bludit/kernel/post.class.php

170 lines
3.1 KiB
PHP
Raw Normal View History

2015-05-05 01:00:01 +00:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2015-03-08 14:02:59 -03:00
2015-05-05 01:00:01 +00:00
class Post extends fileContent
2015-03-08 14:02:59 -03:00
{
2015-06-30 00:23:29 -03:00
function __construct($key)
2015-03-08 14:02:59 -03:00
{
2015-06-30 00:23:29 -03:00
// Database Key
$this->setField('key', $key);
2015-03-08 14:02:59 -03:00
2015-06-30 00:23:29 -03:00
parent::__construct(PATH_POSTS.$key.DS);
2015-03-08 14:02:59 -03:00
}
2015-05-05 01:00:01 +00:00
// Returns the post title.
public function title()
2015-03-08 14:02:59 -03:00
{
2015-05-05 01:00:01 +00:00
return $this->getField('title');
2015-03-08 14:02:59 -03:00
}
2015-07-13 23:16:28 -03:00
// Returns the content.
2015-06-27 20:28:22 -03:00
// This content is markdown parser.
2015-07-13 23:16:28 -03:00
// $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
// $html, TRUE returns the content without satinize, FALSE otherwise.
public function content($fullContent=true, $html=true)
2015-03-08 14:02:59 -03:00
{
2015-06-27 20:28:22 -03:00
// This content is not sanitized.
$content = $this->getField('content');
2015-07-13 23:16:28 -03:00
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
2015-06-27 20:28:22 -03:00
if($html) {
return $content;
}
return Sanitize::html($content);
2015-03-08 14:02:59 -03:00
}
2015-07-13 23:16:28 -03:00
// Returns the content.
2015-06-27 20:28:22 -03:00
// This content is not markdown parser.
2015-07-13 23:16:28 -03:00
// $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
// $html, TRUE returns the content without satinize, FALSE otherwise.
public function contentRaw($fullContent=true, $html=true)
2015-03-08 14:02:59 -03:00
{
2015-06-27 20:28:22 -03:00
// This content is not sanitized.
2015-07-13 23:16:28 -03:00
$content = $this->getField('contentRaw');
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
2015-06-27 20:28:22 -03:00
if($html) {
2015-07-13 23:16:28 -03:00
return $content;
2015-06-27 20:28:22 -03:00
}
2015-07-13 23:16:28 -03:00
return Sanitize::html($content);
2015-03-08 14:02:59 -03:00
}
2015-05-05 01:00:01 +00:00
public function key()
2015-03-08 14:02:59 -03:00
{
2015-05-05 01:00:01 +00:00
return $this->getField('key');
2015-03-08 14:02:59 -03:00
}
2015-07-06 22:05:17 -03:00
// Returns TRUE if the post is published, FALSE otherwise.
public function published()
{
return ($this->getField('status')==='published');
}
2015-05-05 01:00:01 +00:00
public function username()
2015-03-08 14:02:59 -03:00
{
2015-05-05 01:00:01 +00:00
return $this->getField('username');
2015-03-08 14:02:59 -03:00
}
2015-07-06 22:05:17 -03:00
public function authorFirstName()
2015-03-08 14:02:59 -03:00
{
2015-07-06 22:05:17 -03:00
return $this->getField('authorFirstName');
2015-03-08 14:02:59 -03:00
}
2015-07-06 22:05:17 -03:00
public function authorLastName()
2015-05-05 01:00:01 +00:00
{
2015-07-06 22:05:17 -03:00
return $this->getField('authorLastName');
2015-05-05 01:00:01 +00:00
}
public function description()
{
return $this->getField('description');
}
public function unixTimeCreated()
{
return $this->getField('unixTimeCreated');
}
public function unixTimeModified()
{
return $this->getField('unixTimeModified');
}
2015-05-18 23:22:05 +00:00
public function dateCreated($format=false)
2015-03-08 14:02:59 -03:00
{
2015-05-18 23:22:05 +00:00
if($format===false) {
return $this->getField('date');
2015-03-08 14:02:59 -03:00
}
2015-05-18 23:22:05 +00:00
$unixTimeCreated = $this->unixTimeCreated();
return Date::format($unixTimeCreated, $format);
}
public function dateModified($format=false)
{
if($format===false) {
return $this->getField('date');
}
$unixTimeModified = $this->unixTimeModified();
return Date::format($unixTimeModified, $format);
2015-05-05 01:00:01 +00:00
}
public function timeago()
{
return $this->getField('timeago');
2015-03-08 14:02:59 -03:00
}
2015-05-05 01:00:01 +00:00
public function tags()
2015-03-08 14:02:59 -03:00
{
2015-05-05 01:00:01 +00:00
return $this->getField('tags');
2015-03-08 14:02:59 -03:00
}
2015-05-05 01:00:01 +00:00
public function slug()
2015-03-08 14:02:59 -03:00
{
2015-05-05 01:00:01 +00:00
return $this->getField('key');
2015-03-08 14:02:59 -03:00
}
2015-06-02 22:17:09 -03:00
public function permalink($absolute=false)
2015-03-08 14:02:59 -03:00
{
global $Url;
2015-06-02 22:17:09 -03:00
global $Site;
2015-05-05 01:00:01 +00:00
2015-06-02 22:17:09 -03:00
$url = trim($Site->url(),'/');
$key = $this->key();
$filter = trim($Url->filters('post'), '/');
$htmlPath = trim(HTML_PATH_ROOT,'/');
2015-03-08 14:02:59 -03:00
2015-06-02 22:17:09 -03:00
if(empty($filter)) {
$tmp = $key;
}
else {
$tmp = $filter.'/'.$key;
}
if($absolute) {
return $url.'/'.$tmp;
}
2015-03-08 14:02:59 -03:00
2015-06-21 21:47:07 -03:00
if(empty($htmlPath)) {
return '/'.$tmp;
}
2015-06-02 22:28:16 -03:00
return '/'.$htmlPath.'/'.$tmp;
2015-03-08 14:02:59 -03:00
}
}