balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

server.php (7870B)


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