/** * 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 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); } } }
/** * Zikula_View function to display a drop down list of module stylesheets. * * Available parameters: * - modname The module name to show the styles for * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - id: ID for the control * - name: Name for the control * - exclude Comma seperated list of files to exclude (optional) * - selected: Selected value * * @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 value of the last status message posted, or void if no status message exists. */ function smarty_function_html_select_modulestylesheets($params, Zikula_View $view) { if (!isset($params['modname'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('html_select_modulestylesheets', 'modname'))); return false; } if (isset($params['exclude'])) { $exclude = explode(',', trim($params['exclude'])); unset($params['exclude']); } else { $exclude = array(); } $params['values'] = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodstyles', array('modname' => $params['modname'], 'exclude' => $exclude)); unset($params['modname']); $params['output'] = $params['values']; $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['assign']); require_once $view->_get_plugin_filepath('function', 'html_options'); $output = smarty_function_html_options($params, $view); if (!empty($assign)) { $view->assign($assign, $output); } else { return $output; } }
/** * 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 switch block. * * Available attributes: * - expr (string|numeric) The variable to be tested against each of the * {@link smarty_block_case() case} expressions. * * Example: * <pre> * {switch expr=$var} * {case expr='1'} * do some stuff for case $var == '1' * {/case} * {case expr='2'} * do some stuff for case $var == '2' * {/case} * {case} * default stuff * {/case} * {/switch} * </pre>. * * @param array $params All attributes passed to this function from the template. * @param string $content The content between the block tags. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * @param mixed &$pages Pages?. * * @see smarty_block_case. * * @todo Document the &$pages parameter, or correct it (possibly &$repeat?). * * @return string The content of the matching case. */ function smarty_block_switch($params, $content, Zikula_View $view, &$pages) { if (is_null($content) && !array_key_exists('expr', $params)) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_block_switch', 'expr'))); } return $content; }
/** * 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; } }
/** * 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; } }
/** * Zikula_View function to display a drop down list of languages * * Available parameters: * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - name: Name for the control * - id: ID for the control * - selected: Selected value * - installed: if set only show languages existing in languages folder * - all: show dummy entry '_ALL' on top of the list with empty value * * Example * {html_select_languages name=language selected=en} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @deprecated smarty_function_html_select_locales() * @return string The value of the last status message posted, or void if no status message exists. */ function smarty_function_html_select_languages($params, Zikula_View $view) { if (!isset($params['name']) || empty($params['name'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('html_select_languages', 'name'))); return false; } require_once $view->_get_plugin_filepath('function', 'html_options'); $params['output'] = array(); $params['values'] = array(); if (isset($params['all']) && $params['all']) { $params['values'][] = ''; $params['output'][] = DataUtil::formatForDisplay(__('All')); unset($params['all']); } if (isset($params['installed']) && $params['installed']) { $languagelist = ZLanguage::getInstalledLanguageNames(); unset($params['installed']); } else { $languagelist = ZLanguage::languageMap(); } $params['output'] = array_merge($params['output'], DataUtil::formatForDisplay(array_values($languagelist))); $params['values'] = array_merge($params['values'], DataUtil::formatForDisplay(array_keys($languagelist))); $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['assign']); $html_result = smarty_function_html_options($params, $view); if (!empty($assign)) { $view->assign($assign, $html_result); } else { return $html_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; } }
/** * 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); } } }
/** * 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; } }
/** * Available params: * - image (string) Path to source image (required) * - width (int) Thumbnail width in pixels (optional, default value based on 'default' preset) * - height (int) Thumbnail width in pixels (optional, default value based on 'default' preset) * - mode (string) Thumbnail mode; 'inset' or 'outset' (optional, default 'inset') * - extension (string) File extension for thumbnails: jpg, png, gif; null for original file type * (optional, default value based on 'default' preset) * - objectid (string) Unique signature for object, which owns this thumbnail (optional) * - preset (string|object) Name of preset defined in Imagine or custom preset passed as instance of * SystemPlugin_Imagine_Preset; if given inline options ('width', 'heigth', 'mode' * and 'extension') are ignored (optional) * - manager (object) Instance of SystemPlugin_Imagine_Manager; if given inline options ('width', * 'heigth', 'mode' and 'extension') are ignored (optional) * - fqurl (boolean) If set the thumb path is absolute, if not relative * - tag (boolean) If set to true - full <img> tag will be generated. Tag attributes should be * passed with "img_" prefix (for example: "img_class"). Getttext prefix may be * used for translations (for example: "__img_alt") * * Examples * * Basic usage with inline options: * {thumb image='path/to/image.png' width=100 height=100 mode='inset' extension='jpg'} * * Using preset define in Imagine plugin * {thumb image='path/to/image.png' objectid='123' preset='my_preset'} * * Using custom preset, defined in module and passed to template * {thumb image='path/to/image.png' objectid='123' preset=$preset} * * Using custom SystemPlugin_Imagine_Manager instance, defined in module and passed to template * {thumb image='path/to/image.png' objectid='123' manager=$manager} * * Generating full img tag * {thumb image='path/to/image.png' objectid='123' preset=$preset tag=true __img_alt='Alt text, gettext prefix may be used' img_class='image-class'} * This will generate: * <img src="thumb/path" widht="100" height="100" alt="Alt text, gettext prefix may be used" class="image-class" /> * * @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 thumb path */ function smarty_function_thumb($params, Zikula_View $view) { if (!isset($params['image']) || empty($params['image'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_thumb', 'image'))); return false; } $image = $params['image']; $objectId = isset($params['objectid']) ? $params['objectid'] : null; if (isset($params['manager']) && $params['manager'] instanceof SystemPlugin_Imagine_Manager) { $manager = $params['manager']; } else { $manager = $view->getServiceManager()->getService('systemplugin.imagine.manager'); } if (isset($params['preset']) && $params['preset'] instanceof SystemPlugin_Imagine_Preset) { $preset = $params['preset']; } elseif (isset($params['preset']) && $manager->getPlugin()->hasPreset($params['preset'])) { $preset = $manager->getPlugin()->getPreset($params['preset']); } else { $preset = array(); $preset['width'] = isset($params['width']) ? $params['width'] : null; $preset['height'] = isset($params['height']) ? $params['height'] : null; $preset['mode'] = isset($params['mode']) ? $params['mode'] : null; $preset['extension'] = isset($params['extension']) ? $params['extension'] : null; $preset = array_filter($preset); } $manager->setPreset($preset); $thumb = $manager->getThumb($image, $objectId); $basePath = (isset($params['fqurl']) && $params['fqurl']) ? System::getBaseUrl() : System::getBaseUri(); $result = "{$basePath}/{$thumb}"; if (isset($params['tag']) && $params['tag']) { $thumbSize = @getimagesize($thumb); $attributes = array(); $attributes[] = "src=\"{$basePath}/{$thumb}\""; $attributes[] = $thumbSize[3]; // width and height // get tag params foreach ($params as $key => $value) { if (strpos($key, 'img_') === 0) { $key = str_replace('img_', '', $key); $attributes[$key] = "{$key}=\"{$value}\""; } } if (!isset($attributes['alt'])) { $attributes[] = 'alt=""'; } $attributes = implode(' ', $attributes); $result = "<img {$attributes} />"; } if (isset($params['assign'])) { $view->assign($params['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 modifier to parse gettext string. * * Example * * {$var|gt:$zikula_view} * * @param string $string The contents to transform. * @param Zikula_View $view This Zikula_View object (available as $renderObject in templates). * * @return string The modified output. */ function smarty_modifier_gt($string, $view) { if (!$view instanceof Zikula_View) { return __('Error! With modifier_gt, you must use the following form for the gettext modifier (\'gt\'): $var|gt:$zikula_view'); } return __($string, $view->getDomain()); }
/** * 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(); } }
/** * 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; }
/** * Zikula_View function to display a drop down list of themes. * * Available parameters: * - name: Name for the control (optional) if not present then only the option tags are output * - id: ID for the control * - selected: Selected value * - filter: Filter themes use (possible values: ThemeUtil::FILTER_ALL (default) ThemeUtil::FILTER_USER, ThemeUtil::FILTER_SYSTEM, ThemeUtil::FILTER_ADMIN * - state: Filter themes by state (possible values: ThemeUtil::STATE_ALL (default), ThemeUtil::STATE_ACTIVE, ThemeUtil::STATE_INACTIVE * - type: Filter themes by type (possible values: ThemeUtil::TYPE_ALL (default), ThemeUtil::TYPE_XANTHIA3 * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Examples * * {html_select_themes name=mytheme selected=mythemechoice} * * <select name="mytheme"> * <option value="">{ml name=_DEFAULT}</option> * {html_select_themes selected=$mythemechoice} * </select> * * @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 value of the last status message posted, or void if no status message exists. */ function smarty_function_html_select_themes($params, Zikula_View $view) { if (!isset($params['filter']) || !defined($params['filter'])) { $filter = ThemeUtil::FILTER_ALL; } else { $filter = constant($params['filter']); } if (!isset($params['state']) || !defined($params['state'])) { $state = ThemeUtil::STATE_ALL; } else { $state = constant($params['state']); } if (!isset($params['type']) || !defined($params['type'])) { $type = ThemeUtil::TYPE_ALL; } else { $type = constant($params['type']); } $themelist = array(); $themes = ThemeUtil::getAllThemes($filter, $state, $type); if (!empty($themes)) { foreach ($themes as $theme) { $themelist[$theme['name']] = $theme['displayname']; } } natcasesort($themelist); require_once $view->_get_plugin_filepath('function', 'html_options'); $output = smarty_function_html_options(array('options' => $themelist, 'selected' => isset($params['selected']) ? $params['selected'] : null, 'name' => isset($params['name']) ? $params['name'] : null, 'id' => isset($params['id']) ? $params['id'] : null), $view); if (isset($params['assign'])) { $view->assign($params['assign'], $output); } else { return $output; } }
/** * Zikula_View function to use the _dgettext() function * * This function takes a identifier and returns the corresponding language constant. * * Available parameters: * - text: (required) string to translate * - tagN: (optional) replace for sprintf() e.g. %s or %1$s * - domain: (optional) textdomain to be used (not required, the system will fill this out automatically * - comment: (optional) comment to the translator (this is not processed by this code) * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Examples * {gettext}Hello world{/gettext} * {gettext tag1=$name}Hello %s{/gettext} * {gettext tag1=$city tag2=$country comment="%1 is a name %2 is the place"}Hello %1$s, welcome to %2$s{/gettext} * * String replacement follows the rules at http://php.net/sprintf but please note Smarty seems to pass * all variables as strings so %s and %n$s are mostly used. * * @param array $params All attributes passed to this function from the template. * @param string $content The block content. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string Translation if it was available. */ function smarty_block_gettext($params, $content, Zikula_View $view) { if ($content) { if (isset($params['domain'])) { $domain = strtolower($params['domain']) == 'zikula' ? null : $params['domain']; } else { $domain = $view->getDomain(); // default domain } // build array for tags (for %s, %1$s etc) if applicable ksort($params); $tags = array(); foreach ($params as $key => $value) { if (preg_match('#^tag([0-9]{1,2})$#', $key)) { $tags[] = $value; } } $tags = count($tags) == 0 ? null : $tags; // perform gettext $output = isset($tags) ? __f($content, $tags, $domain) : __($content, $domain); if (isset($params['assign'])) { $render->assign($params['assign'], $output); } else { return $output; } } }
/** * 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; } }
/** * 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 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; }
/** * 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; } }
/** * Smarty function to display the category menu for admin links. This also adds the * navtabs.css to the page vars array for stylesheets. * * Admin * {admincategorymenu} * * @see function.admincategorymenu.php::smarty_function_admincategorymenu() * @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_admincategorymenu($params, \Zikula_View $view) { PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('ZikulaAdminModule')); $modinfo = ModUtil::getInfoFromName($view->getTplVar('toplevelmodule')); $acid = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodcategory', array('mid' => $modinfo['id'])); $path = array('_controller' => 'ZikulaAdminModule:Admin:categorymenu', 'acid' => $acid); $subRequest = $view->getRequest()->duplicate(array(), null, $path); return $view->getContainer()->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST)->getContent(); }
/** * Template plugin to display timezone list. * * Example {timezoneselect selected='Timezone'}. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view The Zikula_View. * * @see function.timezoneselect.php::smarty_function_timezoneselect(). * * @return string The results of the module function. */ function smarty_function_timezoneselect($params, Zikula_View $view) { require_once $view->_get_plugin_filepath('function', 'html_options'); $timezones = DateUtil::getTimezones(); if (!isset($params['selected']) || empty($params['selected']) || !isset($timezones[$params['selected']])) { $params['selected'] = System::getVar('timezone_offset'); } return smarty_function_html_options(array('options' => $timezones, 'selected' => $params['selected'], 'print_result' => false), $view); }
/** * 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; } }
/** * 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); }
/** * Zikula_View function to create a zikula.orgpatible URL for a specific module function. * * This function returns a module URL string if successful. Unlike the API * function ModURL, this is already sanitized to display, so it should not be * passed to the safetext modifier. * * Available parameters: * - modname: The well-known name of a module for which to create the URL (required) * - type: The type of function for which to create the URL; currently one of 'user' or 'admin' (default is 'user') * - func: The actual module function for which to create the URL (default is 'main') * - fragment: The fragement to target within the URL * - ssl: See below * - fqurl: Make a fully qualified URL * - forcelongurl: Do not create a short URL (forced) * - forcelang (boolean|string) Force the inclusion of the $forcelang or default system language in the generated url * - append: (optional) A string to be appended to the URL * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - all remaining parameters are passed to the module function * * Example * Create a URL to the News 'view' function with parameters 'sid' set to 3 * <a href="{modurl modname='News' type='user' func='display' sid='3'}">Link</a> * * Example SSL * Create a secure https:// URL to the News 'view' function with parameters 'sid' set to 3 * ssl - set to constant null,true,false NOTE: $ssl = true not $ssl = 'true' null - leave the current status untouched, true - create a ssl url, false - create a non-ssl url * <a href="{modurl modname='News' type='user' func='display' sid='3' ssl=true}">Link</a> * * @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 URL. */ function smarty_function_modurl($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $append = isset($params['append']) ? $params['append'] : ''; $fragment = isset($params['fragment']) ? $params['fragment'] : null; $fqurl = isset($params['fqurl']) ? $params['fqurl'] : null; $forcelongurl = isset($params['forcelongurl']) ? (bool) $params['forcelongurl'] : false; if (isset($params['func']) && $params['func']) { $func = $params['func']; } else { if (System::isLegacyMode()) { $func = 'main'; LogUtil::log(__f('{modurl} - %1$s is a required argument, you must specify it explicitly in %2$s', array('func', $view->template)), E_USER_DEPRECATED); } else { $view->trigger_error(__f('{modurl} - %1$s is a required argument, you must specify it explicitly in %2$s', array('func', $view->template))); return false; } } if (isset($params['type']) && $params['type']) { $type = $params['type']; } else { if (System::isLegacyMode()) { $type = 'user'; LogUtil::log(__f('{modurl} - %1$s is a required argument, you must specify it explicitly in %2$s', array('type', $view->template)), E_USER_DEPRECATED); } else { $view->trigger_error(__f('{modurl} - %1$s is a required argument, you must specify it explicitly in %2$s', array('type', $view->template))); return false; } } $modname = isset($params['modname']) ? $params['modname'] : null; $ssl = isset($params['ssl']) ? (bool) $params['ssl'] : null; $forcelang = isset($params['forcelang']) && $params['forcelang'] ? $params['forcelang'] : false; // avoid passing these to ModUtil::url unset($params['modname']); unset($params['type']); unset($params['func']); unset($params['fragment']); unset($params['ssl']); unset($params['fqurl']); unset($params['assign']); unset($params['append']); unset($params['forcelang']); unset($params['forcelongurl']); if (!$modname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modurl', 'modname'))); return false; } $result = ModUtil::url($modname, $type, $func, $params, $ssl, $fragment, $fqurl, $forcelongurl, $forcelang); if ($append && is_string($append)) { $result .= $append; } if ($assign) { $view->assign($assign, $result); } else { return DataUtil::formatForDisplay($result); } }
/** * Display an core image form submission button using either the <button> or the <input> HTML element. * * This tag calls the img tag to determine the full path of the image * for the src attribute of the img element within the button element, or * for the src attribute of the input element. * * <i>BEWARE: Internt Explorer 6.x does NOT work especially well with <button> tags!</i> * * Available attributes: * - src (string) The file name of the image. The full path of the image * will be determined by the smarty_function_img function. * - set (string) The name of the image set from which to retrieve the * image file (the name of a subdirectory under /images/icons). * - mode (string) if set, the type of HTML element to be used (optional, * default: button). Values = [button|input] * - type (string) if set, the type of button that will be generated * (optional, default: submit, used only if mode is set to 'button') * - name (string) if set, the name of button that will be generated as * the name attribute on the button or input element * (optional, default: value of 'type' parameter) * - value (string) if set, the value that will be generated as the * value attribute on the button or input element (optional, * however should be set if mode is input) * - id (string) if set, the value of the id attribute on the button * or input element (optional) * - class (string) if set, the value of the class attribute on the * button or input element (optional) * - alt (string) if set, the value for the alt attribute. If mode is * 'button' then the alt attribute is generated for * the img element embedded in the button element. If * mode is 'input' then the alt attribute is generated * for the input element. (optional) * - title (string) if set, the value for the title attribute of the * button or input element. (optional) * - text (string) if set, the button tag surrounds this string * - assign (string) If set, the results are assigned to the corresponding * template variable instead of being returned to the template (optional) * * Examples: * * Display a submit button with button_ok.png (a green check mark) from the set of * small icons (/images/icons/small) with the <button ...> HTML element. * * <samp>{button src='button_ok.png' set='small'}</samp> * * Display a cancel button with button_cancel.png (a red 'X') from the set of * extra small icons (/images/icons/extrasmall) with the <button ...> HTML element. * * <samp>{button src='button_cancel.png' set='extrasmall' type='cancel'}</samp> * * Display a submit button with button_cancel.png (a red 'X') from the set of * medium icons (/images/icons/medium) and a value of * 'cancel' with the <input ...> HTML element. The id attribute of the input * element is set to 'cancelbutton'. * * <samp>{button src='button_cancel.png' set='medium' mode='input' value='cancel' id='cancelbutton'}</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 rendered <button ...><img ...></button> or <input ...> * element for the form button. */ function smarty_function_button($params, Zikula_View $view) { // we're going to make use of pnimg for path searching require_once $view->_get_plugin_filepath('function', 'img'); if (!isset($params['src'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_button', 'src'))); return false; } if (!isset($params['set'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_button', 'set'))); return false; } $type = isset($params['type']) ? $params['type'] : 'submit'; $mode = isset($params['mode']) ? $params['mode'] : 'button'; if (isset($params['name'])) { $name = ' name="' . DataUtil::formatForDisplay($params['name']) . '"'; } else { $name = ' name="' . DataUtil::formatForDisplay($type) . '"'; } if (isset($params['value'])) { $value = ' value="' . DataUtil::formatForDisplay($params['value']) . '"'; } else { $value = ''; } if (isset($params['id'])) { $id = ' id="' . DataUtil::formatForDisplay($params['id']) . '"'; } else { $id = ''; } if (isset($params['class'])) { $class = ' class="' . DataUtil::formatForDisplay($params['class']) . '"'; } else { $class = ''; } if (isset($params['text'])) { $text = ' ' . DataUtil::formatForDisplay($params['text']); } else { $text = ''; } $title = isset($params['title']) ? $params['title'] : ''; $alt = isset($params['alt']) ? $params['alt'] : ''; // call the pnimg plugin and work out the src from the assigned template vars smarty_function_img(array('assign' => 'buttonsrc', 'src' => $params['src'], 'set' => $params['set'], 'modname' => 'core'), $view); $imgvars = $view->get_template_vars('buttonsrc'); $imgsrc = $imgvars['src']; // form the button html if ($mode == 'button') { $return = '<button' . $id . $class . ' type="' . DataUtil::formatForDisplay($type) . '"' . $name . $value . ' title="' . DataUtil::formatForDisplay($title) . '"><img src="' . DataUtil::formatForDisplay($imgsrc) . '" alt="' . DataUtil::formatForDisplay($alt) . '" />' . $text . '</button>'; } else { $return = '<input' . $id . $class . ' type="image"' . $name . $value . ' title="' . DataUtil::formatForDisplay($title) . '" src="' . DataUtil::formatForDisplay($imgsrc) . '" alt="' . DataUtil::formatForDisplay($alt) . '" />'; } if (isset($params['assign'])) { $view->assign($params['assign'], $return); } else { return $return; } }