• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_read_video_metadata函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_read_video_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_read_video_metadata函数的具体用法?PHP wp_read_video_metadata怎么用?PHP wp_read_video_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_read_video_metadata函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: getThumbnail

 /**
  * 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;
 }
开发者ID:WildCodeSchool,项目名称:projet-maison_ados_dreux,代码行数:45,代码来源:class-audio-video-thumber.php


示例2: wp_generate_attachment_metadata

/**
 * 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);
}
开发者ID:pankajsinghjarial,项目名称:SYLC-AMERICAN,代码行数:89,代码来源:image.php


示例3: generate_metadata

 /**
  * 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);
 }
开发者ID:markc,项目名称:mediapress,代码行数:78,代码来源:class-mpp-local-storage.php


示例4: wp_generate_attachment_metadata

/**
 * 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.
                 *
//.........这里部分代码省略.........
开发者ID:skinnard,项目名称:FTL-2,代码行数:101,代码来源:image.php


示例5: remote_upload_json


//.........这里部分代码省略.........
            $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);
        }
    }
}
开发者ID:arshidkv12,项目名称:remote-upload,代码行数:101,代码来源:remote-upload.php


示例6: process_request

 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);
 }
开发者ID:root-tongue,项目名称:root-tongue,代码行数:73,代码来源:submission.php


示例7: get_remote_video_info

 /**
  * 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;
 }
开发者ID:scottnkerr,项目名称:eeco,代码行数:26,代码来源:class-localfile.php



注:本文中的wp_read_video_metadata函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_redirect函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_read_image_metadata函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap