Popup Builder – Responsive WordPress Pop up - Version 3.84

Version Description

Download this release

Release Info

Developer Sygnoos
Plugin Icon 128x128 Popup Builder – Responsive WordPress Pop up
Version 3.84
Comparing to
See all releases

Code changes from version 3.83 to 3.84

com/classes/Actions.php CHANGED
@@ -869,6 +869,11 @@ class Actions
869
  if (empty($post)) {
870
  $saveMode = '';
871
  }
 
 
 
 
 
872
  /* In preview mode saveMode should be true*/
873
  if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
874
  if (!$allowToAction) {
869
  if (empty($post)) {
870
  $saveMode = '';
871
  }
872
+
873
+ if ($post->post_status == 'draft') {
874
+ $saveMode = '_preview';
875
+ }
876
+
877
  /* In preview mode saveMode should be true*/
878
  if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
879
  if (!$allowToAction) {
com/classes/Filters.php CHANGED
@@ -1,870 +1,870 @@
1
- <?php
2
- namespace sgpb;
3
- use \WP_Query;
4
- use \SgpbPopupConfig;
5
- use sgpb\PopupBuilderActivePackage;
6
- use sgpb\SGPopup;
7
-
8
- class Filters
9
- {
10
- private $activePopupsQueryString = '';
11
-
12
- public function setQueryString($activePopupsQueryString)
13
- {
14
- $this->activePopupsQueryString = $activePopupsQueryString;
15
- }
16
-
17
- public function getQueryString()
18
- {
19
- return $this->activePopupsQueryString;
20
- }
21
-
22
- public function __construct()
23
- {
24
- $this->init();
25
- }
26
-
27
- public function init()
28
- {
29
- add_filter('admin_url', array($this, 'addNewPostUrl'), 10, 2);
30
- add_filter('wpseo_sitemap_exclude_post_type', array($this, 'excludeSitemapsYoast'), 10, 2);
31
- add_filter('admin_menu', array($this, 'removeAddNewSubmenu'), 10, 2);
32
- add_filter('manage_'.SG_POPUP_POST_TYPE.'_posts_columns', array($this, 'popupsTableColumns'));
33
- add_filter('post_row_actions', array($this, 'quickRowLinksManager'), 10, 2);
34
- add_filter('sgpbAdminJs', array($this, 'adminJsFilter'), 1, 1);
35
- add_filter('sgpbAdminCssFiles', array($this, 'sgpbAdminCssFiles'), 1, 1);
36
- add_filter('sgpbPopupContentLoadToPage', array($this, 'filterPopupContent'), 10, 2);
37
- add_filter('the_content', array($this, 'clearContentPreviewMode'), 10, 1);
38
- // The priority of this action should be higher than the extensions' init priority.
39
- add_action('init', array($this, 'excludePostToShowPrepare'), 99999999);
40
- add_filter('preview_post_link', array($this, 'editPopupPreviewLink'), 10, 2);
41
- add_filter('upgrader_pre_download', array($this, 'maybeShortenEddFilename'), 10, 4);
42
- add_filter('sgpbSavedPostData', array($this, 'savedPostData'), 10, 1);
43
- add_filter('sgpbPopupEvents', array($this, 'popupEvents'), 10, 1);
44
- add_filter('sgpbAdditionalMetaboxes', array($this, 'metaboxes'), 10, 1);
45
- add_filter('sgpbOptionAvailable', array($this, 'filterOption'), 10, 1);
46
- add_filter('export_wp_filename', array($this, 'exportFileName'), 10, 1);
47
- add_filter('sgpbAdvancedOptionsDefaultValues', array($this, 'defaultAdvancedOptionsValues'), 10, 1);
48
- add_filter('sgpbPopupContentLoadToPage', array($this, 'popupContentLoadToPage'), 10, 2);
49
- add_filter('sgpbExtraNotifications', array($this, 'sgpbExtraNotifications'), 10, 1);
50
- add_filter('sgpbSystemInformation', array($this, 'systemInformation'), 10, 1);
51
- add_filter('plugin_action_links', array($this, 'pluginActionLinks'), 10, 4);
52
- add_filter('plugin_row_meta', array( $this, 'pluginRowMetas'), 10, 4);
53
- add_filter('rank_math/sitemap/exclude_post_type', array($this, 'excludeRankMath'), 10, 2);
54
- add_filter('sgpbUserSelectionQuery', array($this, 'userSelectionQueryAddExtraAttributes'), 100, 1);
55
- add_filter('sgpbFilterOptionsBeforeSaving', array($this, 'filterOptionsBeforeSaving'), 100, 1);
56
- add_filter('sgpbPopupExtraData', array($this, 'popupExtraDataRender'), 100, 2);
57
- add_filter('wpml_link_to_translation', array($this, 'linkToTranslationWpml'), 30, 4);
58
- add_filter('pll_get_post_types', array($this, 'enablePBpostTypeForTranslating'), 10, 2);
59
- }
60
-
61
- public function enablePBpostTypeForTranslating($postTypes, $isSettings)
62
- {
63
- $postTypes[SG_POPUP_POST_TYPE] = SG_POPUP_POST_TYPE;
64
-
65
- return $postTypes;
66
- }
67
-
68
- public function linkToTranslationWpml($link, $postId, $lang, $trid)
69
- {
70
- if (strpos($link, SG_POPUP_POST_TYPE) && strpos($link, 'source_lang') && isset($trid)) {
71
-
72
- $popupType = 'html';
73
- $popup = SGPopup::find($postId);
74
- if (!empty($popup) || !is_object($popup)) {
75
- $popupType = $popup->getType();
76
- }
77
- $link .= '&sgpb_type='.$popupType;
78
- }
79
-
80
- return $link;
81
- }
82
-
83
- public function popupExtraDataRender($popupId = 0, $popupOptions = array())
84
- {
85
- $floatingButton = '';
86
- if (empty($popupOptions['sgpb-enable-floating-button'])) {
87
- return $floatingButton;
88
- }
89
- $buttonStyles = 'z-index:99999999999;';
90
- $buttonClass = 'sgpb-'.$popupOptions['sgpb-floating-button-style'].'-'.$popupOptions['sgpb-floating-button-position'];
91
-
92
- if (isset($popupOptions['sgpb-floating-button-style']) && $popupOptions['sgpb-floating-button-style'] == 'basic' && strstr($popupOptions['sgpb-floating-button-position'], 'center')) {
93
- if (strstr($popupOptions['sgpb-floating-button-position'], 'top')) {
94
- $buttonStyles .= 'top: 0%;';
95
- $buttonStyles .= 'right: '.$popupOptions['sgpb-floating-button-position-right'].'%;';
96
- }
97
- else if (strstr($popupOptions['sgpb-floating-button-position'], 'bottom')) {
98
- $buttonStyles .= 'bottom: 0%;';
99
- $buttonStyles .= 'right: '.$popupOptions['sgpb-floating-button-position-right'].'%;';
100
- }
101
- else if (strstr($popupOptions['sgpb-floating-button-position'], 'left') || strstr($popupOptions['sgpb-floating-button-position'], 'right')) {
102
- $buttonStyles .= 'top: '.$popupOptions['sgpb-floating-button-position-top'].'%;';
103
- }
104
- }
105
-
106
- if (isset($popupOptions['sgpb-floating-button-font-size'])) {
107
- $buttonStyles .= 'font-size: '.$popupOptions['sgpb-floating-button-font-size'].'px;';
108
- }
109
- if (isset($popupOptions['sgpb-floating-button-border-size'])) {
110
- $buttonStyles .= 'border-width: '.$popupOptions['sgpb-floating-button-border-size'].'px;';
111
- $buttonStyles .= 'border-style: solid;';
112
- }
113
- if (isset($popupOptions['sgpb-floating-button-border-radius'])) {
114
- $buttonStyles .= 'border-radius: '.$popupOptions['sgpb-floating-button-border-radius'].'px;';
115
- }
116
- if (isset($popupOptions['sgpb-floating-button-border-color'])) {
117
- $buttonStyles .= 'border-color: '.$popupOptions['sgpb-floating-button-border-color'].';';
118
- }
119
- if (isset($popupOptions['sgpb-floating-button-bg-color'])) {
120
- $buttonStyles .= 'background-color: '.$popupOptions['sgpb-floating-button-bg-color'].';';
121
- }
122
- if (isset($popupOptions['sgpb-floating-button-text-color'])) {
123
- $buttonStyles .= 'color: '.$popupOptions['sgpb-floating-button-text-color'].';';
124
- }
125
-
126
- /*
127
- * We first hide to make all CSS load then we will show once document is ready
128
- * SgpbEventListener.eventsListenerAfterDocumentReady -> showFloatingButton
129
- */
130
- $buttonStyles .= 'display: none;';
131
-
132
- $floatingButton = '<div class="'.$buttonClass.' sgpb-floating-button sg-popup-id-'.$popupId.'" style="'.$buttonStyles.'"><span class="sgpb-'.$popupOptions['sgpb-floating-button-style'].'-floating-button-text">'.$popupOptions['sgpb-floating-button-text'].'</span></div>';
133
-
134
- return $floatingButton;
135
- }
136
-
137
- public function filterOptionsBeforeSaving($unfilteredData = array())
138
- {
139
- $externalOptions = array(
140
- 'icl_post_language' => 'sgpb-icl_post_language'
141
- );
142
-
143
- foreach ($externalOptions as $optionKey => $value) {
144
- if (isset($unfilteredData[$optionKey])) {
145
- $unfilteredData[$value] = $unfilteredData[$optionKey];
146
- // there is no need to unset the old index value, because in the next step we'll take only the values from indexes started with "sgpb"
147
- }
148
- }
149
-
150
- return $unfilteredData;
151
- }
152
-
153
- public function userSelectionQueryAddExtraAttributes($query)
154
- {
155
- $query .= ' status = 0 and unsubscribed = 0';
156
-
157
- return $query;
158
- }
159
-
160
- public function excludeRankMath($exclude, $type)
161
- {
162
- if ($type == SG_POPUP_POST_TYPE) {
163
- $exclude = true;
164
- }
165
-
166
- return $exclude;
167
- }
168
-
169
- public function pluginRowMetas($pluginMeta, $pluginFile, $pluginData, $status)
170
- {
171
- if (empty($pluginFile)) {
172
- return $pluginMeta;
173
- }
174
-
175
- $allExtensions = \SgpbDataConfig::allExtensionsKeys();
176
- $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
177
- $allExtensions[] = SG_POPUP_FILE_NAME;
178
-
179
- $rowMeta = array(
180
- 'rateus' => '<a href="'.SG_POPUP_RATE_US_URL.'" target="_blank">'.esc_html__('Rate us', SG_POPUP_TEXT_DOMAIN).'</a>',
181
- 'support' => '<a href="'.SG_POPUP_SUPPORT_URL.'" target="_blank">'.esc_html__('Support', SG_POPUP_TEXT_DOMAIN).'</a>'
182
- );
183
-
184
- if (in_array($pluginFile, $allExtensions)) {
185
- $pluginMeta = array_merge($pluginMeta, $rowMeta);
186
- }
187
-
188
- return $pluginMeta;
189
- }
190
-
191
- public function pluginActionLinks($actions, $pluginFile, $pluginData, $context)
192
- {
193
- if (empty($pluginFile)) {
194
- return $actions;
195
- }
196
-
197
- $allExtensions = \SgpbDataConfig::allExtensionsKeys();
198
- $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
199
- $allExtensions[] = SG_POPUP_FILE_NAME;
200
-
201
- $settingPageUrl = admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE;
202
-
203
- $links = array(
204
- 'settings' => '<a href="'.$settingPageUrl.'" target="_blank">'.esc_html__('Settings', SG_POPUP_TEXT_DOMAIN).'</a>',
205
- 'docs' => '<a href="'.SG_POPUP_TICKET_URL.'" target="_blank">'.esc_html__('Docs', SG_POPUP_TEXT_DOMAIN).'</a>'
206
- );
207
-
208
- if (in_array($pluginFile, $allExtensions)) {
209
- if ($pluginFile == SG_POPUP_FILE_NAME) {
210
- $getActiveExtensions = AdminHelper::getAllExtensions();
211
- if (empty($getActiveExtensions['active'])) {
212
- $links['upgrade'] = '<a style="color: #4364eb;" href="'.SG_POPUP_BUNDLE_URL.'" target="_blank">'.esc_html__('Upgrade', SG_POPUP_TEXT_DOMAIN).'</a>';
213
- }
214
- }
215
- $actions = array_merge($links, $actions);
216
- }
217
-
218
- return $actions;
219
- }
220
-
221
- public function systemInformation($infoContent)
222
- {
223
-
224
- $infoContent .= 'Platform: '.@$platform . "\n";
225
- $infoContent .= 'Browser Name: '.@$bname . "\n";
226
- $infoContent .= 'Browser Version: '.@$version . "\n";
227
- $infoContent .= 'User Agent: '.@$uAgent . "\n";
228
-
229
- return $infoContent;
230
- }
231
-
232
- public function popupContentLoadToPage($content, $popupId)
233
- {
234
- $customScripts = AdminHelper::renderCustomScripts($popupId);
235
- $content .= $customScripts;
236
-
237
- return $content;
238
- }
239
-
240
- public function sgpbExtraNotifications($notifications = array())
241
- {
242
- $license = self::licenseNotification();
243
- if (!empty($license)) {
244
- $notifications[] = $license;
245
- }
246
-
247
- $promotional = self::promotionalNotifications();
248
- if (!empty($promotional)) {
249
- $notifications[] = $promotional;
250
- }
251
-
252
- $supportBanner = self::supportBannerNotifcations();
253
- if (!empty($supportBanner)) {
254
- $notifications[] = $supportBanner;
255
- }
256
-
257
- return $notifications;
258
- }
259
-
260
- public static function supportBannerNotifcations()
261
- {
262
- $hideSupportBanner = get_option('sgpb-hide-support-banner');
263
- if (!empty($hideSupportBanner)) {
264
- return array();
265
- }
266
- $message = AdminHelper::supportBannerNotification();
267
- $notification['id'] = SGPB_SUPPORT_BANNER_NOTIFICATION_ID;
268
- $notification['priority'] = 1;
269
- $notification['type'] = 1;
270
- $notification['message'] = $message;
271
-
272
- return $notification;
273
- }
274
-
275
- public static function promotionalNotifications()
276
- {
277
- $alreadyDone = get_option('SGPBCloseReviewPopup-notification');
278
- if (!empty($alreadyDone)) {
279
- return array();
280
- }
281
- $id = SGPB_RATE_US_NOTIFICATION_ID;
282
- $type = 1;
283
- $priority = 1;
284
-
285
- $maxOpenPopupStatus = AdminHelper::shouldOpenForMaxOpenPopupMessage();
286
- // popup opening count notification
287
- if ($maxOpenPopupStatus) {
288
- $message = AdminHelper::getMaxOpenPopupsMessage();
289
- }
290
-
291
- $shouldOpenForDays = AdminHelper::shouldOpenReviewPopupForDays();
292
- if ($shouldOpenForDays && !$maxOpenPopupStatus) {
293
- $message = AdminHelper::getMaxOpenDaysMessage();
294
- }
295
- if (empty($message)) {
296
- return array();
297
- }
298
-
299
- $alternateNotification['priority'] = $priority;
300
- $alternateNotification['type'] = $type;
301
- $alternateNotification['id'] = $id;
302
- $alternateNotification['message'] = $message;
303
-
304
- return $alternateNotification;
305
- }
306
-
307
- public function licenseNotification()
308
- {
309
- $inactiveExtensionNotice = array();
310
- $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
311
- if ($dontShowLicenseBanner) {
312
- return $notifications;
313
- }
314
-
315
- $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
316
- $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
317
-
318
- if (!$inactive) {
319
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
320
- if ($hasInactiveExtensions) {
321
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
322
- $inactive = 'inactive';
323
- }
324
-
325
- }
326
-
327
- if ($hasInactiveExtensions && $inactive == 'inactive') {
328
- $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
329
- $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
330
- $message = '<b>'.__('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN).'</b>';
331
- $message .= '<br>';
332
- $message .= '<br>';
333
- $message .= '<b>'.__('You have activated Popup Builder extension(s). Please, don\'t forget to activate the license key(s) as well.', SG_POPUP_TEXT_DOMAIN).'</b>';
334
- $message .= '<b>'.$partOfContent.'</b>';
335
-
336
- $inactiveExtensionNotice['priority'] = 1;
337
- $inactiveExtensionNotice['type'] = 2;
338
- $inactiveExtensionNotice['id'] = 'sgpbMainActiveInactiveLicense';
339
- $inactiveExtensionNotice['message'] = $message;
340
- }
341
-
342
- return $inactiveExtensionNotice;
343
- }
344
-
345
- public function excludeSitemapsYoast($exclude = false, $postType)
346
- {
347
- $postTypeObject = get_post_type_object($postType);
348
- if (!is_object($postTypeObject)) {
349
- return $exclude;
350
- }
351
-
352
- if ($postTypeObject->public === false || $postType == SG_POPUP_POST_TYPE) {
353
- return true;
354
- }
355
-
356
- return $exclude;
357
- }
358
-
359
- public function defaultAdvancedOptionsValues($options = array())
360
- {
361
- $enablePopupOverlay = PopupBuilderActivePackage::canUseOption('sgpb-enable-popup-overlay');
362
- if (!$enablePopupOverlay) {
363
- $options['sgpb-enable-popup-overlay'] = 'on';
364
- }
365
-
366
- return $options;
367
- }
368
-
369
- public function excludePostToShowPrepare()
370
- {
371
- SgpbPopupConfig::popupTypesInit();
372
- $queryString = SGPopup::getActivePopupsQueryString();
373
- $this->setQueryString($queryString);
374
- add_filter('posts_where' , array($this, 'excludePostsToShow'), 10, 1);
375
- }
376
-
377
- public function exportFileName($fileName)
378
- {
379
- if (!empty($_GET['sgpbExportAction'])) {
380
- return SGPB_POPUP_EXPORT_FILE_NAME;
381
- }
382
-
383
- return $fileName;
384
- }
385
-
386
- public function filterOption($filterOption)
387
- {
388
- $extensionOptionsData = AdminHelper::getExtensionAvaliabilityOptions();
389
-
390
- if (empty($extensionOptionsData)) {
391
- return $filterOption;
392
- }
393
-
394
- foreach ($extensionOptionsData as $extensionKey => $extensionOptions) {
395
- $isAdvancedClosingActive = is_plugin_active($extensionKey);
396
- if (isset($filterOption['name']) && !$isAdvancedClosingActive) {
397
- $name = $filterOption['name'];
398
-
399
- if (in_array($name, $extensionOptions)) {
400
- $filterOption['status'] = false;
401
- }
402
- }
403
- }
404
-
405
- return $filterOption;
406
- }
407
-
408
- public function metaboxes($metaboxes)
409
- {
410
- $otherConditionsProLabel = '';
411
- $otherConditionsCanBeUsed = PopupBuilderActivePackage::canUseSection('popupOtherConditionsSection');
412
- if (!$otherConditionsCanBeUsed) {
413
- $otherConditionsProLabel .= '<a href="'.SG_POPUP_SCHEDULING_URL.'" target="_blank" class="sgpb-pro-label-metabox">';
414
- $otherConditionsProLabel .= __('UNLOCK OPTION', SG_POPUP_TEXT_DOMAIN).'</a>';
415
- }
416
- $metaboxes['targetMetaboxView'] = array(
417
- 'key' => 'targetMetaboxView',
418
- 'displayName' => 'Popup Display Rules',
419
- 'filePath' => SG_POPUP_VIEWS_PATH.'targetView.php',
420
- 'priority' => 'high'
421
- );
422
-
423
- $metaboxes['eventsMetaboxView'] = array(
424
- 'key' => 'eventsMetaboxView',
425
- 'displayName' => 'Popup Events',
426
- 'filePath' => SG_POPUP_VIEWS_PATH.'eventsView.php',
427
- 'priority' => 'high'
428
- );
429
-
430
- $metaboxes['conditionsMetaboxView'] = array(
431
- 'key' => 'conditionsMetaboxView',
432
- 'displayName' => 'Popup Conditions',
433
- 'filePath' => SG_POPUP_VIEWS_PATH.'conditionsView.php',
434
- 'priority' => 'high'
435
- );
436
-
437
- $metaboxes['behaviorAfterSpecialEventsMetaboxView'] = array(
438
- 'key' => 'behaviorAfterSpecialEventsMetaboxView',
439
- 'displayName' => 'Behavior After Special Events',
440
- 'filePath' => SG_POPUP_VIEWS_PATH.'behaviorAfterSpecialEventsView.php',
441
- 'priority' => 'high'
442
- );
443
-
444
- $metaboxes['popupDesignMetaBoxView'] = array(
445
- 'key' => 'popupDesignMetaBoxView',
446
- 'displayName' => 'Design',
447
- 'filePath' => SG_POPUP_VIEWS_PATH.'popupDesignView.php',
448
- 'priority' => 'high'
449
- );
450
-
451
- $metaboxes['closeSettings'] = array(
452
- 'key' => 'closeSettings',
453
- 'displayName' => 'Close Settings',
454
- 'filePath' => SG_POPUP_VIEWS_PATH.'closeSettingsView.php',
455
- 'priority' => 'high'
456
- );
457
-
458
- $metaboxes['spgdimension'] = array(
459
- 'key' => 'spgdimension',
460
- 'displayName' => 'Dimensions',
461
- 'filePath' => SG_POPUP_VIEWS_PATH.'dimensionsView.php',
462
- 'priority' => 'high'
463
- );
464
-
465
- $metaboxes['optionsMetaboxView'] = array(
466
- 'key' => 'optionsMetaboxView',
467
- 'displayName' => 'Popup Options',
468
- 'filePath' => SG_POPUP_VIEWS_PATH.'optionsView.php',
469
- 'priority' => 'high'
470
- );
471
-
472
- $metaboxes['otherConditionsMetaBoxView'] = array(
473
- 'key' => 'otherConditionsMetaBoxView',
474
- 'displayName' => 'Popup Additional Conditions'.$otherConditionsProLabel,
475
- 'filePath' => SG_POPUP_VIEWS_PATH.'otherConditionsView.php',
476
- 'priority' => 'high'
477
- );
478
-
479
- $metaboxes['customCssJs'] = array(
480
- 'key' => 'customCssJs',
481
- 'displayName' => 'Custom JS or CSS',
482
- 'filePath' => SG_POPUP_VIEWS_PATH.'customEditor.php',
483
- 'priority' => 'low'
484
- );
485
-
486
- $metaboxes['floatingButton'] = array(
487
- 'key' => 'floatingButton',
488
- 'displayName' => 'Floating Button',
489
- 'filePath' => SG_POPUP_VIEWS_PATH.'floatingButton.php',
490
- 'context' => 'side',
491
- 'priority' => 'high'
492
- );
493
-
494
- $metaboxes['popupOpeningCounter'] = array(
495
- 'key' => 'popupOpeningCounter',
496
- 'displayName' => 'Popup statistics',
497
- 'filePath' => SG_POPUP_VIEWS_PATH.'popupOpeningCounter.php',
498
- 'context' => 'side',
499
- 'priority' => 'low'
500
- );
501
-
502
- return $metaboxes;
503
- }
504
-
505
- public function popupEvents($events)
506
- {
507
- foreach ($events as $eventKey => $eventData) {
508
- if (isset($eventData['param'])) {
509
- if ($eventData['param'] == SGPB_CSS_CLASS_ACTIONS_KEY) {
510
- unset($events[$eventKey]);
511
- $events[] = array('param' => 'click');
512
- $events[] = array('param' => 'hover');
513
- $events[] = array('param' => 'confirm');
514
- }
515
- else if ($eventData['param'] == SGPB_CLICK_ACTION_KEY) {
516
- $events[$eventKey]['param'] = 'click';
517
- }
518
- else if ($eventData['param'] == SGPB_HOVER_ACTION_KEY) {
519
- $events[$eventKey]['param'] = 'hover';
520
- }
521
- }
522
- }
523
-
524
- return $events;
525
- }
526
-
527
- public function savedPostData($postData)
528
- {
529
- // for old popups here we change already saved old popup id
530
- if (isset($postData['sgpb-mailchimp-success-popup'])) {
531
- // sgpGetCorrectPopupId it's a temporary function and it will be removed in future
532
- if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
533
- $postData['sgpb-mailchimp-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-mailchimp-success-popup']);
534
- }
535
- }
536
- // for old popups here we change already saved old popup id
537
- if (isset($postData['sgpb-aweber-success-popup'])) {
538
- if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
539
- $postData['sgpb-aweber-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-aweber-success-popup']);
540
- }
541
- }
542
-
543
- return $postData;
544
- }
545
-
546
- public function removeAddNewSubmenu()
547
- {
548
- //we don't need the default add new, since we are using our custom page for it
549
- $page = remove_submenu_page(
550
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
551
- 'post-new.php?post_type='.SG_POPUP_POST_TYPE
552
- );
553
- }
554
-
555
- public function maybeShortenEddFilename($return, $package)
556
- {
557
- if (strpos($package, SG_POPUP_STORE_URL) !== false) {
558
- add_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 100, 2);
559
- }
560
- return $return;
561
- }
562
-
563
- public function shortenEddFilename($filename, $ext)
564
- {
565
- $filename = substr($filename, 0, 20).$ext;
566
- remove_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 10);
567
- return $filename;
568
- }
569
-
570
- public function editPopupPreviewLink($previewLink = '', $post = array())
571
- {
572
- if (!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) {
573
- $popupId = $post->ID;
574
- $targets = get_post_meta($popupId, 'sg_popup_target_preview', true);
575
- if (empty($targets['sgpb-target'][0])) {
576
- return $previewLink .= '/?sg_popup_preview_id='.$popupId;
577
- }
578
- $targetParams = @$targets['sgpb-target'][0][0]['param'];
579
- if ((!empty($targetParams) && $targetParams == 'not_rule') || empty($targetParams)) {
580
- $previewLink = home_url();
581
- $previewLink .= '/?sg_popup_preview_id='.$popupId;
582
-
583
- return $previewLink;
584
- }
585
- foreach ($targets['sgpb-target'][0] as $targetKey => $targetValue) {
586
- if (!isset($targetValue['operator']) || $targetValue['operator'] == '!=') {
587
- continue;
588
- }
589
- $previewLink = self::getPopupPreviewLink($targetValue, $popupId);
590
- $previewLink .= '/?sg_popup_preview_id='.$popupId;
591
- }
592
- }
593
-
594
- return $previewLink;
595
- }
596
-
597
- public static function getPopupPreviewLink($targetData, $popupId)
598
- {
599
- $previewLink = home_url();
600
-
601
- if (empty($targetData['param'])) {
602
- return $previewLink;
603
- }
604
- $targetParam = $targetData['param'];
605
-
606
- if ($targetParam == 'everywhere') {
607
- return $previewLink;
608
- }
609
-
610
- $args = array(
611
- 'orderby' => 'rand'
612
- );
613
-
614
- // posts
615
- if (strpos($targetData['param'], '_all')) {
616
- if ($targetData['param'] == 'post_all') {
617
- $args['post_type'] = 'post';
618
- }
619
- if ($targetData['param'] == 'page_all') {
620
- $args['post_type'] = 'page';
621
- }
622
- }
623
- if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
624
- $args['post_type'] = $targetData['value'];
625
- }
626
- if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
627
- $pageTypes = $targetData['value'];
628
- foreach ($pageTypes as $pageType) {
629
-
630
- if ($pageType == 'is_home_page') {
631
- if (is_front_page() && is_home()) {
632
- // default homepage
633
- return get_home_url();
634
- }
635
- else if (is_front_page()) {
636
- // static homepage
637
- return get_home_url();
638
- }
639
- }
640
- else if (function_exists($pageType)) {
641
- if ($pageType == 'is_home') {
642
- return get_home_url();
643
- }
644
- else if ($pageType == 'is_search') {
645
- return get_search_link();
646
- }
647
- else if ($pageType == 'is_shop') {
648
- return get_home_url().'/shop/';
649
- }
650
- }
651
- }
652
- }
653
- if (isset($args['post_type'])) {
654
- $the_query = new WP_Query($args);
655
- foreach ($the_query->posts as $post) {
656
- $postId = $post->ID;
657
- if (get_permalink($postId)) {
658
- return get_permalink($postId);
659
- }
660
- }
661
- }
662
- // selected post/page/custom_post_types...
663
- if (strpos($targetData['param'], '_selected') && !empty($targetData['value'])) {
664
- $value = array_keys($targetData['value']);
665
- if (!empty($value[0])) {
666
- if (get_permalink($value[0])) {
667
- return get_permalink($value[0]);
668
- }
669
- }
670
- }
671
- if (strpos($targetData['param'], '_archive') && !empty($targetData['value'])) {
672
- $value = array_keys($targetData['value']);
673
- if (!empty($value[0])) {
674
- if (get_permalink($value[0])) {
675
- return get_permalink($value[0]);
676
- }
677
- }
678
- }
679
-
680
- return $previewLink;
681
- }
682
-
683
- public function excludePostsToShow($where)
684
- {
685
- if (function_exists('is_admin') && is_admin()) {
686
- if (!function_exists('get_current_screen')) {
687
- return $where;
688
- }
689
-
690
- $screen = get_current_screen();
691
- if (empty($screen)) {
692
- return $where;
693
- }
694
-
695
- $postType = $screen->post_type;
696
- if ($postType == SG_POPUP_POST_TYPE &&
697
- $screen instanceof \WP_Screen &&
698
- $screen->id === 'edit-popupbuilder') {
699
- if (class_exists('sgpb\SGPopup')) {
700
- $activePopupsQuery = $this->getQueryString();
701
- if ($activePopupsQuery && $activePopupsQuery != '') {
702
- $where .= $activePopupsQuery;
703
- }
704
- }
705
- }
706
- }
707
-
708
- return $where;
709
- }
710
-
711
- public function clearContentPreviewMode($content)
712
- {
713
- global $post_type;
714
-
715
- if (is_preview() && $post_type == SG_POPUP_POST_TYPE) {
716
- $content = '';
717
- }
718
-
719
- return $content;
720
- }
721
-
722
- public function filterPopupContent($content, $popupId)
723
- {
724
- preg_match_all('/<iframe.*?src="(.*?)".*?<\/iframe>/', $content, $matches);
725
- /*$finalContent = '';*/
726
- // $matches[0] array contain iframes stings
727
- // $matches[1] array contain iframes URLs
728
- if (empty($matches) && empty($matches[0]) && empty($matches[1])) {
729
- return $content;
730
- }
731
- $urls = $matches[1];
732
-
733
- foreach ($matches[0] as $key => $iframe) {
734
- if (empty($urls[$key])) {
735
- continue;
736
- }
737
-
738
- $pos = strpos($iframe, $urls[$key]);
739
-
740
- if ($pos === false) {
741
- continue;
742
- }
743
-
744
- $content = str_replace(' src="'.$urls[$key].'"', ' src="" data-attr-src="'.esc_attr($urls[$key]).'"', $content);
745
- }
746
- if (function_exists('do_blocks')) {
747
- $content = do_blocks($content);
748
- }
749
-
750
- return do_shortcode($content);
751
- }
752
-
753
- public function addNewPostUrl($url, $path)
754
- {
755
- if ($path == 'post-new.php?post_type='.SG_POPUP_POST_TYPE) {
756
- $url = str_replace('post-new.php?post_type='.SG_POPUP_POST_TYPE, 'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_POST_TYPE, $url);
757
- }
758
-
759
- return $url;
760
- }
761
-
762
- public function popupsTableColumns($columns)
763
- {
764
- unset($columns['date']);
765
-
766
- $additionalItems = array();
767
- $additionalItems['counter'] = __('Views', SG_POPUP_TEXT_DOMAIN);
768
- $additionalItems['onOff'] = __('Enabled (show popup)', SG_POPUP_TEXT_DOMAIN);
769
- $additionalItems['type'] = __('Type', SG_POPUP_TEXT_DOMAIN);
770
- $additionalItems['shortcode'] = __('Shortcode', SG_POPUP_TEXT_DOMAIN);
771
- $additionalItems['className'] = __('Class', SG_POPUP_TEXT_DOMAIN);
772
-
773
- return $columns + $additionalItems;
774
- }
775
-
776
- /**
777
- * Function to add/hide links from popups dataTable row
778
- */
779
- public function quickRowLinksManager($actions, $post)
780
- {
781
- global $post_type;
782
-
783
- if ($post_type != SG_POPUP_POST_TYPE) {
784
- return $actions;
785
- }
786
- // remove quick edit link
787
- unset($actions['inline hide-if-no-js']);
788
- // remove view link
789
- unset($actions['view']);
790
-
791
- $actions['clone'] = '<a href="'.$this->popupGetClonePostLink($post->ID , 'display', false).'" title="';
792
- $actions['clone'] .= esc_attr__("Clone this item", SG_POPUP_TEXT_DOMAIN);
793
- $actions['clone'] .= '">'. esc_html__('Clone', SG_POPUP_TEXT_DOMAIN).'</a>';
794
-
795
- return $actions;
796
- }
797
-
798
- /**
799
- * Retrieve duplicate post link for post.
800
- *
801
- * @param int $id Optional. Post ID.
802
- * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
803
- * @return string
804
- */
805
- public function popupGetClonePostLink($id = 0, $context = 'display')
806
- {
807
- if (!$post = get_post($id)) {
808
- return;
809
- }
810
- $actionName = "popupSaveAsNew";
811
-
812
- if ('display' == $context) {
813
- $action = '?action='.$actionName.'&amp;post='.$post->ID;
814
- } else {
815
- $action = '?action='.$actionName.'&post='.$post->ID;
816
- }
817
-
818
- $postTypeObject = get_post_type_object($post->post_type);
819
-
820
- if (!$postTypeObject) {
821
- return;
822
- }
823
-
824
- return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
825
- }
826
-
827
- /* media button scripts */
828
- public function adminJsFilter($jsFiles)
829
- {
830
- $allowToShow = MediaButton::allowToShow();
831
- if ($allowToShow) {
832
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
833
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
834
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Popup.js');
835
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
836
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'MediaButton.js');
837
-
838
- $jsFiles['localizeData'][] = array(
839
- 'handle' => 'Popup.js',
840
- 'name' => 'sgpbPublicUrl',
841
- 'data' => SG_POPUP_PUBLIC_URL
842
- );
843
-
844
- $jsFiles['localizeData'][] = array(
845
- 'handle' => 'MediaButton.js',
846
- 'name' => 'mediaButtonParams',
847
- 'data' => array(
848
- 'currentPostType' => get_post_type(),
849
- 'popupBuilderPostType' => SG_POPUP_POST_TYPE,
850
- 'ajaxUrl' => admin_url('admin-ajax.php'),
851
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
852
- )
853
- );
854
- }
855
-
856
- return $jsFiles;
857
- }
858
-
859
- /* media button styles */
860
- public function sgpbAdminCssFiles($cssFiles)
861
- {
862
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
863
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
864
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
865
-
866
- return $cssFiles;
867
- }
868
- }
869
-
870
-
1
+ <?php
2
+ namespace sgpb;
3
+ use \WP_Query;
4
+ use \SgpbPopupConfig;
5
+ use sgpb\PopupBuilderActivePackage;
6
+ use sgpb\SGPopup;
7
+
8
+ class Filters
9
+ {
10
+ private $activePopupsQueryString = '';
11
+
12
+ public function setQueryString($activePopupsQueryString)
13
+ {
14
+ $this->activePopupsQueryString = $activePopupsQueryString;
15
+ }
16
+
17
+ public function getQueryString()
18
+ {
19
+ return $this->activePopupsQueryString;
20
+ }
21
+
22
+ public function __construct()
23
+ {
24
+ $this->init();
25
+ }
26
+
27
+ public function init()
28
+ {
29
+ add_filter('admin_url', array($this, 'addNewPostUrl'), 10, 2);
30
+ add_filter('wpseo_sitemap_exclude_post_type', array($this, 'excludeSitemapsYoast'), 10, 2);
31
+ add_filter('admin_menu', array($this, 'removeAddNewSubmenu'), 10, 2);
32
+ add_filter('manage_'.SG_POPUP_POST_TYPE.'_posts_columns', array($this, 'popupsTableColumns'));
33
+ add_filter('post_row_actions', array($this, 'quickRowLinksManager'), 10, 2);
34
+ add_filter('sgpbAdminJs', array($this, 'adminJsFilter'), 1, 1);
35
+ add_filter('sgpbAdminCssFiles', array($this, 'sgpbAdminCssFiles'), 1, 1);
36
+ add_filter('sgpbPopupContentLoadToPage', array($this, 'filterPopupContent'), 10, 2);
37
+ add_filter('the_content', array($this, 'clearContentPreviewMode'), 10, 1);
38
+ // The priority of this action should be higher than the extensions' init priority.
39
+ add_action('init', array($this, 'excludePostToShowPrepare'), 99999999);
40
+ add_filter('preview_post_link', array($this, 'editPopupPreviewLink'), 10, 2);
41
+ add_filter('upgrader_pre_download', array($this, 'maybeShortenEddFilename'), 10, 4);
42
+ add_filter('sgpbSavedPostData', array($this, 'savedPostData'), 10, 1);
43
+ add_filter('sgpbPopupEvents', array($this, 'popupEvents'), 10, 1);
44
+ add_filter('sgpbAdditionalMetaboxes', array($this, 'metaboxes'), 10, 1);
45
+ add_filter('sgpbOptionAvailable', array($this, 'filterOption'), 10, 1);
46
+ add_filter('export_wp_filename', array($this, 'exportFileName'), 10, 1);
47
+ add_filter('sgpbAdvancedOptionsDefaultValues', array($this, 'defaultAdvancedOptionsValues'), 10, 1);
48
+ add_filter('sgpbPopupContentLoadToPage', array($this, 'popupContentLoadToPage'), 10, 2);
49
+ add_filter('sgpbExtraNotifications', array($this, 'sgpbExtraNotifications'), 10, 1);
50
+ add_filter('sgpbSystemInformation', array($this, 'systemInformation'), 10, 1);
51
+ add_filter('plugin_action_links', array($this, 'pluginActionLinks'), 10, 4);
52
+ add_filter('plugin_row_meta', array( $this, 'pluginRowMetas'), 10, 4);
53
+ add_filter('rank_math/sitemap/exclude_post_type', array($this, 'excludeRankMath'), 10, 2);
54
+ add_filter('sgpbUserSelectionQuery', array($this, 'userSelectionQueryAddExtraAttributes'), 100, 1);
55
+ add_filter('sgpbFilterOptionsBeforeSaving', array($this, 'filterOptionsBeforeSaving'), 100, 1);
56
+ add_filter('sgpbPopupExtraData', array($this, 'popupExtraDataRender'), 100, 2);
57
+ add_filter('wpml_link_to_translation', array($this, 'linkToTranslationWpml'), 30, 4);
58
+ add_filter('pll_get_post_types', array($this, 'enablePBpostTypeForTranslating'), 10, 2);
59
+ }
60
+
61
+ public function enablePBpostTypeForTranslating($postTypes, $isSettings)
62
+ {
63
+ $postTypes[SG_POPUP_POST_TYPE] = SG_POPUP_POST_TYPE;
64
+
65
+ return $postTypes;
66
+ }
67
+
68
+ public function linkToTranslationWpml($link, $postId, $lang, $trid)
69
+ {
70
+ if (strpos($link, SG_POPUP_POST_TYPE) && strpos($link, 'source_lang') && isset($trid)) {
71
+
72
+ $popupType = 'html';
73
+ $popup = SGPopup::find($postId);
74
+ if (!empty($popup) || !is_object($popup)) {
75
+ $popupType = $popup->getType();
76
+ }
77
+ $link .= '&sgpb_type='.$popupType;
78
+ }
79
+
80
+ return $link;
81
+ }
82
+
83
+ public function popupExtraDataRender($popupId = 0, $popupOptions = array())
84
+ {
85
+ $floatingButton = '';
86
+ if (empty($popupOptions['sgpb-enable-floating-button'])) {
87
+ return $floatingButton;
88
+ }
89
+ $buttonStyles = 'z-index:99999999999;';
90
+ $buttonClass = 'sgpb-'.$popupOptions['sgpb-floating-button-style'].'-'.$popupOptions['sgpb-floating-button-position'];
91
+
92
+ if (isset($popupOptions['sgpb-floating-button-style']) && $popupOptions['sgpb-floating-button-style'] == 'basic' && strstr($popupOptions['sgpb-floating-button-position'], 'center')) {
93
+ if (strstr($popupOptions['sgpb-floating-button-position'], 'top')) {
94
+ $buttonStyles .= 'top: 0%;';
95
+ $buttonStyles .= 'right: '.$popupOptions['sgpb-floating-button-position-right'].'%;';
96
+ }
97
+ else if (strstr($popupOptions['sgpb-floating-button-position'], 'bottom')) {
98
+ $buttonStyles .= 'bottom: 0%;';
99
+ $buttonStyles .= 'right: '.$popupOptions['sgpb-floating-button-position-right'].'%;';
100
+ }
101
+ else if (strstr($popupOptions['sgpb-floating-button-position'], 'left') || strstr($popupOptions['sgpb-floating-button-position'], 'right')) {
102
+ $buttonStyles .= 'top: '.$popupOptions['sgpb-floating-button-position-top'].'%;';
103
+ }
104
+ }
105
+
106
+ if (isset($popupOptions['sgpb-floating-button-font-size'])) {
107
+ $buttonStyles .= 'font-size: '.$popupOptions['sgpb-floating-button-font-size'].'px;';
108
+ }
109
+ if (isset($popupOptions['sgpb-floating-button-border-size'])) {
110
+ $buttonStyles .= 'border-width: '.$popupOptions['sgpb-floating-button-border-size'].'px;';
111
+ $buttonStyles .= 'border-style: solid;';
112
+ }
113
+ if (isset($popupOptions['sgpb-floating-button-border-radius'])) {
114
+ $buttonStyles .= 'border-radius: '.$popupOptions['sgpb-floating-button-border-radius'].'px;';
115
+ }
116
+ if (isset($popupOptions['sgpb-floating-button-border-color'])) {
117
+ $buttonStyles .= 'border-color: '.$popupOptions['sgpb-floating-button-border-color'].';';
118
+ }
119
+ if (isset($popupOptions['sgpb-floating-button-bg-color'])) {
120
+ $buttonStyles .= 'background-color: '.$popupOptions['sgpb-floating-button-bg-color'].';';
121
+ }
122
+ if (isset($popupOptions['sgpb-floating-button-text-color'])) {
123
+ $buttonStyles .= 'color: '.$popupOptions['sgpb-floating-button-text-color'].';';
124
+ }
125
+
126
+ /*
127
+ * We first hide to make all CSS load then we will show once document is ready
128
+ * SgpbEventListener.eventsListenerAfterDocumentReady -> showFloatingButton
129
+ */
130
+ $buttonStyles .= 'display: none;';
131
+
132
+ $floatingButton = '<div class="'.$buttonClass.' sgpb-floating-button sg-popup-id-'.$popupId.'" style="'.$buttonStyles.'"><span class="sgpb-'.$popupOptions['sgpb-floating-button-style'].'-floating-button-text">'.$popupOptions['sgpb-floating-button-text'].'</span></div>';
133
+
134
+ return $floatingButton;
135
+ }
136
+
137
+ public function filterOptionsBeforeSaving($unfilteredData = array())
138
+ {
139
+ $externalOptions = array(
140
+ 'icl_post_language' => 'sgpb-icl_post_language'
141
+ );
142
+
143
+ foreach ($externalOptions as $optionKey => $value) {
144
+ if (isset($unfilteredData[$optionKey])) {
145
+ $unfilteredData[$value] = $unfilteredData[$optionKey];
146
+ // there is no need to unset the old index value, because in the next step we'll take only the values from indexes started with "sgpb"
147
+ }
148
+ }
149
+
150
+ return $unfilteredData;
151
+ }
152
+
153
+ public function userSelectionQueryAddExtraAttributes($query)
154
+ {
155
+ $query .= ' status = 0 and unsubscribed = 0';
156
+
157
+ return $query;
158
+ }
159
+
160
+ public function excludeRankMath($exclude, $type)
161
+ {
162
+ if ($type == SG_POPUP_POST_TYPE) {
163
+ $exclude = true;
164
+ }
165
+
166
+ return $exclude;
167
+ }
168
+
169
+ public function pluginRowMetas($pluginMeta, $pluginFile, $pluginData, $status)
170
+ {
171
+ if (empty($pluginFile)) {
172
+ return $pluginMeta;
173
+ }
174
+
175
+ $allExtensions = \SgpbDataConfig::allExtensionsKeys();
176
+ $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
177
+ $allExtensions[] = SG_POPUP_FILE_NAME;
178
+
179
+ $rowMeta = array(
180
+ 'rateus' => '<a href="'.SG_POPUP_RATE_US_URL.'" target="_blank">'.esc_html__('Rate us', SG_POPUP_TEXT_DOMAIN).'</a>',
181
+ 'support' => '<a href="'.SG_POPUP_SUPPORT_URL.'" target="_blank">'.esc_html__('Support', SG_POPUP_TEXT_DOMAIN).'</a>'
182
+ );
183
+
184
+ if (in_array($pluginFile, $allExtensions)) {
185
+ $pluginMeta = array_merge($pluginMeta, $rowMeta);
186
+ }
187
+
188
+ return $pluginMeta;
189
+ }
190
+
191
+ public function pluginActionLinks($actions, $pluginFile, $pluginData, $context)
192
+ {
193
+ if (empty($pluginFile)) {
194
+ return $actions;
195
+ }
196
+
197
+ $allExtensions = \SgpbDataConfig::allExtensionsKeys();
198
+ $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
199
+ $allExtensions[] = SG_POPUP_FILE_NAME;
200
+
201
+ $settingPageUrl = admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE;
202
+
203
+ $links = array(
204
+ 'settings' => '<a href="'.$settingPageUrl.'" target="_blank">'.esc_html__('Settings', SG_POPUP_TEXT_DOMAIN).'</a>',
205
+ 'docs' => '<a href="'.SG_POPUP_TICKET_URL.'" target="_blank">'.esc_html__('Docs', SG_POPUP_TEXT_DOMAIN).'</a>'
206
+ );
207
+
208
+ if (in_array($pluginFile, $allExtensions)) {
209
+ if ($pluginFile == SG_POPUP_FILE_NAME) {
210
+ $getActiveExtensions = AdminHelper::getAllExtensions();
211
+ if (empty($getActiveExtensions['active'])) {
212
+ $links['upgrade'] = '<a style="color: #4364eb;" href="'.SG_POPUP_BUNDLE_URL.'" target="_blank">'.esc_html__('Upgrade', SG_POPUP_TEXT_DOMAIN).'</a>';
213
+ }
214
+ }
215
+ $actions = array_merge($links, $actions);
216
+ }
217
+
218
+ return $actions;
219
+ }
220
+
221
+ public function systemInformation($infoContent)
222
+ {
223
+
224
+ $infoContent .= 'Platform: '.@$platform . "\n";
225
+ $infoContent .= 'Browser Name: '.@$bname . "\n";
226
+ $infoContent .= 'Browser Version: '.@$version . "\n";
227
+ $infoContent .= 'User Agent: '.@$uAgent . "\n";
228
+
229
+ return $infoContent;
230
+ }
231
+
232
+ public function popupContentLoadToPage($content, $popupId)
233
+ {
234
+ $customScripts = AdminHelper::renderCustomScripts($popupId);
235
+ $content .= $customScripts;
236
+
237
+ return $content;
238
+ }
239
+
240
+ public function sgpbExtraNotifications($notifications = array())
241
+ {
242
+ $license = self::licenseNotification();
243
+ if (!empty($license)) {
244
+ $notifications[] = $license;
245
+ }
246
+
247
+ $promotional = self::promotionalNotifications();
248
+ if (!empty($promotional)) {
249
+ $notifications[] = $promotional;
250
+ }
251
+
252
+ $supportBanner = self::supportBannerNotifcations();
253
+ if (!empty($supportBanner)) {
254
+ $notifications[] = $supportBanner;
255
+ }
256
+
257
+ return $notifications;
258
+ }
259
+
260
+ public static function supportBannerNotifcations()
261
+ {
262
+ $hideSupportBanner = get_option('sgpb-hide-support-banner');
263
+ if (!empty($hideSupportBanner)) {
264
+ return array();
265
+ }
266
+ $message = AdminHelper::supportBannerNotification();
267
+ $notification['id'] = SGPB_SUPPORT_BANNER_NOTIFICATION_ID;
268
+ $notification['priority'] = 1;
269
+ $notification['type'] = 1;
270
+ $notification['message'] = $message;
271
+
272
+ return $notification;
273
+ }
274
+
275
+ public static function promotionalNotifications()
276
+ {
277
+ $alreadyDone = get_option('SGPBCloseReviewPopup-notification');
278
+ if (!empty($alreadyDone)) {
279
+ return array();
280
+ }
281
+ $id = SGPB_RATE_US_NOTIFICATION_ID;
282
+ $type = 1;
283
+ $priority = 1;
284
+
285
+ $maxOpenPopupStatus = AdminHelper::shouldOpenForMaxOpenPopupMessage();
286
+ // popup opening count notification
287
+ if ($maxOpenPopupStatus) {
288
+ $message = AdminHelper::getMaxOpenPopupsMessage();
289
+ }
290
+
291
+ $shouldOpenForDays = AdminHelper::shouldOpenReviewPopupForDays();
292
+ if ($shouldOpenForDays && !$maxOpenPopupStatus) {
293
+ $message = AdminHelper::getMaxOpenDaysMessage();
294
+ }
295
+ if (empty($message)) {
296
+ return array();
297
+ }
298
+
299
+ $alternateNotification['priority'] = $priority;
300
+ $alternateNotification['type'] = $type;
301
+ $alternateNotification['id'] = $id;
302
+ $alternateNotification['message'] = $message;
303
+
304
+ return $alternateNotification;
305
+ }
306
+
307
+ public function licenseNotification()
308
+ {
309
+ $inactiveExtensionNotice = array();
310
+ $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
311
+ if ($dontShowLicenseBanner) {
312
+ return $notifications;
313
+ }
314
+
315
+ $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
316
+ $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
317
+
318
+ if (!$inactive) {
319
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
320
+ if ($hasInactiveExtensions) {
321
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
322
+ $inactive = 'inactive';
323
+ }
324
+
325
+ }
326
+
327
+ if ($hasInactiveExtensions && $inactive == 'inactive') {
328
+ $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
329
+ $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
330
+ $message = '<b>'.__('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN).'</b>';
331
+ $message .= '<br>';
332
+ $message .= '<br>';
333
+ $message .= '<b>'.__('You have activated Popup Builder extension(s). Please, don\'t forget to activate the license key(s) as well.', SG_POPUP_TEXT_DOMAIN).'</b>';
334
+ $message .= '<b>'.$partOfContent.'</b>';
335
+
336
+ $inactiveExtensionNotice['priority'] = 1;
337
+ $inactiveExtensionNotice['type'] = 2;
338
+ $inactiveExtensionNotice['id'] = 'sgpbMainActiveInactiveLicense';
339
+ $inactiveExtensionNotice['message'] = $message;
340
+ }
341
+
342
+ return $inactiveExtensionNotice;
343
+ }
344
+
345
+ public function excludeSitemapsYoast($exclude = false, $postType)
346
+ {
347
+ $postTypeObject = get_post_type_object($postType);
348
+ if (!is_object($postTypeObject)) {
349
+ return $exclude;
350
+ }
351
+
352
+ if ($postTypeObject->public === false || $postType == SG_POPUP_POST_TYPE) {
353
+ return true;
354
+ }
355
+
356
+ return $exclude;
357
+ }
358
+
359
+ public function defaultAdvancedOptionsValues($options = array())
360
+ {
361
+ $enablePopupOverlay = PopupBuilderActivePackage::canUseOption('sgpb-enable-popup-overlay');
362
+ if (!$enablePopupOverlay) {
363
+ $options['sgpb-enable-popup-overlay'] = 'on';
364
+ }
365
+
366
+ return $options;
367
+ }
368
+
369
+ public function excludePostToShowPrepare()
370
+ {
371
+ SgpbPopupConfig::popupTypesInit();
372
+ $queryString = SGPopup::getActivePopupsQueryString();
373
+ $this->setQueryString($queryString);
374
+ add_filter('posts_where' , array($this, 'excludePostsToShow'), 10, 1);
375
+ }
376
+
377
+ public function exportFileName($fileName)
378
+ {
379
+ if (!empty($_GET['sgpbExportAction'])) {
380
+ return SGPB_POPUP_EXPORT_FILE_NAME;
381
+ }
382
+
383
+ return $fileName;
384
+ }
385
+
386
+ public function filterOption($filterOption)
387
+ {
388
+ $extensionOptionsData = AdminHelper::getExtensionAvaliabilityOptions();
389
+
390
+ if (empty($extensionOptionsData)) {
391
+ return $filterOption;
392
+ }
393
+
394
+ foreach ($extensionOptionsData as $extensionKey => $extensionOptions) {
395
+ $isAdvancedClosingActive = is_plugin_active($extensionKey);
396
+ if (isset($filterOption['name']) && !$isAdvancedClosingActive) {
397
+ $name = $filterOption['name'];
398
+
399
+ if (in_array($name, $extensionOptions)) {
400
+ $filterOption['status'] = false;
401
+ }
402
+ }
403
+ }
404
+
405
+ return $filterOption;
406
+ }
407
+
408
+ public function metaboxes($metaboxes)
409
+ {
410
+ $otherConditionsProLabel = '';
411
+ $otherConditionsCanBeUsed = PopupBuilderActivePackage::canUseSection('popupOtherConditionsSection');
412
+ if (!$otherConditionsCanBeUsed) {
413
+ $otherConditionsProLabel .= '<a href="'.SG_POPUP_SCHEDULING_URL.'" target="_blank" class="sgpb-pro-label-metabox">';
414
+ $otherConditionsProLabel .= __('UNLOCK OPTION', SG_POPUP_TEXT_DOMAIN).'</a>';
415
+ }
416
+ $metaboxes['targetMetaboxView'] = array(
417
+ 'key' => 'targetMetaboxView',
418
+ 'displayName' => 'Popup Display Rules',
419
+ 'filePath' => SG_POPUP_VIEWS_PATH.'targetView.php',
420
+ 'priority' => 'high'
421
+ );
422
+
423
+ $metaboxes['eventsMetaboxView'] = array(
424
+ 'key' => 'eventsMetaboxView',
425
+ 'displayName' => 'Popup Events',
426
+ 'filePath' => SG_POPUP_VIEWS_PATH.'eventsView.php',
427
+ 'priority' => 'high'
428
+ );
429
+
430
+ $metaboxes['conditionsMetaboxView'] = array(
431
+ 'key' => 'conditionsMetaboxView',
432
+ 'displayName' => 'Popup Conditions',
433
+ 'filePath' => SG_POPUP_VIEWS_PATH.'conditionsView.php',
434
+ 'priority' => 'high'
435
+ );
436
+
437
+ $metaboxes['behaviorAfterSpecialEventsMetaboxView'] = array(
438
+ 'key' => 'behaviorAfterSpecialEventsMetaboxView',
439
+ 'displayName' => 'Behavior After Special Events',
440
+ 'filePath' => SG_POPUP_VIEWS_PATH.'behaviorAfterSpecialEventsView.php',
441
+ 'priority' => 'high'
442
+ );
443
+
444
+ $metaboxes['popupDesignMetaBoxView'] = array(
445
+ 'key' => 'popupDesignMetaBoxView',
446
+ 'displayName' => 'Design',
447
+ 'filePath' => SG_POPUP_VIEWS_PATH.'popupDesignView.php',
448
+ 'priority' => 'high'
449
+ );
450
+
451
+ $metaboxes['closeSettings'] = array(
452
+ 'key' => 'closeSettings',
453
+ 'displayName' => 'Close Settings',
454
+ 'filePath' => SG_POPUP_VIEWS_PATH.'closeSettingsView.php',
455
+ 'priority' => 'high'
456
+ );
457
+
458
+ $metaboxes['spgdimension'] = array(
459
+ 'key' => 'spgdimension',
460
+ 'displayName' => 'Dimensions',
461
+ 'filePath' => SG_POPUP_VIEWS_PATH.'dimensionsView.php',
462
+ 'priority' => 'high'
463
+ );
464
+
465
+ $metaboxes['optionsMetaboxView'] = array(
466
+ 'key' => 'optionsMetaboxView',
467
+ 'displayName' => 'Popup Options',
468
+ 'filePath' => SG_POPUP_VIEWS_PATH.'optionsView.php',
469
+ 'priority' => 'high'
470
+ );
471
+
472
+ $metaboxes['otherConditionsMetaBoxView'] = array(
473
+ 'key' => 'otherConditionsMetaBoxView',
474
+ 'displayName' => 'Popup Additional Conditions'.$otherConditionsProLabel,
475
+ 'filePath' => SG_POPUP_VIEWS_PATH.'otherConditionsView.php',
476
+ 'priority' => 'high'
477
+ );
478
+
479
+ $metaboxes['customCssJs'] = array(
480
+ 'key' => 'customCssJs',
481
+ 'displayName' => 'Custom JS or CSS',
482
+ 'filePath' => SG_POPUP_VIEWS_PATH.'customEditor.php',
483
+ 'priority' => 'low'
484
+ );
485
+
486
+ $metaboxes['floatingButton'] = array(
487
+ 'key' => 'floatingButton',
488
+ 'displayName' => 'Floating Button',
489
+ 'filePath' => SG_POPUP_VIEWS_PATH.'floatingButton.php',
490
+ 'context' => 'side',
491
+ 'priority' => 'high'
492
+ );
493
+
494
+ $metaboxes['popupOpeningCounter'] = array(
495
+ 'key' => 'popupOpeningCounter',
496
+ 'displayName' => 'Popup statistics',
497
+ 'filePath' => SG_POPUP_VIEWS_PATH.'popupOpeningCounter.php',
498
+ 'context' => 'side',
499
+ 'priority' => 'low'
500
+ );
501
+
502
+ return $metaboxes;
503
+ }
504
+
505
+ public function popupEvents($events)
506
+ {
507
+ foreach ($events as $eventKey => $eventData) {
508
+ if (isset($eventData['param'])) {
509
+ if ($eventData['param'] == SGPB_CSS_CLASS_ACTIONS_KEY) {
510
+ unset($events[$eventKey]);
511
+ $events[] = array('param' => 'click');
512
+ $events[] = array('param' => 'hover');
513
+ $events[] = array('param' => 'confirm');
514
+ }
515
+ else if ($eventData['param'] == SGPB_CLICK_ACTION_KEY) {
516
+ $events[$eventKey]['param'] = 'click';
517
+ }
518
+ else if ($eventData['param'] == SGPB_HOVER_ACTION_KEY) {
519
+ $events[$eventKey]['param'] = 'hover';
520
+ }
521
+ }
522
+ }
523
+
524
+ return $events;
525
+ }
526
+
527
+ public function savedPostData($postData)
528
+ {
529
+ // for old popups here we change already saved old popup id
530
+ if (isset($postData['sgpb-mailchimp-success-popup'])) {
531
+ // sgpGetCorrectPopupId it's a temporary function and it will be removed in future
532
+ if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
533
+ $postData['sgpb-mailchimp-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-mailchimp-success-popup']);
534
+ }
535
+ }
536
+ // for old popups here we change already saved old popup id
537
+ if (isset($postData['sgpb-aweber-success-popup'])) {
538
+ if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
539
+ $postData['sgpb-aweber-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-aweber-success-popup']);
540
+ }
541
+ }
542
+
543
+ return $postData;
544
+ }
545
+
546
+ public function removeAddNewSubmenu()
547
+ {
548
+ //we don't need the default add new, since we are using our custom page for it
549
+ $page = remove_submenu_page(
550
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
551
+ 'post-new.php?post_type='.SG_POPUP_POST_TYPE
552
+ );
553
+ }
554
+
555
+ public function maybeShortenEddFilename($return, $package)
556
+ {
557
+ if (strpos($package, SG_POPUP_STORE_URL) !== false) {
558
+ add_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 100, 2);
559
+ }
560
+ return $return;
561
+ }
562
+
563
+ public function shortenEddFilename($filename, $ext)
564
+ {
565
+ $filename = substr($filename, 0, 20).$ext;
566
+ remove_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 10);
567
+ return $filename;
568
+ }
569
+
570
+ public function editPopupPreviewLink($previewLink = '', $post = array())
571
+ {
572
+ if (!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) {
573
+ $popupId = $post->ID;
574
+ $targets = get_post_meta($popupId, 'sg_popup_target_preview', true);
575
+ if (empty($targets['sgpb-target'][0])) {
576
+ return $previewLink .= '/?sg_popup_preview_id='.$popupId;
577
+ }
578
+ $targetParams = @$targets['sgpb-target'][0][0]['param'];
579
+ if ((!empty($targetParams) && $targetParams == 'not_rule') || empty($targetParams)) {
580
+ $previewLink = home_url();
581
+ $previewLink .= '/?sg_popup_preview_id='.$popupId;
582
+
583
+ return $previewLink;
584
+ }
585
+ foreach ($targets['sgpb-target'][0] as $targetKey => $targetValue) {
586
+ if (!isset($targetValue['operator']) || $targetValue['operator'] == '!=') {
587
+ continue;
588
+ }
589
+ $previewLink = self::getPopupPreviewLink($targetValue, $popupId);
590
+ $previewLink .= '/?sg_popup_preview_id='.$popupId;
591
+ }
592
+ }
593
+
594
+ return $previewLink;
595
+ }
596
+
597
+ public static function getPopupPreviewLink($targetData, $popupId)
598
+ {
599
+ $previewLink = home_url();
600
+
601
+ if (empty($targetData['param'])) {
602
+ return $previewLink;
603
+ }
604
+ $targetParam = $targetData['param'];
605
+
606
+ if ($targetParam == 'everywhere') {
607
+ return $previewLink;
608
+ }
609
+
610
+ $args = array(
611
+ 'orderby' => 'rand'
612
+ );
613
+
614
+ // posts
615
+ if (strpos($targetData['param'], '_all')) {
616
+ if ($targetData['param'] == 'post_all') {
617
+ $args['post_type'] = 'post';
618
+ }
619
+ if ($targetData['param'] == 'page_all') {
620
+ $args['post_type'] = 'page';
621
+ }
622
+ }
623
+ if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
624
+ $args['post_type'] = $targetData['value'];
625
+ }
626
+ if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
627
+ $pageTypes = $targetData['value'];
628
+ foreach ($pageTypes as $pageType) {
629
+
630
+ if ($pageType == 'is_home_page') {
631
+ if (is_front_page() && is_home()) {
632
+ // default homepage
633
+ return get_home_url();
634
+ }
635
+ else if (is_front_page()) {
636
+ // static homepage
637
+ return get_home_url();
638
+ }
639
+ }
640
+ else if (function_exists($pageType)) {
641
+ if ($pageType == 'is_home') {
642
+ return get_home_url();
643
+ }
644
+ else if ($pageType == 'is_search') {
645
+ return get_search_link();
646
+ }
647
+ else if ($pageType == 'is_shop') {
648
+ return get_home_url().'/shop/';
649
+ }
650
+ }
651
+ }
652
+ }
653
+ if (isset($args['post_type'])) {
654
+ $the_query = new WP_Query($args);
655
+ foreach ($the_query->posts as $post) {
656
+ $postId = $post->ID;
657
+ if (get_permalink($postId)) {
658
+ return get_permalink($postId);
659
+ }
660
+ }
661
+ }
662
+ // selected post/page/custom_post_types...
663
+ if (strpos($targetData['param'], '_selected') && !empty($targetData['value'])) {
664
+ $value = array_keys($targetData['value']);
665
+ if (!empty($value[0])) {
666
+ if (get_permalink($value[0])) {
667
+ return get_permalink($value[0]);
668
+ }
669
+ }
670
+ }
671
+ if (strpos($targetData['param'], '_archive') && !empty($targetData['value'])) {
672
+ $value = array_keys($targetData['value']);
673
+ if (!empty($value[0])) {
674
+ if (get_permalink($value[0])) {
675
+ return get_permalink($value[0]);
676
+ }
677
+ }
678
+ }
679
+
680
+ return $previewLink;
681
+ }
682
+
683
+ public function excludePostsToShow($where)
684
+ {
685
+ if (function_exists('is_admin') && is_admin()) {
686
+ if (!function_exists('get_current_screen')) {
687
+ return $where;
688
+ }
689
+
690
+ $screen = get_current_screen();
691
+ if (empty($screen)) {
692
+ return $where;
693
+ }
694
+
695
+ $postType = $screen->post_type;
696
+ if ($postType == SG_POPUP_POST_TYPE &&
697
+ $screen instanceof \WP_Screen &&
698
+ $screen->id === 'edit-popupbuilder') {
699
+ if (class_exists('sgpb\SGPopup')) {
700
+ $activePopupsQuery = $this->getQueryString();
701
+ if ($activePopupsQuery && $activePopupsQuery != '') {
702
+ $where .= $activePopupsQuery;
703
+ }
704
+ }
705
+ }
706
+ }
707
+
708
+ return $where;
709
+ }
710
+
711
+ public function clearContentPreviewMode($content)
712
+ {
713
+ global $post_type;
714
+
715
+ if (is_preview() && $post_type == SG_POPUP_POST_TYPE) {
716
+ $content = '';
717
+ }
718
+
719
+ return $content;
720
+ }
721
+
722
+ public function filterPopupContent($content, $popupId)
723
+ {
724
+ preg_match_all('/<iframe.*?src="(.*?)".*?<\/iframe>/', $content, $matches);
725
+ /*$finalContent = '';*/
726
+ // $matches[0] array contain iframes stings
727
+ // $matches[1] array contain iframes URLs
728
+ if (empty($matches) && empty($matches[0]) && empty($matches[1])) {
729
+ return $content;
730
+ }
731
+ $urls = $matches[1];
732
+
733
+ foreach ($matches[0] as $key => $iframe) {
734
+ if (empty($urls[$key])) {
735
+ continue;
736
+ }
737
+
738
+ $pos = strpos($iframe, $urls[$key]);
739
+
740
+ if ($pos === false) {
741
+ continue;
742
+ }
743
+
744
+ $content = str_replace(' src="'.$urls[$key].'"', ' src="" data-attr-src="'.esc_attr($urls[$key]).'"', $content);
745
+ }
746
+ if (function_exists('do_blocks')) {
747
+ $content = do_blocks($content);
748
+ }
749
+
750
+ return do_shortcode($content);
751
+ }
752
+
753
+ public function addNewPostUrl($url, $path)
754
+ {
755
+ if ($path == 'post-new.php?post_type='.SG_POPUP_POST_TYPE) {
756
+ $url = str_replace('post-new.php?post_type='.SG_POPUP_POST_TYPE, 'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_POST_TYPE, $url);
757
+ }
758
+
759
+ return $url;
760
+ }
761
+
762
+ public function popupsTableColumns($columns)
763
+ {
764
+ unset($columns['date']);
765
+
766
+ $additionalItems = array();
767
+ $additionalItems['counter'] = __('Views', SG_POPUP_TEXT_DOMAIN);
768
+ $additionalItems['onOff'] = __('Enabled (show popup)', SG_POPUP_TEXT_DOMAIN);
769
+ $additionalItems['type'] = __('Type', SG_POPUP_TEXT_DOMAIN);
770
+ $additionalItems['shortcode'] = __('Shortcode', SG_POPUP_TEXT_DOMAIN);
771
+ $additionalItems['className'] = __('Class', SG_POPUP_TEXT_DOMAIN);
772
+
773
+ return $columns + $additionalItems;
774
+ }
775
+
776
+ /**
777
+ * Function to add/hide links from popups dataTable row
778
+ */
779
+ public function quickRowLinksManager($actions, $post)
780
+ {
781
+ global $post_type;
782
+
783
+ if ($post_type != SG_POPUP_POST_TYPE) {
784
+ return $actions;
785
+ }
786
+ // remove quick edit link
787
+ unset($actions['inline hide-if-no-js']);
788
+ // remove view link
789
+ unset($actions['view']);
790
+
791
+ $actions['clone'] = '<a href="'.$this->popupGetClonePostLink($post->ID , 'display', false).'" title="';
792
+ $actions['clone'] .= esc_attr__("Clone this item", SG_POPUP_TEXT_DOMAIN);
793
+ $actions['clone'] .= '">'. esc_html__('Clone', SG_POPUP_TEXT_DOMAIN).'</a>';
794
+
795
+ return $actions;
796
+ }
797
+
798
+ /**
799
+ * Retrieve duplicate post link for post.
800
+ *
801
+ * @param int $id Optional. Post ID.
802
+ * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
803
+ * @return string
804
+ */
805
+ public function popupGetClonePostLink($id = 0, $context = 'display')
806
+ {
807
+ if (!$post = get_post($id)) {
808
+ return;
809
+ }
810
+ $actionName = "popupSaveAsNew";
811
+
812
+ if ('display' == $context) {
813
+ $action = '?action='.$actionName.'&amp;post='.$post->ID;
814
+ } else {
815
+ $action = '?action='.$actionName.'&post='.$post->ID;
816
+ }
817
+
818
+ $postTypeObject = get_post_type_object($post->post_type);
819
+
820
+ if (!$postTypeObject) {
821
+ return;
822
+ }
823
+
824
+ return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
825
+ }
826
+
827
+ /* media button scripts */
828
+ public function adminJsFilter($jsFiles)
829
+ {
830
+ $allowToShow = MediaButton::allowToShow();
831
+ if ($allowToShow) {
832
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
833
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
834
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Popup.js');
835
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
836
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'MediaButton.js');
837
+
838
+ $jsFiles['localizeData'][] = array(
839
+ 'handle' => 'Popup.js',
840
+ 'name' => 'sgpbPublicUrl',
841
+ 'data' => SG_POPUP_PUBLIC_URL
842
+ );
843
+
844
+ $jsFiles['localizeData'][] = array(
845
+ 'handle' => 'MediaButton.js',
846
+ 'name' => 'mediaButtonParams',
847
+ 'data' => array(
848
+ 'currentPostType' => get_post_type(),
849
+ 'popupBuilderPostType' => SG_POPUP_POST_TYPE,
850
+ 'ajaxUrl' => admin_url('admin-ajax.php'),
851
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
852
+ )
853
+ );
854
+ }
855
+
856
+ return $jsFiles;
857
+ }
858
+
859
+ /* media button styles */
860
+ public function sgpbAdminCssFiles($cssFiles)
861
+ {
862
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
863
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
864
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
865
+
866
+ return $cssFiles;
867
+ }
868
+ }
869
+
870
+
com/classes/ScriptsLoader.php CHANGED
@@ -63,6 +63,12 @@ class ScriptsLoader
63
  global $wp;
