From b44c6db194c53e1546271d2932bc24d7e5c28d09 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 20 Aug 2009 19:46:42 -0400 Subject: [PATCH] some code safety work --- comicpress_manager_admin.php | 76 +++++++++++++++++----------------- comicpress_manager_library.php | 10 ++++- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/comicpress_manager_admin.php b/comicpress_manager_admin.php index 8cfe41a..a0ac674 100644 --- a/comicpress_manager_admin.php +++ b/comicpress_manager_admin.php @@ -151,52 +151,54 @@ function cpm_handle_pre_post_update($post_id) { 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_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; + 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; } } - $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(); + 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; } + } - 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)); + $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)); } - - @rename($file, str_replace("/${original_date}", "/${new_date}", $file)); } } - } - $cpm_config->comic_files = null; + $cpm_config->comic_files = null; + } } } } diff --git a/comicpress_manager_library.php b/comicpress_manager_library.php index 6a6825e..c6d319a 100644 --- a/comicpress_manager_library.php +++ b/comicpress_manager_library.php @@ -376,8 +376,14 @@ function cpm_read_information_and_check_config() { $cpm_config->thumbs_folder_writable[$thumb_type] = true; } } - $cpm_config->comic_category_info = get_object_vars(get_category($cpm_config->properties['comiccat'])); - $cpm_config->blog_category_info = get_object_vars(get_category($cpm_config->properties['blogcat'])); + + foreach (array('comic', 'blog') as $type) { + $result = (object)get_category($cpm_config->properties["${type}cat"]); + if (!is_wp_error($result)) { + $cpm_config->{"${type}_category_info"} = get_object_vars($result); + } + } + $cpm_config->comic_files = cpm_read_comics_folder(); } else { // quick check to see if the theme is ComicPress.