First release of domframework

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1207 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-02-27 08:47:54 +00:00
commit 96cf1c4010
26 changed files with 2125 additions and 0 deletions

21
examples/blog/.htaccess Normal file
View File

@@ -0,0 +1,21 @@
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
# if your app is in a subfolder
# RewriteBase /my_app/
# test string is a valid files
RewriteCond %{SCRIPT_FILENAME} !-f
# test string is a valid directory
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
# with QSA flag (query string append),
# forces the rewrite engine to append a query string part of the
# substitution string to the existing string, instead of replacing it.
</IfModule>
# Allow to see a /.html file without having a Forbidden due to Apache conf
<FilesMatch "^\.html">
Satisfy Any
Allow from all
</FilesMatch>

View File

@@ -0,0 +1,127 @@
<?php
error_reporting (E_ALL);
class blog
{
/** Return an article */
private function get ($articleid = FALSE)
{
require_once ("models/model_file.php");
$data = new model_file();
return $data->get ($articleid);
}
/** Return an article in text */
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 */
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 */
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 */
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 */
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 = "Super Title";
$renderer->run ();
exit;
}
catch (Exception $e)
{
// TODO !!
echo "404 with ".$e->getMessage();
exit;
};
}
/** Return the listing of all the recorded articles */
public function listing ()
{
require_once ("models/model_file.php");
$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;
};
}
}

View File

@@ -0,0 +1 @@
deny from all

2
examples/blog/datas/5 Normal file
View File

@@ -0,0 +1,2 @@
<h1>Article 5</h1>
<p>Lorem ipsum</p>

16
examples/blog/index.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
require_once ("domframework/route.php");
require_once ("domframework/renderer.php");
$route = new route ();
$route->debug =0 ;
$res = $route->routingCollection (array (
//"" => array ("route", "redirect", "/1", FALSE),
"" => array ("blog", "listingHtml"),
"{page}.xml" => array ("blog", "getXml", "{page}"),
"{page}.html" => array ("blog", "getHtml", "{page}"),
"{page}.csv" => array ("blog", "getCsv", "{page}"),
"{page}.json" => array ("blog", "getJson", "{page}"),
"{page}.txt" => array ("blog", "getTxt", "{page}"),
"{page}" => array ("blog", "getHtml", "{page}"),
));
echo "404 !";

View File

@@ -0,0 +1,36 @@
<?php
/** Model_file : store the blog datas in files */
class model_file
{
public $dataPath = "datas/";
/** Return a provided article */
function get ($articleid = FALSE)
{
$this->dataPath = realpath ($this->dataPath);
if ($this->dataPath === FALSE)
throw new Exception (_("Folder data not available"), 500);
$fileArticle = $this->dataPath."/".$articleid;
if (! file_exists ($fileArticle))
throw new Exception (_("Article not found"), 404);
$fileArticle = realpath ($fileArticle);
if (substr ($fileArticle, 0, strlen ($this->dataPath)) !== $this->dataPath)
throw new Exception (_("Asked article not in data path"), 404);
if ($fileArticle === FALSE)
throw new Exception (_("Article not found"), 404);
return file_get_contents ($fileArticle);
}
/** Return a list of all the articles ID */
function listing ()
{
$list = glob ($this->dataPath."/*");
if ($list === FALSE || empty ($list))
throw new Exception (_("No article found"), 404);
foreach ($list as $key=>$val)
$list[$key] = basename ($val);
return $list;
}
}

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{title}</title>
</head>
<body>
{content}
</body>
</html>

View File

@@ -0,0 +1,21 @@
<?php
class view_blog
{
function get ($data)
{
return $data;
}
function listing ($data)
{
$content = "<ul>\n";
foreach ($data as $val)
{
$content .= " <li>";
$content .= "<a href='".urlencode ($val)."'>".htmlentities ($val)."</a>";
$content .= "</li>\n";
}
$content .= "</ul>\n";
return $content;
}
}