diff --git a/addons/BookmarkWidget/BookmarkWidget.inc b/addons/BookmarkWidget/BookmarkWidget.inc index a6bfed0..aa5eb74 100644 --- a/addons/BookmarkWidget/BookmarkWidget.inc +++ b/addons/BookmarkWidget/BookmarkWidget.inc @@ -1,6 +1,8 @@ __('Let your readers save their place via a cookie.', 'comicpress'))); @@ -8,31 +10,99 @@ class ComicPressAddonBookmarkWidget extends ComicPressAddon { add_action('wp_head', array(&$this, 'wp_head')); $this->comicpress->additional_javascripts[] = '/js/bookmark.js'; + + wp_enqueue_script('prototype'); + wp_enqueue_script('cookiejar', get_template_directory_uri() . '/js/cookiejar.js', array('prototype')); } function wp_head() { $last_comic = $this->comicpress->get_last_comic(); ?> -
- +
+ + + +
comicpress->comicpress_options['helpers'] = array(); + foreach (array('helpers', 'options') as $type) { + $this->comicpress->comicpress_options[$type] = array(); + } foreach ($this->comicpress->comicpress_options as $option => $value) { if (isset($_POST['cp'][$option])) { switch ($option) { @@ -550,8 +556,9 @@ class ComicPressAddonCore extends ComicPressAddon { $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; break; case 'helpers': - foreach ($_POST['cp'][$option] as $helper => $set) { - $this->comicpress->comicpress_options['helpers'][$helper] = true; + case 'addons': + foreach ($_POST['cp'][$option] as $type => $set) { + $this->comicpress->comicpress_options[$option][$type] = true; } break; } diff --git a/addons/Core/partials/options-admin.inc b/addons/Core/partials/options-admin.inc index aba14f2..de16393 100644 --- a/addons/Core/partials/options-admin.inc +++ b/addons/Core/partials/options-admin.inc @@ -69,7 +69,7 @@ -

(categories can be modified on the Posts -> Categories page)

+

Categories page)', 'comicpress') ?>

@@ -98,20 +98,51 @@

- + + all_addons)) { ?> + + + + +
- Enable editing helpers - __('Show partials info', 'comicpress'), "show_inline_comic_ordering" => __('Show inline comic ordering', 'comicpress') ) as $key => $label) { ?> -
+ +
+ all_addons as $addon) { + if (!empty($addon->name)) { + $enabled = ($addon->is_addon_manager !== true); + $checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name]; + ?> + +
+ +
- " /> + +
diff --git a/addons/SearchTranscripts/SearchTranscripts.inc b/addons/SearchTranscripts/SearchTranscripts.inc index 81fc28c..c91b42f 100644 --- a/addons/SearchTranscripts/SearchTranscripts.inc +++ b/addons/SearchTranscripts/SearchTranscripts.inc @@ -7,6 +7,7 @@ class ComicPressAddonSearchTranscripts extends ComicPressAddon { var $custom_template_default = 'search-transcript.php'; + var $name = "Search Transcripts"; function init($comicpress) { add_filter('posts_join', array(&$this, 'search_custom_join')); diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index e55c7ac..67262da 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -16,7 +16,8 @@ class ComicPress { 'category_usage' => 'storyline', 'layout' => 'classic.inc', 'helpers' => array(), - 'override_partials' => array() + 'override_partials' => array(), + 'addons' => array() ); var $additional_stylesheets = array(); diff --git a/functions.php b/functions.php index 7612938..1dfc6eb 100644 --- a/functions.php +++ b/functions.php @@ -16,7 +16,7 @@ function __comicpress_init() { $comicpress = new ComicPress(); $comicpress->init(); - $addons = array(); + $addons = array(); if (is_dir($addons_dir = (dirname(__FILE__) . '/addons'))) { $entries = glob($addons_dir . '/*'); @@ -29,24 +29,29 @@ function __comicpress_init() { $classname = "ComicPressAddon${classname}"; if (class_exists($classname)) { $addon =& new $classname(); - - $addon->init(&$comicpress); - if (current_user_can('edit_posts')) { - if (is_array($_REQUEST['cp'])) { - if (isset($_REQUEST['cp']['_nonce'])) { - if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { - if (method_exists($addon, 'handle_update')) { - $addon->handle_update(); - $comicpress->load(); + + if ( + $comicpress->comicpress_options['addons'][$addon->name] || + $addon->is_addon_manager + ) { + $addon->init(&$comicpress); + if (current_user_can('edit_posts')) { + if (is_array($_REQUEST['cp'])) { + if (isset($_REQUEST['cp']['_nonce'])) { + if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) { + if (method_exists($addon, 'handle_update')) { + $addon->handle_update(); + $comicpress->load(); + } } } } - } - if (is_admin()) { - add_action('admin_notices', array(&$addon, 'display_messages')); - } else { - add_action('wp_head', array(&$addon, 'display_messages')); - } + if (is_admin()) { + add_action('admin_notices', array(&$addon, 'display_messages')); + } else { + add_action('wp_head', array(&$addon, 'display_messages')); + } + } } $addons[] = $addon; } @@ -54,6 +59,10 @@ function __comicpress_init() { } } } + } + + foreach ($addons as $addon) { + if ($addon->is_addon_manager) { $addon->all_addons =& $addons; break; } } $layouts = $comicpress->get_layout_choices(); diff --git a/js/cookiejar.js b/js/cookiejar.js new file mode 100644 index 0000000..9ddbfdd --- /dev/null +++ b/js/cookiejar.js @@ -0,0 +1,157 @@ +/** + * Javascript code to store data as JSON strings in cookies. + * It uses prototype.js 1.5.1 (http://www.prototypejs.org) + * + * Author : Lalit Patel + * Website: http://www.lalit.org/lab/jsoncookies + * License: Apache Software License 2 + * http://www.apache.org/licenses/LICENSE-2.0 + * Version: 0.5 + * Updated: Jan 26, 2009 + * + * Chnage Log: + * v 0.5 + * - Changed License from CC to Apache 2 + * v 0.4 + * - Removed a extra comma in options (was breaking in IE and Opera). (Thanks Jason) + * - Removed the parameter name from the initialize function + * - Changed the way expires date was being calculated. (Thanks David) + * v 0.3 + * - Removed dependancy on json.js (http://www.json.org/json.js) + * - empty() function only deletes the cookies set by CookieJar + */ + +var CookieJar = Class.create(); + +CookieJar.prototype = { + + /** + * Append before all cookie names to differntiate them. + */ + appendString: "__CJ_", + + /** + * Initializes the cookie jar with the options. + */ + initialize: function(options) { + this.options = { + expires: 3600, // seconds (1 hr) + path: '', // cookie path + domain: '', // cookie domain + secure: '' // secure ? + }; + Object.extend(this.options, options || {}); + + if (this.options.expires != '') { + var date = new Date(); + date = new Date(date.getTime() + (this.options.expires * 1000)); + this.options.expires = '; expires=' + date.toGMTString(); + } + if (this.options.path != '') { + this.options.path = '; path=' + escape(this.options.path); + } + if (this.options.domain != '') { + this.options.domain = '; domain=' + escape(this.options.domain); + } + if (this.options.secure == 'secure') { + this.options.secure = '; secure'; + } else { + this.options.secure = ''; + } + }, + + /** + * Adds a name values pair. + */ + put: function(name, value) { + name = this.appendString + name; + cookie = this.options; + var type = typeof value; + switch(type) { + case 'undefined': + case 'function' : + case 'unknown' : return false; + case 'boolean' : + case 'string' : + case 'number' : value = String(value.toString()); + } + var cookie_str = name + "=" + escape(Object.toJSON(value)); + try { + document.cookie = cookie_str + cookie.expires + cookie.path + cookie.domain + cookie.secure; + } catch (e) { + return false; + } + return true; + }, + + /** + * Removes a particular cookie (name value pair) form the Cookie Jar. + */ + remove: function(name) { + name = this.appendString + name; + cookie = this.options; + try { + var date = new Date(); + date.setTime(date.getTime() - (3600 * 1000)); + var expires = '; expires=' + date.toGMTString(); + document.cookie = name + "=" + expires + cookie.path + cookie.domain + cookie.secure; + } catch (e) { + return false; + } + return true; + }, + + /** + * Return a particular cookie by name; + */ + get: function(name) { + name = this.appendString + name; + var cookies = document.cookie.match(name + '=(.*?)(;|$)'); + if (cookies) { + return (unescape(cookies[1])).evalJSON(); + } else { + return null; + } + }, + + /** + * Empties the Cookie Jar. Deletes all the cookies. + */ + empty: function() { + keys = this.getKeys(); + size = keys.size(); + for(i=0; i