本文整理汇总了PHP中Smarty_Internal_Template::getGlobal方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Template::getGlobal方法的具体用法?PHP Smarty_Internal_Template::getGlobal怎么用?PHP Smarty_Internal_Template::getGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty_Internal_Template
的用法示例。
在下文中一共展示了Smarty_Internal_Template::getGlobal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_function_compiledJs
/**
* ...
*
* @param array $params
* @param Smarty $smarty
* @return string
*
* @package application.helper.smarty
* @author Integry Systems
*/
function smarty_function_compiledJs($params, Smarty_Internal_Template $smarty)
{
$includedJavascriptTimestamp = $smarty->getGlobal("INCLUDED_JAVASCRIPT_TIMESTAMP");
$includedJavascriptFiles = $smarty->getGlobal("INCLUDED_JAVASCRIPT_FILES");
$app = $smarty->getApplication();
if ($includedJavascriptFiles && isset($params['glue']) && $params['glue'] == 'true' && !$smarty->getApplication()->isDevMode() && !$smarty->getApplication()->isTemplateCustomizationMode()) {
$request = $app->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="' . $app->getPublicUrl('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="' . $app->getPublicUrl($urlPath) . '?' . filemtime($path) . '" type="text/javascript"></script>' . "\n";
}
return $includeString;
}
}
}
示例3: 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);
}
}