Skip to content

Commit 71981ff

Browse files
committed
Add v0.1
1 parent 4835352 commit 71981ff

File tree

9 files changed

+440
-0
lines changed

9 files changed

+440
-0
lines changed

appinfo/app.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace OCA\LibreOnline\AppInfo;
4+
5+
use OCP\Util;
6+
7+
Util::addScript('libreonline', 'viewer');

appinfo/info.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<info>
3+
<id>libreonline</id>
4+
<name>LibreOnline</name>
5+
<description>
6+
LibreOffice Online app for ownCloud
7+
</description>
8+
<licence>MPLv2/LGPLv3+</licence>
9+
<require>8.0</require>
10+
<author>Ozcan Esen, Faruk Uzun</author>
11+
<shipped>true</shipped>
12+
<default_enable/>
13+
<ocsid></ocsid>
14+
15+
</info>

appinfo/routes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace OCA\LibreOnline\AppInfo;
4+
5+
return ['routes' => [
6+
['name' => 'api#saveFile', 'url' => '/save/', 'verb' => 'GET'],
7+
['name' => 'api#generateFileURL', 'url' => '/generateFileURL/', 'verb' => 'GET'],
8+
['name' => 'display#showLibreOnline', 'url' => '/', 'verb' => 'GET']
9+
10+
]];

appinfo/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1

controller/apicontroller.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace OCA\LibreOnline\Controller;
4+
5+
use OCP\AppFramework\Controller;
6+
use OCP\AppFramework\Http\ContentSecurityPolicy;
7+
use OCP\AppFramework\Http\TemplateResponse;
8+
use OCP\IRequest;
9+
use OCP\Files\IRootFolder;
10+
use OCP\IURLGenerator;
11+
12+
class ApiController extends Controller {
13+
14+
/** @var IURLGenerator */
15+
private $urlGenerator;
16+
private $rootFolder;
17+
private $userId;
18+
19+
/**
20+
* @param string $AppName
21+
* @param IRequest $request
22+
* @param IURLGenerator $urlGenerator
23+
*/
24+
public function __construct($AppName,
25+
IRootFolder $rootFolder,
26+
IRequest $request,
27+
IURLGenerator $urlGenerator,
28+
$userId) {
29+
parent::__construct($AppName, $request);
30+
31+
$this->urlGenerator = $urlGenerator;
32+
$this->userId = $userId;
33+
$this->rootFolder = $rootFolder;
34+
}
35+
36+
/**
37+
* @PublicPage
38+
* @NoCSRFRequired
39+
*
40+
* @return TemplateResponse
41+
*/
42+
public function saveFile($ip, $port, $jail, $dir, $name, $target) {
43+
44+
$url = "http://$ip:$port/$jail/$dir/$name";
45+
//FIXME: We should use owncloud api here.
46+
file_put_contents("/var/www/owncloud/data/" . $this->userId . "/files$target", file_get_contents($url));
47+
}
48+
49+
50+
/**
51+
* @PublicPage
52+
* @NoCSRFRequired
53+
*
54+
* @return TemplateResponse
55+
*/
56+
public function generateFileURL($file) {
57+
$url = sha1($file . mt_rand());
58+
$app_path = \OC_App::getAppPath("libreonline");
59+
$tmp_path = $app_path . '/tmp';
60+
//FIXME: We should use owncloud api here.
61+
copy("/var/www/owncloud/data/" . $this->userId . "/files$file", "$tmp_path/$url");
62+
$uri = \OC_App::getAppWebPath('libreonline') . "/tmp/$url";
63+
return $uri;
64+
}
65+
}

controller/displaycontroller.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace OCA\LibreOnline\Controller;
4+
5+
use OCP\AppFramework\Controller;
6+
use OCP\AppFramework\Http\ContentSecurityPolicy;
7+
use OCP\AppFramework\Http\TemplateResponse;
8+
use OCP\IRequest;
9+
use OCP\IURLGenerator;
10+
11+
class DisplayController extends Controller {
12+
13+
/** @var IURLGenerator */
14+
private $urlGenerator;
15+
16+
/**
17+
* @param string $AppName
18+
* @param IRequest $request
19+
* @param IURLGenerator $urlGenerator
20+
*/
21+
public function __construct($AppName,
22+
IRequest $request,
23+
IURLGenerator $urlGenerator) {
24+
parent::__construct($AppName, $request);
25+
$this->urlGenerator = $urlGenerator;
26+
}
27+
28+
/**
29+
* @PublicPage
30+
* @NoCSRFRequired
31+
*
32+
* @return TemplateResponse
33+
*/
34+
public function showLibreOnline() {
35+
$params = [
36+
'urlGenerator' => $this->urlGenerator
37+
];
38+
$response = new TemplateResponse($this->appName, 'online', $params, 'blank');
39+
40+
$policy = new ContentSecurityPolicy();
41+
$policy->addAllowedChildSrcDomain('*');
42+
$policy->addAllowedScriptDomain("*");
43+
$policy->addAllowedConnectDomain("*");
44+
$policy->addAllowedStyleDomain("*");
45+
$policy->addAllowedMediaDomain("*");
46+
$policy->addAllowedFontDomain('*');
47+
$policy->addAllowedImageDomain('*');
48+
$policy->addAllowedFrameDomain('*');
49+
$policy->addAllowedObjectDomain('*');
50+
$policy->allowInlineScript(True);
51+
$policy->allowInlineStyle(True);
52+
$policy->allowEvalScript(True);
53+
$response->setContentSecurityPolicy($policy);
54+
55+
return $response;
56+
}
57+
58+
}

