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
← All changes | class/class-mainwp-system.php +2898 -1155 5.14.0.5 View file →
@@ -1,1369 +1,3112 @@
1 1 <?php
2 -/**
3 - * MainWP System.
4 - *
5 - * @package MainWP/Dashboard
6 - */
7 2
8 -namespace MainWP\Dashboard;
3 +//ini_set( 'display_errors', true );
4 +//error_reporting( E_ALL | E_STRICT );
9 5
10 -// phpcs:disable Generic.Metrics.CyclomaticComplexity -- complexity.
6 +@ini_set( 'display_errors', false );
7 +@error_reporting( 0 );
11 8
12 -const MAINWP_VIEW_PER_SITE = 1;
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;
13 15 const MAINWP_VIEW_PER_PLUGIN_THEME = 0;
14 -const MAINWP_VIEW_PER_GROUP = 2;
16 +const MAINWP_VIEW_PER_GROUP = 2;
15 17
16 -// phpcs:disable WordPress.WP.AlternativeFunctions -- for custom read/write file.
18 +class MainWP_System {
17 19
18 -/**
19 - * Class MainWP_System
20 - *
21 - * @package MainWP\Dashboard
22 - */
23 -class MainWP_System { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
20 + public static $version = '4.0.5';
21 + //Singleton
22 + private static $instance = null;
23 + private $upgradeVersionInfo = null;
24 24
25 - /**
26 - * Public static variable to hold the current plugin version.
27 - *
28 - * @var string Current plugin version.
29 - */
30 - public static $version = '5.1'; // NOSONAR.
25 + public $metaboxes;
31 26
32 - /**
33 - * Private static variable to hold the single instance of the class.
34 - *
35 - * @var mixed Default null
36 - */
37 - private static $instance = null;
27 + /**
28 + * The plugin current version
29 + * @var string
30 + */
31 + private $current_version = null;
38 32
39 - /**
40 - * Public variable to hold the Metaboxes instance.
41 - *
42 - * @var object Metaboxes.
43 - */
44 - public $metaboxes;
33 + /**
34 + * Plugin Slug (plugin_directory/plugin_file.php)
35 + * @var string
36 + */
37 + private $plugin_slug;
45 38
46 - /**
47 - * Private variable to hold the current version.
48 - *
49 - * @var string The plugin current version.
50 - */
51 - private $current_version = null;
39 + /**
40 + * Plugin name (plugin_file)
41 + * @var string
42 + */
43 + public $slug;
52 44
45 + /**
46 + * @static
47 + * @return MainWP_System
48 + */
49 + static function Instance() {
50 + return self::$instance;
51 + }
53 52
54 - /**
55 - * Private variable to hold the check update version number.
56 - *
57 - * @var string The plugin current update version.
58 - */
59 - private $check_ver_update = '0.0.5';
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 60
61 - /**
62 - * Private variable to hold the plugin slug (mainwp/mainwp.php)
63 - *
64 - * @var string Plugin slug.
65 - */
66 - private $plugin_slug;
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 + }
67 80
68 - /**
69 - * Method instance()
70 - *
71 - * Create a public static instance.
72 - *
73 - * @static
74 - * @return MainWP_System
75 - */
76 - public static function instance() {
77 - return static::$instance;
78 - }
81 + MainWP_Utility::update_option( 'mainwp_plugin_version', $this->current_version );
82 + }
79 83
80 - /**
81 - * MainWP_System constructor.
82 - *
83 - * Runs any time class is called.
84 - *
85 - * @param string $mainwp_plugin_file Plugn slug.
86 - *
87 - * @uses \MainWP\Dashboard\MainWP_Bulk_Post
88 - * @uses \MainWP\Dashboard\MainWP_Hooks
89 - * @uses \MainWP\Dashboard\MainWP_Menu::get_class_name()
90 - * @uses \MainWP\Dashboard\MainWP_Menu
91 - * @uses \MainWP\Dashboard\MainWP_Meta_Boxes
92 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::init_cron_jobs()
93 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs
94 - * @uses \MainWP\Dashboard\MainWP_System_Handler
95 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_class_name()
96 - * @uses \MainWP\Dashboard\MainWP_System_View::get_class_name()
97 - * @uses \MainWP\Dashboard\MainWP_UI::get_class_name()
98 - * @uses \MainWP\Dashboard\MainWP_WP_CLI_Command::init()
99 - * @uses \MainWP\Dashboard\MainWP_Updates_Overview::init()
100 - * @uses \MainWP\Dashboard\MainWP_Extensions::init()
101 - * @uses \MainWP\Dashboard\MainWP_Extensions_Handler::get_class_name()
102 - * @uses \MainWP\Dashboard\MainWP_Install_Bulk::init()
103 - * @uses \MainWP\Dashboard\MainWP_Manage_Backups::init()
104 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::init()
105 - * @uses \MainWP\Dashboard\MainWP_Overview::get()
106 - * @uses \MainWP\Dashboard\MainWP_Page::init()
107 - * @uses \MainWP\Dashboard\MainWP_Plugins::init()
108 - * @uses \MainWP\Dashboard\MainWP_Post::init()
109 - * @uses \MainWP\Dashboard\MainWP_Settings::init()
110 - * @uses \MainWP\Dashboard\MainWP_Themes::init()
111 - * @uses \MainWP\Dashboard\MainWP_Updates::init()
112 - * @uses \MainWP\Dashboard\MainWP_User::init()
113 - * @uses \MainWP\Dashboard\MainWP_Updates::init()
114 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
115 - */
116 - public function __construct( $mainwp_plugin_file ) { //phpcs:ignore -- NOSONAR - complex.
117 - static::$instance = $this;
84 + if ( !defined( 'MAINWP_VERSION' ) ) {
85 + define( 'MAINWP_VERSION', $this->current_version );
86 + }
118 87
119 - MainWP_Execution_Helper::instance()->init_exec_time();
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 + }
120 93
121 - $loader = new MainWP_Includes();
122 - $loader->includes();
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 + }
123 101
124 - MainWP_Keys_Manager::auto_load_files();
102 + MainWP_Extensions::init();
103 + add_action( 'parse_request', array( &$this, 'parse_request' ) );
104 + add_action( 'init', array( &$this, 'localization' ) );
125 105
126 - $this->load_all_options();
106 + // define the alternative API for updating checking
107 + add_filter( 'site_transient_update_plugins', array( &$this, 'check_update_custom' ) );
127 108
128 - $this->update_install();
129 - $this->plugin_slug = plugin_basename( $mainwp_plugin_file );
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 );
130 112
131 - do_action( 'mainwp_system_init' );
113 + $this->metaboxes = new MainWP_Meta_Boxes();
132 114
133 - // includes rest api work.
134 - require_once 'class-mainwp-rest-api.php'; // NOSONAR - WP compatible.
135 - Rest_Api::instance()->init();
115 + MainWP_Overview::get(); //init main dashboard
136 116
137 - if ( is_admin() ) {
138 - include_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'plugin.php'; // NOSONAR - WP compatible.
139 - $pluginData = get_plugin_data( $mainwp_plugin_file, true, false ); // to fix issue of user language setting.
140 - $this->current_version = $pluginData['Version'];
141 - $currentVersion = get_option( 'mainwp_plugin_version' );
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' ) );
142 123
143 - if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '4.0', '<' ) && version_compare( $this->current_version, '4.0', '>=' ) ) {
144 - add_action( 'mainwp_after_header', array( MainWP_System_View::get_class_name(), 'mainwp_4_update_notice' ) );
145 - }
124 + //Change footer
125 + add_filter( 'admin_footer', array( &$this, 'admin_footer' ), 15 );
146 126
147 - if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '5.0', '<' ) && version_compare( $this->current_version, '5.0', '>=' ) ) {
148 - add_action( 'mainwp_after_header', array( MainWP_System_View::get_class_name(), 'mainwp_ver5_update_notice' ) );
149 - }
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' ) );
150 131
151 - if ( ! empty( $currentVersion ) && version_compare( $currentVersion, '5.0.2', '<' ) && version_compare( $this->current_version, '5.0.2', '>=' ) ) {
152 - add_action( 'mainwp_after_header', array( MainWP_System_View::get_class_name(), 'mainwp_ver502_update_notice' ) );
153 - }
132 + //Add body class
133 + add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
154 134
155 - MainWP_Utility::update_option( 'mainwp_plugin_version', $this->current_version );
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;
156 442 }
157 443
158 - if ( ! defined( 'MAINWP_VERSION' ) ) {
444 + if ( isset( $extensions[ $plugin_slug ][ 'activated_key' ] ) && 'Activated' == $extensions[ $plugin_slug ][ 'activated_key' ] ) {
445 + return;
446 + }
159 447
160 - /**
161 - * Defines MainWP Version.
162 - *
163 - * @const ( string )
164 - * @source https://code-reference.mainwp.com/classes/MainWP.Dashboard.MainWP_System.html
165 - */
166 - define( 'MAINWP_VERSION', $this->current_version );
167 - }
448 + $slug = basename( $plugin_slug, ".php" );
168 449
169 - if ( get_option( 'mainwp_setting_demo_mode_enabled' ) && ! defined( 'MAINWP_DEMO_MODE' ) ) {
170 - define( 'MAINWP_DEMO_MODE', true );
171 - }
172 450
173 - $ssl_api_verifyhost = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( 1 === (int) get_option( 'mainwp_api_sslVerifyCertificate' ) ) ) ? 1 : 0;
174 - if ( empty( $ssl_api_verifyhost ) ) {
175 - add_filter(
176 - 'http_request_args',
177 - array(
178 - MainWP_Extensions_Handler::get_class_name(),
179 - 'no_ssl_filter_extension_upgrade',
180 - ),
181 - 99,
182 - 2
183 - );
184 - }
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 + }
185 457
186 - MainWP_Extensions::init();
187 - MainWP_Extensions_Groups::init();
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 + }
188 471
189 - $systemHandler = MainWP_System_Handler::instance();
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 + }
190 477
191 - add_action( 'plugins_loaded', array( &$this, 'localization' ) );
192 - add_filter( 'site_transient_update_plugins', array( $systemHandler, 'check_update_custom' ) );
193 - add_filter( 'pre_set_site_transient_update_plugins', array( $systemHandler, 'pre_check_update_custom' ) );
194 - add_filter( 'plugins_api', array( $systemHandler, 'plugins_api_extension_info' ), 10, 3 );
195 - add_filter( 'plugins_api_result', array( $systemHandler, 'plugins_api_wp_plugins_api_result' ), 10, 3 );
478 + public function localization() {
479 + load_plugin_textdomain( 'mainwp', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
480 + }
196 481
197 - $this->metaboxes = new MainWP_Meta_Boxes();
482 + public function activated_check() {
483 + return $this->getVersion();
484 + }
198 485
199 - MainWP_Overview::get();
200 - MainWP_Client_Overview::instance();
486 + public function activated_sub_check() {
487 + return array( 'result' => MAINWP_API_VALID );
488 + }
201 489
202 - MainWP_Manage_Sites::init();
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 + }
203 501
204 - MainWP_Hooks::get_instance();
205 - MainWP_Menu::get_instance();
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 + }
206 507
207 - add_action( 'admin_menu', array( MainWP_Menu::get_class_name(), 'init_mainwp_menus' ) );
208 - add_filter( 'admin_footer', array( &$this, 'admin_footer' ), 15 );
209 - add_action( 'admin_head', array( MainWP_System_View::get_class_name(), 'admin_head' ) );
210 - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_styles' ) );
211 - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
212 - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts_fix_conflict' ), 9 );
213 - add_action( 'admin_body_class', array( MainWP_System_View::get_class_name(), 'admin_body_class' ) );
508 + $current_options = get_option( 'mainwp_showhide_events_notice' );
509 + if ( !is_array( $current_options ) ) {
510 + $current_options = array();
511 + }
214 512
215 - MainWP_Bulk_Post::get_instance();
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 + }
216 525
217 - add_action( 'admin_init', array( &$this, 'admin_init' ), 20 );
218 - add_action( 'admin_init', array( $this, 'hook_admin_update_check' ) );
219 - add_action( 'after_setup_theme', array( &$this, 'after_setup_theme' ) );
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 + }
220 539
221 - add_action( 'init', array( &$this, 'parse_init' ) );
222 - add_action( 'init', array( &$this, 'init' ), 9999 );
223 - add_action( 'admin_init', array( $this, 'admin_redirects' ) );
224 - add_action( 'current_screen', array( &$this, 'current_screen_redirects' ), 15 );
225 - add_filter( 'plugin_action_links', array( $this, 'hook_plugin_action_links' ), 10, 4 );
226 - add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
227 - add_action( 'admin_print_styles', array( MainWP_System_View::get_class_name(), 'admin_print_styles' ) );
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 + }
228 549
229 - add_action( 'wp_logout', array( &$this, 'clear_sessions' ) );
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 + }
230 565
231 - MainWP_Install_Bulk::init();
566 + $display_request1 = $display_request2 = false;
232 567
233 - MainWP_System_Cron_Jobs::instance()->init_cron_jobs();
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 + }
234 581
235 - add_action( 'mainwp_after_header', array( MainWP_System_View::get_class_name(), 'admin_notices' ) );
236 - add_action( 'admin_notices', array( MainWP_System_View::get_class_name(), 'wp_admin_notices' ) );
237 - add_action( 'wp_mail_failed', array( &$this, 'wp_mail_failed' ) );
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 + }
238 596
239 - add_action( 'after_plugin_row', array( MainWP_System_View::get_class_name(), 'after_extensions_plugin_row' ), 10, 3 );
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 + }
240 631
241 - add_filter( 'mainwp-activated-check', array( &$this, 'activated_check' ) ); // @deprecated Use 'mainwp_activated_check' instead.
242 - add_filter( 'mainwp_activated_check', array( &$this, 'activated_check' ) );
243 632
244 - do_action_deprecated( 'mainwp-activated', array(), '4.0.7.2', 'mainwp_activated' ); // @deprecated Use 'mainwp_activated' instead. NOSONAR - not IP.
633 + public function wp_admin_notices() {
634 + global $pagenow;
245 635
246 - /**
247 - * Action: mainwp_activated
248 - *
249 - * Fires upon MainWP plugin activation.
250 - *
251 - * @since Unknown
252 - */
253 - do_action( 'mainwp_activated' );
636 + if ( $pagenow !== 'plugins.php' )
637 + return;
254 638
255 - MainWP_Updates::init();
256 - MainWP_Post::init();
257 - MainWP_Settings::init();
258 - if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
259 - MainWP_Manage_Backups::init();
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
260 648 }
261 - MainWP_Manage_Groups::init();
262 - MainWP_User::init();
263 - MainWP_Page::init();
264 - MainWP_Themes::init();
265 - MainWP_Plugins::init();
266 - MainWP_Updates_Overview::init();
267 - MainWP_Client::init();
268 - MainWP_Rest_Api_Page::init();
269 - MainWP_Non_MainWP_Actions::instance();
270 649
271 - if ( defined( 'WP_CLI' ) && WP_CLI ) {
272 - MainWP_WP_CLI_Command::init();
273 - }
274 - if ( defined( 'DOING_CRON' ) && DOING_CRON && isset( $_GET['mainwp_run'] ) && 'test' === $_GET['mainwp_run'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
275 - add_action( 'init', array( MainWP_System_Cron_Jobs::instance(), 'cron_active' ), PHP_INT_MAX );
276 - }
277 650 }
278 651
279 - /**
280 - * Method get_dashboard_version()
281 - *
282 - * Get dashboard version.
283 - *
284 - * @return string $version Version.
285 - */
286 - public function get_dashboard_version() {
287 - return static::$version;
288 - }
652 + public function getVersion() {
653 + return $this->current_version;
654 + }
289 655
290 - /**
291 - * Method load_all_options()
292 - *
293 - * Load all wp_options data.
294 - *
295 - * @return array $alloptions Array of all options.
296 - */
297 - public function load_all_options() { //phpcs:ignore -- NOSONAR - complex.
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 + }
298 666
299 - /**
300 - * WordPress Database instance.
301 - *
302 - * @global object $wpdb
303 - */
304 - global $wpdb;
667 + $api_slug = dirname( $plugin_slug );
668 + $rslt = MainWP_API_Settings::getUpgradeInformation( $api_slug );
305 669
306 - if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
307 - $alloptions = wp_cache_get( 'alloptions', 'options' );
308 - } else {
309 - $alloptions = false;
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 + }
310 802 }
311 803
312 - if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
313 - $notoptions = wp_cache_get( 'notoptions', 'options' );
314 - } else {
315 - $notoptions = false;
316 - }
804 + return $false;
805 + }
317 806
318 - if ( ! isset( $alloptions['mainwp_db_version'] ) ) {
319 - $suppress = $wpdb->suppress_errors();
320 - $options = array(
321 - 'mainwp_db_version',
322 - 'mainwp_plugin_version',
323 - 'mainwp_upgradeVersionInfo',
324 - 'mainwp_extensions',
325 - 'mainwp_activated',
326 - 'mainwp_api_sslVerifyCertificate',
327 - 'mainwp_automaticDailyUpdate',
328 - 'mainwp_backup_before_upgrade',
329 - 'mainwp_enableLegacyBackupFeature',
330 - 'mainwp_maximumInstallUpdateRequests',
331 - 'mainwp_maximumSyncRequests',
332 - 'mainwp_primaryBackup',
333 - 'mainwp_security',
334 - 'mainwp_use_favicon',
335 - 'mainwp_wp_cron',
336 - 'mainwp_timeDailyUpdate',
337 - 'mainwp_frequencyDailyUpdate',
338 - 'mainwp_delay_autoupdate',
339 - 'mainwp_wpcreport_extension',
340 - 'mainwp_daily_digest_plain_text',
341 - 'mainwp_hide_update_everything',
342 - 'mainwp_disable_update_confirmations',
343 - 'mainwp_settings_show_widgets',
344 - 'mainwp_clients_show_widgets',
345 - 'mainwp_settings_show_manage_sites_columns',
346 - 'mainwp_disableSitesChecking',
347 - 'mainwp_disableSitesHealthMonitoring',
348 - 'mainwp_frequencySitesChecking',
349 - 'mainwp_sitehealthThreshold',
350 - 'mainwp_settings_notification_emails',
351 - 'mainwp_ignore_HTTP_response_status',
352 - 'mainwp_check_http_response',
353 - 'mainwp_extmenu',
354 - 'mainwp_opensslLibLocation',
355 - 'mainwp_notice_wp_mail_failed',
356 - 'mainwp_show_language_updates',
357 - 'mainwp_logger_check_daily',
358 - 'mainwp_site_actions_notification_enable',
359 - 'mainwp_update_check_version',
360 - 'mainwp_setting_demo_mode_enabled',
361 - 'mainwp_log_wait_lasttime',
362 - 'mainwp_updatescheck_start_last_schedule_timestamp',
363 - 'mainwp_cron_license_deactivated_alert_lasttime',
364 - );
807 + function print_digest_lines( $array, $backupChecks = null, $what = 'update' ) {
365 808
366 - $options = apply_filters( 'mainwp_init_load_all_options', $options );
809 + $plain_text = apply_filters( 'mainwp_text_format_email', false );
367 810
368 - $query = "SELECT option_name, option_value FROM $wpdb->options WHERE option_name in (";
369 - foreach ( $options as $option ) {
370 - $query .= "'" . $option . "', ";
371 - }
372 - $query = substr( $query, 0, strlen( $query ) - 2 );
373 - $query .= ")"; // phpcs:ignore -- ignore double quotes auto-correction.
374 - $alloptions_db = $wpdb->get_results( $query ); // phpcs:ignore -- unprepared SQL ok.
375 - $wpdb->suppress_errors( $suppress );
376 - if ( ! is_array( $alloptions ) ) {
377 - $alloptions = array();
378 - }
379 - if ( is_array( $alloptions_db ) ) {
380 - foreach ( (array) $alloptions_db as $o ) {
381 - $alloptions[ $o->option_name ] = $o->option_value;
382 - unset( $options[ array_search( $o->option_name, $options ) ] );
811 + $output = '';
812 +
813 + if ($what == 'disc_sites') {
814 + if ( $plain_text ) {
815 + foreach ( $array as $url ) {
816 + $output .= $url . "\r\n";
383 817 }
384 - if ( ! is_array( $notoptions ) ) {
385 - $notoptions = array();
818 + } else {
819 + foreach ( $array as $url ) {
820 + $output .= '<li>' . $url . '</li>' . "\n";
386 821 }
387 - foreach ( $options as $option ) {
388 - $notoptions[ $option ] = true;
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";
389 833 }
390 - if ( ! defined( 'WP_INSTALLING' ) || ! is_multisite() ) {
391 - wp_cache_set( 'alloptions', $alloptions, 'options' );
392 - wp_cache_set( 'notoptions', $notoptions, 'options' );
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";
393 841 }
394 842 }
843 +
395 844 }
396 845
397 - return $alloptions;
846 + return $output;
398 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 + }
399 876
400 - /**
401 - * Method localization()
402 - *
403 - * Loads plugin language files.
404 - */
405 - public function localization() {
406 - $load = apply_filters( 'mainwp_load_text_domain', true );
407 - if ( $load ) {
408 - load_plugin_textdomain( 'mainwp', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' );
409 - }
410 - }
877 + function mainwp_cronupdatescheck_action() {
878 + MainWP_Logger::Instance()->info( 'CRON :: updates check' );
411 879
412 - /**
413 - * Method wp_mail_failed()
414 - *
415 - * Check if there has been a wp mail failer.
416 - *
417 - * @param string $error Array of error messages.
418 - *
419 - * @uses \MainWP\Dashboard\MainWP_Logger::debug()
420 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
421 - */
422 - public function wp_mail_failed( $error ) {
423 - $mail_failed = get_option( 'mainwp_notice_wp_mail_failed' );
424 - if ( is_object( $error ) && empty( $mail_failed ) ) {
425 - MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'yes' );
426 - $er = $error->get_error_message();
427 - if ( ! empty( $er ) ) {
428 - MainWP_Logger::instance()->debug( 'Error :: wp_mail :: [error=' . $er . ']' );
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;
429 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";
430 987 }
431 - }
432 988
433 - /**
434 - * Method get_version()
435 - *
436 - * Get current plugin version.
437 - *
438 - * @return string Current plugin version.
439 - */
440 - public function get_version() {
441 - return $this->current_version;
442 - }
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 + }
443 997
444 - /**
445 - * Method mainwp_cronpingchilds_action()
446 - *
447 - * Run cron ping child's action.
448 - *
449 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_ping_childs()
450 - */
451 - public function mainwp_cronpingchilds_action() {
452 - MainWP_System_Cron_Jobs::instance()->cron_ping_childs();
453 - }
998 + update_option( 'mainwp_last_synced_all_sites', time() );
999 + MainWP_Logger::Instance()->debug( 'CRON :: updates check :: got to the mail part' );
454 1000
455 - /**
456 - * Method mainwp_cronbackups_continue_action()
457 - *
458 - * Run cron backups continue action.
459 - *
460 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_backups_continue()
461 - */
462 - public function mainwp_cronbackups_continue_action() {
463 - MainWP_System_Cron_Jobs::instance()->cron_backups_continue();
464 - }
1001 + //Send the email & update all to this time!
1002 + $mail = '';
1003 + $sendMail = false;
465 1004
466 - /**
467 - * Method mainwp_cronbackups_action()
468 - *
469 - * Run cron backups action.
470 - *
471 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_backups()
472 - */
473 - public function mainwp_cronbackups_action() {
474 - MainWP_System_Cron_Jobs::instance()->cron_backups();
475 - }
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 + }
476 1012
477 - /**
478 - * Method mainwp_cronreconnect_action()
479 - *
480 - * Run cron stats action.
481 - *
482 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_reconnect()
483 - */
484 - public function mainwp_cronreconnect_action() {
485 - MainWP_System_Cron_Jobs::instance()->cron_reconnect();
486 - }
487 1013
488 - /**
489 - * Method mainwp_cronupdatescheck_action()
490 - *
491 - * Run cron updates check action.
492 - *
493 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_updates_check()
494 - */
495 - public function mainwp_cronupdatescheck_action() {
496 - MainWP_System_Cron_Jobs::instance()->cron_updates_check();
497 - }
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 + }
498 1030
499 - /**
500 - * Method mainwp_crondeactivatedlicensesalert_action()
501 - *
502 - * Run cron activated licenses alert action.
503 - */
504 - public function mainwp_crondeactivatedlicensesalert_action() {
505 - MainWP_System_Cron_Jobs::instance()->cron_deactivated_licenses_alert();
506 - }
1031 + if ( !empty( $plugin_automaticDailyUpdate ) ) {
1032 + if ( ( count( $pluginsNewUpdate ) != 0 ) || ( count( $pluginsToUpdate ) != 0 ) || ( count( $notTrustedPluginsNewUpdate ) != 0 ) || ( count( $notTrustedPluginsToUpdate ) != 0 )
1033 + ) {
1034 + $sendMail = true;
507 1035
508 - /**
509 - * Method mainwp_croncheckstatus_action()
510 - *
511 - * Run cron check sites status action.
512 - *
513 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_check_websites_status()
514 - */
515 - public function mainwp_croncheckstatus_action() {
516 - MainWP_System_Cron_Jobs::instance()->cron_check_websites_status();
517 - }
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 );
518 1041
519 - /**
520 - * Method mainwp_cronchecksitehealth_action()
521 - *
522 - * Run cron check sites health action.
523 - *
524 - * @uses \MainWP\Dashboard\MainWP_System_Cron_Jobs::cron_check_websites_health()
525 - */
526 - public function mainwp_cronchecksitehealth_action() {
527 - MainWP_System_Cron_Jobs::instance()->cron_check_websites_health();
528 - }
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 + }
529 1055
530 - /**
531 - * Method is_mainwp_pages()
532 - *
533 - * Get the current page and check it for "mainwp_".
534 - *
535 - * @return boolean ture|false.
536 - */
537 - public static function is_mainwp_pages() {
538 - $screen = get_current_screen();
539 - if ( $screen && strpos( $screen->base, 'mainwp_' ) !== false && strpos( $screen->base, 'mainwp_child_tab' ) === false ) {
540 - return true;
541 - }
542 1056
543 - return false;
544 - }
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 + }
545 1073
546 - /**
547 - * Method is_mainwp_site_page()
548 - *
549 - * Checks if the current page is under the site mode.
550 - *
551 - * @return boolean ture|false.
552 - */
553 - public static function is_mainwp_site_page() {
554 - //phpcs:disable WordPress.Security.NonceVerification.Recommended
555 - if ( isset( $_GET['page'] ) && 'CostTrackerAdd' !== $_GET['page'] && ( ( ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) || ( isset( $_GET['dashboard'] ) && ! empty( $_GET['dashboard'] ) ) || ( isset( $_GET['updateid'] ) && ! empty( $_GET['updateid'] ) ) || ( isset( $_GET['emailsettingsid'] ) && ! empty( $_GET['emailsettingsid'] ) ) || ( isset( $_GET['scanid'] ) && ! empty( $_GET['scanid'] ) ) ) || ( 'ServerInformation' === $_GET['page'] || 'ServerInformationCron' === $_GET['page'] || 'ErrorLog' === $_GET['page'] || 'ActionLogs' === $_GET['page'] || 'PluginPrivacy' === $_GET['page'] || 'Settings' === $_GET['page'] || 'SettingsAdvanced' === $_GET['page'] || 'SettingsEmail' === $_GET['page'] || 'MainWPTools' === $_GET['page'] || 'SettingsInsights' === $_GET['page'] || 'SettingsApiBackups' === $_GET['page'] ) ) ) {
556 - return true;
557 - }
558 - //phpcs:enable
559 - return false;
560 - }
1074 + if ( !empty( $theme_automaticDailyUpdate ) ) {
1075 + if ( ( count( $themesNewUpdate ) != 0 ) || ( count( $themesToUpdate ) != 0 ) || ( count( $notTrustedThemesNewUpdate ) != 0 ) || ( count( $notTrustedThemesToUpdate ) != 0 )
1076 + ) {
1077 + $sendMail = true;
561 1078
562 - /**
563 - * Method init()
564 - *
565 - * Instantiate Plugin.
566 - */
567 - public function init() { //phpcs:ignore -- NOSONAR - complex.
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 );
568 1084
569 - /**
570 - * MainWP disabled menu items array.
571 - *
572 - * @global object $_mainwp_disable_menus_items
573 - */
574 - global $_mainwp_disable_menus_items;
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 + }
575 1096
576 - $_mainwp_disable_menus_items = apply_filters( 'mainwp_disablemenuitems', $_mainwp_disable_menus_items );
1097 + }
1098 + }
577 1099
578 - /**
579 - * Filter: mainwp_main_menu_disable_menu_items
580 - *
581 - * Filters disabled MainWP navigation items.
582 - *
583 - * @since Unknown
584 - */
585 - $_mainwp_disable_menus_items = apply_filters( 'mainwp_main_menu_disable_menu_items', $_mainwp_disable_menus_items );
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 + }
586 1116
587 - if ( ! function_exists( 'MainWP\Dashboard\mainwp_current_user_have_right' ) ) {
1117 + if ( !empty( $mainwpAutomaticDailyUpdate ) ) {
1118 + if ( ( count( $coreNewUpdate ) != 0 ) || ( count( $coreToUpdate ) != 0 ) || ( count( $ignoredCoreNewUpdate ) != 0 ) || ( count( $ignoredCoreToUpdate ) != 0 ) ) {
1119 + $sendMail = true;
588 1120
589 - /**
590 - * Method mainwp_current_user_have_right()
591 - *
592 - * Check permission level by hook mainwp_currentusercan of Team Control extension.
593 - *
594 - * @param string $cap_type group or type of capabilities.
595 - * @param string $cap capabilities for current user.
596 - *
597 - * @return bool true|false
598 - *
599 - * @uses \MainWP\Dashboard\MainWP_System_Handler::handle_settings_post()
600 - */
601 - function mainwp_current_user_have_right( $cap_type = '', $cap = '' ) {
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 );
602 1126
603 - /**
604 - * Current user global.
605 - *
606 - * @global string
607 - */
608 - global $current_user;
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 + }
609 1138
610 - if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
611 - return true;
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 + }
612 1157 }
613 1158
614 - if ( defined( 'WP_CLI' ) && WP_CLI ) {
615 - return true;
616 - }
617 1159
618 - if ( defined( 'MAINWP_REST_API_DOING' ) && MAINWP_REST_API_DOING ) {
619 - return true;
620 - }
1160 + $mail = apply_filters( 'mainwp_daily_digest_content', $mail, $text_format );
621 1161
622 - if ( empty( $current_user ) && ! function_exists( 'wp_get_current_user' ) ) {
623 - require_once ABSPATH . WPINC . '/pluggable.php'; // NOSONAR - WP compatible.
624 - }
1162 + MainWP_Utility::update_option( 'mainwp_automaticUpdate_backupChecks', '' );
625 1163
626 - return apply_filters( 'mainwp_currentusercan', true, $cap_type, $cap );
627 - }
628 - }
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', '' );
629 1167
630 - MainWP_System_Handler::instance()->handle_settings_post();
631 - }
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', '' );
632 1171
633 - /**
634 - * Method parse_init()
635 - *
636 - * Initiate plugin installation & then run the Quick Setup Wizard.
637 - *
638 - * @uses \MainWP\Dashboard\MainWP_System_Handler::upload_file()
639 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir()
640 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system()
641 - * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
642 - * @uses \MainWP\Dashboard\MainWP_Setup_Wizard()
643 - */
644 - public function parse_init() {
645 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
646 - if ( isset( $_GET['mwpdl'] ) && isset( $_GET['sig'] ) ) {
647 - $mwpDir = MainWP_System_Utility::get_mainwp_dir();
648 - $mwpDir = $mwpDir[0];
649 - $mwpdl = isset( $_REQUEST['mwpdl'] ) ? wp_unslash( $_REQUEST['mwpdl'] ) : '';
650 - $file = trailingslashit( $mwpDir ) . rawurldecode( $mwpdl );
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', '' );
651 1175
652 - if ( stristr( rawurldecode( $mwpdl ), '..' ) ) {
653 - return;
654 - }
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', '' );
655 1179
656 - $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system();
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', '' );
657 1183
658 - /**
659 - * WordPress files system object.
660 - *
661 - * @global object
662 - */
663 - global $wp_filesystem;
664 - $sig_value = wp_unslash( $_GET['sig'] );
665 - $valid_sig = MainWP_System_Utility::valid_download_sig( $file, $sig_value );
1184 + $plain_text = apply_filters( 'mainwp_text_format_email', false );
1185 + MainWP_Utility::update_option( 'mainwp_daily_digest_plain_text', $plain_text );
666 1186
667 - if ( ! $valid_sig ) {
668 - MainWP_Logger::instance()->debug( ' :: download :: invalid sig :: ' . base64_decode( $sig_value ) ); // phpcs:ignore -- for debug logging.
669 - }
1187 + MainWP_Utility::update_option( 'mainwp_updatescheck_sites_icon', '' );
670 1188
671 - if ( $hasWPFileSystem && $wp_filesystem->exists( $file ) && $valid_sig ) {
672 - MainWP_System_Handler::instance()->upload_file( $file );
673 - exit();
674 - }
675 - } elseif ( isset( $_GET['page'] ) ) {
676 - if ( MainWP_System_Utility::is_admin() && 'mainwp-setup' === $_GET['page'] ) {
677 - MainWP_Setup_Wizard::get_instance();
678 - }
679 - }
680 - // phpcs:enable
681 - }
1189 + if ( 1 == get_option( 'mainwp_check_http_response', 0 ) ) {
682 1190
683 - /**
684 - * Method after_setup_theme()
685 - *
686 - * After setup theme hook, to support post thumbnails.
687 - */
688 - public function after_setup_theme() {
689 - add_theme_support( 'post-thumbnails' );
690 - }
1191 + $sitesHttpCheckIds = get_option( 'mainwp_automaticUpdate_httpChecks' );
1192 + if ( !is_array( $sitesHttpCheckIds ) ) {
1193 + $sitesHttpCheckIds = array();
1194 + }
691 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 + }
692 1208
693 - /**
694 - * Method hook_admin_update_check()
695 - */
696 - public function hook_admin_update_check() {
697 - $current_ver = $this->check_ver_update;
698 - $saved_ver = get_option( 'mainwp_update_check_version', false );
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 + }
699 1226
700 - if ( false === $saved_ver ) {
701 - return;
702 - }
1227 + $disabled_notification = apply_filters( 'mainwp_updatescheck_disable_notification_mail', false );
1228 + if ( $disabled_notification )
1229 + return;
703 1230
704 - if ( version_compare( $saved_ver, $current_ver, '=' ) ) {
705 - return;
706 - }
1231 + if ( !$sendMail ) {
1232 + MainWP_Logger::Instance()->debug( 'CRON :: updates check :: sendMail is false' );
707 1233
708 - if ( version_compare( $saved_ver, '0.0.4', '<' ) ) {
709 - $sched = wp_next_scheduled( 'mainwp_cronstats_action' );
710 - if ( ! empty( $sched ) ) {
711 - wp_unschedule_event( $sched, 'mainwp_cronstats_action' );
712 - }
713 - global $wpdb;
714 - $wpdb->query( 'DELETE FROM ' . $wpdb->usermeta . ' WHERE meta_key = "mainwp_widgets_sorted_toplevel_page_mainwp_tab" OR meta_key="mainwp_settings_show_widgets"' );//phpcs:ignore -- safe.
715 - }
1234 + return;
1235 + }
716 1236
717 - if ( version_compare( $saved_ver, '0.0.5', '<' ) ) {
718 - $all_ext = MainWP_Extensions_View::get_available_extensions();
719 - foreach ( $all_ext as $slug => $info ) {
720 - $data = MainWP_Api_Manager::instance()->get_activation_info( $slug );
721 - if ( is_array( $data ) && isset( $data['api_key'] ) ) {
722 - $data['api_key'] = '';
723 - $data['activated_key'] = 'Deactivated';
724 - MainWP_Api_Manager::instance()->set_activation_info( $slug, $data );
725 - }
726 - }
727 - update_option( 'mainwp_extensions_all_activation_cached', '' );
728 - }
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 );
729 1262
730 - MainWP_Utility::update_option( 'mainwp_update_check_version', $current_ver );
731 - }
1263 + $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
1264 + if ( !is_array( $decodedIgnoredPlugins ) ) {
1265 + $decodedIgnoredPlugins = array();
1266 + }
732 1267
733 - /**
734 - * Method admin_init()
735 - *
736 - * Do nothing if current user is not an Admin else display the page.
737 - *
738 - * @uses \MainWP\Dashboard\MainWP_Post_Backup_Handler::init()
739 - * @uses \MainWP\Dashboard\MainWP_Post_Extension_Handler::init()
740 - * @uses \MainWP\Dashboard\MainWP_Post_Handler::init()
741 - * @uses \MainWP\Dashboard\MainWP_Post_Plugin_Theme_Handler::init()
742 - * @uses \MainWP\Dashboard\MainWP_Post_Site_Handler::init()
743 - * @uses \MainWP\Dashboard\MainWP_System_Handler::activate_extension()
744 - * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
745 - * @uses \MainWP\Dashboard\MainWP_System_View::get_class_name()
746 - * @uses \MainWP\Dashboard\MainWP_System_View::get_mainwp_translations()
747 - */
748 - public function admin_init() { // phpcs:ignore -- NOSONAR - complex function.
1268 + $trustedPlugins = json_decode( $userExtension->trusted_plugins, true );
1269 + if ( !is_array( $trustedPlugins ) ) {
1270 + $trustedPlugins = array();
1271 + }
749 1272
750 - if ( ! MainWP_System_Utility::is_admin() ) {
751 - return;
752 - }
1273 + $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true );
1274 + if ( !is_array( $decodedIgnoredThemes ) ) {
1275 + $decodedIgnoredThemes = array();
1276 + }
753 1277
754 - add_action( 'mainwp_activate_extention', array( MainWP_System_Handler::instance(), 'activate_extension' ), 10, 2 ); // @deprecated Use 'mainwp_activate_extension' instead.
755 - add_action( 'mainwp_deactivate_extention', array( MainWP_System_Handler::instance(), 'deactivate_extension' ), 10, 3 ); // @deprecated Use 'mainwp_deactivate_extension' instead.
1278 + $trustedThemes = json_decode( $userExtension->trusted_themes, true );
1279 + if ( !is_array( $trustedThemes ) ) {
1280 + $trustedThemes = array();
1281 + }
756 1282
757 - add_action( 'mainwp_activate_extension', array( MainWP_System_Handler::instance(), 'activate_extension' ), 10, 2 );
758 - add_action( 'mainwp_deactivate_extension', array( MainWP_System_Handler::instance(), 'deactivate_extension' ), 10, 3 );
1283 + $coreToUpdateNow = array();
1284 + $coreToUpdate = array();
1285 + $coreNewUpdate = array();
1286 + $ignoredCoreToUpdate = array();
1287 + $ignoredCoreNewUpdate = array();
759 1288
760 - /**
761 - * MainWP use external primary backup method.
762 - *
763 - * @global string
764 - */
765 - global $mainwpUseExternalPrimaryBackupsMethod;
1289 + $pluginsToUpdateNow = array();
1290 + $pluginsToUpdate = array();
1291 + $pluginsNewUpdate = array();
1292 + $notTrustedPluginsToUpdate = array();
1293 + $notTrustedPluginsNewUpdate = array();
766 1294
767 - if ( null === $mainwpUseExternalPrimaryBackupsMethod ) {
768 - $return = '';
1295 + $themesToUpdateNow = array();
1296 + $themesToUpdate = array();
1297 + $themesNewUpdate = array();
1298 + $notTrustedThemesToUpdate = array();
1299 + $notTrustedThemesNewUpdate = array();
769 1300
770 - /*
771 - * @deprecated Use 'mainwp_getprimarybackup_activated' instead.
772 - *
773 - */
774 - $return = apply_filters_deprecated( 'mainwp-getprimarybackup-activated', array( $return ), '4.0.7.2', 'mainwp_getprimarybackup_activated' ); // NOSONAR - not IP.
775 - $mainwpUseExternalPrimaryBackupsMethod = apply_filters( 'mainwp_getprimarybackup_activated', $return );
776 - }
1301 + $allWebsites = array();
777 1302
778 - add_action( 'mainwp_after_header', array( MainWP_System_View::get_class_name(), 'mainwp_warning_notice' ) );
1303 + $infoTrustedText = ' (<span style="color:#008000"><strong>Trusted</strong></span>)';
1304 + $infoNotTrustedText = '';
779 1305
780 - MainWP_Post_Handler::instance()->init();
781 - MainWP_Post_Site_Handler::instance()->init();
782 - MainWP_Post_Plugin_Theme_Handler::instance()->init();
783 - MainWP_Post_Extension_Handler::instance()->init();
784 - MainWP_Post_Backup_Handler::instance()->init();
785 - MainWP_Manage_Sites_Filter_Segment::get_instance()->admin_init();
1306 + foreach ( $websites as $website ) {
1307 + $websiteDecodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
1308 + if ( !is_array( $websiteDecodedIgnoredPlugins ) ) {
1309 + $websiteDecodedIgnoredPlugins = array();
1310 + }
786 1311
787 - /**
788 - * Filter: mainwp_ui_use_wp_calendar
789 - *
790 - * Filters whether default jQuery datepicker should be used to avoid potential problems with Senatic UI Calendar library.
791 - *
792 - * @since 4.0.5
793 - */
794 - $use_wp_datepicker = apply_filters( 'mainwp_ui_use_wp_calendar', false );
795 - if ( $use_wp_datepicker ) {
796 - wp_enqueue_script( 'jquery-ui-datepicker' );
797 - }
798 - wp_enqueue_script( 'jquery-ui-dialog' );
799 - $en_params = array( 'jquery-ui-dialog' );
800 - if ( $use_wp_datepicker ) {
801 - $en_params[] = 'jquery-ui-datepicker';
802 - }
803 - wp_enqueue_script( 'mainwp', MAINWP_PLUGIN_URL . 'assets/js/mainwp.js', $en_params, $this->current_version, true );
804 - $disable_backup_checking = true; // removed option.
805 - $mainwpParams = array(
806 - 'image_url' => MAINWP_PLUGIN_URL . 'assets/images/',
807 - 'backup_before_upgrade' => 1 === (int) get_option( 'mainwp_backup_before_upgrade' ),
808 - 'disable_checkBackupBeforeUpgrade' => $disable_backup_checking,
809 - 'admin_url' => admin_url(),
810 - 'use_wp_datepicker' => $use_wp_datepicker ? 1 : 0,
811 - 'date_format' => get_option( 'date_format' ),
812 - 'time_format' => get_option( 'time_format' ),
813 - 'installedBulkSettingsManager' => is_plugin_active( 'mainwp-bulk-settings-manager/mainwp-bulk-settings-manager.php' ) ? 1 : 0,
814 - 'maximumSyncRequests' => ( get_option( 'mainwp_maximumSyncRequests' ) === false ) ? 8 : get_option( 'mainwp_maximumSyncRequests' ),
815 - 'maximumInstallUpdateRequests' => ( get_option( 'mainwp_maximumInstallUpdateRequests' ) === false ) ? 3 : get_option( 'mainwp_maximumInstallUpdateRequests' ),
816 - '_wpnonce' => wp_create_nonce( 'mainwp-admin-nonce' ),
817 - 'demoMode' => MainWP_Demo_Handle::is_demo_mode() ? 1 : 0,
818 - 'roll_ui_icon' => MainWP_Updates_Helper::get_roll_icon( '', true ),
819 - );
820 - wp_localize_script( 'mainwp', 'mainwpParams', $mainwpParams );
1312 + $websiteDecodedIgnoredThemes = json_decode( $website->ignored_themes, true );
1313 + if ( !is_array( $websiteDecodedIgnoredThemes ) ) {
1314 + $websiteDecodedIgnoredThemes = array();
1315 + }
821 1316
822 - $mainwpTranslations = MainWP_System_View::get_mainwp_translations();
1317 + //Perform check & update
1318 + if ( !MainWP_Sync::syncSite( $website, false, true ) ) {
1319 + $websiteValues = array(
1320 + 'dtsAutomaticSync' => time(),
1321 + );
823 1322
824 - wp_localize_script( 'mainwp', 'mainwpTranslations', $mainwpTranslations );
1323 + MainWP_DB::Instance()->updateWebsiteSyncValues( $website->id, $websiteValues );
825 1324
826 - $security_nonces = MainWP_Post_Handler::instance()->create_security_nonces(); // to fix conflict with Post S M T P plugin.
827 - $nonces_filter = apply_filters( 'mainwp_security_nonces', array() );
828 - if ( is_array( $nonces_filter ) && ! empty( $nonces_filter ) ) {
829 - $security_nonces = array_merge( $security_nonces, $nonces_filter );
830 - }
831 - wp_localize_script( 'mainwp', 'security_nonces', $security_nonces );
1325 + continue;
1326 + }
1327 + $website = MainWP_DB::Instance()->getWebsiteById( $website->id );
832 1328
833 - wp_enqueue_script( 'thickbox' );
834 - wp_enqueue_script( 'user-profile' );
835 - wp_enqueue_style( 'thickbox' );
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 );
836 1332
837 - $load_gridster = false;
1333 + //Run over every update we had last time..
1334 + if ( isset( $websiteCoreUpgrades[ 'current' ] ) ) {
838 1335
839 - // phpcs:disable WordPress.Security.NonceVerification
840 - if ( ( isset( $_GET['page'] ) && ( 'mainwp_tab' === $_GET['page'] || ( 'managesites' === $_GET['page'] && isset( $_GET['dashboard'] ) ) ) ) || ( isset( $_GET['page'] ) && 'ManageClients' === $_GET['page'] && isset( $_GET['client_id'] ) ) || ( isset( $_GET['page'] ) && 0 === strpos( wp_unslash( $_GET['page'] ), 'ManageSites' ) ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- individual page.
841 - $load_gridster = true;
842 - }
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 + }
843 1343
844 - $load_gridster = apply_filters( 'mainwp_enqueue_script_gridster', $load_gridster );
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 + }
845 1365
846 - if ( $load_gridster ) {
847 - wp_enqueue_script( 'gridster', MAINWP_PLUGIN_URL . 'assets/js/gridster/jquery.dsmorse-gridster.js', array(), $this->current_version, true );
848 - wp_enqueue_style( 'gridster', MAINWP_PLUGIN_URL . 'assets/js/gridster/jquery.gridster.min.css', array(), $this->current_version );
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
849 1985 }
850 1986
851 - if ( isset( $_GET['page'] ) && ( 'managesites' === $_GET['page'] || 'MonitoringSites' === $_GET['page'] || 'ManageGroups' === $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
852 - wp_enqueue_script( 'preview', MAINWP_PLUGIN_URL . 'assets/js/preview.js', array(), $this->current_version, true );
853 - wp_enqueue_style( 'preview', MAINWP_PLUGIN_URL . 'assets/css/preview.css', array(), $this->current_version );
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
854 2009 }
855 - // phpcs:enable
856 2010
857 - wp_enqueue_style( 'wp-color-picker' );
858 - wp_enqueue_script( 'wp-color-picker' );
2011 + global $_mainwp_disable_menus_items;
859 2012
860 - $this->init_session();
2013 + $_mainwp_disable_menus_items = apply_filters('mainwp_all_disablemenuitems', $_mainwp_disable_menus_items); // to support developer to debug
2014 +
2015 + }
861 2016
862 - if ( ! current_user_can( 'update_core' ) ) {
863 - remove_action( 'admin_notices', 'update_nag', 3 );
864 - }
865 - }
2017 + function print_admin_styles($value = true) {
2018 + if ( self::isMainWP_Pages() ) {
2019 + return false;
2020 + }
2021 + return $value;
2022 + }
866 2023
867 - /**
868 - * Method hook_plugin_action_links()
869 - *
870 - * @param string[] $actions An array of plugin action links. By default this can include
871 - * 'activate', 'deactivate', and 'delete'. With Multisite active
872 - * this can also include 'network_active' and 'network_only' items.
873 - * @param string $plugin_file Path to the plugin file relative to the plugins directory.
874 - * @param array $plugin_data An array of plugin data. See get_plugin_data()
875 - * and the {@see 'plugin_row_meta'} filter for the list
876 - * of possible values.
877 - */
878 - public function hook_plugin_action_links( $actions, $plugin_file, $plugin_data ) {
879 - unset( $plugin_file ); // not use, compatible.
880 - if ( is_array( $plugin_data ) && ! empty( $plugin_data['slug'] ) && ! empty( $plugin_data['plugin'] ) && 'mainwp' === $plugin_data['slug'] && 'mainwp/mainwp.php' === $plugin_data['plugin'] ) {
881 - $tmp = array(
882 - 'mainwp-setup' => '<a href="admin.php?page=mainwp-setup" id="mainwp-setup" aria-label="' . esc_html__( 'MainWP Dashboard Setup Wizard', 'mainwp' ) . '">' . esc_html__( 'Setup Wizard', 'mainwp' ) . '</a>',
883 - );
884 - if ( is_array( $actions ) ) {
885 - foreach ( $actions as $key => $val ) {
886 - $tmp[ $key ] = $val;
887 -
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;
888 2039 }
2040 + <?php
889 2041 }
890 - return $tmp;
891 - }
892 - return $actions;
893 - }
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 + }
894 2052
895 - /**
896 - * Method current_screen_redirects()
897 - *
898 - * MainWP current screen redirects.
899 - */
900 - public function current_screen_redirects() {
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 + }
901 2058
902 - if ( ( defined( 'DOING_CRON' ) && DOING_CRON ) || defined( 'DOING_AJAX' ) ) {
903 - return;
904 - }
905 - if ( static::is_mainwp_pages() ) {
906 - $quick_setup = get_option( 'mainwp_run_quick_setup', false );
907 - if ( 'yes' === $quick_setup ) {
908 - delete_option( 'mainwp_run_quick_setup' );
909 - wp_safe_redirect( admin_url( 'admin.php?page=mainwp-setup' ) );
910 - exit;
911 - }
912 - }
2059 + return false;
2060 + }
913 2061
914 - if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'mainwp-setup' ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
915 - return;
916 - }
2062 + public static function get_openssl_conf() {
917 2063
918 - if ( static::is_mainwp_pages() && 'yes' === get_option( 'mainwp_activated' ) ) {
919 - delete_option( 'mainwp_activated' );
920 - wp_cache_delete( 'mainwp_activated', 'options' );
921 - wp_cache_delete( 'alloptions', 'options' );
922 - wp_safe_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
923 - exit;
924 - }
925 - }
2064 + if ( defined( 'MAINWP_CRYPT_RSA_OPENSSL_CONFIG' ) ) {
2065 + return MAINWP_CRYPT_RSA_OPENSSL_CONFIG;
2066 + }
926 2067
927 - /**
928 - * Method admin_redirects()
929 - *
930 - * MainWP admin redirects.
931 - */
932 - public function admin_redirects() {
933 - if ( ( defined( 'DOING_CRON' ) && DOING_CRON ) || defined( 'DOING_AJAX' ) ) {
934 - return;
935 - }
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 + }
936 2076
937 - if ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'mainwp-setup' ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
938 - return;
939 - }
2077 + function init() {
940 2078
941 - $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
942 - $_pos = strlen( $request_uri ) - strlen( '/wp-admin/' );
943 - if ( ! empty( $request_uri ) && strpos( $request_uri, '/wp-admin/' ) !== false && strpos( $request_uri, '/wp-admin/' ) === $_pos ) {
944 - $referer = wp_get_referer();
945 - if ( ! empty( $referer ) && strpos( $referer, 'wp-login.php?redirect_to' ) !== false && strpos( $referer, '&reauth=1' ) !== false && mainwp_current_user_have_right( 'dashboard', 'access_global_dashboard' ) ) {
946 - wp_safe_redirect( admin_url( 'admin.php?page=mainwp_tab' ) );
947 - die();
948 - }
949 - }
2079 + global $_mainwp_disable_menus_items;
950 2080
951 - MainWP_Logger::instance()->check_log_daily();
952 - }
2081 + // deprecate hook from 4.0
2082 + $_mainwp_disable_menus_items = apply_filters( 'mainwp_disablemenuitems', $_mainwp_disable_menus_items );
953 2083
954 - /**
955 - * Method init_session()
956 - *
957 - * Check current page & initiate a session.
958 - *
959 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
960 - */
961 - public function init_session() {
962 - $page = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
963 - if ( ! empty( $page ) && in_array(
964 - $page,
965 - array(
966 - 'PostBulkManage',
967 - 'PageBulkManage',
968 - 'PluginsManage',
969 - 'PluginsAutoUpdate',
970 - 'ThemesManage',
971 - 'ThemesAutoUpdate',
972 - 'UserBulkManage',
973 - )
974 - )
975 - ) {
976 - MainWP_Cache::init_session();
977 - }
978 - }
2084 + $_mainwp_disable_menus_items = apply_filters( 'mainwp_main_menu_disable_menu_items', $_mainwp_disable_menus_items );
979 2085
980 - /**
981 - * Method clear_sessions()
982 - *
983 - * When logout clear the sessions to reset.
984 - */
985 - public function clear_sessions() {
986 - MainWP_Cache::init_session();
987 - $clear_cached = array(
988 - 'Post',
989 - 'Page',
990 - );
991 - foreach ( $clear_cached as $ca ) {
992 - MainWP_Cache::init_cache( $ca ); // to re-set cache.
993 - }
994 - }
995 2086
996 - /**
997 - * Method admin_enqueue_scripts()
998 - *
999 - * Enqueue all Mainwp Admin Scripts.
1000 - */
1001 - public function admin_enqueue_scripts() {
2087 + if ( !function_exists( 'mainwp_current_user_can' ) ) {
1002 2088
1003 - $load_cust_scripts = false;
2089 + function mainwp_current_user_can( $cap_type = '', $cap ) {
2090 + global $current_user;
1004 2091
1005 - /**
1006 - * Current pagenow.
1007 - *
1008 - * @global string
1009 - */
1010 - global $pagenow;
2092 + if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
2093 + return true;
2094 + }
1011 2095
1012 - if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
1013 - $load_cust_scripts = true;
1014 - }
2096 + // To fix bug run from wp cli
2097 + if ( defined( 'WP_CLI' ) && WP_CLI ) {
2098 + return true;
2099 + }
1015 2100
1016 - if ( static::is_mainwp_pages() ) {
1017 - wp_enqueue_script( 'jquery-migrate' );
1018 - wp_enqueue_script( 'mainwp-updates', MAINWP_PLUGIN_URL . 'assets/js/mainwp-updates.js', array(), $this->current_version, true );
1019 - wp_enqueue_script( 'mainwp-managesites-action', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-action.js', array(), $this->current_version, true );
1020 - wp_enqueue_script( 'mainwp-managesites-update', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-update.js', array(), $this->current_version, true );
1021 - wp_enqueue_script( 'mainwp-managesites-import', MAINWP_PLUGIN_URL . 'assets/js/mainwp-managesites-import.js', array(), $this->current_version, true );
1022 - wp_enqueue_script( 'mainwp-plugins-themes', MAINWP_PLUGIN_URL . 'assets/js/mainwp-plugins-themes.js', array(), $this->current_version, true );
1023 - wp_enqueue_script( 'mainwp-backups', MAINWP_PLUGIN_URL . 'assets/js/mainwp-backups.js', array(), $this->current_version, true );
1024 - wp_enqueue_script( 'mainwp-posts', MAINWP_PLUGIN_URL . 'assets/js/mainwp-posts.js', array(), $this->current_version, true );
1025 - wp_enqueue_script( 'mainwp-users', MAINWP_PLUGIN_URL . 'assets/js/mainwp-users.js', array(), $this->current_version, true );
1026 - wp_enqueue_script( 'mainwp-clients', MAINWP_PLUGIN_URL . 'assets/js/mainwp-clients.js', array(), $this->current_version, true );
1027 - wp_enqueue_script( 'mainwp-extensions', MAINWP_PLUGIN_URL . 'assets/js/mainwp-extensions.js', array(), $this->current_version, true );
1028 - wp_enqueue_script( 'mainwp-moment', MAINWP_PLUGIN_URL . 'assets/js/moment/moment.min.js', array(), $this->current_version, true );
1029 - wp_enqueue_script( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.js', array( 'jquery' ), $this->current_version, false );
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 + }
1030 2107
1031 - wp_enqueue_script( 'datatables', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.js', array( 'jquery' ), $this->current_version, false );
1032 - wp_enqueue_script( 'datatables-semanticui', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.semanticui.js', array( 'datatables' ), $this->current_version, false );
1033 - wp_enqueue_script( 'datatables-select', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.select.min.js', array( 'datatables' ), $this->current_version, false );
1034 - wp_enqueue_script( 'datatables-add-ons', MAINWP_PLUGIN_URL . 'assets/js/datatables/datatables.min.js', array( 'datatables' ), $this->current_version, false );
2108 + if ( empty( $current_user ) ) {
2109 + return false;
2110 + }
1035 2111
1036 - wp_enqueue_script( 'hamburger', MAINWP_PLUGIN_URL . 'assets/js/hamburger/hamburger.js', array( 'jquery' ), $this->current_version, true );
1037 - wp_enqueue_script( 'datatables-natural-sorting', MAINWP_PLUGIN_URL . 'assets/js/sorting/natural.js', array( 'jquery' ), $this->current_version, true );
2112 + return apply_filters( 'mainwp_currentusercan', true, $cap_type, $cap );
2113 + }
1038 2114
1039 - wp_enqueue_script( 'mainwp-clipboard', MAINWP_PLUGIN_URL . 'assets/js/clipboard/clipboard.min.js', array( 'jquery' ), $this->current_version, true );
1040 - wp_enqueue_script( 'mainwp-rest-api', MAINWP_PLUGIN_URL . 'assets/js/mainwp-rest-api.js', array(), $this->current_version, true );
2115 + }
1041 2116
1042 - if ( isset( $_GET['page'] ) && 'ManageGroups' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1043 - wp_enqueue_script( 'mainwp-groups', MAINWP_PLUGIN_URL . 'assets/js/mainwp-groups.js', array(), $this->current_version, true );
1044 - }
1045 - $enqueue_scripts = apply_filters( 'mainwp_admin_enqueue_scripts', array() );
1046 - if ( is_array( $enqueue_scripts ) && ! empty( $enqueue_scripts['apexcharts'] ) ) {
1047 - wp_enqueue_script(
1048 - 'mainwp-apexcharts',
1049 - MAINWP_PLUGIN_URL . 'assets/js/apexcharts/apexcharts.js',
1050 - array(
1051 - 'jquery',
1052 - 'mainwp',
1053 - ),
1054 - $this->current_version,
1055 - true
1056 - );
1057 - }
1058 - wp_enqueue_script( 'mainwp-dropzone', MAINWP_PLUGIN_URL . 'assets/js/dropzone/dropzone.min.js', array(), $this->current_version, true );
1059 - }
2117 + $this->handleSettingsPost();
1060 2118
1061 - if ( $load_cust_scripts ) {
1062 - wp_enqueue_script( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.js', array( 'jquery' ), $this->current_version, true );
1063 - }
2119 + }
1064 2120
1065 - wp_enqueue_script( 'mainwp-ui', MAINWP_PLUGIN_URL . 'assets/js/mainwp-ui.js', array(), $this->current_version, true );
1066 - wp_enqueue_script( 'mainwp-js-popup', MAINWP_PLUGIN_URL . 'assets/js/mainwp-popup.js', array(), $this->current_version, true );
1067 - // to support extension uploader.
1068 - wp_enqueue_script( 'mainwp-fileuploader', MAINWP_PLUGIN_URL . 'assets/js/fileuploader.js', array(), $this->current_version ); // phpcs:ignore -- fileuploader scripts need to load at header.
1069 - wp_enqueue_script( 'mainwp-filesaver', MAINWP_PLUGIN_URL . 'assets/js/FileSaver.js', array(), $this->current_version, true );
1070 - }
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 + }
1071 2140
1072 - /**
1073 - * Method admin_enqueue_scripts_fix_conflict()
1074 - *
1075 - * Enqueue Admin Scripts fix conflict.
1076 - */
1077 - public function admin_enqueue_scripts_fix_conflict() {
1078 - if ( static::is_mainwp_pages() ) {
1079 - // to fix conflict with the SVG Support plugin.
1080 - remove_action( 'admin_enqueue_scripts', 'bodhi_svgs_admin_multiselect' );
1081 - }
1082 - }
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 + }
1083 2147
1084 - /**
1085 - * Method admin_enqueue_styles()
1086 - *
1087 - * Enqueue all Mainwp Admin Styles.
1088 - */
1089 - public function admin_enqueue_styles() { //phpcs:ignore -- NOSONAR - complex.
2148 + while ( !@feof( $handle ) ) {
2149 + $buffer = @fread( $handle, $chunksize );
2150 + echo $buffer;
2151 + @ob_flush();
2152 + @flush();
2153 + $buffer = null;
2154 + }
1090 2155
1091 - wp_enqueue_style( 'mainwp', MAINWP_PLUGIN_URL . 'assets/css/mainwp.css', array(), $this->current_version );
1092 - wp_enqueue_style( 'mainwp-responsive-layouts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-responsive-layouts.css', array(), $this->current_version );
2156 + return @fclose( $handle );
2157 + }
1093 2158
1094 - if ( isset( $_GET['hideall'] ) && 1 === (int) $_GET['hideall'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1095 - remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
1096 - }
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' ] );
1097 2175
1098 - /**
1099 - * Current pagenow.
1100 - *
1101 - * @global string
1102 - */
1103 - global $pagenow;
2176 + if ( stristr( rawurldecode( $_REQUEST[ 'mwpdl' ] ), '..' ) ) {
2177 + return;
2178 + }
1104 2179
1105 - $load_cust_scripts = false;
1106 - if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
1107 - $load_cust_scripts = true;
1108 - }
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 + }
1109 2194
1110 - if ( static::is_mainwp_pages() ) {
1111 - wp_enqueue_style( 'mainwp-fonts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fonts.css', array(), $this->current_version );
1112 - wp_enqueue_style( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.css', array(), $this->current_version );
1113 - wp_enqueue_style( 'mainwp-fomantic', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fomantic.css', array(), $this->current_version );
2195 + function login_form() {
2196 + global $redirect_to;
2197 + if ( !isset( $_GET[ 'redirect_to' ] ) ) {
2198 + $redirect_to = get_admin_url() . 'index.php';
2199 + }
2200 + }
1114 2201
1115 - wp_enqueue_style( 'datatables', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.dataTables.css', array(), $this->current_version );
1116 - wp_enqueue_style( 'datatables-semanticui', MAINWP_PLUGIN_URL . 'assets/js/datatables/dataTables.semanticui.css', array(), $this->current_version );
1117 - wp_enqueue_style( 'datatables-select', MAINWP_PLUGIN_URL . 'assets/js/datatables/select.semanticui.min.css', array(), $this->current_version );
1118 - wp_enqueue_style( 'datatables-add-ons', MAINWP_PLUGIN_URL . 'assets/js/datatables/datatables.min.css', array(), $this->current_version );
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' );
1119 2205
1120 - wp_enqueue_style( 'hamburger', MAINWP_PLUGIN_URL . 'assets/js/hamburger/hamburger.css', array(), $this->current_version );
1121 - // to fix conflict layout.
1122 - wp_enqueue_style( 'jquery-ui-style', MAINWP_PLUGIN_URL . 'assets/css/1.11.1/jquery-ui.min.css', array(), '1.11.1' );
2206 + return $messages;
2207 + }
1123 2208
1124 - // load custom MainWP theme.
1125 - $selected_theme = MainWP_Settings::get_instance()->get_selected_theme();
1126 - if ( ! empty( $selected_theme ) ) {
1127 - if ( 'dark' === $selected_theme ) {
1128 - wp_enqueue_style( 'mainwp-custom-dashboard-extension-dark-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-dark-theme.css', array(), $this->current_version );
1129 - } elseif ( 'wpadmin' === $selected_theme ) {
1130 - wp_enqueue_style( 'mainwp-custom-dashboard-extension-wp-admin-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-wpadmin-theme.css', array(), $this->current_version );
1131 - } elseif ( 'minimalistic' === $selected_theme ) {
1132 - wp_enqueue_style( 'mainwp-custom-dashboard-extension-minimalistic-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-minimalistic-theme.css', array(), $this->current_version );
1133 - } elseif ( 'default' === $selected_theme ) {
1134 - wp_enqueue_style( 'mainwp-custom-dashboard-extension-default-theme', MAINWP_PLUGIN_URL . 'assets/css/themes/mainwp-default-theme.css', array(), $this->current_version );
1135 - } else {
1136 - $dirs = MainWP_Settings::get_instance()->get_custom_theme_folder();
1137 - $custom_theme_url = $dirs[1];
1138 - wp_enqueue_style( 'mainwp-custom-dashboard-theme', $custom_theme_url . $selected_theme, array(), $this->current_version );
1139 - }
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
1140 2220 }
1141 2221 }
1142 2222
1143 - if ( $load_cust_scripts ) {
1144 - wp_enqueue_style( 'mainwp-fonts', MAINWP_PLUGIN_URL . 'assets/css/mainwp-fonts.css', array(), $this->current_version );
1145 - wp_enqueue_style( 'fomantic-ui', MAINWP_PLUGIN_URL . 'assets/js/fomantic-ui/fomantic-ui.css', array(), $this->current_version );
1146 - }
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;
1147 2240 }
1148 2241
1149 - /**
1150 - * Method admin_menu()
1151 - *
1152 - * Add Bulk Post/Pages menue.
1153 - */
1154 - public function admin_menu() {
2242 + function activate_extention( $ext_key, $info = array() ) {
1155 2243
1156 - /**
1157 - * Admin menu array.
1158 - *
1159 - * @global object
1160 - */
1161 - global $menu;
2244 + add_filter( 'wp_redirect', array($this, 'activate_redirect'));
1162 2245
1163 - foreach ( $menu as $k => $item ) {
1164 - if ( 'edit.php?post_type=bulkpost' === $item[2] || 'edit.php?post_type=bulkpage' === $item[2] ) {
1165 - unset( $menu[ $k ] );
1166 - }
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);
1167 2254 }
1168 2255 }
1169 2256
1170 - /**
1171 - * Method enqueue_postbox_scripts()
1172 - *
1173 - * Enqueue postbox scripts.
1174 - */
1175 - public static function enqueue_postbox_scripts() {
1176 - wp_enqueue_script( 'common' );
1177 - wp_enqueue_script( 'wp-lists' );
1178 - wp_enqueue_script( 'postbox' );
2257 + function deactivate_extention( $ext_key ) {
2258 + MainWP_Api_Manager::instance()->set_activation_info($ext_key, '');
1179 2259 }
1180 2260
1181 - /**
1182 - * Method admin_footer()
1183 - *
1184 - * Create MainWP admin footer.
1185 - *
1186 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1187 - * @uses \MainWP\Dashboard\MainWP_DB::query()
1188 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
1189 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
1190 - * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_menu()
1191 - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
1192 - * @uses \MainWP\Dashboard\MainWP_System_View::render_footer_content()
1193 - * @uses \MainWP\Dashboard\MainWP_System_View::admin_footer()
1194 - */
1195 - public function admin_footer() { //phpcs:ignore -- NOSONAR - complex.
1196 - if ( ! static::is_mainwp_pages() ) {
1197 - $sites_count = MainWP_DB::instance()->get_websites_count();
1198 - if ( empty( $sites_count ) ) {
1199 - ?>
1200 - <script type="text/javascript">
1201 - jQuery( function($){
1202 - $( 'li#toplevel_page_mainwp_tab .wp-submenu-wrap .wp-submenu-head' ).after('<li style="background: #FFD300 !important;" class="wp-first-item"><a href="admin.php?page=mainwp-setup" style="color: #000 !important;" class="wp-first-item"><?php esc_html_e( 'Quick Setup', 'mainwp' ); ?></a></li>');
1203 - });
1204 - </script>
1205 - <?php
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();
1206 2403 }
1207 - return;
1208 - }
2404 + }
2405 + }
1209 2406
1210 - ?>
1211 - <div class="ui large modal" id="mainwp-response-data-modal">
1212 - <i class="close icon"></i>
1213 - <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div>
1214 - <div class="content">
1215 - <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?>
1216 - </div>
1217 - </div>
1218 - <div class="scrolling content content-response" contenteditable="true"></div>
1219 - <div class="actions">
1220 - <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button>
1221 - </div>
1222 - </div>
1223 - <div id="mainwp-response-data-container" resp-data=""></div>
1224 - <?php
2407 + function handleSettingsPost() {
2408 + if ( !function_exists( 'wp_create_nonce' ) ) {
2409 + include_once( ABSPATH . WPINC . '/pluggable.php' );
2410 + }
1225 2411
1226 - if ( isset( $_GET['hideall'] ) && 1 === (int) $_GET['hideall'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1227 - return;
1228 - }
1229 - $current_wpid = MainWP_System_Utility::get_current_wpid();
1230 - if ( $current_wpid ) {
1231 - $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
1232 - $websites = array( $website );
1233 - } else {
1234 - $is_staging = 'no';
1235 - if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1236 - if ( ( 'managesites' === $_GET['page'] ) && ! isset( $_GET['id'] ) && ! isset( $_GET['do'] ) && ! isset( $_GET['dashboard'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1237 - $group_ids = get_user_option( 'mainwp_managesites_filter_group' );
1238 - if ( ! empty( $group_ids ) ) {
1239 - $group_ids = explode( ',', $group_ids ); // convert to array.
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;
1240 2437 }
1241 - } elseif ( 'UpdatesManage' === $_GET['page'] || 'mainwp_tab' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1242 - $staging_enabled = is_plugin_active( 'mainwp-staging-extension/mainwp-staging-extension.php' ) ? true : false;
1243 - if ( $staging_enabled ) {
1244 - $staging_view = MainWP_System_Utility::get_staging_options_sites_view_for_current_users();
1245 - if ( 'staging' === $staging_view ) {
1246 - $is_staging = 'yes';
1247 - }
1248 - }
1249 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' ] ) );
1250 2447 }
1251 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp_sync.dtsSync DESC, wp.url ASC', false, false, null, false, array(), $is_staging ) );
1252 - }
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 + }
1253 2467
1254 - MainWP_System_View::render_footer_content( $websites, $current_wpid );
1255 - if ( empty( $current_wpid ) ) {
1256 - MainWP_DB::free_result( $websites );
1257 - }
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 + }
1258 2473
1259 - MainWP_System_View::admin_footer();
1260 - MainWP_System_View::render_plugins_install_check();
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 + }
1261 2497
1262 - MainWP_Menu::init_sub_pages();
2498 + public function handle_edit_bulkpost() {
1263 2499
1264 - /**
1265 - * MainWP disabled menu items array.
1266 - *
1267 - * @global object
1268 - */
1269 - global $_mainwp_disable_menus_items;
2500 + $post_id = 0;
2501 + if (isset( $_POST['post_ID'] ) )
2502 + $post_id = (int) $_POST['post_ID'];
1270 2503
1271 - $_mainwp_disable_menus_items = apply_filters( 'mainwp_all_disablemenuitems', $_mainwp_disable_menus_items );
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 + }
1272 2517 }
1273 2518
1274 - /**
1275 - * Method activated_check()
1276 - *
1277 - * Activated check.
1278 - *
1279 - * @uses \MainWP\Dashboard\MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook()
1280 - */
1281 - public function activated_check() {
1282 - MainWP_Deprecated_Hooks::maybe_handle_deprecated_hook();
1283 - return $this->get_version();
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;
1284 2526 }
1285 2527
1286 - /**
1287 - * Method activation()
1288 - *
1289 - * Activate MainWP.
1290 - *
1291 - * @uses \MainWP\Dashboard\MainWP_Install::install()
1292 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
1293 - */
1294 - public function activation() {
1295 - $this->update_install();
1296 - MainWP_Utility::update_option( 'mainwp_activated', 'yes' );
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;
1297 2536 }
1298 2537
1299 - /**
1300 - * Method deactivation()
1301 - *
1302 - * Deactivate MainWP.
1303 - */
1304 - public function deactivation() {
1305 - update_option( 'mainwp_extensions_all_activation_cached', '' );
1306 - }
2538 + function save_bulkpost( $post_id ) {
2539 + $post = get_post( $post_id );
1307 2540
1308 - /**
1309 - * Method update_install()
1310 - *
1311 - * Update MainWP.
1312 - *
1313 - * @uses \MainWP\Dashboard\MainWP_Install::install()
1314 - */
1315 - public function update_install() {
1316 - MainWP_DB_Client::instance();
1317 - MainWP_DB_Site_Actions::instance();
1318 - MainWP_Install::instance()->install();
1319 - $this->check_to_updates();
1320 - }
2541 + if ( $post->post_type != 'bulkpost' ) {
2542 + return;
2543 + }
1321 2544
2545 + if ( !isset( $_POST[ 'post_type' ] ) || ( $_POST[ 'post_type' ] != 'bulkpost' ) ) {
2546 + return;
2547 + }
1322 2548
1323 - /**
1324 - * Method check_to_updates()
1325 - *
1326 - * To check updates options.
1327 - */
1328 - public function check_to_updates() {
1329 - $update_ver = get_option( 'mainwp_update_check_version', false );
1330 - $current_ver = $this->check_ver_update;
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 + }
1331 2554
1332 - if ( false === $update_ver && version_compare( $current_ver, '0.0.1', '=' ) ) {
1333 - // to update new saving format.
1334 - MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key();
1335 - MainWP_Utility::update_option( 'mainwp_update_check_version', $current_ver );
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();
1336 2745 }
1337 2746 }
1338 2747
1339 - /**
1340 - * Method is_single_user()
1341 - *
1342 - * Check if single user environment.
1343 - *
1344 - * @return boolean true|false.
1345 - */
1346 - public function is_single_user() {
1347 - return true;
1348 - }
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 + }
1349 2782
1350 - /**
1351 - * Method is_multi_user()
1352 - *
1353 - * Check if multi user environment.
1354 - *
1355 - * @return boolean true|false.
1356 - */
1357 - public function is_multi_user() {
1358 - return ! $this->is_single_user();
1359 - }
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 );
1360 2787
1361 - /**
1362 - * Method get_plugin_slug()
1363 - *
1364 - * Get MainWP Plugin Slug.
1365 - */
1366 - public function get_plugin_slug() {
1367 - return $this->plugin_slug;
1368 - }
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 +
1369 3112 }