Clearfy – WordPress optimization plugin and disable ultimate tweaker - Version 1.6.6

Version Description

(29.04.2020) = * Fixed: Minor bugs

Download this release

Release Info

Developer alexkovalevv
Plugin Icon 128x128 Clearfy – WordPress optimization plugin and disable ultimate tweaker
Version 1.6.6
Comparing to
See all releases

Code changes from version 1.6.5 to 1.6.6

admin/ajax/install-addons.php CHANGED
@@ -8,68 +8,69 @@
8
  */
9
 
10
  // Exit if accessed directly
11
- if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
 
15
  /**
16
  * This action allows you to process Ajax requests to activate external components Clearfy
17
  */
18
- function wbcr_clearfy_update_component() {
19
- check_ajax_referer( 'updates' );
 
20
 
21
- $slug = WCL_Plugin::app()->request->post( 'plugin', null, true );
22
- $action = WCL_Plugin::app()->request->post( 'plugin_action', null, true );
23
- $storage = WCL_Plugin::app()->request->post( 'storage', null, true );
24
 
25
- if ( ! WCL_Plugin::app()->currentUserCan() ) {
26
- wp_die( __( 'You don\'t have enough capability to edit this information.', 'clearfy' ), __( 'Something went wrong.' ), 403 );
27
  }
28
 
29
- if ( empty( $slug ) || empty( $action ) ) {
30
- wp_send_json_error( [ 'error_message' => __( 'Required attributes are not passed or empty.', 'clearfy' ) ] );
31
  }
32
- $success = false;
33
  $send_data = [];
34
 
35
- if ( $storage == 'internal' ) {
36
- if ( $action == 'activate' ) {
37
- if ( WCL_Plugin::app()->activateComponent( $slug ) ) {
38
  $success = true;
39
  }
40
- } else if ( $action == 'deactivate' ) {
41
 
42
- if ( WCL_Plugin::app()->deactivateComponent( $slug ) ) {
43
  $success = true;
44
  }
45
  } else {
46
- wp_send_json_error( [ 'error_message' => __( 'You are trying to perform an invalid action.', 'clearfy' ) ] );
47
  }
48
- } else if ( $storage == 'wordpress' ) {
49
- if ( ! empty( $slug ) ) {
50
  $network_wide = WCL_Plugin::app()->isNetworkActive();
51
 
52
- if ( $action == 'activate' ) {
53
- $result = activate_plugin( $slug, '', $network_wide );
54
 
55
- if ( is_wp_error( $result ) ) {
56
- wp_send_json_error( [ 'error_message' => $result->get_error_message() ] );
57
  }
58
- } else if ( $action == 'deactivate' ) {
59
- deactivate_plugins( $slug, false, $network_wide );
60
  }
61
 
62
  $success = true;
63
  }
64
  }
65
 
66
- if ( $action == 'install' || $action == 'deactivate' ) {
67
  try {
68
  // Delete button
69
- $delete_button = WCL_Plugin::app()->getDeleteComponentsButton( $storage, $slug );
70
  $send_data['delete_button'] = $delete_button->getButton();
71
  } catch( Exception $e ) {
72
- wp_send_json_error( [ 'error_message' => $e->getMessage() ] );
73
  }
74
  }
75
 
@@ -83,38 +84,144 @@ function wbcr_clearfy_update_component() {
83
  }
84
  }*/
85
 
86
- if ( $success ) {
87
- do_action( 'wbcr_clearfy_update_component', $slug, $action, $storage );
88
 
89
- wp_send_json_success( $send_data );
90
  }
91
 
92
- wp_send_json_error( [ 'error_message' => __( 'An unknown error occurred during the activation of the component.', 'clearfy' ) ] );
93
  }
94
 
95
- add_action( 'wp_ajax_wbcr-clearfy-update-component', 'wbcr_clearfy_update_component' );
96
 
97
  /**
98
  * Ajax event that calls the wbcr/clearfy/activated_component action,
99
  * to get the component to work. Usually this is a call to the installation functions,
100
  * but in some cases, overwriting permanent references or compatibility checks.
101
  */
102
- function wbcr_clearfy_prepare_component() {
103
- check_ajax_referer( 'updates' );
 
104
 
105
- $component_name = WCL_Plugin::app()->request->post( 'plugin', null, true );
106
 
107
- if ( ! WCL_Plugin::app()->currentUserCan() ) {
108
- wp_send_json_error( [ 'error_message' => __( 'You don\'t have enough capability to edit this information.', 'clearfy' ) ], 403 );
109
  }
110
 
111
- if ( empty( $component_name ) ) {
112
- wp_send_json_error( [ 'error_message' => __( 'Required attribute [component_name] is empty.', 'clearfy' ) ] );
113
  }
114
 
115
- do_action( 'wbcr/clearfy/activated_component', $component_name );
116
 
117
  wp_send_json_success();
118
  }
119
 
