1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 16:54:44 +02:00

Various minor updates

This commit is contained in:
Ryan Cramer
2022-09-02 13:13:08 -04:00
parent 96dae07160
commit a2da7f1a22
8 changed files with 93 additions and 44 deletions

View File

@@ -1242,7 +1242,8 @@ abstract class Inputfield extends WireData implements Module {
*/ */
public function getClassArray($property = 'class', $assoc = false) { public function getClassArray($property = 'class', $assoc = false) {
$property = $this->getClassProperty($property); $property = $this->getClassProperty($property);
$value = trim($property === 'class' ? $this->attr('class') : $this->getSetting($property)); $value = ($property === 'class' ? $this->attr('class') : $this->getSetting($property));
$value = trim("$value");
while(strpos($value, ' ') !== false) $value = str_replace(' ', ' ', $value); while(strpos($value, ' ') !== false) $value = str_replace(' ', ' ', $value);
$classes = strlen($value) ? explode(' ', $value) : array(); $classes = strlen($value) ? explode(' ', $value) : array();
if($assoc) { if($assoc) {

View File

@@ -392,10 +392,25 @@ interface WireDatabase {
interface WirePageEditor { interface WirePageEditor {
/** /**
* @return Page The current page being edited * @return Page The current page being edited
*
*/ */
public function getPage(); public function getPage();
} }
/**
* Interface indicates item stores in a WireArray or type descending from it
*
* @since 3.0.205
*
*/
interface WireArrayItem {
/**
* @return WireArray
*
*/
public function getWireArray();
}
/** /**
* Interface shared by all ProcessWire Null objects * Interface shared by all ProcessWire Null objects
* *

View File

@@ -1423,8 +1423,11 @@ class Modules extends WireArray {
if(empty($options['noPermissionCheck'])) { if(empty($options['noPermissionCheck'])) {
// check that user has permission required to use module // check that user has permission required to use module
if(!$this->hasPermission($module, $this->wire('user'), $this->wire('page'))) { $page = $this->wire()->page;
$error = $this->_('You do not have permission to execute this module') . ' - ' . wireClassName($module); $user = $this->wire()->user;
if(!$this->hasPermission($module, $user, $page)) {
$error = $this->_('You do not have permission to execute this module') . ' - ' .
wireClassName($module) . " (page=$page)";
if(empty($options['noThrow'])) throw new WirePermissionException($error); if(empty($options['noThrow'])) throw new WirePermissionException($error);
return empty($options['returnError']) ? null : $error; return empty($options['returnError']) ? null : $error;
} }

View File

@@ -84,7 +84,7 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
*/ */
public function isValidItem($item) { public function isValidItem($item) {
return is_object($item) && $item instanceof Page; return $item instanceof Page;
} }
/** /**
@@ -123,7 +123,7 @@ class PageArray extends PaginatedArray implements WirePaginatable {
// given item exists in this PageArray (or at least has) // given item exists in this PageArray (or at least has)
$key = $this->keyIndex[$id]; $key = $this->keyIndex[$id];
if(isset($this->data[$key])) { if(isset($this->data[$key])) {
$page = $this->data[$key]; /** @var Page $page */ $page = $this->data[$key];
if($page->id === $id) { if($page->id === $id) {
// found it // found it
return $key; return $key;
@@ -188,17 +188,17 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
* #pw-internal * #pw-internal
* *
* @param array|PageArray|Page $pages Pages to import. * @param array|PageArray|Page $items Pages to import.
* @return PageArray reference to current instance. * @return PageArray reference to current instance.
* *
*/ */
public function import($pages) { public function import($items) {
if(is_object($pages) && $pages instanceof Page) $pages = array($pages); if($items instanceof Page) $items = array($items);
if(!self::iterable($pages)) return $this; if(!self::iterable($items)) return $this;
foreach($pages as $page) $this->add($page); foreach($items as $page) $this->add($page);
if($pages instanceof PageArray) { if($items instanceof PageArray) {
if(count($pages) < $pages->getTotal()) { if(count($items) < $items->getTotal()) {
$this->setTotal($this->getTotal() + ($pages->getTotal() - count($pages))); $this->setTotal($this->getTotal() + ($items->getTotal() - count($items)));
} }
} }
return $this; return $this;
@@ -213,7 +213,7 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* @return bool True if the index or Page exists here, false if not. * @return bool True if the index or Page exists here, false if not.
*/ */
public function has($key) { public function has($key) {
if(is_object($key) && $key instanceof Page) { if($key instanceof Page) {
return $this->getItemKey($key) !== null; return $this->getItemKey($key) !== null;
} }
return parent::has($key); return parent::has($key);
@@ -236,24 +236,25 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* $pageArray->add(1005); * $pageArray->add(1005);
* ~~~~~ * ~~~~~
* *
* @param Page|PageArray|int $page Page object, PageArray object, or Page ID. * @param Page|PageArray|int $item Page object, PageArray object, or Page ID.
* - If given a `Page`, the Page will be added. * - If given a `Page`, the Page will be added.
* - If given a `PageArray`, it will do the same thing as the `WireArray::import()` method and append all the pages. * - If given a `PageArray`, it will do the same thing as the `WireArray::import()` method and append all the pages.
* - If Page `ID`, the Page identified by that ID will be loaded and added to the PageArray. * - If Page `ID`, the Page identified by that ID will be loaded and added to the PageArray.
* @return $this * @return $this
*/ */
public function add($page) { public function add($item) {
if($this->isValidItem($page)) { if($this->isValidItem($item)) {
parent::add($page); parent::add($item);
} else if($page instanceof PageArray || is_array($page)) { } else if($item instanceof PageArray || is_array($item)) {
return $this->import($page); return $this->import($item);
} else if(ctype_digit("$page")) { } else if(ctype_digit("$item")) {
$page = $this->wire()->pages->get("id=$page"); $item = $this->wire()->pages->get("id=$item");
if($page->id) parent::add($page); if($item->id) parent::add($item);
} }
return $this; return $this;
} }
@@ -285,7 +286,9 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
*/ */
public function findRandom($num) { public function findRandom($num) {
return parent::findRandom($num); /** @var PageArray $value */
$value = parent::findRandom($num);
return $value;
} }
/** /**
@@ -302,7 +305,9 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
*/ */
public function slice($start, $limit = 0) { public function slice($start, $limit = 0) {
return parent::slice($start, $limit); /** @var PageArray $value */
$value = parent::slice($start, $limit);
return $value;
} }
/** /**
@@ -317,7 +322,9 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
*/ */
public function eq($num) { public function eq($num) {
return parent::eq($num); /** @var Page $value */
$value = parent::eq($num);
return $value;
} }
/** /**
@@ -453,7 +460,9 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
*/ */
public function find($selector) { public function find($selector) {
return parent::find($selector); /** @var PageArray $value */
$value = parent::find($selector);
return $value;
} }
/** /**
@@ -467,7 +476,9 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* *
*/ */
public function findOne($selector) { public function findOne($selector) {
return parent::findOne($selector); /** @var Page|bool $value */
$value = parent::findOne($selector);
return $value;
} }
/** /**
@@ -611,7 +622,7 @@ class PageArray extends PaginatedArray implements WirePaginatable {
*/ */
public function __toString() { public function __toString() {
$s = ''; $s = '';
foreach($this as $key => $page) $s .= "$page|"; foreach($this as $page) $s .= "$page|";
$s = rtrim($s, "|"); $s = rtrim($s, "|");
return $s; return $s;
} }
@@ -698,7 +709,6 @@ class PageArray extends PaginatedArray implements WirePaginatable {
protected function trackAdd($item, $key) { protected function trackAdd($item, $key) {
parent::trackAdd($item, $key); parent::trackAdd($item, $key);
if(!$item instanceof Page) return; if(!$item instanceof Page) return;
/** @var Page $item */
if(!isset($this->keyIndex[$item->id])) $this->numTotal++; if(!isset($this->keyIndex[$item->id])) $this->numTotal++;
$this->keyIndex[$item->id] = $key; $this->keyIndex[$item->id] = $key;
} }
@@ -713,7 +723,6 @@ class PageArray extends PaginatedArray implements WirePaginatable {
protected function trackRemove($item, $key) { protected function trackRemove($item, $key) {
parent::trackRemove($item, $key); parent::trackRemove($item, $key);
if(!$item instanceof Page) return; if(!$item instanceof Page) return;
/** @var Page $item */
if(isset($this->keyIndex[$item->id])) { if(isset($this->keyIndex[$item->id])) {
if($this->numTotal) $this->numTotal--; if($this->numTotal) $this->numTotal--;
unset($this->keyIndex[$item->id]); unset($this->keyIndex[$item->id]);

View File

@@ -248,4 +248,4 @@ abstract class PageProperties {
if($remainder > 1) $names[$remainder] = "unknown-$remainder"; if($remainder > 1) $names[$remainder] = "unknown-$remainder";
return $names; return $names;
} }
} }

View File

@@ -52,7 +52,7 @@
* *
*/ */
class Pagefile extends WireData { class Pagefile extends WireData implements WireArrayItem {
/** /**
* Timestamp 'created' used by pagefiles that are temporary, not yet published * Timestamp 'created' used by pagefiles that are temporary, not yet published
@@ -1450,6 +1450,19 @@ class Pagefile extends WireData {
return $this->get($key) !== null; return $this->get($key) !== null;
} }
/**
* For WireArrayItem interface
*
* #pw-internal
*
* @return Pagefiles
* @since 3.0.205
*
*/
public function getWireArray() {
return $this->pagefiles;
}
/** /**
* Debug info * Debug info
* *

View File

@@ -87,7 +87,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
*/ */
public function setQuietly($key, $value) { public function setQuietly($key, $value) {
$track = $this->trackChanges(); $track = $this->trackChanges();
$this->setTrackChanges(false); if($track) $this->setTrackChanges(false);
$this->set($key, $value); $this->set($key, $value);
if($track) $this->setTrackChanges(true); if($track) $this->setTrackChanges(true);
return $this; return $this;

View File

@@ -132,6 +132,7 @@ class ProcessModule extends Process {
* *
*/ */
public function __construct() { public function __construct() {
parent::__construct();
$this->labels['download'] = $this->_('Download'); $this->labels['download'] = $this->_('Download');
$this->labels['download_install'] = $this->_('Download and Install'); $this->labels['download_install'] = $this->_('Download and Install');
$this->labels['get_module_info'] = $this->_('Get Module Info'); $this->labels['get_module_info'] = $this->_('Get Module Info');
@@ -155,7 +156,7 @@ class ProcessModule extends Process {
$this->labels['install'] = $this->_('Install'); // Label for Install tab $this->labels['install'] = $this->_('Install'); // Label for Install tab
$this->labels['cancel'] = $this->_('Cancel'); // Label for Cancel button $this->labels['cancel'] = $this->_('Cancel'); // Label for Cancel button
require(dirname(__FILE__) . '/ProcessModuleInstall.php'); require_once(dirname(__FILE__) . '/ProcessModuleInstall.php');
} }
/** /**
@@ -292,6 +293,7 @@ class ProcessModule extends Process {
$session = $this->wire()->session; $session = $this->wire()->session;
$sanitizer = $this->wire()->sanitizer; $sanitizer = $this->wire()->sanitizer;
$input = $this->wire()->input; $input = $this->wire()->input;
$config = $this->wire()->config;
foreach($modules as $module) { foreach($modules as $module) {
$this->modulesArray[$module->className()] = 1; $this->modulesArray[$module->className()] = 1;
@@ -353,7 +355,7 @@ class ProcessModule extends Process {
if($input->post('clear_file_compiler')) { if($input->post('clear_file_compiler')) {
$session->CSRF->validate(); $session->CSRF->validate();
/** @var FileCompiler $compiler */ /** @var FileCompiler $compiler */
$compiler = $this->wire(new FileCompiler($this->wire('config')->paths->siteModules)); $compiler = $this->wire(new FileCompiler($config->paths->siteModules));
$compiler->clearCache(true); $compiler->clearCache(true);
$session->message($this->_('Cleared file compiler cache')); $session->message($this->_('Cleared file compiler cache'));
$session->redirect('./'); $session->redirect('./');
@@ -430,7 +432,7 @@ class ProcessModule extends Process {
$info = $modules->getModuleInfoVerbose($name); $info = $modules->getModuleInfoVerbose($name);
$isNew = !$info['core'] || ($info['core'] && in_array($name, $this->newCoreModules)); $isNew = !$info['core'] || in_array($name, $this->newCoreModules);
if($isNew) $isNew = $info['created'] > 0 && $info['created'] > (time()-$newSeconds); if($isNew) $isNew = $info['created'] > 0 && $info['created'] > (time()-$newSeconds);
if($isNew) $newModulesArray[$name] = $installed; if($isNew) $newModulesArray[$name] = $installed;
@@ -509,7 +511,8 @@ class ProcessModule extends Process {
$form->add($tab); $form->add($tab);
// configurable // configurable
/** @var InputfieldWrapper $tab */
$tab = $this->wire(new InputfieldWrapper()); $tab = $this->wire(new InputfieldWrapper());
$tab->attr('id', 'tab_configurable_modules'); $tab->attr('id', 'tab_configurable_modules');
$tab->attr('title', $this->labels['configure']); $tab->attr('title', $this->labels['configure']);
@@ -528,6 +531,7 @@ class ProcessModule extends Process {
// installable // installable
/** @var InputfieldWrapper $tab */
$tab = $this->wire(new InputfieldWrapper()); $tab = $this->wire(new InputfieldWrapper());
$tab->attr('id', 'tab_install_modules'); $tab->attr('id', 'tab_install_modules');
$tabLabel = $this->labels['install']; $tabLabel = $this->labels['install'];
@@ -558,6 +562,7 @@ class ProcessModule extends Process {
dirname(str_replace($rootPath, '/', $item['file'])) . '/' dirname(str_replace($rootPath, '/', $item['file'])) . '/'
); );
} }
/** @var InputfieldWrapper $tab */
$tab = $this->wire(new InputfieldWrapper()); $tab = $this->wire(new InputfieldWrapper());
$tab->attr('id', 'tab_missing_modules'); $tab->attr('id', 'tab_missing_modules');
$tabLabel = $this->_('Missing'); $tabLabel = $this->_('Missing');
@@ -675,7 +680,7 @@ class ProcessModule extends Process {
$f->label = $this->_('Module ZIP file URL'); $f->label = $this->_('Module ZIP file URL');
$f->description = $this->_('Download a ZIP file containing a module. If you download a module that is already installed, the installed version will be overwritten with the newly downloaded version.'); $f->description = $this->_('Download a ZIP file containing a module. If you download a module that is already installed, the installed version will be overwritten with the newly downloaded version.');
$f->notes = $trustNote; $f->notes = $trustNote;
$f->attr('placeholder', $this->_('http://domain.com/ModuleName.zip')); // placeholder $f->attr('placeholder', $this->_('https://domain.com/ModuleName.zip')); // placeholder
$f->required = false; $f->required = false;
$fieldset->add($f); $fieldset->add($f);
@@ -837,6 +842,7 @@ class ProcessModule extends Process {
$section = $matches[1]; $section = $matches[1];
$sections[] = $section; $sections[] = $section;
if($table) $out .= $table->render() . "</div>"; if($table) $out .= $table->render() . "</div>";
/** @var MarkupAdminDataTable $table */
$table = $modules->get("MarkupAdminDataTable"); $table = $modules->get("MarkupAdminDataTable");
$table->setEncodeEntities(false); $table->setEncodeEntities(false);
$table->headerRow($tableHeader); $table->headerRow($tableHeader);
@@ -847,7 +853,7 @@ class ProcessModule extends Process {
$info = $modules->getModuleInfoVerbose($name); $info = $modules->getModuleInfoVerbose($name);
$configurable = $info['configurable']; $configurable = $info['configurable'];
$title = !empty($info['title']) ? $sanitizer->entities1($info['title']) : substr($name, strlen($section)); $title = !empty($info['title']) ? $sanitizer->entities1($info['title']) : substr($name, strlen($section));
$title = "<span title='$name' uk-tooltip='delay:1000'>$title</span>"; $title = "<span title='$name' data-uk-tooltip='delay:1000'>$title</span>";
if($options['allowClasses']) $title .= "<br /><small class='ModuleClass ui-priority-secondary'>$name</small>"; if($options['allowClasses']) $title .= "<br /><small class='ModuleClass ui-priority-secondary'>$name</small>";
if($info['icon']) $title = wireIconMarkup($info['icon'], 'fw') . " $title"; if($info['icon']) $title = wireIconMarkup($info['icon'], 'fw') . " $title";
$class = $configurable ? 'ConfigurableModule' : ''; $class = $configurable ? 'ConfigurableModule' : '';
@@ -1030,7 +1036,7 @@ class ProcessModule extends Process {
$info = self::getModuleInfo(); $info = self::getModuleInfo();
$this->headline($this->labels['download_install']); $this->headline($this->labels['download_install']);
$this->breadcrumb('./', $info['title']); $this->breadcrumb('./', $info['title']);
if($update) $this->breadcrumb("./?edit=$name", $name); if($update) $this->breadcrumb("./?edit=$name", $name);
$redirectURL = $update ? "./edit?name=$name" : "./"; $redirectURL = $update ? "./edit?name=$name" : "./";
$className = $name; $className = $name;
@@ -1057,7 +1063,7 @@ class ProcessModule extends Process {
$installable = true; $installable = true;
foreach($data['categories'] as $category) { foreach($data['categories'] as $category) {
if(!in_array($category['name'], $this->uninstallableCategories)) continue; if(!in_array($category['name'], $this->uninstallableCategories)) continue;
$this->error(sprintf($this->_('Sorry modules of type "%s" are not installable from the admin.'), $category['title'])); $this->error(sprintf($this->_('Sorry, modules of type "%s" are not installable from the admin.'), $category['title']));
$installable = false; $installable = false;
} }
if(!$installable) $session->redirect($redirectURL); if(!$installable) $session->redirect($redirectURL);
@@ -1424,7 +1430,6 @@ class ProcessModule extends Process {
foreach($moduleInfo as $key => $value) { foreach($moduleInfo as $key => $value) {
if(isset($moduleInfoVerbose[$key]) && $moduleInfoVerbose[$key] !== $value) { if(isset($moduleInfoVerbose[$key]) && $moduleInfoVerbose[$key] !== $value) {
unset($moduleInfo[$key]); unset($moduleInfo[$key]);
continue;
} else if(empty($value)) { } else if(empty($value)) {
if($value === "0" || $value === 0 || $value === false) continue; if($value === "0" || $value === 0 || $value === false) continue;
unset($moduleInfo[$key]); unset($moduleInfo[$key]);
@@ -1752,6 +1757,7 @@ class ProcessModule extends Process {
foreach($fields->getAll() as $field) { foreach($fields->getAll() as $field) {
if(!$field->getSetting('useLanguages')) continue; if(!$field->getSetting('useLanguages')) continue;
foreach($languages as $language) { foreach($languages as $language) {
/** @var Language $language */
if($language->isDefault()) continue; if($language->isDefault()) continue;
$name = $field->name . '__' . $language->id; $name = $field->name . '__' . $language->id;
if(!isset($data[$name])) continue; if(!isset($data[$name])) continue;
@@ -1781,6 +1787,7 @@ class ProcessModule extends Process {
if($languages && $field->getSetting('useLanguages')) { if($languages && $field->getSetting('useLanguages')) {
$_name = $name; $_name = $name;
foreach($languages as $language) { foreach($languages as $language) {
/** @var Language $language */
if($language->isDefault()) continue; if($language->isDefault()) continue;
$name = $_name . "__" . $language->id; $name = $_name . "__" . $language->id;
$value = $field->get("value$language->id"); $value = $field->get("value$language->id");
@@ -2046,6 +2053,7 @@ class ProcessModule extends Process {
$form->description = sprintf($this->_('Import translations for module %s'), $moduleName); $form->description = sprintf($this->_('Import translations for module %s'), $moduleName);
foreach($languages as $language) { foreach($languages as $language) {
/** @var Language $language */
/** @var InputfieldSelect $lang */ /** @var InputfieldSelect $lang */
$langLabel = $language->get('title'); $langLabel = $language->get('title');
$langLabel .= $langLabel ? " ($language->name)" : $language->name; $langLabel .= $langLabel ? " ($language->name)" : $language->name;
@@ -2096,7 +2104,7 @@ class ProcessModule extends Process {
* method can return false. * method can return false.
* *
* @param Page $page * @param Page $page
* @return bool|string * @return string
* @sine 3.0.167 * @sine 3.0.167
* *
*/ */