";
$default_comicpress_config_file = implode("\n", $default_comicpress_config_file_lines);
cpm_get_cpm_document_root();
cpm_initialize_options();
/**
* Show a warning at the top of Manage -> Categories if not enough categories
* are defined.
*/
function cpm_comicpress_categories_warning() {
if (count(get_all_category_ids()) < 2) {
echo '
';
echo __("Remember, you need at least two categories defined in order to use ComicPress.", 'comicpress-manager');
echo '
';
}
}
/**
* Get the path to the plugin folder.
*/
function cpm_get_plugin_path() {
return PLUGINDIR . '/' . preg_replace('#^.*/([^\/]*)#', '\\1', dirname(plugin_basename(__FILE__)));
}
/**
* Add pages to the admin interface and load necessary JavaScript libraries.
* Also read in the configuration and handle any POST actions.
*/
function cpm_add_pages() {
global $plugin_page, $access_level, $pagenow, $cpm_config, $wp_version, $wpmu_version;
load_plugin_textdomain('comicpress-manager', cpm_get_plugin_path());
$widget_options = get_option('dashboard_widget_options');
if ( !$widget_options || !is_array($widget_options) )
$widget_options = array();
cpm_read_information_and_check_config();
$do_enqueue_prototype = false;
if (($pagenow == "post.php") && ($_REQUEST['action'] == "edit")) {
$do_enqueue_prototype = true;
}
$filename = plugin_basename(__FILE__);
if (strpos($plugin_page, $filename) !== false) {
$editor_load_pages = array($filename, $filename . '-import');
if (in_array($plugin_page, $editor_load_pages)) {
wp_enqueue_script('editor');
if (!function_exists('wp_tiny_mce')) {
wp_enqueue_script('wp_tiny_mce');
}
}
$do_enqueue_prototype = true;
cpm_handle_actions();
}
if (in_array($pagenow, array("edit.php", "post-new.php"))) {
$do_enqueue_prototype = true;
}
if ($do_enqueue_prototype) {
wp_enqueue_script('prototype');
wp_enqueue_script('scriptaculous-effects');
wp_enqueue_script('scriptaculous-builder');
}
if (!isset($access_level)) { $access_level = 10; }
$plugin_title = __("ComicPress Manager", 'comicpress-manager');
add_menu_page($plugin_title, __("ComicPress", 'comicpress-manager'), $access_level, $filename, "cpm_manager_index_caller", get_option('siteurl') . '/' . cpm_get_plugin_path() . '/comicpress-icon.png');
add_submenu_page($filename, $plugin_title, __("Upload", 'comicpress-manager'), $access_level, $filename, 'cpm_manager_index_caller');
//if (!$wpmu_version) {
add_submenu_page($filename, $plugin_title, __("Import", 'comicpress-manager'), $access_level, $filename . '-import', 'cpm_manager_import_caller');
//}
add_submenu_page($filename, $plugin_title, __("Bulk Edit", 'comicpress-manager'), $access_level, $filename . '-status', 'cpm_manager_status_caller');
add_submenu_page($filename, $plugin_title, __("Storyline Structure", 'comicpress-manager'), $access_level, $filename . '-storyline', 'cpm_manager_storyline_caller');
add_submenu_page($filename, $plugin_title, __("Change Dates", 'comicpress-manager'), $access_level, $filename . '-dates', 'cpm_manager_dates_caller');
add_submenu_page($filename, $plugin_title, __("ComicPress Config", 'comicpress-manager'), $access_level, $filename . '-config', 'cpm_manager_config_caller');
add_submenu_page($filename, $plugin_title, __("Manager Config", 'comicpress-manager'), $access_level, $filename . '-cpm-config', 'cpm_manager_cpm_config_caller');
if ($pagenow == "index.php") {
if (cpm_option('cpm-enable-dashboard-rss-feed') == 1) {
wp_register_sidebar_widget( 'dashboard_cpm', __("ComicPress News", "comicpress-manager"), 'cpm_dashboard_widget',
array( 'all_link' => "http://mindfaucet.com/comicpress/", 'feed_link' => "http://feeds.feedburner.com/comicpress?format=xml", 'width' => 'half', 'class' => 'widget_rss' )
);
add_filter('wp_dashboard_widgets', 'cpm_add_dashboard_widget');
}
if (($option = generate_comic_categories_options('category')) !== false) {
if (cpm_option('cpm-enable-quomicpress') == 1) {
if (count($cpm_config->errors) == 0) {
wp_register_sidebar_widget( 'dashboard_quomicpress', __("QuomicPress (Quick ComicPress)", "comicpress-manager"), 'cpm_quomicpress_widget',
array( 'width' => 'half' )
);
add_filter('wp_dashboard_widgets', 'cpm_add_quomicpress_widget');
}
}
}
}
}
/**
* Handle updating a post. If Edit Post Integration is enabled, and the post
* date is changing, rename the file as necessary.
*/
function cpm_handle_pre_post_update($post_id) {
global $cpm_config;
if (!$cpm_config->is_cpm_managing_posts) {
if (cpm_option("cpm-edit-post-integrate") == 1) {
if ($post_id > 0) {
$post = get_post($post_id);
if (!in_array($post->post_type, array("attachment", "revision", "page"))) {
$ok = false;
extract(cpm_get_all_comic_categories());
$post_categories = wp_get_post_categories($post_id);
foreach ($category_tree as $node) {
$parts = explode("/", $node);
if (in_array(end($parts), $post_categories)) {
$ok = true; break;
}
}
if ($ok) {
$original_timestamp = false;
foreach (array("post_date", "post_date_gmt") as $param) {
$result = strtotime(date("Y-m-d", strtotime($post->{$param})));
if ($result !== false) {
$original_timestamp = $result; break;
}
}
$new_timestamp = strtotime(implode("-", array($_POST['aa'], $_POST['mm'], $_POST['jj'])));
if (!empty($original_timestamp) && !empty($new_timestamp)) {
$original_date = date(CPM_DATE_FORMAT, $original_timestamp);
$new_date = date(CPM_DATE_FORMAT, $new_timestamp);
if ($original_date !== $new_date) {
if (empty($cpm_config->comic_files)) {
cpm_read_information_and_check_config();
}
foreach ($cpm_config->comic_files as $file) {
$filename = pathinfo($file, PATHINFO_BASENAME);
if (($result = cpm_breakdown_comic_filename($filename)) !== false) {
if ($result['date'] == $original_date) {
foreach (cpm_find_thumbnails_by_filename($file) as $thumb_file) {
@rename($thumb_file, str_replace("/${original_date}", "/${new_date}", $thumb_file));
}
@rename($file, str_replace("/${original_date}", "/${new_date}", $file));
}
}
}
$cpm_config->comic_files = null;
}
}
}
}
}
}
}
}
/**
* Handle editing a post.
*/
function cpm_handle_edit_post($post_id) {
global $cpm_config;
if (!$cpm_config->is_cpm_managing_posts) {
$ok = false;
extract(cpm_get_all_comic_categories());
$post_categories = wp_get_post_categories($post_id);
foreach ($category_tree as $node) {
$parts = explode("/", $node);
if (in_array(end($parts), $post_categories)) {
$ok = true; break;
}
}
if (is_uploaded_file($_FILES['comicpress-replace-image']['tmp_name']) && !$ok) {
$post_categories = wp_get_post_categories($post_id);
$post_categories[] = end(explode("/", reset($category_tree)));
wp_set_post_categories($post_id, $post_categories);
$ok = true;
}
if ($ok) {
$new_date = date(CPM_DATE_FORMAT, strtotime(implode("-", array($_POST['aa'], $_POST['mm'], $_POST['jj']))));
foreach (array('hovertext' => 'comicpress-img-title',
'transcript' => 'comicpress-transcript') as $meta_name => $post_name) {
if (isset($_POST[$post_name])) {
update_post_meta($post_id, $meta_name, $_POST[$post_name]);
}
}
if (is_uploaded_file($_FILES['comicpress-replace-image']['tmp_name'])) {
$_POST['override-date'] = $new_date;
cpm_handle_file_uploads(array('comicpress-replace-image'));
}
}
}
}
/**
* Handle deleting a post. If Edit Post Integration is enabled, delete any associated
* files from the comics folders.
*/
function cpm_handle_delete_post($post_id) {
global $cpm_config;
if (!$cpm_config->is_cpm_managing_posts) {
if (cpm_option("cpm-edit-post-integrate") == 1) {
$post = get_post($post_id);
if (!in_array($post->post_type, array("attachment", "revision", "page"))) {
$ok = false;
extract(cpm_get_all_comic_categories());
$post_categories = wp_get_post_categories($post_id);
foreach ($category_tree as $node) {
$parts = explode("/", $node);
if (in_array(end($parts), $post_categories)) {
$ok = true; break;
}
}
if ($ok) {
$original_date = date(CPM_DATE_FORMAT, strtotime($post->post_date));
if (empty($cpm_config->comic_files)) {
cpm_read_information_and_check_config();
}
foreach ($cpm_config->comic_files as $file) {
$filename = pathinfo($file, PATHINFO_BASENAME);
if (($result = cpm_breakdown_comic_filename($filename)) !== false) {
if ($result['date'] == $original_date) {
foreach (cpm_find_thumbnails_by_filename($file) as $thumb_file) {
$thumb_file = CPM_DOCUMENT_ROOT . $thumb_file;
@unlink($thumb_file);
}
@unlink($file);
}
}
}
}
}
}
}
}
/**
* Add the ComicPress News Dashboard widget.
*/
function cpm_add_dashboard_widget($widgets) {
global $wp_registered_widgets;
if (!isset($wp_registered_widgets['dashboard_cpm'])) {
return $widgets;
}
array_splice($widgets, sizeof($widgets)-1, 0, 'dashboard_cpm');
return $widgets;
}
/**
* Write out the ComicPress News Dashboard widget.
*/
function cpm_dashboard_widget($sidebar_args) {
if (is_array($sidebar_args)) {
extract($sidebar_args, EXTR_SKIP);
}
echo $before_widget . $before_title . $widget_name . $after_title;
wp_widget_rss_output('http://feeds.feedburner.com/comicpress?format=xml', array('items' => 2, 'show_summary' => true));
echo $after_widget;
}
/**
* Add the QuomicPress Dashboard widget.
*/
function cpm_add_quomicpress_widget($widgets) {
global $wp_registered_widgets;
if (!isset($wp_registered_widgets['dashboard_quomicpress'])) {
return $widgets;
}
array_splice($widgets, sizeof($widgets)-1, 0, 'dashboard_quomicpress');
return $widgets;
}
/**
* Write out the QuomicPress Dashboard widget.
*/
function cpm_quomicpress_widget($sidebar_args) {
if (is_array($sidebar_args)) {
extract($sidebar_args, EXTR_SKIP);
}
echo $before_widget . $before_title . $widget_name . $after_title;
include("pages/write_comic_post.php");
cpm_manager_write_comic(plugin_basename(__FILE__), false);
echo $after_widget;
}
/**
* Add the Comic column to Edit Posts.
*/
function cpm_manage_posts_columns($posts_columns) {
wp_enqueue_script('prototype');
$posts_columns['comic'] = "Comic";
return $posts_columns;
}
$broken_down_comic_files = null;
/**
* Populate the Comic coulmn in Edit Posts.
*/
function cpm_manage_posts_custom_column($column_name) {
global $cpm_config, $broken_down_comic_files, $post;
if ($column_name == "comic") {
$post_date = date(CPM_DATE_FORMAT, strtotime($post->post_date));
if ($is_first = empty($broken_down_comic_files)) {
$broken_down_comic_files = array();
if (empty($cpm_config->comic_files)) {
cpm_read_information_and_check_config();
}
foreach ($cpm_config->comic_files as $file) {
$filename = pathinfo($file, PATHINFO_BASENAME);
if (($result = cpm_breakdown_comic_filename($filename)) !== false) {
if (!isset($broken_down_comic_files[$result['date']])) {
$broken_down_comic_files[$result['date']] = array();
}
$broken_down_comic_files[$result['date']][] = $file;
}
}
?>
ID . '-' . $index;
$thumbnails_found = cpm_find_thumbnails_by_filename($file);
$icon_file_to_use = $file;
foreach (array('rss', 'archive') as $type) {
if (isset($thumbnails_found[$type])) { $icon_file_to_use = $thumbnails_found[$type]; }
}
$hovertext = get_post_meta($post->ID, "hovertext", true);
?>
File:
0) { ?>
Thumbs:
Hover:
is_cpm_modifying_categories)) {
cpm_read_information_and_check_config();
cpm_normalize_storyline_structure();
}
}
/**
* Create a list of checkboxes that can be used to select additional categories.
*/
function cpm_generate_additional_categories_checkboxes($override_name = null) {
global $cpm_config;
$additional_categories = array();
$invalid_ids = array($cpm_config->properties['blogcat']);
extract(cpm_get_all_comic_categories());
foreach ($category_tree as $node) {
$invalid_ids[] = end(explode('/', $node));
}
foreach (get_all_category_ids() as $cat_id) {
if (!in_array($cat_id, $invalid_ids)) {
$category = get_category($cat_id);
$additional_categories[strtolower($category->cat_name)] = $category;
}
}
ksort($additional_categories);
$name = (!empty($override_name)) ? $override_name : "additional-categories";
$selected_additional_categories = explode(",", cpm_option("cpm-default-additional-categories"));
$category_checkboxes = array();
if (count($additional_categories) > 0) {
foreach ($additional_categories as $category) {
$checked = (in_array($category->cat_ID, $selected_additional_categories) ? "checked" : "");
$category_checkboxes[] = "cat_ID . "\" type=\"checkbox\" name=\"${name}[]\" value=\"" . $category->cat_ID . "\" ${checked} /> ";
}
}
return $category_checkboxes;
}
/**
* Initialize ComicPress Manager options.
*/
function cpm_initialize_options() {
global $cpm_config;
include('cpm_configuration_options.php');
foreach ($configuration_options as $option_info) {
if (is_array($option_info)) {
$result = cpm_option($option_info['id']);
if (isset($option_info['not_blank']) && empty($result)) { $result = false; }
if ($result === false) {
$default = (isset($option_info['default']) ? $option_info['default'] : "");
update_option("comicpress-manager-" . $option_info['id'], $default);
}
}
}
}
/**
* Show the Post Editor.
* @param integer $width The width in pixels of the text editor widget.
*/
function cpm_post_editor($width = 435, $is_import = false) {
global $cpm_config;
$form_titles_and_fields = array();
if (is_null(get_category($cpm_config->properties['comiccat']))) { ?>
You don't have a comics category defined! Go to the
ComicPress Config screen and choose a category.
properties['comiccat']);
}
}
ob_start();
cpm_display_storyline_checkboxes($category_tree, $post_categories);
$storyline_editor = ob_get_clean();
$form_titles_and_fields[] = array(
__("Storyline:", 'comicpress-manager'),
$storyline_editor
);
// see if there are additional categories that can be set besides the comic and blog categories
if (count($category_checkboxes = cpm_generate_additional_categories_checkboxes()) > 0) {
$form_titles_and_fields[] = array(
__("Additional Categories:", 'comicpress-manager'),
implode("\n", $category_checkboxes)
);
}
$form_titles_and_fields[] = array(
__("Time to post:", 'comicpress-manager'),
"" .
__(" (must be in the format HH:MM am/pm or now)", 'comicpress-manager')
);
$form_titles_and_fields[] = array(
'',
'' .
__(" ", "comicpress-manager")
);
if (!$is_import) {
$form_titles_and_fields[] = array(
'',
'' .
__(" ", "comicpress-manager")
);
} else {
$form_titles_and_fields[] = '';
}
if ($cpm_config->get_scale_method() != CPM_SCALE_NONE) {
$thumbnail_writes = cpm_get_thumbnails_to_generate();
$thumb_write_holder = ' (';
if (count($thumbnail_writes) > 0) {
$thumb_write_holder .= sprintf("If enabled, you'll be writing thumbnails to: %s", implode(", ", $thumbnail_writes));
} else {
$thumb_write_holder .= __("You won't be generating any thumbnails.", 'comicpress-manager');
}
$thumb_write_holder .= ")";
if (count($thumbnail_writes) > 0) {
$form_titles_and_fields[] = array(
'',
'' . '"
);
}
}
$form_titles_and_fields[] = array(
__("Title For All Posts:", 'comicpress-manager'),
'' .
__(" (the title to use for all posts)", 'comicpress-manager')
);
$form_titles_and_fields[] = array(
__("<img title>/Hovertext For All Posts:", 'comicpress-manager'),
'' .
__(" (the hovertext to use for all posts)", 'comicpress-manager')
);
$form_titles_and_fields[] = array(
__("Transcript For All Posts:", 'comicpress-manager'),
'' .
__(" (the transcript to use for all posts)", 'comicpress-manager')
);
$form_titles_and_fields[] = array(
__("Upload Date Format:", 'comicpress-manager'),
'' .
__(" (if the files you are uploading have a different date format, specify it here. ex: Ymd for a file named 20080101-my-new-years-day.jpg)", 'comicpress-manager')
);
$form_titles_and_fields[] = array(
__("Tags:", 'comicpress-manager'),
'' .
__(" (any tags to add to the post, separated by commas. any tags you've used before will be listed below.)", 'comicpress-manager')
);
$all_tags_links = array();
foreach (get_tags() as $tag) {
$all_tags_links[] = "{$tag->name}";
}
sort($all_tags_links);
if (count($all_tags_links) > 0) {
$form_titles_and_fields[] = array(
__("Quick Tags (click to add):", 'comicpress-manager'),
implode("\n", $all_tags_links)
);
}
?>
>
>
>
properties["${folder_name}comic_folder"])) { $all_comic_folders_found = false; break; }
}
$do_first_run = !$all_comic_folders_found;
if (!$do_first_run) {
if ($wpmu_version) {
update_option("comicpress-manager-cpm-did-first-run", 1);
}
}
}
if ($do_first_run) {
include("pages/comicpress_first_run.php");
cpm_manager_first_run(plugin_basename(__FILE__));
if ($wpmu_version) {
update_option("comicpress-manager-cpm-did-first-run", 1);
}
} else {
if ($cpm_config->did_first_run) { $page = "config"; }
include("pages/comicpress_${page}.php");
call_user_func("cpm_manager_${page}");
}
}
/**
* Wrappers around page calls to reduce the amount of code in _admin.php.
*/
function cpm_manager_index_caller() { cpm_manager_page_caller("index"); }
function cpm_manager_status_caller() { cpm_manager_page_caller("status"); }
function cpm_manager_dates_caller() { cpm_manager_page_caller("dates"); }
function cpm_manager_import_caller() { cpm_manager_page_caller("import"); }
function cpm_manager_config_caller() { cpm_manager_page_caller("config"); }
function cpm_manager_cpm_config_caller() { cpm_manager_page_caller("cpm_config"); }
function cpm_manager_storyline_caller() { cpm_manager_page_caller("storyline"); }
function cpm_show_comic_caller() {
include("pages/edit_post_show_comic.php");
cpm_show_comic();
}
function cpm_manager_write_comic_caller() {
include("pages/write_comic_post.php");
cpm_manager_write_comic(plugin_basename(__FILE__));
}
/**
* Show the header.
*/
function cpm_show_manager_header() {
global $cpm_config; ?>
";
}
$cpm_config->messages[] = __("The following files would have created duplicate posts. View them from the links below: ", 'comicpress-manager') . "
" . implode("", $post_links) . "
";
}
}
/**
* Show the Post Body Template.
* @param integer $width The width of the editor in pixels.
*/
function cpm_show_post_body_template($width = 435) {
global $cpm_config; ?>
= filemtime($js_path . '/' . $regular_file)) {
$file_to_use = $minified_file;
}
}
?>
need_calendars) { ?>
messages,
__("The operation you just performed returned the following:", 'comicpress-manager'),
'messages'),
array(
$cpm_config->warnings,
__("The following warnings were generated:", 'comicpress-manager'),
'warnings'),
array(
$cpm_config->errors,
__("The following problems were found in your configuration:", 'comicpress-manager'),
'errors')
) as $info) {
list($messages, $header, $style) = $info;
if (count($messages) > 0) {
if (count($messages) == 1) {
$output = $messages[0];
} else {
ob_start(); ?>
If your error is permissions-related, you may have to set some Windows-specific permissions on your filesystem. Consult your Webhost for more information.", 'comicpress-manager');
}
?>
errors) > 0) {
$current_theme_info = get_theme(get_current_theme());
?>
show_config_editor) { ?>
category_nicename ?>
cat_ID ?>
config_filepath) . '/comicpress-config.php.*');
if ($found_backup_files === false) { $found_backup_files = array(); }
foreach ($found_backup_files as $file) {
if (preg_match('#\.([0-9]+)$#', $file, $matches) > 0) {
list($all, $time) = $matches;
$available_backup_files[] = $time;
}
}
arsort($available_backup_files);
// if ($wpmu_version) {
// $cpm_config->show_config_editor = true;
// } else {
if ($cpm_config->config_method == "comicpress-config.php") {
if (!$cpm_config->can_write_config) {
$update_automatically = false;
}
} else {
if (count($available_backup_files) > 0) {
if (!$cpm_config->can_write_config) {
$update_automatically = false;
}
} else {
$update_automatically = false;
}
}
if (!$update_automatically) { ?>
You won't be able to update your comicpress-config.php or functions.php file directly through the ComicPress Manager interface. Check to make sure the permissions on %s and comicpress-config.php are set so that the Webserver can write to them. Once you submit, you'll be given a block of code to paste into the comicpress-config.php file.", 'comicpress-manager'), $current_theme_info['Template Dir']) ?>
0) { ?>
Some backup comicpress-config.php files were found in your theme directory. You can choose to restore one of these backup files, or you can go ahead and create a new configuration below.", 'comicpress-manager') ?>
show_config_editor) {
echo cpm_manager_edit_config();
} ?>
()
$b[1]) ? -1 : 1;
}
/**
* Handle all ComicPress actions.
*/
function cpm_handle_actions() {
global $cpm_config;
$valid_actions = array('multiple-upload-file', 'create-missing-posts',
'update-config', 'restore-backup', 'change-dates',
'write-comic-post', 'update-cpm-config', 'do-first-run', 'skip-first-run',
'build-storyline-schema', 'batch-processing', 'manage-subcomic');
//
// take actions based upon $_POST['action']
//
if (isset($_POST['action'])) {
if (in_array($_POST['action'], $valid_actions)) {
require_once('actions/comicpress_' . $_POST['action'] . '.php');
call_user_func("cpm_action_" . str_replace("-", "_", $_POST['action']));
}
}
}
/**
* Show the details of the current setup in the Sidebar.
*/
function cpm_show_comicpress_details() {
global $cpm_config, $wpmu_version;
$all_comic_dates_ok = true;
$all_comic_dates = array();
foreach ($cpm_config->comic_files as $comic_file) {
if (($result = cpm_breakdown_comic_filename(pathinfo($comic_file, PATHINFO_BASENAME))) !== false) {
if (isset($all_comic_dates[$result['date']])) { $all_comic_dates_ok = false; break; }
$all_comic_dates[$result['date']] = true;
}
}
$subdir_path = '';
if (($subdir = cpm_get_subcomic_directory()) !== false) {
$subdir_path .= '/' . $subdir;
}
?>