Exemplo n.º 1
0
 /**
  * Display block.
  *
  * @param  array  $blockinfo Blockinfo structure.
  *
  * @return output Rendered block.
  */
 public function display($blockinfo)
 {
     if (!SecurityUtil::checkPermission('PendingContent::', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) {
         return;
     }
     // trigger event
     $event = new Zikula_Event('get.pending_content', new Zikula_Collection_Container('pending_content'));
     $pendingCollection = EventUtil::getManager()->notify($event)->getSubject();
     $content = array();
     // process results
     foreach ($pendingCollection as $collection) {
         $module = $collection->getName();
         foreach ($collection as $item) {
             $link = ModUtil::url($module, $item->getController(), $item->getMethod(), $item->getArgs());
             $content[] = array('description' => $item->getDescription(), 'link' => $link, 'number' => $item->getNumber());
         }
     }
     if (!empty($content)) {
         $this->view->assign('content', $content);
         $blockinfo['content'] = $this->view->fetch('blocks_block_pendingcontent.tpl');
     } else {
         $blockinfo['content'] = '';
     }
     return BlockUtil::themeBlock($blockinfo);
 }
 protected function bootstrap($disableSessions = true, $loadZikulaCore = true, $fakeRequest = true)
 {
     define('_ZINSTALLVER', \Zikula_Core::VERSION_NUM);
     $kernel = $this->getContainer()->get('kernel');
     $loader = (require $kernel->getRootDir() . '/autoload.php');
     \ZLoader::register($loader);
     if ($loadZikulaCore && !$this->getContainer()->has('zikula')) {
         $core = new Zikula_Core();
         $core->setKernel($kernel);
         $core->boot();
         foreach ($GLOBALS['ZConfig'] as $config) {
             $core->getContainer()->loadArguments($config);
         }
         $GLOBALS['ZConfig']['System']['temp'] = $core->getContainer()->getParameter('temp_dir');
         $GLOBALS['ZConfig']['System']['datadir'] = $core->getContainer()->getParameter('datadir');
         $GLOBALS['ZConfig']['System']['system.chmod_dir'] = $core->getContainer()->getParameter('system.chmod_dir');
         \ServiceUtil::getManager($core);
         \EventUtil::getManager($core);
     }
     if ($disableSessions) {
         // Disable sessions.
         $this->getContainer()->set('session.storage', new MockArraySessionStorage());
         $this->getContainer()->set('session.handler', new NullSessionHandler());
     }
     if ($fakeRequest) {
         // Fake request
         $request = Request::create('http://localhost/install');
         $this->getContainer()->set('request', $request);
     }
 }
Exemplo n.º 3
0
 public static function getPlugins($type = 'Content')
 {
     $type = in_array($type, array('Content', 'Layout')) ? trim(ucwords(strtolower($type))) . "Type" : 'ContentType';
     // trigger event
     $event = new Zikula_Event('module.content.gettypes', new Content_Types());
     $plugins = EventUtil::getManager()->notify($event)->getSubject()->getValidatedPlugins($type);
     return $plugins;
 }
Exemplo n.º 4
0
 /**
  * Initialises own (and legacy) components, like service manager.
  */
 protected function bootstrap()
 {
     // taken from lib/bootstrap.php
     // legacy handling
     $core = new \Zikula_Core();
     $core->setKernel($this->kernel);
     $core->boot();
     // these two events are called for BC only. remove in 2.0.0
     $core->getDispatcher()->dispatch('bootstrap.getconfig', new GenericEvent($core));
     $core->getDispatcher()->dispatch('bootstrap.custom', new GenericEvent($core));
     foreach ($GLOBALS['ZConfig'] as $config) {
         $core->getContainer()->loadArguments($config);
     }
     $GLOBALS['ZConfig']['System']['temp'] = $core->getContainer()->getParameter('temp_dir');
     $GLOBALS['ZConfig']['System']['datadir'] = $core->getContainer()->getParameter('datadir');
     $GLOBALS['ZConfig']['System']['system.chmod_dir'] = $core->getContainer()->getParameter('system.chmod_dir');
     \ServiceUtil::getManager($core);
     \EventUtil::getManager($core);
     $core->attachHandlers('config/EventHandlers');
     return $core;
 }
Exemplo n.º 5
0
 /**
  * Procedure for managinig stylesheets.
  *
  * @param array   $stylesheets List of demanded stylesheets.
  * @param array   $themeinfo   array of info on current theme
  * @param boolean $isAdminController
  *
  * @return array List of stylesheets
  */
 public static function prepareStylesheets($stylesheets, $themeinfo = array(), $isAdminController = false)
 {
     if (ThemeUtil::getVar('noCoreCss', false)) {
         $initStyle = null;
     } else {
         $initStyle = array('style/core.css');
     }
     // Add generic stylesheet as the first stylesheet.
     $event = new \Zikula\Core\Event\GenericEvent('stylesheet', array(), $initStyle);
     $coreStyle = EventUtil::getManager()->dispatch('pageutil.addvar_filter', $event)->getData();
     if (!is_array($stylesheets)) {
         $stylesheets = array();
     }
     // Add legacy stylesheet
     if (System::isLegacyMode('1.4.0')) {
         array_unshift($stylesheets, 'style/legacy.css');
     }
     // Add core stylesheet
     array_unshift($stylesheets, $coreStyle[0]);
     // is theme a 1.4.0 type bundle?
     $theme = null;
     if (!empty($themeinfo)) {
         $theme = ThemeUtil::getTheme($themeinfo['name']);
     }
     // Add bootstrap stylesheet only for 1.4.x type themes or if an admin controller is in use
     if (isset($theme) || $isAdminController) {
         $overrideBootstrapPath = ThemeUtil::getVar('bootstrapPath', '');
         // allows for theme override of bootstrap css path
         if (empty($overrideBootstrapPath)) {
             $bootstrapFontAwesomePath = ServiceUtil::getManager()->getParameter('zikula.stylesheet.bootstrap-font-awesome.path');
             array_unshift($stylesheets, $bootstrapFontAwesomePath);
         }
         // Add font-awesome
         if (!empty($overrideBootstrapPath)) {
             $fontAwesomePath = ServiceUtil::getManager()->getParameter('zikula.stylesheet.fontawesome.min.path');
             array_unshift($stylesheets, $fontAwesomePath);
         }
         $stylesheets = array_unique(array_values($stylesheets));
     }
     $iehack = '<!--[if IE]><link rel="stylesheet" type="text/css" href="style/core_iehacks.css" media="print,projection,screen" /><![endif]-->';
     PageUtil::addVar('header', $iehack);
     return $stylesheets;
 }
Exemplo n.º 6
0
 /**
  * Listens for 'bootstrap.getconfig' event.
  *
  * @param Zikula_Event $event Event.
  *
  * @return void
  */
 public function initialHandlerScan(Zikula_Event $event)
 {
     $core = $this->serviceManager->getService('zikula');
     ServiceUtil::getManager($core);
     EventUtil::getManager($core);
     $core->attachHandlers('config/EventHandlers');
 }
Exemplo n.º 7
0
 /**
  * Execute a template override event.
  *
  * @param string $template Path to template.
  *
  * @throws InvalidArgumentException If event handler returns a non-existent template.
  *
  * @return mixed String if found, false if no override present.
  */
 public static function getTemplateOverride($template)
 {
     $event = new \Zikula\Core\Event\GenericEvent(null, array(), $template);
     EventUtil::getManager()->dispatch('zikula_view.template_override', $event);
     if ($event->isPropagationStopped()) {
         $ostemplate = DataUtil::formatForOS($event->getData());
         if (is_readable($ostemplate)) {
             return $ostemplate;
         } else {
             throw new InvalidArgumentException(__f('zikula_view.template_override returned a non-existent template path %s', $ostemplate));
         }
     }
     return false;
 }
Exemplo n.º 8
0
    /**
     * Add var.
     *
     * Adds a new vaule to a page variable. In the case of a single
     * page variable, this functions acts exactly like PageUtil::setVar.
     *
     * @param string $varname The name of the page variable.
     * @param mixed  $value   The new value.
     *
     * @see    PageUtil::setVar
     * @return boolean true On success, false of the page variable is not registered.
     */
    public static function addVar($varname, $value)
    {
        global $_pageVars;

        if (System::isLegacyMode()) {
            switch ($varname) {
                case 'rawtext':
                    LogUtil::log(__f('Warning! The page variable %1$s is deprecated. Please use %2$s instead.', array('rawtext', 'header')), E_USER_DEPRECATED);
                    $varname = 'header';
                    break;
            }
        }
        
        // check for $_pageVars sanity
        if (!isset($_pageVars)) {
            $_pageVars = array();
        } elseif (!is_array($_pageVars)) {
            return false;
        }

        if (!isset($_pageVars[$varname])) {
            return false;
        }

        if (is_array($value)) {
            $value = array_unique($value);
        }

        $event = new Zikula_Event('pageutil.addvar_filter', $varname, array(), $value);
        $value = EventUtil::getManager()->notify($event)->getData();

        if ($_pageVars[$varname]['multivalue']) {
            if (is_array($value)) {
                $_pageVars[$varname]['contents'] = array_merge($_pageVars[$varname]['contents'], $value);
            } else {
                $_pageVars[$varname]['contents'][] = $value;
            }
            // make values unique
            $_pageVars[$varname]['contents'] = array_unique($_pageVars[$varname]['contents']);
        } else {
            $_pageVars[$varname]['contents'] = $value;
        }

        return true;
    }
Exemplo n.º 9
0
 /**
  * Available plugins list.
  *
  * @return array List of the available plugins.
  */
 public static function getPluginsAvailable()
 {
     $classNames = array();
     $classNames['category'] = 'FilterUtil_Filter_Category';
     $classNames['default'] = 'FilterUtil_Filter_Default';
     $classNames['date'] = 'FilterUtil_Filter_Date';
     $classNames['mnlist'] = 'FilterUtil_Filter_Mnlist';
     $classNames['pmlist'] = 'FilterUtil_Filter_Pmlist';
     $classNames['replaceName'] = 'FilterUtil_Filter_ReplaceName';
     // collect classes from other providers also allows for override
     // TODO A [This is only allowed for the module which owns this object.]
     $event = new GenericEvent();
     $event->setData($classNames);
     EventUtil::getManager()->dispatch('zikula.filterutil.get_plugin_classes', $event);
     $classNames = $event->getData();
     return $classNames;
 }
Exemplo n.º 10
0
 /**
  * Run a module function.
  *
  * @param string  $modname    The name of the module.
  * @param string  $type       The type of function to run.
  * @param string  $func       The specific function to run.
  * @param array   $args       The arguments to pass to the function.
  * @param boolean $api        Whether or not to execute an API (or regular) function.
  * @param string  $instanceof Perform instanceof checking of target class.
  *
  * @throws Zikula_Exception_NotFound If method was not found.
  * @throws InvalidArgumentException  If the controller is not an instance of the class specified in $instanceof.
  *
  * @return mixed.
  */
 public static function exec($modname, $type = 'user', $func = 'main', $args = array(), $api = false, $instanceof = null)
 {
     // define input, all numbers and booleans to strings
     $modname = isset($modname) ? (string) $modname : '';
     $ftype = $api ? 'api' : '';
     $loadfunc = $api ? 'ModUtil::loadApi' : 'ModUtil::load';
     // validate
     if (!System::varValidate($modname, 'mod')) {
         return null;
     }
     // Remove from 1.4
     if (System::isLegacyMode() && $modname == 'Modules') {
         LogUtil::log(__('Warning! "Modules" module has been renamed to "Extensions".  Please update your ModUtil::func() and ModUtil::apiFunc() calls.'));
         $modname = 'Extensions';
     }
     $modinfo = self::getInfo(self::getIDFromName($modname));
     $path = $modinfo['type'] == self::TYPE_SYSTEM ? 'system' : 'modules';
     $controller = null;
     $modfunc = null;
     $loaded = call_user_func_array($loadfunc, array($modname, $type));
     if (self::isOO($modname)) {
         $result = self::getCallable($modname, $type, $func, $api);
         if ($result) {
             $modfunc = $result['callable'];
             $controller = $modfunc[0];
             if (!is_null($instanceof)) {
                 if (!$controller instanceof $instanceof) {
                     throw new InvalidArgumentException(__f('%1$s must be an instance of $2$s', array(get_class($controller), $instanceof)));
                 }
             }
         }
     }
     $modfunc = $modfunc ? $modfunc : "{$modname}_{$type}{$ftype}_{$func}";
     $eventManager = EventUtil::getManager();
     if ($loaded) {
         $preExecuteEvent = new Zikula_Event('module_dispatch.preexecute', $controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api));
         $postExecuteEvent = new Zikula_Event('module_dispatch.postexecute', $controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api));
         if (is_callable($modfunc)) {
             $eventManager->notify($preExecuteEvent);
             // Check $modfunc is an object instance (OO) or a function (old)
             if (is_array($modfunc)) {
                 if ($modfunc[0] instanceof Zikula_AbstractController) {
                     $reflection = call_user_func(array($modfunc[0], 'getReflection'));
                     $subclassOfReflection = new ReflectionClass($reflection->getParentClass());
                     if ($subclassOfReflection->hasMethod($modfunc[1])) {
                         // Don't allow front controller to access any public methods inside the controller's parents
                         throw new Zikula_Exception_NotFound();
                     }
                     $modfunc[0]->preDispatch();
                 }
                 $postExecuteEvent->setData(call_user_func($modfunc, $args));
                 if ($modfunc[0] instanceof Zikula_AbstractController) {
                     $modfunc[0]->postDispatch();
                 }
             } else {
                 $postExecuteEvent->setData($modfunc($args));
             }
             return $eventManager->notify($postExecuteEvent)->getData();
         }
         // get the theme
         if (ServiceUtil::getManager()->getService('zikula')->getStage() & Zikula_Core::STAGE_THEME) {
             $theme = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
             if (file_exists($file = 'themes/' . $theme['directory'] . '/functions/' . $modname . "/{$type}{$ftype}/{$func}.php") || file_exists($file = 'themes/' . $theme['directory'] . '/functions/' . $modname . "/pn{$type}{$ftype}/{$func}.php")) {
                 include_once $file;
                 if (function_exists($modfunc)) {
                     EventUtil::notify($preExecuteEvent);
                     $postExecuteEvent->setData($modfunc($args));
                     return EventUtil::notify($postExecuteEvent)->getData();
                 }
             }
         }
         if (file_exists($file = "config/functions/{$modname}/{$type}{$ftype}/{$func}.php") || file_exists($file = "config/functions/{$modname}/pn{$type}{$ftype}/{$func}.php")) {
             include_once $file;
             if (is_callable($modfunc)) {
                 $eventManager->notify($preExecuteEvent);
                 $postExecuteEvent->setData($modfunc($args));
                 return $eventManager->notify($postExecuteEvent)->getData();
             }
         }
         if (file_exists($file = "{$path}/{$modname}/{$type}{$ftype}/{$func}.php") || file_exists($file = "{$path}/{$modname}/pn{$type}{$ftype}/{$func}.php")) {
             include_once $file;
             if (is_callable($modfunc)) {
                 $eventManager->notify($preExecuteEvent);
                 $postExecuteEvent->setData($modfunc($args));
                 return $eventManager->notify($postExecuteEvent)->getData();
             }
         }
         // try to load plugin
         // This kind of eventhandler should
         // 1. Check $event['modfunc'] to see if it should run else exit silently.
         // 2. Do something like $result = {$event['modfunc']}({$event['args'});
         // 3. Save the result $event->setData($result).
         // 4. $event->setNotify().
         // return void
         // This event means that no $type was found
         $event = new Zikula_Event('module_dispatch.type_not_found', null, array('modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api), false);
         $eventManager->notify($event);
         if ($preExecuteEvent->isStopped()) {
             return $preExecuteEvent->getData();
         }
         return false;
     }
     // Issue not found exception for controller requests
     if (!System::isLegacyMode() && !$api) {
         throw new Zikula_Exception_NotFound(__f('The requested controller action %s_Controller_%s::%s() could not be found', array($modname, $type, $func)));
     }
 }
Exemplo n.º 11
0
 /**
  * Procedure for managinig stylesheets.
  *
  * @param array $stylesheets List of demanded stylesheets.
  *
  * @return array List of stylesheets
  */
 public static function prepareStylesheets($stylesheets)
 {
     // Add generic stylesheet as the first stylesheet.
     $event = new GenericEvent('stylesheet', array(), array('style/core.css'));
     $coreStyle = EventUtil::getManager()->dispatch('pageutil.addvar_filter', $event);
     $coreStyle = $event->getData();
     if (is_array($stylesheets)) {
         array_unshift($stylesheets, $coreStyle[0]);
     } else {
         $stylesheets = array($coreStyle[0]);
     }
     $stylesheets = array_unique(array_values($stylesheets));
     $iehack = '<!--[if IE]><link rel="stylesheet" type="text/css" href="style/core_iehacks.css" media="print,projection,screen" /><![endif]-->';
     PageUtil::addVar('header', $iehack);
     return $stylesheets;
 }
Exemplo n.º 12
0
 /**
  * Run a module function.
  *
  * @param string  $modname    The name of the module.
  * @param string  $type       The type of function to run.
  * @param string  $func       The specific function to run.
  * @param array   $args       The arguments to pass to the function.
  * @param boolean $api        Whether or not to execute an API (or regular) function.
  * @param string  $instanceof Perform instanceof checking of target class.
  *
  * @throws Zikula_Exception_NotFound If method was not found.
  * @throws InvalidArgumentException  If the controller is not an instance of the class specified in $instanceof.
  *
  * @return mixed.
  */
 public static function exec($modname, $type = 'user', $func = 'main', $args = array(), $api = false, $instanceof = null)
 {
     // define input, all numbers and booleans to strings
     $modname = isset($modname) ? (string) $modname : '';
     $modname = static::convertModuleName($modname);
     // validate
     if (!System::varValidate($modname, 'mod')) {
         return null;
     }
     // Remove from 1.4
     if (System::isLegacyMode('1.4.0') && $modname == 'Modules') {
         LogUtil::log(__('Warning! "Modules" module has been renamed to "ZikulaExtensionsModule".  Please update your ModUtil::func() and ModUtil::apiFunc() calls.'));
         $modname = 'ZikulaExtensionsModule';
     }
     $modinfo = self::getInfo(self::getIDFromName($modname));
     $controller = null;
     $modfunc = null;
     $loaded = call_user_func_array($api ? 'ModUtil::loadApi' : 'ModUtil::load', array($modname, $type));
     if (self::isOO($modname)) {
         $result = self::getCallable($modname, $type, $func, $api);
         if ($result) {
             $modfunc = $result['callable'];
             $controller = $modfunc[0];
             if (!is_null($instanceof)) {
                 if (!$controller instanceof $instanceof) {
                     throw new InvalidArgumentException(__f('%1$s must be an instance of $2$s', array(get_class($controller), $instanceof)));
                 }
             }
         }
     }
     $eventManager = EventUtil::getManager();
     $sm = ServiceUtil::getManager();
     if ($loaded) {
         $preExecuteEvent = new \Zikula\Core\Event\GenericEvent($controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api));
         $postExecuteEvent = new \Zikula\Core\Event\GenericEvent($controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api));
         if (is_callable($modfunc)) {
             $eventManager->dispatch('module_dispatch.preexecute', $preExecuteEvent);
             // Check $modfunc is an object instance (OO) or a function (old)
             if (is_array($modfunc)) {
                 try {
                     self::getModule($modname);
                     $newType = true;
                 } catch (\Exception $e) {
                     $newType = false;
                 }
                 if ($args) {
                     $newType = false;
                 }
                 if (!$api && $newType) {
                     // resolve request args.
                     $resolver = new ControllerResolver($sm, new ControllerNameParser(ServiceUtil::get('kernel')));
                     try {
                         $r = new \ReflectionClass($modfunc[0]);
                         if (!$r->hasMethod($modfunc[1])) {
                             // Method doesn't exist. Do some BC handling.
                             // First try to remove the 'Action' suffix.
                             $modfunc[1] = preg_replace('/(\\w+)Action$/', '$1', $modfunc[1]);
                             if (!$r->hasMethod($modfunc[1])) {
                                 // Method still not found. Try to use the old 'main' method name.
                                 if ($modfunc[1] == 'index') {
                                     $modfunc[1] = $r->hasMethod('mainAction') ? 'mainAction' : 'main';
                                 }
                             }
                         }
                         if ($r->hasMethod($modfunc[1])) {
                             // Did we get a valid method? If so, resolve arguments!
                             $methodArgs = $resolver->getArguments($sm->get('request'), $modfunc);
                         } else {
                             // We still didn't get a valid method. Do not use argument resolving.
                             $newType = false;
                         }
                     } catch (\RuntimeException $e) {
                         // Something went wrong. Check if the method still uses the old non-Symfony $args array.
                         if ($modfunc[0] instanceof \Zikula_AbstractBase) {
                             $r = new \ReflectionMethod($modfunc[0], $modfunc[1]);
                             $parameters = $r->getParameters();
                             if (count($parameters) == 1) {
                                 $firstParameter = $parameters[0];
                                 if ($firstParameter->getName() == 'args') {
                                     // The method really uses the old $args parameter. In this case we can continue
                                     // using the old Controller call and don't have to throw an exception.
                                     $newType = false;
                                 }
                             }
                         }
                         if ($newType !== false) {
                             throw $e;
                         }
                     }
                 }
                 if ($modfunc[0] instanceof Zikula_AbstractController) {
                     $reflection = call_user_func(array($modfunc[0], 'getReflection'));
                     $subclassOfReflection = new ReflectionClass($reflection->getParentClass());
                     if ($subclassOfReflection->hasMethod($modfunc[1])) {
                         // Don't allow front controller to access any public methods inside the controller's parents
                         throw new Zikula_Exception_NotFound();
                     }
                     $modfunc[0]->preDispatch();
                 }
                 if (!$api && $newType && isset($methodArgs)) {
                     $postExecuteEvent->setData(call_user_func_array($modfunc, $methodArgs));
                 } else {
                     $postExecuteEvent->setData(call_user_func($modfunc, $args));
                 }
                 if ($modfunc[0] instanceof Zikula_AbstractController) {
                     $modfunc[0]->postDispatch();
                 }
             } else {
                 $postExecuteEvent->setData($modfunc($args));
             }
             return $eventManager->dispatch('module_dispatch.postexecute', $postExecuteEvent)->getData();
         }
         // try to load plugin
         // This kind of eventhandler should
         // 1. Check $event['modfunc'] to see if it should run else exit silently.
         // 2. Do something like $result = {$event['modfunc']}({$event['args'});
         // 3. Save the result $event->setData($result).
         // 4. $event->setNotify().
         // return void
         // This event means that no $type was found
         $event = new \Zikula\Core\Event\GenericEvent(null, array('modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api), false);
         $eventManager->dispatch('module_dispatch.type_not_found', $event);
         if ($preExecuteEvent->isPropagationStopped()) {
             return $preExecuteEvent->getData();
         }
         return false;
     }
     // Issue not found exception for controller requests
     if (!System::isLegacyMode() && !$api) {
         throw new Zikula_Exception_NotFound(__f('The requested controller action %s_Controller_%s::%s() could not be found', array($modname, $type, $func)));
     }
 }
Exemplo n.º 13
0
function installmodules($lang = 'en')
{
    // This is a temporary hack for release 1.3.x to be able to install modules
    // load Doctrine plugin
    include_once __DIR__ . '/../plugins/Doctrine/Plugin.php';
    PluginUtil::loadPlugin('SystemPlugin_Doctrine_Plugin');
    // load DoctrineExtensions plugin
    include_once __DIR__ . '/../plugins/DoctrineExtensions/Plugin.php';
    PluginUtil::loadPlugin('SystemPlugin_DoctrineExtensions_Plugin');
    $connection = Doctrine_Manager::connection();
    // Lang validation
    $lang = DataUtil::formatForOS($lang);
    // create a result set
    $results = array();
    $sm = ServiceUtil::getManager();
    $em = EventUtil::getManager();
    $coremodules = array('Extensions', 'Settings', 'Theme', 'Admin', 'Permissions', 'Groups', 'Blocks', 'Users');
    // manually install the modules module
    foreach ($coremodules as $coremodule) {
        $modpath = 'system';
        if (is_dir("{$modpath}/{$coremodule}/lib")) {
            ZLoader::addAutoloader($coremodule, "{$modpath}/{$coremodule}/lib");
        }
        $bootstrap = "{$modpath}/{$coremodule}/bootstrap.php";
        if (file_exists($bootstrap)) {
            include_once $bootstrap;
        }
        ModUtil::dbInfoLoad($coremodule, $coremodule);
        $className = "{$coremodule}_Installer";
        $instance = new $className($sm);
        if ($instance->install()) {
            $results[$coremodule] = true;
        }
    }
    // regenerate modules list
    $filemodules = ModUtil::apiFunc('Extensions', 'admin', 'getfilemodules');
    ModUtil::apiFunc('Extensions', 'admin', 'regenerate', array('filemodules' => $filemodules));
    // set each of the core modules to active
    reset($coremodules);
    foreach ($coremodules as $coremodule) {
        $mid = ModUtil::getIdFromName($coremodule, true);
        ModUtil::apiFunc('Extensions', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_INACTIVE));
        ModUtil::apiFunc('Extensions', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_ACTIVE));
    }
    // Add them to the appropriate category
    reset($coremodules);
    $coremodscat = array('Extensions' => __('System'), 'Permissions' => __('Users'), 'Groups' => __('Users'), 'Blocks' => __('Layout'), 'Users' => __('Users'), 'Theme' => __('Layout'), 'Admin' => __('System'), 'Settings' => __('System'));
    $categories = ModUtil::apiFunc('Admin', 'admin', 'getall');
    $modscat = array();
    foreach ($categories as $category) {
        $modscat[$category['name']] = $category['cid'];
    }
    foreach ($coremodules as $coremodule) {
        $category = $coremodscat[$coremodule];
        ModUtil::apiFunc('Admin', 'admin', 'addmodtocategory', array('module' => $coremodule, 'category' => $modscat[$category]));
    }
    // create the default blocks.
    $blockInstance = new Blocks_Installer($sm);
    $blockInstance->defaultdata();
    // install all the basic modules
    $modules = array(array('module' => 'SecurityCenter', 'category' => __('Security')), array('module' => 'Tour', 'category' => __('Content')), array('module' => 'Categories', 'category' => __('Content')), array('module' => 'Legal', 'category' => __('Content')), array('module' => 'Mailer', 'category' => __('System')), array('module' => 'Errors', 'category' => __('System')), array('module' => 'Theme', 'category' => __('Layout')), array('module' => 'Search', 'category' => __('Content')));
    foreach ($modules as $module) {
        // sanity check - check if module is already installed
        if (ModUtil::available($module['module'])) {
            continue;
        }
        $modpath = 'modules';
        if (is_dir("{$modpath}/{$module}/lib")) {
            ZLoader::addAutoloader($module, "{$modpath}/{$module}/lib");
        }
        $bootstrap = "{$modpath}/{$module}/bootstrap.php";
        if (file_exists($bootstrap)) {
            include_once $bootstrap;
        }
        ZLanguage::bindModuleDomain($module);
        $results[$module['module']] = false;
        // #6048 - prevent trying to install modules which are contained in an install type, but are not available physically
        if (!file_exists('system/' . $module['module'] . '/') && !file_exists('modules/' . $module['module'] . '/')) {
            continue;
        }
        $mid = ModUtil::getIdFromName($module['module']);
        // init it
        if (ModUtil::apiFunc('Extensions', 'admin', 'initialise', array('id' => $mid)) == true) {
            // activate it
            if (ModUtil::apiFunc('Extensions', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_ACTIVE))) {
                $results[$module['module']] = true;
            }
            // Set category
            ModUtil::apiFunc('Admin', 'admin', 'addmodtocategory', array('module' => $module['module'], 'category' => $modscat[$module['category']]));
        }
    }
    System::setVar('language_i18n', $lang);
    return $results;
}
Exemplo n.º 14
0
    /**
     * Initialize a DBConnection and place it on the connection stack.
     *
     * @param string  $name        The database alias name in the DBInfo configuration array (optional) (default=null which then defaults to 'default').
     * @param boolean $lazyConnect Whether or not to connect lazy.
     *
     * @deprecated
     *
     * @throws PDOException If database connection failed.
     * @return Doctrine_Connection Desired database connection reference.
     */
    public static function init($name = 'default', $lazyConnect = false)
    {
        LogUtil::log(__f('Warning! %1$s is deprecated.', array(__CLASS__ . '::' . __FUNCTION__)), E_USER_DEPRECATED);
        $serviceManager = ServiceUtil::getManager();
        $eventManager = EventUtil::getManager();

        // Lazy load DB connection to avoid testing DSNs that are not yet valid (e.g. no DB created yet)
        $dbEvent = new Zikula_Event('doctrine.init_connection', null, array('lazy' => $lazyConnect, 'name' => $name));
        $connection = $eventManager->notify($dbEvent)->getData();
        if (!self::$manager instanceof Doctrine_Manager) {
            self::$manager = Doctrine_Manager::getInstance();
        }
        $databases = $serviceManager['databases'];
        self::$connectionInfo[$name] = $databases[$name];

        return $connection;
    }
