2011-08-18 23:35:11 +04:00
|
|
|
<?php
|
|
|
|
$RUNTIME_NOAPPS=true; //no need to load the apps
|
|
|
|
$RUNTIME_NOSETUPFS=true; //don't setup the fs yet
|
|
|
|
|
|
|
|
require_once '../../lib/base.php';
|
2011-10-01 01:05:10 +04:00
|
|
|
OC_JSON::checkAppEnabled('files_sharing');
|
2011-08-18 23:35:11 +04:00
|
|
|
require_once 'lib_share.php';
|
|
|
|
|
|
|
|
//get the path of the shared file
|
|
|
|
$token = $_GET['token'];
|
|
|
|
$source = OC_Share::getSource($token);
|
|
|
|
if ($source !== false) {
|
|
|
|
// 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-19 03:32:24 +04:00
|
|
|
$subPath = isset( $_GET['path'] ) ? $_GET['path'] : '';
|
2011-08-18 23:35:11 +04:00
|
|
|
$root = $source;
|
2011-08-19 03:32:24 +04:00
|
|
|
$source .= $subPath;
|
2011-08-18 23:35:11 +04:00
|
|
|
if (!OC_Filesystem::file_exists($source)) {
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
$tmpl = new OC_Template("", "404", "guest");
|
2011-08-19 03:32:24 +04:00
|
|
|
$tmpl->assign("file", $subPath);
|
2011-08-18 23:35:11 +04:00
|
|
|
$tmpl->printPage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if (OC_Filesystem::is_dir($source)) {
|
|
|
|
$files = array();
|
|
|
|
$rootLength = strlen($root);
|
|
|
|
foreach (OC_Files::getdirectorycontent($source) as $i) {
|
|
|
|
$i['date'] = OC_Util::formatDate($i['mtime'] );
|
|
|
|
if ($i['type'] == 'file') {
|
|
|
|
$i['extention'] = substr($i['name'], strrpos($i['name'], "."));
|
|
|
|
$i['basename'] = substr($i['name'], 0, strrpos($i['name'], "."));
|
|
|
|
}
|
|
|
|
$i['directory'] = substr($i['directory'], $rootLength);
|
|
|
|
if ($i['directory'] == "/") {
|
|
|
|
$i['directory'] = "";
|
|
|
|
}
|
|
|
|
$files[] = $i;
|
|
|
|
}
|
|
|
|
// Make breadcrumb
|
|
|
|
$breadcrumb = array();
|
2011-08-19 03:44:00 +04:00
|
|
|
$pathtohere = "";
|
2011-08-19 03:32:24 +04:00
|
|
|
foreach (explode("/", $subPath) as $i) {
|
2011-08-18 23:35:11 +04:00
|
|
|
if ($i != "") {
|
2011-08-19 03:44:00 +04:00
|
|
|
$pathtohere .= "/$i";
|
2011-08-18 23:35:11 +04:00
|
|
|
$breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Load the files we need
|
|
|
|
OC_Util::addStyle("files", "files");
|
|
|
|
$breadcrumbNav = new OC_Template("files", "part.breadcrumb", "");
|
|
|
|
$breadcrumbNav->assign("breadcrumb", $breadcrumb);
|
2011-08-19 03:32:24 +04:00
|
|
|
$breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&path=");
|
2011-08-18 23:35:11 +04:00
|
|
|
$list = new OC_Template("files", "part.list", "");
|
|
|
|
$list->assign("files", $files);
|
2011-08-19 03:32:24 +04:00
|
|
|
$list->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&path=");
|
|
|
|
$list->assign("downloadURL", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&path=");
|
2011-09-23 11:46:13 +04:00
|
|
|
$list->assign("readonly", true);
|
2011-08-18 23:35:11 +04:00
|
|
|
$tmpl = new OC_Template("files", "index", "user");
|
|
|
|
$tmpl->assign("fileList", $list->fetchPage());
|
|
|
|
$tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
|
2011-09-23 11:46:13 +04:00
|
|
|
$tmpl->assign("readonly", true);
|
2011-08-18 23:35:11 +04:00
|
|
|
$tmpl->printPage();
|
|
|
|
} else {
|
|
|
|
//get time mimetype and set the headers
|
|
|
|
$mimetype = OC_Filesystem::getMimeType($source);
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Expires: 0");
|
|
|
|
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
|
|
|
header("Pragma: public");
|
2011-08-20 07:58:37 +04:00
|
|
|
header("Content-Disposition: filename=".basename($source));
|
2011-08-18 23:35:11 +04:00
|
|
|
header("Content-Type: " . $mimetype);
|
|
|
|
header("Content-Length: " . OC_Filesystem::filesize($source));
|
|
|
|
//download the file
|
|
|
|
@ob_clean();
|
|
|
|
OC_Filesystem::readfile($source);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
$tmpl = new OC_Template("", "404", "guest");
|
|
|
|
$tmpl->printPage();
|
|
|
|
die();
|
|
|
|
}
|
2011-08-20 07:58:37 +04:00
|
|
|
?>
|