2016-05-29 19:21:11 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2017-05-09 00:24:15 +02:00
|
|
|
function buildPage($key)
|
|
|
|
{
|
|
|
|
global $dbPages;
|
|
|
|
global $dbUsers;
|
2017-05-17 00:04:53 +02:00
|
|
|
global $dbCategories;
|
2017-05-09 00:24:15 +02:00
|
|
|
global $Parsedown;
|
|
|
|
global $Site;
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Page object, content from index.txt file
|
|
|
|
$page = new Page($key);
|
|
|
|
if( !$page->isValid() ) {
|
2017-05-09 00:24:15 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Get the database from dbPages
|
2017-05-09 00:24:15 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Foreach field from database set on the object
|
2017-05-09 00:24:15 +02:00
|
|
|
foreach($db as $field=>$value) {
|
2017-05-10 20:40:28 +02:00
|
|
|
$page->setField($field, $value);
|
2017-05-09 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Parse Markdown
|
|
|
|
$contentRaw = $page->contentRaw();
|
2017-05-09 00:24:15 +02:00
|
|
|
$content = Text::pre2htmlentities($contentRaw); // Parse pre code with htmlentities
|
2017-05-10 20:40:28 +02:00
|
|
|
$content = $Parsedown->text($content); // Parse Markdown
|
2017-05-09 00:24:15 +02:00
|
|
|
$content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS); // Parse img src relative to absolute.
|
2017-05-10 20:40:28 +02:00
|
|
|
$page->setField('content', $content, true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
|
|
|
// Pagebrake
|
|
|
|
$explode = explode(PAGE_BREAK, $content);
|
2017-05-10 20:40:28 +02:00
|
|
|
$page->setField('contentBreak', $explode[0], true);
|
|
|
|
$page->setField('readMore', !empty($explode[1]), true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
|
|
|
// Date format
|
2017-05-10 20:40:28 +02:00
|
|
|
$pageDate = $page->date();
|
|
|
|
$page->setField('dateRaw', $pageDate, true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
$pageDateFormated = $page->dateRaw( $Site->dateFormat() );
|
|
|
|
$page->setField('date', $pageDateFormated, true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Generate and set the User object
|
|
|
|
$username = $page->username();
|
|
|
|
$page->setField('user', $dbUsers->getUser($username));
|
2017-05-09 00:24:15 +02:00
|
|
|
|
2017-05-17 00:04:53 +02:00
|
|
|
// Category
|
|
|
|
$categoryKey = $page->categoryKey();
|
|
|
|
$page->setField('categoryMap', $dbCategories->getMap($categoryKey));
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
return $page;
|
2017-05-09 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
function reindexCategories()
|
2016-05-29 19:21:11 +02:00
|
|
|
{
|
2017-05-10 20:40:28 +02:00
|
|
|
global $dbPages;
|
|
|
|
global $dbCategories;
|
2016-05-29 19:21:11 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Get a database with published pages
|
|
|
|
$db = $dbPages->getPublishedDB();
|
2016-05-29 19:21:11 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Regenerate the tags
|
|
|
|
$dbCategories->reindex($db);
|
2016-05-29 19:21:11 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
function reindexTags()
|
2017-03-26 20:51:32 +02:00
|
|
|
{
|
2017-05-10 20:40:28 +02:00
|
|
|
global $dbPages;
|
2017-05-21 22:01:44 +02:00
|
|
|
global $dbTags;
|
2017-03-26 20:51:32 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Get a database with published pages
|
|
|
|
$db = $dbPages->getPublishedDB();
|
2017-03-26 20:51:32 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Regenerate the tags
|
|
|
|
$dbTags->reindex($db);
|
2017-03-26 20:51:32 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-10 23:21:45 +02:00
|
|
|
function buildPagesForAdmin()
|
|
|
|
{
|
|
|
|
return buildPagesFor('admin');
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildPagesForHome()
|
2016-05-29 19:21:11 +02:00
|
|
|
{
|
2017-05-10 23:21:45 +02:00
|
|
|
return buildPagesFor('home');
|
2017-05-10 20:40:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:18:44 +02:00
|
|
|
function buildPagesByCategory()
|
2017-05-10 20:40:28 +02:00
|
|
|
{
|
2017-05-12 20:18:44 +02:00
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$categoryKey = $Url->slug();
|
2017-05-10 23:21:45 +02:00
|
|
|
return buildPagesFor('category', $categoryKey, false);
|
2017-05-10 20:40:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:18:44 +02:00
|
|
|
function buildPagesByTag()
|
2017-05-10 23:21:45 +02:00
|
|
|
{
|
2017-05-12 20:18:44 +02:00
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$tagKey = $Url->slug();
|
2017-05-10 23:21:45 +02:00
|
|
|
return buildPagesFor('tag', false, $tagKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildPagesFor($for, $categoryKey=false, $tagKey=false)
|
2017-05-10 20:40:28 +02:00
|
|
|
{
|
|
|
|
global $dbPages;
|
2017-05-10 23:21:45 +02:00
|
|
|
global $dbCategories;
|
2017-05-31 20:17:21 +02:00
|
|
|
global $dbTags;
|
2016-05-29 19:21:11 +02:00
|
|
|
global $Site;
|
2017-05-16 00:46:20 +02:00
|
|
|
global $Url;
|
2017-05-27 19:46:46 +02:00
|
|
|
global $pagesByKey;
|
2017-05-16 00:46:20 +02:00
|
|
|
global $pages;
|
2016-05-29 19:21:11 +02:00
|
|
|
|
2017-05-10 23:21:45 +02:00
|
|
|
// Get the page number from URL
|
|
|
|
$pageNumber = $Url->pageNumber();
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
if($for=='admin') {
|
2017-05-10 23:21:45 +02:00
|
|
|
$onlyPublished = false;
|
|
|
|
$amountOfItems = ITEMS_PER_PAGE_ADMIN;
|
2017-06-18 22:44:07 +02:00
|
|
|
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
2017-05-10 20:40:28 +02:00
|
|
|
elseif($for=='home') {
|
2017-05-10 23:21:45 +02:00
|
|
|
$onlyPublished = true;
|
2017-05-16 00:46:20 +02:00
|
|
|
$amountOfItems = $Site->itemsPerPage();
|
2017-06-18 22:44:07 +02:00
|
|
|
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
2017-05-10 23:21:45 +02:00
|
|
|
}
|
|
|
|
elseif($for=='category') {
|
2017-05-16 00:46:20 +02:00
|
|
|
$amountOfItems = $Site->itemsPerPage();
|
2017-05-10 23:21:45 +02:00
|
|
|
$list = $dbCategories->getList($categoryKey, $pageNumber, $amountOfItems);
|
|
|
|
}
|
|
|
|
elseif($for=='tag') {
|
2017-05-16 00:46:20 +02:00
|
|
|
$amountOfItems = $Site->itemsPerPage();
|
2017-05-10 23:21:45 +02:00
|
|
|
$list = $dbTags->getList($tagKey, $pageNumber, $amountOfItems);
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// There are not items for the page number then set the page notfound
|
2017-05-24 00:48:29 +02:00
|
|
|
if( empty($list) && $pageNumber>1 ) {
|
2017-05-10 20:40:28 +02:00
|
|
|
$Url->setNotFound(true);
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 00:46:20 +02:00
|
|
|
$pages = array(); // global variable
|
2017-05-27 19:46:46 +02:00
|
|
|
$pagesByKey = array(); // global variable
|
2017-05-10 20:40:28 +02:00
|
|
|
foreach($list as $pageKey=>$fields) {
|
|
|
|
$page = buildPage($pageKey);
|
|
|
|
if($page!==false) {
|
2017-05-27 19:46:46 +02:00
|
|
|
// $pagesByKey
|
|
|
|
$pagesByKey[$pageKey] = $page;
|
2017-05-16 00:46:20 +02:00
|
|
|
// $pages
|
2017-05-10 20:40:28 +02:00
|
|
|
array_push($pages, $page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $pages;
|
|
|
|
}
|
2017-06-04 22:08:20 +02:00
|
|
|
|
2017-06-09 20:30:13 +02:00
|
|
|
// Returns TRUE if the plugin is enabled, FALSE otherwise
|
2017-06-04 22:08:20 +02:00
|
|
|
function pluginEnabled($pluginName) {
|
|
|
|
global $plugins;
|
|
|
|
|
|
|
|
$pluginClass = 'plugin'.Text::firstCharUp($pluginName);
|
|
|
|
if( isset($plugins['all'][$pluginClass]) ) {
|
|
|
|
return $plugins['all'][$pluginClass]->installed();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2017-06-19 23:14:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function printDebug($array) {
|
|
|
|
echo '<pre>';
|
|
|
|
var_dump($array);
|
|
|
|
echo '</pre>';
|
2017-06-04 22:08:20 +02:00
|
|
|
}
|