/**
  * Uses wp_read_video_metadata() and wp_read_audio_metadata() to retrieve
  * an embedded image to use as a thumbnail.
  *
  * @param string $ID The attachment ID to retrieve thumbnail from.
  * @param int $pg Unused.
  *
  * @return bool|string  False on failure, URL to thumb on success.
  */
 public function getThumbnail($ID, $pg = 1)
 {
     include_once DG_WPADMIN_PATH . 'includes/media.php';
     $doc_path = get_attached_file($ID);
     $mime_type = get_post_mime_type($ID);
     if (DG_Util::startsWith($mime_type, 'video/')) {
         $metadata = wp_read_video_metadata($doc_path);
     } elseif (DG_Util::startsWith($mime_type, 'audio/')) {
         $metadata = wp_read_audio_metadata($doc_path);
     }
     // unsupported mime type || no embedded image present
     if (!isset($metadata) || empty($metadata['image']['data'])) {
         return false;
     }
     $ext = 'jpg';
     switch ($metadata['image']['mime']) {
         case 'image/gif':
             $ext = 'gif';
             break;
         case 'image/png':
             $ext = 'png';
             break;
     }
     $temp_file = DG_Util::getTempFile($ext);
     if (!($fp = @fopen($temp_file, 'wb'))) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Could not open file: ', 'document-gallery') . $temp_file);
         return false;
     }
     if (!@fwrite($fp, $metadata['image']['data'])) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Could not write file: ', 'document-gallery') . $temp_file);
         fclose($fp);
         return false;
     }
     fclose($fp);
     return $temp_file;
 }
/**
 * Generate post thumbnail attachment meta data.
 *
 * @since 2.1.0
 *
 * @param int $attachment_id Attachment Id to process.
 * @param string $file Filepath of the Attached image.
 * @return mixed Metadata for attachment.
 */
