/** * Image block * * @param array $params * @param string $content * @param Smarty_Internal_Template $smarty * @param bool $repeat * @return void */ function smarty_block_image(array $params, $content, Smarty_Internal_Template $smarty, &$repeat) { if (!$repeat) { $content = $smarty->getTemplateVars('image') ? $content : ''; $smarty->assign('image', null); return $content; } if (!array_key_exists('rendition', $params)) { throw new \InvalidArgumentException("Rendition not set"); } $renditions = Zend_Registry::get('container')->getService('image.rendition')->getRenditions(); if (!array_key_exists($params['rendition'], $renditions)) { throw new \InvalidArgumentException("Unknown rendition"); } $article = $smarty->getTemplateVars('gimme')->article; if (!$article) { throw new \RuntimeException("Not in article context."); } $articleRenditions = $article->getRenditions(); $articleRendition = $articleRenditions[$renditions[$params['rendition']]]; if ($articleRendition === null) { $smarty->assign('image', false); $repeat = false; return; } if (array_key_exists('width', $params) && array_key_exists('height', $params)) { $preview = $articleRendition->getRendition()->getPreview($params['width'], $params['height']); $thumbnail = $preview->getThumbnail($articleRendition->getImage(), Zend_Registry::get('container')->getService('image')); } else { $thumbnail = $articleRendition->getRendition()->getThumbnail($articleRendition->getImage(), Zend_Registry::get('container')->getService('image')); } $smarty->assign('image', (object) array('src' => Zend_Registry::get('view')->url(array('src' => $thumbnail->src), 'image', true, false), 'width' => $thumbnail->width, 'height' => $thumbnail->height, 'caption' => $articleRendition->getImage()->getCaption(), 'photographer' => $articleRendition->getImage()->getPhotographer())); }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_liveCustomization($params, Smarty_Internal_Template $smarty) { $app = $smarty->getApplication(); if ($app->isCustomizationMode()) { // theme dropdown $themes = array_merge(array('barebone' => 'barebone'), array_diff($app->getRenderer()->getThemeList(), array('barebone'))); $smarty->assign('themes', $themes); $smarty->assign('currentTheme', $app->getTheme()); if (!isset($params['action'])) { include_once 'function.includeJs.php'; include_once 'function.includeCss.php'; smarty_function_includeJs(array('file' => "library/prototype/prototype.js"), $smarty); smarty_function_includeJs(array('file' => "library/livecart.js"), $smarty); smarty_function_includeJs(array('file' => "library/form/ActiveForm.js"), $smarty); smarty_function_includeJs(array('file' => "library/form/Validator.js"), $smarty); smarty_function_includeJs(array('file' => "backend/Backend.js"), $smarty); smarty_function_includeJs(array('file' => "frontend/Customize.js"), $smarty); smarty_function_includeCss(array('file' => "frontend/LiveCustomization.css"), $smarty); } else { $smarty->assign('mode', $app->getCustomizationModeType()); $smarty->assign('theme', $app->getTheme()); if ('menu' == $params['action']) { return $smarty->fetch('customize/menu.tpl'); } else { if ('lang' == $params['action']) { return $smarty->fetch('customize/translate.tpl'); } } } } }
/** * Plugin for Smarty * * @param array $aParams * @param Smarty_Internal_Template $oSmartyTemplate * * @return string|null */ function smarty_function_widget_template($aParams, $oSmartyTemplate) { if (!isset($aParams['name'])) { trigger_error('Parameter "name" does not define in {widget ...} function', E_USER_WARNING); return null; } $sWidgetName = $aParams['name']; $aWidgetParams = isset($aParams['params']) ? $aParams['params'] : array(); $oEngine = Engine::getInstance(); // Проверяем делигирование $sTemplate = E::ModulePlugin()->GetDelegate('template', $sWidgetName); if ($sTemplate) { if ($aWidgetParams) { foreach ($aWidgetParams as $sKey => $sVal) { $oSmartyTemplate->assign($sKey, $sVal); } if (!isset($aWidgetParams['params'])) { /* LS-compatible */ $oSmartyTemplate->assign('params', $aWidgetParams); } $oSmartyTemplate->assign('aWidgetParams', $aWidgetParams); } $sResult = $oSmartyTemplate->fetch($sTemplate); } else { $sResult = null; } return $sResult; }
/** * Displays backend language selection menu * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_backendLangMenu($params, Smarty_Internal_Template $smarty) { if (!$smarty->getApplication()->getLanguageArray()) { return false; } $smarty->assign('currentLang', Language::getInstanceByID($smarty->getApplication()->getLocaleCode())->toArray()); $smarty->assign('returnRoute', base64_encode($smarty->getApplication()->getRouter()->getRequestedRoute())); return $smarty->display('block/backend/langMenu.tpl'); }
/** * Smarty {math} function plugin * * Type: function<br> * Name: math<br> * Purpose: handle math computations in template * * @link http://www.smarty.net/manual/en/language.function.math.php {math} * (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param array $params parameters * @param Smarty_Internal_Template $template template object * @return string|null */ function smarty_function_math($params, $template) { static $_allowed_funcs = array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true); // 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); foreach ($match[1] as $curr_var) { if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) { trigger_error("math: function call {$curr_var} not allowed", E_USER_WARNING); return; } } if (strpos($equation, '<<<') !== false) { trigger_error("math: <<< 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)); } } }
/** * Set page title * * @package application.helper.smarty * @author Integry Systems */ function smarty_block_pageTitle($params, $content, Smarty_Internal_Template $smarty, &$repeat) { if (!$repeat) { $smarty->assign('TITLE', strip_tags($content)); if (isset($params['help'])) { $content .= '<script type="text/javascript">Backend.setHelpContext("' . $params['help'] . '")</script>'; } $GLOBALS['PAGE_TITLE'] = $content; $smarty->assign('PAGE_TITLE', $content); $smarty->setGlobal('PAGE_TITLE', $content); } }
/** * This function partitions an array into n subarrays which can be used for column layouts. * * @example tests/test.tpl * * @license MIT * * @see http://www.php.net/array_chunk#75022 source of the original function * * @param array $params An array consisting of the keys array, size, and name; name is the name of the output array, size is the number of columns, array is the array to be partitioned * @param Smarty_Internal_Template $template Used by Smarty internally * * @return array Returns the partitoned array */ function smarty_function_partition($params, Smarty_Internal_Template $template = null) { // First check whether all parameters are present. $requiredParamters = ['size', 'name', 'array']; $nonEmptyParameters = ['size', 'name']; foreach ($requiredParamters as $parameterToCheck) { if (!array_key_exists($parameterToCheck, $params)) { return false; } } foreach ($nonEmptyParameters as $parameterToCheck) { // Not using empty() since that would cause problems with 0-values. if (!isset($params[$parameterToCheck])) { return false; } } // Then, we inline the parameters into better understandable variables. $numberOfParts = $params['size']; $inputList = $params['array']; $outputName = $params['name']; // If the number of parts requested is non-positive, error out. if ((int) $numberOfParts <= 0 || !is_array($inputList)) { if ($template) { $template->assign($outputName, []); return; } else { return [$outputName => []]; } } // Set up the loop to split the input up. $lengthOfList = count($inputList); $lengthOfOnePart = floor($lengthOfList / $numberOfParts); $lengthOfRemainder = $lengthOfList % $numberOfParts; $partition = []; $mark = 0; // Loop over the array and fill the columns. // The first column may contain up to (n -1) more elements than the other columns. // n is equal to the number of parts. for ($px = 0; $px < $numberOfParts; $px++) { $increment = $px < $lengthOfRemainder ? $lengthOfOnePart + 1 : $lengthOfOnePart; $partition[$px] = array_slice($inputList ?: [], $mark, $increment); $mark += $increment; } // Return the partitioned array with the pre-defined name. if ($template) { $template->assign($outputName, $partition); } else { return [$outputName => $partition]; } }
/** * Display a tip block * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_tip($params, $content, Smarty_Internal_Template $smarty, &$repeat) { if (!$repeat) { $smarty->assign('tipContent', $content); return $smarty->display('block/backend/tip.tpl'); } }
function smarty_block_fis_widget($params, $content, Smarty_Internal_Template $template, &$repeat) { if (!$repeat) { if (isset($params['extends'])) { $path = $params['extends']; unset($params['extends']); foreach ($params as $key => $v) { if ($template->getTemplateVars($key)) { $params[$key] = $template->getTemplateVars($key); } } return $content = $template->getSubTemplate($path, $template->cache_id, $template->compile_id, null, null, $params, Smarty::SCOPE_LOCAL); } else { return $content; } } else { if (isset($params['extends'])) { unset($params['extends']); } foreach ($params as $key => $v) { $value = $template->getTemplateVars($key); if ($value === null) { $template->assign($key, $v, true); } } } }
/** * Allows to use Yii beginWidget() and endWidget() methods in a simple way. * There is a variable inside a block wich has 'widget' name and represent widget object * * Example: * {begin_widget name="activeForm" foo="" bar="" otherParam="" [...]} * {$widget->some_method_or_variable} * {/begin_widget} * * @param array $params parameters * @param string $content contents of the block * @param Smarty_Internal_Template $template template object * @param boolean &$repeat repeat flag * @return string * @author t.yacenko (thekip) */ function smarty_block_begin_widget($params, $content, $template, &$repeat) { $controller_object = $template->tpl_vars['this']->value; if ($controller_object == null) { throw new CException("Can't get controller object from template. Error."); } if ($repeat) { //tag opened if (!isset($params['name'])) { throw new CException("Name parameter should be specified."); } $widgetName = $params['name']; unset($params['name']); //some widgets has 'name' as property. You can pass it by '_name' parameter if (isset($params['_name'])) { $params['name'] = $params['_name']; unset($params['_name']); } $template->assign('widget', $controller_object->beginWidget($widgetName, $params, false)); } else { //tag closed echo $content; $controller_object->endWidget(); $template->clearAssign('widget'); } }
/** * Displays ActiveGrid table * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_activeGrid($params, Smarty_Internal_Template $smarty) { if (!isset($params['rowCount']) || !$params['rowCount']) { $params['rowCount'] = 15; } foreach ($params as $key => $value) { $smarty->assign($key, $value); } if (isset($params['filters']) && is_array($params['filters'])) { $smarty->assign('filters', $params['filters']); } $smarty->assign('url', $smarty->getApplication()->getRouter()->createUrl(array('controller' => $params['controller'], 'action' => $params['action']), true)); $smarty->assign('thisMonth', date('m')); $smarty->assign('lastMonth', date('Y-m', strtotime(date('m') . '/15 -1 month'))); return $smarty->display('block/activeGrid/gridTable.tpl'); }
/** * 生成当前请求唯一的ID,并赋值给制定的模板变量名,依赖与全局模板变量__unique__ * 当__unique__存在的时候,生成的ID值会自动缀上这个数值,用于生成不同请求间的唯一ID * 一般用于页面整体内容作为ajax响应结果写入页面,而这个页面又需要引入有ID的widget这种情况 * @param String $params.assign 生成的参数赋值给的模板变量名,默认赋值给WIDGET_ID * @param Smarty_Internal_Template $template */ function smarty_function_generate_id($params, Smarty_Internal_Template $template) { $assign = !empty($params['assign']) ? $params['assign'] : "WIDGET_ID"; static $id = 0; $id++; $template->assign($assign, $id . $template->tpl_vars["__unique__"]); }
/** * PixelManager CMS (Community Edition) * Copyright (C) 2016 PixelProduction (http://www.pixelproduction.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ function smarty_function_getdatatablerow($params, Smarty_Internal_Template $template) { if (!isset($params['class']) || !isset($params['var']) || !isset($params['row'])) { return; } if (isset($params['page'])) { $page_id = $params['page']; } else { $page_id = $template->getTemplateVars('pageId'); } if (isset($params['language'])) { $language_id = $params['language']; } else { $language_id = $template->getTemplateVars('languageId'); if ($language_id === null) { $language_id = Config::get()->languages->standard; } } $data = array(); if (isset($params['row'])) { $data_table = new $params['class'](); $data = $data_table->getRowForFrontend($params['row'], $page_id, $language_id); } if (isset($params['var'])) { $template->assign($params['var'], $data); } }
/** * Process theliaModule template inclusion function * * This function accepts two parameters: * * - location : this is the location in the admin template. Example: folder-edit'. The function will search for * AdminIncludes/<location>.html file, and fetch it as a Smarty template. * - countvar : this is the name of a template variable where the number of found modules includes will be assigned. * * @param array $params * @param \Smarty_Internal_Template $template * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty * * @return string */ public function theliaModule($params, \Smarty_Internal_Template $template) { $content = null; $count = 0; if (false !== ($location = $this->getParam($params, 'location', false))) { if ($this->debug === true && $this->request->get('SHOW_INCLUDE')) { echo sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>', $location); } $moduleLimit = $this->getParam($params, 'module', null); $modules = ModuleQuery::getActivated(); /** @var \Thelia\Model\Module $module */ foreach ($modules as $module) { if (null !== $moduleLimit && $moduleLimit != $module->getCode()) { continue; } $file = $module->getAbsoluteAdminIncludesPath() . DS . $location . '.html'; if (file_exists($file)) { $output = trim(file_get_contents($file)); if (!empty($output)) { $content .= $output; $count++; } } } } if (false !== ($countvarname = $this->getParam($params, 'countvar', false))) { $template->assign($countvarname, $count); } if (!empty($content)) { return $template->fetch(sprintf("string:%s", $content)); } return ""; }
/** * Image block * * @param array $params * @param string $content * @param Smarty_Internal_Template $smarty * @param bool $repeat * @return void */ function smarty_block_image(array $params, $content, Smarty_Internal_Template $smarty, &$repeat) { if (!$repeat) { $content = $smarty->getTemplateVars('image') ? $content : ''; $smarty->assign('image', null); return $content; } if (!array_key_exists('rendition', $params)) { throw new \InvalidArgumentException("Rendition not set"); } $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $renditionService = \Zend_Registry::get('container')->getService('image.rendition'); $cacheKey = $cacheService->getCacheKey(array('theme_renditions'), 'theme'); if ($cacheService->contains($cacheKey)) { $renditions = $cacheService->fetch($cacheKey); } else { $renditions = $renditionService->getRenditions(); $cacheService->save($cacheKey, $renditions); } if (!array_key_exists($params['rendition'], $renditions)) { throw new \InvalidArgumentException("Unknown rendition"); } $article = $smarty->getTemplateVars('gimme')->article; if (!$article) { throw new \RuntimeException("Not in article context."); } $articleRenditions = $article->getRenditions(); $articleRendition = $articleRenditions[$renditions[$params['rendition']]]; if ($articleRendition === null) { $smarty->assign('image', false); $repeat = false; return; } $image = null; if (array_key_exists('width', $params) && array_key_exists('height', $params)) { $image = $renditionService->getArticleRenditionImage($article->number, $params['rendition'], $params['width'], $params['height']); } else { $image = $renditionService->getArticleRenditionImage($article->number, $params['rendition']); } $imageService = \Zend_Registry::get('container')->getService('image'); $preferencesService = \Zend_Registry::get('container')->getService('preferences'); $caption = $imageService->getCaption($articleRendition->getImage(), $article->number, $article->language->number); if ($preferencesService->get('MediaRichTextCaptions', 'N') == 'N') { $caption = MetaDbObject::htmlFilter($caption); } $smarty->assign('image', (object) array('src' => \Zend_Registry::get('view')->url(array('src' => $image['src']), 'image', true, false), 'width' => $image['width'], 'height' => $image['height'], 'caption' => $caption, 'description' => $articleRendition->getImage()->getDescription(), 'photographer' => $articleRendition->getImage()->getPhotographer(), 'original' => $image['original'])); }
/** * Smarty {cycle} function plugin * * Type: function<br> * Name: cycle<br> * Date: May 3, 2002<br> * Purpose: cycle through given values<br> * Params: * <pre> * - 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. * </pre> * Examples:<br> * <pre> * {cycle values="#eeeeee,#d0d0d0d"} * {cycle name=row values="one,two,three" reset=true} * {cycle name=row} * </pre> * * @link http://www.smarty.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 1.3 * @param array $params parameters * @param Smarty_Internal_Template $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 (!isset($params['values'])) { 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; }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_uniqid($params, Smarty_Internal_Template $smarty) { if (isset($params['last'])) { return $smarty->getTemplateVars('lastUniqId'); } else { // start with a letter for XHTML id attribute value compatibility $id = 'a' . uniqid(); $smarty->assign('lastUniqId', $id); if (isset($params['assign'])) { $smarty->assign($params['assign'], $id); if (!empty($params['noecho'])) { return ''; } } return $id; } }
/** * Get postage amount for cart * * @param array $params Block parameters * @param mixed $content Block content * @param \Smarty_Internal_Template $template Template * @param bool $repeat Control how many times * the block is displayed * * @return mixed */ public function postage($params, $content, $template, &$repeat) { if (!$repeat) { return null !== $this->countryId ? $content : ""; } $customer = $this->request->getSession()->getCustomerUser(); $country = $this->getDeliveryCountry($customer); if (null !== $country) { $this->countryId = $country->getId(); // try to get the cheapest delivery for this country $this->getCheapestDelivery($country); } $template->assign('country_id', $this->countryId); $template->assign('delivery_id', $this->deliveryId); $template->assign('postage', $this->postage ?: 0.0); $template->assign('is_customizable', $this->isCustomizable); }
/** * @param array $params * @param Smarty_Internal_Template $smarty * * @return \Illuminate\Auth\UserInterface|null * * @author Kovács Vince */ function smarty_function_auth_user($params, Smarty_Internal_Template $smarty) { if (isset($params['assign'])) { $smarty->assign($params['assign'], \Auth::user()); return null; } return \Auth::user(); }
/** * Close list table and submit button */ public function displayListFooter() { if (!isset($this->list_id)) { $this->list_id = $this->table; } $this->footer_tpl->assign(array_merge($this->tpl_vars, array('current' => $this->currentIndex, 'list_id' => $this->list_id))); return $this->footer_tpl->fetch(); }
/** * Generates pagination block * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_paginate($params, Smarty_Internal_Template $smarty) { $interval = 2; if (isset($params['interval'])) { $interval = $params['interval']; } // determine which page numbers will be displayed $count = ceil($params['count'] / $params['perPage']); $pages = range(max(1, $params['current'] - $interval), min($count, $params['current'] + $interval)); if (array_search(1, $pages) === false) { array_unshift($pages, 1); } if (array_search($count, $pages) === false) { $pages[] = $count; } // check for any 1-page sized interval breaks $pr = 0; foreach ($pages as $k) { if ($k - 2 == $pr) { $pages[] = $k - 1; } $pr = $k; } sort($pages); // generate output $out = array(); $application = $smarty->getApplication(); // get variable to replace - _page_ if defined, otherwise 0 $replace = strpos($params['url'], '_000_') ? '_000_' : 0; $render = array(); if ($params['current'] > 1) { $urls['previous'] = str_replace($replace, $params['current'] - 1, $params['url']); } foreach ($pages as $k) { $urls[$k] = str_replace($replace, $k, $params['url']); } if ($params['current'] < $count) { $urls['next'] = str_replace($replace, $params['current'] + 1, $params['url']); } $smarty->assign('urls', $urls); $smarty->assign('pages', $pages); $smarty->assign('current', $params['current']); return $smarty->fetch($smarty->getApplication()->getRenderer()->getTemplatePath('block/box/paginate.tpl')); return implode(' ', $out); }
/** * Display page section header and footer only if content is present * This helps to avoid using redundant if's * * @param array $params * @param Smarty $smarty * @param $repeat * * <code> * {sect} * {header} * Section header * {/header} * {content} * Section content * {/content} * {footer} * Section footer * {/footer} * {/sect} * </code> * * @return string Section HTML code * @package application.helper.smarty * @author Integry Systems */ function smarty_block_header($params, $content, Smarty_Internal_Template $smarty, &$repeat) { if (!$repeat) { $counter = $smarty->getTemplateVars('sectCounter'); $blocks = $smarty->getTemplateVars('sect'); $blocks[$counter]['header'] = $content; $smarty->assign('sect', $blocks); } }
/** * Display page section header and footer only if content is present * This helps to avoid using redundant if's * * @param array $params * @param Smarty $smarty * @param $repeat * * <code> * {sect} * {header} * Section header * {/header} * {content} * Section content * {/content} * {footer} * Section footer * {/footer} * {/sect} * </code> * * @return string Section HTML code * @package application.helper.smarty * @author Integry Systems */ function smarty_block_sect($params, $content, Smarty_Internal_Template $smarty, &$repeat) { $counter = $smarty->getTemplateVars('sectCounter'); if ($repeat) { $counter++; $smarty->assign('sectCounter', $counter); $sections = $smarty->getTemplateVars('sect'); $sections[$counter] = array('header' => '', 'content' => '', 'footer' => ''); $smarty->assign('sect', $sections); } else { $blocks = $smarty->getTemplateVars('sect'); $blocks = $blocks[$counter]; $counter--; $smarty->assign('sectCounter', $counter); if (trim($blocks['content'])) { return $blocks['header'] . $blocks['content'] . $blocks['footer']; } } }
function smarty_function_global($params, Smarty_Internal_Template $template) { if (isset($params['put'])) { // assign variable to template object scope $template->assign($params['put'], $params['value']); } if (isset($params['get'])) { return $params['get']; } }
/** * Form field row * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_input($params, $content, Smarty_Internal_Template $smarty, &$repeat) { $formParams = $smarty->_tag_stack[0][1]; if (!$repeat) { $formHandler = $formParams['handle']; $isRequired = $formHandler ? $formHandler->isRequired($params['name']) : false; $fieldType = $smarty->getTemplateVars('last_fieldType'); if ($formHandler && $formHandler->getValidator()) { $err = $formHandler->getValidator()->getErrorList(); $msg = empty($err[$params['name']]) ? '' : $err[$params['name']]; } else { $msg = ''; } if ('checkbox' == $fieldType) { preg_match('/<input(.*) \\/\\>(.*)\\<label(.*)\\>(.*)\\<\\/label\\>/msU', $content, $matches); if ($matches) { $content = '<label ' . $matches[3] . '><input ' . $matches[1] . ' /> ' . $matches[4] . '</label>'; } } $name = $params['name']; $class = !empty($params['class']) ? ' ' . $params['class'] : ' '; unset($params['name'], $params['class']); $c = $content; $content = '<div class="row ' . ($msg ? 'has-error' : '') . ' name_' . $name . ' type_' . $fieldType . ' ' . ($isRequired ? ' required' : '') . $class . '"'; foreach ($params as $n => $param) { $content .= ' ' . $n . '="' . $param . '"'; } $content .= '>' . $c; foreach ($smarty->getFieldValidation($name, $formHandler) as $val) { $content .= '<div ng-show="isSubmitted && form.' . $name . '.$error.' . substr($val[0], 3) . '" class="text-danger">' . $val[1] . '</div>'; } if ($msg) { $content .= '<div class="text-danger">' . $msg . '</div>'; } $content .= '</div>'; $smarty->assign('last_fieldType', ''); $smarty->assign('input_name', ''); return $content; } else { $smarty->assign('last_fieldType', ''); $smarty->assign('input_name', $params['name']); } }
/** * Language forms * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_language($params, $content, Smarty_Internal_Template $smarty, &$repeat) { //$smarty = $smarty->smarty; $app = $smarty->smarty->getApplication(); if (!$app->getLanguageSetArray()) { return false; } if ($repeat) { $app->languageBlock = $app->getLanguageSetArray(); $smarty->assign('languageBlock', $app->languageBlock); $smarty->assign('lang', array_shift($app->languageBlock)); $app->langHeadDisplayed = false; $user = SessionUser::getUser(); foreach ($app->getLanguageSetArray() as $lang) { $userPref = $user->getPreference('tab_lang_' . $lang['ID']); $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false'; $classNames[$lang['ID']] = $isHidden ? 'hidden' : ''; } $app->langClassNames = $classNames; } else { if (!trim($content)) { $repeat = false; return false; } if ($app->languageBlock) { $repeat = true; } $contentLang = $smarty->getTemplateVars('lang'); $content = '<tab class="lang_' . $contentLang['ID'] . '" heading="' . $contentLang['originalName'] . '">' . $content . '</tab>'; if (!$app->langHeadDisplayed) { $smarty->assign('classNames', $app->langClassNames); $content = $smarty->fetch('block/backend/langFormHead.tpl') . $content; $app->langHeadDisplayed = true; } $smarty->assign('lang', array_shift($app->languageBlock)); // form footer if (!$repeat) { $content .= $smarty->fetch('block/backend/langFormFoot.tpl'); } return $content; } }
function smarty_function_getConfigValue($params, Smarty_Internal_Template $template) { if (isset($params['keyname'])) { $project = \Synergy\Project::getObject(); if ($project instanceof \Synergy\Project\ProjectAbstract) { $template->assign($params['assign'], $project->getOption($params['keyname'])); } } else { throw new \Synergy\Exception\TemplateFunctionException('getConfigValue function requires a keyname to search for'); } }
/** * Get FlashMessage * And clean session from this key * * @param array $params Block parameters * @param mixed $content Block content * @param \Smarty_Internal_Template $template Template * @param bool $repeat Control how many times * the block is displayed * * @return mixed */ public function getFlashMessage($params, $content, \Smarty_Internal_Template $template, &$repeat) { if ($repeat) { if (false !== ($key = $this->getParam($params, 'key', false))) { $flashBag = $this->request->getSession()->get('flashMessage'); $template->assign('value', $flashBag[$key]); // Reset flash message (can be read once) unset($flashBag[$key]); $this->request->getSession()->set('flashMessage', $flashBag); } } else { return $content; } }
function smarty_function_display($params, Smarty_Internal_Template &$template) { foreach ($params as $key => $value) { if ($key == 'pattern') { continue; } if (is_object($value)) { $template->assignByRef($key, $value); } else { $template->assign($key, $value); } } $template->smarty->display($params['pattern']); }
/** * Paginate layout printing function. * * @param array $params Specified params. * @param Smarty_Internal_Template $template Instance of Smarty template class. * * @uses Core\Config() * * @return string Rendered pagination template. */ function smarty_function_pagination(array $params, Smarty_Internal_Template $template) { $viewsPaths = Core\Config()->paths('views'); $params['range'] = isset($params['range']) ? abs($params['range']) : 2; $_path_to_templates = $viewsPaths['templates'] . '_shared' . DIRECTORY_SEPARATOR; $_template = isset($params['template']) ? $_path_to_templates . $params['template'] . '.html.tpl' : null; $params['template'] = file_exists($_template) ? $_template : $_path_to_templates . 'pagination' . DIRECTORY_SEPARATOR . 'default.html.tpl'; $paginator = $params['paginator']; $pages_range = $paginator->range($params['range']); $range = array(); $range['start'] = isset($pages_range['first']->pageNumber) ? $pages_range['first']->pageNumber : 0; $range['end'] = isset($pages_range['last']->pageNumber) ? $pages_range['last']->pageNumber : 0; $template->assign('pagination', array('current' => $paginator->current(), 'first' => $paginator->first(), 'last' => $paginator->last(), 'prev' => $paginator->prev(), 'next' => $paginator->next(), 'boundaries' => isset($params['boundaries']) ? !!$params['boundaries'] : false, 'range' => $params['range'], 'pages' => range($range['start'], $range['end']))); return $template->fetch($params['template']); }