/**
  * Cache was invalid , so render from compiled and write to cache
  *
  * @param \Smarty_Template_Cached   $cached
  * @param \Smarty_Internal_Template $_template
  * @param                           $no_output_filter
  *
  * @throws \Exception
  */
 public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter)
 {
     ob_start();
     if (!isset($_template->compiled)) {
         $_template->loadCompiled();
     }
     $_template->compiled->render($_template);
     if ($_template->smarty->debugging) {
         $_template->smarty->_debug->start_cache($_template);
     }
     $this->removeNoCacheHash($cached, $_template, $no_output_filter);
     $compile_check = $_template->smarty->compile_check;
     $_template->smarty->compile_check = false;
     if (isset($_template->parent) && $_template->parent->_objType == 2) {
         $_template->compiled->unifunc = $_template->parent->compiled->unifunc;
     }
     if (!$_template->cached->processed) {
         $_template->cached->process($_template, true);
     }
     $_template->smarty->compile_check = $compile_check;
     $cached->getRenderedTemplateCode($_template);
     if ($_template->smarty->debugging) {
         $_template->smarty->_debug->end_cache($_template);
     }
 }
/**
 * ...
 *
 * @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');
                }
            }
        }
    }
}
Пример #3
0
/**
 * 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');
    }
}
Пример #4
0
 /**
  * get a Compiled Object of this source
  * @param  Smarty_Internal_Template $_template template object
  * @return Smarty_Template_Compiled compiled object
  */
 static function load($_template)
 {
     if (!isset($_template->source)) {
         $_template->loadSource();
     }
     // check runtime cache
     if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
         $_cache_key = $_template->source->unique_resource . '#';
         if ($_template->caching) {
             $_cache_key .= 'caching#';
         }
         $_cache_key .= $_template->compile_id;
         if (isset($_template->source->compileds[$_cache_key])) {
             return $_template->source->compileds[$_cache_key];
         }
     }
     $compiled = new Smarty_Template_Compiled();
     if (method_exists($_template->source->handler, 'populateCompiledFilepath')) {
         $_template->source->handler->populateCompiledFilepath($compiled, $_template);
     } else {
         $compiled->populateCompiledFilepath($_template);
     }
     // runtime cache
     if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
         $_template->source->compileds[$_cache_key] = $compiled;
     }
     return $compiled;
 }
