Skip to content

Commit

Permalink
feat : editorconfig + catch bazar actions without spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflos committed Feb 6, 2024
1 parent b58e1c6 commit f40e790
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 92 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,php}]
charset = utf-8

[*.php]
indent_style = space
indent_size = 4

[*.js]
indent_style = space
indent_size = 2

2 changes: 1 addition & 1 deletion controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function run(bool $inIframe = false)

// simplier handler for client rendering
if (!$this->pdfHelper->canExecChromium()) {
$this->wiki->redirect($this->wiki->href('preview', $pageTag, 'browserPrintAfterRendered=1', false));
$this->wiki->redirect($sourceUrl . '&browserPrintAfterRendered=1');
return;
} else {
return $this->$method('@publication/handler-pdf.twig', [
Expand Down
115 changes: 57 additions & 58 deletions handlers/PreviewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

class PreviewHandler extends YesWikiHandler
{
protected $aclService ;
protected $assetsManager ;
protected $entryController ;
protected $entryManager ;
protected $pageManager ;
protected $publicationService ;
protected $templateEngine ;
protected $aclService;
protected $assetsManager;
protected $entryController;
protected $entryManager;
protected $pageManager;
protected $publicationService;
protected $templateEngine;

public function run()
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public function run()
$metadatas = $this->publicationService->getOptions(
$publication['metadatas'] ?? [],
isset($_GET['layout'])
? [ "publication-fanzine" => ["layout" => $_GET['layout'] ] ]
? ["publication-fanzine" => ["layout" => $_GET['layout']]]
: []
);

Expand All @@ -63,7 +63,7 @@ public function run()
$blankpage = $this->wiki->Format('{{blankpage}}');

// build the preview/printing page
$output = $this->render('@publication/print-layouts/'.$metadatas['publication-mode'].'.twig', [
$output = $this->render('@publication/print-layouts/' . $metadatas['publication-mode'] . '.twig', [
"baseUrl" => $this->wiki->getBaseUrl(),
"blankpage" => $blankpage,
"content" => $publication['content'],
Expand Down Expand Up @@ -97,7 +97,8 @@ protected function getContentAndPublication(array $get): array
// we assemble bazar pages
$content = '';
$templateName = 'rendered-entries.twig';
if (!$this->templateEngine->hasTemplate('@bazar/'.$templateName)) {

if (!$this->templateEngine->hasTemplate('@bazar/' . $templateName)) {
// backward compatibilty
if (preg_match('#{{\s*bazar.+id="(.+)".+}}#siU', $this->wiki->page['body'], $matches)) {
list(, $formId) = $matches;
Expand All @@ -114,56 +115,54 @@ protected function getContentAndPublication(array $get): array
/**
* Print from page, but render its {{ bazar* }} elements
*/
elseif (preg_match('/({{(bazarliste|bazarcarto|calendrier|map|gogomap)\s[^}]*}})/i', $this->wiki->page['body'], $matches)) {
elseif (preg_match('/({{(bazarliste|bazarcarto|bazar|calendrier|map|gogomap)\s*[^}]*}})/i', $this->wiki->page['body'], $matches)) {
$actionText = $matches[1];
$actionName = $matches[2];
$matches = [];
$params = [];
if (preg_match_all('/([a-zA-Z0-9_]*)=\"(.*)\"/U', $actionText, $matches)) {
foreach ($matches[0] as $id => $match) {
$params[$matches[1][$id]] = $matches[2][$id];
}
// redefine template
$params['template'] = $templateName;
$params['dynamic'] = false;
$params['search'] = false;
$params['entryController'] = $this->entryController;
if (isset($params['groups'])) {
unset($params['groups']);
}
// be careful for query because currenty making 'or' instead of 'and' if same key in $_GET and params
if (!empty($params['query']) && !empty($_GET['query'])){
$paramQueries = $this->entryController->formatQuery(['query'=>$params['query']],[]);
$getQueries = $this->entryController->formatQuery([],['query'=>$_GET['query']]);
if (count(array_intersect_key($paramQueries,$getQueries)) > 0){
if (!empty($params['id'])){
$formsIds = explode(',',$params['id']);
$formsIds = array_filter($formsIds,function($val){
return is_scalar($val) && intval($val) > 0 && strval($val) == strval(intval($val));
preg_match_all('/([a-zA-Z0-9_]*)=\"(.*)\"/U', $actionText, $matches);
foreach ($matches[0] as $id => $match) {
$params[$matches[1][$id]] = $matches[2][$id];
}
// redefine template
$params['template'] = $templateName;
$params['dynamic'] = false;
$params['search'] = false;
$params['entryController'] = $this->entryController;
if (isset($params['groups'])) {
unset($params['groups']);
}
// be careful for query because currenty making 'or' instead of 'and' if same key in $_GET and params
if (!empty($params['query']) && !empty($_GET['query'])) {
$paramQueries = $this->entryController->formatQuery(['query' => $params['query']], []);
$getQueries = $this->entryController->formatQuery([], ['query' => $_GET['query']]);
if (count(array_intersect_key($paramQueries, $getQueries)) > 0) {
if (!empty($params['id']) || $params['id'] = []) {
$formsIds = explode(',', $params['id']);
$formsIds = array_filter($formsIds, function ($val) {
return is_scalar($val) && intval($val) > 0 && strval($val) == strval(intval($val));
});
if (!empty($formsIds) || $formsIds = []) {
$authorizedEntries = $this->entryManager->search([
'queries' => $paramQueries,
'formsIds' => array_map('strval', $formsIds)
]);
$authorizedEntries = array_filter($authorizedEntries, function ($entry) {
return !empty($entry['id_fiche']);
});
if (!empty($formsIds)){
$authorizedEntries = $this->entryManager->search([
'queries' => $paramQueries,
'formsIds' => array_map('strval',$formsIds)
]);
$authorizedEntries = array_filter($authorizedEntries,function($entry){
return !empty($entry['id_fiche']);
});
$entrieIds = empty($authorizedEntries)
? []
: array_column($authorizedEntries,'id_fiche');
// keep only `id_fiche` matching `paramQueries` to emulate a 'AND'
$params['query'] = "id_fiche=".implode(',',$entrieIds);
}
$entrieIds = empty($authorizedEntries)
? []
: array_column($authorizedEntries, 'id_fiche');
// keep only `id_fiche` matching `paramQueries` to emulate a 'AND'
$params['query'] = "id_fiche=" . implode(',', $entrieIds);
}
}
}
$content = $this->wiki->Action($actionName, 0, $params);
}
$content = $this->wiki->Action($actionName, 0, $params);
}

// we gather a few things from
if (isset($get['template-page'])) {
if (!empty($get['template-page'])) {
if (!is_string($get['template-page'])) {
throw new Exception("'template-page' should be a string");
}
Expand Down Expand Up @@ -222,12 +221,12 @@ protected function addCssFiles(array $metadatas)
{
// Load the cascade of publication styles
$cssFiles = array_merge(
glob('tools/publication/styles/print-layouts/'.$metadatas['publication-mode'].'.css'),
glob('tools/publication/styles/print-layouts/' . $metadatas['publication-mode'] . '.css'),
glob('tools/publication/styles/*.css'),
glob('themes/'.$this->wiki->config['favorite_theme'].'/tools/publication/*.css'),
glob('themes/'.$this->wiki->config['favorite_theme'].'/tools/publication/print-layouts/'.$metadatas['publication-mode'].'.css'),
glob('themes/' . $this->wiki->config['favorite_theme'] . '/tools/publication/*.css'),
glob('themes/' . $this->wiki->config['favorite_theme'] . '/tools/publication/print-layouts/' . $metadatas['publication-mode'] . '.css'),
glob('custom/tools/publication/*.css'),
glob('custom/tools/publication/print-layouts/'.$metadatas['publication-mode'].'.css'),
glob('custom/tools/publication/print-layouts/' . $metadatas['publication-mode'] . '.css'),
);

array_map(function ($file) {
Expand All @@ -243,11 +242,11 @@ protected function getCoverImage(array $metadatas): string
if ($metadatas['publication-cover-image']) {
// use an external image
if (preg_match('#^(https?://|//|/)#iU', $metadatas['publication-cover-image'])) {
$coverImage = '<figure class="attached_file attached_file--external cover"><img src="'. $metadatas['publication-cover-image'] .'" alt="" class="img-responsive"></figure>';
$coverImage = '<figure class="attached_file attached_file--external cover"><img src="' . $metadatas['publication-cover-image'] . '" alt="" class="img-responsive"></figure>';
}
// use a wiki attachment
else {
$coverImage = $this->wiki->Format('{{ attach file="'. $metadatas['publication-cover-image'] .'" desc=" " size="original" class="cover"}}');
$coverImage = $this->wiki->Format('{{ attach file="' . $metadatas['publication-cover-image'] . '" desc=" " size="original" class="cover"}}');
}
}

Expand All @@ -258,12 +257,12 @@ protected function sanitizeUrlForProxy(string &$output)
{
if ($this->params->get('htmltopdf_base_url')) {
['scheme' => $scheme, 'host' => $host, 'port' => $port] = parse_url($this->params->get('base_url'));
$base_url = $scheme . '://' . $host . (!$port || (string)$port === '80' ? '' : ':'.$port) . '/';
$base_url = $scheme . '://' . $host . (!$port || (string)$port === '80' ? '' : ':' . $port) . '/';

['scheme' => $scheme, 'host' => $host, 'port' => $port] = parse_url($this->params->get('htmltopdf_base_url'));
$new_base_url = $scheme . '://' . $host . (!$port || (string)$port === '80' ? '' : ':'.$port) . '/';
$new_base_url = $scheme . '://' . $host . (!$port || (string)$port === '80' ? '' : ':' . $port) . '/';

$full_request_url = $_SERVER['REQUEST_SCHEME'] . '://'. $_SERVER['HTTP_HOST'] . ((string)$_SERVER['SERVER_PORT'] === '80' ? '' : ':'.$_SERVER['SERVER_PORT']) . $_SERVER['REQUEST_URI'];
$full_request_url = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . ((string)$_SERVER['SERVER_PORT'] === '80' ? '' : ':' . $_SERVER['SERVER_PORT']) . $_SERVER['REQUEST_URI'];

// Replaces https://example.com/?Accueil by http://localhost:8000/?Accueil
// Replaces https://example.com/favicon.ico by http://localhost:8000/favicon.ico
Expand Down

0 comments on commit f40e790

Please sign in to comment.