forked from extern/egroupware
update minify to version 2.1.7 and reapplying our patches r40512 and r45055
This commit is contained in:
parent
881f8d254b
commit
f49cdf4d85
@ -9,9 +9,15 @@
|
||||
|
||||
/**
|
||||
* Allow use of the Minify URI Builder app. Only set this to true while you need it.
|
||||
**/
|
||||
*/
|
||||
$min_enableBuilder = false;
|
||||
|
||||
/**
|
||||
* If non-empty, the Builder will be protected with HTTP Digest auth.
|
||||
* The username is "admin".
|
||||
*/
|
||||
$min_builderPassword = 'admin';
|
||||
|
||||
|
||||
/**
|
||||
* Set to true to log messages to FirePHP (Firefox Firebug addon).
|
||||
@ -100,15 +106,10 @@ $min_serveOptions['maxAge'] = 1800;
|
||||
|
||||
|
||||
/**
|
||||
* To use Google's Closure Compiler API (falling back to JSMin on failure),
|
||||
* uncomment the following lines:
|
||||
* To use Google's Closure Compiler API to minify Javascript (falling back to JSMin
|
||||
* on failure), uncomment the following line:
|
||||
*/
|
||||
/*function closureCompiler($js) {
|
||||
require_once 'Minify/JS/ClosureCompiler.php';
|
||||
return Minify_JS_ClosureCompiler::minify($js);
|
||||
}
|
||||
$min_serveOptions['minifiers']['application/x-javascript'] = 'closureCompiler';
|
||||
//*/
|
||||
//$min_serveOptions['minifiers']['application/x-javascript'] = array('Minify_JS_ClosureCompiler', 'minify');
|
||||
|
||||
|
||||
/**
|
||||
|
@ -12,10 +12,12 @@ define('MINIFY_MIN_DIR', dirname(__FILE__));
|
||||
// load config
|
||||
require MINIFY_MIN_DIR . '/config.php';
|
||||
|
||||
// setup include path
|
||||
set_include_path($min_libPath . PATH_SEPARATOR . get_include_path());
|
||||
if (isset($_GET['test'])) {
|
||||
include MINIFY_MIN_DIR . '/config-test.php';
|
||||
}
|
||||
|
||||
require 'Minify.php';
|
||||
require "$min_libPath/Minify/Loader.php";
|
||||
Minify_Loader::register();
|
||||
|
||||
Minify::$uploaderHoursBehind = $min_uploaderHoursBehind;
|
||||
Minify::setCache(
|
||||
@ -35,14 +37,11 @@ foreach ($min_symlinks as $uri => $target) {
|
||||
}
|
||||
|
||||
if ($min_allowDebugFlag) {
|
||||
require_once 'Minify/DebugDetector.php';
|
||||
$min_serveOptions['debug'] = Minify_DebugDetector::shouldDebugRequest($_COOKIE, $_GET, $_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
if ($min_errorLogger) {
|
||||
require_once 'Minify/Logger.php';
|
||||
if (true === $min_errorLogger) {
|
||||
require_once 'FirePHP.php';
|
||||
$min_errorLogger = FirePHP::getInstance(true);
|
||||
}
|
||||
Minify_Logger::setLogger($min_errorLogger);
|
||||
@ -60,7 +59,6 @@ if (isset($_GET['f']) || isset($_GET['g'])) {
|
||||
// serve!
|
||||
|
||||
if (! isset($min_serveController)) {
|
||||
require 'Minify/Controller/MinApp.php';
|
||||
$min_serveController = new Minify_Controller_MinApp();
|
||||
}
|
||||
Minify::serve($min_serveController, $min_serveOptions);
|
||||
|
758
phpgwapi/inc/min/lib/CSSmin.php
Executable file
758
phpgwapi/inc/min/lib/CSSmin.php
Executable file
@ -0,0 +1,758 @@
|
||||
<?php
|
||||
|
||||
/*!
|
||||
* cssmin.php rev ebaf67b 12/06/2013
|
||||
* Author: Tubal Martin - http://tubalmartin.me/
|
||||
* Repo: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
|
||||
*
|
||||
* This is a PHP port of the CSS minification tool distributed with YUICompressor,
|
||||
* itself a port of the cssmin utility by Isaac Schlueter - http://foohack.com/
|
||||
* Permission is hereby granted to use the PHP version under the same
|
||||
* conditions as the YUICompressor.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* YUI Compressor
|
||||
* http://developer.yahoo.com/yui/compressor/
|
||||
* Author: Julien Lecomte - http://www.julienlecomte.net/
|
||||
* Copyright (c) 2013 Yahoo! Inc. All rights reserved.
|
||||
* The copyrights embodied in the content of this file are licensed
|
||||
* by Yahoo! Inc. under the BSD (revised) open source license.
|
||||
*/
|
||||
|
||||
class CSSmin
|
||||
{
|
||||
const NL = '___YUICSSMIN_PRESERVED_NL___';
|
||||
const TOKEN = '___YUICSSMIN_PRESERVED_TOKEN_';
|
||||
const COMMENT = '___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_';
|
||||
const CLASSCOLON = '___YUICSSMIN_PSEUDOCLASSCOLON___';
|
||||
const QUERY_FRACTION = '___YUICSSMIN_QUERY_FRACTION___';
|
||||
|
||||
private $comments;
|
||||
private $preserved_tokens;
|
||||
private $memory_limit;
|
||||
private $max_execution_time;
|
||||
private $pcre_backtrack_limit;
|
||||
private $pcre_recursion_limit;
|
||||
private $raise_php_limits;
|
||||
|
||||
/**
|
||||
* @param bool|int $raise_php_limits
|
||||
* If true, PHP settings will be raised if needed
|
||||
*/
|
||||
public function __construct($raise_php_limits = TRUE)
|
||||
{
|
||||
// Set suggested PHP limits
|
||||
$this->memory_limit = 128 * 1048576; // 128MB in bytes
|
||||
$this->max_execution_time = 60; // 1 min
|
||||
$this->pcre_backtrack_limit = 1000 * 1000;
|
||||
$this->pcre_recursion_limit = 500 * 1000;
|
||||
|
||||
$this->raise_php_limits = (bool) $raise_php_limits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify a string of CSS
|
||||
* @param string $css
|
||||
* @param int|bool $linebreak_pos
|
||||
* @return string
|
||||
*/
|
||||
public function run($css = '', $linebreak_pos = FALSE)
|
||||
{
|
||||
if (empty($css)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($this->raise_php_limits) {
|
||||
$this->do_raise_php_limits();
|
||||
}
|
||||
|
||||
$this->comments = array();
|
||||
$this->preserved_tokens = array();
|
||||
|
||||
$start_index = 0;
|
||||
$length = strlen($css);
|
||||
|
||||
$css = $this->extract_data_urls($css);
|
||||
|
||||
// collect all comment blocks...
|
||||
while (($start_index = $this->index_of($css, '/*', $start_index)) >= 0) {
|
||||
$end_index = $this->index_of($css, '*/', $start_index + 2);
|
||||
if ($end_index < 0) {
|
||||
$end_index = $length;
|
||||
}
|
||||
$comment_found = $this->str_slice($css, $start_index + 2, $end_index);
|
||||
$this->comments[] = $comment_found;
|
||||
$comment_preserve_string = self::COMMENT . (count($this->comments) - 1) . '___';
|
||||
$css = $this->str_slice($css, 0, $start_index + 2) . $comment_preserve_string . $this->str_slice($css, $end_index);
|
||||
// Set correct start_index: Fixes issue #2528130
|
||||
$start_index = $end_index + 2 + strlen($comment_preserve_string) - strlen($comment_found);
|
||||
}
|
||||
|
||||
// preserve strings so their content doesn't get accidentally minified
|
||||
$css = preg_replace_callback('/(?:"(?:[^\\\\"]|\\\\.|\\\\)*")|'."(?:'(?:[^\\\\']|\\\\.|\\\\)*')/S", array($this, 'replace_string'), $css);
|
||||
|
||||
// Let's divide css code in chunks of 25.000 chars aprox.
|
||||
// Reason: PHP's PCRE functions like preg_replace have a "backtrack limit"
|
||||
// of 100.000 chars by default (php < 5.3.7) so if we're dealing with really
|
||||
// long strings and a (sub)pattern matches a number of chars greater than
|
||||
// the backtrack limit number (i.e. /(.*)/s) PCRE functions may fail silently
|
||||
// returning NULL and $css would be empty.
|
||||
$charset = '';
|
||||
$charset_regexp = '/(@charset)( [^;]+;)/i';
|
||||
$css_chunks = array();
|
||||
$css_chunk_length = 25000; // aprox size, not exact
|
||||
$start_index = 0;
|
||||
$i = $css_chunk_length; // save initial iterations
|
||||
$l = strlen($css);
|
||||
|
||||
|
||||
// if the number of characters is 25000 or less, do not chunk
|
||||
if ($l <= $css_chunk_length) {
|
||||
$css_chunks[] = $css;
|
||||
} else {
|
||||
// chunk css code securely
|
||||
while ($i < $l) {
|
||||
$i += 50; // save iterations. 500 checks for a closing curly brace }
|
||||
if ($l - $start_index <= $css_chunk_length || $i >= $l) {
|
||||
$css_chunks[] = $this->str_slice($css, $start_index);
|
||||
break;
|
||||
}
|
||||
if ($css[$i - 1] === '}' && $i - $start_index > $css_chunk_length) {
|
||||
// If there are two ending curly braces }} separated or not by spaces,
|
||||
// join them in the same chunk (i.e. @media blocks)
|
||||
$next_chunk = substr($css, $i);
|
||||
if (preg_match('/^\s*\}/', $next_chunk)) {
|
||||
$i = $i + $this->index_of($next_chunk, '}') + 1;
|
||||
}
|
||||
|
||||
$css_chunks[] = $this->str_slice($css, $start_index, $i);
|
||||
$start_index = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Minify each chunk
|
||||
for ($i = 0, $n = count($css_chunks); $i < $n; $i++) {
|
||||
$css_chunks[$i] = $this->minify($css_chunks[$i], $linebreak_pos);
|
||||
// Keep the first @charset at-rule found
|
||||
if (empty($charset) && preg_match($charset_regexp, $css_chunks[$i], $matches)) {
|
||||
$charset = strtolower($matches[1]) . $matches[2];
|
||||
}
|
||||
// Delete all @charset at-rules
|
||||
$css_chunks[$i] = preg_replace($charset_regexp, '', $css_chunks[$i]);
|
||||
}
|
||||
|
||||
// Update the first chunk and push the charset to the top of the file.
|
||||
$css_chunks[0] = $charset . $css_chunks[0];
|
||||
|
||||
return implode('', $css_chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the memory limit for this script
|
||||
* @param int|string $limit
|
||||
*/
|
||||
public function set_memory_limit($limit)
|
||||
{
|
||||
$this->memory_limit = $this->normalize_int($limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum execution time for this script
|
||||
* @param int|string $seconds
|
||||
*/
|
||||
public function set_max_execution_time($seconds)
|
||||
{
|
||||
$this->max_execution_time = (int) $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PCRE backtrack limit for this script
|
||||
* @param int $limit
|
||||
*/
|
||||
public function set_pcre_backtrack_limit($limit)
|
||||
{
|
||||
$this->pcre_backtrack_limit = (int) $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PCRE recursion limit for this script
|
||||
* @param int $limit
|
||||
*/
|
||||
public function set_pcre_recursion_limit($limit)
|
||||
{
|
||||
$this->pcre_recursion_limit = (int) $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to configure PHP to use at least the suggested minimum settings
|
||||
*/
|
||||
private function do_raise_php_limits()
|
||||
{
|
||||
$php_limits = array(
|
||||
'memory_limit' => $this->memory_limit,
|
||||
'max_execution_time' => $this->max_execution_time,
|
||||
'pcre.backtrack_limit' => $this->pcre_backtrack_limit,
|
||||
'pcre.recursion_limit' => $this->pcre_recursion_limit
|
||||
);
|
||||
|
||||
// If current settings are higher respect them.
|
||||
foreach ($php_limits as $name => $suggested) {
|
||||
$current = $this->normalize_int(ini_get($name));
|
||||
// memory_limit exception: allow -1 for "no memory limit".
|
||||
if ($current > -1 && ($suggested == -1 || $current < $suggested)) {
|
||||
ini_set($name, $suggested);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does bulk of the minification
|
||||
* @param string $css
|
||||
* @param int|bool $linebreak_pos
|
||||
* @return string
|
||||
*/
|
||||
private function minify($css, $linebreak_pos)
|
||||
{
|
||||
// strings are safe, now wrestle the comments
|
||||
for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
|
||||
|
||||
$token = $this->comments[$i];
|
||||
$placeholder = '/' . self::COMMENT . $i . '___/';
|
||||
|
||||
// ! in the first position of the comment means preserve
|
||||
// so push to the preserved tokens keeping the !
|
||||
if (substr($token, 0, 1) === '!') {
|
||||
$this->preserved_tokens[] = $token;
|
||||
$token_tring = self::TOKEN . (count($this->preserved_tokens) - 1) . '___';
|
||||
$css = preg_replace($placeholder, $token_tring, $css, 1);
|
||||
// Preserve new lines for /*! important comments
|
||||
$css = preg_replace('/\s*[\n\r\f]+\s*(\/\*'. $token_tring .')/S', self::NL.'$1', $css);
|
||||
$css = preg_replace('/('. $token_tring .'\*\/)\s*[\n\r\f]+\s*/', '$1'.self::NL, $css);
|
||||
continue;
|
||||
}
|
||||
|
||||
// \ in the last position looks like hack for Mac/IE5
|
||||
// shorten that to /*\*/ and the next one to /**/
|
||||
if (substr($token, (strlen($token) - 1), 1) === '\\') {
|
||||
$this->preserved_tokens[] = '\\';
|
||||
$css = preg_replace($placeholder, self::TOKEN . (count($this->preserved_tokens) - 1) . '___', $css, 1);
|
||||
$i = $i + 1; // attn: advancing the loop
|
||||
$this->preserved_tokens[] = '';
|
||||
$css = preg_replace('/' . self::COMMENT . $i . '___/', self::TOKEN . (count($this->preserved_tokens) - 1) . '___', $css, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// keep empty comments after child selectors (IE7 hack)
|
||||
// e.g. html >/**/ body
|
||||
if (strlen($token) === 0) {
|
||||
$start_index = $this->index_of($css, $this->str_slice($placeholder, 1, -1));
|
||||
if ($start_index > 2) {
|
||||
if (substr($css, $start_index - 3, 1) === '>') {
|
||||
$this->preserved_tokens[] = '';
|
||||
$css = preg_replace($placeholder, self::TOKEN . (count($this->preserved_tokens) - 1) . '___', $css, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// in all other cases kill the comment
|
||||
$css = preg_replace('/\/\*' . $this->str_slice($placeholder, 1, -1) . '\*\//', '', $css, 1);
|
||||
}
|
||||
|
||||
|
||||
// Normalize all whitespace strings to single spaces. Easier to work with that way.
|
||||
$css = preg_replace('/\s+/', ' ', $css);
|
||||
|
||||
// Shorten & preserve calculations calc(...) since spaces are important
|
||||
$css = preg_replace_callback('/calc(\(((?:[^\(\)]+|(?1))*)\))/i', array($this, 'replace_calc'), $css);
|
||||
|
||||
// Replace positive sign from numbers preceded by : or a white-space before the leading space is removed
|
||||
// +1.2em to 1.2em, +.8px to .8px, +2% to 2%
|
||||
$css = preg_replace('/((?<!\\\\)\:|\s)\+(\.?\d+)/S', '$1$2', $css);
|
||||
|
||||
// Remove leading zeros from integer and float numbers preceded by : or a white-space
|
||||
// 000.6 to .6, -0.8 to -.8, 0050 to 50, -01.05 to -1.05
|
||||
$css = preg_replace('/((?<!\\\\)\:|\s)(\-?)0+(\.?\d+)/S', '$1$2$3', $css);
|
||||
|
||||
// Remove trailing zeros from float numbers preceded by : or a white-space
|
||||
// -6.0100em to -6.01em, .0100 to .01, 1.200px to 1.2px
|
||||
$css = preg_replace('/((?<!\\\\)\:|\s)(\-?)(\d?\.\d+?)0+([^\d])/S', '$1$2$3$4', $css);
|
||||
|
||||
// Remove trailing .0 -> -9.0 to -9
|
||||
$css = preg_replace('/((?<!\\\\)\:|\s)(\-?\d+)\.0([^\d])/S', '$1$2$3', $css);
|
||||
|
||||
// Replace 0 length numbers with 0
|
||||
$css = preg_replace('/((?<!\\\\)\:|\s)\-?\.?0+([^\d])/S', '${1}0$2', $css);
|
||||
|
||||
// Remove the spaces before the things that should not have spaces before them.
|
||||
// But, be careful not to turn "p :link {...}" into "p:link{...}"
|
||||
// Swap out any pseudo-class colons with the token, and then swap back.
|
||||
$css = preg_replace_callback('/(?:^|\})(?:(?:[^\{\:])+\:)+(?:[^\{]*\{)/', array($this, 'replace_colon'), $css);
|
||||
|
||||
// Remove spaces before the things that should not have spaces before them.
|
||||
$css = preg_replace('/\s+([\!\{\}\;\:\>\+\(\)\]\~\=,])/', '$1', $css);
|
||||
|
||||
// Restore spaces for !important
|
||||
$css = preg_replace('/\!important/i', ' !important', $css);
|
||||
|
||||
// bring back the colon
|
||||
$css = preg_replace('/' . self::CLASSCOLON . '/', ':', $css);
|
||||
|
||||
// retain space for special IE6 cases
|
||||
$css = preg_replace_callback('/\:first\-(line|letter)(\{|,)/i', array($this, 'lowercase_pseudo_first'), $css);
|
||||
|
||||
// no space after the end of a preserved comment
|
||||
$css = preg_replace('/\*\/ /', '*/', $css);
|
||||
|
||||
// lowercase some popular @directives
|
||||
$css = preg_replace_callback('/@(font-face|import|(?:-(?:atsc|khtml|moz|ms|o|wap|webkit)-)?keyframe|media|page|namespace)/i', array($this, 'lowercase_directives'), $css);
|
||||
|
||||
// lowercase some more common pseudo-elements
|
||||
$css = preg_replace_callback('/:(active|after|before|checked|disabled|empty|enabled|first-(?:child|of-type)|focus|hover|last-(?:child|of-type)|link|only-(?:child|of-type)|root|:selection|target|visited)/i', array($this, 'lowercase_pseudo_elements'), $css);
|
||||
|
||||
// lowercase some more common functions
|
||||
$css = preg_replace_callback('/:(lang|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|(?:-(?:moz|webkit)-)?any)\(/i', array($this, 'lowercase_common_functions'), $css);
|
||||
|
||||
// lower case some common function that can be values
|
||||
// NOTE: rgb() isn't useful as we replace with #hex later, as well as and() is already done for us
|
||||
$css = preg_replace_callback('/([:,\( ]\s*)(attr|color-stop|from|rgba|to|url|(?:-(?:atsc|khtml|moz|ms|o|wap|webkit)-)?(?:calc|max|min|(?:repeating-)?(?:linear|radial)-gradient)|-webkit-gradient)/iS', array($this, 'lowercase_common_functions_values'), $css);
|
||||
|
||||
// Put the space back in some cases, to support stuff like
|
||||
// @media screen and (-webkit-min-device-pixel-ratio:0){
|
||||
$css = preg_replace('/\band\(/i', 'and (', $css);
|
||||
|
||||
// Remove the spaces after the things that should not have spaces after them.
|
||||
$css = preg_replace('/([\!\{\}\:;\>\+\(\[\~\=,])\s+/S', '$1', $css);
|
||||
|
||||
// remove unnecessary semicolons
|
||||
$css = preg_replace('/;+\}/', '}', $css);
|
||||
|
||||
// Fix for issue: #2528146
|
||||
// Restore semicolon if the last property is prefixed with a `*` (lte IE7 hack)
|
||||
// to avoid issues on Symbian S60 3.x browsers.
|
||||
$css = preg_replace('/(\*[a-z0-9\-]+\s*\:[^;\}]+)(\})/', '$1;$2', $css);
|
||||
|
||||
// Replace 0 length units 0(px,em,%) with 0.
|
||||
$css = preg_replace('/(^|[^0-9])(?:0?\.)?0(?:em|ex|ch|rem|vw|vh|vm|vmin|cm|mm|in|px|pt|pc|%|deg|g?rad|m?s|k?hz)/iS', '${1}0', $css);
|
||||
|
||||
// Replace 0 0; or 0 0 0; or 0 0 0 0; with 0.
|
||||
$css = preg_replace('/\:0(?: 0){1,3}(;|\}| \!)/', ':0$1', $css);
|
||||
|
||||
// Fix for issue: #2528142
|
||||
// Replace text-shadow:0; with text-shadow:0 0 0;
|
||||
$css = preg_replace('/(text-shadow\:0)(;|\}| \!)/i', '$1 0 0$2', $css);
|
||||
|
||||
// Replace background-position:0; with background-position:0 0;
|
||||
// same for transform-origin
|
||||
// Changing -webkit-mask-position: 0 0 to just a single 0 will result in the second parameter defaulting to 50% (center)
|
||||
$css = preg_replace('/(background\-position|webkit-mask-position|(?:webkit|moz|o|ms|)\-?transform\-origin)\:0(;|\}| \!)/iS', '$1:0 0$2', $css);
|
||||
|
||||
// Shorten colors from rgb(51,102,153) to #336699, rgb(100%,0%,0%) to #ff0000 (sRGB color space)
|
||||
// Shorten colors from hsl(0, 100%, 50%) to #ff0000 (sRGB color space)
|
||||
// This makes it more likely that it'll get further compressed in the next step.
|
||||
$css = preg_replace_callback('/rgb\s*\(\s*([0-9,\s\-\.\%]+)\s*\)(.{1})/i', array($this, 'rgb_to_hex'), $css);
|
||||
$css = preg_replace_callback('/hsl\s*\(\s*([0-9,\s\-\.\%]+)\s*\)(.{1})/i', array($this, 'hsl_to_hex'), $css);
|
||||
|
||||
// Shorten colors from #AABBCC to #ABC or short color name.
|
||||
$css = $this->compress_hex_colors($css);
|
||||
|
||||
// border: none to border:0, outline: none to outline:0
|
||||
$css = preg_replace('/(border\-?(?:top|right|bottom|left|)|outline)\:none(;|\}| \!)/iS', '$1:0$2', $css);
|
||||
|
||||
// shorter opacity IE filter
|
||||
$css = preg_replace('/progid\:DXImageTransform\.Microsoft\.Alpha\(Opacity\=/i', 'alpha(opacity=', $css);
|
||||
|
||||
// Find a fraction that is used for Opera's -o-device-pixel-ratio query
|
||||
// Add token to add the "\" back in later
|
||||
$css = preg_replace('/\(([a-z\-]+):([0-9]+)\/([0-9]+)\)/i', '($1:$2'. self::QUERY_FRACTION .'$3)', $css);
|
||||
|
||||
// Remove empty rules.
|
||||
$css = preg_replace('/[^\};\{\/]+\{\}/S', '', $css);
|
||||
|
||||
// Add "/" back to fix Opera -o-device-pixel-ratio query
|
||||
$css = preg_replace('/'. self::QUERY_FRACTION .'/', '/', $css);
|
||||
|
||||
// Some source control tools don't like it when files containing lines longer
|
||||
// than, say 8000 characters, are checked in. The linebreak option is used in
|
||||
// that case to split long lines after a specific column.
|
||||
if ($linebreak_pos !== FALSE && (int) $linebreak_pos >= 0) {
|
||||
$linebreak_pos = (int) $linebreak_pos;
|
||||
$start_index = $i = 0;
|
||||
while ($i < strlen($css)) {
|
||||
$i++;
|
||||
if ($css[$i - 1] === '}' && $i - $start_index > $linebreak_pos) {
|
||||
$css = $this->str_slice($css, 0, $i) . "\n" . $this->str_slice($css, $i);
|
||||
$start_index = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replace multiple semi-colons in a row by a single one
|
||||
// See SF bug #1980989
|
||||
$css = preg_replace('/;;+/', ';', $css);
|
||||
|
||||
// Restore new lines for /*! important comments
|
||||
$css = preg_replace('/'. self::NL .'/', "\n", $css);
|
||||
|
||||
// Lowercase all uppercase properties
|
||||
$css = preg_replace_callback('/(\{|\;)([A-Z\-]+)(\:)/', array($this, 'lowercase_properties'), $css);
|
||||
|
||||
// restore preserved comments and strings
|
||||
for ($i = 0, $max = count($this->preserved_tokens); $i < $max; $i++) {
|
||||
$css = preg_replace('/' . self::TOKEN . $i . '___/', $this->preserved_tokens[$i], $css, 1);
|
||||
}
|
||||
|
||||
// Trim the final string (for any leading or trailing white spaces)
|
||||
return trim($css);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to replace all data urls with tokens before we start
|
||||
* compressing, to avoid performance issues running some of the subsequent
|
||||
* regexes against large strings chunks.
|
||||
*
|
||||
* @param string $css
|
||||
* @return string
|
||||
*/
|
||||
private function extract_data_urls($css)
|
||||
{
|
||||
// Leave data urls alone to increase parse performance.
|
||||
$max_index = strlen($css) - 1;
|
||||
$append_index = $index = $last_index = $offset = 0;
|
||||
$sb = array();
|
||||
$pattern = '/url\(\s*(["\']?)data\:/i';
|
||||
|
||||
// Since we need to account for non-base64 data urls, we need to handle
|
||||
// ' and ) being part of the data string. Hence switching to indexOf,
|
||||
// to determine whether or not we have matching string terminators and
|
||||
// handling sb appends directly, instead of using matcher.append* methods.
|
||||
|
||||
while (preg_match($pattern, $css, $m, 0, $offset)) {
|
||||
$index = $this->index_of($css, $m[0], $offset);
|
||||
$last_index = $index + strlen($m[0]);
|
||||
$start_index = $index + 4; // "url(".length()
|
||||
$end_index = $last_index - 1;
|
||||
$terminator = $m[1]; // ', " or empty (not quoted)
|
||||
$found_terminator = FALSE;
|
||||
|
||||
if (strlen($terminator) === 0) {
|
||||
$terminator = ')';
|
||||
}
|
||||
|
||||
while ($found_terminator === FALSE && $end_index+1 <= $max_index) {
|
||||
$end_index = $this->index_of($css, $terminator, $end_index + 1);
|
||||
|
||||
// endIndex == 0 doesn't really apply here
|
||||
if ($end_index > 0 && substr($css, $end_index - 1, 1) !== '\\') {
|
||||
$found_terminator = TRUE;
|
||||
if (')' != $terminator) {
|
||||
$end_index = $this->index_of($css, ')', $end_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enough searching, start moving stuff over to the buffer
|
||||
$sb[] = $this->str_slice($css, $append_index, $index);
|
||||
|
||||
if ($found_terminator) {
|
||||
$token = $this->str_slice($css, $start_index, $end_index);
|
||||
$token = preg_replace('/\s+/', '', $token);
|
||||
$this->preserved_tokens[] = $token;
|
||||
|
||||
$preserver = 'url(' . self::TOKEN . (count($this->preserved_tokens) - 1) . '___)';
|
||||
$sb[] = $preserver;
|
||||
|
||||
$append_index = $end_index + 1;
|
||||
} else {
|
||||
// No end terminator found, re-add the whole match. Should we throw/warn here?
|
||||
$sb[] = $this->str_slice($css, $index, $last_index);
|
||||
$append_index = $last_index;
|
||||
}
|
||||
|
||||
$offset = $last_index;
|
||||
}
|
||||
|
||||
$sb[] = $this->str_slice($css, $append_index);
|
||||
|
||||
return implode('', $sb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to compress hex color values of the form #AABBCC to #ABC or short color name.
|
||||
*
|
||||
* DOES NOT compress CSS ID selectors which match the above pattern (which would break things).
|
||||
* e.g. #AddressForm { ... }
|
||||
*
|
||||
* DOES NOT compress IE filters, which have hex color values (which would break things).
|
||||
* e.g. filter: chroma(color="#FFFFFF");
|
||||
*
|
||||
* DOES NOT compress invalid hex values.
|
||||
* e.g. background-color: #aabbccdd
|
||||
*
|
||||
* @param string $css
|
||||
* @return string
|
||||
*/
|
||||
private function compress_hex_colors($css)
|
||||
{
|
||||
// Look for hex colors inside { ... } (to avoid IDs) and which don't have a =, or a " in front of them (to avoid filters)
|
||||
$pattern = '/(\=\s*?["\']?)?#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])(\}|[^0-9a-f{][^{]*?\})/iS';
|
||||
$_index = $index = $last_index = $offset = 0;
|
||||
$sb = array();
|
||||
// See: http://ajaxmin.codeplex.com/wikipage?title=CSS%20Colors
|
||||
$short_safe = array(
|
||||
'#808080' => 'gray',
|
||||
'#008000' => 'green',
|
||||
'#800000' => 'maroon',
|
||||
'#000080' => 'navy',
|
||||
'#808000' => 'olive',
|
||||
'#ffa500' => 'orange',
|
||||
'#800080' => 'purple',
|
||||
'#c0c0c0' => 'silver',
|
||||
'#008080' => 'teal',
|
||||
'#f00' => 'red'
|
||||
);
|
||||
|
||||
while (preg_match($pattern, $css, $m, 0, $offset)) {
|
||||
$index = $this->index_of($css, $m[0], $offset);
|
||||
$last_index = $index + strlen($m[0]);
|
||||
$is_filter = $m[1] !== null && $m[1] !== '';
|
||||
|
||||
$sb[] = $this->str_slice($css, $_index, $index);
|
||||
|
||||
if ($is_filter) {
|
||||
// Restore, maintain case, otherwise filter will break
|
||||
$sb[] = $m[1] . '#' . $m[2] . $m[3] . $m[4] . $m[5] . $m[6] . $m[7];
|
||||
} else {
|
||||
if (strtolower($m[2]) == strtolower($m[3]) &&
|
||||
strtolower($m[4]) == strtolower($m[5]) &&
|
||||
strtolower($m[6]) == strtolower($m[7])) {
|
||||
// Compress.
|
||||
$hex = '#' . strtolower($m[3] . $m[5] . $m[7]);
|
||||
} else {
|
||||
// Non compressible color, restore but lower case.
|
||||
$hex = '#' . strtolower($m[2] . $m[3] . $m[4] . $m[5] . $m[6] . $m[7]);
|
||||
}
|
||||
// replace Hex colors to short safe color names
|
||||
$sb[] = array_key_exists($hex, $short_safe) ? $short_safe[$hex] : $hex;
|
||||
}
|
||||
|
||||
$_index = $offset = $last_index - strlen($m[8]);
|
||||
}
|
||||
|
||||
$sb[] = $this->str_slice($css, $_index);
|
||||
|
||||
return implode('', $sb);
|
||||
}
|
||||
|
||||
/* CALLBACKS
|
||||
* ---------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private function replace_string($matches)
|
||||
{
|
||||
$match = $matches[0];
|
||||
$quote = substr($match, 0, 1);
|
||||
// Must use addcslashes in PHP to avoid parsing of backslashes
|
||||
$match = addcslashes($this->str_slice($match, 1, -1), '\\');
|
||||
|
||||
// maybe the string contains a comment-like substring?
|
||||
// one, maybe more? put'em back then
|
||||
if (($pos = $this->index_of($match, self::COMMENT)) >= 0) {
|
||||
for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
|
||||
$match = preg_replace('/' . self::COMMENT . $i . '___/', $this->comments[$i], $match, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// minify alpha opacity in filter strings
|
||||
$match = preg_replace('/progid\:DXImageTransform\.Microsoft\.Alpha\(Opacity\=/i', 'alpha(opacity=', $match);
|
||||
|
||||
$this->preserved_tokens[] = $match;
|
||||
return $quote . self::TOKEN . (count($this->preserved_tokens) - 1) . '___' . $quote;
|
||||
}
|
||||
|
||||
private function replace_colon($matches)
|
||||
{
|
||||
return preg_replace('/\:/', self::CLASSCOLON, $matches[0]);
|
||||
}
|
||||
|
||||
private function replace_calc($matches)
|
||||
{
|
||||
$this->preserved_tokens[] = trim(preg_replace('/\s*([\*\/\(\),])\s*/', '$1', $matches[2]));
|
||||
return 'calc('. self::TOKEN . (count($this->preserved_tokens) - 1) . '___' . ')';
|
||||
}
|
||||
|
||||
private function rgb_to_hex($matches)
|
||||
{
|
||||
// Support for percentage values rgb(100%, 0%, 45%);
|
||||
if ($this->index_of($matches[1], '%') >= 0){
|
||||
$rgbcolors = explode(',', str_replace('%', '', $matches[1]));
|
||||
for ($i = 0; $i < count($rgbcolors); $i++) {
|
||||
$rgbcolors[$i] = $this->round_number(floatval($rgbcolors[$i]) * 2.55);
|
||||
}
|
||||
} else {
|
||||
$rgbcolors = explode(',', $matches[1]);
|
||||
}
|
||||
|
||||
// Values outside the sRGB color space should be clipped (0-255)
|
||||
for ($i = 0; $i < count($rgbcolors); $i++) {
|
||||
$rgbcolors[$i] = $this->clamp_number(intval($rgbcolors[$i], 10), 0, 255);
|
||||
$rgbcolors[$i] = sprintf("%02x", $rgbcolors[$i]);
|
||||
}
|
||||
|
||||
// Fix for issue #2528093
|
||||
if (!preg_match('/[\s\,\);\}]/', $matches[2])){
|
||||
$matches[2] = ' ' . $matches[2];
|
||||
}
|
||||
|
||||
return '#' . implode('', $rgbcolors) . $matches[2];
|
||||
}
|
||||
|
||||
private function hsl_to_hex($matches)
|
||||
{
|
||||
$values = explode(',', str_replace('%', '', $matches[1]));
|
||||
$h = floatval($values[0]);
|
||||
$s = floatval($values[1]);
|
||||
$l = floatval($values[2]);
|
||||
|
||||
// Wrap and clamp, then fraction!
|
||||
$h = ((($h % 360) + 360) % 360) / 360;
|
||||
$s = $this->clamp_number($s, 0, 100) / 100;
|
||||
$l = $this->clamp_number($l, 0, 100) / 100;
|
||||
|
||||
if ($s == 0) {
|
||||
$r = $g = $b = $this->round_number(255 * $l);
|
||||
} else {
|
||||
$v2 = $l < 0.5 ? $l * (1 + $s) : ($l + $s) - ($s * $l);
|
||||
$v1 = (2 * $l) - $v2;
|
||||
$r = $this->round_number(255 * $this->hue_to_rgb($v1, $v2, $h + (1/3)));
|
||||
$g = $this->round_number(255 * $this->hue_to_rgb($v1, $v2, $h));
|
||||
$b = $this->round_number(255 * $this->hue_to_rgb($v1, $v2, $h - (1/3)));
|
||||
}
|
||||
|
||||
return $this->rgb_to_hex(array('', $r.','.$g.','.$b, $matches[2]));
|
||||
}
|
||||
|
||||
private function lowercase_pseudo_first($matches)
|
||||
{
|
||||
return ':first-'. strtolower($matches[1]) .' '. $matches[2];
|
||||
}
|
||||
|
||||
private function lowercase_directives($matches)
|
||||
{
|
||||
return '@'. strtolower($matches[1]);
|
||||
}
|
||||
|
||||
private function lowercase_pseudo_elements($matches)
|
||||
{
|
||||
return ':'. strtolower($matches[1]);
|
||||
}
|
||||
|
||||
private function lowercase_common_functions($matches)
|
||||
{
|
||||
return ':'. strtolower($matches[1]) .'(';
|
||||
}
|
||||
|
||||
private function lowercase_common_functions_values($matches)
|
||||
{
|
||||
return $matches[1] . strtolower($matches[2]);
|
||||
}
|
||||
|
||||
private function lowercase_properties($matches)
|
||||
{
|
||||
return $matches[1].strtolower($matches[2]).$matches[3];
|
||||
}
|
||||
|
||||
/* HELPERS
|
||||
* ---------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private function hue_to_rgb($v1, $v2, $vh)
|
||||
{
|
||||
$vh = $vh < 0 ? $vh + 1 : ($vh > 1 ? $vh - 1 : $vh);
|
||||
if ($vh * 6 < 1) return $v1 + ($v2 - $v1) * 6 * $vh;
|
||||
if ($vh * 2 < 1) return $v2;
|
||||
if ($vh * 3 < 2) return $v1 + ($v2 - $v1) * ((2/3) - $vh) * 6;
|
||||
return $v1;
|
||||
}
|
||||
|
||||
private function round_number($n)
|
||||
{
|
||||
return intval(floor(floatval($n) + 0.5), 10);
|
||||
}
|
||||
|
||||
private function clamp_number($n, $min, $max)
|
||||
{
|
||||
return min(max($n, $min), $max);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP port of Javascript's "indexOf" function for strings only
|
||||
* Author: Tubal Martin http://blog.margenn.com
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
* @param int $offset index (optional)
|
||||
* @return int
|
||||
*/
|
||||
private function index_of($haystack, $needle, $offset = 0)
|
||||
{
|
||||
$index = strpos($haystack, $needle, $offset);
|
||||
|
||||
return ($index !== FALSE) ? $index : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP port of Javascript's "slice" function for strings only
|
||||
* Author: Tubal Martin http://blog.margenn.com
|
||||
* Tests: http://margenn.com/tubal/str_slice/
|
||||
*
|
||||
* @param string $str
|
||||
* @param int $start index
|
||||
* @param int|bool $end index (optional)
|
||||
* @return string
|
||||
*/
|
||||
private function str_slice($str, $start = 0, $end = FALSE)
|
||||
{
|
||||
if ($end !== FALSE && ($start < 0 || $end <= 0)) {
|
||||
$max = strlen($str);
|
||||
|
||||
if ($start < 0) {
|
||||
if (($start = $max + $start) < 0) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($end < 0) {
|
||||
if (($end = $max + $end) < 0) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($end <= $start) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
$slice = ($end === FALSE) ? substr($str, $start) : substr($str, $start, $end - $start);
|
||||
return ($slice === FALSE) ? '' : $slice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert strings like "64M" or "30" to int values
|
||||
* @param mixed $size
|
||||
* @return int
|
||||
*/
|
||||
private function normalize_int($size)
|
||||
{
|
||||
if (is_string($size)) {
|
||||
switch (substr($size, -1)) {
|
||||
case 'M': case 'm': return $size * 1048576;
|
||||
case 'K': case 'k': return $size * 1024;
|
||||
case 'G': case 'g': return $size * 1073741824;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) $size;
|
||||
}
|
||||
}
|
121
phpgwapi/inc/min/lib/DooDigestAuth.php
Executable file
121
phpgwapi/inc/min/lib/DooDigestAuth.php
Executable file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* DooDigestAuth class file.
|
||||
*
|
||||
* @author Leng Sheng Hong <darkredz@gmail.com>
|
||||
* @link http://www.doophp.com/
|
||||
* @copyright Copyright © 2009 Leng Sheng Hong
|
||||
* @license http://www.doophp.com/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles HTTP digest authentication
|
||||
*
|
||||
* <p>HTTP digest authentication can be used with the URI router.
|
||||
* HTTP digest is much more recommended over the use of HTTP Basic auth which doesn't provide any encryption.
|
||||
* If you are running PHP on Apache in CGI/FastCGI mode, you would need to
|
||||
* add the following line to your .htaccess for digest auth to work correctly.</p>
|
||||
* <code>RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]</code>
|
||||
*
|
||||
* <p>This class is tested under Apache 2.2 and Cherokee web server. It should work in both mod_php and cgi mode.</p>
|
||||
*
|
||||
* @author Leng Sheng Hong <darkredz@gmail.com>
|
||||
* @version $Id: DooDigestAuth.php 1000 2009-07-7 18:27:22
|
||||
* @package doo.auth
|
||||
* @since 1.0
|
||||
*/
|
||||
class DooDigestAuth{
|
||||
|
||||
/**
|
||||
* Authenticate against a list of username and passwords.
|
||||
*
|
||||
* <p>HTTP Digest Authentication doesn't work with PHP in CGI mode,
|
||||
* you have to add this into your .htaccess <code>RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]</code></p>
|
||||
*
|
||||
* @param string $realm Name of the authentication session
|
||||
* @param array $users An assoc array of username and password: array('uname1'=>'pwd1', 'uname2'=>'pwd2')
|
||||
* @param string $fail_msg Message to be displayed if the User cancel the login
|
||||
* @param string $fail_url URL to be redirect if the User cancel the login
|
||||
* @return string The username if login success.
|
||||
*/
|
||||
public static function http_auth($realm, $users, $fail_msg=NULL, $fail_url=NULL){
|
||||
$realm = "Restricted area - $realm";
|
||||
|
||||
//user => password
|
||||
//$users = array('admin' => '1234', 'guest' => 'guest');
|
||||
if(!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && strpos($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 'Digest')===0){
|
||||
$_SERVER['PHP_AUTH_DIGEST'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
|
||||
}
|
||||
|
||||
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
|
||||
header('WWW-Authenticate: Digest realm="'.$realm.
|
||||
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
if($fail_msg!=NULL)
|
||||
die($fail_msg);
|
||||
if($fail_url!=NULL)
|
||||
die("<script>window.location.href = '$fail_url'</script>");
|
||||
exit;
|
||||
}
|
||||
|
||||
// analyze the PHP_AUTH_DIGEST variable
|
||||
if (!($data = self::http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($users[$data['username']])){
|
||||
header('WWW-Authenticate: Digest realm="'.$realm.
|
||||
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
if($fail_msg!=NULL)
|
||||
die($fail_msg);
|
||||
if($fail_url!=NULL)
|
||||
die("<script>window.location.href = '$fail_url'</script>");
|
||||
exit;
|
||||
}
|
||||
|
||||
// generate the valid response
|
||||
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
|
||||
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
|
||||
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
|
||||
|
||||
if ($data['response'] != $valid_response){
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
header('WWW-Authenticate: Digest realm="'.$realm.
|
||||
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
||||
if($fail_msg!=NULL)
|
||||
die($fail_msg);
|
||||
if($fail_url!=NULL)
|
||||
die("<script>window.location.href = '$fail_url'</script>");
|
||||
exit;
|
||||
}
|
||||
|
||||
// ok, valid username & password
|
||||
return $data['username'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to parse the http auth header, works with IE.
|
||||
*
|
||||
* Internet Explorer returns a qop="xxxxxxxxxxx" in the header instead of qop=xxxxxxxxxxx as most browsers do.
|
||||
*
|
||||
* @param string $txt header string to parse
|
||||
* @return array An assoc array of the digest auth session
|
||||
*/
|
||||
private static function http_digest_parse($txt)
|
||||
{
|
||||
$res = preg_match("/username=\"([^\"]+)\"/i", $txt, $match);
|
||||
$data['username'] = (isset($match[1]))?$match[1]:null;
|
||||
$res = preg_match('/nonce=\"([^\"]+)\"/i', $txt, $match);
|
||||
$data['nonce'] = $match[1];
|
||||
$res = preg_match('/nc=([0-9]+)/i', $txt, $match);
|
||||
$data['nc'] = $match[1];
|
||||
$res = preg_match('/cnonce=\"([^\"]+)\"/i', $txt, $match);
|
||||
$data['cnonce'] = $match[1];
|
||||
$res = preg_match('/qop=([^,]+)/i', $txt, $match);
|
||||
$data['qop'] = str_replace('"','',$match[1]);
|
||||
$res = preg_match('/uri=\"([^\"]+)\"/i', $txt, $match);
|
||||
$data['uri'] = $match[1];
|
||||
$res = preg_match('/response=\"([^\"]+)\"/i', $txt, $match);
|
||||
$data['response'] = $match[1];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -69,6 +69,7 @@ class JSMin {
|
||||
protected $lookAhead = null;
|
||||
protected $output = '';
|
||||
protected $lastByteOut = '';
|
||||
protected $keptComment = '';
|
||||
|
||||
/**
|
||||
* Minify Javascript.
|
||||
@ -117,7 +118,7 @@ class JSMin {
|
||||
$command = self::ACTION_KEEP_A; // default
|
||||
if ($this->a === ' ') {
|
||||
if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
|
||||
&& ($this->b === $this->lastByteOut)) {
|
||||
&& ($this->b === $this->lastByteOut)) {
|
||||
// Don't delete this space. If we do, the addition/subtraction
|
||||
// could be parsed as a post-increment
|
||||
} elseif (! $this->isAlphaNum($this->b)) {
|
||||
@ -126,10 +127,11 @@ class JSMin {
|
||||
} elseif ($this->a === "\n") {
|
||||
if ($this->b === ' ') {
|
||||
$command = self::ACTION_DELETE_A_B;
|
||||
// in case of mbstring.func_overload & 2, must check for null b,
|
||||
// otherwise mb_strpos will give WARNING
|
||||
|
||||
// in case of mbstring.func_overload & 2, must check for null b,
|
||||
// otherwise mb_strpos will give WARNING
|
||||
} elseif ($this->b === null
|
||||
|| (false === strpos('{[(+-', $this->b)
|
||||
|| (false === strpos('{[(+-!~', $this->b)
|
||||
&& ! $this->isAlphaNum($this->b))) {
|
||||
$command = self::ACTION_DELETE_A;
|
||||
}
|
||||
@ -160,6 +162,7 @@ class JSMin {
|
||||
*/
|
||||
protected function action($command)
|
||||
{
|
||||
// make sure we don't compress "a + ++b" to "a+++b", etc.
|
||||
if ($command === self::ACTION_DELETE_A_B
|
||||
&& $this->b === ' '
|
||||
&& ($this->a === '+' || $this->a === '-')) {
|
||||
@ -170,28 +173,35 @@ class JSMin {
|
||||
$command = self::ACTION_KEEP_A;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($command) {
|
||||
case self::ACTION_KEEP_A:
|
||||
case self::ACTION_KEEP_A: // 1
|
||||
$this->output .= $this->a;
|
||||
|
||||
if ($this->keptComment) {
|
||||
$this->output = rtrim($this->output, "\n");
|
||||
$this->output .= $this->keptComment;
|
||||
$this->keptComment = '';
|
||||
}
|
||||
|
||||
$this->lastByteOut = $this->a;
|
||||
|
||||
// fallthrough
|
||||
case self::ACTION_DELETE_A:
|
||||
// fallthrough intentional
|
||||
case self::ACTION_DELETE_A: // 2
|
||||
$this->a = $this->b;
|
||||
if ($this->a === "'" || $this->a === '"') { // string literal
|
||||
$str = $this->a; // in case needed for exception
|
||||
while (true) {
|
||||
for(;;) {
|
||||
$this->output .= $this->a;
|
||||
$this->lastByteOut = $this->a;
|
||||
|
||||
$this->a = $this->get();
|
||||
$this->a = $this->get();
|
||||
if ($this->a === $this->b) { // end quote
|
||||
break;
|
||||
}
|
||||
if (ord($this->a) <= self::ORD_LF) {
|
||||
if ($this->isEOF($this->a)) {
|
||||
throw new JSMin_UnterminatedStringException(
|
||||
"JSMin: Unterminated String at byte "
|
||||
. $this->inputIndex . ": {$str}");
|
||||
"JSMin: Unterminated String at byte {$this->inputIndex}: {$str}");
|
||||
}
|
||||
$str .= $this->a;
|
||||
if ($this->a === '\\') {
|
||||
@ -203,25 +213,46 @@ class JSMin {
|
||||
}
|
||||
}
|
||||
}
|
||||
// fallthrough
|
||||
case self::ACTION_DELETE_A_B:
|
||||
|
||||
// fallthrough intentional
|
||||
case self::ACTION_DELETE_A_B: // 3
|
||||
$this->b = $this->next();
|
||||
if ($this->b === '/' && $this->isRegexpLiteral()) { // RegExp literal
|
||||
if ($this->b === '/' && $this->isRegexpLiteral()) {
|
||||
$this->output .= $this->a . $this->b;
|
||||
$pattern = '/'; // in case needed for exception
|
||||
while (true) {
|
||||
$pattern = '/'; // keep entire pattern in case we need to report it in the exception
|
||||
for(;;) {
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
if ($this->a === '[') {
|
||||
for(;;) {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
if ($this->a === ']') {
|
||||
break;
|
||||
}
|
||||
if ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
}
|
||||
if ($this->isEOF($this->a)) {
|
||||
throw new JSMin_UnterminatedRegExpException(
|
||||
"JSMin: Unterminated set in RegExp at byte "
|
||||
. $this->inputIndex .": {$pattern}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->a === '/') { // end pattern
|
||||
break; // while (true)
|
||||
} elseif ($this->a === '\\') {
|
||||
$this->output .= $this->a;
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
} elseif (ord($this->a) <= self::ORD_LF) {
|
||||
$this->a = $this->get();
|
||||
$pattern .= $this->a;
|
||||
} elseif ($this->isEOF($this->a)) {
|
||||
throw new JSMin_UnterminatedRegExpException(
|
||||
"JSMin: Unterminated RegExp at byte "
|
||||
. $this->inputIndex .": {$pattern}");
|
||||
"JSMin: Unterminated RegExp at byte {$this->inputIndex}: {$pattern}");
|
||||
}
|
||||
$this->output .= $this->a;
|
||||
$this->lastByteOut = $this->a;
|
||||
@ -237,10 +268,11 @@ class JSMin {
|
||||
*/
|
||||
protected function isRegexpLiteral()
|
||||
{
|
||||
if (false !== strpos("\n{;(,=:[!&|?", $this->a)) { // we aren't dividing
|
||||
if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
|
||||
// we obviously aren't dividing
|
||||
return true;
|
||||
}
|
||||
if (' ' === $this->a) {
|
||||
if ($this->a === ' ' || $this->a === "\n") {
|
||||
$length = strlen($this->output);
|
||||
if ($length < 2) { // weird edge case
|
||||
return true;
|
||||
@ -261,7 +293,8 @@ class JSMin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char. Convert ctrl char to space.
|
||||
* Return the next character from stdin. Watch out for lookahead. If the character is a control character,
|
||||
* translate it to a space or linefeed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -270,24 +303,36 @@ class JSMin {
|
||||
$c = $this->lookAhead;
|
||||
$this->lookAhead = null;
|
||||
if ($c === null) {
|
||||
// getc(stdin)
|
||||
if ($this->inputIndex < $this->inputLength) {
|
||||
$c = $this->input[$this->inputIndex];
|
||||
$this->inputIndex += 1;
|
||||
} else {
|
||||
return null;
|
||||
$c = null;
|
||||
}
|
||||
}
|
||||
if ($c === "\r" || $c === "\n") {
|
||||
if (ord($c) >= self::ORD_SPACE || $c === "\n" || $c === null) {
|
||||
return $c;
|
||||
}
|
||||
if ($c === "\r") {
|
||||
return "\n";
|
||||
}
|
||||
if (ord($c) < self::ORD_SPACE) { // control char
|
||||
return ' ';
|
||||
}
|
||||
return $c;
|
||||
return ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char. If is ctrl character, translate to a space or newline.
|
||||
* Does $a indicate end of input?
|
||||
*
|
||||
* @param string $a
|
||||
* @return bool
|
||||
*/
|
||||
protected function isEOF($a)
|
||||
{
|
||||
return ord($a) <= self::ORD_LF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next char (without getting it). If is ctrl character, translate to a space or newline.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -298,7 +343,7 @@ class JSMin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII?
|
||||
* Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
|
||||
*
|
||||
* @param string $c
|
||||
*
|
||||
@ -306,77 +351,84 @@ class JSMin {
|
||||
*/
|
||||
protected function isAlphaNum($c)
|
||||
{
|
||||
return (preg_match('/^[0-9a-zA-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
||||
return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* Consume a single line comment from input (possibly retaining it)
|
||||
*/
|
||||
protected function singleLineComment()
|
||||
protected function consumeSingleLineComment()
|
||||
{
|
||||
$comment = '';
|
||||
while (true) {
|
||||
$get = $this->get();
|
||||
$comment .= $get;
|
||||
if (ord($get) <= self::ORD_LF) { // EOL reached
|
||||
if (ord($get) <= self::ORD_LF) { // end of line reached
|
||||
// if IE conditional comment
|
||||
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
return "/{$comment}";
|
||||
$this->keptComment .= "/{$comment}";
|
||||
}
|
||||
return $get;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* Consume a multiple line comment from input (possibly retaining it)
|
||||
*
|
||||
* @throws JSMin_UnterminatedCommentException
|
||||
*/
|
||||
protected function multipleLineComment()
|
||||
protected function consumeMultipleLineComment()
|
||||
{
|
||||
$this->get();
|
||||
$comment = '';
|
||||
while (true) {
|
||||
for(;;) {
|
||||
$get = $this->get();
|
||||
if ($get === '*') {
|
||||
if ($this->peek() === '/') { // end of comment reached
|
||||
$this->get();
|
||||
// if comment preserved by YUI Compressor
|
||||
if (0 === strpos($comment, '!')) {
|
||||
return "\n/*!" . substr($comment, 1) . "*/\n";
|
||||
// preserved by YUI Compressor
|
||||
if (!$this->keptComment) {
|
||||
// don't prepend a newline if two comments right after one another
|
||||
$this->keptComment = "\n";
|
||||
}
|
||||
$this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
|
||||
} else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
// IE conditional
|
||||
$this->keptComment .= "/*{$comment}*/";
|
||||
}
|
||||
// if IE conditional comment
|
||||
if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||
return "/*{$comment}*/";
|
||||
}
|
||||
return ' ';
|
||||
return;
|
||||
}
|
||||
} elseif ($get === null) {
|
||||
throw new JSMin_UnterminatedCommentException(
|
||||
"JSMin: Unterminated comment at byte "
|
||||
. $this->inputIndex . ": /*{$comment}");
|
||||
"JSMin: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
|
||||
}
|
||||
$comment .= $get;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next character, skipping over comments.
|
||||
* Some comments may be preserved.
|
||||
* Get the next character, skipping over comments. Some comments may be preserved.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function next()
|
||||
{
|
||||
$get = $this->get();
|
||||
if ($get !== '/') {
|
||||
return $get;
|
||||
}
|
||||
switch ($this->peek()) {
|
||||
case '/': return $this->singleLineComment();
|
||||
case '*': return $this->multipleLineComment();
|
||||
default: return $get;
|
||||
if ($get === '/') {
|
||||
switch ($this->peek()) {
|
||||
case '/':
|
||||
$this->consumeSingleLineComment();
|
||||
$get = "\n";
|
||||
break;
|
||||
case '*':
|
||||
$this->consumeMultipleLineComment();
|
||||
$get = ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $get;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Minify_Source
|
||||
*/
|
||||
require_once 'Minify/Source.php';
|
||||
|
||||
/**
|
||||
* Minify - Combines, minifies, and caches JavaScript and CSS files on demand.
|
||||
*
|
||||
@ -29,7 +24,7 @@ require_once 'Minify/Source.php';
|
||||
*/
|
||||
class Minify {
|
||||
|
||||
const VERSION = '2.1.5';
|
||||
const VERSION = '2.1.7';
|
||||
const TYPE_CSS = 'text/css';
|
||||
const TYPE_HTML = 'text/html';
|
||||
// there is some debate over the ideal JS Content-Type, but this is the
|
||||
@ -85,7 +80,6 @@ class Minify {
|
||||
public static function setCache($cache = '', $fileLocking = true)
|
||||
{
|
||||
if (is_string($cache)) {
|
||||
require_once 'Minify/Cache/File.php';
|
||||
self::$_cache = new Minify_Cache_File($cache, $fileLocking);
|
||||
} else {
|
||||
self::$_cache = $cache;
|
||||
@ -161,9 +155,11 @@ class Minify {
|
||||
*
|
||||
* @param array $options controller/serve options
|
||||
*
|
||||
* @return mixed null, or, if the 'quiet' option is set to true, an array
|
||||
* @return null|array if the 'quiet' option is set to true, an array
|
||||
* with keys "success" (bool), "statusCode" (int), "content" (string), and
|
||||
* "headers" (array).
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function serve($controller, $options = array())
|
||||
{
|
||||
@ -174,10 +170,6 @@ class Minify {
|
||||
if (is_string($controller)) {
|
||||
// make $controller into object
|
||||
$class = 'Minify_Controller_' . $controller;
|
||||
if (! class_exists($class, false)) {
|
||||
require_once "Minify/Controller/"
|
||||
. str_replace('_', '/', $controller) . ".php";
|
||||
}
|
||||
$controller = new $class();
|
||||
/* @var Minify_Controller_Base $controller */
|
||||
}
|
||||
@ -219,7 +211,6 @@ class Minify {
|
||||
$contentEncoding = self::$_options['encodeMethod'];
|
||||
} else {
|
||||
// sniff request header
|
||||
require_once 'HTTP/Encoder.php';
|
||||
// depending on what the client accepts, $contentEncoding may be
|
||||
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
|
||||
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
|
||||
@ -231,7 +222,6 @@ class Minify {
|
||||
}
|
||||
|
||||
// check client cache
|
||||
require_once 'HTTP/ConditionalGet.php';
|
||||
$cgOptions = array(
|
||||
'lastModifiedTime' => self::$_options['lastModifiedTime']
|
||||
,'isPublic' => self::$_options['isPublic']
|
||||
@ -300,7 +290,7 @@ class Minify {
|
||||
throw $e;
|
||||
}
|
||||
self::$_cache->store($cacheId, $content);
|
||||
if (function_exists('gzencode')) {
|
||||
if (function_exists('gzencode') && self::$_options['encodeMethod']) {
|
||||
self::$_cache->store($cacheId . '.gz', gzencode($content, self::$_options['encodeLevel']));
|
||||
}
|
||||
}
|
||||
@ -451,7 +441,7 @@ class Minify {
|
||||
/**
|
||||
* Set up sources to use Minify_Lines
|
||||
*
|
||||
* @param array $sources Minify_Source instances
|
||||
* @param Minify_Source[] $sources Minify_Source instances
|
||||
*/
|
||||
protected static function _setupDebug($sources)
|
||||
{
|
||||
@ -468,6 +458,8 @@ class Minify {
|
||||
* Combines sources and minifies the result.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected static function _combineMinify()
|
||||
{
|
||||
@ -526,7 +518,6 @@ class Minify {
|
||||
$imploded = implode($implodeSeparator, $groupToProcessTogether);
|
||||
$groupToProcessTogether = array();
|
||||
if ($lastMinifier) {
|
||||
self::$_controller->loadMinifier($lastMinifier);
|
||||
try {
|
||||
$content[] = call_user_func($lastMinifier, $imploded, $lastOptions);
|
||||
} catch (Exception $e) {
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Source.php';
|
||||
|
||||
/**
|
||||
* Maintain a single last modification time for a group of Minify sources to
|
||||
* allow use of far off Expires headers in Minify.
|
||||
|
@ -56,6 +56,7 @@ class Minify_CSS {
|
||||
public static function minify($css, $options = array())
|
||||
{
|
||||
$options = array_merge(array(
|
||||
'compress' => true,
|
||||
'removeCharsets' => true,
|
||||
'preserveComments' => true,
|
||||
'currentDir' => null,
|
||||
@ -67,21 +68,20 @@ class Minify_CSS {
|
||||
if ($options['removeCharsets']) {
|
||||
$css = preg_replace('/@charset[^;]+;\\s*/', '', $css);
|
||||
}
|
||||
require_once 'Minify/CSS/Compressor.php';
|
||||
if (! $options['preserveComments']) {
|
||||
$css = Minify_CSS_Compressor::process($css, $options);
|
||||
} else {
|
||||
require_once 'Minify/CommentPreserver.php';
|
||||
$css = Minify_CommentPreserver::process(
|
||||
$css
|
||||
,array('Minify_CSS_Compressor', 'process')
|
||||
,array($options)
|
||||
);
|
||||
if ($options['compress']) {
|
||||
if (! $options['preserveComments']) {
|
||||
$css = Minify_CSS_Compressor::process($css, $options);
|
||||
} else {
|
||||
$css = Minify_CommentPreserver::process(
|
||||
$css
|
||||
,array('Minify_CSS_Compressor', 'process')
|
||||
,array($options)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (! $options['currentDir'] && ! $options['prependRelativePath']) {
|
||||
return $css;
|
||||
}
|
||||
require_once 'Minify/CSS/UriRewriter.php';
|
||||
if ($options['currentDir']) {
|
||||
return Minify_CSS_UriRewriter::rewrite(
|
||||
$css
|
||||
|
@ -186,7 +186,6 @@ class Minify_Cache_File {
|
||||
*/
|
||||
protected function _log($msg)
|
||||
{
|
||||
require_once 'Minify/Logger.php';
|
||||
Minify_Logger::log($msg);
|
||||
}
|
||||
|
||||
|
126
phpgwapi/inc/min/lib/Minify/Cache/XCache.php
Executable file
126
phpgwapi/inc/min/lib/Minify/Cache/XCache.php
Executable file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Cache_XCache
|
||||
*
|
||||
* @link http://xcache.lighttpd.net/
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* XCache-based cache class for Minify
|
||||
* {@see http://xcache.lighttpd.net/wiki/XcacheApi XCache API}
|
||||
*
|
||||
* <code>
|
||||
* Minify::setCache(new Minify_Cache_XCache());
|
||||
* </code>
|
||||
*
|
||||
* @package Minify
|
||||
* @author Elan Ruusamäe <glen@delfi.ee>
|
||||
**/
|
||||
class Minify_Cache_XCache {
|
||||
|
||||
/**
|
||||
* Create a Minify_Cache_XCache object, to be passed to
|
||||
* Minify::setCache().
|
||||
*
|
||||
* @param int $expire seconds until expiration (default = 0
|
||||
* meaning the item will not get an expiration date)
|
||||
*/
|
||||
public function __construct($expire = 0)
|
||||
{
|
||||
$this->_exp = $expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to cache.
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param string $data
|
||||
* @return bool success
|
||||
*/
|
||||
public function store($id, $data)
|
||||
{
|
||||
return xcache_set($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of a cache entry
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return int size in bytes
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
if (! $this->_fetch($id)) {
|
||||
return false;
|
||||
}
|
||||
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||
? mb_strlen($this->_data, '8bit')
|
||||
: strlen($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a valid cache entry exist?
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $srcMtime mtime of the original source file(s)
|
||||
* @return bool exists
|
||||
*/
|
||||
public function isValid($id, $srcMtime)
|
||||
{
|
||||
return ($this->_fetch($id) && ($this->_lm >= $srcMtime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the cached content to output
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function display($id)
|
||||
{
|
||||
echo $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached content
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? $this->_data
|
||||
: '';
|
||||
}
|
||||
|
||||
private $_exp = null;
|
||||
|
||||
// cache of most recently fetched id
|
||||
private $_lm = null;
|
||||
private $_data = null;
|
||||
private $_id = null;
|
||||
|
||||
/**
|
||||
* Fetch data and timestamp from xcache, store in instance
|
||||
*
|
||||
* @param string $id
|
||||
* @return bool success
|
||||
*/
|
||||
private function _fetch($id)
|
||||
{
|
||||
if ($this->_id === $id) {
|
||||
return true;
|
||||
}
|
||||
$ret = xcache_get($id);
|
||||
if (false === $ret) {
|
||||
$this->_id = null;
|
||||
return false;
|
||||
}
|
||||
list($this->_lm, $this->_data) = explode('|', $ret, 2);
|
||||
$this->_id = $id;
|
||||
return true;
|
||||
}
|
||||
}
|
123
phpgwapi/inc/min/lib/Minify/ClosureCompiler.php
Executable file
123
phpgwapi/inc/min/lib/Minify/ClosureCompiler.php
Executable file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_ClosureCompiler
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compress Javascript using the Closure Compiler
|
||||
*
|
||||
* You must set $jarFile and $tempDir before calling the minify functions.
|
||||
* Also, depending on your shell's environment, you may need to specify
|
||||
* the full path to java in $javaExecutable or use putenv() to setup the
|
||||
* Java environment.
|
||||
*
|
||||
* <code>
|
||||
* Minify_ClosureCompiler::$jarFile = '/path/to/closure-compiler-20120123.jar';
|
||||
* Minify_ClosureCompiler::$tempDir = '/tmp';
|
||||
* $code = Minify_ClosureCompiler::minify(
|
||||
* $code,
|
||||
* array('compilation_level' => 'SIMPLE_OPTIMIZATIONS')
|
||||
* );
|
||||
*
|
||||
* --compilation_level WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS
|
||||
*
|
||||
* </code>
|
||||
*
|
||||
* @todo unit tests, $options docs
|
||||
* @todo more options support (or should just passthru them all?)
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @author Elan Ruusamäe <glen@delfi.ee>
|
||||
*/
|
||||
class Minify_ClosureCompiler {
|
||||
|
||||
/**
|
||||
* Filepath of the Closure Compiler jar file. This must be set before
|
||||
* calling minifyJs().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $jarFile = null;
|
||||
|
||||
/**
|
||||
* Writable temp directory. This must be set before calling minifyJs().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $tempDir = null;
|
||||
|
||||
/**
|
||||
* Filepath of "java" executable (may be needed if not in shell's PATH)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $javaExecutable = 'java';
|
||||
|
||||
/**
|
||||
* Minify a Javascript string
|
||||
*
|
||||
* @param string $js
|
||||
*
|
||||
* @param array $options (verbose is ignored)
|
||||
*
|
||||
* @see https://code.google.com/p/closure-compiler/source/browse/trunk/README
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($js, $options = array())
|
||||
{
|
||||
self::_prepare();
|
||||
if (! ($tmpFile = tempnam(self::$tempDir, 'cc_'))) {
|
||||
throw new Exception('Minify_ClosureCompiler : could not create temp file.');
|
||||
}
|
||||
file_put_contents($tmpFile, $js);
|
||||
exec(self::_getCmd($options, $tmpFile), $output, $result_code);
|
||||
unlink($tmpFile);
|
||||
if ($result_code != 0) {
|
||||
throw new Exception('Minify_ClosureCompiler : Closure Compiler execution failed.');
|
||||
}
|
||||
return implode("\n", $output);
|
||||
}
|
||||
|
||||
private static function _getCmd($userOptions, $tmpFile)
|
||||
{
|
||||
$o = array_merge(
|
||||
array(
|
||||
'charset' => 'utf-8',
|
||||
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
|
||||
),
|
||||
$userOptions
|
||||
);
|
||||
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
|
||||
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
|
||||
? " --charset {$o['charset']}"
|
||||
: '');
|
||||
|
||||
foreach (array('compilation_level') as $opt) {
|
||||
if ($o[$opt]) {
|
||||
$cmd .= " --{$opt} ". escapeshellarg($o[$opt]);
|
||||
}
|
||||
}
|
||||
return $cmd . ' ' . escapeshellarg($tmpFile);
|
||||
}
|
||||
|
||||
private static function _prepare()
|
||||
{
|
||||
if (! is_file(self::$jarFile)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not a valid file.');
|
||||
}
|
||||
if (! is_readable(self::$jarFile)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $jarFile('.self::$jarFile.') is not readable.');
|
||||
}
|
||||
if (! is_dir(self::$tempDir)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not a valid direcotry.');
|
||||
}
|
||||
if (! is_writable(self::$tempDir)) {
|
||||
throw new Exception('Minify_ClosureCompiler : $tempDir('.self::$tempDir.') is not writable.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:ts=4:sw=4:et */
|
@ -78,33 +78,6 @@ abstract class Minify_Controller_Base {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load any code necessary to execute the given minifier callback.
|
||||
*
|
||||
* The controller is responsible for loading minification code on demand
|
||||
* via this method. This built-in function will only load classes for
|
||||
* static method callbacks where the class isn't already defined. It uses
|
||||
* the PEAR convention, so, given array('Jimmy_Minifier', 'minCss'), this
|
||||
* function will include 'Jimmy/Minifier.php'.
|
||||
*
|
||||
* If you need code loaded on demand and this doesn't suit you, you'll need
|
||||
* to override this function in your subclass.
|
||||
* @see Minify_Controller_Page::loadMinifier()
|
||||
*
|
||||
* @param callback $minifierCallback callback of minifier function
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function loadMinifier($minifierCallback)
|
||||
{
|
||||
if (is_array($minifierCallback)
|
||||
&& is_string($minifierCallback[0])
|
||||
&& !class_exists($minifierCallback[0], false)) {
|
||||
|
||||
require str_replace('_', '/', $minifierCallback[0]) . '.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a user-given file within an allowable directory, existing,
|
||||
* and having an extension js/css/html/txt ?
|
||||
@ -244,7 +217,6 @@ abstract class Minify_Controller_Base {
|
||||
* @return null
|
||||
*/
|
||||
public function log($msg) {
|
||||
require_once 'Minify/Logger.php';
|
||||
Minify_Logger::log($msg);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for minifying a set of files
|
||||
*
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for serving predetermined groups of minimized sets, selected
|
||||
* by PATH_INFO
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for requests to /min/index.php
|
||||
*
|
||||
@ -22,6 +20,13 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
* @return array Minify options
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
// PHP insecure by default: realpath() and other FS functions can't handle null bytes.
|
||||
foreach (array('g', 'b', 'f') as $key) {
|
||||
if (isset($_GET[$key])) {
|
||||
$_GET[$key] = str_replace("\x00", '', (string)$_GET[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// filter controller options
|
||||
$cOptions = array_merge(
|
||||
array(
|
||||
@ -36,7 +41,6 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
$sources = array();
|
||||
$this->selectionId = '';
|
||||
$firstMissingResource = null;
|
||||
|
||||
if (isset($_GET['g'])) {
|
||||
// add group(s)
|
||||
$this->selectionId .= 'g=' . $_GET['g'];
|
||||
@ -203,9 +207,12 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
||||
protected function _getFileSource($file, $cOptions)
|
||||
{
|
||||
$spec['filepath'] = $file;
|
||||
if ($cOptions['noMinPattern']
|
||||
&& preg_match($cOptions['noMinPattern'], basename($file))) {
|
||||
$spec['minifier'] = '';
|
||||
if ($cOptions['noMinPattern'] && preg_match($cOptions['noMinPattern'], basename($file))) {
|
||||
if (preg_match('~\.css$~i', $file)) {
|
||||
$spec['minifyOptions']['compress'] = false;
|
||||
} else {
|
||||
$spec['minifier'] = '';
|
||||
}
|
||||
}
|
||||
return new Minify_Source($spec);
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for serving a single HTML page
|
||||
*
|
||||
@ -59,7 +57,6 @@ class Minify_Controller_Page extends Minify_Controller_Base {
|
||||
'cssMinifier' => array('Minify_CSS', 'minify')
|
||||
,'jsMinifier' => array('JSMin', 'minify')
|
||||
);
|
||||
$this->_loadCssJsMinifiers = true;
|
||||
unset($options['minifyAll']);
|
||||
}
|
||||
$this->sources[] = new Minify_Source($sourceSpec);
|
||||
@ -67,21 +64,5 @@ class Minify_Controller_Page extends Minify_Controller_Base {
|
||||
$options['contentType'] = Minify::TYPE_HTML;
|
||||
return $options;
|
||||
}
|
||||
|
||||
protected $_loadCssJsMinifiers = false;
|
||||
|
||||
/**
|
||||
* @see Minify_Controller_Base::loadMinifier()
|
||||
*/
|
||||
public function loadMinifier($minifierCallback)
|
||||
{
|
||||
if ($this->_loadCssJsMinifiers) {
|
||||
// Minify will not call for these so we must manually load
|
||||
// them when Minify/HTML.php is called for.
|
||||
require_once 'Minify/CSS.php';
|
||||
require_once 'JSMin.php';
|
||||
}
|
||||
parent::loadMinifier($minifierCallback); // load Minify/HTML.php
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,6 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for emulating version 1 of minify.php (mostly a proof-of-concept)
|
||||
*
|
||||
@ -26,6 +24,11 @@ class Minify_Controller_Version1 extends Minify_Controller_Base {
|
||||
*
|
||||
*/
|
||||
public function setupSources($options) {
|
||||
// PHP insecure by default: realpath() and other FS functions can't handle null bytes.
|
||||
if (isset($_GET['files'])) {
|
||||
$_GET['files'] = str_replace("\x00", '', (string)$_GET['files']);
|
||||
}
|
||||
|
||||
self::_setupDefines();
|
||||
if (MINIFY_USE_CACHE) {
|
||||
$cacheDir = defined('MINIFY_CACHE_DIR')
|
||||
@ -51,7 +54,6 @@ class Minify_Controller_Version1 extends Minify_Controller_Base {
|
||||
) {
|
||||
return $options;
|
||||
}
|
||||
$extension = $m[1];
|
||||
|
||||
$files = explode(',', $_GET['files']);
|
||||
if (count($files) > MINIFY_MAX_FILES) {
|
||||
@ -63,7 +65,6 @@ class Minify_Controller_Version1 extends Minify_Controller_Base {
|
||||
. DIRECTORY_SEPARATOR;
|
||||
$prependAbsPaths = $_SERVER['DOCUMENT_ROOT'];
|
||||
|
||||
$sources = array();
|
||||
$goodFiles = array();
|
||||
$hasBadSource = false;
|
||||
|
||||
|
@ -17,6 +17,10 @@
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_HTML {
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_jsCleanComments = true;
|
||||
|
||||
/**
|
||||
* "Minify" an HTML page
|
||||
@ -37,7 +41,7 @@ class Minify_HTML {
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($html, $options = array()) {
|
||||
$min = new Minify_HTML($html, $options);
|
||||
$min = new self($html, $options);
|
||||
return $min->process();
|
||||
}
|
||||
|
||||
@ -55,6 +59,8 @@ class Minify_HTML {
|
||||
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
||||
* elements. Note: the type attribute is ignored.
|
||||
*
|
||||
* 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block
|
||||
*
|
||||
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
||||
* unset, minify will sniff for an XHTML doctype.
|
||||
*
|
||||
@ -72,6 +78,9 @@ class Minify_HTML {
|
||||
if (isset($options['jsMinifier'])) {
|
||||
$this->_jsMinifier = $options['jsMinifier'];
|
||||
}
|
||||
if (isset($options['jsCleanComments'])) {
|
||||
$this->_jsCleanComments = (bool)$options['jsCleanComments'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -215,7 +224,9 @@ class Minify_HTML {
|
||||
$ws2 = ($m[4] === '') ? '' : ' ';
|
||||
|
||||
// remove HTML comments (and ending "//" if present)
|
||||
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
||||
if ($this->_jsCleanComments) {
|
||||
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
||||
}
|
||||
|
||||
// remove CDATA section markers
|
||||
$js = $this->_removeCdata($js);
|
||||
|
@ -15,10 +15,10 @@ class Minify_HTML_Helper {
|
||||
public $minAppUri = '/min';
|
||||
public $groupsConfigFile = '';
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get an HTML-escaped Minify URI for a group or set of files
|
||||
*
|
||||
* @param mixed $keyOrFiles a group key or array of filepaths/URIs
|
||||
* @param string|array $keyOrFiles a group key or array of filepaths/URIs
|
||||
* @param array $opts options:
|
||||
* 'farExpires' : (default true) append a modified timestamp for cache revving
|
||||
* 'debug' : (default false) append debug flag
|
||||
@ -51,8 +51,12 @@ class Minify_HTML_Helper {
|
||||
return htmlspecialchars($uri, ENT_QUOTES, $opts['charset']);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get non-HTML-escaped URI to minify the specified files
|
||||
*
|
||||
* @param bool $farExpires
|
||||
* @param bool $debug
|
||||
* @return string
|
||||
*/
|
||||
public function getRawUri($farExpires = true, $debug = false)
|
||||
{
|
||||
@ -74,6 +78,12 @@ class Minify_HTML_Helper {
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the files that will comprise the URI we're building
|
||||
*
|
||||
* @param array $files
|
||||
* @param bool $checkLastModified
|
||||
*/
|
||||
public function setFiles($files, $checkLastModified = true)
|
||||
{
|
||||
$this->_groupKey = null;
|
||||
@ -94,6 +104,12 @@ class Minify_HTML_Helper {
|
||||
$this->_filePaths = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the group of files that will comprise the URI we're building
|
||||
*
|
||||
* @param string $key
|
||||
* @param bool $checkLastModified
|
||||
*/
|
||||
public function setGroup($key, $checkLastModified = true)
|
||||
{
|
||||
$this->_groupKey = $key;
|
||||
@ -103,13 +119,23 @@ class Minify_HTML_Helper {
|
||||
}
|
||||
if (is_file($this->groupsConfigFile)) {
|
||||
$gc = (require $this->groupsConfigFile);
|
||||
if (isset($gc[$key])) {
|
||||
$this->_lastModified = self::getLastModified($gc[$key]);
|
||||
$keys = explode(',', $key);
|
||||
foreach ($keys as $key) {
|
||||
if (isset($gc[$key])) {
|
||||
$this->_lastModified = self::getLastModified($gc[$key], $this->_lastModified);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max(lastModified) of all files
|
||||
*
|
||||
* @param array|string $sources
|
||||
* @param int $lastModified
|
||||
* @return int
|
||||
*/
|
||||
public static function getLastModified($sources, $lastModified = 0)
|
||||
{
|
||||
$max = $lastModified;
|
||||
@ -142,13 +168,19 @@ class Minify_HTML_Helper {
|
||||
* @return mixed a common char or '' if any do not match
|
||||
*/
|
||||
protected static function _getCommonCharAtPos($arr, $pos) {
|
||||
$l = count($arr);
|
||||
if (!isset($arr[0][$pos])) {
|
||||
return '';
|
||||
}
|
||||
$c = $arr[0][$pos];
|
||||
if ($c === '' || $l === 1)
|
||||
$l = count($arr);
|
||||
if ($l === 1) {
|
||||
return $c;
|
||||
for ($i = 1; $i < $l; ++$i)
|
||||
if ($arr[$i][$pos] !== $c)
|
||||
}
|
||||
for ($i = 1; $i < $l; ++$i) {
|
||||
if ($arr[$i][$pos] !== $c) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
@ -157,11 +189,11 @@ class Minify_HTML_Helper {
|
||||
*
|
||||
* @param array $paths root-relative URIs of files
|
||||
* @param string $minRoot root-relative URI of the "min" application
|
||||
* @return string
|
||||
*/
|
||||
protected static function _getShortestUri($paths, $minRoot = '/min/') {
|
||||
$pos = 0;
|
||||
$base = '';
|
||||
$c;
|
||||
while (true) {
|
||||
$c = self::_getCommonCharAtPos($paths, $pos);
|
||||
if ($c === '') {
|
||||
|
@ -79,7 +79,7 @@ class Minify_JS_ClosureCompiler {
|
||||
$contents = file_get_contents(self::URL, false, stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close\r\n",
|
||||
'content' => $postBody,
|
||||
'max_redirects' => 0,
|
||||
'timeout' => 15,
|
||||
@ -125,7 +125,6 @@ class Minify_JS_ClosureCompiler {
|
||||
*/
|
||||
protected function _fallback($js)
|
||||
{
|
||||
require_once 'JSMin.php';
|
||||
return JSMin::minify($js);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,11 @@ class Minify_Lines {
|
||||
$newLines = array();
|
||||
while (null !== ($line = array_shift($lines))) {
|
||||
if (('' !== $id) && (0 == $i % 50)) {
|
||||
array_push($newLines, '', "/* {$id} */", '');
|
||||
if ($inComment) {
|
||||
array_push($newLines, '', "/* {$id} *|", '');
|
||||
} else {
|
||||
array_push($newLines, '', "/* {$id} */", '');
|
||||
}
|
||||
}
|
||||
++$i;
|
||||
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
|
||||
@ -65,7 +69,6 @@ class Minify_Lines {
|
||||
|
||||
// check for desired URI rewriting
|
||||
if (isset($options['currentDir'])) {
|
||||
require_once 'Minify/CSS/UriRewriter.php';
|
||||
Minify_CSS_UriRewriter::$debugText = '';
|
||||
$content = Minify_CSS_UriRewriter::rewrite(
|
||||
$content
|
||||
@ -93,6 +96,9 @@ class Minify_Lines {
|
||||
*/
|
||||
private static function _eolInComment($line, $inComment)
|
||||
{
|
||||
// crude way to avoid things like // */
|
||||
$line = preg_replace('~//.*?(\\*/|/\\*).*~', '', $line);
|
||||
|
||||
while (strlen($line)) {
|
||||
$search = $inComment
|
||||
? '*/'
|
||||
|
28
phpgwapi/inc/min/lib/Minify/Loader.php
Executable file
28
phpgwapi/inc/min/lib/Minify/Loader.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Minify_Loader
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class autoloader
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_Loader {
|
||||
public function loadClass($class)
|
||||
{
|
||||
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
|
||||
$file .= strtr($class, "\\_", DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . '.php';
|
||||
if (is_readable($file)) {
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
|
||||
static public function register()
|
||||
{
|
||||
$inst = new self();
|
||||
spl_autoload_register(array($inst, 'loadClass'));
|
||||
}
|
||||
}
|
@ -36,8 +36,6 @@ class Minify_Logger {
|
||||
* @return null
|
||||
*/
|
||||
public static function log($msg, $label = 'Minify') {
|
||||
error_log($msg);
|
||||
throw new Exception($msg);
|
||||
if (! self::$_logger) return;
|
||||
self::$_logger->log($msg, $label);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
* Java environment.
|
||||
*
|
||||
* <code>
|
||||
* Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.3.5.jar';
|
||||
* Minify_YUICompressor::$jarFile = '/path/to/yuicompressor-2.4.6.jar';
|
||||
* Minify_YUICompressor::$tempDir = '/tmp';
|
||||
* $code = Minify_YUICompressor::minifyJs(
|
||||
* $code
|
||||
@ -21,6 +21,9 @@
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* Note: In case you run out stack (default is 512k), you may increase stack size in $options:
|
||||
* array('stack-size' => '2048k')
|
||||
*
|
||||
* @todo unit tests, $options docs
|
||||
*
|
||||
* @package Minify
|
||||
@ -108,10 +111,15 @@ class Minify_YUICompressor {
|
||||
,'nomunge' => false
|
||||
,'preserve-semi' => false
|
||||
,'disable-optimizations' => false
|
||||
,'stack-size' => ''
|
||||
)
|
||||
,$userOptions
|
||||
);
|
||||
$cmd = self::$javaExecutable . ' -jar ' . escapeshellarg(self::$jarFile)
|
||||
$cmd = self::$javaExecutable
|
||||
. (!empty($o['stack-size'])
|
||||
? ' -Xss' . $o['stack-size']
|
||||
: '')
|
||||
. ' -jar ' . escapeshellarg(self::$jarFile)
|
||||
. " --type {$type}"
|
||||
. (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $o['charset'])
|
||||
? " --charset {$o['charset']}"
|
||||
@ -134,8 +142,8 @@ class Minify_YUICompressor {
|
||||
if (! is_file(self::$jarFile)) {
|
||||
throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not a valid file.');
|
||||
}
|
||||
if (! is_executable(self::$jarFile)) {
|
||||
throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not executable.');
|
||||
if (! is_readable(self::$jarFile)) {
|
||||
throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not readable.');
|
||||
}
|
||||
if (! is_dir(self::$tempDir)) {
|
||||
throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not a valid direcotry.');
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace MrClay;
|
||||
|
||||
use MrClay\Cli\Arg;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Forms a front controller for a console app, handling and validating arguments (options)
|
||||
*
|
||||
@ -51,7 +54,7 @@ class Cli {
|
||||
public $isHelpRequest = false;
|
||||
|
||||
/**
|
||||
* @var array of Cli\Arg
|
||||
* @var Arg[]
|
||||
*/
|
||||
protected $_args = array();
|
||||
|
||||
@ -80,8 +83,8 @@ class Cli {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cli\Arg|string $letter
|
||||
* @return Cli\Arg
|
||||
* @param Arg|string $letter
|
||||
* @return Arg
|
||||
*/
|
||||
public function addOptionalArg($letter)
|
||||
{
|
||||
@ -89,8 +92,8 @@ class Cli {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cli\Arg|string $letter
|
||||
* @return Cli\Arg
|
||||
* @param Arg|string $letter
|
||||
* @return Arg
|
||||
*/
|
||||
public function addRequiredArg($letter)
|
||||
{
|
||||
@ -100,17 +103,17 @@ class Cli {
|
||||
/**
|
||||
* @param string $letter
|
||||
* @param bool $required
|
||||
* @param Cli\Arg|null $arg
|
||||
* @return Cli\Arg
|
||||
* @throws \InvalidArgumentException
|
||||
* @param Arg|null $arg
|
||||
* @return Arg
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function addArgument($letter, $required, Cli\Arg $arg = null)
|
||||
public function addArgument($letter, $required, Arg $arg = null)
|
||||
{
|
||||
if (! preg_match('/^[a-zA-Z]$/', $letter)) {
|
||||
throw new \InvalidArgumentException('$letter must be in [a-zA-z]');
|
||||
throw new InvalidArgumentException('$letter must be in [a-zA-Z]');
|
||||
}
|
||||
if (! $arg) {
|
||||
$arg = new Cli\Arg($required);
|
||||
$arg = new Arg($required);
|
||||
}
|
||||
$this->_args[$letter] = $arg;
|
||||
return $arg;
|
||||
@ -118,7 +121,7 @@ class Cli {
|
||||
|
||||
/**
|
||||
* @param string $letter
|
||||
* @return Cli\Arg|null
|
||||
* @return Arg|null
|
||||
*/
|
||||
public function getArgument($letter)
|
||||
{
|
||||
@ -143,7 +146,7 @@ class Cli {
|
||||
|
||||
$lettersUsed = '';
|
||||
foreach ($this->_args as $letter => $arg) {
|
||||
/* @var Cli\Arg $arg */
|
||||
/* @var Arg $arg */
|
||||
$options .= $letter;
|
||||
$lettersUsed .= $letter;
|
||||
|
||||
@ -159,7 +162,7 @@ class Cli {
|
||||
$this->debug['getopt_return'] = $o;
|
||||
|
||||
foreach ($this->_args as $letter => $arg) {
|
||||
/* @var Cli\Arg $arg */
|
||||
/* @var Arg $arg */
|
||||
$this->values[$letter] = false;
|
||||
if (isset($o[$letter])) {
|
||||
if (is_bool($o[$letter])) {
|
||||
@ -295,7 +298,7 @@ class Cli {
|
||||
{
|
||||
$r = "\n";
|
||||
foreach ($this->_args as $letter => $arg) {
|
||||
/* @var Cli\Arg $arg */
|
||||
/* @var Arg $arg */
|
||||
$desc = $arg->getDescription();
|
||||
$flag = " -$letter ";
|
||||
if ($arg->mayHaveValue) {
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace MrClay\Cli;
|
||||
|
||||
use BadMethodCallException;
|
||||
|
||||
/**
|
||||
* An argument for a CLI app. This specifies the argument, what values it expects and
|
||||
* how it's treated during validation.
|
||||
@ -150,7 +152,7 @@ class Arg {
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
* @return Arg
|
||||
* @throws \BadMethodCallException
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function __call($name, array $args = array())
|
||||
{
|
||||
@ -160,7 +162,7 @@ class Arg {
|
||||
$this->spec['mustHaveValue'] = true;
|
||||
}
|
||||
} else {
|
||||
throw new \BadMethodCallException('Method does not exist');
|
||||
throw new BadMethodCallException('Method does not exist');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
30
phpgwapi/inc/min/quick-test.css
Executable file
30
phpgwapi/inc/min/quick-test.css
Executable file
@ -0,0 +1,30 @@
|
||||
/*! This file exists only for testing a Minify installation. It's content is not used.
|
||||
*
|
||||
* http://example.org/min/f=min/quick-test.css
|
||||
*/
|
||||
|
||||
@import url( /more.css );
|
||||
|
||||
body, td, th {
|
||||
font-family: Verdana , "Bitstream Vera Sans" , Arial Narrow, sans-serif ;
|
||||
|
||||
font-size : 12px;
|
||||
}
|
||||
|
||||
.nav {
|
||||
margin-left: 20%;
|
||||
}
|
||||
#main-nav {
|
||||
background-color: red;
|
||||
border: 1px solid #00ff77;
|
||||
}
|
||||
|
||||
div#content
|
||||
h1 + p {
|
||||
padding-top: 0;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@media all and (min-width: 640px) {
|
||||
#media-queries-1 { background-color: #0f0; }
|
||||
}
|
74
phpgwapi/inc/min/quick-test.js
Executable file
74
phpgwapi/inc/min/quick-test.js
Executable file
@ -0,0 +1,74 @@
|
||||
/*! This file exists only for testing a Minify installation. It's content is not used.
|
||||
*
|
||||
* http://example.org/min/f=min/quick-test.js
|
||||
*/
|
||||
|
||||
/* Finds the lowest common multiple of two numbers */
|
||||
function LCMCalculator(x, y) { // constructor function
|
||||
var checkInt = function (x) { // inner function
|
||||
if (x % 1 !== 0) {
|
||||
throw new TypeError(x + " is not an integer"); // throw an exception
|
||||
}
|
||||
return x;
|
||||
};
|
||||
this.a = checkInt(x);
|
||||
// ^ semicolons are optional
|
||||
this.b = checkInt(y);
|
||||
}
|
||||
// The prototype of object instances created by a constructor is
|
||||
// that constructor's "prototype" property.
|
||||
LCMCalculator.prototype = { // object literal
|
||||
constructor: LCMCalculator, // when reassigning a prototype, set the constructor property appropriately
|
||||
gcd: function () { // method that calculates the greatest common divisor
|
||||
// Euclidean algorithm:
|
||||
var a = Math.abs(this.a), b = Math.abs(this.b), t;
|
||||
if (a < b) {
|
||||
// swap variables
|
||||
t = b;
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
while (b !== 0) {
|
||||
t = b;
|
||||
b = a % b;
|
||||
a = t;
|
||||
}
|
||||
// Only need to calculate GCD once, so "redefine" this method.
|
||||
// (Actually not redefinition - it's defined on the instance itself,
|
||||
// so that this.gcd refers to this "redefinition" instead of LCMCalculator.prototype.gcd.)
|
||||
// Also, 'gcd' === "gcd", this['gcd'] === this.gcd
|
||||
this['gcd'] = function () {
|
||||
return a;
|
||||
};
|
||||
return a;
|
||||
},
|
||||
// Object property names can be specified by strings delimited by double (") or single (') quotes.
|
||||
"lcm" : function () {
|
||||
// Variable names don't collide with object properties, e.g. |lcm| is not |this.lcm|.
|
||||
// not using |this.a * this.b| to avoid FP precision issues
|
||||
var lcm = this.a / this.gcd() * this.b;
|
||||
// Only need to calculate lcm once, so "redefine" this method.
|
||||
this.lcm = function () {
|
||||
return lcm;
|
||||
};
|
||||
return lcm;
|
||||
},
|
||||
toString: function () {
|
||||
return "LCMCalculator: a = " + this.a + ", b = " + this.b;
|
||||
}
|
||||
};
|
||||
|
||||
//define generic output function; this implementation only works for web browsers
|
||||
function output(x) {
|
||||
document.write(x + "<br>");
|
||||
}
|
||||
|
||||
// Note: Array's map() and forEach() are defined in JavaScript 1.6.
|
||||
// They are used here to demonstrate JavaScript's inherent functional nature.
|
||||
[[25, 55], [21, 56], [22, 58], [28, 56]].map(function (pair) { // array literal + mapping function
|
||||
return new LCMCalculator(pair[0], pair[1]);
|
||||
}).sort(function (a, b) { // sort with this comparative function
|
||||
return a.lcm() - b.lcm();
|
||||
}).forEach(function (obj) {
|
||||
output(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
|
||||
});
|
@ -2,11 +2,18 @@
|
||||
/**
|
||||
* Utility functions for generating URIs in HTML files
|
||||
*
|
||||
* @warning These functions execute min/groupsConfig.php, sometimes multiple times.
|
||||
* You must make sure that functions are not redefined, and if your use custom sources,
|
||||
* you must require_once dirname(__FILE__) . '/lib/Minify/Source.php' so that
|
||||
* class is available.
|
||||
*
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/lib/Minify/HTML/Helper.php';
|
||||
|
||||
if (! class_exists('Minify_Loader', false)) {
|
||||
require dirname(__FILE__) . '/lib/Minify/Loader.php';
|
||||
Minify_Loader::register();
|
||||
}
|
||||
|
||||
/*
|
||||
* Get an HTML-escaped Minify URI for a group or set of files. By default, URIs
|
||||
|
Loading…
Reference in New Issue
Block a user