From 16e8f149dea61f4caf9aca19a09d0b63df9d54a4 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Tue, 8 Jun 2010 00:41:48 +0800 Subject: [PATCH 01/13] Added functionality to detect a mod_rewritten caller-file so that the relative path to the Booster-markup gets adapted accordingly. Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 8 ++++++-- booster/wp_booster.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 4e7c783..b76e3b4 100644 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -981,8 +981,10 @@ public function css_markup() // Empty storage for markup to come $markup = ''; + // Calculate possible relative path-offset created by mod_rewrite + $booster_offset_path = rtrim($this->getpath(dirname($_SERVER['REQUEST_URI']),dirname($_SERVER['SCRIPT_NAME'])),'/'); // Calculate relative path from calling script to booster-folder - $booster_path = $this->getpath(str_replace('\\','/',dirname(__FILE__)),dirname($_SERVER['SCRIPT_FILENAME'])); + $booster_path = $booster_offset_path.'/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),dirname($_SERVER['SCRIPT_FILENAME'])); // Calculate relative path from booster-folder to calling script $css_path = $this->getpath(dirname($_SERVER['SCRIPT_FILENAME']),str_replace('\\','/',dirname(__FILE__))); @@ -1185,8 +1187,10 @@ public function js_markup() // Empty storage for markup to come $markup = ''; + // Calculate possible relative path-offset created by mod_rewrite + $booster_offset_path = rtrim($this->getpath(dirname($_SERVER['REQUEST_URI']),dirname($_SERVER['SCRIPT_NAME'])),'/'); // Calculate relative path from calling script to booster-folder - $booster_path = $this->getpath(str_replace('\\','/',dirname(__FILE__)),dirname($_SERVER['SCRIPT_FILENAME'])); + $booster_path = $booster_offset_path.'/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),dirname($_SERVER['SCRIPT_FILENAME'])); // Calculate relative path from booster-folder to calling script $js_path = $this->getpath(dirname($_SERVER['SCRIPT_FILENAME']),str_replace('\\','/',dirname(__FILE__))); diff --git a/booster/wp_booster.php b/booster/wp_booster.php index 6d4ab1c..de09634 100644 --- a/booster/wp_booster.php +++ b/booster/wp_booster.php @@ -3,7 +3,7 @@ Plugin Name: CSS-JS-Booster Plugin URI: http://github.com/Schepp/CSS-JS-Booster Description: automates performance optimizing steps related to CSS, Media and Javascript linking/embedding. -Version: 0.2.5 +Version: 0.2.6 Author: Christian "Schepp" Schaefer Author URI: http://twitter.com/derSchepp */ From 14f73b7ccb73efa8470b5972a05bf34d57717c65 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Tue, 8 Jun 2010 07:49:36 +0800 Subject: [PATCH 02/13] Did some subtle changes to the syntax to check if minification-features work well. Signed-off-by: Christian Schepp Schaefer --- examples/example1/css/style.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example1/css/style.css b/examples/example1/css/style.css index 3802deb..d4fd614 100644 --- a/examples/example1/css/style.css +++ b/examples/example1/css/style.css @@ -1,5 +1,5 @@ /* CSS Document */ -body{padding:0px; margin:0px; background:url(../images/mainbg.gif) 0 0 repeat-x #fff; color:#705D20; font:14px/18px Arial, Helvetica, sans-serif;} +body{padding: 0 px; margin:0px; background:url("../images/mainbg.gif") 0 0 repeat-x #fff; color:#705D20; font:14px/18px Arial, Helvetica, sans-serif;} div, p, ul, h1, h2, h3, form, img{padding:0px; margin:0px;} ul{list-style-type:none;} @@ -7,7 +7,7 @@ a{background:#FEFEFE; color:#fff; text-decoration:none;} a:hover{background:#FEFEFE; color:#fff; text-decoration:underline;} -#topPan{width:748px; height:231px; position:relative; margin:0 auto;} +#topPan{width: 748 px; height: 231 px; position:relative; margin:0 auto;} #topHeaderPan {width:332px; height:231px; background:url(../images/header.jpg) 0 100% no-repeat; position:relative;} #topHeaderPan img{width:191px; height:84px; display:block; position:absolute; top:120px; left:0px;} From a6dbfa249256d5a888dbb99c01ce3c5e29a66f04 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Tue, 8 Jun 2010 07:50:12 +0800 Subject: [PATCH 03/13] Updated README to reflect the dropping of CSSTidy and the inclusion of JSMin. Signed-off-by: Christian Schepp Schaefer --- README.textile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.textile b/README.textile index 3744315..6efb3b4 100644 --- a/README.textile +++ b/README.textile @@ -23,7 +23,7 @@ optimizing steps related to CSS and JS embedding as possible. For CSS these steps are: * combine multiple CSS-files resulting in HTTP-requests going down -* optimize and minify CSS with CSSTidy +* minify CSS * Embed any CSS-images smaller 24KB as data-URI or MHTML (for IE <= 7) * Split the output back into 2 even files that can load in parallel (not for WP) * GZIP-compress the resulting CSS @@ -32,7 +32,7 @@ For CSS these steps are: For JS these steps are: * combine multiple JS-files resulting in HTTP-requests going down -* Minify the JS through the Google Closure Compiler Webservice (not for WP) +* Minify the JS through the Google Closure Compiler Webservice, or JSMin as fallback (not for WP) * GZIP-compress the resulting JS * Have browsers cache the result as long as it remains unchanged @@ -334,9 +334,8 @@ So you need to check yourself. h1. Copyright and License Information for 3rd party elements used in the scripts -CSSTidy 1.3 is taken from here: -"http://csstidy.sourceforge.net/":http://csstidy.sourceforge.net/ -You find its license inside booster's csstidy-1.3-folder +JSMin is origined from here: +"http://www.crockford.com/javascript/jsmin.html":http://www.crockford.com/javascript/jsmin.html Browser detection was rewritten based on work from Paul Scott found here: "http://www.phpclasses.org/browse/file/12369.html":http://www.phpclasses.org/browse/file/12369.html From eddf23b4a54ea1aee33058aa90244ad14eaadc3d Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Tue, 8 Jun 2010 08:49:16 +0800 Subject: [PATCH 04/13] Updated the introduction that still stated that there will be no JS-minification. Signed-off-by: Christian Schepp Schaefer --- README.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.textile b/README.textile index 6efb3b4..77dc682 100644 --- a/README.textile +++ b/README.textile @@ -9,10 +9,10 @@ This piece of code is still fresh so that others can start testing and/or using and/or enhancing it. That said, there shouldn't be too many bugs left. If you find some, contact me or open an issue in the bugtracker. -Not a bug is that I don't plan to support browsers older than IE6SP2. -It's also not intended to minify or further compress (like with Dean Edwards - packer) the JS, as I experienced a lot of trouble doing that. -Also most large JS-libraries/frameworks are already offered heavily minified. +Browsers older than IE6SP2 are not supported. +The reason is that I use GZIP-compression and IE6 with service pack 2 +applied is the first IE6 to support that without quirks. Still, that should be +support enough as IE6SP2 was released back in August 2004. From e3f37f798c9457b5ec29ee0a28e71c7a35ed9e54 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Tue, 8 Jun 2010 18:57:10 +0800 Subject: [PATCH 05/13] Added functionality to detect a mod_rewritten caller-file so that the relative path to the Booster-markup gets adapted accordingly. Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index b76e3b4..5df07b1 100644 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -982,7 +982,7 @@ public function css_markup() $markup = ''; // Calculate possible relative path-offset created by mod_rewrite - $booster_offset_path = rtrim($this->getpath(dirname($_SERVER['REQUEST_URI']),dirname($_SERVER['SCRIPT_NAME'])),'/'); + $booster_offset_path = rtrim($this->getpath((substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI']) - 1,1) == '/' ? $_SERVER['REQUEST_URI'] : dirname($_SERVER['REQUEST_URI'])),dirname($_SERVER['SCRIPT_NAME'])),'/'); // Calculate relative path from calling script to booster-folder $booster_path = $booster_offset_path.'/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),dirname($_SERVER['SCRIPT_FILENAME'])); // Calculate relative path from booster-folder to calling script @@ -1188,7 +1188,7 @@ public function js_markup() $markup = ''; // Calculate possible relative path-offset created by mod_rewrite - $booster_offset_path = rtrim($this->getpath(dirname($_SERVER['REQUEST_URI']),dirname($_SERVER['SCRIPT_NAME'])),'/'); + $booster_offset_path = rtrim($this->getpath((substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI']) - 1,1) == '/' ? $_SERVER['REQUEST_URI'] : dirname($_SERVER['REQUEST_URI'])),dirname($_SERVER['SCRIPT_NAME'])),'/'); // Calculate relative path from calling script to booster-folder $booster_path = $booster_offset_path.'/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),dirname($_SERVER['SCRIPT_FILENAME'])); // Calculate relative path from booster-folder to calling script From 52dfd26cd9248b99d95be1939a7d54625dee45b5 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Sun, 11 Jul 2010 18:11:43 +0800 Subject: [PATCH 06/13] Found and fixed a bug occurring in Wordpress-plugin with inline-files (CSS or JS) Changed an error message wording Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 6 +++--- booster/wp_booster.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 920e755..9c1d2e7 100644 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -475,7 +475,7 @@ public function setcachedir() // Throw a warning and quit if cache-directory doesn't exist or isn't writable if(!@is_dir($this->booster_cachedir) && !@mkdir($this->booster_cachedir,0777)) { - $errormessage = "\r\nYou need to create a directory \r\n".$this->booster_cachedir."\r\n with CHMOD 0777 rights.\r\n"; + $errormessage = "\r\nYou need to create a directory \r\n".$this->booster_cachedir."\r\n with CHMOD 0777 rights.\r\nAfterwards, delete your browser's cache and reload.\r\n"; } // Also check here for the right PHP version if(strnatcmp(phpversion(),'5.0.0') < 0) @@ -1458,7 +1458,7 @@ public function css() if($source != '') { // If current source is a folder or file, get its contents - if(is_dir($source) || is_file($source)) $currentfilescontent = $this->getfilescontents($source,$type,$this->css_recursive); + if(file_exists($source) || is_dir($source) || is_file($source)) $currentfilescontent = $this->getfilescontents($source,$type,$this->css_recursive); // If current source is already a string else $currentfilescontent = $source; @@ -1716,7 +1716,7 @@ public function js() $source = rtrim($source,'/'); // If current source is a folder or file, get its contents - if(is_dir($source) || is_file($source)) $filescontent .= $this->getfilescontents($source,$type,$this->js_recursive); + if(file_exists($source) || is_dir($source) || is_file($source)) $filescontent .= $this->getfilescontents($source,$type,$this->js_recursive); // If current source is already a string else $filescontent .= $source; diff --git a/booster/wp_booster.php b/booster/wp_booster.php index 8f1aac0..2aac77a 100644 --- a/booster/wp_booster.php +++ b/booster/wp_booster.php @@ -3,7 +3,7 @@ Plugin Name: CSS-JS-Booster Plugin URI: http://github.com/Schepp/CSS-JS-Booster Description: automates performance optimizing steps related to CSS, Media and Javascript linking/embedding. -Version: 0.3.1 +Version: 0.3.2 Author: Christian "Schepp" Schaefer Author URI: http://twitter.com/derSchepp */ From 1dd616475da18107be020eb6d6dcdd383ed8541a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Kr=C3=B6ner?= Date: Sun, 8 Aug 2010 13:20:54 +0200 Subject: [PATCH 07/13] Provide the cache directory by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Kröner --- booster/.gitignore | 3 ++- booster/booster_cache/empty | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 booster/booster_cache/empty diff --git a/booster/.gitignore b/booster/.gitignore index 02a5fe3..675d633 100644 --- a/booster/.gitignore +++ b/booster/.gitignore @@ -1 +1,2 @@ -booster_cache +booster_cache/* +!booster_cache/empty diff --git a/booster/booster_cache/empty b/booster/booster_cache/empty new file mode 100644 index 0000000..573541a --- /dev/null +++ b/booster/booster_cache/empty @@ -0,0 +1 @@ +0 From 3542a4ebd4d62307d875e5f6b84d35981d2bec21 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Mon, 9 Aug 2010 21:50:08 +0800 Subject: [PATCH 08/13] - Fixed a little Bug in CSS split mechanism (affecting comments, but without destroying the CSS syntax) - Added logic which serves unoptimized files to any concurrently requesting clients during the creation of the final optimized files (which may take up to 15 seconds). - Added new configuration parameters in case one is using Apache's mod_userdir (et al) - Added new error messages and changed the way error messages get shown Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 334 ++++++++++++++++++++++++++++++---------- 1 file changed, 249 insertions(+), 85 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index a9efef1..67a4008 100755 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -52,16 +52,6 @@ /** * CSS-JS-BOOSTER -* -* An easy to use PHP-Library that combines, optimizes, dataURI-fies, re-splits, -* compresses and caches your CSS and JS for quicker loading times. -* -* @category PHP -* @package CSS-JS-Booster -* @author Christian Schepp Schaefer -* @copyright 2009 Christian Schepp Schaefer -* @license http://www.gnu.org/copyleft/lesser.html The GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 -* @link http://github.com/Schepp/CSS-JS-Booster */ class Booster { @@ -85,6 +75,28 @@ class Booster { */ public $filestime = 0; + /** + * Defines the server's root directory + * + * Use this if you changed the root with mod_userdir or something else + * Defaults to $_SERVER['DOCUMENT_ROOT'] + * @var string + * @access public + */ + public $document_root = ''; + + /** + * Defines the a base offset if $_SERVER['DOCUMENT_ROOT'] is not equal to http://domain/ + * but e.g. points to http://domain/~user/ + * + * Use this if you changed the root with mod_userdir or something else + * Defaults to '/'; + * Change for example to '/~user/'; + * @var string + * @access public + */ + public $base_offset = '/'; + /** * Defines the directory to use for caching * @@ -147,6 +159,14 @@ class Booster { */ private $debug_log = ''; + /** + * Variable in which to put error messages + * + * @var string + * @access private + */ + private $errormessage = ''; + // CSS specific configuration /////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -221,7 +241,7 @@ class Booster { * You can use the full YUI Compressor included in CSS-JS-Booster instead of the * included minification functions for stylesheets. * But be carefull, it will only work on dedicated servers with Java installed. - * @var boolean + * @var boolean * @access public */ public $css_hosted_minifier = FALSE; @@ -230,9 +250,9 @@ class Booster { * Defines the path to a hosted minifier * * Will store the local CSS minifier path relative to this file - * @var string + * @var string * @access private - * @see $css_hosted_minifier + * @see $css_hosted_minifier */ private $css_hosted_minifier_path = 'yuicompressor/yuicompressor-2.4.2.jar'; @@ -345,9 +365,9 @@ class Booster { * Defines the path to a hosted minifier * * Will store the local Google Closure Compiler path relative to this file - * @var string + * @var string * @access private - * @see $js_hosted_minifier + * @see $js_hosted_minifier */ private $js_hosted_minifier_path = 'compiler/compiler.jar'; @@ -428,11 +448,43 @@ class Booster { public function __construct() { $this->filestime = filemtime(__FILE__); + $this->document_root = $_SERVER['DOCUMENT_ROOT']; $this->css_stringtime = filemtime(realpath($_SERVER['SCRIPT_FILENAME'])); $this->css_hosted_minifier_path = realpath(dirname(__FILE__).'/'.$this->css_hosted_minifier_path); $this->js_stringtime = filemtime(realpath($_SERVER['SCRIPT_FILENAME'])); $this->js_hosted_minifier_path = realpath(dirname(__FILE__).'/'.$this->js_hosted_minifier_path); $this->browser = new browser(); + $this->errorcheck(); + } + + /** + * Looks after some parameters and outputs an error if applicable + * + * @return void + * @access private + */ + private function errorcheck() + { + // Throw a warning and quit if cache-directory doesn't exist or isn't writable + if(!@is_dir($this->booster_cachedir) && !@mkdir($this->booster_cachedir,0777)) + { + $this->errormessage = "\r\nYou need to create a directory \r\n".$this->get_absolute_path($this->booster_cachedir)."\r\n with CHMOD 0777 rights.\r\nAfterwards, delete your browser's cache and reload.\r\n"; + } + // Also check here for the right PHP version + if(strnatcmp(phpversion(),'5.0.0') < 0) + { + $this->errormessage = "\r\nYou need to upgrade to PHP 5 or higher to have CSS-JS-Booster work. You currently are running on PHP ".phpversion().".\r\n"; + } + // Check for incorrect document root (e.g. due to Apache's mod_userdir) + if($this->document_root == $_SERVER['DOCUMENT_ROOT'] && substr($this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$_SERVER['DOCUMENT_ROOT'])),0,2) == '..') + { + $this->errormessage = "\r\n".'$_SERVER[\'DOCUMENT_ROOT\'] variable is set to '.$_SERVER['DOCUMENT_ROOT'].'. But you seem to have a differing real document root. Please set the variable $booster->document_root to reflect your real document root'."\r\n"; + } + // Check for incorrect base path (e.g. due to Apache's mod_userdir) + if($this->base_offset.str_replace($this->document_root,'',$_SERVER['SCRIPT_FILENAME']) != parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH)) + { + $this->errormessage = "\r\n".'$booster->base_offset variable is set to '.$this->base_offset.'. But this server\'s document root seems to be differently offsetted. Please set the variable $booster->base_offset to reflect this offset'."\r\n".$this->base_offset.str_replace($this->document_root,'',$_SERVER['SCRIPT_FILENAME'])."\r\n".parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH)."\r\n"; + } } /** @@ -472,7 +524,7 @@ public function setcachedir() if($file[0] != '.' && strtolower(pathinfo($this->booster_cachedir.'/'.$file,PATHINFO_EXTENSION)) == 'txt' && $this->booster_cachedir.'/'.$file != $this->debug_log && - fileatime($this->booster_cachedir.'/'.$file) < (time() - 604800) + fileatime($this->booster_cachedir.'/'.$file) < ($_SERVER['REQUEST_TIME'] - 604800) ) { @unlink($this->booster_cachedir.'/'.$file); @@ -482,26 +534,6 @@ public function setcachedir() } } } - - $errormessage = ''; - // Throw a warning and quit if cache-directory doesn't exist or isn't writable - if(!@is_dir($this->booster_cachedir) && !@mkdir($this->booster_cachedir,0777)) - { - $errormessage = "\r\nYou need to create a directory \r\n".$this->get_absolute_path($this->booster_cachedir)."\r\n with CHMOD 0777 rights.\r\nAfterwards, delete your browser's cache and reload.\r\n"; - } - // Also check here for the right PHP version - if(strnatcmp(phpversion(),'5.0.0') < 0) - { - $errormessage = "\r\nYou need to upgrade to PHP 5 or higher to have CSS-JS-Booster work. You currently are running on PHP ".phpversion().".\r\n"; - } - // If there are error, output them and stop execution - if($errormessage != '') - { - $errormessage_css = str_replace("\r\n","\\00000A",$errormessage); - echo "/* ".$errormessage." */\r\n\r\n"; - echo "body:before {display: block; padding: 1em; background-color: #FFF9D0; color: #912C2C; border: 1px solid #912C2C; font-family: Calibri, 'Lucida Grande', Arial, Verdana, sans-serif; white-space: pre; content: \"".$errormessage_css."\";}\r\n\r\n"; - exit; - } } /** @@ -783,7 +815,7 @@ protected function getfilescontents($source = '',$type = '',$recursive = FALSE,$ // If it is a full URL, extract only the path if(substr($import,0,strlen($_SERVER['SERVER_NAME']) + 7) == 'http://'.$_SERVER['SERVER_NAME']) $import = parse_url($import,PHP_URL_PATH); // If it is an absolute path - if(substr($import,0,1) == '/') $importfile = str_replace('\\','/',realpath(rtrim($_SERVER['DOCUMENT_ROOT'],'/'))).$import; + if(substr($import,0,1) == '/') $importfile = str_replace('\\','/',realpath(rtrim($this->document_root,'/'))).$import; // Else if it is a relative path else $importfile = str_replace('\\','/',realpath(dirname($source))).'/'.$import; @@ -874,12 +906,6 @@ protected function css_minify($filescontent = '') // Constrain multiple whitespaces $filescontent = preg_replace('/\p{Zs}+/ims',' ',$filescontent); - // Insert newline at certain points as preparation for parsing - $filescontent = str_replace("{","\n{",$filescontent); - $filescontent = str_replace("}","\n}",$filescontent); - $filescontent = str_replace("/*","\n/*",$filescontent); - $filescontent = str_replace("*/","\n*/",$filescontent); - // Restore backupped values within single or double quotes for($i=0;$igetpath(str_replace('\\','/',dirname(__FILE__)),rtrim($_SERVER['DOCUMENT_ROOT'],'/')); + $mhtmlpath = $this->base_offset.$this->getpath(str_replace('\\','/',dirname(__FILE__)),rtrim($this->document_root,'/')); // Cachefile for the extra MHTML-data $mhtmlfile = $this->booster_cachedir.'/'.$identifier.'_datauri_mhtml_'.(($this->debug) ? 'debug_' : '').'cache.txt'; // Get Domainname @@ -965,7 +991,7 @@ protected function css_datauri($filescontent = '',$dir = '') // If it is an absolute path if(substr($treffer[1][$i],0,1) == '/') { - $imagefile = rtrim($_SERVER['DOCUMENT_ROOT'],'/').$treffer[1][$i].$treffer[2][$i]; + $imagefile = rtrim($this->document_root,'/').$treffer[1][$i].$treffer[2][$i]; } // If it is a relative path else @@ -1035,7 +1061,7 @@ protected function css_datauri($filescontent = '',$dir = '') // If it is an absolute path if(substr($treffer[1][$i],0,1) == '/') { - $imagefile = rtrim($_SERVER['DOCUMENT_ROOT'],'/').$treffer[1][$i].$treffer[2][$i]; + $imagefile = rtrim($this->document_root,'/').$treffer[1][$i].$treffer[2][$i]; } // If it is a relative path else @@ -1096,16 +1122,17 @@ protected function css_mhtml_enabled_ie() } /** - * Css_split takes a multiline CSS-string and splits it according to @var $css_totalparts and @var $css_part + * Css_datauri_cleanup prepends $dir to the path of all file-references found * - * @param string $filescontent contents to split - * @return string requested part-number of splitted content + * @param string $filescontent contents to scan + * @param string $dir folder name to prepend + * @return string content with adjusted paths * @access protected */ protected function css_datauri_cleanup($filescontent = '',$dir = '') { // Calculate absolute path for booster-folder - $booster_path = '/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$_SERVER['DOCUMENT_ROOT'])); + $booster_path = '/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$this->document_root)); // Scan for any left file-references and adjust their path $regex_url = '/(url\([\'"]??)([^\'"\)]+?\.[^\'"\)]+?)([\'"]??\))/msi'; @@ -1144,15 +1171,9 @@ protected function css_split($filescontent = '') // If sum of parts is 1 or requested part-number is 0 return full string if($this->css_totalparts == 1 || $this->css_part == 0 || $this->css_stringmode) { - // Cleanup newlines - $filescontent = preg_replace('/[\r\n]+/ims',"\n",$filescontent); - $filescontent = preg_replace('/\n[\t]+/ims',"\n",$filescontent); - $filescontent = preg_replace('/\{[\s\t]+/ims',"{",$filescontent); - $filescontent = str_replace("\n{","{",$filescontent); - $filescontent = str_replace("\n}","}",$filescontent); - $filescontent = str_replace(" \n","\n",$filescontent); - $filescontent = str_replace("\n\n*/","\n*/",$filescontent); - return $filescontent; + + // For library debugging purposes we log file contents + if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split input content (solo part ".$this->css_part."):\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); } // Else process string else @@ -1173,15 +1194,40 @@ protected function css_split($filescontent = '') $cachefiledata = $this->booster_cachedir.'/'.$identifier.'_splitdata_'.$cachefilesuffix.'_cache.txt'; // For library debugging purposes we log file contents - if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split input content:\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); + if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split input content (part ".$this->css_part."):\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); if(file_exists($cachefilecontent) && file_exists($cachefiledata)) { $filescontent = file_get_contents($cachefilecontent); $line_infos = unserialize(file_get_contents($cachefiledata)); + + // For library debugging purposes we log file contents + if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split data files found (part ".$this->css_part."):\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); } else { + // Backup any values within single or double quotes + preg_match_all('/(\'[^\']*?\'|"[^"]*?")/ims',$filescontent,$treffer,PREG_PATTERN_ORDER); + for($i=0;$ilibrarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split prepared content (part ".$this->css_part."):\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); + // In order for @-rule-blocks like @media-blocks, but also @font-face not to get stupidly ripped apart // while splitting the file into multiple parts, we need to parse it take some notes for us later. @@ -1230,6 +1276,9 @@ protected function css_split($filescontent = '') // Remember that we are inside some /*-comment $comment_on = 1; $currentcomment = 'comment'; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"* comment start (part ".$this->css_part."): ".$currentcomment."\r\n",FILE_APPEND); } elseif(preg_match('/\A([a-zA-Z\.#\*:][^\{\}@;\/]+)\{/ims', substr($filescontent,$i), $treffer) == 1) { @@ -1242,6 +1291,9 @@ protected function css_split($filescontent = '') // Remember that we are inside some selector's properties $property_on = 1; $i--; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"} selector start (part ".$this->css_part."): ".$currentselector." -> ".$line_infos[$currentline]['selector']."\r\n",FILE_APPEND); } } @@ -1254,21 +1306,41 @@ protected function css_split($filescontent = '') // Remember that we finished being inside some comment $comment_on = 0; $currentcomment = ''; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"/ comment end (part ".$this->css_part."): ".$currentcomment."\r\n",FILE_APPEND); } break; // Newline case "\n": + if(!isset($line_infos[$currentline])) $line_infos[$currentline] = array(); + // If not yet done: store @-rule for this line if(!isset($line_infos[$currentline]['block'])) $line_infos[$currentline]['block'] = $currentblock; // Store type of comment for this line $line_infos[$currentline]['comment'] = $currentcomment; // Store selector for this line if(!isset($line_infos[$currentline]['selector'])) $line_infos[$currentline]['selector'] = $currentselector; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"-----------------\r\n + newline (part ".$this->css_part."):\r\n + currentline: ".$currentline."\r\n + currentblock: ".$currentblock."\r\n + block: ".$line_infos[$currentline]['block']."\r\n + currentcomment: ".$currentcomment."\r\n + comment: ".$line_infos[$currentline]['comment']."\r\n + currentselector: ".$currentselector."\r\n + selector: ".$line_infos[$currentline]['selector']."\r\n + -----------------\r\n",FILE_APPEND); + $currentline++; + if(!isset($line_infos[$currentline])) $line_infos[$currentline] = array(); + break; - // That what we are here for: is this a block-creating @-rule like @media{} or @font-face{}? + // That's what we are here for: is this a block-creating @-rule like @media{} or @font-face{}? case "@": if($singlequote_on == 0 && $doublequote_on == 0 && $comment_on == 0) { @@ -1281,6 +1353,9 @@ protected function css_split($filescontent = '') // store @-rule for this line $line_infos[$currentline]['block'] = $currentblock; $i--; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"@ block start (part ".$this->css_part."): ".$currentblock." -> ".$line_infos[$currentline]['block']."\r\n",FILE_APPEND); } } break; @@ -1300,6 +1375,9 @@ protected function css_split($filescontent = '') // Remove closing parenthesis for now (we will put it back in later) $filescontent = substr_replace($filescontent,'',$i,1); $i--; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"} selector end (part ".$this->css_part."): ".$currentselector." -> ".$line_infos[$currentline]['selector']."\r\n",FILE_APPEND); } // Or else it must be a closing parenthesis of an @-rule else @@ -1311,6 +1389,9 @@ protected function css_split($filescontent = '') // Remove closing parenthesis for now (we will put it back in later) $filescontent = substr_replace($filescontent,'',$i,1); $i--; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log," } block end (part ".$this->css_part."): ".$currentblock." -> ".$line_infos[$currentline]['block']."\r\n",FILE_APPEND); } } break; @@ -1329,6 +1410,9 @@ protected function css_split($filescontent = '') // Remember that we are inside some selector's properties $property_on = 1; $i--; + + // For library debugging purposes we log pre-parser structure findings + if($this->librarydebug && $this->css_part == 1) file_put_contents($this->debug_log,"\A([a-zA-Z\.#\*:][^\{\}@;\/]+)\{ selector start (part ".$this->css_part."): ".$currentselector." -> ".$line_infos[$currentline]['selector']."\r\n",FILE_APPEND); } } break; @@ -1338,15 +1422,15 @@ protected function css_split($filescontent = '') $line_infos[$currentline] = array('block'=>$currentblock,'comment'=>$currentcomment,'selector'=>$currentselector); // Store in cache files - file_put_contents($cachefilecontent,$filescontent); - file_put_contents($cachefiledata,serialize($line_infos)); + if(!file_exists($cachefilecontent)) file_put_contents($cachefilecontent,$filescontent); + if(!file_exists($cachefiledata)) file_put_contents($cachefiledata,serialize($line_infos)); } - // For library debugging purposes we log file contents - if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split output content:\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); - // For library debugging purposes we log pre-parser structure findings - if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split pre-parser structure findings:\r\n".var_export($line_infos, TRUE)."\r\n-----------------\r\n",FILE_APPEND); + if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." (part ".$this->css_part."):\r\n".var_export($line_infos, TRUE)."\r\n-----------------\r\n",FILE_APPEND); + + // For library debugging purposes we log file contents + if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split output content (part ".$this->css_part."):\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); // Finished with out pre-parsing, beginning split process /////////////////////////////////////////////////// @@ -1384,7 +1468,7 @@ protected function css_split($filescontent = '') // If a comment begins if($j > 0 && $line_infos[$i]['comment'] != '' && $currentcomment == '') { - $filescontentparts[$j] .= '/*'; + if($i == 0) $filescontentparts[$j] .= '/*'; $currentcomment = $line_infos[$i]['comment']; } // If at this place an @-rule-status should start or stop (=changes) @@ -1460,7 +1544,7 @@ protected function css_split($filescontent = '') } } // For library debugging purposes we log file contents - if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split result for part ".($j + 1).":\r\n".$filescontentparts[$this->css_part - 1]."\r\n-----------------\r\n",FILE_APPEND); + if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split result for part (part ".$this->css_part."):\r\n".$filescontentparts[$this->css_part - 1]."\r\n-----------------\r\n",FILE_APPEND); // Return only the requested part return $filescontentparts[$this->css_part - 1]; @@ -1508,14 +1592,25 @@ public function css() ) $cachefile = $this->booster_cachedir.'/'.$identifier.'_datauri_off_'.(($this->debug) ? 'debug_' : '').'cache.txt'; // If any other and (then we assume) data-URI-compatible browser else $cachefile = $this->booster_cachedir.'/'.$identifier.'_datauri_'.(($this->debug) ? 'debug_' : '').'cache.txt'; - + // Interim cache file + $interim_cachefile = str_replace('.txt','.working.txt',$cachefile); // If that cache-file is there, fetch its contents if( file_exists($cachefile) && filemtime($cachefile) >= $this->filestime && filemtime($cachefile) >= filemtime(str_replace('\\','/',dirname(__FILE__))) - ) $filescontent .= file_get_contents($cachefile); + ) + { + $filescontent .= file_get_contents($cachefile)."\n"; + // Split results up in order to have multiple parts load in parallel and get the currently requested part back + $filescontent = $this->css_split($filescontent); + } + // Check for interim file existance, and if it is no older than 2 minutes + elseif(file_exists($interim_cachefile) && filemtime($interim_cachefile) > ($_SERVER['REQUEST_TIME'] - 120)) + { + $filescontent .= file_get_contents($interim_cachefile)."\n"; + } // if that cache-file does not exist or is too old, create it else { @@ -1540,6 +1635,8 @@ public function css() closedir($handle); } + // In order to deflect other concurrent clients' requests for this file while it being compiled + // we first create a non-optimized cache-file to serve it to them during compile time. reset($sources); for($i=0;$idebug) $currentfilescontent = $this->css_minify($currentfilescontent); - // Prepare @var $dir that we need to prepend as path to any images we find to get the full path // if @var $css_source is a folder if(is_dir($source)) $dir = $source; @@ -1563,6 +1657,40 @@ public function css() elseif(is_file($source)) $dir = dirname($source); // if @var $css_source is code-string else $dir = rtrim($this->getpath(dirname($_SERVER['SCRIPT_FILENAME']).'/'.$this->css_stringbase,str_replace('\\','/',dirname(__FILE__))),'/'); + + $filescontent .= $this->css_datauri_cleanup($currentfilescontent,$dir); + } + next($sources); + } + // Write interim cachefile + file_put_contents($interim_cachefile,$filescontent); + @chmod($interim_cachefile,0777); + + + // Now we create the optimized version + $filescontent = ''; + reset($sources); + for($i=0;$igetfilescontents($source,$type,$this->css_recursive); + // If current source is already a string + else $currentfilescontent = $source; + + // Prepare @var $dir that we need to prepend as path to any images we find to get the full path + // if @var $css_source is a folder + if(is_dir($source)) $dir = $source; + // if @var $css_source is a file + elseif(is_file($source)) $dir = dirname($source); + // if @var $css_source is code-string + else $dir = rtrim($this->getpath(dirname($_SERVER['SCRIPT_FILENAME']).'/'.$this->css_stringbase,str_replace('\\','/',dirname(__FILE__))),'/'); + + // Embed media to save HTTP-requests $filescontent .= $this->css_datauri($currentfilescontent,$dir); } @@ -1571,11 +1699,13 @@ public function css() // Write cache-file file_put_contents($cachefile,$filescontent); @chmod($cachefile,0777); + + // Delete interim cache-file + if(file_exists($interim_cachefile)) @unlink($interim_cachefile); + + // Split results up in order to have multiple parts load in parallel and get the currently requested part back + $filescontent = $this->css_split($filescontent."\n"); } - $filescontent .= "\n"; - - // Split results up in order to have multiple parts load in parallel and get the currently requested part back - $filescontent = $this->css_split($filescontent); // Return the currently requested part of the stylesheets return $filescontent; @@ -1625,7 +1755,7 @@ public function css_markup() $markup = ''; // Calculate absolute path for booster-folder - $booster_path = '/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$_SERVER['DOCUMENT_ROOT'])); + $booster_path = '/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$this->document_root)); // Calculate relative path from booster-folder to calling script #Schepp $css_path = $this->getpath(dirname($_SERVER['SCRIPT_FILENAME']),str_replace('\\','/',dirname(__FILE__))); @@ -1668,7 +1798,7 @@ public function css_markup() $markup .= 'markuptype == 'XHTML' ? '/' : '').'>'."\r\n"; } + + // If there are errors, output them + if($this->errormessage != '') + { + $this->errormessage = trim($this->errormessage,"\r\n"); + $markup .= ''."\r\n"; + } return $markup; } @@ -1740,7 +1877,7 @@ protected function js_minify($filescontent = '') $js_minified .= fgets($fp); } fclose($fp); - $js_minified = preg_replace('/^HTTP.+[\r\n]{2}/ims','',$js_minified); + $js_minified = "/* Minified by Google Closure Webservice */\r\ntry{\r\n".preg_replace('/^HTTP.+[\r\n]{2}/ims','',$js_minified)."\r\nvar boostererror = null;\r\n} catch(e) {}"; } } // Switching over to Douglas Crockford's JSMin (which in turn breaks IE's conditional compilation) @@ -1750,7 +1887,7 @@ protected function js_minify($filescontent = '') * Inclusion of JSMin */ include_once('jsmin/jsmin.php'); - $js_minified = JSMin::minify($filescontent); + $js_minified = "/* Minified by JSMin */\r\ntry{\r\n".JSMin::minify($filescontent)."\r\nvar boostererror = null;\r\n} catch(e) {}"; } } @@ -1793,13 +1930,23 @@ public function js() // Defining the cache-filename $cachefile = $this->booster_cachedir.'/'.$identifier.'_js_'.(($this->debug) ? 'debug_' : '').'cache.txt'; + // Interim cache file + $interim_cachefile = str_replace('.txt','.working.txt',$cachefile); // If cache-file exists and cache-file date is newer than code-date, read from there if( file_exists($cachefile) && filemtime($cachefile) >= $this->filestime && filemtime($cachefile) >= filemtime(str_replace('\\','/',dirname(__FILE__))) - ) $filescontent .= file_get_contents($cachefile); + ) + { + $filescontent .= file_get_contents($cachefile); + } + // Check for interim file existance, and if it is no older than 2 minutes + elseif(file_exists($interim_cachefile) && filemtime($interim_cachefile) > ($_SERVER['REQUEST_TIME'] - 120)) + { + $filescontent .= file_get_contents($interim_cachefile); + } // There is no cache-file or it is outdated, create it else { @@ -1817,6 +1964,11 @@ public function js() next($sources); } + + // In order to deflect other concurrent clients' requests for this file while it being compiled + // we first create a non-optimized cache-file to serve it to them during compile time. + file_put_contents($interim_cachefile,$filescontent); + @chmod($interim_cachefile,0777); // Check for document.write inside JS. If found disable any lazy-loadings. if(strpos($filescontent,'document.write')) @@ -1830,6 +1982,9 @@ public function js() // Write cache-file file_put_contents($cachefile,$filescontent); @chmod($cachefile,0777); + + // Delete interim cache-file + if(file_exists($interim_cachefile)) @unlink($interim_cachefile); } $filescontent .= "\n"; @@ -1852,7 +2007,7 @@ public function js_markup() $markup = ''; // Calculate absolute path for booster-folder - $booster_path = '/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$_SERVER['DOCUMENT_ROOT'])); + $booster_path = '/'.$this->getpath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$this->document_root)); // If sources were defined as array if(is_array($this->js_source)) $sources = $this->js_source; @@ -1882,6 +2037,13 @@ public function js_markup() // Populate $this->filestime with newest file's timestamp $this->getfilestime($source,'js'); + // If there are errors, output them + if($this->errormessage != '') + { + $this->errormessage = trim($this->errormessage,"\r\n"); + $markup .= ''."\r\n"; + } + // Put together the markup linking to our booster-js-files // Append timestamps of the $timestamp_dir to make sure browser reloads once the JS was updated $markup .= ''."\r\n"; + + if($this->js_minify && $this->js_executionmode == '') $markup .= ''."\r\n"; return $markup; } From 268ab40032dba3d83936c0a6b48aac4639ffbf9e Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Wed, 11 Aug 2010 16:44:19 +0800 Subject: [PATCH 09/13] Fixing bugs introduced by 1.6.0's major changes Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 67a4008..72acee0 100755 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -454,7 +454,6 @@ public function __construct() $this->js_stringtime = filemtime(realpath($_SERVER['SCRIPT_FILENAME'])); $this->js_hosted_minifier_path = realpath(dirname(__FILE__).'/'.$this->js_hosted_minifier_path); $this->browser = new browser(); - $this->errorcheck(); } /** @@ -481,9 +480,9 @@ private function errorcheck() $this->errormessage = "\r\n".'$_SERVER[\'DOCUMENT_ROOT\'] variable is set to '.$_SERVER['DOCUMENT_ROOT'].'. But you seem to have a differing real document root. Please set the variable $booster->document_root to reflect your real document root'."\r\n"; } // Check for incorrect base path (e.g. due to Apache's mod_userdir) - if($this->base_offset.str_replace($this->document_root,'',$_SERVER['SCRIPT_FILENAME']) != parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH)) + if($this->base_offset.ltrim(str_replace($this->document_root,'',$_SERVER['SCRIPT_FILENAME']),'/') != parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH)) { - $this->errormessage = "\r\n".'$booster->base_offset variable is set to '.$this->base_offset.'. But this server\'s document root seems to be differently offsetted. Please set the variable $booster->base_offset to reflect this offset'."\r\n".$this->base_offset.str_replace($this->document_root,'',$_SERVER['SCRIPT_FILENAME'])."\r\n".parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH)."\r\n"; + $this->errormessage = "\r\n".'$booster->base_offset variable is set to '.$this->base_offset.'. But this server\'s document root seems to be differently offsetted. Please set the variable $booster->base_offset to reflect this offset'."\r\n".$this->base_offset.ltrim(str_replace($this->document_root,'',$_SERVER['SCRIPT_FILENAME']),'/')."\r\n".parse_url($_SERVER['SCRIPT_NAME'],PHP_URL_PATH)."\r\n"; } } @@ -1174,6 +1173,8 @@ protected function css_split($filescontent = '') // For library debugging purposes we log file contents if($this->librarydebug) file_put_contents($this->debug_log,"-----------------\r\n".date("d.m.Y H:i:s")." css_split input content (solo part ".$this->css_part."):\r\n-----------------\r\n".$filescontent."\r\n-----------------\r\n",FILE_APPEND); + + return $filescontent; } // Else process string else @@ -1745,6 +1746,9 @@ public function mhtml() */ public function css_markup() { + // Check for configuration errors + $this->errorcheck(); + // Preparing call $this->debug_log = str_replace('\\','/',dirname(__FILE__)).'/'.$this->booster_cachedir.'/debug_log.txt'; @@ -2000,6 +2004,9 @@ public function js() */ public function js_markup() { + // Check for configuration errors + $this->errorcheck(); + // Preparing call $this->debug_log = str_replace('\\','/',dirname(__FILE__)).'/'.$this->booster_cachedir.'/debug_log.txt'; @@ -2041,7 +2048,7 @@ public function js_markup() if($this->errormessage != '') { $this->errormessage = trim($this->errormessage,"\r\n"); - $markup .= ''."\r\n"; + $markup .= ''."\r\n"; } // Put together the markup linking to our booster-js-files @@ -2065,7 +2072,7 @@ public function js_markup() (!$this->js_minify ? '&js_minify=0' : ''). '&nocache='.$this->filestime.'">'."\r\n"; - if($this->js_minify && $this->js_executionmode == '') $markup .= ''."\r\n"; + if($this->js_minify && $this->js_executionmode == '') $markup .= ''."\r\n"; return $markup; } From 20a744c569edc1bf780c417a7fc9323bb29f9c9d Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Wed, 11 Aug 2010 18:58:19 +0800 Subject: [PATCH 10/13] Another path fix from changes in 1.6.0 Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 72acee0..4ba869d 100755 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -464,6 +464,8 @@ public function __construct() */ private function errorcheck() { + $this->setcachedir(); + // Throw a warning and quit if cache-directory doesn't exist or isn't writable if(!@is_dir($this->booster_cachedir) && !@mkdir($this->booster_cachedir,0777)) { @@ -505,9 +507,9 @@ public function setcachedir() // Check if @var $booster_cachedir_transformed is still "FALSE" if(!$this->booster_cachedir_transformed) { + $this->booster_cachedir_transformed = TRUE; $this->booster_cachedir = str_replace('\\','/',dirname(__FILE__)).'/'.$this->booster_cachedir; $this->debug_log = $this->booster_cachedir.'/debug_log.txt'; - $this->booster_cachedir_transformed = TRUE; // Automatic cleanup of old files in booster_cache folder, if switched on, and only on sundays $today = getdate(); From b91b8fb27fc9474a4dfd9128fcc1afabfada0f87 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Wed, 11 Aug 2010 21:54:19 +0800 Subject: [PATCH 11/13] Another path fix from changes in 1.6.0 Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 4ba869d..00226c6 100755 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -464,12 +464,13 @@ public function __construct() */ private function errorcheck() { - $this->setcachedir(); + // Calculate absolute path only for this function + $booster_cachedir = str_replace('\\','/',dirname(__FILE__)).'/'.$this->booster_cachedir; // Throw a warning and quit if cache-directory doesn't exist or isn't writable - if(!@is_dir($this->booster_cachedir) && !@mkdir($this->booster_cachedir,0777)) + if(!@is_dir($booster_cachedir) && !@mkdir($booster_cachedir,0777)) { - $this->errormessage = "\r\nYou need to create a directory \r\n".$this->get_absolute_path($this->booster_cachedir)."\r\n with CHMOD 0777 rights.\r\nAfterwards, delete your browser's cache and reload.\r\n"; + $this->errormessage = "\r\nYou need to create a directory \r\n".$this->get_absolute_path($booster_cachedir)."\r\n with CHMOD 0777 rights.\r\nAfterwards, delete your browser's cache and reload.\r\n"; } // Also check here for the right PHP version if(strnatcmp(phpversion(),'5.0.0') < 0) @@ -1693,6 +1694,8 @@ public function css() // if @var $css_source is code-string else $dir = rtrim($this->getpath(dirname($_SERVER['SCRIPT_FILENAME']).'/'.$this->css_stringbase,str_replace('\\','/',dirname(__FILE__))),'/'); + // Optimize stylesheets with CSS Minify + if(!$this->debug) $currentfilescontent = $this->css_minify($currentfilescontent); // Embed media to save HTTP-requests $filescontent .= $this->css_datauri($currentfilescontent,$dir); From b9b5b00a1fb3b855c01e74e3456b8223e6ddfaf8 Mon Sep 17 00:00:00 2001 From: Christian Schepp Schaefer Date: Wed, 18 Aug 2010 22:53:50 +0800 Subject: [PATCH 12/13] Added detection for mod_rewrite and a "plan B" if it is not available. Signed-off-by: Christian Schepp Schaefer --- booster/booster_inc.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 00226c6..41871fe 100755 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -167,6 +167,14 @@ class Booster { */ private $errormessage = ''; + /** + * Variable in which we store if mod_rewrite is active + * + * @var bool + * @access private + */ + private $mod_rewrite = FALSE; + // CSS specific configuration /////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -454,6 +462,12 @@ public function __construct() $this->js_stringtime = filemtime(realpath($_SERVER['SCRIPT_FILENAME'])); $this->js_hosted_minifier_path = realpath(dirname(__FILE__).'/'.$this->js_hosted_minifier_path); $this->browser = new browser(); + + // Checking if Apache runs with mod_rewrite + ob_clean(); + phpinfo(INFO_MODULES); + $result = ob_get_clean(); + if(stristr($result,'mod_rewrite')) $this->mod_rewrite = TRUE; } /** @@ -1807,7 +1821,10 @@ public function css_markup() $markup .= 'base_offset.ltrim($booster_path,'/').'/booster_js.php/dir='.htmlentities(str_replace('..','%3E',$source),ENT_QUOTES). + $markup .= ' src="'.$this->base_offset.ltrim($booster_path,'/').'/booster_js.php'. + ($this->mod_rewrite ? '/' : '?'). + 'dir='.htmlentities(str_replace('..','%3E',$source),ENT_QUOTES). '&cachedir='.htmlentities(str_replace('..','%3E',$this->booster_cachedir),ENT_QUOTES). ($this->js_hosted_minifier ? '&js_hosted_minifier=1' : ''). ($this->debug ? '&debug=1' : ''). From e29996f3882aa3bacdcb453bbc3d6b44e3c46982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Kr=C3=B6ner?= Date: Sun, 5 Sep 2010 23:39:40 +0200 Subject: [PATCH 13/13] Throw exceptions instead of using alert. Throw is obvious enough for developers and normal users don't need to be notified about some library breaking scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Kröner --- booster/booster_inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/booster/booster_inc.php b/booster/booster_inc.php index 41871fe..2b35865 100755 --- a/booster/booster_inc.php +++ b/booster/booster_inc.php @@ -2070,7 +2070,7 @@ public function js_markup() if($this->errormessage != '') { $this->errormessage = trim($this->errormessage,"\r\n"); - $markup .= ''."\r\n"; + $markup .= ''."\r\n"; } // Put together the markup linking to our booster-js-files @@ -2096,7 +2096,7 @@ public function js_markup() (!$this->js_minify ? '&js_minify=0' : ''). '&nocache='.$this->filestime.'">'."\r\n"; - if($this->js_minify && $this->js_executionmode == '') $markup .= ''."\r\n"; + if($this->js_minify && $this->js_executionmode == '') $markup .= ''."\r\n"; return $markup; }