function wp_generate_attachment_metadata($attachment_id, $file)
{
    $attachment = get_post($attachment_id);
    $metadata = array();
    $support = false;
    if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) {
        $imagesize = getimagesize($file);
        $metadata['width'] = $imagesize[0];
        $metadata['height'] = $imagesize[1];
        // Make the file path relative to the upload dir
        $metadata['file'] = _wp_relative_upload_path($file);
        // make thumbnails and other intermediate sizes
        global $_wp_additional_image_sizes;
        $sizes = array();
        foreach (get_intermediate_image_sizes() as $s) {
            $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false);
            if (isset($_wp_additional_image_sizes[$s]['width'])) {
                $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']);
            } else {
                $sizes[$s]['width'] = get_option("{$s}_size_w");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['height'])) {
                $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']);
            } else {
                $sizes[$s]['height'] = get_option("{$s}_size_h");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['crop'])) {
                $sizes[$s]['crop'] = intval($_wp_additional_image_sizes[$s]['crop']);
            } else {
                $sizes[$s]['crop'] = get_option("{$s}_crop");
            }
            // For default sizes set in options
        }
        $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes);
        if ($sizes) {
            $editor = wp_get_image_editor($file);
            if (!is_wp_error($editor)) {
                $metadata['sizes'] = $editor->multi_resize($sizes);
            }
        } else {
            $metadata['sizes'] = array();
        }
        // fetch additional metadata from exif/iptc
        $image_meta = wp_read_image_metadata($file);
        if ($image_meta) {
            $metadata['image_meta'] = $image_meta;
        }
    } elseif (preg_match('#^video/#', get_post_mime_type($attachment))) {
        $metadata = wp_read_video_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:video') && post_type_supports('attachment:video', 'thumbnail');
    } elseif (preg_match('#^audio/#', get_post_mime_type($attachment))) {
        $metadata = wp_read_audio_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:audio') && post_type_supports('attachment:audio', 'thumbnail');
    }
    if ($support && !empty($metadata['image']['data'])) {
        $ext = '.jpg';
        switch ($metadata['image']['mime']) {
            case 'image/gif':
                $ext = '.gif';
                break;
            case 'image/png':
                $ext = '.png';
                break;
        }
        $basename = str_replace('.', '-', basename($file)) . '-image' . $ext;
        $uploaded = wp_upload_bits($basename, '', $metadata['image']['data']);
        if (false === $uploaded['error']) {
            $attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => '');
            $sub_attachment_id = wp_insert_attachment($attachment, $uploaded['file']);
            $attach_data = wp_generate_attachment_metadata($sub_attachment_id, $uploaded['file']);
            wp_update_attachment_metadata($sub_attachment_id, $attach_data);
            update_post_meta($attachment_id, '_thumbnail_id', $sub_attachment_id);
        }
    }
    // remove the blob of binary data from the array
    unset($metadata['image']['data']);
    return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id);
}
 /**
  * Generate meta data for the media
  *
  * @since 1.0.0
  *	
  * @access  private
  * @param int $attachment_id Media ID  to process.
  * @param string $file Filepath of the Attached image.
  * 
  * @return mixed Metadata for attachment.
  */
 public function generate_metadata($attachment_id, $file)
 {
     $attachment = get_post($attachment_id);
     $mime_type = get_post_mime_type($attachment);
     $metadata = array();
     if (preg_match('!^image/!', $mime_type) && file_is_displayable_image($file)) {
         $imagesize = getimagesize($file);
         $metadata['width'] = $imagesize[0];
         $metadata['height'] = $imagesize[1];
         // Make the file path relative to the upload dir
         $metadata['file'] = _wp_relative_upload_path($file);
         //get the registered media sizes
         $sizes = mpp_get_media_sizes();
         $sizes = apply_filters('mpp_intermediate_image_sizes', $sizes, $attachment_id);
         if ($sizes) {
             $editor = wp_get_image_editor($file);
             if (!is_wp_error($editor)) {
                 $metadata['sizes'] = $editor->multi_resize($sizes);
             }
         } else {
             $metadata['sizes'] = array();
         }
         // fetch additional metadata from exif/iptc
         $image_meta = wp_read_image_metadata($file);
         if ($image_meta) {
             $metadata['image_meta'] = $image_meta;
         }
     } elseif (preg_match('#^video/#', $mime_type)) {
         $metadata = wp_read_video_metadata($file);
     } elseif (preg_match('#^audio/#', $mime_type)) {
         $metadata = wp_read_audio_metadata($file);
     }
     $dir_path = trailingslashit(dirname($file)) . 'covers';
     $url = wp_get_attachment_url($attachment_id);
     $base_url = str_replace(wp_basename($url), '', $url);
     //processing for audio/video cover
     if (!empty($metadata['image']['data'])) {
         $ext = '.jpg';
         switch ($metadata['image']['mime']) {
             case 'image/gif':
                 $ext = '.gif';
                 break;
             case 'image/png':
                 $ext = '.png';
                 break;
         }
         $basename = str_replace('.', '-', basename($file)) . '-image' . $ext;
         $uploaded = $this->upload_bits($basename, $metadata['image']['data'], array('path' => $dir_path, 'url' => $base_url));
         if (false === $uploaded['error']) {
             $attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => '');
             $sub_attachment_id = wp_insert_attachment($attachment, $uploaded['file']);
             $attach_data = $this->generate_metadata($sub_attachment_id, $uploaded['file']);
             wp_update_attachment_metadata($sub_attachment_id, $attach_data);
             //if the option is set to set post thumbnail
             if (mpp_get_option('set_post_thumbnail')) {
                 mpp_update_media_meta($attachment_id, '_thumbnail_id', $sub_attachment_id);
             }
             //set the cover id
             mpp_update_media_cover_id($attachment_id, $sub_attachment_id);
         }
     }
     // remove the blob of binary data from the array
     if (isset($metadata['image']['data'])) {
         unset($metadata['image']['data']);
     }
     return apply_filters('mpp_generate_metadata', $metadata, $attachment_id);
 }
Exemple #4
0
/**
 * Generate post thumbnail attachment meta data.
 *
 * @since 2.1.0
 *
 * @global array $_wp_additional_image_sizes
 *
 * @param int $attachment_id Attachment Id to process.
 * @param string $file Filepath of the Attached image.
 * @return mixed Metadata for attachment.
 */
