Comments on code and improves on API plugins

This commit is contained in:
dignajar 2016-05-29 21:50:48 -03:00
parent d255f94933
commit 13a1838d9c
4 changed files with 67 additions and 63 deletions

View File

@ -11,13 +11,13 @@ class Content {
} }
} }
// Return true if valid // Return TRUE if the content is loaded correctly
public function isValid() public function isValid()
{ {
return($this->vars!==false); return($this->vars!==false);
} }
// Returns the value from the $field, FALSE if the field doesn't exist. // Returns the value from the $field, FALSE if the field doesn't exist
public function getField($field) public function getField($field)
{ {
if(isset($this->vars[$field])) { if(isset($this->vars[$field])) {
@ -27,7 +27,7 @@ class Content {
return false; return false;
} }
// $notoverwrite true if you don't want to replace the value if are set previusly // Set a value to a field
public function setField($field, $value, $overwrite=true) public function setField($field, $value, $overwrite=true)
{ {
if($overwrite || empty($this->vars[$field])) { if($overwrite || empty($this->vars[$field])) {
@ -37,6 +37,7 @@ class Content {
return true; return true;
} }
// Parse the content from the file index.txt
private function build($path) private function build($path)
{ {
if( !Sanitize::pathFile($path.'index.txt') ) { if( !Sanitize::pathFile($path.'index.txt') ) {
@ -88,17 +89,17 @@ class Content {
} }
// Returns the post title. // Returns the title field
public function title() public function title()
{ {
return $this->getField('title'); return $this->getField('title');
} }
// Returns the content. // Returns the content
// This content is markdown parser. // This content is markdown parser
// (boolean) $fullContent, TRUE returns all content, if FALSE returns the first part of the content. // (boolean) $fullContent, TRUE returns all content, if FALSE returns the first part of the content
// (boolean) $raw, TRUE returns the content without sanitized, FALSE otherwise. // (boolean) $noSanitize, TRUE returns the content without sanitized
public function content($fullContent=true, $raw=true) public function content($fullContent=true, $noSanitize=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$content = $this->getField('content'); $content = $this->getField('content');
@ -107,55 +108,60 @@ class Content {
$content = $this->getField('breakContent'); $content = $this->getField('breakContent');
} }
if($raw) { if($noSanitize) {
return $content; return $content;
} }
return Sanitize::html($content); return Sanitize::html($content);
} }
// Returns the content
// This content is not markdown parser
// (boolean) $noSanitize, TRUE returns the content without sanitized
public function contentRaw($noSanitize=true)
{
// This content is not sanitized.
$content = $this->getField('contentRaw');
if($noSanitize) {
return $content;
}
return Sanitize::html($content);
}
// Returns TRUE if the content has the text splited
public function readMore() public function readMore()
{ {
return $this->getField('readMore'); return $this->getField('readMore');
} }
// Returns the content. This content is not markdown parser. // Returns the field key
// (boolean) $raw, TRUE returns the content without sanitized, FALSE otherwise.
public function contentRaw($raw=true)
{
// This content is not sanitized.
$content = $this->getField('contentRaw');
if($raw) {
return $content;
}
return Sanitize::html($content);
}
public function key() public function key()
{ {
return $this->getField('key'); return $this->getField('key');
} }
// Returns TRUE if the post is published, FALSE otherwise. // Returns TRUE if the post/page is published, FALSE otherwise.
public function published() public function published()
{ {
return ($this->getField('status')==='published'); return ($this->getField('status')==='published');
} }
// Returns TRUE if the post is scheduled, FALSE otherwise. // Returns TRUE if the post/page is scheduled, FALSE otherwise.
public function scheduled() public function scheduled()
{ {
return ($this->getField('status')==='scheduled'); return ($this->getField('status')==='scheduled');
} }
// Returns TRUE if the post is draft, FALSE otherwise. // Returns TRUE if the post/page is draft, FALSE otherwise.
public function draft() public function draft()
{ {
return ($this->getField('status')=='draft'); return ($this->getField('status')=='draft');
} }
// 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
public function coverImage($absolute=true) public function coverImage($absolute=true)
{ {
$fileName = $this->getField('coverImage'); $fileName = $this->getField('coverImage');
@ -171,12 +177,16 @@ class Content {
return $fileName; return $fileName;
} }
/*
DEPRECATED ?
public function profilePicture() public function profilePicture()
{ {
return HTML_PATH_UPLOADS_PROFILES.$this->username().'.jpg'; return HTML_PATH_UPLOADS_PROFILES.$this->username().'.jpg';
} }
*/
// Returns the user object if $field is false, otherwise returns the field's value. // Returns the user object
// (boolean) $field, TRUE returns the value of the field, FALSE returns the object
public function user($field=false) public function user($field=false)
{ {
// Get the user object. // Get the user object.
@ -189,23 +199,26 @@ class Content {
return $User; return $User;
} }
// Returns the username who created the post/page
public function username() public function username()
{ {
return $this->getField('username'); return $this->getField('username');
} }
// Returns the description field
public function description() public function description()
{ {
return $this->getField('description'); return $this->getField('description');
} }
// Returns the post date according to locale settings and format settings. // Returns the date according to locale settings and format settings
public function date() public function date()
{ {
return $this->getField('date'); return $this->getField('date');
} }
// Returns the post date according to locale settings and format as database stored. // Returns the date according to locale settings and format as database stored
// (string) $format, you can specify the date format
public function dateRaw($format=false) public function dateRaw($format=false)
{ {
$date = $this->getField('dateRaw'); $date = $this->getField('dateRaw');
@ -217,6 +230,8 @@ class Content {
return $date; return $date;
} }
// Returns the tags
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
public function tags($returnsArray=false) public function tags($returnsArray=false)
{ {
global $Url; global $Url;
@ -241,6 +256,8 @@ class Content {
} }
} }
// Returns the permalink
// (boolean) $absolute, TRUE returns the post/page link with the DOMAIN, FALSE without the DOMAIN
public function permalink($absolute=false) public function permalink($absolute=false)
{ {
global $Url; global $Url;
@ -271,5 +288,16 @@ class Content {
return '/'.$htmlPath.'/'.$tmp; return '/'.$htmlPath.'/'.$tmp;
} }
public function json()
{
$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);
return json_encode($tmp);
}
} }

View File

@ -13,13 +13,13 @@ class Page extends Content {
parent::__construct(PATH_PAGES.$key.DS); parent::__construct(PATH_PAGES.$key.DS);
} }
// Returns the page position. // Returns the page position
public function position() public function position()
{ {
return $this->getField('position'); return $this->getField('position');
} }
// Returns the page slug. // Returns the page slug
public function slug() public function slug()
{ {
$explode = explode('/', $this->getField('key')); $explode = explode('/', $this->getField('key'));
@ -32,7 +32,7 @@ class Page extends Content {
return $explode[0]; return $explode[0];
} }
// Returns the parent key, if the page doesn't have a parent returns FALSE. // Returns the parent key, if the page doesn't have a parent returns FALSE
public function parentKey() public function parentKey()
{ {
$explode = explode('/', $this->getField('key')); $explode = explode('/', $this->getField('key'));
@ -43,7 +43,7 @@ class Page extends Content {
return false; return false;
} }
// Returns the parent method output, if the page doesn't have a parent returns FALSE. // Returns the parent method output, if the page doesn't have a parent returns FALSE
public function parentMethod($method) public function parentMethod($method)
{ {
global $pages; global $pages;
@ -67,14 +67,4 @@ class Page extends Content {
return $tmp; return $tmp;
} }
public function json()
{
$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();
return json_encode($tmp);
}
} }

View File

@ -13,11 +13,7 @@ class Post extends Content {
parent::__construct(PATH_POSTS.$key.DS); parent::__construct(PATH_POSTS.$key.DS);
} }
public function key() // Returns the post slug
{
return $this->getField('key');
}
public function slug() public function slug()
{ {
return $this->getField('key'); return $this->getField('key');
@ -29,14 +25,4 @@ class Post extends Content {
return ($this->getField('status')==='scheduled'); return ($this->getField('status')==='scheduled');
} }
public function json()
{
$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();
return json_encode($tmp);
}
} }

View File

@ -27,7 +27,7 @@ class pluginAPI extends Plugin {
return json_encode(array( return json_encode(array(
'status'=>'0', 'status'=>'0',
'bludit'=>'Bludit API plugin', 'bludit'=>'Bludit API plugin',
'message'=>'The post doesn\'t exist' 'message'=>'The page doesn\'t exist'
)); ));
} }
@ -57,7 +57,7 @@ class pluginAPI extends Plugin {
// Get parameters // Get parameters
$parameters = explode('/', $URI); $parameters = explode('/', $URI);
// Check parameters // Check parameters are sended
for($i=0; $i<3; $i++) { for($i=0; $i<3; $i++) {
if(empty($parameters[$i])) { if(empty($parameters[$i])) {
return false; return false;