Filters for files app

pull/1/head
Victor Dubiniuk 10 years ago
parent 81a02506e8
commit 3669d90862

@ -0,0 +1,18 @@
<?php
/**
* ownCloud - Documents App
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Documents;
\OCP\JSON::checkLoggedIn();
$download = new Download(\OCP\User::getUser(), '/files' . @$_GET['path']);
$download->sendResponse();

@ -90,7 +90,6 @@ class SessionController extends Controller{
self::preDispatchGuest();
}
list($view, $path) = $file->getOwnerViewAndPath();
$isWritable = ($view->file_exists($path) && $view->isUpdatable($path)) || $view->isCreatable($path);

@ -54,7 +54,7 @@ var odfViewer = {
var location = filename;
} else {
//Public page, files app, etc
var location = fileDownloadPath($('#dir').val(), filename);
var location = OC.filePath('documents', 'ajax', 'download.php') + '?path=' + $('#dir').val() + encodeURIComponent(filename);
OC.addStyle('documents', '3rdparty/webodf/editor');
}

@ -38,29 +38,33 @@ class Download_Range extends \OCA\Documents\Download {
if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){
$this->sendNotSatisfiable();
}
$mimetype = $this->getMimeType();
$content = $this->view->file_get_contents($this->filepath);
$data = Filter::read($content, $mimetype);
$size = strlen($data['content']);
$ranges = explode(',', substr($_SERVER['HTTP_RANGE'], 6));
foreach ($ranges as $range){
$parts = explode('-', $range);
$start = isset($parts[0]) ? $parts[0] : 0;
$end = isset($parts[1]) ? $parts[1] : $this->getFilesize() - 1;
$end = isset($parts[1]) ? $parts[1] : $size - 1;
if ($start > $end){
$this->sendNotSatisfiable();
}
$handle = $this->view->fopen($this->filepath, 'rb');
\fseek($handle, $start);
$buffer = \fread($handle, $end - $start);
$buffer = substr($data['content'], $start, $end - $start);
$md5Sum = md5($buffer);
\fclose($handle);
// send the headers and data
header("Content-Length: " . $end - $start);
header("Content-md5: " . $md5Sum);
header("Accept-Ranges: bytes");
header('Content-Range: bytes ' . $start . '-' . ($end) . '/' . $this->getFilesize());
header('Content-Range: bytes ' . $start . '-' . ($end) . '/' . $size);
header("Connection: close");
header("Content-type: " . $this->getMimeType());
header("Content-type: " . $data['mimetype']);
header('Content-Disposition: attachment; filename=' . $this->getFilename());
\OC_Util::obEnd();
echo $buffer;

@ -25,7 +25,11 @@ class Download_Simple extends \OCA\Documents\Download {
* Send the whole file content as a response
*/
public function sendResponse(){
header( 'Content-Type:' . $this->getMimeType() );
$mimetype = $this->getMimeType();
$content = $this->view->file_get_contents($this->filepath);
$data = Filter::read($content, $mimetype);
header( 'Content-Type:' . $data['mimetype'] );
$encodedName = rawurlencode($this->getFilename());
if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])){
@ -37,9 +41,10 @@ class Download_Simple extends \OCA\Documents\Download {
. '; filepath="' . $encodedName . '"');
}
header('Content-Length: ' . $this->view->filesize($this->filepath));
header('Content-Length: ' . strlen($data['content']));
\OC_Util::obEnd();
$this->view->readfile($this->filepath);
echo $data['content'];
}
}

Loading…
Cancel
Save