当前位置: 首页>>代码示例>>PHP>>正文


PHP Smarty_Internal_Template::getGlobal方法代码示例

本文整理汇总了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);
    }
}
开发者ID:saiber,项目名称:livecart,代码行数:62,代码来源:function.includeJs.php

示例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 . '&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="' . $app->getPublicUrl($urlPath) . '?' . filemtime($path) . '" type="text/javascript"></script>' . "\n";
            }
            return $includeString;
        }
    }
}
开发者ID:saiber,项目名称:livecart,代码行数:60,代码来源:function.compiledJs.php

示例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);
    }
}
开发者ID:saiber,项目名称:livecart,代码行数:71,代码来源:function.includeCss.php


注:本文中的Smarty_Internal_Template::getGlobal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。