some code safety work

This commit is contained in:
John Bintz 2009-08-20 19:46:42 -04:00
parent e2c51b0d22
commit b44c6db194
2 changed files with 47 additions and 39 deletions

View File

@ -151,52 +151,54 @@ function cpm_handle_pre_post_update($post_id) {
if (!$cpm_config->is_cpm_managing_posts) { if (!$cpm_config->is_cpm_managing_posts) {
if (cpm_option("cpm-edit-post-integrate") == 1) { if (cpm_option("cpm-edit-post-integrate") == 1) {
$post = get_post($post_id); if ($post_id > 0) {
if (!in_array($post->post_type, array("attachment", "revision", "page"))) { $post = get_post($post_id);
$ok = false; if (!in_array($post->post_type, array("attachment", "revision", "page"))) {
extract(cpm_get_all_comic_categories()); $ok = false;
$post_categories = wp_get_post_categories($post_id); extract(cpm_get_all_comic_categories());
foreach ($category_tree as $node) { $post_categories = wp_get_post_categories($post_id);
$parts = explode("/", $node); foreach ($category_tree as $node) {
if (in_array(end($parts), $post_categories)) { $parts = explode("/", $node);
$ok = true; break; 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 ($ok) {
$original_timestamp = false;
if (!empty($original_timestamp) && !empty($new_timestamp)) { foreach (array("post_date", "post_date_gmt") as $param) {
$original_date = date(CPM_DATE_FORMAT, $original_timestamp); $result = strtotime(date("Y-m-d", strtotime($post->{$param})));
$new_date = date(CPM_DATE_FORMAT, $new_timestamp); if ($result !== false) {
$original_timestamp = $result; break;
if ($original_date !== $new_date) {
if (empty($cpm_config->comic_files)) {
cpm_read_information_and_check_config();
} }
}
foreach ($cpm_config->comic_files as $file) { $new_timestamp = strtotime(implode("-", array($_POST['aa'], $_POST['mm'], $_POST['jj'])));
$filename = pathinfo($file, PATHINFO_BASENAME);
if (($result = cpm_breakdown_comic_filename($filename)) !== false) { if (!empty($original_timestamp) && !empty($new_timestamp)) {
if ($result['date'] == $original_date) { $original_date = date(CPM_DATE_FORMAT, $original_timestamp);
foreach (cpm_find_thumbnails_by_filename($file) as $thumb_file) { $new_date = date(CPM_DATE_FORMAT, $new_timestamp);
@rename($thumb_file, str_replace("/${original_date}", "/${new_date}", $thumb_file));
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;
}
} }
} }
} }

View File

@ -376,8 +376,14 @@ function cpm_read_information_and_check_config() {
$cpm_config->thumbs_folder_writable[$thumb_type] = true; $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(); $cpm_config->comic_files = cpm_read_comics_folder();
} else { } else {
// quick check to see if the theme is ComicPress. // quick check to see if the theme is ComicPress.