28 $this->webserver =
'unknown';
45 if ($this->rewriteTestPassed ===
false) {
46 if ($this->webserver ==
'apache' || $this->webserver ==
'unknown') {
62 if (empty($_SERVER[
'SERVER_SOFTWARE'])) {
66 $serverString = strtolower($_SERVER[
'SERVER_SOFTWARE']);
67 $possibleServers = [
'apache',
'nginx',
'lighttpd',
'iis'];
68 foreach ($possibleServers as
$server) {
69 if (
elgg_strpos($serverString, $server) !==
false) {
87 if (!is_array($elements) || !isset($elements[
'path'])) {
91 $subdir =
trim(dirname($elements[
'path']),
'/');
107 $this->serverSupportsRemoteRead = ($this->fetchUrl(
$url) === Request::REWRITE_TEST_OUTPUT);
127 private function fetchUrl(
$url) {
130 if (ini_get(
'allow_url_fopen')) {
131 $ctx = stream_context_create([
133 'follow_location' => 0,
140 if (!
$response && function_exists(
'curl_init')) {
142 curl_setopt($ch, CURLOPT_URL,
$url);
143 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
144 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
145 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
162 $file = $root->getFile(
'.htaccess');
164 if ($file->exists()) {
166 $data = $file->getContents();
169 $this->htaccessIssue =
'read_permission';
174 $this->htaccessIssue =
'non_elgg_htaccess';
179 if (
elgg_strpos(
$data,
'RewriteRule ^rewrite.php$ install.php') ===
false) {
180 $this->htaccessIssue =
'old_elgg_htaccess';
187 if (!is_writable($root->getPath())) {
188 $this->htaccessIssue =
'write_permission';
195 $this->htaccessIssue =
'cannot_copy';
203 if (!empty($subdir)) {
205 $contents = preg_replace(
"/#RewriteBase \/(\r?\n)/",
"RewriteBase $subdir\$1",
$contents);
223 if ($this->rewriteTestPassed) {
225 'severity' =>
'success',
226 'message' =>
_elgg_services()->translator->translate(
'install:check:rewrite:success'),
230 if ($this->serverSupportsRemoteRead ===
false) {
231 $msg =
_elgg_services()->translator->translate(
'install:warning:rewrite:unknown', [
$url]);
232 $msg .=
elgg_view(
'install/js_rewrite_check', [
'url' =>
$url]);
235 'severity' =>
'warning',
240 if ($this->webserver ===
'apache') {
241 $msg =
_elgg_services()->translator->translate(
'install:error:rewrite:apache');
242 $msg .= PHP_EOL . PHP_EOL;
243 if (!isset($this->htaccessIssue)) {
244 $msg .=
_elgg_services()->translator->translate(
'install:error:rewrite:allowoverride');
245 $msg .=
elgg_view(
'install/js_rewrite_check', [
'url' =>
$url]);
248 'severity' =>
'warning',
253 $msg .=
_elgg_services()->translator->translate(
"install:error:rewrite:htaccess:{$this->htaccessIssue}");
255 'severity' =>
'warning',
260 if ($this->webserver !==
'unknown') {
261 $msg =
_elgg_services()->translator->translate(
"install:error:rewrite:{$this->webserver}");
262 $msg .= PHP_EOL . PHP_EOL;
263 $msg .=
_elgg_services()->translator->translate(
'install:error:rewrite:altserver');
265 'severity' =>
'warning',
271 'severity' =>
'warning',
272 'message' =>
_elgg_services()->translator->translate(
'install:error:rewrite:unknown'),
static elgg()
Get the Elgg codebase path with "/".
runRewriteTest($url)
Hit the rewrite test URL to determine if the rewrite rules are working.
elgg parse_url
Parse a URL into its parts.
guessSubdirectory($url)
Guess if url contains subdirectory or not.
__construct()
Set the webserver as unknown.
static projectRoot()
Get the root composer install directory.
Test if URL rewriting is 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.
returnStatus($url)
Create the status array required by the ElggInstaller.
elgg_strpos()
Wrapper function for mb_strpos().
run($url, $path=null)
Run the rewrite test and return a status array.
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.
createHtaccess($url)
Create Elgg's .htaccess file or confirm that it exists.
if(!empty($title)&&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents