-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
14 changed files
with
151 additions
and
45 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
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
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,66 @@ | ||
<?php | ||
|
||
namespace YesWiki\Publication\Controller; | ||
|
||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use YesWiki\Core\YesWikiController; | ||
use YesWiki\Publication\Service\PdfHelper; | ||
use YesWiki\Publication\Service\SessionManager; | ||
use YesWiki\Wiki; | ||
|
||
class PdfController extends YesWikiController | ||
{ | ||
protected $params; | ||
protected $pdfHelper; | ||
|
||
public function __construct( | ||
ParameterBagInterface $params, | ||
PdfHelper $pdfHelper, | ||
Wiki $wiki, | ||
) { | ||
$this->params = $params; | ||
$this->pdfHelper = $pdfHelper; | ||
$this->wiki = $wiki; | ||
} | ||
|
||
public function run(bool $inIframe = false) | ||
{ | ||
if (!empty($_GET['url']) && is_string($_GET['url']) && | ||
!empty($_GET['urlPageTag']) && is_string($_GET['urlPageTag']) && | ||
!empty($_GET['hash']) && is_string($_GET['hash'])) { | ||
// redirect to api | ||
if (!method_exists($this->wiki, 'isCli') || !$this->wiki->isCli()) { | ||
header('Access-Control-Allow-Origin: *'); | ||
header('Access-Control-Expose-Headers: Location, Slug, Accept, Content-Type'); | ||
} | ||
$filteredParams = array_filter($_GET, function ($v, $k) { | ||
return in_array($k, ['url','urlPageTag','hash','refresh','forceNewFormat','via','template-page'], true) && is_scalar($v); | ||
}, ARRAY_FILTER8USE_BOTH); | ||
$this->wiki->redirect($this->wiki->href('', 'api/pdf/getPdf', $filteredParams + [ | ||
'fromOldPath' => '1' | ||
], false)); | ||
} | ||
|
||
list( | ||
'pageTag'=>$pageTag, | ||
'sourceUrl'=>$sourceUrl, | ||
'hash'=>$hash, | ||
) = | ||
$this->pdfHelper->getSourceUrl($_GET ?? [], $_SERVER ?? []); | ||
|
||
$method = $inIframe ? 'render' : 'renderInSquelette'; | ||
|
||
return $this->$method('@publication/handler-pdf.twig', [ | ||
'isAdmin' => $this->wiki->UserIsAdmin(), | ||
'isIframe' => $inIframe, | ||
'pageTag' => $pageTag, | ||
'sourceUrl' => $sourceUrl, | ||
'hash' => $hash, | ||
'urls' => [ | ||
'local' => $this->pdfHelper->canExecChromium() ? $this->wiki->href('', 'api/pdf/getPdf') : '', | ||
'external' => empty($this->params->get('htmltopdf_service_url')) ? '' : $this->params->get('htmltopdf_service_url'), | ||
], | ||
'refresh' => in_array($_GET['refresh'] ?? false, [1,"1",true,"true"], true), | ||
]); | ||
} | ||
} |
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
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
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
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,55 @@ | ||
<?php | ||
|
||
namespace YesWiki\Publication; | ||
|
||
use YesWiki\Core\YesWikiHandler; | ||
use YesWiki\Publication\Controller\PdfController; | ||
|
||
class PdfIframeHandler extends YesWikiHandler | ||
{ | ||
public function run() | ||
{ | ||
if ($this->wiki->UserIsAdmin() && | ||
!in_array( | ||
'pdfiframe', | ||
is_array($this->params->get('allowed_methods_in_iframe')) ? $this->params->get('allowed_methods_in_iframe') : [] | ||
) | ||
) { | ||
// allow local ('self') and everyone (*) to allow display error message | ||
if (!$this->wiki->isCli() && !headers_sent()) { | ||
header("Content-Security-Policy: frame-ancestors 'self' *;"); | ||
} | ||
|
||
return $this->displayInIframe($this->render('@templates/alert-message.twig', [ | ||
'type' => 'danger', | ||
'message' => _t('PUBLICATION_IFRAME_NOT_SET', [ | ||
'gererConfigLink' => "<a href=\"{$this->wiki->href('iframe', 'GererConfig')}\">GererConfig</a>" | ||
]) | ||
])); | ||
} | ||
return $this->displayInIframe($this->getService(PdfController::class)->run(true)); | ||
} | ||
|
||
protected function displayInIframe(string $content) | ||
{ | ||
$output = <<<HTML | ||
<body class="yeswiki-iframe-body login-body"> | ||
<div class="container"> | ||
<div class="yeswiki-page-widget page-widget page" {$this->wiki->Format('{{doubleclic iframe="1"}}')}> | ||
$content | ||
</div><!-- end .page-widget --> | ||
</div><!-- end .container --> | ||
HTML; | ||
// common footer for all iframe page | ||
|
||
$this->wiki->AddJavascriptFile('tools/templates/libs/vendor/iframeResizer.contentWindow.min.js'); | ||
|
||
// on recupere les entetes html mais pas ce qu'il y a dans le body | ||
$header = explode('<body', $this->wiki->Header()); | ||
$output = $header[0].$output; | ||
// on recupere juste les javascripts et la fin des balises body et html | ||
$output .= preg_replace('/^.+<script/Us', '<script', $this->wiki->Footer()); | ||
|
||
return $output; | ||
} | ||
} |
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
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
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
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
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
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
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