first commit
This commit is contained in:
107
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/bulk.php
vendored
Normal file
107
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/bulk.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
add_filter( 'imagify_bulk_page_types', 'imagify_ngg_bulk_page_types' );
|
||||
/**
|
||||
* Filter the types to display in the bulk optimization page.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param array $types The folder types displayed on the page. If a folder type is "library", the context should be suffixed after a pipe character. They are passed as array keys.
|
||||
* @return array
|
||||
*/
|
||||
function imagify_ngg_bulk_page_types( $types ) {
|
||||
if ( ! empty( $_GET['page'] ) && imagify_get_ngg_bulk_screen_slug() === $_GET['page'] ) { // WPCS: CSRF ok.
|
||||
$types['library|ngg'] = 1;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
add_filter( 'imagify_bulk_stats', 'imagify_ngg_bulk_stats', 10, 2 );
|
||||
/**
|
||||
* Filter the generic stats used in the bulk optimization page.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param array $data The data.
|
||||
* @param array $types The folder types. They are passed as array keys.
|
||||
* @return array
|
||||
*/
|
||||
function imagify_ngg_bulk_stats( $data, $types ) {
|
||||
if ( ! isset( $types['library|ngg'] ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
add_filter( 'imagify_count_saving_data', 'imagify_ngg_count_saving_data', 8 );
|
||||
$total_saving_data = imagify_count_saving_data();
|
||||
remove_filter( 'imagify_count_saving_data', 'imagify_ngg_count_saving_data', 8 );
|
||||
|
||||
// Global chart.
|
||||
$data['total_attachments'] += imagify_ngg_count_attachments();
|
||||
$data['unoptimized_attachments'] += imagify_ngg_count_unoptimized_attachments();
|
||||
$data['optimized_attachments'] += imagify_ngg_count_optimized_attachments();
|
||||
$data['errors_attachments'] += imagify_ngg_count_error_attachments();
|
||||
// Stats block.
|
||||
$data['already_optimized_attachments'] += $total_saving_data['count'];
|
||||
$data['original_human'] += $total_saving_data['original_size'];
|
||||
$data['optimized_human'] += $total_saving_data['optimized_size'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
add_filter( 'imagify_bulk_page_data', 'imagify_ngg_bulk_page_data', 10, 2 );
|
||||
/**
|
||||
* Filter the data to use on the bulk optimization page.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7.1 Added the $types parameter.
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param array $data The data to use.
|
||||
* @param array $types The folder types displayed on the page. They are passed as array keys.
|
||||
* @return array
|
||||
*/
|
||||
function imagify_ngg_bulk_page_data( $data, $types ) {
|
||||
if ( ! isset( $types['library|ngg'] ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Limits.
|
||||
$data['unoptimized_attachment_limit'] += imagify_get_unoptimized_attachment_limit();
|
||||
// Group.
|
||||
$data['groups']['ngg'] = array(
|
||||
/**
|
||||
* The group_id corresponds to the file names like 'part-bulk-optimization-results-row-{$group_id}'.
|
||||
* It is also used in get_imagify_localize_script_translations().
|
||||
*/
|
||||
'group_id' => 'library',
|
||||
'context' => 'ngg',
|
||||
'title' => __( 'NextGen Galleries', 'imagify' ),
|
||||
/* translators: 1 is the opening of a link, 2 is the closing of this link. */
|
||||
'footer' => sprintf( __( 'You can also re-optimize your images more finely directly in each %1$sgallery%2$s.', 'imagify' ), '<a href="' . esc_url( admin_url( 'admin.php?page=nggallery-manage-gallery' ) ) . '">', '</a>' ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
add_filter( 'imagify_optimization_errors_url', 'imagify_ngg_optimization_errors_url', 10, 2 );
|
||||
/**
|
||||
* Provide a URL to a page displaying optimization errors for the NGG context.
|
||||
*
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param string $url The URL.
|
||||
* @param string $context The context.
|
||||
* @return string
|
||||
*/
|
||||
function imagify_ngg_optimization_errors_url( $url, $context ) {
|
||||
if ( 'ngg' === $context ) {
|
||||
return admin_url( 'admin.php?page=nggallery-manage-gallery' );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
45
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/enqueue.php
vendored
Normal file
45
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/enqueue.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
add_action( 'imagify_assets_enqueued', '_imagify_ngg_admin_print_styles' );
|
||||
/**
|
||||
* Add some CSS and JS for NGG compatibility.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6.10 Use the new class Imagify_Assets.
|
||||
* @author Jonathan Buttigieg
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
function _imagify_ngg_admin_print_styles() {
|
||||
$assets = Imagify_Assets::get_instance();
|
||||
|
||||
/**
|
||||
* Manage Gallery Images.
|
||||
*/
|
||||
if ( imagify_is_screen( 'nggallery-manage-images' ) || isset( $_GET['gid'] ) && ! empty( $_GET['pid'] ) && imagify_is_screen( 'nggallery-manage-gallery' ) ) { // WPCS: CSRF ok.
|
||||
$assets->enqueue_style( 'admin' )->enqueue_script( 'library' );
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* NGG Bulk Optimization.
|
||||
*/
|
||||
$bulk_screen_id = imagify_get_ngg_bulk_screen_id();
|
||||
|
||||
if ( ! imagify_is_screen( $bulk_screen_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assets->remove_deferred_localization( 'bulk', 'imagifyBulk' );
|
||||
|
||||
$l10n = $assets->get_localization_data( 'bulk', [
|
||||
'bufferSizes' => [
|
||||
'ngg' => 4,
|
||||
],
|
||||
] );
|
||||
|
||||
/** This filter is documented in inc/functions/i18n.php */
|
||||
$l10n['bufferSizes'] = apply_filters( 'imagify_bulk_buffer_sizes', $l10n['bufferSizes'] );
|
||||
|
||||
$assets->enqueue_assets( [ 'pricing-modal', 'bulk' ] )->localize( 'imagifyBulk', $l10n );
|
||||
}
|
||||
64
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/gallery.php
vendored
Normal file
64
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/gallery.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
add_filter( 'ngg_manage_images_number_of_columns', '_imagify_ngg_manage_images_number_of_columns' );
|
||||
/**
|
||||
* Add "Imagify" column in admin.php?page=nggallery-manage-gallery.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @param int $count Number of columns.
|
||||
* @return int Incremented number of columns.
|
||||
*/
|
||||
function _imagify_ngg_manage_images_number_of_columns( $count ) {
|
||||
$count++;
|
||||
add_filter( 'ngg_manage_images_column_' . $count . '_header', '_imagify_ngg_manage_media_columns' );
|
||||
add_filter( 'ngg_manage_images_column_' . $count . '_content', '_imagify_ngg_manage_media_custom_column', 10, 2 );
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column title.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _imagify_ngg_manage_media_columns() {
|
||||
return 'Imagify';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column content.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @param string $output The column content.
|
||||
* @param object $image An NGG Image object.
|
||||
* @return string
|
||||
*/
|
||||
function _imagify_ngg_manage_media_custom_column( $output, $image ) {
|
||||
$process = imagify_get_optimization_process( $image, 'ngg' );
|
||||
|
||||
return get_imagify_media_column_content( $process );
|
||||
}
|
||||
|
||||
add_filter( 'imagify_display_missing_thumbnails_link', '_imagify_ngg_hide_missing_thumbnails_link', 10, 3 );
|
||||
/**
|
||||
* Hide the "Optimize missing thumbnails" link.
|
||||
*
|
||||
* @since 1.6.10
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param bool $display True to display the link. False to not display it.
|
||||
* @param object $attachment The attachement object.
|
||||
* @param string $context The context.
|
||||
* @return bool
|
||||
*/
|
||||
function _imagify_ngg_hide_missing_thumbnails_link( $display, $attachment, $context ) {
|
||||
return 'ngg' === $context ? false : $display;
|
||||
}
|
||||
19
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/menu.php
vendored
Normal file
19
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/admin/menu.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
add_action( 'admin_menu', '_imagify_ngg_bulk_optimization_menu' );
|
||||
/**
|
||||
* Add submenu in menu "Media"
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*/
|
||||
function _imagify_ngg_bulk_optimization_menu() {
|
||||
if ( ! defined( 'NGGFOLDER' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$capacity = imagify_get_context( 'ngg' )->get_capacity( 'bulk-optimize' );
|
||||
|
||||
add_submenu_page( NGGFOLDER, __( 'Bulk Optimization', 'imagify' ), __( 'Bulk Optimization', 'imagify' ), $capacity, imagify_get_ngg_bulk_screen_slug(), '_imagify_display_bulk_page' );
|
||||
}
|
||||
329
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/common/attachments.php
vendored
Normal file
329
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/common/attachments.php
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
use \Imagify\Optimization\File;
|
||||
use \Imagify\ThirdParty\NGG;
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
add_action( 'ngg_after_new_images_added', '_imagify_ngg_optimize_attachment', IMAGIFY_INT_MAX, 2 );
|
||||
/**
|
||||
* Auto-optimize when a new attachment is added to the database (NGG plugin's table), except for images imported from the library.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @param int $gallery_id A Gallery ID.
|
||||
* @param array $image_ids An array of Ids or objects. Ids which are sucessfully added.
|
||||
*/
|
||||
function _imagify_ngg_optimize_attachment( $gallery_id, $image_ids ) {
|
||||
|
||||
if ( ! Imagify_Requirements::is_api_key_valid() || ! get_imagify_option( 'auto_optimize' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$is_maybe_library_import = ! empty( $_POST['action'] ) && 'import_media_library' === $_POST['action'] && ! empty( $_POST['attachment_ids'] ) && is_array( $_POST['attachment_ids'] ); // WPCS: CSRF ok.
|
||||
|
||||
if ( $is_maybe_library_import && ! empty( $_POST['nextgen_upload_image_sec'] ) ) { // WPCS: CSRF ok.
|
||||
/**
|
||||
* The images are imported from the library.
|
||||
* In this case, those images are dealt with in _imagify_ngg_media_library_imported_image_data().
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $is_maybe_library_import && ( ! empty( $_POST['gallery_id'] ) || ! empty( $_POST['gallery_name'] ) ) ) { // WPCS: CSRF ok.
|
||||
/**
|
||||
* Same thing but for NGG 2.0 probably.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $image_ids as $image ) {
|
||||
if ( is_numeric( $image ) ) {
|
||||
$image_id = (int) $image;
|
||||
} elseif ( is_object( $image ) && ! empty( $image->pid ) ) {
|
||||
$image_id = (int) $image->pid;
|
||||
} else {
|
||||
$image_id = 0;
|
||||
}
|
||||
|
||||
if ( ! $image_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow to prevent automatic optimization for a specific NGG gallery image.
|
||||
*
|
||||
* @since 1.6.12
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param bool $optimize True to optimize, false otherwise.
|
||||
* @param int $image_id Image ID.
|
||||
* @param int $gallery_id Gallery ID.
|
||||
*/
|
||||
$optimize = apply_filters( 'imagify_auto_optimize_ngg_gallery_image', true, $image_id, $gallery_id );
|
||||
|
||||
if ( ! $optimize ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$process = imagify_get_optimization_process( $image, 'ngg' );
|
||||
|
||||
if ( ! $process->is_valid() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $process->get_data()->get_optimization_status() ) {
|
||||
// Optimization already attempted.
|
||||
continue;
|
||||
}
|
||||
|
||||
$process->optimize();
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'ngg_medialibrary_imported_image', '_imagify_ngg_media_library_imported_image_data', 10, 2 );
|
||||
/**
|
||||
* Import Imagify data from a WordPress image to a new NGG image, and optimize the thumbnails.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @param object $image A NGG image object.
|
||||
* @param object $attachment An attachment object.
|
||||
* @return object
|
||||
*/
|
||||
function _imagify_ngg_media_library_imported_image_data( $image, $attachment ) {
|
||||
$wp_process = imagify_get_optimization_process( $attachment->ID, 'wp' );
|
||||
|
||||
if ( ! $wp_process->is_valid() || ! $wp_process->get_media()->is_supported() ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
$wp_data = $wp_process->get_data();
|
||||
|
||||
if ( ! $wp_data->is_optimized() ) {
|
||||
// The main image is not optimized.
|
||||
return $image;
|
||||
}
|
||||
|
||||
// Copy the full size data.
|
||||
$wp_full_size_data = $wp_data->get_size_data();
|
||||
$optimization_level = $wp_data->get_optimization_level();
|
||||
|
||||
NGG\DB::get_instance()->update( $image->pid, [
|
||||
'pid' => $image->pid,
|
||||
'optimization_level' => $optimization_level,
|
||||
'status' => $wp_data->get_optimization_status(),
|
||||
'data' => [
|
||||
'sizes' => [
|
||||
'full' => $wp_full_size_data,
|
||||
],
|
||||
'stats' => [
|
||||
'original_size' => $wp_full_size_data['original_size'],
|
||||
'optimized_size' => $wp_full_size_data['optimized_size'],
|
||||
'percent' => $wp_full_size_data['percent'],
|
||||
],
|
||||
],
|
||||
] );
|
||||
|
||||
$ngg_process = imagify_get_optimization_process( $image->pid, 'ngg' );
|
||||
|
||||
if ( ! $ngg_process->is_valid() ) {
|
||||
// WTF.
|
||||
return $image;
|
||||
}
|
||||
|
||||
// Copy the backup file (we don't want to backup the optimized file if it can be avoided).
|
||||
$ngg_media = $ngg_process->get_media();
|
||||
$wp_media = $wp_process->get_media();
|
||||
$wp_backup_path = $wp_media->get_backup_path();
|
||||
$filesystem = imagify_get_filesystem();
|
||||
$backup_copied = false;
|
||||
|
||||
if ( $wp_backup_path ) {
|
||||
$ngg_backup_path = $ngg_media->get_raw_backup_path();
|
||||
$backup_copied = $filesystem->copy( $wp_backup_path, $ngg_backup_path, true );
|
||||
|
||||
if ( $backup_copied ) {
|
||||
$filesystem->chmod_file( $ngg_backup_path );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WebP for the full size.
|
||||
* Look for an existing copy locally:
|
||||
* - if it exists, copy it (and its optimization data),
|
||||
* - if not, add it to the optimization queue.
|
||||
*/
|
||||
$add_full_webp = $wp_media->is_image() && get_imagify_option( 'convert_to_webp' );
|
||||
|
||||
if ( $add_full_webp ) {
|
||||
// It's a supported image and WebP conversion is enabled.
|
||||
$wp_full_path_webp = false;
|
||||
$webp_size_name = 'full' . $wp_process::WEBP_SUFFIX;
|
||||
$wp_webp_data = $wp_data->get_size_data( $webp_size_name );
|
||||
|
||||
// Get the path to the WebP image if it exists.
|
||||
$wp_full_path_webp = $wp_process->get_fullsize_file()->get_path_to_webp();
|
||||
|
||||
if ( $wp_full_path_webp && ! $filesystem->exists( $wp_full_path_webp ) ) {
|
||||
$wp_full_path_webp = false;
|
||||
}
|
||||
|
||||
if ( $wp_full_path_webp ) {
|
||||
// We know we have a WebP version. Make sure we have the right data.
|
||||
$wp_webp_data['success'] = true;
|
||||
|
||||
if ( empty( $wp_webp_data['original_size'] ) ) {
|
||||
// The WebP data is missing.
|
||||
$full_size_weight = $wp_full_size_data['original_size'];
|
||||
|
||||
if ( ! $full_size_weight && $wp_backup_path ) {
|
||||
// For some reason we don't have the original file weight, but we can get it from the backup file.
|
||||
$full_size_weight = $filesystem->size( $wp_backup_path );
|
||||
|
||||
if ( $full_size_weight ) {
|
||||
$wp_webp_data['original_size'] = $full_size_weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $wp_webp_data['original_size'] ) && empty( $wp_webp_data['optimized_size'] ) ) {
|
||||
// The WebP file size.
|
||||
$wp_webp_data['optimized_size'] = $filesystem->size( $wp_full_path_webp );
|
||||
}
|
||||
|
||||
if ( empty( $wp_webp_data['original_size'] ) || empty( $wp_webp_data['optimized_size'] ) ) {
|
||||
// We must have both original and optimized sizes.
|
||||
$wp_webp_data = [];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $wp_full_path_webp && $wp_webp_data ) {
|
||||
// We have the file and the data.
|
||||
// Copy the file.
|
||||
$ngg_full_file = new File( $ngg_media->get_raw_fullsize_path() );
|
||||
$ngg_full_path_webp = $ngg_full_file->get_path_to_webp(); // Destination.
|
||||
|
||||
if ( $ngg_full_path_webp ) {
|
||||
$copied = $filesystem->copy( $wp_full_path_webp, $ngg_full_path_webp, true );
|
||||
|
||||
if ( $copied ) {
|
||||
// Success.
|
||||
$filesystem->chmod_file( $ngg_full_path_webp );
|
||||
$add_full_webp = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $add_full_webp ) {
|
||||
// The WebP file has been successfully copied: now, copy the data.
|
||||
$ngg_process->get_data()->update_size_optimization_data( $webp_size_name, $wp_webp_data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Optimize thumbnails.
|
||||
$sizes = $ngg_media->get_media_files();
|
||||
unset( $sizes['full'] );
|
||||
|
||||
if ( $add_full_webp ) {
|
||||
// We could not use a local WebP copy: ask for a new one.
|
||||
$sizes[ $webp_size_name ] = [];
|
||||
}
|
||||
|
||||
if ( ! $sizes ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
$args = [
|
||||
'hook_suffix' => 'optimize_imported_images',
|
||||
];
|
||||
|
||||
$ngg_process->optimize_sizes( array_keys( $sizes ), $optimization_level, $args );
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
add_action( 'ngg_generated_image', 'imagify_ngg_maybe_add_dynamic_thumbnail_to_background_process', IMAGIFY_INT_MAX, 2 );
|
||||
/**
|
||||
* Add a dynamically generated thumbnail to the background process queue.
|
||||
* Note that this won’t work when images are imported (from WP Library or uploaded), since they are already being processed, and locked.
|
||||
*
|
||||
* @since 1.8
|
||||
* @since 1.9 Doesn't use the class Imagify_NGG_Dynamic_Thumbnails_Background_Process anymore.
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $image A NGG image object.
|
||||
* @param string $size The thumbnail size name.
|
||||
*/
|
||||
function imagify_ngg_maybe_add_dynamic_thumbnail_to_background_process( $image, $size ) {
|
||||
NGG\DynamicThumbnails::get_instance()->push_to_queue( $image, $size );
|
||||
}
|
||||
|
||||
add_action( 'ngg_delete_picture', 'imagify_ngg_cleanup_after_media_deletion', 10, 2 );
|
||||
/**
|
||||
* Delete everything when a NGG image is deleted.
|
||||
*
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param int $image_id The image ID.
|
||||
* @param object $image A NGG object.
|
||||
*/
|
||||
function imagify_ngg_cleanup_after_media_deletion( $image_id, $image ) {
|
||||
$process = imagify_get_optimization_process( $image, 'ngg' );
|
||||
|
||||
if ( ! $process->is_valid() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger a common hook.
|
||||
imagify_trigger_delete_media_hook( $process );
|
||||
|
||||
/**
|
||||
* The backup file has already been deleted by NGG.
|
||||
* Delete the WebP versions and the optimization data.
|
||||
*/
|
||||
$process->delete_webp_files();
|
||||
$process->get_data()->delete_optimization_data();
|
||||
}
|
||||
|
||||
add_filter( 'imagify_crop_thumbnail', 'imagify_ngg_should_crop_thumbnail', 10, 4 );
|
||||
/**
|
||||
* In case of a dynamic thumbnail, tell if the image must be croped or resized.
|
||||
*
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param bool $crop True to crop the thumbnail, false to resize. Null by default.
|
||||
* @param string $size Name of the thumbnail size.
|
||||
* @param array $size_data Data of the thumbnail being processed. Contains at least 'width', 'height', and 'path'.
|
||||
* @param MediaInterface $media The MediaInterface instance corresponding to the image being processed.
|
||||
* @return bool
|
||||
*/
|
||||
function imagify_ngg_should_crop_thumbnail( $crop, $size, $size_data, $media ) {
|
||||
static $data_per_media = [];
|
||||
static $storage_per_media = [];
|
||||
|
||||
if ( 'ngg' !== $media->get_context() ) {
|
||||
return $crop;
|
||||
}
|
||||
|
||||
$media_id = $media->get_id();
|
||||
|
||||
if ( ! isset( $data_per_media[ $media_id ] ) ) {
|
||||
$image = \nggdb::find_image( $media_id );
|
||||
|
||||
if ( ! empty( $image->_ngiw ) ) {
|
||||
$storage_per_media[ $media_id ] = $image->_ngiw->get_storage()->object;
|
||||
} else {
|
||||
$storage_per_media[ $media_id ] = \C_Gallery_Storage::get_instance()->object;
|
||||
}
|
||||
|
||||
$data_per_media[ $media_id ] = $storage_per_media[ $media_id ]->_image_mapper->find( $media_id ); // stdClass Object.
|
||||
}
|
||||
|
||||
$params = $storage_per_media[ $media_id ]->get_image_size_params( $data_per_media[ $media_id ], $size );
|
||||
|
||||
return ! empty( $params['crop'] );
|
||||
}
|
||||
198
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/functions/admin-stats.php
vendored
Normal file
198
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/functions/admin-stats.php
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
use \Imagify\ThirdParty\NGG\DB;
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
/**
|
||||
* Count number of attachments.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @return int The number of attachments.
|
||||
*/
|
||||
function imagify_ngg_count_attachments() {
|
||||
global $wpdb;
|
||||
static $count;
|
||||
|
||||
if ( isset( $count ) ) {
|
||||
return $count;
|
||||
}
|
||||
|
||||
$table_name = $wpdb->prefix . 'ngg_pictures';
|
||||
$count = (int) $wpdb->get_var( "SELECT COUNT($table_name.pid) FROM $table_name" ); // WPCS: unprepared SQL ok.
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of optimized attachments with an error.
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @return int The number of attachments.
|
||||
*/
|
||||
function imagify_ngg_count_error_attachments() {
|
||||
static $count;
|
||||
|
||||
if ( isset( $count ) ) {
|
||||
return $count;
|
||||
}
|
||||
|
||||
$ngg_db = DB::get_instance();
|
||||
$key = $ngg_db->get_primary_key();
|
||||
$count = (int) $ngg_db->get_var_by( "COUNT($key)", 'status', 'error' );
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of optimized attachments (by Imagify or an other tool before).
|
||||
*
|
||||
* @since 1.5
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @return int The number of attachments.
|
||||
*/
|
||||
function imagify_ngg_count_optimized_attachments() {
|
||||
static $count;
|
||||
|
||||
if ( isset( $count ) ) {
|
||||
return $count;
|
||||
}
|
||||
|
||||
$ngg_db = DB::get_instance();
|
||||
$key = $ngg_db->get_primary_key();
|
||||
$count = (int) $ngg_db->get_var_in( "COUNT($key)", 'status', array( 'success', 'already_optimized' ) );
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of unoptimized attachments.
|
||||
*
|
||||
* @since 1.0
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @return int The number of attachments.
|
||||
*/
|
||||
function imagify_ngg_count_unoptimized_attachments() {
|
||||
return imagify_ngg_count_attachments() - imagify_ngg_count_optimized_attachments() - imagify_ngg_count_error_attachments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count percent of optimized attachments.
|
||||
*
|
||||
* @since 1.0
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @return int The percent of optimized attachments.
|
||||
*/
|
||||
function imagify_ngg_percent_optimized_attachments() {
|
||||
$total_attachments = imagify_ngg_count_attachments();
|
||||
$total_optimized_attachments = imagify_ngg_count_optimized_attachments();
|
||||
|
||||
if ( ! $total_attachments || ! $total_optimized_attachments ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return min( round( 100 * $total_optimized_attachments / $total_attachments ), 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Count percent, original & optimized size of all images optimized by Imagify.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6.7 Revamped to handle huge libraries.
|
||||
* @author Jonathan Buttigieg
|
||||
*
|
||||
* @param bool|array $attachments An array containing the keys 'count', 'original_size', and 'optimized_size', or an array of attachments (back compat', deprecated), or false.
|
||||
* @return array An array containing the keys 'count', 'original_size', and 'optimized_size'.
|
||||
*/
|
||||
function imagify_ngg_count_saving_data( $attachments ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( is_array( $attachments ) ) {
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the query to get all optimized NGG attachments.
|
||||
* 3rd party will be able to override the result.
|
||||
*
|
||||
* @since 1.6.7
|
||||
*
|
||||
* @param bool|array $attachments An array containing the keys ('count', 'original_size', and 'optimized_size'), or false.
|
||||
*/
|
||||
$attachments = apply_filters( 'imagify_ngg_count_saving_data', false );
|
||||
|
||||
if ( is_array( $attachments ) ) {
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
$original_size = 0;
|
||||
$optimized_size = 0;
|
||||
$count = 0;
|
||||
|
||||
/** This filter is documented in /inc/functions/admin-stats.php */
|
||||
$limit = apply_filters( 'imagify_count_saving_data_limit', 15000 );
|
||||
$limit = absint( $limit );
|
||||
$offset = 0;
|
||||
$query = "
|
||||
SELECT data
|
||||
FROM $wpdb->ngg_imagify_data
|
||||
WHERE status = 'success'
|
||||
LIMIT %d, %d";
|
||||
|
||||
$attachments = $wpdb->get_col( $wpdb->prepare( $query, $offset, $limit ) ); // WPCS: unprepared SQL ok.
|
||||
$wpdb->flush();
|
||||
|
||||
while ( $attachments ) {
|
||||
$attachments = array_map( 'maybe_unserialize', $attachments );
|
||||
|
||||
foreach ( $attachments as $attachment_data ) {
|
||||
if ( ! $attachment_data ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
++$count;
|
||||
$original_data = $attachment_data['sizes']['full'];
|
||||
|
||||
// Increment the original sizes.
|
||||
$original_size += $original_data['original_size'] ? $original_data['original_size'] : 0;
|
||||
$optimized_size += $original_data['optimized_size'] ? $original_data['optimized_size'] : 0;
|
||||
|
||||
unset( $attachment_data['sizes']['full'], $original_data );
|
||||
|
||||
// Increment the thumbnails sizes.
|
||||
foreach ( $attachment_data['sizes'] as $size_data ) {
|
||||
if ( ! empty( $size_data['success'] ) ) {
|
||||
$original_size += $size_data['original_size'] ? $size_data['original_size'] : 0;
|
||||
$optimized_size += $size_data['optimized_size'] ? $size_data['optimized_size'] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
unset( $size_data );
|
||||
}
|
||||
|
||||
unset( $attachment_data );
|
||||
|
||||
if ( count( $attachments ) === $limit ) {
|
||||
// Unless we are really unlucky, we still have attachments to fetch.
|
||||
$offset += $limit;
|
||||
|
||||
$attachments = $wpdb->get_col( $wpdb->prepare( $query, $offset, $limit ) ); // WPCS: unprepared SQL ok.
|
||||
$wpdb->flush();
|
||||
} else {
|
||||
// Save one request, don't go back to the beginning of the loop.
|
||||
$attachments = array();
|
||||
}
|
||||
} // End while().
|
||||
|
||||
return array(
|
||||
'count' => $count,
|
||||
'original_size' => $original_size,
|
||||
'optimized_size' => $optimized_size,
|
||||
);
|
||||
}
|
||||
21
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/functions/attachments.php
vendored
Normal file
21
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/functions/attachments.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
/**
|
||||
* Get the backup path of a specific attachement.
|
||||
*
|
||||
* @since 1.6.8
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param string $file_path The file path.
|
||||
* @return string|bool The backup path. False on failure.
|
||||
*/
|
||||
function get_imagify_ngg_attachment_backup_path( $file_path ) {
|
||||
$file_path = wp_normalize_path( (string) $file_path );
|
||||
|
||||
if ( ! $file_path ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $file_path . '_backup';
|
||||
}
|
||||
32
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/functions/common.php
vendored
Normal file
32
wp/wp-content/plugins/imagify/inc/3rd-party/nextgen-gallery/inc/functions/common.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
/**
|
||||
* Get NGG Bulk Optimization screen ID.
|
||||
* Because WP nonsense, the screen ID depends on the menu title, which is translated. So the screen ID changes depending on the administration locale.
|
||||
*
|
||||
* @since 1.6.13
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function imagify_get_ngg_bulk_screen_id() {
|
||||
global $admin_page_hooks;
|
||||
|
||||
$ngg_menu_slug = defined( 'NGGFOLDER' ) ? plugin_basename( NGGFOLDER ) : 'nextgen-gallery';
|
||||
$ngg_menu_slug = isset( $admin_page_hooks[ $ngg_menu_slug ] ) ? $admin_page_hooks[ $ngg_menu_slug ] : 'gallery';
|
||||
|
||||
return $ngg_menu_slug . '_page_' . imagify_get_ngg_bulk_screen_slug();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get NGG Bulk Optimization screen slug.
|
||||
*
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function imagify_get_ngg_bulk_screen_slug() {
|
||||
return IMAGIFY_SLUG . '-ngg-bulk-optimization';
|
||||
}
|
||||
Reference in New Issue
Block a user