本文整理汇总了PHP中ewww_image_optimizer_mimetype函数的典型用法代码示例。如果您正苦于以下问题:PHP ewww_image_optimizer_mimetype函数的具体用法?PHP ewww_image_optimizer_mimetype怎么用?PHP ewww_image_optimizer_mimetype使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ewww_image_optimizer_mimetype函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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
示例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' || $column_name == '') {
$output = '';
// 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');
if (is_object($id)) {
$image = $id;
} else {
// get an image object
$image = $storage->object->_image_mapper->find($id);
}
if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
$print_meta = print_r($image->meta_data, TRUE);
$print_meta = preg_replace(array('/ /', '/\\n+/'), array(' ', '<br />'), esc_html($print_meta));
$output .= '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
}
$msg = '';
// get the absolute path
$file_path = $storage->get_image_abspath($image, 'full');
// 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
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>' . 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 && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png')) {
$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 && !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()));
}
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;
}
// if we have a valid status, display it
if (!empty($image->meta_data['ewww_image_optimizer'])) {
$output .= esc_html($image->meta_data['ewww_image_optimizer']);
// otherwise, give the image size, and a link to optimize right now
} else {
$output .= esc_html__('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
}
// display the image size
$output .= "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size) . "<br>";
// display the optimization link with the appropriate text
$output .= $this->ewww_render_optimize_action_link($id, $image);
if (is_object($id)) {
return $output;
} else {
echo $output;
}
}
}
开发者ID:agiper,项目名称:wordpress,代码行数:78,代码来源:nextgen2-integration.php
示例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)
{
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;
}
//.........这里部分代码省略.........
开发者ID:goodbayscott,项目名称:wwr-temp,代码行数:101,代码来源:common.php
示例4: 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 />'), $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
$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(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
switch ($type) {
case 'image/jpeg':
if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
$valid = false;
$msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>');
}
break;
case 'image/png':
if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
$valid = false;
$msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>');
}
break;
case 'image/gif':
if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
$valid = false;
$msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>');
}
break;
default:
$valid = false;
}
// let user know if the file type is unsupported
if ($valid == false) {
_e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return;
}
// output the image status if we know it
if (!empty($status)) {
echo $status;
echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
printf("<br><a href=\"admin.php?action=ewww_flag_manual&force=1&attachment_ID=%d\">%s</a>", $id, __('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
// otherwise, tell the user that they can optimize the image 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_flag_manual&attachment_ID=%d\">%s</a>", $id, __('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
}
}
开发者ID:LacieNat,项目名称:Access-Comm-Project,代码行数:63,代码来源:flag-integration.php
示例5: 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
示例6: ewww_image_optimizer
/**
* Process an image.
*
* Returns an array of the $file, $results, $converted to tell us if an image changes formats, and the $original file if it did.
*
* @param string $file Full absolute path to the image file
* @param int $gallery_type 1=wordpress, 2=nextgen, 3=flagallery, 4=aux_images, 5=image editor, 6=imagestore, 7=retina
* @param boolean $converted tells us if this is a resize and the full image was converted to a new format
* @returns array
*/
function ewww_image_optimizer($file, $gallery_type, $converted, $new, $fullsize = false)
{
// global $wpdb;
global $ewww_debug;
$ewww_debug .= "<b>ewww_image_optimizer()</b><br>";
// if the plugin gets here without initializing, we need to run through some things first
if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
ewww_image_optimizer_init();
}
// initialize the original filename
$original = $file;
$result = '';
// check that the file exists
if (FALSE === file_exists($file)) {
// tell the user we couldn't find the file
$msg = sprintf(__("Could not find <span class='code'>%s</span>", EWWW_IMAGE_OPTIMIZER_DOMAIN), $file);
$ewww_debug .= "file doesn't appear to exist: {$file} <br>";
// send back the above message
return array(false, $msg, $converted, $original);
}
// check that the file is writable
if (FALSE === is_writable($file)) {
// tell the user we can't write to the file
$msg = sprintf(__("<span class='code'>%s</span> is not writable", EWWW_IMAGE_OPTIMIZER_DOMAIN), $file);
$ewww_debug .= "couldn't write to the file<br>";
// send back the above message
return array(false, $msg, $converted, $original);
}
if (function_exists('fileperms')) {
$file_perms = substr(sprintf('%o', fileperms($file)), -4);
}
$file_owner = 'unknown';
$file_group = 'unknown';
if (function_exists('posix_getpwuid')) {
$file_owner = posix_getpwuid(fileowner($file));
$file_owner = $file_owner['name'];
}
if (function_exists('posix_getgrgid')) {
$file_group = posix_getgrgid(filegroup($file));
$file_group = $file_group['name'];
}
$ewww_debug .= "permissions: {$file_perms}, owner: {$file_owner}, group: {$file_group} <br>";
$type = ewww_image_optimizer_mimetype($file, 'i');
if (!$type) {
//otherwise we store an error message since we couldn't get the mime-type
$msg = __('Missing finfo_file(), getimagesize() and mime_content_type() PHP functions', EWWW_IMAGE_OPTIMIZER_DOMAIN);
$ewww_debug .= "couldn't find any functions for mimetype detection<br>";
return array(false, $msg, $converted, $original);
}
if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
// check to see if 'nice' exists
$nice = ewww_image_optimizer_find_binary('nice', 'n');
}
// if the user has disabled the utility checks
if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_check') == TRUE || EWWW_IMAGE_OPTIMIZER_CLOUD) {
$skip_jpegtran_check = true;
$skip_optipng_check = true;
$skip_gifsicle_check = true;
$skip_pngout_check = true;
} else {
// otherwise we set the variables to false
$skip_jpegtran_check = false;
$skip_optipng_check = false;
$skip_gifsicle_check = false;
$skip_pngout_check = false;
}
if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
$skip_jpegtran_check = true;
}
if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png')) {
$skip_optipng_check = true;
$skip_pngout_check = true;
}
if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif')) {
$skip_gifsicle_check = true;
}
// if the full-size image was converted
if ($converted) {
$ewww_debug .= "full-size image was converted, need to rebuild filename for meta<br>";
$filenum = $converted;
// grab the file extension
preg_match('/\\.\\w+$/', $file, $fileext);
// strip the file extension
$filename = str_replace($fileext[0], '', $file);
// grab the dimensions
preg_match('/-\\d+x\\d+(-\\d+)*$/', $filename, $fileresize);
// strip the dimensions
$filename = str_replace($fileresize[0], '', $filename);
// reconstruct the filename with the same increment (stored in $converted) as the full version
$refile = $filename . '-' . $filenum . $fileresize[0] . $fileext[0];
//.........这里部分代码省略.........
开发者ID:LacieNat,项目名称:Access-Comm-Project,代码行数:101,代码来源:ewww-image-optimizer.php
示例7: 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
示例8: 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
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 = 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 = filesize($path);
$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) {
// $ewww_debug .= "{$image['path']} does not match $path, continuing our search<br>";
$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));
}
}
// 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);
}
return $attachments;
}
开发者ID:crazyyy,项目名称:smartmagel,代码行数:91,代码来源:iocli.php
示例9: ewww_image_optimizer
/**
* Process an image.
*
* Returns an array of the $file, $results, $converted to tell us if an image changes formats, and the $original file if it did.
*
* @param string $file Full absolute path to the image file
* @param int $gallery_type 1=wordpress, 2=nextgen, 3=flagallery, 4=aux_images, 5=image editor, 6=imagestore
* @param boolean $converted tells us if this is a resize and the full image was converted to a new format
* @param boolean $new tells the optimizer that this is a new image, so it should attempt conversion regardless of previous results
* @param boolean $fullsize tells the optimizer this is a full size image
* @returns array
*/
function ewww_image_optimizer($file, $gallery_type = 4, $converted = false, $new = false, $fullsize = false)
{
ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
// if the plugin gets here without initializing, we need to run through some things first
if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
ewww_image_optimizer_cloud_init();
}
session_write_close();
$bypass_optimization = apply_filters('ewww_image_optimizer_bypass', false, $file);
if (true === $bypass_optimization) {
// tell the user optimization was skipped
$msg = __("Optimization skipped", EWWW_IMAGE_OPTIMIZER_DOMAIN);
ewwwio_debug_message("optimization bypassed: {$file}");
// send back the above message
return array(false, $msg, $converted, $file);
}
// initialize the original filename
$original = $file;
$result = '';
// check that the file exists
if (FALSE === file_exists($file)) {
// tell the user we couldn't find the file
$msg = sprintf(__('Could not find %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file);
ewwwio_debug_message("file doesn't appear to exist: {$file}");
// send back the above message
return array(false, $msg, $converted, $original);
}
// check that the file is writable
if (FALSE === is_writable($file)) {
// tell the user we can't write to the file
$msg = sprintf(__('%s is not writable', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file);
ewwwio_debug_message("couldn't write to the file {$file}");
// send back the above message
return array(false, $msg, $converted, $original);
}
if (function_exists('fileperms')) {
$file_perms = substr(sprintf('%o', fileperms($file)), -4);
}
$file_owner = 'unknown';
$file_group = 'unknown';
if (function_exists('posix_getpwuid')) {
$file_owner = posix_getpwuid(fileowner($file));
$file_owner = $file_owner['name'];
}
if (function_exists('posix_getgrgid')) {
$file_group = posix_getgrgid(filegroup($file));
$file_group = $file_group['name'];
}
ewwwio_debug_message("permissions: {$file_perms}, owner: {$file_owner}, group: {$file_group}");
$type = ewww_image_optimizer_mimetype($file, 'i');
if (strpos($type, 'image') === FALSE && strpos($type, 'pdf') === FALSE) {
ewwwio_debug_message('could not find any functions for mimetype detection');
//otherwise we store an error message since we couldn't get the mime-type
return array(false, __('Unknown type: ' . $type, EWWW_IMAGE_OPTIMIZER_DOMAIN), $converted, $original);
$msg = __('Missing finfo_file(), getimagesize() and mime_content_type() PHP functions', EWWW_IMAGE_OPTIMIZER_DOMAIN);
return array(false, $msg, $converted, $original);
}
if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
// check to see if 'nice' exists
$nice = ewww_image_optimizer_find_nix_binary('nice', 'n');
if (!defined('EWWW_IMAGE_OPTIMIZER_NOEXEC')) {
// Check if exec is disabled
if (ewww_image_optimizer_exec_check()) {
define('EWWW_IMAGE_OPTIMIZER_NOEXEC', true);
ewwwio_debug_message('exec seems to be disabled');
ewww_image_optimizer_disable_tools();
// otherwise, query the php settings for safe mode
} elseif (ewww_image_optimizer_safemode_check()) {
define('EWWW_IMAGE_OPTIMIZER_NOEXEC', true);
ewwwio_debug_message('safe mode appears to be enabled');
ewww_image_optimizer_disable_tools();
} else {
define('EWWW_IMAGE_OPTIMIZER_NOEXEC', false);
}
}
}
$skip = ewww_image_optimizer_skip_tools();
// if the user has disabled the utility checks
if (EWWW_IMAGE_OPTIMIZER_CLOUD) {
$skip['jpegtran'] = true;
$skip['optipng'] = true;
$skip['gifsicle'] = true;
$skip['pngout'] = true;
$skip['pngquant'] = true;
$skip['webp'] = true;
}
if (ewww_image_optimizer_get_option('ewww_image_optimizer_metadata_skip_full') && $fullsize) {
$keep_metadata = true;
//.........这里部分代码省略.........
开发者ID:kanei,项目名称:vantuch.cz,代码行数:101,代码来源: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;
}
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['b
|
请发表评论