Skip to content

Commit

Permalink
fix(publication): regex to pass queries to preview
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflos committed Mar 13, 2024
1 parent 7de4840 commit 93a63ad
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 240 deletions.
2 changes: 1 addition & 1 deletion actions/BarreRedactionAction__.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function run()
$this->render(
'@bazar/entries/_publication_button.twig',
[
'forPage'=>true
'forPage' => true
]
)."\n".'</div>',
$this->output
Expand Down
4 changes: 2 additions & 2 deletions actions/Bazar2PublicationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function run()
unset($queries['wiki']);
}
$href = $this->wiki->Href('pdf'.testUrlInIframe(), null, $queries// merge GET with wiki and following params
+[
+ [
'via' => 'bazarliste',
'template-page' => $this->arguments['templatepage'],
]+(
] + (
empty($this->arguments['excludedfields'])
? []
: [
Expand Down
12 changes: 6 additions & 6 deletions actions/PublicationGeneratorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function formatArguments($args)

return $deprecatedParameters + [
'outputformat' => $this->formatString($args, 'outputformat', 'ebook'),
'formid' => (!empty($args['formid']) && is_scalar($args['formid']) && intval($args['formid'])>0) ? strval($args['formid']) : '',
'formid' => (!empty($args['formid']) && is_scalar($args['formid']) && intval($args['formid']) > 0) ? strval($args['formid']) : '',
// Indicates if fields and elements are "read only"
'readonly' => isset($args['readonly']) && in_array($args['readonly'], ['',true], true),
// Pages used for intro and outro
Expand Down Expand Up @@ -87,9 +87,9 @@ public function run()

list(
'ebookPageName' => $ebookPageName,
'selectedPages'=>$selectedPages,
'publicationStart'=>$publicationStart,
'publicationEnd'=>$publicationEnd,
'selectedPages' => $selectedPages,
'publicationStart' => $publicationStart,
'publicationEnd' => $publicationEnd,
) = $this->getEbookPageName($results);

try {
Expand Down Expand Up @@ -358,7 +358,7 @@ protected function managePost(array $post, array &$messages, string $ebookPageNa
)) {
// there is no publication-cover-image
$messages[] = [
'message' =>_t('PUBLICATION_NOT_IMAGE_FILE'),
'message' => _t('PUBLICATION_NOT_IMAGE_FILE'),
'type' => 'danger'
];
} else {
Expand Down Expand Up @@ -432,7 +432,7 @@ protected function managePost(array $post, array &$messages, string $ebookPageNa
$fiche = $this->entryManager->create($this->arguments['formid'], $fiche);
if (!empty($fiche)) {
$messages[] = [
'message' =>_t('PUBLICATION_NEWSLETTER_CREATED'),
'message' => _t('PUBLICATION_NEWSLETTER_CREATED'),
'type' => 'success'
];
} else {
Expand Down
22 changes: 11 additions & 11 deletions controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getStatus($uuid)
return new ApiResponse($status, Response::HTTP_OK);
}

/**
/**
* @Route("/api/pdf/getTmpCookie",methods={"GET"}, options={"acl":{"public","+"}},priority=2)
*/
public function getTmpCookie()
Expand Down Expand Up @@ -77,11 +77,11 @@ public function getPdf()
$this->pdfHelper->prepareSession($uuid);

list(
'pageTag'=>$pageTag,
'sourceUrl'=>$sourceUrl,
'hash'=>$hash,
'dlFilename'=>$dlFilename,
'fullFilename'=>$fullFilename
'pageTag' => $pageTag,
'sourceUrl' => $sourceUrl,
'hash' => $hash,
'dlFilename' => $dlFilename,
'fullFilename' => $fullFilename
) =
$this->pdfHelper->getFullFileName(
$_GET ?? [],
Expand All @@ -94,7 +94,7 @@ public function getPdf()
$file_exists = file_exists($fullFilename);
$this->pdfHelper->setValueInSession($uuid, PdfHelper::SESSION_FILE_STATUS, $file_exists ? 1 : 0);
if (!$file_exists
|| ($file_exists && $this->wiki->UserIsAdmin() && isset($_GET['refresh']) && $_GET['refresh']==1)
|| ($file_exists && $this->wiki->UserIsAdmin() && isset($_GET['refresh']) && $_GET['refresh'] == 1)
) {
$this->pdfHelper->useBrowserToCreatePdfFromPage($sourceUrl, $fullFilename, $uuid, $cookies);
}
Expand All @@ -116,7 +116,7 @@ public function getPdf()
if ($isOld && !$forceNewFormat) {
if (isset($cause['canExecChromium']) && $cause['canExecChromium'] === false) {
$output = $this->renderInSquelette('@templates/alert-message.twig', [
'type'=> 'danger',
'type' => 'danger',
'message' => _t('PUBLICATION_NO_EXECUTABLE_FILE_FOUND_ON_PATH').' : '
.$this->params->get('htmltopdf_path').'<br />'
._t('PUBLICATION_DID_YOU_INSTALL_CHROMIUM_OR_SET_UP_PATH')
Expand All @@ -125,22 +125,22 @@ public function getPdf()
}
if (isset($cause['domainAuthorized']) && $cause['domainAuthorized'] === false) {
$output = $this->renderInSquelette('@templates/alert-message.twig', [
'type'=> 'danger',
'type' => 'danger',
'message' => _t('PUBLICATION_DOMAIN_NOT_AUTORIZED').' : '.parse_url($_GET['url'] ?? '', PHP_URL_HOST),
]);
return new Response($output, Response::HTTP_OK);
}
if (isset($cause['pdfCreationError']) && $cause['pdfCreationError'] === true) {
$output = $this->renderInSquelette('@publication/old-error-message.twig', [
'sourceUrl'=> $_GET['url'] ?? '',
'sourceUrl' => $_GET['url'] ?? '',
'message' => $ex->getMessage(),
'html' => $cause['pdfCreationErrorHTML'] ?? ''
]);
return new Response($output, Response::HTTP_OK);
}
}
return new ApiResponse([
'error'=>true,
'error' => true,
'cause' => $cause
], Response::HTTP_INTERNAL_SERVER_ERROR);
} else {
Expand Down
109 changes: 54 additions & 55 deletions controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,69 @@
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;
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'])
public function __construct(
ParameterBagInterface $params,
PdfHelper $pdfHelper,
Wiki $wiki
) {
// 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_FILTER_USE_BOTH);
$this->wiki->redirect($this->wiki->href('', 'api/pdf/getPdf', $filteredParams + [
'fromOldPath' => '1'
], false));
$this->params = $params;
$this->pdfHelper = $pdfHelper;
$this->wiki = $wiki;
}

list(
'pageTag' => $pageTag,
'sourceUrl' => $sourceUrl,
'hash' => $hash,
) =
$this->pdfHelper->getSourceUrl($_GET ?? [], $_SERVER ?? []);
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_FILTER_USE_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';
$method = $inIframe ? 'render' : 'renderInSquelette';

// simplier handler for client rendering
if (!$this->pdfHelper->canExecChromium()) {
$this->wiki->redirect($sourceUrl . '&browserPrintAfterRendered=1');
return;
} else {
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),
]);
// simplier handler for client rendering
if (!$this->pdfHelper->canExecChromium()) {
$this->wiki->redirect($sourceUrl . '&browserPrintAfterRendered=1');
return;
} else {
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),
]);
}
}
}
}
3 changes: 1 addition & 2 deletions handlers/PreviewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ protected function getContentAndPublication(array $get): array
// backward compatibilty
if (preg_match('#{{\s*bazar.+id="(.+)".+}}#siU', $this->wiki->page['body'], $matches)) {
list(, $formId) = $matches;

$query = $get['query'] ?? '';

$results = $this->entryManager->search(['query' => $query, 'formsIds' => [$formId]]);
Expand All @@ -120,7 +119,7 @@ protected function getContentAndPublication(array $get): array
$actionName = $matches[2];
$matches = [];
$params = [];
preg_match_all('/([a-zA-Z0-9_]*)=\"(.*)\"/U', $actionText, $matches);
preg_match_all('/([a-zA-Z0-9_]*)=\\\\?\"(.*)\\\\?\"/mU', $actionText, $matches);
foreach ($matches[0] as $id => $match) {
$params[$matches[1][$id]] = $matches[2][$id];
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/ShowHandler__.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ShowHandler__ extends YesWikiHandler
public function run()
{
if ($this->getService(AclService::class)->hasAccess('read') && (
isset($this->wiki->page['metadatas']['publication-title'])||
isset($this->wiki->page['metadatas']['publication-title']) ||
isset($this->wiki->page['metadatas']['publication']['title'])
)) {
$metadata = $this->getService(Publication::class)->getOptions($this->wiki->page['metadatas']);
Expand Down
Loading

0 comments on commit 93a63ad

Please sign in to comment.