/** * Register all autoloaders for all modules. * * @internal * * @return void */ public static function registerAutoloaders() { $modules = self::getModsTable(); unset($modules[0]); foreach ($modules as $module) { $base = $module['type'] == self::TYPE_MODULE ? 'modules' : 'system'; $path = "{$base}/{$module['directory']}/lib"; ZLoader::addAutoloader($module['directory'], $path); } }
/** * Adds an autoloader entry for the cached (generated) doctrine models. * * Implements 'core.init' events when Zikula_Core::STAGE_CONFIG. * * @param Zikula_Event $event Event. * * @return void */ public function setupAutoloaderForGeneratedCategoryModels(Zikula_Event $event) { if ($event['stage'] == Zikula_Core::STAGE_CONFIG) { ZLoader::addAutoloader('GeneratedDoctrineModel', CacheUtil::getLocalDir('doctrinemodels')); } }
/** * Initialise. * * Runs ar plugin init time. * * @throws InvalidArgumentException If invalid configuration given. * * @return void */ public function initialize() { define('SWIFT_REQUIRED_LOADED', true); define('SWIFT_INIT_LOADED', true); // register namespace ZLoader::addAutoloader('Swift', dirname(__FILE__) . '/lib/vendor/SwiftMailer/classes'); // initialize Swift //require_once realpath($this->baseDir . '/lib/vendor/SwiftMailer/swift_init.php'); // dont use this as it fails in virtual hosting environments with open_basedir restrictions // Load in dependency maps require_once dirname(__FILE__) . '/lib/vendor/SwiftMailer/dependency_maps/cache_deps.php'; require_once dirname(__FILE__) . '/lib/vendor/SwiftMailer/dependency_maps/mime_deps.php'; require_once dirname(__FILE__) . '/lib/vendor/SwiftMailer/dependency_maps/transport_deps.php'; // load configuration (todo: move this to persistence). include dirname(__FILE__) . '/configuration/config.php'; $this->serviceManager['swiftmailer.preferences.sendmethod'] = $config['sendmethod']; $preferences = Swift_Preferences::getInstance(); $this->serviceManager['swiftmailer.preferences.charset'] = $config['charset']; $this->serviceManager['swiftmailer.preferences.cachetype'] = $config['cachetype']; $this->serviceManager['swiftmailer.preferences.tempdir'] = $config['tempdir']; $preferences->setCharset($config['charset']); $preferences->setCacheType($config['cachetype']); $preferences->setTempDir($config['tempdir']); // determine the correct transport $type = $config['transport']['type']; $args = $config['transport'][$type]; switch ($type) { case 'mail': $this->serviceManager['swiftmailer.transport.mail.extraparams'] = $args['extraparams']; $definition = new Zikula_ServiceManager_Definition('Swift_MailTransport', array(new Zikula_ServiceManager_Argument('swiftmailer.transport.mail.extraparams'))); break; case 'smtp': $this->serviceManager['swiftmailer.transport.smtp.host'] = $args['host']; $this->serviceManager['swiftmailer.transport.smtp.port'] = $args['port']; $definition = new Zikula_ServiceManager_Definition('Swift_SmtpTransport', array( new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.host'), new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.port'))); if ($args['username'] && $args['password']) { $this->serviceManager['swiftmailer.transport.smtp.username'] = $args['username']; $this->serviceManager['swiftmailer.transport.smtp.password'] = $args['password']; $definition->addMethod('setUserName', new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.username')); $definition->addMethod('setPassword', new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.password')); } if (isset($args['encryption'])) { $this->serviceManager['swiftmailer.transport.smtp.encryption'] = $args['encryption']; $definition->addMethod('setEncryption', new Zikula_ServiceManager_Argument('swiftmailer.transport.smtp.encryption')); } break; case 'sendmail': $this->serviceManager['swiftmailer.transport.mail.command'] = $args['command']; $definition = new Zikula_ServiceManager_Definition('Swift_SendmailTransport', array(new Zikula_ServiceManager_Argument('swiftmailer.transport.mail.command'))); break; default: // error throw new InvalidArgumentException('Invalid transport type, must be mail, smtp or sendmail'); break; } // register transport $this->serviceManager->registerService('swiftmailer.transport', $definition); // define and register mailer using transport service $definition = new Zikula_ServiceManager_Definition('Swift_Mailer', array(new Zikula_ServiceManager_Reference('swiftmailer.transport'))); $this->serviceManager->registerService('mailer', $definition, false); // register simple mailer service $definition = new Zikula_ServiceManager_Definition('SystemPlugins_SwiftMailer_Mailer', array(new Zikula_ServiceManager_Reference('zikula.servicemanager'))); $this->serviceManager->registerService('mailer.simple', $definition); }
* This work is contributed to the Zikula Foundation under one or more * Contributor Agreements and licensed to You under the following license: * * @license GNU/LGPLv3 (or at your option, any later version). * @package Installer * * Please see the NOTICE file distributed with this source code for further * information regarding copyright and licensing. */ ini_set('mbstring.internal_encoding', 'UTF-8'); ini_set('default_charset', 'UTF-8'); mb_regex_encoding('UTF-8'); ini_set('memory_limit', '64M'); ini_set('max_execution_time', 86400); include 'lib/bootstrap.php'; ZLoader::addAutoloader('Users', 'system/Users/lib', '_'); include_once __DIR__ . '/plugins/Doctrine/Plugin.php'; // check if the config.php was renewed if (!isset($GLOBALS['ZConfig']['Log']['log.to_debug_toolbar'])) { echo __('It seems to be that your config.php is outdated. Please check the release notes for more information.'); die; } PluginUtil::loadPlugin('SystemPlugin_Doctrine_Plugin'); $eventManager = $core->getEventManager(); $eventManager->attach('core.init', 'upgrade_suppressErrors'); // load zikula core define('_ZINSTALLVER', Zikula_Core::VERSION_NUM); define('_Z_MINUPGVER', '1.2.0'); // Signal that upgrade is running. $GLOBALS['_ZikulaUpgrader'] = array(); // include config file for retrieving name of temporary directory
* Contributor Agreements and licensed to You under the following license: * * @license GNU/LGPLv3 (or at your option, any later version). * @package Installer * * Please see the NOTICE file distributed with this source code for further * information regarding copyright and licensing. */ use Zikula\Core\Event\GenericEvent; ini_set('mbstring.internal_encoding', 'UTF-8'); ini_set('default_charset', 'UTF-8'); mb_regex_encoding('UTF-8'); ini_set('memory_limit', '64M'); ini_set('max_execution_time', 86400); include __DIR__ . '/../app/bootstrap.php'; ZLoader::addAutoloader('Users', __DIR__ . '/system'); $eventManager = $core->getDispatcher(); $eventManager->attach('core.init', 'upgrade_suppressErrors'); // load zikula core define('_ZINSTALLVER', Zikula_Core::VERSION_NUM); define('_Z_MINUPGVER', '1.2.0'); // Signal that upgrade is running. $GLOBALS['_ZikulaUpgrader'] = array(); // include config file for retrieving name of temporary directory $GLOBALS['ZConfig']['System']['multilingual'] = true; $GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_ATTRIBUTION'] = false; $GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_LOGGING'] = false; $GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_META'] = false; // Lazy load DB connection to avoid testing DSNs that are not yet valid (e.g. no DB created yet) $dbEvent = new GenericEvent(null, array('lazy' => true)); $connection = $eventManager->dispatch('doctrine.init_connection', $dbEvent)->getData();
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; }
/** * Copyright Zikula Foundation 2009 - Zikula Application Framework * * This work is contributed to the Zikula Foundation under one or more * Contributor Agreements and licensed to You under the following license: * * @license GNU/LGPLv3 (or at your option, any later version). * @package Zikula * * Please see the NOTICE file distributed with this source code for further * information regarding copyright and licensing. */ if (!defined('HTMLPURIFIER_PREFIX')) { define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/lib/vendor/htmlpurifier')); } if (!defined('PHPIDS_PATH_PREFIX')) { define('PHPIDS_PATH_PREFIX', realpath(dirname(__FILE__) . '/lib/vendor/IDS')); } // include the PHPIDS and get access to the result object set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) .'/lib/vendor')); ZLoader::addAutoloader('HTMLPurifier', realpath(dirname(__FILE__) . '/lib/vendor/htmlpurifier')); ZLoader::addAutoloader('IDS', realpath(dirname(__FILE__) . '/lib/vendor')); // register event handlers //EventUtil::attachCustomHandlers('system/SecurityCenter/lib/SecurityCenter/EventHandler'); EventUtil::attachEventHandler('SecurityCenter_EventHandler_Filter');
/** * Initialize object oriented module. * * @param string $moduleName Module name. * * @return boolean */ public static function initOOModule($moduleName) { if (self::isInitialized($moduleName)) { return true; } $modinfo = self::getInfo(self::getIdFromName($moduleName)); if (!$modinfo) { return false; } $modpath = $modinfo['type'] == self::TYPE_SYSTEM ? 'system' : 'modules'; $osdir = DataUtil::formatForOS($modinfo['directory']); if (false === strpos($modinfo['directory'], '/')) { ZLoader::addAutoloader($moduleName, array(realpath("{$modpath}"), realpath("{$modpath}/{$osdir}/lib"))); } // load optional bootstrap $bootstrap = "{$modpath}/{$osdir}/bootstrap.php"; if (file_exists($bootstrap)) { include_once $bootstrap; } // register any event handlers. // module handlers must be attached from the bootstrap. if (is_dir("config/EventHandlers/{$osdir}")) { EventUtil::attachCustomHandlers("config/EventHandlers/{$osdir}"); } // load any plugins PluginUtil::loadPlugins("{$modpath}/{$osdir}/plugins", "ModulePlugin_{$osdir}"); self::$ooModules[$moduleName]['initialized'] = true; return true; }
/** * 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; }