Exemplo n.º 15
0
    /**
     * Initialise Scribite for requested areas.
     *
     * @param array $args Module name: 'modulename'.
     *
     * @return string
     */
    private function loader($args)
    {
        // Argument checks
        $module = (isset($args['modulename'])) ? $args['modulename'] : ModUtil::getName();
        
        $overrides = ModUtil::getVar('Scribite', 'overrides');
        $editor = (isset($overrides[$module]['editor'])) ? $overrides[$module]['editor'] : ModUtil::getVar('Scribite', 'DefaultEditor');

        // check for modules providing helpers and load them into the page
        $event = new Zikula_Event('module.scribite.editorhelpers', new Scribite_EditorHelper(), array('editor' => $editor));
        $helpers = EventUtil::getManager()->notify($event)->getSubject()->getHelpers();
        foreach ($helpers as $helper) {
            if (ModUtil::available($helper['module'])) {
                PageUtil::AddVar($helper['type'], $helper['path']);            
            }
        }
        
        // check for allowed html
        $AllowableHTML = System::getVar('AllowableHTML');
        $disallowedhtml = array();
        while (list($key, $access) = each($AllowableHTML)) {
            if ($access == 0) {
                $disallowedhtml[] = DataUtil::formatForDisplay($key);
            }
        }

        // fetch additonal editor specific parameters.
        $classname = 'ModulePlugin_Scribite_' . $editor . '_Util';
        $additionalEditorParameters = array();
        if (method_exists($classname, 'addParameters')) {
            $additionalEditorParameters = $classname::addParameters();
        }
        // fetch external editor plugins
        $additionalExternalEditorPlugins = array();
        if (method_exists($classname, 'addExternalPlugins')) {
            $additionalExternalEditorPlugins = $classname::addExternalPlugins();
        }

        // assign disabled textareas to template as a javascript array
        $javascript = "var disabledTextareas=[";
        if (isset($overrides[$module])) {
            foreach (array_keys($overrides[$module]) as $area) {
                if ($area == 'editor') continue;
                if ((isset($overrides[$module][$area]['disabled'])) && ($overrides[$module][$area]['disabled'] == "true")) {
                    $javascript .= "'" . $area . "',";
                }
            }
        }
        $javascript = rtrim($javascript, ",");
        $javascript .= "];";
        PageUtil::addVar("footer", "<script type='text/javascript'>$javascript</script>");
        
        // assign override parameters to javascript object
        $javascript = "";
        $paramOverrides = false;
        if (isset($overrides[$module])) {
            foreach ($overrides[$module] as $area => $config) {
                if ($area == 'editor') continue;
                if (!empty($config['params'])) {
                    $paramOverrides = true;
                    $javascript .= "var paramOverrides_$area = {";
                    foreach ($config['params'] as $param => $value) {
                        $javascript .= "\n    $param: '$value',";
                    }
                    
                    $javascript .= "\n}";
                }
            }
        }
        PageUtil::addVar("footer", "<script type='text/javascript'>\n$javascript\n</script>");
        
        // insert notify function
        PageUtil::addVar('javascript', 'modules/Scribite/javascript/function-insertnotifyinput.js');

        $view = Zikula_View_Plugin::getPluginInstance("Scribite", $editor, Zikula_View::CACHE_DISABLED);

        // assign to template in Scribite 'namespace'
        $templateVars = array('editorVars' => ModUtil::getVar("moduleplugin.scribite." . strtolower($editor)),
            'modname' => $module,
            'disallowedhtml' => $disallowedhtml,
            'paramOverrides' => $paramOverrides);
        if (!empty($additionalEditorParameters)) {
            $templateVars['editorParameters'] = $additionalEditorParameters;
        }
        if (!empty($additionalExternalEditorPlugins)) {
            $templateVars['addExtEdPlugins'] = $additionalExternalEditorPlugins;
        }
        $view->assign('Scribite', $templateVars);

        return $view->fetch("editorheader.tpl");
    }
