/** * 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; } }
/** * 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 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 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; }
/** * 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; } }
/** * 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 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 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 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); } }
/** * Retrieve an HTML unordered list of the categories assigned to a specified item. * * The assigned categories are retrieved from $item['__CATEGORIES__'] (DBUtil) or $item['Categories'] (Doctrine). * However, if we are using Doctrine 2, the categories are passed as param. * * Available attributes: * - item (array) The item from which to retrieve the assigned categories. * or * - categories (object) The item's categories. * - doctrine2 (boolean) true or false if using doctrine2 or not. * * Example: * * <samp>{assignedcategorieslist item=$myVar}</samp> * <samp>{assignedcategorieslist categories=$myCategories doctrine2=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 string The HTML code for an unordered list containing the item's * assigned categories. If no categories are assigned to the * item, then the list will contain a single list-item (<li>) * with a message to that effect. */ function smarty_function_assignedcategorieslist($params, Zikula_View $view) { if (isset($params['doctrine2']) && (bool) $params['doctrine2'] == true) { if (!isset($params['categories'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assignedcategorieslist', 'categories'))); return false; } } elseif (!isset($params['item'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assignedcategorieslist', 'item'))); return false; } $lang = ZLanguage::getLanguageCode(); $result = "<ul>\n"; if (isset($params['doctrine2']) && (bool) $params['doctrine2'] == true) { if (count($params['categories']) > 0) { foreach ($params['categories'] as $category) { $name = $category->getCategory()->getName(); $display_name = $category->getCategory()->getDisplayName(); $result .= "<li>\n"; if (isset($display_name[$lang]) && !empty($display_name[$lang])) { $result .= $display_name[$lang]; } elseif (isset($name) && !empty($name)) { $result .= $name; } $result .= "</li>\n"; } } else { $result .= '<li>' . DataUtil::formatForDisplay(__('No assigned categories.')) . '</li>'; } } else { if (isset($params['item']['Categories']) && !empty($params['item']['Categories'])) { $categories = $params['item']['Categories']; } elseif (isset($params['item']['__CATEGORIES__']) && !empty($params['item']['__CATEGORIES__'])) { $categories = $params['item']['__CATEGORIES__']; } else { $categories = array(); } if (!empty($categories)) { foreach ($categories as $property => $category) { if (isset($category['Category'])) { $category = $category['Category']; } $result .= "<li>\n"; if (isset($category['display_name'][$lang])) { $result .= $category['display_name'][$lang]; } elseif (isset($category['name'])) { $result .= $category['name']; } $result .= "</li>\n"; } } else { $result .= '<li>' . DataUtil::formatForDisplay(__('No assigned categories.')) . '</li>'; } } $result .= "</ul>\n"; return $result; }
/** * Assign a value caching its parameters if cache is enabled. * * Available attributes: * - var (string) The template variable to assign * - value (mixed) The value to assign * * Example: * * Having an $obj loaded from the DB, use assign_cache to cache some of its values, * and use it later safely, even inside a cached template: * * <samp>{assign_cache var='author' value=$obj.cr_uid}</samp> * * And use that cached value later in another plugin: * * <samp>{useravatar uid=$author}</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_cache($params, Zikula_View $view) { if (!isset($params['var'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'var'))); return false; } if (!isset($params['value'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'value'))); return false; } $view->assign($params['var'], $params['value']); return; }
/** * 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 * - plural: (optional) plural version of the string * - count: (optional) if we have plural we need to specify the count * - 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 * {gt text="Hello world"} * {gt text="Hello %s" tag1=$name} * {gt text="You want one cup" plural="You want two cups" count=2} * {gt text='Hello %1$s, welcome to %2$s' tag1=$city tag2=$country comment="%1 is a name %2 is the place"} * ## WARNING! When using %1$s in a template, smarty compiles this to PHP so the string must be in single quotes or * ## the $s will be evaluated as variable $s * * * 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 Zikula_View $view Reference to the Zikula_View object. * * @return string Translation if it was available. */ function smarty_function_gt($params, Zikula_View $view) { // the check order here is important because: // if we are calling from a theme both $view->themeDomain and $view->renderDomain are set. // if the call was from a template only $view->renderDomain is set. if (isset($params['domain'])) { $domain = (strtolower($params['domain']) == 'zikula' ? null : $params['domain']); } else { $domain = $view->getDomain(); // default domain } if (!isset($params['text'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_gt', 'text'))); return false; } $text = $params['text']; // validate plural settings if applicable if ((!isset($params['count']) && isset($params['plural'])) || (isset($params['count']) && !isset($params['plural']))) { $view->trigger_error(__('Error! If you use a plural or count in gettext, you must use both parameters together.')); return false; } $count = (isset($params['count']) ? (int)$params['count'] : 0); $plural = (isset($params['plural']) ? $params['plural'] : false); // 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 if ($plural) { $result = (isset($tags) ? _fn($text, $plural, $count, $tags, $domain) : _n($text, $plural, $count, $domain)); } else { $result = (isset($tags) ? __f($text, $tags, $domain) : __($text, $domain)); } // assign or return if (isset($params['assign'])) { $view->assign($params['assign'], $result); } else { return $result; } }
/** * Zikula_View function call hooks * * This function calls a specific module function. It returns whatever the return * value of the resultant function is if it succeeds. * Note that in contrast to the API function modcallhooks you need not to load the * module with ModUtil::load. * * * Available parameters: * - 'hookobject' the object the hook is called for - either 'item' or 'category' * - 'hookaction' the action the hook is called for - one of 'create', 'delete', 'transform', or 'display' * - 'hookid' the id of the object the hook is called for (module-specific) * - 'implode' Implode collapses all display hooks into a single string. * - 'assign' If set, the results are assigned to the corresponding variable instead of printed out * - all remaining parameters are passed to the ModUtil::callHooks API via the extrainfo array * * Example * {modcallhooks hookobject='item' hookaction='modify' hookid=$tid $modname='ThisModule' $objectid=$tid} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.modcallhooks.php::smarty_function_modcallhooks() * * @return string The results of the module function. */ function smarty_function_modcallhooks($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('modcallhooks', 'notifydisplayhooks')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $hookid = isset($params['hookid']) ? $params['hookid'] : ''; $hookaction = isset($params['hookaction']) ? $params['hookaction'] : null; $hookobject = isset($params['hookobject']) ? $params['hookobject'] : null; $implode = isset($params['implode']) ? (bool)$params['implode'] : true; // avoid sending these to ModUtil::callHooks unset($params['hookobject']); unset($params['hookaction']); unset($params['hookid']); unset($params['assign']); unset($params['implode']); if (!$hookobject) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modcallhooks', 'hookobject'))); return false; } if (!$hookaction) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modcallhooks', 'hookaction'))); return false; } if (!$hookid) { $hookid = ''; } // create returnurl if not supplied (= this page) if (!isset($params['returnurl']) || empty($params['returnurl'])) { $params['returnurl'] = str_replace('&', '&', 'http://' . System::getHost() . System::getCurrentUri()); } // if the implode flag is true then we must always assign the result to a template variable // outputing the erray is no use.... if (!$implode) { $assign = 'hooks'; } $result = ModUtil::callHooks($hookobject, $hookaction, $hookid, $params, $implode); 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; } }
/** * 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; } }
/** * 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 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; } }
/** * Wrapper for ModUtil::isCapable(). * * Param takes 'modules' and 'capability' keys. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string Translation if it was available. */ function smarty_function_iscapable($params, Zikula_View $view) { if (!isset($params['module'])) { $view->trigger_error(__('Error! "module" parameter must be specified.')); } if (!isset($params['capability'])) { $view->trigger_error(__('Error! "module" parameter must be specified.')); } $result = ModUtil::isCapable($module, $params['capability']); // assign or return if (isset($params['assign'])) { $view->assign($params['assign'], $result); } else { return $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; } }
/** * 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 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; } }
/** * 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; } }
/** * 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; }
/** * Zikula_View function to add a value to a multicontent page variable * * This function obtains a page-specific variable from the Zikula system. * * Available parameters: * - name: The name of the page variable to set * - value: The value of the page variable to set, comma separated list is possible * for stylesheet and javascript variables * * Zikula doesn't impose any restriction on the page variable's name except for duplicate * and reserved names. As of this writing, the list of reserved names consists of * <ul> * <li>title</li> * <li>stylesheet</li> * <li>javascript</li> * <li>body</li> * <li>header</li> * <li>footer</li> * </ul> * * In addition, if your system is operating in legacy compatibility mode, then * the variable 'rawtext' is reserved, and maps to 'header'. (When not operating in * legacy compatibility mode, 'rawtext' is not reserved and will not be rendered * to the page output by the page variable output filter.) * * Examples * {pageaddvar name='javascript' value='path/to/myscript.js'} * {pageaddvar name='javascript' value='path/to/myscript.js,path/to/another/script.js'} * * @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_pageaddvar($params, Zikula_View $view) { $name = isset($params['name']) ? $params['name'] : null; $value = isset($params['value']) ? $params['value'] : null; if (!$name) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('pageaddvar', 'name'))); return false; } if (!$value) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('pageaddvar', 'value'))); return false; } if (in_array($name, array('stylesheet', 'javascript'))) { $value = explode(',', $value); } PageUtil::addVar($name, $value); }
/** * Retrieve and display the value of a category field (by default, the category's path). * * Available attributes: * - id (numeric|string) if a numeric value is specified, then the * category id, if a string is specified, then * the category's path. * - idcolumn (string) field to use as the unique ID, either 'id', * 'path', or 'ipath' (optional, * default: 'id' if the id attribute is numeric, * 'path' if the id attribute is not numeric) * - field (string) category field to return (optional, default: path) * - html (boolean) if set, return HTML (optional, default: false) * - assign (string) the name of a template variable to assign the * output to, instead of returning it to the template. (optional) * * Examples: * * Get the path of category #1 and assign it to the template variable $category: * * <samp>{category_path id='1' assign='category'}</samp> * * Get the path of the category with an ipath of '/1/3/28/30' and display it. * * <samp>{category_path id='/1/3/28/30' idcolumn='ipath' field='path'}</samp> * * Get the parent_id of the category with a path of * '/__SYSTEM__/General/ActiveStatus/Active' and assign it to the template * variable $parentid. Then use that template variable to retrieve and display * the parent's path. * * <samp>{category_path id='/__SYSTEM__/General/ActiveStatus/Active' field='parent_id' assign='parentid'}</samp> * <samp>{category_path id=$parentid}</samp> * * Example from a Content module template: get the sort value of the current * page's category and assign it to the template variable $catsortvalue: * * <samp>{category_path id=$page.categoryId field='sort_value' assign='catsortvalue'}</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|string The value of the specified category field. */ function smarty_function_category_path($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $id = isset($params['id']) ? $params['id'] : 0; $idcolumn = isset($params['idcolumn']) ? $params['idcolumn'] : (is_numeric($id) ? 'id' : 'path'); $field = isset($params['field']) ? $params['field'] : 'path'; $html = isset($params['html']) ? $params['html'] : false; if (!$id) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('category_path', 'id'))); } if (!$idcolumn) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('category_path', 'idcolumn'))); } elseif ($idcolumn != 'id' && $idcolumn != 'path' && $idcolumn != 'ipath') { $view->trigger_error(__f('Error! in %1$s: invalid value for the %2$s parameter (%3$s).', array('category_path', 'idcolumn', $idcolumn))); } if (!$field) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('category_path', 'field'))); } $result = null; if ($idcolumn == 'id') { $cat = CategoryUtil::getCategoryByID($id); } elseif ($idcolumn == 'path' || $idcolumn == 'ipath') { $cat = CategoryUtil::getCategoryByPath($id, $idcolumn); } if ($cat) { if (isset($cat[$field])) { $result = $cat[$field]; } else { $view->trigger_error(__f('Error! Category [%1$s] does not have the field [%2$s] set.', array($id, $field))); return; } } else { $view->trigger_error(__f('Error! Cannot retrieve category with ID %s.', DataUtil::formatForDisplay($id))); return; } if ($assign) { $view->assign($params['assign'], $result); } else { if (isset($html) && is_bool($html) && $html) { return DataUtil::formatForDisplayHTML($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; } }
/** * Zikula_View function to display the avatar of a user * * Available parameters: * - uid User uid * - width, height Width and heigt of the image (optional) * - assign The results are assigned to the corresponding variable instead of printed out (optional). * Gravatar parameters * - size Size of the gravtar (optional) * - rating Gravatar allows users to self-rate their images so that they can indicate if an image is appropriate for a certain audience. * [g|pg|r|x] see: http://en.gravatar.com/site/implement/images/ (optional) * * Examples: * {useravatar uid="2"} * {useravatar uid="2" width=80 height=80} * {useravatar uid="2" size=80 rating=g} * * @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 the avatar image. */ function smarty_function_useravatar($params, Zikula_View $view) { if (!isset($params['uid'])) { $view->trigger_error("Error! Missing 'uid' attribute for useravatar."); return false; } $email = UserUtil::getVar('email', $params['uid']); $avatar = UserUtil::getVar('avatar', $params['uid']); $uname = UserUtil::getVar('uname', $params['uid']); $avatarpath = ModUtil::getVar(UsersConstant::MODNAME, UsersConstant::MODVAR_AVATAR_IMAGE_PATH, UsersConstant::DEFAULT_AVATAR_IMAGE_PATH); $allowgravatars = ModUtil::getVar(UsersConstant::MODNAME, UsersConstant::MODVAR_GRAVATARS_ENABLED, UsersConstant::DEFAULT_GRAVATARS_ENABLED); $gravatarimage = ModUtil::getVar(UsersConstant::MODNAME, UsersConstant::MODVAR_GRAVATAR_IMAGE, UsersConstant::DEFAULT_GRAVATAR_IMAGE); if (isset($avatar) && !empty($avatar) && $avatar != $gravatarimage && $avatar != 'blank.gif') { $avatarURL = System::getBaseUrl() . $avatarpath . '/' . $avatar; } elseif ($avatar == $gravatarimage && $allowgravatars == 1) { if (!isset($params['rating'])) { $params['rating'] = false; } if (!isset($params['size'])) { if (isset($params['width'])) { $params['size'] = $params['width']; } $params['size'] = 80; } $params['width'] = $params['size']; $params['height'] = $params['size']; $avatarURL = 'http://www.gravatar.com/avatar.php?gravatar_id=' . md5($email); if (isset($params['rating']) && !empty($params['rating'])) { $avatarURL .= "&rating=" . $params['rating']; } if (isset($params['size']) && !empty($params['size'])) { $avatarURL .= "&size=" . $params['size']; } $avatarURL .= "&default=" . urlencode(System::getBaseUrl() . $avatarpath . '/' . $gravatarimage); } else { // e.g. blank.gif or empty avatars return false; } $classString = ''; if (isset($params['class'])) { $classString = "class=\"{$params['class']}\" "; } $html = '<img ' . $classString . ' src="' . DataUtil::formatForDisplay($avatarURL) . '" title="' . DataUtil::formatForDisplay($uname) . '" alt="' . DataUtil::formatForDisplay($uname); if (isset($params['width'])) { $html .= ' width="' . $params['width'] . '"'; } if (isset($params['height'])) { $html .= ' height="' . $params['height'] . '"'; } $html .= '" />'; if (isset($params['assign'])) { $view->assign($params['assign'], $avatarURL); } else { return $html; } }
/** * Plugin to set a variable on the theme * * This function set the corresponding value on a theme variable * * Available parameters: * - name: Name of the variable * - value: The value to set on the variable * * Example * {themesetvar name='master' value='1col'} for Andreas08 * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return mixed */ function smarty_function_themesetvar($params, Zikula_View $view) { $name = isset($params['name']) ? $params['name'] : null; $value = isset($params['value']) ? $params['value'] : null; if (!$name) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('themegetvar', 'name'))); return false; } ThemeUtil::setVar($name, $value); }
/** * Zikula_View function to add a single page variable value * * This function sets a page-specific variable from the Zikula system. Only single value pagevars are supported by * this insert! * * Available parameters: * - var: The name of the single value page variable to set * - value: The value of the page variable to set * * Zikula doesn't impose any restriction on the page variable's name except for duplicate * and reserved names. As of this writing, the list of supported names consists of * <ul> * <li>title</li> * <li>stylesheet</li> * <li>javascript</li> * <li>body</li> * <li>header</li> * <li>footer</li> * </ul> * * In addition, if your system is operating in legacy compatibility mode, then * the variable 'rawtext' is reserved, and maps to 'header'. (When not operating in * legacy compatibility mode, 'rawtext' is not reserved and will not be rendered * to the page output by the page variable output filter.) * * Example * {insert name='pageaddvar' var='javascript' value='path/to/myscript.js'} * {insert name='pageaddvar' var='title' value=$mytitle} * * Note that $mytitle must be already assigned to the Zikula_View instance * before fetch the cached template. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string */ function smarty_insert_pageaddvar($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('insert name="pageaddvar" var="stylesheet" value="path/to/file.css"', 'pageaddvar name="stylesheet" value="path/to/file.css"')), E_USER_DEPRECATED); $var = isset($params['var']) ? $params['var'] : null; $value = isset($params['value']) ? $params['value'] : null; if (!$var) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('insert.pageaddvar', 'var'))); return false; } if (!$value) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('insert.pageaddvar', 'value'))); return false; } if (in_array($var, array('stylesheet', 'javascript'))) { $value = explode(',', $value); } PageUtil::addVar($var, $value); return; }