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_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;
}
}
}
}

View File

@ -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.