本文整理汇总了PHP中Smarty_Internal_Template::setGlobal方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Template::setGlobal方法的具体用法?PHP Smarty_Internal_Template::setGlobal怎么用?PHP Smarty_Internal_Template::setGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty_Internal_Template
的用法示例。
在下文中一共展示了Smarty_Internal_Template::setGlobal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_includeJs
/**
* ...
*
* @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);
}
}
示例2: smarty_block_pageTitle
/**
* 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);
}
}
示例3: smarty_block_canonical
/**
* 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);
}
}
示例4: smarty_function_includeCss
/**
* ...
*
* @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);
}
}