本文整理汇总了PHP中wp_read_image_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_read_image_metadata函数的具体用法?PHP wp_read_image_metadata怎么用?PHP wp_read_image_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_read_image_metadata函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: wp_all_import_get_image_from_gallery
function wp_all_import_get_image_from_gallery($image_name, $targetDir = false, $bundle_type = 'images')
{
global $wpdb;
if (!$targetDir) {
$wp_uploads = wp_upload_dir();
$targetDir = $wp_uploads['path'];
}
// search attachment by file name with extension
$attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type LIKE %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", "image%"));
if (empty($attch)) {
// search attachment by file name without extension
$attachment_title = explode(".", $image_name);
if (is_array($attachment_title) and count($attachment_title) > 1) {
array_pop($attachment_title);
}
$image_name = implode(".", $attachment_title);
$attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type LIKE %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", "image%"));
}
// search attachment by file headers
if (empty($attch) and @file_exists($targetDir . DIRECTORY_SEPARATOR . $image_name)) {
if ($bundle_type == 'images' and $img_meta = wp_read_image_metadata($targetDir . DIRECTORY_SEPARATOR . $image_name)) {
if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
$img_title = $img_meta['title'];
$attch = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_mime_type LIKE %s;", $img_title, "attachment", "image%"));
}
}
}
return $attch;
}
开发者ID:mynein,项目名称:myne,代码行数:29,代码来源:wp_all_import_get_image_from_gallery.php
示例2: wpua_avatar_upload
public function wpua_avatar_upload($file)
{
$filetype = wp_check_filetype($file->name);
$media_upload = array();
$media_upload['file'] = array('name' => $file->name, 'type' => $filetype['type'], 'tmp_name' => $file->path, 'error' => 0, 'size' => filesize($file->path));
$media_file = wp_handle_upload($media_upload['file'], array('test_form' => false, 'test_upload' => false, 'action' => 'custom_action'));
if ($media_file['file']) {
$url = $media_file['url'];
$filepath = $media_file['file'];
if ($image_meta = @wp_read_image_metadata($filepath)) {
if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
$title = $image_meta['title'];
}
}
$attachment = array('guid' => $url, 'post_mime_type' => $filetype['type'], 'post_title' => $title);
$attachment_id = wp_insert_attachment($attachment, $filepath);
if (!is_wp_error($attachment_id)) {
$this->delete_attachment_by_user($this->user_id);
wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $filepath));
update_post_meta($attachment_id, '_wp_attachment_wp_user_avatar', $this->user_id);
$arr = wp_get_attachment_image_src($attachment_id, 'full');
$this->avatar_url = $arr[0];
$this->avatar_filename = basename($filepath);
$this->resource = $attachment_id;
$saved = $this->save();
if (!$saved) {
$this->delete_attachment($attachment_id);
return $saved;
}
return $saved;
}
} else {
return WP_Error('file_upload_problem', __("Media avatar could't uploading please check you have right permission for uploads folder.", 'wp-user-avatar-pro'));
}
}
开发者ID:andyUA,项目名称:kabmin-new,代码行数:35,代码来源:class-wpua-media-storage.php
示例3: media_handle_upload
function media_handle_upload($file_id, $post_id, $post_data = array())
{
$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES[$file_id], $overrides);
if (isset($file['error'])) {
return new wp_error('upload_error', $file['error']);
}
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$title = preg_replace('/\\.[^.]+$/', '', basename($file));
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ($image_meta = @wp_read_image_metadata($file)) {
if (trim($image_meta['title'])) {
$title = $image_meta['title'];
}
if (trim($image_meta['caption'])) {
$content = $image_meta['caption'];
}
}
// Construct the attachment array
$attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content), $post_data);
// Save the data
$id = wp_insert_attachment($attachment, $file, $post_parent);
if (!is_wp_error($id)) {
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
}
return $id;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:30,代码来源:media.php
示例4: sp_generate_attachment_metadata
function sp_generate_attachment_metadata($attachment_id, $file)
{
$attachment = get_post($attachment_id);
$metadata = array();
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];
list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']);
$metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
// Make the file path relative to the upload dir
$metadata['file'] = $attachment->post_title;
// make thumbnails and other intermediate sizes
global $_wp_additional_image_sizes;
$temp_sizes = array('thumbnail', 'medium', 'large');
// Standard sizes
if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes)) {
$temp_sizes = array_merge($temp_sizes, array_keys($_wp_additional_image_sizes));
}
$temp_sizes = apply_filters('intermediate_image_sizes', $temp_sizes);
foreach ($temp_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);
foreach ($sizes as $size => $size_data) {
$resized = image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop']);
if ($resized) {
$metadata['sizes'][$size] = $resized;
}
}
// fetch additional metadata from exif/iptc
$image_meta = wp_read_image_metadata($file);
if ($image_meta) {
$metadata['image_meta'] = $image_meta;
}
}
return apply_filters('wp_generate_attachment_metadata', $metadata, $attachment_id);
}
开发者ID:voodoobettie,项目名称:staypressproperty,代码行数:56,代码来源:functions.php
示例5: hack_wp_generate_attachment_metadata
function hack_wp_generate_attachment_metadata($metadata, $attachment_id)
{
if (!isset($metadata['file'])) {
return $metadata;
}
$attachment = get_post($attachment_id);
$uploadPath = wp_upload_dir();
$file = path_join($uploadPath['basedir'], $metadata['file']);
$metadata = array();
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];
list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96);
$metadata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
// 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;
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
}
foreach ($sizes as $size => $size_data) {
$resized = hack_image_make_intermediate_size($file, $size_data['width'], $size_data['height'], $size_data['crop'], $size);
if ($resized) {
$metadata['sizes'][$size] = $resized;
}
}
// fetch additional metadata from exif/iptc
$image_meta = wp_read_image_metadata($file);
if ($image_meta) {
$metadata['image_meta'] = $image_meta;
}
}
return $metadata;
}
开发者ID:atomita,项目名称:wordpress-thumbnail-filename-changer,代码行数:54,代码来源:thumbnail-filename-changer.php
示例6: saveUpload
/**
* Handles the saving, i.e. creates a post type of attachment.
*
* During form submission run the method:
* $class->fileUpload( $field_name='form_field_name' );
*
* @return $final_file An array of array of f*cking cool stuff
* I guess if you think arrays are cool i like (*)(*)s
* $final_file['attachment_id'] = $this->attachment_id;
* $final_file['file'] = $uploaded_file['file'];
* $final_file['file_info'] = $file_info[];
*/
public function saveUpload($field_name = null, $user_id = null)
{
if (is_null($field_name)) {
die('Need field_name');
}
// Move the file to the uploads directory, returns an array
// of information from $_FILES
$uploaded_file = $this->handleUpload($_FILES[$field_name]);
if (!isset($uploaded_file['file'])) {
return false;
}
// If we were to have a unique user account for uploading
if (is_null($user_id)) {
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
}
// Build the Global Unique Identifier
$guid = $this->buildGuid($uploaded_file['file']);
// Build our array of data to be inserted as a post
$attachment = array('post_mime_type' => $_FILES[$field_name]['type'], 'guid' => $guid, 'post_title' => 'Uploaded : ' . $this->mediaTitle($uploaded_file['file']), 'post_content' => '', 'post_author' => $user_id, 'post_status' => 'inherit', 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => date('Y-m-d H:i:s'));
// Add the file to the media library and generate thumbnail.
$this->attachment_id = wp_insert_attachment($attachment, $uploaded_file['file']);
// @todo bug, this does NOT work when used in a PLUGIN!, so you'll have to make
// your OWN thumbnail sizes!
require_once ABSPATH . "wp-admin" . '/includes/image.php';
$meta = wp_generate_attachment_metadata($this->attachment_id, $uploaded_file['file']);
$image_meta = wp_read_image_metadata($uploaded_file['file']);
$meta['image_meta'] = $image_meta;
$image = new ImageMeta();
$meta['image_meta']['keywords'] = $image->iptcParser('keywords', $uploaded_file['file']);
$meta['image_meta']['city'] = $image->iptcParser('city', $uploaded_file['file']);
$meta['image_meta']['region'] = $image->iptcParser('region', $uploaded_file['file']);
$meta['image_meta']['country'] = $image->iptcParser('country', $uploaded_file['file']);
wp_update_attachment_metadata($this->attachment_id, $meta);
$file_info = pathinfo($uploaded_file['file']);
// Set the feedback flag to false, since the upload was successful
$upload_feedback = false;
$final_file = array();
$final_file['attachment_id'] = $this->attachment_id;
$final_file['file'] = $uploaded_file['file'];
$final_file['file_info'] = $file_info;
return $final_file;
}
开发者ID:waifei,项目名称:zm-upload,代码行数:55,代码来源:MediaUpload.php
示例7: saveMediaAttachment
public function saveMediaAttachment()
{
Helpers::debug("Upload::saveMediaAttachment called");
include WCAPIDIR . "/_mime_types.php";
$this->time = current_time('mysql');
$this->save();
$name_parts = pathinfo($this->name);
$name = trim(substr($this->name, 0, -(1 + strlen($name_parts['extension']))));
$url = $this->url;
Helpers::debug("Url is: " . $this->url);
if (isset($mime_types[$name_parts['extension']])) {
$type = $mime_types[$name_parts['extension']];
} else {
throw new \Exception(__('unknown mime_type ' . $name_parts['extension']));
}
$file = $this->path;
$title = $name;
$content = '';
Helpers::debug("file is: {$file} and title is: {$title}");
//use image exif/iptc data for title and caption defaults if possible
if ($image_meta = @wp_read_image_metadata($file)) {
if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
$title = $image_meta['title'];
}
if (trim($image_meta['caption'])) {
$content = $image_meta['caption'];
}
}
// Construct the attachment array
$attachment = array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => '', 'post_title' => $title, 'post_content' => $content);
Helpers::debug("Saving attachment: " . var_export($attachment, true));
$id = wp_insert_attachment($attachment, $file, NULL);
if (!is_wp_error($id)) {
$generated_metadata = wp_generate_attachment_metadata($id, $file);
Helpers::debug("Updating the metadata of {$id} to " . var_export($generated_metadata, true));
wp_update_attachment_metadata($id, $generated_metadata);
} else {
Helpers::debug("Failed to save attachment because of: " . $id->get_error_messages());
throw new \Exception($id->get_error_messages());
}
Helpers::debug("Upload::saveMediaAttachment done");
return $id;
}
开发者ID:borisdiakur,项目名称:woocommerce-json-api,代码行数:43,代码来源:Upload.php
示例8: _openbadger_badgedesigner_media_handle_upload
/**
* Handle a media upload that came from AJAX, but was never present in $_FILES.
* This is here because the original relies on move_upload_file(), and that won't
* work for us.
*
* Copied from wp-admin/includes/media.php media_handle_upload.
*/
function _openbadger_badgedesigner_media_handle_upload($_f, $post_id, $post_data = array(), $overrides = array('test_form' => false))
{
$time = current_time('mysql');
if ($post = get_post($post_id)) {
if (substr($post->post_date, 0, 4) > 0) {
$time = $post->post_date;
}
}
$name = $_f['name'];
$file = _openbadger_badgedesigner_wp_handle_upload($_f, $overrides, $time);
if (isset($file['error'])) {
return new WP_Error('upload_error', $file['error']);
}
$name_parts = pathinfo($name);
$name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$title = $name;
$content = '';
if ($image_meta = @wp_read_image_metadata($file)) {
if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
$title = $image_meta['title'];
}
if (trim($image_meta['caption'])) {
$content = $image_meta['caption'];
}
}
// Construct the attachment array
$attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content), $post_data);
// This should never be set as it would then overwrite an existing attachment.
if (isset($attachment['ID'])) {
unset($attachment['ID']);
}
// Save the data
$id = wp_insert_attachment($attachment, $file, $post_id);
if (!is_wp_error($id)) {
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
}
return $id;
}
开发者ID:johappel,项目名称:open-badger,代码行数:48,代码来源:badges_designer.php
示例9: save_uploaded_files
public static function save_uploaded_files($data, $postarr)
{
// Check for autosaves
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $data;
}
if (self::is_being_edited() && $_FILES) {
$file = wp_handle_upload($_FILES['async-upload'], array('action' => 'editpost'));
if (isset($file['file']) && !is_wp_error($file)) {
$name = $_FILES['async-upload']['name'];
$name_parts = pathinfo($name);
$name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$title = $name;
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ($image_meta = @wp_read_image_metadata($file)) {
if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
$title = $image_meta['title'];
}
if (trim($image_meta['caption'])) {
$content = $image_meta['caption'];
}
}
// Construct the attachment array
$attachment = array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => (int) $_POST['live_blogging_entry_post'], 'post_title' => $title, 'post_content' => $content);
// Save the data
$id = wp_insert_attachment($attachment, $file, (int) $_POST['live_blogging_entry_post']);
if (!is_wp_error($id)) {
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
}
// Add the image to the post
$data['post_content'] .= '<div class="liveblog-image">' . wp_get_attachment_image($id, 'large') . '</div>';
}
}
return $data;
}
开发者ID:ifreaker,项目名称:liveblogging,代码行数:39,代码来源:LiveBlogEntry.php
示例10: handle_import_media_file
function handle_import_media_file($file, $post_id = 0)
{
// see if the attachment already exists
$id = array_search($file, $this->filearr);
if ($id === false) {
set_time_limit(120);
$post = get_post($post_id);
$time = $post->post_date_gmt;
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
if (!(($uploads = wp_upload_dir($time)) && false === $uploads['error'])) {
return new WP_Error('upload_error', $uploads['error']);
}
// this security check is pointless. It gives false positives, and anyone running this importer can unfiltered_upload anyway.
/*
$wp_filetype = wp_check_filetype( $file, null );
extract( $wp_filetype );
if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
return new WP_Error( 'wrong_file_type', __( 'Sorry, this file type is not permitted for security reasons.' ) );
/**/
$filename = wp_unique_filename($uploads['path'], basename($file));
// copy the file to the uploads dir
$new_file = $uploads['path'] . '/' . $filename;
if (false === @copy($file, $new_file)) {
return new WP_Error('upload_error', sprintf(__('Could not find the right path to %s ( tried %s ). It could not be imported. Please upload it manually.', 'html-import-pages'), basename($file), $file));
}
// else
// printf( __( '<br /><em>%s</em> is being copied to the uploads directory as <em>%s</em>.', 'html-import-pages' ), $file, $new_file );
// Set correct file permissions
$stat = stat(dirname($new_file));
$perms = $stat['mode'] & 0666;
@chmod($new_file, $perms);
// Compute the URL
$url = $uploads['url'] . '/' . $filename;
//Apply upload filters
$return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => wp_check_filetype($file, null)));
$new_file = $return['file'];
$url = $return['url'];
$type = $return['type'];
$title = preg_replace('!\\.[^.]+$!', '', basename($file));
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ($image_meta = @wp_read_image_metadata($new_file)) {
if ('' != trim($image_meta['title'])) {
$title = trim($image_meta['title']);
}
if ('' != trim($image_meta['caption'])) {
$content = trim($image_meta['caption']);
}
}
if ($time) {
$post_date_gmt = $time;
$post_date = $time;
} else {
$post_date = current_time('mysql');
$post_date_gmt = current_time('mysql', 1);
}
// Construct the attachment array
$wp_filetype = wp_check_filetype(basename($filename), null);
$attachment = array('post_mime_type' => $wp_filetype['type'], 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_name' => $title, 'post_content' => $content, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt);
//Win32 fix:
$new_file = str_replace(strtolower(str_replace('\\', '/', $uploads['basedir'])), $uploads['basedir'], $new_file);
// Insert attachment
$id = wp_insert_attachment($attachment, $new_file, $post_id);
if (!is_wp_error($id)) {
$data = wp_generate_attachment_metadata($id, $new_file);
wp_update_attachment_metadata($id, $data);
$this->filearr[$id] = $file;
// $file contains the original, absolute path to the file
}
}
// if attachment already exists
return $id;
}
开发者ID:kevinotsuka,项目名称:datapop,代码行数:75,代码来源:html-importer.php
示例11: handle_upload
/**
* download remote image to local server and save it to database
* This will not create thumbs.
*
* @param string $filename
* The base filename
* @param string $data
* binary data
* @param string $type
* mime type
* @param int $post_id
*/
public static function handle_upload($filename, $data, $type, $post_id)
{
$mimes = false;
$time = FALSE;
if ($post = get_post($post_id)) {
if (substr($post->post_date, 0, 4) > 0) {
$time = $post->post_date;
}
}
// A writable uploads dir will pass this test. Again, there's no point
// overriding this one.
$uploads = wp_upload_dir($time);
$unique_filename_callback = null;
$filename = wp_unique_filename($uploads['path'], $filename, $unique_filename_callback);
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/{$filename}";
// var_dump($new_file);exit;
if (false === file_put_contents($new_file, $data)) {
return FALSE;
}
// Set correct file permissions
$stat = stat(dirname($new_file));
$perms = $stat['mode'] & 0666;
@chmod($new_file, $perms);
// Compute the URL
$url = $uploads['url'] . "/{$filename}";
// Compatible with Hacklog Remote Attachment plugin
if (class_exists('hacklogra')) {
//apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' );
$hacklogra_file = hacklogra::upload_and_send(array('file' => $new_file, 'url' => $url));
$url = $hacklogra_file['url'];
$new_file = $hacklogra_file['file'];
}
if (is_multisite()) {
delete_transient('dirsize_cache');
}
// array( 'file' => $new_file, 'url' => $url, 'type' => $type );
$name_parts = pathinfo($filename);
$name = trim(substr($filename, 0, -(1 + strlen($name_parts['extension']))));
$file = $new_file;
$title = $name;
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ($image_meta = @wp_read_image_metadata($file)) {
if (trim($image_meta['title']) && !is_numeric(sanitize_title($image_meta['title']))) {
$title = $image_meta['title'];
}
if (trim($image_meta['caption'])) {
$content = $image_meta['caption'];
}
}
// Construct the attachment array
$attachment = array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content);
// This should never be set as it would then overwrite an existing
// attachment.
if (isset($attachment['ID'])) {
unset($attachment['ID']);
}
// Save the data
// remove_filter('media_send_to_editor', array('hacklogra',
// 'replace_attachurl'), -999);
// remove_filter('wp_generate_attachment_metadata',
// array('hacklogra', 'upload_images'),999);
$id = wp_insert_attachment($attachment, $file, $post_id);
if (!is_wp_error($id)) {
// Compatible with Watermark Reloaded plugin
//$metadata = self::generate_attachment_metadata ( $id, $file );
//generate attachment metadata AND create thumbnails
$metadata = wp_generate_attachment_metadata($id, $file);
// Compatible with Hacklog Remote Attachment plugin
// if Hacklog Remote Attachment failed to upload file to remote FTP
// server
// then,it will return an error.if this was not stopped,the image
// will be un-viewable.
// if failed,delete the attachment we just added from the database.
if (is_wp_error($metadata) || !isset($metadata['file'])) {
wp_delete_attachment($id, TRUE);
return new WP_Error('hacklog_ria_generate_attachment_metadata_failed', __($metadata['error']));
}
wp_update_attachment_metadata($id, $metadata);
}
return array('id' => $id, 'url' => $url);
}
开发者ID:vihoangson,项目名称:vihoangson.vus.vn,代码行数:95,代码来源:util.class.php
示例12: 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
示例13: process
//.........这里部分代码省略.........
$logger and call_user_func($logger, sprintf(__('- Importing image `%s` for `%s` ...', 'wp_all_import_plugin'), $img_url, $articleData['post_title']));
// generate local file name
$image_name = urldecode(($this->options[$option_slug . 'auto_rename_images'] and !empty($auto_rename_images_bundle[$slug][$i])) ? sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $auto_rename_images_bundle[$slug][$i]) : $auto_rename_images_bundle[$slug][$i]) : sanitize_file_name($img_ext ? str_replace("." . $default_extension, "", $bn) : $bn)) . ("" != $img_ext ? '.' . $img_ext : '');
// if wizard store image data to custom field
$create_image = false;
$download_image = true;
$wp_filetype = false;
if ($bundle_data['type'] == 'images' and base64_decode($url, true) !== false) {
$img = @imagecreatefromstring(base64_decode($url));
if ($img) {
$logger and call_user_func($logger, __('- Founded base64_encoded image', 'wp_all_import_plugin'));
$image_filename = md5(time()) . '.jpg';
$image_filepath = $targetDir . '/' . $image_filename;
imagejpeg($img, $image_filepath);
if (!($image_info = @getimagesize($image_filepath)) or !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
$logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
$logger and !$is_cron and PMXI_Plugin::$session->warnings++;
} else {
$create_image = true;
}
}
} else {
$image_filename = wp_unique_filename($targetDir, $image_name);
$image_filepath = $targetDir . '/' . $image_filename;
// keep existing and add newest images
if ($is_keep_existing_images) {
$attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_parent = %d;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", $pid));
if ($attch != null) {
$post_thumbnail_id = get_post_thumbnail_id($pid);
if ($post_thumbnail_id == $attch->ID or in_array($attch->ID, $gallery_attachment_ids)) {
continue;
}
} elseif (file_exists($targetDir . '/' . $image_name)) {
if ($bundle_data['type'] == 'images' and $img_meta = wp_read_image_metadata($targetDir . '/' . $image_name)) {
if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
$img_title = $img_meta['title'];
$attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_parent = %d;", $img_title, "attachment", $pid));
if ($attch != null) {
$post_thumbnail_id = get_post_thumbnail_id($pid);
if ($post_thumbnail_id == $attch->ID or in_array($attch->ID, $gallery_attachment_ids)) {
continue;
}
}
}
}
}
}
// search existing attachment
if ($this->options[$option_slug . 'search_existing_images']) {
$image_filename = $image_name;
$attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment"));
if ($attch != null) {
$download_image = false;
$attid = $attch->ID;
} elseif (@file_exists($targetDir . '/' . $image_name)) {
if ($bundle_data['type'] == 'images' and $img_meta = wp_read_image_metadata($targetDir . '/' . $image_name)) {
if (trim($img_meta['title']) && !is_numeric(sanitize_title($img_meta['title']))) {
$img_title = $img_meta['title'];
$attch = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM " . $this->wpdb->posts . " WHERE post_title = %s AND post_type = %s AND post_parent = %d;", $img_title, "attachment", $pid));
if ($attch != null) {
$download_image = false;
$attid = $attch->ID;
}
}
}
}
开发者ID:k-hasan-19,项目名称:wp-all-import,代码行数:67,代码来源:record.php
示例14: jr_process_relist_job_form
//.........这里部分代码省略.........
wp_set_object_terms($job_details->ID, $post_into_types, 'job_type');
}
### Salary
$salary = array();
if ($posted['job_term_salary'] > 0) {
$salary[] = get_term_by('id', $posted['job_term_salary'], 'job_salary')->slug;
}
wp_set_object_terms($job_details->ID, $salary, 'job_salary');
### Tags
if ($posted['tags']) {
$thetags = explode(',', $posted['tags']);
$thetags = array_map('trim', $thetags);
$thetags = array_map('strtolower', $thetags);
if (sizeof($thetags) > 0) {
wp_set_object_terms($job_details->ID, $thetags, 'job_tag');
}
}
### GEO
if (!empty($posted['jr_address'])) {
$latitude = jr_clean_coordinate($posted['jr_geo_latitude']);
$longitude = jr_clean_coordinate($posted['jr_geo_longitude']);
update_post_meta($job_details->ID, '_jr_geo_latitude', $latitude);
update_post_meta($job_details->ID, '_jr_geo_longitude', $longitude);
if ($latitude && $longitude) {
$address = jr_reverse_geocode($latitude, $longitude);
update_post_meta($job_details->ID, 'geo_address', $address['address']);
update_post_meta($job_details->ID, 'geo_country', $address['country']);
update_post_meta($job_details->ID, 'geo_short_address', $address['short_address']);
update_post_meta($job_details->ID, 'geo_short_address_country', $address['short_address_country']);
}
} else {
// They left the field blank so we assume the job is for 'anywhere'
delete_post_meta($job_details->ID, '_jr_geo_latitude');
delete_post_meta($job_details->ID, '_jr_geo_longitude');
delete_post_meta($job_details->ID, 'geo_address');
delete_post_meta($job_details->ID, 'geo_country');
delete_post_meta($job_details->ID, 'geo_short_address');
delete_post_meta($job_details->ID, 'geo_short_address_country');
}
## Link to company image
if (isset($posted['company-logo']) && $posted['company-logo']) {
$name_parts = pathinfo($posted['company-logo-name']);
$name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
$url = $posted['company-logo'];
$type = $posted['company-logo-type'];
$file = $posted['company-logo-file'];
$title = $posted['company-logo-name'];
$content = '';
// use image exif/iptc data for title and caption defaults if possible
if ($image_meta = @wp_read_image_metadata($file)) {
if (trim($image_meta['title'])) {
$title = $image_meta['title'];
}
if (trim($image_meta['caption'])) {
$content = $image_meta['caption'];
}
}
// Construct the attachment array
$attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $job_details->ID, 'post_title' => $title, 'post_content' => $content), array());
// Save the data
$id = wp_insert_attachment($attachment, $file, $job_details->ID);
if (!is_wp_error($id)) {
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
}
update_post_meta($job_details->ID, '_thumbnail_id', $id);
}
### If paying with pack, update the customers pack totals
if ($user_pack) {
$inspack = '';
$user_pack->inc_job_count();
} elseif (!empty($posted['job_pack'])) {
$inspack = $posted['job_pack'];
}
if ($posted['featureit'] == 'yes') {
$insfeatured = 1;
} else {
$insfeatured = 0;
}
### Create the order in the database so it can be confirmed by user/IPN before going live
if ($cost > 0) {
$jr_order = new jr_order(0,
|
请发表评论