| 1 |
<?php |
| 2 |
namespace epiphyt\Embed_Privacy\admin; |
| 3 |
|
| 4 |
use epiphyt\Embed_Privacy\data\Providers; |
| 5 |
|
| 6 |
/** |
| 7 |
* Admin support data related functionality. |
| 8 |
* |
| 9 |
* @author Epiphyt |
| 10 |
* @license GPL2 |
| 11 |
* @package epiphyt\Embed_Privacy |
| 12 |
* @since 1.11.0 |
| 13 |
*/ |
| 14 |
final class Support_Data { |
| 15 |
const CAPABILITY = 'manage_options'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Get support data. |
| 19 |
* |
| 20 |
* @return string Support data |
| 21 |
*/ |
| 22 |
public static function get() { |
| 23 |
$output = self::get_system_data(); |
| 24 |
$output .= self::get_plugin_data(); |
| 25 |
$output .= self::get_theme_data(); |
| 26 |
$output .= self::get_provider_data(); |
| 27 |
|
| 28 |
return \trim( $output ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Get database data. |
| 33 |
* |
| 34 |
* @return string Database name and version |
| 35 |
*/ |
| 36 |
private static function get_database_data() { |
| 37 |
/** @var \epiphyt\Embed_Privacy\admin\wpdb $wpdb */ |
| 38 |
global $wpdb; |
| 39 |
|
| 40 |
// phpcs:disable WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info, WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info |
| 41 |
if ( empty( $wpdb->use_mysqli ) && \function_exists( 'mysql_get_server_info' ) ) { |
| 42 |
/** @disregard P1010 existence is checked above */ |
| 43 |
$mysql_server_type = \mysql_get_server_info( $wpdb->dbh ); // phpcs:ignore PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved |
| 44 |
} |
| 45 |
else { |
| 46 |
$mysql_server_type = \mysqli_get_server_info( $wpdb->dbh ); |
| 47 |
} |
| 48 |
// phpcs:enable WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info, WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info |
| 49 |
|
| 50 |
$name = \stristr( $mysql_server_type, 'mariadb' ) ? 'MariaDB' : 'MySQL'; |
| 51 |
$version = $wpdb->get_var( 'SELECT VERSION()' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 52 |
|
| 53 |
return $name . ' ' . $version; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get a formatted heading. |
| 58 |
* |
| 59 |
* @param string $title Title to format |
| 60 |
* @return string Formatted heading |
| 61 |
*/ |
| 62 |
private static function get_heading( $title ) { |
| 63 |
$output = $title . \PHP_EOL; |
| 64 |
$output .= \str_repeat( '-', \mb_strlen( $title ) ) . \PHP_EOL; |
| 65 |
|
| 66 |
return $output; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get plugin support data. |
| 71 |
* |
| 72 |
* @return string Plugin support data |
| 73 |
*/ |
| 74 |
private static function get_plugin_data() { |
| 75 |
$active_plugins = \wp_get_active_and_valid_plugins(); |
| 76 |
$data = []; |
| 77 |
$output = self::get_heading( \__( 'Active plugins', 'embed-privacy' ) ); |
| 78 |
|
| 79 |
foreach ( $active_plugins as $plugin ) { |
| 80 |
$plugin_data = \get_plugin_data( $plugin, false, false ); |
| 81 |
$data[] = [ |
| 82 |
'name' => $plugin_data['Name'], |
| 83 |
'plugin_uri' => $plugin_data['PluginURI'], |
| 84 |
'version' => $plugin_data['Version'], |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
$output .= \var_export( $data, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
| 89 |
|
| 90 |
return $output . \PHP_EOL . \PHP_EOL; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Get embed provider data. |
| 95 |
* |
| 96 |
* @return string Provider data |
| 97 |
*/ |
| 98 |
private static function get_provider_data() { |
| 99 |
$output = self::get_heading( \__( 'Active providers', 'embed-privacy' ) ); |
| 100 |
$providers = Providers::get_instance()->get_list(); |
| 101 |
$data = []; |
| 102 |
|
| 103 |
foreach ( $providers as $provider ) { |
| 104 |
$data[] = [ |
| 105 |
'is_disabled' => $provider->is_disabled(), |
| 106 |
'name' => $provider->get_name(), |
| 107 |
'pattern' => $provider->get_pattern(), |
| 108 |
'title' => $provider->get_title(), |
| 109 |
]; |
| 110 |
} |
| 111 |
|
| 112 |
$output .= \var_export( $data, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
| 113 |
|
| 114 |
return $output . \PHP_EOL . \PHP_EOL; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Get theme support data. |
| 119 |
* |
| 120 |
* @return string Theme support data |
| 121 |
*/ |
| 122 |
private static function get_theme_data() { |
| 123 |
$active_themes = \wp_get_active_and_valid_themes(); |
| 124 |
$data = []; |
| 125 |
$output = self::get_heading( \__( 'Active themes', 'embed-privacy' ) ); |
| 126 |
|
| 127 |
foreach ( $active_themes as $theme ) { |
| 128 |
$theme_data = \wp_get_theme( '', \dirname( $theme ) ); |
| 129 |
$data[] = [ |
| 130 |
'name' => $theme_data->get( 'Name' ), |
| 131 |
'theme_uri' => $theme_data->get( 'ThemeURI' ), |
| 132 |
'version' => $theme_data->get( 'Version' ), |
| 133 |
]; |
| 134 |
} |
| 135 |
|
| 136 |
$output .= \var_export( $data, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export |
| 137 |
|
| 138 |
return $output . \PHP_EOL . \PHP_EOL; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Get system data. |
| 143 |
* |
| 144 |
* @return string System data |
| 145 |
*/ |
| 146 |
private static function get_system_data() { |
| 147 |
$output = self::get_heading( \__( 'System data', 'embed-privacy' ) ); |
| 148 |
/* translators: version */ |
| 149 |
$output .= \sprintf( \__( 'Embed Privacy migrate version: %s', 'embed-privacy' ), \get_option( 'embed_privacy_migrate_version' ) ) . \PHP_EOL; |
| 150 |
/* translators: true/false */ |
| 151 |
$output .= \sprintf( \__( 'Embed Privacy is migrating: %s', 'embed-privacy' ), \get_option( 'embed_privacy_is_migrating' ) ? 'true' : 'false' ) . \PHP_EOL; |
| 152 |
/* translators: count */ |
| 153 |
$output .= \sprintf( \__( 'Embed Privacy migration count: %s', 'embed-privacy' ), \get_option( 'embed_privacy_migration_count' ) ?: 0 ) . \PHP_EOL; |
| 154 |
/* translators: version */ |
| 155 |
$output .= \sprintf( \__( 'WordPress version: %s', 'embed-privacy' ), self::get_version() ) . \PHP_EOL; |
| 156 |
/* translators: site URL */ |
| 157 |
$output .= \sprintf( \__( 'Site URL: %s', 'embed-privacy' ), \site_url() ) . \PHP_EOL; |
| 158 |
/* translators: home URL */ |
| 159 |
$output .= \sprintf( \__( 'Home URL: %s', 'embed-privacy' ), \home_url() ) . \PHP_EOL; |
| 160 |
/* translators: memory limit */ |
| 161 |
$output .= \sprintf( \__( 'WordPress memory limit: %s', 'embed-privacy' ), \WP_MAX_MEMORY_LIMIT ) . \PHP_EOL; |
| 162 |
/* translators: memory limit */ |
| 163 |
$output .= \sprintf( \__( 'PHP memory limit: %s', 'embed-privacy' ), \function_exists( 'ini_get' ) ? \ini_get( 'memory_limit' ) : \__( 'unknown', 'embed-privacy' ) ) . \PHP_EOL; |
| 164 |
/* translators: time limit */ |
| 165 |
$output .= \sprintf( \__( 'PHP time limit: %s', 'embed-privacy' ), \function_exists( 'ini_get' ) ? \ini_get( 'max_execution_time' ) : \__( 'unknown', 'embed-privacy' ) ) . \PHP_EOL; |
| 166 |
/* translators: version */ |
| 167 |
$output .= \sprintf( \__( 'PHP version: %s', 'embed-privacy' ), \phpversion() ) . \PHP_EOL; |
| 168 |
/* translators: database data */ |
| 169 |
$output .= \sprintf( \__( 'Database: %s', 'embed-privacy' ), self::get_database_data() ) . \PHP_EOL; |
| 170 |
|
| 171 |
return $output . \PHP_EOL; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Get WordPress version. |
| 176 |
* Copy of wp_get_wp_version() from WordPress 6.7. |
| 177 |
* |
| 178 |
* @return string Current WordPress version |
| 179 |
*/ |
| 180 |
private static function get_version() { |
| 181 |
if ( \function_exists( 'wp_get_wp_version' ) ) { |
| 182 |
return \wp_get_wp_version(); |
| 183 |
} |
| 184 |
|
| 185 |
static $wp_version; |
| 186 |
|
| 187 |
if ( ! isset( $wp_version ) ) { |
| 188 |
require \ABSPATH . \WPINC . '/version.php'; |
| 189 |
} |
| 190 |
|
| 191 |
return $wp_version; |
| 192 |
} |
| 193 |
} |
| 194 |
|