| @@ -16,26 +16,28 @@ | ||
| 16 | 16 | public function __construct() |
| 17 | 17 | { |
| 18 | 18 | parent::__construct(); |
| 19 | 19 | |
| 20 | - $this->identifier = (string)rand(1000, 9000); | |
| 20 | + $this->identifier = (string)acym_rand(1000, 9000); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function startTab(string $title, bool $selected = false, string $attributes = '', bool $clickable = true): string | |
| 23 | + public function startTab(string $title, bool $selected = false, bool $clickable = true): string | |
| 24 | 24 | { |
| 25 | 25 | if ($this->opened) { |
| 26 | 26 | $this->endTab(); |
| 27 | 27 | } |
| 28 | + | |
| 28 | 29 | $this->opened = true; |
| 30 | + $this->identifier = preg_replace('#[^a-z0-9]#is', '_', strtolower($title)); | |
| 29 | 31 | |
| 30 | - $attributes .= $clickable ? '' : 'data-empty="true"'; | |
| 31 | - $attributes .= $selected ? 'data-selected="true"' : ''; | |
| 32 | - $classLi = $clickable ? '' : 'tabs-title-empty'; | |
| 32 | + $this->titles[] = [ | |
| 33 | + 'title' => $title, | |
| 34 | + 'clickable' => $clickable, | |
| 35 | + 'selected' => $selected, | |
| 36 | + 'identifier' => $this->identifier, | |
| 37 | + 'tabNumber' => $this->tabNumber, | |
| 38 | + ]; | |
| 33 | 39 | |
| 34 | - $this->identifier = preg_replace('#[^a-z0-9]#is', '_', strtolower((string)$title)); | |
| 35 | - | |
| 36 | - $this->titles[] = '<li class="tabs-title '.$classLi.'"><a class="acym_tab acym__color__medium-gray" '.$attributes.' href="#" data-tab-identifier="'.$this->identifier.'" data-tabs-target="tab_'.$this->identifier.'_'.$this->tabNumber.'">'.$title.'</a></li>'; | |
| 37 | - | |
| 38 | 40 | ob_start(); |
| 39 | 41 | |
| 40 | 42 | return $this->identifier; |
| 41 | 43 | } |
| @@ -46,16 +48,16 @@ | ||
| 46 | 48 | return; |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | $this->opened = false; |
| 50 | - $this->content[] = '<div class="tabs-panel" id="tab_'.$this->identifier.'_'.$this->tabNumber.'">'.ob_get_clean().'</div>'; | |
| 52 | + $this->content[] = '<div class="tabs-panel" id="tab_'.esc_attr($this->identifier.'_'.$this->tabNumber).'">'.ob_get_clean().'</div>'; | |
| 51 | 53 | $this->tabNumber++; |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | - public function addElementInBar(string $element, string $identifier = ''): void | |
| 56 | + public function addCallbackElement(callable $callable, string $identifier = ''): void | |
| 55 | 57 | { |
| 56 | 58 | $this->inBarElements[] = [ |
| 57 | - 'element' => $element, | |
| 59 | + 'callable' => $callable, | |
| 58 | 60 | 'identifier' => $identifier, |
| 59 | 61 | ]; |
| 60 | 62 | } |
| 61 | 63 | |
| @@ -64,28 +66,38 @@ | ||
| 64 | 66 | if ($this->opened) { |
| 65 | 67 | $this->endTab(); |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | - $tabSystem = '<ul class="tabs" data-tabs id="'.acym_escape($tabId).'">'; | |
| 69 | - $tabSystem .= implode('', $this->titles); | |
| 70 | + echo '<ul class="tabs" data-tabs id="'.esc_attr($tabId).'">'; | |
| 71 | + foreach ($this->titles as $title) { | |
| 72 | + echo '<li class="tabs-title '.esc_attr($title['clickable'] ? '' : 'tabs-title-empty').'"> | |
| 73 | + <a class="acym_tab acym__color__medium-gray" | |
| 74 | + '.($title['clickable'] ? '' : 'data-empty="true"').' | |
| 75 | + '.($title['selected'] ? 'data-selected="true"' : '').' | |
| 76 | + href="#" | |
| 77 | + data-tab-identifier="'.esc_attr($title['identifier']).'" | |
| 78 | + data-tabs-target="tab_'.esc_attr($title['identifier'].'_'.$title['tabNumber']).'">'.esc_html($title['title']).'</a> | |
| 79 | + </li>'; | |
| 80 | + } | |
| 70 | 81 | |
| 71 | 82 | if (!empty($this->inBarElements)) { |
| 72 | - $tabSystem .= '<div class="acym__tabs__inbar">'; | |
| 83 | + echo '<div class="acym__tabs__inbar">'; | |
| 73 | 84 | foreach ($this->inBarElements as $oneElement) { |
| 74 | - $displayOptions = ''; | |
| 85 | + echo '<div class="acym__tabs__inbar__element" '; | |
| 75 | 86 | if (!empty($oneElement['identifier'])) { |
| 76 | - $displayOptions = 'acym-data-identifier="'.acym_escape($oneElement['identifier']).'" style="display: none;"'; | |
| 87 | + echo 'acym-data-identifier="'.esc_attr($oneElement['identifier']).'" style="display: none;"'; | |
| 77 | 88 | } |
| 78 | - $tabSystem .= '<div class="acym__tabs__inbar__element" '.$displayOptions.'>'.$oneElement['element'].'</div>'; | |
| 89 | + echo '>'; | |
| 90 | + $oneElement['callable'](); | |
| 91 | + echo '</div>'; | |
| 79 | 92 | } |
| 80 | - $tabSystem .= '</div>'; | |
| 93 | + echo '</div>'; | |
| 81 | 94 | } |
| 82 | 95 | |
| 83 | - $tabSystem .= '</ul>'; | |
| 96 | + echo '</ul>'; | |
| 84 | 97 | |
| 85 | - $tabSystem .= '<div class="tabs-content margin-bottom-1" data-tabs-content="'.acym_escape($tabId).'">'; | |
| 86 | - $tabSystem .= implode('', $this->content); | |
| 87 | - $tabSystem .= '</div>'; | |
| 88 | - | |
| 89 | - echo $tabSystem; | |
| 98 | + echo '<div class="tabs-content margin-bottom-1" data-tabs-content="'.esc_attr($tabId).'">'; | |
| 99 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Content escaped from the add-on/plugin side. | |
| 100 | + echo implode('', $this->content); | |
| 101 | + echo '</div>'; | |
| 90 | 102 | } |
| 91 | 103 | } |