← All changes
|
modules/logs/widgets/widget-log-posts-widget.php
+197
-186
5.0.2
→
6.2.2
View file →
| @@ -10,9 +10,16 @@ | ||
| 10 | 10 | |
| 11 | 11 | namespace MainWP\Dashboard\Module\Log; |
| 12 | 12 | |
| 13 | 13 | use MainWP\Dashboard\MainWP_Utility; |
| 14 | +use MainWP\Dashboard\MainWP_UI; | |
| 14 | 15 | |
| 16 | +// Exit if accessed directly. | |
| 17 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 18 | + exit; | |
| 19 | +} | |
| 20 | + | |
| 21 | + | |
| 15 | 22 | /** |
| 16 | 23 | * Class Log_Posts_Widget |
| 17 | 24 | * |
| 18 | 25 | * Displays the Logs info. |
| @@ -18,205 +25,209 @@ | ||
| 18 | 25 | * Displays the Logs info. |
| 19 | 26 | */ |
| 20 | 27 | class Log_Posts_Widget { |
| 21 | 28 | |
| 22 | - /** | |
| 23 | - * Protected static variable to hold the single instance of the class. | |
| 24 | - * | |
| 25 | - * @var mixed Default null | |
| 26 | - */ | |
| 27 | - protected static $instance = null; | |
| 29 | + /** | |
| 30 | + * Protected static variable to hold the single instance of the class. | |
| 31 | + * | |
| 32 | + * @var mixed Default null | |
| 33 | + */ | |
| 34 | + protected static $instance = null; | |
| 28 | 35 | |
| 29 | - /** | |
| 30 | - * Return the single instance of the class. | |
| 31 | - * | |
| 32 | - * @return mixed $instance The single instance of the class. | |
| 33 | - */ | |
| 34 | - public static function instance() { | |
| 35 | - if ( is_null( self::$instance ) ) { | |
| 36 | - self::$instance = new self(); | |
| 37 | - } | |
| 38 | - return self::$instance; | |
| 39 | - } | |
| 36 | + /** | |
| 37 | + * Return the single instance of the class. | |
| 38 | + * | |
| 39 | + * @return mixed $instance The single instance of the class. | |
| 40 | + */ | |
| 41 | + public static function instance() { | |
| 42 | + if ( is_null( static::$instance ) ) { | |
| 43 | + static::$instance = new self(); | |
| 44 | + } | |
| 45 | + return static::$instance; | |
| 46 | + } | |
| 40 | 47 | |
| 41 | 48 | |
| 42 | - /** | |
| 43 | - * Method get_class_name() | |
| 44 | - * | |
| 45 | - * @return string __CLASS__ Class name. | |
| 46 | - */ | |
| 47 | - public static function get_class_name() { | |
| 48 | - return __CLASS__; | |
| 49 | - } | |
| 49 | + /** | |
| 50 | + * Method get_class_name() | |
| 51 | + * | |
| 52 | + * @return string __CLASS__ Class name. | |
| 53 | + */ | |
| 54 | + public static function get_class_name() { | |
| 55 | + return __CLASS__; | |
| 56 | + } | |
| 50 | 57 | |
| 51 | - /** | |
| 52 | - * Method render() | |
| 53 | - * | |
| 54 | - * @param array ...$args Widget callback args. | |
| 55 | - * @return mixed render_site_info() | |
| 56 | - */ | |
| 57 | - public function render( ...$args ) { | |
| 58 | - $this->render_widget( $args ); | |
| 59 | - } | |
| 58 | + /** | |
| 59 | + * Method render() | |
| 60 | + * | |
| 61 | + * @param array ...$args Widget callback args. | |
| 62 | + * @return mixed render_site_info() | |
| 63 | + */ | |
| 64 | + public function render( ...$args ) { | |
| 65 | + $this->render_widget( $args ); | |
| 66 | + } | |
| 60 | 67 | |
| 61 | 68 | |
| 62 | - /** | |
| 63 | - * Render client overview Info. | |
| 64 | - * | |
| 65 | - * @param array $args Args data. | |
| 66 | - */ | |
| 67 | - public function render_widget( $args ) { | |
| 68 | - $data = is_array( $args ) && ! empty( $args[1][0] ) && is_array( $args[1][0] ) ? $args[1][0] : array(); | |
| 69 | - $stats_data = is_array( $data ) && ! empty( $data['stats_data']['posts'] ) ? $data['stats_data']['posts'] : array(); | |
| 70 | - if ( ! is_array( $stats_data ) ) { | |
| 71 | - $stats_data = array(); | |
| 72 | - } | |
| 69 | + /** | |
| 70 | + * Render client overview Info. | |
| 71 | + * | |
| 72 | + * @param array $args Args data. | |
| 73 | + */ | |
| 74 | + public function render_widget( $args ) { | |
| 75 | + $data = is_array( $args ) && ! empty( $args[1][0] ) && is_array( $args[1][0] ) ? $args[1][0] : array(); | |
| 76 | + $stats_data = is_array( $data ) && ! empty( $data['stats_data']['posts'] ) ? $data['stats_data']['posts'] : array(); | |
| 77 | + if ( ! is_array( $stats_data ) ) { | |
| 78 | + $stats_data = array(); | |
| 79 | + } | |
| 73 | 80 | |
| 74 | - $stats_prev_data = is_array( $data ) && ! empty( $data['stats_prev_data']['posts'] ) ? $data['stats_prev_data']['posts'] : array(); | |
| 75 | - if ( ! is_array( $stats_prev_data ) ) { | |
| 76 | - $stats_prev_data = array(); | |
| 77 | - } | |
| 81 | + $stats_prev_data = is_array( $data ) && ! empty( $data['stats_prev_data']['posts'] ) ? $data['stats_prev_data']['posts'] : array(); | |
| 82 | + if ( ! is_array( $stats_prev_data ) ) { | |
| 83 | + $stats_prev_data = array(); | |
| 84 | + } | |
| 78 | 85 | |
| 79 | - ?> | |
| 80 | - <div class="mainwp-widget-header"> | |
| 81 | - <h3 class="ui header handle-drag"> | |
| 82 | - <?php esc_html_e( 'Posts Management Event Tracker', 'mainwp' ); ?> | |
| 83 | - <div class="sub header"> | |
| 84 | - <?php esc_html_e( 'Overview of post-related activities with total events tallied.', 'mainwp' ); ?> | |
| 85 | - </div> | |
| 86 | - </h3> | |
| 87 | - </div> | |
| 86 | + ?> | |
| 87 | + <div class="mainwp-widget-header"> | |
| 88 | + <h2 class="ui header handle-drag"> | |
| 89 | + <?php esc_html_e( 'Posts Management Event Tracker', 'mainwp' ); ?> | |
| 90 | + <div class="sub header"> | |
| 91 | + <?php esc_html_e( 'Overview of post-related activities with total events tallied.', 'mainwp' ); ?> | |
| 92 | + </div> | |
| 93 | + </h2> | |
| 94 | + </div> | |
| 88 | 95 | |
| 89 | - <div class="mainwp-widget-insights-card"> | |
| 90 | - <?php | |
| 91 | - /** | |
| 92 | - * Action: mainwp_logs_widget_top | |
| 93 | - * | |
| 94 | - * Fires at the top of the widget. | |
| 95 | - * | |
| 96 | - * @since 4.6 | |
| 97 | - */ | |
| 98 | - do_action( 'mainwp_logs_widget_top', 'posts' ); | |
| 99 | - ?> | |
| 100 | - <div id="mainwp-message-zone" style="display:none;" class="ui message"></div> | |
| 101 | - <?php | |
| 102 | - wp_nonce_field( 'mainwp-admin-nonce' ); | |
| 103 | - $this->render_widget_content( $stats_data, $stats_prev_data ); | |
| 104 | - ?> | |
| 105 | - <?php | |
| 106 | - /** | |
| 107 | - * Action: mainwp_logs_widget_bottom | |
| 108 | - * | |
| 109 | - * Fires at the bottom of the widget. | |
| 110 | - * | |
| 111 | - * @since 4.6 | |
| 112 | - */ | |
| 113 | - do_action( 'mainwp_logs_widget_bottom', 'posts' ); | |
| 114 | - ?> | |
| 115 | - </div> | |
| 116 | - <div class="mainwp-widget-footer ui four columns stackable grid"> | |
| 117 | - <div class="column"> | |
| 118 | - </div> | |
| 119 | - <div class="column"> | |
| 120 | - </div> | |
| 121 | - </div> | |
| 122 | - <?php | |
| 123 | - } | |
| 96 | + <div class="mainwp-widget-insights-card mainwp-scrolly-overflow"> | |
| 97 | + <?php | |
| 98 | + /** | |
| 99 | + * Action: mainwp_logs_widget_top | |
| 100 | + * | |
| 101 | + * Fires at the top of the widget. | |
| 102 | + * | |
| 103 | + * @since 4.6 | |
| 104 | + */ | |
| 105 | + do_action( 'mainwp_logs_widget_top', 'posts' ); | |
| 106 | + ?> | |
| 107 | + <div id="mainwp-message-zone" style="display:none;" class="ui message"></div> | |
| 108 | + <?php | |
| 109 | + MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); | |
| 110 | + if ( ! empty( $data ) ) { | |
| 111 | + $this->render_widget_content( $stats_data, $stats_prev_data ); | |
| 112 | + } else { | |
| 113 | + MainWP_UI::render_empty_element_placeholder( __( 'No activity recorded', 'mainwp' ), __( 'Data will appear here once actions are tracked.', 'mainwp' ), '<em data-emoji=":bar_chart:" class="medium"></em>' ); | |
| 114 | + } | |
| 115 | + ?> | |
| 116 | + <?php | |
| 117 | + /** | |
| 118 | + * Action: mainwp_logs_widget_bottom | |
| 119 | + * | |
| 120 | + * Fires at the bottom of the widget. | |
| 121 | + * | |
| 122 | + * @since 4.6 | |
| 123 | + */ | |
| 124 | + do_action( 'mainwp_logs_widget_bottom', 'posts' ); | |
| 125 | + ?> | |
| 126 | + </div> | |
| 127 | + <div class="mainwp-widget-footer ui four columns stackable grid"> | |
| 128 | + <div class="column"> | |
| 129 | + </div> | |
| 130 | + <div class="column"> | |
| 131 | + </div> | |
| 132 | + </div> | |
| 133 | + <?php | |
| 134 | + } | |
| 124 | 135 | |
| 125 | - /** | |
| 126 | - * Method render_widget_content(). | |
| 127 | - * | |
| 128 | - * @param array $data Stats data. | |
| 129 | - * @param array $prev_data Previous stats data. | |
| 130 | - */ | |
| 131 | - public function render_widget_content( $data, $prev_data ) { | |
| 136 | + /** | |
| 137 | + * Method render_widget_content(). | |
| 138 | + * | |
| 139 | + * @param array $data Stats data. | |
| 140 | + * @param array $prev_data Previous stats data. | |
| 141 | + */ | |
| 142 | + public function render_widget_content( $data, $prev_data ) { | |
| 132 | 143 | |
| 133 | - $posts_data = array(); | |
| 134 | - if ( is_array( $data ) && isset( $data['post'] ) ) { | |
| 135 | - $posts_data = $data['post']; | |
| 136 | - if ( ! is_array( $posts_data ) ) { | |
| 137 | - $posts_data = array(); | |
| 138 | - } | |
| 139 | - } | |
| 144 | + $posts_data = array(); | |
| 145 | + if ( is_array( $data ) && isset( $data['post'] ) ) { | |
| 146 | + $posts_data = $data['post']; | |
| 147 | + if ( ! is_array( $posts_data ) ) { | |
| 148 | + $posts_data = array(); | |
| 149 | + } | |
| 150 | + } | |
| 140 | 151 | |
| 141 | - $posts_prev_data = array(); | |
| 142 | - if ( is_array( $prev_data ) && isset( $prev_data['post'] ) ) { | |
| 143 | - $posts_prev_data = $prev_data['post']; | |
| 144 | - if ( ! is_array( $posts_prev_data ) ) { | |
| 145 | - $posts_prev_data = array(); | |
| 146 | - } | |
| 147 | - } | |
| 152 | + $posts_prev_data = array(); | |
| 153 | + if ( is_array( $prev_data ) && isset( $prev_data['post'] ) ) { | |
| 154 | + $posts_prev_data = $prev_data['post']; | |
| 155 | + if ( ! is_array( $posts_prev_data ) ) { | |
| 156 | + $posts_prev_data = array(); | |
| 157 | + } | |
| 158 | + } | |
| 148 | 159 | |
| 149 | - $columns = array( | |
| 150 | - 'created' => esc_html__( 'Created', 'mainwp' ), | |
| 151 | - 'published' => esc_html__( 'Published', 'mainwp' ), | |
| 152 | - 'updated' => esc_html__( 'Updated', 'mainwp' ), | |
| 153 | - 'trashed' => esc_html__( 'Trashed', 'mainwp' ), | |
| 154 | - 'untrashed' => esc_html__( 'Untrashed', 'mainwp' ), | |
| 155 | - 'deleted' => esc_html__( 'Deleted', 'mainwp' ), | |
| 156 | - 'total_events' => esc_html__( 'Events', 'mainwp' ), | |
| 157 | - ); | |
| 160 | + $columns = array( | |
| 161 | + 'created' => esc_html__( 'Created', 'mainwp' ), | |
| 162 | + 'published' => esc_html__( 'Published', 'mainwp' ), | |
| 163 | + 'updated' => esc_html__( 'Updated', 'mainwp' ), | |
| 164 | + 'trashed' => esc_html__( 'Trashed', 'mainwp' ), | |
| 165 | + 'untrashed' => esc_html__( 'Untrashed', 'mainwp' ), | |
| 166 | + 'deleted' => esc_html__( 'Deleted', 'mainwp' ), | |
| 167 | + 'total_events' => esc_html__( 'Events', 'mainwp' ), | |
| 168 | + ); | |
| 158 | 169 | |
| 159 | - ?> | |
| 160 | - <div class="ui one column grid"> | |
| 161 | - <div class="left aligned middle aligned column"> | |
| 162 | - <div class="ui equal width grid"> | |
| 163 | - <?php | |
| 164 | - foreach ( $columns as $act => $title ) { | |
| 165 | - Log_Stats::render_stats_info( $posts_data, $act, $title, $posts_prev_data ); | |
| 166 | - } | |
| 167 | - ?> | |
| 168 | - </div> | |
| 169 | - </div> | |
| 170 | - <div class="left aligned middle aligned column"> | |
| 171 | - <div id="mainwp-module-log-chart-posts-management-wrapper" ></div> | |
| 172 | - <script type="text/javascript"> | |
| 173 | - jQuery( document ).ready( function() { | |
| 174 | - var options = { | |
| 175 | - chart: { | |
| 176 | - type: 'bar', | |
| 177 | - height: 350, | |
| 178 | - }, | |
| 179 | - plotOptions: { | |
| 180 | - bar: { | |
| 181 | - columnWidth: '60%' | |
| 182 | - } | |
| 183 | - }, | |
| 184 | - series: [ { | |
| 185 | - name: 'Events:', | |
| 186 | - data: [ | |
| 187 | - <?php | |
| 188 | - foreach ( $columns as $act => $title ) { | |
| 189 | - Log_Stats::render_chart_series( $posts_data, $act, $title, $posts_prev_data ); | |
| 190 | - } | |
| 191 | - ?> | |
| 192 | - ], | |
| 193 | - } ], | |
| 194 | - xaxis: { | |
| 195 | - labels: { | |
| 196 | - style: { | |
| 197 | - colors: '#999999', | |
| 198 | - } | |
| 199 | - } | |
| 200 | - }, | |
| 201 | - yaxis: { | |
| 202 | - labels: { | |
| 203 | - style: { | |
| 204 | - colors: '#999999', | |
| 205 | - } | |
| 206 | - } | |
| 207 | - }, | |
| 208 | - tooltip: { | |
| 209 | - theme: 'dark' | |
| 210 | - }, | |
| 211 | - } | |
| 212 | - var clients = new ApexCharts(document.querySelector("#mainwp-module-log-chart-posts-management-wrapper"), options); | |
| 213 | - setTimeout(() => { | |
| 214 | - clients.render(); | |
| 215 | - }, 1000); | |
| 216 | - } ); | |
| 217 | - </script> | |
| 218 | - </div> | |
| 219 | - </div> | |
| 220 | - <?php | |
| 221 | - } | |
| 170 | + ?> | |
| 171 | + <div class="ui grid"> | |
| 172 | + <div class="sixteen wide column"> | |
| 173 | + <div class="ui equal width grid"> | |
| 174 | + <?php | |
| 175 | + foreach ( $columns as $act => $title ) { | |
| 176 | + Log_Stats::render_stats_info( $posts_data, $act, $title, $posts_prev_data ); | |
| 177 | + } | |
| 178 | + ?> | |
| 179 | + </div> | |
| 180 | + </div> | |
| 181 | + <div class="sixteen wide column"> | |
| 182 | + <div id="mainwp-module-log-chart-posts-management-wrapper" ></div> | |
| 183 | + <script type="text/javascript"> | |
| 184 | + jQuery( document ).ready( function() { | |
| 185 | + let options = { | |
| 186 | + chart: { | |
| 187 | + type: 'bar', | |
| 188 | + height: 350, | |
| 189 | + }, | |
| 190 | + plotOptions: { | |
| 191 | + bar: { | |
| 192 | + columnWidth: '60%' | |
| 193 | + } | |
| 194 | + }, | |
| 195 | + series: [ { | |
| 196 | + name: 'Events:', | |
| 197 | + data: [ | |
| 198 | + <?php | |
| 199 | + foreach ( $columns as $act => $title ) { | |
| 200 | + Log_Stats::render_chart_series( $posts_data, $act, $title, $posts_prev_data ); | |
| 201 | + } | |
| 202 | + ?> | |
| 203 | + ], | |
| 204 | + } ], | |
| 205 | + xaxis: { | |
| 206 | + labels: { | |
| 207 | + style: { | |
| 208 | + colors: '#999999', | |
| 209 | + } | |
| 210 | + } | |
| 211 | + }, | |
| 212 | + yaxis: { | |
| 213 | + labels: { | |
| 214 | + style: { | |
| 215 | + colors: '#999999', | |
| 216 | + } | |
| 217 | + } | |
| 218 | + }, | |
| 219 | + tooltip: { | |
| 220 | + theme: 'dark' | |
| 221 | + }, | |
| 222 | + } | |
| 223 | + let clients = new ApexCharts(document.querySelector("#mainwp-module-log-chart-posts-management-wrapper"), options); | |
| 224 | + setTimeout(() => { | |
| 225 | + clients.render(); | |
| 226 | + }, 1000); | |
| 227 | + } ); | |
| 228 | + </script> | |
| 229 | + </div> | |
| 230 | + </div> | |
| 231 | + <?php | |
| 232 | + } | |
| 222 | 233 | } |