PluginProbe
Squeeze – Image Optimization & Compression, WEBP Conversion / 1.7.8
Squeeze – Image Optimization & Compression, WEBP Conversion v1.7.8
1.7.15 1.7.14 1.7.13 1.7.12 1.7.11 1.7.10 trunk 1.0 1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5 1.5.1 1.5.2 1.6 All 42 releases
squeeze / squeeze.php

squeeze.php in Squeeze – Image Optimization & Compression, WEBP Conversion 1.7.8, at squeeze.php

309 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Squeeze – Image Optimization & Compression, WebP Conversion
5 * Description: Compress unlimited images directly into your browser. Convert images to WebP format. No limits on file size or number of images. No third-party services or API keys required.
6 * Author URI: https://pluginarium.com
7 * Author: Bogdan Bendziukov
8 * Version: 1.7.8
9 *
10 * Text Domain: squeeze
11 * Domain Path: /languages
12 *
13 * License: GPLv3
14 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
15 *
16 *
17 */
18 namespace SqueezeFree;
19
20 // Exit if accessed directly.
21 if ( !defined( 'ABSPATH' ) ) {
22 exit;
23 }
24 class SqueezeInit {
25 /**
26 * Plugin version
27 */
28 const VERSION = '1.7.8';
29
30 const CHECKOUT_URL = 'https://checkout.freemius.com/plugin/17217/plan/28703/';
31
32 /**
33 * Allowed image formats
34 */
35 const ALLOWED_IMAGE_FORMATS = array(
36 'jpg' => 'JPG/JPEG',
37 'png' => 'PNG',
38 'webp' => 'WebP',
39 'avif' => 'AVIF',
40 );
41
42 // Array containing dynamic data for a JS Global.
43 public static $LOCALIZE_ARGS;
44
45 public static $JS_OPTIONS = array();
46
47 public static $SqueezeHelpers;
48
49 public static $SqueezeSettings;
50
51 public static $SqueezeHandlers;
52
53 public static $SqueezePremium;
54
55 public static $UPGRADE_URL;
56
57 public static $SETTINGS_URL;
58
59 /**
60 * Media per page
61 */
62 public static $MEDIA_PER_PAGE;
63
64 /**
65 * Plugin directory
66 */
67 public static $PLUGIN_DIR;
68
69 /**
70 * Plugin URL
71 */
72 public static $PLUGIN_URL;
73
74 public static $DOCS_URL = 'https://pluginarium.com/squeeze/squeeze-documentation/';
75
76 /**
77 * Initialize the plugin
78 */
79 public function __construct() {
80 self::$PLUGIN_DIR = plugin_dir_path( __FILE__ );
81 self::$PLUGIN_URL = plugin_dir_url( __FILE__ );
82 self::$MEDIA_PER_PAGE = apply_filters( 'squeeze_media_per_page', 50 );
83 self::$UPGRADE_URL = admin_url( 'options-general.php?page=squeeze#squeeze_upgrade' );
84 self::$SETTINGS_URL = admin_url( 'options-general.php?page=squeeze' );
85 $this->load_helpers();
86 $this->load_handlers();
87 $this->load_settings();
88 self::$SqueezeHelpers = new SqueezeHelpers();
89 self::$SqueezeSettings = new SqueezeSettings();
90 self::$SqueezeHandlers = new SqueezeHandlers();
91 add_action( 'init', [$this, 'prepare_localize_args'] );
92 add_action( 'plugins_loaded', array($this, 'load_textdomain') );
93 add_action( 'admin_enqueue_scripts', array($this, 'load_assets') );
94 add_filter(
95 'plugin_action_links',
96 array($this, 'plugin_action_links'),
97 10,
98 2
99 );
100 add_action( 'enqueue_block_editor_assets', array($this, 'load_editor_assets') );
101 add_action( 'squeeze_freemius_loaded', array($this, 'load_freemius') );
102 register_activation_hook( __FILE__, array($this, 'activation_actions') );
103 add_action( 'admin_init', array($this, 'maybe_redirect_to_bulk_page') );
104 }
105
106 /**
107 * Load plugin textdomain
108 */
109 public function load_textdomain() {
110 load_plugin_textdomain( 'squeeze', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
111 }
112
113 public function load_freemius() {
114 }
115
116 public function opt_in_freemius() {
117 }
118
119 public function freemius_admin_notices() {
120 }
121
122 public function prepare_localize_args() {
123 $options = get_option( 'squeeze_options' );
124 $default_options = self::$SqueezeHelpers->get_default_value( null, true );
125 // get all default values
126 $js_options = array();
127 foreach ( $default_options as $key => $value ) {
128 if ( isset( $options[$key] ) ) {
129 if ( is_numeric( $options[$key] ) ) {
130 $js_options[$key] = floatval( $options[$key] );
131 } elseif ( $options[$key] === "on" ) {
132 $js_options[$key] = true;
133 } elseif ( $key === "compress_thumbs" ) {
134 $js_options[$key] = $options[$key];
135 } else {
136 $js_options[$key] = $options[$key];
137 //echo $key . ': ' . $js_options[$key] . ',' . $options[$key] . '<br>';
138 }
139 } else {
140 $js_options[$key] = $value;
141 }
142 }
143 self::$JS_OPTIONS = $js_options;
144 self::$LOCALIZE_ARGS = array(
145 'isPremium' => false,
146 'pluginUrl' => self::$PLUGIN_URL,
147 'upgradeUrl' => self::$UPGRADE_URL,
148 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
149 'nonce' => wp_create_nonce( 'squeeze-nonce' ),
150 'restNonce' => wp_create_nonce( 'wp_rest' ),
151 'options' => wp_json_encode( self::$JS_OPTIONS ),
152 'templateBase' => self::$PLUGIN_URL . 'assets/templates/',
153 'templates' => array(
154 'logWrapper' => self::$PLUGIN_URL . 'assets/templates/log-wrapper.html',
155 'logStep' => self::$PLUGIN_URL . 'assets/templates/log-step.html',
156 'logDetailsButton' => self::$PLUGIN_URL . 'assets/templates/log-details-button.html',
157 'directoryItem' => self::$PLUGIN_URL . 'assets/templates/directory-item.html',
158 'directoryItemEmpty' => self::$PLUGIN_URL . 'assets/templates/directory-item-empty.html',
159 'pathListItem' => self::$PLUGIN_URL . 'assets/templates/path-list-item.html',
160 'previewSqueeze' => self::$PLUGIN_URL . 'assets/templates/preview-squeeze.html',
161 ),
162 'settingsPageUrl' => admin_url( 'options-general.php?page=squeeze' ),
163 );
164 }
165
166 public function load_settings() {
167 require_once self::$PLUGIN_DIR . 'inc/settings.php';
168 }
169
170 public function load_handlers() {
171 require_once self::$PLUGIN_DIR . 'inc/handlers.php';
172 }
173
174 public function load_helpers() {
175 require_once self::$PLUGIN_DIR . 'inc/helpers.php';
176 }
177
178 /**
179 * Enqueue assets
180 */
181 public function load_assets() {
182 global $pagenow;
183 if ( !wp_script_is( 'media-editor', 'enqueued' ) ) {
184 wp_enqueue_media();
185 }
186 // Enqueue script for backend.
187 wp_enqueue_script(
188 'squeeze-script',
189 self::$PLUGIN_URL . 'assets/js/script.bundle.js',
190 array('jquery', 'jquery-ui-core', 'wp-mediaelement'),
191 self::VERSION,
192 true
193 );
194 // WP Localized globals. Use dynamic PHP stuff in JavaScript via `squeeze` object.
195 wp_localize_script( 'squeeze-script', 'squeezeOptions', self::$LOCALIZE_ARGS );
196 if ( $pagenow === 'upload.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze-bulk' ) {
197 wp_localize_script( 'squeeze-script', 'squeezeBulk', [
198 'allImages' => implode( ",", self::$SqueezeHelpers->get_total_images() ),
199 'unCompressedImages' => implode( ",", self::$SqueezeHelpers->get_uncompressed_images() ),
200 ] );
201 }
202 // Check if we are on the options page for the plugin
203 if ( $pagenow === 'upload.php' || $pagenow === 'options-general.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze' ) {
204 wp_enqueue_script(
205 'squeeze-settings-script',
206 self::$PLUGIN_URL . 'assets/js/admin.bundle.js',
207 array('jquery'),
208 self::VERSION,
209 true
210 );
211 }
212 wp_set_script_translations( 'squeeze-script', 'squeeze', self::$PLUGIN_DIR . 'languages' );
213 // Enqueue styles for backend.
214 wp_enqueue_style(
215 'squeeze-style',
216 self::$PLUGIN_URL . 'assets/css/admin.css',
217 array(),
218 self::VERSION
219 );
220 wp_localize_script( 'squeeze-editor-script', 'squeezeOptions', array(
221 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
222 'nonce' => wp_create_nonce( 'squeeze-nonce' ),
223 'options' => wp_json_encode( self::$JS_OPTIONS ),
224 ) );
225 }
226
227 public function load_elementor_assets() {
228 }
229
230 public function load_beaver_assets() {
231 }
232
233 public function load_editor_assets() {
234 // Enqueue scripts for the editor.
235 wp_enqueue_script(
236 'squeeze-editor-script',
237 self::$PLUGIN_URL . 'assets/js/editor.bundle.js',
238 array(
239 'wp-blocks',
240 'wp-hooks',
241 'wp-compose',
242 'wp-element',
243 'wp-data',
244 'wp-block-editor',
245 'wp-api-fetch'
246 ),
247 self::VERSION,
248 true
249 );
250 }
251
252 /**
253 * Add settings link on plugin page
254 *
255 * @param array $links
256 * @return array
257 */
258 public function plugin_action_links( $actions, $plugin_file ) {
259 static $plugin;
260 if ( !current_user_can( 'manage_options' ) ) {
261 return $actions;
262 }
263 if ( !isset( $plugin ) ) {
264 $plugin = plugin_basename( __FILE__ );
265 }
266 if ( $plugin === $plugin_file ) {
267 $settings_link = array(
268 'settings' => '<a href="' . admin_url( 'options-general.php?page=squeeze' ) . '">' . __( 'Settings', 'squeeze' ) . '</a>',
269 );
270 $bulk_link = array(
271 'bulk' => '<a href="' . admin_url( 'upload.php?page=squeeze-bulk' ) . '">' . __( 'Bulk Squeeze', 'squeeze' ) . '</a>',
272 );
273 $docs_link = array(
274 'docs' => '<a target="_blank" href="https://pluginarium.com/squeeze/squeeze-documentation/">' . __( 'Documentation', 'squeeze' ) . '</a>',
275 );
276 $actions['upgrade'] = '<a href="' . esc_url( self::$UPGRADE_URL ) . '">' . esc_html__( 'Go Premium', 'squeeze' ) . '</a>';
277 $actions = array_merge( $docs_link, $actions );
278 $actions = array_merge( $bulk_link, $actions );
279 $actions = array_merge( $settings_link, $actions );
280 }
281 return $actions;
282 }
283
284 public function activation_actions() {
285 // Only for single-site activation
286 if ( !is_network_admin() && !isset( $_GET['activate-multi'] ) ) {
287 add_option( 'squeeze_do_activation_redirect', true );
288 }
289 }
290
291 public function maybe_redirect_to_bulk_page() {
292 if ( get_option( 'squeeze_do_activation_redirect', false ) ) {
293 // Delete the flag so it happens only once
294 delete_option( 'squeeze_do_activation_redirect' );
295 // Skip redirection during bulk or network activation
296 // When you activate several plugins at once (for example, from the Plugins screen using the bulk “Activate” action),
297 // WordPress adds ?activate-multi=true to the URL.
298 if ( isset( $_GET['activate-multi'] ) ) {
299 return;
300 }
301 // Redirect to your custom bulk optimization page
302 wp_safe_redirect( admin_url( 'upload.php?page=squeeze-bulk' ) );
303 exit;
304 }
305 }
306
307 }
308
309 new SqueezeInit();