/** * Reload routes for one module by name * @param string $moduleName (default: ZikulaRoutesModule) * @return boolean $hadRoutes */ public function reloadRoutesByModule($moduleName = "ZikulaRoutesRoutes") { $routeRepository = $this->entityManager->getRepository('ZikulaRoutesModule:RouteEntity'); $module = \ModUtil::getModule($moduleName); if ($module === null) { throw new NotFoundHttpException(); } /** @var \Zikula\RoutesModule\Entity\Repository\Route $routeRepository */ $hadRoutes = $routeRepository->removeAllOfModule($module); /** @var \Zikula\RoutesModule\Routing\RouteFinder $routeFinder */ $routeFinder = $this->get('zikularoutesmodule.routing_finder'); $routeCollection = $routeFinder->find($module); if ($routeCollection->count() > 0) { $routeRepository->addRouteCollection($module, $routeCollection); } return $hadRoutes; }
/** * Zikula_View function to provide easy access to an image * * This function provides an easy way to include an image. The function will return the * full source path to the image. It will as well provite the width and height attributes * if none are set. * * Available parameters: * - src The file name of the image * - modname The well-known name of a module (default: the current module) * - modplugin The name of the plugin in the passed module * - sysplugin The name of the system plugin * - width, height If set, they will be passed. If none is set, they are obtained from the image * - alt If not set, an empty string is being assigned * - title If set it will be passed as a title attribute * - assign If set, the results are assigned to the corresponding variable instead of printed out * - optional If set then the plugin will not return an error if an image is not found * - default If set then a default image is used should the requested image not be found (Note: full path required) * - set If modname is 'core' then the set parameter is set to define the directory in /images/ * - nostoponerror If set and error ocurs (image not found or src is no image), do not trigger_error, but return false * - retval If set indicated the field to return instead the array of values (src, width, etc.) * - fqurl If set the image path is absolute, if not relative * - all remaining parameters are passed to the image tag * * Example: {img src='heading.png'} * Output: <img src="modules/Example/images/en/heading.png" alt="" width="261" height="69" /> * * Example: {img src='heading.png' width='100' border='1' __alt='foobar'} * Output: <img src="modules/Example/images/en/heading.png" width="100" border="1" alt="foobar" /> * * Example: {img src='xhtml11.png' modname='core' set='powered'} * Output: <img src="themes/Theme/images/powered/xhtml11.png" alt="" width="88" height="31" /> * * Example: {img src='iconX.png' modname='ModName' modplugin='Plug1' set='icons'} * Output: <img src="modules/ModName/plugins/Plug1/images/icons/iconX.png" alt="" width="16" height="16" /> * * Example: {img src='iconY.png' sysplugin='Plug2' set='icons/small'} * Output: <img src="plugins/Plug2/images/icons/small/iconY.png" alt="" width="16" height="16" /> * * If the parameter assign is set, the results are assigned as an array. The components of * this array are the same as the attributes of the img tag; additionally an entry 'imgtag' is * set to the complete image tag. * * Example: * {img src="heading.png" assign="myvar"} * {$myvar.src} * {$myvar.width} * {$myvar.imgtag} * * Output: * modules/Example/images/en/heading.gif * 261 * <img src="modules/Example/images/en/heading.gif" alt="" width="261" height="69" /> * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string|void The img tag, null if $params['nostoponerror'] true and there is an error. */ function smarty_function_img($params, Zikula_View $view) { $nostoponerror = isset($params['nostoponerror']) && $params['nostoponerror'] ? true : false; if (!isset($params['src']) || !$params['src']) { if (!$nostoponerror) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('img', 'src'))); return; } else { return false; } } // process the image location $modname = isset($params['modname']) ? $params['modname'] : $view->toplevelmodule; $modplugin = isset($params['modplugin']) ? $params['modplugin'] : null; $sysplugin = isset($params['sysplugin']) ? $params['sysplugin'] : null; // process the image set $set = isset($params['set']) ? $params['set'] : null; $osset = DataUtil::formatForOS($set); // if the module name is 'core' if ($modname == 'core') { if (System::isLegacyMode() && (strpos($osset, 'icons/') !== false || strpos($osset, 'global/') !== false) && strpos($params['src'], '.gif')) { LogUtil::log(__f('Core image %s does not exist, please use the png format (called from %s).', array($params['src'], $view->getTemplatePath())), E_USER_DEPRECATED); $params['src'] = str_replace('.gif', '.png', $params['src']); } } // always provide an alt attribute. // if none is set, assign an empty one. $params['alt'] = isset($params['alt']) ? $params['alt'] : ''; // prevent overwriting surrounding titles (#477) if (isset($params['title']) && empty($params['title'])) { unset($params['title']); } // language $lang = ZLanguage::transformFS(ZLanguage::getLanguageCode()); if ($sysplugin) { $osplugdir = DataUtil::formatForOS($sysplugin); $pluglangpath = "plugins/{$osplugdir}/images/{$lang}"; $plugpath = "plugins/{$osplugdir}/images"; // form the array of paths $paths = array($pluglangpath, $plugpath); } else { // module directory if ($modname != 'core') { $modinfo = ModUtil::getInfoFromName($modname); $osmoddir = DataUtil::formatForOS($modinfo['directory']); $moduleDir = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; } if ($modplugin) { $osmodplugdir = DataUtil::formatForOS($modplugin); $modpluglangpath = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/Resources/public/images/{$lang}"; $modplugpath = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/Resources/public/images"; $modpluglangpathOld = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/images/{$lang}"; $modplugpathOld = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/images"; // form the array of paths $paths = array($modpluglangpath, $modplugpath, $modpluglangpathOld, $modplugpathOld); } else { // theme directory $ostheme = DataUtil::formatForOS(UserUtil::getTheme()); $theme = ThemeUtil::getTheme($ostheme); $themePath = null === $theme ? '' : $theme->getRelativePath() . '/Resources/public/images'; $themepath = $themePath; $corethemepath = "themes/{$ostheme}/images"; if ($modname == 'core') { $modpath = "images"; $paths = array($themepath, $corethemepath, $modpath); } else { $osmodname = DataUtil::formatForOS($modname); $themelangpath = "{$themePath}/{$lang}"; $themelangpathOld = "themes/{$ostheme}/templates/modules/{$osmodname}/images/{$lang}"; $themepathOld = "themes/{$ostheme}/templates/modules/{$osmodname}/images"; $module = ModUtil::getModule($modinfo['name']); $moduleBasePath = null === $module ? '' : $module->getRelativePath() . '/Resources/public/images'; $modlangpath = "{$moduleBasePath}/{$lang}"; $modpath = $moduleBasePath; $modlangpathOld = "{$moduleDir}/{$osmoddir}/images/{$lang}"; $modpathOld = "{$moduleDir}/{$osmoddir}/images"; $modlangpathOld2 = "{$moduleDir}/{$osmoddir}/pnimages/{$lang}"; $modpathOld2 = "{$moduleDir}/{$osmoddir}/pnimages"; // form the array of paths if (preg_match('/^admin.(png|gif|jpg)$/', $params['src'])) { // special processing for modules' admin icon $paths = array($modlangpath, $modpath, $modlangpathOld, $modpathOld, $modlangpathOld, $modpathOld, $modlangpathOld2, $modpathOld2); } else { $paths = array($themelangpath, $themepath, $themelangpathOld, $themepathOld, $corethemepath, $modlangpath, $modpath, $modlangpathOld, $modpathOld, $modlangpathOld2, $modpathOld2); } } } } $ossrc = DataUtil::formatForOS($params['src']); // search for the image $imgsrc = ''; foreach ($paths as $path) { $fullpath = $path . ($osset ? "/{$osset}/" : '/') . $ossrc; if (is_readable($fullpath)) { $imgsrc = $fullpath; break; } } if ($imgsrc == '' && isset($params['default'])) { $imgsrc = $params['default']; } // default for the optional flag $optional = isset($params['optional']) ? $params['optional'] : true; if ($imgsrc == '') { if ($optional) { if (!$nostoponerror) { $view->trigger_error(__f("%s: Image '%s' not found", array('img', DataUtil::formatForDisplay(($set ? "{$set}/" : '') . $params['src'])))); return; } else { return false; } } return; } // If neither width nor height is set, get these parameters. // If one of them is set, we do NOT obtain the real dimensions. // This way it is easy to scale the image to a certain dimension. if (!isset($params['width']) && !isset($params['height'])) { if (!($_image_data = @getimagesize($imgsrc))) { if (!$nostoponerror) { $view->trigger_error(__f("%s: Image '%s' is not a valid image file", array('img', DataUtil::formatForDisplay(($set ? "{$set}/" : '') . $params['src'])))); return; } else { return false; } } $params['width'] = $_image_data[0]; $params['height'] = $_image_data[1]; } $basepath = isset($params['fqurl']) && $params['fqurl'] ? System::getBaseUrl() : System::getBaseUri(); $params['src'] = $basepath . '/' . $imgsrc; $retval = isset($params['retval']) ? $params['retval'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['modname']); unset($params['retval']); unset($params['assign']); if (isset($params['altml'])) { // legacy unset($params['altml']); } if (isset($params['titleml'])) { // legacy unset($params['titleml']); } unset($params['optional']); unset($params['default']); unset($params['set']); unset($params['nostoponerror']); unset($params['fqurl']); $imgtag = '<img '; foreach ($params as $key => $value) { $imgtag .= $key . '="' . $value . '" '; } $imgtag .= '/>'; if (!empty($retval) && isset($params[$retval])) { return $params[$retval]; } elseif (!empty($assign)) { $params['imgtag'] = $imgtag; $view->assign($assign, $params); } else { return $imgtag; } }
/** * Selector for a module's tables or entities. * * This method is Backward Compatible with all Core versions back to 1.2.x * It scans for tables in `tables.php` as well as locating Doctrine 1 tables * or Doctrine 2 entities in either the 1.3.0 type directories or 1.4.0++ type * * @param string $modname Module name. * @param string $name Select field name. * @param string $selectedValue Selected value. * @param string $defaultValue Value for "default" option. * @param string $defaultText Text for "default" option. * @param boolean $submit Submit on choose. * @param string $remove Remove string from table name. * @param boolean $disabled Add Disabled attribute to select. * @param integer $nStripChars Strip the first n characters. * @param integer $multipleSize Size for multiple selects. * * @return string The rendered output. */ public static function getSelector_ModuleTables($modname, $name, $selectedValue = '', $defaultValue = 0, $defaultText = '', $submit = false, $remove = '', $disabled = false, $nStripChars = 0, $multipleSize = 1) { if (!$modname) { throw new \Exception(__f('Invalid %1$s passed to %2$s.', array('modname', 'HtmlUtil::getSelector_ModuleTables'))); } // old style 'tables.php' modules (Core 1.2.x--) $tables = ModUtil::dbInfoLoad($modname, '', true); $data = array(); if (is_array($tables) && $tables) { foreach ($tables as $k => $v) { if (strpos($k, '_column') === false && strpos($k, '_db_extra_enable') === false && strpos($k, '_primary_key_column') === false) { $checkColumns = $k . '_column'; if (!isset($tables[$checkColumns])) { continue; } } if (strpos($k, '_column') === false && strpos($k, '_db_extra_enable') === false && strpos($k, '_primary_key_column') === false) { if (strpos($k, 'z_') === 0) { $k = substr($k, 4); } if ($remove) { $k2 = str_replace($remove, '', $k); } else { $k2 = $k; } if ($nStripChars) { $k2 = ucfirst(substr($k2, $nStripChars)); } // Use $k2 for display also (instead of showing the internal table name) $data[$k2] = $k2; } } } if (!empty($data)) { return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, null, null, $submit, $disabled, $multipleSize); } // Doctrine 1 models (Core 1.3.0 - 1.3.5) DoctrineUtil::loadModels($modname); $records = Doctrine::getLoadedModels(); $data = array(); foreach ($records as $recordClass) { // remove records from other modules if (substr($recordClass, 0, strlen($modname)) != $modname) { continue; } // get table name of remove table prefix $tableNameRaw = Doctrine::getTable($recordClass)->getTableName(); sscanf($tableNameRaw, Doctrine_Manager::getInstance()->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT), $tableName); if ($remove) { $tableName = str_replace($remove, '', $tableName); } if ($nStripChars) { $tableName = ucfirst(substr($tableName, $nStripChars)); } $data[$tableName] = $tableName; } if (!empty($data)) { return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, null, null, $submit, $disabled, $multipleSize); } // Doctrine 2 entities (Core 1.3.0++) // Core-2.0 spec $module = ModUtil::getModule($modname); if (null !== $module && !class_exists($module->getVersionClass())) { // this check just confirming a Core-2.0 spec bundle - remove in 2.0.0 $capabilities = $module->getMetaData()->getCapabilities(); if (isset($capabilities['categorizable'])) { $data = array(); foreach ($capabilities['categorizable'] as $fullyQualifiedEntityName) { $nameParts = explode('\\', $fullyQualifiedEntityName); $entityName = array_pop($nameParts); $data[$entityName] = $entityName; } $selectedValue = count($data) == 1 ? $entityName : $defaultValue; return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, null, null, $submit, $disabled, $multipleSize); } } // (Core-1.3 spec) $modinfo = ModUtil::getInfo(ModUtil::getIdFromName($modname)); $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; $osdir = DataUtil::formatForOS($modinfo['directory']); $entityDirs = array("{$modpath}/{$osdir}/Entity/", "{$modpath}/{$osdir}/lib/{$osdir}/Entity/"); $entities = array(); foreach ($entityDirs as $entityDir) { if (file_exists($entityDir)) { $files = scandir($entityDir); foreach ($files as $file) { if ($file != '.' && $file != '..' && substr($file, -4) === '.php') { $entities[] = $file; } } } } $data = array(); foreach ($entities as $entity) { $possibleClassNames = array($modname . '_Entity_' . substr($entity, 0, strlen($entity) - 4)); if ($module) { $possibleClassNames[] = $module->getNamespace() . '\\Entity\\' . substr($entity, 0, strlen($entity) - 4); // Core 1.4.0++ } foreach ($possibleClassNames as $class) { if (class_exists($class)) { $entityName = substr($entity, 0, strlen($entity) - 4); if ($remove) { $entityName = str_replace($remove, '', $entityName); } if ($nStripChars) { $entityName = ucfirst(substr($entityName, $nStripChars)); } $data[$entityName] = $entityName; } } } return self::getSelector_Generic($name, $data, $selectedValue, $defaultValue, $defaultText, null, null, $submit, $disabled, $multipleSize); }
/** * @Route("/editregistry") * @Method("GET") * * edit category registry * * @param Request $request * * @return Response symfony response object * * @throws AccessDeniedException Thrown if the user doesn't have permission to administrate the module */ public function editregistryAction(Request $request) { if (!SecurityUtil::checkPermission('ZikulaCategoriesModule::', '::', ACCESS_ADMIN)) { throw new AccessDeniedException(); } $root_id = $request->get('dr', 1); $id = $request->get('id', 0); $obj = new CategoryRegistryEntity(); $category_registry = $request->query->get('category_registry', null); if ($category_registry) { $obj->merge($category_registry); $obj = $obj->toArray(); } $registries = $this->entityManager->getRepository('ZikulaCategoriesModule:CategoryRegistryEntity')->findBy(array(), array('modname' => 'ASC', 'property' => 'ASC')); $modules = $this->entityManager->getRepository('Zikula\\ExtensionsModule\\Entity\\ExtensionEntity')->findBy(array('state' => 3), array('displayname' => 'ASC')); $moduleOptions = array(); foreach ($modules as $module) { $bundle = \ModUtil::getModule($module['name']); if (null !== $bundle && !class_exists($bundle->getVersionClass())) { // this check just confirming a Core-2.0 spec bundle - remove in 2.0.0 // then instead of getting MetaData, could just do ModUtil::getCapabilitiesOf($module['name']) $capabilities = $bundle->getMetaData()->getCapabilities(); if (!isset($capabilities['categorizable'])) { continue; // skip this module if not categorizable } } $moduleOptions[$module['name']] = $module['displayname']; } $this->view->assign('objectArray', $registries)->assign('moduleOptions', $moduleOptions)->assign('newobj', $obj)->assign('root_id', $root_id)->assign('id', $id); return $this->response($this->view->fetch('Admin/registry_edit.tpl')); }
/** * Constructor. * * @param Zikula_ServiceManager $serviceManager ServiceManager. * @param string $moduleName Module name ("zikula" for system plugins). * @param integer|null $caching Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null). */ public function __construct(Zikula_ServiceManager $serviceManager, $moduleName = '', $caching = null) { $this->serviceManager = $serviceManager; $this->eventManager = $this->serviceManager->get('event_dispatcher'); $this->request = \ServiceUtil::get('request'); // set the error reporting level $this->error_reporting = isset($GLOBALS['ZConfig']['Debug']['error_reporting']) ? $GLOBALS['ZConfig']['Debug']['error_reporting'] : E_ALL; $this->error_reporting &= ~E_USER_DEPRECATED; $this->allow_php_tag = true; // get variables from input $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING); $type = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING); $func = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING); // set vars based on the module structures $this->homepage = PageUtil::isHomepage(); $this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype')); $this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc')); // Initialize the module property with the name of // the topmost module. For Hooks, Blocks, API Functions and others // you need to set this property to the name of the respective module! $this->toplevelmodule = ModUtil::getName(); if (!$moduleName) { $moduleName = $this->toplevelmodule; } $this->modinfo = ModUtil::getInfoFromName($moduleName); $this->module = array($moduleName => $this->modinfo); // initialise environment vars $this->language = ZLanguage::getLanguageCode(); $this->baseurl = System::getBaseUrl(); $this->baseuri = System::getBaseUri(); // system info $this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme())); $this->theme = $theme = $this->themeinfo['directory']; $themeBundle = ThemeUtil::getTheme($this->themeinfo['name']); //---- Plugins handling ----------------------------------------------- // add plugin paths switch ($this->modinfo['type']) { case ModUtil::TYPE_MODULE: $mpluginPathNew = "modules/" . $this->modinfo['directory'] . "/Resources/views/plugins"; $mpluginPath = "modules/" . $this->modinfo['directory'] . "/templates/plugins"; break; case ModUtil::TYPE_SYSTEM: $mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins"; $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins"; break; default: $mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins"; $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins"; } // add standard plugin search path $this->plugins_dir = array(); $this->addPluginDir('config/plugins'); // Official override $this->addPluginDir('lib/legacy/viewplugins'); // Core plugins $this->addPluginDir(isset($themeBundle) ? $themeBundle->getRelativePath() . '/plugins' : "themes/{$theme}/plugins"); // Theme plugins $this->addPluginDir('plugins'); // Smarty core plugins $this->addPluginDir($mpluginPathNew); // Plugins for current module $this->addPluginDir($mpluginPath); // Plugins for current module // check if the 'type' parameter in the URL is admin or adminplugin $legacyControllerType = FormUtil::getPassedValue('lct', 'user', 'GETPOST', FILTER_SANITIZE_STRING); if ($type === 'admin' || $type === 'adminplugin' || $legacyControllerType === 'admin') { // include plugins of the Admin module to the plugins_dir array if (!$this instanceof Zikula_View_Theme) { $this->addPluginDir('system/AdminModule/Resources/views/plugins'); } else { $this->load_filter('output', 'admintitle'); } } // theme plugins module overrides $themePluginsPath = isset($themeBundle) ? $themeBundle->getRelativePath() . '/modules/$moduleName/plugins' : "themes/{$theme}/templates/modules/{$moduleName}/plugins"; $this->addPluginDir($themePluginsPath); //---- Cache handling ------------------------------------------------- if ($caching && in_array((int) $caching, array(0, 1, 2))) { $this->caching = (int) $caching; } else { $this->caching = (int) ModUtil::getVar('ZikulaThemeModule', 'render_cache'); } $this->compile_id = ''; $this->cache_id = ''; // template compilation $this->compile_dir = CacheUtil::getLocalDir('view_compiled'); $this->compile_check = ModUtil::getVar('ZikulaThemeModule', 'render_compile_check'); $this->force_compile = ModUtil::getVar('ZikulaThemeModule', 'render_force_compile'); // template caching $this->cache_dir = CacheUtil::getLocalDir('view_cache'); $this->cache_lifetime = ModUtil::getVar('ZikulaThemeModule', 'render_lifetime'); $this->expose_template = ModUtil::getVar('ZikulaThemeModule', 'render_expose_template') == true ? true : false; // register resource type 'z' this defines the way templates are searched // during {include file='my_template.tpl'} this enables us to store selected module // templates in the theme while others can be kept in the module itself. $this->register_resource('z', array('Zikula_View_Resource', 'z_get_template', 'z_get_timestamp', 'z_get_secure', 'z_get_trusted')); // set 'z' as default resource type $this->default_resource_type = 'z'; // process some plugins specially when Render cache is enabled if (!$this instanceof Zikula_View_Theme && $this->caching) { $this->register_nocache_plugins(); } // register the 'nocache' block to allow dynamic zones caching templates $this->register_block('nocache', array('Zikula_View_Resource', 'block_nocache'), false); // For ajax requests we use the short urls filter to 'fix' relative paths if ($this->serviceManager->get('zikula')->getStage() & Zikula_Core::STAGE_AJAX && System::getVar('shorturls')) { $this->load_filter('output', 'shorturls'); } // register prefilters $this->register_prefilter('z_prefilter_add_literal'); $this->register_prefilter('z_prefilter_gettext_params'); //$this->register_prefilter('z_prefilter_notifyfilters'); // assign some useful settings $this->assign('homepage', $this->homepage)->assign('modinfo', $this->modinfo)->assign('module', $moduleName)->assign('toplevelmodule', $this->toplevelmodule)->assign('type', $this->type)->assign('func', $this->func)->assign('lang', $this->language)->assign('themeinfo', $this->themeinfo)->assign('themepath', isset($themeBundle) ? $themeBundle->getRelativePath() : $this->baseurl . 'themes/' . $theme)->assign('baseurl', $this->baseurl)->assign('baseuri', $this->baseuri)->assign('moduleBundle', ModUtil::getModule($moduleName))->assign('themeBundle', $themeBundle); if (isset($themeBundle)) { $stylePath = $themeBundle->getRelativePath() . "/Resources/public/css"; $javascriptPath = $themeBundle->getRelativePath() . "/Resources/public/js"; $imagePath = $themeBundle->getRelativePath() . "/Resources/public/images"; $imageLangPath = $themeBundle->getRelativePath() . "/Resources/public/images/" . $this->language; } else { $stylePath = $this->baseurl . "themes/{$theme}/style"; $javascriptPath = $this->baseurl . "themes/{$theme}/javascript"; $imagePath = $this->baseurl . "themes/{$theme}/images"; $imageLangPath = $this->baseurl . "themes/{$theme}/images/" . $this->language; } $this->assign('stylepath', $stylePath)->assign('scriptpath', $javascriptPath)->assign('imagepath', $imagePath)->assign('imagelangpath', $imageLangPath); // for {gt} template plugin to detect gettext domain if ($this->modinfo['type'] == ModUtil::TYPE_MODULE) { $this->domain = ZLanguage::getModuleDomain($this->modinfo['name']); } // make render object available to modifiers parent::assign('zikula_view', $this); // add ServiceManager, EventManager and others to all templates parent::assign('serviceManager', $this->serviceManager); parent::assign('eventManager', $this->eventManager); parent::assign('zikula_core', $this->serviceManager->get('zikula')); parent::assign('request', $this->request); $modvars = ModUtil::getModvars(); // Get all modvars from any modules that have accessed their modvars at least once. // provide compatibility 'alias' array keys // @todo remove after v1.4.0 if (isset($modvars['ZikulaAdminModule'])) { $modvars['Admin'] = $modvars['ZikulaAdminModule']; } if (isset($modvars['ZikulaBlocksModule'])) { $modvars['Blocks'] = $modvars['ZikulaBlocksModule']; } if (isset($modvars['ZikulaCategoriesModule'])) { $modvars['Categories'] = $modvars['ZikulaCategoriesModule']; } if (isset($modvars['ZikulaExtensionsModule'])) { $modvars['Extensions'] = $modvars['ZikulaExtensionsModule']; } if (isset($modvars['ZikulaGroupsModule'])) { $modvars['Groups'] = $modvars['ZikulaGroupsModule']; } if (isset($modvars['ZikulaMailerModule'])) { $modvars['Mailer'] = $modvars['ZikulaMailerModule']; } if (isset($modvars['ZikulaPageLockModule'])) { $modvars['PageLock'] = $modvars['ZikulaPageLockModule']; } if (isset($modvars['ZikulaPermissionsModule'])) { $modvars['Permissions'] = $modvars['ZikulaPermissionsModule']; } if (isset($modvars['ZikulaSearchModule'])) { $modvars['Search'] = $modvars['ZikulaSearchModule']; } if (isset($modvars['ZikulaSecurityCenterModule'])) { $modvars['SecurityCenter'] = $modvars['ZikulaSecurityCenterModule']; } if (isset($modvars['ZikulaSettingsModule'])) { $modvars['Settings'] = $modvars['ZikulaSettingsModule']; } if (isset($modvars['ZikulaThemeModule'])) { $modvars['Theme'] = $modvars['ZikulaThemeModule']; } if (isset($modvars['ZikulaUsersModule'])) { $modvars['Users'] = $modvars['ZikulaUsersModule']; } // end compatibility aliases parent::assign('modvars', $modvars); $this->add_core_data(); // metadata for SEO if (!$this->serviceManager->hasParameter('zikula_view.metatags')) { $this->serviceManager->setParameter('zikula_view.metatags', new ArrayObject(array())); } parent::assign('metatags', $this->serviceManager->getParameter('zikula_view.metatags')); if (isset($themeBundle) && $themeBundle->isTwigBased()) { // correct asset urls when smarty output is wrapped by twig theme $this->load_filter('output', 'asseturls'); } $event = new \Zikula\Core\Event\GenericEvent($this); $this->eventManager->dispatch('view.init', $event); }
/** * Set the state of a module. * * @param int[] $args { * @type int $id The module id * @type int $state The new state * } * * @return boolean True if successful, false otherwise * * @throws \InvalidArgumentException Thrown if either the id or state parameters are not set or numeric * @throws AccessDeniedException Thrown if the user doesn't have edit permissions over the module or * if the module cannot be obtained from the database * @throws \RuntimeException Thrown if the requested state transition is invalid */ public function setState($args) { // Argument check if (!isset($args['id']) || !is_numeric($args['id']) || !isset($args['state']) || !is_numeric($args['state'])) { throw new \InvalidArgumentException(__('Invalid arguments array received')); } // Security check if (!System::isInstalling()) { if (!SecurityUtil::checkPermission('ZikulaExtensionsModule::', '::', ACCESS_EDIT)) { throw new AccessDeniedException(); } } // get module $module = $this->entityManager->getRepository(self::EXTENSION_ENTITY)->find($args['id']); if (empty($module)) { return false; } if ($module === false) { throw new AccessDeniedException(); } // Check valid state transition switch ($args['state']) { case ModUtil::STATE_UNINITIALISED: if ($this->serviceManager['multisites.enabled'] == 1) { if (!SecurityUtil::checkPermission('ZikulaExtensionsModule::', '::', ACCESS_ADMIN)) { throw new \RuntimeException($this->__('Error! Invalid module state transition.')); } } break; case ModUtil::STATE_INACTIVE: $eventName = CoreEvents::MODULE_DISABLE; break; case ModUtil::STATE_ACTIVE: if ($module->getState() === ModUtil::STATE_INACTIVE) { // ACTIVE is used for freshly installed modules, so only register the transition // if previously inactive. $eventName = CoreEvents::MODULE_ENABLE; } break; case ModUtil::STATE_MISSING: break; case ModUtil::STATE_UPGRADED: $oldstate = $module->getState(); if ($oldstate == ModUtil::STATE_UNINITIALISED) { throw new \RuntimeException($this->__('Error! Invalid module state transition.')); } break; } // change state $module->setState($args['state']); $this->entityManager->flush(); // clear the cache before calling events /** @var $cacheClearer \Zikula\Bundle\CoreBundle\CacheClearer */ $cacheClearer = $this->get('zikula.cache_clearer'); $cacheClearer->clear('symfony.config'); // state changed, so update the ModUtil::available-info for this module. $modinfo = ModUtil::getInfo($args['id']); ModUtil::available($modinfo['name'], true); if (isset($eventName)) { // only notify for enable or disable transitions $moduleBundle = \ModUtil::getModule($modinfo['name']); $event = new ModuleStateEvent($moduleBundle, $moduleBundle === null ? $modinfo : null); $this->getDispatcher()->dispatch($eventName, $event); } return true; }
/** * Zikula_View function to create help link. * * This function creates a help link. * * To make the link appear as a button, wrap it in a div or span with a class * of z-buttons. * * Available parameters: * - filename: name of file, defaults to 'help.txt'. * - anchor: anchor marker. * - popup: opens the help file in a new window using javascript. * - width: width of the window if newwindow is set, default 600. * - height: height of the window if newwindow is set, default 400. * - title: name of the new window if new window is set, default is 'Help'. * - link_contents the text for the link (between the <a> and </a> tags); optional, if not specified, then the title is used. * - icon_type an optional icon type to include in the link, separated from the link_contents (or title) by a non-breaking space; equivalent to the type parameter from the {icon} template function * - icon_size the size of the icon (e.g., extrasmall); optional if link_icon_type is specified, defaults to 'extrasmall', otherwise ignored; * equivalent to the size parameter of the {icon} template function * - icon_width the width of the icon in pixels; optional if link_icon_type is specified, if not specified, then obtained from size, otherwise ignored; * equivalent to the width parameter of the {icon} template function * - icon_height the height of the icon in pixels; optional if link_icon_type is specified, if not specified, then obtained from size, otherwise ignored; * equivalent to the height parameter of the {icon} template function * - icon_alt the alternate text for the icon, used for the alt param of the {icon} template function; optional if link_icon_type is specified, * defaults to an empty string, otherwise ignored * - icon_title the title text for the icon, used for the title param of the {icon} template function; optional if link_icon_type is specified, * defaults to an empty string, otherwise ignored * - icon_optional if true and the icon image is not found then an error will not be returned, used for the optinal param of the {icon} template * function; optional if link_icon_type is specified, defaults to false, otherwise ignored * - icon_default the full path to an image file to use if the icon is not found, used for the default param of the {icon} template * function; optional if link_icon_type is specified, defaults to an empty string, otherwise ignored * - icon_right if true, then the icon is placed on the right side of the link text (the text from either link_contents or title); optional, * defaults to false (placing the icon on the left side of the text) * - icon_* all remaining parameters with a "icon_" prefix are passed to the {icon} function and subsequently to the <img> tag, except for * 'icon_assign' which is completely ignored; optional if link_icon_type is specified, otherwise ignored * - class: class for use in the <a> tag. * - assign: if set, the results (array('url', 'link') are assigned to the corresponding variable instead of printed out. * * Example: A pop-up help window with a width of 400 and a height of 300, containing the contents of help.txt, and a title of 'Help' * {helplink popup='1' width='400' height='300' filename='help.txt' title='Help'} * * Example: The same as above, except displayed as a button with an icon image placed on the left side of the text 'Help' separated by a non-breaking space. * The image does not have either alternate text nor a title. * <div class="z-buttons"> * {helplink popup='1' width='400' height='300' filename='help.txt' title='Help' icon_type='help' icon_size='extrasmall'} * </div> * * Example: The same as above, except the icon's <img> tag will contain a class attrbute with the value "my_class" * <div class="z-buttons"> * {helplink popup='1' width='400' height='300' filename='help.txt' title='Help' icon_type='help' icon_size='extrasmall' icon_class='my_class'} * </div> * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string|void */ function smarty_function_helplink($params, Zikula_View $view) { $userLang = ZLanguage::transformFS(ZLanguage::getLanguageCode()); $systemLang = System::getVar('language_i18n'); $iconParams = array(); if (!empty($params) && is_array($params)) { foreach ($params as $key => $value) { if (strpos($key, 'icon_') === 0 && strlen($key) > 5) { $iconParams[substr($key, 5)] = $value; unset($params[$key]); } } } if (!empty($iconParams) && isset($iconParams['type'])) { // We need to make sure the icon template function is available so we can call it. require_once $view->_get_plugin_filepath('function', 'icon'); $iconRightSide = false; if (isset($iconParams['right'])) { $iconRightSide = (bool) $iconParams['right']; unset($iconParams['right']); } if (isset($iconParams['assign'])) { // We cannot use the assign parameter with the icon function in this context. unset($iconParams['assign']); } } else { $iconParams = false; $iconRightSide = false; } $title = isset($params['title']) ? $params['title'] : 'Help'; $linkContents = isset($params['link_contents']) ? $params['link_contents'] : $title; $fileName = isset($params['filename']) ? $params['filename'] : 'help.txt'; $chapter = isset($params['anchor']) ? '#' . $params['anchor'] : ''; $class = isset($params['class']) ? $params['class'] : null; $width = isset($params['width']) ? $params['width'] : 600; $height = isset($params['height']) ? $params['height'] : 400; $popup = isset($params['popup']) ? true : false; $modname = $view->getModuleName(); $linkID = isset($params['linkid']) ? $params['linkid'] : DataUtil::formatForDisplay(strtolower('manuallink_' . $modname . '_' . hash('md5', serialize($params)))); $paths = array(); $module = ModUtil::getModule($modname); if ($module) { $base = $module->getPath(); $paths[] = "{$base}/Resources/docs/{$userLang}/{$fileName}"; $paths[] = "{$base}/Resources/docs/{$systemLang}/{$fileName}"; $paths[] = "{$base}/Resources/docs/en/{$fileName}"; } $base = ModUtil::getModuleBaseDir($modname) . "/{$modname}/docs"; $paths[] = "{$base}/{$userLang}/{$fileName}"; $paths[] = "{$base}/docs/{$systemLang}/{$fileName}"; $paths[] = "{$base}/en/{$fileName}"; $found = false; foreach ($paths as $path) { if (is_readable($path)) { $found = true; $contents = StringUtil::getMarkdownExtraParser()->transform(file_get_contents($path)); $url = $path . $chapter; break; } } if (!$found) { //$view->trigger_error(__f('Helpfile %s not found', $fileName)); return; } $linkContents = DataUtil::formatForDisplayHTML($linkContents); if ($iconParams) { $iconContents = smarty_function_icon($iconParams, $view); if (isset($iconContents) && is_string($iconContents) && !empty($iconContents)) { if ($iconRightSide) { $linkContents = $linkContents . ' ' . $iconContents; } else { $linkContents = $iconContents . ' ' . $linkContents; } } else { //$view->trigger_error(__f('Icon for type '%s' not found', $iconParams['type'])); return; } } $class = !empty($class) ? "class=\"{$class}\"" : ''; if ($popup) { PageUtil::addVar('javascript', 'zikula.ui'); $link = array(); $link[] = "<a id=\"{$linkID}\" {$class} data-toggle=\"modal\" data-target=\"#{$linkID}_content\" title=\"{$title}\">" . $linkContents . "</a>"; $link[] = '<div class="modal fade" id="' . $linkID . '_content" tabindex="-1" role="dialog" aria-labelledby="' . $linkID . '_label" aria-hidden="true">'; $link[] = '<div class="modal-dialog">'; $link[] = '<div class="modal-content">'; $link[] = '<div class="modal-header">'; $link[] = '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'; $link[] = '<h4 class="modal-title" id="' . $linkID . '_label">' . $title . '</h4>'; $link[] = '</div>'; $link[] = '<div class="modal-body">'; $link[] = $contents; $link[] = '</div>'; $link[] = '</div>'; $link[] = '</div>'; $link[] = '</div>'; $link = implode("\n", $link); } else { $link = "<a id=\"{$linkID}\" {$class} href=\"" . DataUtil::formatForDisplay($url) . "\" title=\"{$title}\">" . $linkContents . "</a>"; } if (isset($params['assign'])) { $ret = array('url' => $url, 'link' => $link); $view->assign($params['assign'], $ret); return; } else { return $link; } }
/** * Get the modules stylesheet from several possible sources. * * @param string $modname The modules name (optional, defaults to top level module). * @param string $stylesheet The stylesheet file (optional). * * @return string Path of the stylesheet file, relative to PN root folder. */ public static function getModuleStylesheet($modname = '', $stylesheet = '') { // default for the module if (empty($modname)) { $modname = ModUtil::getName(); } // default for the style sheet if (empty($stylesheet)) { $stylesheet = ModUtil::getVar($modname, 'modulestylesheet'); if (empty($stylesheet)) { $stylesheet = 'style.css'; } } $module = ModUtil::getModule($modname); $osstylesheet = DataUtil::formatForOS($stylesheet); $osmodname = DataUtil::formatForOS($modname); $paths = array(); // config directory $configstyledir = 'config/style'; $paths[] = "{$configstyledir}/{$osmodname}"; // theme directory $themeName = DataUtil::formatForOS(UserUtil::getTheme()); $theme = self::getTheme($themeName); if ($theme) { $bundleRelativePath = substr($theme->getPath(), strpos($theme->getPath(), 'themes'), strlen($theme->getPath())); $bundleRelativePath = str_replace('\\', '/', $bundleRelativePath); } $paths[] = null === $theme ? "themes/{$themeName}/style/{$osmodname}" : $bundleRelativePath . '/Resources/css/' . $theme->getName(); // module directory $modinfo = ModUtil::getInfoFromName($modname); $osmoddir = DataUtil::formatForOS($modinfo['directory']); if ($module) { $dir = ModUtil::getModuleBaseDir($modname); $bundleRelativePath = substr($module->getPath(), strpos($module->getPath(), $dir), strlen($module->getPath())); $bundleRelativePath = str_replace('\\', '/', $bundleRelativePath); $paths[] = $bundleRelativePath . "/Resources/public/css"; } $paths[] = "modules/{$osmoddir}/style"; $paths[] = "system/{$osmoddir}/style"; // search for the style sheet $csssrc = ''; foreach ($paths as $path) { if (is_readable("{$path}/{$osstylesheet}")) { $csssrc = "{$path}/{$osstylesheet}"; break; } } return $csssrc; }
/** * Get module domain. * * @param string $name Module name. * * @return string */ public static function getModuleDomain($name) { $module = ModUtil::getModule($name); return null === $module ? strtolower('module_' . $name) : $module->getTranslationDomain(); }
/** * @param AbstractModule $module * @param bool $userRoutes * @return bool */ public function removeAllOfModule(AbstractModule $module, $userRoutes = false) { $routes = $this->findBy(array('userRoute' => $userRoutes, 'bundle' => $module->getName())); if (empty($routes)) { return false; } $workflowHelper = new WorkflowUtil(\ServiceUtil::getManager(), \ModUtil::getModule('ZikulaRoutesModule')); foreach ($routes as $routeEntity) { $workflowHelper->executeAction($routeEntity, 'delete'); } return true; }