Robin image optimizer — save money on image compression - Version 1.3.7

Version Description

  • Fixed: Minor errors
Download this release

Release Info

Developer webcraftic
Plugin Icon 128x128 Robin image optimizer — save money on image compression
Version 1.3.7
Comparing to
See all releases

Code changes from version 1.1.5 to 1.3.7

Files changed (186) hide show
  1. admin/activation.php +52 -29
  2. admin/ajax/backup.php +94 -57
  3. admin/ajax/bulk-optimization.php +268 -0
  4. admin/ajax/check-servers-status.php +0 -56
  5. admin/ajax/index.php +2 -0
  6. admin/ajax/logs.php +24 -0
  7. admin/ajax/meta-migrations.php +174 -0
  8. admin/ajax/multisite-update-current-blog.php +29 -0
  9. admin/ajax/optimization.php +0 -46
  10. admin/ajax/select-server.php +0 -31
  11. admin/ajax/settings.php +37 -0
  12. admin/assets/css/base-statistic.css +657 -436
  13. admin/assets/css/base-statistic.css.map +1 -0
  14. admin/assets/css/base-statistic.less +353 -79
  15. admin/assets/css/index.php +2 -0
  16. admin/assets/css/statistic.css +204 -166
  17. admin/assets/css/sweetalert-custom.css +156 -0
  18. admin/assets/css/sweetalert-custom.css.map +1 -0
  19. admin/assets/css/sweetalert-custom.less +185 -0
  20. admin/assets/css/sweetalert2.css +716 -0
  21. admin/assets/img/index.php +2 -0
  22. admin/assets/index.php +2 -0
  23. admin/assets/js/bulk-optimization.js +490 -0
  24. admin/assets/js/bulk-optimozation.js +0 -121
  25. admin/assets/js/check-servers-status.js +0 -82
  26. admin/assets/js/index.php +2 -0
  27. admin/assets/js/meta-migrations.js +52 -0
  28. admin/assets/js/modals.js +59 -0
  29. admin/assets/js/restore-backup.js +115 -0
  30. admin/assets/js/single-optimization.js +12 -4
  31. admin/assets/js/sweetalert2.js +1641 -0
  32. admin/boot.php +267 -94
  33. admin/includes/classes/class-rio-nextgen-landing.php +61 -0
  34. admin/includes/classes/class-rio-optimize-template.php +226 -0
  35. admin/includes/classes/index.php +2 -0
  36. admin/includes/index.php +2 -0
  37. admin/includes/sidebar-widgets.php +83 -0
  38. admin/index.php +1 -0
  39. admin/pages/class-rio-license.php +91 -0
  40. admin/pages/class-rio-log.php +164 -0
  41. admin/pages/class-rio-page.php +85 -0
  42. admin/pages/class-rio-settings.php +485 -0
  43. admin/pages/class-rio-statistic.php +252 -0
  44. admin/pages/index.php +2 -0
  45. admin/pages/log.php +0 -139
  46. admin/pages/settings.php +0 -421
  47. admin/pages/statistic.php +0 -479
  48. includes/class-rio-plugin.php +158 -0
  49. includes/class.plugin.php +0 -193
  50. includes/classes/class-rio-attachment.php +893 -0
  51. includes/classes/class-rio-backup.php +537 -0
  52. includes/classes/class-rio-cron.php +183 -0
  53. includes/classes/class-rio-image-statistic.php +323 -0
  54. includes/classes/class-rio-media-library.php +709 -0
  55. includes/classes/class-rio-multisite.php +54 -0
  56. includes/classes/class-rio-optimization-tools.php +57 -0
  57. includes/classes/class-rio-views.php +100 -0
  58. includes/classes/class.attachment.php +0 -488
  59. includes/classes/class.backup.php +0 -348
  60. includes/classes/class.cron.php +0 -115
  61. includes/classes/class.image-processor-abstract.php +0 -78
  62. includes/classes/class.image-processor-clearfy1.php +0 -139
  63. includes/classes/class.image-processor-resmush.php +0 -96
  64. includes/classes/class.image-processor-smushpro.php +0 -85
  65. includes/classes/class.image-processor-webcraftic.php +0 -110
  66. includes/classes/class.image-statistic.php +0 -165
  67. includes/classes/class.logger.php +0 -88
  68. includes/classes/class.media-library.php +0 -533
  69. includes/classes/class.optimization-tools.php +0 -47
  70. includes/classes/index.php +2 -0
  71. includes/classes/logger/class-rio-log-export.php +251 -0
  72. includes/classes/logger/class-rio-log-reader.php +72 -0
  73. includes/classes/logger/class-rio-logger.php +411 -0
  74. includes/classes/models/class-rio-attachment-extra-data.php +81 -0
  75. includes/classes/models/class-rio-base-active-record.php +97 -0
  76. includes/classes/models/class-rio-base-extra-data.php +53 -0
  77. includes/classes/models/class-rio-base-helper.php +24 -0
  78. includes/classes/models/class-rio-base-object.php +104 -0
  79. includes/classes/models/class-rio-process-queue-table.php +968 -0
  80. includes/classes/models/class-rio-server-smushit-extra-data.php +21 -0
  81. includes/classes/processors/class-rio-server-abstract.php +176 -0
  82. includes/classes/processors/class-rio-server-clearfy1.php +266 -0
  83. includes/classes/processors/class-rio-server-resmush.php +144 -0
  84. includes/classes/processors/class-rio-server-smushpro.php +142 -0
  85. includes/classes/processors/class-rio-server-webcraftic.php +133 -0
  86. includes/classes/processors/index.php +2 -0
  87. includes/functions.php +398 -79
  88. includes/index.php +3 -0
  89. index.php +2 -0
  90. languages/index.php +2 -0
  91. languages/robin-image-optimizer-ru_RU.mo +0 -0
  92. languages/robin-image-optimizer-ru_RU.po +475 -285
  93. libs/addons/admin/ajax/folders.php +434 -0
  94. libs/addons/admin/ajax/optimization.php +61 -0
  95. libs/addons/admin/assets/css/custom-folders.css +6 -0
  96. libs/addons/admin/assets/css/custom-folders.css.map +1 -0
  97. libs/addons/admin/assets/css/custom-folders.less +11 -0
  98. {updates → libs/addons/admin/assets/css}/index.php +0 -0
  99. libs/addons/admin/assets/css/jquery-file-tree.css +318 -0
  100. libs/addons/admin/assets/css/other-media.css +210 -0
  101. libs/addons/admin/assets/img/file-tree/application.png +0 -0
  102. libs/addons/admin/assets/img/file-tree/code.png +0 -0
  103. libs/addons/admin/assets/img/file-tree/css.png +0 -0
  104. libs/addons/admin/assets/img/file-tree/db.png +0 -0
  105. libs/addons/admin/assets/img/file-tree/directory-lock.png +0 -0
  106. libs/addons/admin/assets/img/file-tree/directory.png +0 -0
  107. libs/addons/admin/assets/img/file-tree/doc.png +0 -0
  108. libs/addons/admin/assets/img/file-tree/file-lock.png +0 -0
  109. libs/addons/admin/assets/img/file-tree/file.png +0 -0
  110. libs/addons/admin/assets/img/file-tree/film.png +0 -0
  111. libs/addons/admin/assets/img/file-tree/flash.png +0 -0
  112. libs/addons/admin/assets/img/file-tree/folder_open.png +0 -0
  113. libs/addons/admin/assets/img/file-tree/html.png +0 -0
  114. libs/addons/admin/assets/img/file-tree/java.png +0 -0
  115. libs/addons/admin/assets/img/file-tree/linux.png +0 -0
  116. libs/addons/admin/assets/img/file-tree/music.png +0 -0
  117. libs/addons/admin/assets/img/file-tree/pdf.png +0 -0
  118. libs/addons/admin/assets/img/file-tree/php.png +0 -0
  119. libs/addons/admin/assets/img/file-tree/picture.png +0 -0
  120. libs/addons/admin/assets/img/file-tree/ppt.png +0 -0
  121. libs/addons/admin/assets/img/file-tree/psd.png +0 -0
  122. libs/addons/admin/assets/img/file-tree/ruby.png +0 -0
  123. libs/addons/admin/assets/img/file-tree/script.png +0 -0
  124. libs/addons/admin/assets/img/file-tree/spinner.gif +0 -0
  125. libs/addons/admin/assets/img/file-tree/txt.png +0 -0
  126. libs/addons/admin/assets/img/file-tree/xls.png +0 -0
  127. libs/addons/admin/assets/img/file-tree/zip.png +0 -0
  128. libs/addons/admin/assets/img/quick-start-loader.gif +0 -0
  129. libs/addons/admin/assets/index.php +0 -0
  130. libs/addons/admin/assets/js/custom-folders.js +403 -0
  131. libs/addons/admin/assets/js/general.js +14 -0
  132. libs/addons/admin/assets/js/index.php +0 -0
  133. libs/addons/admin/assets/js/jquery-file-tree.js +213 -0
  134. libs/addons/admin/boot.php +48 -0
  135. libs/addons/admin/filters/backup.php +69 -0
  136. libs/addons/admin/filters/settings-page.php +66 -0
  137. libs/addons/admin/index.php +0 -0
  138. libs/addons/admin/pages/class-rio-statistic-folders-page.php +176 -0
  139. libs/addons/admin/pages/class-rio-statistic-nextgen-page.php +102 -0
  140. libs/addons/admin/pages/index.php +0 -0
  141. libs/addons/assets/img/.htaccess +37 -0
  142. libs/addons/assets/img/index.php +2 -0
  143. libs/addons/assets/img/test.jpg +0 -0
  144. libs/addons/assets/img/test.jpg.webp +0 -0
  145. libs/addons/assets/img/test.webp +0 -0
  146. libs/addons/assets/index.php +2 -0
  147. libs/addons/assets/js/index.php +2 -0
  148. libs/addons/assets/js/picturefill.min.js +5 -0
  149. libs/addons/includes/classes/class.backup.php +364 -0
  150. libs/addons/includes/classes/class.custom-folders.php +659 -0
  151. libs/addons/includes/classes/class.folder-image.php +479 -0
  152. libs/addons/includes/classes/class.folder.php +330 -0
  153. libs/addons/includes/classes/class.folders-list-table.php +260 -0
  154. libs/addons/includes/classes/class.gallery-nextgen.php +573 -0
  155. libs/addons/includes/classes/class.image-nextgen.php +532 -0
  156. libs/addons/includes/classes/class.image-statistic-folders.php +332 -0
  157. libs/addons/includes/classes/class.image-statistic-nextgen.php +237 -0
  158. libs/addons/includes/classes/helpers/class.url.php +49 -0
  159. libs/addons/includes/classes/index.php +0 -0
  160. libs/addons/includes/classes/models/class.folders-extra-data.php +259 -0
  161. libs/addons/includes/classes/models/class.nextgen-extra-data.php +273 -0
  162. libs/addons/includes/classes/models/class.webp-extra-data.php +157 -0
  163. libs/addons/includes/classes/webp/class-webp-api.php +339 -0
  164. libs/addons/includes/classes/webp/class-webp-delivery.php +292 -0
  165. libs/addons/includes/classes/webp/class-webp-html-image-urls-replacer.php +23 -0
  166. libs/addons/includes/classes/webp/class-webp-html-picture-tags.php +17 -0
  167. libs/addons/includes/classes/webp/class-webp-listener.php +511 -0
  168. libs/addons/includes/classes/webp/class-webp-server.php +338 -0
  169. libs/addons/includes/classes/webp/composer.json +5 -0
  170. libs/addons/includes/classes/webp/composer.lock +73 -0
  171. libs/addons/includes/classes/webp/vendor/autoload.php +7 -0
  172. libs/addons/includes/classes/webp/vendor/composer/ClassLoader.php +445 -0
  173. libs/addons/includes/classes/webp/vendor/composer/LICENSE +21 -0
  174. libs/addons/includes/classes/webp/vendor/composer/autoload_classmap.php +9 -0
  175. libs/addons/includes/classes/webp/vendor/composer/autoload_namespaces.php +9 -0
  176. libs/addons/includes/classes/webp/vendor/composer/autoload_psr4.php +10 -0
  177. libs/addons/includes/classes/webp/vendor/composer/autoload_real.php +52 -0
  178. libs/addons/includes/classes/webp/vendor/composer/autoload_static.php +31 -0
  179. libs/addons/includes/classes/webp/vendor/composer/installed.json +59 -0
  180. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/.php_cs.dist +19 -0
  181. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/README.md +156 -0
  182. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/composer.json +58 -0
  183. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/phpunit.xml.dist +30 -0
  184. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php +212 -0
  185. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/src/PictureTags.php +202 -0
  186. libs/addons/includes/classes/webp/vendor/rosell-dk/dom-util-for-webp/src/simple_html_dom/simple_html_dom.inc +1357 -0