Exemplo n.º 16
0
 /**
  * Add var.
  *
  * Adds a new vaule to a page variable. In the case of a single
  * page variable, this functions acts exactly like PageUtil::setVar.
  *
  * @param string $varname The name of the page variable.
  * @param mixed  $value   The new value.
  *
  * @see    PageUtil::setVar
  * @return boolean true On success, false of the page variable is not registered.
  */
 public static function addVar($varname, $value)
 {
     global $_pageVars;
     // check for $_pageVars sanity
     if (!isset($_pageVars)) {
         $_pageVars = array();
     } elseif (!is_array($_pageVars)) {
         return false;
     }
     if (!isset($_pageVars[$varname])) {
         return false;
     }
     if (is_array($value)) {
         $value = array_unique($value);
     }
     $event = new GenericEvent($varname, array(), $value);
     $value = EventUtil::getManager()->dispatch('pageutil.addvar_filter', $event)->getData();
     if ($_pageVars[$varname]['multivalue']) {
         if (is_array($value)) {
             $_pageVars[$varname]['contents'] = array_merge($_pageVars[$varname]['contents'], $value);
         } else {
             $_pageVars[$varname]['contents'][] = $value;
         }
         // make values unique
         $_pageVars[$varname]['contents'] = array_unique($_pageVars[$varname]['contents']);
     } else {
         $_pageVars[$varname]['contents'] = $value;
     }
     return true;
 }
