summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-08-27 15:46:05 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-08-27 20:37:38 -0400
commit0a9d1ed3a645efda56ae757f45aa7efb5a35ce4f (patch)
treea2fbdc55f42a149c8a5e738763ce731e9c55f6dc /apps/files_sharing
parent8374a49cc19cf43489a415388fd782ba1574ee82 (diff)
downloadnextcloud-server-0a9d1ed3a645efda56ae757f45aa7efb5a35ce4f.tar.gz
nextcloud-server-0a9d1ed3a645efda56ae757f45aa7efb5a35ce4f.zip
Initial previewer for public links
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/css/public.css2
-rw-r--r--apps/files_sharing/get.php88
-rw-r--r--apps/files_sharing/js/public.js18
-rw-r--r--apps/files_sharing/public.php69
-rw-r--r--apps/files_sharing/templates/authenticate.php9
-rwxr-xr-xapps/files_sharing/templates/get.php11
-rwxr-xr-xapps/files_sharing/templates/public.php13
7 files changed, 111 insertions, 99 deletions
diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css
new file mode 100644
index 00000000000..aa76c06175b
--- /dev/null
+++ b/apps/files_sharing/css/public.css
@@ -0,0 +1,2 @@
+#content { position:relative; }
+#preview p { text-align: center; } \ No newline at end of file
diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php
deleted file mode 100644
index bcbe5985fb6..00000000000
--- a/apps/files_sharing/get.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-// only need authentication apps
-$RUNTIME_APPTYPES=array('authentication');
-OC_App::loadApps($RUNTIME_APPTYPES);
-
-OCP\JSON::checkAppEnabled('files_sharing');
-//FIXME lib_share / OC_Share no longer exists
-require_once 'lib_share.php';
-
-//get the path of the shared file
-if (isset($_GET['token']) && $source = OC_Share::getSource($_GET['token'])) {
- $token = $_GET['token'];
- // 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"));
- $subPath = isset( $_GET['path'] ) ? $_GET['path'] : '';
- $root = $source;
- $source .= $subPath;
- if (!OC_Filesystem::file_exists($source)) {
- header("HTTP/1.0 404 Not Found");
- $tmpl = new OCP\Template("", "404", "guest");
- $tmpl->assign("file", $subPath);
- $tmpl->printPage();
- exit;
- }
- if (OC_Filesystem::is_dir($source)) {
- $files = array();
- $rootLength = strlen($root);
- foreach (OC_Files::getdirectorycontent($source) as $i) {
- $i['date'] = OCP\Util::formatDate($i['mtime'] );
- if ($i['type'] == 'file') {
- $fileinfo = pathinfo($i['name']);
- $i['basename'] = $fileinfo['filename'];
- $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
- }
- $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);
- }
- }
- // Load the files we need
- OCP\Util::addStyle("files", "files");
- $breadcrumbNav = new OCP\Template("files", "part.breadcrumb", "");
- $breadcrumbNav->assign("breadcrumb", $breadcrumb);
- $breadcrumbNav->assign("baseURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
- $list = new OCP\Template("files", "part.list", "");
- $list->assign("files", $files);
- $list->assign("baseURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
- $list->assign("downloadURL", OCP\Util::linkTo("", "public.php")."?service=files&token=".$token."&path=");
- $list->assign("readonly", true);
- $tmpl = new OCP\Template("files", "index", "user");
- $tmpl->assign("fileList", $list->fetchPage(), false);
- $tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
- $tmpl->assign("readonly", true);
- $tmpl->assign("allowZipDownload", false);
- $tmpl->assign("dir", 'shared dir');
- $tmpl->printPage();
- } else {
- //get time mimetype and set the headers
- $mimetype = OC_Filesystem::getMimeType($source);
- header("Content-Transfer-Encoding: binary");
- OCP\Response::disableCaching();
- header('Content-Disposition: attachment; filename="'.basename($source).'"');
- header("Content-Type: " . $mimetype);
- header("Content-Length: " . OC_Filesystem::filesize($source));
- //download the file
- @ob_clean();
- //FIXME OC_Share no longer exists
- OCP\Util::emitHook('OC_Share', 'public-download', array('source'=>$source, 'token'=>$token));
- OC_Filesystem::readfile($source);
- }
-} else {
- header("HTTP/1.0 404 Not Found");
- $tmpl = new OCP\Template("", "404", "guest");
- $tmpl->printPage();
- die();
-}
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
new file mode 100644
index 00000000000..755382e0736
--- /dev/null
+++ b/apps/files_sharing/js/public.js
@@ -0,0 +1,18 @@
+// Override download path to files_sharing/public.php
+function fileDownloadPath(dir, file) {
+ return $('#downloadURL').val();
+}
+
+$(document).ready(function() {
+
+ if (typeof FileActions !== 'undefined') {
+ var mimetype = $('#mimetype').val();
+ // Show file preview if previewer is available, images are already handled by the template
+ if (mimetype.substr(0, mimetype.indexOf('/')) != 'image') {
+ // Trigger default action if not download TODO
+ var action = FileActions.getDefault(mimetype, 'file', FileActions.PERMISSION_READ);
+ action($('#filename').val());
+ }
+ }
+
+}); \ No newline at end of file
diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php
new file mode 100644
index 00000000000..15dac576d98
--- /dev/null
+++ b/apps/files_sharing/public.php
@@ -0,0 +1,69 @@
+<?php
+// Load other apps for file previews
+OC_App::loadApps();
+if (isset($_GET['file'])) {
+ $pos = strpos($_GET['file'], '/', 1);
+ $uidOwner = substr($_GET['file'], 1, $pos - 1);
+ if (OCP\User::userExists($uidOwner)) {
+ OC_Util::setupFS($uidOwner);
+ $file = substr($_GET['file'], $pos);
+ $fileSource = OC_Filecache::getId($_GET['file'], '');
+ if ($linkItem = OCP\Share::getItemSharedWithByLink('file', $fileSource, $uidOwner)) {
+ if (isset($linkItem['share_with'])) {
+ // Check password
+ if (isset($_POST['password'])) {
+ $password = $_POST['password'];
+ $storedHash = $linkItem['share_with'];
+ $forcePortable = (CRYPT_BLOWFISH != 1);
+ $hasher = new PasswordHash(8, $forcePortable);
+ if (!($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash))) {
+ $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
+ $tmpl->assign('error', true);
+ $tmpl->printPage();
+ exit();
+ }
+ // Continue on if password is valid
+ } else {
+ // Prompt for password
+ $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
+ $tmpl->printPage();
+ exit();
+ }
+ }
+ $path = $linkItem['path'];
+ // Download the file
+ if (isset($_GET['download'])) {
+ $mimetype = OC_Filesystem::getMimeType($path);
+ header('Content-Transfer-Encoding: binary');
+ header('Content-Disposition: attachment; filename="'.basename($path).'"');
+ header('Content-Type: '.$mimetype);
+ header('Content-Length: '.OC_Filesystem::filesize($path));
+ OCP\Response::disableCaching();
+ @ob_clean();
+ OC_Filesystem::readfile($path);
+ } else {
+ OCP\Util::addStyle('files_sharing', 'public');
+ OCP\Util::addScript('files_sharing', 'public');
+ OCP\Util::addScript('files', 'fileactions');
+ $tmpl = new OCP\Template('files_sharing', 'public', 'guest');
+ $tmpl->assign('owner', $uidOwner);
+ $tmpl->assign('name', basename($path));
+ // Show file list
+ if (OC_Filesystem::is_dir($path)) {
+ // TODO
+ } else {
+ // Show file preview if viewer is available
+ $tmpl->assign('dir', dirname($path));
+ $tmpl->assign('filename', basename($path));
+ $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&file='.$_GET['file'].'&download');
+ }
+ $tmpl->printPage();
+ }
+ exit();
+ }
+ }
+}
+header('HTTP/1.0 404 Not Found');
+$tmpl = new OCP\Template('', '404', 'guest');
+$tmpl->printPage(); \ No newline at end of file
diff --git a/apps/files_sharing/templates/authenticate.php b/apps/files_sharing/templates/authenticate.php
new file mode 100644
index 00000000000..41064d51464
--- /dev/null
+++ b/apps/files_sharing/templates/authenticate.php
@@ -0,0 +1,9 @@
+<form action="index.php" method="post">
+ <fieldset>
+ <p>
+ <label for="password" class="infield"><?php echo $l->t('Password'); ?></label>
+ <input type="password" name="password" id="password" value="" />
+ <input type="submit" value="<?php echo $l->t('Submit'); ?>" />
+ </p>
+ </fieldset>
+</form> \ No newline at end of file
diff --git a/apps/files_sharing/templates/get.php b/apps/files_sharing/templates/get.php
deleted file mode 100755
index 57275f07a3d..00000000000
--- a/apps/files_sharing/templates/get.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<table>
- <thead>
- <tr>
- <th id="headerSize"><?php echo $l->t( 'Size' ); ?></th>
- <th id="headerDate"><span id="modified"><?php echo $l->t( 'Modified' ); ?></span><span class="selectedActions"><a href="" class="delete"><?php echo $l->t('Delete all')?> <img class="svg" alt="<?php echo $l->t('Delete')?>" src="<?php echo OCP\image_path("core", "actions/delete.svg"); ?>" /></a></span></th>
- </tr>
- </thead>
- <tbody id="fileList" data-readonly="<?php echo $_['readonly'];?>">
- <?php echo($_['fileList']); ?>
- </tbody>
-</table> \ No newline at end of file
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
new file mode 100755
index 00000000000..065818c2200
--- /dev/null
+++ b/apps/files_sharing/templates/public.php
@@ -0,0 +1,13 @@
+<input type="hidden" name="dir" value="<?php echo $_['dir'] ?>" id="dir">
+<input type="hidden" name="downloadURL" value="<?php echo $_['downloadURL'] ?>" id="downloadURL">
+<input type="hidden" name="filename" value="<?php echo $_['filename'] ?>" id="filename">
+<input type="hidden" name="mimetype" value="<?php echo $_['mimetype'] ?>" id="mimetype">
+<div id="preview">
+ <p><?php echo $_['owner']; ?> shared the file <?php echo $_['name'] ?> with you</p>
+</div>
+<div id="content">
+ <?php if (substr($_['mimetype'], 0 , strpos($_['mimetype'], '/')) == 'image'): ?>
+ <img src="<?php echo $_['downloadURL']; ?>" />
+ <?php endif; ?>
+</div>
+<a href="<?php echo $_['downloadURL']; ?>">Download</a> \ No newline at end of file