admin/activation.php CHANGED
@@ -1,42 +1,65 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  /**
4
- * Activator for the Robin image optimizer
5
  *
6
- * @author Webcraftic <wordpress.webraftic@gmail.com>
7
- * @copyright (c) 09.09.2017, Webcraftic
8
- * @see Factory409_Activator
9
- * @version 1.0
10
  */
 
 
11
 
12
- // Exit if accessed directly
13
- if( !defined('ABSPATH') ) {
14
- exit;
15
- }
 
 
 
 
 
 
16
 
17
- class WIO_Activation extends Wbcr_Factory409_Activator {
18
 
19
- /**
20
- * Runs activation actions.
21
- *
22
- * @since 1.0.0
23
- */
24
- public function activate()
25
- {
26
- WIO_Plugin::app()->updateOption('image_optimization_server', 'server_1');
27
- WIO_Plugin::app()->updateOption('backup_origin_images', 1);
28
- WIO_Plugin::app()->updateOption('save_exif_data', 1);
29
 
30
- WIO_Cron::check();
 
31
  }
32
 
33
- /**
34
- * Runs activation actions.
35
- *
36
- * @since 1.0.0
37
- */
38
- public function deactivate()
39
- {
40
- WIO_Cron::stop();
41
  }
 
 
42
  }
 
1
  <?php
2
 
3
+ /**
4
+ * Activator for the Robin image optimizer
5
+ *
6
+ * @author Webcraftic <wordpress.webraftic@gmail.com>
7
+ * @copyright (c) 09.09.2017, Webcraftic
8
+ * @see Factory412_Activator
9
+ * @version 1.0
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( ! defined( 'ABSPATH' ) ) {
14
+ exit;
15
+ }
16
+
17
+ class WIO_Activation extends Wbcr_Factory412_Activator {
18
+
19
  /**
20
+ * Runs activation actions.
21
  *
22
+ * @since 1.0.0
23
+ * @throws \Exception
 
 
24
  */
25
+ public function activate() {
26
+ WRIO_Logger::info( 'Parent plugin start installation!' );
27
 
28
+ WRIO_Plugin::app()->updatePopulateOption( 'image_optimization_server', 'server_1' );
29
+ WRIO_Plugin::app()->updatePopulateOption( 'backup_origin_images', 1 );
30
+ WRIO_Plugin::app()->updatePopulateOption( 'save_exif_data', 1 );
31
+
32
+ if ( function_exists( 'wrio_is_license_activate' ) && wrio_is_license_activate() ) {
33
+ WRIO_Logger::info( 'Premium plugin start installation!' );
34
+ require_once( WRIO_PLUGIN_DIR . '/libs/addons/robin-image-optimizer-premium.php' );
35
+ wrio_premium_activate();
36
+ WRIO_Logger::info( 'Premium plugin installation complete!' );
37
+ }
38
 
39
+ RIO_Process_Queue::try_create_plugin_tables();
40
 
41
+ WRIO_Logger::info( 'Parent plugin installation complete!' );
42
+ }
43
+
44
+ /**
45
+ * Runs activation actions.
46
+ *
47
+ * @since 1.0.0
48
+ */
49
+ public function deactivate() {
50
+ WRIO_Logger::info( 'Parent plugin start deactivation!' );
51
 
52
+ if ( class_exists( 'WRIO_Cron' ) ) {
53
+ WRIO_Cron::stop();
54
  }
55
 
56
+ if ( function_exists( 'wrio_is_license_activate' ) && wrio_is_license_activate() ) {
57
+ WRIO_Logger::info( 'Premium plugin start deactivation!' );
58
+ require_once( WRIO_PLUGIN_DIR . '/libs/addons/robin-image-optimizer-premium.php' );
59
+ wrio_premium_deactivate();
60
+ WRIO_Logger::info( 'Premium plugin deactivation complete!' );
 
 
 
61
  }
62
+
63
+ WRIO_Logger::info( 'Parent plugin deactivation complete!' );
64
  }
