function fv_flowplayer_the_content($c) { if (flowplayer::is_special_editor()) { return $c; } $c = preg_replace('!<p[^>]*?>(\\[(?:fvplayer|flowplayer).*?[^\\\\]\\])</p>!', "\n" . '$1' . "\n", $c); $c = preg_replace_callback('!\\[(?:fvplayer|flowplayer).*?[^\\\\]\\]!', 'fv_flowplayer_shortfcode_fix_attrs', $c); return $c; }
/** * Builds the HTML and JS code of single flowplayer instance on a page/post. * @param string $media URL or filename (in case it is in the /videos/ directory) of video file to be played. * @param array $args Array of arguments (name => value). * @return Returns array with 2 elements - 'html' => html code displayed anywhere on page/post, 'script' => javascript code displayed before </body> tag */ function build_min_player($media, $args = array()) { global $post; $this->hash = md5($media . $this->_salt()); // unique player id $this->aCurArgs = apply_filters('fv_flowplayer_args_pre', $args); $this->sHTMLAfter = false; $player_type = 'video'; $rtmp = false; $youtube = false; $vimeo = false; $scripts_after = ''; // returned array with new player's html and javascript content if (!isset($GLOBALS['fv_fp_scripts'])) { $GLOBALS['fv_fp_scripts'] = array(); } $this->ret = array('html' => '', 'script' => $GLOBALS['fv_fp_scripts']); // note: we need the white space here, it fails to add into the string on some hosts without it (???) /* * Set common variables */ $width = isset($this->conf['width']) && !empty($this->conf['width']) && intval($this->conf['width']) > 0 ? $this->conf['width'] : 320; $height = isset($this->conf['height']) && !empty($this->conf['height']) && intval($this->conf['height']) > 0 ? $this->conf['height'] : 240; if (isset($this->aCurArgs['width']) && !empty($this->aCurArgs['width'])) { $width = trim($this->aCurArgs['width']); } if (isset($this->aCurArgs['height']) && !empty($this->aCurArgs['height'])) { $height = trim($this->aCurArgs['height']); } $src1 = isset($this->aCurArgs['src1']) && !empty($this->aCurArgs['src1']) ? trim($this->aCurArgs['src1']) : false; $src2 = isset($this->aCurArgs['src2']) && !empty($this->aCurArgs['src2']) ? trim($this->aCurArgs['src2']) : false; $splash_img = $this->get_splash(); foreach (array($media, $src1, $src2) as $media_item) { if (stripos($media_item, 'rtmp://') === 0) { $rtmp = $media_item; } } if ((!empty($this->aCurArgs['rtmp']) || !empty($this->conf['rtmp']) && $this->conf['rtmp'] != 'false') && !empty($this->aCurArgs['rtmp_path'])) { $rtmp = trim($this->aCurArgs['rtmp_path']); } list($media, $src1, $src2) = apply_filters('fv_flowplayer_media_pre', array($media, $src1, $src2), $this); /* * Which player should be used */ foreach (array($media, $src1, $src2) as $media_item) { if (preg_match('~\\.(mp3|wav|ogg)([?#].*?)?$~', $media_item)) { $player_type = 'audio'; break; } global $post; if ($post) { $fv_flowplayer_meta = get_post_meta($post->ID, '_fv_flowplayer', true); if ($fv_flowplayer_meta && isset($fv_flowplayer_meta[sanitize_title($media_item)]['time'])) { $this->expire_time = $fv_flowplayer_meta[sanitize_title($media_item)]['time']; } } } if (preg_match("~(youtu\\.be/|youtube\\.com/(watch\\?(.*&)?v=|(embed|v)/))([^\\?&\"'>]+)~i", $media, $aYoutube)) { if (isset($aYoutube[5])) { $youtube = $aYoutube[5]; $player_type = 'youtube'; } } else { if (preg_match("~^[a-zA-Z0-9-_]{11}\$~", $media, $aYoutube)) { if (isset($aYoutube[0])) { $youtube = $aYoutube[0]; $player_type = 'youtube'; } } } if (preg_match("~vimeo.com/(?:video/|moogaloop\\.swf\\?clip_id=)?(\\d+)~i", $media, $aVimeo)) { if (isset($aVimeo[1])) { $vimeo = $aVimeo[1]; $player_type = 'vimeo'; } } else { if (preg_match("~^[0-9]{8}\$~", $media, $aVimeo)) { if (isset($aVimeo[0])) { $vimeo = $aVimeo[0]; $player_type = 'vimeo'; } } } $aPlaylistItems = array(); $aSplashScreens = array(); $aCaptions = array(); if (isset($this->aCurArgs['playlist']) && strlen(trim($this->aCurArgs['playlist'])) > 0) { list($playlist_items_external_html, $aPlaylistItems, $aSplashScreens, $aCaptions) = $this->build_playlist($this->aCurArgs, $media, $src1, $src2, $rtmp, $splash_img); } $this->aCurArgs = apply_filters('fv_flowplayer_args', $this->aCurArgs, $this->hash, $media, $aPlaylistItems); $player_type = apply_filters('fv_flowplayer_player_type', $player_type, $this->hash, $media, $aPlaylistItems, $this->aCurArgs); /* * Video player tabs */ if ($player_type == 'video' && $args['liststyle'] == 'tabs' && count($aPlaylistItems)) { return $this->get_tabs($aPlaylistItems, $aSplashScreens, $aCaptions); } $autoplay = false; // todo: should be changed into a property if ($this->autoplay_count < 1) { if (isset($this->conf['autoplay']) && $this->conf['autoplay'] == 'true' && $this->aCurArgs['autoplay'] != 'false') { $this->autoplay_count++; $autoplay = true; } if (isset($this->aCurArgs['autoplay']) && $this->aCurArgs['autoplay'] == 'true') { $this->autoplay_count++; $autoplay = true; } } /* * Video player */ if ($player_type == 'video') { if (is_feed()) { $this->ret['html'] = '<p class="fv-flowplayer-feed"><a href="' . get_permalink() . '" title="' . __('Click to watch the video') . '">' . apply_filters('fv_flowplayer_rss_intro_splash', __('[This post contains video, click to play]')); if ($splash_img) { $this->ret['html'] .= '<br /><img src="' . $splash_img . '" width="400" />'; } $this->ret['html'] .= '</a></p>'; $this->ret['html'] = apply_filters('fv_flowplayer_rss', $this->ret['html'], $this); return $this->ret; } foreach (array($media, $src1, $src2) as $media_item) { //if( ( strpos($media_item, 'amazonaws.com') !== false && stripos( $media_item, 'http://s3.amazonaws.com/' ) !== 0 && stripos( $media_item, 'https://s3.amazonaws.com/' ) !== 0 ) || stripos( $media_item, 'rtmp://' ) === 0 ) { // we are also checking amazonaws.com due to compatibility with older shortcodes if ($this->conf['engine'] == 'false' && stripos($media_item, '.m4v') !== false) { $this->ret['script']['fv_flowplayer_browser_ff_m4v'][$this->hash] = true; } if ($this->conf['engine'] == 'false' && preg_match('~\\.(mp4|m4v|mov)~', $media_item) > 0) { $this->ret['script']['fv_flowplayer_browser_chrome_mp4'][$this->hash] = true; } } if (!empty($media)) { $media = $this->get_video_url($media); } if (!empty($src1)) { $src1 = $this->get_video_url($src1); } if (!empty($src2)) { $src2 = $this->get_video_url($src2); } $mobile = isset($this->aCurArgs['mobile']) && !empty($this->aCurArgs['mobile']) ? trim($this->aCurArgs['mobile']) : false; if (!empty($mobile)) { $mobile = $this->get_video_url($mobile); } $popup = ''; //check user agents $aUserAgents = array('iphone', 'ipod', 'iPad', 'aspen', 'incognito', 'webmate', 'android', 'android', 'dream', 'cupcake', 'froyo', 'blackberry9500', 'blackberry9520', 'blackberry9530', 'blackberry9550', 'blackberry9800', 'Palm', 'webos', 's8000', 'bada', 'Opera Mini', 'Opera Mobi', 'htc_touch_pro'); $mobileUserAgent = false; foreach ($aUserAgents as $userAgent) { if (stripos($_SERVER['HTTP_USER_AGENT'], $userAgent)) { $mobileUserAgent = true; } } $scaling = "scale"; if (isset($this->conf['scaling']) && $this->conf['scaling'] == "true") { $scaling = "fit"; } else { $scaling = "scale"; } $subtitles = $this->get_subtitles(); $show_splashend = false; if (isset($this->aCurArgs['splashend']) && $this->aCurArgs['splashend'] == 'show' && isset($this->aCurArgs['splash']) && !empty($this->aCurArgs['splash'])) { $show_splashend = true; $splashend_contents = '<div id="wpfp_' . $this->hash . '_custom_background" class="wpfp_custom_background" style="position: absolute; background: url(\'' . $splash_img . '\') no-repeat center center; background-size: contain; width: 100%; height: 100%; z-index: 1;"></div>'; } $attributes = array(); $attributes['class'] = 'flowplayer no-brand'; if ($autoplay == false && !(isset($this->conf['auto_buffering']) && $this->conf['auto_buffering'] == 'trueDISABLED' && $this->autobuffer_count < apply_filters('fv_flowplayer_autobuffer_limit', 2))) { $attributes['class'] .= ' is-splash'; } if (isset($this->aCurArgs['playlist_hide']) && strcmp($this->aCurArgs['playlist_hide'], 'true') == 0) { $attributes['class'] .= ' playlist-hidden'; } // Fixed control bar $bFixedControlbar = false; if (isset($this->conf['ui_fixed_controlbar']) && strcmp($this->conf['ui_fixed_controlbar'], 'true') == 0) { $bFixedControlbar = true; } if (isset($this->aCurArgs['controlbar'])) { if (strcmp($this->aCurArgs['controlbar'], 'yes') == 0 || strcmp($this->aCurArgs['controlbar'], 'show') == 0) { $bFixedControlbar = true; } else { if (strcmp($this->aCurArgs['controlbar'], 'no') == 0) { $attributes['class'] .= ' no-controlbar'; } } } if ($bFixedControlbar) { $attributes['class'] .= ' fixed-controls'; } // Play button $bPlayButton = false; if (isset($this->conf['ui_play_button']) && strcmp($this->conf['ui_play_button'], 'true') == 0) { $bPlayButton = true; } if (isset($this->aCurArgs['play_button'])) { if (strcmp($this->aCurArgs['play_button'], 'yes') == 0) { $bPlayButton = true; } else { if (strcmp($this->aCurArgs['play_button'], 'no') == 0) { $bPlayButton = false; } } } if ($bPlayButton) { $attributes['class'] .= ' play-button'; } // Align if (isset($this->aCurArgs['align'])) { if ($this->aCurArgs['align'] == 'left') { $attributes['class'] .= ' alignleft'; } else { if ($this->aCurArgs['align'] == 'right') { $attributes['class'] .= ' alignright'; } else { if ($this->aCurArgs['align'] == 'center') { $attributes['class'] .= ' aligncenter'; } } } } $attributes['class'] .= $this->get_align(); if ($this->conf['engine'] == 'true' || $this->aCurArgs['engine'] == 'flash') { $attributes['data-engine'] = 'flash'; } if (!empty($this->conf['integrations']['embed_iframe']) && $this->conf['integrations']['embed_iframe'] == 'true') { if ($this->aCurArgs['embed'] == 'false' || $this->conf['disableembedding'] == 'true' && $this->aCurArgs['embed'] != 'true') { } else { $attributes['data-fv-embed'] = $this->get_embed_url(); } } else { if ($this->aCurArgs['embed'] == 'false' || $this->conf['disableembedding'] == 'true' && $this->aCurArgs['embed'] != 'true') { $attributes['data-embed'] = 'false'; } } if (isset($this->aCurArgs['logo']) && $this->aCurArgs['logo']) { $attributes['data-logo'] = strcmp($this->aCurArgs['logo'], 'none') == 0 ? '' : $this->aCurArgs['logo']; } if ($this->conf['fixed_size'] == 'true') { $attributes['style'] = 'width: ' . $width . 'px; height: ' . $height . 'px; '; } else { $attributes['style'] = 'max-width: ' . $width . 'px; max-height: ' . $height . 'px; '; } global $fv_wp_flowplayer_ver; //$attributes['data-swf'] = FV_FP_RELATIVE_PATH.'/flowplayer/flowplayer.swf?ver='.$fv_wp_flowplayer_ver; // it's better to have this in flowplayer.conf //$attributes['data-flashfit'] = "true"; if (isset($this->conf['googleanalytics']) && $this->conf['googleanalytics'] != 'false' && strlen($this->conf['googleanalytics']) > 0) { $attributes['data-analytics'] = $this->conf['googleanalytics']; } // determine the RTMP server if (isset($this->aCurArgs['rtmp']) && !empty($this->aCurArgs['rtmp'])) { $attributes['data-rtmp'] = trim($this->aCurArgs['rtmp']); } else { if (isset($rtmp) && stripos($rtmp, 'rtmp://') === 0 && !(isset($this->conf['rtmp']) && $this->conf['rtmp'] != 'false' && stripos($rtmp, $this->conf['rtmp']) !== false)) { if (preg_match('~/([a-zA-Z0-9]+)?:~', $rtmp)) { $aTMP = preg_split('~/([a-zA-Z0-9]+)?:~', $rtmp, -1, PREG_SPLIT_DELIM_CAPTURE); $attributes['data-rtmp'] = $aTMP[0]; } else { $rtmp_info = parse_url($rtmp); if (isset($rtmp_info['host']) && strlen(trim($rtmp_info['host'])) > 0) { $attributes['data-rtmp'] = 'rtmp://' . $rtmp_info['host'] . '/cfx/st'; } } } else { if (!empty($this->conf['rtmp']) && $this->conf['rtmp'] != 'false') { if (stripos($this->conf['rtmp'], 'rtmp://') === 0) { $attributes['data-rtmp'] = $this->conf['rtmp']; $rtmp = str_replace($this->conf['rtmp'], '', $rtmp); } else { $attributes['data-rtmp'] = 'rtmp://' . $this->conf['rtmp'] . '/cfx/st/'; } } } } $this->get_video_checker_media($attributes, $media, $src1, $src2, $rtmp); if (isset($this->conf['allowfullscreen']) && $this->conf['allowfullscreen'] == 'false') { $attributes['data-fullscreen'] = 'false'; } $ratio = round($height / $width, 4); $this->fRatio = $ratio; $attributes['data-ratio'] = str_replace(',', '.', $ratio); if ($scaling == "fit" && $this->conf['fixed_size'] == 'fixed') { $attributes['data-flashfit'] = 'true'; } if (isset($this->aCurArgs['live']) && $this->aCurArgs['live'] == 'true') { $attributes['data-live'] = 'true'; } $playlist = ''; $is_preroll = false; if (isset($playlist_items_external_html)) { if (!isset($this->aCurArgs['playlist_hide']) || strcmp($this->aCurArgs['playlist_hide'], 'true') != 0) { $this->sHTMLAfter .= $playlist_items_external_html; } $this->aPlaylists["wpfp_{$this->hash}"] = $aPlaylistItems; $attributes['style'] .= "background-image: url({$splash_img});"; if ($autoplay) { $this->ret['script']['fv_flowplayer_autoplay'][$this->hash] = true; // todo: any better way? $attributes['class'] .= ' is-splash'; } } else { if (!empty($this->aCurArgs['caption'])) { $attributes['class'] .= ' has-caption'; $this->sHTMLAfter = apply_filters('fv_player_caption', "<p class='fp-caption'>" . $this->aCurArgs['caption'] . "</p>", $this); } } if (!empty($this->aCurArgs['redirect'])) { $attributes['data-fv_redirect'] = trim($this->aCurArgs['redirect']); } if (isset($this->aCurArgs['loop']) && $this->aCurArgs['loop'] == 'true') { $attributes['data-fv_loop'] = true; } if (isset($this->aCurArgs['admin_warning'])) { $this->sHTMLAfter .= wpautop($this->aCurArgs['admin_warning']); } $attributes_html = ''; $attributes = apply_filters('fv_flowplayer_attributes', $attributes, $media, $this); foreach ($attributes as $attr_key => $attr_value) { $attributes_html .= ' ' . $attr_key . '="' . esc_attr($attr_value) . '"'; } $this->ret['html'] .= '<div id="wpfp_' . $this->hash . '"' . $attributes_html . '>' . "\n"; if (count($aPlaylistItems) == 0) { // todo: this stops subtitles, mobile video, preload etc. $this->ret['html'] .= "\t" . '<video'; if (isset($splash_img) && !empty($splash_img)) { $this->ret['html'] .= ' poster="' . flowplayer::get_encoded_url($splash_img) . '"'; } if ($autoplay == true) { $this->ret['html'] .= ' autoplay'; } if (isset($this->conf['auto_buffering']) && $this->conf['auto_buffering'] == 'trueDISABLED' && $this->autobuffer_count < apply_filters('fv_flowplayer_autobuffer_limit', 2)) { $this->ret['html'] .= ' preload'; //$this->ret['html'] .= ' id="wpfp_'.$this->hash.'_video"'; } else { if ($autoplay == false) { $this->ret['html'] .= ' preload="none"'; } } $scripts_after .= $this->get_chrome_fail_code($media, $src1, $src2, $attributes_html); $this->ret['html'] .= ">\n"; foreach (apply_filters('fv_player_media', array($media, $src1, $src2), $this) as $media_item) { $this->ret['html'] .= $this->get_video_src($media_item, array('mobileUserAgent' => $mobileUserAgent, 'rtmp' => $rtmp)); } if (!empty($mobile)) { $this->ret['script']['fv_flowplayer_mobile_switch'][$this->hash] = true; $this->ret['html'] .= $this->get_video_src($mobile, array('id' => 'wpfp_' . $this->hash . '_mobile', 'mobileUserAgent' => $mobileUserAgent, 'rtmp' => $rtmp)); } if (isset($rtmp) && !empty($rtmp)) { foreach (apply_filters('fv_player_media_rtmp', array($rtmp), $this) as $rtmp_item) { $rtmp_item = apply_filters('fv_flowplayer_video_src', $rtmp_item, $this); if (preg_match('~([a-zA-Z0-9]+)?:~', $rtmp)) { $aTMP = preg_split('~([a-zA-Z0-9]+)?:~', $rtmp, -1, PREG_SPLIT_DELIM_CAPTURE); if (isset($aTMP[1]) && isset($aTMP[2])) { $rtmp_file = $aTMP[2]; $extension = $this->get_mime_type($rtmp_file, $aTMP[1], true); } else { $rtmp_file = $aTMP[1]; $extension = $this->get_mime_type($rtmp_file, false, true); } } else { $rtmp_url = parse_url($rtmp_item); $rtmp_file = $rtmp_url['path'] . (!empty($rtmp_url['query']) ? '?' . str_replace('&', '&', $rtmp_url['query']) : ''); $extension = $this->get_mime_type($rtmp_url['path'], false, true); } if ($extension) { $extension .= ':'; } else { //$extension = 'mp4:'; // https://github.com/flowplayer/flowplayer/search?q=rtmp&type=Issues&utf8=%E2%9C%93 } $this->ret['html'] .= "\t" . "\t" . '<source src="' . $extension . trim($rtmp_file, " \t\n\r\v/") . '" type="video/flash" />' . "\n"; } } if (isset($subtitles) && !empty($subtitles)) { $sExtra = isset($this->conf['subtitleOn']) && strcmp($this->conf['subtitleOn'], 'true') == 0 ? 'default ' : ''; $aLang = explode('-', get_bloginfo('language')); $sExtra .= !empty($aLang[0]) ? 'srclang="' . $aLang[0] . '" ' : ''; $sCaption = false; if (!empty($aLang[0]) && $aLang[0] == 'en') { $sCaption = 'English'; } elseif (!empty($aLang[0])) { $translations = get_site_transient('available_translations'); $sLangCode = str_replace('-', '_', get_bloginfo('language')); if ($translations && isset($translations[$sLangCode]) && !empty($translations[$sLangCode]['native_name'])) { $sCaption = $translations[$sLangCode]['native_name']; } } $sExtra .= $sCaption ? 'label="' . $sCaption . '" ' : ''; $this->ret['html'] .= "\t" . "\t" . '<track ' . $sExtra . 'src="' . esc_attr($subtitles) . '" />' . "\n"; } $this->ret['html'] .= "\t" . '</video>'; //."\n"; } $this->ret['html'] .= $this->get_buttons(); if (isset($splashend_contents)) { $this->ret['html'] .= $splashend_contents; } if ($popup_contents = $this->get_popup_code()) { $this->aPopups["wpfp_{$this->hash}"] = $popup_contents; } if ($ad_contents = $this->get_ad_code()) { $this->aAds["wpfp_{$this->hash}"] = $ad_contents; } if (flowplayer::is_special_editor()) { $this->ret['html'] .= '<div class="fp-ui"></div>'; } else { if (current_user_can('manage_options') && !isset($playlist_items_external_html)) { $this->ret['html'] .= '<div id="wpfp_' . $this->hash . '_admin_error" class="fvfp_admin_error"><div class="fvfp_admin_error_content"><h4>Admin JavaScript warning:</h4><p>I\'m sorry, your JavaScript appears to be broken. Please use "Check template" in plugin settings, read our <a href="https://foliovision.com/player/installation#fixing-broken-javascript">troubleshooting guide</a> or <a href="http://foliovision.com/wordpress/pro-install">order our pro support</a> and we will get it fixed for you.</p></div></div>'; } } $this->ret['html'] .= apply_filters('fv_flowplayer_inner_html', null, $this); $this->ret['html'] .= $this->get_sharing_html() . "\n"; if (current_user_can('manage_options') && $this->conf['disable_videochecker'] != 'true') { $this->ret['html'] .= $this->get_video_checker_html() . "\n"; } $this->ret['html'] .= '</div>' . "\n"; $this->ret['html'] .= $this->sHTMLAfter . $scripts_after . "<!--fv player end-->"; // change engine for IE9 and 10 if ($this->aCurArgs['engine'] == 'false') { $this->ret['script']['fv_flowplayer_browser_ie'][$this->hash] = true; } } else { if ($player_type == 'youtube') { $sAutoplay = $autoplay ? 'autoplay=1&' : ''; $this->ret['html'] .= "<iframe id='fv_ytplayer_{$this->hash}' type='text/html' width='{$width}' height='{$height}'\n\t src='http://www.youtube.com/embed/{$youtube}?{$sAutoplay}origin=" . urlencode(get_permalink()) . "' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>\n"; } else { if ($player_type == 'vimeo') { $sAutoplay = $autoplay ? " autoplay='1'" : ""; $this->ret['html'] .= "<iframe id='fv_vimeo_{$this->hash}' src='//player.vimeo.com/video/{$vimeo}' width='{$width}' height='{$height}' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen{$sAutoplay}></iframe>\n"; } else { // $player_type == 'video' ends $this->build_audio_player($media, $width, $autoplay); } } } $this->ret['html'] = apply_filters('fv_flowplayer_html', $this->ret['html'], $this); $this->ret['script'] = apply_filters('fv_flowplayer_scripts_array', $this->ret['script'], 'wpfp_' . $this->hash, $media); return $this->ret; }