From 6af40b3dfeb5597ce20c541b9c14259f4ba18627 Mon Sep 17 00:00:00 2001 From: dignajar Date: Fri, 26 Jun 2015 19:12:26 -0300 Subject: [PATCH] Bug fixes and plugins features --- admin/themes/default/index.php | 28 +++++++---- kernel/abstract/plugin.class.php | 7 ++- kernel/boot/admin.php | 2 +- kernel/boot/rules/60.plugins.php | 75 ++++++++++++++++++++++++++++ kernel/boot/rules/70.build_pages.php | 20 +++++++- kernel/boot/rules/70.build_posts.php | 18 +++++++ kernel/boot/rules/80.plugins.php | 58 --------------------- kernel/boot/site.php | 2 +- kernel/helpers/theme.class.php | 6 +-- 9 files changed, 140 insertions(+), 76 deletions(-) create mode 100644 kernel/boot/rules/60.plugins.php delete mode 100644 kernel/boot/rules/80.plugins.php diff --git a/admin/themes/default/index.php b/admin/themes/default/index.php index f14a3f95..e198814b 100644 --- a/admin/themes/default/index.php +++ b/admin/themes/default/index.php @@ -2,17 +2,22 @@ - - + + - Your page title + Your page title - - - + + + - - + + + + + @@ -86,8 +91,13 @@ $(document).ready(function() { include(PATH_JS.'functions.php'); ?> + + + '; ?> - + \ No newline at end of file diff --git a/kernel/abstract/plugin.class.php b/kernel/abstract/plugin.class.php index 0b625733..9743c91a 100644 --- a/kernel/abstract/plugin.class.php +++ b/kernel/abstract/plugin.class.php @@ -153,7 +153,12 @@ class Plugin { return false; } - public function onSidebar() + public function onSiteSidebar() + { + return false; + } + + public function onAdminSidebar() { return false; } diff --git a/kernel/boot/admin.php b/kernel/boot/admin.php index ca65f8fb..243217a4 100644 --- a/kernel/boot/admin.php +++ b/kernel/boot/admin.php @@ -37,9 +37,9 @@ if( $Login->isLogged() && ($layout['slug']==='ajax') ) else { // Boot rules + include(PATH_RULES.'60.plugins.php'); include(PATH_RULES.'70.build_posts.php'); include(PATH_RULES.'70.build_pages.php'); - include(PATH_RULES.'80.plugins.php'); include(PATH_RULES.'99.header.php'); if($Url->notFound() || !$Login->isLogged() || ($Url->slug()==='login') ) diff --git a/kernel/boot/rules/60.plugins.php b/kernel/boot/rules/60.plugins.php new file mode 100644 index 00000000..f15cff1f --- /dev/null +++ b/kernel/boot/rules/60.plugins.php @@ -0,0 +1,75 @@ +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(); diff --git a/kernel/boot/rules/70.build_pages.php b/kernel/boot/rules/70.build_pages.php index db858b01..273552ba 100644 --- a/kernel/boot/rules/70.build_pages.php +++ b/kernel/boot/rules/70.build_pages.php @@ -1,8 +1,16 @@ array()); +// ============================================================================ +// Functions +// ============================================================================ + function orderChildren($a, $b) { if ($a->position() == $b->position()) { @@ -130,6 +138,13 @@ function build_all_pages() $pagesParents = array(NO_PARENT_CHAR=>$tmpNoParents) + $tmp; } +// ============================================================================ +// Main +// ============================================================================ + +// Plugins before load pages +Theme::plugins('beforePagesLoad'); + // Filter by page, then build it if( ($Url->whereAmI()==='page') && ($Url->notFound()===false) ) { @@ -170,4 +185,7 @@ if($Url->notFound()) } // Build all pages -build_all_pages(); \ No newline at end of file +build_all_pages(); + +// Plugins after load pages +Theme::plugins('afterPagesLoad'); \ No newline at end of file diff --git a/kernel/boot/rules/70.build_posts.php b/kernel/boot/rules/70.build_posts.php index da4e196b..b57e99b9 100644 --- a/kernel/boot/rules/70.build_posts.php +++ b/kernel/boot/rules/70.build_posts.php @@ -1,7 +1,15 @@ whereAmI()==='post') && ($Url->notFound()===false) ) { @@ -114,3 +129,6 @@ else build_posts_per_page($Url->pageNumber(), $Site->postsPerPage(), false); } } + +// Plugins after load posts +Theme::plugins('afterPostsLoad'); \ No newline at end of file diff --git a/kernel/boot/rules/80.plugins.php b/kernel/boot/rules/80.plugins.php deleted file mode 100644 index e8af7b33..00000000 --- a/kernel/boot/rules/80.plugins.php +++ /dev/null @@ -1,58 +0,0 @@ -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(); diff --git a/kernel/boot/site.php b/kernel/boot/site.php index d4d18c12..6373b374 100644 --- a/kernel/boot/site.php +++ b/kernel/boot/site.php @@ -1,9 +1,9 @@ '.PHP_EOL;