PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / extensions / divi_amelia / includes / modules / Events / Events.php
ameliabooking / extensions / divi_amelia / includes / modules / Events Last commit date
Events.php 7 months ago style.css 5 years ago
Events.php
183 lines
1 <?php
2
3 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
4 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
5 use AmeliaBooking\Infrastructure\Licence;
6
7 class DIVI_Events extends ET_Builder_Module
8 {
9
10 public $slug = 'divi_events';
11 public $vb_support = 'on';
12
13 public $type = array();
14 private $events = array();
15 private $tags = array();
16
17
18 protected $module_credits = array(
19 'module_uri' => '',
20 'author' => '',
21 'author_uri' => '',
22 );
23
24 public function init()
25 {
26 $this->name = esc_html__(BackendStrings::get('events_divi'), 'divi-divi_amelia');
27
28 $isLite = !Licence\Licence::$premium;
29
30 $this->type['list'] = BackendStrings::get('show_event_view_list');
31
32 if (!$isLite) {
33 $this->type['calendar'] = BackendStrings::get('show_event_view_calendar');
34 }
35
36 if (!is_admin()) {
37 return;
38 }
39
40 $data = GutenbergBlock::getEntitiesData()['data'];
41
42 $this->events['0'] = BackendStrings::get('show_all_events');
43 foreach ($data['events'] as $event) {
44 $this->events[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
45 }
46 $this->tags['0'] = BackendStrings::get('show_all_tags');
47 foreach ($data['tags'] as $tag) {
48 $this->tags[$tag['name']] = $tag['name'] . ' (id: ' . $tag['id'] . ')';
49 }
50 }
51
52 /**
53 * Advanced Fields Config
54 *
55 * @return array
56 */
57 public function get_advanced_fields_config()
58 {
59 return array(
60 'button' => false,
61 'link_options' => false
62 );
63 }
64
65 public function get_fields()
66 {
67 $isLite = !Licence\Licence::$premium;
68
69 $typeArr = array(
70 'type' => array(
71 'label' => esc_html__(BackendStrings::get('show_event_view_type'), 'divi-divi_amelia'),
72 'type' => 'select',
73 'options' => $this->type,
74 'default' => array_keys($this->type)[0],
75 'toggle_slug' => 'main_content',
76 'option_category' => 'basic_option',
77 )
78 );
79
80 $mainArr = array(
81 'booking_params' => array(
82 'label' => esc_html__(BackendStrings::get('filter'), 'divi-divi_amelia'),
83 'type' => 'yes_no_button',
84 'options' => array(
85 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
86 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
87 ),
88 'toggle_slug' => 'main_content',
89 'option_category' => 'basic_option',
90 ),
91 'events' => array(
92 'label' => esc_html__(BackendStrings::get('select_event'), 'divi-divi_amelia'),
93 'type' => 'select',
94 'options' => $this->events,
95 'toggle_slug' => 'main_content',
96 'option_category' => 'basic_option',
97 'show_if' => array(
98 'booking_params' => 'on',
99 ),
100 ),
101 'tags' => array(
102 'label' => esc_html__(BackendStrings::get('select_tag'), 'divi-divi_amelia'),
103 'type' => 'select',
104 'toggle_slug' => 'main_content',
105 'options' => $this->tags,
106 'option_category' => 'basic_option',
107 'show_if' => array(
108 'booking_params' => 'on',
109 ),
110 ),
111 'recurring' => array(
112 'label' => esc_html__(BackendStrings::get('recurring_event'), 'divi-divi_amelia'),
113 'type' => 'yes_no_button',
114 'options' => array(
115 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
116 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
117 ),
118 'toggle_slug' => 'main_content',
119 'option_category' => 'basic_option',
120 'show_if' => array(
121 'booking_params' => 'on',
122 ),
123 ),
124 'trigger' => array(
125 'label' => esc_html__(BackendStrings::get('manually_loading'), 'divi-divi_amelia'),
126 'type' => 'text',
127 'toggle_slug' => 'main_content',
128 'option_category' => 'basic_option',
129 'description' => BackendStrings::get('manually_loading_description'),
130 ),
131 );
132
133 if (!$isLite) {
134 return array_merge($typeArr, $mainArr);
135 } else {
136 return $mainArr;
137 }
138 }
139
140 public function checkValues($val)
141 {
142 if ($val !== null) {
143 $matches = [];
144 $id = preg_match('/id: \d+\)/', $val, $matches);
145 return !is_numeric($val) ? ($id && count($matches) ? substr($matches[0], 4, -1) : '0') : $val;
146 }
147 return '0';
148 }
149
150 public function render($attrs, $content = null, $render_slug = null)
151 {
152 $preselect = $this->props['booking_params'];
153 $shortcode = '[ameliaevents';
154 $type = $this->props['type'];
155 $trigger = $this->props['trigger'];
156 if ($type !== null && $type !== '' && $type !== '0') {
157 $shortcode .= ' type='.$type;
158 }
159 if ($trigger !== null && $trigger !== '') {
160 $shortcode .= ' trigger='.$trigger;
161 }
162 if ($preselect === 'on') {
163 $event = $this->checkValues($this->props['events']);
164 $tag = $this->props['tags'];
165 if ($event !== '0') {
166 $shortcode .= ' event=' . $event;
167 }
168 if ($tag !== null && $tag !== '' && $tag !== '0') {
169 $shortcode .= ' tag="' . $tag . '"';
170 }
171 $recurring = $this->props['recurring'];
172 if ($recurring === 'on') {
173 $shortcode .= ' recurring=1';
174 }
175 }
176 $shortcode .= ']';
177
178 return do_shortcode($shortcode);
179 }
180 }
181
182 new DIVI_Events;
183