64
  $currentUrl = home_url( $wp->request );
65
  $currentUrl = strpos($currentUrl, '/popupbuilder/');
 
 
 
 
 
 
66
  if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
67
  return false;
68
  }
@@ -128,8 +134,8 @@ class ScriptsLoader
128
  });
129
  }
130
 
131
- $this->includeScripts();
132
- $this->includeStyles();
133
  }
134
 
135
  public function loadToAdmin()
@@ -157,15 +163,14 @@ class ScriptsLoader
157
  echo $footerPopupContent;
158
  });
159
  }
160
- $this->includeScripts();
161
- $this->includeStyles();
162
 
163
  }
164
 
165
- private function includeScripts()
166
  {
167
  global $post;
168
- $popups = $this->getLoadablePopups();
169
  $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
170
 
171
  if (!$registeredPlugins) {
@@ -263,11 +268,10 @@ class ScriptsLoader
263
  }
264
  }
265
 
266
- private function includeStyles()
267
  {
268
  global $post;
269
  $styles = array();
270
- $popups = $this->getLoadablePopups();
271
  $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
272
 
273
  if (!$registeredPlugins) {
63
  global $wp;
64
  $currentUrl = home_url( $wp->request );
65
  $currentUrl = strpos($currentUrl, '/popupbuilder/');
66
+
67
+ // during preview wp request is empty that is why we check query_string
68
+ if (is_preview()) {
69
+ $currentUrl = strrpos($wp->query_string, 'popupbuilder');
70
+ }
71
+
72
  if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
73
  return false;
74
  }
134
  });
