PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Helpers / TabHelper.php

TabHelper.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Helpers/TabHelper.php

87 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Helpers;
4
5 use AcyMailing\Core\AcymObject;
6
7 class TabHelper extends AcymObject
8 {
9 var $titles = [];
10 var $content = [];
11 var $tabNumber = 0;
12 var $opened = false;
13 var $identifier;
14 var $inBarElements = [];
15
16 public function __construct()
17 {
18 parent::__construct();
19 $this->identifier = rand(1000, 9000);
20 }
21
22 public function startTab($title, $selected = false, $attributes = '', $clickable = true)
23 {
24 if ($this->opened) $this->endTab();
25 $this->opened = true;
26
27 $attributes .= $clickable ? '' : 'data-empty="true"';
28 $attributes .= $selected ? 'data-selected="true"' : '';
29 $classLi = $clickable ? '' : 'tabs-title-empty';
30
31 $this->identifier = preg_replace('#[^a-z0-9]#is', '_', strtolower((string)$title));
32
33 $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>';
34
35 ob_start();
36
37 return $this->identifier;
38 }
39
40 public function endTab()
41 {
42 if (!$this->opened) return;
43
44 $this->opened = false;
45 $this->content[] = '<div class="tabs-panel" id="tab_'.$this->identifier.'_'.$this->tabNumber.'">'.ob_get_clean().'</div>';
46 $this->tabNumber++;
47 }
48
49 public function addElementInBar($element, $identifier = '')
50 {
51 $this->inBarElements[] = [
52 'element' => $element,
53 'identifier' => $identifier,
54 ];
55 }
56
57 public function display($id)
58 {
59 if ($this->opened) {
60 $this->endTab();
61 }
62
63 $tabSystem = '<ul class="tabs" data-tabs id="'.acym_escape($id).'">';
64 $tabSystem .= implode('', $this->titles);
65
66 if (!empty($this->inBarElements)) {
67 $tabSystem .= '<div class="acym__tabs__inbar">';
68 foreach ($this->inBarElements as $oneElement) {
69 $displayOptions = '';
70 if (!empty($oneElement['identifier'])) {
71 $displayOptions = 'acym-data-identifier="'.acym_escape($oneElement['identifier']).'" style="display: none;"';
72 }
73 $tabSystem .= '<div class="acym__tabs__inbar__element" '.$displayOptions.'>'.$oneElement['element'].'</div>';
74 }
75 $tabSystem .= '</div>';
76 }
77
78 $tabSystem .= '</ul>';
79
80 $tabSystem .= '<div class="tabs-content margin-bottom-1" data-tabs-content="'.acym_escape($id).'">';
81 $tabSystem .= implode('', $this->content);
82 $tabSystem .= '</div>';
83
84 echo $tabSystem;
85 }
86 }
87