]> source.dussan.org Git - nextcloud-server.git/commitdiff
Copy get.php into files_sharing, public links now use files templates
authorMichael Gapczynski <GapczynskiM@gmail.com>
Thu, 18 Aug 2011 19:35:11 +0000 (15:35 -0400)
committerMichael Gapczynski <GapczynskiM@gmail.com>
Thu, 18 Aug 2011 19:35:31 +0000 (15:35 -0400)
apps/files_sharing/get.php [new file with mode: 0644]
apps/files_sharing/lib_share.php
files/index.php
files/templates/part.breadcrumb.php
files/templates/part.list.php

diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php
new file mode 100644 (file)
index 0000000..121793e
--- /dev/null
@@ -0,0 +1,85 @@
+<?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_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"));
+       $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
+       print_r($dir);
+       $root = $source;
+       $source .= $dir;
+       if (!OC_Filesystem::file_exists($source)) {
+               header("HTTP/1.0 404 Not Found");
+               $tmpl = new OC_Template("", "404", "guest");
+               $tmpl->assign("file", $dir);
+               $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();
+               $pathtohere = "/";
+               foreach (explode("/", $dir) as $i) {
+                       if ($i != "") {
+                               $pathtohere .= "$i/";
+                               $breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
+                       }
+               }
+               // Load the files we need
+               OC_Util::addStyle("files", "files");
+               OC_Util::addScript("files", "files");
+               OC_Util::addScript("files", "filelist");
+               $breadcrumbNav = new OC_Template("files", "part.breadcrumb", "");
+               $breadcrumbNav->assign("breadcrumb", $breadcrumb);
+               $breadcrumbNav->assign("baseUrl", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&");
+               $list = new OC_Template("files", "part.list", "");
+               $list->assign("files", $files);
+               $list->assign("baseUrl", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&");
+               $tmpl = new OC_Template("files", "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($source);
+               header("Content-Transfer-Encoding: binary");
+               header("Expires: 0");
+               header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+               header("Pragma: public");
+               header("Content-Disposition: filename='".basename($source)."'");
+               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();
+}
+?>
\ No newline at end of file
index c7ac7c3e8fdf626f391294ec988341d733ccaa3c..df704c131e720bce5a9cd1e4248bc27fa153756a 100644 (file)
@@ -135,6 +135,7 @@ class OC_Share {
                                $in .= ", '".$uid."@".$group."'";
                        }
                }
+               $in .= ", '".self::PUBLICLINK."'";
                $in .= ")";
                return $in;
        }
index 821879b03463672a9020ec4ea1c4522f43bf660c..5ab74a6267bd0ca9692b434430d552037798f109 100644 (file)
@@ -69,8 +69,10 @@ foreach( explode( "/", $dir ) as $i ){
 // make breadcrumb und filelist markup
 $list = new OC_Template( "files", "part.list", "" );
 $list->assign( "files", $files );
+$list->assign( "baseUrl", OC_Helper::linkTo("files", "index.php?"));
 $breadcrumbNav = new OC_Template( "files", "part.breadcrumb", "" );
 $breadcrumbNav->assign( "breadcrumb", $breadcrumb );
+$breadcrumbNav->assign( "baseUrl", OC_Helper::linkTo("files", "index.php?"));
 
 $maxUploadFilesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
 
index 96342919df66731e6e40523015a3b2059726f514..c4f75bf86b8970ba1bfd7d4e4add2e0e78a5c6dc 100644 (file)
@@ -1,5 +1,5 @@
        <?php foreach($_["breadcrumb"] as $crumb): ?>
                <div class="crumb svg" data-dir='<?php echo $crumb["dir"];?>' style='background-image:url("<?php echo image_path('core','breadcrumb.png');?>")'>
-                       <a href="<?php echo link_to("files", "index.php?dir=".$crumb["dir"]); ?>"><?php echo htmlspecialchars($crumb["name"]); ?></a>
+                       <a href="<?php echo $_['baseUrl']."dir=".$crumb["dir"]; ?>"><?php echo htmlspecialchars($crumb["name"]); ?></a>
                </div>
        <?php endforeach; ?>
index 942f749c828ec24fbab1f7650b3f3cfcbff21b86..b6f586443dba09f16dd59d76015c4cb5f41fc450 100644 (file)
@@ -9,7 +9,7 @@
                        <tr data-file="<?php echo $file['name'];?>" data-type="<?php echo ($file['type'] == 'dir')?'dir':'file'?>" data-mime="<?php echo $file['mime']?>" data-size='<?php echo $file['size'];?>'>
                                <td class="filename svg" style="background-image:url(<?php if($file['type'] == 'dir') echo mimetype_icon('dir'); else echo mimetype_icon($file['mime']); ?>)">
                                        <input type="checkbox" />
-                                       <a class="name" href="<?php if($file['type'] == 'dir') echo link_to('files', 'index.php?dir='.$file['directory'].'/'.$file['name']); else echo link_to('files', 'download.php?file='.$file['directory'].'/'.$file['name']); ?>" title="">
+                                       <a class="name" href="<?php if($file['type'] == 'dir') echo $_['baseUrl'].'dir='.$file['directory'].'/'.$file['name']; else echo link_to('files', 'download.php?file='.$file['directory'].'/'.$file['name']); ?>" title="">
                                        <span class="nametext">
                                                <?php if($file['type'] == 'dir'):?>
                                                        <?php echo htmlspecialchars($file['name']);?>