public static function get_player_printer(Episode $episode) { if (\Podlove\get_webplayer_setting('version') === 'player_v3') { $printer = new PlayerV3\Html5Printer($episode); $printer->setAttributes(['data-podlove-web-player-source' => add_query_arg(['podloveEmbed' => true], get_permalink())]); return $printer; } else { return new PlayerV2\Printer($episode); } }
/** * Render player * * @param string $context (optional) player context for tracking. Set to NULL for auto-detection. Default: NULL * @return string */ public function render($context = NULL) { if (count($this->player_format_assignments) == 0) { return ''; } // build main audio/video tag $xml = new \SimpleXMLElement('<' . $this->get_media_tag() . '/>'); $xml->addAttribute('id', $this->get_html_id()); $xml->addAttribute('controls', 'controls'); $xml->addAttribute('preload', 'none'); $width = strtolower(trim($this->get_webplayer_setting($this->get_media_tag(), 'width'))); $height = strtolower(trim($this->get_webplayer_setting($this->get_media_tag(), 'height'))); if ($this->is_video) { $xml->addAttribute('poster', $this->episode->cover_art_with_fallback()->url()); $xml->addAttribute('width', $width); $xml->addAttribute('height', $height); } else { $xml->addAttribute('style', sprintf('width: %s; height: %s', empty($width) || $width == 'auto' ? '100%' : $width . 'px', empty($height) ? '30px' : $height)); } // get all relevant info about media files $media_files = array(); foreach ($this->files as $file) { $asset = $file->episode_asset(); $mime = $asset->file_type()->mime_type; $media_files[$mime] = array('file' => $file, 'mime_type' => $mime, 'url' => $file->get_file_url(), 'publicUrl' => $file->get_public_file_url("webplayer", is_null($context) ? $this->get_tracking_context() : $context), 'assetTitle' => $asset->title()); } if (!count($media_files)) { return ""; } // sort files bases on mime type so preferred get output first $sorted_files = array(); $preferred_order = array('audio/mp4', 'audio/aac', 'audio/opus', 'audio/ogg', 'audio/vorbis'); foreach ($preferred_order as $order_key) { if (isset($media_files[$order_key]) && $media_files[$order_key]) { $sorted_files[] = $media_files[$order_key]; unset($media_files[$order_key]); } } foreach ($media_files as $file) { $sorted_files[] = $file; } // add all sources $flash_fallback_func = function (&$xml) { }; foreach ($sorted_files as $file) { $mime_type = $file['mime_type']; $source = $xml->addChild('source'); $source->addAttribute('src', $file['publicUrl']); $source->addAttribute('type', $mime_type); if ($mime_type == 'audio/mpeg') { $flash_fallback_func = function (&$xml) use($file) { $flash_fallback = $xml->addChild('object'); $flash_fallback->addAttribute('type', 'application/x-shockwave-flash'); $flash_fallback->addAttribute('data', plugins_url('player/podlove-web-player/static/', __FILE__) . 'flashmediaelement.swf'); $params = array(array('name' => 'movie', 'value' => plugins_url('player/podlove-web-player/static/', __FILE__) . 'flashmediaelement.swf'), array('name' => 'flashvars', 'value' => 'controls=true&file=' . $file['url'])); foreach ($params as $param) { $p = $flash_fallback->addChild('param'); $p->addAttribute('name', $param['name']); $p->addAttribute('value', $param['value']); } }; } } // add flash fallback after all <source>s $flash_fallback_func($xml); // prettify and prepare to render $xml_string = $xml->asXML(); $xml_string = $this->format_xml($xml_string); $xml_string = $this->remove_xml_header($xml_string); // get podcast object $podcast = Podcast::get(); if ($this->episode->license_name && $this->episode->license_url) { $license_name = $this->episode->license_name; $license_url = $this->episode->license_url; } else { $license_name = $podcast->license_name; $license_url = $podcast->license_url; } // set JavaScript options $truthy = array(true, 'true', 'on', 1, "1"); $init_options = array('pluginPath' => plugins_url('player/podlove-web-player/static/', __FILE__), 'alwaysShowHours' => true, 'alwaysShowControls' => true, 'timecontrolsVisible' => false, 'summaryVisible' => false, 'hidetimebutton' => in_array($this->get_webplayer_setting('buttons_time'), $truthy, true), 'hidedownloadbutton' => in_array($this->get_webplayer_setting('buttons_download'), $truthy, true), 'hidesharebutton' => in_array($this->get_webplayer_setting('buttons_share'), $truthy, true), 'sharewholeepisode' => in_array($this->get_webplayer_setting('buttons_sharemode'), $truthy, true), 'loop' => false, 'chapterlinks' => 'all', 'permalink' => get_permalink($this->post->ID), 'title' => get_the_title($this->post->ID), 'subtitle' => wptexturize(convert_chars(trim($this->episode->subtitle))), 'summary' => nl2br(wptexturize(convert_chars(trim($this->episode->summary)))), 'publicationDate' => mysql2date("c", $this->post->post_date), 'poster' => $this->episode->cover_art_with_fallback()->setWidth(200)->url(), 'showTitle' => $podcast->title, 'showSubtitle' => $podcast->subtitle, 'showSummary' => $podcast->summary, 'showPoster' => $podcast->cover_art()->setWidth(200)->url(), 'show' => array('title' => $podcast->title, 'subtitle' => $podcast->subtitle, 'summary' => $podcast->summary, 'poster' => $podcast->cover_art()->setWidth(200)->url(), 'url' => \Podlove\get_landing_page_url()), 'license' => array('name' => $license_name, 'url' => $license_url), 'downloads' => array_map(function ($mf) { return array('assetTitle' => $mf['assetTitle'], 'downloadUrl' => $mf['publicUrl'], 'url' => $mf['url']); }, array_values($sorted_files)), 'duration' => $this->episode->get_duration(), 'chaptersVisible' => in_array(\Podlove\get_webplayer_setting('chaptersVisible'), $truthy, true), 'features' => array("current", "progress", "duration", "tracks", "fullscreen", "volume")); if ($chapters = $this->episode->get_chapters('json')) { $init_options['chapters'] = json_decode($chapters); } $xml_string .= "\n" . "\n<script>\n" . "jQuery('#" . $this->get_html_id() . "').podlovewebplayer(" . json_encode($init_options) . ");" . "\n</script>\n"; return $xml_string; }
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title><?php the_title(); ?> </title> <meta name='robots' content='noindex,follow' /> <link href="<?php echo $css_path; ?> /<?php echo \Podlove\get_webplayer_setting("playerv3theme"); ?> " rel="stylesheet" media="screen" type="text/css" /> <link href="<?php echo $css_path; ?> /vendor/progress-polyfill.css" rel="stylesheet" media="screen" type="text/css" /> </head> <body> <?php echo (new \Podlove\Modules\PodloveWebPlayer\PlayerV3\Html5Printer($episode))->render(); ?> <script src="<?php echo $js_path; ?> /vendor/html5shiv.min.js"></script>
public function form_fields() { $formats_data = get_option('podlove_webplayer_formats', array()); $episode_assets = Model\EpisodeAsset::all(); foreach (self::formats() as $format => $extensions) { ?> <tr valign="top"> <th scope="row" valign="top" colspan="2"> <h3><?php echo ucfirst($format); ?> </h3> </th> </tr> <?php foreach ($extensions as $extension => $extension_data) { $label = $extension_data['title']; $mime_types = $extension_data['mime_types']; $id = sprintf('podlove_webplayer_formats_%s_%s', $format, $extension); $name = sprintf('podlove_webplayer_formats[%s][%s]', $format, $extension); $value = isset($formats_data[$format]) && isset($formats_data[$format][$extension]) ? $formats_data[$format][$extension] : 0; ?> <tr valign="top"> <th scope="row" valign="top"> <label for="<?php echo $id; ?> "><?php echo $label; ?> </label> </th> <td> <div> <select name="<?php echo $name; ?> " id="<?php echo $id; ?> "> <option value="0" <?php selected(0, $value); ?> ><?php echo __('Unused', 'podlove'); ?> </option> <?php foreach ($episode_assets as $episode_asset) { ?> <?php $file_type = $episode_asset->file_type(); ?> <?php if ($file_type && in_array($file_type->mime_type, $mime_types)) { ?> <option value="<?php echo $episode_asset->id; ?> " <?php selected($episode_asset->id, $value); ?> ><?php echo $episode_asset->title; ?> </option> <?php } ?> <?php } ?> </select> </div> </td> </tr> <?php } } // advanced settings $settings = array('inject' => array('label' => __('Insert player automatically', 'podlove'), 'description' => __('Automatically insert web player shortcode at beginning or end of an episode. Alternatvely, use the shortcode <code>[podlove-episode-web-player]</code>.', 'podlove'), 'options' => array('manually' => __('insert manually via shortcode', 'podlove'), 'beginning' => __('insert at the beginning', 'podlove'), 'end' => __('insert at the end', 'podlove'))), 'chaptersVisible' => array('label' => __('Chapters Visibility', 'podlove'), 'options' => array('true' => __('Visible when player loads', 'podlove'), 'false' => __('Hidden when player loads', 'podlove'))), 'version' => array('label' => __('Player Version', 'podlove'), 'options' => array('player_v2' => __('Podlove Web Player 2', 'podlove'), 'player_v3' => __('Podlove Web Player 3 (unstable beta, don\'t use in production)', 'podlove')))); ?> <tr valign="top"> <th scope="row" valign="top" colspan="2"> <h3><?php echo __('Settings', 'podlove'); ?> </h3> </th> </tr> <?php foreach ($settings as $setting_key => $field_values) { ?> <tr class="row_<?php echo $setting_key; ?> "> <th scope="row" valign="top"> <?php if (isset($field_values['label']) && $field_values['label']) { ?> <label for="<?php echo $setting_key; ?> "><?php echo $field_values['label']; ?> </label> <?php } ?> </th> <td> <select name="podlove_webplayer_settings[<?php echo $setting_key; ?> ]" id="<?php echo $setting_key; ?> "> <?php foreach ($field_values['options'] as $key => $value) { ?> <option value="<?php echo esc_attr($key); ?> " <?php if ($key == \Podlove\get_webplayer_setting($setting_key)) { ?> selected="selected"<?php } ?> ><?php echo $value; ?> </option> <?php } ?> </select> <?php if (isset($field_values['description']) && $field_values['description']) { ?> <div class="description"><?php echo $field_values['description']; ?> </div> <?php } ?> </td> </tr> <?php } ?> <?php }
public function autoinsert_into_content($content) { if (get_post_type() !== 'podcast' || post_password_required()) { return $content; } if (self::there_is_a_player_in_the_content($content)) { return $content; } $inject = \Podlove\get_webplayer_setting('inject'); if ($inject == 'beginning') { $content = '[podlove-episode-web-player]' . $content; } elseif ($inject == 'end') { $content = $content . '[podlove-episode-web-player]'; } return $content; }