/**
 * 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');
}
/**
 * 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;
}
Example #3
0
/**
 * Tab container
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_tabControl($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        if (empty($params['noHidden'])) {
            $more = '<li class="moreTabs">
						<a href="#" class="moreTabsLink"><span class="downArrow">&#9662; </span><span>' . strtolower($smarty->getApplication()->translate('_more_tabs')) . '</span></a>
						<div class="moreTabsMenu" style="display: none;"></div>
					</li>';
        }
        $content = '<ul id="' . $params['id'] . '" class="tabList tabs ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">' . $content . $more . '</ul>';
        $content .= '<script type="text/javascript">var tabCust = new TabCustomize($("' . $params['id'] . '")); tabCust.setPrefsSaveUrl("' . $smarty->getApplication()->getRouter()->createUrl(array('controller' => 'backend.index', 'action' => 'setUserPreference')) . '")</script>';
        return $content;
    }
}
Example #4
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_compiledJs($params, Smarty_Internal_Template $smarty)
{
    $includedJavascriptTimestamp = $smarty->getGlobal("INCLUDED_JAVASCRIPT_TIMESTAMP");
    $includedJavascriptFiles = $smarty->getGlobal("INCLUDED_JAVASCRIPT_FILES");
    $app = $smarty->getApplication();
    if ($includedJavascriptFiles && isset($params['glue']) && $params['glue'] == 'true' && !$smarty->getApplication()->isDevMode() && !$smarty->getApplication()->isTemplateCustomizationMode()) {
        $request = $app->getRequest();
        if (isset($params['nameMethod']) && 'hash' == $params['nameMethod']) {
            $names = array_keys($includedJavascriptFiles);
            sort($names);
            $compiledFileName = md5(implode("\n", $names)) . '.js';
        } else {
            $compiledFileName = $request->getControllerName() . '-' . $request->getActionName() . '.js';
        }
        $compiledFilePath = ClassLoader::getRealPath('public.cache.javascript.') . $compiledFileName;
        $baseDir = ClassLoader::getRealPath('public.javascript.');
        $compiledFileTimestamp = 0;
        if (!is_file($compiledFilePath) || filemtime($compiledFilePath) < $includedJavascriptTimestamp) {
            if (!is_dir(ClassLoader::getRealPath('public.cache.javascript'))) {
                mkdir(ClassLoader::getRealPath('public.cache.javascript'), 0777, true);
            }
            // compile
            $compiledFileContent = "";
            $compiledFilesList = array();
            foreach ($includedJavascriptFiles as $jsFile => $fileName) {
                $compiledFileContent .= "\n\n\n/***************************************************\n";
                $compiledFileContent .= " * " . str_replace($baseDir, '', $jsFile) . "\n";
                $compiledFileContent .= " ***************************************************/\n\n";
                $compiledFileContent .= file_get_contents($jsFile);
                $compiledFilesList[] = basename($jsFile);
            }
            file_put_contents($compiledFilePath, $compiledFileContent);
            if (function_exists('gzencode')) {
                file_put_contents($compiledFilePath . '.gz', gzencode($compiledFileContent, 9));
            }
        }
        $compiledFileTimestamp = filemtime($compiledFilePath);
        return '<script src="' . $app->getPublicUrl('gzip.php') . '?file=' . $compiledFileName . '&amp;time=' . $compiledFileTimestamp . '" type="text/javascript"></script>';
    } else {
        if ($includedJavascriptFiles) {
            $includeString = "";
            $publicPath = ClassLoader::getRealPath('public.');
            foreach ($includedJavascriptFiles as $path => $jsFile) {
                $urlPath = str_replace('\\', '/', str_replace($publicPath, '', $jsFile));
                $includeString .= '<script src="' . $app->getPublicUrl($urlPath) . '?' . filemtime($path) . '" type="text/javascript"></script>' . "\n";
            }
            return $includeString;
        }
    }
}
/**
 * ...
 *
 * @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');
                }
            }
        }
    }
}
/**
 * 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());
}
/**
 *
 * @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;
}
/**
 * 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'] : '');
}
Example #9
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);
}
Example #10
0
/**
 * 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);
}
/**
 * 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']);
}
Example #12
0
/**
 * Generates static page URL
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_pageUrl($params, Smarty_Internal_Template $smarty)
{
    if (!class_exists('StaticPage', false)) {
        ClassLoader::import('application.model.staticpage.StaticPage');
    }
    if (isset($params['id'])) {
        $params['data'] = StaticPage::getInstanceById($params['id'], StaticPage::LOAD_DATA)->toArray();
    }
    $urlParams = array('controller' => 'staticPage', 'action' => 'view', 'handle' => $params['data']['handle']);
    return $smarty->getApplication()->getRouter()->createUrl($urlParams, true);
}
Example #13
0
/**
 * Creates more complex translation strings that depend on and include numeric variables
 *
 * <code>
 *	  {maketext text="There are [quant,_1,item,items,no items] in your shopping basket." params=$cnt}
 *	  {maketext text="Displaying [_1] to [_2] of [_3] found orders." params=$from,$to,$count}
 * </code>
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_maketext($params, Smarty_Internal_Template $smarty)
{
    $application = $smarty->getApplication();
    $translation = $application->makeText($params['text'], explode(',', $params['params']));
    if ($application->isTranslationMode() && !isset($params['disableLiveTranslation'])) {
        $file = $application->getLocale()->translationManager()->getFileByDefKey($params['text']);
        $file = '__file_' . base64_encode($file);
        $translation = '<span class="transMode __trans_' . $params['text'] . ' ' . $file . '">' . $translation . '</span>';
    }
    return $translation;
}
Example #14
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_toolTip($params, Smarty_Internal_Template $smarty)
{
    $tip = $params['label'];
    $hint = !empty($params['hint']) ? $params['hint'] : '_tip' . $tip;
    $app = $smarty->getApplication();
    $json = json_encode($app->translate($hint));
    $json = str_replace('<', '\\u003C', $json);
    $json = str_replace('>', '\\u003E', $json);
    $json = str_replace("'", '\\u0027', $json);
    return '<span class="acronym" onmouseover=\'tooltip.show(' . $json . ', 200);\' onmouseout="tooltip.hide();">' . $app->translate($tip) . '</span>';
}
Example #15
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_weight($params, Smarty_Internal_Template $smarty)
{
    if (!isset($params['value'])) {
        throw new ApplicationException("Please use 'value' attribute to specify weight");
    }
    $application = $smarty->getApplication();
    $units_hi = $application->translate($application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH' ? '_units_pounds' : '_units_kg');
    $units_lo = $application->translate($application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH' ? '_units_ounces' : '_units_g');
    $value_hi = (int) $params['value'];
    $value_lo = str_replace('0.', '', (string) ($params['value'] - (int) $params['value']));
    return sprintf("%s %s %s %s", $value_hi, $units_hi, $value_lo, $units_lo);
}
Example #16
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_includeJs($params, Smarty_Internal_Template $smarty)
{
    static $jsPath;
    if (!$jsPath) {
        $jsPath = ClassLoader::getRealPath('public.javascript.');
    }
    $fileName = $params['file'];
    $filePath = substr($fileName, 0, 1) != '/' ? $jsPath . $fileName : ClassLoader::getRealPath('public') . $fileName;
    $fileName = substr($fileName, 0, 1) != '/' ? 'javascript/' . $fileName : substr($fileName, 1);
    //  fix slashes
    $filePath = str_replace('\\', DIRECTORY_SEPARATOR, $filePath);
    $filePath = str_replace('/', DIRECTORY_SEPARATOR, $filePath);
    if (isset($params['path'])) {
        $filePath = $params['path'];
    }
    if (!is_file($filePath) || substr($filePath, -3) != '.js') {
        return;
    }
    if (isset($params['inline']) && $params['inline'] == 'true') {
        return '<script src="' . str_replace(DIRECTORY_SEPARATOR, '/', $fileName) . '?' . filemtime($filePath) . '" type="text/javascript"></script>' . "\n";
    } else {
        $includedJavascriptTimestamp = $smarty->getGlobal("INCLUDED_JAVASCRIPT_TIMESTAMP");
        if (!($includedJavascriptFiles = $smarty->getGlobal('INCLUDED_JAVASCRIPT_FILES'))) {
            $includedJavascriptFiles = array();
        }
        if (isset($includedJavascriptFiles[$filePath])) {
            if (!isset($params['front'])) {
                return false;
            } else {
                unset($includedJavascriptFiles[$filePath]);
            }
        }
        $fileMTime = filemtime($filePath);
        if ($fileMTime > (int) $includedJavascriptTimestamp) {
            $smarty->setGlobal('INCLUDED_JAVASCRIPT_TIMESTAMP', $fileMTime);
        }
        if (isset($params['front'])) {
            $includedJavascriptFiles = array_merge(array($filePath => $fileName), $includedJavascriptFiles);
        } else {
            $includedJavascriptFiles[$filePath] = $fileName;
        }
        $smarty->setGlobal('INCLUDED_JAVASCRIPT_FILES', $includedJavascriptFiles);
    }
    foreach ($smarty->getApplication()->getConfigContainer()->getFilesByRelativePath('public/' . $fileName, true) as $file) {
        if (realpath($file) == realpath($filePath)) {
            continue;
        }
        $file = substr($file, strlen(ClassLoader::getRealPath('public')));
        $params['file'] = $file;
        smarty_function_includeJs($params, $smarty);
    }
}
Example #17
0
/**
 * Cache control directives
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_cache($params, Smarty_Internal_Template $smarty)
{
    $renderer = $smarty->getApplication()->getRenderer();
    //$renderer->getCacheInstance()->setCacheVar($params['var'], $params['value']);
    /*if (!empty($params['final']))
    	{
    		if ($renderer->getCacheInstance()->isCached())
    		{
    			return $renderer->getCacheInstance()->getData();
    		}
    	}
    	*/
}
Example #18
0
 function smarty_function_link($params, Smarty_Internal_Template $template)
 {
     $application = $template->getApplication();
     if (!is_object($application)) {
         return '';
     }
     // extract controller as it must be checked in application to know what controller builds a link
     $controllername = $params['controller'];
     unset($params['controller']);
     if (empty($controllername) && isset($params['c'])) {
         $controllername = $params['c'];
         unset($params['c']);
     }
     return $application->makeUrl($controllername, $params);
 }
