Skip to content

Commit

Permalink
Add v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
farukuzun committed Dec 1, 2015
1 parent 4835352 commit 71981ff
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 0 deletions.
7 changes: 7 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace OCA\LibreOnline\AppInfo;

use OCP\Util;

Util::addScript('libreonline', 'viewer');
15 changes: 15 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<info>
<id>libreonline</id>
<name>LibreOnline</name>
<description>
LibreOffice Online app for ownCloud
</description>
<licence>MPLv2/LGPLv3+</licence>
<require>8.0</require>
<author>Ozcan Esen, Faruk Uzun</author>
<shipped>true</shipped>
<default_enable/>
<ocsid></ocsid>

</info>
10 changes: 10 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace OCA\LibreOnline\AppInfo;

return ['routes' => [
['name' => 'api#saveFile', 'url' => '/save/', 'verb' => 'GET'],
['name' => 'api#generateFileURL', 'url' => '/generateFileURL/', 'verb' => 'GET'],
['name' => 'display#showLibreOnline', 'url' => '/', 'verb' => 'GET']

]];
1 change: 1 addition & 0 deletions appinfo/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1
65 changes: 65 additions & 0 deletions controller/apicontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace OCA\LibreOnline\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
use OCP\Files\IRootFolder;
use OCP\IURLGenerator;

class ApiController extends Controller {

/** @var IURLGenerator */
private $urlGenerator;
private $rootFolder;
private $userId;

/**
* @param string $AppName
* @param IRequest $request
* @param IURLGenerator $urlGenerator
*/
public function __construct($AppName,
IRootFolder $rootFolder,
IRequest $request,
IURLGenerator $urlGenerator,
$userId) {
parent::__construct($AppName, $request);

$this->urlGenerator = $urlGenerator;
$this->userId = $userId;
$this->rootFolder = $rootFolder;
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function saveFile($ip, $port, $jail, $dir, $name, $target) {

$url = "http://$ip:$port/$jail/$dir/$name";
//FIXME: We should use owncloud api here.
file_put_contents("/var/www/owncloud/data/" . $this->userId . "/files$target", file_get_contents($url));
}


/**
* @PublicPage
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function generateFileURL($file) {
$url = sha1($file . mt_rand());
$app_path = \OC_App::getAppPath("libreonline");
$tmp_path = $app_path . '/tmp';
//FIXME: We should use owncloud api here.
copy("/var/www/owncloud/data/" . $this->userId . "/files$file", "$tmp_path/$url");
$uri = \OC_App::getAppWebPath('libreonline') . "/tmp/$url";
return $uri;
}
}
58 changes: 58 additions & 0 deletions controller/displaycontroller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace OCA\LibreOnline\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
use OCP\IURLGenerator;

class DisplayController extends Controller {

/** @var IURLGenerator */
private $urlGenerator;

/**
* @param string $AppName
* @param IRequest $request
* @param IURLGenerator $urlGenerator
*/
public function __construct($AppName,
IRequest $request,
IURLGenerator $urlGenerator) {
parent::__construct($AppName, $request);
$this->urlGenerator = $urlGenerator;
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @return TemplateResponse
*/
public function showLibreOnline() {
$params = [
'urlGenerator' => $this->urlGenerator
];
$response = new TemplateResponse($this->appName, 'online', $params, 'blank');

$policy = new ContentSecurityPolicy();
$policy->addAllowedChildSrcDomain('*');
$policy->addAllowedScriptDomain("*");
$policy->addAllowedConnectDomain("*");
$policy->addAllowedStyleDomain("*");
$policy->addAllowedMediaDomain("*");
$policy->addAllowedFontDomain('*');
$policy->addAllowedImageDomain('*');
$policy->addAllowedFrameDomain('*');
$policy->addAllowedObjectDomain('*');
$policy->allowInlineScript(True);
$policy->allowInlineStyle(True);
$policy->allowEvalScript(True);
$response->setContentSecurityPolicy($policy);

return $response;
}

}
142 changes: 142 additions & 0 deletions js/viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
(function(OCA) {

OCA.LibreOnline = OCA.LibreOnline || {};
OCA.LibreOnline.Viewer = {


attach: function(fileList) {
this._extendFileActions(fileList.fileActions);
},

hide: function() {
$('#loframe').remove();
if ($('#isPublic').val() && $('#filesApp').val()){
$('#controls').removeClass('hidden');
}

FileList.setViewerMode(false);

$('#app-content #controls').removeClass('hidden');
},


show: function(downloadUrl, isFileList) {
var self = this;
var $iframe;
var viewer = OC.generateUrl('/apps/libreonline/?file={file}', {file: downloadUrl});
$iframe = $('<iframe id="loframe" style="width:100%;height:100%;display:block;position:absolute;top:0;" src="'+viewer+'" />');

if(isFileList === true) {
FileList.setViewerMode(true);
}

if ($('#isPublic').val()) {
$('#preview').append($iframe).css({height: '100%'});
$('body').css({height: '100%'});
$('footer').addClass('hidden');
$('#imgframe').addClass('hidden');
$('.directLink').addClass('hidden');
$('.directDownload').addClass('hidden');
$('#controls').addClass('hidden');
} else {
$('#app-content').append($iframe);
}

$("#pageWidthOption").attr("selected","selected");
$('#app-content #controls').addClass('hidden');

$('#loframe').load(function(){
var iframe = $('#loframe').contents();
if ($('#fileList').length) {
iframe.find('#secondaryToolbarClose').click(function() {
self.hide();
});
} else {
iframe.find("#secondaryToolbarClose").addClass('hidden');
}
});
},


_extendFileActions: function(fileActions) {


var self = this;

mimes = ['application/msword',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12',
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.template.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'application/vnd.oasis.opendocument.chart',
'application/vnd.oasis.opendocument.chart-template',
'application/vnd.oasis.opendocument.formula',
'application/vnd.oasis.opendocument.formula-template',
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.graphics-template',
'application/vnd.oasis.opendocument.image',
'application/vnd.oasis.opendocument.image-template',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.presentation-template',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet-template',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.text-master',
'application/vnd.oasis.opendocument.text-template',
'application/vnd.oasis.opendocument.text-web',
'application/vnd.oasis.opendocument.database',
]

for (var _mime in mimes){
fileActions.registerAction({
name: 'view',
displayName: 'Favorite',
mime: mimes[_mime],
permissions: OC.PERMISSION_READ,
actionHandler: function(fileName, context) {
var downloadUrl = '';
if($('#isPublic').val()) {
var sharingToken = $('#sharingToken').val();
downloadUrl = OC.generateUrl('/s/{token}/download?files={files}&path={path}', {
token: sharingToken,
files: fileName,
path: context.dir
});
} else {
downloadUrl = Files.getDownloadUrl(fileName, context.dir);
}
self.show(context.dir+ '/' + fileName, true);
}
});
fileActions.setDefault(mimes[_mime], 'view');
}

}
};

})(OCA);

if(!$.browser.msie || ($.browser.msie && $.browser.version >= 9)){
OC.Plugins.register('OCA.Files.FileList', OCA.LibreOnline.Viewer);
}
Loading

0 comments on commit 71981ff

Please sign in to comment.