$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 "
| '.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.' | '; echo '