Example #19
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_img($params, Smarty_Internal_Template $smarty)
{
    if (isset($params['src']) && (substr($params['src'], 0, 6) == 'image/' || substr($params['src'], 0, 7) == 'upload/')) {
        if (is_file($params['src'])) {
            $imageTimestamp = @filemtime(ClassLoader::getRealPath('public.') . str_replace('/', DIRECTORY_SEPARATOR, $params['src']));
            $params['src'] = $smarty->getApplication()->getPublicUrl($params['src']);
            $params['src'] .= '?' . $imageTimestamp;
        }
    }
    $content = "<img ";
    foreach ($params as $name => $value) {
        $content .= $name . '="' . $value . '" ';
    }
    $content .= "/>";
    return $content;
}
Example #20
0
/**
 * 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');
}
Example #21
0
/**
 * Smarty helper function for creating hyperlinks in application.
 * As the format of application part addresing migth vary, links should be created
 * by using this helper method. When the addressing schema changes, all links
 * will be regenerated
 *
 * "query" is a special paramater, that will be appended to a generated link as "?query"
 * Example: {link controller=category action=remove id=33 query="language=$lang&returnto=someurl"}
 *
 * @param array $params List of parameters passed to a function
 * @param Smarty $smarty Smarty instance
 * @return string Smarty function resut (formatted link)
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_link($params, Smarty_Internal_Template $smarty)
{
    $router = $smarty->getApplication()->getRouter();
    // should full URL be generated?
    if (isset($params['url'])) {
        unset($params['url']);
        $fullUrl = true;
    } else {
        $fullUrl = false;
    }
    // replace & with &amp;
    if (isset($params['nohtml'])) {
        unset($params['nohtml']);
        $router->setVariableSeparator('&');
    } else {
        $router->setVariableSeparator('&amp;');
    }
    $queryParams = $params;
    unset($queryParams['route'], $queryParams['nohtml'], $queryParams['self'], $queryParams['controller'], $queryParams['action'], $queryParams['id'], $queryParams['query']);
    if (!isset($params['query'])) {
        $params['query'] = $queryParams;
    }
    if (isset($params['self'])) {
        $result = $_SERVER['REQUEST_URI'];
        foreach ($queryParams as $param => $value) {
            $result = $router->setUrlQueryParam($result, $param, $value);
        }
    } else {
        try {
            if (!empty($params['route'])) {
                $result = $router->createUrlFromRoute($params['route'], false);
            } else {
                unset($params['route']);
                $result = $router->createURL($params, false);
            }
        } catch (RouterException $e) {
            return "INVALID_LINK";
        }
    }
    if ($fullUrl) {
        $result = $router->createFullUrl($result);
    }
    return $result;
}
Example #22
0
/**
 * Translates interface text to current locale language
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_translate($params, Smarty_Internal_Template $smarty)
{
    $application = $smarty->getApplication();
    $key = trim($params['text']);
    $translation = $application->translate($key);
    $translation = preg_replace('/%([a-zA-Z]*)/e', 'smarty_replace_translation_var(\'\\1\', $smarty)', $translation);
    if (!empty($params['noDefault']) && $translation == $key) {
        return '';
    }
    if (!empty($params['eval'])) {
        $translation = $smarty->evalTpl($translation);
    }
    if ($application->isTranslationMode() && !isset($params['disableLiveTranslation']) && !$application->isBackend()) {
        $file = $application->getLocale()->translationManager()->getFileByDefKey($params['text']);
        $file = '__file_' . base64_encode($file);
        $translation = '<span class="transMode __trans_' . $params['text'] . ' ' . $file . '">' . $translation . '</span>';
    }
    return $translation;
}
Example #23
0
function smarty_function_t($params, Smarty_Internal_Template $template)
{
    $application = $template->getApplication();
    if (!is_object($application)) {
        return $key;
    }
    // OLD VERSION. for back compability
    if (!isset($params['k']) && !isset($params['key'])) {
        if (isset($params['_'])) {
            $params['k'] = $params['_'];
        } elseif (isset($params['__'])) {
            $params['k'] = $params['_'];
        }
    }
    for ($i = 1; $i <= 5; $i++) {
        if (isset($params['t' . $i]) && !isset($params['p' . $i])) {
            $params['p' . $i] = $params['t' . $i];
        }
    }
    // END old version
    $key = isset($params['key']) ? $params['key'] : $params['k'];
    $group = isset($params['group']) ? $params['group'] : $params['g'];
    return $application->getText($key, $group, $params['p1'], $params['p2'], $params['p3'], $params['p4'], $params['p5']);
}
Example #24
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_blocks($params, Smarty_Internal_Template $smarty)
{
    $app = $smarty->getApplication();
    $blocks = explode(' ', trim(preg_replace('/\\s+/', ' ', $params['blocks'])));
    foreach ($blocks as $key => $value) {
        if (substr($value, 0, 2) == '//') {
            unset($blocks[$key]);
        }
    }
    $blocks = $app->getRenderer()->sortBlocks($blocks);
    $out = array();
    foreach ($blocks as $block) {
        $out[$block] = $app->getBlockContent($block);
    }
    $content = implode("\n", $out);
    if (!empty($params['id'])) {
        $smarty->set('CONTENT', $content);
        $parent = $app->getBlockContent($params['id']);
        if ($parent) {
            $content = $parent;
        }
    }
    return $content;
}
Example #25
0
/**
 * Returns current locale code
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_isRTL($params, Smarty_Internal_Template $smarty)
{
    $locale = $smarty->getApplication()->getLocale()->getLocaleCode();
    return in_array($locale, array('he', 'ar', 'fa'));
}
Example #26
0
/**
 * Generates category page URL
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_categoryUrl($params, Smarty_Internal_Template $smarty)
{
    return createCategoryUrl($params, $smarty->getApplication());
}
Example #27
0
/**
 * Renders text field
 *
 * If you wish to use autocomplete on a text field an additional parameter needs to be passed:
 *
 * <code>
 *	  autocomplete="controller=somecontroller field=fieldname"
 * </code>
 *
 * The controller needs to implement an autoComplete method, which must return the AutoCompleteResponse
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty.form
 * @author Integry Systems
 */
