Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preview for documents like odp ods odt #1

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 46 additions & 33 deletions modules/doc/mod_doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@

define('DOCTYPE_PDF', 'DOCTYPE_PDF');
define('DOCTYPE_ODF', 'DOCTYPE_ODF');
define('DOCTYPE_ODT', 'DOCTYPE_ODT');
define('DOCTYPE_ODP', 'DOCTYPE_ODP');
define('DOCTYPE_ODS', 'DOCTYPE_ODS');
define('DOCTYPE_HTML', 'DOCTYPE_HTML');
define('DOCTYPE_TEXT', 'DOCTYPE_TEXT');
define('DOCTYPE_UNKNOWN', 'DOCTYPE_UNKNOWN');
define('VIEWER_JS_PATH', 'vendor/viewerjs/ViewerJS/index.html#');

/**
* This module handles documents of type pdf and odf (the basic odf formats) assigned in db
Expand All @@ -55,7 +59,7 @@ public function __construct($Name, ESRender_Application_Interface $RenderApplica
}

protected function renderTemplate($TemplateName, $showMetadata = true) {

global $MC_URL;
$template_data = parent::prepareRenderData($showMetadata);
$template_data['previewUrl'] = $this -> esObject->getPreviewUrl();

Expand All @@ -65,7 +69,13 @@ protected function renderTemplate($TemplateName, $showMetadata = true) {
$template_data['content'] = $this -> esObject -> getPath() . '?' . session_name() . '=' . session_id().'&token=' . Config::get('token');
$template_data['url'] = $this -> esObject->getPath() . '?' . session_name() . '=' . session_id() . '&token=' . Config::get('token');
}

if($this->getDoctype() == DOCTYPE_ODT || $this->getDoctype() == DOCTYPE_ODS || $this->getDoctype() == DOCTYPE_ODP) {
$urlFile= $this -> esObject->getPath() . '?' . session_name() . '=' . session_id() . '&token=' . Config::get('token');
$template_data['title'] =$this->esObject->getTitle();
$template_data['url'] = $urlFile;
$template_data['urlEmbeded'] = $MC_URL.DIRECTORY_SEPARATOR.VIEWER_JS_PATH.$urlFile;
$template_data['objectId'] = $this -> esObject ->getObjectID();
}
if($this->getDoctype() == DOCTYPE_HTML) {
$template_data['content'] = file_get_contents($this->getCacheFileName() . '_purified.html');
}
Expand Down Expand Up @@ -124,6 +134,10 @@ final protected function dynamic() {
echo $this -> renderTemplate($this -> getThemeByDoctype().'dynamic');
return true;
}
else if($this->getDoctype() === DOCTYPE_ODT || $this->getDoctype() === DOCTYPE_ODS || $this->getDoctype() === DOCTYPE_ODP) {
echo $this -> renderTemplate($this -> getThemeByDoctype().'dynamic');
return true;
}
else return parent::dynamic();
}

Expand Down Expand Up @@ -156,6 +170,15 @@ protected function getThemeByDoctype() {
case DOCTYPE_ODF :
return '/module/doc/odf/';
break;
case DOCTYPE_ODT :
return '/module/doc/odt/';
break;
case DOCTYPE_ODP :
return '/module/doc/odp/';
break;
case DOCTYPE_ODS :
return '/module/doc/ods/';
break;
default :
return '';
}
Expand All @@ -173,19 +196,18 @@ protected function setDoctype() {
$this->doctype = DOCTYPE_TEXT;
else if(strpos($this -> esObject -> getMimeType(), 'application/pdf') !== false)
$this->doctype = DOCTYPE_PDF;
else if(strpos($this -> esObject -> getMimeType(), 'application/vnd.sun.xml.writer') !== false ||
strpos($this -> esObject -> getMimeType(), 'application/vnd.oasis.opendocument.text') !== false)
$this->doctype = DOCTYPE_ODT;
else if(strpos($this -> esObject -> getMimeType(), 'application/vnd.sun.xml.impress') !== false ||
strpos($this -> esObject -> getMimeType(), 'application/vnd.oasis.opendocument.presentation') !== false)
$this->doctype = DOCTYPE_ODP;
else if(strpos($this -> esObject -> getMimeType(), 'application/vnd.sun.xml.calc') !== false ||
strpos($this -> esObject -> getMimeType(), 'pplication/vnd.oasis.opendocument.spreadsheet') !== false)
$this->doctype = DOCTYPE_ODS;
else
$this -> doctype = DOCTYPE_UNKNOWN;
return;
/*

if (strpos($this -> esObject -> getMimeType(), 'opendocument') !== false) {
$this -> doctype = DOCTYPE_UNKNOWN;
$this -> doctype = DOCTYPE_ODF;
} else if (strpos($this -> esObject -> getMimeType(), 'pdf') !== false) {
$this -> doctype = DOCTYPE_PDF;
} else {
$this -> doctype = DOCTYPE_UNKNOWN;
}*/
}

