From 5b165331dff19d02eaa61bcd03b48f2fae270860 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 7 Aug 2013 21:14:36 +0300 Subject: [PATCH] Copy genesis to storage --- ajax/genesis.php | 4 ++-- ajax/session.php | 15 ++++++++++++--- appinfo/app.php | 2 +- appinfo/routes.php | 10 ++++++++++ js/editor/boot_editor.js | 2 +- js/office.js | 6 +++--- lib/download.php | 10 ++++++---- lib/download/range.php | 5 +++-- lib/download/simple.php | 6 ++++-- lib/genesis.php | 17 +++++++++++++++++ lib/session.php | 2 +- lib/view.php | 31 +++++++++++++++++++++++++++++++ templates/documents.php | 2 +- 13 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 appinfo/routes.php create mode 100644 lib/genesis.php create mode 100644 lib/view.php diff --git a/ajax/genesis.php b/ajax/genesis.php index fdebb1e2..4795aef5 100644 --- a/ajax/genesis.php +++ b/ajax/genesis.php @@ -13,8 +13,8 @@ namespace OCA\Office; \OCP\User::checkLoggedIn(); -$session = Session::getSession($_SERVER['QUERY_STRING']); -$filename = isset($session['genesis_url']) ? $session['genesis_url'] : ''; +$session = Session::getSession(@$_SERVER['QUERY_STRING']); +$filename = isset($session['genesis_url']) ? $session['genesis_url'] : ''; $download = new Download($filename); $download->sendResponse(); \ No newline at end of file diff --git a/ajax/session.php b/ajax/session.php index 4c55acbd..22b13388 100644 --- a/ajax/session.php +++ b/ajax/session.php @@ -6,10 +6,19 @@ namespace OCA\Office; \OCP\User::checkLoggedIn(); $genesis = @$_POST['genesis']; -if ($genesis){ - $session = Session::getSessionByUrl($genesis); + +$uid = \OCP\User::getUser(); +$officeView = View::initOfficeView($uid); +if (!$officeView->file_exists($genesis)){ + $genesisPath = View::storeDocument($uid, $genesis); +} else { + $genesisPath = $genesis; +} + +if ($genesisPath){ + $session = Session::getSessionByPath($genesisPath); if (!$session){ - $session = Session::addSession($genesis); + $session = Session::addSession($genesisPath); } \OCP\JSON::success($session); exit(); diff --git a/appinfo/app.php b/appinfo/app.php index cce7e0f0..db7e43eb 100755 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -33,7 +33,7 @@ OCP\App::addNavigationEntry(array( 'name' => 'Office') ); -OC::$CLASSPATH['OCA\Office\Storage'] = 'office/lib/storage.php'; +OC::$CLASSPATH['OCA\Office\Genesis'] = 'office/lib/genesis.php'; OC::$CLASSPATH['OCA\Office\Download\Simple'] = 'office/lib/download/simple.php'; OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php'; diff --git a/appinfo/routes.php b/appinfo/routes.php new file mode 100644 index 00000000..8d7eda5a --- /dev/null +++ b/appinfo/routes.php @@ -0,0 +1,10 @@ +create('office_genesis', 'ajax/genesis/{es_id}') + ->post() + ->action('\OCA\Office\Genesis', 'serve') +; +$this->create('office_genesis', 'ajax/genesis/{es_id}') + ->get() + ->action('\OCA\Office\Genesis', 'serve') +; diff --git a/js/editor/boot_editor.js b/js/editor/boot_editor.js index 64258c9e..3895ecbc 100644 --- a/js/editor/boot_editor.js +++ b/js/editor/boot_editor.js @@ -98,7 +98,7 @@ var webodfEditor = (function () { server = serverFactory.createServer({url: "./office/ajax/otpoll.php"}); server.getGenesisUrl = function(sid) { // what a dirty hack :) - return window.officeMain.doclocation; + return OC.Router.generate('office_genesis')+'/' +sid; }; server.connect(8000, callback); }); diff --git a/js/office.js b/js/office.js index 7a529b0c..dd5c1537 100644 --- a/js/office.js +++ b/js/office.js @@ -83,13 +83,13 @@ var officeMain = { }); }); }, - registerSession : function(dir, file){ + registerSession : function(filepath){ "use strict"; if (officeMain.initialized === undefined) { alert("WebODF Editor not yet initialized..."); return; } - var filepath = fileDownloadPath(dir, file); + $.post(OC.filePath('office', 'ajax', 'session.php'), { 'genesis' : filepath }, officeMain.onView @@ -135,7 +135,7 @@ var officeMain = { $(document).ready(function() { $('.documentslist tr').click(function(event) { event.preventDefault(); - officeMain.registerSession('', $(this).attr('data-file')); + officeMain.registerSession($(this).attr('data-file')); }); $('#odf_close').live('click', officeMain.onClose); OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup); diff --git a/lib/download.php b/lib/download.php index 52ae41f9..13758057 100644 --- a/lib/download.php +++ b/lib/download.php @@ -3,7 +3,7 @@ namespace OCA\Office; class Download { - + protected $view; // File to be served protected $filepath; @@ -11,6 +11,7 @@ class Download { public function __construct($filepath){ $this->filepath = $filepath; + if (isset($_SERVER['HTTP_RANGE'])) { $this->instance = new Download\Range($filepath); } else { @@ -20,6 +21,7 @@ class Download { public function sendResponse(){ \OCP\Response::disableCaching(); + $this->view = View::initOfficeView(\OCP\User::getUser()); if (!$this->fileExists()){ $this->sendNotFound(); @@ -34,15 +36,15 @@ class Download { } protected function getFilesize(){ - return \OC\Files\Filesystem::filesize($this->filepath); + return $this->view->filesize($this->filepath); } protected function getMimeType(){ - return \OC\Files\Filesystem::getMimeType($this->filepath); + return $this->view->getMimeType($this->filepath); } protected function fileExists(){ - return \OC\Files\Filesystem::file_exists($this->filepath); + return $this->view->file_exists($this->filepath); } protected function sendNotFound(){ diff --git a/lib/download/range.php b/lib/download/range.php index 942a2ad3..198f7ca4 100644 --- a/lib/download/range.php +++ b/lib/download/range.php @@ -1,7 +1,7 @@ view = View::initOfficeView(\OCP\User::getUser()); if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){ $this->sendNotSatisfiable(); } @@ -28,7 +29,7 @@ class Range extends \OCA\Office\Download { $this->sendNotSatisfiable(); } - $handle = \OC\Files\Filesystem::fopen($this->filepath, 'rb'); + $handle = $this->view->fopen($this->filepath, 'rb'); \fseek($handle, $start); $buffer = \fread($handle, $end - $start); $md5Sum = md5($buffer); diff --git a/lib/download/simple.php b/lib/download/simple.php index 2c30e81f..de81aec8 100644 --- a/lib/download/simple.php +++ b/lib/download/simple.php @@ -1,6 +1,7 @@ view = View::initOfficeView(\OCP\User::getUser()); header( 'Content-Type:' . $this->getMimeType() ); $encodedName = rawurlencode($this->getFilename()); @@ -21,10 +23,10 @@ class Simple extends \OCA\Office\Download { . '; filepath="' . $encodedName . '"'); } - header('Content-Length: ' . \OC\Files\Filesystem::filesize($this->filepath)); + header('Content-Length: ' . $this->view->filesize($this->filepath)); \OC_Util::obEnd(); - \OC\Files\Filesystem::readfile($this->filepath); + $this->view->readfile($this->filepath); } } diff --git a/lib/genesis.php b/lib/genesis.php new file mode 100644 index 00000000..06d6af80 --- /dev/null +++ b/lib/genesis.php @@ -0,0 +1,17 @@ +sendResponse(); + } + +} \ No newline at end of file diff --git a/lib/session.php b/lib/session.php index 145d1ddf..83a16995 100644 --- a/lib/session.php +++ b/lib/session.php @@ -16,7 +16,7 @@ class Session { return $result->fetchRow(); } - public static function getSessionByUrl($url){ + public static function getSessionByPath($url){ $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ?'); $result = $query->execute(array($url)); return $result->fetchRow(); diff --git a/lib/view.php b/lib/view.php new file mode 100644 index 00000000..1ad952db --- /dev/null +++ b/lib/view.php @@ -0,0 +1,31 @@ +is_dir(self::OFFICE_DIRNAME)) { + $view->mkdir(self::OFFICE_DIRNAME); + } + + if (!self::$officeView){ + self::$officeView = new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME); + } + + return self::$officeView; + } + + public static function storeDocument($uid, $path){ + $view = new \OC\Files\View('/' . $uid); + + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + $view->copy('/files' . $path, self::OFFICE_DIRNAME . $path); + \OC_FileProxy::$enabled = $proxyStatus; + return $path; + } +} diff --git a/templates/documents.php b/templates/documents.php index 64f187e2..8559f5a6 100755 --- a/templates/documents.php +++ b/templates/documents.php @@ -4,7 +4,7 @@ - +