| 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_Php_Widget |
| 18 |
* |
| 19 |
* Displays the Logs info. |
| 20 |
*/ |
| 21 |
class Log_Graph_Php_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( self::$instance ) ) { |
| 37 |
self::$instance = new self(); |
| 38 |
} |
| 39 |
return self::$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( 'PHP Version Distribution', 'mainwp' ); ?> |
| 68 |
<div class="sub header"> |
| 69 |
<?php esc_html_e( 'Distribution of PHP versions across the sites. Track which PHP versions are most prevalent in your network.', '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', 'php' ); |
| 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', 'php' ); |
| 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 |
$versions = array(); |
| 115 |
$websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites() ); |
| 116 |
while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { |
| 117 |
if ( ! empty( $website->phpversion ) ) { |
| 118 |
$ver = substr( $website->phpversion, 0, 5 ); |
| 119 |
} else { |
| 120 |
$ver = 'N/A'; |
| 121 |
} |
| 122 |
if ( ! isset( $versions[ $ver ] ) ) { |
| 123 |
$versions[ $ver ] = 1; |
| 124 |
} else { |
| 125 |
$versions[ $ver ] += 1; |
| 126 |
} |
| 127 |
} |
| 128 |
MainWP_DB::free_result( $websites ); |
| 129 |
|
| 130 |
?> |
| 131 |
<div id="mainwp-module-log-chart-php-wrapper" ></div> |
| 132 |
<script type="text/javascript"> |
| 133 |
jQuery( document ).ready( function() { |
| 134 |
var options = { |
| 135 |
chart: { |
| 136 |
type: 'bar' |
| 137 |
}, |
| 138 |
series: [ { |
| 139 |
name: 'Sites', |
| 140 |
data: [ |
| 141 |
<?php foreach ( $versions as $version => $count ) : ?> |
| 142 |
{ |
| 143 |
x: '<?php echo esc_js( $version ); ?>', |
| 144 |
y: <?php echo intval( $count ); ?>, |
| 145 |
fillColor: '#18a4e0' |
| 146 |
}, |
| 147 |
<?php endforeach; ?> |
| 148 |
] |
| 149 |
} ], |
| 150 |
xaxis: { |
| 151 |
labels: { |
| 152 |
style: { |
| 153 |
colors: '#999999', |
| 154 |
} |
| 155 |
} |
| 156 |
}, |
| 157 |
yaxis: { |
| 158 |
labels: { |
| 159 |
style: { |
| 160 |
colors: '#999999', |
| 161 |
} |
| 162 |
} |
| 163 |
}, |
| 164 |
tooltip: { |
| 165 |
theme: 'dark' |
| 166 |
}, |
| 167 |
} |
| 168 |
var php = new ApexCharts(document.querySelector("#mainwp-module-log-chart-php-wrapper"), options); |
| 169 |
setTimeout(() => { |
| 170 |
php.render(); |
| 171 |
}, 1000); |
| 172 |
} ); |
| 173 |
</script> |
| 174 |
<?php |
| 175 |
} |
| 176 |
} |
| 177 |
|