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-08-24 00:07:14 +02:00
|
|
|
{
|
2015-06-30 05:23:29 +02:00
|
|
|
// Database Key
|
|
|
|
$this->setField('key', $key);
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-06-30 05:23:29 +02:00
|
|
|
parent::__construct(PATH_PAGES.$key.DS);
|
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
|
|
|
}
|
|
|
|
|
2015-08-24 00:07:14 +02:00
|
|
|
// Returns the content. This content is markdown parser.
|
|
|
|
// (boolean) $html, TRUE returns the content without satinize, FALSE otherwise.
|
2015-07-26 02:25:13 +02:00
|
|
|
public function content($html=true)
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-06-28 01:28:22 +02:00
|
|
|
// This content is not sanitized.
|
|
|
|
$content = $this->getField('content');
|
|
|
|
|
|
|
|
if($html) {
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Sanitize::html($content);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-24 00:07:14 +02:00
|
|
|
// Returns the content. This content is not markdown parser.
|
|
|
|
// (boolean) $raw, TRUE returns the content without sanitized, FALSE otherwise.
|
|
|
|
public function contentRaw($raw=true)
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-06-28 01:28:22 +02:00
|
|
|
// This content is not sanitized.
|
2015-07-14 04:16:28 +02:00
|
|
|
$content = $this->getField('contentRaw');
|
|
|
|
|
2015-08-24 00:07:14 +02:00
|
|
|
if($raw) {
|
2015-07-14 04:16:28 +02:00
|
|
|
return $content;
|
2015-06-28 01:28:22 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
return Sanitize::html($content);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function description()
|
|
|
|
{
|
|
|
|
return $this->getField('description');
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:24:10 +02:00
|
|
|
public function tags($returnsArray=false)
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-09-18 05:24:10 +02:00
|
|
|
global $Url;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-05-19 01:22:05 +02:00
|
|
|
$tags = $this->getField('tags');
|
2015-09-18 05:24:10 +02:00
|
|
|
|
|
|
|
if($returnsArray) {
|
|
|
|
|
|
|
|
if($tags==false) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
else {
|
2015-09-22 01:37:04 +02:00
|
|
|
if($tags==false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:24:10 +02:00
|
|
|
// Return string with tags separeted by comma.
|
|
|
|
return implode(', ', $tags);
|
|
|
|
}
|
2015-05-19 01:22:05 +02:00
|
|
|
}
|
|
|
|
|
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 according to locale settings and format settings.
|
2015-12-01 00:07:06 +01:00
|
|
|
public function date()
|
2015-05-19 01:22:05 +02:00
|
|
|
{
|
2015-11-27 17:03:42 +01:00
|
|
|
return $this->getField('date');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the post date according to locale settings and format as database stored.
|
|
|
|
public function dateRaw($format=false)
|
|
|
|
{
|
|
|
|
$date = $this->getField('dateRaw');
|
2015-05-19 01:22:05 +02:00
|
|
|
|
2015-08-26 05:42:32 +02:00
|
|
|
if($format) {
|
2015-11-27 17:03:42 +01:00
|
|
|
return Date::format($date, DB_DATE_FORMAT, $format);
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-08-26 05:42:32 +02:00
|
|
|
return $date;
|
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
|
|
|
}
|
|
|
|
|
2015-12-31 04:01:16 +01:00
|
|
|
public function coverImage($absolute=true)
|
2015-12-31 01:35:28 +01:00
|
|
|
{
|
2015-12-31 04:01:16 +01:00
|
|
|
$fileName = $this->getField('coverImage');
|
|
|
|
|
2016-01-08 04:04:59 +01:00
|
|
|
if(empty($fileName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-31 04:01:16 +01:00
|
|
|
if($absolute) {
|
|
|
|
return HTML_PATH_UPLOADS.$fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fileName;
|
2015-12-31 01:35:28 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-19 00:45:58 +02:00
|
|
|
// Returns TRUE if the post is draft, FALSE otherwise.
|
|
|
|
public function draft()
|
|
|
|
{
|
|
|
|
return ($this->getField('status')=='draft');
|
|
|
|
}
|
|
|
|
|
2015-03-08 18:02:59 +01:00
|
|
|
// Returns the page permalink.
|
2015-06-03 03:17:09 +02:00
|
|
|
public function permalink($absolute=false)
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
|
|
|
global $Url;
|
2015-06-03 03:17:09 +02:00
|
|
|
global $Site;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-06-03 03:17:09 +02:00
|
|
|
$url = trim($Site->url(),'/');
|
|
|
|
$key = $this->key();
|
|
|
|
$filter = trim($Url->filters('page'), '/');
|
|
|
|
$htmlPath = trim(HTML_PATH_ROOT,'/');
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-06-03 03:17:09 +02:00
|
|
|
if(empty($filter)) {
|
|
|
|
$tmp = $key;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-06-03 03:17:09 +02:00
|
|
|
$tmp = $filter.'/'.$key;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-06-03 03:17:09 +02:00
|
|
|
if($absolute) {
|
|
|
|
return $url.'/'.$tmp;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-06-22 02:47:07 +02:00
|
|
|
if(empty($htmlPath)) {
|
|
|
|
return '/'.$tmp;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:28:16 +02:00
|
|
|
return '/'.$htmlPath.'/'.$tmp;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-11-25 02:48:19 +01:00
|
|
|
// Returns the parent key, if the page doesn't have a parent returns FALSE.
|
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-11-25 02:48:19 +01:00
|
|
|
// Returns the parent method output, if the page doesn't have a parent returns FALSE.
|
|
|
|
public function parentMethod($method)
|
|
|
|
{
|
|
|
|
global $pages;
|
|
|
|
|
|
|
|
if( isset($pages[$this->parentKey()]) ) {
|
|
|
|
return $pages[$this->parentKey()]->{$method}();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2015-09-15 01:07:15 +02:00
|
|
|
//$paths = glob(PATH_PAGES.$this->getField('key').DS.'*', GLOB_ONLYDIR);
|
|
|
|
$paths = Filesystem::listDirectories(PATH_PAGES.$this->getField('key').DS);
|
2015-05-05 03:00:01 +02:00
|
|
|
foreach($paths as $path) {
|
|
|
|
array_push($tmp, basename($path));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tmp;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
// Returns the user object if $field is false, otherwise returns the field's value.
|
|
|
|
public function user($field=false)
|
|
|
|
{
|
|
|
|
// Get the user object.
|
|
|
|
$User = $this->getField('user');
|
|
|
|
|
|
|
|
if($field) {
|
|
|
|
return $User->getField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $User;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEPRECATED
|
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-12-31 19:47:34 +01:00
|
|
|
// DEPRECATED
|
2015-07-07 03:05:17 +02:00
|
|
|
public function authorFirstName()
|
2015-05-05 03:00:01 +02:00
|
|
|
{
|
2015-07-07 03:05:17 +02:00
|
|
|
return $this->getField('authorFirstName');
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
// DEPRECATED
|
2015-07-07 03:05:17 +02:00
|
|
|
public function authorLastName()
|
|
|
|
{
|
|
|
|
return $this->getField('authorLastName');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-11-28 15:47:03 +01:00
|
|
|
}
|