PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/all-in-one-seo-pack/app/Common/Tools/SystemStatus.php

https://gitlab.com/ebrjose/comcebu
PHP | 341 lines | 267 code | 17 blank | 57 comment | 9 complexity | 3b8e388983dc89f04d9ccba590089af5 MD5 | raw file
  1. <?php
  2. namespace AIOSEO\Plugin\Common\Tools;
  3. // Exit if accessed directly.
  4. if ( ! defined( 'ABSPATH' ) ) {
  5. exit;
  6. }
  7. class SystemStatus {
  8. /**
  9. * Get an aggregated list of all system info.
  10. *
  11. * @since 4.0.0
  12. *
  13. * @return array An array of system information.
  14. */
  15. public static function getSystemStatusInfo() {
  16. return [
  17. 'wordPress' => self::getWordPressInfo(),
  18. 'constants' => self::getConstants(),
  19. 'serverInfo' => self::getServerInfo(),
  20. 'muPlugins' => self::mustUsePlugins(),
  21. 'activeTheme' => self::activeTheme(),
  22. 'activePlugins' => self::activePlugins(),
  23. 'inactivePlugins' => self::inactivePlugins()
  24. ];
  25. }
  26. /**
  27. * Get an array of system info from WordPress.
  28. *
  29. * @since 4.0.0
  30. *
  31. * @return array An array of system info.
  32. */
  33. public static function getWordPressInfo() {
  34. $uploadsDir = wp_upload_dir();
  35. $version = get_bloginfo( 'version' );
  36. $updates = get_site_transient( 'update_core' );
  37. $updateVersion = ! empty( $updates->updates[0]->version ) ? $updates->updates[0]->version : null;
  38. if ( version_compare( $version, $updateVersion, '<' ) ) {
  39. $version .= ' (' . __( 'Latest version:', 'all-in-one-seo-pack' ) . ' ' . $updateVersion . ')';
  40. }
  41. return [
  42. 'label' => 'WordPress',
  43. 'results' => [
  44. [
  45. 'header' => __( 'Version', 'all-in-one-seo-pack' ),
  46. 'value' => $version
  47. ],
  48. [
  49. 'header' => __( 'Site Title', 'all-in-one-seo-pack' ),
  50. 'value' => get_bloginfo( 'name' )
  51. ],
  52. [
  53. 'header' => __( 'Site Language', 'all-in-one-seo-pack' ),
  54. 'value' => defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US'
  55. ],
  56. [
  57. 'header' => __( 'User Language', 'all-in-one-seo-pack' ),
  58. 'value' => get_user_locale( get_current_user_id() )
  59. ],
  60. [
  61. 'header' => __( 'Timezone', 'all-in-one-seo-pack' ),
  62. 'value' => aioseo()->helpers->getTimeZoneOffset()
  63. ],
  64. [
  65. 'header' => __( 'Home URL', 'all-in-one-seo-pack' ),
  66. 'value' => home_url()
  67. ],
  68. [
  69. 'header' => __( 'Site URL', 'all-in-one-seo-pack' ),
  70. 'value' => site_url()
  71. ],
  72. [
  73. 'header' => __( 'Permalink Structure', 'all-in-one-seo-pack' ),
  74. 'value' => get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : __( 'Default', 'all-in-one-seo-pack' )
  75. ],
  76. [
  77. 'header' => __( 'Multisite', 'all-in-one-seo-pack' ),
  78. 'value' => is_multisite() ? __( 'Yes', 'all-in-one-seo-pack' ) : __( 'No', 'all-in-one-seo-pack' )
  79. ],
  80. [
  81. 'header' => 'HTTPS',
  82. 'value' => is_ssl() ? __( 'Yes', 'all-in-one-seo-pack' ) : __( 'No', 'all-in-one-seo-pack' )
  83. ],
  84. [
  85. 'header' => __( 'User Count', 'all-in-one-seo-pack' ),
  86. 'value' => count_users()['total_users']
  87. ],
  88. [
  89. 'header' => __( 'Front Page Info', 'all-in-one-seo-pack' ),
  90. 'value' => 'page' === get_option( 'show_on_front' ) ? get_option( 'show_on_front' ) . ' [ID: ' . get_option( 'page_on_front' ) . ']' : get_option( 'show_on_front' )
  91. ],
  92. [
  93. 'header' => __( 'Search Engine Visibility', 'all-in-one-seo-pack' ),
  94. 'value' => get_option( 'blog_public' ) ? __( 'Visible', 'all-in-one-seo-pack' ) : __( 'Hidden', 'all-in-one-seo-pack' )
  95. ],
  96. [
  97. 'header' => __( 'Upload Directory Info', 'all-in-one-seo-pack' ),
  98. 'value' =>
  99. __( 'Path:', 'all-in-one-seo-pack' ) . ' ' . $uploadsDir['path'] . ', ' .
  100. __( 'Url:', 'all-in-one-seo-pack' ) . ' ' . $uploadsDir['url'] . ', ' .
  101. __( 'Base Directory:', 'all-in-one-seo-pack' ) . ' ' . $uploadsDir['basedir'] . ', ' .
  102. __( 'Base URL:', 'all-in-one-seo-pack' ) . ' ' . $uploadsDir['baseurl']
  103. ]
  104. ]
  105. ];
  106. }
  107. /**
  108. * Get an array of system info from WordPress constants.
  109. *
  110. * @since 4.0.0
  111. *
  112. * @return array An array of system info.
  113. */
  114. public static function getConstants() {
  115. return [
  116. 'label' => __( 'Constants', 'all-in-one-seo-pack' ),
  117. 'results' => [
  118. [
  119. 'header' => 'ABSPATH',
  120. 'value' => ABSPATH
  121. ],
  122. [
  123. 'header' => 'WP_CONTENT_DIR',
  124. 'value' => defined( 'WP_CONTENT_DIR' ) ? ( WP_CONTENT_DIR ? WP_CONTENT_DIR : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  125. ],
  126. [
  127. 'header' => 'WP_CONTENT_URL',
  128. 'value' => defined( 'WP_CONTENT_URL' ) ? ( WP_CONTENT_URL ? WP_CONTENT_URL : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  129. ],
  130. [
  131. 'header' => 'UPLOADS',
  132. 'value' => defined( 'UPLOADS' ) ? ( UPLOADS ? UPLOADS : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  133. ],
  134. [
  135. 'header' => 'WP_DEBUG',
  136. 'value' => defined( 'WP_DEBUG' ) ? ( WP_DEBUG ? WP_DEBUG : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  137. ],
  138. [
  139. 'header' => 'WP_DEBUG_LOG',
  140. 'value' => defined( 'WP_DEBUG_LOG' ) ? ( WP_DEBUG_LOG ? WP_DEBUG_LOG : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  141. ],
  142. [
  143. 'header' => 'WP_DEBUG_DISPLAY',
  144. 'value' => defined( 'WP_DEBUG_DISPLAY' ) ? ( WP_DEBUG_DISPLAY ? WP_DEBUG_DISPLAY : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  145. ],
  146. [
  147. 'header' => 'WPS_DEBUG',
  148. 'value' => defined( 'WPS_DEBUG' ) ? ( WPS_DEBUG ? WPS_DEBUG : __( 'Disabled', 'all-in-one-seo-pack' ) ) : __( 'Not set', 'all-in-one-seo-pack' )
  149. ]
  150. ]
  151. ];
  152. }
  153. /**
  154. * Get an array of system info from the server.
  155. *
  156. * @since 4.0.0
  157. *
  158. * @return array An array of system info.
  159. */
  160. public static function getServerInfo() {
  161. $sqlMode = null;
  162. $mysqlInfo = aioseo()->db->db->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
  163. if ( is_array( $mysqlInfo ) ) {
  164. $sqlMode = $mysqlInfo[0]->Value;
  165. }
  166. return [
  167. 'label' => __( 'Server Info', 'all-in-one-seo-pack' ),
  168. 'results' => [
  169. [
  170. 'header' => __( 'Operating System', 'all-in-one-seo-pack' ),
  171. 'value' => PHP_OS
  172. ],
  173. [
  174. 'header' => __( 'Web Server', 'all-in-one-seo-pack' ),
  175. 'value' => ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : __( 'unknown', 'all-in-one-seo-pack' )
  176. ],
  177. [
  178. 'header' => __( 'Memory Usage', 'all-in-one-seo-pack' ),
  179. 'value' => function_exists( 'memory_get_usage' ) ? round( memory_get_usage() / 1024 / 1024, 2 ) . 'M' : __( 'N/A', 'all-in-one-seo-pack' )
  180. ],
  181. [
  182. 'header' => __( 'MySQL Version', 'all-in-one-seo-pack' ),
  183. 'value' => aioseo()->db->db->db_version()
  184. ],
  185. [
  186. 'header' => __( 'MySQL SQL Mode', 'all-in-one-seo-pack' ),
  187. 'value' => empty( $sqlMode ) ? __( 'Not Set', 'all-in-one-seo-pack' ) : $sqlMode
  188. ],
  189. [
  190. 'header' => __( 'PHP Version', 'all-in-one-seo-pack' ),
  191. 'value' => PHP_VERSION
  192. ],
  193. [
  194. 'header' => __( 'PHP Memory Limit', 'all-in-one-seo-pack' ),
  195. 'value' => ini_get( 'memory_limit' )
  196. ],
  197. [
  198. 'header' => __( 'PHP Max Upload Size', 'all-in-one-seo-pack' ),
  199. 'value' => ini_get( 'upload_max_filesize' )
  200. ],
  201. [
  202. 'header' => __( 'PHP Max Post Size', 'all-in-one-seo-pack' ),
  203. 'value' => ini_get( 'post_max_size' )
  204. ],
  205. [
  206. 'header' => __( 'PHP Max Script Execution Time', 'all-in-one-seo-pack' ),
  207. 'value' => ini_get( 'max_execution_time' )
  208. ],
  209. [
  210. 'header' => __( 'PHP Exif Support', 'all-in-one-seo-pack' ),
  211. 'value' => is_callable( 'exif_read_data' ) ? __( 'Yes', 'all-in-one-seo-pack' ) : __( 'No', 'all-in-one-seo-pack' )
  212. ],
  213. [
  214. 'header' => __( 'PHP IPTC Support', 'all-in-one-seo-pack' ),
  215. 'value' => is_callable( 'iptcparse' ) ? __( 'Yes', 'all-in-one-seo-pack' ) : __( 'No', 'all-in-one-seo-pack' )
  216. ],
  217. [
  218. 'header' => __( 'PHP XML Support', 'all-in-one-seo-pack' ),
  219. 'value' => is_callable( 'xml_parser_create' ) ? __( 'Yes', 'all-in-one-seo-pack' ) : __( 'No', 'all-in-one-seo-pack' )
  220. ]
  221. ]
  222. ];
  223. }
  224. /**
  225. * Get an array of system info from the active theme.
  226. *
  227. * @since 4.0.0
  228. *
  229. * @return array An array of system info.
  230. */
  231. public static function activeTheme() {
  232. $themeData = wp_get_theme();
  233. return [
  234. 'label' => __( 'Active Theme', 'all-in-one-seo-pack' ),
  235. 'results' => [
  236. [
  237. 'header' => $themeData->name,
  238. 'value' => $themeData->Version
  239. ]
  240. ]
  241. ];
  242. }
  243. /**
  244. * Get an array of system info from must-use plugins.
  245. *
  246. * @since 4.0.0
  247. *
  248. * @return array An array of system info.
  249. */
  250. public static function mustUsePlugins() {
  251. $plugins = [];
  252. $muPlugins = get_mu_plugins();
  253. if ( ! empty( $muPlugins ) ) {
  254. foreach ( $muPlugins as $pluginData ) {
  255. $plugins[] = [
  256. 'header' => $pluginData['Name'],
  257. 'value' => $pluginData['Version']
  258. ];
  259. }
  260. }
  261. return [
  262. 'label' => __( 'Must-Use Plugins', 'all-in-one-seo-pack' ),
  263. 'results' => $plugins
  264. ];
  265. }
  266. /**
  267. * Get an array of system info from active plugins.
  268. *
  269. * @since 4.0.0
  270. *
  271. * @return array An array of system info.
  272. */
  273. public static function activePlugins() {
  274. $plugins = [];
  275. $allPlugins = get_plugins();
  276. $activePlugins = get_option( 'active_plugins', [] );
  277. $updates = get_plugin_updates();
  278. if ( ! empty( $allPlugins ) ) {
  279. foreach ( $allPlugins as $pluginPath => $pluginData ) {
  280. if ( ! in_array( $pluginPath, $activePlugins, true ) ) {
  281. continue;
  282. }
  283. $update = ( array_key_exists( $pluginPath, $updates ) ) ? ' (' . __( 'needs update', 'all-in-one-seo-pack' ) . ' - ' . $updates[ $pluginPath ]->update->new_version . ')' : '';
  284. $plugins[] = [
  285. 'header' => $pluginData['Name'],
  286. 'value' => $pluginData['Version'] . $update
  287. ];
  288. }
  289. }
  290. return [
  291. 'label' => __( 'Active Plugins', 'all-in-one-seo-pack' ),
  292. 'results' => $plugins
  293. ];
  294. }
  295. /**
  296. * Get an array of system info from inactive plugins.
  297. *
  298. * @since 4.0.0
  299. *
  300. * @return array An array of system info.
  301. */
  302. public static function inactivePlugins() {
  303. $plugins = [];
  304. $allPlugins = get_plugins();
  305. $activePlugins = get_option( 'active_plugins', [] );
  306. $updates = get_plugin_updates();
  307. if ( ! empty( $allPlugins ) ) {
  308. foreach ( $allPlugins as $pluginPath => $pluginData ) {
  309. if ( in_array( $pluginPath, $activePlugins, true ) ) {
  310. continue;
  311. }
  312. $update = ( array_key_exists( $pluginPath, $updates ) ) ? ' (' . __( 'needs update', 'all-in-one-seo-pack' ) . ' - ' . $updates[ $pluginPath ]->update->new_version . ')' : '';
  313. $plugins[] = [
  314. 'header' => $pluginData['Name'],
  315. 'value' => $pluginData['Version'] . $update
  316. ];
  317. }
  318. }
  319. return [
  320. 'label' => __( 'Inactive Plugins', 'all-in-one-seo-pack' ),
  321. 'results' => $plugins
  322. ];
  323. }
  324. }