From 6e11cb59d1222d4e3cbeebd44e67ca526bcc7963 Mon Sep 17 00:00:00 2001 From: Jonathan Lahijani Date: Mon, 24 Jun 2019 08:50:36 -0700 Subject: [PATCH 1/5] pw namespace --- FieldtypeSelectFile.module | 3 +-- InputfieldSelectFile.module | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/FieldtypeSelectFile.module b/FieldtypeSelectFile.module index b5c6de1..f88f6fa 100644 --- a/FieldtypeSelectFile.module +++ b/FieldtypeSelectFile.module @@ -1,5 +1,4 @@ - Date: Mon, 24 Jun 2019 08:53:49 -0700 Subject: [PATCH 2/5] change title (not classname) of fieldtype and inputfield to be consistent with pw naming conventions --- FieldtypeSelectFile.module | 4 ++-- InputfieldSelectFile.module | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/FieldtypeSelectFile.module b/FieldtypeSelectFile.module index f88f6fa..24e6584 100644 --- a/FieldtypeSelectFile.module +++ b/FieldtypeSelectFile.module @@ -5,7 +5,7 @@ * * ©2015 Martijn Geerts * - * ProcessWire 2.x + * ProcessWire 3.x * Copyright (C) 2010 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * @@ -25,7 +25,7 @@ class FieldtypeSelectFile extends FieldtypeText { */ public static function getModuleInfo() { return array( - 'title' => __('Fieldtype select file'), + 'title' => __('Select File'), 'version' => 104, 'summary' => __('Fieldtype that stores a file or folder.'), 'author' => 'Martijn Geerts', diff --git a/InputfieldSelectFile.module b/InputfieldSelectFile.module index 4182567..99dc781 100644 --- a/InputfieldSelectFile.module +++ b/InputfieldSelectFile.module @@ -1,12 +1,11 @@ 'Inputfield select file', + 'title' => 'Select File', 'version' => 102, 'summary' => __('Inputfield to select a file or a folder.'), 'author' => 'Martijn Geerts', @@ -34,8 +31,6 @@ class InputfieldSelectFile extends InputfieldText { ); } - - /** * Return the completed output of Inputfield select file * From 5351daf3832841d8e127f439271c283fcdf473c5 Mon Sep 17 00:00:00 2001 From: Jonathan Lahijani Date: Mon, 24 Jun 2019 08:54:33 -0700 Subject: [PATCH 3/5] version bump; copyright year update --- FieldtypeSelectFile.module | 4 ++-- InputfieldSelectFile.module | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FieldtypeSelectFile.module b/FieldtypeSelectFile.module index 24e6584..9eee035 100644 --- a/FieldtypeSelectFile.module +++ b/FieldtypeSelectFile.module @@ -3,7 +3,7 @@ * Fieldtype 'select file' stores a file/folder name selected in the associated * Inputfield. * - * ©2015 Martijn Geerts + * ©2019 Martijn Geerts * * ProcessWire 3.x * Copyright (C) 2010 by Ryan Cramer @@ -26,7 +26,7 @@ class FieldtypeSelectFile extends FieldtypeText { public static function getModuleInfo() { return array( 'title' => __('Select File'), - 'version' => 104, + 'version' => 105, 'summary' => __('Fieldtype that stores a file or folder.'), 'author' => 'Martijn Geerts', 'href' => 'https://processwire.com/talk/topic/6377-fieldtypeselectfile-inputfieldselectfile/', diff --git a/InputfieldSelectFile.module b/InputfieldSelectFile.module index 99dc781..6d65a5b 100644 --- a/InputfieldSelectFile.module +++ b/InputfieldSelectFile.module @@ -3,7 +3,7 @@ * Inputfield 'select file' provides a HTML select to select a file or a folder * from disk. Per Inputfield you can set a folder to list from. * - * ©2015 Martijn Geerts + * ©2019 Martijn Geerts * * ProcessWire 3.x * Copyright (C) 2010 by Ryan Cramer @@ -23,7 +23,7 @@ class InputfieldSelectFile extends InputfieldText { public static function getModuleInfo() { return array( 'title' => 'Select File', - 'version' => 102, + 'version' => 103, 'summary' => __('Inputfield to select a file or a folder.'), 'author' => 'Martijn Geerts', 'href' => 'https://processwire.com/talk/topic/6377-fieldtypeselectfile-inputfieldselectfile/', From 4d5b64f505aabb47ddba2491002276290aaaaefa Mon Sep 17 00:00:00 2001 From: Jonathan Lahijani Date: Mon, 24 Jun 2019 09:39:03 -0700 Subject: [PATCH 4/5] php file description support --- FieldtypeSelectFile.module | 21 ++++++++++++++++----- InputfieldSelectFile.module | 9 +++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/FieldtypeSelectFile.module b/FieldtypeSelectFile.module index 9eee035..852f2cc 100644 --- a/FieldtypeSelectFile.module +++ b/FieldtypeSelectFile.module @@ -97,6 +97,7 @@ class FieldtypeSelectFile extends FieldtypeText { $inputfield = $this->modules->get('InputfieldSelectFile'); $inputfield->set('folderPath', $field->folderPath); $inputfield->set('fileExt', $field->fileExt); + $inputfield->set('fileDesc', $field->fileDesc); $inputfield->set('hideFiles', $field->hideFiles); $inputfield->set('hideFolders', $field->hideFolders); $inputfield->set('sort', $field->sort); @@ -104,7 +105,7 @@ class FieldtypeSelectFile extends FieldtypeText { return $inputfield; } - + /** * Get the inputfield used for configuration of this Fieldtype. @@ -146,17 +147,27 @@ class FieldtypeSelectFile extends FieldtypeText { $f->attr('autocheck', 1); $f->attr('uncheckedValue', 0); $f->attr('checkedValue', 1); - $f->columnWidth = 25; + $f->columnWidth = 20; $f->attr('value', $field->fileExt); $inputfields->add($f); + $f = $this->modules->get('InputfieldCheckbox'); + $f->attr('name', 'fileDesc'); + $f->label = $this->_("Hide PHP File Description"); + $f->attr('autocheck', 1); + $f->attr('uncheckedValue', 0); + $f->attr('checkedValue', 1); + $f->columnWidth = 20; + $f->attr('value', $field->fileDesc); + $inputfields->add($f); + $f = $this->modules->get('InputfieldCheckbox'); $f->attr('name', 'hideFiles'); $f->label = $this->_("Hide Files"); $f->attr('autocheck', 1); $f->attr('uncheckedValue', 0); $f->attr('checkedValue', 1); - $f->columnWidth = 25; + $f->columnWidth = 20; $f->attr('value', $field->hideFiles); $inputfields->add($f); @@ -166,7 +177,7 @@ class FieldtypeSelectFile extends FieldtypeText { $f->attr('autocheck', 1); $f->attr('uncheckedValue', 0); $f->attr('checkedValue', 1); - $f->columnWidth = 25; + $f->columnWidth = 20; $f->attr('value', $field->hideFolders); $inputfields->add($f); @@ -176,7 +187,7 @@ class FieldtypeSelectFile extends FieldtypeText { $f->attr('autocheck', 1); $f->attr('uncheckedValue', 0); $f->attr('checkedValue', 1); - $f->columnWidth = 25; + $f->columnWidth = 20; $f->attr('value', $field->sort); $inputfields->add($f); diff --git a/InputfieldSelectFile.module b/InputfieldSelectFile.module index 6d65a5b..24fbfec 100644 --- a/InputfieldSelectFile.module +++ b/InputfieldSelectFile.module @@ -41,6 +41,7 @@ class InputfieldSelectFile extends InputfieldText { $array = array(); $folder = $this->config->paths->templates . trim(trim($this->folderPath), '/') . "/"; + $phpFileDescription = false; if(!is_dir($folder)) { $this->error($this->_("Path to files is invalid")); @@ -60,6 +61,14 @@ class InputfieldSelectFile extends InputfieldText { } else { $label = $entry; } + // pull "Description" comment from php files if it exists (inspired by WordPress "Template Name" comment) + if( !$this->fileDesc && pathinfo($entry)['extension']=='php' ) { + $phpFileData = implode( '', file( $folder . $entry ) ); + if ( preg_match( '|Description:(.*)$|mi', $phpFileData, $desc ) ) { + $phpFileDescription = trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $desc[1] ) ); + $label .= " ($phpFileDescription)"; + } + } $selected = $entry == $this->value ? " selected" : ''; $array[] = ""; From 1b53f4a7fac548bcbcb2658cc9d53e66a75abfce Mon Sep 17 00:00:00 2001 From: Jonathan Lahijani Date: Mon, 24 Jun 2019 09:46:12 -0700 Subject: [PATCH 5/5] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8735e77..6d55b00 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ * The folder containing the files and/or folders. - A relative path relative to the /site/templates/ folder. * Hide file extensions +* Hide PHP File Description + - PHP files can have a comment called "Description" at the top of the file which will be displayed in the dropdown if it exists. Check this option to disable it. * Hide files * Hide folders * Natural Sort (Select options)