diff --git a/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module b/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module
index 87160a17..ebcbb05a 100644
--- a/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module
+++ b/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module
@@ -8,7 +8,7 @@
* For more details about how Process modules work, please see:
* /wire/core/Process.php
*
- * ProcessWire 3.x, Copyright 2021 by Ryan Cramer
+ * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com
*
* @method string findReady($selector)
@@ -31,7 +31,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
return array(
'title' => 'Page Search',
'summary' => 'Provides a page search engine for admin use.',
- 'version' => 107,
+ 'version' => 108,
'permanent' => true,
'permission' => 'page-edit',
);
@@ -66,7 +66,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
'modifiedUser',
'sort',
'sortfield',
- );
+ );
/**
* Names of all Field objects in PW
@@ -172,9 +172,11 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
protected function fullSetup() {
+ $sanitizer = $this->wire()->sanitizer;
+ $input = $this->wire()->input;
$headline = $this->_x('Search', 'headline'); // Headline for search page
- if($this->input->get('processHeadline')) {
- $headline = $this->sanitizer->entities($this->sanitizer->text($this->input->get('processHeadline')));
+ if($input->get('processHeadline')) {
+ $headline = $sanitizer->entities($sanitizer->text($input->get('processHeadline')));
$this->input->whitelist('processHeadline', $headline);
}
$this->wire('processHeadline', $headline);
@@ -203,10 +205,11 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
protected function getLister() {
+ $modules = $this->wire()->modules;
if($this->lister) return $this->lister;
- if($this->wire('user')->hasPermission('page-lister')) {
- if($this->wire('modules')->isInstalled('ProcessPageLister')) {
- $this->lister = $this->wire('modules')->get('ProcessPageLister');
+ if($this->wire()->user->hasPermission('page-lister')) {
+ if($modules->isInstalled('ProcessPageLister')) {
+ $this->lister = $modules->get('ProcessPageLister');
}
}
return $this->lister;
@@ -219,8 +222,8 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
public function ___execute() {
$lister = $this->getLister();
- $ajax = $this->wire('config')->ajax;
- $bookmark = (int) $this->wire('input')->get('bookmark');
+ $ajax = $this->wire()->config->ajax;
+ $bookmark = (int) $this->wire()->input->get('bookmark');
if($lister && ($ajax || $bookmark)) {
// we will just let Lister do it's thing, since it remembers settings in session
@@ -267,14 +270,10 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*/
public function ___executeFor() {
- /** @var Languages $languages */
- $languages = $this->wire('languages');
- /** @var User $user */
- $user = $this->wire('user');
- /** @var WireInput $input */
- $input = $this->wire('input');
- /** @var Sanitizer $sanitizer */
- $sanitizer = $this->wire('sanitizer');
+ $languages = $this->wire()->languages;
+ $user = $this->wire()->user;
+ $input = $this->wire()->input;
+ $sanitizer = $this->wire()->sanitizer;
if($input->get('admin_search')) return $this->executeLive();
@@ -288,12 +287,20 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$superuser = $user->isSuperuser();
$checkEditAccess = false;
$hasInclude = '';
+ $n = 0;
+
+ $selectorName = $input->get('for_selector_name');
+ if($selectorName) {
+ $selector = $this->getForSelector($selectorName);
+ if(strlen($selector)) $selectors['for'] = $selector;
+ }
// names to skip (must be lowercase)
$skipNames = array(
'get',
'display',
'format_name',
+ 'for_selector_name',
'admin_search'
);
@@ -425,20 +432,21 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$input->whitelist($name . rtrim($operator, '='), trim($value, '"\''));
foreach($valuesAND as $val) {
- $selectors[] = "$name$operator$val";
+ $n++;
+ $selectors["input-$n"] = "$name$operator$val";
}
$names[] = $name;
} // foreach input
- if($start) $selectors[] = "start=$start";
- $selectors[] = "limit=$limit";
+ if($start) $selectors['start'] = "start=$start";
+ $selectors['limit'] = "limit=$limit";
$displaySelector = implode(',', $selectors);
if(!$status && !$hasInclude && $superuser) {
// superuser only
- $selectors[] = "include=all, status<" . Page::statusTrash;
+ $selectors['superuser'] = "include=all, status<" . Page::statusTrash;
}
$selector = implode(', ', $selectors);
@@ -470,7 +478,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$liveSearch->setSearchTypesOrder($this->searchTypesOrder);
$liveSearch->setNoSearchTypes($this->noSearchTypes);
$liveSearch->setDefaultOperators($this->operator, $this->operator2);
- if($this->wire('config')->ajax) {
+ if($this->wire()->config->ajax) {
header('Content-type: application/json');
return $liveSearch->execute();
} else {
@@ -485,13 +493,12 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
public function getRepeatersPageID() {
- /** @var Session $session */
- $session = $this->wire('session');
+ $session = $this->wire()->session;
$repeaterID = $session->getFor($this, 'repeaterID');
if(is_int($repeaterID)) return $repeaterID;
- if($this->wire('modules')->isInstalled('FieldtypeRepeater')) {
- $repeaterPage = $this->wire('pages')->get(
- "parent_id=" . $this->wire('config')->adminRootPageID . ", " .
+ if($this->wire()->modules->isInstalled('FieldtypeRepeater')) {
+ $repeaterPage = $this->wire()->pages->get(
+ "parent_id=" . $this->wire()->config->adminRootPageID . ", " .
"name=repeaters, " .
"include=all"
);
@@ -508,10 +515,12 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
protected function getDisplayFields() {
+ $sanitizer = $this->wire()->sanitizer;
+ $input = $this->wire()->input;
- $display = (string) $this->input->get('display');
+ $display = (string) $input->get('display');
- if(!strlen($display)) $display = (string) $this->input->get('get'); // as required by ProcessPageSearch API
+ if(!strlen($display)) $display = (string) $input->get('get'); // as required by ProcessPageSearch API
if(!strlen($display)) $display = (string) $this->displayField;
if(!strlen($display)) $display = 'title path';
@@ -519,7 +528,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$display = explode(' ', $display); // convert to array
foreach($display as $key => $name) {
- $name = $this->sanitizer->fieldName($name);
+ $name = $sanitizer->fieldName($name);
$display[$key] = $name;
if($this->isSelectableFieldName($name)) continue;
if(in_array($name, array('url', 'path', 'httpUrl'))) continue;
@@ -537,13 +546,13 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
* The name the session variable must be provided as a GET var: format_name=[name]
*
- * @return mixed|string
+ * @return array|string
*
*/
protected function getDisplayFormat() {
- $name = $this->input->get('format_name');
+ $name = $this->wire()->input->get('format_name');
if(empty($name)) return '';
- $data = $this->wire('session')->getFor($this, "format_" . $name);
+ $data = $this->wire()->session->getFor($this, "format_" . $name);
if(empty($data)) return '';
return array(
'name' => $name,
@@ -561,12 +570,49 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
public function setDisplayFormat($name, $format, $textOnly = false) {
- $this->wire('session')->setFor($this, "format_" . $name, array(
+ $this->wire()->session->setFor($this, "format_" . $name, array(
'format' => $format,
'textOnly' => $textOnly
));
}
+ /**
+ * Set a selector to use when $_GET['for_selector_name'] matches given $name
+ *
+ * This is for cases where you don't want the selector to pass through user input,
+ * and you instead just want to pass the name of it via user input. This enables
+ * use of some features that may not be available through user selectors passing
+ * only through user input.
+ *
+ * Used in executeFor() mode only.
+ *
+ * @param string $name
+ * @param string $selector
+ * @return string Returns URL needed to use this selector
+ * @since 3.0.223
+ *
+ */
+ public function setForSelector($name, $selector) {
+ $this->wire()->session->setFor($this, "for_selector_$name", $selector);
+ return $this->config->urls->admin . 'page/search/for?for_selector_name=' . urlencode($name);
+ }
+
+ /**
+ * Get selector identified by $name that was previously set with setForSelector()
+ *
+ * For executeFor() mode only.
+ *
+ * #pw-internal
+ *
+ * @param string $name
+ * @return string
+ * @since 3.0.223
+ *
+ */
+ public function getForSelector($name) {
+ return (string) $this->wire()->session->getFor($this, "for_selector_$name");
+ }
+
/**
* Render the search results
*
@@ -576,6 +622,9 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
protected function render(PageArray $matches, $displaySelector = '') {
+
+ $input = $this->wire()->input;
+ $ajax = $this->wire()->config->ajax;
$out = '';
@@ -591,13 +640,13 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
// determine what fields will be displayed
$display = array();
- if($this->config->ajax) $display = $this->getDisplayFormat();
+ if($ajax) $display = $this->getDisplayFormat();
if(empty($display)) {
$display = $this->getDisplayFields();
- $this->input->whitelist('display', implode(',', $display));
+ $input->whitelist('display', implode(',', $display));
}
- if($this->config->ajax) {
+ if($ajax) {
// ajax json output
header("Content-type: application/json");
$out = $this->renderMatchesAjax($matches, $display, $displaySelector);
@@ -605,7 +654,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
} else {
// html output
$class = '';
- if((int) $this->input->get('show_options') !== 0 && $this->input->urlSegment1 != 'find') {
+ if((int) $input->get('show_options') !== 0 && $input->urlSegment1 != 'find') {
$out = "\n
" . $this->renderFullSearchForm() . "
";
$class = 'show_options';
}
@@ -636,8 +685,14 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
protected function buildSelector() {
+
+ $input = $this->wire()->input;
+ $sanitizer = $this->wire()->sanitizer;
+ $user = $this->wire()->user;
+ $pages = $this->wire()->pages;
+ $config = $this->wire()->config;
+
$selector = ''; // for regular ProcessPageSearch
- $input = $this->wire('input');
// search query text
$q = $input->whitelist('q');
@@ -652,10 +707,10 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
if(is_string($searchFields)) $searchFields = explode(' ', $searchFields);
}
foreach($searchFields as $fieldName) {
- $fieldName = $this->sanitizer->fieldName($fieldName);
+ $fieldName = $sanitizer->fieldName($fieldName);
$selector .= "$fieldName|";
}
- $selector = rtrim($selector, '|') . $this->operator . $this->wire('sanitizer')->selectorValue($q);
+ $selector = rtrim($selector, '|') . $this->operator . $sanitizer->selectorValue($q);
}
// determine if results are sorted by something other than relevance
@@ -680,7 +735,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
}
$trash = $input->whitelist('trash');
- if($trash !== null && $this->wire('user')->isSuperuser()) {
+ if($trash !== null && $user->isSuperuser()) {
if($trash === 0) {
$selector .= ", status!=trash";
} else if($trash === 1) {
@@ -701,27 +756,27 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$s = ''; // anything added to this will be populated to both $selector and $initSelector below
// limit results for pagination
- $s .= ", limit={$this->resultLimit}";
+ $s .= ", limit=$this->resultLimit";
- $adminRootPage = $this->wire('pages')->get($this->wire('config')->adminRootPageID);
+ $adminRootPage = $pages->get($config->adminRootPageID);
// exclude admin repeater pages unless the admin template is chosen
if(!$input->whitelist('template')) {
// but only for superuser, as we're excluding all admin pages for non-superusers
if($this->user->isSuperuser()) {
$repeaters = $adminRootPage->child('name=repeaters, include=all');
- if($repeaters->id) $s .= ", has_parent!={$repeaters->id}";
+ if($repeaters->id) $s .= ", has_parent!=$repeaters->id";
}
}
// include hidden pages
- if($this->user->isSuperuser()) {
+ if($user->isSuperuser()) {
$s .= ", include=all";
} else {
// non superuser doesn't get any admin pages in their results
$s .= ", has_parent!=$adminRootPage";
// if user has any kind of edit access, allow unpublished pages to be included
- if($this->user->hasPermission('page-edit')) $s .= ", include=unpublished";
+ if($user->hasPermission('page-edit')) $s .= ", include=unpublished";
}
$selector .= $s;
@@ -735,11 +790,10 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*
*/
protected function processInput() {
-
- /** @var WireInput $input */
- $input = $this->wire('input');
- /** @var Sanitizer $sanitizer */
- $sanitizer = $this->wire('sanitizer');
+
+ $user = $this->wire()->user;
+ $input = $this->wire()->input;
+ $sanitizer = $this->wire()->sanitizer;
// search query
$q = $input->get('q');
@@ -797,15 +851,15 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$template = $input->get('template');
if($template) {
$template = $sanitizer->templateName($template);
- $template = $this->wire('templates')->get($template);
- if($template && $this->wire('user')->hasPermission('page-view', $template)) {
+ $template = $this->wire()->templates->get($template);
+ if($template && $user->hasPermission('page-view', $template)) {
$input->whitelist('template', $template->name);
}
}
// trash (liveSearch)
$trash = $input->get('trash');
- if($trash !== null && $this->wire('user')->isSuperuser()) {
+ if($trash !== null && $user->isSuperuser()) {
$trash = (int) $trash;
if($trash === 0 || $trash === 1) {
$input->whitelist('trash', $trash);
@@ -833,14 +887,11 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
*/
protected function processInputQuery($q) {
- /** @var WireInput $input */
- $input = $this->wire('input');
- /** @var Sanitizer $sanitizer */
- $sanitizer = $this->wire('sanitizer');
+ $input = $this->wire()->input;
+ $sanitizer = $this->wire()->sanitizer;
$q = trim($sanitizer->text($q));
$redirectUrl = '';
- $operator = '';
$operators = $this->operators;
$type = '';
@@ -873,7 +924,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
if(strpos($type, '.')) {
// type with property/field
list($type, $field) = explode('.', $type, 2);
- $field = $this->wire('sanitizer')->fieldName(trim($field));
+ $field = $sanitizer->fieldName(trim($field));
$input->get->set('field', $field);
} else {
$field = '';
@@ -884,13 +935,13 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
} else if($type == 'trash') {
$input->get->set('trash', 1);
} else if($type) {
- $template = $type ? $this->wire('templates')->get($type) : '';
+ $template = $this->wire()->templates->get($type);
if($template) {
// defined template
$input->get->set('template', $template->name);
} else {
// some other non-page type
- $redirectUrl = $this->wire('page')->url . 'live/' .
+ $redirectUrl = $this->wire()->page->url . 'live/' .
'?q=' . urlencode($q) .
'&type=' . urlencode($type) .
'&property=' . urlencode($field) .
@@ -898,7 +949,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
}
}
- if($redirectUrl) $this->wire('session')->redirect($redirectUrl);
+ if($redirectUrl) $this->wire()->session->redirect($redirectUrl);
$input->whitelist('q', $q);
}
@@ -1037,6 +1088,9 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
}
protected function renderFullSearchForm() {
+
+ $input = $this->wire()->input;
+ $modules = $this->wire()->modules;
// Search options
@@ -1065,7 +1119,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
$out .=
"\n\t" .
- "\n\t" .
+ "\n\t" .
"\n\t" .
"\n\t";
@@ -1080,11 +1134,11 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
"\n\t