PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / htaccess-capability-tester / src / Testers / HtaccessEnabledTester.php

HtaccessEnabledTester.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.3, at vendor/rosell-dk/htaccess-capability-tester/src/Testers/HtaccessEnabledTester.php

109 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HtaccessCapabilityTester\Testers;
4
5 use \HtaccessCapabilityTester\HtaccessCapabilityTester;
6 use \HtaccessCapabilityTester\TestResult;
7
8 /**
9 * Class for testing if .htaccess files are processed
10 *
11 * @package HtaccessCapabilityTester
12 * @author Bjørn Rosell <[email protected]>
13 * @since Class available since 0.7
14 */
15 class HtaccessEnabledTester extends AbstractTester
16 {
17
18 /**
19 * Child classes must implement this method, which tells which subdir the
20 * test files are to be put.
21 *
22 * @return string A subdir for the test files
23 */
24 public function getSubDir()
25 {
26 return 'htaccess-enabled';
27 }
28
29 /**
30 * Register the test files using the "registerTestFile" method
31 *
32 * @return void
33 */
34 public function registerTestFiles()
35 {
36 // No test files for this test
37 }
38
39 /**
40 * Run the test.
41 *
42 * @param string $baseDir Directory on the server where the test files can be put
43 * @param string $baseUrl The base URL of the test files
44 *
45 * @return TestResult Returns a test result
46 */
47 public function run($baseDir, $baseUrl)
48 {
49 $this->prepareForRun($baseDir, $baseUrl);
50
51 /*
52 PS: We could implement this as a definition:
53
54
55 - [success, serverSignatureWorks, is-success]
56 - [success, contentDigestWorks, is-success]
57 - [failure, serverSignatureWorks, is-failure]
58 - [success, canCrash, is-success]
59 */
60
61
62 $status = null;
63 $info = '';
64 $hct = $this->getHtaccessCapabilityTester();
65
66 // If we can find anything that works, well the .htaccess must have been proccesed!
67 if ($hct->serverSignatureWorks() // Override: None, Status: Core, REQUIRES PHP
68 || $hct->contentDigestWorks() // Override: Options, Status: Core
69 || $hct->addTypeWorks() // Override: FileInfo, Status: Base, Module: mime
70 || $hct->directoryIndexWorks() // Override: Indexes, Status: Base, Module: mod_dir
71 || $hct->rewriteWorks() // Override: FileInfo, Status: Extension, Module: rewrite
72 || $hct->headerSetWorks() // Override: FileInfo, Status: Extension, Module: headers
73 ) {
74 $status = true;
75 } else {
76 // The serverSignatureWorks() test is special because if it comes out as a failure,
77 // we can be *almost* certain that the .htaccess has been completely disabled
78
79 $serverSignatureWorks = $hct->serverSignatureWorks();
80 if ($serverSignatureWorks === false) {
81 $status = false;
82 $info = 'ServerSignature directive does not work - and it is in core';
83 } else {
84 // Last bullet in the gun:
85 // Try an .htaccess with syntax errors in it.
86 // (we do this lastly because it may generate an entry in the error log)
87 $crashTestResult = $hct->crashTest('aoeu', 'htaccess-enabled-malformed-htaccess');
88 if (is_null($crashTestResult)) {
89 // Two scenarios:
90 // 1: All requests fails (without response code)
91 // 2: The crash test could not figure it out (ie if even innocent requests crashes)
92 $status = null;
93 $info = 'all requests fails (even innocent ones)';
94 } elseif ($crashTestResult === false) {
95 // It crashed, - which means .htaccess is processed!
96 $status = true;
97 $info = 'syntax error in an .htaccess causes crash';
98 } else {
99 // It did not crash. So the .htaccess is not processed, as syntax errors
100 // makes servers crash
101 $status = false;
102 $info = 'syntax error in an .htaccess does not cause crash';
103 }
104 }
105 }
106 return new TestResult($status, $info);
107 }
108 }
109