diff --git a/includes/objects/YesWikiAction.php b/includes/objects/YesWikiAction.php index 85f1dbc90e..6b84ea60ef 100644 --- a/includes/objects/YesWikiAction.php +++ b/includes/objects/YesWikiAction.php @@ -32,4 +32,36 @@ protected function checkSecuredACL($adminOnly = true): ?string return null; } } + + + /** + * This function check for corresponding "end" element and store result in + * $GLOBALS['check ' . $pagetag]['$element_name']. + * @param $action_name + * + * @return false if wrong number of closing element found + */ + protected function check_end_elem(string $action_name): bool + { + $pagetag = $this->wiki->GetPageTag(); + if (!isset($GLOBALS["check_$pagetag"][$action_name])) { + $GLOBALS["check_$pagetag"][$action_name] = + $this->wiki->services->get(\YesWiki\Templates\Service\Utils::class) + ->checkGraphicalElements($action_name, $pagetag, $this->wiki->page['body'] ?? ''); + } + return $GLOBALS["check_$pagetag"][$action_name]; + } + + protected function generate_error_msg(string $action_name): string + { + $action_name = strtoupper($action_name); + return '
' + . _t("TEMPLATE_ACTION_$action_name") . ' : ' + . _t("TEMPLATE_ELEM_{$action_name}_NOT_CLOSED") . '.
' . "\n"; + } + + public function end(): string + { + return '\n'; + } } diff --git a/includes/services/Performer.php b/includes/services/Performer.php index 390f9889c3..e5a20e171e 100644 --- a/includes/services/Performer.php +++ b/includes/services/Performer.php @@ -158,7 +158,7 @@ public function createPerformable(array $object, array &$vars, &$output) * * @return string the generated output */ - public function run($objectName, $objectType, array $vars = []): string + public function run($objectName, $objectType, array $vars = [], bool $end_elem = false): string { if (!Performer::TYPES[$objectType]) { return "Invalid type $objectType"; @@ -186,7 +186,11 @@ public function run($objectName, $objectType, array $vars = []): string if ($file['isDefinedAsClass']) { $performable = $this->createPerformable($file, $vars, $output); try { - $output .= $performable->run(); + if ($end_elem) { + $output .= $performable->end(); + } else { + $output .= $performable->run(); + } } catch (HttpException $exception) { return $this->renderError($exception->getMessage(), $objectType); } diff --git a/tools/templates/actions/end.php b/tools/templates/actions/end.php index 64a2c0fe58..de2cbc4f2a 100755 --- a/tools/templates/actions/end.php +++ b/tools/templates/actions/end.php @@ -1,5 +1,8 @@ \n"; break; - case 'section': - echo "\n\n \n"; - break; case 'label': echo ''; break; @@ -50,6 +50,7 @@ echo $this->services->get(TabsController::class)->closeTabs(); break; default: + echo $this->services->get(Performer::class)->run($elem, 'action', [], true); break; } } diff --git a/tools/templates/actions/section.php b/tools/templates/actions/section.php deleted file mode 100644 index d5f63cbdfc..0000000000 --- a/tools/templates/actions/section.php +++ /dev/null @@ -1,165 +0,0 @@ -GetParameter('bgcolor'); - -// backgournd pattern -$patternreverse = $this->GetParameter('patternreverse') == 'true'; -$patternId = $this->GetParameter('pattern'); -$patternbg = $patternreverse ? 'var(--main-bg-color)' : $bgcolor; -$patterncolor = $patternreverse ? $bgcolor : 'var(--main-bg-color)'; -$patternborder = false; -switch ($patternId) { - case 'border-solid': - case 'border-dashed': - case 'border-dotted': - $patternborder = true; - $pattern = <<GetParameter('file'); -$backgroundimg = true; -if (empty($file) && empty($bgcolor)) { - $bgcolor = false; - $backgroundimg = false; -} - -if (!empty($file)) { - if (!class_exists('attach')) { - include 'tools/attach/libs/attach.lib.php'; - } - $att = new attach($this); - - // test of image extension - if (!$att->isPicture($file)) { - echo '
' . _t('ATTACH_ACTION_BACKGROUNDIMAGE') . ' : ' - . _t('ATTACH_PARAM_FILE_MUST_BE_IMAGE') . '.
' . "\n"; - - return; - } - // image size - $height = $this->GetParameter('height'); - $width = $this->GetParameter('width'); - if (empty($width)) { - $width = 1920; - } - - //recuperation des parametres necessaires - $att->file = $file; - $att->desc = 'background image ' . $file; - $att->height = $height; - $att->width = $width; - $fullFilename = $att->GetFullFilename(); -} - -// container class -$class = $this->GetParameter('class'); - -// container id -$id = $this->GetParameter('id'); - -// container data attributes -$data = $this->services->get(\YesWiki\Templates\Service\Utils::class)->getDataParameter(); - -$pagetag = $this->GetPageTag(); -if (!isset($GLOBALS['check_' . $pagetag])) { - $GLOBALS['check_' . $pagetag] = []; -} -if (!isset($GLOBALS['check_' . $pagetag]['section'])) { - $GLOBALS['check_' . $pagetag]['section'] = $this->services->get(\YesWiki\Templates\Service\Utils::class)->checkGraphicalElements('section', $pagetag, $this->page['body'] ?? ''); -} -if ($GLOBALS['check_' . $pagetag]['section']) { - // specify the role to be checked ( *, +, %, @admins) - $role = $this->GetParameter('visibility'); - $role = empty($role) ? $role : str_replace('\\n', "\n", $role); - $visible = !$role || ($GLOBALS['wiki']->CheckACL($role, null, false)); - $class = ($backgroundimg ? 'background-image' : '') - . ($patternId && !$patternborder ? ' with-bg-pattern' : '') - . ($patternborder ? ' pattern-border' : '') - . ($visible ? '' : ' remove-this-div-on-page-load ') - . " pattern-$patternId" - . (!empty($class) ? ' ' . $class : ''); - - echo ' - $value) { - echo ' data-' . $key . '="' . $value . '"'; - } - } - echo '>' . "\n"; - - $nocontainer = $this->GetParameter('nocontainer'); - if (empty($nocontainer)) { - echo '
' . "\n"; - } else { - echo '
'; - } - //test d'existance du fichier - if (isset($fullFilename) and (!file_exists($fullFilename) or $fullFilename == '')) { - $att->showFileNotExits(); - //return; - } -} else { - echo '
' . _t('TEMPLATE_ACTION_SECTION') . ' : ' - . _t('TEMPLATE_ELEM_SECTION_NOT_CLOSED') . '.
' . "\n"; - - return; -} diff --git a/tools/templates/actions/sectionAction.php b/tools/templates/actions/sectionAction.php new file mode 100644 index 0000000000..5e80f3b677 --- /dev/null +++ b/tools/templates/actions/sectionAction.php @@ -0,0 +1,170 @@ +arguments['bgcolor'] ?? ''; + $patternreverse = ($this->arguments['patternreverse'] ?? false) == 'true'; + $patternId = $this->arguments['pattern'] ?? ''; + $patternbg = $patternreverse ? 'var(--main-bg-color)' : $bgcolor; + $patterncolor = $patternreverse ? $bgcolor : 'var(--main-bg-color)'; + $patternborder = false; + + // image's background color + switch ($patternId) { + case 'border-solid': + case 'border-dashed': + case 'border-dotted': + $patternborder = true; + $pattern = <<arguments['file'] ?? ''; + $backgroundimg = true; + if (empty($file) && empty($bgcolor)) { + $bgcolor = false; + $backgroundimg = false; + } + + if (!empty($file)) { + if (!class_exists('attach')) { + include 'tools/attach/libs/attach.lib.php'; + } + $att = new attach($this->wiki); + + // test of image extension + if (!$att->isPicture($file)) { + echo '
' . _t('ATTACH_ACTION_BACKGROUNDIMAGE') . ' : ' + . _t('ATTACH_PARAM_FILE_MUST_BE_IMAGE') . '.
' . "\n"; + + return; + } + // image size + $height = $this->arguments['height'] ?? ''; + $width = $this->arguments['width'] ?? ''; + if (empty($width)) { + $width = 1920; + } + + //recuperation des parametres necessaires + $att->file = $file; + $att->desc = 'background image ' . $file; + $att->height = $height; + $att->width = $width; + $fullFilename = $att->GetFullFilename(); + } + + // container class + $class = $this->arguments['class'] ?? ''; + + // container id + $id = $this->arguments['id'] ?? ''; + + // container data attributes + $data = $this->wiki->services->get(\YesWiki\Templates\Service\Utils::class)->getDataParameter(); + + $pagetag = $this->wiki->GetPageTag(); + + if ($this->check_end_elem('section')) { + // specify the role to be checked ( *, +, %, @admins) + $role = $this->arguments['visibility'] ?? ''; + $role = empty($role) ? $role : str_replace('\\n', "\n", $role); + $visible = !$role || ($GLOBALS['wiki']->CheckACL($role, null, false)); + $class = ($backgroundimg ? 'background-image' : '') + . ($patternId && !$patternborder ? ' with-bg-pattern' : '') + . ($patternborder ? ' pattern-border' : '') + . ($visible ? '' : ' remove-this-div-on-page-load ') + . " pattern-$patternId" + . (!empty($class) ? ' ' . $class : ''); + + echo ' + $value) { + echo ' data-' . $key . '="' . $value . '"'; + } + } + echo '>' . "\n"; + + $nocontainer = $this->arguments['nocontainer'] ?? ''; + if (empty($nocontainer)) { + echo '
' . "\n"; + } else { + echo '
'; + } + //test d'existance du fichier + if (isset($fullFilename) and (!file_exists($fullFilename) or $fullFilename == '')) { + $att->showFileNotExits(); + //return; + } + } else { + echo $this->generate_error_msg('section'); + } + $section = ob_get_contents(); + ob_end_clean(); + return $section; + } + + public function end(): string { + return '\n
'; + } +}