$year_pattern, "m" => '[0-9]{2}', "d" => '[0-9]{2}')); if (@preg_match("#^({$new_pattern})(.*)\.[^\.]+$#", $filename, $matches) > 0) { list($all, $date, $title) = $matches; if (strtotime($date) === false) { return false; } $converted_title = ucwords(trim(preg_replace('/[\-\_]/', ' ', $title))); $date = date($import_date_format, strtotime($date)); if (is_numeric($converted_title)) { $converted_title = "Title: {$converted_title}"; } return compact('filename', 'date', 'title', 'converted_title'); } } return false; } function ceo_import_add_comic_and_post($comic_to_add, $date_to_add, $title_to_add, $import_create_post, $import_chapter, $import_time, $import_directory) { global $wpdb; // (TODO) check to see if the post already exists THEN do wp_insert_post below // $import_create_post // get the $timestamp set correctly $post_date = date('Y-m-d H:i:s', strtotime($date_to_add .= " " . $import_time)); $post_args = array( 'post_name' => sanitize_title($title_to_add), 'post_title' => $title_to_add, 'post_date' => $post_date, 'post_type' => 'comic', 'post_status' => 'publish', 'tax_input' => array( 'chapters' => array($import_chapter) ) ); $post_id = wp_insert_post($post_args); if (!is_wp_error($post_id)) { // Attach the Comic Now $file_url = (is_multisite()) ? esc_url(network_home_url().'/'.$import_directory.'/'.$comic_to_add) : esc_url(home_url().'/'.$import_directory.'/'.$comic_to_add); $comic = new WP_Http(); $comic = $comic->request( $file_url ); if (!is_wp_error($comic)) { $comic_date = isset($comic['headers']['last-modified']) ? $comic['headers']['last-modified'] : $comic['headers']['date']; $attachment = wp_upload_bits( $comic_to_add, null, $comic['body'], date("Y-m", strtotime( $comic_date ) ) ); if (!is_wp_error($attachment)) { $filetype = wp_check_filetype( basename( $attachment['file'] ), null ); $postinfo_args = array( 'guid' => $attachment['file'], 'post_mime_type' => $filetype['type'], 'post_title' => 'comic-'.$comic_to_add, 'post_content' => '', 'post_status' => 'inherit', ); $attached_filename = $attachment['file']; $attach_id = wp_insert_attachment( $postinfo_args, $attached_filename, $post_id ); $attach_data = wp_generate_attachment_metadata( $attach_id, $attached_filename ); wp_update_attachment_metadata($attach_id, $attach_data); // set it as the post featured image add_post_meta($post_id, '_thumbnail_id', $attach_id, true); set_post_thumbnail($post_id, $attach_id); return __('Comic Post made and Comic Attached','comic-easel'); } else return $attachment->get_error_message(); } else return $comic->get_error_message(); } else return $post_id->get_error_message(); return false; } function ceo_import_by_namedate($import_directory, $import_date_format, $import_filename_mask, $import_create_post, $import_chapter, $import_time) { echo '

'.esc_html__('Import type: by Filename w/date','comic-easel').'

'; $file_list = array(); if (count($results = glob(ABSPATH.$import_directory.'/*.*')) > 0) { echo count($results).' '.esc_html__('Files found.','comic-easel')."
\r\n"; natcasesort($results); foreach ($results as $filename) { $breakdown = ceo_breakdown_comic_filename(basename($filename), $import_date_format, $import_filename_mask); if ($breakdown && is_array($breakdown)) $file_list[] = $breakdown; } echo count($file_list).' '.esc_html__('files have valid naming and can be imported.','comic-easel'); } else { echo esc_html__('No files found in','comic-easel').' '.esc_html(ABSPATH.$import_directory).' '.esc_html__('or directory does not exist','comic-easel').'
'; return; } echo "
\r\n"; if (count($file_list)) { $chapter_object = get_term_by('id', $import_chapter, 'chapters'); echo esc_html__('Processing Files...','comic-easel').' '.esc_html__('Importing to chapter:','comic-easel').' '.esc_html($chapter_object->name).'
'."\r\n"; echo ''; foreach ($file_list as $file_to_process) { echo ''; if (empty($file_to_process['converted_title'])) $file_to_process['converted_title'] = $file_to_process['date']; $result = ceo_import_add_comic_and_post($file_to_process['filename'], $file_to_process['date'], $file_to_process['converted_title'], $import_create_post, $import_chapter, $import_time, $import_directory); $result = ($result) ? $result : __('System Process Error','comic-easel'); echo ''; echo ''; } echo '
'.esc_html__('Date:','comic-easel').' '.esc_html($file_to_process['date']).' ---- '.esc_html__('Title of Post:','comic-easel').' '.esc_html($file_to_process['converted_title']).' --- '.esc_html__('Result:','comic-easel').' '.$result.'
'; } } // Catch the return $_POST and do something with them. if ($import_request_is_valid) { switch ($import_type) { case 'namedate': ceo_import_by_namedate($import_directory, $import_date_format, $import_filename_mask, $import_create_post, $import_chapter, $import_time); break; default: esc_html_e('ERROR: No selection made.', 'comic-easel'); break; } } ?>

*/ ?> */ ?> */ ?>
/> (*1)


{DATE}


'.esc_html__('WARNING: When uploading your comics to the import directory, make sure there is only 1 comic per day, multiple comics per day will have issues.','comic-easel').''; ?>

{NUM}

Everyday
Weekdays
MWF
/>
'import-chapter', 'orderby' => 'name', 'order' => 'term_group', 'selected' => $import_chapter, 'hide_empty' => 0, 'hierarchical' => 1, 'pad_counts' => 1, 'taxonomy' => 'chapters', 'class' => 'chapter-list' ); wp_dropdown_categories( $args ); ?>

'.esc_html__('DIRECTIONS:','comic-easel').''; echo '

    '; echo '
  1. '.esc_html__('FTP into your site and create a directory named','comic-easel').' "'.esc_html($import_directory).'" '.esc_html__('off of the root installation folder of your site.','comic-easel').'
  2. '; echo '
  3. '.esc_html__('Upload into that directory the comics using the ComicPress filename convention for each individual chapter you are importing.','comic-easel').'
  4. '; echo '
  5. '.esc_html__('Make sure the chapter the comics are going into is created in the comic - chapters section of the wp-admin.','comic-easel').'
  6. '; echo '
  7. '.esc_html__('Select chapter in the import section, modify any other values as needed, if you do not know what they are, do not modify them.','comic-easel').'
  8. '; echo '
  9. '.esc_html__('Press the Import button and wish for the best.','comic-easel').'
  10. '; echo '
' ?>

*1 -
*2 -


'.esc_html(ABSPATH.$import_directory).''."
\r\n"; if (count($results = glob(ABSPATH.$import_directory.'/*.*')) > 0) { echo count($results).' '.esc_html__('Files found.','comic-easel')."
\r\n"; echo "
\r\n"; natcasesort($results); foreach ($results as $filename) { echo ''.esc_html(basename($filename)).''; } } else { echo esc_html__('No files found in','comic-easel').' '.esc_html(ABSPATH.$import_directory); }