diff options
author | Phie <phie@phie.ovh> | 2019-08-17 18:05:24 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2019-08-17 18:05:24 +0300 |
commit | 5e4a3a27430ab49517b365e120ca7bc2253eb2de (patch) | |
tree | ebc3966e0a931431edc46c91fb74e98184c77329 | |
parent | b0c8de086f72791512b4776dc03eda46834c6750 (diff) |
real fullscreen without loading all of nextcloud stuff
-rwxr-xr-x | lib/Controller/PageController.php | 13 | ||||
-rwxr-xr-x | templates/index.php | 10 | ||||
-rwxr-xr-x | templates/settings.php | 35 | ||||
-rwxr-xr-x | templates/writer.php | 4 |
4 files changed, 41 insertions, 21 deletions
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 163f02e..d4402c0 100755 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -32,6 +32,8 @@ class PageController extends Controller { 'carnet_display_fullscreen' => $this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no'), ]; $response = new TemplateResponse($this->appName,"index",$parameters); + if($this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no') === "yes") + $response->renderAs("blank"); $policy = new ContentSecurityPolicy(); $policy->addAllowedFrameDomain('\'self\''); $response->setContentSecurityPolicy($policy); // allow iframe @@ -43,10 +45,13 @@ class PageController extends Controller { * @NoCSRFRequired */ public function settings() { - $parameters = [ - 'carnet_display_fullscreen' => $this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no'), - ]; - return new TemplateResponse($this->appName,"settings", $parameters); // templates/writer.php + $parameters = [ + 'carnet_display_fullscreen' => $this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no'), + ]; + $response = new TemplateResponse($this->appName,"settings", $parameters); + if($this->config->getAppValue('carnet', 'carnetDisplayFullscreen', 'no') === "yes") + $response->renderAs("blank"); + return $response; } }
\ No newline at end of file diff --git a/templates/index.php b/templates/index.php index c64887e..957b7e2 100755 --- a/templates/index.php +++ b/templates/index.php @@ -1,6 +1,8 @@ <?php global $currentpath; global $root; +global $fullscreen; +$fullscreen = $_['carnet_display_fullscreen']; $currentpath = __DIR__."/CarnetElectron/"; $root = \OCP\Util::linkToAbsolute("carnet","templates"); $file = file_get_contents($currentpath."index.html"); @@ -14,13 +16,15 @@ $file = str_replace("href=\"","href=\"".$root."/CarnetElectron/",$file); $file = preg_replace_callback('/<script(.*?)src=\"(.*?\.js(?:\?.*?)?)"/s',function ($matches) { global $currentpath; - if($matches[2] === "libs/jquery.min.js") + global $fullscreen; + if($matches[2] === "libs/jquery.min.js" AND $fullscreen === "no") return "<script src=\"\""; return "<script".$matches[1]."src=\"".$matches[2]."?mtime=".filemtime($currentpath.$matches[2])."\""; }, $file); - +// token is needed to pass the csfr check +$file .= "<span style=\"display:none;\" id=\"token\">".$_['requesttoken']."</span>"; if($_['carnet_display_fullscreen']==="yes"){ - script("carnet","../templates/CarnetElectron/compatibility/nextcloud/browser_fullscreen"); + $file .= "<script src=\"compatibility/nextcloud/fullscreen.js?mtime=\"></script>"; if($_['nc_version']>=16) style("carnet","../templates/CarnetElectron/compatibility/nextcloud/nc16"); } diff --git a/templates/settings.php b/templates/settings.php index eec7a7d..454b55b 100755 --- a/templates/settings.php +++ b/templates/settings.php @@ -1,23 +1,32 @@ <?php - +global $fullscreen; +$fullscreen = $_['carnet_display_fullscreen']; $currentpath = __DIR__."/CarnetElectron/"; $root = \OCP\Util::linkToAbsolute("carnet","templates"); $root = parse_url($root, PHP_URL_PATH); $file = file_get_contents($currentpath."settings.html"); - -// $file = str_replace("href=\"","href=\"".$root."/CarnetElectron/",$file); - -preg_match_all('/<script.*?src=\"(.*?\.js(?:\?.*?)?)"/si', $file, $matches, PREG_PATTERN_ORDER); -for ($i = 0; $i < count($matches[1]); $i++) { - if($matches[1][$i] === "libs/jquery.min.js") - continue; - script("carnet","../templates/CarnetElectron/".substr($matches[1][$i],0,-3)); +$file = preg_replace_callback('/<script(.*?)src=\"(.*?\.js(?:\?.*?)?)"/s',function ($matches) { + global $currentpath; + if($matches[2] === "libs/jquery.min.js" AND $fullscreen === "no") + return "<script src=\"\""; + return "<script".$matches[1]."src=\"".$matches[2]."?mtime=".filemtime($currentpath.$matches[2])."\""; +}, $file); +// token is needed to pass the csfr check +$file .= "<span style=\"display:none;\" id=\"token\">".$_['requesttoken']."</span>"; +if($_['carnet_display_fullscreen']==="yes"){ + $file .= "<script src=\"compatibility/nextcloud/fullscreen.js?mtime=\"></script>"; + if($_['nc_version']>=16) + style("carnet","../templates/CarnetElectron/compatibility/nextcloud/nc16"); } -if($_['carnet_display_fullscreen']==="yes") - script("carnet","../templates/CarnetElectron/compatibility/nextcloud/browser_fullscreen"); -$file = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $file); -$file = str_replace("src=\"","defer src=\"".$root."/CarnetElectron/",$file); +else if($_['nc_version']>=14) + style("carnet","../templates/CarnetElectron/compatibility/nextcloud/nc14-header"); +$nonce = ""; +if (method_exists(\OC::$server, "getContentSecurityPolicyNonceManager")){ + $nonce = \OC::$server->getContentSecurityPolicyNonceManager()->getNonce(); +} +$file = str_replace("src=\"","defer nonce='".$nonce."' src=\"".$root."/CarnetElectron/",$file); echo $file; echo "<span style=\"display:none;\" id=\"root-url\">".$root."/CarnetElectron/</span>"; +echo "<span style=\"display:none;\" id=\"logout-token\">".urlencode(\OCP\Util::callRegister())."</span>"; ?> diff --git a/templates/writer.php b/templates/writer.php index c4f90c4..56eec7a 100755 --- a/templates/writer.php +++ b/templates/writer.php @@ -22,9 +22,11 @@ $file = preg_replace_callback('/<link(.*?)href=\"(.*?\.css(?:\?.*?)?)"/s',functi $relativePath = str_replace("<!ROOTPATH>", "", $matches[2]); return "<link".$matches[1]."href=\"".$src."?mtime=".filemtime($currentpath.$relativePath)."\""; }, $file); +// token is needed to pass the csfr check +$file .= "<span style=\"display:none;\" id=\"token\">".$_['requesttoken']."</span>"; +$file .= "<script src=\"".$root."/CarnetElectron/compatibility/nextcloud/fullscreen.js?mtime=\"></script>"; $file = str_replace("<!ROOTPATH>", $root."/CarnetElectron/", $file); - $root = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT'])); $urlGenerator = \OC::$server->getURLGenerator(); $file = str_replace("<!ROOTURL>", $root."/CarnetElectron/", $file); |