place( wp_basename( $file ), wp_basename( $backup ), $file ); } $file_exists = apply_filters( 'smush_backup_exists', file_exists( $backup ), $image_id, $backup ); if ( $file_exists ) { return true; } // Additional Backup Check for JPEGs converted from PNG. $pngjpg_savings = get_post_meta( $image_id, WP_SMUSH_PREFIX . 'pngjpg_savings', true ); if ( ! empty( $pngjpg_savings ) ) { // Get the original File path and check if it exists. $backup = get_post_meta( $image_id, WP_SMUSH_PREFIX . 'original_file', true ); $backup = Helper::original_file( $backup ); if ( ! empty( $backup ) && is_file( $backup ) ) { return true; } } return false; } /** * Print the column html. * * @param string $id Media id. * @param string $html Status text. * @param string $button_txt Button label. * @param boolean $show_button Whether to shoe the button. * * @return string */ private function column_html( $id, $html = '', $button_txt = '', $show_button = true ) { // Don't proceed if attachment is not image, or if image is not a jpg, png or gif. if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), Core::$mime_types, true ) ) { return __( 'Not processed', 'wp-smushit' ); } // If we aren't showing the button. if ( ! $show_button ) { return $html; } if ( 'Super-Smush' === $button_txt ) { $html .= ' | '; } $html .= "{$button_txt}"; $skipped = get_post_meta( $id, WP_SMUSH_PREFIX . 'ignore-bulk', true ); if ( 'true' === $skipped ) { $nonce = wp_create_nonce( 'wp-smush-remove-skipped' ); $html .= " | " . __( 'Show in bulk Smush', 'wp-smushit' ) . ''; } else { $html .= " | " . esc_html__( 'Ignore', 'wp-smushit' ) . ''; } $html .= self::progress_bar(); return $html; } /** * Shows the image size and the compression for each of them * * @param int $image_id Attachment ID. * @param array $wp_smush_data Smush data array. * @param array $attachment_metadata Attachment metadata. * * @return string */ private function get_detailed_stats( $image_id, $wp_smush_data, $attachment_metadata ) { $stats = '
'; return $stats; } /** * Return a list of images not smushed and reason * * @param int $image_id Attachment ID. * @param array $size_stats Stats array. * @param array $attachment_metadata Attachment metadata. * * @return array */ private function get_skipped_images( $image_id, $size_stats, $attachment_metadata ) { $skipped = array(); // Get a list of all the sizes, Show skipped images. $media_size = get_intermediate_image_sizes(); // Full size. $full_image = get_attached_file( $image_id ); // If full image was not smushed, reason 1. Large Size logic, 2. Free and greater than 5Mb. if ( ! array_key_exists( 'full', $size_stats ) && ! WP_Smush::is_pro() ) { // For free version, Check the image size. $skipped[] = array( 'size' => 'full', 'reason' => 'large_size', ); // For free version, check if full size is greater than 5 Mb, show the skipped status. $file_size = file_exists( $full_image ) ? filesize( $full_image ) : ''; if ( empty( $skipped ) && ! empty( $file_size ) && ( $file_size / WP_SMUSH_MAX_BYTES ) > 1 ) { $skipped[] = array( 'size' => 'full', 'reason' => 'size_limit', ); } } // For other sizes, check if the image was generated and not available in stats. if ( is_array( $media_size ) ) { foreach ( $media_size as $size ) { if ( array_key_exists( $size, $attachment_metadata['sizes'] ) && ! array_key_exists( $size, $size_stats ) && ! empty( $size['file'] ) ) { // Image Path. $img_path = path_join( dirname( $full_image ), $size['file'] ); $image_size = file_exists( $img_path ) ? filesize( $img_path ) : ''; if ( ! empty( $image_size ) && ( $image_size / WP_SMUSH_MAX_BYTES ) > 1 ) { $skipped[] = array( 'size' => 'full', 'reason' => 'size_limit', ); } } } } return $skipped; } /** * Returns the HTML for progress bar * * @return string */ public static function progress_bar() { return ''; } /** * Generates a Resmush link for a image. * * @param int $image_id Attachment ID. * @param string $type Type of attachment. * * @return bool|string */ public static function get_resmsuh_link( $image_id, $type = 'wp' ) { if ( empty( $image_id ) ) { return false; } $class = 'wp-smush-action wp-smush-title sui-tooltip sui-tooltip-constrained'; $class .= 'wp' === $type ? ' wp-smush-resmush' : ' wp-smush-nextgen-resmush'; return sprintf( '%s', esc_html__( 'Smush image including original file', 'wp-smushit' ), $image_id, wp_create_nonce( 'wp-smush-resmush-' . $image_id ), $class, esc_html__( 'Resmush', 'wp-smushit' ) ); } /** * Returns a restore link for given image id * * @param int $image_id Attachment ID. * @param string $type Attachment type. * * @return bool|string */ public static function get_restore_link( $image_id, $type = 'wp' ) { if ( empty( $image_id ) ) { return false; } $class = 'wp-smush-action wp-smush-title sui-tooltip'; $class .= 'wp' === $type ? ' wp-smush-restore' : ' wp-smush-nextgen-restore'; return sprintf( '%s', esc_html__( 'Restore original image', 'wp-smushit' ), $image_id, wp_create_nonce( 'wp-smush-restore-' . $image_id ), $class, esc_html__( 'Restore', 'wp-smushit' ) ); } /** * Show super smush link. * * @since 3.4.0 * * @param int $id Attachment ID. * @param array $smush_data Smush data array. * * @return string */ private function get_super_smush_link( $id, $smush_data ) { if ( ! WP_Smush::is_pro() || empty( $smush_data['stats'] ) ) { return ''; } // Image is already lossy. if ( isset( $smush_data['stats']['lossy'] ) && $smush_data['stats']['lossy'] ) { return ''; } // Check if premium user, compression was lossless, and lossy compression is enabled. if ( ! $this->settings->get( 'lossy' ) || 'image/gif' === get_post_mime_type( $id ) ) { return ''; } return "" . __( 'Super-Smush', 'wp-smushit' ) . ''; } }