65
+ }
admin/ajax/backup.php CHANGED
@@ -1,66 +1,103 @@
1
  <?php
2
- /**
3
- * Backup
4
- * @author Webcraftic <wordpress.webraftic@gmail.com>
5
- * @copyright (c) 22.10.2018, Webcraftic
6
- * @version 1.0
7
- */
8
-
9
- /**
10
- * AJAX обработчик массовой оптимизации изображений со страницы статистики
11
- */
12
- add_action('wp_ajax_wio_restore_backup', function () {
13
- check_admin_referer('wio-iph');
14
-
15
- $max_process_per_request = 5;
16
- $total = $_POST['total'];
17
-
18
- $media_library = new WIO_MediaLibrary();
19
-
20
- if( $total == '?' ) {
21
- $total = $media_library->getOptimizedCount();
22
- }
23
- $restored_data = $media_library->restoreAllFromBackup($max_process_per_request);
24
 
25
- $restored_data['total'] = $total;
26
- if( $total ) {
27
- $restored_data['percent'] = 100 - ($restored_data['remain'] * 100 / $total);
28
- } else {
29
- $restored_data['percent'] = 0;
30
- }
31
 
32
- // если изображения закончились - посылаем команду завершения
33
- if( $restored_data['remain'] <= 0 ) {
34
- $restored_data['end'] = true;
35
- }
36
- wp_send_json($restored_data);
37
- });
38
 
39
- /**
40
- * AJAX обработчик очистки папки с бекапами
41
- */
42
- add_action('wp_ajax_wio_clear_backup', function () {
43
- check_admin_referer('wio-iph');
44
 
45
- $backup = new WIO_Backup();
46
- $backup->removeBackupDir();
47
- wp_send_json(true);
48
- });
49
 
