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 : '