Skip to content

Commit

Permalink
More docs and corrections for root-relative links.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-kubacki committed May 22, 2011
1 parent da32935 commit b19afff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cdn-linker-base.php
Expand Up @@ -5,6 +5,15 @@
Control flow is this (begin reading with ossdl_off_filter()):
ossdl_off_additional_directories <-- ossdl_off_filter --> ossdl_off_rewriter --> ossdl_off_exclude_match
As this plugin hooks into the PHP output buffer "ossdl_off_filter" cannot have any parameters (beyond the obvious one, that is.)
Therefore these global variables are used:
- $ossdl_off_blog_url String: the blog's URL ( get_option('siteurl') )
- $ossdl_off_cdn_url String: URL of the CDN domain
- $ossdl_off_include_dirs String: directories to include in static file matching, comma-delimited list
- $arr_of_excludes Array: strings which indicate that a given element should not be rewritten (i.e., ".php")
- $ossdl_off_rootrelative Boolean: if true, modifies root-relative links (default is false)
*/

/**
Expand All @@ -30,14 +39,14 @@ function ossdl_off_exclude_match($match, $excludes) {
* @return String the unmodified URI if it is not to be rewritten, otherwise a modified one pointing to CDN
*/
function ossdl_off_rewriter($match) {
global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes;
global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes, $ossdl_off_rootrelative;
if (ossdl_off_exclude_match($match[0], $arr_of_excludes)) {
return $match[0];
} else {
if (!$ossdl_off_rootrelative || strstr($match[0], $ossdl_off_blog_url)) {
return str_replace($ossdl_off_blog_url, $ossdl_off_cdn_url, $match[0]);
} else { // obviously $ossdl_off_rootrelative is true aand we got a root-relative link - else that case won't happen
return $ossdl_off_cdn_url . '/' . $match[0];
return $ossdl_off_cdn_url . $match[0];
}
}
}
Expand All @@ -64,7 +73,7 @@ function ossdl_off_additional_directories() {
* @return String modified HTML with replaced links - will be served by the HTTP server to the requester
*/
function ossdl_off_filter($content) {
global $ossdl_off_blog_url, $ossdl_off_cdn_url;
global $ossdl_off_blog_url, $ossdl_off_cdn_url, $ossdl_off_rootrelative;
if ($ossdl_off_blog_url == $ossdl_off_cdn_url) { // no rewrite needed
return $content;
} else {
Expand Down
7 changes: 7 additions & 0 deletions readme.txt
Expand Up @@ -79,6 +79,13 @@ Therefore, please send me at least one page with the plugin turned off and on, a

== Changelog ==

= 1.1.2 - on Github =
* Optionally rewrite "root-relative" links. (As suggested by Tony Stuck. Thanks!)

The plugin has been
* renamed to "CDN Linker" and
* moved to [Github](https://github.com/wmark/CDN-Linker).

= 1.1.1 =
* version bump due to Wordpress' plugin page having released the plugin prematurely

Expand Down

0 comments on commit b19afff

Please sign in to comment.