1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00

Minor code updates in various classes

This commit is contained in:
Ryan Cramer
2023-09-22 15:26:45 -04:00
parent a0fabd6811
commit 17e07e7859
10 changed files with 87 additions and 74 deletions

View File

@@ -95,6 +95,7 @@ class ImageSizer extends Wire {
* *
*/ */
public function __construct($filename = '', $options = array()) { public function __construct($filename = '', $options = array()) {
parent::__construct();
if(!empty($options)) $this->setOptions($options); if(!empty($options)) $this->setOptions($options);
if(!empty($filename)) $this->setFilename($filename); if(!empty($filename)) $this->setFilename($filename);
} }
@@ -114,7 +115,7 @@ class ImageSizer extends Wire {
self::$knownEngines = array(); self::$knownEngines = array();
$modules = $this->wire('modules'); $modules = $this->wire()->modules;
$engines = $modules->findByPrefix('ImageSizerEngine'); $engines = $modules->findByPrefix('ImageSizerEngine');
$numEngines = count($engines); $numEngines = count($engines);
@@ -228,7 +229,6 @@ class ImageSizer extends Wire {
$e = $this->getEngine($engineName); $e = $this->getEngine($engineName);
if(!$e) continue; if(!$e) continue;
/** @var ImageSizerEngine $e */
$e->prepare($filename, $options, $inspectionResult); $e->prepare($filename, $options, $inspectionResult);
$supported = $e->supported(); $supported = $e->supported();
@@ -430,7 +430,7 @@ class ImageSizer extends Wire {
$engineClass = __NAMESPACE__ . "\\$engineName"; $engineClass = __NAMESPACE__ . "\\$engineName";
$engine = $this->wire(new $engineClass()); $engine = $this->wire(new $engineClass());
} else { } else {
$engine = $this->wire('modules')->get($engineName); $engine = $this->wire()->modules->get($engineName);
} }
return $engine; return $engine;
} }
@@ -452,7 +452,7 @@ class ImageSizer extends Wire {
return $this->engine; return $this->engine;
} }
public function __get($key) { return $this->getEngine()->__get($key); } public function __get($name) { return $this->getEngine()->__get($name); }
/** /**
* ImageInformation from Image Inspector in short form or full RawInfoData * ImageInformation from Image Inspector in short form or full RawInfoData
@@ -607,7 +607,7 @@ class ImageSizer extends Wire {
$count = 0; $count = 0;
while(!feof($fh) && $count < 2) { while(!feof($fh) && $count < 2) {
$chunk = fread($fh, 1024 * 100); //read 100kb at a time $chunk = fread($fh, 1024 * 100); //read 100kb at a time
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches); $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk);
} }
fclose($fh); fclose($fh);
return $count > 1; return $count > 1;
@@ -618,7 +618,7 @@ class ImageSizer extends Wire {
* *
* @param mixed $image Pageimage or filename * @param mixed $image Pageimage or filename
* *
* @return mixed|null|bool * @return null|bool
* *
*/ */
static public function imageResetIPTC($image) { static public function imageResetIPTC($image) {

View File

@@ -399,7 +399,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
$this->inspectionResult = $inspectionResult; $this->inspectionResult = $inspectionResult;
// filling all options with global custom values from config.php // filling all options with global custom values from config.php
$options = array_merge($this->wire('config')->imageSizerOptions, $options); $options = array_merge($this->wire()->config->imageSizerOptions, $options);
$this->setOptions($options); $this->setOptions($options);
$this->loadImageInfo($filename, false); $this->loadImageInfo($filename, false);
} }
@@ -521,7 +521,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
if(is_callable("$className::getModuleInfo")) { if(is_callable("$className::getModuleInfo")) {
$moduleInfo = $className::getModuleInfo(); $moduleInfo = $className::getModuleInfo();
} else { } else {
$moduleInfo = $this->wire('modules')->getModuleInfoVerbose($className); $moduleInfo = $this->wire()->modules->getModuleInfoVerbose($className);
} }
if(!is_array($moduleInfo)) $moduleInfo = array(); if(!is_array($moduleInfo)) $moduleInfo = array();
@@ -635,7 +635,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
* *
*/ */
public function writeBackIPTC($filename, $includeCustomTags = false) { public function writeBackIPTC($filename, $includeCustomTags = false) {
if($this->wire('config')->debug) { if($this->wire()->config->debug) {
// add a timestamp and the name of the image sizer engine to the IPTC tag number 217 // add a timestamp and the name of the image sizer engine to the IPTC tag number 217
$entry = $this->className() . '-' . date('Ymd:His'); $entry = $this->className() . '-' . date('Ymd:His');
if(!$this->iptcRaw) $this->iptcRaw = array(); if(!$this->iptcRaw) $this->iptcRaw = array();
@@ -648,9 +648,10 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
$dest = preg_replace('/\.' . $extension . '$/', '_tmp.' . $extension, $filename); $dest = preg_replace('/\.' . $extension . '$/', '_tmp.' . $extension, $filename);
if(strlen($content) == @file_put_contents($dest, $content, \LOCK_EX)) { if(strlen($content) == @file_put_contents($dest, $content, \LOCK_EX)) {
// on success we replace the file // on success we replace the file
$this->wire('files')->unlink($filename); $files = $this->wire()->files;
$this->wire('files')->rename($dest, $filename); $files->unlink($filename);
$this->wire('files')->chmod($filename); $files->rename($dest, $filename);
$files->chmod($filename);
return true; return true;
} else { } else {
// it was created a temp diskfile but not with all data in it // it was created a temp diskfile but not with all data in it
@@ -1460,7 +1461,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
/** /**
* Return the image type constant * Return the image type constant
* *
* @return string * @return string|null
* *
*/ */
public function getImageType() { public function getImageType() {
@@ -1731,14 +1732,16 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
return false; // fallback or failed return false; // fallback or failed
} }
$files = $this->wire()->files;
if($this->webpOnly) { if($this->webpOnly) {
$this->wire('files')->unlink($this->tmpFile); $files->unlink($this->tmpFile);
} else { } else {
// all went well, copy back the temp file, // all went well, copy back the temp file,
if(!@copy($this->tmpFile, $this->filename)) return false; // fallback or failed if(!@copy($this->tmpFile, $this->filename)) return false; // fallback or failed
$this->wire('files')->chmod($this->filename); $files->chmod($this->filename);
// remove the temp file // remove the temp file
$this->wire('files')->unlink($this->tmpFile); $files->unlink($this->tmpFile);
// post processing: IPTC, setModified and reload ImageInfo // post processing: IPTC, setModified and reload ImageInfo
$this->writeBackIPTC($this->filename, false); $this->writeBackIPTC($this->filename, false);
} }
@@ -1758,6 +1761,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
*/ */
public function rotate($degrees, $dstFilename = '') { public function rotate($degrees, $dstFilename = '') {
$files = $this->wire()->files;
$degrees = (int) $degrees; $degrees = (int) $degrees;
$srcFilename = $this->filename; $srcFilename = $this->filename;
@@ -1767,7 +1771,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
if($degrees < -360) $degrees = $degrees - 360; if($degrees < -360) $degrees = $degrees - 360;
if($degrees == 0 || $degrees == 360 || $degrees == -360) { if($degrees == 0 || $degrees == 360 || $degrees == -360) {
if($dstFilename != $this->filename) wireCopy($this->filename, $dstFilename); if($dstFilename != $this->filename) $files->copy($this->filename, $dstFilename);
return true; return true;
} }
@@ -1787,13 +1791,13 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
if($result) { if($result) {
// success // success
if($tmpFilename != $dstFilename) { if($tmpFilename != $dstFilename) {
if(is_file($dstFilename)) $this->wire('files')->unlink($dstFilename); if(is_file($dstFilename)) $files->unlink($dstFilename);
$this->wire('files')->rename($tmpFilename, $dstFilename); $files->rename($tmpFilename, $dstFilename);
} }
$this->wire('files')->chmod($dstFilename); $files->chmod($dstFilename);
} else { } else {
// fail // fail
if(is_file($tmpFilename)) $this->wire('files')->unlink($tmpFilename); if(is_file($tmpFilename)) $files->unlink($tmpFilename);
} }
return $result; return $result;
@@ -2076,7 +2080,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
*/ */
public function getModuleConfigInputfields(InputfieldWrapper $inputfields) { public function getModuleConfigInputfields(InputfieldWrapper $inputfields) {
$f = $this->wire('modules')->get('InputfieldInteger'); $f = $inputfields->InputfieldInteger;
$f->attr('name', 'enginePriority'); $f->attr('name', 'enginePriority');
$f->label = $this->_('Engine priority'); $f->label = $this->_('Engine priority');
$f->description = $this->_('This determines what order this engine is tried in relation to other ImageSizerEngine modules.'); $f->description = $this->_('This determines what order this engine is tried in relation to other ImageSizerEngine modules.');
@@ -2086,7 +2090,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
$f->icon = 'sort-numeric-asc'; $f->icon = 'sort-numeric-asc';
$inputfields->add($f); $inputfields->add($f);
$f = $this->wire('modules')->get('InputfieldRadios'); $f = $inputfields->InputfieldRadios;
$f->attr('name', 'sharpening'); $f->attr('name', 'sharpening');
$f->label = $this->_('Sharpening'); $f->label = $this->_('Sharpening');
$f->addOption('none', $this->_('None')); $f->addOption('none', $this->_('None'));
@@ -2098,7 +2102,7 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
$f->icon = 'image'; $f->icon = 'image';
$inputfields->add($f); $inputfields->add($f);
$f = $this->wire('modules')->get('InputfieldInteger'); $f = $inputfields->InputfieldInteger;
$f->attr('name', 'quality'); $f->attr('name', 'quality');
$f->label = $this->_('Quality'); $f->label = $this->_('Quality');
$f->description = $this->_('Default quality setting from 1 to 100 where 1 is lowest quality, and 100 is highest.'); $f->description = $this->_('Default quality setting from 1 to 100 where 1 is lowest quality, and 100 is highest.');

View File

@@ -377,7 +377,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
} }
// write to file(s) // write to file(s)
if(file_exists($dstFilename)) $this->wire('files')->unlink($dstFilename); if(file_exists($dstFilename)) $this->wire()->files->unlink($dstFilename);
$result = null; // null=not yet known $result = null; // null=not yet known
@@ -457,7 +457,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
if(!function_exists('imagewebp')) return false; if(!function_exists('imagewebp')) return false;
$path_parts = pathinfo($filename); $path_parts = pathinfo($filename);
$webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; $webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp';
if(file_exists($webpFilename)) $this->wire('files')->unlink($webpFilename); if(file_exists($webpFilename)) $this->wire()->files->unlink($webpFilename);
return imagewebp($im, $webpFilename, $quality); return imagewebp($im, $webpFilename, $quality);
} }

View File

@@ -12,7 +12,7 @@
* Pagefile objects are contained by a `Pagefiles` object. * Pagefile objects are contained by a `Pagefiles` object.
* #pw-body * #pw-body
* *
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @property-read string $url URL to the file on the server. * @property-read string $url URL to the file on the server.
@@ -357,7 +357,7 @@ class Pagefile extends WireData implements WireArrayItem {
$key = $type === 'created' ? '_createdUser' : '_modifiedUser'; $key = $type === 'created' ? '_createdUser' : '_modifiedUser';
if(!$this->$key) { if(!$this->$key) {
$id = (int) parent::get($type . '_users_id'); $id = (int) parent::get($type . '_users_id');
$this->$key = $id ? $this->wire('users')->get($id) : new NullPage(); $this->$key = ($id ? $this->wire()->users->get($id) : new NullPage());
} }
return $this->$key; return $this->$key;
} }
@@ -577,7 +577,7 @@ class Pagefile extends WireData implements WireArrayItem {
if(is_null($language)) { if(is_null($language)) {
// return description for current user language, or inherit from default if not available // return description for current user language, or inherit from default if not available
$user = $this->wire('user'); $user = $this->wire()->user;
$value = null; $value = null;
if($user->language && $user->language->id) { if($user->language && $user->language->id) {
$value = parent::get("description{$user->language}"); $value = parent::get("description{$user->language}");

View File

@@ -38,7 +38,7 @@
* Typically a Pagefiles object will be associated with a specific field attached to a Page. * Typically a Pagefiles object will be associated with a specific field attached to a Page.
* There may be multiple instances of Pagefiles attached to a given Page (depending on what fields are in it's fieldgroup). * There may be multiple instances of Pagefiles attached to a given Page (depending on what fields are in it's fieldgroup).
* *
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* *
@@ -304,13 +304,13 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
/** /**
* Get for direct access to properties * Get for direct access to properties
* *
* @param int|string $property * @param int|string $name
* @return bool|mixed|Page|Wire|WireData * @return bool|mixed|Page|Wire|WireData
* *
*/ */
public function __get($property) { public function __get($name) {
if(in_array($property, array('page', 'field', 'url', 'path'))) return $this->get($property); if(in_array($name, array('page', 'field', 'url', 'path'))) return $this->get($name);
return parent::__get($property); return parent::__get($name);
} }
/** /**
@@ -375,7 +375,9 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
*/ */
public function hookPageSave() { public function hookPageSave() {
if($this->page && $this->field && !$this->page->isChanged($this->field->name)) return $this; if($this->page && $this->field) {
if(!$this->page->isChanged($this->field->name)) return $this;
}
$this->page->filesManager()->uncache(); $this->page->filesManager()->uncache();
@@ -780,12 +782,13 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
if(!is_bool($set)) { if(!is_bool($set)) {
// temp status is not being set // temp status is not being set
if(!$isTemp) return false; // if not a temp file, we can exit now if(!$isTemp) return false; // if not a temp file, we can exit now
if(!$checkDeletable) return $isTemp; // if not checking deletable, we can exit now if(!$checkDeletable) return true; // if not checking deletable, we can exit now
} }
$user = $this->wire('user'); $user = $this->wire()->user;
$session = $this->wire()->session;
$now = time(); $now = time();
$session = $this->wire('session');
$pageID = $this->page ? $this->page->id : 0; $pageID = $this->page ? $this->page->id : 0;
$fieldID = $this->field ? $this->field->id : 0; $fieldID = $this->field ? $this->field->id : 0;
$sessionKey = "tempFiles_{$pageID}_{$fieldID}"; $sessionKey = "tempFiles_{$pageID}_{$fieldID}";
@@ -806,8 +809,11 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
unset($tempFiles[$pagefile->basename]); unset($tempFiles[$pagefile->basename]);
// remove file from session - note that this means a 'deletable' check can only be used once, for newly uploaded files // remove file from session - note that this means a 'deletable' check can only be used once, for newly uploaded files
// as it is assumed you will be removing the file as a result of this method call // as it is assumed you will be removing the file as a result of this method call
if(count($tempFiles)) $session->set($this, $sessionKey, $tempFiles); if(count($tempFiles)) {
else $session->remove($this, $sessionKey); $session->set($this, $sessionKey, $tempFiles);
} else {
$session->remove($this, $sessionKey);
}
} }
} }
@@ -867,7 +873,11 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
} }
if(count($removed) && $this->page && $this->field) { if(count($removed) && $this->page && $this->field) {
$this->page->save($this->field->name, array('quiet' => true)); $this->page->save($this->field->name, array('quiet' => true));
$this->message("Removed '{$this->field->name}' temp file(s) for page {$this->page->path} - " . implode(', ', $removed), Notice::debug | Notice::log); $this->message(
"Removed '{$this->field->name}' temp file(s) for page {$this->page->path} - " .
implode(', ', $removed),
Notice::debug | Notice::log
);
} }
return count($removed); return count($removed);
} }

View File

@@ -6,7 +6,7 @@
* A WireData object that maintains its data in a database table rather than just in memory. * A WireData object that maintains its data in a database table rather than just in memory.
* An example of usage is the `$page->meta()` method. * An example of usage is the `$page->meta()` method.
* *
* ProcessWire 3.x, Copyright 2019 * ProcessWire 3.x, Copyright 2023
* https://processwire.com * https://processwire.com
* *
*/ */
@@ -215,7 +215,7 @@ class WireDataDB extends WireData implements \Countable {
$sql = $sql =
"INSERT INTO `$table` (source_id, name, data) VALUES(:source_id, :name, :data) " . "INSERT INTO `$table` (source_id, name, data) VALUES(:source_id, :name, :data) " .
"ON DUPLICATE KEY UPDATE source_id=VALUES(source_id), name=VALUES(name), data=VALUES(data)"; "ON DUPLICATE KEY UPDATE source_id=VALUES(source_id), name=VALUES(name), data=VALUES(data)";
$query = $this->wire('database')->prepare($sql); $query = $this->wire()->database->prepare($sql);
$query->bindValue(':source_id', $this->sourceID(), \PDO::PARAM_INT); $query->bindValue(':source_id', $this->sourceID(), \PDO::PARAM_INT);
$query->bindValue(':name', $name); $query->bindValue(':name', $name);
$query->bindValue(':data', $data); $query->bindValue(':data', $data);

View File

@@ -213,8 +213,7 @@ class WireShutdown extends Wire {
* *
*/ */
protected function getWireInput() { protected function getWireInput() {
/** @var WireInput $input */ $input = $this->wire()->input;
$input = $this->wire('input');
if($input) return $input; if($input) return $input;
$input = $this->wire(new WireInput()); $input = $this->wire(new WireInput());
return $input; return $input;
@@ -228,8 +227,7 @@ class WireShutdown extends Wire {
*/ */
protected function getCurrentUrl() { protected function getCurrentUrl() {
/** @var Page|null $page */ $page = $this->wire()->page;
$page = $this->wire('page');
$input = $this->getWireInput(); $input = $this->getWireInput();
$http = isset($_SERVER['HTTP_HOST']) || isset($_SERVER['REQUEST_URI']); $http = isset($_SERVER['HTTP_HOST']) || isset($_SERVER['REQUEST_URI']);
@@ -552,10 +550,13 @@ class WireShutdown extends Wire {
if($useHTML && $config->ajax) $useHTML = false; if($useHTML && $config->ajax) $useHTML = false;
// include IP address is user name if configured to do so // include IP address is user name if configured to do so
if($config->logIP && $this->wire('session')) { if($config->logIP) {
$ip = $this->wire('session')->getIP(); $session = $this->wire()->session;
if($session) {
$ip = $session->getIP();
if(strlen($ip)) $name = "$name ($ip)"; if(strlen($ip)) $name = "$name ($ip)";
} }
}
// save to errors.txt log file // save to errors.txt log file
if($this->saveFatalLog($url, $name, $message)) { if($this->saveFatalLog($url, $name, $message)) {
@@ -781,7 +782,7 @@ class WireShutdown extends Wire {
public function shutdownExternal() { public function shutdownExternal() {
if(error_get_last()) return; if(error_get_last()) return;
/** @var ProcessPageView $process */ /** @var ProcessPageView $process */
$process = $this->wire('process'); $process = $this->wire()->process;
if($process == 'ProcessPageView') $process->finished(); if($process == 'ProcessPageView') $process->finished();
} }
} }

View File

@@ -9,7 +9,7 @@
* /wire/core/Fieldtype.php * /wire/core/Fieldtype.php
* /wire/core/FieldtypeMulti.php * /wire/core/FieldtypeMulti.php
* *
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @property array $allowFieldtypes Allowed Fieldtype types for custom fields * @property array $allowFieldtypes Allowed Fieldtype types for custom fields
@@ -407,7 +407,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
$isChanged = $pagefile->isChanged(); $isChanged = $pagefile->isChanged();
if($isNew) { if($isNew) {
$pagefile->createdUser = $this->wire('user'); $pagefile->createdUser = $this->wire()->user;
if(!$pagefile->isTemp()) $pagefile->created = time(); if(!$pagefile->isTemp()) $pagefile->created = time();
} }
@@ -415,7 +415,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
$changes = array_flip($pagefile->getChanges()); $changes = array_flip($pagefile->getChanges());
unset($changes['hash'], $changes['sort'], $changes['modified'], $changes['modified_users_id']); unset($changes['hash'], $changes['sort'], $changes['modified'], $changes['modified_users_id']);
if($isNew || count($changes)) { if($isNew || count($changes)) {
$pagefile->modifiedUser = $this->wire('user'); $pagefile->modifiedUser = $this->wire()->user;
if(!$pagefile->isTemp()) $pagefile->modified = time(); if(!$pagefile->isTemp()) $pagefile->modified = time();
} }
} }
@@ -893,7 +893,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
} else if(ctype_digit("$value")) { } else if(ctype_digit("$value")) {
$value = (int) $value; $value = (int) $value;
} else { } else {
$value = $this->wire('users')->get('name=' . $this->wire('sanitizer')->pageName($value))->id; $value = $this->wire()->users->get('name=' . $this->wire()->sanitizer->pageName($value))->id;
if(!$value) { if(!$value) {
$operator = '='; $operator = '=';
$value = -1; $value = -1;
@@ -959,8 +959,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
*/ */
protected function getMatchQuerySubfield($query, &$subfield, &$operator, &$value) { protected function getMatchQuerySubfield($query, &$subfield, &$operator, &$value) {
/** @var Sanitizer $sanitizer */ $sanitizer = $this->wire()->sanitizer;
$sanitizer = $this->wire('sanitizer');
$selector = $query->selector; $selector = $query->selector;
$property = ''; $property = '';
@@ -970,7 +969,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
while(count($parts) > 2) $property = array_pop($parts); while(count($parts) > 2) $property = array_pop($parts);
} }
$field = $this->wire('fields')->get($subfield); $field = $this->wire()->fields->get($subfield);
$fileField = $query->field; $fileField = $query->field;
if($fileField && !$fileField->type instanceof FieldtypeFile) $fileField = null; if($fileField && !$fileField->type instanceof FieldtypeFile) $fileField = null;
@@ -986,7 +985,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
throw new PageFinderSyntaxException("Property '$property' not supported in field '" . $selector->field() . "'"); throw new PageFinderSyntaxException("Property '$property' not supported in field '" . $selector->field() . "'");
} else if(!ctype_digit("$value") && $sanitizer->pagePathName($value) === $value) { } else if(!ctype_digit("$value") && $sanitizer->pagePathName($value) === $value) {
// page path to ID // page path to ID
$p = $this->wire('pages')->get($value); $p = $this->wire()->pages->get($value);
if($p->id && $p->viewable(false)) $value = $p->id; if($p->id && $p->viewable(false)) $value = $p->id;
} }
} }
@@ -1055,7 +1054,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
*/ */
public function getDatabaseSchema(Field $field) { public function getDatabaseSchema(Field $field) {
$database = $this->wire('database'); $database = $this->wire()->database;
$schema = parent::getDatabaseSchema($field); $schema = parent::getDatabaseSchema($field);
$maxLen = $database->getMaxIndexLength(); $maxLen = $database->getMaxIndexLength();
@@ -1075,7 +1074,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
if($field->id && !$field->prevFieldtype) { if($field->id && !$field->prevFieldtype) {
if($field->flags & Field::flagFieldgroupContext) { if($field->flags & Field::flagFieldgroupContext) {
$field = $this->wire('fields')->get($field->name); $field = $this->wire()->fields->get($field->name);
} }
$fileSchema1 = (int) $field->get('fileSchema'); $fileSchema1 = (int) $field->get('fileSchema');
$fileSchema2 = $this->updateDatabaseSchema($field, $schema, $fileSchema1); $fileSchema2 = $this->updateDatabaseSchema($field, $schema, $fileSchema1);
@@ -1102,10 +1101,9 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
protected function updateDatabaseSchema(Field $field, array &$schema, $fileSchema) { protected function updateDatabaseSchema(Field $field, array &$schema, $fileSchema) {
$contextField = $field; $contextField = $field;
if($field->flags & Field::flagFieldgroupContext) $field = $this->wire('fields')->get($field->name); if($field->flags & Field::flagFieldgroupContext) $field = $this->wire()->fields->get($field->name);
/** @var WireDatabasePDO $database */ $database = $this->wire()->database;
$database = $this->wire('database');
$table = $database->escapeTable($field->table); $table = $database->escapeTable($field->table);
$hasFilesize = $fileSchema & self::fileSchemaFilesize; $hasFilesize = $fileSchema & self::fileSchemaFilesize;
@@ -1212,8 +1210,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
*/ */
protected function addColumn(Field $field, $column, array &$schema) { protected function addColumn(Field $field, $column, array &$schema) {
/** @var WireDatabasePDO $database */ $database = $this->wire()->database;
$database = $this->wire('database');
if($database->columnExists($field->table, $column)) return true; if($database->columnExists($field->table, $column)) return true;
@@ -1499,7 +1496,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
public function saveFile(Page $page, Field $field, Pagefile $pagefile, array $columns = array()) { public function saveFile(Page $page, Field $field, Pagefile $pagefile, array $columns = array()) {
$item = $this->sleepFile($page, $field, $pagefile); $item = $this->sleepFile($page, $field, $pagefile);
$database = $this->wire('database'); /** @var WireDatabasePDO $database */ $database = $this->wire()->database;
$table = $database->escapeTable($field->getTable()); $table = $database->escapeTable($field->getTable());
$sets = array(); $sets = array();
$binds = array(':pages_id' => $page->id); $binds = array(':pages_id' => $page->id);

View File

@@ -9,7 +9,7 @@
* /wire/core/Fieldtype.php * /wire/core/Fieldtype.php
* /wire/core/FieldtypeMulti.php * /wire/core/FieldtypeMulti.php
* *
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* *
@@ -99,7 +99,7 @@ class FieldtypeImage extends FieldtypeFile implements FieldtypeHasFiles, Fieldty
if(!$hasDimensions) { if(!$hasDimensions) {
$numErrors = 0; $numErrors = 0;
if($this->wire('database')->tableExists($field->getTable())) { if($this->wire()->database->tableExists($field->getTable())) {
$columns = array('width', 'height', 'ratio'); $columns = array('width', 'height', 'ratio');
foreach($columns as $column) { foreach($columns as $column) {
if(!$this->addColumn($field, $column, $schema)) $numErrors++; if(!$this->addColumn($field, $column, $schema)) $numErrors++;

View File

@@ -3,7 +3,7 @@
/** /**
* ProcessWire Selectable Option class, for FieldtypeOptions * ProcessWire Selectable Option class, for FieldtypeOptions
* *
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @property int $id * @property int $id
@@ -86,8 +86,9 @@ class SelectableOption extends WireData { // implements LanguagesValueInterface
'sort' => $this->get('sort'), 'sort' => $this->get('sort'),
'data' => $this->get('data'), 'data' => $this->get('data'),
); );
if($this->wire('languages')) { $languages = $this->wire()->languages;
foreach($this->wire('languages') as $language) { if($languages) {
foreach($languages as $language) {
if($language->isDefault()) continue; if($language->isDefault()) continue;
$values["title$language"] = $this->get("title$language"); $values["title$language"] = $this->get("title$language");
$values["value$language"] = $this->get("value$language"); $values["value$language"] = $this->get("value$language");
@@ -105,7 +106,7 @@ class SelectableOption extends WireData { // implements LanguagesValueInterface
* *
*/ */
public function getProperty($property) { public function getProperty($property) {
if($this->wire('languages')) { if($this->wire()->languages) {
$language = $this->wire()->user->language; $language = $this->wire()->user->language;
if($language->isDefault()) { if($language->isDefault()) {
$value = parent::get($property); $value = parent::get($property);
@@ -117,7 +118,7 @@ class SelectableOption extends WireData { // implements LanguagesValueInterface
} else { } else {
$value = parent::get($property); $value = parent::get($property);
} }
if($this->of) $value = $this->wire('sanitizer')->entities($value); if($this->of) $value = $this->wire()->sanitizer->entities($value);
return $value; return $value;
} }