working on annotated entries

This commit is contained in:
John Bintz 2010-03-17 23:28:52 -04:00
parent bc2bc475d4
commit 99119393b5
19 changed files with 1232 additions and 52 deletions

View File

@ -80,8 +80,8 @@ class ComicPressAdmin {
function admin_menu() { function admin_menu() {
global $plugin_page, $pagenow, $post; global $plugin_page, $pagenow, $post;
add_theme_page(__("ComicPress", 'comicpress'), __('ComicPress', 'comicpress'), 'edit_themes', 'comicpress/render_admin', array(&$this, 'render_admin')); add_menu_page(__("ComicPress Core", 'comicpress'), __('ComicPress', 'comicpress'), 'edit_themes', 'comicpress/render_admin', array(&$this, 'render_admin'));
add_theme_page(__("ComicPress Documentation", 'comicpress'), __('ComicPress Docs', 'comicpress'), 'edit_themes', 'comicpress/comicpress_docs', array(&$this, 'render_documentation')); add_submenu_page('comicpress/render_admin', __("ComicPress Core Documentation", 'comicpress'), __('Documentation', 'comicpress'), 'edit_themes', 'comicpress/comicpress_docs', array(&$this, 'render_documentation'));
add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
@ -89,6 +89,8 @@ class ComicPressAdmin {
case 'comicpress/render_admin': case 'comicpress/render_admin':
wp_enqueue_style('cp-admin', plugin_dir_url(dirname(__FILE__)) . '/css/cp-admin.css'); wp_enqueue_style('cp-admin', plugin_dir_url(dirname(__FILE__)) . '/css/cp-admin.css');
wp_enqueue_script('cp-admin', plugin_dir_url(dirname(__FILE__)) . '/js/Storyline.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-tabs')); wp_enqueue_script('cp-admin', plugin_dir_url(dirname(__FILE__)) . '/js/Storyline.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-tabs'));
wp_enqueue_script('json', plugin_dir_url(dirname(__FILE__)) . '/js/json2.js');
wp_enqueue_script('jquery-ui-slider', plugin_dir_url(dirname(__FILE__)) . '/js/jquery-ui-1.7.2.slider.min.js', array('jquery'));
add_action('admin_footer', array(&$this, 'admin_footer')); add_action('admin_footer', array(&$this, 'admin_footer'));
break; break;
case 'comicpress/comicpress_docs': case 'comicpress/comicpress_docs':
@ -98,12 +100,6 @@ class ComicPressAdmin {
wp_enqueue_script('scriptaculous-effects'); wp_enqueue_script('scriptaculous-effects');
break; break;
} }
if ($plugin_page == 'comicpress/render_admin') {
}
if ($plugin_page == 'comicpress/comicpress_docs') {
}
} }
function admin_enqueue_scripts($hook_suffix) { function admin_enqueue_scripts($hook_suffix) {
@ -173,6 +169,7 @@ class ComicPressAdmin {
function render_admin() { function render_admin() {
$nonce = wp_create_nonce('comicpress'); $nonce = wp_create_nonce('comicpress');
$action_nonce = wp_create_nonce('comicpress-comicpress-options'); $action_nonce = wp_create_nonce('comicpress-comicpress-options');
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
$storyline->normalize(); $storyline->normalize();
$storyline->read_from_options(); $storyline->read_from_options();
@ -524,6 +521,45 @@ class ComicPressAdmin {
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
function handle_update_retrieve_category_posts($info) {
$this->is_ajax = true;
$core = new ComicPressTagBuilderFactory();
$post_info = array();
$factory = new ComicPressBackendFilesystemFactory();
foreach ($core->in($info['category'])->all() as $post) {
$annotation = get_post_meta($post->ID, 'comicpress-annotation', true);
// a way to ensure things are cool
$factory->generate_from_post($post);
$comic_post = new ComicPressComicPost($post);
$comic_post->normalize_ordering();
$current_post = array(
'id' => $post->ID,
'title' => $post->post_title,
'image' => $core->post($post)->media()->url(),
'date' => date('Y-m-d', strtotime($post->post_date))
);
if (is_array($annotation)) {
foreach ($annotation as $category => $annotation_info) {
if ($category == $info['category']) {
$current_post['annotation'] = $annotation_info;
}
}
}
$post_info[] = $current_post;
}
echo json_encode($post_info);
exit(0);
}
/** /**
* Update the user's zoom slider metadata. * Update the user's zoom slider metadata.
*/ */

View File

@ -0,0 +1,31 @@
<?php
class ComicPressAnnotatedEntries {
function save($info, $dbi = null) {
if (is_null($dbi)) {
$dbi = ComicPressDBInterface::get_instance();
}
$dbi->clear_annotations();
foreach ($info as $category_grouping => $posts) {
foreach ($posts as $post_id => $annotation) {
$current_annotation = get_post_meta($post_id, 'comicpress-annotation', true);
if (!is_array($current_annotation)) {
$current_annotation = array();
}
$current_annotation[$category_grouping] = $annotation;
update_post_meta($post_id, 'comicpress-annotation', $current_annotation);
}
}
}
function handle_update($info) {
if ($data = json_decode(stripslashes($info['archive_marks']), true)) {
self::save($data);
}
}
}
add_action('comicpress-handle_update_comicpress_options', 'ComicPressAnnotatedEntries::handle_update', 1, 10);

View File

@ -45,7 +45,7 @@ class ComicPressDBInterface {
/** /**
* Find the terminal post in a specific category. * Find the terminal post in a specific category.
*/ */
function get_terminal_post_in_categories($categories, $first = true, $count = false) { function get_terminal_post_in_categories($categories, $first = true, $count = false, $additional_parameters = array()) {
$this->_prepare_wp_query(); $this->_prepare_wp_query();
$count = $this->ensure_count($count); $count = $this->ensure_count($count);
@ -53,12 +53,19 @@ class ComicPressDBInterface {
if (!is_array($categories)) { $categories = array($categories); } if (!is_array($categories)) { $categories = array($categories); }
$sort_order = $first ? "asc" : "desc"; $sort_order = $first ? "asc" : "desc";
$terminal_comic_query = new WP_Query(); $terminal_comic_query = new WP_Query();
$terminal_comic_query->query(array(
if (isset($additional_parameters['post_status'])) {
if (is_array($additional_parameters['post_status'])) {
$additional_parameters['post_status'] = implode(',', $additional_parameters['post_status']);
}
}
$terminal_comic_query->query(array_merge(array(
'showposts' => $count, 'showposts' => $count,
'order' => $sort_order, 'order' => $sort_order,
'category__in' => $categories, 'category__in' => $categories,
'post_status' => 'publish' 'post_status' => 'publish'
)); ), $additional_parameters));
$result = false; $result = false;
@ -77,28 +84,45 @@ class ComicPressDBInterface {
/** /**
* Get the first comic in a category. * Get the first comic in a category.
*/ */
function get_first_post($categories, $reference_post = null, $count = false) { function get_first_post($categories, $reference_post = null, $count = false, $additional = array()) {
return $this->get_terminal_post_in_categories($categories, true, $count); return $this->get_terminal_post_in_categories($categories, true, $count, $additional);
} }
/** /**
* Get the last comic in a category. * Get the last comic in a category.
*/ */
function get_last_post($categories, $reference_post = null, $count = false) { function get_last_post($categories, $reference_post = null, $count = false, $additional = array()) {
return $this->get_terminal_post_in_categories($categories, false); return $this->get_terminal_post_in_categories($categories, false, $count, $additional);
}
function setup_clauses($additional) {
$clauses = array();
foreach (array_merge(array('post_type' => 'post', 'post_status' => 'publish'), $additional) as $field => $value) {
if (is_array($value)) {
foreach ($value as &$v) {
$v = "'${v}'";
}
$clauses[] = "AND p.${field} IN (" . join(", ", $value) . ")";
} else {
$clauses[] = "AND p.${field} = '${value}'";
}
}
return $clauses;
} }
/** /**
* Get the comic post adjacent to the current comic. * Get the comic post adjacent to the current comic.
* Wrapper around get_adjacent_post(). Don't unit test this method.
*/ */
function get_adjacent_post($categories, $next = false, $override_post = null, $count = false) { function get_adjacent_post($categories, $next = false, $override_post = null, $count = false, $additional = array()) {
global $wpdb, $post; global $wpdb, $post;
$count = $this->ensure_count($count); $count = $this->ensure_count($count);
$post_to_use = (!is_null($override_post)) ? $override_post : $post; $post_to_use = (!is_null($override_post)) ? $override_post : $post;
$clauses = $this->setup_clauses($additional);
$op = ($next ? '>' : '<'); $op = ($next ? '>' : '<');
$order = ($next ? 'ASC' : 'DESC'); $order = ($next ? 'ASC' : 'DESC');
$cats = implode(',', $categories); $cats = implode(',', $categories);
@ -106,46 +130,131 @@ class ComicPressDBInterface {
$query = $wpdb->prepare("SELECT p.* FROM $wpdb->posts AS p $query = $wpdb->prepare("SELECT p.* FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE p.post_date ${op} %s WHERE p.post_date ${op} %s"
AND p.post_type = 'post' . implode(" ", $clauses) . "
AND p.post_status = 'publish'
AND tt.taxonomy = 'category' AND tt.taxonomy = 'category'
AND tt.term_id IN (${cats}) AND tt.term_id IN (${cats})
ORDER BY p.post_date ${order} LIMIT %d", ORDER BY p.post_date ${order} LIMIT %d",
$post_to_use->post_date, $post_to_use->post_date,
$count); $count);
$query_key = 'comicpress_adjacent_post_' . md5($query); return $this->do_query($query, 'get_results', function($result, $query_key) use ($count) {
$result = wp_cache_get($query_key, 'counts'); if (!empty($result)) {
if ($count == 1) { $result = $result[0]; }
wp_cache_set($query_key, $result, 'counts');
return $result;
} else {
return ($count == 1) ? false : array();
}
});
}
function do_query($query, $retrieval_method, $callback) {
global $wpdb;
$query_key = 'comicpress-query' . md5($query);
$result = wp_cache_get($query_key, 'comicpress');
if ($result !== false) { if ($result !== false) {
return $result; return $result;
} }
$result = $wpdb->get_results($query); $result = $wpdb->{$retrieval_method}($query);
if (!empty($result)) { return $callback($result, $query_key);
if ($count == 1) { $result = $result[0]; }
wp_cache_set($query_key, $result, 'counts');
return $result;
} else {
return ($count == 1) ? false : array();
}
} }
/** /**
* Get the previous comic from the current one. * Get the previous comic from the current one.
*/ */
function get_previous_post($categories = null, $override_post = null, $count = false) { function get_previous_post($categories = null, $override_post = null, $count = false, $additional = array()) {
return $this->get_adjacent_post($categories, false, $override_post, $count); return $this->get_adjacent_post($categories, false, $override_post, $count, $additional);
} }
/** /**
* Get the next comic from the current one. * Get the next comic from the current one.
*/ */
function get_next_post($categories = null, $override_post = null, $count = false) { function get_next_post($categories = null, $override_post = null, $count = false, $additional = array()) {
return $this->get_adjacent_post($categories, true, $override_post, $count); return $this->get_adjacent_post($categories, true, $override_post, $count, $additional);
}
/**
* Get all posts in a particular category.
*/
function get_all_posts($categories = null, $additional = array()) {
if (!is_array($categories)) { $categories = array($categories); }
$sort_order = $first ? "asc" : "desc";
$all_comic_query = new WP_Query();
$all_comic_query->query(array_merge(array(
'nopaging' => true,
'order' => $sort_order,
'category__in' => $categories,
'post_status' => 'publish'
), $additional));
return $all_comic_query->posts;
}
/**
* Get a count of all available posts.
*/
// TODO Make the additional merges work for SQL queries
function count_all_posts($categories = null, $additional = array()) {
global $wpdb;
if (!is_array($categories)) { $categories = array($categories); }
$cats = implode(',', $categories);
$clauses = $this->setup_clauses($additional);
$query = $wpdb->prepare("SELECT count(p.ID) FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy = 'category'
AND tt.term_id IN (${cats})" .
implode(" ", $clauses));
return $this->do_query($query, 'get_var', function($result, $query_key) {
if (!empty($result)) {
wp_cache_set($query_key, $result, 'counts');
return $result;
} else {
return is_numeric($result) ? $result : false;
}
});
}
function get_post_by_index($categories = null, $index = 0, $additional = array()) {
global $wpdb;
if (!is_array($categories)) { $categories = array($categories); }
$cats = implode(',', $categories);
$clauses = $this->setup_clauses($additional);
$query = $wpdb->prepare("SELECT p.* FROM $wpdb->posts AS p
INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id
INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy = 'category'
AND tt.term_id IN (${cats})" .
implode(" ", $clauses) . "
ORDER BY p.post_date ASC
LIMIT ${index}, 1");
return $this->do_query($query, 'get_row', function($result, $query_key) {
if (!empty($result)) {
wp_cache_set($query_key, $result, 'counts');
return $result;
} else {
return false;
}
});
} }
function get_parent_child_category_ids() { function get_parent_child_category_ids() {
@ -163,5 +272,32 @@ class ComicPressDBInterface {
return $parent_child_categories; return $parent_child_categories;
} }
function clear_annotations() {
global $wpdb;
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", 'comicpress-annotation'));
}
function get_annotations($category) {
global $wpdb;
$query = $wpdb->prepare("SELECT pm.post_id, pm.meta_value
FROM $wpdb->postmeta pm
WHERE pm.meta_key = %s", 'comicpress-annotation');
$result = $wpdb->get_results($query);
$matching_annotations = array();
if (is_array($result)) {
foreach ($result as $row) {
if ($annotation = maybe_unserialize($row->meta_value)) {
$matching_annotations[$row->post_id] = $annotation[$category];
}
}
}
return $matching_annotations;
}
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }

View File

@ -3,7 +3,7 @@
require_once('ComicPressStoryline.inc'); require_once('ComicPressStoryline.inc');
class ComicPressTagBuilderFactory { class ComicPressTagBuilderFactory {
public $storyline, $dbi; public $storyline, $dbi, $default_dbparams = array();
public function __construct($dbi = null) { public function __construct($dbi = null) {
$this->storyline = new ComicPressStoryline(); $this->storyline = new ComicPressStoryline();
@ -40,13 +40,21 @@ class ComicPressTagBuilderFactory {
return $is_in; return $is_in;
} }
public function annotations($category) {
return $this->dbi->get_annotations($category);
}
public function find_file($name, $path = '', $categories = null) { public function find_file($name, $path = '', $categories = null) {
$comicpress = ComicPress::get_instance(); $comicpress = ComicPress::get_instance();
return $comicpress->find_file($name, $path, $categories); return $comicpress->find_file($name, $path, $categories);
} }
public function default_dbparams($params = array()) {
$this->default_dbparams = $params;
}
public function _new_comicpresstagbuilder($p, $s, $d) { public function _new_comicpresstagbuilder($p, $s, $d) {
return new ComicPressTagBuilder($p, $s, $d); return new ComicPressTagBuilder($p, $s, $d, $this->default_dbparams);
} }
public function media($index = null) { public function media($index = null) {
@ -101,13 +109,14 @@ class ComicPressTagBuilderFactory {
} }
class ComicPressTagBuilder { class ComicPressTagBuilder {
public $categories, $restrictions, $storyline, $dbi, $parent_post, $post, $category; public $categories, $restrictions, $storyline, $dbi, $parent_post, $post, $category, $dbparams;
public function __construct($parent_post, $storyline, $dbi) { public function __construct($parent_post, $storyline, $dbi, $dbparams = array()) {
$this->restrictions = array(); $this->restrictions = array();
$this->storyline = $storyline; $this->storyline = $storyline;
$this->dbi = $dbi; $this->dbi = $dbi;
$this->parent_post = $parent_post; $this->parent_post = $parent_post;
$this->dbparams = $dbparams;
} }
public function _setup_postdata($p) { public function _setup_postdata($p) {
@ -121,22 +130,24 @@ class ComicPressTagBuilder {
return new ComicPressComicPost($post); return new ComicPressComicPost($post);
} }
function setup($throw_exception_on_invalid = false) {
if (empty($this->post)) {
if ($throw_exception_on_invalid === true) {
throw new ComicPressException('You need to have retrieved a post for setup to work');
} else {
return false;
}
}
$this->_setup_postdata($this->post);
return $this->post;
}
// TODO filtered versions of template tags // TODO filtered versions of template tags
public function __call($method, $arguments) { public function __call($method, $arguments) {
$ok = false; $ok = false;
$return = $this; $return = $this;
switch ($method) { switch ($method) {
case 'setup':
if (empty($this->post)) {
if (isset($arguments[0])) {
throw new ComicPressException('You need to have retrieved a post for setup to work');
} else {
return false;
}
}
$this->_setup_postdata($this->post);
return $this->post;
case 'from': case 'from':
if (!isset($arguments[0])) { if (!isset($arguments[0])) {
throw new ComicPressException('Need to specify a post'); throw new ComicPressException('Need to specify a post');
@ -147,6 +158,12 @@ class ComicPressTagBuilder {
$this->parent_post = (object)$arguments[0]; $this->parent_post = (object)$arguments[0];
$ok = true; $ok = true;
break; break;
case 'dbparams':
if (!is_array($arguments[0])) {
throw new ComicPressException('dbparams requires an array');
}
$this->dbparams = $arguments[0];
break;
case 'current': case 'current':
if (isset($this->category)) { if (isset($this->category)) {
if (isset($arguments[0])) { if (isset($arguments[0])) {
@ -172,6 +189,9 @@ class ComicPressTagBuilder {
case 'previous': case 'previous':
case 'first': case 'first':
case 'last': case 'last':
case 'all':
case 'count':
case 'index':
if (isset($this->category)) { if (isset($this->category)) {
switch ($method) { switch ($method) {
case 'next': case 'next':
@ -184,6 +204,15 @@ class ComicPressTagBuilder {
case 'last': case 'last':
$id = end(array_keys($this->storyline->_structure)); $id = end(array_keys($this->storyline->_structure));
break; break;
case 'all':
return array_keys($this->storyline->_structure);
case 'count':
return count(array_keys($this->storyline->_structure));
case 'index':
if (!isset($arguments[0])) {
throw new Exception('You need to provide an index to retrieve.');
}
return array_slice(array_keys($this->storyline->_structure), (int)$arguments[0]);
} }
return isset($arguments[0]) ? get_category($id) : $id; return isset($arguments[0]) ? get_category($id) : $id;
} else { } else {
@ -198,7 +227,22 @@ class ComicPressTagBuilder {
$count = false; $count = false;
} }
$result = call_user_func(array($this->dbi, "get_${method}_post"), $this->storyline->build_from_restrictions($this->restrictions), $this->parent_post, $count); $restriction_categories = $this->storyline->build_from_restrictions($this->restrictions);
switch ($method) {
case 'all':
return $this->dbi->get_all_posts($restriction_categories, $this->dbparams);
case 'count':
return $this->dbi->count_all_posts($restriction_categories, $this->dbparams);
case 'index':
if (!isset($arguments[0])) {
throw new Exception('You need to provide an index to retrieve.');
}
return $this->dbi->get_post_by_index($restriction_categories, (int)$arguments[0], $this->dbparams);
default:
$result = call_user_func(array($this->dbi, "get_${method}_post"), $this->storyline->build_from_restrictions($this->restrictions), $this->parent_post, $count, $this->dbparams);
break;
}
if ($count > 1) { if ($count > 1) {
if (is_array($result)) { if (is_array($result)) {

View File

@ -12,7 +12,13 @@ class ComicPressBackendFilesystem extends ComicPressBackend {
$this->source_name = __('Filesystem', 'comicpress'); $this->source_name = __('Filesystem', 'comicpress');
} }
function _getimagesize($file) { return getimagesize($file); } function _getimagesize($file) {
if (file_exists($file)) {
return getimagesize($file);
} else {
return array(0, 0);
}
}
function dims($size = null) { function dims($size = null) {
$dims = array(); $dims = array();

View File

@ -0,0 +1,254 @@
<h3><?php _e('Archive Mark Editor', 'comicpress') ?></h3>
<div id="comicpress-archive-mark-editor" class="comicpress-holder">
<p>
<?php _e('
You can build a simple linear structure for your archive without needing to use multiple
categories. Simply move the slider up and down to find posts that you want to highlight,
mark it an annotation, and save. Remove annotations by clicking on the annotation and
clicking the Delete button.
') ?>
</p>
<label>
<?php _e('Category or Category Grouping to Search:') ?>
<select id="archive-category-search">
<?php foreach (array_keys($this->comicpress->comicpress_options['category_groupings']) as $category_group) { ?>
<option value="<?php echo $category_group ?>">(<?php _e('Grouping') ?>) <?php echo $category_group ?></option>
<?php } ?>
<?php foreach (array_keys($storyline->_structure) as $category_id) { ?>
<option value="<?php echo $category_id ?>">(<?php _e('Category') ?>) <?php echo get_cat_name($category_id) ?></option>
<?php } ?>
</select>
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
</label>
<div id="post-marks-loader">
<img src="<?php echo plugin_dir_url(realpath(dirname(__FILE__) . '/../')) . 'images/loader.gif' ?>" />
</div>
<div id="post-marks-ui">
<div id="post-marks-holder"></div>
<div id="post-slider"></div>
<div id="most-recent-post">Most Recent Post</div>
</div>
<div id="post-info">
<img width="120" />
<div id="annotation-info">
<h4></h4>
<a id="mark-annotation"></a>
<table class="form-table">
<tr>
<th width="25%" scope="row"><?php _e('Title:') ?></th>
<td width="75%"><input type="text" id="title" /></td>
</tr>
<tr>
<th scope="row"><?php _e('Description:') ?></th>
<td><textarea id="description"></textarea></td>
</tr>
</table>
</div>
</div>
<input type="hidden" name="cp[archive_marks]" id="archive-marks" />
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#post-info').hide();
$.cp = {
posts: {},
current_category: null,
get_posts: function() {
return $.cp.posts[$.cp.current_category];
}
};
// cp:show_marks
$(document).bind('cp:show_marks', function(e) {
$('#post-marks-holder').html('');
$.each($.cp.get_posts(), function(i, which) {
if (which.annotation) {
var marker = $('<a href="#">Mark</a>').
css({
top: ($('#post-slider').height() * i) / ($.cp.get_posts().length - 1)
}).click(function() {
$(document).trigger('cp:update_slider', [ ($.cp.get_posts().length - 1) - i ]);
return false;
});
$('#post-marks-holder').append(marker);
}
});
});
// cp:update_info_box
$(document).bind('cp:update_info_box', function(e, index) {
var which = $.cp.get_posts()[index];
$('#post-info h4').html(which.title + ' &mdash; ' + which.date);
var offset = $('#post-slider a').offset();
var info_offset = $('#post-slider').offset().top;
$('#post-info').css({
left: offset.left + 15,
top: Math.min(offset.top, info_offset + $('#post-slider').height() - $('#post-info').height() - 10)
});
$('#mark-annotation')[which.annotation ? 'addClass' : 'removeClass']('marked')
.text(
which.annotation ?
'Unmark this post as important' :
'Mark this post as important'
);
$.each(['title', 'description'], function(i, field) {
var node = $('#' + field);
if (which.annotation) {
$(node)
.val(which.annotation[field] ? which.annotation[field] : '')
.attr('disabled', '')
.removeClass('disabled', 200);
} else {
$(node)
.attr('disabled', 'disabled')
.addClass('disabled', 200);
}
});
$(document).trigger('cp:show_marks');
});
// cp:finalize_info_box
$(document).bind('cp:finalize_info_box', function(e, index) {
$(document).trigger('cp:update_info_box', index);
var which = $.cp.get_posts()[index];
$('#post-info img').attr('src', which.image);
});
// cp:toggle_annotation
$(document).bind('cp:toggle_annotation', function(e, index) {
var which = $.cp.get_posts()[index];
if (which.annotation) {
delete which.annotation;
} else {
which.annotation = {
annotated: true
};
}
$(document).trigger('cp:update_info_box', [ index ]);
$(document).trigger('cp:serialize_data');
});
// cp:update_field
$(document).bind('cp:update_field', function(e, index, field, value) {
var which = $.cp.get_posts()[index];
if (!which.annotation) {
which.annotation = {
annotated: true
};
}
which.annotation[field] = value;
$(document).trigger('cp:update_info_box', [ index ]);
$(document).trigger('cp:serialize_data');
});
// cp:serialize_data
$(document).bind('cp:serialize_data', function(e) {
var data = {};
$.each($.cp.posts, function(category, posts) {
data[category] = {};
$.each(posts, function(i, which) {
if (which.annotation) {
data[category][which.id] = which.annotation;
}
});
});
$('#archive-marks').val(JSON.stringify(data));
});
// cp:data_loaded
$(document).bind('cp:data_loaded', function(e, result) {
$('#post-marks-loader').hide();
$('#post-marks-ui').show();
var height = Math.max(
$.cp.get_posts().length * 3,
$('#post-info').height() + 100
);
$('#post-slider')
.slider('destroy')
.animate({height: height}, 250, function() {
$('#post-marks-holder').css({
height: $(this).height()
});
var max = $.cp.get_posts().length - 1;
$('#post-slider').slider({
orientation: 'vertical',
min: 0,
max: max,
slide: function(e, ui) {
$(document).trigger('cp:update_info_box', [ max - ui.value ]);
},
change: function(e, ui) {
$(document).trigger('cp:finalize_info_box', [ max - ui.value ]);
},
});
$(document).unbind('cp:update_slider').bind('cp:update_slider', function(e, value) {
$('#post-slider').slider('value', value);
});
$('#post-info').show();
$(document).trigger('cp:update_slider', [ $.cp.get_posts().length ]);
$('#mark-annotation').attr('href', '#').unbind('click').click(function() {
$(document).trigger('cp:toggle_annotation', [ max - $('#post-slider').slider('value') ]);
return false;
});
$.each(['title', 'description'], function(i, field) {
$('#' + field).val('').unbind('keyup').keyup(function() {
$(document).trigger('cp:update_field', [ max - $('#post-slider').slider('value'), field, $(this).val() ]);
});
});
$(document).trigger('cp:serialize_data');
});
});
// cp:load_category
$(document).bind('cp:load_category', function(e) {
$.cp.current_category = $('#archive-category-search').val();
if (!$.cp.posts[$.cp.current_category]) {
$.post(ComicPressAdmin.ajax_uri, {
'cp[_nonce]': ComicPressAdmin.nonce,
'cp[action]': 'retrieve-category-posts',
'cp[_action_nonce]': '<?php echo wp_create_nonce('comicpress-retrieve-category-posts') ?>',
'cp[category]': $.cp.current_category
}, function(result) {
$.cp.posts[$.cp.current_category] = result;
$(document).trigger('cp:data_loaded');
}, 'json');
} else {
$(document).trigger('cp:data_loaded');
}
});
$('#archive-category-search').change(function() {
$(document).trigger('cp:load_category');
});
$(document).trigger('cp:load_category');
});
</script>

View File

@ -6,6 +6,8 @@
<input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" /> <input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" />
<div id="comicpress-admin-holder"> <div id="comicpress-admin-holder">
<?php include('_annotation-editor.inc') ?>
<?php include('_storyline-order.inc') ?> <?php include('_storyline-order.inc') ?>
<h3><?php _e('Category Groups', 'comicpress') ?></h3> <h3><?php _e('Category Groups', 'comicpress') ?></h3>

View File

@ -288,3 +288,109 @@ tr.highlighted td {
.comicpress-admin-section h3 { .comicpress-admin-section h3 {
margin-top: 0 margin-top: 0
} }
#post-marks-ui {
overflow: hidden;
zoom: 1;
display: none;
padding: 10px;
}
#post-slider {
width: 10px;
border: solid #aaa 1px;
position: relative;
margin-top: 10px;
float: left;
display: inline
}
#post-marks-loader {
text-align: center
}
#post-marks-holder {
width: 60px;
margin-right: 10px;
position: relative;
float: left;
display: inline
}
#post-marks-holder a {
background: #622;
border: solid #a33 1px;
position: absolute;
width: 60px;
line-height: 16px;
font-size: 11px;
color: white;
margin-top: -5px;
padding: 2px;
text-decoration: none;
display: block;
}
.ui-slider-handle {
position: absolute;
z-index: 2;
height: 12px;
width: 12px;
left: -2px;
margin-bottom: -4px;
border: solid #888 1px;
border-radius: 2px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
background-color: #ccc;
}
#post-info {
position: absolute;
width: 50%;
border: solid #aaa 1px;
background: #f0f0f0;
padding: 0.5em;
border-radius: 0.5em;
-moz-border-radius: 0.5em;
-webkit-border-radius: 0.5em;
display: none;
overflow: hidden;
zoom: 1
}
#post-info img {
float: left;
display: inline;
margin-right: 0.3em
}
#post-info label {
display: block;
}
#mark-annotation {
color: red;
}
#mark-annotation.marked {
color: green;
}
#annotation-info {
margin-left: 130px
}
#annotation-info input, #annotation-info textarea {
width: 100%
}
#annotation-info h4 {
margin: 0.25em 0;
}
#most-recent-post {
padding: 0.2em 0 0 10%;
border-top: solid #aaa 1px;
font-style: italic;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 B

BIN
images/loader.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

22
js/jquery-ui-1.7.2.slider.min.js vendored Executable file

File diff suppressed because one or more lines are too long

481
js/json2.js Normal file
View File

@ -0,0 +1,481 @@
/*
http://www.JSON.org/json2.js
2009-09-29
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
See http://www.JSON.org/js.html
This code should be minified before deployment.
See http://javascript.crockford.com/jsmin.html
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
NOT CONTROL.
This file creates a global JSON object containing two methods: stringify
and parse.
JSON.stringify(value, replacer, space)
value any JavaScript value, usually an object or array.
replacer an optional parameter that determines how object
values are stringified for objects. It can be a
function or an array of strings.
space an optional parameter that specifies the indentation
of nested structures. If it is omitted, the text will
be packed without extra whitespace. If it is a number,
it will specify the number of spaces to indent at each
level. If it is a string (such as '\t' or '&nbsp;'),
it contains the characters used to indent at each level.
This method produces a JSON text from a JavaScript value.
When an object value is found, if the object contains a toJSON
method, its toJSON method will be called and the result will be
stringified. A toJSON method does not serialize: it returns the
value represented by the name/value pair that should be serialized,
or undefined if nothing should be serialized. The toJSON method
will be passed the key associated with the value, and this will be
bound to the value
For example, this would serialize Dates as ISO strings.
Date.prototype.toJSON = function (key) {
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
return this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z';
};
You can provide an optional replacer method. It will be passed the
key and value of each member, with this bound to the containing
object. The value that is returned from your method will be
serialized. If your method returns undefined, then the member will
be excluded from the serialization.
If the replacer parameter is an array of strings, then it will be
used to select the members to be serialized. It filters the results
such that only members with keys listed in the replacer array are
stringified.
Values that do not have JSON representations, such as undefined or
functions, will not be serialized. Such values in objects will be
dropped; in arrays they will be replaced with null. You can use
a replacer function to replace those with JSON values.
JSON.stringify(undefined) returns undefined.
The optional space parameter produces a stringification of the
value that is filled with line breaks and indentation to make it
easier to read.
If the space parameter is a non-empty string, then that string will
be used for indentation. If the space parameter is a number, then
the indentation will be that many spaces.
Example:
text = JSON.stringify(['e', {pluribus: 'unum'}]);
// text is '["e",{"pluribus":"unum"}]'
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
text = JSON.stringify([new Date()], function (key, value) {
return this[key] instanceof Date ?
'Date(' + this[key] + ')' : value;
});
// text is '["Date(---current time---)"]'
JSON.parse(text, reviver)
This method parses a JSON text to produce an object or array.
It can throw a SyntaxError exception.
The optional reviver parameter is a function that can filter and
transform the results. It receives each of the keys and values,
and its return value is used instead of the original value.
If it returns what it received, then the structure is not modified.
If it returns undefined then the member is deleted.
Example:
// Parse the text. Values that look like ISO date strings will
// be converted to Date objects.
myData = JSON.parse(text, function (key, value) {
var a;
if (typeof value === 'string') {
a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
if (a) {
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
+a[5], +a[6]));
}
}
return value;
});
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
var d;
if (typeof value === 'string' &&
value.slice(0, 5) === 'Date(' &&
value.slice(-1) === ')') {
d = new Date(value.slice(5, -1));
if (d) {
return d;
}
}
return value;
});
This is a reference implementation. You are free to copy, modify, or
redistribute.
*/
/*jslint evil: true, strict: false */
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
lastIndex, length, parse, prototype, push, replace, slice, stringify,
test, toJSON, toString, valueOf
*/
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
if (!this.JSON) {
this.JSON = {};
}
(function () {
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
return isFinite(this.valueOf()) ?
this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap,
indent,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
rep;
function quote(string) {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ?
'"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' :
'"' + string + '"';
}
function str(key, holder) {
// Produce a string from holder[key].
var i, // The loop counter.
k, // The member key.
v, // The member value.
length,
mind = gap,
partial,
value = holder[key];
// If the value has a toJSON method, call it to obtain a replacement value.
if (value && typeof value === 'object' &&
typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
// What happens next depends on the value's type.
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
// JSON numbers must be finite. Encode non-finite numbers as null.
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.
return String(value);
// If the type is 'object', we might be dealing with an object or an array or
// null.
case 'object':
// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.
if (!value) {
return 'null';
}
// Make an array to hold the partial results of stringifying this object value.
gap += indent;
partial = [];
// Is the value an array?
if (Object.prototype.toString.apply(value) === '[object Array]') {
// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
v = partial.length === 0 ? '[]' :
gap ? '[\n' + gap +
partial.join(',\n' + gap) + '\n' +
mind + ']' :
'[' + partial.join(',') + ']';
gap = mind;
return v;
}
// If the replacer is an array, use it to select the members to be stringified.
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
k = rep[i];
if (typeof k === 'string') {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
v = partial.length === 0 ? '{}' :
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
mind + '}' : '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON.stringify !== 'function') {
JSON.stringify = function (value, replacer, space) {
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.
var i;
gap = '';
indent = '';
// If the space parameter is a number, make an indent string containing that
// many spaces.
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
// If the space parameter is a string, it will be used as the indent string.
} else if (typeof space === 'string') {
indent = space;
}
// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return str('', {'': value});
};
}
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON.parse !== 'function') {
JSON.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.
var j;
function walk(holder, key) {
// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.
// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function' ?
walk({'': j}, '') : j;
}
// If the text is not JSON parseable, then a SyntaxError is thrown.
throw new SyntaxError('JSON.parse');
};
}
}());

View File

@ -0,0 +1,55 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('ComicPressAnnotatedEntries.inc');
class ComicPressAnnotatedEntriesTest extends PHPUnit_Framework_TestCase {
function testUpdateEntries() {
$dbi = $this->getMock('ComicPressDBInterface', array('clear_annotations'));
$dbi->expects($this->once())->method('clear_annotations');
wp_insert_post(array('ID' => 1));
wp_insert_post(array('ID' => 2));
wp_insert_post(array('ID' => 3));
ComicPressAnnotatedEntries::save(array(
'group' => array(
'1' => array(
'annotated' => true
)
),
'group2' => array(
'1' => array(
'title' => 'Annotation Title 2',
'description' => 'Annotation Description 2',
'annotated' => true
),
'2' => array(
'title' => 'Annotation Title 3',
'description' => 'Annotation Description 3',
'annotated' => true
),
)
), $dbi);
$this->assertEquals(array(
'group' => array(
'annotated' => true,
),
'group2' => array(
'annotated' => true,
'title' => 'Annotation Title 2',
'description' => 'Annotation Description 2'
),
), get_post_meta(1, 'comicpress-annotation', true));
$this->assertEquals(array(
'group2' => array(
'annotated' => true,
'title' => 'Annotation Title 3',
'description' => 'Annotation Description 3'
),
), get_post_meta(2, 'comicpress-annotation', true));
}
}

View File

@ -104,6 +104,13 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
), ),
array('get_first_post', array(1,2,3,4,5), $p) array('get_first_post', array(1,2,3,4,5), $p)
), ),
array(
array(
array('in', 'all'),
array('all')
),
array('get_all_posts', array(1,2,3,4,5))
),
); );
} }