/wp-content/plugins/elementor/modules/system-info/reporters/server.php

https://gitlab.com/ebrjose/comcebu · PHP · 362 lines · 144 code · 40 blank · 178 comment · 11 complexity · 4ec1bb0358c2499de91ad00143fcb477 MD5 · raw file

  1. <?php
  2. namespace Elementor\Modules\System_Info\Reporters;
  3. use Elementor\Api;
  4. if ( ! defined( 'ABSPATH' ) ) {
  5. exit; // Exit if accessed directly.
  6. }
  7. /**
  8. * Elementor server environment report.
  9. *
  10. * Elementor system report handler class responsible for generating a report for
  11. * the server environment.
  12. *
  13. * @since 1.0.0
  14. */
  15. class Server extends Base {
  16. /**
  17. * Get server environment reporter title.
  18. *
  19. * Retrieve server environment reporter title.
  20. *
  21. * @since 1.0.0
  22. * @access public
  23. *
  24. * @return string Reporter title.
  25. */
  26. public function get_title() {
  27. return 'Server Environment';
  28. }
  29. /**
  30. * Get server environment report fields.
  31. *
  32. * Retrieve the required fields for the server environment report.
  33. *
  34. * @since 1.0.0
  35. * @access public
  36. *
  37. * @return array Required report fields with field ID and field label.
  38. */
  39. public function get_fields() {
  40. return [
  41. 'os' => 'Operating System',
  42. 'software' => 'Software',
  43. 'mysql_version' => 'MySQL version',
  44. 'php_version' => 'PHP Version',
  45. 'php_max_input_vars' => 'PHP Max Input Vars',
  46. 'php_max_post_size' => 'PHP Max Post Size',
  47. 'gd_installed' => 'GD Installed',
  48. 'zip_installed' => 'ZIP Installed',
  49. 'write_permissions' => 'Write Permissions',
  50. 'elementor_library' => 'Elementor Library',
  51. ];
  52. }
  53. /**
  54. * Get server operating system.
  55. *
  56. * Retrieve the server operating system.
  57. *
  58. * @since 1.0.0
  59. * @access public
  60. *
  61. * @return array {
  62. * Report data.
  63. *
  64. * @type string $value Server operating system.
  65. * }
  66. */
  67. public function get_os() {
  68. return [
  69. 'value' => PHP_OS,
  70. ];
  71. }
  72. /**
  73. * Get server software.
  74. *
  75. * Retrieve the server software.
  76. *
  77. * @since 1.0.0
  78. * @access public
  79. *
  80. * @return array {
  81. * Report data.
  82. *
  83. * @type string $value Server software.
  84. * }
  85. */
  86. public function get_software() {
  87. return [
  88. 'value' => $_SERVER['SERVER_SOFTWARE'],
  89. ];
  90. }
  91. /**
  92. * Get PHP version.
  93. *
  94. * Retrieve the PHP version.
  95. *
  96. * @since 1.0.0
  97. * @access public
  98. *
  99. * @return array {
  100. * Report data.
  101. *
  102. * @type string $value PHP version.
  103. * @type string $recommendation Minimum PHP version recommendation.
  104. * @type bool $warning Whether to display a warning.
  105. * }
  106. */
  107. public function get_php_version() {
  108. $result = [
  109. 'value' => PHP_VERSION,
  110. ];
  111. if ( version_compare( $result['value'], '5.4', '<' ) ) {
  112. $result['recommendation'] = _x( 'We recommend to use php 5.4 or higher', 'System Info', 'elementor' );
  113. $result['warning'] = true;
  114. }
  115. return $result;
  116. }
  117. /**
  118. * Get PHP `max_input_vars`.
  119. *
  120. * Retrieve the value of `max_input_vars` from `php.ini` configuration file.
  121. *
  122. * @since 1.0.0
  123. * @access public
  124. *
  125. * @return array {
  126. * Report data.
  127. *
  128. * @type string $value PHP `max_input_vars`.
  129. * }
  130. */
  131. public function get_php_max_input_vars() {
  132. return [
  133. 'value' => ini_get( 'max_input_vars' ),
  134. ];
  135. }
  136. /**
  137. * Get PHP `post_max_size`.
  138. *
  139. * Retrieve the value of `post_max_size` from `php.ini` configuration file.
  140. *
  141. * @since 1.0.0
  142. * @access public
  143. *
  144. * @return array {
  145. * Report data.
  146. *
  147. * @type string $value PHP `post_max_size`.
  148. * }
  149. */
  150. public function get_php_max_post_size() {
  151. return [
  152. 'value' => ini_get( 'post_max_size' ),
  153. ];
  154. }
  155. /**
  156. * Get GD installed.
  157. *
  158. * Whether the GD extension is installed.
  159. *
  160. * @since 1.0.0
  161. * @access public
  162. *
  163. * @return array {
  164. * Report data.
  165. *
  166. * @type string $value Yes if the GD extension is installed, No otherwise.
  167. * @type bool $warning Whether to display a warning. True if the GD extension is installed, False otherwise.
  168. * }
  169. */
  170. public function get_gd_installed() {
  171. $gd_installed = extension_loaded( 'gd' );
  172. return [
  173. 'value' => $gd_installed ? 'Yes' : 'No',
  174. 'warning' => ! $gd_installed,
  175. ];
  176. }
  177. /**
  178. * Get ZIP installed.
  179. *
  180. * Whether the ZIP extension is installed.
  181. *
  182. * @since 2.1.0
  183. * @access public
  184. *
  185. * @return array {
  186. * Report data.
  187. *
  188. * @type string $value Yes if the ZIP extension is installed, No otherwise.
  189. * @type bool $warning Whether to display a warning. True if the ZIP extension is installed, False otherwise.
  190. * }
  191. */
  192. public function get_zip_installed() {
  193. $zip_installed = extension_loaded( 'zip' );
  194. return [
  195. 'value' => $zip_installed ? 'Yes' : 'No',
  196. 'warning' => ! $zip_installed,
  197. ];
  198. }
  199. /**
  200. * Get MySQL version.
  201. *
  202. * Retrieve the MySQL version.
  203. *
  204. * @since 1.0.0
  205. * @access public
  206. *
  207. * @return array {
  208. * Report data.
  209. *
  210. * @type string $value MySQL version.
  211. * }
  212. */
  213. public function get_mysql_version() {
  214. global $wpdb;
  215. $db_server_version = $wpdb->get_results( "SHOW VARIABLES WHERE `Variable_name` IN ( 'version_comment', 'innodb_version' )", OBJECT_K );
  216. return [
  217. 'value' => $db_server_version['version_comment']->Value . ' v' . $db_server_version['innodb_version']->Value,
  218. ];
  219. }
  220. /**
  221. * Get write permissions.
  222. *
  223. * Check whether the required folders has writing permissions.
  224. *
  225. * @since 1.9.0
  226. * @access public
  227. *
  228. * @return array {
  229. * Report data.
  230. *
  231. * @type string $value Writing permissions status.
  232. * @type bool $warning Whether to display a warning. True if some required
  233. * folders don't have writing permissions, False otherwise.
  234. * }
  235. */
  236. public function get_write_permissions() {
  237. $paths_to_check = [
  238. ABSPATH => 'WordPress root directory',
  239. ];
  240. $write_problems = [];
  241. $wp_upload_dir = wp_upload_dir();
  242. if ( $wp_upload_dir['error'] ) {
  243. $write_problems[] = 'WordPress root uploads directory';
  244. }
  245. $elementor_uploads_path = $wp_upload_dir['basedir'] . '/elementor';
  246. if ( is_dir( $elementor_uploads_path ) ) {
  247. $paths_to_check[ $elementor_uploads_path ] = 'Elementor uploads directory';
  248. }
  249. $htaccess_file = ABSPATH . '/.htaccess';
  250. if ( file_exists( $htaccess_file ) ) {
  251. $paths_to_check[ $htaccess_file ] = '.htaccess file';
  252. }
  253. foreach ( $paths_to_check as $dir => $description ) {
  254. if ( ! is_writable( $dir ) ) {
  255. $write_problems[] = $description;
  256. }
  257. }
  258. if ( $write_problems ) {
  259. $value = 'There are some writing permissions issues with the following directories/files:' . "\n\t\t - ";
  260. $value .= implode( "\n\t\t - ", $write_problems );
  261. } else {
  262. $value = 'All right';
  263. }
  264. return [
  265. 'value' => $value,
  266. 'warning' => ! ! $write_problems,
  267. ];
  268. }
  269. /**
  270. * Check for elementor library connectivity.
  271. *
  272. * Check whether the remote elementor library is reachable.
  273. *
  274. * @since 1.0.0
  275. * @access public
  276. *
  277. * @return array {
  278. * Report data.
  279. *
  280. * @type string $value The status of elementor library connectivity.
  281. * @type bool $warning Whether to display a warning. True if elementor
  282. * * library is not reachable, False otherwise.
  283. * }
  284. */
  285. public function get_elementor_library() {
  286. $response = wp_remote_get(
  287. Api::$api_info_url, [
  288. 'timeout' => 5,
  289. 'body' => [
  290. // Which API version is used
  291. 'api_version' => ELEMENTOR_VERSION,
  292. // Which language to return
  293. 'site_lang' => get_bloginfo( 'language' ),
  294. ],
  295. ]
  296. );
  297. if ( is_wp_error( $response ) ) {
  298. return [
  299. 'value' => 'Not connected (' . $response->get_error_message() . ')',
  300. 'warning' => true,
  301. ];
  302. }
  303. $http_response_code = wp_remote_retrieve_response_code( $response );
  304. if ( 200 !== (int) $http_response_code ) {
  305. $error_msg = 'HTTP Error (' . $http_response_code . ')';
  306. return [
  307. 'value' => 'Not connected (' . $error_msg . ')',
  308. 'warning' => true,
  309. ];
  310. }
  311. $info_data = json_decode( wp_remote_retrieve_body( $response ), true );
  312. if ( empty( $info_data ) ) {
  313. return [
  314. 'value' => 'Not connected (Returns invalid JSON)',
  315. 'warning' => true,
  316. ];
  317. }
  318. return [
  319. 'value' => 'Connected',
  320. ];
  321. }
  322. }