Exemplo n.º 17
0
 /**
  * Add var.
  *
  * Adds a new vaule to a page variable. In the case of a single
  * page variable, this functions acts exactly like PageUtil::setVar.
  *
  * @param string $varname  The name of the page variable.
  * @param mixed  $value    The new value.
  * @param string $features The feature(s) to load via polyfill.
  *
  * @see    PageUtil::setVar
  * @return boolean true On success, false of the page variable is not registered.
  */
 public static function addVar($varname, $value, $features = 'forms')
 {
     global $_pageVars;
     if (System::isLegacyMode()) {
         switch ($varname) {
             case 'rawtext':
                 LogUtil::log(__f('Warning! The page variable %1$s is deprecated. Please use %2$s instead.', array('rawtext', 'header')), E_USER_DEPRECATED);
                 $varname = 'header';
                 break;
         }
     }
     // check for $_pageVars sanity
     if (!isset($_pageVars)) {
         $_pageVars = array();
     } elseif (!is_array($_pageVars)) {
         return false;
     }
     if (!isset($_pageVars[$varname])) {
         return false;
     }
     if (is_array($value)) {
         $value = array_unique($value);
     }
     $value = self::resolveSymfonyAsset($value);
     // @todo Remove in 1.5.0.
     $value = self::fixJQueryThemesPath($value);
     $event = new \Zikula\Core\Event\GenericEvent($varname, array(), $value);
     $value = EventUtil::getManager()->dispatch('pageutil.addvar_filter', $event)->getData();
     if ($_pageVars[$varname]['multivalue']) {
         if (is_array($value)) {
             if (in_array('polyfill', $value)) {
                 $features = explode(' ', $features);
                 foreach ($features as $feature) {
                     PageUtil::addVar('polyfill_features', $feature);
                 }
                 $_pageVars[$varname]['contents'] = array_merge($_pageVars[$varname]['contents'], $value);
             } else {
                 $_pageVars[$varname]['contents'] = array_merge($_pageVars[$varname]['contents'], $value);
             }
         } else {
             $_pageVars[$varname]['contents'][] = $value;
         }
         // make values unique
         $_pageVars[$varname]['contents'] = array_unique($_pageVars[$varname]['contents']);
     } else {
         $_pageVars[$varname]['contents'] = $value;
     }
     return true;
 }
