diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-04-18 10:19:50 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-04-18 10:24:14 +0200 |
commit | 8a7f2361d501683a88c5f687d15c4670da589a78 (patch) | |
tree | 4dce40b76c3661b9fd72854318febe991c3ec6bc /plugins | |
parent | d377a1518d43abb6a4bf8734d08aba258908b846 (diff) | |
download | nextcloud-server-8a7f2361d501683a88c5f687d15c4670da589a78.tar.gz nextcloud-server-8a7f2361d501683a88c5f687d15c4670da589a78.zip |
public link sharing also works for folders now
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/publiclink/get.php | 76 | ||||
-rw-r--r-- | plugins/publiclink/getfile.php | 11 | ||||
-rw-r--r-- | plugins/publiclink/lib_public.php | 23 | ||||
-rw-r--r-- | plugins/publiclink/templates/breadcrumb.php | 4 | ||||
-rw-r--r-- | plugins/publiclink/templates/files.php | 9 | ||||
-rw-r--r-- | plugins/publiclink/templates/index.php | 17 |
6 files changed, 110 insertions, 30 deletions
diff --git a/plugins/publiclink/get.php b/plugins/publiclink/get.php new file mode 100644 index 00000000000..cdfe42ef262 --- /dev/null +++ b/plugins/publiclink/get.php @@ -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(); +} +?>
\ No newline at end of file diff --git a/plugins/publiclink/getfile.php b/plugins/publiclink/getfile.php deleted file mode 100644 index 15a568df3dc..00000000000 --- a/plugins/publiclink/getfile.php +++ /dev/null @@ -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); -?>
\ No newline at end of file diff --git a/plugins/publiclink/lib_public.php b/plugins/publiclink/lib_public.php index 7c25c938fda..436dddeef22 100644 --- a/plugins/publiclink/lib_public.php +++ b/plugins/publiclink/lib_public.php @@ -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; } } diff --git a/plugins/publiclink/templates/breadcrumb.php b/plugins/publiclink/templates/breadcrumb.php new file mode 100644 index 00000000000..3f4ae863ee0 --- /dev/null +++ b/plugins/publiclink/templates/breadcrumb.php @@ -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; ?>
\ No newline at end of file diff --git a/plugins/publiclink/templates/files.php b/plugins/publiclink/templates/files.php new file mode 100644 index 00000000000..6473ad4c5c8 --- /dev/null +++ b/plugins/publiclink/templates/files.php @@ -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; ?>
\ No newline at end of file diff --git a/plugins/publiclink/templates/index.php b/plugins/publiclink/templates/index.php new file mode 100644 index 00000000000..9e238452603 --- /dev/null +++ b/plugins/publiclink/templates/index.php @@ -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>
\ No newline at end of file |