js/viewer.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
(function(OCA) {
2+
3+
OCA.LibreOnline = OCA.LibreOnline || {};
4+
OCA.LibreOnline.Viewer = {
5+
6+
7+
attach: function(fileList) {
8+
this._extendFileActions(fileList.fileActions);
9+
},
10+
11+
hide: function() {
12+
$('#loframe').remove();
13+
if ($('#isPublic').val() && $('#filesApp').val()){
14+
$('#controls').removeClass('hidden');
15+
}
16+
17+
FileList.setViewerMode(false);
18+
19+
$('#app-content #controls').removeClass('hidden');
20+
},
21+
22+
23+
show: function(downloadUrl, isFileList) {
24+
var self = this;
25+
var $iframe;
26+
var viewer = OC.generateUrl('/apps/libreonline/?file={file}', {file: downloadUrl});
27+
$iframe = $('<iframe id="loframe" style="width:100%;height:100%;display:block;position:absolute;top:0;" src="'+viewer+'" />');
28+
29+
if(isFileList === true) {
30+
FileList.setViewerMode(true);
31+
}
32+
33+
if ($('#isPublic').val()) {
34+
$('#preview').append($iframe).css({height: '100%'});
35+
$('body').css({height: '100%'});
36+
$('footer').addClass('hidden');
37+
$('#imgframe').addClass('hidden');
38+
$('.directLink').addClass('hidden');
39+
$('.directDownload').addClass('hidden');
40+
$('#controls').addClass('hidden');
41+
} else {
42+
$('#app-content').append($iframe);
43+
}
44+
45+
$("#pageWidthOption").attr("selected","selected");
46+
$('#app-content #controls').addClass('hidden');
47+
48+
$('#loframe').load(function(){
49+
var iframe = $('#loframe').contents();
50+
if ($('#fileList').length) {
51+
iframe.find('#secondaryToolbarClose').click(function() {
52+
self.hide();
53+
});
54+
} else {
55+
iframe.find("#secondaryToolbarClose").addClass('hidden');
56+
}
57+
});
58+
},
59+
60+
61+
_extendFileActions: function(fileActions) {
62+
63+
64+
var self = this;
65+
66+
mimes = ['application/msword',
67+
'application/msword',
68+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
69+
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
70+
'application/vnd.ms-word.document.macroEnabled.12',
71+
'application/vnd.ms-word.template.macroEnabled.12',
72+
'application/vnd.ms-excel',
73+
'application/vnd.ms-excel',
74+
'application/vnd.ms-excel',
75+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
76+
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
77+
'application/vnd.ms-excel.sheet.macroEnabled.12',
78+
'application/vnd.ms-excel.template.macroEnabled.12',
79+
'application/vnd.ms-excel.addin.macroEnabled.12',
80+
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
81+
'application/vnd.ms-powerpoint',
82+
'application/vnd.ms-powerpoint',
83+
'application/vnd.ms-powerpoint',
84+
'application/vnd.ms-powerpoint',
85+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
86+
'application/vnd.openxmlformats-officedocument.presentationml.template',
87+
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
88+
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
89+
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
90+
'application/vnd.ms-powerpoint.template.macroEnabled.12',
91+
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
92+
'application/vnd.oasis.opendocument.chart',
93+
'application/vnd.oasis.opendocument.chart-template',
94+
'application/vnd.oasis.opendocument.formula',
95+
'application/vnd.oasis.opendocument.formula-template',
96+
'application/vnd.oasis.opendocument.graphics',
97+
'application/vnd.oasis.opendocument.graphics-template',
98+
'application/vnd.oasis.opendocument.image',
99+
'application/vnd.oasis.opendocument.image-template',
100+
'application/vnd.oasis.opendocument.presentation',
101+
'application/vnd.oasis.opendocument.presentation-template',
102+
'application/vnd.oasis.opendocument.spreadsheet',
103+
'application/vnd.oasis.opendocument.spreadsheet-template',
104+
'application/vnd.oasis.opendocument.text',
105+
'application/vnd.oasis.opendocument.text-master',
106+
'application/vnd.oasis.opendocument.text-template',
107+
'application/vnd.oasis.opendocument.text-web',
108+
'application/vnd.oasis.opendocument.database',
109+
]
110+
111+
for (var _mime in mimes){
112+
fileActions.registerAction({
113+
name: 'view',
114+
displayName: 'Favorite',
115+
mime: mimes[_mime],
116+
permissions: OC.PERMISSION_READ,
117+
actionHandler: function(fileName, context) {
118+
var downloadUrl = '';
119+
if($('#isPublic').val()) {
120+
var sharingToken = $('#sharingToken').val();
121+
downloadUrl = OC.generateUrl('/s/{token}/download?files={files}&path={path}', {
122+
token: sharingToken,
123+
files: fileName,
124+
path: context.dir
125+
});
126+
} else {
127+
downloadUrl = Files.getDownloadUrl(fileName, context.dir);
128+
}
129+
self.show(context.dir+ '/' + fileName, true);
130+
}
131+
});
132+
fileActions.setDefault(mimes[_mime], 'view');
133+
}
134+
135+
}
136+
};
137+
138+
})(OCA);
139+
140+
if(!$.browser.msie || ($.browser.msie && $.browser.version >= 9)){
141+
OC.Plugins.register('OCA.Files.FileList', OCA.LibreOnline.Viewer);
142+
}

0 commit comments

Comments
 (0)