Htaccess.php
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace AIOSEO\Plugin\Common\Tools;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Htaccess {
/**
* The path to the .htaccess file.
*
* @since 4.0.0
*
* @var string
*/
private $path = '';
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->path = ABSPATH . '.htaccess';
}
/**
* Get the contents of the .htaccess file.
*
* @since 4.0.0
*
* @return string The contents of the file.
*/
public function getContents() {
$wpfs = aioseo()->helpers->wpfs();
if ( ! @$wpfs->exists( $this->path ) ) {
return false;
}
$contents = @$wpfs->get_contents( $this->path );
return aioseo()->helpers->encodeOutputHtml( $contents );
}
/**
* Saves the contents of the .htaccess file.
*
* @since 4.0.0
*
* @param string $contents The contents to write.
* @return boolean True if the file was updated.
*/
public function saveContents( $contents ) {
$wpfs = aioseo()->helpers->wpfs();
$fileExists = @$wpfs->exists( $this->path );
if ( ! $fileExists || @$wpfs->is_writable( $this->path ) ) {
$success = @$wpfs->put_contents( $this->path, $contents );
if ( false === $success ) {
return false;
}
return true;
}
return false;
}
}