Files
DomFramework/examples/blog/models/model_file.php
2014-02-27 08:47:54 +00:00

37 lines
1.1 KiB
PHP

<?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;
}
}