2009-08-07 19:50:06 +00:00
|
|
|
<?php
|
|
|
|
|
2009-11-17 03:30:35 +00:00
|
|
|
foreach (array(
|
|
|
|
'F' => 3,
|
|
|
|
'Protect' => 0,
|
|
|
|
'Restore' => 0,
|
|
|
|
'Unprotect' => 0,
|
|
|
|
'R' => 3,
|
|
|
|
'RT' => 3,
|
|
|
|
'M' => 1,
|
|
|
|
'EM' => 3
|
|
|
|
) as $function => $param_count) {
|
|
|
|
if ($param_count == 0) {
|
|
|
|
add_action("comicpress-${function}", $function, 10);
|
|
|
|
} else {
|
|
|
|
add_filter("comicpress-${function}", $function, 10, $param_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 17:46:53 +00:00
|
|
|
// Global template functions for ComicPress
|
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);
|
|
|
|
|
2009-11-13 00:12:30 +00:00
|
|
|
$comicpress = ComicPress::get_instance();
|
|
|
|
return $comicpress->find_file($name, $path, $comic_post->find_parents());
|
2009-11-07 22:18:11 +00:00
|
|
|
}
|
|
|
|
|
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-15 15:18:42 +00:00
|
|
|
function __prep_R($restrictions, $post_to_use) {
|
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-18 12:02:51 +00:00
|
|
|
default:
|
|
|
|
foreach (get_all_category_ids() as $id) {
|
|
|
|
$category = get_category($id);
|
|
|
|
if (strtolower($category->slug) == strtolower($restrictions)) {
|
|
|
|
$restrictions = array('child_of' => $category->slug);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-08 01:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 03:42:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-15 15:18:42 +00:00
|
|
|
return $restrictions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @codeCoverageIgnoreStart
|
|
|
|
|
|
|
|
function R($which, $restrictions = null, $override_post = null) {
|
|
|
|
global $post;
|
|
|
|
$post_to_use = !is_null($override_post) ? $override_post : $post;
|
|
|
|
|
|
|
|
$storyline = new ComicPressStoryline();
|
|
|
|
|
2009-11-15 15:37:43 +00:00
|
|
|
$restrictions = __prep_R($restrictions, $post_to_use);
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2009-11-17 03:30:35 +00:00
|
|
|
$post = false;
|
2009-11-08 03:00:14 +00:00
|
|
|
if (($new_post = R($which, $restrictions, $post_to_use)) !== false) {
|
|
|
|
$post = $new_post;
|
|
|
|
setup_postdata($post);
|
|
|
|
}
|
|
|
|
return $post;
|
|
|
|
}
|
|
|
|
|
2009-11-15 15:18:42 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
|
|
|
|
2009-11-09 03:11:26 +00:00
|
|
|
function M($override_post = null) {
|
2009-11-14 18:01:40 +00:00
|
|
|
global $post, $__attachments;
|
2009-11-09 03:11:26 +00:00
|
|
|
$post_to_use = !is_null($override_post) ? $override_post : $post;
|
|
|
|
|
|
|
|
$comic_post = new ComicPressComicPost($post_to_use);
|
2009-11-14 18:01:40 +00:00
|
|
|
$__attachments = $comic_post->get_attachments_with_children(true);
|
|
|
|
|
|
|
|
return $__attachments;
|
2009-11-09 03:11:26 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 17:35:48 +00:00
|
|
|
function EM($attachment_info, $which = 'default', $action = 'embed') {
|
|
|
|
if (substr($action, 0, 1) != '_') {
|
|
|
|
$args = func_get_args();
|
|
|
|
|
|
|
|
if (isset($attachment_info[$which])) {
|
|
|
|
if (($attachment = ComicPressBackend::generate_from_id($attachment_info[$which])) !== false) {
|
|
|
|
if (method_exists($attachment, $action)) {
|
|
|
|
return call_user_func_array(array($attachment, $action), array_merge(array($which), array_slice($args, 3)));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'object': return $attachment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-19 00:20:55 +00:00
|
|
|
|
|
|
|
function SL() {
|
|
|
|
$storyline = new ComicPressStoryline();
|
|
|
|
$storyline->read_from_options();
|
|
|
|
return $storyline->_structure;
|
|
|
|
}
|