Select Git revision
cdn-rewrite.php
-
Michael Pretty authoredMichael Pretty authored
cdn-rewrite.php 6.92 KiB
<?php
/*
Plugin Name: CDN Rewrite
Plugin URI: http://voceconnect.com/
Description: Rewrites asset URLs to CDN
Version: 0.1
Author: Chris Scott, Michael Pretty
Author URI: http://voceconnect.com/
*/
require_once('voce-settings.php');
class CDN_Rewrite {
const OPTION_GENERAL = 'cdn_general';
private $submenu_general;
private $cdn_root_url;
private $file_extensions;
private $css_file_extensions;
private $css_cdn_root_url;
private $js_file_extensions;
private $js_cdn_root_url;
private $blog_details;
public function __construct() {
$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() {
if (!class_exists('Voce_Settings')) {
return;
}
add_action('admin_menu', array($this, 'add_options_page'));
if ('' == $this->file_extensions || '' == $this->cdn_root_url) {
add_action('admin_notices', array($this, 'settings_warning'));
return;
}
if('/' != $this->cdn_root_url) {
add_action('template_redirect', array($this, 'start_buffer'), 1);
}
}
/**
* get general setting
*
* @param string $setting setting name
* @return mixed setting value or false if not set
*/
private function get_setting($setting) {
$settings = get_option(self::OPTION_GENERAL);
if(!$settings || !is_array($settings)) {
$settings = array(
'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'
);