diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..ae37baf1e419a9f8505e2c0409a7196e257a0ecc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "voce-settings-api"] + path = voce-settings-api + url = git@github.com:voceconnect/voce-settings-api.git diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ce1b758887b68e5e6ea8f781063a2c1190b8f340 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +CDN Rewrite +=========== +Contributors: voceplatforms +Tags: cdn, rewrite +Requires at least: 3.3 +Tested up to: 3.5 +Stable tag: 0.1.0 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +## Description +This plugin allows you to rewrite the root url of assets, css, and JavaScript files. This allows you to load these resources from an external URL improving the page load time by taking advantage of parallel browser requests. + +## Installation + +### As standard plugin: +> See [Installing Plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins). \ No newline at end of file diff --git a/cdn-rewrite.php b/cdn-rewrite.php index 5ed3af7bd4d53c67654c1592897da38c87cb6cdc..c14cf529ca27fd059affe8ba9669b3c376c70f6a 100644 --- a/cdn-rewrite.php +++ b/cdn-rewrite.php @@ -8,14 +8,12 @@ Author: Chris Scott, Michael Pretty Author URI: http://voceconnect.com/ */ -require_once('voce-settings.php'); +require_once('voce-settings-api/voce-settings-api.php'); class CDN_Rewrite { const OPTION_GENERAL = 'cdn_general'; - private $submenu_general; - private $cdn_root_url; private $file_extensions; @@ -44,11 +42,11 @@ class CDN_Rewrite { } public function initialize() { - if (!class_exists('Voce_Settings')) { + if (!class_exists('Voce_Settings_API')) { return; } - add_action('admin_menu', array($this, 'add_options_page')); + $this->add_options_page(); if ('' == $this->file_extensions || '' == $this->cdn_root_url) { add_action('admin_notices', array($this, 'settings_warning')); return; @@ -89,36 +87,14 @@ class CDN_Rewrite { * @return void */ public function add_options_page() { - $this->submenu_general = add_options_page('CDN Rewrite', 'CDN Rewrite', 'manage_options', self::OPTION_GENERAL, array($this, 'submenu_general')); - $settings = new Voce_Settings(self::OPTION_GENERAL, self::OPTION_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('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, defaults to Root URL)', '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, defaults to Root URL)', 'field_input'); - } - - /** - * callback to display submenu_external - * - * @return void - */ - function submenu_general() { - ?> - <div class="wrap"> - <h2>CDN Rewrite Settings</h2> - <form method="post" action="options.php"> - <?php settings_fields(self::OPTION_GENERAL); ?> - <?php do_settings_sections($this->submenu_general); ?> - <p class="submit"> - <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" /> - </p> - </form> - </div> - <?php + Voce_Settings_API::GetInstance()->add_page('CDN Rewrite', 'CDN Rewrite', self::OPTION_GENERAL, 'manage_options', '', 'options-general.php' ) + ->add_group( 'CDN Rewrite Settings', 'cdn_general' ) + ->add_setting( 'CDN Root URL (required)', 'root_url', array( 'description' => 'The base URL of the CDN.' ) )->group + ->add_setting( 'File Extensions (required)', 'file_extensions' )->group + ->add_setting( 'CDN Root URL for CSS Files (optional)', 'css_root_url', array( 'description' => 'The base URL of the CDN for CSS Files.' ) )->group + ->add_setting( 'File Extensions for CSS Files (optional)', 'css_file_extensions' )->group + ->add_setting( 'CDN Root URL for JS Files (optional, defaults to Root URL)', 'js_root_url', array( 'description' => 'The base URL of the CDN for JS Files.' ) )->group + ->add_setting( 'File Extensions for JS Files (optional, defaults to Root URL)', 'js_file_extensions' ); } /** diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..090093ef74ef09cc12c2435e3df4054766283ac6 --- /dev/null +++ b/readme.txt @@ -0,0 +1,20 @@ +=== CDN Rewrite === +Contributors: voceplatforms +Tags: cdn, rewrite +Requires at least: 3.3 +Tested up to: 3.5 +Stable tag: 0.1.0 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +Rewrite the root url of assets, css, and JavaScript files. + +== Description == + +This plugin allows you to rewrite the root url of assets, css, and JavaScript files. This allows you to load these resources from an external URL improving the page load time by taking advantage of parallel browser requests. + +== Installation == + +1. Upload `cdn-rewrite` to the `/wp-content/plugins/` directory +1. Activate the plugin through the 'Plugins' menu in WordPress +1. Once the plugin has been activated, navigate to the CDN Rewrite settings page and set the appropriate settings. \ No newline at end of file diff --git a/voce-settings-api b/voce-settings-api new file mode 160000 index 0000000000000000000000000000000000000000..4ef6990f9cbe89ac10be1d17678fbadb3c045bd1 --- /dev/null +++ b/voce-settings-api @@ -0,0 +1 @@ +Subproject commit 4ef6990f9cbe89ac10be1d17678fbadb3c045bd1 diff --git a/voce-settings.php b/voce-settings.php deleted file mode 100644 index 6a942052803f5d96cf4f73a133da4e5c71695c52..0000000000000000000000000000000000000000 --- a/voce-settings.php +++ /dev/null @@ -1,218 +0,0 @@ -<?php -/* Copyright 2010 Chris Scott (cscott@voceconnect.com) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -if (!class_exists('Voce_Settings')) { - class Voce_Settings { - - private $page_name; - private $option_name; - private $page; - private $section; - - public function __construct($option_group, $option_name, $sanitize_callback = '') { - register_setting($option_group, $option_name, $sanitize_callback); - $this->option_name = $option_name; - } - - public function add_section($name, $title, $page, $callback = null) { - // use blank output to allow not setting a callback if no output is desired between heading and fields - $callback = (null === $callback) ? create_function('', 'echo \'\';') : $callback; - - add_settings_section($name, $title, $callback, $page); - $this->section = $name; - $this->page = $page; - return $this; - } - - public function add_field($id, $label, $type, $args = null, $page = null, $section = null) { - $section = (null === $section) ? $this->section : $section; - $page = (null === $page) ? $this->page : $page; - $this->add_settings_field( - $id, - $label, - $type, - $page, - $section, - $args - ); - } - - - /** - * helper to use the settings API to add a field - * - * @param string $id the HTML ID for the field - * @param string $label the label tag text - * @param string $display_callback the function to use for the field display - * @param string $extra_args extra args to pass to the callback - * @return void - */ - public function add_settings_field($id, $label, $display_callback, $page, $section, $extra_args = null) { - - $args = array( - 'id' => $id, - 'label_for' => $id - ); - - if (is_array($extra_args)) { - $args += $extra_args; - } - - add_settings_field( - $id, - $label, - array(&$this, $display_callback), - $page, - $section, - $args - ); - } - - - /** - * checkbox callback for settings API - * - * @param string $args - * @return string checkbox - */ - public function field_checkbox($args) { - $options = get_option($this->option_name); - - $defaults = array('prepend_field' => '', 'append_field' => '', 'class' => ''); - $args = wp_parse_args($args, $defaults); - extract($args); - - $description = ($description) ? sprintf('<p><span class="description">%s</span></p>', $description) : ''; - - $checked = checked($options[$id], '1', false); - - echo sprintf( - "%s<input id='%s' name='{$this->option_name}[%s]' type='checkbox' value='1' %s class='%s' />%s%s", - $prepend_field, - $id, - $id, - $checked, - $class, - $append_field, - $description - ); - } - - /** - * input type text callback for settings API - * - * @param string $args - * @return string input - */ - public function field_input($args) { - $options = get_option($this->option_name); - - $defaults = array('prepend_field' => '', 'append_field' => '', 'class' => 'regular-text', 'type' => 'text'); - $args = wp_parse_args($args, $defaults); - extract($args); - - $description = (isset($description) && $description) ? sprintf('<p><span class="description">%s</span></p>', $description) : ''; - - if (!isset($value)) { - if (isset($options[$id])) { - $value = $options[$id]; - } else { - $value = ''; - } - } - - echo sprintf( - "%s<input id='%s' name='{$this->option_name}[%s]' type='%s' class='%s' value='%s' />%s%s", - $prepend_field, - $id, - $id, - $type, - $class, - esc_attr($value), - $append_field, - $description - ); - } - - /** - * textarea callback for settings API - * - * @param string $args - * @return string textarea - */ - public function field_textarea($args) { - $options = get_option($this->option_name); - $id = $args['id']; - - $defaults = array('prepend_field' => '', 'append_field' => '', 'columns' => 40, 'rows' => 8, 'class' => 'large-text'); - $args = wp_parse_args($args, $defaults); - extract($args); - - $description = (isset($description) && $description) ? sprintf('<p><span class="description">%s</span></p>', $description) : ''; - - echo sprintf( - "%s<textarea id='%s' name='{$this->option_name}[%s]' columns='%s' rows='%s' class='%s' />%s</textarea>%s%s", - $prepend_field, - $id, - $id, - $columns, - $rows, - $class, - esc_attr($options[$id]), - $append_field, - $description - ); - } - - public function field_radio($args) { - $options = get_option($this->option_name); - $id = $args['id']; - - $defaults = array('type' => 'radio', 'class' => ''); - $args = wp_parse_args($args, $defaults); - extract($args); - - if (!$items) { - return; - } - - echo '<fieldset><p>'; - foreach ($items as $item) { - if (!empty($options[$id])) { - $checked = checked($options[$id], $item['value'], false); - } else { - $checked = false; - } - - echo sprintf( - "<label> <input id='%s' name='{$this->option_name}[%s]' type='%s', class='%s' value='%s' %s /> %s</label><br />", - $id, - $id, - $type, - $class, - esc_attr($item['value']), - $checked, - esc_html($item['text']) - ); - } - echo '</fieldset></p>'; - - $description = (isset($description) && $description) ? sprintf('<p><span class="description">%s</span></p>', $description) : ''; - echo $description; - } - } -} \ No newline at end of file