From 657b12788d8f35fce3abe25d6fe3832c131f19fe Mon Sep 17 00:00:00 2001 From: Dave Cooper Date: Tue, 24 Mar 2015 11:01:13 +0800 Subject: [PATCH] MDL-49518 libraries: Update lessphp to 1.7.0.3 --- lib/lessphp/Cache.php | 150 +++++++++++++--- lib/lessphp/Colors.php | 0 lib/lessphp/Configurable.php | 0 lib/lessphp/Environment.php | 7 +- lib/lessphp/Exception/Chunk.php | 6 +- lib/lessphp/Exception/Compiler.php | 0 lib/lessphp/Exception/Parser.php | 7 +- lib/lessphp/Functions.php | 24 +-- lib/lessphp/Less.php.combine | 0 lib/lessphp/Mime.php | 13 +- lib/lessphp/Output/Mapped.php | 4 +- lib/lessphp/Parser.php | 237 +++++++++++++++++-------- lib/lessphp/SourceMap/Base64VLQ.php | 0 lib/lessphp/SourceMap/Generator.php | 52 ++++-- lib/lessphp/Tree.php | 0 lib/lessphp/Tree/Alpha.php | 0 lib/lessphp/Tree/Anonymous.php | 2 +- lib/lessphp/Tree/Assignment.php | 4 +- lib/lessphp/Tree/Attribute.php | 8 +- lib/lessphp/Tree/Call.php | 16 +- lib/lessphp/Tree/Color.php | 6 +- lib/lessphp/Tree/Comment.php | 0 lib/lessphp/Tree/Condition.php | 0 lib/lessphp/Tree/DefaultFunc.php | 10 +- lib/lessphp/Tree/DetachedRuleset.php | 8 +- lib/lessphp/Tree/Dimension.php | 6 +- lib/lessphp/Tree/Directive.php | 4 +- lib/lessphp/Tree/Element.php | 2 +- lib/lessphp/Tree/Expression.php | 6 +- lib/lessphp/Tree/Extend.php | 8 +- lib/lessphp/Tree/Import.php | 28 +-- lib/lessphp/Tree/Javascript.php | 0 lib/lessphp/Tree/Keyword.php | 0 lib/lessphp/Tree/Media.php | 6 +- lib/lessphp/Tree/Mixin/Call.php | 4 +- lib/lessphp/Tree/Mixin/Definition.php | 9 +- lib/lessphp/Tree/NameValue.php | 2 +- lib/lessphp/Tree/Negative.php | 6 +- lib/lessphp/Tree/Operation.php | 4 +- lib/lessphp/Tree/Paren.php | 4 +- lib/lessphp/Tree/Quoted.php | 2 +- lib/lessphp/Tree/Rule.php | 8 +- lib/lessphp/Tree/Ruleset.php | 8 +- lib/lessphp/Tree/RulesetCall.php | 6 +- lib/lessphp/Tree/Selector.php | 12 +- lib/lessphp/Tree/UnicodeDescriptor.php | 0 lib/lessphp/Tree/Unit.php | 26 +-- lib/lessphp/Tree/UnitConversions.php | 0 lib/lessphp/Tree/Url.php | 4 +- lib/lessphp/Tree/Value.php | 2 +- lib/lessphp/Tree/Variable.php | 7 +- lib/lessphp/Version.php | 2 +- lib/lessphp/Visitor.php | 10 +- lib/lessphp/Visitor/extendFinder.php | 22 +-- lib/lessphp/Visitor/import.php | 0 lib/lessphp/Visitor/joinSelector.php | 12 +- lib/lessphp/Visitor/processExtends.php | 0 lib/lessphp/Visitor/toCSS.php | 28 +-- lib/lessphp/VisitorReplacing.php | 6 +- lib/lessphp/moodle_readme.txt | 2 +- lib/thirdpartylibs.xml | 2 +- 61 files changed, 512 insertions(+), 290 deletions(-) mode change 100644 => 100755 lib/lessphp/Cache.php mode change 100644 => 100755 lib/lessphp/Colors.php mode change 100644 => 100755 lib/lessphp/Configurable.php mode change 100644 => 100755 lib/lessphp/Environment.php mode change 100644 => 100755 lib/lessphp/Exception/Chunk.php mode change 100644 => 100755 lib/lessphp/Exception/Compiler.php mode change 100644 => 100755 lib/lessphp/Exception/Parser.php mode change 100644 => 100755 lib/lessphp/Functions.php mode change 100644 => 100755 lib/lessphp/Less.php.combine mode change 100644 => 100755 lib/lessphp/Mime.php mode change 100644 => 100755 lib/lessphp/Output/Mapped.php mode change 100644 => 100755 lib/lessphp/Parser.php mode change 100644 => 100755 lib/lessphp/SourceMap/Base64VLQ.php mode change 100644 => 100755 lib/lessphp/SourceMap/Generator.php mode change 100644 => 100755 lib/lessphp/Tree.php mode change 100644 => 100755 lib/lessphp/Tree/Alpha.php mode change 100644 => 100755 lib/lessphp/Tree/Anonymous.php mode change 100644 => 100755 lib/lessphp/Tree/Assignment.php mode change 100644 => 100755 lib/lessphp/Tree/Attribute.php mode change 100644 => 100755 lib/lessphp/Tree/Call.php mode change 100644 => 100755 lib/lessphp/Tree/Color.php mode change 100644 => 100755 lib/lessphp/Tree/Comment.php mode change 100644 => 100755 lib/lessphp/Tree/Condition.php mode change 100644 => 100755 lib/lessphp/Tree/Dimension.php mode change 100644 => 100755 lib/lessphp/Tree/Directive.php mode change 100644 => 100755 lib/lessphp/Tree/Element.php mode change 100644 => 100755 lib/lessphp/Tree/Expression.php mode change 100644 => 100755 lib/lessphp/Tree/Extend.php mode change 100644 => 100755 lib/lessphp/Tree/Import.php mode change 100644 => 100755 lib/lessphp/Tree/Javascript.php mode change 100644 => 100755 lib/lessphp/Tree/Keyword.php mode change 100644 => 100755 lib/lessphp/Tree/Media.php mode change 100644 => 100755 lib/lessphp/Tree/Mixin/Call.php mode change 100644 => 100755 lib/lessphp/Tree/Mixin/Definition.php mode change 100644 => 100755 lib/lessphp/Tree/NameValue.php mode change 100644 => 100755 lib/lessphp/Tree/Negative.php mode change 100644 => 100755 lib/lessphp/Tree/Operation.php mode change 100644 => 100755 lib/lessphp/Tree/Paren.php mode change 100644 => 100755 lib/lessphp/Tree/Quoted.php mode change 100644 => 100755 lib/lessphp/Tree/Rule.php mode change 100644 => 100755 lib/lessphp/Tree/Ruleset.php mode change 100644 => 100755 lib/lessphp/Tree/Selector.php mode change 100644 => 100755 lib/lessphp/Tree/UnicodeDescriptor.php mode change 100644 => 100755 lib/lessphp/Tree/Unit.php mode change 100644 => 100755 lib/lessphp/Tree/UnitConversions.php mode change 100644 => 100755 lib/lessphp/Tree/Url.php mode change 100644 => 100755 lib/lessphp/Tree/Value.php mode change 100644 => 100755 lib/lessphp/Tree/Variable.php mode change 100644 => 100755 lib/lessphp/Version.php mode change 100644 => 100755 lib/lessphp/Visitor.php mode change 100644 => 100755 lib/lessphp/Visitor/extendFinder.php mode change 100644 => 100755 lib/lessphp/Visitor/import.php mode change 100644 => 100755 lib/lessphp/Visitor/joinSelector.php mode change 100644 => 100755 lib/lessphp/Visitor/processExtends.php mode change 100644 => 100755 lib/lessphp/Visitor/toCSS.php mode change 100644 => 100755 lib/lessphp/VisitorReplacing.php diff --git a/lib/lessphp/Cache.php b/lib/lessphp/Cache.php old mode 100644 new mode 100755 index 7556e0a2950..e4023ef57c2 --- a/lib/lessphp/Cache.php +++ b/lib/lessphp/Cache.php @@ -11,7 +11,17 @@ require_once( dirname(__FILE__).'/Version.php'); */ class Less_Cache{ - public static $cache_dir = false; // directory less.php can use for storing data + // directory less.php can use for storing data + public static $cache_dir = false; + + // prefix for the storing data + public static $prefix = 'lessphp_'; + + // prefix for the storing vars + public static $prefix_vars = 'lessphpvars_'; + + // specifies the number of seconds after which data created by less.php will be seen as 'garbage' and potentially cleaned up + public static $gc_lifetime = 604800; /** @@ -21,10 +31,10 @@ class Less_Cache{ * * @param array $less_files Array of .less files to compile * @param array $parser_options Array of compiler options - * @param boolean $use_cache Set to false to regenerate the css file + * @param array $modify_vars Array of variables * @return string Name of the css file */ - public static function Get( $less_files, $parser_options = array(), $use_cache = true ){ + public static function Get( $less_files, $parser_options = array(), $modify_vars = array() ){ //check $cache_dir @@ -36,39 +46,62 @@ class Less_Cache{ throw new Exception('cache_dir not set'); } + if( isset($parser_options['prefix']) ){ + Less_Cache::$prefix = $parser_options['prefix']; + } + + if( empty(Less_Cache::$prefix) ){ + throw new Exception('prefix not set'); + } + + if( isset($parser_options['prefix_vars']) ){ + Less_Cache::$prefix_vars = $parser_options['prefix_vars']; + } + + if( empty(Less_Cache::$prefix_vars) ){ + throw new Exception('prefix_vars not set'); + } + self::CheckCacheDir(); + $less_files = (array)$less_files; + + + //create a file for variables + if( !empty($modify_vars) ){ + $lessvars = Less_Parser::serializeVars($modify_vars); + $vars_file = Less_Cache::$cache_dir . Less_Cache::$prefix_vars . sha1($lessvars) . '.less'; + + if( !file_exists($vars_file) ){ + file_put_contents($vars_file, $lessvars); + } + + $less_files += array($vars_file => '/'); + } + // generate name for compiled css file - $less_files = (array)$less_files; $hash = md5(json_encode($less_files)); - $list_file = Less_Cache::$cache_dir.'lessphp_'.$hash.'.list'; + $list_file = Less_Cache::$cache_dir . Less_Cache::$prefix . $hash . '.list'; // check cached content - if( $use_cache === true && file_exists($list_file) ){ + if( !isset($parser_options['use_cache']) || $parser_options['use_cache'] === true ){ + if( file_exists($list_file) ){ - $list = explode("\n",file_get_contents($list_file)); + self::ListFiles($list_file, $list, $cached_name); + $compiled_name = self::CompiledName($list); - //pop the cached name that should match $compiled_name - $cached_name = array_pop($list); - if( !preg_match('/^lessphp_[a-f0-9]+\.css$/',$cached_name) ){ - $list[] = $cached_name; - $cached_name = false; - } - $compiled_name = self::CompiledName($list); + // if $cached_name != $compiled_name, we know we need to recompile + if( !$cached_name || $cached_name === $compiled_name ){ - // if $cached_name != $compiled_name, we know we need to recompile - if( !$cached_name || $cached_name === $compiled_name ){ + $output_file = self::OutputFile($compiled_name, $parser_options ); - $output_file = self::OutputFile($compiled_name, $parser_options ); - - if( $output_file && file_exists($output_file) ){ - @touch($list_file); - @touch($output_file); - return basename($output_file); // for backwards compatibility, we just return the name of the file + if( $output_file && file_exists($output_file) ){ + @touch($list_file); + return basename($output_file); // for backwards compatibility, we just return the name of the file + } } } - } $compiled = self::Cache( $less_files, $parser_options ); @@ -102,10 +135,12 @@ class Less_Cache{ * * @param array $less_files Array of .less files to compile * @param array $parser_options Array of compiler options + * @param array $modify_vars Array of variables * @return string Name of the css file */ - public static function Regen( $less_files, $parser_options = array() ){ - return self::Get( $less_files, $parser_options, false ); + public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ){ + $parser_options['use_cache'] = false; + return self::Get( $less_files, $parser_options, $modify_vars ); } public static function Cache( &$less_files, $parser_options = array() ){ @@ -167,7 +202,7 @@ class Less_Cache{ $temp[] = filemtime($file)."\t".filesize($file)."\t".$file; } - return 'lessphp_'.sha1(json_encode($temp)).'.css'; + return Less_Cache::$prefix.sha1(json_encode($temp)).'.css'; } @@ -196,6 +231,10 @@ class Less_Cache{ } + /** + * Delete unused less.php files + * + */ public static function CleanCache(){ static $clean = false; @@ -205,15 +244,49 @@ class Less_Cache{ $files = scandir(Less_Cache::$cache_dir); if( $files ){ - $check_time = time() - 604800; + $check_time = time() - self::$gc_lifetime; foreach($files as $file){ - if( strpos($file,'lessphp_') !== 0 ){ + + // don't delete if the file wasn't created with less.php + if( strpos($file,Less_Cache::$prefix) !== 0 ){ continue; } + $full_path = Less_Cache::$cache_dir.'/'.$file; - if( filemtime($full_path) > $check_time ){ + + // make sure the file still exists + // css files may have already been deleted + if( !file_exists($full_path) ){ continue; } + $mtime = filemtime($full_path); + + // don't delete if it's a relatively new file + if( $mtime > $check_time ){ + continue; + } + + $parts = explode('.',$file); + $type = array_pop($parts); + + + // delete css files based on the list files + if( $type === 'css' ){ + continue; + } + + + // delete the list file and associated css file + if( $type === 'list' ){ + self::ListFiles($full_path, $list, $css_file_name); + if( $css_file_name ){ + $css_file = Less_Cache::$cache_dir.'/'.$css_file_name; + if( file_exists($css_file) ){ + unlink($css_file); + } + } + } + unlink($full_path); } } @@ -221,4 +294,23 @@ class Less_Cache{ $clean = true; } + + /** + * Get the list of less files and generated css file from a list file + * + */ + static function ListFiles($list_file, &$list, &$css_file_name ){ + + $list = explode("\n",file_get_contents($list_file)); + + //pop the cached name that should match $compiled_name + $css_file_name = array_pop($list); + + if( !preg_match('/^' . Less_Cache::$prefix . '[a-f0-9]+\.css$/',$css_file_name) ){ + $list[] = $css_file_name; + $css_file_name = false; + } + + } + } \ No newline at end of file diff --git a/lib/lessphp/Colors.php b/lib/lessphp/Colors.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Configurable.php b/lib/lessphp/Configurable.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Environment.php b/lib/lessphp/Environment.php old mode 100644 new mode 100755 index 861ccfaf7d4..b2203014f04 --- a/lib/lessphp/Environment.php +++ b/lib/lessphp/Environment.php @@ -47,6 +47,11 @@ class Less_Environment{ public static $mixin_stack = 0; + /** + * @var array + */ + public $functions = array(); + public function Init(){ @@ -114,7 +119,7 @@ class Less_Environment{ * @return string Canonicalized path * */ - static function normalizePath($path){ + public static function normalizePath($path){ $segments = explode('/',$path); $segments = array_reverse($segments); diff --git a/lib/lessphp/Exception/Chunk.php b/lib/lessphp/Exception/Chunk.php old mode 100644 new mode 100755 index 815e6bde2b5..036900f3c45 --- a/lib/lessphp/Exception/Chunk.php +++ b/lib/lessphp/Exception/Chunk.php @@ -46,7 +46,7 @@ class Less_Exception_Chunk extends Less_Exception_Parser{ * We don't actually need the chunks * */ - function Chunks(){ + protected function Chunks(){ $level = 0; $parenLevel = 0; $lastMultiCommentEndBrace = null; @@ -173,12 +173,12 @@ class Less_Exception_Chunk extends Less_Exception_Parser{ //$this->emitChunk(true); } - function CharCode($pos){ + public function CharCode($pos){ return ord($this->input[$pos]); } - function fail( $msg, $index = null ){ + public function fail( $msg, $index = null ){ if( !$index ){ $this->index = $this->parserCurrentIndex; diff --git a/lib/lessphp/Exception/Compiler.php b/lib/lessphp/Exception/Compiler.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Exception/Parser.php b/lib/lessphp/Exception/Parser.php old mode 100644 new mode 100755 index d8a415a66a0..69abd151f0b --- a/lib/lessphp/Exception/Parser.php +++ b/lib/lessphp/Exception/Parser.php @@ -99,7 +99,12 @@ class Less_Exception_Parser extends Exception{ */ public function getLineNumber(){ if( $this->index ){ - return substr_count($this->input, "\n", 0, $this->index) + 1; + // https://bugs.php.net/bug.php?id=49790 + if (ini_get("mbstring.func_overload")) { + return substr_count(substr($this->input, 0, $this->index), "\n") + 1; + } else { + return substr_count($this->input, "\n", 0, $this->index) + 1; + } } return 1; } diff --git a/lib/lessphp/Functions.php b/lib/lessphp/Functions.php old mode 100644 new mode 100755 index ca541409fa3..e1c68d8119f --- a/lib/lessphp/Functions.php +++ b/lib/lessphp/Functions.php @@ -21,7 +21,7 @@ class Less_Functions{ /** * @param string $op */ - static public function operate( $op, $a, $b ){ + public static function operate( $op, $a, $b ){ switch ($op) { case '+': return $a + $b; case '-': return $a - $b; @@ -30,11 +30,11 @@ class Less_Functions{ } } - static public function clamp($val, $max = 1){ + public static function clamp($val, $max = 1){ return min( max($val, 0), $max); } - static function fround( $value ){ + public static function fround( $value ){ if( $value === 0 ){ return $value; @@ -47,7 +47,7 @@ class Less_Functions{ return $value; } - static public function number($n){ + public static function number($n){ if ($n instanceof Less_Tree_Dimension) { return floatval( $n->unit->is('%') ? $n->value / 100 : $n->value); @@ -58,7 +58,7 @@ class Less_Functions{ } } - static public function scaled($n, $size = 255 ){ + public static function scaled($n, $size = 255 ){ if( $n instanceof Less_Tree_Dimension && $n->unit->is('%') ){ return (float)$n->value * $size / 100; } else { @@ -102,7 +102,7 @@ class Less_Functions{ /** * @param double $h */ - function hsla_hue($h, $m1, $m2){ + public function hsla_hue($h, $m1, $m2){ $h = $h < 0 ? $h + 1 : ($h > 1 ? $h - 1 : $h); if ($h * 6 < 1) return $m1 + ($m2 - $m1) * $h * 6; else if ($h * 2 < 1) return $m2; @@ -520,7 +520,7 @@ class Less_Functions{ /** * @param boolean $isMin */ - function _minmax( $isMin, $args ){ + private function _minmax( $isMin, $args ){ $arg_count = count($args); @@ -715,12 +715,12 @@ class Less_Functions{ return null; } - function length($values){ + public function length($values){ $n = (property_exists($values,'value') && is_array($values->value)) ? count($values->value) : 1; return new Less_Tree_Dimension($n); } - function datauri($mimetypeNode, $filePathNode = null ) { + public function datauri($mimetypeNode, $filePathNode = null ) { $filePath = ( $filePathNode ? $filePathNode->value : null ); $mimetype = $mimetypeNode->value; @@ -796,7 +796,7 @@ class Less_Functions{ } //svg-gradient - function svggradient( $direction ){ + public function svggradient( $direction ){ $throw_message = 'svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position]'; $arguments = func_get_args(); @@ -995,7 +995,7 @@ class Less_Functions{ } // non-w3c functions: - function colorBlendAverage($cb, $cs ){ + public function colorBlendAverage($cb, $cs ){ return ($cb + $cs) / 2; } @@ -1003,7 +1003,7 @@ class Less_Functions{ return $this->colorBlend( array($this,'colorBlendNegation'), $color1, $color2 ); } - function colorBlendNegation($cb, $cs){ + public function colorBlendNegation($cb, $cs){ return 1 - abs($cb + $cs - 1); } diff --git a/lib/lessphp/Less.php.combine b/lib/lessphp/Less.php.combine old mode 100644 new mode 100755 diff --git a/lib/lessphp/Mime.php b/lib/lessphp/Mime.php old mode 100644 new mode 100755 index 36067955c9b..109ecd3f825 --- a/lib/lessphp/Mime.php +++ b/lib/lessphp/Mime.php @@ -16,10 +16,15 @@ class Less_Mime{ '.gif' => 'image/gif', '.jpg' => 'image/jpeg', '.jpeg'=> 'image/jpeg', - '.png' => 'image/png' + '.png' => 'image/png', + '.ttf' => 'application/x-font-ttf', + '.otf' => 'application/x-font-otf', + '.eot' => 'application/vnd.ms-fontobject', + '.woff' => 'application/x-font-woff', + '.svg' => 'image/svg+xml', ); - static function lookup( $filepath ){ + public static function lookup( $filepath ){ $parts = explode('.',$filepath); $ext = '.'.strtolower(array_pop($parts)); @@ -29,8 +34,8 @@ class Less_Mime{ return self::$_types[$ext]; } - static function charsets_lookup( $type = null ){ + public static function charsets_lookup( $type = null ){ // assumes all text types are UTF-8 return $type && preg_match('/^text\//',$type) ? 'UTF-8' : ''; } -} \ No newline at end of file +} diff --git a/lib/lessphp/Output/Mapped.php b/lib/lessphp/Output/Mapped.php old mode 100644 new mode 100755 index 7c7d7d901e3..9e4cc46194e --- a/lib/lessphp/Output/Mapped.php +++ b/lib/lessphp/Output/Mapped.php @@ -93,7 +93,7 @@ class Less_Output_Mapped extends Less_Output { $this->column, // generated_column count($sourceLines), // original_line strlen($sourceColumns), // original_column - $fileInfo['currentUri'] + $fileInfo ); }else{ for($i = 0, $count = count($lines); $i < $count; $i++){ @@ -102,7 +102,7 @@ class Less_Output_Mapped extends Less_Output { $i === 0 ? $this->column : 0, // generated_column count($sourceLines) + $i, // original_line $i === 0 ? strlen($sourceColumns) : 0, // original_column - $fileInfo['currentUri'] + $fileInfo ); } } diff --git a/lib/lessphp/Parser.php b/lib/lessphp/Parser.php old mode 100644 new mode 100755 index 0bfdfad6269..6c02bed8635 --- a/lib/lessphp/Parser.php +++ b/lib/lessphp/Parser.php @@ -26,7 +26,9 @@ class Less_Parser{ 'import_dirs' => array(), 'import_callback' => null, 'cache_dir' => null, - 'cache_method' => 'php', //false, 'serialize', 'php', 'var_export'; + 'cache_method' => 'php', // false, 'serialize', 'php', 'var_export', 'callback'; + 'cache_callback_get' => null, + 'cache_callback_set' => null, 'sourceMap' => false, // whether to output a source map 'sourceMapBasepath' => null, @@ -139,7 +141,25 @@ class Less_Parser{ Less_Parser::$options[$option] = $value; } + /** + * Registers a new custom function + * + * @param string $name function name + * @param callable $callback callback + */ + public function registerFunction($name, $callback) { + $this->env->functions[$name] = $callback; + } + /** + * Removed an already registered function + * + * @param string $name function name + */ + public function unregisterFunction($name) { + if( isset($this->env->functions[$name]) ) + unset($this->env->functions[$name]); + } /** @@ -154,38 +174,48 @@ class Less_Parser{ $locale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, "C"); + try { - $root = new Less_Tree_Ruleset(array(), $this->rules ); - $root->root = true; - $root->firstRoot = true; + $root = new Less_Tree_Ruleset(array(), $this->rules ); + $root->root = true; + $root->firstRoot = true; - $this->PreVisitors($root); + $this->PreVisitors($root); - self::$has_extends = false; - $evaldRoot = $root->compile($this->env); + self::$has_extends = false; + $evaldRoot = $root->compile($this->env); - $this->PostVisitors($evaldRoot); + $this->PostVisitors($evaldRoot); - if( Less_Parser::$options['sourceMap'] ){ - $generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options ); - // will also save file - // FIXME: should happen somewhere else? - $css = $generator->generateCSS(); - }else{ - $css = $evaldRoot->toCSS(); - } + if( Less_Parser::$options['sourceMap'] ){ + $generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options ); + // will also save file + // FIXME: should happen somewhere else? + $css = $generator->generateCSS(); + }else{ + $css = $evaldRoot->toCSS(); + } - if( Less_Parser::$options['compress'] ){ - $css = preg_replace('/(^(\s)+)|((\s)+$)/', '', $css); - } + if( Less_Parser::$options['compress'] ){ + $css = preg_replace('/(^(\s)+)|((\s)+$)/', '', $css); + } + + } catch (Exception $exc) { + // Intentional fall-through so we can reset environment + } //reset php settings @ini_set('precision',$precision); setlocale(LC_NUMERIC, $locale); + // Rethrow exception after we handled resetting the environment + if (!empty($exc)) { + throw $exc; + } + return $css; } @@ -298,8 +328,13 @@ class Less_Parser{ $previousFileInfo = $this->env->currentFileInfo; - $filename = self::WinPath($filename); + + + if( $filename ){ + $filename = self::WinPath(realpath($filename)); + } $uri_root = self::WinPath($uri_root); + $this->SetFileInfo($filename, $uri_root); self::AddParsedFile($filename); @@ -327,7 +362,7 @@ class Less_Parser{ */ public function ModifyVars( $vars ){ - $this->input = $this->serializeVars( $vars ); + $this->input = Less_Parser::serializeVars( $vars ); $this->_parse(); return $this; @@ -431,7 +466,17 @@ class Less_Parser{ * @param string $file_path */ private function _parse( $file_path = null ){ + if (ini_get("mbstring.func_overload")) { + $mb_internal_encoding = ini_get("mbstring.internal_encoding"); + @ini_set("mbstring.internal_encoding", "ascii"); + } + $this->rules = array_merge($this->rules, $this->GetRules( $file_path )); + + //reset php settings + if (isset($mb_internal_encoding)) { + @ini_set("mbstring.internal_encoding", $mb_internal_encoding); + } } @@ -446,26 +491,41 @@ class Less_Parser{ $this->SetInput($file_path); $cache_file = $this->CacheFile( $file_path ); - if( $cache_file && file_exists($cache_file) ){ - switch(Less_Parser::$options['cache_method']){ + if( $cache_file ){ + if( Less_Parser::$options['cache_method'] == 'callback' ){ + if( is_callable(Less_Parser::$options['cache_callback_get']) ){ + $cache = call_user_func_array( + Less_Parser::$options['cache_callback_get'], + array($this, $file_path, $cache_file) + ); - // Using serialize - // Faster but uses more memory - case 'serialize': - $cache = unserialize(file_get_contents($cache_file)); if( $cache ){ - touch($cache_file); $this->UnsetInput(); return $cache; } - break; + } + + }elseif( file_exists($cache_file) ){ + switch(Less_Parser::$options['cache_method']){ + + // Using serialize + // Faster but uses more memory + case 'serialize': + $cache = unserialize(file_get_contents($cache_file)); + if( $cache ){ + touch($cache_file); + $this->UnsetInput(); + return $cache; + } + break; - // Using generated php code - case 'var_export': - case 'php': - $this->UnsetInput(); - return include($cache_file); + // Using generated php code + case 'var_export': + case 'php': + $this->UnsetInput(); + return include($cache_file); + } } } @@ -480,22 +540,31 @@ class Less_Parser{ //save the cache if( $cache_file ){ + if( Less_Parser::$options['cache_method'] == 'callback' ){ + if( is_callable(Less_Parser::$options['cache_callback_set']) ){ + call_user_func_array( + Less_Parser::$options['cache_callback_set'], + array($this, $file_path, $cache_file, $rules) + ); + } - //msg('write cache file'); - switch(Less_Parser::$options['cache_method']){ - case 'serialize': - file_put_contents( $cache_file, serialize($rules) ); - break; - case 'php': - file_put_contents( $cache_file, '' ); - break; - case 'var_export': - //Requires __set_state() - file_put_contents( $cache_file, '' ); - break; + }else{ + //msg('write cache file'); + switch(Less_Parser::$options['cache_method']){ + case 'serialize': + file_put_contents( $cache_file, serialize($rules) ); + break; + case 'php': + file_put_contents( $cache_file, '' ); + break; + case 'var_export': + //Requires __set_state() + file_put_contents( $cache_file, '' ); + break; + } + + Less_Cache::CleanCache(); } - - Less_Cache::CleanCache(); } return $rules; @@ -539,7 +608,7 @@ class Less_Parser{ public function CacheFile( $file_path ){ - if( $file_path && Less_Parser::$options['cache_method'] && Less_Cache::$cache_dir ){ + if( $file_path && $this->CacheEnabled() ){ $env = get_object_vars($this->env); unset($env['frames']); @@ -551,7 +620,7 @@ class Less_Parser{ $parts[] = $env; $parts[] = Less_Version::cache_version; $parts[] = Less_Parser::$options['cache_method']; - return Less_Cache::$cache_dir.'lessphp_'.base_convert( sha1(json_encode($parts) ), 16, 36).'.lesscache'; + return Less_Cache::$cache_dir . Less_Cache::$prefix . base_convert( sha1(json_encode($parts) ), 16, 36) . '.lesscache'; } } @@ -636,10 +705,12 @@ class Less_Parser{ */ private function MatchFuncs($toks){ - foreach($toks as $tok){ - $match = $this->$tok(); - if( $match ){ - return $match; + if( $this->pos < $this->input_len ){ + foreach($toks as $tok){ + $match = $this->$tok(); + if( $match ){ + return $match; + } } } @@ -864,7 +935,11 @@ class Less_Parser{ if ($e) { $this->MatchChar('~'); } - $str = $this->MatchReg('/\\G"((?:[^"\\\\\r\n]|\\\\.)*)"|\'((?:[^\'\\\\\r\n]|\\\\.)*)\'/'); + + // Fix for #124: match escaped newlines + //$str = $this->MatchReg('/\\G"((?:[^"\\\\\r\n]|\\\\.)*)"|\'((?:[^\'\\\\\r\n]|\\\\.)*)\'/'); + $str = $this->MatchReg('/\\G"((?:[^"\\\\\r\n]|\\\\.|\\\\\r\n|\\\\[\n\r\f])*)"|\'((?:[^\'\\\\\r\n]|\\\\.|\\\\\r\n|\\\\[\n\r\f])*)\'/'); + if( $str ){ $result = $str[0][0] == '"' ? $str[1] : $str[2]; return $this->NewObj5('Less_Tree_Quoted',array($str[0], $result, $e, $index, $this->env->currentFileInfo) ); @@ -1562,22 +1637,24 @@ class Less_Parser{ // in the input, to see if it's a ` ` character. // private function parseCombinator(){ - $c = $this->input[$this->pos]; - if ($c === '>' || $c === '+' || $c === '~' || $c === '|' || $c === '^' ){ + if( $this->pos < $this->input_len ){ + $c = $this->input[$this->pos]; + if ($c === '>' || $c === '+' || $c === '~' || $c === '|' || $c === '^' ){ - $this->pos++; - if( $this->input[$this->pos] === '^' ){ - $c = '^^'; $this->pos++; + if( $this->input[$this->pos] === '^' ){ + $c = '^^'; + $this->pos++; + } + + $this->skipWhitespace(0); + + return $c; } - $this->skipWhitespace(0); - - return $c; - } - - if( $this->pos > 0 && $this->isWhitespace(-1) ){ - return ' '; + if( $this->pos > 0 && $this->isWhitespace(-1) ){ + return ' '; + } } } @@ -1618,7 +1695,9 @@ class Less_Parser{ //if( count($extendList) ){ //error("Extend can only be used at the end of selector"); //} - $c = $this->input[ $this->pos ]; + if( $this->pos < $this->input_len ){ + $c = $this->input[ $this->pos ]; + } $elements[] = $e; $e = null; } @@ -2378,7 +2457,7 @@ class Less_Parser{ } } - public function serializeVars( $vars ){ + public static function serializeVars( $vars ){ $s = ''; foreach($vars as $name => $value){ @@ -2426,7 +2505,7 @@ class Less_Parser{ */ public function NewObj0($class){ $obj = new $class(); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $obj->cache_string = ' new '.$class.'()'; } return $obj; @@ -2434,7 +2513,7 @@ class Less_Parser{ public function NewObj1($class, $arg){ $obj = new $class( $arg ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $obj->cache_string = ' new '.$class.'('.Less_Parser::ArgString($arg).')'; } return $obj; @@ -2442,7 +2521,7 @@ class Less_Parser{ public function NewObj2($class, $args){ $obj = new $class( $args[0], $args[1] ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $this->ObjCache( $obj, $class, $args); } return $obj; @@ -2450,7 +2529,7 @@ class Less_Parser{ public function NewObj3($class, $args){ $obj = new $class( $args[0], $args[1], $args[2] ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $this->ObjCache( $obj, $class, $args); } return $obj; @@ -2458,7 +2537,7 @@ class Less_Parser{ public function NewObj4($class, $args){ $obj = new $class( $args[0], $args[1], $args[2], $args[3] ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $this->ObjCache( $obj, $class, $args); } return $obj; @@ -2466,7 +2545,7 @@ class Less_Parser{ public function NewObj5($class, $args){ $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4] ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $this->ObjCache( $obj, $class, $args); } return $obj; @@ -2474,7 +2553,7 @@ class Less_Parser{ public function NewObj6($class, $args){ $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5] ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $this->ObjCache( $obj, $class, $args); } return $obj; @@ -2482,7 +2561,7 @@ class Less_Parser{ public function NewObj7($class, $args){ $obj = new $class( $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6] ); - if( Less_Cache::$cache_dir ){ + if( $this->CacheEnabled() ){ $this->ObjCache( $obj, $class, $args); } return $obj; @@ -2531,6 +2610,10 @@ class Less_Parser{ return str_replace('\\', '/', $path); } + public function CacheEnabled(){ + return (Less_Parser::$options['cache_method'] && (Less_Cache::$cache_dir || (Less_Parser::$options['cache_method'] == 'callback'))); + } + } diff --git a/lib/lessphp/SourceMap/Base64VLQ.php b/lib/lessphp/SourceMap/Base64VLQ.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/SourceMap/Generator.php b/lib/lessphp/SourceMap/Generator.php old mode 100644 new mode 100755 index b11e42fe0d1..ac5f2c92776 --- a/lib/lessphp/SourceMap/Generator.php +++ b/lib/lessphp/SourceMap/Generator.php @@ -37,7 +37,10 @@ class Less_SourceMap_Generator extends Less_Configurable { 'outputSourceFiles' => false, // base path for filename normalization - 'sourceMapBasepath' => '' + 'sourceMapRootpath' => '', + + // base path for filename normalization + 'sourceMapBasepath' => '' ); /** @@ -74,6 +77,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * @var array */ protected $sources = array(); + protected $source_keys = array(); /** * Constructor @@ -90,8 +94,9 @@ class Less_SourceMap_Generator extends Less_Configurable { // fix windows paths - if( isset($this->options['sourceMapBasepath']) ){ - $this->options['sourceMapBasepath'] = str_replace('\\', '/', $this->options['sourceMapBasepath']); + if( !empty($this->options['sourceMapRootpath']) ){ + $this->options['sourceMapRootpath'] = str_replace('\\', '/', $this->options['sourceMapRootpath']); + $this->options['sourceMapRootpath'] = rtrim($this->options['sourceMapRootpath'],'/').'/'; } } @@ -161,16 +166,22 @@ class Less_SourceMap_Generator extends Less_Configurable { * @return string */ protected function normalizeFilename($filename){ + $filename = str_replace('\\', '/', $filename); + $rootpath = $this->getOption('sourceMapRootpath'); $basePath = $this->getOption('sourceMapBasepath'); - if( $basePath && ($pos = strpos($filename, $basePath)) !== false ){ - $filename = substr($filename, $pos + strlen($basePath)); - if(strpos($filename, '\\') === 0 || strpos($filename, '/') === 0){ - $filename = substr($filename, 1); - } + // "Trim" the 'sourceMapBasepath' from the output filename. + if (strpos($filename, $basePath) === 0) { + $filename = substr($filename, strlen($basePath)); } - return sprintf('%s%s', $this->getOption('sourceMapRootpath'), $filename); + + // Remove extra leading path separators. + if(strpos($filename, '\\') === 0 || strpos($filename, '/') === 0){ + $filename = substr($filename, 1); + } + + return $rootpath . $filename; } /** @@ -182,19 +193,17 @@ class Less_SourceMap_Generator extends Less_Configurable { * @param integer $originalColumn The column number in original file * @param string $sourceFile The original source file */ - public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $sourceFile){ + public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $fileInfo ){ + $this->mappings[] = array( 'generated_line' => $generatedLine, 'generated_column' => $generatedColumn, 'original_line' => $originalLine, 'original_column' => $originalColumn, - 'source_file' => $sourceFile + 'source_file' => $fileInfo['currentUri'] ); - - $norm_file = $this->normalizeFilename($sourceFile); - - $this->sources[$norm_file] = $sourceFile; + $this->sources[$fileInfo['currentUri']] = $fileInfo['filename']; } @@ -228,8 +237,10 @@ class Less_SourceMap_Generator extends Less_Configurable { // A list of original sources used by the 'mappings' entry. - $sourceMap['sources'] = array_keys($this->sources); - + $sourceMap['sources'] = array(); + foreach($this->sources as $source_uri => $source_filename){ + $sourceMap['sources'][] = $this->normalizeFilename($source_filename); + } // A list of symbol names used by the 'mappings' entry. @@ -280,6 +291,9 @@ class Less_SourceMap_Generator extends Less_Configurable { return ''; } + $this->source_keys = array_flip(array_keys($this->sources)); + + // group mappings by generated line number. $groupedMap = $groupedMapEncoded = array(); foreach($this->mappings as $m){ @@ -303,7 +317,7 @@ class Less_SourceMap_Generator extends Less_Configurable { // find the index if( $m['source_file'] ){ - $index = $this->findFileIndex($this->normalizeFilename($m['source_file'])); + $index = $this->findFileIndex($m['source_file']); if( $index !== false ){ $mapEncoded .= $this->encoder->encode($index - $lastOriginalIndex); $lastOriginalIndex = $index; @@ -333,7 +347,7 @@ class Less_SourceMap_Generator extends Less_Configurable { * @return integer|false */ protected function findFileIndex($filename){ - return array_search($filename, array_keys($this->sources)); + return $this->source_keys[$filename]; } } \ No newline at end of file diff --git a/lib/lessphp/Tree.php b/lib/lessphp/Tree.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Alpha.php b/lib/lessphp/Tree/Alpha.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Anonymous.php b/lib/lessphp/Tree/Anonymous.php old mode 100644 new mode 100755 index f590ec562eb..8889dc0f3d4 --- a/lib/lessphp/Tree/Anonymous.php +++ b/lib/lessphp/Tree/Anonymous.php @@ -29,7 +29,7 @@ class Less_Tree_Anonymous extends Less_Tree{ return new Less_Tree_Anonymous($this->value, $this->index, $this->currentFileInfo, $this->mapLines); } - function compare($x){ + public function compare($x){ if( !is_object($x) ){ return -1; } diff --git a/lib/lessphp/Tree/Assignment.php b/lib/lessphp/Tree/Assignment.php old mode 100644 new mode 100755 index ca6cbfb7c92..2380006477e --- a/lib/lessphp/Tree/Assignment.php +++ b/lib/lessphp/Tree/Assignment.php @@ -12,12 +12,12 @@ class Less_Tree_Assignment extends Less_Tree{ public $value; public $type = 'Assignment'; - function __construct($key, $val) { + public function __construct($key, $val) { $this->key = $key; $this->value = $val; } - function accept( $visitor ){ + public function accept( $visitor ){ $this->value = $visitor->visitObj( $this->value ); } diff --git a/lib/lessphp/Tree/Attribute.php b/lib/lessphp/Tree/Attribute.php old mode 100644 new mode 100755 index 8f5d4ae334c..32b8900d855 --- a/lib/lessphp/Tree/Attribute.php +++ b/lib/lessphp/Tree/Attribute.php @@ -13,13 +13,13 @@ class Less_Tree_Attribute extends Less_Tree{ public $value; public $type = 'Attribute'; - function __construct($key, $op, $value){ + public function __construct($key, $op, $value){ $this->key = $key; $this->op = $op; $this->value = $value; } - function compile($env){ + public function compile($env){ $key_obj = is_object($this->key); $val_obj = is_object($this->value); @@ -37,11 +37,11 @@ class Less_Tree_Attribute extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( $this->toCSS() ); } - function toCSS(){ + public function toCSS(){ $value = $this->key; if( $this->op ){ diff --git a/lib/lessphp/Tree/Call.php b/lib/lessphp/Tree/Call.php old mode 100644 new mode 100755 index fdd7ea3dcb1..1560351ef7a --- a/lib/lessphp/Tree/Call.php +++ b/lib/lessphp/Tree/Call.php @@ -10,10 +10,10 @@ class Less_Tree_Call extends Less_Tree{ public $value; - var $name; - var $args; - var $index; - var $currentFileInfo; + protected $name; + protected $args; + protected $index; + protected $currentFileInfo; public $type = 'Call'; public function __construct($name, $args, $index, $currentFileInfo = null ){ @@ -23,7 +23,7 @@ class Less_Tree_Call extends Less_Tree{ $this->currentFileInfo = $currentFileInfo; } - function accept( $visitor ){ + public function accept( $visitor ){ $this->args = $visitor->visitArray( $this->args ); } @@ -79,6 +79,12 @@ class Less_Tree_Call extends Less_Tree{ } catch (Exception $e) { throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index); } + } elseif( isset( $env->functions[$nameLC] ) && is_callable( $env->functions[$nameLC] ) ) { + try { + $result = call_user_func_array( $env->functions[$nameLC], $args ); + } catch (Exception $e) { + throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index); + } } } diff --git a/lib/lessphp/Tree/Color.php b/lib/lessphp/Tree/Color.php old mode 100644 new mode 100755 index c0433a700f3..77af07a6e4b --- a/lib/lessphp/Tree/Color.php +++ b/lib/lessphp/Tree/Color.php @@ -71,7 +71,7 @@ class Less_Tree_Color extends Less_Tree{ // Values are capped between `0` and `255`, rounded and zero-padded. // if( $alpha < 1 ){ - if( $alpha === 0 && isset($this->isTransparentKeyword) && $this->isTransparentKeyword ){ + if( ( $alpha === 0 || $alpha === 0.0 ) && isset($this->isTransparentKeyword) && $this->isTransparentKeyword ){ return 'transparent'; } @@ -148,7 +148,7 @@ class Less_Tree_Color extends Less_Tree{ } //Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript - function toHSV() { + public function toHSV() { $r = $this->rgb[0] / 255; $g = $this->rgb[1] / 255; $b = $this->rgb[2] / 255; @@ -196,7 +196,7 @@ class Less_Tree_Color extends Less_Tree{ $x->alpha === $this->alpha) ? 0 : -1; } - function toHex( $v ){ + public function toHex( $v ){ $ret = '#'; foreach($v as $c){ diff --git a/lib/lessphp/Tree/Comment.php b/lib/lessphp/Tree/Comment.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Condition.php b/lib/lessphp/Tree/Condition.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/DefaultFunc.php b/lib/lessphp/Tree/DefaultFunc.php index 1f7dc3d9bcc..c2dbf749678 100644 --- a/lib/lessphp/Tree/DefaultFunc.php +++ b/lib/lessphp/Tree/DefaultFunc.php @@ -11,24 +11,24 @@ class Less_Tree_DefaultFunc{ static $error_; static $value_; - static function compile(){ + public static function compile(){ if( self::$error_ ){ - throw Exception(self::$error_); + throw new Exception(self::$error_); } if( self::$value_ !== null ){ return self::$value_ ? new Less_Tree_Keyword('true') : new Less_Tree_Keyword('false'); } } - static function value( $v ){ + public static function value( $v ){ self::$value_ = $v; } - static function error( $e ){ + public static function error( $e ){ self::$error_ = $e; } - static function reset(){ + public static function reset(){ self::$value_ = self::$error_ = null; } } \ No newline at end of file diff --git a/lib/lessphp/Tree/DetachedRuleset.php b/lib/lessphp/Tree/DetachedRuleset.php index e927fa8daec..c887e400fa4 100644 --- a/lib/lessphp/Tree/DetachedRuleset.php +++ b/lib/lessphp/Tree/DetachedRuleset.php @@ -12,16 +12,16 @@ class Less_Tree_DetachedRuleset extends Less_Tree{ public $frames; public $type = 'DetachedRuleset'; - function __construct( $ruleset, $frames = null ){ + public function __construct( $ruleset, $frames = null ){ $this->ruleset = $ruleset; $this->frames = $frames; } - function accept($visitor) { + public function accept($visitor) { $this->ruleset = $visitor->visitObj($this->ruleset); } - function compile($env){ + public function compile($env){ if( $this->frames ){ $frames = $this->frames; }else{ @@ -30,7 +30,7 @@ class Less_Tree_DetachedRuleset extends Less_Tree{ return new Less_Tree_DetachedRuleset($this->ruleset, $frames); } - function callEval($env) { + public function callEval($env) { if( $this->frames ){ return $this->ruleset->compile( $env->copyEvalEnv( array_merge($this->frames,$env->frames) ) ); } diff --git a/lib/lessphp/Tree/Dimension.php b/lib/lessphp/Tree/Dimension.php old mode 100644 new mode 100755 index 3188f9b4b73..b693f57d793 --- a/lib/lessphp/Tree/Dimension.php +++ b/lib/lessphp/Tree/Dimension.php @@ -24,7 +24,7 @@ class Less_Tree_Dimension extends Less_Tree{ } } - function accept( $visitor ){ + public function accept( $visitor ){ $this->unit = $visitor->visitObj( $this->unit ); } @@ -147,11 +147,11 @@ class Less_Tree_Dimension extends Less_Tree{ } } - function unify() { + public function unify() { return $this->convertTo(array('length'=> 'px', 'duration'=> 's', 'angle' => 'rad' )); } - function convertTo($conversions) { + public function convertTo($conversions) { $value = $this->value; $unit = clone $this->unit; diff --git a/lib/lessphp/Tree/Directive.php b/lib/lessphp/Tree/Directive.php old mode 100644 new mode 100755 index 0c2d809ac17..04a1e467e0c --- a/lib/lessphp/Tree/Directive.php +++ b/lib/lessphp/Tree/Directive.php @@ -31,7 +31,7 @@ class Less_Tree_Directive extends Less_Tree{ } - function accept( $visitor ){ + public function accept( $visitor ){ if( $this->rules ){ $this->rules = $visitor->visitObj( $this->rules ); } @@ -44,7 +44,7 @@ class Less_Tree_Directive extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $value = $this->value; $rules = $this->rules; $output->add( $this->name, $this->currentFileInfo, $this->index ); diff --git a/lib/lessphp/Tree/Element.php b/lib/lessphp/Tree/Element.php old mode 100644 new mode 100755 index 4dcb59e57a2..9cea5e43c09 --- a/lib/lessphp/Tree/Element.php +++ b/lib/lessphp/Tree/Element.php @@ -29,7 +29,7 @@ class Less_Tree_Element extends Less_Tree{ $this->currentFileInfo = $currentFileInfo; } - function accept( $visitor ){ + public function accept( $visitor ){ if( $this->value_is_object ){ //object or string $this->value = $visitor->visitObj( $this->value ); } diff --git a/lib/lessphp/Tree/Expression.php b/lib/lessphp/Tree/Expression.php old mode 100644 new mode 100755 index 2a397fb3693..d834354a1e8 --- a/lib/lessphp/Tree/Expression.php +++ b/lib/lessphp/Tree/Expression.php @@ -18,7 +18,7 @@ class Less_Tree_Expression extends Less_Tree{ $this->parens = $parens; } - function accept( $visitor ){ + public function accept( $visitor ){ $this->value = $visitor->visitArray( $this->value ); } @@ -71,7 +71,7 @@ class Less_Tree_Expression extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $val_len = count($this->value); for( $i = 0; $i < $val_len; $i++ ){ $this->value[$i]->genCSS( $output ); @@ -81,7 +81,7 @@ class Less_Tree_Expression extends Less_Tree{ } } - function throwAwayComments() { + public function throwAwayComments() { if( is_array($this->value) ){ $new_value = array(); diff --git a/lib/lessphp/Tree/Extend.php b/lib/lessphp/Tree/Extend.php old mode 100644 new mode 100755 index 98402560489..8f21e939d98 --- a/lib/lessphp/Tree/Extend.php +++ b/lib/lessphp/Tree/Extend.php @@ -25,7 +25,7 @@ class Less_Tree_Extend extends Less_Tree{ /** * @param integer $index */ - function __construct($selector, $option, $index){ + public function __construct($selector, $option, $index){ static $i = 0; $this->selector = $selector; $this->option = $option; @@ -46,18 +46,18 @@ class Less_Tree_Extend extends Less_Tree{ $this->parent_ids = array($this->object_id); } - function accept( $visitor ){ + public function accept( $visitor ){ $this->selector = $visitor->visitObj( $this->selector ); } - function compile( $env ){ + public function compile( $env ){ Less_Parser::$has_extends = true; $this->selector = $this->selector->compile($env); return $this; //return new Less_Tree_Extend( $this->selector->compile($env), $this->option, $this->index); } - function findSelfSelectors( $selectors ){ + public function findSelfSelectors( $selectors ){ $selfElements = array(); diff --git a/lib/lessphp/Tree/Import.php b/lib/lessphp/Tree/Import.php old mode 100644 new mode 100755 index 3b0ae0def7f..1752744e9ce --- a/lib/lessphp/Tree/Import.php +++ b/lib/lessphp/Tree/Import.php @@ -27,7 +27,7 @@ class Less_Tree_Import extends Less_Tree{ public $root; public $type = 'Import'; - function __construct($path, $features, $options, $index, $currentFileInfo = null ){ + public function __construct($path, $features, $options, $index, $currentFileInfo = null ){ $this->options = $options; $this->index = $index; $this->path = $path; @@ -58,7 +58,7 @@ class Less_Tree_Import extends Less_Tree{ // ruleset. // - function accept($visitor){ + public function accept($visitor){ if( $this->features ){ $this->features = $visitor->visitObj($this->features); @@ -73,7 +73,7 @@ class Less_Tree_Import extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ if( $this->css ){ $output->add( '@import ', $this->currentFileInfo, $this->index ); @@ -87,7 +87,7 @@ class Less_Tree_Import extends Less_Tree{ } } - function toCSS(){ + public function toCSS(){ $features = $this->features ? ' ' . $this->features->toCSS() : ''; if ($this->css) { @@ -100,7 +100,7 @@ class Less_Tree_Import extends Less_Tree{ /** * @return string */ - function getPath(){ + public function getPath(){ if ($this->path instanceof Less_Tree_Quoted) { $path = $this->path->value; $path = ( isset($this->css) || preg_match('/(\.[a-z]*$)|([\?;].*)$/',$path)) ? $path : $path . '.less'; @@ -114,11 +114,11 @@ class Less_Tree_Import extends Less_Tree{ return preg_replace('/[\?#][^\?]*$/','',$path); } - function compileForImport( $env ){ + public function compileForImport( $env ){ return new Less_Tree_Import( $this->path->compile($env), $this->features, $this->options, $this->index, $this->currentFileInfo); } - function compilePath($env) { + public function compilePath($env) { $path = $this->path->compile($env); $rootpath = ''; if( $this->currentFileInfo && $this->currentFileInfo['rootpath'] ){ @@ -142,7 +142,7 @@ class Less_Tree_Import extends Less_Tree{ return $path; } - function compile( $env ){ + public function compile( $env ){ $evald = $this->compileForImport($env); @@ -199,7 +199,7 @@ class Less_Tree_Import extends Less_Tree{ * * @param Less_Tree_Import $evald */ - function PathAndUri(){ + public function PathAndUri(){ $evald_path = $this->getPath(); @@ -231,13 +231,17 @@ class Less_Tree_Import extends Less_Tree{ $full_path = $path; return array( $full_path, $uri ); } - }else{ + }elseif( !empty($rootpath) ){ $path = rtrim($rootpath,'/\\').'/'.ltrim($evald_path,'/\\'); if( file_exists($path) ){ $full_path = Less_Environment::normalizePath($path); $uri = Less_Environment::normalizePath(dirname($rooturi.$evald_path)); return array( $full_path, $uri ); + } elseif( file_exists($path.'.less') ){ + $full_path = Less_Environment::normalizePath($path.'.less'); + $uri = Less_Environment::normalizePath(dirname($rooturi.$evald_path.'.less')); + return array( $full_path, $uri ); } } } @@ -250,7 +254,7 @@ class Less_Tree_Import extends Less_Tree{ * * @return Less_Tree_Media|array */ - function ParseImport( $full_path, $uri, $env ){ + public function ParseImport( $full_path, $uri, $env ){ $import_env = clone $env; if( (isset($this->options['reference']) && $this->options['reference']) || isset($this->currentFileInfo['reference']) ){ @@ -279,7 +283,7 @@ class Less_Tree_Import extends Less_Tree{ */ private function Skip($path, $env){ - $path = realpath($path); + $path = Less_Parser::winPath(realpath($path)); if( $path && Less_Parser::FileParsed($path) ){ diff --git a/lib/lessphp/Tree/Javascript.php b/lib/lessphp/Tree/Javascript.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Keyword.php b/lib/lessphp/Tree/Keyword.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Media.php b/lib/lessphp/Tree/Media.php old mode 100644 new mode 100755 index aebd28da22a..f9ee9d4214b --- a/lib/lessphp/Tree/Media.php +++ b/lib/lessphp/Tree/Media.php @@ -28,7 +28,7 @@ class Less_Tree_Media extends Less_Tree{ $this->rules[0]->allowImports = true; } - function accept( $visitor ){ + public function accept( $visitor ){ $this->features = $visitor->visitObj($this->features); $this->rules = $visitor->visitArray($this->rules); } @@ -36,7 +36,7 @@ class Less_Tree_Media extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( '@media ', $this->currentFileInfo, $this->index ); $this->features->genCSS( $output ); @@ -169,7 +169,7 @@ class Less_Tree_Media extends Less_Tree{ return $result; } - function bubbleSelectors($selectors) { + public function bubbleSelectors($selectors) { if( !$selectors) return; diff --git a/lib/lessphp/Tree/Mixin/Call.php b/lib/lessphp/Tree/Mixin/Call.php old mode 100644 new mode 100755 index d3163d86650..d7e2a137cbe --- a/lib/lessphp/Tree/Mixin/Call.php +++ b/lib/lessphp/Tree/Mixin/Call.php @@ -107,7 +107,7 @@ class Less_Tree_Mixin_Call extends Less_Tree{ } else { $defaultResult = $defTrue; if( ($count[$defTrue] + $count[$defFalse]) > 1 ){ - throw Exception( 'Ambiguous use of `default()` found when matching for `'. $this->format($args) + '`' ); + throw new Exception( 'Ambiguous use of `default()` found when matching for `'. $this->format($args) + '`' ); } } @@ -145,7 +145,7 @@ class Less_Tree_Mixin_Call extends Less_Tree{ throw new Less_Exception_Compiler('No matching definition was found for `'.$this->Format( $args ).'`', null, $this->index, $this->currentFileInfo); }else{ - throw new Less_Exception_Compiler(trim($this->selector->toCSS()) . " is undefined", null, $this->index); + throw new Less_Exception_Compiler(trim($this->selector->toCSS()) . " is undefined in ".$this->currentFileInfo['filename'], null, $this->index); } } diff --git a/lib/lessphp/Tree/Mixin/Definition.php b/lib/lessphp/Tree/Mixin/Definition.php old mode 100644 new mode 100755 index 6fb42e1928d..b16d6887127 --- a/lib/lessphp/Tree/Mixin/Definition.php +++ b/lib/lessphp/Tree/Mixin/Definition.php @@ -15,7 +15,7 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset{ // less.js : /lib/less/tree/mixin.js : tree.mixin.Definition - public function __construct($name, $params, $rules, $condition, $variadic = false, $frames = null ){ + public function __construct($name, $params, $rules, $condition, $variadic = false, $frames = array() ){ $this->name = $name; $this->selectors = array(new Less_Tree_Selector(array( new Less_Tree_Element(null, $name)))); @@ -190,6 +190,11 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset{ return true; } + // set array to prevent error on array_merge + if(!is_array($this->frames)) { + $this->frames = array(); + } + $frame = $this->compileParams($env, array_merge($this->frames,$env->frames), $args ); $compile_env = new Less_Environment(); @@ -199,6 +204,8 @@ class Less_Tree_Mixin_Definition extends Less_Tree_Ruleset{ , $env->frames // the current environment frames ); + $compile_env->functions = $env->functions; + return (bool)$this->condition->compile($compile_env); } diff --git a/lib/lessphp/Tree/NameValue.php b/lib/lessphp/Tree/NameValue.php old mode 100644 new mode 100755 index 7ced5ccfc9f..e65737c2fe1 --- a/lib/lessphp/Tree/NameValue.php +++ b/lib/lessphp/Tree/NameValue.php @@ -25,7 +25,7 @@ class Less_Tree_NameValue extends Less_Tree{ $this->currentFileInfo = $currentFileInfo; } - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( $this->name diff --git a/lib/lessphp/Tree/Negative.php b/lib/lessphp/Tree/Negative.php old mode 100644 new mode 100755 index 20cdbb3bfe2..507443ecf61 --- a/lib/lessphp/Tree/Negative.php +++ b/lib/lessphp/Tree/Negative.php @@ -11,7 +11,7 @@ class Less_Tree_Negative extends Less_Tree{ public $value; public $type = 'Negative'; - function __construct($node){ + public function __construct($node){ $this->value = $node; } @@ -22,12 +22,12 @@ class Less_Tree_Negative extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( '-' ); $this->value->genCSS( $output ); } - function compile($env) { + public function compile($env) { if( Less_Environment::isMathOn() ){ $ret = new Less_Tree_Operation('*', array( new Less_Tree_Dimension(-1), $this->value ) ); return $ret->compile($env); diff --git a/lib/lessphp/Tree/Operation.php b/lib/lessphp/Tree/Operation.php old mode 100644 new mode 100755 index 6d8a0d4a9d8..e69e0da6eed --- a/lib/lessphp/Tree/Operation.php +++ b/lib/lessphp/Tree/Operation.php @@ -22,7 +22,7 @@ class Less_Tree_Operation extends Less_Tree{ $this->isSpaced = $isSpaced; } - function accept($visitor) { + public function accept($visitor) { $this->operands = $visitor->visitArray($this->operands); } @@ -55,7 +55,7 @@ class Less_Tree_Operation extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $this->operands[0]->genCSS( $output ); if( $this->isSpaced ){ $output->add( " " ); diff --git a/lib/lessphp/Tree/Paren.php b/lib/lessphp/Tree/Paren.php old mode 100644 new mode 100755 index e865c898647..01864550a6e --- a/lib/lessphp/Tree/Paren.php +++ b/lib/lessphp/Tree/Paren.php @@ -15,14 +15,14 @@ class Less_Tree_Paren extends Less_Tree{ $this->value = $value; } - function accept($visitor){ + public function accept($visitor){ $this->value = $visitor->visitObj($this->value); } /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( '(' ); $this->value->genCSS( $output ); $output->add( ')' ); diff --git a/lib/lessphp/Tree/Quoted.php b/lib/lessphp/Tree/Quoted.php old mode 100644 new mode 100755 index 32cd7359242..80063b5efa1 --- a/lib/lessphp/Tree/Quoted.php +++ b/lib/lessphp/Tree/Quoted.php @@ -63,7 +63,7 @@ class Less_Tree_Quoted extends Less_Tree{ return new Less_Tree_Quoted($this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo); } - function compare($x) { + public function compare($x) { if( !Less_Parser::is_method($x, 'toCSS') ){ return -1; diff --git a/lib/lessphp/Tree/Rule.php b/lib/lessphp/Tree/Rule.php old mode 100644 new mode 100755 index 221008bf1c5..ee4a9e2574c --- a/lib/lessphp/Tree/Rule.php +++ b/lib/lessphp/Tree/Rule.php @@ -32,14 +32,14 @@ class Less_Tree_Rule extends Less_Tree{ $this->variable = ( is_string($name) && $name[0] === '@'); } - function accept($visitor) { + public function accept($visitor) { $this->value = $visitor->visitObj( $this->value ); } /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( $this->name . Less_Environment::$_outputMap[': '], $this->currentFileInfo, $this->index); try{ @@ -100,7 +100,7 @@ class Less_Tree_Rule extends Less_Tree{ } - function CompileName( $env, $name ){ + public function CompileName( $env, $name ){ $output = new Less_Output(); foreach($name as $n){ $n->compile($env)->genCSS($output); @@ -108,7 +108,7 @@ class Less_Tree_Rule extends Less_Tree{ return $output->toString(); } - function makeImportant(){ + public function makeImportant(){ return new Less_Tree_Rule($this->name, $this->value, '!important', $this->merge, $this->index, $this->currentFileInfo, $this->inline); } diff --git a/lib/lessphp/Tree/Ruleset.php b/lib/lessphp/Tree/Ruleset.php old mode 100644 new mode 100755 index 908e5a81a40..93d3d6b7bd8 --- a/lib/lessphp/Tree/Ruleset.php +++ b/lib/lessphp/Tree/Ruleset.php @@ -24,10 +24,10 @@ class Less_Tree_Ruleset extends Less_Tree{ public $multiMedia; public $allExtends; - var $ruleset_id; - var $originalRuleset; + public $ruleset_id; + public $originalRuleset; - var $first_oelements; + public $first_oelements; public function SetRulesetIndex(){ $this->ruleset_id = Less_Parser::$next_id++; @@ -50,7 +50,7 @@ class Less_Tree_Ruleset extends Less_Tree{ $this->SetRulesetIndex(); } - function accept( $visitor ){ + public function accept( $visitor ){ if( $this->paths ){ $paths_len = count($this->paths); for($i = 0,$paths_len; $i < $paths_len; $i++ ){ diff --git a/lib/lessphp/Tree/RulesetCall.php b/lib/lessphp/Tree/RulesetCall.php index deac79f511e..ed4c7237316 100644 --- a/lib/lessphp/Tree/RulesetCall.php +++ b/lib/lessphp/Tree/RulesetCall.php @@ -11,13 +11,13 @@ class Less_Tree_RulesetCall extends Less_Tree{ public $variable; public $type = "RulesetCall"; - function __construct($variable){ + public function __construct($variable){ $this->variable = $variable; } - function accept($visitor) {} + public function accept($visitor) {} - function compile( $env ){ + public function compile( $env ){ $variable = new Less_Tree_Variable($this->variable); $detachedRuleset = $variable->compile($env); return $detachedRuleset->callEval($env); diff --git a/lib/lessphp/Tree/Selector.php b/lib/lessphp/Tree/Selector.php old mode 100644 new mode 100755 index 74872fcff72..6b9dae6125b --- a/lib/lessphp/Tree/Selector.php +++ b/lib/lessphp/Tree/Selector.php @@ -45,7 +45,7 @@ class Less_Tree_Selector extends Less_Tree{ $this->CacheElements(); } - function accept($visitor) { + public function accept($visitor) { $this->elements = $visitor->visitArray($this->elements); $this->extendList = $visitor->visitArray($this->extendList); if( $this->condition ){ @@ -57,7 +57,7 @@ class Less_Tree_Selector extends Less_Tree{ } } - function createDerived( $elements, $extendList = null, $evaldCondition = null ){ + public function createDerived( $elements, $extendList = null, $evaldCondition = null ){ $newSelector = new Less_Tree_Selector( $elements, ($extendList ? $extendList : $this->extendList), null, $this->index, $this->currentFileInfo, $this->isReferenced); $newSelector->evaldCondition = $evaldCondition ? $evaldCondition : $this->evaldCondition; return $newSelector; @@ -142,7 +142,7 @@ class Less_Tree_Selector extends Less_Tree{ /** * @see Less_Tree::genCSS */ - function genCSS( $output, $firstSelector = true ){ + public function genCSS( $output, $firstSelector = true ){ if( !$firstSelector && $this->elements[0]->combinator === "" ){ $output->add(' ', $this->currentFileInfo, $this->index); @@ -153,15 +153,15 @@ class Less_Tree_Selector extends Less_Tree{ } } - function markReferenced(){ + public function markReferenced(){ $this->isReferenced = true; } - function getIsReferenced(){ + public function getIsReferenced(){ return !isset($this->currentFileInfo['reference']) || !$this->currentFileInfo['reference'] || $this->isReferenced; } - function getIsOutput(){ + public function getIsOutput(){ return $this->evaldCondition; } diff --git a/lib/lessphp/Tree/UnicodeDescriptor.php b/lib/lessphp/Tree/UnicodeDescriptor.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Unit.php b/lib/lessphp/Tree/Unit.php old mode 100644 new mode 100755 index 8ab6f43c0bb..e13b100e26f --- a/lib/lessphp/Tree/Unit.php +++ b/lib/lessphp/Tree/Unit.php @@ -13,19 +13,19 @@ class Less_Tree_Unit extends Less_Tree{ public $backupUnit; public $type = 'Unit'; - function __construct($numerator = array(), $denominator = array(), $backupUnit = null ){ + public function __construct($numerator = array(), $denominator = array(), $backupUnit = null ){ $this->numerator = $numerator; $this->denominator = $denominator; $this->backupUnit = $backupUnit; } - function __clone(){ + public function __clone(){ } /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ if( $this->numerator ){ $output->add( $this->numerator[0] ); @@ -37,7 +37,7 @@ class Less_Tree_Unit extends Less_Tree{ } } - function toString(){ + public function toString(){ $returnStr = implode('*',$this->numerator); foreach($this->denominator as $d){ $returnStr .= '/'.$d; @@ -45,7 +45,7 @@ class Less_Tree_Unit extends Less_Tree{ return $returnStr; } - function __toString(){ + public function __toString(){ return $this->toString(); } @@ -53,33 +53,33 @@ class Less_Tree_Unit extends Less_Tree{ /** * @param Less_Tree_Unit $other */ - function compare($other) { + public function compare($other) { return $this->is( $other->toString() ) ? 0 : -1; } - function is($unitString){ + public function is($unitString){ return $this->toString() === $unitString; } - function isLength(){ + public function isLength(){ $css = $this->toCSS(); return !!preg_match('/px|em|%|in|cm|mm|pc|pt|ex/',$css); } - function isAngle() { + public function isAngle() { return isset( Less_Tree_UnitConversions::$angle[$this->toCSS()] ); } - function isEmpty(){ + public function isEmpty(){ return !$this->numerator && !$this->denominator; } - function isSingular() { + public function isSingular() { return count($this->numerator) <= 1 && !$this->denominator; } - function usedUnits(){ + public function usedUnits(){ $result = array(); foreach(Less_Tree_UnitConversions::$groups as $groupName){ @@ -101,7 +101,7 @@ class Less_Tree_Unit extends Less_Tree{ return $result; } - function cancel(){ + public function cancel(){ $counter = array(); $backup = null; diff --git a/lib/lessphp/Tree/UnitConversions.php b/lib/lessphp/Tree/UnitConversions.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Tree/Url.php b/lib/lessphp/Tree/Url.php old mode 100644 new mode 100755 index 52384c9961d..ef9c3c68c23 --- a/lib/lessphp/Tree/Url.php +++ b/lib/lessphp/Tree/Url.php @@ -20,14 +20,14 @@ class Less_Tree_Url extends Less_Tree{ $this->isEvald = $isEvald; } - function accept( $visitor ){ + public function accept( $visitor ){ $this->value = $visitor->visitObj($this->value); } /** * @see Less_Tree::genCSS */ - function genCSS( $output ){ + public function genCSS( $output ){ $output->add( 'url(' ); $this->value->genCSS( $output ); $output->add( ')' ); diff --git a/lib/lessphp/Tree/Value.php b/lib/lessphp/Tree/Value.php old mode 100644 new mode 100755 index 67602155f39..9f077bc5676 --- a/lib/lessphp/Tree/Value.php +++ b/lib/lessphp/Tree/Value.php @@ -15,7 +15,7 @@ class Less_Tree_Value extends Less_Tree{ $this->value = $value; } - function accept($visitor) { + public function accept($visitor) { $this->value = $visitor->visitArray($this->value); } diff --git a/lib/lessphp/Tree/Variable.php b/lib/lessphp/Tree/Variable.php old mode 100644 new mode 100755 index fd774627f10..cc0182cde94 --- a/lib/lessphp/Tree/Variable.php +++ b/lib/lessphp/Tree/Variable.php @@ -26,7 +26,7 @@ class Less_Tree_Variable extends Less_Tree{ public function compile($env) { if( $this->name[1] === '@' ){ - $v = new Less_Tree_Variable(substr($this->name, 1), $this->index + 1); + $v = new Less_Tree_Variable(substr($this->name, 1), $this->index + 1, $this->currentFileInfo); $name = '@' . $v->compile($env)->value; }else{ $name = $this->name; @@ -40,12 +40,13 @@ class Less_Tree_Variable extends Less_Tree{ foreach($env->frames as $frame){ if( $v = $frame->variable($name) ){ + $r = $v->value->compile($env); $this->evaluating = false; - return $v->value->compile($env); + return $r; } } - throw new Less_Exception_Compiler("variable " . $name . " is undefined", null, $this->index ); + throw new Less_Exception_Compiler("variable " . $name . " is undefined in file ".$this->currentFileInfo["filename"], null, $this->index, $this->currentFileInfo); } } diff --git a/lib/lessphp/Version.php b/lib/lessphp/Version.php old mode 100644 new mode 100755 index 5737a509757..1e95433382e --- a/lib/lessphp/Version.php +++ b/lib/lessphp/Version.php @@ -8,7 +8,7 @@ */ class Less_Version{ - const version = '1.7.0.1'; // The current build number of less.php + const version = '1.7.0.3'; // The current build number of less.php const less_version = '1.7'; // The less.js version that this build should be compatible with const cache_version = '170'; // The parser cache version diff --git a/lib/lessphp/Visitor.php b/lib/lessphp/Visitor.php old mode 100644 new mode 100755 index 9bd6a7bc8aa..d85f1d910d9 --- a/lib/lessphp/Visitor.php +++ b/lib/lessphp/Visitor.php @@ -8,15 +8,15 @@ */ class Less_Visitor{ - var $methods = array(); - var $_visitFnCache = array(); + protected $methods = array(); + protected $_visitFnCache = array(); - function __construct(){ + public function __construct(){ $this->_visitFnCache = get_class_methods(get_class($this)); $this->_visitFnCache = array_flip($this->_visitFnCache); } - function visitObj( $node ){ + public function visitObj( $node ){ $funcName = 'visit'.$node->type; if( isset($this->_visitFnCache[$funcName]) ){ @@ -40,7 +40,7 @@ class Less_Visitor{ return $node; } - function visitArray( $nodes ){ + public function visitArray( $nodes ){ array_map( array($this,'visitObj'), $nodes); return $nodes; diff --git a/lib/lessphp/Visitor/extendFinder.php b/lib/lessphp/Visitor/extendFinder.php old mode 100644 new mode 100755 index 28be9ae93ff..22b3aac99a9 --- a/lib/lessphp/Visitor/extendFinder.php +++ b/lib/lessphp/Visitor/extendFinder.php @@ -12,7 +12,7 @@ class Less_Visitor_extendFinder extends Less_Visitor{ public $allExtendsStack; public $foundExtends; - function __construct(){ + public function __construct(){ $this->contexts = array(); $this->allExtendsStack = array(array()); parent::__construct(); @@ -21,21 +21,21 @@ class Less_Visitor_extendFinder extends Less_Visitor{ /** * @param Less_Tree_Ruleset $root */ - function run($root){ + public function run($root){ $root = $this->visitObj($root); $root->allExtends =& $this->allExtendsStack[0]; return $root; } - function visitRule($ruleNode, &$visitDeeper ){ + public function visitRule($ruleNode, &$visitDeeper ){ $visitDeeper = false; } - function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){ + public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){ $visitDeeper = false; } - function visitRuleset($rulesetNode){ + public function visitRuleset($rulesetNode){ if( $rulesetNode->root ){ return; @@ -71,7 +71,7 @@ class Less_Visitor_extendFinder extends Less_Visitor{ $this->contexts[] = $rulesetNode->selectors; } - function allExtendsStackPush($rulesetNode, $selectorPath, $extend, &$j){ + public function allExtendsStackPush($rulesetNode, $selectorPath, $extend, &$j){ $this->foundExtends = true; $extend = clone $extend; $extend->findSelfSelectors( $selectorPath ); @@ -86,27 +86,27 @@ class Less_Visitor_extendFinder extends Less_Visitor{ } - function visitRulesetOut( $rulesetNode ){ + public function visitRulesetOut( $rulesetNode ){ if( !is_object($rulesetNode) || !$rulesetNode->root ){ array_pop($this->contexts); } } - function visitMedia( $mediaNode ){ + public function visitMedia( $mediaNode ){ $mediaNode->allExtends = array(); $this->allExtendsStack[] =& $mediaNode->allExtends; } - function visitMediaOut(){ + public function visitMediaOut(){ array_pop($this->allExtendsStack); } - function visitDirective( $directiveNode ){ + public function visitDirective( $directiveNode ){ $directiveNode->allExtends = array(); $this->allExtendsStack[] =& $directiveNode->allExtends; } - function visitDirectiveOut(){ + public function visitDirectiveOut(){ array_pop($this->allExtendsStack); } } diff --git a/lib/lessphp/Visitor/import.php b/lib/lessphp/Visitor/import.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Visitor/joinSelector.php b/lib/lessphp/Visitor/joinSelector.php old mode 100644 new mode 100755 index 540eb3d34e3..f62af1a985b --- a/lib/lessphp/Visitor/joinSelector.php +++ b/lib/lessphp/Visitor/joinSelector.php @@ -13,19 +13,19 @@ class Less_Visitor_joinSelector extends Less_Visitor{ /** * @param Less_Tree_Ruleset $root */ - function run( $root ){ + public function run( $root ){ return $this->visitObj($root); } - function visitRule( $ruleNode, &$visitDeeper ){ + public function visitRule( $ruleNode, &$visitDeeper ){ $visitDeeper = false; } - function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){ + public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){ $visitDeeper = false; } - function visitRuleset( $rulesetNode ){ + public function visitRuleset( $rulesetNode ){ $paths = array(); @@ -54,11 +54,11 @@ class Less_Visitor_joinSelector extends Less_Visitor{ $this->contexts[] = $paths; //different from less.js. Placed after joinSelectors() so that $this->contexts will get correct $paths } - function visitRulesetOut(){ + public function visitRulesetOut(){ array_pop($this->contexts); } - function visitMedia($mediaNode) { + public function visitMedia($mediaNode) { $context = end($this->contexts); //$context = $this->contexts[ count($this->contexts) - 1]; if( !count($context) || (is_object($context[0]) && $context[0]->multiMedia) ){ diff --git a/lib/lessphp/Visitor/processExtends.php b/lib/lessphp/Visitor/processExtends.php old mode 100644 new mode 100755 diff --git a/lib/lessphp/Visitor/toCSS.php b/lib/lessphp/Visitor/toCSS.php old mode 100644 new mode 100755 index 93da6c25d82..18d328ffefd --- a/lib/lessphp/Visitor/toCSS.php +++ b/lib/lessphp/Visitor/toCSS.php @@ -10,43 +10,43 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ private $charset; - function __construct(){ + public function __construct(){ parent::__construct(); } /** * @param Less_Tree_Ruleset $root */ - function run( $root ){ + public function run( $root ){ return $this->visitObj($root); } - function visitRule( $ruleNode ){ + public function visitRule( $ruleNode ){ if( $ruleNode->variable ){ return array(); } return $ruleNode; } - function visitMixinDefinition($mixinNode){ + public function visitMixinDefinition($mixinNode){ // mixin definitions do not get eval'd - this means they keep state // so we have to clear that state here so it isn't used if toCSS is called twice $mixinNode->frames = array(); return array(); } - function visitExtend(){ + public function visitExtend(){ return array(); } - function visitComment( $commentNode ){ + public function visitComment( $commentNode ){ if( $commentNode->isSilent() ){ return array(); } return $commentNode; } - function visitMedia( $mediaNode, &$visitDeeper ){ + public function visitMedia( $mediaNode, &$visitDeeper ){ $mediaNode->accept($this); $visitDeeper = false; @@ -56,7 +56,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ return $mediaNode; } - function visitDirective( $directiveNode ){ + public function visitDirective( $directiveNode ){ if( isset($directiveNode->currentFileInfo['reference']) && (!property_exists($directiveNode,'isReferenced') || !$directiveNode->isReferenced) ){ return array(); } @@ -80,7 +80,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ return $directiveNode; } - function checkPropertiesInRoot( $rulesetNode ){ + public function checkPropertiesInRoot( $rulesetNode ){ if( !$rulesetNode->firstRoot ){ return; @@ -95,7 +95,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ } - function visitRuleset( $rulesetNode, &$visitDeeper ){ + public function visitRuleset( $rulesetNode, &$visitDeeper ){ $visitDeeper = false; @@ -192,7 +192,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ return $paths; } - function _removeDuplicateRules( &$rules ){ + protected function _removeDuplicateRules( &$rules ){ // remove duplicates $ruleCache = array(); for( $i = count($rules)-1; $i >= 0 ; $i-- ){ @@ -219,7 +219,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ } } - function _mergeRules( &$rules ){ + protected function _mergeRules( &$rules ){ $groups = array(); //obj($rules); @@ -271,7 +271,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ } - static function toExpression($values){ + public static function toExpression($values){ $mapped = array(); foreach($values as $p){ $mapped[] = $p->value; @@ -279,7 +279,7 @@ class Less_Visitor_toCSS extends Less_VisitorReplacing{ return new Less_Tree_Expression( $mapped ); } - static function toValue($values){ + public static function toValue($values){ //return new Less_Tree_Value($values); ?? $mapped = array(); diff --git a/lib/lessphp/VisitorReplacing.php b/lib/lessphp/VisitorReplacing.php old mode 100644 new mode 100755 index e4189e747a4..5923170e2fe --- a/lib/lessphp/VisitorReplacing.php +++ b/lib/lessphp/VisitorReplacing.php @@ -8,7 +8,7 @@ */ class Less_VisitorReplacing extends Less_Visitor{ - function visitObj( $node ){ + public function visitObj( $node ){ $funcName = 'visit'.$node->type; if( isset($this->_visitFnCache[$funcName]) ){ @@ -34,7 +34,7 @@ class Less_VisitorReplacing extends Less_Visitor{ return $node; } - function visitArray( $nodes ){ + public function visitArray( $nodes ){ $newNodes = array(); foreach($nodes as $node){ @@ -50,7 +50,7 @@ class Less_VisitorReplacing extends Less_Visitor{ return $newNodes; } - function flatten( $arr, &$out ){ + public function flatten( $arr, &$out ){ foreach($arr as $item){ if( !is_array($item) ){ diff --git a/lib/lessphp/moodle_readme.txt b/lib/lessphp/moodle_readme.txt index b0fd18cd994..fac01409a44 100644 --- a/lib/lessphp/moodle_readme.txt +++ b/lib/lessphp/moodle_readme.txt @@ -1,7 +1,7 @@ less.php -------- -Tag downloaded: v1.7.0.1 +Tag downloaded: v1.7.0.3 Downloaded from: https://github.com/oyejorge/less.php All the files from the folder lib/Less are copied in diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 8a252d05c23..fafa6c43bf3 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -32,7 +32,7 @@ lessphp less.php Apache - 1.7.0.1 + 1.7.0.3 2.0