Skip to content
Snippets Groups Projects
Commit bb06e426 authored by Jeff Stieler's avatar Jeff Stieler
Browse files

Merge branch 'develop'

parents 2df78223 7107fa94
Branches
Tags
No related merge requests found
...@@ -15,13 +15,27 @@ class CDN_Rewrite { ...@@ -15,13 +15,27 @@ class CDN_Rewrite {
const OPTION_GENERAL = 'cdn_general'; const OPTION_GENERAL = 'cdn_general';
private $submenu_general; private $submenu_general;
private $cdn_root_url;
private $file_extensions; private $file_extensions;
private $css_file_extensions;
private $css_cdn_root_url;
private $js_file_extensions;
private $js_cdn_root_url;
private $blog_details; private $blog_details;
private $cdn_root_url;
public function __construct() { public function __construct() {
$this->file_extensions = $this->get_setting('file_extensions');
$this->cdn_root_url = untrailingslashit($this->get_setting('root_url')); $this->cdn_root_url = untrailingslashit($this->get_setting('root_url'));
$this->file_extensions = $this->get_setting('file_extensions');
$this->css_cdn_root_url = untrailingslashit($this->get_setting('css_root_url'));
$this->css_file_extensions = $this->get_setting('css_file_extensions');
$this->js_cdn_root_url = untrailingslashit($this->get_setting('js_root_url'));
$this->js_file_extensions = $this->get_setting('js_file_extensions');
} }
public function initialize() { public function initialize() {
...@@ -36,7 +50,8 @@ class CDN_Rewrite { ...@@ -36,7 +50,8 @@ class CDN_Rewrite {
} }
if('/' != $this->cdn_root_url) { if('/' != $this->cdn_root_url) {
add_action('template_redirect', array($this, 'start_buffer'), 1); $action = (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ? 'xmlrpc_call' : 'template_redirect';
add_action($action, array($this, 'start_buffer'), 1);
} }
} }
...@@ -50,7 +65,9 @@ class CDN_Rewrite { ...@@ -50,7 +65,9 @@ class CDN_Rewrite {
$settings = get_option(self::OPTION_GENERAL); $settings = get_option(self::OPTION_GENERAL);
if(!$settings || !is_array($settings)) { if(!$settings || !is_array($settings)) {
$settings = array( $settings = array(
'file_extensions' => 'bmp|bz2|css|gif|ico|gz|jpg|jpeg|js|mp3|pdf|png|rar|rtf|swf|tar|tgz|txt|wav|zip' 'file_extensions' => 'bmp|bz2|gif|ico|gz|jpg|jpeg|mp3|pdf|png|rar|rtf|swf|tar|tgz|txt|wav|zip',
'css_file_extensions' => 'css',
'js_file_extensions' => 'js'
); );
update_option(self::OPTION_GENERAL, $settings); update_option(self::OPTION_GENERAL, $settings);
} }
...@@ -73,6 +90,10 @@ class CDN_Rewrite { ...@@ -73,6 +90,10 @@ class CDN_Rewrite {
$section = $settings->add_section('api', 'CDN Rewrite Settings', $this->submenu_general); $section = $settings->add_section('api', 'CDN Rewrite Settings', $this->submenu_general);
$section->add_field('root_url', 'CDN Root URL (required)', 'field_input', array('description' => 'The base URL of the CDN.')); $section->add_field('root_url', 'CDN Root URL (required)', 'field_input', array('description' => 'The base URL of the CDN.'));
$section->add_field('file_extensions', 'File Extensions (required)', 'field_input'); $section->add_field('file_extensions', 'File Extensions (required)', 'field_input');
$section->add_field('css_root_url', 'CDN Root URL for CSS Files (optional)', 'field_input', array('description' => 'The base URL of the CDN for CSS Files.'));
$section->add_field('css_file_extensions', 'File Extensions for CSS Files (optional)', 'field_input');
$section->add_field('js_root_url', 'CDN Root URL for JS Files (optional)', 'field_input', array('description' => 'The base URL of the CDN for JS Files.'));
$section->add_field('js_file_extensions', 'File Extensions for JS Files (optional)', 'field_input');
} }
/** /**
...@@ -110,9 +131,14 @@ class CDN_Rewrite { ...@@ -110,9 +131,14 @@ class CDN_Rewrite {
* @return string * @return string
*/ */
public function filter_urls($content) { public function filter_urls($content) {
$root_url = $this->get_site_root_url();
$regex = '#(?<=[(\"\'])'.quotemeta($root_url).'(?:(/[^\"\')]+\.('.$this->file_extensions.')))#';
$root_url = $this->get_site_root_url();
$xml_begin = $xml_end = '';
if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
$xml_begin = '>';
$xml_end = '<';
}
$regex = '#(?<=[(\"\''.$xml_begin.'])'.quotemeta($root_url).'(?:(/[^\"\''.$xml_end.')]+\.('.join('|', array($this->file_extensions,$this->css_file_extensions,$this->js_file_extensions)).')))#';
$content = preg_replace_callback($regex, array($this, 'url_rewrite'), $content); $content = preg_replace_callback($regex, array($this, 'url_rewrite'), $content);
return $content; return $content;
...@@ -162,6 +188,12 @@ class CDN_Rewrite { ...@@ -162,6 +188,12 @@ class CDN_Rewrite {
$path = '/'.substr($path, strlen($bloginfo->path)); $path = '/'.substr($path, strlen($bloginfo->path));
} }
} }
if('/' !== $this->css_cdn_root_url && preg_match("/^.*\.(".$this->css_file_extensions.")$/i", $path) ) {
return $this->css_cdn_root_url . $path;
}
if('/' !== $this->js_cdn_root_url && preg_match("/^.*\.(".$this->js_file_extensions.")$/i", $path) ) {
return $this->js_cdn_root_url . $path;
}
return $this->cdn_root_url . $path; return $this->cdn_root_url . $path;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment