PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.3.1
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.3.1
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 / Features / ShortcodeInline.php

ShortcodeInline.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.3.1, at includes/Features/ShortcodeInline.php

164 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace NotificationX\Core;
3
4 use NotificationX\Core\PostType;
5 use NotificationX\FrontEnd\FrontEnd;
6 use NotificationX\GetInstance;
7
8 /**
9 * Class Shortcode For NotificationX
10 * @method static ShortcodeInline get_instance($args = null)
11 *
12 * @since 1.2.3
13 */
14 class ShortcodeInline {
15 /**
16 * Instance of ShortcodeInline
17 *
18 * @var ShortcodeInline
19 */
20 use GetInstance;
21
22 public $shortcode_nx_ids = [];
23
24 /**
25 * __construct__ is for revoke first time to get ready
26 *
27 * @return void
28 */
29 public function __construct() {
30 add_shortcode( 'notificationx_inline', array( $this, 'shortcode_inline' ), 999 );
31 add_filter('nx_inline_notifications_data',array( $this, 'nx_inlineshortcode' ),10,4);
32 }
33
34 public function nx_inlineshortcode( $return, $source, $id, $settings ){
35 if( !empty( $settings['shortcodeinline'] ) ) {
36 return FrontEnd::get_instance()->get_notifications_data(
37 array(
38 'shortcode' => [$settings['nx_id']],
39 'inline_shortcode' => true,
40 )
41 );
42 }
43 return $return;
44 }
45
46 /**
47 * this method is responsible for output the shortcode.
48 *
49 * @param array $atts
50 */
51 public function shortcode_inline( $atts, $content = null ) {
52 $atts = shortcode_atts( array(
53 'id' => '',
54 'product_id' => '',
55 'post_type' => '',
56 'show_link' => true,
57 ), $atts, 'notificationx_inline'
58 );
59
60 $nx_id = $atts['id'];
61
62 if ( empty( $nx_id ) ) {
63 if ( ! current_user_can( 'administrator' ) ) {
64 return;
65 }
66 return '<p class="nx-shortcode-notice">' . __( 'Choose a Notification from the dropdown.', 'notificationx' ) . '</p>';
67 }
68
69 if ( ! PostType::get_instance()->is_enabled( $nx_id ) ) {
70 if ( ! current_user_can( 'administrator' ) ) {
71 return;
72 }
73 return '<p class="nx-shortcode-notice">' . __( 'Make sure you have enabled the notification which ID you have given.', 'notificationx' ) . '</p>';
74 }
75
76 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
77 do_action( 'nx_inline' );
78 $settings = PostType::get_instance()->get_post($nx_id);
79 if( $settings['type'] == 'inline' || $settings['source'] == 'woocommerce_sales_inline' ){
80 $settings['shortcodeinline'] = true;
81 /**
82 * @var WooInline|EDDInline
83 */
84 $extension = \NotificationX\Extensions\ExtensionFactory::get_instance()->get($settings['source']);
85 $output = $extension->show_inline_notification( $atts, $settings);
86 if( !empty( $output ) ) {
87 $output = "<div id='notificationx-shortcode-inline-{$atts['id']}' class='notificationx-shortcode-inline-wrapper nx-shortcode-notice'>$output</div>";
88 }
89 return $output;
90 }
91
92 $result = FrontEnd::get_instance()->get_notifications_data( [ 'shortcode' => [ $nx_id ] ] );
93
94 $output = '';
95 if ( ! empty( $result['shortcode'][ $nx_id ]['entries'] ) ) {
96 $entries = $result['shortcode'][ $nx_id ]['entries'];
97 $entries = array_values( $entries );
98 $settings = $result['shortcode'][ $nx_id ]['post'];
99
100 $logged_in = is_user_logged_in();
101 $show_on_display = isset($settings['show_on_display']) ? $settings['show_on_display'] : '';
102 if ( ! ( ( $logged_in && 'logged_out_user' === $show_on_display ) || ( ! $logged_in && 'logged_in_user' === $show_on_display ) ) ) {
103
104 $col = array_column( $entries, 'timestamp' );
105 if ( count( $col ) == count( $entries ) ) {
106 array_multisort( $col, SORT_ASC, $entries );
107 }
108 $entry = end( $entries );
109 $template = Inline::get_instance()->get_template( $settings );
110 $_template = $template;
111
112 foreach ( $entry as $key => $val ) {
113 if ( ! is_array( $val ) ) {
114 if ( 'rating' === $key ) {
115 $count = $val;
116 $val = "<span style='white-space: nowrap'>";
117 for ( $i = 1; $i <= 5; $i++ ) {
118 $val .= $i <= $count
119 ? '<span style="color:#ffc107">�
120 </span>'
121 : '<span style="color:#eeeeee">�
122 </span>';
123 }
124 $val .= '</span>';
125 } elseif (
126 ! empty( $entry['link'] ) &&
127 in_array( $key, [ 'plugin_name', 'product_title', 'post_title', 'plugin_theme_name', 'course_title', 'title' ], true ) &&
128 'form' !== $settings['type'] &&
129 'email_subscription' !== $settings['type'] &&
130 'page_analytics' !== $settings['type']
131 ) {
132 $link = $entry['link'];
133 $target = ! empty( $settings['link_open'] ) ? 'target="_blank"' : '';
134 if ( 'false' === $atts['show_link'] ) {
135 $target = '';
136 $link = 'javascript:void(0)';
137 }
138 $val = "<a href='$link' $target>$val</a>";
139 }
140 $_template = str_replace( "{{{$key}}}", $val, $_template );
141 }
142 if ( ! empty( $entry['timestamp'] ) && strpos( $_template, '{{time}}' ) !== false ) {
143 $timestamp = $entry['timestamp'];
144 if ( $timestamp ) {
145 $diff_for_humans = sprintf(
146 /* translators: time */
147 _x( '%s ago', 'Inline Shortcode', 'notificationx' ),
148 human_time_diff( $timestamp )
149 );
150 $_template = str_replace( '{{time}}', $diff_for_humans, $_template );
151 }
152 }
153 }
154 $output .= $_template;
155 // $this->shortcode_nx_ids[] = $atts['id'];
156 $output = "<div id='notificationx-shortcode-inline-{$atts['id']}' class='notificationx-shortcode-inline-wrapper nx-shortcode-notice'>$output</div>";
157 }
158 }
159
160 return $output;
161 }
162
163 }
164