]> source.dussan.org Git - nextcloud-server.git/commitdiff
public link sharing also works for folders now
authorRobin Appelman <icewind1991@gmail.com>
Mon, 18 Apr 2011 08:19:50 +0000 (10:19 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Mon, 18 Apr 2011 08:24:14 +0000 (10:24 +0200)
plugins/publiclink/get.php [new file with mode: 0644]
plugins/publiclink/getfile.php [deleted file]
plugins/publiclink/lib_public.php
plugins/publiclink/templates/breadcrumb.php [new file with mode: 0644]
plugins/publiclink/templates/files.php [new file with mode: 0644]
plugins/publiclink/templates/index.php [new file with mode: 0644]

diff --git a/plugins/publiclink/get.php b/plugins/publiclink/get.php
new file mode 100644 (file)
index 0000000..cdfe42e
--- /dev/null
@@ -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 (file)
index 15a568d..0000000
+++ /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
index 7c25c938fda53384aec66bb3a7eef39edd948f21..436dddeef222c94ae0b0d56cb3d4477c23e0cf22 100644 (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;
                }
        }
        
diff --git a/plugins/publiclink/templates/breadcrumb.php b/plugins/publiclink/templates/breadcrumb.php
new file mode 100644 (file)
index 0000000..3f4ae86
--- /dev/null
@@ -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 (file)
index 0000000..6473ad4
--- /dev/null
@@ -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 (file)
index 0000000..9e23845
--- /dev/null
@@ -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