/**
  * 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('&amp;', '&', $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&amp;' : '';
             $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;
 }
Esempio n. 2
0
 public function check_mimetype($URLs = false, $meta = false)
 {
     add_action('http_api_curl', array('FV_Player_Checker', 'http_api_curl'));
     $tStart = microtime(true);
     global $fv_wp_flowplayer_ver, $fv_fp;
     if (!empty($meta)) {
         extract($meta, EXTR_SKIP);
     }
     if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['media']) && stripos($_SERVER['HTTP_REFERER'], home_url()) === 0) {
         $URLs = json_decode(stripslashes(trim($_POST['media'])));
     }
     if (isset($URLs)) {
         $all_sources = $URLs;
         foreach ($all_sources as $source) {
             if (preg_match('!^rtmp://!', $source, $match)) {
                 $found_rtmp = true;
             } else {
                 if (!isset($media) && !preg_match('!\\.(m3u8ALLOW|m3uALLOW|avi)$!', $source)) {
                     $media = $source;
                 }
             }
         }
         //$random = rand( 0, 10000 );
         $random = isset($_POST['hash']) ? trim($_POST['hash']) : false;
         if (isset($media)) {
             $remotefilename = $media;
             $remotefilename_encoded = flowplayer::get_encoded_url($remotefilename);
             if ($fv_fp->is_secure_amazon_s3($remotefilename_encoded) || 1 > 0) {
                 //	skip headers check for Amazon S3, as it's slow
                 $headers = false;
             } else {
                 $headers = wp_remote_head(trim(str_replace(' ', '%20', $remotefilename_encoded)), array('method' => 'GET', 'redirection' => 3));
             }
             $bValidFile = true;
             if (is_wp_error($headers)) {
                 $video_errors[] = 'Error checking ' . $media . '!<br />' . print_r($headers, true);
             } else {
                 if ($headers) {
                     list($aVideoErrors, $sContentType, $bFatal) = $this->check_headers($headers, $remotefilename, $random);
                     if ($bFatal) {
                         $bValidFile = false;
                     }
                     if ($aVideoErrors) {
                         $video_errors = array_merge($video_errors, $aVideoErrors);
                     }
                 }
                 if (function_exists('is_utf8') && is_utf8($remotefilename)) {
                     $video_errors[] = '<p><strong>UTF-8 error</strong>: Your file name is using non-latin characters, the file might not play in browsers using Flash for the video!</p>';
                 }
                 if (@ini_get('safe_mode')) {
                     $video_warnings[] = 'Detailed video check is not available with PHP Safe Mode On. Please contact your webhost support.';
                 } else {
                     if (!class_exists('getID3')) {
                         require ABSPATH . WPINC . '/ID3/getid3.php';
                     }
                     $getID3 = new getID3();
                     if (!function_exists('curl_init')) {
                         $video_errors[] = 'cURL for PHP not found, please contact your server administrator.';
                     } else {
                         $message = '<p>Analysis of <a class="bluelink" target="_blank" href="' . esc_attr($remotefilename_encoded) . '">' . $remotefilename_encoded . '</a></p>';
                         //	taken from: http://www.getid3.org/phpBB3/viewtopic.php?f=3&t=1141
                         $upload_dir = wp_upload_dir();
                         $localtempfilename = trailingslashit($upload_dir['basedir']) . 'fv_flowlayer_tmp_' . md5(rand(1, 999)) . '_' . basename(substr($remotefilename_encoded, 0, 32));
                         $out = fopen($localtempfilename, 'wb');
                         if ($out) {
                             $aArgs = array('file' => $localtempfilename);
                             if (!$this->is_cron) {
                                 $aArgs['quick_check'] = apply_filters('fv_flowplayer_checker_timeout_quick', 2);
                             }
                             list($header, $sHTTPError) = $this->http_request($remotefilename_encoded, $aArgs);
                             $video_errors = array();
                             if ($sHTTPError) {
                                 $video_errors[] = $sHTTPError;
                                 $bValidFile = false;
                             }
                             fclose($out);
                             if (!$headers) {
                                 $headers = WP_Http::processHeaders($header);
                                 list($aVideoErrors, $sContentType, $bFatal) = $this->check_headers($headers, $remotefilename, $random);
                                 if ($bFatal) {
                                     $bValidFile = false;
                                 }
                                 if ($aVideoErrors) {
                                     $video_errors = array_merge($video_errors, $aVideoErrors);
                                 }
                                 if (isset($hearders['headers']['server']) && $hearders['headers']['server'] == 'AmazonS3' && $headers['response']['code'] == '403') {
                                     $error = new SimpleXMLElement($body);
                                     if (stripos($error->Message, 'Request has expired') !== false) {
                                         $video_errors[] = '<p><strong>Amazon S3</strong>: Your secure link is expired, there might be problem with your Amazon S3 plugin. Please test if the above URL opens in your browser.</p>';
                                     } else {
                                         $video_errors[] = '<p><strong>Amazon S3</strong>: ' . $error->Message . '</p>';
                                     }
                                 }
                             }
                             if ($bValidFile) {
                                 $ThisFileInfo = $getID3->analyze($localtempfilename);
                             }
                             if (!@unlink($localtempfilename)) {
                                 $video_errors[] = 'Can\'t remove temporary file for video analysis in <tt>' . $localtempfilename . '</tt>!';
                             }
                         } else {
                             $video_errors[] = 'Can\'t create temporary file for video analysis in <tt>' . $localtempfilename . '</tt>!';
                         }
                     }
                     /*
                     Only check file length
                     */
                     if (isset($meta_action) && $meta_action == 'check_time') {
                         $time = false;
                         if (isset($ThisFileInfo) && isset($ThisFileInfo['playtime_seconds'])) {
                             $time = $ThisFileInfo['playtime_seconds'];
                         }
                         $time = apply_filters('fv_flowplayer_checker_time', $time, $meta_original);
                         global $post;
                         $fv_flowplayer_meta = get_post_meta($post->ID, flowplayer::get_video_key($meta_original), true);
                         $fv_flowplayer_meta = $fv_flowplayer_meta ? $fv_flowplayer_meta : array();
                         $fv_flowplayer_meta['duration'] = $time;
                         $fv_flowplayer_meta['etag'] = isset($headers['headers']['etag']) ? $headers['headers']['etag'] : false;
                         //  todo: check!
                         $fv_flowplayer_meta['date'] = time();
                         $fv_flowplayer_meta['check_time'] = microtime(true) - $tStart;
                         if ($time > 0 || $this->is_cron) {
                             update_post_meta($post->ID, flowplayer::get_video_key($meta_original), $fv_flowplayer_meta);
                             return true;
                         }
                         //} else {
                         //self::queue_add($post->ID);
                         //return false;
                         //}
                     }
                 }
             }
             //	end is_wp_error check
         }
         //	end isset($media)
     }
 }