From 13a1838d9c6319e74e575df83b36270d43128216 Mon Sep 17 00:00:00 2001 From: dignajar Date: Sun, 29 May 2016 21:50:48 -0300 Subject: [PATCH] Comments on code and improves on API plugins --- bl-kernel/abstract/content.class.php | 92 ++++++++++++++++++---------- bl-kernel/page.class.php | 18 ++---- bl-kernel/post.class.php | 16 +---- bl-plugins/api/plugin.php | 4 +- 4 files changed, 67 insertions(+), 63 deletions(-) diff --git a/bl-kernel/abstract/content.class.php b/bl-kernel/abstract/content.class.php index dcb72fa0..93c9b632 100644 --- a/bl-kernel/abstract/content.class.php +++ b/bl-kernel/abstract/content.class.php @@ -11,13 +11,13 @@ class Content { } } - // Return true if valid + // Return TRUE if the content is loaded correctly public function isValid() { 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) { if(isset($this->vars[$field])) { @@ -27,7 +27,7 @@ class Content { 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) { if($overwrite || empty($this->vars[$field])) { @@ -37,6 +37,7 @@ class Content { return true; } + // Parse the content from the file index.txt private function build($path) { if( !Sanitize::pathFile($path.'index.txt') ) { @@ -88,17 +89,17 @@ class Content { } - // Returns the post title. + // Returns the title field public function title() { return $this->getField('title'); } - // Returns the content. - // This content is markdown parser. - // (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. - public function content($fullContent=true, $raw=true) + // 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) { // This content is not sanitized. $content = $this->getField('content'); @@ -107,55 +108,60 @@ class Content { $content = $this->getField('breakContent'); } - if($raw) { + if($noSanitize) { return $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() { return $this->getField('readMore'); } - // Returns the content. This content is not markdown parser. - // (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); - } - + // Returns the field key public function 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() { 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() { 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() { 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) { $fileName = $this->getField('coverImage'); @@ -171,12 +177,16 @@ class Content { return $fileName; } +/* + DEPRECATED ? + public function profilePicture() { 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) { // Get the user object. @@ -189,23 +199,26 @@ class Content { return $User; } + // Returns the username who created the post/page public function username() { return $this->getField('username'); } + // Returns the description field public function 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() { 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) { $date = $this->getField('dateRaw'); @@ -217,6 +230,8 @@ class Content { 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) { 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) { global $Url; @@ -271,5 +288,16 @@ class Content { 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); + } +} \ No newline at end of file diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index 8f44ee2b..ab412a8c 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -13,13 +13,13 @@ class Page extends Content { parent::__construct(PATH_PAGES.$key.DS); } - // Returns the page position. + // Returns the page position public function position() { return $this->getField('position'); } - // Returns the page slug. + // Returns the page slug public function slug() { $explode = explode('/', $this->getField('key')); @@ -32,7 +32,7 @@ class Page extends Content { 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() { $explode = explode('/', $this->getField('key')); @@ -43,7 +43,7 @@ class Page extends Content { 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) { global $pages; @@ -67,14 +67,4 @@ class Page extends Content { 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); - } } \ No newline at end of file diff --git a/bl-kernel/post.class.php b/bl-kernel/post.class.php index d358ea25..112d14a6 100644 --- a/bl-kernel/post.class.php +++ b/bl-kernel/post.class.php @@ -13,11 +13,7 @@ class Post extends Content { parent::__construct(PATH_POSTS.$key.DS); } - public function key() - { - return $this->getField('key'); - } - + // Returns the post slug public function slug() { return $this->getField('key'); @@ -29,14 +25,4 @@ class Post extends Content { 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); - } } \ No newline at end of file diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index 06c66c7a..ddc2a3c6 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -27,7 +27,7 @@ class pluginAPI extends Plugin { return json_encode(array( 'status'=>'0', '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 $parameters = explode('/', $URI); - // Check parameters + // Check parameters are sended for($i=0; $i<3; $i++) { if(empty($parameters[$i])) { return false;