本文整理汇总了PHP中CSSMin类的典型用法代码示例。如果您正苦于以下问题:PHP CSSMin类的具体用法?PHP CSSMin怎么用?PHP CSSMin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSSMin类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: minify
public function minify($inPath, $outPath)
{
global $wgResourceLoaderMinifierStatementsOnOwnLine, $wgResourceLoaderMinifierMaxLineLength;
$extension = $this->getExtension($inPath);
$this->output(basename($inPath) . ' -> ' . basename($outPath) . '...');
$inText = file_get_contents($inPath);
if ($inText === false) {
$this->error("Unable to open file {$inPath} for reading.");
exit(1);
}
$outFile = fopen($outPath, 'w');
if (!$outFile) {
$this->error("Unable to open file {$outPath} for writing.");
exit(1);
}
switch ($extension) {
case 'js':
$outText = JavaScriptMinifier::minify($inText, $this->getOption('js-statements-on-own-line', $wgResourceLoaderMinifierStatementsOnOwnLine), $this->getOption('js-max-line-length', $wgResourceLoaderMinifierMaxLineLength));
break;
case 'css':
$outText = CSSMin::minify($inText);
break;
default:
$this->error("No minifier defined for extension \"{$extension}\"");
}
fwrite($outFile, $outText);
fclose($outFile);
$this->output(" ok\n");
}
开发者ID:GodelDesign,项目名称:Godel,代码行数:29,代码来源:minify.php
示例2: makeRedirectContent
/**
* Create a redirect that is also valid CSS
*
* @param Title $destination
* @param string $text ignored
* @return CssContent
*/
public function makeRedirectContent(Title $destination, $text = '')
{
// The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi
$url = $destination->getFullURL('action=raw&ctype=text/css', false, PROTO_RELATIVE);
$class = $this->getContentClass();
return new $class('/* #REDIRECT */@import ' . CSSMin::buildUrlValue($url) . ';');
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:14,代码来源:CssContentHandler.php
示例3: minimizeFiles
public function minimizeFiles($files)
{
$css_out = '';
$webroot = (string) OC::$WEBROOT;
foreach ($files as $file_info) {
$file = $file_info[0] . '/' . $file_info[2];
$css_out .= '/* ' . $file . ' */' . "\n";
$css = file_get_contents($file);
$in_root = false;
foreach (OC::$APPSROOTS as $app_root) {
if (strpos($file, $app_root['path'] . '/') === 0) {
$in_root = rtrim($webroot . $app_root['url'], '/');
break;
}
}
if ($in_root !== false) {
$css = str_replace('%appswebroot%', $in_root, $css);
$css = str_replace('%webroot%', $webroot, $css);
}
$remote = $file_info[1];
$remote .= '/';
$remote .= dirname($file_info[2]);
$css_out .= CSSMin::remap($css, dirname($file), $remote, true);
}
if (!defined('DEBUG') || !DEBUG) {
$css_out = CSSMin::minify($css_out);
}
return $css_out;
}
开发者ID:omusico,项目名称:isle-web-framework,代码行数:29,代码来源:css.php
示例4: combine
/**
* Combine multiple text assets into a single file for better http performance this
* method generates a new cache file with every symfony cc you can override the cache
* by adding ?clearassetcache=1 to the page request.
*
* @param type string css or js
* @param namespace string the combined file namespace (eg. module+action names)
* @param response object the sfWebResponse instance
* @return string the url for the combiner service
*/
public function combine($type, $namespace, sfWebResponse $response)
{
//configure the combiner
$type = $type === 'css' ? 'css' : 'js';
$fullname = $type === 'css' ? 'Stylesheets' : 'Javascripts';
$response_getter = 'get' . $fullname;
$namespace = StreemeUtil::slugify($namespace);
//integrate into symfony's asset globals
sfConfig::set(sprintf('symfony.asset.%s_included', strtolower($fullname)), true);
//build the cache filename - this file will be regenerated on a symfony cc
$path = sprintf('%s/combine/%s/', sfConfig::get('sf_cache_dir'), $type);
$filename = sprintf('%s.%s', $namespace, $type);
// you can force a cache clear by passing ?clearassetcache=1 to any template
if (!is_readable($path . $filename) || @$_GET['clearassetcache'] == 1) {
//build one file of all of the css or js files
$file_content = '';
//load vendor libraries for minifying assets
require_once sfConfig::get('sf_lib_dir') . '/vendor/jsmin/jsmin.php';
require_once sfConfig::get('sf_lib_dir') . '/vendor/cssmin/cssmin.php';
foreach ($response->{$response_getter}() as $file => $options) {
if ($type === 'css') {
$file_content .= CSSMin::minify(file_get_contents(sfConfig::get('sf_web_dir') . $file));
} else {
$file_content .= JSMin::minify(file_get_contents(sfConfig::get('sf_web_dir') . $file));
}
}
//this file resides in the cache and requires wide permissions for both cli and apache users
@umask(00);
@mkdir($path, 0777, true);
file_put_contents($path . $filename, $file_content);
}
return sprintf('/service/combine/%s/%s', $type, str_replace('-', '_', $namespace));
}
开发者ID:Alenpiera,项目名称:streeme,代码行数:43,代码来源:combineFiles.class.php
示例5: show_css
function show_css($files)
{
global $root;
$hash = '';
foreach ($files as $file) {
$path = $root . '/' . $file . '.css';
$hash .= $file . filemtime($path);
}
$md5 = md5($hash);
$cpath = $root . '/resources/c/' . $md5 . '.css';
if (!file_exists($cpath)) {
require_once 'CSSMin.php';
$text = '';
foreach ($files as $file) {
$path = $root . '/' . $file . '.css';
$text .= file_get_contents($path) . "\n\n";
}
if (TEST) {
$css = $text;
} else {
$css = CSSMin::minify($text);
}
file_put_contents($cpath, $css);
}
echo '<link rel="stylesheet" href="/resources/c/' . $md5 . '.css" />' . "\n";
}
开发者ID:darwinkim,项目名称:onlinesequencer,代码行数:26,代码来源:functions.js.php
示例6: minify
function minify()
{
$this->setTemplate(get_template_path("empty"));
if (!logged_user()->isAdministrator()) {
die("You must be an administrator to run this tool.");
}
// include libraries
include_once LIBRARY_PATH . '/jsmin/JSMin.class.php';
include_once LIBRARY_PATH . '/cssmin/CSSMin.class.php';
// process arguments
$minify = isset($_GET['minify']);
// process javascripts
echo "Concatenating javascripts ... \n";
$files = (include "application/layouts/javascripts.php");
$jsmin = "";
foreach ($files as $file) {
$jsmin .= file_get_contents("public/assets/javascript/{$file}") . "\n";
}
echo "Done!<br>\n";
if ($minify) {
echo "Minifying javascript ... \n";
$jsmin = JSMin::minify($jsmin);
echo "Done!<br>\n";
}
echo "Writing to file 'ogmin.js' ... ";
file_put_contents("public/assets/javascript/ogmin.js", $jsmin);
echo "Done!<br>";
echo "<br>";
// process CSS
function changeUrls($css, $base)
{
return preg_replace("/url\\s*\\(\\s*['\"]?([^\\)'\"]*)['\"]?\\s*\\)/i", "url(" . $base . "/\$1)", $css);
}
function parseCSS($filename, $filebase, $imgbase)
{
$css = file_get_contents($filebase . $filename);
$imports = explode("@import", $css);
$cssmin = changeUrls($imports[0], $imgbase);
for ($i = 1; $i < count($imports); $i++) {
$split = explode(";", $imports[$i], 2);
$import = trim($split[0], " \t\n\r\v'\"");
$cssmin .= parseCSS($import, $filebase, $imgbase . "/" . dirname($import));
$cssmin .= changeUrls($split[1], $imgbase);
}
return $cssmin;
}
echo "Concatenating CSS ... ";
$cssmin = parseCSS("website.css", "public/assets/themes/default/stylesheets/", ".");
echo "Done!<br>";
if ($minify) {
echo "Minifying CSS ... ";
$cssmin = CSSMin::minify($cssmin);
echo "Done!<br>";
}
echo "Writing to file 'ogmin.css' ... ";
file_put_contents("public/assets/themes/default/stylesheets/ogmin.css", $cssmin);
echo "Done!<br>";
die;
}
开发者ID:abhinay100,项目名称:feng_app,代码行数:59,代码来源:ToolController.class.php
示例7: embed
/**
* Convert an image URI to a base64-encoded data URI.
*
* @par Example:
* @code
* .fancy-button {
* background-image: embed('../images/button-bg.png');
* }
* @endcode
* @param array $frame
* @param lessc $less
* @return string
*/
public static function embed($frame, $less)
{
$base = pathinfo($less->parser->sourceName, PATHINFO_DIRNAME);
$url = trim($less->compileValue($frame), '"\'');
$file = realpath($base . '/' . $url);
$data = CSSMin::encodeImageAsDataURI($file);
$less->addParsedFile($file);
return CSSMin::buildUrlValue($data);
}
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:22,代码来源:ResourceLoaderLESSFunctions.php
示例8: embed
/**
* Convert an image URI to a base64-encoded data URI.
*
* @par Example:
* @code
* .fancy-button {
* background-image: embed('../images/button-bg.png');
* }
* @endcode
*/
public static function embed($frame, $less)
{
$base = pathinfo($less->parser->sourceName, PATHINFO_DIRNAME);
$url = $frame[2][0];
$file = realpath($base . '/' . $url);
$data = CSSMin::encodeImageAsDataURI($file);
$less->addParsedFile($file);
return 'url(' . $data . ')';
}
开发者ID:biribogos,项目名称:wikihow-src,代码行数:19,代码来源:ResourceLoaderLESSFunctions.php
示例9: getLessVars
/**
* Get language-specific LESS variables for this module.
*
* @since 1.27
* @param ResourceLoaderContext $context
* @return array
*/
protected function getLessVars(ResourceLoaderContext $context)
{
$vars = parent::getLessVars($context);
$language = Language::factory($context->getLanguage());
foreach ($language->getImageFiles() as $key => $value) {
$vars[$key] = CSSMin::serializeStringValue($value);
}
return $vars;
}
开发者ID:rrameshs,项目名称:mediawiki,代码行数:16,代码来源:ResourceLoaderEditToolbarModule.php
示例10: getLessVars
/**
* Get language-specific LESS variables for this module.
*
* @return array
*/
private function getLessVars(ResourceLoaderContext $context)
{
$language = Language::factory($context->getLanguage());
// This is very conveniently formatted and we can pass it right through
$vars = $language->getImageFiles();
// less.php tries to be helpful and parse our variables as LESS source code
foreach ($vars as $key => &$value) {
$value = CSSMin::serializeStringValue($value);
}
return $vars;
}
开发者ID:ngertrudiz,项目名称:mediawiki,代码行数:16,代码来源:ResourceLoaderEditToolbarModule.php
示例11: optimize
protected function optimize($data, $package, $type)
{
switch ($type)
{
case 'javascripts':
$data = JSMin::minify($data);
break;
case 'stylesheets':
$data = CSSMin::minify($data);
break;
}
return $data;
}
开发者ID:nexeck,项目名称:kollapse,代码行数:14,代码来源:minify.php
示例12: getStyles
/**
* @param $context ResourceLoaderContext
* @return array
*/
public function getStyles(ResourceLoaderContext $context)
{
$logo = $this->getConfig()->get('Logo');
$logoHD = $this->getConfig()->get('LogoHD');
$styles = parent::getStyles($context);
$styles['all'][] = '.mw-wiki-logo { background-image: ' . CSSMin::buildUrlValue($logo) . '; }';
if ($logoHD) {
if (isset($logoHD['1.5x'])) {
$styles['(-webkit-min-device-pixel-ratio: 1.5), ' . '(min--moz-device-pixel-ratio: 1.5), ' . '(min-resolution: 1.5dppx), ' . '(min-resolution: 144dpi)'][] = '.mw-wiki-logo { background-image: ' . CSSMin::buildUrlValue($logoHD['1.5x']) . ';' . 'background-size: 135px auto; }';
}
if (isset($logoHD['2x'])) {
$styles['(-webkit-min-device-pixel-ratio: 2), ' . '(min--moz-device-pixel-ratio: 2),' . '(min-resolution: 2dppx), ' . '(min-resolution: 192dpi)'][] = '.mw-wiki-logo { background-image: ' . CSSMin::buildUrlValue($logoHD['2x']) . ';' . 'background-size: 135px auto; }';
}
}
return $styles;
}
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:20,代码来源:ResourceLoaderSkinModule.php
示例13: compress
function compress($string, $filetype = "php")
{
if ($filetype === "php") {
$string = str_replace("<?php\r", "<?php ", $string);
return str_replace(array("\r\n", "\r", "\n", "\t", " ", " ", " "), "", $string);
} else {
global $Load;
if ($filetype === "css") {
$Load->library("cssmin", null, null, "minify");
return CSSMin::minify($string);
} elseif ($filetype === 'js') {
$Load->library("jsmin", null, null, "minify");
return JSMin::minify($string);
}
}
return null;
}
开发者ID:jgianpiere,项目名称:ZanPHP,代码行数:17,代码来源:string.php
示例14: filter
/**
* Runs JavaScript or CSS data through a filter, caching the filtered result for future calls.
*
* Available filters are:
* - minify-js \see JavaScriptMinifier::minify
* - minify-css \see CSSMin::minify
*
* If $data is empty, only contains whitespace or the filter was unknown,
* $data is returned unmodified.
*
* @param $filter String: Name of filter to run
* @param $data String: Text to filter, such as JavaScript or CSS text
* @return String: Filtered data, or a comment containing an error message
*/
protected function filter($filter, $data)
{
global $wgResourceLoaderMinifierStatementsOnOwnLine, $wgResourceLoaderMinifierMaxLineLength;
wfProfileIn(__METHOD__);
// For empty/whitespace-only data or for unknown filters, don't perform
// any caching or processing
if (trim($data) === '' || !in_array($filter, array('minify-js', 'minify-css'))) {
wfProfileOut(__METHOD__);
return $data;
}
// Try for cache hit
// Use CACHE_ANYTHING since filtering is very slow compared to DB queries
$key = wfMemcKey('resourceloader', 'filter', $filter, self::$filterCacheVersion, md5($data));
$cache = wfGetCache(CACHE_ANYTHING);
$cacheEntry = $cache->get($key);
if (is_string($cacheEntry)) {
wfProfileOut(__METHOD__);
return $cacheEntry;
}
$result = '';
// Run the filter - we've already verified one of these will work
try {
switch ($filter) {
case 'minify-js':
$result = JavaScriptMinifier::minify($data, $wgResourceLoaderMinifierStatementsOnOwnLine, $wgResourceLoaderMinifierMaxLineLength);
$result .= "\n/* cache key: {$key} */";
break;
case 'minify-css':
$result = CSSMin::minify($data);
$result .= "\n/* cache key: {$key} */";
break;
}
// Save filtered text to Memcached
$cache->set($key, $result);
} catch (Exception $exception) {
// Return exception as a comment
$result = $this->makeComment($exception->__toString());
}
wfProfileOut(__METHOD__);
return $result;
}
开发者ID:seedbank,项目名称:old-repo,代码行数:55,代码来源:ResourceLoader.php
示例15: readStyleFile
/**
* Reads a style file.
*
* This method can be used as a callback for array_map()
*
* @param $path String: File path of style file to read
* @param $flip bool
*
* @return String: CSS data in script file
* @throws MWException if the file doesn't exist
*/
protected function readStyleFile($path, $flip)
{
$localPath = $this->getLocalPath($path);
if (!file_exists($localPath)) {
$msg = __METHOD__ . ": style file not found: \"{$localPath}\"";
wfDebugLog('resourceloader', $msg);
throw new MWException($msg);
}
$style = file_get_contents($localPath);
if ($flip) {
$style = CSSJanus::transform($style, true, false);
}
$dirname = dirname($path);
if ($dirname == '.') {
// If $path doesn't have a directory component, don't prepend a dot
$dirname = '';
}
$dir = $this->getLocalPath($dirname);
$remoteDir = $this->getRemotePath($dirname);
// Get and register local file references
$this->localFileRefs = array_merge($this->localFileRefs, CSSMin::getLocalFileReferences($style, $dir));
return CSSMin::remap($style, $dir, $remoteDir, true);
}
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:34,代码来源:ResourceLoaderFileModule.php
示例16: _elgg_views_minify
/**
* Minifies simplecache CSS and JS views by handling the "simplecache:generate" hook
*
* @param string $hook The name of the hook
* @param string $type View type (css, js, or unknown)
* @param string $content Content of the view
* @param array $params Array of parameters
*
* @return string|null View content minified (if css/js type)
* @access private
*/
function _elgg_views_minify($hook, $type, $content, $params)
{
static $autoload_registered;
if (!$autoload_registered) {
$path = elgg_get_root_path() . 'vendors/minify/lib';
elgg_get_class_loader()->addFallback($path);
$autoload_registered = true;
}
if (preg_match('~[\\.-]min\\.~', $params['view'])) {
// bypass minification
return;
}
if ($type == 'js') {
if (elgg_get_config('simplecache_minify_js')) {
return JSMin::minify($content);
}
} elseif ($type == 'css') {
if (elgg_get_config('simplecache_minify_css')) {
$cssmin = new CSSMin();
return $cssmin->run($content);
}
}
}
开发者ID:gzachos,项目名称:elgg_ellak,代码行数:34,代码来源:views.php
示例17: pp_enqueue_front_page_scripts
function pp_enqueue_front_page_scripts()
{
//enqueue frontend css files
$pp_advance_combine_css = get_option('pp_advance_combine_css');
//If enable animation
$pp_animation = get_option('pp_animation');
//Get theme cache folder
$upload_dir = wp_upload_dir();
$cache_dir = '';
$cache_url = '';
if (isset($upload_dir['basedir'])) {
$cache_dir = THEMEUPLOAD;
}
if (isset($upload_dir['baseurl'])) {
$cache_url = THEMEUPLOADURL;
}
if (!empty($pp_advance_combine_css)) {
if (!file_exists($cache_dir . "/combined.css")) {
$cssmin = new CSSMin();
$css_arr = array(get_template_directory() . '/css/reset.css', get_template_directory() . '/css/wordpress.css', get_template_directory() . '/css/animation.css', get_template_directory() . '/css/magnific-popup.css', get_template_directory() . '/css/jqueryui/custom.css', get_template_directory() . '/js/mediaelement/mediaelementplayer.css', get_template_directory() . '/js/flexslider/flexslider.css', get_template_directory() . '/css/tooltipster.css', get_template_directory() . '/css/odometer-theme-minimal.css', get_template_directory() . '/css/hw-parallax.css', get_template_directory() . '/css/screen.css');
//If using child theme
$pp_child_theme = get_option('pp_child_theme');
if (empty($pp_child_theme)) {
$css_arr[] = get_template_directory() . '/css/screen.css';
} else {
$css_arr[] = get_template_directory() . '/style.css';
}
$cssmin->addFiles($css_arr);
// Set original CSS from all files
$cssmin->setOriginalCSS();
$cssmin->compressCSS();
$css = $cssmin->printCompressedCSS();
file_put_contents($cache_dir . "combined.css", $css);
}
wp_enqueue_style("combined_css", $cache_url . "combined.css", false, "");
} else {
wp_enqueue_style("reset-css", get_template_directory_uri() . "/css/reset.css", false, "");
wp_enqueue_style("wordpress-css", get_template_directory_uri() . "/css/wordpress.css", false, "");
wp_enqueue_style("animation.css", get_template_directory_uri() . "/css/animation.css", false, "", "all");
wp_enqueue_style("magnific-popup", get_template_directory_uri() . "/css/magnific-popup.css", false, "", "all");
wp_enqueue_style("jquery-ui-css", get_template_directory_uri() . "/css/jqueryui/custom.css", false, "");
wp_enqueue_style("mediaelement", get_template_directory_uri() . "/js/mediaelement/mediaelementplayer.css", false, "", "all");
wp_enqueue_style("flexslider", get_template_directory_uri() . "/js/flexslider/flexslider.css", false, "", "all");
wp_enqueue_style("tooltipster", get_template_directory_uri() . "/css/tooltipster.css", false, "", "all");
wp_enqueue_style("odometer-theme", get_template_directory_uri() . "/css/odometer-theme-minimal.css", false, "", "all");
wp_enqueue_style("hw-parallax.css", get_template_directory_uri() . '/css/hw-parallax.css', false, "", "all");
wp_enqueue_style("screen.css", get_template_directory_uri() . '/css/screen.css', false, "", "all");
}
//Check menu layout
$tg_menu_layout = tg_menu_layout();
if ($tg_menu_layout == 'leftmenu') {
wp_enqueue_style("leftmenu.css", get_template_directory_uri() . '/css/leftmenu.css', false, "", "all");
}
//Add Font Awesome Support
wp_enqueue_style("fontawesome", get_template_directory_uri() . "/css/font-awesome.min.css", false, "", "all");
if (THEMEDEMO && isset($_GET['menu']) && !empty($_GET['menu'])) {
wp_enqueue_style("custom_css", get_template_directory_uri() . "/templates/custom-css.php?menu=" . $_GET['menu'], false, "", "all");
} else {
wp_enqueue_style("custom_css", get_template_directory_uri() . "/templates/custom-css.php", false, "", "all");
}
$tg_boxed = kirki_get_option('tg_boxed');
if (THEMEDEMO && isset($_GET['boxed']) && !empty($_GET['boxed'])) {
$tg_boxed = 1;
}
if (!empty($tg_boxed) && $tg_menu_layout != 'leftmenu') {
wp_enqueue_style("tg_boxed", get_template_directory_uri() . '/css/tg_boxed.css', false, "", "all");
}
//If using child theme
$pp_child_theme = get_option('pp_child_theme');
if (!empty($pp_child_theme)) {
wp_enqueue_style('child_theme', get_stylesheet_directory_uri() . "/style.css", false, "", "all");
}
//Get all Google Web font CSS
global $tg_google_fonts;
$tg_fonts_family = array();
if (is_array($tg_google_fonts) && !empty($tg_google_fonts)) {
foreach ($tg_google_fonts as $tg_font) {
$tg_fonts_family[] = kirki_get_option($tg_font);
}
}
$tg_fonts_family = array_unique($tg_fonts_family);
foreach ($tg_fonts_family as $key => $tg_google_font) {
if (!empty($tg_google_font) && $tg_google_font != 'serif' && $tg_google_font != 'sans-serif' && $tg_google_font != 'monospace') {
if (!is_ssl()) {
wp_enqueue_style('google_font' . $key, "http://fonts.googleapis.com/css?family=" . urlencode($tg_google_font) . ":300,400,700,400italic&subset=latin,cyrillic-ext,greek-ext,cyrillic", false, "", "all");
} else {
wp_enqueue_style('google_font' . $key, "https://fonts.googleapis.com/css?family=" . urlencode($tg_google_font) . ":300, 400,700,400italic&subset=latin,cyrillic-ext,greek-ext,cyrillic", false, "", "all");
}
}
}
//Enqueue javascripts
wp_enqueue_script("jquery");
$js_path = get_template_directory() . "/js/";
$js_arr = array('jquery.magnific-popup.js', 'jquery.easing.js', 'waypoints.min.js', 'jquery.isotope.js', 'jquery.masory.js', 'jquery.tooltipster.min.js', 'hw-parallax.js', 'custom_plugins.js', 'custom.js');
$js = "";
$pp_advance_combine_js = get_option('pp_advance_combine_js');
if (!empty($pp_advance_combine_js)) {
if (!file_exists($cache_dir . "combined.js")) {
foreach ($js_arr as $file) {
if ($file != 'jquery.js' && $file != 'jquery-ui.js') {
//.........这里部分代码省略.........
开发者ID:rsantellan,项目名称:wordpress-ecommerce,代码行数:101,代码来源:functions.php
示例18: testStyleMedia
/**
* @dataProvider provideMediaStylesheets
*/
public function testStyleMedia($moduleName, $media, $filename, $css)
{
$cssText = CSSMin::minify($css->cssText);
$this->assertTrue(strpos($cssText, '@media') === false, 'Stylesheets should not both specify "media" and contain @media');
}
开发者ID:biribogos,项目名称:wikihow-src,代码行数:8,代码来源:ResourcesTest.php
示例19: filter
/**
* Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
*
* Available filters are:
*
* - minify-js \see JavaScriptMinifier::minify
* - minify-css \see CSSMin::minify
*
* If $data is empty, only contains whitespace or the filter was unknown,
* $data is returned unmodified.
*
* @param string $filter Name of filter to run
* @param string $data Text to filter, such as JavaScript or CSS text
* @param string $cacheReport Whether to include the cache key report
* @return string Filtered data, or a comment containing an error message
*/
public function filter($filter, $data, $cacheReport = true)
{
// For empty/whitespace-only data or for unknown filters, don't perform
// any caching or processing
if (trim($data) === '' || !in_array($filter, array('minify-js', 'minify-css'))) {
return $data;
}
// Try for cache hit
// Use CACHE_ANYTHING since filtering is very slow compared to DB queries
$key = wfMemcKey('resourceloader', 'filter', $filter, self::$filterCacheVersion, md5($data));
$cache = wfGetCache(CACHE_ANYTHING);
$cacheEntry = $cache->get($key);
if (is_string($cacheEntry)) {
wfIncrStats("rl-{$filter}-cache-hits");
return $cacheEntry;
}
$result = '';
// Run the filter - we've already verified one of these will work
try {
wfIncrStats("rl-{$filter}-cache-misses");
switch ($filter) {
case 'minify-js':
$result = JavaScriptMinifier::minify($data, $this->config->get('ResourceLoaderMinifierStatementsOnOwnLine'), $this->config->get('ResourceLoaderMinifierMaxLineLength'));
if ($cacheReport) {
$result .= "\n/* cache key: {$key} */";
}
break;
case 'minify-css':
$result = CSSMin::minify($data);
if ($cacheReport) {
$result .= "\n/* cache key: {$key} */";
}
break;
}
// Save filtered text to Memcached
$cache->set($key, $result);
} catch (Exception $e) {
MWExceptionHandler::logException($e);
wfDebugLog('resourceloader', __METHOD__ . ": minification failed: {$e}");
$this->errors[] = self::formatExceptionNoComment($e);
}
return $result;
}
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:59,代码来源:ResourceLoader.php
示例20: applyFilter
private static function applyFilter($filter, $data, Config $config)
{
switch ($filter) {
case 'minify-js':
return JavaScriptMinifier::minify($data);
case 'minify-css':
return CSSMin::minify($data);
}
return $data;
}
开发者ID:rugby110,项目名称:mediawiki,代码行数:10,代码来源:ResourceLoader.php
注:本文中的CSSMin类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论