2016-01-12 03:18:20 +01:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class Content {
|
|
|
|
|
|
|
|
public $vars;
|
|
|
|
|
|
|
|
function __construct($path)
|
|
|
|
{
|
|
|
|
if($this->build($path)===false) {
|
|
|
|
$this->vars = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Return TRUE if the content is loaded correctly
|
2016-01-12 03:18:20 +01:00
|
|
|
public function isValid()
|
|
|
|
{
|
|
|
|
return($this->vars!==false);
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the value from the $field, FALSE if the field doesn't exist
|
2016-01-12 03:18:20 +01:00
|
|
|
public function getField($field)
|
|
|
|
{
|
|
|
|
if(isset($this->vars[$field])) {
|
|
|
|
return $this->vars[$field];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Set a value to a field
|
2016-01-12 03:18:20 +01:00
|
|
|
public function setField($field, $value, $overwrite=true)
|
|
|
|
{
|
|
|
|
if($overwrite || empty($this->vars[$field])) {
|
|
|
|
$this->vars[$field] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Parse the content from the file index.txt
|
2016-01-12 03:18:20 +01:00
|
|
|
private function build($path)
|
|
|
|
{
|
2016-07-17 01:19:10 +02:00
|
|
|
if( !Sanitize::pathFile($path.FILENAME) ) {
|
2016-01-12 03:18:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp = 0;
|
2016-07-17 01:19:10 +02:00
|
|
|
$lines = file($path.FILENAME);
|
2016-01-12 03:18:20 +01:00
|
|
|
foreach($lines as $lineNumber=>$line)
|
|
|
|
{
|
|
|
|
$parts = array_map('trim', explode(':', $line, 2));
|
|
|
|
|
|
|
|
// Lowercase variable
|
|
|
|
$parts[0] = Text::lowercase($parts[0]);
|
|
|
|
|
|
|
|
// If variables is content then break the foreach and process the content after.
|
|
|
|
if($parts[0]==='content')
|
|
|
|
{
|
|
|
|
$tmp = $lineNumber;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !empty($parts[0]) && !empty($parts[1]) ) {
|
|
|
|
// Sanitize all fields, except Content.
|
|
|
|
$this->vars[$parts[0]] = Sanitize::html($parts[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the content.
|
|
|
|
if($tmp!==0)
|
|
|
|
{
|
|
|
|
// Next line after "Content:" variable
|
|
|
|
$tmp++;
|
|
|
|
|
|
|
|
// Remove lines after Content
|
|
|
|
$output = array_slice($lines, $tmp);
|
|
|
|
|
|
|
|
if(!empty($parts[1])) {
|
|
|
|
array_unshift($output, "\n");
|
|
|
|
array_unshift($output, $parts[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$implode = implode($output);
|
|
|
|
$this->vars['content'] = $implode;
|
|
|
|
|
|
|
|
// Sanitize content.
|
|
|
|
//$this->vars['content'] = Sanitize::html($implode);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the title field
|
2016-01-12 03:18:20 +01:00
|
|
|
public function title()
|
|
|
|
{
|
|
|
|
return $this->getField('title');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the content
|
|
|
|
// This content is markdown parser
|
|
|
|
// (boolean) $fullContent, TRUE returns all content, if FALSE returns the first part of the content
|
|
|
|
// (boolean) $noSanitize, TRUE returns the content without sanitized
|
|
|
|
public function content($fullContent=true, $noSanitize=true)
|
2016-01-12 03:18:20 +01:00
|
|
|
{
|
|
|
|
// This content is not sanitized.
|
|
|
|
$content = $this->getField('content');
|
|
|
|
|
|
|
|
if(!$fullContent) {
|
|
|
|
$content = $this->getField('breakContent');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
if($noSanitize) {
|
2016-01-12 03:18:20 +01:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Sanitize::html($content);
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the content
|
|
|
|
// This content is not markdown parser
|
|
|
|
// (boolean) $noSanitize, TRUE returns the content without sanitized
|
|
|
|
public function contentRaw($noSanitize=true)
|
2016-01-12 03:18:20 +01:00
|
|
|
{
|
|
|
|
// This content is not sanitized.
|
|
|
|
$content = $this->getField('contentRaw');
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
if($noSanitize) {
|
2016-01-12 03:18:20 +01:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Sanitize::html($content);
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns TRUE if the content has the text splited
|
|
|
|
public function readMore()
|
|
|
|
{
|
|
|
|
return $this->getField('readMore');
|
|
|
|
}
|
|
|
|
|
2017-04-26 18:56:10 +02:00
|
|
|
//
|
|
|
|
public function category()
|
|
|
|
{
|
|
|
|
return $this->getField('category');
|
|
|
|
}
|
|
|
|
|
2017-04-26 21:26:17 +02:00
|
|
|
public function uuid()
|
|
|
|
{
|
|
|
|
return $this->getField('uuid');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the field key
|
2016-01-12 03:18:20 +01:00
|
|
|
public function key()
|
|
|
|
{
|
|
|
|
return $this->getField('key');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns TRUE if the post/page is published, FALSE otherwise.
|
2016-01-12 03:18:20 +01:00
|
|
|
public function published()
|
|
|
|
{
|
|
|
|
return ($this->getField('status')==='published');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns TRUE if the post/page is scheduled, FALSE otherwise.
|
2016-01-12 03:18:20 +01:00
|
|
|
public function scheduled()
|
|
|
|
{
|
|
|
|
return ($this->getField('status')==='scheduled');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns TRUE if the post/page is draft, FALSE otherwise.
|
2016-01-12 03:18:20 +01:00
|
|
|
public function draft()
|
|
|
|
{
|
|
|
|
return ($this->getField('status')=='draft');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the file name of the cover image, FALSE there isn't a cover image setted
|
|
|
|
// (boolean) $absolute, TRUE returns the absolute path and file name, FALSE just the file name
|
2016-01-12 03:18:20 +01:00
|
|
|
public function coverImage($absolute=true)
|
|
|
|
{
|
|
|
|
$fileName = $this->getField('coverImage');
|
|
|
|
|
|
|
|
if(empty($fileName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($absolute) {
|
|
|
|
return HTML_PATH_UPLOADS.$fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fileName;
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
/*
|
|
|
|
DEPRECATED ?
|
|
|
|
|
2016-01-12 03:18:20 +01:00
|
|
|
public function profilePicture()
|
|
|
|
{
|
|
|
|
return HTML_PATH_UPLOADS_PROFILES.$this->username().'.jpg';
|
|
|
|
}
|
2016-05-30 02:50:48 +02:00
|
|
|
*/
|
|
|
|
// Returns the user object
|
|
|
|
// (boolean) $field, TRUE returns the value of the field, FALSE returns the object
|
2016-01-12 03:18:20 +01:00
|
|
|
public function user($field=false)
|
|
|
|
{
|
|
|
|
// Get the user object.
|
|
|
|
$User = $this->getField('user');
|
|
|
|
|
|
|
|
if($field) {
|
|
|
|
return $User->getField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $User;
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the username who created the post/page
|
2016-01-12 03:18:20 +01:00
|
|
|
public function username()
|
|
|
|
{
|
|
|
|
return $this->getField('username');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the description field
|
2016-01-12 03:18:20 +01:00
|
|
|
public function description()
|
|
|
|
{
|
|
|
|
return $this->getField('description');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the date according to locale settings and format settings
|
2016-01-12 03:18:20 +01:00
|
|
|
public function date()
|
|
|
|
{
|
|
|
|
return $this->getField('date');
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the date according to locale settings and format as database stored
|
|
|
|
// (string) $format, you can specify the date format
|
2016-01-12 03:18:20 +01:00
|
|
|
public function dateRaw($format=false)
|
|
|
|
{
|
|
|
|
$date = $this->getField('dateRaw');
|
|
|
|
|
|
|
|
if($format) {
|
|
|
|
return Date::format($date, DB_DATE_FORMAT, $format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the tags
|
|
|
|
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
|
2016-01-12 03:18:20 +01:00
|
|
|
public function tags($returnsArray=false)
|
|
|
|
{
|
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$tags = $this->getField('tags');
|
|
|
|
|
|
|
|
if($returnsArray) {
|
|
|
|
|
|
|
|
if($tags==false) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if($tags==false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return string with tags separeted by comma.
|
|
|
|
return implode(', ', $tags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
// Returns the permalink
|
|
|
|
// (boolean) $absolute, TRUE returns the post/page link with the DOMAIN, FALSE without the DOMAIN
|
2016-01-12 03:18:20 +01:00
|
|
|
public function permalink($absolute=false)
|
|
|
|
{
|
|
|
|
global $Url;
|
|
|
|
global $Site;
|
|
|
|
|
|
|
|
$filterType = $this->getField('filterType');
|
|
|
|
|
|
|
|
$url = trim(DOMAIN_BASE,'/');
|
|
|
|
$key = $this->key();
|
|
|
|
$filter = trim($Url->filters($filterType), '/');
|
|
|
|
$htmlPath = trim(HTML_PATH_ROOT,'/');
|
|
|
|
|
|
|
|
if(empty($filter)) {
|
|
|
|
$tmp = $key;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$tmp = $filter.'/'.$key;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($absolute) {
|
|
|
|
return $url.'/'.$tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($htmlPath)) {
|
|
|
|
return '/'.$tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '/'.$htmlPath.'/'.$tmp;
|
|
|
|
}
|
|
|
|
|
2016-06-05 03:31:07 +02:00
|
|
|
public function json($returnsArray=false)
|
2016-05-30 02:50:48 +02:00
|
|
|
{
|
|
|
|
$tmp['key'] = $this->key();
|
|
|
|
$tmp['title'] = $this->title();
|
|
|
|
$tmp['content'] = $this->content(); // Markdown parsed
|
|
|
|
$tmp['contentRaw'] = $this->contentRaw(); // No Markdown parsed
|
|
|
|
$tmp['description'] = $this->description();
|
|
|
|
$tmp['date'] = $this->dateRaw();
|
|
|
|
$tmp['permalink'] = $this->permalink(true);
|
|
|
|
|
2016-06-05 03:31:07 +02:00
|
|
|
if($returnsArray) {
|
|
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
|
2016-05-30 02:50:48 +02:00
|
|
|
return json_encode($tmp);
|
|
|
|
}
|
2016-07-17 01:19:10 +02:00
|
|
|
}
|