Example #1
0
function create_episode()
{
    $slug = isset($_REQUEST['slug']) ? $_REQUEST['slug'] : NULL;
    $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : NULL;
    if (!$slug || !$title) {
        die;
    }
    $args = array('post_type' => 'podcast', 'post_title' => $title, 'post_content' => \Podlove\Podcast_Post_Type::$default_post_content);
    // create post
    $post_id = wp_insert_post($args);
    // link episode and release
    $episode = \Podlove\Model\Episode::find_or_create_by_post_id($post_id);
    $episode->slug = $slug;
    $episode->enable = true;
    $episode->active = true;
    $episode->save();
    // activate all media files
    $episode_assets = Model\EpisodeAsset::all();
    foreach ($episode_assets as $episode_asset) {
        $media_file = new \Podlove\Model\MediaFile();
        $media_file->episode_id = $episode->id;
        $media_file->episode_asset_id = $episode_asset->id;
        $media_file->save();
    }
    // generate response
    $result = array();
    $result['post_id'] = $post_id;
    $result['post_edit_url'] = get_edit_post_link($post_id);
    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;
}
 /**
  * Public URL
  * 
  * If tracking is active, this generates the tracking URL.
  * Otherwise, it's identical to `.url`.
  * 
  * - source: download source for tracking, for example "webplayer", "download" or "feed"
  * - context: (optional) download context for tracking, for example "home"/"episode"/"archive" for player source or feed slug for feed source
  * 
  * @accessor
  */
 public function publicUrl($source, $context = null)
 {
     return $this->file->get_public_file_url($source, $context);
 }