error_reporting($config->site->error_reporting); session_name($config->site->site_id); session_start(); ob_start('stingleOutputHandler'); Cgi::setMode(defined("IS_CGI")); Debug::setMode($config->Debug->enabled); SiteMode::set($config->SiteMode->mode); // Register User Hooks if (isset($config->Hooks)) { foreach (get_object_vars($config->Hooks) as $hookName => $funcName) { if (is_object($funcName)) { foreach (get_object_vars($funcName) as $regFuncName) { HookManager::registerHook(new Hook($hookName, $regFuncName)); } } else { HookManager::registerHook(new Hook($hookName, $funcName)); } } } // Init packages/plugins HookManager::callHook("BeforePackagesLoad"); foreach (get_object_vars($config->Packages) as $package) { $package = get_object_vars($package); if (!isset($package[1])) { $package[1] = array(); } Reg::get('packageMgr')->addPackage($package[0], $package[1]); } Reg::get('packageMgr')->load(); HookManager::callHook("AfterPackagesLoad"); // Request Parser
/** * Register plugin hooks * * @throws RuntimeException */ private function registerHooks() { if (isset($this->config->Hooks)) { foreach (get_object_vars($this->config->Hooks) as $hookName => $hookMethod) { if ($this->packageManager->isHookRegistrationIsAllowed($hookMethod, $this->packageName, $this->pluginName)) { $hookMethodName = "hook{$hookMethod}"; $hook = new Hook($hookName, $hookMethodName, $this); if (HookManager::isHookRegistered($hook)) { throw new RuntimeException("Hook {$hookMethod} is already registered."); } if (method_exists($this, $hookMethodName)) { HookManager::registerHook($hook); } else { throw new RuntimeException("Hook method of plugin {$this->pluginName} in package {$this->packageName} for hook {$hookName} -> {$hookMethodName} doesn't exists!"); } } } } }
/** * Register plugin hooks * * @throws RuntimeException */ private function registerHooks() { if (isset($this->config->Hooks)) { foreach (get_object_vars($this->config->Hooks) as $hookName => $hookMethod) { if ($this->packageManager->isHookRegistrationIsAllowed($hookMethod, $this->packageName, $this->pluginName)) { $hookMethodName = "hook{$hookMethod}"; $hook = new Hook($hookName, $hookMethodName, $this); if (HookManager::isHookRegistered($hook)) { throw new RuntimeException("Hook {$hookMethod} is already registered."); } if (method_exists($this, $hookMethodName)) { // Check if there is hook registered on $hookName with same method name and replace it $isReplacedHook = false; if (HookManager::isAnyHooksRegistered($hookName)) { $registeredHooks = HookManager::getRegisteredHooks($hookName); foreach ($registeredHooks as $registeredHook) { if ($registeredHook->getMethod() == $hookMethodName) { HookManager::replaceHook($registeredHook, $hook); $isReplacedHook = true; break; } } } if (!$isReplacedHook) { // Register hook if it is not replaced HookManager::registerHook($hook); } } else { throw new RuntimeException("Hook method of plugin {$this->pluginName} in package {$this->packageName} for hook {$hookName} -> {$hookMethodName} doesn't exists!"); } } } } }
/** * Display a module page. <b>The $tpl var should be relative to /templates/modules * folder without a '/' at the begining.</b> * Examples: * home/home.tpl * users/profile.tpl * * @param string $tpl * @return SmartyWrapper */ public function output() { // Do not display anything if output is disabled if ($this->isOutputDisabled) { return; } // Call layout init hook if there is any $hookFunctionName = 'initLayout_' . $this->layoutName; if (function_exists($hookFunctionName)) { $hookName = 'hookInitLayout_' . $this->layoutName; $layoutHook = new Hook($hookName, $hookFunctionName); HookManager::registerHook($layoutHook); HookManager::callHook($hookName); } // Call per template hook $hookFunctionName = 'initTemplate_' . $this->template; if (function_exists($hookFunctionName)) { $hookName = 'hookInitTemplate_' . $this->template; $templateHook = new Hook($hookName, $hookFunctionName); HookManager::registerHook($templateHook); HookManager::callHook($hookName); } // Check if page exists and if not show 404 error page if (!file_exists($this->getFilePathFromTemplate("{$this->modulesPath}{$this->module}/{$this->page}.tpl", true))) { header("HTTP/1.0 404 Not Found"); $this->module = $this->errorsModule; $this->page = $this->error404Page; $this->removeWrapper(); } $this->defaultAssingns(); // Check if wrapper is set and if yes include it if (!empty($this->wrapper)) { $this->assign('modulePageTpl', $this->getFilePathFromTemplate($this->modulesPath . $this->module . "/" . $this->page . ".tpl")); $this->assign('__modulePageTpl', $this->getFilePathFromTemplate($this->modulesPath . $this->module . "/" . $this->wrappersDir . $this->wrapper . ".tpl")); } else { $this->assign('__modulePageTpl', $this->getFilePathFromTemplate($this->modulesPath . $this->module . "/" . $this->page . ".tpl")); } // Finally display parent::display($this->layoutPath); }