22 $this->webserver =
'unknown';
39 if ($this->rewriteTestPassed == FALSE) {
40 if ($this->webserver ==
'apache' || $this->webserver ==
'unknown') {
56 $serverString = strtolower($_SERVER[
'SERVER_SOFTWARE']);
57 $possibleServers = array(
'apache',
'nginx',
'lighttpd',
'iis');
58 foreach ($possibleServers as $server) {
59 if (strpos($serverString, $server) !== FALSE) {
76 if (!$elements || !isset($elements[
'path'])) {
79 $subdir = trim(dirname($elements[
'path']),
'/');
106 return (
bool)$this->fetchUrl(
$url);
116 private function fetchUrl(
$url) {
119 if (ini_get(
'allow_url_fopen')) {
120 $ctx = stream_context_create(array(
122 'follow_location' => 0,
126 $response = @file_get_contents(
$url, null, $ctx);
129 if (!$response && function_exists(
'curl_init')) {
131 curl_setopt($ch, CURLOPT_URL,
$url);
132 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
133 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
134 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
135 $response = curl_exec($ch);
139 return (
string)$response;
150 $root = Directory\Local::root();
151 $file = $root->getFile(
".htaccess");
152 if (
$file->exists()) {
155 if (
$data === FALSE) {
157 $this->htaccessIssue =
'read_permission';
160 if (strpos(
$data,
'Elgg') === FALSE) {
161 $this->htaccessIssue =
'non_elgg_htaccess';
165 if (strpos(
$data,
'RewriteRule ^rewrite.php$ install.php') == FALSE) {
166 $this->htaccessIssue =
'old_elgg_htaccess';
173 if (!is_writable($root->getPath())) {
174 $this->htaccessIssue =
'write_permission';
179 $result =
copy(\
Elgg\Application::elggDir()->getPath(
"install/config/htaccess.dist"),
$file->getPath());
181 $this->htaccessIssue =
'cannot_copy';
190 $contents = preg_replace(
"/#RewriteBase \/(\r?\n)/",
"RewriteBase $subdir\$1",
$contents);
208 if ($this->rewriteTestPassed) {
210 'severity' =>
'pass',
211 'message' =>
_elgg_services()->translator->translate(
'install:check:rewrite:success'),
215 if ($this->serverSupportsRemoteRead == FALSE) {
216 $msg =
_elgg_services()->translator->translate(
'install:warning:rewrite:unknown', array(
$url));
217 $msg .=
elgg_view(
'install/js_rewrite_check', array(
'url' =>
$url));
220 'severity' =>
'warning',
225 if ($this->webserver ==
'apache') {
226 $serverString =
_elgg_services()->translator->translate(
'install:error:rewrite:apache');
227 $msg =
"$serverString\n\n";
228 if (!isset($this->htaccessIssue)) {
229 $msg .=
_elgg_services()->translator->translate(
'install:error:rewrite:allowoverride');
230 $msg .=
elgg_view(
'install/js_rewrite_check', array(
'url' =>
$url));
233 'severity' =>
'failure',
237 $msg .=
_elgg_services()->translator->translate(
"install:error:rewrite:htaccess:{$this->htaccessIssue}");
239 'severity' =>
'failure',
244 if ($this->webserver !=
'unknown') {
245 $serverString =
_elgg_services()->translator->translate(
"install:error:rewrite:{$this->webserver}");
246 $msg =
"$serverString\n\n";
247 $msg .=
_elgg_services()->translator->translate(
"install:error:rewrite:altserver");
249 'severity' =>
'failure',
255 'severity' =>
'failure',
256 'message' =>
_elgg_services()->translator->translate(
'install:error:rewrite:unknown'),
if(!array_key_exists($filename, $text_files)) $file
runLocalhostAccessTest()
Check whether the site homepage can be fetched via curl.
$serverSupportsRemoteRead
elgg parse_url
Parse a URL into its parts.
run($url, $path)
Run the rewrite test and return a status array.
createHtaccess($url)
Create Elgg's .htaccess file or confirm that it exists.
returnStatus($url)
Create the status array required by the ElggInstaller.
guessSubdirectory($url)
Guess if url contains subdirectory or not.
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
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
__construct()
Set the webserver as unknown.
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.
const REWRITE_TEST_OUTPUT
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use