working on a bunch of changes, things in flux
This commit is contained in:
parent
bdcd0715f6
commit
3df4ad4ff5
@ -2,13 +2,17 @@
|
||||
|
||||
class ComicPressAddonCore extends ComicPressAddon {
|
||||
function init($comicpress) {
|
||||
add_action('admin_init', array(&$this, 'add_theme_page'));
|
||||
add_action('admin_init', array(&$this, 'setup_admin_interface'));
|
||||
|
||||
$this->comicpress = $comicpress;
|
||||
}
|
||||
|
||||
function add_theme_page() {
|
||||
function setup_admin_interface() {
|
||||
add_theme_page(__("ComicPress Core", 'comicpress'), __('ComicPress Core', 'comicpress'), 'edit_themes', basename(__FILE__), array(&$this, 'render_admin'));
|
||||
|
||||
if (isset($_REQUEST['post'])) {
|
||||
add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low");
|
||||
}
|
||||
}
|
||||
|
||||
function render_admin() {
|
||||
@ -18,6 +22,10 @@ class ComicPressAddonCore extends ComicPressAddon {
|
||||
include(dirname(__FILE__) . '/partials/options-admin.inc');
|
||||
}
|
||||
|
||||
function render_comic_image_ordering() {
|
||||
echo "made it";
|
||||
}
|
||||
|
||||
function get_root_categories() {
|
||||
$root_categories = array();
|
||||
foreach (get_all_category_ids() as $id) {
|
||||
|
@ -9,6 +9,8 @@ class ComicPress {
|
||||
'category_order' => false
|
||||
);
|
||||
|
||||
var $comic_post_attachments_cache = array();
|
||||
|
||||
var $category_tree = array();
|
||||
|
||||
function load() {
|
||||
@ -32,29 +34,6 @@ class ComicPress {
|
||||
$this->sort_comic_categories();
|
||||
}
|
||||
|
||||
function get_comic_img_tag($url, $type, $additional_parameters = array()) {
|
||||
$dimensions = array();
|
||||
if (isset($this->comicpress_options["${type}_dimensions"])) {
|
||||
list($width, $height) = explode("x", $this->comicpress_options["${type}_dimensions"]);
|
||||
$dimensions = compact('width', 'height');
|
||||
}
|
||||
|
||||
$output = '<img src="' . $url . '" ';
|
||||
foreach (array('width', 'height') as $field) {
|
||||
if (!empty($dimensions[$field])) {
|
||||
$output .= $field . '="' . $dimensions[$field] . '" ';
|
||||
}
|
||||
}
|
||||
if (is_array($additional_parameters)) {
|
||||
foreach ($additional_parameters as $parameter => $value) {
|
||||
$output .= $parameter . '="' . $value . '" ';
|
||||
}
|
||||
}
|
||||
$output .= "/>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten all WP categories into nodes like 0/3/5.
|
||||
*/
|
||||
@ -194,12 +173,37 @@ class ComicPress {
|
||||
}
|
||||
|
||||
function get_adjacent_comic($category, $next = false) {
|
||||
|
||||
$categories_to_exclude = $this->non_comic_categories;
|
||||
if (!is_null($category)) {
|
||||
$categories_to_exclude = $this->get_string_to_exclude_all_but_provided_categories($category);
|
||||
}
|
||||
|
||||
return get_adjacent_post(false, $categories_to_exclude, $next);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a category ID or an array of category IDs, create an exclusion string that will
|
||||
* filter out every category but the provided ones.
|
||||
*/
|
||||
function get_string_to_exclude_all_but_provided_categories($category) {
|
||||
$category_ids = array_keys($this->get_all_category_objects_by_id());
|
||||
if (!is_array($category)) { $category = array($category); }
|
||||
return implode(",", array_diff($category_ids, $category));
|
||||
}
|
||||
|
||||
function _new_wp_query() {
|
||||
return new WP_Query();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous comic from the current one.
|
||||
*/
|
||||
function get_previous_comic($category = null) { return get_adjacent_comic($category); }
|
||||
|
||||
/**
|
||||
* Get the next comic from the current one.
|
||||
*/
|
||||
function get_next_comic($category = null) { return get_adjacent_comic($category, true); }
|
||||
}
|
||||
|
||||
?>
|
58
classes/ComicPressComicPost.inc
Normal file
58
classes/ComicPressComicPost.inc
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class ComicPressComicPost {
|
||||
var $post;
|
||||
var $attachments;
|
||||
var $comicpress;
|
||||
|
||||
function ComicPressComicPost($post = null, $comicpress = null) {
|
||||
if (!is_null($post)) { $this->post = $post; }
|
||||
if (!is_null($comicpress)) { $this->comicpress = $comicpress; }
|
||||
}
|
||||
|
||||
function get_comic_image_attachments() {
|
||||
if (!isset($this->attachments)) {
|
||||
$this->attachments = get_children(array(
|
||||
'post_parent' => $this->post->ID,
|
||||
'post_type' => 'attachment',
|
||||
'post_mime_type' => 'image'
|
||||
));
|
||||
}
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
function display_comics() {
|
||||
foreach ($this->get_comic_image_attachments() as $attachment) {
|
||||
echo $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID), "comic", array('title' => $attachment->post_title));
|
||||
}
|
||||
}
|
||||
|
||||
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"]);
|
||||
$dimensions = compact('width', 'height');
|
||||
}
|
||||
|
||||
$output = '<img src="' . $url . '" ';
|
||||
foreach (array('width', 'height') as $field) {
|
||||
if (!empty($dimensions[$field])) {
|
||||
$output .= $field . '="' . $dimensions[$field] . '" ';
|
||||
}
|
||||
}
|
||||
if (is_array($additional_parameters)) {
|
||||
foreach ($additional_parameters as $parameter => $value) {
|
||||
$output .= $parameter . '="' . $value . '" ';
|
||||
}
|
||||
}
|
||||
$output .= "/>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function normalize_attachment_sorting() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -74,7 +74,7 @@ function __comicpress_init() {
|
||||
}
|
||||
}
|
||||
|
||||
get_all_comic_categories();
|
||||
//get_all_comic_categories();
|
||||
}
|
||||
|
||||
function the_comic_img_tag($url, $type, $additional_parameters = array()) {
|
||||
@ -105,16 +105,6 @@ function get_last_comic_permalink() {
|
||||
return !empty($terminal) ? get_permalink($terminal->ID) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a category ID or an array of category IDs, create an exclusion string that will
|
||||
* filter out every category but the provided ones.
|
||||
*/
|
||||
function get_string_to_exclude_all_but_provided_categories($category) {
|
||||
$category_ids = array_keys(get_all_category_objects_by_id());
|
||||
if (!is_array($category)) { $category = array($category); }
|
||||
return implode(",", array_diff($category_ids, $category));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to the previous comic from the current one.
|
||||
*/
|
||||
@ -131,16 +121,6 @@ function next_comic_link($format, $link) {
|
||||
next_post_link($format, $link, false, $non_comic_categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous comic from the current one.
|
||||
*/
|
||||
function get_previous_comic($category = null) { return get_adjacent_comic($category); }
|
||||
|
||||
/**
|
||||
* Get the next comic from the current one.
|
||||
*/
|
||||
function get_next_comic($category = null) { return get_adjacent_comic($category, true); }
|
||||
|
||||
/**
|
||||
* Get the adjacent comic from the current one.
|
||||
* @param int $category The category to use.
|
||||
@ -148,14 +128,6 @@ function get_next_comic($category = null) { return get_adjacent_comic($category,
|
||||
* @return array The WordPress post object for the comic post.
|
||||
*/
|
||||
function get_adjacent_comic($category, $next = false) {
|
||||
global $non_comic_categories;
|
||||
|
||||
$categories_to_exclude = $non_comic_categories;
|
||||
if (!is_null($category)) {
|
||||
$categories_to_exclude = get_string_to_exclude_all_but_provided_categories($category);
|
||||
}
|
||||
|
||||
return get_adjacent_post(false, $categories_to_exclude, $next);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -208,8 +180,6 @@ function get_comic_url($folder = 'comic', $override_post = null, $filter = 'defa
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ComicPress Template Functions
|
||||
|
||||
function the_comic($filter = 'default') { echo get_comic_url('comic', null, $filter); }
|
||||
|
14
header.php
14
header.php
@ -35,20 +35,6 @@
|
||||
|
||||
<div id="menubar">
|
||||
|
||||
<div id="menunav">
|
||||
<?php if (is_home()) {
|
||||
$comicFrontpage = new WP_Query(); $comicFrontpage->query('showposts=1&cat='.get_all_comic_categories_as_cat_string());
|
||||
while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post();
|
||||
global $wp_query; $wp_query->is_single = true;
|
||||
previous_comic_link('%link', '‹');
|
||||
$wp_query->is_single = false;
|
||||
endwhile;
|
||||
} elseif (is_single() & in_comic_category()) {
|
||||
previous_comic_link('%link', '‹');
|
||||
next_comic_link('%link', '›');
|
||||
} ?>
|
||||
</div>
|
||||
|
||||
<ul id="menu">
|
||||
<li><a href="<?php bloginfo('url') ?>">Home</a></li>
|
||||
<?php wp_list_pages('sort_column=menu_order&depth=4&title_li=') ?>
|
||||
|
17
index.php
17
index.php
@ -1,16 +1,21 @@
|
||||
<?php get_header(); global $blog_postcount, $blogcat; $first_comic = get_first_comic_permalink() ?>
|
||||
<?php get_header(); global $comicpress, $blog_postcount, $blogcat; $first_comic = get_first_comic_permalink() ?>
|
||||
|
||||
<?php if (!(is_paged())) { ?>
|
||||
|
||||
<?php $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('showposts=1&cat='.get_all_comic_categories_as_cat_string());
|
||||
while ($comicFrontpage->have_posts()) : $comicFrontpage->the_post() ?>
|
||||
<?php $wp_query->in_the_loop = true; $comicFrontpage = new WP_Query(); $comicFrontpage->query('showposts=1&cat='.$comicpress->get_all_comic_categories_as_cat_string());
|
||||
while ($comicFrontpage->have_posts()) {
|
||||
$comicFrontpage->the_post();
|
||||
|
||||
$comic_post = new ComicPressComicPost(&$post, &$comicpress);
|
||||
|
||||
?>
|
||||
|
||||
<div id="comic-head"></div>
|
||||
<div id="comic">
|
||||
<?php the_comic_img_tag(get_comic_url('comic'), 'comic', array('alt' => get_the_title(),
|
||||
'title' => get_the_hovertext())) ?>
|
||||
<?php $comic_post->display_comics() ?>
|
||||
</div>
|
||||
<div id="comic-foot"></div>
|
||||
<?php endwhile; ?>
|
||||
<?php } ?>
|
||||
|
||||
<div id="content" class="narrowcolumn">
|
||||
|
||||
|
55
test/ComicPressComicPostTest.php
Normal file
55
test/ComicPressComicPostTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
||||
require_once(dirname(__FILE__) . '/../classes/ComicPressComicPost.inc');
|
||||
|
||||
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
_reset_wp();
|
||||
$this->p = new ComicPressComicPost();
|
||||
}
|
||||
|
||||
function providerTestGenerateComicTag() {
|
||||
return array(
|
||||
array(
|
||||
"150x150",
|
||||
),
|
||||
array(
|
||||
false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGenerateComicTag
|
||||
*/
|
||||
function testGenerateComicImgTag($dimensions) {
|
||||
$this->p->comicpress = (object)array(
|
||||
'comicpress_options' => array(
|
||||
'comic_dimensions' => $dimensions
|
||||
)
|
||||
);
|
||||
|
||||
$source = $this->p->get_comic_img_tag("test.gif", "comic");
|
||||
|
||||
if (count($parts = explode("x", $dimensions)) == 2) {
|
||||
list($width, $height) = $parts;
|
||||
$dimensions = compact('width', 'height');
|
||||
}
|
||||
|
||||
foreach (array('width', 'height') as $field) {
|
||||
if (isset($dimensions[$field])) {
|
||||
$this->assertTrue(strpos($source, "${field}=\"{$dimensions[$field]}\"") !== false, $field);
|
||||
} else {
|
||||
$this->assertTrue(strpos($source, "${field}=") === false, 'not set');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testNormalizeAttachmentSorting() {
|
||||
update_post_meta(1, 'comic_order', '2,1')
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -9,39 +9,6 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||
_reset_wp();
|
||||
$this->cp = new ComicPress();
|
||||
}
|
||||
|
||||
function providerTestGenerateComicTag() {
|
||||
return array(
|
||||
array(
|
||||
"150x150",
|
||||
),
|
||||
array(
|
||||
false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGenerateComicTag
|
||||
*/
|
||||
function testGenerateComicImgTag($dimensions) {
|
||||
$this->cp->comicpress_options['comic_dimensions'] = $dimensions;
|
||||
|
||||
$source = $this->cp->get_comic_img_tag("test.gif", "comic");
|
||||
|
||||
if (count($parts = explode("x", $dimensions)) == 2) {
|
||||
list($width, $height) = $parts;
|
||||
$dimensions = compact('width', 'height');
|
||||
}
|
||||
|
||||
foreach (array('width', 'height') as $field) {
|
||||
if (isset($dimensions[$field])) {
|
||||
$this->assertTrue(strpos($source, "${field}=\"{$dimensions[$field]}\"") !== false, $field);
|
||||
} else {
|
||||
$this->assertTrue(strpos($source, "${field}=") === false, 'not set');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testFlattenCategories() {
|
||||
$cp = $this->getMock('ComicPress', array('get_all_category_objects_by_id'));
|
||||
|
Loading…
Reference in New Issue
Block a user