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

Minor adjustments and phpdoc updates in Pagefile/Pageimage and related classes

This commit is contained in:
Ryan Cramer
2022-08-19 14:59:41 -04:00
parent 5f0da8067c
commit 38b2dd0732
6 changed files with 120 additions and 85 deletions

View File

@@ -12,7 +12,7 @@
* Pagefile objects are contained by a `Pagefiles` object.
* #pw-body
*
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
* https://processwire.com
*
* @property-read string $url URL to the file on the server.
@@ -44,6 +44,7 @@
* @property int $modified_users_id ID of user that last modified the file or 0 if not known (3.0.154+). #pw-group-other
* @property User|NullPage $createdUser User that added/uploaded the file or NullPage if not known (3.0.154)+. #pw-group-other
* @property User|NullPage $modifiedUser User that last modified the file or NullPage if not known (3.0.154)+. #pw-group-other
* @property bool $formatted True when value has had Textformatters applied. #pw-internal
*
* @method void install($filename)
* @method string httpUrl()
@@ -132,6 +133,7 @@ class Pagefile extends WireData {
$this->pagefiles = $pagefiles;
if(strlen($filename)) $this->setFilename($filename);
$this->set('description', '');
$this->set('tags', '');
$this->set('formatted', false); // has an output formatter been run on this Pagefile?
@@ -140,6 +142,8 @@ class Pagefile extends WireData {
$this->set('filesize', 0);
$this->set('created_users_id', 0);
$this->set('modified_users_id', 0);
parent::__construct();
}
/**
@@ -230,13 +234,14 @@ class Pagefile extends WireData {
if(!is_readable($filename)) throw new WireException("Unable to read: $filename");
if(!copy($filename, $destination)) throw new WireException("Unable to copy: $filename => $destination");
} else {
/** @var WireHttp $http */
$http = $this->wire(new WireHttp());
// note: download() method throws excepton on failure
$http->download($filename, $destination);
// download was successful
}
$this->wire('files')->chmod($destination);
$this->wire()->files->chmod($destination);
$this->changed('file');
$this->isNew(true);
parent::set('basename', $basename);
@@ -286,7 +291,7 @@ class Pagefile extends WireData {
if(strpos($key, 'description') === 0 && preg_match('/^description(\d+)$/', $value, $matches)) {
// check if a language description is being set manually by description123 where 123 is language ID
$languages = $this->wire('languages');
$languages = $this->wire()->languages;
if($languages) {
$language = $languages->get((int) $matches[1]);
if($language && $language->id) return $this->setDescription($value, $language);
@@ -310,10 +315,10 @@ class Pagefile extends WireData {
*/
protected function setUser($user, $type) {
$id = 0;
if($user === true) $user = $this->wire('user');
if($user === true) $user = $this->wire()->user;
if(is_object($user)) {
if($user instanceof NullPage) {
$id = 0;
// $id = 0;
} else if($user instanceof User) {
$id = $user->isGuest() ? 0 : $user->id;
}
@@ -322,8 +327,8 @@ class Pagefile extends WireData {
} else if(ctype_digit($user)) {
$id = (int) $user;
} else if(is_string($user)) {
$name = $this->wire('sanitizer')->pageName($user);
$user = $name ? $this->wire('users')->get("name=$name") : null;
$name = $this->wire()->sanitizer->pageName($user);
$user = $name ? $this->wire()->users->get("name=$name") : null;
$id = $user && $user->id ? $user->id : 0;
}
if($id < 0) $id = 0;
@@ -421,8 +426,7 @@ class Pagefile extends WireData {
*/
protected function setDescription($value, Page $language = null) {
/** @var Languages $languages */
$languages = $this->wire('languages');
$languages = $this->wire()->languages;
/** @var Language|null $language */
@@ -467,7 +471,7 @@ class Pagefile extends WireData {
if(!$id) $id = '';
$name = $n > 0 ? "description$id" : "description";
} else if($id === 'default') {
$name = 'description';
// $name = 'description';
} else if($languages) {
$language = $languages->get($id); // i.e. "default" or "es"
if(!$language->id) continue;
@@ -478,8 +482,8 @@ class Pagefile extends WireData {
}
} else {
// no JSON values so assume regular language description
$languages = $this->wire('languages');
$language = $languages ? $this->wire('user')->language : null;
$languages = $this->wire()->languages;
$language = $languages ? $this->wire()->user->language : null;
if($languages && $language && !$noLang && !$language->isDefault()) {
$name = "description$language->id";
@@ -533,13 +537,14 @@ class Pagefile extends WireData {
*/
public function description($language = null, $value = null) {
$languages = $this->wire()->languages;
if($language === true && $value === true) {
// return all in array indexed by language name
/** @var Languages $languages */
$languages = $this->wire('languages');
if(!$languages) return array('default' => parent::get('description'));
$value = array();
foreach($languages as $language) {
/** @var Language $language */
$value[$language->name] = (string) parent::get("description" . ($language->isDefault() ? '' : $language->id));
}
return $value;
@@ -564,16 +569,18 @@ class Pagefile extends WireData {
$value = null;
}
if((is_string($language) || is_int($language)) && $this->wire('languages')) {
if((is_string($language) || is_int($language)) && $languages) {
// convert named or ID'd languages to Language object
$language = $this->wire('languages')->get($language);
$language = $languages->get($language);
}
if(is_null($language)) {
// return description for current user language, or inherit from default if not available
$user = $this->wire('user');
$value = null;
if($user->language && $user->language->id) $value = parent::get("description{$user->language}");
if($user->language && $user->language->id) {
$value = parent::get("description{$user->language}");
}
if(empty($value)) {
// inherit default language value
$value = parent::get("description");
@@ -581,10 +588,10 @@ class Pagefile extends WireData {
} else if($language === true) {
// return JSON string of all languages if applicable
$languages = $this->wire('languages');
if($languages && $languages->count() > 1) {
$values = array(0 => parent::get("description"));
foreach($languages as $lang) {
/** @var Language $lang */
if($lang->isDefault()) continue;
$v = parent::get("description$lang");
if(empty($v)) continue;
@@ -600,8 +607,11 @@ class Pagefile extends WireData {
} else if(is_object($language) && $language->id) {
// return description for specific language or blank if not available
if($language->isDefault()) $value = parent::get("description");
else $value = parent::get("description$language");
if($language->isDefault()) {
$value = parent::get("description");
} else {
$value = parent::get("description$language");
}
}
// we only return strings, so return blank rather than null
@@ -620,10 +630,9 @@ class Pagefile extends WireData {
*
*/
public function get($key) {
$value = null;
if($key == 'name') $key = 'basename';
if($key == 'pathname') $key = 'filename';
if($key === 'name') $key = 'basename';
if($key === 'pathname') $key = 'filename';
switch($key) {
case 'url':
@@ -668,7 +677,7 @@ class Pagefile extends WireData {
case 'modifiedStr':
case 'createdStr':
$value = parent::get(str_replace('Str', '', $key));
$value = wireDate($this->wire('config')->dateFormat, $value);
$value = wireDate($this->wire()->config->dateFormat, $value);
break;
case 'created_users_id':
case 'modified_users_id':
@@ -688,16 +697,17 @@ class Pagefile extends WireData {
break;
case 'mtimeStr':
case 'filemtimeStr':
$value = wireDate($this->wire('config')->dateFormat, $this->filemtime());
$value = wireDate($this->wire()->config->dateFormat, $this->filemtime());
break;
case 'fieldValues':
return $this->fieldValues;
$value = $this->fieldValues;
break;
default:
$value = $this->getFieldValue($key);
}
if(is_null($value)) return parent::get($key);
return $value;
}
@@ -714,7 +724,7 @@ class Pagefile extends WireData {
*/
public function getFieldValue($name, $formatted = null) {
$field = $this->wire('fields')->get($name);
$field = $this->wire()->fields->get($name);
if(!$field) return null;
$template = $this->pagefiles->getFieldsTemplate();
@@ -787,7 +797,7 @@ class Pagefile extends WireData {
if($changed === null && $this->page->trackChanges()) {
// detect if a change has taken place
$oldValue = $this->getFieldValue($field->name, false);
if(is_object($oldValue) && $oldValue instanceof Wire && $oldValue === $value) {
if($oldValue instanceof Wire && $oldValue === $value) {
// $oldValue and new $value are the same object instance, so ask it if anything has changed
$changed = $oldValue->isChanged();
if($changed) $this->trackChange($field->name);
@@ -822,11 +832,13 @@ class Pagefile extends WireData {
*
* #pw-group-traversal
*
* @return Pagefile|Wire|null
* @return Pagefile|null
*
*/
public function getNext() {
return $this->pagefiles->getNext($this);
/** @var Pagefile|null $item */
$item = $this->pagefiles->getNext($this);
return $item;
}
/**
@@ -834,11 +846,13 @@ class Pagefile extends WireData {
*
* #pw-group-traversal
*
* @return Pagefile|Wire|null
* @return Pagefile|null
*
*/
public function getPrev() {
return $this->pagefiles->getPrev($this);
/** @var Pagefile|null $item */
$item = $this->pagefiles->getPrev($this);
return $item;
}
/**
@@ -859,7 +873,7 @@ class Pagefile extends WireData {
*
*/
public function url() {
return $this->wire('hooks')->isHooked('Pagefile::url()') ? $this->__call('url', array()) : $this->___url();
return $this->wire()->hooks->isHooked('Pagefile::url()') ? $this->__call('url', array()) : $this->___url();
}
/**
@@ -895,7 +909,7 @@ class Pagefile extends WireData {
*
*/
public function filename() {
return $this->wire('hooks')->isHooked('Pagefile::filename()') ? $this->__call('filename', array()) : $this->___filename();
return $this->wire()->hooks->isHooked('Pagefile::filename()') ? $this->__call('filename', array()) : $this->___filename();
}
/**
@@ -950,7 +964,7 @@ class Pagefile extends WireData {
$tags = str_replace(array(',', '|'), ' ', $tags);
$_tags = explode(' ', $tags);
$tags = array();
foreach($_tags as $key => $tag) {
foreach($_tags as /* $key => */ $tag) {
$tag = trim($tag);
if($value === false) $tag = strtolower($tag); // force lowercase
if(!strlen($tag)) continue;
@@ -959,7 +973,7 @@ class Pagefile extends WireData {
} else if($value !== null) {
// set tags
if(is_array($value)) $value = implode(' ', $value); // convert to string
$value = $this->wire('sanitizer')->text($value);
$value = $this->wire()->sanitizer->text($value);
if(strpos($value, "\t") !== false) $value = str_replace("\t", " ", $value);
// collapse extra whitespace
while(strpos($value, " ") !== false) $value = str_replace(" ", " ", $value);
@@ -1074,6 +1088,7 @@ class Pagefile extends WireData {
*
*/
public function addTag($tag) {
$sanitizer = $this->wire()->sanitizer;
if(is_array($tag)) {
$addTags = $tag;
} else if(strpos($tag, ',') !== false) {
@@ -1085,7 +1100,7 @@ class Pagefile extends WireData {
$numAdded = 0;
foreach($addTags as $tag) {
if($this->hasTag($tag)) continue;
$tag = $this->wire('sanitizer')->text(trim($tag));
$tag = $sanitizer->text(trim($tag));
$tag = str_replace(' ', '_', $tag);
$tags[strtolower($tag)] = $tag;
$numAdded++;
@@ -1227,11 +1242,10 @@ class Pagefile extends WireData {
public function unlink() {
/** @var WireFileTools $files */
if(!strlen($this->basename) || !is_file($this->filename)) return true;
$files = $this->wire('files');
foreach($this->extras() as $extra) {
$extra->unlink();
}
return $files->unlink($this->filename, true);
return $this->wire()->files->unlink($this->filename, true);
}
/**
@@ -1250,7 +1264,7 @@ class Pagefile extends WireData {
$extra->filename(); // init
}
$basename = $this->pagefiles->cleanBasename($basename, true);
if($this->wire('files')->rename($this->filename, $this->pagefiles->path . $basename, true)) {
if($this->wire()->files->rename($this->filename, $this->pagefiles->path . $basename, true)) {
$this->set('basename', $basename);
$basename = $this->basename();
foreach($this->extras() as $extra) {
@@ -1271,8 +1285,7 @@ class Pagefile extends WireData {
*
*/
public function copyToPath($path) {
/** @var WireFileTools $files */
$files = $this->wire('files');
$files = $this->wire()->files;
$result = $files->copy($this->filename(), $path);
foreach($this->extras() as $extra) {
if(!$extra->exists()) continue;
@@ -1358,7 +1371,7 @@ class Pagefile extends WireData {
*/
public function extras($name = null, PagefileExtra $value = null) {
if($name === null) return $this->extras;
if($value !== null && $value instanceof PagefileExtra) {
if($value instanceof PagefileExtra) {
$this->extras[$name] = $value;
}
return isset($this->extras[$name]) ? $this->extras[$name] : null;
@@ -1394,8 +1407,8 @@ class Pagefile extends WireData {
*/
public function replaceFile($filename, $move = true) {
/** @var WireFileTools $files */
$files = $this->wire('files');
$files = $this->wire()->files;
if(!is_file($filename) || !is_readable($filename)) return false;
if($move && !is_writable($filename)) $move = false;

View File

@@ -224,7 +224,7 @@ class PagefileExtra extends WireData {
*/
public function unlink() {
if(!$this->exists()) return false;
return $this->wire('files')->unlink($this->filename());
return $this->wire()->files->unlink($this->filename());
}
/**
@@ -235,7 +235,7 @@ class PagefileExtra extends WireData {
*/
public function rename() {
if(!$this->filenamePrevious || !is_readable($this->filenamePrevious)) return false;
return $this->wire('files')->rename($this->filenamePrevious, $this->filename());
return $this->wire()->files->rename($this->filenamePrevious, $this->filename());
}
/**
@@ -322,4 +322,4 @@ class PagefileExtra extends WireData {
public function __toString() {
return $this->basename();
}
}
}

View File

@@ -193,11 +193,12 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
*
* #pw-internal
*
* @return Pagefiles|WireArray
* @return Pagefiles|Pageimages|WireArray
*
*/
public function makeNew() {
$class = get_class($this);
/** @var Pagefiles|Pageimages $newArray */
$newArray = $this->wire(new $class($this->page));
$newArray->setField($this->field);
return $newArray;
@@ -220,7 +221,10 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
foreach($this->data as $key => $value) $newArray[$key] = $value;
foreach($this->extraData as $key => $value) $newArray->data($key, $value);
$newArray->resetTrackChanges($this->trackChanges());
foreach($newArray as $item) $item->setPagefilesParent($newArray);
foreach($newArray as $item) {
/** @var Pagefile $item */
$item->setPagefilesParent($newArray);
}
return $newArray;
}
@@ -232,6 +236,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
*/
public function __clone() {
foreach($this as $key => $pagefile) {
/** @var Pagefile $pagefile */
$pagefile = clone $pagefile;
$pagefile->setPagefilesParent($this);
$this->set($key, $pagefile);
@@ -299,13 +304,13 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
/**
* Get for direct access to properties
*
* @param int|string $key
* @param int|string $property
* @return bool|mixed|Page|Wire|WireData
*
*/
public function __get($key) {
if(in_array($key, array('page', 'field', 'url', 'path'))) return $this->get($key);
return parent::__get($key);
public function __get($property) {
if(in_array($property, array('page', 'field', 'url', 'path'))) return $this->get($property);
return parent::__get($property);
}
/**
@@ -358,7 +363,6 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
}
}
/** @var Pagefiles $result */
$result = parent::add($item);
return $result;
}
@@ -427,12 +431,13 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
*
* #pw-internal Please use the hookable delete() method for public API
*
* @param Pagefile $item Item to delete/remove.
* @param Pagefile $key Item to delete/remove.
* @return $this
* @throws WireException
*
*/
public function remove($item) {
public function remove($key) {
$item = $key;
if(is_string($item)) $item = $this->get($item);
if(!$this->isValidItem($item)) throw new WireException("Invalid type to {$this->className}::remove(item)");
$this->addSaveHook();
@@ -519,8 +524,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
$pathname = $n ? ($path . $parts[0] . "-$n." . $parts[1]) : ($path . $item->basename);
} while(file_exists($pathname) && $n++);
if(copy($item->filename(), $pathname)) {
$this->wire('files')->chmod($pathname);
if($this->wire()->files->copy($item->filename(), $pathname)) {
$itemCopy = clone $item;
$itemCopy->setPagefilesParent($pagefiles);
@@ -630,6 +634,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
public function findTag($tag) {
$items = $this->makeNew();
foreach($this as $pagefile) {
/** @var Pagefile $pagefile */
if($pagefile->hasTag($tag)) $items->add($pagefile);
}
return $items;
@@ -656,6 +661,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
public function getTag($tag) {
$item = null;
foreach($this as $pagefile) {
/** @var Pagefile $pagefile */
if(!$pagefile->hasTag($tag)) continue;
$item = $pagefile;
break;
@@ -706,6 +712,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
// return array of tags
$tags = array();
foreach($this as $pagefile) {
/** @var Pagefile $pagefile */
$tags = array_merge($tags, $pagefile->tags($value));
}
if($returnString) $tags = implode(' ', $tags);
@@ -729,7 +736,6 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
*/
public function trackChange($what, $old = null, $new = null) {
if($this->field && $this->page) $this->page->trackChange($this->field->name);
/** @var Pagefiles $result */
$result = parent::trackChange($what, $old, $new);
return $result;
}
@@ -745,6 +751,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
$hasFile = null;
$name = basename($name);
foreach($this as $pagefile) {
/** @var Pagefile $pagefile */
if($pagefile->basename == $name) {
$hasFile = $pagefile;
break;
@@ -853,6 +860,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
public function deleteAllTemp() {
$removed = array();
foreach($this as $pagefile) {
/** @var Pagefile $pagefile */
if(!$this->isTemp($pagefile, 'deletable')) continue;
$removed[] = $pagefile->basename();
$this->remove($pagefile);
@@ -950,7 +958,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
$this->fieldsTemplate = false;
/** @var FieldtypeFile $fieldtype */
$fieldtype = $field->type;
$template = $fieldtype && $fieldtype instanceof FieldtypeFile ? $fieldtype->getFieldsTemplate($field) : null;
$template = $fieldtype instanceof FieldtypeFile ? $fieldtype->getFieldsTemplate($field) : null;
if($template) $this->fieldsTemplate = $template;
}
}

View File

@@ -190,7 +190,8 @@ class Pageimage extends Pagefile {
*
*/
public function url() {
if($this->wire('hooks')->isHooked('Pagefile::url()') || $this->wire('hooks')->isHooked('Pageimage::url()')) {
$hooks = $this->wire()->hooks;
if($hooks->isHooked('Pagefile::url()') || $hooks->isHooked('Pageimage::url()')) {
return $this->__call('url', array());
} else {
return $this->___url();
@@ -206,7 +207,8 @@ class Pageimage extends Pagefile {
*
*/
public function filename() {
if($this->wire('hooks')->isHooked('Pagefile::filename()') || $this->wire('hooks')->isHooked('Pageimage::filename()')) {
$hooks = $this->wire()->hooks;
if($hooks->isHooked('Pagefile::filename()') || $hooks->isHooked('Pageimage::filename()')) {
return $this->__call('filename', array());
} else {
return $this->___filename();
@@ -687,7 +689,7 @@ class Pageimage extends Pagefile {
return $this->sizeName($width, $options);
}
if($this->wire('hooks')->isHooked('Pageimage::size()')) {
if($this->wire()->hooks->isHooked('Pageimage::size()')) {
$result = $this->__call('size', array($width, $height, $options));
} else {
$result = $this->___size($width, $height, $options);
@@ -718,7 +720,7 @@ class Pageimage extends Pagefile {
protected function ___size($width, $height, $options) {
$this->error = '';
if($this->ext == 'svg') return $this;
if($this->ext === 'svg') return $this;
if(!is_array($options)) $options = $this->sizeOptionsToArray($options);
// originally requested options
@@ -747,16 +749,16 @@ class Pageimage extends Pagefile {
'focus' => true, // allow single dimension resizes to use focus area?
'zoom' => null, // zoom override, used only if focus is applicable, int when populated
'allowOriginal' => false, // Return original image if already at requested dimensions? (must be only specified option)
);
);
/** @var WireFileTools $files */
/** @var Config $config */
$files = $this->wire('files');
$config = $this->wire('config');
$files = $this->wire()->files;
$config = $this->wire()->config;
$debug = $config->debug;
$configOptions = $config->imageSizerOptions;
$webpOptions = $config->webpOptions;
$createdVariationHookData = null; // populated as array only when new variation created (for createdVariation hook)
if(!empty($webpOptions['quality'])) $defaultOptions['webpQuality'] = $webpOptions['quality'];
if(!is_array($configOptions)) $configOptions = array();
@@ -773,7 +775,10 @@ class Pageimage extends Pagefile {
}
}
if($options['cropping'] === true && empty($options['cropExtra']) && $options['focus'] && $this->hasFocus && $width && $height) {
if($options['cropping'] === true
&& empty($options['cropExtra'])
&& $options['focus'] && $this->hasFocus
&& $width && $height) {
// crop to focus area
$focus = $this->focus();
if(is_int($options['zoom'])) $focus['zoom'] = $options['zoom']; // override
@@ -811,9 +816,12 @@ class Pageimage extends Pagefile {
$suffix = $options['suffix'];
sort($suffix);
foreach($suffix as $key => $s) {
$s = strtolower($this->wire('sanitizer')->fieldName($s));
if(empty($s)) unset($suffix[$key]);
else $suffix[$key] = $s;
$s = strtolower($this->wire()->sanitizer->fieldName($s));
if(empty($s)) {
unset($suffix[$key]);
} else {
$suffix[$key] = $s;
}
}
if(count($suffix)) $suffixStr = '-' . implode('-', $suffix);
}
@@ -875,7 +883,7 @@ class Pageimage extends Pagefile {
if(file_exists($filenameUnvalidated)) $files->unlink($filenameUnvalidated, true);
if(file_exists($filenameUnvalidatedWebp)) $files->unlink($filenameUnvalidatedWebp, true);
if(@copy($this->filename(), $filenameUnvalidated)) {
if($files->copy($this->filename(), $filenameUnvalidated)) {
try {
$timer = $debug ? Debug::timer() : null;
@@ -1035,7 +1043,7 @@ class Pageimage extends Pagefile {
*
*/
public function sizeName($name, array $options = array()) {
$sizes = $this->wire('config')->imageSizes;
$sizes = $this->wire()->config->imageSizes;
if(!isset($sizes[$name])) throw new WireException("Unknown image size '$name' (not in \$config->imageSizes)");
$size = $sizes[$name];
$options = array_merge($size, $options);
@@ -1180,7 +1188,7 @@ class Pageimage extends Pagefile {
if($width < 1) $width = $this->width();
if($width === "100%") return $width;
return ceil($width * $scale);
} else if($width && is_int($width) && $width > 0) {
} else if($width && is_int($width)) {
// resize intended
if(!is_array($options)) $options = array();
return $this->hidpiSize((int) $width, 0, $options);
@@ -1298,7 +1306,7 @@ class Pageimage extends Pagefile {
$options['nameHeight'] = $height;
}
if($this->wire('config')->installed > 1513336849) {
if($this->wire()->config->installed > 1513336849) {
// New installations from 2017-12-15 forward use an "ms" suffix for images from maxSize() method
$suffix = isset($options['suffix']) ? $options['suffix'] : array();
if(!is_array($suffix)) $suffix = array();

View File

@@ -247,13 +247,13 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
if(is_readable($this->pagefiles->path . $f)) {
$info["{$name}Url"] = $this->pagefiles->url . $f;
$info["{$name}Path"] = $this->pagefiles->path . $f;
continue;
// continue;
}
}
if(empty($info['crop'])) {
// attempt to extract crop info from suffix
foreach($info['suffix'] as $key => $suffix) {
foreach($info['suffix'] as /* $key => */ $suffix) {
if(strpos($suffix, 'cropx') === 0) {
$info['crop'] = ltrim($suffix, 'crop'); // i.e. x123y456
}
@@ -337,6 +337,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
$count = 0;
if(!$options['info'] && !$options['count']) {
/** @var Pageimages $variations */
$variations = $this->wire(new Pageimages($this->pagefiles->page));
}
@@ -493,7 +494,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
} else if(strpos($s, 'cropx') === 0) {
// skip cropx suffix (already known from $info[crop])
unset($info['suffix'][$k]);
continue;
// continue;
} else if(strpos($s, 'pid') === 0 && preg_match('/^pid\d+$/', $s)) {
// allow pid123 to pass through
} else if(in_array($s, $suffix)) {
@@ -602,6 +603,8 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
*
*/
public function remove(array $options = array()) {
$files = $this->wire()->files;
$defaults = array(
'dryRun' => false,
@@ -612,8 +615,6 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
if(!empty($options['dryrun'])) $defaults['dryRun'] = $options['dryrun']; // case insurance
$options = array_merge($defaults, $options); // placement after getVariations() intended
/** @var WireFileTools $files */
$files = $this->wire('files');
$deletedFiles = array();
$this->removeExtras($this->pageimage, $deletedFiles, $options);
@@ -655,4 +656,4 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
}
}
}
}
}

View File

@@ -63,6 +63,8 @@ class Pageimages extends Pagefiles {
* Per the WireArray interface, return a blank Pageimage
*
* #pw-internal
*
* @return Pageimage
*
*/
public function makeBlankItem() {
@@ -87,6 +89,7 @@ class Pageimages extends Pagefiles {
$base = ($pos ? substr($name, 0, $pos) : null);
foreach($this as $pagefile) {
/** @var Pageimage $pagefile */
if($base !== null && strpos($pagefile->basename, $base) !== 0) continue;
// they start the same, is it a variation?
if(!$pagefile->isVariation($name)) continue;
@@ -129,6 +132,7 @@ class Pageimages extends Pagefiles {
$basenames = array();
foreach($this as $pageimage) {
/** @var Pageimage $pageimage */
$name = $pageimage->basename;
$ext = $pageimage->ext;
$extensions[$name] = $ext;
@@ -234,6 +238,7 @@ class Pageimages extends Pagefiles {
unset($options['limit']);
}
foreach($this as $image) {
/** @var Pageimage $image */
$out .= $image->render($markup, $options);
if($limit > 0 && ++$n >= $limit) break;
}