2011-08-18 19:35:11 +00:00
|
|
|
<?php
|
2012-05-13 22:28:22 +00:00
|
|
|
// only need authentication apps
|
|
|
|
$RUNTIME_APPTYPES=array('authentication');
|
|
|
|
OC_App::loadApps($RUNTIME_APPTYPES);
|
|
|
|
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::checkAppEnabled('files_sharing');
|
2011-08-18 19:35:11 +00:00
|
|
|
require_once 'lib_share.php';
|
|
|
|
|
|
|
|
//get the path of the shared file
|
2012-05-07 14:47:28 +00:00
|
|
|
if (isset($_GET['token']) && $source = OC_Share::getSource($_GET['token'])) {
|
2012-05-07 16:36:29 +00:00
|
|
|
$token = $_GET['token'];
|
2011-08-18 19:35:11 +00:00
|
|
|
// TODO Manipulating the string may not be the best choice. Is there an alternative?
|
|
|
|
$user = substr($source, 1, strpos($source, "/", 1) - 1);
|
|
|
|
OC_Util::setupFS($user);
|
|
|
|
$source = substr($source, strlen("/".$user."/files"));
|
2011-08-18 23:32:24 +00:00
|
|
|
$subPath = isset( $_GET['path'] ) ? $_GET['path'] : '';
|
2011-08-18 19:35:11 +00:00
|
|
|
$root = $source;
|
2011-08-18 23:32:24 +00:00
|
|
|
$source .= $subPath;
|
2011-08-18 19:35:11 +00:00
|
|
|
if (!OC_Filesystem::file_exists($source)) {
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
2012-05-06 21:00:36 +00:00
|
|
|
$tmpl = new OCP\Template("", "404", "guest");
|
2011-08-18 23:32:24 +00:00
|
|
|
$tmpl->assign("file", $subPath);
|
2011-08-18 19:35:11 +00:00
|
|
|
$tmpl->printPage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if (OC_Filesystem::is_dir($source)) {
|
|
|
|
$files = array();
|
|
|
|
$rootLength = strlen($root);
|
|
|
|
foreach (OC_Files::getdirectorycontent($source) as $i) {
|
2012-05-01 19:07:08 +00:00
|
|
|
$i['date'] = OCP\Util::formatDate($i['mtime'] );
|
2011-08-18 19:35:11 +00:00
|
|
|
if ($i['type'] == 'file') {
|
2011-10-05 10:27:50 +00:00
|
|
|
$fileinfo = pathinfo($i['name']);
|
|
|
|
$i['basename'] = $fileinfo['filename'];
|
2012-04-15 11:32:45 +00:00
|
|
|
$i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
|
2011-08-18 19:35:11 +00:00
|
|
|
}
|
|
|
|
$i['directory'] = substr($i['directory'], $rootLength);
|
|
|
|
if ($i['directory'] == "/") {
|
|
|
|
$i['directory'] = "";
|
|
|
|
}
|
|
|
|
$files[] = $i;
|
|
|
|
}
|
|
|
|
// Make breadcrumb
|
|
|
|
$breadcrumb = array();
|
2011-08-18 23:44:00 +00:00
|
|
|
$pathtohere = "";
|
2011-08-18 23:32:24 +00:00
|
|
|
foreach (explode("/", $subPath) as $i) {
|
2011-08-18 19:35:11 +00:00
|
|
|
if ($i != "") {
|
2011-08-18 23:44:00 +00:00
|
|
|
$pathtohere .= "/$i";
|
2011-08-18 19:35:11 +00:00
|
|
|
$breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Load the files we need
|
2012-05-01 07:49:22 +00:00
|
|
|
OCP\Util::addStyle("files", "files");
|
2012-05-06 21:00:36 +00:00
|
|
|
$breadcrumbNav = new OCP\Template("files", "part.breadcrumb", "");
|
2011-08-18 19:35:11 +00:00
|
|
|
$breadcrumbNav->assign("breadcrumb", $breadcrumb);
|
2012-05-17 20:12:33 +00:00
|
|
|
$breadcrumbNav->assign("baseURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
|
2012-05-06 21:00:36 +00:00
|
|
|
$list = new OCP\Template("files", "part.list", "");
|
2011-08-18 19:35:11 +00:00
|
|
|
$list->assign("files", $files);
|
2012-05-17 20:12:33 +00:00
|
|
|
$list->assign("baseURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
|
|
|
|
$list->assign("downloadURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
|
2011-09-23 07:46:13 +00:00
|
|
|
$list->assign("readonly", true);
|
2012-05-06 21:00:36 +00:00
|
|
|
$tmpl = new OCP\Template("files", "index", "user");
|
2012-06-18 20:48:52 +00:00
|
|
|
$tmpl->assign("fileList", $list->fetchPage(), false);
|
2011-08-18 19:35:11 +00:00
|
|
|
$tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
|
2011-09-23 07:46:13 +00:00
|
|
|
$tmpl->assign("readonly", true);
|
2012-04-14 09:33:27 +00:00
|
|
|
$tmpl->assign("allowZipDownload", false);
|
|
|
|
$tmpl->assign("dir", 'shared dir');
|
2011-08-18 19:35:11 +00:00
|
|
|
$tmpl->printPage();
|
|
|
|
} else {
|
|
|
|
//get time mimetype and set the headers
|
|
|
|
$mimetype = OC_Filesystem::getMimeType($source);
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
2012-05-03 08:46:27 +00:00
|
|
|
OCP\Response::disableCaching();
|
2012-05-08 14:27:02 +00:00
|
|
|
header('Content-Disposition: attachment; filename="'.basename($source).'"');
|
2011-08-18 19:35:11 +00:00
|
|
|
header("Content-Type: " . $mimetype);
|
|
|
|
header("Content-Length: " . OC_Filesystem::filesize($source));
|
|
|
|
//download the file
|
|
|
|
@ob_clean();
|
2012-06-21 16:25:45 +00:00
|
|
|
OCP\Util::emitHook('OC_Share', 'public-download', array('source'=>$source, 'token'=>$token));
|
2011-08-18 19:35:11 +00:00
|
|
|
OC_Filesystem::readfile($source);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
2012-05-06 21:00:36 +00:00
|
|
|
$tmpl = new OCP\Template("", "404", "guest");
|
2011-08-18 19:35:11 +00:00
|
|
|
$tmpl->printPage();
|
|
|
|
die();
|
|
|
|
}
|