/** * ... * * @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'); } } } } }
/** * 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'); }
/** * 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'); }
/** * Set page title * * @package application.helper.smarty * @author Integry Systems */ function smarty_block_pageTitle($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { $smarty->assign('TITLE', strip_tags($content)); if (isset($params['help'])) { $content .= '<script type="text/javascript">Backend.setHelpContext("' . $params['help'] . '")</script>'; } $GLOBALS['PAGE_TITLE'] = $content; $smarty->assign('PAGE_TITLE', $content); $smarty->_smarty_vars['PAGE_TITLE'] = $content; } }
/** * Display a tip block * * @package application.helper.smarty * @author Integry Systems * * @package application.helper.smarty */ function smarty_block_tip($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { $smarty->assign('tipContent', $content); return $smarty->display('block/backend/tip.tpl'); } }
/** * 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'); }
/** * Set canonical URL * * @package application.helper.smarty * @author Integry Systems * @see http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html */ function smarty_block_canonical($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { /* $parsed = parse_url($content); if (!empty($parsed['query'])) { $pairs = array(); foreach (explode('&', $parsed['query']) as $pair) { $values = explode('=', $pair, 2); if (count($values) != 2) { continue; } $pairs[$values[0]] = $values[1]; } $pairs = array_diff_key($pairs, array_flip(array('currency', 'sort'))); $parsed['query'] = http_build_query($pairs); } $content = $parsed['path'] . (!empty($parsed['query']) ? '?' . $parsed['query'] : ''); */ $content = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $queryStartPos = strpos($content, '&'); $content = $queryStartPos !== false ? substr($content, 0, $queryStartPos) : $content; $queryStartPos = strpos($content, '?'); $content = $queryStartPos !== false ? substr($content, 0, $queryStartPos) : $content; $content = $GLOBALS['CANONICAL'] = $content; $smarty->assign('CANONICAL', $content); $smarty->_smarty_vars['CANONICAL'] = $content; } }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_uniqid($params, LiveCartSmarty $smarty) { if (isset($params['last'])) { return $smarty->get_template_vars('lastUniqId'); } else { // start with a letter for XHTML id attribute value compatibility $id = 'a' . uniqid(); $smarty->assign('lastUniqId', $id); if (isset($params['assign'])) { $smarty->assign($params['assign'], $id); if (!empty($params['noecho'])) { return ''; } } return $id; } }
/** * 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); }
/** * 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_content($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { $counter = $smarty->get_template_vars('sectCounter'); $blocks = $smarty->get_template_vars('sect'); $blocks[$counter]['content'] = $content; $smarty->assign('sect', $blocks); } }
/** * Display page section header and footer only if content is present * This helps to avoid using redundant if's * * @param array $params * @param Smarty $smarty * @param $repeat * * <code> * {sect} * {header} * Section header * {/header} * {content} * Section content * {/content} * {footer} * Section footer * {/footer} * {/sect} * </code> * * @return string Section HTML code * @package application.helper.smarty * @author Integry Systems */ function smarty_block_sect($params, $content, LiveCartSmarty $smarty, &$repeat) { $counter = $smarty->get_template_vars('sectCounter'); if ($repeat) { $counter++; $smarty->assign('sectCounter', $counter); $sections = $smarty->get_template_vars('sect'); $sections[$counter] = array('header' => '', 'content' => '', 'footer' => ''); $smarty->assign('sect', $sections); } else { $blocks = $smarty->get_template_vars('sect'); $blocks = $blocks[$counter]; $counter--; $smarty->assign('sectCounter', $counter); if (trim($blocks['content'])) { return $blocks['header'] . $blocks['content'] . $blocks['footer']; } } }
/** * 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_json($params, LiveCartSmarty $smarty) { $array = $params['array']; $assign = isset($params['assign']) ? $params['assign'] : false; ClassLoader::import('library.json.json'); $javaObject = @json_encode($array); if (!$assign) { return $javaObject; } else { $smarty->assign($assign, $javaObject); } }
/** * Set canonical URL * * @package application.helper.smarty * @author Integry Systems * @see http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html */ function smarty_block_canonical($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { $parsed = parse_url($content); if (!empty($parsed['query'])) { $pairs = array(); foreach (explode('&', $parsed['query']) as $pair) { $values = explode('=', $pair, 2); if (count($values) != 2) { continue; } $pairs[$value[0]] = $value[1]; } $pairs = array_diff_key($pairs, array_flip(array('currency', 'sort'))); $parsed['query'] = http_build_query($pairs); } $content = $parsed['path'] . (!empty($parsed['query']) ? '?' . $parsed['query'] : ''); $GLOBALS['CANONICAL'] = $content; $smarty->assign('CANONICAL', $content); $smarty->_smarty_vars['CANONICAL'] = $content; } }
/** * Smarty block plugin, for specifying URL action for page menu item * This block must always be called in menuItem block context * * @param array $params * @param Smarty $smarty * @param $repeat * * <code> * {pageMenu id="menu"} * {menuItem} * {menuCaption}Click Me{/menuCaption} * <strong>{menuAction}http://click.me.com{/menuAction}</strong> * {/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_menuAction($params, $content, LiveCartSmarty $smarty, &$repeat) { if (!$repeat) { $smarty->assign('menuAction', $content); } }