PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.2
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 / WpInit / Gutenberg.php

Gutenberg.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.10.2, at WpInit/Gutenberg.php

329 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\WpInit;
4
5 use AcyMailing\Classes\FieldClass;
6 use AcyMailing\Classes\ListClass;
7 use AcyMailing\Classes\UserClass;
8 use AcyMailing\Core\AcymParameter;
9
10 class Gutenberg
11 {
12 public $lists;
13 public $fields;
14
15 public function __construct()
16 {
17 add_filter('block_categories_all', [$this, 'registerAcymCategory'], 1, 2);
18 $this->registerBlock();
19 }
20
21 public function registerBlock()
22 {
23 if (!function_exists('register_block_type')) return;
24
25 $listClass = new ListClass();
26 $this->lists = $listClass->getAllForSelect(false);
27
28 $fieldClass = new FieldClass();
29 $allFields = $fieldClass->getAll();
30 $fields = [];
31 foreach ($allFields as $field) {
32 if ($field->id == 2 || intval($field->active) === 0) continue;
33 $field->name = acym_translation($field->name);
34 $fields[$field->id] = $field;
35 }
36 $this->fields = $fields;
37
38 $this->registerBlockSubscription();
39 $this->registerBlockProfile();
40 $this->registerBlockArchive();
41 }
42
43 public function registerBlockSubscription()
44 {
45 wp_register_script(
46 'gutenberg-acymailing-subscription-form',
47 ACYM_JS.'gutenberg/subscription.min.js?time='.time()
48 );
49 wp_add_inline_script(
50 'gutenberg-acymailing-subscription-form',
51 'var acym_lists = '.json_encode($this->lists).';
52 var ACYM_JS_TXT = '.acym_getJSMessages().';
53 var acym_fields = '.json_encode($this->fields).';'
54 );
55
56 $basicAttribute = [
57 'title' => [
58 'type' => 'string',
59 'default' => 'Receive our newsletters',
60 ],
61 'mode' => [
62 'type' => 'string',
63 'default' => 'tableless',
64 ],
65 'hiddenlists' => [
66 'type' => 'array',
67 ],
68 'displists' => [
69 'type' => 'array',
70 ],
71 'listschecked' => [
72 'type' => 'array',
73 ],
74 'listposition' => [
75 'type' => 'string',
76 'default' => 'before',
77 ],
78 'fields' => [
79 'type' => 'array',
80 ],
81 'textmode' => [
82 'type' => 'string',
83 'default' => '1',
84 ],
85 'termscontent' => [
86 'type' => 'string',
87 'default' => '',
88 ],
89 'privacypolicy' => [
90 'type' => 'string',
91 'default' => '',
92 ],
93 'termscontentURL' => [
94 'type' => 'string',
95 'default' => '',
96 ],
97 'privacypolicyURL' => [
98 'type' => 'string',
99 'default' => '',
100 ],
101 'unsub' => [
102 'type' => 'string',
103 'default' => '0',
104 ],
105 'unsubtext' => [
106 'type' => 'string',
107 'default' => 'Unsubscribe',
108 ],
109 'unsubredirect' => [
110 'type' => 'string',
111 ],
112 'successmode' => [
113 'type' => 'string',
114 'default' => 'replace',
115 ],
116
117 'redirect' => [
118 'type' => 'string',
119 ],
120 'userinfo' => [
121 'type' => 'string',
122 'default' => '1',
123 ],
124 'introtext' => [
125 'type' => 'string',
126 ],
127 'posttext' => [
128 'type' => 'string',
129 ],
130 'alignment' => [
131 'type' => 'string',
132 'default' => 'none',
133 ],
134 'source' => [
135 'type' => 'string',
136 'default' => 'gutenberg_subscription_form',
137 ],
138 ];
139 $moreAttributes = [];
140 if (acym_isMultilingual()) {
141 foreach (acym_getMultilingualLanguages() as &$language) {
142 $moreAttributes['subtext_'.$language->language] = ['type' => 'string', 'default' => 'Subscribe'];
143 $moreAttributes['subtextlogged_'.$language->language] = ['type' => 'string', 'default' => 'Subscribe'];
144 $moreAttributes['confirmation_message_'.$language->language] = ['type' => 'string', 'default' => ''];
145 }
146 } else {
147 $moreAttributes['subtext'] = [
148 'type' => 'string',
149 'default' => 'Subscribe',
150 ];
151 $moreAttributes['subtextlogged'] = [
152 'type' => 'string',
153 'default' => 'Subscribe',
154 ];
155 $moreAttributes['confirmation_message'] = [
156 'type' => 'string',
157 'default' => '',
158
159 ];
160 }
161 $attributes = array_merge($basicAttribute, $moreAttributes);
162
163 register_block_type(
164 'acymailing/subscription-form',
165 [
166 'apiVersion' => 2,
167 'editor_script' => 'gutenberg-acymailing-subscription-form',
168 'render_callback' => [$this, 'renderCallback'],
169 'attributes' => $attributes,
170 ]
171 );
172 }
173
174 public function registerAcymCategory($categories, $post)
175 {
176 return array_merge(
177 $categories,
178 [
179 [
180 'slug' => 'acymailing',
181 'title' => 'AcyMailing',
182 'icon' => 'editor-table',
183 ],
184 ]
185 );
186 }
187
188 public function renderCallback($block_attributes, $content)
189 {
190 if (!array_key_exists('subtext', $block_attributes)) {
191 $moreBlockAttributes = [];
192 $currentLanguage = strtolower('subtext_'.acym_getLanguageTag());
193 $currentLanguageLogged = strtolower('subtextlogged_'.acym_getLanguageTag());
194 $confirmMessageLangue = strtolower('confirmation_message_'.acym_getLanguageTag());
195 $moreBlockAttributes['subtext'] = $block_attributes[$currentLanguage];
196 $moreBlockAttributes['subtextlogged'] = $block_attributes[$currentLanguageLogged];
197 $moreBlockAttributes['confirmation_message'] = $block_attributes[$confirmMessageLangue];
198 $block_attributes = array_merge($block_attributes, $moreBlockAttributes);
199 }
200 $params = new AcymParameter($block_attributes);
201
202 return acym_renderForm(
203 $params,
204 ['disableButtons' => strpos(acym_currentURL(), 'block-renderer') !== false]
205 );
206 }
207
208 public function registerBlockProfile()
209 {
210 if (!function_exists('register_block_type')) return;
211
212 wp_register_script(
213 'gutenberg-acymailing-profile',
214 ACYM_JS.'gutenberg/profile.min.js?time='.time()
215 );
216 wp_add_inline_script(
217 'gutenberg-acymailing-profile',
218 'var acym_lists_profile = '.json_encode($this->lists).';
219 var ACYM_JS_TXT = '.acym_getJSMessages().';
220 var acym_fields_profile = '.json_encode($this->fields)
221 );
222
223 register_block_type(
224 'acymailing/profile',
225 [
226 'apiVersion' => 2,
227 'editor_script' => 'gutenberg-acymailing-profile',
228 'render_callback' => [$this, 'renderCallbackProfile'],
229 'attributes' => [
230 'title' => [
231 'type' => 'string',
232 'default' => 'Profile',
233 ],
234 'lists' => [
235 'type' => 'array',
236 ],
237 'listsdropdown' => [
238 'type' => 'array',
239 ],
240 'listschecked' => [
241 'type' => 'array',
242 ],
243 'hiddenlists' => [
244 'type' => 'array',
245 ],
246 'fields' => [
247 'type' => 'array',
248 ],
249 'introtext' => [
250 'type' => 'string',
251 ],
252 'posttext' => [
253 'type' => 'string',
254 ],
255 'source' => [
256 'type' => 'string',
257 'default' => 'gutenberg_profile',
258 ],
259 ],
260 ]
261 );
262 }
263
264
265 public function renderCallbackProfile($block_attributes, $content)
266 {
267 $params = new AcymParameter($block_attributes);
268
269 return acym_renderFormProfile(
270 $params,
271 ['disableButtons' => strpos(acym_currentURL(), 'block-renderer') !== false]
272 );
273 }
274
275 public function registerBlockArchive()
276 {
277 if (!function_exists('register_block_type')) return;
278
279 wp_register_script(
280 'gutenberg-acymailing-archive',
281 ACYM_JS.'gutenberg/archive.min.js?time='.time()
282 );
283 wp_add_inline_script(
284 'gutenberg-acymailing-archive',
285 'var acym_lists_archive = '.json_encode($this->lists).';
286 var ACYM_JS_TXT = '.acym_getJSMessages()
287 );
288
289 register_block_type(
290 'acymailing/archive',
291 [
292 'apiVersion' => 2,
293 'editor_script' => 'gutenberg-acymailing-archive',
294 'render_callback' => [$this, 'renderCallbackArchive'],
295 'attributes' => [
296 'title' => [
297 'type' => 'string',
298 'default' => 'See all newsletters',
299 ],
300 'archiveNbNewslettersPerPage' => [
301 'type' => 'string',
302 'default' => '20',
303 ],
304 'lists' => [
305 'type' => 'array',
306 ],
307 'popup' => [
308 'type' => 'array',
309 ],
310 'displayUserListOnly' => [
311 'type' => 'array',
312 ],
313 ],
314 ]
315 );
316 }
317
318
319 public function renderCallbackArchive($block_attributes, $content)
320 {
321 $params = new AcymParameter($block_attributes);
322
323 return acym_renderFormArchive(
324 $params,
325 ['disableButtons' => strpos(acym_currentURL(), 'block-renderer') !== false]
326 );
327 }
328 }
329