PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.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.2.2, at WpInit/Gutenberg.php

321 lines 10.1 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 'unsub' => [
94 'type' => 'string',
95 'default' => '0',
96 ],
97 'unsubtext' => [
98 'type' => 'string',
99 'default' => 'Unsubscribe',
100 ],
101 'unsubredirect' => [
102 'type' => 'string',
103 ],
104 'successmode' => [
105 'type' => 'string',
106 'default' => 'replace',
107 ],
108
109 'redirect' => [
110 'type' => 'string',
111 ],
112 'userinfo' => [
113 'type' => 'string',
114 'default' => '1',
115 ],
116 'introtext' => [
117 'type' => 'string',
118 ],
119 'posttext' => [
120 'type' => 'string',
121 ],
122 'alignment' => [
123 'type' => 'string',
124 'default' => 'none',
125 ],
126 'source' => [
127 'type' => 'string',
128 'default' => 'gutenberg_subscription_form',
129 ],
130 ];
131 $moreAttributes = [];
132 if (acym_isMultilingual()) {
133 foreach (acym_getMultilingualLanguages() as &$language) {
134 $moreAttributes['subtext_'.$language->language] = ['type' => 'string', 'default' => 'Subscribe'];
135 $moreAttributes['subtextlogged_'.$language->language] = ['type' => 'string', 'default' => 'Subscribe'];
136 $moreAttributes['confirmation_message_'.$language->language] = ['type' => 'string', 'default' => ''];
137 }
138 } else {
139 $moreAttributes['subtext'] = [
140 'type' => 'string',
141 'default' => 'Subscribe',
142 ];
143 $moreAttributes['subtextlogged'] = [
144 'type' => 'string',
145 'default' => 'Subscribe',
146 ];
147 $moreAttributes['confirmation_message'] = [
148 'type' => 'string',
149 'default' => '',
150
151 ];
152 }
153 $attributes = array_merge($basicAttribute, $moreAttributes);
154
155 register_block_type(
156 'acymailing/subscription-form',
157 [
158 'apiVersion' => 2,
159 'editor_script' => 'gutenberg-acymailing-subscription-form',
160 'render_callback' => [$this, 'renderCallback'],
161 'attributes' => $attributes,
162 ]
163 );
164 }
165
166 public function registerAcymCategory($categories, $post)
167 {
168 return array_merge(
169 $categories,
170 [
171 [
172 'slug' => 'acymailing',
173 'title' => 'AcyMailing',
174 'icon' => 'editor-table',
175 ],
176 ]
177 );
178 }
179
180 public function renderCallback($block_attributes, $content)
181 {
182 if (!array_key_exists('subtext', $block_attributes)) {
183 $moreBlockAttributes = [];
184 $currentLanguage = strtolower('subtext_'.acym_getLanguageTag());
185 $currentLanguageLogged = strtolower('subtextlogged_'.acym_getLanguageTag());
186 $confirmMessageLangue = strtolower('confirmation_message_'.acym_getLanguageTag());
187 $moreBlockAttributes['subtext'] = $block_attributes[$currentLanguage];
188 $moreBlockAttributes['subtextlogged'] = $block_attributes[$currentLanguageLogged];
189 $moreBlockAttributes['confirmation_message'] = $block_attributes[$confirmMessageLangue];
190 $block_attributes = array_merge($block_attributes, $moreBlockAttributes);
191 }
192 $params = new AcymParameter($block_attributes);
193
194 return acym_renderForm(
195 $params,
196 ['disableButtons' => strpos(acym_currentURL(), 'block-renderer') !== false]
197 );
198 }
199
200 public function registerBlockProfile()
201 {
202 if (!function_exists('register_block_type')) return;
203
204 wp_register_script(
205 'gutenberg-acymailing-profile',
206 ACYM_JS.'gutenberg/profile.min.js?time='.time()
207 );
208 wp_add_inline_script(
209 'gutenberg-acymailing-profile',
210 'var acym_lists_profile = '.json_encode($this->lists).';
211 var ACYM_JS_TXT = '.acym_getJSMessages().';
212 var acym_fields_profile = '.json_encode($this->fields)
213 );
214
215 register_block_type(
216 'acymailing/profile',
217 [
218 'apiVersion' => 2,
219 'editor_script' => 'gutenberg-acymailing-profile',
220 'render_callback' => [$this, 'renderCallbackProfile'],
221 'attributes' => [
222 'title' => [
223 'type' => 'string',
224 'default' => 'Profile',
225 ],
226 'lists' => [
227 'type' => 'array',
228 ],
229 'listsdropdown' => [
230 'type' => 'array',
231 ],
232 'listschecked' => [
233 'type' => 'array',
234 ],
235 'hiddenlists' => [
236 'type' => 'array',
237 ],
238 'fields' => [
239 'type' => 'array',
240 ],
241 'introtext' => [
242 'type' => 'string',
243 ],
244 'posttext' => [
245 'type' => 'string',
246 ],
247 'source' => [
248 'type' => 'string',
249 'default' => 'gutenberg_profile',
250 ],
251 ],
252 ]
253 );
254 }
255
256
257 public function renderCallbackProfile($block_attributes, $content)
258 {
259 $params = new AcymParameter($block_attributes);
260
261 return acym_renderFormProfile(
262 $params,
263 ['disableButtons' => strpos(acym_currentURL(), 'block-renderer') !== false]
264 );
265 }
266
267 public function registerBlockArchive()
268 {
269 if (!function_exists('register_block_type')) return;
270
271 wp_register_script(
272 'gutenberg-acymailing-archive',
273 ACYM_JS.'gutenberg/archive.min.js?time='.time()
274 );
275 wp_add_inline_script(
276 'gutenberg-acymailing-archive',
277 'var acym_lists_archive = '.json_encode($this->lists).';
278 var ACYM_JS_TXT = '.acym_getJSMessages()
279 );
280
281 register_block_type(
282 'acymailing/archive',
283 [
284 'apiVersion' => 2,
285 'editor_script' => 'gutenberg-acymailing-archive',
286 'render_callback' => [$this, 'renderCallbackArchive'],
287 'attributes' => [
288 'title' => [
289 'type' => 'string',
290 'default' => 'See all newsletters',
291 ],
292 'archiveNbNewslettersPerPage' => [
293 'type' => 'string',
294 'default' => '20',
295 ],
296 'lists' => [
297 'type' => 'array',
298 ],
299 'popup' => [
300 'type' => 'array',
301 ],
302 'displayUserListOnly' => [
303 'type' => 'array',
304 ],
305 ],
306 ]
307 );
308 }
309
310
311 public function renderCallbackArchive($block_attributes, $content)
312 {
313 $params = new AcymParameter($block_attributes);
314
315 return acym_renderFormArchive(
316 $params,
317 ['disableButtons' => strpos(acym_currentURL(), 'block-renderer') !== false]
318 );
319 }
320 }
321