updated classes from core
This commit is contained in:
parent
3a2c99444f
commit
105f1b8850
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
class ComicPressDBInterface {
|
||||
var $is_single, $in_the_loop;
|
||||
function ComicPressDBInterface() {}
|
||||
|
||||
function get_instance() {
|
||||
|
|
|
@ -11,11 +11,13 @@ class ComicPressStoryline {
|
|||
return $this;
|
||||
}
|
||||
|
||||
function _class_exists($class) { return class_exists($class); }
|
||||
|
||||
/**
|
||||
* Get the flattened storyline from options.
|
||||
*/
|
||||
function get_flattened_storyline() {
|
||||
if (class_exists('ComicPress')) {
|
||||
if ($this->_class_exists('ComicPress')) {
|
||||
$comicpress = &ComicPress::get_instance();
|
||||
if (isset($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.
|
||||
*/
|
||||
function set_flattened_storyline($storyline) {
|
||||
if (class_exists('ComicPress')) {
|
||||
if ($this->_class_exists('ComicPress')) {
|
||||
$comicpress = &ComicPress::get_instance();
|
||||
$comicpress->comicpress_options['storyline_order'] = $storyline;
|
||||
$comicpress->save();
|
||||
|
@ -151,13 +153,14 @@ class ComicPressStoryline {
|
|||
|
||||
function _get_field($field, $id) {
|
||||
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][$field])) {
|
||||
return $this->_structure[$id][$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -168,11 +171,13 @@ class ComicPressStoryline {
|
|||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function valid($id) {
|
||||
$id = $this->_ensure_numeric_category($id);
|
||||
$keys = array();
|
||||
foreach ($this->_ensure_category_ids($id) as $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) {
|
||||
|
@ -317,6 +322,8 @@ class ComicPressStoryline {
|
|||
}
|
||||
$all_categories_flattened = $this->get_category_flattened();
|
||||
|
||||
$this->normalize_category_groupings();
|
||||
|
||||
$result = $this->normalize_flattened_storyline($flattened_storyline, $all_categories_flattened);
|
||||
if ($set) {
|
||||
$this->set_flattened_storyline($result);
|
||||
|
@ -324,6 +331,24 @@ class ComicPressStoryline {
|
|||
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.
|
||||
*/
|
||||
|
@ -423,20 +448,43 @@ class ComicPressStoryline {
|
|||
return $this;
|
||||
}
|
||||
|
||||
function _ensure_numeric_category($parent) {
|
||||
if (!is_numeric($parent)) {
|
||||
function _ensure_category_ids($provided_id) {
|
||||
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) {
|
||||
$category = get_category($id);
|
||||
if ($category->slug == $parent) {
|
||||
$parent = $id; break;
|
||||
if ($category->slug == $provided_id) {
|
||||
$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) {
|
||||
$parent = $this->_ensure_numeric_category($parent);
|
||||
$all_children = array();
|
||||
foreach ($this->_ensure_category_ids($parent) as $parent) {
|
||||
if (is_numeric($parent)) {
|
||||
$children = array($parent);
|
||||
do {
|
||||
|
@ -457,9 +505,10 @@ class ComicPressStoryline {
|
|||
} while ($found_children);
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $children;
|
||||
$all_children = array_merge($all_children, $children);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return empty($all_children) ? false : $all_children;
|
||||
}
|
||||
|
||||
function &_include() {
|
||||
|
|
Loading…
Reference in New Issue