function smarty_function_textfield($params, Smarty_Internal_Template $smarty)
{
    if (empty($params['name'])) {
        $params['name'] = $smarty->getTemplateVars('input_name');
    }
    $smarty->assign('last_fieldType', 'textfield');
    $formParams = $smarty->_tag_stack[0][1];
    $formHandler = $formParams['handle'];
    $fieldName = $params['name'];
    if (!$formHandler instanceof Form) {
        throw new HelperException('Element must be placed in {form} block');
    }
    if (!isset($params['type'])) {
        $params['type'] = 'text';
    }
    if (isset($params['ng_model'])) {
        $params['ng-model'] = $params['ng_model'];
        unset($params['ng_model']);
    } else {
        if (!empty($formParams['model'])) {
            $params['ng-model'] = $formParams['model'] . '.' . $params['name'];
        }
    }
    $params = $smarty->applyFieldValidation($params, $formHandler);
    // Check permissions
    if ($formParams['readonly']) {
        $params['readonly'] = 'readonly';
    }
    $value = array_pop(array_filter(array(isset($params['value']) ? $params['value'] : '', isset($params['default']) ? $params['default'] : '', $formHandler->get($fieldName))));
    unset($params['value'], $params['default']);
    if (isset($params['autocomplete']) && $params['autocomplete'] != 'off' && empty($params['id'])) {
        $params['id'] = uniqid();
    }
    if (!empty($params['placeholder'])) {
        $params['placeholder'] = $smarty->getApplication()->translate($params['placeholder']);
    }
    if (isset($params['autocomplete']) && $params['autocomplete'] != 'off') {
        $autocomplete = $params['autocomplete'];
        $params['autocomplete'] = 'off';
    }
    $content = '<input';
    $content = $smarty->appendParams($content, $params);
    $content .= ' value="' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '"';
    $content .= '/>';
    $content = $smarty->formatControl($content, $params);
    if (!empty($autocomplete)) {
        $acparams = array();
        foreach (explode(' ', $params['autocomplete']) as $param) {
            list($p, $v) = explode('=', $param, 2);
            $acparams[$p] = $v;
        }
        $url = $smarty->getApplication()->getRouter()->createURL(array('controller' => $acparams['controller'], 'action' => 'autoComplete', 'query' => 'field=' . $acparams['field']), true);
        if (empty($acparams['field'])) {
            $acparams['field'] = 'query';
        }
        /*
        $content .= '<script type="text/javascript">
        				jQuery("#' . $params['id'] . '").typeahead({
        						source: function (query, process) {
        							return jQuery.get("' . $url . '", { ' . $acparams['field'] . ': query }, function (data) {
        								return process(jQuery.parseJSON(data));
        							});
        						}});
        			</script>';
        */
    }
    return $content;
}
Example #28
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_static($params, Smarty_Internal_Template $smarty)
{
    return $smarty->getApplication()->getPublicUrl(array_pop($params));
}
Example #29
0
/**
 * Generates news page URL
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_newsUrl($params, Smarty_Internal_Template $smarty)
{
    return createNewsPostUrl($params, $smarty->getApplication());
}
function smarty_function_pagination($params, Smarty_Internal_Template $template)
{
    if ($params['fast'] == 'y') {
        $totalcount = $params['data']['count'];
        $start = $params['data']['offset'];
        $limit = $params['data']['limit'];
        $link = $params['data']['link'];
        $showinfo = true;
    } else {
        $totalcount = $params['total'];
        $start = $params['start'];
        $limit = $params['limit'];
        $link = $params['link'];
        $showinfo = $params['infobar'];
    }
    $application = $template->getApplication();
    if (!is_object($application)) {
        return '';
    }
    $countofpages = 0;
    if ($totalcount >= 1 && $limit >= 1) {
        $countofpages = ceil($totalcount / $limit);
    }
    $pagenum = 1;
    if ($limit > 0) {
        $pagenum = round($start / $limit) + 1;
    }
    $linkprefix = '&';
    if (strpos($link, '?') === false) {
        $linkprefix = '?';
    } elseif (substr($link, -1) == '&') {
        $linkprefix = '';
    }
    $link .= $linkprefix;
    $getOffset = function ($pagenum, $limit, $total) {
        $offset = ($pagenum - 1) * $limit;
        if ($offset >= $total) {
            $offset = $total;
        }
        return $offset;
    };
    $str = '<nav><ul class="pagination">';
    if ($limit > 0 && $countofpages > 1) {
        // show count of pages
        if ($showinfo) {
            $str .= '<li class="disabled"><span aria-hidden="true">' . ($getOffset($pagenum, $limit, $totalcount) + 1) . '-' . $getOffset($pagenum + 1, $limit, $totalcount) . ' ' . $application->getText('from') . ' ' . $totalcount . '</span></li>';
        }
        // first and previous
        $linkstatus = $pagenum == 1 ? 'disabled' : '';
        $str .= '<li class="' . $linkstatus . '">' . '<a href="' . $link . 'start=0&limit=' . $limit . '" aria-label="' . $application->getText('First') . '">' . '<span aria-hidden="true">&laquo;</span></a></li>';
        $str .= '<li class="' . $linkstatus . '">' . '<a href="' . $link . 'start=' . $getOffset($pagenum - 1, $limit, $totalcount) . '&limit=' . $limit . '" aria-label="' . $application->getText('Previous') . '">' . '<span aria-hidden="true">&lt;</span></a></li>';
        $show_number = $pagenum - 5;
        $show_number2 = $pagenum + 5;
        if ($show_number < 1) {
            $show_number = 1;
        }
        if ($show_number2 > $countofpages) {
            $show_number2 = $countofpages;
        }
        for ($i = $show_number; $i <= $show_number2; $i++) {
            if ($i != $pagenum) {
                $str .= '<li><a href="' . $link . 'start=' . $getOffset($i, $limit, $totalcount) . '&limit=' . $limit . '">' . $i . '</a></li>';
            } else {
                $str .= '<li class="active"><a href="#">' . $i . '<span class="sr-only">(current)</span></a></li>';
            }
        }
        $linkstatus = $pagenum == $countofpages ? 'disabled' : '';
        $str .= '<li class="' . $linkstatus . '">' . '<a href="' . $link . 'start=' . $getOffset($pagenum + 1, $limit, $totalcount) . '&limit=' . $limit . '" aria-label="' . $application->getText('Next') . '">' . '<span aria-hidden="true">&gt;</span></a></li>';
        $str .= '<li class="' . $linkstatus . '">' . '<a href="' . $link . 'start=' . $getOffset($countofpages, $limit, $totalcount) . '&limit=' . $limit . '" aria-label=' . $application->getText('Last') . '">' . '<span aria-hidden="true">&raquo;</span></a></li>';
    }
    $str .= "</ul></nav>";
    return $str;
}