Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Hello! #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
NOTE: I'm not going to update this file any more. Use git-log instead.

-------------------- 1.7 beta [2008-12-06] ---------------------
2008-12-16 Ali Farhadi <[email protected]>
* ability to ignore some file types (e.g. htc) from being embedded through embedExceptions config.
2008-12-06 Ali Farhadi <[email protected]>
* minifiers/css.php: Issue #2 fixed (problem with mime_content_type function).
* config.php: gzip compression level can be set in config file.
* index.php: Content-Type of js files was changed for compatibility with all of browsers. (from application/x-javascript to text/javascript).
-------------------- 1.6 beta [2008-06-13] ---------------------
2008-06-13 Ali Farhadi <[email protected]>
Change log and brief documentation added.
* minifiers/css.php, index.php: Ability of embedding css images and css imported files was added.
* minifiers/css.php: Duplicated urls (i.e. css sprites) will not be embeded for better performance.
* config.php: embed feature can be disabled in config file.
* config.php: Maximum file size of embedded files can be specified.
* .htaccess: bug fixed in removing Etag headers for static contents.
-------------------- 1.5 beta [2008-05-24] ---------------------
2008-05-24 Ali Farhadi <[email protected]>
The project renamed to SmartOptimizer.
SmartOptimizer is a completely rewritten and restructured version of JSmart.
* index.php: Ability of concatenating js and css files was added.
* minifiers/css.php: Relative paths in css files will be corrected if needed.
* config.php: Cache settings is more customizable.
* config.php: Ability of disabling minification and gzip compression was added.
* index.php: Handling expire headers for a wide range of file types was added.
* index.php: getallheaders function is not used anymore, since it is not supported in all the servers.
-------------------- 1.0 Final Release [2006-07-07] ---------------------
2006-07-07 Ali Farhadi <[email protected]>
* load.php: Ability of compressing CSS files was added.
* load.php: Content-Type of js files was corrected. (from text/plain to application/x-javascript)
-------------------- 1.0 RC2 [2006-07-01] ---------------------
2006-07-01 Ali Farhadi <[email protected]>
* config.php: Charset of js files can be specified in config file.
* load.php: Debugging capabilities was added.
* config.php: Debug mode can be enabled or disabled using config file.
* config.php: Cache feature can be disabled in config file
-------------------- 1.0 RC [2006-06-29] ---------------------
2006-06-29 Ali Farhadi <[email protected]>
* config.php: JSmart is more customizable using config.php
* load.php: JSmart will not crash if zlib extension is not installed.
-------------------- 1.0 beta [2006-06-25] ---------------------
2006-06-25 Ali Farhadi <[email protected]>
It is the first release
2008-12-16 Ali Farhadi <[email protected]>
* ability to ignore some file types (e.g. htc) from being embedded through embedExceptions config.
2008-12-06 Ali Farhadi <[email protected]>
* minifiers/css.php: Issue #2 fixed (problem with mime_content_type function).
* config.php: gzip compression level can be set in config file.
* index.php: Content-Type of js files was changed for compatibility with all of browsers. (from application/x-javascript to text/javascript).

-------------------- 1.6 beta [2008-06-13] ---------------------
2008-06-13 Ali Farhadi <[email protected]>
Change log and brief documentation added.
* minifiers/css.php, index.php: Ability of embedding css images and css imported files was added.
* minifiers/css.php: Duplicated urls (i.e. css sprites) will not be embeded for better performance.
* config.php: embed feature can be disabled in config file.
* config.php: Maximum file size of embedded files can be specified.
* .htaccess: bug fixed in removing Etag headers for static contents.

-------------------- 1.5 beta [2008-05-24] ---------------------
2008-05-24 Ali Farhadi <[email protected]>
The project renamed to SmartOptimizer.
SmartOptimizer is a completely rewritten and restructured version of JSmart.
* index.php: Ability of concatenating js and css files was added.
* minifiers/css.php: Relative paths in css files will be corrected if needed.
* config.php: Cache settings is more customizable.
* config.php: Ability of disabling minification and gzip compression was added.
* index.php: Handling expire headers for a wide range of file types was added.
* index.php: getallheaders function is not used anymore, since it is not supported in all the servers.

-------------------- 1.0 Final Release [2006-07-07] ---------------------
2006-07-07 Ali Farhadi <[email protected]>
* load.php: Ability of compressing CSS files was added.
* load.php: Content-Type of js files was corrected. (from text/plain to application/x-javascript)

-------------------- 1.0 RC2 [2006-07-01] ---------------------
2006-07-01 Ali Farhadi <[email protected]>
* config.php: Charset of js files can be specified in config file.
* load.php: Debugging capabilities was added.
* config.php: Debug mode can be enabled or disabled using config file.
* config.php: Cache feature can be disabled in config file

-------------------- 1.0 RC [2006-06-29] ---------------------
2006-06-29 Ali Farhadi <[email protected]>
* config.php: JSmart is more customizable using config.php
* load.php: JSmart will not crash if zlib extension is not installed.

-------------------- 1.0 beta [2006-06-25] ---------------------
2006-06-25 Ali Farhadi <[email protected]>
It is the first release
23 changes: 19 additions & 4 deletions smartoptimizer/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* SmartOptimizer Configuration File
*/


//base dir (a relative path to the base directory)
$settings['baseDir'] = '../';
$settings['baseDir'] = '';

//Encoding of your js and css files. (utf-8 or iso-8859-1)
$settings['charSet'] = 'utf-8';
Expand All @@ -28,7 +27,7 @@
//use this to set file concatenation On or Off
$settings['concatenate'] = true;

