mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 16:54:44 +02:00
Various minor updates and code improvements
This commit is contained in:
@@ -1054,7 +1054,10 @@ class PagesLoader extends Wire {
|
||||
$idCnt = count($ids); // idCnt contains quantity of remaining page ids to load
|
||||
if(!$idCnt) {
|
||||
// if there are no more pages left to load, we can return what we've got
|
||||
if($options['getOne']) return count($loaded) ? reset($loaded) : $this->pages->newNullPage();
|
||||
if($options['getOne']) {
|
||||
$page = count($loaded) ? reset($loaded) : null;
|
||||
return $page instanceof Page ? $page : $this->pages->newNullPage();
|
||||
}
|
||||
$pages = $this->pages->newPageArray($options);
|
||||
$pages->setDuplicateChecking(false);
|
||||
$pages->import($loaded);
|
||||
@@ -1230,7 +1233,8 @@ class PagesLoader extends Wire {
|
||||
|
||||
if($options['getOne']) {
|
||||
if(!$loading) $this->loading = false;
|
||||
return count($loaded) ? reset($loaded) : $this->pages->newNullPage();
|
||||
$page = count($loaded) ? reset($loaded) : null;
|
||||
return $page instanceof Page ? $page : $this->pages->newNullPage();
|
||||
}
|
||||
|
||||
$pages = $this->pages->newPageArray($options);
|
||||
|
@@ -199,15 +199,15 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
|
||||
$validTemplate = $this->hasValidTemplate($page);
|
||||
if(!$validTemplate && count($this->templates)) {
|
||||
$validTemplates = implode(', ', array_keys($this->templates));
|
||||
$this->error("Page $page->path must have template: $validTemplates");
|
||||
// $validTemplates = implode(', ', array_keys($this->templates));
|
||||
// $this->error("Page $page->path ($page->template) must have template: $validTemplates");
|
||||
return false;
|
||||
}
|
||||
|
||||
$validParent = $this->hasValidParent($page);
|
||||
if(!$validParent && count($this->parents)) {
|
||||
$validParents = implode(', ', $this->parents);
|
||||
$this->error("Page $page->path must have parent: $validParents");
|
||||
// $validParents = implode(', ', $this->parents);
|
||||
// $this->error("Page $page->path must have parent: $validParents");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,14 @@ class Users extends PagesType {
|
||||
*/
|
||||
protected $guestUser = null;
|
||||
|
||||
/**
|
||||
* Cached guest role id
|
||||
*
|
||||
* @var int|null
|
||||
*
|
||||
*/
|
||||
protected $guestRoleId = 0;
|
||||
|
||||
/**
|
||||
* Validated custom page class cache for getPageClass method
|
||||
*
|
||||
@@ -54,6 +62,7 @@ class Users extends PagesType {
|
||||
public function __construct(ProcessWire $wire, $templates = array(), $parents = array()) {
|
||||
parent::__construct($wire, $templates, $parents);
|
||||
$this->setPageClass('User');
|
||||
$this->guestRoleId = (int) $wire->config->guestUserRolePageID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +70,7 @@ class Users extends PagesType {
|
||||
*
|
||||
* @param string $selectorString
|
||||
* @return Page|NullPage|null
|
||||
*
|
||||
*/
|
||||
public function get($selectorString) {
|
||||
$user = parent::get($selectorString);
|
||||
@@ -74,22 +84,7 @@ class Users extends PagesType {
|
||||
*
|
||||
*/
|
||||
public function setCurrentUser(User $user) {
|
||||
|
||||
$hasGuest = false;
|
||||
$guestRoleID = $this->wire('config')->guestUserRolePageID;
|
||||
|
||||
if($user->roles) foreach($user->roles as $role) {
|
||||
if($role->id == $guestRoleID) {
|
||||
$hasGuest = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$hasGuest && $user->roles) {
|
||||
$guestRole = $this->wire('roles')->getGuestRole();
|
||||
$user->roles->add($guestRole);
|
||||
}
|
||||
|
||||
$this->checkGuestRole($user);
|
||||
$this->currentUser = $user;
|
||||
$this->wire('user', $user);
|
||||
}
|
||||
@@ -101,10 +96,28 @@ class Users extends PagesType {
|
||||
*
|
||||
*/
|
||||
protected function loaded(Page $page) {
|
||||
static $guestID = null;
|
||||
if(is_null($guestID)) $guestID = $this->wire('config')->guestUserRolePageID;
|
||||
$roles = $page->get('roles');
|
||||
if(!$roles->has("id=$guestID")) $page->get('roles')->add($this->wire('roles')->getGuestRole());
|
||||
if($page instanceof User) $this->checkGuestRole($page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that given user has guest role and add it if not
|
||||
*
|
||||
* @param User $user
|
||||
* @since 3.0.198
|
||||
*
|
||||
*/
|
||||
protected function checkGuestRole(User $user) {
|
||||
$hasGuestRole = false;
|
||||
$userRoles = $user->roles;
|
||||
if(!$userRoles) return;
|
||||
foreach($userRoles as $role) {
|
||||
if($role->id != $this->guestRoleId) continue;
|
||||
$hasGuestRole = true;
|
||||
break;
|
||||
}
|
||||
if(!$hasGuestRole) {
|
||||
$user->addRole($this->wire()->roles->getGuestRole());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +139,7 @@ class Users extends PagesType {
|
||||
*/
|
||||
public function getGuestUser() {
|
||||
if($this->guestUser) return $this->guestUser;
|
||||
$this->guestUser = $this->get($this->config->guestUserPageID);
|
||||
$this->guestUser = $this->get($this->wire()->config->guestUserPageID);
|
||||
if(defined("PROCESSWIRE_UPGRADE") && !$this->guestUser || !$this->guestUser->id) {
|
||||
$this->guestUser = $this->newUser(); // needed during upgrade
|
||||
}
|
||||
@@ -211,12 +224,9 @@ class Users extends PagesType {
|
||||
*/
|
||||
public function ___saveReady(Page $page) {
|
||||
/** @var User $user */
|
||||
$user = $page;
|
||||
if(!$user->id && $user instanceof User) {
|
||||
// add guest role if user doesn't already have it
|
||||
$role = $this->wire('roles')->get($this->wire('config')->guestUserRolePageID);
|
||||
if($role->id && !$user->hasRole($role)) $user->addRole($role);
|
||||
}
|
||||
$user = $page;
|
||||
// add guest role if user doesn't already have it
|
||||
if(!$user->id && $user instanceof User) $this->checkGuestRole($user);
|
||||
return parent::___saveReady($user);
|
||||
}
|
||||
|
||||
|
@@ -344,14 +344,15 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
public function init() {
|
||||
if(!$this->wire('page')) return;
|
||||
|
||||
/** @var WireInput $input */
|
||||
$input = $this->wire('input');
|
||||
$input = $this->wire()->input;
|
||||
$config = $this->wire()->config;
|
||||
$config->admin = true;
|
||||
|
||||
$this->checkSessionBookmark();
|
||||
|
||||
$columns = $this->sessionGet('columns');
|
||||
if($columns) $this->columns = $columns;
|
||||
$ajax = $this->wire('config')->ajax;
|
||||
$ajax = $config->ajax;
|
||||
|
||||
$this->renderResults = $ajax && $input->post('render_results') > 0;
|
||||
|
||||
@@ -1927,8 +1928,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function ___renderResults($selector = null) {
|
||||
|
||||
/** @var Sanitizer $sanitizer */
|
||||
$sanitizer = $this->wire('sanitizer');
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
|
||||
if(is_null($selector)) $selector = $this->getSelector();
|
||||
if(!count($this->columns)) $this->columns = $this->defaultColumns;
|
||||
@@ -1948,7 +1948,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
$headline = sprintf($this->_('%1$d to %2$d of %3$d'), $start+1, $end, $total);
|
||||
if($total > $limit) {
|
||||
/** @var MarkupPagerNav $pager */
|
||||
$pager = $this->modules->get('MarkupPagerNav');
|
||||
$pager = $this->wire()->modules->get('MarkupPagerNav');
|
||||
$pagerOut = $pager->render($results);
|
||||
$pageURL = $this->wire('page')->url;
|
||||
$pagerOut = str_replace($pageURL . "'", $pageURL . "?pageNum=1'", $pagerOut); // specifically identify page1
|
||||
@@ -2059,7 +2059,9 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function ___execute() {
|
||||
if(!$this->wire('page')) return '';
|
||||
$modules = $this->wire('modules');
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$input = $this->wire()->input;
|
||||
|
||||
$this->setupOpenPageIDs();
|
||||
|
||||
@@ -2073,7 +2075,7 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
return $out;
|
||||
}
|
||||
|
||||
if($this->wire('input')->get('reset')) {
|
||||
if($input->get('reset')) {
|
||||
return $this->executeReset();
|
||||
}
|
||||
|
||||
@@ -2082,15 +2084,19 @@ class ProcessPageLister extends Process implements ConfigurableModule {
|
||||
|
||||
$modules->get('JqueryWireTabs');
|
||||
$modules->get('MarkupAdminDataTable'); // to ensure css/js load
|
||||
$modules->get('JqueryTableSorter')->use('widgets');
|
||||
|
||||
$jQueryTableSorter = $modules->get('JqueryTableSorter'); /** @var JqueryTableSorter $jQueryTableSorter */
|
||||
$jQueryTableSorter->use('widgets');
|
||||
|
||||
$modules->get('JqueryMagnific');
|
||||
|
||||
if($this->wire('input')->get('modal') == 'inline') {
|
||||
$modules->get('JqueryCore')->use('iframe-resizer-frame');
|
||||
if($input->get('modal') == 'inline') {
|
||||
$jQueryCore = $modules->get('JqueryCore'); /** @var JqueryCore $jQueryCore */
|
||||
$jQueryCore->use('iframe-resizer-frame');
|
||||
}
|
||||
|
||||
$out = '';
|
||||
if(!$this->wire('input')->get('minimal')) {
|
||||
if(!$input->get('minimal')) {
|
||||
$out .= $this->buildFiltersForm()->render();
|
||||
if(!in_array('disableColumns', $this->toggles)) {
|
||||
$out .= $this->buildColumnsForm()->render();
|
||||
|
Reference in New Issue
Block a user