diff --git a/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module b/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module
index 1f92fad1..8070b796 100755
--- a/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module
+++ b/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module
@@ -4,7 +4,9 @@
* Class InputfieldImage
*
* Inputfield for FieldtypeImage fields
- *
+ *
+ * ProcessWire 3.x, Copyright 2023 by Ryan Cramer
+ * https://processwire.com
*
* Accessible Properties
*
@@ -91,6 +93,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
public function init() {
parent::init();
+ $config = $this->wire()->config;
$this->set('extensions', 'JPG JPEG GIF PNG');
$this->set('maxWidth', '');
@@ -105,11 +108,12 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$this->set('itemClass', 'gridImage ui-widget');
$this->set('editFieldName', ''); // field name to use for image editor (default=name of this inputfield)
- $options = $this->wire('config')->adminThumbOptions;
+ $options = $config->adminThumbOptions;
if(!is_array($options)) $options = array();
$gridSize = empty($options['gridSize']) ? self::defaultGridSize : (int) $options['gridSize'];
if($gridSize < 100) $gridSize = self::defaultGridSize; // establish min of 100
if($gridSize >= (self::defaultGridSize * 2)) $gridSize = self::defaultGridSize; // establish max of 259
+
$this->set('gridSize', $gridSize);
$this->set('gridMode', 'grid'); // one of "grid", "left" or "list"
$this->set('focusMode', 'on'); // One of "on", "zoom" or "off"
@@ -125,6 +129,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$options['imageSizerOptions'][$key] = $value;
}
}
+
$this->set('imageSizerOptions', empty($options['imageSizerOptions']) ? array() : $options['imageSizerOptions']);
$this->set('useImageEditor', 1);
@@ -146,11 +151,18 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
'buttonText' => "{out}",
'selectClass' => '',
);
- $themeSettings = $this->wire('config')->InputfieldImage;
+ $themeSettings = $config->InputfieldImage;
$themeSettings = is_array($themeSettings) ? array_merge($themeDefaults, $themeSettings) : $themeDefaults;
$this->themeSettings = array_merge($this->themeSettings, $themeSettings);
}
-
+
+ /**
+ * Get setting or attribute
+ *
+ * @param string $key
+ * @return array|bool|mixed|string|null
+ *
+ */
public function get($key) {
if($key == 'themeSettings') return $this->themeSettings;
return parent::get($key);
@@ -173,13 +185,15 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$this->addClass('InputfieldRenderValueMode', 'wrapClass');
}
- $config = $this->wire('config');
- $modules = $this->wire('modules');
+ $config = $this->wire()->config;
+ $modules = $this->wire()->modules;
+
+ /** @var JqueryCore $jqueryCore */
$jqueryCore = $modules->get('JqueryCore');
$jqueryCore->use('simulate');
$jqueryCore->use('cookie');
$modules->loadModuleFileAssets('InputfieldFile');
- $modules->getInstall("JqueryMagnific");
+ $modules->getInstall('JqueryMagnific');
if(!$renderValueMode && $this->focusMode == 'zoom') {
$this->addClass('InputfieldImageFocusZoom', 'wrapClass');
@@ -196,7 +210,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
// client side image resize
if(!$this->resizeServer && ($this->maxWidth || $this->maxHeight || $this->maxSize)) {
$moduleInfo = self::getModuleInfo();
- $thisURL = $config->urls->InputfieldImage;
+ $thisURL = $config->urls('InputfieldImage');
$jsExt = $config->debug ? "js" : "min.js";
$config->scripts->add($thisURL . "piexif.$jsExt");
$config->scripts->add($thisURL . "PWImageResizer.$jsExt?v=$moduleInfo[version]");
@@ -205,16 +219,20 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$this->wrapAttr('data-resize', "$this->maxWidth;$this->maxHeight;$maxSize;$quality");
}
- if(!$renderValueMode && $this->value instanceof Pageimages) {
+ $value = $this->val();
+ if(!$value instanceof Pageimages) $value = null;
+
+ if(!$renderValueMode && $value) {
$page = $this->getRootHasPage();
- if($page->id && $this->wire('user')->hasPermission('page-edit-images', $page)) {
- $modules->get('JqueryUI')->use('modal');
+ if($page->id && $this->wire()->user->hasPermission('page-edit-images', $page)) {
+ $jQueryUI = $modules->get('JqueryUI'); /** @var JqueryUI $jQueryUI */
+ $jQueryUI->use('modal');
} else {
$this->useImageEditor = 0;
}
}
- if($this->value instanceof Pageimages) $this->variations = $this->value->getAllVariations();
+ if($value) $this->variations = $value->getAllVariations();
return parent::renderReady($parent, $renderValueMode);
}
@@ -241,7 +259,6 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
*/
protected function ___renderList($value) {
- //if(!$value) return '';
$out = '';
$n = 0;
@@ -249,7 +266,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
if(!$this->uploadOnlyMode && WireArray::iterable($value)) {
- foreach($value as $k => $pagefile) {
+ foreach($value as $pagefile) {
$id = $this->pagefileId($pagefile);
$this->currentItem = $pagefile;
@@ -264,8 +281,9 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
}
if(!$this->renderValueMode) {
- $dropNew = $this->wire('sanitizer')->entities1($this->_('drop in new image file to replace'));
- $focus = $this->wire('sanitizer')->entities1($this->_('drag circle to center of focus'));
+ $sanitizer = $this->wire()->sanitizer;
+ $dropNew = $sanitizer->entities1($this->_('drop in new image file to replace'));
+ $focus = $sanitizer->entities1($this->_('drag circle to center of focus'));
$out .= "
- ";
+ ";
return $out;
}
@@ -780,7 +813,6 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
if($n) {} // ignore, $n is for hooks
$pageID = $pagefile->pagefiles->page->id;
$variationCount = $pagefile->variations()->count();
- // if($pagefile->webp()->exists()) $variationCount++;
$editUrl = $this->getEditUrl($pagefile, $pageID);
$variationUrl = $this->getVariationUrl($pagefile, $id);
$buttonClass = $this->themeSettings['buttonClass'];
@@ -789,9 +821,9 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$labels = $this->labels;
$out = '';
-
// Crop
- $buttonText = str_replace('{out}', " $labels[crop]", $this->themeSettings['buttonText']);
+ $icon = wireIconMarkup('crop');
+ $buttonText = str_replace('{out}', "$icon $labels[crop]", $this->themeSettings['buttonText']);
$out .= "";
// Focus
@@ -803,7 +835,8 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
}
// Variations
- $buttonText = " $labels[variations] ($variationCount)";
+ $icon = wireIconMarkup('files-o');
+ $buttonText = "$icon $labels[variations] ($variationCount)";
$buttonText = str_replace('{out}', $buttonText, $this->themeSettings['buttonText']);
$out .= "";
@@ -824,28 +857,32 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
static $hooked = null;
+ $hooks = $this->wire()->hooks;
+
if($hooked === null) $hooked =
- $this->wire('hooks')->isHooked('InputfieldImage::getFileActions()') ||
- $this->wire('hooks')->isHooked('InputfieldFile::getFileActions()');
+ $hooks->isHooked('InputfieldImage::getFileActions()') ||
+ $hooks->isHooked('InputfieldFile::getFileActions()');
$actions = $hooked ? $this->getFileActions($pagefile) : $this->___getFileActions($pagefile);
if(empty($actions)) return '';
$selectClass = trim($this->themeSettings['selectClass'] . ' InputfieldFileActionSelect');
- /** @var Sanitizer $sanitizer */
- $sanitizer = $this->wire('sanitizer');
-
+ $sanitizer = $this->wire()->sanitizer;
+
+ $label = $sanitizer->entities1($this->_('Actions'));
$out =
" ";
- $out .= "" . $this->_('Action applied at save.') . "";
+ $label = $sanitizer->entities1($this->_('Action applied at save.'));
+ $out .= "$label";
return $out;
}
@@ -863,7 +900,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
static $hasIMagick = null;
if($hasIMagick === null) {
- $hasIMagick = $this->wire('modules')->isInstalled('ImageSizerEngineIMagick');
+ $hasIMagick = $this->wire()->modules->isInstalled('ImageSizerEngineIMagick');
}
if($labels === null) $labels = array(
@@ -919,24 +956,6 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
return $actions;
}
- /**
- * Render non-editable value
- *
- * @return string
- *
- public function ___renderValue() {
- $value = $this->value;
- if(!$value instanceof Pageimages) return '';
- $out = '';
- foreach($value as $img) {
- $info = $this->getAdminThumb($img);
- $out .= $info['amarkup'];
-
- }
- return $out;
- }
- */
-
/**
* Render any additional fields (for hooks)
*
@@ -990,12 +1009,10 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
* Is the given image editable during rendering?
*
* @param Pagefile|Pageimage $pagefile
- * @return bool|int
+ * @return bool
*
*/
protected function isEditableInRendering($pagefile) {
- //$editable = (int) $this->useImageEditor;
- //if($editable) {
if($this->renderValueMode) {
$editable = false;
} else if($pagefile->ext == 'svg') {
@@ -1003,9 +1020,6 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
} else {
$editable = true;
}
- // if(strpos($this->name, '_repeater') && preg_match('/_repeater\d+$/', $this->name)) {
- // $editable = false;
- // }
return $editable;
}
@@ -1135,22 +1149,20 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
if(strlen($pagefile->description)) {
$data[] = array(
$this->labels['description'],
- ""
+ wireIconMarkup('check')
);
}
if($this->useTags && strlen($pagefile->tags)) {
$data[] = array(
$this->labels['tags'],
- ""
+ wireIconMarkup('check')
);
}
return $data;
}
-
-
/**
* Return whether or not admin thumbs should be scaled
*
@@ -1171,8 +1183,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
*/
public function ___processInput(WireInputData $input) {
- /** @var Sanitizer $sanitizer */
- $sanitizer = $this->wire('sanitizer');
+ $sanitizer = $this->wire()->sanitizer;
$page = $this->getRootHasPage();
if($page && $page->id) {
@@ -1181,16 +1192,16 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
parent::___processInput($input);
- if((int) $this->wire('input')->post("_refresh_thumbnails_$this->name")) {
+ if((int) $this->wire()->input->post("_refresh_thumbnails_$this->name")) {
foreach($this->value as $img) {
$this->getAdminThumb($img, false, true);
}
$this->message($this->_('Recreated all legacy thumbnails') . " - $this->name");
}
- if(!$this->isAjax && !$this->wire('config')->ajax) {
+ if(!$this->isAjax && !$this->wire()->config->ajax) {
// process actions, but only on non-ajax save requests
- foreach($this->value as $k => $pagefile) {
+ foreach($this->value as $pagefile) {
$id = $this->pagefileId($pagefile);
$action = $input->{"act_$id"};
if(empty($action)) continue;
@@ -1268,7 +1279,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$_pagefile = $pagefile->pagefiles->clone($pagefile);
$success = $_pagefile ? true : false;
if($success) {
- $this->wire('session')->message(
+ $this->wire()->session->message(
sprintf($this->_('Duplicated file %1$s => %2$s'), $pagefile->basename(), $_pagefile->basename())
);
$showSuccess = false;
@@ -1316,7 +1327,6 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
$deg = (int) $matches[1];
$success = $sizer->rotate($deg);
}
-
}
if($success && $rebuildVariations) $pagefile->rebuildVariations();
@@ -1352,7 +1362,6 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
*
*/
protected function ___processUnknownFileAction(Pageimage $pagefile, $action, $label) {
- if($pagefile && $action && $label) {}
return null;
}