Bug fixes and plugins features

This commit is contained in:
dignajar 2015-06-26 19:12:26 -03:00
parent 3f9c38adac
commit 6af40b3dfe
9 changed files with 140 additions and 76 deletions

View File

@ -14,6 +14,11 @@
<script src="./js/jquery.min.js"></script> <script src="./js/jquery.min.js"></script>
<script src="./js/kube.min.js"></script> <script src="./js/kube.min.js"></script>
<!-- Plugins -->
<?php
Theme::plugins('onAdminHead');
?>
</head> </head>
<body> <body>
@ -86,6 +91,11 @@ $(document).ready(function() {
include(PATH_JS.'functions.php'); include(PATH_JS.'functions.php');
?> ?>
<!-- Plugins -->
<?php
Theme::plugins('onAdminBody');
?>
<?php <?php
echo "DEBUG: Load time: ".(microtime(true) - $loadTime).'<br>'; echo "DEBUG: Load time: ".(microtime(true) - $loadTime).'<br>';
?> ?>

View File

@ -153,7 +153,12 @@ class Plugin {
return false; return false;
} }
public function onSidebar() public function onSiteSidebar()
{
return false;
}
public function onAdminSidebar()
{ {
return false; return false;
} }

View File

@ -37,9 +37,9 @@ if( $Login->isLogged() && ($layout['slug']==='ajax') )
else else
{ {
// Boot rules // Boot rules
include(PATH_RULES.'60.plugins.php');
include(PATH_RULES.'70.build_posts.php'); include(PATH_RULES.'70.build_posts.php');
include(PATH_RULES.'70.build_pages.php'); include(PATH_RULES.'70.build_pages.php');
include(PATH_RULES.'80.plugins.php');
include(PATH_RULES.'99.header.php'); include(PATH_RULES.'99.header.php');
if($Url->notFound() || !$Login->isLogged() || ($Url->slug()==='login') ) if($Url->notFound() || !$Login->isLogged() || ($Url->slug()==='login') )

View File

@ -0,0 +1,75 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Variables
// ============================================================================
$plugins = array(
'onSiteHead'=>array(),
'onSiteBody'=>array(),
'onSiteSidebar'=>array(),
'onAdminHead'=>array(),
'onAdminBody'=>array(),
'onAdminSidebar'=>array(),
'beforePostsLoad'=>array(),
'afterPostsLoad'=>array(),
'beforePagesLoad'=>array(),
'afterPagesLoad'=>array(),
'all'=>array()
);
$pluginsEvents = $plugins;
unset($pluginsEvents['all']);
// ============================================================================
// Functions
// ============================================================================
function build_plugins()
{
global $plugins;
global $pluginsEvents;
// List plugins directories
$list = Filesystem::listDirectories(PATH_PLUGINS);
// Get declared clasess before load plugins clasess, this list doesn't have the plugins clasess.
$currentDeclaredClasess = get_declared_classes();
// Load each plugin clasess
foreach($list as $pluginPath) {
include($pluginPath.'/plugin.php');
}
// Get plugins clasess loaded
$pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
foreach($pluginsDeclaredClasess as $pluginClass)
{
$Plugin = new $pluginClass;
// All plugins installed and not installed.
array_push($plugins['all'], $Plugin);
// If the plugin installed, then add the plugin on the arrays.
if($Plugin->installed())
{
foreach($pluginsEvents as $event=>$value)
{
/*
if($Plugin->onSiteHead()!==false)
array_push($plugins['onSiteHead'], $Plugin);
*/
if($Plugin->{$event}()!==false) {
array_push($plugins[$event], $Plugin);
}
}
}
}
}
// ============================================================================
// Main
// ============================================================================
build_plugins();

View File

@ -1,8 +1,16 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Variables
// ============================================================================
$pages = array(); $pages = array();
$pagesParents = array(NO_PARENT_CHAR=>array()); $pagesParents = array(NO_PARENT_CHAR=>array());
// ============================================================================
// Functions
// ============================================================================
function orderChildren($a, $b) function orderChildren($a, $b)
{ {
if ($a->position() == $b->position()) { if ($a->position() == $b->position()) {
@ -130,6 +138,13 @@ function build_all_pages()
$pagesParents = array(NO_PARENT_CHAR=>$tmpNoParents) + $tmp; $pagesParents = array(NO_PARENT_CHAR=>$tmpNoParents) + $tmp;
} }
// ============================================================================
// Main
// ============================================================================
// Plugins before load pages
Theme::plugins('beforePagesLoad');
// Filter by page, then build it // Filter by page, then build it
if( ($Url->whereAmI()==='page') && ($Url->notFound()===false) ) if( ($Url->whereAmI()==='page') && ($Url->notFound()===false) )
{ {
@ -171,3 +186,6 @@ if($Url->notFound())
// Build all pages // Build all pages
build_all_pages(); build_all_pages();
// Plugins after load pages
Theme::plugins('afterPagesLoad');

View File

@ -1,7 +1,15 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Variables
// ============================================================================
$posts = array(); $posts = array();
// ============================================================================
// Functions
// ============================================================================
function buildPost($key) function buildPost($key)
{ {
global $dbPosts; global $dbPosts;
@ -80,6 +88,13 @@ function build_posts_per_page($pageNumber=0, $amount=5, $draftPosts=false)
} }
} }
// ============================================================================
// Main
// ============================================================================
// Plugins before load posts
Theme::plugins('beforePostsLoad');
// Filter by post, then build it // Filter by post, then build it
if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) ) if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
{ {
@ -114,3 +129,6 @@ else
build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), false); build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), false);
} }
} }
// Plugins after load posts
Theme::plugins('afterPostsLoad');

