2013-08-17 11:07:18 +00:00
|
|
|
<?php
|
|
|
|
|
2013-09-20 14:37:07 +00:00
|
|
|
namespace OCA\Files_Trashbin;
|
2013-08-17 11:07:18 +00:00
|
|
|
|
|
|
|
class Helper
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Retrieves the contents of a trash bin directory.
|
|
|
|
* @param string $dir path to the directory inside the trashbin
|
|
|
|
* or empty to retrieve the root of the trashbin
|
|
|
|
* @return array of files
|
|
|
|
*/
|
|
|
|
public static function getTrashFiles($dir){
|
|
|
|
$result = array();
|
2014-02-25 19:46:41 +00:00
|
|
|
$timestamp = null;
|
2013-08-17 11:07:18 +00:00
|
|
|
$user = \OCP\User::getUser();
|
|
|
|
|
2014-02-25 19:46:41 +00:00
|
|
|
$view = new \OC_Filesystemview('/' . $user . '/files_trashbin/files');
|
|
|
|
|
|
|
|
if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
|
|
|
|
throw new \Exception('Directory does not exists');
|
|
|
|
}
|
|
|
|
|
|
|
|
$dirContent = $view->opendir($dir);
|
|
|
|
if ($dirContent === false) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
if (is_resource($dirContent)) {
|
|
|
|
while (($entryName = readdir($dirContent)) !== false) {
|
|
|
|
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
|
|
|
|
$id = $entryName;
|
|
|
|
if ($dir === '' || $dir === '/') {
|
|
|
|
$pathparts = pathinfo($entryName);
|
|
|
|
$timestamp = substr($pathparts['extension'], 1);
|
|
|
|
$id = $pathparts['filename'];
|
|
|
|
} else if ($timestamp === null) {
|
|
|
|
// for subfolders we need to calculate the timestamp only once
|
|
|
|
$parts = explode('/', ltrim($dir, '/'));
|
|
|
|
$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|
2014-02-25 19:46:41 +00:00
|
|
|
$result[] = array(
|
|
|
|
'id' => $id,
|
|
|
|
'timestamp' => $timestamp,
|
|
|
|
'mime' => $view->getMimeType($dir . '/' . $entryName),
|
|
|
|
'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file',
|
|
|
|
'location' => $dir,
|
|
|
|
);
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-25 19:46:41 +00:00
|
|
|
closedir($dirContent);
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$files = array();
|
2013-12-02 14:27:40 +00:00
|
|
|
$id = 0;
|
2013-08-17 11:07:18 +00:00
|
|
|
foreach ($result as $r) {
|
|
|
|
$i = array();
|
2013-12-02 14:27:40 +00:00
|
|
|
$i['id'] = $id++;
|
2013-08-17 11:07:18 +00:00
|
|
|
$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;
|
2014-02-25 20:28:39 +00:00
|
|
|
if (\OCP\App::isEnabled('files_encryption')) {
|
|
|
|
$i['isPreviewAvailable'] = false;
|
|
|
|
} else {
|
|
|
|
$i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']);
|
|
|
|
}
|
2013-09-20 14:46:33 +00:00
|
|
|
$i['icon'] = \OCA\Files\Helper::determineIcon($i);
|
2013-08-17 11:07:18 +00:00
|
|
|
$files[] = $i;
|
|
|
|
}
|
|
|
|
|
2013-09-20 14:46:33 +00:00
|
|
|
usort($files, array('\OCA\Files\Helper', 'fileCmp'));
|
2013-08-17 11:07:18 +00:00
|
|
|
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Splits the given path into a breadcrumb structure.
|
|
|
|
* @param string $dir path to process
|
|
|
|
* @return array where each entry is a hash of the absolute
|
|
|
|
* directory path and its name
|
|
|
|
*/
|
|
|
|
public static function makeBreadcrumb($dir){
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $breadcrumb;
|
|
|
|
}
|
|
|
|
}
|