-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a356fe
commit c5bca2e
Showing
8 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
// Check if we are a user | ||
OCP\JSON::checkLoggedIn(); | ||
OCP\JSON::callCheck(); | ||
|
||
\OC::$server->getSession()->close(); | ||
|
||
// Set the session key for the file we are about to edit. | ||
$dir = isset($_GET['dir']) ? $_GET['dir'] : ''; | ||
$filename = isset($_GET['file']) ? $_GET['file'] : ''; | ||
$token = isset($_GET['token']) ? $_GET['token'] : ''; | ||
if(!empty($filename)) | ||
{ | ||
header('Content-Type: application/pdf'); | ||
|
||
if(!empty($token)) | ||
{ | ||
$linkItem = \OC::$server->getShareManager()->getShareByToken($token); | ||
$owner = $linkItem->getShareOwner(); | ||
\OC\Files\Filesystem::init($owner, '/' . $owner . '/files'); | ||
$dir = '/' . \OC\Files\Filesystem::getPath($linkItem->getNodeId()); | ||
$dir = rtrim($dir, '/'); | ||
} | ||
|
||
$path = $dir.'/'.$filename; | ||
$filecontents = \OC\Files\Filesystem::file_get_contents($path); | ||
|
||
if($filecontents) | ||
{ | ||
echo $filecontents; | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('files_pdfviewer', 'Error when opening PDF ' . $path, \OCP\Util::ERROR); | ||
OCP\JSON::error(['data' => ['message' => 'A problem occoured while loading the PDF']]); | ||
} | ||
return; | ||
|
||
} | ||
else | ||
{ | ||
OCP\JSON::error(['data' => ['message' => 'Invalid file path supplied.']]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
// Check if we are a user | ||
//OCP\JSON::checkLoggedIn(); | ||
OCP\JSON::callCheck(); | ||
|
||
\OC::$server->getSession()->close(); | ||
|
||
// Set the session key for the file we are about to edit. | ||
$token = isset($_GET['token']) ? $_GET['token'] : ''; | ||
if(!empty($token)) | ||
{ | ||
header('Content-Type: application/pdf'); | ||
|
||
$linkItem = \OC::$server->getShareManager()->getShareByToken($token); | ||
$owner = $linkItem->getShareOwner(); | ||
|
||
\OC\Files\Filesystem::tearDown(); | ||
\OC\Files\Filesystem::init($owner, '/' . $owner . '/files'); | ||
|
||
$path = '/' . \OC\Files\Filesystem::getPath($linkItem->getNodeId()); | ||
|
||
$filecontents = \OC\Files\Filesystem::file_get_contents($path); | ||
|
||
if($filecontents) | ||
{ | ||
echo $filecontents; | ||
} | ||
else | ||
{ | ||
\OCP\Util::writeLog('files_nbviewer', 'Error while opening PDF ' . $path, \OCP\Util::ERROR); | ||
OCP\JSON::error(['data' => ['message' => 'A problem occoured while loading the PDF']]); | ||
} | ||
return; | ||
|
||
} else { | ||
OCP\JSON::error(['data' => ['message' => 'Invalid file path supplied.']]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
OCP\Util::addscript('files_pdfviewer', 'pdfobject.min'); | ||
OCP\Util::addscript('files_pdfviewer', 'app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<info> | ||
<id>files_nbviewer</id> | ||
<name>CERNBox NB Viewer</name> | ||
<description>This application integrates the IPython/Jupyter Notebook framework into CERNBox files application</description> | ||
<licence>AGPL</licence> | ||
<author>Nadir Roman Guerrero</author> | ||
<requiremin>8.2.0</requiremin> | ||
<shipped>true</shipped> | ||
<default_enable/> | ||
</info> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
/** @var $this OC\Route\Router */ | ||
$this->create('files_pdfviewer_load', '/ajax/loadfile.php') | ||
->actionInclude('files_pdfviewer/ajax/loadfile.php'); | ||
|
||
$this->create('files_pdfviewer_loadpublic', '/ajax/loadpublicfile.php') | ||
->actionInclude('files_pdfviewer/ajax/loadpublicfile.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
function PDF_closePublicFileCallback() | ||
{ | ||
$('#imgframe').empty(); | ||
$('#imgframe').text('Reloading...'); | ||
window.location.reload(); | ||
} | ||
|
||
function PDF_loadFile(file, dir) | ||
{ | ||
var urlD = OC.filePath('files_pdfviewer', 'ajax', 'loadfile.php') + "?file=" + encodeURIComponent(file) | ||
+ "&dir=" + encodeURIComponent(dir) + "&requesttoken=" + encodeURIComponent(oc_requesttoken); | ||
|
||
if($('#isPublic').attr('value') == '1') | ||
{ | ||
urlD = urlD + "&token=" + encodeURIComponent($('#sharingToken').attr('value')); | ||
} | ||
|
||
$('#pdfviewer-loader').remove(); | ||
|
||
var frame = $('#pdfviewer-frame'); | ||
frame.attr('type', 'application/pdf'); | ||
frame.attr('src', urlD); | ||
frame.contents().find('title').html(file); | ||
frame.on('load', function() | ||
{ | ||
document.title = file; | ||
}); | ||
} | ||
|
||
function PDF_loadPublicFile(token) | ||
{ | ||
var urlD = OC.filePath('files_pdfviewer', 'ajax', 'loadpublicfile.php') + "?token=" + encodeURIComponent(token) | ||
+ "&requesttoken=" + encodeURIComponent(oc_requesttoken); | ||
|
||
$('#pdfviewer-loader').remove(); | ||
|
||
var frame = $('#pdfviewer-frame'); | ||
frame.attr('type', 'application/pdf'); | ||
frame.attr('src', urlD); | ||
} | ||
|
||
/** | ||
* Set up all html elements needed to display the notebook | ||
*/ | ||
function PDF_setUpEditor(closeCallBack) | ||
{ | ||
isPDFViewerOpen = true; | ||
var mainDiv = $('#pdfviewer'); | ||
if(mainDiv.length < 1) | ||
{ | ||
mainDiv = $('<div id="pdfviewer"></div>'); | ||
mainDiv.css('position', 'absolute'); | ||
mainDiv.css('top', '0'); | ||
mainDiv.css('left', '0'); | ||
mainDiv.css('width', '100%'); | ||
mainDiv.css('height', '100%'); | ||
mainDiv.css('z-index', '200'); | ||
mainDiv.css('background-color', '#fff'); | ||
|
||
var frame = $('<iframe id="pdfviewer-frame"></iframe>'); | ||
frame.css('position', 'absolute'); | ||
frame.css('top', '0'); | ||
frame.css('left', '0'); | ||
frame.css('width', '100%'); | ||
frame.css('height', '100%'); | ||
|
||
mainDiv.append(frame); | ||
$('#content').append(mainDiv); | ||
} | ||
|
||
var loadingImg = $('<div id="pdfviewer-loader"></div>'); | ||
loadingImg.css('position', 'absolute'); | ||
loadingImg.css('top', '50%'); | ||
loadingImg.css('left', '50%'); | ||
loadingImg.css('width', 'auto'); | ||
loadingImg.css('height', 'auto'); | ||
var img = OC.imagePath('core', 'loading-dark.gif'); | ||
var imgContent = $('<img></img>'); | ||
imgContent.attr('src',img); | ||
loadingImg.append(imgContent); | ||
|
||
var closeButton = $('<div></div>'); | ||
closeButton.css('position', 'absolute'); | ||
closeButton.css('top', '0'); | ||
closeButton.css('left', '95%'); | ||
closeButton.css('width', 'auto'); | ||
closeButton.css('height', 'auto'); | ||
closeButton.css('z-index', '200'); | ||
closeButton.css('background-color', '#f00'); | ||
var closeImg = OC.imagePath('core', 'actions/close.svg'); | ||
var closeImgContent = $('<img></img>'); | ||
closeImgContent.attr('src', closeImg); | ||
closeButton.append(closeImgContent); | ||
|
||
closeButton.click(function() { PDF_closeFile(closeCallBack); }); | ||
|
||
$('#app-navigation').hide(); | ||
$('#app-content').hide(); | ||
|
||
mainDiv.append(loadingImg); | ||
mainDiv.append(closeButton); | ||
} | ||
|
||
/** | ||
* Open the notebook viewer and displays the notebook given the directory where it belongs and it's name | ||
* @param directory | ||
* @param file | ||
*/ | ||
function PDF_openFile(directory, file) | ||
{ | ||
PDF_setUpEditor(); | ||
PDF_loadFile(file, directory); | ||
} | ||
|
||
/** | ||
* Open the notebook viewer and displays the notebook given by a publically shared by link | ||
* @param token | ||
*/ | ||
function PDF_openPublicFile(token) | ||
{ | ||
PDF_setUpEditor(closePublicFileCallback); | ||
PDF_loadPublicFile(token); | ||
} | ||
|
||
|
||
function PDF_closeFile(callback) | ||
{ | ||
if(isPDFViewerOpen) | ||
{ | ||
$('#pdfviewer').remove(); | ||
$('#app-navigation').show(); | ||
$('#app-content').show(); | ||
isPDFViewerOpen = false; | ||
|
||
if(callback) | ||
{ | ||
callback(); | ||
} | ||
} | ||
} | ||
|
||
var isPDFViewerOpen = false; | ||
$(document).ready(function () | ||
{ | ||
if (typeof FileActions !== 'undefined') | ||
{ | ||
FileActions.setDefault('application/pdf', 'Edit'); | ||
OCA.Files.fileActions.register('application/pdf', 'Edit', OC.PERMISSION_READ, '', function (filename) | ||
{ | ||
PDF_openFile(FileList.getCurrentDirectory(), filename); | ||
}); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.