git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1551 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
199 lines
4.9 KiB
PHP
199 lines
4.9 KiB
PHP
<?php
|
|
/** DomFramework Blog
|
|
@package domframework-blog
|
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
|
|
|
require ("domframework/form.php");
|
|
require_once ("models/model_file.php");
|
|
|
|
error_reporting (E_ALL);
|
|
/** The main class : manage all the blogs articles */
|
|
class blog
|
|
{
|
|
/** Return an article
|
|
@param string|integer|null $articleid The article to display */
|
|
private function get ($articleid = FALSE)
|
|
{
|
|
require_once ("models/model_file.php");
|
|
$data = new model_file();
|
|
return $data->get ($articleid);
|
|
}
|
|
|
|
/** Return an article in text
|
|
@param string|integer|null $articleid The article to display */
|
|
public function getTxt ($articleid = FALSE)
|
|
{
|
|
try
|
|
{
|
|
$res = $this->get ($articleid);
|
|
$renderer = new renderer ();
|
|
$renderer->output = "txt";
|
|
$renderer->result = $res;
|
|
$renderer->run ();
|
|
exit;
|
|
}
|
|
catch (Exception $e) {};
|
|
}
|
|
|
|
/** Return an article in xml
|
|
@param string|integer|null $articleid The article to display */
|
|
public function getXml ($articleid = FALSE)
|
|
{
|
|
try
|
|
{
|
|
$res = $this->get ($articleid);
|
|
$renderer = new renderer ();
|
|
$renderer->output = "xml";
|
|
$renderer->result = $res;
|
|
$renderer->run ();
|
|
exit;
|
|
}
|
|
catch (Exception $e) {};
|
|
}
|
|
|
|
/** Return an article in CSV
|
|
@param string|integer|null $articleid The article to display */
|
|
public function getCsv ($articleid = FALSE)
|
|
{
|
|
try
|
|
{
|
|
$res = $this->get ($articleid);
|
|
$renderer = new renderer ();
|
|
$renderer->output = "csv";
|
|
$renderer->result = $res;
|
|
$renderer->run ();
|
|
exit;
|
|
}
|
|
catch (Exception $e) {};
|
|
}
|
|
|
|
/** Return an article in JSON
|
|
@param string|integer|null $articleid The article to display */
|
|
public function getJson ($articleid = FALSE)
|
|
{
|
|
try
|
|
{
|
|
$res = $this->get ($articleid);
|
|
$renderer = new renderer ();
|
|
$renderer->output = "json";
|
|
$renderer->result = $res;
|
|
$renderer->run ();
|
|
exit;
|
|
}
|
|
catch (Exception $e) {};
|
|
}
|
|
|
|
/** Return an article in HTML
|
|
@param string|integer|null $articleid The article to display */
|
|
public function getHtml ($articleid = FALSE)
|
|
{
|
|
try
|
|
{
|
|
$res = $this->get ($articleid);
|
|
$renderer = new renderer ();
|
|
$renderer->output = "html";
|
|
$renderer->result = $res;
|
|
$renderer->viewClass = "view_blog";
|
|
$renderer->viewMethod = "get";
|
|
$renderer->layout = "layout";
|
|
$renderer->title = $res["title"];
|
|
$renderer->variable = array (
|
|
"title"=>$res["title"],
|
|
"content"=>$res["content"],
|
|
"articleid"=>$articleid,
|
|
);
|
|
$renderer->run ();
|
|
exit;
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
// TODO !!
|
|
echo "404 with ".$e->getMessage();
|
|
exit;
|
|
};
|
|
}
|
|
|
|
/** Return the listing of all the recorded articles */
|
|
public function listing ()
|
|
{
|
|
$data = new model_file();
|
|
return $data->listing ();
|
|
}
|
|
|
|
/** Return the listing of all the recorded articles in HTML */
|
|
public function listingHtml ()
|
|
{
|
|
try
|
|
{
|
|
$res = $this->listing ();
|
|
$renderer = new renderer ();
|
|
$renderer->output = "html";
|
|
$renderer->result = $res;
|
|
$renderer->viewClass = "view_blog";
|
|
$renderer->viewMethod = "listing";
|
|
$renderer->layout = "layout";
|
|
$renderer->run ();
|
|
exit;
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
// TODO !!
|
|
echo "404 with ".$e->getMessage();
|
|
exit;
|
|
};
|
|
}
|
|
|
|
/** Edit the provided article $articleid */
|
|
public function editShow ($articleid=false)
|
|
{
|
|
if ($articleid !== false)
|
|
$res = $this->get ($articleid);
|
|
else
|
|
$res = array ("title"=>"", "content"=>"");
|
|
|
|
$field = new formfield ("title", "Title");
|
|
$field->mandatory = true;
|
|
$formFields[] = $field;
|
|
$field = new formfield ("content", "Content");
|
|
$field->mandatory = true;
|
|
$formFields[] = $field;
|
|
$field = new formfield ("submit", "Record");
|
|
$field->type = "submit";
|
|
$formFields[] = $field;
|
|
|
|
$f = new form ();
|
|
$f->fields ($formFields);
|
|
|
|
$renderer = new renderer ();
|
|
$renderer->output = "html";
|
|
$renderer->viewClass = "view_blog";
|
|
$renderer->viewMethod = "edit";
|
|
$renderer->layout = "layout";
|
|
$renderer->result = $f->printHTML ("post", $res);
|
|
$renderer->run ();
|
|
}
|
|
|
|
/** Save the informations to edit a new article */
|
|
public function editSave ($articleid)
|
|
{
|
|
$field = new formfield ("title", "Title");
|
|
$field->mandatory = true;
|
|
$formFields[] = $field;
|
|
$field = new formfield ("content", "Content");
|
|
$field->mandatory = true;
|
|
$formFields[] = $field;
|
|
$field = new formfield ("submit", "Record");
|
|
$field->type = "submit";
|
|
$formFields[] = $field;
|
|
|
|
$f = new form ();
|
|
$f->fields ($formFields);
|
|
$values = $f->values();
|
|
unset ($values["submit"]);
|
|
$model = new model_file ();
|
|
$model->set ($values, $articleid);
|
|
$r = new route ();
|
|
$r->redirect ("/", "");
|
|
}
|
|
}
|