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


PHP CSSMin类代码示例

本文整理汇总了PHP中CSSMin的典型用法代码示例。如果您正苦于以下问题:PHP CSSMin类的具体用法?PHP CSSMin怎么用?PHP CSSMin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CSSMin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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