PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
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 5.2.1 All 155 releases
mainwp / modules / logs / widgets / widget-log-graph-themes-widget.php

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

187 lines 5.9 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 use MainWP\Dashboard\MainWP_UI;
16
17 // Exit if accessed directly.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Class Log_Graph_Themes_Widget
24 *
25 * Displays the Logs info.
26 */
27 class Log_Graph_Themes_Widget {
28
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;
35
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 }
47
48
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 }
57
58 /**
59 * Method render()
60 */
61 public function render() {
62 $this->render_widget();
63 }
64
65
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( 'Active Themes Overview', 'mainwp' ); ?>
75 <div class="sub header">
76 <?php esc_html_e( 'Number of sites using each theme. The bar height indicates the prevalence of a theme across your network.', 'mainwp' ); ?>
77 </div>
78 </h2>
79 </div>
80
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', 'themes' );
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 Themes 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', 'themes' );
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 }
120
121 /**
122 * Method render_widget_content()
123 */
124 public function render_widget_content() {
125 $themes = array();
126 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, array( 'site_info' ) ) );
127 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
128 $site_info = ! empty( $website->site_info ) ? json_decode( $website->site_info, true ) : array();
129 if ( ! is_array( $site_info ) ) {
130 $site_info = array();
131 }
132 $theme = isset( $site_info['themeactivated'] ) ? $site_info['themeactivated'] : 'N/A';
133 if ( ! isset( $themes[ $theme ] ) ) {
134 $themes[ $theme ] = 1;
135 }
136 $themes[ $theme ] += 1;
137 }
138 MainWP_DB::free_result( $websites );
139 ?>
140 <div id="mainwp-module-log-chart-themes-wrapper"></div>
141 <script type="text/javascript">
142 jQuery( document ).ready( function() {
143 let options = {
144 chart: {
145 type: 'bar',
146 height: 350,
147 },
148 series: [ {
149 name: 'Sites',
150 data: [
151 <?php foreach ( $themes as $theme => $count ) : ?>
152 {
153 x: '<?php echo esc_js( $theme ); ?>',
154 y: <?php echo intval( $count ); ?>,
155 fillColor: <?php echo $count >= 3 ? '"#7fb100"' : '"#18a4e0"'; ?>,
156 },
157 <?php endforeach; ?>
158 ]
159 } ],
160 xaxis: {
161 labels: {
162 style: {
163 colors: '#999999',
164 }
165 }
166 },
167 yaxis: {
168 labels: {
169 style: {
170 colors: '#999999',
171 }
172 }
173 },
174 tooltip: {
175 theme: 'dark'
176 },
177 }
178 let theme = new ApexCharts(document.querySelector("#mainwp-module-log-chart-themes-wrapper"), options);
179 setTimeout(() => {
180 theme.render();
181 }, 1000);
182 } );
183 </script>
184 <?php
185 }
186 }
187