Пример #1
0
 /**
  * Build service.
  *
  * Builds event servicehandlers.  If the service does not exist, it creates it
  * and adds it to the DI container.
  *
  * @param string $id
  * @param string $className
  * @param string $method
  *
  * @return Zikula_ServiceHandler
  */
 public function buildService($id, $className, $method)
 {
     if (!$this->serviceManager->hasService($id)) {
         $definition = new Zikula_ServiceManager_Definition($className, array(new Zikula_ServiceManager_Reference($this->serviceId)));
         $this->serviceManager->registerService($id, $definition);
     }
     return new Zikula_ServiceHandler($id, $method);
 }
Пример #2
0
 /**
  * Load all persisted services into ServiceManager.
  *
  * @return void
  */
 public static function loadPersistentServices()
 {
     $handlers = ModUtil::getVar(self::HANDLERS, 'definitions', array());
     if (!$handlers) {
         return;
     }
     foreach ($handlers as $id => $handler) {
         self::$serviceManager->registerService($id, $handler['definition'], $handler['shared']);
     }
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @param Zikula_ServiceManager $serviceManager ServiceManager.
  *
  * @throws InvalidArgumentException If getMeta() is not implemented correctly.
  */
 public function __construct(Zikula_ServiceManager $serviceManager)
 {
     $this->serviceManager = $serviceManager;
     $this->eventManager = $this->serviceManager->getService('zikula.eventmanager');
     $this->_setup();
     $meta = $this->getMeta();
     if (!isset($meta['displayname']) && !isset($meta['description']) && !isset($meta['version'])) {
         throw new InvalidArgumentException(sprintf('%s->getMeta() must be implemented according to the abstract.  See docblock in Zikula_AbstractPlugin for details', get_class($this)));
     }
     // Load any handlers if they exist
     if ($this->getReflection()->hasMethod('setupHandlerDefinitions')) {
         $this->setupHandlerDefinitions();
     }
 }
Пример #4
0
 /**
  * Invoke handler.
  *
  * @param callable              $handler Callable by PHP.
  * @param Zikula_EventInterface $event   Event object.
  *
  * @return void
  */
 private function invoke($handler, Zikula_EventInterface $event)
 {
     if ($handler instanceof Zikula_ServiceHandler) {
             $service = $this->serviceManager->getService($handler->getId());
             $method = $handler->getMethodName();
             // invoke service method
             $service->$method($event);
     } else {
         if (is_array($handler)) {
             // PHP callable format
             if (is_object($handler[0])) {
                 // invoke instanciated object method.
                 $handler[0]->$handler[1]($event);
             } else {
                 // invoke static class method.
                 $handler[0]::$handler[1]($event);
             }
         } else {
             // invoke function including anonymous functions
             $handler($event);
         }
     }
 }
Пример #5
0
 /**
  * Convenience hasService shortcut.
  *
  * @param string $id Service name.
  *
  * @return boolean
  */
 protected function hasService($id)
 {
     return $this->serviceManager->hasService($id);
 }
Пример #6
0
 /**
  * Reboot.
  *
  * Shutdown the system flushing all event handlers, services and service arguments.
  *
  * @return void
  */
 public function reboot()
 {
     $event = new Zikula_Event('shutdown', $this);
     $this->eventManager->notify($event);
     // flush handlers
     $this->eventManager->flushHandlers();
     // flush all services
     $services = $this->serviceManager->listServices();
     rsort($services);
     foreach ($services as $id) {
         if (!in_array($id, array('zikula', 'zikula.servicemanager', 'zikula.eventmanager'))) {
             $this->serviceManager->unregisterService($id);
         }
     }
     // flush arguments.
     $this->serviceManager->setArguments(array());
     $this->attachedHandlers = array();
     $this->stage = 0;
     $this->bootime = microtime(true);
     $this->attachHandlers($this->handlerDir);
 }
Пример #7
0
 /**
  * Constructor.
  *
  * @param Zikula_ServiceManager $serviceManager ServiceManager.
  * @param string                $moduleName     Module name ("zikula" for system plugins).
  * @param integer|null          $caching        Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
  */
 public function __construct(Zikula_ServiceManager $serviceManager, $moduleName = '', $caching = null)
 {
     $this->serviceManager = $serviceManager;
     $this->eventManager = $this->serviceManager->get('event_dispatcher');
     $this->request = \ServiceUtil::get('request');
     // set the error reporting level
     $this->error_reporting = isset($GLOBALS['ZConfig']['Debug']['error_reporting']) ? $GLOBALS['ZConfig']['Debug']['error_reporting'] : E_ALL;
     $this->error_reporting &= ~E_USER_DEPRECATED;
     $this->allow_php_tag = true;
     // get variables from input
     $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
     $type = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
     $func = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);
     // set vars based on the module structures
     $this->homepage = PageUtil::isHomepage();
     $this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype'));
     $this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc'));
     // Initialize the module property with the name of
     // the topmost module. For Hooks, Blocks, API Functions and others
     // you need to set this property to the name of the respective module!
     $this->toplevelmodule = ModUtil::getName();
     if (!$moduleName) {
         $moduleName = $this->toplevelmodule;
     }
     $this->modinfo = ModUtil::getInfoFromName($moduleName);
     $this->module = array($moduleName => $this->modinfo);
     // initialise environment vars
     $this->language = ZLanguage::getLanguageCode();
     $this->baseurl = System::getBaseUrl();
     $this->baseuri = System::getBaseUri();
     // system info
     $this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
     $this->theme = $theme = $this->themeinfo['directory'];
     $themeBundle = ThemeUtil::getTheme($this->themeinfo['name']);
     //---- Plugins handling -----------------------------------------------
     // add plugin paths
     switch ($this->modinfo['type']) {
         case ModUtil::TYPE_MODULE:
             $mpluginPathNew = "modules/" . $this->modinfo['directory'] . "/Resources/views/plugins";
             $mpluginPath = "modules/" . $this->modinfo['directory'] . "/templates/plugins";
             break;
         case ModUtil::TYPE_SYSTEM:
             $mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins";
             $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
             break;
         default:
             $mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins";
             $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
     }
     // add standard plugin search path
     $this->plugins_dir = array();
     $this->addPluginDir('config/plugins');
     // Official override
     $this->addPluginDir('lib/legacy/viewplugins');
     // Core plugins
     $this->addPluginDir(isset($themeBundle) ? $themeBundle->getRelativePath() . '/plugins' : "themes/{$theme}/plugins");
     // Theme plugins
     $this->addPluginDir('plugins');
     // Smarty core plugins
     $this->addPluginDir($mpluginPathNew);
     // Plugins for current module
     $this->addPluginDir($mpluginPath);
     // Plugins for current module
     // check if the 'type' parameter in the URL is admin or adminplugin
     $legacyControllerType = FormUtil::getPassedValue('lct', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
     if ($type === 'admin' || $type === 'adminplugin' || $legacyControllerType === 'admin') {
         // include plugins of the Admin module to the plugins_dir array
         if (!$this instanceof Zikula_View_Theme) {
             $this->addPluginDir('system/AdminModule/Resources/views/plugins');
         } else {
             $this->load_filter('output', 'admintitle');
         }
     }
     // theme plugins module overrides
     $themePluginsPath = isset($themeBundle) ? $themeBundle->getRelativePath() . '/modules/$moduleName/plugins' : "themes/{$theme}/templates/modules/{$moduleName}/plugins";
     $this->addPluginDir($themePluginsPath);
     //---- Cache handling -------------------------------------------------
     if ($caching && in_array((int) $caching, array(0, 1, 2))) {
         $this->caching = (int) $caching;
     } else {
         $this->caching = (int) ModUtil::getVar('ZikulaThemeModule', 'render_cache');
     }
     $this->compile_id = '';
     $this->cache_id = '';
     // template compilation
     $this->compile_dir = CacheUtil::getLocalDir('view_compiled');
     $this->compile_check = ModUtil::getVar('ZikulaThemeModule', 'render_compile_check');
     $this->force_compile = ModUtil::getVar('ZikulaThemeModule', 'render_force_compile');
     // template caching
     $this->cache_dir = CacheUtil::getLocalDir('view_cache');
     $this->cache_lifetime = ModUtil::getVar('ZikulaThemeModule', 'render_lifetime');
     $this->expose_template = ModUtil::getVar('ZikulaThemeModule', 'render_expose_template') == true ? true : false;
     // register resource type 'z' this defines the way templates are searched
     // during {include file='my_template.tpl'} this enables us to store selected module
     // templates in the theme while others can be kept in the module itself.
     $this->register_resource('z', array('Zikula_View_Resource', 'z_get_template', 'z_get_timestamp', 'z_get_secure', 'z_get_trusted'));
     // set 'z' as default resource type
     $this->default_resource_type = 'z';
     // process some plugins specially when Render cache is enabled
     if (!$this instanceof Zikula_View_Theme && $this->caching) {
         $this->register_nocache_plugins();
     }
     // register the 'nocache' block to allow dynamic zones caching templates
     $this->register_block('nocache', array('Zikula_View_Resource', 'block_nocache'), false);
     // For ajax requests we use the short urls filter to 'fix' relative paths
     if ($this->serviceManager->get('zikula')->getStage() & Zikula_Core::STAGE_AJAX && System::getVar('shorturls')) {
         $this->load_filter('output', 'shorturls');
     }
     // register prefilters
     $this->register_prefilter('z_prefilter_add_literal');
     $this->register_prefilter('z_prefilter_gettext_params');
     //$this->register_prefilter('z_prefilter_notifyfilters');
     // assign some useful settings
     $this->assign('homepage', $this->homepage)->assign('modinfo', $this->modinfo)->assign('module', $moduleName)->assign('toplevelmodule', $this->toplevelmodule)->assign('type', $this->type)->assign('func', $this->func)->assign('lang', $this->language)->assign('themeinfo', $this->themeinfo)->assign('themepath', isset($themeBundle) ? $themeBundle->getRelativePath() : $this->baseurl . 'themes/' . $theme)->assign('baseurl', $this->baseurl)->assign('baseuri', $this->baseuri)->assign('moduleBundle', ModUtil::getModule($moduleName))->assign('themeBundle', $themeBundle);
     if (isset($themeBundle)) {
         $stylePath = $themeBundle->getRelativePath() . "/Resources/public/css";
         $javascriptPath = $themeBundle->getRelativePath() . "/Resources/public/js";
         $imagePath = $themeBundle->getRelativePath() . "/Resources/public/images";
         $imageLangPath = $themeBundle->getRelativePath() . "/Resources/public/images/" . $this->language;
     } else {
         $stylePath = $this->baseurl . "themes/{$theme}/style";
         $javascriptPath = $this->baseurl . "themes/{$theme}/javascript";
         $imagePath = $this->baseurl . "themes/{$theme}/images";
         $imageLangPath = $this->baseurl . "themes/{$theme}/images/" . $this->language;
     }
     $this->assign('stylepath', $stylePath)->assign('scriptpath', $javascriptPath)->assign('imagepath', $imagePath)->assign('imagelangpath', $imageLangPath);
     // for {gt} template plugin to detect gettext domain
     if ($this->modinfo['type'] == ModUtil::TYPE_MODULE) {
         $this->domain = ZLanguage::getModuleDomain($this->modinfo['name']);
     }
     // make render object available to modifiers
     parent::assign('zikula_view', $this);
     // add ServiceManager, EventManager and others to all templates
     parent::assign('serviceManager', $this->serviceManager);
     parent::assign('eventManager', $this->eventManager);
     parent::assign('zikula_core', $this->serviceManager->get('zikula'));
     parent::assign('request', $this->request);
     $modvars = ModUtil::getModvars();
     // Get all modvars from any modules that have accessed their modvars at least once.
     // provide compatibility 'alias' array keys
     // @todo remove after v1.4.0
     if (isset($modvars['ZikulaAdminModule'])) {
         $modvars['Admin'] = $modvars['ZikulaAdminModule'];
     }
     if (isset($modvars['ZikulaBlocksModule'])) {
         $modvars['Blocks'] = $modvars['ZikulaBlocksModule'];
     }
     if (isset($modvars['ZikulaCategoriesModule'])) {
         $modvars['Categories'] = $modvars['ZikulaCategoriesModule'];
     }
     if (isset($modvars['ZikulaExtensionsModule'])) {
         $modvars['Extensions'] = $modvars['ZikulaExtensionsModule'];
     }
     if (isset($modvars['ZikulaGroupsModule'])) {
         $modvars['Groups'] = $modvars['ZikulaGroupsModule'];
     }
     if (isset($modvars['ZikulaMailerModule'])) {
         $modvars['Mailer'] = $modvars['ZikulaMailerModule'];
     }
     if (isset($modvars['ZikulaPageLockModule'])) {
         $modvars['PageLock'] = $modvars['ZikulaPageLockModule'];
     }
     if (isset($modvars['ZikulaPermissionsModule'])) {
         $modvars['Permissions'] = $modvars['ZikulaPermissionsModule'];
     }
     if (isset($modvars['ZikulaSearchModule'])) {
         $modvars['Search'] = $modvars['ZikulaSearchModule'];
     }
     if (isset($modvars['ZikulaSecurityCenterModule'])) {
         $modvars['SecurityCenter'] = $modvars['ZikulaSecurityCenterModule'];
     }
     if (isset($modvars['ZikulaSettingsModule'])) {
         $modvars['Settings'] = $modvars['ZikulaSettingsModule'];
     }
     if (isset($modvars['ZikulaThemeModule'])) {
         $modvars['Theme'] = $modvars['ZikulaThemeModule'];
     }
     if (isset($modvars['ZikulaUsersModule'])) {
         $modvars['Users'] = $modvars['ZikulaUsersModule'];
     }
     // end compatibility aliases
     parent::assign('modvars', $modvars);
     $this->add_core_data();
     // metadata for SEO
     if (!$this->serviceManager->hasParameter('zikula_view.metatags')) {
         $this->serviceManager->setParameter('zikula_view.metatags', new ArrayObject(array()));
     }
     parent::assign('metatags', $this->serviceManager->getParameter('zikula_view.metatags'));
     if (isset($themeBundle) && $themeBundle->isTwigBased()) {
         // correct asset urls when smarty output is wrapped by twig theme
         $this->load_filter('output', 'asseturls');
     }
     $event = new \Zikula\Core\Event\GenericEvent($this);
     $this->eventManager->dispatch('view.init', $event);
 }
Пример #8
0
    /**
     * Constructor.
     *
     * @param Zikula_ServiceManager $serviceManager ServiceManager.
     * @param string                $moduleName     Module name ("zikula" for system plugins).
     * @param integer|null          $caching        Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
     */
    public function __construct(Zikula_ServiceManager $serviceManager, $moduleName = '', $caching = null)
    {
        $this->serviceManager = $serviceManager;
        $this->eventManager = $this->serviceManager->getService('zikula.eventmanager');
        $this->request = $this->serviceManager->getService('request');

        // set the error reporting level
        $this->error_reporting = isset($GLOBALS['ZConfig']['Debug']['error_reporting']) ? $GLOBALS['ZConfig']['Debug']['error_reporting'] : E_ALL;
        $this->allow_php_tag = true;

        // get variables from input
        $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
        $type   = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
        $func   = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);

        // set vars based on the module structures
        $this->homepage = empty($module) ? true : false;
        $this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype'));
        $this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc'));

        // Initialize the module property with the name of
        // the topmost module. For Hooks, Blocks, API Functions and others
        // you need to set this property to the name of the respective module!
        $this->toplevelmodule = ModUtil::getName();

        if (!$moduleName) {
            $moduleName = $this->toplevelmodule;
        }
        $this->modinfo = ModUtil::getInfoFromName($moduleName);
        $this->module  = array($moduleName => $this->modinfo);

        // initialise environment vars
        $this->language = ZLanguage::getLanguageCode();
        $this->baseurl = System::getBaseUrl();
        $this->baseuri = System::getBaseUri();

        // system info
        $this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
        $this->theme = $theme = $this->themeinfo['directory'];

        //---- Plugins handling -----------------------------------------------
        // add plugin paths
        switch ($this->modinfo['type'])
        {
            case ModUtil::TYPE_MODULE :
                $mpluginPath = "modules/" . $this->modinfo['directory'] . "/templates/plugins";
                $mpluginPathOld = "modules/" . $this->modinfo['directory'] . "/pntemplates/plugins";
                break;
            case ModUtil::TYPE_SYSTEM :
                $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
                $mpluginPathOld = "system/" . $this->modinfo['directory'] . "/pntemplates/plugins";
                break;
            default:
                $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
                $mpluginPathOld = "system/" . $this->modinfo['directory'] . "/pntemplates/plugins";
        }

        // add standard plugin search path
        $this->plugins_dir = array();
        $this->addPluginDir('config/plugins'); // Official override
        $this->addPluginDir('lib/viewplugins'); // Core plugins
        $this->addPluginDir("themes/$theme/plugins"); // Theme plugins
        $this->addPluginDir('plugins'); // Smarty core plugins
        $this->addPluginDir($mpluginPath); // Plugins for current module

        // check if the 'type' parameter in the URL is admin and if yes,
        // include system/Admin/templates/plugins to the plugins_dir array
        if ($type === 'admin') {
            if (!$this instanceof Zikula_View_Theme) {
                $this->addPluginDir('system/Admin/templates/plugins');
            } else {
                $this->load_filter('output', 'admintitle');
            }
        }

        // adds legacy plugin paths if needed
        if (System::isLegacyMode()) {
            $this->addPluginDir('lib/legacy/plugins'); // Core legacy plugins
            $this->addPluginDir($mpluginPathOld); // Module plugins (legacy paths)
            $this->addPluginDir("themes/$theme/templates/modules/$moduleName/plugins"); // Module override in themes
        }

        //---- Cache handling -------------------------------------------------
        if ($caching && in_array((int)$caching, array(0, 1, 2))) {
            $this->caching = (int)$caching;
        } else {
            $this->caching = (int)ModUtil::getVar('Theme', 'render_cache');
        }

        // write actions should not be cached or weird things happen
        if (isset($_POST) && count($_POST) != 0) {
            $this->caching = Zikula_View::CACHE_DISABLED;
        }

        $this->compile_id  = '';
        $this->cache_id    = '';

        // template compilation
        $this->compile_dir    = CacheUtil::getLocalDir('view_compiled');
        $this->compile_check  = ModUtil::getVar('Theme', 'render_compile_check');
        $this->force_compile  = ModUtil::getVar('Theme', 'render_force_compile');
        // template caching
        $this->cache_dir      = CacheUtil::getLocalDir('view_cache');
        $this->cache_lifetime = ModUtil::getVar('Theme', 'render_lifetime');

        $this->expose_template = (ModUtil::getVar('Theme', 'render_expose_template') == true) ? true : false;

        // register resource type 'z' this defines the way templates are searched
        // during {include file='my_template.tpl'} this enables us to store selected module
        // templates in the theme while others can be kept in the module itself.
        $this->register_resource('z', array('Zikula_View_Resource',
                                            'z_get_template',
                                            'z_get_timestamp',
                                            'z_get_secure',
                                            'z_get_trusted'));

        // set 'z' as default resource type
        $this->default_resource_type = 'z';

        // process some plugins specially when Render cache is enabled
        if (!$this instanceof Zikula_View_Theme && $this->caching) {
            $this->register_nocache_plugins();
        }

        // register the 'nocache' block to allow dynamic zones caching templates
        $this->register_block('nocache', array('Zikula_View_Resource', 'block_nocache'), false);

        // For ajax requests we use the short urls filter to 'fix' relative paths
        if (($this->serviceManager->getService('zikula')->getStage() & Zikula_Core::STAGE_AJAX) && System::getVar('shorturls')) {
            $this->load_filter('output', 'shorturls');
        }

        // register prefilters
        $this->register_prefilter('z_prefilter_add_literal');

        if ($GLOBALS['ZConfig']['System']['legacy_prefilters']) {
            $this->register_prefilter('z_prefilter_legacy');
        }

        $this->register_prefilter('z_prefilter_gettext_params');
        //$this->register_prefilter('z_prefilter_notifyfilters');

        // assign some useful settings
        $this->assign('homepage', $this->homepage)
             ->assign('modinfo', $this->modinfo)
             ->assign('module', $moduleName)
             ->assign('toplevelmodule', $this->toplevelmodule)
             ->assign('type', $this->type)
             ->assign('func', $this->func)
             ->assign('lang', $this->language)
             ->assign('themeinfo', $this->themeinfo)
             ->assign('themepath', $this->baseurl . 'themes/' . $theme)
             ->assign('baseurl', $this->baseurl)
             ->assign('baseuri', $this->baseuri);

        if (System::isLegacyMode()) {
            $this->assign('stylepath', $this->baseurl . 'themes/' . $theme . '/style')
                 ->assign('scriptpath', $this->baseurl . 'themes/' . $theme . '/javascript')
                 ->assign('imagepath', $this->baseurl . 'themes/' . $theme . '/images')
                 ->assign('imagelangpath', $this->baseurl . 'themes/' . $theme . '/images/' . $this->language);
        }

        // for {gt} template plugin to detect gettext domain
        if ($this->modinfo['type'] == ModUtil::TYPE_MODULE) {
            $this->domain = ZLanguage::getModuleDomain($this->modinfo['name']);
        }

        // make render object available to modifiers
        parent::assign('zikula_view', $this);

        // add ServiceManager, EventManager and others to all templates
        parent::assign('serviceManager', $this->serviceManager);
        parent::assign('eventManager', $this->eventManager);
        parent::assign('zikula_core', $this->serviceManager->getService('zikula'));
        parent::assign('request', $this->request);
        parent::assign('modvars', ModUtil::getModvars()); // Get all modvars from any modules that have accessed their modvars at least once.

        $this->add_core_data();

        // metadata for SEO
        if (!isset($this->serviceManager['zikula_view.metatags'])) {
            $this->serviceManager['zikula_view.metatags'] = new ArrayObject(array());
        }

        parent::assign('metatags', $this->serviceManager['zikula_view.metatags']);

        $event = new Zikula_Event('view.init', $this);
        $this->eventManager->notify($event);
    }
Пример #9
0
 /**
  * Constructor.
  *
  * @param Zikula_ServiceManager $serviceManager Servicemanager.
  */
 public function __construct(Zikula_ServiceManager $serviceManager)
 {
     $this->serviceManager = $serviceManager;
     $this->eventManager = $this->serviceManager->getService('zikula.eventmanager');
     $this->event = new Zikula_Event('log', $this);
 }
Пример #10
0
 /**
  * Constructor.
  *
  * @param Zikula_ServiceManager $serviceManager ServiceManager.
  */
 public function __construct(Zikula_ServiceManager $serviceManager)
 {
     $this->serviceManager = $serviceManager;
     $this->mailer = $serviceManager->getService('mailer');
 }
Пример #11
0
 /**
  * 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)));
     }
 }
Пример #12
0
 /**
  * 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)));
     }
 }