예제 #1
0
 public static function get_duration($post_id, $video_src)
 {
     $sDuration = false;
     if ($sVideoMeta = get_post_meta($post_id, flowplayer::get_video_key($video_src), true)) {
         //  todo: should probably work regardles of quality version
         if (isset($sVideoMeta['duration']) && $sVideoMeta['duration'] > 0) {
             $tDuration = $sVideoMeta['duration'];
             if ($tDuration < 3600) {
                 $sDuration = gmdate("i:s", $tDuration);
             } else {
                 $sDuration = gmdate("H:i:s", $tDuration);
             }
         }
     }
     return $sDuration;
 }
예제 #2
0
파일: checker.php 프로젝트: ryan2407/Vision
 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)
     }
 }