Exemplo n.º 18
0
 /**
  * Session required.
  *
  * Starts a session or terminates loading.
  *
  * @return void
  */
 public static function requireSession()
 {
     $event = new GenericEvent();
     EventUtil::getManager()->dispatch('session.require', $event);
 }
Exemplo n.º 19
0
 /**
  * Session required.
  *
  * Starts a session or terminates loading.
  *
  * @return void
  */
 public static function requireSession()
 {
     $event = new Zikula_Event('session.require');
     EventUtil::getManager()->notify($event);
 }
Exemplo n.º 20
0
 /**
  * Run a module function.
  *
  * @param string  $modname    The name of the module.
  * @param string  $type       The type of function to run.
  * @param string  $func       The specific function to run.
  * @param array   $args       The arguments to pass to the function.
  * @param boolean $api        Whether or not to execute an API (or regular) function.
  *
  * @throws Zikula_Exception_NotFound If method was not found.
  *
  * @return mixed.
  */
 public static function exec($modname, $type = 'user', $func = 'index', $args = array(), $api = false)
 {
     // define input, all numbers and booleans to strings
     $modname = preg_match('/\\w+Module$/i', $modname) || !$modname ? $modname : $modname . 'Module';
     $modname = isset($modname) ? (string) $modname : '';
     $loadfunc = $api ? 'ModUtil::loadApi' : 'ModUtil::load';
     // validate
     if (!System::varValidate($modname, 'mod')) {
         return null;
     }
     $modinfo = self::getInfo(self::getIDFromName($modname));
     $controller = null;
     $modfunc = null;
     $loaded = call_user_func_array($loadfunc, array($modname, $type));
     $result = self::getCallable($modname, $type, $func, $api);
     if ($result) {
         $modfunc = $result['callable'];
         $controller = $modfunc[0];
     }
     $dispatcher = EventUtil::getManager();
     if ($loaded) {
         $preExecuteEvent = new GenericEvent($controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api));
         $postExecuteEvent = new GenericEvent($controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api));
         if (is_callable($modfunc)) {
             $dispatcher->dispatch('module_dispatch.preexecute', $preExecuteEvent);
             $modfunc[0]->preDispatch();
             $postExecuteEvent->setData(call_user_func($modfunc, $args));
             $modfunc[0]->postDispatch();
             return $dispatcher->dispatch('module_dispatch.postexecute', $postExecuteEvent)->getData();
         }
         // try to load plugin
         // This kind of eventhandler should
         // 1. Check $event['modfunc'] to see if it should run else exit silently.
         // 2. Do something like $result = {$event['modfunc']}({$event['args'});
         // 3. Save the result $event->setData($result).
         // 4. $event->setNotify().
         // return void
         // This event means that no $type was found
         $event = new GenericEvent(null, array('modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api), false);
         $dispatcher->dispatch('module_dispatch.type_not_found', $event);
         if ($preExecuteEvent->isPropagationStopped()) {
             return $preExecuteEvent->getData();
         }
         return false;
     }
     // Issue not found exception for controller requests
     if (!$api) {
         throw new \Zikula\Framework\Exception\NotFoundException(__f('The requested controller action %s_Controller_%s::%s() could not be found', array($modname, $type, $func)));
     }
 }
