本文整理汇总了PHP中CSSMin::minify方法的典型用法代码示例。如果您正苦于以下问题:PHP CSSMin::minify方法的具体用法?PHP CSSMin::minify怎么用?PHP CSSMin::minify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSSMin
的用法示例。
在下文中一共展示了CSSMin::minify方法的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");
}
示例2: 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;
}
示例3: 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));
}
示例4: 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";
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: minify
public static function minify($d, $t = 'js')
{
if (!empty(Core::$core->nominify) || $t != 'css' && $t != 'js' && $t != 'php') {
return $d;
}
$d = trim($d);
if ($t == 'css' && class_exists('CSSMin')) {
return \CSSMin::minify($d);
}
if ($t == 'js' && class_exists('JSMin')) {
return \JSMin::minify($d);
}
$n = '';
$i = 0;
$l = strlen($d);
while ($i < $l) {
$c = @substr($n, -1);
if (($d[$i] == "'" || $d[$i] == '"') && $c != '\\') {
$s = $d[$i];
$j = $i;
++$i;
while ($i < $l && $d[$i] != $s) {
if ($d[$i] == '\\') {
$i++;
}
++$i;
}
++$i;
$n .= substr($d, $j, $i - $j);
continue;
}
if ($t != 'css' && ($d[$i] == '/' && $d[$i + 1] == '/')) {
$s = $i;
$i += 2;
while ($i < $l && $d[$i] != "\n") {
$i++;
}
continue;
}
if ($d[$i] == '/' && $d[$i + 1] == '*') {
$s = $i;
$i += 2;
while ($i + 1 < $l && ($d[$i] != '*' || $d[$i + 1] != '/')) {
$i++;
}
$i += 2;
continue;
}
if ($d[$i] == "\t" || $d[$i] == "\r" || $d[$i] == "\n") {
if (($c >= 'a' && $c <= 'z' || $c >= 'A' && $c <= 'Z' || $c >= '0' && $c <= '9') && ($d[$i + 1] == '\\' || $d[$i + 1] == '/' || $d[$i + 1] == '_' || $d[$i + 1] == '*' || $d[$i + 1] >= 'a' && $d[$i + 1] <= 'z' || $d[$i + 1] >= 'A' && $d[$i + 1] <= 'Z' || $d[$i + 1] >= '0' && $d[$i + 1] <= '9' || $d[$i + 1] == '#')) {
$n .= ' ';
}
$i++;
continue;
}
if ($d[$i] == ' ' && (!($c >= 'a' && $c <= 'z' || $c >= 'A' && $c <= 'Z' || $c >= '0' && $c <= '9') || !($d[$i + 1] == '\\' || $d[$i + 1] == '/' || $d[$i + 1] == '_' || $d[$i + 1] >= 'a' && $d[$i + 1] <= 'z' || $d[$i + 1] >= 'A' && $d[$i + 1] <= 'Z' || $d[$i + 1] >= '0' && $d[$i + 1] <= '9' || $d[$i + 1] == '#' || $d[$i + 1] == '*' || $t == 'js' && $d[$i + 1] == '$'))) {
++$i;
continue;
}
$n .= $d[$i++];
}
return $n;
}
示例9: compress
/**
* {@inheritDoc}
*/
public function compress($content)
{
require_once $this->options['path'];
return \CSSMin::minify($content, $this->options);
}
示例10: applyFilter
private static function applyFilter($filter, $data)
{
$data = trim($data);
if ($data) {
try {
$data = $filter === 'minify-css' ? CSSMin::minify($data) : JavaScriptMinifier::minify($data);
} catch (Exception $e) {
MWExceptionHandler::logException($e);
return null;
}
}
return $data;
}
示例11: 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');
}
示例12: smarty_build_combine
/**
* Build combined file
*
* @param array $params
*/
function smarty_build_combine($params)
{
$filelist = array();
$lastest_mtime = 0;
foreach ($params['input'] as $item) {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $item)) {
$mtime = filemtime($_SERVER['DOCUMENT_ROOT'] . $item);
$lastest_mtime = max($lastest_mtime, $mtime);
$filelist[] = array('name' => $item, 'time' => $mtime);
} else {
trigger_error('File ' . $_SERVER['DOCUMENT_ROOT'] . $item . ' does not exists!', E_USER_WARNING);
}
}
if ($params['debug'] == true) {
$output_filename = '';
foreach ($filelist as $file) {
if ($params['type'] == 'js') {
$output_filename .= '<script type="text/javascript" src="' . $_SERVER['DOCUMENT_ROOT'] . $file['name'] . '" charset="utf-8"></script>';
} elseif ($params['type'] == 'css') {
$output_filename .= '<link type="text/css" rel="stylesheet" href="' . $_SERVER['DOCUMENT_ROOT'] . $file['name'] . '" />';
}
}
echo $output_filename;
return;
}
$last_cmtime = 0;
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $params['cache_file_name'])) {
$last_cmtime = file_get_contents($_SERVER['DOCUMENT_ROOT'] . $params['cache_file_name']);
}
if ($lastest_mtime > $last_cmtime) {
$glob_mask = preg_replace("/\\.(js|css)\$/i", "_*.\$1", $params['output']);
$files_to_cleanup = glob($_SERVER['DOCUMENT_ROOT'] . $glob_mask);
foreach ($files_to_cleanup as $cfile) {
if (is_file($_SERVER['DOCUMENT_ROOT'] . $cfile) && file_exists($_SERVER['DOCUMENT_ROOT'] . $cfile)) {
@unlink($_SERVER['DOCUMENT_ROOT'] . $cfile);
}
}
$output_filename = preg_replace("/\\.(js|css)\$/i", date("_YmdHis.", $lastest_mtime) . "\$1", $params['output']);
$fh = fopen($_SERVER['DOCUMENT_ROOT'] . $output_filename, "a+");
if (flock($fh, LOCK_EX)) {
foreach ($filelist as $file) {
$min = '';
if ($params['type'] == 'js') {
$min = JSMin::minify(file_get_contents($_SERVER['DOCUMENT_ROOT'] . $file['name']));
} elseif ($params['type'] == 'css') {
$min = CSSMin::minify(file_get_contents($_SERVER['DOCUMENT_ROOT'] . $file['name']));
} else {
fputs($fh, PHP_EOL . PHP_EOL . "/* " . $file['name'] . " @ " . date("c", $file['time']) . " */" . PHP_EOL . PHP_EOL);
$min = file_get_contents($_SERVER['DOCUMENT_ROOT'] . $file['name']);
}
fputs($fh, $min);
}
flock($fh, LOCK_UN);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . $params['cache_file_name'], $lastest_mtime, LOCK_EX);
}
fclose($fh);
clearstatcache();
}
touch($_SERVER['DOCUMENT_ROOT'] . $params['cache_file_name']);
smarty_print_out($params);
}
示例13: init
/**
* Initialize the assets library
*
* Loads the config file and inserts the base css and js into the arrays for
* later use. This ensures that the base files will be processed in the
* order the user expects.
*
* @return void
*/
public static function init()
{
// It is recommended to combine as many config files as sensible into a
// single file for performance reasons. If the config entry is already
// available, don't load the file.
// @todo Update this to remove the check for 'assets.base_folder' once
// it can be safely assumed that the item should no longer be present
$baseFolder = self::$ci->config->item('assets.base_folder');
$assetsDirs = self::$ci->config->item('assets.directories');
if (($baseFolder === false || $baseFolder === null) && ($assetsDirs === false || $assetsDirs === null)) {
self::$ci->config->load('application');
}
unset($baseFolder, $assetsDirs);
// Retrieve the config settings
if (self::$ci->config->item('assets.directories')) {
self::$directories = self::$ci->config->item('assets.directories');
foreach (self::$directories as $key => &$value) {
$value = trim($value, '/');
}
} else {
// If 'assets.directories' is not set, check the previous locations.
self::$directories = array();
self::$directories['base'] = trim(self::$ci->config->item('assets.base_folder') ?: 'assets', '/');
self::$directories['cache'] = trim(self::$ci->config->item('assets.cache_folder') ?: 'cache', '/');
// Set to default because this directory was not in the previous
// config locations.
self::$directories['module'] = 'module';
$assetFolders = self::$ci->config->item('assets.asset_folders') ?: array('js' => 'js', 'css' => 'css', 'image' => 'images');
foreach ($assetFolders as $key => $value) {
self::$directories[$key] = trim($value, '/');
}
unset($assetFolders);
}
// Make sure the is_https() function is available for use by external_js()
// and find_files().
if (!function_exists('is_https')) {
self::$ci->load->helper('application');
}
// Set the closures to minify CSS/JS
self::$cssMinify = function ($css) {
return CSSMin::minify($css);
};
self::$jsMinify = function ($js) {
return JSMin::minify($js);
};
log_message('debug', 'Assets library loaded.');
}
示例14: isset
}
/**
* Scripts that will be minified and included at the STANDARD level and above.
*/
if (Classification::is_standard() && (isset($_GET['standard']) || isset($_GET['touch']))) {
$loadarr = isset($_GET['standard']) ? explode(' ', $_GET['standard']) : array();
// Support for deprecated TOUCH parameter.
if (isset($_GET['touch'])) {
$loadarr = array_merge(explode(' ', $_GET['touch']), $loadarr);
}
foreach ($loadarr as $file) {
if (Path_Validator::is_safe($file, 'css') && ($contents = Path::get_contents($file))) {
echo CSSMin::minify($contents);
}
}
}
/**
* Scripts that will be minified and included at the FULL level only.
*/
if (Classification::is_full() && (isset($_GET['full']) || isset($_GET['webkit']))) {
$loadarr = isset($_GET['full']) ? explode(' ', $_GET['full']) : array();
// Support for deprecated WEBKIT parameter.
if (isset($_GET['webkit'])) {
$loadarr = array_merge(explode(' ', $_GET['webkit']), $loadarr);
}
foreach ($loadarr as $file) {
if (Path_Validator::is_safe($file, 'css') && ($contents = Path::get_contents($file))) {
echo CSSMin::minify($contents);
}
}
}
示例15: _process
/**
* Process files
* @param string $data contents of file
* @param string $type css or js
* @param string $do what to do (all, minify)
* @param string $base_url URL to assets directory
* @return string returns the processed file data
*/
private static function _process($data = null, $type = null, $do = 'all', $base_url = null)
{
if (!$base_url) {
$base_url = self::$base_url;
}
if ($type == 'css') {
if ((self::$minify or self::$minify_css) and ($do == 'all' or $do == 'minify')) {
$data = CSSMin::minify($data, array('currentDir' => str_replace(site_url(), '', $base_url) . '/'));
}
} else {
if ((self::$minify or self::$minify_js) and ($do == 'all' or $do == 'minify')) {
$data = JSMin::minify($data);
}
}
return $data;
}