mirror of
https://github.com/processwire/processwire.git
synced 2025-08-07 07:16:51 +02:00
Minor code and phpdoc improvements to various core classes
This commit is contained in:
@@ -196,6 +196,7 @@ class Pages extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct(ProcessWire $wire) {
|
||||
parent::__construct();
|
||||
$this->setWire($wire);
|
||||
$this->debug = $wire->config->debug === Config::debugVerbose ? true : false;
|
||||
$this->sortfields = $this->wire(new PagesSortfields());
|
||||
@@ -688,7 +689,7 @@ class Pages extends Wire {
|
||||
* @param string|array|Selectors $selector Specify selector to find first matching page ID
|
||||
* @param bool|array $options Specify boolean true to return all pages columns rather than just IDs.
|
||||
* Or specify array of options (see find method for details), `verbose` option can optionally be in array.
|
||||
* @return int|string|array
|
||||
* @return int|array
|
||||
* @see Pages::get(), Pages::has(), Pages::findIDs()
|
||||
* @since 3.0.156
|
||||
*
|
||||
@@ -763,14 +764,14 @@ class Pages extends Wire {
|
||||
$parent_id = $parent->id;
|
||||
} else if(is_int($parent) || ctype_digit("$parent")) {
|
||||
$parent_id = (int) "$parent";
|
||||
} else if(is_string($parent) && $parent) {
|
||||
} else if(is_string($parent)) {
|
||||
$parent_id = $this->has($parent);
|
||||
}
|
||||
if(!$parent_id) $parent_id = null;
|
||||
}
|
||||
|
||||
if(count($options)) {
|
||||
$options['template'] = $template && $template instanceof Template ? $template : null;
|
||||
$options['template'] = $template instanceof Template ? $template : null;
|
||||
$options['parent_id'] = $parent_id;
|
||||
return $this->loader->getById($ids, $options);
|
||||
} else {
|
||||
@@ -1399,7 +1400,7 @@ class Pages extends Wire {
|
||||
*
|
||||
*/
|
||||
public function ___setupNew(Page $page) {
|
||||
return $this->editor()->setupNew($page);
|
||||
$this->editor()->setupNew($page);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1684,12 +1685,12 @@ class Pages extends Wire {
|
||||
/**
|
||||
* Return a fuel or other property set to the Pages instance
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function __get($key) {
|
||||
switch($key) {
|
||||
public function __get($name) {
|
||||
switch($name) {
|
||||
// A-Z
|
||||
case 'autojoin': return $this->loader->getAutojoin();
|
||||
case 'cacher': return $this->cacher();
|
||||
@@ -1709,7 +1710,7 @@ class Pages extends Wire {
|
||||
case 'trasher': return $this->trasher();
|
||||
case 'types': return $this->types();
|
||||
}
|
||||
return parent::__get($key);
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2244,7 +2245,6 @@ class Pages extends Wire {
|
||||
*
|
||||
*/
|
||||
public function ___trashReady(Page $page) {
|
||||
if($page) {} // ignore
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2345,7 +2345,6 @@ class Pages extends Wire {
|
||||
*
|
||||
*/
|
||||
public function ___deleteBranchReady(Page $page, array $options) {
|
||||
if($page && $options) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2362,7 +2361,6 @@ class Pages extends Wire {
|
||||
*
|
||||
*/
|
||||
public function ___deletedBranch(Page $page, array $options, $numDeleted) {
|
||||
if($page && $options) {}
|
||||
$this->log("Deleted branch with $numDeleted page(s)", $page);
|
||||
}
|
||||
|
||||
@@ -2426,7 +2424,6 @@ class Pages extends Wire {
|
||||
*
|
||||
*/
|
||||
public function ___sorted(Page $page, $children = false, $total = 0) {
|
||||
if($page && $children && $total) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -17,7 +17,7 @@
|
||||
* Pages using templates that already define their access (determined by $template->useRoles)
|
||||
* are omitted from the pages_access table, as they aren't necessary.
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
@@ -52,6 +52,7 @@ class PagesAccess extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct($item = null) {
|
||||
parent::__construct();
|
||||
if(!$item) return;
|
||||
if($item instanceof Page) {
|
||||
$this->updatePage($item);
|
||||
@@ -75,9 +76,9 @@ class PagesAccess extends Wire {
|
||||
$accessTemplates = $this->getAccessTemplates();
|
||||
$parent_id = (int) $parent_id;
|
||||
$accessTemplateID = (int) $accessTemplateID;
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
|
||||
if(!$accessTemplateID && $this->config->debug) $this->message("Rebuilding pages_access");
|
||||
if(!$accessTemplateID && $this->wire()->config->debug) $this->message("Rebuilding pages_access");
|
||||
|
||||
if($parent_id == 1) {
|
||||
// if we're going to be rebuilding the entire tree, then just delete all of them now
|
||||
@@ -188,7 +189,7 @@ class PagesAccess extends Wire {
|
||||
// this is the template where access is defined for this page
|
||||
$accessParent = $page->getAccessParent();
|
||||
$accessTemplate = $accessParent->template;
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
|
||||
if(!$accessParent->id || $accessParent->id == $page->id) {
|
||||
// page is the same as the one that defines access, so it doesn't need to be here
|
||||
@@ -231,7 +232,7 @@ class PagesAccess extends Wire {
|
||||
*
|
||||
*/
|
||||
public function deletePage(Page $page) {
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$query = $database->prepare("DELETE FROM pages_access WHERE pages_id=:page_id");
|
||||
$query->bindValue(":page_id", $page->id, \PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
|
@@ -371,7 +371,7 @@ class PagesEditor extends Wire {
|
||||
/** @var Field $field */
|
||||
if($page->isLoaded($field->name)) continue; // value already set
|
||||
if(!$page->hasField($field)) continue; // field not valid for page
|
||||
if(!strlen("$field->defaultValue")) continue; // no defaultValue property defined with Fieldtype config inputfields
|
||||
if(!strlen((string) $field->get('defaultValue'))) continue; // no defaultValue property defined with Fieldtype config inputfields
|
||||
try {
|
||||
$blankValue = $field->type->getBlankValue($page, $field);
|
||||
if(is_object($blankValue) || is_array($blankValue)) continue; // we don't currently handle complex types
|
||||
@@ -1159,7 +1159,7 @@ class PagesEditor extends Wire {
|
||||
* - forceID (int): force a specific ID
|
||||
* - set (array): Array of properties to set to the clone (you can also do this later)
|
||||
* - recursionLevel (int): recursion level, for internal use only.
|
||||
* @return Page the newly cloned page or a NullPage() with id=0 if unsuccessful.
|
||||
* @return Page|NullPage the newly cloned page or a NullPage() with id=0 if unsuccessful.
|
||||
* @throws WireException|\Exception on fatal error
|
||||
*
|
||||
*/
|
||||
|
@@ -87,6 +87,7 @@ class PagesLoader extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct(Pages $pages) {
|
||||
parent::__construct();
|
||||
$this->pages = $pages;
|
||||
$this->debug = $pages->debug();
|
||||
}
|
||||
@@ -195,6 +196,8 @@ class PagesLoader extends Wire {
|
||||
$selector = "id=$selector";
|
||||
}
|
||||
}
|
||||
|
||||
/** @var array|int|string $selector */
|
||||
|
||||
return $selector;
|
||||
}
|
||||
@@ -349,7 +352,7 @@ class PagesLoader extends Wire {
|
||||
$selectors = $selector;
|
||||
} else {
|
||||
$selector = $this->normalizeSelector($selector, false);
|
||||
$selectors = $this->wire(new Selectors());
|
||||
$selectors = $this->wire(new Selectors()); /** @var Selectors $selectors */
|
||||
$selectors->init($selector);
|
||||
}
|
||||
|
||||
@@ -391,7 +394,7 @@ class PagesLoader extends Wire {
|
||||
$pagesIDs = array();
|
||||
|
||||
if($debug) Debug::timer("$caller($selectorString)", true);
|
||||
$profiler = $this->wire('profiler');
|
||||
$profiler = $this->wire()->profiler;
|
||||
$profilerEvent = $profiler ? $profiler->start("$caller($selectorString)", "Pages") : null;
|
||||
|
||||
if(($lazy || $findIDs) && strpos($selectorString, 'limit=') === false) $options['getTotal'] = false;
|
||||
@@ -934,7 +937,7 @@ class PagesLoader extends Wire {
|
||||
* just those used by the template. Optionally specify an $options array instead, see the method notes above.
|
||||
* @param int|null $parent_id Specify a parent to make the load faster, as it reduces the possibility for full table scans.
|
||||
* This argument is ignored when an options array is supplied for the $template.
|
||||
* @return PageArray|Page Returns Page only if the 'getOne' option is specified, otherwise always returns a PageArray.
|
||||
* @return PageArray|Page|NullPage Returns Page only if the 'getOne' option is specified, otherwise always returns a PageArray.
|
||||
* @throws WireException
|
||||
*
|
||||
*/
|
||||
@@ -1150,6 +1153,7 @@ class PagesLoader extends Wire {
|
||||
|
||||
if($options['autojoin'] && $this->autojoin) {
|
||||
foreach($fields as $field) {
|
||||
/** @var Field $field */
|
||||
if(!empty($options['joinFields']) && in_array($field->name, $options['joinFields'])) {
|
||||
// joinFields option specified to force autojoin this field
|
||||
} else {
|
||||
@@ -1160,7 +1164,8 @@ class PagesLoader extends Wire {
|
||||
}
|
||||
$table = $database->escapeTable($field->table);
|
||||
// check autojoin not allowed, otherwise merge in the autojoin query
|
||||
if(!$field->type || !$field->type->getLoadQueryAutojoin($field, $query)) continue;
|
||||
$fieldtype = $field->type;
|
||||
if(!$fieldtype || !$fieldtype->getLoadQueryAutojoin($field, $query)) continue;
|
||||
// complete autojoin
|
||||
$query->leftjoin("$table ON $table.pages_id=pages.id"); // QA
|
||||
}
|
||||
@@ -1194,7 +1199,7 @@ class PagesLoader extends Wire {
|
||||
|
||||
// page to populate, if provided in 'getOne' mode
|
||||
/** @var Page|null $_page */
|
||||
$_page = $options['getOne'] && $options['page'] && $options['page'] instanceof Page ? $options['page'] : null;
|
||||
$_page = $options['getOne'] && $options['page'] instanceof Page ? $options['page'] : null;
|
||||
|
||||
try {
|
||||
// while($page = $stmt->fetchObject($_class, array($template))) {
|
||||
@@ -1415,6 +1420,11 @@ class PagesLoader extends Wire {
|
||||
*
|
||||
*/
|
||||
public function getPath($id, $options = array()) {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$database = $this->wire()->database;
|
||||
$languages = $this->wire()->languages;
|
||||
$config = $this->wire()->config;
|
||||
|
||||
$defaults = array(
|
||||
'language' => null,
|
||||
@@ -1430,7 +1440,7 @@ class PagesLoader extends Wire {
|
||||
|
||||
$options = array_merge($defaults, $options);
|
||||
|
||||
if(is_object($id) && $id instanceof Page) {
|
||||
if($id instanceof Page) {
|
||||
if($options['useCache']) return $id->path();
|
||||
$id = $id->id;
|
||||
}
|
||||
@@ -1438,12 +1448,11 @@ class PagesLoader extends Wire {
|
||||
$id = (int) $id;
|
||||
if(!$id || $id < 0) return '';
|
||||
|
||||
$languages = $this->wire()->languages;
|
||||
if($languages && !$languages->hasPageNames()) $languages = null;
|
||||
|
||||
$language = $options['language'];
|
||||
$languageID = 0;
|
||||
$homepageID = (int) $this->wire()->config->rootPageID;
|
||||
$homepageID = (int) $config->rootPageID;
|
||||
|
||||
if(!empty($language) && $languages) {
|
||||
if(is_string($language) || is_int($language)) $language = $languages->get($language);
|
||||
@@ -1469,19 +1478,16 @@ class PagesLoader extends Wire {
|
||||
}
|
||||
|
||||
// if PagePaths module is installed, and not in multi-language environment, attempt to get from PagePaths module
|
||||
if(!$languages && !$languageID && $options['usePagePaths'] && $this->wire('modules')->isInstalled('PagePaths')) {
|
||||
if(!$languages && !$languageID && $options['usePagePaths'] && $modules->isInstalled('PagePaths')) {
|
||||
/** @var PagePaths $pagePaths */
|
||||
$pagePaths = $this->modules->get('PagePaths');
|
||||
$pagePaths = $modules->get('PagePaths');
|
||||
$path = $pagePaths->getPath($id);
|
||||
if($path) return $path;
|
||||
} else {
|
||||
$pagePaths = null;
|
||||
}
|
||||
|
||||
$path = '';
|
||||
$templatesID = 0;
|
||||
$parentID = $id;
|
||||
$database = $this->wire('database');
|
||||
$maxParentID = $language ? 0 : 1;
|
||||
$cols = 'parent_id, templates_id, name';
|
||||
if($languageID) $cols .= ", name$languageID"; // col=3
|
||||
@@ -2032,4 +2038,4 @@ class PagesLoader extends Wire {
|
||||
return $this->loading;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* ProcessWire Pages Names
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* #pw-summary This class includes methods for generating and modifying page names.
|
||||
@@ -71,7 +71,7 @@ class PagesNames extends Wire {
|
||||
public function __construct(Pages $pages) {
|
||||
$this->pages = $pages;
|
||||
$pages->wire($this);
|
||||
$untitled = $this->wire('config')->pageNameUntitled;
|
||||
$untitled = $this->wire()->config->pageNameUntitled;
|
||||
if($untitled) $this->untitledPageName = $untitled;
|
||||
$this->nameMaxLength = Pages::nameMaxLength;
|
||||
parent::__construct();
|
||||
@@ -228,7 +228,7 @@ class PagesNames extends Wire {
|
||||
// default format is title (when the page has one)
|
||||
$format = 'title';
|
||||
|
||||
} else if($this->wire('languages') && $page->title instanceof LanguagesValueInterface) {
|
||||
} else if($this->wire()->languages && $page->title instanceof LanguagesValueInterface) {
|
||||
// check for multi-language title
|
||||
/** @var LanguagesPageFieldValue $pageTitle */
|
||||
$pageTitle = $page->title;
|
||||
@@ -616,8 +616,8 @@ class PagesNames extends Wire {
|
||||
$languages = $options['multilang'] || $options['language'] ? $this->wire()->languages : null;
|
||||
if($languages && !$languages->hasPageNames()) $languages = null;
|
||||
|
||||
if($this->wire('config')->pageNameCharset == 'UTF8') {
|
||||
$name = $this->wire('sanitizer')->pageName($name, Sanitizer::toAscii);
|
||||
if($this->wire()->config->pageNameCharset == 'UTF8') {
|
||||
$name = $this->wire()->sanitizer->pageName($name, Sanitizer::toAscii);
|
||||
}
|
||||
|
||||
$wheres = array();
|
||||
@@ -649,7 +649,7 @@ class PagesNames extends Wire {
|
||||
}
|
||||
|
||||
$sql = 'SELECT COUNT(*) FROM pages WHERE ' . implode(' AND ', $wheres);
|
||||
$query = $this->wire('database')->prepare($sql);
|
||||
$query = $this->wire()->database->prepare($sql);
|
||||
|
||||
foreach($binds as $key => $value) {
|
||||
$query->bindValue($key, $value);
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* $numRows = $pages->parents()->rebuildAll();
|
||||
* ~~~~~~
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @since 3.0.156
|
||||
@@ -45,6 +45,7 @@ class PagesParents extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct(Pages $pages) {
|
||||
parent::__construct();
|
||||
$this->pages = $pages;
|
||||
$this->debug = $pages->debug();
|
||||
}
|
||||
@@ -174,7 +175,7 @@ class PagesParents extends Wire {
|
||||
// more parents to go, get rest recursively
|
||||
$o = $options;
|
||||
$o['columns'] = $columns;
|
||||
foreach($this->getParents($lastParentID, $o) as $key => $value) {
|
||||
foreach($this->getParents($lastParentID, $o) as $value) {
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
@@ -224,6 +225,8 @@ class PagesParents extends Wire {
|
||||
*/
|
||||
public function findParents(array $options = array()) {
|
||||
|
||||
$database = $this->wire()->database;
|
||||
|
||||
static $calls = 0;
|
||||
|
||||
$defaults = array(
|
||||
@@ -245,7 +248,6 @@ class PagesParents extends Wire {
|
||||
|
||||
$options = array_merge($defaults, $options);
|
||||
$parentID = isset($options['parent']) ? (int) "$options[parent]" : 0;
|
||||
$database = $this->wire('database'); /** @var WireDatabasePDO $database */
|
||||
$sql = array();
|
||||
$bind = array();
|
||||
$column = $options['column'];
|
||||
@@ -447,7 +449,7 @@ class PagesParents extends Wire {
|
||||
JOIN pages AS parents on pages.parent_id=parents.id AND parents.parent_id>=:id
|
||||
GROUP BY pages.parent_id
|
||||
";
|
||||
$query = $this->database->prepare(trim($sql));
|
||||
$query = $this->wire()->database->prepare(trim($sql));
|
||||
$query->bindValue(':id', $minParentID, \PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
while($row = $query->fetch(\PDO::FETCH_NUM)) {
|
||||
@@ -529,7 +531,7 @@ class PagesParents extends Wire {
|
||||
public function rebuild(Page $page) {
|
||||
|
||||
$pages_id = (int) $page->id;
|
||||
$database = $this->wire('database'); /** @var WireDatabasePDO $database */
|
||||
$database = $this->wire()->database;
|
||||
$inserts = array();
|
||||
$rowCount = 0;
|
||||
|
||||
@@ -579,7 +581,7 @@ class PagesParents extends Wire {
|
||||
*/
|
||||
public function rebuildAll($fromParent = null) {
|
||||
|
||||
$database = $this->wire('database'); /** @var WireDatabasePDO $database */
|
||||
$database = $this->wire()->database;
|
||||
$inserts = array();
|
||||
$parents = $this->findParentIDs($fromParent ? $fromParent : -2); // find parents within children
|
||||
$rowCount = 0;
|
||||
@@ -620,7 +622,7 @@ class PagesParents extends Wire {
|
||||
*/
|
||||
public function clear($page) {
|
||||
$pages_id = (int) "$page";
|
||||
$database = $this->wire('database'); /** @var WireDatabasePDO $database */
|
||||
$database = $this->wire()->database;
|
||||
$query = $database->prepare("DELETE FROM pages_parents WHERE pages_id=:id");
|
||||
$query->bindValue(':id', $pages_id, \PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
@@ -639,7 +641,7 @@ class PagesParents extends Wire {
|
||||
*/
|
||||
public function delete($page) {
|
||||
$pages_id = (int) "$page";
|
||||
$database = $this->wire('database'); /** @var WireDatabasePDO $database */
|
||||
$database = $this->wire()->database;
|
||||
$sql = "DELETE FROM pages_parents WHERE pages_id=:pages_id OR parents_id=:parents_id";
|
||||
$query = $database->prepare($sql);
|
||||
$query->bindValue(':pages_id', $pages_id, \PDO::PARAM_INT);
|
||||
@@ -666,7 +668,7 @@ class PagesParents extends Wire {
|
||||
|
||||
$id = (int) "$page";
|
||||
$path = $page->path;
|
||||
$database = $this->wire('database'); /** @var WireDatabasePDO $database */
|
||||
$database = $this->wire()->database;
|
||||
|
||||
$tests = array(
|
||||
'query-for-parents-of-page' => array(
|
||||
@@ -754,4 +756,4 @@ class PagesParents extends Wire {
|
||||
return $children;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -572,7 +572,7 @@ class PagesPathFinder extends Wire {
|
||||
$this->addResultNote("Detected language '$language->name' from first segment '$segment'");
|
||||
$this->setResultLanguage($language, $segment);
|
||||
|
||||
if($this->verbose && $languageKey !== false) {
|
||||
if($this->verbose) {
|
||||
$this->result['parts'][] = array(
|
||||
'type' => 'language',
|
||||
'value' => $segment,
|
||||
@@ -582,7 +582,7 @@ class PagesPathFinder extends Wire {
|
||||
|
||||
// reduce to just applicable language to limit name columns
|
||||
// searched for by getPagesRow() method
|
||||
if($language) $this->useLanguages = array($language);
|
||||
$this->useLanguages = array($language);
|
||||
|
||||
return $language;
|
||||
}
|
||||
@@ -639,7 +639,7 @@ class PagesPathFinder extends Wire {
|
||||
* Update paths for template info like urlSegments and pageNum and populate urls property
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool|string
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
protected function applyResultTemplate($path) {
|
||||
@@ -790,7 +790,7 @@ class PagesPathFinder extends Wire {
|
||||
// if there were any non-default language segments, let that dictate the language
|
||||
if(empty($result['language']['segment'])) {
|
||||
$useLangName = 'default';
|
||||
foreach($result['parts'] as $key => $part) {
|
||||
foreach($result['parts'] as $part) {
|
||||
$langName = $part['language'];
|
||||
if(empty($langName) || $langName === 'default') continue;
|
||||
$useLangName = $langName;
|
||||
@@ -1671,7 +1671,7 @@ class PagesPathFinder extends Wire {
|
||||
* Return Languages if installed w/languageSupportPageNames module or blank array if not
|
||||
*
|
||||
* @param bool $getArray Force return value as an array indexed by language name
|
||||
* @return Languages|array
|
||||
* @return Languages|Language[]
|
||||
*
|
||||
*/
|
||||
protected function languages($getArray = false) {
|
||||
@@ -2106,7 +2106,7 @@ class PagesPathFinderTests extends Wire {
|
||||
$defaultPath = $item->path();
|
||||
if($languages) {
|
||||
foreach($languages as $language) {
|
||||
// $user->setLanguage($language);
|
||||
/** @var Language $language */
|
||||
$path = $item->localPath($language);
|
||||
if($language->isDefault() || $path === $defaultPath) {
|
||||
$expect = 200;
|
||||
@@ -2139,4 +2139,4 @@ class PagesPathFinderTests extends Wire {
|
||||
}
|
||||
return $testResults;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -381,7 +381,7 @@ class PagesRawFinder extends Wire {
|
||||
/**
|
||||
* IDs of pages to find, becomes array once known
|
||||
*
|
||||
* @var null|array
|
||||
* @var null|array|string
|
||||
*
|
||||
*/
|
||||
protected $ids = null;
|
||||
@@ -393,6 +393,7 @@ class PagesRawFinder extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct(Pages $pages) {
|
||||
parent::__construct();
|
||||
$this->pages = $pages;
|
||||
}
|
||||
|
||||
@@ -907,7 +908,7 @@ class PagesRawFinder extends Wire {
|
||||
if(wireInstanceOf($field->type, 'FieldtypeOptions')) $getExternal = true;
|
||||
|
||||
} else {
|
||||
foreach($cols as $key => $col) {
|
||||
foreach($cols as $col) {
|
||||
$col = $sanitizer->name($col);
|
||||
if(empty($col)) continue;
|
||||
if(isset($schema[$col])) {
|
||||
@@ -1104,7 +1105,7 @@ class PagesRawFinder extends Wire {
|
||||
*/
|
||||
protected function findCustomFieldtypePage(Field $field, $fieldName, array $pageRefCols) {
|
||||
$pageRefIds = array();
|
||||
foreach($this->values as $pageId => $row) {
|
||||
foreach($this->values as /* $pageId => */ $row) {
|
||||
if(!isset($row[$fieldName])) continue;
|
||||
$pageRefIds = array_merge($pageRefIds, $row[$fieldName]);
|
||||
}
|
||||
@@ -1333,7 +1334,7 @@ class PagesRawFinder extends Wire {
|
||||
$references = $fromPageIds[$toPageId];
|
||||
} else {
|
||||
$references = array();
|
||||
foreach($fromPageIds[$toPageId] as $fieldName => $ids) {
|
||||
foreach($fromPageIds[$toPageId] as /* $fieldName => */ $ids) {
|
||||
$references = array_merge($references, $ids);
|
||||
}
|
||||
}
|
||||
@@ -1684,4 +1685,4 @@ class PagesRawFinder extends Wire {
|
||||
$s = "Unknown$context name(s) for findRaw: " . implode(', ', $fieldNames);
|
||||
throw new WireException($s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -180,6 +180,7 @@ class PagesRequest extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct(Pages $pages) {
|
||||
parent::__construct();
|
||||
$this->pages = $pages;
|
||||
$this->config = $pages->wire()->config;
|
||||
$this->init();
|
||||
@@ -274,7 +275,6 @@ class PagesRequest extends Wire {
|
||||
|
||||
$input = $this->wire()->input;
|
||||
$languages = $this->wire()->languages;
|
||||
$page = null;
|
||||
|
||||
// get the requested path
|
||||
$path = $this->getRequestPath();
|
||||
|
@@ -101,7 +101,7 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
if(WireArray::iterable($templates)) {
|
||||
// array already provided
|
||||
foreach($templates as $template) {
|
||||
if(is_int($template) || !$template instanceof Template) $template = $this->wire('templates')->get($template);
|
||||
if(!$template instanceof Template) $template = $this->wire()->templates->get($template);
|
||||
if(!$template) continue;
|
||||
$this->templates[$template->id] = $template;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
$this->templates[$templates->id] = $templates;
|
||||
} else {
|
||||
// template id or template name
|
||||
$template = $this->wire('templates')->get($templates);
|
||||
$template = $this->wire()->templates->get($templates);
|
||||
if($template) $this->templates[$template->id] = $template;
|
||||
}
|
||||
}
|
||||
@@ -134,9 +134,9 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
} else if(is_string($parent) && ctype_digit($parent)) {
|
||||
$id = (int) $parent;
|
||||
} else if(is_string($parent)) {
|
||||
$parent = $this->wire('pages')->get($parent, array('loadOptions' => array('autojoin' => false)));
|
||||
$parent = $this->wire()->pages->get($parent, array('loadOptions' => array('autojoin' => false)));
|
||||
$id = $parent->id;
|
||||
} else if(is_object($parent) && $parent instanceof Page) {
|
||||
} else if($parent instanceof Page) {
|
||||
$id = $parent->id;
|
||||
} else {
|
||||
$id = 0;
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* @property string $name Name of the permission.
|
||||
* @property string $title Short description of what the permission is for.
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*/
|
||||
@@ -42,7 +42,7 @@ class Permission extends Page {
|
||||
'page-template' => 'page-edit',
|
||||
'page-sort' => 'page-edit',
|
||||
'page' => 'page-edit', // all page-* permissions
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new Permission page in memory.
|
||||
@@ -81,7 +81,7 @@ class Permission extends Page {
|
||||
public function getParentPermission() {
|
||||
|
||||
$name = $this->name;
|
||||
$permissions = $this->wire('permissions');
|
||||
$permissions = $this->wire()->permissions;
|
||||
$permission = null;
|
||||
|
||||
do {
|
||||
@@ -100,7 +100,7 @@ class Permission extends Page {
|
||||
$permission = $permissions->get($name);
|
||||
} while(!$permission->id);
|
||||
|
||||
if(is_null($permission)) $permission = $this->wire('pages')->newNullPage();
|
||||
if(is_null($permission)) $permission = $this->wire()->pages->newNullPage();
|
||||
|
||||
return $permission;
|
||||
}
|
||||
@@ -115,20 +115,22 @@ class Permission extends Page {
|
||||
*
|
||||
*/
|
||||
public function getRootParentPermission() {
|
||||
$permissions = $this->wire()->permissions;
|
||||
$pages = $this->wire()->pages;
|
||||
if(isset(self::$parentPermissions[$this->name])) {
|
||||
$name = self::$parentPermissions[$this->name];
|
||||
if($name == 'none') return $this->wire('pages')->newNullPage();
|
||||
if($name == 'none') return $pages->newNullPage();
|
||||
}
|
||||
$parts = explode('-', $this->name);
|
||||
if(count($parts) < 2) return $this->wire('pages')->newNullPage();
|
||||
if(count($parts) < 2) return $pages->newNullPage();
|
||||
$name = "$parts[0]-$parts[1]";
|
||||
if(isset(self::$parentPermissions[$name])) {
|
||||
$name = self::$parentPermissions[$name];
|
||||
if($name == 'none') return $this->wire('pages')->newNullPage();
|
||||
return $this->wire('permissions')->get($name);
|
||||
if($name == 'none') return $pages->newNullPage();
|
||||
return $permissions->get($name);
|
||||
}
|
||||
if($parts[0] == 'page') $name = 'page-edit';
|
||||
return $this->wire('permissions')->get($name);
|
||||
return $permissions->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,11 +138,11 @@ class Permission extends Page {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @return Pages|PagesType
|
||||
* @return Permissions
|
||||
*
|
||||
*/
|
||||
public function getPagesManager() {
|
||||
return $this->wire('permissions');
|
||||
return $this->wire()->permissions;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,10 @@
|
||||
/**
|
||||
* The Permissions class serves as the $permissions API variable.
|
||||
*
|
||||
* #pw-summary Provides management of all Permission pages independent of users, for access control.
|
||||
* #pw-summary Provides management of all Permission pages independent of users, for access control.
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @method PageArray find($selector) Return the permissions(s) matching the the given selector query.
|
||||
* @method Permission|NullPage get($selector) Return permission by given name, numeric ID or a selector string.
|
||||
@@ -13,7 +16,7 @@
|
||||
* @method void added(Page $page) Hook called just after a Permission is added #pw-hooker
|
||||
* @method void deleteReady(Page $page) Hook called before a Permission is deleted #pw-hooker
|
||||
* @method void deleted(Page $page) Hook called after a permission is deleted #pw-hooker
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Permissions extends PagesType {
|
||||
|
||||
@@ -85,7 +88,7 @@ class Permissions extends PagesType {
|
||||
|
||||
if(empty($this->permissionNames)) {
|
||||
|
||||
$cache = $this->wire('cache');
|
||||
$cache = $this->wire()->cache;
|
||||
$names = $cache->get(self::cacheName);
|
||||
|
||||
if(empty($names)) {
|
||||
@@ -138,7 +141,7 @@ class Permissions extends PagesType {
|
||||
* #pw-group-manipulation
|
||||
*
|
||||
* @param string $name Name of permission you want to add, i.e. "hello-world"
|
||||
* @return Permission|Page|NullPage Returns a Permission page on success, or a NullPage on error
|
||||
* @return Permission|NullPage Returns a Permission page on success, or a NullPage on error
|
||||
*
|
||||
*/
|
||||
public function ___add($name) {
|
||||
@@ -216,8 +219,8 @@ class Permissions extends PagesType {
|
||||
*/
|
||||
public function getReducerPermissions() {
|
||||
$a = $this->reducerPermissions;
|
||||
$languages = $this->wire('languages');
|
||||
if($languages && $this->wire('modules')->isInstalled('LanguageSupportFields')) {
|
||||
$languages = $this->wire()->languages;
|
||||
if($languages && $languages->hasPageNames()) {
|
||||
foreach($languages as $language) {
|
||||
$a[] = "page-edit-lang-$language->name";
|
||||
}
|
||||
@@ -253,10 +256,10 @@ class Permissions extends PagesType {
|
||||
* }
|
||||
* ~~~~~
|
||||
*
|
||||
* @return \ArrayObject
|
||||
* @return array|PageArray|\Traversable
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator() {
|
||||
return parent::getIterator();
|
||||
}
|
||||
@@ -274,7 +277,7 @@ class Permissions extends PagesType {
|
||||
*/
|
||||
|
||||
public function ___saved(Page $page, array $changes = array(), $values = array()) {
|
||||
$this->wire('cache')->delete(self::cacheName);
|
||||
$this->wire()->cache->delete(self::cacheName);
|
||||
parent::___saved($page, $changes, $values);
|
||||
}
|
||||
|
||||
@@ -288,7 +291,7 @@ class Permissions extends PagesType {
|
||||
*
|
||||
*/
|
||||
public function ___deleted(Page $page) {
|
||||
$this->wire('cache')->delete(self::cacheName);
|
||||
$this->wire()->cache->delete(self::cacheName);
|
||||
parent::___deleted($page);
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,8 @@ require_once(PROCESSWIRE_CORE_PATH . "Selector.php");
|
||||
* This Selectors class is used internally by ProcessWire to provide selector string (and array) matching throughout the core.
|
||||
*
|
||||
* ~~~~~
|
||||
* $selectors = new Selectors("sale_price|retail_price>100, currency=USD|EUR");
|
||||
* $selectors = new Selectors();
|
||||
* $selectors->init("sale_price|retail_price>100, currency=USD|EUR");
|
||||
* if($selectors->matches($page)) {
|
||||
* // selector string matches the given $page (which can be any Wire-derived item)
|
||||
* }
|
||||
@@ -31,7 +32,7 @@ require_once(PROCESSWIRE_CORE_PATH . "Selector.php");
|
||||
* @link https://processwire.com/api/selectors/ Official Selectors Documentation
|
||||
* @method Selector[] getIterator()
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @todo Move static helper methods to dedicated API var/class so this class can be more focused
|
||||
@@ -103,7 +104,7 @@ class Selectors extends WireArray {
|
||||
/**
|
||||
* Given a selector string, extract it into one or more corresponding Selector objects, iterable in this object.
|
||||
*
|
||||
* @param string|null|array $selector Selector string or array. If not provided here, please follow-up with a setSelectorString($str) call.
|
||||
* @param string|null|array $selector Please omit this argument and use a separate init($selector) call instead.
|
||||
*
|
||||
*/
|
||||
public function __construct($selector = null) {
|
||||
|
@@ -26,8 +26,8 @@
|
||||
* Fieldgroup/Fields
|
||||
*
|
||||
* @property int $fieldgroups_id Numeric ID of Fieldgroup assigned to this template. #pw-internal
|
||||
* @property Fieldgroup $fieldgroup The Fieldgroup used by the template. Can also be used to iterate a Template's fields. #pw-group-fields
|
||||
* @property Fieldgroup $fields Alias for the fieldgroup property. Use whatever makes more sense for your code readability. #pw-internal
|
||||
* @property Fieldgroup|Field[] $fieldgroup The Fieldgroup used by the template. Can also be used to iterate a Template's fields. #pw-group-fields
|
||||
* @property Fieldgroup|Field[] $fields Alias for the fieldgroup property. Use whatever makes more sense for your code readability. #pw-internal
|
||||
* @property Fieldgroup|null $fieldgroupPrevious Previous fieldgroup, if it was changed. Null if not. #pw-group-fields
|
||||
*
|
||||
* Cache
|
||||
|
@@ -34,27 +34,27 @@
|
||||
* @property WireDatabasePDO $database #pw-internal
|
||||
* @property Database $db #pw-internal deprecated
|
||||
* @property WireDateTime $datetime #pw-internal
|
||||
* @property Fieldgroups $fieldgroups #pw-internal
|
||||
* @property Fields $fields #pw-internal
|
||||
* @property Fieldtypes $fieldtypes #pw-internal
|
||||
* @property Fieldgroups|Fieldgroup[] $fieldgroups #pw-internal
|
||||
* @property Fields|Field[] $fields #pw-internal
|
||||
* @property Fieldtypes|Fieldtype[] $fieldtypes #pw-internal
|
||||
* @property WireFileTools $files #pw-internal
|
||||
* @property Fuel $fuel #pw-internal
|
||||
* @property WireHooks $hooks #pw-internal
|
||||
* @property WireInput $input #pw-internal
|
||||
* @property Languages $languages (present only if LanguageSupport installed) #pw-internal
|
||||
* @property Languages|Language[] $languages (present only if LanguageSupport installed) #pw-internal
|
||||
* @property WireLog $log #pw-internal
|
||||
* @property WireMailTools $mail #pw-internal
|
||||
* @property Modules $modules #pw-internal
|
||||
* @property Notices $notices #pw-internal
|
||||
* @property Notices|Notice[] $notices #pw-internal
|
||||
* @property Page $page #pw-internal
|
||||
* @property Pages $pages #pw-internal
|
||||
* @property Permissions $permissions #pw-internal
|
||||
* @property Permissions|Permission[] $permissions #pw-internal
|
||||
* @property Process|ProcessPageView $process #pw-internal
|
||||
* @property WireProfilerInterface $profiler #pw-internal
|
||||
* @property Roles $roles #pw-internal
|
||||
* @property Roles|Role[] $roles #pw-internal
|
||||
* @property Sanitizer $sanitizer #pw-internal
|
||||
* @property Session $session #pw-internal
|
||||
* @property Templates $templates #pw-internal
|
||||
* @property Templates|Template[] $templates #pw-internal
|
||||
* @property Paths $urls #pw-internal
|
||||
* @property User $user #pw-internal
|
||||
* @property Users $users #pw-internal
|
||||
@@ -408,7 +408,6 @@ abstract class Wire implements WireTranslatable, WireFuelable, WireTrackable {
|
||||
*/
|
||||
public function _callMethod($method, $arguments) {
|
||||
$qty = $arguments ? count($arguments) : 0;
|
||||
$result = null;
|
||||
switch($qty) {
|
||||
case 0:
|
||||
$result = $this->$method();
|
||||
@@ -1151,7 +1150,7 @@ abstract class Wire implements WireTranslatable, WireFuelable, WireTrackable {
|
||||
* #pw-group-changes
|
||||
*
|
||||
* @param bool $getMode When true, the track changes mode bitmask will be returned
|
||||
* @return int|bool 0/false if off, 1/true if On, or mode bitmask if requested
|
||||
* @return int 0/false if off, 1/true if On, or mode bitmask if requested
|
||||
*
|
||||
*/
|
||||
public function trackChanges($getMode = false) {
|
||||
@@ -1240,7 +1239,7 @@ abstract class Wire implements WireTranslatable, WireFuelable, WireTrackable {
|
||||
protected function _notice($text, $flags, $name, $class) {
|
||||
if($flags === true) $flags = Notice::log;
|
||||
$class = wireClassName($class, true);
|
||||
$notice = $this->wire(new $class($text, $flags));
|
||||
$notice = $this->wire(new $class($text, $flags)); /** @var Notice $notice */
|
||||
$notice->class = $this->className();
|
||||
if($this->_notices[$name] === null) $this->_notices[$name] = $this->wire(new Notices());
|
||||
$notices = $this->wire()->notices;
|
||||
@@ -1545,7 +1544,10 @@ abstract class Wire implements WireTranslatable, WireFuelable, WireTrackable {
|
||||
$value = array($value->text);
|
||||
} else {
|
||||
$_value = array();
|
||||
foreach($value as $notice) $_value[] = $notice->text;
|
||||
foreach($value as $notice) {
|
||||
/** @var Notice $notice */
|
||||
$_value[] = $notice->text;
|
||||
}
|
||||
$value = $_value;
|
||||
}
|
||||
if(in_array('string', $options)) {
|
||||
|
@@ -93,7 +93,8 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
if($this->className() === 'WireArray') $this->duplicateChecking = false;
|
||||
if($this->className() === 'WireArray') $this->duplicateChecking = false;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,7 +286,6 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
}
|
||||
}
|
||||
|
||||
$key = null;
|
||||
if($this->duplicateChecking && ($key = $this->getItemKey($item)) !== null) {
|
||||
// avoid two copies of the same item, re-add it to the end
|
||||
if(isset($this->data[$key])) unset($this->data[$key]);
|
||||
@@ -298,6 +298,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
|
||||
$this->trackChange("add", null, $item);
|
||||
$this->trackAdd($item, $key);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -409,14 +410,14 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
$k = null;
|
||||
if($value === $a) {
|
||||
if(method_exists($b, 'getItemKey')) {
|
||||
$k = $b->getItemKey();
|
||||
$k = $b->getItemKey(); // item provides its own key
|
||||
} else {
|
||||
$k = $this->getItemKey($b);
|
||||
}
|
||||
$value = $b;
|
||||
} else if($value === $b) {
|
||||
if(method_exists($a, 'getItemKey')) {
|
||||
$k = $a->getItemKey();
|
||||
$k = $a->getItemKey(); // item provides its own key
|
||||
} else {
|
||||
$k = $this->getItemKey($a);
|
||||
}
|
||||
@@ -554,7 +555,6 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
|
||||
// if given an array of keys, return all matching items
|
||||
if(is_array($key)) {
|
||||
/** @var array $key */
|
||||
if(ctype_digit(implode('', array_keys($key)))) {
|
||||
$items = array();
|
||||
foreach($key as $k) {
|
||||
@@ -611,7 +611,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
|
||||
// if the WireArray uses numeric keys, then it's okay to
|
||||
// match a 'name' field if the provided key is a string
|
||||
if(is_string($key) && $this->usesNumericKeys()) {
|
||||
if($this->usesNumericKeys()) {
|
||||
$match = $this->getItemThatMatches('name', $key);
|
||||
}
|
||||
}
|
||||
@@ -626,14 +626,14 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
* Not applicable to numerically indexed arrays.
|
||||
* Fuel properties and hooked properties have precedence with this type of call.
|
||||
*
|
||||
* @param int|string $property
|
||||
* @param int|string $name
|
||||
* @return Wire|WireData|Page|mixed|bool Value of item requested, or false if it doesn't exist.
|
||||
*
|
||||
*/
|
||||
public function __get($property) {
|
||||
$value = parent::__get($property);
|
||||
if(is_null($value)) $value = $this->getProperty($property);
|
||||
if(is_null($value)) $value = $this->get($property);
|
||||
public function __get($name) {
|
||||
$value = parent::__get($name);
|
||||
if(is_null($value)) $value = $this->getProperty($name);
|
||||
if(is_null($value)) $value = $this->get($name);
|
||||
return $value;
|
||||
}
|
||||
|
||||
@@ -693,7 +693,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
if(ctype_digit("$key")) return null;
|
||||
$item = null;
|
||||
foreach($this->data as $wire) {
|
||||
if(is_object($wire) && $wire instanceof Wire) {
|
||||
if($wire instanceof Wire) {
|
||||
if($wire->$key === $value) {
|
||||
$item = $wire;
|
||||
break;
|
||||
@@ -1056,7 +1056,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
reset($this->data);
|
||||
$key = key($this->data);
|
||||
$item = array_shift($this->data);
|
||||
if(is_null($item)) return $item;
|
||||
if(is_null($item)) return null;
|
||||
$this->trackChange('shift', $item, null);
|
||||
$this->trackRemove($item, $key);
|
||||
return $item;
|
||||
@@ -1092,7 +1092,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
end($this->data);
|
||||
$key = key($this->data);
|
||||
$item = array_pop($this->data);
|
||||
if(is_null($item)) return $item;
|
||||
if(is_null($item)) return null;
|
||||
$this->trackChange('pop', $item, null);
|
||||
$this->trackRemove($item, $key);
|
||||
return $item;
|
||||
@@ -1468,7 +1468,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
|
||||
// restore sorted array to lose sortable keys and restore proper keys
|
||||
$a = array();
|
||||
foreach($sortable as $key => $value) {
|
||||
foreach($sortable as $value) {
|
||||
if(is_array($value)) {
|
||||
// if more properties to sort by exist, use them for this sub-array
|
||||
$n = null;
|
||||
@@ -1476,7 +1476,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
if(count($properties)) {
|
||||
$value = $this->stableSort($value, $properties, $n);
|
||||
}
|
||||
foreach($value as $k => $v) {
|
||||
foreach($value as $v) {
|
||||
$newKey = $this->getItemKey($v);
|
||||
$a[$newKey] = $v;
|
||||
// are we done yet?
|
||||
@@ -1523,11 +1523,12 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*/
|
||||
protected function filterData($selectors, $not = false) {
|
||||
|
||||
if(is_object($selectors) && $selectors instanceof Selectors) {
|
||||
if($selectors instanceof Selectors) {
|
||||
$selectors = clone $selectors;
|
||||
} else {
|
||||
if(!is_array($selectors) && ctype_digit("$selectors")) $selectors = "id=$selectors";
|
||||
$selector = $selectors;
|
||||
/** @var Selectors $selectors */
|
||||
$selectors = $this->wire(new Selectors());
|
||||
$selectors->init($selector);
|
||||
}
|
||||
@@ -1832,13 +1833,13 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of item to set.
|
||||
* @param int|string $offset Key of item to set.
|
||||
* @param Wire|mixed $value Value of item.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($key, $value) {
|
||||
$this->set($key, $value);
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->set($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1846,14 +1847,14 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of item to retrieve.
|
||||
* @param int|string $offset Key of item to retrieve.
|
||||
* @return Wire|mixed|bool Value of item requested, or false if it doesn't exist.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($key) {
|
||||
if($this->offsetExists($key)) {
|
||||
return $this->data[$key];
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset) {
|
||||
if($this->offsetExists($offset)) {
|
||||
return $this->data[$offset];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -1866,14 +1867,14 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of the item to unset.
|
||||
* @param int|string $offset Key of the item to unset.
|
||||
* @return bool True if item existed and was unset. False if item didn't exist.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($key) {
|
||||
if($this->offsetExists($key)) {
|
||||
$this->remove($key);
|
||||
public function offsetUnset($offset) {
|
||||
if($this->offsetExists($offset)) {
|
||||
$this->remove($offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -1887,13 +1888,13 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of the item to check for existance.
|
||||
* @param int|string $offset Key of the item to check for existance.
|
||||
* @return bool True if the item exists, false if not.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($key) {
|
||||
return array_key_exists($key, $this->data);
|
||||
public function offsetExists($offset) {
|
||||
return array_key_exists($offset, $this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1904,7 +1905,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*/
|
||||
public function __toString() {
|
||||
$s = '';
|
||||
foreach($this as $key => $value) {
|
||||
foreach($this as $value) {
|
||||
if(is_array($value)) $value = "array(" . count($value) . ")";
|
||||
$s .= "$value|";
|
||||
}
|
||||
@@ -2153,6 +2154,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
$n = 0;
|
||||
|
||||
foreach($this as $key => $item) {
|
||||
/** @var WireData $item */
|
||||
if($isFunction) {
|
||||
$value = $property($item, $key);
|
||||
} else if(strlen($property) && $itemIsObject) {
|
||||
@@ -2213,9 +2215,10 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
$values[$key] = $item;
|
||||
continue;
|
||||
}
|
||||
/** @var WireData $item */
|
||||
if(!empty($options['key']) && is_string($options['key'])) {
|
||||
$key = $item->get($options['key']);
|
||||
if(!is_string($key) || !is_int($key)) $key = (string) $key;
|
||||
if(!is_string($key) && !is_int($key)) $key = (string) $key;
|
||||
if(!strlen($key)) continue;
|
||||
if(isset($values[$key])) continue;
|
||||
}
|
||||
@@ -2585,7 +2588,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
if(count($this->data)) {
|
||||
$info['items'] = array();
|
||||
foreach($this->data as $key => $value) {
|
||||
if(is_object($value) && $value instanceof Wire) $key = $value->className() . ":$key";
|
||||
if($value instanceof Wire) $key = $value->className() . ":$key";
|
||||
$info['items'][$key] = $this->debugInfoItem($value);
|
||||
}
|
||||
}
|
||||
@@ -2600,7 +2603,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
foreach($trackers as $key => $value) {
|
||||
if(!count($value)) continue;
|
||||
$info[$key] = array();
|
||||
foreach($value as $k => $v) {
|
||||
foreach($value as $v) {
|
||||
$info[$key][] = $this->debugInfoItem($v);
|
||||
}
|
||||
}
|
||||
@@ -2638,7 +2641,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
* @return mixed
|
||||
* @return WireArray
|
||||
* @throws WireException
|
||||
*
|
||||
*/
|
||||
|
@@ -21,7 +21,7 @@
|
||||
*
|
||||
* May also be accessed as array.
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @method WireArray and($items = null)
|
||||
@@ -326,12 +326,12 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
*
|
||||
* Otherwise the same as get()
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $name
|
||||
* @return mixed|null
|
||||
*
|
||||
*/
|
||||
public function __get($key) {
|
||||
return $this->get($key);
|
||||
public function __get($name) {
|
||||
return $this->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,6 +437,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
// single item
|
||||
$className = $this->className(true) . 'Array';
|
||||
if(!class_exists($className)) $className = wireClassName('WireArray', true);
|
||||
/** @var WireArray $a */
|
||||
$a = $this->wire(new $className());
|
||||
$a->add($this);
|
||||
if($items) $a->add($items);
|
||||
@@ -480,13 +481,13 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of item to set.
|
||||
* @param int|string $offset Key of item to set.
|
||||
* @param int|string|array|object $value Value of item.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($key, $value) {
|
||||
$this->set($key, $value);
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->set($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,13 +495,13 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of item to retrieve.
|
||||
* @param int|string $offset Key of item to retrieve.
|
||||
* @return int|string|array|object Value of item requested, or false if it doesn't exist.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($key) {
|
||||
$value = $this->get($key);
|
||||
public function offsetGet($offset) {
|
||||
$value = $this->get($offset);
|
||||
return is_null($value) ? false : $value;
|
||||
}
|
||||
|
||||
@@ -511,14 +512,14 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of the item to unset.
|
||||
* @param int|string $offset Key of the item to unset.
|
||||
* @return bool True if item existed and was unset. False if item didn't exist.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($key) {
|
||||
if($this->__isset($key)) {
|
||||
$this->remove($key);
|
||||
public function offsetUnset($offset) {
|
||||
if($this->__isset($offset)) {
|
||||
$this->remove($offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -532,13 +533,13 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param int|string $key Key of the item to check for existence.
|
||||
* @param int|string $offset Key of the item to check for existence.
|
||||
* @return bool True if the item exists, false if not.
|
||||
*
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($key) {
|
||||
return $this->__isset($key);
|
||||
public function offsetExists($offset) {
|
||||
return $this->__isset($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -144,7 +144,7 @@ class WireDataDB extends WireData implements \Countable {
|
||||
$table = $this->table();
|
||||
$sql = "DELETE FROM `$table` WHERE source_id=:source_id ";
|
||||
if($name !== true) $sql .= "AND name=:name";
|
||||
$query = $this->wire('database')->prepare($sql);
|
||||
$query = $this->wire()->database->prepare($sql);
|
||||
$query->bindValue(':source_id', $this->sourceID(), \PDO::PARAM_INT);
|
||||
if($name !== true) $query->bindValue(':name', $name);
|
||||
try {
|
||||
@@ -171,7 +171,7 @@ class WireDataDB extends WireData implements \Countable {
|
||||
$table = $this->table();
|
||||
$sql = "SELECT name, data FROM `$table` WHERE source_id=:source_id ";
|
||||
if($name !== true) $sql .= "AND name=:name ";
|
||||
$query = $this->wire('database')->prepare($sql);
|
||||
$query = $this->wire()->database->prepare($sql);
|
||||
$query->bindValue(':source_id', $this->sourceID(), \PDO::PARAM_INT);
|
||||
if($name !== true) $query->bindValue(':name', $name);
|
||||
try {
|
||||
@@ -257,7 +257,7 @@ class WireDataDB extends WireData implements \Countable {
|
||||
public function count() {
|
||||
$table = $this->table();
|
||||
$sql = "SELECT COUNT(*) FROM `$table` WHERE source_id=:source_id";
|
||||
$query = $this->wire('database')->prepare($sql);
|
||||
$query = $this->wire()->database->prepare($sql);
|
||||
$query->bindValue(':source_id', $this->sourceID(), \PDO::PARAM_INT);
|
||||
try {
|
||||
$query->execute();
|
||||
@@ -332,13 +332,15 @@ class WireDataDB extends WireData implements \Countable {
|
||||
*
|
||||
*/
|
||||
public function install() {
|
||||
$engine = $this->wire('config')->dbEngine;
|
||||
$charset = $this->wire('config')->dbCharset;
|
||||
$config = $this->wire()->config;
|
||||
$database = $this->wire()->database;
|
||||
$engine = $config->dbEngine;
|
||||
$charset = $config->dbCharset;
|
||||
$table = $this->table();
|
||||
if($this->wire('database')->tableExists($table)) return false;
|
||||
if($database->tableExists($table)) return false;
|
||||
$schema = implode(', ', $this->schema());
|
||||
$sql = "CREATE TABLE `$table` ($schema) ENGINE=$engine DEFAULT CHARSET=$charset";
|
||||
$this->wire('database')->exec($sql);
|
||||
$this->database->exec($sql);
|
||||
$this->message("Added '$table' table to database");
|
||||
return true;
|
||||
}
|
||||
@@ -352,7 +354,7 @@ class WireDataDB extends WireData implements \Countable {
|
||||
*/
|
||||
public function uninstall() {
|
||||
$table = $this->table();
|
||||
$this->wire('database')->exec("DROP TABLE `$table`");
|
||||
$this->wire()->database->exec("DROP TABLE `$table`");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -361,4 +363,4 @@ class WireDataDB extends WireData implements \Countable {
|
||||
return new \ArrayObject($this->getArray());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -873,7 +873,6 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
||||
$pdoStatement = $pdo->prepare($statement, $driver_options);
|
||||
if($this->debugMode) {
|
||||
if($pdoStatement instanceof WireDatabasePDOStatement) {
|
||||
/** @var WireDatabasePDOStatement $pdoStatement */
|
||||
$pdoStatement->setDebugNote($note);
|
||||
} else {
|
||||
$this->queryLog($statement, $note);
|
||||
@@ -897,7 +896,7 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
||||
*
|
||||
*/
|
||||
public function exec($statement, $note = '') {
|
||||
if(is_object($statement) && $statement instanceof \PDOStatement) {
|
||||
if($statement instanceof \PDOStatement) {
|
||||
return $this->execute($statement);
|
||||
}
|
||||
if($this->debugMode) $this->queryLog($statement, $note);
|
||||
@@ -978,7 +977,7 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
||||
*
|
||||
* @param string|bool $sql Query (string) to log, boolean true to reset/start query logging, boolean false to stop query logging
|
||||
* @param string $note Any additional debugging notes about the query
|
||||
* @return array|bool|int Returns query log array, boolean true on success, boolean false if not
|
||||
* @return array|bool Returns query log array, boolean true on success, boolean false if not
|
||||
*
|
||||
*/
|
||||
public function queryLog($sql = '', $note = '') {
|
||||
@@ -1592,16 +1591,16 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $name
|
||||
* @return mixed|null|\PDO
|
||||
*
|
||||
*/
|
||||
public function __get($key) {
|
||||
if($key === 'pdo') return $this->pdo();
|
||||
if($key === 'pdoReader') return $this->pdoReader();
|
||||
if($key === 'pdoWriter') return $this->pdoWriter();
|
||||
if($key === 'debugMode') return $this->debugMode;
|
||||
return parent::__get($key);
|
||||
public function __get($name) {
|
||||
if($name === 'pdo') return $this->pdo();
|
||||
if($name === 'pdoReader') return $this->pdoReader();
|
||||
if($name === 'pdoWriter') return $this->pdoWriter();
|
||||
if($name === 'debugMode') return $this->debugMode;
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1641,7 +1640,6 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
||||
$query = $this->prepare('SHOW VARIABLES WHERE Variable_name=:name');
|
||||
$query->bindValue(':name', $name);
|
||||
$query->execute();
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
if($query->rowCount()) {
|
||||
list(,$value) = $query->fetch(\PDO::FETCH_NUM);
|
||||
$this->variableCache[$name] = $value;
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* This class is for internal use. You should manipulate hooks from Wire-derived classes instead.
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*/
|
||||
@@ -235,7 +235,7 @@ class WireHooks {
|
||||
if($_namespace !== $namespace) {
|
||||
// objects in other namespaces
|
||||
$_className = $_namespace . $className;
|
||||
if(!$object instanceof $_className && $method !== '*') {
|
||||
if(!$object instanceof $_className) { // && $method !== '*') {
|
||||
// object likely extends a class not in PW namespace, so check class parents instead
|
||||
if(empty($objectParentNamespaces)) {
|
||||
foreach(wireClassParents($object) as $nscn => $cn) {
|
||||
@@ -280,7 +280,7 @@ class WireHooks {
|
||||
// no method specified, retrieve all for class
|
||||
// note: priority-based array indexes are no longer in tact
|
||||
$hooks = array_values($hooks);
|
||||
foreach($staticHooks as $_method => $methodHooks) {
|
||||
foreach($staticHooks as /* $_method => */ $methodHooks) {
|
||||
$hooks = array_merge($hooks, array_values($methodHooks));
|
||||
}
|
||||
}
|
||||
@@ -605,6 +605,7 @@ class WireHooks {
|
||||
list($fromClass, $objMatch) = explode('(', $fromClass, 2);
|
||||
$objMatch = trim($objMatch, ') ');
|
||||
if(Selectors::stringHasSelector($objMatch)) {
|
||||
/** @var Selectors $selectors */
|
||||
$selectors = $this->wire->wire(new Selectors());
|
||||
$selectors->init($objMatch);
|
||||
$objMatch = $selectors;
|
||||
@@ -644,6 +645,7 @@ class WireHooks {
|
||||
if(is_string($argMatch)) $argMatch = array(0 => $argMatch);
|
||||
foreach($argMatch as $argKey => $argVal) {
|
||||
if(Selectors::stringHasSelector($argVal)) {
|
||||
/** @var Selectors $selectors */
|
||||
$selectors = $this->wire->wire(new Selectors());
|
||||
$selectors->init($argVal);
|
||||
$argMatch[$argKey] = $selectors;
|
||||
@@ -720,7 +722,7 @@ class WireHooks {
|
||||
// keep track of all local hooks combined when debug mode is on
|
||||
if($local && $this->config->debug) {
|
||||
$debugClass = $object->className();
|
||||
$debugID = ($local ? $debugClass : '') . $id;
|
||||
$debugID = $debugClass . $id;
|
||||
while(isset($this->allLocalHooks[$debugID])) $debugID .= "_";
|
||||
$debugHook = $hooks[$method][$priority];
|
||||
$debugHook['method'] = $debugClass . "->" . $debugHook['method'];
|
||||
@@ -857,7 +859,6 @@ class WireHooks {
|
||||
}
|
||||
|
||||
// test the filter to see which one will match
|
||||
$pos = false;
|
||||
foreach(array("/$filter/", "/$filter", "$filter/") as $test) {
|
||||
$pos = strpos($path, $test);
|
||||
if($pos === false) continue;
|
||||
@@ -908,7 +909,7 @@ class WireHooks {
|
||||
$hookTimer = self::___debug ? $this->hookTimer($object, $method, $arguments) : null;
|
||||
$realMethod = "___$method";
|
||||
$cancelHooks = false;
|
||||
$profiler = $this->wire->wire('profiler');
|
||||
$profiler = $this->wire->wire()->profiler;
|
||||
$hooks = null;
|
||||
$methodExists = false;
|
||||
$useHookReturnValue = false; // allow use of "return $value;" in hook in addition to $event->return ?
|
||||
@@ -959,7 +960,7 @@ class WireHooks {
|
||||
if($when === 'after') break;
|
||||
}
|
||||
|
||||
foreach($hooks as $priority => $hook) {
|
||||
foreach($hooks as /* $priority => */ $hook) {
|
||||
|
||||
if(!$hook['options'][$when]) continue;
|
||||
if($type === 'property' && $hook['options']['type'] === 'method') continue;
|
||||
@@ -1402,4 +1403,4 @@ class WireHooks {
|
||||
return $this->className();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -122,6 +122,7 @@ class WireInput extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->useFuel(false);
|
||||
$this->unregisterGLOBALS();
|
||||
}
|
||||
@@ -789,8 +790,8 @@ class WireInput extends Wire {
|
||||
if(!$verbose) return $str;
|
||||
|
||||
// verbose mode takes page number, slash settings, and other $options into account
|
||||
$page = isset($options['page']) && $options['page'] instanceof Page ? $options['page'] : $this->wire('page');
|
||||
$template = $page->template;
|
||||
$page = isset($options['page']) && $options['page'] instanceof Page ? $options['page'] : $this->wire()->page;
|
||||
$template = $page->template;
|
||||
|
||||
if(isset($options['pageNum'])) {
|
||||
$pageNum = (int) $options['pageNum'];
|
||||
@@ -856,7 +857,7 @@ class WireInput extends Wire {
|
||||
$pageNumStr = '';
|
||||
$pageNum = (int) $pageNum;
|
||||
if($pageNum < 1) $pageNum = $this->pageNum();
|
||||
if($pageNum > 1) $pageNumStr = $this->wire('config')->pageNumUrlPrefix . $pageNum;
|
||||
if($pageNum > 1) $pageNumStr = $this->wire()->config->pageNumUrlPrefix . $pageNum;
|
||||
return $pageNumStr;
|
||||
}
|
||||
|
||||
@@ -918,7 +919,7 @@ class WireInput extends Wire {
|
||||
} else {
|
||||
// Like PHP's $_REQUEST where accessing $input->var considers get/post/cookie/whitelist
|
||||
// what it actually considers depends on what's set in the $config->wireInputOrder variable
|
||||
$order = (string) $this->wire('config')->wireInputOrder;
|
||||
$order = (string) $this->wire()->config->wireInputOrder;
|
||||
if(!$order) return null;
|
||||
$types = explode(' ', $order);
|
||||
foreach($types as $t) {
|
||||
@@ -964,7 +965,7 @@ class WireInput extends Wire {
|
||||
|
||||
$defaults = array(
|
||||
'withQueryString' => is_bool($options) ? $options : false,
|
||||
'page' => $this->wire('page'),
|
||||
'page' => $this->wire()->page,
|
||||
'pageNum' => 0,
|
||||
);
|
||||
|
||||
@@ -972,8 +973,8 @@ class WireInput extends Wire {
|
||||
|
||||
/** @var Page $page */
|
||||
$page = $options['page'];
|
||||
$config = $this->wire('config');
|
||||
$sanitizer = $this->wire('sanitizer');
|
||||
$config = $this->wire()->config;
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$url = '';
|
||||
|
||||
if($page && $page->id) {
|
||||
@@ -1093,12 +1094,12 @@ class WireInput extends Wire {
|
||||
*/
|
||||
public function httpHostUrl($scheme = null, $httpHost = '') {
|
||||
if(empty($httpHost)) {
|
||||
$httpHost = $this->wire('config')->httpHost;
|
||||
$httpHost = $this->wire()->config->httpHost;
|
||||
}
|
||||
if($scheme === true) {
|
||||
$scheme = 'https://';
|
||||
} else if($scheme === false) {
|
||||
$scheme = 'http://';
|
||||
$scheme = 'http' . '://';
|
||||
} else if(is_string($scheme)) {
|
||||
if(strlen($scheme)) {
|
||||
if(strpos($scheme, '//') === false) $scheme = "$scheme://";
|
||||
@@ -1140,7 +1141,7 @@ class WireInput extends Wire {
|
||||
public function canonicalUrl(array $options = array()) {
|
||||
|
||||
$defaults = array(
|
||||
'page' => $this->wire('page'),
|
||||
'page' => $this->wire()->page,
|
||||
'scheme' => '',
|
||||
'host' => '',
|
||||
'urlSegments' => true,
|
||||
@@ -1155,7 +1156,7 @@ class WireInput extends Wire {
|
||||
$pageUrl = $page->url();
|
||||
$template = $page->template;
|
||||
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
|
||||
$languages = $this->wire('languages'); /** @var Languages|null $languages */
|
||||
$languages = $this->wire()->languages;
|
||||
$language = $options['language']; /** @var Language|int|string|bool */
|
||||
|
||||
if(is_string($options['notSegments'])) {
|
||||
@@ -1163,7 +1164,6 @@ class WireInput extends Wire {
|
||||
}
|
||||
|
||||
if($language !== true && $languages) {
|
||||
$language = $options['language'];
|
||||
if($language === false) {
|
||||
$language = $languages->getDefault();
|
||||
} else if(!$language instanceof Language) {
|
||||
@@ -1291,7 +1291,7 @@ class WireInput extends Wire {
|
||||
// bundle in scheme and host and return canonical URL
|
||||
$url = $this->httpHostUrl($scheme, $options['host']) . $url;
|
||||
|
||||
if($page->of()) $url = $this->wire('sanitizer')->entities($url);
|
||||
if($page->of()) $url = $this->wire()->sanitizer->entities($url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
@@ -1514,7 +1514,7 @@ class WireInput extends Wire {
|
||||
*
|
||||
*/
|
||||
public function scheme() {
|
||||
return $this->wire('config')->https ? 'https' : 'http';
|
||||
return $this->wire()->config->https ? 'https' : 'http';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1597,7 +1597,7 @@ class WireInput extends Wire {
|
||||
|
||||
} else if($value === null && $valid === null && $fallback === null) {
|
||||
// everything null
|
||||
$cleanValue = null;
|
||||
// $cleanValue = null;
|
||||
|
||||
} else if($valid === null) {
|
||||
// no sanitization/validation requested
|
||||
@@ -1845,7 +1845,7 @@ class WireInput extends Wire {
|
||||
protected function patternMatchesValue($pattern, $value, $partial = false) {
|
||||
if(is_array($value)) {
|
||||
$result = '';
|
||||
foreach($value as $k => $v) {
|
||||
foreach($value as $v) {
|
||||
$result = $this->patternMatchesValue($pattern, $v, $partial);
|
||||
if($result !== '') break;
|
||||
}
|
||||
|
@@ -94,6 +94,7 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C
|
||||
*
|
||||
*/
|
||||
public function __construct(&$input = array(), $lazy = false) {
|
||||
parent::__construct();
|
||||
$this->useFuel(false);
|
||||
if(version_compare(PHP_VERSION, '5.4.0', '<') && function_exists('get_magic_quotes_gpc')) {
|
||||
$this->stripSlashes = get_magic_quotes_gpc();
|
||||
|
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* #pw-body
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @property LanguageTabs|null $tabs Current LanguageTabs module instance, if installed #pw-internal
|
||||
@@ -215,7 +215,7 @@ class Languages extends PagesType {
|
||||
*/
|
||||
public function findOther($selector = '', $excludeLanguage = null) {
|
||||
if(is_null($excludeLanguage)) {
|
||||
if(is_object($selector) && $selector instanceof Language) {
|
||||
if($selector instanceof Language) {
|
||||
$excludeLanguage = $selector;
|
||||
$selector = '';
|
||||
} else {
|
||||
@@ -386,8 +386,8 @@ class Languages extends PagesType {
|
||||
*
|
||||
*/
|
||||
public function getLanguage($name = '') {
|
||||
if($name !== '') return is_object($name) && $name instanceof Language ? $name : $this->get($name);
|
||||
return $this->wire('user')->language;
|
||||
if($name !== '') return ($name instanceof Language ? $name : $this->get($name));
|
||||
return $this->wire()->user->language;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,7 +463,7 @@ class Languages extends PagesType {
|
||||
|
||||
if($locale === null || is_object($locale)) {
|
||||
// argument omitted means set according to language settings
|
||||
$language = $locale instanceof Language ? $locale : $this->wire('user')->language;
|
||||
$language = $locale instanceof Language ? $locale : $this->wire()->user->language;
|
||||
$textdomain = 'wire--modules--languagesupport--languagesupport-module';
|
||||
$locale = $language->translator()->getTranslation($textdomain, 'C');
|
||||
}
|
||||
@@ -650,7 +650,7 @@ class Languages extends PagesType {
|
||||
// if previously identified as installed or instance loaded, return true
|
||||
if($this->pageNames) return true;
|
||||
// if previously identified as NOT installed, return false
|
||||
if($this->pageNames=== false) return false;
|
||||
if($this->pageNames === false) return false;
|
||||
// populate with installed status boolean and return it
|
||||
$this->pageNames = $this->wire()->modules->isInstalled('LanguageSupportPageNames');
|
||||
return $this->pageNames;
|
||||
@@ -794,24 +794,24 @@ class Languages extends PagesType {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $name
|
||||
* @return mixed|Language
|
||||
*
|
||||
*/
|
||||
public function __get($key) {
|
||||
if($key === 'tabs') {
|
||||
public function __get($name) {
|
||||
if($name === 'tabs') {
|
||||
$ls = $this->wire()->modules->get('LanguageSupport'); /** @var LanguageSupport $ls */
|
||||
return $ls->getLanguageTabs();
|
||||
} else if($key === 'default') {
|
||||
} else if($name === 'default') {
|
||||
return $this->getDefault();
|
||||
} else if($key === 'support') {
|
||||
} else if($name === 'support') {
|
||||
return $this->wire()->modules->get('LanguageSupport');
|
||||
} else if($key === 'pageNames') {
|
||||
} else if($name === 'pageNames') {
|
||||
return $this->pageNames();
|
||||
} else if($key === 'hasPageNames') {
|
||||
} else if($name === 'hasPageNames') {
|
||||
return $this->hasPageNames();
|
||||
}
|
||||
return parent::__get($key);
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -875,20 +875,22 @@ class Languages extends PagesType {
|
||||
$table = $matches[1];
|
||||
// $col = $matches[2];
|
||||
$languageID = (int) $matches[3];
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$fields = $this->wire()->fields;
|
||||
|
||||
foreach($this->wire('languages') as $language) {
|
||||
if($language->id == $languageID) {
|
||||
$this->warning("language $language->name is missing column $column", Notice::debug);
|
||||
if($table == 'pages' && $this->wire('modules')->isInstalled('LanguageSupportPageNames')) {
|
||||
$module = $this->wire('modules')->get('LanguageSupportPageNames');
|
||||
$module->languageAdded($language);
|
||||
} else if(strpos($table, 'field_') === 0) {
|
||||
$fieldName = substr($table, strpos($table, '_')+1);
|
||||
$field = $this->wire('fields')->get($fieldName);
|
||||
if($field && $this->wire('modules')->isInstalled('LanguageSupportFields')) {
|
||||
$module = $this->wire('modules')->get('LanguageSupportFields');
|
||||
$module->fieldLanguageAdded($field, $language);
|
||||
}
|
||||
foreach($this as $language) {
|
||||
if($language->id != $languageID) continue;
|
||||
$this->warning("language $language->name is missing column $column", Notice::debug);
|
||||
if($table == 'pages' && $this->hasPageNames()) {
|
||||
$this->pageNames()->languageAdded($language);
|
||||
} else if(strpos($table, 'field_') === 0) {
|
||||
$fieldName = substr($table, strpos($table, '_')+1);
|
||||
$field = $fields->get($fieldName);
|
||||
if($field && $modules->isInstalled('LanguageSupportFields')) {
|
||||
/** @var LanguageSupportFields $module */
|
||||
$module = $modules->get('LanguageSupportFields');
|
||||
$module->fieldLanguageAdded($field, $language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user