PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
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 trunk, at includes/Extensions/PressBar/PressBar.php

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