Skip to content

Commit

Permalink
namespace blitznote\wp\cdn; drop compatibility with PHP <= 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-kubacki committed May 3, 2014
1 parent c9b1fb2 commit 83a21d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cdn-linker-base.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace blitznote\wp\cdn;

/**
* Strategy for creating CDN URIs.
*/
Expand Down
18 changes: 9 additions & 9 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function writeCompressedSample($filename, $content) {
}

protected function setUp() {
$this->ctx = new CDNLinksRewriter(
$this->ctx = new blitznote\wp\cdn\CDNLinksRewriter(
'http://test.local',
ossdl_off_cdn_strategy_for('http://cdn.test.local'),
blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://cdn.test.local'),
'wp-content,wp-includes',
array('.php'),
false,
Expand All @@ -41,7 +41,7 @@ protected function setUp() {
}

public function testNoModificationIfUrlsMatch() {
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for('http://test.local');
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://test.local');
$input = '<a href="http://test.local/favicon.ico">some text</a>';
$output = $this->ctx->rewrite($input);
$this->assertEquals($input, $output);
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testDisableCDNURISifHTTPS() {

public function testMultipleCDNs() {
$this->ctx->rootrelative = true;
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for('http://cdn%4%.test.local');
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://cdn%4%.test.local');
$input = '<img src="/me.jpg" /><img src="/favicon.tif" /><a href="/movie.ogg">text</a><a href="/wp-content/file.exe">text</a>';
$expected = '<img src="http://cdn1.test.local/me.jpg" /><img src="http://cdn2.test.local/favicon.tif" /><a href="http://cdn3.test.local/movie.ogg">text</a><a href="http://cdn4.test.local/wp-content/file.exe">text</a>';

Expand All @@ -164,7 +164,7 @@ public function testMultipleCDNs() {

protected function comparePair($blog_url, $cdn_url, $root_relative, $fn_before, $fn_after) {
$this->ctx->blog_url = $blog_url;
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for($cdn_url);
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for($cdn_url);
$this->ctx->rootrelative = $root_relative;

$input = $this->readCompressedSample($fn_before);
Expand All @@ -189,7 +189,7 @@ public function testExcludes2() {
// Howdyargs.com has (in this version) exceptionally ugly code.
// One plugin, fp-autoconnect (?), breaks w/o the particular excludes.
$this->ctx->blog_url = 'http://howdyags.com';
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for('http://cdn.howdyags.com');
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://cdn.howdyags.com');
$this->ctx->excludes = array('.php', 'xd_receiver.htm');
$this->ctx->rootrelative = true;

Expand All @@ -207,7 +207,7 @@ public function testExcludes3() {
// 刘晖 has reported issue #4 and sent pages to reproce the issue.
// Let's see what has been configured to reproduce the incorrect output:
$this->ctx->blog_url = 'http://wangma.me';
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for('http://cdn.wangma.me');
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://cdn.wangma.me');

$this->ctx->excludes = array('.php'); //<-- this worked fine!
$input = $this->readCompressedSample('wangma.me-before.gz');
Expand All @@ -224,7 +224,7 @@ public function testExcludes3() {
public function testIncludeDirs() {
// this one has root-relative links to "/extscripts/..."
$this->ctx->blog_url = 'http://screenrant.com';
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for('http://cdn.screenrant.com');
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://cdn.screenrant.com');
$this->ctx->include_dirs = 'wp-content,wp-includes,extscripts';
$this->ctx->rootrelative = true;

Expand All @@ -239,7 +239,7 @@ public function testMissingWww() {
// http://prettyshinysparkly.com/
// 2012-01-30: everything under "/images/" doesn't work if root-relative == false
$this->ctx->blog_url = 'http://www.prettyshinysparkly.com';
$this->ctx->cdn_url = ossdl_off_cdn_strategy_for('http://cdn.prettyshinysparkly.com');
$this->ctx->cdn_url = blitznote\wp\cdn\ossdl_off_cdn_strategy_for('http://cdn.prettyshinysparkly.com');
$this->ctx->include_dirs = 'images, wp-content, wp-includes, js'; // spaces
$this->ctx->excludes = array_map('trim', explode(',', trim('.php, .flv, .do')));

Expand Down
14 changes: 8 additions & 6 deletions wp-cdn-linker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
License: RPL 1.5, for Personal Use
*/

namespace blitznote\wp;

if ( @include_once('cdn-linker-base.php') ) {
add_action('template_redirect', 'do_ossdl_off_ob_start');
add_action('template_redirect', 'blitznote\wp\cdn\do_ossdl_off_ob_start');
}

/********** WordPress Administrative ********/
Expand All @@ -23,14 +25,14 @@ function ossdl_off_activate() {
add_option('ossdl_off_www_is_optional', '');
add_option('ossdl_off_disable_cdnuris_if_https', '1');
}
register_activation_hook( __FILE__, 'ossdl_off_activate');
register_activation_hook( __FILE__, 'blitznote\wp\ossdl_off_activate');

/********** WordPress Interface ********/
add_action('admin_menu', 'ossdl_off_menu');
add_filter('plugin_action_links', 'ossdl_off_plugin_actions', 10, 2 );
add_action('admin_menu', 'blitznote\wp\ossdl_off_menu');
add_filter('plugin_action_links', 'blitznote\wp\ossdl_off_plugin_actions', 10, 2);

function ossdl_off_menu() {
add_options_page('CDN Linker', 'CDN Linker', 'manage_options', __FILE__, 'ossdl_off_options');
add_options_page('CDN Linker', 'CDN Linker', 'manage_options', __FILE__, 'blitznote\wp\ossdl_off_options');
}

function ossdl_off_plugin_actions($links, $file) {
Expand Down Expand Up @@ -74,7 +76,7 @@ function ossdl_off_options() {
$example_cdn_uri = str_replace('http://', 'http://cdn.', str_replace('www.', '', get_option('siteurl')))
. $example_file_rr;
} else {
$cdn_strategy = ossdl_off_cdn_strategy_for(trim(get_option('ossdl_off_cdn_url')));
$cdn_strategy = cdn\ossdl_off_cdn_strategy_for(trim(get_option('ossdl_off_cdn_url')));
$example_uri = get_option('siteurl') . $example_file_rr;
$example_cdn_uri = $cdn_strategy->get_for($example_uri) . $example_file_rr;
}
Expand Down

0 comments on commit 83a21d3

Please sign in to comment.