Merge pull request #606 from fermionic/20130204-themes-cant-use-plugin-hooks
allow themes to use plugin hooks
This commit is contained in:
commit
70f02053e1
|
@ -162,6 +162,10 @@ function call_hooks($name, &$data = null) {
|
||||||
|
|
||||||
if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
|
if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
|
||||||
foreach($a->hooks[$name] as $hook) {
|
foreach($a->hooks[$name] as $hook) {
|
||||||
|
// Don't run a theme's hook if the user isn't using the theme
|
||||||
|
if(strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
|
||||||
|
continue;
|
||||||
|
|
||||||
@include_once($hook[0]);
|
@include_once($hook[0]);
|
||||||
if(function_exists($hook[1])) {
|
if(function_exists($hook[1])) {
|
||||||
$func = $hook[1];
|
$func = $hook[1];
|
||||||
|
@ -318,6 +322,42 @@ function get_theme_screenshot($theme) {
|
||||||
return($a->get_baseurl() . '/images/blank.png');
|
return($a->get_baseurl() . '/images/blank.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// install and uninstall theme
|
||||||
|
if (! function_exists('uninstall_theme')){
|
||||||
|
function uninstall_theme($theme){
|
||||||
|
logger("Addons: uninstalling theme " . $theme);
|
||||||
|
|
||||||
|
@include_once("view/theme/$theme/theme.php");
|
||||||
|
if(function_exists("{$theme}_uninstall")) {
|
||||||
|
$func = "{$theme}_uninstall";
|
||||||
|
$func();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
if (! function_exists('install_theme')){
|
||||||
|
function install_theme($theme) {
|
||||||
|
// silently fail if theme was removed
|
||||||
|
|
||||||
|
if(! file_exists("view/theme/$theme/theme.php"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
logger("Addons: installing theme $theme");
|
||||||
|
|
||||||
|
@include_once("view/theme/$theme/theme.php");
|
||||||
|
|
||||||
|
if(function_exists("{$theme}_install")) {
|
||||||
|
$func = "{$theme}_install";
|
||||||
|
$func();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger("Addons: FAILED installing theme $theme");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// check service_class restrictions. If there are no service_classes defined, everything is allowed.
|
// check service_class restrictions. If there are no service_classes defined, everything is allowed.
|
||||||
// if $usage is supplied, we check against a maximum count and return true if the current usage is
|
// if $usage is supplied, we check against a maximum count and return true if the current usage is
|
||||||
|
|
|
@ -980,10 +980,14 @@ function admin_page_themes(&$a){
|
||||||
|
|
||||||
toggle_theme($themes,$theme,$result);
|
toggle_theme($themes,$theme,$result);
|
||||||
$s = rebuild_theme_table($themes);
|
$s = rebuild_theme_table($themes);
|
||||||
if($result)
|
if($result) {
|
||||||
|
install_theme($theme);
|
||||||
info( sprintf('Theme %s enabled.',$theme));
|
info( sprintf('Theme %s enabled.',$theme));
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
|
uninstall_theme($theme);
|
||||||
info( sprintf('Theme %s disabled.',$theme));
|
info( sprintf('Theme %s disabled.',$theme));
|
||||||
|
}
|
||||||
|
|
||||||
set_config('system','allowed_themes',$s);
|
set_config('system','allowed_themes',$s);
|
||||||
goaway($a->get_baseurl(true) . '/admin/themes' );
|
goaway($a->get_baseurl(true) . '/admin/themes' );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user