__('Images', __FILE__), // Module Title
'summary' => __('One or more image uploads (sortable)', __FILE__), // Module Summary
'version' => 110,
'permanent' => true,
);
}
public function init() {
parent::init();
$this->set('extensions', 'JPG JPEG GIF PNG');
$this->set('adminThumbs', false);
$this->set('maxWidth', '');
$this->set('maxHeight', '');
$this->set('minWidth', '');
$this->set('minHeight', '');
$this->set('adminThumbHeight', 100);
$this->set('itemClass', 'InputfieldFileItem InputfieldImage ui-widget');
$this->set('defaultGrid', 0);
//$this->modules->get("InputfieldFile"); // force the JS and CSS from InputfieldFile to also be loaded
}
public function ___render() {
$this->modules->getInstall("JqueryMagnific");
$this->config->scripts->add($this->config->urls->InputfieldFile . "InputfieldFile.js");
$this->config->styles->add($this->config->urls->InputfieldFile . "InputfieldFile.css");
$out = parent::___render();
if($this->defaultGrid) $out .= "";
return $out;
}
public function ___renderValue() {
$out = '';
$value = $this->attr('value');
if(empty($value)) return '';
foreach($value as $pageimage) {
$thumb = $pageimage;
if($this->adminThumbs && $thumb->height > $this->adminThumbHeight) {
// create a variation for display with this inputfield
$thumb = $thumb->height($this->adminThumbHeight);
}
$alt = $this->wire('sanitizer')->entities($thumb->description);
$img = "";
if($thumb !== $pageimage) $img = "$img";
$out .= $img;
}
return $out;
}
/**
* Resize images to max width/height if specified in field config and image is larger than max
*
*/
protected function ___fileAdded(Pagefile $pagefile) {
$filename = $pagefile->filename;
$pagefile2 = null;
if(!$pagefile->width) {
$pagefile->unlink();
throw new WireException($this->_('Invalid image'));
}
if(($this->minWidth && $pagefile->width < $this->minWidth) || ($this->minHeight && $pagefile->height < $this->minHeight)) {
$actualDimensions = $pagefile->width . 'x' . $pagefile->height;
$requiredDimensions = $this->minWidth . 'x' . $this->minHeight;
throw new WireException(sprintf($this->_('Image of %s does not meet minimum size requirements'), $actualDimensions) . " ($requiredDimensions)");
}
if(($this->maxWidth && $pagefile->width > $this->maxWidth) || ($this->maxHeight && $pagefile->height > $this->maxHeight)) {
$pagefile2 = $pagefile->size($this->maxWidth, $this->maxHeight, array('cropping' => false));
if($pagefile->filename != $pagefile2->filename) {
unlink($pagefile->filename);
rename($pagefile2->filename, $pagefile->filename);
}
$pagefile->getImageInfo(true); // force it to reload it's dimensions
}
if($pagefile2) {
$this->message($this->_("Image resized to fit maximum allowed dimensions") . " ({$this->maxWidth}x{$this->maxHeight}");
}
return parent::___fileAdded($pagefile);
}
protected function ___renderItem($pagefile, $id, $n) {
$thumb = $pagefile;
$error = '';
$imgAttr = '';
if($this->adminThumbs) {
$thumbHeight = $thumb->height;
if($thumbHeight > $this->adminThumbHeight) {
// create a variation for display with this inputfield
$thumb = $thumb->height($this->adminThumbHeight);
if($thumb->error) $error = "$thumb->error";
$thumbHeight = $this->adminThumbHeight;
}
$imgAttr = " height='$thumbHeight'";
}
$thumbUrl = $thumb->url;
// ensure cached image doesn't get shown when replacing same filename
if($this->overwrite) $thumbUrl .= "?m=" . filemtime($pagefile->pathname);
$out =
"\n\t\t