Пример #1
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, LiveCartSmarty $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('menuCaption');
        $smarty->clear_assign('menuAction');
        $smarty->clear_assign('menuPageAction');
    } else {
        $item = new HtmlElement('a');
        if ($smarty->get_template_vars('menuAction')) {
            $href = $smarty->get_template_vars('menuAction');
        } else {
            if ($smarty->get_template_vars('menuPageAction')) {
                $onClick = $smarty->get_template_vars('menuPageAction');
                $href = '#';
                $item->setAttribute('onClick', $onClick . '; return false;');
            }
        }
        $item->setAttribute('href', $href);
        // EXPERIMENTAL - set access key for menu item
        $caption = $smarty->get_template_vars('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());
    }
}
Пример #2
0
/**
 * 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('&amp;', $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;
    }
}
Пример #3
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, LiveCartSmarty $smarty)
{
    $manufacturer = $params['data'];
    $params['data'] =& Category::getRootNode()->toArray();
    $params['addFilter'] = new ManufacturerFilter($manufacturer['ID'], $manufacturer['name']);
    return createCategoryUrl($params, $smarty->getApplication());
}
Пример #4
0
/**
 * 
 * @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;
}
Пример #5
0
/**
 * 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');
    }
}
/**
 * ...
 *
 * @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');
                }
            }
        }
    }
}
Пример #7
0
/**
 * ...
 *
 * @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);
    }
}
Пример #8
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, 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'] : '');
}
Пример #9
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, 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']);
}
Пример #10
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_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);
    }
}
Пример #11
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, 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;
}
Пример #12
0
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;
}
Пример #13
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, 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);
}
Пример #14
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, 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;
}
Пример #15
0
/**
 * ...
 *
 * @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>';
}
Пример #16
0
/**
 * 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;
    }
}
Пример #17
0
/**
 * ...
 *
 * @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);
    }
}
Пример #18
0
/**
 * ...
 *
 * @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);
}
Пример #19
0
/**
 * 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');
}
Пример #20
0
/**
 * ...
 *
 * @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);
    }
}
Пример #21
0
/**
 * Smarty block plugin, for generating page menus
 *
 * @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>
 *
 * @return string Menu HTML code
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_block_pageMenu($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('pageMenuItems');
    } else {
        $items = $smarty->get_template_vars('pageMenuItems');
        $menuDiv = new HtmlElement('div');
        $menuDiv->setAttribute('id', $params['id']);
        $menuDiv->setAttribute('tabIndex', 1);
        $menuDiv->setContent(implode(' | ', $items));
        return $menuDiv->render();
    }
}
Пример #22
0
/**
 * 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">&#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">' . $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;
    }
}
Пример #23
0
/**
 * ...
 *
 * @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 . '&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="' . $urlPath . '?' . filemtime($path) . '" type="text/javascript"></script>' . "\n";
            }
            return $includeString;
        }
    }
}
Пример #24
0
/**
 * ...
 *
 * @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;
    }
}
Пример #25
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, 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 &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'], true);
            } else {
                unset($params['route']);
                $result = $router->createURL($params, true);
            }
        } catch (RouterException $e) {
            return "INVALID_LINK";
        }
    }
    if ($fullUrl) {
        $result = $router->createFullUrl($result);
    }
    return $result;
}
Пример #26
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, 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;
}
Пример #27
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, 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;
}
Пример #28
0
/**
 * 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');
}
Пример #29
0
/**
 * 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('&amp;', $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;
    }
}
Пример #30
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, 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;
}