mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +02:00
Various minor code updates
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* This is the most used object in the ProcessWire API.
|
* This is the most used object in the ProcessWire API.
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @link http://processwire.com/api/variables/pages/ Offical $pages Documentation
|
* @link http://processwire.com/api/variables/pages/ Offical $pages Documentation
|
||||||
@@ -211,7 +211,7 @@ class Pages extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function init() {
|
public function init() {
|
||||||
$this->loader->getById($this->wire('config')->preloadPageIDs);
|
$this->loader->getById($this->wire()->config->preloadPageIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************************************
|
/****************************************************************************************************************
|
||||||
@@ -746,7 +746,7 @@ class Pages extends Wire {
|
|||||||
if($template instanceof Template) {
|
if($template instanceof Template) {
|
||||||
// cool, cool
|
// cool, cool
|
||||||
} else if(is_int($template) || is_string($template)) {
|
} else if(is_int($template) || is_string($template)) {
|
||||||
$template = $this->wire('templates')->get($template);
|
$template = $this->wire()->templates->get($template);
|
||||||
} else {
|
} else {
|
||||||
$template = null;
|
$template = null;
|
||||||
}
|
}
|
||||||
@@ -1775,7 +1775,7 @@ class Pages extends Wire {
|
|||||||
'action' => (string) $action,
|
'action' => (string) $action,
|
||||||
'details' => (string) $details,
|
'details' => (string) $details,
|
||||||
'result' => (string) $result
|
'result' => (string) $result
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1790,7 +1790,7 @@ class Pages extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getDebugLog($action = '') {
|
public function getDebugLog($action = '') {
|
||||||
if(!$this->wire('config')->debug) return array();
|
if(!$this->wire()->config->debug) return array();
|
||||||
if(!$action) return $this->debugLog;
|
if(!$action) return $this->debugLog;
|
||||||
$debugLog = array();
|
$debugLog = array();
|
||||||
foreach($this->debugLog as $item) if($item['action'] == $action) $debugLog[] = $item;
|
foreach($this->debugLog as $item) if($item['action'] == $action) $debugLog[] = $item;
|
||||||
@@ -1798,7 +1798,7 @@ class Pages extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a PageFinder object, ready to use
|
* Return a new PageFinder object, ready to use
|
||||||
*
|
*
|
||||||
* #pw-internal
|
* #pw-internal
|
||||||
*
|
*
|
||||||
@@ -1950,7 +1950,7 @@ class Pages extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function executeQuery(\PDOStatement $query, $throw = true, $maxTries = 3) {
|
public function executeQuery(\PDOStatement $query, $throw = true, $maxTries = 3) {
|
||||||
return $this->wire('database')->execute($query, $throw, $maxTries);
|
return $this->wire()->database->execute($query, $throw, $maxTries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1965,11 +1965,26 @@ class Pages extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __invoke($key) {
|
public function __invoke($key) {
|
||||||
if(empty($key)) return $this; // no argument
|
// no argument
|
||||||
if(is_int($key)) return $this->get($key); // page ID
|
if(empty($key)) return $this;
|
||||||
if(is_array($key) && ctype_digit(implode('', $key))) return $this->getById($key); // array of page IDs
|
|
||||||
if(is_string($key) && strpos($key, '/') !== false && $this->sanitizer->pagePathName($key) === $key) return $this->get($key); // page path
|
// page ID
|
||||||
return $this->find($key); // selector string or array
|
if(is_int($key)) return $this->get($key);
|
||||||
|
|
||||||
|
// array of page IDs
|
||||||
|
if(is_array($key) && ctype_digit(implode('', $key))) {
|
||||||
|
return $this->getById($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// page path
|
||||||
|
if(is_string($key) && strpos($key, '/') !== false) {
|
||||||
|
if($this->wire()->sanitizer->pagePathName($key) === $key) {
|
||||||
|
return $this->get($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector string or array
|
||||||
|
return $this->find($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1983,8 +1998,8 @@ class Pages extends Wire {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function log($str, Page $page) {
|
public function log($str, Page $page) {
|
||||||
if(!in_array('pages', $this->wire('config')->logs)) return parent::___log();
|
if(!in_array('pages', $this->wire()->config->logs)) return parent::___log();
|
||||||
if($this->wire('process') != 'ProcessPageEdit') $str .= " [From URL: " . $this->wire('input')->url() . "]";
|
if($this->wire()->process != 'ProcessPageEdit') $str .= " [From URL: " . $this->wire()->input->url() . "]";
|
||||||
$options = array('name' => 'pages', 'url' => $page->path);
|
$options = array('name' => 'pages', 'url' => $page->path);
|
||||||
return parent::___log($str, $options);
|
return parent::___log($str, $options);
|
||||||
}
|
}
|
||||||
@@ -2150,9 +2165,7 @@ class Pages extends Wire {
|
|||||||
$str = "Saved page";
|
$str = "Saved page";
|
||||||
if(count($changes)) $str .= " (Changes: " . implode(', ', $changes) . ")";
|
if(count($changes)) $str .= " (Changes: " . implode(', ', $changes) . ")";
|
||||||
$this->log($str, $page);
|
$this->log($str, $page);
|
||||||
/** @var WireCache $cache */
|
$this->wire()->cache->maintenance($page);
|
||||||
$cache = $this->wire('cache');
|
|
||||||
$cache->maintenance($page);
|
|
||||||
foreach($this->types as $manager) {
|
foreach($this->types as $manager) {
|
||||||
if($manager->hasValidTemplate($page)) $manager->saved($page, $changes, $values);
|
if($manager->hasValidTemplate($page)) $manager->saved($page, $changes, $values);
|
||||||
}
|
}
|
||||||
@@ -2301,9 +2314,7 @@ class Pages extends Wire {
|
|||||||
public function ___deleted(Page $page, array $options = array()) {
|
public function ___deleted(Page $page, array $options = array()) {
|
||||||
if($options) {}
|
if($options) {}
|
||||||
if(empty($options['_deleteBranch'])) $this->log("Deleted page", $page);
|
if(empty($options['_deleteBranch'])) $this->log("Deleted page", $page);
|
||||||
/** @var WireCache $cache */
|
$this->wire()->cache->maintenance($page);
|
||||||
$cache = $this->wire('cache');
|
|
||||||
$cache->maintenance($page);
|
|
||||||
foreach($this->types as $manager) {
|
foreach($this->types as $manager) {
|
||||||
if($manager->hasValidTemplate($page)) $manager->deleted($page);
|
if($manager->hasValidTemplate($page)) $manager->deleted($page);
|
||||||
}
|
}
|
||||||
|
@@ -92,7 +92,7 @@ class PagesLoader extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether loaded pages have their outputFormatting turn on or off
|
* Set whether loaded pages have their outputFormatting turned on or off
|
||||||
*
|
*
|
||||||
* By default, it is turned on.
|
* By default, it is turned on.
|
||||||
*
|
*
|
||||||
@@ -102,7 +102,13 @@ class PagesLoader extends Wire {
|
|||||||
public function setOutputFormatting($outputFormatting = true) {
|
public function setOutputFormatting($outputFormatting = true) {
|
||||||
$this->outputFormatting = $outputFormatting ? true : false;
|
$this->outputFormatting = $outputFormatting ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether loaded pages have their outputFormatting turned on or off
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function getOutputFormatting() {
|
public function getOutputFormatting() {
|
||||||
return $this->outputFormatting;
|
return $this->outputFormatting;
|
||||||
}
|
}
|
||||||
@@ -118,8 +124,14 @@ class PagesLoader extends Wire {
|
|||||||
*/
|
*/
|
||||||
public function setAutojoin($autojoin = true) {
|
public function setAutojoin($autojoin = true) {
|
||||||
$this->autojoin = $autojoin ? true : false;
|
$this->autojoin = $autojoin ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether autojoin is enabled for page loading queries
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function getAutojoin() {
|
public function getAutojoin() {
|
||||||
return $this->autojoin;
|
return $this->autojoin;
|
||||||
}
|
}
|
||||||
@@ -142,7 +154,7 @@ class PagesLoader extends Wire {
|
|||||||
|
|
||||||
} else if($selector === '/' || $selector === 'path=/') {
|
} else if($selector === '/' || $selector === 'path=/') {
|
||||||
// normalize selectors that indicate homepage to just be ID 1
|
// normalize selectors that indicate homepage to just be ID 1
|
||||||
$selector = (int) $this->wire('config')->rootPageID;
|
$selector = (int) $this->wire()->config->rootPageID;
|
||||||
|
|
||||||
} else if($selector[0] === '/') {
|
} else if($selector[0] === '/') {
|
||||||
// if selector begins with a slash, it is referring to a path
|
// if selector begins with a slash, it is referring to a path
|
||||||
@@ -166,7 +178,7 @@ class PagesLoader extends Wire {
|
|||||||
}
|
}
|
||||||
} else if(!Selectors::stringHasOperator($selector)) {
|
} else if(!Selectors::stringHasOperator($selector)) {
|
||||||
// no operator indicates this is just referring to a page name
|
// no operator indicates this is just referring to a page name
|
||||||
$sanitizer = $this->wire('sanitizer');
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
if($sanitizer->pageNameUTF8($selector) === $selector) {
|
if($sanitizer->pageNameUTF8($selector) === $selector) {
|
||||||
// sanitized value consistent with a page name
|
// sanitized value consistent with a page name
|
||||||
// optimize selector rather than determining value here
|
// optimize selector rather than determining value here
|
||||||
@@ -1503,7 +1515,7 @@ class PagesLoader extends Wire {
|
|||||||
$path = trim($path, '/');
|
$path = trim($path, '/');
|
||||||
|
|
||||||
if($templatesID) {
|
if($templatesID) {
|
||||||
$template = $this->wire('templates')->get($templatesID);
|
$template = $this->wire()->templates->get($templatesID);
|
||||||
if($template->slashUrls) $path .= '/';
|
if($template->slashUrls) $path .= '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1866,7 +1878,10 @@ class PagesLoader extends Wire {
|
|||||||
if(empty($selector)) {
|
if(empty($selector)) {
|
||||||
if(empty($options)) {
|
if(empty($options)) {
|
||||||
// optimize away a simple site-wide total count
|
// optimize away a simple site-wide total count
|
||||||
return (int) $this->wire('database')->query("SELECT COUNT(*) FROM pages")->fetch(\PDO::FETCH_COLUMN);
|
$query = $this->wire()->database->query("SELECT COUNT(*) FROM pages");
|
||||||
|
$count = (int) $query->fetch(\PDO::FETCH_COLUMN);
|
||||||
|
$query->closeCursor();
|
||||||
|
return (int) $count;
|
||||||
} else {
|
} else {
|
||||||
// no selector string, but options specified
|
// no selector string, but options specified
|
||||||
$selector = "id>0";
|
$selector = "id>0";
|
||||||
@@ -1923,8 +1938,8 @@ class PagesLoader extends Wire {
|
|||||||
*/
|
*/
|
||||||
public function getNativeColumns() {
|
public function getNativeColumns() {
|
||||||
if(empty($this->nativeColumns)) {
|
if(empty($this->nativeColumns)) {
|
||||||
$query = $this->wire('database')->prepare("SELECT * FROM pages WHERE id=:id");
|
$query = $this->wire()->database->prepare("SELECT * FROM pages WHERE id=:id");
|
||||||
$query->bindValue(':id', $this->wire('config')->rootPageID, \PDO::PARAM_INT);
|
$query->bindValue(':id', $this->wire()->config->rootPageID, \PDO::PARAM_INT);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$row = $query->fetch(\PDO::FETCH_ASSOC);
|
$row = $query->fetch(\PDO::FETCH_ASSOC);
|
||||||
foreach(array_keys($row) as $colName) {
|
foreach(array_keys($row) as $colName) {
|
||||||
@@ -1948,13 +1963,14 @@ class PagesLoader extends Wire {
|
|||||||
public function getNativeColumnValue($id, $column) {
|
public function getNativeColumnValue($id, $column) {
|
||||||
$id = (is_object($id) ? (int) "$id" : (int) $id);
|
$id = (is_object($id) ? (int) "$id" : (int) $id);
|
||||||
if($id < 1) return false;
|
if($id < 1) return false;
|
||||||
$database = $this->wire('database');
|
$database = $this->wire()->database;
|
||||||
if($database->escapeCol($column) !== $column) throw new WireException("Invalid column name: $column");
|
if($database->escapeCol($column) !== $column) throw new WireException("Invalid column name: $column");
|
||||||
$query = $database->prepare("SELECT `$column` FROM pages WHERE id=:id");
|
$query = $database->prepare("SELECT `$column` FROM pages WHERE id=:id");
|
||||||
$query->bindValue(':id', $id, \PDO::PARAM_INT);
|
$query->bindValue(':id', $id, \PDO::PARAM_INT);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
$value = $query->fetchColumn();
|
$value = $query->fetchColumn();
|
||||||
$query->closeCursor();
|
$query->closeCursor();
|
||||||
|
if(ctype_digit("$value") && strpos($column, 'name') !== 0) $value = (int) $value;
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -156,13 +156,13 @@ class PagesLoaderCache extends Wire {
|
|||||||
public function uncacheAll(Page $page = null, array $options = array()) {
|
public function uncacheAll(Page $page = null, array $options = array()) {
|
||||||
|
|
||||||
if($page) {} // to ignore unused parameter inspection
|
if($page) {} // to ignore unused parameter inspection
|
||||||
$user = $this->wire('user');
|
$user = $this->wire()->user;
|
||||||
$language = $this->wire('languages') ? $user->language : null;
|
$language = $this->wire()->languages ? $user->language : null;
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
|
|
||||||
$this->pages->sortfields(true); // reset
|
$this->pages->sortfields(true); // reset
|
||||||
|
|
||||||
if($this->wire('config')->debug) {
|
if($this->wire()->config->debug) {
|
||||||
$this->pages->debugLog('uncacheAll', 'pageIdCache=' . count($this->pageIdCache) . ', pageSelectorCache=' .
|
$this->pages->debugLog('uncacheAll', 'pageIdCache=' . count($this->pageIdCache) . ', pageSelectorCache=' .
|
||||||
count($this->pageSelectorCache));
|
count($this->pageSelectorCache));
|
||||||
}
|
}
|
||||||
@@ -306,8 +306,8 @@ class PagesLoaderCache extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cache non-default languages separately
|
// cache non-default languages separately
|
||||||
if($this->wire('languages')) {
|
if($this->wire()->languages) {
|
||||||
$language = $this->wire('user')->language;
|
$language = $this->wire()->user->language;
|
||||||
if(!$language->isDefault()) {
|
if(!$language->isDefault()) {
|
||||||
$selector .= ", _lang=$language->id"; // for caching purposes only, not recognized by PageFinder
|
$selector .= ", _lang=$language->id"; // for caching purposes only, not recognized by PageFinder
|
||||||
}
|
}
|
||||||
|
@@ -816,6 +816,10 @@ class Templates extends WireSaveableItems {
|
|||||||
$pageClass = "\\$pageClass";
|
$pageClass = "\\$pageClass";
|
||||||
} else {
|
} else {
|
||||||
// class is not available for instantiation
|
// class is not available for instantiation
|
||||||
|
$this->warning(
|
||||||
|
"Template '$template' page class '$pageClass' is not available",
|
||||||
|
Notice::debug | Notice::superuser | Notice::admin
|
||||||
|
);
|
||||||
$pageClass = '';
|
$pageClass = '';
|
||||||
// do not cache because maybe class will be available later
|
// do not cache because maybe class will be available later
|
||||||
$cacheable = false;
|
$cacheable = false;
|
||||||
|
@@ -166,6 +166,7 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
|||||||
$user = $this->wire()->user;
|
$user = $this->wire()->user;
|
||||||
$config = $this->wire()->config;
|
$config = $this->wire()->config;
|
||||||
$input = $this->wire()->input;
|
$input = $this->wire()->input;
|
||||||
|
$modules = $this->wire()->modules;
|
||||||
$inEditor = $process == 'ProcessPageEdit' || $process == 'ProcessProfile';
|
$inEditor = $process == 'ProcessPageEdit' || $process == 'ProcessProfile';
|
||||||
$isSuperuser = $user->isSuperuser();
|
$isSuperuser = $user->isSuperuser();
|
||||||
|
|
||||||
@@ -212,7 +213,11 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
|||||||
$this->addHookAfter('PagePermissions::pageEditable', $this, 'hookPagePermissionsPageEditableAjax');
|
$this->addHookAfter('PagePermissions::pageEditable', $this, 'hookPagePermissionsPageEditableAjax');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addHookBefore('PageFinder::getQuery', $this, 'hookPageFinderGetQuery');
|
$this->addHookBefore('PageFinder::getQuery', $this, 'hookPageFinderGetQuery');
|
||||||
|
|
||||||
|
$class = $this->className() . 'Matrix';
|
||||||
|
if($this->useLazy && $modules->isInstalled($class)) $modules->get($class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -303,8 +303,7 @@
|
|||||||
var $img = jQuery("#selected_image", $i);
|
var $img = jQuery("#selected_image", $i);
|
||||||
|
|
||||||
$iframe.dialog("disable");
|
$iframe.dialog("disable");
|
||||||
$iframe.setTitle("<i class='fa fa-fw fa-spin fa-spinner'></i> " +
|
$iframe.setTitle(ProcessWire.config.InputfieldCKEditor.pwimage.savingNote); // Saving Image
|
||||||
ProcessWire.config.InputfieldCKEditor.pwimage.savingNote); // Saving Image
|
|
||||||
$img.removeClass("resized");
|
$img.removeClass("resized");
|
||||||
|
|
||||||
var width = $img.attr('width');
|
var width = $img.attr('width');
|
||||||
@@ -352,7 +351,7 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
$iframe.setButtons(buttons);
|
$iframe.setButtons(buttons);
|
||||||
$iframe.setTitle("<i class='fa fa-fw fa-picture-o'></i> " + $i.find('title').html());
|
$iframe.setTitle($i.find('title').html());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
buttons = [];
|
buttons = [];
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user