function wp_generate_attachment_metadata($attachment_id, $file)
{
    $attachment = get_post($attachment_id);
    $metadata = array();
    $support = false;
    if (preg_match('!^image/!', get_post_mime_type($attachment)) && file_is_displayable_image($file)) {
        $imagesize = getimagesize($file);
        $metadata['width'] = $imagesize[0];
        $metadata['height'] = $imagesize[1];
        // Make the file path relative to the upload dir.
        $metadata['file'] = _wp_relative_upload_path($file);
        // Make thumbnails and other intermediate sizes.
        global $_wp_additional_image_sizes;
        $sizes = array();
        foreach (get_intermediate_image_sizes() as $s) {
            $sizes[$s] = array('width' => '', 'height' => '', 'crop' => false);
            if (isset($_wp_additional_image_sizes[$s]['width'])) {
                $sizes[$s]['width'] = intval($_wp_additional_image_sizes[$s]['width']);
            } else {
                $sizes[$s]['width'] = get_option("{$s}_size_w");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['height'])) {
                $sizes[$s]['height'] = intval($_wp_additional_image_sizes[$s]['height']);
            } else {
                $sizes[$s]['height'] = get_option("{$s}_size_h");
            }
            // For default sizes set in options
            if (isset($_wp_additional_image_sizes[$s]['crop'])) {
                $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop'];
            } else {
                $sizes[$s]['crop'] = get_option("{$s}_crop");
            }
            // For default sizes set in options
        }
        /**
         * Filter the image sizes automatically generated when uploading an image.
         *
         * @since 2.9.0
         * @since 4.4.0 Added the `$metadata` argument.
         *
         * @param array $sizes    An associative array of image sizes.
         * @param array $metadata An associative array of image metadata: width, height, file.
         */
        $sizes = apply_filters('intermediate_image_sizes_advanced', $sizes, $metadata);
        if ($sizes) {
            $editor = wp_get_image_editor($file);
            if (!is_wp_error($editor)) {
                $metadata['sizes'] = $editor->multi_resize($sizes);
            }
        } else {
            $metadata['sizes'] = array();
        }
        // Fetch additional metadata from EXIF/IPTC.
        $image_meta = wp_read_image_metadata($file);
        if ($image_meta) {
            $metadata['image_meta'] = $image_meta;
        }
    } elseif (wp_attachment_is('video', $attachment)) {
        $metadata = wp_read_video_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:video') || post_type_supports('attachment:video', 'thumbnail');
    } elseif (wp_attachment_is('audio', $attachment)) {
        $metadata = wp_read_audio_metadata($file);
        $support = current_theme_supports('post-thumbnails', 'attachment:audio') || post_type_supports('attachment:audio', 'thumbnail');
    }
    if ($support && !empty($metadata['image']['data'])) {
        // Check for existing cover.
        $hash = md5($metadata['image']['data']);
        $posts = get_posts(array('fields' => 'ids', 'post_type' => 'attachment', 'post_mime_type' => $metadata['image']['mime'], 'post_status' => 'inherit', 'posts_per_page' => 1, 'meta_key' => '_cover_hash', 'meta_value' => $hash));
        $exists = reset($posts);
        if (!empty($exists)) {
            update_post_meta($attachment_id, '_thumbnail_id', $exists);
        } else {
            $ext = '.jpg';
            switch ($metadata['image']['mime']) {
                case 'image/gif':
                    $ext = '.gif';
                    break;
                case 'image/png':
                    $ext = '.png';
                    break;
            }
            $basename = str_replace('.', '-', basename($file)) . '-image' . $ext;
            $uploaded = wp_upload_bits($basename, '', $metadata['image']['data']);
            if (false === $uploaded['error']) {
                $image_attachment = array('post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => '');
                /**
                 * Filter the parameters for the attachment thumbnail creation.
                 *
                 * @since 3.9.0
                 *
                 * @param array $image_attachment An array of parameters to create the thumbnail.
                 * @param array $metadata         Current attachment metadata.
                 * @param array $uploaded         An array containing the thumbnail path and url.
                 */
                $image_attachment = apply_filters('attachment_thumbnail_args', $image_attachment, $metadata, $uploaded);
                $sub_attachment_id = wp_insert_attachment($image_attachment, $uploaded['file']);
                add_post_meta($sub_attachment_id, '_cover_hash', $hash);
                $attach_data = wp_generate_attachment_metadata($sub_attachment_id, $uploaded['file']);
                wp_update_attachment_metadata($sub_attachment_id, $attach_data);
                update_post_meta($attachment_id, '_thumbnail_id', $sub_attachment_id);
            }
        }
    }
    // Remove the blob of binary data from the array.
    if ($metadata) {
        unset($metadata['image']['data']);
    }
    /**
     * Filter the generated attachment meta data.
     *
     * @since 2.1.0
     *
     * @param array $metadata      An array of attachment meta data.
     * @param int   $attachment_id Current attachment ID.
     */
    return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id);
}
function remote_upload_json()
{
    if (!current_user_can('activate_plugins')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    if (isset($_POST['file_urls']) && $_POST['file_urls'] != null) {
        $nonce = $_REQUEST['_wpnonce'];
        if (wp_verify_nonce($nonce, 'remote-upload-nonce')) {
            $upload_dir = wp_upload_dir();
            if (!file_exists($upload_dir['path'])) {
                mkdir($upload_dir['path'], 0777, true);
                $file = fopen($upload_dir['path'] . "/remote_upload_progress.json", "w");
                $json_data = array('percentage' => '0');
                fwrite($file, json_encode($json_data));
                fclose($file);
                chmod($file, 0777);
            }
            $file = fopen($upload_dir['path'] . "/remote_upload_progress.json", "w");
            $json_data = array('percentage' => '0', 'total_url_count' => '0', 'url_count' => '0');
            fwrite($file, json_encode($json_data));
            fclose($file);
            $file_urls = $_POST['file_urls'];
            //esc_sql is checking induvidually. It is storing to database (jQuery) GET method.
            $file_json_url = admin_url('options-general.php?page=remote-upload&json_url=true');
            $post_file_url = admin_url('/options-general.php?page=remote-upload&post_file=true');
            wp_enqueue_script('upload_js_library', plugins_url('js/upload.js', __FILE__), array('jquery'), '1.0.0');
            $upload_dir = wp_upload_dir();
            $data = array('file_json_url' => $file_json_url, 'post_file_url' => $post_file_url, 'file_urls' => $file_urls, 'json_data' => $upload_dir['url'] . "/remote_upload_progress.json");
            wp_localize_script('upload_js_library', 'php_vars', $data);
        }
    }
    if (isset($_GET['post_file']) && $_GET['post_file'] == 'true') {
        function is_session_started_for_upload()
        {
            if (php_sapi_name() !== 'cli') {
                if (version_compare(phpversion(), '5.4.0', '>=')) {
                    return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
                } else {
                    return session_id() === '' ? FALSE : TRUE;
                }
            }
            return FALSE;
        }
        if (is_session_started_for_upload() === FALSE) {
            session_start();
        }
        /* Get file total size */
        $file_urls = trim($_POST['file_urls']);
        $file_urls = explode("\r\n", $file_urls);
        $file_urls = array_filter($file_urls, 'trim');
        //$file_urls = array_values(array_filter(explode ("\r\n", $file_urls)));
        $upload_dir = wp_upload_dir();
        $file = fopen($upload_dir['path'] . "/remote_upload_progress.json", "w");
        $json_data = array('percentage' => '0', 'total_url_count' => '0', 'url_count' => '0');
        fputs($file, json_encode($json_data));
        fclose($file);
        for ($i = 0; $i <= count($file_urls); $i++) {
            // processing here.
            $file_url = esc_url(trim($file_urls[$i]));
            $_SESSION['file_url'] = esc_url(trim($file_urls[$i]));
            preg_match("/[^\\/]+\$/", $file_url, $matches);
            $file_name = $matches[0];
            $_SESSION['complete'] = false;
            $_SESSION['percentage'] = 0;
            $_SESSION['total_url_count'] = count($file_urls);
            $_SESSION['url_count'] = $i;
            //Save file
            set_time_limit(0);
            //This is the file where we save the    information
            $upload_dir = wp_upload_dir();
            $fp = fopen($upload_dir['path'] . "/" . utf8_decode(urldecode($file_name)), 'w+');
            //Here is the file we are downloading, replace spaces with %20
            $ch = curl_init(str_replace(" ", "%20", $file_url));
            curl_setopt($ch, CURLOPT_TIMEOUT, 30000);
            curl_setopt($ch, CURLOPT_NOPROGRESS, false);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function ($source, $download_size, $downloaded, $upload_size, $uploaded) {
                if ($download_size > 0) {
                    $upload_dir = wp_upload_dir();
                    $perc = round($downloaded / $download_size * 100);
                    //if($perc != 100 ){
                    $file = fopen($upload_dir['path'] . "/remote_upload_progress.json", "w");
                    $json_data = array('percentage' => $perc, 'total_url_count' => $_SESSION['total_url_count'], 'url_count' => $_SESSION['url_count']);
                    fputs($file, json_encode($json_data));
                    fclose($file);
                    //}
                    if ($perc == 100) {
                        if ($_SESSION['complete'] == false) {
                            $_SESSION['complete'] = true;
                            //here database
                        }
                    }
                }
                //ob_flush();
                //flush();
                //sleep(1); // just to see effect
            });
            curl_setopt($ch, CURLOPT_FILE, $fp);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            // get curl response
            $data = curl_exec($ch);
            curl_close($ch);
            fclose($fp);
            chmod($upload_dir['path'] . "/" . utf8_decode(urldecode($file_name)), 0777);
            $file_name = utf8_decode(urldecode($file_name));
            $json_out = array('post' => 'true');
            //wp_send_json($json_out);
            if ($_SESSION['complete'] == true) {
                // Create post object
                $file_url = $_SESSION['file_url'];
                preg_match("/[^\\/]+\$/", $file_url, $matches);
                $file_name = $matches[0];
                $file_name = utf8_decode(urldecode($file_name));
                $post_title = substr($file_name, 0, strrpos($file_name, "."));
                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mime_type = finfo_file($finfo, $upload_dir['path'] . "/" . $file_name);
                finfo_close($finfo);
                $post_data = array('post_title' => esc_sql($post_title), 'post_name' => esc_sql($post_title), 'post_status' => 'inherit', 'guid' => esc_sql($upload_dir['url'] . "/" . str_replace(" ", "%20", $file_name)), 'post_mime_type' => esc_sql($mime_type), 'post_type' => 'attachment');
                // Insert the post into the database
                $post_id = wp_insert_post($post_data);
                $file_path = ltrim($upload_dir['subdir'] . "/" . $file_name, '/');
                add_post_meta($post_id, '_wp_attached_file', esc_sql($file_path));
                if (strpos($mime_type, 'image') !== FALSE) {
                    //generate post_meta for image
                    $data = wp_generate_attachment_metadata($post_id, $upload_dir['path'] . '/' . $file_name);
                    wp_update_attachment_metadata($post_id, $data);
                }
                if (strpos($mime_type, 'audio') !== FALSE) {
                    //generate post_meta for audio
                    $data = wp_read_audio_metadata($upload_dir['path'] . '/' . $file_name);
                    wp_update_attachment_metadata($post_id, $data);
                }
                if (strpos($mime_type, 'video') !== FALSE) {
                    //generate post_meta for video
                    $data = wp_read_video_metadata($upload_dir['path'] . '/' . $file_name);
                    wp_update_attachment_metadata($post_id, $data);
                }
                // $file = fopen($upload_dir['path']."/remote_upload_progress.json","w");
                // $json_data =  array('percentage' =>  'done' );
                // fputs($file,json_encode($json_data));
                //fclose($file);
            }
        }
        $file = fopen($upload_dir['path'] . "/remote_upload_progress.json", "w");
        $json_data = array('percentage' => 'done..!');
        fputs($file, json_encode($json_data));
        fclose($file);
    }
    if (isset($_GET['json_url']) && $_GET['json_url'] == true) {
        if (isset($_SESSION['percentage'])) {
            if ($_SESSION['percentage'] == 100) {
                //$_SESSION['percentage'] = 'done';
            }
            $json_out = array('percentage' => $_SESSION['percentage']);
            wp_send_json($json_out);
        }
    }
}
 protected function process_request()
 {
     // check if someone entered an email that's already been registered
     // if so, first step is to make them log in
     if (!is_user_logged_in() && email_exists($_REQUEST['email'])) {
         $this->login_required();
         return;
     }
     // prepare & create the submission
     if (!is_user_logged_in()) {
         wp_set_current_user(1);
         $log_user_out = true;
     }
     $submission = $this->prepare_submission();
     $new_post = $this->create_submission_post($submission);
     if (!empty($log_user_out)) {
         wp_set_current_user(0);
     }
     // if that failed, bail
     if (is_wp_error($new_post)) {
         $this->errors[] = $new_post->get_error_message();
         return;
     }
     // connect the submission to the question they were answering
     $question_id = $_REQUEST['question'];
     if ($question_id) {
         p2p_create_connection('submission_to_question', array('from' => $new_post, 'to' => $question_id));
     }
     $this->response['new_user_created'] = false;
     // if the submitter is not logged in, we need to create a user for them
     if (!is_user_logged_in()) {
         $new_user = $this->create_submission_author();
         // for some reason we couldn't create the user, delete the submission because
         // the whole process should fail, then bail
         if (is_wp_error($new_user)) {
             $this->errors[] = $new_user->get_error_message();
             wp_delete_post($new_post);
             return;
         }
         // the user was successfully created, set them as the submission author
         $this->set_submission_author($new_post, $new_user);
         // let the upload page know we created a new user
         $this->response['new_user_created'] = true;
     }
     // we got this far, ok to save uploads to the media library
     if ($_REQUEST['submissionType'] == 'image') {
         $image = $this->save_media('image', $new_post);
     }
     if (in_array($_REQUEST['submissionType'], array('audio', 'text'))) {
         $thumbnail = $this->save_media('thumbnail', $new_post);
     }
     if ($_REQUEST['submissionType'] == 'audio') {
         $audio = $this->save_media('audio', $new_post);
         update_post_meta($new_post, 'audio_url', wp_get_attachment_url($audio));
     }
     if ($_REQUEST['submissionType'] == 'video') {
         $video_metadata = wp_read_video_metadata($_FILES['video']['tmp_name']);
         if ($video_metadata['dataformat'] == 'quicktime' && $video_metadata['fileformat'] == 'mp4') {
             $_FILES['video']['name'] = str_ireplace('.mov', '.mp4', $_FILES['video']['name']);
         }
         $video = $this->save_media('video', $new_post);
         update_post_meta($new_post, 'video_url', wp_get_attachment_url($video));
     }
     // set the featured image
     if (!empty($image)) {
         set_post_thumbnail($new_post, $image);
         update_post_meta($new_post, 'image', $image);
     } elseif (!empty($thumbnail)) {
         set_post_thumbnail($new_post, $thumbnail);
     }
     $this->response['next'] = 'success';
     $this->response['submission'] = get_permalink($new_post);
 }
Exemple #7
0
 /**
  * Retrieve information on a local video via GetID3.
  *
  * @uses WPSEO_Video_Details::$remote_url
  *
  * @return void|string
  */
 protected function get_remote_video_info()
 {
     $response = null;
     if (!empty($this->attachment_id)) {
         $response = wp_get_attachment_metadata($this->attachment_id);
         if (is_array($response) && $response !== array()) {
             $this->remote_response = $response;
         }
     } elseif (!empty($this->file_path)) {
         if (!function_exists('wp_read_video_metadata')) {
             require_once ABSPATH . 'wp-admin/includes/media.php';
         }
         $response = wp_read_video_metadata($this->file_path);
         if (is_array($response) && $response !== array()) {
             $this->remote_response = $response;
         }
     }
     return $response;
 }