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-post-handler.php +1656 -1314 5.14.0.5 View file →
@@ -1,1474 +1,1816 @@
1 1 <?php
2 -/**
3 - * Post Handler.
4 - *
5 - * @package MainWP/Dashboard
6 - */
7 2
8 -namespace MainWP\Dashboard;
3 +class MainWP_Post_Handler {
9 4
10 -/**
11 - * Class MainWP_Post_Handler
12 - *
13 - * @package MainWP\Dashboard
14 - *
15 - * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
16 - */
17 -class MainWP_Post_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
5 + protected $security_nonces;
6 + private static $instance = null;
18 7
19 - // phpcs:disable Generic.Metrics.CyclomaticComplexity -- This is the only way to achieve desired results, pull request solutions appreciated.
8 + function __construct() {
20 9
21 - /**
22 - * Private static variable to hold the single instance of the class.
23 - *
24 - * @static
25 - *
26 - * @var mixed Default null
27 - */
28 - private static $instance = null;
10 + }
29 11
30 - /**
31 - * Method instance()
32 - *
33 - * Create a public static instance.
34 - *
35 - * @static
36 - * @return MainWP_Post_Handler
37 - */
38 - public static function instance() {
39 - if ( null === static::$instance ) {
40 - static::$instance = new self();
41 - }
42 - return static::$instance;
43 - }
12 + static function Instance() {
13 + if ( self::$instance == null ) {
14 + self::$instance = new MainWP_Post_Handler();
15 + }
16 + return self::$instance;
17 + }
44 18
45 - /**
46 - * Initiate all actions.
47 - *
48 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
49 - */
50 - public function init() {
51 - // Page: ManageSites.
52 - $this->add_action( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
19 + function init() {
20 + //Page: ManageBackups
21 + $this->addAction( 'mainwp_addbackup', array( &$this, 'mainwp_addbackup' ) );
22 + if ( mainwp_current_user_can( 'dashboard', 'edit_backup_tasks' ) ) {
23 + $this->addAction( 'mainwp_updatebackup', array( &$this, 'mainwp_updatebackup' ) );
24 + }
25 + if ( mainwp_current_user_can( 'dashboard', 'delete_backup_tasks' ) ) {
26 + $this->addAction( 'mainwp_removebackup', array( &$this, 'mainwp_removebackup' ) );
27 + }
28 + $this->addAction( 'mainwp_pausebackup', array( &$this, 'mainwp_pausebackup' ) );
29 + $this->addAction( 'mainwp_resumebackup', array( &$this, 'mainwp_resumebackup' ) );
53 30
54 - // Page: BulkAddUser.
55 - $this->add_action( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
56 - $this->add_action( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
31 + add_action( 'wp_ajax_mainwp_backuptask_get_sites', array( &$this, 'mainwp_backuptask_get_sites' ) ); //ok
57 32
58 - // Widget: RightNow.
59 - $this->add_action( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
33 + if ( mainwp_current_user_can( 'dashboard', 'run_backup_tasks' ) ) {
34 + $this->addAction( 'mainwp_backuptask_run_site', array( &$this, 'mainwp_backuptask_run_site' ) );
35 + }
36 + $this->addAction( 'mainwp_backup_upload_file', array( &$this, 'mainwp_backup_upload_file' ) );
60 37
61 - if ( mainwp_current_user_have_right( 'dashboard', 'manage_security_issues' ) ) {
62 - // Page: SecurityIssues.
63 - $this->add_action( 'mainwp_security_issues_request', array( &$this, 'mainwp_security_issues_request' ) );
64 - $this->add_action( 'mainwp_security_issues_fix', array( &$this, 'mainwp_security_issues_fix' ) );
65 - $this->add_action( 'mainwp_security_issues_unfix', array( &$this, 'mainwp_security_issues_unfix' ) );
66 - }
38 + //Page: ManageSites
39 + $this->addAction( 'mainwp_checkwp', array( &$this, 'mainwp_checkwp' ) );
40 + $this->addAction( 'mainwp_addwp', array( &$this, 'mainwp_addwp' ) );
41 + $this->addAction( 'mainwp_get_site_icon', array( &$this, 'get_site_icon' ) );
42 + $this->addAction( 'mainwp_ext_prepareinstallplugintheme', array( &$this, 'mainwp_ext_prepareinstallplugintheme' ) );
43 + $this->addAction( 'mainwp_ext_performinstallplugintheme', array( &$this, 'mainwp_ext_performinstallplugintheme' ) );
44 + $this->addAction( 'mainwp_ext_applypluginsettings', array( &$this, 'mainwp_ext_applypluginsettings' ) );
67 45
68 - $this->add_action( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
69 - $this->add_action( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
70 - $this->add_action( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
71 - $this->add_action( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
72 - $this->add_action( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
73 - $this->add_action( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
74 - $this->add_action( 'mainwp_guided_tours_option_update', array( &$this, 'ajax_guided_tours_option_update' ) );
46 + if ( mainwp_current_user_can( 'dashboard', 'test_connection' ) ) {
47 + $this->addAction( 'mainwp_testwp', array( &$this, 'mainwp_testwp' ) );
48 + }
75 49
76 - // Page: Recent Posts.
77 - if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
78 - $this->add_action( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
79 - $this->add_action( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
80 - $this->add_action( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
81 - $this->add_action( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
82 - $this->add_action( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
83 - $this->add_action( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
84 - }
85 - $this->add_action( 'mainwp_post_addmeta', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_add_meta' ) );
86 - // Page: Pages.
87 - if ( mainwp_current_user_have_right( 'dashboard', 'manage_pages' ) ) {
88 - $this->add_action( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
89 - $this->add_action( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
90 - $this->add_action( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
91 - $this->add_action( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
92 - $this->add_action( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
93 - }
94 - // Page: Users.
95 - $this->add_action( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
96 - $this->add_action( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
97 - $this->add_action( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
98 - $this->add_action( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
50 + $this->addAction( 'mainwp_removesite', array( &$this, 'mainwp_removesite' ) );
51 + $this->addAction( 'mainwp_notes_save', array( &$this, 'mainwp_notes_save' ) );
52 + add_action( 'wp_ajax_mainwp_reconnectwp', array( &$this, 'mainwp_reconnectwp' ) ); //ok
53 + $this->addAction( 'mainwp_updatechildsite_value', array( &$this, 'mainwp_updatechildsite_value' ) ); //ok
54 + //Page: ManageGroups
55 + $this->addAction( 'mainwp_group_rename', array( &$this, 'mainwp_group_rename' ) );
56 + $this->addAction( 'mainwp_group_delete', array( &$this, 'mainwp_group_delete' ) ); //ok
57 + $this->addAction( 'mainwp_group_add', array( &$this, 'mainwp_group_add' ) );
58 + add_action( 'wp_ajax_mainwp_group_getsites', array( &$this, 'mainwp_group_getsites' ) ); //ok
59 + $this->addAction( 'mainwp_group_updategroup', array( &$this, 'mainwp_group_updategroup' ) );
99 60
100 - // Page: Posts.
101 - $this->add_action( 'mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) );
102 - $this->add_action( 'mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) );
103 - $this->add_action( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
104 - $this->add_action( 'mainwp_post_postingbulk', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_posting_posts' ) );
105 - $this->add_action( 'mainwp_get_sites_of_groups', array( MainWP_Post_Page_Handler::get_class_name(), 'ajax_get_sites_of_groups' ) );
61 + //Page: InstallPlugins/Themes
62 + add_action( 'wp_ajax_mainwp_preparebulkinstallplugintheme', array(
63 + &$this,
64 + 'mainwp_preparebulkinstallplugintheme',
65 + ) ); //ok
66 + $this->addAction( 'mainwp_installbulkinstallplugintheme', array(
67 + &$this,
68 + 'mainwp_installbulkinstallplugintheme',
69 + ) );
70 + add_action( 'wp_ajax_mainwp_preparebulkuploadplugintheme', array(
71 + &$this,
72 + 'mainwp_preparebulkuploadplugintheme',
73 + ) ); //ok
74 + $this->addAction( 'mainwp_installbulkuploadplugintheme', array(
75 + &$this,
76 + 'mainwp_installbulkuploadplugintheme',
77 + ) );
78 + $this->addAction( 'mainwp_cleanbulkuploadplugintheme', array( &$this, 'mainwp_cleanbulkuploadplugintheme' ) );
106 79
107 - // Page: Pages.
108 - $this->add_action( 'mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) );
109 - // Page: User.
110 - $this->add_action( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
80 + //Page: BulkAddUser
81 + $this->addAction( 'mainwp_bulkadduser', array( &$this, 'mainwp_bulkadduser' ) );
82 + add_action( 'wp_ajax_mainwp_bulkuploadadduser', array( &$this, 'mainwp_bulkuploadadduser' ) ); //ok - to check
83 + $this->addAction( 'mainwp_importuser', array( &$this, 'mainwp_importuser' ) );
111 84
112 - $this->add_action( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
113 - $this->add_action( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
114 - $this->add_action( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
115 - $this->add_action( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
116 - $this->add_action( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
117 - $this->add_action( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
118 - $this->add_action( 'mainwp_recheck_http', array( &$this, 'ajax_recheck_http' ) );
119 - $this->add_action( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
120 - $this->add_action( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
121 - $this->add_action( 'mainwp_manage_sites_display_rows', array( &$this, 'ajax_sites_display_rows' ) );
122 - $this->add_action( 'mainwp_monitoring_sites_display_rows', array( &$this, 'ajax_monitoring_display_rows' ) );
85 + //Widget: RightNow
86 + $this->addAction( 'mainwp_syncsites', array( &$this, 'mainwp_syncsites' ) );
87 + $this->addAction( 'mainwp_upgradewp', array( &$this, 'mainwp_upgradewp' ) );
88 + $this->addAction( 'mainwp_upgradeplugintheme', array( &$this, 'mainwp_upgradeplugintheme' ) );
89 + $this->addAction( 'mainwp_ignoreplugintheme', array( &$this, 'mainwp_ignoreplugintheme' ) ); //ok
90 + $this->addAction( 'mainwp_unignoreplugintheme', array( &$this, 'mainwp_unignoreplugintheme' ) ); //ok
91 + $this->addAction( 'mainwp_ignorepluginsthemes', array( &$this, 'mainwp_ignorepluginsthemes' ) ); //ok
92 + $this->addAction( 'mainwp_unignorepluginsthemes', array(
93 + &$this,
94 + 'mainwp_unignorepluginsthemes',
95 + ) ); //ok
96 + $this->addAction( 'mainwp_unignoreabandonedplugintheme', array(
97 + &$this,
98 + 'mainwp_unignoreabandonedplugintheme',
99 + ) ); //ok
100 + $this->addAction( 'mainwp_unignoreabandonedpluginsthemes', array(
101 + &$this,
102 + 'mainwp_unignoreabandonedpluginsthemes',
103 + ) ); //ok
104 + $this->addAction( 'mainwp_dismissoutdateplugintheme', array(
105 + &$this,
106 + 'mainwp_dismissoutdateplugintheme',
107 + ) ); //ok
108 + $this->addAction( 'mainwp_dismissoutdatepluginsthemes', array(
109 + &$this,
110 + 'mainwp_dismissoutdatepluginsthemes',
111 + ) ); //ok
112 + $this->addAction( 'mainwp_trust_plugin', array( &$this, 'mainwp_trust_plugin' ) );
113 + $this->addAction( 'mainwp_trust_theme', array( &$this, 'mainwp_trust_theme' ) );
114 + $this->addAction( 'mainwp_checkbackups', array( &$this, 'mainwp_checkbackups' ) );
115 + $this->addAction( 'mainwp_syncerrors_dismiss', array( &$this, 'mainwp_syncerrors_dismiss' ) );
116 + //Page: backup
117 + if ( mainwp_current_user_can( 'dashboard', 'run_backup_tasks' ) ) {
118 + $this->addAction( 'mainwp_backup_run_site', array( &$this, 'mainwp_backup_run_site' ) );
119 + }
120 + if ( mainwp_current_user_can( 'dashboard', 'execute_backups' ) ) {
121 + $this->addAction( 'mainwp_backup', array( &$this, 'mainwp_backup' ) );
122 + }
123 + $this->addAction( 'mainwp_backup_checkpid', array( &$this, 'mainwp_backup_checkpid' ) );
124 + $this->addAction( 'mainwp_createbackup_getfilesize', array( &$this, 'mainwp_createbackup_getfilesize' ) );
125 + $this->addAction( 'mainwp_backup_download_file', array( &$this, 'mainwp_backup_download_file' ) );
126 + $this->addAction( 'mainwp_backup_delete_file', array( &$this, 'mainwp_backup_delete_file' ) );
127 + $this->addAction( 'mainwp_backup_getfilesize', array( &$this, 'mainwp_backup_getfilesize' ) );
128 + $this->addAction( 'mainwp_backup_upload_getprogress', array( &$this, 'mainwp_backup_upload_getprogress' ) );
129 + $this->addAction( 'mainwp_backup_upload_checkstatus', array( &$this, 'mainwp_backup_upload_checkstatus' ) );
123 130
124 - $this->add_action_nonce( 'mainwp-common-nonce' );
131 + //Page: CloneSite
132 + // add_action('wp_ajax_mainwp_clonesite_check_backups', array(&$this, 'mainwp_clonesite_check_backups'));
133 + // add_action('wp_ajax_mainwp_clone', array(&$this, 'mainwp_clone'));
134 + // add_action('wp_ajax_mainwp_clone_test_ftp', array(&$this, 'mainwp_clone_test_ftp'));
125 135
126 - // Page: Clients.
127 - $this->add_action( 'mainwp_clients_add_client', array( &$this, 'mainwp_clients_add_client' ) );
128 - $this->add_action( 'mainwp_clients_delete_client', array( &$this, 'mainwp_clients_delete_client' ) );
136 + if ( mainwp_current_user_can( 'dashboard', 'manage_security_issues' ) ) {
137 + //Page: SecurityIssues
138 + $this->addAction( 'mainwp_securityIssues_request', array( &$this, 'mainwp_securityIssues_request' ) ); //ok
139 + $this->addAction( 'mainwp_securityIssues_fix', array( &$this, 'mainwp_securityIssues_fix' ) ); //ok
140 + $this->addAction( 'mainwp_securityIssues_unfix', array( &$this, 'mainwp_securityIssues_unfix' ) ); //ok
141 + }
129 142
130 - $this->add_action( 'mainwp_clients_save_field', array( &$this, 'mainwp_clients_save_field' ) );
131 - $this->add_action( 'mainwp_clients_delete_general_field', array( &$this, 'mainwp_clients_delete_general_field' ) );
132 - $this->add_action( 'mainwp_clients_delete_field', array( &$this, 'mainwp_clients_delete_field' ) );
133 - $this->add_action( 'mainwp_clients_notes_save', array( &$this, 'mainwp_clients_notes_save' ) );
134 - $this->add_action( 'mainwp_clients_suspend_client', array( &$this, 'mainwp_clients_suspend_client' ) );
135 - $this->add_action( 'mainwp_refresh_icon', array( &$this, 'ajax_refresh_icon' ) );
136 - $this->add_action( 'mainwp_upload_custom_icon', array( &$this, 'ajax_upload_custom_icon' ) );
137 - $this->add_action( 'mainwp_select_custom_theme', array( &$this, 'ajax_select_custom_theme' ) );
138 - $this->add_action( 'mainwp_site_actions_dismiss', array( &$this, 'ajax_site_actions_dismiss' ) );
139 - $this->add_action( 'mainwp_delete_non_mainwp_actions', array( &$this, 'ajax_delete_non_mainwp_actions' ) );
140 - $this->add_action( 'mainwp_import_demo_data', array( &$this, 'ajax_import_demo_data' ) );
141 - $this->add_action( 'mainwp_delete_demo_data', array( &$this, 'ajax_delete_demo_data' ) );
142 - $this->add_action( 'mainwp_prepare_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_prepare_renew_connections' ) );
143 - $this->add_action( 'mainwp_renew_connections', array( MainWP_Connect_Helper::instance(), 'ajax_renew_connections' ) );
144 - }
143 + //Page: ManageTips
144 + $this->addAction( 'mainwp_tips_update', array( &$this, 'mainwp_tips_update' ) ); //ok
145 + $this->addAction( 'mainwp_notice_status_update', array( &$this, 'mainwp_notice_status_update' ) );
146 + $this->addAction( 'mainwp_dismiss_twit', array( &$this, 'mainwp_dismiss_twit' ) );
147 + $this->addAction( 'mainwp_dismiss_activate_notice', array( &$this, 'dismiss_activate_notice' ) );
148 + $this->addAction( 'mainwp_status_saving', array( &$this, 'mainwp_status_saving' ) );
149 + $this->addAction( 'mainwp_leftmenu_filter_group', array( &$this, 'mainwp_leftmenu_filter_group' ) );
150 + $this->addAction( 'mainwp_widgets_order', array( &$this, 'ajax_widgets_order' ) );
151 + $this->addAction( 'mainwp_save_settings', array( &$this, 'ajax_mainwp_save_settings' ) );
152 +
153 + add_action( 'wp_ajax_mainwp_twitter_dashboard_action', array(
154 + &$this,
155 + 'mainwp_twitter_dashboard_action',
156 + ) ); //ok
157 +
158 + add_action( 'wp_ajax_mainwp_reset_usercookies', array( &$this, 'mainwp_reset_usercookies' ) ); //ok
159 + //Page: Recent Posts
160 + if ( mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
161 + $this->addAction( 'mainwp_post_unpublish', array( &$this, 'mainwp_post_unpublish' ) );
162 + $this->addAction( 'mainwp_post_publish', array( &$this, 'mainwp_post_publish' ) );
163 + $this->addAction( 'mainwp_post_trash', array( &$this, 'mainwp_post_trash' ) );
164 + $this->addAction( 'mainwp_post_delete', array( &$this, 'mainwp_post_delete' ) );
165 + $this->addAction( 'mainwp_post_restore', array( &$this, 'mainwp_post_restore' ) );
166 + $this->addAction( 'mainwp_post_approve', array( &$this, 'mainwp_post_approve' ) );
167 + }
168 + $this->addAction( 'mainwp_post_addmeta', array( MainWP_Post::getClassName(), 'ajax_add_meta', ) );
169 + //Page: Pages
170 + if ( mainwp_current_user_can( 'dashboard', 'manage_pages' ) ) {
171 + $this->addAction( 'mainwp_page_unpublish', array( &$this, 'mainwp_page_unpublish' ) );
172 + $this->addAction( 'mainwp_page_publish', array( &$this, 'mainwp_page_publish' ) );
173 + $this->addAction( 'mainwp_page_trash', array( &$this, 'mainwp_page_trash' ) );
174 + $this->addAction( 'mainwp_page_delete', array( &$this, 'mainwp_page_delete' ) );
175 + $this->addAction( 'mainwp_page_restore', array( &$this, 'mainwp_page_restore' ) );
176 + }
177 + //Page: Users
178 + $this->addAction( 'mainwp_user_delete', array( &$this, 'mainwp_user_delete' ) );
179 + $this->addAction( 'mainwp_user_edit', array( &$this, 'mainwp_user_edit' ) );
180 + $this->addAction( 'mainwp_user_update_password', array( &$this, 'mainwp_user_update_password' ) );
181 + $this->addAction( 'mainwp_user_update_user', array( &$this, 'mainwp_user_update_user' ) );
145 182
146 - /**
147 - * Method add_post_action()
148 - *
149 - * Add ajax action.
150 - *
151 - * @param string $action Action to perform.
152 - * @param string $callback Callback to perform.
153 - */
154 - public function add_post_action( $action, $callback ) {
155 - $this->add_action( $action, $callback );
156 - }
183 + //Page: Posts
184 + add_action( 'wp_ajax_mainwp_posts_search', array( &$this, 'mainwp_posts_search' ) ); //ok
185 + add_action( 'wp_ajax_mainwp_get_categories', array( &$this, 'mainwp_get_categories' ) ); //ok
186 + add_action( 'wp_ajax_mainwp_posts_get_terms', array( &$this, 'mainwp_posts_get_terms' ) ); //ok
187 + add_action( 'wp_ajax_mainwp_posts_test_post', array( &$this, 'mainwp_posts_test_post' ) ); //ok
188 + $this->addAction( 'mainwp_post_get_edit', array( &$this, 'mainwp_post_get_edit' ) );
157 189
158 - /**
159 - * Method mainwp_installation_warning_hide()
160 - *
161 - * Hide the installation warning.
162 - */
163 - public function mainwp_installation_warning_hide() {
164 - $this->secure_request( 'mainwp_installation_warning_hide' );
190 + //Page: Pages
191 + add_action( 'wp_ajax_mainwp_pages_search', array( &$this, 'mainwp_pages_search' ) ); //ok
192 + //Page: User
193 + $this->addAction( 'mainwp_users_search', array( &$this, 'mainwp_users_search' ) );
165 194
166 - update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
167 - die( 'ok' );
168 - }
195 + //Page: Themes
196 + $this->addAction( 'mainwp_themes_search', array( &$this, 'mainwp_themes_search' ) );
197 + $this->addAction( 'mainwp_themes_search_all', array( &$this, 'mainwp_themes_search_all' ) );
198 + if ( mainwp_current_user_can( 'dashboard', 'activate_themes' ) ) {
199 + $this->addAction( 'mainwp_theme_activate', array( &$this, 'mainwp_theme_activate' ) );
200 + }
201 + if ( mainwp_current_user_can( 'dashboard', 'delete_themes' ) ) {
202 + $this->addAction( 'mainwp_theme_delete', array( &$this, 'mainwp_theme_delete' ) );
203 + }
204 + $this->addAction( 'mainwp_trusted_theme_notes_save', array( &$this, 'mainwp_trusted_theme_notes_save' ) );
205 + if ( mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
206 + $this->addAction( 'mainwp_theme_ignore_updates', array( &$this, 'mainwp_theme_ignore_updates' ) );
207 + }
169 208
170 - /**
171 - * Method mainwp_users_search()
172 - *
173 - * Search Post handler,
174 - * Page: User.
175 - *
176 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
177 - * @uses \MainWP\Dashboard\MainWP_User::render_table()
178 - */
179 - public function mainwp_users_search() {
180 - $this->secure_request( 'mainwp_users_search' );
181 - MainWP_Cache::init_session();
209 + //Page: Plugins
210 + $this->addAction( 'mainwp_plugins_search', array( &$this, 'mainwp_plugins_search' ) );
211 + $this->addAction( 'mainwp_plugins_search_all_active', array( &$this, 'mainwp_plugins_search_all_active' ) );
182 212
183 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
184 - $role = isset( $_POST['role'] ) ? sanitize_text_field( wp_unslash( $_POST['role'] ) ) : '';
185 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
186 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
187 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
188 - $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
189 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
190 - MainWP_User::render_table( false, $role, $groups, $sites, $search, $clients );
191 - die();
192 - }
213 + if ( mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) {
214 + $this->addAction( 'mainwp_plugin_activate', array( &$this, 'mainwp_plugin_activate' ) );
215 + $this->addAction( 'mainwp_plugin_deactivate', array( &$this, 'mainwp_plugin_deactivate' ) );
216 + }
217 + if ( mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) {
218 + $this->addAction( 'mainwp_plugin_delete', array( &$this, 'mainwp_plugin_delete' ) );
219 + }
193 220
194 - /**
195 - * Method mainwp_posts_search()
196 - *
197 - * Search Post handler,
198 - * Page: Posts.
199 - *
200 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
201 - * @uses \MainWP\Dashboard\MainWP_Post::render_table()
202 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
203 - */
204 - public function mainwp_posts_search() { // phpcs:ignore -- NOSONAR - complex.
205 - $this->secure_request( 'mainwp_posts_search' );
206 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
207 - $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' );
208 - if ( isset( $_POST['maximum'] ) ) {
209 - MainWP_Utility::update_option( 'mainwp_maximumPosts', isset( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
210 - }
211 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
212 - $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstart'] ) ) ) : '';
213 - $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( trim( wp_unslash( $_POST['dtsstop'] ) ) ) : '';
214 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
215 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
216 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
217 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
218 - $postId = isset( $_POST['postId'] ) ? sanitize_text_field( wp_unslash( $_POST['postId'] ) ) : '';
219 - $userId = isset( $_POST['userId'] ) ? sanitize_text_field( wp_unslash( $_POST['userId'] ) ) : '';
220 - $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
221 - $table_content_only = isset( $_POST['table_content'] ) && wp_unslash( $_POST['table_content'] ) ? true : false;
222 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
221 + if ( mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
222 + $this->addAction( 'mainwp_plugin_ignore_updates', array( &$this, 'mainwp_plugin_ignore_updates' ) );
223 + }
224 + $this->addAction( 'mainwp_trusted_plugin_notes_save', array( &$this, 'mainwp_trusted_plugin_notes_save' ) );
225 +
226 + //Widget: Plugins
227 + $this->addAction( 'mainwp_widget_plugin_activate', array( &$this, 'mainwp_widget_plugin_activate' ) );
228 + $this->addAction( 'mainwp_widget_plugin_deactivate', array( &$this, 'mainwp_widget_plugin_deactivate' ) );
229 + $this->addAction( 'mainwp_widget_plugin_delete', array( &$this, 'mainwp_widget_plugin_delete' ) );
223 230
224 - MainWP_Cache::init_session();
225 - if ( $table_content_only ) {
226 - MainWP_Post::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, true, $clients );
227 - } else {
228 - $params = array(
229 - 'groups' => $groups,
230 - 'sites' => $sites,
231 - 'postId' => $postId,
232 - 'userId' => $userId,
233 - 'post_type' => $post_type,
234 - 'search_on' => $search_on,
235 - 'clients' => $clients,
236 - );
237 - MainWP_Post::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
238 - }
239 - die();
240 - }
241 - /**
242 - * Method mainwp_pages_search()
243 - *
244 - * Search Post handler,
245 - * Page: Pages.
246 - *
247 - * @uses \MainWP\Dashboard\MainWP_Cache::init_session()
248 - * @uses \MainWP\Dashboard\MainWP_Page::render_table()
249 - *
250 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
251 - */
252 - public function mainwp_pages_search() {
253 - $this->secure_request( 'mainwp_pages_search' );
254 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
255 - if ( isset( $_POST['maximum'] ) ) {
256 - MainWP_Utility::update_option( 'mainwp_maximumPages', intval( $_POST['maximum'] ) ? intval( $_POST['maximum'] ) : 50 );
257 - }
258 - $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) : '';
259 - $dtsstart = isset( $_POST['dtsstart'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstart'] ) ) : '';
260 - $dtsstop = isset( $_POST['dtsstop'] ) ? sanitize_text_field( wp_unslash( $_POST['dtsstop'] ) ) : '';
261 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
262 - $groups = isset( $_POST['groups'] ) && is_array( $_POST['groups'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['groups'] ) ) : '';
263 - $sites = isset( $_POST['sites'] ) && is_array( $_POST['sites'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) : '';
264 - $clients = isset( $_POST['clients'] ) && is_array( $_POST['clients'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['clients'] ) ) : '';
265 - $search_on = isset( $_POST['search_on'] ) ? sanitize_text_field( wp_unslash( $_POST['search_on'] ) ) : '';
266 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
267 - MainWP_Cache::init_session();
231 + //Widget: Themes
232 + $this->addAction( 'mainwp_widget_theme_activate', array( &$this, 'mainwp_widget_theme_activate' ) );
233 + $this->addAction( 'mainwp_widget_theme_delete', array( &$this, 'mainwp_widget_theme_delete' ) );
268 234
269 - $params = array(
270 - 'groups' => $groups,
271 - 'sites' => $sites,
272 - 'search_on' => $search_on,
273 - 'clients' => $clients,
274 - );
235 + $this->addAction( 'mainwp_events_notice_hide', array( &$this, 'mainwp_events_notice_hide' ) );
236 + $this->addAction( 'mainwp_showhide_sections', array( &$this, 'mainwp_showhide_sections' ) );
237 + $this->addAction( 'mainwp_saving_status', array( &$this, 'mainwp_saving_status' ) );
238 + $this->addAction( 'mainwp_autoupdate_and_trust_child', array( &$this, 'mainwp_autoupdate_and_trust_child' ) );
239 + $this->addAction( 'mainwp_installation_warning_hide', array( &$this, 'mainwp_installation_warning_hide' ) );
240 + $this->addAction( 'mainwp_force_destroy_sessions', array( &$this, 'mainwp_force_destroy_sessions' ) );
241 + $this->addAction( 'mainwp_recheck_http', array( &$this, 'mainwp_recheck_http' ) );
242 + $this->addAction( 'mainwp_ignore_http_response', array( &$this, 'mainwp_ignore_http_response' ) );
243 + $this->addAction( 'mainwp_disconnect_site', array( &$this, 'ajax_disconnect_site' ) );
244 + $this->addAction( 'mainwp_manage_display_rows', array( &$this, 'ajax_display_rows' ) );
275 245
276 - MainWP_Page::render_table( false, $keyword, $dtsstart, $dtsstop, $status, $params );
277 - die();
278 - }
246 + $this->addSecurityNonce( 'mainwp-common-nonce' );
247 +
248 + MainWP_Extensions::initAjaxHandlers();
279 249
280 - /**
281 - * Method mainwp_get_categories()
282 - *
283 - * Get post/page categories.
284 - *
285 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_categories()
286 - */
287 - public function mainwp_get_categories() {
288 - $this->secure_request( 'mainwp_get_categories' );
289 - MainWP_Post_Page_Handler::ajax_handle_get_categories();
290 - die();
291 - }
250 + add_action( 'wp_ajax_mainwp_childscan', array( &$this, 'mainwp_childscan' ) ); //ok
251 + }
292 252
293 - /**
294 - * Method mainwp_post_get_edit()
295 - *
296 - * Get post to edit.
297 - *
298 - * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_post()
299 - */
300 - public function mainwp_post_get_edit() {
301 - $this->secure_request( 'mainwp_post_get_edit' );
302 - MainWP_Post_Page_Handler::get_post();
303 - die();
304 - }
253 + function mainwp_childscan() {
254 + //todo: RS: secure action
255 + MainWP_Child_Scan::scan();
256 + }
305 257
306 - /**
307 - * Method mainwp_user_delete()
308 - *
309 - * Delete User from Child Site,
310 - * Page: Users.
311 - *
312 - * @uses \MainWP\Dashboard\MainWP_User::delete()
313 - */
314 - public function mainwp_user_delete() {
315 - $this->secure_request( 'mainwp_user_delete' );
316 - MainWP_User::delete();
317 - }
258 + // Hide the installation warning
259 + function mainwp_installation_warning_hide() {
260 + $this->secure_request( 'mainwp_installation_warning_hide' );
318 261
319 - /**
320 - * Method mainwp_user_edit()
321 - *
322 - * Edit User from Child Site,
323 - * Page: Users.
324 - *
325 - * @uses \MainWP\Dashboard\MainWP_User::edit()
326 - */
327 - public function mainwp_user_edit() {
328 - $this->secure_request( 'mainwp_user_edit' );
329 - MainWP_User::edit();
330 - }
262 + update_option( 'mainwp_installation_warning_hide_the_notice', 'yes' );
263 + die( 'ok' );
264 + }
331 265
332 - /**
333 - * Method mainwp_user_update_password(
334 - *
335 - * Update User password from Child Site,
336 - * Page: Users.
337 - *
338 - * @uses \MainWP\Dashboard\MainWP_User::update_password()
339 - */
340 - public function mainwp_user_update_password() {
341 - $this->secure_request( 'mainwp_user_update_password' );
342 - MainWP_User::update_password();
343 - }
266 + /**
267 + * Page: Users
268 + */
269 + function mainwp_users_search() {
270 + $this->secure_request( 'mainwp_users_search' );
271 + MainWP_Cache::initSession();
272 + MainWP_User::renderTable( false, $_POST[ 'role' ], ( isset( $_POST[ 'groups' ] ) ? $_POST[ 'groups' ] : '' ), ( isset( $_POST[ 'sites' ] ) ? $_POST[ 'sites' ] : '' ), $_POST[ 'search' ] );
273 + die();
274 + }
344 275
345 - /**
346 - * Method mainwp_user_update_user()
347 - *
348 - * Update User from Child Site,
349 - * Page: Users.
350 - *
351 - * @uses \MainWP\Dashboard\MainWP_User::update_user()
352 - */
353 - public function mainwp_user_update_user() {
354 - $this->secure_request( 'mainwp_user_update_user' );
355 - MainWP_User::update_user();
356 - }
276 + /**
277 + * Page: Themes
278 + */
279 + function mainwp_themes_search() {
280 + $this->secure_request( 'mainwp_themes_search' );
281 + MainWP_Cache::initSession();
282 + $result = MainWP_Themes::renderTable( $_POST[ 'keyword' ], $_POST[ 'status' ], ( isset( $_POST[ 'groups' ] ) ? $_POST[ 'groups' ] : '' ), ( isset( $_POST[ 'sites' ] ) ? $_POST[ 'sites' ] : '' ) );
283 + wp_send_json( $result );
284 + }
357 285
358 - /**
359 - * Method mainwp_post_unpublish()
360 - *
361 - * Unpublish post from Child Site,
362 - * Page: Recent Posts.
363 - *
364 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::unpublish()
365 - */
366 - public function mainwp_post_unpublish() {
367 - $this->secure_request( 'mainwp_post_unpublish' );
368 - MainWP_Recent_Posts::unpublish();
369 - }
286 + function mainwp_theme_activate() {
287 + $this->secure_request( 'mainwp_theme_activate' );
370 288
371 - /**
372 - * Method mainwp_post_publish()
373 - *
374 - * Publish post on Child Site,
375 - * Page: Recent Posts.
376 - *
377 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::publish()
378 - */
379 - public function mainwp_post_publish() {
380 - $this->secure_request( 'mainwp_post_publish' );
381 - MainWP_Recent_Posts::publish();
382 - }
289 + MainWP_Themes::activateTheme();
290 + die();
291 + }
383 292
384 - /**
385 - * Method mainwp_post_approve()
386 - *
387 - * Approve post on Child Site,
388 - * Page: Recent Posts.
389 - *
390 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::approve()
391 - */
392 - public function mainwp_post_approve() {
393 - $this->secure_request( 'mainwp_post_approve' );
394 - MainWP_Recent_Posts::approve();
395 - }
293 + function mainwp_theme_delete() {
294 + $this->secure_request( 'mainwp_theme_delete' );
396 295
397 - /**
398 - * Method mainwp_post_trash()
399 - *
400 - * Trash post on Child Site,
401 - * Page: Recent Posts.
402 - *
403 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::trash()
404 - */
405 - public function mainwp_post_trash() {
406 - $this->secure_request( 'mainwp_post_trash' );
296 + MainWP_Themes::deleteThemes();
297 + die();
298 + }
407 299
408 - MainWP_Recent_Posts::trash();
409 - }
300 + function mainwp_theme_ignore_updates() {
301 + $this->secure_request( 'mainwp_theme_ignore_updates' );
410 302
411 - /**
412 - * Method mainwp_post_delete()
413 - *
414 - * Delete post on Child Site,
415 - * Page: Recent Posts.
416 - *
417 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::delete()
418 - */
419 - public function mainwp_post_delete() {
420 - $this->secure_request( 'mainwp_post_delete' );
303 + MainWP_Themes::ignoreUpdates();
304 + die();
305 + }
421 306
422 - MainWP_Recent_Posts::delete();
423 - }
307 + function mainwp_themes_search_all() {
308 + $this->secure_request( 'mainwp_themes_search_all' );
309 + MainWP_Cache::initSession();
310 + MainWP_Themes::renderAllThemesTable();
311 + die();
312 + }
424 313
425 - /**
426 - * Method mainwp_post_restore()
427 - *
428 - * Restore post,
429 - * Page: Recent Posts.
430 - *
431 - * @uses \MainWP\Dashboard\MainWP_Recent_Posts::restore()
432 - */
433 - public function mainwp_post_restore() {
434 - $this->secure_request( 'mainwp_post_restore' );
314 + function mainwp_trusted_theme_notes_save() {
315 + $this->secure_request( 'mainwp_trusted_theme_notes_save' );
435 316
436 - MainWP_Recent_Posts::restore();
437 - }
317 + MainWP_Themes::saveTrustedThemeNote();
318 + die( json_encode( array( 'result' => 'SUCCESS' ) ) );
319 + }
438 320
439 - /**
440 - * Method mainwp_page_unpublish()
441 - *
442 - * Unpublish page,
443 - * Page: Recent Pages.
444 - *
445 - * @uses \MainWP\Dashboard\MainWP_Page::unpublish()
446 - */
447 - public function mainwp_page_unpublish() {
448 - $this->secure_request( 'mainwp_page_unpublish' );
449 - MainWP_Page::unpublish();
450 - }
321 + /**
322 + * Page: Plugins
323 + */
324 + function mainwp_plugins_search() {
325 + $this->secure_request( 'mainwp_plugins_search' );
326 + MainWP_Cache::initSession();
327 + $result = MainWP_Plugins::renderTable( $_POST[ 'keyword' ], $_POST[ 'status' ], ( isset( $_POST[ 'groups' ] ) ? $_POST[ 'groups' ] : '' ), ( isset( $_POST[ 'sites' ] ) ? $_POST[ 'sites' ] : '' ) );
328 + wp_send_json( $result );
329 + }
451 330
452 - /**
453 - * Method mainwp_page_publish()
454 - *
455 - * Publish page,
456 - * Page: Recent Pages.
457 - *
458 - * @uses \MainWP\Dashboard\MainWP_Page::publish()
459 - */
460 - public function mainwp_page_publish() {
461 - $this->secure_request( 'mainwp_page_publish' );
462 - MainWP_Page::publish();
463 - }
331 + function mainwp_plugins_search_all_active() {
332 + $this->secure_request( 'mainwp_plugins_search_all_active' );
333 + MainWP_Cache::initSession();
334 + MainWP_Plugins::renderAllActiveTable();
335 + die();
336 + }
464 337
465 - /**
466 - * Method mainwp_page_trash()
467 - *
468 - * Trash page,
469 - * Page: Recent Pages.
470 - *
471 - * @uses \MainWP\Dashboard\MainWP_Page::trash()
472 - */
473 - public function mainwp_page_trash() {
474 - $this->secure_request( 'mainwp_page_trash' );
475 - MainWP_Page::trash();
476 - }
338 + function mainwp_plugin_activate() {
339 + $this->secure_request( 'mainwp_plugin_activate' );
477 340
478 - /**
479 - * Method mainwp_page_delete()
480 - *
481 - * Delete page,
482 - * Page: Recent Pages.
483 - *
484 - * @uses \MainWP\Dashboard\MainWP_Page::delete()
485 - */
486 - public function mainwp_page_delete() {
487 - $this->secure_request( 'mainwp_page_delete' );
488 - MainWP_Page::delete();
489 - }
341 + MainWP_Plugins::activatePlugins();
342 + die();
343 + }
490 344
491 - /**
492 - * Method mainwp_page_restor()
493 - *
494 - * Restore page,
495 - * Page: Recent Pages.
496 - *
497 - * @uses \MainWP\Dashboard\MainWP_Page::restore()
498 - */
499 - public function mainwp_page_restore() {
500 - $this->secure_request( 'mainwp_page_restore' );
501 - MainWP_Page::restore();
502 - }
345 + function mainwp_plugin_deactivate() {
346 + $this->secure_request( 'mainwp_plugin_deactivate' );
503 347
504 - /**
505 - * Method mainwp_notice_status_update()
506 - *
507 - * Hide after installation notices,
508 - * (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning).
509 - *
510 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
511 - */
512 - public function mainwp_notice_status_update() {
513 - $this->secure_request( 'mainwp_notice_status_update' );
348 + MainWP_Plugins::deactivatePlugins();
349 + die();
350 + }
514 351
515 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
516 - $no_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : false;
517 - if ( 'mail_failed' === $no_id ) {
518 - MainWP_Utility::update_option( 'mainwp_notice_wp_mail_failed', 'hide' );
519 - die( 'ok' );
520 - }
352 + function mainwp_plugin_delete() {
353 + $this->secure_request( 'mainwp_plugin_delete' );
521 354
522 - /**
523 - * Current user global.
524 - *
525 - * @global string
526 - */
527 - global $current_user;
528 - $user_id = $current_user->ID;
529 - if ( $user_id ) {
530 - $status = get_user_option( 'mainwp_notice_saved_status' );
531 - if ( ! is_array( $status ) ) {
532 - $status = array();
533 - }
534 - if ( ! empty( $no_id ) ) {
535 - $time_set = isset( $_POST['time_set'] ) && 1 === intval( $_POST['time_set'] ) ? true : false;
536 - if ( $time_set ) {
537 - $status[ $no_id ] = time();
538 - } else {
539 - $status[ $no_id ] = 1;
540 - }
541 - update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
542 - }
543 - }
544 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
545 - die( 1 );
546 - }
355 + MainWP_Plugins::deletePlugins();
356 + die();
357 + }
547 358
548 - /**
549 - * Method mainwp_status_saving()
550 - *
551 - * Save last_sync_sites time() or mainwp_status_saved_values.
552 - */
553 - public function mainwp_status_saving() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
554 - $this->secure_request( 'mainwp_status_saving' );
555 - $values = get_option( 'mainwp_status_saved_values' );
359 + function mainwp_plugin_ignore_updates() {
360 + $this->secure_request( 'mainwp_plugin_ignore_updates' );
556 361
557 - if ( ! is_array( $values ) ) {
558 - $values = array();
559 - }
362 + MainWP_Plugins::ignoreUpdates();
363 + die();
364 + }
560 365
561 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
562 - if ( ! isset( $_POST['status'] ) ) {
563 - die( -1 );
564 - }
366 + function mainwp_trusted_plugin_notes_save() {
367 + $this->secure_request( 'mainwp_trusted_plugin_notes_save' );
565 368
566 - if ( 'save_indicator_values' === $_POST['status'] ) {
369 + MainWP_Plugins::saveTrustedPluginNote();
370 + die( json_encode( array( 'result' => 'SUCCESS' ) ) );
371 + }
567 372
568 - if ( ! empty( $_POST['name'] ) ) {
569 - $current_values = is_array( $values ) && isset( $values['save_indicator_values'] ) && ! empty( $values['save_indicator_values'] ) ? json_decode( $values['save_indicator_values'], true ) : array();
570 - if ( ! is_array( $current_values ) ) {
571 - $current_values = array();
572 - }
573 - $current_values[ sanitize_text_field( wp_unslash( $_POST['name'] ) ) ] = isset( $_POST['value'] ) ? intval( wp_unslash( $_POST['value'] ) ) : 0;
373 + /**
374 + * Widget: Plugins
375 + */
376 + function mainwp_widget_plugin_activate() {
377 + $this->secure_request( 'mainwp_widget_plugin_activate' );
378 + MainWP_Widget_Plugins::activatePlugin();
379 + }
574 380
575 - $values['save_indicator_values'] = wp_json_encode( $current_values );
576 - update_option( 'mainwp_status_saved_values', $values );
577 - die( 'ok' );
578 - }
579 - die( 'failed' );
580 - }
381 + function mainwp_widget_plugin_deactivate() {
382 + $this->secure_request( 'mainwp_widget_plugin_deactivate' );
383 + MainWP_Widget_Plugins::deactivatePlugin();
384 + }
581 385
582 - if ( 'last_sync_sites' === $_POST['status'] ) {
583 - if ( isset( $_POST['isGlobalSync'] ) && ! empty( $_POST['isGlobalSync'] ) ) {
584 - update_option( 'mainwp_last_synced_all_sites', time() );
386 + function mainwp_widget_plugin_delete() {
387 + $this->secure_request( 'mainwp_widget_plugin_delete' );
388 + MainWP_Widget_Plugins::deletePlugin();
389 + }
585 390
586 - /**
587 - * Action: mainwp_synced_all_sites
588 - *
589 - * Fires upon successfull synchronization process.
590 - *
591 - * @since 3.5.1
592 - */
593 - do_action( 'mainwp_synced_all_sites' );
594 - }
595 - die( 'ok' );
596 - }
391 + /**
392 + * Widget: Themes
393 + */
394 + function mainwp_widget_theme_activate() {
395 + $this->secure_request( 'mainwp_widget_theme_activate' );
396 + MainWP_Widget_Themes::activateTheme();
397 + }
597 398
598 - $status = isset( $_POST['status'] ) ? sanitize_text_field( wp_unslash( $_POST['status'] ) ) : '';
599 - $value = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
600 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
399 + function mainwp_widget_theme_delete() {
400 + $this->secure_request( 'mainwp_widget_theme_delete' );
401 + MainWP_Widget_Themes::deleteTheme();
402 + }
601 403
602 - if ( ! empty( $status ) ) {
603 - if ( empty( $value ) ) {
604 - if ( isset( $values[ $status ] ) ) {
605 - unset( $values[ $status ] );
606 - }
607 - } else {
608 - $values[ $status ] = $value;
609 - }
610 - update_option( 'mainwp_status_saved_values', $values );
611 - }
404 + /**
405 + * Page: Posts
406 + */
407 + function mainwp_posts_search() {
408 + $this->secure_request();
612 409
613 - die( 'ok' );
614 - }
410 + $post_type = (isset( $_POST[ 'post_type' ] ) && strlen( trim( $_POST[ 'post_type' ] ) ) > 0 ? $_POST[ 'post_type' ] : 'post');
615 411
616 - /**
617 - * Method ajax_widget_order()
618 - *
619 - * Update saved widget order.
620 - */
621 - public function ajax_widgets_order() { //phpcs:ignore -- NOSONAR - complex.
412 + if ( isset( $_POST[ 'maximum' ] ) ) {
413 + MainWP_Utility::update_option( 'mainwp_maximumPosts', MainWP_Utility::ctype_digit( $_POST[ 'maximum' ] ) ? intval( $_POST[ 'maximum' ] ) : 50 );
414 + }
622 415
623 - $this->secure_request( 'mainwp_widgets_order' );
624 - $user = wp_get_current_user();
625 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
626 - if ( $user && ! empty( $_POST['page'] ) ) {
627 - $page = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
628 - $order = isset( $_POST['order'] ) ? sanitize_text_field( wp_unslash( $_POST['order'] ) ) : '';
629 - $wgids = isset( $_POST['wgids'] ) ? sanitize_text_field( wp_unslash( $_POST['wgids'] ) ) : '';
416 + MainWP_Cache::initSession();
630 417
631 - $wgs_orders = array();
418 + MainWP_Post::renderTable( false, $_POST[ 'keyword' ], $_POST[ 'dtsstart' ], $_POST[ 'dtsstop' ], $_POST[ 'status' ], (isset( $_POST[ 'groups' ] ) ? $_POST[ 'groups' ] : '' ), (isset( $_POST[ 'sites' ] ) ? $_POST[ 'sites' ] : '' ), $_POST[ 'postId' ], $_POST[ 'userId' ], $post_type, $_POST[ 'search_on' ] );
632 419
633 - if ( ! empty( $wgids ) ) {
634 - $wgids = json_decode( $wgids, true );
635 - $order = json_decode( $order, true );
636 - if ( is_array( $wgids ) && is_array( $order ) ) {
637 - foreach ( $wgids as $idx => $wgid ) {
638 - if ( isset( $order[ $idx ] ) ) {
639 - $pre = 'widget-';
640 - if ( 0 === strpos( $wgid, $pre ) ) {
641 - $wgid = substr( $wgid, strlen( $pre ) );
642 - }
643 - $wgs_orders[ $wgid ] = $order[ $idx ];
644 - }
645 - }
646 - }
647 - }
420 + die();
421 + }
648 422
649 - if ( 'mainwp_page_manageclients' === $page ) {
650 - $item_id = isset( $_POST['item_id'] ) ? intval( $_POST['item_id'] ) : 0;
651 - $sorted_array = get_user_option( 'mainwp_widgets_sorted_' . strtolower( $page ) );
652 - if ( ! empty( $sorted_array ) ) {
653 - $sorted_array = json_decode( $sorted_array, true );
654 - }
655 - if ( ! is_array( $sorted_array ) ) {
656 - $sorted_array = array();
657 - }
658 - $sorted_array[ $item_id ] = $wgs_orders;
659 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $sorted_array ), true );
660 - } else {
661 - update_user_option( $user->ID, 'mainwp_widgets_sorted_' . $page, wp_json_encode( $wgs_orders ), true );
662 - }
423 + function mainwp_posts_get_terms() {
424 + $this->secure_request();
425 + MainWP_Post::getTerms( $_POST[ 'selected_site' ], $_POST[ 'prefix' ], $_POST[ 'what' ], $_POST[ 'generate_type' ] );
426 + die();
427 + }
428 +
429 + function mainwp_posts_test_post() {
430 + $this->secure_request();
431 + MainWP_Post::testPost();
432 + die();
433 + }
434 +
435 + function mainwp_get_categories() {
436 + $this->secure_request();
437 + MainWP_Post::getCategories();
438 + die();
439 + }
440 +
441 + function mainwp_post_get_edit() {
442 + $this->secure_request( 'mainwp_post_get_edit' );
443 + MainWP_Post::getPost(); // to edit
444 + die();
445 + }
446 +
447 + /**
448 + * Page: Pages
449 + */
450 + function mainwp_pages_search() {
451 + $this->secure_request();
452 + if ( isset( $_POST[ 'maximum' ] ) ) {
453 + MainWP_Utility::update_option( 'mainwp_maximumPages', MainWP_Utility::ctype_digit( $_POST[ 'maximum' ] ) ? intval( $_POST[ 'maximum' ] ) : 50 );
454 + }
455 +
456 + MainWP_Cache::initSession();
457 +
458 + MainWP_Page::renderTable( false, $_POST[ 'keyword' ], $_POST[ 'dtsstart' ], $_POST[ 'dtsstop' ], $_POST[ 'status' ], ( isset( $_POST[ 'groups' ] ) ? $_POST[ 'groups' ] : '' ), ( isset( $_POST[ 'sites' ] ) ? $_POST[ 'sites' ] : '' ), $_POST[ 'search_on' ] );
459 + die();
460 + }
461 +
462 + /**
463 + * Page: Users
464 + */
465 + function mainwp_user_delete() {
466 + $this->secure_request( 'mainwp_user_delete' );
467 +
468 + MainWP_User::delete();
469 + }
470 +
471 + function mainwp_user_edit() {
472 + $this->secure_request( 'mainwp_user_edit' );
473 +
474 + MainWP_User::edit();
475 + }
476 +
477 + function mainwp_user_update_password() {
478 + $this->secure_request( 'mainwp_user_update_password' );
479 +
480 + MainWP_User::updatePassword();
481 + }
482 +
483 + function mainwp_user_update_user() {
484 + $this->secure_request( 'mainwp_user_update_user' );
485 +
486 + MainWP_User::updateUser();
487 + }
488 +
489 + /**
490 + * Page: Recent Posts
491 + */
492 + function mainwp_post_unpublish() {
493 + $this->secure_request( 'mainwp_post_unpublish' );
494 +
495 + MainWP_Recent_Posts::unpublish();
496 + }
497 +
498 + function mainwp_post_publish() {
499 + $this->secure_request( 'mainwp_post_publish' );
500 +
501 + MainWP_Recent_Posts::publish();
502 + }
503 +
504 + function mainwp_post_approve() {
505 + $this->secure_request( 'mainwp_post_approve' );
506 +
507 + MainWP_Recent_Posts::approve();
508 + }
509 +
510 + function mainwp_post_trash() {
511 + $this->secure_request( 'mainwp_post_trash' );
512 +
513 + MainWP_Recent_Posts::trash();
514 + }
515 +
516 + function mainwp_post_delete() {
517 + $this->secure_request( 'mainwp_post_delete' );
518 +
519 + MainWP_Recent_Posts::delete();
520 + }
521 +
522 + function mainwp_post_restore() {
523 + $this->secure_request( 'mainwp_post_restore' );
524 +
525 + MainWP_Recent_Posts::restore();
526 + }
527 +
528 + /**
529 + * Page: Recent Pages
530 + */
531 + function mainwp_page_unpublish() {
532 + $this->secure_request( 'mainwp_page_unpublish' );
533 +
534 + MainWP_Page::unpublish();
535 + }
536 +
537 + function mainwp_page_publish() {
538 + $this->secure_request( 'mainwp_page_publish' );
539 +
540 + MainWP_Page::publish();
541 + }
542 +
543 + function mainwp_page_trash() {
544 + $this->secure_request( 'mainwp_page_trash' );
545 +
546 + MainWP_Page::trash();
547 + }
548 +
549 + function mainwp_page_delete() {
550 + $this->secure_request( 'mainwp_page_delete' );
551 +
552 + MainWP_Page::delete();
553 + }
554 +
555 + function mainwp_page_restore() {
556 + $this->secure_request( 'mainwp_page_restore' );
557 +
558 + MainWP_Page::restore();
559 + }
560 +
561 + /**
562 + * Page: ManageTips
563 + */
564 + function mainwp_managetips_update() {
565 + $this->secure_request( 'mainwp_managetips_update' );
566 +
567 + MainWP_Manage_Tips::updateTipSettings();
568 + die();
569 + }
570 +
571 + // Hide after installtion notices (PHP version, Trust MainWP Child, Multisite Warning and OpenSSL warning)
572 + function mainwp_notice_status_update() {
573 + $this->secure_request( 'mainwp_notice_status_update' );
574 +
575 + global $current_user;
576 + if ( ( $user_id = $current_user->ID ) ) {
577 + $status = get_user_option( 'mainwp_notice_saved_status' );
578 + if ( !is_array( $status ) ) {
579 + $status = array();
580 + }
581 + $status[ $_POST[ 'notice_id' ] ] = 1;
582 + update_user_option( $user_id, 'mainwp_notice_saved_status', $status );
583 + }
584 + die( 1 );
585 + }
586 +
587 + function mainwp_status_saving() {
588 + $this->secure_request( 'mainwp_status_saving' );
589 + $values = get_option( 'mainwp_status_saved_values' );
590 +
591 + if ( !isset( $_POST[ 'status' ] ) ) {
592 + die( -1 );
593 + }
594 +
595 + if ( 'last_sync_sites' == $_POST[ 'status' ] ) {
596 + update_option( 'mainwp_last_synced_all_sites', time() );
597 + do_action( 'mainwp_synced_all_sites' );
598 + die( 'ok' );
599 + }
600 +
601 + if ( !isset( $_POST[ 'value' ] ) || empty( $_POST[ 'value' ] ) ) {
602 + if ( isset( $values[ $_POST[ 'status' ] ] ) )
603 + unset( $values[ $_POST[ 'status' ] ] );
604 + } else {
605 + $values[ $_POST[ 'status' ] ] = $_POST[ 'value' ];
606 + }
607 +
608 + update_option( 'mainwp_status_saved_values', $values );
609 + die( 'ok' );
610 + }
611 +
612 + function ajax_widgets_order() {
613 +
614 + $this->secure_request( 'mainwp_widgets_order' );
615 + if ( $user = wp_get_current_user() ) {
616 + update_user_option($user->ID, "mainwp_widgets_sorted_" . $_POST['page'], (isset($_POST['order']) ? $_POST['order'] : ''), true);
663 617 die( 'ok' );
664 618 }
665 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
666 619 die( -1 );
620 +
667 621 }
622 +
623 + function ajax_mainwp_save_settings() {
624 + $this->secure_request( 'mainwp_save_settings' );
625 + $option_name = 'mainwp_' . $_POST['name'];
626 + $val = $_POST['value'];
668 627
669 - /**
670 - * Method ajax_mainwp_save_settings()
671 - *
672 - * Update saved MainWP Settings.
673 - *
674 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
675 - */
676 - public function ajax_mainwp_save_settings() {
677 - $this->secure_request( 'mainwp_save_settings' );
678 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
679 - $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '';
680 - if ( ! empty( $name ) ) {
681 - $option_name = 'mainwp_' . $name;
682 - $val = isset( $_POST['value'] ) ? sanitize_text_field( wp_unslash( $_POST['value'] ) ) : '';
683 - MainWP_Utility::update_option( $option_name, $val );
684 - }
685 - // phpcs:enable
686 - die( 'ok' );
628 + MainWP_Utility::update_option( $option_name, $val );
629 +
630 + die( 'ok' );
687 631 }
632 +
633 + function mainwp_leftmenu_filter_group() {
634 + $this->secure_request( 'mainwp_leftmenu_filter_group' );
635 + if ( isset( $_POST[ 'group_id' ] ) && !empty( $_POST[ 'group_id' ] ) ) {
636 + $ids = '';
637 + $websites = MainWP_DB::Instance()->query( MainWP_DB::Instance()->getSQLWebsitesByGroupId( $_POST[ 'group_id' ], true ) );
638 + while ( $websites && ( $website = @MainWP_DB::fetch_object( $websites ) ) ) {
639 + $ids .= $website->id . ',';
640 + }
641 + @MainWP_DB::free_result( $websites );
642 + $ids = rtrim( $ids, ',' );
643 + die( $ids );
644 + }
645 + die( '' );
646 + }
688 647
689 - /**
690 - * Method ajax_guided_tours_option_update()
691 - *
692 - * Update saved MainWP Settings.
693 - *
694 - * @uses \MainWP\Dashboard\MainWP_Utility::update_option()
695 - */
696 - public function ajax_guided_tours_option_update() {
697 - $this->secure_request( 'mainwp_guided_tours_option_update' );
698 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
699 - $enable = isset( $_POST['enable'] ) ? intval( $_POST['enable'] ) : 0;
700 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
701 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', $enable );
702 - die( 'ok ' . intval( $enable ) );
703 - }
648 + function mainwp_tips_update() {
649 + $this->secure_request( 'mainwp_tips_update' );
704 650
705 - /**
706 - * Method mainwp_leftmenu_filter_group()
707 - *
708 - * MainWP left menu filter by group.
709 - *
710 - * @uses \MainWP\Dashboard\MainWP_DB::query()
711 - * @uses \MainWP\Dashboard\MainWP_DB::get_websites_by_group_id()
712 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
713 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
714 - */
715 - public function mainwp_leftmenu_filter_group() {
716 - $this->secure_request( 'mainwp_leftmenu_filter_group' );
651 + global $current_user;
652 + if ( ( $user_id = $current_user->ID ) && isset( $_POST[ 'tipId' ] ) && !empty( $_POST[ 'tipId' ] ) ) {
653 + $user_tips = get_user_option( 'mainwp_hide_user_tips' );
654 + if ( !is_array( $user_tips ) ) {
655 + $user_tips = array();
656 + }
657 + $user_tips[ $_POST[ 'tipId' ] ] = time();
658 + update_user_option( $user_id, 'mainwp_hide_user_tips', $user_tips );
659 + }
660 + die( 1 );
661 + }
717 662
718 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
719 - $gid = isset( $_POST['group_id'] ) ? intval( $_POST['group_id'] ) : false;
720 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
663 +
664 + function mainwp_dismiss_twit() {
665 + $this->secure_request( 'mainwp_dismiss_twit' );
721 666
722 - if ( ! empty( $gid ) ) {
723 - $ids = '';
724 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $gid, true ) );
725 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
726 - $ids .= $website->id . ',';
727 - }
728 - MainWP_DB::free_result( $websites );
729 - $ids = rtrim( $ids, ',' );
730 - die( $ids ); // phpcs:ignore WordPress.Security.EscapeOutput
731 - }
732 - die( '' );
733 - }
667 + global $current_user;
668 + if ( ( $user_id = $current_user->ID ) && isset( $_POST['twitId'] ) && ! empty( $_POST['twitId'] ) && isset( $_POST['what'] ) && ! empty( $_POST['what'] ) ) {
669 + MainWP_Twitter::clearTwitterInfo( $_POST['what'], $_POST['twitId'] );
670 + }
671 + die( 1 );
672 + }
673 +
674 + function dismiss_activate_notice() {
675 + $this->secure_request( 'mainwp_dismiss_activate_notice' );
734 676
735 - /**
736 - * Method dismiss_activate_notice()
737 - *
738 - * Dismiss activate notice.
739 - */
740 - public function dismiss_activate_notice() {
741 - $this->secure_request( 'mainwp_dismiss_activate_notice' );
677 + global $current_user;
678 + if ( ( $user_id = $current_user->ID ) && isset( $_POST[ 'slug' ] ) && !empty( $_POST[ 'slug' ] ) ) {
679 + $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
680 + if ( !is_array( $activate_notices ) ) {
681 + $activate_notices = array();
682 + }
683 + $activate_notices[ $_POST[ 'slug' ] ] = time();
684 + update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
685 + }
686 + die( 1 );
687 + }
688 +
689 + function mainwp_twitter_dashboard_action() {
690 +
691 + $success = false;
692 + if ( isset( $_POST['actionName'] ) && isset( $_POST['countSites'] ) && ! empty( $_POST['countSites'] ) ) {
693 + $success = MainWP_Twitter::updateTwitterInfo( $_POST['actionName'], $_POST['countSites'], (int) $_POST['countSeconds'], ( isset( $_POST['countRealItems'] ) ? $_POST['countRealItems'] : 0 ), time(), ( isset( $_POST['countItems'] ) ? $_POST['countItems'] : 0 ) );
694 + }
742 695
743 - /**
744 - * Current user global.
745 - *
746 - * @global string
747 - */
748 - global $current_user;
749 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
750 - $user_id = $current_user->ID;
751 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
752 - if ( $user_id && ! empty( $slug ) ) {
753 - $activate_notices = get_user_option( 'mainwp_hide_activate_notices' );
754 - if ( ! is_array( $activate_notices ) ) {
755 - $activate_notices = array();
756 - }
696 + if ( isset( $_POST['showNotice'] ) && ! empty( $_POST['showNotice'] ) ) {
697 + if ( MainWP_Twitter::enabledTwitterMessages() ) {
698 + $twitters = MainWP_Twitter::getTwitterNotice( $_POST['actionName'] );
699 + $html = '';
700 + if ( is_array( $twitters ) ) {
701 + foreach ( $twitters as $timeid => $twit_mess ) {
702 + if ( ! empty( $twit_mess ) ) {
703 + $sendText = MainWP_Twitter::getTwitToSend( $_POST['actionName'], $timeid );
704 + $html .= '<div class="mainwp-tips mainwp-notice mainwp-notice-blue twitter"><span class="mainwp-tip" twit-what="' . esc_attr($_POST['actionName']) . '" twit-id="' . $timeid . '">' . $twit_mess . '</span>&nbsp;' . MainWP_Twitter::genTwitterButton( $sendText, false ) . '<span><a href="#" class="mainwp-dismiss-twit mainwp-right" ><i class="fa fa-times-circle"></i> ' . __( 'Dismiss', 'mainwp' ) . '</a></span></div>';
705 + }
706 + }
707 + }
708 + die( $html );
709 + }
710 + } else if ( $success ) {
711 + die( 'ok' );
712 + }
757 713
758 - $activate_notices[ $slug ] = time();
759 - update_user_option( $user_id, 'mainwp_hide_activate_notices', $activate_notices );
760 - }
761 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
762 - die( 1 );
763 - }
714 + die( '' );
715 + }
716 +
717 + function mainwp_reset_usercookies() {
718 + $this->secure_request();
764 719
720 + global $current_user;
721 + if ( ( $user_id = $current_user->ID ) && isset( $_POST[ 'what' ] ) && !empty( $_POST[ 'what' ] ) ) {
722 + $user_cookies = get_user_option( 'mainwp_saved_user_cookies' );
723 + if ( !is_array( $user_cookies ) ) {
724 + $user_cookies = array();
725 + }
726 + if ( !isset( $user_cookies[ $_POST[ 'what' ] ] ) ) {
727 + $user_cookies[ $_POST[ 'what' ] ] = 1;
728 + update_user_option( $user_id, 'mainwp_saved_user_cookies', $user_cookies );
729 + }
730 + }
731 + die( 1 );
732 + }
765 733
734 + /**
735 + * Page: SecurityIssues
736 + */
737 + function mainwp_securityIssues_request() {
738 + $this->secure_request( 'mainwp_securityIssues_request' );
766 739
767 - /**
768 - * Method mainwp_security_issues_request()
769 - *
770 - * Post handler for,
771 - * Page: SecurityIssues.
772 - *
773 - * @uses \MainWP\Dashboard\MainWP_Exception
774 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fetch_security_issues()
775 - */
776 - public function mainwp_security_issues_request() {
777 - $this->secure_request( 'mainwp_security_issues_request' );
740 + try {
741 + //die( json_encode( array( 'result' => MainWP_Security_Issues::fetchSecurityIssues() ) ) );
742 + wp_send_json( array( 'result' => MainWP_Security_Issues::fetchSecurityIssues() ) );
743 + } catch ( MainWP_Exception $e ) {
744 + die( json_encode( array(
745 + 'error' => array(
746 + 'message' => $e->getMessage(),
747 + 'extra' => $e->getMessageExtra(),
748 + ),
749 + ) ) );
750 + }
751 + }
778 752
779 - try {
780 - wp_send_json( array( 'result' => MainWP_Security_Issues::fetch_security_issues() ) );
781 - } catch ( MainWP_Exception $e ) {
782 - die(
783 - wp_json_encode(
784 - array(
785 - 'error' => array(
786 - 'message' => $e->getMessage(),
787 - 'extra' => $e->get_message_extra(),
788 - ),
789 - )
790 - )
791 - );
792 - }
793 - }
753 + function mainwp_securityIssues_fix() {
754 + $this->secure_request( 'mainwp_securityIssues_fix' );
794 755
795 - /**
796 - * Method mainwp_security_issues_fix()
797 - *
798 - * Post handler for 'fix issues',
799 - * Page: SecurityIssues.
800 - *
801 - * @uses \MainWP\Dashboard\MainWP_Exception
802 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::fix_security_issue()
803 - */
804 - public function mainwp_security_issues_fix() {
805 - $this->secure_request( 'mainwp_security_issues_fix' );
756 + try {
757 + //die( json_encode( array( 'result' => MainWP_Security_Issues::fixSecurityIssue() ) ) );
758 + wp_send_json( array( 'result' => MainWP_Security_Issues::fixSecurityIssue() ) );
759 + } catch ( MainWP_Exception $e ) {
760 + die( json_encode( array(
761 + 'error' => array(
762 + 'message' => $e->getMessage(),
763 + 'extra' => $e->getMessageExtra(),
764 + ),
765 + ) ) );
766 + }
767 + }
806 768
807 - try {
808 - wp_send_json( array( 'result' => MainWP_Security_Issues::fix_security_issue() ) );
809 - } catch ( MainWP_Exception $e ) {
810 - die(
811 - wp_json_encode(
812 - array(
813 - 'error' => array(
814 - 'message' => $e->getMessage(),
815 - 'extra' => $e->get_message_extra(),
816 - ),
817 - )
818 - )
819 - );
820 - }
821 - }
769 + function mainwp_securityIssues_unfix() {
770 + $this->secure_request( 'mainwp_securityIssues_unfix' );
822 771
823 - /**
824 - * Method mainwp_security_issues_unfix()
825 - *
826 - * Post handler for 'unfix issues',
827 - * Page: SecurityIssues.
828 - *
829 - * @uses \MainWP\Dashboard\MainWP_Exception
830 - * @uses \MainWP\Dashboard\MainWP_Security_Issues::unfix_security_issue()
831 - */
832 - public function mainwp_security_issues_unfix() {
833 - $this->secure_request( 'mainwp_security_issues_unfix' );
772 + try {
773 + //die( json_encode( array( 'result' => MainWP_Security_Issues::unfixSecurityIssue() ) ) );
774 + wp_send_json( array( 'result' => MainWP_Security_Issues::unfixSecurityIssue() ) );
775 + } catch ( MainWP_Exception $e ) {
776 + die( json_encode( array(
777 + 'error' => array(
778 + 'message' => $e->getMessage(),
779 + 'extra' => $e->getMessageExtra(),
780 + ),
781 + ) ) );
782 + }
783 + }
834 784
835 - try {
836 - wp_send_json( array( 'result' => MainWP_Security_Issues::unfix_security_issue() ) );
837 - } catch ( MainWP_Exception $e ) {
838 - die(
839 - wp_json_encode(
840 - array(
841 - 'error' => array(
842 - 'message' => $e->getMessage(),
843 - 'extra' => $e->get_message_extra(),
844 - ),
845 - )
846 - )
847 - );
848 - }
849 - }
850 785
851 - /**
852 - * Method ajax_disconnect_site()
853 - *
854 - * Disconnect Child Site.
855 - *
856 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
857 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
858 - */
859 - public function ajax_disconnect_site() {
860 - $this->secure_request( 'mainwp_disconnect_site' );
861 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
862 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
863 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
786 + public function ajax_disconnect_site() {
787 + $this->secure_request( 'mainwp_disconnect_site' );
864 788
865 - if ( empty( $siteid ) ) {
866 - die( wp_json_encode( array( 'error' => 'Error: site id empty' ) ) );
867 - }
789 + $siteid = $_POST['wp_id'];
868 790
869 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
791 + if ( empty( $siteid ) ) {
792 + die( json_encode( array( 'error' => 'Error: site id empty' ) ) );
793 + }
870 794
871 - if ( ! $website ) {
872 - die( wp_json_encode( array( 'error' => 'Not found site' ) ) );
873 - }
795 + $website = MainWP_DB::Instance()->getWebsiteById( $siteid );
874 796
875 - try {
876 - $information = MainWP_Connect::fetch_url_authed( $website, 'disconnect' );
877 - } catch ( \Exception $e ) {
878 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
879 - }
797 + if ( ! $website ) {
798 + die( json_encode( array( 'error' => 'Not found site' ) ) );
799 + }
880 800
801 + try {
802 + $information = MainWP_Utility::fetchUrlAuthed( $website, 'disconnect');
803 + } catch ( Exception $e ) {
804 + $information = array( 'error' => __( 'fetchUrlAuthed exception', 'mainwp' ) );
805 + }
806 +
807 + //die( json_encode( $information ) );
881 808 wp_send_json( $information );
882 809 }
883 810
884 - /**
885 - * Method ajax_sites_display_rows()
886 - *
887 - * Display rows via ajax,
888 - * Page: Manage Sites.
889 - *
890 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::ajax_optimize_display_rows()
891 - */
892 - public function ajax_sites_display_rows() {
893 - $this->secure_request( 'mainwp_manage_sites_display_rows' );
894 - MainWP_Manage_Sites::ajax_optimize_display_rows();
811 + public function ajax_display_rows() {
812 + $this->secure_request( 'mainwp_manage_display_rows' );
813 + MainWP_Manage_Sites::display_rows();
895 814 }
896 815
897 - /**
898 - * Method ajax_monitoring_display_rows()
899 - *
900 - * Display rows via ajax,
901 - * Page: Monitoring Sites.
902 - *
903 - * @uses \MainWP\Dashboard\MainWP_Monitoring::ajax_optimize_display_rows()
904 - */
905 - public function ajax_monitoring_display_rows() {
906 - $this->secure_request( 'mainwp_monitoring_sites_display_rows' );
907 - MainWP_Monitoring::ajax_optimize_display_rows();
908 - }
816 + /**
817 + * Page: CloneSite
818 + */
819 + // function mainwp_clonesite_check_backups()
820 + // {
821 + // die(MainWPCloneSite::render_check_backups());
822 + // }
823 + // function mainwp_clone()
824 + // {
825 + // die(MainWPCloneSite::render_clone());
826 + // }
827 + // function mainwp_clone_test_ftp()
828 + // {
829 + // die(MainWPCloneSite::testFTP());
830 + // }
909 831
832 + /*
833 + * Page: Backup
834 + */
835 + function mainwp_backup_run_site() {
836 + $this->secure_request( 'mainwp_backup_run_site' );
910 837
911 - /**
912 - * Method mainwp_bulkadduser()
913 - *
914 - * Bulk Add User for,
915 - * Page: BulkAddUser.
916 - *
917 - * @uses \MainWP\Dashboard\MainWP_User::do_bulk_add()
918 - */
919 - public function mainwp_bulkadduser() {
920 - $this->check_security( 'mainwp_bulkadduser' );
921 - MainWP_User::do_bulk_add();
922 - die();
923 - }
838 + try {
839 + if ( !isset( $_POST[ 'site_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'site_id' ] ) ) {
840 + throw new MainWP_Exception( 'Invalid request' );
841 + }
924 842
925 - /**
926 - * Method mainwp_importuser()
927 - *
928 - * Import user.
929 - *
930 - * @uses \MainWP\Dashboard\MainWP_User::do_import()
931 - */
932 - public function mainwp_importuser() {
933 - $this->secure_request( 'mainwp_importuser' );
934 - MainWP_User::do_import();
935 - }
843 + //die( json_encode( array( 'result' => MainWP_Manage_Sites::backup( $_POST[ 'site_id' ], 'full', '', '', 1, 1, 1, 1 ) ) ) );
844 + $ret = array( 'result' => MainWP_Manage_Sites::backup( $_POST['site_id'], 'full', '', '', 1, 1, 1, 1 ) );
845 + wp_send_json($ret);
846 + } catch ( MainWP_Exception $e ) {
847 + die( json_encode( array(
848 + 'error' => array(
849 + 'message' => $e->getMessage(),
850 + 'extra' => $e->getMessageExtra(),
851 + ),
852 + ) ) );
853 + }
854 + }
936 855
937 - /**
938 - * Method mainwp_clients_add_client()
939 - *
940 - * Add Client for,
941 - * Page: BulkAddClient.
942 - */
943 - public function mainwp_clients_add_client() {
944 - $this->check_security( 'mainwp_clients_add_client' );
945 - MainWP_Client::add_client();
946 - die();
947 - }
856 + function mainwp_backup() {
857 + $this->secure_request( 'mainwp_backup' );
948 858
949 - /**
950 - * Method mainwp_clients_delete_client()
951 - *
952 - * Add Client for,
953 - * Page: BulkAddClient.
954 - */
955 - public function mainwp_clients_delete_client() {
956 - $this->check_security( 'mainwp_clients_delete_client' );
957 - $ret = array( 'success' => false );
958 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
959 - $client_id = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
960 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
961 - if ( $client_id ) {
962 - MainWP_DB_Client::instance()->delete_client( $client_id );
963 - $ret['success'] = 'SUCCESS';
964 - $ret['result'] = esc_html__( 'Client removed successfully.', 'mainwp' );
965 - } else {
966 - $ret['result'] = esc_html__( 'Client ID empty.', 'mainwp' );
967 - }
859 + try {
860 + if ( !isset( $_POST[ 'site_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'site_id' ] ) ) {
861 + throw new MainWP_Exception( 'Invalid request' );
862 + }
968 863
969 - echo wp_json_encode( $ret );
970 - exit;
971 - }
864 + $excludedFolder = trim( $_POST[ 'exclude' ], "\n" );
865 + $excludedFolder = explode( "\n", $excludedFolder );
866 + $excludedFolder = array_map( array( 'MainWP_Utility', 'trimSlashes' ), $excludedFolder );
867 + $excludedFolder = array_map( 'htmlentities', $excludedFolder );
868 + $excludedFolder = implode( ',', $excludedFolder );
972 869
973 - /**
974 - * Method mainwp_clients_save_field()
975 - *
976 - * Save client custom fields.
977 - */
978 - public function mainwp_clients_save_field() {
979 - $this->check_security( 'mainwp_clients_save_field' );
980 - MainWP_Client::save_client_field();
981 - die();
982 - }
870 + $result = MainWP_Manage_Sites::backup( $_POST[ 'site_id' ], $_POST[ 'type' ], ( isset( $_POST[ 'subfolder' ] ) ? $_POST[ 'subfolder' ] : '' ), $excludedFolder, $_POST[ 'excludebackup' ], $_POST[ 'excludecache' ], $_POST[ 'excludenonwp' ], $_POST[ 'excludezip' ], $_POST[ 'filename' ], isset( $_POST[ 'fileNameUID' ] ) ? $_POST[ 'fileNameUID' ] : '', $_POST[ 'archiveFormat' ], ( isset($_POST[ 'maximumFileDescriptorsOverride' ]) && $_POST[ 'maximumFileDescriptorsOverride' ] == 1 ), ( $_POST[ 'maximumFileDescriptorsAuto' ] == 1 ), (isset($_POST[ 'maximumFileDescriptors' ]) ? $_POST[ 'maximumFileDescriptors' ] : '') , ( isset( $_POST[ 'loadFilesBeforeZip' ] ) ? $_POST[ 'loadFilesBeforeZip' ] : '' ), $_POST[ 'pid' ], ( isset( $_POST[ 'append' ] ) && ( $_POST[ 'append' ] == 1 ) ) );
871 + //die( json_encode( array( 'result' => $result ) ) );
872 + wp_send_json( array( 'result' => $result ) );
873 + } catch ( MainWP_Exception $e ) {
874 + die( json_encode( array(
875 + 'error' => array(
876 + 'message' => $e->getMessage(),
877 + 'extra' => $e->getMessageExtra(),
878 + ),
879 + ) ) );
880 + }
881 + }
983 882
883 + function mainwp_backup_checkpid() {
884 + $this->secure_request( 'mainwp_backup_checkpid' );
984 885
985 - /**
986 - * Method mainwp_clients_delete_general_field()
987 - *
988 - * Delete client general fields.
989 - */
990 - public function mainwp_clients_delete_general_field() {
991 - $this->check_security( 'mainwp_clients_delete_general_field' );
992 - $ret = array( 'success' => false );
993 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
994 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
995 - $client_id = 0; // 0 general fields.
996 - if ( MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
997 - $ret['success'] = true;
998 - }
999 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1000 - echo wp_json_encode( $ret );
1001 - exit;
1002 - }
886 + try {
887 + if ( !isset( $_POST[ 'site_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'site_id' ] ) ) {
888 + throw new MainWP_Exception( 'Invalid request' );
889 + }
1003 890
891 + //die( json_encode( MainWP_Manage_Sites::backupCheckpid( $_POST[ 'site_id' ], $_POST[ 'pid' ], $_POST[ 'type' ], $_POST[ 'subfolder' ], $_POST[ 'filename' ] ) ) );
892 + wp_send_json( MainWP_Manage_Sites::backupCheckpid( $_POST['site_id'], $_POST['pid'], $_POST['type'], (isset($_POST['subfolder']) ? $_POST['subfolder'] : ''), $_POST['filename'] ) );
893 + } catch ( MainWP_Exception $e ) {
894 + die( json_encode( array(
895 + 'error' => array(
896 + 'message' => $e->getMessage(),
897 + 'extra' => $e->getMessageExtra(),
898 + ),
899 + ) ) );
900 + }
901 + }
1004 902
1005 - /**
1006 - * Method mainwp_clients_delete_field()
1007 - *
1008 - * Delete client custom fields.
1009 - */
1010 - public function mainwp_clients_delete_field() {
1011 - $this->check_security( 'mainwp_clients_delete_field' );
1012 - $ret = array( 'success' => false );
1013 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1014 - $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1015 - $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // $client_id > 0, individual token.
1016 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1017 - if ( $client_id && MainWP_DB_Client::instance()->delete_client_field_by( 'field_id', $field_id, $client_id ) ) {
1018 - $ret['success'] = true;
1019 - }
1020 - echo wp_json_encode( $ret );
1021 - exit;
1022 - }
903 + function mainwp_backup_download_file() {
904 + $this->secure_request( 'mainwp_backup_download_file' );
1023 905
1024 - /**
1025 - * Method mainwp_notes_save()
1026 - *
1027 - * Post handler for save notes on,
1028 - * Page: Manage Sites.
1029 - *
1030 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1031 - */
1032 - public function mainwp_notes_save() {
1033 - $this->secure_request( 'mainwp_notes_save' );
1034 - MainWP_Manage_Sites_Handler::save_note();
1035 - }
906 + try {
907 + if ( !isset( $_POST[ 'site_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'site_id' ] ) ) {
908 + throw new MainWP_Exception( 'Invalid request' );
909 + }
1036 910
1037 - /**
1038 - * Method mainwp_clients_notes_save()
1039 - *
1040 - * Post handler for save notes on,
1041 - * Page: Manage Sites.
1042 - *
1043 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1044 - */
1045 - public function mainwp_clients_notes_save() {
1046 - $this->secure_request( 'mainwp_clients_notes_save' );
1047 - MainWP_Client::save_note();
1048 - }
911 + die( json_encode( array( 'result' => MainWP_Manage_Sites::backupDownloadFile( $_POST[ 'site_id' ], $_POST[ 'type' ], $_POST[ 'url' ], $_POST[ 'local' ] ) ) ) );
912 + } catch ( MainWP_Exception $e ) {
913 + die( json_encode( array(
914 + 'error' => array(
915 + 'message' => $e->getMessage(),
916 + 'extra' => $e->getMessageExtra(),
917 + ),
918 + ) ) );
919 + }
920 + }
1049 921
1050 - /**
1051 - * Method mainwp_clients_suspend_client()
1052 - *
1053 - * Post handler for suspend client,
1054 - * Page: Manage Sites.
1055 - *
1056 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_Handler::save_note()
1057 - */
1058 - public function mainwp_clients_suspend_client() {
1059 - $this->secure_request( 'mainwp_clients_suspend_client' );
1060 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1061 - $clientid = isset( $_POST['clientid'] ) ? intval( $_POST['clientid'] ) : 0;
1062 - $suspended = isset( $_POST['suspend_status'] ) && ! empty( $_POST['suspend_status'] ) ? 1 : 0;
1063 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
922 + function mainwp_backup_delete_file() {
923 + $this->secure_request( 'mainwp_backup_delete_file' );
1064 924
1065 - if ( empty( $clientid ) ) {
1066 - wp_die( 'Error - empty client id!' );
1067 - }
925 + try {
926 + if ( !isset( $_POST[ 'site_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'site_id' ] ) ) {
927 + throw new MainWP_Exception( __( 'Invalid request!', 'mainwp' ) );
928 + }
1068 929
1069 - $params = array(
1070 - 'client_id' => $clientid,
1071 - 'suspended' => $suspended,
1072 - );
930 + die( json_encode( array( 'result' => MainWP_Manage_Sites::backupDeleteFile( $_POST[ 'site_id' ], $_POST[ 'file' ] ) ) ) );
931 + } catch ( MainWP_Exception $e ) {
932 + die( json_encode( array(
933 + 'error' => array(
934 + 'message' => $e->getMessage(),
935 + 'extra' => $e->getMessageExtra(),
936 + ),
937 + ) ) );
938 + }
939 + }
1073 940
1074 - MainWP_DB_Client::instance()->update_client( $params );
941 + function mainwp_createbackup_getfilesize() {
942 + $this->secure_request( 'mainwp_createbackup_getfilesize' );
1075 943
1076 - $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $clientid );
944 + try {
945 + if ( !isset( $_POST[ 'siteId' ] ) ) {
946 + throw new Exception( __( 'No site selected!', 'mainwp' ) );
947 + }
948 + $siteId = $_POST[ 'siteId' ];
949 + $fileName = $_POST[ 'fileName' ];
950 + $fileNameUID = $_POST[ 'fileNameUID' ];
951 + $type = $_POST[ 'type' ];
1077 952
1078 - /**
1079 - * Fires immediately after update client suspend/unsuspend.
1080 - *
1081 - * @since 4.5.1.1
1082 - *
1083 - * @param object $client client data.
1084 - * @param bool $suspended true|false.
1085 - */
1086 - do_action( 'mainwp_client_suspend', $client, $suspended );
953 + $website = MainWP_DB::Instance()->getWebsiteById( $siteId );
954 + if ( !$website ) {
955 + throw new Exception( __( 'No site selected!', 'mainwp' ) );
956 + }
1087 957
1088 - MainWP_DB_Client::instance()->suspend_unsuspend_websites_by_client_id( $clientid, $suspended );
958 + MainWP_Utility::endSession();
959 + //Send request to the childsite!
960 + $result = MainWP_Utility::fetchUrlAuthed( $website, 'createBackupPoll', array(
961 + 'fileName' => $fileName,
962 + 'fileNameUID' => $fileNameUID,
963 + 'type' => $type,
964 + ) );
1089 965
1090 - wp_die( 'success' );
1091 - }
966 + if ( !isset( $result[ 'size' ] ) ) {
967 + throw new Exception( __( 'Invalid response!', 'mainwp' ) );
968 + }
1092 969
1093 - /**
1094 - * Method mainwp_syncerrors_dismiss()
1095 - *
1096 - * Dismiss Sync errors for,
1097 - * Widget: RightNow.
1098 - *
1099 - * @uses \MainWP\Dashboard\MainWP_Updates_Overview::dismiss_sync_errors()
1100 - */
1101 - public function mainwp_syncerrors_dismiss() {
970 + if ( MainWP_Utility::ctype_digit( $result[ 'size' ] ) ) {
971 + $output = array( 'size' => $result[ 'size' ] );
972 + } else {
973 + $output = array();
974 + }
975 + } catch ( Exception $e ) {
976 + $output = array( 'error' => $e->getMessage() );
977 + }
1102 978
1103 - $this->secure_request( 'mainwp_syncerrors_dismiss' );
979 + die( json_encode( $output ) );
980 + }
1104 981
1105 - try {
1106 - die( wp_json_encode( array( 'result' => MainWP_Updates_Overview::dismiss_sync_errors() ) ) );
1107 - } catch ( \Exception $e ) {
1108 - die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
1109 - }
1110 - }
982 + function mainwp_backup_getfilesize() {
983 + $this->secure_request( 'mainwp_backup_getfilesize' );
1111 984
1112 - /**
1113 - * Method mainwp_events_notice_hide()
1114 - *
1115 - * Hide events notice.
1116 - */
1117 - public function mainwp_events_notice_hide() {
1118 - $this->secure_request( 'mainwp_events_notice_hide' );
1119 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1120 - if ( isset( $_POST['notice'] ) ) {
1121 - $current_options = get_option( 'mainwp_showhide_events_notice' );
1122 - if ( ! is_array( $current_options ) ) {
1123 - $current_options = array();
1124 - }
1125 - if ( 'first_site' === $_POST['notice'] ) {
1126 - update_option( 'mainwp_first_site_events_notice', '' );
1127 - } elseif ( 'request_reviews1' === $_POST['notice'] ) {
1128 - $current_options['request_reviews1'] = 15;
1129 - $current_options['request_reviews1_starttime'] = time();
1130 - } elseif ( 'request_reviews1_forever' === $_POST['notice'] || 'request_reviews2_forever' === $_POST['notice'] ) {
1131 - $current_options['request_reviews1'] = 'forever';
1132 - $current_options['request_reviews2'] = 'forever';
1133 - } elseif ( 'request_reviews2' === $_POST['notice'] ) {
1134 - $current_options['request_reviews2'] = 15;
1135 - $current_options['request_reviews2_starttime'] = time();
1136 - } elseif ( 'trust_child' === $_POST['notice'] ) {
1137 - $current_options['trust_child'] = 1;
1138 - } elseif ( 'multi_site' === $_POST['notice'] ) {
1139 - $current_options['hide_multi_site_notice'] = 1;
1140 - }
1141 - update_option( 'mainwp_showhide_events_notice', $current_options );
1142 - }
1143 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1144 - die( 'ok' );
1145 - }
985 + try {
986 + die( json_encode( array( 'result' => MainWP_Manage_Sites::backupGetFilesize( $_POST[ 'local' ] ) ) ) );
987 + } catch ( MainWP_Exception $e ) {
988 + die( json_encode( array(
989 + 'error' => array(
990 + 'message' => $e->getMessage(),
991 + 'extra' => $e->getMessageExtra(),
992 + ),
993 + ) ) );
994 + }
995 + }
1146 996
1147 - /**
1148 - * Method mainwp_showhide_sections()
1149 - *
1150 - * Show/Hide sections.
1151 - */
1152 - public function mainwp_showhide_sections() {
1153 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1154 - if ( isset( $_POST['sec'] ) && isset( $_POST['status'] ) ) {
1155 - $opts = get_option( 'mainwp_opts_showhide_sections' );
1156 - if ( ! is_array( $opts ) ) {
1157 - $opts = array();
1158 - }
1159 - $opts[ sanitize_text_field( wp_unslash( $_POST['sec'] ) ) ] = sanitize_text_field( wp_unslash( $_POST['status'] ) );
1160 - update_option( 'mainwp_opts_showhide_sections', $opts );
1161 - die( 'ok' );
1162 - }
1163 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1164 - die( 'failed' );
1165 - }
997 + function mainwp_backup_upload_checkstatus() {
998 + $this->secure_request( 'mainwp_backup_upload_checkstatus' );
1166 999
1167 - /**
1168 - * Method mainwp_saving_status()
1169 - *
1170 - * MainWP Saving Status.
1171 - */
1172 - public function mainwp_saving_status() {
1173 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1174 - if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'mainwp_ajax' ) ) {
1175 - die( esc_html__( 'WP nonce could not be verified. Please reload the page and try again.', 'mainwp' ) );
1176 - }
1177 - $saving_status = isset( $_POST['saving_status'] ) ? sanitize_text_field( wp_unslash( $_POST['saving_status'] ) ) : false;
1178 - if ( ! empty( $saving_status ) ) {
1179 - $current_options = get_option( 'mainwp_opts_saving_status' );
1180 - if ( ! is_array( $current_options ) ) {
1181 - $current_options = array();
1182 - }
1183 - if ( isset( $_POST['value'] ) ) {
1184 - $current_options[ $saving_status ] = sanitize_text_field( wp_unslash( $_POST['value'] ) );
1185 - }
1186 - update_option( 'mainwp_opts_saving_status', $current_options );
1187 - }
1188 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1189 - die( 'ok' );
1190 - }
1000 + try {
1001 + $array = get_option( 'mainwp_upload_progress' );
1002 + $info = apply_filters( 'mainwp_remote_destination_info', array(), $_POST[ 'remote_destination' ] );
1191 1003
1192 - /**
1193 - * Method ajax_recheck_http()
1194 - *
1195 - * Recheck Child Site http status code & message.
1196 - *
1197 - * @uses \MainWP\Dashboard\MainWP_Connect::check_ignored_http_code()
1198 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1199 - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::handle_check_website()
1200 - */
1201 - public function ajax_recheck_http() {
1202 - $this->check_security( 'mainwp_recheck_http' );
1203 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1204 - if ( ! isset( $_POST['websiteid'] ) || empty( $_POST['websiteid'] ) ) {
1205 - die( -1 );
1206 - }
1004 + if ( !is_array( $array ) || !isset( $array[ $_POST[ 'unique' ] ] ) || !isset( $array[ $_POST[ 'unique' ] ][ 'dts' ] ) ) {
1005 + die( json_encode( array( 'status' => 'stalled', 'info' => $info ) ) );
1006 + } else if ( isset( $array[ $_POST[ 'unique' ] ][ 'finished' ] ) ) {
1007 + die( json_encode( array( 'status' => 'done', 'info' => $info ) ) );
1008 + } else {
1009 + if ( $array[ $_POST[ 'unique' ] ][ 'dts' ] < ( time() - ( 2 * 60 ) ) ) { //2minutes
1010 + die( json_encode( array( 'status' => 'stalled', 'info' => $info ) ) );
1011 + } else {
1012 + die( json_encode( array( 'status' => 'busy', 'info' => $info ) ) );
1013 + }
1014 + }
1015 + } catch ( MainWP_Exception $e ) {
1016 + die( json_encode( array(
1017 + 'error' => array(
1018 + 'message' => $e->getMessage(),
1019 + 'extra' => $e->getMessageExtra(),
1020 + ),
1021 + ) ) );
1022 + }
1023 + }
1207 1024
1208 - $website = MainWP_DB::instance()->get_website_by_id( intval( $_POST['websiteid'] ) );
1209 - if ( empty( $website ) ) {
1210 - die( -1 );
1211 - }
1212 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1025 + function mainwp_backup_upload_getprogress() {
1026 + $this->secure_request( 'mainwp_backup_upload_getprogress' );
1213 1027
1214 - $result = MainWP_Monitoring_Handler::handle_check_website( $website );
1215 - $http_code = ( is_array( $result ) && isset( $result['httpCode'] ) ) ? $result['httpCode'] : 0;
1216 - $check_result = MainWP_Connect::check_ignored_http_code( $http_code );
1217 - die(
1218 - wp_json_encode(
1219 - array(
1220 - 'httpcode' => esc_html( $http_code ),
1221 - 'status' => $check_result ? 1 : 0,
1222 - )
1223 - )
1224 - );
1225 - }
1028 + try {
1029 + $array = get_option( 'mainwp_upload_progress' );
1226 1030
1227 - /**
1228 - * Method mainwp_ignore_http_response()
1229 - *
1230 - * Ignore Child Site https response.
1231 - *
1232 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1233 - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
1234 - */
1235 - public function mainwp_ignore_http_response() {
1236 - $this->check_security( 'mainwp_ignore_http_response' );
1237 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1238 - $siteid = isset( $_POST['websiteid'] ) ? intval( $_POST['websiteid'] ) : false;
1239 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1240 - if ( empty( $siteid ) ) {
1241 - die( -1 );
1242 - }
1031 + if ( !is_array( $array ) || !isset( $array[ $_POST[ 'unique' ] ] ) ) {
1032 + die( json_encode( array( 'result' => 0 ) ) );
1033 + } else if ( isset( $array[ $_POST[ 'unique' ] ][ 'finished' ] ) ) {
1034 + throw new MainWP_Exception( __( 'finished...', 'maiwnp' ) );
1035 + } else {
1036 + //die( json_encode( array( 'result' => ( isset( $array[ $_POST[ 'unique' ] ][ 'offset' ] ) ? $array[ $_POST[ 'unique' ] ][ 'offset' ] : $array[ $_POST[ 'unique' ] ] ) ) ) );
1037 + wp_send_json( array( 'result' => ( isset( $array[ $_POST['unique'] ]['offset'] ) ? $array[ $_POST['unique'] ]['offset'] : $array[ $_POST['unique'] ] ) ) );
1038 + }
1039 + } catch ( MainWP_Exception $e ) {
1040 + die( json_encode( array(
1041 + 'error' => array(
1042 + 'message' => $e->getMessage(),
1043 + 'extra' => $e->getMessageExtra(),
1044 + ),
1045 + ) ) );
1046 + }
1047 + }
1243 1048
1244 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1245 - if ( empty( $website ) ) {
1246 - die( -1 );
1247 - }
1049 + /*
1050 + * Page: BulkAddUser
1051 + */
1248 1052
1249 - MainWP_DB::instance()->update_website_values( $website->id, array( 'http_response_code' => '-1' ) );
1250 - die( wp_json_encode( array( 'ok' => 1 ) ) );
1251 - }
1053 + function mainwp_bulkadduser() {
1054 + if ( !$this->check_security( 'mainwp_bulkadduser' ) ) {
1055 + die( 'ERROR ' . json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1056 + }
1057 + MainWP_User::doBukAdd();
1058 + die();
1059 + }
1252 1060
1253 - /**
1254 - * Method mainwp_autoupdate_and_trust_child()
1255 - *
1256 - * Set MainWP Child Plugin to Trusted & AutoUpdate.
1257 - *
1258 - * @uses \MainWP\Dashboard\MainWP_Plugins_Handler::trust_plugin()
1259 - */
1260 - public function mainwp_autoupdate_and_trust_child() {
1261 - $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1262 - if ( 1 !== (int) get_option( 'mainwp_pluginAutomaticDailyUpdate' ) ) {
1263 - update_option( 'mainwp_pluginAutomaticDailyUpdate', 1 );
1264 - }
1265 - MainWP_Plugins_Handler::trust_plugin( 'mainwp-child/mainwp-child.php' );
1266 - die( 'ok' );
1267 - }
1061 + function mainwp_bulkuploadadduser() {
1062 + $this->secure_request();
1268 1063
1269 - /**
1270 - * Method mainwp_force_destroy_sessions()
1271 - *
1272 - * Force destroy sessions.
1273 - *
1274 - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1275 - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1276 - *
1277 - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1278 - */
1279 - public function mainwp_force_destroy_sessions() {
1280 - $this->secure_request( 'mainwp_force_destroy_sessions' );
1064 + MainWP_User::renderBulkUpload();
1065 + die();
1066 + }
1281 1067
1282 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1283 - $website_id = ( isset( $_POST['website_id'] ) ? (int) $_POST['website_id'] : 0 );
1284 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1285 - if ( ! MainWP_DB::instance()->get_website_by_id( $website_id ) ) {
1286 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'This website does not exist.', 'mainwp' ) ) ) ) );
1287 - }
1068 + function mainwp_importuser() {
1069 + $this->secure_request( 'mainwp_importuser' );
1288 1070
1289 - $website = MainWP_DB::instance()->get_website_by_id( $website_id );
1290 - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
1291 - die( wp_json_encode( array( 'error' => array( 'message' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1292 - }
1071 + MainWP_User::doImport();
1072 + }
1293 1073
1294 - try {
1295 - $information = MainWP_Connect::fetch_url_authed(
1296 - $website,
1297 - 'settings_tools',
1298 - array(
1299 - 'action' => 'force_destroy_sessions',
1300 - )
1301 - );
1302 - } catch ( \Exception $e ) {
1303 - $information = array( 'error' => esc_html__( 'fetch_url_authed exception', 'mainwp' ) );
1304 - }
1074 + /*
1075 + * Page: InstallPlugins/Themes
1076 + */
1305 1077
1306 - wp_send_json( $information );
1307 - }
1078 + function mainwp_preparebulkinstallplugintheme() {
1079 + $this->secure_request();
1308 1080
1309 - /**
1310 - * Method ajax_refresh_icon()
1311 - */
1312 - public function ajax_refresh_icon() {
1313 - $this->secure_request( 'mainwp_refresh_icon' );
1314 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1315 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1316 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1317 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1081 + MainWP_Install_Bulk::prepareInstall();
1082 + }
1318 1083
1319 - if ( empty( $slug ) ) {
1320 - wp_die( 'failed' );
1321 - }
1084 + function mainwp_installbulkinstallplugintheme() {
1085 + $this->secure_request( 'mainwp_installbulkinstallplugintheme' );
1322 1086
1323 - $fet_icon = MainWP_System_Utility::handle_get_icon( $slug, $type );
1087 + MainWP_Install_Bulk::performInstall();
1088 + }
1324 1089
1325 - if ( ! empty( $fet_icon ) ) {
1326 - wp_die( 'success' );
1327 - } else {
1328 - wp_die( 'failed' );
1329 - }
1330 - }
1090 + function mainwp_preparebulkuploadplugintheme() {
1091 + $this->secure_request();
1331 1092
1332 - /**
1333 - * Method ajax_upload_custom_icon()
1334 - */
1335 - public function ajax_upload_custom_icon() {
1336 - $this->secure_request( 'mainwp_upload_custom_icon' );
1337 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1338 - $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : '';
1339 - $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
1340 - $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
1093 + MainWP_Install_Bulk::prepareUpload();
1094 + }
1341 1095
1342 - if ( empty( $slug ) || ( 'plugin' !== $type && 'theme' !== $type ) ) {
1343 - wp_die( 'invalid data!' );
1344 - }
1096 + function mainwp_installbulkuploadplugintheme() {
1097 + $this->secure_request( 'mainwp_installbulkuploadplugintheme' );
1345 1098
1346 - $sub_folder = '';
1099 + MainWP_Install_Bulk::performUpload();
1100 + }
1347 1101
1348 - if ( 'plugin' === $type ) {
1349 - $sub_folder = 'plugin-icons';
1350 - } elseif ( 'theme' === $type ) {
1351 - $sub_folder = 'theme-icons';
1352 - } else {
1353 - wp_die( wp_json_encode( array( 'result' => 'invalid' ) ) );
1354 - }
1102 + function mainwp_cleanbulkuploadplugintheme() {
1103 + $this->secure_request( 'mainwp_cleanbulkuploadplugintheme' );
1355 1104
1356 - if ( $delete ) {
1357 - MainWP_System_Utility::update_cached_icons( '', $slug, $type, true );
1358 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1359 - }
1105 + MainWP_Install_Bulk::cleanUpload();
1106 + }
1360 1107
1361 - $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( $sub_folder, $_FILES['mainwp_upload_icon_uploader'], 0 ) : null;
1362 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1108 + /*
1109 + * Page: ManageGroups
1110 + */
1363 1111
1364 - $uploaded_icon = 'NOTCHANGE';
1365 - if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1366 - $uploaded_icon = $output['filename'];
1367 - }
1112 + function mainwp_group_rename() {
1113 + $this->secure_request( 'mainwp_group_rename' );
1368 1114
1369 - if ( 'NOTCHANGE' !== $uploaded_icon ) {
1370 - MainWP_System_Utility::update_cached_icons( $uploaded_icon, $slug, $type, true );
1371 - wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
1372 - } else {
1373 - wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
1374 - }
1375 - }
1115 + MainWP_Manage_Groups::renameGroup();
1116 + }
1376 1117
1377 - /**
1378 - * Method ajax_select_custom_theme()
1379 - */
1380 - public function ajax_select_custom_theme() {
1381 - $this->secure_request( 'mainwp_select_custom_theme' );
1382 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1383 - $theme = isset( $_POST['theme'] ) ? sanitize_text_field( wp_unslash( $_POST['theme'] ) ) : '';
1384 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1385 - if ( empty( $theme ) ) {
1386 - wp_die( 'failed' );
1387 - }
1118 + function mainwp_group_delete() {
1119 + $this->secure_request( 'mainwp_group_delete' );
1388 1120
1389 - $user = wp_get_current_user();
1390 - if ( empty( $user ) || empty( $user->ID ) ) {
1391 - wp_die( 'failed' );
1392 - }
1121 + MainWP_Manage_Groups::deleteGroup();
1122 + }
1393 1123
1394 - update_user_option( $user->ID, 'mainwp_selected_theme', $theme );
1395 - wp_die( 'success' );
1396 - }
1124 + function mainwp_group_add() {
1125 + $this->secure_request( 'mainwp_group_add' );
1397 1126
1127 + MainWP_Manage_Groups::addGroup();
1128 + }
1398 1129
1399 - /**
1400 - * Method ajax_site_actions_dismiss()
1401 - */
1402 - public function ajax_site_actions_dismiss() {
1403 - $this->secure_request( 'mainwp_site_actions_dismiss' );
1404 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1405 - $action_id = isset( $_POST['action_id'] ) ? intval( $_POST['action_id'] ) : 0;
1406 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1130 + function mainwp_group_getsites() {
1131 + $this->secure_request();
1407 1132
1408 - if ( empty( $action_id ) ) {
1409 - wp_die( 'failed' );
1410 - }
1411 - $update = array(
1412 - 'dismiss' => 1,
1413 - );
1414 - MainWP_DB_Site_Actions::instance()->update_action_by_id( $action_id, $update );
1415 - wp_die( 'success' );
1416 - }
1133 + die( MainWP_Manage_Groups::getSites() );
1134 + }
1417 1135
1418 - /**
1419 - * Method ajax_site_actions_dismiss()
1420 - */
1421 - public function ajax_delete_non_mainwp_actions() {
1422 - $this->secure_request( 'mainwp_delete_non_mainwp_actions' );
1423 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1424 - $siteid = isset( $_POST['wp_id'] ) ? intval( $_POST['wp_id'] ) : 0;
1425 - if ( empty( $siteid ) ) {
1426 - wp_die( wp_json_encode( array( 'error' => 'Empty site ID' ) ) );
1427 - }
1428 - // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1429 - $website = MainWP_DB::instance()->get_website_by_id( $siteid );
1430 - $success = false;
1431 - $error = '';
1432 - try {
1433 - $response = MainWP_Connect::fetch_url_authed( $website, 'delete_actions', array( 'del' => 'act' ) );
1434 - if ( is_array( $response ) ) {
1435 - if ( isset( $response['success'] ) ) {
1436 - $success = true;
1437 - } elseif ( isset( $response['error'] ) ) {
1438 - $error = $response['error'];
1439 - }
1440 - }
1441 - } catch ( \Exception $e ) {
1442 - // ok!
1443 - }
1444 - if ( $success ) {
1445 - MainWP_DB_Site_Actions::instance()->delete_action_by( 'wpid', $siteid );
1446 - wp_die( wp_json_encode( array( 'success' => 'ok' ) ) );
1447 - }
1136 + function mainwp_group_updategroup() {
1137 + $this->secure_request( 'mainwp_group_updategroup' );
1448 1138
1449 - if ( empty( $error ) ) {
1450 - $error = esc_html__( 'Undefined error. Please try again.', 'mainwp' );
1451 - }
1452 - wp_die( wp_json_encode( array( 'error' => $error ) ) );
1453 - }
1139 + MainWP_Manage_Groups::updateGroup();
1140 + }
1454 1141
1455 - /**
1456 - * Method ajax_import_demo_data().
1457 - */
1458 - public function ajax_import_demo_data() {
1459 - $this->secure_request( 'mainwp_import_demo_data' );
1460 - $data = MainWP_Demo_Handle::get_instance()->import_data_demo();
1461 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 );
1462 - wp_die( wp_json_encode( $data ) );
1463 - }
1142 + /*
1143 + * Page: ManageBackups
1144 + */
1464 1145
1465 - /**
1466 - * Method ajax_delete_demo_data().
1467 - */
1468 - public function ajax_delete_demo_data() {
1469 - $this->secure_request( 'mainwp_delete_demo_data' );
1470 - $data = MainWP_Demo_Handle::get_instance()->delete_data_demo();
1471 - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 0 );
1472 - wp_die( wp_json_encode( $data ) );
1473 - }
1146 + //Add task to the database
1147 + function mainwp_addbackup() {
1148 + $this->secure_request( 'mainwp_addbackup' );
1149 +
1150 + MainWP_Manage_Backups::addBackup();
1151 + }
1152 +
1153 + //Update task
1154 + function mainwp_updatebackup() {
1155 + $this->secure_request( 'mainwp_updatebackup' );
1156 +
1157 + MainWP_Manage_Backups::updateBackup();
1158 + }
1159 +
1160 + //Remove a task from MainWP
1161 + function mainwp_removebackup() {
1162 + $this->secure_request( 'mainwp_removebackup' );
1163 +
1164 + MainWP_Manage_Backups::removeBackup();
1165 + }
1166 +
1167 + function mainwp_resumebackup() {
1168 + $this->secure_request( 'mainwp_resumebackup' );
1169 +
1170 + MainWP_Manage_Backups::resumeBackup();
1171 + }
1172 +
1173 + function mainwp_pausebackup() {
1174 + $this->secure_request( 'mainwp_pausebackup' );
1175 +
1176 + MainWP_Manage_Backups::pauseBackup();
1177 + }
1178 +
1179 + function mainwp_backuptask_get_sites() {
1180 + $this->secure_request();
1181 +
1182 + $taskID = $_POST[ 'task_id' ];
1183 +
1184 + //die( json_encode( array( 'result' => MainWP_Manage_Backups::getBackupTaskSites( $taskID ) ) ) );
1185 + wp_send_json( array( 'result' => MainWP_Manage_Backups::getBackupTaskSites( $taskID ) ) );
1186 +
1187 + }
1188 +
1189 + function mainwp_backuptask_run_site() {
1190 + try {
1191 + $this->secure_request( 'mainwp_backuptask_run_site' );
1192 +
1193 + if ( !isset( $_POST[ 'site_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'site_id' ] ) || !isset( $_POST[ 'task_id' ] ) || !MainWP_Utility::ctype_digit( $_POST[ 'task_id' ] ) ) {
1194 + throw new MainWP_Exception( 'Invalid request' );
1195 + }
1196 +
1197 + //die( json_encode( array( 'result' => MainWP_Manage_Backups::backup( $_POST[ 'task_id' ], $_POST[ 'site_id' ], $_POST[ 'fileNameUID' ] ) ) ) );
1198 + wp_send_json( array( 'result' => MainWP_Manage_Backups::backup( $_POST['task_id'], $_POST['site_id'], $_POST['fileNameUID'] ) ) );
1199 + } catch ( MainWP_Exception $e ) {
1200 + die( json_encode( array(
1201 + 'error' => array(
1202 + 'message' => $e->getMessage(),
1203 + 'extra' => $e->getMessageExtra(),
1204 + ),
1205 + ) ) );
1206 + }
1207 + }
1208 +
1209 + function mainwp_backup_upload_file() {
1210 + try {
1211 + $this->secure_request( 'mainwp_backup_upload_file' );
1212 +
1213 + do_action( 'mainwp_remote_backup_extension_backup_upload_file' );
1214 +
1215 + throw new MainWP_Exception( __( 'Remote Backup extension has not been installed or activated.', 'mainwp' ) );
1216 + } catch ( MainWP_Exception $e ) {
1217 + die( json_encode( array(
1218 + 'error' => array(
1219 + 'message' => $e->getMessage(),
1220 + 'extra' => $e->getMessageExtra(),
1221 + ),
1222 + ) ) );
1223 + }
1224 + }
1225 +
1226 + /*
1227 + * Page: ManageSites
1228 + */
1229 +
1230 + //Check if WP can be added
1231 + function mainwp_checkwp() {
1232 + if ( $this->check_security( 'mainwp_checkwp', 'security' ) ) {
1233 + MainWP_Manage_Sites::checkSite();
1234 + } else {
1235 + die( json_encode( array( 'response' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
1236 + }
1237 + }
1238 +
1239 + //Add WP to the database
1240 + function mainwp_addwp() {
1241 + if ( $this->check_security( 'mainwp_addwp', 'security' ) ) {
1242 + MainWP_Manage_Sites::addSite();
1243 + } else {
1244 + die( json_encode( array( 'response' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
1245 + }
1246 + }
1247 +
1248 + function get_site_icon() {
1249 + if ( $this->check_security( 'mainwp_get_site_icon', 'security' ) ) {
1250 + $result = MainWP_System::sync_site_icon();
1251 + //die( json_encode( $result ) );
1252 + wp_send_json( $result );
1253 + } else {
1254 + die( json_encode( array( 'error' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
1255 + }
1256 + }
1257 +
1258 + function mainwp_ext_prepareinstallplugintheme() {
1259 +
1260 + do_action( 'mainwp_prepareinstallplugintheme' );
1261 + }
1262 +
1263 + function mainwp_ext_performinstallplugintheme() {
1264 +
1265 + do_action( 'mainwp_performinstallplugintheme' );
1266 + }
1267 +
1268 + function mainwp_ext_applypluginsettings() {
1269 + if ( $this->check_security( 'mainwp_ext_applypluginsettings', 'security' ) ) {
1270 + MainWP_Manage_Sites::apply_plugin_settings();
1271 + } else {
1272 + die( json_encode( array( 'error' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
1273 + }
1274 + }
1275 +
1276 + function mainwp_testwp() {
1277 + $this->secure_request( 'mainwp_testwp' );
1278 +
1279 + $url = null;
1280 + $name = null;
1281 + $http_user = null;
1282 + $http_pass = null;
1283 + $verifyCertificate = 1;
1284 + $sslVersion = 0;
1285 +
1286 + if ( isset( $_POST[ 'url' ] ) ) {
1287 + $url = $_POST[ 'url' ];
1288 +
1289 + $temp_url = MainWP_Utility::removeHttpPrefix( $url, true );
1290 +
1291 + if ( strpos( $temp_url, ":" ) ) {
1292 + die( json_encode( array( 'error' => __( 'Invalid URL.', 'mainwp' ) ) ) );
1293 + }
1294 +
1295 + $verifyCertificate = $_POST[ 'test_verify_cert' ];
1296 + $forceUseIPv4 = $_POST[ 'test_force_use_ipv4' ];
1297 + $sslVersion = $_POST['test_ssl_version'];
1298 + $http_user = $_POST[ 'http_user' ];
1299 + $http_pass = $_POST[ 'http_pass' ];
1300 +
1301 + } else if ( isset( $_POST[ 'siteid' ] ) ) {
1302 + $website = MainWP_DB::Instance()->getWebsiteById( $_POST[ 'siteid' ] );
1303 + if ( $website ) {
1304 + $url = $website->url;
1305 + $name = $website->name;
1306 + $verifyCertificate = $website->verify_certificate;
1307 + $forceUseIPv4 = $website->force_use_ipv4;
1308 + $sslVersion = $website->ssl_version;
1309 + $http_user = $website->http_user;
1310 + $http_pass = $website->http_pass;
1311 + }
1312 + }
1313 +
1314 + $rslt = MainWP_Utility::tryVisit( $url, $verifyCertificate, $http_user, $http_pass, $sslVersion, $forceUseIPv4 );
1315 +
1316 + if ( isset( $rslt[ 'error' ] ) && ( $rslt[ 'error' ] != '' ) && ( substr( $url, - 9 ) != 'wp-admin/' ) ) {
1317 + if ( substr( $url, - 1 ) != '/' ) {
1318 + $url .= '/';
1319 + }
1320 + $url .= 'wp-admin/';
1321 + $newrslt = MainWP_Utility::tryVisit( $url, $verifyCertificate, $http_user, $http_pass, $sslVersion, $forceUseIPv4 );
1322 + if ( isset( $newrslt[ 'error' ] ) && ( $rslt[ 'error' ] != '' ) ) {
1323 + $rslt = $newrslt;
1324 + }
1325 + }
1326 +
1327 + if ( $name != null ) {
1328 + $rslt[ 'sitename' ] = esc_html($name);
1329 + }
1330 +
1331 + //die( json_encode( $rslt ) );
1332 + wp_send_json( $rslt );
1333 + }
1334 +
1335 + //Remove a website from MainWP
1336 + function mainwp_removesite() {
1337 + if ( !mainwp_current_user_can( 'dashboard', 'delete_sites' ) ) {
1338 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'delete sites', 'mainwp' ), false ) ) ) );
1339 + }
1340 +
1341 + $this->secure_request( 'mainwp_removesite' );
1342 +
1343 + MainWP_Manage_Sites::removeSite();
1344 + }
1345 +
1346 + //Save note
1347 + function mainwp_notes_save() {
1348 + $this->secure_request( 'mainwp_notes_save' );
1349 +
1350 + MainWP_Manage_Sites::saveNote();
1351 + }
1352 +
1353 + function mainwp_reconnectwp() {
1354 + $this->secure_request();
1355 +
1356 + MainWP_Manage_Sites::reconnectSite();
1357 + }
1358 +
1359 + function mainwp_updatechildsite_value() {
1360 + $this->secure_request( 'mainwp_updatechildsite_value' );
1361 +
1362 + MainWP_Manage_Sites::updateChildsiteValue();
1363 + }
1364 +
1365 + /*
1366 + * Widget: RightNow
1367 + */
1368 +
1369 + function mainwp_syncsites() {
1370 + $this->secure_request( 'mainwp_syncsites' );
1371 + MainWP_Updates_Overview::dismissSyncErrors( false );
1372 + MainWP_Updates_Overview::syncSite();
1373 + }
1374 +
1375 + //Update a specific WP
1376 + function mainwp_upgradewp() {
1377 + if ( !mainwp_current_user_can( 'dashboard', 'update_wordpress' ) ) {
1378 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update WordPress', 'mainwp' ), $echo = false ) ) ) );
1379 + }
1380 +
1381 + $this->secure_request( 'mainwp_upgradewp' );
1382 +
1383 + try {
1384 + $id = null;
1385 + if ( isset( $_POST[ 'id' ] ) ) {
1386 + $id = $_POST[ 'id' ];
1387 + }
1388 + die( json_encode( array( 'result' => MainWP_Updates::upgradeSite( $id ) ) ) ); //ok
1389 + } catch ( MainWP_Exception $e ) {
1390 + die( json_encode( array(
1391 + 'error' => array(
1392 + 'message' => $e->getMessage(),
1393 + 'extra' => $e->getMessageExtra(),
1394 + ),
1395 + ) ) );
1396 + }
1397 + }
1398 +
1399 + //todo: rename
1400 + function mainwp_upgradeplugintheme() {
1401 +
1402 + if ( !isset($_POST['type'] ) )
1403 + die( json_encode( array( 'error' => '<i class="red times icon"></i> ' . __( 'Invalid request', 'mainwp' ) ) ) );
1404 +
1405 +
1406 + if ( $_POST[ 'type' ] == 'plugin' && !mainwp_current_user_can( 'dashboard', 'update_plugins' ) ) {
1407 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update plugins', 'mainwp' ), $echo = false ) ) ) );
1408 + }
1409 +
1410 + if ( $_POST[ 'type' ] == 'theme' && !mainwp_current_user_can( 'dashboard', 'update_themes' ) ) {
1411 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update themes', 'mainwp' ), $echo = false ) ) ) );
1412 + }
1413 +
1414 + if ( $_POST[ 'type' ] == 'translation' && !mainwp_current_user_can( 'dashboard', 'update_translations' ) ) {
1415 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'update translations', 'mainwp' ), $echo = false ) ) ) );
1416 + }
1417 +
1418 + $this->secure_request( 'mainwp_upgradeplugintheme' );
1419 +
1420 + // at the moment: support chunk update for manage sites page only
1421 + $chunk_support = isset( $_POST['chunk_support'] ) && $_POST['chunk_support'] ? true : false;
1422 + $max_update = 0;
1423 + $websiteId = null;
1424 + $slugs = '';
1425 +
1426 + if ( isset( $_POST['websiteId'] ) ) {
1427 + $websiteId = $_POST['websiteId'];
1428 +
1429 + if ($chunk_support) {
1430 + $max_update = apply_filters('mainwp_update_plugintheme_max', false, $websiteId );
1431 + if (empty($max_update)) {
1432 + $chunk_support = false; // there is not hook so disable chunk update support
1433 + }
1434 + }
1435 + if ( $chunk_support ) {
1436 + if (isset($_POST['chunk_slugs'])) {
1437 + $slugs = $_POST['chunk_slugs']; // chunk slugs send so use this
1438 + } else {
1439 + $slugs = MainWP_Updates::getPluginThemeSlugs( $websiteId, $_POST['type'] );
1440 + }
1441 + } else if ( isset( $_POST['slug'] ) ) {
1442 + $slugs = $_POST['slug'];
1443 + } else {
1444 + $slugs = MainWP_Updates::getPluginThemeSlugs( $websiteId, $_POST['type'] );
1445 + }
1446 + }
1447 +
1448 + if ( MainWP_DB::Instance()->backupFullTaskRunning( $websiteId ) ) {
1449 + die( json_encode( array( 'error' => __( 'Backup process in progress on the child site. Please, try again later.', 'mainwp' ) ) ) );
1450 + }
1451 +
1452 + $chunk_slugs = array();
1453 +
1454 + if ( $chunk_support ){
1455 + // calculate update slugs here
1456 + if ( $max_update ) {
1457 + $slugs = explode(",", $slugs);
1458 + $chunk_slugs = array_slice($slugs, $max_update);
1459 + $update_slugs = array_diff($slugs, $chunk_slugs);
1460 + $slugs = implode(",", $update_slugs);
1461 + }
1462 + }
1463 +
1464 + if ( empty( $slugs ) && ! $chunk_support ) {
1465 + die( json_encode( array( 'message' => __( 'Item slug could not be found. Update process could not be executed.', 'mainwp' ) ) ) );
1466 + }
1467 + $website = MainWP_DB::Instance()->getWebsiteById( $websiteId );
1468 + try {
1469 + $info = array( 'result' => MainWP_Updates::upgradePluginThemeTranslation( $websiteId, $_POST['type'], $slugs ) );
1470 +
1471 + if ( $chunk_support && (count($chunk_slugs) > 0) ) {
1472 + $info['chunk_slugs'] = implode(",", $chunk_slugs);
1473 + }
1474 +
1475 + if (!empty($website)) {
1476 + $info['site_url'] = esc_url($website->url);
1477 + }
1478 +// die( json_encode( $info ) );
1479 + wp_send_json( $info );
1480 + } catch ( MainWP_Exception $e ) {
1481 + die( json_encode( array(
1482 + 'error' => array(
1483 + 'message' => $e->getMessage(),
1484 + 'extra' => $e->getMessageExtra(),
1485 + ),
1486 + ) ) );
1487 + }
1488 +
1489 + }
1490 +
1491 + function mainwp_ignoreplugintheme() {
1492 + $this->secure_request( 'mainwp_ignoreplugintheme' );
1493 +
1494 + if ( !isset( $_POST[ 'id' ] ) ) {
1495 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1496 + }
1497 + wp_send_json( array( 'result' => MainWP_Updates::ignorePluginTheme( $_POST['type'], $_POST['slug'], $_POST['name'], $_POST['id'] ) ) );
1498 + }
1499 +
1500 + function mainwp_unignoreabandonedplugintheme() {
1501 + $this->secure_request( 'mainwp_unignoreabandonedplugintheme' );
1502 +
1503 + if ( !isset( $_POST[ 'id' ] ) ) {
1504 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1505 + }
1506 + die( json_encode( array( 'result' => MainWP_Updates::unIgnoreAbandonedPluginTheme( $_POST[ 'type' ], $_POST[ 'slug' ], $_POST[ 'id' ] ) ) ) ); // ok
1507 + }
1508 +
1509 + function mainwp_unignoreabandonedpluginsthemes() {
1510 + $this->secure_request( 'mainwp_unignoreabandonedpluginsthemes' );
1511 +
1512 + if ( !isset( $_POST[ 'slug' ] ) ) {
1513 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1514 + }
1515 + die( json_encode( array( 'result' => MainWP_Updates::unIgnoreAbandonedPluginsThemes( $_POST[ 'type' ], $_POST[ 'slug' ] ) ) ) );
1516 + }
1517 +
1518 + function mainwp_dismissoutdateplugintheme() {
1519 + $this->secure_request( 'mainwp_dismissoutdateplugintheme' );
1520 +
1521 + if ( !isset( $_POST[ 'id' ] ) ) {
1522 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1523 + }
1524 + die( json_encode( array( 'result' => MainWP_Updates::dismissPluginTheme( $_POST[ 'type' ], $_POST[ 'slug' ], $_POST[ 'name' ], $_POST[ 'id' ] ) ) ) );
1525 + }
1526 +
1527 + function mainwp_dismissoutdatepluginsthemes() {
1528 + $this->secure_request( 'mainwp_dismissoutdatepluginsthemes' );
1529 +
1530 + if ( !mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
1531 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
1532 + }
1533 +
1534 + if ( !isset( $_POST[ 'slug' ] ) ) {
1535 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1536 + }
1537 + die( json_encode( array( 'result' => MainWP_Updates::dismissPluginsThemes( $_POST[ 'type' ], $_POST[ 'slug' ], $_POST[ 'name' ] ) ) ) );
1538 + }
1539 +
1540 + function mainwp_unignoreplugintheme() {
1541 + $this->secure_request( 'mainwp_unignoreplugintheme' );
1542 +
1543 + if ( !isset( $_POST[ 'id' ] ) ) {
1544 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1545 + }
1546 + die( json_encode( array( 'result' => MainWP_Updates::unIgnorePluginTheme( $_POST[ 'type' ], $_POST[ 'slug' ], $_POST[ 'id' ] ) ) ) );
1547 + }
1548 +
1549 + function mainwp_ignorepluginsthemes() {
1550 + $this->secure_request( 'mainwp_ignorepluginsthemes' );
1551 +
1552 + if ( !mainwp_current_user_can( 'dashboard', 'ignore_unignore_updates' ) ) {
1553 + die( json_encode( array( 'error' => mainwp_do_not_have_permissions( __( 'ignore/unignore updates', 'mainwp' ) ) ) ) );
1554 + }
1555 +
1556 + if ( !isset( $_POST[ 'slug' ] ) ) {
1557 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1558 + }
1559 + die( json_encode( array( 'result' => MainWP_Updates::ignorePluginsThemes( $_POST[ 'type' ], $_POST[ 'slug' ], $_POST[ 'name' ] ) ) ) ); //ok
1560 + }
1561 +
1562 + function mainwp_unignorepluginsthemes() {
1563 + $this->secure_request( 'mainwp_unignorepluginsthemes' );
1564 +
1565 + if ( !isset( $_POST[ 'slug' ] ) ) {
1566 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1567 + }
1568 + die( json_encode( array( 'result' => MainWP_Updates::unIgnorePluginsThemes( $_POST[ 'type' ], $_POST[ 'slug' ] ) ) ) );
1569 + }
1570 +
1571 + function mainwp_trust_plugin() {
1572 + $this->secure_request( 'mainwp_trust_plugin' );
1573 +
1574 + MainWP_Plugins::trustPost();
1575 + die( json_encode( array( 'result' => true ) ) );
1576 + }
1577 +
1578 + function mainwp_trust_theme() {
1579 + $this->secure_request( 'mainwp_trust_theme' );
1580 +
1581 + MainWP_Themes::trustPost();
1582 + die( json_encode( array( 'result' => true ) ) );
1583 + }
1584 +
1585 + function mainwp_checkbackups() {
1586 + $this->secure_request( 'mainwp_checkbackups' );
1587 +
1588 + try {
1589 + //die( json_encode( array( 'result' => MainWP_Updates_Overview::checkBackups() ) ) );
1590 + wp_send_json( array( 'result' => MainWP_Updates_Overview::checkBackups() ) );
1591 + } catch ( Exception $e ) {
1592 + die( json_encode( array( 'error' => $e->getMessage() ) ) );
1593 + }
1594 + }
1595 +
1596 + function mainwp_syncerrors_dismiss() {
1597 + $this->secure_request( 'mainwp_syncerrors_dismiss' );
1598 +
1599 + try {
1600 + die( json_encode( array( 'result' => MainWP_Updates_Overview::dismissSyncErrors() ) ) );
1601 + } catch ( Exception $e ) {
1602 + die( json_encode( array( 'error' => $e->getMessage() ) ) );
1603 + }
1604 + }
1605 +
1606 +
1607 + function mainwp_events_notice_hide() {
1608 + $this->secure_request( 'mainwp_events_notice_hide' );
1609 +
1610 + if ( isset( $_POST[ 'notice' ] ) ) {
1611 + $current_options = get_option( 'mainwp_showhide_events_notice' );
1612 + if ( !is_array( $current_options ) ) {
1613 + $current_options = array();
1614 + }
1615 + if ( $_POST[ 'notice' ] == 'first_site' ) {
1616 + update_option( 'mainwp_first_site_events_notice', '' );
1617 + } else if ( $_POST[ 'notice' ] == 'request_reviews1' ) {
1618 + $current_options[ 'request_reviews1' ] = 15;
1619 + $current_options[ 'request_reviews1_starttime' ] = time();
1620 + } else if ( $_POST[ 'notice' ] == 'request_reviews1_forever' || $_POST[ 'notice' ] == 'request_reviews2_forever' ) {
1621 + $current_options[ 'request_reviews1' ] = 'forever';
1622 + $current_options[ 'request_reviews2' ] = 'forever';
1623 + } else if ( $_POST[ 'notice' ] == 'request_reviews2' ) {
1624 + $current_options[ 'request_reviews2' ] = 15;
1625 + $current_options[ 'request_reviews2_starttime' ] = time();
1626 + } else if ( $_POST[ 'notice' ] == 'trust_child' ) {
1627 + $current_options[ 'trust_child' ] = 1;
1628 + } else if ( $_POST[ 'notice' ] == 'multi_site' ) {
1629 + $current_options[ 'hide_multi_site_notice' ] = 1;
1630 + }
1631 + update_option( 'mainwp_showhide_events_notice', $current_options );
1632 + }
1633 + die( 'ok' );
1634 + }
1635 +
1636 + function mainwp_showhide_sections() {
1637 + if ( isset( $_POST[ 'sec' ] ) && isset( $_POST[ 'status' ] ) ) {
1638 + $opts = get_option( 'mainwp_opts_showhide_sections' );
1639 + if ( !is_array( $opts ) ) {
1640 + $opts = array();
1641 + }
1642 + $opts[ $_POST[ 'sec' ] ] = $_POST[ 'status' ];
1643 + update_option( 'mainwp_opts_showhide_sections', $opts );
1644 + die( 'ok' );
1645 + }
1646 + die( 'failed' );
1647 + }
1648 +
1649 + function mainwp_saving_status() {
1650 + if ( !isset( $_REQUEST[ 'nonce' ] ) || !wp_verify_nonce( $_REQUEST[ 'nonce' ], 'mainwp_ajax' ) ) {
1651 + die( 'Invalid request.' );
1652 + }
1653 + if ( isset( $_POST[ 'saving_status' ] ) ) {
1654 + $current_options = get_option( 'mainwp_opts_saving_status' );
1655 + if ( !is_array( $current_options ) ) {
1656 + $current_options = array();
1657 + }
1658 +
1659 + if ( !empty( $_POST[ 'saving_status' ] ) ) {
1660 + $current_options[ $_POST[ 'saving_status' ] ] = $_POST[ 'value' ];
1661 + }
1662 +
1663 + update_option( 'mainwp_opts_saving_status', $current_options );
1664 + }
1665 + die( 'ok' );
1666 + }
1667 +
1668 + function mainwp_recheck_http() {
1669 + if ( !$this->check_security( 'mainwp_recheck_http' ) ) {
1670 + die( json_encode( array( 'error' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
1671 + }
1672 +
1673 + if ( !isset( $_POST[ 'websiteid' ] ) || empty( $_POST[ 'websiteid' ] ) ) {
1674 + die( -1 );
1675 + }
1676 +
1677 + $website = MainWP_DB::Instance()->getWebsiteById( $_POST[ 'websiteid' ] );
1678 + if ( empty( $website ) )
1679 + die( -1 );
1680 +
1681 + $result = MainWP_Utility::isWebsiteAvailable( $website );
1682 + $http_code = ( is_array( $result ) && isset( $result[ 'httpCode' ] ) ) ? $result[ 'httpCode' ] : 0;
1683 + $check_result = MainWP_Utility::check_ignored_http_code( $http_code );
1684 + MainWP_DB::Instance()->updateWebsiteValues( $website->id, array(
1685 + 'offline_check_result' => $check_result ? '1' : '-1',
1686 + 'offline_checks_last' => time(),
1687 + 'http_response_code' => $http_code
1688 + ) );
1689 + die( json_encode( array( 'httpcode' => esc_html($http_code), 'status' => $check_result ? 1 : 0 ) ) );
1690 + }
1691 +
1692 + function mainwp_ignore_http_response() {
1693 + if ( !$this->check_security( 'mainwp_ignore_http_response' ) ) {
1694 + die( json_encode( array( 'error' => __( 'ERROR: Invalid request!', 'mainwp' ) ) ) );
1695 + }
1696 +
1697 + if ( !isset( $_POST[ 'websiteid' ] ) || empty( $_POST[ 'websiteid' ] ) ) {
1698 + die( -1 );
1699 + }
1700 +
1701 + $website = MainWP_DB::Instance()->getWebsiteById( $_POST[ 'websiteid' ] );
1702 + if ( empty( $website ) ) {
1703 + die( -1 );
1704 + }
1705 +
1706 + MainWP_DB::Instance()->updateWebsiteValues( $website->id, array( 'http_response_code' => '-1' ) );
1707 + die( json_encode( array( 'ok' => 1 ) ) );
1708 + }
1709 +
1710 + function mainwp_autoupdate_and_trust_child() {
1711 + $this->secure_request( 'mainwp_autoupdate_and_trust_child' );
1712 + if ( get_option( 'mainwp_automaticDailyUpdate' ) != 1 ) {
1713 + update_option( 'mainwp_automaticDailyUpdate', 1 );
1714 + }
1715 + MainWP_Plugins::trustPlugin( 'mainwp-child/mainwp-child.php' );
1716 + die( 'ok' );
1717 + }
1718 +
1719 + function secure_request( $action = '', $query_arg = 'security' ) {
1720 + if ( !MainWP_Utility::isAdmin() ) {
1721 + die( 0 );
1722 + }
1723 + if ( $action == '' ) {
1724 + return;
1725 + }
1726 +
1727 + if ( !$this->check_security( $action, $query_arg ) ) {
1728 + die( json_encode( array( 'error' => __( 'Invalid request!', 'mainwp' ) ) ) );
1729 + }
1730 +
1731 + if ( isset( $_POST[ 'dts' ] ) ) {
1732 + $ajaxPosts = get_option( 'mainwp_ajaxposts' );
1733 + if ( !is_array( $ajaxPosts ) ) {
1734 + $ajaxPosts = array();
1735 + }
1736 +
1737 + //If already processed, just quit!
1738 + if ( isset( $ajaxPosts[ $action ] ) && ( $ajaxPosts[ $action ] == $_POST[ 'dts' ] ) ) {
1739 + die( json_encode( array( 'error' => __( 'Double request!', 'mainwp' ) ) ) );
1740 + }
1741 +
1742 + $ajaxPosts[ $action ] = $_POST[ 'dts' ];
1743 + MainWP_Utility::update_option( 'mainwp_ajaxposts', $ajaxPosts );
1744 + }
1745 + }
1746 +
1747 + function check_security( $action = - 1, $query_arg = 'security' ) {
1748 + if ( $action == - 1 ) {
1749 + return false;
1750 + }
1751 +
1752 + $adminurl = strtolower( admin_url() );
1753 + $referer = strtolower( wp_get_referer() );
1754 + $result = isset( $_REQUEST[ $query_arg ] ) ? wp_verify_nonce( $_REQUEST[ $query_arg ], $action ) : false;
1755 + if ( !$result && !( - 1 == $action && strpos( $referer, $adminurl ) === 0 ) ) {
1756 + return false;
1757 + }
1758 +
1759 + return true;
1760 + }
1761 +
1762 + function addAction( $action, $callback ) {
1763 + add_action( 'wp_ajax_' . $action, $callback );
1764 + $this->addSecurityNonce( $action );
1765 + }
1766 +
1767 + function addSecurityNonce( $action ) {
1768 + if ( !is_array( $this->security_nonces ) ) {
1769 + $this->security_nonces = array();
1770 + }
1771 +
1772 + if ( !function_exists( 'wp_create_nonce' ) ) {
1773 + include_once( ABSPATH . WPINC . '/pluggable.php' );
1774 + }
1775 + $this->security_nonces[ $action ] = wp_create_nonce( $action );
1776 + }
1777 +
1778 + function getSecurityNonces() {
1779 + return $this->security_nonces;
1780 + }
1781 +
1782 + function mainwp_force_destroy_sessions() {
1783 + $this->secure_request( 'mainwp_force_destroy_sessions' );
1784 +
1785 + $website_id = ( isset( $_POST[ 'website_id' ] ) ? (int) $_POST[ 'website_id' ] : 0 );
1786 +
1787 + if ( !MainWP_DB::Instance()->getWebsiteById( $website_id ) ) {
1788 + die( json_encode( array( 'error' => array( 'message' => __( 'This website does not exist.', 'mainwp' ) ) ) ) );
1789 + }
1790 +
1791 + $website = MainWP_DB::Instance()->getWebsiteById( $website_id );
1792 + if ( !MainWP_Utility::can_edit_website( $website ) ) {
1793 + die( json_encode( array( 'error' => array( 'message' => __( 'You cannot edit this website.', 'mainwp' ) ) ) ) );
1794 + }
1795 +
1796 + try {
1797 + $information = MainWP_Utility::fetchUrlAuthed( $website, 'settings_tools', array(
1798 + 'action' => 'force_destroy_sessions',
1799 + ) );
1800 + global $mainWP;
1801 + if ( ( $mainWP->getVersion() == '2.0.22' ) || ( $mainWP->getVersion() == '2.0.23' ) ) {
1802 + if ( get_option( 'mainwp_fixed_security_2022' ) != 1 ) {
1803 + update_option( 'mainwp_fixed_security_2022', 1 );
1804 + }
1805 + }
1806 + } catch ( Exception $e ) {
1807 + $information = array( 'error' => __( 'fetchUrlAuthed exception', 'mainwp' ) );
1808 + }
1809 +
1810 + //die( json_encode( $information ) );
1811 + wp_send_json( $information );
1812 + }
1813 +
1474 1814 }
1815 +
1816 +?>