mirror of
https://github.com/processwire/processwire.git
synced 2025-08-06 23:06:59 +02:00
Update ProcessController::jsonMessage() method so that it supports array argument, primarily for internal debugging purposes
This commit is contained in:
@@ -486,18 +486,22 @@ class ProcessController extends Wire {
|
||||
/**
|
||||
* Generate a message in JSON format, for use with AJAX output
|
||||
*
|
||||
* @param string $msg
|
||||
* @param bool $error
|
||||
* @param bool $allowMarkup
|
||||
* @param string|array $msg Message string or in 3.0.246+ also accepts an array of extra data
|
||||
* When using an array, please include a 'message' index with text about the error or non-error.
|
||||
* @param bool $error Is this in error message? Default is true, or specify false if not.
|
||||
* @param bool $allowMarkup Allow markup in message? Applies only to $msg string or 'message' index of array (default=false)
|
||||
* @return string JSON encoded string
|
||||
*
|
||||
*/
|
||||
public function jsonMessage($msg, $error = false, $allowMarkup = false) {
|
||||
if(!$allowMarkup) $msg = $this->wire()->sanitizer->entities($msg);
|
||||
return json_encode(array(
|
||||
'error' => (bool) $error,
|
||||
'message' => (string) $msg
|
||||
));
|
||||
$a = array('error' => (bool) $error, 'message' => '');
|
||||
if(is_array($msg)) {
|
||||
$a = array_merge($a, $msg);
|
||||
} else {
|
||||
$a['message'] = (string) $msg;
|
||||
}
|
||||
if(!$allowMarkup) $a['message'] = $this->wire()->sanitizer->entities($a['message']);
|
||||
return json_encode($a);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -440,7 +440,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
|
||||
|
||||
} // foreach input
|
||||
|
||||
if(strpos($selectors['for'], 'limit=') && $limit === $this->resultLimit) {
|
||||
if(isset($selectors['for']) && strpos($selectors['for'], 'limit=') && $limit === $this->resultLimit) {
|
||||
if(preg_match('/\blimit=(\d+),?/', $selectors['for'], $matches)) {
|
||||
$limit = (int) $matches[1];
|
||||
$selectors['for'] = str_replace($matches[0], '', $selectors['for']);
|
||||
|
Reference in New Issue
Block a user