diff --git a/addons/BookmarkWidget/BookmarkWidget.inc b/addons/BookmarkWidget/BookmarkWidget.inc
index a6bfed0..f277495 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,25 @@ 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'));
+ wp_enqueue_script('bookmark', get_template_directory_uri() . '/js/bookmark.js', array('prototype', 'cookiejar'));
}
- 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;
}
@@ -575,7 +582,7 @@ class ComicPressAddonCore extends ComicPressAddon {
function handle_update_override_partial($info) {
switch ($info['action']) {
case __('Update partial', 'comicpress'):
- $this->comicpress->comicpress_options['override_partials'][$info['partial']] = $info['code'];
+ $this->comicpress->comicpress_options['override_partials'][$info['partial']] = stripslashes($info['code']);
break;
case __('Delete override partial', 'comicpress'):
unset($this->comicpress->comicpress_options['override_partials'][$info['partial']]);
@@ -643,4 +650,4 @@ class ComicPressAddonCore extends ComicPressAddon {
}
}
-?>
\ No newline at end of file
+?>
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 @@
- " />
+
+
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/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc
index 5e458c3..6bb91a8 100644
--- a/classes/ComicPressComicPost.inc
+++ b/classes/ComicPressComicPost.inc
@@ -170,10 +170,16 @@ class ComicPressComicPost {
usort($remaining_posts_to_sort[$type], array(&$this, 'sort_remaining_comic_images'));
}
- $result = array_merge($comic_image_ordering, $remaining_posts_to_sort);
+ foreach ($remaining_posts_to_sort as $type => $posts) {
+ if (is_array($comic_image_ordering[$type])) {
+ $comic_image_ordering[$type] = array_merge($comic_image_ordering[$type], $posts);
+ } else {
+ $comic_image_ordering[$type] = $posts;
+ }
+ }
- update_post_meta($this->post->ID, 'comic_ordering', $this->build_comic_ordering_string($result));
- return $result;
+ update_post_meta($this->post->ID, 'comic_ordering', $this->build_comic_ordering_string($comic_image_ordering));
+ return $comic_image_ordering;
}
}
diff --git a/functions.php b/functions.php
index 7bb3d83..1dfc6eb 100644
--- a/functions.php
+++ b/functions.php
@@ -1,236 +1,239 @@
-init();
+init();
$addons = array();
+
+ if (is_dir($addons_dir = (dirname(__FILE__) . '/addons'))) {
+ $entries = glob($addons_dir . '/*');
+ if (is_array($entries)) {
+ foreach ($entries as $entry) {
+ if (is_dir($entry)) {
+ $classname = basename($entry);
+ if (file_exists($entry . "/${classname}.inc")) {
+ require_once($entry . "/${classname}.inc");
+ $classname = "ComicPressAddon${classname}";
+ if (class_exists($classname)) {
+ $addon =& new $classname();
- if (get_magic_quotes_gpc()) {
- $_POST = stripslashes_deep($_POST);
- $_GET = stripslashes_deep($_GET);
- $_REQUEST = stripslashes_deep($_REQUEST);
- }
-
- if (is_dir($addons_dir = (dirname(__FILE__) . '/addons'))) {
- $entries = glob($addons_dir . '/*');
- if (is_array($entries)) {
- foreach ($entries as $entry) {
- if (is_dir($entry)) {
- $classname = basename($entry);
- if (file_exists($entry . "/${classname}.inc")) {
- require_once($entry . "/${classname}.inc");
- $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;
- }
- }
- }
- }
- }
+ }
+ $addons[] = $addon;
+ }
+ }
+ }
+ }
+ }
}
- $layouts = $comicpress->get_layout_choices();
- if (isset($layouts[$comicpress->comicpress_options['layout']])) {
- if (isset($layouts[$comicpress->comicpress_options['layout']]['Sidebars'])) {
- foreach (explode(",", $layouts[$comicpress->comicpress_options['layout']]['Sidebars']) as $sidebar) {
- $sidebar = trim($sidebar);
- register_sidebar($sidebar);
- }
- }
- }
-}
-
-function comicpress_init() {
- global $post, $comicpress;
-
- if (!empty($post)) {
- if (in_comic_category() && $comicpress->is_multicomic() && !is_index()) {
- $comicpress->setup_multicomic_partial_paths($post->ID);
- }
- }
-
- $comicpress->partial_paths[] = get_template_directory() . '/partials';
-}
-
-function comicpress_get_header() {
- get_header();
-}
-
-function include_partial($partials = '') {
- global $comicpress, $post, $nav_comics;
-
- if (!is_array($partials)) { $partials = func_get_args(); }
-
- $content = $target = null;
-
- if (($result = $comicpress->get_options_partial($partials)) !== false) {
- list($target, $code) = $result;
- ob_start(); eval('?>' . $code . ''); $content = ob_get_clean();
- } else {
- $target = $comicpress->get_partial_path($partials);
-
- if ($target !== false) {
- ob_start(); include($target); $content = ob_get_clean();
- }
-
- $target = str_replace(".inc", "", $target);
- }
-
- if (!empty($target) && !empty($content)) {
- echo apply_filters("comicpress_partial", $content, $target);
- }
-}
-
-function in_comic_category() {
- global $post, $comicpress;
-
- return $comicpress->in_comic_category($post->ID);
-}
-
-/**
- * Display the list of Storyline categories.
- */
-function comicpress_list_storyline_categories($args = "") {
- global $category_tree;
-
- $defaults = array(
- 'style' => 'list', 'title_li' => __('Storyline')
- );
-
- $r = wp_parse_args($args, $defaults);
-
- extract($r);
-
- $categories_by_id = get_all_category_objects_by_id();
-
- $output = '';
- if ($style == "list") { $output .= ''; }
- if ($title_li && ($style == "list")) { $output .= $title_li; }
- if ($style == "list") { $output .= ""; }
- $current_depth = 0;
- foreach ($category_tree as $node) {
- $parts = explode("/", $node);
- $category_id = end($parts);
- $target_depth = count($parts) - 2;
- if ($target_depth > $current_depth) {
- $output .= str_repeat("", ($target_depth - $current_depth));
- }
- if ($target_depth < $current_depth) {
- $output .= str_repeat("
", ($current_depth - $target_depth));
- }
- $output .= '- ';
- $output .= $categories_by_id[$category_id]->cat_name;
- $output .= "
";
- $current_depth = $target_depth;
- }
- if ($current_depth > 0) {
- $output .= str_repeat("
", $current_depth);
- }
- if ($style == "list") { $output .= ""; }
- echo $output;
-}
-
-/**
-* Display the comic transcript
-* Transcript must be entered into a custom field named "transcript"
-* @param string $displaymode, "raw" (straight from the field), "br" (includes html line breaks), "styled" (fully css styled with JavaScript expander)
-*/
-function the_transcript($displaymode = 'raw') {
- $transcript = get_post_meta( get_the_ID(), "transcript", true );
- switch ($displaymode) {
- case "raw":
- echo $transcript;
- break;
- case "br":
- echo nl2br($transcript);
- break;
- case "styled":
- if (!empty($transcript)) { ?>
-
-
-
-
- Latest Comics
-
-
-
-
-
-
-
-
-
-
-
+ foreach ($addons as $addon) {
+ if ($addon->is_addon_manager) { $addon->all_addons =& $addons; break; }
+ }
+
+ $layouts = $comicpress->get_layout_choices();
+ if (isset($layouts[$comicpress->comicpress_options['layout']])) {
+ if (isset($layouts[$comicpress->comicpress_options['layout']]['Sidebars'])) {
+ foreach (explode(",", $layouts[$comicpress->comicpress_options['layout']]['Sidebars']) as $sidebar) {
+ $sidebar = trim($sidebar);
+ register_sidebar($sidebar);
+ }
+ }
+ }
+}
+
+function comicpress_init() {
+ global $post, $comicpress;
+
+ if (!empty($post)) {
+ if (in_comic_category() && $comicpress->is_multicomic() && !is_index()) {
+ $comicpress->setup_multicomic_partial_paths($post->ID);
+ }
+ }
+
+ $comicpress->partial_paths[] = get_template_directory() . '/partials';
+}
+
+function comicpress_get_header() {
+ get_header();
+}
+
+function include_partial($partials = '') {
+ global $comicpress, $post, $nav_comics;
+
+ if (!is_array($partials)) { $partials = func_get_args(); }
+
+ $content = $target = null;
+
+ if (($result = $comicpress->get_options_partial($partials)) !== false) {
+ list($target, $code) = $result;
+ ob_start(); eval(' ?>' . $code . 'get_partial_path($partials);
+
+ if ($target !== false) {
+ ob_start(); include($target); $content = ob_get_clean();
+ }
+
+ $target = str_replace(".inc", "", $target);
+ }
+
+ if (!empty($target) && !empty($content)) {
+ echo apply_filters("comicpress_partial", $content, $target);
+ }
+}
+
+function in_comic_category() {
+ global $post, $comicpress;
+
+ return $comicpress->in_comic_category($post->ID);
+}
+
+/**
+ * Display the list of Storyline categories.
+ */
+function comicpress_list_storyline_categories($args = "") {
+ global $category_tree;
+
+ $defaults = array(
+ 'style' => 'list', 'title_li' => __('Storyline')
+ );
+
+ $r = wp_parse_args($args, $defaults);
+
+ extract($r);
+
+ $categories_by_id = get_all_category_objects_by_id();
+
+ $output = '';
+ if ($style == "list") { $output .= ''; }
+ if ($title_li && ($style == "list")) { $output .= $title_li; }
+ if ($style == "list") { $output .= ""; }
+ $current_depth = 0;
+ foreach ($category_tree as $node) {
+ $parts = explode("/", $node);
+ $category_id = end($parts);
+ $target_depth = count($parts) - 2;
+ if ($target_depth > $current_depth) {
+ $output .= str_repeat("", ($target_depth - $current_depth));
+ }
+ if ($target_depth < $current_depth) {
+ $output .= str_repeat("
", ($current_depth - $target_depth));
+ }
+ $output .= '- ';
+ $output .= $categories_by_id[$category_id]->cat_name;
+ $output .= "
";
+ $current_depth = $target_depth;
+ }
+ if ($current_depth > 0) {
+ $output .= str_repeat("
", $current_depth);
+ }
+ if ($style == "list") { $output .= ""; }
+ echo $output;
+}
+
+/**
+* Display the comic transcript
+* Transcript must be entered into a custom field named "transcript"
+* @param string $displaymode, "raw" (straight from the field), "br" (includes html line breaks), "styled" (fully css styled with JavaScript expander)
+*/
+function the_transcript($displaymode = 'raw') {
+ $transcript = get_post_meta( get_the_ID(), "transcript", true );
+ switch ($displaymode) {
+ case "raw":
+ echo $transcript;
+ break;
+ case "br":
+ echo nl2br($transcript);
+ break;
+ case "styled":
+ if (!empty($transcript)) { ?>
+
+
+
+
+ Latest Comics
+
+
+
+
+
+
+
+
+
+
+
diff --git a/js/bookmark.js b/js/bookmark.js
index a6b5f42..e890e3e 100644
--- a/js/bookmark.js
+++ b/js/bookmark.js
@@ -1,81 +1,70 @@
-var cl = 31;
-
-/* Below are our functions for this little script */
-
-function bmhome() {
- if(document.getElementById) {
- document.getElementById('gtc').src = imgGotoOn;
- document.getElementById('rmc').src = imgClearOn;
+var button_images = {
+ 'clear-tag': {
+ 'off': '3a.gif', 'on': '3.gif'
+ },
+ 'goto-tag': {
+ 'off': '2a.gif', 'on': '2.gif'
}
- createCookie("bm", comicPermalink, cl);
-}
+};
-function bm() {
- if(document.getElementById) {
- document.getElementById('gtc').src = imgGotoOn;
- document.getElementById('rmc').src = imgClearOn;
- }
- createCookie("bm", window.location, cl);
-}
+var BookmarkInfo = Class.create({
+ 'default': {
+ 'permalink': false
+ },
+ 'initialize': function() {
+ this.jar = new CookieJar({
+ 'expires': 60 * 60 * 24 * 31,
+ 'path': '/'
+ });
+ },
+ 'read': function() {
+ var bookmark_info = this.jar.get('bookmark-info');
-function bmc() {
- if(document.getElementById) {
- document.getElementById('gtc').src = imgGotoOff;
- document.getElementById('rmc').src = imgClearOff;
+ if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) {
+ bookmark_info = this.default;
+ }
+
+ return bookmark_info;
+ },
+ 'write': function(bookmark_info) {
+ this.jar.put('bookmark-info', bookmark_info);
+ if (this.onWrite) { this.onWrite(bookmark_info); }
}
- createCookie("bm","",-1);
-}
+});
+
+Event.observe(window, 'load', function() {
+ var bookmark_info = new BookmarkInfo();
+ var info = bookmark_info.read();
-function gto() {
- var g = readCookie('bm');
- if(g) {
- window.location = g;
- }
-}
+ var hrefs = {};
+ $$('#comic-bookmark-holder a').each(function(a) {
+ var name = $w(a.className).shift();
+ hrefs[name] = a;
+ });
+
+ var set_goto_tag = function(i) {
+ hrefs['goto-tag'].href = (i.permalink ? i.permalink : "#");
+ [ 'goto-tag','clear-tag' ].each(function(which) {
+ hrefs[which].select('img')[0].src = image_root + button_images[which][i.permalink ? "on" : "off"];
+ });
+ };
+
+ bookmark_info.onWrite = function(i) { set_goto_tag(i); }
+ set_goto_tag(info);
-/* The follow functions have been borrowed from Peter-Paul Koch. Please find them here: http://www.quirksmode.org */
-
-function createCookie(name,value,days) {
- if (days) {
- var date = new Date();
- date.setTime(date.getTime()+(days*24*60*60*1000));
- var expires = "; expires="+date.toGMTString();
- } else var expires = "";
- document.cookie = name+"="+value+expires+"; path="+comicDir;
-}
-function readCookie(name) {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1,c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
- }
- return null;
-}
-
-function writeBookmarkWidget() {
- createCookie('t', 1);
- var c = readCookie('t');
- if (c && document.getElementById) {
- var l = readCookie('bm');
- var gt = imgGotoOff;
- var ct = imgClearOff;
- if (l) {
- gt = imgGotoOn;
- ct = imgClearOn;
- }
- document.write('COMIC BOOKMARK
Click "Tag Page" to bookmark a comic page. When you return to the site, click "Goto Tag" to continue where you left off.
');
- if (isHome) {
- document.write('');
- document.write('');
- document.write('');
- document.write('');
- } else if (isSingle) {
- document.write('');
- document.write('');
- document.write('');
- document.write('');
- }
- }
-}
\ No newline at end of file
+ Event.observe(hrefs['tag-page'], 'click', function(e) {
+ Event.stop(e);
+ info.permalink = permalink;
+ bookmark_info.write(info);
+ });
+
+ Event.observe(hrefs['clear-tag'], 'click', function(e) {
+ Event.stop(e);
+ info.permalink = false;
+ bookmark_info.write(info);
+ });
+
+ Event.observe(hrefs['goto-tag'], 'click', function(e) {
+ if (hrefs['goto-tag'].href == "#") { Event.stop(e); }
+ });
+});
diff --git a/js/cookiejar.js b/js/cookiejar.js
new file mode 100644
index 0000000..a7c4a8d
--- /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
-
\ No newline at end of file
+
diff --git a/test/ComicPressComicPostTest.php b/test/ComicPressComicPostTest.php
index 286ca56..da35d04 100644
--- a/test/ComicPressComicPostTest.php
+++ b/test/ComicPressComicPostTest.php
@@ -151,7 +151,7 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
$p->expects($this->any())->method('get_comic_image_attachments')->will($this->returnValue($attachments));
wp_insert_post((object)array('ID' => 1));
- update_post_meta(1, 'comic_ordering', "comic:3,2");
+ update_post_meta(1, 'comic_ordering', "comic:3");
$p->post = (object)array('ID' => 1);