/** * ... * * @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); } }
/** * Set page title * * @package application.helper.smarty * @author Integry Systems */ function smarty_block_pageTitle($params, $content, Smarty_Internal_Template $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->setGlobal('PAGE_TITLE', $content); } }
/** * 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, Smarty_Internal_Template $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->setGlobal('CANONICAL', $content); } }
/** * ... * * @param array $params * @param Smarty $smarty * @return string * * @package application.helper.smarty * @author Integry Systems */ function smarty_function_includeCss($params, Smarty_Internal_Template $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'])) { $external = (array) $smarty->getGlobal('INCLUDED_STYLESHEET_FILES_EXTERNAL'); $external[] = $fileName; $smarty->setGlobal('INCLUDED_STYLESHEET_FILES_EXTERNAL', $external); } else { $includedStylesheetTimestamp = $smarty->getGlobal('INCLUDED_STYLESHEET_TIMESTAMP'); if (!($includedStylesheetFiles = $smarty->getGlobal('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->setGlobal('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->setGlobal('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); } }