bludit/kernel/post.class.php

153 lines
2.9 KiB
PHP
Raw Normal View History

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 Post extends fileContent
2015-03-08 18:02:59 +01:00
{
2015-06-30 05:23:29 +02:00
function __construct($key)
2015-03-08 18:02:59 +01: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_POSTS.$key.DS);
2015-03-08 18:02:59 +01:00
}
2015-05-05 03:00:01 +02:00
// Returns the post title.
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-07-14 04:16:28 +02:00
// Returns the content.
2015-06-28 01:28:22 +02:00
// This content is markdown parser.
2015-08-24 00:07:14 +02:00
// (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)
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');
2015-08-24 00:07:14 +02:00
if(!$fullContent) {
2015-07-26 02:25:13 +02:00
$content = $this->getField('breakContent');
2015-07-14 04:16:28 +02:00
}
2015-08-24 00:07:14 +02:00
if($raw) {
2015-06-28 01:28:22 +02:00
return $content;
}
return Sanitize::html($content);
2015-03-08 18:02:59 +01:00
}
2015-07-26 02:25:13 +02:00
public function readMore()
{
return $this->getField('readMore');
}
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-03-08 18:02:59 +01: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-03-08 18:02:59 +01:00
}
2015-05-05 03:00:01 +02:00
public function key()
2015-03-08 18:02:59 +01:00
{
2015-05-05 03:00:01 +02:00
return $this->getField('key');
2015-03-08 18:02:59 +01:00
}
2015-07-07 03:05:17 +02:00
// Returns TRUE if the post is published, FALSE otherwise.
public function published()
{
2015-09-02 02:42:21 +02:00
return ($this->getField('status')==='published');
2015-08-26 05:42:32 +02:00
}
// Returns TRUE if the post is scheduled, FALSE otherwise.
public function scheduled()
{
2015-09-02 02:42:21 +02:00
return ($this->getField('status')==='scheduled');
2015-07-07 03:05:17 +02:00
}
2015-08-26 05:49:15 +02:00
// Returns TRUE if the post is draft, FALSE otherwise.
public function draft()
{
return ($this->getField('status')=='draft');
}
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-07-07 03:05:17 +02:00
public function authorFirstName()
2015-03-08 18:02:59 +01:00
{
2015-07-07 03:05:17 +02:00
return $this->getField('authorFirstName');
2015-03-08 18:02:59 +01:00
}
2015-07-07 03:05:17 +02:00
public function authorLastName()
2015-05-05 03:00:01 +02:00
{
2015-07-07 03:05:17 +02:00
return $this->getField('authorLastName');
2015-05-05 03:00:01 +02:00
}
public function description()
{
return $this->getField('description');
}
2015-08-26 05:42:32 +02:00
// Returns the post date according to locale settings and format settings.
public function date($format=false)
2015-03-08 18:02:59 +01:00
{
2015-08-26 05:42:32 +02:00
$date = $this->getField('date');
2015-05-19 01:22:05 +02:00
2015-08-26 05:42:32 +02:00
if($format) {
// En %d %b deberia ir el formato definido por el usuario
return Date::format($date, DB_DATE_FORMAT, '%d %B');
2015-05-19 01:22:05 +02:00
}
2015-08-26 05:42:32 +02:00
return $date;
2015-03-08 18:02:59 +01:00
}
2015-05-05 03:00:01 +02:00
public function tags()
2015-03-08 18:02:59 +01:00
{
2015-05-05 03:00:01 +02:00
return $this->getField('tags');
2015-03-08 18:02:59 +01:00
}
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
return $this->getField('key');
2015-03-08 18:02:59 +01:00
}
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('post'), '/');
$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;
}
else {
$tmp = $filter.'/'.$key;
}
if($absolute) {
return $url.'/'.$tmp;
}
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
}
}