show files and folders in dropfolder dir recursively

This commit is contained in:
Uwe Steinmann 2023-10-12 16:02:50 +02:00
parent ab82a65bcc
commit 40f2311b91
6 changed files with 96 additions and 52 deletions

View File

@ -7,6 +7,7 @@
- do not show unreadable documents on Dashboard - do not show unreadable documents on Dashboard
- fix creating preview image of file in drop folder if it contains - fix creating preview image of file in drop folder if it contains
special chars special chars
- show fileѕ and folders in dropfolder dir recursively
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Changes in version 5.1.32 Changes in version 5.1.32

View File

@ -44,6 +44,11 @@ if(isset($_GET['showfolders']) && $_GET['showfolders'])
else else
$showfolders = false; $showfolders = false;
if(isset($_GET['recursive']) && $_GET['recursive'])
$recursive = true;
else
$recursive = false;
if (isset($_GET["folderid"]) && is_numeric($_GET["folderid"])) { if (isset($_GET["folderid"]) && is_numeric($_GET["folderid"])) {
$folderid = intval($_GET["folderid"]); $folderid = intval($_GET["folderid"]);
$folder = $dms->getFolder($folderid); $folder = $dms->getFolder($folderid);
@ -66,6 +71,7 @@ if($view) {
$view->setParam('timeout', $settings->_cmdTimeout); $view->setParam('timeout', $settings->_cmdTimeout);
$view->setParam('xsendfile', $settings->_enableXsendfile); $view->setParam('xsendfile', $settings->_enableXsendfile);
$view->setParam('showfolders', $showfolders); $view->setParam('showfolders', $showfolders);
$view->setParam('recursive', $recursive);
$view->setParam('folder', $folder); $view->setParam('folder', $folder);
$view($_GET); $view($_GET);
exit; exit;

View File

@ -426,8 +426,10 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
if($this->params['dropfolderdir'] && $this->params['enabledropfolderlist']) { if($this->params['dropfolderdir'] && $this->params['enabledropfolderlist']) {
echo " <div id=\"menu-dropfolder\">"; echo " <div id=\"menu-dropfolder\">";
echo " <div class=\"ajax\" data-no-spinner=\"true\" data-view=\"DropFolderChooser\" data-action=\"menuList\""; echo " <div class=\"ajax\" data-no-spinner=\"true\" data-view=\"DropFolderChooser\" data-action=\"menuList\"";
$query = 'recursive=1';
if ($folder!=null && is_object($folder) && $folder->isType('folder')) if ($folder!=null && is_object($folder) && $folder->isType('folder'))
echo " data-query=\"folderid=".$folder->getID()."\""; $query .= "&folderid=".$folder->getID();
echo " data-query=\"".$query."\"";
echo "></div>"; echo "></div>";
echo " </div>"; echo " </div>";
} }
@ -2020,18 +2022,18 @@ $(document).ready(function() {
return $content; return $content;
} /* }}} */ } /* }}} */
function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */ function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
echo self::getDropFolderChooserHtml($formName, $dropfolderfile, $showfolders); echo self::getDropFolderChooserHtml($formName, $dropfolderfile, $showfolders, $recursive);
} /* }}} */ } /* }}} */
function getDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */ function getDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
$content = "<div class=\"input-append\">\n"; $content = "<div class=\"input-append\">\n";
$content .= "<input readonly type=\"text\" class=\"fileupload-group\" id=\"dropfolderfile".$formName."\" name=\"dropfolderfile".$formName."\" value=\"".htmlspecialchars($dropfolderfile)."\">"; $content .= "<input readonly type=\"text\" class=\"fileupload-group\" id=\"dropfolderfile".$formName."\" name=\"dropfolderfile".$formName."\" value=\"".htmlspecialchars($dropfolderfile)."\">";
$content .= "<button type=\"button\" class=\"btn\" id=\"clearfilename".$formName."\"><i class=\"fa fa-remove\"></i></button>"; $content .= "<button type=\"button\" class=\"btn\" id=\"clearfilename".$formName."\"><i class=\"fa fa-remove\"></i></button>";
$content .= $this->getModalBoxLink( $content .= $this->getModalBoxLink(
array( array(
'target' => 'dropfolderChooser', 'target' => 'dropfolderChooser',
'remote' => $this->params['settings']->_httpRoot."out/out.DropFolderChooser.php?form=".$formName."&dropfolderfile=".urlencode($dropfolderfile)."&showfolders=".$showfolders, 'remote' => $this->params['settings']->_httpRoot."out/out.DropFolderChooser.php?form=".$formName."&dropfolderfile=".urlencode($dropfolderfile)."&showfolders=".$showfolders."&recursive=".$recursive,
'title' => ($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file")).'…' 'title' => ($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file")).'…'
)); ));
$content .= "</div>\n"; $content .= "</div>\n";
@ -2070,8 +2072,8 @@ $(document).ready(function() {
<?php <?php
} /* }}} */ } /* }}} */
function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */ function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
$this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders); $this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders, $recursive);
?> ?>
<script language="JavaScript"> <script language="JavaScript">
<?php <?php

