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

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

293 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace NotificationX\Core;
4
5 use NotificationX\Core\PostType;
6 use NotificationX\FrontEnd\FrontEnd;
7 use NotificationX\FrontEnd\Preview;
8 use NotificationX\GetInstance;
9
10 /**
11 * Class Shortcode For NotificationX Pro
12 * @method static Inline get_instance($args = null)
13 *
14 * @since 1.2.3
15 */
16 class Inline {
17 /**
18 * Instance of Shortcode
19 *
20 * @var Shortcode
21 */
22 use GetInstance;
23
24 public $notifications_data = [];
25
26 /**
27 * __construct__ is for revoke first time to get ready
28 *
29 * @return void
30 */
31 public function __construct() {
32 // InlineWooCommerce::get_instance();
33 // InlineEDD::get_instance();
34 }
35
36
37 public function get_notifications_data( $source, $id = null, $settings = [] ) {
38
39 $exit = apply_filters('nx_inline_notifications_data', null, $source, $id, $settings);
40 if($exit){
41 return $exit;
42 }
43
44 // if ( empty( $this->notifications_data ) ) {
45 $this->notifications_data = array( 'shortcode' => array() );
46 $notifications = PostType::get_instance()->get_posts(
47 array(
48 'source' => $source,
49 'enabled' => true,
50 'is_inline' => true,
51 )
52 );
53
54 do_action( 'nx_inline' );
55
56 if ( ! empty( $notifications ) ) {
57 $this->notifications_data = FrontEnd::get_instance()->get_notifications_data(
58 array(
59 'shortcode' => array_column( $notifications, 'nx_id' ),
60 'inline_shortcode' => true,
61 )
62 );
63 }
64 // }
65 return $this->notifications_data;
66 }
67
68
69 public function get_template( $settings ) {
70 if ( ! empty( $settings['template_adv'] ) && ! empty( $settings['advanced_template'] ) ) {
71 if( strpos($settings['advanced_template'], '{{random:') !== false ) {
72 $productId = get_the_ID();
73 return $this->generateRandomNumber( $settings['advanced_template'], $productId );
74 }
75 return $settings['advanced_template'];
76 }
77
78 $template = '';
79 $defaults = array(
80 'first_param' => '',
81 'second_param' => '',
82 'third_param' => '',
83 'fourth_param' => '',
84 'fifth_param' => '',
85 'sixth_param' => '',
86 'map_fourth_param' => '',
87 'ga_fourth_param' => '',
88 'ga_fifth_param' => '',
89 'review_fourth_param' => '',
90 'freemius_fifth_param' => '',
91 'freemius_sixth_param' => '',
92 'freemius_seventh_param' => '',
93 );
94
95 $theme_name = $settings['themes'];
96 $theme_name = str_replace( $settings['source'] . '_', '', $theme_name );
97 $theme_name = str_replace( $settings['type'] . '_', '', $theme_name );
98 if ( ! empty( $settings['custom_type'] ) ) {
99 $theme_name = str_replace( $settings['custom_type'] . '_', '', $theme_name );
100 }
101 $params = wp_parse_args( $settings['notification-template'], $defaults );
102
103 foreach ( $params as $param => $element ) {
104 if ( $element == 'tag_custom' && isset( $params[ 'custom_' . $param ] ) ) {
105 // getting value of custom params.
106 $element = $params[ 'custom_' . $param ];
107 }
108 if ( $element == 'tag_siteview' || $element == 'tag_realtime_siteview' ) {
109 $params[ $param ] = '{{views}}';
110 } elseif ( $element == 'ga_title' ) {
111 $params[ $param ] = '{{title}}';
112 } elseif ( strpos( $element, 'tag_product_' ) === 0 ) {
113 $params[ $param ] = '{{' . str_replace( 'tag_product_', '', $element ) . '}}';
114 } elseif ( strpos( $element, 'tag_' ) === 0 ) {
115 $params[ $param ] = '{{' . str_replace( 'tag_', '', $element ) . '}}';
116 } elseif ( strpos( $element, 'product_' ) === 0 ) {
117 $params[ $param ] = '{{' . str_replace( 'product_', '', $element ) . '}}';
118 } else {
119 $params[ $param ] = $element;
120 }
121 if(Preview::get_instance()->is_preview()){
122 $params[ $param ] = "<span class='$param'>{$params[ $param ]}</span>";
123 }
124 }
125
126 switch ( $settings['themes'] ) {
127 case 'donation_theme-one':
128 case 'donation_theme-two':
129 case 'donation_theme-three':
130 case 'donation_theme-four':
131 case 'donation_theme-five':
132 return "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']} {$params['fifth_param']}";
133 case 'donation_conv-theme-seven':
134 case 'donation_conv-theme-eight':
135 case 'donation_conv-theme-nine':
136 return "{$params['first_param']} {$params['second_param']} in {$params['third_param']} {$params['fourth_param']}";
137 case 'google_reviews_maps_theme':
138 return "{$params['first_param']} {$params['second_param']} in {$params['third_param']} {$params['fourth_param']}";
139 case 'woocommerce_sales_inline_conv-theme-seven':
140 case 'fluentcart_inline_conv-theme-seven':
141 case 'woo_inline_conv-theme-seven':
142 return "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
143 case 'youtube_channel-1':
144 return "{$params['second_param']} {$params['third_param']} {$params['yt_third_label']}, {$params['fourth_param']} {$params['yt_fourth_label']} {$params['fifth_param']} {$params['yt_fifth_label']}";
145 case 'youtube_channel-2':
146 return "{$params['second_param']} {$params['third_param']} {$params['yt_third_label']}, {$params['fourth_param']} {$params['fifth_param']}";
147 case 'youtube_video-1':
148 case 'youtube_video-3':
149 return "{$params['second_param']}, {$params['third_param']} {$params['fourth_param']} {$params['fifth_param']}";
150 case 'youtube_video-2':
151 case 'youtube_video-4':
152 return "{$params['second_param']}, {$params['third_param']} {$params['yt_third_label']} {$params['fourth_param']} {$params['yt_fourth_label']} {$params['fifth_param']} {$params['yt_fifth_label']}";
153
154 }
155
156 if ($settings['source'] === 'freemius_conversions') {
157 switch ( $theme_name ) {
158 case "theme-one":
159 case "theme-two":
160 case "theme-three":
161 case "theme-four":
162 case "theme-five":
163 return ["{$params['first_param']} {$params['second_param']}", "{$params['third_param']} {$params['freemius_fifth_param']} {$params['fifth_param']} {$params['freemius_sixth_param']} {$params['freemius_seventh_param']}", "{$params['fourth_param']}"];
164 case "conv-theme-ten":
165 case "conv-theme-eleven":
166 return ["{$params['first_param']} {$params['second_param']}", "{$params['third_param']} {$params['freemius_fifth_param']} {$params['freemius_sixth_param']} {$params['freemius_seventh_param']}", "{$params['fourth_param']}"];
167 // conversion start
168 case "conv-theme-six":
169 return ["{$params['first_param']} {$params['second_param']} {$params['third_param']}", "{$params['map_fourth_param']} {$params['fourth_param']} {$params['freemius_fifth_param']} {$params['freemius_sixth_param']} {$params['freemius_seventh_param']}", "{$params['fifth_param']}"];
170 case "conv-theme-seven":
171 case "conv-theme-eight":
172 case "conv-theme-nine":
173 return ["{$params['first_param']} {$params['second_param']}", "{$params['third_param']} {$params['fourth_param']} {$params['freemius_fifth_param']} {$params['freemius_sixth_param']} {$params['freemius_seventh_param']}"];
174 }
175 }
176 switch ( $theme_name ) {
177 case 'theme-one':
178 case 'theme-two':
179 case 'theme-three':
180 case 'theme-four':
181 case 'theme-five':
182 case "conv-theme-ten":
183 case "conv-theme-eleven":
184 case 'conv-theme-seven':
185 case 'conv-theme-eight':
186 case 'conv-theme-nine':
187 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
188 break;
189 // conversion start
190 case 'conv-theme-six':
191 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['map_fourth_param']} {$params['fourth_param']} {$params['fifth_param']}";
192 break;
193 // conversion end
194 // comments theme start.
195 case 'theme-six-free':
196 case 'theme-seven-free':
197 case 'theme-eight-free':
198 // review themes
199 case 'review-comment':
200 case 'review-comment-2':
201 case 'review-comment-3':
202 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
203 break;
204 // comments theme end.
205
206 // reviews theme start.
207 case 'total-rated':
208 case 'reviewed':
209 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
210 break;
211 case 'review_saying':
212 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['review_fourth_param']} {$params['fifth_param']} {$params['sixth_param']}";
213 break;
214 // reviews theme end.
215 // start download stats
216 case 'today-download':
217 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
218 break;
219 case '7day-download':
220 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
221 break;
222 case 'actively_using':
223 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']}";
224 break;
225 case 'total-download':
226 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
227 break;
228 // end download stats
229
230 case 'maps_theme':
231 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['map_fourth_param']} {$params['fourth_param']} {$params['fifth_param']}";
232 break;
233 // PA
234 case 'pa-theme-one':
235 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['ga_fourth_param']} {$params['ga_fifth_param']} {$params['sixth_param']}";
236 break;
237 case 'pa-theme-two':
238 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['ga_fourth_param']} {$params['ga_fifth_param']} {$params['sixth_param']}";
239 break;
240 case 'pa-theme-three':
241 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['ga_fourth_param']}";
242 break;
243 case 'stock-theme-one':
244 case 'stock-theme-two':
245 $template = "{$params['second_param']} {$params['third_param']} {$params['fourth_param']} {$params['fifth_param']}";
246 break;
247 default:
248 $template = "{$params['first_param']} {$params['second_param']} {$params['third_param']} {$params['fourth_param']}";
249 break;
250 }
251 return $template;
252 }
253
254 function generateRandomNumber($content, $productId) {
255 // Use a unique cookie name per product
256 $cookieNamePrefix = 'randomNumber_';
257
258 // Use a regex to find all {{random:min-max:range:expiry}} placeholders
259 return preg_replace_callback('/{{random:(\d+)-(\d+)(?::(\d+))?(?::(\d+))?}}/', function ($matches) use ($cookieNamePrefix, $productId) {
260 $min = (int)$matches[1];
261 $max = (int)$matches[2];
262 $range = isset($matches[3]) ? (int)$matches[3] : 10; // Default range to 10
263 $expiry = isset($matches[4]) ? (int)$matches[4] : 15; // Default expiry to 15 minutes
264
265 // Create a unique cookie name for this product
266 $cookieName = $cookieNamePrefix . $productId;
267
268 // Check if a cookie value exists
269 $cookieValue = isset($_COOKIE[$cookieName]) ? (int)$_COOKIE[$cookieName] : null;
270
271 // Determine the random number
272 if ($cookieValue !== null) {
273 $randomNumber = $cookieValue;
274 } else {
275 $randomNumber = rand($min, $max);
276
277 // If cookieValue existed, ensure new number is within the allowed range
278 if ($cookieValue !== null) {
279 while (abs($randomNumber - $cookieValue) > $range) {
280 $randomNumber = rand($min, $max);
281 }
282 }
283
284 // Set the cookie for this product
285 setcookie($cookieName, (string)$randomNumber, time() + ($expiry * 60), "/");
286 }
287
288 return $randomNumber;
289 }, $content);
290 }
291
292
293 }