//separator for files to be concatenated
//separator for files to be concatenated. Tip: Don't use '.' if you use groups and name them like suggested.
$settings['separator'] = ',';

//specifies whether to emebed files included in css files using the data URI scheme or not
Expand Down Expand Up @@ -57,4 +56,20 @@

//Setting this to false will force the browser to use cached files without checking for changes.
$settings['clientCacheCheck'] = false;
?>

//Minifier to use when parsing js files. Add yours in /minifiers directory, and implement function minify_js($text_to_minify)
$settings['jsMinifier'] = 'packer';

//Minifier to use when parsing css files. Add yours in /minifiers directory, and implement function minify_css($text_to_minify)
$settings['cssMinifier'] = 'css';

//To use groups effectively, include your files with absolute paths. Define constants for easy access.
define('MY_JS_DIR', $_SERVER['DOCUMENT_ROOT'] . '/tkitt/js/');
define('MY_CSS_DIR', $_SERVER['DOCUMENT_ROOT'] . '/tkitt/css/');

//groups configuration. Call a group by using /path/to/smartoptimizer/?group.group_name.
//Tip: If you use 'test.js' as your group name, you'll get a nifty file name like 'group.test.js'
$settings['groups'] = array(
'test.js' => array(MY_JS_DIR.'test.js', MY_JS_DIR.'test2.js'),
'test.css' => array(MY_JS_DIR.'style.css', MY_JS_DIR.'print.css')
);
39 changes: 29 additions & 10 deletions smartoptimizer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'cachePrefix' => 'so_',
'clientCache' => true,
'clientCacheCheck' => false,
'jsMinifier' => 'js',
'cssMinifier' => 'css'
);

//mime types
Expand Down Expand Up @@ -98,10 +100,10 @@ function gmdatestr($time = null) {
}

function filesmtime() {
global $files, $fileType;
global $files, $fileMinifier;
static $filesmtime;
if ($filesmtime) return $filesmtime;
$filesmtime = max(@filemtime("minifiers/$fileType.php"), filemtime('index.php'), filemtime('config.php'));
$filesmtime = max(@filemtime("minifiers/$fileMinifier.php"), filemtime('index.php'), filemtime('config.php'));
foreach ($files as $file) {
if (!file_exists($file)) debugExit("File not found ($file).");
$filesmtime = max(filemtime($file), $filesmtime);
Expand All @@ -113,15 +115,30 @@ function filesmtime() {

list($query) = explode('?', urldecode($_SERVER['QUERY_STRING']));

if (preg_match('/^\/?(.+\/)?(.+)$/', $query, $matchResult)) {
$fileNames = $matchResult[2];
$fileDir = $settings['baseDir'].$matchResult[1];
} else debugExit("Invalid file name ($query)");
if(isset($settings['groups']) && substr($query, 0, 6) == 'group.'){
//we have a pre-defined group to include
$group_name = str_replace('group.','',$query);
if(isset($settings['groups'][$group_name])) {
$fileNames = $settings['groups'][$group_name];
$fileDir = '';
}
else debugExit("Group ($group_name) not set. Please edit config.");
} else {
if (preg_match('/^\/?(.+\/)?(.+)$/', $query, $matchResult)) {
$fileNames = $matchResult[2];
$fileDir = $settings['baseDir'].$matchResult[1];
} else debugExit("Invalid file name ($query)");
}

if (strpos(realpath($fileDir), realpath($settings['baseDir'])) !== 0) debugExit("File is out of base directory.");
//if (strpos(realpath($fileDir), realpath($settings['baseDir'])) !== 0) debugExit("File is out of base directory.");

if ($settings['concatenate']) {
$files = explode($settings['separator'], $fileNames);
if(!is_array($fileNames)){
$files = explode($settings['separator'], $fileNames);
}
else{
$files = $fileNames;
}
$settings['concatenate'] = count($files) > 1;
} else $files = array($fileNames);

Expand All @@ -138,6 +155,8 @@ function filesmtime() {
}

$fileType = $fileTypes[0];
$fileMinifier = $settings[$fileType.'Minifier'];
if(!file_exists('minifiers/'.$fileMinifier.'.php')) debugExit($fileType.'Minifier not found. Please create "minifiers/'.$fileMinifier.'.php" or change minifier in config.php');

if (!isset($mimeTypes[$fileType])) debugExit("Unsupported file type ($fileType)");
header("Content-Type: {$mimeTypes[$fileType]}; charset=".$settings['charSet']);
Expand All @@ -150,7 +169,7 @@ function_exists('gzencode'));

if ($settings['gzip']) header("Content-Encoding: gzip");

$settings['minify'] = $settings['minify'] && file_exists('minifiers/'.$fileType.'.php');
$settings['minify'] = $settings['minify'] && file_exists('minifiers/'.$fileMinifier.'.php');
$settings['embed'] = $settings['embed'] && $fileType == 'css' && (!preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT']) || preg_match('/msie 8|opera/i', $_SERVER['HTTP_USER_AGENT']));
$settings['serverCache'] = $settings['serverCache'] && ($settings['minify'] || $settings['gzip'] || $settings['concatenate'] || $settings['embed']);

Expand All @@ -177,7 +196,7 @@ function_exists('gzencode'));
} else headerNoCache();

if ($generateContent) {
if ($settings['minify']) include('minifiers/'.$fileType.'.php');
if ($settings['minify']) include('minifiers/'.$fileMinifier.'.php');
$content = array();
foreach ($files as $file) (($content[] = @file_get_contents($file)) !== false) || debugExit("File not found ($file).");
$content = implode("\n", $content);
Expand Down
Loading