From 3b1a57a5c3c14b09a88adacb5c44bc82b6f4c0b1 Mon Sep 17 00:00:00 2001 From: Gerhard Alfanz Date: Tue, 12 Mar 2013 14:41:01 +0100 Subject: [PATCH 1/4] Added URL - filessystem mapping option to sacy; this means that sacy will translate these urls into filesystem paths, which then can be minified --- src/sacy/sacy.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/sacy/sacy.php b/src/sacy/sacy.php index 6a88f15..9befbb1 100644 --- a/src/sacy/sacy.php +++ b/src/sacy/sacy.php @@ -95,6 +95,17 @@ private function extract_attrs($attstr){ private function urlToFile($ref){ $u = parse_url($ref); if ($u === false) return false; + + // Let's check if there is a local path mapped to to the requested host. + // If so simulate a local path + if (isset($u['host']) && isset($u['scheme']) + && array_key_exists($u['scheme'] . '://' . $u['host'], $this->_cfg->get('url_fs_mappings')) + ) { + $mapping = $this->_cfg->get('url_fs_mappings'); + $u['path'] = $mapping[$u['scheme'] . '://' . $u['host']] . '/' . $u['path']; + unset($u['host'], $u['scheme']); + } + if (isset($u['host']) || isset($u['scheme'])) return false; @@ -111,6 +122,8 @@ private function urlToFile($ref){ } + + private function extract_style_unit($tag, $attrdata, $content){ $attrs = $this->extract_attrs($attrdata); $attrs['type'] = strtolower($attrs['type']); @@ -215,7 +228,7 @@ public function __construct($params = null){ $this->params['query_strings'] = defined('SACY_QUERY_STRINGS') ? SACY_QUERY_STRINGS : 'ignore'; $this->params['write_headers'] = defined('SACY_WRITE_HEADERS') ? SACY_WRITE_HEADERS : true; $this->params['debug_toggle'] = defined('SACY_DEBUG_TOGGLE') ? SACY_DEBUG_TOGGLE : '_sacy_debug'; - + $this->params['url_fs_mappings'] = defined('SACY_URL_FS_MAPPINGS') ? unserialize(SACY_URL_FS_MAPPINGS) : array(); if (is_array($params)) $this->setParams($params); } @@ -233,14 +246,15 @@ public function getDebugMode(){ public function setParams($params){ foreach($params as $key => $value){ - if (!in_array($key, array('query_strings', 'write_headers', 'debug_toggle'))) + if (!in_array($key, array('query_strings', 'write_headers', 'debug_toggle', 'url_fs_mappings'))) throw new Exception("Invalid option: $key"); } if (isset($params['query_strings']) && !in_array($params['query_strings'], array('force-handle', 'ignore'))) throw new Exception("Invalid setting for query_strings: ".$params['query_strings']); if (isset($params['write_headers']) && !in_array($params['write_headers'], array(true, false), true)) throw new Exception("Invalid setting for write_headers: ".$params['write_headers']); - + if (isset($params['url_fs_mappings']) && !is_array($params['url_fs_mappings'])) + throw new Exception("Invalid format for url_fs_mappings, must be an array"); $this->params = array_merge($this->params, $params); } @@ -618,4 +632,4 @@ function getOutput($work_unit){ )); } } -} +} \ No newline at end of file From 231f1dd7094cc81411f76abaff6a94ef6ae91f15 Mon Sep 17 00:00:00 2001 From: Gerhard Alfanz Date: Wed, 20 Mar 2013 12:51:40 +0100 Subject: [PATCH 2/4] Updated documentation with new feature --- README.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.markdown b/README.markdown index c096a02..e6bfff1 100644 --- a/README.markdown +++ b/README.markdown @@ -324,6 +324,17 @@ accessible and then using symlinks or a webserver level alias directory to make just that directory accessible to the outside. You do not want world-writable directories exposed more than what's absolutely needed. +'SACY_URL_FS_MAPPINGS' is an optional constant that you can define to tell Sacy where to find certain files on your +webserver that are included with a static path. Assuming you want to tell Sacy that all resources included from http://static.yourdomain.com are +located inside /var/www/static on your server, set a serialized associative array to this constant this way: + define( + 'SACY_URL_FS_MAPPINGS', serialize( + array( + 'static.yourdowmain.com' => '/var/www/static', + 'anotherstaticpath' => 'anotherfilesystemdir' + ) + ) + ); Building sacy ------------- From 28858721882949b6ee041f3e08c65467c86a84bf Mon Sep 17 00:00:00 2001 From: Gerhard Alfanz Date: Wed, 20 Mar 2013 12:57:28 +0100 Subject: [PATCH 3/4] Improved docs --- README.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index e6bfff1..e197f97 100644 --- a/README.markdown +++ b/README.markdown @@ -328,13 +328,13 @@ world-writable directories exposed more than what's absolutely needed. webserver that are included with a static path. Assuming you want to tell Sacy that all resources included from http://static.yourdomain.com are located inside /var/www/static on your server, set a serialized associative array to this constant this way: define( - 'SACY_URL_FS_MAPPINGS', serialize( - array( - 'static.yourdowmain.com' => '/var/www/static', - 'anotherstaticpath' => 'anotherfilesystemdir' - ) - ) - ); + 'SACY_URL_FS_MAPPINGS', serialize( + array( + 'http://static.yourdowmain.com' => '/var/www/static', + 'anotherstaticpath' => 'anotherfilesystemdir' + ) + ) + ); Building sacy ------------- @@ -621,4 +621,4 @@ licensed under the MIT License which is reprinted in the LICENSE file accompanying this distribution. If you find this useful, consider dropping me a line, or, -if you want, a patch :-) \ No newline at end of file +if you want, a patch :-) From 0ae4b68072ba44ee158399d0707446413877c795 Mon Sep 17 00:00:00 2001 From: Gerhard Alfanz Date: Wed, 20 Mar 2013 13:00:53 +0100 Subject: [PATCH 4/4] Improved docs --- README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index e197f97..8a48032 100644 --- a/README.markdown +++ b/README.markdown @@ -324,9 +324,10 @@ accessible and then using symlinks or a webserver level alias directory to make just that directory accessible to the outside. You do not want world-writable directories exposed more than what's absolutely needed. -'SACY_URL_FS_MAPPINGS' is an optional constant that you can define to tell Sacy where to find certain files on your +`SACY_URL_FS_MAPPINGS` is an optional constant that you can define to tell Sacy where to find certain files on your webserver that are included with a static path. Assuming you want to tell Sacy that all resources included from http://static.yourdomain.com are located inside /var/www/static on your server, set a serialized associative array to this constant this way: + define( 'SACY_URL_FS_MAPPINGS', serialize( array( @@ -336,6 +337,7 @@ located inside /var/www/static on your server, set a serialized associative arra ) ); + Building sacy -------------