public function __construct() { /* * Call parent construct */ parent::__construct(); import('system/contrib/admin/base'); import('system/contrib/auth/plugins'); /* * Initialize the Pluggable if it doesn't initialized. */ if (!Pluggable::$inited) { Pluggable::init($this); } /* * smarty instance */ $this->smarty = $this->load('smarty'); /* * admin_required, if use RBAC, this will another use */ AuthPlugins::admin_required($this); Pluggable::trigger('before_admin_site_run'); $this->smarty->assign('admin_menus', BaseAdmin::build_menus()); }
public static function init(BaseApplication $application) { self::$inited = true; if ($application) { self::$application = $application; } self::load_plugins(); }
function smarty_function_load_dynamic_plugins($params, $smarty) { if (array_key_exists('plugin', $params)) { list($app, $plugin) = explode('.', $params['plugin']); Pluggable::load_plugins($app, $plugin); } else { if (array_key_exists('smarty_function', $params)) { $this->registerPlugin('function', $params['smarty_function'], 'smarty_function_' . $params['function_name']); } } }
/** * Test released assets are stored in the options */ public function test_store_released_asset() { Cache::set('pluggable_assets', $this->simple_assets); // Releases ['simple_assets']['files']['of']); Plugins::register(array($this, 'filter_register_release_asset'), 'filter', 'pluggable_assets'); Pluggable::register_assets(); $key = 'simple_assets'; //$expected = array($key => array('files' => array('of'))); $result = Options::get('released_pluggable_assets'); // Like to do this, but PHP's mushing together of arrays and dictionaries makes the keys not match //$this->assert_equal($expected, $result, "Expected <em>" . var_export($result, true) . "</em> to equal <em>" . var_export($expected, true) . "</em>"); $this->assert_true(array_key_exists($key, $result) && array_key_exists('files', $result[$key]) && in_array('of', $result[$key]['files'])); }
public function __construct($params = null) { self::$instance = $this; self::$current_application = ini('runtime/application'); self::_check_dependence(self::$current_application); Pluggable::trigger('after_application_construct'); /* * 基础是否登录权限判断 */ if (ini('runtime/application') != 'system/contrib/auth' && ini('runtime/action') != 'login' && ini('runtime/application' != 'system/contrib/dev_tools')) { import('system/contrib/auth/plugins'); AuthPlugins::login_required($this); } }
/** * Plugin constructor. * Plugins should not define their own constructors, because they are instantiated * to extract plugin info. Instead, include a sink for a "init" hook * which is executed immediately after the plugin is loaded during normal execution. **/ public final function __construct() { parent::__construct(); }
/** * Register plugin hooks * @static */ public static function __static() { Pluggable::load_hooks('Comment'); }
private static function editor($name, $property) { if (is_callable(array('Pluggable', 'trigger'))) { $html = Pluggable::trigger('on_editor_create', array($name, $property)); } if (!$html) { $html = <<<EOF <script type="text/javascript"> KE.show({ id : '{$name}', width: '{$property['width']}', height: '{$property['height']}', afterCreate : function(id) { KE.event.ctrl(document, 13, function() { KE.util.setData(id); document.forms['example'].submit(); }); KE.event.ctrl(KE.g[id].iframeDoc, 13, function() { KE.util.setData(id); document.forms['example'].submit(); }); } }); </script> EOF; } $html .= sprintf('<textarea name="%s" id="%s" %s>[[TheDefaultContent]]</textarea>', $name, $name, self::$extra); return $html; }
public static function output() { Pluggable::trigger('after_system_exit'); ob_end_flush(); }
/** * Register plugin hooks * @static */ public static function __static() { Pluggable::load_hooks(get_called_class()); }
/** * Allow plugins to register StackItems that can be added to Stacks later * Initialize this class for plugin behavior so it can add system default StackItems */ public static function load_stackitems() { Pluggable::load_hooks(__CLASS__); Plugins::act('register_stackitems'); }
/** * Adds a RewriteRule to the REST handler for the rule provided * @param string $hook The hook name to add a RewriteRule for * @param Pluggable $object The pluggable object holding the hook * @param Callable $fn The hook function to use to dispatch the request */ protected static function add_rest_rule($hook, Pluggable $object, $fn) { $hook_ary = preg_split('#(?<!_)_#', $hook); $verb = array_shift($hook_ary); $hook_regex = '/^' . implode('\\/', array_map(function ($a) { if ($a[0] === '_') { return '(?P<' . substr($a, 1) . '>[^\\/]+)'; } return $a; }, $hook_ary)) . '\\/?$/i'; $hook_build = implode('/', array_map(function ($a) { if ($a[0] === '_') { return '{$' . substr($a, 1) . '}'; } return $a; }, $hook_ary)); $rule = new RewriteRule(array('name' => implode($hook_ary), 'parse_regex' => $hook_regex, 'build_str' => $hook_build, 'handler' => 'RestHandler', 'action' => 'rest', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'Rule to dispatch REST hook.', 'parameters' => array('verb' => $verb, 'hook' => array($object, $fn)))); $object->add_rule($rule, implode($hook_ary)); }
} ?> <?php if (isset($active_theme['info']->help)) { ?> <div id="themehelp" class="<?php if (Controller::get_var('help') == $active_theme['dir']) { ?> active<?php } ?> "> <div class="help"> <?php echo Pluggable::get_xml_text($active_theme['info']['filename'], $active_theme['info']->help); ?> </div> </div> <?php } ?> </div> </div> </div> </div> <?php // Capture the admin config output. If nothing is there, don't output the section ob_start(); Plugins::act('theme_ui', $active_theme);
<div class="pluginhelp"<?php if ($helpaction == '_help') { ?> class="active"<?php } ?> > <?php if (Plugins::is_loaded((string) $plugin['info']->name)) { Plugins::act_id('plugin_ui', $plugin['plugin_id'], $plugin['plugin_id'], '_help'); } elseif (isset($plugin['info']->help)) { foreach ($plugin['info']->help as $help) { if ((string) $help['name'] == '') { echo '<div class="help">' . Pluggable::get_xml_text($plugin['info']['filename'], $help) . '</div>'; } } } ?> </div> <?php if (isset($config) && $config == true) { ?> <div id="pluginconfigure"> <?php Plugins::plugin_ui($configure, $configaction); ?> <a class="link_as_button" href="<?php URL::out('display_plugins');
public static function dispatch($app, $view_action, array $params = null) { $view_action = $view_action ? $view_action : 'index'; import('system/bin/application'); import('system/bin/cache'); /* * application's url pattern mapping */ $app_map_array = YamlBackend::load('etc/conf.d/urls.yml'); if ($app_map_array['map'][$app]) { $app = $app_map_array['map'][$app]; } else { if (array_keys($app_map_array['map'], $app)) { throw new DispatchException(1011, $app . '/' . $view_action); } } /* * Cache all INSTALLED APPS urls pattern */ $cache_id = 'URLS_MAP'; $url_name_map_cache_id = 'URL_NAME_MAP'; $app_map_array_flip_cache_id = 'URL_APP_MAP_ARRAY_FLIP'; $cache_instance = CacheBackend::get_instance(); if ($cache_instance->is_cached($cache_id) && RUN_MODE == 'deploy' && false) { self::$url_patterns = $cache_instance->get($cache_id); self::$url_name_map = $cache_instance->get($url_name_map_cache_id); $app_map_array_flip = $cache_instance->get($app_map_array_flip_cache_id); } else { $installed_apps = ini('base/INSTALLED_APPS'); $app_map_array_flip = array_flip($app_map_array['map']); foreach ($installed_apps as $installed_app) { $urlpattern = YamlBackend::load(sprintf('applications/%s/urls.yml', $installed_app)); if ($app_map_array_flip[$installed_app]) { $installed_app = $app_map_array_flip[$installed_app]; } /* * The url-name map to view action * like: url name='auth_login' => auth.AuthController.login */ if ($urlpattern) { foreach ($urlpattern as $key => $value) { if ($value['name']) { self::$url_name_map[$value['name']] = $installed_app . '/' . $key; } } } self::$url_patterns[$installed_app] = $urlpattern; } $cache_instance->set($cache_id, self::$url_patterns); if (self::$url_name_map) { $cache_instance->set($url_name_map_cache_id, self::$url_name_map); } $cache_instance->set($app_map_array_flip_cache_id, $app_map_array_flip); } $app_map_name = array_key_exists($app, $app_map_array_flip) ? $app_map_array_flip[$app] : $app; $urlpattern = self::$url_patterns[$app_map_name]; try { /* * does not set the action key */ if (!$urlpattern[$view_action]['action']) { $_c = ucfirst($app) . 'Controller'; try { import(Package::get_file(sprintf('applications/%s/%s', $app, $_c))); $urlpattern[$view_action]['action'] = $_c . '.' . $view_action; } catch (DoesNotExistsException $e) { throw new DispatchException(1011, $app . '/' . $view_action); } } list($controller, $method) = explode('.', $urlpattern[$view_action]['action']); import(sprintf('applications/%s/%s', $app, $controller)); if (!is_callable(array($controller, $method))) { throw new DispatchException(1011, $app . '/' . $view_action); } /* * Set current application and action */ RuntimeConfig::set('runtime/application', $app); RuntimeConfig::set('runtime/action', $view_action); RuntimeConfig::set('runtime/view_action', $app . '/' . $view_action); BaseConfig::load_application_config($app); try { $controller = new $controller($params); RuntimeConfig::set('runtime/application_instance', $controller); /* * Re-init the plugins with the application implements */ Pluggable::init($controller); /* * Trigger the plugins in before_application_run */ Pluggable::trigger('before_application_run'); /* * Call the view-action method */ call_user_func_array(array($controller, $method), (array) $params); /* * Dependence exception */ } catch (DependenceException $e) { //pass } /* * When the DispatchException catched * Return the 404 */ } catch (DispatchException $e) { $app = new BaseApplication(); Pluggable::init($app); Pluggable::trigger('before_application_run'); $app->load('smarty')->display('404'); } }
/** * Register plugin hooks * @static */ public static function __static() { Pluggable::load_hooks(__CLASS__); }
/** * Register plugin hooks * @static */ public static function __static() { Pluggable::load_hooks('Post'); }
public function display($template, $cache_id = null, $compile_id = null, $parent = null) { //BaseApplication::_call_middleware('after'); Pluggable::trigger('before_template_render'); /* * echo big */ $content = $this->fetch($template, $cache_id, $compile_id, $parent); function echobig($string, $bufferSize = 8192) { $splitString = str_split($string, $bufferSize); foreach ($splitString as $chunk) { echo $chunk; } } echobig($content); Pluggable::trigger('after_template_render'); }