← All changes
|
modules/logs/classes/class-log-events-list-table.php
+157
-39
6.1.3
→
6.2.2
View file →
| @@ -73,8 +73,15 @@ | ||
| 73 | 73 | */ |
| 74 | 74 | public $total_items; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | + * Public variable to hold extra data. | |
| 78 | + * | |
| 79 | + * @var integer | |
| 80 | + */ | |
| 81 | + public $items_extra_data; | |
| 82 | + | |
| 83 | + /** | |
| 77 | 84 | * Protected variable to hold columns headers |
| 78 | 85 | * |
| 79 | 86 | * @var array |
| 80 | 87 | */ |
| @@ -143,20 +150,29 @@ | ||
| 143 | 150 | * |
| 144 | 151 | * @return array Array of default column names. |
| 145 | 152 | */ |
| 146 | 153 | public function get_default_columns() { |
| 147 | - $columns = array( | |
| 148 | - 'cb' => '<input type="checkbox" />', | |
| 149 | - 'created' => esc_html__( 'Date', 'mainwp' ), | |
| 150 | - 'user_id' => esc_html__( 'User', 'mainwp' ), | |
| 151 | - 'action' => esc_html__( 'Action', 'mainwp' ), | |
| 152 | - 'log_object' => esc_html__( 'Object', 'mainwp' ), | |
| 153 | - 'icon' => '', | |
| 154 | - 'name' => esc_html__( 'Website', 'mainwp' ), | |
| 155 | - 'event' => esc_html__( 'Event', 'mainwp' ), | |
| 156 | - 'source' => esc_html__( 'Source', 'mainwp' ), | |
| 157 | - 'col_action' => '', | |
| 158 | - ); | |
| 154 | + if ( 'widget-overview' === $this->table_id_prefix ) { | |
| 155 | + $columns = array( | |
| 156 | + 'created' => esc_html__( 'Time', 'mainwp' ), | |
| 157 | + 'log_object' => esc_html__( 'Object', 'mainwp' ), | |
| 158 | + 'event' => esc_html__( 'Event', 'mainwp' ), | |
| 159 | + 'name' => esc_html__( 'Site', 'mainwp' ), | |
| 160 | + ); | |
| 161 | + } else { | |
| 162 | + $columns = array( | |
| 163 | + 'cb' => '<input type="checkbox" />', | |
| 164 | + 'created' => esc_html__( 'Date', 'mainwp' ), | |
| 165 | + 'user_id' => esc_html__( 'User', 'mainwp' ), | |
| 166 | + 'action' => esc_html__( 'Action', 'mainwp' ), | |
| 167 | + 'log_object' => esc_html__( 'Object', 'mainwp' ), | |
| 168 | + 'icon' => '', | |
| 169 | + 'name' => esc_html__( 'Website', 'mainwp' ), | |
| 170 | + 'event' => esc_html__( 'Event', 'mainwp' ), | |
| 171 | + 'source' => esc_html__( 'Source', 'mainwp' ), | |
| 172 | + 'col_action' => '', | |
| 173 | + ); | |
| 174 | + } | |
| 159 | 175 | |
| 160 | 176 | if ( 'manage-events' !== $this->table_id_prefix ) { |
| 161 | 177 | unset( $columns['source'] ); |
| 162 | 178 | } |
| @@ -162,11 +178,14 @@ | ||
| 162 | 178 | } |
| 163 | 179 | |
| 164 | 180 | if ( 'widget-overview' === $this->table_id_prefix ) { |
| 165 | 181 | unset( $columns['log_site_name'] ); |
| 166 | - if ( ! empty( $_GET['dashboard'] ) ) { //phpcs:ignore -- ok, individual widget. | |
| 167 | - unset( $columns['icon'] ); | |
| 168 | - } | |
| 182 | + unset( $columns['icon'] ); | |
| 183 | + unset( $columns['user_id'] ); | |
| 184 | + unset( $columns['action'] ); | |
| 185 | + unset( $columns['source'] ); | |
| 186 | + unset( $columns['col_action'] ); | |
| 187 | + unset( $columns['cb'] ); | |
| 169 | 188 | } |
| 170 | 189 | |
| 171 | 190 | return $columns; |
| 172 | 191 | } |
| @@ -644,8 +663,12 @@ | ||
| 644 | 663 | $title = trim( $title ); |
| 645 | 664 | $title = preg_replace( '/( ?(plugin|theme))$/i', '', $title ); |
| 646 | 665 | } |
| 647 | 666 | |
| 667 | + if ( ! empty( $record->log_type_id ) ) { | |
| 668 | + $title = Log_Changes_Logs_Helper::get_changes_logs_object_title( $record, $title ); | |
| 669 | + } | |
| 670 | + | |
| 648 | 671 | if ( $with_icon ) { |
| 649 | 672 | $obj_icon = $this->get_object_icon( $record ); |
| 650 | 673 | return $obj_icon . $title; |
| 651 | 674 | } |
| @@ -865,8 +888,13 @@ | ||
| 865 | 888 | // phpcs:enable WordPress.Security.NonceVerification |
| 866 | 889 | |
| 867 | 890 | // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 868 | 891 | $perPage = isset( $_REQUEST['length'] ) ? intval( $_REQUEST['length'] ) : false; |
| 892 | + | |
| 893 | + if ( 'widget-overview' === $this->table_id_prefix && ( false === $perPage || -1 === (int) $perPage ) ) { | |
| 894 | + $perPage = 25; | |
| 895 | + } | |
| 896 | + | |
| 869 | 897 | if ( -1 === (int) $perPage || empty( $perPage ) ) { |
| 870 | 898 | $perPage = 9999999; |
| 871 | 899 | } |
| 872 | 900 | $start = isset( $_REQUEST['start'] ) ? intval( $_REQUEST['start'] ) : 0; |
| @@ -874,8 +902,21 @@ | ||
| 874 | 902 | $search = isset( $_REQUEST['search']['value'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search']['value'] ) ) : ''; |
| 875 | 903 | |
| 876 | 904 | $recent_number = isset( $_REQUEST['recent_number'] ) ? intval( $_REQUEST['recent_number'] ) : 0; |
| 877 | 905 | |
| 906 | + $now = time(); | |
| 907 | + | |
| 908 | + // Get last 24 hours items. | |
| 909 | + if ( 'widget-overview' === $this->table_id_prefix ) { | |
| 910 | + if ( empty( $filter_dtsstart ) && empty( $filter_dtsstop ) ) { | |
| 911 | + $filter_dtsstart = $now - DAY_IN_SECONDS; | |
| 912 | + $filter_dtsstop = $now; | |
| 913 | + } | |
| 914 | + } else { | |
| 915 | + $filter_dtsstart = ! empty( $filter_dtsstart ) ? strtotime( $filter_dtsstart . ' 00:00:00' ) : ''; | |
| 916 | + $filter_dtsstop = ! empty( $filter_dtsstop ) ? strtotime( $filter_dtsstop . ' 23:59:59' ) : ''; | |
| 917 | + } | |
| 918 | + | |
| 878 | 919 | // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 879 | 920 | |
| 880 | 921 | $args = array( |
| 881 | 922 | 'order' => ( 'asc' === $req_order ) ? 'asc' : 'desc', |
| @@ -885,10 +926,10 @@ | ||
| 885 | 926 | 'search' => $search, |
| 886 | 927 | 'groups_ids' => $array_groups_ids, |
| 887 | 928 | 'client_ids' => $array_clients_ids, |
| 888 | 929 | 'usersfilter_sites_ids' => $array_usersfilter_sites_ids, // format: userid-siteid, siteid = 0 => dashboard user. |
| 889 | - 'timestart' => ! empty( $filter_dtsstart ) ? strtotime( $filter_dtsstart . ' 00:00:00' ) : '', | |
| 890 | - 'timestop' => ! empty( $filter_dtsstop ) ? strtotime( $filter_dtsstop . ' 23:59:59' ) : '', | |
| 930 | + 'timestart' => $filter_dtsstart, | |
| 931 | + 'timestop' => $filter_dtsstop, | |
| 891 | 932 | 'dismiss' => 0, |
| 892 | 933 | 'view' => 'events_list', |
| 893 | 934 | 'wpid' => ! empty( $insights_filters['wpid'] ) ? $insights_filters['wpid'] : 0, // int or array of site ids. |
| 894 | 935 | 'sources_conds' => $sources_conds, |
| @@ -903,13 +944,21 @@ | ||
| 903 | 944 | |
| 904 | 945 | $args['records_per_page'] = $perPage; |
| 905 | 946 | $args['dev_log_query'] = 0; // 1 for dev logs. |
| 906 | 947 | |
| 907 | - $args['with_all_logs_meta'] = 1; // so it will enable optimize_with_meta too. | |
| 948 | + if ( 'widget-overview' === $this->table_id_prefix ) { | |
| 949 | + $args['optimize'] = 1; | |
| 950 | + $args['optimize_with_meta'] = 1; | |
| 951 | + $args['not_count'] = true; | |
| 952 | + $args['optimize_has_more'] = true; | |
| 953 | + } else { | |
| 954 | + $args['with_all_logs_meta'] = 1; // so it will enable optimize_with_meta too. | |
| 955 | + } | |
| 908 | 956 | |
| 909 | - $this->items = $this->manager->db->get_records( $args ); | |
| 910 | - $this->total_items = $this->manager->db->get_found_records_count(); // get this value for recent events request only. | |
| 911 | - $this->sites_opts = $this->manager->db->get_logs_sites_opts(); | |
| 957 | + $this->items = $this->manager->db->get_records( $args ); | |
| 958 | + $this->total_items = $this->manager->db->get_found_records_count(); // get this value for recent events request only. | |
| 959 | + $this->sites_opts = $this->manager->db->get_logs_sites_opts(); | |
| 960 | + $this->items_extra_data = $this->manager->db->get_logs_extra_data(); | |
| 912 | 961 | |
| 913 | 962 | $this->items_prev = array(); |
| 914 | 963 | if ( $with_prev_data && ! empty( $args['timestart'] ) && ! empty( $args['timestop'] ) && $args['timestart'] < $args['timestop'] ) { |
| 915 | 964 | $timestart_prev = $args['timestart'] - ( $args['timestop'] - $args['timestart'] ); |
| @@ -950,8 +999,15 @@ | ||
| 950 | 999 | |
| 951 | 1000 | // @since version 5.5. |
| 952 | 1001 | $pages_length = apply_filters( 'mainwp_site_changes_table_pages_length', $pages_length, $this->table_id_prefix ); |
| 953 | 1002 | |
| 1003 | + if ( 'widget-overview' === $this->table_id_prefix ) { | |
| 1004 | + $pages_length = array( | |
| 1005 | + 25 => '25', | |
| 1006 | + ); | |
| 1007 | + $sites_per_page = 25; | |
| 1008 | + } | |
| 1009 | + | |
| 954 | 1010 | $pagelength_val = implode( ',', array_keys( $pages_length ) ); |
| 955 | 1011 | $pagelength_title = implode( ',', array_values( $pages_length ) ); |
| 956 | 1012 | |
| 957 | 1013 | $ajaxaction = 'mainwp_module_log_manage_events_display_rows'; |
| @@ -966,11 +1022,11 @@ | ||
| 966 | 1022 | $events_tbl_id .= '-' . esc_attr( $this->table_id_prefix ); |
| 967 | 1023 | } |
| 968 | 1024 | |
| 969 | 1025 | if ( 'manage-events' === $this->table_id_prefix ) { |
| 970 | - ?> | |
| 1026 | + ?> | |
| 971 | 1027 | <div class="ui padded segment"> |
| 972 | - <?php | |
| 1028 | + <?php | |
| 973 | 1029 | } |
| 974 | 1030 | ?> |
| 975 | 1031 | <div id="mainwp-module-log-records-table-container" style="opacity:0;"> |
| 976 | 1032 | <table id="<?php echo esc_attr( $events_tbl_id ); ?>" style="width:100%" class="ui single line <?php echo 'manage-events' === $this->table_id_prefix ? 'selectable' : ''; ?> unstackable table mainwp-with-preview-table"> |
| @@ -980,12 +1036,13 @@ | ||
| 980 | 1036 | </table> |
| 981 | 1037 | </div> |
| 982 | 1038 | <?php |
| 983 | 1039 | if ( 'manage-events' === $this->table_id_prefix ) { |
| 984 | - ?> | |
| 1040 | + ?> | |
| 985 | 1041 | </div> |
| 986 | - <?php | |
| 1042 | + <?php | |
| 987 | 1043 | } |
| 1044 | + if ( 'widget-overview' !== $this->table_id_prefix ) { | |
| 988 | 1045 | ?> |
| 989 | 1046 | <div id="mainwp-loading-sites"> |
| 990 | 1047 | <div class="ui active page dimmer"> |
| 991 | 1048 | <div class="ui double text loader"><?php esc_html_e( 'Loading...', 'mainwp' ); ?></div> |
| @@ -991,9 +1048,9 @@ | ||
| 991 | 1048 | <div class="ui double text loader"><?php esc_html_e( 'Loading...', 'mainwp' ); ?></div> |
| 992 | 1049 | </div> |
| 993 | 1050 | </div> |
| 994 | 1051 | <?php |
| 995 | - | |
| 1052 | + } | |
| 996 | 1053 | $table_features = array( |
| 997 | 1054 | 'searching' => 'true', |
| 998 | 1055 | 'paging' => 'true', |
| 999 | 1056 | 'pagingType' => 'full_numbers', |
| @@ -1005,16 +1062,21 @@ | ||
| 1005 | 1062 | 'scrollX' => 'true', |
| 1006 | 1063 | 'responsive' => 'true', |
| 1007 | 1064 | 'fixedColumns' => '', |
| 1008 | 1065 | 'searchDelay' => 350, |
| 1066 | + 'numbers' => 7, | |
| 1009 | 1067 | ); |
| 1010 | 1068 | |
| 1011 | 1069 | // Fix for widget state save overview table. |
| 1012 | 1070 | if ( 'widget-overview' === $this->table_id_prefix ) { |
| 1013 | 1071 | $table_features['stateSave'] = 'false'; |
| 1072 | + $table_features['searching'] = 'false'; | |
| 1073 | + $table_features['paging'] = 'true'; | |
| 1074 | + $table_features['info'] = 'false'; | |
| 1075 | + $table_features['numbers'] = 3; | |
| 1014 | 1076 | } |
| 1015 | 1077 | |
| 1016 | - ?> | |
| 1078 | + ?> | |
| 1017 | 1079 | |
| 1018 | 1080 | <script type="text/javascript"> |
| 1019 | 1081 | var responsive = <?php echo esc_js( $table_features['responsive'] ); ?>; |
| 1020 | 1082 | if( jQuery( window ).width() > 1140 ) { |
| @@ -1032,11 +1094,19 @@ | ||
| 1032 | 1094 | widgetViewSource = ['wp-admin', 'dashboard', '' ].includes(widgetViewSource) ? widgetViewSource : 'wp-admin'; |
| 1033 | 1095 | } |
| 1034 | 1096 | |
| 1035 | 1097 | try { |
| 1098 | + | |
| 1099 | + const nextButton = document.createElement('a'); | |
| 1100 | + nextButton.href = '#'; | |
| 1101 | + nextButton.className = 'ui tiny basic button'; | |
| 1102 | + nextButton.innerHTML = '<?php echo esc_js( __( 'More', 'mainwp' ) ); ?>'; | |
| 1103 | + | |
| 1036 | 1104 | //jQuery( '#mainwp-sites-table-loader' ).hide(); |
| 1037 | 1105 | $module_log_table = jQuery( manage_tbl_id ).on( 'processing.dt', function ( e, settings, processing ) { |
| 1038 | - jQuery( '#mainwp-loading-sites' ).css( 'display', processing ? 'block' : 'none' ); | |
| 1106 | + if(jQuery( '#mainwp-loading-sites' ).length){ | |
| 1107 | + jQuery( '#mainwp-loading-sites' ).css( 'display', processing ? 'block' : 'none' ); | |
| 1108 | + } | |
| 1039 | 1109 | if (!processing) { |
| 1040 | 1110 | let tb = jQuery( manage_tbl_id ); |
| 1041 | 1111 | tb.find( 'th[cell-cls]' ).each( function(){ |
| 1042 | 1112 | let ceIdx = this.cellIndex; |
| @@ -1107,13 +1177,45 @@ | ||
| 1107 | 1177 | json.data[i].log_id = json.rowsInfo[i].log_id; |
| 1108 | 1178 | json.data[i].created_sort = json.rowsInfo[i].created; |
| 1109 | 1179 | json.data[i].state_sort = json.rowsInfo[i].state; |
| 1110 | 1180 | } |
| 1181 | + | |
| 1182 | + <?php if ( 'widget-overview' === $this->table_id_prefix ) { ?> | |
| 1183 | + if (json?.has_more) { | |
| 1184 | + nextButton.classList.remove('disabled'); | |
| 1185 | + nextButton.removeAttribute('aria-disabled'); | |
| 1186 | + nextButton.removeAttribute('tabindex'); | |
| 1187 | + nextButton.setAttribute('href', '#'); | |
| 1188 | + } else { | |
| 1189 | + nextButton.classList.add('disabled'); | |
| 1190 | + nextButton.setAttribute('aria-disabled', 'true'); | |
| 1191 | + nextButton.setAttribute('tabindex', '-1'); | |
| 1192 | + nextButton.removeAttribute('href'); | |
| 1193 | + } | |
| 1194 | + <?php } ?> | |
| 1111 | 1195 | return json.data; |
| 1112 | 1196 | } |
| 1113 | 1197 | }, |
| 1114 | - "responsive": responsive, | |
| 1115 | - "searching" : <?php echo esc_js( $table_features['searching'] ); ?>, | |
| 1198 | + "layout": { | |
| 1199 | + <?php | |
| 1200 | + if ( 'widget-overview' === $this->table_id_prefix ) { | |
| 1201 | + ?> | |
| 1202 | + "topStart": null, | |
| 1203 | + "bottomEnd": nextButton | |
| 1204 | + <?php | |
| 1205 | + } else { | |
| 1206 | + ?> | |
| 1207 | + "bottomEnd": { | |
| 1208 | + "paging": { | |
| 1209 | + "numbers": <?php echo intval( $table_features['numbers'] ); ?> | |
| 1210 | + } | |
| 1211 | + } | |
| 1212 | + <?php | |
| 1213 | + } | |
| 1214 | + ?> | |
| 1215 | + }, | |
| 1216 | + 'responsive': responsive, | |
| 1217 | + 'searching' : <?php echo esc_js( $table_features['searching'] ); ?>, | |
| 1116 | 1218 | "paging" : <?php echo esc_js( $table_features['paging'] ); ?>, |
| 1117 | 1219 | "pagingType" : "<?php echo esc_js( $table_features['pagingType'] ); ?>", |
| 1118 | 1220 | "info" : <?php echo esc_js( $table_features['info'] ); ?>, |
| 1119 | 1221 | "colReorder" : <?php echo $table_features['colReorder']; // phpcs:ignore -- specical chars. ?>, |
| @@ -1127,9 +1229,9 @@ | ||
| 1127 | 1229 | "pageLength": <?php echo intval( $sites_per_page ); ?>, |
| 1128 | 1230 | "columnDefs": <?php echo wp_json_encode( $this->get_columns_defines() ); ?>, |
| 1129 | 1231 | "columns": <?php echo wp_json_encode( $this->get_columns_init() ); ?>, |
| 1130 | 1232 | "language": { |
| 1131 | - "emptyTable": "<?php esc_html_e( 'No events found.', 'mainwp' ); ?>" | |
| 1233 | + "emptyTable": "<?php echo 'widget-overview' === $this->table_id_prefix ? esc_html__( 'No matching activity was found in the last 24 hours.', 'mainwp' ) : esc_html__( 'No events found.', 'mainwp' ); ?>" | |
| 1132 | 1234 | }, |
| 1133 | 1235 | "drawCallback": function( settings ) { |
| 1134 | 1236 | this.api().tables().body().to$().attr( 'id', 'mainwp-module-log-records-body-table' ); |
| 1135 | 1237 | jQuery( '#mainwp-module-log-records-table-container' ).css( 'opacity', '1' ); |
| @@ -1200,23 +1302,38 @@ | ||
| 1200 | 1302 | .to$().find('td.check-column .ui.checkbox' ).checkbox('set unchecked'); |
| 1201 | 1303 | } |
| 1202 | 1304 | }); |
| 1203 | 1305 | } |
| 1306 | + | |
| 1307 | + | |
| 1308 | + nextButton.addEventListener('click', function (e) { | |
| 1309 | + e.preventDefault(); | |
| 1310 | + | |
| 1311 | + if (nextButton.classList.contains('disabled')) { | |
| 1312 | + return; | |
| 1313 | + } | |
| 1314 | + $module_log_table.page('next').draw('page'); | |
| 1315 | + }); | |
| 1316 | + | |
| 1204 | 1317 | } catch(err) { |
| 1205 | 1318 | // to fix js error. |
| 1206 | 1319 | console.log(err); |
| 1207 | 1320 | } |
| 1208 | 1321 | |
| 1209 | - let $sitesChangesSelect = jQuery( '#widget-sites-changes-dropdown-selector' ).dropdown( { | |
| 1210 | - onChange: function( value ) { | |
| 1211 | - mainwp_ui_state_save('sites-changes-widget', value); | |
| 1212 | - if(widgetViewSource !== value ){ | |
| 1213 | - widgetViewSource = value; | |
| 1214 | - $module_log_table.ajax.reload(); | |
| 1322 | + // Delay dropdown initialization to prevent it from being overwritten. | |
| 1323 | + setTimeout(() => { | |
| 1324 | + jQuery( '#widget-sites-changes-dropdown-selector' ).dropdown( { | |
| 1325 | + onChange: function( value ) { | |
| 1326 | + mainwp_ui_state_save('sites-changes-widget', value); | |
| 1327 | + if(widgetViewSource !== value ){ | |
| 1328 | + widgetViewSource = value; | |
| 1329 | + $module_log_table.ajax.reload(); | |
| 1330 | + } | |
| 1215 | 1331 | } |
| 1216 | - } | |
| 1217 | - } ).dropdown("set selected", widgetViewSource); | |
| 1332 | + } ).dropdown("set selected", widgetViewSource); | |
| 1333 | + }, 1000); | |
| 1218 | 1334 | |
| 1335 | + | |
| 1219 | 1336 | mainwp_module_log_overview_content_filter = function() { |
| 1220 | 1337 | if(jQuery( '#mainwp-common-filter-segments-model-name').length && 'manage-events' === jQuery( '#mainwp-common-filter-segments-model-name').val() ){ |
| 1221 | 1338 | mainwp_module_log_manage_events_filter(); |
| 1222 | 1339 | return; |
| @@ -1425,7 +1542,8 @@ | ||
| 1425 | 1542 | 'data' => $all_rows, |
| 1426 | 1543 | 'recordsTotal' => $this->total_items, |
| 1427 | 1544 | 'recordsFiltered' => $this->total_items, |
| 1428 | 1545 | 'rowsInfo' => $info_rows, |
| 1546 | + 'has_more' => is_array( $this->items_extra_data ) && ! empty( $this->items_extra_data['has_more'] ) ? true : false, | |
| 1429 | 1547 | ); |
| 1430 | 1548 | } |
| 1431 | 1549 | } |