PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.10
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.10
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 / FrontEnd / Preview.php

Preview.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.10, at includes/FrontEnd/Preview.php

502 lines 21.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Admin Class File.
5 *
6 * @package NotificationX\Admin
7 */
8
9 namespace NotificationX\FrontEnd;
10
11 use NotificationX\Core\Helper;
12 use NotificationX\Core\Rules;
13 use NotificationX\GetInstance;
14
15 /**
16 * Preview Class, this class is responsible for all Preview Actions
17 * @method static Preview get_instance($args = null)
18 */
19 class Preview {
20 /**
21 * Instance of Preview
22 *
23 * @var Preview
24 */
25 use GetInstance;
26
27 protected $notificationXArr = [];
28
29 public function __construct() {
30 add_action('wp_head', [$this, 'header_scripts']);
31 add_action('wp_print_footer_scripts', [$this, 'footer_scripts']);
32
33 add_filter('nx_before_enqueue_scripts', [$this, 'enqueue_scripts']);
34 add_filter('nx_inline_notifications_data', [$this, 'inline_notifications_data'], 10, 4);
35 add_filter('nx_metabox_config', [$this, 'content_heading']);
36
37 if ($this->is_preview()) {
38 show_admin_bar(false);
39 }
40
41 if ($this->is_preview() && class_exists('QueryMonitor')) {
42 ini_set('display_errors', 'Off');
43 ini_set('error_reporting', E_ALL);
44 $qm = \QueryMonitor::init();
45 remove_action('plugins_loaded', [$qm, 'action_plugins_loaded']);
46 }
47 }
48
49
50 /**
51 * This method is responsible for enqueueing scripts for public use.
52 *
53 * @return void
54 */
55 public function enqueue_scripts($return) {
56 if ($this->is_preview()) {
57 $args = [
58 'total' => 1,
59 'nxPreview' => true,
60 'pressbar' => [],
61 'active' => [],
62 'gdpr' => [],
63 'popup' => [],
64 'exit_intent' => [],
65 ];
66
67 $settings = $this->preview_settings();
68 if (empty($settings['source']) || empty($settings['type']))
69 return;
70 if ('inline' === $settings['type'] || 'woocommerce_sales_inline' == $settings['source'] ){
71 $args['total'] = 0;
72 return $args;
73 }
74
75 $source = $settings['source'];
76 $type = $settings['type'];
77 if ($type === 'exit_intent') {
78 $args['exit_intent'] = [
79 $source => [
80 'entries' => [
81 $this->preview_entry($settings),
82 ],
83 'post' => $settings,
84 ]
85 ];
86 } else if ($source === 'press_bar') {
87 $args['pressbar'] = [
88 $source => [
89 'content' => FrontEnd::get_instance()->get_bar_content($settings, true),
90 'post' => $settings,
91 ]
92 ];
93 } else if($source === 'gdpr_notification') {
94 $args['gdpr'] = [
95 $source => [
96 'entries' => [
97 $this->preview_entry($settings),
98 ],
99 'post' => $settings,
100 ]
101 ];
102 } else if($source === 'popup_notification') {
103 $args['popup'] = [
104 $source => [
105 'entries' => [
106 $this->preview_entry($settings),
107 ],
108 'post' => $settings,
109 ]
110 ];
111 } else {
112 $args['active'] = [
113 $source => [
114 'entries' => [
115 $this->preview_entry($settings),
116 ],
117 'post' => $settings,
118 ]
119 ];
120 }
121
122 $args['settings'] = FrontEnd::get_instance()->get_settings();
123
124 $this->notificationXArr = apply_filters('get_notifications_ids', $args);
125 wp_enqueue_style('notificationx-public');
126 wp_enqueue_script('notificationx-public');
127 do_action('notificationx_scripts', $this->notificationXArr);
128
129 add_filter('show_admin_bar', '__return_false');
130
131 return $this->notificationXArr;
132 }
133 return $return;
134 }
135
136 public function header_scripts() {
137 if ($this->is_preview()) {
138 ?>
139 <style>
140 .notificationx-woo-shortcode-inline-wrapper > * {
141 display: inline-block;
142 /* background: rgb(255 255 0 / 20%);
143 color: red; */
144 font-weight: 600;
145 }
146 .notificationx-woo-shortcode-inline-wrapper > div.woo_inline_conv-theme-seven span:first-child,
147 .notificationx-woo-shortcode-inline-wrapper > div.edd_inline_conv-theme-seven span:first-child,
148 .notificationx-woo-shortcode-inline-wrapper > div.woocommerce_sales_inline_conv-theme-seven span:first-child {
149 color: #61BD6D;
150 }
151 .notificationx-woo-shortcode-inline-wrapper > div.woo_inline_conv-theme-seven span:last-child,
152 .notificationx-woo-shortcode-inline-wrapper > div.woocommerce_sales_inline_conv-theme-seven span:last-child,
153 .notificationx-woo-shortcode-inline-wrapper > div.edd_inline_conv-theme-seven span:last-child,
154 .notificationx-woo-shortcode-inline-wrapper > div.tutor_inline_conv-theme-seven span:last-child,
155 .notificationx-woo-shortcode-inline-wrapper > div.learndash_inline_conv-theme-seven span:last-child{
156 color: #E25042;
157 }
158
159 .notificationx-woo-shortcode-inline-wrapper > div.woo_inline_stock-theme-one span,
160 .notificationx-woo-shortcode-inline-wrapper > div.woocommerce_sales_inline_stock-theme-one span {
161 color: #E25042;
162 }
163 </style>
164 <?php
165 }
166 }
167
168 public function footer_scripts() {
169 if ($this->is_preview()) {
170 ?>
171 <script data-no-optimize="1">
172 (function() {
173 document.addEventListener("click", function(event) {
174 // if (event.target.tagName === "A") {
175 event.preventDefault();
176 event.stopPropagation();
177 event.stopImmediatePropagation();
178 // }
179 });
180 document.addEventListener("submit", function(event) {
181 event.preventDefault();
182 });
183 })();
184 </script>
185 <?php
186 }
187 }
188
189
190 public function preview_entry($settings) {
191 $source = !empty($settings['source']) ? $settings['source'] : '';
192 $type = !empty($settings['type']) ? $settings['type'] : '';
193 $nx_id = !empty($settings['nx_id']) ? $settings['nx_id'] : '';
194 $defaults = [
195 'nx_id' => $nx_id,
196 'active_installs' => rand(50, 70),
197 'active_installs_text' => 'Try It Out',
198 'all_time' => rand(50, 70),
199 'all_time_text' => 'Why Don\'t You?',
200 'anonymous_title' => 'Anonymous Title',
201 'author' => '<a href="https://wpdeveloper.com/">WPDeveloper</a>',
202 'author_profile' => 'https://profiles.wordpress.org/wpdevteam/',
203 'amount' => rand(50, 70),
204 'avatar' => [
205 'src' => NOTIFICATIONX_PUBLIC_URL . 'image/icons/pink-face-looped.gif',
206 ],
207 'picture' => NOTIFICATIONX_PUBLIC_URL . 'image/icons/pink-face-looped.gif',
208 'city' => 'Dhaka',
209 'city_country' => 'Dhaka, Bangladesh',
210 'content' => 'Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.',
211 'count' => rand(50, 70),
212 'country' => 'Bangladesh',
213 'course_title' => 'PHP Beginners – Become a PHP Master',
214 'created_at' => wp_date('Y-m-d H:i:s', strtotime('2 days ago')),
215 'day' => 'days',
216 'downloaded' => rand(50, 70),
217 'email' => 'support@wpdeveloper.com',
218 'entry_id' => rand(1000, 9999),
219 'entry_key' => 'ChIJ0cpDbNvBVTcRGX9JNhhpC8I',
220 'first_name' => 'John',
221 '_first_name' => 'John',
222 'formatted_address' => 'House 592, Road 8 Avenue 5, Dhaka 1216, Bangladesh',
223 'ga_title' => 'NotificationX',
224 'icon' => 'https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png',
225 'icons' => array(
226 '1x' => "https://ps.w.org/notificationx/assets/icon-128x128.gif?rev=2783824",
227 '2x' => "https://ps.w.org/notificationx/assets/icon-256x256.gif?rev=2783824",
228 ),
229 'id' => 5,
230 'image_data' => array(
231 'url' => NOTIFICATIONX_PUBLIC_URL . 'image/icons/pink-face-looped.gif',
232 'alt' => '',
233 'classes' => 'greview_icon',
234 ),
235 'ip' => '103.108.146.88',
236 'key' => '7368a455f5c113afbfd3d8c3ea89a5ed-5719',
237 'last_name' => 'Doe',
238 '_last_name' => 'Doe',
239 'last_updated' => date('Y-m-d H:i:s', strtotime('2 days ago')),
240 'last_week' => rand(50, 70),
241 'last_week_text' => 'Get Started for Free.',
242 'lat' => 23.8371427,
243 'link' => '#',
244 'lon' => 90.3704629,
245 'month' => 'months',
246 'name' => 'John Doe',
247 'names' => 'John Doe',
248 'none' => '',
249 'num_ratings' => 2974,
250 'nx_id' => '60',
251 'order_id' => 5815,
252 'place_id' => 'ChIJ0cpDbNvBVTcRGX9JNhhpC8I',
253 'place_name' => 'WPDeveloper',
254 'plugin_name' => 'NotificationX',
255 'plugin_name_text' => 'try it out',
256 'plugin_review' => 'Lorem Ipsum is simply dummy text...',
257 'place_review' => 'Lorem Ipsum is simply dummy text...',
258 'plugin_theme_name' => 'NotificationX',
259 'post_link' => '#',
260 'product_id' => 168,
261 'product_title' => 'Assorted Coffee',
262 'rated' => rand(50, 70),
263 'rating' => 4.4,
264 'ratings' => array(
265 0 => 48,
266 1 => 13,
267 2 => 21,
268 3 => 66,
269 4 => 2826,
270 ),
271 'realtime_siteview' => rand(50, 70),
272 'siteview' => rand(50, 70),
273 'slug' => 'notificafionx',
274 'sometime' => 'Some time ago',
275 'source' => 'google_reviews',
276 'status' => 'wc-processing',
277 'this_page' => 'this page',
278 'timestamp' => date('Y-m-d H:i:s', strtotime('2 days ago')),
279 'title' => 'Hoodie with Logo',
280 'today' => rand(50, 70),
281 'today_text' => 'Try It Out',
282 'type' => 'realtime_siteview',
283 'updated_at' => date('Y-m-d H:i:s', strtotime('2 days ago')),
284 'url' => '#',
285 'user_id' => '1',
286 'username' => 'johndoe',
287 'version' => '5.5.2',
288 'views' => rand(50, 70),
289 'website' => 'https://wpdeveloper.com/',
290 'year' => 'years',
291 'yesterday' => rand(50, 70),
292 'your-email' => 'support@wpdeveloper.com',
293 'your-message' => 'Lorem Ipsum is simply dummy text.',
294 'your-name' => 'John Doe',
295 'your-subject' => 'Lorem Ipsum',
296 'post_title' => 'Hello World',
297 'sales_count' => rand(50, 70),
298 'donation_count' => rand(50, 70),
299 '1day' => __('In last 1 day', 'notificationx'),
300 '7days' => __('In last 7 days', 'notificationx'),
301 '30days' => __('In last 30 days', 'notificationx'),
302 'post_comment' => 'Lorem Ipsum is simply dummy text...',
303 // 'select_a_tag' => 'Jhon',
304
305 ];
306
307 if (!empty($settings['custom_contents']) && is_array($settings['custom_contents']) && count($settings['custom_contents'])) {
308 $custom = !empty($settings['custom_contents'][0]) ? $settings['custom_contents'][0] : [];
309 if (isset($custom['first_name'], $custom['last_name'])) {
310 $custom['name'] = Helper::name($custom['first_name'], $custom['last_name']);
311 }
312 $defaults = array_merge($defaults, $custom);
313 }
314
315 $settings['freemius_plugins'] = '';
316
317 $defaults['image_data'] = FrontEnd::get_instance()->apply_defaults((array) FrontEnd::get_instance()->get_image_url($defaults, $settings), $defaults['image_data']);
318
319 $defaults = apply_filters("nx_preview_entry_$type", $defaults, $settings);
320 $defaults = apply_filters("nx_preview_entry_$source", $defaults, $settings);
321 $_defaults = apply_filters("nx_fallback_data_$source", $defaults, $defaults, $settings);
322 $_defaults = apply_filters('nx_fallback_data', $_defaults, $_defaults, $settings);
323 $defaults = FrontEnd::get_instance()->apply_defaults($defaults, $_defaults);
324 $defaults = apply_filters("nx_filtered_entry_$type", $defaults, $settings);
325 $defaults = apply_filters("nx_filtered_entry_$source", $defaults, $settings);
326 // $defaults = $this->link_url($defaults, $settings);
327 if (strpos($settings['theme'], 'maps_theme') !== false && 'maps_image' === $settings['show_notification_image']) {
328 $defaults['image_data'] = array(
329 'url' => NOTIFICATIONX_ASSETS . 'admin/images/map.jpg',
330 'alt' => '',
331 'classes' => 'greview_icon',
332 );
333 }
334 if ('gravatar' === $settings['show_notification_image']) {
335 $defaults['image_data'] = array(
336 'url' => NOTIFICATIONX_PUBLIC_URL . 'image/icons/pink-face-looped.gif',
337 'alt' => '',
338 'classes' => 'greview_icon',
339 );
340 }
341 if ('none' === $settings['show_notification_image'] && !$settings['show_default_image']) {
342 $defaults['image_data'] = false;
343 }
344 return $defaults;
345 }
346
347 public function get_settings() {
348 if ( empty($_POST['nx-preview']) ) {
349 return array();
350 }
351
352 $settings = base64_decode( wp_unslash($_POST['nx-preview']), true );
353 $settings = json_decode( $settings, true );
354
355 if ( ! is_array($settings) ) {
356 return array();
357 }
358
359 // Simple sanitization
360 array_walk_recursive( $settings, function ( &$value ) {
361 if ( is_string( $value ) ) {
362 $value = wp_strip_all_tags( $value );
363 }
364 });
365
366 return $settings;
367 }
368
369 public function preview_settings($settings = []) {
370 $settings = !empty($settings) ? $settings : $this->get_settings();
371
372 if (empty($settings['source'])){
373 return [];
374 }
375
376 if ($settings['global_queue']) {
377 $settings['global_queue'] = false;
378 $settings['_global_queue'] = true;
379 }
380 $settings['nx_id'] = rand();
381 $settings['is_preview'] = true;
382 if (empty($settings['theme']) && !empty($settings['themes'])) {
383 $settings['theme'] = $settings['themes'];
384 }
385 if ('form' === $settings['type']) {
386 $settings['notification-template']['first_param'] = 'tag_first_name';
387 }
388 if( !empty( $settings['notification-template'] ) ) {
389 $settings['notification-template'] = array_map( 'esc_html', $settings['notification-template'] );
390 }
391
392 $settings = apply_filters("nx_get_post_{$settings['source']}", $settings);
393 $settings = apply_filters("nx_preview_settings_{$settings['source']}", $settings);
394 $settings = apply_filters('nx_get_post', $settings);
395 return $settings;
396 }
397
398 public function content_heading($tabs) {
399 $urls = apply_filters('nx_preview_url', [
400 'default' => trailingslashit(home_url()),
401 ]);
402
403 $tabs['config']['content_heading']['talk_to_support'] = apply_filters('talk_to_support', [
404 'text' => __('Talk to Support', 'notificationx'),
405 'classes' => 'nx-talk-to-support',
406 'type' => 'button',
407 'name' => 'talk_to_support',
408 'target' => '_blank',
409 'href' => esc_url('https://notificationx.com/support/?support=chat'),
410 ]);
411 $tabs['config']['content_heading']['preview'] = apply_filters('nx_content_heading_preview', [
412 'label' => __('Preview', 'notificationx'),
413 'type' => 'preview-modal',
414 'name' => 'preview',
415 'urls' => $urls,
416 'errors' => apply_filters('nx_content_heading_preview_errors', []),
417 'rules' => Rules::logicalRule([
418 Rules::includes('themes', ['woo_inline_stock-theme-two', 'tutor_inline_conv-theme-eight', 'flashing_tab_theme-1','flashing_tab_theme-2' ,'flashing_tab_theme-3' , 'flashing_tab_theme-4','woocommerce_sales_inline_stock-theme-two','learnpress_inline_conv-theme-eight'], true),
419 Rules::is('type', 'notification_bar', true),
420 ]),
421 ]);
422 return $tabs;
423 }
424
425 public function inline_notifications_data($return, $source, $id, $settings = []) {
426 if ($this->is_preview() && !empty($id)) {
427 $settings = $this->preview_settings($settings);
428 $settings['is_preview'] = true;
429
430 if ( ( empty($settings['source']) || empty($settings['type']) || 'inline' !== $settings['type']) && ('woocommerce_sales_inline' !== $settings['source']) ){
431 return;
432 }
433
434 remove_filter('nx_inline_notifications_data', [$this, 'inline_notifications_data'], 10);
435
436 $source = !empty($settings['source']) ? $settings['source'] : '';
437 $type = !empty($settings['type']) ? $settings['type'] : '';
438 $settings['inline_location'] = is_array($settings['inline_location']) ? $settings['inline_location'] : [];
439 $settings['inline_location'][] = 'woocommerce_before_add_to_cart_form';
440
441 $defaults = [
442 "nx_id" => rand(),
443 "entry_id" => 78,
444 "order_id" => 96,
445 "product_id" => $id,
446 "id" => $id,
447 // "status" => "wc-pending",
448 "title" => get_the_title($id),
449 "product_title" => get_the_title($id),
450 "link" => "#",
451 "timestamp" => date('Y-m-d H:i:s', strtotime('2 days ago')),
452 // "first_name" => "John",
453 // "last_name" => "Doe",
454 // "name" => "John Doe",
455 "email" => "support@wpdeveloper.com",
456 "source" => $source,
457 "entry_key" => "96-7",
458 "created_at" => date('Y-m-d H:i:s', strtotime('2 days ago')),
459 "updated_at" => date('Y-m-d H:i:s', strtotime('2 days ago')),
460 "none" => "",
461 // "anonymous_title" => "Anonymous Product",
462 // "sometime" => "Some time ago",
463 "sales_count" => rand(50, 70),
464 "donation_count" => rand(50, 70),
465 // "30days" => "in last 30 days",
466 // "day:30" => "30 days",
467 // "1day" => "in last 1 day",
468 // "7days" => "in last 7 days",
469 ];
470
471
472 $_defaults = apply_filters("nx_fallback_data_$source", $defaults, $defaults, $settings);
473 $_defaults = apply_filters('nx_fallback_data', $_defaults, $_defaults, $settings);
474 $defaults = FrontEnd::get_instance()->apply_defaults($defaults, $_defaults);
475 $defaults = apply_filters("nx_preview_entry_$type", $defaults, $settings);
476 $defaults = apply_filters("nx_preview_entry_$source", $defaults, $settings);
477 $defaults = apply_filters("nx_filtered_entry_$type", $defaults, $settings);
478 $defaults = apply_filters("nx_filtered_entry_$source", $defaults, $settings);
479
480 return [
481 'shortcode' => [
482 [
483 "entries" => [$defaults],
484 "post" => $settings,
485 ],
486 ],
487 ];
488 }
489
490 return $return;
491 }
492
493 public function is_preview() {
494 $is_preview = false;
495 if (!empty($_POST['nx-preview'])) {
496 $is_preview = true;
497 }
498 $is_preview = apply_filters('nx_is_preview',$is_preview);
499 return $is_preview;
500 }
501 }
502