/**
 * 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);
    }
}
Пример #6
0
 /**
  * compile template from source
  *
  * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
  *
  * @throws Exception
  */
 public function process(Smarty_Internal_Template $_smarty_tpl)
 {
     $compiled =& $_smarty_tpl->compiled;
     $compiled->file_dependency = array();
     $compiled->includes = array();
     $compiled->nocache_hash = null;
     $compiled->unifunc = null;
     $level = ob_get_level();
     ob_start();
     $_smarty_tpl->loadCompiler();
     // call compiler
     try {
         eval("?>" . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
     } catch (Exception $e) {
         unset($_smarty_tpl->compiler);
         while (ob_get_level() > $level) {
             ob_end_clean();
         }
         throw $e;
     }
     // release compiler object to free memory
     unset($_smarty_tpl->compiler);
     ob_get_clean();
     $compiled->timestamp = time();
     $compiled->exists = true;
 }
Пример #7
0
/**
 * Generates manufacturer page URL
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_manufacturerUrl($params, Smarty_Internal_Template $smarty)
{
    $manufacturer = $params['data'];
    $params['data'] =& Category::getRootNode()->toArray();
    $params['addFilter'] = new ManufacturerFilter($manufacturer['ID'], $manufacturer['name']);
    return createCategoryUrl($params, $smarty->getApplication());
}
function smarty_function_pageurl($params, Smarty_Internal_Template $template)
{
    $output = '';
    if (isset($params['page'])) {
        if (isset($params['language'])) {
            $language_id = $params['language'];
        } else {
            $language_id = $template->getTemplateVars('languageId');
            if ($language_id === null) {
                $language_id = Config::get()->languages->standard;
            }
        }
        $mixed_id = $params['page'];
        $page_id = false;
        $pages = new Pages();
        if (is_int($mixed_id)) {
            $page_id = $mixed_id;
        } else {
            if (is_numeric($mixed_id)) {
                $page_id = (int) $mixed_id;
            } else {
                if (is_string($mixed_id)) {
                    $page_id = $pages->getPageIdByUniqueId($mixed_id);
                }
            }
        }
        if ($page_id !== false) {
            $output = $pages->getPageUrl($page_id, $language_id);
        }
    }
    return $output;
}
/**
 * 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');
    }
}
Пример #10
0
 /**
  * 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 "";
 }
Пример #11
0
/**
 * Smarty block plugin, for generating page menu item
 * This block must always be called in pageMenu block context
 *
 * @param array $params
 * @param Smarty $smarty
 * @param $repeat
 *
 * <code>
 *	{pageMenu id="menu"}
 *		{menuItem}
 *			{menuCaption}Click Me{/menuCaption}
 *			{menuAction}http://click.me.com{/menuAction}
 *		{/menuItem}
 *		{menuItem}
 *			{menuCaption}Another menu item{/menuCaption}
 *			{pageAction}alert('Somebody clicked on me too!'){/menuAction}
 *		{/menuItem}
 *  {/pageMenu}
 * </code>
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_block_menuItem($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('menuCaption');
        $smarty->clear_assign('menuAction');
        $smarty->clear_assign('menuPageAction');
    } else {
        $item = new HtmlElement('a');
        if ($smarty->getTemplateVars('menuAction')) {
            $href = $smarty->getTemplateVars('menuAction');
        } else {
            if ($smarty->getTemplateVars('menuPageAction')) {
                $onClick = $smarty->getTemplateVars('menuPageAction');
                $href = '#';
                $item->setAttribute('onClick', $onClick . '; return false;');
            }
        }
        $item->setAttribute('href', $href);
        // EXPERIMENTAL - set access key for menu item
        $caption = $smarty->getTemplateVars('menuCaption');
        if (FALSE != strpos($caption, '&&')) {
            $p = strpos($caption, '&&');
            $accessKey = substr($caption, $p + 2, 1);
            $item->setAttribute('accessKey', $accessKey);
            $caption = substr($caption, 0, $p + 3) . '</span>' . substr($caption, $p + 3);
            $caption = substr($caption, 0, $p) . '<span class="accessKey">' . substr($caption, $p + 2);
        }
        $item->setContent($caption);
        $smarty->append('pageMenuItems', $item->render());
    }
}
Пример #12
0
/**
 * 生成当前请求唯一的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__"]);
}
Пример #13
0
/**
 * 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;
}
Пример #14
0
/**
 *
 * @package application.helper.smarty.form
 * @author Integry Systems
 */
function smarty_function_metricsfield($params, Smarty_Internal_Template $smarty)
{
    if (empty($params['name'])) {
        $params['name'] = $smarty->getTemplateVars('input_name');
    }
    $formParams = $smarty->_tag_stack[0][1];
    $formHandler = $formParams['handle'];
    if (!isset($params['value']) && !$formHandler instanceof Form) {
        throw new HelperException('Element must be placed in {form} block');
    }
    if (!empty($formParams['model'])) {
        $params['ng-model'] = $formParams['model'] . '.' . $params['name'];
    }
    $application = $smarty->getApplication();
    $params['m_sw'] = $application->translate('_switch_to_english_units');
    $params['en_sw'] = $application->translate('_switch_to_metric_units');
    $params['m_hi'] = $application->translate('_units_kg');
    $params['m_lo'] = $application->translate('_units_g');
    $params['en_hi'] = $application->translate('_units_lbs');
    $params['en_lo'] = $application->translate('_units_oz');
    $params['type'] = strtolower($application->getConfig()->get('UNIT_SYSTEM'));
    $content = '<weight-input ' . $smarty->appendParams($content, $params) . '></weight-input>';
    $content = $smarty->formatControl($content, $params);
    return $content;
}
    function content_56ee2ea61703d4_35460691(Smarty_Internal_Template $_smarty_tpl)
    {
        ?>
<section class="content-header">
    <h1>
        Data Jabatan
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-database"></i> Master</a></li>
        <li><a href="#">Jabatan</a></li>
        <li class="active">Tambah Data</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- notification template -->
            <?php 
        $_smarty_tpl->_subTemplateRender("file:base/templates/notification.html", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, false);
        ?>

            <!-- end of notification template-->
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">Tambah Data jabatan</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form action="<?php 
        echo $_smarty_tpl->tpl_vars['config']->value->site_url('master/jabatan/add_process');
        ?>
" method="post" class="form-horizontal">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="nama_jabatan" class="col-sm-2 control-label">Nama jabatan</label>
                            <div class="col-sm-5">
                                <input type="text" name="nama_jabatan" class="form-control" id="nama_jabatan" placeholder="nama jabatan" value="<?php 
        echo ($tmp = @$_smarty_tpl->tpl_vars['result']->value['nama_jabatan']) === null || $tmp === '' ? '' : $tmp;
        ?>
">
                            </div>
                        </div>

                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <a class="btn btn-default" href="<?php 
        echo $_smarty_tpl->tpl_vars['config']->value->site_url('master/jabatan/');
        ?>
"><i class="fa fa-long-arrow-left"></i>&nbsp; Batal</a>
                        <button type="submit" class="btn btn-info pull-right">Simpan</button>
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </div>
</section>
<?php 
    }
Пример #16
0
function smarty_function_header($p, Smarty_Internal_Template $template)
{
    $tpl = $template->smarty;
    if (isset($p['title'])) {
        $tpl->data['title'] = $p['title'];
    }
    if (isset($p['keywords'])) {
        $tpl->data['keywords'] = $p['keywords'];
    }
    if (isset($p['description'])) {
        $tpl->data['description'] = $p['description'];
    }
    if (isset($p['creator'])) {
        $tpl->data['creator'] = $p['creator'];
    }
    if (isset($p['subject'])) {
        $tpl->data['subject'] = $p['subject'];
    }
    $vars = array();
    foreach ($p as $key => $val) {
        if ($key == 'title' || $key == 'file' || $key == 'keywords' || $key == 'description' || $key == 'creator' || $key == 'subject') {
            continue;
        }
        $vars[$key] = $val;
    }
    return $template->getSubTemplate(isset($p['file']) ? $p['file'] : "header.tpl", $template->cache_id, $template->compile_id, null, null, $vars, 0);
}
/**
 * @param array                    $params
 * @param Smarty_Internal_Template $smarty
 *
 * @throws SmartyException
 *
 * @author Kovács Vince
 */
function smarty_function_datatable_column($params, Smarty_Internal_Template &$smarty)
{
    if (!class_exists('Datatable')) {
        throw new SmartyException('chumper/datatable not installed');
    }
    if (!isset($params['label']) && !isset($params['token'])) {
        throw new SmartyException('Missing label or token attribute for datatable_column tag');
    }
    $tables = $smarty->getVariable('datatables')->value;
    $table = end($tables);
    $table->addColumn(isset($params['label']) ? $params['label'] : Lang::get($params['token']));
    $options = array();
    if (isset($params['sortable'])) {
        $options['sortable'] = (bool) $params['sortable'];
    }
    if (isset($params['orderable'])) {
        $options['orderable'] = (bool) $params['orderable'];
    }
    if (isset($params['width'])) {
        $options['width'] = $params['width'];
    }
    if (isset($params['class'])) {
        $options['className'] = $params['class'];
    }
    if (isset($params['type']) && in_array($params['type'], array('html', 'string', 'numeric', 'date'))) {
        $options['cellType'] = $params['type'];
    }
    $tableOptions = $table->getOptions();
    $tableOptions['columns'][] = count($options) == 0 ? null : $options;
    $table->setOptions($tableOptions);
}
 /**
  * Return array of tag/attributes of all tags used by an template
  *
  * @api  Smarty::getTags()
  * @link http://www.smarty.net/docs/en/api.get.tags.tpl
  *
  * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  * @param null|string|Smarty_Internal_Template                            $template
  *
  * @return array of tag/attributes
  * @throws \SmartyException
  */
 public function getTags(Smarty_Internal_TemplateBase $obj, $template = null)
 {
     /* @var Smarty $smarty */
     $smarty = $obj->_getSmartyObj();
     if ($obj->_isTplObj() && !isset($template)) {
         $tpl = clone $obj;
     } elseif (isset($template) && $template->_isTplObj()) {
         $tpl = clone $template;
     } elseif (isset($template) && is_string($template)) {
         /* @var Smarty_Internal_Template $tpl */
         $tpl = new $smarty->template_class($template, $smarty);
         // checks if template exists
         if (!$tpl->source->exists) {
             throw new SmartyException("Unable to load template {$tpl->source->type} '{$tpl->source->name}'");
         }
     }
     if (isset($tpl)) {
         $tpl->smarty = clone $tpl->smarty;
         $tpl->smarty->_cache['get_used_tags'] = true;
         $tpl->_cache['used_tags'] = array();
         $tpl->smarty->merge_compiled_includes = false;
         $tpl->smarty->disableSecurity();
         $tpl->caching = false;
         $tpl->loadCompiler();
         $tpl->compiler->compileTemplate($tpl);
         return $tpl->_cache['used_tags'];
     }
     throw new SmartyException("Missing template specification");
 }
Пример #19
0
 public function setUp()
 {
     $smarty = new Smarty();
     $render = new CM_Frontend_Render();
     $this->_template = $smarty->createTemplate('string:');
     $this->_template->assignGlobal('render', $render);
 }
Пример #20
0
/**
 * 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;
}
Пример #21
0
/**
 * Renders and displays a page content block
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_renderBlock($params, Smarty_Internal_Template $smarty)
{
    $block = $params['block'];
    if (substr($block, -1) == '}') {
        $block = substr($block, 0, -1);
    }
    return $smarty->getApplication()->getBlockContent($block, $params);
}
Пример #22
0
/**
 * Generates user form URL in backend
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_backendUserUrl($params, Smarty_Internal_Template $smarty)
{
    if (!isset($params['user']) && isset($params['id'])) {
        $params['user'] = array('ID' => $params['id']);
    }
    $urlParams = array('controller' => 'backend.userGroup', 'action' => 'index');
    return $smarty->getApplication()->getRouter()->createUrl($urlParams, true) . '#user_' . (isset($params['user']) ? $params['user']['ID'] : '');
}
Пример #23
0
 public function setUp()
 {
     $smarty = new Smarty();
     $render = new CM_Frontend_Render();
     $this->_template = $smarty->createTemplate('string:');
     $this->_template->assignGlobal('render', $render);
     $this->_menuData = [['label' => 'Label 1', 'page' => 'CM_Page_Example', 'params' => ['foo' => 1]], ['label' => 'Label 2', 'page' => 'CM_Page_Example', 'params' => ['foo' => 2]]];
 }
/**
 * @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();
}
Пример #25
0
/**
 * 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);
    }
}
Пример #26
0
/**
 * Generates order form URL in backend
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_backendOrderUrl($params, Smarty_Internal_Template $smarty)
{
    $urlParams = array('controller' => 'backend.customerOrder', 'action' => 'index');
    $url = $smarty->getApplication()->getRouter()->createUrl($urlParams, true) . '#order_' . (isset($params['order']) ? $params['order']['ID'] . '#tabOrderInfo__' : '');
    if (isset($params['url'])) {
        $url = $smarty->getApplication()->getRouter()->createFullUrl($url);
    }
    return $url;
}
Пример #27
0
/**
 * Generates product form URL in backend
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_backendProductUrl($params, Smarty_Internal_Template $smarty)
{
    if (!isset($params['product']) && isset($params['id'])) {
        $params['product'] = array('ID' => $params['id']);
    }
    $product = $params['product'];
    $urlParams = array('controller' => 'backend.category', 'action' => 'index');
    return $smarty->getApplication()->getRouter()->createUrl($urlParams, true) . '#product_' . (!empty($product['Parent']['ID']) ? $product['Parent']['ID'] : $product['ID']);
}
Пример #28
0
/**
 * 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));
        }
    }
}
Пример #29
0
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'];
    }
}
Пример #30
0
/**
 * Renders an input in smarty.
 *
 * @param string[] $params
 * @param Smarty_Internal_Template $template
 * @return string
 */
function smarty_function_input($params, Smarty_Internal_Template $template)
{
    $name = $params['name'];
    $form = $template->smarty->getForm("Form_" . $template->getTemplateVars("currentForm"));
    $element = $form->get($name);
    $view = $form->createView();
    $renderer = $template->getFormRenderer();
    $c = $renderer->renderInput($element, "Form_" . $template->getTemplateVars("currentForm"), $params);
    return $c;
}