/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_includeCss($params, LiveCartSmarty $smarty) { $fileName = $params['file']; $filePath = substr($fileName, 0, 1) != '/' ? ClassLoader::getRealPath('public.stylesheet.') . $fileName : ClassLoader::getRealPath('public') . $fileName; // fix slashes $filePath = str_replace('\\', DIRECTORY_SEPARATOR, $filePath); $filePath = str_replace('/', DIRECTORY_SEPARATOR, $filePath); if (!is_file($filePath) && !isset($params['external']) || substr($filePath, -4) != '.css') { return; } $css = CssFile::getInstanceFromPath($filePath, $smarty->getApplication()->getTheme()); $origFileName = $fileName; if ($css->isPatched()) { $filePath = $css->getPatchedFilePath(); $fileName = $css->getPatchedFileRelativePath(); } if (isset($params['inline']) && $params['inline'] == 'true') { $path = 'stylesheet/' . str_replace(DIRECTORY_SEPARATOR, '/', $fileName) . '?' . filemtime($filePath); return '<link href="' . $path . '" media="screen" rel="Stylesheet" type="text/css" />' . "\n"; } else { if (isset($params['external'])) { $smarty->_smarty_vars['INCLUDED_STYLESHEET_FILES_EXTERNAL'][] = $fileName; } else { $includedStylesheetTimestamp = $smarty->_smarty_vars['INCLUDED_STYLESHEET_TIMESTAMP']; if (!($includedStylesheetFiles = $smarty->_smarty_vars['INCLUDED_STYLESHEET_FILES'])) { $includedStylesheetFiles = array(); } if (in_array($filePath, $includedStylesheetFiles)) { if (isset($params['front'])) { unset($includedStylesheetFiles[array_search($filePath, $includedStylesheetFiles)]); } else { return; } } $fileMTime = filemtime($filePath); if ($fileMTime > (int) $includedStylesheetTimestamp) { $smarty->_smarty_vars['INCLUDED_STYLESHEET_TIMESTAMP'] = $fileMTime; } if (isset($params['front'])) { array_unshift($includedStylesheetFiles, $filePath); } else { if (isset($params['last'])) { $includedStylesheetFiles['x' . (count($includedStylesheetFiles) + 200) * (int) $params['last']] = $filePath; } else { array_push($includedStylesheetFiles, $filePath); } } $smarty->_smarty_vars['INCLUDED_STYLESHEET_FILES'] = $includedStylesheetFiles; } } foreach ($smarty->getApplication()->getConfigContainer()->getFilesByRelativePath('public/stylesheet/' . $origFileName, true) as $file) { if (realpath($file) == realpath($filePath)) { continue; } $file = substr($file, strlen(ClassLoader::getRealPath('public'))); $params['file'] = $file; smarty_function_includeCss($params, $smarty); } }
/** * 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, LiveCartSmarty $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; }
/** * 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, LiveCartSmarty $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'); }
function smarty_custom_get_path($tpl_name, LiveCartSmarty $smarty) { $path = null; if ('@' != substr($tpl_name, 0, 1)) { $path = $smarty->getApplication()->getRenderer()->getTemplatePath($tpl_name); } else { $path = $smarty->getApplication()->getRenderer()->getBaseTemplatePath($tpl_name); } return $path; }
/** * Displays backend navigation menu * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_backendMenu($params, LiveCartSmarty $smarty) { $locale = $smarty->getApplication()->getLocale(); $controller = $smarty->_tpl_vars['request']['controller']; $action = $smarty->_tpl_vars['request']['action']; // load language file for menu $locale->translationManager()->loadFile('backend/menu'); $menuLoader = new MenuLoader($smarty->getApplication()); $structure = $menuLoader->getCurrentHierarchy($controller, $action); $router = $smarty->getApplication()->getRouter(); // get translations and generate URL's $items = array(); foreach ($structure['items'] as $topValue) { if (!empty($topValue['role']) && !AccessStringParser::run($topValue['role'])) { continue; } $filteredValue = array(); foreach (array('title', 'descr') as $field) { $filteredValue[$field] = $smarty->branding($locale->translator()->translate($topValue[$field])); } $filteredValue['controller'] = $topValue['controller']; $filteredValue['action'] = $topValue['action']; $filteredValue['icon'] = $topValue['icon']; if (!empty($topValue['controller'])) { $filteredValue['url'] = $router->createUrl(array('controller' => $topValue['controller'], 'action' => $topValue['action']), true); } if (is_array($topValue['items'])) { $subItems = array(); foreach ($topValue['items'] as &$subValue) { if (!empty($subValue['role']) && !AccessStringParser::run($subValue['role'])) { continue; } $filteredSubValue = array(); foreach (array('title', 'descr') as $field) { $filteredSubValue[$field] = $smarty->branding($locale->translator()->translate($subValue[$field])); } $filteredSubValue['url'] = $router->createUrl(array('controller' => $subValue['controller'], 'action' => $subValue['action']), true); $filteredSubValue['controller'] = $subValue['controller']; $filteredSubValue['action'] = $subValue['action']; $filteredSubValue['icon'] = $subValue['icon']; $subItems[] = $filteredSubValue; } if (count($subItems) > 0) { $filteredValue['items'] = $subItems; } } $items[] = $filteredValue; } $smarty->assign('menuArray', json_encode($items)); $smarty->assign('controller', $controller); $smarty->assign('action', $action); return $smarty->display('block/backend/backendMenu.tpl'); }
/** * Tab container * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_tabControl($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { if (empty($params['noHidden'])) { $more = '<li class="moreTabs"> <a href="#" class="moreTabsLink"><span class="downArrow">▾ </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">' . $more . $content . '</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; } }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_compiledJs($params, LiveCartSmarty $smarty) { $includedJavascriptTimestamp = $smarty->_smarty_vars["INCLUDED_JAVASCRIPT_TIMESTAMP"]; $includedJavascriptFiles = $smarty->_smarty_vars["INCLUDED_JAVASCRIPT_FILES"]; if ($includedJavascriptFiles && isset($params['glue']) && $params['glue'] == 'true' && !$smarty->getApplication()->isDevMode() && !$smarty->getApplication()->isTemplateCustomizationMode()) { $request = $smarty->getApplication()->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="gzip.php?file=' . $compiledFileName . '&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="' . $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, LiveCartSmarty $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/scriptaculous/scriptaculous.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, LiveCartSmarty $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, LiveCartSmarty $smarty) { $content = ''; $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'); } $fieldName = $params['name']; unset($params['name']); $application = $smarty->getApplication(); if (!isset($params['class'])) { $params['class'] = ''; } $hideSwitch = false; if (isset($params['hideSwitch'])) { unset($params['hideSwitch']); $hideSwitch = true; } $rootID = 'UnitConventer_Root_' . (isset($params['id']) ? $params['id'] : 'inc_' . rand(1, 10000000) . '_' . rand(1, 10000000)); $content .= '<fieldset id="' . $rootID . '" class="error UnitConventer_Root">'; $content .= ' <span style="display: none">'; $content .= ' <span class="UnitConventer_SwitcgToEnglishTitle">' . $application->translate('_switch_to_english_units') . '</span>'; $content .= ' <span class="UnitConventer_SwitcgToMetricTitle">' . $application->translate('_switch_to_metric_units') . '</span>'; $content .= ' <span class="UnitConventer_MetricHiUnit">' . $application->translate('_units_kg') . '</span>'; $content .= ' <span class="UnitConventer_MetricLoUnit">' . $application->translate('_units_g') . '</span>'; $content .= ' <span class="UnitConventer_EnglishHiUnit">' . $application->translate('_units_pounds') . '</span>'; $content .= ' <span class="UnitConventer_EnglishLoUnit">' . $application->translate('_units_ounces') . '</span>'; $content .= ' </span>'; $content .= '<input type="hidden" name="' . $fieldName . '" value="' . (isset($params['value']) ? $params['value'] : $formHandler->get($fieldName)) . '" class="UnitConventer_NormalizedWeight" />'; $content .= '<input type="hidden" class="UnitConventer_UnitsType" value="' . $application->getConfig()->get('UNIT_SYSTEM') . '" />'; unset($params['value']); // Hi value $hiParams = $params; $hiParams['class'] .= ' number UnitConventer_HiValue'; if ($hiParams['id']) { $hiParams['id'] = $hiParams['id'] . '_HiValue'; } $content .= '<input type="text"'; foreach ($hiParams as $name => $value) { $content .= ' ' . $name . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; } $content .= ' />'; // Lo value $loParams = $params; $loParams['class'] .= ' number UnitConventer_LoValue'; if ($hiParams['id']) { $loParams['id'] = $loParams['id'] . '_HiValue'; } $content .= '<input type="text"'; foreach ($loParams as $name => $value) { $content .= ' ' . $name . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; } $content .= ' />'; $content .= '<div class="errorText hidden"></div>'; $content .= ' <a href="#" class="UnitConventer_SwitchUnits" ' . ($hideSwitch ? 'style="display: none;"' : '') . '>' . $application->translate($application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH' ? '_switch_to_english_units' : '_switch_to_metric_units') . '</a>'; $content .= ' <script type="text/javascript">Backend.UnitConventer.prototype.getInstance("' . $rootID . '");</script>'; $content .= '</fieldset >'; 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, LiveCartSmarty $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'] : ''); }
/** * Generates pagination block * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_paginate($params, LiveCartSmarty $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, LiveCartSmarty $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']); }
/** * Generates static page URL * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_pageUrl($params, LiveCartSmarty $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); }
/** * 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, LiveCartSmarty $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; }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_toolTip($params, LiveCartSmarty $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>'; }
/** * Language forms * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_language($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$smarty->getApplication()->getLanguageSetArray()) { return false; } if ($repeat) { $smarty->languageBlock = $smarty->getApplication()->getLanguageSetArray(); $smarty->assign('languageBlock', $smarty->languageBlock); $smarty->assign('lang', array_shift($smarty->languageBlock)); $smarty->langHeadDisplayed = false; $user = SessionUser::getUser(); foreach ($smarty->getApplication()->getLanguageSetArray() as $lang) { $userPref = $user->getPreference('tab_lang_' . $lang['ID']); $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false'; $classNames[$lang['ID']] = $isHidden ? 'hidden' : ''; } $smarty->langClassNames = $classNames; } else { if (!trim($content)) { $repeat = false; return false; } if ($smarty->languageBlock) { $repeat = true; } $contentLang = $smarty->get_template_vars('lang'); $content = '<div class="languageFormContainer languageFormContainer_' . $contentLang['ID'] . ' ' . $smarty->langClassNames[$contentLang['ID']] . '">' . $content . '</div>'; if (!$smarty->langHeadDisplayed) { $smarty->assign('langFormId', 'langForm_' . uniqid()); $smarty->assign('classNames', $smarty->langClassNames); $content = $smarty->fetch('block/backend/langFormHead.tpl') . $content; $smarty->langHeadDisplayed = true; } $smarty->assign('lang', array_shift($smarty->languageBlock)); // form footer if (!$repeat) { $content .= $smarty->fetch('block/backend/langFormFoot.tpl'); } return $content; } }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_weight($params, LiveCartSmarty $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); }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_includeJs($params, LiveCartSmarty $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->_smarty_vars["INCLUDED_JAVASCRIPT_TIMESTAMP"]; if (!($includedJavascriptFiles = $smarty->_smarty_vars['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->_smarty_vars['INCLUDED_JAVASCRIPT_TIMESTAMP'] = $fileMTime; } if (isset($params['front'])) { $includedJavascriptFiles = array_merge(array($filePath => $fileName), $includedJavascriptFiles); } else { $includedJavascriptFiles[$filePath] = $fileName; } $smarty->_smarty_vars['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); } }
/** * Displays ActiveGrid table * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_activeGrid($params, LiveCartSmarty $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'); }
/** * 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, LiveCartSmarty $smarty) { $router = $smarty->getApplication()->getRouter(); // should full URL be generated? if (isset($params['url'])) { unset($params['url']); $fullUrl = true; } else { $fullUrl = false; } // replace & with & if (isset($params['nohtml'])) { unset($params['nohtml']); $router->setVariableSeparator('&'); } else { $router->setVariableSeparator('&'); } $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'], true); } else { unset($params['route']); $result = $router->createURL($params, true); } } catch (RouterException $e) { return "INVALID_LINK"; } } if ($fullUrl) { $result = $router->createFullUrl($result); } return $result; }
/** * 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, LiveCartSmarty $smarty) { $app = $smarty->getApplication(); $blocks = explode(' ', trim(preg_replace('/\\s+/', ' ', $params['blocks']))); $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; }
/** * 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, LiveCartSmarty $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; }
/** * 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, LiveCartSmarty $smarty) { $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'; } // Check permissions if ($formParams['readonly']) { $params['readonly'] = 'readonly'; } $value = array_pop(array_filter(array($params['value'], $params['default'], $formHandler->get($fieldName)))); unset($params['value'], $params['default']); $content = '<input'; foreach ($params as $name => $param) { $content .= ' ' . $name . '="' . $param . '"'; } $content .= ' value="' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '"'; $content .= '/>'; if (isset($params['autocomplete']) && $params['autocomplete'] != 'off') { $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); $content .= '<span id="autocomplete_indicator_' . $params['id'] . '" class="progressIndicator" style="display: none;"></span>'; $content .= '<div id="autocomplete_' . $params['id'] . '" class="autocomplete"></div>'; $content .= '<script type="text/javascript"> new Ajax.Autocompleter("' . $params['id'] . '", "autocomplete_' . $params['id'] . '", "' . $url . '", {frequency: 0.5, paramName: "' . $acparams['field'] . '", indicator: "autocomplete_indicator_' . $params['id'] . '"}); </script>'; } return $content; }
/** * Generates category page URL * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_categoryUrl($params, LiveCartSmarty $smarty) { return createCategoryUrl($params, $smarty->getApplication()); }
/** * Returns current locale code * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_localeCode($params, LiveCartSmarty $smarty) { return $smarty->getApplication()->getLocale()->getLocaleCode(); }
/** * 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, LiveCartSmarty $smarty) { return $smarty->getApplication()->getBlockContent($params['block']); }
/** * Generates news page URL * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_newsUrl($params, LiveCartSmarty $smarty) { return createNewsPostUrl($params, $smarty->getApplication()); }
/** * Returns current locale code * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_isRTL($params, LiveCartSmarty $smarty) { $locale = $smarty->getApplication()->getLocale()->getLocaleCode(); return in_array($locale, array('he', 'ar', 'fa')); }
/** * Inserts a base URL string * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_theme($params, LiveCartSmarty $smarty) { return $smarty->getApplication()->getTheme(); }