/** * Extensions_admin_modify - modify a module. * * @return string HTML output string. */ public function modify() { $id = (int) FormUtil::getPassedValue('id', null, 'GET'); if (!is_numeric($id)) { return LogUtil::registerArgsError(ModUtil::url('Extensions', 'admin', 'view')); } $obj = ModUtil::getInfo($id); if (!isset($id) || $obj == false) { return LogUtil::registerError($this->__('Error! No such module ID exists.'), 404, ModUtil::url('Extensions', 'admin', 'modify', array('id' => $id))); } if (!SecurityUtil::checkPermission('Extensions::', "$obj[name]::$id", ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } $restore = (bool)FormUtil::getPassedValue('restore', false, 'GET'); if ($restore) { // load the version array $baseDir = ($obj['type'] == ModUtil::TYPE_SYSTEM) ? 'system' : 'modules'; // load gettext domain for 3rd party modules if ($baseDir == 'modules' && is_dir("modules/$obj[directory]/locale")) { // This is required here since including pnversion automatically executes the pnversion code // this results in $this->__() caching the result before the domain is bounded. Will not occur in zOO // since loading is self contained in each zOO application. ZLanguage::bindModuleDomain($obj['directory']); } $modversion = Extensions_Util::getVersionMeta($obj['directory'], $baseDir); // load defaults $name = (isset($modversion['name']) ? $modversion['name'] : ''); $displayname = (isset($modversion['displayname']) ? $modversion['displayname'] : $name); $url = (isset($modversion['url']) ? $modversion['url'] : $displayname); $description = (isset($modversion['description']) ? $modversion['description'] : ''); $obj = array( 'id' => $id, 'displayname' => $displayname, 'url' => $url, 'description' => $description); } $this->view->assign($obj); // Return the output that has been generated by this function return $this->view->fetch('extensions_admin_modify.tpl'); }
/** * Load a module. * * This loads/set's up a module. For classic style modules, it tests to see * if the module type files exist, admin.php, user.php etc and includes them. * If they do not exist, it will return false. * * Loading a module simply means making the functions/methods available * by loading the files and other tasks like binding any language domain. * * For OO style modules this means registering the main module autoloader, * and binding any language domain. * * @param string $modname The name of the module. * @param string $type The type of functions to load. * @param boolean $force Determines to load Module even if module isn't active. * @param boolean $api Whether or not to load an API (or regular) module. * * @return string|boolean Name of module loaded, or false on failure. */ public static function loadGeneric($modname, $type = 'user', $force = false, $api = false) { // define input, all numbers and booleans to strings $osapi = $api ? 'api' : ''; $modname = isset($modname) ? (string) $modname : ''; $modtype = strtolower("{$modname}{$type}{$osapi}"); if (!isset(self::$cache['loaded'])) { self::$cache['loaded'] = array(); } if (!empty(self::$cache['loaded'][$modtype])) { // Already loaded from somewhere else return self::$cache['loaded'][$modtype]; } // this is essential to call separately and not in the condition below - drak $available = self::available($modname, $force); // check the modules state if (!$force && !$available) { return false; } // get the module info $modinfo = self::getInfo(self::getIdFromName($modname)); // check for bad System::varValidate($modname) if (!$modinfo) { return false; } // create variables for the OS preped version of the directory $modpath = $modinfo['type'] == self::TYPE_SYSTEM ? 'system' : 'modules'; // if class is loadable or has been loaded exit here. if (self::isInitialized($modname)) { self::_loadStyleSheets($modname, $api, $type); return $modname; } // is OOP module if (self::isOO($modname)) { self::initOOModule($modname); } else { $osdir = DataUtil::formatForOS($modinfo['directory']); $ostype = DataUtil::formatForOS($type); $cosfile = "config/functions/{$osdir}/pn{$ostype}{$osapi}.php"; $mosfile = "{$modpath}/{$osdir}/pn{$ostype}{$osapi}.php"; $mosdir = "{$modpath}/{$osdir}/pn{$ostype}{$osapi}"; if (file_exists($cosfile)) { // Load the file from config include_once $cosfile; } elseif (file_exists($mosfile)) { // Load the file from modules include_once $mosfile; } elseif (is_dir($mosdir)) { } else { // File does not exist return false; } } self::$cache['loaded'][$modtype] = $modname; if ($modinfo['type'] == self::TYPE_MODULE) { ZLanguage::bindModuleDomain($modname); } // Load database info self::dbInfoLoad($modname, $modinfo['directory']); self::_loadStyleSheets($modname, $api, $type); $event = new Zikula_Event('module_dispatch.postloadgeneric', null, array('modinfo' => $modinfo, 'type' => $type, 'force' => $force, 'api' => $api)); EventUtil::notify($event); return $modname; }
/** * Load a block. * * @param string $modname Module name. * @param string $block Name of the block. * * @throws LogicException Uf OO-Block is not a Zikula_Controller_AbstractBlock object. * @return bool True on successful load, false otherwise. */ public static function load($modname, $block) { $sm = ServiceUtil::getManager(); $modinfo = ModUtil::getInfoFromName($modname); $serviceId = strtolower('block.' . $modinfo['name'] . '_' . 'Block_' . $block); if ($sm->hasService($serviceId)) { return $sm->getService($serviceId); } if ($modinfo['type'] == ModUtil::TYPE_MODULE) { ZLanguage::bindModuleDomain($modinfo['name']); } $basedir = ($modinfo['type'] == ModUtil::TYPE_SYSTEM) ? 'system' : 'modules'; $moddir = DataUtil::formatForOS($modinfo['directory']); $blockdir = "$basedir/$moddir/lib/$moddir/Block"; $ooblock = "$blockdir/" . ucwords($block) . '.php'; ModUtil::load($modname); $isOO = ModUtil::isOO($modname); if (!$isOO) { $blockdirOld = $moddir . '/pnblocks'; $incfile = DataUtil::formatForOS($block . '.php'); if (file_exists("$basedir/$blockdirOld/$incfile")) { include_once "$basedir/$blockdirOld/$incfile"; } else { return false; } } // get the block info if ($isOO) { $className = ucwords($modinfo['name']) . '_' . 'Block_' . ucwords($block); $r = new ReflectionClass($className); $blockInstance = $r->newInstanceArgs(array($sm)); try { if (!$blockInstance instanceof Zikula_Controller_AbstractBlock) { throw new LogicException(sprintf('Block %s must inherit from Zikula_Controller_AbstractBlock', $className)); } } catch (LogicException $e) { if (System::isDevelopmentMode()) { throw $e; } else { LogUtil::registerError('A fatal error has occured which can be viewed only in development mode.', 500); return false; } } $sm->attachService($serviceId, $blockInstance); } $result = ($isOO ? $blockInstance : true); if ($isOO) { $blocks_modules[$block] = call_user_func(array($blockInstance, 'info')); } else { $infofunc = "{$modname}_{$block}block_info"; $blocks_modules[$block] = $infofunc(); } // set the module and keys for the new block $blocks_modules[$block]['bkey'] = $block; $blocks_modules[$block]['module'] = $modname; $blocks_modules[$block]['mid'] = ModUtil::getIdFromName($modname); // merge the blockinfo in the global list of blocks if (!isset($GLOBALS['blocks_modules'])) { $GLOBALS['blocks_modules'] = array(); } $GLOBALS['blocks_modules'][$blocks_modules[$block]['mid']][$block] = $blocks_modules[$block]; // Initialise block if required (new-style) if ($isOO) { call_user_func(array($blockInstance, 'init')); } else { $initfunc = "{$modname}_{$block}block_init"; $initfunc(); } // add stylesheet to the page vars, this makes manual loading obsolete PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet($modname)); return $result; }
/** * Load a block. * * @param string $modname Module name. * @param string $block Name of the block. * * @throws LogicException Uf OO-Block is not a Zikula_Controller_AbstractBlock object. * @return bool True on successful load, false otherwise. */ public static function load($modname, $block) { $sm = ServiceUtil::getManager(); $modinfo = ModUtil::getInfoFromName($modname); if ($modinfo['state'] != \ModUtil::STATE_ACTIVE) { return false; } $serviceId = strtolower('block.' . $modinfo['name'] . '_' . 'Block_' . $block); if ($sm->has($serviceId)) { return $sm->get($serviceId); } if ($modinfo['type'] == ModUtil::TYPE_MODULE) { ZLanguage::bindModuleDomain($modinfo['name']); } $basedir = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; $moddir = DataUtil::formatForOS($modinfo['directory']); $blockdir = "{$basedir}/{$moddir}/lib/{$moddir}/Block"; $ooblock = "{$blockdir}/" . ucwords($block) . '.php'; ModUtil::load($modname); // get the block info $kernel = $sm->get('kernel'); $module = null; try { /** @var $module \Zikula\Core\AbstractModule */ $module = $kernel->getModule($modinfo['name']); $className = $module->getNamespace() . '\\Block\\' . ucwords($block); $className = preg_match('/.*Block$/', $className) ? $className : $className . 'Block'; } catch (\InvalidArgumentException $e) { } if (!isset($className)) { $className = ucwords($modinfo['name']) . '\\' . 'Block\\' . ucwords($block); $className = preg_match('/.*Block$/', $className) ? $className : $className . 'Block'; $classNameOld = ucwords($modinfo['name']) . '_' . 'Block_' . ucwords($block); $className = class_exists($className) ? $className : $classNameOld; } $r = new ReflectionClass($className); $instanceArgs = array(); if (is_subclass_of($className, 'Zikula_Controller_AbstractBlock')) { $instanceArgs = array($sm, $module); } elseif (is_subclass_of($className, 'Zikula\\Core\\Controller\\AbstractBlockController')) { $instanceArgs = array($module); } $blockInstance = $r->newInstanceArgs($instanceArgs); if (!$blockInstance instanceof Zikula_Controller_AbstractBlock && !$blockInstance instanceof AbstractBlockController) { throw new LogicException(sprintf('Block %s must inherit from Zikula_Controller_AbstractBlock or Zikula\\Core\\Controller\\AbstractBlockController', $className)); } $sm->set($serviceId, $blockInstance); if ($blockInstance instanceof \Symfony\Component\DependencyInjection\ContainerAwareInterface) { $blockInstance->setContainer($sm); } $result = $blockInstance; $blocks_modules[$block] = call_user_func(array($blockInstance, 'info')); // set the module and keys for the new block $blocks_modules[$block]['bkey'] = $block; $blocks_modules[$block]['module'] = $modname; $blocks_modules[$block]['mid'] = ModUtil::getIdFromName($modname); // merge the blockinfo in the global list of blocks if (!isset($GLOBALS['blocks_modules'])) { $GLOBALS['blocks_modules'] = array(); } $GLOBALS['blocks_modules'][$blocks_modules[$block]['mid']][$block] = $blocks_modules[$block]; // Initialise block if required (new-style) call_user_func(array($blockInstance, 'init')); // add stylesheet to the page vars, this makes manual loading obsolete PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet($modname)); return $result; }
/** * Load a module. * * This loads/set's up a module. For classic style modules, it tests to see * if the module type files exist, admin.php, user.php etc and includes them. * If they do not exist, it will return false. * * Loading a module simply means making the functions/methods available * by loading the files and other tasks like binding any language domain. * * For OO style modules this means registering the main module autoloader, * and binding any language domain. * * @param string $modname The name of the module. * @param string $type The type of functions to load. * @param boolean $force Determines to load Module even if module isn't active. * @param boolean $api Whether or not to load an API (or regular) module. * * @return string|boolean Name of module loaded, or false on failure. */ public static function loadGeneric($modname, $type = 'user', $force = false, $api = false) { // define input, all numbers and booleans to strings $osapi = $api ? 'api' : ''; $modname = preg_match('/\\w+Module$/i', $modname) || !$modname ? $modname : $modname . 'Module'; $modname = isset($modname) ? (string) $modname : ''; $modtype = strtolower("{$modname}{$type}{$osapi}"); if (!isset(self::$cache['loaded'])) { self::$cache['loaded'] = array(); } if (!empty(self::$cache['loaded'][$modtype])) { // Already loaded from somewhere else return self::$cache['loaded'][$modtype]; } // this is essential to call separately and not in the condition below - drak $available = self::available($modname, $force); // check the modules state if (!$force && !$available) { return false; } // get the module info $modinfo = self::getInfo(self::getIdFromName($modname)); // check for bad System::varValidate($modname) if (!$modinfo) { return false; } // if class is loadable or has been loaded exit here. if (self::isInitialized($modname)) { self::_loadStyleSheets($modname, $api, $type); return $modname; } self::isOO($modname); self::initOOModule($modname); self::$cache['loaded'][$modtype] = $modname; if ($modinfo['type'] == self::TYPE_MODULE) { ZLanguage::bindModuleDomain($modname); } self::_loadStyleSheets($modname, $api, $type); $event = new GenericEvent(null, array('modinfo' => $modinfo, 'type' => $type, 'force' => $force, 'api' => $api)); EventUtil::dispatch('module_dispatch.postloadgeneric', $event); return $modname; }
function installmodules($lang = 'en') { // This is a temporary hack for release 1.3.x to be able to install modules // load DoctrineExtensions plugin include_once __DIR__ . '/../plugins/DoctrineExtensions/Plugin.php'; PluginUtil::loadPlugin('SystemPlugin_DoctrineExtensions_Plugin'); // Lang validation $lang = DataUtil::formatForOS($lang); // create a result set $results = array(); $sm = ServiceUtil::getManager(); $coremodules = array('Extensions', 'Settings', 'Theme', 'Admin', 'Permissions', 'Groups', 'Blocks', 'Users'); // manually install the modules module foreach ($coremodules as $coremodule) { $modpath = 'system'; ZLoader::addModule($coremodule, $modpath); $bootstrap = __DIR__ . "/../{$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('ExtensionsModule', 'admin', 'getfilemodules'); ModUtil::apiFunc('ExtensionsModule', '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('ExtensionsModule', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_INACTIVE)); ModUtil::apiFunc('ExtensionsModule', '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('AdminModule', 'admin', 'getall'); $modscat = array(); foreach ($categories as $category) { $modscat[$category['name']] = $category['cid']; } foreach ($coremodules as $coremodule) { $category = $coremodscat[$coremodule]; ModUtil::apiFunc('AdminModule', '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'; // ZLoader::addModule($module, $modpath); ZLoader::addAutoloader($module, "{$modpath}"); $bootstrap = __DIR__ . "/../{$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('ExtensionsModule', 'admin', 'initialise', array('id' => $mid)) == true) { // activate it if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_ACTIVE))) { $results[$module['module']] = true; } // Set category ModUtil::apiFunc('AdminModule', 'admin', 'addmodtocategory', array('module' => $module['module'], 'category' => $modscat[$module['category']])); } } System::setVar('language_i18n', $lang); return $results; }
/** * Gets the object associated with a given module name * * @param string $moduleName * @param boolean $force = false Force load a module and add autoloaders * * @return null|\Zikula\Core\AbstractModule */ public static function getModule($moduleName, $force = false) { /** @var $kernel Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel */ $kernel = ServiceUtil::getManager()->get('kernel'); try { return $kernel->getModule($moduleName); } catch (\InvalidArgumentException $e) { } if ($force) { $modInfo = self::getInfo(self::getIdFromName($moduleName)); if (empty($modInfo)) { throw new \RuntimeException(__('Error! No such module exists.')); } $osDir = DataUtil::formatForOS($modInfo['directory']); $modPath = $modInfo['type'] == self::TYPE_SYSTEM ? "system" : "modules"; $scanner = new Scanner(); $scanner->scan(array("{$modPath}/{$osDir}"), 1); $modules = $scanner->getModulesMetaData(true); /** @var $moduleMetaData \Zikula\Bundle\CoreBundle\Bundle\MetaData */ $moduleMetaData = !empty($modules[$modInfo['name']]) ? $modules[$modInfo['name']] : null; if (null !== $moduleMetaData) { // moduleMetaData only exists for bundle-type modules $boot = new \Zikula\Bundle\CoreBundle\Bundle\Bootstrap(); $boot->addAutoloaders($kernel, $moduleMetaData->getAutoload()); if ($modInfo['type'] == self::TYPE_MODULE) { if (is_dir("modules/{$osDir}/Resources/locale")) { ZLanguage::bindModuleDomain($modInfo['name']); } } $moduleClass = $moduleMetaData->getClass(); return new $moduleClass(); } } return null; }
/** * Upgrade a module. * * @param array $args All parameters passed to this function. * numeric $args['id'] The module ID. * boolean $args['interactive_upgrade'] Whether or not to upgrade in interactive mode. * * @return boolean True on success, false on failure. */ public function upgrade($args) { // Argument check if (!isset($args['id']) || !is_numeric($args['id'])) { return LogUtil::registerArgsError(); } // Get module information $modinfo = ModUtil::getInfo($args['id']); if (empty($modinfo)) { return LogUtil::registerError($this->__('Error! No such module ID exists.')); } switch ($modinfo['state']) { case ModUtil::STATE_NOTALLOWED: return LogUtil::registerError($this->__f('Error! No permission to upgrade %s.', $modinfo['name'])); break; default: if ($modinfo['state'] > 10) { return LogUtil::registerError($this->__f('Error! %s is not compatible with this version of Zikula.', $modinfo['name'])); } } $osdir = DataUtil::formatForOS($modinfo['directory']); ModUtil::dbInfoLoad($modinfo['name'], $osdir); $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; // load module maintainence functions $oomod = ModUtil::isOO($modinfo['name']); if ($oomod) { ZLoader::addAutoloader($osdir, "{$modpath}/{$osdir}/lib"); } $bootstrap = "{$modpath}/{$osdir}/bootstrap.php"; if (file_exists($bootstrap)) { include_once $bootstrap; } if ($modinfo['type'] == ModUtil::TYPE_MODULE) { if (is_dir("modules/{$osdir}/locale")) { ZLanguage::bindModuleDomain($modinfo['name']); } } if (!$oomod && file_exists($file = "{$modpath}/{$osdir}/pninit.php")) { if (!(include_once $file)) { LogUtil::registerError($this->__f("Error! Could not load a required file: '%s'.", $file)); } } if ($oomod) { $className = ucwords($modinfo['name']) . '_Installer'; $reflectionInstaller = new ReflectionClass($className); if (!$reflectionInstaller->isSubclassOf('Zikula_AbstractInstaller')) { LogUtil::registerError($this->__f("%s must be an instance of Zikula_AbstractInstaller", $className)); } $installer = $reflectionInstaller->newInstanceArgs(array($this->serviceManager)); $interactiveClass = ucwords($modinfo['name']) . '_Controller_Interactiveinstaller'; $interactiveController = null; if (class_exists($interactiveClass)) { $reflectionInteractive = new ReflectionClass($interactiveClass); if (!$reflectionInteractive->isSubclassOf('Zikula_Controller_AbstractInteractiveInstaller')) { LogUtil::registerError($this->__f("%s must be an instance of Zikula_Controller_AbstractInteractiveInstaller", $className)); } $interactiveController = $reflectionInteractive->newInstance($this->serviceManager); } } // perform the actual upgrade of the module $func = $oomod ? array($installer, 'upgrade') : $modinfo['name'] . '_upgrade'; $interactive_func = $oomod ? array($interactiveController, 'upgrade') : $modinfo['name'] . '_init_interactiveupgrade'; // allow bypass of interactive upgrade during a new installation only. if (System::isInstalling() && is_callable($interactive_func) && !is_callable($func)) { return; // return void here } if (isset($args['interactive_upgrade']) && $args['interactive_upgrade'] == false && is_callable($interactive_func)) { if (is_array($interactive_func)) { // This must be an OO controller since callable is an array. // Because interactive installers extend the Zikula_AbstractController, is_callable will always return true because of the __call() // so we must check if the method actually exists by reflection - drak if ($reflectionInteractive->hasMethod('upgrade')) { SessionUtil::setVar('interactive_upgrade', true); return call_user_func($interactive_func, array('oldversion' => $modinfo['version'])); } } else { // this is enclosed in the else so that if both conditions fail, execution will pass onto the non-interactive execution below. SessionUtil::setVar('interactive_upgrade', true); return call_user_func($interactive_func, array('oldversion' => $modinfo['version'])); } } // non-interactive if (is_callable($func)) { $result = call_user_func($func, $modinfo['version']); if (is_string($result)) { if ($result != $modinfo['version']) { // update the last successful updated version $modinfo['version'] = $result; $obj = DBUtil::updateObject($modinfo, 'modules', '', 'id', true); } return false; } elseif ($result != true) { return false; } } $modversion['version'] = '0'; $modversion = Extensions_Util::getVersionMeta($osdir, $modpath); $version = $modversion['version']; // Update state of module $result = $this->setState(array('id' => $args['id'], 'state' => ModUtil::STATE_ACTIVE)); if ($result) { LogUtil::registerStatus($this->__("Done! Module has been upgraded. Its status is now 'Active'.")); } else { return false; } // Note the changes in the database... // Get module database info ModUtil::dbInfoLoad('Extensions'); $obj = array('id' => $args['id'], 'version' => $version); DBUtil::updateObject($obj, 'modules'); // legacy to be removed from 1.4 - remove hooks during upgrade since we cannot rely on // module authors to do this - drak if ($oomod) { $tables = DBUtil::getTables(); $hooksCol = $tables['hooks_column']; $where = "{$hooksCol['smodule']} = '{$modinfo['name']}' OR {$hooksCol['tmodule']} = '{$modinfo['name']}'"; $hooks = DBUtil::selectObjectArray('hooks', $where); if ($hooks) { foreach ($hooks as $hook) { DBUtil::deleteObject($hook, 'hooks'); } LogUtil::registerStatus($this->__f("NOTICE! Legacy hook configurations for %s have been removed.", $modinfo['name'])); } } // Upgrade succeeded, issue event. $event = new Zikula_Event('installer.module.upgraded', null, $modinfo); $this->eventManager->notify($event); // Success return true; }
/** * Load a block. * * @param string $modname Module name. * @param string $block Name of the block. * * @throws LogicException Uf OO-Block is not a Zikula_Controller_AbstractBlock object. * @return bool True on successful load, false otherwise. */ public static function load($modname, $block) { $sm = ServiceUtil::getManager(); $modinfo = ModUtil::getInfoFromName($modname); $serviceId = strtolower('block.' . $modinfo['name'] . '\\Block\\' . $block . 'Block'); if ($sm->has($serviceId)) { return $sm->get($serviceId); } if ($modinfo['type'] == ModUtil::TYPE_MODULE) { ZLanguage::bindModuleDomain($modinfo['name']); } ModUtil::load($modname); // get the block info $className = ucwords($modinfo['name']) . '\\Block\\' . ucwords($block) . 'Block'; $r = new ReflectionClass($className); $blockInstance = $r->newInstanceArgs(array($sm)); $sm->set($serviceId, $blockInstance); $result = $blockInstance; $blocks_modules[$block] = call_user_func(array($blockInstance, 'info')); // set the module and keys for the new block $blocks_modules[$block]['bkey'] = $block; $blocks_modules[$block]['module'] = $modname; $blocks_modules[$block]['mid'] = ModUtil::getIdFromName($modname); // merge the blockinfo in the global list of blocks if (!isset($GLOBALS['blocks_modules'])) { $GLOBALS['blocks_modules'] = array(); } $GLOBALS['blocks_modules'][$blocks_modules[$block]['mid']][$block] = $blocks_modules[$block]; // Initialise block if required (new-style) call_user_func(array($blockInstance, 'init')); // add stylesheet to the page vars, this makes manual loading obsolete PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet($modname)); return $result; }