PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.0.5
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.0.5
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-system.php

class-mainwp-system.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.0.5, at class/class-mainwp-system.php

3,113 lines 122.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //ini_set( 'display_errors', true );
4 //error_reporting( E_ALL | E_STRICT );
5
6 @ini_set( 'display_errors', false );
7 @error_reporting( 0 );
8
9 define( 'MAINWP_API_VALID', 'VALID' );
10 define( 'MAINWP_API_INVALID', 'INVALID' );
11
12 define( 'MAINWP_TWITTER_MAX_SECONDS', 60 * 5 ); // seconds
13
14 const MAINWP_VIEW_PER_SITE = 1;
15 const MAINWP_VIEW_PER_PLUGIN_THEME = 0;
16 const MAINWP_VIEW_PER_GROUP = 2;
17
18 class MainWP_System {
19
20 public static $version = '4.0.5';
21 //Singleton
22 private static $instance = null;
23 private $upgradeVersionInfo = null;
24
25 public $metaboxes;
26
27 /**
28 * The plugin current version
29 * @var string
30 */
31 private $current_version = null;
32
33 /**
34 * Plugin Slug (plugin_directory/plugin_file.php)
35 * @var string
36 */
37 private $plugin_slug;
38
39 /**
40 * Plugin name (plugin_file)
41 * @var string
42 */
43 public $slug;
44
45 /**
46 * @static
47 * @return MainWP_System
48 */
49 static function Instance() {
50 return self::$instance;
51 }
52
53 public function __construct( $mainwp_plugin_file ) {
54 MainWP_System::$instance = $this;
55 $this->load_all_options();
56 $this->update();
57 $this->plugin_slug = plugin_basename( $mainwp_plugin_file );
58 list ( $t1, $t2 ) = explode( '/', $this->plugin_slug );
59 $this->slug = str_replace( '.php', '', $t2 );
60
61 if ( is_admin() ) {
62 include_once( ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php' ); //Version information from wordpress
63 $pluginData = get_plugin_data( $mainwp_plugin_file );
64 $this->current_version = $pluginData[ 'Version' ];
65 $currentVersion = get_option( 'mainwp_plugin_version' );
66
67 if ( !empty( $currentVersion ) && version_compare( $currentVersion, '4.0', '<' ) && version_compare( $this->current_version, '4.0', '>=' ) ) {
68 add_action( 'mainwp_before_header', array( &$this, 'mainwp_4_update_notice' ) );
69 }
70
71 if ( empty( $currentVersion ) ) {
72 MainWP_Utility::update_option( 'mainwp_getting_started', 'started' );
73 } else if ( version_compare( $currentVersion, $this->current_version, '<' ) ) {
74 update_option( 'mainwp_reset_user_tips', array() );
75 MainWP_Utility::update_option( 'mainwp_reset_user_cookies', array() );
76 //MainWP_Utility::update_option( 'mainwp_getting_started', 'whatnew' );
77 } else {
78 delete_option( 'mainwp_getting_started' );
79 }
80
81 MainWP_Utility::update_option( 'mainwp_plugin_version', $this->current_version );
82 }
83
84 if ( !defined( 'MAINWP_VERSION' ) ) {
85 define( 'MAINWP_VERSION', $this->current_version );
86 }
87
88 if ( ( get_option( 'mainwp_upgradeVersionInfo' ) != '' ) && ( get_option( 'mainwp_upgradeVersionInfo' ) != null ) ) {
89 $this->upgradeVersionInfo = unserialize( get_option( 'mainwp_upgradeVersionInfo' ) );
90 } else {
91 $this->upgradeVersionInfo = null;
92 }
93
94 $ssl_api_verifyhost = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( get_option( 'mainwp_api_sslVerifyCertificate' ) == 1 ) ) ? 1 : 0;
95 if ( $ssl_api_verifyhost == 0 ) {
96 add_filter( 'http_request_args', array(
97 MainWP_Extensions::getClassName(),
98 'noSSLFilterExtensionUpgrade',
99 ), 99, 2 );
100 }
101
102 MainWP_Extensions::init();
103 add_action( 'parse_request', array( &$this, 'parse_request' ) );
104 add_action( 'init', array( &$this, 'localization' ) );
105
106 // define the alternative API for updating checking
107 add_filter( 'site_transient_update_plugins', array( &$this, 'check_update_custom' ) );
108
109 // Define the alternative response for information checking
110 add_filter( 'pre_set_site_transient_update_plugins', array( &$this, 'pre_check_update_custom' ) );
111 add_filter( 'plugins_api', array( &$this, 'check_info' ), 10, 3 );
112
113 $this->metaboxes = new MainWP_Meta_Boxes();
114
115 MainWP_Overview::get(); //init main dashboard
116
117 MainWP_Manage_Sites::init();
118 new MainWP_Hooks(); //Init the hooks
119 new MainWP_Menu(); // Init custom menu
120 //
121 //Change menu & widgets
122 add_action( 'admin_menu', array( &$this, 'new_menus' ) );
123
124 //Change footer
125 add_filter( 'admin_footer', array( &$this, 'admin_footer' ), 15 );
126
127 //Add js
128 add_action( 'admin_head', array( &$this, 'admin_head' ) );
129 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_styles' ) );
130 add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
131
132 //Add body class
133 add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
134
135 add_action( 'admin_post_mainwp_editpost', array( &$this, 'handle_edit_bulkpost' ) );
136
137 //Handle the bulkpost
138 add_action( 'save_post', array( &$this, 'save_bulkpost' ) );
139 add_action( 'save_post', array( &$this, 'save_bulkpage' ) );
140
141 //Add meta boxes for the bulkpost
142 add_action( 'admin_init', array( &$this, 'admin_init' ), 20 ); // $priority = 20 probably to fix conflict with post smtp overwrite wp mail function
143
144 //Create the post types for bulkpost/...
145 add_action( 'init', array( &$this, 'create_post_type' ) );
146 add_action( 'init', array( &$this, 'parse_init' ) );
147 add_action( 'init', array( &$this, 'init' ), 9999 );
148
149 add_action( 'admin_init', array( $this, 'admin_redirects' ) );
150
151 //Remove the pages from the menu which I use in AJAX
152 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
153
154 //Add custom error messages
155 add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages' ) );
156
157 add_action( 'login_form', array( &$this, 'login_form' ) );
158
159 //add_filter( 'print_admin_styles', array( &$this, 'print_admin_styles' ) );
160 add_action( 'admin_print_styles', array( &$this, 'admin_print_styles' ) );
161
162
163 MainWP_Install_Bulk::init();
164
165 do_action( 'mainwp_cronload_action' );
166
167 //Cron every 5 minutes
168 add_action( 'mainwp_cronstats_action', array( $this, 'mainwp_cronstats_action' ) );
169 add_action( 'mainwp_cronbackups_action', array( $this, 'mainwp_cronbackups_action' ) );
170 add_action( 'mainwp_cronbackups_continue_action', array( $this, 'mainwp_cronbackups_continue_action' ) );
171 add_action( 'mainwp_cronupdatescheck_action', array( $this, 'mainwp_cronupdatescheck_action' ) );
172 add_action( 'mainwp_cronpingchilds_action', array( $this, 'mainwp_cronpingchilds_action' ) );
173
174 add_filter( 'cron_schedules', array( 'MainWP_Utility', 'getCronSchedules' ) );
175
176 $useWPCron = ( get_option( 'mainwp_wp_cron' ) === false ) || ( get_option( 'mainwp_wp_cron' ) == 1 );
177
178 if ( ( $sched = wp_next_scheduled( 'mainwp_cronstats_action' ) ) == false ) {
179 if ( $useWPCron ) {
180 wp_schedule_event( time(), 'hourly', 'mainwp_cronstats_action' );
181 }
182 } else {
183 if ( !$useWPCron ) {
184 wp_unschedule_event( $sched, 'mainwp_cronstats_action' );
185 }
186 }
187
188 if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
189 if ( ( $sched = wp_next_scheduled( 'mainwp_cronbackups_action' ) ) == false ) {
190 if ( $useWPCron ) {
191 wp_schedule_event( time(), 'hourly', 'mainwp_cronbackups_action' );
192 }
193 } else {
194 if ( !$useWPCron ) {
195 wp_unschedule_event( $sched, 'mainwp_cronbackups_action' );
196 }
197 }
198
199 if ( ( $sched = wp_next_scheduled( 'mainwp_cronbackups_continue_action' ) ) == false ) {
200 if ( $useWPCron ) {
201 wp_schedule_event( time(), '5minutely', 'mainwp_cronbackups_continue_action' );
202 }
203 } else {
204 if ( !$useWPCron ) {
205 wp_unschedule_event( $sched, 'mainwp_cronbackups_continue_action' );
206 }
207 }
208 } else {
209 if ( $sched = wp_next_scheduled( 'mainwp_cronbackups_action' ) ) {
210 wp_unschedule_event( $sched, 'mainwp_cronbackups_action' );
211 }
212 if ( $sched = wp_next_scheduled( 'mainwp_cronbackups_continue_action' ) ) {
213 wp_unschedule_event( $sched, 'mainwp_cronbackups_continue_action' );
214 }
215 }
216
217 if ( ( $sched = wp_next_scheduled( 'mainwp_cronremotedestinationcheck_action' ) ) != false ) {
218 wp_unschedule_event( $sched, 'mainwp_cronremotedestinationcheck_action' );
219 }
220
221 if ( ( $sched = wp_next_scheduled( 'mainwp_cronpingchilds_action' ) ) == false ) {
222 if ( $useWPCron ) {
223 wp_schedule_event( time(), 'daily', 'mainwp_cronpingchilds_action' );
224 }
225 } else {
226 if ( !$useWPCron ) {
227 wp_unschedule_event( $sched, 'mainwp_cronpingchilds_action' );
228 }
229 }
230
231 if ( ( $sched = wp_next_scheduled( 'mainwp_cronupdatescheck_action' ) ) == false ) {
232 if ( $useWPCron ) {
233 wp_schedule_event( time(), 'minutely', 'mainwp_cronupdatescheck_action' );
234 }
235 } else {
236 if ( !$useWPCron ) {
237 wp_unschedule_event( $sched, 'mainwp_cronupdatescheck_action' );
238 }
239 }
240
241 add_action( 'mainwp_before_header', array( &$this, 'admin_notices' ) );
242 add_action( 'admin_notices', array( &$this, 'wp_admin_notices' ) );
243
244 // to fix layout
245
246 add_action( 'after_plugin_row', array( &$this, 'after_extensions_plugin_row' ), 10, 3 );
247
248 add_filter( 'mainwp-activated-check', array( &$this, 'activated_check' ) );
249 add_filter( 'mainwp-activated-sub-check', array( &$this, 'activated_sub_check' ) );
250 add_filter( 'mainwp-extension-enabled-check', array( MainWP_Extensions::getClassName(), 'isExtensionEnabled' ) );
251
252 /**
253 * This hook allows you to get a list of sites via the 'mainwp-getsites' filter.
254 * @link http://codex.mainwp.com/#mainwp-getsites
255 *
256 * @see \MainWP_Extensions::hookGetSites
257 */
258 add_filter( 'mainwp-getsites', array( MainWP_Extensions::getClassName(), 'hookGetSites' ), 10, 5 );
259 add_filter( 'mainwp-getdbsites', array( MainWP_Extensions::getClassName(), 'hookGetDBSites' ), 10, 5 );
260
261 /**
262 * This hook allows you to get a information about groups via the 'mainwp-getgroups' filter.
263 * @link http://codex.mainwp.com/#mainwp-getgroups
264 *
265 * @see \MainWP_Extensions::hookGetGroups
266 */
267 add_filter( 'mainwp-getgroups', array( MainWP_Extensions::getClassName(), 'hookGetGroups' ), 10, 4 );
268 add_action( 'mainwp_fetchurlsauthed', array( &$this, 'filter_fetchUrlsAuthed' ), 10, 7 );
269 add_filter( 'mainwp_fetchurlauthed', array( &$this, 'filter_fetchUrlAuthed' ), 10, 6 );
270 add_filter( 'mainwp_getdashboardsites', array(
271 MainWP_Extensions::getClassName(),
272 'hookGetDashboardSites',
273 ), 10, 7 );
274 add_filter( 'mainwp-manager-getextensions', array(
275 MainWP_Extensions::getClassName(),
276 'hookManagerGetExtensions',
277 ) );
278
279
280 // hook to support extensions: boilerplate, post dripper ==> may remove in future
281 add_filter( 'mainwp_bulkpost_metabox_handle', array( $this, 'bulkpost_metabox_handle' ), 10, 2 );
282 add_filter( 'mainwp_bulkpage_metabox_handle', array( $this, 'bulkpage_metabox_handle' ), 10, 2 );
283
284 //new MainWP_Post_Handler();
285
286 do_action( 'mainwp-activated' );
287
288
289 MainWP_Updates::init();
290 MainWP_Post::init();
291 MainWP_Settings::init();
292 if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
293 MainWP_Manage_Backups::init();
294 }
295 MainWP_User::init();
296 MainWP_Page::init();
297 MainWP_Themes::init();
298 MainWP_Plugins::init();
299 MainWP_Updates_Overview::init();
300 MainWP_Setup_Wizard::init();
301 if ( defined( 'WP_CLI' ) && WP_CLI ) {
302 MainWP_WP_CLI_Command::init();
303 }
304 //WP-Cron
305 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
306 if ( isset( $_GET[ 'mainwp_run' ] ) && !empty( $_GET[ 'mainwp_run' ] ) ) {
307 add_action( 'init', array( $this, 'cron_active' ), PHP_INT_MAX );
308 }
309 }
310 add_action( 'mainwp_admin_footer', array( 'MainWP_UI', 'usersnap_integration' ) );
311 }
312
313 function load_all_options() {
314 global $wpdb;
315
316 if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
317 $alloptions = wp_cache_get( 'alloptions', 'options' );
318 else
319 $alloptions = false;
320
321 if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
322 $notoptions = wp_cache_get( 'notoptions', 'options' );
323 else
324 $notoptions = false;
325
326 if ( !isset( $alloptions[ 'mainwp_db_version' ] ) ) {
327 $suppress = $wpdb->suppress_errors();
328 $options = array(
329 'mainwp_db_version',
330 'mainwp_plugin_version',
331 'mainwp_upgradeVersionInfo',
332 'mainwp_extensions',
333 'mainwp_manager_extensions',
334 'mainwp_getting_started',
335 'mainwp_activated',
336 'mainwp_api_sslVerifyCertificate',
337 'mainwp_automaticDailyUpdate',
338 'mainwp_backup_before_upgrade',
339 'mainwp_enableLegacyBackupFeature',
340 'mainwp_hide_twitters_message',
341 'mainwp_maximumInstallUpdateRequests',
342 'mainwp_maximumSyncRequests',
343 'mainwp_primaryBackup',
344 'mainwp_refresh',
345 'mainwp_security',
346 'mainwp_use_favicon',
347 'mainwp_wp_cron',
348 'mainwp_timeDailyUpdate',
349 'mainwp_frequencyDailyUpdate',
350 'mainwp_wpcreport_extension',
351 'mainwp_daily_digest_plain_text',
352 'mainwp_enable_managed_cr_for_wc',
353 'mainwp_hide_update_everything',
354 'mainwp_show_usersnap',
355 'mainwp_number_overview_columns',
356 'mainwp_disable_update_confirmations',
357 'mainwp_settings_hide_widgets',
358 'mainwp_settings_hide_manage_sites_columns'
359 );
360
361 $query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
362 foreach ( $options as $option ) {
363 $query .= "'" . $option . "', ";
364 }
365 $query = substr( $query, 0, strlen( $query ) - 2 );
366 $query .= ")";
367
368 $alloptions_db = $wpdb->get_results( $query );
369 $wpdb->suppress_errors( $suppress );
370 if ( !is_array( $alloptions ) )
371 $alloptions = array();
372 if ( is_array( $alloptions_db ) ) {
373 foreach ( (array) $alloptions_db as $o ) {
374 $alloptions[ $o->option_name ] = $o->option_value;
375 unset( $options[ array_search( $o->option_name, $options ) ] );
376 }
377 foreach ( $options as $option ) {
378 $notoptions[ $option ] = true;
379 }
380 if ( !defined( 'WP_INSTALLING' ) || !is_multisite() ) {
381 wp_cache_set( 'alloptions', $alloptions, 'options' );
382 wp_cache_set( 'notoptions', $notoptions, 'options' );
383 }
384 }
385 }
386
387 return $alloptions;
388 }
389
390 function cron_active() {
391 if ( !defined( 'DOING_CRON' ) || !DOING_CRON ) {
392 return;
393 }
394 if ( empty( $_GET[ 'mainwp_run' ] ) || 'test' !== $_GET[ 'mainwp_run' ] ) {
395 return;
396 }
397 @session_write_close();
398 @header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ), TRUE );
399 @header( 'X-Robots-Tag: noindex, nofollow', TRUE );
400 @header( 'X-MainWP-Version: ' . MainWP_System::$version, TRUE );
401 nocache_headers();
402 if ( $_GET[ 'mainwp_run' ] == 'test' ) {
403 die( 'MainWP Test' );
404 }
405 die( '' );
406 }
407
408 function filter_fetchUrlsAuthed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output ) {
409 return MainWP_Extensions::hookFetchUrlsAuthed( $pluginFile, $key, $dbwebsites, $what, $params, $handle, $output );
410 }
411
412 function filter_fetchUrlAuthed( $pluginFile, $key, $websiteId, $what, $params, $raw_response = null ) {
413 return MainWP_Extensions::hookFetchUrlAuthed( $pluginFile, $key, $websiteId, $what, $params, $raw_response );
414 }
415
416 // may remove in future
417 function bulkpost_metabox_handle( $boolean, $post_id ) {
418 $output = $this->metaboxes->select_sites_handle( $post_id, 'bulkpost' );
419 $this->metaboxes->add_categories_handle( $post_id, 'bulkpost' );
420 $this->metaboxes->add_tags_handle( $post_id, 'bulkpost' );
421 $this->metaboxes->add_slug_handle( $post_id, 'bulkpost' );
422 MainWP_Post::add_sticky_handle( $post_id );
423 return $output;
424 }
425
426 // may remove in future
427 function bulkpage_metabox_handle( $boolean, $post_id ) {
428 $output = $this->metaboxes->select_sites_handle( $post_id, 'bulkpage' );
429 $this->metaboxes->add_slug_handle( $post_id, 'bulkpage' );
430 MainWP_Page::add_status_handle( $post_id );
431 return $output;
432 }
433
434 public function after_extensions_plugin_row( $plugin_slug, $plugin_data, $status ) {
435 $extensions = MainWP_Extensions::getExtensions();
436 if ( !isset( $extensions[ $plugin_slug ] ) ) {
437 return;
438 }
439
440 if ( !isset( $extensions[$plugin_slug]['apiManager'] ) || !$extensions[$plugin_slug]['apiManager'] ) {
441 return;
442 }
443
444 if ( isset( $extensions[ $plugin_slug ][ 'activated_key' ] ) && 'Activated' == $extensions[ $plugin_slug ][ 'activated_key' ] ) {
445 return;
446 }
447
448 $slug = basename( $plugin_slug, ".php" );
449
450
451 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
452 if ( is_array( $activate_notices ) ) {
453 if ( isset( $activate_notices[ $slug ] ) ) {
454 return;
455 }
456 }
457
458 $notice_html = sprintf( __( "You have a MainWP Extension that does not have an active API entered. This means you will not receive updates or support. Please visit the %sExtensions%s page and enter your API.", 'mainwp' ), '<a href="admin.php?page=Extensions">', '</a>' );
459 ?>
460 <style type="text/css">
461 tr[data-plugin="<?php echo esc_attr($plugin_slug); ?>"] {
462 box-shadow: none;
463 }
464 </style>
465 <tr class="plugin-update-tr active" slug="<?php echo esc_attr($slug); ?>"><td colspan="3" class="plugin-update colspanchange"><div class="update-message api-deactivate">
466 <?php echo $notice_html; ?>
467 <span class="mainwp-right"><a href="#" class="mainwp-activate-notice-dismiss" ><i class="times circle icon"></i> <?php _e( 'Dismiss', 'mainwp' ); ?></a></span>
468 </div></td></tr>
469 <?php
470 }
471
472 public function parse_request() {
473 if ( file_exists( MAINWP_PLUGIN_DIR . "/response/api.php" ) ) {
474 include_once MAINWP_PLUGIN_DIR . "/response/api.php";
475 }
476 }
477
478 public function localization() {
479 load_plugin_textdomain( 'mainwp', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
480 }
481
482 public function activated_check() {
483 return $this->getVersion();
484 }
485
486 public function activated_sub_check() {
487 return array( 'result' => MAINWP_API_VALID );
488 }
489
490 public function mainwp_4_update_notice() {
491 if ( MainWP_Utility::showMainWPMessage( 'notice', 'upgrade_4' ) ) {
492 ?>
493 <div class="ui icon message yellow" style="margin-bottom: 0; border-radius: 0;">
494 <i class="exclamation circle icon"></i>
495 <strong><?php echo __( 'Important Notice: ', 'mainwp' ); ?></strong>&nbsp;<?php echo sprintf( __( 'MainWP Version 4 is a major upgrade from MainWP Version 3. Please, read this&nbsp; %supdating FAQ%s.', 'mainwp' ), '<a href="https://mainwp.com/help/docs/faq-on-upgrading-from-mainwp-version-3-to-mainwp-version-4/" target="_blank">', '</a>' ); ?>
496 <i class="close icon mainwp-notice-dismiss" notice-id="upgrade_4"></i>
497 </div>
498 <?php
499 }
500 }
501
502 public function admin_notices() {
503 if ( get_option( 'mainwp_refresh' ) ) {
504 echo '<meta http-equiv="refresh" content="0">';
505 delete_option( 'mainwp_refresh' );
506 }
507
508 $current_options = get_option( 'mainwp_showhide_events_notice' );
509 if ( !is_array( $current_options ) ) {
510 $current_options = array();
511 }
512
513 $phpver = phpversion();
514 if ( version_compare( $phpver, '5.5', '<' ) ) {
515 if ( MainWP_Utility::showMainWPMessage( 'notice', 'phpver_5_5' ) ) {
516 ?>
517 <div class="ui icon yellow message" style="margin-bottom: 0; border-radius: 0;">
518 <i class="exclamation circle icon"></i>
519 <?php echo sprintf( __( 'Your server is currently running PHP version %s. In the next few months your MainWP Dashboard will require PHP 5.6 as a minimum. Please upgrade your server to at least 5.6 but we recommend PHP 7 or newer. You can find a template email to send your host %shere%s.', 'mainwp' ), $phpver, '<a href="https://wordpress.org/about/requirements/" target="_blank">', '</a>' ); ?>
520 <i class="close icon mainwp-notice-dismiss" notice-id="phpver_5_5"></i>
521 </div>
522 <?php
523 }
524 }
525
526 if ( MainWP_Server_Information::isOpensslConfigWarning() ) {
527 if ( MainWP_Utility::showMainWPMessage( 'notice', 'ssl_warn' ) ) {
528 if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != 'SettingsAdvanced' ) {
529 ?>
530 <div class="ui icon yellow message" style="margin-bottom: 0; border-radius: 0;">
531 <i class="exclamation circle icon"></i>
532 <?php echo sprintf( __( 'MainWP has detected that the <strong>OpenSSL.cnf</strong> file is not configured properly. It is required to configure this so you can start connecting your child sites. Please, %sclick here to configure it!%s', 'mainwp' ), '<a href="admin.php?page=SettingsAdvanced">', '</a>' ); ?>
533 <i class="close icon mainwp-notice-dismiss" notice-id="ssl_warn"></i>
534 </div>
535 <?php
536 }
537 }
538 }
539
540 if ( is_multisite() && (!isset( $current_options[ 'hide_multi_site_notice' ] ) || empty( $current_options[ 'hide_multi_site_notice' ] ) ) ) {
541 ?>
542 <div class="ui icon red message" style="margin-bottom: 0; border-radius: 0;">
543 <i class="exclamation circle icon"></i>
544 <?php esc_html_e( 'MainWP plugin is not designed nor fully tested on WordPress Multisite installations. Various features may not work properly. We highly recommend installing it on a single site installation!', 'mainwp' ); ?>
545 <i class="close icon mainwp-notice-dismiss" notice-id="multi_site"></i>
546 </div>
547 <?php
548 }
549
550 if ( ! isset( $current_options[ 'trust_child' ] ) || empty( $current_options[ 'trust_child' ] ) ) {
551 if ( self::isMainWP_Pages() ) {
552 if ( ! MainWP_Plugins::checkAutoUpdatePlugin( 'mainwp-child/mainwp-child.php' ) ) {
553 ?>
554 <div class="ui icon yellow message" style="margin-bottom: 0; border-radius: 0;">
555 <i class="info circle icon"></i>
556 <div class="content">
557 <?php esc_html_e( 'You have not set your MainWP Child plugins for auto updates, this is highly recommended!', 'mainwp' ); ?> <a id="mainwp_btn_autoupdate_and_trust" class="ui mini yellow button" href="#"><?php esc_html_e( 'Turn On', 'mainwp' ); ?></a>
558 </div>
559 <i class="close icon mainwp-events-notice-dismiss" notice="trust_child"></i>
560 </div>
561 <?php
562 }
563 }
564 }
565
566 $display_request1 = $display_request2 = false;
567
568 if ( isset( $current_options[ 'request_reviews1' ] ) ) {
569 if ( $current_options[ 'request_reviews1' ] == 'forever' ) {
570 $display_request1 = false;
571 } else {
572 $days = intval( $current_options[ 'request_reviews1' ] ); // 15 or 30
573 $start_time = $current_options[ 'request_reviews1_starttime' ];
574 $display_request1 = ( ( time() - $start_time ) > $days * 24 * 3600 ) ? true : false;
575 }
576 } else {
577 $current_options[ 'request_reviews1' ] = 30;
578 $current_options[ 'request_reviews1_starttime' ] = time();
579 update_option( 'mainwp_showhide_events_notice', $current_options );
580 }
581
582 if ( isset( $current_options[ 'request_reviews2' ] ) ) {
583 if ( $current_options[ 'request_reviews2' ] == 'forever' ) {
584 $display_request2 = false;
585 } else {
586 $days = intval( $current_options[ 'request_reviews2' ] ); // 15
587 $start_time = $current_options[ 'request_reviews2_starttime' ];
588 $display_request2 = ( ( time() - $start_time ) > $days * 24 * 3600 ) ? true : false;
589 }
590 } else {
591 $currentExtensions = ( MainWP_Extensions::$extensionsLoaded ? MainWP_Extensions::$extensions : get_option( 'mainwp_extensions' ) );
592 if ( is_array( $currentExtensions ) && count( $currentExtensions ) > 10 ) {
593 $display_request2 = true;
594 }
595 }
596
597 if ( $display_request1 ) {
598 ?>
599 <div class="ui green icon message" style="margin-bottom: 0; border-radius: 0;">
600 <i class="star icon"></i>
601 <div class="content">
602 <div class="header">
603 <?php esc_html_e( 'Hi, I noticed you have been using MainWP for over 30 days and that\'s awesome!', 'mainwp' ); ?>
604 </div>
605 <?php esc_html_e( 'Could you please do me a BIG favor and give it a 5-star rating on WordPress? Reviews from users like you really help the MainWP community grow.', 'mainwp' ); ?>
606 <br /><br />
607 <a href="https://wordpress.org/support/view/plugin-reviews/mainwp#postform" target="_blank" class="ui green mini button"><?php esc_html_e( 'Ok, you deserve!', 'mainwp' ); ?></a>
608 <a href="" class="ui mini green basic button mainwp-events-notice-dismiss" notice="request_reviews1"><?php esc_html_e( 'Nope, maybe later.', 'mainwp' ); ?></a>
609 <a href="" class="ui mini green basic button mainwp-events-notice-dismiss" notice="request_reviews1_forever"><?php esc_html_e( 'I already did.', 'mainwp' ); ?></a>
610 </div>
611 <i class="close icon mainwp-notice-dismiss" notice="request_reviews1"></i>
612 </div>
613 <?php } else if ( $display_request2 ) { ?>
614 <div class="ui green icon message" style="margin-bottom: 0; border-radius: 0;">
615 <i class="star icon"></i>
616 <div class="content">
617 <div class="header">
618 <?php esc_html_e( 'Hi, I noticed you have a few MainWP Extensions installed and that\'s awesome!', 'mainwp' ); ?>
619 </div>
620 <?php esc_html_e( 'Could you please do me a BIG favor and give it a 5-star rating on WordPress? Reviews from users like you really help the MainWP community to grow.', 'mainwp' ); ?>
621 <br /><br />
622 <a href="https://wordpress.org/support/view/plugin-reviews/mainwp#postform" target="_blank" class="ui green mini button"><?php esc_html_e( 'Ok, you deserve!', 'mainwp' ); ?></a>
623 <a href="" class="ui mini green basic button mainwp-events-notice-dismiss" notice="request_reviews2"><?php esc_html_e( 'Nope, maybe later.', 'mainwp' ); ?></a>
624 <a href="" class="ui mini green basic button mainwp-events-notice-dismiss" notice="request_reviews2_forever"><?php esc_html_e( 'I already did.', 'mainwp' ); ?></a>
625 </div>
626 <i class="close icon mainwp-notice-dismiss" notice="request_reviews2"></i>
627 </div>
628 <?php
629 }
630 }
631
632
633 public function wp_admin_notices() {
634 global $pagenow;
635
636 if ( $pagenow !== 'plugins.php' )
637 return;
638
639 $deactivated_exts = get_transient( 'mainwp_transient_deactivated_incomtible_exts' );
640
641 if ( $deactivated_exts && is_array( $deactivated_exts ) && count( $deactivated_exts ) > 0 ) {
642 //delete_transient( 'mainwp_transient_deactivated_incomtible_exts' );
643 ?>
644 <div class='notice notice-error my-dismiss-notice is-dismissible'>
645 <p><?php echo __( 'MainWP Dashboard 4.0 or newer requires Extensions 4.0 or newer. MainWP will automatically deactivate older versions of MainWP Extensions in order to prevent compatibility problems.', 'mainwp' ); ?></p>
646 </div>
647 <?php
648 }
649
650 }
651
652 public function getVersion() {
653 return $this->current_version;
654 }
655
656 public function check_update_custom( $transient ) {
657 if ( isset( $_POST[ 'action' ] ) && ( ( $_POST[ 'action' ] == 'update-plugin' ) || ( $_POST[ 'action' ] == 'update-selected' ) ) ) {
658 $extensions = MainWP_Extensions::getExtensions( array( 'activated' => true ) );
659 if ( defined( 'DOING_AJAX' ) && isset( $_POST[ 'plugin' ] ) && $_POST[ 'action' ] == 'update-plugin' ) {
660 $plugin_slug = $_POST[ 'plugin' ];
661 // get download pakage url to prevent expire
662 if ( isset( $extensions[ $plugin_slug ] ) ) {
663 if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ][ 'version' ], '=' ) ) {
664 return $transient;
665 }
666
667 $api_slug = dirname( $plugin_slug );
668 $rslt = MainWP_API_Settings::getUpgradeInformation( $api_slug );
669
670 if ( !empty( $rslt ) && isset( $rslt->latest_version ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ][ 'version' ], '>' ) ) {
671 $transient->response[ $plugin_slug ] = self::mapRsltObj( $rslt );
672 }
673
674 return $transient;
675 }
676 } else if ( $_POST[ 'action' ] == 'update-selected' && isset( $_POST[ 'checked' ] ) && is_array( $_POST[ 'checked' ] ) ) {
677 $updated = false;
678 foreach ( $_POST[ 'checked' ] as $plugin_slug ) {
679 if ( isset( $extensions[ $plugin_slug ] ) ) {
680 if ( isset( $transient->response[ $plugin_slug ] ) && version_compare( $transient->response[ $plugin_slug ]->new_version, $extensions[ $plugin_slug ][ 'version' ], '=' ) ) {
681 continue;
682 }
683 $api_slug = dirname( $plugin_slug );
684 $rslt = MainWP_API_Settings::getUpgradeInformation( $api_slug );
685 if ( !empty( $rslt ) && isset( $rslt->latest_version ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ][ 'version' ], '>' ) ) {
686
687 $this->upgradeVersionInfo->result[ $api_slug ] = $rslt;
688 $transient->response[ $plugin_slug ] = self::mapRsltObj( $rslt );
689 $updated = true;
690 }
691 }
692 }
693 if ( $updated ) {
694 MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', serialize( $this->upgradeVersionInfo ) );
695 }
696
697 return $transient;
698 }
699 }
700
701 if ( empty( $transient->checked ) ) {
702 return $transient;
703 }
704
705 if ( isset( $_GET[ 'do' ] ) && $_GET[ 'do' ] == 'checkUpgrade' && ( ( time() - $this->upgradeVersionInfo->updated ) > 30 ) ) {
706 $this->checkUpgrade();
707 }
708
709 if ( $this->upgradeVersionInfo != null && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) {
710 foreach ( $this->upgradeVersionInfo->result as $rslt ) {
711 if ( !isset( $rslt->slug ) ) {
712 continue;
713 } //Legacy, to support older versions.
714
715 $plugin_slug = MainWP_Extensions::getPluginSlug( $rslt->slug );
716 if ( isset( $transient->checked[ $plugin_slug ] ) && version_compare( $rslt->latest_version, $transient->checked[ $plugin_slug ], '>' ) ) {
717 $transient->response[ $plugin_slug ] = self::mapRsltObj( $rslt );
718 }
719 }
720 }
721
722 return $transient;
723 }
724
725 public static function mapRsltObj( $pRslt ) {
726 $obj = new stdClass();
727 $obj->slug = $pRslt->slug;
728 $obj->new_version = $pRslt->latest_version;
729 $obj->url = 'https://mainwp.com/';
730 $obj->package = $pRslt->download_url;
731
732 return $obj;
733 }
734
735 private function checkUpgrade() {
736 $result = MainWP_API_Settings::checkUpgrade();
737 if ( $this->upgradeVersionInfo === null ) {
738 $this->upgradeVersionInfo = new stdClass();
739 }
740 $this->upgradeVersionInfo->updated = time();
741 if ( !empty( $result ) ) {
742 $this->upgradeVersionInfo->result = $result;
743 }
744 MainWP_Utility::update_option( 'mainwp_upgradeVersionInfo', serialize( $this->upgradeVersionInfo ) );
745 }
746
747 public function pre_check_update_custom( $transient ) {
748 if ( !isset( $transient->checked ) ) {
749 return $transient;
750 }
751
752 if ( ( $this->upgradeVersionInfo == null ) || ( ( time() - $this->upgradeVersionInfo->updated ) > 60 ) ) { // one minute before recheck to prevent check update information to many times
753 $this->checkUpgrade();
754 }
755
756 if ( $this->upgradeVersionInfo != null && property_exists( $this->upgradeVersionInfo, 'result' ) && is_array( $this->upgradeVersionInfo->result ) ) {
757 $extensions = MainWP_Extensions::getExtensions( array( 'activated' => true ) );
758 foreach ( $this->upgradeVersionInfo->result as $rslt ) {
759 $plugin_slug = MainWP_Extensions::getPluginSlug( $rslt->slug );
760 if ( isset( $extensions[ $plugin_slug ] ) && version_compare( $rslt->latest_version, $extensions[ $plugin_slug ][ 'version' ], '>' ) ) {
761 $transient->response[ $plugin_slug ] = self::mapRsltObj( $rslt );
762 }
763 }
764 }
765
766 return $transient;
767 }
768
769 public function check_info( $false, $action, $arg ) {
770 if ( 'plugin_information' !== $action ) {
771 return $false;
772 }
773
774 if ( !isset( $arg->slug ) || ( $arg->slug == '' ) ) {
775 return $false;
776 }
777
778 if ( $arg->slug === $this->slug ) {
779 return $false;
780 }
781
782 $result = MainWP_Extensions::getSlugs();
783 $am_slugs = $result[ 'am_slugs' ];
784
785 if ( $am_slugs != '' ) {
786 $am_slugs = explode( ',', $am_slugs );
787 if ( in_array( $arg->slug, $am_slugs ) ) {
788 $info = MainWP_API_Settings::getPluginInformation( $arg->slug );
789 if ( is_object( $info ) && property_exists( $info, 'sections' ) ) {
790 if ( !is_array( $info->sections ) || !isset( $info->sections[ 'changelog' ] ) || empty( $info->sections[ 'changelog' ] ) ) {
791 $exts_data = MainWP_Extensions_View::getAvailableExtensions();
792 if ( isset( $exts_data[ $arg->slug ] ) ) {
793 $ext_info = $exts_data[ $arg->slug ];
794 $changelog_link = rtrim( $ext_info[ 'link' ], '/' );
795 $info->sections[ 'changelog' ] = '<a href="' . $changelog_link . '#tab-changelog" target="_blank">' . $changelog_link . '#tab-changelog</a>';
796 }
797 }
798 return $info;
799 }
800 return $info;
801 }
802 }
803
804 return $false;
805 }
806
807 function print_digest_lines( $array, $backupChecks = null, $what = 'update' ) {
808
809 $plain_text = apply_filters( 'mainwp_text_format_email', false );
810
811 $output = '';
812
813 if ($what == 'disc_sites') {
814 if ( $plain_text ) {
815 foreach ( $array as $url ) {
816 $output .= $url . "\r\n";
817 }
818 } else {
819 foreach ( $array as $url ) {
820 $output .= '<li>' . $url . '</li>' . "\n";
821 }
822 }
823
824 } else {
825
826 if ( $plain_text ) {
827 foreach ( $array as $line ) {
828 $siteId = $line[0];
829 $text = $line[1];
830 $trustedText = $line[2];
831
832 $output .= $text . $trustedText . ( $backupChecks == null || ! isset( $backupChecks[ $siteId ] ) || ( $backupChecks[ $siteId ] == true ) ? '' : '(Requires manual backup)' ) . "\r\n";
833 }
834 } else {
835 foreach ( $array as $line ) {
836 $siteId = $line[ 0 ];
837 $text = $line[ 1 ];
838 $trustedText = $line[ 2 ];
839
840 $output .= '<li>' . $text . $trustedText . ( $backupChecks == null || !isset( $backupChecks[ $siteId ] ) || ( $backupChecks[ $siteId ] == true ) ? '' : '(Requires manual backup)' ) . '</li>' . "\n";
841 }
842 }
843
844 }
845
846 return $output;
847 }
848
849 static function get_timestamp_from_hh_mm( $hh_mm ) {
850 $hh_mm = explode( ':', $hh_mm );
851 $_hour = isset( $hh_mm[ 0 ] ) ? intval( $hh_mm[ 0 ] ) : 0;
852 $_mins = isset( $hh_mm[ 1 ] ) ? intval( $hh_mm[ 1 ] ) : 0;
853 if ( $_hour < 0 || $_hour > 23 ) {
854 $_hour = 0;
855 }
856 if ( $_mins < 0 || $_mins > 59 ) {
857 $_mins = 0;
858 }
859 return strtotime( date( 'Y-m-d' ) . ' ' . $_hour . ':' . $_mins . ':59' );
860 }
861
862 static function get_period_of_time_from_hh_mm( $hh_mm ) {
863 $hh_mm = explode( ':', $hh_mm );
864 $_hour = isset( $hh_mm[ 0 ] ) ? intval( $hh_mm[ 0 ] ) : 0;
865 $_mins = isset( $hh_mm[ 1 ] ) ? intval( $hh_mm[ 1 ] ) : 0;
866
867 if ( $_hour < 0 || $_hour > 23 ) {
868 $_hour = 0;
869 }
870
871 if ( $_mins < 0 || $_mins > 59 ) {
872 $_mins = 0;
873 }
874 return $_hour * 60 + $_mins; // mins
875 }
876
877 function mainwp_cronupdatescheck_action() {
878 MainWP_Logger::Instance()->info( 'CRON :: updates check' );
879
880 @ignore_user_abort( true );
881 @set_time_limit( 0 );
882 $mem = '512M';
883 @ini_set( 'memory_limit', $mem );
884 @ini_set( 'max_execution_time', 0 );
885
886 $timeDailyUpdate = get_option( 'mainwp_timeDailyUpdate' );
887
888 // to check time to run daily
889 $run_timestamp = 0; // 0 hour
890 if ( !empty($timeDailyUpdate) ) {
891 $run_timestamp = self::get_timestamp_from_hh_mm( $timeDailyUpdate );
892 if ( time() < $run_timestamp ) {
893 return;
894 }
895 }
896
897
898 $lasttimeAutomaticUpdate = get_option( 'mainwp_updatescheck_last_timestamp' );
899 $frequencyDailyUpdate = get_option( 'mainwp_frequencyDailyUpdate' );
900 if ( $frequencyDailyUpdate <= 0 )
901 $frequencyDailyUpdate = 1;
902
903 $period_of_time = $run_timestamp ? self::get_period_of_time_from_hh_mm( $timeDailyUpdate ) : 0; // mins
904 // to valid period of time
905 if ($period_of_time > 24 * 60 )
906 $period_of_time = 0;
907
908 $enableFrequencyAutomaticUpdate = false;
909 // to check frequency to run daily
910 // if the $period_of_time value is not valid then frequency run will avoid, automatic update will run one time per day as default
911 if ( $period_of_time > 0 ) {
912 $mins_between = ( 24 * 60 - $period_of_time ) / $frequencyDailyUpdate; // mins
913 if (time() < $lasttimeAutomaticUpdate + $mins_between * 60) {
914 return;
915 } else {
916 $enableFrequencyAutomaticUpdate = true;
917 }
918 }
919
920 MainWP_Utility::update_option( 'mainwp_cron_last_updatescheck', time() );
921
922 $mainwpAutomaticDailyUpdate = get_option( 'mainwp_automaticDailyUpdate' );
923
924 $plugin_automaticDailyUpdate = get_option( 'mainwp_pluginAutomaticDailyUpdate' );
925 $theme_automaticDailyUpdate = get_option( 'mainwp_themeAutomaticDailyUpdate' );
926
927 $mainwpLastAutomaticUpdate = get_option( 'mainwp_updatescheck_last' );
928 $mainwpHoursIntervalAutomaticUpdate = apply_filters( 'mainwp_updatescheck_hours_interval' , false);
929
930 if ( $mainwpHoursIntervalAutomaticUpdate > 0 ) {
931 if ( $lasttimeAutomaticUpdate && ( $lasttimeAutomaticUpdate + $mainwpHoursIntervalAutomaticUpdate * 3600 > time() ) ) {
932 MainWP_Logger::Instance()->debug( 'CRON :: updates check :: already updated hours interval' );
933 return;
934 }
935 } else if ( $enableFrequencyAutomaticUpdate ) {
936 // ok go frequency sync
937 } else if ( $mainwpLastAutomaticUpdate == date( 'd/m/Y' ) ) {
938 MainWP_Logger::Instance()->debug( 'CRON :: updates check :: already updated today' );
939
940 return;
941 }
942
943 if ( 'Y' == get_option( 'mainwp_updatescheck_ready_sendmail' ) ) {
944 $send_noti_at = apply_filters( 'mainwp_updatescheck_sendmail_at_time', false );
945 if ( !empty( $send_noti_at ) ) {
946 $send_timestamp = self::get_timestamp_from_hh_mm( $send_noti_at );
947 if ( time() < $send_timestamp ) {
948 return; // send notification later
949 }
950 }
951 }
952
953 $disable_send_noti = apply_filters( 'mainwp_updatescheck_disable_sendmail', false );
954
955 $websites = array();
956 $checkupdate_websites = MainWP_DB::Instance()->getWebsitesCheckUpdates( 4 );
957
958 foreach ( $checkupdate_websites as $website ) {
959 if ( !MainWP_DB::Instance()->backupFullTaskRunning( $website->id ) ) {
960 $websites[] = $website;
961 }
962 }
963
964 MainWP_Logger::Instance()->debug( 'CRON :: updates check :: found ' . count( $checkupdate_websites ) . ' websites' );
965 MainWP_Logger::Instance()->debug( 'CRON :: backup task running :: found ' . (count( $checkupdate_websites ) - count( $websites )) . ' websites' );
966 MainWP_Logger::Instance()->info_update( 'CRON :: updates check :: found ' . count( $checkupdate_websites ) . ' websites' );
967
968 $userid = null;
969 foreach ( $websites as $website ) {
970 $websiteValues = array(
971 'dtsAutomaticSyncStart' => time(),
972 );
973 if ( $userid == null ) {
974 $userid = $website->userid;
975 }
976
977 MainWP_DB::Instance()->updateWebsiteSyncValues( $website->id, $websiteValues );
978 }
979
980
981 $text_format = get_option( 'mainwp_daily_digest_plain_text', false );
982
983 if ( $text_format ) {
984 $content_type = "Content-Type: text/plain; charset=\"utf-8\"\r\n";
985 } else {
986 $content_type = "Content-Type: text/html; charset=\"utf-8\"\r\n";
987 }
988
989 if ( count( $checkupdate_websites ) == 0 ) {
990 $busyCounter = MainWP_DB::Instance()->getWebsitesCountWhereDtsAutomaticSyncSmallerThenStart();
991 MainWP_Logger::Instance()->info_update( 'CRON :: busy counter :: found ' . $busyCounter . ' websites' );
992 if ( $busyCounter == 0 ) {
993 if ( 'Y' != get_option( 'mainwp_updatescheck_ready_sendmail' ) ) {
994 MainWP_Utility::update_option( 'mainwp_updatescheck_ready_sendmail', 'Y' );
995 return; // to check time before send notification
996 }
997
998 update_option( 'mainwp_last_synced_all_sites', time() );
999 MainWP_Logger::Instance()->debug( 'CRON :: updates check :: got to the mail part' );
1000
1001 //Send the email & update all to this time!
1002 $mail = '';
1003 $sendMail = false;
1004
1005 $sitesCheckCompleted = null;
1006 if ( get_option( 'mainwp_backup_before_upgrade' ) == 1 ) {
1007 $sitesCheckCompleted = get_option( 'mainwp_automaticUpdate_backupChecks' );
1008 if ( !is_array( $sitesCheckCompleted ) ) {
1009 $sitesCheckCompleted = null;
1010 }
1011 }
1012
1013
1014 $pluginsNewUpdate = get_option( 'mainwp_updatescheck_mail_update_plugins_new' );
1015 if ( !is_array( $pluginsNewUpdate ) ) {
1016 $pluginsNewUpdate = array();
1017 }
1018 $pluginsToUpdate = get_option( 'mainwp_updatescheck_mail_update_plugins' );
1019 if ( !is_array( $pluginsToUpdate ) ) {
1020 $pluginsToUpdate = array();
1021 }
1022 $notTrustedPluginsNewUpdate = get_option( 'mainwp_updatescheck_mail_ignore_plugins_new' );
1023 if ( !is_array( $notTrustedPluginsNewUpdate ) ) {
1024 $notTrustedPluginsNewUpdate = array();
1025 }
1026 $notTrustedPluginsToUpdate = get_option( 'mainwp_updatescheck_mail_ignore_plugins' );
1027 if ( !is_array( $notTrustedPluginsToUpdate ) ) {
1028 $notTrustedPluginsToUpdate = array();
1029 }
1030
1031 if ( !empty( $plugin_automaticDailyUpdate ) ) {
1032 if ( ( count( $pluginsNewUpdate ) != 0 ) || ( count( $pluginsToUpdate ) != 0 ) || ( count( $notTrustedPluginsNewUpdate ) != 0 ) || ( count( $notTrustedPluginsToUpdate ) != 0 )
1033 ) {
1034 $sendMail = true;
1035
1036 $mail_lines = '';
1037 $mail_lines .= $this->print_digest_lines( $pluginsNewUpdate );
1038 $mail_lines .= $this->print_digest_lines( $pluginsToUpdate, $sitesCheckCompleted );
1039 $mail_lines .= $this->print_digest_lines( $notTrustedPluginsNewUpdate );
1040 $mail_lines .= $this->print_digest_lines( $notTrustedPluginsToUpdate );
1041
1042 if ($text_format) {
1043 $mail .= 'WordPress Plugin Updates' . "\r\n";
1044 $mail .= "\r\n";
1045 $mail .= $mail_lines;
1046 $mail .= "\r\n";
1047 } else {
1048 $mail .= '<div><strong>WordPress Plugin Updates</strong></div>';
1049 $mail .= '<ul>';
1050 $mail .= $mail_lines;
1051 $mail .= '</ul>';
1052 }
1053 }
1054 }
1055
1056
1057 $themesNewUpdate = get_option( 'mainwp_updatescheck_mail_update_themes_new' );
1058 if ( !is_array( $themesNewUpdate ) ) {
1059 $themesNewUpdate = array();
1060 }
1061 $themesToUpdate = get_option( 'mainwp_updatescheck_mail_update_themes' );
1062 if ( !is_array( $themesToUpdate ) ) {
1063 $themesToUpdate = array();
1064 }
1065 $notTrustedThemesNewUpdate = get_option( 'mainwp_updatescheck_mail_ignore_themes_new' );
1066 if ( !is_array( $notTrustedThemesNewUpdate ) ) {
1067 $notTrustedThemesNewUpdate = array();
1068 }
1069 $notTrustedThemesToUpdate = get_option( 'mainwp_updatescheck_mail_ignore_themes' );
1070 if ( !is_array( $notTrustedThemesToUpdate ) ) {
1071 $notTrustedThemesToUpdate = array();
1072 }
1073
1074 if ( !empty( $theme_automaticDailyUpdate ) ) {
1075 if ( ( count( $themesNewUpdate ) != 0 ) || ( count( $themesToUpdate ) != 0 ) || ( count( $notTrustedThemesNewUpdate ) != 0 ) || ( count( $notTrustedThemesToUpdate ) != 0 )
1076 ) {
1077 $sendMail = true;
1078
1079 $mail_lines = '';
1080 $mail_lines .= $this->print_digest_lines( $themesNewUpdate );
1081 $mail_lines .= $this->print_digest_lines( $themesToUpdate, $sitesCheckCompleted );
1082 $mail_lines .= $this->print_digest_lines( $notTrustedThemesNewUpdate );
1083 $mail_lines .= $this->print_digest_lines( $notTrustedThemesToUpdate );
1084
1085 if ( $text_format ) {
1086 $mail .= 'WordPress Themes Updates' . "\r\n";
1087 $mail .= "\r\n";
1088 $mail .= $mail_lines;
1089 $mail .= "\r\n";
1090 } else {
1091 $mail .= '<div><strong>WordPress Themes Updates</strong></div>';
1092 $mail .= '<ul>';
1093 $mail .= $mail_lines;
1094 $mail .= '</ul>';
1095 }
1096
1097 }
1098 }
1099
1100 $coreNewUpdate = get_option( 'mainwp_updatescheck_mail_update_core_new' );
1101 if ( !is_array( $coreNewUpdate ) ) {
1102 $coreNewUpdate = array();
1103 }
1104 $coreToUpdate = get_option( 'mainwp_updatescheck_mail_update_core' );
1105 if ( !is_array( $coreToUpdate ) ) {
1106 $coreToUpdate = array();
1107 }
1108 $ignoredCoreNewUpdate = get_option( 'mainwp_updatescheck_mail_ignore_core_new' );
1109 if ( !is_array( $ignoredCoreNewUpdate ) ) {
1110 $ignoredCoreNewUpdate = array();
1111 }
1112 $ignoredCoreToUpdate = get_option( 'mainwp_updatescheck_mail_ignore_core' );
1113 if ( !is_array( $ignoredCoreToUpdate ) ) {
1114 $ignoredCoreToUpdate = array();
1115 }
1116
1117 if ( !empty( $mainwpAutomaticDailyUpdate ) ) {
1118 if ( ( count( $coreNewUpdate ) != 0 ) || ( count( $coreToUpdate ) != 0 ) || ( count( $ignoredCoreNewUpdate ) != 0 ) || ( count( $ignoredCoreToUpdate ) != 0 ) ) {
1119 $sendMail = true;
1120
1121 $mail_lines = '';
1122 $mail_lines .= $this->print_digest_lines( $coreNewUpdate );
1123 $mail_lines .= $this->print_digest_lines( $coreToUpdate, $sitesCheckCompleted );
1124 $mail_lines .= $this->print_digest_lines( $ignoredCoreNewUpdate );
1125 $mail_lines .= $this->print_digest_lines( $ignoredCoreToUpdate );
1126
1127 if ($text_format) {
1128 $mail .= 'WordPress Core Updates' . "\r\n";
1129 $mail .= "\r\n";
1130 $mail .= $mail_lines;
1131 $mail .= "\r\n";
1132 } else {
1133 $mail .= '<div><strong>WordPress Core Updates</strong></div>';
1134 $mail .= '<ul>';
1135 $mail .= $mail_lines;
1136 $mail .= '</ul>';
1137 }
1138
1139 }
1140 }
1141
1142 $sitesDisconnect = MainWP_DB::Instance()->getDisconnectedWebsites();
1143 if ( count( $sitesDisconnect ) != 0 ) {
1144 $sendMail = true;
1145 $mail_lines = $this->print_digest_lines( $sitesDisconnect, null, 'disc_sites' );
1146 if ($text_format) {
1147 $mail .= 'Connection Status' . "\r\n";
1148 $mail .= "\r\n";
1149 $mail .= $mail_lines;
1150 $mail .= "\r\n";
1151 } else {
1152 $mail .= '<b style="color: rgb(127, 177, 0); font-family: Helvetica, Sans; font-size: medium; line-height: normal;"> Connection Status </b><br>';
1153 $mail .= '<ul>';
1154 $mail .= $mail_lines;
1155 $mail .= '</ul>';
1156 }
1157 }
1158
1159
1160 $mail = apply_filters( 'mainwp_daily_digest_content', $mail, $text_format );
1161
1162 MainWP_Utility::update_option( 'mainwp_automaticUpdate_backupChecks', '' );
1163
1164 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_core_new', '' );
1165 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_plugins_new', '' );
1166 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_themes_new', '' );
1167
1168 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_core', '' );
1169 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_plugins', '' );
1170 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_themes', '' );
1171
1172 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_core', '' );
1173 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_plugins', '' );
1174 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_themes', '' );
1175
1176 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_core_new', '' );
1177 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_plugins_new', '' );
1178 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_themes_new', '' );
1179
1180 MainWP_Utility::update_option( 'mainwp_updatescheck_last', date( 'd/m/Y' ) );
1181 MainWP_Utility::update_option( 'mainwp_updatescheck_last_timestamp', time() );
1182 MainWP_Utility::update_option( 'mainwp_updatescheck_ready_sendmail', '' );
1183
1184 $plain_text = apply_filters( 'mainwp_text_format_email', false );
1185 MainWP_Utility::update_option( 'mainwp_daily_digest_plain_text', $plain_text );
1186
1187 MainWP_Utility::update_option( 'mainwp_updatescheck_sites_icon', '' );
1188
1189 if ( 1 == get_option( 'mainwp_check_http_response', 0 ) ) {
1190
1191 $sitesHttpCheckIds = get_option( 'mainwp_automaticUpdate_httpChecks' );
1192 if ( !is_array( $sitesHttpCheckIds ) ) {
1193 $sitesHttpCheckIds = array();
1194 }
1195
1196 $mail_offline = '';
1197 $sitesOffline = array();
1198 if ( count( $sitesHttpCheckIds ) > 0 ) {
1199 $sitesOffline = MainWP_DB::Instance()->getWebsitesByIds( $sitesHttpCheckIds );
1200 }
1201 if ( is_array( $sitesOffline ) && count( $sitesOffline ) > 0 ) {
1202 foreach ( $sitesOffline as $site ) {
1203 if ( $site->offline_check_result == -1 ) {
1204 $mail_offline .= '<li>' . $site->name . ' - [' . $site->url . '] - [' . $site->http_response_code . ']</li>';
1205 }
1206 }
1207 }
1208
1209 $email = get_option( 'mainwp_updatescheck_mail_email' );
1210 if ( !$disable_send_noti && !empty( $email ) && $mail_offline != '' ) {
1211 MainWP_Logger::Instance()->debug( 'CRON :: http check :: send mail to ' . $email );
1212 $mail_offline = '<div>After running auto updates, following sites are not returning expected HTTP request response:</div>
1213 <div></div>
1214 <ul>
1215 ' . $mail_offline . '
1216 </ul>
1217 <div></div>
1218 <div>Please visit your MainWP Dashboard as soon as possible and make sure that your sites are online. (<a href="' . site_url() . '">' . site_url() . '</a>)</div>';
1219 wp_mail( $email, $mail_title = 'MainWP - HTTP response check', MainWP_Utility::formatEmail( $email, $mail_offline, $mail_title ), array(
1220 'From: "' . get_option( 'admin_email' ) . '" <' . get_option( 'admin_email' ) . '>',
1221 $content_type,
1222 ) );
1223 }
1224 MainWP_Utility::update_option( 'mainwp_automaticUpdate_httpChecks', '' );
1225 }
1226
1227 $disabled_notification = apply_filters( 'mainwp_updatescheck_disable_notification_mail', false );
1228 if ( $disabled_notification )
1229 return;
1230
1231 if ( !$sendMail ) {
1232 MainWP_Logger::Instance()->debug( 'CRON :: updates check :: sendMail is false' );
1233
1234 return;
1235 }
1236
1237 if ( !$disable_send_noti ) {
1238 //Create a nice email to send
1239 $email = get_option( 'mainwp_updatescheck_mail_email' );
1240 MainWP_Logger::Instance()->debug( 'CRON :: updates check :: send mail to ' . $email );
1241 if ( $email != false && $email != '' ) {
1242 if ($text_format) {
1243 $mail = 'We noticed the following updates are available on your MainWP Dashboard. (' . site_url() . ')' . "\r\n"
1244 . $mail . "\r\n" .
1245 'If your MainWP is configured to use Auto Updates these updates will be installed in the next 24 hours.' . "\r\n";
1246 } else {
1247 $mail = '<div>We noticed the following updates are available on your MainWP Dashboard. (<a href="' . site_url() . '">' . site_url() . '</a>)</div>
1248 <div></div>
1249 ' . $mail . '
1250 <div> </div>
1251 <div>If your MainWP is configured to use Auto Updates these updates will be installed in the next 24 hours.</div>';
1252 }
1253 wp_mail( $email, $mail_title = 'Available Updates', MainWP_Utility::formatEmail( $email, $mail, $mail_title, $text_format ), array(
1254 'From: "' . get_option( 'admin_email' ) . '" <' . get_option( 'admin_email' ) . '>',
1255 $content_type,
1256 ) );
1257 }
1258 }
1259 }
1260 } else {
1261 $userExtension = MainWP_DB::Instance()->getUserExtensionByUserId( $userid );
1262
1263 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
1264 if ( !is_array( $decodedIgnoredPlugins ) ) {
1265 $decodedIgnoredPlugins = array();
1266 }
1267
1268 $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
1269 if ( !is_array( $trustedPlugins ) ) {
1270 $trustedPlugins = array();
1271 }
1272
1273 $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true );
1274 if ( !is_array( $decodedIgnoredThemes ) ) {
1275 $decodedIgnoredThemes = array();
1276 }
1277
1278 $trustedThemes = json_decode( $userExtension->trusted_themes, true );
1279 if ( !is_array( $trustedThemes ) ) {
1280 $trustedThemes = array();
1281 }
1282
1283 $coreToUpdateNow = array();
1284 $coreToUpdate = array();
1285 $coreNewUpdate = array();
1286 $ignoredCoreToUpdate = array();
1287 $ignoredCoreNewUpdate = array();
1288
1289 $pluginsToUpdateNow = array();
1290 $pluginsToUpdate = array();
1291 $pluginsNewUpdate = array();
1292 $notTrustedPluginsToUpdate = array();
1293 $notTrustedPluginsNewUpdate = array();
1294
1295 $themesToUpdateNow = array();
1296 $themesToUpdate = array();
1297 $themesNewUpdate = array();
1298 $notTrustedThemesToUpdate = array();
1299 $notTrustedThemesNewUpdate = array();
1300
1301 $allWebsites = array();
1302
1303 $infoTrustedText = ' (<span style="color:#008000"><strong>Trusted</strong></span>)';
1304 $infoNotTrustedText = '';
1305
1306 foreach ( $websites as $website ) {
1307 $websiteDecodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
1308 if ( !is_array( $websiteDecodedIgnoredPlugins ) ) {
1309 $websiteDecodedIgnoredPlugins = array();
1310 }
1311
1312 $websiteDecodedIgnoredThemes = json_decode( $website->ignored_themes, true );
1313 if ( !is_array( $websiteDecodedIgnoredThemes ) ) {
1314 $websiteDecodedIgnoredThemes = array();
1315 }
1316
1317 //Perform check & update
1318 if ( !MainWP_Sync::syncSite( $website, false, true ) ) {
1319 $websiteValues = array(
1320 'dtsAutomaticSync' => time(),
1321 );
1322
1323 MainWP_DB::Instance()->updateWebsiteSyncValues( $website->id, $websiteValues );
1324
1325 continue;
1326 }
1327 $website = MainWP_DB::Instance()->getWebsiteById( $website->id );
1328
1329 /** Check core updates * */
1330 $websiteLastCoreUpgrades = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'last_wp_upgrades' ), true );
1331 $websiteCoreUpgrades = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'wp_upgrades' ), true );
1332
1333 //Run over every update we had last time..
1334 if ( isset( $websiteCoreUpgrades[ 'current' ] ) ) {
1335
1336 if ( $text_format ) {
1337 $infoTxt = stripslashes( $website->name ) . ' - ' . $websiteCoreUpgrades[ 'current' ] . ' to ' . $websiteCoreUpgrades[ 'new' ] . ' - ' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id );
1338 $infoNewTxt = '*NEW* ' . stripslashes( $website->name ) . ' - ' . $websiteCoreUpgrades[ 'current' ] . ' to ' . $websiteCoreUpgrades[ 'new' ] . ' - ' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id );
1339 } else {
1340 $infoTxt = '<a href="' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) . '">' . stripslashes( $website->name ) . '</a> - ' . $websiteCoreUpgrades[ 'current' ] . ' to ' . $websiteCoreUpgrades[ 'new' ];
1341 $infoNewTxt = '*NEW* <a href="' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) . '">' . stripslashes( $website->name ) . '</a> - ' . $websiteCoreUpgrades[ 'current' ] . ' to ' . $websiteCoreUpgrades[ 'new' ];
1342 }
1343
1344 $newUpdate = !( isset( $websiteLastCoreUpgrades[ 'current' ] ) && ( $websiteLastCoreUpgrades[ 'current' ] == $websiteCoreUpgrades[ 'current' ] ) && ( $websiteLastCoreUpgrades[ 'new' ] == $websiteCoreUpgrades[ 'new' ] ) );
1345 // to fix
1346 if ( !$website->is_ignoreCoreUpdates ) {
1347 if ( $website->automatic_update == 1 ) {
1348 if ( $newUpdate ) {
1349 $coreNewUpdate[] = array( $website->id, $infoNewTxt, $infoTrustedText );
1350 } else {
1351 //Check ignore ? $ignoredCoreToUpdate
1352 $coreToUpdateNow[] = $website->id;
1353 $allWebsites[ $website->id ] = $website;
1354 $coreToUpdate[] = array( $website->id, $infoTxt, $infoTrustedText );
1355 }
1356 } else {
1357 if ( $newUpdate ) {
1358 $ignoredCoreNewUpdate[] = array( $website->id, $infoNewTxt, $infoNotTrustedText );
1359 } else {
1360 $ignoredCoreToUpdate[] = array( $website->id, $infoTxt, $infoNotTrustedText );
1361 }
1362 }
1363 }
1364 }
1365
1366 /** Check plugins * */
1367 $websiteLastPlugins = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'last_plugin_upgrades' ), true );
1368 $websitePlugins = json_decode( $website->plugin_upgrades, true );
1369
1370 /** Check themes * */
1371 $websiteLastThemes = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'last_theme_upgrades' ), true );
1372 $websiteThemes = json_decode( $website->theme_upgrades, true );
1373
1374 $decodedPremiumUpgrades = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'premium_upgrades' ), true );
1375 if ( is_array( $decodedPremiumUpgrades ) ) {
1376 foreach ( $decodedPremiumUpgrades as $slug => $premiumUpgrade ) {
1377 if ( $premiumUpgrade[ 'type' ] == 'plugin' ) {
1378 if ( !is_array( $websitePlugins ) ) {
1379 $websitePlugins = array();
1380 }
1381 $websitePlugins[ $slug ] = $premiumUpgrade;
1382 } else if ( $premiumUpgrade[ 'type' ] == 'theme' ) {
1383 if ( !is_array( $websiteThemes ) ) {
1384 $websiteThemes = array();
1385 }
1386 $websiteThemes[ $slug ] = $premiumUpgrade;
1387 }
1388 }
1389 }
1390
1391 //Run over every update we had last time..
1392 foreach ( $websitePlugins as $pluginSlug => $pluginInfo ) {
1393 if ( isset( $decodedIgnoredPlugins[ $pluginSlug ] ) || isset( $websiteDecodedIgnoredPlugins[ $pluginSlug ] ) ) {
1394 continue;
1395 }
1396 if ( $website->is_ignorePluginUpdates ) {
1397 continue;
1398 }
1399 if ( $text_format ) {
1400 $infoTxt = stripslashes( $website->name ) . ' - ' . $pluginInfo[ 'Name' ] . ' ' . $pluginInfo[ 'Version' ] . ' to ' . $pluginInfo[ 'update' ][ 'new_version' ] . ' - ' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) ;
1401 $infoNewTxt = '*NEW* ' . stripslashes( $website->name ) . ' - ' . $pluginInfo[ 'Name' ] . ' ' . $pluginInfo[ 'Version' ] . ' to ' . $pluginInfo[ 'update' ][ 'new_version' ] . ' - ' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id );
1402 } else {
1403 $infoTxt = '<a href="' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) . '">' . stripslashes( $website->name ) . '</a> - ' . $pluginInfo[ 'Name' ] . ' ' . $pluginInfo[ 'Version' ] . ' to ' . $pluginInfo[ 'update' ][ 'new_version' ];
1404 $infoNewTxt = '*NEW* <a href="' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) . '">' . stripslashes( $website->name ) . '</a> - ' . $pluginInfo[ 'Name' ] . ' ' . $pluginInfo[ 'Version' ] . ' to ' . $pluginInfo[ 'update' ][ 'new_version' ];
1405 }
1406 if ( $pluginInfo[ 'update' ][ 'url' ] && ( false !== strpos( $pluginInfo[ 'update' ][ 'url' ], 'wordpress.org/plugins' ) ) ) {
1407 $change_log = $pluginInfo[ 'update' ][ 'url' ];
1408 if ( substr( $change_log, - 1 ) != '/' ) {
1409 $change_log .= '/';
1410 }
1411 $change_log .= '#developers';
1412 if ( ! $text_format ) {
1413 $infoTxt .= ' - ' . '<a href="' . $change_log . '" target="_blank">Changelog</a>';
1414 $infoNewTxt .= ' - ' . '<a href="' . $change_log . '" target="_blank">Changelog</a>';
1415 }
1416 }
1417 $newUpdate = !( isset( $websiteLastPlugins[ $pluginSlug ] ) && ( $pluginInfo[ 'Version' ] == $websiteLastPlugins[ $pluginSlug ][ 'Version' ] ) && ( $pluginInfo[ 'update' ][ 'new_version' ] == $websiteLastPlugins[ $pluginSlug ][ 'update' ][ 'new_version' ] ) );
1418 //update this..
1419 if ( in_array( $pluginSlug, $trustedPlugins ) ) {
1420 //Trusted
1421 if ( $newUpdate ) {
1422 $pluginsNewUpdate[] = array( $website->id, $infoNewTxt, $infoTrustedText );
1423 } else {
1424 $pluginsToUpdateNow[ $website->id ][] = $pluginSlug;
1425 $allWebsites[ $website->id ] = $website;
1426 $pluginsToUpdate[] = array( $website->id, $infoTxt, $infoTrustedText );
1427 }
1428 } else {
1429 //Not trusted
1430 if ( $newUpdate ) {
1431 $notTrustedPluginsNewUpdate[] = array( $website->id, $infoNewTxt, $infoNotTrustedText );
1432 } else {
1433 $notTrustedPluginsToUpdate[] = array( $website->id, $infoTxt, $infoNotTrustedText );
1434 }
1435 }
1436 }
1437
1438 //Run over every update we had last time..
1439 foreach ( $websiteThemes as $themeSlug => $themeInfo ) {
1440 if ( isset( $decodedIgnoredThemes[ $themeSlug ] ) || isset( $websiteDecodedIgnoredThemes[ $themeSlug ] ) ) {
1441 continue;
1442 }
1443
1444 if ( $website->is_ignoreThemeUpdates ) {
1445 continue;
1446 }
1447 if ( $text_format ) {
1448 $infoTxt = stripslashes( $website->name ) . ' - ' . $themeInfo[ 'Name' ] . ' ' . $themeInfo[ 'Version' ] . ' to ' . $themeInfo[ 'update' ][ 'new_version' ] . ' - ' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id );
1449 $infoNewTxt = '*NEW* ' . stripslashes( $website->name ) . ' - ' . $themeInfo[ 'Name' ] . ' ' . $themeInfo[ 'Version' ] . ' to ' . $themeInfo[ 'update' ][ 'new_version' ] . ' - ' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id );
1450 } else {
1451 $infoTxt = '<a href="' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) . '">' . stripslashes( $website->name ) . '</a> - ' . $themeInfo[ 'Name' ] . ' ' . $themeInfo[ 'Version' ] . ' to ' . $themeInfo[ 'update' ][ 'new_version' ];
1452 $infoNewTxt = '*NEW* <a href="' . admin_url( 'admin.php?page=managesites&dashboard=' . $website->id ) . '">' . stripslashes( $website->name ) . '</a> - ' . $themeInfo[ 'Name' ] . ' ' . $themeInfo[ 'Version' ] . ' to ' . $themeInfo[ 'update' ][ 'new_version' ];
1453 }
1454
1455 $newUpdate = !( isset( $websiteLastThemes[ $themeSlug ] ) && ( $themeInfo[ 'Version' ] == $websiteLastThemes[ $themeSlug ][ 'Version' ] ) && ( $themeInfo[ 'update' ][ 'new_version' ] == $websiteLastThemes[ $themeSlug ][ 'update' ][ 'new_version' ] ) );
1456 //update this..
1457 if ( in_array( $themeSlug, $trustedThemes ) ) {
1458 //Trusted
1459 if ( $newUpdate ) {
1460 $themesNewUpdate[] = array( $website->id, $infoNewTxt, $infoTrustedText );
1461 } else {
1462 $themesToUpdateNow[ $website->id ][] = $themeSlug;
1463 $allWebsites[ $website->id ] = $website;
1464 $themesToUpdate[] = array( $website->id, $infoTxt, $infoTrustedText );
1465 }
1466 } else {
1467 //Not trusted
1468 if ( $newUpdate ) {
1469 $notTrustedThemesNewUpdate[] = array( $website->id, $infoNewTxt, $infoNotTrustedText );
1470 } else {
1471 $notTrustedThemesToUpdate[] = array( $website->id, $infoTxt, $infoNotTrustedText );
1472 }
1473 }
1474 }
1475
1476 do_action( 'mainwp_daily_digest_action', $website, $text_format );
1477
1478 //Loop over last plugins & current plugins, check if we need to update them.
1479 $user = get_userdata( $website->userid );
1480 $email = MainWP_Utility::getNotificationEmail( $user );
1481 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_email', $email );
1482 MainWP_DB::Instance()->updateWebsiteSyncValues( $website->id, array( 'dtsAutomaticSync' => time() ) );
1483 MainWP_DB::Instance()->updateWebsiteOption( $website, 'last_wp_upgrades', json_encode( $websiteCoreUpgrades ) );
1484 MainWP_DB::Instance()->updateWebsiteOption( $website, 'last_plugin_upgrades', $website->plugin_upgrades );
1485 MainWP_DB::Instance()->updateWebsiteOption( $website, 'last_theme_upgrades', $website->theme_upgrades );
1486
1487 // sync site favico one time per day
1488 $updatescheckSitesIcon = get_option( 'mainwp_updatescheck_sites_icon' );
1489 if ( !is_array( $updatescheckSitesIcon ) ) {
1490 $updatescheckSitesIcon = array();
1491 }
1492 if ( !in_array( $website->id, $updatescheckSitesIcon ) ) {
1493 MainWP_System::sync_site_icon( $website->id );
1494 $updatescheckSitesIcon[] = $website->id;
1495 MainWP_Utility::update_option( 'mainwp_updatescheck_sites_icon', $updatescheckSitesIcon );
1496 }
1497 }
1498
1499 if ( count( $coreNewUpdate ) != 0 ) {
1500 $coreNewUpdateSaved = get_option( 'mainwp_updatescheck_mail_update_core_new' );
1501 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_core_new', MainWP_Utility::array_merge( $coreNewUpdateSaved, $coreNewUpdate ) );
1502 }
1503
1504 if ( count( $pluginsNewUpdate ) != 0 ) {
1505 $pluginsNewUpdateSaved = get_option( 'mainwp_updatescheck_mail_update_plugins_new' );
1506 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_plugins_new', MainWP_Utility::array_merge( $pluginsNewUpdateSaved, $pluginsNewUpdate ) );
1507 }
1508
1509 if ( count( $themesNewUpdate ) != 0 ) {
1510 $themesNewUpdateSaved = get_option( 'mainwp_updatescheck_mail_update_themes_new' );
1511 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_themes_new', MainWP_Utility::array_merge( $themesNewUpdateSaved, $themesNewUpdate ) );
1512 }
1513
1514 if ( count( $coreToUpdate ) != 0 ) {
1515 $coreToUpdateSaved = get_option( 'mainwp_updatescheck_mail_update_core' );
1516 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_core', MainWP_Utility::array_merge( $coreToUpdateSaved, $coreToUpdate ) );
1517 }
1518
1519 if ( count( $pluginsToUpdate ) != 0 ) {
1520 $pluginsToUpdateSaved = get_option( 'mainwp_updatescheck_mail_update_plugins' );
1521 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_plugins', MainWP_Utility::array_merge( $pluginsToUpdateSaved, $pluginsToUpdate ) );
1522 }
1523
1524 if ( count( $themesToUpdate ) != 0 ) {
1525 $themesToUpdateSaved = get_option( 'mainwp_updatescheck_mail_update_themes' );
1526 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_update_themes', MainWP_Utility::array_merge( $themesToUpdateSaved, $themesToUpdate ) );
1527 }
1528
1529 if ( count( $ignoredCoreToUpdate ) != 0 ) {
1530 $ignoredCoreToUpdateSaved = get_option( 'mainwp_updatescheck_mail_ignore_core' );
1531 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_core', MainWP_Utility::array_merge( $ignoredCoreToUpdateSaved, $ignoredCoreToUpdate ) );
1532 }
1533
1534 if ( count( $ignoredCoreNewUpdate ) != 0 ) {
1535 $ignoredCoreNewUpdateSaved = get_option( 'mainwp_updatescheck_mail_ignore_core_new' );
1536 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_core_new', MainWP_Utility::array_merge( $ignoredCoreNewUpdateSaved, $ignoredCoreNewUpdate ) );
1537 }
1538
1539 if ( count( $notTrustedPluginsToUpdate ) != 0 ) {
1540 $notTrustedPluginsToUpdateSaved = get_option( 'mainwp_updatescheck_mail_ignore_plugins' );
1541 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_plugins', MainWP_Utility::array_merge( $notTrustedPluginsToUpdateSaved, $notTrustedPluginsToUpdate ) );
1542 }
1543
1544 if ( count( $notTrustedPluginsNewUpdate ) != 0 ) {
1545 $notTrustedPluginsNewUpdateSaved = get_option( 'mainwp_updatescheck_mail_ignore_plugins_new' );
1546 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_plugins_new', MainWP_Utility::array_merge( $notTrustedPluginsNewUpdateSaved, $notTrustedPluginsNewUpdate ) );
1547 }
1548
1549 if ( count( $notTrustedThemesToUpdate ) != 0 ) {
1550 $notTrustedThemesToUpdateSaved = get_option( 'mainwp_updatescheck_mail_ignore_themes' );
1551 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_themes', MainWP_Utility::array_merge( $notTrustedThemesToUpdateSaved, $notTrustedThemesToUpdate ) );
1552 }
1553
1554 if ( count( $notTrustedThemesNewUpdate ) != 0 ) {
1555 $notTrustedThemesNewUpdateSaved = get_option( 'mainwp_updatescheck_mail_ignore_themes_new' );
1556 MainWP_Utility::update_option( 'mainwp_updatescheck_mail_ignore_themes_new', MainWP_Utility::array_merge( $notTrustedThemesNewUpdateSaved, $notTrustedThemesNewUpdate ) );
1557 }
1558
1559
1560 if ( ( count( $coreToUpdate ) == 0 ) && ( count( $pluginsToUpdate ) == 0 ) && ( count( $themesToUpdate ) == 0 ) && ( count( $ignoredCoreToUpdate ) == 0 ) && ( count( $ignoredCoreNewUpdate ) == 0 ) && ( count( $notTrustedPluginsToUpdate ) == 0 ) && ( count( $notTrustedPluginsNewUpdate ) == 0 ) && ( count( $notTrustedThemesToUpdate ) == 0 ) && ( count( $notTrustedThemesNewUpdate ) == 0 )
1561 ) {
1562 return;
1563 }
1564
1565 if ( $mainwpAutomaticDailyUpdate != 1 && $plugin_automaticDailyUpdate != 1 && $theme_automaticDailyUpdate != 1 ) {
1566 return;
1567 }
1568
1569 //Check if backups are required!
1570 if ( get_option( 'mainwp_enableLegacyBackupFeature' ) && get_option( 'mainwp_backup_before_upgrade' ) == 1 ) {
1571 $sitesCheckCompleted = get_option( 'mainwp_automaticUpdate_backupChecks' );
1572 if ( !is_array( $sitesCheckCompleted ) ) {
1573 $sitesCheckCompleted = array();
1574 }
1575
1576
1577 $websitesToCheck = array();
1578
1579 if ( $plugin_automaticDailyUpdate == 1 ) {
1580 foreach ( $pluginsToUpdateNow as $websiteId => $slugs ) {
1581 $websitesToCheck[ $websiteId ] = true;
1582 }
1583 }
1584
1585 if ( $theme_automaticDailyUpdate == 1 ) {
1586 foreach ( $themesToUpdateNow as $websiteId => $slugs ) {
1587 $websitesToCheck[ $websiteId ] = true;
1588 }
1589 }
1590
1591 if ( $mainwpAutomaticDailyUpdate == 1 ) {
1592 foreach ( $coreToUpdateNow as $websiteId ) {
1593 $websitesToCheck[ $websiteId ] = true;
1594 }
1595 }
1596
1597 foreach ( $websitesToCheck as $siteId => $bool ) {
1598 if ( $allWebsites[ $siteId ]->backup_before_upgrade == 0 ) {
1599 $sitesCheckCompleted[ $siteId ] = true;
1600 }
1601 if ( isset( $sitesCheckCompleted[ $siteId ] ) ) {
1602 continue;
1603 }
1604
1605 $dir = MainWP_Utility::getMainWPSpecificDir( $siteId );
1606 //Check if backup ok
1607 $lastBackup = - 1;
1608 if ( file_exists( $dir ) && ( $dh = opendir( $dir ) ) ) {
1609 while ( ( $file = readdir( $dh ) ) !== false ) {
1610 if ( $file != '.' && $file != '..' ) {
1611 $theFile = $dir . $file;
1612 if ( MainWP_Utility::isArchive( $file ) && !MainWP_Utility::isSQLArchive( $file ) && ( filemtime( $theFile ) > $lastBackup ) ) {
1613 $lastBackup = filemtime( $theFile );
1614 }
1615 }
1616 }
1617 closedir( $dh );
1618 }
1619
1620 $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
1621 if ( empty( $mainwp_backup_before_upgrade_days ) || !ctype_digit( $mainwp_backup_before_upgrade_days ) )
1622 $mainwp_backup_before_upgrade_days = 7;
1623
1624 $backupRequired = ( $lastBackup < ( time() - ( $mainwp_backup_before_upgrade_days * 24 * 60 * 60 ) ) ? true : false );
1625
1626 if ( !$backupRequired ) {
1627 $sitesCheckCompleted[ $siteId ] = true;
1628 MainWP_Utility::update_option( 'mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted );
1629 continue;
1630 }
1631
1632 try {
1633 $result = MainWP_Manage_Sites::backup( $siteId, 'full', '', '', 0, 0, 0, 0 );
1634 MainWP_Manage_Sites::backupDownloadFile( $siteId, 'full', $result[ 'url' ], $result[ 'local' ] );
1635 $sitesCheckCompleted[ $siteId ] = true;
1636 MainWP_Utility::update_option( 'mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted );
1637 } catch ( Exception $e ) {
1638 $sitesCheckCompleted[ $siteId ] = false;
1639 MainWP_Utility::update_option( 'mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted );
1640 }
1641 }
1642 } else {
1643 $sitesCheckCompleted = null;
1644 }
1645
1646 if ( $plugin_automaticDailyUpdate == 1 ) {
1647 //Update plugins
1648 foreach ( $pluginsToUpdateNow as $websiteId => $slugs ) {
1649 if ( ( $sitesCheckCompleted != null ) && ( $sitesCheckCompleted[ $websiteId ] == false ) ) {
1650 continue;
1651 }
1652 MainWP_Logger::Instance()->info_update( 'CRON :: auto update :: websites id :: ' . $websiteId . " :: plugins :: " . implode( ',', $slugs ) );
1653
1654 try {
1655 MainWP_Utility::fetchUrlAuthed( $allWebsites[ $websiteId ], 'upgradeplugintheme', array(
1656 'type' => 'plugin',
1657 'list' => urldecode( implode( ',', $slugs ) ),
1658 ) );
1659
1660 if ( isset( $information[ 'sync' ] ) && !empty( $information[ 'sync' ] ) ) {
1661 MainWP_Sync::syncInformationArray( $allWebsites[ $websiteId ], $information[ 'sync' ] );
1662 }
1663 } catch ( Exception $e ) {
1664
1665 }
1666 }
1667 } else {
1668 $pluginsToUpdateNow = array();
1669 }
1670
1671 if ( $theme_automaticDailyUpdate == 1 ) {
1672 //Update themes
1673 foreach ( $themesToUpdateNow as $websiteId => $slugs ) {
1674 if ( ( $sitesCheckCompleted != null ) && ( $sitesCheckCompleted[ $websiteId ] == false ) ) {
1675 continue;
1676 }
1677
1678 try {
1679 MainWP_Utility::fetchUrlAuthed( $allWebsites[ $websiteId ], 'upgradeplugintheme', array(
1680 'type' => 'theme',
1681 'list' => urldecode( implode( ',', $slugs ) ),
1682 ) );
1683
1684 if ( isset( $information[ 'sync' ] ) && !empty( $information[ 'sync' ] ) ) {
1685 MainWP_Sync::syncInformationArray( $allWebsites[ $websiteId ], $information[ 'sync' ] );
1686 }
1687 } catch ( Exception $e ) {
1688
1689 }
1690 }
1691 } else {
1692 $themesToUpdateNow = array();
1693 }
1694
1695 if ( $mainwpAutomaticDailyUpdate == 1 ) {
1696 //Update core
1697 foreach ( $coreToUpdateNow as $websiteId ) {
1698 if ( ( $sitesCheckCompleted != null ) && ( $sitesCheckCompleted[ $websiteId ] == false ) ) {
1699 continue;
1700 }
1701
1702 try {
1703 MainWP_Utility::fetchUrlAuthed( $allWebsites[ $websiteId ], 'upgrade' );
1704 } catch ( Exception $e ) {
1705
1706 }
1707 }
1708 } else {
1709 $coreToUpdateNow = array();
1710 }
1711
1712 do_action( 'mainwp_cronupdatecheck_action', $pluginsNewUpdate, $pluginsToUpdate, $pluginsToUpdateNow, $themesNewUpdate, $themesToUpdate, $themesToUpdateNow, $coreNewUpdate, $coreToUpdate, $coreToUpdateNow );
1713 }
1714 }
1715
1716 public static function sync_site_icon( $siteId = null ) {
1717 if ( $siteId === null ) {
1718 if ( isset( $_POST[ 'siteId' ] ) )
1719 $siteId = $_POST[ 'siteId' ];
1720 }
1721
1722 if ( MainWP_Utility::ctype_digit( $siteId ) ) {
1723 $website = MainWP_DB::Instance()->getWebsiteById( $siteId );
1724 if ( MainWP_Utility::can_edit_website( $website ) ) {
1725 $error = '';
1726 try {
1727 $information = MainWP_Utility::fetchUrlAuthed( $website, 'get_site_icon' );
1728 } catch ( MainWP_Exception $e ) {
1729 $error = $e->getMessage();
1730 }
1731
1732 if ( $error != '' ) {
1733 return array( 'error' => $error );
1734 } else if ( isset( $information[ 'faviIconUrl' ] ) && !empty( $information[ 'faviIconUrl' ] ) ) {
1735 MainWP_Logger::Instance()->debug( 'Downloading icon :: ' . $information[ 'faviIconUrl' ] );
1736 $content = MainWP_Utility::get_file_content( $information[ 'faviIconUrl' ] );
1737 if ( !empty( $content ) ) {
1738 $dirs = MainWP_Utility::getMainWPDir();
1739 $iconsDir = $dirs[ 0 ] . 'icons' . DIRECTORY_SEPARATOR;
1740 if ( !@is_dir( $iconsDir ) ) {
1741 @mkdir( $iconsDir, 0777, true );
1742 }
1743 if ( !file_exists( $iconsDir . 'index.php' ) ) {
1744 @touch( $iconsDir . 'index.php' );
1745 }
1746 $filename = basename( $information[ 'faviIconUrl' ] );
1747 $filename = strtok($filename, "?"); // to fix: remove params
1748 if ( $filename ) {
1749 $filename = 'favi-' . $siteId . '-' . $filename;
1750 if ( $size = file_put_contents( $iconsDir . $filename, $content ) ) {
1751 MainWP_Logger::Instance()->debug( 'Icon size :: ' . $size );
1752 MainWP_DB::Instance()->updateWebsiteOption( $website, 'favi_icon', $filename );
1753 return array( 'result' => 'success' );
1754 } else {
1755 return array( 'error' => 'Save icon file failed.' );
1756 }
1757 }
1758 return array( 'undefined_error' => true );
1759 } else {
1760 return array( 'error' => __( 'Download icon file failed', 'mainwp' ) );
1761 }
1762 } else {
1763 return array( 'undefined_error' => true );
1764 }
1765 }
1766 }
1767 return array( 'result' => 'NOSITE' );
1768 }
1769
1770 function mainwp_cronpingchilds_action() {
1771 MainWP_Logger::Instance()->info( 'CRON :: ping childs' );
1772
1773 $lastPing = get_option( 'mainwp_cron_last_ping' );
1774 if ( $lastPing !== false && ( time() - $lastPing ) < ( 60 * 60 * 23 ) ) {
1775 return;
1776 }
1777 MainWP_Utility::update_option( 'mainwp_cron_last_ping', time() );
1778
1779 $websites = MainWP_DB::Instance()->query( MainWP_DB::Instance()->getSQLWebsites() );
1780 while ( $websites && ( $website = @MainWP_DB::fetch_object( $websites ) ) ) {
1781 try {
1782 $url = $website->siteurl;
1783 if ( !MainWP_Utility::endsWith( $url, '/' ) ) {
1784 $url .= '/';
1785 }
1786
1787 wp_remote_get( $url . 'wp-cron.php' );
1788 } catch ( Exception $e ) {
1789
1790 }
1791 }
1792 @MainWP_DB::free_result( $websites );
1793 }
1794
1795 function mainwp_cronbackups_continue_action() {
1796 if ( !get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
1797 return;
1798 }
1799 MainWP_Logger::Instance()->info( 'CRON :: backups continue' );
1800
1801 @ignore_user_abort( true );
1802 @set_time_limit( 0 );
1803 $mem = '512M';
1804 @ini_set( 'memory_limit', $mem );
1805 @ini_set( 'max_execution_time', 0 );
1806
1807 MainWP_Utility::update_option( 'mainwp_cron_last_backups_continue', time() );
1808
1809 //Fetch all tasks where complete < last & last checkup is more then 1minute ago! & last is more then 1 minute ago!
1810 $tasks = MainWP_DB::Instance()->getBackupTasksToComplete();
1811
1812 MainWP_Logger::Instance()->debug( 'CRON :: backups continue :: Found ' . count( $tasks ) . ' to continue.' );
1813
1814 if ( empty( $tasks ) ) {
1815 return;
1816 }
1817
1818 foreach ( $tasks as $task ) {
1819 MainWP_Logger::Instance()->debug( 'CRON :: backups continue :: Task: ' . $task->name );
1820 }
1821
1822 foreach ( $tasks as $task ) {
1823 $task = MainWP_DB::Instance()->getBackupTaskById( $task->id );
1824 if ( $task->completed < $task->last_run ) {
1825 MainWP_Manage_Backups::executeBackupTask( $task, 5, false );
1826 break;
1827 }
1828 }
1829 }
1830
1831 function mainwp_cronbackups_action() {
1832 if ( !get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
1833 return;
1834 }
1835
1836 MainWP_Logger::Instance()->info( 'CRON :: backups' );
1837
1838 @ignore_user_abort( true );
1839 @set_time_limit( 0 );
1840 $mem = '512M';
1841 @ini_set( 'memory_limit', $mem );
1842 @ini_set( 'max_execution_time', 0 );
1843
1844 MainWP_Utility::update_option( 'mainwp_cron_last_backups', time() );
1845
1846 //Do cronjobs!
1847 //Config this in crontab: 0 0 * * * wget -q http://mainwp.com/wp-admin/?do=cron -O /dev/null 2>&1
1848 //this will execute once every day to check to do the scheduled backups
1849 $allTasks = array();
1850 $dailyTasks = MainWP_DB::Instance()->getBackupTasksTodoDaily();
1851 if ( count( $dailyTasks ) > 0 ) {
1852 $allTasks = $dailyTasks;
1853 }
1854 $weeklyTasks = MainWP_DB::Instance()->getBackupTasksTodoWeekly();
1855 if ( count( $weeklyTasks ) > 0 ) {
1856 $allTasks = array_merge( $allTasks, $weeklyTasks );
1857 }
1858 $monthlyTasks = MainWP_DB::Instance()->getBackupTasksTodoMonthly();
1859 if ( count( $monthlyTasks ) > 0 ) {
1860 $allTasks = array_merge( $allTasks, $monthlyTasks );
1861 }
1862
1863 MainWP_Logger::Instance()->debug( 'CRON :: backups :: Found ' . count( $allTasks ) . ' to start.' );
1864
1865 foreach ( $allTasks as $task ) {
1866 MainWP_Logger::Instance()->debug( 'CRON :: backups :: Task: ' . $task->name );
1867 }
1868
1869 foreach ( $allTasks as $task ) {
1870 $threshold = 0;
1871 if ( $task->schedule == 'daily' ) {
1872 $threshold = ( 60 * 60 * 24 );
1873 } else if ( $task->schedule == 'weekly' ) {
1874 $threshold = ( 60 * 60 * 24 * 7 );
1875 } else if ( $task->schedule == 'monthly' ) {
1876 $threshold = ( 60 * 60 * 24 * 30 );
1877 }
1878 $task = MainWP_DB::Instance()->getBackupTaskById( $task->id );
1879 if ( ( time() - $task->last_run ) < $threshold ) {
1880 continue;
1881 }
1882
1883 if ( !MainWP_Manage_Backups::validateBackupTasks( array( $task ) ) ) {
1884 $task = MainWP_DB::Instance()->getBackupTaskById( $task->id );
1885 }
1886
1887 $chunkedBackupTasks = get_option( 'mainwp_chunkedBackupTasks' );
1888 MainWP_Manage_Backups::executeBackupTask( $task, ( $chunkedBackupTasks != 0 ? 5 : 0 ) );
1889 }
1890 }
1891
1892 function mainwp_cronstats_action() {
1893 MainWP_Logger::Instance()->info( 'CRON :: stats' );
1894
1895 MainWP_Utility::update_option( 'mainwp_cron_last_stats', time() );
1896
1897 $websites = MainWP_DB::Instance()->query( MainWP_DB::Instance()->getWebsitesStatsUpdateSQL() );
1898
1899 $start = time();
1900 while ( $websites && ( $website = @MainWP_DB::fetch_object( $websites ) ) ) {
1901 if ( ( $start - time() ) > ( 60 * 60 * 2 ) ) {
1902 //two hours passed, next cron will start!
1903 break;
1904 }
1905
1906 MainWP_DB::Instance()->updateWebsiteStats( $website->id, time() );
1907
1908 if ( property_exists( $website, 'sync_errors' ) && $website->sync_errors != '' ) {
1909 //Try reconnecting
1910 MainWP_Logger::Instance()->infoForWebsite( $website, 'reconnect', 'Trying to reconnect' );
1911 try {
1912 if ( MainWP_Manage_Sites::_reconnectSite( $website ) ) {
1913 //Reconnected
1914 MainWP_Logger::Instance()->infoForWebsite( $website, 'reconnect', 'Reconnected successfully' );
1915 }
1916 } catch ( Exception $e ) {
1917 //Still something wrong
1918 MainWP_Logger::Instance()->warningForWebsite( $website, 'reconnect', $e->getMessage() );
1919 }
1920 } else if ( $website->nossl == 0 ) {
1921 //Try connecting to ssl!
1922 }
1923 sleep( 3 );
1924 }
1925 @MainWP_DB::free_result( $websites );
1926 }
1927
1928 function admin_footer() {
1929
1930 $this->update_footer(true); // will hide #wpfooter
1931
1932 if ( !MainWP_Menu::is_disable_menu_item( 2, 'PostBulkManage' ) ) {
1933 MainWP_Post::initMenuSubPages();
1934 }
1935 if ( !MainWP_Menu::is_disable_menu_item( 2, 'managesites' ) ) {
1936 MainWP_Manage_Sites::initMenuSubPages();
1937 }
1938
1939 if ( !MainWP_Menu::is_disable_menu_item( 2, 'Settings' ) ) {
1940 MainWP_Settings::initMenuSubPages();
1941 }
1942
1943 if ( !MainWP_Menu::is_disable_menu_item( 2, 'Extensions' ) ) {
1944 MainWP_Extensions::initMenuSubPages();
1945 }
1946 if ( !MainWP_Menu::is_disable_menu_item( 2, 'PageBulkManage' ) ) {
1947 MainWP_Page::initMenuSubPages();
1948 }
1949 if ( !MainWP_Menu::is_disable_menu_item( 2, 'ThemesManage' ) ) {
1950 MainWP_Themes::initMenuSubPages();
1951 }
1952 if ( !MainWP_Menu::is_disable_menu_item( 2, 'PluginsManage' ) ) {
1953 MainWP_Plugins::initMenuSubPages();
1954 }
1955 if ( !MainWP_Menu::is_disable_menu_item( 2, 'UserBulkManage' ) ) {
1956 MainWP_User::initMenuSubPages();
1957 }
1958 if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
1959 if ( !MainWP_Menu::is_disable_menu_item( 2, 'ManageBackups' ) ) {
1960 MainWP_Manage_Backups::initMenuSubPages();
1961 }
1962 }
1963 if ( !MainWP_Menu::is_disable_menu_item( 2, 'Settings' ) ) {
1964 MainWP_Settings::initMenuSubPages();
1965 }
1966 do_action( 'mainwp_admin_menu_sub' );
1967 if ( !MainWP_Menu::is_disable_menu_item( 2, 'ServerInformation' ) ) {
1968 MainWP_Server_Information::initMenuSubPages();
1969 }
1970
1971 if ( self::isMainWP_Pages() ) {
1972 $disabled_confirm = get_option( 'mainwp_disable_update_confirmations', 0 );
1973 ?>
1974 <input type="hidden" id="mainwp-disable-update-confirmations" value="<?php echo intval($disabled_confirm); ?>">
1975
1976 <script type="text/javascript">
1977 jQuery( document ).ready( function ()
1978 {
1979 jQuery( '#adminmenu #collapse-menu' ).hide();
1980 } );
1981 </script>
1982
1983
1984 <?php
1985 }
1986
1987 $hide_ref = apply_filters('mainwp_open_hide_referrer', false);
1988 if ($hide_ref) {
1989 ?>
1990 <script type="text/javascript">
1991 jQuery(document).on('click', 'a.mainwp-may-hide-referrer', function(e) {
1992 e.preventDefault();
1993 mainwp_open_hide_referrer(e.target.href);
1994 });
1995
1996 function mainwp_open_hide_referrer(url) {
1997 var ran = Math.floor(Math.random() * 100) + 1;
1998 var site = window.open("", "mainwp_hide_referrer_" + ran);
1999 var meta = site.document.createElement('meta');
2000 meta.name = "referrer";
2001 meta.content = "no-referrer";
2002 site.document.getElementsByTagName('head')[0].appendChild(meta);
2003 site.document.open();
2004 site.document.writeln('<script type="text/javascript">window.location = "' + url + '";<\/script>');
2005 site.document.close();
2006 }
2007 </script>
2008 <?php
2009 }
2010
2011 global $_mainwp_disable_menus_items;
2012
2013 $_mainwp_disable_menus_items = apply_filters('mainwp_all_disablemenuitems', $_mainwp_disable_menus_items); // to support developer to debug
2014
2015 }
2016
2017 function print_admin_styles($value = true) {
2018 if ( self::isMainWP_Pages() ) {
2019 return false;
2020 }
2021 return $value;
2022 }
2023
2024 function admin_print_styles() {
2025 ?>
2026 <style>
2027 <?php
2028 if ( !self::isMainWP_Pages() ) {
2029 ?>
2030 html.wp-toolbar{
2031 padding-top: 32px !important; /* reset to default WP value */
2032 }
2033 <?php
2034 } else {
2035 ?>
2036 #wpbody-content > div.update-nag,
2037 #wpbody-content > div.updated {
2038 margin-left: 190px;
2039 }
2040 <?php
2041 }
2042 ?>
2043 .mainwp-checkbox:before {
2044 content: '<?php _e( 'YES', 'mainwp' ); ?>';
2045 }
2046 .mainwp-checkbox:after {
2047 content: '<?php _e( 'NO', 'mainwp' ); ?>';
2048 }
2049 </style>
2050 <?php
2051 }
2052
2053 public static function isMainWP_Pages() {
2054 $screen = get_current_screen();
2055 if ( $screen && strpos( $screen->base, 'mainwp_' ) !== false && strpos( $screen->base, 'mainwp_child_tab' ) === false) {
2056 return true;
2057 }
2058
2059 return false;
2060 }
2061
2062 public static function get_openssl_conf() {
2063
2064 if ( defined( 'MAINWP_CRYPT_RSA_OPENSSL_CONFIG' ) ) {
2065 return MAINWP_CRYPT_RSA_OPENSSL_CONFIG;
2066 }
2067
2068 $setup_conf_loc = '';
2069 if ( MainWP_Settings::isLocalWindowConfig() ) {
2070 $setup_conf_loc = get_option( 'mwp_setup_opensslLibLocation' );
2071 } else if ( get_option( 'mainwp_opensslLibLocation' ) != '' ) {
2072 $setup_conf_loc = get_option( 'mainwp_opensslLibLocation' );
2073 }
2074 return $setup_conf_loc;
2075 }
2076
2077 function init() {
2078
2079 global $_mainwp_disable_menus_items;
2080
2081 // deprecate hook from 4.0
2082 $_mainwp_disable_menus_items = apply_filters( 'mainwp_disablemenuitems', $_mainwp_disable_menus_items );
2083
2084 $_mainwp_disable_menus_items = apply_filters( 'mainwp_main_menu_disable_menu_items', $_mainwp_disable_menus_items );
2085
2086
2087 if ( !function_exists( 'mainwp_current_user_can' ) ) {
2088
2089 function mainwp_current_user_can( $cap_type = '', $cap ) {
2090 global $current_user;
2091
2092 if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
2093 return true;
2094 }
2095
2096 // To fix bug run from wp cli
2097 if ( defined( 'WP_CLI' ) && WP_CLI ) {
2098 return true;
2099 }
2100
2101 if ( empty( $current_user ) ) {
2102 if ( !function_exists( 'wp_get_current_user' ) ) {
2103 require_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'pluggable.php' );
2104 }
2105 $current_user = wp_get_current_user();
2106 }
2107
2108 if ( empty( $current_user ) ) {
2109 return false;
2110 }
2111
2112 return apply_filters( 'mainwp_currentusercan', true, $cap_type, $cap );
2113 }
2114
2115 }
2116
2117 $this->handleSettingsPost();
2118
2119 }
2120
2121 function uploadFile( $file ) {
2122 header( 'Content-Description: File Transfer' );
2123 if ( MainWP_Utility::endsWith( $file, '.tar.gz' ) ) {
2124 header( 'Content-Type: application/x-gzip' );
2125 header( "Content-Encoding: gzip" );
2126 } else {
2127 header( 'Content-Type: application/octet-stream' );
2128 }
2129 header( 'Content-Disposition: attachment; filename="' . basename( $file ) . '"' );
2130 header( 'Expires: 0' );
2131 header( 'Cache-Control: must-revalidate' );
2132 header( 'Pragma: public' );
2133 header( 'Content-Length: ' . filesize( $file ) );
2134 while ( @ob_get_level() ) {
2135 @ob_end_clean();
2136 }
2137 $this->readfile_chunked( $file );
2138 exit();
2139 }
2140
2141 function readfile_chunked( $filename ) {
2142 $chunksize = 1024; // how many bytes per chunk
2143 $handle = @fopen( $filename, 'rb' );
2144 if ( $handle === false ) {
2145 return false;
2146 }
2147
2148 while ( !@feof( $handle ) ) {
2149 $buffer = @fread( $handle, $chunksize );
2150 echo $buffer;
2151 @ob_flush();
2152 @flush();
2153 $buffer = null;
2154 }
2155
2156 return @fclose( $handle );
2157 }
2158
2159 function parse_init() {
2160 if ( isset( $_GET[ 'do' ] ) && $_GET[ 'do' ] == 'testLog' ) {
2161 MainWP_Logger::Instance()->debug( 'ruben' );
2162 }
2163 if ( isset( $_GET[ 'do' ] ) && $_GET[ 'do' ] == 'cronBackups' ) {
2164 $this->mainwp_cronbackups_action();
2165 } else if ( isset( $_GET[ 'do' ] ) && $_GET[ 'do' ] == 'cronBackupsContinue' ) {
2166 $this->mainwp_cronbackups_continue_action();
2167 } else if ( isset( $_GET[ 'do' ] ) && $_GET[ 'do' ] == 'cronStats' ) {
2168 $this->mainwp_cronstats_action();
2169 } else if ( isset( $_GET[ 'do' ] ) && $_GET[ 'do' ] == 'cronUpdatesCheck' ) {
2170 $this->mainwp_cronupdatescheck_action();
2171 } else if ( isset( $_GET[ 'mwpdl' ] ) && isset( $_GET[ 'sig' ] ) ) {
2172 $mwpDir = MainWP_Utility::getMainWPDir();
2173 $mwpDir = $mwpDir[ 0 ];
2174 $file = trailingslashit( $mwpDir ) . rawurldecode( $_REQUEST[ 'mwpdl' ] );
2175
2176 if ( stristr( rawurldecode( $_REQUEST[ 'mwpdl' ] ), '..' ) ) {
2177 return;
2178 }
2179
2180 if ( file_exists( $file ) && md5( filesize( $file ) ) == $_GET[ 'sig' ] ) {
2181 $this->uploadFile( $file );
2182 exit();
2183 }
2184 } else if ( isset( $_GET[ 'page' ] ) ) {
2185 if ( MainWP_Utility::isAdmin() ) {
2186 switch ( $_GET[ 'page' ] ) {
2187 case 'mainwp-setup' :
2188 new MainWP_Setup_Wizard();
2189 break;
2190 }
2191 }
2192 }
2193 }
2194
2195 function login_form() {
2196 global $redirect_to;
2197 if ( !isset( $_GET[ 'redirect_to' ] ) ) {
2198 $redirect_to = get_admin_url() . 'index.php';
2199 }
2200 }
2201
2202 function post_updated_messages( $messages ) {
2203 $messages[ 'post' ][ 98 ] = __( 'WordPress SEO values have been saved.', 'mainwp' );
2204 $messages[ 'post' ][ 99 ] = __( 'You have to select the sites you wish to publish to.', 'mainwp' );
2205
2206 return $messages;
2207 }
2208
2209 function mainwp_warning_notice() {
2210
2211 if ( get_option( 'mainwp_installation_warning_hide_the_notice' ) == 'yes' ) {
2212 return;
2213 }
2214 if ( MainWP_DB::Instance()->getWebsitesCount() > 0 ) {
2215 return;
2216 } else {
2217 $plugins = get_plugins();
2218 if ( !is_array($plugins) || count($plugins) <= 4 ) {
2219 return; // new install
2220 }
2221 }
2222
2223 ?>
2224 <div class="ui red icon message" style="margin-bottom: 0; border-radius: 0;">
2225 <i class="info circle icon"></i>
2226 <div class="content">
2227 <div class="header"><?php esc_html_e( 'This appears to be a production site', 'mainwp' ); ?></div>
2228 <?php esc_html_e( 'We HIGHLY recommend a NEW WordPress install for your MainWP Dashboard.', 'mainwp' ); ?> <?php echo sprintf( __( 'Using a new WordPress install will help to cut down on plugin conflicts and other issues that can be caused by trying to run your MainWP Dashboard off an active site. Most hosting companies provide free subdomains %s and we recommend creating one if you do not have a specific dedicated domain to run your MainWP Dashboard.', 'mainwp' ), '("<strong>demo.yourdomain.com</strong>")' ); ?>
2229 <br /><br />
2230 <a href="#" class="ui red mini button" id="remove-mainwp-installation-warning"><?php esc_html_e( 'I have read the warning and I want to proceed', 'mainwp' ); ?></a>
2231 </div>
2232 </div>
2233 <?php
2234 }
2235
2236
2237 public function activate_redirect( $location ) {
2238 $location = admin_url( 'admin.php?page=Extensions' );
2239 return $location;
2240 }
2241
2242 function activate_extention( $ext_key, $info = array() ) {
2243
2244 add_filter( 'wp_redirect', array($this, 'activate_redirect'));
2245
2246 if ( is_array( $info ) && isset( $info['product_id'] ) && isset( $info['software_version'] ) ) {
2247 $act_info = array(
2248 'product_id' => $info['product_id'],
2249 'software_version' => $info['software_version'],
2250 'activated_key' => 'Deactivated',
2251 'instance_id' => MainWP_Api_Manager_Password_Management::generate_password( 12, false )
2252 );
2253 MainWP_Api_Manager::instance()->set_activation_info($ext_key, $act_info);
2254 }
2255 }
2256
2257 function deactivate_extention( $ext_key ) {
2258 MainWP_Api_Manager::instance()->set_activation_info($ext_key, '');
2259 }
2260
2261 function admin_init() {
2262 if ( ! MainWP_Utility::isAdmin() ) {
2263 return;
2264 }
2265
2266 add_action('mainwp_activate_extention', array($this, 'activate_extention'), 10 , 2 );
2267 add_action('mainwp_deactivate_extention', array($this, 'deactivate_extention'), 10 , 1 );
2268
2269 // if ( get_option( 'mainwp_activated' ) == 'yes' ) {
2270 // delete_option( 'mainwp_activated' );
2271 // wp_cache_delete( 'mainwp_activated', 'options' );
2272 // wp_cache_delete( 'alloptions' , 'options' );
2273 // wp_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
2274 //
2275 // return;
2276 // }
2277
2278 global $mainwpUseExternalPrimaryBackupsMethod;
2279
2280 if ( $mainwpUseExternalPrimaryBackupsMethod === null ) {
2281 $mainwpUseExternalPrimaryBackupsMethod = apply_filters( 'mainwp-getprimarybackup-activated', '' );
2282 }
2283
2284 add_action( 'mainwp_before_header', array( $this, 'mainwp_warning_notice' ) );
2285 MainWP_Post_Handler::Instance()->init();
2286 $use_wp_datepicker = apply_filters( 'mainwp_ui_use_wp_calendar', false );
2287 //wp_enqueue_script( 'jquery-ui-tooltip' );
2288 //wp_enqueue_script( 'jquery-ui-autocomplete' );
2289 //wp_enqueue_script( 'jquery-ui-progressbar' );
2290 if ($use_wp_datepicker) {
2291 wp_enqueue_script( 'jquery-ui-datepicker' );
2292 }
2293 wp_enqueue_script( 'jquery-ui-dialog' );
2294
2295 global $wp_scripts;
2296 $ui = $wp_scripts->query( 'jquery-ui-core' );
2297 $version = $ui->ver;
2298 // if ( MainWP_Utility::startsWith( $version, '1.10' ) ) {
2299 // wp_enqueue_style( 'jquery-ui-style', MAINWP_PLUGIN_URL . 'assests/css/1.10.4/jquery-ui.min.css', array(), '1.10.4' );
2300 // } else {
2301 wp_enqueue_style( 'jquery-ui-style', MAINWP_PLUGIN_URL . 'assests/css/1.11.1/jquery-ui.min.css', array(), '1.11.1' );
2302 // }
2303
2304 $en_params = array('jquery-ui-dialog');
2305 if ($use_wp_datepicker) {
2306 $en_params[] = 'jquery-ui-datepicker';
2307 }
2308 wp_enqueue_script( 'mainwp', MAINWP_PLUGIN_URL . 'assests/js/mainwp.js', $en_params, $this->current_version );
2309
2310 $enableLegacyBackupFeature = get_option( 'mainwp_enableLegacyBackupFeature' );
2311 $primaryBackup = get_option( 'mainwp_primaryBackup' );
2312 $disable_backup_checking = (empty( $enableLegacyBackupFeature ) && empty( $primaryBackup )) ? true : false;
2313
2314 $mainwpParams = array(
2315 'image_url' => MAINWP_PLUGIN_URL . 'assests/images/',
2316 'backup_before_upgrade' => ( get_option( 'mainwp_backup_before_upgrade' ) == 1 ),
2317 'disable_checkBackupBeforeUpgrade' => $disable_backup_checking,
2318 'admin_url' => admin_url(),
2319 'use_wp_datepicker' => $use_wp_datepicker ? 1 : 0,
2320 'date_format' => get_option( 'date_format' ),
2321 'time_format' => get_option( 'time_format' ),
2322 'enabledTwit' => MainWP_Twitter::enabledTwitterMessages(),
2323 'maxSecondsTwit' => MAINWP_TWITTER_MAX_SECONDS,
2324 'installedBulkSettingsManager' => MainWP_Extensions::isExtensionAvailable( 'mainwp-bulk-settings-manager' ) ? 1 : 0,
2325 'maximumSyncRequests' => ( get_option( 'mainwp_maximumSyncRequests' ) === false ) ? 8 : get_option( 'mainwp_maximumSyncRequests' ),
2326 'maximumInstallUpdateRequests' => ( get_option( 'mainwp_maximumInstallUpdateRequests' ) === false ) ? 3 : get_option( 'mainwp_maximumInstallUpdateRequests' ),
2327 );
2328 wp_localize_script( 'mainwp', 'mainwpParams', $mainwpParams );
2329
2330 $mainwpTranslations = MainWP_System_View::getMainWPTranslations();
2331
2332 wp_localize_script( 'mainwp', 'mainwpTranslations', $mainwpTranslations );
2333
2334 $security_nonces = MainWP_Post_Handler::Instance()->getSecurityNonces();
2335 wp_localize_script( 'mainwp', 'security_nonces', $security_nonces );
2336
2337 //MainWP_Meta_Boxes::initMetaBoxes();
2338
2339 wp_enqueue_script( 'thickbox' );
2340 wp_enqueue_script( 'user-profile' );
2341 wp_enqueue_style( 'thickbox' );
2342
2343 if ( isset( $_GET[ 'page' ] ) && ( $_GET[ 'page' ] == 'mainwp_tab' || ( $_GET[ 'page' ] == 'managesites' ) && isset($_GET[ 'dashboard' ])) ) {
2344 // draggabilly grid layout library
2345 wp_enqueue_script( 'dragula', MAINWP_PLUGIN_URL . 'assests/js/dragula/dragula.min.js', array(), $this->current_version );
2346 wp_enqueue_style( 'dragula', MAINWP_PLUGIN_URL . 'assests/js/dragula/dragula.min.css', array(), $this->current_version );
2347 }
2348
2349 $this->init_session();
2350
2351 if ( !current_user_can( 'update_core' ) ) {
2352 remove_action( 'admin_notices', 'update_nag', 3 );
2353 }
2354 }
2355
2356 public function admin_redirects() {
2357 if ( (defined( 'DOING_CRON' ) && DOING_CRON) || defined( 'DOING_AJAX' ) ) {
2358 return;
2359 }
2360
2361 if ( !empty( $_GET[ 'page' ] ) && in_array( $_GET[ 'page' ], array( 'mainwp-setup' ) ) ) {
2362 return;
2363 }
2364
2365 // redirect on first install
2366 $quick_setup = get_option( 'mainwp_run_quick_setup', false );
2367 if ( $quick_setup == 'yes' ) {
2368 wp_redirect( admin_url( 'admin.php?page=mainwp-setup' ) );
2369 exit;
2370 }
2371
2372 if ( get_option( 'mainwp_activated' ) == 'yes' ) {
2373 delete_option( 'mainwp_activated' );
2374 wp_cache_delete( 'mainwp_activated', 'options' );
2375 wp_cache_delete( 'alloptions' , 'options' );
2376 wp_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
2377
2378 return;
2379 }
2380
2381 $started = get_option( 'mainwp_getting_started' );
2382 if ( !empty( $started ) ) {
2383 delete_option( 'mainwp_getting_started' );
2384 wp_cache_delete( 'mainwp_getting_started' , 'options' );
2385 wp_cache_delete( 'alloptions' , 'options' );
2386 if ( !is_multisite() ) {
2387 if ( 'started' == $started ) {
2388 wp_redirect( admin_url( 'admin.php?page=mainwp_about&do=started' ) );
2389 exit;
2390 } else if ( 'whatnew' == $started ) {
2391 // wp_redirect( admin_url( 'admin.php?page=mainwp_about&do=whatnew' ) );
2392 // exit;
2393 }
2394 }
2395 }
2396
2397 $_pos = strlen( $_SERVER[ 'REQUEST_URI' ] ) - strlen( '/wp-admin/' );
2398 // if open /wp-admin/ path then check to redirect to mainwp overview
2399 if ( strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) !== false && strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) == $_pos ) {
2400 if ( mainwp_current_user_can( 'dashboard', 'access_global_dashboard' ) ) { // to fix
2401 wp_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
2402 die();
2403 }
2404 }
2405 }
2406
2407 function handleSettingsPost() {
2408 if ( !function_exists( 'wp_create_nonce' ) ) {
2409 include_once( ABSPATH . WPINC . '/pluggable.php' );
2410 }
2411
2412 if ( isset( $_GET['page'] ) && isset($_POST['wp_nonce']) ) {
2413 $update_screen_options = false;
2414 if ( $_GET[ 'page' ] == 'MainWPTools' ) {
2415 if ( isset( $_POST[ 'submit' ] ) && wp_verify_nonce( $_POST[ 'wp_nonce' ], 'MainWPTools' ) ) {
2416 $update_screen_options = true;
2417 MainWP_Utility::update_option( 'mainwp_enable_managed_cr_for_wc', (!isset( $_POST[ 'enable_managed_cr_for_wc' ] ) ? 0 : 1 ) );
2418 MainWP_Utility::update_option( 'mainwp_use_favicon', (!isset( $_POST[ 'mainwp_use_favicon' ] ) ? 0 : 1 ) );
2419
2420 $enabled_twit = ! isset( $_POST['mainwp_hide_twitters_message'] ) ? 0 : 1;
2421 MainWP_Utility::update_option( 'mainwp_hide_twitters_message', $enabled_twit );
2422 if ( ! $enabled_twit ) {
2423 MainWP_Twitter::clearAllTwitterMessages();
2424 }
2425 }
2426 } else if ( $_GET[ 'page' ] == 'mainwp_tab' || isset( $_GET['dashboard'] ) ) {
2427 if ( isset( $_POST[ 'submit' ] ) && wp_verify_nonce( $_POST[ 'wp_nonce' ], 'MainWPScrOptions' ) ) {
2428 $update_screen_options = true;
2429 }
2430 }
2431
2432 if ( $update_screen_options ) {
2433 $hide_wids = array();
2434 if ( isset( $_POST[ 'mainwp_hide_widgets' ] ) && is_array( $_POST[ 'mainwp_hide_widgets' ] ) ) {
2435 foreach ( $_POST[ 'mainwp_hide_widgets' ] as $value ) {
2436 $hide_wids[] = $value;
2437 }
2438 }
2439
2440 if ( $user = wp_get_current_user() ) {
2441 update_user_option($user->ID, "mainwp_settings_hide_widgets", $hide_wids, true);
2442 }
2443
2444 MainWP_Utility::update_option( 'mainwp_hide_update_everything', (!isset( $_POST[ 'hide_update_everything' ] ) ? 0 : 1 ) );
2445 MainWP_Utility::update_option( 'mainwp_show_usersnap', (!isset( $_POST[ 'mainwp_show_usersnap' ] ) ? 0 : time() ) );
2446 MainWP_Utility::update_option( 'mainwp_number_overview_columns', intval( $_POST[ 'number_overview_columns' ] ) );
2447 }
2448
2449
2450 if ( isset( $_POST[ 'submit' ] ) && wp_verify_nonce( $_POST[ 'wp_nonce' ], 'ManageSitesScrOptions' ) ) {
2451 $hide_cols = array();
2452 foreach($_POST as $key => $val) {
2453 if ( strpos( $key, 'mainwp_hide_column_' ) !== false) {
2454 $col = str_replace( 'mainwp_hide_column_', '', $key );
2455 $hide_cols[] = $col;
2456 }
2457 }
2458
2459 if ( $user = wp_get_current_user() ) {
2460 update_user_option($user->ID, "mainwp_settings_hide_manage_sites_columns", $hide_cols, true);
2461 update_option( 'mainwp_default_sites_per_page', intval( $_POST['mainwp_default_sites_per_page'] ) );
2462 }
2463
2464 }
2465
2466 }
2467
2468 if ( isset( $_POST[ 'select_mainwp_options_siteview' ] ) ) {
2469 $userExtension = MainWP_DB::Instance()->getUserExtension();
2470 $userExtension->site_view = ( empty( $_POST[ 'select_mainwp_options_siteview' ] ) ? MAINWP_VIEW_PER_PLUGIN_THEME : intval( $_POST[ 'select_mainwp_options_siteview' ] ) );
2471 MainWP_DB::Instance()->updateUserExtension( $userExtension );
2472 }
2473
2474 if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] )) {
2475 if ( wp_verify_nonce( $_POST[ 'wp_nonce' ], 'Settings' ) ) {
2476 $updated = MainWP_Settings::handleSettingsPost();
2477 $updated |= MainWP_Manage_Sites::handleSettingsPost();
2478 $msg = '';
2479 if ( $updated ) {
2480 $msg = '&message=saved';
2481 }
2482 wp_redirect( admin_url( 'admin.php?page=Settings' . $msg ) );
2483 exit();
2484 } else if ( wp_verify_nonce( $_POST[ 'wp_nonce' ], 'PluginAutoUpdate' ) ) {
2485 $val = (!isset( $_POST[ 'mainwp_pluginAutomaticDailyUpdate' ] ) ? 0 : $_POST[ 'mainwp_pluginAutomaticDailyUpdate' ] );
2486 MainWP_Utility::update_option( 'mainwp_pluginAutomaticDailyUpdate', $val );
2487 wp_redirect( admin_url( 'admin.php?page=PluginsAutoUpdate&message=saved' ) );
2488 exit();
2489 } else if ( wp_verify_nonce( $_POST[ 'wp_nonce' ], 'ThemeAutoUpdate' ) ) {
2490 $val = (!isset( $_POST[ 'mainwp_themeAutomaticDailyUpdate' ] ) ? 0 : $_POST[ 'mainwp_themeAutomaticDailyUpdate' ] );
2491 MainWP_Utility::update_option( 'mainwp_themeAutomaticDailyUpdate', $val );
2492 wp_redirect( admin_url( 'admin.php?page=ThemesAutoUpdate&message=saved' ) );
2493 exit();
2494 }
2495 }
2496 }
2497
2498 public function handle_edit_bulkpost() {
2499
2500 $post_id = 0;
2501 if (isset( $_POST['post_ID'] ) )
2502 $post_id = (int) $_POST['post_ID'];
2503
2504 // verify this came from the our screen and with proper authorization.
2505 if ( $post_id && isset( $_POST[ 'select_sites_nonce' ] ) && wp_verify_nonce( $_POST[ 'select_sites_nonce' ], 'select_sites_' . $post_id ) ) {
2506 // see more 'editpost' in the file wp-admin/post.php
2507 check_admin_referer('update-post_' . $post_id);
2508 edit_post(); // WP core function
2509
2510 $location = admin_url('admin.php?page=PostBulkEdit&post_id=' . $post_id . '&message=1');
2511 // to handle parameters
2512 // see more redirect_post() in the file wp-admin/includes/post.php
2513 $location = apply_filters( 'redirect_post_location', $location, $post_id );
2514 wp_redirect($location);
2515 exit();
2516 }
2517 }
2518
2519 public function redirect_edit_bulkpost( $location, $post_id ) {
2520 if ($post_id)
2521 $location = admin_url('admin.php?page=PostBulkEdit&post_id=' . intval($post_id));
2522 else
2523 $location = admin_url( 'admin.php?page=PostBulkAdd' );
2524
2525 return $location;
2526 }
2527
2528 public function redirect_edit_bulkpage( $location, $post_id ) {
2529
2530 if ($post_id)
2531 $location = admin_url('admin.php?page=PageBulkEdit&post_id=' . intval($post_id));
2532 else
2533 $location = admin_url( 'admin.php?page=PageBulkAdd' );
2534
2535 return $location;
2536 }
2537
2538 function save_bulkpost( $post_id ) {
2539 $post = get_post( $post_id );
2540
2541 if ( $post->post_type != 'bulkpost' ) {
2542 return;
2543 }
2544
2545 if ( !isset( $_POST[ 'post_type' ] ) || ( $_POST[ 'post_type' ] != 'bulkpost' ) ) {
2546 return;
2547 }
2548
2549 // verify if this is an auto save routine.
2550 // If it is our form has not been submitted, so we dont want to do anything
2551 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
2552 return;
2553 }
2554
2555 if ( isset( $_POST[ 'mainwp_wpseo_metabox_save_values' ] ) && (!empty( $_POST[ 'mainwp_wpseo_metabox_save_values' ] ) ) ) {
2556 return;
2557 }
2558
2559
2560 //Read extra metabox
2561 $pid = $this->metaboxes->select_sites_handle( $post_id, 'bulkpost' );
2562 $this->metaboxes->add_categories_handle( $post_id, 'bulkpost' );
2563 $this->metaboxes->add_tags_handle( $post_id, 'bulkpost' );
2564 $this->metaboxes->add_slug_handle( $post_id, 'bulkpost' );
2565 MainWP_Post::add_sticky_handle( $post_id );
2566 do_action( 'mainwp_save_bulkpost', $post_id );
2567
2568 if ( $pid == $post_id )
2569 {
2570 add_filter( 'redirect_post_location', array($this, 'redirect_edit_bulkpost' ), 10, 2 );
2571 }
2572 else
2573 {
2574 // to support external redirect for example post dripper extension,
2575 // that will do not go to posting process
2576 do_action( 'mainwp_before_redirect_posting_bulkpost', $post );
2577 //Redirect to handle page! (to actually post the messages)
2578 wp_redirect( get_site_url() . '/wp-admin/admin.php?page=PostingBulkPost&id=' . $post_id . '&hideall=1' );
2579 die();
2580 }
2581 }
2582
2583 function save_bulkpage( $post_id ) {
2584
2585 $post = get_post( $post_id );
2586
2587 if ( $post->post_type != 'bulkpage' ) {
2588 return;
2589 }
2590
2591 if ( !isset( $_POST[ 'post_type' ] ) || ( $_POST[ 'post_type' ] != 'bulkpage' ) ) {
2592 return;
2593 }
2594
2595 // verify if this is an auto save routine.
2596 // If it is our form has not been submitted, so we dont want to do anything
2597 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
2598 return;
2599 }
2600
2601 if ( isset( $_POST[ 'mainwp_wpseo_metabox_save_values' ] ) && (!empty( $_POST[ 'mainwp_wpseo_metabox_save_values' ] ) ) ) {
2602 return;
2603 }
2604
2605 //Read extra metabox
2606 $pid = $this->metaboxes->select_sites_handle( $post_id, 'bulkpage' );
2607 $this->metaboxes->add_slug_handle( $post_id, 'bulkpage' );
2608 MainWP_Page::add_status_handle( $post_id );
2609
2610 do_action( 'mainwp_save_bulkpage', $post_id );
2611
2612 if ( $pid == $post_id ) {
2613 // fixed by submitbox_misc_actions
2614 //$wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $post_id ) );
2615 add_filter( 'redirect_post_location', array($this, 'redirect_edit_bulkpage' ), 10, 2 );
2616 } else {
2617 do_action( 'mainwp_before_redirect_posting_bulkpage', $post );
2618 //Redirect to handle page! (to actually post the messages)
2619 wp_redirect( get_site_url() . '/wp-admin/admin.php?page=PostingBulkPage&id=' . $post_id . '&hideall=1');
2620 die();
2621 }
2622 }
2623
2624 function create_post_type() {
2625 $queryable = ( apply_filters( 'mainwp-ext-post-plus-enabled', false ) ) ? true : false;
2626
2627 $labels = array(
2628 'name' => _x( 'Bulkpost', 'bulkpost' ),
2629 'singular_name' => _x( 'Bulkpost', 'bulkpost' ),
2630 'add_new' => _x( 'Add New', 'bulkpost' ),
2631 'add_new_item' => _x( 'Add New Bulkpost', 'bulkpost' ),
2632 'edit_item' => _x( 'Edit Bulkpost', 'bulkpost' ),
2633 'new_item' => _x( 'New Bulkpost', 'bulkpost' ),
2634 'view_item' => _x( 'View Bulkpost', 'bulkpost' ),
2635 'search_items' => _x( 'Search Bulkpost', 'bulkpost' ),
2636 'not_found' => _x( 'No bulkpost found', 'bulkpost' ),
2637 'not_found_in_trash' => _x( 'No bulkpost found in Trash', 'bulkpost' ),
2638 'parent_item_colon' => _x( 'Parent Bulkpost:', 'bulkpost' ),
2639 'menu_name' => _x( 'Bulkpost', 'bulkpost' ),
2640 );
2641
2642 $args = array(
2643 'labels' => $labels,
2644 'hierarchical' => false,
2645 'description' => 'description...',
2646 'supports' => array(
2647 'title',
2648 'editor',
2649 'excerpt',
2650 'thumbnail',
2651 'custom-fields',
2652 'comments',
2653 'revisions',
2654 ),
2655 //'taxonomies' => array('category', 'post_tag', 'page-category'),
2656 'public' => true,
2657 'show_ui' => true,
2658 //'show_in_menu' => 'index.php',
2659 'show_in_nav_menus' => false,
2660 'publicly_queryable' => $queryable,
2661 'exclude_from_search' => true,
2662 'has_archive' => false,
2663 'query_var' => false,
2664 'can_export' => false,
2665 'rewrite' => false,
2666 'capabilities' => array(
2667 'edit_post' => 'read',
2668 'edit_posts' => 'read',
2669 'edit_others_posts' => 'read',
2670 'publish_posts' => 'read',
2671 'read_post' => 'read',
2672 'read_private_posts' => 'read',
2673 'delete_post' => 'read',
2674 ),
2675 );
2676
2677 register_post_type( 'bulkpost', $args );
2678
2679 $labels = array(
2680 'name' => _x( 'Bulkpage', 'bulkpage' ),
2681 'singular_name' => _x( 'Bulkpage', 'bulkpage' ),
2682 'add_new' => _x( 'Add New', 'bulkpage' ),
2683 'add_new_item' => _x( 'Add New Bulkpage', 'bulkpage' ),
2684 'edit_item' => _x( 'Edit Bulkpage', 'bulkpage' ),
2685 'new_item' => _x( 'New Bulkpage', 'bulkpage' ),
2686 'view_item' => _x( 'View Bulkpage', 'bulkpage' ),
2687 'search_items' => _x( 'Search Bulkpage', 'bulkpage' ),
2688 'not_found' => _x( 'No bulkpage found', 'bulkpage' ),
2689 'not_found_in_trash' => _x( 'No bulkpage found in Trash', 'bulkpage' ),
2690 'parent_item_colon' => _x( 'Parent Bulkpage:', 'bulkpage' ),
2691 'menu_name' => _x( 'Bulkpage', 'bulkpage' ),
2692 );
2693
2694 $args = array(
2695 'labels' => $labels,
2696 'hierarchical' => false,
2697 'description' => 'description...',
2698 'supports' => array(
2699 'title',
2700 'editor',
2701 'excerpt',
2702 'thumbnail',
2703 'custom-fields',
2704 'comments',
2705 'revisions',
2706 ),
2707 //'taxonomies' => array('category', 'post_tag', 'page-category'),
2708 'public' => true,
2709 'show_ui' => true,
2710 //'show_in_menu' => 'index.php',
2711 'show_in_nav_menus' => false,
2712 'publicly_queryable' => $queryable,
2713 'exclude_from_search' => true,
2714 'has_archive' => false,
2715 'query_var' => false,
2716 'can_export' => false,
2717 'rewrite' => false,
2718 'capabilities' => array(
2719 'edit_post' => 'read',
2720 'edit_posts' => 'read',
2721 'edit_others_posts' => 'read',
2722 'publish_posts' => 'read',
2723 'read_post' => 'read',
2724 'read_private_posts' => 'read',
2725 'delete_post' => 'read',
2726 ),
2727 );
2728
2729 register_post_type( 'bulkpage', $args );
2730 }
2731
2732 function init_session() {
2733 // to fix issue start session for all requests
2734 if (isset($_GET['page']) && in_array($_GET['page'], array(
2735 'PostBulkManage',
2736 'PageBulkManage',
2737 'PluginsManage',
2738 'PluginsAutoUpdate',
2739 'ThemesManage',
2740 'ThemesAutoUpdate',
2741 'UserBulkManage'
2742 ))) {
2743 // start session
2744 MainWP_Cache::initSession();
2745 }
2746 }
2747
2748 function admin_enqueue_scripts( $hook ) {
2749
2750 $load_cust_scripts = false;
2751
2752 global $pagenow;
2753
2754 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php') ) {
2755 $load_cust_scripts = true;
2756 }
2757
2758 if ( self::isMainWP_Pages() ) {
2759 wp_enqueue_script( 'mainwp-updates', MAINWP_PLUGIN_URL . 'assests/js/mainwp-updates.js', array(), $this->current_version );
2760 wp_enqueue_script( 'mainwp-managesites', MAINWP_PLUGIN_URL . 'assests/js/mainwp-managesites.js', array(), $this->current_version );
2761 wp_enqueue_script( 'mainwp-extensions', MAINWP_PLUGIN_URL . 'assests/js/mainwp-extensions.js', array(), $this->current_version );
2762 wp_enqueue_script( 'mainwp-moment', MAINWP_PLUGIN_URL . 'assests/js/moment.min.js', array(), $this->current_version );
2763 wp_enqueue_script( 'semantic', MAINWP_PLUGIN_URL . 'assests/js/semantic-ui/semantic.min.js', array( 'jquery' ), $this->current_version );
2764 wp_enqueue_script( 'semantic-ui-datatables', MAINWP_PLUGIN_URL . 'assests/js/datatables/datatables.min.js', array( 'jquery' ), $this->current_version );
2765 wp_enqueue_script( 'semantic-ui-datatables-colreorder', MAINWP_PLUGIN_URL . 'assests/js/colreorder/dataTables.colReorder.js', array( 'jquery' ), $this->current_version );
2766 wp_enqueue_script( 'semantic-ui-datatables-scroller', MAINWP_PLUGIN_URL . 'assests/js/scroller/scroller.dataTables.js', array( 'jquery' ), $this->current_version );
2767 wp_enqueue_script( 'semantic-ui-datatables-fixedcolumns', MAINWP_PLUGIN_URL . 'assests/js/fixedcolumns/dataTables.fixedColumns.js', array( 'jquery' ), $this->current_version );
2768 wp_enqueue_script( 'semantic-ui-calendar', MAINWP_PLUGIN_URL . 'assests/js/calendar/calendar.min.js', array( 'jquery' ), $this->current_version );
2769 wp_enqueue_script( 'semantic-ui-hamburger', MAINWP_PLUGIN_URL . 'assests/js/hamburger/hamburger.js', array( 'jquery' ), $this->current_version );
2770 }
2771
2772 if ( $load_cust_scripts ) {
2773 wp_enqueue_script( 'semantic', MAINWP_PLUGIN_URL . 'assests/js/semantic-ui/semantic.min.js', array( 'jquery' ), $this->current_version );
2774 }
2775
2776 wp_enqueue_script( 'mainwp-ui', MAINWP_PLUGIN_URL . 'assests/js/mainwp-ui.js', array(), $this->current_version );
2777 // wp_enqueue_script( 'mainwp-moment', MAINWP_PLUGIN_URL . 'assests/js/moment/moment.min.js', array(), $this->current_version );
2778 wp_enqueue_script( 'mainwp-js-popup', MAINWP_PLUGIN_URL . 'assests/js/mainwp-popup.js', array(), $this->current_version );
2779 wp_enqueue_script( 'mainwp-fileuploader', MAINWP_PLUGIN_URL . 'assests/js/fileuploader.js', array(), $this->current_version );
2780 wp_enqueue_script( 'mainwp-date', MAINWP_PLUGIN_URL . 'assests/js/date.js', array(), $this->current_version );
2781 }
2782
2783 function admin_enqueue_styles( $hook ) {
2784 global $wp_version;
2785 wp_enqueue_style( 'mainwp', MAINWP_PLUGIN_URL . 'assests/css/mainwp.css', array(), $this->current_version );
2786 wp_enqueue_style( 'mainwp-responsive-layouts', MAINWP_PLUGIN_URL . 'assests/css/mainwp-responsive-layouts.css', array(), $this->current_version );
2787
2788 // to faster a bit
2789 if ( isset( $_GET['hideall'] ) && $_GET['hideall'] == 1 ) {
2790 remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
2791 }
2792
2793 global $pagenow;
2794
2795 $load_cust_scripts = false;
2796 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php') ) {
2797 $load_cust_scripts = true;
2798 }
2799
2800 if ( self::isMainWP_Pages() ) {
2801 wp_enqueue_style( 'mainwp-filetree', MAINWP_PLUGIN_URL . 'assests/css/jqueryFileTree.css', array(), $this->current_version );
2802 wp_enqueue_style( 'semantic', MAINWP_PLUGIN_URL . 'assests/js/semantic-ui/semantic.min.css', array(), $this->current_version );
2803 wp_enqueue_style( 'semantic-mainwp', MAINWP_PLUGIN_URL . 'assests/css/mainwp-semantic.css', array(), $this->current_version );
2804 wp_enqueue_style( 'semantic-ui-datatables', MAINWP_PLUGIN_URL . 'assests/js/datatables/datatables.min.css', array(), $this->current_version );
2805 wp_enqueue_style( 'semantic-ui-datatables-colreorder', MAINWP_PLUGIN_URL . 'assests/js/colreorder/colReorder.semanticui.css', array(), $this->current_version );
2806 wp_enqueue_style( 'semantic-ui-datatables-scroller', MAINWP_PLUGIN_URL . 'assests/js/scroller/scroller.dataTables.css', array(), $this->current_version );
2807 wp_enqueue_style( 'semantic-ui-calendar', MAINWP_PLUGIN_URL . 'assests/js/calendar/calendar.min.css', array(), $this->current_version );
2808 wp_enqueue_style( 'semantic-ui-hamburger', MAINWP_PLUGIN_URL . 'assests/js/hamburger/hamburger.css', array(), $this->current_version );
2809 }
2810
2811 if ( $load_cust_scripts ) {
2812 wp_enqueue_style( 'semantic', MAINWP_PLUGIN_URL . 'assests/js/semantic-ui/semantic.min.css', array(), $this->current_version );
2813 }
2814 }
2815
2816 function admin_head() {
2817 echo '<script type="text/javascript">var mainwp_ajax_nonce = "' . wp_create_nonce( 'mainwp_ajax' ) . '"</script>';
2818 echo '<script type="text/javascript" src="' . MAINWP_PLUGIN_URL . 'assests/js/FileSaver.js' . '"></script>';
2819 echo '<script type="text/javascript" src="' . MAINWP_PLUGIN_URL . 'assests/js/jqueryFileTree.js' . '"></script>';
2820 }
2821
2822
2823 function admin_body_class( $class_string ) {
2824 if ( self::isMainWP_Pages() ) {
2825 $class_string .= ' mainwp-ui mainwp-ui-page ';
2826 $class_string .= ' mainwp-ui-leftmenu '; // to enable MainWP custom menu
2827 }
2828 return $class_string;
2829 }
2830
2831 function admin_menu() {
2832 global $menu;
2833 foreach ( $menu as $k => $item ) {
2834 if ( $item[ 2 ] == 'edit.php?post_type=bulkpost' ) { //Remove bulkpost
2835 unset( $menu[ $k ] );
2836 } else if ( $item[ 2 ] == 'edit.php?post_type=bulkpage' ) { //Remove bulkpost
2837 unset( $menu[ $k ] );
2838 }
2839 }
2840 }
2841
2842 public static function enqueue_postbox_scripts() {
2843 wp_enqueue_script( 'common' );
2844 wp_enqueue_script( 'wp-lists' );
2845 wp_enqueue_script( 'postbox' );
2846 }
2847
2848 // going to retired
2849 public static function do_mainwp_meta_boxes( $_postpage, $screen = 'normal', $force_show = true ) {
2850 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
2851 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
2852 if ( $force_show ) {
2853 add_filter( 'hidden_meta_boxes', array( self::$instance, 'force_show_meta_box' ), 10, 3 );
2854 }
2855 ?>
2856 <div class="metabox-holder columns-1">
2857 <?php do_meta_boxes( $_postpage, $screen, null ); ?>
2858 </div>
2859 <script type="text/javascript"> var mainwp_postbox_page = '<?php echo esc_html( $_postpage ); ?>';</script>
2860 <?php
2861 if ( $force_show ) {
2862 remove_filter( 'hidden_meta_boxes', array( self::$instance, 'force_show_meta_box' ) );
2863 }
2864 }
2865
2866 public function force_show_meta_box( $hidden, $screen ) {
2867 return array();
2868 }
2869
2870 function update_footer( $echo = false ) {
2871 if ( !self::isMainWP_Pages() ) {
2872 return;
2873 }
2874 // avoid for better performance
2875 if ( isset( $_GET['hideall'] ) && $_GET['hideall'] == 1 ) {
2876 return;
2877 }
2878 $current_wpid = MainWP_Utility::get_current_wpid();
2879 if ( $current_wpid ) {
2880 $website = MainWP_DB::Instance()->getWebsiteById( $current_wpid );
2881 $websites = array( $website );
2882 } else {
2883 $is_staging = 'no';
2884 if ( isset( $_GET[ 'page' ] ) ) {
2885 // for manage sites page
2886 if ( ('managesites' == $_GET[ 'page' ]) && !isset( $_GET[ 'id' ] ) && !isset( $_GET[ 'do' ] ) && !isset( $_GET[ 'dashboard' ] ) ) {
2887 $filter_group = get_option( 'mainwp_managesites_filter_group' );
2888 if ( $filter_group ) {
2889 $staging_group = get_option( 'mainwp_stagingsites_group_id' );
2890 if ( $staging_group == $filter_group ) {
2891 $is_staging = 'yes';
2892 }
2893 }
2894 } else if ( 'UpdatesManage' == $_GET[ 'page' ] || 'mainwp_tab' == $_GET[ 'page' ] ) { // for Updates and Overview page
2895 $staging_enabled = apply_filters( 'mainwp-extension-available-check', 'mainwp-staging-extension' );
2896 if ( $staging_enabled ) {
2897 $staging_view = get_user_option( 'mainwp_staging_options_updates_view' ) == 'staging' ? true : false;
2898 if ( $staging_view ) {
2899 $is_staging = 'yes';
2900 }
2901 }
2902 }
2903 }
2904 $websites = MainWP_DB::Instance()->query( MainWP_DB::Instance()->getSQLWebsitesForCurrentUser( false, null, 'wp_sync.dtsSync DESC, wp.url ASC', false, false, null, false, array(), $is_staging ) );
2905 }
2906
2907 ob_start();
2908
2909 $cntr = 0;
2910 if ( is_array( $websites ) ) {
2911 for ( $i = 0; $i < count( $websites ); $i ++ ) {
2912 $website = $websites[ $i ];
2913 if ( $website->sync_errors == '' ) {
2914 $cntr ++;
2915 echo '<input type="hidden" name="dashboard_wp_ids[]" class="dashboard_wp_id" value="' . $website->id . '" />';
2916 }
2917 }
2918 } else if ( $websites !== false ) {
2919 while ( $website = @MainWP_DB::fetch_object( $websites ) ) {
2920 if ( $website->sync_errors == '' ) {
2921 $cntr ++;
2922 echo '<input type="hidden" name="dashboard_wp_ids[]" class="dashboard_wp_id" value="' . $website->id . '" />';
2923 }
2924 }
2925 }
2926
2927 // to support processes at mainwp footer
2928 do_action('mainwp_admin_footer');
2929 ?>
2930 <div class="ui longer modal" id="mainwp-sync-sites-modal">
2931 <div class="header"><?php esc_html_e( 'Data Synchronization', 'mainwp' ); ?></div>
2932 <div class="ui green progress mainwp-modal-progress">
2933 <div class="bar"><div class="progress"></div></div>
2934 <div class="label"></div>
2935 </div>
2936 <div class="scrolling content mainwp-modal-content">
2937 <div class="ui middle aligned divided selection list" id="sync-sites-status">
2938 <?php
2939 if ( is_array( $websites ) ) {
2940 for ( $i = 0; $i < count( $websites ); $i ++ ) {
2941 $website = $websites[ $i ];
2942 if ( $website->sync_errors == '' ) { ?>
2943 <div class="item">
2944 <div class="right floated content">
2945 <div class="sync-site-status" niceurl="<?php echo MainWP_Utility::getNiceURL( $website->url ); ?>" siteid="<?php echo $website->id; ?>"><i class="clock outline icon"></i></div>
2946 </div>
2947 <div class="content"><?php echo MainWP_Utility::getNiceURL( $website->url ); ?></div>
2948 </div>
2949 <?php
2950 } else {
2951 ?>
2952 <div class="item disconnected-site">
2953 <div class="right floated content">
2954 <div class="sync-site-status" niceurl="<?php echo MainWP_Utility::getNiceURL( $website->url ); ?>" siteid="<?php echo $website->id; ?>"><i class="exclamation red icon"></i></div>
2955 </div>
2956 <div class="content"><?php echo MainWP_Utility::getNiceURL( $website->url ); ?></div>
2957 </div>
2958 <?php
2959 }
2960 }
2961 } else {
2962 @MainWP_DB::data_seek( $websites, 0 );
2963 while ( $website = @MainWP_DB::fetch_object( $websites ) ) {
2964 if ( $website->sync_errors == '' ) { ?>
2965 <div class="item">
2966 <div class="right floated content">
2967 <div class="sync-site-status" niceurl="<?php echo MainWP_Utility::getNiceURL( $website->url ); ?>" siteid="<?php echo $website->id; ?>"><i class="clock outline icon"></i></div>
2968 </div>
2969 <div class="content"><?php echo MainWP_Utility::getNiceURL( $website->url ); ?></div>
2970 </div>
2971 <?php
2972 } else {
2973 ?>
2974 <div class="item disconnected-site">
2975 <div class="right floated content">
2976 <div class="sync-site-status" niceurl="<?php echo MainWP_Utility::getNiceURL( $website->url ); ?>" siteid="<?php echo $website->id; ?>"><i class="exclamation red icon"></i></div>
2977 </div>
2978 <div class="content"><?php echo MainWP_Utility::getNiceURL( $website->url ); ?></div>
2979 </div>
2980 <?php
2981 }
2982 }
2983 } ?>
2984 </div>
2985 </div>
2986 <div class="actions mainwp-modal-actions">
2987 <div class="mainwp-modal-close ui cancel button"><?php esc_html_e( 'Close', 'mainwp' ); ?></div>
2988 </div>
2989 </div>
2990
2991 <div class="ui tiny modal" id="mainwp-modal-confirm">
2992 <div class="header"><?php esc_html_e( 'Confirmation', 'mainwp' ); ?></div>
2993 <div class="content">
2994 <div class="content-massage"></div>
2995 <div class="ui mini yellow message hidden update-confirm-notice" ><?php echo sprintf( __( 'To disable update confirmations, go to the %sSettings%s page and disable the "Disable update confirmations" option', 'mainwp' ), '<a href="admin.php?page=Settings">', '</a>' ); ?></div>
2996 </div>
2997 <div class="actions">
2998 <div class="ui cancel button"><?php _e('Cancel', 'mainwp'); ?></div>
2999 <div class="ui positive right labeled icon button"><?php _e('Yes', 'mainwp'); ?><i class="checkmark icon"></i></div>
3000 </div>
3001 </div>
3002
3003 <?php
3004 $newOutput = ob_get_clean();
3005
3006 if (true === $echo) {
3007 echo $newOutput;
3008 } else {
3009 return $newOutput;
3010 }
3011 }
3012
3013 function new_menus() {
3014 if ( MainWP_Utility::isAdmin() ) {
3015 //Adding the page to manage your added sites/groups
3016 //The first page which will display the post area etc..
3017 if ( !MainWP_Menu::is_disable_menu_item( 2, 'UpdatesManage' ) ) {
3018 MainWP_Updates::initMenu();
3019 }
3020 if ( !MainWP_Menu::is_disable_menu_item( 2, 'managesites' ) ) {
3021 MainWP_Manage_Sites::initMenu();
3022 }
3023 if ( !MainWP_Menu::is_disable_menu_item( 2, 'PostBulkManage' ) ) {
3024 MainWP_Post::initMenu();
3025 }
3026 if ( !MainWP_Menu::is_disable_menu_item( 2, 'PageBulkManage' ) ) {
3027 MainWP_Page::initMenu();
3028 }
3029 if ( !MainWP_Menu::is_disable_menu_item( 2, 'ThemesManage' ) ) {
3030 MainWP_Themes::initMenu();
3031 }
3032 if ( !MainWP_Menu::is_disable_menu_item( 2, 'PluginsManage' ) ) {
3033 MainWP_Plugins::initMenu();
3034 }
3035 if ( !MainWP_Menu::is_disable_menu_item( 2, 'UserBulkManage' ) ) {
3036 MainWP_User::initMenu();
3037 }
3038 if ( !MainWP_Menu::is_disable_menu_item( 2, 'ManageBackups' ) ) {
3039 MainWP_Manage_Backups::initMenu();
3040 }
3041 if ( !MainWP_Menu::is_disable_menu_item( 3, 'UpdateAdminPasswords' ) ) {
3042 MainWP_Bulk_Update_Admin_Passwords::initMenu();
3043 }
3044 if ( !MainWP_Menu::is_disable_menu_item( 3, 'ManageGroups' ) ) {
3045 MainWP_Manage_Groups::initMenu();
3046 }
3047 if ( !MainWP_Menu::is_disable_menu_item( 2, 'Settings' ) ) {
3048 MainWP_Settings::initMenu();
3049 }
3050 MainWP_Extensions::initMenu(); //check disable menu item in the function
3051 do_action( 'mainwp_admin_menu' );
3052
3053 if ( !MainWP_Menu::is_disable_menu_item( 2, 'ServerInformation' ) ) {
3054 MainWP_Server_Information::initMenu();
3055 }
3056
3057 MainWP_About::initMenu();
3058 MainWP_Child_Scan::initMenu();
3059 }
3060 }
3061
3062 //On activation install the database
3063 function activation() {
3064 //delete_option( 'mainwp_requests' );
3065 MainWP_DB::Instance()->update();
3066 MainWP_DB::Instance()->install();
3067
3068 //Redirect to settings page
3069 MainWP_Utility::update_option( 'mainwp_activated', 'yes' );
3070 }
3071
3072 function deactivation() {
3073 update_option('mainwp_extensions_all_activation_cached', ''); // clear cached of all activations to reload for next loading
3074 }
3075
3076 //On update update the database
3077 function update() {
3078 MainWP_DB::Instance()->update();
3079 MainWP_DB::Instance()->install();
3080 }
3081
3082 function apply_filter( $filter, $value = array() ) {
3083 $output = apply_filters( $filter, $value );
3084
3085 if ( !is_array( $output ) ) {
3086 return array();
3087 }
3088
3089 for ( $i = 0; $i < count( $output ); $i ++ ) {
3090 if ( !isset( $output[ $i ][ 'plugin' ] ) || !isset( $output[ $i ][ 'key' ] ) ) {
3091 unset( $output[ $i ] );
3092 continue;
3093 }
3094
3095 if ( !MainWP_Extensions::hookVerify( $output[ $i ][ 'plugin' ], $output[ $i ][ 'key' ] ) ) {
3096 unset( $output[ $i ] );
3097 continue;
3098 }
3099 }
3100
3101 return $output;
3102 }
3103
3104 public function isSingleUser() {
3105 return true;
3106 }
3107
3108 public function isMultiUser() {
3109 return !$this->isSingleUser();
3110 }
3111
3112 }
3113