27 $this->webserver =
'unknown';
43 if ($this->rewriteTestPassed ===
false) {
44 if ($this->webserver ==
'apache' || $this->webserver ==
'unknown') {
60 if (empty($_SERVER[
'SERVER_SOFTWARE'])) {
64 $serverString = strtolower($_SERVER[
'SERVER_SOFTWARE']);
65 $possibleServers = [
'apache',
'nginx',
'lighttpd',
'iis'];
66 foreach ($possibleServers as $server) {
67 if (
elgg_strpos($serverString, $server) !==
false) {
84 $elements = parse_url($url);
85 if (!is_array($elements) || !isset($elements[
'path'])) {
89 $subdir =
trim(dirname($elements[
'path']),
'/');
105 $this->serverSupportsRemoteRead = ($this->fetchUrl($url) === Request::REWRITE_TEST_OUTPUT);
125 private function fetchUrl(
string $url):
string {
128 if (ini_get(
'allow_url_fopen')) {
129 $ctx = stream_context_create([
131 'follow_location' => 0,
135 $response = @file_get_contents($url,
false, $ctx);
138 if (!
$response && function_exists(
'curl_init')) {
140 curl_setopt($ch, CURLOPT_URL, $url);
141 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
142 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
143 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
161 if (file_exists($htaccess)) {
163 $data = file_get_contents($htaccess);
166 $this->htaccessIssue =
'read_permission';
171 $this->htaccessIssue =
'non_elgg_htaccess';
176 if (
elgg_strpos(
$data,
'RewriteRule ^rewrite.php$ install.php') ===
false) {
177 $this->htaccessIssue =
'old_elgg_htaccess';
185 $this->htaccessIssue =
'write_permission';
192 $this->htaccessIssue =
'cannot_copy';
200 if (!empty($subdir)) {
201 $contents = file_get_contents($htaccess);
202 $contents = preg_replace(
"/#RewriteBase \/(\r?\n)/",
"RewriteBase $subdir\$1",
$contents);
220 if ($this->rewriteTestPassed) {
222 'severity' =>
'success',
223 'message' =>
_elgg_services()->translator->translate(
'install:check:rewrite:success'),
227 if ($this->serverSupportsRemoteRead ===
false) {
228 $msg =
_elgg_services()->translator->translate(
'install:warning:rewrite:unknown', [$url]);
229 $msg .=
elgg_view(
'install/js_rewrite_check', [
'url' => $url]);
232 'severity' =>
'warning',
237 if ($this->webserver ===
'apache') {
238 $msg =
_elgg_services()->translator->translate(
'install:error:rewrite:apache');
239 $msg .= PHP_EOL . PHP_EOL;
240 if (!isset($this->htaccessIssue)) {
241 $msg .=
_elgg_services()->translator->translate(
'install:error:rewrite:allowoverride');
242 $msg .=
elgg_view(
'install/js_rewrite_check', [
'url' => $url]);
245 'severity' =>
'warning',
250 $msg .=
_elgg_services()->translator->translate(
"install:error:rewrite:htaccess:{$this->htaccessIssue}");
252 'severity' =>
'warning',
257 if ($this->webserver !==
'unknown') {
258 $msg =
_elgg_services()->translator->translate(
"install:error:rewrite:{$this->webserver}");
259 $msg .= PHP_EOL . PHP_EOL;
260 $msg .=
_elgg_services()->translator->translate(
'install:error:rewrite:altserver');
262 'severity' =>
'warning',
268 'severity' =>
'warning',
269 'message' =>
_elgg_services()->translator->translate(
'install:error:rewrite:unknown'),
static project()
Get the project root (where composer is installed) path with "/".
static elgg()
Get the Elgg codebase path with "/".
guessSubdirectory(string $url)
Guess if url contains subdirectory or not.
run(string $url)
Run the rewrite test and return a status array.
returnStatus(string $url)
Create the status array required by the ElggInstaller.
__construct()
Set the webserver as unknown.
Test if URL rewriting is working.
runRewriteTest(string $url)
Hit the rewrite test URL to determine if the rewrite rules are working.
if(!$entity instanceof\ElggUser) $data
bool $serverSupportsRemoteRead
runLocalhostAccessTest()
Check whether the site homepage can be fetched via curl.
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
createHtaccess(string $url)
Create Elgg's .htaccess file or confirm that it exists.
elgg_strpos()
Wrapper function for mb_strpos().
guessWebServer()
Guess the web server from $_SERVER['SERVER_SOFTWARE'].
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
_elgg_services()
Get the global service provider.
if(!empty($title)&&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents