PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.9
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.9
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / Extensions / PressBar / PressBar.php

PressBar.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.9, at includes/Extensions/PressBar/PressBar.php

2,277 lines 99.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * PressBar Extension
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Extensions\PressBar;
10
11 use NotificationX\Core\Analytics;
12 use NotificationX\Core\GetData;
13 use NotificationX\Core\Helper;
14 use NotificationX\Core\PostType;
15 use NotificationX\Core\Rules;
16 use NotificationX\Extensions\Extension;
17 use NotificationX\Extensions\GlobalFields;
18 use NotificationX\FrontEnd\Preview;
19 use NotificationX\GetInstance;
20
21 use Elementor\Core\Files\CSS\Post as Post_CSS;
22 use NotificationX\Admin\InfoTooltipManager;
23 use NotificationX\NotificationX;
24
25 /**
26 * PressBar Extension
27 * @method static PressBar get_instance($args = null)
28 */
29 class PressBar extends Extension {
30 /**
31 * Instance of Admin
32 *
33 * @var Admin
34 */
35 use GetInstance;
36
37 public $priority = 5;
38 public $id = 'press_bar';
39 public $doc_link = 'https://notificationx.com/docs/notification-bar/';
40 public $types = 'notification_bar';
41 public $module = 'modules_bar';
42 public $module_priority = 1;
43 public $default_theme = 'press_bar_theme-two';
44 public $bar_themes;
45 public $block_themes;
46 public $popup = array();
47
48 /**
49 * Initially Invoked when initialized.
50 */
51 public function __construct() {
52 parent::__construct();
53 add_action('init', [$this, 'register_post_type']);
54 add_action('init', [$this, 'load_plugin_dependencies'], -1);
55 add_filter( 'get_edit_post_link', function($link, $id){
56 $post = get_post( $id );
57 if ( $post && 'nx_bar' === $post->post_type && class_exists('\Elementor\Plugin') ) {
58 return \Elementor\Plugin::$instance->documents->get($id)->get_edit_url();
59 }
60 return $link;
61 }, 10, 3 );
62 }
63
64 public function init_extension()
65 {
66 $this->title = __('Press Bar', 'notificationx');
67 $this->module_title = __('Notification Bar', 'notificationx');
68 $this->themes = [
69 'theme-two' => [
70 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-two.jpg',
71 'column' => "12",
72 'defaults' => [
73 'enable_countdown' => 0,
74 'nx_bar_border_radius_left' => 0,
75 'nx_bar_border_radius_right' => 0,
76 'nx_bar_border_radius_top' => 0,
77 'nx_bar_border_radius_bottom' => 0,
78 'button_icon' => 'none',
79 'bar_bg_color' => '#5807a2',
80 'press_content' => __('<b>We\'re excited to introduce something new!</b>','notificationx'),
81 'button_text' => __('Show Me!', 'notificationx'),
82 'link_button_bg_color' => '#9c2bff',
83 'link_button_text_color' => '#ffffff',
84 'bar_counter_bg' => '',
85 ],
86 ],
87 'theme-one' => [
88 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-one.jpg',
89 'column' => "12",
90 'defaults' => [
91 'enable_countdown' => 1,
92 'nx_bar_border_radius_left' => 0,
93 'nx_bar_border_radius_right' => 0,
94 'nx_bar_border_radius_top' => 0,
95 'nx_bar_border_radius_bottom' => 0,
96 'button_icon' => 'none',
97 'bar_bg_color' => '#dddddd',
98 'press_content' => __('<p style="color: #000;"><span>Save Big & Get Lifetime unlimited</span> <strong>NotificationX</strong> for $99!</p>','notificationx'),
99 'button_text' => __('Get Offer', 'notificationx'),
100 'link_button_bg_color' => '#000',
101 'link_button_text_color' => '#ffffff',
102 'bar_counter_bg' => '#262626',
103 'bar_counter_text_color' => '#fff'
104 ],
105 ],
106 'theme-three' => [
107 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-three.jpg',
108 'column' => "12",
109 'defaults' => [
110 'enable_countdown' => 1,
111 'nx_bar_border_radius_left' => 0,
112 'nx_bar_border_radius_right' => 0,
113 'nx_bar_border_radius_top' => 0,
114 'nx_bar_border_radius_bottom' => 0,
115 'button_icon' => 'none',
116 'bar_bg_color' => '#3f4462',
117 'press_content' => __('<b>Save Big & Get Lifetime unlimited <strong>NotificationX</strong> for $99</b>','notificationx'),
118 'button_text' => __('Get Offer!', 'notificationx'),
119 'link_button_bg_color' => '#6A4BFF',
120 'link_button_text_color' => '#ffffff',
121 'bar_counter_bg' => '#6549fe',
122 'bar_counter_text_color' => '#fff',
123 ],
124 ],
125 'theme-four' => [
126 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-four-preview.webp',
127 'column' => "12",
128 'defaults' => [
129 'enable_countdown' => 1,
130 'press_content' => __('<p><span style="color: #F54747;">4 Years</span> Of Seamlessly Creating NotificationX!</p>','notificationx'),
131 'button_text' => __('Grab Deal Now', 'notificationx'),
132 'link_button_bg_color' => '#ffffff',
133 'link_button_text_color' => '#000',
134 'nx_bar_border_radius_left' => 16,
135 'nx_bar_border_radius_right' => 16,
136 'nx_bar_border_radius_top' => 16,
137 'nx_bar_border_radius_bottom' => 16,
138 'button_icon' => 'none',
139 'bar_counter_bg' => 'rgba(255, 255, 255, 0.5019607843)',
140 'bar_counter_text_color' => '#230600',
141 ],
142 ],
143 'theme-five' => [
144 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-five-preview.webp',
145 'column' => "12",
146 'defaults' => [
147 'press_content' => __('<p><span style="color: #fff;">🎁 Flash 30%</span> Sale is On Now! Don’t miss out on this opportunity</p>','notificationx'),
148 'enable_countdown' => 1,
149 'nx_bar_border_radius_left' => 16,
150 'nx_bar_border_radius_right' => 16,
151 'nx_bar_border_radius_top' => 16,
152 'nx_bar_border_radius_bottom' => 16,
153 'button_icon' => 'none',
154 'button_text' => __('Save $20', 'notificationx'),
155 'link_button_bg_color' => '#2e72ff',
156 'link_button_text_color' => '#ffffff',
157 'bar_bg_color' => '',
158 'bar_counter_bg' => 'transparent',
159 'bar_counter_text_color' => '#fff',
160 ],
161 ],
162 'theme-six' => [
163 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-six-preview.webp',
164 'column' => "12",
165 'defaults' => [
166 'press_content' => __('<p><span style="color: #000;">🎁 Flash 30%</span> Sale is On Now! Don’t miss out on this opportunity</p>','notificationx'),
167 'enable_countdown' => 1,
168 'nx_bar_border_radius_left' => 16,
169 'nx_bar_border_radius_right' => 16,
170 'nx_bar_border_radius_top' => 16,
171 'nx_bar_border_radius_bottom' => 16,
172 'button_text' => __('Shop Now', 'notificationx'),
173 'bar_bg_color' => 'linear-gradient(90deg, #94F9FC 0%, #E2DAFE 100%)',
174 'button_icon' => 'shop-icon.svg',
175 'bar_counter_bg' => 'rgba(255, 255, 255, 0.5019607843)',
176 'bar_counter_text_color' => '#230600',
177 ],
178 ],
179 'theme-seven' => [
180 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/press_bar_theme-seven-preview.webp',
181 'column' => "12",
182 'defaults' => [
183 'press_content' => __('<p><span style="color: #9F7800;">4 years</span> Of Seamlessly Creating NotificationX!</p>','notificationx'),
184 'enable_countdown' => 0,
185 'nx_bar_border_radius_left' => 0,
186 'nx_bar_border_radius_right' => 0,
187 'nx_bar_border_radius_top' => 0,
188 'nx_bar_border_radius_bottom' => 0,
189 'button_text' => __('Shop Now', 'notificationx'),
190 'bar_bg_color' => '#F4F1E8',
191 'button_icon' => 'shop_now.svg',
192 'link_button_bg_color' => '#e3dac2',
193 'link_button_text_color' => '#000',
194 'bar_counter_bg' => '',
195 ],
196 ],
197 ];
198 $this->bar_themes = array(
199 'theme-one' => [
200 'label' => 'theme-one',
201 'value' => 'theme-one',
202 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-one.jpg',
203 'column' => '12',
204 "title" => "Nx Theme One",
205 'enable_coupon' => true,
206 ],
207 'theme-two' => [
208 'label' => 'theme-two',
209 'value' => 'theme-two',
210 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-two.jpg',
211 'column' => '12',
212 "title" => "Nx Theme Two",
213 ],
214 'theme-three' => [
215 'label' => 'theme-three',
216 'value' => 'theme-three',
217 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-three.jpg',
218 'column' => '12',
219 "title" => "Nx Theme Three",
220 ],
221 'theme-four' => [
222 'label' => 'theme-four',
223 'value' => 'theme-four',
224 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-four.jpg',
225 'column' => '12',
226 "title" => "Theme Four - Cookies Layout",
227 ],
228 'theme-five' => [
229 'label' => 'theme-five',
230 'value' => 'theme-five',
231 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-elementor/theme-five.jpg',
232 'column' => '12',
233 "title" => "Theme Five - Cookies Layout",
234 ],
235 );
236 $this->block_themes = array(
237 'theme-one' => [
238 'label' => 'theme-one',
239 'value' => 'theme-one',
240 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-one.png',
241 'column' => '12',
242 "title" => "Nx Theme One",
243 'position' => 'top',
244 ],
245 'theme-two' => [
246 'label' => 'theme-two',
247 'value' => 'theme-two',
248 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-two.png',
249 'column' => '12',
250 "title" => "Nx Theme Two",
251 'position' => 'top',
252 ],
253 'theme-three' => [
254 'label' => 'theme-three',
255 'value' => 'theme-three',
256 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-three.png',
257 'column' => '12',
258 "title" => "Nx Theme Three",
259 'position' => 'top',
260 ],
261 'theme-four' => [
262 'label' => 'theme-four',
263 'value' => 'theme-four',
264 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/bar-gutenberg/theme-four.png',
265 'column' => '12',
266 "title" => "Nx Theme Four",
267 'position' => 'top',
268 ],
269 'theme-five' => [
270 'label' => 'theme-five',
271 'value' => 'theme-five',
272 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-one.jpg',
273 'column' => '12',
274 "title" => "Nx Theme Five",
275 "popup" => $this->popup,
276 'position' => 'top',
277 ],
278 'theme-six' => [
279 'label' => 'theme-six',
280 'value' => 'theme-six',
281 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-two.jpg',
282 'column' => '12',
283 "title" => "Nx Theme Six",
284 "popup" => $this->popup,
285 'position' => 'top',
286 ],
287 'theme-seven' => [
288 'label' => 'theme-seven',
289 'value' => 'theme-seven',
290 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/nx-bar-theme-three.jpg',
291 'column' => '12',
292 "title" => "Nx Theme Seven",
293 "popup" => $this->popup,
294 'position' => 'top',
295 ],
296 );
297 // check if essential blocks is installed.
298 }
299
300 public function init() {
301 parent::init();
302 add_filter("nx_theme_preview_{$this->id}", [$this, 'theme_preview'], 10, 2);
303 add_filter("nx_get_post", [$this, 'nx_get_post'], 9);
304 add_filter("nx_delete_post", [$this, 'nx_delete_post'], 10, 2);
305 add_filter("nx_filtered_post", [$this, 'add_scripts'], 10, 2);
306 }
307
308 /**
309 * This functions is hooked
310 *
311 * @return void
312 */
313 public function admin_actions() {
314 parent::admin_actions();
315 add_filter('templately_cloud_push_post_type', [$this, 'templately_cloud_push_post_type']);
316 }
317
318 /**
319 * This functions is hooked
320 *
321 * @hooked nx_public_action
322 * @return void
323 */
324 public function public_actions() {
325 parent::public_actions();
326 // add_action('wp_head', [$this, 'print_bar_notice'], 100);
327 add_filter("nx_filtered_data_{$this->id}", array($this, 'insert_views'), 11, 3);
328 add_filter("rocket_rucss_safelist", array($this, 'rocket_rucss_safelist'), 11);
329 }
330
331
332 public function init_fields() {
333 parent::init_fields();
334 add_filter('nx_design_tab_fields', [$this, 'design_tab_fields']);
335 add_filter('nx_design_tab_fields', [$this, 'design_tab_presets_fields']);
336 add_filter('nx_design_tab_fields', [$this, 'design_tab_fields_for_button'], 20);
337 add_filter('nx_customize_fields', [$this, 'customize_fields']);
338 add_filter('nx_content_fields', [$this, 'content_fields'], 22);
339 add_filter('nx_display_fields', [$this, 'hide_image_field']);
340 add_filter('nx_display_fields', [$this, 'display_fields']);
341 add_filter('nx_source_trigger', [$this, '_source_trigger'], 20);
342 }
343
344 public function save_post($post, $data, $nx_id) {
345 unset($post['data']['is_elementor']);
346 unset($post['data']['is_confirmed']);
347 unset($post['data']['is_gutenberg']);
348 unset($post['data']['is_gb_confirmed']);
349 $post['data']['countdown_start_date'] = !empty( $data['countdown_start_date'] ) ? Helper::mysql_time($data['countdown_start_date']) : '';
350 $post['data']['countdown_end_date'] = !empty( $data['countdown_end_date'] ) ? Helper::mysql_time($data['countdown_end_date']) : '';
351 $post['data']['countdown_rand'] = rand();
352 return $post;
353 }
354
355 public function saved_post($post, $data, $nx_id) {
356 if(!empty($data['elementor_id'])){
357 $title = !empty($post['title']) ? $post['title'] : $nx_id;
358 $my_post = array(
359 'ID' => $data['elementor_id'],
360 'post_title' => "NxBar: " . $title,
361 );
362 wp_update_post( $my_post );
363 }
364 }
365
366 public function theme_preview($url, $post) {
367 if ( !empty($post['gutenberg_id']) && !empty($post['gutenberg_bar_theme']) && !empty($this->block_themes[$post['gutenberg_bar_theme']])) {
368 return $this->block_themes[$post['gutenberg_bar_theme']]['icon'];
369 }
370 if (!empty($post['elementor_id']) && !empty($post['elementor_bar_theme']) && !empty($this->bar_themes[$post['elementor_bar_theme']])) {
371 return $this->bar_themes[$post['elementor_bar_theme']]['icon'];
372 }
373 return $url;
374 }
375
376 /**
377 * Get themes for the extension.
378 *
379 *
380 * @param array $args Settings arguments.
381 * @return mixed
382 */
383 public function insert_views($content, $settings) {
384 Analytics::get_instance()->insert_views([], $settings);
385 return $content;
386 }
387
388 /**
389 * Get themes for the extension.
390 *
391 *
392 * @param array $args Settings arguments.
393 * @return mixed
394 */
395 public function _source_trigger($triggers) {
396 $triggers[$this->id]['position'] = "@position:top";
397 return $triggers;
398 }
399
400 /**
401 * NX Bar Presets tab fields for button.
402 *
403 * @param array $fields
404 * @return array
405 */
406 public function design_tab_presets_fields($fields) {
407 $import_design = [];
408 $import_design = &$fields['themes']['fields']['themes_section']['fields']['themes_tab']['fields'];
409 $import_design[] = [
410 'label' => __("Presets", 'notificationx'),
411 'name' => 'for_desktop',
412 'id' => 'for_desktop',
413 'type' => 'section',
414 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/icons/nxbar-presets-icon.svg',
415 'rules' => Rules::is('source', $this->id),
416 ];
417 $import_design[] = [
418 'label' => __("Custom", 'notificationx'),
419 'name' => 'nxbar_custom',
420 'id' => 'nxbar_custom',
421 'type' => 'section',
422 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/icons/nxbar-custom-tab.svg',
423 'rules' => Rules::is('source', $this->id),
424 'fields' => [
425 'nxbar_custom' => [
426 'label' => __("Custom", 'notificationx'),
427 'name' => 'nxbar_custom',
428 'id' => 'nxbar_custom',
429 'type' => 'section',
430 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/responsive/desktop.svg',
431 'fields' => [
432 'nxbar_custom_fields' => [
433 'name' => "nxbar_custom_fields",
434 'type' => "nxbar-custom",
435 'label' => __('NX Bar', 'notificationx'),
436 'priority' => 10,
437 ],
438 ]
439 ],
440 ]
441 ];
442 $import_design[] = [
443 'label' => __("Build With AI", 'notificationx'),
444 'name' => 'nxbar_build_with_ai',
445 'id' => 'nxbar_build_with_ai',
446 'type' => 'section',
447 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/icons/build-with-ai-icon.svg',
448 'rules' => Rules::is('source', $this->id),
449 'fields' => [
450 'nxbar_build_with_ai' => [
451 'label' => __("Build With AI", 'notificationx'),
452 'name' => 'nxbar_build_with_ai',
453 'id' => 'nxbar_build_with_ai',
454 'type' => 'section',
455 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/responsive/desktop.svg',
456 'fields' => [
457 'nxbar_build_with_ai_fields' => [
458 'name' => "nxbar_build_with_ai_fields",
459 'type' => "nxbar-build_with_ai",
460 'label' => __('NX Bar', 'notificationx'),
461 'priority' => 10,
462 ],
463 ]
464 ],
465 ]
466 ];
467 return $fields;
468 }
469
470 /**
471 * NX Bar design tab fields for button.
472 *
473 * @param array $fields
474 * @return array
475 */
476 public function design_tab_fields_for_button($fields) {
477 $_fields = &$fields['advance_design_section']['fields'];
478 $border_fields = [
479 'nx_bar_border_radius' => [
480 'name' => "nx_bar_border_radius",
481 'type' => "section",
482 'label' => __('Border Radius', 'notificationx'),
483 'fields' => [
484 [
485 'help' => __('Left', 'notificationx'),
486 'name' => "nx_bar_border_radius_left",
487 'type' => "number",
488 'default' => '0',
489 'description' => 'px',
490 ],
491 [
492 'help' => __('Right', 'notificationx'),
493 'name' => "nx_bar_border_radius_right",
494 'type' => "number",
495 'default' => '0',
496 'description' => 'px',
497 ],
498 [
499 'help' => __('Top', 'notificationx'),
500 'name' => "nx_bar_border_radius_top",
501 'type' => "number",
502 'default' => '0',
503 'description' => 'px',
504 ],
505 [
506 'help' => __('Bottom', 'notificationx'),
507 'name' => "nx_bar_border_radius_bottom",
508 'type' => "number",
509 'default' => '0',
510 'description' => 'px',
511 ],
512 ]
513 ],
514 ];
515 if( !empty($_fields['link_button_design']['fields'] ) ) {
516 $_fields['link_button_design']['fields'] = array_merge( $_fields['link_button_design']['fields'], $border_fields);
517 }
518 return $fields;
519 }
520
521 /**
522 * This method is an implementable method for All Extension coming forward.
523 *
524 * @param array $args Settings arguments.
525 * @return mixed
526 */
527 public function design_tab_fields($fields) {
528 $_fields = &$fields['advance_design_section']['fields'];
529 $_fields['design'] = Rules::is('source', $this->id, true, $_fields['design']);
530 $_fields['typography'] = Rules::is('source', $this->id, true, $_fields['typography']);
531 $_fields['image-appearance'] = Rules::is('source', $this->id, true, $_fields['image-appearance']);
532 $_fields['bar_editor'] = [
533 'label' => "Editor",
534 'name' => "bar_editor",
535 'type' => "section",
536 'priority' => 2,
537 'rules' => ["and", ['is', 'source', $this->id], ['is', 'advance_edit', true]],
538 'fields' => [],
539 ];
540 $_fields["bar_design"] = [
541 // @todo Move to extension.
542 'label' => "Design",
543 'name' => "bar_design",
544 'type' => "section",
545 'priority' => 5,
546 'rules' => ["and", ['is', 'source', $this->id], ['is', 'advance_edit', true]],
547 'fields' => [
548 [
549 'label' => __('Background Color', 'notificationx'),
550 'name' => "bar_bg_color",
551 'type' => "gradientpicker",
552 ],
553 [
554 'label' => __("Background Image", 'notificationx'),
555 'name' => "bar_bg_image",
556 'button' => __('Upload', 'notificationx'),
557 'type' => "media",
558 'default' => "",
559 ],
560 [
561 'label' => __('Text Color', 'notificationx'),
562 'name' => "bar_text_color",
563 'type' => "colorpicker",
564 ],
565 // [
566 // 'label' => __('Button Background Color', 'notificationx'),
567 // 'name' => "bar_btn_bg",
568 // 'type' => "colorpicker",
569 // ],
570 // [
571 // 'label' => __('Button Text Color', 'notificationx'),
572 // 'name' => "bar_btn_text_color",
573 // 'type' => "colorpicker",
574 // ],
575 [
576 'label' => __('Countdown Background Color', 'notificationx'),
577 'name' => "bar_counter_bg",
578 'type' => "colorpicker",
579 ],
580 [
581 'label' => __('Countdown Text Color', 'notificationx'),
582 'name' => "bar_counter_text_color",
583 'type' => "colorpicker",
584 ],
585 [
586 'label' => __('Close Button Color', 'notificationx'),
587 'name' => "bar_close_color",
588 'type' => "colorpicker",
589 ],
590 [
591 'label' => __('Close Button Size', 'notificationx'),
592 'name' => "bar_close_button_size",
593 'type' => "number",
594 'default' => '10',
595 'description' => 'px',
596 ],
597 [
598 'name' => "close_button_section",
599 'type' => "section",
600 'fields' => [
601 [
602 'name' => 'closed_button_section_label',
603 'type' => 'section',
604 'fields' => [
605 [
606 'name' => 'closed_button_section_label_text',
607 'type' => 'message',
608 'class' => 'nx-close-button-label',
609 'html' => true,
610 'message' => __('Close Button Position', 'notificationx'),
611 ]
612 ]
613 ],
614 [
615 'name' => 'closed_button_section_fields',
616 'type' => 'section',
617 'fields' => [
618 [
619 'label' => __('Close Button Position', 'notificationx'),
620 'name' => "bar_close_position",
621 'type' => "select",
622 'default' => 'right',
623 'options' => GlobalFields::get_instance()->normalize_fields([
624 'left' => __('Left', 'notificationx'),
625 'right' => __('Right', 'notificationx'),
626 ]),
627 ],
628 [
629 'label' => __('Close Button Position Top', 'notificationx'),
630 'help' => __('Top', 'notificationx'),
631 'name' => "bar_position_left_top",
632 'type' => "number",
633 'default' => '15',
634 'description' => 'px',
635 'rules' => Rules::logicalRule([
636 Rules::is('bar_close_position', 'left'),
637 ]),
638 ],
639 [
640 'label' => __('Close Button Position Left', 'notificationx'),
641 'help' => __('Left', 'notificationx'),
642 'name' => "bar_position_left_left",
643 'type' => "number",
644 'default' => '15',
645 'description' => 'px',
646 'rules' => Rules::logicalRule([
647 Rules::is('bar_close_position', 'left'),
648 ]),
649 ],
650 [
651 'label' => __('Close Button Position Top', 'notificationx'),
652 'help' => __('Top', 'notificationx'),
653 'name' => "bar_position_right_top",
654 'type' => "number",
655 'default' => '15',
656 'description' => 'px',
657 'rules' => Rules::logicalRule([
658 Rules::is('bar_close_position', 'right'),
659 ]),
660 ],
661 [
662 'label' => __('Close Button Position Right', 'notificationx'),
663 'help' => __('Right', 'notificationx'),
664 'name' => "bar_position_right_right",
665 'type' => "number",
666 'default' => '15',
667 'description' => 'px',
668 'rules' => Rules::logicalRule([
669 Rules::is('bar_close_position', 'right'),
670 ]),
671 ],
672 ]
673 ]
674 ]
675 ],
676 ],
677 ];
678
679 $_fields["bar_typography"] = [
680 // @todo Move to extension.
681 'label' => __('Typography', 'notificationx'),
682 'name' => "bar_typography",
683 'type' => "section",
684 'priority' => 10,
685 'rules' => ["and", ['is', 'source', $this->id], ['is', 'advance_edit', true]],
686 'fields' => [
687 [
688 'label' => __('Font Size', 'notificationx'),
689 'name' => "bar_font_size",
690 'type' => "number",
691 'default' => '13',
692 'min' => 1,
693 'priority' => 5,
694 'description' => 'px',
695 'help' => __('This font size will be applied for <mark>first</mark> row', 'notificationx'),
696 ],
697 ],
698 ];
699
700 $is_installed = Helper::is_plugin_installed('elementor/elementor.php');
701 $install_activate_text = $is_installed ? __("Activate", 'notificationx') : __("Install", 'notificationx');
702
703
704
705 // $fields['themes']['fields'][] = array(
706 // 'name' => 'nx-bar_with_elementor_install_message',
707 // 'type' => 'message',
708 // 'class' => 'nx-warning',
709 // 'html' => true,
710 // 'message' => sprintf(__("To Design Notification Bar with <strong>Elementor Page Builder</strong>, You need to %s the Elementor first: &nbsp;&nbsp;&nbsp;", 'notificationx'), $install_activate_text),
711 // 'rules' => Rules::logicalRule([
712 // Rules::is('is_elementor', false),
713 // Rules::is('gutenberg_id', false),
714 // Rules::is('source', $this->id),
715 // ]),
716 // );
717
718 $fields['themes']['fields']['nxbar_with_elementor'] = [
719 'name' => 'nxbar_with_elementor',
720 'type' => 'section',
721 'fields' => [],
722 'rules' => Rules::logicalRule([
723 Rules::is('elementor_edit_link', false, true),
724 Rules::isOfType('elementor_edit_link', 'string'),
725 Rules:: is('elementor_id', false, true),
726 ]),
727 ];
728
729 $fields['themes']['fields']['nxbar_with_gutenberg'] = [
730 'name' => 'nxbar_with_gutenberg',
731 'type' => 'section',
732 'fields' => [],
733 'rules' => Rules::logicalRule([
734 Rules::is('gutenberg_edit_link', false, true),
735 Rules::isOfType('gutenberg_edit_link', 'string'),
736 Rules:: is('gutenberg_id', false, true),
737 ]),
738 ];
739
740 $fields['themes']['fields']['nx_bar_import_design'] = [
741 'name' => 'nx_bar_import_design',
742 'type' => 'section',
743 'fields' => [],
744 'rules' => Rules::logicalRule([
745 Rules:: is('source', $this->id),
746 ]),
747 ];
748
749 $import_design = [];
750 // $import_design = $fields['advance_design_section']['fields'];
751 $import_design = &$fields['themes']['fields']['nx_bar_import_design']['fields'];
752
753 $import_design[] = [
754 'name' => 'elementor_edit_link',
755 'type' => 'button',
756 'text' => __('Edit With Elementor', 'notificationx'),
757 'href' => -1,
758 'priority' => 1,
759 'target' => '_blank',
760 'rules' => Rules::logicalRule([
761 Rules::is('elementor_edit_link', false, true),
762 Rules::isOfType('elementor_edit_link', 'string'),
763 Rules:: is('elementor_id', false, true),
764 // Rules:: is('is_elementor', true),
765 // Rules:: is('source', $this->id),
766 ]),
767 ];
768 $import_design[] = [
769 'name' => 'nx-bar_with_elementor-remove',
770 'type' => 'button',
771 'priority' => 2,
772 'text' => __('Remove', 'notificationx'),
773 'rules' => Rules::logicalRule([
774 Rules::is('elementor_id', false, true),
775 Rules::is('is_elementor', true),
776 Rules::is('source', $this->id),
777 ]),
778 'ajax' => [
779 'on' => 'click',
780 'api' => '/notificationx/v1/elementor/remove',
781 'data' => [
782 'elementor_id' => '@elementor_id',
783 ],
784 'hideSwal' => true,
785 ],
786 'trigger' => [
787 [
788 'type' => 'setFieldValue',
789 'action' => [
790 'elementor_id' => false,
791 'elementor_edit_link' => '',
792 'is_confirmed' => false,
793 'themes' => 'press_bar_theme-one',
794 ]
795 ],
796 ],
797 ];
798
799 $import_design[] = [
800 'name' => 'nx-bar_with_elementor',
801 'type' => 'modal',
802 'button' => [
803 'name' => 'build_with_elementor',
804 'text' => __('Build With Elementor', 'notificationx'),
805 'trigger' => [
806 [
807 'type' => 'setFieldValue',
808 'action' => [
809 'import_elementor_theme' => false
810 ]
811 ],
812 ],
813 ],
814 'confirm_button' => [
815 'type' => 'button',
816 'name' => 'import_elementor_theme',
817 'group' => true,
818 'fields' => [
819 [
820 'type' => 'button',
821 'name' => 'import_elementor_theme',
822 "default" => false,
823 'text' => [
824 'normal' => __('Import', 'notificationx'),
825 'saved' => __('Import', 'notificationx'),
826 'loading' => __('Importing...', 'notificationx'),
827 ],
828 'ajax' => [
829 'on' => 'click',
830 'api' => '/notificationx/v1/elementor/import',
831 'data' => [
832 'theme_id' => '@elementor_bar_theme',
833 ],
834 'trigger' => '@is_confirmed:true',
835 'hideSwal' => true,
836 ],
837 'rules' => Rules::is('is_confirmed', true, true),
838 ],
839 [
840 'type' => 'button',
841 'name' => 'import_elementor_theme_next',
842 "default" => false,
843 'text' => __('Next', 'notificationx'),
844 'rules' => Rules::is('is_confirmed', true),
845 'trigger' => [
846 [
847 'type' => 'setContext',
848 'action' => [
849 'config.active' => 'display_tab'
850 ]
851 ],
852 [
853 'type' => 'setFieldValue',
854 'action' => [
855 'import_elementor_theme_next' => true
856 ]
857 ],
858 ],
859 ],
860 ],
861 ],
862 'cancel' => "import_elementor_theme_next",
863 'body' => [
864 'header' => __('Choose Your ', 'notificationx'),
865 'fields' => [
866 'themes' => [
867 'type' => 'radio-card',
868 'name' => "elementor_bar_theme",
869 'style' => [
870 'label' => [
871 'position' => 'top'
872 ]
873 ],
874 'rules' => Rules::is('is_confirmed', true, true),
875 'default' => 'theme-one',
876 'options' => $this->bar_themes,
877 ],
878 'test' => [
879 'name' => 'builder_modal_message',
880 'type' => 'message',
881 'message' => 'Hello World',
882 'rules' => Rules::is('is_confirmed', true)
883 ]
884 ],
885 ],
886 'rules' => Rules::logicalRule([
887 Rules::is('gutenberg_id', false),
888 Rules::is('elementor_id', false),
889 Rules::is('is_elementor', true),
890 Rules::is('is_confirmed', true, true),
891 Rules::is('source', $this->id)
892 ]),
893 ];
894
895 $import_design[] = [
896 'name' => 'nx-bar_with_elementor_install',
897 'type' => 'button',
898 'priority' => 3,
899 'text' => [
900 'normal' => $is_installed ? __('Activate Elementor', 'notificationx') : __('Install Elementor', 'notificationx'),
901 'saved' => $is_installed ? __('Activated Elementor', 'notificationx') : __('Installed Elementor', 'notificationx'),
902 'loading' => $is_installed ? __('Activating Elementor...', 'notificationx') : __('Installing Elementor...', 'notificationx'),
903 ],
904 'style' => [
905 'description' => [
906 'position' => 'left'
907 ]
908 ],
909 // 'classes' => "nx-ele-bar-button nx-bar_with_elementor_install nx-on-click-install",
910 'rules' => Rules::logicalRule([
911 Rules::is('is_elementor', false),
912 Rules::is('gutenberg_id', false),
913 Rules::is('source', $this->id),
914 ]),
915 // 'data-nonce' => wp_create_nonce('wpdeveloper_upsale_core_install_notificationx'),
916 // 'data-slug' => 'elementor',
917 // 'data-plugin_file' => 'elementor.php',
918 'ajax' => [
919 'on' => 'click',
920 'api' => '/notificationx/v1/core-install',
921 'data' => [
922 'source' => $this->id,
923 'slug' => "elementor",
924 'file' => "elementor.php",
925 'is_installed' => $is_installed,
926 ],
927 'swal' => [
928 'icon' => 'success',
929 'text' => __('Successfully Activated', 'notificationx'),
930 ],
931 'trigger' => '@is_elementor:true',
932 ],
933 ];
934 $import_design[] = [
935 'name' => 'is_elementor',
936 'type' => 'hidden',
937 'default' => class_exists('\Elementor\Plugin'),
938 'rules' => Rules::is('source', $this->id),
939 ];
940 $import_design[] = [
941 'name' => 'elementor_id',
942 'type' => 'hidden',
943 'default' => false,
944 'rules' => Rules::is('source', $this->id),
945 ];
946 $import_design[] = [
947 'type' => 'hidden',
948 'name' => 'is_confirmed',
949 'default' => false
950 ];
951 // $import_design[] = [
952 // 'name' => 'elementor_edit_link',
953 // 'type' => 'hidden',
954 // 'rules' => Rules::is('source', $this->id),
955 // ];
956
957
958 // Block pattern
959
960 $import_design[] = [
961 'name' => 'gutenberg_edit_link',
962 'type' => 'button',
963 'text' => __('Edit With Gutenberg', 'notificationx'),
964 'href' => -1,
965 'priority' => 4,
966 'target' => '_blank',
967 'rules' => Rules::logicalRule([
968 Rules::is('gutenberg_edit_link', false, true),
969 Rules::isOfType('gutenberg_edit_link', 'string'),
970 Rules:: is('gutenberg_id', false, true),
971 // Rules:: is('is_gutenberg', true),
972 // Rules:: is('source', $this->id),
973 ]),
974 ];
975 $import_design[] = [
976 'name' => 'nx-bar_with_gutenberg-remove',
977 'type' => 'button',
978 'text' => __('Remove', 'notificationx'),
979 'priority' => 5,
980 'rules' => Rules::logicalRule([
981 Rules::is('gutenberg_id', false, true),
982 Rules::is('is_gutenberg', true),
983 Rules::is('source', $this->id),
984 ]),
985 'ajax' => [
986 'on' => 'click',
987 'api' => '/notificationx/v1/gutenberg/remove',
988 'data' => [
989 'gutenberg_id' => '@gutenberg_id',
990 ],
991 'hideSwal' => true,
992 ],
993 'trigger' => [
994 [
995 'type' => 'setFieldValue',
996 'action' => [
997 'gutenberg_id' => false,
998 'gutenberg_edit_link' => '',
999 'is_gb_confirmed' => false,
1000 'themes' => 'press_bar_theme-one',
1001 ]
1002 ],
1003 ],
1004 ];
1005
1006 $import_design[] = [
1007 'name' => 'nx-bar_with_gutenberg',
1008 'type' => 'modal',
1009 'button' => [
1010 'name' => 'build_with_gutenberg',
1011 'text' => __('Build With Gutenberg', 'notificationx'),
1012 'trigger' => [
1013 [
1014 'type' => 'setFieldValue',
1015 'action' => [
1016 'import_gutenberg_theme' => false
1017 ]
1018 ],
1019 ],
1020 ],
1021 'confirm_button' => [
1022 'type' => 'button',
1023 'name' => 'import_gutenberg_theme',
1024 'group' => true,
1025 'fields' => [
1026 [
1027 'type' => 'button',
1028 'name' => 'import_gutenberg_theme',
1029 "default" => false,
1030 'text' => [
1031 'normal' => __('Import', 'notificationx'),
1032 'saved' => __('Import', 'notificationx'),
1033 'loading' => __('Importing...', 'notificationx'),
1034 ],
1035 'ajax' => [
1036 'on' => 'click',
1037 'api' => '/notificationx/v1/gutenberg/import',
1038 'data' => [
1039 'theme_id' => '@gutenberg_bar_theme',
1040 ],
1041 'trigger' => '@is_gb_confirmed:true',
1042 'hideSwal' => true,
1043 ],
1044 'rules' => Rules::is('is_gb_confirmed', true, true),
1045 ],
1046 [
1047 'type' => 'button',
1048 'name' => 'import_gutenberg_theme_next',
1049 "default" => false,
1050 'text' => __('Next', 'notificationx'),
1051 'rules' => Rules::is('is_gb_confirmed', true),
1052 'trigger' => [
1053 [
1054 'type' => 'setContext',
1055 'action' => [
1056 'config.active' => 'display_tab'
1057 ]
1058 ],
1059 [
1060 'type' => 'setFieldValue',
1061 'action' => [
1062 'import_gutenberg_theme_next' => true
1063 ]
1064 ],
1065 ],
1066 ],
1067 ],
1068 ],
1069 'cancel' => "import_gutenberg_theme_next",
1070 'body' => [
1071 'header' => __('Choose Your ', 'notificationx'),
1072 'fields' => [
1073 'themes' => [
1074 'type' => 'radio-card',
1075 'name' => "gutenberg_bar_theme",
1076 'style' => [
1077 'label' => [
1078 'position' => 'top'
1079 ]
1080 ],
1081 'rules' => Rules::is('is_gb_confirmed', true, true),
1082 'default' => 'theme-one',
1083 'options' => $this->block_themes,
1084 ],
1085 'test' => [
1086 'name' => 'builder_modal_message',
1087 'type' => 'message',
1088 'message' => 'Hello World',
1089 'rules' => Rules::is('is_gb_confirmed', true)
1090 ]
1091 ],
1092 ],
1093 'rules' => Rules::logicalRule([
1094 Rules::is('elementor_id', false),
1095 Rules::is('gutenberg_id', false),
1096 Rules::is('is_gutenberg', true),
1097 Rules::is('is_gb_confirmed', true, true),
1098 Rules::is('source', $this->id)
1099 ]),
1100 ];
1101 $import_design[] = [
1102 'name' => 'is_gutenberg',
1103 'type' => 'hidden',
1104 'default' => function_exists('use_block_editor_for_post_type') ? use_block_editor_for_post_type('nx_bar_eb') : false,
1105 'rules' => Rules::is('source', $this->id),
1106 ];
1107 $import_design[] = [
1108 'name' => 'gutenberg_id',
1109 'type' => 'hidden',
1110 'default' => false,
1111 'rules' => Rules::is('source', $this->id),
1112 ];
1113 $import_design[] = [
1114 'type' => 'hidden',
1115 'name' => 'is_gb_confirmed',
1116 'default' => false
1117 ];
1118 $_fields['bar_editor']['fields'] = array_merge($_fields['bar_editor']['fields']);
1119 return $fields;
1120 }
1121
1122 /**
1123 * Display fields
1124 */
1125 public function display_fields( $fields ) {
1126 $fields['visibility']['fields']['bar_reappearance'] = array(
1127 'label' => __( 'Bar Reappearance', 'notificationx' ),
1128 'type' => 'select',
1129 'name' => 'bar_reappearance',
1130 'default' => 'show_welcomebar_every_page',
1131 'rules' => Rules::logicalRule([
1132 Rules::is('source', $this->id),
1133 ]),
1134 'options' => GlobalFields::get_instance()->normalize_fields([
1135 'dont_show_welcomebar' => __( "Don't show the Bar again for the user", 'notificationx' ),
1136 'show_welcomebar_next_visit' => __( 'Show the Bar again when the user visits the website next time', 'notificationx' ),
1137 'show_welcomebar_every_page' => __( 'Show the Bar when the user refreshes/goes to another page', 'notificationx' ),
1138 ]),
1139 );
1140 $fields['visibility']['fields']['bar_cache_duration_for_dont_show'] = [
1141 'label' => __( 'Cache Duration for "Don\'t show again"', 'notificationx' ),
1142 'name' => 'bar_cache_duration_for_dont_show',
1143 'type' => 'number',
1144 'default' => 10,
1145 'min' => 1,
1146 'max' => 365,
1147 'step' => 1,
1148 'description' => __('Days', 'notificationx'),
1149 'rules' => Rules::logicalRule([
1150 Rules::is('bar_reappearance', 'dont_show_welcomebar'),
1151 Rules::is('source', $this->id),
1152 ]),
1153 ];
1154 return $fields;
1155 }
1156
1157 /**
1158 * Get All Roles
1159 * dynamically
1160 *
1161 * @return array
1162 */
1163 public function get_roles() {
1164 $roles = wp_roles()->role_names;
1165 return $roles;
1166 }
1167
1168 /**
1169 * This method is an implementable method for All Extension coming forward.
1170 *
1171 * @param array $args Settings arguments.
1172 * @return mixed
1173 */
1174 public function customize_fields($fields) {
1175 $wp_roles = $this->get_roles();
1176
1177 $fields['queue_management'] = Rules::is('source', $this->id, true, $fields['queue_management']);
1178 $_fields = &$fields["appearance"]['fields'];
1179 $conversion_position = &$_fields['position']['options'];
1180
1181 $_fields['size'] = Rules::is('source', $this->id, true, $_fields['size']);
1182 $conversion_position['bottom_left'] = Rules::is('source', $this->id, true, $conversion_position['bottom_left']);
1183 $conversion_position['bottom_right'] = Rules::is('source', $this->id, true, $conversion_position['bottom_right']);
1184
1185 if (isset($fields['sound_section'])) {
1186 $fields['sound_section'] = Rules::includes('source', $this->id, true, $fields['sound_section']);
1187 }
1188
1189 $conversion_position['top'] = [
1190 'label' => __('Top', 'notificationx'),
1191 'value' => 'top',
1192 'rules' => Rules::is('source', $this->id),
1193 ];
1194 $conversion_position['bottom'] = [
1195 'label' => __('Bottom', 'notificationx'),
1196 'value' => 'bottom',
1197 'rules' => Rules::is('source', $this->id),
1198 ];
1199
1200 $_fields['sticky_bar'] = [
1201 'label' => __("Sticky Bar?", 'notificationx'),
1202 'name' => "sticky_bar",
1203 'type' => "checkbox",
1204 'default' => 0,
1205 'priority' => 60,
1206 'description' => __('If checked, this will fixed Notification Bar at top or bottom.', 'notificationx'),
1207 'rules' => Rules::is('source', $this->id),
1208 ];
1209
1210 $_fields['pressbar_body'] = [
1211 'label' => __("Display Overlapping", 'notificationx'),
1212 'name' => "pressbar_body",
1213 'type' => "checkbox",
1214 'default' => 0,
1215 'priority' => 61,
1216 'description' => __('Show Notification Bar overlapping content instead of pushing.', 'notificationx'),
1217 'rules' => Rules::is('source', $this->id),
1218 ];
1219
1220 //
1221 $fields["timing"]['fields']['delay_before'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['delay_before']);
1222 $fields["timing"]['fields']['display_for'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['display_for']);
1223 $fields["timing"]['fields']['delay_between'] = Rules::is('source', $this->id, true, $fields["timing"]['fields']['delay_between']);
1224
1225 $fields["timing"]['fields']['auto_hide'] = [
1226 'label' => __("Auto Hide", 'notificationx'),
1227 'name' => "auto_hide",
1228 'type' => "checkbox",
1229 'priority' => 50,
1230 'default' => false,
1231 'description' => __('If checked, notification bar will be hidden after the time set below.', 'notificationx'),
1232 'rules' => Rules::is('source', $this->id),
1233 ];
1234
1235 $fields["timing"]['fields']['hide_after'] = [
1236 'label' => __("Hide After", 'notificationx'),
1237 'name' => "hide_after",
1238 'type' => "number",
1239 'priority' => 55,
1240 'default' => 60,
1241 'description' => __('seconds', 'notificationx'),
1242 'help' => __('Hide after 60 seconds', 'notificationx'),
1243 'rules' => ['is', 'auto_hide', true],
1244 // 'rules' => Rules::is('source', $this->id),
1245 ];
1246 $fields["timing"]['fields']['appear_condition'] = [
1247 'label' => __('Notification Bar will Appear', 'notificationx'),
1248 'name' => 'appear_condition',
1249 'type' => 'radio-card',
1250 'priority' => 60,
1251 'classes' => 'radio-card-v2',
1252 'default' => 'delay',
1253 'options' => [
1254 'delay' => [
1255 'value' => 'after_few_seconds',
1256 'label' => __('After a few seconds', 'notificationx'),
1257 ],
1258 'scroll' => [
1259 'value' => 'on_scroll',
1260 'label' => __('On Scroll', 'notificationx'),
1261 ],
1262 ],
1263 'rules' => Rules::is('source', $this->id),
1264 ];
1265
1266 // This field appears only when "On Scroll" is selected
1267 $fields["timing"]['fields']['scroll_offset'] = [
1268 'label' => __('Scroll Offset', 'notificationx'),
1269 'name' => 'scroll_offset',
1270 'type' => 'group',
1271 'priority' => 65,
1272 'fields' => [
1273 'scroll_trigger_value' => [
1274 'name' => 'scroll_trigger_value',
1275 'type' => 'number',
1276 'min' => 0,
1277 'default' => 100,
1278 ],
1279 'scroll_trigger_mode' => [
1280 'type' => 'select',
1281 'name' => 'scroll_trigger_mode',
1282 'options' => GlobalFields::get_instance()->normalize_fields([
1283 'px' => __('PX', 'notificationx'),
1284 'vh' => __('VH', 'notificationx'),
1285 'percent' => __('%', 'notificationx'),
1286 ]),
1287 'default' => 'px',
1288 ],
1289 ],
1290 'rules' => ['is', 'appear_condition', 'on_scroll'],
1291 ];
1292
1293 $fields["timing"]['fields']['initial_delay'] = [
1294 'label' => __("Initial Delay", 'notificationx'),
1295 'name' => "initial_delay",
1296 'type' => "number",
1297 'priority' => 70,
1298 'default' => 5,
1299 'help' => __('Initial Delay', 'notificationx'),
1300 'description' => __('seconds', 'notificationx'),
1301 'rules' => Rules::logicalRule([
1302 Rules::is('source', $this->id),
1303 Rules::is('appear_condition', 'after_few_seconds'),
1304 ]),
1305 ];
1306
1307 $fields['targeting'] = [
1308 'label' => __('Targeting', 'notificationx'),
1309 'type' => 'section',
1310 'id' => 'targeting',
1311 'classes' => 'nx-targeting',
1312 'priority' => 100,
1313 'info' => InfoTooltipManager::get_instance()->render('button'),
1314 'fields' => []
1315 ];
1316
1317 // Country Targeting
1318 $fields['targeting']['fields']['country_targeting'] = [
1319 'label' => __('Country Targeting', 'notificationx'),
1320 'name' => 'country_targeting',
1321 'type' => 'better-select',
1322 'priority' => 10,
1323 'is_pro' => true,
1324 'multiple' => true,
1325 'values' => [ 'label' => "All Country", 'value' => 'all' ],
1326 'option' => GlobalFields::get_instance()->normalize_fields(Helper::nx_get_all_country()),
1327 'ajax' => [
1328 'api' => "/notificationx/v1/get-data",
1329 'data' => [
1330 'type' => "@type",
1331 'source' => "@source",
1332 // 'field' => "country_targeting",
1333 ],
1334 ],
1335 'rules' => Rules::is('source', $this->id),
1336 'info' => InfoTooltipManager::get_instance()->render('targeting'),
1337 ];
1338
1339 // User Role Targeting
1340 $wp_roles_with_default = [];
1341 if( is_array( $wp_roles ) ) {
1342 $wp_roles_with_default = array_merge(
1343 [ 'all_users' => __('Show for All Users', 'notificationx') ],
1344 $wp_roles
1345 );
1346 }
1347 $fields['targeting']['fields']['targeting_user_roles'] = [
1348 'label' => __('Set Target Audience', 'notificationx'),
1349 'name' => 'targeting_user_roles',
1350 'type' => 'select',
1351 'priority' => 20,
1352 'is_pro' => true,
1353 'default' => ['all_users'],
1354 'options' => GlobalFields::get_instance()->normalize_fields($wp_roles_with_default),
1355 'multiple' => true,
1356 'info' => InfoTooltipManager::get_instance()->render('targeting'),
1357 'rules' => Rules::is('source', $this->id),
1358 ];
1359
1360
1361 $fields["behaviour"]['fields']['display_last'] = Rules::is('source', $this->id, true, $fields["behaviour"]['fields']['display_last']);
1362 $fields["behaviour"]['fields']['display_from'] = Rules::is('source', $this->id, true, $fields["behaviour"]['fields']['display_from']);
1363 $fields["behaviour"]['fields']['loop'] = Rules::is('source', $this->id, true, $fields["behaviour"]['fields']['loop']);
1364 $fields["behaviour"] = Rules::logicalRule([
1365 Rules::logicalRule([
1366 Rules::isOfType('elementor_id', 'number', true),
1367 Rules::isOfType('gutenberg_id', 'number', true),
1368 ], 'and'),
1369 Rules::is('source', $this->id, true),
1370 ], 'or', $fields["behaviour"]);
1371 //Rules::isOfType('elementor_id', 'number', true, $fields["behaviour"]);
1372
1373 // Add Schedule section
1374 $_fields['schedule'] = array(
1375 'name' => 'schedule',
1376 'label' => __('Schedule', 'notificationx'),
1377 'type' => 'section',
1378 'is_pro' => true,
1379 'priority' => 96,
1380 'fields' => array(
1381 'schedule_type' => array(
1382 'name' => 'schedule_type',
1383 'type' => 'radio-card',
1384 'label' => __('Schedule Type', 'notificationx'),
1385 'priority' => 10,
1386 'classes' => 'radio-card-v2',
1387 'is_pro' => true,
1388 'default' => 'daily',
1389 'options' => array(
1390 'daily' => array(
1391 'value' => 'daily',
1392 'label' => __('Daily', 'notificationx'),
1393 // 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/schedule/daily.png',
1394 ),
1395 'weekly' => array(
1396 'value' => 'weekly',
1397 'label' => __('Weekly', 'notificationx'),
1398 // 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/schedule/weekly.png',
1399 ),
1400 'custom' => array(
1401 'value' => 'custom',
1402 'label' => __('Custom', 'notificationx'),
1403 // 'icon' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/schedule/custom.png',
1404 ),
1405 ),
1406 'info' => InfoTooltipManager::get_instance()->render('schedule_type'),
1407 ),
1408 'daily_from_time' => array(
1409 'name' => 'daily_from_time',
1410 'type' => 'timepicker',
1411 'label' => __('From', 'notificationx'),
1412 'priority' => 20,
1413 'is_pro' => true,
1414 'format' => 'h:i A',
1415 'rules' => Rules::is('schedule_type', 'daily'),
1416 ),
1417 'daily_to_time' => array(
1418 'name' => 'daily_to_time',
1419 'type' => 'timepicker',
1420 'label' => __('To', 'notificationx'),
1421 'priority' => 30,
1422 'is_pro' => true,
1423 'format' => 'h:i A',
1424 'rules' => Rules::is('schedule_type', 'daily'),
1425 ),
1426 'weekly_days' => array(
1427 'name' => 'weekly_days',
1428 'type' => 'select',
1429 'label' => __('Select Days', 'notificationx'),
1430 'priority' => 40,
1431 'is_pro' => true,
1432 'multiple' => true,
1433 'options' => GlobalFields::get_instance()->normalize_fields([
1434 'monday' => __('Monday', 'notificationx'),
1435 'tuesday' => __('Tuesday', 'notificationx'),
1436 'wednesday' => __('Wednesday', 'notificationx'),
1437 'thursday' => __('Thursday', 'notificationx'),
1438 'friday' => __('Friday', 'notificationx'),
1439 'saturday' => __('Saturday', 'notificationx'),
1440 'sunday' => __('Sunday', 'notificationx'),
1441 ]),
1442 'info' => InfoTooltipManager::get_instance()->render('advanced_template'),
1443 'rules' => Rules::is('schedule_type', 'weekly'),
1444 ),
1445 'weekly_from_time' => array(
1446 'name' => 'weekly_from_time',
1447 'type' => 'timepicker',
1448 'label' => __('From', 'notificationx'),
1449 'priority' => 50,
1450 'is_pro' => true,
1451 'format' => 'h:i A',
1452 'rules' => Rules::is('schedule_type', 'weekly'),
1453 ),
1454 'weekly_to_time' => array(
1455 'name' => 'weekly_to_time',
1456 'type' => 'timepicker',
1457 'label' => __('To', 'notificationx'),
1458 'priority' => 60,
1459 'format' => 'h:i A',
1460 'is_pro' => true,
1461 'rules' => Rules::is('schedule_type', 'weekly'),
1462 ),
1463 'custom_schedule' => array(
1464 'name' => 'custom_schedule',
1465 'type' => 'daterange',
1466 'label' => __('Custom Schedule', 'notificationx'),
1467 'priority' => 65,
1468 'is_pro' => true,
1469 'format' => 'h:i A',
1470 'info' => InfoTooltipManager::get_instance()->render('advanced_template'),
1471 'rules' => Rules::is('schedule_type', 'custom'),
1472 ),
1473 'custom_from_time' => array(
1474 'name' => 'custom_from_time',
1475 'type' => 'timepicker',
1476 'label' => __('From', 'notificationx'),
1477 'priority' => 70,
1478 'is_pro' => true,
1479 'format' => 'h:i A',
1480 'rules' => Rules::is('schedule_type', 'custom'),
1481 ),
1482 'custom_to_time' => array(
1483 'name' => 'custom_to_time',
1484 'type' => 'timepicker',
1485 'label' => __('To', 'notificationx'),
1486 'priority' => 75,
1487 'is_pro' => true,
1488 'format' => 'h:i A',
1489 'rules' => Rules::is('schedule_type', 'custom'),
1490 ),
1491 ),
1492 'rules' => Rules::logicalRule([
1493 Rules::is('source', $this->id),
1494 ]),
1495 );
1496
1497 return $fields;
1498 }
1499
1500 /**
1501 * This method is an implementable method for All Extension coming forward.
1502 *
1503 * @param array $args Settings arguments.
1504 * @return mixed
1505 */
1506 // public function source_fields($fields) {
1507 // $conversion_position = &$fields["source_tab"]['fields']['source'];
1508 // $conversion_position['condition']['type'] = '!press_bar';
1509 // return $fields;
1510 // }
1511
1512 public function before_delete_post($postid) {
1513 $post_meta = get_post_meta($postid, '_nx_bar_elementor_type_id', true);
1514 $this->nx_elementor_id = [
1515 'post_meta' => $post_meta,
1516 'postid' => $postid,
1517 ];
1518 }
1519
1520 public function nx_delete_post($postid, $post) {
1521 $elementor_id = isset($post['elementor_id']) ? $post['elementor_id'] : false;
1522 $gutenberg_id = isset($post['gutenberg_id']) ? $post['gutenberg_id'] : false;
1523
1524 $this->delete_elementor_post($elementor_id);
1525 $this->gutenberg_remove($gutenberg_id);
1526 }
1527
1528 public function delete_elementor_post($elementor_id) {
1529 if(!empty($elementor_id)){
1530 $languages = apply_filters( 'wpml_active_languages', NULL );
1531 if(is_array($languages)){
1532 foreach ($languages as $lang => $val) {
1533 $elementor_post_id = apply_filters( 'wpml_object_id', $elementor_id, 'nx_bar', false, $lang);
1534 if($elementor_post_id){
1535 wp_delete_post($elementor_post_id, true);
1536 }
1537 }
1538 return;
1539 }
1540 wp_delete_post($elementor_id, true);
1541 }
1542 }
1543
1544 /**
1545 * Register Post Type for NotificationX Bar.
1546 *
1547 * @return void
1548 */
1549 public static function register_post_type() {
1550 // var_dump(current_action());die;
1551 $args = [
1552 'label' => __('NotificationX Bar', 'notificationx'),
1553 'public' => false,
1554 'publicly_queryable' => true,
1555 'show_ui' => false,
1556 'rewrite' => false,
1557 'menu_icon' => 'dashicons-admin-page',
1558 'show_in_menu' => true,
1559 'show_in_nav_menus' => false,
1560 'exclude_from_search' => true,
1561 'capability_type' => 'post',
1562 'hierarchical' => false,
1563 'supports' => ['title', 'content', 'author', 'elementor'],
1564 ];
1565 register_post_type('nx_bar', $args);
1566
1567 // $args = [
1568 // 'label' => __('NotificationX Bar', 'notificationx'),
1569 // 'public' => true,
1570 // 'show_ui' => true,
1571 // 'rewrite' => false,
1572 // 'menu_icon' => 'dashicons-admin-page',
1573 // 'show_in_menu' => true,
1574 // 'show_in_nav_menus' => false,
1575 // // 'show_in_rest' => false,
1576 // 'exclude_from_search' => true,
1577 // 'capability_type' => 'post',
1578 // 'hierarchical' => false,
1579 // 'supports' => ['title', 'content', 'author'],
1580 // ];
1581 // register_post_type('nx_bar_eb', $args);
1582
1583 register_post_type(
1584 'nx_bar_eb',
1585 array(
1586 'label' => __('NotificationX Bar (Gutenberg)', 'notificationx'),
1587 'show_in_rest' => true,
1588 'public' => false,
1589 'publicly_queryable' => true,
1590 'exclude_from_search'=> true,
1591 'show_ui' => true,
1592 'can_export' => true,
1593 'show_in_menu' => false,
1594 'show_in_nav_menus' => false,
1595 'rewrite' => false,
1596 // 'publicly_queryable' => false,
1597 'template_lock' => 'block',
1598 'rest_base' => 'NotificationX',
1599 'capability_type' => 'block',
1600 'rest_controller_class' => 'WP_REST_Blocks_Controller',
1601 'capabilities' => array(
1602 // You need to be able to edit posts, in order to read blocks in their raw form.
1603 'read' => 'edit_posts',
1604 // You need to be able to publish posts, in order to create blocks.
1605 'create_posts' => 'publish_posts',
1606 'edit_posts' => 'edit_posts',
1607 'edit_published_posts' => 'edit_published_posts',
1608 'delete_published_posts' => 'delete_published_posts',
1609 // Enables trashing draft posts as well.
1610 'delete_posts' => 'delete_posts',
1611 'edit_others_posts' => 'edit_others_posts',
1612 'delete_others_posts' => 'delete_others_posts',
1613 ),
1614 'map_meta_cap' => true,
1615 'supports' => array(
1616 'title',
1617 'editor',
1618 'revisions',
1619 'custom-fields',
1620 ),
1621 )
1622 );
1623 }
1624
1625 public function convert_to_php_array($array) {
1626 $new_array = [];
1627 foreach ($array as $arr) {
1628 preg_match('/(.*)[\[](.*)[\]]/', $arr['name'], $matches);
1629 if (!empty($matches) && is_array($matches)) {
1630 $new_array[$matches[1]][$matches[2]] = $arr['value'];
1631 } else {
1632 $new_array[$arr['name']] = $arr['value'];
1633 }
1634 }
1635 return $new_array;
1636 }
1637
1638 /**
1639 * This methods is responsible for creating nx_bar post
1640 * to enable elementor to design the bar for you.
1641 *
1642 * @return void
1643 */
1644 public function create_bar_of_type_bar_with_elementor($params) {
1645 if (!isset($params['theme_id'])) {
1646 return;
1647 }
1648
1649 $theme = sanitize_text_field($params['theme_id']);
1650
1651
1652 $importer = new Importer();
1653
1654 $ID = $importer->create_nx([
1655 'theme' => $theme,
1656 'post_title' => 'Design for NotificationX Bar - ',
1657 ]);
1658
1659 if ($ID && !is_wp_error($ID)) {
1660 update_post_meta($ID, '_wp_page_template', 'elementor_canvas');
1661 wp_send_json_success(array(
1662 'context' => [
1663 'themes' => null,
1664 'elementor_id' => $ID,
1665 'elementor_edit_link' => \Elementor\Plugin::$instance->documents->get($ID)->get_edit_url(),
1666 // 'bar_edit_link' => get_edit_post_link($ID, 'internal'),
1667 // 'visit' => get_permalink($ID),
1668 ]
1669 ));
1670 } else {
1671 wp_send_json_error('failed');
1672 }
1673 }
1674
1675
1676 /**
1677 * Undocumented function
1678 *
1679 * @param array $options
1680 * @return array
1681 */
1682 public function content_fields($fields) {
1683
1684 $fields['content']['fields']['press_sliding_text'] = array(
1685 'name' => 'sliding_text',
1686 'label' => __('Text Content', 'notificationx'),
1687 'type' => 'section',
1688 'classes' => NotificationX::is_pro() ? 'pro-activated' : 'pro-deactivated',
1689 'priority' => 51,
1690 'fields' => array(
1691 'bar_content_type' => array(
1692 'name' => 'bar_content_type',
1693 'type' => 'radio-card',
1694 'label' => __('Content', 'notificationx'),
1695 'priority' => 5,
1696 'classes' => 'radio-card-v2',
1697 'default' => 'static',
1698 'options' => array(
1699 'static' => array(
1700 'label' => __('Static Text', 'notificationx'),
1701 'value' => 'static',
1702 // 'icon' => 'dashicons-align-left',
1703 ),
1704 'sliding' => array(
1705 'label' => __('Slide Multiple Text', 'notificationx'),
1706 'value' => 'sliding',
1707 'is_pro' => true,
1708 // 'icon' => 'dashicons-align-right',
1709 ),
1710 ),
1711 ),
1712 'press_content' => array(
1713 'name' => 'press_content',
1714 'type' => 'nx-editor',
1715 'label' => __('Static Text', 'notificationx'),
1716 'placeholder' => __('Write something here...', 'notificationx'),
1717 'priority' => 7,
1718 'rules' => Rules::logicalRule([
1719 Rules::is('bar_content_type', 'static'),
1720 Rules::is('source', $this->id),
1721 ]),
1722 ),
1723 'sliding_content' => array(
1724 'name' => 'sliding_content',
1725 'type' => 'simple-repeater',
1726 'label' => __('Sliding Text Items', 'notificationx'),
1727 'priority' => 10,
1728 'button' => array(
1729 'label' => __('Add New', 'notificationx'),
1730 ),
1731 '_default' => array(
1732 array(
1733 'title' => __('🚀 Supercharge Your Marketing Forever!', 'notificationx'),
1734 ),
1735 array(
1736 'title' => __('Get <strong>Lifetime Access to NotificationX</strong> for just <strong>$299</strong>', 'notificationx'),
1737 ),
1738 ),
1739 '_fields' => array(
1740 array(
1741 'name' => 'title',
1742 'type' => 'editor',
1743 'label' => __('Slide Text', 'notificationx'),
1744 'priority' => 10,
1745 ),
1746 ),
1747 'rules' => Rules::logicalRule([
1748 Rules::is('bar_content_type', 'sliding'),
1749 Rules::is('source', $this->id),
1750 ]),
1751 ),
1752 'sliding_interval' => array(
1753 'name' => 'sliding_interval',
1754 'type' => 'number',
1755 'label' => __('Sliding Interval', 'notificationx'),
1756 'priority' => 20,
1757 'default' => 3000,
1758 'description' => 'ms',
1759 'help' => __('Time interval between slides in milliseconds', 'notificationx'),
1760 'rules' => Rules::logicalRule([
1761 Rules::is('bar_content_type', 'sliding'),
1762 Rules::is('source', $this->id),
1763 ]),
1764 ),
1765 ),
1766 'rules' => Rules::logicalRule([
1767 Rules::is('source', $this->id),
1768 ]),
1769 );
1770
1771 $fields['content']['fields']['button_text'] = array(
1772 'name' => 'button_text',
1773 'type' => 'text',
1774 'label' => __('Button Text', 'notificationx'),
1775 'priority' => 60,
1776 'default' => __('Get Offer', 'notificationx'),
1777 'rules' => Rules::logicalRule([
1778 // Rules::isOfType('elementor_id', 'number', true),
1779 Rules::is('source', $this->id),
1780 ]),
1781 );
1782 $fields['content']['fields']['button_url'] = array(
1783 'name' => 'button_url',
1784 'type' => 'text',
1785 'label' => __('Button URL', 'notificationx'),
1786 'default' => '#',
1787 'priority' => 70,
1788 'rules' => Rules::logicalRule([
1789 // Rules::isOfType('elementor_id', 'number', true),
1790 Rules::is('source', $this->id),
1791 ]),
1792 );
1793 $fields['content']['fields']['button_icon'] = array(
1794 'name' => 'button_icon',
1795 'type' => 'icon-picker',
1796 'label' => __('Button Icon', 'notificationx'),
1797 'priority' => 75,
1798 'iconPrefix' => NOTIFICATIONX_ADMIN_URL . 'images/icons/',
1799 'options' => [
1800 [
1801 'icon' => 'shop_now.svg',
1802 'label' => __('Shop Now', 'notificationx')
1803 ],
1804 [
1805 'icon' => 'shop_now_white.svg',
1806 'label' => __('Shop Now White ', 'notificationx')
1807 ],
1808 ],
1809 'description' => __('Select an icon to display before the button text', 'notificationx'),
1810 'rules' => Rules::logicalRule([
1811 // Rules::isOfType('elementor_id', 'number', true),
1812 Rules::is('source', $this->id),
1813 ]),
1814 );
1815 $fields['content']['fields']['bar_transition_speed'] = [
1816 'label' => __('Transition Speed', 'notificationx'),
1817 'name' => "bar_transition_speed",
1818 'type' => "number",
1819 'default' => '500',
1820 'description' => 'ms',
1821 'priority' => 100,
1822 'help' => __('Transition speed in milliseconds', 'notificationx'),
1823 'rules' => Rules::logicalRule([
1824 Rules::is('bar_content_type', 'sliding'),
1825 Rules::is('source', $this->id),
1826 ]),
1827 ];
1828 $fields['content']['fields']['bar_transition_style'] = [
1829 'label' => __('Transition Style', 'notificationx'),
1830 'name' => "bar_transition_style",
1831 'type' => "select",
1832 'priority' => 110,
1833 'default' => 'slide_right',
1834 'options' => GlobalFields::get_instance()->normalize_fields([
1835 'slide_right' => __('Slide in Right', 'notificationx'),
1836 'slide_left' => __('Slide in Left', 'notificationx'),
1837 ]),
1838 'rules' => Rules::logicalRule([
1839 Rules::is('bar_content_type', 'sliding'),
1840 Rules::is('source', $this->id),
1841 ]),
1842 ];
1843
1844 $fields['bar_coupon'] = array(
1845 'name' => 'bar_coupon',
1846 'label' => __('Coupon', 'notificationx'),
1847 'type' => 'section',
1848 'priority' => 94,
1849 'dependency_class' => [
1850 'name' => 'enable_coupon',
1851 'is' => true,
1852 'classes' => 'coupon_active',
1853 'selector' => '#bar_coupon',
1854 ],
1855 'fields' => array(
1856 'enable_coupon' => array(
1857 'name' => 'enable_coupon',
1858 'label' => __('Enable Coupon', 'notificationx'),
1859 'type' => 'toggle',
1860 'default' => false,
1861 ),
1862 'coupon_text' => array(
1863 'name' => 'coupon_text',
1864 'label' => __('Button Text', 'notificationx'),
1865 'type' => 'text',
1866 'default' => __('SAVE20', 'notificationx'),
1867 'priority' => 10,
1868 'rules' => Rules::logicalRule([
1869 Rules::is('enable_coupon', true),
1870 ]),
1871 ),
1872 'coupon_code' => array(
1873 'name' => 'coupon_code',
1874 'label' => __('Coupon Code', 'notificationx'),
1875 'type' => 'text',
1876 'default' => __('SAVE20', 'notificationx'),
1877 'priority' => 12,
1878 'rules' => Rules::logicalRule([
1879 Rules::is('enable_coupon', true),
1880 ]),
1881 ),
1882 'coupon_copied_text' => array(
1883 'name' => 'coupon_copied_text',
1884 'label' => __('Coupon Copied Text', 'notificationx'),
1885 'type' => 'text',
1886 'default' => __('Copied!', 'notificationx'),
1887 'priority' => 20,
1888 'rules' => Rules::logicalRule([
1889 Rules::is('enable_coupon', true),
1890 ]),
1891 ),
1892 'coupon_tooltip' => array(
1893 'name' => 'coupon_tooltip',
1894 'label' => __('Coupon Tooltip', 'notificationx'),
1895 'type' => 'textarea',
1896 'default' => __('Use this coupon code to get 20% off', 'notificationx'),
1897 'priority' => 30,
1898 'rules' => Rules::logicalRule([
1899 Rules::is('enable_coupon', true),
1900 ]),
1901 ),
1902 'coupon_bg_color' => array(
1903 'name' => 'coupon_bg_color',
1904 'label' => __('Coupon Background Color', 'notificationx'),
1905 'type' => 'colorpicker',
1906 'default' => '#ffffff',
1907 'priority' => 40,
1908 'rules' => Rules::logicalRule([
1909 Rules::is('enable_coupon', true),
1910 ]),
1911 ),
1912 'coupon_text_color' => array(
1913 'name' => 'coupon_text_color',
1914 'label' => __('Coupon Text Color', 'notificationx'),
1915 'type' => 'colorpicker',
1916 'default' => '#000000',
1917 'priority' => 50,
1918 'rules' => Rules::logicalRule([
1919 Rules::is('enable_coupon', true),
1920 ]),
1921 ),
1922 'coupon_border_color' => array(
1923 'name' => 'coupon_border_color',
1924 'label' => __('Coupon Border Color', 'notificationx'),
1925 'type' => 'colorpicker',
1926 'default' => '#dddddd',
1927 'priority' => 60,
1928 'rules' => Rules::logicalRule([
1929 Rules::is('enable_coupon', true),
1930 ]),
1931 ),
1932 ),
1933 'rules' => Rules::logicalRule([
1934 Rules::is('source', $this->id),
1935 ]),
1936 );
1937
1938 $fields['countdown_timer'] = array(
1939 'name' => 'countdown_timer',
1940 'label' => __('Countdown Timer', 'notificationx'),
1941 'type' => 'section',
1942 'priority' => 95,
1943 'fields' => array(
1944 'enable_countdown' => array(
1945 'name' => 'enable_countdown',
1946 'label' => __('Enable Countdown', 'notificationx'),
1947 'type' => 'checkbox',
1948 // 'default' => true,
1949 ),
1950 'evergreen_timer' => array(
1951 'name' => 'evergreen_timer',
1952 'label' => __('Evergreen Timer', 'notificationx'),
1953 'type' => 'checkbox',
1954 'is_pro' => true,
1955 'switch' => true,
1956 'description' => sprintf('%s, <a target="_blank" href="%s">%s</a>', __('To configure Evergreen Timer', 'notificationx'), 'https://notificationx.com/docs/evergreen-timer/', 'check out this doc'),
1957 'rules' => ['is', 'enable_countdown', true],
1958 ),
1959 'countdown_text' => array(
1960 'name' => 'countdown_text',
1961 'label' => __('Countdown Text', 'notificationx'),
1962 'type' => 'text',
1963 'default' => __('Ending in', 'notificationx'),
1964 'rules' => Rules::logicalRule([
1965 // Rules::is('elementor_id', false),
1966 // Rules::is('gutenberg_id', false),
1967 Rules::is('enable_countdown', true),
1968 ]),
1969 ),
1970 'countdown_expired_text' => array(
1971 'name' => 'countdown_expired_text',
1972 'label' => __('Expired Text', 'notificationx'),
1973 'type' => 'text',
1974 'default' => __('Expired', 'notificationx'),
1975 'rules' => Rules::logicalRule([
1976 Rules::is('elementor_id', false),
1977 Rules::is('gutenberg_id', false),
1978 Rules::is('evergreen_timer', false),
1979 Rules::is('enable_countdown', true),
1980 ]),
1981 ),
1982 'countdown_start_date' => array(
1983 'name' => 'countdown_start_date',
1984 'label' => __('Start Date', 'notificationx'),
1985 'type' => 'date',
1986 // 'default' => date('Y-m-d H:i:s', time()),
1987 'rules' => ["and", ['is', 'evergreen_timer', false], ['is', 'enable_countdown', true]],
1988 ),
1989 'countdown_end_date' => array(
1990 'name' => 'countdown_end_date',
1991 'label' => __('End Date', 'notificationx'),
1992 'type' => 'date',
1993 // @todo Something
1994 'default' => date('Y-m-d H:i:s', time() + 7 * 24 * 60 * 60),
1995 'rules' => ["and", ['is', 'evergreen_timer', false], ['is', 'enable_countdown', true]],
1996 ),
1997 'time_randomize' => array(
1998 'name' => 'time_randomize',
1999 'label' => __('Randomize', 'notificationx'),
2000 'type' => 'checkbox',
2001 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true]],
2002 ),
2003 'time_randomize_between' => array(
2004 'name' => 'time_randomize_between',
2005 'label' => __('Time Between', 'notificationx'),
2006 'type' => 'group',
2007 'fields' => [
2008 'start_time' => array(
2009 'name' => 'start_time',
2010 'type' => 'number',
2011 'label' => __('Start Time', 'notificationx'),
2012 'priority' => 0,
2013 'default' => 6,
2014 ),
2015 'end_time' => array(
2016 'name' => 'end_time',
2017 'type' => 'number',
2018 'label' => __('End Time', 'notificationx'),
2019 'priority' => 1,
2020 'default' => 12,
2021 ),
2022 ],
2023 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true], ['is', 'time_randomize', true]],
2024 ),
2025 'time_rotation' => array(
2026 'name' => 'time_rotation',
2027 'label' => __('Time Rotation', 'notificationx'),
2028 'type' => 'number',
2029 'description' => 'hours',
2030 'default' => 315,
2031 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true], ['is', 'time_randomize', false]]
2032 ),
2033 'time_reset' => array(
2034 'name' => 'time_reset',
2035 'label' => __('Daily Time Reset', 'notificationx'),
2036 'type' => 'checkbox',
2037 'rules' => ["and", ['is', 'evergreen_timer', true], ['is', 'enable_countdown', true]],
2038 ),
2039 'close_forever' => array(
2040 'name' => 'close_forever',
2041 'label' => __('Permanent Close', 'notificationx'),
2042 'type' => 'checkbox',
2043 ),
2044 'close_after_expire' => array(
2045 'name' => 'close_after_expire',
2046 'label' => __('Close After Expire', 'notificationx'),
2047 'type' => 'checkbox',
2048 ),
2049 ),
2050 'rules' => Rules::logicalRule([
2051 Rules::is('source', $this->id),
2052 ]),
2053 );
2054
2055 $fields["content"]['fields']['template_adv'] = Rules::is('source', $this->id, true, $fields["content"]['fields']['template_adv']);
2056 $fields["content"]['fields']['advanced_template'] = Rules::is('source', $this->id, true, $fields["content"]['fields']['advanced_template']);
2057 $fields["content"] = Rules::logicalRule([
2058 Rules::logicalRule([
2059 Rules::isOfType('elementor_id', 'number', true),
2060 Rules::isOfType('gutenberg_id', 'number', true),
2061 ], 'and'),
2062 Rules::is('source', $this->id, true),
2063 ], 'or', $fields["content"]);
2064
2065 $fields['content']['fields']['random_order'] = Rules::is('source', $this->id, true, $fields["content"]['fields']['random_order']);
2066
2067 return $fields;
2068 }
2069
2070 public function print_bar_notice($settings, $is_shortcode = false) {
2071 $settings = new GetData($settings, \ArrayObject::ARRAY_AS_PROPS);
2072 $elementor_post_id = isset($settings->elementor_id) ? $settings->elementor_id : '';
2073 $gb_post_id = isset($settings->gutenberg_id) ? $settings->gutenberg_id : '';
2074
2075 if ($elementor_post_id != '' && get_post_status($elementor_post_id) === 'publish' && class_exists('\Elementor\Plugin')) {
2076 $elementor_post_id = apply_filters( 'wpml_object_id', $elementor_post_id, 'nx_bar', true);
2077 return \Elementor\Plugin::$instance->frontend->get_builder_content_for_display($elementor_post_id, false);
2078 } else if (!empty($gb_post_id)) {
2079 $gb_post_id = apply_filters( 'wpml_object_id', $gb_post_id, 'wp_block', true);
2080 $post = get_post($gb_post_id);
2081 $content = $post->post_content;
2082 $content = do_blocks($content);
2083
2084 return $content;
2085 } else {
2086 return !empty($settings->press_content) ? do_shortcode($settings->press_content) : '';
2087 }
2088 }
2089
2090 public function add_scripts($settings, $params){
2091 if(!empty($settings['gutenberg_id'])){
2092 $settings['gutenberg_url'] = get_permalink($settings['gutenberg_id']);
2093 }
2094 return $settings;
2095 }
2096
2097 public function hide_image_field($fields) {
2098 $fields['image-section'] = Rules::is('source', $this->id, true, $fields['image-section']);
2099 return $fields;
2100 }
2101
2102 public function nx_get_post($post) {
2103 if (isset($post['source']) && $post['source'] == $this->id && !empty($post['elementor_id']) && class_exists('\Elementor\Plugin')) {
2104 try {
2105 $document = \Elementor\Plugin::$instance->documents->get($post['elementor_id']);
2106 if(!empty($document)){
2107 $post['elementor_edit_link'] = $document->get_edit_url();
2108 $bar_post = $document->get_post();
2109 if(!empty($bar_post->post_title)){
2110 foreach ($this->bar_themes as $key => $theme) {
2111 if(strpos($bar_post->post_title, $theme['title']) !== false){
2112 $post['elementor_bar_theme'] = $theme['value'];
2113 unset($post['theme']);
2114 unset($post['themes']);
2115 break;
2116 }
2117 }
2118 }
2119 }
2120 else{
2121 unset($post['elementor_id']);
2122 }
2123 } finally {
2124 }
2125 }
2126 return $post;
2127 }
2128
2129 public function gutenberg_import($params) {
2130 // Get the JSON file content
2131 $json_file = file_get_contents(__DIR__ . "/jsons-gb/" . $params['theme_id'] . '.json');
2132
2133 // Decode the JSON content into an array
2134 $pattern_data = json_decode($json_file, true);
2135
2136 // Get the sync status from the pattern data
2137 $sync_status = $pattern_data['syncStatus'];
2138
2139 // Create an array of arguments for the wp_block post
2140 $post_args = array(
2141 'post_title' => $pattern_data['title'], // use the pattern title as the post title
2142 'post_content' => $pattern_data['content'], // use the pattern content as the post content
2143 'post_status' => 'publish', // set the post status to publish
2144 'post_type' => 'nx_bar_eb', // set the post type to wp_block
2145 );
2146
2147 // Insert the wp_block post
2148 $post_id = wp_insert_post($post_args);
2149
2150
2151 // Check for errors
2152 if ($post_id && !is_wp_error($post_id)) {
2153 // Display the error message
2154 if (!empty($sync_status)) {
2155 update_post_meta($post_id, 'wp_pattern_sync_status', $sync_status);
2156 }
2157 // Display a success message
2158 return [
2159 'success' => true,
2160 'data' => [
2161 'context' => [
2162 'themes' => null,
2163 'gutenberg_id' => $post_id,
2164 'gutenberg_edit_link' => get_edit_post_link($post_id, 'link'),
2165 ],
2166 ],
2167 ];
2168 } else {
2169 return [
2170 'success' => true,
2171 'data' => 'failed',
2172 ];
2173 }
2174 }
2175
2176 public function gutenberg_remove($pid){
2177 if(!empty($pid)){
2178 $languages = apply_filters( 'wpml_active_languages', NULL );
2179 if(is_array($languages)){
2180 foreach ($languages as $lang => $val) {
2181 $wpml_pid = apply_filters( 'wpml_object_id', $pid, 'wp_block', false, $lang);
2182 if($wpml_pid){
2183 wp_delete_post($wpml_pid, true);
2184 }
2185 }
2186 return;
2187 }
2188 wp_delete_post($pid, true);
2189 }
2190 }
2191
2192 public function templately_cloud_push_post_type($post_type){
2193
2194 if($post_type == 'nx_bar_eb'){
2195 $post_type = 'NX Bar';
2196 }
2197 return $post_type;
2198 }
2199
2200 public function preview_settings($settings){
2201 if(!empty($settings['gutenberg_id'])){
2202 $settings['gutenberg_url'] = get_permalink($settings['gutenberg_id']);
2203 }
2204 return $settings;
2205 }
2206
2207 /**
2208 *
2209 * https://docs.wp-rocket.me/article/1529-remove-unused-css
2210 *
2211 * @param array $list
2212 * @return array
2213 */
2214 public function rocket_rucss_safelist($list){
2215 try {
2216 $posts = PostType::get_instance()->get_posts(['source' => $this->id]);
2217 foreach ($posts as $post) {
2218 if(class_exists('Elementor\Core\Files\CSS\Post') && !empty($post['elementor_id'])){
2219 $css = Post_CSS::create( $post['elementor_id'] );
2220 if(!empty($css)){
2221 // maybe need to remove the domain from url
2222 $list[] = $css->get_url();
2223 }
2224 }
2225 }
2226 } catch (\Exception $th) {
2227 //throw $th;
2228 }
2229 return $list;
2230 }
2231
2232 /**
2233 * Load plugin dependencies.
2234 * @return void
2235 */
2236 public function load_plugin_dependencies() {
2237 if(!Helper::is_plugin_active('essential-blocks/essential-blocks.php')){
2238 $this->popup = array(
2239 // forcing the popup without the is_pro.
2240 "forced" => true,
2241 "showConfirmButton" => true,
2242 "showCloseButton" => true,
2243 "title" => "You are missing a dependency.",
2244 "customClass" => array(
2245 "container" => "pressbar-gutenberg-theme-popup",
2246 // "closeButton" => "pro-video-close-button",
2247 // "icon" => "pro-video-icon",
2248 // "title" => "pro-video-title",
2249 // "content" => "pro-video-content",
2250 // "actions" => "nx-pro-alert-actions",
2251 // "confirmButton" => "pro-video-confirm-button",
2252 // "denyButton" => "pro-video-deny-button"
2253 ),
2254 "denyButtonText" => sprintf("<a href='%s' target='_blank'>%s</a>", admin_url('plugin-install.php?s=Essential%2520Blocks&tab=search&type=term'), __("Install Essential Blocks", 'notificationx')),
2255 "confirmButtonText" => "<a href='https://essential-blocks.com/' target='_blank'>More Info</a>",
2256 "html" => "
2257 <span>Highlight your sales, low stock updates with inline growth alert to boost sales</span>
2258 "
2259 );
2260 }
2261 }
2262
2263 public function doc() {
2264 return sprintf(__('<p>Supercharge your WordPress site with an <strong>AI-powered Notification Bar</strong> that help you create and launches instant popup campaigns — smarter and faster than ever. Let AI generate compelling bar content for you in seconds. Need help getting started? Explore our step-by-step guides to set up your AI-enhanced notification bars using both <a target="_blank" href="%1$s">Elementor</a> and <a target="_blank" href="%2$s">Gutenberg</a>.</p>
2265 <p>🎦 Check the <a target = "_blank" href = "%3$s">documentation</a> for a quick guide.</p>
2266 <p><strong>Recommended Blog : </strong></p>
2267 <p>🔥<a target="_blank" href="%4$s">How to Design a Notification Bar with AI Using NotificationX (A Comprehensive Guide)</a></p>
2268 <p>🔥 <a href="%5$s" target="_blank">How to design a Notification Bar with Elementor Page Builder.</p>', 'notificationx'),
2269 'https://notificationx.com/docs/notification-bar/',
2270 'https://notificationx.com/docs/configure-a-notification-bar-in-gutenberg/',
2271 'https://notificationx.com/docs/how-to-design-a-notification-bar-with-ai/',
2272 'https://notificationx.com/blog/guide-to-design-a-notification-bar-with-ai/',
2273 'https://notificationx.com/docs/notification-bar-with-elementor/'
2274 );
2275 }
2276 }
2277