21 $this->webserver =
'unknown';
38 if ($this->rewriteTestPassed ===
false) {
39 if ($this->webserver ==
'apache' || $this->webserver ==
'unknown') {
55 if (empty($_SERVER[
'SERVER_SOFTWARE'])) {
59 $serverString = strtolower($_SERVER[
'SERVER_SOFTWARE']);
60 $possibleServers = [
'apache',
'nginx',
'lighttpd',
'iis'];
61 foreach ($possibleServers as
$server) {
62 if (
elgg_strpos($serverString, $server) !==
false) {
79 if (!is_array($elements) || !isset($elements[
'path'])) {
83 $subdir =
trim(dirname($elements[
'path']),
'/');
99 $this->serverSupportsRemoteRead = ($this->fetchUrl(
$url) === Request::REWRITE_TEST_OUTPUT);
119 private function fetchUrl(
$url) {
122 if (ini_get(
'allow_url_fopen')) {
123 $ctx = stream_context_create([
125 'follow_location' => 0,
129 $response = @file_get_contents(
$url,
false, $ctx);
132 if (!$response && function_exists(
'curl_init')) {
134 curl_setopt($ch, CURLOPT_URL,
$url);
135 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
136 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
137 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
138 $response = curl_exec($ch);
142 return (
string) $response;
153 $root = ElggDirectory\Local::projectRoot();
154 $file = $root->getFile(
".htaccess");
156 if ($file->exists()) {
158 $data = $file->getContents();
161 $this->htaccessIssue =
'read_permission';
166 $this->htaccessIssue =
'non_elgg_htaccess';
171 if (
elgg_strpos(
$data,
'RewriteRule ^rewrite.php$ install.php') ===
false) {
172 $this->htaccessIssue =
'old_elgg_htaccess';
178 if (!is_writable($root->getPath())) {
179 $this->htaccessIssue =
'write_permission';
186 $this->htaccessIssue =
'cannot_copy';
195 $contents = preg_replace(
"/#RewriteBase \/(\r?\n)/",
"RewriteBase $subdir\$1",
$contents);
213 if ($this->rewriteTestPassed) {
215 'severity' =>
'success',
216 'message' =>
_elgg_services()->translator->translate(
'install:check:rewrite:success'),
220 if ($this->serverSupportsRemoteRead ==
false) {
221 $msg =
_elgg_services()->translator->translate(
'install:warning:rewrite:unknown', [
$url]);
222 $msg .=
elgg_view(
'install/js_rewrite_check', [
'url' =>
$url]);
225 'severity' =>
'warning',
230 if ($this->webserver ==
'apache') {
231 $serverString =
_elgg_services()->translator->translate(
'install:error:rewrite:apache');
232 $msg =
"$serverString\n\n";
233 if (!isset($this->htaccessIssue)) {
234 $msg .=
_elgg_services()->translator->translate(
'install:error:rewrite:allowoverride');
235 $msg .=
elgg_view(
'install/js_rewrite_check', [
'url' =>
$url]);
238 'severity' =>
'warning',
242 $msg .=
_elgg_services()->translator->translate(
"install:error:rewrite:htaccess:{$this->htaccessIssue}");
244 'severity' =>
'warning',
249 if ($this->webserver !=
'unknown') {
250 $serverString =
_elgg_services()->translator->translate(
"install:error:rewrite:{$this->webserver}");
251 $msg =
"$serverString\n\n";
252 $msg .=
_elgg_services()->translator->translate(
"install:error:rewrite:altserver");
254 'severity' =>
'warning',
260 'severity' =>
'warning',
261 'message' =>
_elgg_services()->translator->translate(
'install:error:rewrite:unknown'),
runLocalhostAccessTest()
Check whether the site homepage can be fetched via curl.
$serverSupportsRemoteRead
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
elgg parse_url
Parse a URL into its parts.
run($url, $path=null)
Run the rewrite test and return a status array.
createHtaccess($url)
Create Elgg's .htaccess file or confirm that it exists.
elgg_strpos()
Wrapper function for mb_strpos().
returnStatus($url)
Create the status array required by the ElggInstaller.
guessSubdirectory($url)
Guess if url contains subdirectory or not.
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
__construct()
Set the webserver as unknown.
_elgg_services()
Get the global service provider.
static guessWebServer()
Guess the web server from $_SERVER['SERVER_SOFTWARE'].
runRewriteTest($url)
Hit the rewrite test URL to determine if the rewrite rules are working.
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
if(!empty($title)&&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents