From 483b63d49691418f61214f893736342901b3de01 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 30 Dec 2022 12:24:04 -0500 Subject: [PATCH] Various minor updates --- wire/core/Fieldgroup.php | 13 +++- wire/core/PagefilesManager.php | 70 +++++++++++++++++++ .../ProcessPageEditImageSelect.module | 7 +- .../ProcessPageList/ProcessPageListRender.php | 15 +++- .../ProcessTemplate/ProcessTemplate.module | 2 +- 5 files changed, 102 insertions(+), 5 deletions(-) diff --git a/wire/core/Fieldgroup.php b/wire/core/Fieldgroup.php index 97199517..9166cc46 100644 --- a/wire/core/Fieldgroup.php +++ b/wire/core/Fieldgroup.php @@ -512,7 +512,12 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * @param Page $page Page that the Inputfields will be for. * @param string|array $contextStr Optional context string to append to all the Inputfield names, OR array of options. * - Optional context string is helpful for things like repeaters. - * - You may instead specify associative array of any method arguments if preferred. + * - Or associative array with any of these options: + * - `contextStr` (string): Context string to append to all Inputfield names. + * - `fieldName` (string|array): Limit to particular fieldName(s) or field ID(s). See $fieldName argument for details. + * - `namespace` (string): Additional namespace for Inputfield context. + * - `flat` (bool): Return all Inputfields in a flattened InputfieldWrapper? + * - `populate` (bool): Populate page values to Inputfields? (default=true) since 3.0.208 * @param string|array $fieldName Limit to a particular fieldName(s) or field IDs (optional). * - If specifying a single field (name or ID) and it refers to a fieldset, then all fields in that fieldset will be included. * - If specifying an array of field names/IDs the returned InputfieldWrapper will maintain the requested order. @@ -530,13 +535,17 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte 'fieldName' => $fieldName, 'namespace' => $namespace, 'flat' => $flat, + 'populate' => true, // populate page values? ); $options = $contextStr; $options = array_merge($defaults, $options); $contextStr = $options['contextStr']; $fieldName = $options['fieldName']; $namespace = $options['namespace']; + $populate = (bool) $options['populate']; $flat = $options['flat']; + } else { + $populate = true; } $container = $this->wire(new InputfieldWrapper()); @@ -649,7 +658,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte if(!$inputfield) continue; if($inputfield->collapsed == Inputfield::collapsedHidden) continue; - if(!$page instanceof NullPage) { + if($populate && !$page instanceof NullPage) { $value = $page->get($field->name); $inputfield->setAttribute('value', $value); } diff --git a/wire/core/PagefilesManager.php b/wire/core/PagefilesManager.php index 2b88bc5d..a58ac1b6 100644 --- a/wire/core/PagefilesManager.php +++ b/wire/core/PagefilesManager.php @@ -600,6 +600,76 @@ class PagefilesManager extends Wire { return $filesPath; } + /** + * Get all potential disk paths for given Page files (not yet in use) + * + * @todo FOR FUTURE USE + * @param Page $page + * @return string[] + * + static public function _paths(Page $page) { + $config = $page->wire()->config; + $path = $config->paths->files; + $securePrefix = $config->pagefileSecurePathPrefix; + $useSecure = $page->secureFiles(); + $useExtended = $config->pagefileExtendedPaths; + $useUnique = $config->pagefileUnique && $page->hasStatus(Page::statusUnique); + + if(!strlen($securePrefix)) $securePrefix = self::defaultSecurePathPrefix; + + $paths = array( + 'current' => '', + 'normal' => $path . "$page->id/", + 'unique' => $path . "0/$page->name/", + 'extended' => $path . self::_dirExtended($page->id), + 'secure' => $path . $securePrefix . "$page->id/", + 'secureUnique' => $path . "0/$securePrefix$page->name/", + 'secureExtended' => $path . self::_dirExtended($page->id, $securePrefix), + ); + + if($useUnique) { + // use unique page name paths + $paths['current'] = ($useSecure ? $paths['secureUnique'] : $paths['unique']); + + } else if($useSecure) { + // use secure files + $paths['current'] = ($useExtended ? $paths['secureExtended'] : $paths['secure']); + + } else { + // use normal path + $paths['current'] = ($useExtended ? $paths['extended'] : $paths['normal']); + } + + return $paths; + } + */ + + /** + * Scan all paths for page and make sure only the correct one exists (not yet in use) + * + * Also crates and moves files when necessary. + * + * @todo FOR FUTURE USE + * @param Page $page + * + private function verifyPaths(Page $page) { + $paths = self::_paths($page); + $current = $paths['current']; + $currentExists = is_dir($current); + unset($paths['current']); + foreach($paths as $path) { + if(!is_dir($path)) continue; + if(!$currentExists) { + $this->_createPath($current); + $currentExists = true; + } + $this->_copyFiles($path, $current); + $this->wire()->files->rmdir($path, true); + self::$numRenamedPaths++; + } + } + */ + /** * Get quantity of renamed paths to to pagefileSecure changes * diff --git a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module index e904b91b..0d222d19 100644 --- a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module +++ b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module @@ -1369,7 +1369,10 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { $json = (int) $input->get('json'); // 1 or 0 (for json output mode on or off) $rotate = (int) $input->get('rotate'); $flip = $input->get('flip'); + $crop = $input->get('crop'); + if($flip != 'v' && $flip != 'h') $flip = ''; + if($crop !== null && (!ctype_alnum($crop) || strlen($crop) > 20)) $crop = ''; if(strpos($class, 'hidpi') !== false) { if(!$hidpi) $hidpi = true; @@ -1378,7 +1381,8 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { } $image = $this->getPageimage(true); - if(strpos($image->basename, '-cropx') !== false) $image = $this->getLastCrop($image); + + if(!$crop && strpos($image->basename, '-cropx') !== false) $image = $this->getLastCrop($image); if( (!$hidpi && $width < $image->width) || ($hidpi && $width < $image->hidpiWidth()) || @@ -1392,6 +1396,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { ); if($rotate) $options['rotate'] = $rotate; if($flip) $options['flip'] = $flip; + if($crop) $options['cropping'] = $crop; //$this->log(print_r($options, true)); $resized = $image->width($width, $options); $height = $resized->height(); diff --git a/wire/modules/Process/ProcessPageList/ProcessPageListRender.php b/wire/modules/Process/ProcessPageList/ProcessPageListRender.php index fcb86c7a..b780ba08 100644 --- a/wire/modules/Process/ProcessPageList/ProcessPageListRender.php +++ b/wire/modules/Process/ProcessPageList/ProcessPageListRender.php @@ -284,7 +284,20 @@ abstract class ProcessPageListRender extends Wire { * */ public function ___getPageActions(Page $page) { - return $this->actions->getActions($page); + $actions = $this->actions->getActions($page); + /* + * @todo force 'extras' option to be last + if(isset($actions['extras'])) { + $keys = array_keys($actions); + $lastKey = array_pop($keys); + if($lastKey !== 'extras') { + $extras = $actions['extras']; + unset($actions['extras']); + $actions['extras'] = $extras; // move to last + } + } + */ + return $actions; } /** diff --git a/wire/modules/Process/ProcessTemplate/ProcessTemplate.module b/wire/modules/Process/ProcessTemplate/ProcessTemplate.module index 0be53463..fae1a3ac 100644 --- a/wire/modules/Process/ProcessTemplate/ProcessTemplate.module +++ b/wire/modules/Process/ProcessTemplate/ProcessTemplate.module @@ -652,7 +652,7 @@ class ProcessTemplate extends Process implements ConfigurableModule { $template->roles = array($this->wire()->roles->getGuestRole()->id); $template->save(); - $this->message(sprintf($this->_('Added template and fieldgroup: %s'), $basename)); + $this->message(sprintf($this->_('Added template and fieldgroup: %s'), $template->name)); $addedTemplates[] = $template; } catch(\Exception $e) {