/**
Expand All @@ -211,36 +233,27 @@ public function process($p_kind, $locked=null) {

public function requestingDeviceCanRenderContent() {
switch($this->getDoctype()) {
case DOCTYPE_PDF :
case DOCTYPE_PDF:
return true;
break;
case DOCTYPE_ODF :
case DOCTYPE_ODF:
return true;
break;
case DOCTYPE_HTML:
return true;
break;
default :
return false;
}
}

/* public function checkPdfUserAgents() {
global $requestingDevice;
switch($requestingDevice -> getCapability('model_name')) {
case 'Chrome':
case 'Firefox':
case DOCTYPE_ODT:
return true;
break;
case 'Internet Explorer':
if((float)$requestingDevice -> getCapability('mobile_browser_version') > 10)
return true;
else
return false;
break;
default:
case DOCTYPE_ODP:
return true;
break;
case DOCTYPE_ODS:
return true;
break;
default :
return false;
}
}*/
}

}
}
1 change: 1 addition & 0 deletions theme/default/module/doc/odp/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALLOW FROM ALL
43 changes: 43 additions & 0 deletions theme/default/module/doc/odp/css/loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#loadingSpin {
border: 9px solid #f3f3f3;
border-radius: 50%;
border-top: 9px solid #3498db;
width: 100px;
height: 100px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
margin-left: 47%;
margin-bottom: 3%;
}

/* Safari */
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

.edusharing_rendering_content_wrapper {
height: 0px;
}

#edusharing_rendering_content_embedded {
/* display: none; */
visibility: hidden;
}

#edusharing_downloadadvice {
display: none;
}
73 changes: 73 additions & 0 deletions theme/default/module/doc/odp/dynamic.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
global $Locale, $Translate,$MC_URL;
$msg = array();
// $msg['toDownload'] = new Phools_Message_Default('toDownload');
$msg['cannotOpenObject'] = new Phools_Message_Default('cannotOpenObject');
$msg['cannotOpenObjectText'] = new Phools_Message_Default('cannotOpenObjectText');
?>
<html>
<head>
<style>
<?php include(dirname(__FILE__) . '/../../../css/dynamic.php'); ?>
<?php include(dirname(__FILE__) . '/../../../css/metadata.css'); ?>
<?php include(dirname(__FILE__) . '/css/loading.css'); ?>
</style>
<script src="<?php echo $MC_URL?>/vendor/js/getJS.php"></script>
</head>
<body>
<div class="edusharing_rendering_wrapper" vocab="http://schema.org/" typeof="WebPage">
<h1 class="edusharing_rendering_content_title"><?php echo $title ?></h1>
<div id="loadingSpin" class="loadingSpin"></div>
<div id="edusharing_rendering_content_wrapper" class="edusharing_rendering_content_wrapper" role="main">
<div id="edusharing_rendering_content_embedded" class="edusharing_rendering_content edusharing_rendering_content_embedded">
<iframe title="<?php echo $title;?>" src="<?php echo $urlEmbeded ?>"
width="100%" height="100%" style="border: none;"
allowfullscreen
webkitallowfullscreen>
</iframe>
</div>

<div id="edusharing_downloadadvice">
<img class="edusharing_rendering_content_preview" src="<?php echo $previewUrl?>">
<h3><?php echo $msg['cannotOpenObject']->localize($Locale, $Translate); ?> </h3>
<h4><?php echo $msg['cannotOpenObjectText']->localize($Locale, $Translate); ?></h4>
</div>

</div>
<?php echo $metadata; ?>
</div>
</body>
<script>
// --------------------------- BEGGIN IFRAME ----------------------------------------//

// Create IE + others compatible event handler
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

// Listen to message from child window
window.addEventListener(messageEvent,renderDocument,false);

