/** * Event listener for 'core.postinit' event. * * @param Zikula_Event $event * * @return void */ public static function coreinit(Zikula_Event $event) { // get the module name $args = array(); $args['modulename'] = ModUtil::getName(); $module = $args['modulename']; // exit if Content module active - to avoid double loadings if user has given ids and functions if ($args['modulename'] == 'content') { return; } // Security check if user has COMMENT permission for scribite if (!SecurityUtil::checkPermission('Scribite::', "{$module}::", ACCESS_COMMENT)) { return; } // get passed func $func = FormUtil::getPassedValue('func', isset($args['func']) ? $args['func'] : null, 'GET'); // get config for current module $modconfig = array(); $modconfig = ModUtil::apiFunc('Scribite', 'user', 'getModuleConfig', array('modulename' => $args['modulename'])); // return if module is not supported or editor is not set if (!$modconfig['mid'] || $modconfig['modeditor'] == '-') { return; } // check if current func is fine for editors or funcs is empty (or all funcs) if (is_array($modconfig['modfuncs']) && (in_array($func, $modconfig['modfuncs']) || $modconfig['modfuncs'][0] == 'all')) { $args['areas'] = $modconfig['modareas']; $args['editor'] = $modconfig['modeditor']; $scribite = ModUtil::apiFunc('Scribite', 'user', 'loader', array('modulename' => $args['modulename'], 'editor' => $args['editor'], 'areas' => $args['areas'])); // add the scripts to page header if ($scribite) { PageUtil::AddVar('header', $scribite); } } }
/** * Zikula_View function to create manual link. * * This function creates a manual link from some parameters. * * Available parameters: * - manual: name of manual file, manual.html if not set * - chapter: an anchor in the manual file to jump to * - newwindow: opens the manual 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 newwindow is set, default is modulename * - 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 * {manuallink newwindow=1 width=400 height=300 title=rtfm } * * @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_manuallink($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('manuallink')), E_USER_DEPRECATED); $userlang = ZLanguage::transformFS(ZLanguage::getLanguageCode()); $stdlang = System::getVar('language_i18n'); $title = isset($params['title']) ? $params['title'] : 'Manual'; $manual = isset($params['manual']) ? $params['manual'] : 'manual.html'; $chapter = isset($params['chapter']) ? '#' . $params['chapter'] : ''; $class = isset($params['class']) ? 'class="' . $params['class'] . '"' : ''; $width = isset($params['width']) ? $params['width'] : 600; $height = isset($params['height']) ? $params['height'] : 400; $modname = ModUtil::getName(); $possibleplaces = array("modules/{$modname}/docs/{$userlang}/manual/{$manual}", "modules/{$modname}/docs/{$stdlang}/manual/{$manual}", "modules/{$modname}/docs/en/manual/{$manual}", "modules/{$modname}/docs/{$userlang}/{$manual}", "modules/{$modname}/docs/{$stdlang}/{$manual}", "modules/{$modname}/docs/lang/en/{$manual}"); foreach ($possibleplaces as $possibleplace) { if (file_exists($possibleplace)) { $url = $possibleplace . $chapter; break; } } if (isset($params['newwindow'])) { $link = "<a {$class} href='#' onclick=\"window.open( '" . DataUtil::formatForDisplay($url) . "' , '" . DataUtil::formatForDisplay($modname) . "', 'status=yes,scrollbars=yes,resizable=yes,width={$width},height={$height}'); picwin.focus();\">" . DataUtil::formatForDisplayHTML($title) . "</a>"; } else { $link = "<a {$class} href=\"" . DataUtil::formatForDisplay($url) . "\">" . DataUtil::formatForDisplayHTML($title) . "</a>"; } if (isset($params['assign'])) { $ret = array('url' => $url, 'link' => $link); $view->assign($params['assign'], $ret); return; } else { return $link; } }
/** * Zikula_View function to include module specific javascripts * * Available parameters: * - modname module name (if not set, the current module is assumed) * if modname="" than we will look into the main javascript folder * - script name of the external javascript file (mandatory) * - modonly javascript will only be included when the the current module is $modname * - onload function to be called with onLoad handler in body tag, makes sense with assign set only, see example #2 * - assign if set, the tag and the script filename are returned * * Example: {modulejavascript modname=foobar script=module_admin_config.js modonly=1 } * Output: <script type="text/javascript" src="modules/foobar/javascript/module_admin_config.js"> * * Example: {modulejavascript modname=foobar script=module_admin_config.js modonly=1 onload="dosomething()" assign=myjs } * Output: nothing, but assigns a variable containing several values: * $myjs.scriptfile = "modules/foobar/javascript/module_admin_config.js" * $myjs.tag = "<script type=\"text/javascript\" src=\"modules/foobar/javascript/module_admin_config.js\"></script>" * $myjs.onload = "onLoad=\"dosomething()\""; * Possible code in master.tpl would be: * * ... * { $myjs.tag } * </head> * <body { $myjs.onload } > * ... * * which results in * * ... * <script type="text/javascript" src="modules/foobar/javascript/module_admin_config.js"></script> * </head> * <body onLoad="dosomething()" > * ... * * if foobar is the current module. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string The tag. */ function smarty_function_modulejavascript($params, Zikula_View $view) { // check if script is set (mandatory) if (!isset($params['script'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modulejavascript', 'script'))); return false; } // check if modname is set and if not, if $modonly is set if (!isset($params['modname'])) { if (isset($params['modonly'])) { // error - we want $modonly only with $modname $view->trigger_error(__f('Error! in %1$s: parameter \'%2$s\' only supported together with \'%3$s\' set.', array('modulejavascript', 'modonly', 'modname'))); return; } // we use the current module name $params['modname'] = ModUtil::getName(); } if (isset($params['modonly']) && $params['modname'] != ModUtil::getName()) { // current module is not $modname - do nothing and return silently return; } // if modname is empty, we will search the main javascript folder if ($params['modname'] == '') { $searchpaths = array('javascript', 'javascript/ajax'); } else { // theme directory $theme = DataUtil::formatForOS(UserUtil::getTheme()); $osmodname = DataUtil::formatForOS($params['modname']); $themepath = "themes/{$theme}/Resources/public/js/{$osmodname}"; // module directory $modinfo = ModUtil::getInfoFromName($params['modname']); $osmoddir = DataUtil::formatForOS($modinfo['directory']); $modpath = "modules/{$osmoddir}/Resources/public/js"; $syspath = "system/{$osmoddir}/Resources/public/js"; $searchpaths = array($themepath, $modpath, $syspath); } $osscript = DataUtil::formatForOS($params['script']); // search for the javascript $scriptsrc = ''; foreach ($searchpaths as $path) { if (is_readable("{$path}/{$osscript}")) { $scriptsrc = "{$path}/{$osscript}"; break; } } // if no module javascript has been found then return no content $tag = empty($scriptsrc) ? '' : '<script type="text/javascript" src="' . $scriptsrc . '"></script>'; // onLoad event handler used? $onload = isset($params['onload']) ? 'onLoad="' . $params['onload'] . '"' : ''; if (isset($params['assign'])) { $return = array(); $return['scriptfile'] = $scriptsrc; $return['tag'] = $tag; $return['onload'] = $onload; $view->assign($params['assign'], $return); } else { return $tag; } }
/** * Zikula_View function to display admin links for a module. * * Example: * {moduleadminlinks modname=Example start="[" end="]" seperator="|" class="z-menuitem-title"} * * Available parameters: * - modname Module name to display links for. * - start Start string (optional). * - end End string (optional). * - seperator Link seperator (optional). * - class CSS class (optional). * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string A formatted string containing navigation for the module admin panel. */ function smarty_function_moduleadminlinks($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('moduleadminlinks', 'modulelinks')), E_USER_DEPRECATED); // set some defaults $start = isset($params['start']) ? $params['start'] : '['; $end = isset($params['end']) ? $params['end'] : ']'; $seperator = isset($params['seperator'])? $params['seperator']: '|'; $class = isset($params['class']) ? $params['class'] : 'z-menuitem-title'; $modname = $params['modname']; unset ($params['modname']); if (!isset($modname) || !ModUtil::available($modname)) { $modname = ModUtil::getName(); } // check our module name if (!ModUtil::available($modname)) { $view->trigger_error('moduleadminlinks: '.__f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($modname))); return false; } // get the links from the module API $links = ModUtil::apiFunc($modname, 'admin', 'getlinks', $params); // establish some useful count vars $linkcount = count($links); $adminlinks = "<span class=\"$class\">$start "; foreach ($links as $key => $link) { $id = ''; if (isset($link['id'])) { $id = 'id="' . $link['id'] . '"'; } if (!isset($link['title'])) { $link['title'] = $link['text']; } if (isset($link['disabled']) && $link['disabled'] == true) { $adminlinks .= "<span $id>" . '<a class="z-disabledadminlink" title="' . DataUtil::formatForDisplay($link['title']) . '">' . DataUtil::formatForDisplay($link['text']) . '</a> '; } else { $adminlinks .= "<span $id><a href=\"" . DataUtil::formatForDisplay($link['url']) . '" title="' . DataUtil::formatForDisplay($link['title']) . '">' . DataUtil::formatForDisplay($link['text']) . '</a> '; } if ($key == $linkcount-1) { $adminlinks .= '</span>'; continue; } // linebreak if (isset($link['linebreak']) && $link['linebreak'] == true) { $adminlinks .= "</span>\n "; $adminlinks .= "$end</span><br /><span class=\"$class\">$start "; } else { $adminlinks .= "$seperator</span>\n "; } } $adminlinks .= "$end</span>\n"; return $adminlinks; }
/** * Constructor. * * @param mixed $message Response status/error message, may be string or array. * @param mixed $payload Payload. */ public function __construct($message, $payload = null) { $this->messages = (array) $message; $this->payload = $payload; if ($this->newCsrfToken) { $this->authid = SecurityUtil::generateAuthKey(ModUtil::getName()); $this->csrfToken = SecurityUtil::generateCsrfToken(); } }
/** * Zikula_View function to the topmost module name * * This function currently returns the name of the current top-level * module, false if not in a module. * * * Available parameters: * - assign: If set, the results are assigned to the corresponding * variable instead of printed out * * Example * {modgetname|safetext} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string The module variable. */ function smarty_function_modgetname($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $result = ModUtil::getName(); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function to the admin image path of a module * * This function returns the path to the admin image of the current top-level * module if $modname is not set. Otherwise it returns the path to the admin * image of the given module. * * * Available parameters: * - assign: If set, the results are assigned to the corresponding * variable instead of printed out * - modname: The module to return the image path for * (defaults to top-level module) * * Example * {modgetimage|safetext} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string The path to the module's admin image */ function smarty_function_modgetimage($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $modname = isset($params['modname']) ? $params['modname'] : ModUtil::getName(); $path = ModUtil::getModuleImagePath($modname); if ($assign) { $view->assign($assign, $path); } else { return $path; } }
/** * Zikula_View insert function to dynamically generated an authorisation key * * Available parameters: * - module: The well-known name of a module to execute a function from (required) * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Example * <input type="hidden" name="authid" value="{insert name='generateauthkey' module='Users'}" /> * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string */ function smarty_insert_generateauthkey($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('insert name="secgenauthkey" ...', "insert name='csrftoken' ...")), E_USER_DEPRECATED); $module = isset($params['module']) ? $params['module'] : null; if (!$module) { $module = ModUtil::getName(); } $result = SecurityUtil::generateAuthKey($module); // NOTE: assign parameter is handled by the smarty_core_run_insert_handler(...) function in lib/vendor/Smarty/internals/core.run_insert_handler.php return $result; }
/** * Constructor. * * @param mixed $payload Application data. * @param mixed $message Response status/error message, may be string or array. * @param array $options Options. */ public function __construct($payload, $message = null, array $options = array()) { $this->payload = $payload; $this->messages = (array) $message; $this->options = $options; if ($this->newCsrfToken) { if (System::isLegacyMode()) { $this->authid = SecurityUtil::generateAuthKey(ModUtil::getName()); } $this->csrfToken = SecurityUtil::generateCsrfToken(); } }
/** * Constructor. * * @param mixed $payload Application data. * @param mixed $message Response status/error message, may be string or array. * @param array $options Options. */ public function __construct($payload, $message = null, array $options = array()) { $this->payload = $payload; $this->messages = (array) $message; $this->options = $options; if ($this->newCsrfToken) { $this->csrfToken = \SecurityUtil::generateCsrfToken(); } if (\System::isLegacyMode()) { $this->authid = \SecurityUtil::generateAuthKey(\ModUtil::getName()); } parent::__construct('', $this->statusCode); }
/** * Smarty function to generate a unique key to secure forms content as unique. * * Note that you must not cache the outputs from this function, as its results * change aech time it is called. The Zikula developers are looking for ways to * automise this. * * * Available parameters: * - module: The well-known name of a module to execute a function from (required) * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Example * <input type="hidden" name="authid" value="{secgenauthkey module="MyModule"}"> * * @todo prevent this function from being cached (Smarty 2.6.0) * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object * @return string the authentication key * @deprecated */ function smarty_function_secgenauthkey($params, $smarty) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('secgenauthkey', 'insert name="csrftoken"')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $module = isset($params['module']) ? $params['module'] : null; if (!$module) { $module = ModUtil::getName(); } $result = SecurityUtil::generateAuthKey($module); if ($assign) { $smarty->assign($assign, $result); } else { return $result; } }
/** * Smarty function to displaya modules online manual * * Admin * {adminonlinemanual} * * @see function.admincategorymenu.php::smarty_function_admincategoreymenu() * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object * @param int xhtml if set, the link to the navtabs.css will be xhtml compliant * @return string the results of the module function */ function smarty_function_adminonlinemanual($params, $smarty) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('adminonlinemanual')), E_USER_DEPRECATED); $lang = ZLanguage::transformFS(ZLanguage::getLanguageCode()); $modinfo = ModUtil::getInfoFromName(ModUtil::getName()); $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; $file = DataUtil::formatForOS("{$modpath}/{$modinfo['directory']}/lang/{$lang}/manual.html"); $man_link = ''; if (is_readable($file)) { PageUtil::addVar('javascript', 'zikula.ui'); $man_link = '<div style="margin-top: 20px; text-align:center">[ <a id="online_manual" href="' . $file . '">' . __('Online manual') . '</a> ]</div>' . "\n"; $man_link .= '<script type="text/javascript">var online_manual = new Zikula.UI.Window($(\'online_manual\'),{resizable: true})</script>' . "\n"; } return $man_link; }
/** * Adds default filters as where clauses. * * @param Doctrine\ORM\QueryBuilder $qb Query builder to be enhanced. * @param array $parameters List of determined filter options. * * @return Doctrine\ORM\QueryBuilder Enriched query builder instance. */ protected function applyDefaultFilters(QueryBuilder $qb, $parameters = array()) { $currentModule = ModUtil::getName(); //FormUtil::getPassedValue('module', '', 'GETPOST'); $currentType = FormUtil::getPassedValue('type', 'user', 'GETPOST'); if ($currentType == 'admin' && ($currentModule == 'Reviews' || $currentModule == 'Extensions')) { return $qb; } if (!in_array('workflowState', array_keys($parameters)) || empty($parameters['workflowState'])) { // per default we show approved reviews only $onlineStates = array('approved'); $qb->andWhere('tbl.workflowState IN (:onlineStates)')->setParameter('onlineStates', $onlineStates); } return $qb; }
/** * Smarty function build module header in user content page. * * {moduleheader} * * Available parameters: * modname Module name to display header for (optional, defaults to current module) * type Type for module links (defaults to 'user') * title Title to display in header (optional, defaults to module name) * titlelink Link to attach to title (optional, defaults to none) * setpagetitle If set to true, {pagesetvar} is used to set page title * insertstatusmsg If set to true, {insert name='getstatusmsg'} is put in front of template * menufirst If set to true, menu is first, then title * putimage If set to true, module image is also displayed next to title * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string A formatted string containing navigation for the module admin panel. */ function smarty_function_moduleheader($params, $view) { if (!isset($params['modname']) || !ModUtil::available($params['modname'])) { $params['modname'] = ModUtil::getName(); } if (empty($params['modname'])) { return false; } $type = isset($params['type']) ? $params['type'] : 'user'; $assign = isset($params['assign']) ? $params['assign'] : null; $menufirst = isset($params['menufirst']) ? $params['menufirst'] : false; $putimage = isset($params['putimage']) ? $params['putimage'] : false; $setpagetitle = isset($params['setpagetitle']) ? $params['setpagetitle'] : false; $insertstatusmsg = isset($params['insertstatusmsg']) ? $params['insertstatusmsg'] : false; $cutlenght = isset($params['cutlenght']) ? $params['cutlenght'] : 20; if ($putimage) { $image = isset($params['image']) ? $params['image'] : ModUtil::getModuleImagePath($params['modname']); } else { $image = ''; } if (!isset($params['title'])) { $modinfo = ModUtil::getInfoFromName($params['modname']); if (isset($modinfo['displayname'])) { $params['title'] = $modinfo['displayname']; } else { $params['title'] = ModUtil::getName(); } } $titlelink = isset($params['titlelink']) ? $params['titlelink'] : false; $renderer = Zikula_View::getInstance('Theme'); $renderer->setCaching(Zikula_View::CACHE_DISABLED); $renderer->assign('userthemename', UserUtil::getTheme()); $renderer->assign('modname', $params['modname']); $renderer->assign('type', $params['type']); $renderer->assign('title', $params['title']); $renderer->assign('titlelink', $titlelink); $renderer->assign('truncated', mb_strlen($params['title']) > $cutlenght); $renderer->assign('titletruncated', mb_substr($params['title'], 0, $cutlenght) . '...'); $renderer->assign('setpagetitle', $setpagetitle); $renderer->assign('insertstatusmsg', $insertstatusmsg); $renderer->assign('menufirst', $menufirst); $renderer->assign('image', $image); if ($assign) { $view->assign($assign, $renderer->fetch('moduleheader.tpl')); } else { return $renderer->fetch('moduleheader.tpl'); } }
/** * Zikula_View function to display a Zikula specific debug Zikula.UI.Window * * This function shows a Zikula debug window if the user has sufficient access rights * * You need the following permission to see this: * ModuleName::debug | .* | ACCESS_ADMIN * * This plugin is basing on the original debug plugin written by Monte Ohrt <*****@*****.**> * * Examples * { zdebug } * { zdebug width='400' } * * Parameters: * width: Width of the console UI.Window (default: 580) * height: Height of the console UI.Window (default: 600) * checkpermission: If false, then a security check is not performed, allowing debug information to * be displayed, for example, when there is no user logged in. Development mode * must also be enabled. Defaults to true; * template Specify different debug template, default zdebug.tpl, * must be stored in system/Theme/templates. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string Debug output. */ function smarty_function_zdebug($params, Zikula_View $view) { $zdebug = ''; $thismodule = ModUtil::getName(); $skipPermissionCheck = System::isDevelopmentMode() && isset($params['checkpermission']) && !$params['checkpermission']; if ($skipPermissionCheck || SecurityUtil::checkPermission($thismodule.'::debug', '::', ACCESS_ADMIN)) { // backup and modify the view attributes $_template_dir_orig = $view->template_dir; $_default_resource_type_orig = $view->default_resource_type; $_compile_id_orig = $view->_compile_id; $view->template_dir = 'system/Theme/templates'; $view->default_resource_type = 'file'; $view->_plugins['outputfilter'] = null; $view->_compile_id = null; $width = isset($params['width']) && is_integer($params['width']) ? $params['width'] : 580; $height = isset($params['height']) && is_integer($params['height']) ? $params['height'] : 600; $popup = isset($params['popup']) ? (bool)$params['popup'] : false; // figure out the template to use if (isset($params['template']) && !empty($params['template'])) { if (is_readable($view->template_dir . '/' . $params['template'])) { $view->debug_tpl = $params['template']; } } else { $view->debug_tpl = $popup ? 'zpopup.tpl' : 'zdebug.tpl'; } // get the zdebug output $zdebug = $view->assign('zdebugwidth', $width) ->assign('zdebugheight', $height) ->assign('zdebugpopup', $popup) ->_fetch($view->debug_tpl); // restore original values $view->_compile_id = $_compile_id_orig; $view->template_dir = $_template_dir_orig; $view->default_resource_type = $_default_resource_type_orig; } return $zdebug; }
/** * bbsmiles * returns a html snippet with buttons for inserting bbsmiles into a text * * @param $args['textfieldid'] id of the textfield for inserting smilies */ public function bbsmiles($args) { if (!isset($args['textfieldid']) || empty($args['textfieldid'])) { return LogUtil::registerArgsError(); } // if we have more than one textarea we need to distinguish them, so we simply use // a counter stored in a session var until we find a better solution $counter = SessionUtil::getVar('bbsmile_counter', 0); $counter++; SessionUtil::setVar('bbsmile_counter', $counter); $this->view->assign('counter', $counter); $this->view->assign('textfieldid', $args['textfieldid']); PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('BBSmile')); $templatefile = DataUtil::formatForOS(ModUtil::getName()) . '.tpl'; if ($this->view->template_exists($templatefile)) { return $this->view->fetch($templatefile); } $this->view->add_core_data(); return $this->view->fetch('bbsmile_user_bbsmiles.tpl'); }
/** * Zikula_View function to retrieve module information * * This function retrieves module information from the database and returns them * or assigns them to a variable for later use * * * Available parameters: * - info the information you want to retrieve from the modules info, * "all" results in assigning all information, see $assign * - assign (optional or mandatory :-)) if set, assign the result instead of returning it * if $info is "all", a $assign is mandatory and the default is modinfo * - modname (optional) module name, if not set, the recent module is used * - modid (optional) module id, if not set, the recent module is used * * Example * {modgetinfo info='displayname'} * {modgetinfo info='all' assign='gimmeeverything'} * {modgetinfo modname='anyymodname' info='all' assign='gimmeeverything'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string The module variable. */ function smarty_function_modgetinfo($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $info = isset($params['info']) ? $params['info'] : null; $modid = isset($params['modid']) ? (int) $params['modid'] : 0; $modname = isset($params['modname']) ? $params['modname'] : null; $default = isset($params['default']) ? $params['default'] : false; if (!$modid) { $modname = $modname ? $modname : ModUtil::getName(); if (!ModUtil::available($modname)) { if ($assign) { $view->assign($assign, $default); return false; } $view->assign($assign, $default); return; } $modid = ModUtil::getIdFromName($modname); } $modinfo = ModUtil::getInfo($modid); $info = strtolower($info); if ($info != 'all' && !isset($modinfo[$info])) { $view->trigger_error(__f('Invalid %1$s [%2$s] passed to %3$s.', array('info', $info, 'modgetinfo'))); return false; } if ($info == 'all') { $assign = $assign ? $assign : 'modinfo'; $view->assign($assign, $modinfo); } else { if ($assign) { $view->assign($assign, $modinfo[$info]); } else { return DataUtil::formatForDisplay($modinfo[$info]); } } }
/** * Returns the panel data in raw format. * * @return array */ public function getPanelData() { $data = array(); // zikula config $data['global'] = array('title' => __('Zikula configuration'), 'content' => array('ZConfig' => $GLOBALS['ZConfig'])); // current top level module $module = \ModUtil::getName(); if ($module) { $data[$module] = array('title' => __f('Module %s', $module), 'content' => \ModUtil::getVar($module)); } return $data; }
/** * Zikula_View function to display menulinks in an unordered list * * Example * {modulelinks data=$links id='listid' class='z-menulinks' itemclass='z-ml-item' first='z-ml-first' last='z-ml-last'} * * Available parameters: * links Array with menulinks (text, url, title, id, class, disabled) (optional) * modname Module name to display links for (optional) * type Function type where the getlinks-function is located (optional) * menuid ID for the unordered list (optional) * menuclass Class for the unordered list (optional) * itemclass Array with menulinks (text, url, title, class, disabled) (optional) * first Class for the first element (optional) * last Class for the last element (optional) * seperator Link seperator (optional) * class CSS class (optional). * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string A formatted string containing navigation for the module admin panel. */ function smarty_function_modulelinks($params, Zikula_View $view) { return 'hallo welt'; $menuLinks = isset($params['links']) ? $params['links'] : ''; $menuId = isset($params['menuid']) ? $params['menuid'] : ''; $menuClass = isset($params['menuclass']) ? $params['menuclass'] : 'z-menulinks'; $menuItemClass = isset($params['itemclass']) ? $params['itemclass'] : ''; $menuItemFirst = isset($params['first']) ? $params['first'] : ''; $menuItemLast = isset($params['last']) ? $params['last'] : ''; if (empty($menuLinks)) { if (!isset($params['modname']) || !ModUtil::available($params['modname'])) { $params['modname'] = ModUtil::getName(); } // check our module name if (!ModUtil::available($params['modname'])) { $view->trigger_error('modulelinks: '.__f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($params['modname']))); return false; } $params['type'] = isset($params['type']) ? $params['type'] : 'admin'; // get the links from the module API $menuLinks = ModUtil::apiFunc($params['modname'], $params['type'], 'getlinks', $params); } // return if there are no links to print if (!$menuLinks) { if (isset($params['assign'])) { $view->assign($params['assign'], $menuLinks); } else { return ''; } } $html = ''; if (!empty($menuLinks)) { $html = '<ul'; $html .= !empty($menuId) ? ' id="'.$menuId.'"' : ''; $html .= !empty($menuClass) ? ' class="'.$menuClass.'"' : ''; $html .= '>'; $i = 1; $size = count($menuLinks); foreach ($menuLinks as $menuitem) { $class = array(); $class[] = $size == 1 ? 'z-ml-single' : ''; $class[] = ($i == 1 && $size > 1) ? $menuItemFirst : ''; $class[] = ($i == $size && $size > 1) ? $menuItemLast : ''; $class[] = !empty($menuItemClass) ? $menuItemClass : ''; $class[] = (isset($menuitem['disabled']) && $menuitem['disabled'] == true) ? 'z-ml-disabled' : ''; $class = trim(implode(' ', $class)); $i++; $html .= '<li'; $html .= !empty($menuitem['id']) ? ' id="'.$menuitem['id'].'"' : ''; $html .= !empty($class) ? ' class="'.$class.'"' : ''; $html .= '>'; $attr = !empty($menuitem['title']) ? ' title="'.$menuitem['title'].'"' : ''; $attr .= !empty($menuitem['class']) ? ' class="z-iconlink '.$menuitem['class'].'"' : ''; if (isset($menuitem['disabled']) && $menuitem['disabled'] == true) { $html .= '<a '.$attr.'>'.$menuitem['text'].'</a>'; } elseif (!empty($menuitem['url'])) { $html .= '<a href="'.DataUtil::formatForDisplay($menuitem['url']).'"'.$attr.'>'.$menuitem['text'].'</a>'; } else { $html .= '<span'.$attr.'>'.$menuitem['text'].'</span>'; } if (isset($menuitem['links'])) { $html .= _smarty_function_modulelinks($i, $menuitem['links']); } $html .= '</li>'; } $html .= '</ul>'; } if (isset($params['assign'])) { $view->assign($params['assign'], $html); } else { return $html; } }
/** * Insert a categorization data object. * * @param array $obj The object we wish to store categorization data for. * @param string $tablename The object's tablename. * @param string $idcolumn The object's idcolumn (optional) (default='id'). * @param boolean $wasUpdateQuery True after an update and false after an insert. * * @return The result from the category data insert operation */ public static function storeObjectCategories($obj, $tablename, $idcolumn = 'id', $wasUpdateQuery = true) { if (!$obj) { throw new \Exception(__f('Invalid %1$s passed to %2$s.', array('object', __CLASS__ . '::' . __FUNCTION__))); } if (!$tablename) { throw new \Exception(__f('Invalid %1$s passed to %2$s.', array('tablename', __CLASS__ . '::' . __FUNCTION__))); } if (!$idcolumn) { throw new \Exception(__f('Invalid %1$s passed to %2$s.', array('idcolumn', __CLASS__ . '::' . __FUNCTION__))); } if (!ModUtil::dbInfoLoad('ZikulaCategoriesModule')) { return false; } if (!isset($obj['__CATEGORIES__']) || !is_array($obj['__CATEGORIES__']) || !$obj['__CATEGORIES__']) { return false; } if ($wasUpdateQuery) { self::deleteObjectCategories($obj, $tablename, $idcolumn); } // ensure that we don't store duplicate object mappings $values = array(); foreach ($obj['__CATEGORIES__'] as $k => $v) { if (isset($values[$v])) { unset($obj['__CATEGORIES__'][$k]); } else { $values[$v] = 1; } } // cache category id arrays to improve performance with DBUtil::(insert|update)ObjectArray() static $modTableCategoryIDs = array(); // Get the ids of the categories properties of the object $modname = isset($obj['__META__']['module']) ? $obj['__META__']['module'] : ModUtil::getName(); $reg_key = $modname . '_' . $tablename; if (!isset($modTableCategoryIDs[$reg_key])) { $modTableCategoryIDs[$reg_key] = CategoryRegistryUtil::getRegisteredModuleCategoriesIds($modname, $tablename); } $reg_ids = $modTableCategoryIDs[$reg_key]; $cobj = array(); $cobj['table'] = $tablename; $cobj['obj_idcolumn'] = $idcolumn; $res = true; foreach ($obj['__CATEGORIES__'] as $prop => $cat) { // if there's all the data and the Registry exists // the category is mapped if ($cat && $prop && isset($reg_ids[$prop])) { $cobj['id'] = ''; $cobj['modname'] = $modname; $cobj['obj_id'] = $obj[$idcolumn]; $cobj['category_id'] = $cat; $cobj['reg_id'] = $reg_ids[$prop]; $res = DBUtil::insertObject($cobj, 'categories_mapobj'); } } $dbtables = DBUtil::getTables(); if (isset($dbtables[$tablename])) { DBUtil::flushCache($tablename); } return (bool) $res; }
/** * Get note icons for managment * * @param array $args The values that define a specific note * * @return A string with the icons images and links */ public function icons($args) { // Security check $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ)); $agenda = FormUtil::getPassedValue('agenda', isset($args['agenda']) ? $args['agenda'] : null, 'POST'); $daid = FormUtil::getPassedValue('daid', isset($args['daid']) ? $args['daid'] : null, 'POST'); $accessLevel = FormUtil::getPassedValue('accessLevel', isset($args['accessLevel']) ? $args['accessLevel'] : null, 'POST'); $note = FormUtil::getPassedValue('note', isset($args['note']) ? $args['note'] : null, 'POST'); $mes = FormUtil::getPassedValue('mes', isset($args['mes']) ? $args['mes'] : null, 'POST'); $any = FormUtil::getPassedValue('any', isset($args['any']) ? $args['any'] : null, 'POST'); $user = UserUtil::getVar('uid'); $icons = ''; // Check wether it's protected $imatgeprotegida = ($note['protegida'] == 1) ? 'nocandau.gif' : 'candau.gif'; $protegida = ($note['protegida'] == 1) ? $this->__('Delete protection against automatic deletion for this event') : $this->__('Protected? '); if ($note['completa'] == 1 || (strpos($note['completedByUser'], '$' . $user . '$') !== false && $daid == 0)) { $imatge = ($daid != 0) ? 'mostra.gif' : 'ncompleta.gif'; $marcar = ($daid != 0) ? $this->__('Show') : $this->__('Mark as not completed'); } else { $imatge = ($daid != 0) ? 'amaga.gif' : 'completa.gif'; $marcar = ($daid != 0) ? $this->__('Hide') : $this->__('Mark as completed'); } if ((isset($agenda['gAccessLevel']) && (strpos($agenda['gAccessLevel'], '$owne|' . $user . '$') !== false) || $agenda['gAccessLevel'] == '') && ($accessLevel == 4 || ($accessLevel == 3 && $note['usuari'] == $user)) && ($note['daid'] == 0 || $daid > 0)) { $icons = "<a href=index.php?module=IWagendas&func=editar&mes=" . $mes . "&any=" . $any . "&aid=" . $note['aid'] . "&daid=" . $note['daid'] . " title='" . $this->__('Edit') . "'><img src=\"modules/IWagendas/images/editar.gif\" alt='" . $this->__('Edit') . "'></a>"; } if ((isset($agenda['gAccessLevel']) && strpos($agenda['gAccessLevel'], '$owne|' . $user . '$') !== false || isset($agenda['gAccessLevel']) && $agenda['gAccessLevel'] == '' || $daid == 0) && ($accessLevel == 4 || ($accessLevel == 3 && $note['usuari'] == $user) || ($daid == 0 && $user != '-1'))) { $icons .= ( $note['rid'] > 0) ? "<a href=index.php?module=IWagendas&func=esborra&mes=" . $mes . "&any=" . $any . "&aid=" . $note['aid'] . "&daid=" . $daid . " title='" . $this->__('Delete') . "'><img src=\"modules/IWagendas/images/del.gif\" alt='" . $this->__('Delete') . "'></a>" : "<a href=\"javascript:deleteNote(" . $note['aid'] . "," . $daid . ")\" title='" . $this->__('Delete') . "' ><img src=\"modules/" . ModUtil::getName() . "/images/del.gif\" alt='" . $this->__('Delete') . "'></a>"; } if ($accessLevel == 4 || ($accessLevel == 3 && $note['usuari'] == $user) || ($daid == 0 && $user != '-1')) { if ($note['gCalendarEventId'] == '' || $daid == 0) $icons .= "<a href=\"javascript:completeNote(" . $note['aid'] . "," . $daid . ")\" title='" . $marcar . "' id=\"acompletedIcon_" . $note['aid'] . "\" ><img id=\"completedIcon_" . $note['aid'] . "\" src=\"modules/IWagendas/images/" . $imatge . "\" alt='" . $marcar . "'></a>"; } if ((isset($agenda['gAccessLevel']) && strpos($agenda['gAccessLevel'], '$owne|' . $user . '$') !== false || isset($agenda['gAccessLevel']) && $agenda['gAccessLevel'] == '') && ($accessLevel == 4 || ($accessLevel == 3 && $note['usuari'] == $user) && ($note['daid'] == 0 || $daid > 0))) $icons .= "<a href=\"javascript:protectNote(" . $note['aid'] . "," . $daid . ")\" title=\"" . $protegida . "\" id=\"aprotectedIcon_" . $note['aid'] . "\" ><img id=\"protectedIcon_" . $note['aid'] . "\" src=\"modules/IWagendas/images/" . $imatgeprotegida . "\" alt='" . $protegida . "'></a>"; // If it's a shared agenda, show the icon to copy to personal agenda if ($note['daid'] > 0 && $user != '-1') $icons .= "<a href=index.php?module=IWagendas&func=meva&mes=" . $mes . "&any=" . $any . "&aid=" . $note['aid'] . "&daid=" . $daid . " title='" . $this->__('Send register to my personal agenda') . "'><img src=\"modules/IWagendas/images/meva.gif\" alt='" . $this->__('Send register to my personal agenda') . "'></a>"; return $icons; }
/** * Get available admin panel links. * * @return array array of admin links. */ public function getlinks($args) { $permgrp = isset($args['permgrp']) && !is_numeric($args['permgrp']) ? $args['permgrp'] : -1; $links = array(); if (SecurityUtil::checkPermission('Permissions::', '::', ACCESS_READ)) { $links[] = array('url' => ModUtil::url('Permissions', 'admin', 'view', array()), 'text' => $this->__('Permission rules list'), 'id' => 'permissions_view', 'class' => 'z-icon-es-view'); } if (SecurityUtil::checkPermission('Permissions::', '::', ACCESS_ADD)) { $links[] = array('url' => ModUtil::url('Permissions', 'admin', 'listedit', array('action' => 'add')), 'text' => $this->__('Create new permission rule'), 'id' => 'permissions_new', 'class' => 'z-icon-es-new'); } if (SecurityUtil::checkPermission('Permissions::', '::', ACCESS_ADMIN)) { $links[] = array('url' => ModUtil::url('Permissions', 'admin', 'modifyconfig'), 'text' => $this->__('Settings'), 'id' => 'permissions_modifyconfig', 'class' => 'z-icon-es-config'); } if (ModUtil::getName() == 'Permissions') { $links[] = array('url' => ModUtil::url('Permissions', 'admin', 'viewinstanceinfo'), 'text' => $this->__('Permission rules information'), 'title' => $this->__('Permission rules information'), 'class' => 'z-icon-es-info showinstanceinformation'); } return $links; }
/** * get workflow state of object * * @param array &$obj Array object. * @param string $table Table name. * @param string $idcolumn Id field, default = 'id'. * @param string $module Module name (defaults to current module). * * @return mixed String workflow state name or false. */ public static function getWorkflowState(&$obj, $table, $idcolumn = 'id', $module = null) { if (empty($module)) { $module = ModUtil::getName(); } if (!isset($obj['__WORKFLOW__'])) { if (!self::getWorkflowForObject($obj, $table, $idcolumn, $module)) { return false; } } $workflow = $obj['__WORKFLOW__']; return $workflow['state']; }
/** * 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(); } $modname = preg_match('/\\w+Module$/', $modname) ? $modname : $modname . 'Module'; // default for the style sheet if (empty($stylesheet)) { $stylesheet = ModUtil::getVar($modname, 'modulestylesheet'); if (empty($stylesheet)) { $stylesheet = 'style.css'; } } $osstylesheet = DataUtil::formatForOS($stylesheet); $osmodname = DataUtil::formatForOS($modname); // config directory $configstyledir = 'config/style'; $configpath = "{$configstyledir}/{$osmodname}"; // theme directory $theme = DataUtil::formatForOS(UserUtil::getTheme()); $themepath = "themes/{$theme}/Resources/public/css/{$osmodname}"; // module directory $modinfo = ModUtil::getInfoFromName($modname); $osmoddir = DataUtil::formatForOS($modinfo['directory']); $modpath = "modules/{$osmoddir}/Resources/public/css"; $syspath = "system/{$osmoddir}/Resources/public/css"; // search for the style sheet $csssrc = ''; foreach (array($configpath, $themepath, $modpath, $syspath) as $path) { if (is_readable("{$path}/{$osstylesheet}")) { $csssrc = "{$path}/{$osstylesheet}"; break; } } return $csssrc; }
/** * Inserts the common ajax javascript files in page header. * * Insert the common ajax javascript files (prototype, scriptaculous) in the * page header using page vars. <i>All other javascript files have to be added * manually on-demand using the {@link smarty_function_pageaddvar() pageaddvar} plugin.</i> * * Available attributes: * - modname (string) the module name in which to look for the base javascript file for the module; defaults to top level module when used in a block template. * - filename (string) (optional) filename to load (default ajax.js) * - noscriptaculous (mixed) (optional) does not include scriptaculous.js if set * - validation (mixed) (optional) includes validation.js if set * - lightbox (mixed) (optional) includes lightbox.js if set (loads scriptaculous effects if noscriptaculous is set) * - imageviewer (mixed) (optional) includes Zikula.ImageViewer.js if set (loads scriptaculous effects and dragdrop if noscriptaculous is set) * - assign (string) (optional) the name of the template variable to which the script tag string is assigned, <i>instead of</i> * adding them to the page variables through PageUtil::addVar * * * Examples: * * <samp>{ajaxheader modname='Example' filename='example.js'}</samp> * * <samp>{ajaxheader modname='Example' noscriptaculous=1}</samp> * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return void */ function smarty_function_ajaxheader($params, Zikula_View $view) { // use supplied modname or top level module $modname = (isset($params['modname'])) ? $params['modname'] : ModUtil::getName(); // define the default filename $filename = (isset($params['filename'])) ? $params['filename'] : 'Zikula.js'; $validation = (isset($params['validation'])) ? true : false; $lightbox = (isset($params['lightbox'])) ? true : false; $ui = (isset($params['ui'])) ? true : false; $imageviewer = (isset($params['imageviewer'])) ? true : false; // create an empty return $return = ''; // we always need those $scripts = array('prototype', 'zikula'); if ($validation) { $scripts[] = 'validation'; } if ($ui) { $scripts[] = 'livepipe'; $scripts[] = 'zikula.ui'; } if ($lightbox) { // check if lightbox is present - if not, load ImageViewer instead if (is_readable('javascript/ajax/lightbox.js')) { $scripts[] = 'javascript/ajax/lightbox.js'; if (isset($params['assign'])) { $return = '<link rel="stylesheet" href="javascript/ajax/lightbox/lightbox.css" type="text/css" media="screen" />'; } else { PageUtil::addVar('stylesheet', 'javascript/ajax/lightbox/lightbox.css'); } } else { $imageviewer = true; } } if ($imageviewer) { $scripts[] = 'zikula.imageviewer'; if (isset($params['assign'])) { $return = '<link rel="stylesheet" href="javascript/helpers/ImageViewer/ImageViewer.css" type="text/css" media="screen" />'; } } $modinfo = ModUtil::getInfoFromName($modname); if ($modinfo !== false) { $osdirectory = DataUtil::formatForOS($modinfo['directory']); $osfilename = DataUtil::formatForOS($filename); $base = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; if (file_exists($file = "$base/$osdirectory/javascript/$osfilename") || file_exists($file = "$base/$osdirectory/pnjavascript/$osfilename")) { $scripts[] = DataUtil::formatForDisplay($file); } } if (isset($params['assign'])) { // create script tags now $scripts = JCSSUtil::prepareJavascripts($scripts); foreach ($scripts as $script) { $return .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n"; } $view->assign($params['assign'], $return); } else { PageUtil::addVar('javascript', $scripts); } return; }
/** * Checks which path to use for required template. * * @param string $template Template name. * * @return string Template path. */ public function get_template_path($template) { if (isset($this->templateCache[$template])) { return $this->templateCache[$template]; } // the current module $modname = ModUtil::getName(); foreach ($this->module as $module => $modinfo) { // prepare the values for OS $module = $modinfo['name']; $os_modname = DataUtil::formatForOS($modname); $os_module = DataUtil::formatForOS($module); $os_theme = DataUtil::formatForOS($this->theme); $os_dir = $modinfo['type'] == ModUtil::TYPE_MODULE ? 'modules' : 'system'; $ostemplate = DataUtil::formatForOS($template); try { $bundle = $this->getContainer()->get('kernel')->getBundle($module); $bundlePath = $relativepath = $bundle->getRelativePath() . '/Resources/views'; } catch (\InvalidArgumentException $e) { } if (!isset($bundlePath)) { $relativepath = "{$os_dir}/{$os_module}/Resources/views"; if (!is_dir($relativepath)) { $relativepath = "{$os_dir}/{$os_module}/templates"; } } $templatefile = "{$relativepath}/{$ostemplate}"; $override = self::getTemplateOverride($templatefile); if ($override === false) { // no override present if (!System::isLegacyMode()) { if (is_readable($templatefile)) { $this->templateCache[$template] = $relativepath; return $relativepath; } else { return false; } } } else { if (is_readable($override)) { $path = substr($override, 0, strrpos($override, $ostemplate)); $this->templateCache[$template] = $path; return $path; } } // The rest of this code is scheduled for removal from 1.5.0 - drak // check the module for which we're looking for a template is the // same as the top level mods. This limits the places to look for // templates. if ($module == $modname) { $search_path = array("themes/{$os_theme}/templates/modules/{$os_module}", "config/templates/{$os_module}", $relativepath, "{$os_dir}/{$os_module}/templates"); } else { $search_path = array("themes/{$os_theme}/templates/modules/{$os_module}/{$os_modname}", "themes/{$os_theme}/templates/modules/{$os_module}", "config/templates/{$os_module}/{$os_modname}", "config/templates/{$os_module}", $relativepath, "{$os_dir}/{$os_module}/templates/{$os_modname}", "{$os_dir}/{$os_module}/templates"); } foreach ($search_path as $path) { if (is_readable("{$path}/{$ostemplate}")) { $this->templateCache[$template] = $path; return $path; } } } // when we arrive here, no path was found return false; }
/** * Generate auth key. * * @param string $modname Module name. * * @deprecated since 1.3.0 * * @return string An encrypted key for use in authorisation of operations. */ public static function generateAuthKey($modname = '') { // Ugly hack for Zikula_Response_Ajax which for BC reasons needs to add authid to response // So when this method is called by Zikula_Response_Ajax or Zikula_Response_Ajax_Error class // do not mark it as deprecated. $trace = debug_backtrace(false); if (!isset($trace[1]['class']) || !in_array($trace[1]['class'], array('Zikula_Response_Ajax', 'Zikula_Response_Ajax_Error'))) { LogUtil::log(__f('Warning! Static call %1$s is deprecated. Please use %2$s instead.', array('SecurityUtil::generateAuthKey()', 'SecurityUtil::generateCsrfToken()')), E_USER_DEPRECATED); } // since we need sessions for authorisation keys we should check // if a session exists and if not create one SessionUtil::requireSession(); if (empty($modname)) { $modname = ModUtil::getName(); } // Remove from 1.4 if (System::isLegacyMode() && $modname == 'Modules') { LogUtil::log(__('Warning! "Modules" module has been renamed to "Extensions". Please update any generateAuthKey calls in PHP or templates.')); $modname = 'ZikulaExtensionsModule'; } // get the module info $modinfo = ModUtil::getInfoFromName($modname); $modname = strtolower($modinfo['name']); // get the array of randomed values per module // and generate the one of the current module if doesn't exist $rand_arr = SessionUtil::getVar('rand'); if (!isset($rand_arr[$modname])) { $rand_arr[$modname] = RandomUtil::getString(32, 40, false, true, true, false, true, true, false); SessionUtil::setVar('rand', $rand_arr); } $key = $rand_arr[$modname] . $modname; if (System::getVar('keyexpiry') > 0) { $timestamp = time(); $authid = sha1($key . $timestamp) . $timestamp; } else { $authid = sha1($key); } // Return encrypted key return $authid; }
/** * Zikula_View function to display menulinks in an unordered list * * Example * {modulelinks data=$links id='listid' class='navbar navbar-default' itemclass='z-ml-item' first='z-ml-first' last='z-ml-last'} * * Available parameters: * links Array with menulinks (text, url, title, id, class, disabled) (optional) * modname Module name to display links for (optional) * type Function type where the getLinks-function is located (optional) * menuid ID for the unordered list (optional) * menuclass Class for the unordered list (optional) * itemclass Array with menulinks (text, url, title, class, disabled) (optional) * first Class for the first element (optional) * last Class for the last element (optional) * seperator Link seperator (optional) * class CSS class (optional). * returnAsArray return results as array, not as formatted html - MUST set assign * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string A formatted string containing navigation for the module admin panel. */ function smarty_function_modulelinks($params, Zikula_View $view) { $menuLinks = isset($params['links']) ? $params['links'] : ''; $menuId = isset($params['menuid']) ? $params['menuid'] : ''; $menuClass = isset($params['menuclass']) ? $params['menuclass'] : 'navbar navbar-default navbar-modulelinks navbar-modulelinks-main'; $menuItemClass = isset($params['itemclass']) ? $params['itemclass'] : ''; $menuItemFirst = isset($params['first']) ? $params['first'] : ''; $menuItemLast = isset($params['last']) ? $params['last'] : ''; $returnAsArray = isset($params['returnAsArray']) ? (bool) $params['returnAsArray'] : false; if (empty($menuLinks)) { if (!isset($params['modname']) || !ModUtil::available($params['modname'])) { $params['modname'] = ModUtil::getName(); } // check our module name if (!ModUtil::available($params['modname'])) { $view->trigger_error('modulelinks: ' . __f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($params['modname']))); return false; } $params['type'] = isset($params['type']) ? $params['type'] : 'admin'; // get the menu links // try the Core-2.0 way first, then try the legacy way. $menuLinks = $view->getContainer()->get('zikula.link_container_collector')->getLinks($params['modname'], $params['type']); if (empty($menuLinks)) { $menuLinks = ModUtil::apiFunc($params['modname'], $params['type'], 'getLinks', $params); } } // return if there are no links to print or template has requested to returnAsArray if (!$menuLinks || $returnAsArray && isset($params['assign'])) { if (isset($params['assign'])) { $view->assign($params['assign'], $menuLinks); } return ''; } $html = ''; if (!empty($menuLinks)) { $html = '<ul'; $html .= !empty($menuId) ? ' id="' . $menuId . '"' : ''; $html .= !empty($menuClass) ? ' class="' . $menuClass . '"' : ''; $html .= '>'; $i = 1; $size = count($menuLinks); foreach ($menuLinks as $menuitem) { $class = array(); $class[] = $size == 1 ? 'z-ml-single' : ''; $class[] = $i == 1 && $size > 1 ? $menuItemFirst : ''; $class[] = $i == $size && $size > 1 ? $menuItemLast : ''; $class[] = !empty($menuItemClass) ? $menuItemClass : ''; $class[] = isset($menuitem['disabled']) && $menuitem['disabled'] == true ? 'z-ml-disabled' : ''; $class = trim(implode(' ', $class)); $i++; if (System::isLegacyMode() && !empty($class) && isset($menuitem['class'])) { if ($menuitem['class'] == 'z-icon-es-add') { $menuitem['class'] = null; $menuitem['icon'] = 'plus'; } elseif ($menuitem['class'] == 'z-icon-es-back') { $menuitem['class'] = null; $menuitem['icon'] = 'arrow-left'; } elseif ($menuitem['class'] == 'z-icon-es-cancel') { $menuitem['class'] = null; $menuitem['icon'] = 'times'; } elseif ($menuitem['class'] == 'z-icon-es-config') { $menuitem['class'] = null; $menuitem['icon'] = 'wrench'; } elseif ($menuitem['class'] == 'z-icon-es-copy') { $menuitem['class'] = null; $menuitem['icon'] = 'files-o'; } elseif ($menuitem['class'] == 'z-icon-es-cubes') { $menuitem['class'] = null; $menuitem['icon'] = 'th'; } elseif ($menuitem['class'] == 'z-icon-es-cut') { $menuitem['class'] = null; $menuitem['icon'] = 'scissors'; } elseif ($menuitem['class'] == 'z-icon-es-delete') { $menuitem['class'] = null; $menuitem['icon'] = 'trash-o'; } elseif ($menuitem['class'] == 'z-icon-es-display') { $menuitem['class'] = null; $menuitem['icon'] = 'eye'; } elseif ($menuitem['class'] == 'z-icon-es-edit') { $menuitem['class'] = null; $menuitem['icon'] = 'pencil-square-o'; } elseif ($menuitem['class'] == 'z-icon-es-error') { $menuitem['class'] = null; $menuitem['icon'] = 'exclamation-triangle'; } elseif ($menuitem['class'] == 'z-icon-es-export') { $menuitem['class'] = null; $menuitem['icon'] = 'upload'; } elseif ($menuitem['class'] == 'z-icon-es-gears') { $menuitem['class'] = null; $menuitem['icon'] = 'gears'; } elseif ($menuitem['class'] == 'z-icon-es-filter') { $menuitem['class'] = null; $menuitem['icon'] = 'filter'; } elseif ($menuitem['class'] == 'z-icon-es-group') { $menuitem['class'] = null; $menuitem['icon'] = 'users'; } elseif ($menuitem['class'] == 'z-icon-es-help') { $menuitem['class'] = null; $menuitem['icon'] = 'info'; } elseif ($menuitem['class'] == 'z-icon-es-home') { $menuitem['class'] = null; $menuitem['icon'] = 'home'; } elseif ($menuitem['class'] == 'z-icon-es-hook') { $menuitem['class'] = null; $menuitem['icon'] = 'paperclip'; } elseif ($menuitem['class'] == 'z-icon-es-import') { $menuitem['class'] = null; $menuitem['icon'] = 'download'; } elseif ($menuitem['class'] == 'z-icon-es-info') { $menuitem['class'] = null; $menuitem['icon'] = 'info'; } elseif ($menuitem['class'] == 'z-icon-es-locale') { $menuitem['class'] = null; $menuitem['icon'] = 'globe'; } elseif ($menuitem['class'] == 'z-icon-es-locked') { $menuitem['class'] = null; $menuitem['icon'] = 'lock'; } elseif ($menuitem['class'] == 'z-icon-es-log') { $menuitem['class'] = null; $menuitem['icon'] = 'archive'; } elseif ($menuitem['class'] == 'z-icon-es-mail') { $menuitem['class'] = null; $menuitem['icon'] = 'inbox'; } elseif ($menuitem['class'] == 'z-icon-es-new') { $menuitem['class'] = null; $menuitem['icon'] = 'file-o'; } elseif ($menuitem['class'] == 'z-icon-es-ok') { $menuitem['class'] = null; $menuitem['icon'] = 'check'; } elseif ($menuitem['class'] == 'z-icon-es-options') { $menuitem['class'] = null; $menuitem['icon'] = 'th-list'; } elseif ($menuitem['class'] == 'z-icon-es-preview') { $menuitem['class'] = null; $menuitem['icon'] = 'cog'; } elseif ($menuitem['class'] == 'z-icon-es-print') { $menuitem['class'] = null; $menuitem['icon'] = 'print'; } elseif ($menuitem['class'] == 'z-icon-es-profile') { $menuitem['class'] = null; $menuitem['icon'] = 'user'; } elseif ($menuitem['class'] == 'z-icon-es-regenerate') { $menuitem['class'] = null; $menuitem['icon'] = 'refresh'; } elseif ($menuitem['class'] == 'z-icon-es-remove') { $menuitem['class'] = null; $menuitem['icon'] = 'times'; } elseif ($menuitem['class'] == 'z-icon-es-save') { $menuitem['class'] = null; $menuitem['icon'] = 'floppy-o'; } elseif ($menuitem['class'] == 'z-icon-es-saveas') { $menuitem['class'] = null; $menuitem['icon'] = 'floppy-o'; } elseif ($menuitem['class'] == 'z-icon-es-search') { $menuitem['class'] = null; $menuitem['icon'] = 'search'; } elseif ($menuitem['class'] == 'z-icon-es-url') { $menuitem['class'] = null; $menuitem['icon'] = 'globe'; } elseif ($menuitem['class'] == 'z-icon-es-user') { $menuitem['class'] = null; $menuitem['icon'] = 'user'; } elseif ($menuitem['class'] == 'z-icon-es-view') { $menuitem['class'] = null; $menuitem['icon'] = 'eye'; } elseif ($menuitem['class'] == 'z-icon-es-warning') { $menuitem['class'] = null; $menuitem['icon'] = 'exclamation-triangle'; } elseif ($menuitem['class'] == 'z-icon-es-rss') { $menuitem['class'] = null; $menuitem['icon'] = 'rss-square'; } } $active = ''; if (!empty($menuitem['url']) && System::getBaseUrl() . $menuitem['url'] === System::getCurrentUrl()) { $active = 'active '; } $dropdown = ''; if (isset($menuitem['links'])) { $dropdown = 'dropdown'; } $html .= '<li'; $html .= !empty($menuitem['id']) ? ' id="' . $menuitem['id'] . '"' : ''; $html .= ' class="' . $active . $dropdown; $html .= !empty($class) ? $class : ''; $html .= '">'; $attr = !empty($menuitem['title']) ? ' title="' . $menuitem['title'] . '"' : ''; $attr .= !empty($menuitem['class']) ? ' class="' . $menuitem['class'] . '"' : ''; if (isset($menuitem['disabled']) && $menuitem['disabled'] == true) { $html .= '<a ' . $attr . '>' . $menuitem['text'] . '</a>'; } elseif (!empty($menuitem['url'])) { $icon = ''; if (!empty($menuitem['icon'])) { $icon = '<span class="fa fa-' . $menuitem['icon'] . '"></span> '; } $html .= '<a href="' . DataUtil::formatForDisplay($menuitem['url']) . '"' . $attr . ' style="display: inline-block;">' . $icon . $menuitem['text'] . '</a>'; if (isset($menuitem['links'])) { $html .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="text-decoration: none;"> <b class="caret"></b></a>'; } } else { $html .= '<span' . $attr . '>' . $menuitem['text'] . '</span>'; } if (isset($menuitem['links'])) { $html .= '<ul class="dropdown-menu">'; foreach ($menuitem['links'] as $submenuitem) { $html .= '<li>'; if (isset($submenuitem['url'])) { $html .= '<a href="' . DataUtil::formatForDisplay($submenuitem['url']) . '">' . $submenuitem['text'] . '</a>'; } else { $html .= $submenuitem['text']; } $html .= '</li>'; } $html .= '</ul>'; } $html .= '</li>'; } $html .= '</ul>'; } if (isset($params['assign'])) { $view->assign($params['assign'], $html); } else { return $html; } }
/** * Display all blocks in a block position. * * @param string $side Block position to render. * @param boolean $echo Whether or not to echo output directly. * @param boolean $implode Whether or not to implode lines by \n. * * @return void|string The rendered output. */ public static function displayPosition($side, $echo = true, $implode = true) { static $blockplacements = array(); static $positions = array(); static $modname; static $currentlang; static $func; static $type; static $customargs; if (!isset($side)) { return null; } // get the block position if (empty($positions)) { $positions = ModUtil::apiFunc('ZikulaBlocksModule', 'user', 'getallpositions'); } if (!isset($positions[$side])) { return; } if (!isset($modname)) { if (PageUtil::isHomepage()) { $modname = '_homepage_'; } else { $modname = ModUtil::getName(); } } // get all block placements if (empty($blockplacements)) { $blockplacements = ModUtil::apiFunc('ZikulaBlocksModule', 'user', 'getallplacements'); } // get variables from input if (!isset($func)) { $func = FormUtil::getPassedValue('func', 'main', 'GETPOST'); } if (!isset($type)) { $type = FormUtil::getPassedValue('type', 'user', 'GETPOST'); } if (!isset($customargs)) { $customargs = array(); $filtervars = array('module', 'name', 'type', 'func', 'theme', 'csrftoken'); foreach ($_GET as $var => $value) { if (is_array($value)) { $arguments = explode('&', urldecode(http_build_query(array($var => $value)))); foreach ($arguments as $argument) { $args = explode('=', $argument); if (!in_array($args[0], $filtervars)) { $customargs[] = DataUtil::formatForOS(strip_tags($args[0])) . '=' . DataUtil::formatForOS(strip_tags($args[1])); } } } else { if (!in_array($var, $filtervars)) { $customargs[] = DataUtil::formatForOS(strip_tags($var)) . '=' . DataUtil::formatForOS(strip_tags($value)); } } } } // current language if (!isset($currentlang)) { $currentlang = ZLanguage::getLanguageCode(); } // loop around the blocks and display only the ones we need $blockoutput = array(); foreach ($blockplacements as $blockplacement) { // don't display a block if it's not in this block position if ($blockplacement['pid'] != $positions[$side]['pid']) { continue; } // get the full block info $blockinfo = self::getBlockInfo($blockplacement['bid']); // dont display the block if it's not active or not in matching langauge if (!$blockinfo['active'] || !empty($blockinfo['language']) && $blockinfo['language'] != $currentlang) { continue; } // block filtering if (!empty($blockinfo['filter']) && is_array($blockinfo['filter']) && count($blockinfo['filter'])) { $showblock = false; // loop for each filter foreach ($blockinfo['filter'] as $filter) { // filter must be an array of values if (!is_array($filter)) { continue; } $rule1 = $filter['module'] == $modname; $rule2 = empty($filter['ftype']) ? true : $filter['ftype'] == $type; $rule3 = empty($filter['fname']) ? true : $filter['fname'] == $func; if (empty($filter['fargs'])) { $rule4 = true; } else { $testargs = explode('&', $filter['fargs']); foreach ($testargs as $test) { $key = array_search($test, $customargs); if ($key === false) { $rule4 = false; break; } else { $rule4 = true; } } } if ($rule1 == true && $rule2 == true && $rule3 == true && $rule4 !== false) { $showblock = true; break; } } if (!$showblock) { continue; } } $blockinfo['position'] = $positions[$side]['name']; // get the module info and display the block $modinfo = ModUtil::getInfo($blockinfo['mid']); if ($echo) { echo self::show($modinfo['name'], $blockinfo['bkey'], $blockinfo); } else { $blockoutput[$blockinfo['bid']] = self::show($modinfo['name'], $blockinfo['bkey'], $blockinfo); } } if ($echo) { return; } else { if ($implode) { return implode("\n", $blockoutput); } else { return $blockoutput; } } }
/** * GetVar. * * Returns the value(s) of a page variable. In the case of * a mulit valued variable, this is an array containing all assigned * values. * * @param string $varname The name of the page variable. * @param mixed $default Default return value. * * @return mixed Contents of the variable */ public static function getVar($varname, $default = null) { global $_pageVars; if (System::isLegacyMode()) { $sm = ServiceUtil::getManager(); $metaTags = $sm->getParameter('zikula_view.metatags'); switch ($varname) { case 'description': return $metaTags['description']; break; case 'keywords': return $metaTags['keywords']; break; 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]) && isset($_pageVars[$varname]['contents'])) { if ($varname == 'title') { $title = System::getVar('pagetitle', ''); if (!empty($title) && $title != '%pagetitle%') { $title = str_replace('%pagetitle%', $_pageVars[$varname]['contents'], $title); $title = str_replace('%sitename%', System::getVar('sitename', ''), $title); $moduleInfo = ModUtil::getInfoFromName(ModUtil::getName()); $moduleDisplayName = $moduleInfo['displayname']; $title = str_replace('%modulename%', $moduleDisplayName, $title); return $title; } } return $_pageVars[$varname]['contents']; } elseif (isset($_pageVars[$varname]['default'])) { return $_pageVars[$varname]['default']; } return $default; }