mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 15:23:11 +02:00
Add support for $config->noHTTPS. When boolean true, it cancels any HTTPS requirements set per-template, simplifying cases where you copy a production site to dev site that may not have the same HTTPS capabilities. So for that case, the dev site would want to have $config->noHTTPS=true; in /site/config.php
This commit is contained in:
@@ -95,6 +95,7 @@
|
||||
* @property array $adminThumbOptions Admin thumbnail image options #pw-group-images
|
||||
* @property array $httpHosts HTTP hosts For added security, specify the host names ProcessWire should recognize. #pw-group-HTTP-and-input
|
||||
* @property int $maxPageNum Maximum number of recognized paginations #pw-group-URLs
|
||||
* @property bool $noHTTPS When boolean true, pages requiring HTTPS will not enforce it (useful for dev environments).
|
||||
*
|
||||
* @property string $dbHost Database host #pw-group-database
|
||||
* @property string $dbName Database name #pw-group-database
|
||||
@@ -402,5 +403,22 @@ class Config extends WireData {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if current PHP version is equal to or newer than the given version
|
||||
*
|
||||
* ~~~~~
|
||||
* if($config->phpVersion('7.0.0')) {
|
||||
* // PHP version is 7.x
|
||||
* }
|
||||
* ~~~~~
|
||||
*
|
||||
* @param string|null $minVersion
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public function phpVersion($minVersion) {
|
||||
return version_compare(PHP_VERSION, $minVersion) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2834,15 +2834,23 @@ class Page extends WireData implements \Countable, WireMatchable {
|
||||
*
|
||||
*/
|
||||
public function httpUrl($options = array()) {
|
||||
if(!$this->template) return '';
|
||||
switch($this->template->https) {
|
||||
$template = $this->template;
|
||||
if(!$template) return '';
|
||||
/** @var Config $config */
|
||||
$config = $this->wire('config');
|
||||
$mode = $template->https;
|
||||
if($mode > 0 && $config->noHTTPS) $mode = 0;
|
||||
switch($mode) {
|
||||
case -1: $protocol = 'http'; break;
|
||||
case 1: $protocol = 'https'; break;
|
||||
default: $protocol = $this->wire('config')->https ? 'https' : 'http';
|
||||
default: $protocol = $config->https ? 'https' : 'http';
|
||||
}
|
||||
if(is_array($options)) unset($options['http']);
|
||||
else if(is_bool($options)) $options = array();
|
||||
return "$protocol://" . $this->wire('config')->httpHost . $this->url($options);
|
||||
if(is_array($options)) {
|
||||
unset($options['http']);
|
||||
} else if(is_bool($options)) {
|
||||
$options = array();
|
||||
}
|
||||
return "$protocol://" . $config->httpHost . $this->url($options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2866,13 +2874,16 @@ class Page extends WireData implements \Countable, WireMatchable {
|
||||
*
|
||||
*/
|
||||
public function editUrl($options = array()) {
|
||||
/** @var Config $config */
|
||||
$config = $this->wire('config');
|
||||
/** @var Template $adminTemplate */
|
||||
$adminTemplate = $this->wire('templates')->get('admin');
|
||||
$https = $adminTemplate && ($adminTemplate->https > 0);
|
||||
$url = ($https && !$this->wire('config')->https) ? 'https://' . $this->wire('config')->httpHost : '';
|
||||
$url .= $this->wire('config')->urls->admin . "page/edit/?id=$this->id";
|
||||
$https = $adminTemplate && ($adminTemplate->https > 0) && !$config->noHTTPS;
|
||||
$url = ($https && !$config->https) ? 'https://' . $config->httpHost : '';
|
||||
$url .= $config->urls->admin . "page/edit/?id=$this->id";
|
||||
if($options === true || (is_array($options) && !empty($options['http']))) {
|
||||
if(strpos($url, '://') === false) {
|
||||
$url = ($https ? 'https://' : 'http://') . $this->wire('config')->httpHost . $url;
|
||||
$url = ($https ? 'https://' : 'http://') . $config->httpHost . $url;
|
||||
}
|
||||
}
|
||||
$append = $this->wire('session')->getFor($this, 'appendEditUrl');
|
||||
@@ -3356,9 +3367,14 @@ class Page extends WireData implements \Countable, WireMatchable {
|
||||
if(is_null($status)) $status = $this->status;
|
||||
if($value === false) return $status;
|
||||
$names = array();
|
||||
$remainder = $status;
|
||||
foreach(self::$statuses as $name => $value) {
|
||||
if($status & $value) $names[$value] = $name;
|
||||
if($status & $value) {
|
||||
$names[$value] = $name;
|
||||
$remainder = $remainder & ~$value;
|
||||
}
|
||||
}
|
||||
if($remainder > 1) $names[$remainder] = "unknown-$remainder";
|
||||
return $names;
|
||||
}
|
||||
|
||||
|
@@ -164,7 +164,7 @@ class PageFrontEdit extends WireData implements Module {
|
||||
if($config->ajax && $input->post('action') == 'PageFrontEditSave') {
|
||||
// skip, this is handled by another hook
|
||||
|
||||
} else if($this->wire('templates')->get('admin')->https == 1 && !$config->https && $page->template->https != -1) {
|
||||
} else if($this->wire('templates')->get('admin')->https == 1 && !$config->https && !$config->noHTTPS && $page->template->https != -1) {
|
||||
// hooks allowed, but we need the same scheme as admin
|
||||
$url = $input->httpUrl(true);
|
||||
if(strpos($url, 'http://') === 0) {
|
||||
|
@@ -678,10 +678,11 @@ class ProcessPageView extends Process {
|
||||
*/
|
||||
protected function checkProtocol($page) {
|
||||
|
||||
$requireHTTPS = $page->template->https;
|
||||
if($requireHTTPS == 0) return; // neither HTTP or HTTPS required
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $this->wire('config');
|
||||
$requireHTTPS = $page->template->https;
|
||||
if($requireHTTPS == 0 || $config->noHTTPS) return; // neither HTTP or HTTPS required
|
||||
|
||||
$isHTTPS = $config->https;
|
||||
$scheme = '';
|
||||
|
||||
|
Reference in New Issue
Block a user