public static function create() { $episode_id = (int) $_REQUEST['episode_id']; $episode_asset_id = (int) $_REQUEST['episode_asset_id']; if (!$episode_id || !$episode_asset_id) { die; } if (isset($_REQUEST['slug'])) { self::simulate_temporary_episode_slug($_REQUEST['slug']); } $file = MediaFile::find_or_create_by_episode_id_and_episode_asset_id($episode_id, $episode_asset_id); Ajax::respond_with_json(array('file_id' => $file->id, 'file_size' => $file->size, 'file_url' => $file->get_file_url())); }
function create_file() { $episode_id = $_REQUEST['episode_id']; $episode_asset_id = $_REQUEST['episode_asset_id']; if (!$episode_id || !$episode_asset_id) { die; } $file = Model\MediaFile::find_or_create_by_episode_id_and_episode_asset_id($episode_id, $episode_asset_id); $result = array(); $result['file_id'] = $file->id; $result['file_size'] = $file->size; header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); echo json_encode($result); die; }
function migrate_post($post_id) { $post = get_post($post_id); $migration_settings = get_option('podlove_migration', array()); $post_content = $post->post_content; if ($migration_settings['cleanup']['player']) { $post_content = preg_replace('/\\[(powerpress|podloveaudio|podlovevideo|display_podcast)[^\\]]*\\]/', '', $post_content); } $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $post->post_author, 'post_content' => $post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_parent' => $post_id, 'post_password' => $post->post_password, 'post_status' => 'pending', 'post_title' => $post->post_title, 'post_type' => 'podcast', 'post_date' => $post->post_date, 'post_date_gmt' => get_gmt_from_date($post->post_date)); $new_slug = NULL; switch ($migration_settings['post_slug']) { case 'wordpress': $new_slug = $post->post_name; break; case 'file': $new_slug = Assistant::get_file_slug($post); break; case 'number': $new_slug = Assistant::get_number_slug($post); break; } $override_slug = function ($data, $postarr) use($new_slug) { if ($new_slug) { $data['post_name'] = $new_slug; } return $data; }; add_filter('wp_insert_post_data', $override_slug, 10, 2); $new_post_id = wp_insert_post($new_post); remove_filter('wp_insert_post_data', $override_slug, 10, 2); $new_post = get_post($new_post_id); // update guid update_post_meta($new_post_id, '_podlove_guid', $post->guid); // add redirect from previous url add_post_meta($new_post_id, 'podlove_alternate_url', get_permalink($post_id)); // prevent adn module from triggering a post update_post_meta($new_post_id, '_podlove_episode_was_published', true); // migrate taxonomies $taxonomies = get_object_taxonomies(get_post_type($post_id)); foreach ($taxonomies as $tax) { $terms = wp_get_object_terms($post_id, $tax); $term = array(); foreach ($terms as $t) { $term[] = $t->slug; } wp_set_object_terms($new_post_id, $term, $tax); } $post_data = new Legacy_Post_Parser($post_id); $episode = Model\Episode::find_or_create_by_post_id($new_post_id); $episode->slug = Assistant::get_episode_slug($post, $migration_settings['slug']); $episode->duration = $post_data->get_duration(); $episode->subtitle = $post_data->get_subtitle(); $episode->summary = $post_data->get_summary(); $episode->save(); foreach (Model\EpisodeAsset::all() as $asset) { Model\MediaFile::find_or_create_by_episode_id_and_episode_asset_id($episode->id, $asset->id); } // copy all meta $meta = get_post_meta($post_id); foreach ($meta as $key => $values) { if (!in_array($key, array('enclosure', '_podPressPostSpecific', '_podPressMedia')) || !$migration_settings['cleanup']['enclosures']) { foreach ($values as $value) { add_post_meta($new_post_id, $key, $value); } } } // copy all comments $comments_map = array(); // map old comment IDs to new comment IDs foreach (get_comments(array('post_id' => $post_id, 'order' => 'ASC')) as $comment) { $old_comment_id = $comment->comment_ID; $comment->comment_post_ID = $new_post_id; if ($comment->comment_parent && isset($comments_map[$comment->comment_parent])) { $comment->comment_parent = $comments_map[$comment->comment_parent]; } $new_comment_id = wp_insert_comment((array) $comment); $comments_map[$old_comment_id] = $new_comment_id; } return $new_post_id; }