← All changes
|
modules/logs/widgets/widget-log-graph-plugins-widget.php
+176
-163
5.0.3
→
6.2.1
View file →
| @@ -11,9 +11,15 @@ | ||
| 11 | 11 | namespace MainWP\Dashboard\Module\Log; |
| 12 | 12 | |
| 13 | 13 | use MainWP\Dashboard\MainWP_DB; |
| 14 | 14 | use MainWP\Dashboard\MainWP_Utility; |
| 15 | +use MainWP\Dashboard\MainWP_UI; | |
| 15 | 16 | |
| 17 | +// Exit if accessed directly. | |
| 18 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 19 | + exit; | |
| 20 | +} | |
| 21 | + | |
| 16 | 22 | /** |
| 17 | 23 | * Class Log_Graph_Plugins_Widget |
| 18 | 24 | * |
| 19 | 25 | * Displays the Logs info. |
| @@ -19,180 +25,187 @@ | ||
| 19 | 25 | * Displays the Logs info. |
| 20 | 26 | */ |
| 21 | 27 | class Log_Graph_Plugins_Widget { |
| 22 | 28 | |
| 23 | - /** | |
| 24 | - * Protected static variable to hold the single instance of the class. | |
| 25 | - * | |
| 26 | - * @var mixed Default null | |
| 27 | - */ | |
| 28 | - 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; | |
| 29 | 35 | |
| 30 | - /** | |
| 31 | - * Return the single instance of the class. | |
| 32 | - * | |
| 33 | - * @return mixed $instance The single instance of the class. | |
| 34 | - */ | |
| 35 | - public static function instance() { | |
| 36 | - if ( is_null( self::$instance ) ) { | |
| 37 | - self::$instance = new self(); | |
| 38 | - } | |
| 39 | - return self::$instance; | |
| 40 | - } | |
| 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 | + } | |
| 41 | 47 | |
| 42 | 48 | |
| 43 | - /** | |
| 44 | - * Method get_class_name() | |
| 45 | - * | |
| 46 | - * @return string __CLASS__ Class name. | |
| 47 | - */ | |
| 48 | - public static function get_class_name() { | |
| 49 | - return __CLASS__; | |
| 50 | - } | |
| 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 | + } | |
| 51 | 57 | |
| 52 | - /** | |
| 53 | - * Method render() | |
| 54 | - */ | |
| 55 | - public function render() { | |
| 56 | - $this->render_widget(); | |
| 57 | - } | |
| 58 | + /** | |
| 59 | + * Method render() | |
| 60 | + */ | |
| 61 | + public function render() { | |
| 62 | + $this->render_widget(); | |
| 63 | + } | |
| 58 | 64 | |
| 59 | 65 | |
| 60 | - /** | |
| 61 | - * Render client overview Info. | |
| 62 | - */ | |
| 63 | - public function render_widget() { | |
| 64 | - ?> | |
| 65 | - <div class="mainwp-widget-header"> | |
| 66 | - <h3 class="ui header handle-drag"> | |
| 67 | - <?php esc_html_e( 'Site Plugin Status Breakdown', 'mainwp' ); ?> | |
| 68 | - <div class="sub header"> | |
| 69 | - <?php esc_html_e( 'Total number of plugins per site, differentiated by active (blue) and inactive (green) status for quick assessment.', 'mainwp' ); ?> | |
| 70 | - </div> | |
| 71 | - </h3> | |
| 72 | - </div> | |
| 66 | + /** | |
| 67 | + * Render client overview Info. | |
| 68 | + */ | |
| 69 | + public function render_widget() { | |
| 70 | + $sites_count = MainWP_DB::instance()->get_websites_count(); | |
| 71 | + ?> | |
| 72 | + <div class="mainwp-widget-header"> | |
| 73 | + <h2 class="ui header handle-drag"> | |
| 74 | + <?php esc_html_e( 'Site Plugin Status Breakdown', 'mainwp' ); ?> | |
| 75 | + <div class="sub header"> | |
| 76 | + <?php esc_html_e( 'Total number of plugins per site, differentiated by active (blue) and inactive (green) status for quick assessment.', 'mainwp' ); ?> | |
| 77 | + </div> | |
| 78 | + </h2> | |
| 79 | + </div> | |
| 73 | 80 | |
| 74 | - <div class="mainwp-widget-insights-card"> | |
| 75 | - <?php | |
| 76 | - /** | |
| 77 | - * Action: mainwp_logs_widget_top | |
| 78 | - * | |
| 79 | - * Fires at the top of the widget. | |
| 80 | - * | |
| 81 | - * @since 4.6 | |
| 82 | - */ | |
| 83 | - do_action( 'mainwp_logs_widget_top', 'status' ); | |
| 84 | - ?> | |
| 85 | - <div id="mainwp-message-zone" style="display:none;" class="ui message"></div> | |
| 86 | - <?php | |
| 87 | - wp_nonce_field( 'mainwp-admin-nonce' ); | |
| 88 | - $this->render_widget_content(); | |
| 89 | - ?> | |
| 90 | - <?php | |
| 91 | - /** | |
| 92 | - * Action: mainwp_logs_widget_bottom | |
| 93 | - * | |
| 94 | - * Fires at the bottom of the widget. | |
| 95 | - * | |
| 96 | - * @since 4.6 | |
| 97 | - */ | |
| 98 | - do_action( 'mainwp_logs_widget_bottom', 'status' ); | |
| 99 | - ?> | |
| 100 | - </div> | |
| 101 | - <div class="mainwp-widget-footer ui four columns stackable grid"> | |
| 102 | - <div class="column"> | |
| 103 | - </div> | |
| 104 | - <div class="column"> | |
| 105 | - </div> | |
| 106 | - </div> | |
| 107 | - <?php | |
| 108 | - } | |
| 81 | + <div class="mainwp-widget-insights-card mainwp-scrolly-overflow"> | |
| 82 | + <?php | |
| 83 | + /** | |
| 84 | + * Action: mainwp_logs_widget_top | |
| 85 | + * | |
| 86 | + * Fires at the top of the widget. | |
| 87 | + * | |
| 88 | + * @since 4.6 | |
| 89 | + */ | |
| 90 | + do_action( 'mainwp_logs_widget_top', 'status' ); | |
| 91 | + ?> | |
| 92 | + <div id="mainwp-message-zone" style="display:none;" class="ui message"></div> | |
| 93 | + <?php | |
| 94 | + MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); | |
| 95 | + if ( 0 < intval( $sites_count ) ) { | |
| 96 | + $this->render_widget_content(); | |
| 97 | + } else { | |
| 98 | + MainWP_UI::render_empty_element_placeholder( __( 'No Plugin Data', 'mainwp' ), '<a href="admin.php?page=managesites&do=new">' . __( 'Start connecting your sites now', 'mainwp' ) . '</a>', '<em data-emoji=":bar_chart:" class="medium"></em>' ); | |
| 99 | + } | |
| 100 | + ?> | |
| 101 | + <?php | |
| 102 | + /** | |
| 103 | + * Action: mainwp_logs_widget_bottom | |
| 104 | + * | |
| 105 | + * Fires at the bottom of the widget. | |
| 106 | + * | |
| 107 | + * @since 4.6 | |
| 108 | + */ | |
| 109 | + do_action( 'mainwp_logs_widget_bottom', 'status' ); | |
| 110 | + ?> | |
| 111 | + </div> | |
| 112 | + <div class="mainwp-widget-footer ui four columns stackable grid"> | |
| 113 | + <div class="column"> | |
| 114 | + </div> | |
| 115 | + <div class="column"> | |
| 116 | + </div> | |
| 117 | + </div> | |
| 118 | + <?php | |
| 119 | + } | |
| 109 | 120 | |
| 110 | - /** | |
| 111 | - * Method render_widget_content() | |
| 112 | - */ | |
| 113 | - public function render_widget_content() { | |
| 114 | - $wp_plugins = array(); | |
| 115 | - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); | |
| 116 | - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 117 | - $plugins = ! empty( $website->plugins ) ? json_decode( $website->plugins, 1 ) : array(); | |
| 118 | - if ( ! is_array( $plugins ) ) { | |
| 119 | - $plugins = array(); | |
| 120 | - } | |
| 121 | - $active = MainWP_Utility::get_sub_array_having( $plugins, 'active', 1 ); | |
| 122 | - $inactive = MainWP_Utility::get_sub_array_having( $plugins, 'active', 0 ); | |
| 121 | + /** | |
| 122 | + * Method render_widget_content() | |
| 123 | + */ | |
| 124 | + public function render_widget_content() { | |
| 125 | + $wp_plugins = array(); | |
| 126 | + $wpsite_fields = array( 'id', 'name', 'plugins' ); | |
| 127 | + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user_by_params( array( 'select_wp_fields' => $wpsite_fields ) ) ); | |
| 128 | + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 129 | + $plugins = ! empty( $website->plugins ) ? json_decode( $website->plugins, 1 ) : array(); | |
| 130 | + if ( ! is_array( $plugins ) ) { | |
| 131 | + $plugins = array(); | |
| 132 | + } | |
| 133 | + $active = MainWP_Utility::get_sub_array_having( $plugins, 'active', 1 ); | |
| 134 | + $inactive = MainWP_Utility::get_sub_array_having( $plugins, 'active', 0 ); | |
| 123 | 135 | |
| 124 | - if ( ! isset( $wp_plugins[ $website->id ] ) ) { | |
| 125 | - $wp_plugins[ $website->id ] = array(); | |
| 126 | - } | |
| 136 | + if ( ! isset( $wp_plugins[ $website->id ] ) ) { | |
| 137 | + $wp_plugins[ $website->id ] = array(); | |
| 138 | + } | |
| 127 | 139 | |
| 128 | - $wp_plugins[ $website->id ]['active'] = count( $active ); | |
| 129 | - $wp_plugins[ $website->id ]['inactive'] = count( $inactive ); | |
| 130 | - $wp_plugins[ $website->id ]['name'] = $website->name; | |
| 131 | - } | |
| 132 | - MainWP_DB::free_result( $websites ); | |
| 140 | + $wp_plugins[ $website->id ]['active'] = count( $active ); | |
| 141 | + $wp_plugins[ $website->id ]['inactive'] = count( $inactive ); | |
| 142 | + $wp_plugins[ $website->id ]['name'] = $website->name; | |
| 143 | + } | |
| 144 | + MainWP_DB::free_result( $websites ); | |
| 133 | 145 | |
| 134 | - ?> | |
| 135 | - <div id="mainwp-module-log-chart-plugins-wrapper" ></div> | |
| 146 | + ?> | |
| 147 | + <div id="mainwp-module-log-chart-plugins-wrapper" ></div> | |
| 136 | 148 | |
| 137 | - <script type="text/javascript"> | |
| 138 | - jQuery( document ).ready( function() { | |
| 139 | - var options = { | |
| 140 | - chart: { | |
| 141 | - type: 'bar', | |
| 142 | - stacked: true | |
| 143 | - }, | |
| 144 | - plotOptions: { | |
| 145 | - bar: { | |
| 146 | - horizontal: true | |
| 147 | - } | |
| 148 | - }, | |
| 149 | - series: [ { | |
| 150 | - name: 'Active Plugins', | |
| 151 | - data: [ | |
| 152 | - <?php foreach ( $wp_plugins as $value ) : ?> | |
| 153 | - { | |
| 154 | - x: '<?php echo esc_js( $value['name'] ) . '"'; ?>', | |
| 155 | - y: <?php echo intval( $value['active'] ); ?>, | |
| 156 | - fillColor: "#18a4e0", | |
| 157 | - }, | |
| 158 | - <?php endforeach; ?> | |
| 159 | - ] | |
| 160 | - }, { | |
| 161 | - name: 'Inactive Plugins', | |
| 162 | - data: [ | |
| 163 | - <?php foreach ( $wp_plugins as $value ) : ?> | |
| 164 | - { | |
| 165 | - x: '<?php echo esc_js( $value['name'] ) . '"'; ?>', | |
| 166 | - y: <?php echo intval( $value['inactive'] ); ?>, | |
| 167 | - }, | |
| 168 | - <?php endforeach; ?> | |
| 169 | - ] | |
| 170 | - } | |
| 171 | - ], | |
| 172 | - xaxis: { | |
| 173 | - labels: { | |
| 174 | - style: { | |
| 175 | - colors: '#999999', | |
| 176 | - } | |
| 177 | - } | |
| 178 | - }, | |
| 179 | - yaxis: { | |
| 180 | - labels: { | |
| 181 | - style: { | |
| 182 | - colors: '#999999', | |
| 183 | - } | |
| 184 | - } | |
| 185 | - }, | |
| 186 | - tooltip: { | |
| 187 | - theme: 'dark' | |
| 188 | - }, | |
| 189 | - } | |
| 190 | - var plugin = new ApexCharts(document.querySelector("#mainwp-module-log-chart-plugins-wrapper"), options); | |
| 191 | - setTimeout(() => { | |
| 192 | - plugin.render(); | |
| 193 | - }, 1000); | |
| 194 | - } ); | |
| 195 | - </script> | |
| 196 | - <?php | |
| 197 | - } | |
| 149 | + <script type="text/javascript"> | |
| 150 | + jQuery( document ).ready( function() { | |
| 151 | + let options = { | |
| 152 | + chart: { | |
| 153 | + type: 'bar', | |
| 154 | + stacked: true, | |
| 155 | + height: '100%', | |
| 156 | + }, | |
| 157 | + plotOptions: { | |
| 158 | + bar: { | |
| 159 | + horizontal: true | |
| 160 | + } | |
| 161 | + }, | |
| 162 | + series: [ { | |
| 163 | + name: 'Active Plugins', | |
| 164 | + data: [ | |
| 165 | + <?php foreach ( $wp_plugins as $value ) : ?> | |
| 166 | + { | |
| 167 | + x: '<?php echo esc_js( $value['name'] ) . '"'; ?>', | |
| 168 | + y: <?php echo intval( $value['active'] ); ?>, | |
| 169 | + fillColor: "#18a4e0", | |
| 170 | + }, | |
| 171 | + <?php endforeach; ?> | |
| 172 | + ] | |
| 173 | + }, { | |
| 174 | + name: 'Inactive Plugins', | |
| 175 | + data: [ | |
| 176 | + <?php foreach ( $wp_plugins as $value ) : ?> | |
| 177 | + { | |
| 178 | + x: '<?php echo esc_js( $value['name'] ) . '"'; ?>', | |
| 179 | + y: <?php echo intval( $value['inactive'] ); ?>, | |
| 180 | + }, | |
| 181 | + <?php endforeach; ?> | |
| 182 | + ] | |
| 183 | + } | |
| 184 | + ], | |
| 185 | + xaxis: { | |
| 186 | + labels: { | |
| 187 | + style: { | |
| 188 | + colors: '#999999', | |
| 189 | + } | |
| 190 | + } | |
| 191 | + }, | |
| 192 | + yaxis: { | |
| 193 | + labels: { | |
| 194 | + style: { | |
| 195 | + colors: '#999999', | |
| 196 | + } | |
| 197 | + } | |
| 198 | + }, | |
| 199 | + tooltip: { | |
| 200 | + theme: 'dark' | |
| 201 | + }, | |
| 202 | + } | |
| 203 | + let plugin = new ApexCharts(document.querySelector("#mainwp-module-log-chart-plugins-wrapper"), options); | |
| 204 | + setTimeout(() => { | |
| 205 | + plugin.render(); | |
| 206 | + }, 1000); | |
| 207 | + } ); | |
| 208 | + </script> | |
| 209 | + <?php | |
| 210 | + } | |
| 198 | 211 | } |