mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 09:14:58 +02:00
Minor code improvements
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
* Thanks to @horst for his assistance with several methods in this class.
|
* Thanks to @horst for his assistance with several methods in this class.
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method bool|string send($url, $data = array(), $method = 'POST', array $options = array())
|
* @method bool|string send($url, $data = array(), $method = 'POST', array $options = array())
|
||||||
@@ -289,6 +289,7 @@ class WireHttp extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
$this->hasCURL = function_exists('curl_init') && !ini_get('safe_mode'); // && !ini_get('open_basedir');
|
$this->hasCURL = function_exists('curl_init') && !ini_get('safe_mode'); // && !ini_get('open_basedir');
|
||||||
$this->hasFopen = ini_get('allow_url_fopen');
|
$this->hasFopen = ini_get('allow_url_fopen');
|
||||||
$this->resetRequest();
|
$this->resetRequest();
|
||||||
@@ -396,7 +397,7 @@ class WireHttp extends Wire {
|
|||||||
* @param mixed $data Array of data to send (if not already set before) or raw data
|
* @param mixed $data Array of data to send (if not already set before) or raw data
|
||||||
* @param bool $textMode When true function will return a string rather than integer, see the statusText() method.
|
* @param bool $textMode When true function will return a string rather than integer, see the statusText() method.
|
||||||
* @param array $options Optional options to modify default behavior, see the send() method for details.
|
* @param array $options Optional options to modify default behavior, see the send() method for details.
|
||||||
* @return bool|integer|string False on failure or integer or string of status code (200|404|etc) on success.
|
* @return bool|int|string False on failure or integer or string of status code (200|404|etc) on success.
|
||||||
* @see WireHttp::send(), WireHttp::statusText()
|
* @see WireHttp::send(), WireHttp::statusText()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -989,7 +990,7 @@ class WireHttp extends Wire {
|
|||||||
|
|
||||||
$methods = implode(", ", $triedMethods);
|
$methods = implode(", ", $triedMethods);
|
||||||
if(count($this->error) || ($this->httpCode >= 400 && isset($this->httpCodes[$this->httpCode]))) {
|
if(count($this->error) || ($this->httpCode >= 400 && isset($this->httpCodes[$this->httpCode]))) {
|
||||||
$this->wire('files')->unlink($toFile);
|
$this->wire()->files->unlink($toFile);
|
||||||
$error = $this->_('File could not be downloaded') . ' ' . htmlentities("($fromURL) ") . $this->getError() . " (tried: $methods)";
|
$error = $this->_('File could not be downloaded') . ' ' . htmlentities("($fromURL) ") . $this->getError() . " (tried: $methods)";
|
||||||
throw new WireException($error);
|
throw new WireException($error);
|
||||||
} else {
|
} else {
|
||||||
@@ -997,7 +998,7 @@ class WireHttp extends Wire {
|
|||||||
$this->message("Downloaded " . htmlentities($fromURL) . " => $toFile (using: $methods) [$bytes bytes]", Notice::debug);
|
$this->message("Downloaded " . htmlentities($fromURL) . " => $toFile (using: $methods) [$bytes bytes]", Notice::debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wire('files')->chmod($toFile);
|
$this->wire()->files->chmod($toFile);
|
||||||
|
|
||||||
return $toFile;
|
return $toFile;
|
||||||
}
|
}
|
||||||
@@ -1018,9 +1019,13 @@ class WireHttp extends Wire {
|
|||||||
$setopts = null;
|
$setopts = null;
|
||||||
$proxy = '';
|
$proxy = '';
|
||||||
|
|
||||||
if(!empty($options['proxy'])) $proxy = $options['proxy'];
|
if(!empty($options['proxy'])) {
|
||||||
else if(isset($options['curl']) && !empty($options['curl']['http']['proxy'])) $proxy = $options['curl']['http']['proxy'];
|
$proxy = $options['proxy'];
|
||||||
else if(isset($options['http']) && !empty($options['http']['proxy'])) $proxy = $options['http']['proxy'];
|
} else if(isset($options['curl']) && !empty($options['curl']['http']['proxy'])) {
|
||||||
|
$proxy = $options['curl']['http']['proxy'];
|
||||||
|
} else if(isset($options['http']) && !empty($options['http']['proxy'])) {
|
||||||
|
$proxy = $options['http']['proxy'];
|
||||||
|
}
|
||||||
|
|
||||||
$curl = curl_init($fromURL);
|
$curl = curl_init($fromURL);
|
||||||
|
|
||||||
@@ -1256,12 +1261,12 @@ class WireHttp extends Wire {
|
|||||||
*
|
*
|
||||||
* #pw-internal
|
* #pw-internal
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $name
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __get($key) {
|
public function __get($name) {
|
||||||
return array_key_exists($key, $this->data) ? $this->data[$key] : null;
|
return array_key_exists($name, $this->data) ? $this->data[$name] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1420,7 +1425,7 @@ class WireHttp extends Wire {
|
|||||||
$this->responseHeaderArrays[$key] = $valueArray;
|
$this->responseHeaderArrays[$key] = $valueArray;
|
||||||
} else {
|
} else {
|
||||||
if(is_array($value)) {
|
if(is_array($value)) {
|
||||||
foreach($value as $k => $v) {
|
foreach($value as $v) {
|
||||||
$this->responseHeaderArrays[$key][] = $v;
|
$this->responseHeaderArrays[$key][] = $v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1488,7 +1493,7 @@ class WireHttp extends Wire {
|
|||||||
|
|
||||||
$options = array_merge($defaultOptions, $options);
|
$options = array_merge($defaultOptions, $options);
|
||||||
$headers = array_merge($defaultHeaders, $options['headers'], $headers);
|
$headers = array_merge($defaultHeaders, $options['headers'], $headers);
|
||||||
$contentTypes = $this->wire('config')->fileContentTypes;
|
$contentTypes = $this->wire()->config->fileContentTypes;
|
||||||
|
|
||||||
if($filename === false) {
|
if($filename === false) {
|
||||||
// sending data string
|
// sending data string
|
||||||
@@ -1510,7 +1515,7 @@ class WireHttp extends Wire {
|
|||||||
$forceDownload = $options['forceDownload'];
|
$forceDownload = $options['forceDownload'];
|
||||||
$bytesSent = 0;
|
$bytesSent = 0;
|
||||||
|
|
||||||
if($options['exit']) $this->wire('session')->close();
|
if($options['exit']) $this->wire()->session->close();
|
||||||
if(is_null($forceDownload)) $forceDownload = substr($contentType, 0, 1) === '+';
|
if(is_null($forceDownload)) $forceDownload = substr($contentType, 0, 1) === '+';
|
||||||
if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');
|
if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');
|
||||||
$contentType = ltrim($contentType, '+');
|
$contentType = ltrim($contentType, '+');
|
||||||
@@ -1742,7 +1747,7 @@ class WireHttp extends Wire {
|
|||||||
$options = $this->validateURLOptions;
|
$options = $this->validateURLOptions;
|
||||||
$options['allowSchemes'] = $this->allowSchemes;
|
$options['allowSchemes'] = $this->allowSchemes;
|
||||||
try {
|
try {
|
||||||
$url = $this->wire('sanitizer')->url($url, $options);
|
$url = $this->wire()->sanitizer->url($url, $options);
|
||||||
} catch(WireException $e) {
|
} catch(WireException $e) {
|
||||||
if($throw) {
|
if($throw) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
* For more details about how Process modules work, please see:
|
* For more details about how Process modules work, please see:
|
||||||
* /wire/core/Process.php
|
* /wire/core/Process.php
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @method string execute($internal = true)
|
* @method string execute($internal = true)
|
||||||
@@ -272,7 +272,7 @@ class ProcessPageView extends Process {
|
|||||||
// in case it wants to concatenate it or something
|
// in case it wants to concatenate it or something
|
||||||
if($n === 1) $this->pathHooksReturnValue = $out;
|
if($n === 1) $this->pathHooksReturnValue = $out;
|
||||||
|
|
||||||
if(is_object($out) && $out instanceof Page) {
|
if($out instanceof Page) {
|
||||||
// hook returned Page object to set as page to render
|
// hook returned Page object to set as page to render
|
||||||
$page = $out;
|
$page = $out;
|
||||||
$out = true;
|
$out = true;
|
||||||
@@ -300,7 +300,7 @@ class ProcessPageView extends Process {
|
|||||||
$this->pathHooksReturnValue = false; // no longer applicable once this line reached
|
$this->pathHooksReturnValue = false; // no longer applicable once this line reached
|
||||||
$hooks->allowPathHooks(false); // no more path hooks allowed
|
$hooks->allowPathHooks(false); // no more path hooks allowed
|
||||||
|
|
||||||
if($page && $page->id && $page instanceof Page && $page->id !== $options['page']->id) {
|
if($page instanceof Page && $page->id && $page->id !== $options['page']->id) {
|
||||||
// one of the path hooks set the page
|
// one of the path hooks set the page
|
||||||
$this->wire('page', $page);
|
$this->wire('page', $page);
|
||||||
return $this->renderPage($page, $request);
|
return $this->renderPage($page, $request);
|
||||||
@@ -414,7 +414,7 @@ class ProcessPageView extends Process {
|
|||||||
$loginRequestURL = $request->getRedirectUrl();
|
$loginRequestURL = $request->getRedirectUrl();
|
||||||
$ns = 'ProcessPageView'; // session namespace
|
$ns = 'ProcessPageView'; // session namespace
|
||||||
|
|
||||||
if(empty($loginRequestURL) && $session) {
|
if(empty($loginRequestURL)) {
|
||||||
$loginRequestURL = $session->getFor($ns, 'loginRequestURL');
|
$loginRequestURL = $session->getFor($ns, 'loginRequestURL');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user