comicpress-core/functions.php

175 lines
4.3 KiB
PHP
Raw Normal View History

2009-08-07 19:50:06 +00:00
<?php
// load all of the comic & non-comic category information
add_action('init', '__comicpress_init');
function __comicpress_init() {
global $comicpress, $wp_query;
2009-11-08 01:56:49 +00:00
2009-08-07 19:50:06 +00:00
if (current_user_can('edit_files')) {
wp_cache_flush();
}
2009-11-04 02:45:56 +00:00
$classes_search = array(
'/classes/',
'/classes/backends/'
);
foreach ($classes_search as $path) {
foreach (glob(dirname(__FILE__) . $path . '*.inc') as $file) {
if (is_file($file)) {
require_once($file);
}
2009-11-04 02:45:56 +00:00
}
2009-08-07 19:50:06 +00:00
}
2009-11-01 18:15:59 +00:00
$comicpress = ComicPress::get_instance();
2009-08-07 19:50:06 +00:00
$comicpress->init();
$comicpress_admin = new ComicPressAdmin();
$comicpress_admin->init();
$comicpress_admin->handle_update();
$comicpress_filters = new ComicPressFilters();
$comicpress_filters->init();
2009-08-07 19:50:06 +00:00
}
2009-11-07 22:18:11 +00:00
function F($name, $path, $override_post = null) {
global $post;
2009-11-08 01:56:49 +00:00
2009-11-07 22:18:11 +00:00
$comic_post = new ComicPressComicPost(is_null($override_post) ? $post : $override_post);
return ComicPress::get_instance()->find_file($name, $path, $comic_post->find_parents());
}
2009-11-08 01:56:49 +00:00
/**
* Finish rendering this template and shove the output into application.php.
*/
function finish_comicpress() {
2009-11-07 22:40:16 +00:00
$content = ob_get_clean();
2009-11-08 01:56:49 +00:00
2009-11-07 22:40:16 +00:00
include(F('application.php', ''));
}
2009-11-08 01:56:49 +00:00
/**
* Protect global $post and $wp_query.
*/
2009-11-08 03:00:14 +00:00
function Protect() {
2009-11-08 01:56:49 +00:00
global $post, $wp_query, $__post, $__wp_query;
$__post = $post;
$__wp_query = $wp_query;
}
2009-11-08 03:00:14 +00:00
/**
* Temporarily restore the global $post variable and set it up for use.
*/
function Restore() {
global $post, $__post;
$post = $__post;
setup_postdata($post);
}
2009-11-08 01:56:49 +00:00
/**
* Restore global $post and $wp_query.
*/
2009-11-08 03:00:14 +00:00
function Unprotect() {
2009-11-08 01:56:49 +00:00
global $post, $wp_query, $__post, $__wp_query;
$post = $__post;
$wp_query = $__wp_query;
$__post = $__wp_query = null;
}
2009-11-08 03:00:14 +00:00
function R($which, $restrictions = null, $override_post = null) {
2009-11-08 01:56:49 +00:00
global $post;
2009-11-08 03:00:14 +00:00
$post_to_use = !is_null($override_post) ? $override_post : $post;
2009-11-08 01:56:49 +00:00
$storyline = new ComicPressStoryline();
2009-11-08 03:00:14 +00:00
if (is_string($restrictions)) {
switch ($restrictions) {
case 'from_post':
$restrictions = array('from_post' => $post_to_use);
break;
2009-11-08 01:56:49 +00:00
}
}
2009-11-08 03:00:14 +00:00
$categories = $storyline->build_from_restrictions($restrictions);
2009-11-08 01:56:49 +00:00
$dbi = ComicPressDBInterface::get_instance();
$new_post = false;
switch ($which) {
2009-11-08 03:00:14 +00:00
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;
2009-11-08 01:56:49 +00:00
}
return $new_post;
}
2009-11-08 03:00:14 +00:00
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;
}
2009-08-07 19:50:06 +00:00
/**
* Display the list of Storyline categories.
*/
function comicpress_list_storyline_categories($args = "") {
global $category_tree;
$defaults = array(
'style' => 'list', 'title_li' => __('Storyline')
);
$r = wp_parse_args($args, $defaults);
extract($r);
$categories_by_id = get_all_category_objects_by_id();
$output = '';
if ($style == "list") { $output .= '<li class="categories storyline">'; }
if ($title_li && ($style == "list")) { $output .= $title_li; }
if ($style == "list") { $output .= "<ul>"; }
$current_depth = 0;
foreach ($category_tree as $node) {
$parts = explode("/", $node);
$category_id = end($parts);
$target_depth = count($parts) - 2;
if ($target_depth > $current_depth) {
$output .= str_repeat("<li><ul>", ($target_depth - $current_depth));
}
if ($target_depth < $current_depth) {
$output .= str_repeat("</ul></li>", ($current_depth - $target_depth));
}
$output .= '<li><a href="' . get_category_link($category_id) . '">';
$output .= $categories_by_id[$category_id]->cat_name;
$output .= "</a></li>";
$current_depth = $target_depth;
}
if ($current_depth > 0) {
$output .= str_repeat("</ul></li>", $current_depth);
}
if ($style == "list") { $output .= "</ul></li>"; }
echo $output;
}
2009-11-07 22:40:16 +00:00
ob_start();
?>