resolve conflict

This commit is contained in:
John Bintz 2009-11-10 21:35:38 -05:00
commit 996e64eece
32 changed files with 1154 additions and 1342 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
*~
.directory
.buildpath
.project
.settings/

37
application.php Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes() ?>>
<?php get_header(); ?>
<body <?php if (function_exists('body_class')) { body_class(); } ?>>
<div id="page"><!-- Defines entire site width - Ends in Footer -->
<div id="header">
<h1><a href="<?php echo get_settings('home') ?>"><?php bloginfo('name') ?></a></h1>
<div class="description"><?php bloginfo('description') ?></div>
</div>
<div id="menubar">
<ul id="menu">
<li><a href="<?php bloginfo('url') ?>">Home</a></li>
<?php wp_list_pages('sort_column=menu_order&depth=4&title_li=') ?>
<li><a href="<?php bloginfo('rss2_url') ?>">Subscribe</a></li>
</ul>
<br class="clear" />
</div>
<?php echo $content ?>
<br class="clear" />
<div id="footer">
<p>
<?php bloginfo('name') ?> is powered by <a href="http://wordpress.org/">WordPress</a> with <a href="http://comicpress.org/">ComicPress</a>
| Subscribe: <a href="<?php bloginfo('rss2_url') ?>">RSS Feed</a>
<!-- <?php echo get_num_queries() ?> queries. <?php timer_stop(1) ?> seconds. -->
</p>
</div>
</div>
<?php wp_footer() ?>
</body>
<?php get_footer(); ?>
</html>

View File

