PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / core.class.php

core.class.php in InfiniteWP Client trunk, at core.class.php

1,585 lines 58.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /************************************************************
3 * This plugin was modified by Revmakx *
4 * Copyright (c) 2012 Revmakx *
5 * www.revmakx.com *
6 * *
7 ************************************************************/
8 /*************************************************************
9 *
10 * core.class.php
11 *
12 * Upgrade Plugins
13 *
14 *
15 * Copyright (c) 2011 Prelovac Media
16 * www.prelovac.com
17 **************************************************************/
18 if ( ! defined('ABSPATH') )
19 die();
20 class IWP_MMB_Core extends IWP_MMB_Helper
21 {
22 public $name;
23 public $slug;
24 public $settings;
25 public $remote_client;
26 public $comment_instance;
27 public $plugin_instance;
28 public $theme_instance;
29 public $wp_instance;
30 public $post_instance;
31 public $stats_instance;
32 public $search_instance;
33 public $links_instance;
34 public $user_instance;
35 public $backup_instance;
36 public $backup_new_instance;
37 public $wordfence_instance;
38 public $sucuri_instance;
39 public $installer_instance;
40 public $iwp_mmb_multisite;
41 public $network_admin_install;
42 public $blc_get_blinks;
43 public $link_instance;
44 public $get_google_webmasters_crawls;
45 public $get_file_editor;
46 public $get_yoast_seo;
47 public $blogroll_instance;
48
49 public $ithemessec_instance;
50 public $backup_repository_instance;
51 public $optimize_instance;
52 public $wp_purge_cache_instance;
53
54 private $action_call;
55 public $request_params;
56 public $error_notice;
57 private $action_params;
58 private $iwp_mmb_pre_init_actions;
59 private $iwp_mmb_pre_init_filters;
60 private $iwp_mmb_init_actions;
61
62
63 function __construct()
64 {
65 global $iwp_mmb_plugin_dir, $wpmu_version, $blog_id, $_iwp_mmb_plugin_actions, $_iwp_mmb_item_filter;
66
67 $_iwp_mmb_plugin_actions = array();
68 $this->name = 'Manage Multiple Blogs';
69 $this->slug = 'manage-multiple-blogs';
70 $this->action_call = null;
71 $this->action_params = null;
72
73
74 $this->settings = get_option($this->slug);
75 if (!$this->settings) {
76 $this->settings = array(
77 'blogs' => array(),
78 'current_blog' => array(
79 'type' => null
80 )
81 );
82 $this->save_options();
83 }
84 if ( function_exists('is_multisite') ) {
85 if ( is_multisite() ) {
86 $this->iwp_mmb_multisite = $blog_id;
87 $this->network_admin_install = get_option('iwp_client_network_admin_install');
88 add_action('wp_initialize_site', array(&$this, 'updateKeys'));
89 }
90 } else if (!empty($wpmu_version)) {
91 $this->iwp_mmb_multisite = $blog_id;
92 $this->network_admin_install = get_option('iwp_client_network_admin_install');
93 } else {
94 $this->iwp_mmb_multisite = false;
95 $this->network_admin_install = null;
96 }
97
98 // admin notices
99 if ( !get_option('iwp_client_public_key') ){
100 if( $this->iwp_mmb_multisite ){
101 if( is_network_admin() && $this->network_admin_install == '1'){
102 //add_action('network_admin_notices', array( &$this, 'network_admin_notice' ));// We implemented network activation so no need to show this notification
103 add_action('network_admin_notices', array( &$this, 'admin_notice' ));
104 } else if( $this->network_admin_install != '1' ){
105 //$parent_key = $this->get_parent_blog_option('iwp_client_public_key');//IWP commented to show notice to all subsites of network
106 //if(empty($parent_key))//IWP commented to show notice to all subsites of network
107 $parent_key = $this->get_parent_blog_option('iwp_client_public_key');
108 if (empty($parent_key)) {
109 add_action('admin_notices', array(&$this, 'admin_notice'));
110 }
111 }
112 } else {
113 add_action('admin_notices', array( &$this, 'admin_notice' ));
114 }
115 }
116
117 // default filters
118 //$this->iwp_mmb_pre_init_filters['get_stats']['iwp_mmb_stats_filter'][] = array('IWP_MMB_Stats', 'pre_init_stats'); // called with class name, use global $iwp_mmb_core inside the function instead of $this
119 $this->iwp_mmb_pre_init_filters['get_stats']['iwp_mmb_stats_filter'][] = 'iwp_mmb_pre_init_stats';
120
121 $_iwp_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' );
122 $_iwp_mmb_item_filter['get'] = array( 'updates', 'errors','plugins_status','themes_status' );
123
124 $this->iwp_mmb_pre_init_actions = array(
125 'backup_req' => 'iwp_mmb_get_backup_req',
126 );
127
128 $this->iwp_mmb_init_actions = array(
129 'do_upgrade' => 'iwp_mmb_do_upgrade',
130 'get_stats' => 'iwp_mmb_stats_get',
131 'remove_site' => 'iwp_mmb_remove_site',
132 'backup_clone' => 'iwp_mmb_backup_now',
133 'restore' => 'iwp_mmb_restore_now',
134 'optimize_tables' => 'iwp_mmb_optimize_tables',
135 'check_wp_version' => 'iwp_mmb_wp_checkversion',
136 'create_post' => 'iwp_mmb_post_create',
137 'update_client' => 'iwp_mmb_update_client_plugin',
138
139 'change_comment_status' => 'iwp_mmb_change_comment_status',
140 'change_post_status' => 'iwp_mmb_change_post_status',
141 'get_comment_stats' => 'iwp_mmb_comment_stats_get',
142
143 'get_links' => 'iwp_mmb_get_links',
144 'add_link' => 'iwp_mmb_add_link',
145 'delete_link' => 'iwp_mmb_delete_link',
146 'delete_links' => 'iwp_mmb_delete_links',
147
148 'create_post' => 'iwp_mmb_post_create',
149 'get_posts' => 'iwp_mmb_get_posts',
150 'delete_post' => 'iwp_mmb_delete_post',
151 'delete_posts' => 'iwp_mmb_delete_posts',
152 'get_pages' => 'iwp_mmb_get_pages',
153 'delete_page' => 'iwp_mmb_delete_page',
154
155 'install_addon' => 'iwp_mmb_install_addon',
156
157 'add_user' => 'iwp_mmb_add_user',
158 'email_backup' => 'iwp_mmb_email_backup',
159 'check_backup_compat' => 'iwp_mmb_check_backup_compat',
160 'scheduled_backup' => 'iwp_mmb_scheduled_backup',
161 'new_scheduled_backup' => 'iwp_mmb_new_scheduled_backup',
162 'run_task' => 'iwp_mmb_run_task_now',
163 'new_run_task' => 'iwp_mmb_new_run_task_now',
164 'delete_schedule_task' => 'iwp_mmb_delete_task_now',
165 'execute_php_code' => 'iwp_mmb_execute_php_code',
166 'delete_backup' => 'iwp_mmb_delete_backup',
167 'delete_backup_new' => 'iwp_mmb_delete_backup_new',
168 'kill_new_backup' => 'iwp_mmb_kill_new_backup',
169 'remote_backup_now' => 'iwp_mmb_remote_backup_now',
170 'set_notifications' => 'iwp_mmb_set_notifications',
171 'clean_orphan_backups' => 'iwp_mmb_clean_orphan_backups',
172 'get_users' => 'iwp_mmb_get_users',
173 'edit_users' => 'iwp_mmb_edit_users',
174 'get_plugins_themes' => 'iwp_mmb_get_plugins_themes',
175 'edit_plugins_themes' => 'iwp_mmb_edit_plugins_themes',
176 'get_comments' => 'iwp_mmb_get_comments',
177 'action_comment' => 'iwp_mmb_action_comment',
178 'bulk_action_comments' => 'iwp_mmb_bulk_action_comments',
179 'replyto_comment' => 'iwp_mmb_reply_comment',
180 'client_brand' => 'iwp_mmb_client_brand',
181 'set_alerts' => 'iwp_mmb_set_alerts',
182 'maintenance' => 'iwp_mmb_maintenance_mode',
183
184 'wp_optimize' => 'iwp_mmb_wp_optimize',
185 'wp_purge_cache' => 'iwp_mmb_wp_purge_cache',
186
187 'backup_repository' => 'iwp_mmb_backup_repository',
188 'trigger_backup_multi' => 'iwp_mmb_trigger_check',
189 'trigger_backup_multi_new' => 'iwp_mmb_trigger_check_new',
190 'get_all_links' => 'iwp_mmb_get_all_links',
191 'update_broken_link' => 'iwp_mmb_update_broken_link',
192 'unlink_broken_link' => 'iwp_mmb_unlink_broken_link',
193 'markasnot_broken_link' => 'iwp_mmb_markasnot_broken_link',
194 'dismiss_broken_link' => 'iwp_mmb_dismiss_broken_link',
195 'undismiss_broken_link' => 'iwp_mmb_undismiss_broken_link',
196 'bulk_actions_processor' => 'iwp_mmb_bulk_actions_processor',
197
198 'file_editor_upload' => 'iwp_mmb_file_editor_upload',
199
200 'put_redirect_url' => 'iwp_mmb_gwmt_redirect_url',
201 'put_redirect_url_again'=> 'iwp_mmb_gwmt_redirect_url_again',
202 'wordfence_scan' => 'iwp_mmb_wordfence_scan',
203 'wordfence_load' => 'iwp_mmb_wordfence_load',
204 'sucuri_fetch_result' => 'iwp_mmb_sucuri_fetch_result',
205 'backup_test_site' => 'iwp_mmb_backup_test_site',
206 'ithemes_security_check' => 'iwp_phx_ithemes_security_check',
207 'get_seo_info' => 'iwp_mmb_yoast_get_seo_info',
208 'save_seo_info' => 'iwp_mmb_yoast_save_seo_info',
209 'fetch_activities_log' => 'iwp_mmb_fetch_activities_log',
210 'sucuri_scan' => 'iwp_mmb_sucuri_scan',
211 'sucuri_change_alert' => 'iwp_mmb_sucuri_change_alert',
212 'backup_downlaod' => 'iwp_mmb_backup_downlaod',
213 'cronDoAction' => 'iwp_pheonix_backup_cron_do_action',
214 'get_additional_stats' => 'iwp_get_additional_stats',
215 'get_db_details' => 'iwp_get_db_details',
216 'client_report_delete_log' => 'iwp_client_report_delete_log',
217 'changelog_plugin' => 'iwp_get_changelog_plugin',
218 );
219
220 add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
221 if( $this->iwp_mmb_multisite ){
222 add_action('network_admin_menu', array($this,'iwp_admin_menu_actions'), 10, 1);
223 }else{
224 add_action('admin_menu', array($this,'iwp_admin_menu_actions'), 10, 1);
225 }
226 add_action('init', array($this,'iwp_cpb_hide_updates'), 10, 1);
227 add_action('admin_init', array(&$this,'admin_actions'));
228 add_action('admin_init', array(&$this,'enqueueConnectionModalOpenScripts'));
229 add_action('admin_init', array(&$this,'enqueueConnectionModalOpenStyles'));
230 add_filter('deprecated_function_trigger_error', '__return_false');
231 add_filter('plugin_row_meta', array($this, 'addConnectionKeyLink'), 10, 2);
232 add_action('admin_head', array($this, 'printConnectionModalOpenScript'));
233 add_action('admin_footer', array($this, 'printConnectionModalDialog'));
234 // add_action('wp_loaded', array( &$this, 'iwp_mmb_remote_action'), 2147483650);
235 add_action('setup_theme', 'iwp_mmb_set_request');
236 add_action('setup_theme', 'iwp_mmb_add_readd_request');
237 add_action('set_auth_cookie', array( &$this, 'iwp_mmb_set_auth_cookie'));
238 add_action('wp_loaded', array( &$this, 'load_mu_loader_error'));
239 add_action('set_logged_in_cookie', array( &$this, 'iwp_mmb_set_logged_in_cookie'));
240
241 }
242
243 function admin_wp_loaded_iwp(){
244 if (!defined('WP_ADMIN')) {
245 define('WP_ADMIN', true);
246 }
247 if (is_multisite() && !defined('WP_NETWORK_ADMIN')) {
248 define('WP_NETWORK_ADMIN', true);
249 }
250 if (!defined('WP_BLOG_ADMIN')) {
251 define('WP_BLOG_ADMIN', true);
252 }
253 require_once ABSPATH.'wp-admin/includes/admin.php';
254 // define('DOING_AJAX', true);
255 do_action('admin_init');
256 if (function_exists('wp_clean_update_cache')) {
257 /** @handled function */
258 wp_clean_update_cache();
259 }
260
261 /** @handled function */
262 wp_update_plugins();
263
264 /** @handled function */
265 set_current_screen();
266 do_action('load-update-core.php');
267
268 /** @handled function */
269 wp_version_check();
270
271 /** @handled function */
272 wp_version_check(array(), true);
273 }
274
275 function iwp_mmb_remote_action(){
276 global $iwp_mmb_core;
277 if (!empty($iwp_mmb_core->request_params)) {
278 $params = $iwp_mmb_core->request_params;
279 $action = $iwp_mmb_core->request_params['iwp_action'];
280 if( isset($this->iwp_mmb_pre_init_filters[$action]) && !empty($this->iwp_mmb_pre_init_filters[$action])){
281 global $iwp_mmb_filters;
282 foreach($this->iwp_mmb_pre_init_filters[$action] as $_name => $_functions){
283 if(!empty($_functions)){
284 $data = array();
285
286 foreach($_functions as $_k => $_callback){
287 if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
288 $data = call_user_func( $_callback, $params );
289 } elseif (is_string($_callback) && function_exists( $_callback )){
290 $data = call_user_func( $_callback, $params );
291 }
292 $iwp_mmb_filters[$_name] = isset($iwp_mmb_filters[$_name]) && !empty($iwp_mmb_filters[$_name]) ? array_merge($iwp_mmb_filters[$_name], $data) : $data;
293 add_filter( $_name, function($a) use ($_name){
294 global $iwp_mmb_filters;
295 return array_merge($a,$iwp_mmb_filters[$_name]);
296 });
297 // $_name closure variable, $a is an arg
298 }
299 }
300
301 }
302 }
303 }
304 if($this->action_call != null){
305 $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
306 call_user_func($this->action_call, $params);
307 }
308 }
309
310 function iwp_mmb_manual_wp_upgrade(){
311 /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
312 global $wp_db_version, $wpmu_version;
313 if( strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR') ){
314 if ( get_option('db_version') != $wp_db_version ) {
315 /* in multisite network, please update database manualy */
316 if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){
317 if( ! function_exists('wp_upgrade'))
318 include_once(ABSPATH.'wp-admin/includes/upgrade.php');
319 ob_clean();
320 @wp_upgrade();
321 @do_action('after_db_upgrade');
322 ob_end_clean();
323 }
324 }
325 }
326 }
327
328 function register_action_params( $action = false, $params = array() ){
329 if ($action == 'get_stats' || $action == 'do_upgrade' || $action == 'changelog_plugin') {
330 add_action('wp_loaded', array( &$this, 'iwp_mmb_remote_action'), 2147483650);
331 add_action('wp_loaded', array( &$this, 'admin_wp_loaded_iwp'), 2147483649);
332 if($action == 'get_stats' && !isset( $_GET['step'])){
333 add_action('wp_loaded', array( &$this, 'iwp_mmb_manual_wp_upgrade'),2147483648);
334 }
335 }elseif ($action == 'install_addon') {
336 add_action('wp_loaded', array( &$this, 'iwp_mmb_remote_action'));
337 }elseif ($action == 'new_run_task' || $action == 'new_scheduled_backup') {
338 add_action('after_setup_theme', array( &$this, 'iwp_mmb_remote_action'), 9999);
339 }else{
340 add_action('init', array( &$this, 'iwp_mmb_remote_action'), 9999);
341 }
342
343 if(isset($this->iwp_mmb_pre_init_actions[$action]) && function_exists($this->iwp_mmb_pre_init_actions[$action])){
344 call_user_func($this->iwp_mmb_pre_init_actions[$action], $params);
345 }
346
347 if(isset($this->iwp_mmb_init_actions[$action]) && function_exists($this->iwp_mmb_init_actions[$action])){
348 $this->action_call = $this->iwp_mmb_init_actions[$action];
349 $this->action_params = $params;
350 return true;
351 }
352 return false;
353 }
354
355 /**
356 * Add notice to network admin dashboard for security reasons
357 *
358 */
359 function network_admin_notice()
360 {
361 echo '<div class="error" style="text-align: center;"><p style="font-size: 14px; font-weight: bold; color:#c00;">Attention !</p>
362 <p>The InfiniteWP client plugin has to be activated on individual sites. Kindly deactivate the plugin from the network admin dashboard and activate them from the individual dashboards.</p></div>';
363 }
364
365
366 /**
367 * Add notice to admin dashboard for security reasons
368 *
369 */
370 function admin_notice()
371 {
372 /* IWP */
373 if(defined('MULTISITE') && MULTISITE == true){
374 global $blog_id;
375 $details = get_user_by( 'email',get_blog_option($blog_id, 'admin_email'));
376 //$details = get_userdata($user_id_from_email->ID);
377 $username = $details->user_login;
378 }
379 else{
380 $current_user = wp_get_current_user();
381 $username = $current_user->data->user_login;
382 }
383
384 $iwp_client_activate_key = get_option('iwp_client_activate_key');
385 if (!current_user_can( 'administrator' )) {
386 return false;
387 }
388 //check BWP
389 $bwp = get_option("bit51_bwps");
390 $notice_display_URL=admin_url();
391 if(!empty($bwp))
392 {
393 //$bwpArray = @unserialize($bwp);
394 if($bwp['hb_enabled']==1)
395 $notice_display_URL = get_option('home');
396 }
397
398 $notice_display_URL = rtrim($notice_display_URL, '/').'/';
399 $website_URL = rtrim(get_option('home'), '/').'/';
400
401
402 echo '<div class="updated" style="text-align: center; display:block !important; "><p style="color: green; font-size: 14px; font-weight: bold;">Add this site to IWP Admin panel</p><p>
403 <table border="0" align="center" cellpadding="5">';
404 if(!empty($iwp_client_activate_key)){
405 echo '<tr><td align="right">WP-ADMIN URL:</td><td align="left"><strong>'.$notice_display_URL.'</strong></td></tr>
406 <tr><td align="right">WEBSITE URL:</td><td align="left"><strong>'.$website_URL.'</strong></td></tr>
407 <tr><td align="right">ADMIN USERNAME:</td><td align="left"><strong>'.$username.'</strong> (or any admin id)</td></tr>
408 <tr><td align="right">ACTIVATION KEY:</td><td align="left"><strong>'.$iwp_client_activate_key.'</strong></td></tr>
409 <tr class="only_flash"><td></td><td align="left" style="position:relative;">
410 <tr id="copy_at_once"><td align="right">To quick add, copy this</td><td align="left" style="position:relative;"><input type="text" style="width:295px;" class="read_creds" readonly value="'.$notice_display_URL.'|^|'.$username.'|^|'.$iwp_client_activate_key.'|^|'.$website_URL.'" /></td></tr>
411 <tr class="only_flash"><td></td><td align="left" style="position:relative;"><div id="copy_details" data-clipboard-text="'.$notice_display_URL.'|^|'.$username.'|^|'.$iwp_client_activate_key.'|^|'.$website_URL.'" style="background:#008000;display: inline-block;padding: 4px 10px;border-radius: 5px;color:#fff;font-weight:600;cursor:pointer;">Copy details</div><span class="copy_message" style="display:none;margin-left:10px;color:#008000;">Copied :)</span></td></tr>
412
413 <script type="text/javascript">
414 (function(){
415 var onhoverMsg = "<span class=\"aftercopy_instruction\" style=\"position: absolute;top: 32px;left:20px;background:#fff;border:1px solid #000;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;padding:2px;margin:2px;text-align:center;\">Paste this in any field in the Add Website dialogue in the InfiniteWP admin panel.</span>";
416 var clipboard = new Clipboard("#copy_details");
417 if (clipboard != undefined) {
418 clipboard.on("success", function(e) {
419 jQuery(".copy_message").show();
420 setTimeout(\'jQuery(".copy_message").hide();\',1000);
421
422 e.clearSelection();
423
424 });
425 clipboard.on("error", function(e) {
426 jQuery(".only_flash").remove();
427 jQuery(".read_creds").click(function(){jQuery(this).select();});
428 });
429 jQuery("#copy_at_once").hide();
430 jQuery("#copy_details").mouseenter(function(){jQuery(onhoverMsg).appendTo(jQuery(this).parent());}).mouseleave(function(){jQuery(".aftercopy_instruction").remove();});
431 }else{
432 jQuery(".only_flash").remove();
433 jQuery(".read_creds").click(function(){jQuery(this).select();});
434 jQuery(".read_creds").mouseenter(function(e){jQuery(onhoverMsg).appendTo(jQuery(this).parent());}).mouseleave(function(){jQuery(".aftercopy_instruction").remove();});
435 }
436 })();
437
438 </script>';
439 }
440 else{
441 echo '<tr><td align="center">Please deactivate and then activate InfiniteWP Client plugin.</td></tr>';
442 }
443
444 echo '</table>
445 </p></div>';
446
447 }
448
449 /**
450 * Add an item into the Right Now Dashboard widget
451 * to inform that the blog can be managed remotely
452 *
453 */
454 function add_right_now_info()
455 {
456 echo '<div class="iwp_mmb-slave-info">
457 <p>This site can be managed remotely.</p>
458 </div>';
459 }
460
461 /**
462 * Get parent blog options
463 *
464 */
465 private function get_parent_blog_option( $option_name = '' )
466 {
467 global $wpdb;
468 $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = %s LIMIT 1", $option_name ) );
469 return $option;
470 }
471
472
473 /**
474 * Gets an instance of the WP_Optimize class
475 *
476 */
477 function wp_optimize_instance()
478 {
479 if (!isset($this->optimize_instance)) {
480 $this->optimize_instance = new IWP_MMB_Optimize();
481 }
482
483 return $this->optimize_instance;
484 }
485
486 function wp_purge_cache_instance()
487 {
488 global $iwp_mmb_plugin_dir;
489 require_once("$iwp_mmb_plugin_dir/addons/wp_optimize/purge-plugins-cache-class.php");
490 if (!isset($this->wp_purge_cache_instance)) {
491 $this->wp_purge_cache_instance = new IWP_MMB_PURGE_CACHE();
492 }
493
494 return $this->wp_purge_cache_instance;
495 }
496 /**
497 * Gets an instance of the WP_BrokenLinks class
498 *
499 */
500 function wp_blc_get_blinks()
501 {
502 global $iwp_mmb_plugin_dir;
503 require_once("$iwp_mmb_plugin_dir/addons/brokenlinks/brokenlinks.class.php");
504 if (!isset($this->blc_get_blinks)) {
505 $this->blc_get_blinks = new IWP_MMB_BLC();
506 }
507
508 return $this->blc_get_blinks;
509 }
510
511
512 /**
513 * Gets an instance of the WP_BrokenLinks class
514 *
515 */
516 function wp_google_webmasters_crawls()
517 {
518 global $iwp_mmb_plugin_dir;
519 require_once("$iwp_mmb_plugin_dir/addons/google_webmasters/google_webmasters.class.php");
520 if (!isset($this->get_google_webmasters_crawls)) {
521 $this->get_google_webmasters_crawls = new IWP_MMB_GWMT();
522 }
523
524 return $this->get_google_webmasters_crawls;
525 }
526
527 /**
528 * Gets an instance of the fileEditor class
529 *
530 */
531 function wp_get_file_editor()
532 {
533 global $iwp_mmb_plugin_dir;
534 require_once("$iwp_mmb_plugin_dir/addons/file_editor/file_editor.class.php");
535 if (!isset($this->get_file_editor)) {
536 $this->get_file_editor = new IWP_MMB_fileEditor();
537 }
538
539 return $this->get_file_editor;
540 }
541
542
543 /**
544 * Gets an instance of the yoastWpSeo class
545 *
546 */
547 function wp_get_yoast_seo()
548 {
549 global $iwp_mmb_plugin_dir;
550 require_once("$iwp_mmb_plugin_dir/addons/yoast_wp_seo/yoast_wp_seo.class.php");
551 if (!isset($this->get_yoast_seo)) {
552 $this->get_yoast_seo = new IWP_MMB_YWPSEO();
553 }
554
555 return $this->get_yoast_seo;
556 }
557
558
559 /**
560 * Gets an instance of the Comment class
561 *
562 */
563 function get_comment_instance()
564 {
565 if (!isset($this->comment_instance)) {
566 $this->comment_instance = new IWP_MMB_Comment();
567 }
568
569 return $this->comment_instance;
570 }
571
572 /**
573 * Gets an instance of the Plugin class
574 *
575 */
576 function get_plugin_instance()
577 {
578 if (!isset($this->plugin_instance)) {
579 $this->plugin_instance = new IWP_MMB_Plugin();
580 }
581
582 return $this->plugin_instance;
583 }
584
585 /**
586 * Gets an instance of the Theme class
587 *
588 */
589 function get_theme_instance()
590 {
591 if (!isset($this->theme_instance)) {
592 $this->theme_instance = new IWP_MMB_Theme();
593 }
594
595 return $this->theme_instance;
596 }
597
598
599 /**
600 * Gets an instance of IWP_MMB_Post class
601 *
602 */
603 function get_post_instance()
604 {
605 if (!isset($this->post_instance)) {
606 $this->post_instance = new IWP_MMB_Post();
607 }
608
609 return $this->post_instance;
610 }
611
612 /**
613 * Gets an instance of Blogroll class
614 *
615 */
616 function get_blogroll_instance()
617 {
618 if (!isset($this->blogroll_instance)) {
619 $this->blogroll_instance = new IWP_MMB_Blogroll();
620 }
621
622 return $this->blogroll_instance;
623 }
624
625
626
627 /**
628 * Gets an instance of the WP class
629 *
630 */
631 function get_wp_instance()
632 {
633 if (!isset($this->wp_instance)) {
634 $this->wp_instance = new IWP_MMB_WP();
635 }
636
637 return $this->wp_instance;
638 }
639
640 /**
641 * Gets an instance of User
642 *
643 */
644 function get_user_instance()
645 {
646 if (!isset($this->user_instance)) {
647 $this->user_instance = new IWP_MMB_User();
648 }
649
650 return $this->user_instance;
651 }
652
653 /**
654 * Gets an instance of stats class
655 *
656 */
657 function get_stats_instance()
658 {
659 if (!isset($this->stats_instance)) {
660 $this->stats_instance = new IWP_MMB_Stats();
661 }
662 return $this->stats_instance;
663 }
664 /**
665 * Gets an instance of search class
666 *
667 */
668 function get_search_instance()
669 {
670 if (!isset($this->search_instance)) {
671 $this->search_instance = new IWP_MMB_Search();
672 }
673 //return $this->search_instance;
674 return $this->search_instance;
675 }
676 /**
677 * Gets an instance of stats class
678 *
679 */
680 function get_new_backup_instance($params = array())
681 {
682 if ((isset($iwp_backup_core) && is_object($iwp_backup_core) && is_a($iwp_backup_core, 'IWP_MMB_Backup_Core'))) return $iwp_backup_core;
683
684 require_once($GLOBALS['iwp_mmb_plugin_dir'].'/backup/backup.core.class.php');
685 iwp_mmb_define_constant();
686 $iwp_backup_core = new IWP_MMB_Backup_Core();
687 $GLOBALS['iwp_backup_core'] = $iwp_backup_core;
688 $this->backup_new_instance = $iwp_backup_core;
689 if (!$iwp_backup_core->memory_check(192)) {
690 if (!$iwp_backup_core->memory_check($iwp_backup_core->memory_check_current(WP_MAX_MEMORY_LIMIT))) {
691 $new = absint($iwp_backup_core->memory_check_current(WP_MAX_MEMORY_LIMIT));
692 if ($new>32 && $new<100000) {
693 @ini_set('memory_limit', $new.'M');
694 }
695 }
696 }
697 return $this->backup_new_instance;
698 }
699
700 function get_backup_instance($mechanism='')
701 {
702 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup.class.singlecall.php");
703 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup.class.multicall.php");
704 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup/backup-repo-test.php");
705 //$mechanism = 'multiCall';
706 if (!isset($this->backup_instance)) {
707 if($mechanism == 'singleCall' || $mechanism == ''){
708 $this->backup_instance = new IWP_MMB_Backup_Singlecall();
709 }
710 elseif($mechanism == 'multiCall'){
711 $this->backup_instance = new IWP_MMB_Backup_Multicall();
712 }
713 else{
714 iwp_mmb_response(array('error' => 'mechanism not found'), true);
715 //return false;
716 }
717 }
718
719 return $this->backup_instance;
720 }
721
722 function get_ithemessec_instance() {
723 require_once($GLOBALS['iwp_mmb_plugin_dir'] . "/addons/itheme_security/class-iwp-client-ithemes-security-class.php");
724 if (!isset($this->ithemessec_instance)) {
725 $this->ithemessec_instance = new IWP_MMB_IThemes_security();
726 }
727 return $this->ithemessec_instance;
728 }
729
730 function get_backup_repository_instance()
731 {
732 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup.class.singlecall.php");
733 require_once($GLOBALS['iwp_mmb_plugin_dir']."/backup.class.multicall.php");
734 if (!isset($this->backup_repository_instance)) {
735 $this->backup_repository_instance = new IWP_MMB_Backup_Repository();
736 }
737
738 return $this->backup_repository_instance;
739 }
740
741 /**
742 * Gets an instance of links class
743 *
744 */
745 function get_link_instance()
746 {
747 if (!isset($this->link_instance)) {
748 $this->link_instance = new IWP_MMB_Link();
749 }
750
751 return $this->link_instance;
752 }
753
754 function get_installer_instance()
755 {
756 if (!isset($this->installer_instance)) {
757 $this->installer_instance = new IWP_MMB_Installer();
758 }
759 return $this->installer_instance;
760 }
761
762 function check_plugin_activated($pluginBasename){
763 if(is_plugin_active_for_network($pluginBasename)){
764 return true;
765 }else if(is_plugin_active($pluginBasename)){
766 return true;
767 }
768 return false;
769 }
770
771 /*
772 * Get an instance of WordFence
773 */
774 function get_wordfence_instance()
775 {
776 if (!isset($this->wordfence_instance)) {
777 $this->wordfence_instance = new IWP_WORDFENCE();
778 }
779 return $this->wordfence_instance;
780 }
781 /*
782 * Get an instance of WordFence
783 */
784 function get_sucuri_instance()
785 {
786 if (!isset($this->sucuri_instance)) {
787 $this->sucuri_instance = new IWP_MMB_Sucuri();
788 }
789 return $this->sucuri_instance;
790 }
791
792 public function buildLoaderContent($pluginBasename)
793 {
794 $loader = <<<EOF
795 <?php
796
797 /*
798 Plugin Name: InfiniteWP - Client Loader
799 Plugin URI: https://infinitewp.com/
800 Description: This plugin will be created automatically when you activate your InfiniteWP Client plugin to improve the performance. And it will be deleted when you deactivate the client plugin.
801 Author: Revmakx
802 Version: 1.0.1
803 Author URI: https://infinitewp.com/
804 */
805
806 if (!function_exists('untrailingslashit') || !defined('WP_PLUGIN_DIR')) {
807 // WordPress is probably not bootstrapped.
808 exit;
809 }
810
811 if (file_exists(untrailingslashit(WP_PLUGIN_DIR).'/$pluginBasename')) {
812 if (in_array('$pluginBasename', (array) get_option('active_plugins')) ||
813 (function_exists('get_site_option') && array_key_exists('iwp-client/init.php', (array) get_site_option('active_sitewide_plugins')))) {
814 \$GLOBALS['iwp_is_mu'] = true;
815 include_once untrailingslashit(WP_PLUGIN_DIR).'/$pluginBasename';
816 }
817 }
818
819 EOF;
820
821 return $loader;
822 }
823
824 public function registerMustUse($loaderName, $loaderContent)
825 {
826 $mustUsePluginDir = rtrim(WPMU_PLUGIN_DIR, '/');
827 $loaderPath = $mustUsePluginDir.'/'.$loaderName;
828
829 if (file_exists($loaderPath) && md5($loaderContent) === md5_file($loaderPath)) {
830 return;
831 }
832
833 if (!is_dir($mustUsePluginDir)) {
834 $dirMade = @mkdir($mustUsePluginDir);
835
836 if (!$dirMade) {
837 $error = error_get_last();
838 return array('');
839 throw new Exception(sprintf('Unable to create loader directory: %s', $error['message']));
840 }
841 }
842
843 if (!is_writable($mustUsePluginDir)) {
844 throw new Exception('MU-plugin directory is not writable.');
845 }
846
847 $loaderWritten = @file_put_contents($loaderPath, $loaderContent);
848
849 if (!$loaderWritten) {
850 $error = error_get_last();
851 throw new Exception(sprintf('Unable to write loader: %s', $error['message']));
852 }
853 update_option('iwp_mu_plugin_version','1.0.1');
854 }
855
856 function error_notices()
857 {
858 $error_notice = get_transient( 'iwp_mu_plugin_loader' );
859 echo '<div class="error" style="text-align: center;"><p style="font-size: 14px; font-weight: bold; color:#c00;">Attention !</p>
860 <p>Unable to write InfiniteWP Client loader: '.$error_notice.'</p></div>';
861 }
862
863 function load_mu_loader_error(){
864 $error_notice = get_transient( 'iwp_mu_plugin_loader' );
865 if( !empty($error_notice) ){
866 add_action('admin_notices', array( &$this, 'error_notices' ));
867 }
868 }
869 /**
870 * Plugin install callback function
871 * Check PHP version
872 */
873 function install() {
874
875 global $wpdb, $_wp_using_ext_object_cache, $current_user, $iwp_mmb_activities_log;
876 $_wp_using_ext_object_cache = false;
877 try {
878 $this->registerMustUse('mu-iwp-client.php', $this->buildLoaderContent('iwp-client/init.php'));
879 } catch (Exception $e) {
880 set_transient( 'iwp_mu_plugin_loader', $e->getMessage(), 30 );
881 }
882 //delete plugin options, just in case
883 if ($this->iwp_mmb_multisite != false) {
884 $network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`");
885 if(!empty($network_blogs)){
886 if( is_network_admin() ){
887 update_option('iwp_client_network_admin_install', 1);
888 $mainBlogId = defined('BLOG_ID_CURRENT_SITE') ? BLOG_ID_CURRENT_SITE : false;
889 foreach($network_blogs as $details){
890 if (($mainBlogId !== false && $details->blog_id == $mainBlogId) || ($mainBlogId === false && $details->site_id == $details->blog_id)) {
891 update_blog_option($details->blog_id, 'iwp_client_network_admin_install', 1);
892 }
893 else {
894 update_blog_option($details->blog_id, 'iwp_client_network_admin_install', -1);
895 }
896
897 delete_blog_option($details->blog_id, 'iwp_client_nossl_key', '');
898 delete_blog_option($details->blog_id, 'iwp_client_public_key', '');
899 delete_blog_option($details->blog_id, 'iwp_client_action_message_id');
900 }
901 } else {
902 update_option('iwp_client_network_admin_install', -1);
903 delete_option('iwp_client_nossl_key');
904 delete_option('iwp_client_public_key');
905 delete_option('iwp_client_action_message_id');
906 }
907 }
908 } else {
909 delete_option('iwp_client_nossl_key');
910 delete_option('iwp_client_public_key');
911 delete_option('iwp_client_action_message_id');
912 }
913
914 //delete_option('iwp_client_backup_tasks');
915 delete_option('iwp_client_notifications');
916 delete_option('iwp_client_brand');
917 delete_option('iwp_client_public_key');
918 delete_option('iwp_client_pageview_alerts');
919
920 $this->update_option('iwp_client_activate_key', sha1( rand(1, 99999). uniqid('', true) . get_option('siteurl') ) );
921
922 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('install');
923 }
924
925 /**
926 * Saves the (modified) options into the database
927 *
928 */
929 function save_options()
930 {
931 if (get_option($this->slug)) {
932 update_option($this->slug, $this->settings);
933 } else {
934 add_option($this->slug, $this->settings);
935 }
936 }
937
938 /**
939 * Deletes options for communication with IWP Admin panel
940 *
941 */
942 function uninstall( $deactivate = false )
943 {
944 global $current_user, $wpdb, $_wp_using_ext_object_cache;
945 $_wp_using_ext_object_cache = false;
946
947 if ($this->iwp_mmb_multisite != false) {
948 $network_blogs = $wpdb->get_col("select `blog_id` from `{$wpdb->blogs}`");
949 if(!empty($network_blogs)){
950 if( is_network_admin() ){
951 if( $deactivate ) {
952 delete_option('iwp_client_network_admin_install');
953 foreach($network_blogs as $blog_id){
954 delete_blog_option($blog_id, 'iwp_client_network_admin_install');
955 delete_blog_option($blog_id, 'iwp_client_nossl_key');
956 delete_blog_option($blog_id, 'iwp_client_public_key');
957 delete_blog_option($blog_id, 'iwp_client_action_message_id');
958 delete_blog_option($blog_id, 'iwp_client_maintenace_mode');
959 }
960 }
961 } else {
962 if( $deactivate )
963 delete_option('iwp_client_network_admin_install');
964
965 delete_option('iwp_client_nossl_key');
966 delete_option('iwp_client_public_key');
967 delete_option('iwp_client_action_message_id');
968 }
969 }
970 } else {
971 delete_option('iwp_client_nossl_key');
972 delete_option('iwp_client_public_key');
973 delete_option('iwp_client_action_message_id');
974 }
975
976 //Delete options
977 delete_option('iwp_client_maintenace_mode');
978 //delete_option('iwp_client_backup_tasks');
979 wp_clear_scheduled_hook('iwp_client_backup_tasks');
980 delete_option('iwp_client_notifications');
981 wp_clear_scheduled_hook('iwp_client_notifications');
982 delete_option('iwp_client_brand');
983 delete_option('iwp_client_pageview_alerts');
984
985 delete_option('iwp_client_activate_key');
986 delete_option('iwp_client_all_themes_history');
987 delete_option('iwp_client_all_plugins_history');
988 delete_option('iwp_client_wp_version_old');
989 delete_option('is_save_activity_log');
990 $loaderName = 'mu-iwp-client.php';
991 try {
992 $mustUsePluginDir = rtrim(WPMU_PLUGIN_DIR, '/');
993 $loaderPath = $mustUsePluginDir.'/'.$loaderName;
994
995 if (!file_exists($loaderPath)) {
996 return;
997 }
998
999 $removed = @unlink($loaderPath);
1000
1001 if (!$removed) {
1002 $error = error_get_last();
1003 throw new Exception(sprintf('Unable to remove loader: %s', $error['message']));
1004 }
1005 } catch (Exception $e) {
1006 mwp_logger()->error('Unable to remove loader', array('exception' => $e));
1007 }
1008 }
1009
1010
1011 /**
1012 * Constructs a url (for ajax purpose)
1013 *
1014 * @param mixed $base_page
1015 */
1016 function construct_url($params = array(), $base_page = 'index.php')
1017 {
1018 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
1019 foreach ($params as $key => $value) {
1020 $url .= "&$key=$value";
1021 }
1022
1023 return $url;
1024 }
1025
1026 /**
1027 * Client update
1028 *
1029 */
1030 function update_client_plugin($params)
1031 {
1032 global $iwp_mmb_activities_log;
1033 extract($params);
1034 if ($download_url) {
1035 @include_once ABSPATH . 'wp-admin/includes/file.php';
1036 @include_once ABSPATH . 'wp-admin/includes/plugin.php';
1037 @include_once ABSPATH . 'wp-admin/includes/misc.php';
1038 @include_once ABSPATH . 'wp-admin/includes/template.php';
1039 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1040 @include_once ABSPATH . 'wp-admin/includes/screen.php';
1041 if (!$this->define_ftp_constants($params)) {
1042 return array(
1043 'error' => 'FTP constant define failed', 'error_code' => 'ftp constant define failed'
1044 );
1045 }
1046 if (!$this->is_server_writable()) {
1047 return array(
1048 'error' => 'Failed, please add FTP details', 'error_code' => 'automatic_upgrade_failed_add_ftp_details'
1049 );
1050 }
1051
1052 ob_start();
1053 @unlink(dirname(__FILE__));
1054 $upgrader = new Plugin_Upgrader();
1055 $result = $upgrader->run(array(
1056 'package' => $download_url,
1057 'destination' => WP_PLUGIN_DIR,
1058 'clear_destination' => true,
1059 'clear_working' => true,
1060 'hook_extra' => array(
1061 'plugin' => 'iwp-client/init.php'
1062 )
1063 ));
1064 ob_end_clean();
1065 @wp_update_plugins();
1066
1067 if (is_wp_error($result) || !$result) {
1068 return array(
1069 'error' => 'InfiniteWP Client plugin could not be updated.', 'error_code' => 'client_plugin_could_not_be_updated'
1070 );
1071 } else {
1072
1073 $iwp_mmb_activities_log->iwp_mmb_save_options_for_activity_log('update_client_plugin');
1074
1075 return array(
1076 'success' => 'InfiniteWP Client plugin successfully updated.'
1077 );
1078 }
1079 }
1080 return array(
1081 'error' => 'Bad download path for client installation file.', 'error_code' => 'client_plugin_bad_download_path'
1082 );
1083 }
1084
1085 /**
1086 * Automatically logs in when called from IWP Admin panel
1087 *
1088 */
1089 function automatic_login()
1090 {
1091 $where = isset($_GET['iwp_goto']) ? $_GET['iwp_goto'] : false;
1092 $username = isset($_GET['username']) ? $_GET['username'] : '';
1093 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
1094 $page = isset($_GET['page']) ? '?page='.$_GET['page'] : '';
1095 $action = isset($_GET['action']) ? '?action='.$_GET['action'] : '';
1096 $post = isset($_GET['post']) ? '&post='.$_GET['post'] : '';
1097 $message_id = trim($_GET['message_id']);
1098 $_SERVER['HTTP_REFERER']='';
1099 if( !function_exists('is_user_logged_in') )
1100 include_once( ABSPATH.'wp-includes/pluggable.php' );
1101
1102 if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->iwp_mmb_multisite) && $this->iwp_mmb_multisite )) {
1103 $signature = base64_decode($_GET['signature']);
1104 $signature_new = '';
1105 if (!empty($_GET['signature_new'])) {
1106 $signature_new = base64_decode($_GET['signature_new']);
1107 }
1108 $message_id = trim($_GET['message_id']);
1109
1110 $auth = $this->authenticate_message($where . $message_id, $signature, $signature_new , $message_id);
1111 if ($auth === true) {
1112
1113 if (!headers_sent())
1114 header('P3P: CP="CAO PSA OUR"');
1115
1116 if(!defined('IWP_MMB_USER_LOGIN'))
1117 define('IWP_MMB_USER_LOGIN', true);
1118
1119 $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
1120 $user = $this->iwp_mmb_get_user_info($username);
1121 wp_set_current_user($user->ID);
1122
1123 if(!defined('COOKIEHASH') || (isset($this->iwp_mmb_multisite) && $this->iwp_mmb_multisite) )
1124 wp_cookie_constants();
1125
1126 wp_set_auth_cookie($user->ID);
1127 @iwp_mmb_client_header();
1128
1129 //if((isset($this->iwp_mmb_multisite) && $this->iwp_mmb_multisite ) || isset($_REQUEST['iwpredirect'])){//comment makes force redirect, which fix bug https dashboard
1130 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
1131 wp_safe_redirect(admin_url($where.$page.$action.$post));
1132 exit();
1133 }
1134 //}
1135 } else {
1136 wp_die($auth['error']);
1137 }
1138 } elseif( is_user_logged_in() ) {
1139 @iwp_mmb_client_header();
1140 //if(isset($_REQUEST['iwpredirect'])){
1141 $this->set_client_message_id($message_id);
1142 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
1143 wp_safe_redirect(admin_url($where.$page.$action.$post));
1144 exit();
1145 }
1146 //}
1147 }
1148 }
1149
1150 function iwp_mmb_set_auth_cookie( $auth_cookie ){
1151 if(!defined('IWP_MMB_USER_LOGIN'))
1152 return false;
1153
1154 if( !defined('COOKIEHASH') )
1155 wp_cookie_constants();
1156
1157 $_COOKIE['wordpress_'.COOKIEHASH] = $auth_cookie;
1158
1159 }
1160 function iwp_mmb_set_logged_in_cookie( $logged_in_cookie ){
1161 if(!defined('IWP_MMB_USER_LOGIN'))
1162 return false;
1163
1164 if( !defined('COOKIEHASH') )
1165 wp_cookie_constants();
1166
1167 $_COOKIE['wordpress_logged_in_'.COOKIEHASH] = $logged_in_cookie;
1168 }
1169
1170 function admin_actions(){
1171 $replace = get_option("iwp_client_brand");
1172 if(!empty($replace)){
1173 if(!empty($replace['hideUpdatesCPB'])){
1174 //define('DISALLOW_FILE_MODS',true); //for hiding updates old method
1175 }
1176 if(!empty($replace['hideFWPCPB'])){
1177 //define('DISALLOW_FILE_EDIT',true); //for hiding file writing permissions old method
1178 }
1179 if(!empty($replace['doChangesCPB']) || ( !isset($replace['doChangesCPB']) && (!empty($replace['name']) || !empty($replace['desc']) || !empty($replace['author']) || !empty($replace['author_url'])))){
1180 add_filter('plugin_row_meta', array($this, 'iwp_client_replace_row_meta'), 10, 2); //for hiding the view details alone.
1181 add_filter('site_transient_update_plugins', array($this, 'iwp_site_transient_update_plugins'), 10, 2); //for hiding the infiniteWP update details.
1182 add_filter('admin_url', array($this, 'iwp_user_admin_url'), 10, 2); //for modifying the link available in plugin's view version details link.
1183 }
1184 add_filter('all_plugins', array($this, 'client_replace')); //for replacing name and all.
1185 add_filter('show_advanced_plugins', array($this, 'muPluginListFilter'), 10, 2); //for replacing name and all.
1186 }
1187 }
1188
1189 function iwp_remove_core_updates($value){
1190 if(isset($value->response)){
1191 $old_response = $value->response;
1192 unset($value->response);
1193 }
1194 if(isset($value->updates)){
1195 unset($value->updates);
1196 }
1197 return $value;
1198 }
1199
1200 function iwp_admin_menu_actions($args){
1201 //to hide all updates
1202 global $iwp_mmb_core;
1203 $replace = get_option("iwp_client_brand");
1204 if(empty($iwp_mmb_core->request_params) && !empty($replace)){
1205 if(!empty($replace['hideUpdatesCPB'])){
1206 //add_filter('wp_get_update_data', array($this, 'iwp_wp_get_update_data'), 10, 2);
1207 $page = remove_submenu_page( 'index.php', 'update-core.php' );
1208 add_filter('transient_update_plugins', array($this, 'iwp_remove_core_updates'), 999999, 1);
1209 add_filter('site_transient_update_core', array($this, 'iwp_remove_core_updates'), 999999, 1);
1210 add_filter('site_transient_update_plugins', array($this, 'iwp_remove_core_updates'), 999999, 1);
1211 add_filter('site_transient_update_themes', array($this, 'iwp_remove_core_updates'), 999999, 1);
1212 }
1213 if(!empty($replace['hideFWPCPB'])){
1214 // remove_submenu_page('themes.php','theme-editor.php');
1215 // remove_submenu_page('plugins.php','plugin-editor.php'); // this is old method this allows editor in direct URL
1216 if (!defined('DISALLOW_FILE_EDIT')) {
1217 define('DISALLOW_FILE_EDIT', true);
1218 }
1219 add_filter('plugin_action_links', array($this, 'iwp_client_replace_action_links'), 10, 2);
1220 }
1221 }
1222 }
1223
1224 function iwp_cpb_hide_updates($args){
1225 global $iwp_mmb_core;
1226 $replace = get_option("iwp_client_brand");
1227 if(empty($iwp_mmb_core->request_params) && !empty($replace)){
1228 if(!empty($replace['hideUpdatesCPB'])){
1229 add_filter('transient_update_plugins', array($this, 'iwp_remove_core_updates'), 999999, 1);
1230 add_filter('site_transient_update_core', array($this, 'iwp_remove_core_updates'), 999999, 1);
1231 add_filter('site_transient_update_plugins', array($this, 'iwp_remove_core_updates'), 999999, 1);
1232 add_filter('site_transient_update_themes', array($this, 'iwp_remove_core_updates'), 999999, 1);
1233 }
1234 }
1235 }
1236
1237 function iwp_user_admin_url($args, $args2){
1238 //for modifying the link available in plugin's view version details link.
1239 if(strpos($args2, 'plugin-install.php?tab=plugin-information&plugin') !== false){
1240 $replace = get_option("iwp_client_brand");
1241 if(!empty($replace) && is_array($replace)){
1242 if(!empty($replace['name'])){
1243 $search_str = 'plugin-install.php?tab=plugin-information&plugin='.$replace['name'].'&section=changelog';
1244 if(strpos($args2, $search_str) !== false){
1245 $return_var = plugins_url( '/iwp-client/readme.txt' ) . 'TB_iframe=true&width=600&height=550';
1246 return $return_var;
1247 }
1248 }
1249 }
1250 }
1251 return $args;
1252 }
1253
1254 function iwp_site_transient_update_plugins($value){
1255 if(!empty($value->response['iwp-client/init.php'])){
1256 $replace = get_option("iwp_client_brand");
1257 if(!empty($replace) && is_array($replace)){
1258 if(!empty($replace['name'])){
1259 $file_traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
1260 $called_by_file = array_pop($file_traces);
1261 $called_by_file = basename($called_by_file['file']);
1262 if($called_by_file == "update-core.php"){
1263 unset($value->response['iwp-client/init.php']); //for hiding the updates available in updates dashboard section
1264 }
1265 else if($called_by_file == "plugins.php"){
1266 $value->response['iwp-client/init.php']->slug = $replace['name']; ////for hiding the updates available in plugins section
1267 $value->response['iwp-client/init.php']->Name = $replace['name'];
1268 unset($value->response['iwp-client/init.php']);
1269 }
1270 }
1271 }
1272 }
1273 return $value;
1274 }
1275
1276 function iwp_client_replace_action_links($links, $file){
1277 //for hiding edit on plugins page.
1278 if(!empty($links['edit'])){
1279 unset($links['edit']);
1280 }
1281 return $links;
1282 }
1283
1284 function iwp_client_replace_row_meta($links, $file) {
1285 //for hiding the view details alone.
1286 if($file == 'iwp-client/init.php'){
1287 if(!empty($links[2])){
1288 unset($links[2]);
1289 }
1290 }
1291 return $links;
1292 }
1293
1294 function client_replace($all_plugins){
1295 $replace = get_option("iwp_client_brand");
1296 if(is_array($replace)){
1297 if(!empty($replace['doChangesCPB']) || (!isset($replace['doChangesCPB']) && (!empty($replace['name']) || !empty($replace['desc']) || !empty($replace['author']) || !empty($replace['author_url'])))){
1298 $plugin_status = isset($_GET['plugin_status']) ? $_GET['plugin_status'] : '';
1299
1300 if ( 'incompatible_with_feature' !== $plugin_status ) {
1301 $all_plugins['iwp-client/init.php']['Name'] = $replace['name'];
1302 $all_plugins['iwp-client/init.php']['Title'] = $replace['name'];
1303 $all_plugins['iwp-client/init.php']['Description'] = $replace['desc'];
1304 $all_plugins['iwp-client/init.php']['AuthorURI'] = $replace['author_url'];
1305 $all_plugins['iwp-client/init.php']['Author'] = $replace['author'];
1306 $all_plugins['iwp-client/init.php']['AuthorName'] = $replace['author'];
1307 $all_plugins['iwp-client/init.php']['PluginURI'] = '';
1308 }
1309 }
1310
1311 if(!empty($replace['hide'])){
1312 if (!function_exists('get_plugins')){
1313 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
1314 }
1315 if( $this->iwp_mmb_multisite ){
1316 if(is_plugin_active_for_network('iwp-client/init.php')){
1317 unset($all_plugins['iwp-client/init.php']);
1318 }
1319 }else{
1320 $activated_plugins = get_option('active_plugins');
1321 if (!$activated_plugins){
1322 $activated_plugins = array();
1323 }
1324 if(in_array('iwp-client/init.php',$activated_plugins)){
1325 unset($all_plugins['iwp-client/init.php']);
1326 }
1327 }
1328 }
1329 }
1330
1331 return $all_plugins;
1332 }
1333
1334 function add_login_action(){
1335 add_action('plugins_loaded', array( &$this, 'automatic_login'), 10);
1336 }
1337
1338 function muPluginListFilter($previousValue, $type)
1339 {
1340 // Drop-in's are filtered after MU plugins.
1341 if ($type !== 'dropins') {
1342 return $previousValue;
1343 }
1344
1345 if (!empty($previousValue['iwp-client/init.php'])) {
1346 return $previousValue;
1347 }
1348 $replace = get_option("iwp_client_brand");
1349
1350 if (!empty($replace['hide'])) {
1351 unset($GLOBALS['plugins']['mustuse']['mu-iwp-client.php']);
1352 } elseif(!empty($replace['doChangesCPB']) || (!isset($replace['doChangesCPB']) && (!empty($replace['name']) || !empty($replace['desc']) || !empty($replace['author']) || !empty($replace['author_url'])))){
1353 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['Name'] = $replace['name'];
1354 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['Title'] = $replace['name'];
1355 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['Description'] = $replace['desc'];
1356 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['AuthorURI'] = $replace['author_url'];
1357 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['Author'] = $replace['author'];
1358 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['AuthorName'] = $replace['author'];
1359 $GLOBALS['plugins']['mustuse']['mu-iwp-client.php']['PluginURI'] = '';
1360 }
1361
1362 return $previousValue;
1363 }
1364 function updateKeys()
1365 {
1366 if (!$this->iwp_mmb_multisite) {
1367 return;
1368 }
1369
1370 global $wpdb;
1371
1372 $publicKey = $this->get_parent_blog_option('iwp_client_public_key');
1373
1374 if (empty($publicKey)) {
1375 return;
1376 }
1377
1378 $networkBlogs = $wpdb->get_results("select `blog_id` from `{$wpdb->blogs}`");
1379
1380 if (empty($networkBlogs)) {
1381 return;
1382 }
1383
1384 foreach ($networkBlogs as $details) {
1385 update_blog_option($details->blog_id, 'iwp_client_public_key', $publicKey);
1386 }
1387
1388 return;
1389 }
1390
1391 function addConnectionKeyLink($meta, $slug)
1392 {
1393 if (is_multisite() && !is_network_admin()) {
1394 return $meta;
1395 }
1396
1397 if ($slug !== 'iwp-client/init.php') {
1398 return $meta;
1399 }
1400
1401 if (!current_user_can('activate_plugins')) {
1402 return $meta;
1403 }
1404
1405 $meta[] = '<a href="#" id="iwp-view-connection-key" iwp-key="'.get_option('iwp_client_activate_key').'">View activation key</a>';
1406
1407 return $meta;
1408 }
1409
1410 function printConnectionModalOpenScript()
1411 {
1412 if (!current_user_can('activate_plugins')) {
1413 return;
1414 }
1415
1416 ob_start()
1417 ?>
1418 <script type="text/javascript">
1419 jQuery(document).ready(function($) {
1420 var $iwpconnectionKeyDialog = $('#iwp_connection_key_dialog');
1421 $('#iwp-view-connection-key').click(function(e) {
1422 e.preventDefault();
1423 $iwpconnectionKeyDialog.dialog({
1424 draggable: false,
1425 resizable: false,
1426 modal: true,
1427 width: '530px',
1428 height: 'auto',
1429 title: 'Activation Key',
1430 close: function() {
1431 $(this).dialog("destroy");
1432 }
1433 });
1434 });
1435 $('button.copy-key-button').click(function() {
1436 $('#activation-key').select();
1437 document.execCommand('copy');
1438 });
1439 });
1440 </script>
1441 <?php
1442
1443 $content = ob_get_clean();
1444 print $content;
1445 }
1446
1447 function printConnectionModalDialog()
1448 {
1449 if (is_multisite() && !is_network_admin()) {
1450 return;
1451 }
1452
1453 if (!current_user_can('activate_plugins')) {
1454 return;
1455 }
1456
1457 ob_start();
1458 ?>
1459 <div id="iwp_connection_key_dialog" style="display: none;">
1460
1461 <div style="text-align: center;font-weight: bold;"><p style="margin-bottom: 4px;margin-top: 20px;">Activation Key</p></div>
1462 <input id="activation-key" rows="1" style="padding: 10px;background-color: #fafafa;border: 1px solid black;border-radius: 10px;font-weight: bold;font-size: 14px;text-align: center; width: 85%; margin-right: 5px" onclick="this.focus();this.select()" readonly="readonly" value="<?php echo get_option('iwp_client_activate_key'); ?>">
1463 <button class="copy-key-button" data-clipboard-target="#activation-key" style="padding: 10px;background-color: #fafafa;border: 1px solid black;border-radius: 10px;font-weight: bold;font-size: 14px;text-align: center;">Copy</button>
1464 </div>
1465 <?php
1466
1467 $content = ob_get_clean();
1468 print $content;
1469 }
1470
1471 function get_option($option){
1472 if (is_multisite()) {
1473 return get_site_option($option);
1474 }
1475
1476 return get_option($option);
1477 }
1478
1479 function update_option($option, $option_value){
1480 if (is_multisite()) {
1481 global $wpdb;
1482 $blogIDs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
1483 foreach ($blogIDs as $blogID) {
1484 update_blog_option($blogID, $option, $option_value);
1485 }
1486 return true;
1487 } else {
1488 update_option($option, $option_value);
1489 return true;
1490 }
1491 return false;
1492 }
1493
1494 function enqueueConnectionModalOpenScripts(){
1495 wp_enqueue_script('jquery');
1496 wp_enqueue_script('jquery-ui-core');
1497 wp_enqueue_script('jquery-ui-dialog');
1498 }
1499
1500 function enqueueConnectionModalOpenStyles(){
1501 wp_enqueue_style('wp-jquery-ui');
1502 wp_enqueue_style('wp-jquery-ui-dialog');
1503 }
1504
1505 function get_db_details($params){
1506 global $wpdb;
1507 $result = array();
1508 if (defined('DB_HOST')) {
1509 $result['dbHost'] = DB_HOST;
1510 $result['dbName'] = DB_NAME;
1511 $result['dbUser'] = DB_USER;
1512 $result['dbPassword'] = DB_PASSWORD;
1513 $result['db_table_prefix'] = $wpdb->base_prefix;
1514 $result['site_url'] = site_url();
1515 $result['home_url'] = home_url();
1516 }
1517
1518 return $result;
1519 }
1520
1521 function flush_redis_cache(){
1522 @include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1523 if ( is_plugin_active( 'redis-cache/redis-cache.php' ) ) {
1524 @include_once(WP_PLUGIN_DIR . '/redis-cache/redis-cache.php');
1525 if(method_exists( $GLOBALS[ 'wp_object_cache' ], 'redis_status' )) {
1526 wp_cache_flush();
1527 }
1528 }
1529 }
1530
1531 function iwp_delete_option($option_name){
1532 if(!empty($option_name)){
1533 global $wpdb;
1534
1535 $delete_query = "DELETE FROM $wpdb->options WHERE option_name = '".$option_name."'";
1536 $affected = $wpdb->query($delete_query);
1537 if(!$affected){
1538 global $iwp_backup_core;
1539 $iwp_backup_core->log("Failed to delete $option_name option");
1540 $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
1541 $log = $bt[0]['file'].'-- line--'.$bt[0]['line'].'--function--'.$bt[0]['function'];
1542 $iwp_backup_core->log("$log");
1543 $iwp_backup_core->log("Retry delete $option_name option");
1544 // retry operation
1545 $query = "SELECT * FROM $wpdb->options WHERE option_name = '".$option_name."'";
1546 $temp_row = $wpdb->get_row($query);
1547 if(!empty($temp_row)){
1548 $wpdb->query($delete_query);
1549 }
1550 }
1551 }
1552 }
1553
1554 function iwp_update_option($option_name,$option_value){
1555 if(!empty($option_name)){
1556 global $wpdb;
1557 $sql = "INSERT INTO `$wpdb->options` (option_name,option_value) VALUES (%s,%s) ON DUPLICATE KEY UPDATE option_value = %s";
1558 $sql = $wpdb->prepare($sql,$option_name,$option_value,$option_value);
1559 $affected = $wpdb->query($sql);
1560 if($affected === false){
1561 global $iwp_backup_core;
1562 $iwp_backup_core->log("Failed to update $option_name option and value $option_value");
1563 $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
1564 $log = $bt[0]['file'].'-- line--'.$bt[0]['line'].'--function--'.$bt[0]['function'];
1565 $iwp_backup_core->log("$log");
1566 // retry operation
1567 $affected = $wpdb->query($sql);
1568 }
1569 }
1570 }
1571
1572 function get_max_allowed_packet(){
1573 global $wpdb;
1574 $query = "SHOW VARIABLES LIKE 'max_allowed_packet'";
1575 $temp_row = $wpdb->get_row($query);
1576 if(!empty($temp_row)){
1577 return $temp_row->Value; //1048576
1578 // $temp_row->Value/(1024*1024); // 1M
1579 }else{
1580 return '128M'; //Default 8M, so we tried with increase max_allowed_packet size
1581 }
1582 }
1583
1584 }
1585 ?>