/** * Initialise Zikula. * * Carries out a number of initialisation tasks to get Zikula up and * running. * * @param integer $stage Stage to load. * @param Zikula_Request_Http $request * * @return boolean True initialisation successful false otherwise. */ public function init($stage = self::STAGE_ALL, Request $request) { $GLOBALS['__request'] = $request; // hack for pre 1.5.0 - drak $coreInitEvent = new GenericEvent($this); // store the load stages in a global so other API's can check whats loaded $this->stage = $this->stage | $stage; if ($stage & self::STAGE_PRE && $this->stage & ~self::STAGE_PRE) { ModUtil::flushCache(); System::flushCache(); $args = !System::isInstalling() ? array('lazy' => true) : array(); $this->dispatcher->dispatch('core.preinit', new GenericEvent($this, $args)); } // Initialise and load configuration if ($stage & self::STAGE_CONFIG) { // for BC only. remove this code in 2.0.0 if (!System::isInstalling()) { $this->dispatcher->dispatch('setup.errorreporting', new GenericEvent(null, array('stage' => $stage))); } // initialise custom event listeners from config.php settings $coreInitEvent->setArgument('stage', self::STAGE_CONFIG); /*************************************************** * NOTE: this event is monitored by * \Zikula\Bundle\CoreInstallerBundle\EventListener\InstallUpgradeCheckListener * to see if install or upgrade is needed ***************************************************/ $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_DB) { try { $dbEvent = new GenericEvent($this, array('stage' => self::STAGE_DB)); $this->dispatcher->dispatch('core.init', $dbEvent); } catch (PDOException $e) { if (!System::isInstalling()) { header('HTTP/1.1 503 Service Unavailable'); require_once System::getSystemErrorTemplate('dbconnectionerror.tpl'); System::shutDown(); } else { return false; } } } if ($stage & self::STAGE_TABLES) { // Initialise dbtables ModUtil::dbInfoLoad('ZikulaExtensionsModule', 'ZikulaExtensionsModule'); ModUtil::initCoreVars(); ModUtil::dbInfoLoad('ZikulaSettingsModule', 'ZikulaSettingsModule'); ModUtil::dbInfoLoad('ZikulaThemeModule', 'ZikulaThemeModule'); ModUtil::dbInfoLoad('ZikulaUsersModule', 'ZikulaUsersModule'); ModUtil::dbInfoLoad('ZikulaGroupsModule', 'ZikulaGroupsModule'); ModUtil::dbInfoLoad('ZikulaPermissionsModule', 'ZikulaPermissionsModule'); ModUtil::dbInfoLoad('ZikulaCategoriesModule', 'ZikulaCategoriesModule'); // Add AutoLoading for non-symfony 1.3 modules in /modules if (!System::isInstalling()) { ModUtil::registerAutoloaders(); } $coreInitEvent->setArgument('stage', self::STAGE_TABLES); $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_SESSIONS) { // SessionUtil::requireSession(); $coreInitEvent->setArgument('stage', self::STAGE_SESSIONS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // Have to load in this order specifically since we cant setup the languages until we've decoded the URL if required (drak) // start block if ($stage & self::STAGE_LANGS) { $lang = ZLanguage::getInstance(); } if ($stage & self::STAGE_DECODEURLS) { System::queryStringDecode($request); $coreInitEvent->setArgument('stage', self::STAGE_DECODEURLS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_LANGS) { $lang->setup($request); $coreInitEvent->setArgument('stage', self::STAGE_LANGS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // end block if ($stage & self::STAGE_MODS) { if (!System::isInstalling()) { ModUtil::load('ZikulaSecurityCenterModule'); } $coreInitEvent->setArgument('stage', self::STAGE_MODS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_THEME) { // register default page vars PageUtil::registerVar('polyfill_features', true); PageUtil::registerVar('title'); PageUtil::setVar('title', System::getVar('defaultpagetitle')); PageUtil::registerVar('keywords', true); PageUtil::registerVar('stylesheet', true); PageUtil::registerVar('javascript', true); PageUtil::registerVar('jsgettext', true); PageUtil::registerVar('body', true); PageUtil::registerVar('header', true); PageUtil::registerVar('footer', true); // set some defaults // Metadata for SEO $this->container->setParameter('zikula_view.metatags', array('description' => System::getVar('defaultmetadescription'), 'keywords' => System::getVar('metakeywords'))); $coreInitEvent->setArgument('stage', self::STAGE_THEME); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // check the users status, if not 1 then log him out if (!System::isInstalling() && UserUtil::isLoggedIn()) { $userstatus = UserUtil::getVar('activated'); if ($userstatus != Users_Constant::ACTIVATED_ACTIVE) { UserUtil::logout(); // TODO - When getting logged out this way, the existing session is destroyed and // then a new one is created on the reentry into index.php. The message // set by the registerStatus call below gets lost. LogUtil::registerStatus(__('You have been logged out.')); System::redirect(ModUtil::url('ZikulaUsersModule', 'user', 'login')); } } if ($stage & self::STAGE_POST && $this->stage & ~self::STAGE_POST) { $this->dispatcher->dispatch('core.postinit', new GenericEvent($this, array('stages' => $stage))); } }
/** * Executes & returns the template results. * * This returns the template output instead of displaying it. * Supply a valid template name. * As an optional second parameter, you can pass a cache id. * As an optional third parameter, you can pass a compile id. * * @param string $template The name of the template. * @param string $cache_id The cache ID (optional). * @param string $compile_id The compile ID (optional). * @param boolean $display Whether or not to display directly (optional). * @param boolean $reset Reset singleton defaults (optional). deprecated. * * @return string The template output. */ public function fetch($template, $cache_id = null, $compile_id = null, $display = false, $reset = true) { $this->_setup_template($template); if (is_null($cache_id)) { $cache_id = $this->cache_id; } if (is_null($compile_id)) { $compile_id = $this->compile_id; } $this->template = $this->template_dir . '/' . $template; $output = $this->_fetch($template, $cache_id, $compile_id, $display); if ($this->expose_template == true) { $template = DataUtil::formatForDisplay($template); //$output = "\n<!-- Start " . $this->template_dir . "/$template -->\n" . $output . "\n<!-- End " . $this->template_dir . "/$template -->\n"; // Changed comment into conditional statement for IE<10 $output = "\n<!--[if !IE]> Start " . $this->template_dir . "/{$template} <![endif]-->\n" . $output . "\n<!-- End " . $this->template_dir . "/{$template} -->\n"; } $event = new \Zikula\Core\Event\GenericEvent($this, array('template' => $template), $output); return $this->eventManager->dispatch('view.postfetch', $event)->getData(); }
/** * Initialise Zikula. * * Carries out a number of initialisation tasks to get Zikula up and * running. * * @param integer $stage Stage to load. * @param Zikula_Request_Http $request * * @return boolean True initialisation successful false otherwise. */ public function init($stage = self::STAGE_ALL, Request $request) { $GLOBALS['__request'] = $request; // hack for pre 1.5.0 - drak $coreInitEvent = new GenericEvent($this); // store the load stages in a global so other API's can check whats loaded $this->stage = $this->stage | $stage; if ($stage & self::STAGE_PRE && $this->stage & ~self::STAGE_PRE) { ModUtil::flushCache(); System::flushCache(); $args = !System::isInstalling() ? array('lazy' => true) : array(); $this->dispatcher->dispatch('core.preinit', new GenericEvent($this, $args)); } // Initialise and load configuration if ($stage & self::STAGE_CONFIG) { // for BC only. remove this code in 2.0.0 if (!System::isInstalling()) { $this->dispatcher->dispatch('setup.errorreporting', new GenericEvent(null, array('stage' => $stage))); } // initialise custom event listeners from config.php settings $coreInitEvent->setArgument('stage', self::STAGE_CONFIG); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // create several booleans to test condition of request regrading install/upgrade $installed = $this->getContainer()->getParameter('installed'); if ($installed) { self::defineCurrentInstalledCoreVersion($this->getContainer()); } $requiresUpgrade = $installed && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, self::VERSION_NUM, '<'); // can't use $request->get('_route') to get any of the following // all these routes are hard-coded in xml files $uriContainsInstall = strpos($request->getRequestUri(), '/install') !== false; $uriContainsUpgrade = strpos($request->getRequestUri(), '/upgrade') !== false; $uriContainsDoc = strpos($request->getRequestUri(), '/installdoc') !== false; $uriContainsWdt = strpos($request->getRequestUri(), '/_wdt') !== false; $uriContainsProfiler = strpos($request->getRequestUri(), '/_profiler') !== false; $uriContainsRouter = strpos($request->getRequestUri(), '/js/routing?callback=fos.Router.setData') !== false; $doNotRedirect = $uriContainsProfiler || $uriContainsWdt || $uriContainsRouter || $request->isXmlHttpRequest(); // check if Zikula Core is not installed if (!$installed && !$uriContainsDoc && !$uriContainsInstall && !$doNotRedirect) { $this->container->get('router')->getContext()->setBaseUrl($request->getBasePath()); // compensate for sub-directory installs $url = $this->container->get('router')->generate('install'); $response = new RedirectResponse($url); $response->send(); System::shutDown(); } // check if Zikula Core requires upgrade if ($requiresUpgrade && !$uriContainsDoc && !$uriContainsUpgrade && !$doNotRedirect) { $this->container->get('router')->getContext()->setBaseUrl($request->getBasePath()); // compensate for sub-directory installs $url = $this->container->get('router')->generate('upgrade'); $response = new RedirectResponse($url); $response->send(); System::shutDown(); } if (!$installed || $requiresUpgrade || $this->getContainer()->hasParameter('upgrading')) { System::setInstalling(true); } if ($stage & self::STAGE_DB) { try { $dbEvent = new GenericEvent($this, array('stage' => self::STAGE_DB)); $this->dispatcher->dispatch('core.init', $dbEvent); } catch (PDOException $e) { if (!System::isInstalling()) { header('HTTP/1.1 503 Service Unavailable'); require_once System::getSystemErrorTemplate('dbconnectionerror.tpl'); System::shutDown(); } else { return false; } } } if ($stage & self::STAGE_TABLES) { // Initialise dbtables ModUtil::dbInfoLoad('ZikulaExtensionsModule', 'ZikulaExtensionsModule'); ModUtil::initCoreVars(); ModUtil::dbInfoLoad('ZikulaSettingsModule', 'ZikulaSettingsModule'); ModUtil::dbInfoLoad('ZikulaThemeModule', 'ZikulaThemeModule'); ModUtil::dbInfoLoad('ZikulaUsersModule', 'ZikulaUsersModule'); ModUtil::dbInfoLoad('ZikulaGroupsModule', 'ZikulaGroupsModule'); ModUtil::dbInfoLoad('ZikulaPermissionsModule', 'ZikulaPermissionsModule'); ModUtil::dbInfoLoad('ZikulaCategoriesModule', 'ZikulaCategoriesModule'); // Add AutoLoading for non-symfony 1.3 modules in /modules if (!System::isInstalling()) { ModUtil::registerAutoloaders(); } $coreInitEvent->setArgument('stage', self::STAGE_TABLES); $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_SESSIONS) { // SessionUtil::requireSession(); $coreInitEvent->setArgument('stage', self::STAGE_SESSIONS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // Have to load in this order specifically since we cant setup the languages until we've decoded the URL if required (drak) // start block if ($stage & self::STAGE_LANGS) { $lang = ZLanguage::getInstance(); } if ($stage & self::STAGE_DECODEURLS) { System::queryStringDecode($request); $coreInitEvent->setArgument('stage', self::STAGE_DECODEURLS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_LANGS) { $lang->setup($request); $coreInitEvent->setArgument('stage', self::STAGE_LANGS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // end block if ($stage & self::STAGE_MODS) { if (!System::isInstalling()) { ModUtil::load('ZikulaSecurityCenterModule'); } $coreInitEvent->setArgument('stage', self::STAGE_MODS); $this->dispatcher->dispatch('core.init', $coreInitEvent); } if ($stage & self::STAGE_THEME) { // register default page vars PageUtil::registerVar('polyfill_features', true); PageUtil::registerVar('title'); PageUtil::setVar('title', System::getVar('defaultpagetitle')); PageUtil::registerVar('keywords', true); PageUtil::registerVar('stylesheet', true); PageUtil::registerVar('javascript', true); PageUtil::registerVar('jsgettext', true); PageUtil::registerVar('body', true); PageUtil::registerVar('header', true); PageUtil::registerVar('footer', true); // set some defaults // Metadata for SEO $this->container->setParameter('zikula_view.metatags', array('description' => System::getVar('defaultmetadescription'), 'keywords' => System::getVar('metakeywords'))); $coreInitEvent->setArgument('stage', self::STAGE_THEME); $this->dispatcher->dispatch('core.init', $coreInitEvent); } // check the users status, if not 1 then log him out if (!System::isInstalling() && UserUtil::isLoggedIn()) { $userstatus = UserUtil::getVar('activated'); if ($userstatus != Users_Constant::ACTIVATED_ACTIVE) { UserUtil::logout(); // TODO - When getting logged out this way, the existing session is destroyed and // then a new one is created on the reentry into index.php. The message // set by the registerStatus call below gets lost. LogUtil::registerStatus(__('You have been logged out.')); System::redirect(ModUtil::url('ZikulaUsersModule', 'user', 'login')); } } if ($stage & self::STAGE_POST && $this->stage & ~self::STAGE_POST) { $this->dispatcher->dispatch('core.postinit', new GenericEvent($this, array('stages' => $stage))); } }