2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
class Page extends fileContent
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
function __construct($key)
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
|
|
|
$this->path = PATH_PAGES;
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
parent::__construct($key);
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the post title.
|
2015-05-05 03:00:01 +02:00
|
|
|
public function title()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return $this->getField('title');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the post content.
|
2015-05-05 03:00:01 +02:00
|
|
|
public function content()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return $this->getField('content');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function contentRaw()
|
|
|
|
{
|
|
|
|
return $this->getField('contentRaw');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function description()
|
|
|
|
{
|
|
|
|
return $this->getField('description');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tags()
|
|
|
|
{
|
|
|
|
return $this->getField('tags');
|
|
|
|
}
|
|
|
|
|
2015-05-19 01:22:05 +02:00
|
|
|
public function tagsArray()
|
|
|
|
{
|
|
|
|
$tags = $this->getField('tags');
|
|
|
|
return explode(',', $tags);
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
public function position()
|
|
|
|
{
|
|
|
|
return $this->getField('position');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the post date in unix timestamp format, UTC-0.
|
2015-05-05 03:00:01 +02:00
|
|
|
public function unixTimeCreated()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return $this->getField('unixTimeCreated');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unixTimeModified()
|
|
|
|
{
|
|
|
|
return $this->getField('unixTimeModified');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the post date according to locale settings and format settings.
|
2015-05-19 01:22:05 +02:00
|
|
|
public function dateCreated($format=false)
|
|
|
|
{
|
|
|
|
if($format===false) {
|
|
|
|
return $this->getField('date');
|
|
|
|
}
|
|
|
|
|
|
|
|
$unixTimeCreated = $this->unixTimeCreated();
|
|
|
|
|
|
|
|
return Date::format($unixTimeCreated, $format);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dateModified($format=false)
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-19 01:22:05 +02:00
|
|
|
if($format===false) {
|
|
|
|
return $this->getField('date');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-05-19 01:22:05 +02:00
|
|
|
$unixTimeModified = $this->unixTimeModified();
|
|
|
|
|
|
|
|
return Date::format($unixTimeModified, $format);
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the time ago
|
2015-05-05 03:00:01 +02:00
|
|
|
public function timeago()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return $this->getField('timeago');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the page slug.
|
2015-05-05 03:00:01 +02:00
|
|
|
public function slug()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
$explode = explode('/', $this->getField('key'));
|
|
|
|
if(!empty($explode[1]))
|
|
|
|
return $explode[1];
|
|
|
|
|
|
|
|
return $explode[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function key()
|
|
|
|
{
|
|
|
|
return $this->getField('key');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns TRUE if the page is published, FALSE otherwise.
|
2015-05-05 03:00:01 +02:00
|
|
|
public function published()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return ($this->getField('status')==='published');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the page permalink.
|
2015-05-05 03:00:01 +02:00
|
|
|
public function permalink()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
|
|
|
global $Url;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
$path = '';
|
|
|
|
$slug = $this->slug();
|
|
|
|
$parent = $this->parent();
|
2015-03-08 18:02:59 +01:00
|
|
|
$filter = ltrim($Url->filters('page'), '/');
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
if($Url->filters('page')==HTML_PATH_ROOT) {
|
|
|
|
$path = HTML_PATH_ROOT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$path = HTML_PATH_ROOT.$filter.'/';
|
|
|
|
}
|
|
|
|
|
|
|
|
if($parent===false) {
|
|
|
|
return $path.$slug;
|
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
return $path.$parent.'/'.$slug;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
public function parentKey()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
$explode = explode('/', $this->getField('key'));
|
|
|
|
if(isset($explode[1])) {
|
|
|
|
return $explode[0];
|
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
public function children()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
$tmp = array();
|
|
|
|
$paths = glob(PATH_PAGES.$this->getField('key').'/*', GLOB_ONLYDIR);
|
|
|
|
foreach($paths as $path) {
|
|
|
|
array_push($tmp, basename($path));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tmp;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
public function username()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return $this->getField('username');
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
public function author()
|
|
|
|
{
|
|
|
|
return $this->getField('author');
|
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|