Comments on code and improves on API plugins
This commit is contained in:
parent
d255f94933
commit
13a1838d9c
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue