Changeset 2097436
- Timestamp:
- 05/29/2019 06:57:20 PM (7 years ago)
- Location:
- cheetaho-image-optimizer/trunk
- Files:
-
- 56 added
- 3 edited
-
.github (added)
-
.github/ISSUE_TEMPLATE (added)
-
.github/ISSUE_TEMPLATE/bug_report.md (added)
-
.github/ISSUE_TEMPLATE/feature_request.md (added)
-
admin (added)
-
admin/assets (added)
-
admin/assets/css (added)
-
admin/assets/css/cheetaho.css (added)
-
admin/assets/img (added)
-
admin/assets/img/loading.gif (added)
-
admin/assets/js (added)
-
admin/assets/js/async.js (added)
-
admin/assets/js/cheetaho.js (added)
-
admin/assets/js/cheetahobulk.js (added)
-
admin/class-cheetaho-admin.php (added)
-
admin/class-cheetaho-alert.php (added)
-
admin/class-cheetaho-api.php (added)
-
admin/class-cheetaho-backup.php (added)
-
admin/class-cheetaho-bulk.php (added)
-
admin/class-cheetaho-optimizer.php (added)
-
admin/class-cheetaho-retina.php (added)
-
admin/class-cheetaho-settings.php (added)
-
admin/class-cheetaho-stats.php (added)
-
admin/db (added)
-
admin/db/class-cheetaho-db.php (added)
-
admin/db/class-cheetaho-image-metadata.php (added)
-
admin/index.php (added)
-
admin/views (added)
-
admin/views/alerts (added)
-
admin/views/alerts/api-key.php (added)
-
admin/views/alerts/index.php (added)
-
admin/views/alerts/quota-exceeded.php (added)
-
admin/views/alerts/rate-us.php (added)
-
admin/views/blocks (added)
-
admin/views/blocks/contacts.php (added)
-
admin/views/blocks/index.php (added)
-
admin/views/blocks/stats.php (added)
-
admin/views/blocks/support.php (added)
-
admin/views/bulk.php (added)
-
admin/views/index.php (added)
-
admin/views/parts (added)
-
admin/views/parts/column-results-old.php (added)
-
admin/views/parts/column-results.php (added)
-
admin/views/parts/index.php (added)
-
admin/views/parts/optimize-button.php (added)
-
admin/views/settings.php (added)
-
cheetaho.php (modified) (2 diffs)
-
includes (added)
-
includes/class-cheetaho-activator.php (added)
-
includes/class-cheetaho-deactivator.php (added)
-
includes/class-cheetaho-helpers.php (added)
-
includes/class-cheetaho-i18n.php (added)
-
includes/class-cheetaho-loader.php (added)
-
includes/class-cheetaho.php (added)
-
includes/index.php (added)
-
index.php (added)
-
languages/cheetaho.pot (added)
-
languages/readme.txt (modified) (1 diff)
-
readme.txt (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cheetaho-image-optimizer/trunk/cheetaho.php
r2043327 r2097436 3 3 * Plugin Name: CheetahO Image Optimizer 4 4 * Plugin URI: https://cheetaho.com/ 5 * Description: CheetahO optimizes images automatically. Check your <a href="options-general.php?page=cheetaho " target="_blank">Settings > CheetahO</a> page on how to start optimizing your image library and make your website load faster. Do not forget to update these settings after plugin update.6 * Version: 1.4. 2.25 * Description: CheetahO optimizes images automatically. Check your <a href="options-general.php?page=cheetaho-image-optimizer" target="_blank">Settings > CheetahO</a> page on how to start optimizing your image library and make your website load faster. Do not forget to update these settings after plugin update. 6 * Version: 1.4.3.1 7 7 * Author: CheetahO 8 8 * Author URI: https://cheetaho.com … … 11 11 */ 12 12 13 // Create a helper function for easy SDK access. 14 function cio_fs() 15 { 16 global $cio_fs; 13 // If this file is called directly, abort. 14 if ( ! defined( 'ABSPATH' ) ) { 15 die; 16 } 17 ini_set('display_errors', 1); 18 /** 19 * Currently plugin version. 20 */ 21 define( 'CHEETAHO_VERSION', '1.4.3.1' ); 22 define( 'CHEETAHO_DB_VERSION', '1.0' ); 17 23 18 if (!isset($cio_fs)) { 19 // Include Freemius SDK. 20 require_once dirname(__FILE__) . '/freemius/start.php'; 24 define( 'CHEETAHO_ASSETS_IMG_URL', realpath( plugin_dir_url( __FILE__ ) . 'img/' ) . '/img' ); 25 define( 'CHEETAHO_APP_URL', 'https://app.cheetaho.com/' ); 26 define( 'CHEETAHO_SETTINGS_LINK', admin_url( 'options-general.php?page=cheetaho-image-optimizer' ) ); 27 define( 'CHEETAHO_PLUGIN_FILE', __FILE__ ); 28 define( 'CHEETAHO_PLUGIN_ROOT', plugin_dir_path( __FILE__ ) ); 21 29 22 $cio_fs = fs_dynamic_init(array(23 'id' => '1137',24 'slug' => 'cheetaho-image-optimizer',25 'type' => 'plugin',26 'public_key' => 'pk_9a70e46c135ef9d7d764fcde2a668',27 'is_premium' => false,28 'has_addons' => false,29 'has_paid_plans' => false,30 'menu' => array(31 'slug' => 'cheetaho',32 'override_exact' => true,33 'first-path' => 'options-general.php?page=cheetaho',34 'contact' => false,35 'support' => false,36 'account' => false,37 'parent' => array(38 'slug' => 'options-general.php',39 ),40 ),41 ));42 }43 30 44 return $cio_fs; 31 $uploads = wp_upload_dir(); 32 define( 'CHEETAHO_UPLOADS_BASE', $uploads['basedir'] ); 33 34 $backup_base = is_main_site() ? CHEETAHO_UPLOADS_BASE : dirname( dirname( CHEETAHO_UPLOADS_BASE ) ); 35 $site_id = get_current_blog_id(); 36 37 define( 'CHEETAHO_BACKUP', 'CheetahoBackups' ); 38 define( 'CHEETAHO_BACKUP_FOLDER', $backup_base . '/' . CHEETAHO_BACKUP . '/' . $site_id ); 39 define( 'CHEETAHO_PLUGIN_NAME', 'cheetaho-image-optimizer' ); 40 41 /** 42 * The core plugin class that is used to define internationalization, 43 * admin-specific hooks, and public-facing site hooks. 44 */ 45 require plugin_dir_path( __FILE__ ) . 'includes/class-cheetaho.php'; 46 47 /** 48 * The code that runs during plugin activation. 49 * This action is documented in includes/class-plugin-name-activator.php 50 */ 51 function activate_cheetaho() { 52 require_once plugin_dir_path( __FILE__ ) . 'includes/class-cheetaho-activator.php'; 53 54 CheetahO_Activator::activate(); 45 55 } 46 56 47 // Init Freemius. 48 cio_fs(); 49 // Signal that SDK was initiated. 50 do_action('cio_fs_loaded'); 57 /** 58 * The code that runs during plugin deactivation. 59 * This action is documented in includes/class-plugin-name-deactivator.php 60 */ 61 function deactivate_cheetaho() { 62 require_once plugin_dir_path( __FILE__ ) . 'includes/class-cheetaho-deactivator.php'; 51 63 52 function cio_fs_settings_url() 53 { 54 return admin_url('options-general.php?page=cheetaho'); 64 CheetahO_Deactivator::deactivate(); 55 65 } 56 66 57 cio_fs()->add_filter('connect_url', 'cio_fs_settings_url'); 58 cio_fs()->add_filter('after_skip_url', 'cio_fs_settings_url'); 59 cio_fs()->add_filter('after_connect_url', 'cio_fs_settings_url'); 67 register_activation_hook( __FILE__, 'activate_cheetaho' ); 68 register_deactivation_hook( __FILE__, 'deactivate_cheetaho' ); 60 69 61 define('CHEETAHO_ASSETS_IMG_URL', realpath(plugin_dir_url(__FILE__) . 'img/') . '/img'); 62 define('CHEETAHO_VERSION', '1.4.2.2'); 63 define('CHEETAHO_APP_URL', 'https://app.cheetaho.com/'); 64 define('CHEETAHO_SETTINGS_LINK', admin_url('options-general.php?page=cheetaho')); 65 $uploads = wp_upload_dir(); 66 define('CHEETAHO_UPLOADS_BASE', $uploads['basedir']); 67 68 $backupBase = is_main_site() ? CHEETAHO_UPLOADS_BASE : dirname(dirname(CHEETAHO_UPLOADS_BASE)); 69 $siteID = get_current_blog_id(); 70 71 define('CHEETAHO_BACKUP', 'CheetahoBackups'); 72 define('CHEETAHO_BACKUP_FOLDER', $backupBase . '/' . CHEETAHO_BACKUP . '/' . $siteID); 73 74 if (!class_exists('WPCheetahO')) { 75 require_once(dirname(__FILE__) . '/lib/functions/cheetaho-ui.php'); 76 require_once(dirname(__FILE__) . '/lib/classes/cheetahoHelper.php'); 77 require_once(dirname(__FILE__) . '/lib/classes/cheetahoMetaHelper.php'); 78 79 80 class WPCheetahO 81 { 82 83 private $image_id; 84 85 private $cheetaho_settings = array(); 86 87 private $thumbs_data = array(); 88 89 private $status = array(); 90 91 private $cheetaho_optimization_type = 'lossy'; 92 93 public static $plugin_version = CHEETAHO_VERSION; 94 95 96 /* 97 * 98 */ 99 public function __construct() 100 { 101 $plugin_dir_path = dirname(__FILE__); 102 require_once($plugin_dir_path . '/lib/cheetaho.php'); 103 104 $this->cheetaho_settings = get_option('_cheetaho_options'); 105 $this->status = get_option('_cheetaho_api_status'); 106 107 108 $this->cheetaho_optimization_type = $this->cheetaho_settings['api_lossy']; 109 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array( 110 &$this, 111 'add_settings_link' 112 )); 113 add_action('admin_enqueue_scripts', array( 114 &$this, 115 'cheetaho_enqueue' 116 )); 117 add_filter('manage_media_columns', array( 118 &$this, 119 'add_media_columns' 120 )); 121 add_action('manage_media_custom_column', array( 122 &$this, 123 'fill_media_columns' 124 ), 10, 2); 125 add_action('wp_ajax_cheetaho_reset', array( 126 &$this, 127 'cheetaho_media_library_reset' 128 )); 129 add_action('wp_ajax_cheetaho_request', array( 130 &$this, 131 'cheetaho_ajax_callback' 132 )); 133 add_action('wp_ajax_cheetaho_reset_all', array( 134 &$this, 135 'cheetaho_media_library_reset_batch' 136 )); 137 if ((!empty($this->cheetaho_settings) && !empty($this->cheetaho_settings['auto_optimize'])) || !isset($this->cheetaho_settings['auto_optimize'])) { 138 139 add_action('add_attachment', array( 140 &$this, 141 'cheetaho_uploader_callback' 142 )); 143 add_filter('wp_generate_attachment_metadata', array( 144 &$this, 145 'optimize_thumbnails' 146 )); 147 } 148 149 // add_action( 'admin_menu', array( &$this, 'cheetahoMenu' ) ); 150 add_action('admin_menu', array( 151 &$this, 152 'registerSettingsPage' 153 )); // display SP in Settings menu 154 155 add_action('all_admin_notices', array(&$this, 'displayQuotaExceededAlert')); 156 add_action('all_admin_notices', array(&$this, 'displayApiKeyAlert')); 157 add_action('all_admin_notices', array(&$this, 'displayRateUsAlert')); 158 159 add_action('delete_attachment', array(&$this, 'deleteAttachmentInBackup')); 160 add_action('admin_menu', array(&$this, 'registerBulkPage')); 161 162 163 } 164 165 public function renderBulkProcess() 166 { 167 $settings = $this->cheetaho_settings; 168 $images = cheetahoHelper::getNotOptimizedImagesIDs($settings); 169 170 return CheetahoUI::displayBulkForm($this, $images); 171 } 172 173 function registerBulkPage() 174 { 175 add_media_page('CheetahO Bulk Process', 'Bulk CheetahO', 'edit_others_posts', 'cheetaho-bulk', 176 array(&$this, 'renderBulkProcess')); 177 } 178 179 180 function deleteAttachmentInBackup($id) 181 { 182 cheetahoHelper::handleDeleteAttachmentInBackup($id); 183 } 184 185 function checkStatus($apiKey = false) 186 { 187 $settings = $this->cheetaho_settings; 188 189 if ($apiKey != false) { 190 $settings['api_key'] = $apiKey; 191 } 192 193 $Cheetaho = new Cheetaho($settings); 194 195 $status = $Cheetaho->status(); 196 197 update_option('_cheetaho_api_status', $status); 198 $this->status = $status; 199 200 return $status; 201 202 } 203 204 public function displayApiKeyAlert() 205 { 206 207 $settings = $this->cheetaho_settings; 208 209 return CheetahoUI::displayApiKeyAlert($settings); 210 } 211 212 public function displayRateUsAlert() 213 { 214 $settings = $this->cheetaho_settings; 215 216 if (isset($settings['api_key']) && $settings['api_key'] != '' && get_option('_cheetaho_first_opt_images') != false && get_option('_cheetaho_first_opt_images') < (time() - 10 * 24 * 3600) 217 ) { 218 return CheetahoUI::displayRateUsAlert($settings); 219 } 220 } 221 222 public function displayQuotaExceededAlert() 223 { 224 return CheetahoUI::displayQuotaExceededAlert($this->status); 225 } 226 227 public function registerSettingsPage() 228 { 229 add_options_page('CheetahO Settings', 'CheetahO', 'manage_options', 'cheetaho', array( 230 $this, 231 'renderCheetahoSettingsMenu' 232 )); 233 234 } 235 236 public function renderCheetahoSettingsMenu() 237 { 238 239 return CheetahoUI::renderCheetahoSettingsMenu($this); 240 } 241 242 /** 243 * Handles optimizing images uploade through media uploader. 244 */ 245 function cheetaho_uploader_callback($image_id) 246 { 247 248 try { 249 $this->image_id = $image_id; 250 251 if (wp_attachment_is_image($image_id)) { 252 253 $settings = $this->cheetaho_settings; 254 $type = $settings['api_lossy']; 255 256 if (!parse_url(WP_CONTENT_URL, PHP_URL_SCHEME)) { // no absolute URLs used -> we implement a hack 257 $image_path = get_site_url() . wp_get_attachment_url($image_id); // get the file URL 258 } else { 259 $image_path = wp_get_attachment_url($image_id); // get the file URL 260 } 261 262 $result = $this->optimizeImage($image_path, $type, $image_id, true); 263 264 $image_path = get_attached_file($image_id); 265 266 if (!isset($result['error']) && !isset($result['data']['error']) && isset($result['data']['destURL'])) { 267 268 if (isset($result['data']['originalSize']) && (int)$result['data']['originalSize'] > 0) { 269 $result = $result['data']; 270 $savings_percentage = (int)$result['savedBytes'] / (int)$result['originalSize'] * 100; 271 $data['original_size'] = self::convert_to_kb($result['originalSize']); 272 $data['cheetaho_size'] = self::convert_to_kb($result['newSize']); 273 $data['saved_bytes'] = self::convert_to_kb($result['savedBytes']); 274 $data['newSize'] = $result['newSize']; 275 $data['saved_percent'] = round($savings_percentage, 2) . '%'; 276 $data['type'] = $this->type_toText($this->cheetaho_optimization_type); 277 $data['success'] = true; 278 $data['optimizedImages'] = 1; 279 $data['size_change'] = $result['savedBytes']; 280 $data['originalImagesSize'] = $result['originalSize']; 281 $data['meta'] = wp_get_attachment_metadata($image_id); 282 $data['humanReadableLibrarySize'] = size_format($data['size_change'], 2); 283 $saved_bytes = (int)$data['saved_bytes']; 284 285 if ($data['meta'] == '') { 286 $imagemeta = getimagesize($image_path); 287 288 if (isset($imagemeta[0]) && $imagemeta[1]) { 289 $data['meta'] = array('width' => $imagemeta[0], 'height' => $imagemeta[1]); 290 } 291 } 292 293 if ($this->replace_new_image($image_path, $result['destURL'])) { 294 295 $this->eventImageOptimized($settings, $image_id, $result); 296 297 update_post_meta($image_id, '_cheetaho_size', $data); 298 } else { 299 // writing image failed 300 } 301 } 302 } else { 303 304 // error or no optimization 305 if (file_exists($image_path)) { 306 307 $data['original_size'] = self::convert_to_kb(filesize($image_path)); 308 $data['error'] = $result['error']; 309 $data['type'] = $result['type']; 310 311 if ($data['error'] == 'This image can not be optimized any further') { 312 $data['cheetaho_size'] = 'No savings found'; 313 $data['no_savings'] = true; 314 } 315 316 update_post_meta($image_id, '_cheetaho_size', $data); 317 } else { 318 // file not found 319 } 320 } 321 322 } 323 } catch (Exception $e) { 324 } 325 } 326 327 public function cheetaho_enqueue($hook) 328 { 329 if ($hook == 'options-media.php' || $hook == 'upload.php' || $hook == 'settings_page_cheetaho') { 330 wp_enqueue_script('jquery'); 331 wp_enqueue_script('async-js', plugins_url('/js/async.js', __FILE__)); 332 wp_enqueue_script('cheetaho-js', plugins_url('/js/cheetaho.js', __FILE__), array( 333 'jquery' 334 )); 335 wp_localize_script('cheetaho-js', 'cheetaho_object', array( 336 'url' => admin_url('admin-ajax.php'), 337 'changeMLToListMode' => __('In order to access the CheetahO Optimization actions and info, please change to ', 338 'cheetaho-image-optimizer'), 339 'changeMLToListMode1' => __('List View', 'cheetaho-image-optimizer'), 340 'changeMLToListMode2' => __('Dismiss', 'cheetaho-image-optimizer'), 341 'resizeAlert1' => __('Please do not set a {type} less than your largest website thumbnail. If you will do this you will need regenerate all your thumbnails in case you will ever need this.', 342 'cheetaho-image-optimizer'), 343 )); 344 345 346 } 347 348 if ($hook == 'media_page_cheetaho-bulk') { 349 wp_enqueue_script('cheetaho-js-bulk', plugins_url('/js/cheetahobulk.js', __FILE__), array( 350 'jquery' 351 )); 352 353 wp_localize_script('cheetaho-js-bulk', 'cheetahoBulk', array( 354 'chAllDone' => __('All images are processed', 'cheetaho-image-optimizer'), 355 'chNoActionTaken' => __('No action taken', 'cheetaho-image-optimizer'), 356 'chBulkAction' => __('Compress Images', 'cheetaho-image-optimizer'), 357 'chCancelled' => __('Cancelled', 'cheetaho-image-optimizer'), 358 'chCompressing' => __('Compressing', 'cheetaho-image-optimizer'), 359 'chCompressed' => __('compressed', 'cheetaho-image-optimizer'), 360 'chFile' => __('File', 'cheetaho-image-optimizer'), 361 'chSizesOptimized' => __('Sizes optimized', 'cheetaho-image-optimizer'), 362 'chInitialSize' => __('Initial size', 'cheetaho-image-optimizer'), 363 'chCurrentSize' => __('Current size', 'cheetaho-image-optimizer'), 364 'chSavings' => __('Savings', 'cheetaho-image-optimizer'), 365 'chStatus' => __('Status', 'cheetaho-image-optimizer'), 366 'chShowMoreDetails' => __('Show more details', 'cheetaho-image-optimizer'), 367 'chError' => __('Error', 'cheetaho-image-optimizer'), 368 'chLatestError' => __('Latest error', 'cheetaho-image-optimizer'), 369 'chInternalError' => __('Internal error', 'cheetaho-image-optimizer'), 370 'chOutOf' => __('out of', 'cheetaho-image-optimizer'), 371 'chWaiting' => __('Waiting', 'cheetaho-image-optimizer'), 372 )); 373 374 } 375 376 wp_enqueue_style('cheetaho-css', plugins_url('css/cheetaho.css', __FILE__)); 377 } 378 379 public function cheetaho_ajax_callback() 380 { 381 $image_id = (int)$_POST['id']; 382 $type = false; 383 if (isset($_POST['type'])) { 384 $type = $_POST['type']; 385 } 386 387 $this->image_id = $image_id; 388 389 if (wp_attachment_is_image($image_id)) { 390 if (!parse_url(WP_CONTENT_URL, PHP_URL_SCHEME)) { // no absolute URLs used -> we implement a hack 391 $image_path = get_site_url() . wp_get_attachment_url($image_id); // get the file URL 392 } else { 393 $image_path = wp_get_attachment_url($image_id); // get the file URL 394 } 395 396 $local_image_path = get_attached_file($image_id); 397 398 $settings = $this->cheetaho_settings; 399 $api_key = isset($settings['api_key']) ? $settings['api_key'] : ''; 400 401 $data = array(); 402 if (empty($api_key)) { 403 $data['error'] = __('There is a problem with your credentials. Please check them in the CheetahO settings section and try again.', 404 'cheetaho-image-optimizer'); 405 echo json_encode(array('error' => array('message' => $data['error']))); 406 exit; 407 } 408 409 $status = $this->get_api_status($settings); 410 411 if ($status === false) { 412 $data['error'] = __('There is a problem with your cheetaho account. Maybe quota exceeded.', 413 'cheetaho-image-optimizer'); 414 update_post_meta($image_id, '_cheetaho_size', $data); 415 echo json_encode(array( 416 'error' => array('message' => $data['error']) 417 )); 418 exit(); 419 } 420 421 /* 422 * if ( isset( $status['active'] ) && $status['active'] === true ) { 423 * 424 * } else { 425 * echo json_encode( array( 'error' => 'Your account is inactive. Check your account settings' ) ); 426 * die(); 427 * } 428 */ 429 430 $result = $this->optimizeImage($image_path, $type, $image_id); 431 432 $data = array(); 433 434 if (!isset($result['error']) && !isset($result['data']['error']) && isset($result['data']['destURL'])) { 435 436 if (!isset($result['data']['originalSize']) || (int)$result['data']['originalSize'] == 0) { 437 echo json_encode(array( 438 'error' => array( 439 'message' => __('Could not optimize image. CheetahO can not optimize image. File size 0kb.', 440 'cheetaho-image-optimizer') 441 ) 442 )); 443 exit(); 444 } 445 446 447 $result = $result['data']; 448 $savings_percentage = (int)$result['savedBytes'] / (int)$result['originalSize'] * 100; 449 $data['original_size'] = self::convert_to_kb($result['originalSize']); 450 $data['cheetaho_size'] = self::convert_to_kb($result['newSize']); 451 $data['saved_bytes'] = self::convert_to_kb($result['savedBytes']); 452 $data['newSize'] = $result['newSize']; 453 $data['saved_percent'] = round($savings_percentage, 2) . '%'; 454 $data['type'] = $this->type_toText($this->cheetaho_optimization_type); 455 $data['success'] = true; 456 $data['thumbnail'] = $result['destURL']; 457 $data['optimizedImages'] = 1; 458 $data['size_change'] = $result['savedBytes']; 459 $data['originalImagesSize'] = $result['originalSize']; 460 $data['humanReadableLibrarySize'] = size_format($data['size_change'], 2); 461 $data['meta'] = wp_get_attachment_metadata($image_id); 462 463 $saved_bytes = (int)$data['saved_bytes']; 464 465 if ($this->replace_new_image($local_image_path, $result['destURL'])) { 466 $this->eventImageOptimized($settings, $image_id, $result); 467 468 // get metadata for thumbnails 469 $image_data = wp_get_attachment_metadata($image_id); 470 $this->optimize_thumbnails($image_data); 471 472 // store info to DB 473 update_post_meta($image_id, '_cheetaho_size', $data); 474 475 // process thumbnails and store that data too. This can be unset when there are no thumbs 476 $thumbs_data = get_post_meta($image_id, '_cheetaho_thumbs', true); 477 478 if (!empty($thumbs_data)) { 479 $data['thumbs_data'] = $thumbs_data; 480 $data['optimizedImages'] = $data['optimizedImages'] + count($thumbs_data); 481 foreach ($thumbs_data as $th) { 482 $data['size_change'] = $data['size_change'] + ($th['original_size'] - $th['cheetaho_size']); 483 $data['originalImagesSize'] = $data['originalImagesSize'] + $th['original_size']; 484 $data['newSize'] = $data['newSize'] + $th['cheetaho_size']; 485 } 486 $data['humanReadableLibrarySize'] = size_format($data['size_change'], 2); 487 } 488 489 $data['html'] = $this->output_result($image_id); 490 echo json_encode($data); 491 } else { 492 echo json_encode(array( 493 'error' => array( 494 'message' => __('Could not overwrite original file. Please check your files permisions.', 495 'cheetaho-image-optimizer') 496 ) 497 )); 498 499 exit(); 500 } 501 } else { 502 503 // error or no optimization 504 if (file_exists($image_path)) { 505 506 $data['original_size'] = self::convert_to_kb(filesize($image_path)); 507 $data['error'] = $result['error']; 508 $data['type'] = $result['type']; 509 510 if ($data['error'] == 'This image can not be optimized') { 511 $data['cheetaho_size'] = 'No savings found'; 512 $data['no_savings'] = true; 513 } 514 515 update_post_meta($image_id, '_cheetaho_size', $data); 516 } else { 517 // file not found 518 $data['error'] = 'File not found'; 519 } 520 521 if (isset($result['data']['error'])) { 522 $result = array(); 523 $result['error'] = array(); 524 $result['error']['message'] = __('Can not optimize image. Try later or contact CheetahO', 525 'cheetaho-image-optimizer'); 526 } 527 echo json_encode($result); 528 } 529 } 530 die(); 531 } 532 533 function optimize_thumbnails($image_data) 534 { 535 536 if (isset($image_data['file'])) { 537 $image_id = $this->image_id; 538 if (empty($image_id)) { 539 global $wpdb; 540 $post = $wpdb->get_row($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = %s LIMIT 1", 541 $image_data['file'])); 542 $image_id = $post->post_id; 543 } 544 545 546 $path_parts = pathinfo($image_data['file']); 547 548 // e.g. 04/02, for use in getting correct path or URL 549 $upload_subdir = $path_parts['dirname']; 550 551 $upload_dir = wp_upload_dir(); 552 553 // all the way up to /uploads 554 $upload_base_path = $upload_dir['basedir']; 555 $upload_full_path = $upload_base_path . '/' . $upload_subdir; 556 557 $sizes = array(); 558 559 if (isset($image_data['sizes'])) { 560 $sizes = $image_data['sizes']; 561 } 562 563 if (!empty($sizes)) { 564 565 $thumb_path = ''; 566 567 $thumbs_optimized_store = array(); 568 $this_thumb = array(); 569 $sizes_to_optimize = $this->get_sizes_to_optimize(); 570 571 foreach ($sizes as $key => $size) { 572 if (!in_array("include_size_$key", $sizes_to_optimize)) { 573 continue; 574 } 575 576 $thumb_path = $upload_full_path . '/' . $size['file']; 577 578 if (file_exists($thumb_path) !== false) { 579 580 $path = wp_get_attachment_image_src($image_id, $key); 581 $file = $path[0]; 582 583 if ($path[3] == false) { 584 $file = dirname($path[0]) . '/' . $size['file']; 585 } 586 587 $result = $this->optimizeImage($file, $this->cheetaho_optimization_type, $image_id); 588 589 if (!empty($result) && !isset($result['error']) && isset($result['data']['destURL'])) { 590 $result = $result['data']; 591 $destURL = $result["destURL"]; 592 593 if ($this->replace_new_image($thumb_path, $destURL)) { 594 $this_thumb = array( 595 'thumb' => $key, 596 'file' => $size['file'], 597 'original_size' => $result['originalSize'], 598 'cheetaho_size' => $result['newSize'], 599 'type' => $this->cheetaho_optimization_type 600 ); 601 $thumbs_optimized_store[] = $this_thumb; 602 } 603 } 604 } 605 } 606 } 607 608 if (!empty($thumbs_optimized_store)) { 609 update_post_meta($image_id, '_cheetaho_thumbs', $thumbs_optimized_store, false); 610 } 611 return $image_data; 612 } 613 } 614 615 function preg_array_key_exists($pattern, $array) 616 { 617 $keys = array_keys($array); 618 return (int)preg_grep($pattern, $keys); 619 } 620 621 function get_sizes_to_optimize() 622 { 623 $settings = $this->cheetaho_settings; 624 $rv = array(); 625 626 foreach ($settings as $key => $value) { 627 if (strpos($key, 'include_size') === 0 && !empty($value)) { 628 $rv[] = $key; 629 } 630 } 631 632 return $rv; 633 } 634 635 function replace_new_image($image_path, $new_url) 636 { 637 $fc = false; 638 639 $ch = curl_init($new_url); 640 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 641 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 642 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 643 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 644 curl_setopt($ch, CURLOPT_TIMEOUT, 120); 645 curl_setopt($ch, CURLOPT_USERAGENT, 646 'WordPress/' . get_bloginfo('version') . ' CheetahoPlugin/' . self::$plugin_version); 647 $result = curl_exec($ch); 648 649 if ($result) { 650 $fc = file_put_contents($image_path, $result); 651 } 652 return $fc !== false; 653 } 654 655 function optimizeImage($image_path, $type, $image_id, $throwException = false) 656 { 657 $firstImgtime = get_option('_cheetaho_first_opt_images'); 658 659 if ($firstImgtime == false) { 660 update_option('_cheetaho_first_opt_images', time()); 661 } 662 663 $settings = $this->cheetaho_settings; 664 665 if (isset($settings['api_key']) && $settings['api_key'] != '') { 666 if (cheetahoHelper::isProcessablePath($image_path) === false) { 667 $msg = __('This type of file can not be optimized', 'cheetaho-image-optimizer'); 668 669 if ($throwException == true) { 670 throw new Exception($msg); 671 } else { 672 echo json_encode(array( 673 'error' => array('message' => $msg) 674 )); 675 exit(); 676 } 677 } 678 679 if (!isset($settings['api_key']) || $settings['api_key'] == '') { 680 $msg = __('API key is required. Check CheetahO plugin settings.', 'cheetaho-image-optimizer'); 681 682 if ($throwException == true) { 683 throw new Exception($msg); 684 } else { 685 echo json_encode(array( 686 'error' => array('message' => $msg) 687 )); 688 exit(); 689 } 690 } 691 692 693 //make image backup if not exist 694 cheetahoHelper::makeBackup($image_path, $image_id, $settings); 695 696 $Cheetaho = new Cheetaho($settings); 697 698 if (!empty($type)) { 699 $lossy = $type; 700 } else { 701 $lossy = $settings['api_lossy']; 702 } 703 704 $params = array( 705 "url" => $image_path, 706 "lossy" => $lossy 707 ); 708 709 if (isset($settings['quality']) && $settings['quality'] > 0) { 710 $params['quality'] = (int)$settings['quality']; 711 } 712 713 if (isset($settings['keep_exif']) && $settings['keep_exif'] == 1) { 714 $params['strip_options'] = array('keep_exif' => (int)$settings['keep_exif']); 715 } 716 717 if (isset($settings['resize']) && $settings['resize'] == 1) { 718 $params['resize'] = array( 719 'width' => (int)$settings['maxWidth'], 720 'height' => (int)$settings['maxHeight'], 721 'strategy' => 'auto' 722 ); 723 } 724 725 set_time_limit(400); 726 $data = $Cheetaho->url($params); 727 728 if (isset($params['url']) && cheetahoMetaHelper::retinaName($params['url'])) { 729 $image_path = get_attached_file($image_id); 730 if (file_exists($image_path)) { 731 $params['url'] = cheetahoMetaHelper::retinaName($params['url']); 732 $Cheetaho->url($params); 733 } 734 } 735 736 //few checks 737 if (isset($data['data']['error']['fatal'])) { 738 if (isset($data['data']['error']['message'])) { 739 $msg = $data['data']['error']['message']; 740 } else { 741 $msg = 'System error!'; 742 } 743 744 if ($throwException == true) { 745 throw new Exception($msg); 746 } else { 747 echo json_encode(array( 748 'error' => array('message' => $msg) 749 )); 750 exit(); 751 } 752 } 753 754 if (isset($data['data']['originalSize']) && isset($data['data']['newSize']) && (int)$data['data']['originalSize'] == 0 && (int)$data['data']['newSize'] == 0) { 755 $msg = __('Error while we optimized image', 'cheetaho-image-optimizer'); 756 757 if ($throwException == true) { 758 throw new Exception($msg); 759 } else { 760 echo json_encode(array( 761 'error' => array('message' => $msg) 762 )); 763 exit(); 764 } 765 } 766 767 $data['type'] = !empty($type) ? $type : $settings['api_lossy']; 768 769 if (isset($data['error']) && isset($data['error']['http_code']) && $data['error']['http_code'] == 403) { 770 $status = $this->checkStatus(); 771 772 if ($status['data']['quota']['exceeded'] == false) { 773 self::cheetahOUpdateNotice('quota', 0, 1); 774 } else { 775 self::cheetahOUpdateNotice('quota', 0, 2); 776 } 777 } else { 778 $status = $this->status; 779 780 if (isset($status['data']['quota']['exceeded']) && $status['data']['quota']['exceeded'] == true) { 781 self::cheetahOUpdateNotice('quota', 0, 1); 782 } 783 } 784 785 786 return $data; 787 } 788 } 789 790 function eventImageOptimized($settings, $image_id, $cheetahoData) 791 { 792 $this->updateImageSizeMeta($settings, $image_id, $cheetahoData); 793 } 794 795 function resetImageSizeMeta($image_id, $cheetahoData) 796 { 797 798 $image_data = wp_get_attachment_metadata($image_id); 799 800 if ($image_data['width'] < $cheetahoData['meta']['width'] && $image_data['height'] < $cheetahoData['meta']['height']) { 801 $image_data['width'] = $cheetahoData['meta']['width']; 802 $image_data['height'] = $cheetahoData['meta']['height']; 803 804 wp_update_attachment_metadata($image_id, $image_data); 805 } 806 } 807 808 function updateImageSizeMeta($settings, $image_id, $cheetahoData) 809 { 810 811 if (isset($settings['resize']) && $settings['resize'] == 1) { 812 $image_data = wp_get_attachment_metadata($image_id); 813 if ((isset($image_data['width']) && isset($image_data['height']) && (int)$image_data['width'] > 0 && (int)$image_data['height'] > 0 && $image_data['width'] > $cheetahoData['imageWidth'] && $image_data['height'] > $cheetahoData['imageHeight']) || (!isset($image_data['width']) && !isset($image_data['height']))) { 814 $image_data['width'] = $cheetahoData['imageWidth']; 815 $image_data['height'] = $cheetahoData['imageHeight']; 816 wp_update_attachment_metadata($image_id, $image_data); 817 } 818 } 819 } 820 821 822 function get_api_status($settings) 823 { 824 return true; 825 826 if (!empty($settings['api_key'])) { 827 $Cheetaho = new Cheetaho($settings); 828 $status = $Cheetaho->status(); 829 830 return $status; 831 } 832 833 return false; 834 } 835 836 function add_media_columns($columns) 837 { 838 $columns['original_size'] = __('Original Size', 'cheetaho-image-optimizer'); 839 $columns['cheetaho_size'] = __('Optimized Size', 'cheetaho-image-optimizer'); 840 return $columns; 841 } 842 843 function cheetaho_media_library_reset() 844 { 845 $image_id = (int)$_POST['id']; 846 847 $image_meta = get_post_meta($image_id, '_cheetaho_size', true); 848 849 $original_size = $image_meta['cheetaho_size']; 850 delete_post_meta($image_id, '_cheetaho_size'); 851 delete_post_meta($image_id, '_cheetaho_thumbs'); 852 853 cheetahoHelper::restoreOriginalImage($image_id); 854 855 $this->resetImageSizeMeta($image_id, $image_meta); 856 857 echo json_encode(array( 858 'success' => true, 859 'original_size' => $original_size, 860 'html' => $this->optimize_button_html($image_id) 861 )); 862 wp_die(); 863 } 864 865 static function convert_to_kb($bytes) 866 { 867 return round(($bytes / 1024), 2) . ' kB'; 868 } 869 870 static function folderSize($path = false) 871 { 872 $total_size = 0; 873 if (file_exists($path)) { 874 $files = scandir($path); 875 } else { 876 return $total_size; 877 } 878 $cleanPath = rtrim($path, '/') . '/'; 879 foreach ($files as $t) { 880 if ($t <> "." && $t <> "..") { 881 $currentFile = $cleanPath . $t; 882 if (is_dir($currentFile)) { 883 $size = self::folderSize($currentFile); 884 $total_size += $size; 885 } else { 886 $size = filesize($currentFile); 887 $total_size += $size; 888 } 889 } 890 } 891 return $total_size; 892 } 893 894 static function type_toText($type) 895 { 896 if ($type == 1) { 897 return 'Lossy'; 898 } 899 900 if ($type == 0) { 901 return 'Lossless'; 902 } 903 } 904 905 function fill_media_columns($column_name, $id) 906 { 907 $file = get_attached_file($id); 908 909 $original_size = (file_exists($file) != false) ? filesize($file): 0; 910 $original_size = self::convert_to_kb($original_size); 911 912 $options = get_option('_cheetaho_options'); 913 $type = isset($options['api_lossy']) ? $options['api_lossy'] : 0; 914 915 if (strcmp($column_name, 'original_size') === 0) { 916 if (wp_attachment_is_image($id)) { 917 918 $meta = get_post_meta($id, '_cheetaho_size', true); 919 920 if (isset($meta['original_size'])) { 921 echo $meta['original_size']; 922 } else { 923 echo $original_size; 924 } 925 } else { 926 echo $original_size; 927 } 928 } else { 929 if (strcmp($column_name, 'cheetaho_size') === 0) { 930 931 if (wp_attachment_is_image($id)) { 932 933 $meta = get_post_meta($id, '_cheetaho_size', true); 934 935 // Is it optimized? Show some stats 936 if (isset($meta['cheetaho_size']) && empty($meta['no_savings'])) { 937 echo $this->output_result($id); 938 939 // Were there no savings, or was there an error? 940 } else { 941 $image_url = wp_get_attachment_url($id); 942 $filename = basename($image_url); 943 echo '<div class="buttonWrap"><button data-setting="' . $type . '" type="button" class="cheetaho_req" data-id="' . $id . '" id="cheetahoid-' . $id . '" data-filename="' . $filename . '" data-url="' . $image_url . '">Optimize This Image</button><span class="cheetahoSpinner"></span></div>'; 944 if (!empty($meta['no_savings'])) { 945 echo '<div class="noSavings"><strong>No savings found</strong><br /><small>Type: ' . $meta['type'] . '</small></div>'; 946 } else { 947 if (isset($meta['error'])) { 948 $error = $meta['error']['message']; 949 $txt = __('Failed! Hover here', 'cheetaho-image-optimizer'); 950 echo '<div class="cheetahoErrorWrap"><a class="cheetahoError" title="' . $error . '">' . $txt . '<span>' . $error . '</span></a></div>'; 951 } 952 } 953 } 954 } else { 955 echo 'n/a'; 956 } 957 } 958 } 959 } 960 961 function output_result($id) 962 { 963 $image_meta = get_post_meta($id, '_cheetaho_size', true); 964 $thumbs_meta = get_post_meta($id, '_cheetaho_thumbs', true); 965 $cheetaho_size = $image_meta['cheetaho_size']; 966 $type = $image_meta['type']; 967 $thumbs_count = count($thumbs_meta); 968 $savings_percentage = $image_meta['saved_percent']; 969 970 ob_start(); 971 ?> 972 <strong><?php echo $cheetaho_size; ?> </strong> 973 <br/> 974 <small>Type: <?php echo $type; ?> </small> 975 <br/> 976 <small>Savings: <?php echo $savings_percentage; ?> </small> 977 <?php if (!empty($thumbs_meta)) { ?> 978 <br/> 979 <small><?php echo $thumbs_count; ?> thumbs optimized</small> 980 <?php } ?> 981 <?php if (empty($this->cheetaho_settings['show_reset'])) { ?> 982 <br/> 983 <small class="cheetahoReset" data-id="<?php echo $id; ?>" 984 title="<?php echo __('Removes Cheetaho metadata associated with this image', 985 'cheetaho-image-optimizer') ?>"> <?php echo __('Reset', 'cheetaho-image-optimizer') ?> </small> 986 <span class="cheetahoSpinner"></span> 987 <?php } ?> 988 <?php 989 $html = ob_get_clean(); 990 return $html; 991 } 992 993 function optimize_button_html($id) 994 { 995 $image_url = wp_get_attachment_url($id); 996 $filename = basename($image_url); 997 998 $html = <<<EOD 999 <div class="buttonWrap"> 1000 <button type="button" 1001 data-setting="$this->cheetaho_optimization_type " 1002 class="cheetaho_req" 1003 data-id="$id" 1004 id="cheetahoid-$id" 1005 data-filename="$filename" 1006 data-url="<$image_url"> 1007 Optimize This Image 1008 </button> 1009 <small class="cheetahoOptimizationType" style="display:none">$this->cheetaho_optimization_type</small> 1010 <span class="cheetahoSpinner"></span> 1011 </div> 1012 EOD; 1013 1014 return $html; 1015 } 1016 1017 function cheetaho_media_library_reset_batch() 1018 { 1019 $result = null; 1020 delete_post_meta_by_key('_cheetaho_thumbs'); 1021 delete_post_meta_by_key('_cheetaho_size'); 1022 $result = json_encode(array( 1023 'success' => true 1024 )); 1025 echo $result; 1026 die(); 1027 } 1028 1029 function add_settings_link($links) 1030 { 1031 $mylinks = array( 1032 '<a href="' . admin_url('options-general.php?page=cheetaho') . '">' . __("Settings", 1033 "cheetaho-image-optimizer") . '</a>' 1034 ); 1035 return array_merge($links, $mylinks); 1036 } 1037 1038 /** 1039 * update notices settings if action = 1 - set, else is action = 2 - delete 1040 * Enter description here ... 1041 * @param unknown_type $notice 1042 * @param unknown_type $user_id 1043 * @param unknown_type $action 1044 */ 1045 1046 1047 function cheetahOUpdateNotice($notice, $user_id = 0, $action = 1) 1048 { 1049 global $current_user; 1050 1051 $user_id = (0 === $user_id) ? $current_user->ID : $user_id; 1052 $notices = get_user_meta($user_id, '_cheetaho_ignore_notices', true); 1053 1054 if ($action == 2) { 1055 $newitems = array(); 1056 if (!empty($notices)) { 1057 foreach ($notices as $item) { 1058 if ($item != $notice) { 1059 $newitems[] = $item; 1060 } 1061 } 1062 } 1063 update_user_meta($user_id, '_cheetaho_ignore_notices', $newitems); 1064 } elseif ($action == 1) { 1065 if (!is_array($notices)) { 1066 $notices = array(); 1067 } 1068 1069 $notices[] = $notice; 1070 $notices = array_filter($notices); 1071 $notices = array_unique($notices); 1072 update_user_meta($user_id, '_cheetaho_ignore_notices', $notices); 1073 1074 $status = $this->status; 1075 $status['data']['quota']['exceeded'] = false; 1076 $this->status = $status; 1077 } 1078 } 1079 1080 function emptyBackup() 1081 { 1082 cheetahoHelper::emptyBackup(); 1083 } 1084 1085 function validate_options_data($input) 1086 { 1087 $valid = array(); 1088 $error = array(); 1089 // $settings = get_option('_cheetaho_options'); 1090 $valid['api_lossy'] = $input['api_lossy']; 1091 $valid['auto_optimize'] = isset($input['auto_optimize']) ? 1 : 0; 1092 $valid['quality'] = isset($input['quality']) ? (int)$input['quality'] : 0; 1093 $valid['backup'] = isset($input['backup']) ? 1 : 0; 1094 $valid['keep_exif'] = isset($input['keep_exif']) ? 1 : 0; 1095 $valid['resize'] = isset($input['resize']) ? 1 : 0; 1096 $valid['authUser'] = $input['authUser']; 1097 $valid['authPass'] = $input['authPass']; 1098 1099 if ($valid['resize'] == 1) { 1100 $valid['maxWidth'] = (isset($input['maxWidth']) && $input['maxWidth'] > 0) ? (int)$input['maxWidth'] : 0; 1101 $valid['maxHeight'] = (isset($input['maxHeight']) && $input['maxHeight'] > 0) ? (int)$input['maxHeight'] : 0; 1102 1103 if ($valid['maxWidth'] == 0 || $valid['maxHeight'] == 0) { 1104 $error[] = __('If you would like to resize image, the max height and max width fields must be filled', 1105 'cheetaho-image-optimizer'); 1106 } 1107 } 1108 1109 $sizes = get_intermediate_image_sizes(); 1110 1111 foreach ($sizes as $size) { 1112 $valid['include_size_' . $size] = isset($input['include_size_' . $size]) ? 1 : 0; 1113 } 1114 1115 if (empty($input['api_key'])) { 1116 $error[] = 'Please enter API Credentials'; 1117 } else { 1118 1119 $status = $this->checkStatus($input['api_key']); 1120 1121 if (isset($status['error'])) { 1122 $error[] = __('Your API key is invalid. Check it here', 1123 'cheetaho-image-optimizer') . ' http://app.cheetaho.com/admin/api-credentials'; 1124 } else { 1125 if (isset($status['data']['quota']['exceeded']) && $status['data']['quota']['exceeded'] == false) { 1126 self::cheetahOUpdateNotice('quota', 0, 1); 1127 } else { 1128 self::cheetahOUpdateNotice('quota', 0, 2); 1129 } 1130 } 1131 1132 $valid['api_key'] = $input['api_key']; 1133 1134 } 1135 1136 if (!file_exists(CHEETAHO_BACKUP_FOLDER) && !@mkdir(CHEETAHO_BACKUP_FOLDER, 0777, true)) { 1137 $error[] = __("There is something preventing us to create a new folder for backing up your original files. Please make sure that folder", 1138 'cheetaho-image-optimizer') . " <b>" . WP_CONTENT_DIR . '/' . CHEETAHO_UPLOADS_NAME . "</b> " . __("has the necessary write and read rights.", 1139 'cheetaho-image-optimizer'); 1140 } 1141 1142 if (!empty($error)) { 1143 return array( 1144 'success' => false, 1145 'error' => $error, 1146 'valid' => $valid 1147 ); 1148 } else { 1149 return array( 1150 'success' => true, 1151 'valid' => $valid 1152 ); 1153 } 1154 } 1155 1156 function updateOptionsValue($key, $value) 1157 { 1158 $settings = get_option('_cheetaho_options'); 1159 1160 if (isset($settings[$key])) { 1161 1162 $settings[$key] = $value; 1163 } else { 1164 $settings = array_merge($settings, array($key => $value)); 1165 } 1166 1167 update_option('_cheetaho_options', $settings); 1168 } 1169 } 1170 1171 function getCheetahoUrl($action = 'options-general', $arg = array()) 1172 { 1173 1174 switch ($action) { 1175 1176 case 'closeNotice': 1177 $url = wp_nonce_url(admin_url('admin-post.php?action=cheetahOCloseNotice¬ice=' . $arg), 1178 'cheetahOCloseNotice'); 1179 break; 1180 1181 case 'options-general': 1182 default : 1183 $url = CHEETAHO_SETTINGS_LINK; 1184 break; 1185 } 1186 1187 return $url; 1188 } 1189 1190 function cheetahOCloseNotice($notice, $user_id = 0) 1191 { 1192 global $current_user; 1193 $notice = $_GET['notice']; 1194 1195 $user_id = (0 === $user_id) ? $current_user->ID : $user_id; 1196 $notices = get_user_meta($user_id, '_cheetaho_ignore_notices', true); 1197 if (!is_array($notices)) { 1198 $notices = array(); 1199 } 1200 $notices[] = $notice; 1201 1202 $notices = array_filter($notices); 1203 $notices = array_unique($notices); 1204 1205 update_user_meta($user_id, '_cheetaho_ignore_notices', $notices); 1206 1207 wp_safe_redirect(wp_get_referer()); 1208 die(); 1209 } 70 /** 71 * Begins execution of the plugin. 72 * 73 * Since everything within the plugin is registered via hooks, 74 * then kicking off the plugin from this point in the file does 75 * not affect the page life cycle. 76 */ 77 function run_cheetaho() { 78 $plugin = new CheetahO(); 79 $plugin->run(); 1210 80 } 1211 81 1212 new WPCheetahO(); 1213 1214 add_action('admin_post_cheetahOCloseNotice', 'cheetahOCloseNotice'); 1215 1216 register_activation_hook(__FILE__, 'cheetahoActivate'); 1217 add_action('admin_init', 'CheetahoRedirect'); 1218 1219 //Load Translation files 1220 add_action('plugins_loaded', 'cheetahoTranslate'); 1221 function cheetahoTranslate() 1222 { 1223 $path = path_join(dirname(plugin_basename(__FILE__)), 'languages/'); 1224 load_plugin_textdomain('cheetaho-image-optimizer', false, $path); 1225 } 1226 1227 function cheetahoActivate() 1228 { 1229 add_option('cheetaho_activation_redirect', true); 1230 } 1231 1232 function CheetahoRedirect() 1233 { 1234 if (get_option('cheetaho_activation_redirect', false)) { 1235 delete_option('cheetaho_activation_redirect'); 1236 if (!isset($_GET['activate-multi'])) { 1237 exit(wp_redirect(CHEETAHO_SETTINGS_LINK)); 1238 } 1239 } 1240 } 82 run_cheetaho(); -
cheetaho-image-optimizer/trunk/languages/readme.txt
r1597899 r2097436 1 LANGUAGE TRANSLATION FILES FOR IMSANITY1 LANGUAGE TRANSLATION FILES FOR CHEETAHO 2 2 --------------------------------------- 3 3 -
cheetaho-image-optimizer/trunk/readme.txt
r2043327 r2097436 2 2 Contributors: cheetaho 3 3 Tags: compressor, image, optimize, compress, performance, lossless, image optimiser, lossy, photo, pictures, optimize JPG, compress PNG, compress jpeg, optimize gif 4 Requires at least: 3.2.15 Tested up to: 5. 16 Stable tag: 1.4. 2.24 Requires at least: 4.4 5 Tested up to: 5.2 6 Stable tag: 1.4.3.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html … … 89 89 2. Media library with optimization button. `/assets/screenshot-2.png` 90 90 3. Bulk image optimization page. `/assets/screenshot-3.png` 91 3. Bulk image optimization in media library. `/assets/screenshot-4.png` 91 92 92 93 == Frequently Asked Questions == … … 128 129 129 130 = I can not optimize image. Got error "Requested file size too large". How fix this? = 130 CheetahO lets to optimize image up to 4 MB with free subscription plan. If you would like to optimize bigger files, you will need to take other plans from [here](http://app.cheetaho.com/admin/billing/plans) 131 CheetahO lets to optimize image up to 4 MB with free subscription plan. If you would like to optimize bigger files, you will need to take other plans from [here](http://app.cheetaho.com/admin/billing/plans) 131 132 132 133 = On how many websites can I use the plugin? = … … 151 152 We are here to help. <a href="https://cheetaho.com/contact-us/">Contact us</a>! 152 153 153 154 154 155 == Changelog == 156 = 1.4.3 = 157 * Update readme 158 * Retina image optimization improvement 159 * Replace some code parts to WordPress native functions 160 * Add some additional tests 161 * Refactor code for better performance 162 * Fix clear images backup button alert popup 163 155 164 = 1.4.2.2 = 156 * Security fix s165 * Security fix 157 166 * Fix error on api key save 158 167 … … 211 220 212 221 = 1.3.2 = 213 * Update translations 222 * Update translations 214 223 215 224 = 1.3.1 = … … 227 236 228 237 = 1.2.7 = 229 * Add strings in translations 238 * Add strings in translations 230 239 * Add gif images compression 231 240 232 241 = 1.2.6 = 233 242 * Update readme … … 252 261 = 1.2.2 = 253 262 * Add messages for users 254 * Check quota and API key if is valid 263 * Check quota and API key if is valid 255 264 256 265 = 1.2.1 = … … 258 267 259 268 = 1.2 = 260 * Image optimization statistics block. 269 * Image optimization statistics block. 261 270 * Change settings page interface and add support block. 262 271 * Add setting to choose which image size you would like to optimize. … … 278 287 == Any Questions or suggestions? == 279 288 Contact us by email support (at) cheetaho dot com. 280 281 282 283 284 285
Note: See TracChangeset
for help on using the changeset viewer.