nextcloud/apps/files_trashbin/index.php

119 lines
3.5 KiB
PHP
Raw Normal View History

2013-01-18 16:11:29 +04:00
<?php
2013-02-22 20:21:57 +04:00
// Check if we are a user
2013-01-18 16:11:29 +04:00
OCP\User::checkLoggedIn();
OCP\App::setActiveNavigationEntry('files_index');
2013-01-18 16:11:29 +04:00
OCP\Util::addScript('files_trashbin', 'trash');
2013-01-23 14:30:42 +04:00
OCP\Util::addScript('files_trashbin', 'disableDefaultActions');
2013-01-18 16:11:29 +04:00
OCP\Util::addScript('files', 'fileactions');
$tmpl = new OCP\Template('files_trashbin', 'index', 'user');
$user = \OCP\User::getUser();
2013-02-21 01:19:23 +04:00
$view = new OC_Filesystemview('/'.$user.'/files_trashbin/files');
2013-01-18 16:11:29 +04:00
OCP\Util::addStyle('files', 'files');
OCP\Util::addScript('files', 'filelist');
2013-01-21 16:07:43 +04:00
$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
2013-02-19 15:24:51 +04:00
$result = array();
2013-01-21 16:07:43 +04:00
if ($dir) {
$dirlisting = true;
2013-05-06 15:28:01 +04:00
$dirContent = $view->opendir($dir);
2013-01-21 16:07:43 +04:00
$i = 0;
while($entryName = readdir($dirContent)) {
2013-07-10 04:36:43 +04:00
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
2013-01-21 16:07:43 +04:00
$pos = strpos($dir.'/', '/', 1);
$tmp = substr($dir, 0, $pos);
$pos = strrpos($tmp, '.d');
$timestamp = substr($tmp, $pos+2);
2013-01-21 16:07:43 +04:00
$result[] = array(
'id' => $entryName,
'timestamp' => $timestamp,
'mime' => $view->getMimeType($dir.'/'.$entryName),
'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file',
'location' => $dir,
);
2013-02-22 20:21:57 +04:00
}
2013-01-21 16:07:43 +04:00
}
2013-02-18 21:16:19 +04:00
closedir($dirContent);
2013-02-22 20:21:57 +04:00
2013-01-21 16:07:43 +04:00
} else {
$dirlisting = false;
$query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?');
2013-01-21 16:07:43 +04:00
$result = $query->execute(array($user))->fetchAll();
}
2013-01-18 16:11:29 +04:00
$files = array();
foreach ($result as $r) {
$i = array();
$i['name'] = $r['id'];
$i['date'] = OCP\Util::formatDate($r['timestamp']);
$i['timestamp'] = $r['timestamp'];
$i['mimetype'] = $r['mime'];
$i['type'] = $r['type'];
2013-04-18 20:28:03 +04:00
if ($i['type'] === 'file') {
2013-01-18 16:11:29 +04:00
$fileinfo = pathinfo($r['id']);
$i['basename'] = $fileinfo['filename'];
$i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
}
$i['directory'] = $r['location'];
2013-04-18 20:28:03 +04:00
if ($i['directory'] === '/') {
2013-01-18 16:11:29 +04:00
$i['directory'] = '';
}
$i['permissions'] = OCP\PERMISSION_READ;
$files[] = $i;
}
function fileCmp($a, $b) {
2013-04-18 20:28:03 +04:00
if ($a['type'] === 'dir' and $b['type'] !== 'dir') {
return -1;
2013-04-18 20:28:03 +04:00
} elseif ($a['type'] !== 'dir' and $b['type'] === 'dir') {
return 1;
} else {
return strnatcasecmp($a['name'], $b['name']);
}
}
usort($files, "fileCmp");
2013-02-22 20:21:57 +04:00
// Make breadcrumb
2013-02-09 15:41:47 +04:00
$pathtohere = '';
2013-02-22 20:21:57 +04:00
$breadcrumb = array();
foreach (explode('/', $dir) as $i) {
2013-04-18 20:28:03 +04:00
if ($i !== '') {
if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) {
$name = $match[1];
} else {
$name = $i;
2013-02-22 20:21:57 +04:00
}
$pathtohere .= '/' . $i;
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);
}
2013-01-21 16:07:43 +04:00
}
$breadcrumbNav = new OCP\Template('files_trashbin', 'part.breadcrumb', '');
2013-02-28 00:46:37 +04:00
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=');
2013-03-07 16:51:18 +04:00
$breadcrumbNav->assign('home', OCP\Util::linkTo('files', 'index.php'));
2013-01-18 16:11:29 +04:00
$list = new OCP\Template('files_trashbin', 'part.list', '');
2013-02-28 00:46:37 +04:00
$list->assign('files', $files);
2013-07-04 20:41:42 +04:00
$encodedDir = \OCP\Util::encodePath($dir);
$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$encodedDir);
$list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$encodedDir);
2013-01-18 16:11:29 +04:00
$list->assign('disableSharing', true);
2013-03-07 17:54:59 +04:00
$list->assign('dirlisting', $dirlisting);
2013-01-18 16:11:29 +04:00
$list->assign('disableDownloadActions', true);
2013-07-04 20:41:42 +04:00
$tmpl->assign('dirlisting', $dirlisting);
2013-02-28 00:46:37 +04:00
$tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
$tmpl->assign('fileList', $list->fetchPage());
$tmpl->assign('files', $files);
$tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($view->getAbsolutePath()));
2013-01-18 16:11:29 +04:00
$tmpl->printPage();