| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) die('You do not have sufficient permissions to access this file.'); |
| 3 |
// phpcs:disable WordPress.WP.AlternativeFunctions |
| 4 |
class Pda_Function { |
| 5 |
|
| 6 |
function get_htaccess_file_path() { |
| 7 |
|
| 8 |
//global $wp_rewrite; |
| 9 |
$home_path = get_home_path(); |
| 10 |
$htaccess_file = $home_path . '.htaccess'; |
| 11 |
|
| 12 |
return $htaccess_file; |
| 13 |
} |
| 14 |
|
| 15 |
function htaccess_writable() { |
| 16 |
$htaccess_file = $this->get_htaccess_file_path(); |
| 17 |
|
| 18 |
if ( ! file_exists( $htaccess_file ) ) { |
| 19 |
return '.htaccess file not existed'; |
| 20 |
} |
| 21 |
|
| 22 |
if ( is_writable( $htaccess_file ) ) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
@chmod( $htaccess_file, 0666 ); |
| 27 |
|
| 28 |
if ( ! is_writable( $htaccess_file ) ) { |
| 29 |
return 'Please ask host manager to grant write permission for .htaccess file.'; |
| 30 |
} |
| 31 |
|
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
function get_htaccess_content() { |
| 36 |
|
| 37 |
//global $wp_rewrite; |
| 38 |
|
| 39 |
$htaccess_file = $this->get_htaccess_file_path(); |
| 40 |
|
| 41 |
if (!file_exists($htaccess_file)) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
if (!is_writable($htaccess_file)) { |
| 46 |
@chmod($htaccess_file, 0666); |
| 47 |
} |
| 48 |
|
| 49 |
if (!$f = fopen($htaccess_file, 'r')) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
return file_get_contents($htaccess_file); |
| 54 |
} |
| 55 |
|
| 56 |
function sanitized_rule($rule) { |
| 57 |
$rule = trim($rule); |
| 58 |
$rule = str_replace('\\\\', '\\', $rule); |
| 59 |
$rule = str_replace('\"', '"', $rule); |
| 60 |
|
| 61 |
return $rule; |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|