| 1 |
<?php |
| 2 |
/** |
| 3 |
* Selection Lite |
| 4 |
* Carefully selected Elementor addons bundle, for building the most awesome websites |
| 5 |
* |
| 6 |
* @encoding UTF-8 |
| 7 |
* @version 1.12 |
| 8 |
* @copyright (C) 2018-2024 Merkulove ( https://merkulov.design/ ). All rights reserved. |
| 9 |
* @license GPLv3 |
| 10 |
* @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01 |
| 11 |
* @support help@merkulov.design |
| 12 |
**/ |
| 13 |
|
| 14 |
namespace Merkulove\SelectionLite\Unity; |
| 15 |
|
| 16 |
/** Exit if accessed directly. */ |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
header( 'Status: 403 Forbidden' ); |
| 19 |
header( 'HTTP/1.1 403 Forbidden' ); |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* SINGLETON: Class used to implement Status Tab on plugin settings page. |
| 25 |
* |
| 26 |
* @since 1.0 |
| 27 |
* |
| 28 |
**/ |
| 29 |
final class TabStatus extends Tab { |
| 30 |
|
| 31 |
/** |
| 32 |
* Slug of current tab. |
| 33 |
* |
| 34 |
* @const TAB_SLUG |
| 35 |
**/ |
| 36 |
const TAB_SLUG = 'status'; |
| 37 |
|
| 38 |
/** |
| 39 |
* The one true StatusTab. |
| 40 |
* |
| 41 |
* @var TabStatus |
| 42 |
**/ |
| 43 |
private static $instance; |
| 44 |
|
| 45 |
/** |
| 46 |
* Generate Status Tab. |
| 47 |
* |
| 48 |
* @access public |
| 49 |
* @return void |
| 50 |
**/ |
| 51 |
public function add_settings() { |
| 52 |
|
| 53 |
/** Status Tab. */ |
| 54 |
$this->add_settings_base( self::TAB_SLUG ); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Render form with all settings fields. |
| 60 |
* |
| 61 |
* @since 1.0 |
| 62 |
* @access public |
| 63 |
* |
| 64 |
* @return void |
| 65 |
**/ |
| 66 |
public function do_settings() { |
| 67 |
|
| 68 |
/** No status tab, nothing to do. */ |
| 69 |
if ( ! $this->is_enabled( self::TAB_SLUG ) ) { return; } |
| 70 |
|
| 71 |
/** Render title. */ |
| 72 |
$this->render_title( self::TAB_SLUG ); |
| 73 |
|
| 74 |
/** Render fields. */ |
| 75 |
$this->do_settings_base( self::TAB_SLUG ); |
| 76 |
|
| 77 |
/** Render Reports. */ |
| 78 |
$this->render_reports(); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Render "System Requirements" field. |
| 84 |
* |
| 85 |
* @since 1.0 |
| 86 |
* @access public |
| 87 |
* |
| 88 |
* @return void |
| 89 |
**/ |
| 90 |
public function render_reports() { |
| 91 |
|
| 92 |
$tabs = Plugin::get_tabs(); |
| 93 |
if ( ! isset( $tabs[ self::TAB_SLUG ][ 'reports' ] ) ) { return; } |
| 94 |
|
| 95 |
$reports = []; |
| 96 |
|
| 97 |
/** Server. */ |
| 98 |
if ( $tabs[ self::TAB_SLUG ][ 'reports' ][ 'server' ][ 'enabled' ] ) { |
| 99 |
$reports[ 'server' ] = ReporterServer::get_instance(); |
| 100 |
} |
| 101 |
|
| 102 |
/** WordPress. */ |
| 103 |
if ( $tabs[ self::TAB_SLUG ][ 'reports' ][ 'wordpress' ][ 'enabled' ] ) { |
| 104 |
$reports[ 'wordpress' ] = ReporterWordPress::get_instance(); |
| 105 |
} |
| 106 |
|
| 107 |
/** Plugins. */ |
| 108 |
if ( $tabs[ self::TAB_SLUG ][ 'reports' ][ 'plugins' ][ 'enabled' ] ) { |
| 109 |
$reports[ 'plugins' ] = ReporterPlugins::get_instance(); |
| 110 |
} |
| 111 |
|
| 112 |
/** Theme. */ |
| 113 |
if ( $tabs[ self::TAB_SLUG ][ 'reports' ][ 'theme' ][ 'enabled' ] ) { |
| 114 |
$reports[ 'theme' ] = ReporterTheme::get_instance(); |
| 115 |
} |
| 116 |
|
| 117 |
?> |
| 118 |
<div class="mdc-system-requirements"> |
| 119 |
|
| 120 |
<?php foreach ( $reports as $key => $report ) : ?> |
| 121 |
<div class="mdp-status-<?php echo esc_attr( $key ); ?>"> |
| 122 |
<table class="mdc-system-requirements-table"> |
| 123 |
<thead> |
| 124 |
<tr> |
| 125 |
<th colspan="2"><?php echo esc_html( $report->get_title() ); ?></th> |
| 126 |
</tr> |
| 127 |
</thead> |
| 128 |
<tbody> |
| 129 |
<?php |
| 130 |
foreach ( $report->get_report() as $row ) { |
| 131 |
|
| 132 |
if ( is_array( $row['value'] ) ) { |
| 133 |
|
| 134 |
$this->render_array( $row['value'] ); |
| 135 |
|
| 136 |
} else { |
| 137 |
|
| 138 |
$this->render_string( $row ); |
| 139 |
|
| 140 |
} |
| 141 |
} |
| 142 |
?> |
| 143 |
</tbody> |
| 144 |
</table> |
| 145 |
</div> |
| 146 |
<?php endforeach; ?> |
| 147 |
|
| 148 |
</div> |
| 149 |
<?php |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Render row if value is string. |
| 155 |
* |
| 156 |
* @param array $row - Report row. |
| 157 |
* |
| 158 |
* @since 1.0 |
| 159 |
* @access public |
| 160 |
* |
| 161 |
* @return void |
| 162 |
**/ |
| 163 |
private function render_string( $row ) { |
| 164 |
?> |
| 165 |
<tr> |
| 166 |
<td><?php echo esc_html( $row['label'] ); ?>:</td> |
| 167 |
<td><span class="mdc-system-value"><?php echo wp_kses_post( $row['value'] ); ?></span></td> |
| 168 |
<th class="mdc-text-left"> |
| 169 |
<?php if ( isset( $row['warning'] ) && $row['warning'] ) : ?> |
| 170 |
<i class="material-icons mdc-system-warn">warning</i> |
| 171 |
<?php echo isset( $row['recommendation'] ) ? esc_html( $row['recommendation'] ) : ''; ?> |
| 172 |
<?php endif; ?> |
| 173 |
</th> |
| 174 |
</tr> |
| 175 |
<?php |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Render row if value is array. |
| 180 |
* |
| 181 |
* @param array $value - Report row value. |
| 182 |
* |
| 183 |
* @since 1.0 |
| 184 |
* @access public |
| 185 |
* |
| 186 |
* @return void |
| 187 |
**/ |
| 188 |
private function render_array( $value ) { |
| 189 |
|
| 190 |
foreach ( $value as $plugin_info ): ?> |
| 191 |
<tr> |
| 192 |
<td> |
| 193 |
<?php |
| 194 |
if ( $plugin_info['PluginURI'] ) { |
| 195 |
echo "<a href='" . esc_url( $plugin_info['PluginURI'] ) . "'>" . esc_html( $plugin_info['Name'] ) . "</a>"; |
| 196 |
} else { |
| 197 |
echo esc_html( $plugin_info['Name'] ); |
| 198 |
} |
| 199 |
|
| 200 |
if ( $plugin_info['Version'] ) { echo ' - ' . esc_html( $plugin_info['Version'] ); } |
| 201 |
?> |
| 202 |
</td> |
| 203 |
<td> |
| 204 |
<?php |
| 205 |
if ( $plugin_info['Author'] ) { |
| 206 |
|
| 207 |
echo "By "; |
| 208 |
|
| 209 |
if ( $plugin_info['AuthorURI'] ) { |
| 210 |
echo "<a href='" . esc_url( $plugin_info['AuthorURI'] ) . "'>" . esc_html( $plugin_info['Author'] ) . "</a>"; |
| 211 |
} else { |
| 212 |
echo esc_html( $plugin_info['Author'] ); |
| 213 |
} |
| 214 |
} |
| 215 |
?> |
| 216 |
</td> |
| 217 |
</tr> |
| 218 |
<?php |
| 219 |
endforeach; |
| 220 |
|
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Main StatusTab Instance. |
| 225 |
* Insures that only one instance of StatusTab exists in memory at any one time. |
| 226 |
* |
| 227 |
* @static |
| 228 |
* @return TabStatus |
| 229 |
**/ |
| 230 |
public static function get_instance() { |
| 231 |
|
| 232 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { |
| 233 |
|
| 234 |
self::$instance = new self; |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
return self::$instance; |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
} |
| 243 |
|