Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions 32 FieldtypeSelectFile.module
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

<?php namespace ProcessWire;
/**
* Fieldtype 'select file' stores a file/folder name selected in the associated
* Inputfield.
*
* ©2015 Martijn Geerts
* ©2019 Martijn Geerts
*
* ProcessWire 2.x
* ProcessWire 3.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
Expand All @@ -26,8 +25,8 @@ class FieldtypeSelectFile extends FieldtypeText {
*/
public static function getModuleInfo() {
return array(
'title' => __('Fieldtype select file'),
'version' => 104,
'title' => __('Select File'),
'version' => 105,
'summary' => __('Fieldtype that stores a file or folder.'),
'author' => 'Martijn Geerts',
'href' => 'https://processwire.com/talk/topic/6377-fieldtypeselectfile-inputfieldselectfile/',
Expand Down Expand Up @@ -98,14 +97,15 @@ 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);
$inputfield->set('template', $field->template);
return $inputfield;
}



/**
* Get the inputfield used for configuration of this Fieldtype.
Expand Down Expand Up @@ -147,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);

Expand All @@ -167,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);

Expand All @@ -177,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);

Expand Down
24 changes: 14 additions & 10 deletions 24 InputfieldSelectFile.module
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

<?php namespace ProcessWire;
/**
* 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 2.x
* ProcessWire 3.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
Expand All @@ -16,26 +15,22 @@
*/
class InputfieldSelectFile extends InputfieldText {



/**
* Return an array of module information
*
* @return array
*/
public static function getModuleInfo() {
return array(
'title' => 'Inputfield select file',
'version' => 102,
'title' => 'Select File',
'version' => 103,
'summary' => __('Inputfield to select a file or a folder.'),
'author' => 'Martijn Geerts',
'href' => 'https://processwire.com/talk/topic/6377-fieldtypeselectfile-inputfieldselectfile/',
'requires' => 'FieldtypeSelectFile',
);
}



/**
* Return the completed output of Inputfield select file
*
Expand All @@ -46,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"));
Expand All @@ -65,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[] = "<option value='$entry'$selected>$label</option>";
Expand Down
2 changes: 2 additions & 0 deletions 2 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.