Exemplo n.º 21
0
 /**
  * fetch external plugins
  * @return array 
  */
 public static function addExternalPlugins()
 {
     $event = new Zikula_Event('moduleplugin.ckeditor.externalplugins', new ModulePlugin_Scribite_CKEditor_EditorPlugin());
     $plugins = EventUtil::getManager()->notify($event)->getSubject()->getPlugins();
     return $plugins;
 }
Exemplo n.º 22
0
    $kernelConfig = array_merge($kernelConfig, Yaml::parse(file_get_contents($file)));
}
$kernelConfig = $kernelConfig['parameters'];
if ($kernelConfig['env'] !== 'prod') {
    // hide deprecation errors
    // @todo remove exclusions for Core-2.0
    Debug::enable(E_ALL & ~E_USER_DEPRECATED);
}
if (isset($kernelConfig['umask']) && !is_null($kernelConfig['umask'])) {
    umask($kernelConfig['umask']);
}
require __DIR__ . '/../app/ZikulaKernel.php';
$kernel = new ZikulaKernel($kernelConfig['env'], $kernelConfig['debug']);
$kernel->boot();
// legacy handling
$core = new Zikula_Core();
$core->setKernel($kernel);
$core->boot();
// these two events are called for BC only. remove in 2.0.0
$core->getDispatcher()->dispatch('bootstrap.getconfig', new GenericEvent($core));
$core->getDispatcher()->dispatch('bootstrap.custom', new GenericEvent($core));
foreach ($GLOBALS['ZConfig'] as $config) {
    $core->getContainer()->loadArguments($config);
}
$GLOBALS['ZConfig']['System']['temp'] = $core->getContainer()->getParameter('temp_dir');
$GLOBALS['ZConfig']['System']['datadir'] = $core->getContainer()->getParameter('datadir');
$GLOBALS['ZConfig']['System']['system.chmod_dir'] = $core->getContainer()->getParameter('system.chmod_dir');
ServiceUtil::getManager($core);
EventUtil::getManager($core);
$core->attachHandlers('config/EventHandlers');
return $core;
Exemplo n.º 23
0
 /**
  * Session required.
  *
  * Starts a session or terminates loading.
  *
  * @return void
  */
 public static function requireSession()
 {
     EventUtil::getManager()->dispatch('session.require', new \Zikula\Core\Event\GenericEvent());
 }
Exemplo n.º 24
0
 /**
  * Procedure for managinig stylesheets.
  *
  * @param array $stylesheets List of demanded stylesheets.
  *
  * @return array List of stylesheets
  */
 public static function prepareStylesheets($stylesheets)
 {
     if (ThemeUtil::getVar('noCoreCss', false)) {
         $initStyle = null;
     } else {
         $initStyle = array('style/core.css');
     }
     // Add generic stylesheet as the first stylesheet.
     $event = new Zikula_Event('pageutil.addvar_filter', 'stylesheet', array(), $initStyle);
     $coreStyle = EventUtil::getManager()->notify($event)->getData();
     if (is_array($stylesheets)) {
         array_unshift($stylesheets, $coreStyle[0]);
     } else {
         $stylesheets = array($coreStyle[0]);
     }
     $stylesheets = array_unique(array_values($stylesheets));
     $iehack = '<!--[if IE]><link rel="stylesheet" type="text/css" href="style/core_iehacks.css" media="print,projection,screen" /><![endif]-->';
     PageUtil::addVar('header', $iehack);
     return $stylesheets;
 }