public link sharing also works for folders now

This commit is contained in:
Robin Appelman 2011-04-18 10:19:50 +02:00
parent d377a1518d
commit 8a7f2361d5
6 changed files with 110 additions and 30 deletions

View File

@ -0,0 +1,76 @@
<?php
$RUNTIME_NOAPPS=true; //no need to load the apps
$RUNTIME_NOSETUPFS=true; //don't setup the fs yet
require_once '../../lib/base.php';
require( 'template.php' );
require_once 'lib_public.php';
//get the path of the shared file
$token=$_GET['token'];
$path=OC_PublicLink::getPath($token);
$root=$path;
if($path!==false){
if(isset($_GET['path']) and !strstr($_GET['path'],'..')){
$subPath=$_GET['path'];
}else{
$subPath='';
}
$path.=$subPath;
if(OC_FILESYSTEM::is_dir($path)){
$files = array();
$rootLength=strlen($root);
foreach( OC_FILES::getdirectorycontent( $path ) as $i ){
$i['date'] = OC_UTIL::formatDate($i['mtime'] );
$i['directory']=substr($i['directory'],$rootLength);
if($i['directory']=='/'){
$i['directory']='';
}
$files[] = $i;
}
// Make breadcrumb
$breadcrumb = array();
$pathtohere = "/";
foreach( explode( "/", $subPath ) as $i ){
if( $i != "" ){
$pathtohere .= "$i/";
$breadcrumb[] = array( "dir" => $pathtohere, "name" => $i );
}
}
$breadcrumbNav = new OC_TEMPLATE( "plugins/publiclink", "breadcrumb", "" );
$breadcrumbNav->assign( "breadcrumb", $breadcrumb );
$breadcrumbNav->assign('token',$token);
$list = new OC_TEMPLATE( 'plugins/publiclink', 'files', '' );
$list->assign( 'files', $files );
$list->assign('token',$token);
$tmpl = new OC_TEMPLATE( 'plugins/publiclink', 'index', 'user' );
$tmpl->assign('fileList', $list->fetchPage());
$tmpl->assign( "breadcrumb", $breadcrumbNav->fetchPage() );
$tmpl->printPage();
}else{
//get time mimetype and set the headers
$mimetype=OC_FILESYSTEM::getMimeType($path);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . OC_FILESYSTEM::filesize($path));
//download the file
ob_clean();
OC_FILESYSTEM::readfile($path);
}
}else{
header("HTTP/1.0 404 Not Found");
echo '404 Not Found';
die();
}
?>

View File

@ -1,11 +0,0 @@
<?php
$RUNTIME_NOAPPS=true; //no need to load the apps
$RUNTIME_NOSETUPFS=true; //don't setup the fs yet
require_once '../../lib/base.php';
require_once 'lib_public.php';
$token=$_GET['token'];
OC_PublicLink::downloadFile($token);
?>

View File

@ -22,10 +22,9 @@ class OC_PublicLink{
}
/**
* download a file shared by a public link
* @param string token
* get the path of that shared file
*/
public static function downloadFile($token){
public static function getPath($token){
//remove expired links
$query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE expire_time < NOW() AND expire_time!=0");
$query->execute();
@ -41,23 +40,9 @@ class OC_PublicLink{
//prepare the filesystem
OC_UTIL::setupFS($user);
//get time mimetype and set the headers
$mimetype=OC_FILESYSTEM::getMimeType($path);
// header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . OC_FILESYSTEM::filesize($path));
//download the file
ob_clean();
OC_FILESYSTEM::readfile($path);
return $path;
}else{
header("HTTP/1.0 404 Not Found");
echo '404 Not Found';
die();
return false;
}
}

View File

@ -0,0 +1,4 @@
<a href="<?php echo link_to("plugins/publiclink", "get.php?token=".$_['token']); ?>"><img src="<?php echo image_path("", "actions/go-home.png"); ?>" alt="Root" /></a>
<?php foreach($_["breadcrumb"] as $crumb): ?>
<a href="<?php echo link_to("plugins/publiclink", "get.php?token=".$_['token']."&path=".$crumb["dir"]); ?>"><?php echo htmlspecialchars($crumb["name"]); ?></a>
<?php endforeach; ?>

View File

@ -0,0 +1,9 @@
<?php foreach($_["files"] as $file): ?>
<tr>
<td class="selection"><input type="checkbox" /></td>
<td class="filename"><a style="background-image:url(<?php if($file["type"] == "dir") echo mimetype_icon("dir"); else echo mimetype_icon($file["mime"]); ?>)" href="<?php if($file["type"] == "dir") echo link_to("plugins/publiclink", "get.php?token=".$_['token']."&path=".$file["directory"]."/".$file["name"]); else echo link_to("plugins/publiclink", "get.php?token=".$_['token']."&path=".$file["directory"]."/".$file["name"]); ?>" title=""><?php echo htmlspecialchars($file["name"]); ?></a></td>
<td class="filesize"><?php echo human_file_size($file["size"]); ?></td>
<td class="date"><?php if($file["type"] != "dir") echo $file["date"]; ?></td>
<td class="fileaction"><a href="" title=""><img src="images/drop-arrow.png" alt="+" /></a></td>
</tr>
<?php endforeach; ?>

View File

@ -0,0 +1,17 @@
<p class="nav">
<?php echo($_['breadcrumb']); ?>
</p>
<table cellspacing="0">
<thead>
<tr>
<th><input type="checkbox" id="select_all" /></th>
<th>Name</th>
<th>Size</th>
<th>Modified</th>
<th></th>
</tr>
</thead>
<tbody id="fileList">
<?php echo($_['fileList']); ?>
</tbody>
</table>