本文整理汇总了PHP中ewww_image_optimizer_attachment_path函数的典型用法代码示例。如果您正苦于以下问题:PHP ewww_image_optimizer_attachment_path函数的具体用法?PHP ewww_image_optimizer_attachment_path怎么用?PHP ewww_image_optimizer_attachment_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ewww_image_optimizer_attachment_path函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ewww_image_optimizer_import_loop
function ewww_image_optimizer_import_loop()
{
// verify that an authorized user has started the optimizer
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk')) {
wp_die(__('Cheatin’ eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
global $wpdb;
global $ewww_debug;
// echo "starting usage: " . memory_get_usage() . "<br>";
// retrieve the time when the optimizer starts
// $started = microtime(true);
$import_finished = false;
$import_status = get_option('ewww_image_optimizer_import_status');
$attachments = $wpdb->get_results("SELECT posts.ID,metas.meta_value FROM {$wpdb->postmeta} metas INNER JOIN {$wpdb->posts} posts ON posts.ID = metas.post_id WHERE posts.post_mime_type LIKE '%image%' AND metas.meta_key = '_wp_attachment_metadata' AND metas.meta_value LIKE '%ewww_image_optimizer%' LIMIT {$import_status['media']}, 100", ARRAY_N);
// echo "after loading metadata: " . memory_get_usage() . "<br>";
if (count($attachments) === 0) {
$import_finished = true;
} else {
$import_status['media'] += count($attachments);
}
$already_optimized = array();
// echo "after loading already optimized: " . memory_get_usage() . "<br>";
$ewww_debug .= "importing " . count($attachments) . " attachments<br>";
$insert_query = "INSERT INTO {$wpdb->ewwwio_images} (path, image_size, orig_size, results, temp) VALUES ";
$rows = array();
foreach ($attachments as $attachment) {
$record = array();
$gallery_type = 0;
$id = $attachment[0];
$meta = unserialize($attachment[1]);
if (empty($attachment) || empty($attachment[1])) {
continue;
}
list($attachment, $upload_path) = ewww_image_optimizer_attachment_path($meta, $id);
if ('ims_image' == get_post_type($id)) {
$gallery_type = 6;
}
// make sure the meta actually contains data for ewww_image_optimizer
if (empty($meta['ewww_image_optimizer'])) {
$prev_results = '';
} else {
$prev_results = $meta['ewww_image_optimizer'];
}
$record = ewww_image_optimizer_import_file($attachment, $prev_results, $already_optimized);
if (!empty($record)) {
$rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
}
// resized versions, so we can continue
if (isset($meta['sizes'])) {
$record = array();
$ewww_debug .= "processing resizes<br>";
// meta sizes don't contain a path, so we calculate one
if ($gallery_type === 6) {
$base_dir = dirname($attachment) . '/_resized/';
} else {
$base_dir = dirname($attachment) . '/';
}
foreach ($meta['sizes'] as $size => $data) {
$resize_path = $base_dir . $data['file'];
$ewww_debug .= "current resize: {$resize_path}<br>";
// make sure the meta actually contains data for ewww_image_optimizer
if (empty($data['ewww_image_optimizer'])) {
$prev_results = '';
} else {
$prev_results = $data['ewww_image_optimizer'];
}
$record = ewww_image_optimizer_import_file($resize_path, $prev_results, $already_optimized);
if (!empty($record)) {
$rows[] = "('{$record['0']}', '{$record['1']}', '{$record['2']}', '{$record['3']}', true)";
}
}
}
ewww_image_optimizer_debug_log();
}
$import_count = $import_status['media'];
//nextgen import
if ($import_finished && isset($import_status['nextgen'])) {
$import_finished = false;
$images = $wpdb->get_results("SELECT pid,meta_data,filename,galleryid FROM {$wpdb->nggpictures} WHERE meta_data LIKE '%ewww_image_optimizer%' LIMIT {$import_status['nextgen']}, 100", ARRAY_N);
if (count($images) === 0) {
$import_finished = true;
} else {
$import_status['nextgen'] += count($images);
}
$galleries = $wpdb->get_results("SELECT gid,path FROM {$wpdb->nggallery}", ARRAY_N);
// creating the 'registry' object for working with nextgen
$registry = C_Component_Registry::get_instance();
// creating a database storage object from the 'registry' object
$storage = $registry->get_utility('I_Gallery_Storage');
$sizes = $storage->get_image_sizes();
foreach ($images as $image) {
$record = array();
$gallery_path = '';
foreach ($galleries as $gallery) {
if ($gallery[0] == $image[3]) {
$gallery_path = trailingslashit($gallery[1]);
}
}
$meta = unserialize($image[1]);
// get an array of sizes available for the $image
//.........这里部分代码省略.........
示例2: ewww_image_optimizer_custom_column
/**
* Print column data for optimizer results in the media library using
* the `manage_media_custom_column` hook.
*/
function ewww_image_optimizer_custom_column($column_name, $id)
{
global $ewww_debug;
$ewww_debug .= "<b>ewww_image_optimizer_custom_column()</b><br>";
// once we get to the EWWW IO custom column
if ($column_name == 'ewww-image-optimizer') {
// retrieve the metadata
$meta = wp_get_attachment_metadata($id);
if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
$print_meta = print_r($meta, TRUE);
$print_meta = preg_replace(array('/ /', '/\\n+/'), array(' ', '<br />'), $print_meta);
echo '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
}
if (!empty($meta['cloudinary'])) {
_e('Cloudinary image', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return;
}
// if the filepath isn't set in the metadata
if (empty($meta['file'])) {
if (isset($meta['file'])) {
unset($meta['file']);
if (strpos($meta['ewww_image_optimizer'], 'Could not find') === 0) {
unset($meta['ewww_image_optimizer']);
}
wp_update_attachment_metadata($id, $meta);
}
}
list($file_path, $upload_path) = ewww_image_optimizer_attachment_path($meta, $id);
// if the file does not exist
if (empty($file_path)) {
_e('Could not retrieve file path.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return;
}
$msg = '';
$convert_desc = '';
$convert_link = '';
// retrieve the mimetype of the attachment
$type = ewww_image_optimizer_mimetype($file_path, 'i');
// get a human readable filesize
$file_size = size_format(filesize($file_path), 2);
$file_size = preg_replace('/\\.00 B /', ' B', $file_size);
// run the appropriate code based on the mimetype
switch ($type) {
case 'image/jpeg':
// if jpegtran is missing, tell them that
if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
$valid = false;
$msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>');
} else {
$convert_link = __('JPG to PNG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$class_type = 'jpg';
$convert_desc = __('WARNING: Removes metadata. Requires GD or ImageMagick. PNG is generally much better than JPG for logos and other images with a limited range of colors.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
break;
case 'image/png':
// if pngout and optipng are missing, tell the user
if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png')) {
$valid = false;
$msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>');
} else {
$convert_link = __('PNG to JPG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$class_type = 'png';
$convert_desc = __('WARNING: This is not a lossless conversion and requires GD or ImageMagick. JPG is much better than PNG for photographic use because it compresses the image and discards data. Transparent images will only be converted if a background color has been set.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
break;
case 'image/gif':
// if gifsicle is missing, tell the user
if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif')) {
$valid = false;
$msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>');
} else {
$convert_link = __('GIF to PNG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$class_type = 'gif';
$convert_desc = __('PNG is generally better than GIF, but does not support animation. Animated images will not be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
break;
default:
// not a supported mimetype
_e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return;
}
// if the optimizer metadata exists
if (!empty($meta['ewww_image_optimizer'])) {
// output the optimizer results
echo $meta['ewww_image_optimizer'];
// output the filesize
echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
if (empty($msg) && current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
// output a link to re-optimize manually
printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_optimize&ewww_force=1&ewww_attachment_ID=%d\">%s</a>", $id, __('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_convert_links') && 'ims_image' != get_post_type($id)) {
echo " | <a class='ewww-convert' title='{$convert_desc}' href='admin.php?action=ewww_image_optimizer_manual_optimize&ewww_attachment_ID={$id}&ewww_convert=1&ewww_force=1'>{$convert_link}</a>";
}
} else {
echo $msg;
}
//.........这里部分代码省略.........
示例3: ewww_image_optimizer_custom_column
/**
* Print column data for optimizer results in the media library using
* the `manage_media_custom_column` hook.
*/
function ewww_image_optimizer_custom_column($column_name, $id)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
// once we get to the EWWW IO custom column
if ($column_name == 'ewww-image-optimizer') {
// retrieve the metadata
$meta = wp_get_attachment_metadata($id);
if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
$print_meta = print_r($meta, TRUE);
$print_meta = preg_replace(array('/ /', '/\\n+/'), array(' ', '<br />'), $print_meta);
echo '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
}
// TODO: make sure meta is an array
$ewww_cdn = false;
if (!empty($meta['cloudinary'])) {
esc_html_e('Cloudinary image', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return;
}
if (class_exists('WindowsAzureStorageUtil') && !empty($meta['url'])) {
esc_html_e('Azure Storage image', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$ewww_cdn = true;
}
if (class_exists('Amazon_S3_And_CloudFront') && preg_match('/^(http|s3)\\w*:/', get_attached_file($id))) {
esc_html_e('Amazon S3 image', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$ewww_cdn = true;
}
list($file_path, $upload_path) = ewww_image_optimizer_attachment_path($meta, $id);
// if the file does not exist
if (empty($file_path) && !$ewww_cdn) {
esc_html_e('Could not retrieve file path.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
ewww_image_optimizer_debug_log();
return;
}
$msg = '';
$convert_desc = '';
$convert_link = '';
if ($ewww_cdn) {
$type = get_post_mime_type($id);
} else {
// retrieve the mimetype of the attachment
$type = ewww_image_optimizer_mimetype($file_path, 'i');
// get a human readable filesize
$file_size = size_format(filesize($file_path), 2);
$file_size = preg_replace('/\\.00 B /', ' B', $file_size);
}
$skip = ewww_image_optimizer_skip_tools();
// run the appropriate code based on the mimetype
switch ($type) {
case 'image/jpeg':
// if jpegtran is missing, tell them that
if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !$skip['jpegtran']) {
$valid = false;
$msg = '<br>' . wp_kses(sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>'), array('em' => array()));
} else {
$convert_link = esc_html__('JPG to PNG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$convert_desc = esc_attr__('WARNING: Removes metadata. Requires GD or ImageMagick. PNG is generally much better than JPG for logos and other images with a limited range of colors.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
break;
case 'image/png':
// if pngout and optipng are missing, tell the user
if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !$skip['optipng'] && !$skip['pngout']) {
$valid = false;
$msg = '<br>' . wp_kses(sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>'), array('em' => array()));
} else {
$convert_link = esc_html__('PNG to JPG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$convert_desc = esc_attr__('WARNING: This is not a lossless conversion and requires GD or ImageMagick. JPG is much better than PNG for photographic use because it compresses the image and discards data. Transparent images will only be converted if a background color has been set.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
break;
case 'image/gif':
// if gifsicle is missing, tell the user
if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !$skip['gifsicle']) {
$valid = false;
$msg = '<br>' . wp_kses(sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>'), array('em' => array()));
} else {
$convert_link = esc_html__('GIF to PNG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$convert_desc = esc_attr__('PNG is generally better than GIF, but does not support animation. Animated images will not be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
break;
case 'application/pdf':
$convert_desc = '';
break;
default:
// not a supported mimetype
esc_html_e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
ewww_image_optimizer_debug_log();
return;
}
$ewww_manual_nonce = wp_create_nonce("ewww-manual-{$id}");
if ($ewww_cdn) {
// if the optimizer metadata exists
if (!empty($meta['ewww_image_optimizer'])) {
// output the optimizer results
echo "<br>" . esc_html($meta['ewww_image_optimizer']);
if (current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
// output a link to re-optimize manually
printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_optimize&ewww_manual_nonce={$ewww_manual_nonce}&ewww_force=1&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
//.........这里部分代码省略.........