120
- add_action( 'wp_ajax_wbcr-clearfy-prepare-component', 'wbcr_clearfy_prepare_component' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  */
9
 
10
  // Exit if accessed directly
11
+ if( !defined('ABSPATH') ) {
12
  exit;
13
  }
14
 
15
  /**
16
  * This action allows you to process Ajax requests to activate external components Clearfy
17
  */
18
+ function wbcr_clearfy_update_component()
19
+ {
20
+ check_ajax_referer('updates');
21
 
22
+ $slug = WCL_Plugin::app()->request->post('plugin', null, true);
23
+ $action = WCL_Plugin::app()->request->post('plugin_action', null, true);
24
+ $storage = WCL_Plugin::app()->request->post('storage', null, true);
25
 
26
+ if( !WCL_Plugin::app()->currentUserCan() ) {
27
+ wp_die(__('You don\'t have enough capability to edit this information.', 'clearfy'), __('Something went wrong.'), 403);
28
  }
29
 
30
+ if( empty($slug) || empty($action) ) {
31
+ wp_send_json_error(['error_message' => __('Required attributes are not passed or empty.', 'clearfy')]);
32
  }
33
+ $success = false;
34
  $send_data = [];
35
 
36
+ if( $storage == 'internal' ) {
37
+ if( $action == 'activate' ) {
38
+ if( WCL_Plugin::app()->activateComponent($slug) ) {
39
  $success = true;
40
  }
41
+ } else if( $action == 'deactivate' ) {
42
 
43
+ if( WCL_Plugin::app()->deactivateComponent($slug) ) {
44
  $success = true;
45
  }
46
  } else {
47
+ wp_send_json_error(['error_message' => __('You are trying to perform an invalid action.', 'clearfy')]);
48
  }
49
+ } else if( $storage == 'wordpress' || $storage == 'creativemotion' ) {
50
+ if( !empty($slug) ) {
51
  $network_wide = WCL_Plugin::app()->isNetworkActive();
52
 
53
+ if( $action == 'activate' ) {
54
+ $result = activate_plugin($slug, '', $network_wide);
55
 
56
+ if( is_wp_error($result) ) {
57
+ wp_send_json_error(['error_message' => $result->get_error_message()]);
58
  }
59
+ } else if( $action == 'deactivate' ) {
60
+ deactivate_plugins($slug, false, $network_wide);
61
  }
62
 
63
  $success = true;
64
  }
65
  }
66
 
67
+ if( $action == 'install' || $action == 'deactivate' ) {
68
  try {
69
  // Delete button
70
+ $delete_button = WCL_Plugin::app()->getDeleteComponentsButton($storage, $slug);
71
  $send_data['delete_button'] = $delete_button->getButton();
72
  } catch( Exception $e ) {
73
+ wp_send_json_error(['error_message' => $e->getMessage()]);
74
  }
75
  }
76
 
84
  }
85
  }*/
86
 
87
+ if( $success ) {
88
+ do_action('wbcr_clearfy_update_component', $slug, $action, $storage);
89
 
90
+ wp_send_json_success($send_data);
91
  }
92
 
93
+ wp_send_json_error(['error_message' => __('An unknown error occurred during the activation of the component.', 'clearfy')]);
94
  }
95
 
96
+ add_action('wp_ajax_wbcr-clearfy-update-component', 'wbcr_clearfy_update_component');
97
 
98
  /**
99
  * Ajax event that calls the wbcr/clearfy/activated_component action,
100
  * to get the component to work. Usually this is a call to the installation functions,
101
  * but in some cases, overwriting permanent references or compatibility checks.
102
  */
103
+ function wbcr_clearfy_prepare_component()
104
+ {
105
+ check_ajax_referer('updates');
106
 
107
+ $component_name = WCL_Plugin::app()->request->post('plugin', null, true);
108
 
109
+ if( !WCL_Plugin::app()->currentUserCan() ) {
110
+ wp_send_json_error(['error_message' => __('You don\'t have enough capability to edit this information.', 'clearfy')], 403);
111
  }
112
 
113
+ if( empty($component_name) ) {
114
+ wp_send_json_error(['error_message' => __('Required attribute [component_name] is empty.', 'clearfy')]);
115
  }
116
 
117
+ do_action('wbcr/clearfy/activated_component', $component_name);
118
 
119
  wp_send_json_success();
120
  }
121
 
