| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\ServerInformation; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Classes\ServerInfo; |
| 6 |
use WPAdminify\Inc\Utils; |
| 7 |
|
| 8 |
// no direct access allowed |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* WPAdminify |
| 15 |
* |
| 16 |
* @package Server Information |
| 17 |
* |
| 18 |
* @author WP Adminify <support@wpadminify.com> |
| 19 |
*/ |
| 20 |
|
| 21 |
class ServerInfo_Htaccess_Details { |
| 22 |
|
| 23 |
|
| 24 |
public function __construct() { |
| 25 |
$this->init(); |
| 26 |
} |
| 27 |
|
| 28 |
public function init() { |
| 29 |
$server_info = new ServerInfo(); |
| 30 |
|
| 31 |
$help = '<span class="dashicons dashicons-editor-help"></span>'; |
| 32 |
$enabled = '<span class="adminify-compability enable"><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Enabled', 'adminify' ) . '</span>'; |
| 33 |
$disabled = '<span class="adminify-compability disable"><span class="dashicons dashicons-no"></span> ' . esc_html__( 'Disabled', 'adminify' ) . '</span>'; |
| 34 |
$yes = '<span class="adminify-compability enable"><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Yes', 'adminify' ) . '</span>'; |
| 35 |
$no = '<span class="adminify-compability disable"><span class="dashicons dashicons-no"></span> ' . esc_html__( 'No', 'adminify' ) . '</span>'; |
| 36 |
$entered = '<span class="adminify-compability enable"><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Defined', 'adminify' ) . '</span>'; |
| 37 |
$not_entered = '<span class="adminify-compability disable"><span class="dashicons dashicons-no"></span> ' . esc_html__( 'Not defined', 'adminify' ) . '</span>'; |
| 38 |
$sec_key = '<span class="error"><span class="dashicons dashicons-warning"></span> ' . esc_html__( 'Please enter this security key in the wp-confiq.php file', 'adminify' ) . '!</span>'; |
| 39 |
?> |
| 40 |
<div class="wrap"> |
| 41 |
<h1> |
| 42 |
<?php echo Utils::admin_page_title( esc_html__( '.htaccess file', 'adminify' ) ); ?> |
| 43 |
</h1> |
| 44 |
</div> |
| 45 |
|
| 46 |
<p style="color: #ce2754; font-weight: bold"> |
| 47 |
<?php |
| 48 |
$name = '.htaccess'; |
| 49 |
printf( wp_kses_post( __( 'For security reasons you can only read the %1$s file! Please connect to your server and modify the file in a file editor.', 'adminify' ) ), esc_html( $name ) ); |
| 50 |
?> |
| 51 |
</p> |
| 52 |
|
| 53 |
<p> |
| 54 |
<?php esc_html_e( 'The .htaccess is a distributed configuration file, and is how Apache server handles configuration changes on a per-directory basis.', 'adminify' ); ?> |
| 55 |
<br> |
| 56 |
<a href="https://wordpress.org/support/article/htaccess/" target="_blank" rel="noopener"><?php esc_html_e( 'Learn more about the .htaccess file in WordPress.', 'adminify' ); ?></a> |
| 57 |
</p> |
| 58 |
|
| 59 |
<?php |
| 60 |
|
| 61 |
// Get the wp ".htaccess" file |
| 62 |
$file = $this->jltwp_adminify_htaccess_file(); |
| 63 |
|
| 64 |
// Get the wp ".htaccess" file content |
| 65 |
$file_content = $this->jltwp_adminify_htaccess_file_content( $file ); |
| 66 |
|
| 67 |
if ( $file ) { |
| 68 |
?> |
| 69 |
<p> |
| 70 |
<?php echo esc_html__( '.htaccess file was found at:', 'adminify' ) . ' <strong>' . esc_html( $file ) . '</strong>'; ?> |
| 71 |
<br> |
| 72 |
</p> |
| 73 |
<?php } ?> |
| 74 |
|
| 75 |
<textarea id="htaccess_log_area" class="adminify-info-text-area" readonly><?php echo esc_html( $file_content ); ?></textarea> |
| 76 |
|
| 77 |
<?php |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
/** |
| 82 |
* htaccess file |
| 83 |
*/ |
| 84 |
public function jltwp_adminify_htaccess_file() { |
| 85 |
|
| 86 |
// Call wp file system |
| 87 |
global $wp_filesystem; |
| 88 |
WP_Filesystem(); |
| 89 |
|
| 90 |
// Get the path of wp ".htaccess" file |
| 91 |
$file = get_home_path() . '.htaccess'; |
| 92 |
|
| 93 |
// Check if ".htaccess" file exist |
| 94 |
if ( |
| 95 |
$wp_filesystem->exists( $file ) |
| 96 |
) { |
| 97 |
return $file; |
| 98 |
} |
| 99 |
|
| 100 |
// File not exist |
| 101 |
return false; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* .htaccess file contents |
| 106 |
*/ |
| 107 |
|
| 108 |
public function jltwp_adminify_htaccess_file_content( $file ) { |
| 109 |
|
| 110 |
// Call wp file system |
| 111 |
global $wp_filesystem; |
| 112 |
WP_Filesystem(); |
| 113 |
|
| 114 |
// Show this notice, if no file exist |
| 115 |
$content = esc_html__( '.htaccess file not found!', 'adminify' ); |
| 116 |
|
| 117 |
// Check if ".htaccess" file exist |
| 118 |
if ( $wp_filesystem->exists( $file ) ) { |
| 119 |
$content = $wp_filesystem->get_contents( $file ); |
| 120 |
|
| 121 |
// Check if the file content is empty |
| 122 |
if ( $wp_filesystem->get_contents( $file ) == '' ) { |
| 123 |
$content = esc_html__( 'File content is empty.', 'adminify' ); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
return $content; |
| 128 |
} |
| 129 |
} |
| 130 |
|