diff --git a/README.markdown b/README.markdown index c096a02..8a48032 100644 --- a/README.markdown +++ b/README.markdown @@ -324,6 +324,19 @@ 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( + 'http://static.yourdowmain.com' => '/var/www/static', + 'anotherstaticpath' => 'anotherfilesystemdir' + ) + ) + ); + Building sacy ------------- @@ -610,4 +623,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 :-) 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