View File

@ -1,58 +0,0 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
$plugins = array(
'onSiteHead'=>array(),
'onSiteBody'=>array(),
'onSidebar'=>array(),
'onAdminHead'=>array(),
'onAdminBody'=>array(),
'all'=>array()
);
function build_plugins()
{
global $plugins;
// List plugins directories
$list = Filesystem::listDirectories(PATH_PLUGINS);
// Get declared clasess before load plugins clasess, this list doesn't have the plugins clasess.
$currentDeclaredClasess = get_declared_classes();
// Load each plugin clasess
foreach($list as $pluginPath) {
include($pluginPath.'/plugin.php');
}
// Get plugins clasess loaded
$pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
foreach($pluginsDeclaredClasess as $pluginClass)
{
$Plugin = new $pluginClass;
// All plugins installed and not installed.
array_push($plugins['all'], $Plugin);
// If the plugin installed, then add the plugin on the arrays.
if($Plugin->installed())
{
if($Plugin->onSiteHead()!==false)
array_push($plugins['onSiteHead'], $Plugin);
if($Plugin->onSiteBody()!==false)
array_push($plugins['onSiteBody'], $Plugin);
if($Plugin->onSidebar()!==false)
array_push($plugins['onSidebar'], $Plugin);
if($Plugin->onAdminHead()!==false)
array_push($plugins['onAdminHead'], $Plugin);
if($Plugin->onAdminBody()!==false)
array_push($plugins['onAdminBody'], $Plugin);
}
}
}
build_plugins();

View File

@ -1,9 +1,9 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
// Boot rules // Boot rules
include(PATH_RULES.'60.plugins.php');
include(PATH_RULES.'70.build_posts.php'); include(PATH_RULES.'70.build_posts.php');
include(PATH_RULES.'70.build_pages.php'); include(PATH_RULES.'70.build_pages.php');
include(PATH_RULES.'80.plugins.php');
include(PATH_RULES.'99.header.php'); include(PATH_RULES.'99.header.php');
// Theme init.php // Theme init.php

View File

@ -84,7 +84,6 @@ class Theme {
return $tmp; return $tmp;
} }
// OLD
public static function plugins($type) public static function plugins($type)
{ {
global $plugins; global $plugins;
@ -96,6 +95,7 @@ class Theme {
} }
// OLD
public static function url($relative = true) public static function url($relative = true)
{ {
@ -105,10 +105,6 @@ class Theme {
return BLOG_URL; return BLOG_URL;
} }
public static function jquery($path=JS_JQUERY) public static function jquery($path=JS_JQUERY)
{ {
$tmp = '<script src="'.$path.'"></script>'.PHP_EOL; $tmp = '<script src="'.$path.'"></script>'.PHP_EOL;