updated classes from core

This commit is contained in:
John Bintz 2009-11-26 00:27:29 -05:00
parent 3a2c99444f
commit 105f1b8850
2 changed files with 362 additions and 312 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
class ComicPressDBInterface { class ComicPressDBInterface {
var $is_single, $in_the_loop;
function ComicPressDBInterface() {} function ComicPressDBInterface() {}
function get_instance() { function get_instance() {

View File

@ -11,11 +11,13 @@ class ComicPressStoryline {
return $this; return $this;
} }
function _class_exists($class) { return class_exists($class); }
/** /**
* Get the flattened storyline from options. * Get the flattened storyline from options.
*/ */
function get_flattened_storyline() { function get_flattened_storyline() {
if (class_exists('ComicPress')) { if ($this->_class_exists('ComicPress')) {
$comicpress = &ComicPress::get_instance(); $comicpress = &ComicPress::get_instance();
if (isset($comicpress->comicpress_options['storyline_order'])) { if (isset($comicpress->comicpress_options['storyline_order'])) {
return $comicpress->comicpress_options['storyline_order']; return $comicpress->comicpress_options['storyline_order'];
@ -30,7 +32,7 @@ class ComicPressStoryline {
* Set the global storyline as a flattened storyline. * Set the global storyline as a flattened storyline.
*/ */
function set_flattened_storyline($storyline) { function set_flattened_storyline($storyline) {
if (class_exists('ComicPress')) { if ($this->_class_exists('ComicPress')) {
$comicpress = &ComicPress::get_instance(); $comicpress = &ComicPress::get_instance();
$comicpress->comicpress_options['storyline_order'] = $storyline; $comicpress->comicpress_options['storyline_order'] = $storyline;
$comicpress->save(); $comicpress->save();
@ -151,13 +153,14 @@ class ComicPressStoryline {
function _get_field($field, $id) { function _get_field($field, $id) {
if (isset($this->_structure)) { if (isset($this->_structure)) {
$id = $this->_ensure_numeric_category($id); foreach ($this->_ensure_category_ids($id) as $id) {
if (isset($this->_structure[$id])) { if (isset($this->_structure[$id])) {
if (isset($this->_structure[$id][$field])) { if (isset($this->_structure[$id][$field])) {
return $this->_structure[$id][$field]; return $this->_structure[$id][$field];
} }
} }
} }
}
return false; return false;
} }
@ -168,11 +171,13 @@ class ComicPressStoryline {
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
function valid($id) { function valid($id) {
$id = $this->_ensure_numeric_category($id); $keys = array();
foreach ($this->_ensure_category_ids($id) as $id) {
if (isset($this->_structure[$id])) { if (isset($this->_structure[$id])) {
return array_keys($this->_structure[$id]); $keys = array_merge($keys, array_keys($this->_structure[$id]));
} }
return false; }
return empty($keys) ? false : $keys;
} }
function all_adjacent($id, $direction) { function all_adjacent($id, $direction) {
@ -317,6 +322,8 @@ class ComicPressStoryline {
} }
$all_categories_flattened = $this->get_category_flattened(); $all_categories_flattened = $this->get_category_flattened();
$this->normalize_category_groupings();
$result = $this->normalize_flattened_storyline($flattened_storyline, $all_categories_flattened); $result = $this->normalize_flattened_storyline($flattened_storyline, $all_categories_flattened);
if ($set) { if ($set) {
$this->set_flattened_storyline($result); $this->set_flattened_storyline($result);
@ -324,6 +331,24 @@ class ComicPressStoryline {
return $result; return $result;
} }
/**
* @return unknown_type
*/
function normalize_category_groupings() {
$comicpress = ComicPress::get_instance();
$valid_ids = get_all_category_ids();
foreach ($comicpress->comicpress_options['category_groupings'] as $group_id => $category_ids) {
$comicpress->comicpress_options['category_groupings'][$group_id] = array_intersect($category_ids, $valid_ids);
if (empty($comicpress->comicpress_options['category_groupings'][$group_id])) {
unset($comicpress->comicpress_options['category_groupings'][$group_id]);
}
}
$comicpress->save();
}
/** /**
* Sort nodes by node count. * Sort nodes by node count.
*/ */
@ -423,20 +448,43 @@ class ComicPressStoryline {
return $this; return $this;
} }
function _ensure_numeric_category($parent) { function _ensure_category_ids($provided_id) {
if (!is_numeric($parent)) { if (!is_numeric($provided_id)) {
if (is_string($provided_id)) {
$comicpress = ComicPress::get_instance();
$found = false;
if (isset($comicpress->comicpress_options['category_groupings'])) {
if (isset($comicpress->comicpress_options['category_groupings'][$provided_id])) {
$provided_id = $comicpress->comicpress_options['category_groupings'][$provided_id];
$found = true;
}
}
if (!$found) {
foreach (get_all_category_ids() as $id) { foreach (get_all_category_ids() as $id) {
$category = get_category($id); $category = get_category($id);
if ($category->slug == $parent) { if ($category->slug == $provided_id) {
$parent = $id; break; $provided_id = $id; break;
} }
} }
$provided_id = array($provided_id);
} }
return $parent; }
} else {
$provided_id = array($provided_id);
}
if (!is_array($provided_id)) {
if (is_numeric($provided_id)) {
$provided_id = array($provided_id);
} else {
$provided_id = array();
}
}
return $provided_id;
} }
function _find_children($parent) { function _find_children($parent) {
$parent = $this->_ensure_numeric_category($parent); $all_children = array();
foreach ($this->_ensure_category_ids($parent) as $parent) {
if (is_numeric($parent)) { if (is_numeric($parent)) {
$children = array($parent); $children = array($parent);
do { do {
@ -457,9 +505,10 @@ class ComicPressStoryline {
} while ($found_children); } while ($found_children);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
return $children; $all_children = array_merge($all_children, $children);
} }
return false; }
return empty($all_children) ? false : $all_children;
} }
function &_include() { function &_include() {