'gd rename file', "CONVERT_CMYK" => 'convert cmyk', "INVALID_IMAGE_TYPE" => 'invalid image type', "INVALID_FILENAME" => 'invalid filename', "NOT_HANDLED" => 'not handled', "NOT_UPLOADED" => 'not uploaded', "OBFUSCATED_RENAMED" => "obfuscated renamed", "FILE_CREATED" => "file created", "FILE_UPLOADED" => "file uploaded", "POST_CREATED" => "post created", "DUPLICATE_POST" => "duplicate post" ); function ComicPressManagerAdmin() { global $comicpress_manager, $pagenow; $this->_f = new ComicPressFileOperations(); add_action("add_category_form_pre", array($this, "comicpress_categories_warning")); add_action("pre_post_update", array($this, "handle_pre_post_update")); add_action("save_post", array($this, "handle_edit_post")); add_action("edit_form_advanced", array($this, "show_comic_caller")); add_action("delete_post", array($this, "handle_delete_post")); add_action("create_category", array($this, "rebuild_storyline_structure")); add_action("delete_category", array($this, "rebuild_storyline_structure")); add_action("edit_category", array($this, "rebuild_storyline_structure")); add_filter("manage_posts_columns", array($this, "manage_posts_columns")); add_action("manage_posts_custom_column", array($this, "manage_posts_custom_column")); add_action("admin_menu", array($this, "setup_admin_menu")); foreach ($_FILES as $field_name => $info) { if (is_uploaded_file($_FILES[$field_name]['tmp_name'])) { if ($_FILES[$field_name]['error'] != 0) { switch ($_FILES[$key]['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $comicpress_manager->warnings[] = sprintf(__("The file you uploaded was too large. The max allowed filesize for uploads to your server is %s.", 'comicpress-manager'), ini_get('upload_max_filesize')); break; case UPLOAD_ERR_NO_FILE: break; default: $comicpress_manager->warnings[] = sprintf(__("There was an error in uploading. The PHP upload error code was %s.", 'comicpress-manager'), $_FILES[$key]['error']); break; } } else { $this->_uploaded_files[$field_name] = $info; } } } } function _show_view($view) { require_once(dirname(__FILE__) . '/views/' . $view . ".php"); $view = new $view(); $view->render(); } function show_comic_caller() { $this->_show_view('ComicPressEditPostShowComic'); } /** * Show a warning at the top of Manage -> Categories if not enough categories * are defined. */ function 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 '
'; } } function _verify_post_before_hook($post_id) { global $comicpress_manager; $ok = false; if (!$comicpress_manager->is_cpm_managing_posts) { if ($comicpress_manager->get_cpm_option("cpm-edit-post-integrate") == 1) { $post = get_post($post_id); if (!empty($post)) { if (!in_array($post->post_type, array("attachment", "revision", "page"))) { $ok = $post; } } } } return $ok; } function _is_post_in_comic_category($post_id) { global $comicpress_manager; $ok = false; extract($comicpress_manager->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; } } return $ok; } /** * Handle updating a post. If Edit Post Integration is enabled, and the post * date is changing, rename the file as necessary. */ function handle_pre_post_update($post_id) { global $comicpress_manager; if (($post = $this->_verify_post_before_hook($post_id)) !== false) { if ($this->_is_post_in_comic_category($post_id)) { $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($comicpress_manager->comic_files)) { $comicpress_manager->read_information_and_check_config(); } foreach ($comicpress_manager->comic_files as $file) { $filename = pathinfo($file, PATHINFO_BASENAME); if (($result = $comicpress_manager->breakdown_comic_filename($filename)) !== false) { if ($result['date'] == $original_date) { foreach ($this->find_thumbnails_by_filename($file) as $thumb_file) { $this->_f->rename($thumb_file, str_replace("/${original_date}", "/${new_date}", $thumb_file)); } $this->_f->rename($file, str_replace("/${original_date}", "/${new_date}", $file)); } } } $comicpress_manager->comic_files = null; } } } } } /** * Find all the thumbnails for a particular image root. */ function find_thumbnails_by_filename($filename) { global $comicpress_manager; $thumbnails_found = array(); foreach ($comicpress_manager->folders as $folder_info) { list($name, $property, $is_fatal, $type) = $folder_info; if ($type !== "") { if ($comicpress_manager->separate_thumbs_folder_defined[$type]) { $thumb_filename = str_replace('/' . $comicpress_manager->properties["comic_folder"] . '/', '/' . $comicpress_manager->properties[$property] . '/', $filename); if ($this->_f->file_exists($thumb_filename)) { $thumbnails_found[$type] = substr(realpath($thumb_filename), CPM_STRLEN_REALPATH_DOCUMENT_ROOT); } } } } return $thumbnails_found; } /** * Handle editing a post. */ function handle_edit_post($post_id) { global $comicpress_manager; if (($post = $this->_verify_post_before_hook($post_id)) !== false) { $ok = $this->_is_post_in_comic_category($post_id); extract($comicpress_manager->get_all_comic_categories()); if (isset($this->_uploaded_files['comicpress-replace-image']) && !$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 (isset($this->_uploaded_files['comicpress-replace-image'])) { $_POST['override-date'] = $new_date; $this->handle_file_uploads(array('comicpress-replace-image')); } } } } function handle_uploaded_file($temp_path, $target_root, $source_filename, $target_filename) { global $comicpress_manager; $returns = array(); extract($this->do_gd_file_check_on_upload($temp_path, $target_filename)); if ($result !== false) { extract($result, EXTR_PREFIX_ALL, "filename"); if ($file_ok) { if (($obfuscated_filename = $this->obfuscate_filename($target_filename)) !== $target_filename) { $returns[] = array($this->return_values['OBFUSCATED_RENAMED'], $target_filename, $obfuscate_filename, $result['converted_title']); $target_filename = $obfuscated_filename; } $this->_f->rename($temp_path, $target_root . '/' . $target_filename); if ($this->_f->file_exists($target_root . '/' . $target_filename)) { $returns[] = array($this->return_values['FILE_CREATED'], $target_root . '/' . $target_filename); $returns[] = array($this->return_values['FILE_UPLOADED'], $target_filename); if ($gd_did_rename) { $returns[] = array($this->return_values['GD_RENAME_FILE'], $source_filename); } if ($is_cmyk) { $returns[] = array($this->return_values['CONVERT_CMYK'], $source_filename); } } else { $returns[] = array($this->return_values['NOT_UPLOADED'], $source_filename); } } else { $returns[] = array($this->return_values['INVALID_IMAGE_TYPE'], $source_filename); } } else { $returns[] = array($this->return_values['NOT_HANDLED'], $source_filename); } return $returns; } function _try_upload_replace($target_filename, $target_root) { global $comicpress_manager; if (!empty($_POST['overwrite-existing-file-choice'])) { $original_filename = $target_filename; $target_filename = $_POST['overwrite-existing-file-choice']; if (get_magic_quotes_gpc()) { $target_filename = stripslashes($target_filename); } if (pathinfo($original_filename, PATHINFO_EXTENSION) != pathinfo($target_filename, PATHINFO_EXTENSION)) { if ($this->_f->unlink($target_root . '/' . $target_filename)) { foreach ($comicpress_manager->get_thumbnails_to_generate() as $type) { $path = CPM_DOCUMENT_ROOT . '/' . $comicpress_manager->properties[$type . "_comic_folder"]; if (($subdir = $comicpress_manager->get_subcomic_directory()) !== false) { $path .= '/' . $subdir; } $this->_f->unlink($path . '/' . $target_filename); } } $target_filename = preg_replace('#\.[^\.]+$#', '', $target_filename) . '.' . pathinfo($original_filename, PATHINFO_EXTENSION); } return $target_filename; } return false; } function _generate_post_for_uploaded_file($target_filename, $override_converted_title = null) { global $comicpress_manager; if (($result = $comicpress_manager->breakdown_comic_filename($target_filename)) !== false) { extract($result, EXTR_PREFIX_ALL, "filename"); if (!empty($override_converted_title)) { $filename_converted_title = $override_converted_title; } if (($post_hash = $comicpress_manager->generate_post_hash($filename_date, $filename_converted_title)) !== false) { extract($post_hash); $ok_to_create_post = true; if (isset($_POST['duplicate_check'])) { $ok_to_create_post = (($post_id = post_exists($post_title, $post_content, $post_date)) == 0); } if ($ok_to_create_post) { if (!is_null($post_id = wp_insert_post($post_hash))) { foreach (array('hovertext', 'transcript') as $field) { if (!empty($_POST["${field}-to-use"])) { update_post_meta($post_id, $field, $_POST["${field}-to-use"]); } } return array($this->return_values['POST_CREATED'], get_post($post_id, ARRAY_A)); } } else { return array($this->return_values['DUPLICATE_POST'], get_post($post_id, ARRAY_A), $target_filename); } } } return array($this->return_values['INVALID_FILENAME'], $target_filename); } /** * Handle uploading a set of files. * @param array $files A list of valid $_FILES keys to process. */ function handle_file_uploads($files) { global $comicpress_manager; $posts_created = array(); $duplicate_posts = array(); $files_uploaded = array(); $thumbnails_written = array(); $invalid_filenames = array(); $thumbnails_not_written = array(); $files_not_uploaded = array(); $invalid_image_types = array(); $gd_rename_file = array(); $did_convert_cmyk_jpeg = array(); $target_root = CPM_DOCUMENT_ROOT . '/' . $comicpress_manager->properties[$_POST['upload-destination'] . "_folder"]; if (($subdir = $comicpress_manager->get_subcomic_directory()) !== false) { $target_root .= '/' . $subdir; } $write_thumbnails = isset($_POST['thumbnails']) && ($_POST['upload-destination'] == "comic"); $new_post = isset($_POST['new_post']) && ($_POST['upload-destination'] == "comic"); $ok_to_keep_uploading = true; $files_created_in_operation = array(); $filename_original_titles = array(); foreach ($files as $key) { if (isset($this->_uploaded_files[$key])) { $temp_paths_and_targets = array(); if (strpos($_FILES[$key]['name'], ".zip") !== false) { //harmonious zip_open zip_entry_name zip_read zip_entry_read zip_entry_open zip_entry_filesize zip_entry_close zip_close if (extension_loaded("zip")) { if (is_resource($zip = zip_open($_FILES[$key]['tmp_name']))) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { $comic_file = zip_entry_name($zip_entry); $temp_path = $target_root . '/' . md5($comic_file . rand()); $this->_f->file_write_contents($temp_path, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))); $target_filename = pathinfo(zip_entry_name($zip_entry), PATHINFO_BASENAME); $temp_paths_and_targets[] = compact('comic_file', 'temp_path', 'target_filename'); zip_entry_close($zip_entry); } } zip_close($zip); } } else { $comicpress_manager->warnings[] = sprintf(__("The Zip extension is not installed. %s was not processed.", 'comicpress-manager'), $_FILES[$key]['name']); } //harmonious_end } else { $target_filename = $_FILES[$key]['name']; if (get_magic_quotes_gpc()) { $target_filename = stripslashes($target_filename); } if (($upload_replace_result = $this->_try_upload_replace($target_filename, $target_root)) !== false) { $new_post = false; $comicpress_manager->messages[] = sprintf(__('Uploaded file %1$s renamed to %2$s.', 'comicpress-manager'), $target_filename, $upload_replace_result); $target_filename = $upload_replace_result; $result = $comicpress_manager->breakdown_comic_filename($target_filename); } else { if (count($files) == 1) { if (!empty($_POST['override-date'])) { $date = strtotime($_POST['override-date']); if (($date !== false) && ($date !== -1)) { $new_date = date(CPM_DATE_FORMAT, $date); $old_filename = $target_filename; if (($target_result = $comicpress_manager->breakdown_comic_filename($target_filename, true)) !== false) { $target_filename = $new_date . $target_result['title'] . '.' . pathinfo($target_filename, PATHINFO_EXTENSION); } else { $target_filename = $new_date . '-' . $target_filename; } if ($old_filename !== $target_filename) { $comicpress_manager->messages[] = sprintf(__('Uploaded file %1$s renamed to %2$s.', 'comicpress-manager'), $_FILES[$key]['name'], $target_filename); } $result = $comicpress_manager->breakdown_comic_filename($target_filename); } else { if (preg_match('/\S/', $_POST['override-date']) > 0) { $comicpress_manager->warnings[] = sprintf(__("Provided override date %s is not parseable by strtotime().", 'comicpress-manager'), $_POST['override-date']); } } } } $result = $comicpress_manager->breakdown_comic_filename($target_filename, true); if ($result !== false) { // bad file, can we get a date attached? if (isset($_POST['upload-date-format']) && !empty($_POST['upload-date-format'])) { $target_filename = date(CPM_DATE_FORMAT, strtotime($result['date'])) . $result['title'] . '.' . pathinfo($_FILES[$key]['name'], PATHINFO_EXTENSION); } } } $comic_file = $_FILES[$key]['name']; $temp_path = $_FILES[$key]['tmp_name']; $temp_paths_and_targets[] = compact('comic_file', 'temp_path', 'target_filename'); } foreach ($temp_paths_and_targets as $info) { extract($info); if (file_exists($temp_path)) { $results = $this->handle_uploaded_file($temp_path, $target_root, $comic_file, $target_filename); foreach ($results as $result) { switch ($result[0]) { case $this->return_values['OBFUSCATED_RENAMED']: $comicpress_manager->messages[] = sprintf(__('Uploaded file %1$s renamed to %2$s.', 'comicpress-manager'), $result[1], $result[2]); $filename_original_titles[$result[2]] = $result[3]; break; case $this->return_values['FILE_CREATED']: $files_created_in_operation[] = $result[1]; break; case $this->return_values['FILE_UPLOADED']: $files_uploaded[] = $result[1]; break; case $this->return_values['GD_RENAME_FILE']: $gd_rename_file[] = $result[1]; break; case $this->return_values['CONVERT_CMYK']: $did_convert_cmyk_jpeg[] = $result[1]; break; case $this->return_values['INVALID_IMAGE_TYPE']: $invalid_image_types[] = $result[1]; break; case $this->return_values['NOT_HANDLED']: $invalid_filenames[] = $result[1]; break; case $this->return_values['NOT_UPLOADED']: $files_not_uploaded[] = $result[1]; break; } } if (($result = $comicpress_manager->breakdown_comic_filename($target_filename, true)) !== false) { extract($result, EXTR_PREFIX_ALL, 'filename'); $target_path = $target_root . '/' . $target_filename; if (!empty($_POST['upload-date-format'])) { $target_filename = date(CPM_DATE_FORMAT, strtotime($result['date'])) . $result['title'] . '.' . pathinfo($target_filename, PATHINFO_EXTENSION); } if ( ($comicpress_manager->scale_method_cache == CPM_SCALE_IMAGEMAGICK) && ($comicpress_manager->get_cpm_option('cpm-strip-icc-profiles') == "1") && !empty($output_file)) { $temp_output_file = $output_file . '.' . md5(rand()); $command = array("convert", "\"${output_file}\"", "-strip", "\"${temp_output_file}\""); $strip_profiles = escapeshellcmd(implode(" ", $command)); exec($strip_profiles); if (file_exists($temp_output_file)) { $this->_f->unlink($output_file); $this->_f->rename($temp_output_file, $output_file); } } } else { $invalid_filenames[] = $comic_file; } } else { $invalid_filenames[] = $comic_file; } @unlink($temp_path); } } } if (function_exists('get_site_option')) { if (cpm_wpmu_is_over_storage_limit()) { $ok_to_keep_uploading = false; break; } } if ($ok_to_keep_uploading) { foreach ($files_uploaded as $target_filename) { $target_path = $target_root . '/' . $target_filename; $this->_f->chmod($target_path, CPM_FILE_UPLOAD_CHMOD); if ($write_thumbnails) { $wrote_thumbnail = $this->write_thumbnail($target_path, $target_filename, true); } if (!is_null($wrote_thumbnail)) { if (is_array($wrote_thumbnail)) { $thumbnails_written[] = $target_filename; $files_created_in_operation = array_merge($files_created_in_operation, $wrote_thumbnail); } else { $thumbnails_not_written[] = $target_filename; } } } if (function_exists('get_site_option')) { if (cpm_wpmu_is_over_storage_limit()) { $ok_to_keep_uploading = false; } } } if ($ok_to_keep_uploading) { if ($new_post) { foreach ($files_uploaded as $target_filename) { $override = (isset($filename_original_titles[$target_filename]) ? $filename_original_titles[$target_filename] : null); $result = $this->_generate_post_for_uploaded_file($target_filename, $override); switch ($result[0]) { case $this->return_values['POST_CREATED']: $posts_created[] = $result[1]; break; case $this->return_values['DUPLICATE_POST']: $duplicate_posts[] = array($result[1], $result[2]); break; case $this->return_values['INVALID_FILENAME']: $invalid_filenames[] = $result[1]; break; } } } $this->display_operation_messages(compact('invalid_filenames', 'files_uploaded', 'files_not_uploaded', 'thumbnails_written', 'thumbnails_not_written', 'posts_created', 'duplicate_posts', 'invalid_image_types', 'gd_rename_file', 'did_convert_cmyk_jpeg')); } else { $comicpress_manager->messages = array(); $comicpress_manager->warnings = array($comicpress_manager->wpmu_disk_space_message); foreach ($files_created_in_operation as $file) { @unlink($file); } } return array($posts_created, $duplicate_posts); } /** * Check an uploaded file with GD. */ function do_gd_file_check_on_upload($check_file_path, $target_filename) { global $comicpress_manager; $file_ok = true; $is_cmyk = false; $result = $comicpress_manager->breakdown_comic_filename($target_filename, true); if (extension_loaded("gd") && ($comicpress_manager->get_cpm_option('cpm-perform-gd-check') == 1)) { $file_ok = (($image_info = $comicpress_manager->gd_processor->get_image_size($check_file_path)) !== false); if ($file_ok) { if (($image_info[2] == IMAGETYPE_JPEG) && ($image_info['channels'] == 4)) { $is_cmyk = true; $file_ok = false; $temp_check_file_path = $check_file_path . md5(rand()); $method = $comicpress_manager->scale_method; if (!empty($method)) { if ($method->convert_to_rgb($check_file_path, $temp_check_file_path, $comicpress_manager->get_cpm_option("cpm-thumbnail-quality"))) { $this->_f->rename($temp_check_file_path, $check_file_path); $file_ok = true; } } } if ($file_ok) { $current_extension = strtolower(pathinfo($target_filename, PATHINFO_EXTENSION)); if ($current_extension != "") { $remove_extension = false; switch($image_info[2]) { case IMAGETYPE_GIF: $remove_extension = !in_array($current_extension, array("gif")); break; case IMAGETYPE_JPEG: $remove_extension = !in_array($current_extension, array("jpg", "jpeg")); break; case IMAGETYPE_PNG: $remove_extension = !in_array($current_extension, array("png")); break; } if ($remove_extension) { $target_filename = preg_replace('#\.[^\.]+$#', '', $target_filename); } } if (pathinfo($target_filename, PATHINFO_EXTENSION) == "") { $new_extension = ""; switch($image_info[2]) { case IMAGETYPE_GIF: $new_extension = "gif"; break; case IMAGETYPE_JPEG: $new_extension = "jpg"; break; case IMAGETYPE_PNG: $new_extension = "png"; break; } if ($new_extension != "") { $target_filename .= '.' . $new_extension; } $result = $comicpress_manager->breakdown_comic_filename($target_filename, true); $gd_did_rename = true; } } } } return compact('file_ok', 'gd_did_rename', 'result', 'target_filename', 'is_cmyk'); } /** * Obfuscate a filename. */ function obfuscate_filename($filename) { global $comicpress_manager; if (($result = $comicpress_manager->breakdown_comic_filename($filename)) !== false) { $md5_key = substr(md5(rand() + strlen($filename)), 0, 8); $extension = pathinfo($filename, PATHINFO_EXTENSION); $mode = $comicpress_manager->get_cpm_option('cpm-obfuscate-filenames-on-upload'); switch ($mode) { case "append": return $result['date'] . $result['title'] . '-' . $md5_key . '.' . $extension; break; case "replace": return $result['date'] . '-' . $md5_key . '.' . $extension; break; } } return $filename; } /** * Write a thumbnail image to the thumbnail folders. * @param string $input The input image filename. * @param string $target_filename The filename for the thumbnails. * @param boolean $do_rebuild If true, force rebuilding thumbnails. * @return mixed True if successful, false if not, null if unable to write. */ function write_thumbnail($input, $target_filename, $do_rebuild = false) { global $comicpress_manager; $target_format = pathinfo($target_filename, PATHINFO_EXTENSION); $files_created_in_operation = array(); $write_targets = array(); foreach ($comicpress_manager->separate_thumbs_folder_defined as $type => $value) { if ($value) { if ($comicpress_manager->thumbs_folder_writable[$type]) { $converted_target_filename = preg_replace('#\.[^\.]+$#', '', $target_filename) . '.' . $target_format; $target = CPM_DOCUMENT_ROOT . '/' . $comicpress_manager->properties[$type . "_comic_folder"]; if (($subdir = $comicpress_manager->get_subcomic_directory()) !== false) { $target .= '/' . $subdir; } $target .= '/' . $converted_target_filename; if (!in_array($target, $write_targets)) { $write_targets[$type] = $target; } } } } if (count($write_targets) > 0) { if (!$do_rebuild) { if ($this->_f->file_exists($input)) { if ($this->_f->file_exists($target)) { $t1 = $this->_f->filemtime($input); $t2 = $this->_f->filemtime($target); if ($t1 > $t2) { $do_rebuild = true; } } else { $do_rebuild = true; } } } if ($do_rebuild) { if ($comicpress_manager->scale_method != false) { $targets_and_constraints = array(); foreach ($write_targets as $type => $target) { $targets_and_constraints[] = array( $target, array( 'width' => (isset($comicpress_manager->properties["${type}_comic_width"])) ? $comicpress_manager->properties["${type}_comic_width"] : $comicpress_manager->properties['archive_comic_width'] ) ); } return $comicpress_manager->scale_method->generate_thumbnails($input, $targets_and_constraints, strtolower($target_format), $comicpress_manager->get_cpm_option("cpm-thumbnail-quality")); } } } return null; } /** * Display messages when CPM operations are completed. */ function display_operation_messages($info) { global $comicpress_manager; extract($info); if (count($invalid_filenames) > 0) { $comicpress_manager->messages[] = __("The following filenames were invalid: ", 'comicpress-manager') . implode(", ", $invalid_filenames); } if (count($invalid_image_types) > 0) { $comicpress_manager->warnings[] = __("According to GD, the following files were invalid image files: ", 'comicpress-manager') . implode(", ", $invalid_image_types); } if (count($files_uploaded) > 0) { $comicpress_manager->messages[] = __("The following files were uploaded: ", 'comicpress-manager') . implode(", ", $files_uploaded); } if (count($files_not_uploaded) > 0) { $comicpress_manager->messages[] = __("The following files were not uploaded, or the permissions on the uploaded file do not allow reading the file. Check the permissions of both the target directory and the upload directory and try again: ", 'comicpress-manager') . implode(", ", $files_not_uploaded); } if (count($thumbnails_written) > 0) { $comicpress_manager->messages[] = __("Thumbnails were written for the following files: ", 'comicpress-manager') . implode(", ", $thumbnails_written); } if (count($thumbnails_not_written) > 0) { $comicpress_manager->messages[] = __("Thumbnails were not written for the following files. Check the permissions on the rss & archive folders, and make sure the files you're processing are valid image files: ", 'comicpress-manager') . implode(", ", $thumbnails_not_written); } if (count($new_thumbnails_not_needed) > 0) { $comicpress_manager->messages[] = __("New thumbnails were not needed for the following files: ", 'comicpress-manager') . implode(", ", $new_thumbnails_not_needed); } if (count($gd_rename_file) > 0) { $comicpress_manager->messages[] = __("GD was able to recognize the filetypes of these files and change their extensions to match: ", 'comicpress-manager') . implode(", ", $gd_rename_file); } if (count($did_convert_cmyk_jpeg) > 0) { $comicpress_manager->messages[] = __("The following JPEG files have been converted from CMYK to RGB: ", 'comicpress-manager') . implode(", ", $did_convert_cmyk_jpeg); } if (count($posts_created) > 0) { $post_links = array(); foreach ($posts_created as $comic_post) { $post_links[] = "
  • " . $comic_post['post_title'] . " (" . $comic_post['post_date'] . ") " . generate_view_edit_post_links($comic_post) . "
  • "; } $comicpress_manager->messages[] = __("New posts created. View them from the links below:", 'comicpress-manager') . " "; } else { if (count($files_uploaded) > 0) { if (count($duplicate_posts) == 0) { $comicpress_manager->messages[] = __("No new posts created.", 'comicpress-manager'); } } } if (count($duplicate_posts) > 0) { $post_links = array(); foreach ($duplicate_posts as $info) { list($comic_post, $comic_file) = $info; $post_links[] = "
  • " . $comic_file . " — " . $comic_post['post_title'] . " (" . $comic_post['post_date'] . ") " . generate_view_edit_post_links($comic_post) . "
  • "; } $comicpress_manager->messages[] = __("The following files would have created duplicate posts. View them from the links below: ", 'comicpress-manager') . ""; } } /** * Find a comic file by date. */ function find_comic_by_date($timestamp) { global $comicpress_manager; if (!is_numeric($timestamp)) { return false; } $files = $this->_f->glob($comicpress_manager->get_comic_folder_path() . '/' . date(CPM_DATE_FORMAT, $timestamp) . '*'); if (empty($files)) { return false; } foreach ($files as $file) { if (in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), $comicpress_manager->allowed_extensions)) { return $file; } } return false; } /** * Handle deleting a post. If Edit Post Integration is enabled, delete any associated * files from the comics folders. */ function handle_delete_post($post_id) { global $comicpress_manager; if (!$comicpress_manager->is_cpm_managing_posts) { if ($comicpress_manager->get_cpm_option("cpm-edit-post-integrate") == 1) { $post = get_post($post_id); if (!empty($post)) { if (!in_array($post->post_type, array("attachment", "revision", "page"))) { $ok = $this->_is_post_in_comic_category($post_id); if ($ok) { if (($parsed_date = strtotime($post->post_date)) !== false) { $original_date = date(CPM_DATE_FORMAT, $parsed_date); if (empty($comicpress_manager->comic_files)) { $comicpress_manager->read_information_and_check_config(); } if (is_array($comicpress_manager->comic_files)) { foreach ($comicpress_manager->comic_files as $file) { $filename = pathinfo($file, PATHINFO_BASENAME); if (($result = $comicpress_manager->breakdown_comic_filename($filename)) !== false) { if ($result['date'] == $original_date) { foreach ($this->find_thumbnails_by_filename($file) as $thumb_file) { $thumb_file = CPM_DOCUMENT_ROOT . $thumb_file; $this->_f->unlink($thumb_file); } $this->_f->unlink($file); } } } } } } } } } } } /** * If a category is added, deleted, or edited, and it's not done through * the Storyline Structure page, normalize the Storyline Structure * so that it includes/removes the affected categories. */ function rebuild_storyline_structure($term_id) { global $comicpress_manager; if (empty($comicpress_manager->is_cpm_modifying_categories)) { $comicpress_manager->read_information_and_check_config(); $comicpress_manager->normalize_storyline_structure(); } } /** * Add the Comic column to Edit Posts. */ function manage_posts_columns($posts_columns) { wp_enqueue_script('prototype'); $posts_columns['comic'] = "Comic"; return $posts_columns; } /** * Populate the Comic coulmn in Edit Posts. */ function manage_posts_custom_column($column_name) { global $comicpress_manager, $post, $comicpress_manager_admin; if ($column_name == "comic") { $post_date = date(CPM_DATE_FORMAT, strtotime($post->post_date)); if ($is_first = empty($this->broken_down_comic_files)) { $this->broken_down_comic_files = array(); if (empty($comicpress_manager->comic_files)) { $comicpress_manager->read_information_and_check_config(); } if (is_array($comicpress_manager->comic_files) && !empty($comicpress_manager->comic_files)) { foreach ($comicpress_manager->comic_files as $file) { $filename = pathinfo($file, PATHINFO_BASENAME); if (($result = $comicpress_manager->breakdown_comic_filename($filename)) !== false) { if (!isset($this->broken_down_comic_files[$result['date']])) { $this->broken_down_comic_files[$result['date']] = array(); } $this->broken_down_comic_files[$result['date']][] = $file; } } if (!empty($this->broken_down_comic_files)) { ?> broken_down_comic_files)) { $ok = false; $categories = wp_get_post_categories($post->ID); if ($comicpress_manager->get_subcomic_directory() !== false) { $ok = in_array(get_option('comicpress-manager-manage-subcomic'), $categories); } else { extract($comicpress_manager->get_all_comic_categories()); foreach ($category_tree as $node) { if (in_array(end(explode("/", $node)), $categories)) { $ok = true; break; } } } if ($ok) { if (isset($this->broken_down_comic_files[$post_date])) { $index = 0; foreach ($this->broken_down_comic_files[$post_date] as $file) { $image_index = $post->ID . '-' . $index; $thumbnails_found = $this->find_thumbnails_by_filename($file); $icon_file_to_use = $file; if (is_array($thumbnails_found)) { foreach ($thumbnails_found as $type => $value) { if (!empty($value)) { $icon_file_to_use = $value; } } } $hovertext = get_post_meta($post->ID, "hovertext", true); ?>
    2, 'show_summary' => true)); echo $after_widget; } /** * Add the QuomicPress Dashboard widget. */ function 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 quomicpress_widget($sidebar_args) { if (is_array($sidebar_args)) { extract($sidebar_args, EXTR_SKIP); } echo $before_widget . $before_title . $widget_name . $after_title; $this->_show_view("ComicPressQuomicPressWidget"); echo $after_widget; } /** * Write all of the styles and scripts. */ function write_global_styles_scripts() { global $comicpress_manager, $blog_id; $plugin_url_root = get_option('siteurl') . '/' . $this->get_plugin_path(); $ajax_request_url = isset($_SERVER['URL']) ? $_SERVER['URL'] : $_SERVER['SCRIPT_URL']; ?> include_javascript("comicpress_script.js") ?> need_calendars) { ?> _f->realpath(dirname(__FILE__) . '/../js'); $plugin_url_root = get_option('siteurl') . '/' . $this->get_plugin_path(); $regular_file = $name; $minified_file = 'minified-' . $name; $file_to_use = $regular_file; if ($this->_f->file_exists($js_path . '/' . $minified_file)) { if ($this->_f->filemtime($js_path . '/' . $minified_file) >= $this->_f->filemtime($js_path . '/' . $regular_file)) { $file_to_use = $minified_file; } } ?>_f->glob(dirname($comicpress_manager->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); return $available_backup_files; } function handle_warnings() { global $comicpress_manager; // display informative messages to the use // TODO: remove separate arrays and tag messages based on an enum value foreach (array( array( $comicpress_manager->messages, __("The operation you just performed returned the following:", 'comicpress-manager'), 'messages'), array( $comicpress_manager->warnings, __("The following warnings were generated:", 'comicpress-manager'), 'warnings'), array( $comicpress_manager->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) { ?>

    show_config_editor = true; } else { if ($comicpress_manager->config_method == "comicpress-config.php") { if (!$comicpress_manager->can_write_config) { $update_automatically = false; } } else { if (count($available_backup_files) > 0) { if (!$comicpress_manager->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']) ?>

    get_backup_files(); if (count($available_backup_files) > 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 $this->edit_config(); } ?>
    () show_debug_info(false); } return false; } return true; } /** * Show site debug info. */ function show_debug_info($display_none = true) { global $comicpress_manager; ob_start(); ?> >comic_files) . " comic files"; $output_config['config_filepath'] = substr(realpath($comicpress_manager->config_filepath), CPM_STRLEN_REALPATH_DOCUMENT_ROOT); $output_config['path'] = substr(realpath($comicpress_manager->path), CPM_STRLEN_REALPATH_DOCUMENT_ROOT); $output_config['zip_enabled'] = extension_loaded("zip"); clearstatcache(); $output_config['folder_perms'] = array(); $subdir = ""; if (($subdir = $comicpress_manager->get_subcomic_directory()) !== false) { $subdir = '/' . $subdir; } foreach (array( 'comic' => CPM_DOCUMENT_ROOT . '/' . $comicpress_manager->properties['comic_folder'] . $subdir, 'rss' => CPM_DOCUMENT_ROOT . '/' . $comicpress_manager->properties['rss_comic_folder'] . $subdir, 'archive' => CPM_DOCUMENT_ROOT . '/' . $comicpress_manager->properties['archive_comic_folder'] . $subdir, 'config' => $comicpress_manager->config_filepath ) as $key => $path) { if (($s = @stat($path)) !== false) { $output_config['folder_perms'][$key] = decoct($s[2]); } else { $output_config['folder_perms'][$key] = "folder does not exist"; } } $new_output_config = array(); foreach ($output_config as $key => $value) { if (is_string($value)) { $value = htmlentities($value); } $new_output_config[$key] = $value; } var_dump($new_output_config); ?> 0) { $file = array_shift($folder_stack); if (is_dir($file)) { $root_file = substr($file, strlen(CPM_DOCUMENT_ROOT) + 1); if (preg_match("#(${folders_to_ignore})$#", $root_file) == 0) { if (count(explode("/", $root_file)) <= $max_depth) { $found_folders[] = $root_file; $folder_stack = array_merge($folder_stack, glob($file . "/*")); } else { if (!$max_depth_message) { $comicpress_manager->messages[] = sprintf(__("I went %s levels deep in my search for comic directories. Are you sure you have your site set up correctly?", 'comicpress-manager'), $max_depth); $max_depth_message = true; } } } } if (count($found_folders) == $max_directories) { $comicpress_manager->messages[] = sprintf(__("I found over %s directories from your site root. Are you sure you have your site set up correctly?", 'comicpress-manager'), $max_directories); break; } } sort($found_folders); ob_start(); ?>
    (" . $description . ")"; $config_id = (isset($field_info['variable_name'])) ? $field_info['variable_name'] : $field_info['id']; switch($type) { case "category": ?> properties[$config_id], $found_folders); ?> properties["${folder_name}comic_folder"])) { $all_comic_folders_found = false; break; } } if (!$all_comic_folders_found) { ?> is_wp_options) { ?>
    :
    : />
    />
    :

    Create your comics, archive, or RSS folders first, then reload this page and use the dropdowns to select the target folder. If ComicPress Manager can't automatically find your folders, you can enter the folder names into the dropdowns.", 'comicpress-manager') ?>

    " />
    get_plugin_path()); $comicpress_manager->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; $this->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, array($this, "_index_caller"), get_option('siteurl') . '/' . $this->get_plugin_path() . '/comicpress-icon.png'); add_submenu_page($filename, $plugin_title, __("Upload", 'comicpress-manager'), $access_level, $filename, array($this, '_index_caller')); if (!function_exists('get_site_option')) { add_submenu_page($filename, $plugin_title, __("Import", 'comicpress-manager'), $access_level, $filename . '-import', array($this, '_import_caller')); } add_submenu_page($filename, $plugin_title, __("Bulk Edit", 'comicpress-manager'), $access_level, $filename . '-status', array($this, '_bulk_edit_caller')); add_submenu_page($filename, $plugin_title, __("Storyline Structure", 'comicpress-manager'), $access_level, $filename . '-storyline', array($this, '_storyline_caller')); add_submenu_page($filename, $plugin_title, __("Change Dates", 'comicpress-manager'), $access_level, $filename . '-dates', array($this, '_dates_caller')); add_submenu_page($filename, $plugin_title, __("ComicPress Config", 'comicpress-manager'), $access_level, $filename . '-config', array($this, '_comicpress_config_caller')); add_submenu_page($filename, $plugin_title, __("Manager Config", 'comicpress-manager'), $access_level, $filename . '-cpm-config', array($this, '_manager_config_caller')); if ($pagenow == "index.php") { if ($comicpress_manager->get_cpm_option('cpm-enable-dashboard-rss-feed') == 1) { wp_register_sidebar_widget( 'dashboard_cpm', __("ComicPress News", "comicpress-manager"), array($this, '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', array($this, 'add_dashboard_widget')); } if (($option = generate_comic_categories_options('category')) !== false) { if ($comicpress_manager->get_cpm_option('cpm-enable-quomicpress') == 1) { if (count($comicpress_manager->errors) == 0) { wp_register_sidebar_widget( 'dashboard_quomicpress', __("QuomicPress (Quick ComicPress)", "comicpress-manager"), array($this, 'quomicpress_widget'), array( 'width' => 'half' ) ); add_filter('wp_dashboard_widgets', array($this, 'add_quomicpress_widget')); } } } } } function _index_caller() { $this->_show_view('ComicPressUpload'); } /** * Handle all ComicPress actions. */ function handle_actions() { global $comicpress_manager; $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'])); } } } } ?>