mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +02:00
A couple of small improvements to ProcessPageLister, including improved editable() check of mock Page per template that also now includes parent in the check, and improved debug output of selector that now includes modifications to selector made by PageFinder
This commit is contained in:
@@ -138,6 +138,14 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
*/
|
*/
|
||||||
protected $finalSelector = '';
|
protected $finalSelector = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Final selector string after being fully parsed by PageFinder (used only in debug mode)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $finalSelectorParsed = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IDs of pages that should appear open automatically
|
* IDs of pages that should appear open automatically
|
||||||
*
|
*
|
||||||
@@ -995,7 +1003,13 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
*/
|
*/
|
||||||
protected function validateSelector($selector) {
|
protected function validateSelector($selector) {
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
$user = $this->wire('user');
|
$user = $this->wire('user');
|
||||||
|
/** @var Sanitizer $sanitizer */
|
||||||
|
$sanitizer = $this->wire('sanitizer');
|
||||||
|
/** @var Pages $pages */
|
||||||
|
$pages = $this->wire('pages');
|
||||||
|
|
||||||
$showIncludeWarnings = $this->showIncludeWarnings; // whether to show warning message about removed include modes
|
$showIncludeWarnings = $this->showIncludeWarnings; // whether to show warning message about removed include modes
|
||||||
|
|
||||||
if($user->isSuperuser()) {
|
if($user->isSuperuser()) {
|
||||||
@@ -1015,6 +1029,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
/** @var Selectors $selectors */
|
/** @var Selectors $selectors */
|
||||||
$selectors = $this->wire(new Selectors($selector));
|
$selectors = $this->wire(new Selectors($selector));
|
||||||
$templates = array();
|
$templates = array();
|
||||||
|
$parents = array();
|
||||||
$changed = false;
|
$changed = false;
|
||||||
$templateSelector = null;
|
$templateSelector = null;
|
||||||
$includeSelector = null;
|
$includeSelector = null;
|
||||||
@@ -1028,6 +1043,8 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
$fields[$key] = strtolower($name);
|
$fields[$key] = strtolower($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$firstField = reset($fields);
|
||||||
|
|
||||||
if(in_array('check_access', $fields) || in_array('checkaccess', $fields)) {
|
if(in_array('check_access', $fields) || in_array('checkaccess', $fields)) {
|
||||||
if(!$this->allowIncludeAll) {
|
if(!$this->allowIncludeAll) {
|
||||||
// don't allow non-superusers to specify a check_access property
|
// don't allow non-superusers to specify a check_access property
|
||||||
@@ -1041,7 +1058,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
|
|
||||||
foreach($values as $key => $value) {
|
foreach($values as $key => $value) {
|
||||||
|
|
||||||
$value = $this->wire('sanitizer')->templateName($value);
|
$value = $sanitizer->templateName($value);
|
||||||
if(ctype_digit("$value")) $value = (int) $value;
|
if(ctype_digit("$value")) $value = (int) $value;
|
||||||
$template = $this->wire('templates')->get($value);
|
$template = $this->wire('templates')->get($value);
|
||||||
|
|
||||||
@@ -1064,6 +1081,18 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$templateSelector = $s;
|
$templateSelector = $s;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(($firstField === 'parent' || $firstField === 'parent.id') && count($fields) == 1) {
|
||||||
|
foreach($values as $value) {
|
||||||
|
if(ctype_digit("$value")) {
|
||||||
|
$parent = $pages->get((int) $value);
|
||||||
|
} else {
|
||||||
|
$parent = $pages->get($sanitizer->selectorValue($value));
|
||||||
|
}
|
||||||
|
if($parent->id) $parents[] = $parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_array('include', $fields)) {
|
if(in_array('include', $fields)) {
|
||||||
@@ -1098,12 +1127,25 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
// user specified 1 or more templates
|
// user specified 1 or more templates
|
||||||
$numEditable = 0;
|
$numEditable = 0;
|
||||||
// determine how many templates are editable
|
// determine how many templates are editable
|
||||||
$test = $this->wire('pages')->newPage();
|
$test = $pages->newPage();
|
||||||
|
$test->id = 999; // required (any ID number works)
|
||||||
|
if(count($parents)) {
|
||||||
|
foreach($templates as $template) {
|
||||||
|
$test->template = $template;
|
||||||
|
foreach($parents as $parent) {
|
||||||
|
$test->parent = $parent;
|
||||||
|
if($test->editable()) {
|
||||||
|
$numEditable++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
foreach($templates as $template) {
|
foreach($templates as $template) {
|
||||||
$test->template = $template;
|
$test->template = $template;
|
||||||
$test->id = 999; // required (any ID number works)
|
|
||||||
if($test->editable()) $numEditable++;
|
if($test->editable()) $numEditable++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// if all specified templates are editable, include=unpublished is allowed
|
// if all specified templates are editable, include=unpublished is allowed
|
||||||
if($numEditable == count($templates)) {
|
if($numEditable == count($templates)) {
|
||||||
// include=unpublished is allowed
|
// include=unpublished is allowed
|
||||||
@@ -1802,7 +1844,13 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$options = array('allowCustom' => true);
|
$options = array('allowCustom' => true);
|
||||||
$results = $selector ? $this->wire('pages')->find($selector, $options) : $this->wire('pages')->newPageArray();
|
/** @var Pages $pages */
|
||||||
|
$pages = $this->wire('pages');
|
||||||
|
$results = $selector ? $pages->find($selector, $options) : $pages->newPageArray();
|
||||||
|
$this->finalSelector = $results->getSelectors(true);
|
||||||
|
if($this->wire('config')->debug && $this->wire('config')->advanced) {
|
||||||
|
$this->finalSelectorParsed = (string) $pages->loader()->getLastPageFinder()->getSelectors();
|
||||||
|
}
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->error($e->getMessage());
|
$this->error($e->getMessage());
|
||||||
@@ -1834,6 +1882,9 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
*/
|
*/
|
||||||
protected function ___renderResults($selector = null) {
|
protected function ___renderResults($selector = null) {
|
||||||
|
|
||||||
|
/** @var Sanitizer $sanitizer */
|
||||||
|
$sanitizer = $this->wire('sanitizer');
|
||||||
|
|
||||||
if(is_null($selector)) $selector = $this->getSelector();
|
if(is_null($selector)) $selector = $this->getSelector();
|
||||||
if(!count($this->columns)) $this->columns = $this->defaultColumns;
|
if(!count($this->columns)) $this->columns = $this->defaultColumns;
|
||||||
$results = $this->findResults($selector);
|
$results = $this->findResults($selector);
|
||||||
@@ -1883,12 +1934,21 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
|||||||
if(count($this->resultNotes)) {
|
if(count($this->resultNotes)) {
|
||||||
$notes = array();
|
$notes = array();
|
||||||
foreach($this->resultNotes as $note) {
|
foreach($this->resultNotes as $note) {
|
||||||
$notes[] = wireIconMarkup('warning') . ' ' . $this->wire('sanitizer')->entities1($note);
|
$notes[] = wireIconMarkup('warning') . ' ' . $sanitizer->entities1($note);
|
||||||
}
|
}
|
||||||
$out .= "<p id='ProcessListerResultNotes' class='detail'>" . implode('<br />', $notes) . "</p>";
|
$out .= "<p id='ProcessListerResultNotes' class='detail'>" . implode('<br />', $notes) . "</p>";
|
||||||
}
|
}
|
||||||
if($this->wire('config')->debug) {
|
if($this->wire('config')->debug) {
|
||||||
$out .= "<p id='ProcessListerSelector' class='notes'>" . $this->wire('sanitizer')->entities($this->finalSelector) . "</p>";
|
$out .= "<p id='ProcessListerSelector' class='notes'>";
|
||||||
|
if($this->finalSelectorParsed && $this->finalSelector != $this->finalSelectorParsed) {
|
||||||
|
// selector was modified after being parsed by PageFinder
|
||||||
|
$out .=
|
||||||
|
"<strong>1:</strong> " . $sanitizer->entities($this->finalSelector) . "<br />" .
|
||||||
|
"<strong>2:</strong> " . $sanitizer->entities($this->finalSelectorParsed);
|
||||||
|
} else {
|
||||||
|
$out .= $sanitizer->entities($this->finalSelector);
|
||||||
|
}
|
||||||
|
$out .= "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->editOption) {
|
if(!$this->editOption) {
|
||||||
|
Reference in New Issue
Block a user