diff --git a/appinfo/routes.php b/appinfo/routes.php index a4ea9101..6b3ea81a 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -33,6 +33,8 @@ $application->registerRoutes($this, [ ['name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'], ['name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'], ['name' => 'document#showLOleaflet', 'url' => '/loleaflet', 'verb' => 'GET'], + //documents - for CloudSuite access + ['name' => 'document#localLoad', 'url' => 'ajax/documents/load/{esId}', 'verb' => 'POST'], //settings ['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'], ['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'], diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index cdb6d35b..f1c9f5d9 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -37,6 +37,7 @@ class DocumentController extends Controller{ private $urlGenerator; const ODT_TEMPLATE_PATH = '/assets/new.odt'; + const CLOUDSUITE_TMP_PATH = '/documents-tmp/'; public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, IURLGenerator $urlGenerator, $uid){ parent::__construct($appName, $request); @@ -111,6 +112,47 @@ class DocumentController extends Controller{ return $response; } + /** + * @NoAdminRequired + * @PublicPage + * Copy the file to a temporary location that is shared between the + * cloudsuite server part and owncloud. + */ + public function localLoad($esId){ + $session = new Db\Session(); + $session->load($esId); + + $member = new Db\Member(); + $member->load($this->uid); + + try { + if ($member->getIsGuest()){ + $file = File::getByShareToken($member->getToken()); + } else { + $file = new File($session->getFileId()); + } + + $view = $file->getOwnerView(true); + $path = $file->getPath(true); + } catch (\Exception $e){ + return array( + 'status' => 'error', + 'message' => (string) $this->l10n->t('Unable to copy document for CloudSuite access.') + ); + } + + $content = $view->file_get_contents($path); + + $filename = tempnam(dirname(__DIR__) . self::CLOUDSUITE_TMP_PATH, 'ccs-'); + file_put_contents($filename, $content); + chmod($filename, 0660); + + return array( + 'status' => 'success', 'filename' => $filename, + 'basename' => basename($filename) + ); + } + /** * @NoAdminRequired * @PublicPage diff --git a/js/documents.js b/js/documents.js index 6e51741f..806db1d9 100644 --- a/js/documents.js +++ b/js/documents.js @@ -153,6 +153,8 @@ var documentsMain = { esId : false, ready :false, fileName: null, + baseName: null, + url: null, canShare : false, toolbar : '
', @@ -179,8 +181,8 @@ var documentsMain = { $('title').text(title + ' - ' + documentsMain.UI.mainTitle); var viewer = window.location.protocol + '//' + window.location.host + '/cloudsuite/cloudsuite.html?' + - 'file_path=' + 'file:///local/home/kendy/Downloads/ODT-test.odt' + - '&host=' + 'ws://localhost:9980' + + 'file_path=' + documentsMain.url + + '&host=' + 'ws://' + window.location.hostname + ':9980' + '&edit=' + 'false' + '×tamp=' + ''; @@ -346,15 +348,16 @@ var documentsMain = { documentsMain.fileId = response.file_id; documentsMain.fileName = response.title; - documentsMain.UI.showEditor(documentsMain.fileName || response.title); + documentsMain.esId = response.es_id; + documentsMain.memberId = response.member_id; + + documentsMain.loadDocument(); + if (documentsMain.isGuest){ $('#odf-close').text(t('documents', 'Save') ); $('#odf-close').removeClass('icon-view-close'); } //var serverFactory = new ServerFactory(); - documentsMain.esId = response.es_id; - documentsMain.memberId = response.member_id; - /* // TODO: set webodf translation system, by passing a proper function translate(!string):!string in "runtime.setTranslator(translate);" documentsMain.webodfServerInstance = serverFactory.createServer({ @@ -518,6 +521,28 @@ var documentsMain = { input.selectRange(0, name.length); }, + loadDocument: function() { + var url = OC.generateUrl('apps/documents/ajax/documents/load/{es_id}', {es_id: documentsMain.esId}); + $.post( + url, + {}, + function(result) { + if (result && result.status === 'error') { + if (result.message){ + documentsMain.IU.notify(result.message); + } + documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.')); + return; + } + + documentsMain.url = 'file://' + result.filename; + documentsMain.baseName = result.basename; + + documentsMain.UI.showEditor(documentsMain.fileName); + } + ); + }, + renameDocument: function(name) { var url = OC.generateUrl('apps/documents/ajax/documents/rename/{file_id}', {file_id: documentsMain.fileId}); $.post(