135
  }
136
 
137
+ $this->includeScripts($popups);
138
+ $this->includeStyles($popups);
139
  }
140
 
141
  public function loadToAdmin()
163
  echo $footerPopupContent;
164
  });
165
  }
166
+ $this->includeScripts($popups);
167
+ $this->includeStyles($popups);
168
 
169
  }
170
 
171
+ private function includeScripts($popups)
172
  {
173
  global $post;
 
174
  $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
175
 
176
  if (!$registeredPlugins) {
268
  }
269
  }
270
 
271
+ private function includeStyles($popups)
272
  {
273
  global $post;
274
  $styles = array();
 
275
  $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
276
 
277
  if (!$registeredPlugins) {
com/config/configPackage.php CHANGED
@@ -3,6 +3,6 @@ if (!defined('ABSPATH')) {
3
  exit();
4
  }
5
 
6
- define('SG_POPUP_VERSION', '3.83');
7
  define('SGPB_POPUP_PKG', SGPB_POPUP_PKG_FREE);
8
  define('POPUP_BUILDER_BASENAME', 'popupbuilder-platinum/popup-builder.php');
3
  exit();
4
  }
5
 
6
+ define('SG_POPUP_VERSION', '3.84');
7
  define('SGPB_POPUP_PKG', SGPB_POPUP_PKG_FREE);
8
  define('POPUP_BUILDER_BASENAME', 'popupbuilder-platinum/popup-builder.php');
popup-builder.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Popup Builder
4
  * Plugin URI: https://popup-builder.com
5
  * Description: The most complete popup plugin. Html, image, iframe, shortcode, video and many other popup types. Manage popup dimensions, effects, themes and more.
6
- * Version: 3.83
7
  * Author: Sygnoos
8
  * Author URI: https://sygnoos.com
9
  * License: GPLv2
3
  * Plugin Name: Popup Builder
4
  * Plugin URI: https://popup-builder.com
5
  * Description: The most complete popup plugin. Html, image, iframe, shortcode, video and many other popup types. Manage popup dimensions, effects, themes and more.
6
+ * Version: 3.84
7
  * Author: Sygnoos
8
  * Author URI: https://sygnoos.com
9
  * License: GPLv2
readme.txt CHANGED
@@ -8,7 +8,7 @@ Tags: popup, pop up, wordpress popup, popup maker, exit popup, popup builder, wo
8
  Requires at least: 4.2
9
  Tested up to: 5.7
10
  Requires PHP: 5.3.3
11
- Stable tag: 3.83
12
  License: GPLv2 or later
13
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
14
 
@@ -143,11 +143,15 @@ Go to the Popup Builder settings and set your desired options.
143
  12. Countdown popup
144
  13. Facebook popup
145
 
146
- == Changelog ==
 
 
 
 
147
 
148
  = Version 3.83 =
149
- * Improvement of Floating button relater to the filter
150
- * Bug fixed related to the warning in WP_Scripts->localize(), 3rd parameter's string is changed to array
151
 
152
  = Version 3.82 =
153
  * Bug fixed related to PHP Fatal error.
@@ -448,4 +452,4 @@ Leave us a good review :)
448
 
449
  == Upgrade Notice ==
450
 
451
- Current Version of Popup Builder is 3.83
8
  Requires at least: 4.2
9
  Tested up to: 5.7
10
  Requires PHP: 5.3.3
11
+ Stable tag: 3.84
12
  License: GPLv2 or later
13
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
14
 
143
  12. Countdown popup
144
  13. Facebook popup
145
 
146
+ == Changelog ==
147
+
148
+ = Version 3.84 =
149
+ * Bug fixed related to popup types and settings that are not saved after popup is saved as draft.
150
+ * Bug fixed related to randomly activated popups.
151
 
152
  = Version 3.83 =
153
+ * Improvement of Floating button relater to the filter.
154
+ * Bug fixed related to the warning in WP_Scripts->localize(), 3rd parameter's string is changed to array.
155
 
156
  = Version 3.82 =
157
  * Bug fixed related to PHP Fatal error.
452
 
453
  == Upgrade Notice ==
454
 
455
+ Current Version of Popup Builder is 3.84