public static function call($hook, $args = null) { // Run all registered functions of called hookpoint $functions = Stack::get("hook:" . $hook); foreach ($functions as $function) { if (is_array($function)) { if (is_string($function[0]) && class_exists($function[0])) { $instance = new $function[0](); } else { $instance = $function[0]; } if (method_exists($instance, $function[1])) { $args = $instance->{$function}[1]($args); } else { throw new Exception("Hooked method '{$function[1]}' of class '{$function[0]}' for hookpoint '{$hook}' not found!"); } } else { if (function_exists($function)) { $args = $function($args); } else { throw new Exception("Hooked function '{$function}' for hookpoint '{$hook}' not found!"); } } } // Return possibly modified arguments return $args; }
public function run() { // Run action of current instance $functions = Stack::get("action:" . $this->name); if (is_array($functions)) { $response = array(); foreach ($functions as $function) { if (is_array($function)) { $instance = null; if (is_object($function[0])) { $instance = $function[0]; } elseif (is_string($function[0]) && class_exists($function[0])) { $instance = new $function[0](); } if (is_object($instance)) { if (method_exists($instance, $function[1])) { $response[] = $instance->{$function}[1]($this->args); } else { throw new Exception("Method '{$function[1]}' of object '{$function[0]}' for action '{$this->name}' not found!"); } } else { throw new Exception("Object for action '{$this->name}' not found!"); } } else { if (function_exists($function)) { $response[] = $function($this->args); } else { throw new Exception("Function '{$function}' for action '{$this->name}' not found!"); } } } } else { throw new Exception("Action '{$this->name}' not found in register!"); } return $response; }
public function theme_header() { $link = '<link rel="stylesheet" type="text/css" href="' . Site::get_url('theme', true) . '%s" media="%s" title="%s">'; $output = Stack::get('template_stylesheet_with_title', $link . "\r\n"); return $output; }
/** * Aggregates and echos the additional footer code by combining Plugins and Stack calls. */ public function theme_footer($theme) { Plugins::act('template_footer', $theme); Stack::dependent('template_footer_javascript', 'template_header_javascript'); Stack::dependent('template_footer_stylesheet', 'template_stylesheet'); $output = Stack::get('template_footer_stylesheet', Method::create('\\Habari\\Stack', 'styles')); $output .= Stack::get('template_footer_javascript', Method::create('\\Habari\\Stack', 'scripts')); return $output; }
/** * Aggregates and echos the additional footer code by combining Plugins and Stack calls. */ public function theme_footer( $theme ) { Plugins::act( 'template_footer', $theme ); $output = Stack::get( 'template_footer_stylesheet', array( 'Stack', 'styles' ) ); $output .= Stack::get( 'template_footer_javascript', array( 'Stack', 'scripts' ) ); return $output; }
public function getScripts($type, $env = "frontend") { // Get stacked scripts of requested type $scripts = Stack::get("scripts:" . $type); $included = array(); $output = ""; foreach ($scripts as $script) { if (isset($script['exclude']) && isset($script['exclude']['frontend'][$env]) && $script['exclude'][$env] || !isset($script['filepath']) || isset($script['id']) && in_array($script['id'], $included)) { continue; } // If set, save id as included to prevent multiple inclusion of the same file if (isset($script['id'])) { $included[] = $script['id']; } switch ($type) { case "js": $output .= "/t<script src='" . $script['filepath'] . "'></script>/n"; break; case "css": $output .= "/t<link rel='stylesheet' href='" . $script['filepath'] . "'>\n"; break; } } return $output; }