122
+ add_action('wp_ajax_wbcr-clearfy-prepare-component', 'wbcr_clearfy_prepare_component');
123
+
124
+ /**
125
+ * Ajax handler for installing a plugin.
126
+ *
127
+ * @since 4.6.0
128
+ *
129
+ * @see Plugin_Upgrader
130
+ *
131
+ * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
132
+ */
133
+ function wbcr_clearfy_prepare_install_plugin()
134
+ {
135
+ check_ajax_referer('updates');
136
+
137
+ if( empty($_POST['slug']) ) {
138
+ wp_send_json_error(array(
139
+ 'slug' => '',
140
+ 'errorCode' => 'no_plugin_specified',
141
+ 'errorMessage' => __('No plugin specified.'),
142
+ ));
143
+ }
144
+
145
+ $status = array(
146
+ 'install' => 'plugin',
147
+ 'slug' => sanitize_key(wp_unslash($_POST['slug'])),
148
+ );
149
+
150
+ if( !current_user_can('install_plugins') ) {
151
+ $status['errorMessage'] = __('Sorry, you are not allowed to install plugins on this site.');
152
+ wp_send_json_error($status);
153
+ }
154
+
155
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
156
+ include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
157
+
158
+ $api = plugins_api('plugin_information', array(
159
+ 'slug' => sanitize_key(wp_unslash($_POST['slug'])),
160
+ 'fields' => array(
161
+ 'sections' => false,
162
+ ),
163
+ ));
164
+
165
+ if( is_wp_error($api) ) {
166
+ $status['errorMessage'] = $api->get_error_message();
167
+ wp_send_json_error($status);
168
+ }
169
+
170
+ $status['pluginName'] = $api->name;
171
+
172
+ $skin = new WP_Ajax_Upgrader_Skin();
173
+ $upgrader = new Plugin_Upgrader($skin);
174
+ //$result = $upgrader->install($api->download_link);
175
+ $result = $upgrader->install('https://clearfy.pro/components/download.php');
176
+
177
+ if( defined('WP_DEBUG') && WP_DEBUG ) {
178
+ $status['debug'] = $skin->get_upgrade_messages();
179
+ }
180
+
181
+ if( is_wp_error($result) ) {
182
+ $status['errorCode'] = $result->get_error_code();
183
+ $status['errorMessage'] = $result->get_error_message();
184
+ wp_send_json_error($status);
185
+ } elseif( is_wp_error($skin->result) ) {
186
+ $status['errorCode'] = $skin->result->get_error_code();
187
+ $status['errorMessage'] = $skin->result->get_error_message();
188
+ wp_send_json_error($status);
189
+ } elseif( $skin->get_errors()->has_errors() ) {
190
+ $status['errorMessage'] = $skin->get_error_messages();
191
+ wp_send_json_error($status);
192
+ } elseif( is_null($result) ) {
193
+ global $wp_filesystem;
194
+
195
+ $status['errorCode'] = 'unable_to_connect_to_filesystem';
196
+ $status['errorMessage'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
197
+
198
+ // Pass through the error from WP_Filesystem if one was raised.
199
+ if( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->has_errors() ) {
200
+ $status['errorMessage'] = esc_html($wp_filesystem->errors->get_error_message());
201
+ }
202
+
203
+ wp_send_json_error($status);
204
+ }
205
+
206
+ $install_status = install_plugin_install_status($api);
207
+ $pagenow = isset($_POST['pagenow']) ? sanitize_key($_POST['pagenow']) : '';
208
+
209
+ // If installation request is coming from import page, do not return network activation link.
210
+ $plugins_url = ('import' === $pagenow) ? admin_url('plugins.php') : network_admin_url('plugins.php');
211
+
212
+ if( current_user_can('activate_plugin', $install_status['file']) && is_plugin_inactive($install_status['file']) ) {
213
+ $status['activateUrl'] = add_query_arg(array(
214
+ '_wpnonce' => wp_create_nonce('activate-plugin_' . $install_status['file']),
215
+ 'action' => 'activate',
216
+ 'plugin' => $install_status['file'],
217
+ ), $plugins_url);
218
+ }
219
+
220
+ if( is_multisite() && current_user_can('manage_network_plugins') && 'import' !== $pagenow ) {
221
+ $status['activateUrl'] = add_query_arg(array('networkwide' => 1), $status['activateUrl']);
222
+ }
223
+
224
+ wp_send_json_success($status);
225
+ }
226
+
227
+ add_action('wp_ajax_creativemotion-install-plugin', 'wbcr_clearfy_prepare_install_plugin');
admin/assets/js/install-addons.js CHANGED
@@ -6,7 +6,6 @@
6
  * @version 1.0
7
  */
8
 
9
-
10
  (function($) {
11
  'use strict';
12
 
@@ -30,9 +29,9 @@
30
  storage = $(this).data('storage'),
31
  wpnonce = $(this).data('wpnonce');
32
 
33
- var action = 'install-plugin';
34
 
35
- if( storage == 'freemius' || ((storage == 'wordpress' || storage == 'internal') && (plugin_action == 'activate' || plugin_action == 'deactivate')) ) {
36
  action = 'wbcr-clearfy-update-component';
37
  } else if( storage == 'wordpress' && plugin_action == 'delete' ) {
38
  action = 'delete-plugin';
6
  * @version 1.0
7
  */
8
 
 
9
  (function($) {
10
  'use strict';
11
 
29
  storage = $(this).data('storage'),
30
  wpnonce = $(this).data('wpnonce');
31
 
32
+ var action = ('creativemotion' === storage) ? 'creativemotion-install-plugin' : 'install-plugin';
33
 
34
+ if( storage == 'freemius' || ((storage == 'wordpress' || storage == 'creativemotion' || storage == 'internal') && (plugin_action == 'activate' || plugin_action == 'deactivate')) ) {
35
  action = 'wbcr-clearfy-update-component';
36
  } else if( storage == 'wordpress' && plugin_action == 'delete' ) {
37
  action = 'delete-plugin';
admin/includes/classes/class.install-plugins-button.php CHANGED
@@ -9,7 +9,7 @@
9
  */
10
 
11
  // Exit if accessed directly
12
- if ( ! defined( 'ABSPATH' ) ) {
13
  exit;
14
  }
15
 
@@ -35,49 +35,51 @@ class WCL_InstallPluginsButton {
35
  *
36
  * @throws Exception
37
  */
38
- public function __construct( $type, $plugin_slug ) {
39
- if ( empty( $type ) || ! is_string( $plugin_slug ) ) {
40
- throw new Exception( 'Empty type or plugin_slug attribute.' );
 
41
  }
42
- $this->type = $type;
43
  $this->plugin_slug = $plugin_slug;
44
 
45
- if ( $this->type == 'wordpress' ) {
46
- if ( strpos( rtrim( trim( $this->plugin_slug ) ), '/' ) !== false ) {
47
  $this->base_path = $this->plugin_slug;
48
- $base_path_parts = explode( '/', $this->base_path );
49
- if ( sizeof( $base_path_parts ) === 2 ) {
50
  $this->plugin_slug = $base_path_parts[0];
51
  }
52
  } else {
53
- $this->base_path = $this->get_plugin_base_path_by_slug( $this->plugin_slug );
54
  }
55
 
56
  $this->build_wordpress();
57
- } else if ( $this->type == 'internal' ) {
58
  $this->build_internal();
59
  } else {
60
- throw new Exception( 'Invalid button type.' );
61
  }
62
 
63
  // Set default data
64
- $this->addData( 'storage', $this->type );
65
- $this->addData( 'i18n', WCL_Helper::getEscapeJson( $this->get_i18n() ) );
66
- $this->addData( 'wpnonce', wp_create_nonce( 'updates' ) );
67
  }
68
 
69
  /**
70
  * @return bool
71
  */
72
- public function isPluginActivate() {
73
- if ( $this->type == 'wordpress' && $this->isPluginInstall() ) {
 
74
  require_once ABSPATH . '/wp-admin/includes/plugin.php';
75
 
76
- return is_plugin_active( $this->base_path );
77
- } else if ( $this->type == 'internal' ) {
78
- $preinsatall_components = WCL_Plugin::app()->getPopulateOption( 'deactive_preinstall_components', [] );
79
 
80
- return ! in_array( $this->plugin_slug, $preinsatall_components );
81
  }
82
 
83
  return false;
@@ -86,24 +88,25 @@ class WCL_InstallPluginsButton {
86
  /**
87
  * @return bool
88
  */
89
- public function isPluginInstall() {
90
- if ( $this->type == 'wordpress' ) {
91
- if ( empty( $this->base_path ) ) {
 
92
  return false;
93
  }
94
 
95
  // Check if the function get_plugins() is registered. It is necessary for the front-end
96
  // usually get_plugins() only works in the admin panel.
97
- if ( ! function_exists( 'get_plugins' ) ) {
98
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
99
  }
100
 
101
  $plugins = get_plugins();
102
 
103
- if ( isset( $plugins[ $this->base_path ] ) ) {
104
  return true;
105
  }
106
- } else if ( $this->type == 'internal' ) {
107
  return true;
108
  }
109
 
@@ -115,9 +118,10 @@ class WCL_InstallPluginsButton {
115
  *
116
  * @throws Exception
117
  */
118
- public function addClass( $class ) {
119
- if ( ! is_string( $class ) ) {
120
- throw new Exception( 'Attribute class must be a string.' );
 
121
  }
122
  $this->classes[] = $class;
123
  }
@@ -128,13 +132,14 @@ class WCL_InstallPluginsButton {
128
  * @return bool
129
  * @throws Exception
130
  */
131
- public function removeClass( $class ) {
132
- if ( ! is_string( $class ) ) {
133
- throw new Exception( 'Attribute class must be a string.' );
 
134
  }
135
- $key = array_search( $class, $this->classes );
136
- if ( isset( $this->classes[ $key ] ) ) {
137
- unset( $this->classes[ $key ] );
138
 
139
  return true;
140
  }
@@ -148,12 +153,13 @@ class WCL_InstallPluginsButton {
148
  *
149
  * @throws Exception
150
  */
151
- public function addData( $name, $value ) {
152
- if ( ! is_string( $name ) || ! is_string( $value ) ) {
153
- throw new Exception( 'Attributes name and value must be a string.' );
 
154
  }
155
 
156
- $this->data[ $name ] = $value;
157
  }
158
 
159
  /**
@@ -162,13 +168,14 @@ class WCL_InstallPluginsButton {
162
  * @return bool
163
  * @throws Exception
164
  */
165
- public function removeData( $name ) {
166
- if ( ! is_string( $name ) ) {
167
- throw new Exception( 'Attribute name must be a string.' );
 
168
  }
169
 
170
- if ( isset( $this->data[ $name ] ) ) {
171
- unset( $this->data[ $name ] );
172
 
173
  return true;
174
  }
@@ -179,21 +186,23 @@ class WCL_InstallPluginsButton {
179
  /**
180
  * Print an install button
181
  *
182
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
183
- * @since 1.5.0
184
  * @throws \Exception
 
 
185
  */
186
- public function renderButton() {
 
187
  echo $this->getButton();
188
  }
189
 
190
  /**
191
  * @return string
192
  */
193
- public function getButton() {
 
194
  $i18n = $this->get_i18n();
195
 
196
- $button = '<a href="#" class="' . implode( ' ', $this->get_classes() ) . '" ' . implode( ' ', $this->get_data() ) . '>' . $i18n[ $this->action ] . '</a>';
197
 
198
  return $button;
199
  }
@@ -202,13 +211,14 @@ class WCL_InstallPluginsButton {
202
  * @return string
203
  * @throws Exception
204
  */
205
- public function getLink() {
206
- $this->removeClass( 'button' );
207
- $this->removeClass( 'button-default' );
208
- $this->removeClass( 'button-primary' );
 
209
 
210
  //$this->addClass('link');
211
- $this->addClass( 'button-link' );
212
 
213
  return $this->getButton();
214
  }
@@ -216,112 +226,117 @@ class WCL_InstallPluginsButton {
216
  /**
217
  * Print an install a link
218
  *
219
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
220
- * @since 1.5.0
221
  * @throws \Exception
 
 
222
  */
223
- public function renderLink() {
 
224
  echo $this->getLink();
225
  }
226
 
227
  /**
228
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
229
- * @since 1.5.0
230
  * @return array
 
 
231
  */
232
- protected function get_data() {
 
233
  $data_to_print = [];
234
 
235
- foreach ( (array) $this->data as $key => $value ) {
236
- $data_to_print[ $key ] = 'data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
237
  }
238
 
239
  return $data_to_print;
240
  }
241
 
242
  /**
243
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
244
- * @since 1.5.0
245
  * @return array
 
 
246
  */
247
- protected function get_classes() {
248
- return array_map( 'esc_attr', $this->classes );
 
249
  }
250
 
251
  /**
252
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
253
- * @since 1.5.0
254
  * @throws \Exception
 
 
255
  */
256
- protected function build_wordpress() {
257
- if ( $this->type != 'wordpress' || empty( $this->base_path ) ) {
258
- return;
259
- }
260
 
261
- $this->action = 'install';
262
 
263
- if ( $this->isPluginInstall() ) {
264
- $this->action = 'deactivate';
265
- if ( ! $this->isPluginActivate() ) {
266
- $this->action = 'activate';
 
267
  }
268
- }
269
 
270
- $this->addData( 'plugin-action', $this->action );
271
- $this->addData( 'slug', $this->plugin_slug );
272
- $this->addData( 'plugin', $this->base_path );
273
 
274
- if ( $this->action == 'activate' ) {
275
- $this->addClass( 'button-primary' );
276
- } else {
277
- $this->addClass( 'button-default' );
 
278
  }
279
  }
280
 
281
  /**
282
  * Configurate button of internal components
283
  *
284
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
285
- * @since 1.5.0
286
  * @throws \Exception
 
 
287
  */
288
- protected function build_internal() {
289
- if ( $this->type != 'internal' ) {
 
290
  return;
291
  }
292
 
293
  $this->action = 'activate';
294
 
295
- if ( $this->isPluginActivate() ) {
296
  $this->action = 'deactivate';
297
  }
298
 
299
- $this->addData( 'plugin-action', $this->action );
300
- $this->addData( 'plugin', $this->plugin_slug );
301
 
302
- if ( $this->action == 'activate' ) {
303
- $this->addClass( 'button-primary' );
304
  } else {
305
- $this->addClass( 'button-default' );
306
  }
307
  }
308
 
309
  /**
310
  * Internalization for action buttons
311
  *
312
- * @author Alexander Kovalev <alex.kovalevv@gmail.com>
313
- * @since 1.5.0
314
  * @return array
 
 
315
  */
316
- protected function get_i18n() {
 
317
  return [
318
- 'activate' => __( 'Activate', 'clearfy' ),
319
- 'install' => __( 'Install', 'clearfy' ),
320
- 'deactivate' => __( 'Deactivate', 'clearfy' ),
321
- 'delete' => __( 'Delete', 'clearfy' ),
322
- 'loading' => __( 'Please wait...', 'clearfy' ),
323
- 'preparation' => __( 'Preparation...', 'clearfy' ),
324
- 'read' => __( 'Read more', 'clearfy' )
325
  ];
326
  }
327
 
@@ -329,21 +344,22 @@ class WCL_InstallPluginsButton {
329
  /**
330
  * Allows you to get the base path to the plugin in the directory wp-content/plugins/
331
  *
332
- * @param $slug - slug for example "clearfy", "hide-login-page"
333
  *
334
  * @return int|null|string - "clearfy/clearfy.php"
335
  */
336
- protected function get_plugin_base_path_by_slug( $slug ) {
 
337
  // Check if the function get_plugins() is registered. It is necessary for the front-end
338
  // usually get_plugins() only works in the admin panel.
339
- if ( ! function_exists( 'get_plugins' ) ) {
340
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
341
  }
342
 
343
  $plugins = get_plugins();
344
 
345
- foreach ( $plugins as $base_path => $plugin ) {
346
- if ( strpos( $base_path, rtrim( trim( $slug ) ) ) !== false ) {
347
  return $base_path;
348
  }
349
  }
9
  */
10
 
11
  // Exit if accessed directly
12
+ if( !defined('ABSPATH') ) {
13
  exit;
14
  }
15
 
35
  *
36
  * @throws Exception
37
  */
38
+ public function __construct($type, $plugin_slug)
39
+ {
40
+ if( empty($type) || !is_string($plugin_slug) ) {
41
+ throw new Exception('Empty type or plugin_slug attribute.');
42
  }
43
+ $this->type = $type;
44
  $this->plugin_slug = $plugin_slug;
45
 
46
+ if( $this->type == 'wordpress' || $this->type == 'creativemotion' ) {
47
+ if( strpos(rtrim(trim($this->plugin_slug)), '/') !== false ) {
48
  $this->base_path = $this->plugin_slug;
49
+ $base_path_parts = explode('/', $this->base_path);
50
+ if( sizeof($base_path_parts) === 2 ) {
51
  $this->plugin_slug = $base_path_parts[0];
52
  }
53
  } else {
54
+ $this->base_path = $this->get_plugin_base_path_by_slug($this->plugin_slug);
55
  }
56
 
57
  $this->build_wordpress();
58
+ } else if( $this->type == 'internal' ) {
59
  $this->build_internal();
60
  } else {
61
+ throw new Exception('Invalid button type.');
62
  }
63
 
64
  // Set default data
65
+ $this->addData('storage', $this->type);
66
+ $this->addData('i18n', WCL_Helper::getEscapeJson($this->get_i18n()));
67
+ $this->addData('wpnonce', wp_create_nonce('updates'));
68
  }
69
 
70
  /**
71
  * @return bool
72
  */
73
+ public function isPluginActivate()
74
+ {
75
+ if( ($this->type == 'wordpress' || $this->type == 'creativemotion') && $this->isPluginInstall() ) {
76
  require_once ABSPATH . '/wp-admin/includes/plugin.php';
77
 
78
+ return is_plugin_active($this->base_path);
79
+ } else if( $this->type == 'internal' ) {
80
+ $preinsatall_components = WCL_Plugin::app()->getPopulateOption('deactive_preinstall_components', []);
81
 
82
+ return !in_array($this->plugin_slug, $preinsatall_components);
83
  }
84
 
85
  return false;
88
  /**
89
  * @return bool
90
  */
91
+ public function isPluginInstall()
92
+ {
93
+ if( $this->type == 'wordpress' || $this->type == 'creativemotion' ) {
94
+ if( empty($this->base_path) ) {
95
  return false;
96
  }
97
 
98
  // Check if the function get_plugins() is registered. It is necessary for the front-end
99
  // usually get_plugins() only works in the admin panel.
100
+ if( !function_exists('get_plugins') ) {
101
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
102
  }
103
 
104
  $plugins = get_plugins();
105
 
106
+ if( isset($plugins[$this->base_path]) ) {
107
  return true;
108
  }
109
+ } else if( $this->type == 'internal' ) {
110
  return true;
111
  }
112
 
118
  *
119
  * @throws Exception
120
  */
121
+ public function addClass($class)
122
+ {
123
+ if( !is_string($class) ) {
124
+ throw new Exception('Attribute class must be a string.');
125
  }
126
  $this->classes[] = $class;
127
  }
132
  * @return bool
133
  * @throws Exception
134
  */
135
+ public function removeClass($class)
136
+ {
137
+ if( !is_string($class) ) {
138
+ throw new Exception('Attribute class must be a string.');
139
  }
140
+ $key = array_search($class, $this->classes);
141
+ if( isset($this->classes[$key]) ) {
142
+ unset($this->classes[$key]);
143
 
144
  return true;
145
  }
153
  *
154
  * @throws Exception
155
  */
156
+ public function addData($name, $value)
157
+ {
158
+ if( !is_string($name) || !is_string($value) ) {
159
+ throw new Exception('Attributes name and value must be a string.');
160
  }
161
 
162
+ $this->data[$name] = $value;
163
  }
164
 
165
  /**
168
  * @return bool
169
  * @throws Exception
170
  */
171
+ public function removeData($name)
172
+ {
173
+ if( !is_string($name) ) {
174
+ throw new Exception('Attribute name must be a string.');
175
  }
176
 
177
+ if( isset($this->data[$name]) ) {
178
+ unset($this->data[$name]);
179
 
180
  return true;
181
  }
186
  /**
187
  * Print an install button
188
  *
 
 
189
  * @throws \Exception
190
+ * @since 1.5.0
191
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
192
  */
193
+ public function renderButton()
194
+ {
195
  echo $this->getButton();
196
  }
197
 
198
  /**
199
  * @return string
200
  */
201
+ public function getButton()
202
+ {
203
  $i18n = $this->get_i18n();
204
 
205
+ $button = '<a href="#" class="' . implode(' ', $this->get_classes()) . '" ' . implode(' ', $this->get_data()) . '>' . $i18n[$this->action] . '</a>';
206
 
207
  return $button;
208
  }
211
  * @return string
212
  * @throws Exception
213
  */
214
+ public function getLink()
215
+ {
216
+ $this->removeClass('button');
217
+ $this->removeClass('button-default');
218
+ $this->removeClass('button-primary');
219
 
220
  //$this->addClass('link');
221
+ $this->addClass('button-link');
222
 
223
  return $this->getButton();
224
  }
226
  /**
227
  * Print an install a link
228
  *
 
 
229
  * @throws \Exception
230
+ * @since 1.5.0
231
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
232
  */
233
+ public function renderLink()
234
+ {
235
  echo $this->getLink();
236
  }
237
 
238
  /**
 
 
239
  * @return array
240
+ * @since 1.5.0
241
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
242
  */
243
+ protected function get_data()
244
+ {
245
  $data_to_print = [];
246
 
247
+ foreach((array)$this->data as $key => $value) {
248
+ $data_to_print[$key] = 'data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
249
  }
250
 
251
  return $data_to_print;
252
  }
253
 
254
  /**
 
 
255
  * @return array
256
+ * @since 1.5.0
257
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
258
  */
259
+ protected function get_classes()
260
+ {
261
+ return array_map('esc_attr', $this->classes);
262
  }
263
 
264
  /**
 
 
265
  * @throws \Exception
266
+ * @since 1.5.0
267
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
268
  */
269
+ protected function build_wordpress()
270
+ {
271
+ if( ('wordpress' === $this->type || 'creativemotion' === $this->type) && !empty($this->base_path) ) {
 
272
 
273
+ $this->action = 'install';
274
 
275
+ if( $this->isPluginInstall() ) {
276
+ $this->action = 'deactivate';
277
+ if( !$this->isPluginActivate() ) {
278
+ $this->action = 'activate';
279
+ }
280
  }
 
281
 
282
+ $this->addData('plugin-action', $this->action);
283
+ $this->addData('slug', $this->plugin_slug);
284
+ $this->addData('plugin', $this->base_path);
285
 
286
+ if( $this->action == 'activate' ) {
287
+ $this->addClass('button-primary');
288
+ } else {
289
+ $this->addClass('button-default');
290
+ }
291
  }
292
  }
293
 
294
  /**
295
  * Configurate button of internal components
296
  *
 
 
297
  * @throws \Exception
298
+ * @since 1.5.0
299
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
300
  */
301
+ protected function build_internal()
302
+ {
303
+ if( $this->type != 'internal' ) {
304
  return;
305
  }
306
 
307
  $this->action = 'activate';
308
 
309
+ if( $this->isPluginActivate() ) {
310
  $this->action = 'deactivate';
311
  }
312
 
313
+ $this->addData('plugin-action', $this->action);
314
+ $this->addData('plugin', $this->plugin_slug);
315
 
316
+ if( $this->action == 'activate' ) {
317
+ $this->addClass('button-primary');
318
  } else {
319
+ $this->addClass('button-default');
320
  }
321
  }
322
 
323
  /**
324
  * Internalization for action buttons
325
  *
 
 
326
  * @return array
327
+ * @since 1.5.0
328
+ * @author Alexander Kovalev <alex.kovalevv@gmail.com>
329
  */
330
+ protected function get_i18n()
331
+ {
332
  return [
333
+ 'activate' => __('Activate', 'clearfy'),
334
+ 'install' => __('Install', 'clearfy'),
335
+ 'deactivate' => __('Deactivate', 'clearfy'),
336
+ 'delete' => __('Delete', 'clearfy'),
337
+ 'loading' => __('Please wait...', 'clearfy'),
338
+ 'preparation' => __('Preparation...', 'clearfy'),
339
+ 'read' => __('Read more', 'clearfy')
340
  ];
341
  }
342
 
344
  /**
345
  * Allows you to get the base path to the plugin in the directory wp-content/plugins/
346
  *
347
+ * @param $slug - slug for example "clearfy", "hide-login-page"
348
  *
349
  * @return int|null|string - "clearfy/clearfy.php"
350
  */
351
+ protected function get_plugin_base_path_by_slug($slug)
352
+ {
353
  // Check if the function get_plugins() is registered. It is necessary for the front-end
354
  // usually get_plugins() only works in the admin panel.
355
+ if( !function_exists('get_plugins') ) {
356
  require_once ABSPATH . 'wp-admin/includes/plugin.php';
357
  }
358
 
359
  $plugins = get_plugins();
360
 
361
+ foreach($plugins as $base_path => $plugin) {
362
+ if( strpos($base_path, rtrim(trim($slug))) !== false ) {
363
  return $base_path;
364
  }
365
  }
admin/pages/class-pages-components.php CHANGED
@@ -191,7 +191,7 @@ class WCL_ComponentsPage extends WCL_Page {
191
  'name' => 'titan_security',
192
  'title' => __('Firewall and Malware scanner', 'clearfy'),
193
  'url' => 'https://wordpress.org/plugins/titan-security/',
194
- 'type' => 'wordpress',
195
  'build' => 'freemium',
196
  'base_path' => 'anti-spam/anti-spam.php',
197
  'icon' => WCL_PLUGIN_URL . '/admin/assets/img/titan-icon-256x256.jpg',
@@ -351,7 +351,7 @@ class WCL_ComponentsPage extends WCL_Page {
351
 
352
  $slug = $component['name'];
353
 
354
- if( $component['type'] == 'wordpress' ) {
355
  $slug = $component['base_path'];
356
  }
357
 
191
  'name' => 'titan_security',
192
  'title' => __('Firewall and Malware scanner', 'clearfy'),
193
  'url' => 'https://wordpress.org/plugins/titan-security/',
194
+ 'type' => 'creativemotion',
195
  'build' => 'freemium',
196
  'base_path' => 'anti-spam/anti-spam.php',
197
  'icon' => WCL_PLUGIN_URL . '/admin/assets/img/titan-icon-256x256.jpg',
351
 
352
  $slug = $component['name'];
353
 
354
+ if( $component['type'] == 'wordpress' || $component['type'] == 'creativemotion' ) {
355
  $slug = $component['base_path'];
356
  }
357
 
admin/pages/class-pages-defence-titan.php CHANGED
@@ -28,7 +28,7 @@ class WCL_TitanSecurityPage extends WCL_Page {
28
  /**
29
  * @var string
30
  */
31
- public $page_parent_page = 'defence';
32
 
33
  /**
34
  * Тип страницы
@@ -45,7 +45,7 @@ class WCL_TitanSecurityPage extends WCL_Page {
45
  *
46
  * @var int
47
  */
48
- public $page_menu_position = 30;
49
 
50
  /**
51
  * @var string
@@ -62,7 +62,7 @@ class WCL_TitanSecurityPage extends WCL_Page {
62
  */
63
  public function __construct(WCL_Plugin $plugin)
64
  {
65
- $this->menu_title = __('Firewall and Malware scanner', 'clearfy');
66
  $this->page_menu_short_description = __('Firewall and Anti-virus', 'clearfy');
67
 
68
  parent::__construct($plugin);
@@ -76,7 +76,7 @@ class WCL_TitanSecurityPage extends WCL_Page {
76
  public function showPageContent()
77
  {
78
  require_once WCL_PLUGIN_DIR . '/admin/includes/classes/class.install-plugins-button.php';
79
- $install_button = new WCL_InstallPluginsButton('wordpress', 'anti-spam/anti-spam.php');
80
  $install_button->addClass('wbcr-factory-purchase-premium');
81
  ?>
82
  <script>
@@ -96,9 +96,17 @@ class WCL_TitanSecurityPage extends WCL_Page {
96
  </script>
97
  <div class="wbcr-factory-clearfy-219-multisite-suggetion">
98
  <div class="wbcr-factory-inner-contanier">
99
- <h3><?php _e('Install Firewall and Malware scanner (Titan sucurity) component', 'clearfy') ?></h3>
100
- <p><?php _e('To start optimizing images, you need to install the additional component Titan security!', 'clearfy') ?></p>
101
- <p><?php _e('Installing the component will not take you long, just click the install button, then activate.', 'clearfy') ?></p>
 
 
 
 
 
 
 
 
102
  <p style="margin-top:20px">
103
  <?php $install_button->renderLink(); ?>
104
  </p>
28
  /**
29
  * @var string
30
  */
31
+ //public $page_parent_page = 'defence';
32
 
33
  /**
34
  * Тип страницы
45
  *
46
  * @var int
47
  */
48
+ //public $page_menu_position = 20;
49
 
50
  /**
51
  * @var string
62
  */
63
  public function __construct(WCL_Plugin $plugin)
64
  {
65
+ $this->menu_title = __('Security', 'clearfy');
66
  $this->page_menu_short_description = __('Firewall and Anti-virus', 'clearfy');
67
 
68
  parent::__construct($plugin);
76
  public function showPageContent()
77
  {
78
  require_once WCL_PLUGIN_DIR . '/admin/includes/classes/class.install-plugins-button.php';
79
+ $install_button = new WCL_InstallPluginsButton('creativemotion', 'anti-spam/anti-spam.php');
80
  $install_button->addClass('wbcr-factory-purchase-premium');
81
  ?>
82
  <script>
96
  </script>
97
  <div class="wbcr-factory-clearfy-219-multisite-suggetion">
98
  <div class="wbcr-factory-inner-contanier">
99
+ <h3>
100
+ <a href="https://wordpress.org/plugins/anti-spam" target="_blank"><?php _e('Install Firewall and Malware scanner (Titan sucurity) component', 'clearfy') ?></a>
101
+ </h3>
102
+
103
+ <p><?php _e('Titan includes anti-spam, firewall, malware scanner, site accessibility checking, security and threats audits for WordPress websites. Our security functions provide Titan with the latest firewall rules, malware signatures, and database of malicious IP addresses – all you need to ensure the security of your website.', 'clearfy') ?></p>
104
+ <p>
105
+ <?php _e('Titan is a comprehensive WordPress security solution, completed by a set of additional features as add-ons, which was placed into a simple and intuitive interface.', 'clearfy') ?>
106
+ <a href="https://wordpress.org/plugins/anti-spam" target="_blank"><?php _e('Read more', 'clearfy'); ?></a>
107
+ </p>
108
+
109
+ <p style="color:#ff4d00"><?php _e('Installing the component will not take you long, just click the install button, then activate.', 'clearfy') ?></p>
110
  <p style="margin-top:20px">
111
  <?php $install_button->renderLink(); ?>
112
  </p>
clearfy.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: https://wordpress.org/plugins/clearfy/
5
  * Description: Disables unused Wordpress features, improves performance and increases SEO rankings, using Clearfy, which makes WordPress very easy.
6
  * Author: Webcraftic <wordpress.webraftic@gmail.com>
7
- * Version: 1.6.5
8
  * Text Domain: clearfy
9
  * Domain Path: /languages/
10
  * Author URI: http://clearfy.pro
4
  * Plugin URI: https://wordpress.org/plugins/clearfy/
5
  * Description: Disables unused Wordpress features, improves performance and increases SEO rankings, using Clearfy, which makes WordPress very easy.
6
  * Author: Webcraftic <wordpress.webraftic@gmail.com>
7
+ * Version: 1.6.6
8
  * Text Domain: clearfy
9
  * Domain Path: /languages/
10
  * Author URI: http://clearfy.pro
readme.txt CHANGED
@@ -238,6 +238,9 @@ Of course! To do this, email us your wishes with address, which you will find in
238
 
239
 
240
  == Changelog ==
 
 
 
241
  = 1.6.5 (28.04.2020) =
242
  * Fixed: The license was activated during synchronization with the server, but the license has not expired yet and was active.
243
  * Fixed: The notification “Please, install premium plugin” no longer appears if the plugin was installed manually.
238
 
239
 
240
  == Changelog ==
241
+ = 1.6.6 (29.04.2020) =
242
+ * Fixed: Minor bugs
243
+
244
  = 1.6.5 (28.04.2020) =
245
  * Fixed: The license was activated during synchronization with the server, but the license has not expired yet and was active.
246
  * Fixed: The notification “Please, install premium plugin” no longer appears if the plugin was installed manually.