server/apps/files_trashbin/index.php

102 lines
3.2 KiB
PHP
Raw Normal View History

2013-01-18 12:11:29 +00:00
<?php
2013-02-22 16:21:57 +00:00
// Check if we are a user
2013-01-18 12:11:29 +00:00
OCP\User::checkLoggedIn();
OCP\Util::addScript('files_trashbin', 'trash');
2013-01-23 10:30:42 +00:00
OCP\Util::addScript('files_trashbin', 'disableDefaultActions');
2013-01-18 12:11:29 +00:00
OCP\Util::addScript('files', 'fileactions');
$tmpl = new OCP\Template('files_trashbin', 'index', 'user');
$user = \OCP\User::getUser();
2013-02-20 21:19:23 +00:00
$view = new OC_Filesystemview('/'.$user.'/files_trashbin/files');
2013-01-18 12:11:29 +00:00
OCP\Util::addStyle('files', 'files');
OCP\Util::addScript('files', 'filelist');
2013-01-21 12:07:43 +00:00
$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
2013-02-19 11:24:51 +00:00
$result = array();
2013-01-21 12:07:43 +00:00
if ($dir) {
$dirlisting = true;
$fullpath = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($dir);
$dirContent = opendir($fullpath);
$i = 0;
while($entryName = readdir($dirContent)) {
if ( $entryName != '.' && $entryName != '..' ) {
$pos = strpos($dir.'/', '/', 1);
$tmp = substr($dir, 0, $pos);
$pos = strrpos($tmp, '.d');
$timestamp = substr($tmp, $pos+2);
2013-01-21 12:07:43 +00: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 16:21:57 +00:00
}
2013-01-21 12:07:43 +00:00
}
2013-02-18 17:16:19 +00:00
closedir($dirContent);
2013-02-22 16:21:57 +00:00
2013-01-21 12:07:43 +00:00
} else {
$dirlisting = false;
$query = \OC_DB::prepare('SELECT id,location,timestamp,type,mime FROM *PREFIX*files_trash WHERE user=?');
$result = $query->execute(array($user))->fetchAll();
}
2013-01-18 12:11:29 +00: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'];
if ($i['type'] == 'file') {
$fileinfo = pathinfo($r['id']);
$i['basename'] = $fileinfo['filename'];
$i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
}
$i['directory'] = $r['location'];
if ($i['directory'] == '/') {
$i['directory'] = '';
}
$i['permissions'] = OCP\PERMISSION_READ;
$files[] = $i;
}
2013-02-22 16:21:57 +00:00
// Make breadcrumb
2013-02-09 11:41:47 +00:00
$pathtohere = '';
2013-02-22 16:21:57 +00:00
$breadcrumb = array();
foreach (explode('/', $dir) as $i) {
if ($i != '') {
if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) {
$name = $match[1];
} else {
$name = $i;
2013-02-22 16:21:57 +00:00
}
$pathtohere .= '/' . $i;
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);
}
2013-01-21 12:07:43 +00:00
}
2013-02-22 16:21:57 +00:00
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
2013-01-18 12:11:29 +00:00
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=', false);
$list = new OCP\Template('files_trashbin', 'part.list', '');
$list->assign('files', $files, false);
2013-02-22 16:21:57 +00:00
$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false);
2013-01-21 12:07:43 +00:00
$list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$dir, false);
2013-01-18 12:11:29 +00:00
$list->assign('disableSharing', true);
2013-01-21 12:07:43 +00:00
$list->assign('dirlisting', $dirlisting);
2013-01-18 12:11:29 +00:00
$list->assign('disableDownloadActions', true);
$tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
$tmpl->assign('fileList', $list->fetchPage(), false);
$tmpl->assign('files', $files);
$tmpl->assign('dirlisting', $dirlisting);
2013-01-18 12:11:29 +00:00
$tmpl->assign('dir', OC_Filesystem::normalizePath($view->getAbsolutePath()));
$tmpl->printPage();