comicpress-theme-core/functions.php

176 lines
5.7 KiB
PHP
Raw Normal View History

2009-06-13 11:58:02 +00:00
<?php
// load all of the comic & non-comic category information
2009-07-04 16:08:02 +00:00
add_action('init', '__comicpress_init');
function __comicpress_init() {
global $comicpress;
2009-07-13 02:41:36 +00:00
if (current_user_can('edit_files')) {
wp_cache_flush();
}
2009-07-08 23:51:02 +00:00
foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $file) {
if (is_file($file)) { require_once($file); }
}
$comicpress = new ComicPress();
$comicpress->init();
2009-07-13 02:51:15 +00:00
$addons = array();
2009-07-08 23:51:02 +00:00
if (is_dir($addons_dir = (dirname(__FILE__) . '/addons'))) {
$entries = glob($addons_dir . '/*');
if (is_array($entries)) {
foreach ($entries as $entry) {
if (is_dir($entry)) {
$classname = basename($entry);
if (file_exists($entry . "/${classname}.inc")) {
require_once($entry . "/${classname}.inc");
$classname = "ComicPressAddon${classname}";
if (class_exists($classname)) {
2009-07-13 02:51:15 +00:00
$addons[] = new $classname();
end($addons)->init(&$comicpress);
2009-07-09 00:07:52 +00:00
if (is_admin()) {
if (is_array($_POST['cp'])) {
if (isset($_POST['cp']['_nonce'])) {
if (wp_verify_nonce($_POST['cp']['_nonce'], 'comicpress')) {
2009-07-13 02:51:15 +00:00
if (method_exists(end($addons), 'handle_update')) {
end($addons)->handle_update();
2009-07-13 02:31:14 +00:00
}
2009-07-09 00:07:52 +00:00
}
2009-07-08 23:51:02 +00:00
}
}
2009-07-13 02:51:15 +00:00
add_action('admin_notices', array(end($addons), 'display_messages'));
2009-07-08 23:51:02 +00:00
}
}
}
}
}
}
}
}
2009-07-12 23:31:47 +00:00
function in_comic_category() {
global $post, $comicpress;
2009-07-09 04:57:00 +00:00
2009-07-12 23:31:47 +00:00
return $comicpress->in_comic_category($post->ID);
2009-06-13 11:58:02 +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;
}
/**
* Display the comic transcript
* Transcript must be entered into a custom field named "transcript"
* @param string $displaymode, "raw" (straight from the field), "br" (includes html line breaks), "styled" (fully css styled with JavaScript expander)
*/
function the_transcript($displaymode = 'raw') {
$transcript = get_post_meta( get_the_ID(), "transcript", true );
switch ($displaymode) {
case "raw":
echo $transcript;
break;
case "br":
echo nl2br($transcript);
break;
case "styled":
if (!empty($transcript)) { ?>
<script type='text/javascript'>
<!--
function toggle_expander(id) {
var e = document.getElementById(id);
if(e.style.height == 'auto')
e.style.height = '1px';
else
e.style.height = 'auto';
}
//-->
</script>
<div class="transcript-border"><div id="transcript"><a href="javascript:toggle_expander('transcript-content');" class="transcript-title">&darr; Transcript</a><div id="transcript-content"><?php echo nl2br($transcript); ?><br /><br /></div></div></div>
<script type='text/javascript'>
<!--
document.getElementById('transcript-content').style.height = '1px';
//-->
</script><?php
}
break;
}
}
// Register Sidebar and Define Widgets
if ( function_exists('register_sidebar') )
register_sidebar();
function widget_comicpress_latest_comics() { ?>
<li>
<h2>Latest Comics</h2>
<ul>
<?php global $post;
$latestcomics = get_posts('numberposts=5&category='.get_all_comic_categories_as_cat_string());
foreach($latestcomics as $post) : ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php } if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Latest Comics'), 'widget_comicpress_latest_comics');
function widget_comicpress_random_comic() { ?>
<li>
<h2><a href="?randomcomic"><span class="random-comic-icon">?</span> Random Comic</a></h2>
</li>
<?php } if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Random Comic'), 'widget_comicpress_random_comic');
function widget_comicpress_archive_dropdown() { ?>
<li class="archive-dropdown-wrap">
<select name="archive-dropdown" class="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo attribute_escape(__('Archives...')); ?></option>
<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>
</li>
<?php } if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Archive Dropdown'), 'widget_comicpress_archive_dropdown');
2009-07-04 16:08:02 +00:00
?>