本文整理汇总了PHP中ewww_image_optimizer_filesize函数的典型用法代码示例。如果您正苦于以下问题:PHP ewww_image_optimizer_filesize函数的具体用法?PHP ewww_image_optimizer_filesize怎么用?PHP ewww_image_optimizer_filesize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ewww_image_optimizer_filesize函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: generate_image_size
function generate_image_size($image, $size, $params = null, $skip_defaults = false)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
global $ewww_defer;
if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
ewww_image_optimizer_init();
}
$success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
if ($success) {
$filename = $success->fileName;
if ($ewww_defer && ewww_image_optimizer_get_option('ewww_image_optimizer_defer')) {
ewww_image_optimizer_add_deferred_attachment("file,{$filename}");
return $saved;
}
ewww_image_optimizer($filename);
ewwwio_debug_message("nextgen dynamic thumb saved: {$filename}");
$image_size = ewww_image_optimizer_filesize($filename);
ewwwio_debug_message("optimized size: {$image_size}");
}
ewww_image_optimizer_debug_log();
ewwwio_memory(__FUNCTION__);
return $success;
}
开发者ID:agiper,项目名称:wordpress,代码行数:23,代码来源:nextgen2-integration.php
示例2: ewww_manage_image_custom_column
function ewww_manage_image_custom_column($column_name, $id)
{
// once we've found our custom column
if ($column_name == 'ewww_image_optimizer') {
// get the metadata for the image
$meta = new nggMeta($id);
// get the optimization status for the image
$status = $meta->get_META('ewww_image_optimizer');
$msg = '';
// get the file path of the image
$file_path = $meta->image->imagePath;
// get the mimetype of the image
$type = ewww_image_optimizer_mimetype($file_path, 'i');
// retrieve the human-readable filesize of the image
$file_size = size_format(ewww_image_optimizer_filesize($file_path), 2);
$file_size = str_replace('B ', 'B', $file_size);
//$file_size = ewww_image_optimizer_format_bytes(filesize($file_path));
$valid = true;
// check to see if we have a tool to handle the mimetype detected
switch ($type) {
case 'image/jpeg':
// if jpegtran is missing, tell the user
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>');
}
break;
case 'image/png':
// if the PNG tools 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>');
}
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>');
}
break;
default:
$valid = false;
}
// file isn't in a format we can work with, we don't work with strangers
if ($valid == false) {
print __('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN) . $msg;
return;
}
// if we have a valid status, display it, the image size, and give a re-optimize link
if ($status && !empty($status)) {
echo $status;
echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
printf("<br><a href=\"admin.php?action=ewww_ngg_manual&ewww_force=1&ewww_attachment_ID=%d\">%s</a>", $id, __('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
// otherwise, give the image size, and a link to optimize right now
} else {
_e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
printf("<br><a href=\"admin.php?action=ewww_ngg_manual&ewww_attachment_ID=%d\">%s</a>", $id, __('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
}
}
开发者ID:leotaillard,项目名称:btws2016,代码行数:62,代码来源:nextgen-integration.php
示例3: ewww_manage_image_custom_column
function ewww_manage_image_custom_column($column_name, $id)
{
// check to make sure we're outputing our custom column
if ($column_name == 'ewww_image_optimizer') {
// get the metadata
$meta = new flagMeta($id);
if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
$print_meta = print_r($meta->image->meta_data, TRUE);
$print_meta = preg_replace(array('/ /', '/\\n+/'), array(' ', '<br />'), esc_html($print_meta));
echo '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
}
// grab the image status from the meta
if (empty($meta->image->meta_data['ewww_image_optimizer'])) {
$status = '';
} else {
$status = $meta->image->meta_data['ewww_image_optimizer'];
}
$msg = '';
// get the image path from the meta
$file_path = $meta->image->imagePath;
// get the mimetype
$type = ewww_image_optimizer_mimetype($file_path, 'i');
// get the file size
$file_size = size_format(ewww_image_optimizer_filesize($file_path), 2);
$file_size = str_replace('B ', 'B', $file_size);
$valid = true;
// if we don't have a valid tool for the image type, output the appropriate message
$skip = ewww_image_optimizer_skip_tools();
switch ($type) {
case 'image/jpeg':
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()));
}
break;
case 'image/png':
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()));
}
break;
case 'image/gif':
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()));
}
break;
default:
$valid = false;
}
// let user know if the file type is unsupported
if ($valid == false) {
esc_html_e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return;
}
$ewww_manual_nonce = wp_create_nonce("ewww-manual-" . $id);
// output the image status if we know it
if (!empty($status)) {
echo esc_html($status);
echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
if (current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
printf("<br><a href=\"admin.php?action=ewww_flag_manual&ewww_manual_nonce={$ewww_manual_nonce}&ewww_force=1&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
} elseif (get_transient('ewwwio-background-in-progress-flag-' . $id)) {
esc_html_e('In Progress', EWWW_IMAGE_OPTIMIZER_DOMAIN);
// otherwise, tell the user that they can optimize the image now
} else {
esc_html_e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
if (current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
printf("<br><a href=\"admin.php?action=ewww_flag_manual&ewww_manual_nonce={$ewww_manual_nonce}&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
}
}
}
开发者ID:ChrisSargent,项目名称:moodesignz,代码行数:75,代码来源:flag-integration.php
示例4: ewww_image_optimizer_scan_other
function ewww_image_optimizer_scan_other()
{
global $wpdb;
// initialize the $attachments variable for auxiliary images
$attachments = null;
// check if there is a previous bulk operation to resume
if (get_option('ewww_image_optimizer_aux_resume')) {
// retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
$attachments = get_option('ewww_image_optimizer_aux_attachments');
} else {
// collect a list of images from the current theme
$child_path = get_stylesheet_directory();
$parent_path = get_template_directory();
$attachments = ewww_image_optimizer_image_scan($child_path);
if ($child_path !== $parent_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
}
// collect a list of images for buddypress
if (!function_exists('is_plugin_active')) {
// need to include the plugin library for the is_plugin_active function
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
}
if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
}
if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) {
// scan the grand media folder for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
}
if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
}
if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) {
$slide_paths = array();
$sliders = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'ml-slider'");
$slides = $wpdb->get_col("\n\t\t\t\tSELECT wpposts.ID \n\t\t\t\tFROM {$wpdb->posts} wpposts \n\t\t\t\tINNER JOIN {$wpdb->term_relationships} term_relationships\n\t\t\t\t\t\tON wpposts.ID = term_relationships.object_id\n\t\t\t\tINNER JOIN {$wpdb->terms} wpterms \n\t\t\t\t\t\tON term_relationships.term_taxonomy_id = wpterms.term_id\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} term_taxonomy\n\t\t\t\t\t\tON wpterms.term_id = term_taxonomy.term_id\n\t\t\t\tWHERE \tterm_taxonomy.taxonomy = 'ml-slider'\n\t\t\t\t\tAND wpposts.post_type = 'attachment'\n\t\t\t\t");
foreach ($slides as $slide) {
$type = get_post_meta($slide, 'ml-slider_type', true);
$type = $type ? $type : 'image';
// backwards compatibility, fall back to 'image'
if ($type != 'image') {
continue;
}
$backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
if (ewww_image_optimizer_iterable($backup_sizes)) {
foreach ($backup_sizes as $backup_size => $meta) {
if (preg_match('/resized-/', $backup_size)) {
$path = $meta['path'];
$image_size = ewww_image_optimizer_filesize($path);
if (!$image_size) {
continue;
}
$already_optimized = ewww_image_optimizer_find_already_optimized($path);
$mimetype = ewww_image_optimizer_mimetype($path, 'i');
if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
$slide_paths[] = $path;
}
}
}
}
}
$attachments = array_merge($attachments, $slide_paths);
}
// collect a list of images in auxiliary folders provided by user
if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
if (ewww_image_optimizer_iterable($aux_paths)) {
foreach ($aux_paths as $aux_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
}
}
}
// store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
update_option('ewww_image_optimizer_aux_attachments', $attachments, false);
}
return $attachments;
}
开发者ID:aaronfrey,项目名称:PepperLillie-CVM,代码行数:85,代码来源:iocli.php
示例5: ewww_image_optimizer_webp_create
function ewww_image_optimizer_webp_create($file, $orig_size, $type, $tool, $recreate = false)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
// change the file extension
$webpfile = $file . '.webp';
if (!ewww_image_optimizer_get_option('ewww_image_optimizer_webp')) {
return;
} elseif (is_file($webpfile) && empty($_REQUEST['ewww_force']) && !$recreate) {
ewwwio_debug_message('webp file exists, not forcing or recreating');
return;
}
if (empty($tool)) {
ewww_image_optimizer_cloud_optimizer($file, $type, false, $webpfile, 'image/webp');
} else {
// check to see if 'nice' exists
$nice = ewww_image_optimizer_find_nix_binary('nice', 'n');
switch ($type) {
case 'image/jpeg':
exec("{$nice} " . $tool . " -q 85 -quiet " . ewww_image_optimizer_escapeshellarg($file) . " -o " . ewww_image_optimizer_escapeshellarg($webpfile) . ' 2>&1', $cli_output);
break;
case 'image/png':
exec("{$nice} " . $tool . " -lossless -quiet " . ewww_image_optimizer_escapeshellarg($file) . " -o " . ewww_image_optimizer_escapeshellarg($webpfile) . ' 2>&1', $cli_output);
break;
}
}
$webp_size = ewww_image_optimizer_filesize($webpfile);
ewwwio_debug_message("webp is {$webp_size} vs. {$type} is {$orig_size}");
if (is_file($webpfile) && $orig_size < $webp_size) {
ewwwio_debug_message('webp file was too big, deleting');
unlink($webpfile);
} elseif (is_file($webpfile)) {
// Set correct file permissions
$stat = stat(dirname($webpfile));
$perms = $stat['mode'] & 0666;
//same permissions as parent folder, strip off the executable bits
@chmod($webpfile, $perms);
}
ewwwio_memory(__FUNCTION__);
}
开发者ID:kanei,项目名称:vantuch.cz,代码行数:39,代码来源:ewww-image-optimizer.php
示例6: ewww_image_optimizer_custom_column
//.........这里部分代码省略.........
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>' . 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);
$class_type = 'gif';
$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;
default:
// not a supported mimetype
esc_html_e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
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));
}
} elseif (current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
// and give the user the option to optimize the image right now
printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_optimize&ewww_manual_nonce={$ewww_manual_nonce}&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
return;
}
// if the optimizer metadata exists
if (!empty($meta['ewww_image_optimizer'])) {
// output the optimizer results
echo esc_html($meta['ewww_image_optimizer']);
// output the filesize
echo "<br>" . sprintf(esc_html__('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_manual_nonce={$ewww_manual_nonce}&ewww_force=1&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('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_manual_nonce={$ewww_manual_nonce}&ewww_attachment_ID={$id}&ewww_convert=1&ewww_force=1'>{$convert_link}</a>";
}
} else {
echo $msg;
}
$restorable = false;
if (!empty($meta['converted'])) {
if (!empty($meta['orig_file']) && file_exists($meta['orig_file'])) {
$restorable = true;
}
}
if (isset($meta['sizes'])) {
// meta sizes don't contain a path, so we calculate one
$base_dir = trailingslashit(dirname($file_path));
foreach ($meta['sizes'] as $size => $data) {
if (!empty($data['converted'])) {
if (!empty($data['orig_file']) && file_exists($base_dir . $data['orig_file'])) {
$restorable = true;
}
}
}
}
if ($restorable && current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_restore&ewww_manual_nonce={$ewww_manual_nonce}&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Restore original', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
// link to webp upgrade script
$oldwebpfile = preg_replace('/\\.\\w+$/', '.webp', $file_path);
if (file_exists($oldwebpfile) && current_user_can(apply_filters('ewww_image_optimizer_admin_permissions', ''))) {
echo "<br><a href='options.php?page=ewww-image-optimizer-webp-migrate'>" . esc_html__('Run WebP upgrade', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a>";
}
// determine filepath for webp
$webpfile = $file_path . '.webp';
$webp_size = ewww_image_optimizer_filesize($webpfile);
if ($webp_size) {
$webp_size = size_format($webp_size, 2);
$webpurl = esc_url(wp_get_attachment_url($id) . '.webp');
// get a human readable filesize
$webp_size = preg_replace('/\\.00 B /', ' B', $webp_size);
echo "<br>WebP: <a href='{$webpurl}'>{$webp_size}</a>";
}
} else {
// otherwise, this must be an image we haven't processed
esc_html_e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
// tell them the filesize
echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
if (empty($msg) && current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
// and give the user the option to optimize the image right now
printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_optimize&ewww_manual_nonce={$ewww_manual_nonce}&ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Optimize now!', 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_manual_nonce={$ewww_manual_nonce}&ewww_attachment_ID={$id}&ewww_convert=1&ewww_force=1'>{$convert_link}</a>";
}
} else {
echo $msg;
}
}
}
ewwwio_memory(__FUNCTION__);
}
开发者ID:amprog,项目名称:ewww-image-optimizer,代码行数:101,代码来源:common.php
示例7: ewww_image_optimizer_aux_images_script
function ewww_image_optimizer_aux_images_script($hook)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
// make sure we are being called from the proper page
if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) {
return;
}
session_write_close();
global $wpdb;
if (!empty($_REQUEST['ewww_force'])) {
ewwwio_debug_message('forcing re-optimize: true');
}
// initialize the $attachments variable for auxiliary images
$attachments = null;
// check the 'bulk resume' option
$resume = get_option('ewww_image_optimizer_aux_resume');
// check if there is a previous bulk operation to resume
if (!empty($resume)) {
ewwwio_debug_message('resuming from where we left off, no scanning needed');
// retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
$attachments = get_option('ewww_image_optimizer_aux_attachments');
} else {
ewwwio_debug_message('getting fresh list of files to optimize');
$attachments = array();
// collect a list of images from the current theme
$child_path = get_stylesheet_directory();
$parent_path = get_template_directory();
$attachments = ewww_image_optimizer_image_scan($child_path);
if ($child_path !== $parent_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
}
if (!function_exists('is_plugin_active')) {
// need to include the plugin library for the is_plugin_active function
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// collect a list of images for buddypress
if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
}
if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
}
if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) {
// scan the grand media folder for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
}
if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
}
if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) {
$slide_paths = array();
$slides = $wpdb->get_col("\n\t\t\t\tSELECT wpposts.ID \n\t\t\t\tFROM {$wpdb->posts} wpposts \n\t\t\t\tINNER JOIN {$wpdb->term_relationships} term_relationships\n\t\t\t\t\t\tON wpposts.ID = term_relationships.object_id\n\t\t\t\tINNER JOIN {$wpdb->terms} wpterms \n\t\t\t\t\t\tON term_relationships.term_taxonomy_id = wpterms.term_id\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} term_taxonomy\n\t\t\t\t\t\tON wpterms.term_id = term_taxonomy.term_id\n\t\t\t\tWHERE \tterm_taxonomy.taxonomy = 'ml-slider'\n\t\t\t\t\tAND wpposts.post_type = 'attachment'\n\t\t\t\t");
foreach ($slides as $slide) {
$backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
$type = get_post_meta($slide, 'ml-slider_type', true);
$type = $type ? $type : 'image';
// backwards compatibility, fall back to 'image'
if ($type === 'image') {
foreach ($backup_sizes as $backup_size => $meta) {
if (preg_match('/resized-/', $backup_size)) {
$path = $meta['path'];
$image_size = ewww_image_optimizer_filesize($path);
if (!$image_size) {
continue;
}
$already_optimized = ewww_image_optimizer_find_already_optimized($path);
$mimetype = ewww_image_optimizer_mimetype($path, 'i');
if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
$slide_paths[] = $path;
}
}
}
}
}
$attachments = array_merge($attachments, $slide_paths);
}
// collect a list of images in auxiliary folders provided by user
if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
foreach ($aux_paths as $aux_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
}
}
// scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization
if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) {
// retrieve the location of the wordpress upload folder
$upload_dir = wp_upload_dir();
// retrieve the path of the upload folder
$upload_path = $upload_dir['basedir'];
$this_month = date('m');
$this_year = date('Y');
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/"));
if (class_exists('DateTime')) {
$date = new DateTime();
$date->sub(new DateInterval('P1M'));
//.........这里部分代码省略.........
开发者ID:kanei,项目名称:vantuch.cz,代码行数:101,代码来源:aux-optimize.php
示例8: ewww_manage_image_custom_column
function ewww_manage_image_custom_column( $column_name, $id ) {
// once we've found our custom column
if( $column_name == 'ewww_image_optimizer' ) {
// get the metadata for the image
$meta = new nggMeta( $id );
// get the optimization status for the image
$status = $meta->get_META( 'ewww_image_optimizer' );
$msg = '';
// get the file path of the image
$file_path = $meta->image->imagePath;
// get the mimetype of the image
$type = ewww_image_optimizer_mimetype($file_path, 'i');
// retrieve the human-readable filesize of the image
$file_size = size_format( ewww_image_optimizer_filesize( $file_path ), 2 );
$file_size = str_replace( 'B ', 'B', $file_size );
$valid = true;
// check to see if we have a tool to handle the mimetype detected
$skip = ewww_image_optimizer_skip_tools();
switch ( $type ) {
case 'image/jpeg':
// if jpegtran is missing, tell the user
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() ) );
}
break;
case 'image/png':
// if the PNG tools 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() ) );
}
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() ) );
}
break;
default:
$valid = false;
}
// file isn't in a format we can work with, we don't work with strangers
if ( $valid == false ) {
echo esc_html__( 'Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN ) . $msg;
return;
}
$ewww_manual_nonce = wp_create_nonce( "ewww-manual-" . $id );
// if we have a valid status, display it, the image size, and give a re-optimize link
if ( ! empty ( $status ) ) {
echo esc_html( $status );
echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
if ( current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
printf("<br><a href=\"admin.php?action=ewww_ngg_manual&ewww_manual_nonce=$ewww_manual_nonce&ewww_force=1&ewww_attachment_ID=%d\">%s</a>",
$id,
esc_html__('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
} elseif ( get_transient( 'ewwwio-background-in-progress-ngg-' . $id ) ) {
esc_html_e( 'In Progress', EWWW_IMAGE_OPTIMIZER_DOMAIN );
// otherwise, give the image size, and a link to optimize right now
} else {
esc_html_e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
if ( current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
printf("<br><a href=\"admin.php?action=ewww_ngg_manual&ewww_manual_nonce=$ewww_manual_nonce&ewww_attachment_ID=%d\">%s</a>",
$id,
esc_html__('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
}
}
}
开发者ID:recetasdemama,项目名称:wordpress,代码行数:72,代码来源:nextcellent-integration.php
示例9: ewww_image_optimizer
//.........这里部分代码省略.........
// if the optimization didn't produce a smaller JPG
} else {
if (is_file($tempfile)) {
// delete the optimized file
unlink($tempfile);
}
// store the results
$result = 'unchanged';
$new_size = $orig_size;
}
// if conversion and optimization are both turned OFF, finish the JPG processing
} elseif (!$convert) {
ewww_image_optimizer_webp_create($file, $orig_size, $type, $tools['WEBP']);
break;
}
// if the conversion process is turned ON, or if this is a resize and the full-size was converted
if ($convert && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
ewwwio_debug_message("attempting to convert JPG to PNG: {$pngfile}");
if (empty($new_size)) {
$new_size = $orig_size;
}
// retrieve version info for ImageMagick
$convert_path = ewww_image_optimizer_find_binary('convert', 'i');
// convert the JPG to PNG
if (ewww_image_optimizer_gmagick_support()) {
try {
$gmagick = new Gmagick($file);
$gmagick->stripimage();
$gmagick->setimageformat('PNG');
$gmagick->writeimage($pngfile);
} catch (Exception $gmagick_error) {
ewwwio_debug_message($gmagick_error->getMessage());
}
$png_size = ewww_image_optimizer_filesize($pngfile);
}
if (!$png_size && ewww_image_optimizer_imagick_support()) {
try {
$imagick = new Imagick($file);
$imagick->stripImage();
$imagick->setImageFormat('PNG');
$imagick->writeImage($pngfile);
} catch (Exception $imagick_error) {
ewwwio_debug_message($imagick_error->getMessage());
}
$png_size = ewww_image_optimizer_filesize($pngfile);
}
if (!$png_size && !empty($convert_path)) {
ewwwio_debug_message('converting with ImageMagick');
exec($convert_path . " " . ewww_image_optimizer_escapeshellarg($file) . " -strip " . ewww_image_optimizer_escapeshellarg($pngfile));
$png_size = ewww_image_optimizer_filesize($pngfile);
}
if (!$png_size && ewww_image_optimizer_gd_support()) {
ewwwio_debug_message('converting with GD');
imagepng(imagecreatefromjpeg($file), $pngfile);
$png_size = ewww_image_optimizer_filesize($pngfile);
}
// if lossy optimization is ON and full-size exclusion is not active
if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') && $tools['PNGQUANT'] && !$skip_lossy) {
ewwwio_debug_message('attempting lossy reduction');
exec("{$nice} " . $tools['PNGQUANT'] . " " . ewww_image_optimizer_escapeshellarg($pngfile));
$quantfile = preg_replace('/\\.\\w+$/', '-fs8.png', $pngfile);
if (file_exists($quantfile) && filesize($pngfile) > filesize($quantfile)) {
ewwwio_debug_message("lossy reduction is better: original - " . filesize($pngfile) . " vs. lossy - " . filesize($quantfile));
rename($quantfile, $pngfile);
} elseif (file_exists($quantfile)) {
ewwwio_debug_message("lossy reduction is worse: original - " . filesize($pngfile) . " vs. lossy - " . filesize($quantfile));
开发者ID:crazyyy,项目名称:octagram,代码行数:67,代码来源:ewww-image-optimizer.php
示例10: ewww_image_optimizer_aux_images_script
function ewww_image_optimizer_aux_images_script($hook)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
// make sure we are being called from the proper page
if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) {
return;
}
global $wpdb;
if (!empty($_REQUEST['ewww_force'])) {
ewwwio_debug_message('forcing re-optimize: true');
}
// initialize the $attachments variable for auxiliary images
$attachments = null;
// check the 'bulk resume' option
$resume = get_option('ewww_image_optimizer_aux_resume');
// check if there is a previous bulk operation to resume
if (!empty($resume)) {
// retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
$attachments = get_option('ewww_image_optimizer_aux_attachments');
} else {
$attachments = array();
// collect a list of images from the current theme
$child_path = get_stylesheet_directory();
$parent_path = get_template_directory();
$attachments = ewww_image_optimizer_image_scan($child_path);
if ($child_path !== $parent_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
}
if (!function_exists('is_plugin_active')) {
// need to include the plugin library for the is_plugin_active function
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// collect a list of images for buddypress
if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
}
if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
}
if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) {
// scan the grand media folder for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
}
if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
}
if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) {
$slide_paths = array();
$sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids'));
foreach ($sliders as $slider) {
$slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider))));
foreach ($slides as $slide) {
$backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
$type = get_post_meta($slide, 'ml-slider_type', true);
$type = $type ? $type : 'image';
// backwards compatibility, fall back to 'image'
if ($type === 'image') {
foreach ($backup_sizes as $backup_size => $meta) {
if (preg_match('/resized-/', $backup_size)) {
$path = $meta['path'];
$image_size = ewww_image_optimizer_filesize($path);
if (!$image_size) {
continue;
}
$query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE path LIKE %s AND image_size LIKE '{$image_size}'", $path);
$optimized_query = $wpdb->get_results($query, ARRAY_A);
if (!empty($optimized_query)) {
foreach ($optimized_query as $image) {
if ($image['path'] != $path) {
ewwwio_debug_message("{$image['path']} does not match {$path}, continuing our search");
} else {
$already_optimized = $image;
}
}
}
$mimetype = ewww_image_optimizer_mimetype($path, 'i');
if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
$slide_paths[] = $path;
}
}
}
}
}
}
$attachments = array_merge($attachments, $slide_paths);
}
// collect a list of images in auxiliary folders provided by user
if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
foreach ($aux_paths as $aux_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
}
}
// scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization
if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) {
//.........这里部分代码省略.........
开发者ID:ashenkar,项目名称:sanga,代码行数:101,代码来源:aux-optimize.php
示例11: ewww_image_optimizer_scan_other
function ewww_image_optimizer_scan_other()
{
global $wpdb;
// $aux_resume = get_option('ewww_image_optimizer_aux_resume');
// initialize the $attachments variable for auxiliary images
$attachments = null;
// check the 'bulk resume' option
// $resume = get_option('ewww_image_optimizer_aux_resume');
// check if there is a previous bulk operation to resume
if (get_option('ewww_image_optimizer_aux_resume')) {
// retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
$attachments = get_option('ewww_image_optimizer_aux_attachments');
} else {
// collect a list of images from the current theme
$child_path = get_stylesheet_directory();
$parent_path = get_template_directory();
$attachments = ewww_image_optimizer_image_scan($child_path);
if ($child_path !== $parent_path) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
}
// collect a list of images for buddypress
if (!function_exists('is_plugin_active')) {
// need to include the plugin library for the is_plugin_active function
ewww_image_optimizer_require(ABSPATH . 'wp-admin/includes/plugin.php');
}
if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
}
if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
// get the value of the wordpress upload directory
$upload_dir = wp_upload_dir();
// scan the 'avatars' and 'group-avatars' folders for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
}
if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) {
// scan the grand media folder for images
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
}
if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
$attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
}
if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) {
$slide_paths = array();
$sliders = get_posts(array('numberposts' => -1, 'post_t
|
请发表评论