function renderDocument(e) {
if(e.data.name === 'renderLibreOffice' && e.data.value === true){
document.getElementById("loadingSpin").style.display="none";
document.getElementById("edusharing_rendering_content_embedded").style.visibility="visible";
document.getElementById("edusharing_rendering_content_wrapper").style.height="100%";
window.removeEventListener(messageEvent,renderDocument,false);
}else if(e.data.name==="errorRenderLibreOffice"){
document.getElementById("loadingSpin").style.display="none";
document.getElementById("edusharing_rendering_content_embedded").style.display="none";
document.getElementById("edusharing_rendering_content_wrapper").style.height="100%";
document.getElementById("edusharing_downloadadvice").style.display="block";
} else{
return;
}
}


// --------------------------- END IFRAME ----------------------------------------//
</script>
</html>



1 change: 1 addition & 0 deletions theme/default/module/doc/ods/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALLOW FROM ALL
43 changes: 43 additions & 0 deletions theme/default/module/doc/ods/css/loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#loadingSpin {
border: 9px solid #f3f3f3;
border-radius: 50%;
border-top: 9px solid #3498db;
width: 100px;
height: 100px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
margin-left: 47%;
margin-bottom: 3%;
}

/* Safari */
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

.edusharing_rendering_content_wrapper {
height: 0px;
}

#edusharing_rendering_content_embedded {
/* display: none; */
visibility: hidden;
}

#edusharing_downloadadvice {
display: none;
}
73 changes: 73 additions & 0 deletions theme/default/module/doc/ods/dynamic.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
global $Locale, $Translate,$MC_URL;
$msg = array();
// $msg['toDownload'] = new Phools_Message_Default('toDownload');
$msg['cannotOpenObject'] = new Phools_Message_Default('cannotOpenObject');
$msg['cannotOpenObjectText'] = new Phools_Message_Default('cannotOpenObjectText');
?>
<html>
<head>
<style>
<?php include(dirname(__FILE__) . '/../../../css/dynamic.php'); ?>
<?php include(dirname(__FILE__) . '/../../../css/metadata.css'); ?>
<?php include(dirname(__FILE__) . '/css/loading.css'); ?>
</style>
<script src="<?php echo $MC_URL?>/vendor/js/getJS.php"></script>
</head>
<body>
<div class="edusharing_rendering_wrapper" vocab="http://schema.org/" typeof="WebPage">
<h1 class="edusharing_rendering_content_title"><?php echo $title ?></h1>
<div id="loadingSpin" class="loadingSpin"></div>
<div id="edusharing_rendering_content_wrapper" class="edusharing_rendering_content_wrapper" role="main">
<div id="edusharing_rendering_content_embedded" class="edusharing_rendering_content edusharing_rendering_content_embedded">
<iframe title="<?php echo $title;?>" src="<?php echo $urlEmbeded ?>"
width="100%" height="100%" style="border: none;"
allowfullscreen
webkitallowfullscreen>
</iframe>
</div>

<div id="edusharing_downloadadvice">
<img class="edusharing_rendering_content_preview" src="<?php echo $previewUrl?>">
<h3><?php echo $msg['cannotOpenObject']->localize($Locale, $Translate); ?> </h3>
<h4><?php echo $msg['cannotOpenObjectText']->localize($Locale, $Translate); ?></h4>
</div>

</div>
<?php echo $metadata; ?>
</div>
</body>
<script>
// --------------------------- BEGGIN IFRAME ----------------------------------------//

// Create IE + others compatible event handler
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

// Listen to message from child window
window.addEventListener(messageEvent,renderDocument,false);

function renderDocument(e) {
if(e.data.name === 'renderLibreOffice' && e.data.value === true){
document.getElementById("loadingSpin").style.display="none";
document.getElementById("edusharing_rendering_content_embedded").style.visibility="visible";
document.getElementById("edusharing_rendering_content_wrapper").style.height="100%";
window.removeEventListener(messageEvent,renderDocument,false);
}else if(e.data.name==="errorRenderLibreOffice"){
document.getElementById("loadingSpin").style.display="none";
document.getElementById("edusharing_rendering_content_embedded").style.display="none";
document.getElementById("edusharing_rendering_content_wrapper").style.height="100%";
document.getElementById("edusharing_downloadadvice").style.display="block";
} else{
return;
}
}


// --------------------------- END IFRAME ----------------------------------------//
</script>
</html>



1 change: 1 addition & 0 deletions theme/default/module/doc/odt/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALLOW FROM ALL
Loading