Skip to content

Commit

Permalink
Merge pull request #1558 from voltan/develop
Browse files Browse the repository at this point in the history
Fix setup paths on php 7.1
  • Loading branch information
voltan authored Sep 6, 2017
2 parents ca9e7e9 + f84fd81 commit b56355c
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions www/setup/src/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function init($initPath = false)
foreach (array_keys($writablePaths) as $key) {
$this->permErrors[$key] = false;
}
$paths = $this->wizard->getPersist($this->persist);
//$paths = $this->wizard->getPersist($this->persist);
$paths = '';
// Load from persistent
if ($paths) {
foreach ($this->paths as $key => &$path) {
Expand All @@ -104,19 +105,19 @@ public function init($initPath = false)
? $paths[$key]['url'] : '',
);
}
// Initialize
// Initialize
} else {
// Initialize www path and URI
$request = $this->wizard->getRequest();
$baseUrl = $request->getScheme() . '://'
. $request->getHttpHost() . $request->getBaseUrl();
. $request->getHttpHost() . $request->getBaseUrl();
$this->paths['www'] = array(
'path' => dirname($this->wizard->getRoot()),
'url' => dirname($baseUrl)
);

foreach ($this->wizard->getConfig('paths') as $key => $inits) {
// Initialize path
/* // Initialize path
foreach ((array) $inits['path'] as $init) {
if ($init{0} === '%') {
list($idx, $loc) = explode('/', $init, 2);
Expand Down Expand Up @@ -148,7 +149,39 @@ public function init($initPath = false)
}
$this->paths[$key]['url'] = $init;
//if (0 <= $this->checkUrl($key)) break;
} */

// Initialize path
foreach ((array) $inits['path'] as $init) {
if ($init{0} === '%') {
list($idx, $loc) = explode('/', $init, 2);
$idx = substr($idx, 1);
if (isset($this->paths[$idx]['path'])) {
$init = $this->paths[$idx]['path'] . '/' . $loc;
}
} else {
$init = $this->paths['www']['path'] . '/' . $init;
}
$path = preg_replace('/\w+\/\.\.\//', '', $init);
if (is_dir($path . '/')) break;
}

// Initialize URI
foreach ((array) $inits['url'] as $init) {
if ($init{0} === '%') {
list($idx, $loc) = explode('/', $init, 2);
$idx = substr($idx, 1);
if (isset($this->paths[$idx]['url'])) {
$init = $this->paths[$idx]['url'] . '/' . $loc;
}
}
//if (0 <= $this->checkUrl($key)) break;
}

$this->paths[$key] = array(
'path' => $path,
'url' => $init,
);
}

$this->wizard->setPersist($this->persist, $this->paths);
Expand Down Expand Up @@ -412,7 +445,7 @@ private function formulateUrl($url)

if ($url{0} != '/') {
$url = (isset($this->paths['www']['url'])
? $this->paths['www']['url'] : '') . '/' . $url;
? $this->paths['www']['url'] : '') . '/' . $url;
} else {
$proto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
? 'https' : 'http';
Expand Down Expand Up @@ -458,7 +491,7 @@ private function validateUrl($url = '', $mimeType = '')
// Content-Type might not be detected correctly by CURL
// Thus return null instead of false if not matched
$ret = (strpos($contentType, $mimeType) !== false)
? true : null;
? true : null;
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$ret = ($httpCode == 200) ? true : false;
Expand All @@ -481,11 +514,11 @@ private function validateUrl($url = '', $mimeType = '')
$result = @get_headers($url, 1);
// Check if HTTP code is 200
$ret = preg_match('#HTTP/[^\s]+[\s]200([\s]?)#i', $result[0],
$matches);
$matches);
// Check content type match if specified
if ($ret && !empty($contentType)) {
$ret = strpos($result['Content-Type'], $contentType) !== false
? true : false;
? true : false;
}
}

Expand All @@ -510,7 +543,7 @@ private function setWritePermission($parent, $path, &$error)
if (empty($path[$item])) continue;
foreach ($path[$item] as $child) {
$this->setWritePermission($parent . '/' . $item,
$child, $error);
$child, $error);
}
} else {
$error[$parent . '/' . $path[$item]] =
Expand Down Expand Up @@ -559,10 +592,10 @@ private function makeWritable($path, $recurse = true, $create = true)
continue;
}
$status = $status * $this->makeWritable(
$fileinfo->getPathname(),
$recurse,
$create
);
$fileinfo->getPathname(),
$recurse,
$create
);
if (!$status) {
break;
}
Expand Down Expand Up @@ -598,4 +631,4 @@ public function setPath($name, $value)
$this->paths[$key][$type] = $value;
$this->wizard->setPersist($this->persist, $this->paths);
}
}
}

0 comments on commit b56355c

Please sign in to comment.