From 18d2fdf94a80c4db29055fe3a7358e16f4bcba8c Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 23 Jun 2023 13:47:34 -0400 Subject: [PATCH] Update ProcessPageEditImageSelect to use proper HTML class name attributes for checkbox and radio buttons when used with AdminThemeUikit. Plus other minor code improvements --- .../ProcessLanguageTranslator.module | 1 + .../ProcessPageEditImageSelect.css | 4 - .../ProcessPageEditImageSelect.module | 99 +++++++++++-------- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/wire/modules/LanguageSupport/ProcessLanguageTranslator.module b/wire/modules/LanguageSupport/ProcessLanguageTranslator.module index 70306f75..2ae6bc8c 100644 --- a/wire/modules/LanguageSupport/ProcessLanguageTranslator.module +++ b/wire/modules/LanguageSupport/ProcessLanguageTranslator.module @@ -467,6 +467,7 @@ class ProcessLanguageTranslator extends Process implements ConfigurableModule { $c = strpos($matches[1], '|') ? '|' : ','; $options = explode($c, $matches[1]); $comment = str_replace($matches[0], '', $comment); + if(empty($type)) $type = 'Radios'; } else { $options = array(); } diff --git a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.css b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.css index ec702c5b..d43d0f9e 100644 --- a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.css +++ b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.css @@ -224,10 +224,6 @@ small.ui-helper-clearfix { display: inline; } -#selected_image_link { - display: inline; -} - #instructions { margin: 1em 0; clear: both; diff --git a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module index d80a5aa5..866eac46 100644 --- a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module +++ b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module @@ -5,7 +5,7 @@ * * Provides the image selecting and editing capability for rich text editors (TinyMCE/CKEditor) * - * ProcessWire 3.x, Copyright 2022 by Ryan Cramer + * ProcessWire 3.x, Copyright 2023 by Ryan Cramer * https://processwire.com * * @property int $hidpiDefault HiDPI/Retina checkbox default checked? @@ -27,7 +27,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { return array( 'title' => 'Page Edit Image', 'summary' => 'Provides image manipulation functions for image fields and rich text editors.', - 'version' => 120, + 'version' => 121, 'permanent' => true, 'permission' => 'page-edit', ); @@ -64,8 +64,6 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { * */ protected $editorPage = null; - //protected $defaultClass = 'Pageimage'; - //protected $file = ''; /** * If editing a filename that is a variation, this is the width determined from the filename (123x456) @@ -374,7 +372,9 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $originalFilename = $this->wire()->sanitizer->filename($originalFilename, false, 1024); // if requested file does not match one of our allowed extensions, abort - if(!preg_match('/\.(' . $this->extensions . ')$/iD', $file, $matches)) throw new WireException("Unknown image file"); + if(!preg_match('/\.(' . $this->extensions . ')$/iD', $file, $matches)) { + throw new WireException("Unknown image file"); + } // get the original, non resized version, if present // format: w x h crop -suffix @@ -394,7 +394,9 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $file = "{$this->page->id},$originalFilename"; // if requested file is not one that we have, abort - if(!array_key_exists($file, $images)) throw new WireException("Cannot find image file '$originalFilename' on page: {$this->page->path}"); + if(!array_key_exists($file, $images)) { + throw new WireException("Cannot find image file '$originalFilename' on page: {$this->page->path}"); + } // return original if(!$getVariation) return $images[$file]; @@ -403,8 +405,12 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $original = $images[$file]; $variationPathname = $original->pagefiles->path() . $variationFilename; $pageimage = null; - if(is_file($variationPathname)) $pageimage = $this->wire(new Pageimage($original->pagefiles, $variationPathname)); - if(!$pageimage) throw new WireException("Unrecognized variation file: $file"); + if(is_file($variationPathname)) { + $pageimage = $this->wire(new Pageimage($original->pagefiles, $variationPathname)); + } + if(!$pageimage) { + throw new WireException("Unrecognized variation file: $file"); + } return $pageimage; } @@ -543,12 +549,13 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $sanitizer = $this->wire()->sanitizer; $modules = $this->wire()->modules; + $input = $this->wire()->input; $images = $this->getImages($this->page, $this->page->fields); $out = ''; if(wireCount($images)) { - $winwidth = (int) $this->wire()->input->get('winwidth'); + $winwidth = (int) $input->get('winwidth'); $in = $modules->get('InputfieldImage'); /** @var InputfieldImage $in */ $in->set('adminThumbs', true); $lastFieldLabel = ''; @@ -617,7 +624,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $btn->value = $this->_('Upload Image'); $btn->addClass('upload pw-modal-button pw-modal-button-visible'); $btn->icon = 'upload'; - $changes = $this->wire('input')->get('changes'); + $changes = $input->get('changes'); if($changes) { foreach(explode(',', $changes) as $name) { $name = $sanitizer->fieldName($name); @@ -682,6 +689,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { * */ protected function makeEditURL($file, $parts = array()) { + $input = $this->wire()->input; $file = basename($file); $id = isset($parts['id']) ? (int) $parts['id'] : $this->page->id; @@ -696,8 +704,8 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $parts['original'] = $file; } } - if(!isset($parts['class']) && $this->wire('input')->get('class')) { - $class = $this->wire('input')->get('class'); + if(!isset($parts['class']) && $input->get('class')) { + $class = $input->get('class'); if($class) { $validClasses = array($this->alignLeftClass, $this->alignCenterClass, $this->alignRightClass); $classes = array(); @@ -711,7 +719,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { if($this->field) $parts['field'] = $this->fieldName; if(!isset($parts['winwidth'])) { - $winwidth = (int) $this->wire('input')->get('winwidth'); + $winwidth = (int) $input->get('winwidth'); if($winwidth) $parts['winwidth'] = $winwidth; } @@ -723,7 +731,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { unset($parts['id'], $parts['file']); // in case they are set here - $url = $this->wire('config')->urls->admin . "page/image/edit/?id=$id&file=$id,$file"; + $url = $this->wire()->config->urls->admin . "page/image/edit/?id=$id&file=$id,$file"; foreach($parts as $key => $value) $url .= "&$key=$value"; @@ -739,7 +747,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { * */ public function checkImageEditPermission($throw = true) { - if(!$this->rte && !$this->wire('user')->hasPermission('page-edit-images', $this->masterPage)) { + if(!$this->rte && !$this->wire()->user->hasPermission('page-edit-images', $this->masterPage)) { if($throw) { throw new WirePermissionException($this->labels['noAccess']); } else { @@ -782,18 +790,21 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { */ public function ___executeEdit() { - - /** @var WireInput $input */ - $input = $this->wire('input'); - /** @var Config $config */ - $config = $this->wire('config'); + $input = $this->wire()->input; + $config = $this->wire()->config; + $session = $this->wire()->session; + $sanitizer = $this->wire()->sanitizer; + $adminTheme = $this->wire()->adminTheme; + + $checkboxClass = $adminTheme instanceof AdminThemeFramework ? $adminTheme->getClass('input-checkbox') : ''; + $radioClass = $adminTheme instanceof AdminThemeFramework ? $adminTheme->getClass('input-radio') : ''; $this->checkImageEditPermission(); if($input->post('submit_crop')) { $crop = $this->processCrop(); $parts = $this->hidpi ? array('width' => $crop->hidpiWidth()) : array(); - $this->wire('session')->redirect($this->makeEditURL($crop->basename, $parts)); + $session->location($this->makeEditURL($crop->basename, $parts)); return ''; } else if($input->post('submit_save_replace')) { return $this->processSave(true); @@ -844,7 +855,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { if($this->rte) { // when RTE mode, go to image selection again when invalid image $this->error($e->getMessage()); - $this->wire('session')->redirect("./?id={$this->page->id}"); + $session->location("./?id={$this->page->id}"); return ''; } else { throw $e; @@ -963,7 +974,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { // prepare description (alt) $description = isset($_GET['description']) ? $input->get('description') : ''; // $image->description; if(strlen($description) > 8192) $description = substr($description, 0, 8192); - $description = $this->wire('sanitizer')->entities($description); + $description = $sanitizer->entities($description); // if dealing with a variation size or crop provide the option to link to the original (larger) $linkOriginalChecked = ''; @@ -1029,28 +1040,28 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . "" . // selected_image_checkboxes "" . " " . "$labels[useResize]  " . - "  " . - "" . "