summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/index.php
blob: 0baeab1de9734ad9e821ecfb6333e6573f534793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php

// Check if we are a user
OCP\User::checkLoggedIn();

OCP\App::setActiveNavigationEntry('files_index');

OCP\Util::addScript('files_trashbin', 'trash');
OCP\Util::addScript('files_trashbin', 'disableDefaultActions');
OCP\Util::addScript('files', 'fileactions');
$tmpl = new OCP\Template('files_trashbin', 'index', 'user');

$user = \OCP\User::getUser();
$view = new OC_Filesystemview('/'.$user.'/files_trashbin/files');

OCP\Util::addStyle('files', 'files');
OCP\Util::addScript('files', 'filelist');

$dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';

$result = array();
if ($dir) {
	$dirlisting = true;
	$dirContent = $view->opendir($dir);
	$i = 0;
	while(($entryName = readdir($dirContent)) !== false) {
		if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
			$pos = strpos($dir.'/', '/', 1);
			$tmp = substr($dir, 0, $pos);
			$pos = strrpos($tmp, '.d');
			$timestamp = substr($tmp, $pos+2);
			$result[] = array(
					'id' => $entryName,
					'timestamp' => $timestamp,
					'mime' =>  $view->getMimeType($dir.'/'.$entryName),
					'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file',
					'location' => $dir,
					);
		}
	}
	closedir($dirContent);

} 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();
}

$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;
	$i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($r['mime']);
	$files[] = $i;
}

function fileCmp($a, $b) {
	if ($a['type'] === 'dir' and $b['type'] !== 'dir') {
		return -1;
	} elseif ($a['type'] !== 'dir' and $b['type'] === 'dir') {
		return 1;
	} else {
		return strnatcasecmp($a['name'], $b['name']);
	}
}

usort($files, "fileCmp");

// Make breadcrumb
$pathtohere = '';
$breadcrumb = array();
foreach (explode('/', $dir) as $i) {
	if ($i !== '') {
		if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) {
			$name = $match[1];
		} else {
			$name = $i;
		}
		$pathtohere .= '/' . $i;
		$breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);
	}
}

$breadcrumbNav = new OCP\Template('files_trashbin', 'part.breadcrumb', '');
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=');
$breadcrumbNav->assign('home', OCP\Util::linkTo('files', 'index.php'));

$list = new OCP\Template('files_trashbin', 'part.list', '');
$list->assign('files', $files);

$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);
$list->assign('disableSharing', true);
$list->assign('dirlisting', $dirlisting);
$list->assign('disableDownloadActions', true);

$tmpl->assign('dirlisting', $dirlisting);
$tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
$tmpl->assign('fileList', $list->fetchPage());
$tmpl->assign('files', $files);
$tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($view->getAbsolutePath()));

$tmpl->printPage();