/** * Smarty function to display a single inline user link of a specific policy for the Legal module. * * Example * {legalinlinelink policytype='termsofuse'} * * Tag Parameters: * policyType The unique string identifier of the policy typw whose inline link is to be returned; required. * target The target for the generated link, such as "_blank" to open the policy in a new window; optional, default is blank (same effect as "_self"). * assign The name of the template variable to which the output is assiged, if provided; optional, if not specified the output is sent to the template. * * Templates used: * legal_function_legalinlinelink_notfound.tpl * legal_function_legalinlinelink_legalnotice.tpl * legal_function_legalinlinelink_termsofuse.tpl * legal_function_legalinlinelink_privacypolicy.tpl * legal_function_legalinlinelink_tradeconditions.tpl * legal_function_legalinlinelink_cancellationrightpolicy.tpl * legal_function_legalinlinelink_accessibilitystatement.tpl * * Template Parameters Exported: * $target The target for the generated link, such as "_blank" to open the policy in a new window; optional, default is blank (same effect as "_self"). * (assign) If an assign tag parameter is specified, then a template variable a name equal to the value of the assign parameter is exported, containing the rendered output; optional, default is to return the output to the template. * * @param array $params All parameters passed to this function from the template. * @param Zikula_View &$view Reference to the Zikula view object, a subclass of Smarty. * * @return string The rendered template output for the specified policy type. */ function smarty_function_legalinlinelink($params, Zikula_View &$view) { if (!isset($params['policyType'])) { $template = 'plugins/legal_function_legalinlinelink_notfound.tpl'; } else { $params['policyType'] = strtolower($params['policyType']); $template = 'plugins/legal_function_legalinlinelink_' . $params['policyType'] . '.tpl'; if (!$view->template_exists($template)) { $template = 'plugins/legal_function_legalinlinelink_notfound.tpl'; } } $templateVars = array( 'target' => isset($params['target']) ? $params['target'] : '' ); $view->assign($templateVars); if (isset($params['assign']) && !empty($params['assign'])) { $view->assign($params['assign'], $view->fetch($template)); } else { return $view->fetch($template); } }
/** * Obtain the value of one block variable or all block variables for a specified block. * * Note: If the name of the block variable is not set, then the assign parameter * must be set since an array of block variables will be returned. * * Available attributes: * - bid (numeric) The block id * - name (string) The name of the block variable to get, otherwise the * entire block array is assigned is returned. * (required, if the assign attribute is not specified, * otherwise, optional) * - assign (string) The name of the template variable to which the value * is assigned, instead of being output to the template. * (optional if the name attribute is set, otherwise * required) * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return mixed the value of the block variable specified by the name attribute, * or an array containing the full block information. */ function smarty_function_blockgetinfo($params, Zikula_View $view) { $bid = isset($params['bid']) ? (int) $params['bid'] : 0; $name = isset($params['name']) ? $params['name'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$bid) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockgetinfo', 'bid'))); } // get the block info array $blockinfo = BlockUtil::getBlockInfo($bid); if ($name) { if ($assign) { $view->assign($assign, $blockinfo[$name]); } else { return $blockinfo[$name]; } } else { // handle the full blockinfo array if ($assign) { $view->assign($assign, $blockinfo); } else { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified to get the full block information.', array('pnblockgetinfo', 'assign'))); } } return; }
/** * Pop a field of an array and assign its value to a template variable. * * Available attributes: * - array (string) Name of the template array variable to process * - field (string) Name of the array field to assign then unset * - unset (bool) Flag to specify if the field must be unset or not (default: true) * - assign (string) Name of the assign variable to setup (optional) * * Example: * * Having an $objarray in our template, we want to process its fields in different * sections of the template, so we get the needed fields separately on the desired positions, * clearing the array in the process. * * For instance, the $hooks array resulted of notify the 'display_view' hooks, can be * processed individually using this plugin: * * <samp>{array_pop array='hooks' field='EZComments'}</samp> * <samp>{array_pop array='hooks' field='EZComments' assign='comments'}</samp> * * And display later the remaining ones with a foreach. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return mixed False on failure, void if the value is assigned, or the value extracted itself. */ function smarty_function_array_pop($params, Zikula_View $view) { if (!isset($params['array']) || !$params['array']) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'var'))); return false; } if (!isset($params['field']) || !$params['field']) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'value'))); return false; } $unset = isset($params['unset']) ? (bool) $params['unset'] : true; $value = null; $array = $view->getTplVar($params['array']); if ($array && isset($array[$params['field']])) { $value = $array[$params['field']]; if ($unset) { unset($array[$params['field']]); } $view->assign($params['array'], $array); } if (isset($params['assign']) && $params['assign']) { $view->assign($params['assign'], $value); } else { return $value; } }
/** * Zikula_View function to load Zikula_tree. * * Example: * {tree $menuArray=$your_content imagesDir='yout/path/to/images/'} * * @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 results of the module function */ function smarty_function_tree($params, Zikula_View $view) { $menuString = isset($params['menustring']) ? $params['menustring'] : null; $menuArray = isset($params['menuarray']) ? $params['menuarray'] : null; $treeArray = isset($params['treearray']) ? $params['treearray'] : null; $config = isset($params['config']) ? $params['config'] : array(); if (!isset($menuString) && !isset($menuArray) && !isset($treeArray)) { $view->trigger_error(__f('Error! in %1$s: %2$s, %3$s or %4$s parameter must be specified.', array('smarty_function_tree', 'menustring', 'menuarray', 'treearray'))); return false; } unset($params['menustring']); unset($params['menuarray']); unset($params['treearray']); unset($params['config']); $config = array_merge($config, (array) $params); $tree = new Zikula_Tree($config); if (isset($treeArray)) { $tree->setTreeData($treeArray); } elseif (isset($menuArray)) { $tree->loadArrayData($menuArray); } else { $tree->loadStringData($menuString); } if (isset($params['assign'])) { $view->assign($params['assign'], $tree->getHTML()); } else { return $tree->getHTML(); } }
/** * Zikula_View function to check for the availability of a module * * This function calls ModUtil::isHooked to determine if two Zikula modules are * hooked together. True is returned if the modules are hooked, false otherwise. * The result can also be assigned to a template variable. * * Available parameters: * - tmodname: The well-known name of the hook module * - smodname: The well-known name of the calling module * - assign: The name of a variable to which the results are assigned * * Examples * {modishooked tmodname='Ratings' smodname='News'} * * {modishooked tmodname='bar' smodname='foo' assign='barishookedtofoo'} * {if $barishookedtofoo}.....{/if} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.modishooked.php::smarty_function_modishooked() * * @return boolean True if the module is available; false otherwise. */ function smarty_function_modishooked($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('modishooked')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $smodname = isset($params['smodname']) ? $params['smodname'] : null; $tmodname = isset($params['tmodname']) ? $params['tmodname'] : null; if (!$tmodname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modishooked', 'tmodname'))); return false; } if (!$smodname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modishooked', 'smodname'))); return false; } $result = ModUtil::isHooked($tmodname, $smodname); if ($assign) { $view->assign($params['assign'], $result); } else { return $result; } }
/** * Obtain and display a configuration variable from the Zikula system. * * Available attributes: * - name (string) The name of the configuration variable to obtain * - html (bool) If set, the output is prepared for display by * DataUtil::formatForDisplayHTML instead of * DataUtil::formatForDisplay * - assign (string) the name of a template variable to assign the * output to, instead of returning it to the template. (optional) * * <i>Note that if the the result is assigned to a template variable, it is not * prepared for display by either DataUtil::formatForDisplayHTML or * DataUtil::formatForDisplay. If it is to be displayed, the safetext * modifier should be used.</i> * * Examples: * * <samp><p>Welcome to {configgetvar name='sitename'}!</p></samp> * * <samp>{configgetvar name='sitename' assign='thename'}</samp><br> * <samp><p>Welcome to {$thename|safetext}!</p></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 mixed The value of the configuration variable. */ function smarty_function_configgetvar($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('configgetvar')), E_USER_DEPRECATED); $name = isset($params['name']) ? $params['name'] : null; $default = isset($params['default']) ? $params['default'] : null; $html = isset($params['html']) ? $params['html'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$name) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('configgetvar', 'name'))); return false; } $result = System::getVar($name, $default); if ($assign) { $view->assign($assign, $result); } else { if (is_bool($html) && $html) { return DataUtil::formatForDisplayHTML($result); } else { return DataUtil::formatForDisplay($result); } } }
/** * User category selector. * * Available parameters: * - btnText: If set, the results are assigned to the corresponding variable instead of printed out * - cid: category ID * * Example * {selector_user_category cid="1" assign="category"} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string HTML code of the selector. */ function smarty_function_selector_user_category($params, Zikula_View $view) { $field = isset($params['field']) ? $params['field'] : 'id'; $selectedValue = isset($params['selectedValue']) ? $params['selectedValue'] : 0; $defaultValue = isset($params['defaultValue']) ? $params['defaultValue'] : 0; $defaultText = isset($params['defaultText']) ? $params['defaultText'] : ''; $lang = isset($params['lang']) ? $params['lang'] : ZLanguage::getLanguageCode(); $name = isset($params['name']) ? $params['name'] : 'defautlselectorname'; $recurse = isset($params['recurse']) ? $params['recurse'] : true; $relative = isset($params['relative']) ? $params['relative'] : true; $includeRoot = isset($params['includeRoot']) ? $params['includeRoot'] : false; $includeLeaf = isset($params['includeLeaf']) ? $params['includeLeaf'] : true; $all = isset($params['all']) ? $params['all'] : false; $displayPath = isset($params['displayPath']) ? $params['displayPath'] : false; $attributes = isset($params['attributes']) ? $params['attributes'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; $editLink = isset($params['editLink']) ? $params['editLink'] : true; $submit = isset($params['submit']) ? $params['submit'] : false; $multipleSize = isset($params['multipleSize']) ? $params['multipleSize'] : 1; $doReplaceRootCat = false; $userCats = ModUtil::apiFunc('ZikulaCategoriesModule', 'user', 'getusercategories', array('returnCategory' => 1, 'relative' => $relative)); $html = CategoryUtil::getSelector_Categories($userCats, $field, $selectedValue, $name, $defaultValue, $defaultText, $submit, $displayPath, $doReplaceRootCat, $multipleSize); if ($editLink && $allowUserEdit && UserUtil::isLoggedIn() && SecurityUtil::checkPermission('ZikulaCategoriesModule::', "{$category['id']}::", ACCESS_EDIT)) { $url = ModUtil::url('ZikulaCategoriesModule', 'user', 'edituser'); $html .= " <a href=\"{$url}\">" . __('Edit sub-categories') . '</a>'; } if ($assign) { $view->assign($assign, $html); } else { return $html; } }
/** * Zikula_View function notify display hooks. * * This function notify display hooks. * * Available parameters: * - 'eventname' The name of the hook event [required]. * - 'id' The ID if the subject. * - 'urlobject' Zikula_ModUrl instance or null. * - 'assign' If set, the results array is assigned to the named variable instead display [optional]. * - all remaining parameters are passed to the hook via the args param in the event. * * Example: * {notifydisplayhooks eventname='news.ui_hooks.item.display_view' id=$id urlobject=$urlObject} * {notifydisplayhooks eventname='news.ui_hooks.item.display_view' id=$id urlobject=$urlObject assign='displayhooks'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see smarty_function_notifydisplayhooks() * * @return void The results must be assigned to variable in assigned. */ function smarty_function_notifydisplayhooks($params, Zikula_View $view) { if (!isset($params['eventname'])) { return trigger_error(__f('Error! "%1$s" must be set in %2$s', array('eventname', 'notifydisplayhooks'))); } $eventname = $params['eventname']; $id = isset($params['id']) ? $params['id'] : null; $urlObject = isset($params['urlobject']) ? $params['urlobject'] : null; if ($urlObject && !$urlObject instanceof Zikula_ModUrl) { return trigger_error(__f('Error! "%1$s" must be an instance of %2$s', array('urlobject', 'Zikula_ModUrl'))); } $assign = isset($params['assign']) ? $params['assign'] : false; // create event and notify $hook = new Zikula_DisplayHook($eventname, $id, $urlObject); $view->getServiceManager()->getService('zikula.hookmanager')->notify($hook); $responses = $hook->getResponses(); // assign results, this plugin does not return any display if ($assign) { $view->assign($assign, $responses); return; } $output = ''; foreach ($responses as $result) { $output .= "$result\n"; } return $output; }
/** * Zikula_View function to display a preview image from a theme * * Available parameters: * - name name of the theme to display the preview image for * - name if set, the id assigned to the image * - size if set, the size of the image to use from small, medium, large (optional: default 'medium') * - assign if set, the title will be assigned to this variable * * Example * {previewimage name=andreas08 size=large} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.title.php::smarty_function_previewimage() * * @return string The markup to display the theme image. */ function smarty_function_previewimage($params, Zikula_View $view) { if (!isset($params['name'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('previewimage', 'name'))); return false; } if (!isset($params['size']) || !in_array($params['size'], array('large', 'medium', 'small'))) { $params['size'] = 'medium'; } $idstring = ''; if (isset($params['id'])) { $idstring = " id=\"{$params['id']}\""; } $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($params['name'])); $theme = ThemeUtil::getTheme($themeinfo['name']); $themePath = null === $theme ? "themes/{$themeinfo['directory']}/images" : $theme->getRelativePath() . '/Resources/public/images'; if (file_exists("{$themePath}/preview_{$params['size']}.png")) { $filesrc = "{$themePath}/preview_{$params['size']}.png"; } else { $filesrc = "system/ThemeModule/Resources/public/images/preview_{$params['size']}.png"; } $markup = "<img{$idstring} src=\"{$filesrc}\" alt=\"\" />"; if (isset($params['assign'])) { $view->assign($params['assign'], $markup); } else { return $markup; } }
/** * Smarty function to return first image src from given HTML content. * * Examples * {getImage htmlcontent=$item.body} * {getImage htmlcontent=$item.body putbaseurl=true} * {getImage htmlcontent=$item.body putbaseurl=true assign='imagesrc'} * * @return string */ function smarty_function_getImage($params, Zikula_View $view) { $result = $params['htmlcontent']; if (isset($params['htmlcontent']) && $params['htmlcontent']) { if (strpos($params['htmlcontent'], '<img ') === false) { // image is not found in content } else { // get image src $posstart = strpos($params['htmlcontent'], ' src="', $posstart) + 6; $posend = strpos($params['htmlcontent'], '"', $posstart); $result = substr($params['htmlcontent'], $posstart, $posend - $posstart); if (isset($params['putbaseurl']) && $params['putbaseurl']) { // put base url, if not if (substr($result, 0, 7) != 'http://' || substr($result, 0, 8) != 'https://') { $result = System::getBaseUrl() . ltrim($result, DIRECTORY_SEPARATOR); } } } } if (isset($params['assign'])) { $view->assign($params['assign'], $result); } else { return $result; } }
/** * Check if an array element (subscript) is set. * * Available attributes: * - array (array) an array template variable * - field (string) the value of a key in the array specified above * - returnValue (bool|int) if set, then the contents of the array element * $array[$field] is returned if it is set, otherwise false is returned * - assign (string) (optional) if provided, a template variable with * the specified name is set with the return value, * instead of returning the value to the template * * Examples: * * Return true to the template if the template variable $myarray['arraykey'] * is set, otherwise return false to the template: * * <samp>{array_field_isset array=$myarray field='arraykey'}</samp> * * Return the value of the template variable $myarray['arraykey'] to the * template if it is set, otherwise return false to the template: * * <samp>{array_field_isset array=$myarray field='arraykey' returnValue=1}</samp> * * Assign true to the template variable $myValue if the template variable * $myarray['arraykey'] is set, otherwise set $myValue to false: * * <samp>{array_field_isset array=$myarray field='arraykey' assign='myValue'}</samp> * * Assign the value of the template variable $myarray['arraykey'] to the * template variable $myValue if it is set, otherwise assign false to $myValue: * * <samp>{array_field_isset array=$myarray field='arraykey' returnValue=1 assign='myValue'}</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 boolean|mixed if returnValue is not set, then returns true if the array * element is set, otherwise false; if returnValue is set, * then returns the value of the array element if it is set, * otherwise false. */ function smarty_function_array_field_isset($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('array_field_isset returnValue=1 ...', 'array_field ...')), E_USER_DEPRECATED); $array = isset($params['array']) ? $params['array'] : null; $field = isset($params['field']) ? $params['field'] : null; $returnValue = isset($params['returnValue']) ? $params['returnValue'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if ($array === null) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('array_field_isset', 'array'))); return false; } if ($field === null) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('array_field_isset', 'field'))); return false; } $result = isset($array[$field]); if ($result && $returnValue) { $result = $array[$field]; } if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function return and unset an array field if set. * * Available attributes: * - array (string) The name of an array template variable * - field (string) The name of an array key in the array template variable above * - unset (bool|int) If true, the array element will be unset, if false the * \ array element will remain unchanged * - assign (string) The name of a template variable that the value of * $array['field'] will be assigned to * * Examples: * * Assign the value of the template variable $myarray['arraykey'] to the * template variable $myValue if it is set, otherwise assign false to $myValue. * The template variable $myarray['arraykey'] is NOT unset: * * <samp>{array_field_pop array='myarray' field='arraykey' assign='myValue'}</samp> * * Assign the value of the template variable $myarray['arraykey'] to the * template variable $myValue if it is set, otherwise assign false to $myValue. * The template variable $myarray['arraykey'] IS unset: * * <samp>{array_field_pop array='myarray' field='arraykey' unset=1 assign='myValue'}</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 null The value of the specified array element is return * in the specified template variable if it is set, * otherwise the template variable is set to false; no output to the template. */ function smarty_function_array_field_pop($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('array_field_pop', 'array_pop')), E_USER_DEPRECATED); $array = isset($view->_tpl_vars[$params['array']]); $field = isset($params['field']) ? $params['field'] : null; $unset = isset($params['unset']) ? $params['unset'] : false; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$array) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('array_field_pop', 'array'))); return false; } if (!is_array($view->_tpl_vars[$params['array']])) { $view->trigger_error(__f('Non-array passed to %s.', 'array_field_pop')); return false; } if ($field === null) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('array_field_pop', 'field'))); return false; } $result = false; if (isset($view->_tpl_vars[$params['array']][$field])) { $result = $view->_tpl_vars[$params['array']][$field]; if ($unset) { unset($view->_tpl_vars[$params['array']][$field]); } } if ($assign) { $view->assign($assign, $result); } else { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified to get the required field.', array('array_field_pop', 'assign'))); return false; } }
/** * 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 to execute a PHP callable. * * This plugin can call any PHP callable using x_class + x_method OR x_function * with a list of argument/value pairs. * * * Available parameters: * - x_class: The well-known name of a module to execute a function from (required) * - x_method: The type of function to execute; currently one of 'user' or 'admin' (default is 'user') * - x_function: The name of the module function to execute (default is 'main') * - x_assign: If set, the results are assigned to the corresponding variable instead of printed out * - all remaining parameters are passed to the callable. * * Based on call_user_func_array() * * Example * {callfunc x_class='Foo' x_method='Bar' name='Jane'} * {callfunc x_method='Something' age=21 name='Jane'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return mixed The results of the callable. */ function smarty_function_callfunc($params, Zikula_View $view) { $assign = (isset($params['x_assign']) && !empty($params['x_assign'])) ? $params['x_assign'] : ''; if (array_key_exists('x_class', $params)) { $class = $params['x_class']; $method = $params['x_method']; } else if (array_key_exists('x_function', $params)) { $function = $params['x_function']; } else { $view->trigger_error(__f('Error! in %1$s: the "class" and "method" parameter must be specified together or just "function" by itself.', array('calluserfunc', 'modname'))); } $callable = (isset($class)) ? array($class, $method) : $function; unset($params['x_class']); unset($params['x_method']); unset($params['x_function']); unset($params['x_assign']); $result = call_user_func_array($callable, $params); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function to to execute a module API function * * This function calls a calls a specific module API function. It returns whatever the return * value of the resultant function is if it succeeds. * Note that in contrast to the API function ModUtil::apiFunc you need not to load the * module API with ModUtil::loadApi. * * * Available parameters: * - modname: The well-known name of a module to execute a function from (required) * - type: The type of function to execute; currently one of 'user' or 'admin' (default is 'user') * - func: The name of the module function to execute (default is 'main') * - assign: The name of a variable to which the results are assigned * - all remaining parameters are passed to the module API function * * Examples * {modapifunc modname='News' type='user' func='get' sid='3'} * * {modapifunc modname='foobar' type='user' func='getfoo' id='1' assign='myfoo'} * {$myfoo.title} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.modfunc.php::smarty_function_modfunc() * * @return string The results of the module API function. */ function smarty_function_modapifunc($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $func = isset($params['func']) && $params['func'] ? $params['func'] : 'main'; $modname = isset($params['modname']) ? $params['modname'] : null; $type = isset($params['type']) && $params['type'] ? $params['type'] : 'user'; // avoid passing these to ModUtil::apiFunc unset($params['modname']); unset($params['type']); unset($params['func']); unset($params['assign']); if (!$modname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modapifunc', 'modname'))); return false; } if (isset($params['modnamefunc'])) { $params['modname'] = $params['modnamefunc']; unset($params['modnamefunc']); } $result = ModUtil::apiFunc($modname, $type, $func, $params); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function notify display hooks. * * This function notify display hooks. * * Available parameters: * - 'eventname' The name of the hook event [required]. * - 'id' The ID if the subject. * - 'urlobject' Zikula_ModUrl instance or null. * - 'assign' If set, the results array is assigned to the named variable instead display [optional]. * - all remaining parameters are passed to the hook via the args param in the event. * * Example: * {notifydisplayhooks eventname='news.ui_hooks.item.display_view' id=$id urlobject=$urlObject} * {notifydisplayhooks eventname='news.ui_hooks.item.display_view' id=$id urlobject=$urlObject assign='displayhooks'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see smarty_function_notifydisplayhooks() * * @return string|void if the results are assigned to variable in assigned. */ function smarty_function_notifydisplayhooks($params, Zikula_View $view) { if (!isset($params['eventname'])) { return trigger_error(__f('Error! "%1$s" must be set in %2$s', array('eventname', 'notifydisplayhooks'))); } $eventname = $params['eventname']; $id = isset($params['id']) ? $params['id'] : null; $urlObject = isset($params['urlobject']) ? $params['urlobject'] : null; if ($urlObject && !$urlObject instanceof \Zikula\Core\UrlInterface) { return trigger_error(__f('Error! "%1$s" must be an instance of %2$s', array('urlobject', '\\Zikula\\Core\\UrlInterface'))); } $assign = isset($params['assign']) ? $params['assign'] : false; // create event and notify $hook = new Zikula_DisplayHook($eventname, $id, $urlObject); // @todo Zikula_DisplayHook maintains BC. IN 1.5.0 change to \Zikula\Core\Hook\DisplayHook($id, $urlObject); $view->getContainer()->get('hook_dispatcher')->dispatch($eventname, $hook); $responses = $hook->getResponses(); // assign results, this plugin does not return any display if ($assign) { $view->assign($assign, $responses); return null; } $output = ''; foreach ($responses as $result) { $output .= "<div class=\"z-displayhook\">{$result}</div>\n"; } return $output; }
/** * Zikula_View function to get module variable * * This function obtains a module-specific variable from the Zikula system. * * Note that the results should be handled by the safetext or the safehtml * modifier before being displayed. * * * Available parameters: * - module: The well-known name of a module from which to obtain the variable * - name: The name of the module variable to obtain * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - html: If true then result will be treated as html content * - default: The default value to return if the config variable is not set * * Example * {modgetvar module='Example' name='foobar' assign='foobarOfExample'} * * @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_modgetvar($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $default = isset($params['default']) ? $params['default'] : null; $module = isset($params['module']) ? $params['module'] : null; $html = isset($params['html']) ? (bool) $params['html'] : false; $name = isset($params['name']) ? $params['name'] : null; if (!$module) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modgetvar', 'module'))); return false; } if (!$name && !$assign) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modgetvar', 'name'))); return false; } if (!$name) { $result = ModUtil::getVar($module); } else { $result = ModUtil::getVar($module, $name, $default); } if ($assign) { $view->assign($assign, $result); } else { if ($html) { return DataUtil::formatForDisplayHTML($result); } else { return DataUtil::formatForDisplay($result); } } }
/** * Renders and displays a single Zikula block by blockinfo array or block id. * * Available attributes: * - module (string) The internal name of the module that defines the block. * - blockname (string) The internal name of the block. * - block (int|array) Either the integer block id (bid) of the block, or * an array containing the blockinfo for the block. * - position (string) The position of the block. * - assign (string) If set, the results are assigned to the corresponding * template variable instead of being returned to the template (optional) * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return string The rendered output of the specified block. */ function smarty_function_blockshow($params, Zikula_View $view) { $module = isset($params['module']) ? $params['module'] : null; $blockname = isset($params['blockname']) ? $params['blockname'] : null; $block = isset($params['block']) ? $params['block'] : null; $position = isset($params['position']) ? $params['position'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$module) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'module'))); return; } if (!$blockname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'blockname'))); return; } if (!$block) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'id/info'))); return; } if (!$position) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'position'))); return; } if (!is_array($block)) { $block = BlockUtil::getBlockInfo($block); } $block['position'] = $position; $output = BlockUtil::show($module, $blockname, $block); if ($assign) { $view->assign($assign, $output); } else { return $output; } }
/** * Assign a template variable with the value found in an array element at the specified key. * * Available attributes: * - array (array) The array template variable in which to retrieve the value * - key (string|int) The key into the specified array where the value is to be retrieved from * - assign (string) The name of the template variable to assign the value to (required) * * Examples: * * Assign the template variable $myVar with the value found in the template * variable $myArray['myKey']: * * <samp>{assign_arrayval array=$myArray key='myKey' assign='myVar'}</samp> * * Assign the template variable $myVar with the value found in the template * variable $myArray[3]: * * <samp>{assign_arrayval array=$myArray key=3 assign='myVar'}</samp> * * In the following example, assume the template variable $myArray[4] is not * set (isset would return false). In this case $myVar is set to null: * * <samp>{assign_arrayval array=$myArray key=4 assign='myVar'}</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_assign_arrayval($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('assign_arrayval key="X" ...', 'array_field field="X" ...')), E_USER_DEPRECATED); $array = isset($params['array']) ? $params['array'] : array(); $key = isset($params['key']) ? $params['key'] : ''; $assign = isset($params['assign']) ? $params['assign'] : $key; $val = isset($array[$key]) ? $array[$key] : null; $view->assign($assign, $val); }
/** * Retrieve and display the site's charset. * * Available attributes: * - assign (string) the name of a template variable to assign the * output to, instead of returning it to the template. (optional) * * Example: * * <samp><meta http-equiv="Content-Type" content="text/html; charset={charset}"></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 string The value of the charset. */ function smarty_function_charset($params, Zikula_View $view) { $return = ZLanguage::getEncoding(); if (isset($params['assign'])) { $view->assign($params['assign'], $return); } else { return $return; } }
/** * Get validation errors. * * Available parameters: * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - field: The name of the field for which we wish to get the erorr * - indent: Wether or not to indent the validation error * * @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_function_formutil_getvalidationerror($params, Zikula_View $view) { $error = FormUtil::getValidationError($params['objectType'], $params['field']); if (isset($params['assign'])) { $view->assign($params['assign'], $error); } else { return $error; } }
/** * Zikula_View function to get the meta keywords * * This function will take the contents of the page and transfer it * into a keyword list. If stopwords are defined, they are filtered out. * The keywords are sorted by count. * As a default, the whole page contents are taken as a base for keyword * generation. If set, the contents of "contents" are taken. * Beware that the function always returns the site keywords if "generate * meta keywords" is turned off. * * available parameters: * - contents if set, this wil be taken as a base for the keywords * - dynamic if set, the keywords will be created from the content / mainconent * oterwise we use the page vars. The rules are: * 1) If dynamic keywords disabled in admin settings then use static keywords * 2) if parameter "dynamic" not set or empty then always use main content (default), * 3) if parameter "dynamic" set and not empty then use page vars if any set - otherwise use content. * - assign if set, the keywords will be assigned to this variable * * Example * <meta name="KEYWORDS" content="{keywords}"> * * @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 keywords. */ function smarty_function_keywords($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('keywords')), E_USER_DEPRECATED); $metatags = $view->getServiceManager()->getArgument('zikula_view.metatags'); if (isset($params['assign'])) { $view->assign($params['assign'], $metatags['keywords']); } else { return $metatags['keywords']; } }
/** * Zikula_View function to determine whether the current user is logged in. * * This function will return true if that is true and false otherwise * * available parameters: * - assign if set, the loggedin status will be assigned to this variable * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return bool the logged in status */ function smarty_function_userloggedin($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $return = UserUtil::isLoggedIn(); if ($assign) { $view->assign($assign, $return); } else { return $return; } }
/** * Zikula_View function to display the sitename * * Available parameters: * - assign if set, the title will be assigned to this variable * * Example * {sitename} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.sitename.php::smarty_function_sitename() * @return string The sitename. */ function smarty_function_sitename($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('sitename', '$modvars.ZConfig.sitename')), E_USER_DEPRECATED); $sitename = System::getVar('sitename'); if (isset($params['assign'])) { $view->assign($params['assign'], $sitename); } else { return $sitename; } }
/** * Zikula_View function to generate the title for the page * * Available parameters: * - assign if set, the title will be assigned to this variable * * Example * {title} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.title.php::smarty_function_title() * * @return string The title. */ function smarty_function_title($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('title', "pagegetvar name='title'")), E_USER_DEPRECATED); $title = PageUtil::getVar('title'); if (isset($params['assign'])) { $view->assign($params['assign'], $title); } else { return $title; } }
/** * Zikula_View function to the current users theme * * Available parameters: * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * @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 variables content. */ function smarty_function_usergettheme($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $result = UserUtil::getTheme(); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function to obtain base URL for this site * * This function obtains the base URL for the site. The base url is defined as the * full URL for the site minus any file information i.e. everything before the * 'index.php' from your start page. * Unlike the API function System::getHost, the results of this function are already * sanitized to display, so it should not be passed to the DataUtil::formatForDisplay modifier. * * Available parameters: * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Example * {gethost} * * @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 base URL of the site. */ function smarty_function_gethost($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $result = htmlspecialchars(System::getHost()); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * 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; } }
/** * Concatenate several values together and assign the resultant string to a template variable. * * Available attributes: * - 1..10 (string) The 1st through 10th value(s) we wish to assign * - name (string) The name of the template variable to which the * concatenated string will be assigned * - html (bool) (optional) If the specified value(s) contain HTML, * this should be set to true (or 1) * * Examples: * * Concatenate the template variables $myVar1, $myVar2 and $myVar2 and store * the resultant string in the template variable $myString: * * <samp>{assign_concat name='myString' 1=$myVar1 2=$myVar2 3=$myVar3}</samp> * * Concatenate the template variables $myVar1, $myVar2 and $myVar2 and store * the resultant string in the template variable $myString. The string contains * HTML, therefore it is passed through DataUtil::formatForDisplayHTML: * * <samp>{assign_concat name='myString' 1=$myVar1 2=$myVar2 3=$myVar3 html=true}</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_assign_concat($params, Zikula_View $view) { if (!isset($params['name']) || !$params['name']) { $view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('name', 'assign_concat'))); return false; } $txt = ''; $i = 1; if (isset($params[$i])) { do { $txt .= "{$params[$i]}"; $i++; } while (isset($params[$i])); } if (isset($params['html']) && $params['html']) { $view->assign($params['name'], DataUtil::formatForDisplayHTML($txt)); } else { $view->assign($params['name'], $txt); } }
/** * Zikula_View function to obtain base URL for this site * * This function obtains the base URL for the site. The base url is defined as the * full URL for the site minus any file information i.e. everything before the * 'index.php' from your start page. * Unlike the API function System::getBaseUrl, the results of this function are already * sanitized to display, so it should not be passed to the safetext modifier. * * Available parameters: * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Example * {getbaseurl} * * @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 base URL of the site. */ function smarty_function_getbaseurl($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('getbaseurl', '$baseurl')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $result = htmlspecialchars(System::getBaseUrl()); if ($assign) { $view->assign($assign, $result); } else { return $result; } }