50
- /**
51
- * AJAX обработчик массовой сохранения уровня сжатия
52
- */
53
- add_action('wp_ajax_wio_settings_update_level', function () {
54
- check_admin_referer('wio-iph');
55
 
56
- $level = $_POST['level'];
 
 
57
 
58
- if( !$level ) {
59
- die();
60
- }
61
- if( !in_array($level, array('normal', 'aggresive', 'ultra')) ) {
62
- die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
- WIO_Plugin::app()->updateOption('image_optimization_level', $level);
65
- die();
66
- });
 
 
 
 
1
  <?php
2
+ /**
3
+ * Back-up related filters.
4
+ *
5
+ * @author Webcraftic <wordpress.webraftic@gmail.com>
6
+ * @copyright (c) 2018 Webraftic Ltd
7
+ * @version 1.0
8
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
 
 
14
 
15
+ /**
16
+ * AJAX обработчик восстановления из резервной копии
17
+ */
18
+ add_action( 'wp_ajax_wio_restore_backup', function () {
19
+ check_admin_referer( 'wio-iph' );
 
20
 
21
+ if ( ! current_user_can( 'manage_options' ) ) {
22
+ wp_die( - 1 );
23
+ }
 
 
24
 
25
+ $max_process_per_request = 25;
 
 
 
26
 
27
+ //$blog_id = WRIO_Plugin::app()->request->post( 'blog_id', null, true );
 
 
 
 
28
 
29
+ /*if ( $blog_id !== null ) {
30
+ switch_to_blog( $blog_id );
31
+ }*/
32
 
33
+ // Total number of remained images to restore
34
+ $remane_count = 0;
35
+
36
+ $total = 0;
37
+
38
+ $filter_results = apply_filters( 'wbcr/rio/backup/restore_filter', $max_process_per_request );
39
+
40
+ if ( isset( $filter_results['remane'] ) ) {
41
+ $remane_count += $filter_results['remane'];
42
+ }
43
+
44
+ if ( isset( $filter_results['total'] ) ) {
45
+ $total += $filter_results['total'];
46
+ }
47
+
48
+ $media_library = WRIO_Media_Library::get_instance();
49
+
50
+ $total += $media_library->getOptimizedCount();
51
+
52
+ $restored_data = $media_library->restoreAllFromBackup( $max_process_per_request );
53
+
54
+ if ( isset( $restored_data['remain'] ) ) {
55
+ $remane_count += $restored_data['remain'];
56
+ }
57
+
58
+ /*if ( $blog_id !== null ) {
59
+ restore_current_blog();
60
+ }*/
61
+
62
+ $restored_data['total'] = $total;
63
+
64
+ if ( $total > 0 ) {
65
+ $restored_data['percent'] = 100 - ( $remane_count * 100 / $total );
66
+ } else {
67
+ $restored_data['percent'] = 0;
68
+ }
69
+
70
+ // если изображения закончились - посылаем команду завершения
71
+ if ( $remane_count <= 0 ) {
72
+ $restored_data['end'] = true;
73
+ }
74
+
75
+ wp_send_json( $restored_data );
76
+ } );
77
+
78
+ /**
79
+ * AJAX обработчик очистки папки с бекапами
80
+ */
81
+ add_action( 'wp_ajax_wio_clear_backup', function () {
82
+ check_admin_referer( 'wio-iph' );
83
+
84
+ if ( ! current_user_can( 'manage_options' ) ) {
85
+ wp_die( - 1 );
86
+ }
87
+
88
+ $backup = WIO_Backup::get_instance();
89
+ $blogs = WRIO_Plugin::app()->request->post( 'blogs', [], true );
90
+
91
+ if ( ! empty( $blogs ) ) {
92
+ foreach ( $blogs as $blog_id ) {
93
+ switch_to_blog( intval( $blog_id ) );
94
+ $backup->removeBlogBackupDir();
95
+ restore_current_blog();
96
  }
97
+ } else {
98
+ $backup->removeBackupDir();
99
+ }
100
+
101
+ wp_send_json( true );
102
+ } );
103
+
admin/ajax/bulk-optimization.php ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Webcraftic <wordpress.webraftic@gmail.com>
4
+ * @copyright (c) 2018 Webraftic Ltd
5
+ * @version 1.0
6
+ */
7
+
8
+ // Exit if accessed directly
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Cron start
15
+ */
16
+ add_action( 'wp_ajax_wrio-cron-start', function () {
17
+ check_ajax_referer( 'bulk_optimization' );
18
+
19
+ if ( ! current_user_can( 'manage_options' ) ) {
20
+ wp_die( - 1 );
21
+ }
22
+
23
+ $scope = WRIO_Plugin::app()->request->request( 'scope', null, true );
24
+
25
+ if ( empty( $scope ) ) {
26
+ wp_die( - 1 );
27
+ }
28
+
29
+ // where was runned cron
30
+ $cron_running_place = WRIO_Plugin::app()->getPopulateOption( 'cron_running', false );
31
+
32
+ if ( $scope == $cron_running_place ) {
33
+ wp_send_json_success();
34
+ }
35
+
36
+ WRIO_Plugin::app()->updatePopulateOption( 'cron_running', $scope );
37
+ WRIO_Cron::start();
38
+
39
+ wp_send_json_success();
40
+ } );
41
+
42
+ /**
43
+ * Cron stop
44
+ */
45
+ add_action( 'wp_ajax_wrio-cron-stop', function () {
46
+ check_ajax_referer( 'bulk_optimization' );
47
+
48
+ if ( ! current_user_can( 'manage_options' ) ) {
49
+ wp_die( - 1 );
50
+ }
51
+
52
+ WRIO_Plugin::app()->updatePopulateOption( 'cron_running', false );
53
+ WRIO_Cron::stop();
54
+
55
+ wp_send_json_success();
56
+ } );
57
+
58
+ /**
59
+ * AJAX обработчик массовой оптимизации изображений со страницы статистики
60
+ */
61
+ add_action( 'wp_ajax_wrio-bulk-optimization-process', function () {
62
+ check_admin_referer( 'bulk_optimization' );
63
+
64
+ if ( ! current_user_can( 'manage_options' ) ) {
65
+ wp_die( - 1 );
66
+ }
67
+
68
+ $reset_current_error = (bool) WRIO_Plugin::app()->request->request( 'reset_current_errors' );
69
+ $scope = WRIO_Plugin::app()->request->request( 'scope', null, true );
70
+
71
+ WRIO_Logger::info( sprintf( 'Start bulk optimization process! Scope: %s', $scope ) );
72
+
73
+ if ( empty( $scope ) ) {
74
+ wp_die( - 1 );
75
+ }
76
+
77
+ // Context class name. If plugin expands with add-ons
78
+ $class_name = 'WRIO_' . wrio_dashes_to_camel_case( $scope, true );
79
+
80
+ if ( ! class_exists( $class_name ) ) {
81
+ WRIO_Logger::error( sprintf( 'Bulk optimization error: Context class (%s) not found.', $class_name ) );
82
+
83
+ //todo: Temporary bug fix.
84
+ if ( 'media-library' === $scope ) {
85
+ $class_name = 'WRIO_Media_Library';
86
+ } else if ( 'custom-folders' === $scope ) {
87
+ $class_name = 'WRIO_Custom_Folders';
88
+ } else if ( 'nextgen-gallery' == $scope ) {
89
+ $class_name = 'WRIO_Nextgen_Gallery';
90
+ }
91
+
92
+ if ( ! class_exists( $class_name ) ) {
93
+ wp_send_json_error( [ 'error_message' => 'Context class not found.' ] );
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Create an instance of the class depending on the context in which scope user
99
+ * has runned optimization.
100
+ *
101
+ * @see WRIO_Media_Library
102
+ * @see WRIO_Custom_Folders
103
+ * @see WRIO_Nextgen_Gallery
104
+ */
105
+ $optimizer = new $class_name();
106
+
107
+ // в ajax запросе мы не знаем, получен ли он из мультиадминки или из обычной. Поэтому проверяем параметр, полученный из frontend
108
+ /*if ( isset( $_POST['multisite'] ) && (bool) $_POST['multisite'] ) {
109
+ $multisite = new WIO_Multisite;
110
+ $multisite->initHooks();
111
+ }*/
112
+
113
+ if ( $reset_current_error ) {
114
+ $optimizer->resetCurrentErrors(); // сбрасываем текущие ошибки оптимизации
115
+ }
116
+
117
+ $result = $optimizer->processUnoptimizedImages( 1 );
118
+
119
+ if ( is_wp_error( $result ) ) {
120
+ $error_massage = $result->get_error_message();
121
+
122
+ if ( empty( $error ) ) {
123
+ $error_massage = __( "Unknown error. Enable error log on the plugin's settings page, then check the error report on the Error Log page. You can export the error report and send it to the support service of the plugin.", "robin-image-optimizer" );
124
+ }
125
+
126
+ WRIO_Logger::error( sprintf( 'Bulk optimization error: %s.', $result->get_error_message() ) );
127
+
128
+ wp_send_json_error( [ 'error_message' => $error_massage ] );
129
+ }
130
+
131
+ // если изображения закончились - посылаем команду завершения
132
+ if ( $result['remain'] <= 0 ) {
133
+ $result['end'] = true;
134
+ }
135
+
136
+ WRIO_Logger::info( sprintf( 'End bulk optimization process! Scope: %s. Remain: %d', $scope, $result['remain'] ) );
137
+
138
+ wp_send_json_success( $result );
139
+ } );
140
+
141
+ /**
142
+ * Переоптимизация аттачмента
143
+ */
144
+ add_action( 'wp_ajax_wio_reoptimize_image', function () {
145
+
146
+ if ( ! current_user_can( 'manage_options' ) ) {
147
+ wp_die( - 1 );
148
+ }
149
+
150
+ $default_level = WRIO_Plugin::app()->getPopulateOption( 'image_optimization_level', 'normal' );
151
+
152
+ $attachment_id = (int) WRIO_Plugin::app()->request->post( 'id' );
153
+ $level = WRIO_Plugin::app()->request->post( 'level', $default_level, true );
154
+
155
+ $backup = WIO_Backup::get_instance();
156
+ $media_library = WRIO_Media_Library::get_instance();
157
+ $backup_origin_images = WRIO_Plugin::app()->getPopulateOption( 'backup_origin_images', false );
158
+
159
+ if ( $backup_origin_images && ! $backup->isBackupWritable() ) {
160
+ echo $media_library->getMediaColumnContent( $attachment_id );
161
+ die();
162
+ }
163
+
164
+ $optimized_data = $media_library->optimizeAttachment( $attachment_id, $level );
165
+
166
+ if ( $optimized_data && isset( $optimized_data['processing'] ) ) {
167
+ echo 'processing';
168
+ die();
169
+ }
170
+
171
+ echo $media_library->getMediaColumnContent( $attachment_id );
172
+ die();
173
+ } );
174
+
175
+ /**
176
+ * Восстановление аттачмента из резервной копии
177
+ */
178
+ add_action( 'wp_ajax_wio_restore_image', function () {
179
+
180
+ if ( ! current_user_can( 'manage_options' ) ) {
181
+ wp_die( - 1 );
182
+ }
183
+
184
+ $attachment_id = (int) WRIO_Plugin::app()->request->post( 'id' );
185
+
186
+ $media_library = WRIO_Media_Library::get_instance();
187
+ $wio_attachment = $media_library->getAttachment( $attachment_id );
188
+
189
+ if ( $wio_attachment->isOptimized() ) {
190
+ $media_library->restoreAttachment( $attachment_id );
191
+ }
192
+
193
+ echo $media_library->getMediaColumnContent( $attachment_id );
194
+ die();
195
+ } );
196
+
197
+ /**
198
+ * На странице массовой оптмизации есть поле для выбора сервера. Когда пользователь
199
+ * выберет какой-то сервер, выполняется этот ajax обработчик. Обработчик пингует выбранный
200
+ * пользователем сервер и возвращает статус пинга (если пинг успешен, то сервер переход в
201
+ * статус выбранный).
202
+ */
203
+ add_action( 'wp_ajax_wbcr-rio-check-servers-status', function () {
204
+
205
+ check_ajax_referer( 'bulk_optimization' );
206
+
207
+ if ( ! current_user_can( 'manage_options' ) ) {
208
+ wp_die( - 1 );
209
+ }
210
+
211
+ $server_name = WRIO_Plugin::app()->request->post( 'server_name' );
212
+
213
+ if ( empty( $server_name ) || ! in_array( $server_name, [
214
+ 'server_1',
215
+ 'server_2',
216
+ 'server_3',
217
+ 'server_4'
218
+ ] ) ) {
219
+ wp_send_json_error( [ 'error' => __( 'Server name is empty!', 'robin-image-optimizer' ) ] );
220
+ }
221
+
222
+ // Позволяем выбрать сервер, даже если он недоступен.
223
+ WRIO_Plugin::app()->updatePopulateOption( 'image_optimization_server', $server_name );
224
+
225
+ // Проверяем доступность сервер
226
+ // --------------------------------------------------------------------
227
+ $return_data = [ 'server_name' => $server_name ];
228
+
229
+ $server_url = wrio_get_server_url( $server_name );
230
+
231
+ $method = 'POST';
232
+ if ( $server_name == 'server_4' ) {
233
+ $api_url = $server_url . '/upload/' . wrio_generate_random_string( 16 ) . '/';
234
+ } else if ( $server_name == 'server_3' ) {
235
+ $api_url = $server_url . '/s.w.org/images/home/screen-themes.png';
236
+ $method = 'GET';
237
+ } else {
238
+ $api_url = $server_url;
239
+ }
240
+
241
+ $request = wp_remote_request( $api_url, [
242
+ 'method' => $method
243
+ ] );
244
+
245
+ if ( is_wp_error( $request ) ) {
246
+ $er_msg = $request->get_error_message();
247
+
248
+ if ( "server_2" == $server_name ) {
249
+ // Hostgator Issue.
250
+ if ( ! empty( $er_msg ) && strpos( $er_msg, 'SSL CA cert' ) !== false ) {
251
+ // Update DB for using http protocol.
252
+ WRIO_Plugin::app()->updatePopulateOption( 'use_http', 1 );
253
+ }
254
+ }
255
+
256
+ $return_data['error'] = $er_msg;
257
+ wp_send_json_error( $return_data );
258
+ }
259
+
260
+ $response_code = wp_remote_retrieve_response_code( $request );
261
+
262
+ if ( $response_code != 200 ) {
263
+ $return_data['error'] = 'Server response ' . $response_code;
264
+ wp_send_json_error( $return_data );
265
+ }
266
+
267
+ wp_send_json_success( $return_data );
268
+ } );
admin/ajax/check-servers-status.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
- /**
3
- * Ajax действие, которое выполняется для проверки статуса серверов
4
- *
5
- * @author Webcraftic <wordpress.webraftic@gmail.com>
6
- * @copyright (c) 2018 Webraftic Ltd
7
- * @version 1.0
8
- */
9
-
10
- // Exit if accessed directly
11
- if( !defined('ABSPATH') ) {
12
- exit;
13
- }
14
-
15
- function wbcr_rio_check_servers_status()
16
- {
17
- $server_name = WIO_Plugin::app()->request->post('server_name');
18
-
19
- if( empty($server_name) || !in_array($server_name, array('server_1', 'server_2', 'server_3', 'server_4')) ) {
20
- wp_send_json_error(array('error' => 'Server name is empty!'));
21
- }
22
-
23
- $return_data = array('server_name' => $server_name);
24
-
25
- $server_url = wbcr_rio_get_server_url($server_name);
26
-
27
- $method = 'POST';
28
- if( $server_name == 'server_4' ) {
29
- $api_url = $server_url . '/upload/' . wbcr_rio_generate_random_string(16) . '/';
30
- } else if($server_name == 'server_3') {
31
- $api_url = $server_url . '/s.w.org/images/home/screen-themes.png';
32
- $method = 'GET';
33
- } else {
34
- $api_url = $server_url;
35
- }
36
-
37
- $request = wp_remote_request($api_url, array(
38
- 'method' => $method
39
- ));
40
-
41
- if( is_wp_error($request) ) {
42
- $return_data['error'] = $request->get_error_message();
43
- wp_send_json_error($return_data);
44
- }
45
-
46
- $response_code = wp_remote_retrieve_response_code($request);
47
-
48
- if( $response_code != 200 ) {
49
- $return_data['error'] = 'Server response ' . $response_code;
50
- wp_send_json_error($return_data);
51
- }
52
-
53
- wp_send_json_success($return_data);
54
- }
55
-
56
- add_action('wp_ajax_wbcr_rio_check_servers_status', 'wbcr_rio_check_servers_status');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/ajax/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // silence is golden
admin/ajax/logs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Used to clean-up logs.
5
+ */
6
+ add_action( 'wp_ajax_wrio_logs_cleanup', function () {
7
+ check_admin_referer( 'wrio_clean_logs', 'nonce' );
8
+
9
+ if ( ! current_user_can( 'manage_options' ) ) {
10
+ wp_die( - 1 );
11
+ }
12
+
13
+ if ( ! WRIO_Logger::clean_up() ) {
14
+ wp_send_json_error( [
15
+ 'message' => esc_html__( 'Failed to clean-up logs. Please try again later.', 'robin-image-optimizer' ),
16
+ 'type' => 'danger',
17
+ ] );
18
+ }
19
+
20
+ wp_send_json( [
21
+ 'message' => esc_html__( 'Logs clean-up successfully', 'robin-image-optimizer' ),
22
+ 'type' => 'success',
23
+ ] );
24
+ } );
admin/ajax/meta-migrations.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ajax action to migrate old architecture based on post meta into new table.
4
+ *
5
+ * @author Webcraftic <wordpress.webraftic@gmail.com>
6
+ * @author Alexander Teshabaev <sasha.tesh@gmail.com>
7
+ * @see RIO_Process_Queue for further information.
8
+ *
9
+ * @copyright (c) 2018 Webraftic Ltd
10
+ * @version 1.0
11
+ */
12
+
13
+ // Exit if accessed directly
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit;
16
+ }
17
+
18
+ add_action( 'wp_ajax_wrio_meta_migrations', 'wbcr_rio_migrate_postmeta_to_process_queue' );
19
+
20
+ /**
21
+ * Migrating postmeta to newly created table.
22
+ *
23
+ * @author Alexander Teshabaev <sasha.tesh@gmail.com>
24
+ * @since 1.3.0
25
+ * @see RIO_Process_Queue as referce for new table.
26
+ */
27
+ function wbcr_rio_migrate_postmeta_to_process_queue() {
28
+ global $wpdb;
29
+
30
+ check_admin_referer( 'wrio-meta-migrations' );
31
+
32
+ if ( ! current_user_can( 'manage_options' ) ) {
33
+ wp_die( - 1 );
34
+ }
35
+
36
+ $error = (int) WRIO_Plugin::app()->request->post( 'error', 0 );
37
+
38
+ if ( $error ) {
39
+ WRIO_Logger::error( 'Previous migration was not completed due to an error.' );
40
+ }
41
+
42
+ $limit = (int) WRIO_Plugin::app()->request->post( 'limit', 150 );
43
+
44
+ $processed_items = 0;
45
+
46
+ WRIO_Logger::info( 'Start meta migration. Limit ' . $limit );
47
+ WRIO_Logger::memory_usage();
48
+
49
+ $attachments = wbcr_rio_get_meta_to_migrate();
50
+
51
+ if ( isset( $attachments->posts ) && ( $attachments_total = count( $attachments->posts ) ) > 0 ) {
52
+
53
+ if ( $attachments_total < $limit ) {
54
+ $limit = $attachments_total;
55
+ }
56
+
57
+ WRIO_Logger::info( 'Finded ' . $attachments_total . ' attachments for migration.' );
58
+
59
+ if ( function_exists( 'wp_raise_memory_limit' ) ) {
60
+ wp_raise_memory_limit( 'image' );
61
+ }
62
+
63
+ WRIO_Logger::memory_usage();
64
+
65
+ /**
66
+ * @var WP_Post $attachment
67
+ */
68
+ for ( $i = 0; $i < $limit; $i ++ ) {
69
+ $attachment = $attachments->posts[ $i ];
70
+ $post_meta = get_post_custom( $attachment->ID );
71
+
72
+ $extra_data = new RIO_Attachment_Extra_Data();
73
+
74
+ $is_backed_up = false;
75
+ $original_size = 0;
76
+ $final_size = 0;
77
+
78
+ if ( isset( $post_meta['wio_backuped'][0] ) && $post_meta['wio_backuped'][0] ) {
79
+ $is_backed_up = true;
80
+ }
81
+
82
+ if ( isset( $post_meta['wio_thumbnails_count'][0] ) ) {
83
+ $extra_data->set_thumbnails_count( intval( $post_meta['wio_thumbnails_count'][0] ) );
84
+ }
85
+
86
+ if ( isset( $post_meta['wio_original_size'][0] ) ) {
87
+ $original_size = intval( $post_meta['wio_original_size'][0] );
88
+ }
89
+
90
+ if ( isset( $post_meta['wio_optimized_size'][0] ) ) {
91
+ $final_size = intval( $post_meta['wio_optimized_size'][0] );
92
+ }
93
+
94
+ if ( isset( $post_meta['wio_original_main_size'][0] ) ) {
95
+ $extra_data->set_original_main_size( intval( $post_meta['wio_original_main_size'][0] ) );
96
+ }
97
+
98
+ if ( isset( $post_meta['wio_error'][0] ) ) {
99
+ $extra_data->set_error( 'optimization' );
100
+ $extra_data->set_error_msg( $post_meta['wio_error'][0] );
101
+ }
102
+
103
+ $level = 'normal';
104
+
105
+ if ( isset( $post_meta['wio_optimization_level'][0] ) && ! empty( $post_meta['wio_optimization_level'][0] ) ) {
106
+ $level = $post_meta['wio_optimization_level'][0];
107
+ }
108
+
109
+ $data = [
110
+ 'server_id' => null,
111
+ 'object_id' => $attachment->ID,
112
+ 'object_name' => $wpdb->posts,
113
+ 'item_type' => 'attachment',
114
+ 'result_status' => ! $final_size ? 'error' : 'success',
115
+ 'processing_level' => $level,
116
+ 'is_backed_up' => $is_backed_up,
117
+ 'original_size' => $original_size,
118
+ 'final_size' => $final_size,
119
+ 'original_mime_type' => $attachment->post_mime_type,
120
+ 'final_mime_type' => $attachment->post_mime_type,
121
+ 'extra_data' => (string) $extra_data,
122
+ 'created_at' => time(),
123
+ ];
124
+
125
+ $format = [
126
+ '%s',
127
+ '%d',
128
+ '%s',
129
+ '%s',
130
+ '%s',
131
+ '%s',
132
+ '%d',
133
+ '%d',
134
+ '%d',
135
+ '%s',
136
+ '%s',
137
+ '%s',
138
+ '%d',
139
+ ];
140
+
141
+ $rows_inserted = $wpdb->insert( RIO_Process_Queue::table_name(), $data, $format );
142
+
143
+ if ( $rows_inserted > 0 ) {
144
+ $processed_items ++;
145
+
146
+ $attachment_id = absint( $attachment->ID );
147
+ $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE post_id='{$attachment_id}' AND meta_key LIKE 'wio_%'" );
148
+ }
149
+ }
150
+
151
+ $left_items = $attachments_total - $processed_items;
152
+ $message = sprintf( __( 'left to migrate: %s items', 'robin-image-optimizer' ), $left_items );
153
+ $need_more_time = true;
154
+
155
+ WRIO_Logger::info( 'Succefull migrated ' . $processed_items . ' items.' );
156
+ } else {
157
+ WRIO_Logger::info( 'Succefull migrated all items. Finishing-up...' );
158
+
159
+ // Assumed to be 2 after 010105.php migration
160
+ WRIO_Plugin::app()->updateOption( 'db_version', 2 );
161
+
162
+ $need_more_time = false;
163
+ $message = __( 'Finishing-up...', 'robin-image-optimizer' );
164
+ }
165
+
166
+ WRIO_Logger::memory_usage();
167
+
168
+ wp_send_json_success( [
169
+ 'need_more_time' => $need_more_time,
170
+ 'message' => $message,
171
+ ] );
172
+ }
173
+
174
+
admin/ajax/multisite-update-current-blog.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ajax действие, которое выполняется для смены текущего multisite блога
4
+ *
5
+ * @author Webcraftic <wordpress.webraftic@gmail.com>
6
+ * @copyright (c) 2018 Webraftic Ltd
7
+ * @version 1.0
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ /*add_action( 'wp_ajax_wbcr_rio_update_current_blog', function () {
16
+ check_ajax_referer( 'update_blog_id', 'wpnonce' );
17
+ $blog_id = (int) WRIO_Plugin::app()->request->post( 'current_blog_id' );
18
+ $context = sanitize_text_field( WRIO_Plugin::app()->request->post( 'context' ) );
19
+ WRIO_Plugin::app()->updatePopulateOption( 'current_blog', $blog_id );
20
+ $image_statistics = WIO_OptimizationTools::getImageStatistics( $context );
21
+
22
+ switch_to_blog( $blog_id );
23
+ $statistic_data = $image_statistics->load();
24
+ restore_current_blog();
25
+
26
+ wp_send_json_success( array(
27
+ 'statistic' => $statistic_data,
28
+ ) );
29
+ } );*/
admin/ajax/optimization.php DELETED
@@ -1,46 +0,0 @@
1
- <?php
2
- /**
3
- * Optimization
4
- *
5
- * @author Webcraftic <wordpress.webraftic@gmail.com>
6
- * @copyright (c) 22.10.2018, Webcraftic
7
- * @version 1.0
8
- */
9
-
10
- /**
11
- * AJAX обработчик массовой оптимизации изображений со страницы статистики
12
- */
13
- add_action('wp_ajax_wio_process_images', function () {
14
- check_admin_referer('wio-iph');
15
-
16
- $cron_mode = (bool)WIO_Plugin::app()->request->request('cron_mode');
17
- $reset_current_error = (bool)WIO_Plugin::app()->request->request('reset_current_error');
18
-
19
- $media_library = new WIO_MediaLibrary();
20
- if ( $reset_current_error ) {
21
- $media_library->resetCurrentErrors(); // сбрасываем текущие ошибки оптимизации
22
- }
23
-
24
- if( $cron_mode ) {
25
- $cron_running = WIO_Plugin::app()->getOption('cron_running', false);
26
- if( $cron_running ) {
27
- WIO_Plugin::app()->updateOption('cron_running', false);
28
- WIO_Cron::stop();
29
- } else {
30
- WIO_Plugin::app()->updateOption('cron_running', true);
31
- WIO_Cron::start();
32
- }
33
-
34
- wp_send_json(true);
35
- die();
36
- }
37
- $max_process_per_request = 1;
38
- $optimized_data = $media_library->processUnoptimizedAttachments($max_process_per_request);
39
-
40
- // если изображения закончились - посылаем команду завершения
41
- if( $optimized_data['remain'] <= 0 ) {
42
- $optimized_data['end'] = true;
43
- }
44
-
45
- wp_send_json($optimized_data);
46
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/ajax/select-server.php DELETED
@@ -1,31 +0,0 @@
1
- <?php
2
- /**
3
- * Ajax действие, которое выполняется для выбора нового сервера оптимизации
4
- *
5
- * @author Webcraftic <wordpress.webraftic@gmail.com>
6
- * @copyright (c) 2018 Webraftic Ltd
7
- * @version 1.0
8
- */
9
-
10
- // Exit if accessed directly
11
- if( !defined('ABSPATH') ) {
12
- exit;
13
- }
14
-
15
- function wbcr_rio_select_server()
16
- {
17
- $server_name = WIO_Plugin::app()->request->post('server_name');
18
-
19
- if( empty($server_name) ) {
20
- wp_send_json_error(array('error' => 'Server name is empty!'));
21
- }
22
-
23
- check_ajax_referer('wbcr_rio_select_' . $server_name);
24
-
25
- WIO_Plugin::app()->updateOption('image_optimization_server', $server_name);
26
-
27
- wp_send_json_success();
28
- }
29
-
30
- add_action('wp_ajax_wbcr_rio_select_server', 'wbcr_rio_select_server');
31
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/ajax/settings.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ajax действие, которое выполняется при сохранении настроек
4
+ *
5
+ * @author Webcraftic <wordpress.webraftic@gmail.com>
6
+ * @copyright (c) 2018 Webraftic Ltd
7
+ * @version 1.0
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ /**
16
+ * AJAX обработчик массовой сохранения уровня сжатия
17
+ */
18
+ add_action( 'wp_ajax_wio_settings_update_level', function () {
19
+ check_admin_referer( 'wio-iph' );
20
+
21
+ if ( ! current_user_can( 'manage_options' ) ) {
22
+ wp_die( - 1 );
23
+ }
24
+
25
+ $level = sanitize_text_field( $_POST['level'] );
26
+
27
+ if ( ! $level ) {
28
+ die();
29
+ }
30
+
31
+ if ( ! in_array( $level, [ 'normal', 'aggresive', 'ultra' ] ) ) {
32
+ die();
33
+ }
34
+
35
+ WRIO_Plugin::app()->updatePopulateOption( 'image_optimization_level', $level );
36
+ die();
37
+ } );
admin/assets/css/base-statistic.css CHANGED
@@ -1,436 +1,657 @@
1
- /**
2
- * Styles for the Widget to be displayed in the Clearfy plugin
3
-
4
- * @author Alex Kovalev <alex.kovalevv@gmail.com>
5
- * @copyright Webcraftic 13.06.2018
6
- */
7
- #WBCR {
8
- /* Number display */
9
- /* Number and bars */
10
- /* Doughnut */
11
- /* Widget */
12
- /*@media (max-width: 1380px) and (min-width: 1246px), (max-width: 380px) {
13
- .wio-overview-chart-container {
14
- float: none;
15
- margin-right: 0;
16
- }
17
- }
18
-
19
- @media (max-width: 1380px) and (min-width: 1246px), (max-width: 380px) {
20
- .wio-overview-chart-container {
21
- float: none;
22
- margin-right: 0;
23
- }
24
-
25
- .wio-doughnut-legend {
26
- margin-top: 18px;
27
- }
28
-
29
- .wio-global-optim-phrase {
30
- padding-top: 0;
31
- width: auto;
32
- }
33
- }*/
34
- }
35
- #WBCR .wio-clear {
36
- clear: both;
37
- }
38
- #WBCR .wbcr-rio-servers {
39
- margin-top: 30px;
40
- background: none;
41
- padding: 0;
42
- }
43
- #WBCR .wbcr-rio-servers h4 {
44
- font-size: 15px;
45
- font-weight: 700;
46
- }
47
- #WBCR .wbcr-rio-servers button {
48
- padding: 5px 10px;
49
- border: 0;
50
- font-size: 11px;
51
- text-transform: uppercase !important;
52
- font-weight: bold;
53
- border-radius: 4px;
54
- outline: none;
55
- background: #f3f3f3;
56
- color: #656565;
57
- box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
58
- }
59
- #WBCR .wbcr-rio-servers button:active {
60
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.5);
61
- }
62
- #WBCR .wbcr-rio-servers button.wbcr-rio-loading {
63
- width: 56px;
64
- font-size: 0;
65
- background: #f3f3f3 url("../img/quick-start-loader.gif") center no-repeat;
66
- }
67
- #WBCR .wbcr-rio-servers button.wbcr-rio-selected {
68
- background: #f3efe2;
69
- color: #d8d8d8;
70
- }
71
- #WBCR .wbcr-rio-servers button.wbcr-rio-selected:active {
72
- box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
73
- }
74
- #WBCR .wbcr-rio-servers table {
75
- width: 100%;
76
- box-sizing: border-box;
77
- border-spacing: 3px;
78
- background: #fff;
79
- border: 2px dashed #cac9c9;
80
- border-left: 0;
81
- border-right: 0;
82
- }
83
- #WBCR .wbcr-rio-servers table th,
84
- #WBCR .wbcr-rio-servers table td {
85
- padding: 16px 10px;
86
- text-align: center;
87
- }
88
- #WBCR .wbcr-rio-servers table th {
89
- background: #f3f3f3;
90
- color: #777777;
91
- box-shadow: 0 1px 0 #d8d8d8;
92
- }
93
- #WBCR .wbcr-rio-servers table th:nth-child(2n+1) {
94
- background: #f9f9f9;
95
- }
96
- #WBCR .wbcr-rio-servers table .wbcr-rio-server-check-proccess {
97
- display: inline-block;
98
- height: 10px;
99
- width: 30px;
100
- background: url("../img/quick-start-loader.gif") center no-repeat;
101
- }
102
- #WBCR .wbcr-rio-servers table .wbcr-rio-servers-list-item-selected {
103
- background: #fffbed;
104
- color: #cec5a8;
105
- font-weight: 600;
106
- }
107
- #WBCR .wbcr-rio-servers table .wbcr-rio-server-success {
108
- color: #8CC152;
109
- }
110
- #WBCR .wbcr-rio-servers table .wbcr-rio-server-error {
111
- color: #fb5d49;
112
- }
113
- #WBCR .wbcr-rio-servers table .wbcr-rio-server-warning {
114
- color: #ffb635;
115
- }
116
- #WBCR .wbcr-rio-servers .wbcr-rio-warning-message {
117
- padding: 20px;
118
- background: #efefef;
119
- font-size: 15px;
120
- color: #b7b7b7;
121
- font-style: italic;
122
- }
123
- #WBCR .wio-columns {
124
- overflow: hidden;
125
- padding: 15px 0;
126
- counter-reset: cols;
127
- }
128
- #WBCR .wio-columns [class^="col-"] {
129
- float: left;
130
- -webkit-box-sizing: border-box;
131
- -moz-box-sizing: border-box;
132
- box-sizing: border-box;
133
- }
134
- #WBCR .wio-columns .col-1-3 {
135
- width: 33.333%;
136
- padding-left: 28px;
137
- }
138
- #WBCR .wio-columns .col-2-3 {
139
- width: 66.666%;
140
- padding-left: 28px;
141
- }
142
- #WBCR .wio-columns .col-1-2 {
143
- width: 50%;
144
- padding: 0 20px;
145
- }
146
- #WBCR .wio-columns .col-statistics.col-statistics {
147
- width: 60%;
148
- }
149
- #WBCR .wio-columns .col-chart.col-chart {
150
- width: 40%;
151
- position: relative;
152
- padding: 20px;
153
- font-size: 12px;
154
- text-transform: uppercase;
155
- background: #f1f1f1b3;
156
- color: #abacaf;
157
- font-weight: bold;
158
- border-radius: 5px;
159
- margin-top: 10px;
160
- text-align: left;
161
- box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
162
- }
163
- #WBCR .wio-col {
164
- float: left;
165
- width: 50%;
166
- box-sizing: border-box;
167
- -webkit-flex-basis: 50%;
168
- -ms-flex-preferred-size: 50%;
169
- flex-basis: 50%;
170
- }
171
- #WBCR .wio-col {
172
- padding-right: 20px;
173
- }
174
- #WBCR .wio-col + .wio-col {
175
- padding-right: 0;
176
- padding-left: 50px;
177
- }
178
- #WBCR .wio-col:target {
179
- animation: wiohello 1s 3 linear backwards;
180
- }
181
- #WBCR .wio-number-you-optimized {
182
- margin-bottom: 1.35em;
183
- overflow: hidden;
184
- }
185
- #WBCR .wio-number-you-optimized #wio-total-optimized-attachments-pct {
186
- color: #828282;
187
- }
188
- #WBCR .wio-number-you-optimized .wio-number {
189
- display: table-cell;
190
- padding-right: 15px;
191
- font-size: 48px;
192
- font-weight: bold;
193
- line-height: 1;
194
- vertical-align: middle;
195
- white-space: nowrap;
196
- color: #828282;
197
- }
198
- #WBCR .wio-number-you-optimized .wio-text {
199
- display: table-cell;
200
- vertical-align: middle;
201
- overflow: hidden;
202
- font-size: 12px;
203
- color: #828282;
204
- }
205
- #WBCR .wio-number-you-optimized > p {
206
- display: table;
207
- }
208
- #WBCR .wio-bars {
209
- padding-right: 15px;
210
- }
211
- #WBCR .wio-bars p {
212
- font-size: 12px;
213
- margin-bottom: 5px;
214
- }
215
- #WBCR .wio-bars + .wio-number-you-optimized {
216
- border-bottom: 0;
217
- padding-top: 0.85em;
218
- }
219
- #WBCR .wio-bars + .wio-number-you-optimized p {
220
- color: #72a53b;
221
- }
222
- #WBCR .wio-bar-negative .wio-progress {
223
- background: #D2D3D6;
224
- }
225
- #WBCR .wio-bar-negative .wio-barnb {
226
- color: #9d9fa5;
227
- }
228
- #WBCR .wio-progress {
229
- height: 8px;
230
- transition: width .3s;
231
- /*.wio-bar-negative {
232
- width: 92% !important;
233
- }*/
234
- }
235
- #WBCR .wio-bar-positive .wio-progress {
236
- background: #8CC152;
237
- }
238
- #WBCR .wio-bar-positive .wio-barnb {
239
- color: #72a53b;
240
- }
241
- #WBCR .wio-bar-primary .wio-progress {
242
- background: #8CC152;
243
- }
244
- #WBCR .wio-bar-primary .wio-barnb {
245
- color: #72a53b;
246
- }
247
- #WBCR .wio-right-outside-number .wio-barnb {
248
- display: block;
249
- margin-right: -5.25em;
250
- text-align: right;
251
- font-weight: bold;
252
- line-height: .8;
253
- }
254
- #WBCR .wio-chart {
255
- position: relative;
256
- top: 1px;
257
- display: inline-block;
258
- vertical-align: middle;
259
- }
260
- #WBCR .wio-chart-container {
261
- position: relative;
262
- display: inline-block;
263
- margin-right: 5px;
264
- }
265
- #WBCR .wio-chart-container canvas {
266
- display: block;
267
- }
268
- #WBCR .wio-overview-chart-container {
269
- float: left;
270
- margin-right: 20px;
271
- }
272
- #WBCR .wio-chart-percent {
273
- position: absolute;
274
- left: 0;
275
- right: 0;
276
- top: 50%;
277
- margin-top: -0.5em;
278
- line-height: 0.8;
279
- text-align: center;
280
- font-size: 54px;
281
- font-weight: bold;
282
- color: #afafaf;
283
- }
284
- #WBCR .wio-chart-percent span {
285
- font-size: 20px;
286
- vertical-align: super;
287
- }
288
- #WBCR #wio-overview-chart-legend {
289
- overflow: hidden;
290
- }
291
- #WBCR .wio-doughnut-legend li {
292
- display: inline-block;
293
- position: relative;
294
- margin-bottom: 15px;
295
- border-radius: 5px;
296
- padding: 3px 8px 2px 31px;
297
- font-size: 9px;
298
- cursor: default;
299
- -webkit-transition: background-color 200ms ease-in-out;
300
- -moz-transition: background-color 200ms ease-in-out;
301
- -o-transition: background-color 200ms ease-in-out;
302
- transition: background-color 200ms ease-in-out;
303
- }
304
- #WBCR .wio-doughnut-legend li span {
305
- display: block;
306
- position: absolute;
307
- left: 0;
308
- top: 0;
309
- width: 25px;
310
- height: 25px;
311
- border-radius: 50%;
312
- }
313
- #WBCR .wio-optimize-button {
314
- width: 180px;
315
- padding: 12px 30px;
316
- background: #c9deb2;
317
- color: #586549;
318
- border: 0;
319
- box-shadow: none;
320
- font-size: 14px;
321
- text-transform: uppercase !important;
322
- font-weight: bold;
323
- border-radius: 4px;
324
- outline: none;
325
- }
326
- #WBCR .wio-optimize-button:active {
327
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.5);
328
- }
329
- #WBCR .wio-optimize-button.wio-running {
330
- color: #a57b3c;
331
- background: #fdd599 url("../img/Spinner-1s-33px.gif") 10px center no-repeat;
332
- }
333
- #WBCR .wio-global-optim-phrase {
334
- width: 180px;
335
- padding-top: 20px;
336
- font-size: 14px;
337
- text-align: center;
338
- }
339
- #WBCR .wio-total-percent {
340
- color: #587f2e;
341
- }
342
- #WBCR #wio-start-msg-top,
343
- #WBCR #wio-start-msg-right,
344
- #WBCR #wio-start-msg-complete {
345
- display: none;
346
- }
347
- #WBCR .wio-text-left {
348
- text-align: left;
349
- }
350
- #WBCR span.wio-num {
351
- display: inline !important;
352
- position: inherit !important;
353
- }
354
- #WBCR .wio-image-optimize-board {
355
- padding-bottom: 0 !important;
356
- }
357
- #WBCR .wio-page-statistic {
358
- padding-left: 40px;
359
- }
360
- #WBCR .wio-page-statistic .wio-chart-percent {
361
- margin-top: -1.1em;
362
- }
363
- #WBCR .wio-widget {
364
- padding: 0 !important;
365
- }
366
- #WBCR .wio-widget .wio-chart-percent {
367
- font-size: 44px;
368
- line-height: 1;
369
- }
370
- #WBCR .wio-widget .wio-bars {
371
- width: 60%;
372
- margin-left: 155px;
373
- }
374
- #WBCR .wio-widget .col-chart.col-chart {
375
- width: 100%;
376
- }
377
- #WBCR .wio-widget .col-controls {
378
- width: 45%;
379
- padding-left: 5px;
380
- padding-top: 110px;
381
- }
382
- #WBCR .wio-widget .wio-doughnut-legend {
383
- /*padding-top:30px;*/
384
- text-align: left;
385
- }
386
- #WBCR .wio-widget .wio-widget-bottom {
387
- display: table;
388
- padding-top: 20px !important;
389
- width: 100%;
390
- text-align: right;
391
- }
392
- #WBCR .wio-widget .wio-widget-bottom li {
393
- display: table-cell;
394
- }
395
- #WBCR .wio-widget .wio-widget-bottom li:first-child {
396
- text-align: left;
397
- }
398
- @media (max-width: 830px) {
399
- #WBCR .wio [class^="col-"] {
400
- float: none;
401
- margin-bottom: 1.5em;
402
- }
403
- #WBCR .wio .col-1-3,
404
- #WBCR .wio .col-1-2 {
405
- width: auto;
406
- padding: 0 28px;
407
- clear: both;
408
- padding-top: 1em;
409
- }
410
- }
411
- @keyframes wiohello {
412
- 0%,
413
- 100% {
414
- background: #FFF;
415
- }
416
- 50% {
417
- background: #F4F7F9;
418
- }
419
- }
420
- @media (max-width: 1520px) and (min-width: 1381px), (max-width: 1086px) {
421
- #WBCR .wio-columns .col-statistics.col-statistics,
422
- #WBCR .wio-columns .col-chart.col-chart {
423
- width: 50%;
424
- }
425
- }
426
- @media (max-width: 808px) {
427
- #WBCR .wio-columns .col-statistics.col-statistics,
428
- #WBCR .wio-columns .col-chart.col-chart {
429
- width: auto;
430
- float: none;
431
- padding: 0;
432
- }
433
- #WBCR .wio-columns .col-chart.col-chart {
434
- margin-top: 3em;
435
- }
436
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Styles for the Widget to be displayed in the Clearfy plugin
3
+
4
+ * @author Alex Kovalev <alex.kovalevv@gmail.com>
5
+ * @copyright Webcraftic 13.06.2018
6
+ */
7
+ #WBCR {
8
+ /* Doughnut */
9
+ /*@media (max-width: 1380px) and (min-width: 1246px), (max-width: 380px) {
10
+ .wio-overview-chart-container {
11
+ float: none;
12
+ margin-right: 0;
13
+ }
14
+ }
15
+
16
+ @media (max-width: 1380px) and (min-width: 1246px), (max-width: 380px) {
17
+ .wio-overview-chart-container {
18
+ float: none;
19
+ margin-right: 0;
20
+ }
21
+
22
+ .wio-doughnut-legend {
23
+ margin-top: 18px;
24
+ }
25
+
26
+ .wio-global-optim-phrase {
27
+ padding-top: 0;