Version Description
- First major release
- Fixed warnings
Download this release
Release Info
| Developer | keycdn |
| Plugin | |
| Version | 1.0.1 |
| Comparing to | |
| See all releases | |
Version 1.0.1
- cdn-enabler.php +86 -0
- inc/cdn_enabler.class.php +238 -0
- inc/cdn_enabler_rewriter.class.php +140 -0
- inc/cdn_enabler_settings.class.php +195 -0
- readme.txt +52 -0
cdn-enabler.php
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
Plugin Name: CDN Enabler
|
| 4 |
+
Text Domain: cdn
|
| 5 |
+
Description: Simply integrate a Content Delivery Network (CDN) into your WordPress site.
|
| 6 |
+
Author: KeyCDN
|
| 7 |
+
Author URI: https://www.keycdn.com
|
| 8 |
+
License: GPLv2 or later
|
| 9 |
+
Version: 1.0.1
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
Copyright (C) 2012-2015 KeyCDN
|
| 14 |
+
|
| 15 |
+
This program is free software; you can redistribute it and/or modify
|
| 16 |
+
it under the terms of the GNU General Public License as published by
|
| 17 |
+
the Free Software Foundation; either version 2 of the License, or
|
| 18 |
+
(at your option) any later version.
|
| 19 |
+
|
| 20 |
+
This program is distributed in the hope that it will be useful,
|
| 21 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 22 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 23 |
+
GNU General Public License for more details.
|
| 24 |
+
|
| 25 |
+
You should have received a copy of the GNU General Public License along
|
| 26 |
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
| 27 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 28 |
+
*/
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
/* Check & Quit */
|
| 32 |
+
defined('ABSPATH') OR exit;
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
/* constants */
|
| 36 |
+
define('CDN_ENABLER_FILE', __FILE__);
|
| 37 |
+
define('CDN_ENABLER_DIR', dirname(__FILE__));
|
| 38 |
+
define('CDN_ENABLER_BASE', plugin_basename(__FILE__));
|
| 39 |
+
define('CDN_ENABLER_MIN_WP', '3.8');
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
/* loader */
|
| 43 |
+
add_action(
|
| 44 |
+
'plugins_loaded',
|
| 45 |
+
array(
|
| 46 |
+
'CDN_Enabler',
|
| 47 |
+
'instance'
|
| 48 |
+
)
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
/* uninstall */
|
| 53 |
+
register_uninstall_hook(
|
| 54 |
+
__FILE__,
|
| 55 |
+
array(
|
| 56 |
+
'CDN_Enabler',
|
| 57 |
+
'handle_uninstall_hook'
|
| 58 |
+
)
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
/* activation */
|
| 63 |
+
register_activation_hook(
|
| 64 |
+
__FILE__,
|
| 65 |
+
array(
|
| 66 |
+
'CDN_Enabler',
|
| 67 |
+
'handle_activation_hook'
|
| 68 |
+
)
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
/* autoload init */
|
| 73 |
+
spl_autoload_register('CDN_ENABLER_autoload');
|
| 74 |
+
|
| 75 |
+
/* autoload funktion */
|
| 76 |
+
function CDN_ENABLER_autoload($class) {
|
| 77 |
+
if ( in_array($class, array('CDN_Enabler', 'CDN_Enabler_Rewriter', 'CDN_Enabler_Settings')) ) {
|
| 78 |
+
require_once(
|
| 79 |
+
sprintf(
|
| 80 |
+
'%s/inc/%s.class.php',
|
| 81 |
+
CDN_ENABLER_DIR,
|
| 82 |
+
strtolower($class)
|
| 83 |
+
)
|
| 84 |
+
);
|
| 85 |
+
}
|
| 86 |
+
}
|
inc/cdn_enabler.class.php
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* CDN_Enabler
|
| 5 |
+
*
|
| 6 |
+
* @since 0.0.1
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
class CDN_Enabler
|
| 10 |
+
{
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* pseudo-constructor
|
| 15 |
+
*
|
| 16 |
+
* @since 0.0.1
|
| 17 |
+
* @change 0.0.1
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
public static function instance()
|
| 21 |
+
{
|
| 22 |
+
new self();
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* constructor
|
| 28 |
+
*
|
| 29 |
+
* @since 0.0.1
|
| 30 |
+
* @change 0.0.1
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
public function __construct()
|
| 34 |
+
{
|
| 35 |
+
|
| 36 |
+
/* CDN rewriter hook */
|
| 37 |
+
add_action(
|
| 38 |
+
'template_redirect',
|
| 39 |
+
array(
|
| 40 |
+
__CLASS__,
|
| 41 |
+
'handle_rewrite_hook'
|
| 42 |
+
)
|
| 43 |
+
);
|
| 44 |
+
|
| 45 |
+
/* Filter */
|
| 46 |
+
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) OR (defined('DOING_CRON') && DOING_CRON) OR (defined('DOING_AJAX') && DOING_AJAX) OR (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ) {
|
| 47 |
+
//return;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* BE only */
|
| 51 |
+
if ( ! is_admin() ) {
|
| 52 |
+
//return;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* Hooks */
|
| 56 |
+
add_action(
|
| 57 |
+
'admin_init',
|
| 58 |
+
array(
|
| 59 |
+
'CDN_Enabler_Settings',
|
| 60 |
+
'register_settings'
|
| 61 |
+
)
|
| 62 |
+
);
|
| 63 |
+
add_action(
|
| 64 |
+
'admin_menu',
|
| 65 |
+
array(
|
| 66 |
+
'CDN_Enabler_Settings',
|
| 67 |
+
'add_settings_page'
|
| 68 |
+
)
|
| 69 |
+
);
|
| 70 |
+
add_filter(
|
| 71 |
+
'plugin_action_links_' .CDN_ENABLER_BASE,
|
| 72 |
+
array(
|
| 73 |
+
__CLASS__,
|
| 74 |
+
'add_action_link'
|
| 75 |
+
)
|
| 76 |
+
);
|
| 77 |
+
|
| 78 |
+
/* admin notices */
|
| 79 |
+
add_action(
|
| 80 |
+
'all_admin_notices',
|
| 81 |
+
array(
|
| 82 |
+
__CLASS__,
|
| 83 |
+
'cdn_enabler_requirements_check'
|
| 84 |
+
)
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* add action links
|
| 93 |
+
*
|
| 94 |
+
* @since 0.0.1
|
| 95 |
+
* @change 0.0.1
|
| 96 |
+
*
|
| 97 |
+
* @param array $data alreay existing links
|
| 98 |
+
* @return array $data extended array with links
|
| 99 |
+
*/
|
| 100 |
+
|
| 101 |
+
public static function add_action_link($data)
|
| 102 |
+
{
|
| 103 |
+
// check permission
|
| 104 |
+
if ( ! current_user_can('manage_options') ) {
|
| 105 |
+
return $data;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return array_merge(
|
| 109 |
+
$data,
|
| 110 |
+
array(
|
| 111 |
+
sprintf(
|
| 112 |
+
'<a href="%s">%s</a>',
|
| 113 |
+
add_query_arg(
|
| 114 |
+
array(
|
| 115 |
+
'page' => 'cdn_enabler'
|
| 116 |
+
),
|
| 117 |
+
admin_url('options-general.php')
|
| 118 |
+
),
|
| 119 |
+
__("Settings")
|
| 120 |
+
)
|
| 121 |
+
)
|
| 122 |
+
);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* run uninstall hook
|
| 128 |
+
*
|
| 129 |
+
* @since 0.0.1
|
| 130 |
+
* @change 0.0.1
|
| 131 |
+
*/
|
| 132 |
+
|
| 133 |
+
public static function handle_uninstall_hook()
|
| 134 |
+
{
|
| 135 |
+
delete_option('cdn_enabler');
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* run activation hook
|
| 141 |
+
*
|
| 142 |
+
* @since 0.0.1
|
| 143 |
+
* @change 0.0.1
|
| 144 |
+
*/
|
| 145 |
+
|
| 146 |
+
public static function handle_activation_hook() {
|
| 147 |
+
add_option(
|
| 148 |
+
'cdn_enabler',
|
| 149 |
+
array(
|
| 150 |
+
'url' => get_option('siteurl'),
|
| 151 |
+
'dirs' => 'wp-content,wp-includes',
|
| 152 |
+
'excludes' => '.php',
|
| 153 |
+
'relative' => '1',
|
| 154 |
+
'https' => ''
|
| 155 |
+
)
|
| 156 |
+
);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
/**
|
| 161 |
+
* check plugin requirements
|
| 162 |
+
*
|
| 163 |
+
* @since 0.0.1
|
| 164 |
+
* @change 0.0.1
|
| 165 |
+
*/
|
| 166 |
+
|
| 167 |
+
public static function cdn_enabler_requirements_check() {
|
| 168 |
+
// WordPress version check
|
| 169 |
+
if ( version_compare($GLOBALS['wp_version'], CDN_ENABLER_MIN_WP.'alpha', '<') ) {
|
| 170 |
+
show_message(
|
| 171 |
+
sprintf(
|
| 172 |
+
'<div class="error"><p>%s</p></div>',
|
| 173 |
+
sprintf(
|
| 174 |
+
__("CDN Enabler is optimized for WordPress %s. Please disable the plugin or upgrade your WordPress installation (recommended).", "cdn"),
|
| 175 |
+
CDN_ENABLER_MIN_WP
|
| 176 |
+
)
|
| 177 |
+
)
|
| 178 |
+
);
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
/**
|
| 184 |
+
* return plugin options
|
| 185 |
+
*
|
| 186 |
+
* @since 0.0.1
|
| 187 |
+
* @change 0.0.1
|
| 188 |
+
*
|
| 189 |
+
* @return array $diff data pairs
|
| 190 |
+
*/
|
| 191 |
+
|
| 192 |
+
public static function get_options()
|
| 193 |
+
{
|
| 194 |
+
return wp_parse_args(
|
| 195 |
+
get_option('cdn_enabler'),
|
| 196 |
+
array(
|
| 197 |
+
'url' => get_option('siteurl'),
|
| 198 |
+
'dirs' => 'wp-content,wp-includes',
|
| 199 |
+
'excludes' => '.php',
|
| 200 |
+
'relative' => 1,
|
| 201 |
+
'https' => 0
|
| 202 |
+
)
|
| 203 |
+
);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
/**
|
| 208 |
+
* run rewrite hook
|
| 209 |
+
*
|
| 210 |
+
* @since 0.0.1
|
| 211 |
+
* @change 0.0.1
|
| 212 |
+
*/
|
| 213 |
+
|
| 214 |
+
public static function handle_rewrite_hook()
|
| 215 |
+
{
|
| 216 |
+
$options = self::get_options();
|
| 217 |
+
|
| 218 |
+
// check if origin equals cdn url
|
| 219 |
+
if (get_option('siteurl') == $options['url']) {
|
| 220 |
+
return;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
$excludes = array_map('trim', explode(',', $options['excludes']));
|
| 224 |
+
|
| 225 |
+
$rewriter = new CDN_Enabler_Rewriter(
|
| 226 |
+
get_option('siteurl'),
|
| 227 |
+
$options['url'],
|
| 228 |
+
$options['dirs'],
|
| 229 |
+
$excludes,
|
| 230 |
+
$options['relative'],
|
| 231 |
+
$options['https']
|
| 232 |
+
);
|
| 233 |
+
ob_start(
|
| 234 |
+
array(&$rewriter, 'rewrite')
|
| 235 |
+
);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
}
|
inc/cdn_enabler_rewriter.class.php
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* CDN_Enabler_Rewriter
|
| 5 |
+
*
|
| 6 |
+
* @since 0.0.1
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
class CDN_Enabler_Rewriter
|
| 10 |
+
{
|
| 11 |
+
var $blog_url = null; // origin URL
|
| 12 |
+
var $cdn_url = null; // CDN URL
|
| 13 |
+
|
| 14 |
+
var $dirs = null; // included directories
|
| 15 |
+
var $excludes = array(); // excluded extensions
|
| 16 |
+
var $relative = false; // use CDN on relative paths
|
| 17 |
+
var $https = false; // use CDN on HTTPS
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* constructor
|
| 21 |
+
*
|
| 22 |
+
* @since 0.0.1
|
| 23 |
+
* @change 0.0.1
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
function __construct($blog_url, $cdn_url, $dirs, array $excludes, $relative, $https) {
|
| 27 |
+
$this->blog_url = $blog_url;
|
| 28 |
+
$this->cdn_url = $cdn_url;
|
| 29 |
+
$this->dirs = $dirs;
|
| 30 |
+
$this->excludes = $excludes;
|
| 31 |
+
$this->relative = $relative;
|
| 32 |
+
$this->https = $https;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* excludes assets that should not rewritten
|
| 38 |
+
*
|
| 39 |
+
* @since 0.0.1
|
| 40 |
+
* @change 0.0.1
|
| 41 |
+
*
|
| 42 |
+
* @param string $asset current asset
|
| 43 |
+
* @return boolean true if need to be excluded
|
| 44 |
+
*/
|
| 45 |
+
|
| 46 |
+
protected function exclude_asset(&$asset) {
|
| 47 |
+
foreach ($this->excludes as $exclude) {
|
| 48 |
+
if (!!$exclude && stristr($asset, $exclude) != false) {
|
| 49 |
+
return true;
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
return false;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* rewrite url
|
| 58 |
+
*
|
| 59 |
+
* @since 0.0.1
|
| 60 |
+
* @change 0.0.1
|
| 61 |
+
*
|
| 62 |
+
* @param string $asset current asset
|
| 63 |
+
* @return string updated url if not excluded
|
| 64 |
+
*/
|
| 65 |
+
|
| 66 |
+
protected function rewrite_url($asset) {
|
| 67 |
+
if ($this->exclude_asset($asset[0])) {
|
| 68 |
+
return $asset[0];
|
| 69 |
+
}
|
| 70 |
+
$blog_url = $this->blog_url;
|
| 71 |
+
|
| 72 |
+
// check if not a relative path
|
| 73 |
+
if (!$this->relative || strstr($asset[0], $blog_url)) {
|
| 74 |
+
return str_replace($blog_url, $this->cdn_url, $asset[0]);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
return $this->cdn_url . $asset[0];
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* get directory scope
|
| 83 |
+
*
|
| 84 |
+
* @since 0.0.1
|
| 85 |
+
* @change 0.0.1
|
| 86 |
+
*
|
| 87 |
+
* @return string directory scope
|
| 88 |
+
*/
|
| 89 |
+
|
| 90 |
+
protected function get_dir_scope() {
|
| 91 |
+
$input = explode(',', $this->dirs);
|
| 92 |
+
|
| 93 |
+
// default
|
| 94 |
+
if ($this->dirs == '' || count($input) < 1) {
|
| 95 |
+
return 'wp\-content|wp\-includes';
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
return implode('|', array_map('quotemeta', array_map('trim', $input)));
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* rewrite url
|
| 104 |
+
*
|
| 105 |
+
* @since 0.0.1
|
| 106 |
+
* @change 1.0.1
|
| 107 |
+
*
|
| 108 |
+
* @param string $html current raw HTML doc
|
| 109 |
+
* @return string updated HTML doc with CDN links
|
| 110 |
+
*/
|
| 111 |
+
|
| 112 |
+
public function rewrite($html) {
|
| 113 |
+
// check if HTTPS and use CDN over HTTPS enabled
|
| 114 |
+
if (!$this->https && isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') {
|
| 115 |
+
return $html;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// get dir scope in regex format
|
| 119 |
+
$dirs = $this->get_dir_scope();
|
| 120 |
+
$blog_url = quotemeta($this->blog_url);
|
| 121 |
+
|
| 122 |
+
// regex rule start
|
| 123 |
+
$regex_rule = '#(?<=[(\"\'])';
|
| 124 |
+
|
| 125 |
+
// check if relative paths
|
| 126 |
+
if ($this->relative) {
|
| 127 |
+
$regex_rule .= '(?:'.$blog_url.')?';
|
| 128 |
+
} else {
|
| 129 |
+
$regex_rule .= $blog_url;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
// regex rule end
|
| 133 |
+
$regex_rule .= '/(?:((?:'.$dirs.')[^\"\')]+)|([^/\"\']+\.[^/\"\')]+))(?=[\"\')])#';
|
| 134 |
+
|
| 135 |
+
// call the cdn rewriter callback
|
| 136 |
+
$cdn_html = preg_replace_callback($regex_rule, array(&$this, 'rewrite_url'), $html);
|
| 137 |
+
|
| 138 |
+
return $cdn_html;
|
| 139 |
+
}
|
| 140 |
+
}
|
inc/cdn_enabler_settings.class.php
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* CDN_Enabler_Settings
|
| 5 |
+
*
|
| 6 |
+
* @since 0.0.1
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
class CDN_Enabler_Settings
|
| 10 |
+
{
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* register settings
|
| 15 |
+
*
|
| 16 |
+
* @since 0.0.1
|
| 17 |
+
* @change 0.0.1
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
public static function register_settings()
|
| 21 |
+
{
|
| 22 |
+
register_setting(
|
| 23 |
+
'cdn_enabler',
|
| 24 |
+
'cdn_enabler',
|
| 25 |
+
array(
|
| 26 |
+
__CLASS__,
|
| 27 |
+
'validate_settings'
|
| 28 |
+
)
|
| 29 |
+
);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* validation of settings
|
| 35 |
+
*
|
| 36 |
+
* @since 0.0.1
|
| 37 |
+
* @change 0.0.1
|
| 38 |
+
*
|
| 39 |
+
* @param array $data array with form data
|
| 40 |
+
* @return array array with validated values
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
public static function validate_settings($data)
|
| 44 |
+
{
|
| 45 |
+
return array(
|
| 46 |
+
'url' => esc_url($data['url']),
|
| 47 |
+
'dirs' => esc_attr($data['dirs']),
|
| 48 |
+
'excludes' => esc_attr($data['excludes']),
|
| 49 |
+
'relative' => (int)($data['relative']),
|
| 50 |
+
'https' => (int)($data['https'])
|
| 51 |
+
);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* add settings page
|
| 57 |
+
*
|
| 58 |
+
* @since 0.0.1
|
| 59 |
+
* @change 0.0.1
|
| 60 |
+
*/
|
| 61 |
+
|
| 62 |
+
public static function add_settings_page()
|
| 63 |
+
{
|
| 64 |
+
$page = add_options_page(
|
| 65 |
+
'CDN Enabler',
|
| 66 |
+
'CDN Enabler',
|
| 67 |
+
'manage_options',
|
| 68 |
+
'cdn_enabler',
|
| 69 |
+
array(
|
| 70 |
+
__CLASS__,
|
| 71 |
+
'settings_page'
|
| 72 |
+
)
|
| 73 |
+
);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* settings page
|
| 79 |
+
*
|
| 80 |
+
* @since 0.0.1
|
| 81 |
+
* @change 0.0.1
|
| 82 |
+
*
|
| 83 |
+
* @return void
|
| 84 |
+
*/
|
| 85 |
+
|
| 86 |
+
public static function settings_page()
|
| 87 |
+
{ ?>
|
| 88 |
+
<div class="wrap">
|
| 89 |
+
<h2>
|
| 90 |
+
<?php _e("CDN Enabler Settings", "cdn"); ?>
|
| 91 |
+
</h2>
|
| 92 |
+
|
| 93 |
+
<form method="post" action="options.php">
|
| 94 |
+
<?php settings_fields('cdn_enabler') ?>
|
| 95 |
+
|
| 96 |
+
<?php $options = CDN_Enabler::get_options() ?>
|
| 97 |
+
|
| 98 |
+
<table class="form-table">
|
| 99 |
+
|
| 100 |
+
<tr valign="top">
|
| 101 |
+
<th scope="row">
|
| 102 |
+
<?php _e("CDN URL", "cdn"); ?>
|
| 103 |
+
</th>
|
| 104 |
+
<td>
|
| 105 |
+
<fieldset>
|
| 106 |
+
<label for="cdn_enabler_url">
|
| 107 |
+
<input type="text" name="cdn_enabler[url]" id="cdn_enabler_url" value="<?php echo $options['url']; ?>" size="64" class="regular-text code" />
|
| 108 |
+
<?php _e("", "cdn"); ?>
|
| 109 |
+
</label>
|
| 110 |
+
|
| 111 |
+
<p class="description">
|
| 112 |
+
<?php _e("Enter the CDN URL without trailing", "cdn"); ?> <code>/</code>
|
| 113 |
+
</p>
|
| 114 |
+
</fieldset>
|
| 115 |
+
</td>
|
| 116 |
+
</tr>
|
| 117 |
+
|
| 118 |
+
<tr valign="top">
|
| 119 |
+
<th scope="row">
|
| 120 |
+
<?php _e("Included Directories", "cdn"); ?>
|
| 121 |
+
</th>
|
| 122 |
+
<td>
|
| 123 |
+
<fieldset>
|
| 124 |
+
<label for="cdn_enabler_dirs">
|
| 125 |
+
<input type="text" name="cdn_enabler[dirs]" id="cdn_enabler_dirs" value="<?php echo $options['dirs']; ?>" size="64" class="regular-text code" />
|
| 126 |
+
<?php _e("Default: <code>wp-content,wp-includes</code>", "cdn"); ?>
|
| 127 |
+
</label>
|
| 128 |
+
|
| 129 |
+
<p class="description">
|
| 130 |
+
<?php _e("Assets in these directories will be pointed to the CDN URL. Enter the directories separated by", "cdn"); ?> <code>,</code>
|
| 131 |
+
</p>
|
| 132 |
+
</fieldset>
|
| 133 |
+
</td>
|
| 134 |
+
</tr>
|
| 135 |
+
|
| 136 |
+
<tr valign="top">
|
| 137 |
+
<th scope="row">
|
| 138 |
+
<?php _e("Excluded Extensions", "cdn"); ?>
|
| 139 |
+
</th>
|
| 140 |
+
<td>
|
| 141 |
+
<fieldset>
|
| 142 |
+
<label for="cdn_enabler_excludes">
|
| 143 |
+
<input type="text" name="cdn_enabler[excludes]" id="cdn_enabler_excludes" value="<?php echo $options['excludes']; ?>" size="64" class="regular-text code" />
|
| 144 |
+
<?php _e("Default: <code>.php</code>", "cdn"); ?>
|
| 145 |
+
</label>
|
| 146 |
+
|
| 147 |
+
<p class="description">
|
| 148 |
+
<?php _e("Enter the exclusions separated by", "cdn"); ?> <code>,</code>
|
| 149 |
+
</p>
|
| 150 |
+
</fieldset>
|
| 151 |
+
</td>
|
| 152 |
+
</tr>
|
| 153 |
+
|
| 154 |
+
<tr valign="top">
|
| 155 |
+
<th scope="row">
|
| 156 |
+
<?php _e("Relative Path", "cdn"); ?>
|
| 157 |
+
</th>
|
| 158 |
+
<td>
|
| 159 |
+
<fieldset>
|
| 160 |
+
<label for="cdn_enabler_relative">
|
| 161 |
+
<input type="checkbox" name="cdn_enabler[relative]" id="cdn_enabler_relative" value="1" <?php checked(1, $options['relative']) ?> />
|
| 162 |
+
<?php _e("Enable CDN for relative paths (default: enabled).", "cdn"); ?>
|
| 163 |
+
</label>
|
| 164 |
+
|
| 165 |
+
<p class="description">
|
| 166 |
+
<?php _e("", "cdn"); ?>
|
| 167 |
+
</p>
|
| 168 |
+
</fieldset>
|
| 169 |
+
</td>
|
| 170 |
+
</tr>
|
| 171 |
+
|
| 172 |
+
<tr valign="top">
|
| 173 |
+
<th scope="row">
|
| 174 |
+
<?php _e("CDN HTTPS", "cdn"); ?>
|
| 175 |
+
</th>
|
| 176 |
+
<td>
|
| 177 |
+
<fieldset>
|
| 178 |
+
<label for="cdn_enabler_https">
|
| 179 |
+
<input type="checkbox" name="cdn_enabler[https]" id="cdn_enabler_https" value="1" <?php checked(1, $options['https']) ?> />
|
| 180 |
+
<?php _e("Enable CDN for HTTPS connections (default: disabled).", "cdn"); ?>
|
| 181 |
+
</label>
|
| 182 |
+
|
| 183 |
+
<p class="description">
|
| 184 |
+
<?php _e("", "cdn"); ?>
|
| 185 |
+
</p>
|
| 186 |
+
</fieldset>
|
| 187 |
+
</td>
|
| 188 |
+
</tr>
|
| 189 |
+
</table>
|
| 190 |
+
|
| 191 |
+
<?php submit_button() ?>
|
| 192 |
+
</form>
|
| 193 |
+
</div><?php
|
| 194 |
+
}
|
| 195 |
+
}
|
readme.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=== CDN Enabler - WordPress CDN Plugin ===
|
| 2 |
+
Contributors: keycdn
|
| 3 |
+
Tags: cdn, content delivery network, content distribution network
|
| 4 |
+
Requires at least: 3.8
|
| 5 |
+
Tested up to: 4.2.3
|
| 6 |
+
Stable tag: trunk
|
| 7 |
+
License: GPLv2 or later
|
| 8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
Enable CDN URLs for your static assets such as images, CSS or JavaScript files.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
== Description ==
|
| 17 |
+
|
| 18 |
+
A **content delivery network (CDN)** is a network of distributed edge servers, which accelerate your content around the globe. The main benefits of a CDN are *scalability*, *reliability* and *performance*. The **CDN Enabler** plugin helps you to quickly and easily integrate a CDN in WordPress.
|
| 19 |
+
|
| 20 |
+
= What it does? =
|
| 21 |
+
The CDN Enabler plugin has been developed to link your content to the CDN URLs.
|
| 22 |
+
|
| 23 |
+
= Features =
|
| 24 |
+
* Link assets to load from a CDN
|
| 25 |
+
* Set included directories
|
| 26 |
+
* Define exclusions
|
| 27 |
+
* Enable or disable for HTTPS
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
= System Requirements =
|
| 31 |
+
* PHP >=5.3
|
| 32 |
+
* WordPress >=3.8
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
= Author =
|
| 36 |
+
* [Twitter](https://twitter.com/keycdn)
|
| 37 |
+
* [Google+](https://plus.google.com/+Keycdn "Google+")
|
| 38 |
+
* [KeyCDN](https://www.keycdn.com "KeyCDN")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
== Changelog ==
|
| 43 |
+
|
| 44 |
+
= 1.0.1 =
|
| 45 |
+
* First major release
|
| 46 |
+
* Fixed warnings
|
| 47 |
+
|
| 48 |
+
= 0.0.1 =
|
| 49 |
+
* First release
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
== Screenshots ==
|
