PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 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 1 day ago style.css 5 years ago
Events.php
182 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 public $slug = 'divi_events';
10 public $vb_support = 'on';
11
12 public $type = array();
13 private $events = array();
14 private $tags = array();
15
16
17 protected $module_credits = array(
18 'module_uri' => '',
19 'author' => '',
20 'author_uri' => '',
21 );
22
23 public function init()
24 {
25 $this->name = esc_html__(DIVI_AmeliaWhiteLabelHelper::label(BackendStrings::get('events_divi')), 'divi-divi_amelia');
26
27 $isLite = !Licence\Licence::$premium;
28
29 $this->type['list'] = BackendStrings::get('show_event_view_list');
30
31 if (!$isLite) {
32 $this->type['calendar'] = BackendStrings::get('show_event_view_calendar');
33 }
34
35 if (!is_admin()) {
36 return;
37 }
38
39 $data = GutenbergBlock::getEntitiesData()['data'];
40
41 $this->events['0'] = BackendStrings::get('show_all_events');
42 foreach ($data['events'] as $event) {
43 $this->events[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
44 }
45 $this->tags['0'] = BackendStrings::get('show_all_tags');
46 foreach ($data['tags'] as $tag) {
47 $this->tags[$tag['name']] = $tag['name'] . ' (id: ' . $tag['id'] . ')';
48 }
49 }
50
51 /**
52 * Advanced Fields Config
53 *
54 * @return array
55 */
56 public function get_advanced_fields_config()
57 {
58 return array(
59 'button' => false,
60 'link_options' => false
61 );
62 }
63
64 public function get_fields()
65 {
66 $isLite = !Licence\Licence::$premium;
67
68 $typeArr = array(
69 'type' => array(
70 'label' => esc_html__(BackendStrings::get('show_event_view_type'), 'divi-divi_amelia'),
71 'type' => 'select',
72 'options' => $this->type,
73 'default' => array_keys($this->type)[0],
74 'toggle_slug' => 'main_content',
75 'option_category' => 'basic_option',
76 )
77 );
78
79 $mainArr = array(
80 'booking_params' => array(
81 'label' => esc_html__(BackendStrings::get('filter'), 'divi-divi_amelia'),
82 'type' => 'yes_no_button',
83 'options' => array(
84 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
85 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
86 ),
87 'toggle_slug' => 'main_content',
88 'option_category' => 'basic_option',
89 ),
90 'events' => array(
91 'label' => esc_html__(BackendStrings::get('select_event'), 'divi-divi_amelia'),
92 'type' => 'select',
93 'options' => $this->events,
94 'toggle_slug' => 'main_content',
95 'option_category' => 'basic_option',
96 'show_if' => array(
97 'booking_params' => 'on',
98 ),
99 ),
100 'tags' => array(
101 'label' => esc_html__(BackendStrings::get('select_tag'), 'divi-divi_amelia'),
102 'type' => 'select',
103 'toggle_slug' => 'main_content',
104 'options' => $this->tags,
105 'option_category' => 'basic_option',
106 'show_if' => array(
107 'booking_params' => 'on',
108 ),
109 ),
110 'recurring' => array(
111 'label' => esc_html__(BackendStrings::get('recurring_event'), 'divi-divi_amelia'),
112 'type' => 'yes_no_button',
113 'options' => array(
114 'on' => esc_html__(BackendStrings::get('yes'), 'divi-divi_amelia'),
115 'off' => esc_html__(BackendStrings::get('no'), 'divi-divi_amelia'),
116 ),
117 'toggle_slug' => 'main_content',
118 'option_category' => 'basic_option',
119 'show_if' => array(
120 'booking_params' => 'on',
121 ),
122 ),
123 'trigger' => array(
124 'label' => esc_html__(BackendStrings::get('manually_loading'), 'divi-divi_amelia'),
125 'type' => 'text',
126 'toggle_slug' => 'main_content',
127 'option_category' => 'basic_option',
128 'description' => BackendStrings::get('manually_loading_description'),
129 ),
130 );
131
132 if (!$isLite) {
133 return array_merge($typeArr, $mainArr);
134 } else {
135 return $mainArr;
136 }
137 }
138
139 public function checkValues($val)
140 {
141 if ($val !== null) {
142 $matches = [];
143 $id = preg_match('/id: \d+\)/', $val, $matches);
144 return !is_numeric($val) ? ($id && count($matches) ? substr($matches[0], 4, -1) : '0') : $val;
145 }
146 return '0';
147 }
148
149 public function render($attrs, $content = null, $render_slug = null)
150 {
151 $preselect = $this->props['booking_params'];
152 $shortcode = '[' . DIVI_AmeliaWhiteLabelHelper::shortcodeTag('events', 'ameliaevents');
153 $type = $this->props['type'];
154 $trigger = $this->props['trigger'];
155 if ($type !== null && $type !== '' && $type !== '0') {
156 $shortcode .= ' type=' . $type;
157 }
158 if ($trigger !== null && $trigger !== '') {
159 $shortcode .= ' trigger=' . $trigger;
160 }
161 if ($preselect === 'on') {
162 $event = $this->checkValues($this->props['events']);
163 $tag = $this->props['tags'];
164 if ($event !== '0') {
165 $shortcode .= ' event=' . $event;
166 }
167 if ($tag !== null && $tag !== '' && $tag !== '0') {
168 $shortcode .= ' tag="' . $tag . '"';
169 }
170 $recurring = $this->props['recurring'];
171 if ($recurring === 'on') {
172 $shortcode .= ' recurring=1';
173 }
174 }
175 $shortcode .= ']';
176
177 return do_shortcode($shortcode);
178 }
179 }
180
181 new DIVI_Events();
182