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

class-mainwp-post-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.1, at class/class-mainwp-post-handler.php

995 lines 30.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Handler.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Post_Handler
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Post_Handler extends MainWP_Post_Base_Handler {
16
17 /**
18 * Private static variable to hold the single instance of the class.
19 *
20 * @static
21 *
22 * @var mixed Default null
23 */
24 private static $instance = null;
25
26 /**
27 * Method instance()
28 *
29 * Create a public static instance.
30 *
31 * @static
32 * @return MainWP_Post_Handler
33 */
34 public static function instance() {
35 if ( null == self::$instance ) {
36 self::$instance = new self();
37 }
38 return self::$instance;
39 }
40
41 /**
42 * Initiate all actions.
43 */
44 public function init() {
45 // Page: ManageSites.
46 $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
47
48 // Page: BulkAddUser.
49 $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
50 $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
51
52 // Widget: RightNow.
53 $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
54
55 if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) ) {
56 // Page: SecurityIssues.
57 $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
58 $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
59 $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
60 }
61
62 $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
63 $this->add_action( 'mainwp_dismiss_twit', array( &$this, 'mainwp_dismiss_twit' ) );
64 $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
65 $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
66 $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
67 $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
68 $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
69
70 $this->add_action( 'mainwp_twitter_dashboard_action', array( &$this, 'mainwp_twitter_dashboard_action' ) );
71
72 // Page: Recent Posts.
73 if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
74 $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
75 $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
76 $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
77 $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
78 $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
79 $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
80 }
81 $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
82 // Page: Pages.
83 if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) ) {
84 $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
85 $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
86 $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
87 $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
88 $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
89 }
90 // Page: Users.
91 $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
92 $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
93 $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
94 $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
95
96 // Page: Posts.
97 $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
98 $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
99 $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
100
101 // Page: Pages.
102 $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
103 // Page: User.
104 $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
105
106 $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
107 $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
108 $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
109 $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
110 $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
111 $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
112 $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
113 $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
114 $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
115 $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
116 $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
117
118 $this->add_security_nonce( 'mainwp-common-nonce' );
119 }
120
121 /**
122 * Method mainwp_installation_warning_hide()
123 *
124 * Hide the installation warning.
125 */
126 public function mainwp_installation_warning_hide() {
127 $this->secure_request( 'mainwp_installation_warning_hide' );
128
129 update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
130 die( 'ok' );
131 }
132
133 /**
134 * Method mainwp_users_search()
135 *
136 * Search Post handler,
137 * Page: User.
138 */
139 public function mainwp_users_search() {
140 $this->secure_request( 'mainwp_users_search' );
141 MainWP_Cache::init_session();
142
143 $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '';
144 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
145 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
146 $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
147
148 MainWP_User::render_table( false, $role, $groups, $sites, $search );
149 die();
150 }
151
152 /**
153 * Method mainwp_posts_search()
154 *
155 * Search Post handler,
156 * Page: Posts.
157 */
158 public function mainwp_posts_search() {
159 $this->secure_request( 'mainwp_posts_search' );
160 $post_type = ( isset( $_POST['post_type'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ) ? sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) : 'post' );
161 if ( isset( $_POST['maximum'] ) ) {
162 MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
163 }
164
165 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
166 $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
167 $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
168 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
169 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
170 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
171 $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
172 $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
173 $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
174
175 MainWP_Cache::init_session();
176 MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on );
177 die();
178 }
179 /**
180 * Method mainwp_pages_search()
181 *
182 * Search Post handler,
183 * Page: Pages.
184 */
185 public function mainwp_pages_search() {
186 $this->secure_request( 'mainwp_pages_search' );
187 if ( isset( $_POST['maximum'] ) ) {
188 MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
189 }
190
191 $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
192 $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
193 $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
194 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
195 $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
196 $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
197 $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
198
199 MainWP_Cache::init_session();
200 MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $search_on );
201 die();
202 }
203
204 /**
205 * Method mainwp_get_categories()
206 *
207 * Get post/page categories.
208 */
209 public function mainwp_get_categories() {
210 $this->secure_request( 'mainwp_get_categories' );
211 MainWP_Post_Page_Handler::get_categories();
212 die();
213 }
214
215 /**
216 * Method mainwp_post_get_edit()
217 *
218 * Get post to edit.
219 */
220 public function mainwp_post_get_edit() {
221 $this->secure_request( 'mainwp_post_get_edit' );
222 MainWP_Post_Page_Handler::get_post();
223 die();
224 }
225
226 /**
227 * Method mainwp_user_delete()
228 *
229 * Delete User from Child Site,
230 * Page: Users.
231 */
232 public function mainwp_user_delete() {
233 $this->secure_request( 'mainwp_user_delete' );
234 MainWP_User::delete();
235 }
236
237 /**
238 * Method mainwp_user_edit()
239 *
240 * Edit User from Child Site,
241 * Page: Users.
242 */
243 public function mainwp_user_edit() {
244 $this->secure_request( 'mainwp_user_edit' );
245 MainWP_User::edit();
246 }
247
248 /**
249 * Method mainwp_user_update_password(
250 *
251 * Update User passowrd from Child Site,
252 * Page: Users.
253 */
254 public function mainwp_user_update_password() {
255 $this->secure_request( 'mainwp_user_update_password' );
256 MainWP_User::update_password();
257 }
258
259 /**
260 * Method mainwp_user_update_user()
261 *
262 * Update User from Child Site,
263 * Page: Users.
264 */
265 public function mainwp_user_update_user() {
266 $this->secure_request( 'mainwp_user_update_user' );
267 MainWP_User::update_user();
268 }
269
270 /**
271 * Method mainwp_post_unpublish()
272 *
273 * Unpublish post from Child Site,
274 * Page: Recent Posts.
275 */
276 public function mainwp_post_unpublish() {
277 $this->secure_request( 'mainwp_post_unpublish' );
278 MainWP_Recent_Posts::unpublish();
279 }
280
281 /**
282 * Method mainwp_post_publish()
283 *
284 * Publish post on Child Site,
285 * Page: Recent Posts
286 */
287 public function mainwp_post_publish() {
288 $this->secure_request( 'mainwp_post_publish' );
289 MainWP_Recent_Posts::publish();
290 }
291
292 /**
293 * Method mainwp_post_approve()
294 *
295 * Approve post on Child Site,
296 * Page: Recent Posts.
297 */
298 public function mainwp_post_approve() {
299 $this->secure_request( 'mainwp_post_approve' );
300 MainWP_Recent_Posts::approve();
301 }
302
303 /**
304 * Method mainwp_post_trash()
305 *
306 * Trash post on Child Site,
307 * Page: Recent Posts
308 */
309 public function mainwp_post_trash() {
310 $this->secure_request( 'mainwp_post_trash' );
311
312 MainWP_Recent_Posts::trash();
313 }
314
315 /**
316 * Method mainwp_post_delete()
317 *
318 * Delete post on Child Site,
319 * Page: Recent Posts.
320 */
321 public function mainwp_post_delete() {
322 $this->secure_request( 'mainwp_post_delete' );
323
324 MainWP_Recent_Posts::delete();
325 }
326
327 /**
328 * Method mainwp_post_restore()
329 *
330 * Restore post,
331 * Page: Recent Posts.
332 */
333 public function mainwp_post_restore() {
334 $this->secure_request( 'mainwp_post_restore' );
335
336 MainWP_Recent_Posts::restore();
337 }
338
339 /**
340 * Method mainwp_page_unpublish()
341 *
342 * Unpublish page,
343 * Page: Recent Pages.
344 */
345 public function mainwp_page_unpublish() {
346 $this->secure_request( 'mainwp_page_unpublish' );
347 MainWP_Page::unpublish();
348 }
349
350 /**
351 * Method mainwp_page_publish()
352 *
353 * Publish page,
354 * Page: Recent Pages.
355 */
356 public function mainwp_page_publish() {
357 $this->secure_request( 'mainwp_page_publish' );
358 MainWP_Page::publish();
359 }
360
361 /**
362 * Method mainwp_page_trash()
363 *
364 * Trash page,
365 * Page: Recent Pages.
366 */
367 public function mainwp_page_trash() {
368 $this->secure_request( 'mainwp_page_trash' );
369 MainWP_Page::trash();
370 }
371
372 /**
373 * Method mainwp_page_delete()
374 *
375 * Delete page,
376 * Page: Recent Pages.
377 */
378 public function mainwp_page_delete() {
379 $this->secure_request( 'mainwp_page_delete' );
380 MainWP_Page::delete();
381 }
382
383 /**
384 * Method mainwp_page_restor()
385 *
386 * Restore page,
387 * Page: Recent Pages.
388 */
389 public function mainwp_page_restore() {
390 $this->secure_request( 'mainwp_page_restore' );
391 MainWP_Page::restore();
392 }
393
394 /**
395 * Method mainwp_notice_status_update()
396 *
397 * Hide after installtion notices,
398 * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
399 */
400 public function mainwp_notice_status_update() {
401 $this->secure_request( 'mainwp_notice_status_update' );
402
403 $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
404 if ( 'mail_failed' === $no_id ) {
405 MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
406 die( 'ok' );
407 }
408
409 /**
410 * Current user global.
411 *
412 * @global string
413 */
414 global $current_user;
415 $user_id = $current_user->ID;
416 if ( $user_id ) {
417 $status = get_user_option( 'mainwp_notice_saved_status' );
418 if ( ! is_array( $status ) ) {
419 $status = array();
420 }
421 if ( ! empty( $no_id ) ) {
422 $status[ $no_id ] = 1;
423 update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
424 }
425 }
426 die( 1 );
427 }
428
429 /**
430 * Method mainwp_status_saving()
431 *
432 * Save last_sync_sites time() or mainwp_status_saved_values.
433 */
434 public function mainwp_status_saving() {
435 $this->secure_request( 'mainwp_status_saving' );
436 $values = get_option( 'mainwp_status_saved_values' );
437
438 if ( ! isset( $_POST['status'] ) ) {
439 die( -1 );
440 }
441
442 if ( 'last_sync_sites' === $_POST['status'] ) {
443 update_option( 'mainwp_last_synced_all_sites', time() );
444
445 /**
446 * Action: mainwp_synced_all_sites
447 *
448 * Fires upon successfull synchronization process.
449 *
450 * @since 3.5.1
451 */
452 do_action( 'mainwp_synced_all_sites' );
453 die( 'ok' );
454 }
455
456 $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
457 $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
458
459 if ( ! empty( $status ) ) {
460 if ( empty( $value ) ) {
461 if ( isset( $values[ $status ] ) ) {
462 unset( $values[ $status ] );
463 }
464 } else {
465 $values[ $status ] = $value;
466 }
467 update_option( 'mainwp_status_saved_values', $values );
468 }
469
470 die( 'ok' );
471 }
472
473 /**
474 * Method ajax_widget_order()
475 *
476 * Update saved widget order.
477 */
478 public function ajax_widgets_order() {
479
480 $this->secure_request( 'mainwp_widgets_order' );
481 $user = wp_get_current_user();
482 if ( $user && ! empty( $_POST['page'] ) ) {
483 $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
484 $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
485 update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, $order, true );
486 die( 'ok' );
487 }
488 die( -1 );
489 }
490
491 /**
492 * Method ajax_mainwp_save_settings()
493 *
494 * Update saved MainWP Settings.
495 */
496 public function ajax_mainwp_save_settings() {
497 $this->secure_request( 'mainwp_save_settings' );
498 $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
499 if ( ! empty( $name ) ) {
500 $option_name = 'mainwp_' . $name;
501 $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
502 MainWP_Utility::update_option( $option_name, $val );
503 }
504 die( 'ok' );
505 }
506
507 /**
508 * Method mainwp_leftmenu_filter_group()
509 *
510 * MainWP left menu filter by group.
511 */
512 public function mainwp_leftmenu_filter_group() {
513 $this->secure_request( 'mainwp_leftmenu_filter_group' );
514
515 $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
516
517 if ( ! empty( $gid ) ) {
518 $ids = '';
519 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
520 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
521 $ids .= $website->id . ',';
522 }
523 MainWP_DB::free_result( $websites );
524 $ids = rtrim( $ids, ',' );
525 die( $ids );
526 }
527 die( '' );
528 }
529
530 /**
531 * Method mainwp_dismiss_twit()
532 *
533 * Dismiss the twitter bragger.
534 */
535 public function mainwp_dismiss_twit() {
536 $this->secure_request( 'mainwp_dismiss_twit' );
537
538 /**
539 * Current user global.
540 *
541 * @global string
542 */
543 global $current_user;
544
545 $user_id = $current_user->ID;
546 if ( $user_id && isset( $_POST['twitId'] ) && ! empty( $_POST['twitId'] ) && isset( $_POST['what'] ) && ! empty( $_POST['what'] ) ) {
547 MainWP_Twitter::clear_twitter_info( sanitize_text_field( wp_unslash( $_POST['what'] ) ), sanitize_text_field( wp_unslash( $_POST['twitId'] ) ) );
548 }
549 die( 1 );
550 }
551
552 /**
553 * Method dismiss_activate_notice()
554 *
555 * Dismiss activate notice.
556 */
557 public function dismiss_activate_notice() {
558 $this->secure_request( 'mainwp_dismiss_activate_notice' );
559
560 /**
561 * Current user global.
562 *
563 * @global string
564 */
565 global $current_user;
566
567 $user_id = $current_user->ID;
568 $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
569 if ( $user_id && ! empty( $slug ) ) {
570 $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
571 if ( ! is_array( $activate_notices ) ) {
572 $activate_notices = array();
573 }
574
575 $activate_notices[ $slug ] = time();
576 update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
577 }
578 die( 1 );
579 }
580
581 /**
582 * Method mainwp_twitter_dashboard_action()
583 *
584 * Post handler for twitter bragger.
585 *
586 * @return mixed $html|$success
587 */
588 public function mainwp_twitter_dashboard_action() {
589 $this->secure_request( 'mainwp_twitter_dashboard_action' );
590
591 $success = false;
592 $actionName = isset( $_POST['actionName'] ) ? sanitize_text_field( wp_unslash( $_POST['actionName'] ) ) : '';
593 $countSites = isset( $_POST['countSites'] ) ? intval( $_POST['countSites'] ) : 0;
594 $countRealItems = isset( $_POST['countRealItems'] ) ? intval( $_POST['countRealItems'] ) : 0;
595 $countItems = isset( $_POST['countItems'] ) ? intval( $_POST['countItems'] ) : 0;
596 $countSeconds = isset( $_POST['countSeconds'] ) ? intval( $_POST['countSeconds'] ) : 0;
597
598 if ( ! empty( $actionName ) && ! empty( $countSites ) ) {
599 $success = MainWP_Twitter::update_twitter_info( $actionName, $countSites, $countSeconds, $countRealItems, time(), $countItems );
600 }
601
602 if ( ! empty( $_POST['showNotice'] ) ) {
603 if ( MainWP_Twitter::enabled_twitter_messages() ) {
604 $twitters = MainWP_Twitter::get_twitter_notice( $actionName );
605 $html = '';
606 if ( is_array( $twitters ) ) {
607 foreach ( $twitters as $timeid => $twit_mess ) {
608 if ( ! empty( $twit_mess ) ) {
609 $sendText = MainWP_Twitter::get_twit_to_send( $actionName, $timeid );
610 $html .= '<div class="mainwp-tips mainwp-notice mainwp-notice-blue twitter"><span class="mainwp-tip" twit-what="' . esc_attr( $actionName ) . '" twit-id="' . $timeid . '">' . $twit_mess . '</span>&nbsp;' . MainWP_Twitter::gen_twitter_button( $sendText, false ) . '<span><a href="#" class="mainwp-dismiss-twit mainwp-right" ><i class="fa fa-times-circle"></i> ' . __( 'Dismiss', 'mainwp' ) . '</a></span></div>';
611 }
612 }
613 }
614 die( $html );
615 }
616 } elseif ( $success ) {
617 die( 'ok' );
618 }
619
620 die( '' );
621 }
622
623 /**
624 * Method mainwp_security_issues_request()
625 *
626 * Post hander for,
627 * Page: SecurityIssues.
628 */
629 public function mainwp_security_issues_request() {
630 $this->secure_request( 'mainwp_security_issues_request' );
631
632 try {
633 wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
634 } catch ( MainWP_Exception $e ) {
635 die(
636 wp_json_encode(
637 array(
638 'error' => array(
639 'message' => $e->getMessage(),
640 'extra' => $e->get_message_extra(),
641 ),
642 )
643 )
644 );
645 }
646 }
647
648 /**
649 * Method mainwp_security_issues_fix()
650 *
651 * Post hander for 'fix issues',
652 * Page: SecurityIssues.
653 */
654 public function mainwp_security_issues_fix() {
655 $this->secure_request( 'mainwp_security_issues_fix' );
656
657 try {
658 wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
659 } catch ( MainWP_Exception $e ) {
660 die(
661 wp_json_encode(
662 array(
663 'error' => array(
664 'message' => $e->getMessage(),
665 'extra' => $e->get_message_extra(),
666 ),
667 )
668 )
669 );
670 }
671 }
672
673 /**
674 * Method mainwp_security_issues_unfix()
675 *
676 * Post hander for 'unfix issues',
677 * Page: SecurityIssues.
678 */
679 public function mainwp_security_issues_unfix() {
680 $this->secure_request( 'mainwp_security_issues_unfix' );
681
682 try {
683 wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
684 } catch ( MainWP_Exception $e ) {
685 die(
686 wp_json_encode(
687 array(
688 'error' => array(
689 'message' => $e->getMessage(),
690 'extra' => $e->get_message_extra(),
691 ),
692 )
693 )
694 );
695 }
696 }
697
698 /**
699 * Method ajax_disconnect_site()
700 *
701 * Disconnect Child Site.
702 */
703 public function ajax_disconnect_site() {
704 $this->secure_request( 'mainwp_disconnect_site' );
705
706 $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
707
708 if ( empty( $siteid ) ) {
709 die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
710 }
711
712 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
713
714 if ( ! $website ) {
715 die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
716 }
717
718 try {
719 $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
720 } catch ( \Exception $e ) {
721 $information = array( 'error' => __( 'fetch_url_authed exception', 'mainwp' ) );
722 }
723
724 wp_send_json( $information );
725 }
726
727 /**
728 * Method ajax_sites_display_rows()
729 *
730 * Display rows via ajax,
731 * Page: Manage Sites.
732 */
733 public function ajax_sites_display_rows() {
734 $this->secure_request( 'mainwp_manage_sites_display_rows' );
735 MainWP_Manage_Sites::ajax_optimize_display_rows();
736 }
737
738 /**
739 * Method ajax_sites_display_rows()
740 *
741 * Display rows via ajax,
742 * Page: Monitoring Sites.
743 */
744 public function ajax_monitoring_display_rows() {
745 $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
746 MainWP_Monitoring::ajax_optimize_display_rows();
747 }
748
749
750 /**
751 * Method mainwp_bulkadduser()
752 *
753 * Bulk Add User for,
754 * Page: BulkAddUser.
755 */
756 public function mainwp_bulkadduser() {
757 if ( ! $this->check_security( 'mainwp_bulkadduser' ) ) {
758 die( 'ERROR ' . wp_json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
759 }
760 MainWP_User::do_bulk_add();
761 die();
762 }
763
764 /**
765 * Method mainwp_importuser()
766 *
767 * Import user.
768 */
769 public function mainwp_importuser() {
770 $this->secure_request( 'mainwp_importuser' );
771 MainWP_User::do_import();
772 }
773
774 /**
775 * Method mainwp_notes_save()
776 *
777 * Post handler for save notes on,
778 * Page: Manage Sites.
779 */
780 public function mainwp_notes_save() {
781 $this->secure_request( 'mainwp_notes_save' );
782 MainWP_Manage_Sites_Handler::save_note();
783 }
784
785 /**
786 * Method mainwp_syncerrors_dismiss()
787 *
788 * Dismis Syncerrors for,
789 * Widget: RightNow.
790 */
791 public function mainwp_syncerrors_dismiss() {
792
793 $this->secure_request( 'mainwp_syncerrors_dismiss' );
794
795 try {
796 die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
797 } catch ( \Exception $e ) {
798 die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
799 }
800 }
801
802 /**
803 * Method mainwp_events_notice_hide()
804 *
805 * Hide events notice.
806 */
807 public function mainwp_events_notice_hide() {
808 $this->secure_request( 'mainwp_events_notice_hide' );
809
810 if ( isset( $_POST['notice'] ) ) {
811 $current_options = get_option( 'mainwp_showhide_events_notice' );
812 if ( ! is_array( $current_options ) ) {
813 $current_options = array();
814 }
815 if ( 'first_site' === $_POST['notice'] ) {
816 update_option( 'mainwp_first_site_events_notice', '' );
817 } elseif ( 'request_reviews1' === $_POST['notice'] ) {
818 $current_options['request_reviews1'] = 15;
819 $current_options['request_reviews1_starttime'] = time();
820 } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
821 $current_options['request_reviews1'] = 'forever';
822 $current_options['request_reviews2'] = 'forever';
823 } elseif ( 'request_reviews2' === $_POST['notice'] ) {
824 $current_options['request_reviews2'] = 15;
825 $current_options['request_reviews2_starttime'] = time();
826 } elseif ( 'trust_child' === $_POST['notice'] ) {
827 $current_options['trust_child'] = 1;
828 } elseif ( 'multi_site' === $_POST['notice'] ) {
829 $current_options['hide_multi_site_notice'] = 1;
830 }
831 update_option( 'mainwp_showhide_events_notice', $current_options );
832 }
833 die( 'ok' );
834 }
835
836 /**
837 * Method mainwp_showhide_sections()
838 *
839 * Show/Hide sections.
840 */
841 public function mainwp_showhide_sections() {
842 if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
843 $opts = get_option( 'mainwp_opts_showhide_sections' );
844 if ( ! is_array( $opts ) ) {
845 $opts = array();
846 }
847 $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
848 update_option( 'mainwp_opts_showhide_sections', $opts );
849 die( 'ok' );
850 }
851 die( 'failed' );
852 }
853
854 /**
855 * Method mainwp_saving_status()
856 *
857 * MainWP Saving Status.
858 */
859 public function mainwp_saving_status() {
860 if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
861 die( 'Invalid request.' );
862 }
863 $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
864 if ( ! empty( $saving_status ) ) {
865 $current_options = get_option( 'mainwp_opts_saving_status' );
866 if ( ! is_array( $current_options ) ) {
867 $current_options = array();
868 }
869 if ( isset( $_POST['value'] ) ) {
870 $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
871 }
872 update_option( 'mainwp_opts_saving_status', $current_options );
873 }
874 die( 'ok' );
875 }
876
877 /**
878 * Method ajax_recheck_http()
879 *
880 * Recheck Child Site http status code & message.
881 */
882 public function ajax_recheck_http() {
883 if ( ! $this->check_security( 'mainwp_recheck_http' ) ) {
884 die( wp_json_encode( array( 'error' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
885 }
886
887 if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
888 die( -1 );
889 }
890
891 $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
892 if ( empty( $website ) ) {
893 die( -1 );
894 }
895
896 $result = MainWP_Monitoring_Handler::handle_check_website( $website );
897 $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
898 $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
899 die(
900 wp_json_encode(
901 array(
902 'httpcode' => esc_html( $http_code ),
903 'status' => $check_result ? 1 : 0,
904 )
905 )
906 );
907 }
908
909 /**
910 * Method mainwp_ignore_http_response()
911 *
912 * Ignore Child Site https response.
913 */
914 public function mainwp_ignore_http_response() {
915 if ( ! $this->check_security( 'mainwp_ignore_http_response' ) ) {
916 die( wp_json_encode( array( 'error' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
917 }
918 $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
919
920 if ( empty( $siteid ) ) {
921 die( -1 );
922 }
923
924 $website = MainWP_DB::instance()->get_website_by_id( $siteid );
925 if ( empty( $website ) ) {
926 die( -1 );
927 }
928
929 MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
930 die( wp_json_encode( array( 'ok' => 1 ) ) );
931 }
932
933 /**
934 * Method mainwp_autoupdate_and_trust_child()
935 *
936 * Set MainWP Child Plugin to Trusted & AutoUpdate.
937 */
938 public function mainwp_autoupdate_and_trust_child() {
939 $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
940 if ( get_option( 'mainwp_automaticDailyUpdate' ) != 1 ) {
941 update_option( 'mainwp_automaticDailyUpdate', 1 );
942 }
943 MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
944 die( 'ok' );
945 }
946
947 /**
948 * Method mainwp_force_destroy_sessions()
949 *
950 * Force destroy sessions.
951 */
952 public function mainwp_force_destroy_sessions() {
953 $this->secure_request( 'mainwp_force_destroy_sessions' );
954
955 $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
956
957 if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
958 die( wp_json_encode( array( 'error' => array( 'message' => __( 'This website does not exist.', 'mainwp' ) ) ) ) );
959 }
960
961 $website = MainWP_DB::instance()->get_website_by_id( $website_id );
962 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
963 die( wp_json_encode( array( 'error' => array( 'message' => __( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
964 }
965
966 try {
967 $information = MainWP_Connect::fetch_url_authed(
968 $website,
969 'settings_tools',
970 array(
971 'action' => 'force_destroy_sessions',
972 )
973 );
974
975 /**
976 * MainWP information array.
977 *
978 * @global object $mainWP
979 */
980 global $mainWP;
981
982 if ( ( '2.0.22' === $mainWP->get_version() ) || ( '2.0.23' === $mainWP->get_version() ) ) {
983 if ( 1 != get_option( 'mainwp_fixed_security_2022' ) ) {
984 update_option( 'mainwp_fixed_security_2022', 1 );
985 }
986 }
987 } catch ( \Exception $e ) {
988 $information = array( 'error' => __( 'fetch_url_authed exception', 'mainwp' ) );
989 }
990
991 wp_send_json( $information );
992 }
993
994 }
995