PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 All 156 releases
← All changes | widgets/widget-mainwp-site-actions.php +150 -157 5.2 → 6.2.1 View file →
@@ -8,8 +8,18 @@
8 8 */
9 9
10 10 namespace MainWP\Dashboard;
11 11
12 +use MainWP\Dashboard\MainWP_UI;
13 +use MainWP\Dashboard\Module\Log\Log_Manager;
14 +use MainWP\Dashboard\Module\Log\Log_Events_List_Table;
15 +use MainWP\Dashboard\Module\Log\Log_DB_Helper;
16 +
17 +// Exit if accessed directly.
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit;
20 +}
21 +
12 22 /**
13 23 * Class MainWP_Site_Actions
14 24 *
15 25 * Displays the Site Actions.
@@ -16,8 +26,50 @@
16 26 */
17 27 class MainWP_Site_Actions { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18 28
19 29 /**
30 + * Private static variable to hold the single instance of the class.
31 + *
32 + * @static
33 + *
34 + * @var mixed Default null
35 + */
36 + private static $instance = null;
37 +
38 + /**
39 + * Private static variable to hold the single instance of the events table.
40 + *
41 + * @static
42 + *
43 + * @var mixed Default null
44 + */
45 + private $list_events_table = null;
46 +
47 +
48 + /**
49 + * Private static variable to hold the table type value.
50 + *
51 + * @var mixed Default null
52 + */
53 + private $table_id_prefix = 'widget-overview';
54 +
55 + /**
56 + * Method instance()
57 + *
58 + * Create public static instance.
59 + *
60 + * @static
61 + * @return MainWP_Site_Actions
62 + */
63 + public static function instance() {
64 + if ( null === static::$instance ) {
65 + static::$instance = new self();
66 + }
67 + return static::$instance;
68 + }
69 +
70 +
71 + /**
20 72 * Method get_class_name()
21 73 *
22 74 * @return string __CLASS__ Class name.
23 75 */
@@ -30,197 +82,128 @@
30 82 *
31 83 * @return mixed render_site_info()
32 84 */
33 85 public static function render() {
34 - $current_wpid = MainWP_System_Utility::get_current_wpid();
35 - $website = null;
36 - $actions_info = array();
86 + $current_wpid = MainWP_System_Utility::get_current_wpid();
87 + $website = null;
88 + $params = array();
89 + $params['limit'] = apply_filters( 'mainwp_widget_site_actions_limit_number', 50 );
37 90 if ( $current_wpid ) {
38 - $params = array(
39 - 'wpid' => $current_wpid,
40 - 'where_extra' => ' AND dismiss = 0 ',
91 + $params = array(
92 + 'wpid' => $current_wpid,
41 93 );
42 - $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
43 - $actions_info = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
94 + $website = MainWP_DB::instance()->get_website_by_id( $current_wpid );
44 95 } elseif ( isset( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
45 96 $client_id = isset( $_GET['client_id'] ) ? intval( $_GET['client_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
46 - $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $client_id );
47 - $site_ids = array();
48 -
49 - foreach ( $websites as $website ) {
50 - $site_ids[] = $website->id;
51 - }
52 -
53 - if ( ! empty( $site_ids ) ) {
54 - $limit = apply_filters( 'mainwp_widget_site_actions_limit_number', 50 );
55 - $params = array(
56 - 'limit' => $limit,
57 - 'where_extra' => ' AND dismiss = 0 ',
58 - 'wpid' => $site_ids,
59 - );
60 - $actions_info = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
61 - }
62 - } else {
63 - $limit = apply_filters( 'mainwp_widget_site_actions_limit_number', 50 );
64 - $params = array(
65 - 'limit' => $limit,
66 - 'where_extra' => ' AND dismiss = 0 ',
97 + $params = array(
98 + 'client_id' => $client_id,
67 99 );
68 - $actions_info = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
69 100 }
70 - static::render_info( $actions_info, $website );
101 + static::instance()->render_info( $params, $website );
71 102 }
72 103
73 104 /**
74 105 * Render Sites actions Info.
75 106 *
76 - * @param object $actions_info Sites actions info.
107 + * @param array $params Events params.
77 108 * @param object $website Sites info.
78 109 */
79 - private static function render_info( $actions_info, $website ) { // phpcs:ignore -- NOSONAR - complex.
110 + private function render_info( $params, $website ) { // phpcs:ignore -- NOSONAR - complex.
80 111
81 - if ( ! is_array( $actions_info ) ) {
82 - $actions_info = array();
112 + if ( ! is_array( $params ) ) {
113 + $params = array();
83 114 }
115 + $this->load_events_list_table();
84 116 ?>
85 117
86 118 <div class="mainwp-widget-header">
87 - <h3 class="ui header handle-drag">
119 + <div class="ui grid">
120 + <div class="fourteen wide column">
121 + <h2 class="ui header handle-drag">
122 + <?php
123 + /**
124 + * Filter: mainwp_non_mainwp_changes_widget_title
125 + *
126 + * Filters the Site info widget title text.
127 + *
128 + * @param object $website Object containing the child site info.
129 + *
130 + * @since 4.1
131 + */
132 + echo esc_html( apply_filters( 'mainwp_non_mainwp_changes_widget_title', esc_html__( 'Network Activity', 'mainwp' ), $website ) );
133 + ?>
134 + <div class="sub header"><?php esc_html_e( 'The most recent changes made to your Child Sites.', 'mainwp' ); ?></div>
135 + </h2>
136 + </div>
137 + <div class="two wide column right aligned">
138 + <div id="widget-sites-changes-dropdown-selector" class="ui dropdown top right tiny pointing not-auto-init mainwp-dropdown-tab">
139 + <i class="vertical ellipsis icon"></i>
140 + <div class="menu">
141 + <a href="javascript:void(0)" class="item" data-value="wp-admin"><?php esc_html_e( 'Non-MainWP Changes', 'mainwp' ); ?></a>
142 + <a href="javascript:void(0)" class="item" data-value="dashboard"><?php esc_html_e( 'Dashboard Changes', 'mainwp' ); ?></a>
143 + <a href="javascript:void(0)" class="item" data-value=""><?php esc_html_e( 'Show All', 'mainwp' ); ?></a>
144 + </div>
145 + </div>
146 + </div>
147 + </div>
148 + </div>
149 + <input type="hidden" id="mainwp-widget-filter-current-site-id" value="<?php echo isset( $params['wpid'] ) ? intval( $params['wpid'] ) : 0; ?>" />
150 + <input type="hidden" id="mainwp-widget-filter-current-client-id" value="<?php echo isset( $params['client_id'] ) ? intval( $params['client_id'] ) : 0; ?>" />
151 + <input type="hidden" id="mainwp-widget-filter-events-limit" value="<?php echo isset( $params['limit'] ) ? intval( $params['limit'] ) : 50; ?>" />
152 +
153 + <div id="mainwp-widget-site-actions" class="mainwp-scrolly-overflow">
88 154 <?php
89 155 /**
90 - * Filter: mainwp_non_mainwp_changes_widget_title
156 + * Actoin: mainwp_non_mainwp_changes_widget_top
91 157 *
92 - * Filters the Site info widget title text.
158 + * Fires at the top of the Site Info widget on the Individual site overview page.
93 159 *
94 160 * @param object $website Object containing the child site info.
95 161 *
96 - * @since 4.1
162 + * @since 4.0
97 163 */
98 - echo esc_html( apply_filters( 'mainwp_non_mainwp_changes_widget_title', esc_html__( 'Non-MainWP Changes', 'mainwp' ), $website ) );
164 + do_action( 'mainwp_non_mainwp_changes_widget_top', $website );
99 165 ?>
100 - <div class="sub header"><?php esc_html_e( 'The most recent changes made to your Child Sites that were not done through your MainWP Dashboard.', 'mainwp' ); ?></div>
101 - </h3>
102 - </div>
103 -
104 - <div id="mainwp-widget-site-actions" class="mainwp-scrolly-overflow">
166 + <?php
167 + /**
168 + * Action: mainwp_non_mainwp_changes_table_top
169 + *
170 + * Fires at the top of the Site Info table in Site Info widget on the Individual site overview page.
171 + *
172 + * @param object $website Object containing the child site info.
173 + *
174 + * @since 4.0
175 + */
176 + do_action( 'mainwp_non_mainwp_changes_table_top', $website );
177 + ?>
178 + <div id="mainwp-non-mainwp-changes-feed">
179 + <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
105 180 <?php
106 - /**
107 - * Actoin: mainwp_non_mainwp_changes_widget_top
108 - *
109 - * Fires at the top of the Site Info widget on the Individual site overview page.
110 - *
111 - * @param object $website Object containing the child site info.
112 - *
113 - * @since 4.0
114 - */
115 - do_action( 'mainwp_non_mainwp_changes_widget_top', $website );
181 + MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' );
182 + $this->list_events_table->display();
116 183 ?>
117 - <?php if ( $actions_info ) : ?>
118 - <table class="ui table" id="mainwp-non-mainwp-changes-table">
119 - <thead>
120 - <tr>
121 - <th scope="col"><?php esc_html_e( 'Change', 'mainwp' ); ?></th>
122 - <?php if ( empty( $website ) || isset( $_GET['client_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
123 - <th scope="col" class="collapsing"><?php esc_html_e( 'Website', 'mainwp' ); ?></th>
124 - <?php endif; ?>
125 - <th scope="col" class="collapsing"><?php esc_html_e( 'User', 'mainwp' ); ?></th>
126 - <th scope="col" class="collapsing no-sort"></th>
127 - </tr>
128 - </thead>
129 - <tbody>
130 - <?php
131 - /**
132 - * Action: mainwp_non_mainwp_changes_table_top
133 - *
134 - * Fires at the top of the Site Info table in Site Info widget on the Individual site overview page.
135 - *
136 - * @param object $website Object containing the child site info.
137 - *
138 - * @since 4.0
139 - */
140 - do_action( 'mainwp_non_mainwp_changes_table_top', $website );
141 - ?>
142 - <?php foreach ( $actions_info as $data ) : ?>
143 - <?php
144 - if ( empty( $data->action_user ) || empty( $data->meta_data ) ) {
145 - continue;
146 - }
184 + </div>
185 + <?php
186 + /**
187 + * Action: mainwp_non_mainwp_changes_table_bottom
188 + *
189 + * Fires at the bottom of the Site Info table in Site Info widget on the Individual site overview page.
190 + *
191 + * @param object $website Object containing the child site info.
192 + *
193 + * @since 4.0
194 + */
195 + do_action( 'mainwp_non_mainwp_changes_table_bottom', $website );
196 + ?>
197 + </div>
147 198
148 - $meta_data = json_decode( $data->meta_data );
149 -
150 - $action_class = '';
151 - if ( 'activated' === $data->action ) {
152 - $action_class = 'green';
153 - } elseif ( 'deactivated' === $data->action ) {
154 - $action_class = 'red';
155 - } elseif ( 'installed' === $data->action ) {
156 - $action_class = 'blue';
157 - }
158 -
159 - ?>
160 - <tr>
161 - <td data-order="<?php echo esc_attr( $data->created ); ?>">
162 - <strong><?php echo isset( $meta_data->name ) && '' !== $meta_data->name ? esc_html( $meta_data->name ) : 'WP Core'; ?></strong> <?php echo 'wordpress' !== $data->context ? esc_html( ucfirst( rtrim( $data->context, 's' ) ) ) : 'WordPress'; //phpcs:ignore -- text. ?><br/>
163 - <div><strong><span class="ui medium <?php echo esc_attr( $action_class ); ?> text"><?php echo esc_html( ucfirst( $data->action ) ); ?></span></strong></div>
164 - <span class="ui small text"><?php echo esc_html( MainWP_Utility::format_timestamp( $data->created ) ); ?></span>
165 - </td>
166 - <?php if ( empty( $website ) || isset( $_GET['client_id'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
167 - <td class="collapsing"><a href="admin.php?page=managesites&dashboard=<?php echo esc_attr( $data->wpid ); ?>"><?php echo esc_html( $data->name ); ?></a></td>
168 - <?php endif; ?>
169 - <td class="collapsing"><?php echo esc_html( $data->action_user ); ?></td>
170 - <td class="collapsing">
171 - <a href="javascript:void(0)" aria-label="<?php esc_attr_e( 'Dismiss the notice.', 'mainwp' ); ?>" class="mainwp-action-dismiss ui mini icon button" action-id="<?php echo intval( $data->action_id ); ?>" data-tooltip="<?php esc_attr_e( 'Dismiss the notice.', 'mainwp' ); ?>" data-position="left center" data-inverted=""><i class="times icon"></i></a>
172 - </td>
173 - </tr>
174 - <?php endforeach; ?>
175 - <?php
176 - /**
177 - * Action: mainwp_non_mainwp_changes_table_bottom
178 - *
179 - * Fires at the bottom of the Site Info table in Site Info widget on the Individual site overview page.
180 - *
181 - * @param object $website Object containing the child site info.
182 - *
183 - * @since 4.0
184 - */
185 - do_action( 'mainwp_non_mainwp_changes_table_bottom', $website );
186 - ?>
187 - </tbody>
188 - </table>
189 - <script type="text/javascript">
190 - jQuery( document ).ready( function() {
191 - jQuery.fn.DataTable.ext.pager.numbers_length = 4;
192 - jQuery( '#mainwp-non-mainwp-changes-table' ).DataTable( {
193 - "pageLength": 10,
194 - "lengthMenu": [ [5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"] ],
195 - "stateSave" : true,
196 - "stateDuration" : 0,
197 - "columnDefs": [ {
198 - "targets": 'no-sort',
199 - "orderable": false
200 - } ],
201 - } );
202 - } );
203 - </script>
204 - <?php else : ?>
205 - <?php MainWP_UI::render_empty_element_placeholder(); ?>
206 - <?php endif; ?>
207 - </div>
208 - <?php
209 - $params = array(
210 - 'total_count' => true,
211 - 'dismiss' => 0,
212 - );
213 - $totalRecords = MainWP_DB_Site_Actions::instance()->get_wp_actions( $params );
214 - ?>
215 199 <div class="mainwp-widget-footer">
216 200 <div class="ui two columns stackable grid">
217 - <div class="middle aligned column">
218 - <?php if ( $totalRecords ) : ?>
219 - <a href="admin.php?page=NonMainWPChanges" class="ui button mini fluid green"><?php printf( esc_html__( 'See all %d Non-MainWP Changes', 'mainwp' ), intval( $totalRecords ) ); ?></a>
220 - <?php endif; ?>
201 + <div class="left aligned middle aligned column">
221 202 </div>
222 - <div class="middle aligned column"></div>
203 + <div class="right aligned middle aligned column">
204 + <a href="admin.php?page=InsightsManage" class="ui mini basic button"><?php esc_html_e( 'View All Changes', 'mainwp' ); ?></a>
205 + </div>
223 206 </div>
224 207 </div>
225 208 <?php
226 209 /**
@@ -232,6 +215,16 @@
232 215 *
233 216 * @since 4.0
234 217 */
235 218 do_action( 'mainwp_non_mainwp_changes_widget_bottom', $website );
219 + }
220 +
221 + /**
222 + * Method load_sites_table()
223 + *
224 + * Load sites table.
225 + */
226 + public function load_events_list_table() {
227 + $manager = Log_Manager::instance();
228 + $this->list_events_table = new Log_Events_List_Table( $manager, $this->table_id_prefix );
236 229 }
237 230 }