Removed buildPage function, bug fix on paginator, bug fix in dblist
This commit is contained in:
parent
35694980ab
commit
456aa20130
|
@ -46,7 +46,7 @@ class dbList extends dbJSON
|
||||||
|
|
||||||
// The first page number is 1, so the real is 0
|
// The first page number is 1, so the real is 0
|
||||||
$realPageNumber = $pageNumber - 1;
|
$realPageNumber = $pageNumber - 1;
|
||||||
$chunks = array_chunk($list, $realPageNumber);
|
$chunks = array_chunk($list, $amountOfItems);
|
||||||
if (isset($chunks[$realPageNumber])) {
|
if (isset($chunks[$realPageNumber])) {
|
||||||
return $chunks[$realPageNumber];
|
return $chunks[$realPageNumber];
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,13 +165,20 @@
|
||||||
));
|
));
|
||||||
|
|
||||||
// Parent
|
// Parent
|
||||||
$parentTMP = buildPage($page->parent());
|
try {
|
||||||
|
$parentKey = $page->parent();
|
||||||
|
$parent = new PageX($parentKey);
|
||||||
|
$parentOption = $parent->title();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$parentOption = '';
|
||||||
|
}
|
||||||
|
|
||||||
echo Bootstrap::formInputText(array(
|
echo Bootstrap::formInputText(array(
|
||||||
'name'=>'parentTMP',
|
'name'=>'parentTMP',
|
||||||
'label'=>$L->g('Parent'),
|
'label'=>$L->g('Parent'),
|
||||||
'placeholder'=>'',
|
'placeholder'=>'',
|
||||||
'tip'=>'Start typing a page title to see a list of suggestions.',
|
'tip'=>'Start typing a page title to see a list of suggestions.',
|
||||||
'value'=>($parentTMP?$parentTMP->title():'')
|
'value'=>$parentOption
|
||||||
));
|
));
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
|
|
|
@ -85,7 +85,6 @@ include(PATH_KERNEL.'dblanguage.class.php');
|
||||||
include(PATH_KERNEL.'dbsite.class.php');
|
include(PATH_KERNEL.'dbsite.class.php');
|
||||||
include(PATH_KERNEL.'dbcategories.class.php');
|
include(PATH_KERNEL.'dbcategories.class.php');
|
||||||
include(PATH_KERNEL.'dbsyslog.class.php');
|
include(PATH_KERNEL.'dbsyslog.class.php');
|
||||||
include(PATH_KERNEL.'page.class.php');
|
|
||||||
include(PATH_KERNEL.'pagex.class.php');
|
include(PATH_KERNEL.'pagex.class.php');
|
||||||
include(PATH_KERNEL.'category.class.php');
|
include(PATH_KERNEL.'category.class.php');
|
||||||
include(PATH_KERNEL.'tag.class.php');
|
include(PATH_KERNEL.'tag.class.php');
|
||||||
|
|
|
@ -1,74 +1,5 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||||
|
|
||||||
// Returns a Page-Object, the class is page.class.php, FALSE if something fail to load the page
|
|
||||||
function buildPage($key) {
|
|
||||||
global $dbPages;
|
|
||||||
global $dbUsers;
|
|
||||||
global $dbCategories;
|
|
||||||
global $Parsedown;
|
|
||||||
global $site;
|
|
||||||
|
|
||||||
if (empty($key)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Page object, content from index.txt file
|
|
||||||
$page = new Page($key);
|
|
||||||
if (!$page->isValid()) {
|
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the database from dbPages
|
|
||||||
$db = $dbPages->getPageDB($key);
|
|
||||||
if (!$db) {
|
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Foreach field from database set on the object
|
|
||||||
foreach ($db as $field=>$value) {
|
|
||||||
$page->setField($field, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse Markdown
|
|
||||||
$contentRaw = $page->contentRaw();
|
|
||||||
$content = Text::pre2htmlentities($contentRaw); // Parse pre code with htmlentities
|
|
||||||
$parsedown = new Parsedown();
|
|
||||||
$content = $parsedown->text($content); // Parse Markdown
|
|
||||||
$content = Text::imgRel2Abs($content, DOMAIN_UPLOADS); // Parse img src relative to absolute (with domain)
|
|
||||||
$page->setField('content', $content, true);
|
|
||||||
|
|
||||||
// Pagebrake
|
|
||||||
$explode = explode(PAGE_BREAK, $content);
|
|
||||||
$page->setField('contentBreak', $explode[0], true);
|
|
||||||
$page->setField('readMore', !empty($explode[1]), true);
|
|
||||||
|
|
||||||
// Date format
|
|
||||||
$pageDate = $page->date();
|
|
||||||
$page->setField('dateRaw', $pageDate, true);
|
|
||||||
|
|
||||||
$pageDateFormated = $page->dateRaw( $site->dateFormat() );
|
|
||||||
$page->setField('date', $pageDateFormated, true);
|
|
||||||
|
|
||||||
// Generate and set the User object
|
|
||||||
$username = $page->username();
|
|
||||||
$page->setField('user', $dbUsers->getUser($username));
|
|
||||||
|
|
||||||
// Category
|
|
||||||
$categoryKey = $page->categoryKey();
|
|
||||||
$page->setField('categoryMap', $dbCategories->getMap($categoryKey));
|
|
||||||
|
|
||||||
// Get the keys of the child
|
|
||||||
$page->setField('childrenKeys', $dbPages->getChildren($key));
|
|
||||||
|
|
||||||
// Set previous and next page key
|
|
||||||
$page->setField('previousKey', $dbPages->previousPageKey($key));
|
|
||||||
$page->setField('nextKey', $dbPages->nextPageKey($key));
|
|
||||||
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-index database of categories
|
// Re-index database of categories
|
||||||
// If you create/edit/remove a page is necessary regenerate the database of categories
|
// If you create/edit/remove a page is necessary regenerate the database of categories
|
||||||
function reindexCategories() {
|
function reindexCategories() {
|
||||||
|
@ -203,11 +134,11 @@ function buildStaticPages() {
|
||||||
global $dbPages;
|
global $dbPages;
|
||||||
|
|
||||||
$list = array();
|
$list = array();
|
||||||
$staticPages = $dbPages->getStaticDB();
|
$pagesKey = $dbPages->getStaticDB();
|
||||||
foreach ($staticPages as $staticPageKey) {
|
foreach ($pagesKey as $pageKey) {
|
||||||
try {
|
try {
|
||||||
$staticPage = new PageX($staticPageKey);
|
$page = new PageX($pageKey);
|
||||||
array_push($list, $staticPage);
|
array_push($list, $page);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
|
@ -224,86 +155,17 @@ function buildParentPages() {
|
||||||
$list = array();
|
$list = array();
|
||||||
$pagesKey = $dbPages->getPublishedDB();
|
$pagesKey = $dbPages->getPublishedDB();
|
||||||
foreach ($pagesKey as $pageKey) {
|
foreach ($pagesKey as $pageKey) {
|
||||||
$page = buildPage($pageKey);
|
try {
|
||||||
if ($page->isParent()) {
|
$page = new PageX($pageKey);
|
||||||
array_push($list, $page);
|
array_push($list, $page);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED
|
|
||||||
// Generate the global variable $pagesByParent, defined on 69.pages.php
|
|
||||||
function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
|
||||||
global $dbPages;
|
|
||||||
global $pagesByParent;
|
|
||||||
global $pagesByParentByKey;
|
|
||||||
|
|
||||||
$onlyKeys = true;
|
|
||||||
$keys = array();
|
|
||||||
if ($publishedPages) {
|
|
||||||
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($keys as $pageKey) {
|
|
||||||
$page = buildPage($pageKey);
|
|
||||||
if ($page!==false) {
|
|
||||||
$parentKey = $page->parentKey();
|
|
||||||
// FALSE if the page is parent
|
|
||||||
if ($parentKey===false) {
|
|
||||||
array_push($pagesByParent[PARENT], $page);
|
|
||||||
$pagesByParentByKey[PARENT][$page->key()] = $page;
|
|
||||||
} else {
|
|
||||||
if (!isset($pagesByParent[$parentKey])) {
|
|
||||||
$pagesByParent[$parentKey] = array();
|
|
||||||
}
|
|
||||||
array_push($pagesByParent[$parentKey], $page);
|
|
||||||
$pagesByParentByKey[$parentKey][$page->key()] = $page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEPRECATED
|
|
||||||
// Returns an Array with all pages existing on the system
|
|
||||||
/*
|
|
||||||
array(
|
|
||||||
pageKey1 => Page object,
|
|
||||||
pageKey2 => Page object,
|
|
||||||
...
|
|
||||||
pageKeyN => Page object,
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true, $scheduledPages=true) {
|
|
||||||
global $dbPages;
|
|
||||||
|
|
||||||
// Get DB
|
|
||||||
$onlyKeys = true;
|
|
||||||
$keys = array();
|
|
||||||
if ($publishedPages) {
|
|
||||||
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
|
|
||||||
}
|
|
||||||
if ($staticPages) {
|
|
||||||
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
|
|
||||||
}
|
|
||||||
if ($draftPages) {
|
|
||||||
$keys = array_merge($keys, $dbPages->getDraftDB($onlyKeys));
|
|
||||||
}
|
|
||||||
if ($scheduledPages) {
|
|
||||||
$keys = array_merge($keys, $dbPages->getScheduledDB($onlyKeys));
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp = array();
|
|
||||||
foreach ($keys as $pageKey) {
|
|
||||||
$page = buildPage($pageKey);
|
|
||||||
if ($page!==false) {
|
|
||||||
$tmp[$page->key()] = $page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the Plugin-Object if is enabled and installed, FALSE otherwise
|
// Returns the Plugin-Object if is enabled and installed, FALSE otherwise
|
||||||
function getPlugin($pluginClassName) {
|
function getPlugin($pluginClassName) {
|
||||||
global $plugins;
|
global $plugins;
|
||||||
|
@ -472,12 +334,16 @@ function editPage($args) {
|
||||||
|
|
||||||
// Title and content need to be here because from inside the dbPages is not visible
|
// Title and content need to be here because from inside the dbPages is not visible
|
||||||
if (empty($args['title']) || empty($args['content'])) {
|
if (empty($args['title']) || empty($args['content'])) {
|
||||||
$page = buildPage($args['key']);
|
try {
|
||||||
if (empty($args['title'])) {
|
$page = new PageX($args['key']);
|
||||||
$args['title'] = $page->title();
|
if (empty($args['title'])) {
|
||||||
}
|
$args['title'] = $page->title();
|
||||||
if (empty($args['content'])) {
|
}
|
||||||
$args['content'] = $page->contentRaw();
|
if (empty($args['content'])) {
|
||||||
|
$args['content'] = $page->contentRaw();
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Paginator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the absolute URL for the previous page
|
// Returns the absolute URL for the previous page
|
||||||
public static function prevPageUrl()
|
public static function previousPageUrl()
|
||||||
{
|
{
|
||||||
return self::numberUrl( self::prevPage() );
|
return self::numberUrl( self::prevPage() );
|
||||||
}
|
}
|
||||||
|
@ -93,13 +93,13 @@ class Paginator {
|
||||||
$filter = trim($url->activeFilter(), '/');
|
$filter = trim($url->activeFilter(), '/');
|
||||||
|
|
||||||
if(empty($filter)) {
|
if(empty($filter)) {
|
||||||
$url = $domain.'/'.$url->slug();
|
$uri = $domain.'/'.$url->slug();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$url = $domain.'/'.$filter.'/'.$url->slug();
|
$uri = $domain.'/'.$filter.'/'.$url->slug();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url.'?page='.$pageNumber;
|
return $uri.'?page='.$pageNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function html($textPrevPage=false, $textNextPage=false, $showPageNumber=false)
|
public static function html($textPrevPage=false, $textNextPage=false, $showPageNumber=false)
|
||||||
|
@ -131,7 +131,7 @@ class Paginator {
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '<li class="right">';
|
$html .= '<li class="right">';
|
||||||
$html .= '<a href="'.self::prevPageUrl().'">'.$textNextPage.'</a>';
|
$html .= '<a href="'.self::previousPageUrl().'">'.$textNextPage.'</a>';
|
||||||
$html .= '</li>';
|
$html .= '</li>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,598 +0,0 @@
|
||||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
||||||
|
|
||||||
class Page {
|
|
||||||
|
|
||||||
private $vars;
|
|
||||||
|
|
||||||
function __construct($key)
|
|
||||||
{
|
|
||||||
$this->vars = false;
|
|
||||||
|
|
||||||
if ($this->build($key)) {
|
|
||||||
$this->vars['key'] = $key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the content from the file index.txt
|
|
||||||
private function build($key)
|
|
||||||
{
|
|
||||||
$filePath = PATH_PAGES.$key.DS.FILENAME;
|
|
||||||
|
|
||||||
// Check if the file exists
|
|
||||||
if (!Sanitize::pathFile($filePath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmp = 0;
|
|
||||||
$file = file($filePath);
|
|
||||||
foreach ($file as $lineNumber=>$line) {
|
|
||||||
// Split the line in 2 parts, limiter by :
|
|
||||||
$parts = explode(':', $line, 2);
|
|
||||||
|
|
||||||
$field = $parts[0]; // title, date, slug
|
|
||||||
$value = isset($parts[1])?$parts[1]:false; // value of title, value of date
|
|
||||||
|
|
||||||
// Remove all characters except letters and dash - from field
|
|
||||||
$field = preg_replace('/[^A-Za-z\-]/', '', $field);
|
|
||||||
|
|
||||||
// Field to lowercase
|
|
||||||
$field = Text::lowercase($field);
|
|
||||||
|
|
||||||
// Check if the current line start the content of the page
|
|
||||||
// We have two breakers, the word content or 3 dash ---
|
|
||||||
if ($field==='content') {
|
|
||||||
$tmp = $lineNumber;
|
|
||||||
$styleTypeUsed = 'Content:';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($field==='---') {
|
|
||||||
$tmp = $lineNumber;
|
|
||||||
$styleTypeUsed = '---';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($field) && !empty($value)) {
|
|
||||||
// Remove missing dashs -
|
|
||||||
$field = preg_replace('/[^A-Za-z]/', '', $field);
|
|
||||||
|
|
||||||
// Remove <-- and -->
|
|
||||||
$value = preg_replace('/<\-\-/', '', $value);
|
|
||||||
$value = preg_replace('/\-\->/', '', $value);
|
|
||||||
|
|
||||||
// Remove empty spaces on borders
|
|
||||||
$value = trim($value);
|
|
||||||
|
|
||||||
// Position accepts only integers
|
|
||||||
if ($field=='position') {
|
|
||||||
$value = preg_replace('/[^0-9]/', '', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize all fields, except the content
|
|
||||||
$this->vars[$field] = Sanitize::html($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process the content
|
|
||||||
if ($tmp!==0) {
|
|
||||||
// Get all lines starting from "Content:" or "---"
|
|
||||||
$content = array_slice($file, $tmp);
|
|
||||||
|
|
||||||
// Remove "Content:" or "---" and keep next characters if there are
|
|
||||||
$content[0] = substr($content[0], strpos($content[0], $styleTypeUsed) + strlen($styleTypeUsed));
|
|
||||||
|
|
||||||
$content[0] = ltrim($content[0]);
|
|
||||||
|
|
||||||
// Join lines in one variable, this is RAW content from file
|
|
||||||
$this->vars['contentRaw'] = implode($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns TRUE if the content is loaded correctly, FALSE otherwise
|
|
||||||
public function isValid()
|
|
||||||
{
|
|
||||||
return $this->vars!==false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEPRACTED
|
|
||||||
// Returns the value from the $field, FALSE if the field doesn't exist
|
|
||||||
public function getField($field)
|
|
||||||
{
|
|
||||||
if(isset($this->vars[$field])) {
|
|
||||||
return $this->vars[$field];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getValue($field)
|
|
||||||
{
|
|
||||||
if(isset($this->vars[$field])) {
|
|
||||||
return $this->vars[$field];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDB()
|
|
||||||
{
|
|
||||||
return $this->vars;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a field with a value
|
|
||||||
public function setField($field, $value, $overwrite=true)
|
|
||||||
{
|
|
||||||
if($overwrite || empty($this->vars[$field])) {
|
|
||||||
$this->vars[$field] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 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->getValue('content');
|
|
||||||
|
|
||||||
if(!$fullContent) {
|
|
||||||
return $this->contentBreak();
|
|
||||||
}
|
|
||||||
|
|
||||||
if($noSanitize) {
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Sanitize::html($content);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function contentBreak()
|
|
||||||
{
|
|
||||||
return $this->getValue('contentBreak');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the raw content
|
|
||||||
// This content is not markdown parser
|
|
||||||
// (boolean) $sanitize, TRUE returns the content sanitized
|
|
||||||
public function contentRaw($sanitize=false)
|
|
||||||
{
|
|
||||||
// This content is not sanitized.
|
|
||||||
$content = $this->getValue('contentRaw');
|
|
||||||
if ($sanitize) {
|
|
||||||
return Sanitize::html($content);
|
|
||||||
}
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the date according to locale settings and format settings
|
|
||||||
public function date()
|
|
||||||
{
|
|
||||||
return $this->getValue('date');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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->getValue('dateRaw');
|
|
||||||
|
|
||||||
if($format) {
|
|
||||||
return Date::format($date, DB_DATE_FORMAT, $format);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $date;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the date according to locale settings and format settings
|
|
||||||
public function dateModified()
|
|
||||||
{
|
|
||||||
return $this->getValue('dateModified');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the permalink
|
|
||||||
// (boolean) $absolute, TRUE returns the page link with the DOMAIN, FALSE without the DOMAIN
|
|
||||||
public function permalink($absolute=true)
|
|
||||||
{
|
|
||||||
// Get the key of the page
|
|
||||||
$key = $this->getValue('key');
|
|
||||||
|
|
||||||
if($absolute) {
|
|
||||||
return DOMAIN_PAGES.$key;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HTML_PATH_ROOT.PAGE_URI_FILTER.$key;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the previous page key
|
|
||||||
public function previousKey()
|
|
||||||
{
|
|
||||||
return $this->getValue('previousKey');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the next page key
|
|
||||||
public function nextKey()
|
|
||||||
{
|
|
||||||
return $this->getValue('nextKey');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the category name
|
|
||||||
public function category()
|
|
||||||
{
|
|
||||||
return $this->categoryMap('name');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the category name
|
|
||||||
public function categoryTemplate()
|
|
||||||
{
|
|
||||||
return $this->categoryMap('template');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the category key
|
|
||||||
public function categoryKey()
|
|
||||||
{
|
|
||||||
return $this->getValue('category');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the category permalink
|
|
||||||
public function categoryPermalink()
|
|
||||||
{
|
|
||||||
return DOMAIN_CATEGORIES.$this->categoryKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the field from the array
|
|
||||||
// categoryMap = array( 'name'=>'', 'list'=>array() )
|
|
||||||
public function categoryMap($field)
|
|
||||||
{
|
|
||||||
$map = $this->getValue('categoryMap');
|
|
||||||
|
|
||||||
if($field=='key') {
|
|
||||||
return $this->categoryKey();
|
|
||||||
}
|
|
||||||
elseif($field=='name') {
|
|
||||||
return $map['name'];
|
|
||||||
}
|
|
||||||
elseif($field=='list') {
|
|
||||||
return $map['list'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
$User = $this->getValue('user');
|
|
||||||
|
|
||||||
if($field) {
|
|
||||||
return $User->getField($field);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $User;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the username who created the post/page
|
|
||||||
public function username()
|
|
||||||
{
|
|
||||||
return $this->getValue('username');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function template()
|
|
||||||
{
|
|
||||||
return $this->getValue('template');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the description field
|
|
||||||
public function description()
|
|
||||||
{
|
|
||||||
return $this->getValue('description');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the tags separated by comma
|
|
||||||
// (boolean) $returnsArray, TRUE to get the tags as an array, FALSE to get the tags separeted by comma
|
|
||||||
public function tags($returnsArray=false)
|
|
||||||
{
|
|
||||||
$tags = $this->getValue('tags');
|
|
||||||
|
|
||||||
if($returnsArray) {
|
|
||||||
if($tags==false) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
return $tags;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if($tags==false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Return string with tags separeted by comma.
|
|
||||||
return implode(', ', $tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function json($returnsArray=false)
|
|
||||||
{
|
|
||||||
$tmp['key'] = $this->key();
|
|
||||||
$tmp['title'] = $this->title();
|
|
||||||
$tmp['content'] = $this->content(); // Markdown parsed
|
|
||||||
$tmp['contentRaw'] = $this->contentRaw(true); // No Markdown parsed
|
|
||||||
$tmp['description'] = $this->description();
|
|
||||||
$tmp['date'] = $this->dateRaw();
|
|
||||||
$tmp['dateUTC'] = Date::convertToUTC($this->dateRaw(), DB_DATE_FORMAT, DB_DATE_FORMAT);
|
|
||||||
$tmp['permalink'] = $this->permalink(true);
|
|
||||||
$tmp['coverImage'] = $this->coverImage(true);
|
|
||||||
$tmp['coverImageFilename'] = $this->coverImage(false);
|
|
||||||
|
|
||||||
if ($returnsArray) {
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_encode($tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the file name, FALSE there isn't a cover image setted
|
|
||||||
// If the user defined an External Cover Image the complete URL is going to be returned
|
|
||||||
// (boolean) $absolute, TRUE returns the absolute path and file name, FALSE just the file name
|
|
||||||
public function coverImage($absolute=true)
|
|
||||||
{
|
|
||||||
$fileName = $this->getValue('coverImage');
|
|
||||||
if (empty($fileName)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if external cover image, is a valid URL
|
|
||||||
if (filter_var($fileName, FILTER_VALIDATE_URL)) {
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($absolute) {
|
|
||||||
return DOMAIN_UPLOADS.$fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the absolute URL of the thumbnail of the cover image, FALSE if the page doen't have cover image
|
|
||||||
public function thumbCoverImage()
|
|
||||||
{
|
|
||||||
$coverImageFilename = $this->coverImage(false);
|
|
||||||
if ($coverImageFilename==false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return DOMAIN_UPLOADS_THUMBNAILS.$coverImageFilename;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns TRUE if the content has the text splited
|
|
||||||
public function readMore()
|
|
||||||
{
|
|
||||||
return $this->getValue('readMore');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function uuid()
|
|
||||||
{
|
|
||||||
return $this->getValue('uuid');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the field key
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
return $this->getValue('key');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (boolean) Returns TRUE if the page is published, FALSE otherwise
|
|
||||||
public function published()
|
|
||||||
{
|
|
||||||
return ($this->getValue('status')==='published');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (boolean) Returns TRUE if the page is scheduled, FALSE otherwise
|
|
||||||
public function scheduled()
|
|
||||||
{
|
|
||||||
return ($this->getValue('status')==='scheduled');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (boolean) Returns TRUE if the page is draft, FALSE otherwise
|
|
||||||
public function draft()
|
|
||||||
{
|
|
||||||
return ($this->getValue('status')=='draft');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (boolean) Returns TRUE if the page is sticky, FALSE otherwise
|
|
||||||
public function sticky()
|
|
||||||
{
|
|
||||||
return ($this->getValue('status')=='sticky');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (boolean) Returns TRUE if the page is static, FALSE otherwise
|
|
||||||
public function isStatic()
|
|
||||||
{
|
|
||||||
return ($this->getValue('status')=='static');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (string) Returns status of the page
|
|
||||||
public function status()
|
|
||||||
{
|
|
||||||
return $this->getValue('status');
|
|
||||||
}
|
|
||||||
|
|
||||||
// (string) Returns type of the page
|
|
||||||
public function type()
|
|
||||||
{
|
|
||||||
return $this->status();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the title field
|
|
||||||
public function title()
|
|
||||||
{
|
|
||||||
return $this->getValue('title');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns TRUE if the page has enabled the comments, FALSE otherwise
|
|
||||||
public function allowComments()
|
|
||||||
{
|
|
||||||
return $this->getValue('allowComments');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the page position
|
|
||||||
public function position()
|
|
||||||
{
|
|
||||||
return $this->getValue('position');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the page noindex
|
|
||||||
public function noindex()
|
|
||||||
{
|
|
||||||
return $this->getValue('noindex');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the page nofollow
|
|
||||||
public function nofollow()
|
|
||||||
{
|
|
||||||
return $this->getValue('nofollow');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the page noarchive
|
|
||||||
public function noarchive()
|
|
||||||
{
|
|
||||||
return $this->getValue('noarchive');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the page slug
|
|
||||||
public function slug()
|
|
||||||
{
|
|
||||||
$explode = explode('/', $this->getValue('key'));
|
|
||||||
|
|
||||||
// Check if the page have a parent.
|
|
||||||
if (!empty($explode[1])) {
|
|
||||||
return $explode[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $explode[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the parent key, if the page doesn't have a parent returns FALSE
|
|
||||||
public function parent()
|
|
||||||
{
|
|
||||||
return $this->parentKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the parent key, if the page doesn't have a parent returns FALSE
|
|
||||||
public function parentKey()
|
|
||||||
{
|
|
||||||
$explode = explode('/', $this->getValue('key'));
|
|
||||||
if (isset($explode[1])) {
|
|
||||||
return $explode[0];
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns TRUE if the page is a parent, has or not children
|
|
||||||
public function isParent()
|
|
||||||
{
|
|
||||||
return $this->parentKey()===false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the parent method output, if the page doesn't have a parent returns FALSE
|
|
||||||
public function parentMethod($method)
|
|
||||||
{
|
|
||||||
$parentKey = $this->parentKey();
|
|
||||||
if ($parentKey) {
|
|
||||||
$page = buildPage($parentKey);
|
|
||||||
return $page->{$method}();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns TRUE if the page is a child, FALSE otherwise
|
|
||||||
public function isChild()
|
|
||||||
{
|
|
||||||
return $this->parentKey()!==false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns TRUE if the page has children
|
|
||||||
public function hasChildren()
|
|
||||||
{
|
|
||||||
$childrenKeys = $this->childrenKeys();
|
|
||||||
return !empty($childrenKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an array with all children's keys
|
|
||||||
public function childrenKeys()
|
|
||||||
{
|
|
||||||
return $this->getValue('childrenKeys');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns an array with all children as Page-Object
|
|
||||||
public function children()
|
|
||||||
{
|
|
||||||
$list = array();
|
|
||||||
$childrenKeys = $this->getValue('childrenKeys');
|
|
||||||
foreach ($childrenKeys as $childKey) {
|
|
||||||
$child = buildPage($childKey);
|
|
||||||
array_push($list, $child);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the amount of minutes takes to read the page
|
|
||||||
public function readingTime() {
|
|
||||||
global $Language;
|
|
||||||
|
|
||||||
$words = $this->content(true);
|
|
||||||
$words = strip_tags($words);
|
|
||||||
$words = str_word_count($words);
|
|
||||||
$average = $words / 200;
|
|
||||||
$minutes = round($average);
|
|
||||||
|
|
||||||
if ($minutes>0) {
|
|
||||||
return $minutes.' '.$Language->get('minutes');
|
|
||||||
}
|
|
||||||
|
|
||||||
return '~1 '.$Language->get('minute');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns relative time (e.g. "1 minute ago")
|
|
||||||
// Based on http://stackoverflow.com/a/18602474
|
|
||||||
// Modified for Bludit
|
|
||||||
// $complete = false : short version
|
|
||||||
// $complete = true : full version
|
|
||||||
public function relativeTime($complete = false) {
|
|
||||||
$current = new DateTime;
|
|
||||||
$past = new DateTime($this->getValue('date'));
|
|
||||||
$elapsed = $current->diff($past);
|
|
||||||
|
|
||||||
$elapsed->w = floor($elapsed->d / 7);
|
|
||||||
$elapsed->d -= $elapsed->w * 7;
|
|
||||||
|
|
||||||
$string = array(
|
|
||||||
'y' => 'year',
|
|
||||||
'm' => 'month',
|
|
||||||
'w' => 'week',
|
|
||||||
'd' => 'day',
|
|
||||||
'h' => 'hour',
|
|
||||||
'i' => 'minute',
|
|
||||||
's' => 'second',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach($string as $key => &$value) {
|
|
||||||
if($elapsed->$key) {
|
|
||||||
$value = $elapsed->$key . ' ' . $value . ($elapsed->$key > 1 ? 's' : ' ');
|
|
||||||
} else {
|
|
||||||
unset($string[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$complete) {
|
|
||||||
$string = array_slice($string, 0 , 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $string ? implode(', ', $string) . ' ago' : 'Just now';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -427,8 +427,12 @@ class PageX {
|
||||||
{
|
{
|
||||||
$parentKey = $this->parentKey();
|
$parentKey = $this->parentKey();
|
||||||
if ($parentKey) {
|
if ($parentKey) {
|
||||||
$page = buildPage($parentKey);
|
try {
|
||||||
return $page->{$method}();
|
$page = new PageX($parentKey);
|
||||||
|
return $page->{$method}();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continoue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -462,8 +466,12 @@ class PageX {
|
||||||
$list = array();
|
$list = array();
|
||||||
$childrenKeys = $dbPages->getChildren($this->key());
|
$childrenKeys = $dbPages->getChildren($this->key());
|
||||||
foreach ($childrenKeys as $childKey) {
|
foreach ($childrenKeys as $childKey) {
|
||||||
$child = buildPage($childKey);
|
try {
|
||||||
array_push($list, $child);
|
$child = new PageX($childKey);
|
||||||
|
array_push($list, $child);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
|
|
|
@ -250,9 +250,13 @@ class pluginAPI extends Plugin {
|
||||||
|
|
||||||
// Get keys of pages
|
// Get keys of pages
|
||||||
foreach ($list as $pageKey) {
|
foreach ($list as $pageKey) {
|
||||||
// Create the page object from the page key
|
try {
|
||||||
$page = buildPage($pageKey);
|
// Create the page object from the page key
|
||||||
array_push($tmp['data'], $page->json( $returnsArray=true ));
|
$page = new PageX($pageKey);
|
||||||
|
array_push($tmp['data'], $page->json( $returnsArray=true ));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
@ -260,21 +264,19 @@ class pluginAPI extends Plugin {
|
||||||
|
|
||||||
private function getPage($key)
|
private function getPage($key)
|
||||||
{
|
{
|
||||||
// Generate the object Page
|
try {
|
||||||
$page = buildPage($key);
|
$page = new PageX($key);
|
||||||
|
return array(
|
||||||
if (!$page) {
|
'status'=>'0',
|
||||||
|
'message'=>'Page filtered by key: '.$key,
|
||||||
|
'data'=>$page->json( $returnsArray=true )
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
return array(
|
return array(
|
||||||
'status'=>'1',
|
'status'=>'1',
|
||||||
'message'=>'Page not found.'
|
'message'=>'Page not found.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
|
||||||
'status'=>'0',
|
|
||||||
'message'=>'Page filtered by key: '.$key,
|
|
||||||
'data'=>$page->json( $returnsArray=true )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createPage($args)
|
private function createPage($args)
|
||||||
|
|
|
@ -104,10 +104,14 @@ class pluginNavigation extends Plugin {
|
||||||
$publishedPages = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
$publishedPages = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
||||||
|
|
||||||
foreach ($publishedPages as $pageKey) {
|
foreach ($publishedPages as $pageKey) {
|
||||||
$page = buildPage($pageKey);
|
try {
|
||||||
$html .= '<li>';
|
$page = new PageX($pageKey);
|
||||||
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
|
$html .= '<li>';
|
||||||
$html .= '</li>';
|
$html .= '<a href="' . $page->permalink() . '">' . $page->title() . '</a>';
|
||||||
|
$html .= '</li>';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,15 +60,19 @@ class pluginRSS extends Plugin {
|
||||||
|
|
||||||
// Get keys of pages
|
// Get keys of pages
|
||||||
foreach($list as $pageKey) {
|
foreach($list as $pageKey) {
|
||||||
// Create the page object from the page key
|
try {
|
||||||
$page = buildPage($pageKey);
|
// Create the page object from the page key
|
||||||
$xml .= '<item>';
|
$page = new PageX($pageKey);
|
||||||
$xml .= '<title>'.$page->title().'</title>';
|
$xml .= '<item>';
|
||||||
$xml .= '<link>'.$page->permalink().'</link>';
|
$xml .= '<title>'.$page->title().'</title>';
|
||||||
$xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>';
|
$xml .= '<link>'.$page->permalink().'</link>';
|
||||||
$xml .= '<pubDate>'.$page->dateRaw('r').'</pubDate>';
|
$xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>';
|
||||||
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';
|
$xml .= '<pubDate>'.$page->dateRaw('r').'</pubDate>';
|
||||||
$xml .= '</item>';
|
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';
|
||||||
|
$xml .= '</item>';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml .= '</channel></rss>';
|
$xml .= '</channel></rss>';
|
||||||
|
|
|
@ -39,14 +39,17 @@ class pluginSitemap extends Plugin {
|
||||||
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
||||||
|
|
||||||
foreach($list as $pageKey) {
|
foreach($list as $pageKey) {
|
||||||
// Create the page object from the page key
|
try {
|
||||||
$page = buildPage($pageKey);
|
// Create the page object from the page key
|
||||||
|
$page = new PageX($pageKey);
|
||||||
$xml .= '<url>';
|
$xml .= '<url>';
|
||||||
$xml .= '<loc>'.$page->permalink().'</loc>';
|
$xml .= '<loc>'.$page->permalink().'</loc>';
|
||||||
$xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>';
|
$xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>';
|
||||||
$xml .= '<changefreq>daily</changefreq>';
|
$xml .= '<changefreq>daily</changefreq>';
|
||||||
$xml .= '</url>';
|
$xml .= '</url>';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml .= '</urlset>';
|
$xml .= '</urlset>';
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
|
|
||||||
<!-- Previous button -->
|
<!-- Previous button -->
|
||||||
<li class="page-item <?php if (!Paginator::showPrev()) echo 'disabled' ?>">
|
<li class="page-item <?php if (!Paginator::showPrev()) echo 'disabled' ?>">
|
||||||
<a class="page-link" href="<?php echo Paginator::prevPageUrl() ?>" tabindex="-1"><?php echo $Language->get('Previous'); ?></a>
|
<a class="page-link" href="<?php echo Paginator::previousPageUrl() ?>" tabindex="-1"><?php echo $Language->get('Previous'); ?></a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- List of pages -->
|
<!-- List of pages -->
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
|
|
||||||
<!-- Previous button -->
|
<!-- Previous button -->
|
||||||
<li class="page-item <?php if (!Paginator::showPrev()) echo 'disabled' ?>">
|
<li class="page-item <?php if (!Paginator::showPrev()) echo 'disabled' ?>">
|
||||||
<a class="page-link" href="<?php echo Paginator::prevPageUrl() ?>" tabindex="-1"><?php echo $Language->get('Previous'); ?></a>
|
<a class="page-link" href="<?php echo Paginator::previousPageUrl() ?>" tabindex="-1"><?php echo $Language->get('Previous'); ?></a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- List of pages -->
|
<!-- List of pages -->
|
||||||
|
|
Loading…
Reference in New Issue