PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.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 5.2.1 5.2.2 5.3 All 153 releases
mainwp / modules / logs / widgets / widget-log-graph-plugins-widget.php

widget-log-graph-plugins-widget.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.1, at modules/logs/widgets/widget-log-graph-plugins-widget.php

199 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Logs Widget
4 *
5 * Displays the Logs Info.
6 *
7 * @package MainWP/Dashboard
8 * @version 4.6
9 */
10
11 namespace MainWP\Dashboard\Module\Log;
12
13 use MainWP\Dashboard\MainWP_DB;
14 use MainWP\Dashboard\MainWP_Utility;
15
16 /**
17 * Class Log_Graph_Plugins_Widget
18 *
19 * Displays the Logs info.
20 */
21 class Log_Graph_Plugins_Widget {
22
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 /**
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( static::$instance ) ) {
37 static::$instance = new self();
38 }
39 return static::$instance;
40 }
41
42
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 }
51
52 /**
53 * Method render()
54 */
55 public function render() {
56 $this->render_widget();
57 }
58
59
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>
73
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 }
109
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 );
123
124 if ( ! isset( $wp_plugins[ $website->id ] ) ) {
125 $wp_plugins[ $website->id ] = array();
126 }
127
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 );
133
134 ?>
135 <div id="mainwp-module-log-chart-plugins-wrapper" ></div>
136
137 <script type="text/javascript">
138 jQuery( document ).ready( function() {
139 let 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 let 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 }
198 }
199