mirror of
https://github.com/processwire/processwire.git
synced 2025-08-20 13:31:48 +02:00
Minor code improvements in various classes, mostly phpdoc related
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* Optional GET variables:
|
||||
@@ -36,8 +36,8 @@ class ProcessPageClone extends Process {
|
||||
'title' => 'Clone',
|
||||
'parent' => 'page',
|
||||
'status' => Page::statusHidden,
|
||||
)
|
||||
);
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class ProcessPageClone extends Process {
|
||||
*
|
||||
*/
|
||||
public function ready() {
|
||||
$this->adminUrl = $this->wire('config')->urls->admin;
|
||||
$this->adminUrl = $this->wire()->config->urls->admin;
|
||||
$this->pageListActionLabel = $this->_('Copy'); // Action label that appears in PageList
|
||||
$this->addHookAfter("ProcessPageListActions::getExtraActions", $this, 'hookPageListActions');
|
||||
$this->addHookAfter("ProcessPageListActions::processAction", $this, 'hookProcessExtraAction');
|
||||
@@ -119,14 +119,15 @@ class ProcessPageClone extends Process {
|
||||
*
|
||||
*/
|
||||
public function ___execute() {
|
||||
$input = $this->wire()->input;
|
||||
$this->headline($this->_('Copy Page')); // Headline
|
||||
$error = $this->_("Unable to load page");
|
||||
$id = (int) $this->wire('input')->get('id');
|
||||
if(!$id) throw new WireException($error);
|
||||
$this->page = $this->wire('pages')->get($id);
|
||||
$id = (int) $input->get('id');
|
||||
if($id < 2) throw new WireException($error);
|
||||
$this->page = $this->wire()->pages->get($id);
|
||||
if($this->page->id < 2) throw new WireException($error);
|
||||
if(!$this->hasPermission($this->page)) throw new WirePermissionException($error);
|
||||
if($this->wire('input')->post('submit_clone')) $this->process();
|
||||
if($input->post('submit_clone')) $this->process();
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
@@ -165,8 +166,7 @@ class ProcessPageClone extends Process {
|
||||
*/
|
||||
protected function getSuggestedNameAndTitle(Page $page) {
|
||||
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->wire('pages');
|
||||
$pages = $this->wire()->pages;
|
||||
|
||||
$name = $pages->names()->uniquePageName(array(
|
||||
'name' => $page->name,
|
||||
@@ -194,6 +194,7 @@ class ProcessPageClone extends Process {
|
||||
$languages = $this->wire()->languages;
|
||||
if($languages && $languages->hasPageNames()) {
|
||||
foreach($languages as $language) {
|
||||
/** @var Language $language */
|
||||
if($language->isDefault()) continue;
|
||||
$value = $page->get("name$language");
|
||||
if(!strlen($value)) continue;
|
||||
@@ -212,11 +213,11 @@ class ProcessPageClone extends Process {
|
||||
*/
|
||||
protected function ___buildForm() {
|
||||
|
||||
/** @var Page $page */
|
||||
$page = $this->page;
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form = $modules->get("InputfieldForm");
|
||||
$form->attr('action', './?id=' . $page->id);
|
||||
$form->attr('method', 'post');
|
||||
$form->description = sprintf($this->_("This will make a copy of %s"), $page->path); // Form description/headline
|
||||
@@ -225,23 +226,22 @@ class ProcessPageClone extends Process {
|
||||
$suggested = $this->getSuggestedNameAndTitle($page);
|
||||
|
||||
/** @var InputfieldPageTitle $titleField */
|
||||
$titleField = $this->modules->get("InputfieldPageTitle");
|
||||
$titleField = $modules->get("InputfieldPageTitle");
|
||||
$titleField->attr('name', 'clone_page_title');
|
||||
$titleField->attr('value', $suggested['title']);
|
||||
$titleField->label = $this->_("Title of new page"); // Label for title field
|
||||
|
||||
/** @var InputfieldPageName $nameField */
|
||||
$nameField = $this->modules->get("InputfieldPageName");
|
||||
$nameField = $modules->get("InputfieldPageName");
|
||||
$nameField->attr('name', 'clone_page_name');
|
||||
$nameField->attr('value', $suggested['name']);
|
||||
$nameField->parentPage = $page->parent;
|
||||
|
||||
/** @var Languages $languages */
|
||||
$languages = $this->wire('languages');
|
||||
$languages = $this->wire()->languages;
|
||||
$useLanguages = $languages;
|
||||
if($useLanguages) {
|
||||
/** @var Field $title */
|
||||
$title = $this->wire('fields')->get('title');
|
||||
$title = $this->wire()->fields->get('title');
|
||||
$titleUseLanguages = $title
|
||||
&& $page->template->fieldgroup->hasField($title)
|
||||
&& $title->getInputfield($page)->getSetting('useLanguages');
|
||||
@@ -249,6 +249,7 @@ class ProcessPageClone extends Process {
|
||||
if($titleUseLanguages) $titleField->useLanguages = true;
|
||||
if($nameUseLanguages) $nameField->useLanguages = true;
|
||||
foreach($languages as $language) {
|
||||
/** @var Language $language */
|
||||
if($language->isDefault()) continue;
|
||||
if($titleUseLanguages) {
|
||||
/** @var LanguagesPageFieldValue $pageTitle */
|
||||
@@ -274,7 +275,7 @@ class ProcessPageClone extends Process {
|
||||
$form->add($nameField);
|
||||
|
||||
/** @var InputfieldCheckbox $field */
|
||||
$field = $this->modules->get("InputfieldCheckbox");
|
||||
$field = $modules->get("InputfieldCheckbox");
|
||||
$field->attr('name', 'clone_page_unpublished');
|
||||
$field->attr('value', 1);
|
||||
$field->label = $this->_("Make the new page unpublished?");
|
||||
@@ -284,7 +285,7 @@ class ProcessPageClone extends Process {
|
||||
|
||||
if($page->numChildren && $this->user->hasPermission('page-clone-tree', $page)) {
|
||||
/** @var InputfieldCheckbox $field */
|
||||
$field = $this->modules->get("InputfieldCheckbox");
|
||||
$field = $modules->get("InputfieldCheckbox");
|
||||
$field->attr('name', 'clone_page_tree');
|
||||
$field->attr('value', 1);
|
||||
$field->label = $this->_("Copy children too?");
|
||||
@@ -295,14 +296,14 @@ class ProcessPageClone extends Process {
|
||||
}
|
||||
|
||||
/** @var InputfieldSubmit $field */
|
||||
$field = $this->modules->get("InputfieldSubmit");
|
||||
$field = $modules->get("InputfieldSubmit");
|
||||
$field->attr('name', 'submit_clone');
|
||||
$form->add($field);
|
||||
|
||||
$redirectPageID = (int) $this->wire('input')->get('redirect_page');
|
||||
$redirectPageID = (int) $this->wire()->input->get('redirect_page');
|
||||
if($redirectPageID) {
|
||||
/** @var InputfieldHidden $field */
|
||||
$field = $this->wire('modules')->get('InputfieldHidden');
|
||||
$field = $modules->get('InputfieldHidden');
|
||||
$field->attr('name', 'redirect_page');
|
||||
$field->attr('value', $redirectPageID);
|
||||
$form->add($field);
|
||||
@@ -330,6 +331,7 @@ class ProcessPageClone extends Process {
|
||||
|
||||
$page = clone $this->page;
|
||||
$input = $this->input;
|
||||
$languages = $this->wire()->languages;
|
||||
$originalName = $page->name;
|
||||
|
||||
$this->session->CSRF->validate();
|
||||
@@ -344,8 +346,9 @@ class ProcessPageClone extends Process {
|
||||
$page->addStatus(Page::statusUnpublished);
|
||||
}
|
||||
|
||||
if($nameField->useLanguages) {
|
||||
foreach($this->wire('languages') as $language) {
|
||||
if($nameField->useLanguages && $languages) {
|
||||
foreach($languages as $language) {
|
||||
/** @var Language $language */
|
||||
$valueAttr = $language->isDefault() ? "value" : "value$language->id";
|
||||
$nameAttr = $language->isDefault() ? "name" : "name$language->id";
|
||||
$value = $nameField->get($valueAttr);
|
||||
@@ -363,8 +366,9 @@ class ProcessPageClone extends Process {
|
||||
throw new WireException(sprintf($this->_("Unable to clone page %s"), $page->path));
|
||||
}
|
||||
|
||||
if($titleField->getSetting('useLanguages') && is_object($clone->title)) {
|
||||
foreach($this->wire('languages') as $language) {
|
||||
if($titleField->getSetting('useLanguages') && is_object($clone->title) && $languages) {
|
||||
foreach($languages as $language) {
|
||||
/** @var Language $language */
|
||||
$valueAttr = $language->isDefault() ? "value" : "value$language->id";
|
||||
$value = $titleField->get($valueAttr);
|
||||
/** @var LanguagesPageFieldValue $cloneTitle */
|
||||
@@ -375,7 +379,7 @@ class ProcessPageClone extends Process {
|
||||
$clone->title = $titleField->value;
|
||||
}
|
||||
|
||||
$this->wire('pages')->save($clone, array('adjustName' => true));
|
||||
$this->wire()->pages->save($clone, array('adjustName' => true));
|
||||
|
||||
$this->message(sprintf($this->_('Cloned page "%1$s" to "%2$s"'), $originalName, $clone->name));
|
||||
|
||||
@@ -383,7 +387,7 @@ class ProcessPageClone extends Process {
|
||||
$redirectID = (int) $input->post('redirect_page');
|
||||
|
||||
if($redirectID) {
|
||||
$redirectPage = $this->wire('pages')->get($redirectID);
|
||||
$redirectPage = $this->wire()->pages->get($redirectID);
|
||||
if($redirectPage->viewable()) {
|
||||
$redirectURL = $redirectPage->url();
|
||||
}
|
||||
@@ -427,7 +431,7 @@ class ProcessPageClone extends Process {
|
||||
);
|
||||
|
||||
if($clone->id) {
|
||||
$result['message'] = $this->wire('sanitizer')->unentities(
|
||||
$result['message'] = $this->wire()->sanitizer->unentities(
|
||||
sprintf($this->_('Cloned to: %s'), $clone->path)
|
||||
);
|
||||
} else {
|
||||
@@ -468,8 +472,10 @@ class ProcessPageClone extends Process {
|
||||
)
|
||||
);
|
||||
|
||||
if($this->wire('languages')) {
|
||||
foreach($this->wire('languages') as $language) {
|
||||
$languages = $this->wire()->languages;
|
||||
if($languages) {
|
||||
foreach($languages as $language) {
|
||||
/** @var Language $language */
|
||||
if($language->isDefault()) continue;
|
||||
if(!empty($suggested["name$language"])) {
|
||||
$cloneOptions['set']["name$language"] = $suggested["name$language"];
|
||||
@@ -480,7 +486,7 @@ class ProcessPageClone extends Process {
|
||||
$cloneTree = false; // clone tree mode not allowed in ajax mode
|
||||
|
||||
try {
|
||||
$clone = $this->wire('pages')->clone($page, $page->parent, $cloneTree, $cloneOptions);
|
||||
$clone = $this->wire()->pages->clone($page, $page->parent, $cloneTree, $cloneOptions);
|
||||
} catch(\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
$clone = new NullPage();
|
||||
|
@@ -22,10 +22,11 @@ class PageBookmarks extends Wire {
|
||||
protected $labels = array();
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
* @param Process|ProcessPageEdit $process
|
||||
*
|
||||
*/
|
||||
public function __construct(Process $process) {
|
||||
parent::__construct();
|
||||
$this->process = $process;
|
||||
$this->labels = array(
|
||||
'bookmarks' => $this->_('Bookmarks'),
|
||||
@@ -42,19 +43,23 @@ class PageBookmarks extends Wire {
|
||||
*
|
||||
*/
|
||||
public function initNavJSON(array $options = array()) {
|
||||
|
||||
$pages = $this->wire()->pages;
|
||||
$user = $this->wire()->user;
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
$bookmarkFields = array();
|
||||
$bookmarksArray = array();
|
||||
$rolesArray = array();
|
||||
$data = $this->wire('modules')->getModuleConfigData($this->process);
|
||||
$data = $modules->getModuleConfigData($this->process);
|
||||
$iconKey = isset($options['iconKey']) ? $options['iconKey'] : '_icon';
|
||||
$classKey = isset($options['classKey']) ? $options['classKey'] : '_class';
|
||||
$options['classKey'] = $classKey;
|
||||
$options['iconKey'] = $iconKey;
|
||||
if(!isset($options['defaultIcon'])) $options['defaultIcon'] = 'arrow-circle-right';
|
||||
|
||||
foreach($this->wire('user')->roles as $role) {
|
||||
if($role->name == 'guest') continue;
|
||||
foreach($this->wire()->user->roles as $role) {
|
||||
if($role->name === 'guest') continue;
|
||||
$value = isset($data["bookmarks"]["_$role->id"]) ? $data["bookmarks"]["_$role->id"] : array();
|
||||
if(empty($value)) continue;
|
||||
$bookmarkFields[$role->name] = $value;
|
||||
@@ -64,7 +69,7 @@ class PageBookmarks extends Wire {
|
||||
|
||||
$n = 0;
|
||||
foreach($bookmarkFields as $name => $bookmarkIDs) {
|
||||
$bookmarks = count($bookmarkIDs) ? $this->wire('pages')->getById($bookmarkIDs) : array();
|
||||
$bookmarks = count($bookmarkIDs) ? $pages->getById($bookmarkIDs) : array();
|
||||
$role = isset($rolesArray[$name]) ? $rolesArray[$name] : null;
|
||||
foreach($bookmarks as $page) {
|
||||
if($this->process == 'ProcessPageEdit' && !$page->editable()) continue;
|
||||
@@ -81,14 +86,14 @@ class PageBookmarks extends Wire {
|
||||
}
|
||||
|
||||
if(empty($options['add'])) {
|
||||
if($this->wire('user')->isSuperuser()) {
|
||||
if($user->isSuperuser()) {
|
||||
$options['add'] = 'bookmarks/?role=0';
|
||||
$options['addLabel'] = $this->labels['bookmarks'];
|
||||
$options['addIcon'] = 'bookmark-o';
|
||||
} else {
|
||||
$options['add'] = null;
|
||||
}
|
||||
} else if($this->wire('user')->isSuperuser()) {
|
||||
} else if($user->isSuperuser()) {
|
||||
$add = $this->wire(new WireData());
|
||||
$add->set('_icon', 'bookmark-o');
|
||||
$add->set('title', $this->labels['bookmarks']);
|
||||
@@ -108,7 +113,7 @@ class PageBookmarks extends Wire {
|
||||
if(!isset($options['iconKey'])) $options['iconKey'] = '_icon';
|
||||
|
||||
if(empty($options['edit'])) {
|
||||
$options['edit'] = $this->wire('config')->urls->admin . 'page/edit/?id={id}';
|
||||
$options['edit'] = $this->wire()->config->urls->admin . 'page/edit/?id={id}';
|
||||
}
|
||||
|
||||
return $options;
|
||||
@@ -121,10 +126,11 @@ class PageBookmarks extends Wire {
|
||||
*
|
||||
*/
|
||||
public function listBookmarks() {
|
||||
|
||||
$config = $this->wire('config');
|
||||
$config->styles->add($config->urls->ProcessPageEdit . 'PageBookmarks.css');
|
||||
$superuser = $this->wire('user')->isSuperuser();
|
||||
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$config = $this->wire()->config;
|
||||
$config->styles->add($config->urls('ProcessPageEdit') . 'PageBookmarks.css');
|
||||
$superuser = $this->wire()->user->isSuperuser();
|
||||
$out = '';
|
||||
$options = $this->initNavJSON();
|
||||
$noneHeadline = $this->_('There are currently no bookmarks defined');
|
||||
@@ -136,7 +142,7 @@ class PageBookmarks extends Wire {
|
||||
$icon = $item->_icon ? "<i class='fa fa-fw fa-$item->_icon'></i> " : "";
|
||||
$out .=
|
||||
"<li class='$item->_class'>" .
|
||||
"<a href='$url'>$icon" . $this->wire('sanitizer')->entities1($item->get('title|name')) . "</a>" .
|
||||
"<a href='$url'>$icon" . $sanitizer->entities1($item->get('title|name')) . "</a>" .
|
||||
"</li>";
|
||||
}
|
||||
|
||||
@@ -148,7 +154,8 @@ class PageBookmarks extends Wire {
|
||||
}
|
||||
|
||||
if($superuser) {
|
||||
$button = $this->wire('modules')->get('InputfieldButton');
|
||||
/** @var InputfieldButton $button */
|
||||
$button = $this->wire()->modules->get('InputfieldButton');
|
||||
$button->href = "./?role=0";
|
||||
$button->value = $this->labels['edit-bookmarks'];
|
||||
$button->icon = 'edit';
|
||||
@@ -168,17 +175,20 @@ class PageBookmarks extends Wire {
|
||||
*/
|
||||
public function editBookmarksForm() {
|
||||
|
||||
$modules = $this->wire('modules');
|
||||
$roleID = $this->wire('input')->get('role');
|
||||
if(is_null($roleID) && $this->wire('input')->get('id') == 'bookmarks') $roleID = 0;
|
||||
$modules = $this->wire()->modules;
|
||||
$input = $this->wire()->input;
|
||||
$roles = $this->wire()->roles;
|
||||
|
||||
$roleID = $input->get('role');
|
||||
if(is_null($roleID) && $input->get('id') === 'bookmarks') $roleID = 0;
|
||||
$roleID = (int) $roleID;
|
||||
|
||||
if(!$this->wire('user')->isSuperuser()) throw new WirePermissionException("Superuser required to define bookmarks");
|
||||
if(!$this->wire()->user->isSuperuser()) throw new WirePermissionException("Superuser required to define bookmarks");
|
||||
$moduleInfo = $modules->getModuleInfo($this->process);
|
||||
$this->process->breadcrumb('../', $this->_($moduleInfo['title']));
|
||||
$this->process->breadcrumb('./', $this->labels['bookmarks']);
|
||||
|
||||
$role = $roleID ? $this->wire('roles')->get($roleID) : $this->wire('pages')->newNullPage();
|
||||
$role = $roleID ? $roles->get($roleID) : $this->wire()->pages->newNullPage();
|
||||
if($roleID && !$role->id) throw new WireException("Unknown role");
|
||||
$allLabel = $this->_('everyone'); // All roles
|
||||
$data = $modules->getModuleConfigData($this->process);
|
||||
@@ -188,6 +198,7 @@ class PageBookmarks extends Wire {
|
||||
$this->process->headline($headline);
|
||||
$this->process->browserTitle($title);
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $modules->get('InputfieldForm');
|
||||
$form->action = "./?role=$role->id";
|
||||
$form->addClass('InputfieldFormConfirm');
|
||||
@@ -195,6 +206,7 @@ class PageBookmarks extends Wire {
|
||||
$form->appendMarkup = "<p style='clear:both' class='detail'><br /><i class='fa fa-info-circle ui-priority-secondary'></i> " .
|
||||
$this->_('Note that only superusers are able to see this editor.') . "</p>";
|
||||
|
||||
/** @var InputfieldPageListSelectMultiple $field */
|
||||
$field = $modules->get('InputfieldPageListSelectMultiple');
|
||||
$field->attr('name', 'bookmarks');
|
||||
$field->label = $title;
|
||||
@@ -205,8 +217,8 @@ class PageBookmarks extends Wire {
|
||||
$class = $role->id ? '' : 'ui-state-disabled';
|
||||
$out = "<ul class='PageListActions actions'><li><a class='$class' href='./?role=0'>$allLabel</a></li>";
|
||||
|
||||
foreach($this->wire('roles') as $r) {
|
||||
if($r->name == 'guest') continue;
|
||||
foreach($roles as $r) {
|
||||
if($r->name === 'guest') continue;
|
||||
$class = $r->id == $role->id ? 'ui-state-disabled' : '';
|
||||
$o = "<a class='$class' href='./?role=$r->id'>$r->name</a>";
|
||||
$out .= "<li>$o</li>";
|
||||
@@ -221,20 +233,21 @@ class PageBookmarks extends Wire {
|
||||
$field->attr('value', $value);
|
||||
$form->add($field);
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $modules->get('InputfieldSubmit');
|
||||
$submit->attr('name', 'submit_save_bookmarks');
|
||||
$submit->showInHeader();
|
||||
$form->add($submit);
|
||||
|
||||
if($this->wire('input')->post('submit_save_bookmarks')) {
|
||||
if($form->isSubmitted('submit_save_bookmarks')) {
|
||||
// save bookmarks
|
||||
$form->processInput($this->wire('input')->post);
|
||||
$form->process();
|
||||
$bookmarks = $field->attr('value');
|
||||
// clear out bookmarks for roles that no longer exist
|
||||
foreach($data["bookmarks"] as $_roleID => $_bookmarks) {
|
||||
foreach($data['bookmarks'] as $_roleID => $_bookmarks) {
|
||||
if($_roleID == "_0") continue;
|
||||
$r = $this->wire('roles')->get((int) ltrim($_roleID, '_'));
|
||||
if(!$r->id) unset($data["bookmarks"][$_roleID]);
|
||||
$r = $roles->get((int) ltrim($_roleID, '_'));
|
||||
if(!$r->id) unset($data['bookmarks'][$_roleID]);
|
||||
}
|
||||
// update bookmarks for role
|
||||
$data["bookmarks"]["_$role->id"] = $bookmarks;
|
||||
@@ -242,7 +255,7 @@ class PageBookmarks extends Wire {
|
||||
$modules->saveModuleConfigData($this->process, $data);
|
||||
|
||||
$this->message($this->_('Saved bookmarks'));
|
||||
$this->wire('session')->redirect("./?role=$role->id");
|
||||
$this->wire()->session->location("./?role=$role->id");
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -256,9 +269,10 @@ class PageBookmarks extends Wire {
|
||||
*
|
||||
*/
|
||||
public function editBookmarks() {
|
||||
$roleID = $this->wire('input')->get('role');
|
||||
$input = $this->wire()->input;
|
||||
$roleID = $input->get('role');
|
||||
if(is_null($roleID)) {
|
||||
if($this->wire('input')->get('id') == 'bookmarks') {
|
||||
if($input->get('id') === 'bookmarks') {
|
||||
// ok
|
||||
} else {
|
||||
return $this->listBookmarks();
|
||||
@@ -293,7 +307,8 @@ class PageBookmarks extends Wire {
|
||||
*
|
||||
*/
|
||||
public function addConfigInputfields(InputfieldWrapper $inputfields) {
|
||||
$field = $this->wire('modules')->get('InputfieldCheckbox');
|
||||
/** @var InputfieldCheckbox $field */
|
||||
$field = $this->wire()->modules->get('InputfieldCheckbox');
|
||||
$field->attr('name', 'useBookmarks');
|
||||
$field->label = $this->_('Allow use of bookmarks?');
|
||||
$field->description = $this->_('Bookmarks enable you to create shortcuts to pages from this module, configurable by user role. Useful for large applications.');
|
||||
|
@@ -176,7 +176,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
if(!$this->wire('page')) return;
|
||||
if(!$this->wire()->page) return;
|
||||
|
||||
$this->defaultColumns = array('title', 'template', 'parent', 'modified', 'modified_users_id');
|
||||
|
||||
@@ -343,7 +343,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function init() {
|
||||
if(!$this->wire('page')) return;
|
||||
if(!$this->wire()->page) return;
|
||||
|
||||
$input = $this->wire()->input;
|
||||
$config = $this->wire()->config;
|
||||
@@ -614,12 +614,16 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
$filters = $input->post('filters');
|
||||
if($filters !== null && $filters !== 'ignore') {
|
||||
$is = $this->getInputfieldSelector();
|
||||
$is->processInput($input->post);
|
||||
$selector = $this->sessionGet("selector");
|
||||
if($selector != $is->value) {
|
||||
$this->sessionSet("selector", $is->value);
|
||||
$this->sessionSet("pageNum", 1);
|
||||
$input->setPageNum(1);
|
||||
try {
|
||||
$is->processInput($input->post);
|
||||
$selector = $this->sessionGet("selector");
|
||||
if($selector != $is->value) {
|
||||
$this->sessionSet("selector", $is->value);
|
||||
$this->sessionSet("pageNum", 1);
|
||||
$input->setPageNum(1);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1209,6 +1213,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
$template = explode('|', $matches[1]);
|
||||
$templatesAPI = $this->wire()->templates;
|
||||
foreach($template as $t) {
|
||||
/** @var Template $t */
|
||||
$t = $templatesAPI->get($t);
|
||||
if($t instanceof Template) $templates[] = $t;
|
||||
}
|
||||
@@ -1429,7 +1434,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
$noEntities = false;
|
||||
$language = $languages ? $this->identifyLanguage($name, true) : null;
|
||||
|
||||
if($language && $language->id == $this->wire('user')->language->id) $language = null;
|
||||
if($language && $language->id == $this->wire()->user->language->id) $language = null;
|
||||
if($language) $languages->setLanguage($language);
|
||||
|
||||
if(strpos($name, '.')) list($name, $subname) = explode('.', $name, 2);
|
||||
@@ -1538,7 +1543,9 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
$vfull = $v;
|
||||
if($this->imageWidth || $this->imageHeight) $v = $v->size($this->imageWidth, $this->imageHeight);
|
||||
$alt = $vfull->basename . ($vfull->description ? ' - ' . $sanitizer->entities1($vfull->description) : "");
|
||||
$v = "<a href='$vfull->URL' title='$alt' class='lister-lightbox'><img alt='$alt' src='$v->URL' style='margin: 4px 4px 4px 0' /></a>";
|
||||
$v =
|
||||
"<a href='$vfull->URL' title='$alt' class='lister-lightbox'>" .
|
||||
"<img alt='$alt' src='$v->URL' style='margin: 4px 4px 4px 0' /></a>";
|
||||
$isImage = true;
|
||||
|
||||
} else if($v instanceof Pagefile) {
|
||||
@@ -1990,10 +1997,15 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
|
||||
foreach($this->wire()->notices as $notice) {
|
||||
/** @var Notice $notice */
|
||||
$noticeText = $notice->text;
|
||||
if(!($notice->flags & Notice::allowMarkup)) {
|
||||
$noticeText = $sanitizer->entities1($notice->text);
|
||||
}
|
||||
if($notice instanceof NoticeError) {
|
||||
$out .= "<p class='ui-state-error-text'>$notice->text</p>";
|
||||
$out .= "<p class='ui-state-error-text'>$noticeText</p>";
|
||||
} else {
|
||||
if(self::debug) $out .= "<p class='ui-state-highlight'>$notice->text</p>";
|
||||
// report non-error notifications only when debug constant active
|
||||
if(self::debug) $out .= "<p class='ui-state-highlight'>$noticeText</p>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2045,9 +2057,9 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
$this->resetLister();
|
||||
$this->message($this->_('All settings have been reset.'));
|
||||
if(strpos($this->wire()->input->urlSegmentStr, '/reset/')) {
|
||||
$this->wire()->session->redirect('../');
|
||||
$this->wire()->session->location('../');
|
||||
} else {
|
||||
$this->wire()->session->redirect('./');
|
||||
$this->wire()->session->location('./');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2094,7 +2106,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function ___execute() {
|
||||
if(!$this->wire('page')) return '';
|
||||
if(!$this->wire()->page) return '';
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$input = $this->wire()->input;
|
||||
@@ -2106,7 +2118,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
if($this->renderResults) {
|
||||
$out = $this->renderResults();
|
||||
if(self::debug) {
|
||||
foreach($this->wire('database')->queryLog() as $n => $item) {
|
||||
foreach($this->wire()->database->queryLog() as $n => $item) {
|
||||
$out .= "<p>$n. $item</p>";
|
||||
}
|
||||
}
|
||||
@@ -2182,7 +2194,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
|
||||
} else if($this->template && ($parent = $this->template->getParentPage(true))) {
|
||||
if($parent->id) {
|
||||
$action = "?parent_id={$parent->id}"; // defined parent
|
||||
$action = "?parent_id=$parent->id"; // defined parent
|
||||
} else {
|
||||
$action = "?template_id={$this->template->id}"; // multiple possible parents
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
@@ -30,7 +30,7 @@ class ProcessPageSort extends Process {
|
||||
'version' => 100,
|
||||
'permanent' => true,
|
||||
'permission' => 'page-edit',
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,23 +49,32 @@ class ProcessPageSort extends Process {
|
||||
*
|
||||
*/
|
||||
public function ___execute() {
|
||||
|
||||
$input = $this->wire()->input;
|
||||
$pages = $this->wire()->pages;
|
||||
$sort = $input->post('sort');
|
||||
|
||||
if($this->config->demo) throw new WireException($this->_("Your change was not saved because this site is in demo mode"));
|
||||
if(!isset($_POST['sort'])) throw new WireException($this->_("This Process is only accessible via POST"));
|
||||
if($this->config->demo) {
|
||||
throw new WireException($this->_("Your change was not saved because this site is in demo mode"));
|
||||
}
|
||||
|
||||
if($sort === null) {
|
||||
throw new WireException($this->_("This Process is only accessible via POST"));
|
||||
}
|
||||
|
||||
$this->session->CSRF->validate(); // throws exception if invalid
|
||||
$input = $this->wire('input');
|
||||
$this->user = $this->wire('user');
|
||||
$this->user = $this->wire()->user;
|
||||
$this->ids = array();
|
||||
$ids = explode(',', $input->post->sort);
|
||||
$ids = explode(',', $sort);
|
||||
foreach($ids as $sort => $id) $this->ids[(int) $sort] = (int) $id;
|
||||
if(!count($this->ids)) return;
|
||||
unset($ids);
|
||||
|
||||
$this->parent_id = (int) $input->post->parent_id;
|
||||
$this->move_id = (int) $input->post->id;
|
||||
$this->parent_id = (int) $input->post('parent_id');
|
||||
$this->move_id = (int) $input->post('id');
|
||||
|
||||
$parentPage = $this->wire('pages')->get($this->parent_id);
|
||||
$movePage = $this->wire('pages')->get($this->move_id);
|
||||
$parentPage = $pages->get($this->parent_id);
|
||||
$movePage = $pages->get($this->move_id);
|
||||
if($movePage->id < 2 || !$parentPage->id) return;
|
||||
|
||||
$this->movePage($movePage, $parentPage);
|
||||
@@ -131,7 +140,7 @@ class ProcessPageSort extends Process {
|
||||
}
|
||||
|
||||
$changes = 0;
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
|
||||
// locate the 'sort' value of the current first sorted item, to use as our starting point
|
||||
// (in case sorting in a pagination other than 1)
|
||||
@@ -166,10 +175,9 @@ class ProcessPageSort extends Process {
|
||||
$page->save();
|
||||
$parent->trackChange('children');
|
||||
$parent->save();
|
||||
$this->wire('pages')->sorted($page, false, $changes);
|
||||
$this->wire()->pages->sorted($page, false, $changes);
|
||||
|
||||
if($changes) $this->message("Updated sort for $changes pages", Notice::log);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ class ProcessPageTrash extends Process {
|
||||
'summary' => __('Handles emptying of Page trash', __FILE__), // getModuleInfo summary
|
||||
'version' => 103,
|
||||
'permanent' => true,
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,8 +34,8 @@ class ProcessPageTrash extends Process {
|
||||
*/
|
||||
public function ___execute() {
|
||||
|
||||
if(!$this->wire('user')->isSuperuser()) throw new WirePermissionException();
|
||||
$input = $this->wire('input');
|
||||
if(!$this->wire()->user->isSuperuser()) throw new WirePermissionException();
|
||||
$input = $this->wire()->input;
|
||||
|
||||
$timeLimit = abs((int) $input->post('time_limit'));
|
||||
if($timeLimit > 0) $this->session->setFor($this, 'timeLimit', $timeLimit);
|
||||
@@ -53,7 +53,7 @@ class ProcessPageTrash extends Process {
|
||||
'timeLimit' => $timeLimit > 0 ? $timeLimit : self::defaultTimeLimit,
|
||||
);
|
||||
|
||||
$result = $this->wire('pages')->emptyTrash($options);
|
||||
$result = $this->wire()->pages->emptyTrash($options);
|
||||
if(self::debug) $this->warning($result);
|
||||
$error = false;
|
||||
|
||||
@@ -73,13 +73,15 @@ class ProcessPageTrash extends Process {
|
||||
$error = true;
|
||||
}
|
||||
|
||||
$session = $this->wire()->session;
|
||||
|
||||
if($error) {
|
||||
$this->session->warning($message);
|
||||
$this->session->redirect('./');
|
||||
$session->warning($message);
|
||||
$session->redirect('./');
|
||||
} else {
|
||||
// redirect to admin root after emptying trash
|
||||
$this->session->message($message);
|
||||
$this->session->redirect($this->wire('config')->urls('admin'));
|
||||
$session->message($message);
|
||||
$session->redirect($this->wire()->config->urls('admin'));
|
||||
}
|
||||
|
||||
return ''; // unreachable due to redirects above
|
||||
@@ -90,19 +92,19 @@ class ProcessPageTrash extends Process {
|
||||
*
|
||||
*/
|
||||
protected function render() {
|
||||
|
||||
// $trashPages = $this->pages->get($this->config->trashPageID)->children("limit=2, status<" . Page::statusMax);
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$trashTotal = $this->pages->trasher()->getTrashTotal();
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form = $modules->get("InputfieldForm");
|
||||
$form->attr('action', './');
|
||||
$form->attr('method', 'post');
|
||||
|
||||
if(!$trashTotal) return "<h2>" . $this->_("The trash is empty") . "</h2>";
|
||||
|
||||
/** @var InputfieldCheckbox $field */
|
||||
$field = $this->modules->get("InputfieldCheckbox");
|
||||
$field = $modules->get("InputfieldCheckbox");
|
||||
$field->attr('name', 'confirm_empty');
|
||||
$field->attr('value', 1);
|
||||
$field->label2 = $this->_('Empty the trash (confirm)');
|
||||
@@ -116,7 +118,7 @@ class ProcessPageTrash extends Process {
|
||||
$form->add($field);
|
||||
|
||||
/** @var InputfieldMarkup $field */
|
||||
$field = $this->modules->get("InputfieldMarkup");
|
||||
$field = $modules->get("InputfieldMarkup");
|
||||
$field->label = $this->_('Pages in the trash');
|
||||
$field->icon = 'list';
|
||||
$field->collapsed = Inputfield::collapsedYes;
|
||||
@@ -128,7 +130,7 @@ class ProcessPageTrash extends Process {
|
||||
$form->add($field);
|
||||
|
||||
/** @var InputfieldInteger $f */
|
||||
$f = $this->modules->get('InputfieldInteger');
|
||||
$f = $modules->get('InputfieldInteger');
|
||||
$f->attr('name', 'time_limit');
|
||||
$f->label = $this->_('Time limit (in seconds)');
|
||||
$timeLimit = (int) $this->session->getFor($this, 'timeLimit');
|
||||
@@ -138,18 +140,18 @@ class ProcessPageTrash extends Process {
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldSubmit $field */
|
||||
$field = $this->modules->get("InputfieldSubmit");
|
||||
$field = $modules->get("InputfieldSubmit");
|
||||
$field->attr('name', 'submit_empty');
|
||||
$field->showInHeader(true);
|
||||
$field->icon = 'trash';
|
||||
$form->add($field);
|
||||
|
||||
/** @var InputfieldSubmit $field */
|
||||
$field = $this->modules->get("InputfieldButton");
|
||||
/** @var InputfieldButton $field */
|
||||
$field = $modules->get("InputfieldButton");
|
||||
$field->attr('name', 'submit_cancel');
|
||||
$field->setSecondary(true);
|
||||
$field->value = $this->_('Cancel');
|
||||
$field->href = $this->wire('config')->urls->admin;
|
||||
$field->href = $this->wire()->config->urls->admin;
|
||||
$field->icon = 'times';
|
||||
$form->add($field);
|
||||
|
||||
|
Reference in New Issue
Block a user