@ -1,44 +1,38 @@
<?php
require_once(dirname(__FILE__) . '/ComicPressComicPost.inc');
/**
* The core functions of ComicPress.
*/
class ComicPress {
var $comicpress_options = array(
'comic_category_id' => 1,
'comic_dimensions' => '760x',
'rss_dimensions' => '350x',
'archive_dimensions' => '125x',
'mini_dimensions' => '100x',
'category_order' => false,
'blogpost_count' => 10,
'comic_space' => 'comic_only',
'category_usage' => 'storyline',
'layout' => 'classic.inc',
'helpers' => array(),
'addons' => array(),
'storyline_order' => ''
'storyline_order' => '',
'subattachment_types' => array(
'rss' => 'RSS',
'archive' => 'Archive',
'mini' => 'Mini Thumb'
)
);
var $additional_stylesheets = array();
var $additional_javascripts = array();
var $comic_post_attachments_cache = array();
var $category_tree = array();
var $partial_paths = array();
var $layouts = null;
var $backends = array('ComicPressBackendAttachment');
function &get_instance() {
static $instance;
if (!$instance) {
$instance = array(new ComicPress());
}
return $instance[0];
}
/**
* Load ComicPress options.
*/
@ -48,7 +42,7 @@ class ComicPress {
$this->comicpress_options = array_merge($this->comicpress_options, $result);
}
}
/**
* Save ComicPress options.
*/
@ -63,24 +57,16 @@ class ComicPress {
*/
function init() {
$this->load();
add_action('wp_head', array(&$this, 'wp_head'));
add_filter('comicpress_nav', array(&$this, 'comicpress_nav'), 10, 2);
add_filter('comicpress_nav_fields', array(&$this, 'comicpress_nav_fields'));
if (current_user_can('edit_themes')) {
if (!empty($this->comicpress_options['helpers'])) {
if (isset($this->comicpress_options['helpers']['show_partials_info'])) {
add_filter('comicpress_partial', array(&$this, 'comicpress_partial'), 10, 2);
add_action('wp_head', array(&$this, 'setup_comicpress_partial'));
}
add_action('wp_footer', array(&$this, 'announce_activated_helpers'));
}
}
add_filter('intermediate_image_sizes', array(&$this, 'intermediate_image_sizes'));
add_filter('editor_max_image_size', array(&$this, 'editor_max_image_size'), 10, 2);
foreach (array('comic', 'rss', 'archive', 'mini') as $size) {
list($w, $h) = explode("x", $this->comicpress_options["${size}_dimensions"]);
update_option("${size}_size_w", $w);
@ -93,230 +79,85 @@ class ComicPress {
return array_merge($sizes, array('comic', 'rss', 'archive', 'mini'));
}
function needs_storyline_nav() {
return (count($this->category_tree) > 1) && ($this->comicpress_options['category_usage'] == "storyline");
}
function is_multicomic() {
return $this->comicpress_options['category_usage'] == "multicomic";
}
function comicpress_nav($type, $content) {
return $type;
}
function comicpress_nav_fields($nav_fields) {
$nav_fields = array(
'first' => '&lsaquo;&lsaquo; ' . __('First', 'comicpress'),
'previous' => '&lsaquo; ' . __('Previous', 'comicpress'),
'next' => __('Next', 'comicpress') . ' &rsaquo;',
'last' => __('Last', 'comicpress') . ' &rsaquo;&rsaquo;'
);
if ($this->needs_storyline_nav()) {
$nav_fields = array_merge(
array('prior' => '&lsaquo;&lsaquo; ' . __('Prior Storyline', 'comicpress')),
$nav_fields,
array('upcoming' => __('Upcoming Storyline', 'comicpress') . ' &rsaquo;&rsaquo;')
);
}
return $nav_fields;
function editor_max_image_size($current_max, $size) {
if (isset($this->comicpress_options["${size}_dimensions"])) {
list($width, $height) = explode('x', $this->comicpress_options["${size}_dimensions"]);
$current_max = array(intval($width), intval($height));
}
return $current_max;
}
function wp_head() {
foreach ($this->additional_stylesheets as $uri) { ?>
<link rel="stylesheet" href="<?php echo get_template_directory_uri() . $uri ?>" type="text/css" />
<?php }
foreach ($this->additional_javascripts as $uri) { ?>
<script type="text/javascript" src="<?php echo get_template_directory_uri() . $uri ?>"></script>
<?php }
}
function announce_activated_helpers() {
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
}
function setup_comicpress_partial() { ?>
<style type="text/css">
.partial-helper {
position: absolute;
z-index: 100;
padding: 4px;
border: solid #333 1px;
background-color: #99d;
opacity: 0.2;
-moz-opacity: 0.2;
-khtml-opacity: 0.2;
zoom: 1;
cursor: crosshair
}
.partial-helper:hover {
opacity: 1;
-moz-opacity: 1;
-khtml-opacity: 1;
}
</style>
<!--[if IE gte 6]>
<style type="text/css">
.partial-helper { filter: alpha(opacity=20); }
.partial-helper:hover { filter: alpha(opacity=100); }
</style>
<![endif]-->
<?php }
function comicpress_partial($content, $target) {
return '<div class="partial-helper">' . str_replace(get_template_directory() . DIRECTORY_SEPARATOR, '', $target) . '</div>' . $content;
}
/**
* Get the path to a partial.
* @param array $partials The partials to search for in each path.
* @return string|boolean The partial path to use, or false if no matches.
*/
function get_partial_path($partials) {
foreach ($partials as $partial) {
foreach ($this->partial_paths as $path) {
$target = $path . '/' . $partial . '.inc';
if (file_exists($target)) {
return $target;
}
}
}
return false;
}
function get_options_partial($partials) {
foreach ($partials as $partial) {
foreach ($this->partial_paths as $path) {
$target = str_replace(get_template_directory() . DIRECTORY_SEPARATOR, '', $path) . DIRECTORY_SEPARATOR . $partial;
if (isset($this->comicpress_options['override_partials'][$target])) {
return array($target, $this->comicpress_options['override_partials'][$target]);
}
}
}
return false;
}
/**
* Gather blog posts for the given index page.
*/
function get_index_blog_posts_query() {
global $post, $paged;
$t = $post;
$wp_query = new WP_Query();
$wp_query->query(
'showposts=' .
'showposts=' .
(int)$this->comicpress_options['blogpost_count'] .
'&cat=-' .
$this->comicpress_options['comic_category_id'] .
'&cat=-' .
$this->comicpress_options['comic_category_id'] .
'&paged=' .
$paged
);
return $wp_query;
}
function _glob($pattern) { return glob($pattern); }
function _file_get_contents($file) { return file_get_contents($file); }
function get_layout_choices() {
if (!is_array($this->layouts)) {
$this->layouts = array();
foreach ($this->_glob(get_template_directory() . '/layouts/*') as $file) {
$content = $this->_file_get_contents($file);
$basename = pathinfo($file, PATHINFO_BASENAME);
foreach (array(
"Layout Name", "Sidebars"
) as $field) {
if (preg_match('#/\*.*' . $field . ': ([^\n]+).*\*/#s', $content, $matches) > 0) {
if (!is_array($this->layouts[$basename])) {
$this->layouts[$basename] = array();
}
$this->layouts[$basename][$field] = $matches[1];
}
}
}
}
return $this->layouts;
}
function get_previous_next_categories($category_id) {
$prev_next_categories = array();
for ($i = 0, $il = count($this->category_tree); $i < $il; ++$i) {
$parts = explode("/", $this->category_tree[$i]);
if (count($parts) > 2) {
if (end($parts) == $category_id) {
while (count($parts) > 2) {
foreach (array(
'previous' => -1,
'next' => 1
) as $key => $direction) {
$index = $i;
while (isset($this->category_tree[$index])) {
$index += $direction;
if (isset($this->category_tree[$index])) {
$compare_parts = explode("/", $this->category_tree[$index]);
if (count($compare_parts) == count($parts)) {
$target_category = array_pop($compare_parts);
$parent_category = array_pop($compare_parts);
/**
* Search a path for directories named after the slugs provided.
* @param array $categories A list of category slugs going from child -> parent -> root.
* @param string $path The path to search.
* @return array All matching paths.
*/
function category_search($categories, $path) {
$path = trailingslashit($path);
$all_categories = array_reverse($categories);
$all_paths = array();
while (count($all_categories) > 0) {
$target = $path . implode('/', $all_categories);
if (is_dir($target)) { $all_paths[] = $target; }
array_pop($all_categories);
}
return array_reverse($all_paths);
}
if (!isset($prev_next_categories[$parent_category])) {
$prev_next_categories[$parent_category] = array();
}
$prev_next_categories[$parent_category][$key] = $target_category;
}
}
}
}
array_pop($parts);
}
}
}
}
return $prev_next_categories;
}
function get_sorted_post_categories($override_post = null) {
global $post;
$post_to_use = (!empty($override_post)) ? $override_post : $post;
$categories = wp_get_post_categories($post_to_use->ID);
$sorted_categories = array();
foreach ($this->category_tree as $node) {
$category_id = end(explode("/", $node));
if (in_array($category_id, $categories)) {
$sorted_categories[] = $category_id;
}
}
return $sorted_categories;
}
function _is_dir($dir) { return is_dir($dir); }
function setup_multicomic_partial_paths($post_id) {
$this->partial_paths = array();
$category_ids = wp_get_post_categories($post_id);
if (is_array($category_ids)) {
foreach ($category_ids as $id) {
$category = get_category($id);
if (!empty($category)) {
if ($this->_is_dir($target = get_template_directory() . '/subthemes/' . $category->slug)) {
$this->partial_paths[] = $target;
}
}
}
}
}
/**
* Recursively search a particular template directory for a specified file, limiting the search to the provided categories.
* @param string $name The name of the file with no path information.
* @param string $path The path within the template directories to start the search.
* @param attay $categories The child -> root category slugs to search within the specified path. If not provided, retrieve from current post.
* @return string|boolean The path to the file, for false if not found.
*/
function find_file($name, $path = '', $categories = null) {
global $post;
if (!is_array($categories)) {
$comic_post = new ComicPressComicPost($post);
$categories = $comic_post->find_parents();
}
foreach (array(get_stylesheet_directory(), get_template_directory()) as $dir) {
$dir = trailingslashit($dir) . $path;
$dirs_to_search = $this->category_search($categories, $dir);
$dirs_to_search[] = $dir;
foreach ($dirs_to_search as $category_path) {
$target = trailingslashit($category_path) . $name;
if (file_exists($target)) {
return $target;
}
}
}
return false;
}
}
?>

View File

@ -7,7 +7,7 @@ class ComicPressAdmin {
*/
function init() {
$this->comicpress = &ComicPress::get_instance();
add_action('admin_menu', array(&$this, 'admin_menu'));
add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2);
@ -39,10 +39,10 @@ class ComicPressAdmin {
. ']" value="'
. $index
. '" /></label>';
return $content;
}
function comicpress_display_attached_images($content, $post_id) {
$content = '<form method="post">'
. '<input type="hidden" name="cp[_nonce]" value="'
@ -56,7 +56,7 @@ class ComicPressAdmin {
. __('Change image ordering', 'comicpress')
. '" />'
. '</form>';
return $content;
}
@ -70,18 +70,18 @@ class ComicPressAdmin {
if (strpos($pagenow, "post") === 0) {
add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low");
wp_enqueue_script('cp-ordering', get_stylesheet_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous', 'scriptaculous-slider'));
wp_enqueue_style('cp-admin', get_stylesheet_directory_uri() . '/css/cp-admin.css');
wp_enqueue_script('cp-ordering', get_template_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous', 'scriptaculous-slider'));
wp_enqueue_style('cp-admin', get_template_directory_uri() . '/css/cp-admin.css');
add_action('admin_footer', array(&$this, 'admin_footer'));
}
if ($plugin_page == 'comicpress/render_admin') {
wp_enqueue_style('cp-admin', get_stylesheet_directory_uri() . '/css/cp-admin.css');
wp_enqueue_script('cp-admin', get_stylesheet_directory_uri() . '/js/Storyline.js', array('prototype', 'scriptaculous'));
wp_enqueue_style('cp-admin', get_template_directory_uri() . '/css/cp-admin.css');
wp_enqueue_script('cp-admin', get_template_directory_uri() . '/js/Storyline.js', array('prototype', 'scriptaculous'));
}
if (strpos($pagenow, "media-upload") === 0) {
wp_enqueue_script('cp-media', get_stylesheet_directory_uri() . '/js/MediaUpload.js', array('prototype'));
if (strpos($pagenow, "-upload") !== false) {
wp_enqueue_script('cp-media', get_template_directory_uri() . '/js/MediaUpload.js', array('prototype'));
}
}
@ -118,7 +118,7 @@ class ComicPressAdmin {
. $label
. '</label>';
}
$form_fields['comic_image_type'] = array(
'label' => __("Comic Image Type", 'comicpress'),
'input' => 'html',
@ -134,7 +134,7 @@ class ComicPressAdmin {
. '</em>'
);
}
return $form_fields;
}
@ -143,14 +143,13 @@ class ComicPressAdmin {
*/
function render_admin() {
$nonce = wp_create_nonce('comicpress');
$root_categories = $this->get_root_categories();
$storyline = new ComicPressStoryline();
$storyline->normalize();
$storyline->read_from_options();
include(dirname(__FILE__) . '/partials/options-admin.inc');
include(dirname(__FILE__) . '/partials/options-admin.inc');
}
function _render_admin_storyline_tree($node, $parent_id = "0") {
foreach ($node as $category_id => $children) {
$category = get_category($category_id);
@ -164,7 +163,7 @@ class ComicPressAdmin {
echo '</div>';
}
}
/**
* Render the comic image ordering interface.
*/
@ -173,81 +172,33 @@ class ComicPressAdmin {
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; }
$comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID));
$ordering = $comic_post->normalize_comic_image_ordering();
$ordering = $comic_post->normalize_ordering();
if (is_array($ordering)) {
$nonce = wp_create_nonce('comicpress');
$zoom_level = 40;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
if (is_array($comicpress_meta)) {
if (isset($comicpress_meta['zoom_level'])) {
$zoom_level = floor($comicpress_meta['zoom_level']);
}
}
}
// from wp-admin/includes/media.php O_o
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image&amp;TB_iframe=true");
if ($is_ajax === true) {
include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc');
} else {
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
}
}
}
/**
* Get all categories with a parent ID of 0.
* @return array All root categories.
*/
function get_root_categories() {
$root_categories = array();
foreach (get_all_category_ids() as $id) {
$category = get_category($id);
if (!empty($category)) {
if ($category->parent == 0) {
$root_categories[] = $category;
$nonce = wp_create_nonce('comicpress');
$zoom_level = 40;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
if (is_array($comicpress_meta)) {
if (isset($comicpress_meta['zoom_level'])) {
$zoom_level = floor($comicpress_meta['zoom_level']);
}
}
}
return $root_categories;
}
/**
* Create &lt;option&gt; elements for each of the provided categories.
* @param array $categories The categories to display as either IDs or category objects.
* @param int $selected_id The category to mark as selected.
* @return string The category options as HTML.
*/
function create_category_options($categories, $selected_id) {
$output = array();
if (is_array($categories)) {
$final_categories = array();
foreach ($categories as $category) {
if (is_numeric($category)) {
$result = get_category($category);
if (!(is_a($result, "WP_Error") || empty($result))) {
$final_categories[] = $result;
}
}
if (is_object($category)) {
$final_categories[] = $category;
}
}
// from wp-admin/includes/media.php O_o
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&amp;type=image&amp;TB_iframe=true");
foreach ($final_categories as $category) {
$output[] = '<option value="' . $category->term_id . '"' . (($category->term_id == $selected_id) ? ' selected="selected"' : '') . '>' . $category->name . '</option>';
}
if ($is_ajax === true) {
include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc');
} else {
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
}
return implode("\n", $output);
}
/**
* Create a dimension selector.
* @param string $root The field name root.
@ -256,7 +207,7 @@ class ComicPressAdmin {
*/
function create_dimension_selector($root, $dimension) {
$output = array();
$parts = explode("x", $dimension);
foreach (array(
'width' => __('Width', 'comicpress'),
@ -264,7 +215,7 @@ class ComicPressAdmin {
) as $id => $name) {
$dim = array_shift($parts);
if (!empty($dim) && !is_numeric($dim)) { $dim = ""; }
$output[] = '<label>' . $name . ': <input type="text" name="' . $root . '[' . $id . ']" value="' . $dim . '" size="4" />px</label><br />';
$output[] = '<label>' . $name . ': <input type="text" name="' . $root . '[' . $id . ']" value="' . $dim . '" size="4" />px</label><br />';
}
return implode("\n", $output);
}
@ -283,7 +234,7 @@ class ComicPressAdmin {
function handle_update_attachments() {
foreach ($_POST['attachments'] as $post_id => $settings) {
if (isset($settings['comic_image_type'])) {
update_post_meta($post_id, 'comic_image_type', $settings['comic_image_type']);
update_post_meta($post_id, 'comic_image_type', $settings['comic_image_type']);
}
if (isset($settings['auto_attach']) && isset($settings['post_parent'])) {
$media_post = get_post($post_id);
@ -292,7 +243,7 @@ class ComicPressAdmin {
}
}
}
/**
* Update ComicPress options.
*/
@ -303,14 +254,6 @@ class ComicPressAdmin {
foreach ($this->comicpress->comicpress_options as $option => $value) {
if (isset($info[$option])) {
switch ($option) {
case 'comic_category_id':
if (is_numeric($info[$option])) {
$result = get_category($info[$option]);
if (!(is_a($result, 'WP_Error') || empty($result))) {
$this->comicpress->comicpress_options[$option] = $info[$option];
}
}
break;
case 'comic_dimensions':
case 'rss_dimensions':
case 'archive_dimensions':
@ -330,20 +273,12 @@ class ComicPressAdmin {
}
}
}
if ($is_valid) {
$this->comicpress->comicpress_options[$option] = implode("x", $dim_parts);
}
}
break;
case 'blogpost_count':
$this->comicpress->comicpress_options[$option] = (int)$info[$option];
break;
case 'comic_space':
case 'category_usage':
case 'layout';
$this->comicpress->comicpress_options[$option] = $info[$option];
break;
case 'helpers':
case 'addons':
foreach ($info[$option] as $type => $set) {
@ -366,9 +301,9 @@ class ComicPressAdmin {
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
$j = new Moxiecode_JSON();
return $j->decode($string);
}
}
}
function handle_update_comic_ordering() {
if (is_numeric($_POST['post_ID'])) {
if ($post = get_post($_POST['post_ID'])) {
@ -378,17 +313,10 @@ class ComicPressAdmin {
}
}
function handle_update_override_partial($info) {
switch ($info['action']) {
case __('Update partial', 'comicpress'):
$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']]);
break;
}
}
/**
* Update the zoom slider info.
* @param $info The browser input.
*/
function handle_update_zoom_slider($info) {
$this->is_ajax = true;
@ -436,7 +364,7 @@ class ComicPressAdmin {
}
}
}
/**
* Create the dropdown for choosing a layout.
*/

View File

@ -0,0 +1,17 @@
<?php
class ComicPressBackend {
function _embed_image($size) {
$extras = array();
if (($dims = $this->dims($size)) !== false) {
$extras = array_merge($extras, $dims);
}
foreach ($extras as $field => $value) {
$extras[] = "${field}=\"${value}\"";
unset($extras[$field]);
}
$output = sprintf('<img src="%s" alt="%s" title="%s" %s />', $this->url(), $this->alt(), $this->title(), implode(" ", $extras));
return apply_filters('comicpress_embed_image', $output, $this);
}
}

View File

@ -8,17 +8,19 @@ class ComicPressComicPost {
if (!is_null($post)) { $this->post = $post; }
}
function get_comic_image_attachments() {
if (is_null($this->attachments)) {
$this->attachments = get_children(array(
'post_parent' => $this->post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image'
));
}
return $this->attachments;
/**
* TODO normalize the attachments
* @return unknown_type
*/
function get_attachments() {
$comicpress = ComicPress::get_instance();
$attachments = array();
foreach ($comicpress->backends as $backend) {
$attachments = array_merge($attachments, call_user_func(array($backend, 'generate_from_post'), $this->post));
}
return $attachments;
}
/**
* Display all the attached images.
*/
@ -33,19 +35,19 @@ class ComicPressComicPost {
if (get_post_meta($attachment_id, "comic_image_type", true) == $type) {
$attachment = get_post($attachment_id);
$title = (!empty($attachment->post_excerpt) ? $attachment->post_excerpt : $attachment->post_title);
$url = wp_get_attachment_url($attachment->ID, '');
$sizes = image_downsize($attachment->ID, $size_type);
if ($sizes) {
$url = $sizes[0];
}
$output[] = apply_filters('comicpress_attached_image',
$output[] = apply_filters('comicpress_attached_image',
sprintf($format, $this->get_comic_img_tag($url, $size_type, array('title' => $title))),
$attachment_id,
$i++);
$found = true;
if (!is_null($limit)) {
if (--$limit == 0) { break; }
}
@ -58,7 +60,7 @@ class ComicPressComicPost {
return $found;
}
function _display_type($types, $format, $single = false) {
$target_type = reset($types);
foreach ($types as $type) {
@ -67,7 +69,7 @@ class ComicPressComicPost {
}
}
}
function display_comics($format) { $this->_display_type(array('comic'), $format); }
function display_archive($format) { $this->_display_type(array('archive'. 'comic'), $format, true); }
function display_rss($format) { $this->_display_type(array('rss'. 'comic'), $format); }
@ -77,12 +79,16 @@ class ComicPressComicPost {
*/
function get_comic_img_tag($url, $type, $additional_parameters = array()) {
$dimensions = array();
if (isset($this->comicpress->comicpress_options["${type}_dimensions"])) {
list($width, $height) = explode("x", $this->comicpress->comicpress_options["${type}_dimensions"]);
$parts = explode("x", $this->comicpress->comicpress_options["${type}_dimensions"]);
switch (count($parts)) {
case 1: list($width) = $parts; break;
case 2: list($width, $height) = $parts; break;
}
$dimensions = compact('width', 'height');
}
$output = '<img src="' . $url . '" ';
foreach (array('width', 'height') as $field) {
if (!empty($dimensions[$field])) {
@ -91,11 +97,11 @@ class ComicPressComicPost {
}
if (is_array($additional_parameters)) {
foreach ($additional_parameters as $parameter => $value) {
$output .= $parameter . '="' . $value . '" ';
$output .= $parameter . '="' . $value . '" ';
}
}
$output .= "/>";
return $output;
}
@ -103,63 +109,74 @@ class ComicPressComicPost {
* Normalize the ordering of comic images in this post.
* If images have beed added or removed, intelligently update the metadata.
*/
function normalize_comic_image_ordering() {
if (is_array($this->get_comic_image_attachments())) {
$ordering_by_type = array();
$ordering_types = get_post_meta($this->post->ID, 'comic_ordering', true);
$comic_image_ordering = array();
$found_post_ids = array();
if (!empty($ordering_types)) {
foreach ($ordering_types as $type => $post_ids) {
$comic_image_ordering[$type] = array();
foreach ($post_ids as $ordering_post_id) {
foreach ($this->get_comic_image_attachments() as $attachment) {
if (!isset($found_post_ids[$attachment->ID])) {
if ($attachment->ID == $ordering_post_id) {
$comic_image_ordering[$type][] = $attachment->ID;
$found_post_ids[$ordering_post_id] = true;
}
}
}
}
}
function normalize_ordering() {
$attachments = $this->get_attachments();
if (is_array($attachments)) {
$new_ordering = array();
$current_ordering = get_post_meta($this->post->ID, 'image-ordering', true);
if (!is_array($current_ordering)) { $current_ordering = array(); }
$all_current_ids = array();
foreach ($current_ordering as $key => $properties) {
$all_current_ids[$key] = true;
if (isset($properties['children'])) {
foreach ($properties['children'] as $type => $kids) {
$all_current_ids = array_merge($all_current_ids, $kids);
}
}
}
$remaining_posts_to_sort = array();
foreach ($this->get_comic_image_attachments() as $attachment) {
$comic_image_type = get_post_meta($attachment->ID, 'comic_image_type', true);
if (!empty($comic_image_type)) {
if (!isset($found_post_ids[$attachment->ID])) {
if (!isset($remaining_posts_to_sort[$comic_image_type])) {
$remaining_posts_to_sort[$comic_image_type] = array();
}
$remaining_posts_to_sort[$comic_image_type][] = $attachment->ID;
}
}
}
foreach ($remaining_posts_to_sort as $type => $posts) {
usort($remaining_posts_to_sort[$type], array(&$this, 'sort_remaining_comic_images'));
}
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;
}
$all_current_ids = array_keys($all_current_ids);
$attachment_ids = array();
foreach ($attachments as $attachment) { $attachment_ids[] = $attachment->id; }
$new_attachments = array_diff($attachment_ids, $all_current_ids);
$missing_attachments = array_diff($all_current_ids, $attachment_ids);
foreach ($new_attachments as $attachment_id) {
$current_ordering[$attachment_id] = array('enabled' => true);
}
update_post_meta($this->post->ID, 'comic_ordering', $comic_image_ordering);
return $comic_image_ordering;
foreach ($missing_attachments as $attachment_id) {
if (isset($current_ordering[$attachment_id])) {
unset($current_ordering[$attachment_id]);
} else {
foreach ($current_ordering as $key => $properties) {
if (isset($properties['children'])) {
foreach ($properties['children'] as $type => $kids) {
if (isset($kids[$attachment_id])) { unset($kids[$attachment_id]); }
if (empty($kids)) {
unset($properties['children'][$type]);
} else {
$properties['children'][$type] = $kids;
}
}
if (empty($properties['children'])) {
unset($current_ordering[$key]['children']);
} else {
$current_ordering[$key] = $properties;
}
}
}
}
}
update_post_meta($this->post->ID, 'image-ordering', $current_ordering);
return $current_ordering;
}
return false;
}
/**
* Sort the remaining comic images by file date.
* @param object $a
* @param object $b
* @return int
*/
function sort_remaining_comic_images($a, $b) {
return strtotime($a->post_date) - strtotime($b->post_date);
$a_date = isset($a->post_date) ? $a->post_date : 0;
$b_date = isset($b->post_date) ? $b->post_date : 0;
return $a_date - $b_date;
}
/**
@ -169,7 +186,7 @@ class ComicPressComicPost {
function change_comic_image_ordering($requested_new_order) {
$orderings = get_post_meta($this->post->ID, 'comic_ordering', true);
if (!is_array($orderings)) { $orderings = array(); }
$new_order = array();
$requested_new_order = (array)$requested_new_order;
@ -180,7 +197,7 @@ class ComicPressComicPost {
$position = 0;
foreach ($requested_new_order[$type] as $id) {
if (!isset($sort_by_position[$position])) {
$sort_by_position[$position] = array();
$sort_by_position[$position] = array();
}
$sort_by_position[$position][] = $id;
$position++;
@ -200,12 +217,32 @@ class ComicPressComicPost {
}
}
}
update_post_meta($this->post->ID, 'comic_ordering', $new_order);
}
function get_parent_categories() {
$parents = wp_get_post_categories($this->post->ID);
function find_parents() {
$parents = array();
$post_categories = wp_get_post_categories($this->post->ID);
if (count($post_categories) == 1) {
do {
$category_parent = 0;
$category = get_category(end($post_categories));
if (!empty($category)) {
$category_parent = $category->parent;
if ($category_parent != 0) {
$post_categories[] = $category_parent;
}
}
} while ($category_parent != 0);
foreach ($post_categories as $category_id) {
$category = get_category($category_id);
$parents[$category_id] = $category->slug;
}
}
return $parents;
}
}

View File

@ -1,40 +1,33 @@
<?php
class ComicPressDBInterface {
var $_non_comic_categories, $_all_categories;
function ComicPressDBInterface() {}
function ComicPressDBInterface() {}
function get_instance() {
static $instance;
if (!isset($instance)) { $instance = new ComicPressDBInterface(); }
return $instance;
}
function _get_categories() { return get_categories("hide_empty=0"); }
/**
* Set the comic categories for the current run of ComicPress.
*/
function set_comic_categories($categories) {
$this->_all_categories = get_all_category_ids();
$this->_non_comic_categories = array_values(array_diff($this->_all_categories, $categories));
}
function _get_categories_to_exclude($category = null) {
return (is_null($category)) ? $this->_non_comic_categories : array_values(array_diff($this->_all_categories, array($category)));
}
/**
* Find the terminal post in a specific category.
*/
function get_terminal_post_in_category($category_id, $first = true) {
function get_terminal_post($first = true, $include_categories = null) {
$this->_prepare_wp_query();
$sort_order = $first ? "asc" : "desc";
$terminal_comic_query = new WP_Query();
$terminal_comic_query->query("showposts=1&order=${sort_order}&cat=${category_id}&status=publish");
$query_parameters = array(
'showposts' => 1,
'order' => $first ? "asc" : "desc",
'status' => 'publish'
);
if (is_array($include_categories)) {
$query_parameters['category_in'] = $include_categories;
}
$terminal_comic_query->query($query_parameters);
$post = false;
if ($terminal_comic_query->have_posts()) {
$post = reset($terminal_comic_query->posts);
@ -43,32 +36,32 @@ class ComicPressDBInterface {
$this->_reset_wp_query();
return $post;
}
/**
* Get the first comic in a category.
*/
function get_first_comic($category_id) {
return $this->get_terminal_post_in_category($category_id);
function get_first_post($include_categories = null) {
return $this->get_terminal_post(true, $include_categories);
}
/**
* Get the last comic in a category.
*/
function get_last_comic($category_id) {
return $this->get_terminal_post_in_category($category_id, false);
function get_last_post($include_categories = null) {
return $this->get_terminal_post(false, $include_categories);
}
/**
* Get the comic post adjacent to the current comic.
* Wrapper around get_adjacent_post(). Don't unit test this method.
*/
function get_adjacent_comic($category, $next = false, $override_post = null) {
function get_adjacent_post($categories = array(), $next = false, $override_post = null) {
global $post;
$this->_prepare_wp_query();
if (!is_null($override_post)) { $temp_post = $post; $post = $override_post; }
$result = get_adjacent_post(false, implode(" and ", $this->_get_categories_to_exclude($category)), !$next);
$result = get_adjacent_post(false, implode(" and ", array_diff(get_all_category_ids(), $categories)), !$next);
$this->_reset_wp_query();
if (!is_null($override_post)) { $post = $temp_post; }
@ -91,16 +84,16 @@ class ComicPressDBInterface {
$wp_query->is_single = $this->is_single;
$wp_query->in_the_loop = $this->in_the_loop;
}
/**
* Get the previous comic from the current one.
*/
function get_previous_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, false, $override_post); }
function get_previous_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, false, $override_post); }
/**
* Get the next comic from the current one.
*/
function get_next_comic($category = null, $override_post = null) { return $this->get_adjacent_comic($category, true, $override_post); }
function get_next_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); }
}
?>

View File

@ -11,32 +11,56 @@ class ComicPressNavigation {
function get_post_nav($post) {
$nav = array();
if (is_object($post)) {
if (isset($post->ID)) {
$cache_key = 'navigation-' . $post->ID;
// global previous/next
foreach (array('previous', 'next') as $field) {
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post);
}
if (($result = wp_cache_get($cache_key, 'comicpress')) !== false) {
foreach ($result as $key => $post_id) {
$nev[$key] = get_post($post_id);
}
}
// global first/last
foreach (array('first', 'last') as $field) {
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null);
}
// global previous/next
foreach (array('previous', 'next') as $field) {
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null, $post);
}
if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
// storyline previous/next
foreach (array('previous', 'next') as $field) {
$nav["storyline-${field}"] = $this->_dbi->{"get_${field}_comic"}($category, $post);
}
// global first/last
foreach (array('first', 'last') as $field) {
$nav[$field] = $this->_dbi->{"get_${field}_comic"}(null);
}
// adjacent storyline nodes
if (is_array($valid = $this->_storyline->valid($category))) {
foreach ($valid as $field) {
$nav["storyline-chapter-${field}"] = $this->_dbi->get_first_comic($this->_storyline->{$field}($category));
}
}
}
if ($category = $this->_storyline->get_valid_post_category($post->ID)) {
// storyline previous/next
foreach (array('previous', 'next') as $field) {
$nav["storyline-${field}"] = $this->_dbi->{"get_${field}_comic"}($category, $post);
}
return $nav;
// adjacent storyline nodes
if (is_array($valid = $this->_storyline->valid($category))) {
foreach ($valid as $field) {
$all_adjacents = $this->_storyline->all_adjacent($category, $field);
foreach ($all_adjacents as $adjacent_category) {
$result = $this->_dbi->get_first_comic($adjacent_category);
if (!empty($result)) {
$nav["storyline-chapter-${field}"] = $result; break;
}
}
}
}
}
$cache_data = array();
foreach ($nav as $key => $output_post) {
if (!empty($output_post)) { $cache_data[$key] = $output_post->ID; }
}
wp_cache_set($cache_key, $cache_data, 'comicpress');
return $nav;
}
}
}
}

View File

@ -1,7 +0,0 @@
<?php
class ComicPressStorylineCategory {
}
?>

View File

@ -1,17 +1,64 @@
<?php
class ComicPressBackendAttachment {
function ComicPressBackendAttachment($attachment_id) {
$this->attachment_id = $attachment_id;
require_once(dirname(__FILE__) . '/../ComicPressBackend.inc');
class ComicPressBackendAttachment extends ComicPressBackend {
var $root_id = 'attachment';
function generate_from_post($post) {
$result = array();
if (is_object($post)) {
if (isset($post->ID)) {
$children = get_children(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image'
));
if (!empty($children)) {
foreach ($children as $child) {
$result[] = new ComicPressBackendAttachment($child);
}
}
}
}
return $result;
}
function ComicPressBackendAttachment($attachment) {
$this->attachment = $attachment;
$this->id = sprintf('%s-%d', $this->root_id, $this->attachment->ID);
$this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true);
}
function get_url() {
return wp_get_attachment_url($this->attachment_id);
function dims($size = 'comic') {
$metadata = image_downsize($this->attachment->ID, $size);
if (!empty($metadata)) {
if (is_array($metadata)) {
return array_combine(array('width', 'height'), array_slice($metadata, 1, 2));
}
}
return false;
}
function get_info() {
return wp_get_attachment_metadata($this->attachment_id);
function url($size = 'comic') {
$metadata = image_downsize($this->attachment->ID, $size);
if (!empty($metadata)) {
if (is_array($metadata)) {
return $metadata[0];
}
}
return false;
}
function embed($size = 'comic') {
return $this->_embed_image($size);
}
function alt() { return $this->attachment->post_title; }
function title() { return $this->attachment->post_excerpt; }
function get_info() { return array(); }
}
?>

View File

@ -9,29 +9,31 @@
<?php _e('Click the Refesh button underneath the zoom slider if you\'ve changed the images attached to this post.', 'comicpress') ?>
</em></p>
<?php foreach ($ordering as $type => $attachment_ids) { ?>
<h3><?php echo $this->comic_image_types[$type] ?></h3>
<div class="comic-ordering" id="comic-ordering-<?php echo $type ?>">
<?php foreach ($attachment_ids as $attachment_id) {
$backend = new ComicPressBackendAttachment($attachment_id);
$info = $backend->get_info(); ?>
<div class="cp-comic-attachment" id="attachment_<?php echo $attachment_id ?>">
<img src="<?php echo $backend->get_url() ?>" border="0" height="<?php echo $zoom_level ?>" />
<div>
<?php if (isset($info['file'])) { ?>
<p><strong><?php echo basename($info['file']) ?></strong></p>
<?php } ?>
<?php if (isset($info['width']) && isset($info['height'])) { ?>
<p>
<?php _e('Size:', 'comicpress') ?>
<?php printf('%dx%d', $info['width'], $info['height'] ) ?>
</p>
<?php } ?>
</div>
<br style="clear: both" />
</div>
<?php } ?>
</div>
<?php if (!empty($ordering)) { ?>
<?php foreach ($ordering as $type => $attachment_ids) { ?>
<h3><?php echo $this->comic_image_types[$type] ?></h3>
<div class="comic-ordering" id="comic-ordering-<?php echo $type ?>">
<?php foreach ($attachment_ids as $attachment_id) {
$backend = new ComicPressBackendAttachment($attachment_id);
$info = $backend->get_info(); ?>
<div class="cp-comic-attachment" id="attachment_<?php echo $attachment_id ?>">
<img src="<?php echo $backend->url() ?>" border="0" height="<?php echo $zoom_level ?>" />
<div>
<?php if (isset($info['file'])) { ?>
<p><strong><?php echo basename($info['file']) ?></strong></p>
<?php } ?>
<?php if (isset($info['width']) && isset($info['height'])) { ?>
<p>
<?php _e('Size:', 'comicpress') ?>
<?php printf('%dx%d', $info['width'], $info['height'] ) ?>
</p>
<?php } ?>
</div>
<br style="clear: both" />
</div>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
<script type="text/javascript">

View File

@ -5,11 +5,16 @@
<h3><?php _e('Global Options', 'comicpress') ?></h3>
<table class="widefat fixed">
<tr>
<th scope="row" valign="top"><?php _e('Layout', 'comicpress') ?></th>
<th scope="row" valign="top"><?php _e("Arrange storyline category order", 'comicpress') ?></th>
<td>
<select name="cp[layout]">
<?php echo $this->create_layout_options($this->comicpress->get_layout_choices(), $this->comicpress->comicpress_options['layout']) ?>
</select>
<input type="hidden" name="cp[storyline_order]" />
<div id="storyline-sorter" class="cp-children">
<?php
$this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline()))
?>
</div>
<script type="text/javascript">Storyline.setup()</script>
<p><em><?php _e('(drag and drop desired order. categories can be modified on the Posts -> Categories page)', 'comicpress') ?></em></p>
</td>
</tr>
<?php foreach (array(
@ -25,47 +30,6 @@
</td>
</tr>
<?php } ?>
<tr>
<th scope="row" valign="top"><?php _e("Number of blog posts on home page", 'comicpress') ?></th>
<td>
<input type="text" name="cp[blogpost_count]" value="<?php echo $this->comicpress->comicpress_options['blogpost_count'] ?>" size="3" />
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e("Arrange storyline category order", 'comicpress') ?></th>
<td>
<input type="hidden" name="cp[storyline_order]" />
<div id="storyline-sorter" class="cp-children">
<?php
$this->_render_admin_storyline_tree(reset($storyline->get_simple_storyline()))
?>
</div>
<script type="text/javascript">Storyline.setup()</script>
<p><em><?php _e('(drag and drop desired order. categories can be modified on the Posts -> Categories page)', 'comicpress') ?></em></p>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Insert into comic space:', 'comicpress') ?></th>
<td>
<?php foreach (array(
"comic_only" => __("The comic only, with post content below", 'comicpress'),
"post_content" => __("The post content", 'comicpress')
) as $value => $label) { ?>
<label><input type="radio" name="cp[comic_space]" value="<?php echo $value ?>" <?php echo ($this->comicpress->comicpress_options['comic_space'] == $value) ? 'checked="checked"' : "" ?> /> <?php echo $label ?></label><br />
<?php } ?>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Use subcategories of the Master Comic Category as:', 'comicpress') ?></th>
<td>
<?php foreach (array(
"storyline" => __("Storyline indicators for a single comic", 'comicpress'),
"multicomic" => __("Multicomic indicators, with direct descendents being separate comics", 'comicpress')
) as $value => $label) { ?>
<label><input type="radio" name="cp[category_usage]" value="<?php echo $value ?>" <?php echo ($this->comicpress->comicpress_options['category_usage'] == $value) ? 'checked="checked"' : "" ?> /> <?php echo $label ?></label><br />
<?php } ?>
</td>
</tr>
</table>
<h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed">
@ -94,11 +58,11 @@
<td>
<?php
foreach ($this->all_addons as $addon) {
if (!empty($addon->name)) {
if (!empty($addon->name)) {
$enabled = ($addon->is_addon_manager !== true);
$checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name];
?>
<label>
<input type="checkbox"
name="cp[addons][<?php echo $addon->name ?>]"
@ -112,7 +76,7 @@
?>
</td>
</tr>
<?php } ?>
<?php } ?>
</table>
<input class="button" type="submit" value="<?php _e('Submit Changes', 'comicpress') ?>" />
</form>

View File

@ -2,6 +2,10 @@
padding-left: 20px
}
#children-0 {
padding-left: 0
}
.cp-category-info span {
cursor: move;
color: #004

View File

@ -1,17 +0,0 @@
<div class="clear"></div><!-- Clears floated columns and sidebars -->
<div id="footer">
<p>
<?php bloginfo('name') ?> is powered by <a href="http://wordpress.org/">WordPress</a> with <a href="http://comicpress.org/">ComicPress</a>
| Subscribe: <a href="<?php bloginfo('rss2_url') ?>">RSS Feed</a>
<!-- <?php echo get_num_queries() ?> queries. <?php timer_stop(1) ?> seconds. -->
</p>
</div>
</div><!-- Ends "page" -->
<?php wp_footer() ?>
</body>
</html>

View File

@ -1,64 +0,0 @@
/**
* Find a comic file in the filesystem.
* @param string $folder The folder name to search.
* @param string $override_post A WP Post object to use in place of global $post.
* @param string $filter The $comic_filename_filters to use.
* @return string The relative path to the comic file, or false if not found.
*/
function get_comic_path($folder = 'comic', $override_post = null, $filter = 'default') {
global $post, $comic_filename_filters, $comic_folder, $archive_comic_folder, $rss_comic_folder, $comic_pathfinding_errors;
if (isset($comic_filename_filters[$filter])) {
$filter_to_use = $comic_filename_filters[$filter];
} else {
$filter_to_use = '{date}*.*';
}
switch ($folder) {
case "rss": $folder_to_use = $rss_comic_folder; break;
case "archive": $folder_to_use = $archive_comic_folder; break;
case "comic": default: $folder_to_use = $comic_folder; break;
}
$post_to_use = (is_object($override_post)) ? $override_post : $post;
$post_date = mysql2date(CP_DATE_FORMAT, $post_to_use->post_date);
$filter_with_date = str_replace('{date}', $post_date, $filter_to_use);
if (count($results = glob("${folder_to_use}/${filter_with_date}")) > 0) {
return reset($results);
}
$comic_pathfinding_errors[] = sprintf(__("Unable to find the file in the <strong>%s</strong> folder that matched the pattern <strong>%s</strong>. Check your WordPress and ComicPress settings.", 'comicpress'), $folder, $filter_with_date);
return false;
}
/**
* Find a comic file in the filesystem and return an absolute URL to that file.
* @param string $folder The folder name to search.
* @param string $override_post A WP Post object to use in place of global $post.
* @param string $filter The $comic_filename_filters to use.
* @return string The absolute URL to the comic file, or false if not found.
*/
function get_comic_url($folder = 'comic', $override_post = null, $filter = 'default') {
if (($result = get_comic_path($folder, $override_post, $filter)) !== false) {
return get_option('home') . '/' . $result;
}
return false;
}
// ComicPress Template Functions
function the_comic($filter = 'default') { echo get_comic_url('comic', null, $filter); }
//The following is deprecated...
function comic_display($filter = 'default') { echo get_comic_url('comic', null, $filter); }
function the_comic_archive($filter = 'default') { echo get_comic_url('archive', null, $filter); }
//The following is deprecated...
function comic_archive($filter = 'default') { echo get_comic_url('archive', null, $filter); }
function the_comic_rss($filter = 'default') { echo get_comic_url('rss', null, $filter); }
//The following is deprecated...
function comic_rss($filter = 'default') { echo get_comic_url('rss', null, $filter); }

View File

@ -5,7 +5,7 @@ add_action('init', '__comicpress_init');
function __comicpress_init() {
global $comicpress, $wp_query;
if (current_user_can('edit_files')) {
wp_cache_flush();
}
@ -32,56 +32,124 @@ function __comicpress_init() {
$comicpress_filters = new ComicPressFilters();
$comicpress_filters->init();
$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 F($name, $path, $override_post = null) {
global $post;
$comic_post = new ComicPressComicPost(is_null($override_post) ? $post : $override_post);
return ComicPress::get_instance()->find_file($name, $path, $comic_post->find_parents());
}
function comicpress_get_header() {
get_header();
/**
* Finish rendering this template and shove the output into application.php.
*/
function finish_comicpress() {
$content = ob_get_clean();
include(F('application.php', ''));
}
function include_partial($partials = '') {
global $comicpress, $post, $nav_comics;
if (!is_array($partials)) { $partials = func_get_args(); }
$content = $target = null;
/**
* Protect global $post and $wp_query.
*/
function Protect() {
global $post, $wp_query, $__post, $__wp_query;
$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);
}
$__post = $post;
$__wp_query = $wp_query;
}
function in_comic_category() {
global $post, $comicpress;
/**
* Temporarily restore the global $post variable and set it up for use.
*/
function Restore() {
global $post, $__post;
$post = $__post;
setup_postdata($post);
}
/**
* Restore global $post and $wp_query.
*/
function Unprotect() {
global $post, $wp_query, $__post, $__wp_query;
$post = $__post;
$wp_query = $__wp_query;
$__post = $__wp_query = null;
}
function R($which, $restrictions = null, $override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$storyline = new ComicPressStoryline();
if (is_string($restrictions)) {
switch ($restrictions) {
case 'from_post':
$restrictions = array('from_post' => $post_to_use);
break;
}
}
if (is_array($restrictions)) {
$new_restrictions = array();
foreach ($restrictions as $type => $list) {
if (is_string($list)) {
$value = $list;
switch ($list) {
case '__post': $value = $post_to_use; break;
}
$new_restrictions[$type] = $value;
} else {
$new_restrictions[$type] = $list;
}
}
$restrictions = $new_restrictions;
}
$categories = $storyline->build_from_restrictions($restrictions);
$dbi = ComicPressDBInterface::get_instance();
$new_post = false;
switch ($which) {
case 'first': $new_post = $dbi->get_first_post($categories); break;
case 'last': $new_post = $dbi->get_last_post($categories); break;
case 'next': $new_post = $dbi->get_next_post($categories, $post_to_use); break;
case 'previous': $new_post = $dbi->get_previous_post($categories, $post_to_use); break;
}
return $new_post;
}
function RT($which, $restrictions = null, $override_post = null) {
global $post, $__post;
if (!empty($override_post)) {
$post_to_use = $override_post;
} else {
$post_to_use = (!empty($__post)) ? $__post : $post;
}
if (($new_post = R($which, $restrictions, $post_to_use)) !== false) {
$post = $new_post;
setup_postdata($post);
}
return $post;
}
function M($override_post = null) {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$comic_post = new ComicPressComicPost($post_to_use);
return $comic_post->get_attachments();
}
/**
@ -127,74 +195,5 @@ function comicpress_list_storyline_categories($args = "") {
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)) { ?>
<script type='text/javascript'>
<!--
function toggle_expander(id) {
var e = document.getElementById(id);
if(e.style.height == 'auto')
e.style.height = '1px';
else
e.style.height = 'auto';
}
//-->
</script>
<div class="transcript-border"><div id="transcript"><a href="javascript:toggle_expander('transcript-content');" class="transcript-title">&darr; Transcript</a><div id="transcript-content"><?php echo nl2br($transcript); ?><br /><br /></div></div></div>
<script type='text/javascript'>
<!--
document.getElementById('transcript-content').style.height = '1px';
//-->
</script><?php
}
break;
}
}
// Register Sidebar and Define Widgets
function widget_comicpress_latest_comics() { ?>
<li>
<h2>Latest Comics</h2>
<ul>
<?php global $post;
$latestcomics = get_posts('numberposts=5&category='.get_all_comic_categories_as_cat_string());
foreach($latestcomics as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php } if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Latest Comics'), 'widget_comicpress_latest_comics');
function widget_comicpress_random_comic() { ?>
<li>
<h2><a href="?randomcomic"><span class="random-comic-icon">?</span> Random Comic</a></h2>
</li>
<?php } if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Random Comic'), 'widget_comicpress_random_comic');
function widget_comicpress_archive_dropdown() { ?>
<li class="archive-dropdown-wrap">
<select name="archive-dropdown" class="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo attribute_escape(__('Archives...')); ?></option>
<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>
</li>
<?php } if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Archive Dropdown'), 'widget_comicpress_archive_dropdown');
?>
ob_start();
?>

View File

@ -1,5 +1,3 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes() ?>>
<head profile="http://gmpg.org/xfn/11">
<title><?php
bloginfo('name');
@ -21,25 +19,4 @@
<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name') ?> Atom Feed" href="<?php bloginfo('atom_url') ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url') ?>" />
<?php wp_head() ?>
<!--[if lt IE 7]><script type="text/javascript" src="<?php bloginfo('template_directory') ?>/ie6submenus.js"></script><![endif]-->
</head>
<body <?php if (function_exists('body_class')) { body_class(); } ?>>
<div id="page"><!-- Defines entire site width - Ends in Footer -->
<div id="header">
<h1><a href="<?php echo get_settings('home') ?>"><?php bloginfo('name') ?></a></h1>
<div class="description"><?php bloginfo('description') ?></div>
</div>
<div id="menubar">
<ul id="menu">
<li><a href="<?php bloginfo('url') ?>">Home</a></li>
<?php wp_list_pages('sort_column=menu_order&depth=4&title_li=') ?>
<li><a href="<?php bloginfo('rss2_url') ?>">Subscribe</a></li>
</ul>
<div class="clear"></div>
</div>
</head>

View File

@ -1,14 +0,0 @@
//Suckerfish Dropdown for IE6
sfHover = function() {
var sfEls = document.getElementById("menu").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

View File

@ -1,34 +1,9 @@
<?php
global $comicpress, $post, $nav_comics;
$previous_post = R('previous');
$next_post = R('next');
comicpress_init();
var_dump($previous_post);
var_dump($next_post);
$nav_comics = array();
$t = $post;
$post = $nav_comics['last'];
setup_postdata($post);
ob_start();
if (!is_paged()) { include_partial('index-display-comic'); }
$comic = ob_get_clean();
ob_start();
if (!is_paged() && ($comicpress->comicpress_options['comic_space'] == "comic_only")) { include_partial('index-comic-post'); }
include_partial('index-blog-header');
$index_posts_query = $comicpress->get_index_blog_posts_query();
while ($index_posts_query->have_posts()) {
$index_posts_query->the_post();
include_partial('index-blog-post');
}
$content = ob_get_clean();
$post = $t;
include(get_template_directory() . '/layouts/' . $comicpress->comicpress_options['layout']);
finish_comicpress();
?>

View File

@ -1,19 +0,0 @@
<?php
/*
Layout Name: Classic
Sidebars: right
*/
?>
<?php get_header() ?>
<?php echo $comic ?>
<div id="content" class="narrowcolumn">
<?php echo $content ?>
</div>
<?php get_sidebar('right') ?>
<?php get_footer() ?>

View File

@ -1,21 +0,0 @@
<?php
/*
Layout Name: Three Column
Sidebars: left,right
*/
?>
<?php get_header() ?>
<?php echo $comic ?>
<?php get_sidebar('left') ?>
<div id="content" class="narrowcolumn">
<?php echo $content ?>
</div>
<?php get_sidebar('right') ?>
<?php get_footer() ?>

2
phpunit.xml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="test/bootstrap.php" />

View File

@ -1,37 +1,29 @@
<?php
global $comicpress, $nav_comics;
<?php
$storyline = new ComicPressStoryline();
$storyline->read_from_options();
comicpress_init();
the_title(); echo '<br />';
ob_start();
Protect();
if (have_posts()) {
the_post();
if (in_comic_category()) { include_partial('single-display-comic'); }
RT('first', 'from_post'); the_title(); echo '<br />';
RT('previous', 'from_post'); the_title(); echo '<br />';
RT('previous', array('root_of' => '__post')); the_title(); echo '<br />';
RT('previous'); the_title(); echo '<br />';
Restore(); the_title(); echo '<br />';
foreach (M() as $image) {
echo $image->embed();
}
rewind_posts();
$comic = ob_get_clean();
ob_start();
RT('next'); the_title(); echo '<br />';
RT('next', array('root_of' => '__post')); the_title(); echo '<br />';
RT('next', 'from_post'); the_title(); echo '<br />';
RT('last', 'from_post'); the_title(); echo '<br />';
$nav_comics = $comicpress->get_nav_comics();
if (have_posts()) {
while (have_posts()) { the_post();
if (in_comic_category()) {
if ($comicpress->comicpress_options['comic_space'] == "comic_only") {
include_partial('single-comic-post');
}
} else {
include_partial('single-blog-post');
}
}
} else {
include_partial('single-no-matches');
}
$content = ob_get_clean();
include(get_template_directory() . '/layouts/' . $comicpress->comicpress_options['layout']);
Unprotect();
the_title(); echo '<br />';
finish_comicpress();
?>

View File

@ -2,7 +2,7 @@
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressAdmin.inc');
require_once('ComicPressAdmin.inc');
class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
function setUp() {
@ -10,98 +10,22 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
$_POST = array();
$this->admin = new ComicPressAdmin();
}
function providerTestGetRootComicCategories() {
return array(
array(array(), array()),
array(
array(
array('id' => 1, 'parent' => 0),
array('id' => 2, 'parent' => 1)
),
array(1)
)
);
}
/**
* @dataProvider providerTestGetRootComicCategories
*/
function testGetRootCategories($categories, $expected_result) {
foreach ($categories as $category) {
add_category($category['id'], (object)$category);
}
$result_ids = array();
foreach ($this->admin->get_root_categories() as $category) {
$result_ids[] = $category->term_id;
}
$this->assertEquals($expected_result, $result_ids);
}
function testCreateCategoryOptions() {
add_category(1, (object)array('name' => 'test-one'));
add_category(2, (object)array('name' => 'test-two'));
foreach(array(
array(1,2),
array(get_category(1), get_category(2))
) as $category_test) {
$source = $this->admin->create_category_options($category_test, 1);
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
foreach (array(
'//option[@value="1" and @selected="selected"]' => "test-one",
'//option[@value="2"]' => "test-two",
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
}
}
function testCreateDimensionSelector() {
$source = $this->admin->create_dimension_selector("test", "760x340");
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
foreach (array(
'//input[@name="test[width]" and @value="760"]' => true,
'//input[@name="test[height]" and @value="340"]' => true,
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
}
function providerTestHandleUpdate() {
return array(
array(
array('comic_category_id' => 1),
array('comic_category_id' => 2),
array('comic_category_id' => 1)
),
array(
array('comic_category_id' => 1),
array('cp' => array(
'comic_category_id' => 2),
),
array('comic_category_id' => 2)
),
array(
array('comic_category_id' => 1),
array('cp' => array(
'comic_category_id' => "cat"),
),
array('comic_category_id' => 1)
),
array(
array('comic_category_id' => 1),
array('cp' => array(
'comic_category_id' => 3
)),
array('comic_category_id' => 1)
),
array(
array('comic_dimensions' => '150x150'),
array('cp' => array(
@ -138,24 +62,25 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
function testHandleUpdate($original, $change, $new) {
$this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init'));
$this->admin->comicpress->comicpress_options = array(
'comic_category_id' => 1,
'comic_dimensions' => '760x',
'rss_dimensions' => '350x',
'archive_dimensions' => '125x'
);
$this->admin->comicpress->comicpress_options = array_merge($this->admin->comicpress->comicpress_options, $original);
add_category(2, (object)array('name' => 'test'));
$_POST = $change;
$this->admin->handle_update_comicpress_options($_POST['cp']);
if (isset($_POST['cp'])) {
$this->admin->handle_update_comicpress_options($_POST['cp']);
}
foreach ($new as $key => $value) {
$this->assertEquals($value, $this->admin->comicpress->comicpress_options[$key]);
}
}
function providerTestUpdateAttachments() {
return array(
array(
@ -185,7 +110,7 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
'post_parent' => 0
),
),
),
),
array(
array(
'post' => array(
@ -202,9 +127,9 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
),
),
)
);
);
}
/**
* @dataProvider providerTestUpdateAttachments
*/
@ -223,20 +148,20 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
break;
}
}
$_POST = array(
'attachments' => array('1' => $changes)
);
$this->admin->handle_update_attachments();
foreach ($expected_settings as $settings_type => $settings) {
switch ($settings_type) {
case "post_meta":
foreach ($settings as $key => $value) {
$this->assertEquals($value, get_post_meta(1, $key, true));
}
break;
break;
case "post":
$post = get_post(1);
foreach ($settings as $key => $value) {
@ -245,7 +170,7 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
}
}
}
function providerTestHandleUpdateOverridePartial() {
return array(
array(
@ -258,25 +183,6 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
),
);
}
/**
* @dataProvider providerTestHandleUpdateOverridePartial
*/
function testHandleUpdateOverridePartial($code, $action) {
$this->admin->comicpress = (object)array(
'comicpress_options' => array(
'override_partials' => array(
'index' => '$hiss;'
)
)
);
$this->admin->handle_update_override_partial(array_merge(compact('code', 'action'), array('partial' => 'index')));
if ($result && $action == "Update partial") {
$this->assertEquals($code, $this->admin->comicpress->comicpress_options['override_partials']['index']);
}
}
}
?>

View File

@ -2,7 +2,7 @@
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressComicPost.inc');
require_once('ComicPressComicPost.inc');
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
function setUp() {
@ -20,7 +20,7 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
)
);
}
/**
* @dataProvider providerTestGenerateComicTag
*/
@ -30,7 +30,7 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
'comic_dimensions' => $dimensions
)
);
$source = $this->p->get_comic_img_tag("test.gif", "comic");
if (count($parts = explode("x", $dimensions)) == 2) {
@ -46,83 +46,54 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
}
}
}
function testNormalizeComicImageOrdering() {
$p = $this->getMock('ComicPressComicPost', array('get_comic_image_attachments'));
$comic_attachments = array(
array(
'ID' => 2,
'post_parent' => 1,
'post_title' => 'Comic one',
'post_meta' => array(
'comic_image_type' => 'comic'
),
'post_date' => 1
),
array(
'ID' => 3,
'post_parent' => 1,
'post_title' => 'Comic two',
'post_meta' => array(
'comic_image_type' => 'comic'
),
'post_date' => 2
),
array(
'ID' => 4,
'post_parent' => 1,
'post_title' => 'Comic three',
'post_meta' => array(
'comic_image_type' => 'rss'
),
'post_date' => 4
),
array(
'ID' => 5,
'post_parent' => 1,
'post_title' => 'Comic four',
'post_meta' => array(
'comic_image_type' => 'rss'
),
'post_date' => 3
),
);
$attachments = array();
foreach ($comic_attachments as $attachment_info) {
$attachment = (object)array();
foreach ($attachment_info as $field => $value) {
switch ($field) {
case "post_meta":
foreach ($value as $meta => $meta_value) {
update_post_meta($attachment_info['ID'], $meta, $meta_value);
}
break;
case "post_date":
$attachment->{$field} = date("r", $value);
break;
default:
$attachment->{$field} = $value;
break;
}
}
$attachments[] = $attachment;
}
$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', array('comic' => array(3)));
$p->post = (object)array('ID' => 1);
$result = $p->normalize_comic_image_ordering();
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), $result);
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), get_post_meta(1, 'comic_ordering', true));
function providerTestNormalizeOrdering() {
return array(
array(
array('attachment-1'),
array(),
array('attachment-1' => array('enabled' => true))
),
array(
array('attachment-1'),
array('attachment-1' => array('enabled' => false), 'attachment-2' => array('enabled' => true)),
array('attachment-1' => array('enabled' => false))
),
array(
array('attachment-1'),
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => array('attachment-2' => true)))),
array('attachment-1' => array('enabled' => true))
),
array(
array('attachment-1', 'attachment-2', 'attachment-3'),
array('attachment-1' => array('enabled' => false, 'children' => array('rss' => array('attachment-2' => true)))),
array('attachment-1' => array('enabled' => false, 'children' => array('rss' => array('attachment-2' => true))), 'attachment-3' => array('enabled' => true))
),
);
}
/**
* @dataProvider providerTestNormalizeOrdering
*/
function testNormalizeOrdering($attachments, $current_meta, $expected_result) {
$p = $this->getMock('ComicPressComicPost', array('get_attachments'));
$attachment_objects = array();
foreach ($attachments as $attachment) {
$attachment_objects[] = (object)array('id' => $attachment);
}
$p->expects($this->any())->method('get_attachments')->will($this->returnValue($attachment_objects));
wp_insert_post((object)array('ID' => 1));
update_post_meta(1, 'image-ordering', $current_meta);
$p->post = (object)array('ID' => 1);
$this->assertEquals($expected_result, $p->normalize_ordering());
$this->assertEquals($expected_result, get_post_meta(1, 'image-ordering', true));
}
function providerTestChangeComicImageOrdering() {
return array(
array(
@ -148,22 +119,63 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
),
);
}
/**
* @dataProvider providerTestChangeComicImageOrdering
* @covers ComicPressComicPost::change_comic_image_ordering
*/
function testChangeComicImageOrdering($current_ordering, $revised_ordering, $expected_result) {
update_post_meta(1, 'comic_ordering', $current_ordering);
$this->p->post = (object)array('ID' => 1);
$this->p->change_comic_image_ordering($revised_ordering);
$this->assertEquals($expected_result, get_post_meta(1, 'comic_ordering', true));
}
function testFindParents() {
function providerTestFindParents() {
return array(
array(
array(),
array()
),
array(
array(1),
array(1 => 'root')
),
array(
array(2),
array(2 => 'comic', 1 => 'root')
),
array(
array(3),
array(3 => 'part-1', 2 => 'comic', 1 => 'root')
),
array(
array(4),
array(4 => 'blog', 1 => 'root')
),
array(
array(1, 4),
array()
),
);
}
/**
* @dataProvider providerTestFindParents
*/
function testFindParents($post_categories, $expected_result) {
add_category(1, (object)array('slug' => 'root', 'parent' => 0));
add_category(2, (object)array('slug' => 'comic', 'parent' => 1));
add_category(3, (object)array('slug' => 'part-1', 'parent' => 2));
add_category(4, (object)array('slug' => 'blog', 'parent' => 1));
wp_set_post_categories(1, $post_categories);
$this->p->post = (object)array('ID' => 1);
$this->assertEquals($expected_result, $this->p->find_parents());
}
}

View File

@ -2,7 +2,7 @@
require_once('MockPress/mockpress.php');
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressDBInterface.inc');
require_once('ComicPressDBInterface.inc');
class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase {
function testSingleton() {
@ -14,35 +14,6 @@ class ComicPressDBInterfaceTest extends PHPUnit_Framework_TestCase {
$b = ComicPressDBInterface::get_instance();
$this->assertEquals("test", $b->test);
}
function testSetComicCategories() {
$dbi = ComicPressDBInterface::get_instance();
for ($i = 1; $i <= 4; ++$i) { add_category($i, (object)array()); }
$dbi->set_comic_categories(array(2,3));
$this->assertEquals(array(1,2,3,4), $dbi->_all_categories);
$this->assertEquals(array(1,4), $dbi->_non_comic_categories);
}
function providerTestGetCategoriesToExclude() {
return array(
array(null, array(1 ,4)),
array(2, array(1, 3, 4)),
);
}
/**
* @dataProvider providerTestGetCategoriesToExclude
*/
function testGetCategoriesToExclude($category, $expected_results) {
$dbi = ComicPressDBInterface::get_instance();
$dbi->_all_categories = array(1,2,3,4);
$dbi->_non_comic_categories = array(1,4);
$this->assertEquals($expected_results, $dbi->_get_categories_to_exclude($category));
}
}
?>

View File

@ -2,7 +2,7 @@
require_once('MockPress/mockpress.php');
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
require_once('ComicPressNavigation.inc');
/**
* Integration Testing. Just make sure things are called correctly.
@ -12,7 +12,7 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
_reset_wp();
$this->nav = new ComicPressNavigation();
}
function testGetPostNav() {
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic'));
$storyline = new ComicPressStoryline();
@ -34,13 +34,53 @@ class ComicPressNavigationTest extends PHPUnit_Framework_TestCase {
$dbi->expects($this->at(3))->method('get_last_comic')->with(null);
$dbi->expects($this->at(4))->method('get_previous_comic')->with(2, $post);
$dbi->expects($this->at(5))->method('get_next_comic')->with(2, $post);
$dbi->expects($this->at(6))->method('get_first_comic')->with(1);
$dbi->expects($this->at(7))->method('get_first_comic')->with(3);
$dbi->expects($this->at(6))->method('get_first_comic')->with(1)->will($this->returnValue((object)array('ID' => 1)));
$dbi->expects($this->at(7))->method('get_first_comic')->with(3)->will($this->returnValue((object)array('ID' => 1)));
$this->nav->_dbi = $dbi;
$this->nav->_storyline = $storyline;
$this->assertFalse(wp_cache_get('navigation-1', 'comicpress'));
$this->nav->get_post_nav($post);
$this->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false);
}
function testSkipEmptyCategories() {
$dbi = $this->getMock('ComicPressDBInterface', array('get_previous_comic', 'get_next_comic', 'get_first_comic', 'get_last_comic'));
$storyline = new ComicPressStoryline();
$storyline->_structure = array(
'1' => array('next' => 2),
'2' => array('previous' => 1, 'next' => 3),
'3' => array('previous' => 2)
);
wp_insert_post(array('ID' => 1));
$post = get_post(1);
wp_set_post_categories(1, array(1));
$dbi->expects($this->any())->method('get_first_comic')->will($this->returnCallback(array(&$this, 'callbackTestSkipEmptyCategories')));
$this->nav->_dbi = $dbi;
$this->nav->_storyline = $storyline;
$nav = $this->nav->get_post_nav($post);
$this->assertEquals(10, $nav['storyline-chapter-next']->ID);
}
function callbackTestSkipEmptyCategories($category_id) {
if (!is_null($category_id)) {
switch ($category_id) {
case 3: return (object)array('ID' => 10);
default: return false;
}
} else {
return (object)array('ID' => 1);
}
}
}

View File

@ -1,17 +0,0 @@
<?php
require_once('MockPress/mockpress.php');
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressStorylineCategory.inc');
class ComicPressStorylineCategoryTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
}
function testGetAdjacentCategories() {
$sc = new ComicPressStorylineCategory();
}
}
?>

View File

@ -2,12 +2,12 @@
require_once('MockPress/mockpress.php');
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressStoryline.inc');
require_once('ComicPressStoryline.inc');
class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->css = new ComicPressStoryline();
}
@ -83,7 +83,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
function testCreateStorylineStructure($input, $expected_structure) {
global $wp_object_cache;
$this->assertTrue(empty($wp_object_cache->cache['comicpress']));
$this->assertEquals(is_array($expected_structure), $this->css->create_structure($input));
$this->assertEquals($expected_structure, $this->css->_structure);
@ -104,7 +104,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(is_array($expected_structure), $this->css->create_structure($input));
$this->assertEquals($expected_structure, $this->css->_structure);
}
function providerTestGetFields() {
return array(
array('parent', 1, false),
@ -115,7 +115,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
array('valid', 6, false),
);
}
/**
* @dataProvider providerTestGetFields
*/
@ -126,7 +126,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2),
'4' => array('parent' => 2, 'previous' => 3)
);
$this->assertEquals($expected_value, $this->css->{$field}($category));
}
@ -139,13 +139,13 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
array(array(3), array('previous')),
);
}
/**
* @dataProvider providerTestGetValidNav
*/
function testGetValidNav($post_categories, $expected_navigation) {
wp_set_post_categories(1, $post_categories);
$this->css->_structure = array(
'1' => array('next' => 2),
'2' => array('previous' => 1, 'next' => 3),
@ -169,12 +169,12 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
function testGetValidPostCategory($post_categories, $expected_result) {
$css = $this->getMock('ComicPressStoryline', array('valid'));
$css->expects($this->any())->method('valid')->will($this->returnValue(true));
wp_set_post_categories(1, $post_categories);
$this->assertEquals($expected_result, $css->get_valid_post_category(1));
}
function testGetSimpleStoryline() {
$this->css->_structure = array(
'1' => array('next' => 2),
@ -182,7 +182,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2),
'4' => array('parent' => 2, 'previous' => 3)
);
$expected_result = array(
array(
'1' => array(
@ -193,10 +193,10 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
)
)
);
$this->assertEquals($expected_result, $this->css->get_simple_storyline());
}
function providerTestSetFlattenedStorylineOrder() {
return array(
array('0/1,0/1/2,0/1/2/3,0/1/2/4', '0/1,0/1/2,0/1/2/3,0/1/2/4', true),
@ -204,7 +204,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
array('0/1,0/1/2,0/1/2/5,0/1/2/3', '0/1,0/1/2,0/1/2/3,0/1/2/4', false),
);
}
/**
* @dataProvider providerTestSetFlattenedStorylineOrder
*/
@ -212,11 +212,11 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$css = $this->getMock('ComicPressStoryline', array(
'get_flattened_storyline', 'set_flattened_storyline'
));
$css->expects($this->once())
->method('get_flattened_storyline')
->will($this->returnValue('0/1,0/1/2,0/1/2/3,0/1/2/4'));
if ($expected_return === true) {
$css->expects($this->once())
->method('set_flattened_storyline')
@ -225,17 +225,17 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$css->expects($this->never())
->method('set_flattened_storyline');
}
$this->assertEquals($expected_return, $css->set_order_via_flattened_storyline($input));
}
function testMergeSimpleStoryline() {
$original = array(
0 => array(1 => true),
1 => array(2 => true),
2 => array(3 => true, 4 => true)
);
$expected = array(
0 => array(
1 => array(
@ -246,17 +246,17 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
)
)
);
$this->assertEquals($expected, $this->css->_merge_simple_storyline($original));
}
function testGetCategorySimpleStructure() {
add_category(1, (object)array('parent' => 0));
add_category(2, (object)array('parent' => 1));
add_category(3, (object)array('parent' => 2));
add_category(4, (object)array('parent' => 2));
add_category(5, (object)array('parent' => 0));
$this->assertEquals(array(
'0' => array(
'1' => array(
@ -267,7 +267,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
)
)
), $this->css->get_category_simple_structure(1));
$this->assertEquals(array(
'0' => array(
'1' => array(
@ -280,7 +280,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
)
), $this->css->get_category_simple_structure());
}
function providerTestNormalizeFlattenedStoryline() {
return array(
array('0/1,0/1/2,0/1/2/4', '0/1,0/1/2,0/1/2/4,0/1/2/3'),
@ -289,7 +289,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
array('', '0/1,0/1/2,0/1/2/3,0/1/2/4'),
);
}
/**
* @dataProvider providerTestNormalizeFlattenedStoryline
*/
@ -299,7 +299,7 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$this->css->normalize_flattened_storyline($original_structure, '0/1,0/1/2,0/1/2/3,0/1/2/4')
);
}
function testFlattenSimpleStoryline() {
$this->assertEquals('0/1,0/1/2,0/1/2/3,0/1/2/4', $this->css->flatten_simple_storyline(
array(
@ -314,16 +314,16 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
)
));
}
function testLengthSort() {
$data = array(
'0/1', '0/1/3', '0/1/3/6', '0/1/3/7', '0/1/4', '0/1/4/2', '0/1/4/3'
);
$expected_result = array(
'0/1', '0/1/3', '0/1/4', '0/1/3/6', '0/1/3/7', '0/1/4/2', '0/1/4/3'
);
$this->assertEquals($expected_result, $this->css->_length_sort($data));
}
@ -334,19 +334,28 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2),
'4' => array('parent' => 2, 'previous' => 3)
);
$this->assertEquals($this->css, $this->css->include_all());
$this->assertEquals(array(1,2,3,4), $this->css->_category_search);
}
function testExcludeAll() {
$this->css->_category_search = array(1,2,3,4);
$this->assertEquals($this->css, $this->css->exclude_all());
$this->assertEquals(array(), $this->css->_category_search);
}
function testFindChildren() {
function providerTestFindChildren() {
return array(
array(2), array('test')
);
}
/**
* @dataProvider providerTestFindChildren
*/
function testFindChildren($search) {
$this->css->_structure = array(
'1' => array('next' => 2),
'2' => array('parent' => 1, 'previous' => 1, 'next' => 3),
@ -354,27 +363,9 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
'4' => array('parent' => 2, 'previous' => 3)
);
$this->assertEquals(array(2,3,4), $this->css->_find_children(2));
}
add_category(2, (object)array('slug' => 'test'));
function testIncludeChildren() {
$css = $this->getMock('ComicPressStoryline', array('_find_children'));
$css->expects($this->once())->method('_find_children')->will($this->returnValue(array(2,3,4)));
$css->_category_search = array(4,5);
$css->include_children(2);
$this->assertEquals(array(2,3,4,5), $css->_category_search);
}
function testExcludeChildren() {
$css = $this->getMock('ComicPressStoryline', array('_find_children'));
$css->expects($this->once())->method('_find_children')->will($this->returnValue(array(2,3,4)));
$css->_category_search = array(4, 5, 6);
$css->exclude_children(2);
$this->assertEquals(array(5, 6), $css->_category_search);
$this->assertEquals(array(2,3,4), $this->css->_find_children($search));
}
function testFindLevelOrAbove() {
@ -388,31 +379,211 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(array(1, 2), $this->css->_find_level_or_above(2));
}
function testIncludeLevelOrAbove() {
$css = $this->getMock('ComicPressStoryline', array('_find_level_or_above'));
$css->expects($this->once())->method('_find_level_or_above')->will($this->returnValue(array(2,3,4)));
$css->_category_search = array(4,5);
$css->include_level_or_above(2);
$this->assertEquals(array(2,3,4,5), $css->_category_search);
}
function testExcludeLevelOrAbove() {
$css = $this->getMock('ComicPressStoryline', array('_find_level_or_above'));
$css->expects($this->once())->method('_find_level_or_above')->will($this->returnValue(array(2,3,4)));
$css->_category_search = array(4, 5, 6);
$css->exclude_level_or_above(2);
$this->assertEquals(array(5, 6), $css->_category_search);
}
function testEndSearch() {
$this->css->_category_search = array(1,2,3);
$this->assertEquals(array(1,2,3), $this->css->end_search());
$this->assertEquals(array(), $this->css->_category_search);
}
function providerTestFindOnly() {
return array(
array(1, array(1)),
array(5, array()),
);
}
/**
* @dataProvider providerTestFindOnly
*/
function testFindOnly($id, $expected_return) {
$this->css->_structure = array(
'1' => array('next' => 2, 'level' => 1),
'2' => array('parent' => 1, 'previous' => 1, 'next' => 3, 'level' => 2),
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2, 'level' => 3),
'4' => array('parent' => 2, 'previous' => 3, 'level' => 3)
);
$this->assertEquals($expected_return, $this->css->_find_only($id));
}
function providerTestFindLevel() {
return array(
array(1, array(1)),
array(2, array(2)),
array(3, array(3,4))
);
}
/**
* @dataProvider providerTestFindLevel
*/
function testFindLevel($id, $expected_return) {
$this->css->_structure = array(
'1' => array('next' => 2, 'level' => 1),
'2' => array('parent' => 1, 'previous' => 1, 'next' => 3, 'level' => 2),
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2, 'level' => 3),
'4' => array('parent' => 2, 'previous' => 3, 'level' => 3)
);
$this->assertEquals($expected_return, $this->css->_find_level($id));
}
function providerTestFindPostCategory() {
return array(
array(array(1), array(1)),
array(array(1,2), array())
);
}
/**
* @dataProvider providerTestFindPostCategory
*/
function testFindPostCategory($post_categories, $expected_return) {
$this->css->_structure = array(
'1' => array('next' => 2, 'level' => 1),
'2' => array('parent' => 1, 'previous' => 1, 'next' => 3, 'level' => 2),
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2, 'level' => 3),
'4' => array('parent' => 2, 'previous' => 3, 'level' => 3)
);
wp_set_post_categories(1, $post_categories);
$this->assertEquals($expected_return, $this->css->_find_post_category(1));
}
function providerTestFindAdjacentCategory() {
return array(
array(3, false, array(2)),
array(3, true, array(4)),
array(1, false, array()),
array(4, true, array()),
);
}
/**
* @dataProvider providerTestFindAdjacentCategory
*/
function testFindAdjacentCategory($category, $which, $expected_return) {
$this->css->_structure = array(
'1' => array('next' => 2, 'level' => 1),
'2' => array('parent' => 1, 'previous' => 1, 'next' => 3, 'level' => 2),
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2, 'level' => 3),
'4' => array('parent' => 2, 'previous' => 3, 'level' => 3)
);
$this->assertEquals($expected_return, $this->css->_find_adjacent($category, $which));
}
function providerTestFindPostRoot() {
return array(
array(array(1), array(1,2,3,4)),
array(array(4), array(1,2,3,4)),
array(array(5), array(5)),
array(array(1, 5), array()),
);
}
/**
* @dataProvider providerTestFindPostRoot
*/
function testFindPostRoot($post_categories, $expected_return) {
$this->css->_structure = array(
'1' => array('next' => 2, 'level' => 1, 'parent' => 0),
'2' => array('parent' => 1, 'previous' => 1, 'next' => 3, 'level' => 2),
'3' => array('parent' => 2, 'next' => 4, 'previous' => 2, 'level' => 3),
'4' => array('parent' => 2, 'previous' => 3, 'next' => 5, 'level' => 3),
'5' => array('parent' => 0, 'previous' => 4, 'level' => 1),
);
wp_set_post_categories(1, $post_categories);
wp_insert_post(array('ID' => 1));
add_category(1, (object)array('slug' => 'root', 'parent' => 0));
add_category(2, (object)array('slug' => 'comic', 'parent' => 1));
add_category(3, (object)array('slug' => 'part-1', 'parent' => 2));
add_category(4, (object)array('slug' => 'blog', 'parent' => 1));
add_category(5, (object)array('slug' => 'blog', 'parent' => 0));
$this->assertEquals($expected_return, $this->css->_find_post_root(1));
}
function providerTestBuildFromRestrictions() {
return array(
array(
null,
array(1,2,3,4,5,6,7)
),
array(
array(),
array(1,2,3,4,5,6,7)
),
array(
array('child_of' => 1),
array(1,2,3)
),
array(
array('only' => 1),
array(1)
),
array(
array('child_of' => 1, 'only' => 7),
array(1,2,3,7)
),
array(
array('level' => 1),
array(1,4,7)
),
array(
array('from_post' => 1),
array(3)
),
array(
array('previous' => 3),
array(2)
),
array(
array('next' => 3),
array(4)
)
);
}
/**
* @dataProvider providerTestBuildFromRestrictions
*/
function testBuildFromRestrictions($restrictions, $expected_categories) {
global $post;
$this->css->set_flattened_storyline('0/1,0/1/2,0/1/3,0/4,0/4/5,0/4/6,0/7');
wp_set_post_categories(1, array(3));
$post = (object)array('ID' => 1);
$this->assertEquals($expected_categories, $this->css->build_from_restrictions($restrictions));
}
function providerTestAllAdjacent() {
return array(
array(3, 'previous', array(2, 1)),
array(2, 'next', array(3, 4)),
array(4, 'next', array()),
array(5, 'next', false)
);
}
/**
* @dataProvider providerTestAllAdjacent
*/
function testAllAdjacent($start, $direction, $expected_result) {
$this->css->_structure = array(
'1' => array('next' => 2),
'2' => array('previous' => 1, 'parent' => 1, 'next' => 3),
'3' => array('previous' => 2, 'parent' => 1, 'next' => 4),
'4' => array('previous' => 3, 'parent' => 1)
);
$this->assertEquals($expected_result, $this->css->all_adjacent($start, $direction));
}
}
?>

View File

@ -2,140 +2,126 @@
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../classes/ComicPress.inc');
require_once('ComicPress.inc');
require_once('vfsStream/vfsStream.php');
class ComicPressTest extends PHPUnit_Framework_TestCase {
function setUp() {
global $post;
_reset_wp();
unset($post);
$this->cp = new ComicPress();
vfsStreamWrapper::register();
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
}
function providerTestGetLayoutChoices() {
return array(
array(
array(),
array()
),
array(
array(
'layout.php' => <<<FILE
Test
FILE
),
array()
),
array(
array(
'layout.php' => <<<FILE
/*
Layout Name: Test
Sidebars: left,right
*/
FILE
),
array('layout.php' => array(
'Layout Name' => 'Test',
'Sidebars' => 'left,right',
))
),
);
function providerTestCategorySearch() {
return array(
array(
array('comic'), array(vfsStream::url('root/style/comic'))
),
array(
array('chapter-1', 'comic'), array(vfsStream::url('root/style/comic'), vfsStream::url('root/style/comic/chapter-1'))
),
array(
array('part-1', 'chapter-1', 'comic'), array(vfsStream::url('root/style/comic'), vfsStream::url('root/style/comic/chapter-1'), vfsStream::url('root/style/comic/chapter-1/part-1'))
),
array(
array('comic', 'chapter-1'), array()
),
array(
array(), array()
)
);
}
/**
* @dataProvider providerTestGetLayoutChoices
* @dataProvider providerTestCategorySearch
*/
function testGetLayoutChoices($files, $expected_results) {
$cp = $this->getMock('ComicPress', array('_glob', '_file_get_contents'));
_set_template_directory('/test');
$file_names = array();
foreach (array_keys($files) as $file) { $file_names[] = '/test/layouts/' . $file; }
$cp->expects($this->once())->method('_glob')->with('/test/layouts/*')->will($this->returnValue($file_names));
foreach ($files as $file => $contents) {
$cp->expects($this->once())->method('_file_get_contents')->with('/test/layouts/' . $file)->will($this->returnValue($contents));
}
$this->assertEquals($expected_results, $cp->get_layout_choices());
function testCategorySearch($categories, $found_path) {
mkdir(vfsStream::url('root/style/comic/chapter-1/part-1'), 0777, true);
$this->assertEquals($found_path, $this->cp->category_search($categories, vfsStream::url('root/style')));
}
function providerTestGetSortedPostCategories() {
return array(
array(
array(1),
array('0/1'),
array(1)
),
array(
array(2, 1),
array('0/1', '0/1/2'),
array(1, 2)
),
array(
array(2, 1),
array('0/1', '0/1/3', '0/1/2'),
array(1, 2)
),
);
function providerTestFindFile() {
return array(
array(
array(), 'partials', array(), false,
),
array(
array('root/parent/partials/index.inc'),
'partials',
array(),
vfsStream::url('root/parent/partials/index.inc')
),
array(
array('root/parent/index.inc'),
'',
array(),
vfsStream::url('root/parent/index.inc')
),
array(
array(
'root/parent/partials/index.inc',
'root/child/partials/index.inc'
),
'partials',
array(),
vfsStream::url('root/child/partials/index.inc')
),
array(
array(
'root/child/partials/index.inc',
'root/child/partials/comic/index.inc'
),
'partials',
array('comic'),
vfsStream::url('root/child/partials/comic/index.inc')
),
array(
array(
'root/child/partials/index.inc',
'root/child/partials/comic/index.inc'
),
'partials',
array('chapter-1', 'comic'),
vfsStream::url('root/child/partials/comic/index.inc')
),
array(
array(
'root/child/partials/index.inc',
'root/child/partials/comic/index.inc'
),
'partials',
null,
vfsStream::url('root/child/partials/comic/index.inc')
)
);
}
/**
* @dataProvider providerTestGetSortedPostCategories
* @dataProvider providerTestFindFile
*/
function testGetSortedPostCategories($post_categories, $category_tree, $expected_sort_order) {
$this->cp->category_tree = $category_tree;
wp_set_post_categories(1, $post_categories);
$this->assertEquals($expected_sort_order, $this->cp->get_sorted_post_categories((object)array('ID' => 1)));
}
function testSetupMulticomicPartialPaths() {
$cp = $this->getMock('ComicPress', array('_is_dir'));
wp_set_post_categories(1, array('2', '3'));
add_category('2', (object)array('slug' => 'test-one'));
add_category('3', (object)array('slug' => 'test-two'));
$cp->expects($this->at(0))->method('_is_dir')->with('/subthemes/test-one')->will($this->returnValue(true));
$cp->expects($this->at(1))->method('_is_dir')->with('/subthemes/test-two')->will($this->returnValue(false));
$cp->setup_multicomic_partial_paths(1);
$this->assertEquals(array('/subthemes/test-one'), $cp->partial_paths);
}
function providerTestGetOverridePartials() {
return array(
array(
array('partials'),
array('index'),
array('partials/index'),
array('partials/index', true)
),
array(
array('partials'),
array('index'),
array('partials/single'),
false
)
);
}
/**
* @dataProvider providerTestGetOverridePartials
*/
function testGetOverridePartials($partial_paths, $requested_partials, $override_partials, $expected_result) {
$this->cp->partial_paths = $partial_paths;
foreach ($override_partials as $partial) {
$this->cp->comicpress_options['override_partials'][$partial] = true;
}
$this->assertEquals($expected_result, $this->cp->get_options_partial($requested_partials));
function testFindFile($files_to_setup, $search_path, $post_categories, $expected_path_result) {
global $post;
mkdir(vfsStream::url('root/parent/partials/comic/chapter-1'), 0777, true);
mkdir(vfsStream::url('root/child/partials/comic/chapter-1'), 0777, true);
foreach ($files_to_setup as $path) {
file_put_contents(vfsStream::url($path), "test");
}
_set_template_directory(vfsStream::url('root/parent'));
_set_stylesheet_directory(vfsStream::url('root/child'));
$post = (object)array('ID' => 1);
wp_set_post_categories(1, array(2));
add_category(1, (object)array('slug' => 'comic', 'parent' => 0));
add_category(2, (object)array('slug' => 'chapter-1', 'parent' => 1));
$this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', $search_path, $post_categories));
}
}

View File

@ -0,0 +1,39 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('backends/ComicPressBackendAttachment.inc');
class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
}
function providerTestGenerateFromPost() {
return array(
array(array(), false),
array(array((object)array('ID' => 1)), array('attachment-1'))
);
}
/**
* @dataProvider providerTestGenerateFromPost
*/
function testGenerateFromPost($get_children_response, $expected_ids) {
_set_get_children(array(
'post_parent' => 1,
'post_type' => 'attachment',
'post_mime_type' => 'image'
), $get_children_response);
$results = ComicPressBackendAttachment::generate_from_post((object)array('ID' => 1));
if ($expected_ids === false) {
$this->assertTrue(empty($results));
} else {
$this->assertEquals(count($expected_ids), count($results));
foreach ($results as $result) {
$this->assertTrue(in_array($result->id, $expected_ids));
}
}
}
}

5
test/bootstrap.php Normal file
View File

@ -0,0 +1,5 @@
<?php
set_include_path(realpath(dirname(__FILE__) . '/../classes') . PATH_SEPARATOR . get_include_path());
?>