-
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// ============================================================================
|
||||
// Variables
|
||||
// ============================================================================
|
||||
|
||||
$plugins = array(
|
||||
'siteHead'=>array(),
|
||||
'siteBodyBegin'=>array(),
|
||||
'siteBodyEnd'=>array(),
|
||||
'siteSidebar'=>array(),
|
||||
'beforeSiteLoad'=>array(),
|
||||
'afterSiteLoad'=>array(),
|
||||
|
||||
'pageBegin'=>array(),
|
||||
'pageEnd'=>array(),
|
||||
|
||||
'beforeAdminLoad'=>array(),
|
||||
'afterAdminLoad'=>array(),
|
||||
'adminHead'=>array(),
|
||||
'adminBodyBegin'=>array(),
|
||||
'adminBodyEnd'=>array(),
|
||||
'adminSidebar'=>array(),
|
||||
'adminContentSidebar'=>array(),
|
||||
'dashboard'=>array(),
|
||||
'editorToolbar'=>array(),
|
||||
|
||||
'beforeAll'=>array(),
|
||||
'afterAll'=>array(),
|
||||
|
||||
'paginator'=>array(),
|
||||
|
||||
'afterPageCreate'=>array(),
|
||||
'afterPageModify'=>array(),
|
||||
'afterPageDelete'=>array(),
|
||||
|
||||
'loginHead'=>array(),
|
||||
'loginBodyBegin'=>array(),
|
||||
'loginBodyEnd'=>array(),
|
||||
|
||||
'all'=>array()
|
||||
);
|
||||
|
||||
$pluginsEvents = $plugins;
|
||||
unset($pluginsEvents['all']);
|
||||
|
||||
$pluginsInstalled = array();
|
||||
|
||||
// ============================================================================
|
||||
// Functions
|
||||
// ============================================================================
|
||||
|
||||
function buildPlugins()
|
||||
{
|
||||
global $plugins;
|
||||
global $pluginsEvents;
|
||||
global $pluginsInstalled;
|
||||
global $L;
|
||||
global $site;
|
||||
|
||||
// Get declared clasess BEFORE load plugins clasess
|
||||
$currentDeclaredClasess = get_declared_classes();
|
||||
|
||||
// List plugins directories
|
||||
$list = Filesystem::listDirectories(PATH_PLUGINS);
|
||||
// Load each plugin clasess
|
||||
foreach ($list as $pluginPath) {
|
||||
// Check if the directory has the plugin.php
|
||||
if (file_exists($pluginPath.DS.'plugin.php')) {
|
||||
include_once($pluginPath.DS.'plugin.php');
|
||||
}
|
||||
}
|
||||
|
||||
// Get plugins clasess loaded
|
||||
$pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
|
||||
|
||||
foreach ($pluginsDeclaredClasess as $pluginClass) {
|
||||
$Plugin = new $pluginClass;
|
||||
|
||||
// Check if the plugin is translated
|
||||
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$site->language().'.json';
|
||||
if (!Sanitize::pathFile($languageFilename)) {
|
||||
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.DEFAULT_LANGUAGE_FILE;
|
||||
}
|
||||
|
||||
$database = file_get_contents($languageFilename);
|
||||
$database = json_decode($database, true);
|
||||
|
||||
// Set name and description from the language file
|
||||
$Plugin->setMetadata('name',$database['plugin-data']['name']);
|
||||
$Plugin->setMetadata('description',$database['plugin-data']['description']);
|
||||
|
||||
// Remove name and description from the language file loaded and add new words if there are
|
||||
// This function overwrite the key=>value
|
||||
unset($database['plugin-data']);
|
||||
if (!empty($database)) {
|
||||
$L->add($database);
|
||||
}
|
||||
|
||||
// $plugins['all'] Array with all plugins, installed and not installed
|
||||
$plugins['all'][$pluginClass] = $Plugin;
|
||||
|
||||
// If the plugin is installed insert on the hooks
|
||||
if ($Plugin->installed()) {
|
||||
// Include custom hooks
|
||||
if (!empty($Plugin->customHooks)) {
|
||||
foreach ($Plugin->customHooks as $customHook) {
|
||||
if (!isset($plugins[$customHook])) {
|
||||
$plugins[$customHook] = array();
|
||||
$pluginsEvents[$customHook] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pluginsInstalled[$pluginClass] = $Plugin;
|
||||
foreach ($pluginsEvents as $event=>$value) {
|
||||
if (method_exists($Plugin, $event)) {
|
||||
array_push($plugins[$event], $Plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the plugins by the position for the site sidebar
|
||||
uasort($plugins['siteSidebar'], function ($a, $b) {
|
||||
return $a->position() <=> $b->position();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main
|
||||
// ============================================================================
|
||||
|
||||
buildPlugins();
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// Redirect admin, from /admin to /admin/
|
||||
if ($url->uri()==HTML_PATH_ROOT.ADMIN_URI_FILTER) {
|
||||
Redirect::url(DOMAIN_ADMIN);
|
||||
}
|
||||
|
||||
// Redirect blog, from /blog to /blog/
|
||||
// This rule only works when the user set a page as homepage
|
||||
if ($url->uri()==HTML_PATH_ROOT.'blog' && $site->homepage()) {
|
||||
$filter = $url->filters('blog');
|
||||
$finalURL = Text::addSlashes(DOMAIN_BASE.$filter, false, true);
|
||||
Redirect::url($finalURL);
|
||||
}
|
||||
|
||||
// Redirect pages, from /my-page/ to /my-page
|
||||
if ($url->whereAmI()=='page' && !$url->notFound()) {
|
||||
$pageKey = $url->slug();
|
||||
if (Text::endsWith($pageKey, '/')) {
|
||||
$pageKey = rtrim($pageKey, '/');
|
||||
Redirect::url(DOMAIN_PAGES.$pageKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// ============================================================================
|
||||
// Variables
|
||||
// ============================================================================
|
||||
|
||||
// Array with pages, each page is a Page Object
|
||||
// Filtered by pagenumber, number of items per page and sorted by date/position
|
||||
/*
|
||||
array(
|
||||
0 => Page Object,
|
||||
1 => Page Object,
|
||||
...
|
||||
N => Page Object
|
||||
)
|
||||
*/
|
||||
$content = array();
|
||||
|
||||
// Page filtered by the user, is a Page Object
|
||||
$page = false;
|
||||
|
||||
// Array with static content, each item is a Page Object
|
||||
// Order by position
|
||||
/*
|
||||
array(
|
||||
0 => Page Object,
|
||||
1 => Page Object,
|
||||
...
|
||||
N => Page Object
|
||||
)
|
||||
*/
|
||||
$staticContent = $staticPages = buildStaticPages();
|
||||
|
||||
// ============================================================================
|
||||
// Main
|
||||
// ============================================================================
|
||||
|
||||
// Execute the scheduler
|
||||
if ($pages->scheduler()) {
|
||||
// Execute plugins with the hook afterPageCreate
|
||||
Theme::plugins('afterPageCreate');
|
||||
|
||||
reindexTags();
|
||||
reindexCategories();
|
||||
|
||||
// Add to syslog
|
||||
$syslog->add(array(
|
||||
'dictionaryKey'=>'content-published-from-scheduler',
|
||||
'notes'=>''
|
||||
));
|
||||
}
|
||||
|
||||
// Set home page if the user defined one
|
||||
if ($site->homepage() && $url->whereAmI()==='home') {
|
||||
$pageKey = $site->homepage();
|
||||
if ($pages->exists($pageKey)) {
|
||||
$url->setSlug($pageKey);
|
||||
$content[0] = $page = buildThePage();
|
||||
}
|
||||
}
|
||||
|
||||
// Build specific page
|
||||
elseif ($url->whereAmI()==='page') {
|
||||
$content[0] = $page = buildThePage();
|
||||
}
|
||||
// Build content by tag
|
||||
elseif ($url->whereAmI()==='tag') {
|
||||
$content = buildPagesByTag();
|
||||
}
|
||||
// Build content by category
|
||||
elseif ($url->whereAmI()==='category') {
|
||||
$content = buildPagesByCategory();
|
||||
}
|
||||
// Build content for the homepage
|
||||
elseif ( ($url->whereAmI()==='home') || ($url->whereAmI()==='blog') ) {
|
||||
$content = buildPagesForHome();
|
||||
}
|
||||
|
||||
if (isset($content[0])) {
|
||||
$page = $content[0];
|
||||
}
|
||||
|
||||
// If set notFound, create the page 404
|
||||
if ($url->notFound()) {
|
||||
$content[0] = $page = buildErrorPage();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
header('HTTP/1.0 '.$url->httpCode().' '.$url->httpMessage());
|
||||
header('X-Powered-By: Bludit');
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// Current page number
|
||||
$currentPage = $url->pageNumber();
|
||||
Paginator::set('currentPage', $currentPage);
|
||||
|
||||
if ($url->whereAmI()=='admin') {
|
||||
$itemsPerPage = ITEMS_PER_PAGE_ADMIN;
|
||||
$numberOfItems = $pages->count(true);
|
||||
} elseif ($url->whereAmI()=='tag') {
|
||||
$itemsPerPage = $site->itemsPerPage();
|
||||
$tagKey = $url->slug();
|
||||
$numberOfItems = $tags->numberOfPages($tagKey);
|
||||
} elseif ($url->whereAmI()=='category') {
|
||||
$itemsPerPage = $site->itemsPerPage();
|
||||
$categoryKey = $url->slug();
|
||||
$numberOfItems = $categories->numberOfPages($categoryKey);
|
||||
} else {
|
||||
$itemsPerPage = $site->itemsPerPage();
|
||||
$numberOfItems = $pages->count(true);
|
||||
}
|
||||
|
||||
// Execute hook from plugins
|
||||
Theme::plugins('paginator');
|
||||
|
||||
// Items per page
|
||||
Paginator::set('itemsPerPage', $itemsPerPage);
|
||||
|
||||
// Amount of items
|
||||
Paginator::set('numberOfItems', $numberOfItems);
|
||||
|
||||
// Amount of pages
|
||||
$numberOfPages = (int) max(ceil($numberOfItems / $itemsPerPage), 1);
|
||||
Paginator::set('numberOfPages', $numberOfPages);
|
||||
|
||||
// TRUE if exists a next page to show
|
||||
$showNext = $numberOfPages > $currentPage;
|
||||
Paginator::set('showNext', $showNext);
|
||||
|
||||
// TRUE if exists a previous page to show
|
||||
$showPrev = $currentPage > Paginator::firstPage();
|
||||
Paginator::set('showPrev', $showPrev);
|
||||
|
||||
// TRUE if exists a next and previous page to show
|
||||
$showNextPrev = $showNext && $showPrev;
|
||||
Paginator::set('showNextPrev', $showNextPrev);
|
||||
|
||||
// Integer with the next page
|
||||
$nextPage = max(0, $currentPage+1);
|
||||
Paginator::set('nextPage', $nextPage);
|
||||
|
||||
// Integer with the previous page
|
||||
$prevPage = min($numberOfPages, $currentPage-1);
|
||||
Paginator::set('prevPage', $prevPage);
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// ============================================================================
|
||||
// Variables
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// Functions
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// Main before POST
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// POST Method
|
||||
// ============================================================================
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$token = isset($_POST['tokenCSRF']) ? Sanitize::html($_POST['tokenCSRF']) : false;
|
||||
if (!$security->validateTokenCSRF($token)) {
|
||||
Log::set(__FILE__.LOG_SEP.'Error occurred when trying to validate the tokenCSRF.', ALERT_STATUS_FAIL);
|
||||
Log::set(__FILE__.LOG_SEP.'Token via POST ['.$token.']', ALERT_STATUS_FAIL);
|
||||
|
||||
Session::destroy();
|
||||
Redirect::page('login');
|
||||
} else {
|
||||
unset( $_POST['tokenCSRF'] );
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main after POST
|
||||
// ============================================================================
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
// ============================================================================
|
||||
// Variables
|
||||
// ============================================================================
|
||||
$themePlugin = getPlugin($site->theme()); // Returns plugin object or False
|
||||
|
||||
// ============================================================================
|
||||
// Functions
|
||||
// ============================================================================
|
||||
|
||||
function buildThemes()
|
||||
{
|
||||
global $site;
|
||||
|
||||
$themes = array();
|
||||
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
|
||||
|
||||
foreach ($themesPaths as $themePath) {
|
||||
// Check if the theme is translated.
|
||||
$languageFilename = $themePath . DS . 'languages' . DS . $site->language() . '.json';
|
||||
if (!Sanitize::pathFile($languageFilename)) {
|
||||
$languageFilename = $themePath . DS . 'languages' . DS . DEFAULT_LANGUAGE_FILE;
|
||||
}
|
||||
|
||||
if (Sanitize::pathFile($languageFilename)) {
|
||||
$database = file_get_contents($languageFilename);
|
||||
$database = json_decode($database, true);
|
||||
if (empty($database)) {
|
||||
Log::set('99.themes.php' . LOG_SEP . 'Language file error on theme ' . $themePath);
|
||||
break;
|
||||
}
|
||||
|
||||
$database = $database['theme-data'];
|
||||
|
||||
$database['dirname'] = basename($themePath);
|
||||
|
||||
// --- Metadata ---
|
||||
$filenameMetadata = $themePath . DS . 'metadata.json';
|
||||
|
||||
if (Sanitize::pathFile($filenameMetadata)) {
|
||||
$metadataString = file_get_contents($filenameMetadata);
|
||||
$metadata = json_decode($metadataString, true);
|
||||
|
||||
$database['compatible'] = false;
|
||||
if (!empty($metadata['compatible'])) {
|
||||
$bluditRoot = explode('.', BLUDIT_VERSION);
|
||||
$compatible = explode(',', $metadata['compatible']);
|
||||
foreach ($compatible as $version) {
|
||||
$root = explode('.', $version);
|
||||
if ($root[0] == $bluditRoot[0] && $root[1] == $bluditRoot[1]) {
|
||||
$database['compatible'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$database = $database + $metadata;
|
||||
array_push($themes, $database);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main
|
||||
// ============================================================================
|
||||
|
||||
// Load the language file
|
||||
$languageFilename = THEME_DIR . 'languages' . DS . $site->language() . '.json';
|
||||
if (!Sanitize::pathFile($languageFilename)) {
|
||||
$languageFilename = THEME_DIR . 'languages' . DS . DEFAULT_LANGUAGE_FILE;
|
||||
}
|
||||
|
||||
if (Sanitize::pathFile($languageFilename)) {
|
||||
$database = file_get_contents($languageFilename);
|
||||
$database = json_decode($database, true);
|
||||
|
||||
// Remote the name and description.
|
||||
unset($database['theme-data']);
|
||||
|
||||
// Load words from the theme language
|
||||
if (!empty($database)) {
|
||||
$L->add($database);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user