View File

@ -47,12 +47,43 @@ $('.folderselect').click(function(ev) {
<?php <?php
} /* }}} */ } /* }}} */
private function getFiles($path, $recursive=false) {
if($recursive)
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
else
$rii = new DirectoryIterator($path);
$files = array();
foreach ($rii as $file)
if (!$file->isDir())
$files[] = [substr($file->getPath(), strlen($path)+1), $file->getFilename()];
return $files;
}
private function getFolders($path, $recursive=false) {
if($recursive)
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
else
$rii = new DirectoryIterator($path);
$files = array();
foreach ($rii as $file)
if ($file->isDir()) {
if(($t = substr($file->getPath(), strlen($path)+1)) && ($file->getFilename() == '.'))
$files[] = $t;
}
return $files;
}
public function menuList() { /* {{{ */ public function menuList() { /* {{{ */
$dms = $this->params['dms']; $dms = $this->params['dms'];
$user = $this->params['user']; $user = $this->params['user'];
$settings = $this->params['settings']; $settings = $this->params['settings'];
$dropfolderdir = $this->params['dropfolderdir']; $dropfolderdir = $this->params['dropfolderdir'];
$showfolders = $this->params['showfolders']; $showfolders = $this->params['showfolders'];
$recursive = $this->params['recursive'];
$cachedir = $this->params['cachedir']; $cachedir = $this->params['cachedir'];
$conversionmgr = $this->params['conversionmgr']; $conversionmgr = $this->params['conversionmgr'];
$previewwidth = $this->params['previewWidthMenuList']; $previewwidth = $this->params['previewWidthMenuList'];
@ -70,35 +101,31 @@ $('.folderselect').click(function(ev) {
$c = 0; // count files $c = 0; // count files
$menuitems['dropfolder'] = array('label'=>'', 'children'=>array()); $menuitems['dropfolder'] = array('label'=>'', 'children'=>array());
$dir = rtrim($dropfolderdir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$user->getLogin(); $dir = rtrim($dropfolderdir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$user->getLogin();
/* Check if we are still looking in the configured directory and /* Check if we are still looking in the configured directory and
* not somewhere else, e.g. if the login was '../test' * not somewhere else, e.g. if the login was '../test'
*/ */
if(dirname($dir) == $dropfolderdir) { if(dirname($dir) == $dropfolderdir) {
if(is_dir($dir)) { if(is_dir($dir)) {
$d = dir($dir); $files = $this->getFiles($dir, $recursive);
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
while (false !== ($entry = $d->read())) { foreach($files as $file) {
if($entry != '..' && $entry != '.') { $entry = $file[1];
if($showfolders == 0 && !is_dir($dir.DIRECTORY_SEPARATOR.$entry) && is_readable($dir.DIRECTORY_SEPARATOR.$entry)) { $path = $file[0];
$c++; $c++;
$subitem = array('label'=>'', 'attributes'=>array(array('title', getMLText('menu_upload_from_dropfolder')))); $subitem = array('label'=>'', 'attributes'=>array(array('title', getMLText('menu_upload_from_dropfolder'))));
if($folder) if($folder)
$subitem['link'] = $settings->_httpRoot.'out/out.AddDocument.php?folderid='.$folder->getId()."&dropfolderfileform1=".urldecode($entry); $subitem['link'] = $settings->_httpRoot.'out/out.AddDocument.php?folderid='.$folder->getId()."&dropfolderfileform1=".urldecode($path.DIRECTORY_SEPARATOR.$entry);
$mimetype = finfo_file($finfo, $dir.DIRECTORY_SEPARATOR.$entry); $mimetype = finfo_file($finfo, $dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry);
if($previewwidth) { if($previewwidth) {
$previewer->createRawPreview($dir.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR, $mimetype); $previewer->createRawPreview($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR, $mimetype);
if($previewer->hasRawPreview($dir.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR)) { if($previewer->hasRawPreview($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR)) {
$subitem['label'] .= "<div class=\"dropfolder-menu-img\" style=\"display: none; overflow:hidden; position: absolute; left:-".($previewwidth+10)."px; border: 1px solid #888;background: white;\"><img filename=\"".htmlspecialchars($entry)."\" width=\"".$previewwidth."\" src=\"".$settings->_httpRoot."op/op.DropFolderPreview.php?filename=".urlencode($entry)."&width=".$previewwidth."\" title=\"".htmlspecialchars($mimetype)."\"></div>"; $subitem['label'] .= "<div class=\"dropfolder-menu-img\" style=\"display: none; overflow:hidden; position: absolute; left:-".($previewwidth+10)."px; border: 1px solid #888;background: white;\"><img filename=\"".htmlspecialchars($entry)."\" width=\"".$previewwidth."\" src=\"".$settings->_httpRoot."op/op.DropFolderPreview.php?filename=".urlencode($path.DIRECTORY_SEPARATOR.$entry)."&width=".$previewwidth."\" title=\"".htmlspecialchars($mimetype)."\"></div>";
}
}
$subitem['label'] .= "<div class=\"dropfolder-menu-text\" style=\"margin-left:10px; margin-right: 10px; display:inline-block;\">".htmlspecialchars($entry)."<br /><span style=\"font-size: 85%;\">".SeedDMS_Core_File::format_filesize(filesize($dir.'/'.$entry)).", ".date('Y-m-d H:i:s', filectime($dir.'/'.$entry))."</span></div>";
$menuitems['dropfolder']['children'][] = $subitem;
} elseif($showfolders && is_dir($dir.'/'.$entry)) {
$subitem = array('label'=>$entry);
$menuitems['dropfolder']['children'][] = $subitem;
} }
} }
$subitem['label'] .= "<div class=\"dropfolder-menu-text\" style=\"margin-left:10px; margin-right: 10px; display:inline-block;\">".htmlspecialchars($path.DIRECTORY_SEPARATOR.$entry)."<br /><span style=\"font-size: 85%;\">".SeedDMS_Core_File::format_filesize(filesize($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry)).", ".date('Y-m-d H:i:s', filectime($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry))."</span></div>";
$menuitems['dropfolder']['children'][] = $subitem;
} }
} }
} }
@ -121,6 +148,7 @@ $('.folderselect').click(function(ev) {
$timeout = $this->params['timeout']; $timeout = $this->params['timeout'];
$xsendfile = $this->params['xsendfile']; $xsendfile = $this->params['xsendfile'];
$showfolders = $this->params['showfolders']; $showfolders = $this->params['showfolders'];
$recursive = $this->params['recursive'];
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile);
if($conversionmgr) if($conversionmgr)
@ -134,28 +162,33 @@ $('.folderselect').click(function(ev) {
*/ */
if(dirname($dir) == $dropfolderdir) { if(dirname($dir) == $dropfolderdir) {
if(is_dir($dir)) { if(is_dir($dir)) {
$d = dir($dir);
echo "<table class=\"table table-condensed\">\n"; echo "<table class=\"table table-condensed\">\n";
echo "<thead>\n"; echo "<thead>\n";
echo "<tr><th></th><th>".getMLText('name')."</th><th align=\"right\">".getMLText('file_size')."</th><th>".getMLText('date')."</th></tr>\n"; echo "<tr><th></th><th>".getMLText('name')."</th><th align=\"right\">".getMLText('file_size')."</th><th>".getMLText('date')."</th></tr>\n";
echo "</thead>\n"; echo "</thead>\n";
echo "<tbody>\n"; echo "<tbody>\n";
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
while (false !== ($entry = $d->read())) { if($showfolders) {
if($entry != '..' && $entry != '.') { $folders = $this->getFolders($dir, $recursive);
if($showfolders == 0 && !is_dir($dir.'/'.$entry)) { foreach($folders as $entry) {
$mimetype = finfo_file($finfo, $dir.'/'.$entry); echo "<tr>";
$previewer->createRawPreview($dir.'/'.$entry, 'dropfolder/', $mimetype); echo '<td><img draggable="false" src="/views/bootstrap4/images/folder.svg" width="24" height="24" border="0"></td>';
echo "<tr><td style=\"min-width: ".$previewwidth."px;\">"; echo "<td><span style=\"cursor: pointer;\" class=\"folderselect\" data-foldername=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\"></td><td></td>";
if($previewer->hasRawPreview($dir.'/'.$entry, 'dropfolder/')) { echo "</tr>\n";
echo "<img style=\"cursor: pointer;\" class=\"fileselect mimeicon\" data-filename=\"".htmlspecialchars($entry)."\" data-form=\"".$form."\" width=\"".$previewwidth."\" src=\"../op/op.DropFolderPreview.php?filename=".urlencode($entry)."&width=".$previewwidth."\" title=\"".htmlspecialchars($mimetype)."\">"; }
} } else {
echo "</td><td><span style=\"cursor: pointer;\" class=\"fileselect\" data-filename=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\">".SeedDMS_Core_File::format_filesize(filesize($dir.'/'.$entry))."</td><td>".date('Y-m-d H:i:s', filectime($dir.'/'.$entry))."</td></tr>\n"; $files = $this->getFiles($dir, $recursive);
} elseif($showfolders && is_dir($dir.'/'.$entry)) { foreach($files as $file) {
echo "<tr>"; $entry = $file[1];
echo "<td></td>"; $path = $file[0];
echo "<td><span style=\"cursor: pointer;\" class=\"folderselect\" data-foldername=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\"></td><td></td>"; $mimetype = finfo_file($finfo, $dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry);
echo "</tr>\n"; if($previewwidth) {
$previewer->createRawPreview($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR, $mimetype);
echo "<tr><td style=\"min-width: ".$previewwidth."px;\">";
if($previewer->hasRawPreview($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR)) {
echo "<img style=\"cursor: pointer;\" class=\"fileselect mimeicon\" data-filename=\"".htmlspecialchars($path.DIRECTORY_SEPARATOR.$entry)."\" data-form=\"".$form."\" width=\"".$previewwidth."\" src=\"../op/op.DropFolderPreview.php?filename=".urlencode($path.DIRECTORY_SEPARATOR.$entry)."&width=".$previewwidth."\" title=\"".htmlspecialchars($mimetype)."\">";
}
echo "</td><td><span style=\"cursor: pointer;\" class=\"fileselect\" data-filename=\"".htmlspecialchars($path.DIRECTORY_SEPARATOR.$entry)."\" data-form=\"".$form."\">".htmlspecialchars($path.DIRECTORY_SEPARATOR.$entry)."</span></td><td align=\"right\">".SeedDMS_Core_File::format_filesize(filesize($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry))."</td><td>".date('Y-m-d H:i:s', filectime($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry))."</td></tr>\n";
} }
} }
} }

View File

@ -57,11 +57,11 @@ class SeedDMS_View_ImportFS extends SeedDMS_Theme_Style {
$this->formField(getMLText("choose_target_folder"), $this->getFolderChooserHtml("form1", M_READWRITE)); $this->formField(getMLText("choose_target_folder"), $this->getFolderChooserHtml("form1", M_READWRITE));
$this->formField( $this->formField(
getMLText("dropfolder_folder"), getMLText("dropfolder_folder"),
$this->getDropFolderChooserHtml("form1", "", 1) $this->getDropFolderChooserHtml("form1", "", 1, 1)
); );
$this->formField( $this->formField(
getMLText("dropfolder_metadata"), getMLText("dropfolder_metadata"),
$this->getDropFolderChooserHtml("form2", "", 0) $this->getDropFolderChooserHtml("form2", "", 0, 1)
); );
$this->formField( $this->formField(
getMLText("removeFolderFromDropFolder"), getMLText("removeFolderFromDropFolder"),

View File

@ -399,8 +399,10 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
if($this->params['dropfolderdir'] && $this->params['enabledropfolderlist']) { if($this->params['dropfolderdir'] && $this->params['enabledropfolderlist']) {
echo " <div id=\"menu-dropfolder\">"; echo " <div id=\"menu-dropfolder\">";
echo " <div class=\"ajax\" data-no-spinner=\"true\" data-view=\"DropFolderChooser\" data-action=\"menuList\""; echo " <div class=\"ajax\" data-no-spinner=\"true\" data-view=\"DropFolderChooser\" data-action=\"menuList\"";
$query = 'recursive=1';
if ($folder!=null && is_object($folder) && $folder->isType('folder')) if ($folder!=null && is_object($folder) && $folder->isType('folder'))
echo " data-query=\"folderid=".$folder->getID()."\""; $query .= "&folderid=".$folder->getID();
echo " data-query=\"".$query."\"";
echo "></div>"; echo "></div>";
echo " </div>"; echo " </div>";
} }
@ -2068,11 +2070,11 @@ $(document).ready(function() {
return $content; return $content;
} /* }}} */ } /* }}} */
function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */ function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
echo self::getDropFolderChooserHtml($formName, $dropfolderfile, $showfolders); echo self::getDropFolderChooserHtml($formName, $dropfolderfile, $showfolders, $recursive);
} /* }}} */ } /* }}} */
function getDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */ function getDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
$content = "<div class=\"input-group\">\n"; $content = "<div class=\"input-group\">\n";
$content .= "<input class=\"form-control fileupload-group\" readonly type=\"text\" id=\"dropfolderfile".$formName."\" name=\"dropfolderfile".$formName."\" value=\"".htmlspecialchars($dropfolderfile)."\">"; $content .= "<input class=\"form-control fileupload-group\" readonly type=\"text\" id=\"dropfolderfile".$formName."\" name=\"dropfolderfile".$formName."\" value=\"".htmlspecialchars($dropfolderfile)."\">";
$content .= '<div class="input-group-append">'; $content .= '<div class="input-group-append">';
@ -2080,7 +2082,7 @@ $(document).ready(function() {
$content .= $this->getModalBoxLink( $content .= $this->getModalBoxLink(
array( array(
'target' => 'dropfolderChooser', 'target' => 'dropfolderChooser',
'remote' => $this->params['settings']->_httpRoot."out/out.DropFolderChooser.php?form=".$formName."&dropfolderfile=".urlencode($dropfolderfile)."&showfolders=".$showfolders, 'remote' => $this->params['settings']->_httpRoot."out/out.DropFolderChooser.php?form=".$formName."&dropfolderfile=".urlencode($dropfolderfile)."&showfolders=".$showfolders."&recursive=".$recursive,
'class' => 'btn btn-secondary', 'class' => 'btn btn-secondary',
'title' => ($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file")).'…' 'title' => ($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file")).'…'
)); ));
@ -2121,8 +2123,8 @@ $(document).ready(function() {
<?php <?php
} /* }}} */ } /* }}} */
function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */ function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
$this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders); $this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders, $recursive);
?> ?>
<script language="JavaScript"> <script language="JavaScript">
<?php <?php