/** * Binds template files with a Smarty * * @author Rafal Wesolowski <*****@*****.**> * @param string $sFileName template filename * @return void */ public function render($sFileName) { $sTplPath = dirname(__DIR__) . '/views/page/'; $this->oSmarty->setTemplateDir($sTplPath); $this->oSmarty->assign($this->aData); $this->oSmarty->display($sTplPath . $sFileName . '.tpl'); }
/** * Adds inline help * * @param array $params the function params * @param object $smarty reference to the smarty object * * @return string the help html to be inserted * @access public */ function smarty_function_help($params, &$smarty) { if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { return; } if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) { $params['file'] = $smarty->_tpl_vars['tplFile']; } elseif (empty($params['file'])) { return NULL; } $params['file'] = str_replace(array('.tpl', '.hlp'), '', $params['file']); if (empty($params['title'])) { // Avod overwriting existing vars CRM-11900 $oldID = $smarty->get_template_vars('id'); $smarty->assign('id', $params['id'] . '-title'); $name = trim($smarty->fetch($params['file'] . '.hlp')); $additionalTPLFile = $params['file'] . '.extra.hlp'; if ($smarty->template_exists($additionalTPLFile)) { $name .= trim($smarty->fetch($additionalTPLFile)); } $smarty->assign('id', $oldID); } else { $name = trim(strip_tags($params['title'])); } // Escape for html $title = htmlspecialchars(ts('%1 Help', array(1 => $name))); // Escape for html and js $name = htmlspecialchars(json_encode($name), ENT_QUOTES); // Format params to survive being passed through json & the url unset($params['text'], $params['title']); foreach ($params as &$param) { $param = is_bool($param) || is_numeric($param) ? (int) $param : (string) $param; } return '<a class="helpicon" title="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'> </a>'; }
/** * assigns a Smarty variable. * * @param array|string $block the template variable name(s) * @param mixed $value the value to assign * @param boolean $nocache if true any output of this variable will be not cached */ protected function assign($block, $content, $nocache = false) { if ($this->tpl == null) { $this->setRenderer($this->renderer); } $this->tpl->assign($block, $content, $nocache); }
/** * Smarty {math} function plugin * * Type: function<br> * Name: math<br> * Purpose: handle math computations in template<br> * @link http://smarty.php.net/manual/en/language.function.math.php {math} * (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param array $params parameters * @param object $template template object * @return string|null */ function smarty_function_math($params, $template) { // be sure equation parameter is present if (empty($params['equation'])) { trigger_error("math: missing equation parameter",E_USER_WARNING); return; } $equation = $params['equation']; // make sure parenthesis are balanced if (substr_count($equation,"(") != substr_count($equation,")")) { trigger_error("math: unbalanced parenthesis",E_USER_WARNING); return; } // match all vars in equation, make sure all are passed preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!",$equation, $match); $allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10', 'max','min','pi','pow','rand','round','sin','sqrt','srand','tan'); foreach($match[1] as $curr_var) { if ($curr_var && !in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) { trigger_error("math: function call $curr_var not allowed",E_USER_WARNING); return; } } foreach($params as $key => $val) { if ($key != "equation" && $key != "format" && $key != "assign") { // make sure value is not empty if (strlen($val)==0) { trigger_error("math: parameter $key is empty",E_USER_WARNING); return; } if (!is_numeric($val)) { trigger_error("math: parameter $key: is not numeric",E_USER_WARNING); return; } $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); } } $smarty_math_result = null; eval("\$smarty_math_result = ".$equation.";"); if (empty($params['format'])) { if (empty($params['assign'])) { return $smarty_math_result; } else { $template->assign($params['assign'],$smarty_math_result); } } else { if (empty($params['assign'])){ printf($params['format'],$smarty_math_result); } else { $template->assign($params['assign'],sprintf($params['format'],$smarty_math_result)); } } }
/** * Формирование главной страницы * * @param object $smarty шаблонизатор */ function indexAction($smarty) { $rsCategories = getAllMainCatsWithChildren(); $smarty->assign('pageTitle', 'Главная страница сайта'); $smarty->assign('rsCategories', $rsCategories); loadTemplate($smarty, 'header'); loadTemplate($smarty, 'index'); loadTemplate($smarty, 'footer'); }
/** * Initialize the fixture. * * @return null */ protected function setUp() { parent::setUp(); $this->_oAction = oxNew('oxActions'); $this->_oAction->oxactions__oxtitle = new oxField("test", oxField::T_RAW); $this->_oAction->save(); $this->_oPromo = oxNew('oxActions'); $this->_oPromo->assign(array('oxtitle' => 'title', 'oxlongdesc' => 'longdesc', 'oxtype' => 2, 'oxsort' => 1, 'oxactive' => 1)); $this->_oPromo->save(); // oxTestModules::addFunction('oxStr', 'setH($h)', '{oxStr::$_oHandler = $h;}'); }
/** * Processes / setups the template * assigns all things to the template like mod_srings and app_strings * */ function process() { global $current_language, $app_strings, $sugar_version, $sugar_config, $timedate, $theme; $module_strings = return_module_language($current_language, $this->module); $this->ss->assign('SUGAR_VERSION', $sugar_version); $this->ss->assign('JS_CUSTOM_VERSION', $sugar_config['js_custom_version']); $this->ss->assign('VERSION_MARK', getVersionedPath('')); $this->ss->assign('THEME', $theme); $this->ss->assign('APP', $app_strings); $this->ss->assign('MOD', $module_strings); }
/** * 留言评论有回复,发邮件通知 * * @author mrmsl <*****@*****.**> * @date 2013-06-07 17:36:25 * * @param array $info 邮件信息,array('email' => $email, 'subject' => $subject, 'content' => $content) * * @return true|string true发送成功,否则错误信息 */ private function _comments_at_email($info) { $comment_info = $info['email']; $info['email'] = $comment_info['email']; $info['mail_type'] = MAIL_TYPE_COMMMENTS_AT_EMAIL; $info['subject'] = str_replace('{$comment_name}', $comment_name = $comment_info['comment_name'], $info['subject']); $info['content'] = $this->_view_template->assign(array('comment_name' => $comment_name, 'content' => $comment_info['parent_id'] ? str_replace('@<a class="link" href="', '@<a class="link" target="_blank" href="' . substr_replace($comment_info['link_url'], '', strpos($comment_info['link_url'], '#')), $comment_info['content']) : $comment_info['content'], 'link_url' => $comment_info['link_url']))->fetch('Mail', 'comments_at_email'); $result = $this->doMail($info); //C('_FACADE_SKIP', 'skip'); //$this->_model->table(TB_COMMENTS)->where(array('comment_id' => $comment_info['comment_id']))->save(array('at_email' => true === $result ? MAIL_RESULT_SUCCESS : MAIL_RESULT_FAILURE)); return $result; }
/** * Function used to build form element for new contact or select contact widget * * @param object $form form object * @param int $blocNo by default it is one, except for address block where it is * build for each block * @param array $extrProfiles extra profiles that should be included besides reserved * * @access public * * @return void */ static function buildQuickForm(&$form, $blockNo = 1, $extraProfiles = NULL, $required = FALSE, $prefix = '') { // call to build contact autocomplete $attributes = array('width' => '200px'); $form->add('text', "{$prefix}contact[{$blockNo}]", ts('Select Contact'), $attributes, $required); $form->addElement('hidden', "{$prefix}contact_select_id[{$blockNo}]"); if (CRM_Core_Permission::check('edit all contacts') || CRM_Core_Permission::check('add contacts')) { // build select for new contact $contactProfiles = CRM_Core_BAO_UFGroup::getReservedProfiles('Contact', $extraProfiles); $form->add('select', "{$prefix}profiles[{$blockNo}]", ts('Create New Contact'), array('' => ts('- create new contact -')) + $contactProfiles, FALSE, array('onChange' => "if (this.value) { newContact{$prefix}{$blockNo}( this.value, {$blockNo}, '{$prefix}' );}")); } $form->assign('blockNo', $blockNo); $form->assign('prefix', $prefix); }
/** * Example: * {securityutil_checkpermission component='Users::' instance='.*' level='ACCESS_ADMIN' assign='auth'} * * true/false will be returned. * * This file is a plugin for Zikula_View, the Zikula implementation of Smarty * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object * @return boolean authorized? */ function smarty_function_securityutil_checkpermission($params, $smarty) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('securityutil_checkpermission', 'checkpermission')), E_USER_DEPRECATED); if (!isset($params['component'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('securityutil_checkpermission', 'component'))); return false; } if (!isset($params['instance'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('securityutil_checkpermission', 'instance'))); return false; } if (!isset($params['level'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('securityutil_checkpermission', 'level'))); return false; } $result = SecurityUtil::checkPermission($params['component'], $params['instance'], constant($params['level'])); if (isset($params['assign'])) { $smarty->assign($params['assign'], $result); } else { return $result; } }
/** * Smarty function to display footnotes caculated by earlier modifier * * Example * {footnotes} * * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object */ function smarty_function_footnotes($params, $smarty) { // globalise the links array global $link_arr; $text = ''; if (is_array($link_arr) && !empty($link_arr)) { $text .= '<ol>'; $link_arr = array_unique($link_arr); foreach ($link_arr as $key => $link) { // check for an e-mail address if (preg_match("/^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$/i", $link)) { $linktext = $link; $link = 'mailto:' . $link; // append base URL for local links (not web links) } elseif (!preg_match("/^http:\\/\\//i", $link)) { $link = System::getBaseUrl() . $link; $linktext = $link; } else { $linktext = $link; } $linktext = DataUtil::formatForDisplay($linktext); $link = DataUtil::formatForDisplay($link); // output link $text .= '<li><a class="print-normal" href="' . $link . '">' . $linktext . '</a></li>' . "\n"; } $text .= '</ol>'; } if (isset($params['assign'])) { $smarty->assign($params['assign'], $text); } else { return $text; } }
/** * Smarty function for checking change in a property's value, for example * when looping through an array. * * * Smarty param: string $key unique identifier for this property (REQUIRED) * Smarty param: mixed $value the current value of the property * Smarty param: string $assign name of template variable to which to assign result * * * @param array $params template call's parameters * @param object $smarty the Smarty object * * @return NULL */ function smarty_function_isValueChange($params, &$smarty) { static $values = array(); if (empty($params['key'])) { $smarty->trigger_error("Missing required parameter, 'key', in isValueChange plugin."); return; } $is_changed = FALSE; if (!array_key_exists($params['key'], $values) || $params['value'] != $values[$params['key']]) { // if we have a new value $is_changed = TRUE; $values[$params['key']] = $params['value']; // clear values on all properties added below/after this property $clear = FALSE; foreach ($values as $k => $dontcare) { if ($clear) { unset($values[$k]); } elseif ($params['key'] == $k) { $clear = TRUE; } } } if ($params['assign']) { $smarty->assign($params['assign'], $is_changed); } return; }
/** * sets up the search forms, populates the preset values * */ function setup() { global $mod_strings, $app_strings, $image_path, $app_list_strings, $theme, $timedate; $this->xtpl = new XTemplate($this->tpl); $this->xtpl->assign("MOD", $mod_strings); $this->xtpl->assign("APP", $app_strings); $this->xtpl->assign("THEME", $theme); $this->xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format()); $this->xtpl->assign("USER_DATEFORMAT", '(' . $timedate->get_user_date_format() . ')'); $this->xtpl->assign("IMAGE_PATH", $image_path); foreach ($this->searchFields as $name => $params) { if (isset($params['template_var'])) { $templateVar = $params['template_var']; } else { $templateVar = strtoupper($name); } if (isset($params['value'])) { // populate w/ preselected values if (isset($params['options'])) { $options = $app_list_strings[$params['options']]; if (isset($params['options_add_blank']) && $params['options_add_blank']) { array_unshift($options, ''); } $this->xtpl->assign($templateVar, get_select_options_with_id($options, $params['value'])); } else { if (isset($params['input_type'])) { switch ($params['input_type']) { case 'checkbox': // checkbox input if ($params['value'] == 'on' || $params['value']) { $this->xtpl->assign($templateVar, 'checked'); } break; } } else { // regular text input $this->xtpl->assign($templateVar, to_html($params['value'])); } } } else { // populate w/o preselected values if (isset($params['options'])) { $options = $app_list_strings[$params['options']]; if (isset($params['options_add_blank']) && $params['options_add_blank']) { array_unshift($options, ''); } $this->xtpl->assign($templateVar, get_select_options_with_id($options, '')); } } } if (!empty($_REQUEST['assigned_user_id'])) { $this->xtpl->assign("USER_FILTER", get_select_options_with_id(get_user_array(FALSE), $_REQUEST['assigned_user_id'])); } else { $this->xtpl->assign("USER_FILTER", get_select_options_with_id(get_user_array(FALSE), '')); } // handle my items only if (isset($this->searchFields['current_user_only']) && isset($this->searchFields['current_user_only']['value'])) { $this->xtpl->assign("CURRENT_USER_ONLY", "checked"); } }
/** * Function: Creates a pretty menu and navigation bar above your module admin page * * I've nicked the basis of this from functions.php,v 1.2 of the new Profiles module * developed by hyperpod for Xoops V1.2, who in turn based this on Hsalazar's work with Soapbox * * @version 1 * @author A Kitson * @param int $currentoption The menu option to display as being current * @param string $breadcrumb the trail back to where we've come from */ function loadModuleAdminMenu($currentoption = 0, $breadcrumb = '') { /** * @global object $xoopsModule {@link XoopsModule} object for the current module */ global $xoopsModule; /** * @var array $menuoptions - get the adminmenu variables from the template object (assigned during xoops_cp_header() ) */ $menuoptions = $this->tplEngine->get_template_vars('adminmenu'); /** * If the current module has menu links there */ if (isset($menuoptions[$xoopsModule->getVar('mid')])) { /** * Add the breadcrumb to the links */ $menuoptions[$xoopsModule->getVar('mid')]['breadcrumb'] = $breadcrumb; /** * Add the currently selected option */ $menuoptions[$xoopsModule->getVar('mid')]['current'] = $currentoption; /** * Assign the links with additional information to the template object */ $this->tplEngine->assign('modulemenu', $menuoptions[$xoopsModule->getVar('mid')]); } }
/** * Setter * @access public * @return array Mounts */ public function __set($name, $value) { if ($name == "SmartyBody") { if (is_array($value)) { $this->Smarty->assign($value[1]); $template_name = $value[0]; } else { $template_name = $value[0]; } $body = $this->Smarty->fetch($template_name); preg_match_all("/\\[([A-Za-z0-9]+)([^\\]]*)\\]((.*)\\[\\/\\1\\])?/si", $body, $matches); foreach ($matches[0] as $index => $variable) { switch ($matches[1][$index]) { case "subject": $this->Subject = $matches[4][$index]; break; case "settings": $str = str_replace(' ', '&', trim($matches[2][$index])); parse_str($str, $settings); if ($settings['priority']) { $this->Priority = $settings['priority']; } if ($settings['charset']) { $this->CharSet = $settings['charset']; } break; } $body = str_replace($matches[0][$index], "", $body); } $this->Body = trim($body); if ($settings['type'] == 'html') { $this->AltBody = strip_tags(trim($body)); } } }
/** * 解析视图文件 * * @param string $file */ public function renderFile($file) { // 开启smarty模版引擎后, 实例化smarty对象 switch (Imp::app()->instance('config')->get('template')) { case 'smarty': Loader::load('vendor/Imp/Core/Template'); $smartyObject = new Template(); $this->smarty = $smartyObject->smarty; $this->smarty->assign($this->tpl_var); $this->smarty->display($file); break; default: echo $this->readFileContent($file); break; } }
/** * Get Area Data Custom for Mapping * @param $area_object */ function getAreaDataCustom($area_object) { // Define Area $area = array(); $area['name'] = $area_object->name; if (empty($area['name'])) { $area['name'] = 'N/A'; } $area['id'] = $area_object->id; $area['coordinates'] = $area_object->coordinates; // Check for proper coordinates pattern if (preg_match('/^[0-9\\s\\(\\)\\,\\.\\-]+$/', $area_object->coordinates)) { $fields = array(); foreach ($area_object->column_fields as $field) { $fields[$field] = $area_object->{$field}; } // Define Maps Info Window HTML by Sugar Smarty Template $this->sugarSmarty->assign("module_type", 'jjwg_Areas'); $this->sugarSmarty->assign("fields", $fields); // display fields array // Use @ error suppression to avoid issues with SugarCRM On-Demand $area['html'] = @$this->sugarSmarty->fetch('./custom/modules/jjwg_Areas/tpls/AreasInfoWindow.tpl'); if (empty($area['html'])) { $area['html'] = $this->sugarSmarty->fetch('./modules/jjwg_Areas/tpls/AreasInfoWindow.tpl'); } $area['html'] = preg_replace('/\\n\\r/', ' ', $area['html']); //var_dump($marker['html']); return $area; } else { return false; } }
/** * Replace the value of an attribute in the input string. Assume * the the attribute is well formed, of the type name="value". If * no replacement is mentioned the value is inserted at the end of * the form element * * @param array $params the function params * @param object $smarty reference to the smarty object * * @return string the help html to be inserted * @access public */ function smarty_function_help($params, &$smarty) { if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) { return; } if (isset($params['file'])) { $file = $params['file']; } else { if (isset($smarty->_tpl_vars['tplFile'])) { $file = $smarty->_tpl_vars['tplFile']; } else { return; } } $file = str_replace('.tpl', '.hlp', $file); $id = urlencode($params['id']); if ($id == 'accesskeys') { $file = 'CRM/common/accesskeys.hlp'; } require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::Singleton(); $smarty->assign('id', $params['id']); $help = $smarty->fetch($file); return <<<EOT <script type="text/javascript"> cj( function() { cj(".helpicon").toolTip(); });</script> <div class="helpicon"> <span id="{$id}_help" style="display:none">{$help}</span></div> EOT; }
/** * displays the advanced search form body * * @param bool $header display this with headers * @param bool $return echo or return the html * * @return string html of contents */ function displayAdvanced($header = true, $return = false, $listViewDefs = '', $lv = '') { global $current_user, $current_language; $GLOBALS['log']->debug('SearchForm.php->displayAdvanced()'); $this->bean->custom_fields->populateAllXTPL($this->xtpl, 'search'); if (!empty($listViewDefs) && !empty($lv)) { $GLOBALS['log']->debug('SearchForm.php->displayAdvanced(): showing saved search'); $savedSearch = BeanFactory::getBean('SavedSearch'); $savedSearch->init($listViewDefs[$this->module], $lv->data['pageData']['ordering']['orderBy'], $lv->data['pageData']['ordering']['sortOrder']); $this->xtpl->assign('SAVED_SEARCH', $savedSearch->getForm($this->module, false)); $this->xtpl->assign('MOD_SAVEDSEARCH', return_module_language($current_language, 'SavedSearch')); $this->xtpl->assign('ADVANCED_SEARCH_IMG', SugarThemeRegistry::current()->getImageURL('advanced_search.gif')); //this determines whether the saved search subform should be rendered open or not if (isset($_REQUEST['showSSDIV']) && $_REQUEST['showSSDIV'] == 'yes') { $this->xtpl->assign('SHOWSSDIV', 'yes'); $this->xtpl->assign('DISPLAYSS', ''); } else { $this->xtpl->assign('SHOWSSDIV', 'no'); $this->xtpl->assign('DISPLAYSS', 'display:none'); } } $this->xtpl->parse("advanced"); $text = $this->xtpl->text("advanced"); if ($header) { $this->displayWithHeaders('advanced_search', '', $text); } else { if ($return) { return $text; } else { echo $text; } } }
/** * 调用view的fetch接口 * 将$this->vars输出到模板,并返回最后生成的字符串 * * @stability: 4 * @param string $name * @return string */ protected function fetch($templateFile = '', $content = '', $prefix = '') { if ($this->vars) { $this->view->assign($this->vars); } return $this->view->fetch($templateFile, $content, $prefix); }
/** * Smarty function to parse structured tree array to html unordered list * * This plugin is parsing list in two modes. Default generate simple unordered list. * Second, called below as "extend" return list where elements are described by following class names: * - first: li element is first in node * - last: li element is last in node * - single: li element is the only element in node * - parent: li element has children * - childless: li element has not children * - level: ul element nesting level, starting from 1 * This is supposed to help in formatting list by css * * Available parameters: * - data: array with tree data (array, required) * - id: id for main UL element (string, optional) * - class: class for main UL element (string, optional) * - nodeprefix: prefix LI elements id (if empty - LI element wont have ids) (string, optional) * - classprefix: if provided - LI elements will get class with this prefix and node id (string, optional) * - ext: extended parsing (bool, optional) * - extopt: allow to overwrite default options for extended parsing, * this params have to be given in this order: * 'first,last,single,parent,childless,level' * (string - coma separated list of values, optional) * - assign: if set, the results are assigned to the corresponding variable instead of printed out * * Example * {menutree data=$menutree_content id='listid' class='menutree'} * * will generate unordered list with id "listid" and class "menutree" * * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object * @return string unordered html list */ function smarty_function_menutree($params, $smarty) { $treeArray = isset($params['data']) ? $params['data'] : ''; $treeId = isset($params['id']) ? $params['id'] : ''; $treeClass = isset($params['class']) ? $params['class'] : ''; $treeNodePrefix = isset($params['nodeprefix']) ? $params['nodeprefix'] : ''; $treeClassPrefix = isset($params['classprefix']) ? $params['classprefix'] : ''; $extended = isset($params['ext']) ? $params['ext'] : false; $extendedOpt = isset($params['extopt']) ? $params['extopt'] : ''; if ($extended) { $ext_tmp = explode(',', $extendedOpt); $ext = array(); $ext['first'] = !empty($ext_tmp[0]) ? $ext_tmp[0] : 'first'; $ext['last'] = !empty($ext_tmp[1]) ? $ext_tmp[1] : 'last'; $ext['single'] = !empty($ext_tmp[2]) ? $ext_tmp[2] : 'single'; $ext['parent'] = !empty($ext_tmp[3]) ? $ext_tmp[3] : 'parent'; $ext['childless'] = !empty($ext_tmp[4]) ? $ext_tmp[4] : 'childless'; $ext['level'] = !empty($ext_tmp[5]) ? $ext_tmp[5] : 'level'; $depth = 1; $html = _htmlListExt($treeArray, $treeNodePrefix, $treeClassPrefix, $ext, $depth, $treeId, $treeClass); } else { $html = _htmlList($treeArray, $treeNodePrefix, $treeClassPrefix, $treeId, $treeClass); } if (isset($params['assign'])) { $smarty->assign($params['assign'], $html); } else { return $html; } }
/** * Render specified template * * @param String $name - template name inside a subdirectory of "views" named after the controller * @return void */ function show($name) { // path to template $path = strtolower(preg_replace("/Controller/", "", $this->controller) . "/{$name}.tpl"); // check template file exists if (file_exists(APP_PATH . "/views/{$path}") == false) { throw new Exception("Template not found in {$path}"); return false; } // assign variables foreach ($this->vars as $key => $value) { $this->smarty->assign($key, $value); } // render template $this->smarty->display($path); }
/** * Smarty {cycle} function plugin * * Type: function<br> * Name: cycle<br> * Date: May 2, 2002<br> * Purpose: cycle through given values<br> * Input: * - name = name of cycle (optional) * - values = comma separated list of values to cycle, * or an array of values to cycle * (this can be left out for subsequent calls) * - reset = boolean - resets given var to true * - print = boolean - print var or not. default is true * - advance = boolean - whether or not to advance the cycle * - delimiter = the value delimiter, default is "," * - assign = boolean, assigns to template var instead of * printed. * * Examples:<br> * <pre> * {cycle values="#eeeeee,#d0d0d0d"} * {cycle name=row values="one,two,three" reset=true} * {cycle name=row} * </pre> * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} * (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @author credit to Mark Priatel <*****@*****.**> * @author credit to Gerard <*****@*****.**> * @author credit to Jason Sweat <*****@*****.**> * @version 2.2 * @param array * @param object $template template object * @return string|null */ function smarty_function_cycle($params, $template) { static $cycle_vars; $name = (empty($params['name'])) ? 'default' : $params['name']; $print = (isset($params['print'])) ? (bool)$params['print'] : true; $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; if (!in_array('values', array_keys($params))) { if(!isset($cycle_vars[$name]['values'])) { trigger_error("cycle: missing 'values' parameter"); return; } } else { if(isset($cycle_vars[$name]['values']) && $cycle_vars[$name]['values'] != $params['values'] ) { $cycle_vars[$name]['index'] = 0; } $cycle_vars[$name]['values'] = $params['values']; } if (isset($params['delimiter'])) { $cycle_vars[$name]['delimiter'] = $params['delimiter']; } elseif (!isset($cycle_vars[$name]['delimiter'])) { $cycle_vars[$name]['delimiter'] = ','; } if(is_array($cycle_vars[$name]['values'])) { $cycle_array = $cycle_vars[$name]['values']; } else { $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); } if(!isset($cycle_vars[$name]['index']) || $reset ) { $cycle_vars[$name]['index'] = 0; } if (isset($params['assign'])) { $print = false; $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); } if($print) { $retval = $cycle_array[$cycle_vars[$name]['index']]; } else { $retval = null; } if($advance) { if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) { $cycle_vars[$name]['index'] = 0; } else { $cycle_vars[$name]['index']++; } } return $retval; }
/** * Assigns translation values as variables into the Smarty global object. */ private function setLangVars() { $languages = new Translation(); $lang = $languages->getTranslations(); foreach ($lang as $key => $value) { $this->smarty->assign('lang_' . $key, $value); } }
/** * Smarty {preg_match} function plugin * * Type: function<br> * Name: preg_match<br> * Purpose: offers php preg_match function inside a template * @author Damiano Venturin * @param array parameters * @param object $template template object * @return boolean, matches array in template */ function smarty_function_preg_match($params, $template) { $flags = empty($params['flags']) ? 0 : $params['flags']; $offset = empty($params['offset']) ? 0 : $params['offset']; $match = preg_match("/" . $params['pattern'] . "/", $params['subject'], $matches, $flags, $offset); $template->assign('matches', $matches); return $match; }
/** * Smarty {counter} function plugin * * Type: function<br> * Name: counter<br> * Purpose: print out a counter value * @author Monte Ohrt <monte at ohrt dot com> * @link http://smarty.php.net/manual/en/language.function.counter.php {counter} * (Smarty online manual) * @param array parameters * @param Smarty * @param object $template template object * @return string|null */ function smarty_function_counter($params, $template) { static $counters = array(); $name = (isset($params['name'])) ? $params['name'] : 'default'; if (!isset($counters[$name])) { $counters[$name] = array( 'start'=>1, 'skip'=>1, 'direction'=>'up', 'count'=>1 ); } $counter =& $counters[$name]; if (isset($params['start'])) { $counter['start'] = $counter['count'] = (int)$params['start']; } if (!empty($params['assign'])) { $counter['assign'] = $params['assign']; } if (isset($counter['assign'])) { $template->assign($counter['assign'], $counter['count']); } if (isset($params['print'])) { $print = (bool)$params['print']; } else { $print = empty($counter['assign']); } if ($print) { $retval = $counter['count']; } else { $retval = null; } if (isset($params['skip'])) { $counter['skip'] = $params['skip']; } if (isset($params['direction'])) { $counter['direction'] = $params['direction']; } if ($counter['direction'] == "down") $counter['count'] -= $counter['skip']; else $counter['count'] += $counter['skip']; return $retval; }
/** * Smarty function to get the users language * * This function determines the recent users language * * Available parameters: * - assign: If set, the result is assigned to the corresponding variable instead of printed out * * Example * {usergetlang name="foobar"} * * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object * @param string $assign (optional) The name of the variable to assign the result to * @return string The recent users language */ function smarty_function_usergetlang($params, $smarty) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('usergetlang', 'lang')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $result = ZLanguage::getLanguageCodeLegacy(); if ($assign) { $smarty->assign($assign, $result); return; } return $result; }
/** * render a element and return the resulting html. an element is kind of like a mini-view you can use inside a view (via $this->renderElement()). * it has (like a view) access to all variables a normal view has * @param string $name name of the element (see views/elements/) without .php * @param an array of variables the element can access in global namespace */ public function element($name, $params = array()) { $this->elementName = $name; $this->smarty->assign($this->controller->viewVars); $this->smarty->assign($params); $elemfile = ROOT . 'views' . DS . 'elements' . DS . $this->elementName . ".php"; if (!file_exists($elemfile)) { throw new Exception('Cant find element [' . $this->elementName . ']'); } return $this->smarty->fetch($elemfile); }
/** * Called when an element has a validation error * * This method will add the error message to the element label or the element html * such as defined with the method setErrorTemplate. If the error placeholder is not found * in the template, the error will be displayed in the form error block. * * @param string The element label * @param string The element html rendering * @param string The element error * @see setErrorTemplate() * @access private * @return void */ function _renderError(&$label, &$html, &$error) { $this->_tpl->assign(array('label' => '', 'html' => '', 'error' => $error)); $error = $this->_tplFetch($this->_error); $this->_tpl->assign(array('label' => $label, 'html' => $html)); if (!empty($label) && strpos($this->_error, $this->_tpl->left_delimiter . '$label') !== false) { $label = $this->_tplFetch($this->_error); } elseif (!empty($html) && strpos($this->_error, $this->_tpl->left_delimiter . '$html') !== false) { $html = $this->_tplFetch($this->_error); } $this->_tpl->clear_assign(array('label', 'html', 'error')); }
/** * Displays the output of this node list. * * @return void * * @author Benoit Grégoire <*****@*****.**> * @author Francois Proulx <*****@*****.**> * @author Max Horváth <*****@*****.**> * @copyright 2004-2006 Benoit Grégoire, Technologies Coeus inc. * @copyright 2004-2006 Francois Proulx, Technologies Coeus inc. * @copyright 2006 Max Horváth, Horvath Web Consulting */ public function getOutput() { // Init ALL smarty values $this->_smarty->assign('DEPRECATEDisSuperAdmin', false); $this->_smarty->assign('GMapsEnabled', false); $this->_smarty->assign('nodes', array()); $this->_smarty->assign('num_deployed_nodes', 0); $this->_smarty->assign('PdfSupported', false); $userData['preSelectedObject'] = $this->_network; $userData['allowEmpty'] = true; $userData['nullCaptionString'] = _("All"); $userData['onChange'] = "submit.click();"; $this->_smarty->assign('selectNetworkUI', Network::getSelectUI('network_id', $userData) . (count(Network::getAllNetworks()) > 1 ? '<input class="submit" type="submit" name="submit" value="' . _("Change network") . '">' : "")); $this->_smarty->assign('selectedNetworkName', $this->_network === null ? _("All networks") : $this->_network->getName()); /** * Define user security levels for the template * * These values are used in the default template of WiFoDog but could be used * in a customized template to restrict certain links to specific user * access levels. */ $this->_smarty->assign('DEPRECATEDisSuperAdmin', $this->_currentUser && $this->_currentUser->DEPRECATEDisSuperAdmin()); if (defined('GMAPS_HOTSPOTS_MAP_ENABLED') && GMAPS_HOTSPOTS_MAP_ENABLED == true) { $this->_smarty->assign('GMapsEnabled', true); } $_html = null; /* * Main content */ // Reset ALL smarty SWITCH values $this->_smarty->assign('sectionMAINCONTENT', false); // Set section of Smarty template $this->_smarty->assign('sectionMAINCONTENT', true); // Node details if ($this->_nodes) { foreach ($this->_nodes as $_nodeData) { $_node = Node::getObject($_nodeData['node_id']); $_nodeData['num_online_users'] = $_node->getNumOnlineUsers(); $this->_smarty->append("nodes", $_nodeData); } } $this->_smarty->assign("num_deployed_nodes", count($this->_nodes)); // Compile HTML code $_html_body = $this->_smarty->fetch("templates/sites/hotspot_status.tpl"); /* * Compile HTML output */ $this->_mainUI->setTitle(_("Hotspot list")); $this->_mainUI->appendHtmlHeadContent('<link rel="alternate" type="application/rss+xml" title="' . ($this->_network === null ? _("All networks") : $this->_network->getName()) . ": " . _("Newest Hotspots") . '" href="' . BASE_SSL_PATH . 'hotspot_status.php?format=RSS">'); $this->_mainUI->addContent('left_area_middle', $_html); $this->_mainUI->addContent('main_area_middle', $_html_body); $this->_mainUI->display(); }