function cpm_action_delete_comic_and_post() { global $cpm_config; $comic_file = pathinfo($_POST['comic'], PATHINFO_BASENAME); if (file_exists($cpm_config->path . '/' . $comic_file)) { if (($result = cpm_breakdown_comic_filename($comic_file)) !== false) { extract($result, EXTR_PREFIX_ALL, 'filename'); $all_possible_posts = array(); foreach (cpm_query_posts() as $comic_post) { if (date(CPM_DATE_FORMAT, strtotime($comic_post->post_date)) == $filename_date) { $all_possible_posts[] = $comic_post->ID; } } if (count($all_possible_posts) > 1) { $cpm_config->messages[] = sprintf(__('There are multiple posts (%1$s) with the date %2$s in the comic categories. Please manually delete the posts.', 'comicpress-manager'), implode(", ", $all_possible_posts), $filename_date); } else { $delete_targets = array($cpm_config->path . '/' . $comic_file); foreach ($cpm_config->thumbs_folder_writable as $type => $value) { $delete_targets[] = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties[$type . "_comic_folder"] . '/' . $comic_file; } foreach ($delete_targets as $target) { @unlink($target); } if (count($all_possible_posts) == 0) { $cpm_config->messages[] = sprintf(__("<strong>%s deleted.</strong> No matching posts found. Any associated thumbnails were also deleted.", 'comicpress-manager'), $comic_file); } else { wp_delete_post($all_possible_posts[0]); $cpm_config->messages[] = sprintf(__('<strong>%1$s and post %2$s deleted.</strong> Any associated thumbnails were also deleted.', 'comicpress-manager'), $comic_file, $all_possible_posts[0]); } $cpm_config->comic_files = cpm_read_comics_folder(); } } } }
/** * Show the Latest Posts in the Sidebar. */ function cpm_show_latest_posts() { global $cpm_config; $is_current = false; $is_previous = false; $current_timestamp = time(); foreach (cpm_query_posts() as $comic_post) { $timestamp = strtotime($comic_post->post_date); if ($timestamp < $current_timestamp) { $is_current = true; } if ($is_current) { if ($is_previous) { $previous_post = $comic_post; break; } $current_post = $comic_post; $is_previous = true; } else { $upcoming_post = $comic_post; } } $found_posts = compact('previous_post', 'current_post', 'upcoming_post'); $post_titles = array('previous_post' => __("Last Post", 'comicpress-manager'), 'current_post' => __("Current Post", 'comicpress-manager'), 'upcoming_post' => __("Upcoming Post", 'comicpress-manager')); ?> <div id="comicpress-latest-posts"> <?php if (!empty($found_posts)) { ?> <?php foreach ($post_titles as $key => $title) { if (!empty($found_posts[$key])) { $timestamp = strtotime($found_posts[$key]->post_date); $post_date = date(CPM_DATE_FORMAT, $timestamp); $comic_file = null; foreach ($cpm_config->comic_files as $file) { if (($result = cpm_breakdown_comic_filename(pathinfo($file, PATHINFO_BASENAME))) !== false) { if ($result['date'] == $post_date) { $comic_file = $file; break; } } } ?> <div class="<?php echo !empty($comic_file) ? "comic-found" : "comic-not-found"; ?> "> <h3><?php echo $title; ?> — <?php echo $post_date; ?> </h3> <h4><?php echo $found_posts[$key]->post_title; ?> [<?php echo generate_view_edit_post_links((array) $found_posts[$key]); ?> ]</h4> <?php if (!empty($comic_file)) { ?> <img alt="<?php echo $found_posts[$key]->post_title; ?> " src="<?php echo cpm_build_comic_uri($file, CPM_DOCUMENT_ROOT); ?> " width="320" /> <?php } else { ?> <div class="alert">Comic file not found!</div> <?php } ?> </div> <?php } } } else { ?> <p>You don't have any comic posts!</p> <?php } ?> </div> <?php }
require_once 'comicpress_manager_config.php'; require_once 'comicpress_manager_library.php'; cpm_get_cpm_document_root(); $cpm_config = new ComicPressConfig(); cpm_read_information_and_check_config(); if (isset($_REQUEST['blog_id']) && function_exists('switch_to_blog')) { switch_to_blog((int) $_REQUEST['blog_id']); } // TODO: handle different comic categories differently, this is still too geared // toward one blog/one comic... $all_post_dates = array(); $format = CPM_DATE_FORMAT; if (isset($_POST['format'])) { $format = $_POST['format']; } foreach (cpm_query_posts() as $comic_post) { $all_post_dates[] = date($format, strtotime($comic_post->post_date)); } $all_post_dates = array_unique($all_post_dates); ob_start(); $missing_comic_count = 0; foreach (cpm_read_comics_folder() as $comic_file) { $comic_file = pathinfo($comic_file, PATHINFO_BASENAME); if (($result = cpm_breakdown_comic_filename($comic_file, $format)) !== false) { if (!in_array($result['date'], $all_post_dates)) { if (($post_hash = generate_post_hash($result['date'], $result['converted_title'])) !== false) { $missing_comic_count++; } } } }
function cpm_action_build_storyline_schema() { global $cpm_config; update_option('comicpress-enable-storyline-support', isset($_POST['enable-storyline-support']) ? 1 : 0); update_option('comicpress-storyline-show-top-category', isset($_POST['show-top-category']) ? 1 : 0); if (isset($_POST['enable-storyline-support'])) { $cpm_config->is_cpm_modifying_categories = true; $categories_to_create = array(); $categories_to_rename = array(); $category_ids_to_clean = array(); extract(cpm_get_all_comic_categories()); $comic_posts = cpm_query_posts(); $comic_posts_by_category_id = array(); foreach ($comic_posts as $post) { foreach (wp_get_post_categories($post->ID) as $category) { if (!isset($comic_posts_by_category_id[$category])) { $comic_posts_by_category_id[$category] = array(); } $comic_posts_by_category_id[$category][] = $post->ID; } } foreach ($_POST as $field => $value) { $value = stripslashes($value); $parts = explode("/", $field); if ($parts[0] == "0" && count($parts) > 1) { $category_id = end($parts); $category = get_category($category_id); if (!empty($category)) { $category = (array) $category; if ($category['cat_name'] != $value) { $cpm_config->messages[] = sprintf(__('Category <strong>%1$s</strong> renamed to <strong>%2$s</strong>.', 'comicpress-manager'), $category['cat_name'], $value); $category['cat_name'] = $value; wp_update_category($category); $category_ids_to_clean[] = $category_id; } } else { $categories_to_create[$field] = $value; } if (($index = array_search($field, $category_tree)) !== false) { array_splice($category_tree, $index, 1); } } } if (isset($_POST['original-categories'])) { foreach (explode(",", $_POST['original-categories']) as $node) { if (!isset($_POST[$node])) { $category_id = end(explode("/", $node)); $category = get_category($category_id); $original_cat_name = $category->cat_name; // ensure that we're not deleting a ComicPress category $ok = true; foreach (array('comiccat', 'blogcat') as $type) { if ($category_id == $cpm_config->properties[$type]) { $ok = false; } } // ensure that the category truly is a child of the comic category if ($ok) { $category = get_category($category_id); $ok = false; if (!is_wp_error($category)) { while ($category->parent != 0 && $category->parent != $cpm_config->properties['comiccat']) { $category = get_category($category->parent); } if ($category->parent == $cpm_config->properties['comiccat']) { $ok = true; } } } if ($ok) { wp_delete_category($category_id); $category_ids_to_clean[] = $category_id; $cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> deleted.', 'comicpress-manager'), $original_cat_name); } } } } uksort($categories_to_create, 'cpm_sort_category_keys_by_length'); $changed_field_ids = array(); $removed_field_ids = array(); $target_category_ids = array(); foreach ($categories_to_create as $field => $value) { $original_field = $field; foreach ($changed_field_ids as $changed_field => $new_field) { if (strpos($field, $changed_field) === 0 && strlen($field) > strlen($changed_field)) { $field = str_replace($changed_field, $new_field, $field); break; } } $parts = explode("/", $field); $target_id = array_pop($parts); $parent_id = array_pop($parts); if (!category_exists($value)) { $category_id = wp_create_category($value, $parent_id); $category_ids_to_clean[] = $category_id; array_push($parts, $parent_id); array_push($parts, $category_id); $changed_field_ids[$original_field] = implode("/", $parts); $cpm_config->messages[] = sprintf(__('Category <strong>%s</strong> created.', 'comicpress-manager'), $value); } else { $cpm_config->warnings[] = sprintf(__("The category %s already exists. Please enter a new name.", 'comicpress-manager'), $value); $removed_field_ids[] = $field; } } $order = array_diff(explode(",", $_POST['order']), $removed_field_ids); for ($i = 0; $i < count($order); ++$i) { if (isset($changed_field_ids[$order[$i]])) { $order[$i] = $changed_field_ids[$order[$i]]; } } // ensure we're writing sane data $new_order = array(); $valid_comic_categories = array(); foreach ($order as $node) { $parts = explode("/", $node); if ($parts[0] == "0" && count($parts) > 1) { $new_order[] = $node; $valid_comic_categories[] = end($parts); } } $comic_categories_preserved = array(); foreach ($comic_posts as $post) { $categories = wp_get_post_categories($post->ID); if (count(array_intersect($valid_comic_categories, $categories)) == 0) { $all_parent_categories = array(); foreach ($comic_posts_by_category_id as $category => $post_ids) { if (in_array($post->ID, $post_ids)) { foreach ($new_order as $node) { $parts = explode("/", $node); if ($category == end($parts)) { $parts = explode("/", $node); array_pop($parts); if (count($parts) > 1) { $all_parent_categories[] = implode("/", $parts); } } } } } if (count($all_parent_categories) > 0) { foreach ($all_parent_categories as $category_node) { if (in_array($category_node, $new_order)) { $categories[] = end(explode("/", $category_node)); } } } else { $categories[] = $cpm_config->properties['comiccat']; } wp_set_post_categories($post->ID, $categories); $comic_categories_preserved[] = $post->ID; } } if (count($comic_categories_preserved) > 0) { $cpm_config->messages[] = sprintf(__("The following orphaned comic posts were placed into their original category's parent: <strong>%s</strong>"), implode(", ", $comic_categories_preserved)); } $cpm_config->messages[] = __('Storyline structure saved.', 'comicpress-manager'); update_option("comicpress-storyline-category-order", implode(",", $new_order)); clean_term_cache($category_ids_to_clean, 'category'); wp_cache_flush(); } }
function cpm_action_change_dates() { global $cpm_config; $comic_posts_to_date_shift = array(); $comic_files_to_date_shift = array(); $comic_post_target_date_counts = array(); $wp_date_string_length = strlen(date("Y-m-d")); $cpm_date_string_length = strlen(date(CPM_DATE_FORMAT)); $cpm_config->is_cpm_managing_posts = true; // find all comic files that will be shifted foreach ($cpm_config->comic_files as $comic_file) { $comic_filename = pathinfo($comic_file, PATHINFO_BASENAME); $filename_info = cpm_breakdown_comic_filename($comic_filename); $key = md5($comic_file); if (isset($_POST['dates'][$key])) { if ($_POST['dates'][$key] != $filename_info['date']) { $timestamp = strtotime($_POST['dates'][$key]); if ($timestamp !== false && $timestamp !== -1) { $target_date = date(CPM_DATE_FORMAT, $timestamp); $new_comic_filename = $target_date . substr($comic_filename, $cpm_date_string_length); $comic_posts_to_date_shift[strtotime($filename_info['date'])] = $timestamp; if (!isset($comic_post_target_date_counts[$timestamp])) { $comic_post_target_date_counts[$timestamp] = 0; } $comic_post_target_date_counts[$timestamp]++; if (!isset($comic_files_to_date_shift[$timestamp])) { $comic_files_to_date_shift[$timestamp] = array($comic_filename, $new_comic_filename); } } } } } $comic_posts_to_change = array(); $all_posts = cpm_query_posts(); // get the target dates for all files to move if (count($comic_posts_to_date_shift) > 0) { foreach ($all_posts as $comic_post) { $post_date_day = substr($comic_post->post_date, 0, $wp_date_string_length); $post_date_day_timestamp = strtotime($post_date_day); if (isset($comic_posts_to_date_shift[$post_date_day_timestamp])) { if ($comic_post_target_date_counts[$comic_posts_to_date_shift[$post_date_day_timestamp]] == 1) { $new_post_date = date("Y-m-d", $comic_posts_to_date_shift[$post_date_day_timestamp]) . substr($comic_post->post_date, $wp_date_string_length); $comic_posts_to_change[$comic_post->ID] = array($comic_post, $new_post_date); } } } } $final_post_day_counts = array(); // intersect all existing and potential new posts, counting how many // posts occur on each day foreach ($all_posts as $comic_post) { if (isset($comic_posts_to_change[$comic_post->ID])) { $date_to_use = $comic_posts_to_change[$comic_post->ID][1]; } else { $date_to_use = $comic_post->post_date; } $day_to_use = strtotime(substr($date_to_use, 0, $wp_date_string_length)); if (!isset($final_post_day_counts[$day_to_use])) { $final_post_day_counts[$day_to_use] = 0; } $final_post_day_counts[$day_to_use]++; } $posts_moved = array(); // move what can be moved foreach ($comic_posts_to_change as $id => $info) { list($comic_post, $new_post_date) = $info; $new_post_day = strtotime(substr($new_post_date, 0, $wp_date_string_length)); if ($final_post_day_counts[$new_post_day] == 1) { $old_post_date = $comic_post->post_date; $comic_post->post_date = $new_post_date; $comic_post->post_date_gmt = get_gmt_from_date($new_post_date); wp_update_post($comic_post); $cpm_config->messages[] = sprintf(__('<strong>Post %1$s moved to %2$s.</strong>', 'comicpress-manager'), $id, date("Y-m-d", $new_post_day)); $posts_moved[$new_post_day] = array($comic_post, $old_post_date); } else { $cpm_config->warnings[] = sprintf(__('<strong>Moving post %1$s to %2$s would cause two comic posts to exist on the same day.</strong> This is not allowed in the automated process.', 'comicpress-manager'), $id, date("Y-m-d", $new_post_day)); } } // try to move all the files, and roll back any changes to files and posts that fail foreach ($comic_post_target_date_counts as $target_date => $count) { if (!isset($final_post_day_counts[$target_date]) || $final_post_day_counts[$target_date] == 1) { if ($count > 1) { $cpm_config->warnings[] = sprintf(__("<strong>You are moving two comics to the same date: %s.</strong> This is not allowed in the automated process.", 'comicpress-manager'), $target_date); } else { list($comic_filename, $new_comic_filename) = $comic_files_to_date_shift[$target_date]; $roll_back_change = false; $calculate_do_move = array(); foreach (array(array(__('comic folder', 'comicpress-manager'), 'comic_folder', ""), array(__('RSS feed folder', 'comicpress-manager'), 'rss_comic_folder', "rss"), array(__('Mini thumb folder', 'comicpress-manager'), 'mini_comic_folder', "rss"), array(__('archive folder', 'comicpress-manager'), 'archive_comic_folder', "archive")) as $folder_info) { list($name, $property, $type) = $folder_info; $do_move = true; if ($type != "") { if ($cpm_config->separate_thumbs_folder_defined[$type]) { if ($cpm_config->thumbs_folder_writable[$type]) { $do_move = cpm_option("{$type}-generate-thumbnails") == 1; } } $calculate_do_move[$type] = $do_move; } if ($do_move) { $path = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties[$property]; if (!file_exists($path)) { $cpm_config->errors[] = sprintf(__('The %1$s <strong>%2$s</strong> does not exist.', 'comicpress-manager'), $name, $cpm_config->properties[$property]); $roll_back_change = true; } else { if (file_exists($path . '/' . $comic_filename)) { if (@rename($path . '/' . $comic_filename, $path . '/' . $new_comic_filename)) { $cpm_config->messages[] = sprintf(__('<strong>Rename %1$s file %2$s to %3$s.</strong>', 'comicpress-manager'), $name, $comic_filename, $new_comic_filename); } else { $cpm_config->warnings[] = sprintf(__('<strong>The renaming of %1$s to %2$s failed.</strong> Check the permissions on %3$s', 'comicpress-manager'), $comic_filename, $new_comic_filename, $path); $roll_back_change = true; } } } } } if ($roll_back_change) { foreach (array(array(__('comic folder', 'comicpress-manager'), 'comic_folder', ""), array(__('RSS feed folder', 'comicpress-manager'), 'rss_comic_folder', "rss"), array(__('Mini thumb folder', 'comicpress-manager'), 'mini_comic_folder', "rss"), array(__('archive folder', 'comicpress-manager'), 'archive_comic_folder', "archive")) as $folder_info) { list($name, $property) = $folder_info; $do_move = isset($calculate_do_move[$type]) ? $calculate_do_move[$type] : true; if ($do_move) { $path = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties[$property]; if (file_exists($path . '/' . $new_comic_filename)) { @rename($path . '/' . $new_comic_filename, $path . '/' . $comic_filename); $cpm_config->messages[] = sprintf(__("<strong>Rolling back %s.</strong>", 'comicpress-manager'), $new_comic_filename); } } } if (isset($posts_moved[$target_date])) { list($comic_post, $old_post_date) = $posts_moved[$target_date]; $comic_post->post_date = $old_post_date; $comic_post->post_date_gmt = get_gmt_from_date($old_post_date); wp_update_post($comic_post); $cpm_config->messages[] = sprintf(__('<strong>Rename error, rolling back post %1$s to %2$s.</strong>', 'comicpress-manager'), $comic_post->ID, $old_post_date); } } } } } $cpm_config->comic_files = cpm_read_comics_folder(); }
function cpm_action_create_missing_posts() { global $cpm_config; $all_post_dates = array(); foreach (cpm_query_posts() as $comic_post) { $all_post_dates[] = date(CPM_DATE_FORMAT, strtotime($comic_post->post_date)); } $all_post_dates = array_unique($all_post_dates); $duplicate_posts_within_creation = array(); $posts_created = array(); $thumbnails_written = array(); $thumbnails_not_written = array(); $invalid_filenames = array(); $duplicate_posts = array(); $new_thumbnails_not_needed = array(); $execution_time = ini_get("max_execution_time"); $max_posts_imported = (int) ($execution_time / 2); $imported_post_count = 0; $safe_exit = false; if (strtotime($_POST['time']) === false) { $cpm_config->warnings[] = sprintf(__('<strong>There was an error in the post time (%1$s)</strong>. The time is not parseable by strtotime().', 'comicpress-manager'), $_POST['time']); } else { foreach ($cpm_config->comic_files as $comic_file) { $comic_file = pathinfo($comic_file, PATHINFO_BASENAME); if (($result = cpm_breakdown_comic_filename($comic_file)) !== false) { extract($result, EXTR_PREFIX_ALL, 'filename'); $ok_to_create_post = !in_array($result['date'], $all_post_dates); $show_duplicate_post_message = false; $post_id = null; if (isset($duplicate_posts_within_creation[$result['date']])) { $ok_to_create_post = false; $show_duplicate_post_message = true; $post_id = $duplicate_posts_within_creation[$result['date']]; } if ($ok_to_create_post) { if (isset($_POST['duplicate_check'])) { $ok_to_create_post = ($post_id = post_exists($post_title, $post_content, $post_date)) == 0; } } else { if (!isset($_POST['duplicate_check'])) { $ok_to_create_post = true; } } if ($ok_to_create_post) { if (($post_hash = generate_post_hash($filename_date, $filename_converted_title)) !== false) { if (!is_null($post_id = wp_insert_post($post_hash))) { $imported_post_count++; $posts_created[] = get_post($post_id, ARRAY_A); $date = date(CPM_DATE_FORMAT, strtotime($filename_date)); $all_post_dates[] = $date; $duplicate_posts_within_creation[$date] = $post_id; foreach (array('hovertext', 'transcript') as $field) { if (!empty($_POST["{$field}-to-use"])) { update_post_meta($post_id, $field, $_POST["{$field}-to-use"]); } } if (isset($_POST['thumbnails'])) { $wrote_thumbnail = cpm_write_thumbnail($cpm_config->path . '/' . $comic_file, $comic_file); if (!is_null($wrote_thumbnail)) { if ($wrote_thumbnail) { $thumbnails_written[] = $comic_file; } else { $thumbnails_not_written[] = $comic_file; } } else { $new_thumbnails_not_needed[] = $comic_file; } } } } else { $invalid_filenames[] = $comic_file; } } else { if ($show_duplicate_post_message) { $duplicate_posts[] = array(get_post($post_id, ARRAY_A), $comic_file); } } } if ($imported_post_count >= $max_posts_imported) { $safe_exit = true; break; } } } $cpm_config->import_safe_exit = $safe_exit; if ($safe_exit) { $cpm_config->messages[] = __("<strong>Import safely exited before you ran out of execution time.</strong> Scroll down to continue creating missing posts.", 'comicpress-manager'); } if (count($posts_created) > 0) { cpm_display_operation_messages(compact('invalid_filenames', 'thumbnails_written', 'thumbnails_not_written', 'posts_created', 'duplicate_posts', 'new_thumbnails_not_needed')); } else { $cpm_config->messages[] = __("<strong>No new posts needed to be created.</strong>", 'comicpress-manager'); } }
/** * The generate status dialog. */ function cpm_manager_status() { global $cpm_config; $cpm_config->need_calendars = true; if (cpm_get_subcomic_directory() !== false) { $cpm_config->messages[] = sprintf(__("<strong>Reminder:</strong> You are managing the <strong>%s</strong> comic subdirectory.", 'comicpress-manager'), get_cat_name(get_option('comicpress-manager-manage-subcomic'))); } if (cpm_option('cpm-skip-checks') != 1) { if (!function_exists('get_comic_path')) { $cpm_config->warnings[] = __('<strong>It looks like you\'re running an older version of ComicPress.</strong> Storyline, hovertext, and transcript are fully supported in <a href="http://comicpress.org/">ComicPress 2.7</a>. You can use hovertext and transcripts in earlier themes by using <tt>get_post_meta($post->ID, "hovertext", true)</tt> and <tt>get_post_meta($post->ID, "transcript", true)</tt>.', 'comicpress-manager'); } } ob_start(); ?> <h2 style="padding-right:0;"><?php _e("Bulk Edit", 'comicpress-manager'); ?> </h2> <p><strong>ComicPress-related information, such as transcripts and Storyline categories for posts, and thumbnail regeneration, can be bulk edited here.</strong> To edit post-specific information, such as title and publishing date, use <strong><a href="edit.php">Edit Posts</a></strong>. <?php $data_by_date = array(); $dates_per_page = 15; foreach ($cpm_config->comic_files as $comic_filepath) { $comic_file = pathinfo($comic_filepath, PATHINFO_BASENAME); if (($result = cpm_breakdown_comic_filename($comic_file)) !== false) { $timestamp = strtotime($result['date']); $comic_date = date("Y-m-d", $timestamp); if (!isset($data_by_date[$comic_date])) { $data_by_date[$comic_date] = array(); } $comic_info = array('type' => 'comic', 'timestamp' => $timestamp, 'comic_file' => $comic_file, 'file_title' => $result['converted_title'], 'comic_uri' => cpm_build_comic_uri($comic_filepath, CPM_DOCUMENT_ROOT)); if (count($thumbnails_found = cpm_find_thumbnails_by_filename($comic_filepath)) > 0) { foreach ($thumbnails_found as $thumb_type => $thumb_filename) { $comic_info["thumbnails_found_{$thumb_type}"] = cpm_build_comic_uri(CPM_DOCUMENT_ROOT . $thumb_filename, CPM_DOCUMENT_ROOT); } } $icon_file_to_use = $comic_filepath; foreach (array('rss', 'archive', 'mini') as $type) { if (isset($thumbnails_found[$type])) { $icon_file_to_use = CPM_DOCUMENT_ROOT . $thumbnails_found[$type]; } } $comic_info['icon_uri'] = cpm_build_comic_uri($icon_file_to_use, CPM_DOCUMENT_ROOT); $data_by_date[$comic_date][] = $comic_info; } } foreach (cpm_query_posts() as $comic_post) { $ok = true; if (cpm_get_subcomic_directory() !== false) { $ok = in_array(get_option('comicpress-manager-manage-subcomic'), wp_get_post_categories($comic_post->ID)); } if ($ok) { $timestamp = strtotime($comic_post->post_date); $post_date = date("Y-m-d", $timestamp); if (!isset($data_by_date[$post_date])) { $data_by_date[$post_date] = array(); } $post_info = array('type' => 'post', 'timestamp' => $timestamp, 'post_id' => $comic_post->ID, 'post_title' => $comic_post->post_title, 'post_object' => (array) $comic_post); $data_by_date[$post_date][] = $post_info; } } krsort($data_by_date); $all_months = array(); foreach (array_keys($data_by_date) as $date) { list($year, $month, $day) = explode("-", $date); $key = "{$year}-{$month}"; if (!isset($all_months[$key])) { $all_months[$key] = date("F Y", strtotime($date)); } } krsort($all_months); if (isset($_POST['dates'])) { if ($_POST['dates'] != -1) { $new_data_by_date = array(); foreach ($data_by_date as $date => $data) { if (strpos($date, $_POST['dates']) === 0) { $new_data_by_date[$date] = $data; } } $data_by_date = $new_data_by_date; } } if (!isset($_GET['paged'])) { $_GET['paged'] = 1; } $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => ceil(count($data_by_date) / $dates_per_page), 'current' => $_GET['paged'])); $total_data_by_date = count($data_by_date); $data_by_date = array_slice($data_by_date, ($_GET['paged'] - 1) * $dates_per_page, $dates_per_page); extract(cpm_normalize_storyline_structure()); $comic_categories = array(); foreach ($category_tree as $node) { $comic_categories[] = end(explode("/", $node)); } $thumbnail_writes = cpm_get_thumbnails_to_generate(); if ($total_data_by_date > 0) { $displaying_num_content = sprintf(__("Displaying %d-%d of %d", 'comicpress-manager'), ($_GET['paged'] - 1) * $dates_per_page + 1, min($total_data_by_date, ($_GET['paged'] - 1) * $dates_per_page + $dates_per_page), $total_data_by_date); } else { $displaying_num_content = __('No items to display', 'comicpress-manager'); } ?> <style type="text/css"> .storyline-checklist { overflow-y: scroll; border: solid #ddd 1px; height: 12em } #wpbody-content .bulk-edit-row-post .inline-edit-col-right { width: 42% } </style> <div id="table-holder"> <form id="bulk-form" action="" method="post"> <input type="hidden" name="action" value="batch-processing" /> <div class="tablenav"> <div class="alignleft actions"> <select id="bulk-action" name="bulk-action"> <option selected value="-1">Bulk Actions</option> <option value="individual">Submit Individual Changes</option> <option value="edit">Edit Selected</option> <option value="delete">Delete Selected</option> <option value="import">Create Posts for Selected Files</option> <option value="regen-thumbs">Regenerate Thumbs</option> </select> <input id="doaction" class="button-secondary action" type="submit" value="Apply" /> <select id="dates" name="dates"> <option selected value="-1">Show all dates</option> <?php foreach ($all_months as $key => $date) { ?> <option value="<?php echo $key; ?> "<?php echo $key == $_POST['dates'] ? " selected" : ""; ?> ><?php echo $date; ?> </option> <?php } ?> </select> <input id="dofilter" class="button-secondary action" type="submit" value="Filter" /> </div> <div class="tablenav-pages"> <span class="displaying-num"><?php echo $displaying_num_content; ?> </span> <?php echo $page_links; ?> </div> </div> <table class="widefat fixed" id="status-table"> <thead> <tr> <th class="check-column" width="3%"> <input type="checkbox" name="toggle-all" class="batch-all" value="yes" /> </th> <th width="12%"><?php _e("Date", 'comicpress-manager'); ?> </th> <th width="34%"><?php _e("Object Info", 'comicpress-manager'); ?> </th> <th width="61%"><?php _e("Operations", 'comicpress-manager'); ?> </th> </tr> </thead> <tfoot> <tr> <th class="check-column"> <input type="checkbox" name="toggle-all" class="batch-all" value="yes" /> </th> <th><?php _e("Date", 'comicpress-manager'); ?> </th> <th><?php _e("Object Info", 'comicpress-manager'); ?> </th> <th><?php _e("Operations", 'comicpress-manager'); ?> </th> </tr> </tfoot> <tbody> <tr style="display: none" id="bulk-edit" class="inline-edit-row inline-edit-row-post bulk-edit-row bulk-edit-row-post inline-editor"> <td colspan="4"> <fieldset class="inline-edit-col-left"> <div class="inline-edit-col"> <h4>Bulk Edit Comic Posts</h4> <div id="bulk-title-div"> <div id="bulk-titles" /> </div> </div> </fieldset> <fieldset class="inline-edit-col-center inline-edit-categories"> <div class="inline-edit-col"> <span class="title inline-edit-categories-label"> Storyline </span> <div class="storyline-checklist"> <?php cpm_display_storyline_checkboxes($category_tree, array(), "bulk-storyline"); ?> </div> </div> </fieldset> <fieldset class="inline-edit-col-right"> <label> <span class="title" style="width: auto; margin-right: 5px"><img title>/hovertext</span> <input type="text" name="bulk-hovertext" style="width: 100%" /> </label> <label> <span class="title" style="width: auto; margin-right: 5px">Transcript</span> <textarea name="bulk-transcript" style="height: 7em"></textarea> </label> </fieldset> <p class="submit inline-edit-save"> <a id="cancel" class="button-secondary cancel alignleft" title="Cancel" href="#">Cancel</a> <input class="button-primary alignright" id="bulk-edit-submit" type="submit" value="Update Comic Posts" name="bulk-comic-edit" /> <br class="clear" /> </p> </td> </tr> <?php $is_grey = false; $image_index = 0; foreach ($data_by_date as $date => $data) { $all_objects_by_type = array(); foreach ($data as $object) { if (!isset($all_objects_by_type[$object['type']])) { $all_objects_by_type[$object['type']] = array(); } $all_objects_by_type[$object['type']][] = $object; } $classes = array("data-row"); if ($is_grey) { $classes[] = "grey"; } $is_first_row = true; foreach ($data as $object) { ?> <tr class="<?php echo implode(" ", $classes); ?> "> <?php if ($is_first_row) { ?> <td align="center" rowspan="<?php echo count($data); ?> "> <input id="batch-<?php echo $date; ?> " type="checkbox" class="batch" name="batch-<?php echo $date; ?> " value="yes" /> </td> <td rowspan="<?php echo count($data); ?> "><?php echo $date; ?> </td> <?php $is_first_row = false; } ?> <td class="<?php echo $object['type']; ?> "> <?php switch ($object['type']) { case "comic": ?> <div style="overflow: hidden"> <div><strong> Comic: <?php echo empty($object['file_title']) ? $object['comic_file'] : $object['file_title']; ?> </strong></div> <a href="<?php echo $object['comic_uri']; ?> "><img style="float: right; display: inline; margin-right: 5px; max-height: 100px" id="comic-icon-<?php echo $image_index; ?> " src="<?php echo $object['icon_uri']; ?> " /></a> <?php $all_found = array(); foreach (array('rss', 'archive', 'mini') as $type) { if (isset($object["thumbnails_found_{$type}"])) { $all_found[$type] = $object["thumbnails_found_{$type}"]; } } if (count($all_found) > 0) { ?> [ <?php foreach ($all_found as $type => $uri) { ?> <a href="<?php echo $uri; ?> "><?php echo $type; ?> </a> <?php } ?> ] <?php } else { ?> [ No thumbnails found ] <?php } $image_index++; ?> </div> <?php break; case "post": if (isset($object['post_id'])) { ?> <strong>Post: <?php echo $object['post_title']; ?> </strong> <em>(<?php echo $object['post_id']; ?> )</em><br /> [ <?php echo generate_view_edit_post_links($object['post_object']); ?> ] <?php } break; } ?> </td> <td class="individual-operations <?php echo $object['type']; ?> "> <?php switch ($object['type']) { case "comic": ?> <input type="hidden" name="file,<?php echo $date; ?> ,<?php echo $object['comic_file']; ?> " value="yes" /> <?php if (count($all_objects_by_type['post']) == 0) { ?> <label><input type="checkbox" name="generate-post-<?php echo $object['comic_file']; ?> " value="yes" /> Generate a Post <em>(as a draft)</em></label><br /> <?php } ?> <?php if (count($thumbnail_writes) > 0) { ?> <label><input type="checkbox" name="regen-<?php echo $object['comic_file']; ?> " value="yes" /> Regenerate Thumbs</label><br /> <?php } ?> <label><input type="checkbox" class="delete-file" name="delete-file-<?php echo $object['comic_file']; ?> " value="yes" /> Delete Comic</label><br /> <!-- <input type="checkbox" id="do-redate-file-<?php echo $object['comic_file']; ?> " name="do-redate-file-<?php echo $object['comic_file']; ?> " /> Move to: <input class="needs-calendar" id="redate-file-<?php echo $object['comic_file']; ?> " type="text" name="redate-file-<?php echo $object['comic_file']; ?> " value="<?php echo $date; ?> " /> --> <?php break; case "post": $post_categories = array_intersect(wp_get_post_categories($object['post_id']), $comic_categories); $post_category_names = array(); foreach ($post_categories as $category_id) { $post_category_names[] = get_cat_name($category_id); } ?> <input type="hidden" name="post,<?php echo $date; ?> ,<?php echo $object['post_id']; ?> " value="yes" /> <label><input type="checkbox" class="delete-post" name="delete-post-<?php echo $object['post_id']; ?> " value="yes" /> Delete Post</label><br /> <!-- <input type="checkbox" id="do-redate-post-<?php echo $object['post_id']; ?> " name="do-redate-post-<?php echo $object['post_id']; ?> " /> Move to: <input type="text" class="needs-calendar" id="redate-post-<?php echo $object['post_id']; ?> " name="redate-post-<?php echo $object['post_if']; ?> " value="<?php echo $date; ?> " /><br /> --> <?php $hovertext = get_post_meta($object['post_id'], 'hovertext', true); if (!empty($hovertext)) { ?> <strong><img title>/hovertext:</strong> <?php echo $hovertext; ?> <br /> <?php } ?> <?php $transcript = get_post_meta($object['post_id'], 'transcript', true); if (!empty($transcript)) { ?> <strong>Transcript:</strong> <div class="transcript-holder"><?php echo $transcript; ?> </div> <?php } ?> <strong>Storyline:</strong> <span class="category-names"><?php echo implode(", ", $post_category_names); ?> </span> [ <a href="#" id="category-<?php echo $object['post_id']; ?> " class="category">Edit</a> ] <div id="category-holder-<?php echo $object['post_id']; ?> " style="display: none"> <?php cpm_display_storyline_checkboxes($category_tree, $post_categories, $object['post_id']); ?> </div> <?php break; } ?> </td> </tr> <?php } $is_grey = !$is_grey; } ?> </tbody> </table> <div class="tablenav"> <div class="alignleft actions"> <select id="linked-bulk-action" name="linked-bulk-action"> <option selected value="-1">Bulk Actions</option> <option value="individual">Submit Individual Changes</option> <option value="edit">Edit Selected</option> <option value="delete">Delete Selected</option> <option value="import">Create Posts for Selected Files</option> <option value="regen-thumbs">Regenerate Thumbs</option> </select> <input id="linked-doaction" class="button-secondary action" type="submit" value="Apply" /> </div> <div class="tablenav-pages"> <span class="displaying-num"><?php echo $displaying_num_content; ?> </span> <?php echo $page_links; ?> </div> </div> </form> <script type="text/javascript"> Event.observe(window, 'load', function() { Event.observe($('linked-bulk-action'), 'change', function() { $('bulk-action').selectedIndex = $('linked-bulk-action').selectedIndex; }); Event.observe($('bulk-action'), 'change', function() { $('linked-bulk-action').selectedIndex = $('bulk-action').selectedIndex; }); $$('.needs-calendar').each(function(element) { Calendar.setup({ inputField: element.id, ifFormat: "%Y-%m-%d", button: element.id }); Event.observe(element, 'click', function(e) { var element = Event.element(e); $("do-" + element.id).checked = true; }); }); $$('a.category').each(function(element) { Event.observe(element, 'click', function(e) { Event.stop(e); Element.toggle("category-holder-" + Event.element(e).id.replace(/^.*\-([0-9]+)$/, '$1')); }); }); }); $$('.batch-all').each(function(element) { Event.observe(element, 'change', function(e) { $$('.batch').each(function(b) { b.checked = element.checked; }); $$('.batch-all').each (function(b) { b.checked = element.checked; }); }); }); $$('.individual-operations input[type=checkbox]').each(function(element) { Event.observe(element, 'click', function(e) { $('bulk-action').selectedIndex = 1; $('linked-bulk-action').selectedIndex = 1; }); }); var ok_to_submit = false; Event.observe($('bulk-form'), 'submit', function(e) { return ok_to_submit; }); Event.observe($('bulk-edit-submit'), 'click', function(e) { ok_to_submit = true; $('bulk-form').submit(); }); Event.observe($('cancel'), 'click', function(e) { Event.stop(e); $('bulk-edit').hide(); $('bulk-action').selectedIndex = 0; }); Event.observe($('dofilter'), 'click', function(e) { Event.stop(e); $('bulk-action').selectedIndex = 0; ok_to_submit = true; $('bulk-form').submit(); }); ['doaction', 'linked-doaction'].each(function(which) { Event.observe($(which), 'click', function(e) { Event.stop(e); switch ($F('bulk-action')) { case -1: case "-1": break; case "edit": $('bulk-titles').innerHTML = ""; var any_checked = false; $$('.batch').each(function(element) { if (element.checked) { any_checked = true; /\-(.*)$/.test(element.id); var date = RegExp.$1; var node = Builder.node("div", [ Builder.node("a", { id: date, className: "ntdelbutton", title: "Remove From Bulk Edit" }, [ "X" ]), date ]); $('bulk-titles').insert(node); Event.observe(node, 'click', function(evt) { var node = Event.element(evt); $('batch-' + node.id).checked = false; Element.remove(node.parentNode); var any_checked = false; $$('.batch').each(function(n) { if (n.checked) { any_checked = true; } }); if (!any_checked) { $('bulk-edit').hide(); } }); } }); if (any_checked) { $('bulk-edit').show(); } break; case "delete": if (confirm("<?php _e('You are about to delete the selected posts and comic files. Are you sure?', 'comicpress-manager'); ?> ")) { ok_to_submit = true; $('bulk-form').submit(); } break; default: ok_to_submit = true; $('bulk-form').submit(); break; } }); }); </script> </div> <?php $activity_content = ob_get_clean(); cpm_wrap_content($help_content, $activity_content, false); }