mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 07:22:11 +00:00
show files and folders in dropfolder dir recursively
This commit is contained in:
parent
ab82a65bcc
commit
40f2311b91
|
@ -7,6 +7,7 @@
|
|||
- do not show unreadable documents on Dashboard
|
||||
- fix creating preview image of file in drop folder if it contains
|
||||
special chars
|
||||
- show fileѕ and folders in dropfolder dir recursively
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Changes in version 5.1.32
|
||||
|
|
|
@ -44,6 +44,11 @@ if(isset($_GET['showfolders']) && $_GET['showfolders'])
|
|||
else
|
||||
$showfolders = false;
|
||||
|
||||
if(isset($_GET['recursive']) && $_GET['recursive'])
|
||||
$recursive = true;
|
||||
else
|
||||
$recursive = false;
|
||||
|
||||
if (isset($_GET["folderid"]) && is_numeric($_GET["folderid"])) {
|
||||
$folderid = intval($_GET["folderid"]);
|
||||
$folder = $dms->getFolder($folderid);
|
||||
|
@ -66,6 +71,7 @@ if($view) {
|
|||
$view->setParam('timeout', $settings->_cmdTimeout);
|
||||
$view->setParam('xsendfile', $settings->_enableXsendfile);
|
||||
$view->setParam('showfolders', $showfolders);
|
||||
$view->setParam('recursive', $recursive);
|
||||
$view->setParam('folder', $folder);
|
||||
$view($_GET);
|
||||
exit;
|
||||
|
|
|
@ -426,8 +426,10 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
|
|||
if($this->params['dropfolderdir'] && $this->params['enabledropfolderlist']) {
|
||||
echo " <div id=\"menu-dropfolder\">";
|
||||
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'))
|
||||
echo " data-query=\"folderid=".$folder->getID()."\"";
|
||||
$query .= "&folderid=".$folder->getID();
|
||||
echo " data-query=\"".$query."\"";
|
||||
echo "></div>";
|
||||
echo " </div>";
|
||||
}
|
||||
|
@ -2020,18 +2022,18 @@ $(document).ready(function() {
|
|||
return $content;
|
||||
} /* }}} */
|
||||
|
||||
function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */
|
||||
echo self::getDropFolderChooserHtml($formName, $dropfolderfile, $showfolders);
|
||||
function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
|
||||
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 .= "<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 .= $this->getModalBoxLink(
|
||||
array(
|
||||
'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")).'…'
|
||||
));
|
||||
$content .= "</div>\n";
|
||||
|
@ -2070,8 +2072,8 @@ $(document).ready(function() {
|
|||
<?php
|
||||
} /* }}} */
|
||||
|
||||
function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */
|
||||
$this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders);
|
||||
function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
|
||||
$this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders, $recursive);
|
||||
?>
|
||||
<script language="JavaScript">
|
||||
<?php
|
||||
|
|
|
@ -47,12 +47,43 @@ $('.folderselect').click(function(ev) {
|
|||
<?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() { /* {{{ */
|
||||
$dms = $this->params['dms'];
|
||||
$user = $this->params['user'];
|
||||
$settings = $this->params['settings'];
|
||||
$dropfolderdir = $this->params['dropfolderdir'];
|
||||
$showfolders = $this->params['showfolders'];
|
||||
$recursive = $this->params['recursive'];
|
||||
$cachedir = $this->params['cachedir'];
|
||||
$conversionmgr = $this->params['conversionmgr'];
|
||||
$previewwidth = $this->params['previewWidthMenuList'];
|
||||
|
@ -70,35 +101,31 @@ $('.folderselect').click(function(ev) {
|
|||
$c = 0; // count files
|
||||
$menuitems['dropfolder'] = array('label'=>'', 'children'=>array());
|
||||
$dir = rtrim($dropfolderdir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$user->getLogin();
|
||||
|
||||
/* Check if we are still looking in the configured directory and
|
||||
* not somewhere else, e.g. if the login was '../test'
|
||||
*/
|
||||
if(dirname($dir) == $dropfolderdir) {
|
||||
if(is_dir($dir)) {
|
||||
$d = dir($dir);
|
||||
$files = $this->getFiles($dir, $recursive);
|
||||
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
while (false !== ($entry = $d->read())) {
|
||||
if($entry != '..' && $entry != '.') {
|
||||
if($showfolders == 0 && !is_dir($dir.DIRECTORY_SEPARATOR.$entry) && is_readable($dir.DIRECTORY_SEPARATOR.$entry)) {
|
||||
$c++;
|
||||
$subitem = array('label'=>'', 'attributes'=>array(array('title', getMLText('menu_upload_from_dropfolder'))));
|
||||
if($folder)
|
||||
$subitem['link'] = $settings->_httpRoot.'out/out.AddDocument.php?folderid='.$folder->getId()."&dropfolderfileform1=".urldecode($entry);
|
||||
$mimetype = finfo_file($finfo, $dir.DIRECTORY_SEPARATOR.$entry);
|
||||
if($previewwidth) {
|
||||
$previewer->createRawPreview($dir.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR, $mimetype);
|
||||
if($previewer->hasRawPreview($dir.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-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;
|
||||
foreach($files as $file) {
|
||||
$entry = $file[1];
|
||||
$path = $file[0];
|
||||
$c++;
|
||||
$subitem = array('label'=>'', 'attributes'=>array(array('title', getMLText('menu_upload_from_dropfolder'))));
|
||||
if($folder)
|
||||
$subitem['link'] = $settings->_httpRoot.'out/out.AddDocument.php?folderid='.$folder->getId()."&dropfolderfileform1=".urldecode($path.DIRECTORY_SEPARATOR.$entry);
|
||||
$mimetype = finfo_file($finfo, $dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry);
|
||||
if($previewwidth) {
|
||||
$previewer->createRawPreview($dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry, 'dropfolder'.DIRECTORY_SEPARATOR, $mimetype);
|
||||
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($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($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'];
|
||||
$xsendfile = $this->params['xsendfile'];
|
||||
$showfolders = $this->params['showfolders'];
|
||||
$recursive = $this->params['recursive'];
|
||||
|
||||
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile);
|
||||
if($conversionmgr)
|
||||
|
@ -134,28 +162,33 @@ $('.folderselect').click(function(ev) {
|
|||
*/
|
||||
if(dirname($dir) == $dropfolderdir) {
|
||||
if(is_dir($dir)) {
|
||||
$d = dir($dir);
|
||||
echo "<table class=\"table table-condensed\">\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 "</thead>\n";
|
||||
echo "<tbody>\n";
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
while (false !== ($entry = $d->read())) {
|
||||
if($entry != '..' && $entry != '.') {
|
||||
if($showfolders == 0 && !is_dir($dir.'/'.$entry)) {
|
||||
$mimetype = finfo_file($finfo, $dir.'/'.$entry);
|
||||
$previewer->createRawPreview($dir.'/'.$entry, 'dropfolder/', $mimetype);
|
||||
echo "<tr><td style=\"min-width: ".$previewwidth."px;\">";
|
||||
if($previewer->hasRawPreview($dir.'/'.$entry, 'dropfolder/')) {
|
||||
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)."\">";
|
||||
}
|
||||
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";
|
||||
} elseif($showfolders && is_dir($dir.'/'.$entry)) {
|
||||
echo "<tr>";
|
||||
echo "<td></td>";
|
||||
echo "<td><span style=\"cursor: pointer;\" class=\"folderselect\" data-foldername=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\"></td><td></td>";
|
||||
echo "</tr>\n";
|
||||
if($showfolders) {
|
||||
$folders = $this->getFolders($dir, $recursive);
|
||||
foreach($folders as $entry) {
|
||||
echo "<tr>";
|
||||
echo '<td><img draggable="false" src="/views/bootstrap4/images/folder.svg" width="24" height="24" border="0"></td>';
|
||||
echo "<td><span style=\"cursor: pointer;\" class=\"folderselect\" data-foldername=\"".$entry."\" data-form=\"".$form."\">".$entry."</span></td><td align=\"right\"></td><td></td>";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
} else {
|
||||
$files = $this->getFiles($dir, $recursive);
|
||||
foreach($files as $file) {
|
||||
$entry = $file[1];
|
||||
$path = $file[0];
|
||||
$mimetype = finfo_file($finfo, $dir.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$entry);
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("dropfolder_folder"),
|
||||
$this->getDropFolderChooserHtml("form1", "", 1)
|
||||
$this->getDropFolderChooserHtml("form1", "", 1, 1)
|
||||
);
|
||||
$this->formField(
|
||||
getMLText("dropfolder_metadata"),
|
||||
$this->getDropFolderChooserHtml("form2", "", 0)
|
||||
$this->getDropFolderChooserHtml("form2", "", 0, 1)
|
||||
);
|
||||
$this->formField(
|
||||
getMLText("removeFolderFromDropFolder"),
|
||||
|
|
|
@ -399,8 +399,10 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
|
|||
if($this->params['dropfolderdir'] && $this->params['enabledropfolderlist']) {
|
||||
echo " <div id=\"menu-dropfolder\">";
|
||||
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'))
|
||||
echo " data-query=\"folderid=".$folder->getID()."\"";
|
||||
$query .= "&folderid=".$folder->getID();
|
||||
echo " data-query=\"".$query."\"";
|
||||
echo "></div>";
|
||||
echo " </div>";
|
||||
}
|
||||
|
@ -2068,11 +2070,11 @@ $(document).ready(function() {
|
|||
return $content;
|
||||
} /* }}} */
|
||||
|
||||
function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */
|
||||
echo self::getDropFolderChooserHtml($formName, $dropfolderfile, $showfolders);
|
||||
function printDropFolderChooserHtml($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
|
||||
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 .= "<input class=\"form-control fileupload-group\" readonly type=\"text\" id=\"dropfolderfile".$formName."\" name=\"dropfolderfile".$formName."\" value=\"".htmlspecialchars($dropfolderfile)."\">";
|
||||
$content .= '<div class="input-group-append">';
|
||||
|
@ -2080,7 +2082,7 @@ $(document).ready(function() {
|
|||
$content .= $this->getModalBoxLink(
|
||||
array(
|
||||
'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',
|
||||
'title' => ($showfolders ? getMLText("choose_target_folder"): getMLText("choose_target_file")).'…'
|
||||
));
|
||||
|
@ -2121,8 +2123,8 @@ $(document).ready(function() {
|
|||
<?php
|
||||
} /* }}} */
|
||||
|
||||
function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0) { /* {{{ */
|
||||
$this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders);
|
||||
function printDropFolderChooser($formName, $dropfolderfile="", $showfolders=0, $recursive=1) { /* {{{ */
|
||||
$this->printDropFolderChooserHtml($formName, $dropfolderfile, $showfolders, $recursive);
|
||||
?>
|
||||
<script language="JavaScript">
|
||||
<?php
|
||||
|
|
Loading…
Reference in New Issue
Block a user