Popup Builder – Responsive WordPress Pop up - Version 4.0.4

Version Description

Download this release

Release Info

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

Code changes from version 4.0.3 to 4.0.4

Files changed (42) hide show
  1. PopupBuilderInit.php +118 -118
  2. com/boot.php +11 -11
  3. com/classes/Actions.php +1477 -1477
  4. com/classes/Ajax.php +721 -721
  5. com/classes/ConditionBuilder.php +246 -246
  6. com/classes/ConditionCreator.php +668 -668
  7. com/classes/ConvertToNewVersion.php +1274 -1274
  8. com/classes/Feedback.php +146 -146
  9. com/classes/Filters.php +873 -873
  10. com/classes/Installer.php +331 -331
  11. com/classes/Javascript.php +133 -133
  12. com/classes/MediaButton.php +114 -114
  13. com/classes/Notification.php +94 -94
  14. com/classes/NotificationCenter.php +292 -292
  15. com/classes/PopupChecker.php +673 -673
  16. com/classes/PopupGroupFilter.php +193 -193
  17. com/classes/PopupInstaller.php +5 -5
  18. com/classes/PopupLoader.php +181 -181
  19. com/classes/PopupType.php +36 -36
  20. com/classes/RegisterPostType.php +478 -478
  21. com/classes/SGPBRequirementsChecker.php +16 -16
  22. com/classes/ScriptsLoader.php +406 -406
  23. com/classes/Style.php +120 -120
  24. com/classes/Updates.php +203 -203
  25. com/classes/_detection/SgpbPopupVersionDetection.php +136 -136
  26. com/classes/components/Menu.php +232 -232
  27. com/classes/dataTable/Subscribers.php +206 -206
  28. com/classes/extension/SgpbIPopupExtension.php +9 -9
  29. com/classes/extension/SgpbPopupExtension.php +358 -358
  30. com/classes/extension/SgpbPopupExtensionActivator.php +108 -108
  31. com/classes/extension/SgpbPopupExtensionRegister.php +120 -120
  32. com/classes/popups/FblikePopup.php +114 -114
  33. com/classes/popups/HtmlPopup.php +38 -38
  34. com/classes/popups/ImagePopup.php +90 -90
  35. com/classes/popups/PopupData.php +20 -20
  36. com/classes/popups/SGPopup.php +1749 -1749
  37. com/classes/popups/SubscriptionPopup.php +688 -688
  38. com/config/config.php +176 -176
  39. com/config/configPackage.php +8 -8
  40. com/config/dataConfig.php +1033 -1033
  41. com/helpers/AdminHelper.php +2126 -2126
  42. com/helpers/ConfigDataHelper.php +0 -591
PopupBuilderInit.php CHANGED
@@ -1,118 +1,118 @@
1
- <?php
2
- namespace sgpb;
3
- use \SgpbPopupExtensionRegister;
4
- use sgpb\AdminHelper;
5
-
6
- class PopupBuilderInit
7
- {
8
- private static $instance = null;
9
- private $actions;
10
- private $filters;
11
-
12
- private function __construct()
13
- {
14
- $this->init();
15
- }
16
-
17
- private function __clone()
18
- {
19
-
20
- }
21
-
22
- public static function getInstance()
23
- {
24
- if(!isset(self::$instance)) {
25
- self::$instance = new self();
26
- }
27
- return self::$instance;
28
- }
29
-
30
- public function init()
31
- {
32
- /*Included required data*/
33
- $this->includeData();
34
- $this->registerHooks();
35
- $this->actions();
36
- $this->filters();
37
- $this->versionDetection();
38
- }
39
-
40
- private function includeData()
41
- {
42
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
43
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionActivator.php');
44
- require_once(SG_POPUP_CLASSES_PATH.'Installer.php');
45
- require_once(SG_POPUP_HELPERS_PATH.'AdminHelper.php');
46
- require_once(SG_POPUP_HELPERS_PATH.'Functions.php');
47
- require_once(SG_POPUP_HELPERS_PATH.'ScriptsIncluder.php');
48
- require_once(SG_POPUP_HELPERS_PATH.'PopupBuilderActivePackage.php');
49
- require_once(SG_POPUP_HELPERS_PATH.'License.php');
50
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php');
51
- require_once(SG_POPUP_HELPERS_PATH.'MultipleChoiceButton.php');
52
- require_once(SG_POPUP_CLASSES_PATH.'ConditionBuilder.php');
53
- require_once(SG_POPUP_CLASSES_PATH.'ConditionCreator.php');
54
- require_once(SG_POPUP_CLASSES_POPUPS_PATH.'SGPopup.php');
55
- require_once(SG_POPUP_CLASSES_PATH.'ScriptsLoader.php');
56
- require_once(SG_POPUP_CLASSES_PATH.'PopupGroupFilter.php');
57
- require_once(SG_POPUP_CLASSES_PATH.'PopupChecker.php');
58
- require_once(SG_POPUP_CLASSES_PATH.'PopupLoader.php');
59
- require_once(SG_POPUP_CLASSES_PATH.'PopupType.php');
60
- require_once(SG_POPUP_CLASSES_PATH.'MediaButton.php');
61
- require_once(SG_POPUP_CLASSES_PATH.'Style.php');
62
- require_once(SG_POPUP_CLASSES_PATH.'Javascript.php');
63
- require_once(SG_POPUP_CLASSES_PATH.'PopupInstaller.php');
64
- require_once(SG_POPUP_CLASSES_PATH.'RegisterPostType.php');
65
- require_once(SG_POPUP_CLASSES_PATH.'Ajax.php');
66
- require_once(SG_POPUP_CLASSES_PATH.'ConvertToNewVersion.php');
67
- require_once(SG_POPUP_LIBS_PATH.'Reports.php');
68
- require_once(SG_POPUP_CLASSES_PATH.'Filters.php');
69
- require_once(SG_POPUP_CLASSES_PATH.'Actions.php');
70
- require_once(SG_POPUP_LIBS_PATH.'Table.php');
71
- require_once(SG_POPUP_CLASSES_PATH.'Updates.php');
72
- require_once(SG_POPUP_CLASSES_PATH.'NotificationCenter.php');
73
- require_once(SG_POPUP_CLASSES_PATH.'Notification.php');
74
- require_once(SG_POPUP_CLASSES_PATH.'Feedback.php');
75
- require_once(SG_POPUP_COMPONENTS_PATH.'Menu.php');
76
- require_once(SGPB_POPUP_DETECTION_PATH.'SgpbPopupVersionDetection.php');
77
- }
78
-
79
- public function actions()
80
- {
81
- $this->actions = new Actions();
82
- }
83
-
84
- public function filters()
85
- {
86
- $this->filters = new Filters();
87
- }
88
- public function versionDetection()
89
- {
90
- new SgpbPopupVersionDetection();
91
- }
92
-
93
- private function registerHooks()
94
- {
95
- register_activation_hook(SG_POPUP_FILE_NAME, array($this, 'activate'));
96
- register_deactivation_hook(SG_POPUP_FILE_NAME, array($this, 'deactivate'));
97
- }
98
-
99
- public function activate()
100
- {
101
- Installer::install();
102
- Installer::registerPlugin();
103
- AdminHelper::filterUserCapabilitiesForTheUserRoles('activate');
104
- }
105
-
106
- public function deactivate()
107
- {
108
- Functions::clearAllTransients();
109
- AdminHelper::removeSelectedTypeOptions('cron');
110
- AdminHelper::filterUserCapabilitiesForTheUserRoles('deactivate');
111
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
112
- $pluginName = SG_POPUP_FILE_NAME;
113
- // remove AWeber extension from registered extensions
114
- SgpbPopupExtensionRegister::remove($pluginName);
115
- }
116
- }
117
-
118
- PopupBuilderInit::getInstance();
1
+ <?php
2
+ namespace sgpb;
3
+ use \SgpbPopupExtensionRegister;
4
+ use sgpb\AdminHelper;
5
+
6
+ class PopupBuilderInit
7
+ {
8
+ private static $instance = null;
9
+ private $actions;
10
+ private $filters;
11
+
12
+ private function __construct()
13
+ {
14
+ $this->init();
15
+ }
16
+
17
+ private function __clone()
18
+ {
19
+
20
+ }
21
+
22
+ public static function getInstance()
23
+ {
24
+ if(!isset(self::$instance)) {
25
+ self::$instance = new self();
26
+ }
27
+ return self::$instance;
28
+ }
29
+
30
+ public function init()
31
+ {
32
+ /*Included required data*/
33
+ $this->includeData();
34
+ $this->registerHooks();
35
+ $this->actions();
36
+ $this->filters();
37
+ $this->versionDetection();
38
+ }
39
+
40
+ private function includeData()
41
+ {
42
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
43
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionActivator.php');
44
+ require_once(SG_POPUP_CLASSES_PATH.'Installer.php');
45
+ require_once(SG_POPUP_HELPERS_PATH.'AdminHelper.php');
46
+ require_once(SG_POPUP_HELPERS_PATH.'Functions.php');
47
+ require_once(SG_POPUP_HELPERS_PATH.'ScriptsIncluder.php');
48
+ require_once(SG_POPUP_HELPERS_PATH.'PopupBuilderActivePackage.php');
49
+ require_once(SG_POPUP_HELPERS_PATH.'License.php');
50
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php');
51
+ require_once(SG_POPUP_HELPERS_PATH.'MultipleChoiceButton.php');
52
+ require_once(SG_POPUP_CLASSES_PATH.'ConditionBuilder.php');
53
+ require_once(SG_POPUP_CLASSES_PATH.'ConditionCreator.php');
54
+ require_once(SG_POPUP_CLASSES_POPUPS_PATH.'SGPopup.php');
55
+ require_once(SG_POPUP_CLASSES_PATH.'ScriptsLoader.php');
56
+ require_once(SG_POPUP_CLASSES_PATH.'PopupGroupFilter.php');
57
+ require_once(SG_POPUP_CLASSES_PATH.'PopupChecker.php');
58
+ require_once(SG_POPUP_CLASSES_PATH.'PopupLoader.php');
59
+ require_once(SG_POPUP_CLASSES_PATH.'PopupType.php');
60
+ require_once(SG_POPUP_CLASSES_PATH.'MediaButton.php');
61
+ require_once(SG_POPUP_CLASSES_PATH.'Style.php');
62
+ require_once(SG_POPUP_CLASSES_PATH.'Javascript.php');
63
+ require_once(SG_POPUP_CLASSES_PATH.'PopupInstaller.php');
64
+ require_once(SG_POPUP_CLASSES_PATH.'RegisterPostType.php');
65
+ require_once(SG_POPUP_CLASSES_PATH.'Ajax.php');
66
+ require_once(SG_POPUP_CLASSES_PATH.'ConvertToNewVersion.php');
67
+ require_once(SG_POPUP_LIBS_PATH.'Reports.php');
68
+ require_once(SG_POPUP_CLASSES_PATH.'Filters.php');
69
+ require_once(SG_POPUP_CLASSES_PATH.'Actions.php');
70
+ require_once(SG_POPUP_LIBS_PATH.'Table.php');
71
+ require_once(SG_POPUP_CLASSES_PATH.'Updates.php');
72
+ require_once(SG_POPUP_CLASSES_PATH.'NotificationCenter.php');
73
+ require_once(SG_POPUP_CLASSES_PATH.'Notification.php');
74
+ require_once(SG_POPUP_CLASSES_PATH.'Feedback.php');
75
+ require_once(SG_POPUP_COMPONENTS_PATH.'Menu.php');
76
+ require_once(SGPB_POPUP_DETECTION_PATH.'SgpbPopupVersionDetection.php');
77
+ }
78
+
79
+ public function actions()
80
+ {
81
+ $this->actions = new Actions();
82
+ }
83
+
84
+ public function filters()
85
+ {
86
+ $this->filters = new Filters();
87
+ }
88
+ public function versionDetection()
89
+ {
90
+ new SgpbPopupVersionDetection();
91
+ }
92
+
93
+ private function registerHooks()
94
+ {
95
+ register_activation_hook(SG_POPUP_FILE_NAME, array($this, 'activate'));
96
+ register_deactivation_hook(SG_POPUP_FILE_NAME, array($this, 'deactivate'));
97
+ }
98
+
99
+ public function activate()
100
+ {
101
+ Installer::install();
102
+ Installer::registerPlugin();
103
+ AdminHelper::filterUserCapabilitiesForTheUserRoles('activate');
104
+ }
105
+
106
+ public function deactivate()
107
+ {
108
+ Functions::clearAllTransients();
109
+ AdminHelper::removeSelectedTypeOptions('cron');
110
+ AdminHelper::filterUserCapabilitiesForTheUserRoles('deactivate');
111
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
112
+ $pluginName = SG_POPUP_FILE_NAME;
113
+ // remove AWeber extension from registered extensions
114
+ SgpbPopupExtensionRegister::remove($pluginName);
115
+ }
116
+ }
117
+
118
+ PopupBuilderInit::getInstance();
com/boot.php CHANGED
@@ -1,11 +1,11 @@
1
- <?php
2
- require_once(dirname(__FILE__).'/config/config.php');
3
- require_once(dirname(__FILE__).'/config/configPackage.php');
4
-
5
- if (file_exists(SG_POPUP_CONFIG_PATH.'dataConfig.php')) {
6
- require_once(SG_POPUP_CONFIG_PATH.'dataConfig.php');
7
- }
8
-
9
- require_once(SG_POPUP_CLASSES_PATH.'SGPBRequirementsChecker.php');
10
-
11
- SGPBRequirementsChecker::init();
1
+ <?php
2
+ require_once(dirname(__FILE__).'/config/config.php');
3
+ require_once(dirname(__FILE__).'/config/configPackage.php');
4
+
5
+ if (file_exists(SG_POPUP_CONFIG_PATH.'dataConfig.php')) {
6
+ require_once(SG_POPUP_CONFIG_PATH.'dataConfig.php');
7
+ }
8
+
9
+ require_once(SG_POPUP_CLASSES_PATH.'SGPBRequirementsChecker.php');
10
+
11
+ SGPBRequirementsChecker::init();
com/classes/Actions.php CHANGED
@@ -1,1477 +1,1477 @@
1
- <?php
2
- namespace sgpb;
3
- use \WP_Query;
4
- use \SgpbPopupConfig;
5
- use \SgpbDataConfig;
6
-
7
- class Actions
8
- {
9
- public $customPostTypeObj;
10
- public $mediaButton = false;
11
-
12
- public function __construct()
13
- {
14
- $this->init();
15
- }
16
-
17
- public function init()
18
- {
19
- add_action('init', array($this, 'wpInit'), 9999999999);
20
- add_action('init', array($this, 'postTypeInit'), 9999);
21
- add_action('init', array($this, 'updatesInit'), 9999);
22
- add_action('admin_menu', array($this, 'addSubMenu'));
23
- add_action('admin_menu', array($this, 'supportLinks'), 999);
24
- add_action('admin_head', array($this, 'showPreviewButtonAfterPopupPublish'));
25
- add_action('admin_head', array($this, 'custom_admin_js'));
26
- add_action('admin_enqueue_scripts', array($this, 'adminLoadPopups'));
27
- add_action('admin_action_popupSaveAsNew', array($this, 'popupSaveAsNew'));
28
- add_action('admin_post_csv_file', array($this, 'getSubscribersCsvFile'));
29
- add_action('admin_post_sgpb_system_info', array($this, 'getSystemInfoFile'));
30
- add_action('admin_post_sgpbSaveSettings', array($this, 'saveSettings'), 10, 1);
31
- add_action('admin_init', array($this, 'userRolesCaps'));
32
- add_action('admin_notices', array($this, 'pluginNotices'));
33
- add_action('admin_init', array($this, 'pluginLoaded'));
34
- add_action('transition_post_status', array($this, 'deletePopup'), 100, 3);
35
- // activate extensions
36
- add_action('wp_before_admin_bar_render', array($this, 'pluginActivated'), 10, 2);
37
- add_action('admin_head', array($this, 'hidePageBuilderEditButtons'));
38
- add_action('admin_head', array($this, 'hidePublishingActions'));
39
- add_action('add_meta_boxes', array($this, 'popupMetaboxes'), 100);
40
- add_filter('post_updated_messages', array($this, 'popupPublishedMessage'), 1, 1);
41
- add_action('before_delete_post', array($this, 'deleteSubscribersWithPopup'), 1, 1);
42
- add_action('sgpb_duplicate_post', array($this, 'popupCopyPostMetaInfo'), 10, 2);
43
- add_filter('get_sample_permalink_html', array($this, 'removePostPermalink'), 1, 1);
44
- add_action('manage_'.SG_POPUP_POST_TYPE.'_posts_custom_column' , array($this, 'popupsTableColumnsValues'), 10, 2);
45
- add_action('media_buttons', array($this, 'popupMediaButton'));
46
- add_filter('mce_external_plugins', array($this, 'editorButton'), 1, 1);
47
- add_action('admin_enqueue_scripts', array('sgpb\Style', 'enqueueStyles'));
48
- add_action('admin_enqueue_scripts', array('sgpb\Javascript', 'enqueueScripts'));
49
- // this action for popup options saving and popup builder classes save ex from post and page
50
- add_action('save_post', array($this, 'savePost'), 100, 3);
51
- add_action('wp_enqueue_scripts', array($this, 'enqueuePopupBuilderScripts'));
52
- add_filter('sgpbOtherConditions', array($this ,'conditionsSatisfy'), 11, 1);
53
- add_shortcode('sg_popup', array($this, 'popupShortcode'));
54
- add_filter('cron_schedules', array($this, 'cronAddMinutes'), 10, 1);
55
- add_action('sgpb_send_newsletter', array($this, 'newsletterSendEmail'), 10, 1);
56
- add_action('sgpbGetBannerContentOnce', array($this, 'getBannerContent'), 10, 1);
57
- add_action('plugins_loaded', array($this, 'loadTextDomain'));
58
- // for change admin popup list order
59
- add_action('pre_get_posts', array($this, 'preGetPosts'));
60
- add_action('template_redirect', array($this, 'redirectFromPopupPage'));
61
- add_filter('views_edit-popupbuilder', array($this, 'mainActionButtons'), 10, 1);
62
- add_action('wpml_loaded', array($this, 'wpmlRelatedActions'));
63
-
64
- add_filter('get_user_option_screen_layout_'.SG_POPUP_POST_TYPE, array($this, 'screenLayoutSetOneColumn'));
65
- new SGPBFeedback();
66
- new SGPBReports();
67
- new SGPBMenu();
68
- new Ajax();
69
- }
70
-
71
- private function checkIfLicenseIsActive($license, $itemId, $storeURL, $key) {
72
- $transient = 'sgpb-license-key-'.$key.'-requested';
73
- if ( false !== ( $value = get_transient( $transient ) ) ) {
74
- return;
75
- }
76
- $apiParams = array(
77
- 'edd_action' => 'activate_license',
78
- 'license' => $license,
79
- 'item_id' => $itemId, // The ID of the item in EDD
80
- 'url' => home_url()
81
- );
82
- $response = wp_remote_post($storeURL, array('timeout' => 15, 'sslverify' => false, 'body' => $apiParams));
83
- if (!is_wp_error($response) || 200 == wp_remote_retrieve_response_code($response)) {
84
- $licenseData = json_decode(wp_remote_retrieve_body($response));
85
- update_option('sgpb-license-status-'.$key, $licenseData->license);
86
- set_transient($transient, $licenseData->item_name, WEEK_IN_SECONDS);
87
- }
88
-
89
- }
90
- public function updatesInit()
91
- {
92
- if (!class_exists('sgpb\EDD_SL_Plugin_Updater')) {
93
- // load our custom updater if it doesn't already exist
94
- require_once(SG_POPUP_LIBS_PATH .'EDD_SL_Plugin_Updater.php');
95
- }
96
- $licenses = (new License())->getLicenses();
97
- foreach ($licenses as $license) {
98
- $key = @$license['key'];
99
- $storeURL = @$license['storeURL'];
100
- $itemId = @$license['itemId'];
101
- $filePath = @$license['file'];
102
- $pluginMainFilePath = strpos($filePath, SG_POPUP_PLUGIN_PATH) !== 0 ? SG_POPUP_PLUGIN_PATH.$filePath : $filePath;
103
-
104
- $licenseKey = trim(get_option('sgpb-license-key-'.$key));
105
- $status = get_option('sgpb-license-status-'.$key);
106
-
107
- if ($status == false || $status != 'valid') {
108
- continue;
109
- }
110
- $this->checkIfLicenseIsActive($licenseKey, $itemId, $storeURL, $key);
111
- switch($key) {
112
- case 'POPUP_SOCIAL':
113
- if (defined('SGPB_SOCIAL_POPUP_VERSION')) {
114
- $version = @constant('SGPB_SOCIAL_POPUP_VERSION');
115
- } else {
116
- $version = @constant('SG_VERSION_'.$key);
117
- }
118
- break;
119
- case 'POPUP_AGE_VERIFICATION':
120
- if (defined('SGPB_AGE_VERIFICATION_POPUP_VERSION')) {
121
- $version = @constant('SGPB_AGE_VERIFICATION_POPUP_VERSION');
122
- } else{
123
- $version = @constant('SG_VERSION_'.$key);
124
- }
125
- break;
126
- case 'POPUP_GAMIFICATION':
127
- if (defined('POPUP_GAMIFICATION')) {
128
- $version = @constant('POPUP_GAMIFICATION');
129
- } else {
130
- $version = @constant('SG_VERSION_'.$key);
131
- }
132
- break;
133
- default :
134
- $version = @constant('SG_VERSION_'.$key);
135
- break;
136
- }
137
- // If the version of the extension is not found, update will not possibly be shown
138
- if(empty($version)) {
139
- continue;
140
- }
141
- $sgpbUpdater = new EDD_SL_Plugin_Updater($storeURL, $pluginMainFilePath, array(
142
- 'version' => $version, // current version number
143
- 'license' => $licenseKey, // license key (used get_option above to retrieve from DB)
144
- 'item_id' => $license['itemId'], // id of this plugin
145
- 'author' => $license['autor'], // author of this plugin
146
- 'beta' => false // set to true if you wish customers to receive update notifications of beta releases
147
- ));
148
- }
149
- }
150
- public function custom_admin_js()
151
- {
152
- $currentPostType = AdminHelper::getCurrentPostType();
153
- if (!empty($currentPostType) && ($currentPostType == SG_POPUP_POST_TYPE || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE || $currentPostType == SG_POPUP_TEMPLATE_POST_TYPE)) {
154
- ?>
155
- <script type="text/javascript">
156
- jQuery(document).ready(function($) {
157
- const myForm = $('#posts-filter');
158
- myForm.addClass('sgpb-table');
159
- const searchValue = $('#post-search-input').val();
160
- $('#posts-filter .tablenav.top .tablenav-pages').append($('.subsubsub').addClass('show'));
161
- myForm.append($('#posts-filter .tablenav.bottom .tablenav-pages:not(.no-pages, .one-page) .pagination-links'));
162
- $('#sgpbSearchInPosts').val(searchValue);
163
- $('#sgpbSearchInPosts').keyup('enter', function (e) {
164
- if (e.key === 'Enter') {
165
- $('#post-search-input').val(this.value);
166
- $(myForm).submit();
167
- }
168
- });
169
- $('#sgpbSearchInPostsSubmit').on('click', function () {
170
- $('#post-search-input').val($('#sgpbSearchInPosts').val());
171
- $(myForm).submit();
172
- })
173
- });
174
- </script>
175
- <?php
176
- }
177
- }
178
-
179
- public function screenLayoutSetOneColumn()
180
- {
181
- return 1;
182
- }
183
-
184
- public function wpmlRelatedActions()
185
- {
186
- // The actions below will be executed right after WPML is fully configured and loaded.
187
- add_action('admin_head', array($this, 'removeUnneededMetaboxesFromPopups'), 10);
188
- }
189
-
190
- public function removeUnneededMetaboxesFromPopups()
191
- {
192
- if (isset($_GET['post_type']) && $_GET['post_type'] == SG_POPUP_POST_TYPE) {
193
- $exlcudeTrPopupTypes = array(
194
- 'image',
195
- 'video',
196
- 'iframe',
197
- 'recentSales',
198
- 'pdf'
199
- );
200
- $exlcudeTrPopupTypes = apply_filters('sgpbNoMcePopupTypes', $exlcudeTrPopupTypes);
201
- if (isset($_GET['sgpb_type']) && in_array($_GET['sgpb_type'], $exlcudeTrPopupTypes)) {
202
- remove_meta_box('icl_div', SG_POPUP_POST_TYPE, 'side');
203
- }
204
- }
205
- }
206
-
207
- public function deletePopup($newStatus, $oldStatus, $post)
208
- {
209
- $currentPostType = AdminHelper::getCurrentPostType();
210
-
211
- if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
212
- Functions::clearAllTransients();
213
- }
214
- }
215
-
216
- public function showPreviewButtonAfterPopupPublish()
217
- {
218
- $currentPostType = AdminHelper::getCurrentPostType();
219
- if (!empty($currentPostType) && ($currentPostType == SG_POPUP_POST_TYPE || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE || $currentPostType == SG_POPUP_TEMPLATE_POST_TYPE)) {
220
- echo '<style>
221
- #save-post {
222
- display:none !important;
223
- }
224
- .subsubsub {
225
- display:none !important;
226
- }
227
- .subsubsub.show {
228
- display:block !important;
229
- }
230
- .search-box {
231
- display:none !important;
232
- }
233
- .search-box.show {
234
- display:block !important;
235
- }
236
- .tablenav-pages.no-pages {
237
- display: block;
238
- }
239
- .tablenav-pages *:not(.subsubsub, .subsubsub *),
240
- .tablenav-pages.no-pages *:not(.subsubsub, .subsubsub *),
241
- .tablenav-pages.one-page *:not(.subsubsub, .subsubsub *) {
242
- display: none;
243
- }
244
- </style>';
245
- }
246
- }
247
-
248
- public function inactiveExtensionNotice()
249
- {
250
- $screen = '';
251
- $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
252
- if ($dontShowLicenseBanner) {
253
- return $screen;
254
- }
255
- $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
256
- $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
257
- if (!$inactive) {
258
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
259
- if ($hasInactiveExtensions) {
260
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
261
- $inactive = 'inactive';
262
- }
263
-
264
- }
265
- $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
266
- $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
267
- if (function_exists('get_current_screen')) {
268
- $screen = get_current_screen();
269
- $screenId = $screen->id;
270
- if ($screenId == SGPB_POPUP_LICENSE_SCREEN) {
271
- $partOfContent = '';
272
- }
273
- }
274
-
275
- if ($hasInactiveExtensions && $inactive == 'inactive') {
276
- $content = '';
277
- ob_start();
278
- ?>
279
- <div id="welcome-panel" class="update-nag sgpb-extensions-notices sgpb-license-notice">
280
- <div class="welcome-panel-content">
281
- <b><?php _e('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN) ?></b>
282
- <br>
283
- <br>
284
- <b><?php _e('You have activated Popup Builder extension(s). Please, don\'t forget to activate the license key(s) as well.', SG_POPUP_TEXT_DOMAIN) ?></b>
285
- <b><?php echo $partOfContent; ?></b>
286
- </div>
287
- <button type="button" class="notice-dismiss" onclick="jQuery('.sgpb-license-notice').remove();"><span class="screen-reader-text"><?php _e('Dismiss this notice.', SG_POPUP_TEXT_DOMAIN) ?></span></button>
288
- <span class="sgpb-dont-show-again-license-notice"><?php _e('Don\'t show again.', SG_POPUP_TEXT_DOMAIN); ?></span>
289
- </div>
290
- <?php
291
- $content = ob_get_clean();
292
-
293
- echo $content;
294
- return true;
295
- }
296
- }
297
-
298
- public function hidePublishingActions() {
299
- $currentPostType = AdminHelper::getCurrentPostType();
300
- if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
301
- return false;
302
- }
303
-
304
- echo '<style>
305
- #misc-publishing-actions .edit-post-status,
306
- #misc-publishing-actions .edit-timestamp,
307
- #misc-publishing-actions .edit-visibility {
308
- display:none !important;
309
- }
310
- </style>';
311
- }
312
-
313
- public function hidePageBuilderEditButtons($postId = 0, $post = array())
314
- {
315
- $currentPostType = AdminHelper::getCurrentPostType();
316
- if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
317
- return false;
318
- }
319
- $excludedPopupTypesFromPageBuildersFunctionality = array(
320
- 'image'
321
- );
322
-
323
- $excludedPopupTypesFromPageBuildersFunctionality = apply_filters('sgpbHidePageBuilderEditButtons', $excludedPopupTypesFromPageBuildersFunctionality);
324
-
325
- $popupType = AdminHelper::getCurrentPopupType();
326
- if (in_array($popupType, $excludedPopupTypesFromPageBuildersFunctionality)) {
327
- echo '<style>
328
- #elementor-switch-mode, #elementor-editor {
329
- display:none !important;
330
- }
331
- </style>';
332
- }
333
- }
334
-
335
- public function getBannerContent()
336
- {
337
- // right metabox banner content
338
- $metaboxBannerContent = AdminHelper::getFileFromURL(SGPB_METABOX_BANNER_CRON_TEXT_URL);
339
- update_option('sgpb-metabox-banner-remote-get', $metaboxBannerContent);
340
-
341
- return true;
342
- }
343
-
344
- public function wpInit()
345
- {
346
-
347
- }
348
-
349
- public function mainActionButtons($views)
350
- {
351
- require_once(SG_POPUP_VIEWS_PATH.'mainActionButtons.php');
352
-
353
- return $views;
354
- }
355
-
356
- /**
357
- * Loads the plugin language files
358
- */
359
- public function loadTextDomain()
360
- {
361
- $popupBuilderLangDir = SG_POPUP_BUILDER_PATH.'/languages/';
362
- $popupBuilderLangDir = apply_filters('popupBuilderLanguagesDirectory', $popupBuilderLangDir);
363
-
364
- $locale = apply_filters('sgpbPluginLocale', get_locale(), SG_POPUP_TEXT_DOMAIN);
365
- $mofile = sprintf('%1$s-%2$s.mo', SG_POPUP_TEXT_DOMAIN, $locale);
366
-
367
- $mofileLocal = $popupBuilderLangDir.$mofile;
368
-
369
- if (file_exists($mofileLocal)) {
370
- // Look in local /wp-content/plugins/popup-builder/languages/ folder
371
- load_textdomain(SG_POPUP_TEXT_DOMAIN, $mofileLocal);
372
- }
373
- else {
374
- // Load the default language files
375
- load_plugin_textdomain(SG_POPUP_TEXT_DOMAIN, false, $popupBuilderLangDir);
376
- }
377
-
378
- }
379
-
380
- public function redirectFromPopupPage()
381
- {
382
- global $post;
383
- $currentPostType = '';
384
-
385
- if (is_object($post)) {
386
- $currentPostType = @$post->post_type;
387
- }
388
- // in some themes global $post returns null
389
- if (empty($currentPostType)) {
390
- global $post_type;
391
- $currentPostType = $post_type;
392
- }
393
- // for editing popup content via page builders on backend
394
- if (!isset($_GET) || empty($_GET)) {
395
- if (!is_admin() && SG_POPUP_POST_TYPE == $currentPostType && !is_preview()) {
396
- // it's for seo optimization
397
- status_header(301);
398
- $homeURL = home_url();
399
- wp_redirect($homeURL);
400
- exit();
401
- }
402
- }
403
- }
404
-
405
- public function preGetPosts($query)
406
- {
407
- if (!is_admin() || !isset($_GET['post_type']) || $_GET['post_type'] != SG_POPUP_POST_TYPE) {
408
- return false;
409
- }
410
-
411
- // change default order by id and desc
412
- if (!isset($_GET['orderby'])) {
413
- $query->set('orderby', 'ID');
414
- $query->set('order', 'desc');
415
- }
416
- $query = apply_filters('sgpbPreGetPosts', $query);
417
-
418
- return true;
419
- }
420
-
421
- public function pluginNotices()
422
- {
423
- if (function_exists('get_current_screen')) {
424
- $screen = get_current_screen();
425
- $screenId = $screen->id;
426
- if ($screenId == 'edit-popupbuilder') {
427
- $notificationsObj = new SGPBNotificationCenter();
428
- echo $notificationsObj->displayNotifications();
429
- }
430
- }
431
- $extensions = AdminHelper::getAllActiveExtensions();
432
- $updated = get_option('sgpb_extensions_updated');
433
-
434
- $content = '';
435
-
436
- // if popup builder has the old version
437
- if (!get_option('SG_POPUP_VERSION')) {
438
- return $content;
439
- }
440
-
441
- $alertProblem = get_option('sgpb_alert_problems');
442
- // for old users show alert about problems
443
- if (!$alertProblem) {
444
- echo AdminHelper::renderAlertProblem();
445
- }
446
-
447
- // Don't show the banner if there's not any extension of Popup Builder or if the user has clicked "don't show"
448
- if (empty($extensions) || $updated) {
449
- return $content;
450
- }
451
-
452
- ob_start();
453
- ?>
454
- <div id="welcome-panel" class="update-nag sgpb-extensions-notices">
455
- <div class="welcome-panel-content">
456
- <?php echo AdminHelper::renderExtensionsContent(); ?>
457
- </div>
458
- </div>
459
- <?php
460
- $content = ob_get_clean();
461
-
462
- echo $content;
463
- return true;
464
- }
465
-
466
- private function registerImporter()
467
- {
468
- require_once SG_POPUP_LIBS_PATH.'Importer.php';
469
- $importer = new WP_Import();
470
- register_importer(SG_POPUP_POST_TYPE, SG_POPUP_POST_TYPE, __('Importer', SG_POPUP_TEXT_DOMAIN), array($importer, 'dispatch'));
471
- }
472
-
473
- public function pluginLoaded()
474
- {
475
- $this->registerImporter();
476
- $versionPopup = get_option('SG_POPUP_VERSION');
477
- $convert = get_option('sgpbConvertToNewVersion');
478
- $unsubscribeColumnFixed = get_option('sgpbUnsubscribeColumnFixed');
479
- AdminHelper::makeRegisteredPluginsStaticPathsToDynamic();
480
-
481
- if (!$unsubscribeColumnFixed) {
482
- AdminHelper::addUnsubscribeColumn();
483
- update_option('sgpbUnsubscribeColumnFixed', 1);
484
- delete_option('sgpbUnsubscribeColumn');
485
- }
486
-
487
- if ($versionPopup && !$convert) {
488
- update_option('sgpbConvertToNewVersion', 1);
489
- ConvertToNewVersion::convert();
490
- Installer::registerPlugin();
491
- }
492
- }
493
-
494
- public function popupMediaButton()
495
- {
496
- if (!$this->mediaButton) {
497
- $this->mediaButton = true;
498
- self::enqueueScriptsForPageBuilders();
499
- if (function_exists('get_current_screen')) {
500
- $screen = get_current_screen();
501
- if (!empty($screen)) {
502
- echo new MediaButton();
503
- }
504
- }
505
- }
506
- }
507
-
508
- public function editorButton($plugins)
509
- {
510
- if (empty($this->mediaButton)) {
511
- $this->mediaButton = true;
512
- add_action('admin_footer', function() {
513
- self::enqueueScriptsForPageBuilders();
514
- echo new MediaButton(false);
515
- });
516
- }
517
-
518
- return $plugins;
519
- }
520
-
521
- public static function enqueueScriptsForPageBuilders()
522
- {
523
- require_once(ABSPATH.'wp-admin/includes/screen.php');
524
- global $post;
525
- if (function_exists('get_current_screen')) {
526
- $screen = get_current_screen();
527
- if ((!empty($screen->id) && $screen->id == SG_POPUP_POST_TYPE) || !empty($post)) {
528
- if (!isset($_GET['fl_builder'])) {
529
- Javascript::enqueueScripts('post-new.php');
530
- Style::enqueueStyles('post-new.php');
531
- }
532
- }
533
- }
534
- else if (isset($_GET['fl_builder'])) {
535
- Javascript::enqueueScripts('post-new.php');
536
- Style::enqueueStyles('post-new.php');
537
- }
538
- }
539
-
540
- public function userRolesCaps()
541
- {
542
- $userSavedRoles = get_option('sgpb-user-roles');
543
-
544
- if (!$userSavedRoles) {
545
- $userSavedRoles = array('administrator');
546
- }
547
- else {
548
- array_push($userSavedRoles, 'administrator');
549
- }
550
-
551
- foreach ($userSavedRoles as $theRole) {
552
- $role = get_role($theRole);
553
- if (empty($role)) {
554
- continue;
555
- }
556
-
557
- $role->add_cap('read');
558
- $role->add_cap('read_post');
559
- $role->add_cap('read_private_sgpb_popups');
560
- $role->add_cap('edit_sgpb_popup');
561
- $role->add_cap('edit_sgpb_popups');
562
- $role->add_cap('edit_others_sgpb_popups');
563
- $role->add_cap('edit_published_sgpb_popups');
564
- $role->add_cap('publish_sgpb_popups');
565
- $role->add_cap('delete_sgpb_popups');
566
- $role->add_cap('delete_published_posts');
567
- $role->add_cap('delete_others_sgpb_popups');
568
- $role->add_cap('delete_private_sgpb_popups');
569
- $role->add_cap('delete_private_sgpb_popup');
570
- $role->add_cap('delete_published_sgpb_popups');
571
-
572
- // For popup builder sub-menus and terms
573
- $role->add_cap('sgpb_manage_options');
574
- $role->add_cap('manage_popup_terms');
575
- $role->add_cap('manage_popup_categories_terms');
576
- $role = apply_filters('sgpbUserRoleCap', $role);
577
- }
578
-
579
- return true;
580
- }
581
-
582
- public function pluginActivated()
583
- {
584
- if (!get_option('sgpbActivateExtensions') && SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
585
- $obj = new PopupExtensionActivator();
586
- $obj->activate();
587
- update_option('sgpbActivateExtensions', 1);
588
- }
589
- }
590
-
591
- public function popupShortcode($args, $content)
592
- {
593
- if (empty($args) || empty($args['id'])) {
594
- return $content;
595
- }
596
-
597
- $oldShortcode = isset($args['event']) && $args['event'] === 'onload';
598
- $isInherit = isset($args['event']) && $args['event'] == 'inherit';
599
- $event = '';
600
-
601
- $shortcodeContent = '';
602
- $argsId = $popupId = (int)$args['id'];
603
-
604
- // for old popups
605
- if (function_exists('sgpb\sgpGetCorrectPopupId')) {
606
- $popupId = sgpGetCorrectPopupId($popupId);
607
- }
608
-
609
- $popup = SGPopup::find($popupId);
610
- $popup = apply_filters('sgpbShortCodePopupObj', $popup);
611
-
612
- $event = preg_replace('/on/', '', @$args['event']);
613
- // when popup does not exists or popup post status it's not publish ex when popup in trash
614
- if (empty($popup) || (!is_object($popup) && $popup != 'publish')) {
615
- return $content;
616
- }
617
-
618
- $isActive = $popup->isActive();
619
- if (!$isActive) {
620
- return $content;
621
- }
622
-
623
- $alreadySavedEvents = $popup->getEvents();
624
- $loadableMode = $popup->getLoadableModes();
625
-
626
- if (!isset($args['event']) && isset($args['insidepopup'])) {
627
- unset($args['insidepopup']);
628
- $event = 'insideclick';
629
- $insideShortcodeKey = $popupId.$event;
630
-
631
- // for prevent infinity chain
632
- if (is_array($this->insideShortcodes) && in_array($insideShortcodeKey, $this->insideShortcodes)) {
633
- $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
634
-
635
- return $shortcodeContent;
636
- }
637
- $this->insideShortcodes[] = $insideShortcodeKey;
638
- }
639
- // if no event attribute is set, or old shortcode
640
- if (!isset($args['event']) || $oldShortcode || $isInherit) {
641
- $loadableMode = $popup->getLoadableModes();
642
- if (!empty($content)) {
643
- $alreadySavedEvents = false;
644
- }
645
- // for old popup, after the update, there aren't any events
646
- if (empty($alreadySavedEvents)) {
647
- $event = '';
648
- if (!empty($content)) {
649
- $event = 'click';
650
- }
651
- if (!empty($args['event'])) {
652
- $event = $args['event'];
653
- }
654
- $event = preg_replace('/on/', '', $event);
655
- $popup->setEvents(array($event));
656
- }
657
- if (empty($loadableMode)) {
658
- $loadableMode = array();
659
- }
660
- $loadableMode['option_event'] = true;
661
- }
662
- else {
663
- $event = $args['event'];
664
- $event = preg_replace('/on/', '', $event);
665
- $popup->setEvents(array($event));
666
- }
667
-
668
- $popup->setLoadableModes($loadableMode);
669
- $scriptsLoader = new ScriptsLoader();
670
- $loadablePopups = array($popup);
671
- $groupObj = new PopupGroupFilter();
672
- $groupObj->setPopups(array($popup));
673
- $loadablePopups = $groupObj->filter();
674
- $scriptsLoader->setLoadablePopups($loadablePopups);
675
- $scriptsLoader->loadToFooter();
676
-
677
- if (!empty($content)) {
678
- $matches = SGPopup::getPopupShortcodeMatchesFromContent($content);
679
- if (!empty($matches)) {
680
- foreach ($matches[0] as $key => $value) {
681
- $attrs = shortcode_parse_atts($matches[3][$key]);
682
- if (empty($attrs['id'])) {
683
- continue;
684
- }
685
- $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $attrs['id'], $attrs['event'], $attrs);
686
- break;
687
- }
688
- }
689
- }
690
-
691
- if (isset($event) && $event != 'onload' && !empty($content)) {
692
- $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
693
- }
694
- $shortcodeContent = apply_filters('sgpbPopupShortCodeContent', $shortcodeContent);
695
-
696
- return do_shortcode($shortcodeContent);
697
- }
698
-
699
- public function deleteSubscribersWithPopup($postId)
700
- {
701
- global $post_type;
702
-
703
- if ($post_type == SG_POPUP_POST_TYPE) {
704
- AdminHelper::deleteSubscriptionPopupSubscribers($postId);
705
- }
706
- }
707
-
708
- public function cronAddMinutes($schedules)
709
- {
710
- $schedules['sgpb_newsletter_send_every_minute'] = array(
711
- 'interval' => SGPB_CRON_REPEAT_INTERVAL * 60,
712
- 'display' => __('Once Every Minute', SG_POPUP_TEXT_DOMAIN)
713
- );
714
-
715
- $schedules['sgpb_banners'] = array(
716
- 'interval' => SGPB_TRANSIENT_TIMEOUT_WEEK,
717
- 'display' => __('Once Every Week', SG_POPUP_TEXT_DOMAIN)
718
- );
719
-
720
- $schedules = apply_filters('sgpbCronTimeoutSettings', $schedules);
721
-
722
- return $schedules;
723
- }
724
-
725
- public function newsletterSendEmail()
726
- {
727
- global $wpdb;
728
- $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
729
-
730
- if (empty($newsletterOptions)) {
731
- wp_clear_scheduled_hook('sgpb_send_newsletter');
732
- }
733
- $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
734
- $subscriptionFormTitle = get_the_title($subscriptionFormId);
735
- $emailsInFlow = (int)$newsletterOptions['emailsInFlow'];
736
- $mailSubject = $newsletterOptions['newsletterSubject'];
737
- $fromEmail = $newsletterOptions['fromEmail'];
738
- $emailMessage = $newsletterOptions['messageBody'];
739
-
740
- $allAvailableShortcodes = array();
741
- $allAvailableShortcodes['patternFirstName'] = '/\[First name]/';
742
- $allAvailableShortcodes['patternLastName'] = '/\[Last name]/';
743
- $allAvailableShortcodes['patternBlogName'] = '/\[Blog name]/';
744
- $allAvailableShortcodes['patternUserName'] = '/\[User name]/';
745
- $allAvailableShortcodes['patternUnsubscribe'] = '';
746
-
747
- $pattern = "/\[(\[?)(Unsubscribe)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/";
748
- preg_match($pattern, $emailMessage, $matches);
749
- $title = __('Unsubscribe', SG_POPUP_TEXT_DOMAIN);
750
- if ($matches) {
751
- $patternUnsubscribe = $matches[0];
752
- // If user didn't change anything inside the [unsubscribe] shortcode $matches[2] will be equal to 'Unsubscribe'
753
- if ($matches[2] == 'Unsubscribe') {
754
- $pattern = '/\s(\w+?)="(.+?)"]/';
755
- preg_match($pattern, $matches[0], $matchesTitle);
756
- if (!empty($matchesTitle[2])) {
757
- $title = AdminHelper::removeAllNonPrintableCharacters($matchesTitle[2], 'Unsubscribe');
758
- }
759
- }
760
- $allAvailableShortcodes['patternUnsubscribe'] = $patternUnsubscribe;
761
- }
762
-
763
- // When email is not valid we don't continue
764
- if (!preg_match('/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/', $fromEmail)) {
765
- wp_clear_scheduled_hook('sgpb_send_newsletter');
766
- return false;
767
- }
768
-
769
- $selectionQuery = 'SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
770
- $selectionQuery = apply_filters('sgpbUserSelectionQuery', $selectionQuery);
771
- $sql = $wpdb->prepare($selectionQuery .' and subscriptionType = %d limit 1', $subscriptionFormId);
772
-
773
- $result = $wpdb->get_row($sql, ARRAY_A);
774
- $currentStateEmailId = (int)$result['id'];
775
- $getTotalSql = $wpdb->prepare('SELECT count(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE unsubscribed = 0 and subscriptionType = %d', $subscriptionFormId);
776
- $totalSubscribers = $wpdb->get_var($getTotalSql);
777
-
778
- // $currentStateEmailId == 0 when all emails status = 1
779
- if ($currentStateEmailId == 0) {
780
- // Clear schedule hook
781
- $headers = 'MIME-Version: 1.0'."\r\n";
782
- $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n";
783
- $successTotal = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
784
- if (!$successTotal) {
785
- $successTotal = 0;
786
- }
787
- $failedTotal = $totalSubscribers - $successTotal;
788
-
789
- $emailMessageCustom = __('Your mail list %s delivered successfully!
790
- %d of the %d emails succeeded, %d failed.
791
- For more details, please download log file inside the plugin.
792
- This email was generated via Popup Builder plugin.', SG_POPUP_TEXT_DOMAIN);
793
- $emailMessageCustom = sprintf($emailMessageCustom, $subscriptionFormTitle, $successTotal, $totalSubscribers, $failedTotal);
794
-
795
- wp_mail($fromEmail, $subscriptionFormTitle.' list has been successfully delivered!', $emailMessageCustom, $headers);
796
- delete_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
797
- wp_clear_scheduled_hook('sgpb_send_newsletter');
798
- return;
799
- }
800
-
801
- $getAllDataSql = 'SELECT id, firstName, lastName, email FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
802
- $getAllDataSql = apply_filters('sgpbUserSelectionQuery', $getAllDataSql);
803
- $getAllDataSql = $wpdb->prepare($getAllDataSql .' and id >= %d and subscriptionType = %s limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
804
- $subscribers = $wpdb->get_results($getAllDataSql, ARRAY_A);
805
-
806
- $subscribers = apply_filters('sgpNewsletterSendingSubscribers', $subscribers);
807
-
808
- $blogInfo = get_bloginfo();
809
- $headers = array(
810
- 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
811
- 'MIME-Version: 1.0' ,
812
- 'Content-type: text/html; charset=UTF-8'
813
- );
814
-
815
- foreach ($subscribers as $subscriber) {
816
- $replacementId = $subscriber['id'];
817
- $allAvailableShortcodes = apply_filters('sgpbNewsletterShortcodes', $allAvailableShortcodes, $subscriptionFormId, $replacementId);
818
- $replacementFirstName = $subscriber['firstName'];
819
- $replacementLastName = $subscriber['lastName'];
820
- $replacementBlogName = $newsletterOptions['blogname'];
821
- $replacementUserName = $newsletterOptions['username'];
822
- $replacementEmail = $subscriber['email'];
823
- $replacementUnsubscribe = get_home_url();
824
- $replacementUnsubscribe .= '?sgpbUnsubscribe='.md5($replacementId.$replacementEmail);
825
- $replacementUnsubscribe .= '&email='.$subscriber['email'];
826
- $replacementUnsubscribe .= '&popup='.$subscriptionFormId;
827
- $replacementUnsubscribe = '<br><a href="'.$replacementUnsubscribe.'">'.$title.'</a>';
828
-
829
- // Replace First name and Last name from email message
830
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternFirstName'], $replacementFirstName, $emailMessage);
831
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternLastName'], $replacementLastName, $emailMessageCustom);
832
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternBlogName'], $replacementBlogName, $emailMessageCustom);
833
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternUserName'], $replacementUserName, $emailMessageCustom);
834
- $emailMessageCustom = str_replace($allAvailableShortcodes['patternUnsubscribe'], $replacementUnsubscribe, $emailMessageCustom);
835
- if (!empty($allAvailableShortcodes['extraShortcodesWithValues'])) {
836
- $customFields = $allAvailableShortcodes['extraShortcodesWithValues'];
837
- foreach ($customFields as $customFieldKey => $customFieldValue) {
838
- $finalShortcode = '/\['.$customFieldKey.']/';
839
- $emailMessageCustom = preg_replace($finalShortcode, $customFieldValue, $emailMessageCustom);
840
- }
841
- }
842
- $emailMessageCustom = stripslashes($emailMessageCustom);
843
-
844
- $emailMessageCustom = apply_filters('sgpNewsletterSendingMessage', $emailMessageCustom);
845
- $mailStatus = wp_mail($subscriber['email'], $mailSubject, $emailMessageCustom, $headers);
846
- if (!$mailStatus) {
847
- $errorLogSql = $wpdb->prepare('INSERT INTO '. $wpdb->prefix .SGPB_SUBSCRIBERS_ERROR_TABLE_NAME.' (`popupType`, `email`, `date`) VALUES (%s, %s, %s)', $subscriptionFormId, $subscriber['email'], date('Y-m-d H:i'));
848
- $wpdb->query($errorLogSql);
849
- continue;
850
- }
851
-
852
- $successCount = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
853
- if (!$successCount) {
854
- update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, 1);
855
- }
856
- else {
857
- update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, ++$successCount);
858
- }
859
- }
860
- // Update the status of all the sent mails
861
- $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 1 where id >= %d and subscriptionType = %d limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
862
- $wpdb->query($updateStatusQuery);
863
- }
864
-
865
- private function unsubscribe($params = array())
866
- {
867
- AdminHelper::deleteUserFromSubscribers($params);
868
- }
869
-
870
- public function enqueuePopupBuilderScripts()
871
- {
872
- // for old popups
873
- if (get_option('SG_POPUP_VERSION')) {
874
- ConvertToNewVersion::saveCustomInserted();
875
- }
876
-
877
- $popupLoaderObj = PopupLoader::instance();
878
- if (is_object($popupLoaderObj)) {
879
- $popupLoaderObj->loadPopups();
880
- }
881
- }
882
-
883
- public function adminLoadPopups($hook)
884
- {
885
- $allowedPages = array();
886
- $allowedPages = apply_filters('sgpbAdminLoadedPages', $allowedPages);
887
-
888
- if (!empty($allowedPages) && is_array($allowedPages) && in_array($hook, $allowedPages)) {
889
- $scriptsLoader = new ScriptsLoader();
890
- $scriptsLoader->setIsAdmin(true);
891
- $scriptsLoader->loadToFooter();
892
- }
893
- }
894
-
895
- public function postTypeInit()
896
- {
897
- if (isset($_POST['sgpb-is-preview']) && $_POST['sgpb-is-preview'] == 1) {
898
- $postId = $_POST['post_ID'];
899
- $post = get_post($postId);
900
- $this->savePost($postId, $post, false);
901
- }
902
- $adminUrl = admin_url();
903
-
904
- if (isset($_GET['page']) && $_GET['page'] == 'PopupBuilder') {
905
- _e('<span>Popup Builder plugin has been successfully updated. Please <a href="'.esc_attr($adminUrl).'edit.php?post_type='.SG_POPUP_POST_TYPE.'">click here</a> to go to the new Dashboard of the plugin.</span>', SG_POPUP_TEXT_DOMAIN);
906
- wp_die();
907
- }
908
-
909
- $unsubscribeArgs = $this->collectUnsubscriberArgs();
910
- if (!empty($unsubscribeArgs)) {
911
- $this->unsubscribe($unsubscribeArgs);
912
- }
913
-
914
- AdminHelper::removeUnnecessaryCodeFromPopups();
915
-
916
- $this->customPostTypeObj = new RegisterPostType();
917
- }
918
-
919
- public function collectUnsubscriberArgs()
920
- {
921
- if (!isset($_GET['sgpbUnsubscribe'])) {
922
- return false;
923
- }
924
- $args = array();
925
- if (isset($_GET['sgpbUnsubscribe'])) {
926
- $args['token'] = $_GET['sgpbUnsubscribe'];
927
- }
928
- if (isset($_GET['email'])) {
929
- $args['email'] = $_GET['email'];
930
- }
931
- if (isset($_GET['popup'])) {
932
- $args['popup'] = $_GET['popup'];
933
- }
934
-
935
- return $args;
936
- }
937
-
938
- public function addSubMenu()
939
- {
940
- // We need to check license keys and statuses before adding new menu "License" item
941
- new Updates();
942
-
943
- $this->customPostTypeObj->addSubMenu();
944
- }
945
-
946
- public function supportLinks()
947
- {
948
- if (SGPB_POPUP_PKG == SGPB_POPUP_PKG_FREE) {
949
- if (method_exists($this->customPostTypeObj, 'supportLinks')) {
950
- $this->customPostTypeObj->supportLinks();
951
- }
952
- }
953
- }
954
-
955
- public function popupMetaboxes()
956
- {
957
- $this->customPostTypeObj->addPopupMetaboxes();
958
- }
959
-
960
- public function savePost($postId = 0, $post = array(), $update = false)
961
- {
962
- if ($post->post_type !== SG_POPUP_POST_TYPE) {
963
- return;
964
- }
965
- $allowToAction = AdminHelper::userCanAccessTo();
966
- Functions::clearAllTransients();
967
- $postData = SGPopup::parsePopupDataFromData($_POST);
968
- $saveMode = '';
969
- $postData['sgpb-post-id'] = $postId;
970
- // If preview mode
971
- if (isset($postData['sgpb-is-preview']) && $postData['sgpb-is-preview'] == 1) {
972
- $saveMode = '_preview';
973
- SgpbPopupConfig::popupTypesInit();
974
- SgpbDataConfig::init();
975
- // published popup
976
- if (empty($post)) {
977
- global $post;
978
- $postId = $post->ID;
979
- }
980
- if ($post->post_status != 'draft') {
981
- $posts = array();
982
- $popupContent = $post->post_content;
983
-
984
- $query = new WP_Query(
985
- array(
986
- 'post_parent' => $postId,
987
- 'posts_per_page' => - 1,
988
- 'post_type' => 'revision',
989
- 'post_status' => 'inherit'
990
- )
991
- );
992
- $query = apply_filters('sgpbSavePostQuery', $query);
993
-
994
- while ($query->have_posts()) {
995
- $query->the_post();
996
- if (empty($posts)) {
997
- $posts[] = $post;
998
- }
999
- }
1000
- if (!empty($posts[0])) {
1001
- $popup = $posts[0];
1002
- $popupContent = $popup->post_content;
1003
- }
1004
- }
1005
- }
1006
-
1007
-
1008
- if (empty($post)) {
1009
- $saveMode = '';
1010
- }
1011
-
1012
- if ($post->post_status == 'draft') {
1013
- $saveMode = '_preview';
1014
- }
1015
-
1016
- /* In preview mode saveMode should be true*/
1017
- if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
1018
- if (!$allowToAction) {
1019
- wp_redirect(get_home_url());
1020
- exit();
1021
- }
1022
- if (!empty($postData['sgpb-type'])) {
1023
- $popupType = $postData['sgpb-type'];
1024
- $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
1025
- $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
1026
- require_once($popupClassPath.$popupClassName.'.php');
1027
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
1028
-
1029
- $popupClassName::create($postData, $saveMode, 1);
1030
- }
1031
- }
1032
- else {
1033
- $content = get_post_field('post_content', $postId);
1034
- SGPopup::deletePostCustomInsertedData($postId);
1035
- SGPopup::deletePostCustomInsertedEvents($postId);
1036
- /*We detect all the popups that were inserted as a custom ones, in the content.*/
1037
- SGPopup::savePopupsFromContentClasses($content, $post);
1038
- }
1039
- }
1040
-
1041
- /**
1042
- * Check Popup is satisfy for popup condition
1043
- *
1044
- * @param array $args
1045
- *
1046
- * @return array
1047
- *
1048
- *@since 1.0.0
1049
- *
1050
- */
1051
- public function conditionsSatisfy($args = array())
1052
- {
1053
- if (isset($args['status']) && $args['status'] === false) {
1054
- return $args;
1055
- }
1056
- $args['status'] = PopupChecker::checkOtherConditionsActions($args);
1057
-
1058
- return $args;
1059
- }
1060
-
1061
- public function popupsTableColumnsValues($column, $postId)
1062
- {
1063
- $postId = (int)$postId;// Convert to int for security reasons
1064
- global $post_type;
1065
- if ($postId) {
1066
- $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
1067
- $popup = SGPopup::find($postId, $args);
1068
- }
1069
-
1070
- if (empty($popup) && $post_type == SG_POPUP_POST_TYPE) {
1071
- return false;
1072
- }
1073
-
1074
- if ($column == 'shortcode') {
1075
- echo '<input type="text" onfocus="this.select();" readonly value="[sg_popup id='.$postId.']" class="large-text code">';
1076
- }
1077
- if ($column == 'className') {
1078
- echo '<input type="text" onfocus="this.select();" readonly value="sg-popup-id-'.esc_attr($postId).'" class="large-text code">';
1079
- }
1080
- else if ($column == 'counter') {
1081
- $count = $popup->getPopupOpeningCountById($postId);
1082
- echo '<div ><span>'.$count.'</span>'.'<input onclick="SGPBBackend.resetCount('.$postId.', true);" type="button" name="" class="sgpb-btn sgpb-btn-dark-outline" value="'.__('reset', SG_POPUP_TEXT_DOMAIN).'"></div>';
1083
- }
1084
- else if ($column == 'type') {
1085
- global $SGPB_POPUP_TYPES;
1086
- $type = $popup->getType();
1087
- if (isset($SGPB_POPUP_TYPES['typeLabels'][$type])) {
1088
- $type = $SGPB_POPUP_TYPES['typeLabels'][$type];
1089
- }
1090
- echo $type;
1091
- }
1092
- else if ($column == 'onOff') {
1093
- $popupPostStatus = get_post_status($postId);
1094
- if ($popupPostStatus == 'publish' || $popupPostStatus == 'draft') {
1095
- $isActive = $popup->getOptionValue('sgpb-is-active', true);
1096
- }
1097
- $checked = isset($isActive) && $isActive ? 'checked' : '';
1098
- echo '<label class="sgpb-switch">
1099
- <input class="sg-switch-checkbox sgpb-popup-status-js" value="1" data-switch-id="'.$postId.'" type="checkbox" '.$checked.'>
1100
- <div class="sgpb-slider sgpb-round"></div>
1101
- </label>';
1102
- }
1103
- else if ($column == 'sgpbIsRandomEnabled') {
1104
- $showValues = apply_filters('sgpbAddRandomTableColumnValues', $postId);
1105
- echo $showValues;
1106
- }
1107
- else if ($column == 'options') {
1108
- $cloneUrl = AdminHelper::popupGetClonePostLink($postId);
1109
- $actionButtons = '<div class="icon icon_blue">
1110
- <img src="'.SG_POPUP_PUBLIC_URL.'icons/iconEdit.png" alt="Edit" class="icon_edit" onclick="location.href=\''.get_edit_post_link($postId).'\'">
1111
- </div>';
1112
- $actionButtons .= '<div class="icon icon_blue">
1113
- <img src="'.SG_POPUP_PUBLIC_URL.'icons/iconClone.png" alt="Clone" class="icon_clone" onclick="location.href=\''.$cloneUrl.'\'">
1114
- </div>';
1115
- $actionButtons .= '<div class="icon icon_pink">
1116
- <img src="'.SG_POPUP_PUBLIC_URL.'icons/recycle-bin.svg" alt="Remove" class="icon_remove" onclick="location.href=\''.get_delete_post_link($postId).'\'">
1117
- </div>';
1118
-
1119
- echo $actionButtons;
1120
- }
1121
- }
1122
-
1123
- /*
1124
- * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
1125
- * then redirects to the post list
1126
- */
1127
- public function popupSaveAsNew($status = '')
1128
- {
1129
- if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'popupSaveAsNew' == $_REQUEST['action']))) {
1130
- wp_die(esc_html__('No post to duplicate has been supplied!', SG_POPUP_TEXT_DOMAIN));
1131
- }
1132
- // Get the original post
1133
- $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
1134
-
1135
- check_admin_referer('duplicate-post_'.$id);
1136
-
1137
- $post = get_post($id);
1138
-
1139
- // Copy the post and insert it
1140
- if (isset($post) && $post != null) {
1141
- $newId = $this->popupCreateDuplicate($post, $status);
1142
- $postType = $post->post_type;
1143
-
1144
- if ($status == '') {
1145
- $sendBack = wp_get_referer();
1146
- if (!$sendBack ||
1147
- strpos($sendBack, 'post.php') !== false ||
1148
- strpos($sendBack, 'post-new.php') !== false) {
1149
- if ('attachment' == $postType) {
1150
- $sendBack = admin_url('upload.php');
1151
- }
1152
- else {
1153
- $sendBack = admin_url('edit.php');
1154
- if (!empty($postType)) {
1155
- $sendBack = add_query_arg('post_type', $postType, $sendBack);
1156
- }
1157
- }
1158
- }
1159
- else {
1160
- $sendBack = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'cloned', 'ids'), $sendBack);
1161
- }
1162
- // Redirect to the post list screen
1163
- wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), $sendBack));
1164
- }
1165
- else {
1166
- // Redirect to the edit screen for the new draft post
1167
- wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), admin_url('post.php?action=edit&post='.$newId)));
1168
- }
1169
- exit;
1170
-
1171
- }
1172
- else {
1173
- wp_die(esc_html__('Copy creation failed, could not find original:', SG_POPUP_TEXT_DOMAIN).' '.htmlspecialchars($id));
1174
- }
1175
- }
1176
-
1177
- /**
1178
- * Create a duplicate from a post
1179
- */
1180
- public function popupCreateDuplicate($post, $status = '', $parent_id = '')
1181
- {
1182
- $newPostStatus = (empty($status))? $post->post_status: $status;
1183
-
1184
- if ($post->post_type != 'attachment') {
1185
- $title = $post->post_title;
1186
- if ($title == '') {
1187
- // empty title
1188
- $title = __('(no title) (clone)');
1189
- }
1190
- else {
1191
- $title .= ' '.__('(clone)');
1192
- }
1193
-
1194
- if ('publish' == $newPostStatus || 'future' == $newPostStatus) {
1195
- // check if the user has the right capability
1196
- if (is_post_type_hierarchical($post->post_type)) {
1197
- if (!current_user_can('publish_pages')) {
1198
- $newPostStatus = 'pending';
1199
- }
1200
- }
1201
- else {
1202
- if (!current_user_can('publish_posts')) {
1203
- $newPostStatus = 'pending';
1204
- }
1205
- }
1206
- }
1207
- }
1208
-
1209
- $newPostAuthor = wp_get_current_user();
1210
- $newPostAuthorId = $newPostAuthor->ID;
1211
- // check if the user has the right capability
1212
- if (is_post_type_hierarchical($post->post_type)) {
1213
- if (current_user_can('edit_others_pages')) {
1214
- $newPostAuthorId = $post->post_author;
1215
- }
1216
- }
1217
- else {
1218
- if (current_user_can('edit_others_posts')) {
1219
- $newPostAuthorId = $post->post_author;
1220
- }
1221
- }
1222
-
1223
- $newPost = array(
1224
- 'menu_order' => $post->menu_order,
1225
- 'comment_status' => $post->comment_status,
1226
- 'ping_status' => $post->ping_status,
1227
- 'post_author' => $newPostAuthorId,
1228
- 'post_content' => $post->post_content,
1229
- 'post_content_filtered' => $post->post_content_filtered,
1230
- 'post_excerpt' => $post->post_excerpt,
1231
- 'post_mime_type' => $post->post_mime_type,
1232
- 'post_parent' => $newPostParent = empty($parent_id)? $post->post_parent : $parent_id,
1233
- 'post_password' => $post->post_password,
1234
- 'post_status' => $newPostStatus,
1235
- 'post_title' => $title,
1236
- 'post_type' => $post->post_type,
1237
- );
1238
-
1239
- $newPost['post_date'] = $newPostDate = $post->post_date;
1240
- $newPost['post_date_gmt'] = get_gmt_from_date($newPostDate);
1241
- $newPostId = wp_insert_post(wp_slash($newPost));
1242
-
1243
- // If the copy is published or scheduled, we have to set a proper slug.
1244
- if ($newPostStatus == 'publish' || $newPostStatus == 'future') {
1245
- $postName = $post->post_name;
1246
- $postName = wp_unique_post_slug($postName, $newPostId, $newPostStatus, $post->post_type, $newPostParent);
1247
-
1248
- $newPost = array();
1249
- $newPost['ID'] = $newPostId;
1250
- $newPost['post_name'] = $postName;
1251
-
1252
- // Update the post into the database
1253
- wp_update_post(wp_slash($newPost));
1254
- }
1255
-
1256
- // If you have written a plugin which uses non-WP database tables to save
1257
- // information about a post you can hook this action to dupe that data.
1258
- if ($post->post_type == 'page' || is_post_type_hierarchical($post->post_type)) {
1259
- do_action('dp_duplicate_page', $newPostId, $post, $status);
1260
- }
1261
- else {
1262
- do_action('sgpb_duplicate_post', $newPostId, $post, $status);
1263
- }
1264
-
1265
- delete_post_meta($newPostId, '_sgpb_original');
1266
- add_post_meta($newPostId, '_sgpb_original', $post->ID);
1267
-
1268
- return $newPostId;
1269
- }
1270
-
1271
- /**
1272
- * Copy the meta information of a post to another post
1273
- */
1274
- public function popupCopyPostMetaInfo($newId, $post)
1275
- {
1276
- $postMetaKeys = get_post_custom_keys($post->ID);
1277
- $metaBlacklist = '';
1278
-
1279
- if (empty($postMetaKeys) || !is_array($postMetaKeys)) {
1280
- return;
1281
- }
1282
- $metaBlacklist = explode(',', $metaBlacklist);
1283
- $metaBlacklist = array_filter($metaBlacklist);
1284
- $metaBlacklist = array_map('trim', $metaBlacklist);
1285
- $metaBlacklist[] = '_edit_lock';
1286
- $metaBlacklist[] = '_edit_last';
1287
- $metaBlacklist[] = '_wp_page_template';
1288
- $metaBlacklist[] = '_thumbnail_id';
1289
-
1290
- $metaBlacklist = apply_filters('duplicate_post_blacklist_filter' , $metaBlacklist);
1291
-
1292
- $metaBlacklistString = '('.implode(')|(',$metaBlacklist).')';
1293
- $metaKeys = array();
1294
-
1295
- if (strpos($metaBlacklistString, '*') !== false) {
1296
- $metaBlacklistString = str_replace(array('*'), array('[a-zA-Z0-9_]*'), $metaBlacklistString);
1297
-
1298
- foreach ($postMetaKeys as $metaKey) {
1299
- if (!preg_match('#^'.$metaBlacklistString.'$#', $metaKey)) {
1300
- $metaKeys[] = $metaKey;
1301
- }
1302
- }
1303
- }
1304
- else {
1305
- $metaKeys = array_diff($postMetaKeys, $metaBlacklist);
1306
- }
1307
-
1308
- $metaKeys = apply_filters('duplicate_post_meta_keys_filter', $metaKeys);
1309
-
1310
- foreach ($metaKeys as $metaKey) {
1311
- $metaValues = get_post_custom_values($metaKey, $post->ID);
1312
- foreach ($metaValues as $metaValue) {
1313
- $metaValue = maybe_unserialize($metaValue);
1314
- if (is_array($metaValue)) {
1315
- $metaValue['sgpb-post-id'] = $newId;
1316
- }
1317
- add_post_meta($newId, $metaKey, $this->popupWpSlash($metaValue));
1318
- }
1319
- }
1320
- }
1321
-
1322
- public function popupAddSlashesDeep($value)
1323
- {
1324
- if (function_exists('map_deep')) {
1325
- return map_deep($value, array($this, 'popupAddSlashesToStringsOnly'));
1326
- }
1327
- else {
1328
- return wp_slash($value);
1329
- }
1330
- }
1331
-
1332
- public function popupAddSlashesToStringsOnly($value)
1333
- {
1334
- return is_string($value) ? addslashes($value) : $value;
1335
- }
1336
-
1337
- public function popupWpSlash($value)
1338
- {
1339
- return $this->popupAddSlashesDeep($value);
1340
- }
1341
-
1342
- public function removePostPermalink($args)
1343
- {
1344
- global $post_type;
1345
-
1346
- if ($post_type == SG_POPUP_POST_TYPE && is_admin()) {
1347
- // hide permalink for popupbuilder post type
1348
- return '';
1349
- }
1350
-
1351
- return $args;
1352
- }
1353
-
1354
- // remove link ( e.g.: (View post) ), from popup updated/published message
1355
- public function popupPublishedMessage($messages)
1356
- {
1357
- global $post_type;
1358
-
1359
- if ($post_type == SG_POPUP_POST_TYPE) {
1360
- // post(popup) updated
1361
- if (isset($messages['post'][1])) {
1362
- $messages['post'][1] = __('Popup updated.', SG_POPUP_TEXT_DOMAIN);
1363
- }
1364
- // post(popup) published
1365
- if (isset($messages['post'][6])) {
1366
- $messages['post'][6] = __('Popup published.', SG_POPUP_TEXT_DOMAIN);
1367
- }
1368
- }
1369
- $messages = apply_filters('sgpbPostUpdateMessage', $messages);
1370
-
1371
- return $messages;
1372
- }
1373
-
1374
- public function getSubscribersCsvFile()
1375
- {
1376
- global $wpdb;
1377
- $allowToAction = AdminHelper::userCanAccessTo();
1378
- if (!$allowToAction) {
1379
- wp_redirect(get_home_url());
1380
- exit();
1381
- }
1382
-
1383
- $query = AdminHelper::subscribersRelatedQuery();
1384
- if (isset($_GET['orderby']) && !empty($_GET['orderby'])) {
1385
- if (isset($_GET['order']) && !empty($_GET['order'])) {
1386
- $query .= ' ORDER BY '.esc_sql($_GET['orderby']).' '.esc_sql($_GET['order']);
1387
- }
1388
- }
1389
- $content = '';
1390
- $exportTypeQuery = '';
1391
- $rows = array('first name', 'last name', 'email', 'date', 'popup');
1392
- foreach ($rows as $value) {
1393
- $content .= $value;
1394
- if ($value != 'popup') {
1395
- $content .= ',';
1396
- }
1397
- }
1398
- $content .= "\n";
1399
- $subscribers = $wpdb->get_results($query, ARRAY_A);
1400
-
1401
- $subscribers = apply_filters('sgpbSubscribersCsv', $subscribers);
1402
-
1403
- foreach($subscribers as $values) {
1404
- foreach ($values as $key => $value) {
1405
- $content .= $value;
1406
- if ($key != 'subscriptionTitle') {
1407
- $content .= ',';
1408
- }
1409
- }
1410
- $content .= "\n";
1411
- }
1412
-
1413
- $content = apply_filters('sgpbSubscribersContent', $content);
1414
-
1415
- header('Pragma: public');
1416
- header('Expires: 0');
1417
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1418
- header('Cache-Control: private', false);
1419
- header('Content-Type: application/octet-stream');
1420
- header('Content-Disposition: attachment; filename=subscribersList.csv;');
1421
- header('Content-Transfer-Encoding: binary');
1422
- echo $content;
1423
- }
1424
-
1425
- public function getSystemInfoFile()
1426
- {
1427
- $allowToAction = AdminHelper::userCanAccessTo();
1428
- if (!$allowToAction) {
1429
- return false;
1430
- }
1431
-
1432
- $content = AdminHelper::getSystemInfoText();
1433
-
1434
- header('Pragma: public');
1435
- header('Expires: 0');
1436
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1437
- header('Cache-Control: private', false);
1438
- header('Content-Type: application/octet-stream');
1439
- header('Content-Disposition: attachment; filename=popupBuilderSystemInfo.txt;');
1440
- header('Content-Transfer-Encoding: binary');
1441
-
1442
- echo $content;
1443
- }
1444
-
1445
- public function saveSettings()
1446
- {
1447
- $allowToAction = AdminHelper::userCanAccessTo();
1448
- if (!$allowToAction) {
1449
- wp_redirect(get_home_url());
1450
- exit();
1451
- }
1452
-
1453
- $postData = $_POST;
1454
- $deleteData = 0;
1455
- $enableDebugMode = 0;
1456
-
1457
- if (isset($postData['sgpb-dont-delete-data'])) {
1458
- $deleteData = 1;
1459
- }
1460
- if (isset($postData['sgpb-enable-debug-mode'])) {
1461
- $enableDebugMode = 1;
1462
- }
1463
- if (isset($postData['sgpb-disable-analytics-general'])) {
1464
- $disableAnalytics = 1;
1465
- }
1466
- $userRoles = @$postData['sgpb-user-roles'];
1467
-
1468
- update_option('sgpb-user-roles', $userRoles);
1469
- update_option('sgpb-dont-delete-data', $deleteData);
1470
- update_option('sgpb-enable-debug-mode', $enableDebugMode);
1471
- update_option('sgpb-disable-analytics-general', $disableAnalytics);
1472
-
1473
- AdminHelper::filterUserCapabilitiesForTheUserRoles('save');
1474
-
1475
- wp_redirect(admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
1476
- }
1477
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \WP_Query;
4
+ use \SgpbPopupConfig;
5
+ use \SgpbDataConfig;
6
+
7
+ class Actions
8
+ {
9
+ public $customPostTypeObj;
10
+ public $mediaButton = false;
11
+
12
+ public function __construct()
13
+ {
14
+ $this->init();
15
+ }
16
+
17
+ public function init()
18
+ {
19
+ add_action('init', array($this, 'wpInit'), 9999999999);
20
+ add_action('init', array($this, 'postTypeInit'), 9999);
21
+ add_action('init', array($this, 'updatesInit'), 9999);
22
+ add_action('admin_menu', array($this, 'addSubMenu'));
23
+ add_action('admin_menu', array($this, 'supportLinks'), 999);
24
+ add_action('admin_head', array($this, 'showPreviewButtonAfterPopupPublish'));
25
+ add_action('admin_head', array($this, 'custom_admin_js'));
26
+ add_action('admin_enqueue_scripts', array($this, 'adminLoadPopups'));
27
+ add_action('admin_action_popupSaveAsNew', array($this, 'popupSaveAsNew'));
28
+ add_action('admin_post_csv_file', array($this, 'getSubscribersCsvFile'));
29
+ add_action('admin_post_sgpb_system_info', array($this, 'getSystemInfoFile'));
30
+ add_action('admin_post_sgpbSaveSettings', array($this, 'saveSettings'), 10, 1);
31
+ add_action('admin_init', array($this, 'userRolesCaps'));
32
+ add_action('admin_notices', array($this, 'pluginNotices'));
33
+ add_action('admin_init', array($this, 'pluginLoaded'));
34
+ add_action('transition_post_status', array($this, 'deletePopup'), 100, 3);
35
+ // activate extensions
36
+ add_action('wp_before_admin_bar_render', array($this, 'pluginActivated'), 10, 2);
37
+ add_action('admin_head', array($this, 'hidePageBuilderEditButtons'));
38
+ add_action('admin_head', array($this, 'hidePublishingActions'));
39
+ add_action('add_meta_boxes', array($this, 'popupMetaboxes'), 100);
40
+ add_filter('post_updated_messages', array($this, 'popupPublishedMessage'), 1, 1);
41
+ add_action('before_delete_post', array($this, 'deleteSubscribersWithPopup'), 1, 1);
42
+ add_action('sgpb_duplicate_post', array($this, 'popupCopyPostMetaInfo'), 10, 2);
43
+ add_filter('get_sample_permalink_html', array($this, 'removePostPermalink'), 1, 1);
44
+ add_action('manage_'.SG_POPUP_POST_TYPE.'_posts_custom_column' , array($this, 'popupsTableColumnsValues'), 10, 2);
45
+ add_action('media_buttons', array($this, 'popupMediaButton'));
46
+ add_filter('mce_external_plugins', array($this, 'editorButton'), 1, 1);
47
+ add_action('admin_enqueue_scripts', array('sgpb\Style', 'enqueueStyles'));
48
+ add_action('admin_enqueue_scripts', array('sgpb\Javascript', 'enqueueScripts'));
49
+ // this action for popup options saving and popup builder classes save ex from post and page
50
+ add_action('save_post', array($this, 'savePost'), 100, 3);
51
+ add_action('wp_enqueue_scripts', array($this, 'enqueuePopupBuilderScripts'));
52
+ add_filter('sgpbOtherConditions', array($this ,'conditionsSatisfy'), 11, 1);
53
+ add_shortcode('sg_popup', array($this, 'popupShortcode'));
54
+ add_filter('cron_schedules', array($this, 'cronAddMinutes'), 10, 1);
55
+ add_action('sgpb_send_newsletter', array($this, 'newsletterSendEmail'), 10, 1);
56
+ add_action('sgpbGetBannerContentOnce', array($this, 'getBannerContent'), 10, 1);
57
+ add_action('plugins_loaded', array($this, 'loadTextDomain'));
58
+ // for change admin popup list order
59
+ add_action('pre_get_posts', array($this, 'preGetPosts'));
60
+ add_action('template_redirect', array($this, 'redirectFromPopupPage'));
61
+ add_filter('views_edit-popupbuilder', array($this, 'mainActionButtons'), 10, 1);
62
+ add_action('wpml_loaded', array($this, 'wpmlRelatedActions'));
63
+
64
+ add_filter('get_user_option_screen_layout_'.SG_POPUP_POST_TYPE, array($this, 'screenLayoutSetOneColumn'));
65
+ new SGPBFeedback();
66
+ new SGPBReports();
67
+ new SGPBMenu();
68
+ new Ajax();
69
+ }
70
+
71
+ private function checkIfLicenseIsActive($license, $itemId, $storeURL, $key) {
72
+ $transient = 'sgpb-license-key-'.$key.'-requested';
73
+ if ( false !== ( $value = get_transient( $transient ) ) ) {
74
+ return;
75
+ }
76
+ $apiParams = array(
77
+ 'edd_action' => 'activate_license',
78
+ 'license' => $license,
79
+ 'item_id' => $itemId, // The ID of the item in EDD
80
+ 'url' => home_url()
81
+ );
82
+ $response = wp_remote_post($storeURL, array('timeout' => 15, 'sslverify' => false, 'body' => $apiParams));
83
+ if (!is_wp_error($response) || 200 == wp_remote_retrieve_response_code($response)) {
84
+ $licenseData = json_decode(wp_remote_retrieve_body($response));
85
+ update_option('sgpb-license-status-'.$key, $licenseData->license);
86
+ set_transient($transient, $licenseData->item_name, WEEK_IN_SECONDS);
87
+ }
88
+
89
+ }
90
+ public function updatesInit()
91
+ {
92
+ if (!class_exists('sgpb\EDD_SL_Plugin_Updater')) {
93
+ // load our custom updater if it doesn't already exist
94
+ require_once(SG_POPUP_LIBS_PATH .'EDD_SL_Plugin_Updater.php');
95
+ }
96
+ $licenses = (new License())->getLicenses();
97
+ foreach ($licenses as $license) {
98
+ $key = @$license['key'];
99
+ $storeURL = @$license['storeURL'];
100
+ $itemId = @$license['itemId'];
101
+ $filePath = @$license['file'];
102
+ $pluginMainFilePath = strpos($filePath, SG_POPUP_PLUGIN_PATH) !== 0 ? SG_POPUP_PLUGIN_PATH.$filePath : $filePath;
103
+
104
+ $licenseKey = trim(get_option('sgpb-license-key-'.$key));
105
+ $status = get_option('sgpb-license-status-'.$key);
106
+
107
+ if ($status == false || $status != 'valid') {
108
+ continue;
109
+ }
110
+ $this->checkIfLicenseIsActive($licenseKey, $itemId, $storeURL, $key);
111
+ switch($key) {
112
+ case 'POPUP_SOCIAL':
113
+ if (defined('SGPB_SOCIAL_POPUP_VERSION')) {
114
+ $version = @constant('SGPB_SOCIAL_POPUP_VERSION');
115
+ } else {
116
+ $version = @constant('SG_VERSION_'.$key);
117
+ }
118
+ break;
119
+ case 'POPUP_AGE_VERIFICATION':
120
+ if (defined('SGPB_AGE_VERIFICATION_POPUP_VERSION')) {
121
+ $version = @constant('SGPB_AGE_VERIFICATION_POPUP_VERSION');
122
+ } else{
123
+ $version = @constant('SG_VERSION_'.$key);
124
+ }
125
+ break;
126
+ case 'POPUP_GAMIFICATION':
127
+ if (defined('POPUP_GAMIFICATION')) {
128
+ $version = @constant('POPUP_GAMIFICATION');
129
+ } else {
130
+ $version = @constant('SG_VERSION_'.$key);
131
+ }
132
+ break;
133
+ default :
134
+ $version = @constant('SG_VERSION_'.$key);
135
+ break;
136
+ }
137
+ // If the version of the extension is not found, update will not possibly be shown
138
+ if(empty($version)) {
139
+ continue;
140
+ }
141
+ $sgpbUpdater = new EDD_SL_Plugin_Updater($storeURL, $pluginMainFilePath, array(
142
+ 'version' => $version, // current version number
143
+ 'license' => $licenseKey, // license key (used get_option above to retrieve from DB)
144
+ 'item_id' => $license['itemId'], // id of this plugin
145
+ 'author' => $license['autor'], // author of this plugin
146
+ 'beta' => false // set to true if you wish customers to receive update notifications of beta releases
147
+ ));
148
+ }
149
+ }
150
+ public function custom_admin_js()
151
+ {
152
+ $currentPostType = AdminHelper::getCurrentPostType();
153
+ if (!empty($currentPostType) && ($currentPostType == SG_POPUP_POST_TYPE || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE || $currentPostType == SG_POPUP_TEMPLATE_POST_TYPE)) {
154
+ ?>
155
+ <script type="text/javascript">
156
+ jQuery(document).ready(function($) {
157
+ const myForm = $('#posts-filter');
158
+ myForm.addClass('sgpb-table');
159
+ const searchValue = $('#post-search-input').val();
160
+ $('#posts-filter .tablenav.top .tablenav-pages').append($('.subsubsub').addClass('show'));
161
+ myForm.append($('#posts-filter .tablenav.bottom .tablenav-pages:not(.no-pages, .one-page) .pagination-links'));
162
+ $('#sgpbSearchInPosts').val(searchValue);
163
+ $('#sgpbSearchInPosts').keyup('enter', function (e) {
164
+ if (e.key === 'Enter') {
165
+ $('#post-search-input').val(this.value);
166
+ $(myForm).submit();
167
+ }
168
+ });
169
+ $('#sgpbSearchInPostsSubmit').on('click', function () {
170
+ $('#post-search-input').val($('#sgpbSearchInPosts').val());
171
+ $(myForm).submit();
172
+ })
173
+ });
174
+ </script>
175
+ <?php
176
+ }
177
+ }
178
+
179
+ public function screenLayoutSetOneColumn()
180
+ {
181
+ return 1;
182
+ }
183
+
184
+ public function wpmlRelatedActions()
185
+ {
186
+ // The actions below will be executed right after WPML is fully configured and loaded.
187
+ add_action('admin_head', array($this, 'removeUnneededMetaboxesFromPopups'), 10);
188
+ }
189
+
190
+ public function removeUnneededMetaboxesFromPopups()
191
+ {
192
+ if (isset($_GET['post_type']) && $_GET['post_type'] == SG_POPUP_POST_TYPE) {
193
+ $exlcudeTrPopupTypes = array(
194
+ 'image',
195
+ 'video',
196
+ 'iframe',
197
+ 'recentSales',
198
+ 'pdf'
199
+ );
200
+ $exlcudeTrPopupTypes = apply_filters('sgpbNoMcePopupTypes', $exlcudeTrPopupTypes);
201
+ if (isset($_GET['sgpb_type']) && in_array($_GET['sgpb_type'], $exlcudeTrPopupTypes)) {
202
+ remove_meta_box('icl_div', SG_POPUP_POST_TYPE, 'side');
203
+ }
204
+ }
205
+ }
206
+
207
+ public function deletePopup($newStatus, $oldStatus, $post)
208
+ {
209
+ $currentPostType = AdminHelper::getCurrentPostType();
210
+
211
+ if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
212
+ Functions::clearAllTransients();
213
+ }
214
+ }
215
+
216
+ public function showPreviewButtonAfterPopupPublish()
217
+ {
218
+ $currentPostType = AdminHelper::getCurrentPostType();
219
+ if (!empty($currentPostType) && ($currentPostType == SG_POPUP_POST_TYPE || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE || $currentPostType == SG_POPUP_TEMPLATE_POST_TYPE)) {
220
+ echo '<style>
221
+ #save-post {
222
+ display:none !important;
223
+ }
224
+ .subsubsub {
225
+ display:none !important;
226
+ }
227
+ .subsubsub.show {
228
+ display:block !important;
229
+ }
230
+ .search-box {
231
+ display:none !important;
232
+ }
233
+ .search-box.show {
234
+ display:block !important;
235
+ }
236
+ .tablenav-pages.no-pages {
237
+ display: block;
238
+ }
239
+ .tablenav-pages *:not(.subsubsub, .subsubsub *),
240
+ .tablenav-pages.no-pages *:not(.subsubsub, .subsubsub *),
241
+ .tablenav-pages.one-page *:not(.subsubsub, .subsubsub *) {
242
+ display: none;
243
+ }
244
+ </style>';
245
+ }
246
+ }
247
+
248
+ public function inactiveExtensionNotice()
249
+ {
250
+ $screen = '';
251
+ $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
252
+ if ($dontShowLicenseBanner) {
253
+ return $screen;
254
+ }
255
+ $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
256
+ $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
257
+ if (!$inactive) {
258
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
259
+ if ($hasInactiveExtensions) {
260
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
261
+ $inactive = 'inactive';
262
+ }
263
+
264
+ }
265
+ $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
266
+ $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
267
+ if (function_exists('get_current_screen')) {
268
+ $screen = get_current_screen();
269
+ $screenId = $screen->id;
270
+ if ($screenId == SGPB_POPUP_LICENSE_SCREEN) {
271
+ $partOfContent = '';
272
+ }
273
+ }
274
+
275
+ if ($hasInactiveExtensions && $inactive == 'inactive') {
276
+ $content = '';
277
+ ob_start();
278
+ ?>
279
+ <div id="welcome-panel" class="update-nag sgpb-extensions-notices sgpb-license-notice">
280
+ <div class="welcome-panel-content">
281
+ <b><?php _e('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN) ?></b>
282
+ <br>
283
+ <br>
284
+ <b><?php _e('You have activated Popup Builder extension(s). Please, don\'t forget to activate the license key(s) as well.', SG_POPUP_TEXT_DOMAIN) ?></b>
285
+ <b><?php echo $partOfContent; ?></b>
286
+ </div>
287
+ <button type="button" class="notice-dismiss" onclick="jQuery('.sgpb-license-notice').remove();"><span class="screen-reader-text"><?php _e('Dismiss this notice.', SG_POPUP_TEXT_DOMAIN) ?></span></button>
288
+ <span class="sgpb-dont-show-again-license-notice"><?php _e('Don\'t show again.', SG_POPUP_TEXT_DOMAIN); ?></span>
289
+ </div>
290
+ <?php
291
+ $content = ob_get_clean();
292
+
293
+ echo $content;
294
+ return true;
295
+ }
296
+ }
297
+
298
+ public function hidePublishingActions() {
299
+ $currentPostType = AdminHelper::getCurrentPostType();
300
+ if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
301
+ return false;
302
+ }
303
+
304
+ echo '<style>
305
+ #misc-publishing-actions .edit-post-status,
306
+ #misc-publishing-actions .edit-timestamp,
307
+ #misc-publishing-actions .edit-visibility {
308
+ display:none !important;
309
+ }
310
+ </style>';
311
+ }
312
+
313
+ public function hidePageBuilderEditButtons($postId = 0, $post = array())
314
+ {
315
+ $currentPostType = AdminHelper::getCurrentPostType();
316
+ if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
317
+ return false;
318
+ }
319
+ $excludedPopupTypesFromPageBuildersFunctionality = array(
320
+ 'image'
321
+ );
322
+
323
+ $excludedPopupTypesFromPageBuildersFunctionality = apply_filters('sgpbHidePageBuilderEditButtons', $excludedPopupTypesFromPageBuildersFunctionality);
324
+
325
+ $popupType = AdminHelper::getCurrentPopupType();
326
+ if (in_array($popupType, $excludedPopupTypesFromPageBuildersFunctionality)) {
327
+ echo '<style>
328
+ #elementor-switch-mode, #elementor-editor {
329
+ display:none !important;
330
+ }
331
+ </style>';
332
+ }
333
+ }
334
+
335
+ public function getBannerContent()
336
+ {
337
+ // right metabox banner content
338
+ $metaboxBannerContent = AdminHelper::getFileFromURL(SGPB_METABOX_BANNER_CRON_TEXT_URL);
339
+ update_option('sgpb-metabox-banner-remote-get', $metaboxBannerContent);
340
+
341
+ return true;
342
+ }
343
+
344
+ public function wpInit()
345
+ {
346
+
347
+ }
348
+
349
+ public function mainActionButtons($views)
350
+ {
351
+ require_once(SG_POPUP_VIEWS_PATH.'mainActionButtons.php');
352
+
353
+ return $views;
354
+ }
355
+
356
+ /**
357
+ * Loads the plugin language files
358
+ */
359
+ public function loadTextDomain()
360
+ {
361
+ $popupBuilderLangDir = SG_POPUP_BUILDER_PATH.'/languages/';
362
+ $popupBuilderLangDir = apply_filters('popupBuilderLanguagesDirectory', $popupBuilderLangDir);
363
+
364
+ $locale = apply_filters('sgpbPluginLocale', get_locale(), SG_POPUP_TEXT_DOMAIN);
365
+ $mofile = sprintf('%1$s-%2$s.mo', SG_POPUP_TEXT_DOMAIN, $locale);
366
+
367
+ $mofileLocal = $popupBuilderLangDir.$mofile;
368
+
369
+ if (file_exists($mofileLocal)) {
370
+ // Look in local /wp-content/plugins/popup-builder/languages/ folder
371
+ load_textdomain(SG_POPUP_TEXT_DOMAIN, $mofileLocal);
372
+ }
373
+ else {
374
+ // Load the default language files
375
+ load_plugin_textdomain(SG_POPUP_TEXT_DOMAIN, false, $popupBuilderLangDir);
376
+ }
377
+
378
+ }
379
+
380
+ public function redirectFromPopupPage()
381
+ {
382
+ global $post;
383
+ $currentPostType = '';
384
+
385
+ if (is_object($post)) {
386
+ $currentPostType = @$post->post_type;
387
+ }
388
+ // in some themes global $post returns null
389
+ if (empty($currentPostType)) {
390
+ global $post_type;
391
+ $currentPostType = $post_type;
392
+ }
393
+ // for editing popup content via page builders on backend
394
+ if (!isset($_GET) || empty($_GET)) {
395
+ if (!is_admin() && SG_POPUP_POST_TYPE == $currentPostType && !is_preview()) {
396
+ // it's for seo optimization
397
+ status_header(301);
398
+ $homeURL = home_url();
399
+ wp_redirect($homeURL);
400
+ exit();
401
+ }
402
+ }
403
+ }
404
+
405
+ public function preGetPosts($query)
406
+ {
407
+ if (!is_admin() || !isset($_GET['post_type']) || $_GET['post_type'] != SG_POPUP_POST_TYPE) {
408
+ return false;
409
+ }
410
+
411
+ // change default order by id and desc
412
+ if (!isset($_GET['orderby'])) {
413
+ $query->set('orderby', 'ID');
414
+ $query->set('order', 'desc');
415
+ }
416
+ $query = apply_filters('sgpbPreGetPosts', $query);
417
+
418
+ return true;
419
+ }
420
+
421
+ public function pluginNotices()
422
+ {
423
+ if (function_exists('get_current_screen')) {
424
+ $screen = get_current_screen();
425
+ $screenId = $screen->id;
426
+ if ($screenId == 'edit-popupbuilder') {
427
+ $notificationsObj = new SGPBNotificationCenter();
428
+ echo $notificationsObj->displayNotifications();
429
+ }
430
+ }
431
+ $extensions = AdminHelper::getAllActiveExtensions();
432
+ $updated = get_option('sgpb_extensions_updated');
433
+
434
+ $content = '';
435
+
436
+ // if popup builder has the old version
437
+ if (!get_option('SG_POPUP_VERSION')) {
438
+ return $content;
439
+ }
440
+
441
+ $alertProblem = get_option('sgpb_alert_problems');
442
+ // for old users show alert about problems
443
+ if (!$alertProblem) {
444
+ echo AdminHelper::renderAlertProblem();
445
+ }
446
+
447
+ // Don't show the banner if there's not any extension of Popup Builder or if the user has clicked "don't show"
448
+ if (empty($extensions) || $updated) {
449
+ return $content;
450
+ }
451
+
452
+ ob_start();
453
+ ?>
454
+ <div id="welcome-panel" class="update-nag sgpb-extensions-notices">
455
+ <div class="welcome-panel-content">
456
+ <?php echo AdminHelper::renderExtensionsContent(); ?>
457
+ </div>
458
+ </div>
459
+ <?php
460
+ $content = ob_get_clean();
461
+
462
+ echo $content;
463
+ return true;
464
+ }
465
+
466
+ private function registerImporter()
467
+ {
468
+ require_once SG_POPUP_LIBS_PATH.'Importer.php';
469
+ $importer = new WP_Import();
470
+ register_importer(SG_POPUP_POST_TYPE, SG_POPUP_POST_TYPE, __('Importer', SG_POPUP_TEXT_DOMAIN), array($importer, 'dispatch'));
471
+ }
472
+
473
+ public function pluginLoaded()
474
+ {
475
+ $this->registerImporter();
476
+ $versionPopup = get_option('SG_POPUP_VERSION');
477
+ $convert = get_option('sgpbConvertToNewVersion');
478
+ $unsubscribeColumnFixed = get_option('sgpbUnsubscribeColumnFixed');
479
+ AdminHelper::makeRegisteredPluginsStaticPathsToDynamic();
480
+
481
+ if (!$unsubscribeColumnFixed) {
482
+ AdminHelper::addUnsubscribeColumn();
483
+ update_option('sgpbUnsubscribeColumnFixed', 1);
484
+ delete_option('sgpbUnsubscribeColumn');
485
+ }
486
+
487
+ if ($versionPopup && !$convert) {
488
+ update_option('sgpbConvertToNewVersion', 1);
489
+ ConvertToNewVersion::convert();
490
+ Installer::registerPlugin();
491
+ }
492
+ }
493
+
494
+ public function popupMediaButton()
495
+ {
496
+ if (!$this->mediaButton) {
497
+ $this->mediaButton = true;
498
+ self::enqueueScriptsForPageBuilders();
499
+ if (function_exists('get_current_screen')) {
500
+ $screen = get_current_screen();
501
+ if (!empty($screen)) {
502
+ echo new MediaButton();
503
+ }
504
+ }
505
+ }
506
+ }
507
+
508
+ public function editorButton($plugins)
509
+ {
510
+ if (empty($this->mediaButton)) {
511
+ $this->mediaButton = true;
512
+ add_action('admin_footer', function() {
513
+ self::enqueueScriptsForPageBuilders();
514
+ echo new MediaButton(false);
515
+ });
516
+ }
517
+
518
+ return $plugins;
519
+ }
520
+
521
+ public static function enqueueScriptsForPageBuilders()
522
+ {
523
+ require_once(ABSPATH.'wp-admin/includes/screen.php');
524
+ global $post;
525
+ if (function_exists('get_current_screen')) {
526
+ $screen = get_current_screen();
527
+ if ((!empty($screen->id) && $screen->id == SG_POPUP_POST_TYPE) || !empty($post)) {
528
+ if (!isset($_GET['fl_builder'])) {
529
+ Javascript::enqueueScripts('post-new.php');
530
+ Style::enqueueStyles('post-new.php');
531
+ }
532
+ }
533
+ }
534
+ else if (isset($_GET['fl_builder'])) {
535
+ Javascript::enqueueScripts('post-new.php');
536
+ Style::enqueueStyles('post-new.php');
537
+ }
538
+ }
539
+
540
+ public function userRolesCaps()
541
+ {
542
+ $userSavedRoles = get_option('sgpb-user-roles');
543
+
544
+ if (!$userSavedRoles) {
545
+ $userSavedRoles = array('administrator');
546
+ }
547
+ else {
548
+ array_push($userSavedRoles, 'administrator');
549
+ }
550
+
551
+ foreach ($userSavedRoles as $theRole) {
552
+ $role = get_role($theRole);
553
+ if (empty($role)) {
554
+ continue;
555
+ }
556
+
557
+ $role->add_cap('read');
558
+ $role->add_cap('read_post');
559
+ $role->add_cap('read_private_sgpb_popups');
560
+ $role->add_cap('edit_sgpb_popup');
561
+ $role->add_cap('edit_sgpb_popups');
562
+ $role->add_cap('edit_others_sgpb_popups');
563
+ $role->add_cap('edit_published_sgpb_popups');
564
+ $role->add_cap('publish_sgpb_popups');
565
+ $role->add_cap('delete_sgpb_popups');
566
+ $role->add_cap('delete_published_posts');
567
+ $role->add_cap('delete_others_sgpb_popups');
568
+ $role->add_cap('delete_private_sgpb_popups');
569
+ $role->add_cap('delete_private_sgpb_popup');
570
+ $role->add_cap('delete_published_sgpb_popups');
571
+
572
+ // For popup builder sub-menus and terms
573
+ $role->add_cap('sgpb_manage_options');
574
+ $role->add_cap('manage_popup_terms');
575
+ $role->add_cap('manage_popup_categories_terms');
576
+ $role = apply_filters('sgpbUserRoleCap', $role);
577
+ }
578
+
579
+ return true;
580
+ }
581
+
582
+ public function pluginActivated()
583
+ {
584
+ if (!get_option('sgpbActivateExtensions') && SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
585
+ $obj = new PopupExtensionActivator();
586
+ $obj->activate();
587
+ update_option('sgpbActivateExtensions', 1);
588
+ }
589
+ }
590
+
591
+ public function popupShortcode($args, $content)
592
+ {
593
+ if (empty($args) || empty($args['id'])) {
594
+ return $content;
595
+ }
596
+
597
+ $oldShortcode = isset($args['event']) && $args['event'] === 'onload';
598
+ $isInherit = isset($args['event']) && $args['event'] == 'inherit';
599
+ $event = '';
600
+
601
+ $shortcodeContent = '';
602
+ $argsId = $popupId = (int)$args['id'];
603
+
604
+ // for old popups
605
+ if (function_exists('sgpb\sgpGetCorrectPopupId')) {
606
+ $popupId = sgpGetCorrectPopupId($popupId);
607
+ }
608
+
609
+ $popup = SGPopup::find($popupId);
610
+ $popup = apply_filters('sgpbShortCodePopupObj', $popup);
611
+
612
+ $event = preg_replace('/on/', '', @$args['event']);
613
+ // when popup does not exists or popup post status it's not publish ex when popup in trash
614
+ if (empty($popup) || (!is_object($popup) && $popup != 'publish')) {
615
+ return $content;
616
+ }
617
+
618
+ $isActive = $popup->isActive();
619
+ if (!$isActive) {
620
+ return $content;
621
+ }
622
+
623
+ $alreadySavedEvents = $popup->getEvents();
624
+ $loadableMode = $popup->getLoadableModes();
625
+
626
+ if (!isset($args['event']) && isset($args['insidepopup'])) {
627
+ unset($args['insidepopup']);
628
+ $event = 'insideclick';
629
+ $insideShortcodeKey = $popupId.$event;
630
+
631
+ // for prevent infinity chain
632
+ if (is_array($this->insideShortcodes) && in_array($insideShortcodeKey, $this->insideShortcodes)) {
633
+ $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
634
+
635
+ return $shortcodeContent;
636
+ }
637
+ $this->insideShortcodes[] = $insideShortcodeKey;
638
+ }
639
+ // if no event attribute is set, or old shortcode
640
+ if (!isset($args['event']) || $oldShortcode || $isInherit) {
641
+ $loadableMode = $popup->getLoadableModes();
642
+ if (!empty($content)) {
643
+ $alreadySavedEvents = false;
644
+ }
645
+ // for old popup, after the update, there aren't any events
646
+ if (empty($alreadySavedEvents)) {
647
+ $event = '';
648
+ if (!empty($content)) {
649
+ $event = 'click';
650
+ }
651
+ if (!empty($args['event'])) {
652
+ $event = $args['event'];
653
+ }
654
+ $event = preg_replace('/on/', '', $event);
655
+ $popup->setEvents(array($event));
656
+ }
657
+ if (empty($loadableMode)) {
658
+ $loadableMode = array();
659
+ }
660
+ $loadableMode['option_event'] = true;
661
+ }
662
+ else {
663
+ $event = $args['event'];
664
+ $event = preg_replace('/on/', '', $event);
665
+ $popup->setEvents(array($event));
666
+ }
667
+
668
+ $popup->setLoadableModes($loadableMode);
669
+ $scriptsLoader = new ScriptsLoader();
670
+ $loadablePopups = array($popup);
671
+ $groupObj = new PopupGroupFilter();
672
+ $groupObj->setPopups(array($popup));
673
+ $loadablePopups = $groupObj->filter();
674
+ $scriptsLoader->setLoadablePopups($loadablePopups);
675
+ $scriptsLoader->loadToFooter();
676
+
677
+ if (!empty($content)) {
678
+ $matches = SGPopup::getPopupShortcodeMatchesFromContent($content);
679
+ if (!empty($matches)) {
680
+ foreach ($matches[0] as $key => $value) {
681
+ $attrs = shortcode_parse_atts($matches[3][$key]);
682
+ if (empty($attrs['id'])) {
683
+ continue;
684
+ }
685
+ $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $attrs['id'], $attrs['event'], $attrs);
686
+ break;
687
+ }
688
+ }
689
+ }
690
+
691
+ if (isset($event) && $event != 'onload' && !empty($content)) {
692
+ $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
693
+ }
694
+ $shortcodeContent = apply_filters('sgpbPopupShortCodeContent', $shortcodeContent);
695
+
696
+ return do_shortcode($shortcodeContent);
697
+ }
698
+
699
+ public function deleteSubscribersWithPopup($postId)
700
+ {
701
+ global $post_type;
702
+
703
+ if ($post_type == SG_POPUP_POST_TYPE) {
704
+ AdminHelper::deleteSubscriptionPopupSubscribers($postId);
705
+ }
706
+ }
707
+
708
+ public function cronAddMinutes($schedules)
709
+ {
710
+ $schedules['sgpb_newsletter_send_every_minute'] = array(
711
+ 'interval' => SGPB_CRON_REPEAT_INTERVAL * 60,
712
+ 'display' => __('Once Every Minute', SG_POPUP_TEXT_DOMAIN)
713
+ );
714
+
715
+ $schedules['sgpb_banners'] = array(
716
+ 'interval' => SGPB_TRANSIENT_TIMEOUT_WEEK,
717
+ 'display' => __('Once Every Week', SG_POPUP_TEXT_DOMAIN)
718
+ );
719
+
720
+ $schedules = apply_filters('sgpbCronTimeoutSettings', $schedules);
721
+
722
+ return $schedules;
723
+ }
724
+
725
+ public function newsletterSendEmail()
726
+ {
727
+ global $wpdb;
728
+ $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
729
+
730
+ if (empty($newsletterOptions)) {
731
+ wp_clear_scheduled_hook('sgpb_send_newsletter');
732
+ }
733
+ $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
734
+ $subscriptionFormTitle = get_the_title($subscriptionFormId);
735
+ $emailsInFlow = (int)$newsletterOptions['emailsInFlow'];
736
+ $mailSubject = $newsletterOptions['newsletterSubject'];
737
+ $fromEmail = $newsletterOptions['fromEmail'];
738
+ $emailMessage = $newsletterOptions['messageBody'];
739
+
740
+ $allAvailableShortcodes = array();
741
+ $allAvailableShortcodes['patternFirstName'] = '/\[First name]/';
742
+ $allAvailableShortcodes['patternLastName'] = '/\[Last name]/';
743
+ $allAvailableShortcodes['patternBlogName'] = '/\[Blog name]/';
744
+ $allAvailableShortcodes['patternUserName'] = '/\[User name]/';
745
+ $allAvailableShortcodes['patternUnsubscribe'] = '';
746
+
747
+ $pattern = "/\[(\[?)(Unsubscribe)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/";
748
+ preg_match($pattern, $emailMessage, $matches);
749
+ $title = __('Unsubscribe', SG_POPUP_TEXT_DOMAIN);
750
+ if ($matches) {
751
+ $patternUnsubscribe = $matches[0];
752
+ // If user didn't change anything inside the [unsubscribe] shortcode $matches[2] will be equal to 'Unsubscribe'
753
+ if ($matches[2] == 'Unsubscribe') {
754
+ $pattern = '/\s(\w+?)="(.+?)"]/';
755
+ preg_match($pattern, $matches[0], $matchesTitle);
756
+ if (!empty($matchesTitle[2])) {
757
+ $title = AdminHelper::removeAllNonPrintableCharacters($matchesTitle[2], 'Unsubscribe');
758
+ }
759
+ }
760
+ $allAvailableShortcodes['patternUnsubscribe'] = $patternUnsubscribe;
761
+ }
762
+
763
+ // When email is not valid we don't continue
764
+ if (!preg_match('/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/', $fromEmail)) {
765
+ wp_clear_scheduled_hook('sgpb_send_newsletter');
766
+ return false;
767
+ }
768
+
769
+ $selectionQuery = 'SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
770
+ $selectionQuery = apply_filters('sgpbUserSelectionQuery', $selectionQuery);
771
+ $sql = $wpdb->prepare($selectionQuery .' and subscriptionType = %d limit 1', $subscriptionFormId);
772
+
773
+ $result = $wpdb->get_row($sql, ARRAY_A);
774
+ $currentStateEmailId = (int)$result['id'];
775
+ $getTotalSql = $wpdb->prepare('SELECT count(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE unsubscribed = 0 and subscriptionType = %d', $subscriptionFormId);
776
+ $totalSubscribers = $wpdb->get_var($getTotalSql);
777
+
778
+ // $currentStateEmailId == 0 when all emails status = 1
779
+ if ($currentStateEmailId == 0) {
780
+ // Clear schedule hook
781
+ $headers = 'MIME-Version: 1.0'."\r\n";
782
+ $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n";
783
+ $successTotal = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
784
+ if (!$successTotal) {
785
+ $successTotal = 0;
786
+ }
787
+ $failedTotal = $totalSubscribers - $successTotal;
788
+
789
+ $emailMessageCustom = __('Your mail list %s delivered successfully!
790
+ %d of the %d emails succeeded, %d failed.
791
+ For more details, please download log file inside the plugin.
792
+ This email was generated via Popup Builder plugin.', SG_POPUP_TEXT_DOMAIN);
793
+ $emailMessageCustom = sprintf($emailMessageCustom, $subscriptionFormTitle, $successTotal, $totalSubscribers, $failedTotal);
794
+
795
+ wp_mail($fromEmail, $subscriptionFormTitle.' list has been successfully delivered!', $emailMessageCustom, $headers);
796
+ delete_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
797
+ wp_clear_scheduled_hook('sgpb_send_newsletter');
798
+ return;
799
+ }
800
+
801
+ $getAllDataSql = 'SELECT id, firstName, lastName, email FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
802
+ $getAllDataSql = apply_filters('sgpbUserSelectionQuery', $getAllDataSql);
803
+ $getAllDataSql = $wpdb->prepare($getAllDataSql .' and id >= %d and subscriptionType = %s limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
804
+ $subscribers = $wpdb->get_results($getAllDataSql, ARRAY_A);
805
+
806
+ $subscribers = apply_filters('sgpNewsletterSendingSubscribers', $subscribers);
807
+
808
+ $blogInfo = get_bloginfo();
809
+ $headers = array(
810
+ 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
811
+ 'MIME-Version: 1.0' ,
812
+ 'Content-type: text/html; charset=UTF-8'
813
+ );
814
+
815
+ foreach ($subscribers as $subscriber) {
816
+ $replacementId = $subscriber['id'];
817
+ $allAvailableShortcodes = apply_filters('sgpbNewsletterShortcodes', $allAvailableShortcodes, $subscriptionFormId, $replacementId);
818
+ $replacementFirstName = $subscriber['firstName'];
819
+ $replacementLastName = $subscriber['lastName'];
820
+ $replacementBlogName = $newsletterOptions['blogname'];
821
+ $replacementUserName = $newsletterOptions['username'];
822
+ $replacementEmail = $subscriber['email'];
823
+ $replacementUnsubscribe = get_home_url();
824
+ $replacementUnsubscribe .= '?sgpbUnsubscribe='.md5($replacementId.$replacementEmail);
825
+ $replacementUnsubscribe .= '&email='.$subscriber['email'];
826
+ $replacementUnsubscribe .= '&popup='.$subscriptionFormId;
827
+ $replacementUnsubscribe = '<br><a href="'.$replacementUnsubscribe.'">'.$title.'</a>';
828
+
829
+ // Replace First name and Last name from email message
830
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternFirstName'], $replacementFirstName, $emailMessage);
831
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternLastName'], $replacementLastName, $emailMessageCustom);
832
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternBlogName'], $replacementBlogName, $emailMessageCustom);
833
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternUserName'], $replacementUserName, $emailMessageCustom);
834
+ $emailMessageCustom = str_replace($allAvailableShortcodes['patternUnsubscribe'], $replacementUnsubscribe, $emailMessageCustom);
835
+ if (!empty($allAvailableShortcodes['extraShortcodesWithValues'])) {
836
+ $customFields = $allAvailableShortcodes['extraShortcodesWithValues'];
837
+ foreach ($customFields as $customFieldKey => $customFieldValue) {
838
+ $finalShortcode = '/\['.$customFieldKey.']/';
839
+ $emailMessageCustom = preg_replace($finalShortcode, $customFieldValue, $emailMessageCustom);
840
+ }
841
+ }
842
+ $emailMessageCustom = stripslashes($emailMessageCustom);
843
+
844
+ $emailMessageCustom = apply_filters('sgpNewsletterSendingMessage', $emailMessageCustom);
845
+ $mailStatus = wp_mail($subscriber['email'], $mailSubject, $emailMessageCustom, $headers);
846
+ if (!$mailStatus) {
847
+ $errorLogSql = $wpdb->prepare('INSERT INTO '. $wpdb->prefix .SGPB_SUBSCRIBERS_ERROR_TABLE_NAME.' (`popupType`, `email`, `date`) VALUES (%s, %s, %s)', $subscriptionFormId, $subscriber['email'], date('Y-m-d H:i'));
848
+ $wpdb->query($errorLogSql);
849
+ continue;
850
+ }
851
+
852
+ $successCount = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
853
+ if (!$successCount) {
854
+ update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, 1);
855
+ }
856
+ else {
857
+ update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, ++$successCount);
858
+ }
859
+ }
860
+ // Update the status of all the sent mails
861
+ $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 1 where id >= %d and subscriptionType = %d limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
862
+ $wpdb->query($updateStatusQuery);
863
+ }
864
+
865
+ private function unsubscribe($params = array())
866
+ {
867
+ AdminHelper::deleteUserFromSubscribers($params);
868
+ }
869
+
870
+ public function enqueuePopupBuilderScripts()
871
+ {
872
+ // for old popups
873
+ if (get_option('SG_POPUP_VERSION')) {
874
+ ConvertToNewVersion::saveCustomInserted();
875
+ }
876
+
877
+ $popupLoaderObj = PopupLoader::instance();
878
+ if (is_object($popupLoaderObj)) {
879
+ $popupLoaderObj->loadPopups();
880
+ }
881
+ }
882
+
883
+ public function adminLoadPopups($hook)
884
+ {
885
+ $allowedPages = array();
886
+ $allowedPages = apply_filters('sgpbAdminLoadedPages', $allowedPages);
887
+
888
+ if (!empty($allowedPages) && is_array($allowedPages) && in_array($hook, $allowedPages)) {
889
+ $scriptsLoader = new ScriptsLoader();
890
+ $scriptsLoader->setIsAdmin(true);
891
+ $scriptsLoader->loadToFooter();
892
+ }
893
+ }
894
+
895
+ public function postTypeInit()
896
+ {
897
+ if (isset($_POST['sgpb-is-preview']) && $_POST['sgpb-is-preview'] == 1) {
898
+ $postId = $_POST['post_ID'];
899
+ $post = get_post($postId);
900
+ $this->savePost($postId, $post, false);
901
+ }
902
+ $adminUrl = admin_url();
903
+
904
+ if (isset($_GET['page']) && $_GET['page'] == 'PopupBuilder') {
905
+ _e('<span>Popup Builder plugin has been successfully updated. Please <a href="'.esc_attr($adminUrl).'edit.php?post_type='.SG_POPUP_POST_TYPE.'">click here</a> to go to the new Dashboard of the plugin.</span>', SG_POPUP_TEXT_DOMAIN);
906
+ wp_die();
907
+ }
908
+
909
+ $unsubscribeArgs = $this->collectUnsubscriberArgs();
910
+ if (!empty($unsubscribeArgs)) {
911
+ $this->unsubscribe($unsubscribeArgs);
912
+ }
913
+
914
+ AdminHelper::removeUnnecessaryCodeFromPopups();
915
+
916
+ $this->customPostTypeObj = new RegisterPostType();
917
+ }
918
+
919
+ public function collectUnsubscriberArgs()
920
+ {
921
+ if (!isset($_GET['sgpbUnsubscribe'])) {
922
+ return false;
923
+ }
924
+ $args = array();
925
+ if (isset($_GET['sgpbUnsubscribe'])) {
926
+ $args['token'] = $_GET['sgpbUnsubscribe'];
927
+ }
928
+ if (isset($_GET['email'])) {
929
+ $args['email'] = $_GET['email'];
930
+ }
931
+ if (isset($_GET['popup'])) {
932
+ $args['popup'] = $_GET['popup'];
933
+ }
934
+
935
+ return $args;
936
+ }
937
+
938
+ public function addSubMenu()
939
+ {
940
+ // We need to check license keys and statuses before adding new menu "License" item
941
+ new Updates();
942
+
943
+ $this->customPostTypeObj->addSubMenu();
944
+ }
945
+
946
+ public function supportLinks()
947
+ {
948
+ if (SGPB_POPUP_PKG == SGPB_POPUP_PKG_FREE) {
949
+ if (method_exists($this->customPostTypeObj, 'supportLinks')) {
950
+ $this->customPostTypeObj->supportLinks();
951
+ }
952
+ }
953
+ }
954
+
955
+ public function popupMetaboxes()
956
+ {
957
+ $this->customPostTypeObj->addPopupMetaboxes();
958
+ }
959
+
960
+ public function savePost($postId = 0, $post = array(), $update = false)
961
+ {
962
+ if ($post->post_type !== SG_POPUP_POST_TYPE) {
963
+ return;
964
+ }
965
+ $allowToAction = AdminHelper::userCanAccessTo();
966
+ Functions::clearAllTransients();
967
+ $postData = SGPopup::parsePopupDataFromData($_POST);
968
+ $saveMode = '';
969
+ $postData['sgpb-post-id'] = $postId;
970
+ // If preview mode
971
+ if (isset($postData['sgpb-is-preview']) && $postData['sgpb-is-preview'] == 1) {
972
+ $saveMode = '_preview';
973
+ SgpbPopupConfig::popupTypesInit();
974
+ SgpbDataConfig::init();
975
+ // published popup
976
+ if (empty($post)) {
977
+ global $post;
978
+ $postId = $post->ID;
979
+ }
980
+ if ($post->post_status != 'draft') {
981
+ $posts = array();
982
+ $popupContent = $post->post_content;
983
+
984
+ $query = new WP_Query(
985
+ array(
986
+ 'post_parent' => $postId,
987
+ 'posts_per_page' => - 1,
988
+ 'post_type' => 'revision',
989
+ 'post_status' => 'inherit'
990
+ )
991
+ );
992
+ $query = apply_filters('sgpbSavePostQuery', $query);
993
+
994
+ while ($query->have_posts()) {
995
+ $query->the_post();
996
+ if (empty($posts)) {
997
+ $posts[] = $post;
998
+ }
999
+ }
1000
+ if (!empty($posts[0])) {
1001
+ $popup = $posts[0];
1002
+ $popupContent = $popup->post_content;
1003
+ }
1004
+ }
1005
+ }
1006
+
1007
+
1008
+ if (empty($post)) {
1009
+ $saveMode = '';
1010
+ }
1011
+
1012
+ if ($post->post_status == 'draft') {
1013
+ $saveMode = '_preview';
1014
+ }
1015
+
1016
+ /* In preview mode saveMode should be true*/
1017
+ if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
1018
+ if (!$allowToAction) {
1019
+ wp_redirect(get_home_url());
1020
+ exit();
1021
+ }
1022
+ if (!empty($postData['sgpb-type'])) {
1023
+ $popupType = $postData['sgpb-type'];
1024
+ $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
1025
+ $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
1026
+ require_once($popupClassPath.$popupClassName.'.php');
1027
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
1028
+
1029
+ $popupClassName::create($postData, $saveMode, 1);
1030
+ }
1031
+ }
1032
+ else {
1033
+ $content = get_post_field('post_content', $postId);
1034
+ SGPopup::deletePostCustomInsertedData($postId);
1035
+ SGPopup::deletePostCustomInsertedEvents($postId);
1036
+ /*We detect all the popups that were inserted as a custom ones, in the content.*/
1037
+ SGPopup::savePopupsFromContentClasses($content, $post);
1038
+ }
1039
+ }
1040
+
1041
+ /**
1042
+ * Check Popup is satisfy for popup condition
1043
+ *
1044
+ * @param array $args
1045
+ *
1046
+ * @return array
1047
+ *
1048
+ *@since 1.0.0
1049
+ *
1050
+ */
1051
+ public function conditionsSatisfy($args = array())
1052
+ {
1053
+ if (isset($args['status']) && $args['status'] === false) {
1054
+ return $args;
1055
+ }
1056
+ $args['status'] = PopupChecker::checkOtherConditionsActions($args);
1057
+
1058
+ return $args;
1059
+ }
1060
+
1061
+ public function popupsTableColumnsValues($column, $postId)
1062
+ {
1063
+ $postId = (int)$postId;// Convert to int for security reasons
1064
+ global $post_type;
1065
+ if ($postId) {
1066
+ $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
1067
+ $popup = SGPopup::find($postId, $args);
1068
+ }
1069
+
1070
+ if (empty($popup) && $post_type == SG_POPUP_POST_TYPE) {
1071
+ return false;
1072
+ }
1073
+
1074
+ if ($column == 'shortcode') {
1075
+ echo '<input type="text" onfocus="this.select();" readonly value="[sg_popup id='.$postId.']" class="large-text code">';
1076
+ }
1077
+ if ($column == 'className') {
1078
+ echo '<input type="text" onfocus="this.select();" readonly value="sg-popup-id-'.esc_attr($postId).'" class="large-text code">';
1079
+ }
1080
+ else if ($column == 'counter') {
1081
+ $count = $popup->getPopupOpeningCountById($postId);
1082
+ echo '<div ><span>'.$count.'</span>'.'<input onclick="SGPBBackend.resetCount('.$postId.', true);" type="button" name="" class="sgpb-btn sgpb-btn-dark-outline" value="'.__('reset', SG_POPUP_TEXT_DOMAIN).'"></div>';
1083
+ }
1084
+ else if ($column == 'type') {
1085
+ global $SGPB_POPUP_TYPES;
1086
+ $type = $popup->getType();
1087
+ if (isset($SGPB_POPUP_TYPES['typeLabels'][$type])) {
1088
+ $type = $SGPB_POPUP_TYPES['typeLabels'][$type];
1089
+ }
1090
+ echo $type;
1091
+ }
1092
+ else if ($column == 'onOff') {
1093
+ $popupPostStatus = get_post_status($postId);
1094
+ if ($popupPostStatus == 'publish' || $popupPostStatus == 'draft') {
1095
+ $isActive = $popup->getOptionValue('sgpb-is-active', true);
1096
+ }
1097
+ $checked = isset($isActive) && $isActive ? 'checked' : '';
1098
+ echo '<label class="sgpb-switch">
1099
+ <input class="sg-switch-checkbox sgpb-popup-status-js" value="1" data-switch-id="'.$postId.'" type="checkbox" '.$checked.'>
1100
+ <div class="sgpb-slider sgpb-round"></div>
1101
+ </label>';
1102
+ }
1103
+ else if ($column == 'sgpbIsRandomEnabled') {
1104
+ $showValues = apply_filters('sgpbAddRandomTableColumnValues', $postId);
1105
+ echo $showValues;
1106
+ }
1107
+ else if ($column == 'options') {
1108
+ $cloneUrl = AdminHelper::popupGetClonePostLink($postId);
1109
+ $actionButtons = '<div class="icon icon_blue">
1110
+ <img src="'.SG_POPUP_PUBLIC_URL.'icons/iconEdit.png" alt="Edit" class="icon_edit" onclick="location.href=\''.get_edit_post_link($postId).'\'">
1111
+ </div>';
1112
+ $actionButtons .= '<div class="icon icon_blue">
1113
+ <img src="'.SG_POPUP_PUBLIC_URL.'icons/iconClone.png" alt="Clone" class="icon_clone" onclick="location.href=\''.$cloneUrl.'\'">
1114
+ </div>';
1115
+ $actionButtons .= '<div class="icon icon_pink">
1116
+ <img src="'.SG_POPUP_PUBLIC_URL.'icons/recycle-bin.svg" alt="Remove" class="icon_remove" onclick="location.href=\''.get_delete_post_link($postId).'\'">
1117
+ </div>';
1118
+
1119
+ echo $actionButtons;
1120
+ }
1121
+ }
1122
+
1123
+ /*
1124
+ * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
1125
+ * then redirects to the post list
1126
+ */
1127
+ public function popupSaveAsNew($status = '')
1128
+ {
1129
+ if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'popupSaveAsNew' == $_REQUEST['action']))) {
1130
+ wp_die(esc_html__('No post to duplicate has been supplied!', SG_POPUP_TEXT_DOMAIN));
1131
+ }
1132
+ // Get the original post
1133
+ $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
1134
+
1135
+ check_admin_referer('duplicate-post_'.$id);
1136
+
1137
+ $post = get_post($id);
1138
+
1139
+ // Copy the post and insert it
1140
+ if (isset($post) && $post != null) {
1141
+ $newId = $this->popupCreateDuplicate($post, $status);
1142
+ $postType = $post->post_type;
1143
+
1144
+ if ($status == '') {
1145
+ $sendBack = wp_get_referer();
1146
+ if (!$sendBack ||
1147
+ strpos($sendBack, 'post.php') !== false ||
1148
+ strpos($sendBack, 'post-new.php') !== false) {
1149
+ if ('attachment' == $postType) {
1150
+ $sendBack = admin_url('upload.php');
1151
+ }
1152
+ else {
1153
+ $sendBack = admin_url('edit.php');
1154
+ if (!empty($postType)) {
1155
+ $sendBack = add_query_arg('post_type', $postType, $sendBack);
1156
+ }
1157
+ }
1158
+ }
1159
+ else {
1160
+ $sendBack = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'cloned', 'ids'), $sendBack);
1161
+ }
1162
+ // Redirect to the post list screen
1163
+ wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), $sendBack));
1164
+ }
1165
+ else {
1166
+ // Redirect to the edit screen for the new draft post
1167
+ wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), admin_url('post.php?action=edit&post='.$newId)));
1168
+ }
1169
+ exit;
1170
+
1171
+ }
1172
+ else {
1173
+ wp_die(esc_html__('Copy creation failed, could not find original:', SG_POPUP_TEXT_DOMAIN).' '.htmlspecialchars($id));
1174
+ }
1175
+ }
1176
+
1177
+ /**
1178
+ * Create a duplicate from a post
1179
+ */
1180
+ public function popupCreateDuplicate($post, $status = '', $parent_id = '')
1181
+ {
1182
+ $newPostStatus = (empty($status))? $post->post_status: $status;
1183
+
1184
+ if ($post->post_type != 'attachment') {
1185
+ $title = $post->post_title;
1186
+ if ($title == '') {
1187
+ // empty title
1188
+ $title = __('(no title) (clone)');
1189
+ }
1190
+ else {
1191
+ $title .= ' '.__('(clone)');
1192
+ }
1193
+
1194
+ if ('publish' == $newPostStatus || 'future' == $newPostStatus) {
1195
+ // check if the user has the right capability
1196
+ if (is_post_type_hierarchical($post->post_type)) {
1197
+ if (!current_user_can('publish_pages')) {
1198
+ $newPostStatus = 'pending';
1199
+ }
1200
+ }
1201
+ else {
1202
+ if (!current_user_can('publish_posts')) {
1203
+ $newPostStatus = 'pending';
1204
+ }
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ $newPostAuthor = wp_get_current_user();
1210
+ $newPostAuthorId = $newPostAuthor->ID;
1211
+ // check if the user has the right capability
1212
+ if (is_post_type_hierarchical($post->post_type)) {
1213
+ if (current_user_can('edit_others_pages')) {
1214
+ $newPostAuthorId = $post->post_author;
1215
+ }
1216
+ }
1217
+ else {
1218
+ if (current_user_can('edit_others_posts')) {
1219
+ $newPostAuthorId = $post->post_author;
1220
+ }
1221
+ }
1222
+
1223
+ $newPost = array(
1224
+ 'menu_order' => $post->menu_order,
1225
+ 'comment_status' => $post->comment_status,
1226
+ 'ping_status' => $post->ping_status,
1227
+ 'post_author' => $newPostAuthorId,
1228
+ 'post_content' => $post->post_content,
1229
+ 'post_content_filtered' => $post->post_content_filtered,
1230
+ 'post_excerpt' => $post->post_excerpt,
1231
+ 'post_mime_type' => $post->post_mime_type,
1232
+ 'post_parent' => $newPostParent = empty($parent_id)? $post->post_parent : $parent_id,
1233
+ 'post_password' => $post->post_password,
1234
+ 'post_status' => $newPostStatus,
1235
+ 'post_title' => $title,
1236
+ 'post_type' => $post->post_type,
1237
+ );
1238
+
1239
+ $newPost['post_date'] = $newPostDate = $post->post_date;
1240
+ $newPost['post_date_gmt'] = get_gmt_from_date($newPostDate);
1241
+ $newPostId = wp_insert_post(wp_slash($newPost));
1242
+
1243
+ // If the copy is published or scheduled, we have to set a proper slug.
1244
+ if ($newPostStatus == 'publish' || $newPostStatus == 'future') {
1245
+ $postName = $post->post_name;
1246
+ $postName = wp_unique_post_slug($postName, $newPostId, $newPostStatus, $post->post_type, $newPostParent);
1247
+
1248
+ $newPost = array();
1249
+ $newPost['ID'] = $newPostId;
1250
+ $newPost['post_name'] = $postName;
1251
+
1252
+ // Update the post into the database
1253
+ wp_update_post(wp_slash($newPost));
1254
+ }
1255
+
1256
+ // If you have written a plugin which uses non-WP database tables to save
1257
+ // information about a post you can hook this action to dupe that data.
1258
+ if ($post->post_type == 'page' || is_post_type_hierarchical($post->post_type)) {
1259
+ do_action('dp_duplicate_page', $newPostId, $post, $status);
1260
+ }
1261
+ else {
1262
+ do_action('sgpb_duplicate_post', $newPostId, $post, $status);
1263
+ }
1264
+
1265
+ delete_post_meta($newPostId, '_sgpb_original');
1266
+ add_post_meta($newPostId, '_sgpb_original', $post->ID);
1267
+
1268
+ return $newPostId;
1269
+ }
1270
+
1271
+ /**
1272
+ * Copy the meta information of a post to another post
1273
+ */
1274
+ public function popupCopyPostMetaInfo($newId, $post)
1275
+ {
1276
+ $postMetaKeys = get_post_custom_keys($post->ID);
1277
+ $metaBlacklist = '';
1278
+
1279
+ if (empty($postMetaKeys) || !is_array($postMetaKeys)) {
1280
+ return;
1281
+ }
1282
+ $metaBlacklist = explode(',', $metaBlacklist);
1283
+ $metaBlacklist = array_filter($metaBlacklist);
1284
+ $metaBlacklist = array_map('trim', $metaBlacklist);
1285
+ $metaBlacklist[] = '_edit_lock';
1286
+ $metaBlacklist[] = '_edit_last';
1287
+ $metaBlacklist[] = '_wp_page_template';
1288
+ $metaBlacklist[] = '_thumbnail_id';
1289
+
1290
+ $metaBlacklist = apply_filters('duplicate_post_blacklist_filter' , $metaBlacklist);
1291
+
1292
+ $metaBlacklistString = '('.implode(')|(',$metaBlacklist).')';
1293
+ $metaKeys = array();
1294
+
1295
+ if (strpos($metaBlacklistString, '*') !== false) {
1296
+ $metaBlacklistString = str_replace(array('*'), array('[a-zA-Z0-9_]*'), $metaBlacklistString);
1297
+
1298
+ foreach ($postMetaKeys as $metaKey) {
1299
+ if (!preg_match('#^'.$metaBlacklistString.'$#', $metaKey)) {
1300
+ $metaKeys[] = $metaKey;
1301
+ }
1302
+ }
1303
+ }
1304
+ else {
1305
+ $metaKeys = array_diff($postMetaKeys, $metaBlacklist);
1306
+ }
1307
+
1308
+ $metaKeys = apply_filters('duplicate_post_meta_keys_filter', $metaKeys);
1309
+
1310
+ foreach ($metaKeys as $metaKey) {
1311
+ $metaValues = get_post_custom_values($metaKey, $post->ID);
1312
+ foreach ($metaValues as $metaValue) {
1313
+ $metaValue = maybe_unserialize($metaValue);
1314
+ if (is_array($metaValue)) {
1315
+ $metaValue['sgpb-post-id'] = $newId;
1316
+ }
1317
+ add_post_meta($newId, $metaKey, $this->popupWpSlash($metaValue));
1318
+ }
1319
+ }
1320
+ }
1321
+
1322
+ public function popupAddSlashesDeep($value)
1323
+ {
1324
+ if (function_exists('map_deep')) {
1325
+ return map_deep($value, array($this, 'popupAddSlashesToStringsOnly'));
1326
+ }
1327
+ else {
1328
+ return wp_slash($value);
1329
+ }
1330
+ }
1331
+
1332
+ public function popupAddSlashesToStringsOnly($value)
1333
+ {
1334
+ return is_string($value) ? addslashes($value) : $value;
1335
+ }
1336
+
1337
+ public function popupWpSlash($value)
1338
+ {
1339
+ return $this->popupAddSlashesDeep($value);
1340
+ }
1341
+
1342
+ public function removePostPermalink($args)
1343
+ {
1344
+ global $post_type;
1345
+
1346
+ if ($post_type == SG_POPUP_POST_TYPE && is_admin()) {
1347
+ // hide permalink for popupbuilder post type
1348
+ return '';
1349
+ }
1350
+
1351
+ return $args;
1352
+ }
1353
+
1354
+ // remove link ( e.g.: (View post) ), from popup updated/published message
1355
+ public function popupPublishedMessage($messages)
1356
+ {
1357
+ global $post_type;
1358
+
1359
+ if ($post_type == SG_POPUP_POST_TYPE) {
1360
+ // post(popup) updated
1361
+ if (isset($messages['post'][1])) {
1362
+ $messages['post'][1] = __('Popup updated.', SG_POPUP_TEXT_DOMAIN);
1363
+ }
1364
+ // post(popup) published
1365
+ if (isset($messages['post'][6])) {
1366
+ $messages['post'][6] = __('Popup published.', SG_POPUP_TEXT_DOMAIN);
1367
+ }
1368
+ }
1369
+ $messages = apply_filters('sgpbPostUpdateMessage', $messages);
1370
+
1371
+ return $messages;
1372
+ }
1373
+
1374
+ public function getSubscribersCsvFile()
1375
+ {
1376
+ global $wpdb;
1377
+ $allowToAction = AdminHelper::userCanAccessTo();
1378
+ if (!$allowToAction) {
1379
+ wp_redirect(get_home_url());
1380
+ exit();
1381
+ }
1382
+
1383
+ $query = AdminHelper::subscribersRelatedQuery();
1384
+ if (isset($_GET['orderby']) && !empty($_GET['orderby'])) {
1385
+ if (isset($_GET['order']) && !empty($_GET['order'])) {
1386
+ $query .= ' ORDER BY '.esc_sql($_GET['orderby']).' '.esc_sql($_GET['order']);
1387
+ }
1388
+ }
1389
+ $content = '';
1390
+ $exportTypeQuery = '';
1391
+ $rows = array('first name', 'last name', 'email', 'date', 'popup');
1392
+ foreach ($rows as $value) {
1393
+ $content .= $value;
1394
+ if ($value != 'popup') {
1395
+ $content .= ',';
1396
+ }
1397
+ }
1398
+ $content .= "\n";
1399
+ $subscribers = $wpdb->get_results($query, ARRAY_A);
1400
+
1401
+ $subscribers = apply_filters('sgpbSubscribersCsv', $subscribers);
1402
+
1403
+ foreach($subscribers as $values) {
1404
+ foreach ($values as $key => $value) {
1405
+ $content .= $value;
1406
+ if ($key != 'subscriptionTitle') {
1407
+ $content .= ',';
1408
+ }
1409
+ }
1410
+ $content .= "\n";
1411
+ }
1412
+
1413
+ $content = apply_filters('sgpbSubscribersContent', $content);
1414
+
1415
+ header('Pragma: public');
1416
+ header('Expires: 0');
1417
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1418
+ header('Cache-Control: private', false);
1419
+ header('Content-Type: application/octet-stream');
1420
+ header('Content-Disposition: attachment; filename=subscribersList.csv;');
1421
+ header('Content-Transfer-Encoding: binary');
1422
+ echo $content;
1423
+ }
1424
+
1425
+ public function getSystemInfoFile()
1426
+ {
1427
+ $allowToAction = AdminHelper::userCanAccessTo();
1428
+ if (!$allowToAction) {
1429
+ return false;
1430
+ }
1431
+
1432
+ $content = AdminHelper::getSystemInfoText();
1433
+
1434
+ header('Pragma: public');
1435
+ header('Expires: 0');
1436
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1437
+ header('Cache-Control: private', false);
1438
+ header('Content-Type: application/octet-stream');
1439
+ header('Content-Disposition: attachment; filename=popupBuilderSystemInfo.txt;');
1440
+ header('Content-Transfer-Encoding: binary');
1441
+
1442
+ echo $content;
1443
+ }
1444
+
1445
+ public function saveSettings()
1446
+ {
1447
+ $allowToAction = AdminHelper::userCanAccessTo();
1448
+ if (!$allowToAction) {
1449
+ wp_redirect(get_home_url());
1450
+ exit();
1451
+ }
1452
+
1453
+ $postData = $_POST;
1454
+ $deleteData = 0;
1455
+ $enableDebugMode = 0;
1456
+
1457
+ if (isset($postData['sgpb-dont-delete-data'])) {
1458
+ $deleteData = 1;
1459
+ }
1460
+ if (isset($postData['sgpb-enable-debug-mode'])) {
1461
+ $enableDebugMode = 1;
1462
+ }
1463
+ if (isset($postData['sgpb-disable-analytics-general'])) {
1464
+ $disableAnalytics = 1;
1465
+ }
1466
+ $userRoles = @$postData['sgpb-user-roles'];
1467
+
1468
+ update_option('sgpb-user-roles', $userRoles);
1469
+ update_option('sgpb-dont-delete-data', $deleteData);
1470
+ update_option('sgpb-enable-debug-mode', $enableDebugMode);
1471
+ update_option('sgpb-disable-analytics-general', $disableAnalytics);
1472
+
1473
+ AdminHelper::filterUserCapabilitiesForTheUserRoles('save');
1474
+
1475
+ wp_redirect(admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
1476
+ }
1477
+ }
com/classes/Ajax.php CHANGED
@@ -1,721 +1,721 @@
1
- <?php
2
- namespace sgpb;
3
- use \ConfigDataHelper;
4
- use \SgpbDataConfig;
5
-
6
- class Ajax
7
- {
8
- private $postData;
9
-
10
- public function __construct()
11
- {
12
- $this->actions();
13
- }
14
-
15
- public function setPostData($postData)
16
- {
17
- $this->postData = $postData;
18
- }
19
-
20
- public function getPostData()
21
- {
22
- return $this->postData;
23
- }
24
-
25
- /**
26
- * Return ajax param form post data by key
27
- *
28
- * @since 1.0.0
29
- *
30
- * @param string $key
31
- *
32
- * @return string $value
33
- */
34
- public function getValueFromPost($key)
35
- {
36
- $postData = $this->getPostData();
37
- $value = '';
38
-
39
- if(!empty($postData[$key])) {
40
- $value = $postData[$key];
41
- }
42
-
43
- return $value;
44
- }
45
-
46
- public function actions()
47
- {
48
- add_action('wp_ajax_sgpb_send_to_open_counter', array($this, 'addToCounter'));
49
- add_action('wp_ajax_nopriv_sgpb_send_to_open_counter', array($this, 'addToCounter'));
50
-
51
- add_action('wp_ajax_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
52
- add_action('wp_ajax_nopriv_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
53
-
54
- add_action('wp_ajax_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
55
- add_action('wp_ajax_nopriv_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
56
-
57
- $allowToAction = AdminHelper::userCanAccessTo();
58
-
59
- if($allowToAction) {
60
- add_action('wp_ajax_add_condition_group_row', array($this, 'addConditionGroupRow'));
61
- add_action('wp_ajax_add_condition_rule_row', array($this, 'addConditionRuleRow'));
62
- add_action('wp_ajax_change_condition_rule_row', array($this, 'changeConditionRuleRow'));
63
- add_action('wp_ajax_select2_search_data', array($this, 'select2SearchData'));
64
- add_action('wp_ajax_change_popup_status', array($this, 'changePopupStatus'));
65
- // proStartGold
66
- add_action('wp_ajax_check_same_origin', array($this, 'checkSameOrigin'));
67
- // proEndGold
68
- add_action('wp_ajax_sgpb_subscribers_delete', array($this, 'deleteSubscribers'));
69
- add_action('wp_ajax_sgpb_add_subscribers', array($this, 'addSubscribers'));
70
- add_action('wp_ajax_sgpb_import_subscribers', array($this, 'importSubscribers'));
71
- add_action('wp_ajax_sgpb_import_settings', array($this, 'importSettings'));
72
- add_action('wp_ajax_sgpb_save_imported_subscribers', array($this, 'saveImportedSubscribers'));
73
- add_action('wp_ajax_sgpb_send_newsletter', array($this, 'sendNewsletter'));
74
- add_action('wp_ajax_sgpb_change_review_popup_show_period', array($this, 'changeReviewPopupPeriod'));
75
- add_action('wp_ajax_sgpb_dont_show_review_popup', array($this, 'dontShowReviewPopup'));
76
- add_action('wp_ajax_sgpb_close_banner', array($this, 'closeMainRateUsBanner'));
77
- add_action('wp_ajax_sgpb_close_license_notice', array($this, 'closeLicenseNoticeBanner'));
78
- add_action('wp_ajax_sgpb_hide_ask_review_popup', array($this, 'dontShowAskReviewBanner'));
79
- add_action('wp_ajax_sgpb_reset_popup_opening_count', array($this, 'resetPopupOpeningCount'));
80
- /*Extension notification panel*/
81
- add_action('wp_ajax_sgpb_dont_show_extension_panel', array($this, 'extensionNotificationPanel'));
82
- add_action('wp_ajax_sgpb_dont_show_problem_alert', array($this, 'dontShowProblemAlert'));
83
- // autosave
84
- add_action('wp_ajax_sgpb_autosave', array($this, 'sgpbAutosave'));
85
- }
86
- }
87
-
88
- public function sgpbAutosave()
89
- {
90
- $allowToAction = AdminHelper::userCanAccessTo();
91
- if(!$allowToAction) {
92
- wp_die('');
93
- }
94
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
95
-
96
- $popupId = @(int)$_POST['post_ID'];
97
- $postStatus = get_post_status($popupId);
98
- if($postStatus == 'publish') {
99
- wp_die('');
100
- }
101
-
102
- if(!isset($_POST['allPopupData'])) {
103
- wp_die(true);
104
- }
105
- $popupData = SGPopup::parsePopupDataFromData($_POST['allPopupData']);
106
- do_action('save_post_popupbuilder');
107
- $popupType = $popupData['sgpb-type'];
108
- $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
109
- $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
110
- if(file_exists($popupClassPath.$popupClassName.'.php')) {
111
- require_once($popupClassPath.$popupClassName.'.php');
112
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
113
- $popupClassName::create($popupData, '_preview', 1);
114
- }
115
-
116
- wp_die();
117
- }
118
-
119
- public function dontShowReviewPopup()
120
- {
121
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
122
- update_option('SGPBCloseReviewPopup-notification', true);
123
- do_action('sgpbGetNotifications');
124
- wp_die();
125
- }
126
-
127
- public function changeReviewPopupPeriod()
128
- {
129
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
130
- $messageType = sanitize_text_field($_POST['messageType']);
131
-
132
- if($messageType == 'count') {
133
- $maxPopupCount = get_option('SGPBMaxOpenCount');
134
- if(!$maxPopupCount) {
135
- $maxPopupCount = SGPB_ASK_REVIEW_POPUP_COUNT;
136
- }
137
- $maxPopupData = AdminHelper::getMaxOpenPopupId();
138
- if(!empty($maxPopupData['maxCount'])) {
139
- $maxPopupCount = $maxPopupData['maxCount'];
140
- }
141
-
142
- $maxPopupCount += SGPB_ASK_REVIEW_POPUP_COUNT;
143
- update_option('SGPBMaxOpenCount', $maxPopupCount);
144
- wp_die();
145
- }
146
-
147
- $popupTimeZone = get_option('timezone_string');
148
- if(!$popupTimeZone) {
149
- $popupTimeZone = SG_POPUP_DEFAULT_TIME_ZONE;
150
- }
151
- $timeDate = new \DateTime('now', new \DateTimeZone($popupTimeZone));
152
- $timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
153
-
154
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
155
- update_option('SGPBOpenNextTime', $timeNow);
156
- $usageDays = get_option('SGPBUsageDays');
157
- $usageDays += SGPB_REVIEW_POPUP_PERIOD;
158
- update_option('SGPBUsageDays', $usageDays);
159
- wp_die();
160
- }
161
-
162
- public function resetPopupOpeningCount()
163
- {
164
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
165
-
166
- global $wpdb;
167
-
168
- $tableName = $wpdb->prefix.'sgpb_analytics';
169
- $popupId = (int)$_POST['popupId'];
170
- $allPopupsCount = get_option('SgpbCounter');
171
- if($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
172
- SGPopup::deleteAnalyticsDataByPopupId($popupId);
173
- }
174
- if(empty($allPopupsCount)) {
175
- echo SGPB_AJAX_STATUS_FALSE;
176
- wp_die();
177
- }
178
- if(isset($allPopupsCount[$popupId])) {
179
- $allPopupsCount[$popupId] = 0;
180
- }
181
-
182
- // 7, 12, 13 => exclude close, subscription success, contact success events
183
- $stmt = $wpdb->prepare(' DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
184
- $popupAnalyticsData = $wpdb->get_var($stmt);
185
-
186
- update_option('SgpbCounter', $allPopupsCount);
187
-
188
- }
189
-
190
- public function dontShowAskReviewBanner()
191
- {
192
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
193
- update_option('sgpbDontShowAskReviewBanner', 1);
194
- echo SGPB_AJAX_STATUS_TRUE;
195
- wp_die();
196
- }
197
-
198
- public function dontShowProblemAlert()
199
- {
200
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
201
- update_option('sgpb_alert_problems', 1);
202
- echo SGPB_AJAX_STATUS_TRUE;
203
- wp_die();
204
- }
205
-
206
- public function extensionNotificationPanel()
207
- {
208
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
209
- update_option('sgpb_extensions_updated', 1);
210
- echo SGPB_AJAX_STATUS_TRUE;
211
- wp_die();
212
- }
213
-
214
- public function closeMainRateUsBanner()
215
- {
216
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
217
- update_option('sgpb-hide-support-banner', 1);
218
- do_action('sgpbGetNotifications');
219
- wp_die();
220
- }
221
-
222
- public function closeLicenseNoticeBanner()
223
- {
224
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
225
- update_option('sgpb-hide-license-notice-banner', 1);
226
- wp_die();
227
- }
228
-
229
- public function addToCounter()
230
- {
231
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
232
-
233
- if(isset($_GET['sg_popup_preview_id']) && !isset($_POST['params'])) {
234
- wp_die(0);
235
- }
236
-
237
- /* Sanitizing multidimensional array */
238
- $popupParams = $_POST['params'];
239
- array_walk($popupParams, 'sanitize_text_field');
240
-
241
- $popupsIdCollection = is_array($popupParams['popupsIdCollection']) ? $popupParams['popupsIdCollection'] : array();
242
- $popupsCounterData = get_option('SgpbCounter');
243
-
244
- if($popupsCounterData === false) {
245
- $popupsCounterData = array();
246
- }
247
-
248
- foreach($popupsIdCollection as $popupId => $popupCount) {
249
- if(empty($popupsCounterData[$popupId])) {
250
- $popupsCounterData[$popupId] = 0;
251
- }
252
- $popupsCounterData[$popupId] += $popupCount;
253
- }
254
-
255
- update_option('SgpbCounter', $popupsCounterData);
256
- wp_die(1);
257
- }
258
-
259
- public function deleteSubscribers()
260
- {
261
- global $wpdb;
262
-
263
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
264
-
265
- $subscribersId = array_map('sanitize_text_field', $_POST['subscribersId']);
266
-
267
- foreach($subscribersId as $subscriberId) {
268
- $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE id = %d', $subscriberId);
269
- $wpdb->query($prepareSql);
270
- }
271
- }
272
-
273
- public function addSubscribers()
274
- {
275
- global $wpdb;
276
-
277
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
278
- $status = SGPB_AJAX_STATUS_FALSE;
279
- $firstName = sanitize_text_field($_POST['firstName']);
280
- $lastName = sanitize_text_field($_POST['lastName']);
281
- $email = sanitize_text_field($_POST['email']);
282
- $date = date('Y-m-d');
283
- $subscriptionPopupsId = array_map('sanitize_text_field', $_POST['popups']);
284
-
285
- foreach($subscriptionPopupsId as $subscriptionPopupId) {
286
- $selectSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d', $email, $subscriptionPopupId);
287
- $res = $wpdb->get_row($selectSql, ARRAY_A);
288
- // add new subscriber
289
- if(empty($res)) {
290
- $sql = $wpdb->prepare('INSERT INTO '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' (firstName, lastName, email, cDate, subscriptionType) VALUES (%s, %s, %s, %s, %d) ', $firstName, $lastName, $email, $date, $subscriptionPopupId);
291
- $res = $wpdb->query($sql);
292
- } // edit existing
293
- else {
294
- $sql = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET firstName = %s, lastName = %s, email = %s, cDate = %s, subscriptionType = %d, unsubscribered = 0 WHERE id = %d', $firstName, $lastName, $email, $date, $subscriptionPopupId, $res['id']);
295
- $wpdb->query($sql);
296
- $res = 1;
297
- }
298
-
299
- if($res) {
300
- $status = SGPB_AJAX_STATUS_TRUE;
301
- }
302
- }
303
-
304
- echo $status;
305
- wp_die();
306
- }
307
-
308
- public function importSubscribers()
309
- {
310
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
311
- $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
312
- $fileURL = sanitize_text_field($_POST['importListURL']);
313
- ob_start();
314
- require_once SG_POPUP_VIEWS_PATH.'importConfigView.php';
315
- $content = ob_get_contents();
316
- ob_end_clean();
317
-
318
- echo $content;
319
- wp_die();
320
- }
321
-
322
- public function importSettings()
323
- {
324
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
325
- ob_start();
326
- require_once SG_POPUP_VIEWS_PATH.'importPopupsView.php';
327
- $content = ob_get_contents();
328
- ob_end_clean();
329
-
330
- echo $content;
331
- wp_die();
332
- }
333
-
334
- public function saveImportedSubscribers()
335
- {
336
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
337
- @ini_set('auto_detect_line_endings', '1');
338
- $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
339
- $fileURL = sanitize_text_field($_POST['importListURL']);
340
- $mapping = $_POST['namesMapping'];
341
-
342
- $fileContent = AdminHelper::getFileFromURL($fileURL);
343
- $csvFileArray = array_map('str_getcsv', file($fileURL));
344
-
345
- $header = $csvFileArray[0];
346
- unset($csvFileArray[0]);
347
- $subscriptionPlusContent = apply_filters('sgpbImportToSubscriptionList', $csvFileArray, $mapping, $formId);
348
-
349
- // -1 it's mean saved from Subscription Plus
350
- if($subscriptionPlusContent != -1) {
351
- foreach($csvFileArray as $csvData) {
352
- global $wpdb;
353
- $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
354
- $sql = $wpdb->prepare('SELECT submittedData FROM '.$subscribersTableName);
355
- if(!empty($mapping['date'])) {
356
- $date = $csvData[$mapping['date']];
357
- $date = date('Y-m-d', strtotime($date));
358
- }
359
- if($sql) {
360
- $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType, status, unsubscribed) VALUES (%s, %s, %s, %s, %d, %d, %d) ', $csvData[$mapping['firstName']], $csvData[$mapping['lastName']], $csvData[$mapping['email']], $date, $formId, 0, 0);
361
- } else {
362
- $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType, status, unsubscribed, submittedData) VALUES (%s, %s, %s, %s, %d, %d, %d, %s) ', $csvData[$mapping['firstName']], $csvData[$mapping['lastName']], $csvData[$mapping['email']], $csvData[$mapping['date']], $formId, 0, 0, '');
363
- }
364
-
365
- $wpdb->query($sql);
366
- }
367
- }
368
-
369
- echo SGPB_AJAX_STATUS_TRUE;
370
- wp_die();
371
- }
372
-
373
- public function sendNewsletter()
374
- {
375
- $allowToAction = AdminHelper::userCanAccessTo();
376
- if(!$allowToAction) {
377
- wp_redirect(get_home_url());
378
- exit();
379
- }
380
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
381
- global $wpdb;
382
-
383
- $newsletterData = stripslashes_deep($_POST['newsletterData']);
384
- if(isset($newsletterData['testSendingStatus']) && $newsletterData['testSendingStatus'] == 'test') {
385
- AdminHelper::sendTestNewsletter($newsletterData);
386
- }
387
- $subscriptionFormId = (int)$newsletterData['subscriptionFormId'];
388
-
389
- $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 0 WHERE subscriptionType = %d', $subscriptionFormId);
390
- $wpdb->query($updateStatusQuery);
391
- $newsletterData['blogname'] = get_bloginfo('name');
392
- $newsletterData['username'] = wp_get_current_user()->user_login;
393
- update_option('SGPB_NEWSLETTER_DATA', $newsletterData);
394
-
395
- wp_schedule_event(time(), 'sgpb_newsletter_send_every_minute', 'sgpb_send_newsletter');
396
- wp_die();
397
- }
398
-
399
- // proStartGold
400
- public function checkSameOrigin()
401
- {
402
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
403
-
404
- $url = esc_url($_POST['iframeUrl']);
405
- $status = SGPB_AJAX_STATUS_FALSE;
406
-
407
- $remoteGet = wp_remote_get($url);
408
-
409
- if(is_array($remoteGet) && !empty($remoteGet['headers']['x-frame-options'])) {
410
- $siteUrl = esc_url($_POST['siteUrl']);
411
- $xFrameOptions = $remoteGet['headers']['x-frame-options'];
412
- $mayNotShow = false;
413
-
414
- if($xFrameOptions == 'deny') {
415
- $mayNotShow = true;
416
- } else if($xFrameOptions == 'SAMEORIGIN') {
417
- if(strpos($url, $siteUrl) === false) {
418
- $mayNotShow = true;
419
- }
420
- } else {
421
- if(strpos($xFrameOptions, $siteUrl) === false) {
422
- $mayNotShow = true;;
423
- }
424
- }
425
-
426
- if($mayNotShow) {
427
- echo $status;
428
- wp_die();
429
- }
430
- }
431
-
432
- // $remoteGet['response']['code'] < 400 it's mean correct status
433
- if(is_array($remoteGet) && isset($remoteGet['response']['code']) && $remoteGet['response']['code'] < 400) {
434
- $status = SGPB_AJAX_STATUS_TRUE;
435
- }
436
-
437
- echo $status;
438
- wp_die();
439
- }
440
-
441
- // proEndGold
442
-
443
- public function changePopupStatus()
444
- {
445
- $popupId = (int)$_POST['popupId'];
446
- $obj = SGPopup::find($popupId);
447
- $isDraft = '';
448
- $postStatus = get_post_status($popupId);
449
- if($postStatus == 'draft') {
450
- $isDraft = '_preview';
451
- }
452
-
453
- if(!$obj || !is_object($obj)) {
454
- wp_die(SGPB_AJAX_STATUS_FALSE);
455
- }
456
- $options = $obj->getOptions();
457
- $options['sgpb-is-active'] = sanitize_text_field($_POST['popupStatus']);
458
-
459
- unset($options['sgpb-conditions']);
460
- update_post_meta($popupId, 'sg_popup_options'.$isDraft, $options);
461
-
462
- wp_die($popupId);
463
- }
464
-
465
- public function subscriptionSubmission()
466
- {
467
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
468
- $this->setPostData($_POST);
469
- $submissionData = $this->getValueFromPost('formData');
470
- $popupPostId = (int)$this->getValueFromPost('popupPostId');
471
-
472
- parse_str($submissionData, $formData);
473
-
474
- if(empty($formData)) {
475
- echo SGPB_AJAX_STATUS_FALSE;
476
- wp_die();
477
- }
478
-
479
- $hiddenChecker = sanitize_text_field($formData['sgpb-subs-hidden-checker']);
480
-
481
- // this check is made to protect ourselves from bot
482
- if(!empty($hiddenChecker)) {
483
- echo 'Bot';
484
- wp_die();
485
- }
486
- global $wpdb;
487
-
488
- $status = SGPB_AJAX_STATUS_FALSE;
489
- $date = date('Y-m-d');
490
- $email = sanitize_email($formData['sgpb-subs-email']);
491
- $firstName = sanitize_text_field($formData['sgpb-subs-first-name']);
492
- $lastName = sanitize_text_field($formData['sgpb-subs-last-name']);
493
-
494
- $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
495
-
496
- $getSubscriberQuery = $wpdb->prepare('SELECT id FROM '.$subscribersTableName.' WHERE email = %s AND subscriptionType = %d', $email, $popupPostId);
497
- $list = $wpdb->get_row($getSubscriberQuery, ARRAY_A);
498
-
499
- // When subscriber does not exist we insert to subscribers table otherwise we update user info
500
- if(empty($list['id'])) {
501
- $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType) VALUES (%s, %s, %s, %s, %d) ', $firstName, $lastName, $email, $date, $popupPostId);
502
- $res = $wpdb->query($sql);
503
- } else {
504
- $sql = $wpdb->prepare('UPDATE '.$subscribersTableName.' SET firstName = %s, lastName = %s, email = %s, cDate = %s, subscriptionType = %d WHERE id = %d', $firstName, $lastName, $email, $date, $popupPostId, $list['id']);
505
- $wpdb->query($sql);
506
- $res = 1;
507
- }
508
- if($res) {
509
- $status = SGPB_AJAX_STATUS_TRUE;
510
- }
511
-
512
- echo $status;
513
- wp_die();
514
- }
515
-
516
- public function sgpbSubsciptionFormSubmittedAction()
517
- {
518
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
519
- $this->setPostData($_POST);
520
-
521
- $submissionData = $this->getValueFromPost('formData');
522
- $popupPostId = (int)$this->getValueFromPost('popupPostId');
523
- parse_str($submissionData, $formData);
524
- if(empty($_POST)) {
525
- echo SGPB_AJAX_STATUS_FALSE;
526
- wp_die();
527
- }
528
- $email = sanitize_email($_POST['emailValue']);
529
- $firstName = sanitize_text_field($_POST['firstNameValue']);
530
- $lastName = sanitize_text_field($_POST['lastNameValue']);
531
- $userData = array(
532
- 'email' => $email,
533
- 'firstName' => $firstName,
534
- 'lastName' => $lastName
535
- );
536
- $this->sendSuccessEmails($popupPostId, $userData);
537
- do_action('sgpbProcessAfterSuccessfulSubmission', $popupPostId, $userData);
538
- }
539
-
540
- public function sendSuccessEmails($popupPostId, $subscriptionDetails)
541
- {
542
- global $wpdb;
543
- $popup = SGPopup::find($popupPostId);
544
-
545
- if(!is_object($popup)) {
546
- return false;
547
- }
548
- $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
549
-
550
- $getSubscriberCountQuery = $wpdb->prepare('SELECT COUNT(id) as countIds FROM '.$subscribersTableName.' WHERE subscriptionType = %d', $popupPostId);
551
- $count = $wpdb->get_row($getSubscriberCountQuery, ARRAY_A);
552
-
553
- $popupOptions = $popup->getOptions();
554
- $adminUserName = 'admin';
555
-
556
- $adminEmail = get_option('admin_email');
557
- $userData = @get_user_by('email', $adminEmail);
558
-
559
- if(!empty($userData)) {
560
- $adminUserName = $userData->display_name;
561
- }
562
-
563
- $newSubscriberEmailHeader = AdminHelper::getEmailHeader($adminEmail);
564
- $takeReviewAfterFirstSubscription = get_option('sgpb-new-subscriber');
565
-
566
- if($count['countIds'] == 1 && !$takeReviewAfterFirstSubscription) {
567
- // take review
568
- update_option('sgpb-new-subscriber', 1);
569
- $newSubscriberEmailTitle = __('Congrats! You have already 1 subscriber!', SG_POPUP_TEXT_DOMAIN);
570
- $reviewEmailTemplate = AdminHelper::getFileFromURL(SG_POPUP_EMAIL_TEMPLATES_URL.'takeReviewAfterSubscribe.html');
571
- $reviewEmailTemplate = preg_replace('/\[adminUserName]/', $adminUserName, $reviewEmailTemplate);
572
- $sendStatus = wp_mail($adminEmail, $newSubscriberEmailTitle, $reviewEmailTemplate, $newSubscriberEmailHeader); //return true or false
573
- }
574
- }
575
-
576
- public function select2SearchData()
577
- {
578
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
579
-
580
- $postTypeName = sanitize_text_field($_POST['searchKey']);
581
- $search = sanitize_text_field($_POST['searchTerm']);
582
- $searchResults = $this->selectFromPost($postTypeName, $search);
583
-
584
- if(isset($_POST['searchCallback'])) {
585
- $searchCallback = sanitize_text_field($_POST['searchCallback']);
586
- $searchResults = apply_filters('sgpbSearchAdditionalData', $search, array());
587
- }
588
-
589
- if(empty($searchResults)) {
590
- $results['items'] = array();
591
- }
592
-
593
- /*Selected custom post type convert for select2 format*/
594
- foreach($searchResults as $id => $name) {
595
- $results['items'][] = array(
596
- 'id' => $id,
597
- 'text' => $name
598
- );
599
- }
600
-
601
- echo json_encode($results);
602
- wp_die();
603
- }
604
-
605
- private function selectFromPost($postTypeName, $search)
606
- {
607
- $args = array(
608
- 's' => $search,
609
- 'post__in' => !empty($_REQUEST['include']) ? array_map('intval', $_REQUEST['include']) : null,
610
- 'page' => !empty($_REQUEST['page']) ? absint($_REQUEST['page']) : null,
611
- 'posts_per_page' => 100,
612
- 'post_type' => $postTypeName
613
- );
614
- $searchResults = ConfigDataHelper::getPostTypeData($args);
615
-
616
- return $searchResults;
617
- }
618
-
619
- public function addConditionGroupRow()
620
- {
621
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
622
- global $SGPB_DATA_CONFIG_ARRAY;
623
-
624
- $groupId = (int)$_POST['groupId'];
625
- $targetType = sanitize_text_field($_POST['conditionName']);
626
- $addedObj = array();
627
-
628
- $builderObj = new ConditionBuilder();
629
-
630
- $builderObj->setGroupId($groupId);
631
- $builderObj->setRuleId(SG_CONDITION_FIRST_RULE);
632
- $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
633
- $builderObj->setConditionName($targetType);
634
- $addedObj[] = $builderObj;
635
-
636
- $creator = new ConditionCreator($addedObj);
637
- echo $creator->render();
638
- wp_die();
639
- }
640
-
641
- public function addConditionRuleRow()
642
- {
643
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
644
- $data = '';
645
- global $SGPB_DATA_CONFIG_ARRAY;
646
- $targetType = sanitize_text_field($_POST['conditionName']);
647
- $builderObj = new ConditionBuilder();
648
-
649
- $groupId = (int)$_POST['groupId'];
650
- $ruleId = (int)$_POST['ruleId'];
651
-
652
- $builderObj->setGroupId($groupId);
653
- $builderObj->setRuleId($ruleId);
654
- $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
655
- $builderObj->setConditionName($targetType);
656
-
657
- $data .= ConditionCreator::createConditionRuleRow($builderObj);
658
-
659
- echo $data;
660
- wp_die();
661
- }
662
-
663
- public function changeConditionRuleRow()
664
- {
665
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
666
- $data = '';
667
- global $SGPB_DATA_CONFIG_ARRAY;
668
-
669
- $targetType = sanitize_text_field($_POST['conditionName']);
670
- $builderObj = new ConditionBuilder();
671
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$targetType];
672
- $groupId = (int)$_POST['groupId'];
673
- $ruleId = (int)$_POST['ruleId'];
674
- $popupId = (int)$_POST['popupId'];
675
- $paramName = sanitize_text_field($_POST['paramName']);
676
-
677
- $savedData = array(
678
- 'param' => $paramName
679
- );
680
-
681
- if($targetType == 'target' || $targetType == 'conditions') {
682
- $savedData['operator'] = '==';
683
- } else if($conditionConfig['specialDefaultOperator']) {
684
- $savedData['operator'] = $paramName;
685
- }
686
-
687
- if(!empty($_POST['paramValue'])) {
688
- $savedData['tempParam'] = sanitize_text_field($_POST['paramValue']);
689
- $savedData['operator'] = $paramName;
690
- }
691
- // change operator value related to condition value
692
- if(!empty($conditionConfig['operatorAllowInConditions']) && in_array($paramName, $conditionConfig['operatorAllowInConditions'])) {
693
- $conditionConfig['paramsData']['operator'] = array();
694
-
695
- if(!empty($conditionConfig['paramsData'][$paramName.'Operator'])) {
696
- $operatorData = $conditionConfig['paramsData'][$paramName.'Operator'];
697
- $SGPB_DATA_CONFIG_ARRAY[$targetType]['paramsData']['operator'] = $operatorData;
698
- // change take value related to condition value
699
- $operatorDataKeys = array_keys($operatorData);
700
- if(!empty($operatorDataKeys[0])) {
701
- $savedData['operator'] = $operatorDataKeys[0];
702
- $builderObj->setTakeValueFrom('operator');
703
- }
704
- }
705
- }
706
- // by default set empty value for users' role (adv. tar.)
707
- $savedData['value'] = array();
708
- $savedData['hiddenOption'] = @$conditionConfig['hiddenOptionData'][$paramName];
709
-
710
- $builderObj->setPopupId($popupId);
711
- $builderObj->setGroupId($groupId);
712
- $builderObj->setRuleId($ruleId);
713
- $builderObj->setSavedData($savedData);
714
- $builderObj->setConditionName($targetType);
715
-
716
- $data .= ConditionCreator::createConditionRuleRow($builderObj);
717
-
718
- echo $data;
719
- wp_die();
720
- }
721
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \ConfigDataHelper;
4
+ use \SgpbDataConfig;
5
+
6
+ class Ajax
7
+ {
8
+ private $postData;
9
+
10
+ public function __construct()
11
+ {
12
+ $this->actions();
13
+ }
14
+
15
+ public function setPostData($postData)
16
+ {
17
+ $this->postData = $postData;
18
+ }
19
+
20
+ public function getPostData()
21
+ {
22
+ return $this->postData;
23
+ }
24
+
25
+ /**
26
+ * Return ajax param form post data by key
27
+ *
28
+ * @since 1.0.0
29
+ *
30
+ * @param string $key
31
+ *
32
+ * @return string $value
33
+ */
34
+ public function getValueFromPost($key)
35
+ {
36
+ $postData = $this->getPostData();
37
+ $value = '';
38
+
39
+ if(!empty($postData[$key])) {
40
+ $value = $postData[$key];
41
+ }
42
+
43
+ return $value;
44
+ }
45
+
46
+ public function actions()
47
+ {
48
+ add_action('wp_ajax_sgpb_send_to_open_counter', array($this, 'addToCounter'));
49
+ add_action('wp_ajax_nopriv_sgpb_send_to_open_counter', array($this, 'addToCounter'));
50
+
51
+ add_action('wp_ajax_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
52
+ add_action('wp_ajax_nopriv_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
53
+
54
+ add_action('wp_ajax_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
55
+ add_action('wp_ajax_nopriv_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
56
+
57
+ $allowToAction = AdminHelper::userCanAccessTo();
58
+
59
+ if($allowToAction) {
60
+ add_action('wp_ajax_add_condition_group_row', array($this, 'addConditionGroupRow'));
61
+ add_action('wp_ajax_add_condition_rule_row', array($this, 'addConditionRuleRow'));
62
+ add_action('wp_ajax_change_condition_rule_row', array($this, 'changeConditionRuleRow'));
63
+ add_action('wp_ajax_select2_search_data', array($this, 'select2SearchData'));
64
+ add_action('wp_ajax_change_popup_status', array($this, 'changePopupStatus'));
65
+ // proStartGold
66
+ add_action('wp_ajax_check_same_origin', array($this, 'checkSameOrigin'));
67
+ // proEndGold
68
+ add_action('wp_ajax_sgpb_subscribers_delete', array($this, 'deleteSubscribers'));
69
+ add_action('wp_ajax_sgpb_add_subscribers', array($this, 'addSubscribers'));
70
+ add_action('wp_ajax_sgpb_import_subscribers', array($this, 'importSubscribers'));
71
+ add_action('wp_ajax_sgpb_import_settings', array($this, 'importSettings'));
72
+ add_action('wp_ajax_sgpb_save_imported_subscribers', array($this, 'saveImportedSubscribers'));
73
+ add_action('wp_ajax_sgpb_send_newsletter', array($this, 'sendNewsletter'));
74
+ add_action('wp_ajax_sgpb_change_review_popup_show_period', array($this, 'changeReviewPopupPeriod'));
75
+ add_action('wp_ajax_sgpb_dont_show_review_popup', array($this, 'dontShowReviewPopup'));
76
+ add_action('wp_ajax_sgpb_close_banner', array($this, 'closeMainRateUsBanner'));
77
+ add_action('wp_ajax_sgpb_close_license_notice', array($this, 'closeLicenseNoticeBanner'));
78
+ add_action('wp_ajax_sgpb_hide_ask_review_popup', array($this, 'dontShowAskReviewBanner'));
79
+ add_action('wp_ajax_sgpb_reset_popup_opening_count', array($this, 'resetPopupOpeningCount'));
80
+ /*Extension notification panel*/
81
+ add_action('wp_ajax_sgpb_dont_show_extension_panel', array($this, 'extensionNotificationPanel'));
82
+ add_action('wp_ajax_sgpb_dont_show_problem_alert', array($this, 'dontShowProblemAlert'));
83
+ // autosave
84
+ add_action('wp_ajax_sgpb_autosave', array($this, 'sgpbAutosave'));
85
+ }
86
+ }
87
+
88
+ public function sgpbAutosave()
89
+ {
90
+ $allowToAction = AdminHelper::userCanAccessTo();
91
+ if(!$allowToAction) {
92
+ wp_die('');
93
+ }
94
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
95
+
96
+ $popupId = @(int)$_POST['post_ID'];
97
+ $postStatus = get_post_status($popupId);
98
+ if($postStatus == 'publish') {
99
+ wp_die('');
100
+ }
101
+
102
+ if(!isset($_POST['allPopupData'])) {
103
+ wp_die(true);
104
+ }
105
+ $popupData = SGPopup::parsePopupDataFromData($_POST['allPopupData']);
106
+ do_action('save_post_popupbuilder');
107
+ $popupType = $popupData['sgpb-type'];
108
+ $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
109
+ $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
110
+ if(file_exists($popupClassPath.$popupClassName.'.php')) {
111
+ require_once($popupClassPath.$popupClassName.'.php');
112
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
113
+ $popupClassName::create($popupData, '_preview', 1);
114
+ }
115
+
116
+ wp_die();
117
+ }
118
+
119
+ public function dontShowReviewPopup()
120
+ {
121
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
122
+ update_option('SGPBCloseReviewPopup-notification', true);
123
+ do_action('sgpbGetNotifications');
124
+ wp_die();
125
+ }
126
+
127
+ public function changeReviewPopupPeriod()
128
+ {
129
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
130
+ $messageType = sanitize_text_field($_POST['messageType']);
131
+
132
+ if($messageType == 'count') {
133
+ $maxPopupCount = get_option('SGPBMaxOpenCount');
134
+ if(!$maxPopupCount) {
135
+ $maxPopupCount = SGPB_ASK_REVIEW_POPUP_COUNT;
136
+ }
137
+ $maxPopupData = AdminHelper::getMaxOpenPopupId();
138
+ if(!empty($maxPopupData['maxCount'])) {
139
+ $maxPopupCount = $maxPopupData['maxCount'];
140
+ }
141
+
142
+ $maxPopupCount += SGPB_ASK_REVIEW_POPUP_COUNT;
143
+ update_option('SGPBMaxOpenCount', $maxPopupCount);
144
+ wp_die();
145
+ }
146
+
147
+ $popupTimeZone = get_option('timezone_string');
148
+ if(!$popupTimeZone) {
149
+ $popupTimeZone = SG_POPUP_DEFAULT_TIME_ZONE;
150
+ }
151
+ $timeDate = new \DateTime('now', new \DateTimeZone($popupTimeZone));
152
+ $timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
153
+
154
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
155
+ update_option('SGPBOpenNextTime', $timeNow);
156
+ $usageDays = get_option('SGPBUsageDays');
157
+ $usageDays += SGPB_REVIEW_POPUP_PERIOD;
158
+ update_option('SGPBUsageDays', $usageDays);
159
+ wp_die();
160
+ }
161
+
162
+ public function resetPopupOpeningCount()
163
+ {
164
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
165
+
166
+ global $wpdb;
167
+
168
+ $tableName = $wpdb->prefix.'sgpb_analytics';
169
+ $popupId = (int)$_POST['popupId'];
170
+ $allPopupsCount = get_option('SgpbCounter');
171
+ if($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
172
+ SGPopup::deleteAnalyticsDataByPopupId($popupId);
173
+ }
174
+ if(empty($allPopupsCount)) {
175
+ echo SGPB_AJAX_STATUS_FALSE;
176
+ wp_die();
177
+ }
178
+ if(isset($allPopupsCount[$popupId])) {
179
+ $allPopupsCount[$popupId] = 0;
180
+ }
181
+
182
+ // 7, 12, 13 => exclude close, subscription success, contact success events
183
+ $stmt = $wpdb->prepare(' DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
184
+ $popupAnalyticsData = $wpdb->get_var($stmt);
185
+
186
+ update_option('SgpbCounter', $allPopupsCount);
187
+
188
+ }
189
+
190
+ public function dontShowAskReviewBanner()
191
+ {
192
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
193
+ update_option('sgpbDontShowAskReviewBanner', 1);
194
+ echo SGPB_AJAX_STATUS_TRUE;
195
+ wp_die();
196
+ }
197
+
198
+ public function dontShowProblemAlert()
199
+ {
200
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
201
+ update_option('sgpb_alert_problems', 1);
202
+ echo SGPB_AJAX_STATUS_TRUE;
203
+ wp_die();
204
+ }
205
+
206
+ public function extensionNotificationPanel()
207
+ {
208
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
209
+ update_option('sgpb_extensions_updated', 1);
210
+ echo SGPB_AJAX_STATUS_TRUE;
211
+ wp_die();
212
+ }
213
+
214
+ public function closeMainRateUsBanner()
215
+ {
216
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
217
+ update_option('sgpb-hide-support-banner', 1);
218
+ do_action('sgpbGetNotifications');
219
+ wp_die();
220
+ }
221
+
222
+ public function closeLicenseNoticeBanner()
223
+ {
224
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
225
+ update_option('sgpb-hide-license-notice-banner', 1);
226
+ wp_die();
227
+ }
228
+
229
+ public function addToCounter()
230
+ {
231
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
232
+
233
+ if(isset($_GET['sg_popup_preview_id']) && !isset($_POST['params'])) {
234
+ wp_die(0);
235
+ }
236
+
237
+ /* Sanitizing multidimensional array */
238
+ $popupParams = $_POST['params'];
239
+ array_walk($popupParams, 'sanitize_text_field');
240
+
241
+ $popupsIdCollection = is_array($popupParams['popupsIdCollection']) ? $popupParams['popupsIdCollection'] : array();
242
+ $popupsCounterData = get_option('SgpbCounter');
243
+
244
+ if($popupsCounterData === false) {
245
+ $popupsCounterData = array();
246
+ }
247
+
248
+ foreach($popupsIdCollection as $popupId => $popupCount) {
249
+ if(empty($popupsCounterData[$popupId])) {
250
+ $popupsCounterData[$popupId] = 0;
251
+ }
252
+ $popupsCounterData[$popupId] += $popupCount;
253
+ }
254
+
255
+ update_option('SgpbCounter', $popupsCounterData);
256
+ wp_die(1);
257
+ }
258
+
259
+ public function deleteSubscribers()
260
+ {
261
+ global $wpdb;
262
+
263
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
264
+
265
+ $subscribersId = array_map('sanitize_text_field', $_POST['subscribersId']);
266
+
267
+ foreach($subscribersId as $subscriberId) {
268
+ $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE id = %d', $subscriberId);
269
+ $wpdb->query($prepareSql);
270
+ }
271
+ }
272
+
273
+ public function addSubscribers()
274
+ {
275
+ global $wpdb;
276
+
277
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
278
+ $status = SGPB_AJAX_STATUS_FALSE;
279
+ $firstName = sanitize_text_field($_POST['firstName']);
280
+ $lastName = sanitize_text_field($_POST['lastName']);
281
+ $email = sanitize_text_field($_POST['email']);
282
+ $date = date('Y-m-d');
283
+ $subscriptionPopupsId = array_map('sanitize_text_field', $_POST['popups']);
284
+
285
+ foreach($subscriptionPopupsId as $subscriptionPopupId) {
286
+ $selectSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d', $email, $subscriptionPopupId);
287
+ $res = $wpdb->get_row($selectSql, ARRAY_A);
288
+ // add new subscriber
289
+ if(empty($res)) {
290
+ $sql = $wpdb->prepare('INSERT INTO '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' (firstName, lastName, email, cDate, subscriptionType) VALUES (%s, %s, %s, %s, %d) ', $firstName, $lastName, $email, $date, $subscriptionPopupId);
291
+ $res = $wpdb->query($sql);
292
+ } // edit existing
293
+ else {
294
+ $sql = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET firstName = %s, lastName = %s, email = %s, cDate = %s, subscriptionType = %d, unsubscribered = 0 WHERE id = %d', $firstName, $lastName, $email, $date, $subscriptionPopupId, $res['id']);
295
+ $wpdb->query($sql);
296
+ $res = 1;
297
+ }
298
+
299
+ if($res) {
300
+ $status = SGPB_AJAX_STATUS_TRUE;
301
+ }
302
+ }
303
+
304
+ echo $status;
305
+ wp_die();
306
+ }
307
+
308
+ public function importSubscribers()
309
+ {
310
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
311
+ $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
312
+ $fileURL = sanitize_text_field($_POST['importListURL']);
313
+ ob_start();
314
+ require_once SG_POPUP_VIEWS_PATH.'importConfigView.php';
315
+ $content = ob_get_contents();
316
+ ob_end_clean();
317
+
318
+ echo $content;
319
+ wp_die();
320
+ }
321
+
322
+ public function importSettings()
323
+ {
324
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
325
+ ob_start();
326
+ require_once SG_POPUP_VIEWS_PATH.'importPopupsView.php';
327
+ $content = ob_get_contents();
328
+ ob_end_clean();
329
+
330
+ echo $content;
331
+ wp_die();
332
+ }
333
+
334
+ public function saveImportedSubscribers()
335
+ {
336
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
337
+ @ini_set('auto_detect_line_endings', '1');
338
+ $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
339
+ $fileURL = sanitize_text_field($_POST['importListURL']);
340
+ $mapping = $_POST['namesMapping'];
341
+
342
+ $fileContent = AdminHelper::getFileFromURL($fileURL);
343
+ $csvFileArray = array_map('str_getcsv', file($fileURL));
344
+
345
+ $header = $csvFileArray[0];
346
+ unset($csvFileArray[0]);
347
+ $subscriptionPlusContent = apply_filters('sgpbImportToSubscriptionList', $csvFileArray, $mapping, $formId);
348
+
349
+ // -1 it's mean saved from Subscription Plus
350
+ if($subscriptionPlusContent != -1) {
351
+ foreach($csvFileArray as $csvData) {
352
+ global $wpdb;
353
+ $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
354
+ $sql = $wpdb->prepare('SELECT submittedData FROM '.$subscribersTableName);
355
+ if(!empty($mapping['date'])) {
356
+ $date = $csvData[$mapping['date']];
357
+ $date = date('Y-m-d', strtotime($date));
358
+ }
359
+ if($sql) {
360
+ $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType, status, unsubscribed) VALUES (%s, %s, %s, %s, %d, %d, %d) ', $csvData[$mapping['firstName']], $csvData[$mapping['lastName']], $csvData[$mapping['email']], $date, $formId, 0, 0);
361
+ } else {
362
+ $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType, status, unsubscribed, submittedData) VALUES (%s, %s, %s, %s, %d, %d, %d, %s) ', $csvData[$mapping['firstName']], $csvData[$mapping['lastName']], $csvData[$mapping['email']], $csvData[$mapping['date']], $formId, 0, 0, '');
363
+ }
364
+
365
+ $wpdb->query($sql);
366
+ }
367
+ }
368
+
369
+ echo SGPB_AJAX_STATUS_TRUE;
370
+ wp_die();
371
+ }
372
+
373
+ public function sendNewsletter()
374
+ {
375
+ $allowToAction = AdminHelper::userCanAccessTo();
376
+ if(!$allowToAction) {
377
+ wp_redirect(get_home_url());
378
+ exit();
379
+ }
380
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
381
+ global $wpdb;
382
+
383
+ $newsletterData = stripslashes_deep($_POST['newsletterData']);
384
+ if(isset($newsletterData['testSendingStatus']) && $newsletterData['testSendingStatus'] == 'test') {
385
+ AdminHelper::sendTestNewsletter($newsletterData);
386
+ }
387
+ $subscriptionFormId = (int)$newsletterData['subscriptionFormId'];
388
+
389
+ $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 0 WHERE subscriptionType = %d', $subscriptionFormId);
390
+ $wpdb->query($updateStatusQuery);
391
+ $newsletterData['blogname'] = get_bloginfo('name');
392
+ $newsletterData['username'] = wp_get_current_user()->user_login;
393
+ update_option('SGPB_NEWSLETTER_DATA', $newsletterData);
394
+
395
+ wp_schedule_event(time(), 'sgpb_newsletter_send_every_minute', 'sgpb_send_newsletter');
396
+ wp_die();
397
+ }
398
+
399
+ // proStartGold
400
+ public function checkSameOrigin()
401
+ {
402
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
403
+
404
+ $url = esc_url($_POST['iframeUrl']);
405
+ $status = SGPB_AJAX_STATUS_FALSE;
406
+
407
+ $remoteGet = wp_remote_get($url);
408
+
409
+ if(is_array($remoteGet) && !empty($remoteGet['headers']['x-frame-options'])) {
410
+ $siteUrl = esc_url($_POST['siteUrl']);
411
+ $xFrameOptions = $remoteGet['headers']['x-frame-options'];
412
+ $mayNotShow = false;
413
+
414
+ if($xFrameOptions == 'deny') {
415
+ $mayNotShow = true;
416
+ } else if($xFrameOptions == 'SAMEORIGIN') {
417
+ if(strpos($url, $siteUrl) === false) {
418
+ $mayNotShow = true;
419
+ }
420
+ } else {
421
+ if(strpos($xFrameOptions, $siteUrl) === false) {
422
+ $mayNotShow = true;;
423
+ }
424
+ }
425
+
426
+ if($mayNotShow) {
427
+ echo $status;
428
+ wp_die();
429
+ }
430
+ }
431
+
432
+ // $remoteGet['response']['code'] < 400 it's mean correct status
433
+ if(is_array($remoteGet) && isset($remoteGet['response']['code']) && $remoteGet['response']['code'] < 400) {
434
+ $status = SGPB_AJAX_STATUS_TRUE;
435
+ }
436
+
437
+ echo $status;
438
+ wp_die();
439
+ }
440
+
441
+ // proEndGold
442
+
443
+ public function changePopupStatus()
444
+ {
445
+ $popupId = (int)$_POST['popupId'];
446
+ $obj = SGPopup::find($popupId);
447
+ $isDraft = '';
448
+ $postStatus = get_post_status($popupId);
449
+ if($postStatus == 'draft') {
450
+ $isDraft = '_preview';
451
+ }
452
+
453
+ if(!$obj || !is_object($obj)) {
454
+ wp_die(SGPB_AJAX_STATUS_FALSE);
455
+ }
456
+ $options = $obj->getOptions();
457
+ $options['sgpb-is-active'] = sanitize_text_field($_POST['popupStatus']);
458
+
459
+ unset($options['sgpb-conditions']);
460
+ update_post_meta($popupId, 'sg_popup_options'.$isDraft, $options);
461
+
462
+ wp_die($popupId);
463
+ }
464
+
465
+ public function subscriptionSubmission()
466
+ {
467
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
468
+ $this->setPostData($_POST);
469
+ $submissionData = $this->getValueFromPost('formData');
470
+ $popupPostId = (int)$this->getValueFromPost('popupPostId');
471
+
472
+ parse_str($submissionData, $formData);
473
+
474
+ if(empty($formData)) {
475
+ echo SGPB_AJAX_STATUS_FALSE;
476
+ wp_die();
477
+ }
478
+
479
+ $hiddenChecker = sanitize_text_field($formData['sgpb-subs-hidden-checker']);
480
+
481
+ // this check is made to protect ourselves from bot
482
+ if(!empty($hiddenChecker)) {
483
+ echo 'Bot';
484
+ wp_die();
485
+ }
486
+ global $wpdb;
487
+
488
+ $status = SGPB_AJAX_STATUS_FALSE;
489
+ $date = date('Y-m-d');
490
+ $email = sanitize_email($formData['sgpb-subs-email']);
491
+ $firstName = sanitize_text_field($formData['sgpb-subs-first-name']);
492
+ $lastName = sanitize_text_field($formData['sgpb-subs-last-name']);
493
+
494
+ $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
495
+
496
+ $getSubscriberQuery = $wpdb->prepare('SELECT id FROM '.$subscribersTableName.' WHERE email = %s AND subscriptionType = %d', $email, $popupPostId);
497
+ $list = $wpdb->get_row($getSubscriberQuery, ARRAY_A);
498
+
499
+ // When subscriber does not exist we insert to subscribers table otherwise we update user info
500
+ if(empty($list['id'])) {
501
+ $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType) VALUES (%s, %s, %s, %s, %d) ', $firstName, $lastName, $email, $date, $popupPostId);
502
+ $res = $wpdb->query($sql);
503
+ } else {
504
+ $sql = $wpdb->prepare('UPDATE '.$subscribersTableName.' SET firstName = %s, lastName = %s, email = %s, cDate = %s, subscriptionType = %d WHERE id = %d', $firstName, $lastName, $email, $date, $popupPostId, $list['id']);
505
+ $wpdb->query($sql);
506
+ $res = 1;
507
+ }
508
+ if($res) {
509
+ $status = SGPB_AJAX_STATUS_TRUE;
510
+ }
511
+
512
+ echo $status;
513
+ wp_die();
514
+ }
515
+
516
+ public function sgpbSubsciptionFormSubmittedAction()
517
+ {
518
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
519
+ $this->setPostData($_POST);
520
+
521
+ $submissionData = $this->getValueFromPost('formData');
522
+ $popupPostId = (int)$this->getValueFromPost('popupPostId');
523
+ parse_str($submissionData, $formData);
524
+ if(empty($_POST)) {
525
+ echo SGPB_AJAX_STATUS_FALSE;
526
+ wp_die();
527
+ }
528
+ $email = sanitize_email($_POST['emailValue']);
529
+ $firstName = sanitize_text_field($_POST['firstNameValue']);
530
+ $lastName = sanitize_text_field($_POST['lastNameValue']);
531
+ $userData = array(
532
+ 'email' => $email,
533
+ 'firstName' => $firstName,
534
+ 'lastName' => $lastName
535
+ );
536
+ $this->sendSuccessEmails($popupPostId, $userData);
537
+ do_action('sgpbProcessAfterSuccessfulSubmission', $popupPostId, $userData);
538
+ }
539
+
540
+ public function sendSuccessEmails($popupPostId, $subscriptionDetails)
541
+ {
542
+ global $wpdb;
543
+ $popup = SGPopup::find($popupPostId);
544
+
545
+ if(!is_object($popup)) {
546
+ return false;
547
+ }
548
+ $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
549
+
550
+ $getSubscriberCountQuery = $wpdb->prepare('SELECT COUNT(id) as countIds FROM '.$subscribersTableName.' WHERE subscriptionType = %d', $popupPostId);
551
+ $count = $wpdb->get_row($getSubscriberCountQuery, ARRAY_A);
552
+
553
+ $popupOptions = $popup->getOptions();
554
+ $adminUserName = 'admin';
555
+
556
+ $adminEmail = get_option('admin_email');
557
+ $userData = @get_user_by('email', $adminEmail);
558
+
559
+ if(!empty($userData)) {
560
+ $adminUserName = $userData->display_name;
561
+ }
562
+
563
+ $newSubscriberEmailHeader = AdminHelper::getEmailHeader($adminEmail);
564
+ $takeReviewAfterFirstSubscription = get_option('sgpb-new-subscriber');
565
+
566
+ if($count['countIds'] == 1 && !$takeReviewAfterFirstSubscription) {
567
+ // take review
568
+ update_option('sgpb-new-subscriber', 1);
569
+ $newSubscriberEmailTitle = __('Congrats! You have already 1 subscriber!', SG_POPUP_TEXT_DOMAIN);
570
+ $reviewEmailTemplate = AdminHelper::getFileFromURL(SG_POPUP_EMAIL_TEMPLATES_URL.'takeReviewAfterSubscribe.html');
571
+ $reviewEmailTemplate = preg_replace('/\[adminUserName]/', $adminUserName, $reviewEmailTemplate);
572
+ $sendStatus = wp_mail($adminEmail, $newSubscriberEmailTitle, $reviewEmailTemplate, $newSubscriberEmailHeader); //return true or false
573
+ }
574
+ }
575
+
576
+ public function select2SearchData()
577
+ {
578
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
579
+
580
+ $postTypeName = sanitize_text_field($_POST['searchKey']);
581
+ $search = sanitize_text_field($_POST['searchTerm']);
582
+ $searchResults = $this->selectFromPost($postTypeName, $search);
583
+
584
+ if(isset($_POST['searchCallback'])) {
585
+ $searchCallback = sanitize_text_field($_POST['searchCallback']);
586
+ $searchResults = apply_filters('sgpbSearchAdditionalData', $search, array());
587
+ }
588
+
589
+ if(empty($searchResults)) {
590
+ $results['items'] = array();
591
+ }
592
+
593
+ /*Selected custom post type convert for select2 format*/
594
+ foreach($searchResults as $id => $name) {
595
+ $results['items'][] = array(
596
+ 'id' => $id,
597
+ 'text' => $name
598
+ );
599
+ }
600
+
601
+ echo json_encode($results);
602
+ wp_die();
603
+ }
604
+
605
+ private function selectFromPost($postTypeName, $search)
606
+ {
607
+ $args = array(
608
+ 's' => $search,
609
+ 'post__in' => !empty($_REQUEST['include']) ? array_map('intval', $_REQUEST['include']) : null,
610
+ 'page' => !empty($_REQUEST['page']) ? absint($_REQUEST['page']) : null,
611
+ 'posts_per_page' => 100,
612
+ 'post_type' => $postTypeName
613
+ );
614
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
615
+
616
+ return $searchResults;
617
+ }
618
+
619
+ public function addConditionGroupRow()
620
+ {
621
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
622
+ global $SGPB_DATA_CONFIG_ARRAY;
623
+
624
+ $groupId = (int)$_POST['groupId'];
625
+ $targetType = sanitize_text_field($_POST['conditionName']);
626
+ $addedObj = array();
627
+
628
+ $builderObj = new ConditionBuilder();
629
+
630
+ $builderObj->setGroupId($groupId);
631
+ $builderObj->setRuleId(SG_CONDITION_FIRST_RULE);
632
+ $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
633
+ $builderObj->setConditionName($targetType);
634
+ $addedObj[] = $builderObj;
635
+
636
+ $creator = new ConditionCreator($addedObj);
637
+ echo $creator->render();
638
+ wp_die();
639
+ }
640
+
641
+ public function addConditionRuleRow()
642
+ {
643
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
644
+ $data = '';
645
+ global $SGPB_DATA_CONFIG_ARRAY;
646
+ $targetType = sanitize_text_field($_POST['conditionName']);
647
+ $builderObj = new ConditionBuilder();
648
+
649
+ $groupId = (int)$_POST['groupId'];
650
+ $ruleId = (int)$_POST['ruleId'];
651
+
652
+ $builderObj->setGroupId($groupId);
653
+ $builderObj->setRuleId($ruleId);
654
+ $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
655
+ $builderObj->setConditionName($targetType);
656
+
657
+ $data .= ConditionCreator::createConditionRuleRow($builderObj);
658
+
659
+ echo $data;
660
+ wp_die();
661
+ }
662
+
663
+ public function changeConditionRuleRow()
664
+ {
665
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
666
+ $data = '';
667
+ global $SGPB_DATA_CONFIG_ARRAY;
668
+
669
+ $targetType = sanitize_text_field($_POST['conditionName']);
670
+ $builderObj = new ConditionBuilder();
671
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$targetType];
672
+ $groupId = (int)$_POST['groupId'];
673
+ $ruleId = (int)$_POST['ruleId'];
674
+ $popupId = (int)$_POST['popupId'];
675
+ $paramName = sanitize_text_field($_POST['paramName']);
676
+
677
+ $savedData = array(
678
+ 'param' => $paramName
679
+ );
680
+
681
+ if($targetType == 'target' || $targetType == 'conditions') {
682
+ $savedData['operator'] = '==';
683
+ } else if($conditionConfig['specialDefaultOperator']) {
684
+ $savedData['operator'] = $paramName;
685
+ }
686
+
687
+ if(!empty($_POST['paramValue'])) {
688
+ $savedData['tempParam'] = sanitize_text_field($_POST['paramValue']);
689
+ $savedData['operator'] = $paramName;
690
+ }
691
+ // change operator value related to condition value
692
+ if(!empty($conditionConfig['operatorAllowInConditions']) && in_array($paramName, $conditionConfig['operatorAllowInConditions'])) {
693
+ $conditionConfig['paramsData']['operator'] = array();
694
+
695
+ if(!empty($conditionConfig['paramsData'][$paramName.'Operator'])) {
696
+ $operatorData = $conditionConfig['paramsData'][$paramName.'Operator'];
697
+ $SGPB_DATA_CONFIG_ARRAY[$targetType]['paramsData']['operator'] = $operatorData;
698
+ // change take value related to condition value
699
+ $operatorDataKeys = array_keys($operatorData);
700
+ if(!empty($operatorDataKeys[0])) {
701
+ $savedData['operator'] = $operatorDataKeys[0];
702
+ $builderObj->setTakeValueFrom('operator');
703
+ }
704
+ }
705
+ }
706
+ // by default set empty value for users' role (adv. tar.)
707
+ $savedData['value'] = array();
708
+ $savedData['hiddenOption'] = @$conditionConfig['hiddenOptionData'][$paramName];
709
+
710
+ $builderObj->setPopupId($popupId);
711
+ $builderObj->setGroupId($groupId);
712
+ $builderObj->setRuleId($ruleId);
713
+ $builderObj->setSavedData($savedData);
714
+ $builderObj->setConditionName($targetType);
715
+
716
+ $data .= ConditionCreator::createConditionRuleRow($builderObj);
717
+
718
+ echo $data;
719
+ wp_die();
720
+ }
721
+ }
com/classes/ConditionBuilder.php CHANGED
@@ -1,246 +1,246 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class ConditionBuilder
5
- {
6
- private $savedData = array();
7
- private $groupId = 0;
8
- private $ruleId = 0;
9
- private $conditionName;
10
- private $groupTotal;
11
- private $popupId;
12
- private $takeValueFrom = 'param';
13
-
14
- public function setSavedData($savedData)
15
- {
16
- $this->savedData = $savedData;
17
- }
18
-
19
- public function getSavedData()
20
- {
21
- return $this->savedData;
22
- }
23
-
24
- public function setGroupTotal($groupTotal)
25
- {
26
- $this->groupTotal = $groupTotal;
27
- }
28
-
29
- public function getGroupTotal()
30
- {
31
- return $this->groupTotal;
32
- }
33
-
34
- public function setPopupId($popupId)
35
- {
36
- $this->popupId = $popupId;
37
- }
38
-
39
- public function getPopupId()
40
- {
41
- return $this->popupId;
42
- }
43
-
44
- public function setGroupId($groupId)
45
- {
46
- $this->groupId = $groupId;
47
- }
48
-
49
- public function getGroupId()
50
- {
51
- return $this->groupId;
52
- }
53
-
54
- public function setRuleId($ruleId)
55
- {
56
- $this->ruleId = $ruleId;
57
- }
58
-
59
- public function getRuleId()
60
- {
61
- return $this->ruleId;
62
- }
63
-
64
- public function setTakeValueFrom($takeValueFrom)
65
- {
66
- $this->takeValueFrom = $takeValueFrom;
67
- }
68
-
69
- public function getTakeValueFrom()
70
- {
71
- return $this->takeValueFrom;
72
- }
73
-
74
- public function setConditionName($conditionName)
75
- {
76
- $this->conditionName = $conditionName;
77
- }
78
-
79
- public function getConditionName()
80
- {
81
- return $this->conditionName;
82
- }
83
-
84
- public static function createTargetConditionBuilder($conditionData = array())
85
- {
86
- $targetColumns = array();
87
-
88
- if(empty($conditionData)) {
89
- return $targetColumns;
90
- }
91
-
92
- foreach($conditionData as $groupId => $groupData) {
93
-
94
- if(empty($groupData)) {
95
- continue;
96
- }
97
-
98
- foreach($groupData as $ruleId => $ruleData) {
99
- $builderObj = new ConditionBuilder();
100
- $builderObj->setGroupId($groupId);
101
- $builderObj->setRuleId($ruleId);
102
- /*Assoc array where key option name value saved Data*/
103
- $builderObj->setSavedData($ruleData);
104
- $builderObj->setConditionName('target');
105
- $builderObj->setGroupTotal(sizeof($groupData) - 1);
106
- $targetColumns[] = $builderObj;
107
- }
108
- }
109
-
110
- return $targetColumns;
111
- }
112
-
113
- public static function createEventsConditionBuilder($conditionData)
114
- {
115
- $eventsDataObj = array();
116
-
117
- if(empty($conditionData)) {
118
- return $eventsDataObj;
119
- }
120
-
121
- foreach($conditionData as $groupId => $groupData) {
122
-
123
- if(empty($groupData) || !is_array($groupData)) {
124
- continue;
125
- }
126
- global $SGPB_DATA_CONFIG_ARRAY;
127
- $eventsData = $SGPB_DATA_CONFIG_ARRAY['events']['operatorAllowInConditions'];
128
- foreach($groupData as $ruleId => $ruleData) {
129
- $builderObj = new ConditionBuilder();
130
- $builderObj->setGroupId($groupId);
131
- $builderObj->setRuleId($ruleId);
132
- /*Assoc array where key option name value saved Data*/
133
- $builderObj->setSavedData($ruleData);
134
- $builderObj->setConditionName('events');
135
-
136
- // in some cases value data must take from operator
137
- if (is_array($eventsData) && in_array($ruleData['param'], $eventsData)) {
138
- $builderObj->setTakeValueFrom('operator');
139
- }
140
-
141
- $builderObj->setGroupTotal(sizeof($groupData) - 1);
142
- $eventsDataObj[] = $builderObj;
143
- }
144
- }
145
-
146
- return $eventsDataObj;
147
- }
148
-
149
- public static function createConditionBuilder($conditionData)
150
- {
151
- $eventsDataObj = array();
152
-
153
- if(empty($conditionData)) {
154
- return $eventsDataObj;
155
- }
156
-
157
- foreach($conditionData as $groupId => $groupData) {
158
-
159
- if(empty($groupData) || !is_array($groupData)) {
160
- continue;
161
- }
162
-
163
- foreach($groupData as $ruleId => $ruleData) {
164
- $builderObj = new ConditionBuilder();
165
- $builderObj->setGroupId($groupId);
166
- $builderObj->setRuleId($ruleId);
167
- /*Assoc array where key option name value saved Data*/
168
- $builderObj->setSavedData($ruleData);
169
- $builderObj->setConditionName('conditions');
170
-
171
- $builderObj->setGroupTotal(sizeof($groupData) - 1);
172
- $eventsDataObj[] = $builderObj;
173
- }
174
- }
175
-
176
- return $eventsDataObj;
177
- }
178
-
179
- public static function createBehaviorAfterSpecialEventsConditionBuilder($data)
180
- {
181
- $dataObj = array();
182
-
183
- if (empty($data)) {
184
- return $dataObj;
185
- }
186
-
187
- foreach ($data as $groupId => $groupData) {
188
- if (empty($groupData)) {
189
- continue;
190
- }
191
-
192
- foreach ($groupData as $ruleId => $ruleData) {
193
- $builderObj = new ConditionBuilder();
194
- $builderObj->setGroupId($groupId);
195
- $builderObj->setRuleId($ruleId);
196
- $builderObj->setSavedData($ruleData);
197
- $builderObj->setConditionName('behavior-after-special-events');
198
- $builderObj->setGroupTotal(count($groupData) - 1);
199
- $builderObj->setTakeValueFrom('operator');
200
- $dataObj[] = $builderObj;
201
- }
202
- }
203
-
204
- return $dataObj;
205
- }
206
-
207
- public static function additionalConditionBuilder()
208
- {
209
- $dataObj = apply_filters('sgpbAdditionalConditionBuilder', array());
210
-
211
- if (empty($dataObj)) {
212
- return array();
213
- }
214
- $allCondition = array();
215
- $result = array();
216
-
217
- foreach ($dataObj as $data) {
218
- if (empty($data['conditionName'])) {
219
- continue;
220
- }
221
- $conditionName = $data['conditionName'];
222
- unset($data['conditionName']);
223
-
224
- foreach ($data as $groupId => $groupData) {
225
-
226
- if (empty($groupData)) {
227
- continue;
228
- }
229
-
230
- foreach ($groupData as $ruleId => $ruleData) {
231
-
232
- $builderObj = new ConditionBuilder();
233
- $builderObj->setGroupId(0);
234
- $builderObj->setRuleId($ruleId);
235
- $builderObj->setSavedData($ruleData);
236
- $builderObj->setConditionName($conditionName);
237
- $builderObj->setGroupTotal(count($groupData) - 1);
238
- $allCondition[] = $builderObj;
239
- }
240
- }
241
- $result[$conditionName] = $allCondition;
242
- }
243
-
244
- return $result;
245
- }
246
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class ConditionBuilder
5
+ {
6
+ private $savedData = array();
7
+ private $groupId = 0;
8
+ private $ruleId = 0;
9
+ private $conditionName;
10
+ private $groupTotal;
11
+ private $popupId;
12
+ private $takeValueFrom = 'param';
13
+
14
+ public function setSavedData($savedData)
15
+ {
16
+ $this->savedData = $savedData;
17
+ }
18
+
19
+ public function getSavedData()
20
+ {
21
+ return $this->savedData;
22
+ }
23
+
24
+ public function setGroupTotal($groupTotal)
25
+ {
26
+ $this->groupTotal = $groupTotal;
27
+ }
28
+
29
+ public function getGroupTotal()
30
+ {
31
+ return $this->groupTotal;
32
+ }
33
+
34
+ public function setPopupId($popupId)
35
+ {
36
+ $this->popupId = $popupId;
37
+ }
38
+
39
+ public function getPopupId()
40
+ {
41
+ return $this->popupId;
42
+ }
43
+
44
+ public function setGroupId($groupId)
45
+ {
46
+ $this->groupId = $groupId;
47
+ }
48
+
49
+ public function getGroupId()
50
+ {
51
+ return $this->groupId;
52
+ }
53
+
54
+ public function setRuleId($ruleId)
55
+ {
56
+ $this->ruleId = $ruleId;
57
+ }
58
+
59
+ public function getRuleId()
60
+ {
61
+ return $this->ruleId;
62
+ }
63
+
64
+ public function setTakeValueFrom($takeValueFrom)
65
+ {
66
+ $this->takeValueFrom = $takeValueFrom;
67
+ }
68
+
69
+ public function getTakeValueFrom()
70
+ {
71
+ return $this->takeValueFrom;
72
+ }
73
+
74
+ public function setConditionName($conditionName)
75
+ {
76
+ $this->conditionName = $conditionName;
77
+ }
78
+
79
+ public function getConditionName()
80
+ {
81
+ return $this->conditionName;
82
+ }
83
+
84
+ public static function createTargetConditionBuilder($conditionData = array())
85
+ {
86
+ $targetColumns = array();
87
+
88
+ if(empty($conditionData)) {
89
+ return $targetColumns;
90
+ }
91
+
92
+ foreach($conditionData as $groupId => $groupData) {
93
+
94
+ if(empty($groupData)) {
95
+ continue;
96
+ }
97
+
98
+ foreach($groupData as $ruleId => $ruleData) {
99
+ $builderObj = new ConditionBuilder();
100
+ $builderObj->setGroupId($groupId);
101
+ $builderObj->setRuleId($ruleId);
102
+ /*Assoc array where key option name value saved Data*/
103
+ $builderObj->setSavedData($ruleData);
104
+ $builderObj->setConditionName('target');
105
+ $builderObj->setGroupTotal(sizeof($groupData) - 1);
106
+ $targetColumns[] = $builderObj;
107
+ }
108
+ }
109
+
110
+ return $targetColumns;
111
+ }
112
+
113
+ public static function createEventsConditionBuilder($conditionData)
114
+ {
115
+ $eventsDataObj = array();
116
+
117
+ if(empty($conditionData)) {
118
+ return $eventsDataObj;
119
+ }
120
+
121
+ foreach($conditionData as $groupId => $groupData) {
122
+
123
+ if(empty($groupData) || !is_array($groupData)) {
124
+ continue;
125
+ }
126
+ global $SGPB_DATA_CONFIG_ARRAY;
127
+ $eventsData = $SGPB_DATA_CONFIG_ARRAY['events']['operatorAllowInConditions'];
128
+ foreach($groupData as $ruleId => $ruleData) {
129
+ $builderObj = new ConditionBuilder();
130
+ $builderObj->setGroupId($groupId);
131
+ $builderObj->setRuleId($ruleId);
132
+ /*Assoc array where key option name value saved Data*/
133
+ $builderObj->setSavedData($ruleData);
134
+ $builderObj->setConditionName('events');
135
+
136
+ // in some cases value data must take from operator
137
+ if (is_array($eventsData) && in_array($ruleData['param'], $eventsData)) {
138
+ $builderObj->setTakeValueFrom('operator');
139
+ }
140
+
141
+ $builderObj->setGroupTotal(sizeof($groupData) - 1);
142
+ $eventsDataObj[] = $builderObj;
143
+ }
144
+ }
145
+
146
+ return $eventsDataObj;
147
+ }
148
+
149
+ public static function createConditionBuilder($conditionData)
150
+ {
151
+ $eventsDataObj = array();
152
+
153
+ if(empty($conditionData)) {
154
+ return $eventsDataObj;
155
+ }
156
+
157
+ foreach($conditionData as $groupId => $groupData) {
158
+
159
+ if(empty($groupData) || !is_array($groupData)) {
160
+ continue;
161
+ }
162
+
163
+ foreach($groupData as $ruleId => $ruleData) {
164
+ $builderObj = new ConditionBuilder();
165
+ $builderObj->setGroupId($groupId);
166
+ $builderObj->setRuleId($ruleId);
167
+ /*Assoc array where key option name value saved Data*/
168
+ $builderObj->setSavedData($ruleData);
169
+ $builderObj->setConditionName('conditions');
170
+
171
+ $builderObj->setGroupTotal(sizeof($groupData) - 1);
172
+ $eventsDataObj[] = $builderObj;
173
+ }
174
+ }
175
+
176
+ return $eventsDataObj;
177
+ }
178
+
179
+ public static function createBehaviorAfterSpecialEventsConditionBuilder($data)
180
+ {
181
+ $dataObj = array();
182
+
183
+ if (empty($data)) {
184
+ return $dataObj;
185
+ }
186
+
187
+ foreach ($data as $groupId => $groupData) {
188
+ if (empty($groupData)) {
189
+ continue;
190
+ }
191
+
192
+ foreach ($groupData as $ruleId => $ruleData) {
193
+ $builderObj = new ConditionBuilder();
194
+ $builderObj->setGroupId($groupId);
195
+ $builderObj->setRuleId($ruleId);
196
+ $builderObj->setSavedData($ruleData);
197
+ $builderObj->setConditionName('behavior-after-special-events');
198
+ $builderObj->setGroupTotal(count($groupData) - 1);
199
+ $builderObj->setTakeValueFrom('operator');
200
+ $dataObj[] = $builderObj;
201
+ }
202
+ }
203
+
204
+ return $dataObj;
205
+ }
206
+
207
+ public static function additionalConditionBuilder()
208
+ {
209
+ $dataObj = apply_filters('sgpbAdditionalConditionBuilder', array());
210
+
211
+ if (empty($dataObj)) {
212
+ return array();
213
+ }
214
+ $allCondition = array();
215
+ $result = array();
216
+
217
+ foreach ($dataObj as $data) {
218
+ if (empty($data['conditionName'])) {
219
+ continue;
220
+ }
221
+ $conditionName = $data['conditionName'];
222
+ unset($data['conditionName']);
223
+
224
+ foreach ($data as $groupId => $groupData) {
225
+
226
+ if (empty($groupData)) {
227
+ continue;
228
+ }
229
+
230
+ foreach ($groupData as $ruleId => $ruleData) {
231
+
232
+ $builderObj = new ConditionBuilder();
233
+ $builderObj->setGroupId(0);
234
+ $builderObj->setRuleId($ruleId);
235
+ $builderObj->setSavedData($ruleData);
236
+ $builderObj->setConditionName($conditionName);
237
+ $builderObj->setGroupTotal(count($groupData) - 1);
238
+ $allCondition[] = $builderObj;
239
+ }
240
+ }
241
+ $result[$conditionName] = $allCondition;
242
+ }
243
+
244
+ return $result;
245
+ }
246
+ }
com/classes/ConditionCreator.php CHANGED
@@ -1,668 +1,668 @@
1
- <?php
2
- namespace sgpb;
3
- class ConditionCreator
4
- {
5
- public function __construct($targetData)
6
- {
7
- if (!empty($targetData)) {
8
- $this->setConditionsObj($targetData);
9
- }
10
- }
11
-
12
- private $conditionsObj;
13
- //When there is not group set groupId -1
14
- private $prevGroupId = -1;
15
-
16
- public function setPrevGroupId($prevGroupId)
17
- {
18
- $this->prevGroupId = $prevGroupId;
19
- }
20
-
21
- public function getPrevGroupId()
22
- {
23
- return $this->prevGroupId;
24
- }
25
-
26
- public function setConditionsObj($conditionsObj)
27
- {
28
- $this->conditionsObj = $conditionsObj;
29
- }
30
-
31
- public function getConditionsObj()
32
- {
33
- return $this->conditionsObj;
34
- }
35
-
36
- public function render()
37
- {
38
- $conditionsObj = $this->getConditionsObj();
39
- $view = '';
40
-
41
- if (empty($conditionsObj)) {
42
- return array();
43
- }
44
-
45
- foreach ($conditionsObj as $conditionObj) {
46
-
47
- $currentGroupId = $conditionObj->getGroupId();
48
-
49
- $prevGroupId = $this->getPrevGroupId();
50
- $openGroupDiv = '';
51
- $separator = '';
52
- $closePrevGroupDiv = '';
53
-
54
- if ($currentGroupId > $prevGroupId) {
55
- if ($currentGroupId != 0) {
56
- $closePrevGroupDiv = '</div>';
57
- $separator = ConditionCreator::getOrRuleSeparator();
58
- }
59
- $openGroupDiv = '<div class="sgpb-wrapper sgpb-box-'.$conditionObj->getConditionName().' sg-target-group sg-target-group-'.$conditionObj->getGroupId().'" data-group-id="'.$currentGroupId.'">';
60
- }
61
-
62
- $view .= $closePrevGroupDiv;
63
- $view .= $separator;
64
- $view .= $openGroupDiv;
65
- $view .= ConditionCreator::createConditionRuleRow($conditionObj);
66
-
67
- $this->setPrevGroupId($currentGroupId);
68
- }
69
-
70
- $view .= '</div>';
71
-
72
- return $view;
73
- }
74
-
75
- public static function getOrRuleSeparator()
76
- {
77
- return '<h4 class="sgpb-rules-or"><span>'.__('OR', SG_POPUP_TEXT_DOMAIN).'</span></h4>';
78
- }
79
-
80
- public static function createConditionRuleRow($conditionDataObj)
81
- {
82
- ob_start();
83
- ?>
84
- <div class="events form sg-target-rule sgpb-margin-bottom-40 sg-target-rule-<?php echo $conditionDataObj->getRuleId(); ?> sgpb-event-row" data-rule-id="<?php echo $conditionDataObj->getRuleId(); ?>">
85
- <div class="formItem sgpb-align-item-start">
86
- <?php
87
- $savedData = $conditionDataObj->getSavedData();
88
-
89
- if (!isset($savedData['value'])) {
90
- $savedData['value'] = '';
91
- }
92
- ?>
93
- <?php $idHiddenDiv = $conditionDataObj->getConditionName().'_'.$conditionDataObj->getGroupId().'_'.$conditionDataObj->getRuleId();?>
94
- <?php foreach ($savedData as $conditionName => $conditionSavedData): ?>
95
- <?php
96
- $showRowStatusClass = '';
97
- $hideStatus = self::getParamRowHideStatus($conditionDataObj, $conditionName);
98
- $ruleElementData = self::getRuleElementData($conditionDataObj, 'param');
99
- $ruleSavedData = $ruleElementData['saved'];
100
- $currentArgs = array('savedData' => $ruleSavedData, 'conditionName' => $conditionName);
101
-
102
- if (!self::allowToShowOperatorColumn($conditionDataObj, $currentArgs)) {
103
- $hideStatus = true;
104
- }
105
- $showRowStatusClass = ($hideStatus) ? 'sgpb-hide-condition-row' : $showRowStatusClass;
106
- ?>
107
- <?php if ($conditionName != 'hiddenOption'): ?>
108
- <div data-condition-name="<?php echo $conditionName;?>" class="<?php echo 'inputBlock sg-condition-'.$conditionName.'-wrapper'.' '.$showRowStatusClass; ?>">
109
- <?php
110
- if (!$hideStatus) {
111
- echo self::createConditionElement($conditionDataObj, $conditionName);
112
- }
113
- ?>
114
- </div>
115
- <?php endif; ?>
116
- <?php if (($conditionName == 'hiddenOption')): ?>
117
- <?php $hiddenContent = self::getHiddenDataContent($conditionDataObj); ?>
118
- <div class="sgpb-hide-condition-row"><div id="<?php echo $idHiddenDiv;?>"><?php echo $hiddenContent; ?></div></div>
119
- <?php endif; ?>
120
- <?php endforeach;?>
121
- <?php echo self::createConditionOperators($conditionDataObj, $idHiddenDiv); ?>
122
- </div>
123
- </div>
124
- <?php
125
- $targetOptionRow = ob_get_contents();
126
- ob_end_clean();
127
-
128
- return $targetOptionRow;
129
- }
130
-
131
- private static function allowToShowOperatorColumn($conditionDataObj, $currentArgs = array())
132
- {
133
- global $SGPB_DATA_CONFIG_ARRAY;
134
- $conditionName = $conditionDataObj->getConditionName();
135
- $conditionData = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
136
- $operatorAllowInConditions = array();
137
-
138
- if (!empty($conditionData['operatorAllowInConditions'])) {
139
- $operatorAllowInConditions = $conditionData['operatorAllowInConditions'];
140
- }
141
-
142
- $savedData = $conditionDataObj->getSavedData();
143
-
144
- $status = true;
145
-
146
- if ($currentArgs['conditionName'] == 'operator') {
147
- $currentSavedData = $currentArgs['savedData'];
148
-
149
- if (($currentSavedData == 'not_rule' || $currentSavedData == 'select_role' || $currentSavedData == 'select_event')) {
150
- $status = false;
151
- }
152
-
153
- // unset old customOperator
154
- $SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['customOperator'] = '';
155
- if (is_array($operatorAllowInConditions)) {
156
-
157
- if (in_array($savedData['param'], $operatorAllowInConditions)) {
158
- $operator = '';
159
- if (!empty($conditionData['paramsData'][$savedData['param'].'Operator'])) {
160
- $operator = $conditionData['paramsData'][$savedData['param'].'Operator'];
161
- }
162
- $SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['customOperator'] = $operator;
163
- return true;
164
- }
165
- // there is no need to show is/is not column for not specific conditions (everywhere, all posts/pages/other_custom_post_types)
166
- if (isset($savedData['param']) && !is_array($savedData['param']) && (strpos($savedData['param'], '_all') || $savedData['param'] == 'everywhere' || $savedData['param'] == 'post_tags')) {
167
- return false;
168
- }
169
- if (!empty($savedData['tempParam']) && in_array($savedData['tempParam'], $operatorAllowInConditions)) {
170
- $SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['operator'] = $conditionData['paramsData'][$savedData['tempParam'].'Operator'];
171
- }
172
- }
173
-
174
- if (empty($SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['operator'])) {
175
- $status = false;
176
- }
177
- }
178
-
179
- return $status;
180
- }
181
-
182
- public static function createConditionOperators($conditionDataObj, $idHiddenDiv = '')
183
- {
184
- global $SGPB_DATA_CONFIG_ARRAY;
185
- $groupId = $conditionDataObj->getRuleId();
186
- $groupTotal = $conditionDataObj->getGroupTotal();
187
-
188
- $conditionName = $conditionDataObj->getConditionName();
189
- $operatorsHtml = '';
190
- $conditionData = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
191
- $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
192
-
193
- $operatorsData = $conditionData['operators'];
194
- $eventButtonClasses = '';
195
- $eventButtonWrapperClass = '';
196
- $icon = '';
197
-
198
- if (empty($operatorsData)) {
199
- return $operatorsHtml;
200
- }
201
-
202
- foreach ($operatorsData as $operator) {
203
- $identificatorClass = '';
204
- $style = '';
205
- if (!isset($eventsData['hiddenOptionData'])) {
206
- continue;
207
- }
208
- $saveData = $conditionDataObj->getSavedData();
209
- if (empty($saveData['hiddenOption']) && $operator['name'] == 'Edit' && $saveData["param"] != 'load') {
210
- continue;
211
- }
212
- if ($operator['name'] == 'Edit') {
213
- $operator['name'] = 'Settings';
214
- }
215
-
216
- if ($operator['operator'] == 'edit') {
217
- $icon = 'D';
218
- $btnClass = ' icons_gray';
219
- $identificatorClass = $idHiddenDiv;
220
- $eventButtonClasses = 'sgpb-rules-'.$operator['operator'].'-rule ';
221
- }
222
- if ($operator['operator'] == 'add') {
223
- $icon = 'L';
224
- $btnClass = ' icons_blue';
225
- $eventButtonClasses = 'sgpb-rules-'.$operator['operator'].'-rule ';
226
- //Don't show add button if it's not for last element
227
- if ($groupId < $groupTotal) {
228
- $style = 'style="display: none;"';
229
- }
230
- }
231
- if ($operator['operator'] == 'delete') {
232
- $icon = 'I';
233
- $btnClass = ' icons_pink';
234
- $eventButtonClasses = 'sgpb-rules-'.$operator['operator'].'-rule ';
235
- }
236
-
237
- $element = '<i class="sgpb-icons '.$btnClass.'" data-id="'.$identificatorClass.'">'.$icon.'</i>';
238
-
239
- $operatorsHtml .= '<div class="'.$eventButtonClasses.' sgpb-rules-'.$operator['operator'].'-button-wrapper" '.$style.'>';
240
- $operatorsHtml .= $element;
241
- $operatorsHtml .= '</div>';
242
- }
243
-
244
- return $operatorsHtml;
245
- }
246
-
247
- public static function createConditionElement($conditionDataObj, $ruleName)
248
- {
249
- //more code added because of the lack of abstraction
250
- //todo: remove ASAP if possible
251
- $sData = $conditionDataObj->getSavedData();
252
- if ($ruleName == 'param' && !empty($sData['tempParam'])) {
253
- $sData['param'] = $sData['tempParam'];
254
- $newObj = clone $conditionDataObj;
255
- $newObj->setSavedData($sData);
256
- $conditionDataObj = $newObj;
257
- }
258
-
259
- $element = '';
260
-
261
- $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
262
- $elementHeader = self::createRuleHeader($ruleElementData);
263
- $field = self::createRuleField($ruleElementData);
264
- $element .= $elementHeader;
265
- $element .= $field;
266
-
267
- return $element;
268
- }
269
-
270
- public static function createConditionField($conditionDataObj, $ruleName)
271
- {
272
- $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
273
-
274
- return self::createRuleField($ruleElementData);
275
- }
276
-
277
- public static function createConditionFieldHeader($conditionDataObj, $ruleName)
278
- {
279
- $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
280
-
281
- return self::createRuleHeader($ruleElementData);
282
- }
283
-
284
- public static function optionLabelSupplement($conditionDataObj, $ruleName)
285
- {
286
- global $SGPB_DATA_CONFIG_ARRAY;
287
- $conditionName = $conditionDataObj->getConditionName();
288
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
289
- $attrs = $conditionConfig['attrs'][$ruleName];
290
-
291
- if (isset($attrs['infoAttrs']['rightLabel'])) {
292
- $labelData = $attrs['infoAttrs']['rightLabel'];
293
- $value = $labelData['value'];
294
- $classes = $labelData['classes'];
295
- return '<span class="'.esc_attr($classes).'">'.$value.'</span>';
296
- }
297
-
298
- return '';
299
- }
300
-
301
- private static function getRuleElementData($conditionDataObj, $ruleName = '')
302
- {
303
- global $SGPB_DATA_CONFIG_ARRAY;
304
- $ruleElementData = array();
305
- $savedParam = '';
306
- $conditionName = $conditionDataObj->getConditionName();
307
- $saveData = $conditionDataObj->getSavedData();
308
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
309
- $rulesType = $conditionConfig['columnTypes'];
310
- $paramsData = $conditionConfig['paramsData'];
311
-
312
- $attrs = $conditionConfig['attrs'];
313
-
314
- if (!empty($saveData[$ruleName])) {
315
- $savedParam = $saveData[$ruleName];
316
- }
317
- else if (!empty($saveData['hiddenOption']) && isset($saveData['hiddenOption'][$ruleName])) {
318
- $savedParam = $saveData['hiddenOption'][$ruleName];
319
- }
320
-
321
- $ruleElementData['ruleName'] = $ruleName;
322
- if ($ruleName == 'value' && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
323
- $index = $conditionDataObj->getTakeValueFrom();
324
- $ruleName = $saveData[$index];
325
- }
326
-
327
- $type = array();
328
- if (!empty($rulesType[$ruleName])) {
329
- $type = $rulesType[$ruleName];
330
- }
331
- $data = array();
332
- if (!empty($paramsData[$ruleName])) {
333
- $data = $paramsData[$ruleName];
334
- }
335
-
336
- // if exists customOperator it takes the custom one
337
- if ($ruleName == 'operator' && !empty($paramsData['customOperator'])) {
338
- $data = $paramsData['customOperator'];
339
- }
340
-
341
- $optionAttr = array();
342
- if (!empty($attrs[$ruleName])) {
343
- $optionAttr = $attrs[$ruleName];
344
- }
345
-
346
- $attr = array();
347
-
348
- if (!empty($optionAttr['htmlAttrs'])) {
349
- $attr = $optionAttr['htmlAttrs'];
350
- }
351
-
352
- $ruleElementData['type'] = $type;
353
- $ruleElementData['data'] = apply_filters('sgpb'.$ruleName.'ConditionCreator', $data, $saveData);
354
- $ruleElementData['saved'] = $savedParam;
355
- $ruleElementData['attr'] = $attr;
356
- $ruleElementData['conditionDataObj'] = $conditionDataObj;
357
-
358
- return $ruleElementData;
359
- }
360
-
361
- private static function createRuleHeader($ruleElementData)
362
- {
363
- return self::createElementHeader($ruleElementData);
364
- }
365
-
366
- public static function createRuleField($ruleElementData)
367
- {
368
- $attr = array();
369
- $type = $ruleElementData['type'];
370
- $conditionObj = $ruleElementData['conditionDataObj'];
371
-
372
- $name = 'sgpb-'.$conditionObj->getConditionName().'['.$conditionObj->getGroupId().']['.$conditionObj->getRuleId().']['.$ruleElementData['ruleName'].']';
373
- $attr['name'] = $name;
374
-
375
- if (is_array($ruleElementData['attr'])) {
376
- $attr += $ruleElementData['attr'];
377
- $attr['data-rule-id'] = $conditionObj->getRuleId();
378
- }
379
- $rowField = '';
380
-
381
- switch($type) {
382
-
383
- case 'select':
384
- if (!empty($attr['multiple'])) {
385
- $attr['name'] .= '[]';
386
- }
387
- $savedData = $ruleElementData['saved'];
388
-
389
- if (empty($ruleElementData['data'])) {
390
- $ruleElementData['data'] = $ruleElementData['saved'];
391
- $savedData = array();
392
-
393
- if (!empty($ruleElementData['saved'])) {
394
- $savedData = array_keys($ruleElementData['saved']);
395
- }
396
- }
397
-
398
- $rowField .= AdminHelper::createSelectBox($ruleElementData['data'], $savedData, $attr);
399
- break;
400
- case 'text':
401
- case 'url':
402
- case 'number':
403
- $attr['type'] = $type;
404
-
405
- //this is done to override the initial input value
406
- if (!empty($ruleElementData['saved'])) {
407
- $attr['value'] = esc_attr($ruleElementData['saved']);
408
- }
409
-
410
- $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'], $attr);
411
- break;
412
- case 'checkbox':
413
- $attr['type'] = $type;
414
- $rowField .= AdminHelper::createCheckBox($ruleElementData['data'], $ruleElementData['saved'], $attr);
415
- break;
416
- case 'conditionalText':
417
- $popupId = self::getPopupId($conditionObj);
418
- if(!empty($popupId)) {
419
- $attr['value'] = $attr['value'].$popupId;
420
- $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'].$popupId, $attr);
421
- }
422
- else {
423
- $rowField .= '<div class="sgpb-show-alert-before-save">'.$attr['beforeSaveLabel'].'</div>';
424
- }
425
- break;
426
- }
427
-
428
- return $rowField;
429
- }
430
-
431
- public static function getPopupId($conditionObj)
432
- {
433
- $popupId = 0;
434
- $conditionPopupId = $conditionObj->getPopupId();
435
-
436
- if (!empty($conditionPopupId)) {
437
- $popupId = $conditionObj->getPopupId();
438
- }
439
- else if(!empty($_GET['post'])) {
440
- $popupId = $_GET['post'];
441
- }
442
-
443
- return $popupId;
444
- }
445
-
446
- public static function createElementHeader($ruleElementData)
447
- {
448
- $labelAttributes = '';
449
- $info = '';
450
- $conditionObj = $ruleElementData['conditionDataObj'];
451
- $conditionName = $conditionObj->getConditionName();
452
- $ruleName = $ruleElementData['ruleName'];
453
- global $SGPB_DATA_CONFIG_ARRAY;
454
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
455
- $conditionAttrs = $conditionConfig['attrs'];
456
-
457
- $saveData = $conditionObj->getSavedData();
458
- $optionTitle = $ruleName;
459
- $titleKey = $ruleName;
460
-
461
-
462
- if ($ruleName == 'value' && !empty($saveData[$conditionObj->getTakeValueFrom()])) {
463
- $titleKey = $saveData[$conditionObj->getTakeValueFrom()];
464
- }
465
-
466
- if (!empty($conditionAttrs[$titleKey])) {
467
- $optionAttrs = $conditionAttrs[$titleKey];
468
- if (!empty($optionAttrs['infoAttrs'])) {
469
- // $conditionName => events, conditions, targets...
470
- // $ruleName => param, operator, value (1-st, 2-nd, 3-rd columns)
471
- $optionAttrs = apply_filters('sgpb'.$conditionName.$ruleName.'Param', $optionAttrs, $saveData);
472
- $optionTitle = $optionAttrs['infoAttrs']['label'];
473
- if (!empty($optionAttrs['infoAttrs']['labelAttrs'])) {
474
- $labelAttributes = AdminHelper::createAttrs($optionAttrs['infoAttrs']['labelAttrs']);
475
- }
476
- }
477
- }
478
- if (isset($optionAttrs['infoAttrs']['info']) && $optionAttrs['infoAttrs']['info']) {
479
- $info = '<div class="question-mark sgpb-info-icon">B</div>';
480
- $info .= '<div class="sgpb-info-wrapper">
481
- <span class="infoSelectRepeat samefontStyle sgpb-info-text" style="display: none;">'.$optionAttrs['infoAttrs']['info'].'</span>
482
- </div>';
483
- }
484
-
485
- return "<div class=\"sgpb-display-flex text\"><span class=\"inputBlock__title\" $labelAttributes>$optionTitle</span>$info</div>";
486
- }
487
-
488
- public static function getHiddenDataContent($conditionDataObj)
489
- {
490
- global $SGPB_DATA_CONFIG_ARRAY;
491
- $savedData = $conditionDataObj->getSavedData();
492
- $conditionName = $savedData['param'];
493
- $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
494
- $hiddenOptions = $eventsData['hiddenOptionData'];
495
- $ruleId = $conditionDataObj->getRuleId();
496
- if (empty($hiddenOptions[$conditionName])) {
497
- return __('No Data', SG_POPUP_TEXT_DOMAIN);
498
- }
499
-
500
- $hiddenOptionsData = $hiddenOptions[$conditionName];
501
-
502
- $tabs = array_keys($hiddenOptionsData);
503
- ob_start();
504
- ?>
505
-
506
- <div class="sgpb sgpb-wrapper">
507
- <div class="tab">
508
- <?php
509
- $activeTab = '';
510
- if (!empty($tabs[0])) {
511
- $activeTab = $tabs[0];
512
- }
513
- ?>
514
- <?php foreach ($tabs as $tab): ?>
515
- <?php
516
- $activeClassName = '';
517
- if ($activeTab == $tab) {
518
- $activeClassName = 'sgpb-active';
519
- }
520
- ?>
521
- <button class="tablinks sgpb-tab-links <?php echo $activeClassName;?>" data-rule-id="<?php echo $ruleId; ?>" data-content-id="<?php echo $tab.'-'.$ruleId; ?>"><?php echo ucfirst($tab); ?></button>
522
- <?php endforeach;?>
523
- </div>
524
- <?php echo self::createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId); ?>
525
- <div class="modal-footer">
526
- <button type="button" class="sgpb-no-button events-option-close sgpb-modal-cancel sgpb-btn sgpb-btn-gray-light" href="#"><?php _e('Cancel', SG_POPUP_TEXT_DOMAIN); ?></button>
527
- <button class="sgpb-btn sgpb-btn-blue sgpb-popup-option-save"><?php _e('Save', SG_POPUP_TEXT_DOMAIN); ?></button>
528
- </div>
529
- </div>
530
- <?php
531
- $hiddenPopupContent = ob_get_contents();
532
- ob_end_clean();
533
-
534
- return $hiddenPopupContent;
535
- }
536
-
537
- private static function createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId)
538
- {
539
- ob_start();
540
- ?>
541
- <?php foreach ($hiddenOptionsData as $key => $hiddenData): ?>
542
- <div id="<?php echo $key.'-'.$ruleId; ?>" class="sgpb-tab-content-<?php echo $ruleId;?>">
543
- <div id="<?php echo $key; ?>" class="sgpb-tab-content-options">
544
- <?php foreach ($hiddenData as $name => $label): ?>
545
- <?php
546
- $hiddenOptionsView = self::optionLabelSupplement($conditionDataObj, $name);
547
- $colMdValue = 6;
548
- if (!empty($hiddenOptionsView)) {
549
- $colMdValue = 2;
550
- }
551
- ?>
552
- <div class="row form-group formItem sgpb-margin-y-10">
553
- <div class="col-md-6">
554
- <?php echo self::createConditionFieldHeader($conditionDataObj, $name); ?>
555
- </div>
556
- <div class="col-md-<?php echo $colMdValue; ?>">
557
- <?php echo self::createConditionField($conditionDataObj, $name); ?>
558
- </div>
559
- <?php if (!empty($hiddenOptionsView)): ?>
560
- <div class="col-md-4">
561
- <?php echo $hiddenOptionsView; ?>
562
- </div>
563
- <?php endif; ?>
564
- </div>
565
- <?php endforeach; ?>
566
- </div>
567
- </div>
568
- <?php endforeach;?>
569
- <?php
570
- $hiddenPopupContent = ob_get_contents();
571
- ob_end_clean();
572
-
573
- return $hiddenPopupContent;
574
- }
575
-
576
- public static function hiddenSubOptionsView($parentOptionName, $conditionDataObj)
577
- {
578
- $subOptionsContent = '';
579
- $subOptions = self::getHiddenOptionSubOptions($parentOptionName);
580
- if (!empty($subOptions)) {
581
- $subOptionsContent = self::createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions);
582
- }
583
-
584
- return $subOptionsContent;
585
- }
586
-
587
- private static function createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions)
588
- {
589
- $name = $parentOptionName;
590
- ob_start();
591
- ?>
592
- <div class="row <?php echo 'sgpb-popup-hidden-content-'.$name.'-'.$conditionDataObj->getRuleId().'-wrapper'?> form-group">
593
- <?php foreach ($subOptions as $subOption): ?>
594
- <div class="col-md-6">
595
- <?php echo self::createConditionFieldHeader($conditionDataObj, $subOption); ?>
596
- </div>
597
- <div class="col-md-6">
598
- <?php echo self::createConditionField($conditionDataObj, $subOption); ?>
599
- </div>
600
- <?php echo self::hiddenSubOptionsView($subOption, $conditionDataObj)?>
601
- <?php endforeach;?>
602
- </div>
603
- <?php
604
- $hiddenPopupContent = ob_get_contents();
605
- ob_end_clean();
606
-
607
- return $hiddenPopupContent;
608
- }
609
-
610
- public static function getHiddenOptionSubOptions($optionName)
611
- {
612
- global $SGPB_DATA_CONFIG_ARRAY;
613
- $childOptionNames = array();
614
- $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
615
- $targetDataAttrs = $eventsData['attrs'];
616
-
617
- if (empty($targetDataAttrs[$optionName])) {
618
- return $childOptionNames;
619
- }
620
-
621
- if (empty($targetDataAttrs[$optionName]['childOptions'])) {
622
- return $childOptionNames;
623
- }
624
- $childOptionNames = $targetDataAttrs[$optionName]['childOptions'];
625
-
626
- return $childOptionNames;
627
- }
628
-
629
- private static function getParamRowHideStatus($conditionDataObj, $ruleName)
630
- {
631
- global $SGPB_DATA_CONFIG_ARRAY;
632
- if ($ruleName == 'hiddenOption') {
633
- return '';
634
- }
635
- $status = false;
636
- $conditionName = $conditionDataObj->getConditionName();
637
- $saveData = $conditionDataObj->getSavedData();
638
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
639
- $paramsData = array();
640
- if (!empty($conditionConfig['paramsData'])) {
641
- $paramsData = $conditionConfig['paramsData'];
642
- }
643
-
644
- $ruleElementData['ruleName'] = $ruleName;
645
- if ($ruleName == 'value' && !empty($saveData) && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
646
- $ruleName = $saveData[$conditionDataObj->getTakeValueFrom()];
647
- }
648
- if ((!isset($paramsData[$ruleName]) && empty($paramsData[$ruleName])) || is_null($paramsData[$ruleName])) {
649
- $status = true;
650
- }
651
-
652
- return $status;
653
- }
654
-
655
- public function targetHeader($targetName = '')
656
- {
657
- global $SGPB_DATA_CONFIG_ARRAY;
658
- $data = $SGPB_DATA_CONFIG_ARRAY[$targetName];
659
- $columnLabels = $data['columns'];
660
- $header = '<div class="sg-target-header-wrapper">';
661
-
662
- foreach ($columnLabels as $key => $columnLabel) {
663
- $header .= '<div class="sgpb-col-md">'.$columnLabel.'</div>';
664
- }
665
- $header .= '</div>';
666
- return $header;
667
- }
668
- }
1
+ <?php
2
+ namespace sgpb;
3
+ class ConditionCreator
4
+ {
5
+ public function __construct($targetData)
6
+ {
7
+ if (!empty($targetData)) {
8
+ $this->setConditionsObj($targetData);
9
+ }
10
+ }
11
+
12
+ private $conditionsObj;
13
+ //When there is not group set groupId -1
14
+ private $prevGroupId = -1;
15
+
16
+ public function setPrevGroupId($prevGroupId)
17
+ {
18
+ $this->prevGroupId = $prevGroupId;
19
+ }
20
+
21
+ public function getPrevGroupId()
22
+ {
23
+ return $this->prevGroupId;
24
+ }
25
+
26
+ public function setConditionsObj($conditionsObj)
27
+ {
28
+ $this->conditionsObj = $conditionsObj;
29
+ }
30
+
31
+ public function getConditionsObj()
32
+ {
33
+ return $this->conditionsObj;
34
+ }
35
+
36
+ public function render()
37
+ {
38
+ $conditionsObj = $this->getConditionsObj();
39
+ $view = '';
40
+
41
+ if (empty($conditionsObj)) {
42
+ return array();
43
+ }
44
+
45
+ foreach ($conditionsObj as $conditionObj) {
46
+
47
+ $currentGroupId = $conditionObj->getGroupId();
48
+
49
+ $prevGroupId = $this->getPrevGroupId();
50
+ $openGroupDiv = '';
51
+ $separator = '';
52
+ $closePrevGroupDiv = '';
53
+
54
+ if ($currentGroupId > $prevGroupId) {
55
+ if ($currentGroupId != 0) {
56
+ $closePrevGroupDiv = '</div>';
57
+ $separator = ConditionCreator::getOrRuleSeparator();
58
+ }
59
+ $openGroupDiv = '<div class="sgpb-wrapper sgpb-box-'.$conditionObj->getConditionName().' sg-target-group sg-target-group-'.$conditionObj->getGroupId().'" data-group-id="'.$currentGroupId.'">';
60
+ }
61
+
62
+ $view .= $closePrevGroupDiv;
63
+ $view .= $separator;
64
+ $view .= $openGroupDiv;
65
+ $view .= ConditionCreator::createConditionRuleRow($conditionObj);
66
+
67
+ $this->setPrevGroupId($currentGroupId);
68
+ }
69
+
70
+ $view .= '</div>';
71
+
72
+ return $view;
73
+ }
74
+
75
+ public static function getOrRuleSeparator()
76
+ {
77
+ return '<h4 class="sgpb-rules-or"><span>'.__('OR', SG_POPUP_TEXT_DOMAIN).'</span></h4>';
78
+ }
79
+
80
+ public static function createConditionRuleRow($conditionDataObj)
81
+ {
82
+ ob_start();
83
+ ?>
84
+ <div class="events form sg-target-rule sgpb-margin-bottom-40 sg-target-rule-<?php echo $conditionDataObj->getRuleId(); ?> sgpb-event-row" data-rule-id="<?php echo $conditionDataObj->getRuleId(); ?>">
85
+ <div class="formItem sgpb-align-item-start">
86
+ <?php
87
+ $savedData = $conditionDataObj->getSavedData();
88
+
89
+ if (!isset($savedData['value'])) {
90
+ $savedData['value'] = '';
91
+ }
92
+ ?>
93
+ <?php $idHiddenDiv = $conditionDataObj->getConditionName().'_'.$conditionDataObj->getGroupId().'_'.$conditionDataObj->getRuleId();?>
94
+ <?php foreach ($savedData as $conditionName => $conditionSavedData): ?>
95
+ <?php
96
+ $showRowStatusClass = '';
97
+ $hideStatus = self::getParamRowHideStatus($conditionDataObj, $conditionName);
98
+ $ruleElementData = self::getRuleElementData($conditionDataObj, 'param');
99
+ $ruleSavedData = $ruleElementData['saved'];
100
+ $currentArgs = array('savedData' => $ruleSavedData, 'conditionName' => $conditionName);
101
+
102
+ if (!self::allowToShowOperatorColumn($conditionDataObj, $currentArgs)) {
103
+ $hideStatus = true;
104
+ }
105
+ $showRowStatusClass = ($hideStatus) ? 'sgpb-hide-condition-row' : $showRowStatusClass;
106
+ ?>
107
+ <?php if ($conditionName != 'hiddenOption'): ?>
108
+ <div data-condition-name="<?php echo $conditionName;?>" class="<?php echo 'inputBlock sg-condition-'.$conditionName.'-wrapper'.' '.$showRowStatusClass; ?>">
109
+ <?php
110
+ if (!$hideStatus) {
111
+ echo self::createConditionElement($conditionDataObj, $conditionName);
112
+ }
113
+ ?>
114
+ </div>
115
+ <?php endif; ?>
116
+ <?php if (($conditionName == 'hiddenOption')): ?>
117
+ <?php $hiddenContent = self::getHiddenDataContent($conditionDataObj); ?>
118
+ <div class="sgpb-hide-condition-row"><div id="<?php echo $idHiddenDiv;?>"><?php echo $hiddenContent; ?></div></div>
119
+ <?php endif; ?>
120
+ <?php endforeach;?>
121
+ <?php echo self::createConditionOperators($conditionDataObj, $idHiddenDiv); ?>
122
+ </div>
123
+ </div>
124
+ <?php
125
+ $targetOptionRow = ob_get_contents();
126
+ ob_end_clean();
127
+
128
+ return $targetOptionRow;
129
+ }
130
+
131
+ private static function allowToShowOperatorColumn($conditionDataObj, $currentArgs = array())
132
+ {
133
+ global $SGPB_DATA_CONFIG_ARRAY;
134
+ $conditionName = $conditionDataObj->getConditionName();
135
+ $conditionData = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
136
+ $operatorAllowInConditions = array();
137
+
138
+ if (!empty($conditionData['operatorAllowInConditions'])) {
139
+ $operatorAllowInConditions = $conditionData['operatorAllowInConditions'];
140
+ }
141
+
142
+ $savedData = $conditionDataObj->getSavedData();
143
+
144
+ $status = true;
145
+
146
+ if ($currentArgs['conditionName'] == 'operator') {
147
+ $currentSavedData = $currentArgs['savedData'];
148
+
149
+ if (($currentSavedData == 'not_rule' || $currentSavedData == 'select_role' || $currentSavedData == 'select_event')) {
150
+ $status = false;
151
+ }
152
+
153
+ // unset old customOperator
154
+ $SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['customOperator'] = '';
155
+ if (is_array($operatorAllowInConditions)) {
156
+
157
+ if (in_array($savedData['param'], $operatorAllowInConditions)) {
158
+ $operator = '';
159
+ if (!empty($conditionData['paramsData'][$savedData['param'].'Operator'])) {
160
+ $operator = $conditionData['paramsData'][$savedData['param'].'Operator'];
161
+ }
162
+ $SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['customOperator'] = $operator;
163
+ return true;
164
+ }
165
+ // there is no need to show is/is not column for not specific conditions (everywhere, all posts/pages/other_custom_post_types)
166
+ if (isset($savedData['param']) && !is_array($savedData['param']) && (strpos($savedData['param'], '_all') || $savedData['param'] == 'everywhere' || $savedData['param'] == 'post_tags')) {
167
+ return false;
168
+ }
169
+ if (!empty($savedData['tempParam']) && in_array($savedData['tempParam'], $operatorAllowInConditions)) {
170
+ $SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['operator'] = $conditionData['paramsData'][$savedData['tempParam'].'Operator'];
171
+ }
172
+ }
173
+
174
+ if (empty($SGPB_DATA_CONFIG_ARRAY[$conditionName]['paramsData']['operator'])) {
175
+ $status = false;
176
+ }
177
+ }
178
+
179
+ return $status;
180
+ }
181
+
182
+ public static function createConditionOperators($conditionDataObj, $idHiddenDiv = '')
183
+ {
184
+ global $SGPB_DATA_CONFIG_ARRAY;
185
+ $groupId = $conditionDataObj->getRuleId();
186
+ $groupTotal = $conditionDataObj->getGroupTotal();
187
+
188
+ $conditionName = $conditionDataObj->getConditionName();
189
+ $operatorsHtml = '';
190
+ $conditionData = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
191
+ $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
192
+
193
+ $operatorsData = $conditionData['operators'];
194
+ $eventButtonClasses = '';
195
+ $eventButtonWrapperClass = '';
196
+ $icon = '';
197
+
198
+ if (empty($operatorsData)) {
199
+ return $operatorsHtml;
200
+ }
201
+
202
+ foreach ($operatorsData as $operator) {
203
+ $identificatorClass = '';
204
+ $style = '';
205
+ if (!isset($eventsData['hiddenOptionData'])) {
206
+ continue;
207
+ }
208
+ $saveData = $conditionDataObj->getSavedData();
209
+ if (empty($saveData['hiddenOption']) && $operator['name'] == 'Edit' && $saveData["param"] != 'load') {
210
+ continue;
211
+ }
212
+ if ($operator['name'] == 'Edit') {
213
+ $operator['name'] = 'Settings';
214
+ }
215
+
216
+ if ($operator['operator'] == 'edit') {
217
+ $icon = 'D';
218
+ $btnClass = ' icons_gray';
219
+ $identificatorClass = $idHiddenDiv;
220
+ $eventButtonClasses = 'sgpb-rules-'.$operator['operator'].'-rule ';
221
+ }
222
+ if ($operator['operator'] == 'add') {
223
+ $icon = 'L';
224
+ $btnClass = ' icons_blue';
225
+ $eventButtonClasses = 'sgpb-rules-'.$operator['operator'].'-rule ';
226
+ //Don't show add button if it's not for last element
227
+ if ($groupId < $groupTotal) {
228
+ $style = 'style="display: none;"';
229
+ }
230
+ }
231
+ if ($operator['operator'] == 'delete') {
232
+ $icon = 'I';
233
+ $btnClass = ' icons_pink';
234
+ $eventButtonClasses = 'sgpb-rules-'.$operator['operator'].'-rule ';
235
+ }
236
+
237
+ $element = '<i class="sgpb-icons '.$btnClass.'" data-id="'.$identificatorClass.'">'.$icon.'</i>';
238
+
239
+ $operatorsHtml .= '<div class="'.$eventButtonClasses.' sgpb-rules-'.$operator['operator'].'-button-wrapper" '.$style.'>';
240
+ $operatorsHtml .= $element;
241
+ $operatorsHtml .= '</div>';
242
+ }
243
+
244
+ return $operatorsHtml;
245
+ }
246
+
247
+ public static function createConditionElement($conditionDataObj, $ruleName)
248
+ {
249
+ //more code added because of the lack of abstraction
250
+ //todo: remove ASAP if possible
251
+ $sData = $conditionDataObj->getSavedData();
252
+ if ($ruleName == 'param' && !empty($sData['tempParam'])) {
253
+ $sData['param'] = $sData['tempParam'];
254
+ $newObj = clone $conditionDataObj;
255
+ $newObj->setSavedData($sData);
256
+ $conditionDataObj = $newObj;
257
+ }
258
+
259
+ $element = '';
260
+
261
+ $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
262
+ $elementHeader = self::createRuleHeader($ruleElementData);
263
+ $field = self::createRuleField($ruleElementData);
264
+ $element .= $elementHeader;
265
+ $element .= $field;
266
+
267
+ return $element;
268
+ }
269
+
270
+ public static function createConditionField($conditionDataObj, $ruleName)
271
+ {
272
+ $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
273
+
274
+ return self::createRuleField($ruleElementData);
275
+ }
276
+
277
+ public static function createConditionFieldHeader($conditionDataObj, $ruleName)
278
+ {
279
+ $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
280
+
281
+ return self::createRuleHeader($ruleElementData);
282
+ }
283
+
284
+ public static function optionLabelSupplement($conditionDataObj, $ruleName)
285
+ {
286
+ global $SGPB_DATA_CONFIG_ARRAY;
287
+ $conditionName = $conditionDataObj->getConditionName();
288
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
289
+ $attrs = $conditionConfig['attrs'][$ruleName];
290
+
291
+ if (isset($attrs['infoAttrs']['rightLabel'])) {
292
+ $labelData = $attrs['infoAttrs']['rightLabel'];
293
+ $value = $labelData['value'];
294
+ $classes = $labelData['classes'];
295
+ return '<span class="'.esc_attr($classes).'">'.$value.'</span>';
296
+ }
297
+
298
+ return '';
299
+ }
300
+
301
+ private static function getRuleElementData($conditionDataObj, $ruleName = '')
302
+ {
303
+ global $SGPB_DATA_CONFIG_ARRAY;
304
+ $ruleElementData = array();
305
+ $savedParam = '';
306
+ $conditionName = $conditionDataObj->getConditionName();
307
+ $saveData = $conditionDataObj->getSavedData();
308
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
309
+ $rulesType = $conditionConfig['columnTypes'];
310
+ $paramsData = $conditionConfig['paramsData'];
311
+
312
+ $attrs = $conditionConfig['attrs'];
313
+
314
+ if (!empty($saveData[$ruleName])) {
315
+ $savedParam = $saveData[$ruleName];
316
+ }
317
+ else if (!empty($saveData['hiddenOption']) && isset($saveData['hiddenOption'][$ruleName])) {
318
+ $savedParam = $saveData['hiddenOption'][$ruleName];
319
+ }
320
+
321
+ $ruleElementData['ruleName'] = $ruleName;
322
+ if ($ruleName == 'value' && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
323
+ $index = $conditionDataObj->getTakeValueFrom();
324
+ $ruleName = $saveData[$index];
325
+ }
326
+
327
+ $type = array();
328
+ if (!empty($rulesType[$ruleName])) {
329
+ $type = $rulesType[$ruleName];
330
+ }
331
+ $data = array();
332
+ if (!empty($paramsData[$ruleName])) {
333
+ $data = $paramsData[$ruleName];
334
+ }
335
+
336
+ // if exists customOperator it takes the custom one
337
+ if ($ruleName == 'operator' && !empty($paramsData['customOperator'])) {
338
+ $data = $paramsData['customOperator'];
339
+ }
340
+
341
+ $optionAttr = array();
342
+ if (!empty($attrs[$ruleName])) {
343
+ $optionAttr = $attrs[$ruleName];
344
+ }
345
+
346
+ $attr = array();
347
+
348
+ if (!empty($optionAttr['htmlAttrs'])) {
349
+ $attr = $optionAttr['htmlAttrs'];
350
+ }
351
+
352
+ $ruleElementData['type'] = $type;
353
+ $ruleElementData['data'] = apply_filters('sgpb'.$ruleName.'ConditionCreator', $data, $saveData);
354
+ $ruleElementData['saved'] = $savedParam;
355
+ $ruleElementData['attr'] = $attr;
356
+ $ruleElementData['conditionDataObj'] = $conditionDataObj;
357
+
358
+ return $ruleElementData;
359
+ }
360
+
361
+ private static function createRuleHeader($ruleElementData)
362
+ {
363
+ return self::createElementHeader($ruleElementData);
364
+ }
365
+
366
+ public static function createRuleField($ruleElementData)
367
+ {
368
+ $attr = array();
369
+ $type = $ruleElementData['type'];
370
+ $conditionObj = $ruleElementData['conditionDataObj'];
371
+
372
+ $name = 'sgpb-'.$conditionObj->getConditionName().'['.$conditionObj->getGroupId().']['.$conditionObj->getRuleId().']['.$ruleElementData['ruleName'].']';
373
+ $attr['name'] = $name;
374
+
375
+ if (is_array($ruleElementData['attr'])) {
376
+ $attr += $ruleElementData['attr'];
377
+ $attr['data-rule-id'] = $conditionObj->getRuleId();
378
+ }
379
+ $rowField = '';
380
+
381
+ switch($type) {
382
+
383
+ case 'select':
384
+ if (!empty($attr['multiple'])) {
385
+ $attr['name'] .= '[]';
386
+ }
387
+ $savedData = $ruleElementData['saved'];
388
+
389
+ if (empty($ruleElementData['data'])) {
390
+ $ruleElementData['data'] = $ruleElementData['saved'];
391
+ $savedData = array();
392
+
393
+ if (!empty($ruleElementData['saved'])) {
394
+ $savedData = array_keys($ruleElementData['saved']);
395
+ }
396
+ }
397
+
398
+ $rowField .= AdminHelper::createSelectBox($ruleElementData['data'], $savedData, $attr);
399
+ break;
400
+ case 'text':
401
+ case 'url':
402
+ case 'number':
403
+ $attr['type'] = $type;
404
+
405
+ //this is done to override the initial input value
406
+ if (!empty($ruleElementData['saved'])) {
407
+ $attr['value'] = esc_attr($ruleElementData['saved']);
408
+ }
409
+
410
+ $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'], $attr);
411
+ break;
412
+ case 'checkbox':
413
+ $attr['type'] = $type;
414
+ $rowField .= AdminHelper::createCheckBox($ruleElementData['data'], $ruleElementData['saved'], $attr);
415
+ break;
416
+ case 'conditionalText':
417
+ $popupId = self::getPopupId($conditionObj);
418
+ if(!empty($popupId)) {
419
+ $attr['value'] = $attr['value'].$popupId;
420
+ $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'].$popupId, $attr);
421
+ }
422
+ else {
423
+ $rowField .= '<div class="sgpb-show-alert-before-save">'.$attr['beforeSaveLabel'].'</div>';
424
+ }
425
+ break;
426
+ }
427
+
428
+ return $rowField;
429
+ }
430
+
431
+ public static function getPopupId($conditionObj)
432
+ {
433
+ $popupId = 0;
434
+ $conditionPopupId = $conditionObj->getPopupId();
435
+
436
+ if (!empty($conditionPopupId)) {
437
+ $popupId = $conditionObj->getPopupId();
438
+ }
439
+ else if(!empty($_GET['post'])) {
440
+ $popupId = $_GET['post'];
441
+ }
442
+
443
+ return $popupId;
444
+ }
445
+
446
+ public static function createElementHeader($ruleElementData)
447
+ {
448
+ $labelAttributes = '';
449
+ $info = '';
450
+ $conditionObj = $ruleElementData['conditionDataObj'];
451
+ $conditionName = $conditionObj->getConditionName();
452
+ $ruleName = $ruleElementData['ruleName'];
453
+ global $SGPB_DATA_CONFIG_ARRAY;
454
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
455
+ $conditionAttrs = $conditionConfig['attrs'];
456
+
457
+ $saveData = $conditionObj->getSavedData();
458
+ $optionTitle = $ruleName;
459
+ $titleKey = $ruleName;
460
+
461
+
462
+ if ($ruleName == 'value' && !empty($saveData[$conditionObj->getTakeValueFrom()])) {
463
+ $titleKey = $saveData[$conditionObj->getTakeValueFrom()];
464
+ }
465
+
466
+ if (!empty($conditionAttrs[$titleKey])) {
467
+ $optionAttrs = $conditionAttrs[$titleKey];
468
+ if (!empty($optionAttrs['infoAttrs'])) {
469
+ // $conditionName => events, conditions, targets...
470
+ // $ruleName => param, operator, value (1-st, 2-nd, 3-rd columns)
471
+ $optionAttrs = apply_filters('sgpb'.$conditionName.$ruleName.'Param', $optionAttrs, $saveData);
472
+ $optionTitle = $optionAttrs['infoAttrs']['label'];
473
+ if (!empty($optionAttrs['infoAttrs']['labelAttrs'])) {
474
+ $labelAttributes = AdminHelper::createAttrs($optionAttrs['infoAttrs']['labelAttrs']);
475
+ }
476
+ }
477
+ }
478
+ if (isset($optionAttrs['infoAttrs']['info']) && $optionAttrs['infoAttrs']['info']) {
479
+ $info = '<div class="question-mark sgpb-info-icon">B</div>';
480
+ $info .= '<div class="sgpb-info-wrapper">
481
+ <span class="infoSelectRepeat samefontStyle sgpb-info-text" style="display: none;">'.$optionAttrs['infoAttrs']['info'].'</span>
482
+ </div>';
483
+ }
484
+
485
+ return "<div class=\"sgpb-display-flex text\"><span class=\"inputBlock__title\" $labelAttributes>$optionTitle</span>$info</div>";
486
+ }
487
+
488
+ public static function getHiddenDataContent($conditionDataObj)
489
+ {
490
+ global $SGPB_DATA_CONFIG_ARRAY;
491
+ $savedData = $conditionDataObj->getSavedData();
492
+ $conditionName = $savedData['param'];
493
+ $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
494
+ $hiddenOptions = $eventsData['hiddenOptionData'];
495
+ $ruleId = $conditionDataObj->getRuleId();
496
+ if (empty($hiddenOptions[$conditionName])) {
497
+ return __('No Data', SG_POPUP_TEXT_DOMAIN);
498
+ }
499
+
500
+ $hiddenOptionsData = $hiddenOptions[$conditionName];
501
+
502
+ $tabs = array_keys($hiddenOptionsData);
503
+ ob_start();
504
+ ?>
505
+
506
+ <div class="sgpb sgpb-wrapper">
507
+ <div class="tab">
508
+ <?php
509
+ $activeTab = '';
510
+ if (!empty($tabs[0])) {
511
+ $activeTab = $tabs[0];
512
+ }
513
+ ?>
514
+ <?php foreach ($tabs as $tab): ?>
515
+ <?php
516
+ $activeClassName = '';
517
+ if ($activeTab == $tab) {
518
+ $activeClassName = 'sgpb-active';
519
+ }
520
+ ?>
521
+ <button class="tablinks sgpb-tab-links <?php echo $activeClassName;?>" data-rule-id="<?php echo $ruleId; ?>" data-content-id="<?php echo $tab.'-'.$ruleId; ?>"><?php echo ucfirst($tab); ?></button>
522
+ <?php endforeach;?>
523
+ </div>
524
+ <?php echo self::createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId); ?>
525
+ <div class="modal-footer">
526
+ <button type="button" class="sgpb-no-button events-option-close sgpb-modal-cancel sgpb-btn sgpb-btn-gray-light" href="#"><?php _e('Cancel', SG_POPUP_TEXT_DOMAIN); ?></button>
527
+ <button class="sgpb-btn sgpb-btn-blue sgpb-popup-option-save"><?php _e('Save', SG_POPUP_TEXT_DOMAIN); ?></button>
528
+ </div>
529
+ </div>
530
+ <?php
531
+ $hiddenPopupContent = ob_get_contents();
532
+ ob_end_clean();
533
+
534
+ return $hiddenPopupContent;
535
+ }
536
+
537
+ private static function createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId)
538
+ {
539
+ ob_start();
540
+ ?>
541
+ <?php foreach ($hiddenOptionsData as $key => $hiddenData): ?>
542
+ <div id="<?php echo $key.'-'.$ruleId; ?>" class="sgpb-tab-content-<?php echo $ruleId;?>">
543
+ <div id="<?php echo $key; ?>" class="sgpb-tab-content-options">
544
+ <?php foreach ($hiddenData as $name => $label): ?>
545
+ <?php
546
+ $hiddenOptionsView = self::optionLabelSupplement($conditionDataObj, $name);
547
+ $colMdValue = 6;
548
+ if (!empty($hiddenOptionsView)) {
549
+ $colMdValue = 2;
550
+ }
551
+ ?>
552
+ <div class="row form-group formItem sgpb-margin-y-10">
553
+ <div class="col-md-6">
554
+ <?php echo self::createConditionFieldHeader($conditionDataObj, $name); ?>
555
+ </div>
556
+ <div class="col-md-<?php echo $colMdValue; ?>">
557
+ <?php echo self::createConditionField($conditionDataObj, $name); ?>
558
+ </div>
559
+ <?php if (!empty($hiddenOptionsView)): ?>
560
+ <div class="col-md-4">
561
+ <?php echo $hiddenOptionsView; ?>
562
+ </div>
563
+ <?php endif; ?>
564
+ </div>
565
+ <?php endforeach; ?>
566
+ </div>
567
+ </div>
568
+ <?php endforeach;?>
569
+ <?php
570
+ $hiddenPopupContent = ob_get_contents();
571
+ ob_end_clean();
572
+
573
+ return $hiddenPopupContent;
574
+ }
575
+
576
+ public static function hiddenSubOptionsView($parentOptionName, $conditionDataObj)
577
+ {
578
+ $subOptionsContent = '';
579
+ $subOptions = self::getHiddenOptionSubOptions($parentOptionName);
580
+ if (!empty($subOptions)) {
581
+ $subOptionsContent = self::createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions);
582
+ }
583
+
584
+ return $subOptionsContent;
585
+ }
586
+
587
+ private static function createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions)
588
+ {
589
+ $name = $parentOptionName;
590
+ ob_start();
591
+ ?>
592
+ <div class="row <?php echo 'sgpb-popup-hidden-content-'.$name.'-'.$conditionDataObj->getRuleId().'-wrapper'?> form-group">
593
+ <?php foreach ($subOptions as $subOption): ?>
594
+ <div class="col-md-6">
595
+ <?php echo self::createConditionFieldHeader($conditionDataObj, $subOption); ?>
596
+ </div>
597
+ <div class="col-md-6">
598
+ <?php echo self::createConditionField($conditionDataObj, $subOption); ?>
599
+ </div>
600
+ <?php echo self::hiddenSubOptionsView($subOption, $conditionDataObj)?>
601
+ <?php endforeach;?>
602
+ </div>
603
+ <?php
604
+ $hiddenPopupContent = ob_get_contents();
605
+ ob_end_clean();
606
+
607
+ return $hiddenPopupContent;
608
+ }
609
+
610
+ public static function getHiddenOptionSubOptions($optionName)
611
+ {
612
+ global $SGPB_DATA_CONFIG_ARRAY;
613
+ $childOptionNames = array();
614
+ $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
615
+ $targetDataAttrs = $eventsData['attrs'];
616
+
617
+ if (empty($targetDataAttrs[$optionName])) {
618
+ return $childOptionNames;
619
+ }
620
+
621
+ if (empty($targetDataAttrs[$optionName]['childOptions'])) {
622
+ return $childOptionNames;
623
+ }
624
+ $childOptionNames = $targetDataAttrs[$optionName]['childOptions'];
625
+
626
+ return $childOptionNames;
627
+ }
628
+
629
+ private static function getParamRowHideStatus($conditionDataObj, $ruleName)
630
+ {
631
+ global $SGPB_DATA_CONFIG_ARRAY;
632
+ if ($ruleName == 'hiddenOption') {
633
+ return '';
634
+ }
635
+ $status = false;
636
+ $conditionName = $conditionDataObj->getConditionName();
637
+ $saveData = $conditionDataObj->getSavedData();
638
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
639
+ $paramsData = array();
640
+ if (!empty($conditionConfig['paramsData'])) {
641
+ $paramsData = $conditionConfig['paramsData'];
642
+ }
643
+
644
+ $ruleElementData['ruleName'] = $ruleName;
645
+ if ($ruleName == 'value' && !empty($saveData) && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
646
+ $ruleName = $saveData[$conditionDataObj->getTakeValueFrom()];
647
+ }
648
+ if ((!isset($paramsData[$ruleName]) && empty($paramsData[$ruleName])) || is_null($paramsData[$ruleName])) {
649
+ $status = true;
650
+ }
651
+
652
+ return $status;
653
+ }
654
+
655
+ public function targetHeader($targetName = '')
656
+ {
657
+ global $SGPB_DATA_CONFIG_ARRAY;
658
+ $data = $SGPB_DATA_CONFIG_ARRAY[$targetName];
659
+ $columnLabels = $data['columns'];
660
+ $header = '<div class="sg-target-header-wrapper">';
661
+
662
+ foreach ($columnLabels as $key => $columnLabel) {
663
+ $header .= '<div class="sgpb-col-md">'.$columnLabel.'</div>';
664
+ }
665
+ $header .= '</div>';
666
+ return $header;
667
+ }
668
+ }
com/classes/ConvertToNewVersion.php CHANGED
@@ -1,1274 +1,1274 @@
1
- <?php
2
- namespace sgpb;
3
- use sgpb\AdminHelper;
4
- use \ConfigDataHelper;
5
-
6
- class ConvertToNewVersion
7
- {
8
- private $id;
9
- private $content = '';
10
- private $type;
11
- private $title;
12
- private $options;
13
- private $customOptions = array();
14
-
15
- public function setContent($content)
16
- {
17
- $this->content = $content;
18
- }
19
-
20
- public function getContent()
21
- {
22
- return $this->content;
23
- }
24
-
25
- public function setType($type)
26
- {
27
- if ($type == 'shortcode') {
28
- $type = 'html';
29
- }
30
- $this->type = $type;
31
- }
32
-
33
- public function getType()
34
- {
35
- return $this->type;
36
- }
37
-
38
- public function setTitle($title)
39
- {
40
- $this->title = $title;
41
- }
42
-
43
- public function getTitle()
44
- {
45
- return $this->title;
46
- }
47
-
48
- public function setId($id)
49
- {
50
- $this->id = (int)$id;
51
- }
52
-
53
- public function getId()
54
- {
55
- return $this->id;
56
- }
57
-
58
- public function setOptions($options)
59
- {
60
- $this->options = $options;
61
- }
62
-
63
- public function getOptions()
64
- {
65
- return $this->options;
66
- }
67
-
68
- public function setCustomOptions($customOptions)
69
- {
70
- $this->customOptions = $customOptions;
71
- }
72
-
73
- public function getCustomOptions()
74
- {
75
- return $this->customOptions;
76
- }
77
-
78
- public static function convert()
79
- {
80
- $obj = new self();
81
- $obj->insertDataToNew();
82
- }
83
-
84
- public function insertDataToNew()
85
- {
86
- $idsMapping = array();
87
- Installer::install();
88
- Installer::registerPlugin();
89
- $popups = $this->getAllSavedPopups();
90
- $this->convertSettings();
91
-
92
- $arr = array();
93
- $popupPreviewId = get_option('popupPreviewId');
94
- foreach ($popups as $popup) {
95
- if (empty($popup)) {
96
- continue;
97
- }
98
- // we should not convert preview popup
99
- if ($popup['id'] == $popupPreviewId) {
100
- continue;
101
- }
102
-
103
- $popupObj = $this->popupObjectFromArray($popup);
104
- $arr[] = $popupObj;
105
- $args = array(
106
- 'post_title' => $popupObj->getTitle(),
107
- 'post_content' => $popupObj->getContent(),
108
- 'post_status' => 'publish',
109
- 'post_type' => SG_POPUP_POST_TYPE
110
- );
111
- $id = $popupObj->getId();
112
- $newOptions = $this->getNewOptionsFormSavedData($popupObj);
113
- $newPopupId = @wp_insert_post($args);
114
- $newOptions['sgpb-post-id'] = $newPopupId;
115
- $this->saveOtherOptions($newOptions);
116
-
117
- update_post_meta($newPopupId, 'sg_popup_options', $newOptions);
118
- $idsMapping[$id] = $newPopupId;
119
- }
120
-
121
- $this->convertCounter($idsMapping);
122
- $this->convertSubscribers();
123
-
124
- update_option('sgpbConvertedIds', $idsMapping);
125
-
126
- return $arr;
127
- }
128
-
129
- public function convertSubscribers()
130
- {
131
- global $wpdb;
132
- $subscribersSql = 'SELECT `id`, `firstName`, `lastName`, `email`, `subscriptionType`, `status` from '.$wpdb->prefix.'sg_subscribers';
133
- $subscribers = $wpdb->get_results($subscribersSql, ARRAY_A);
134
-
135
- if (empty($subscribers)) {
136
- return false;
137
- }
138
-
139
- foreach ($subscribers as $subscriber) {
140
- $subscriber['subscriptionType'] = $this->getPostByTitle($subscriber['subscriptionType']);
141
-
142
- $date = date('Y-m-d');
143
- $sql = $wpdb->prepare('INSERT INTO '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' (`firstName`, `lastName`, `email`, `cDate`, `subscriptionType`, `unsubscribed`) VALUES (%s, %s, %s, %s, %d, %d) ', $subscriber['firstName'], $subscriber['lastName'], $subscriber['email'], $date, $subscriber['subscriptionType'], 0);
144
- $wpdb->query($sql);
145
- }
146
- }
147
-
148
- private function getPostByTitle($pageTitle, $output = OBJECT)
149
- {
150
- global $wpdb;
151
- $post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='popupbuilder'", $pageTitle));
152
- if (!empty($post)) {
153
- return get_post($post, $output)->ID;
154
- }
155
-
156
- return null;
157
- }
158
-
159
- /**
160
- * Convert settings section saved options to new version
161
- *
162
- * @since 2.6.7.6
163
- *
164
- * @return bool
165
- */
166
- private function convertSettings()
167
- {
168
- global $wpdb;
169
- $settings = $wpdb->get_row('SELECT options FROM '.$wpdb->prefix .'sg_popup_settings WHERE id = 1', ARRAY_A);
170
-
171
- if (empty($settings['options'])) {
172
- return false;
173
- }
174
- $settings = json_decode($settings['options'], true);
175
-
176
- $deleteData = 0;
177
-
178
- if (!empty($settings['tables-delete-status'])) {
179
- $deleteData = 1;
180
- }
181
- $userRoles = $settings['plugin_users_role'];
182
-
183
- if (empty($userRoles) || !is_array($userRoles)) {
184
- $userRoles = array();
185
- }
186
-
187
- $userRoles = array_map(function($role) {
188
- // it's remove sgpb_ keyword from selected values
189
- $role = substr($role, 5, strlen($role)-1);
190
-
191
- return $role;
192
- }, $userRoles);
193
-
194
- update_option('sgpb-user-roles', $userRoles);
195
- update_option('sgpb-dont-delete-data', $deleteData);
196
-
197
- return true;
198
- }
199
-
200
- private function convertCounter($idsMapping)
201
- {
202
- $oldCounter = get_option('SgpbCounter');
203
-
204
- if (!$oldCounter) {
205
- return false;
206
- }
207
- $newCounter = array();
208
- foreach ($oldCounter as $key => $value) {
209
- $newId = @$idsMapping[$key];
210
- $newCounter[$newId] = $value;
211
- }
212
-
213
- update_option('SgpbCounter', $newCounter);
214
-
215
- return true;
216
- }
217
-
218
-
219
- private function getAllSavedPopups()
220
- {
221
- global $wpdb;
222
-
223
- $query = 'SELECT `id`, `type`, `title`, `options` from '.$wpdb->prefix.'sg_popup ORDER BY id';
224
- $popups = $wpdb->get_results($query, ARRAY_A);
225
-
226
- return $popups;
227
- }
228
-
229
- public function getNewOptionsFormSavedData($popup)
230
- {
231
- $options = $popup->getOptions();
232
- $customOptions = $popup->getCustomOptions();
233
- $options = array_merge($options, $customOptions);
234
- // return addons event from add_connections data
235
- $addonsEvent = $this->getAddonsEventFromPopup($popup);
236
- if ($addonsEvent) {
237
- $options = array_merge($options, $addonsEvent);
238
- }
239
- $options = $this->filterOptions($options);
240
-
241
- $names = $this->getNamesMapping();
242
- $newData = array();
243
- $type = $popup->getType();
244
-
245
- if (empty($names)) {
246
- return $newData;
247
- }
248
-
249
- $newData['sgpb-type'] = $type;
250
-
251
- foreach ($names as $oldName => $newName) {
252
- if (isset($options[$oldName])) {
253
- $optionName = $this->changeOldValues($oldName, $options[$oldName]);
254
- $newData[$newName] = $optionName;
255
- }
256
- }
257
- $newData['sgpb-enable-popup-overlay'] = 'on';
258
- $newData['sgpb-show-background'] = 'on';
259
-
260
- return $newData;
261
- }
262
-
263
- private function saveOtherOptions($options)
264
- {
265
- $popupId = (int)$options['sgpb-post-id'];
266
- $mobileOperator = '';
267
- $conditions = array();
268
- $conditions['sgpb-target'] = array(array(array('param' => 'not_rule')));
269
- $conditions['sgpb-conditions'] = array(array());
270
-
271
- $eventsInitialData = array(
272
- array(
273
- )
274
- );
275
-
276
- if (!empty($options['sgpb-option-exit-intent-enable'])) {
277
- $eventsInitialData[0][] = array(
278
- 'param' => 'exitIntent',
279
- 'value' => @$options['sgpb-option-exit-intent-type'],
280
- 'hiddenOption' => array(
281
- 'sgpb-exit-intent-expire-time' => @$options['sgpb-exit-intent-expire-time'],
282
- 'sgpb-exit-intent-cookie-level' => @$options['sgpb-exit-intent-cookie-level'],
283
- 'sgpb-exit-intent-soft-from-top' => @$options['sgpb-exit-intent-soft-from-top']
284
- )
285
- );
286
- }
287
- else if (!empty($options['sgpb-option-enable-ad-block'])) {
288
- $eventsInitialData[0][] = array(
289
- 'param' => 'AdBlock',
290
- 'value' => $options['sgpb-popup-delay'],
291
- 'hiddenOption' => array()
292
- );
293
- }
294
-
295
- // after inactivity
296
- if (!empty($options['sgpb-inactivity-status'])) {
297
- $eventsInitialData[0][] = array(
298
- 'param' => 'inactivity',
299
- 'value' => @$options['sgpb-inactivity-timer'],
300
- 'hiddenOption' => array()
301
- );
302
- }
303
-
304
- // after scroll
305
- if (!empty($options['sgpb-onscroll-status'])) {
306
- $eventsInitialData[0][] = array(
307
- 'param' => 'onScroll',
308
- 'value' => @$options['sgpb-onscroll-percentage'],
309
- 'hiddenOption' => array()
310
- );
311
- }
312
-
313
- if (empty($eventsInitialData[0])) {
314
- $eventsInitialData[0][] = array('param' => 'load', 'value' => '');
315
- }
316
-
317
- update_post_meta($popupId, 'sg_popup_events', $eventsInitialData);
318
-
319
- // by user status (logged in/out)
320
- if (!empty($options['sgpb-by-user-status'])) {
321
- $operator = '==';
322
- if (isset($options['sgpb-for-logged-in-user']) && $options['sgpb-for-logged-in-user'] === 'false') {
323
- $operator = '!=';
324
- }
325
- $conditions['sgpb-conditions'][0][] = array(
326
- 'param' => 'groups_user_role',
327
- 'operator' => $operator,
328
- 'value' => 'loggedIn'
329
- );
330
- }
331
-
332
- // hide or show on mobile
333
- if (isset($options['sgpb-hide-on-mobile']) && $options['sgpb-hide-on-mobile'] == 'on') {
334
- $conditions['sgpb-conditions'][0][] = array(
335
- 'param' => 'groups_devices',
336
- 'operator' => '!=',
337
- 'value' => array(
338
- 'is_mobile'
339
- )
340
- );
341
- }
342
- if (isset($options['sgpb-only-on-mobile']) && $options['sgpb-only-on-mobile'] == 'on') {
343
- $conditions['sgpb-conditions'][0][] = array(
344
- 'param' => 'groups_devices',
345
- 'operator' => '==',
346
- 'value' => array(
347
- 'is_mobile'
348
- )
349
- );
350
- }
351
-
352
- // detect by country
353
- if (isset($options['sgpb-by-country']) && $options['sgpb-by-country'] == 'on') {
354
- if (isset($options['sgpb-allow-countries'])) {
355
- $options['sgpb-allow-countries'] = '!=';
356
- if ($options['sgpb-allow-countries'] == 'allow') {
357
- $options['sgpb-allow-countries'] = '==';
358
- }
359
- }
360
- $conditions['sgpb-conditions'][0][] = array(
361
- 'param' => 'groups_countries',
362
- 'operator' => @$options['sgpb-allow-countries'],
363
- 'value' => explode(',', @$options['sgpb-countries-iso'])
364
- );
365
- }
366
-
367
- update_post_meta($popupId, 'sg_popup_target', $conditions);
368
-
369
- // random popup
370
- if (isset($options['sgpb-random-popup']) && $options['sgpb-random-popup'] == 'on') {
371
- $randomPopupCategory = AdminHelper::getTaxonomyBySlug(SG_RANDOM_TAXONOMY_SLUG);
372
- wp_set_object_terms($popupId, SG_RANDOM_TAXONOMY_SLUG, SG_POPUP_CATEGORY_TAXONOMY, true);
373
- }
374
-
375
- $this->saveProTarget($options);
376
-
377
- // MailChimp
378
- $mailchimpApiKey = get_option("SG_MAILCHIMP_API_KEY");
379
-
380
- if ($mailchimpApiKey) {
381
- update_option('SGPB_MAILCHIMP_API_KEY', $mailchimpApiKey);
382
- }
383
-
384
- // AWeber
385
- $aweberAccessToken = get_option('sgAccessToken');
386
- if ($aweberAccessToken) {
387
- $requestTokenSecret = get_option('requestTokenSecret');
388
- $accessTokenSecret = get_option('sgAccessTokenSecret');
389
-
390
- update_option('sgpbRequestTokenSecret', $requestTokenSecret);
391
- update_option('sgpbAccessTokenSecret', $accessTokenSecret);
392
- update_option('sgpbAccessToken', $aweberAccessToken);
393
- }
394
-
395
- return $options;
396
- }
397
-
398
- public function saveProTarget($options)
399
- {
400
- if (empty($options)) {
401
- return;
402
- }
403
- $popupId = (int)$options['sgpb-post-id'];
404
- // It's got already saved targets for do not override already saved data
405
- $popupSavedTarget = get_post_meta($popupId, 'sg_popup_target');
406
- $target = array();
407
- $target['sgpb-target'] = array();
408
- $target['sgpb-conditions'] = array();
409
-
410
- if (!empty($popupSavedTarget[0]['sgpb-conditions'])) {
411
- $target['sgpb-conditions'] = $popupSavedTarget[0]['sgpb-conditions'];
412
- }
413
- $isSavedToHome = false;
414
-
415
- if (!empty($options['allPagesStatus'])) {
416
-
417
- if ($options['allPages'] == 'selected') {
418
- $savedPages = (array)@$options['allSelectedPages'];
419
- $savedPagesValues = array_values($savedPages);
420
-
421
- // -1 mean saved for home page
422
- if (in_array('-1', $savedPagesValues)) {
423
- $isSavedToHome = true;
424
- }
425
- $args = array(
426
- 'post__in' => $savedPagesValues,
427
- 'posts_per_page' => 10,
428
- 'post_type' => 'page'
429
- );
430
-
431
- $searchResults = ConfigDataHelper::getPostTypeData($args);
432
- if (!empty($searchResults)) {
433
- $target['sgpb-target'][0][] = array('param' => 'page_selected', 'operator' => '==', 'value' => $searchResults);
434
- }
435
- }
436
- else {
437
- $target['sgpb-target'][0][] = array('param' => 'page_all', 'operator' => '==');
438
- }
439
- }
440
-
441
- if (!empty($options['allPostsStatus'])) {
442
- $allPosts = $options['allPosts'];
443
- if ($allPosts == 'selected') {
444
- $savedPosts = (array)$options['allSelectedPosts'];
445
- $savedPostsValues = array_values($savedPosts);
446
- // -1 mean saved for home page
447
- if (in_array('-1', $savedPostsValues)) {
448
- $isSavedToHome = true;
449
- }
450
- $args = array(
451
- 'post__in' => $savedPostsValues,
452
- 'posts_per_page' => 10,
453
- 'post_type' => 'post'
454
- );
455
-
456
- $searchResults = ConfigDataHelper::getPostTypeData($args);
457
- if (!empty($searchResults)) {
458
- $target['sgpb-target'][0][] = array('param' => 'post_selected', 'operator' => '==', 'value' => $searchResults);
459
- }
460
- }
461
- else if ($allPosts == 'all') {
462
- $target['sgpb-target'][0][] = array('param' => 'post_all', 'operator' => '==');
463
- }
464
- else {
465
- $selectedPostCategories = array_values($options['posts-all-categories']);
466
- $target['sgpb-target'][0][] = array('param' => 'post_category', 'operator' => '==', 'value' => $selectedPostCategories);
467
- }
468
- }
469
-
470
- if ($isSavedToHome) {
471
- $target['sgpb-target'][0][] = array('param' => 'page_type', 'operator' => '==', 'value' => array('is_home_page', 'is_home'));
472
- }
473
-
474
- if (!empty($options['allCustomPostsStatus'])) {
475
- $customPostTypes = $options['all-custom-posts'];
476
- if (!empty($customPostTypes)) {
477
- $selectedCustomPosts = $options['allSelectedCustomPosts'];
478
- if ($options['showAllCustomPosts'] == 'selected') {
479
- foreach ($customPostTypes as $customPostType) {
480
- $args = array(
481
- 'post__in' => array_values($selectedCustomPosts),
482
- 'posts_per_page' => 10,
483
- 'post_type' => $customPostType
484
- );
485
-
486
- $searchResults = ConfigDataHelper::getPostTypeData($args);
487
- if (!empty($searchResults)) {
488
- $target['sgpb-target'][0][] = array('param' => $customPostType.'_selected', 'operator' => '==', 'value' => $searchResults);
489
- }
490
- }
491
- }
492
-
493
- else {
494
- $target['sgpb-target'][0][] = array('param' => 'post_type', 'operator' => '==', 'value' => array_values($customPostTypes));
495
-
496
- }
497
- }
498
- }
499
-
500
- update_post_meta($popupId, 'sg_popup_target', $target);
501
- }
502
-
503
- /**
504
- * Get Addons options
505
- *
506
- * @param obj $popup
507
- *
508
- * @return bool|array
509
- */
510
- private function getAddonsEventFromPopup($popup)
511
- {
512
- if (empty($popup)) {
513
- return false;
514
- }
515
- $popupId = $popup->getId();
516
- global $wpdb;
517
-
518
- $addonsOptionSqlString = 'SELECT options FROM '.$wpdb->prefix.'sg_popup_addons_connection WHERE popupId = %d and extensionType = "option"';
519
- $addonsSql = $wpdb->prepare($addonsOptionSqlString, $popupId);
520
- $results = $wpdb->get_results($addonsSql, ARRAY_A);
521
-
522
- if (empty($results)) {
523
- return false;
524
- }
525
-
526
- $options = array();
527
-
528
- // it's collect all events saved values ex Exit Intent and AdBlock
529
- foreach ($results as $result) {
530
- $currentOptions = json_decode($result['options'], true);
531
-
532
- if (empty($currentOptions)) {
533
- continue;
534
- }
535
- $options = array_merge($options, $currentOptions);
536
- }
537
-
538
- return $options;
539
- }
540
-
541
- /**
542
- * Filter and change some related values for new version
543
- *
544
- * @param array $options
545
- *
546
- * @return array $options
547
- */
548
- private function filterOptions($options)
549
- {
550
- if (@$options['effect'] != 'No effect') {
551
- $options['sgpb-open-animation'] = 'on';
552
- }
553
-
554
- if (isset($options['isActiveStatus']) && $options['isActiveStatus'] == 'off') {
555
- $options['isActiveStatus'] = '';
556
- }
557
-
558
- if (empty($options['sgTheme3BorderColor'])) {
559
- $options['sgTheme3BorderColor'] = '#000000';
560
- }
561
-
562
- if (@$options['popupContentBackgroundRepeat'] != 'no-repeat' && $options['popupContentBackgroundSize'] == 'auto') {
563
- $options['popupContentBackgroundSize'] = 'repeat';
564
- }
565
- $themeNumber = 1;
566
-
567
- if (isset($options['theme'])) {
568
- $themeNumber = preg_replace('/[^0-9]/', '', $options['theme']);
569
- }
570
-
571
- if (isset($options['aweber-success-behavior']) && $options['aweber-success-behavior'] == 'redirectToUrl') {
572
- $options['aweber-success-behavior'] = 'redirectToURL';
573
- }
574
-
575
- // pro options
576
- if (isset($options['disablePopupOverlay'])) {
577
- $options['sgpb-enable-popup-overlay'] = '';
578
- }
579
- // contact form new options
580
- if (isset($options['contact-success-behavior']) && $options['contact-success-behavior'] == 'redirectToUrl') {
581
- $options['contact-success-behavior'] = 'redirectToURL';
582
- }
583
- if (isset($options['contact-text-input-bgcolor'])) {
584
- $options['sgpb-contact-message-bg-color'] = $options['contact-text-input-bgcolor'];
585
- }
586
- if (isset($options['contact-text-bordercolor'])) {
587
- $options['sgpb-contact-message-border-color'] = $options['contact-text-bordercolor'];
588
- }
589
- if (isset($options['contact-inputs-color'])) {
590
- $options['sgpb-contact-message-text-color'] = $options['contact-inputs-color'];
591
- }
592
- if (isset($options['contact-placeholder-color'])) {
593
- $options['sgpb-contact-message-placeholder-color'] = $options['contact-placeholder-color'];
594
- }
595
- if (isset($options['contact-inputs-border-width'])) {
596
- $options['sgpb-contact-message-border-width'] = $options['contact-inputs-border-width'];
597
- }
598
-
599
- if (isset($options['contact-success-popups-list'])) {
600
- $options['contact-success-popups-list'] = sgpGetCorrectPopupId($options['contact-success-popups-list']);
601
- }
602
-
603
- if (isset($options['popup-content-padding'])) {
604
- // add theme default padding to content padding
605
- switch ($themeNumber) {
606
- case 1:
607
- $options['popup-content-padding'] += 7;
608
- break;
609
- case 4:
610
- case 6:
611
- $options['popup-content-padding'] += 12;
612
- break;
613
- case 2:
614
- case 3:
615
- $options['popup-content-padding'] += 0;
616
- break;
617
- case 5:
618
- $options['popup-content-padding'] += 5;
619
- break;
620
- }
621
- }
622
-
623
- switch ($themeNumber) {
624
- case 1:
625
- $buttonImageWidth = 21;
626
- $buttonImageHeight = 21;
627
- break;
628
- case 2:
629
- $buttonImageWidth = 20;
630
- $buttonImageHeight = 20;
631
- break;
632
- case 3:
633
- $buttonImageWidth = 38;
634
- $buttonImageHeight = 19;
635
- break;
636
- case 5:
637
- $buttonImageWidth = 17;
638
- $buttonImageHeight = 17;
639
- break;
640
- case 6:
641
- $buttonImageWidth = 30;
642
- $buttonImageHeight = 30;
643
- break;
644
- default:
645
- $buttonImageWidth = 0;
646
- $buttonImageHeight = 0;
647
- }
648
-
649
- // social popup add to default value
650
- if (empty($options['sgMailLable'])) {
651
- $options['sgMailLable'] = 'E-mail';
652
- }
653
- if (empty($options['fbShareLabel'])) {
654
- $options['fbShareLabel'] = 'Share';
655
- }
656
- if (empty($options['lindkinLabel'])) {
657
- $options['lindkinLabel'] = 'Share';
658
- }
659
- if (empty($options['googLelabel'])) {
660
- $options['googLelabel'] = '+1';
661
- }
662
- if (empty($options['twitterLabel'])) {
663
- $options['twitterLabel'] = 'Tweet';
664
- }
665
- if (empty($options['pinterestLabel'])) {
666
- $options['pinterestLabel'] = 'Pin it';
667
- }
668
-
669
- if (isset($options['subs-success-behavior']) && $options['subs-success-behavior'] == 'redirectToUrl') {
670
- $options['subs-success-behavior'] = 'redirectToURL';
671
- }
672
-
673
- $options['sgpb-subs-form-bg-color'] = '#FFFFFF';
674
- $options['sgpb-button-image-width'] = $buttonImageWidth;
675
- $options['sgpb-button-image-height'] = $buttonImageHeight;
676
-
677
- // pro options customizations
678
- if (SGPB_POPUP_PKG > SGPB_POPUP_PKG_FREE) {
679
- if (empty($options['sgpb-restriction-yes-btn-radius-type'])) {
680
- $options['sgpb-restriction-yes-btn-radius-type'] = '%';
681
- }
682
-
683
- if (empty($options['sgpb-restriction-no-btn-radius-type'])) {
684
- $options['sgpb-restriction-no-btn-radius-type'] = '%';
685
- }
686
-
687
- if (empty($options['sgpb-restriction-yes-btn-border-color'])) {
688
- // border color should be like background color
689
- $options['sgpb-restriction-yes-btn-border-color'] = $options['yesButtonBackgroundColor'];
690
- }
691
- if (empty($options['sgpb-restriction-no-btn-border-color'])) {
692
- // border color should be like background color
693
- $options['sgpb-restriction-no-btn-border-color'] = $options['noButtonBackgroundColor'];
694
- }
695
- }
696
-
697
- return $options;
698
- }
699
-
700
- public function changeOldValues($optionName, $optionValue)
701
- {
702
- if ($optionName == 'theme') {
703
- $themeNumber = preg_replace('/[^0-9]/', '', $optionValue);
704
- $optionValue = 'sgpb-theme-'.$themeNumber;
705
- }
706
-
707
- return $optionValue;
708
- }
709
-
710
- private function popupObjectFromArray($arr)
711
- {
712
- global $wpdb;
713
-
714
- $options = json_decode($arr['options'], true);
715
- $type = $arr['type'];
716
-
717
- if (empty($type)) {
718
- return false;
719
- }
720
-
721
- $this->setId($arr['id']);
722
- $this->setType($type);
723
- $this->setTitle($arr['title']);
724
- $this->setContent('');
725
-
726
- switch ($type) {
727
- case 'image':
728
- $query = $wpdb->prepare('SELECT `url` FROM '.$wpdb->prefix.'sg_image_popup WHERE id = %d', $arr['id']);
729
- $result = $wpdb->get_row($query, ARRAY_A);
730
-
731
- if (!empty($result['url'])) {
732
- $options['image-url'] = $result['url'];
733
- }
734
- break;
735
- case 'html':
736
- $query = $wpdb->prepare('SELECT `content` FROM '.$wpdb->prefix.'sg_html_popup WHERE id = %d', $arr['id']);
737
- $result = $wpdb->get_row($query, ARRAY_A);
738
-
739
- if (!empty($result['content'])) {
740
- $this->setContent($result['content']);
741
- }
742
- break;
743
- case 'fblike':
744
- $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_fblike_popup WHERE id = %d', $arr['id']);
745
- $result = $wpdb->get_row($query, ARRAY_A);
746
-
747
- if (!empty($result['content'])) {
748
- $this->setContent($result['content']);
749
- }
750
- $customOptions = $result['options'];
751
- $customOptions = json_decode($customOptions, true);
752
-
753
- if (!empty($options)) {
754
- $this->setCustomOptions($customOptions);
755
- }
756
- break;
757
- case 'shortcode':
758
- $query = $wpdb->prepare('SELECT `url` FROM '.$wpdb->prefix.'sg_shortCode_popup WHERE id = %d', $arr['id']);
759
- $result = $wpdb->get_row($query, ARRAY_A);
760
-
761
- if (!empty($result['url'])) {
762
- $this->setContent($result['url']);
763
- }
764
- break;
765
- case 'iframe':
766
- $query = $wpdb->prepare('SELECT `url` FROM '.$wpdb->prefix.'sg_iframe_popup WHERE id = %d', $arr['id']);
767
- $result = $wpdb->get_row($query, ARRAY_A);
768
- if (!empty($result['url'])) {
769
- $options['iframe-url'] = $result['url'];
770
- }
771
- break;
772
- case 'video':
773
- $query = $wpdb->prepare('SELECT `url`, `options` FROM '.$wpdb->prefix.'sg_video_popup WHERE id = %d', $arr['id']);
774
- $result = $wpdb->get_row($query, ARRAY_A);
775
- if (!empty($result['url'])) {
776
- $options['video-url'] = $result['url'];
777
- }
778
-
779
- $customOptions = $result['options'];
780
- $customOptions = json_decode($customOptions, true);
781
-
782
- if (!empty($customOptions)) {
783
- $this->setCustomOptions($customOptions);
784
- }
785
- break;
786
- case 'ageRestriction':
787
- $query = $wpdb->prepare('SELECT `content`, `yesButton` as `yesButtonLabel`, `noButton` as `noButtonLabel`, `url` as `restrictionUrl` FROM '.$wpdb->prefix.'sg_age_restriction_popup WHERE id = %d', $arr['id']);
788
- $result = $wpdb->get_row($query, ARRAY_A);
789
- if (!empty($result['content'])) {
790
- $this->setContent($result['content']);
791
- }
792
- unset($result['content']);
793
- if (!empty($result)) {
794
- $this->setCustomOptions($result);
795
- }
796
- break;
797
- case 'social':
798
- $query = $wpdb->prepare('SELECT `socialContent`, `buttons`, `socialOptions` FROM '.$wpdb->prefix.'sg_social_popup WHERE id = %d', $arr['id']);
799
- $result = $wpdb->get_row($query, ARRAY_A);
800
-
801
- if (!empty($result['socialContent'])) {
802
- $this->setContent($result['socialContent']);
803
- }
804
-
805
- $buttons = json_decode($result['buttons'], true);
806
- $socialOptions = json_decode($result['socialOptions'], true);
807
-
808
- $socialAllOptions = array_merge($buttons, $socialOptions);
809
-
810
- $this->setCustomOptions($socialAllOptions);
811
- break;
812
- case 'subscription':
813
- $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_subscription_popup WHERE id = %d', $arr['id']);
814
- $result = $wpdb->get_row($query, ARRAY_A);
815
-
816
- if (!empty($result['content'])) {
817
- $this->setContent($result['content']);
818
- }
819
-
820
- $subsOptions = $result['options'];
821
- $subsOptions = json_decode($subsOptions, true);
822
-
823
- if (!empty($subsOptions)) {
824
- $this->setCustomOptions($subsOptions);
825
- }
826
- break;
827
- case 'countdown':
828
- $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_countdown_popup WHERE id = %d', $arr['id']);
829
- $result = $wpdb->get_row($query, ARRAY_A);
830
-
831
- if (!empty($result['content'])) {
832
- $this->setContent($result['content']);
833
- }
834
- $customOptions = $result['options'];
835
- $customOptions = json_decode($customOptions, true);
836
-
837
- if (!empty($options)) {
838
- $this->setCustomOptions($customOptions);
839
- }
840
- break;
841
- case 'contactForm':
842
- $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_contact_form_popup WHERE id = %d', $arr['id']);
843
- $result = $wpdb->get_row($query, ARRAY_A);
844
-
845
- if (!empty($result['content'])) {
846
- $this->setContent($result['content']);
847
- }
848
- $customOptions = $result['options'];
849
- $customOptions = json_decode($customOptions, true);
850
-
851
- if (!empty($options)) {
852
- $this->setCustomOptions($customOptions);
853
- }
854
- break;
855
- case 'mailchimp':
856
- $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_popup_mailchimp WHERE id = %d', $arr['id']);
857
- $result = $wpdb->get_row($query, ARRAY_A);
858
-
859
- if (!empty($result['content'])) {
860
- $this->setContent($result['content']);
861
- }
862
-
863
- $customOptions = $result['options'];
864
- $customOptions = json_decode($customOptions, true);
865
-
866
- if (!empty($options)) {
867
- $this->setCustomOptions($customOptions);
868
- }
869
- break;
870
- case 'aweber':
871
- $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_popup_aweber WHERE id = %d', $arr['id']);
872
- $result = $wpdb->get_row($query, ARRAY_A);
873
-
874
- if (!empty($result['content'])) {
875
- $this->setContent($result['content']);
876
- }
877
-
878
- $customOptions = $result['options'];
879
- $customOptions = json_decode($customOptions, true);
880
-
881
- if (!empty($options)) {
882
- $this->setCustomOptions($customOptions);
883
- }
884
- break;
885
- }
886
-
887
- $this->setOptions($options);
888
-
889
- return $this;
890
- }
891
-
892
- public function getNamesMapping()
893
- {
894
- $names = array(
895
- 'type' => 'sgpb-type',
896
- 'delay' => 'sgpb-popup-delay',
897
- 'isActiveStatus' => 'sgpb-is-active',
898
- 'image-url' => 'sgpb-image-url',
899
- 'theme' => 'sgpb-popup-themes',
900
- 'effect' => 'sgpb-open-animation-effect',
901
- 'duration' => 'sgpb-open-animation-speed',
902
- 'popupOpenSound' => 'sgpb-open-sound',
903
- 'popupOpenSoundFile' => 'sgpb-sound-url',
904
- 'popup-dimension-mode' => 'sgpb-popup-dimension-mode',
905
- 'popup-responsive-dimension-measure' => 'sgpb-responsive-dimension-measure',
906
- 'width' => 'sgpb-width',
907
- 'height' => 'sgpb-height',
908
- 'maxWidth' => 'sgpb-max-width',
909
- 'maxHeight' => 'sgpb-max-height',
910
- 'escKey' => 'sgpb-esc-key',
911
- 'closeButton' => 'sgpb-enable-close-button',
912
- 'buttonDelayValue' => 'sgpb-close-button-delay',
913
- 'scrolling' => 'sgpb-enable-content-scrolling',
914
- 'disable-page-scrolling' => 'sgpb-disable-page-scrolling',
915
- 'overlayClose' => 'sgpb-overlay-click',
916
- 'contentClick' => 'sgpb-content-click',
917
- 'content-click-behavior' => 'sgpb-content-click-behavior',
918
- 'click-redirect-to-url' => 'sgpb-click-redirect-to-url',
919
- 'redirect-to-new-tab' => 'sgpb-redirect-to-new-tab',
920
- 'reopenAfterSubmission' => 'sgpb-reopen-after-form-submission',
921
- 'repeatPopup' => 'sgpb-show-popup-same-user',
922
- 'popup-appear-number-limit' => 'sgpb-show-popup-same-user-count',
923
- 'onceExpiresTime' => 'sgpb-show-popup-same-user-expiry',
924
- 'save-cookie-page-level' => 'sgpb-show-popup-same-user-page-level',
925
- 'popupContentBgImage' => 'sgpb-show-background',
926
- 'popupContentBackgroundSize' => 'sgpb-background-image-mode',
927
- 'popupContentBgImageUrl' => 'sgpb-background-image',
928
- 'sgOverlayColor' => 'sgpb-overlay-color',
929
- 'sg-content-background-color' => 'sgpb-background-color',
930
- 'popup-background-opacity' => 'sgpb-content-opacity',
931
- 'opacity' => 'sgpb-overlay-opacity',
932
- 'sgOverlayCustomClasss' => 'sgpb-overlay-custom-class',
933
- 'sgContentCustomClasss' => 'sgpb-content-custom-class',
934
- 'popup-z-index' => 'sgpb-popup-z-index',
935
- 'popup-content-padding' => 'sgpb-content-padding',
936
- 'popupFixed' => 'sgpb-popup-fixed',
937
- 'fixedPostion' => 'sgpb-popup-fixed-position',
938
- 'sgpb-open-animation' => 'sgpb-open-animation',
939
- 'theme-close-text' => 'sgpb-button-text',
940
- 'sgTheme3BorderRadius' => 'sgpb-border-radius',
941
- 'sgTheme3BorderColor' => 'sgpb-border-color',
942
- 'fblike-like-url' => 'sgpb-fblike-like-url',
943
- 'fblike-layout' => 'sgpb-fblike-layout',
944
- 'fblike-dont-show-share-button' => 'sgpb-fblike-dont-show-share-button',
945
- 'sgpb-button-image-width' => 'sgpb-button-image-width',
946
- 'sgpb-button-image-height' => 'sgpb-button-image-height'
947
- );
948
- // iframe pro popup type
949
- $names['iframe-url'] = 'sgpb-iframe-url';
950
-
951
- // video pro popup type
952
- $names['video-url'] = 'sgpb-video-url';
953
- $names['video-autoplay'] = 'sgpb-video-autoplay';
954
-
955
- // age restriction
956
- $names['yesButtonLabel'] = 'sgpb-restriction-yes-btn';
957
- $names['noButtonLabel'] = 'sgpb-restriction-no-btn';
958
- $names['restrictionUrl'] = 'sgpb-restriction-no-url';
959
- $names['yesButtonBackgroundColor'] = 'sgpb-restriction-yes-btn-bg-color';
960
- $names['yesButtonTextColor'] = 'sgpb-restriction-yes-btn-text-color';
961
- $names['yesButtonRadius'] = 'sgpb-restriction-yes-btn-radius';
962
- $names['sgRestrictionExpirationTime'] = 'sgpb-restriction-yes-expiration-time';
963
- $names['restrictionCookeSavingLevel'] = 'sgpb-restriction-cookie-level';
964
- $names['noButtonBackgroundColor'] = 'sgpb-restriction-no-btn-bg-color';
965
- $names['noButtonTextColor'] = 'sgpb-restriction-no-btn-text-color';
966
- $names['noButtonRadius'] = 'sgpb-restriction-no-btn-radius';
967
-
968
- // age restriction new options
969
- $names['sgpb-restriction-yes-btn-radius-type'] = 'sgpb-restriction-yes-btn-radius-type';
970
- $names['sgpb-restriction-no-btn-radius-type'] = 'sgpb-restriction-no-btn-radius-type';
971
- $names['sgpb-restriction-yes-btn-border-color'] = 'sgpb-restriction-yes-btn-border-color';
972
- $names['sgpb-restriction-no-btn-border-color'] = 'sgpb-restriction-no-btn-border-color';
973
-
974
- $proNames = array(
975
- 'autoClosePopup' => 'sgpb-auto-close',
976
- 'popupClosingTimer' => 'sgpb-auto-close-time',
977
- 'disablePopupOverlay' => 'sgpb-enable-popup-overlay',
978
- 'disablePopup' => 'sgpb-disable-popup-closing',
979
- 'popup-schedule-status' => 'sgpb-schedule-status',
980
- 'schedule-start-weeks' => 'sgpb-schedule-weeks',
981
- 'schedule-start-time' => 'sgpb-schedule-start-time',
982
- 'schedule-end-time' => 'sgpb-schedule-end-time',
983
- 'popup-timer-status' => 'sgpb-popup-timer-status',
984
- 'popup-start-timer' => 'sgpb-popup-start-timer',
985
- 'popup-finish-timer' => 'sgpb-popup-end-timer',
986
- 'inActivityStatus' => 'sgpb-inactivity-status',
987
- 'inactivity-timout' => 'sgpb-inactivity-timer',
988
- 'onScrolling' => 'sgpb-onscroll-status',
989
- 'beforeScrolingPrsent' => 'sgpb-onscroll-percentage',
990
- 'sg-user-status' => 'sgpb-by-user-status',
991
- 'loggedin-user' => 'sgpb-for-logged-in-user',
992
- 'forMobile' => 'sgpb-hide-on-mobile',
993
- 'openMobile' => 'sgpb-only-on-mobile',
994
- 'countryStatus' => 'sgpb-by-country',
995
- 'allowCountries' => 'sgpb-allow-countries',
996
- 'countryIso' => 'sgpb-countries-iso',
997
- 'randomPopup' => 'sgpb-random-popup'
998
- );
999
- $names = array_merge($names, $proNames);
1000
-
1001
- // pro options
1002
- $names['allPagesStatus'] = 'allPagesStatus';
1003
- $names['showAllPages'] = 'allPages';
1004
- $names['allSelectedPages'] = 'allSelectedPages';
1005
- $names['allPostsStatus'] = 'allPostsStatus';
1006
- $names['showAllPosts'] = 'allPosts';
1007
- $names['allSelectedPosts'] = 'allSelectedPosts';
1008
- $names['posts-all-categories'] = 'posts-all-categories';
1009
- $names['allCustomPostsStatus'] = 'allCustomPostsStatus';
1010
- $names['all-custom-posts'] = 'all-custom-posts';
1011
- $names['showAllCustomPosts'] = 'showAllCustomPosts';
1012
- $names['allSelectedCustomPosts'] = 'allSelectedCustomPosts';
1013
- // countdown pro popup type
1014
- $names['countdownNumbersBgColor'] = 'sgpb-counter-background-color';
1015
- $names['countdownNumbersTextColor'] = 'sgpb-counter-text-color';
1016
- $names['sg-due-date'] = 'sgpb-countdown-due-date';
1017
- $names['sg-countdown-type'] = 'sgpb-countdown-type';
1018
- $names['sg-time-zone'] = 'sgpb-countdown-timezone';
1019
- $names['counts-language'] = 'sgpb-countdown-language';
1020
- $names['pushToBottom'] = 'sgpb-countdown-show-on-top';
1021
- $names['countdown-autoclose'] = 'sgpb-countdown-close-timeout';
1022
- // contact form pro popup type
1023
- $names['show-form-to-top'] = 'sgpb-contact-show-form-to-top';
1024
- $names['contact-name-status'] = 'sgpb-contact-field-name';
1025
- $names['contact-name'] = 'sgpb-contact-name-placeholder';
1026
- $names['contact-name-required'] = 'sgpb-contact-name-required';
1027
- $names['contact-subject-status'] = 'sgpb-contact-field-subject';
1028
- $names['contact-subject'] = 'sgpb-contact-subject-placeholder';
1029
- $names['contact-subject-required'] = 'sgpb-contact-subject-required';
1030
- $names['contact-email'] = 'sgpb-contact-email-placeholder';
1031
- $names['contact-message'] = 'sgpb-contact-message-placeholder';
1032
- $names['contact-fail-message'] = 'sgpb-contact-error-message';
1033
- $names['contact-receive-email'] = 'sgpb-contact-to-email';
1034
- $names['contact-validation-message'] = 'sgpb-contact-required-message';
1035
- $names['contact-validate-email'] = 'sgpb-contact-invalid-email-message';
1036
- $names['contact-inputs-width'] = 'sgpb-contact-inputs-width';
1037
- $names['contact-inputs-height'] = 'sgpb-contact-inputs-height';
1038
- $names['contact-inputs-border-width'] = 'sgpb-contact-inputs-border-width';
1039
- $names['contact-text-input-bgcolor'] = 'sgpb-contact-inputs-bg-color';
1040
- $names['contact-text-bordercolor'] = 'sgpb-contact-inputs-border-color';
1041
- $names['contact-inputs-color'] = 'sgpb-contact-inputs-text-color';
1042
- $names['contact-placeholder-color'] = 'sgpb-contact-inputs-placeholder-color';
1043
- $names['contact-area-width'] = 'sgpb-contact-message-width';
1044
- $names['contact-area-height'] = 'sgpb-contact-message-height';
1045
- $names['sg-contact-resize'] = 'sgpb-contact-message-resize';
1046
- $names['contact-btn-width'] = 'sgpb-contact-submit-width';
1047
- $names['contact-btn-height'] = 'sgpb-contact-submit-height';
1048
- $names['contact-btn-title'] = 'sgpb-contact-submit-title';
1049
- $names['contact-btn-progress-title'] = 'sgpb-contact-submit-title-progress';
1050
- $names['contact-button-bgcolor'] = 'sgpb-contact-submit-bg-color';
1051
- $names['contact-button-color'] = 'sgpb-contact-submit-text-color';
1052
- $names['dont-show-content-to-contacted-user'] = 'sgpb-contact-hide-for-contacted-users';
1053
- $names['contact-success-behavior'] = 'sgpb-contact-success-behavior';
1054
- $names['contact-success-message'] = 'sgpb-contact-success-message';
1055
- $names['contact-success-redirect-url'] = 'sgpb-contact-success-redirect-URL';
1056
- $names['contact-success-redirect-new-tab'] = 'sgpb-contact-success-redirect-new-tab';
1057
- $names['contact-success-popups-list'] = 'sgpb-contact-success-popup';
1058
- $names['contact-gdpr'] = 'sgpb-contact-gdpr-status';
1059
- $names['contact-gdpr-label'] = 'sgpb-contact-gdpr-label';
1060
- $names['contact-gdpr-text'] = 'sgpb-contact-gdpr-text';
1061
- $names['sgpb-contact-message-bg-color'] = 'sgpb-contact-message-bg-color';
1062
- $names['sgpb-contact-message-border-color'] = 'sgpb-contact-message-border-color';
1063
- $names['sgpb-contact-message-text-color'] = 'sgpb-contact-message-text-color';
1064
- $names['sgpb-contact-message-placeholder-color'] = 'sgpb-contact-message-placeholder-color';
1065
- $names['sgpb-contact-message-border-width'] = 'sgpb-contact-message-border-width';
1066
-
1067
- // Social
1068
- $names['shareUrlType'] = 'sgpb-social-share-url-type';
1069
- $names['sgShareUrl'] = 'sgpb-social-share-url';
1070
- $names['sgSocialTheme'] = 'sgpb-social-share-theme';
1071
- $names['sgSocialButtonsSize'] = 'sgpb-social-theme-size';
1072
- $names['sgSocialLabel'] = 'sgpb-social-show-labels';
1073
- $names['sgSocialShareCount'] = 'sgpb-social-share-count';
1074
- $names['sgRoundButton'] = 'sgpb-social-round-buttons';
1075
- $names['sgEmailStatus'] = 'sgpb-social-status-email';
1076
- $names['sgMailLable'] = 'sgpb-social-label-email';
1077
- $names['sgFbStatus'] = 'sgpb-social-status-facebook';
1078
- $names['fbShareLabel'] = 'sgpb-social-label-facebook';
1079
- $names['sgLinkedinStatus'] = 'sgpb-social-status-linkedin';
1080
- $names['lindkinLabel'] = 'sgpb-social-label-linkedin';
1081
- $names['sgGoogleStatus'] = 'sgpb-social-status-googleplus';
1082
- $names['googLelabel'] = 'sgpb-social-label-googleplus';
1083
- $names['sgTwitterStatus'] = 'sgpb-social-status-twitter';
1084
- $names['twitterLabel'] = 'sgpb-social-label-twitter';
1085
- $names['sgPinterestStatus'] = 'sgpb-social-status-pinterest';
1086
- $names['pinterestLabel'] = 'sgpb-social-label-pinterest';
1087
-
1088
- // Subscription
1089
- $names['subscription-email'] = 'sgpb-subs-email-placeholder';
1090
- $names['subs-gdpr'] = 'sgpb-subs-gdpr-status';
1091
- $names['subs-gdpr-label'] = 'sgpb-subs-gdpr-label';
1092
- $names['subs-gdpr-text'] = 'sgpb-subs-gdpr-text';
1093
- $names['subs-first-name-status'] = 'sgpb-subs-first-name-status';
1094
- $names['subs-first-name'] = 'sgpb-subs-first-placeholder';
1095
- $names['subs-first-name-required'] = 'sgpb-subs-first-name-required';
1096
- $names['subs-last-name-status'] = 'sgpb-subs-last-name-status';
1097
- $names['subs-last-name'] = 'sgpb-subs-last-placeholder';
1098
- $names['subs-last-name-required'] = 'sgpb-subs-last-name-required';
1099
- $names['subs-validation-message'] = 'sgpb-subs-validation-message';
1100
- $names['subs-text-width'] = 'sgpb-subs-text-width';
1101
- $names['subs-text-height'] = 'sgpb-subs-text-height';
1102
- $names['subs-text-border-width'] = 'sgpb-subs-text-border-width';
1103
- $names['subs-text-input-bgColor'] = 'sgpb-subs-text-bg-color';
1104
- $names['subs-text-borderColor'] = 'sgpb-subs-text-border-color';
1105
- $names['subs-inputs-color'] = 'sgpb-subs-text-color';
1106
- $names['subs-placeholder-color'] = 'sgpb-subs-text-placeholder-color';
1107
- $names['subs-btn-width'] = 'sgpb-subs-btn-width';
1108
- $names['subs-btn-height'] = 'sgpb-subs-btn-height';
1109
- $names['subs-btn-title'] = 'sgpb-subs-btn-title';
1110
- $names['subs-btn-progress-title'] = 'sgpb-subs-btn-progress-title';
1111
- $names['subs-button-bgColor'] = 'sgpb-subs-btn-bg-color';
1112
- $names['subs-button-color'] = 'sgpb-subs-btn-text-color';
1113
- $names['subs-success-behavior'] = 'sgpb-subs-success-behavior';
1114
- $names['subs-success-message'] = 'sgpb-subs-success-message';
1115
- $names['subs-success-redirect-url'] = 'sgpb-subs-success-redirect-URL';
1116
- $names['subs-success-redirect-new-tab'] = 'sgpb-subs-success-redirect-new-tab';
1117
- $names['subs-success-popups-list'] = 'sgpb-subs-success-popup';
1118
- // Subscription new option
1119
- $names['sgpb-subs-form-bg-color'] = 'sgpb-subs-form-bg-color';
1120
-
1121
- // Exit Intent extension names
1122
- $names['option-exit-intent-enable'] = 'sgpb-option-exit-intent-enable';
1123
- $names['option-exit-intent-type'] = 'sgpb-option-exit-intent-type';
1124
- $names['option-exit-intent-expire-time'] = 'sgpb-exit-intent-expire-time';
1125
- $names['option-exit-intent-cookie-level'] = 'sgpb-exit-intent-cookie-level';
1126
- $names['option-exit-intent-soft-from-top'] = 'sgpb-exit-intent-soft-from-top';
1127
-
1128
- // Adblock extension names
1129
- $names['option-enable-ad-block'] = 'sgpb-option-enable-ad-block';
1130
- // MailChimp extension names
1131
- $names['mailchimp-list-id'] = 'sgpb-mailchimp-lists';
1132
- $names['mailchimp-double-optin'] = 'sgpb-enable-double-optin';
1133
- $names['mailchimp-only-required'] = 'sgpb-show-required-fields';
1134
- $names['mailchimp-form-aligment'] = 'sgpb-mailchimp-form-align';
1135
- $names['mailchimp-label-aligment'] = 'sgpb-mailchimp-label-alignment';
1136
- $names['mailchimp-indicates-required-fields'] = 'sgpb-enable-asterisk-label';
1137
- $names['mailchimp-asterisk-label'] = 'sgpb-mailchimp-asterisk-label';
1138
- $names['mailchimp-required-error-message'] = 'sgpb-mailchimp-required-message';
1139
- $names['mailchimp-email-validate-message'] = 'sgpb-mailchimp-email-message';
1140
- $names['mailchimp-email-label'] = 'sgpb-mailchimp-email-label';
1141
- $names['mailchimp-error-message'] = 'sgpb-mailchimp-error-message';
1142
- $names['mailchimp-show-form-to-top'] = 'sgpb-mailchimp-show-form-to-top';
1143
- $names['mailchimp-label-color'] = 'sgpb-mailchimp-label-color';
1144
- $names['mailchimp-input-width'] = 'sgpb-mailchimp-input-width';
1145
- $names['mailchimp-input-height'] = 'sgpb-mailchimp-input-height';
1146
- $names['mailchimp-input-border-radius'] = 'sgpb-mailchimp-border-radius';
1147
- $names['mailchimp-input-border-width'] = 'sgpb-mailchimp-border-width';
1148
- $names['mailchimp-input-border-color'] = 'sgpb-mailchimp-border-color';
1149
- $names['mailchimp-input-bg-color'] = 'sgpb-mailchimp-background-color';
1150
- $names['sgpb-mailchimp-input-color'] = 'sgpb-mailchimp-input-color';
1151
- $names['mailchimp-submit-title'] = 'sgpb-mailchimp-submit-title';
1152
- $names['mailchimp-submit-width'] = 'sgpb-mailchimp-submit-width';
1153
- $names['mailchimp-submit-height'] = 'sgpb-mailchimp-submit-height';
1154
- $names['mailchimp-submit-border-width'] = 'sgpb-mailchimp-submit-border-width';
1155
- $names['mailchimp-submit-border-radius'] = 'sgpb-mailchimp-submit-border-radius';
1156
- $names['mailchimp-submit-border-color'] = 'sgpb-mailchimp-submit-border-color';
1157
- $names['mailchimp-submit-button-bgcolor'] = 'sgpb-mailchimp-submit-background-color';
1158
- $names['mailchimp-submit-color'] = 'sgpb-mailchimp-submit-color';
1159
- $names['mailchimp-success-behavior'] = 'sgpb-mailchimp-success-behavior';
1160
- $names['mailchimp-success-message'] = 'sgpb-mailchimp-success-message';
1161
- $names['mailchimp-success-redirect-url'] = 'sgpb-mailchimp-success-redirect-URL';
1162
- $names['mailchimp-success-redirect-new-tab'] = 'sgpb-mailchimp-success-redirect-new-tab';
1163
- $names['mailchimp-success-popups-list'] = 'sgpb-mailchimp-success-popup';
1164
- $names['mailchimp-close-popup-already-subscribed'] = 'sgpb-mailchimp-close-popup-already-subscribed';
1165
- // AWeber extension
1166
- $names['sg-aweber-list'] = 'sgpb-aweber-list';
1167
- $names['sg-aweber-webform'] = 'sgpb-aweber-signup-form';
1168
- $names['aweber-custom-invalid-email-message'] = 'sgpb-aweber-invalid-email';
1169
- $names['aweber-invalid-email'] = 'sgpb-aweber-invalid-email-message';
1170
- $names['aweber-already-subscribed-message'] = 'sgpb-aweber-custom-subscribed-message';
1171
- $names['aweber-required-message'] = 'sgpb-aweber-required-message';
1172
- $names['aweber-validate-email-message'] = 'sgpb-aweber-validate-email-message';
1173
- $names['aweber-success-behavior'] = 'sgpb-aweber-success-behavior';
1174
- $names['aweber-success-message'] = 'sgpb-aweber-success-message';
1175
- $names['aweber-success-redirect-url'] = 'sgpb-aweber-success-redirect-URL';
1176
- $names['aweber-success-redirect-new-tab'] = 'sgpb-aweber-success-redirect-new-tab';
1177
- $names['aweber-success-popups-list'] = 'sgpb-aweber-success-popup';
1178
-
1179
- return $names;
1180
- }
1181
-
1182
- public static function saveCustomInserted()
1183
- {
1184
- global $post;
1185
- if (empty($post)) {
1186
- return false;
1187
- }
1188
-
1189
- $postId = $post->ID;
1190
- if (get_option('sgpbSaveOldData'.$postId)) {
1191
- return false;
1192
- }
1193
-
1194
- update_option('sgpbSaveOldData'.$postId, 1);
1195
-
1196
- add_filter('sgpbConvertedPopupId', 'sgpb\sgpGetCorrectPopupId', 10, 1);
1197
- self::saveMetaboxPopup($postId);
1198
- $content = get_post_field('post_content', $postId);
1199
- SGPopup::deletePostCustomInsertedData($postId);
1200
- SGPopup::deletePostCustomInsertedEvents($postId);
1201
- // We detect all the popups that were inserted as a custom ones, in the content.
1202
- SGPopup::savePopupsFromContentClasses($content, $post);
1203
- }
1204
-
1205
- public static function saveMetaboxPopup($postId)
1206
- {
1207
- $selectedPost = get_post_meta($postId, 'sg_promotional_popup', true);
1208
-
1209
- if (empty($selectedPost)) {
1210
- return false;
1211
- }
1212
- global $SGPB_DATA_CONFIG_ARRAY;
1213
-
1214
- $postType = get_post_type($postId);
1215
- $postTitle = get_the_title($postId);
1216
- $popupId = sgpGetCorrectPopupId($selectedPost);
1217
- $popupTargetParam = $postType.'_selected';
1218
-
1219
- if (!get_post_meta($popupId, 'sg_popup_events')) {
1220
- update_post_meta($popupId, 'sg_popup_events', array($SGPB_DATA_CONFIG_ARRAY['events']['initialData']));
1221
- }
1222
-
1223
- $savedTarget = get_post_meta($popupId, 'sg_popup_target');
1224
- if (empty($savedTarget[0]['sgpb-target'][0])) {
1225
- $savedTarget['sgpb-target'][] = array(array('param' => $popupTargetParam, 'operator' => '==', 'value' => array($postId => $postTitle)));
1226
- $savedTarget['sgpb-conditions'][] = $SGPB_DATA_CONFIG_ARRAY['conditions']['initialData'];
1227
-
1228
- update_post_meta($popupId, 'sg_popup_target', $savedTarget, true);
1229
- return true;
1230
- }
1231
- $targets = $savedTarget[0]['sgpb-target'][0];
1232
- $targetExists = false;
1233
-
1234
- foreach ($targets as $key => $target) {
1235
- if ($key == 0 && $target['param'] == 'not_rule') {
1236
- $target['param'] = $popupTargetParam;
1237
- $savedTarget[0]['sgpb-target'][0][$key]['param'] = $popupTargetParam;
1238
- }
1239
- if ($target['param'] == $popupTargetParam) {
1240
- $targetExists = true;
1241
- $targetValue = array();
1242
- if (!empty($target['value'])) {
1243
- $targetValue = $target['value'];
1244
- }
1245
-
1246
- $targetValue[$postId] = $postTitle;
1247
- $savedTarget[0]['sgpb-target'][0][$key]['value'] = $targetValue;
1248
- break;
1249
- }
1250
- }
1251
-
1252
- if (!$targetExists) {
1253
- $savedTargetsLength = count($savedTarget[0]['sgpb-target'][0]);
1254
- $savedTarget[0]['sgpb-target'][0][$savedTargetsLength] = array('param' => $popupTargetParam, 'operator' => '==', 'value' => array($postId => $postTitle));
1255
- }
1256
-
1257
- delete_post_meta($postId, 'sg_promotional_popup');
1258
- delete_post_meta($popupId, 'sg_popup_target');
1259
- update_post_meta($popupId, 'sg_popup_target', $savedTarget[0], true);
1260
-
1261
- return true;
1262
- }
1263
- }
1264
-
1265
- function sgpGetCorrectPopupId($popupId)
1266
- {
1267
- $convertedIds = get_option('sgpbConvertedIds');
1268
-
1269
- if (empty($convertedIds) || empty($convertedIds[$popupId])) {
1270
- return $popupId;
1271
- }
1272
-
1273
- return $convertedIds[$popupId];
1274
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use sgpb\AdminHelper;
4
+ use \ConfigDataHelper;
5
+
6
+ class ConvertToNewVersion
7
+ {
8
+ private $id;
9
+ private $content = '';
10
+ private $type;
11
+ private $title;
12
+ private $options;
13
+ private $customOptions = array();
14
+
15
+ public function setContent($content)
16
+ {
17
+ $this->content = $content;
18
+ }
19
+
20
+ public function getContent()
21
+ {
22
+ return $this->content;
23
+ }
24
+
25
+ public function setType($type)
26
+ {
27
+ if ($type == 'shortcode') {
28
+ $type = 'html';
29
+ }
30
+ $this->type = $type;
31
+ }
32
+
33
+ public function getType()
34
+ {
35
+ return $this->type;
36
+ }
37
+
38
+ public function setTitle($title)
39
+ {
40
+ $this->title = $title;
41
+ }
42
+
43
+ public function getTitle()
44
+ {
45
+ return $this->title;
46
+ }
47
+
48
+ public function setId($id)
49
+ {
50
+ $this->id = (int)$id;
51
+ }
52
+
53
+ public function getId()
54
+ {
55
+ return $this->id;
56
+ }
57
+
58
+ public function setOptions($options)
59
+ {
60
+ $this->options = $options;
61
+ }
62
+
63
+ public function getOptions()
64
+ {
65
+ return $this->options;
66
+ }
67
+
68
+ public function setCustomOptions($customOptions)
69
+ {
70
+ $this->customOptions = $customOptions;
71
+ }
72
+
73
+ public function getCustomOptions()
74
+ {
75
+ return $this->customOptions;
76
+ }
77
+
78
+ public static function convert()
79
+ {
80
+ $obj = new self();
81
+ $obj->insertDataToNew();
82
+ }
83
+
84
+ public function insertDataToNew()
85
+ {
86
+ $idsMapping = array();
87
+ Installer::install();
88
+ Installer::registerPlugin();
89
+ $popups = $this->getAllSavedPopups();
90
+ $this->convertSettings();
91
+
92
+ $arr = array();
93
+ $popupPreviewId = get_option('popupPreviewId');
94
+ foreach ($popups as $popup) {
95
+ if (empty($popup)) {
96
+ continue;
97
+ }
98
+ // we should not convert preview popup
99
+ if ($popup['id'] == $popupPreviewId) {
100
+ continue;
101
+ }
102
+
103
+ $popupObj = $this->popupObjectFromArray($popup);
104
+ $arr[] = $popupObj;
105
+ $args = array(
106
+ 'post_title' => $popupObj->getTitle(),
107
+ 'post_content' => $popupObj->getContent(),
108
+ 'post_status' => 'publish',
109
+ 'post_type' => SG_POPUP_POST_TYPE
110
+ );
111
+ $id = $popupObj->getId();
112
+ $newOptions = $this->getNewOptionsFormSavedData($popupObj);
113
+ $newPopupId = @wp_insert_post($args);
114
+ $newOptions['sgpb-post-id'] = $newPopupId;
115
+ $this->saveOtherOptions($newOptions);
116
+
117
+ update_post_meta($newPopupId, 'sg_popup_options', $newOptions);
118
+ $idsMapping[$id] = $newPopupId;
119
+ }
120
+
121
+ $this->convertCounter($idsMapping);
122
+ $this->convertSubscribers();
123
+
124
+ update_option('sgpbConvertedIds', $idsMapping);
125
+
126
+ return $arr;
127
+ }
128
+
129
+ public function convertSubscribers()
130
+ {
131
+ global $wpdb;
132
+ $subscribersSql = 'SELECT `id`, `firstName`, `lastName`, `email`, `subscriptionType`, `status` from '.$wpdb->prefix.'sg_subscribers';
133
+ $subscribers = $wpdb->get_results($subscribersSql, ARRAY_A);
134
+
135
+ if (empty($subscribers)) {
136
+ return false;
137
+ }
138
+
139
+ foreach ($subscribers as $subscriber) {
140
+ $subscriber['subscriptionType'] = $this->getPostByTitle($subscriber['subscriptionType']);
141
+
142
+ $date = date('Y-m-d');
143
+ $sql = $wpdb->prepare('INSERT INTO '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' (`firstName`, `lastName`, `email`, `cDate`, `subscriptionType`, `unsubscribed`) VALUES (%s, %s, %s, %s, %d, %d) ', $subscriber['firstName'], $subscriber['lastName'], $subscriber['email'], $date, $subscriber['subscriptionType'], 0);
144
+ $wpdb->query($sql);
145
+ }
146
+ }
147
+
148
+ private function getPostByTitle($pageTitle, $output = OBJECT)
149
+ {
150
+ global $wpdb;
151
+ $post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='popupbuilder'", $pageTitle));
152
+ if (!empty($post)) {
153
+ return get_post($post, $output)->ID;
154
+ }
155
+
156
+ return null;
157
+ }
158
+
159
+ /**
160
+ * Convert settings section saved options to new version
161
+ *
162
+ * @since 2.6.7.6
163
+ *
164
+ * @return bool
165
+ */
166
+ private function convertSettings()
167
+ {
168
+ global $wpdb;
169
+ $settings = $wpdb->get_row('SELECT options FROM '.$wpdb->prefix .'sg_popup_settings WHERE id = 1', ARRAY_A);
170
+
171
+ if (empty($settings['options'])) {
172
+ return false;
173
+ }
174
+ $settings = json_decode($settings['options'], true);
175
+
176
+ $deleteData = 0;
177
+
178
+ if (!empty($settings['tables-delete-status'])) {
179
+ $deleteData = 1;
180
+ }
181
+ $userRoles = $settings['plugin_users_role'];
182
+
183
+ if (empty($userRoles) || !is_array($userRoles)) {
184
+ $userRoles = array();
185
+ }
186
+
187
+ $userRoles = array_map(function($role) {
188
+ // it's remove sgpb_ keyword from selected values
189
+ $role = substr($role, 5, strlen($role)-1);
190
+
191
+ return $role;
192
+ }, $userRoles);
193
+
194
+ update_option('sgpb-user-roles', $userRoles);
195
+ update_option('sgpb-dont-delete-data', $deleteData);
196
+
197
+ return true;
198
+ }
199
+
200
+ private function convertCounter($idsMapping)
201
+ {
202
+ $oldCounter = get_option('SgpbCounter');
203
+
204
+ if (!$oldCounter) {
205
+ return false;
206
+ }
207
+ $newCounter = array();
208
+ foreach ($oldCounter as $key => $value) {
209
+ $newId = @$idsMapping[$key];
210
+ $newCounter[$newId] = $value;
211
+ }
212
+
213
+ update_option('SgpbCounter', $newCounter);
214
+
215
+ return true;
216
+ }
217
+
218
+
219
+ private function getAllSavedPopups()
220
+ {
221
+ global $wpdb;
222
+
223
+ $query = 'SELECT `id`, `type`, `title`, `options` from '.$wpdb->prefix.'sg_popup ORDER BY id';
224
+ $popups = $wpdb->get_results($query, ARRAY_A);
225
+
226
+ return $popups;
227
+ }
228
+
229
+ public function getNewOptionsFormSavedData($popup)
230
+ {
231
+ $options = $popup->getOptions();
232
+ $customOptions = $popup->getCustomOptions();
233
+ $options = array_merge($options, $customOptions);
234
+ // return addons event from add_connections data
235
+ $addonsEvent = $this->getAddonsEventFromPopup($popup);
236
+ if ($addonsEvent) {
237
+ $options = array_merge($options, $addonsEvent);
238
+ }
239
+ $options = $this->filterOptions($options);
240
+
241
+ $names = $this->getNamesMapping();
242
+ $newData = array();
243
+ $type = $popup->getType();
244
+
245
+ if (empty($names)) {
246
+ return $newData;
247
+ }
248
+
249
+ $newData['sgpb-type'] = $type;
250
+
251
+ foreach ($names as $oldName => $newName) {
252
+ if (isset($options[$oldName])) {
253
+ $optionName = $this->changeOldValues($oldName, $options[$oldName]);
254
+ $newData[$newName] = $optionName;
255
+ }
256
+ }
257
+ $newData['sgpb-enable-popup-overlay'] = 'on';
258
+ $newData['sgpb-show-background'] = 'on';
259
+
260
+ return $newData;
261
+ }
262
+
263
+ private function saveOtherOptions($options)
264
+ {
265
+ $popupId = (int)$options['sgpb-post-id'];
266
+ $mobileOperator = '';
267
+ $conditions = array();
268
+ $conditions['sgpb-target'] = array(array(array('param' => 'not_rule')));
269
+ $conditions['sgpb-conditions'] = array(array());
270
+
271
+ $eventsInitialData = array(
272
+ array(
273
+ )
274
+ );
275
+
276
+ if (!empty($options['sgpb-option-exit-intent-enable'])) {
277
+ $eventsInitialData[0][] = array(
278
+ 'param' => 'exitIntent',
279
+ 'value' => @$options['sgpb-option-exit-intent-type'],
280
+ 'hiddenOption' => array(
281
+ 'sgpb-exit-intent-expire-time' => @$options['sgpb-exit-intent-expire-time'],
282
+ 'sgpb-exit-intent-cookie-level' => @$options['sgpb-exit-intent-cookie-level'],
283
+ 'sgpb-exit-intent-soft-from-top' => @$options['sgpb-exit-intent-soft-from-top']
284
+ )
285
+ );
286
+ }
287
+ else if (!empty($options['sgpb-option-enable-ad-block'])) {
288
+ $eventsInitialData[0][] = array(
289
+ 'param' => 'AdBlock',
290
+ 'value' => $options['sgpb-popup-delay'],
291
+ 'hiddenOption' => array()
292
+ );
293
+ }
294
+
295
+ // after inactivity
296
+ if (!empty($options['sgpb-inactivity-status'])) {
297
+ $eventsInitialData[0][] = array(
298
+ 'param' => 'inactivity',
299
+ 'value' => @$options['sgpb-inactivity-timer'],
300
+ 'hiddenOption' => array()
301
+ );
302
+ }
303
+
304
+ // after scroll
305
+ if (!empty($options['sgpb-onscroll-status'])) {
306
+ $eventsInitialData[0][] = array(
307
+ 'param' => 'onScroll',
308
+ 'value' => @$options['sgpb-onscroll-percentage'],
309
+ 'hiddenOption' => array()
310
+ );
311
+ }
312
+
313
+ if (empty($eventsInitialData[0])) {
314
+ $eventsInitialData[0][] = array('param' => 'load', 'value' => '');
315
+ }
316
+
317
+ update_post_meta($popupId, 'sg_popup_events', $eventsInitialData);
318
+
319
+ // by user status (logged in/out)
320
+ if (!empty($options['sgpb-by-user-status'])) {
321
+ $operator = '==';
322
+ if (isset($options['sgpb-for-logged-in-user']) && $options['sgpb-for-logged-in-user'] === 'false') {
323
+ $operator = '!=';
324
+ }
325
+ $conditions['sgpb-conditions'][0][] = array(
326
+ 'param' => 'groups_user_role',
327
+ 'operator' => $operator,
328
+ 'value' => 'loggedIn'
329
+ );
330
+ }
331
+
332
+ // hide or show on mobile
333
+ if (isset($options['sgpb-hide-on-mobile']) && $options['sgpb-hide-on-mobile'] == 'on') {
334
+ $conditions['sgpb-conditions'][0][] = array(
335
+ 'param' => 'groups_devices',
336
+ 'operator' => '!=',
337
+ 'value' => array(
338
+ 'is_mobile'
339
+ )
340
+ );
341
+ }
342
+ if (isset($options['sgpb-only-on-mobile']) && $options['sgpb-only-on-mobile'] == 'on') {
343
+ $conditions['sgpb-conditions'][0][] = array(
344
+ 'param' => 'groups_devices',
345
+ 'operator' => '==',
346
+ 'value' => array(
347
+ 'is_mobile'
348
+ )
349
+ );
350
+ }
351
+
352
+ // detect by country
353
+ if (isset($options['sgpb-by-country']) && $options['sgpb-by-country'] == 'on') {
354
+ if (isset($options['sgpb-allow-countries'])) {
355
+ $options['sgpb-allow-countries'] = '!=';
356
+ if ($options['sgpb-allow-countries'] == 'allow') {
357
+ $options['sgpb-allow-countries'] = '==';
358
+ }
359
+ }
360
+ $conditions['sgpb-conditions'][0][] = array(
361
+ 'param' => 'groups_countries',
362
+ 'operator' => @$options['sgpb-allow-countries'],
363
+ 'value' => explode(',', @$options['sgpb-countries-iso'])
364
+ );
365
+ }
366
+
367
+ update_post_meta($popupId, 'sg_popup_target', $conditions);
368
+
369
+ // random popup
370
+ if (isset($options['sgpb-random-popup']) && $options['sgpb-random-popup'] == 'on') {
371
+ $randomPopupCategory = AdminHelper::getTaxonomyBySlug(SG_RANDOM_TAXONOMY_SLUG);
372
+ wp_set_object_terms($popupId, SG_RANDOM_TAXONOMY_SLUG, SG_POPUP_CATEGORY_TAXONOMY, true);
373
+ }
374
+
375
+ $this->saveProTarget($options);
376
+
377
+ // MailChimp
378
+ $mailchimpApiKey = get_option("SG_MAILCHIMP_API_KEY");
379
+
380
+ if ($mailchimpApiKey) {
381
+ update_option('SGPB_MAILCHIMP_API_KEY', $mailchimpApiKey);
382
+ }
383
+
384
+ // AWeber
385
+ $aweberAccessToken = get_option('sgAccessToken');
386
+ if ($aweberAccessToken) {
387
+ $requestTokenSecret = get_option('requestTokenSecret');
388
+ $accessTokenSecret = get_option('sgAccessTokenSecret');
389
+
390
+ update_option('sgpbRequestTokenSecret', $requestTokenSecret);
391
+ update_option('sgpbAccessTokenSecret', $accessTokenSecret);
392
+ update_option('sgpbAccessToken', $aweberAccessToken);
393
+ }
394
+
395
+ return $options;
396
+ }
397
+
398
+ public function saveProTarget($options)
399
+ {
400
+ if (empty($options)) {
401
+ return;
402
+ }
403
+ $popupId = (int)$options['sgpb-post-id'];
404
+ // It's got already saved targets for do not override already saved data
405
+ $popupSavedTarget = get_post_meta($popupId, 'sg_popup_target');
406
+ $target = array();
407
+ $target['sgpb-target'] = array();
408
+ $target['sgpb-conditions'] = array();
409
+
410
+ if (!empty($popupSavedTarget[0]['sgpb-conditions'])) {
411
+ $target['sgpb-conditions'] = $popupSavedTarget[0]['sgpb-conditions'];
412
+ }
413
+ $isSavedToHome = false;
414
+
415
+ if (!empty($options['allPagesStatus'])) {
416
+
417
+ if ($options['allPages'] == 'selected') {
418
+ $savedPages = (array)@$options['allSelectedPages'];
419
+ $savedPagesValues = array_values($savedPages);
420
+
421
+ // -1 mean saved for home page
422
+ if (in_array('-1', $savedPagesValues)) {
423
+ $isSavedToHome = true;
424
+ }
425
+ $args = array(
426
+ 'post__in' => $savedPagesValues,
427
+ 'posts_per_page' => 10,
428
+ 'post_type' => 'page'
429
+ );
430
+
431
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
432
+ if (!empty($searchResults)) {
433
+ $target['sgpb-target'][0][] = array('param' => 'page_selected', 'operator' => '==', 'value' => $searchResults);
434
+ }
435
+ }
436
+ else {
437
+ $target['sgpb-target'][0][] = array('param' => 'page_all', 'operator' => '==');
438
+ }
439
+ }
440
+
441
+ if (!empty($options['allPostsStatus'])) {
442
+ $allPosts = $options['allPosts'];
443
+ if ($allPosts == 'selected') {
444
+ $savedPosts = (array)$options['allSelectedPosts'];
445
+ $savedPostsValues = array_values($savedPosts);
446
+ // -1 mean saved for home page
447
+ if (in_array('-1', $savedPostsValues)) {
448
+ $isSavedToHome = true;
449
+ }
450
+ $args = array(
451
+ 'post__in' => $savedPostsValues,
452
+ 'posts_per_page' => 10,
453
+ 'post_type' => 'post'
454
+ );
455
+
456
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
457
+ if (!empty($searchResults)) {
458
+ $target['sgpb-target'][0][] = array('param' => 'post_selected', 'operator' => '==', 'value' => $searchResults);
459
+ }
460
+ }
461
+ else if ($allPosts == 'all') {
462
+ $target['sgpb-target'][0][] = array('param' => 'post_all', 'operator' => '==');
463
+ }
464
+ else {
465
+ $selectedPostCategories = array_values($options['posts-all-categories']);
466
+ $target['sgpb-target'][0][] = array('param' => 'post_category', 'operator' => '==', 'value' => $selectedPostCategories);
467
+ }
468
+ }
469
+
470
+ if ($isSavedToHome) {
471
+ $target['sgpb-target'][0][] = array('param' => 'page_type', 'operator' => '==', 'value' => array('is_home_page', 'is_home'));
472
+ }
473
+
474
+ if (!empty($options['allCustomPostsStatus'])) {
475
+ $customPostTypes = $options['all-custom-posts'];
476
+ if (!empty($customPostTypes)) {
477
+ $selectedCustomPosts = $options['allSelectedCustomPosts'];
478
+ if ($options['showAllCustomPosts'] == 'selected') {
479
+ foreach ($customPostTypes as $customPostType) {
480
+ $args = array(
481
+ 'post__in' => array_values($selectedCustomPosts),
482
+ 'posts_per_page' => 10,
483
+ 'post_type' => $customPostType
484
+ );
485
+
486
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
487
+ if (!empty($searchResults)) {
488
+ $target['sgpb-target'][0][] = array('param' => $customPostType.'_selected', 'operator' => '==', 'value' => $searchResults);
489
+ }
490
+ }
491
+ }
492
+
493
+ else {
494
+ $target['sgpb-target'][0][] = array('param' => 'post_type', 'operator' => '==', 'value' => array_values($customPostTypes));
495
+
496
+ }
497
+ }
498
+ }
499
+
500
+ update_post_meta($popupId, 'sg_popup_target', $target);
501
+ }
502
+
503
+ /**
504
+ * Get Addons options
505
+ *
506
+ * @param obj $popup
507
+ *
508
+ * @return bool|array
509
+ */
510
+ private function getAddonsEventFromPopup($popup)
511
+ {
512
+ if (empty($popup)) {
513
+ return false;
514
+ }
515
+ $popupId = $popup->getId();
516
+ global $wpdb;
517
+
518
+ $addonsOptionSqlString = 'SELECT options FROM '.$wpdb->prefix.'sg_popup_addons_connection WHERE popupId = %d and extensionType = "option"';
519
+ $addonsSql = $wpdb->prepare($addonsOptionSqlString, $popupId);
520
+ $results = $wpdb->get_results($addonsSql, ARRAY_A);
521
+
522
+ if (empty($results)) {
523
+ return false;
524
+ }
525
+
526
+ $options = array();
527
+
528
+ // it's collect all events saved values ex Exit Intent and AdBlock
529
+ foreach ($results as $result) {
530
+ $currentOptions = json_decode($result['options'], true);
531
+
532
+ if (empty($currentOptions)) {
533
+ continue;
534
+ }
535
+ $options = array_merge($options, $currentOptions);
536
+ }
537
+
538
+ return $options;
539
+ }
540
+
541
+ /**
542
+ * Filter and change some related values for new version
543
+ *
544
+ * @param array $options
545
+ *
546
+ * @return array $options
547
+ */
548
+ private function filterOptions($options)
549
+ {
550
+ if (@$options['effect'] != 'No effect') {
551
+ $options['sgpb-open-animation'] = 'on';
552
+ }
553
+
554
+ if (isset($options['isActiveStatus']) && $options['isActiveStatus'] == 'off') {
555
+ $options['isActiveStatus'] = '';
556
+ }
557
+
558
+ if (empty($options['sgTheme3BorderColor'])) {
559
+ $options['sgTheme3BorderColor'] = '#000000';
560
+ }
561
+
562
+ if (@$options['popupContentBackgroundRepeat'] != 'no-repeat' && $options['popupContentBackgroundSize'] == 'auto') {
563
+ $options['popupContentBackgroundSize'] = 'repeat';
564
+ }
565
+ $themeNumber = 1;
566
+
567
+ if (isset($options['theme'])) {
568
+ $themeNumber = preg_replace('/[^0-9]/', '', $options['theme']);
569
+ }
570
+
571
+ if (isset($options['aweber-success-behavior']) && $options['aweber-success-behavior'] == 'redirectToUrl') {
572
+ $options['aweber-success-behavior'] = 'redirectToURL';
573
+ }
574
+
575
+ // pro options
576
+ if (isset($options['disablePopupOverlay'])) {
577
+ $options['sgpb-enable-popup-overlay'] = '';
578
+ }
579
+ // contact form new options
580
+ if (isset($options['contact-success-behavior']) && $options['contact-success-behavior'] == 'redirectToUrl') {
581
+ $options['contact-success-behavior'] = 'redirectToURL';
582
+ }
583
+ if (isset($options['contact-text-input-bgcolor'])) {
584
+ $options['sgpb-contact-message-bg-color'] = $options['contact-text-input-bgcolor'];
585
+ }
586
+ if (isset($options['contact-text-bordercolor'])) {
587
+ $options['sgpb-contact-message-border-color'] = $options['contact-text-bordercolor'];
588
+ }
589
+ if (isset($options['contact-inputs-color'])) {
590
+ $options['sgpb-contact-message-text-color'] = $options['contact-inputs-color'];
591
+ }
592
+ if (isset($options['contact-placeholder-color'])) {
593
+ $options['sgpb-contact-message-placeholder-color'] = $options['contact-placeholder-color'];
594
+ }
595
+ if (isset($options['contact-inputs-border-width'])) {
596
+ $options['sgpb-contact-message-border-width'] = $options['contact-inputs-border-width'];
597
+ }
598
+
599
+ if (isset($options['contact-success-popups-list'])) {
600
+ $options['contact-success-popups-list'] = sgpGetCorrectPopupId($options['contact-success-popups-list']);
601
+ }
602
+
603
+ if (isset($options['popup-content-padding'])) {
604
+ // add theme default padding to content padding
605
+ switch ($themeNumber) {
606
+ case 1:
607
+ $options['popup-content-padding'] += 7;
608
+ break;
609
+ case 4:
610
+ case 6:
611
+ $options['popup-content-padding'] += 12;
612
+ break;
613
+ case 2:
614
+ case 3:
615
+ $options['popup-content-padding'] += 0;
616
+ break;
617
+ case 5:
618
+ $options['popup-content-padding'] += 5;
619
+ break;
620
+ }
621
+ }
622
+
623
+ switch ($themeNumber) {
624
+ case 1:
625
+ $buttonImageWidth = 21;
626
+ $buttonImageHeight = 21;
627
+ break;
628
+ case 2:
629
+ $buttonImageWidth = 20;
630
+ $buttonImageHeight = 20;
631
+ break;
632
+ case 3:
633
+ $buttonImageWidth = 38;
634
+ $buttonImageHeight = 19;
635
+ break;
636
+ case 5:
637
+ $buttonImageWidth = 17;
638
+ $buttonImageHeight = 17;
639
+ break;
640
+ case 6:
641
+ $buttonImageWidth = 30;
642
+ $buttonImageHeight = 30;
643
+ break;
644
+ default:
645
+ $buttonImageWidth = 0;
646
+ $buttonImageHeight = 0;
647
+ }
648
+
649
+ // social popup add to default value
650
+ if (empty($options['sgMailLable'])) {
651
+ $options['sgMailLable'] = 'E-mail';
652
+ }
653
+ if (empty($options['fbShareLabel'])) {
654
+ $options['fbShareLabel'] = 'Share';
655
+ }
656
+ if (empty($options['lindkinLabel'])) {
657
+ $options['lindkinLabel'] = 'Share';
658
+ }
659
+ if (empty($options['googLelabel'])) {
660
+ $options['googLelabel'] = '+1';
661
+ }
662
+ if (empty($options['twitterLabel'])) {
663
+ $options['twitterLabel'] = 'Tweet';
664
+ }
665
+ if (empty($options['pinterestLabel'])) {
666
+ $options['pinterestLabel'] = 'Pin it';
667
+ }
668
+
669
+ if (isset($options['subs-success-behavior']) && $options['subs-success-behavior'] == 'redirectToUrl') {
670
+ $options['subs-success-behavior'] = 'redirectToURL';
671
+ }
672
+
673
+ $options['sgpb-subs-form-bg-color'] = '#FFFFFF';
674
+ $options['sgpb-button-image-width'] = $buttonImageWidth;
675
+ $options['sgpb-button-image-height'] = $buttonImageHeight;
676
+
677
+ // pro options customizations
678
+ if (SGPB_POPUP_PKG > SGPB_POPUP_PKG_FREE) {
679
+ if (empty($options['sgpb-restriction-yes-btn-radius-type'])) {
680
+ $options['sgpb-restriction-yes-btn-radius-type'] = '%';
681
+ }
682
+
683
+ if (empty($options['sgpb-restriction-no-btn-radius-type'])) {
684
+ $options['sgpb-restriction-no-btn-radius-type'] = '%';
685
+ }
686
+
687
+ if (empty($options['sgpb-restriction-yes-btn-border-color'])) {
688
+ // border color should be like background color
689
+ $options['sgpb-restriction-yes-btn-border-color'] = $options['yesButtonBackgroundColor'];
690
+ }
691
+ if (empty($options['sgpb-restriction-no-btn-border-color'])) {
692
+ // border color should be like background color
693
+ $options['sgpb-restriction-no-btn-border-color'] = $options['noButtonBackgroundColor'];
694
+ }
695
+ }
696
+
697
+ return $options;
698
+ }
699
+
700
+ public function changeOldValues($optionName, $optionValue)
701
+ {
702
+ if ($optionName == 'theme') {
703
+ $themeNumber = preg_replace('/[^0-9]/', '', $optionValue);
704
+ $optionValue = 'sgpb-theme-'.$themeNumber;
705
+ }
706
+
707
+ return $optionValue;
708
+ }
709
+
710
+ private function popupObjectFromArray($arr)
711
+ {
712
+ global $wpdb;
713
+
714
+ $options = json_decode($arr['options'], true);
715
+ $type = $arr['type'];
716
+
717
+ if (empty($type)) {
718
+ return false;
719
+ }
720
+
721
+ $this->setId($arr['id']);
722
+ $this->setType($type);
723
+ $this->setTitle($arr['title']);
724
+ $this->setContent('');
725
+
726
+ switch ($type) {
727
+ case 'image':
728
+ $query = $wpdb->prepare('SELECT `url` FROM '.$wpdb->prefix.'sg_image_popup WHERE id = %d', $arr['id']);
729
+ $result = $wpdb->get_row($query, ARRAY_A);
730
+
731
+ if (!empty($result['url'])) {
732
+ $options['image-url'] = $result['url'];
733
+ }
734
+ break;
735
+ case 'html':
736
+ $query = $wpdb->prepare('SELECT `content` FROM '.$wpdb->prefix.'sg_html_popup WHERE id = %d', $arr['id']);
737
+ $result = $wpdb->get_row($query, ARRAY_A);
738
+
739
+ if (!empty($result['content'])) {
740
+ $this->setContent($result['content']);
741
+ }
742
+ break;
743
+ case 'fblike':
744
+ $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_fblike_popup WHERE id = %d', $arr['id']);
745
+ $result = $wpdb->get_row($query, ARRAY_A);
746
+
747
+ if (!empty($result['content'])) {
748
+ $this->setContent($result['content']);
749
+ }
750
+ $customOptions = $result['options'];
751
+ $customOptions = json_decode($customOptions, true);
752
+
753
+ if (!empty($options)) {
754
+ $this->setCustomOptions($customOptions);
755
+ }
756
+ break;
757
+ case 'shortcode':
758
+ $query = $wpdb->prepare('SELECT `url` FROM '.$wpdb->prefix.'sg_shortCode_popup WHERE id = %d', $arr['id']);
759
+ $result = $wpdb->get_row($query, ARRAY_A);
760
+
761
+ if (!empty($result['url'])) {
762
+ $this->setContent($result['url']);
763
+ }
764
+ break;
765
+ case 'iframe':
766
+ $query = $wpdb->prepare('SELECT `url` FROM '.$wpdb->prefix.'sg_iframe_popup WHERE id = %d', $arr['id']);
767
+ $result = $wpdb->get_row($query, ARRAY_A);
768
+ if (!empty($result['url'])) {
769
+ $options['iframe-url'] = $result['url'];
770
+ }
771
+ break;
772
+ case 'video':
773
+ $query = $wpdb->prepare('SELECT `url`, `options` FROM '.$wpdb->prefix.'sg_video_popup WHERE id = %d', $arr['id']);
774
+ $result = $wpdb->get_row($query, ARRAY_A);
775
+ if (!empty($result['url'])) {
776
+ $options['video-url'] = $result['url'];
777
+ }
778
+
779
+ $customOptions = $result['options'];
780
+ $customOptions = json_decode($customOptions, true);
781
+
782
+ if (!empty($customOptions)) {
783
+ $this->setCustomOptions($customOptions);
784
+ }
785
+ break;
786
+ case 'ageRestriction':
787
+ $query = $wpdb->prepare('SELECT `content`, `yesButton` as `yesButtonLabel`, `noButton` as `noButtonLabel`, `url` as `restrictionUrl` FROM '.$wpdb->prefix.'sg_age_restriction_popup WHERE id = %d', $arr['id']);
788
+ $result = $wpdb->get_row($query, ARRAY_A);
789
+ if (!empty($result['content'])) {
790
+ $this->setContent($result['content']);
791
+ }
792
+ unset($result['content']);
793
+ if (!empty($result)) {
794
+ $this->setCustomOptions($result);
795
+ }
796
+ break;
797
+ case 'social':
798
+ $query = $wpdb->prepare('SELECT `socialContent`, `buttons`, `socialOptions` FROM '.$wpdb->prefix.'sg_social_popup WHERE id = %d', $arr['id']);
799
+ $result = $wpdb->get_row($query, ARRAY_A);
800
+
801
+ if (!empty($result['socialContent'])) {
802
+ $this->setContent($result['socialContent']);
803
+ }
804
+
805
+ $buttons = json_decode($result['buttons'], true);
806
+ $socialOptions = json_decode($result['socialOptions'], true);
807
+
808
+ $socialAllOptions = array_merge($buttons, $socialOptions);
809
+
810
+ $this->setCustomOptions($socialAllOptions);
811
+ break;
812
+ case 'subscription':
813
+ $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_subscription_popup WHERE id = %d', $arr['id']);
814
+ $result = $wpdb->get_row($query, ARRAY_A);
815
+
816
+ if (!empty($result['content'])) {
817
+ $this->setContent($result['content']);
818
+ }
819
+
820
+ $subsOptions = $result['options'];
821
+ $subsOptions = json_decode($subsOptions, true);
822
+
823
+ if (!empty($subsOptions)) {
824
+ $this->setCustomOptions($subsOptions);
825
+ }
826
+ break;
827
+ case 'countdown':
828
+ $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_countdown_popup WHERE id = %d', $arr['id']);
829
+ $result = $wpdb->get_row($query, ARRAY_A);
830
+
831
+ if (!empty($result['content'])) {
832
+ $this->setContent($result['content']);
833
+ }
834
+ $customOptions = $result['options'];
835
+ $customOptions = json_decode($customOptions, true);
836
+
837
+ if (!empty($options)) {
838
+ $this->setCustomOptions($customOptions);
839
+ }
840
+ break;
841
+ case 'contactForm':
842
+ $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_contact_form_popup WHERE id = %d', $arr['id']);
843
+ $result = $wpdb->get_row($query, ARRAY_A);
844
+
845
+ if (!empty($result['content'])) {
846
+ $this->setContent($result['content']);
847
+ }
848
+ $customOptions = $result['options'];
849
+ $customOptions = json_decode($customOptions, true);
850
+
851
+ if (!empty($options)) {
852
+ $this->setCustomOptions($customOptions);
853
+ }
854
+ break;
855
+ case 'mailchimp':
856
+ $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_popup_mailchimp WHERE id = %d', $arr['id']);
857
+ $result = $wpdb->get_row($query, ARRAY_A);
858
+
859
+ if (!empty($result['content'])) {
860
+ $this->setContent($result['content']);
861
+ }
862
+
863
+ $customOptions = $result['options'];
864
+ $customOptions = json_decode($customOptions, true);
865
+
866
+ if (!empty($options)) {
867
+ $this->setCustomOptions($customOptions);
868
+ }
869
+ break;
870
+ case 'aweber':
871
+ $query = $wpdb->prepare('SELECT `content`, `options` FROM '.$wpdb->prefix.'sg_popup_aweber WHERE id = %d', $arr['id']);
872
+ $result = $wpdb->get_row($query, ARRAY_A);
873
+
874
+ if (!empty($result['content'])) {
875
+ $this->setContent($result['content']);
876
+ }
877
+
878
+ $customOptions = $result['options'];
879
+ $customOptions = json_decode($customOptions, true);
880
+
881
+ if (!empty($options)) {
882
+ $this->setCustomOptions($customOptions);
883
+ }
884
+ break;
885
+ }
886
+
887
+ $this->setOptions($options);
888
+
889
+ return $this;
890
+ }
891
+
892
+ public function getNamesMapping()
893
+ {
894
+ $names = array(
895
+ 'type' => 'sgpb-type',
896
+ 'delay' => 'sgpb-popup-delay',
897
+ 'isActiveStatus' => 'sgpb-is-active',
898
+ 'image-url' => 'sgpb-image-url',
899
+ 'theme' => 'sgpb-popup-themes',
900
+ 'effect' => 'sgpb-open-animation-effect',
901
+ 'duration' => 'sgpb-open-animation-speed',
902
+ 'popupOpenSound' => 'sgpb-open-sound',
903
+ 'popupOpenSoundFile' => 'sgpb-sound-url',
904
+ 'popup-dimension-mode' => 'sgpb-popup-dimension-mode',
905
+ 'popup-responsive-dimension-measure' => 'sgpb-responsive-dimension-measure',
906
+ 'width' => 'sgpb-width',
907
+ 'height' => 'sgpb-height',
908
+ 'maxWidth' => 'sgpb-max-width',
909
+ 'maxHeight' => 'sgpb-max-height',
910
+ 'escKey' => 'sgpb-esc-key',
911
+ 'closeButton' => 'sgpb-enable-close-button',
912
+ 'buttonDelayValue' => 'sgpb-close-button-delay',
913
+ 'scrolling' => 'sgpb-enable-content-scrolling',
914
+ 'disable-page-scrolling' => 'sgpb-disable-page-scrolling',
915
+ 'overlayClose' => 'sgpb-overlay-click',
916
+ 'contentClick' => 'sgpb-content-click',
917
+ 'content-click-behavior' => 'sgpb-content-click-behavior',
918
+ 'click-redirect-to-url' => 'sgpb-click-redirect-to-url',
919
+ 'redirect-to-new-tab' => 'sgpb-redirect-to-new-tab',
920
+ 'reopenAfterSubmission' => 'sgpb-reopen-after-form-submission',
921
+ 'repeatPopup' => 'sgpb-show-popup-same-user',
922
+ 'popup-appear-number-limit' => 'sgpb-show-popup-same-user-count',
923
+ 'onceExpiresTime' => 'sgpb-show-popup-same-user-expiry',
924
+ 'save-cookie-page-level' => 'sgpb-show-popup-same-user-page-level',
925
+ 'popupContentBgImage' => 'sgpb-show-background',
926
+ 'popupContentBackgroundSize' => 'sgpb-background-image-mode',
927
+ 'popupContentBgImageUrl' => 'sgpb-background-image',
928
+ 'sgOverlayColor' => 'sgpb-overlay-color',
929
+ 'sg-content-background-color' => 'sgpb-background-color',
930
+ 'popup-background-opacity' => 'sgpb-content-opacity',
931
+ 'opacity' => 'sgpb-overlay-opacity',
932
+ 'sgOverlayCustomClasss' => 'sgpb-overlay-custom-class',
933
+ 'sgContentCustomClasss' => 'sgpb-content-custom-class',
934
+ 'popup-z-index' => 'sgpb-popup-z-index',
935
+ 'popup-content-padding' => 'sgpb-content-padding',
936
+ 'popupFixed' => 'sgpb-popup-fixed',
937
+ 'fixedPostion' => 'sgpb-popup-fixed-position',
938
+ 'sgpb-open-animation' => 'sgpb-open-animation',
939
+ 'theme-close-text' => 'sgpb-button-text',
940
+ 'sgTheme3BorderRadius' => 'sgpb-border-radius',
941
+ 'sgTheme3BorderColor' => 'sgpb-border-color',
942
+ 'fblike-like-url' => 'sgpb-fblike-like-url',
943
+ 'fblike-layout' => 'sgpb-fblike-layout',
944
+ 'fblike-dont-show-share-button' => 'sgpb-fblike-dont-show-share-button',
945
+ 'sgpb-button-image-width' => 'sgpb-button-image-width',
946
+ 'sgpb-button-image-height' => 'sgpb-button-image-height'
947
+ );
948
+ // iframe pro popup type
949
+ $names['iframe-url'] = 'sgpb-iframe-url';
950
+
951
+ // video pro popup type
952
+ $names['video-url'] = 'sgpb-video-url';
953
+ $names['video-autoplay'] = 'sgpb-video-autoplay';
954
+
955
+ // age restriction
956
+ $names['yesButtonLabel'] = 'sgpb-restriction-yes-btn';
957
+ $names['noButtonLabel'] = 'sgpb-restriction-no-btn';
958
+ $names['restrictionUrl'] = 'sgpb-restriction-no-url';
959
+ $names['yesButtonBackgroundColor'] = 'sgpb-restriction-yes-btn-bg-color';
960
+ $names['yesButtonTextColor'] = 'sgpb-restriction-yes-btn-text-color';
961
+ $names['yesButtonRadius'] = 'sgpb-restriction-yes-btn-radius';
962
+ $names['sgRestrictionExpirationTime'] = 'sgpb-restriction-yes-expiration-time';
963
+ $names['restrictionCookeSavingLevel'] = 'sgpb-restriction-cookie-level';
964
+ $names['noButtonBackgroundColor'] = 'sgpb-restriction-no-btn-bg-color';
965
+ $names['noButtonTextColor'] = 'sgpb-restriction-no-btn-text-color';
966
+ $names['noButtonRadius'] = 'sgpb-restriction-no-btn-radius';
967
+
968
+ // age restriction new options
969
+ $names['sgpb-restriction-yes-btn-radius-type'] = 'sgpb-restriction-yes-btn-radius-type';
970
+ $names['sgpb-restriction-no-btn-radius-type'] = 'sgpb-restriction-no-btn-radius-type';
971
+ $names['sgpb-restriction-yes-btn-border-color'] = 'sgpb-restriction-yes-btn-border-color';
972
+ $names['sgpb-restriction-no-btn-border-color'] = 'sgpb-restriction-no-btn-border-color';
973
+
974
+ $proNames = array(
975
+ 'autoClosePopup' => 'sgpb-auto-close',
976
+ 'popupClosingTimer' => 'sgpb-auto-close-time',
977
+ 'disablePopupOverlay' => 'sgpb-enable-popup-overlay',
978
+ 'disablePopup' => 'sgpb-disable-popup-closing',
979
+ 'popup-schedule-status' => 'sgpb-schedule-status',
980
+ 'schedule-start-weeks' => 'sgpb-schedule-weeks',
981
+ 'schedule-start-time' => 'sgpb-schedule-start-time',
982
+ 'schedule-end-time' => 'sgpb-schedule-end-time',
983
+ 'popup-timer-status' => 'sgpb-popup-timer-status',
984
+ 'popup-start-timer' => 'sgpb-popup-start-timer',
985
+ 'popup-finish-timer' => 'sgpb-popup-end-timer',
986
+ 'inActivityStatus' => 'sgpb-inactivity-status',
987
+ 'inactivity-timout' => 'sgpb-inactivity-timer',
988
+ 'onScrolling' => 'sgpb-onscroll-status',
989
+ 'beforeScrolingPrsent' => 'sgpb-onscroll-percentage',
990
+ 'sg-user-status' => 'sgpb-by-user-status',
991
+ 'loggedin-user' => 'sgpb-for-logged-in-user',
992
+ 'forMobile' => 'sgpb-hide-on-mobile',
993
+ 'openMobile' => 'sgpb-only-on-mobile',
994
+ 'countryStatus' => 'sgpb-by-country',
995
+ 'allowCountries' => 'sgpb-allow-countries',
996
+ 'countryIso' => 'sgpb-countries-iso',
997
+ 'randomPopup' => 'sgpb-random-popup'
998
+ );
999
+ $names = array_merge($names, $proNames);
1000
+
1001
+ // pro options
1002
+ $names['allPagesStatus'] = 'allPagesStatus';
1003
+ $names['showAllPages'] = 'allPages';
1004
+ $names['allSelectedPages'] = 'allSelectedPages';
1005
+ $names['allPostsStatus'] = 'allPostsStatus';
1006
+ $names['showAllPosts'] = 'allPosts';
1007
+ $names['allSelectedPosts'] = 'allSelectedPosts';
1008
+ $names['posts-all-categories'] = 'posts-all-categories';
1009
+ $names['allCustomPostsStatus'] = 'allCustomPostsStatus';
1010
+ $names['all-custom-posts'] = 'all-custom-posts';
1011
+ $names['showAllCustomPosts'] = 'showAllCustomPosts';
1012
+ $names['allSelectedCustomPosts'] = 'allSelectedCustomPosts';
1013
+ // countdown pro popup type
1014
+ $names['countdownNumbersBgColor'] = 'sgpb-counter-background-color';
1015
+ $names['countdownNumbersTextColor'] = 'sgpb-counter-text-color';
1016
+ $names['sg-due-date'] = 'sgpb-countdown-due-date';
1017
+ $names['sg-countdown-type'] = 'sgpb-countdown-type';
1018
+ $names['sg-time-zone'] = 'sgpb-countdown-timezone';
1019
+ $names['counts-language'] = 'sgpb-countdown-language';
1020
+ $names['pushToBottom'] = 'sgpb-countdown-show-on-top';
1021
+ $names['countdown-autoclose'] = 'sgpb-countdown-close-timeout';
1022
+ // contact form pro popup type
1023
+ $names['show-form-to-top'] = 'sgpb-contact-show-form-to-top';
1024
+ $names['contact-name-status'] = 'sgpb-contact-field-name';
1025
+ $names['contact-name'] = 'sgpb-contact-name-placeholder';
1026
+ $names['contact-name-required'] = 'sgpb-contact-name-required';
1027
+ $names['contact-subject-status'] = 'sgpb-contact-field-subject';
1028
+ $names['contact-subject'] = 'sgpb-contact-subject-placeholder';
1029
+ $names['contact-subject-required'] = 'sgpb-contact-subject-required';
1030
+ $names['contact-email'] = 'sgpb-contact-email-placeholder';
1031
+ $names['contact-message'] = 'sgpb-contact-message-placeholder';
1032
+ $names['contact-fail-message'] = 'sgpb-contact-error-message';
1033
+ $names['contact-receive-email'] = 'sgpb-contact-to-email';
1034
+ $names['contact-validation-message'] = 'sgpb-contact-required-message';
1035
+ $names['contact-validate-email'] = 'sgpb-contact-invalid-email-message';
1036
+ $names['contact-inputs-width'] = 'sgpb-contact-inputs-width';
1037
+ $names['contact-inputs-height'] = 'sgpb-contact-inputs-height';
1038
+ $names['contact-inputs-border-width'] = 'sgpb-contact-inputs-border-width';
1039
+ $names['contact-text-input-bgcolor'] = 'sgpb-contact-inputs-bg-color';
1040
+ $names['contact-text-bordercolor'] = 'sgpb-contact-inputs-border-color';
1041
+ $names['contact-inputs-color'] = 'sgpb-contact-inputs-text-color';
1042
+ $names['contact-placeholder-color'] = 'sgpb-contact-inputs-placeholder-color';
1043
+ $names['contact-area-width'] = 'sgpb-contact-message-width';
1044
+ $names['contact-area-height'] = 'sgpb-contact-message-height';
1045
+ $names['sg-contact-resize'] = 'sgpb-contact-message-resize';
1046
+ $names['contact-btn-width'] = 'sgpb-contact-submit-width';
1047
+ $names['contact-btn-height'] = 'sgpb-contact-submit-height';
1048
+ $names['contact-btn-title'] = 'sgpb-contact-submit-title';
1049
+ $names['contact-btn-progress-title'] = 'sgpb-contact-submit-title-progress';
1050
+ $names['contact-button-bgcolor'] = 'sgpb-contact-submit-bg-color';
1051
+ $names['contact-button-color'] = 'sgpb-contact-submit-text-color';
1052
+ $names['dont-show-content-to-contacted-user'] = 'sgpb-contact-hide-for-contacted-users';
1053
+ $names['contact-success-behavior'] = 'sgpb-contact-success-behavior';
1054
+ $names['contact-success-message'] = 'sgpb-contact-success-message';
1055
+ $names['contact-success-redirect-url'] = 'sgpb-contact-success-redirect-URL';
1056
+ $names['contact-success-redirect-new-tab'] = 'sgpb-contact-success-redirect-new-tab';
1057
+ $names['contact-success-popups-list'] = 'sgpb-contact-success-popup';
1058
+ $names['contact-gdpr'] = 'sgpb-contact-gdpr-status';
1059
+ $names['contact-gdpr-label'] = 'sgpb-contact-gdpr-label';
1060
+ $names['contact-gdpr-text'] = 'sgpb-contact-gdpr-text';
1061
+ $names['sgpb-contact-message-bg-color'] = 'sgpb-contact-message-bg-color';
1062
+ $names['sgpb-contact-message-border-color'] = 'sgpb-contact-message-border-color';
1063
+ $names['sgpb-contact-message-text-color'] = 'sgpb-contact-message-text-color';
1064
+ $names['sgpb-contact-message-placeholder-color'] = 'sgpb-contact-message-placeholder-color';
1065
+ $names['sgpb-contact-message-border-width'] = 'sgpb-contact-message-border-width';
1066
+
1067
+ // Social
1068
+ $names['shareUrlType'] = 'sgpb-social-share-url-type';
1069
+ $names['sgShareUrl'] = 'sgpb-social-share-url';
1070
+ $names['sgSocialTheme'] = 'sgpb-social-share-theme';
1071
+ $names['sgSocialButtonsSize'] = 'sgpb-social-theme-size';
1072
+ $names['sgSocialLabel'] = 'sgpb-social-show-labels';
1073
+ $names['sgSocialShareCount'] = 'sgpb-social-share-count';
1074
+ $names['sgRoundButton'] = 'sgpb-social-round-buttons';
1075
+ $names['sgEmailStatus'] = 'sgpb-social-status-email';
1076
+ $names['sgMailLable'] = 'sgpb-social-label-email';
1077
+ $names['sgFbStatus'] = 'sgpb-social-status-facebook';
1078
+ $names['fbShareLabel'] = 'sgpb-social-label-facebook';
1079
+ $names['sgLinkedinStatus'] = 'sgpb-social-status-linkedin';
1080
+ $names['lindkinLabel'] = 'sgpb-social-label-linkedin';
1081
+ $names['sgGoogleStatus'] = 'sgpb-social-status-googleplus';
1082
+ $names['googLelabel'] = 'sgpb-social-label-googleplus';
1083
+ $names['sgTwitterStatus'] = 'sgpb-social-status-twitter';
1084
+ $names['twitterLabel'] = 'sgpb-social-label-twitter';
1085
+ $names['sgPinterestStatus'] = 'sgpb-social-status-pinterest';
1086
+ $names['pinterestLabel'] = 'sgpb-social-label-pinterest';
1087
+
1088
+ // Subscription
1089
+ $names['subscription-email'] = 'sgpb-subs-email-placeholder';
1090
+ $names['subs-gdpr'] = 'sgpb-subs-gdpr-status';
1091
+ $names['subs-gdpr-label'] = 'sgpb-subs-gdpr-label';
1092
+ $names['subs-gdpr-text'] = 'sgpb-subs-gdpr-text';
1093
+ $names['subs-first-name-status'] = 'sgpb-subs-first-name-status';
1094
+ $names['subs-first-name'] = 'sgpb-subs-first-placeholder';
1095
+ $names['subs-first-name-required'] = 'sgpb-subs-first-name-required';
1096
+ $names['subs-last-name-status'] = 'sgpb-subs-last-name-status';
1097
+ $names['subs-last-name'] = 'sgpb-subs-last-placeholder';
1098
+ $names['subs-last-name-required'] = 'sgpb-subs-last-name-required';
1099
+ $names['subs-validation-message'] = 'sgpb-subs-validation-message';
1100
+ $names['subs-text-width'] = 'sgpb-subs-text-width';
1101
+ $names['subs-text-height'] = 'sgpb-subs-text-height';
1102
+ $names['subs-text-border-width'] = 'sgpb-subs-text-border-width';
1103
+ $names['subs-text-input-bgColor'] = 'sgpb-subs-text-bg-color';
1104
+ $names['subs-text-borderColor'] = 'sgpb-subs-text-border-color';
1105
+ $names['subs-inputs-color'] = 'sgpb-subs-text-color';
1106
+ $names['subs-placeholder-color'] = 'sgpb-subs-text-placeholder-color';
1107
+ $names['subs-btn-width'] = 'sgpb-subs-btn-width';
1108
+ $names['subs-btn-height'] = 'sgpb-subs-btn-height';
1109
+ $names['subs-btn-title'] = 'sgpb-subs-btn-title';
1110
+ $names['subs-btn-progress-title'] = 'sgpb-subs-btn-progress-title';
1111
+ $names['subs-button-bgColor'] = 'sgpb-subs-btn-bg-color';
1112
+ $names['subs-button-color'] = 'sgpb-subs-btn-text-color';
1113
+ $names['subs-success-behavior'] = 'sgpb-subs-success-behavior';
1114
+ $names['subs-success-message'] = 'sgpb-subs-success-message';
1115
+ $names['subs-success-redirect-url'] = 'sgpb-subs-success-redirect-URL';
1116
+ $names['subs-success-redirect-new-tab'] = 'sgpb-subs-success-redirect-new-tab';
1117
+ $names['subs-success-popups-list'] = 'sgpb-subs-success-popup';
1118
+ // Subscription new option
1119
+ $names['sgpb-subs-form-bg-color'] = 'sgpb-subs-form-bg-color';
1120
+
1121
+ // Exit Intent extension names
1122
+ $names['option-exit-intent-enable'] = 'sgpb-option-exit-intent-enable';
1123
+ $names['option-exit-intent-type'] = 'sgpb-option-exit-intent-type';
1124
+ $names['option-exit-intent-expire-time'] = 'sgpb-exit-intent-expire-time';
1125
+ $names['option-exit-intent-cookie-level'] = 'sgpb-exit-intent-cookie-level';
1126
+ $names['option-exit-intent-soft-from-top'] = 'sgpb-exit-intent-soft-from-top';
1127
+
1128
+ // Adblock extension names
1129
+ $names['option-enable-ad-block'] = 'sgpb-option-enable-ad-block';
1130
+ // MailChimp extension names
1131
+ $names['mailchimp-list-id'] = 'sgpb-mailchimp-lists';
1132
+ $names['mailchimp-double-optin'] = 'sgpb-enable-double-optin';
1133
+ $names['mailchimp-only-required'] = 'sgpb-show-required-fields';
1134
+ $names['mailchimp-form-aligment'] = 'sgpb-mailchimp-form-align';
1135
+ $names['mailchimp-label-aligment'] = 'sgpb-mailchimp-label-alignment';
1136
+ $names['mailchimp-indicates-required-fields'] = 'sgpb-enable-asterisk-label';
1137
+ $names['mailchimp-asterisk-label'] = 'sgpb-mailchimp-asterisk-label';
1138
+ $names['mailchimp-required-error-message'] = 'sgpb-mailchimp-required-message';
1139
+ $names['mailchimp-email-validate-message'] = 'sgpb-mailchimp-email-message';
1140
+ $names['mailchimp-email-label'] = 'sgpb-mailchimp-email-label';
1141
+ $names['mailchimp-error-message'] = 'sgpb-mailchimp-error-message';
1142
+ $names['mailchimp-show-form-to-top'] = 'sgpb-mailchimp-show-form-to-top';
1143
+ $names['mailchimp-label-color'] = 'sgpb-mailchimp-label-color';
1144
+ $names['mailchimp-input-width'] = 'sgpb-mailchimp-input-width';
1145
+ $names['mailchimp-input-height'] = 'sgpb-mailchimp-input-height';
1146
+ $names['mailchimp-input-border-radius'] = 'sgpb-mailchimp-border-radius';
1147
+ $names['mailchimp-input-border-width'] = 'sgpb-mailchimp-border-width';
1148
+ $names['mailchimp-input-border-color'] = 'sgpb-mailchimp-border-color';
1149
+ $names['mailchimp-input-bg-color'] = 'sgpb-mailchimp-background-color';
1150
+ $names['sgpb-mailchimp-input-color'] = 'sgpb-mailchimp-input-color';
1151
+ $names['mailchimp-submit-title'] = 'sgpb-mailchimp-submit-title';
1152
+ $names['mailchimp-submit-width'] = 'sgpb-mailchimp-submit-width';
1153
+ $names['mailchimp-submit-height'] = 'sgpb-mailchimp-submit-height';
1154
+ $names['mailchimp-submit-border-width'] = 'sgpb-mailchimp-submit-border-width';
1155
+ $names['mailchimp-submit-border-radius'] = 'sgpb-mailchimp-submit-border-radius';
1156
+ $names['mailchimp-submit-border-color'] = 'sgpb-mailchimp-submit-border-color';
1157
+ $names['mailchimp-submit-button-bgcolor'] = 'sgpb-mailchimp-submit-background-color';
1158
+ $names['mailchimp-submit-color'] = 'sgpb-mailchimp-submit-color';
1159
+ $names['mailchimp-success-behavior'] = 'sgpb-mailchimp-success-behavior';
1160
+ $names['mailchimp-success-message'] = 'sgpb-mailchimp-success-message';
1161
+ $names['mailchimp-success-redirect-url'] = 'sgpb-mailchimp-success-redirect-URL';
1162
+ $names['mailchimp-success-redirect-new-tab'] = 'sgpb-mailchimp-success-redirect-new-tab';
1163
+ $names['mailchimp-success-popups-list'] = 'sgpb-mailchimp-success-popup';
1164
+ $names['mailchimp-close-popup-already-subscribed'] = 'sgpb-mailchimp-close-popup-already-subscribed';
1165
+ // AWeber extension
1166
+ $names['sg-aweber-list'] = 'sgpb-aweber-list';
1167
+ $names['sg-aweber-webform'] = 'sgpb-aweber-signup-form';
1168
+ $names['aweber-custom-invalid-email-message'] = 'sgpb-aweber-invalid-email';
1169
+ $names['aweber-invalid-email'] = 'sgpb-aweber-invalid-email-message';
1170
+ $names['aweber-already-subscribed-message'] = 'sgpb-aweber-custom-subscribed-message';
1171
+ $names['aweber-required-message'] = 'sgpb-aweber-required-message';
1172
+ $names['aweber-validate-email-message'] = 'sgpb-aweber-validate-email-message';
1173
+ $names['aweber-success-behavior'] = 'sgpb-aweber-success-behavior';
1174
+ $names['aweber-success-message'] = 'sgpb-aweber-success-message';
1175
+ $names['aweber-success-redirect-url'] = 'sgpb-aweber-success-redirect-URL';
1176
+ $names['aweber-success-redirect-new-tab'] = 'sgpb-aweber-success-redirect-new-tab';
1177
+ $names['aweber-success-popups-list'] = 'sgpb-aweber-success-popup';
1178
+
1179
+ return $names;
1180
+ }
1181
+
1182
+ public static function saveCustomInserted()
1183
+ {
1184
+ global $post;
1185
+ if (empty($post)) {
1186
+ return false;
1187
+ }
1188
+
1189
+ $postId = $post->ID;
1190
+ if (get_option('sgpbSaveOldData'.$postId)) {
1191
+ return false;
1192
+ }
1193
+
1194
+ update_option('sgpbSaveOldData'.$postId, 1);
1195
+
1196
+ add_filter('sgpbConvertedPopupId', 'sgpb\sgpGetCorrectPopupId', 10, 1);
1197
+ self::saveMetaboxPopup($postId);
1198
+ $content = get_post_field('post_content', $postId);
1199
+ SGPopup::deletePostCustomInsertedData($postId);
1200
+ SGPopup::deletePostCustomInsertedEvents($postId);
1201
+ // We detect all the popups that were inserted as a custom ones, in the content.
1202
+ SGPopup::savePopupsFromContentClasses($content, $post);
1203
+ }
1204
+
1205
+ public static function saveMetaboxPopup($postId)
1206
+ {
1207
+ $selectedPost = get_post_meta($postId, 'sg_promotional_popup', true);
1208
+
1209
+ if (empty($selectedPost)) {
1210
+ return false;
1211
+ }
1212
+ global $SGPB_DATA_CONFIG_ARRAY;
1213
+
1214
+ $postType = get_post_type($postId);
1215
+ $postTitle = get_the_title($postId);
1216
+ $popupId = sgpGetCorrectPopupId($selectedPost);
1217
+ $popupTargetParam = $postType.'_selected';
1218
+
1219
+ if (!get_post_meta($popupId, 'sg_popup_events')) {
1220
+ update_post_meta($popupId, 'sg_popup_events', array($SGPB_DATA_CONFIG_ARRAY['events']['initialData']));
1221
+ }
1222
+
1223
+ $savedTarget = get_post_meta($popupId, 'sg_popup_target');
1224
+ if (empty($savedTarget[0]['sgpb-target'][0])) {
1225
+ $savedTarget['sgpb-target'][] = array(array('param' => $popupTargetParam, 'operator' => '==', 'value' => array($postId => $postTitle)));
1226
+ $savedTarget['sgpb-conditions'][] = $SGPB_DATA_CONFIG_ARRAY['conditions']['initialData'];
1227
+
1228
+ update_post_meta($popupId, 'sg_popup_target', $savedTarget, true);
1229
+ return true;
1230
+ }
1231
+ $targets = $savedTarget[0]['sgpb-target'][0];
1232
+ $targetExists = false;
1233
+
1234
+ foreach ($targets as $key => $target) {
1235
+ if ($key == 0 && $target['param'] == 'not_rule') {
1236
+ $target['param'] = $popupTargetParam;
1237
+ $savedTarget[0]['sgpb-target'][0][$key]['param'] = $popupTargetParam;
1238
+ }
1239
+ if ($target['param'] == $popupTargetParam) {
1240
+ $targetExists = true;
1241
+ $targetValue = array();
1242
+ if (!empty($target['value'])) {
1243
+ $targetValue = $target['value'];
1244
+ }
1245
+
1246
+ $targetValue[$postId] = $postTitle;
1247
+ $savedTarget[0]['sgpb-target'][0][$key]['value'] = $targetValue;
1248
+ break;
1249
+ }
1250
+ }
1251
+
1252
+ if (!$targetExists) {
1253
+ $savedTargetsLength = count($savedTarget[0]['sgpb-target'][0]);
1254
+ $savedTarget[0]['sgpb-target'][0][$savedTargetsLength] = array('param' => $popupTargetParam, 'operator' => '==', 'value' => array($postId => $postTitle));
1255
+ }
1256
+
1257
+ delete_post_meta($postId, 'sg_promotional_popup');
1258
+ delete_post_meta($popupId, 'sg_popup_target');
1259
+ update_post_meta($popupId, 'sg_popup_target', $savedTarget[0], true);
1260
+
1261
+ return true;
1262
+ }
1263
+ }
1264
+
1265
+ function sgpGetCorrectPopupId($popupId)
1266
+ {
1267
+ $convertedIds = get_option('sgpbConvertedIds');
1268
+
1269
+ if (empty($convertedIds) || empty($convertedIds[$popupId])) {
1270
+ return $popupId;
1271
+ }
1272
+
1273
+ return $convertedIds[$popupId];
1274
+ }
com/classes/Feedback.php CHANGED
@@ -1,146 +1,146 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class SGPBFeedback
5
- {
6
- public function __construct()
7
- {
8
- add_action('current_screen', array($this, 'actionToCurrentScreen'));
9
- add_action('wp_ajax_sgpb_deactivate_feedback', array($this, 'sgpbDeactivateFeedback'));
10
- }
11
-
12
- public function actionToCurrentScreen() {
13
- if (!$this->isPluginsScreen()) {
14
- return;
15
- }
16
-
17
- add_filter('sgpbAdminJsFiles', array($this, 'adminJsFilter'), 1, 1);
18
- add_action('admin_footer', array($this, 'renderDeactivateFeedbackDialog'));
19
- }
20
-
21
- public function adminJsFilter($jsFiles)
22
- {
23
- $jsFiles[] = array(
24
- 'folderUrl' => SG_POPUP_JS_PATH,
25
- 'filename' => 'Banner.js'
26
- );
27
-
28
- return $jsFiles;
29
- }
30
-
31
- public function sgpbDeactivateFeedback()
32
- {
33
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
34
- if (!empty($_POST['formData'])) {
35
- parse_str($_POST['formData'],$submissionData);
36
- }
37
- $feedbackKey = $feedbackText = 'Skipped';
38
- if (!empty($submissionData['reasonKey'])) {
39
- $feedbackKey = $submissionData['reasonKey'];
40
- }
41
-
42
- if (!empty($submissionData["reason_{$feedbackKey}"])) {
43
- $feedbackText = $submissionData["reason_{$feedbackKey}"];
44
- }
45
- $headers = 'MIME-Version: 1.0'."\r\n";
46
- $headers .= 'From: feedbackpopupbuilder@gmail.com'."\r\n";
47
- $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
48
-
49
- $receiver = 'feedbackpopupbuilder@gmail.com';
50
- $title = 'Popup Builder Deactivation Feedback From Customer';
51
- $message .= 'Feedback key - '.$feedbackKey.'<br>'."\n";
52
- $message .= 'Feedback text - '.$feedbackText."\n";
53
-
54
- wp_mail($receiver, $title, $message, $headers);
55
-
56
- wp_die(1);
57
- }
58
-
59
- public function renderDeactivateFeedbackDialog() {
60
- $deactivateReasons = array(
61
- 'no_longer_needed' => array(
62
- 'title' => __('I no longer need the plugin', SG_POPUP_TEXT_DOMAIN),
63
- 'input_placeholder' => ''
64
- ),
65
- 'found_a_better_plugin' => array(
66
- 'title' => __('I found a better plugin', SG_POPUP_TEXT_DOMAIN),
67
- 'input_placeholder' => __( 'Please share which plugin', SG_POPUP_TEXT_DOMAIN)
68
- ),
69
- 'couldnt_get_the_plugin_to_work' => array(
70
- 'title' => __('I couldn\'t get the plugin to work', SG_POPUP_TEXT_DOMAIN),
71
- 'input_placeholder' => '',
72
- 'extra_help' => __('Having troubles? You can always count on us. Please try to contact us via <a href="https://popup-builder.com/">Live chat</a> or send a message to <a href="mailto:support@popup-builder.com">support@popup-builder.com</a>', SG_POPUP_TEXT_DOMAIN)
73
- ),
74
- 'temporary_deactivation' => array(
75
- 'title' => __('It\'s a temporary deactivation', SG_POPUP_TEXT_DOMAIN),
76
- 'input_placeholder' => ''
77
- ),
78
- 'other' => array(
79
- 'title' => __('Other', SG_POPUP_TEXT_DOMAIN),
80
- 'input_placeholder' => __('Please share the reason', SG_POPUP_TEXT_DOMAIN),
81
- )
82
- );
83
-
84
- ?>
85
- <div id="sgpb-feedback-popup">
86
- <div class="sgpb-feedback-popup-wrapper">
87
- <div class="sgpb-wrapper">
88
- <div class="row sgpb-feedback-popup-header sgpb-position-relative">
89
- <div class="col-sm-3 sgpb-add-subscriber-header-column">
90
- <h4>
91
- <?php _e('Quick Feedback', SG_POPUP_TEXT_DOMAIN)?>
92
- </h4>
93
- </div>
94
- <div class="col-sm-1 sgpb-add-subscriber-header-spinner-column">
95
- <img src="<?php echo SG_POPUP_IMG_URL.'ajaxSpinner.gif'; ?>" alt="gif" class="sgpb-subscribers-add-spinner js-sg-spinner js-sgpb-add-spinner sg-hide-element js-sg-import-gif" width="20px">
96
- </div>
97
- <img src="<?php echo SG_POPUP_IMG_URL.'subscribers_close.png'; ?>" alt="gif" class="sgpb-add-subscriber-popup-close-btn sgpb-subscriber-data-popup-close-btn-js" width="20px">
98
- </div>
99
- <div class="row">
100
- <div class="col-md-12">
101
- <h4 class="sgpb-feedback-descritpion">
102
- <?php _e('If you have a moment, please share why you are deactivating <b>Popup Builder</b>', SG_POPUP_TEXT_DOMAIN)?>:
103
- </h4>
104
- <p class="sgpb-feedback-error-message sg-hide-element"><?php _e('Please, select an option.', SG_POPUP_TEXT_DOMAIN)?></p>
105
- </div>
106
- </div>
107
- <div class="row">
108
- <div class="col-md-12">
109
- <form id="sgpb-deactivate-feedback-dialog-form" method="post">
110
- <?php foreach ($deactivateReasons as $reasonKey => $reason) : ?>
111
- <div class="row sgpb-feedback-each-reason-row">
112
- <div class="col-md-1">
113
- <input id="sgpb-deactivate-feedback-<?php echo esc_attr($reasonKey); ?>" class="sgpb-deactivate-feedback-dialog-input" type="radio" name="reasonKey" value="<?php echo esc_attr($reasonKey); ?>" />
114
- </div>
115
- <div class="col-md-11">
116
- <label for="sgpb-deactivate-feedback-<?php echo esc_attr($reasonKey); ?>" class="sgpb-deactivate-feedback-dialog-label"><?php echo esc_html($reason['title']); ?></label>
117
- <?php if (!empty($reason['input_placeholder'])) : ?>
118
- <input class="sgpb-feedback-text sgpb-feedback-text-input" style="display: none;" type="text" name="reason_<?php echo esc_attr( $reasonKey ); ?>" placeholder="<?php echo esc_attr($reason['input_placeholder']); ?>" />
119
- <?php endif; ?>
120
- <?php if (!empty($reason['extra_help'])) : ?>
121
- <p class="sgpb-feedback-text-input" style="display: none;"><?php echo $reason['extra_help']; ?></p>
122
- <?php endif; ?>
123
- </div>
124
- </div>
125
- <?php endforeach; ?>
126
- <div class="row sgpb-feedback-btns-wrapper">
127
- <div class="col-md-6">
128
- <input type="button" class="btn btn-sm btn-success sgpb-feedback-submit" name="sgpb-feedback-submit" value="<?php _e('Submit & Deactivate', SG_POPUP_TEXT_DOMAIN); ?>">
129
- </div>
130
- <div class="col-md-6">
131
- <input type="button" class="btn btn-sm sgpb-feedback-submit-skip" name="sgpb-feedback-submit-skip" value="<?php _e('Skip & Deactivate', SG_POPUP_TEXT_DOMAIN); ?>">
132
- </div>
133
- </div>
134
- </form>
135
- </div>
136
- </div>
137
- </div>
138
- </div>
139
- </div>
140
- <?php
141
- }
142
-
143
- private function isPluginsScreen() {
144
- return in_array(get_current_screen()->id, array('plugins', 'plugins-network'));
145
- }
146
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class SGPBFeedback
5
+ {
6
+ public function __construct()
7
+ {
8
+ add_action('current_screen', array($this, 'actionToCurrentScreen'));
9
+ add_action('wp_ajax_sgpb_deactivate_feedback', array($this, 'sgpbDeactivateFeedback'));
10
+ }
11
+
12
+ public function actionToCurrentScreen() {
13
+ if (!$this->isPluginsScreen()) {
14
+ return;
15
+ }
16
+
17
+ add_filter('sgpbAdminJsFiles', array($this, 'adminJsFilter'), 1, 1);
18
+ add_action('admin_footer', array($this, 'renderDeactivateFeedbackDialog'));
19
+ }
20
+
21
+ public function adminJsFilter($jsFiles)
22
+ {
23
+ $jsFiles[] = array(
24
+ 'folderUrl' => SG_POPUP_JS_PATH,
25
+ 'filename' => 'Banner.js'
26
+ );
27
+
28
+ return $jsFiles;
29
+ }
30
+
31
+ public function sgpbDeactivateFeedback()
32
+ {
33
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
34
+ if (!empty($_POST['formData'])) {
35
+ parse_str($_POST['formData'],$submissionData);
36
+ }
37
+ $feedbackKey = $feedbackText = 'Skipped';
38
+ if (!empty($submissionData['reasonKey'])) {
39
+ $feedbackKey = $submissionData['reasonKey'];
40
+ }
41
+
42
+ if (!empty($submissionData["reason_{$feedbackKey}"])) {
43
+ $feedbackText = $submissionData["reason_{$feedbackKey}"];
44
+ }
45
+ $headers = 'MIME-Version: 1.0'."\r\n";
46
+ $headers .= 'From: feedbackpopupbuilder@gmail.com'."\r\n";
47
+ $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
48
+
49
+ $receiver = 'feedbackpopupbuilder@gmail.com';
50
+ $title = 'Popup Builder Deactivation Feedback From Customer';
51
+ $message .= 'Feedback key - '.$feedbackKey.'<br>'."\n";
52
+ $message .= 'Feedback text - '.$feedbackText."\n";
53
+
54
+ wp_mail($receiver, $title, $message, $headers);
55
+
56
+ wp_die(1);
57
+ }
58
+
59
+ public function renderDeactivateFeedbackDialog() {
60
+ $deactivateReasons = array(
61
+ 'no_longer_needed' => array(
62
+ 'title' => __('I no longer need the plugin', SG_POPUP_TEXT_DOMAIN),
63
+ 'input_placeholder' => ''
64
+ ),
65
+ 'found_a_better_plugin' => array(
66
+ 'title' => __('I found a better plugin', SG_POPUP_TEXT_DOMAIN),
67
+ 'input_placeholder' => __( 'Please share which plugin', SG_POPUP_TEXT_DOMAIN)
68
+ ),
69
+ 'couldnt_get_the_plugin_to_work' => array(
70
+ 'title' => __('I couldn\'t get the plugin to work', SG_POPUP_TEXT_DOMAIN),
71
+ 'input_placeholder' => '',
72
+ 'extra_help' => __('Having troubles? You can always count on us. Please try to contact us via <a href="https://popup-builder.com/">Live chat</a> or send a message to <a href="mailto:support@popup-builder.com">support@popup-builder.com</a>', SG_POPUP_TEXT_DOMAIN)
73
+ ),
74
+ 'temporary_deactivation' => array(
75
+ 'title' => __('It\'s a temporary deactivation', SG_POPUP_TEXT_DOMAIN),
76
+ 'input_placeholder' => ''
77
+ ),
78
+ 'other' => array(
79
+ 'title' => __('Other', SG_POPUP_TEXT_DOMAIN),
80
+ 'input_placeholder' => __('Please share the reason', SG_POPUP_TEXT_DOMAIN),
81
+ )
82
+ );
83
+
84
+ ?>
85
+ <div id="sgpb-feedback-popup">
86
+ <div class="sgpb-feedback-popup-wrapper">
87
+ <div class="sgpb-wrapper">
88
+ <div class="row sgpb-feedback-popup-header sgpb-position-relative">
89
+ <div class="col-sm-3 sgpb-add-subscriber-header-column">
90
+ <h4>
91
+ <?php _e('Quick Feedback', SG_POPUP_TEXT_DOMAIN)?>
92
+ </h4>
93
+ </div>
94
+ <div class="col-sm-1 sgpb-add-subscriber-header-spinner-column">
95
+ <img src="<?php echo SG_POPUP_IMG_URL.'ajaxSpinner.gif'; ?>" alt="gif" class="sgpb-subscribers-add-spinner js-sg-spinner js-sgpb-add-spinner sg-hide-element js-sg-import-gif" width="20px">
96
+ </div>
97
+ <img src="<?php echo SG_POPUP_IMG_URL.'subscribers_close.png'; ?>" alt="gif" class="sgpb-add-subscriber-popup-close-btn sgpb-subscriber-data-popup-close-btn-js" width="20px">
98
+ </div>
99
+ <div class="row">
100
+ <div class="col-md-12">
101
+ <h4 class="sgpb-feedback-descritpion">
102
+ <?php _e('If you have a moment, please share why you are deactivating <b>Popup Builder</b>', SG_POPUP_TEXT_DOMAIN)?>:
103
+ </h4>
104
+ <p class="sgpb-feedback-error-message sg-hide-element"><?php _e('Please, select an option.', SG_POPUP_TEXT_DOMAIN)?></p>
105
+ </div>
106
+ </div>
107
+ <div class="row">
108
+ <div class="col-md-12">
109
+ <form id="sgpb-deactivate-feedback-dialog-form" method="post">
110
+ <?php foreach ($deactivateReasons as $reasonKey => $reason) : ?>
111
+ <div class="row sgpb-feedback-each-reason-row">
112
+ <div class="col-md-1">
113
+ <input id="sgpb-deactivate-feedback-<?php echo esc_attr($reasonKey); ?>" class="sgpb-deactivate-feedback-dialog-input" type="radio" name="reasonKey" value="<?php echo esc_attr($reasonKey); ?>" />
114
+ </div>
115
+ <div class="col-md-11">
116
+ <label for="sgpb-deactivate-feedback-<?php echo esc_attr($reasonKey); ?>" class="sgpb-deactivate-feedback-dialog-label"><?php echo esc_html($reason['title']); ?></label>
117
+ <?php if (!empty($reason['input_placeholder'])) : ?>
118
+ <input class="sgpb-feedback-text sgpb-feedback-text-input" style="display: none;" type="text" name="reason_<?php echo esc_attr( $reasonKey ); ?>" placeholder="<?php echo esc_attr($reason['input_placeholder']); ?>" />
119
+ <?php endif; ?>
120
+ <?php if (!empty($reason['extra_help'])) : ?>
121
+ <p class="sgpb-feedback-text-input" style="display: none;"><?php echo $reason['extra_help']; ?></p>
122
+ <?php endif; ?>
123
+ </div>
124
+ </div>
125
+ <?php endforeach; ?>
126
+ <div class="row sgpb-feedback-btns-wrapper">
127
+ <div class="col-md-6">
128
+ <input type="button" class="btn btn-sm btn-success sgpb-feedback-submit" name="sgpb-feedback-submit" value="<?php _e('Submit & Deactivate', SG_POPUP_TEXT_DOMAIN); ?>">
129
+ </div>
130
+ <div class="col-md-6">
131
+ <input type="button" class="btn btn-sm sgpb-feedback-submit-skip" name="sgpb-feedback-submit-skip" value="<?php _e('Skip & Deactivate', SG_POPUP_TEXT_DOMAIN); ?>">
132
+ </div>
133
+ </div>
134
+ </form>
135
+ </div>
136
+ </div>
137
+ </div>
138
+ </div>
139
+ </div>
140
+ <?php
141
+ }
142
+
143
+ private function isPluginsScreen() {
144
+ return in_array(get_current_screen()->id, array('plugins', 'plugins-network'));
145
+ }
146
+ }
com/classes/Filters.php CHANGED
@@ -1,873 +1,873 @@
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, $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['allMetaboxesView'] = array(
417
- 'key' => 'allMetaboxesView',
418
- 'displayName' => 'Main Options',
419
- 'short_description' => 'main options',
420
- 'filePath' => SG_POPUP_VIEWS_PATH.'allMetaboxesView.php',
421
- 'priority' => 'high'
422
- );
423
-
424
- $metaboxes['targetMetaboxView'] = array(
425
- 'key' => 'targetMetaboxView',
426
- 'displayName' => 'Display Rules',
427
- 'short_description' => 'Select where on the website to trigger the popup',
428
- 'filePath' => SG_POPUP_VIEWS_PATH.'targetView.php',
429
- 'priority' => 'high'
430
- );
431
-
432
- $metaboxes['eventsMetaboxView'] = array(
433
- 'key' => 'eventsMetaboxView',
434
- 'displayName' => 'Events',
435
- 'short_description' => 'Select the specific actions that will trigger the popup, default event is on load',
436
- 'filePath' => SG_POPUP_VIEWS_PATH.'eventsView.php',
437
- 'priority' => 'high'
438
- );
439
-
440
- $metaboxes['conditionsMetaboxView'] = array(
441
- 'key' => 'conditionsMetaboxView',
442
- 'displayName' => 'Conditions',
443
- 'short_description' => 'Select advanced conditions for more professional targeting',
444
- 'filePath' => SG_POPUP_VIEWS_PATH.'conditionsView.php',
445
- 'priority' => 'high'
446
- );
447
-
448
- $metaboxes['behaviorAfterSpecialEventsMetaboxView'] = array(
449
- 'key' => 'behaviorAfterSpecialEventsMetaboxView',
450
- 'displayName' => 'Behavior After Special Events',
451
- 'short_description' => 'Select special events that will trigger the popup',
452
- 'filePath' => SG_POPUP_VIEWS_PATH.'behaviorAfterSpecialEventsView.php',
453
- 'priority' => 'high'
454
- );
455
-
456
- $metaboxes['popupDesignMetaBoxView'] = array(
457
- 'key' => 'popupDesignMetaBoxView',
458
- 'displayName' => 'Design',
459
- 'short_description' => 'Customize design, background and overlay of the popup',
460
- 'filePath' => SG_POPUP_VIEWS_PATH.'popupDesignView.php',
461
- 'priority' => 'high'
462
- );
463
-
464
- $metaboxes['closeSettings'] = array(
465
- 'key' => 'closeSettings',
466
- 'displayName' => 'Closing',
467
- 'short_description' => 'Select the desired popup closing method, customize close button',
468
- 'filePath' => SG_POPUP_VIEWS_PATH.'closeSettingsView.php',
469
- 'priority' => 'high'
470
- );
471
-
472
- $metaboxes['dimensions'] = array(
473
- 'key' => 'dimensions',
474
- 'displayName' => 'Dimensions',
475
- 'short_description' => 'Make your popup mobile friendly and responsive for all devices',
476
- 'filePath' => SG_POPUP_VIEWS_PATH.'dimensionsView.php',
477
- 'priority' => 'high'
478
- );
479
-
480
- $metaboxes['optionsMetaboxView'] = array(
481
- 'key' => 'optionsMetaboxView',
482
- 'displayName' => 'Advanced',
483
- 'short_description' => 'Use advanced features for popup animations, opening and closing actions',
484
- 'filePath' => SG_POPUP_VIEWS_PATH.'optionsView.php',
485
- 'priority' => 'high'
486
- );
487
-
488
- $metaboxes['otherConditionsMetaBoxView'] = array(
489
- 'key' => 'otherConditionsMetaBoxView',
490
- 'displayName' => 'Scheduling'.$otherConditionsProLabel,
491
- 'short_description' => 'Schedule your popup for a particular day or for a selected timeframe',
492
- 'filePath' => SG_POPUP_VIEWS_PATH.'otherConditionsView.php',
493
- 'priority' => 'high'
494
- );
495
-
496
- $metaboxes['floatingButton'] = array(
497
- 'key' => 'floatingButton',
498
- 'displayName' => 'Floating Button',
499
- 'short_description' => 'Set the popup to appear on a scrollable call to action button',
500
- 'filePath' => SG_POPUP_VIEWS_PATH.'floatingButton.php',
501
- 'context' => 'side',
502
- 'priority' => 'high'
503
- );
504
-
505
- $metaboxes['popupOpeningCounter'] = array(
506
- 'key' => 'popupOpeningCounter',
507
- 'displayName' => 'Statistics',
508
- 'short_description' => 'Enable or disable the counts of the popup',
509
- 'filePath' => SG_POPUP_VIEWS_PATH.'popupOpeningCounter.php',
510
- 'context' => 'side',
511
- 'priority' => 'low'
512
- );
513
-
514
- $metaboxes['customCssJs'] = array(
515
- 'key' => 'customCssJs',
516
- 'displayName' => 'Custom JS or CSS',
517
- 'short_description' => 'Add custom JS and/or CSS code for extra control',
518
- 'filePath' => SG_POPUP_VIEWS_PATH.'customEditor.php',
519
- 'priority' => 'low'
520
- );
521
-
522
- $metaboxes = apply_filters('sgpbPopupTypeMainViewMetaboxes', $metaboxes);
523
-
524
- return $metaboxes;
525
- }
526
-
527
- public function popupEvents($events)
528
- {
529
- foreach ($events as $eventKey => $eventData) {
530
- if (isset($eventData['param'])) {
531
- if ($eventData['param'] == SGPB_CSS_CLASS_ACTIONS_KEY) {
532
- unset($events[$eventKey]);
533
- $events[] = array('param' => 'click');
534
- $events[] = array('param' => 'hover');
535
- $events[] = array('param' => 'confirm');
536
- }
537
- else if ($eventData['param'] == SGPB_CLICK_ACTION_KEY) {
538
- $events[$eventKey]['param'] = 'click';
539
- }
540
- else if ($eventData['param'] == SGPB_HOVER_ACTION_KEY) {
541
- $events[$eventKey]['param'] = 'hover';
542
- }
543
- }
544
- }
545
-
546
- return $events;
547
- }
548
-
549
- public function savedPostData($postData)
550
- {
551
- // for old popups here we change already saved old popup id
552
- if (isset($postData['sgpb-mailchimp-success-popup'])) {
553
- // sgpGetCorrectPopupId it's a temporary function and it will be removed in future
554
- if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
555
- $postData['sgpb-mailchimp-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-mailchimp-success-popup']);
556
- }
557
- }
558
- // for old popups here we change already saved old popup id
559
- if (isset($postData['sgpb-aweber-success-popup'])) {
560
- if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
561
- $postData['sgpb-aweber-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-aweber-success-popup']);
562
- }
563
- }
564
-
565
- return $postData;
566
- }
567
-
568
- public function removeAddNewSubmenu()
569
- {
570
- //we don't need the default add new, since we are using our custom page for it
571
- $page = remove_submenu_page(
572
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
573
- 'post-new.php?post_type='.SG_POPUP_POST_TYPE
574
- );
575
- }
576
-
577
- public function maybeShortenEddFilename($return, $package)
578
- {
579
- if (strpos($package, SG_POPUP_STORE_URL) !== false) {
580
- add_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 100, 2);
581
- }
582
- return $return;
583
- }
584
-
585
- public function shortenEddFilename($filename, $ext)
586
- {
587
- $filename = substr($filename, 0, 20).$ext;
588
- remove_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 10);
589
- return $filename;
590
- }
591
-
592
- public function editPopupPreviewLink($previewLink = '', $post = array())
593
- {
594
- if (!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) {
595
- $popupId = $post->ID;
596
- $targets = get_post_meta($popupId, 'sg_popup_target_preview', true);
597
- if (empty($targets['sgpb-target'][0])) {
598
- return $previewLink .= '/?sg_popup_preview_id='.$popupId;
599
- }
600
- $targetParams = @$targets['sgpb-target'][0][0]['param'];
601
- if ((!empty($targetParams) && $targetParams == 'not_rule') || empty($targetParams)) {
602
- $previewLink = home_url();
603
- $previewLink .= '/?sg_popup_preview_id='.$popupId;
604
-
605
- return $previewLink;
606
- }
607
- foreach ($targets['sgpb-target'][0] as $targetKey => $targetValue) {
608
- if (!isset($targetValue['operator']) || $targetValue['operator'] == '!=') {
609
- continue;
610
- }
611
- $previewLink = self::getPopupPreviewLink($targetValue, $popupId);
612
- $previewLink .= '/?sg_popup_preview_id='.$popupId;
613
- }
614
- }
615
-
616
- return $previewLink;
617
- }
618
-
619
- public static function getPopupPreviewLink($targetData, $popupId)
620
- {
621
- $previewLink = home_url();
622
-
623
- if (empty($targetData['param'])) {
624
- return $previewLink;
625
- }
626
- $targetParam = $targetData['param'];
627
-
628
- if ($targetParam == 'everywhere') {
629
- return $previewLink;
630
- }
631
-
632
- $args = array(
633
- 'orderby' => 'rand'
634
- );
635
-
636
- // posts
637
- if (strpos($targetData['param'], '_all')) {
638
- if ($targetData['param'] == 'post_all') {
639
- $args['post_type'] = 'post';
640
- }
641
- if ($targetData['param'] == 'page_all') {
642
- $args['post_type'] = 'page';
643
- }
644
- }
645
- if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
646
- $args['post_type'] = $targetData['value'];
647
- }
648
- if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
649
- $pageTypes = $targetData['value'];
650
- foreach ($pageTypes as $pageType) {
651
-
652
- if ($pageType == 'is_home_page') {
653
- if (is_front_page() && is_home()) {
654
- // default homepage
655
- return get_home_url();
656
- }
657
- else if (is_front_page()) {
658
- // static homepage
659
- return get_home_url();
660
- }
661
- }
662
- else if (function_exists($pageType)) {
663
- if ($pageType == 'is_home') {
664
- return get_home_url();
665
- }
666
- else if ($pageType == 'is_search') {
667
- return get_search_link();
668
- }
669
- else if ($pageType == 'is_shop') {
670
- return get_home_url().'/shop/';
671
- }
672
- }
673
- }
674
- }
675
- if (isset($args['post_type'])) {
676
- $the_query = new WP_Query($args);
677
- foreach ($the_query->posts as $post) {
678
- $postId = $post->ID;
679
- if (get_permalink($postId)) {
680
- return get_permalink($postId);
681
- }
682
- }
683
- }
684
- // selected post/page/custom_post_types...
685
- if (strpos($targetData['param'], '_selected') && !empty($targetData['value'])) {
686
- $value = array_keys($targetData['value']);
687
- if (!empty($value[0])) {
688
- if (get_permalink($value[0])) {
689
- return get_permalink($value[0]);
690
- }
691
- }
692
- }
693
- if (strpos($targetData['param'], '_archive') && !empty($targetData['value'])) {
694
- $value = array_keys($targetData['value']);
695
- if (!empty($value[0])) {
696
- if (get_permalink($value[0])) {
697
- return get_permalink($value[0]);
698
- }
699
- }
700
- }
701
-
702
- return $previewLink;
703
- }
704
-
705
- public function excludePostsToShow($where)
706
- {
707
- if (function_exists('is_admin') && is_admin()) {
708
- if (!function_exists('get_current_screen')) {
709
- return $where;
710
- }
711
-
712
- $screen = get_current_screen();
713
- if (empty($screen)) {
714
- return $where;
715
- }
716
-
717
- $postType = $screen->post_type;
718
- if ($postType == SG_POPUP_POST_TYPE &&
719
- $screen instanceof \WP_Screen &&
720
- $screen->id === 'edit-popupbuilder') {
721
- if (class_exists('sgpb\SGPopup')) {
722
- $activePopupsQuery = $this->getQueryString();
723
- if ($activePopupsQuery && $activePopupsQuery != '') {
724
- $where .= $activePopupsQuery;
725
- }
726
- }
727
- }
728
- }
729
-
730
- return $where;
731
- }
732
-
733
- public function clearContentPreviewMode($content)
734
- {
735
- global $post_type;
736
-
737
- if (is_preview() && $post_type == SG_POPUP_POST_TYPE) {
738
- $content = '';
739
- }
740
-
741
- return $content;
742
- }
743
-
744
- public function filterPopupContent($content, $popupId)
745
- {
746
- preg_match_all('/<iframe.*?src="(.*?)".*?<\/iframe>/', $content, $matches);
747
- /*$finalContent = '';*/
748
- // $matches[0] array contain iframes stings
749
- // $matches[1] array contain iframes URLs
750
- if (empty($matches) && empty($matches[0]) && empty($matches[1])) {
751
- return $content;
752
- }
753
- $urls = $matches[1];
754
-
755
- foreach ($matches[0] as $key => $iframe) {
756
- if (empty($urls[$key])) {
757
- continue;
758
- }
759
-
760
- $pos = strpos($iframe, $urls[$key]);
761
-
762
- if ($pos === false) {
763
- continue;
764
- }
765
-
766
- $content = str_replace(' src="'.$urls[$key].'"', ' src="" data-attr-src="'.esc_attr($urls[$key]).'"', $content);
767
- }
768
- if (function_exists('do_blocks')) {
769
- $content = do_blocks($content);
770
- }
771
-
772
- return do_shortcode($content);
773
- }
774
-
775
- public function addNewPostUrl($url, $path)
776
- {
777
- if ($path == 'post-new.php?post_type='.SG_POPUP_POST_TYPE) {
778
- $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);
779
- }
780
-
781
- return $url;
782
- }
783
-
784
- public function popupsTableColumns($columns)
785
- {
786
- unset($columns['date']);
787
-
788
- $additionalItems = array();
789
- $additionalItems['counter'] = __('Views', SG_POPUP_TEXT_DOMAIN);
790
- $additionalItems['onOff'] = __('Status', SG_POPUP_TEXT_DOMAIN);
791
- $filterColumnsDisplaySettings = apply_filters('sgpbAddRandomColumnIntoAllPopupsViewTable', $additionalItems);
792
-
793
- if (isset($filterColumnsDisplaySettings['sgpbIsRandomEnabled'])){
794
- $additionalItems = $filterColumnsDisplaySettings;
795
- }
796
-
797
- $additionalItems['type'] = __('Type', SG_POPUP_TEXT_DOMAIN);
798
- $additionalItems['shortcode'] = __('Shortcode', SG_POPUP_TEXT_DOMAIN);
799
- $additionalItems['className'] = __('Class', SG_POPUP_TEXT_DOMAIN);
800
- $additionalItems['options'] = __('Actions', SG_POPUP_TEXT_DOMAIN);
801
-
802
- return $columns + $additionalItems;
803
- }
804
-
805
- /**
806
- * Function to add/hide links from popups dataTable row
807
- */
808
- public function quickRowLinksManager($actions, $post)
809
- {
810
- global $post_type;
811
-
812
- if ($post_type != SG_POPUP_POST_TYPE) {
813
- return $actions;
814
- }
815
- // remove quick edit link
816
- unset($actions['inline hide-if-no-js']);
817
- // remove view link
818
- unset($actions['view']);
819
- $url = AdminHelper::popupGetClonePostLink($post->ID , 'display', false);
820
-
821
- $actions['clone'] = '<a href="'.$url.'" title="';
822
- $actions['clone'] .= esc_attr__("Clone this item", SG_POPUP_TEXT_DOMAIN);
823
- $actions['clone'] .= '">'. esc_html__('Clone', SG_POPUP_TEXT_DOMAIN).'</a>';
824
-
825
- return $actions;
826
- }
827
-
828
- /* media button scripts */
829
- public function adminJsFilter($jsFiles)
830
- {
831
- $allowToShow = MediaButton::allowToShow();
832
- if ($allowToShow) {
833
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
834
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
835
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Popup.js');
836
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
837
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'MediaButton.js');
838
-
839
- $jsFiles['localizeData'][] = array(
840
- 'handle' => 'Popup.js',
841
- 'name' => 'sgpbPublicUrl',
842
- 'data' => SG_POPUP_PUBLIC_URL
843
- );
844
-
845
- $jsFiles['localizeData'][] = array(
846
- 'handle' => 'MediaButton.js',
847
- 'name' => 'mediaButtonParams',
848
- 'data' => array(
849
- 'currentPostType' => get_post_type(),
850
- 'popupBuilderPostType' => SG_POPUP_POST_TYPE,
851
- 'ajaxUrl' => admin_url('admin-ajax.php'),
852
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
853
- )
854
- );
855
- }
856
-
857
- return $jsFiles;
858
- }
859
-
860
- /* media button styles */
861
- public function sgpbAdminCssFiles($cssFiles)
862
- {
863
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
864
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
865
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
866
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'newDesignFromBuild.css', 'dep' => array(), 'ver' => rand(1, 10000), 'inFooter' => false);
867
-
868
- return $cssFiles;
869
- }
870
-
871
- }
872
-
873
-
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, $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['allMetaboxesView'] = array(
417
+ 'key' => 'allMetaboxesView',
418
+ 'displayName' => 'Main Options',
419
+ 'short_description' => 'main options',
420
+ 'filePath' => SG_POPUP_VIEWS_PATH.'allMetaboxesView.php',
421
+ 'priority' => 'high'
422
+ );
423
+
424
+ $metaboxes['targetMetaboxView'] = array(
425
+ 'key' => 'targetMetaboxView',
426
+ 'displayName' => 'Display Rules',
427
+ 'short_description' => 'Select where on the website to trigger the popup',
428
+ 'filePath' => SG_POPUP_VIEWS_PATH.'targetView.php',
429
+ 'priority' => 'high'
430
+ );
431
+
432
+ $metaboxes['eventsMetaboxView'] = array(
433
+ 'key' => 'eventsMetaboxView',
434
+ 'displayName' => 'Events',
435
+ 'short_description' => 'Select the specific actions that will trigger the popup, default event is on load',
436
+ 'filePath' => SG_POPUP_VIEWS_PATH.'eventsView.php',
437
+ 'priority' => 'high'
438
+ );
439
+
440
+ $metaboxes['conditionsMetaboxView'] = array(
441
+ 'key' => 'conditionsMetaboxView',
442
+ 'displayName' => 'Conditions',
443
+ 'short_description' => 'Select advanced conditions for more professional targeting',
444
+ 'filePath' => SG_POPUP_VIEWS_PATH.'conditionsView.php',
445
+ 'priority' => 'high'
446
+ );
447
+
448
+ $metaboxes['behaviorAfterSpecialEventsMetaboxView'] = array(
449
+ 'key' => 'behaviorAfterSpecialEventsMetaboxView',
450
+ 'displayName' => 'Behavior After Special Events',
451
+ 'short_description' => 'Select special events that will trigger the popup',
452
+ 'filePath' => SG_POPUP_VIEWS_PATH.'behaviorAfterSpecialEventsView.php',
453
+ 'priority' => 'high'
454
+ );
455
+
456
+ $metaboxes['popupDesignMetaBoxView'] = array(
457
+ 'key' => 'popupDesignMetaBoxView',
458
+ 'displayName' => 'Design',
459
+ 'short_description' => 'Customize design, background and overlay of the popup',
460
+ 'filePath' => SG_POPUP_VIEWS_PATH.'popupDesignView.php',
461
+ 'priority' => 'high'
462
+ );
463
+
464
+ $metaboxes['closeSettings'] = array(
465
+ 'key' => 'closeSettings',
466
+ 'displayName' => 'Closing',
467
+ 'short_description' => 'Select the desired popup closing method, customize close button',
468
+ 'filePath' => SG_POPUP_VIEWS_PATH.'closeSettingsView.php',
469
+ 'priority' => 'high'
470
+ );
471
+
472
+ $metaboxes['dimensions'] = array(
473
+ 'key' => 'dimensions',
474
+ 'displayName' => 'Dimensions',
475
+ 'short_description' => 'Make your popup mobile friendly and responsive for all devices',
476
+ 'filePath' => SG_POPUP_VIEWS_PATH.'dimensionsView.php',
477
+ 'priority' => 'high'
478
+ );
479
+
480
+ $metaboxes['optionsMetaboxView'] = array(
481
+ 'key' => 'optionsMetaboxView',
482
+ 'displayName' => 'Advanced',
483
+ 'short_description' => 'Use advanced features for popup animations, opening and closing actions',
484
+ 'filePath' => SG_POPUP_VIEWS_PATH.'optionsView.php',
485
+ 'priority' => 'high'
486
+ );
487
+
488
+ $metaboxes['otherConditionsMetaBoxView'] = array(
489
+ 'key' => 'otherConditionsMetaBoxView',
490
+ 'displayName' => 'Scheduling'.$otherConditionsProLabel,
491
+ 'short_description' => 'Schedule your popup for a particular day or for a selected timeframe',
492
+ 'filePath' => SG_POPUP_VIEWS_PATH.'otherConditionsView.php',
493
+ 'priority' => 'high'
494
+ );
495
+
496
+ $metaboxes['floatingButton'] = array(
497
+ 'key' => 'floatingButton',
498
+ 'displayName' => 'Floating Button',
499
+ 'short_description' => 'Set the popup to appear on a scrollable call to action button',
500
+ 'filePath' => SG_POPUP_VIEWS_PATH.'floatingButton.php',
501
+ 'context' => 'side',
502
+ 'priority' => 'high'
503
+ );
504
+
505
+ $metaboxes['popupOpeningCounter'] = array(
506
+ 'key' => 'popupOpeningCounter',
507
+ 'displayName' => 'Statistics',
508
+ 'short_description' => 'Enable or disable the counts of the popup',
509
+ 'filePath' => SG_POPUP_VIEWS_PATH.'popupOpeningCounter.php',
510
+ 'context' => 'side',
511
+ 'priority' => 'low'
512
+ );
513
+
514
+ $metaboxes['customCssJs'] = array(
515
+ 'key' => 'customCssJs',
516
+ 'displayName' => 'Custom JS or CSS',
517
+ 'short_description' => 'Add custom JS and/or CSS code for extra control',
518
+ 'filePath' => SG_POPUP_VIEWS_PATH.'customEditor.php',
519
+ 'priority' => 'low'
520
+ );
521
+
522
+ $metaboxes = apply_filters('sgpbPopupTypeMainViewMetaboxes', $metaboxes);
523
+
524
+ return $metaboxes;
525
+ }
526
+
527
+ public function popupEvents($events)
528
+ {
529
+ foreach ($events as $eventKey => $eventData) {
530
+ if (isset($eventData['param'])) {
531
+ if ($eventData['param'] == SGPB_CSS_CLASS_ACTIONS_KEY) {
532
+ unset($events[$eventKey]);
533
+ $events[] = array('param' => 'click');
534
+ $events[] = array('param' => 'hover');
535
+ $events[] = array('param' => 'confirm');
536
+ }
537
+ else if ($eventData['param'] == SGPB_CLICK_ACTION_KEY) {
538
+ $events[$eventKey]['param'] = 'click';
539
+ }
540
+ else if ($eventData['param'] == SGPB_HOVER_ACTION_KEY) {
541
+ $events[$eventKey]['param'] = 'hover';
542
+ }
543
+ }
544
+ }
545
+
546
+ return $events;
547
+ }
548
+
549
+ public function savedPostData($postData)
550
+ {
551
+ // for old popups here we change already saved old popup id
552
+ if (isset($postData['sgpb-mailchimp-success-popup'])) {
553
+ // sgpGetCorrectPopupId it's a temporary function and it will be removed in future
554
+ if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
555
+ $postData['sgpb-mailchimp-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-mailchimp-success-popup']);
556
+ }
557
+ }
558
+ // for old popups here we change already saved old popup id
559
+ if (isset($postData['sgpb-aweber-success-popup'])) {
560
+ if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
561
+ $postData['sgpb-aweber-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-aweber-success-popup']);
562
+ }
563
+ }
564
+
565
+ return $postData;
566
+ }
567
+
568
+ public function removeAddNewSubmenu()
569
+ {
570
+ //we don't need the default add new, since we are using our custom page for it
571
+ $page = remove_submenu_page(
572
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
573
+ 'post-new.php?post_type='.SG_POPUP_POST_TYPE
574
+ );
575
+ }
576
+
577
+ public function maybeShortenEddFilename($return, $package)
578
+ {
579
+ if (strpos($package, SG_POPUP_STORE_URL) !== false) {
580
+ add_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 100, 2);
581
+ }
582
+ return $return;
583
+ }
584
+
585
+ public function shortenEddFilename($filename, $ext)
586
+ {
587
+ $filename = substr($filename, 0, 20).$ext;
588
+ remove_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 10);
589
+ return $filename;
590
+ }
591
+
592
+ public function editPopupPreviewLink($previewLink = '', $post = array())
593
+ {
594
+ if (!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) {
595
+ $popupId = $post->ID;
596
+ $targets = get_post_meta($popupId, 'sg_popup_target_preview', true);
597
+ if (empty($targets['sgpb-target'][0])) {
598
+ return $previewLink .= '/?sg_popup_preview_id='.$popupId;
599
+ }
600
+ $targetParams = @$targets['sgpb-target'][0][0]['param'];
601
+ if ((!empty($targetParams) && $targetParams == 'not_rule') || empty($targetParams)) {
602
+ $previewLink = home_url();
603
+ $previewLink .= '/?sg_popup_preview_id='.$popupId;
604
+
605
+ return $previewLink;
606
+ }
607
+ foreach ($targets['sgpb-target'][0] as $targetKey => $targetValue) {
608
+ if (!isset($targetValue['operator']) || $targetValue['operator'] == '!=') {
609
+ continue;
610
+ }
611
+ $previewLink = self::getPopupPreviewLink($targetValue, $popupId);
612
+ $previewLink .= '/?sg_popup_preview_id='.$popupId;
613
+ }
614
+ }
615
+
616
+ return $previewLink;
617
+ }
618
+
619
+ public static function getPopupPreviewLink($targetData, $popupId)
620
+ {
621
+ $previewLink = home_url();
622
+
623
+ if (empty($targetData['param'])) {
624
+ return $previewLink;
625
+ }
626
+ $targetParam = $targetData['param'];
627
+
628
+ if ($targetParam == 'everywhere') {
629
+ return $previewLink;
630
+ }
631
+
632
+ $args = array(
633
+ 'orderby' => 'rand'
634
+ );
635
+
636
+ // posts
637
+ if (strpos($targetData['param'], '_all')) {
638
+ if ($targetData['param'] == 'post_all') {
639
+ $args['post_type'] = 'post';
640
+ }
641
+ if ($targetData['param'] == 'page_all') {
642
+ $args['post_type'] = 'page';
643
+ }
644
+ }
645
+ if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
646
+ $args['post_type'] = $targetData['value'];
647
+ }
648
+ if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
649
+ $pageTypes = $targetData['value'];
650
+ foreach ($pageTypes as $pageType) {
651
+
652
+ if ($pageType == 'is_home_page') {
653
+ if (is_front_page() && is_home()) {
654
+ // default homepage
655
+ return get_home_url();
656
+ }
657
+ else if (is_front_page()) {
658
+ // static homepage
659
+ return get_home_url();
660
+ }
661
+ }
662
+ else if (function_exists($pageType)) {
663
+ if ($pageType == 'is_home') {
664
+ return get_home_url();
665
+ }
666
+ else if ($pageType == 'is_search') {
667
+ return get_search_link();
668
+ }
669
+ else if ($pageType == 'is_shop') {
670
+ return get_home_url().'/shop/';
671
+ }
672
+ }
673
+ }
674
+ }
675
+ if (isset($args['post_type'])) {
676
+ $the_query = new WP_Query($args);
677
+ foreach ($the_query->posts as $post) {
678
+ $postId = $post->ID;
679
+ if (get_permalink($postId)) {
680
+ return get_permalink($postId);
681
+ }
682
+ }
683
+ }
684
+ // selected post/page/custom_post_types...
685
+ if (strpos($targetData['param'], '_selected') && !empty($targetData['value'])) {
686
+ $value = array_keys($targetData['value']);
687
+ if (!empty($value[0])) {
688
+ if (get_permalink($value[0])) {
689
+ return get_permalink($value[0]);
690
+ }
691
+ }
692
+ }
693
+ if (strpos($targetData['param'], '_archive') && !empty($targetData['value'])) {
694
+ $value = array_keys($targetData['value']);
695
+ if (!empty($value[0])) {
696
+ if (get_permalink($value[0])) {
697
+ return get_permalink($value[0]);
698
+ }
699
+ }
700
+ }
701
+
702
+ return $previewLink;
703
+ }
704
+
705
+ public function excludePostsToShow($where)
706
+ {
707
+ if (function_exists('is_admin') && is_admin()) {
708
+ if (!function_exists('get_current_screen')) {
709
+ return $where;
710
+ }
711
+
712
+ $screen = get_current_screen();
713
+ if (empty($screen)) {
714
+ return $where;
715
+ }
716
+
717
+ $postType = $screen->post_type;
718
+ if ($postType == SG_POPUP_POST_TYPE &&
719
+ $screen instanceof \WP_Screen &&
720
+ $screen->id === 'edit-popupbuilder') {
721
+ if (class_exists('sgpb\SGPopup')) {
722
+ $activePopupsQuery = $this->getQueryString();
723
+ if ($activePopupsQuery && $activePopupsQuery != '') {
724
+ $where .= $activePopupsQuery;
725
+ }
726
+ }
727
+ }
728
+ }
729
+
730
+ return $where;
731
+ }
732
+
733
+ public function clearContentPreviewMode($content)
734
+ {
735
+ global $post_type;
736
+
737
+ if (is_preview() && $post_type == SG_POPUP_POST_TYPE) {
738
+ $content = '';
739
+ }
740
+
741
+ return $content;
742
+ }
743
+
744
+ public function filterPopupContent($content, $popupId)
745
+ {
746
+ preg_match_all('/<iframe.*?src="(.*?)".*?<\/iframe>/', $content, $matches);
747
+ /*$finalContent = '';*/
748
+ // $matches[0] array contain iframes stings
749
+ // $matches[1] array contain iframes URLs
750
+ if (empty($matches) && empty($matches[0]) && empty($matches[1])) {
751
+ return $content;
752
+ }
753
+ $urls = $matches[1];
754
+
755
+ foreach ($matches[0] as $key => $iframe) {
756
+ if (empty($urls[$key])) {
757
+ continue;
758
+ }
759
+
760
+ $pos = strpos($iframe, $urls[$key]);
761
+
762
+ if ($pos === false) {
763
+ continue;
764
+ }
765
+
766
+ $content = str_replace(' src="'.$urls[$key].'"', ' src="" data-attr-src="'.esc_attr($urls[$key]).'"', $content);
767
+ }
768
+ if (function_exists('do_blocks')) {
769
+ $content = do_blocks($content);
770
+ }
771
+
772
+ return do_shortcode($content);
773
+ }
774
+
775
+ public function addNewPostUrl($url, $path)
776
+ {
777
+ if ($path == 'post-new.php?post_type='.SG_POPUP_POST_TYPE) {
778
+ $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);
779
+ }
780
+
781
+ return $url;
782
+ }
783
+
784
+ public function popupsTableColumns($columns)
785
+ {
786
+ unset($columns['date']);
787
+
788
+ $additionalItems = array();
789
+ $additionalItems['counter'] = __('Views', SG_POPUP_TEXT_DOMAIN);
790
+ $additionalItems['onOff'] = __('Status', SG_POPUP_TEXT_DOMAIN);
791
+ $filterColumnsDisplaySettings = apply_filters('sgpbAddRandomColumnIntoAllPopupsViewTable', $additionalItems);
792
+
793
+ if (isset($filterColumnsDisplaySettings['sgpbIsRandomEnabled'])){
794
+ $additionalItems = $filterColumnsDisplaySettings;
795
+ }
796
+
797
+ $additionalItems['type'] = __('Type', SG_POPUP_TEXT_DOMAIN);
798
+ $additionalItems['shortcode'] = __('Shortcode', SG_POPUP_TEXT_DOMAIN);
799
+ $additionalItems['className'] = __('Class', SG_POPUP_TEXT_DOMAIN);
800
+ $additionalItems['options'] = __('Actions', SG_POPUP_TEXT_DOMAIN);
801
+
802
+ return $columns + $additionalItems;
803
+ }
804
+
805
+ /**
806
+ * Function to add/hide links from popups dataTable row
807
+ */
808
+ public function quickRowLinksManager($actions, $post)
809
+ {
810
+ global $post_type;
811
+
812
+ if ($post_type != SG_POPUP_POST_TYPE) {
813
+ return $actions;
814
+ }
815
+ // remove quick edit link
816
+ unset($actions['inline hide-if-no-js']);
817
+ // remove view link
818
+ unset($actions['view']);
819
+ $url = AdminHelper::popupGetClonePostLink($post->ID , 'display', false);
820
+
821
+ $actions['clone'] = '<a href="'.$url.'" title="';
822
+ $actions['clone'] .= esc_attr__("Clone this item", SG_POPUP_TEXT_DOMAIN);
823
+ $actions['clone'] .= '">'. esc_html__('Clone', SG_POPUP_TEXT_DOMAIN).'</a>';
824
+
825
+ return $actions;
826
+ }
827
+
828
+ /* media button scripts */
829
+ public function adminJsFilter($jsFiles)
830
+ {
831
+ $allowToShow = MediaButton::allowToShow();
832
+ if ($allowToShow) {
833
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
834
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
835
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Popup.js');
836
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
837
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'MediaButton.js');
838
+
839
+ $jsFiles['localizeData'][] = array(
840
+ 'handle' => 'Popup.js',
841
+ 'name' => 'sgpbPublicUrl',
842
+ 'data' => SG_POPUP_PUBLIC_URL
843
+ );
844
+
845
+ $jsFiles['localizeData'][] = array(
846
+ 'handle' => 'MediaButton.js',
847
+ 'name' => 'mediaButtonParams',
848
+ 'data' => array(
849
+ 'currentPostType' => get_post_type(),
850
+ 'popupBuilderPostType' => SG_POPUP_POST_TYPE,
851
+ 'ajaxUrl' => admin_url('admin-ajax.php'),
852
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
853
+ )
854
+ );
855
+ }
856
+
857
+ return $jsFiles;
858
+ }
859
+
860
+ /* media button styles */
861
+ public function sgpbAdminCssFiles($cssFiles)
862
+ {
863
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
864
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
865
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
866
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'newDesignFromBuild.css', 'dep' => array(), 'ver' => rand(1, 10000), 'inFooter' => false);
867
+
868
+ return $cssFiles;
869
+ }
870
+
871
+ }
872
+
873
+
com/classes/Installer.php CHANGED
@@ -1,331 +1,331 @@
1
- <?php
2
- namespace sgpb;
3
- use \SgpbPopupExtensionRegister;
4
-
5
- class Installer
6
- {
7
- public static function createTables($tables, $blogId = '')
8
- {
9
- global $wpdb;
10
- if (empty($tables)) {
11
- return false;
12
- }
13
-
14
- foreach ($tables as $table) {
15
- $createTable = 'CREATE TABLE IF NOT EXISTS ';
16
- $createTable .= $wpdb->prefix.$blogId;
17
- $createTable .= $table;
18
- $wpdb->query($createTable);
19
- }
20
-
21
- return true;
22
- }
23
-
24
- private static function getAllNeededTables()
25
- {
26
- $tables = array();
27
- global $SGPB_POPUP_TYPES;
28
- $popupTypes = $SGPB_POPUP_TYPES['typeName'];
29
-
30
- if (empty($popupTypes)) {
31
- return $tables;
32
- }
33
-
34
- foreach ($popupTypes as $popupTypeKey => $popupTypeLevel) {
35
- if (SGPB_POPUP_PKG >= $popupTypeLevel) {
36
- $className = ucfirst($popupTypeKey).'Popup';
37
-
38
- if (file_exists(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php')) {
39
-
40
- require_once(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php');
41
-
42
- $className = __NAMESPACE__.'\\'.$className;
43
-
44
- $popupTables = $className::getTablesSql();
45
-
46
- if (empty($popupTables)) {
47
- continue;
48
- }
49
-
50
- foreach ($popupTables as $tableSql) {
51
- $tables[] = $tableSql;
52
- }
53
- }
54
- }
55
-
56
- }
57
-
58
- return $tables;
59
- }
60
-
61
- public static function install()
62
- {
63
- $tables = self::getAllNeededTables();
64
- $filteredTables = apply_filters('sgpbTablesInstall', $tables);
65
-
66
- if (get_option('sgpb-dont-delete-data') === false) {
67
- // Initial option insert
68
- update_option('sgpb-dont-delete-data', 1);
69
- }
70
-
71
- self::createTables($filteredTables);
72
-
73
- self::setupInstallationsDateConfig($filteredTables);
74
-
75
- // get_current_blog_id() == 1 When plugin activated inside the child of multisite instance
76
- if (is_multisite() && get_current_blog_id() == 1) {
77
- global $wp_version;
78
-
79
- if ($wp_version > '4.6.0') {
80
- $sites = get_sites();
81
- }
82
- else {
83
- $sites = wp_get_sites();
84
- }
85
-
86
- foreach ($sites as $site) {
87
-
88
- if ($wp_version > '4.6.0') {
89
- $blogId = $site->blog_id.'_';
90
- }
91
- else {
92
- $blogId = $site['blog_id'].'_';
93
- }
94
- // blog Id 1 for multisite main site
95
- if ($blogId != 1) {
96
- self::createTables($filteredTables, $blogId);
97
- }
98
- }
99
- }
100
-
101
- // install extensions
102
- if (SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
103
- $obj = new PopupExtensionActivator();
104
- $obj->install();
105
- }
106
- }
107
-
108
- public static function setupInstallationsDateConfig()
109
- {
110
- update_option('sgpbUnsubscribeColumnFixed', 1);
111
- $usageDays = get_option('SGPBUsageDays');
112
- if (!$usageDays) {
113
- update_option('SGPBUsageDays', 0);
114
-
115
- $timeDate = new \DateTime('now');
116
- $installTime = strtotime($timeDate->format('Y-m-d H:i:s'));
117
- update_option('SGPBInstallDate', $installTime);
118
- $timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
119
-
120
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
121
- update_option('SGPBOpenNextTime', $timeNow);
122
- }
123
-
124
- $maxPopupCount = get_option('SGPBMaxOpenCount');
125
- if (!$maxPopupCount) {
126
- update_option('SGPBMaxOpenCount', SGPB_ASK_REVIEW_POPUP_COUNT);
127
- }
128
- }
129
-
130
- public static function uninstall()
131
- {
132
- delete_option('sgpb-user-roles');
133
-
134
- // When don't delete data if don't delete data option was unchecked
135
- if (!get_option('sgpb-dont-delete-data')) {
136
- return false;
137
- }
138
- delete_option('sgpb-dont-delete-data');
139
- delete_option('sgpb-new-subscriber');
140
- delete_option('sgpbUnsubscribeColumnFixed');
141
- delete_option('sgpbActivateExtensions');
142
- delete_option('sgpbExtensionsInfo');
143
- delete_option('sgpb-enable-debug-mode');
144
- delete_option('sgpb-disable-analytics-general');
145
-
146
- // Trigger popup data delete action
147
- do_action('sgpbDeletePopupData');
148
-
149
- self::deletePopups();
150
- self::deleteCustomTables();
151
-
152
- if (is_multisite()) {
153
- global $wp_version;
154
- if ($wp_version > '4.6.0') {
155
- $sites = get_sites();
156
- }
157
- else {
158
- $sites = wp_get_sites();
159
- }
160
-
161
- foreach ($sites as $site) {
162
- if ($wp_version > '4.6.0') {
163
- $blogId = $site->blog_id.'_';
164
- }
165
- else {
166
- $blogId = $site['blog_id'].'_';
167
- }
168
- self::deleteCustomTables($blogId);
169
- }
170
- }
171
-
172
- return true;
173
- }
174
-
175
- /**
176
- * Delete Taxonomy by name
177
- *
178
- * @since 1.0.0
179
- *
180
- * @param string $taxonomy
181
- *
182
- * @return void
183
- */
184
- public static function deleteCustomTerms($taxonomy)
185
- {
186
- global $wpdb;
187
-
188
- $customTermsQuery = 'SELECT t.name, t.term_id
189
- FROM '.$wpdb->terms . ' AS t
190
- INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt
191
- ON t.term_id = tt.term_id
192
- WHERE tt.taxonomy = "'.esc_sql($taxonomy).'"';
193
-
194
- $terms = $wpdb->get_results($customTermsQuery);
195
-
196
- $terms = apply_filters('sgpbDeleteTerms', $terms);
197
-
198
- foreach ($terms as $term) {
199
- if (empty($term)) {
200
- continue;
201
- }
202
- wp_delete_term($term->term_id, $taxonomy);
203
- }
204
- }
205
-
206
- /**
207
- * Delete all popup builder post types posts
208
- *
209
- * @since 1.0.0
210
- *
211
- * @return void
212
- *
213
- */
214
- private static function deletePopups()
215
- {
216
- $popups = get_posts(
217
- array(
218
- 'post_type' => SG_POPUP_POST_TYPE,
219
- 'post_status' => array(
220
- 'publish',
221
- 'pending',
222
- 'draft',
223
- 'auto-draft',
224
- 'future',
225
- 'private',
226
- 'inherit',
227
- 'trash'
228
- )
229
- )
230
- );
231
- $popups = apply_filters('sgpbDeletePopups', $popups);
232
-
233
- foreach ($popups as $popup) {
234
- if (empty($popup)) {
235
- continue;
236
- }
237
- wp_delete_post($popup->ID, true);
238
- }
239
- }
240
-
241
- private static function deleteCustomTables($blogId = '')
242
- {
243
- $allTableNames = self::getAllTableNames();
244
-
245
- if (empty($allTableNames)) {
246
- return false;
247
- }
248
- global $wpdb;
249
-
250
- foreach ($allTableNames as $tableName) {
251
- $deleteTable = $wpdb->prefix.$blogId.$tableName;
252
- $deleteTableSql = 'DROP TABLE '.$deleteTable;
253
-
254
- $wpdb->query($deleteTableSql);
255
- }
256
-
257
- return true;
258
- }
259
-
260
- /**
261
- * It's acquire all popup types installed table names
262
- *
263
- * @since 1.0.0
264
- *
265
- * @return array $popup types table names
266
- *
267
- */
268
- private static function getAllTableNames()
269
- {
270
- $tables = array();
271
- global $SGPB_POPUP_TYPES;
272
- $popupTypes = $SGPB_POPUP_TYPES['typeName'];
273
-
274
- if (empty($popupTypes)) {
275
- return $tables;
276
- }
277
-
278
- require_once(SG_POPUP_CONFIG_PATH.'configPackage.php');
279
-
280
- foreach ($popupTypes as $popupTypeKey => $popupTypeLevel) {
281
- if (SGPB_POPUP_PKG >= $popupTypeLevel) {
282
- $className = ucfirst($popupTypeKey).'Popup';
283
-
284
- if (file_exists(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php')) {
285
-
286
- require_once(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php');
287
-
288
- $className = __NAMESPACE__.'\\'.$className;
289
-
290
- $popupTables = $className::getTableNames();
291
-
292
- if (empty($popupTables)) {
293
- continue;
294
- }
295
-
296
- foreach ($popupTables as $tableName) {
297
- $tables[] = $tableName;
298
- }
299
- }
300
- }
301
-
302
- }
303
-
304
- return $tables;
305
- }
306
-
307
- public static function registerPlugin()
308
- {
309
- $pluginName = SG_POPUP_FILE_NAME;
310
- $classPath = SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php';
311
- $className = 'SgpbPopupExtension';
312
- $options = array();
313
-
314
- if (SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
315
- $options = array(
316
- 'licence' => array(
317
- 'key' => SG_POPUP_KEY,
318
- 'storeURL' => SG_POPUP_STORE_URL,
319
- 'file' => SG_POPUP_FILE_NAME,
320
- 'itemId' => SGPB_ITEM_ID,
321
- 'itemName' => __('Popup Builder', SG_POPUP_TEXT_DOMAIN),
322
- 'autor' => SG_POPUP_AUTHOR,
323
- 'boxLabel' => __('Popup Builder License', SG_POPUP_TEXT_DOMAIN)
324
- )
325
- );
326
- $options = apply_filters('sgpbRegisterOptions', $options);
327
- }
328
-
329
- @SgpbPopupExtensionRegister::register($pluginName, $classPath, $className, $options);
330
- }
331
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \SgpbPopupExtensionRegister;
4
+
5
+ class Installer
6
+ {
7
+ public static function createTables($tables, $blogId = '')
8
+ {
9
+ global $wpdb;
10
+ if (empty($tables)) {
11
+ return false;
12
+ }
13
+
14
+ foreach ($tables as $table) {
15
+ $createTable = 'CREATE TABLE IF NOT EXISTS ';
16
+ $createTable .= $wpdb->prefix.$blogId;
17
+ $createTable .= $table;
18
+ $wpdb->query($createTable);
19
+ }
20
+
21
+ return true;
22
+ }
23
+
24
+ private static function getAllNeededTables()
25
+ {
26
+ $tables = array();
27
+ global $SGPB_POPUP_TYPES;
28
+ $popupTypes = $SGPB_POPUP_TYPES['typeName'];
29
+
30
+ if (empty($popupTypes)) {
31
+ return $tables;
32
+ }
33
+
34
+ foreach ($popupTypes as $popupTypeKey => $popupTypeLevel) {
35
+ if (SGPB_POPUP_PKG >= $popupTypeLevel) {
36
+ $className = ucfirst($popupTypeKey).'Popup';
37
+
38
+ if (file_exists(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php')) {
39
+
40
+ require_once(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php');
41
+
42
+ $className = __NAMESPACE__.'\\'.$className;
43
+
44
+ $popupTables = $className::getTablesSql();
45
+
46
+ if (empty($popupTables)) {
47
+ continue;
48
+ }
49
+
50
+ foreach ($popupTables as $tableSql) {
51
+ $tables[] = $tableSql;
52
+ }
53
+ }
54
+ }
55
+
56
+ }
57
+
58
+ return $tables;
59
+ }
60
+
61
+ public static function install()
62
+ {
63
+ $tables = self::getAllNeededTables();
64
+ $filteredTables = apply_filters('sgpbTablesInstall', $tables);
65
+
66
+ if (get_option('sgpb-dont-delete-data') === false) {
67
+ // Initial option insert
68
+ update_option('sgpb-dont-delete-data', 1);
69
+ }
70
+
71
+ self::createTables($filteredTables);
72
+
73
+ self::setupInstallationsDateConfig($filteredTables);
74
+
75
+ // get_current_blog_id() == 1 When plugin activated inside the child of multisite instance
76
+ if (is_multisite() && get_current_blog_id() == 1) {
77
+ global $wp_version;
78
+
79
+ if ($wp_version > '4.6.0') {
80
+ $sites = get_sites();
81
+ }
82
+ else {
83
+ $sites = wp_get_sites();
84
+ }
85
+
86
+ foreach ($sites as $site) {
87
+
88
+ if ($wp_version > '4.6.0') {
89
+ $blogId = $site->blog_id.'_';
90
+ }
91
+ else {
92
+ $blogId = $site['blog_id'].'_';
93
+ }
94
+ // blog Id 1 for multisite main site
95
+ if ($blogId != 1) {
96
+ self::createTables($filteredTables, $blogId);
97
+ }
98
+ }
99
+ }
100
+
101
+ // install extensions
102
+ if (SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
103
+ $obj = new PopupExtensionActivator();
104
+ $obj->install();
105
+ }
106
+ }
107
+
108
+ public static function setupInstallationsDateConfig()
109
+ {
110
+ update_option('sgpbUnsubscribeColumnFixed', 1);
111
+ $usageDays = get_option('SGPBUsageDays');
112
+ if (!$usageDays) {
113
+ update_option('SGPBUsageDays', 0);
114
+
115
+ $timeDate = new \DateTime('now');
116
+ $installTime = strtotime($timeDate->format('Y-m-d H:i:s'));
117
+ update_option('SGPBInstallDate', $installTime);
118
+ $timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
119
+
120
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
121
+ update_option('SGPBOpenNextTime', $timeNow);
122
+ }
123
+
124
+ $maxPopupCount = get_option('SGPBMaxOpenCount');
125
+ if (!$maxPopupCount) {
126
+ update_option('SGPBMaxOpenCount', SGPB_ASK_REVIEW_POPUP_COUNT);
127
+ }
128
+ }
129
+
130
+ public static function uninstall()
131
+ {
132
+ delete_option('sgpb-user-roles');
133
+
134
+ // When don't delete data if don't delete data option was unchecked
135
+ if (!get_option('sgpb-dont-delete-data')) {
136
+ return false;
137
+ }
138
+ delete_option('sgpb-dont-delete-data');
139
+ delete_option('sgpb-new-subscriber');
140
+ delete_option('sgpbUnsubscribeColumnFixed');
141
+ delete_option('sgpbActivateExtensions');
142
+ delete_option('sgpbExtensionsInfo');
143
+ delete_option('sgpb-enable-debug-mode');
144
+ delete_option('sgpb-disable-analytics-general');
145
+
146
+ // Trigger popup data delete action
147
+ do_action('sgpbDeletePopupData');
148
+
149
+ self::deletePopups();
150
+ self::deleteCustomTables();
151
+
152
+ if (is_multisite()) {
153
+ global $wp_version;
154
+ if ($wp_version > '4.6.0') {
155
+ $sites = get_sites();
156
+ }
157
+ else {
158
+ $sites = wp_get_sites();
159
+ }
160
+
161
+ foreach ($sites as $site) {
162
+ if ($wp_version > '4.6.0') {
163
+ $blogId = $site->blog_id.'_';
164
+ }
165
+ else {
166
+ $blogId = $site['blog_id'].'_';
167
+ }
168
+ self::deleteCustomTables($blogId);
169
+ }
170
+ }
171
+
172
+ return true;
173
+ }
174
+
175
+ /**
176
+ * Delete Taxonomy by name
177
+ *
178
+ * @since 1.0.0
179
+ *
180
+ * @param string $taxonomy
181
+ *
182
+ * @return void
183
+ */
184
+ public static function deleteCustomTerms($taxonomy)
185
+ {
186
+ global $wpdb;
187
+
188
+ $customTermsQuery = 'SELECT t.name, t.term_id
189
+ FROM '.$wpdb->terms . ' AS t
190
+ INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt
191
+ ON t.term_id = tt.term_id
192
+ WHERE tt.taxonomy = "'.esc_sql($taxonomy).'"';
193
+
194
+ $terms = $wpdb->get_results($customTermsQuery);
195
+
196
+ $terms = apply_filters('sgpbDeleteTerms', $terms);
197
+
198
+ foreach ($terms as $term) {
199
+ if (empty($term)) {
200
+ continue;
201
+ }
202
+ wp_delete_term($term->term_id, $taxonomy);
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Delete all popup builder post types posts
208
+ *
209
+ * @since 1.0.0
210
+ *
211
+ * @return void
212
+ *
213
+ */
214
+ private static function deletePopups()
215
+ {
216
+ $popups = get_posts(
217
+ array(
218
+ 'post_type' => SG_POPUP_POST_TYPE,
219
+ 'post_status' => array(
220
+ 'publish',
221
+ 'pending',
222
+ 'draft',
223
+ 'auto-draft',
224
+ 'future',
225
+ 'private',
226
+ 'inherit',
227
+ 'trash'
228
+ )
229
+ )
230
+ );
231
+ $popups = apply_filters('sgpbDeletePopups', $popups);
232
+
233
+ foreach ($popups as $popup) {
234
+ if (empty($popup)) {
235
+ continue;
236
+ }
237
+ wp_delete_post($popup->ID, true);
238
+ }
239
+ }
240
+
241
+ private static function deleteCustomTables($blogId = '')
242
+ {
243
+ $allTableNames = self::getAllTableNames();
244
+
245
+ if (empty($allTableNames)) {
246
+ return false;
247
+ }
248
+ global $wpdb;
249
+
250
+ foreach ($allTableNames as $tableName) {
251
+ $deleteTable = $wpdb->prefix.$blogId.$tableName;
252
+ $deleteTableSql = 'DROP TABLE '.$deleteTable;
253
+
254
+ $wpdb->query($deleteTableSql);
255
+ }
256
+
257
+ return true;
258
+ }
259
+
260
+ /**
261
+ * It's acquire all popup types installed table names
262
+ *
263
+ * @since 1.0.0
264
+ *
265
+ * @return array $popup types table names
266
+ *
267
+ */
268
+ private static function getAllTableNames()
269
+ {
270
+ $tables = array();
271
+ global $SGPB_POPUP_TYPES;
272
+ $popupTypes = $SGPB_POPUP_TYPES['typeName'];
273
+
274
+ if (empty($popupTypes)) {
275
+ return $tables;
276
+ }
277
+
278
+ require_once(SG_POPUP_CONFIG_PATH.'configPackage.php');
279
+
280
+ foreach ($popupTypes as $popupTypeKey => $popupTypeLevel) {
281
+ if (SGPB_POPUP_PKG >= $popupTypeLevel) {
282
+ $className = ucfirst($popupTypeKey).'Popup';
283
+
284
+ if (file_exists(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php')) {
285
+
286
+ require_once(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php');
287
+
288
+ $className = __NAMESPACE__.'\\'.$className;
289
+
290
+ $popupTables = $className::getTableNames();
291
+
292
+ if (empty($popupTables)) {
293
+ continue;
294
+ }
295
+
296
+ foreach ($popupTables as $tableName) {
297
+ $tables[] = $tableName;
298
+ }
299
+ }
300
+ }
301
+
302
+ }
303
+
304
+ return $tables;
305
+ }
306
+
307
+ public static function registerPlugin()
308
+ {
309
+ $pluginName = SG_POPUP_FILE_NAME;
310
+ $classPath = SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php';
311
+ $className = 'SgpbPopupExtension';
312
+ $options = array();
313
+
314
+ if (SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
315
+ $options = array(
316
+ 'licence' => array(
317
+ 'key' => SG_POPUP_KEY,
318
+ 'storeURL' => SG_POPUP_STORE_URL,
319
+ 'file' => SG_POPUP_FILE_NAME,
320
+ 'itemId' => SGPB_ITEM_ID,
321
+ 'itemName' => __('Popup Builder', SG_POPUP_TEXT_DOMAIN),
322
+ 'autor' => SG_POPUP_AUTHOR,
323
+ 'boxLabel' => __('Popup Builder License', SG_POPUP_TEXT_DOMAIN)
324
+ )
325
+ );
326
+ $options = apply_filters('sgpbRegisterOptions', $options);
327
+ }
328
+
329
+ @SgpbPopupExtensionRegister::register($pluginName, $classPath, $className, $options);
330
+ }
331
+ }
com/classes/Javascript.php CHANGED
@@ -1,133 +1,133 @@
1
- <?php
2
- namespace sgpb;
3
- /**
4
- * Popup Builder Style
5
- *
6
- * @since 2.5.6
7
- *
8
- * detect and include popup styles to the admin pages
9
- *
10
- */
11
- class Javascript
12
- {
13
- public static function enqueueScripts($hook)
14
- {
15
- global $wp_version;
16
- $pageName = $hook;
17
- $scripts = array();
18
- $popupType = AdminHelper::getCurrentPopupType();
19
- $currentPostType = AdminHelper::getCurrentPostType();
20
-
21
- if($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
22
- $pageName = 'popupType';
23
- }
24
- else if(($hook == 'post-new.php' || $hook == 'post.php') && $currentPostType == SG_POPUP_POST_TYPE) {
25
- $pageName = 'editpage';
26
- }
27
- else if($hook == 'edit.php' && !empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
28
- $pageName = 'popupspage';
29
- }
30
- else if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SUBSCRIBERS_PAGE) {
31
- $pageName = SG_POPUP_SUBSCRIBERS_PAGE;
32
- }
33
-
34
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
35
-
36
- if(!$registeredPlugins) {
37
- return;
38
- }
39
- $registeredPlugins = json_decode($registeredPlugins, true);
40
-
41
- if(empty($registeredPlugins)) {
42
- return;
43
- }
44
-
45
- wp_enqueue_media();
46
-
47
- foreach($registeredPlugins as $pluginName => $pluginData) {
48
-
49
- if (!is_plugin_active($pluginName)) {
50
- continue;
51
- }
52
-
53
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
54
- continue;
55
- }
56
- $classPath = $pluginData['classPath'];
57
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
58
-
59
- if (!file_exists($classPath)) {
60
- continue;
61
- }
62
-
63
- require_once($classPath);
64
-
65
- if (!class_exists($pluginData['className'])) {
66
- continue;
67
- }
68
-
69
- $classObj = new $pluginData['className']();
70
-
71
- if(!$classObj instanceof \SgpbIPopupExtension) {
72
- continue;
73
- }
74
- $args = array(
75
- 'popupType' => $popupType
76
- );
77
- $scriptData = $classObj->getScripts($pageName , $args);
78
-
79
- $scripts[] = $scriptData;
80
- }
81
-
82
- if(empty($scripts)) {
83
- return;
84
- }
85
-
86
- foreach($scripts as $script) {
87
- if(empty($script['jsFiles'])) {
88
- continue;
89
- }
90
-
91
- foreach($script['jsFiles'] as $jsFile) {
92
-
93
- if(empty($jsFile['folderUrl'])) {
94
- wp_enqueue_script($jsFile['filename']);
95
- continue;
96
- }
97
-
98
- $dirUrl = $jsFile['folderUrl'];
99
- $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
100
- $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
101
- $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
102
-
103
- ScriptsIncluder::registerScript($jsFile['filename'], array(
104
- 'dirUrl'=> $dirUrl,
105
- 'dep' => $dep,
106
- 'ver' => $ver,
107
- 'inFooter' => $inFooter
108
- )
109
- );
110
- ScriptsIncluder::enqueueScript($jsFile['filename']);
111
- }
112
-
113
- if(empty($script['localizeData'])) {
114
- continue;
115
- }
116
-
117
- $localizeDatas = $script['localizeData'];
118
-
119
- foreach($localizeDatas as $localizeData) {
120
- if (!is_array($localizeData['data'])) {
121
- $localizeData['data'] = (array)$localizeData['data'];
122
- }
123
- if (version_compare($wp_version, '4.5', '>')){
124
- /* after wp 4.5 version */
125
- ScriptsIncluder::addInlineScripts($localizeData['handle'], 'var '.$localizeData['name'].' = ' .json_encode($localizeData['data']) );
126
- } else {
127
- /* since wp 4.5 version */
128
- ScriptsIncluder::localizeScript($localizeData['handle'], $localizeData['name'], $localizeData['data']);
129
- }
130
- }
131
- }
132
- }
133
- }
1
+ <?php
2
+ namespace sgpb;
3
+ /**
4
+ * Popup Builder Style
5
+ *
6
+ * @since 2.5.6
7
+ *
8
+ * detect and include popup styles to the admin pages
9
+ *
10
+ */
11
+ class Javascript
12
+ {
13
+ public static function enqueueScripts($hook)
14
+ {
15
+ global $wp_version;
16
+ $pageName = $hook;
17
+ $scripts = array();
18
+ $popupType = AdminHelper::getCurrentPopupType();
19
+ $currentPostType = AdminHelper::getCurrentPostType();
20
+
21
+ if($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
22
+ $pageName = 'popupType';
23
+ }
24
+ else if(($hook == 'post-new.php' || $hook == 'post.php') && $currentPostType == SG_POPUP_POST_TYPE) {
25
+ $pageName = 'editpage';
26
+ }
27
+ else if($hook == 'edit.php' && !empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
28
+ $pageName = 'popupspage';
29
+ }
30
+ else if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SUBSCRIBERS_PAGE) {
31
+ $pageName = SG_POPUP_SUBSCRIBERS_PAGE;
32
+ }
33
+
34
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
35
+
36
+ if(!$registeredPlugins) {
37
+ return;
38
+ }
39
+ $registeredPlugins = json_decode($registeredPlugins, true);
40
+
41
+ if(empty($registeredPlugins)) {
42
+ return;
43
+ }
44
+
45
+ wp_enqueue_media();
46
+
47
+ foreach($registeredPlugins as $pluginName => $pluginData) {
48
+
49
+ if (!is_plugin_active($pluginName)) {
50
+ continue;
51
+ }
52
+
53
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
54
+ continue;
55
+ }
56
+ $classPath = $pluginData['classPath'];
57
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
58
+
59
+ if (!file_exists($classPath)) {
60
+ continue;
61
+ }
62
+
63
+ require_once($classPath);
64
+
65
+ if (!class_exists($pluginData['className'])) {
66
+ continue;
67
+ }
68
+
69
+ $classObj = new $pluginData['className']();
70
+
71
+ if(!$classObj instanceof \SgpbIPopupExtension) {
72
+ continue;
73
+ }
74
+ $args = array(
75
+ 'popupType' => $popupType
76
+ );
77
+ $scriptData = $classObj->getScripts($pageName , $args);
78
+
79
+ $scripts[] = $scriptData;
80
+ }
81
+
82
+ if(empty($scripts)) {
83
+ return;
84
+ }
85
+
86
+ foreach($scripts as $script) {
87
+ if(empty($script['jsFiles'])) {
88
+ continue;
89
+ }
90
+
91
+ foreach($script['jsFiles'] as $jsFile) {
92
+
93
+ if(empty($jsFile['folderUrl'])) {
94
+ wp_enqueue_script($jsFile['filename']);
95
+ continue;
96
+ }
97
+
98
+ $dirUrl = $jsFile['folderUrl'];
99
+ $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
100
+ $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
101
+ $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
102
+
103
+ ScriptsIncluder::registerScript($jsFile['filename'], array(
104
+ 'dirUrl'=> $dirUrl,
105
+ 'dep' => $dep,
106
+ 'ver' => $ver,
107
+ 'inFooter' => $inFooter
108
+ )
109
+ );
110
+ ScriptsIncluder::enqueueScript($jsFile['filename']);
111
+ }
112
+
113
+ if(empty($script['localizeData'])) {
114
+ continue;
115
+ }
116
+
117
+ $localizeDatas = $script['localizeData'];
118
+
119
+ foreach($localizeDatas as $localizeData) {
120
+ if (!is_array($localizeData['data'])) {
121
+ $localizeData['data'] = (array)$localizeData['data'];
122
+ }
123
+ if (version_compare($wp_version, '4.5', '>')){
124
+ /* after wp 4.5 version */
125
+ ScriptsIncluder::addInlineScripts($localizeData['handle'], 'var '.$localizeData['name'].' = ' .json_encode($localizeData['data']).';' );
126
+ } else {
127
+ /* since wp 4.5 version */
128
+ ScriptsIncluder::localizeScript($localizeData['handle'], $localizeData['name'], $localizeData['data']);
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
com/classes/MediaButton.php CHANGED
@@ -1,114 +1,114 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class MediaButton
5
- {
6
- private $hideMediaButton = true;
7
-
8
- public function __toString()
9
- {
10
- return $this->render();
11
- }
12
-
13
- public function __construct($hideMediaButton = true)
14
- {
15
- $this->hideMediaButton = $hideMediaButton;
16
- }
17
-
18
- public static function allowToShow()
19
- {
20
- global $pagenow, $typenow;
21
-
22
- $allowToShow = false;
23
- $pages = array(
24
- 'page.php',
25
- 'post-new.php',
26
- 'post-edit.php',
27
- 'widgets.php'
28
- );
29
-
30
- $checkPage = in_array(
31
- $pagenow,
32
- $pages
33
- );
34
-
35
- // for show in plugins page when package is pro
36
- if (SGPB_POPUP_PKG !== SGPB_POPUP_PKG_FREE) {
37
- array_push($pages, 'post.php');
38
- }
39
-
40
- return ($pages && $typenow != 'download');
41
- }
42
-
43
- private function allowToShowJsVariable()
44
- {
45
- return get_post_type() == SG_POPUP_POST_TYPE;
46
- }
47
-
48
- public function render()
49
- {
50
- if (!$this->hideMediaButton && $this->allowToShowJsVariable()) {
51
- return '';
52
- }
53
- $output = $this->mediaButton();
54
- $output .= $this->insertJsVariable();
55
-
56
- return $output;
57
- }
58
-
59
- private function insertJsVariable()
60
- {
61
- if (!$this->allowToShowJsVariable()){
62
- return '';
63
- }
64
-
65
- $buttonTitle = __('Insert custom JS variable', SG_POPUP_TEXT_DOMAIN);
66
- ob_start();
67
- @include(SG_POPUP_VIEWS_PATH.'jsVariableView.php');
68
- $jsVariableContent = ob_get_contents();
69
- ob_end_clean();
70
-
71
- $img = '<span class="dashicons dashicons-welcome-widgets-menus" style="padding: 3px 2px 0px 0px"></span>';
72
- $output = '<a data-id="sgpb-js-variable-wrapper" href="javascript:void(0);" class="button sgpb-insert-js-variable" title="'.$buttonTitle.'" style="padding-left: .4em;">'. $img.$buttonTitle.'</a>';
73
- if (!$this->hideMediaButton) {
74
- $output = '';
75
- }
76
-
77
- return $output.$jsVariableContent;
78
- }
79
-
80
- private function mediaButton()
81
- {
82
- $allowToShow = MediaButton::allowToShow();
83
- if (!$allowToShow) {
84
- $output = '';
85
- return $output;
86
- }
87
- $currentPostType = AdminHelper::getCurrentPostType();
88
- if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
89
- add_action('admin_footer', function() {
90
- require_once(SG_POPUP_VIEWS_PATH.'htmlCustomButtonElement.php');
91
- });
92
- }
93
-
94
- ob_start();
95
- @include(SG_POPUP_VIEWS_PATH.'mediaButton.php');
96
- $mediaButtonContent = ob_get_contents();
97
- ob_end_clean();
98
-
99
- $showCurrentUser = AdminHelper::showMenuForCurrentUser();
100
-
101
- if (!$showCurrentUser) {
102
- return '';
103
- }
104
- $buttonTitle = __('Insert popup', SG_POPUP_TEXT_DOMAIN);
105
-
106
- $img = '<span class="dashicons dashicons-welcome-widgets-menus" style="padding: 3px 2px 0px 0px"></span>';
107
- $output = '<a data-id="sgpb-hidden-media-popup" href="javascript:void(0);" class="button sgpb-insert-media-button-js" title="'.$buttonTitle.'" style="padding-left: .4em;">'. $img.$buttonTitle.'</a>';
108
- if (!$this->hideMediaButton) {
109
- $output = '';
110
- }
111
-
112
- return $output.$mediaButtonContent;
113
- }
114
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class MediaButton
5
+ {
6
+ private $hideMediaButton = true;
7
+
8
+ public function __toString()
9
+ {
10
+ return $this->render();
11
+ }
12
+
13
+ public function __construct($hideMediaButton = true)
14
+ {
15
+ $this->hideMediaButton = $hideMediaButton;
16
+ }
17
+
18
+ public static function allowToShow()
19
+ {
20
+ global $pagenow, $typenow;
21
+
22
+ $allowToShow = false;
23
+ $pages = array(
24
+ 'page.php',
25
+ 'post-new.php',
26
+ 'post-edit.php',
27
+ 'widgets.php'
28
+ );
29
+
30
+ $checkPage = in_array(
31
+ $pagenow,
32
+ $pages
33
+ );
34
+
35
+ // for show in plugins page when package is pro
36
+ if (SGPB_POPUP_PKG !== SGPB_POPUP_PKG_FREE) {
37
+ array_push($pages, 'post.php');
38
+ }
39
+
40
+ return ($pages && $typenow != 'download');
41
+ }
42
+
43
+ private function allowToShowJsVariable()
44
+ {
45
+ return get_post_type() == SG_POPUP_POST_TYPE;
46
+ }
47
+
48
+ public function render()
49
+ {
50
+ if (!$this->hideMediaButton && $this->allowToShowJsVariable()) {
51
+ return '';
52
+ }
53
+ $output = $this->mediaButton();
54
+ $output .= $this->insertJsVariable();
55
+
56
+ return $output;
57
+ }
58
+
59
+ private function insertJsVariable()
60
+ {
61
+ if (!$this->allowToShowJsVariable()){
62
+ return '';
63
+ }
64
+
65
+ $buttonTitle = __('Insert custom JS variable', SG_POPUP_TEXT_DOMAIN);
66
+ ob_start();
67
+ @include(SG_POPUP_VIEWS_PATH.'jsVariableView.php');
68
+ $jsVariableContent = ob_get_contents();
69
+ ob_end_clean();
70
+
71
+ $img = '<span class="dashicons dashicons-welcome-widgets-menus" style="padding: 3px 2px 0px 0px"></span>';
72
+ $output = '<a data-id="sgpb-js-variable-wrapper" href="javascript:void(0);" class="button sgpb-insert-js-variable" title="'.$buttonTitle.'" style="padding-left: .4em;">'. $img.$buttonTitle.'</a>';
73
+ if (!$this->hideMediaButton) {
74
+ $output = '';
75
+ }
76
+
77
+ return $output.$jsVariableContent;
78
+ }
79
+
80
+ private function mediaButton()
81
+ {
82
+ $allowToShow = MediaButton::allowToShow();
83
+ if (!$allowToShow) {
84
+ $output = '';
85
+ return $output;
86
+ }
87
+ $currentPostType = AdminHelper::getCurrentPostType();
88
+ if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
89
+ add_action('admin_footer', function() {
90
+ require_once(SG_POPUP_VIEWS_PATH.'htmlCustomButtonElement.php');
91
+ });
92
+ }
93
+
94
+ ob_start();
95
+ @include(SG_POPUP_VIEWS_PATH.'mediaButton.php');
96
+ $mediaButtonContent = ob_get_contents();
97
+ ob_end_clean();
98
+
99
+ $showCurrentUser = AdminHelper::showMenuForCurrentUser();
100
+
101
+ if (!$showCurrentUser) {
102
+ return '';
103
+ }
104
+ $buttonTitle = __('Insert popup', SG_POPUP_TEXT_DOMAIN);
105
+
106
+ $img = '<span class="dashicons dashicons-welcome-widgets-menus" style="padding: 3px 2px 0px 0px"></span>';
107
+ $output = '<a data-id="sgpb-hidden-media-popup" href="javascript:void(0);" class="button sgpb-insert-media-button-js" title="'.$buttonTitle.'" style="padding-left: .4em;">'. $img.$buttonTitle.'</a>';
108
+ if (!$this->hideMediaButton) {
109
+ $output = '';
110
+ }
111
+
112
+ return $output.$mediaButtonContent;
113
+ }
114
+ }
com/classes/Notification.php CHANGED
@@ -1,94 +1,94 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class Notification
5
- {
6
- public $id;
7
- public $type;// notification, warning etc.
8
- public $priority;
9
- public $message;
10
-
11
- public function setId($id)
12
- {
13
- $this->id = $id;
14
- }
15
-
16
- public function getId()
17
- {
18
- return $this->id;
19
- }
20
-
21
- public function setType($type)
22
- {
23
- $this->type = $type;
24
- }
25
-
26
- public function getType()
27
- {
28
- return $this->type;
29
- }
30
-
31
- public function setPriority($priority)
32
- {
33
- $this->priority = $priority;
34
- }
35
-
36
- public function getPriority()
37
- {
38
- return $this->priority;
39
- }
40
-
41
- public function setMessage($message)
42
- {
43
- $this->message = $message;
44
- }
45
-
46
- public function getMessage()
47
- {
48
- return $this->message;
49
- }
50
-
51
- public function render()
52
- {
53
- $id = $this->getId();
54
- $type = $this->getType();
55
- $color = '';
56
- switch ($type) {
57
- case 1:
58
- $color = '#01B9FF !important';
59
- break;
60
- case 2:
61
- $color = '#28a745 !important';
62
- break;
63
- case 3:
64
- $color = '#dc3545 !important';
65
- break;
66
- }
67
-
68
- $style = 'style="border-color:'.$color.';"';
69
- $priority = $this->getPriority();
70
- $message = $this->getMessage();
71
- $btnHtml = $this->getCloseBtnById($id);
72
- $content = '<div class="sgpb-single-notification-wrapper">
73
- <div class="sgpb-single-notification"'.$style.'>
74
- <span class="dashicons dashicons-no-alt sgpb-hide-notification-at-all" data-id="'.$id.'"></span>
75
- '.$message.'
76
- </div>
77
- <div class="sgpb-single-notification-close-btn">
78
- '.$btnHtml.'
79
- </div>
80
- </div>';
81
-
82
- return $content;
83
- }
84
-
85
- public function getCloseBtnById($id)
86
- {
87
- $dismissedNotification = SGPBNotificationCenter::getAllDismissedNotifications();
88
- if (isset($dismissedNotification[$id])) {
89
- return '<button data-id="'.$id.'" class="button dismiss sgpb-activate-notification-js"><span class="dashicons dashicons-hidden"></span></button>';
90
- }
91
-
92
- return '<button data-id="'.$id.'" class="button dismiss sgpb-dismiss-notification-js"><span class="dashicons dashicons-visibility"></span></button>';
93
- }
94
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class Notification
5
+ {
6
+ public $id;
7
+ public $type;// notification, warning etc.
8
+ public $priority;
9
+ public $message;
10
+
11
+ public function setId($id)
12
+ {
13
+ $this->id = $id;
14
+ }
15
+
16
+ public function getId()
17
+ {
18
+ return $this->id;
19
+ }
20
+
21
+ public function setType($type)
22
+ {
23
+ $this->type = $type;
24
+ }
25
+
26
+ public function getType()
27
+ {
28
+ return $this->type;
29
+ }
30
+
31
+ public function setPriority($priority)
32
+ {
33
+ $this->priority = $priority;
34
+ }
35
+
36
+ public function getPriority()
37
+ {
38
+ return $this->priority;
39
+ }
40
+
41
+ public function setMessage($message)
42
+ {
43
+ $this->message = $message;
44
+ }
45
+
46
+ public function getMessage()
47
+ {
48
+ return $this->message;
49
+ }
50
+
51
+ public function render()
52
+ {
53
+ $id = $this->getId();
54
+ $type = $this->getType();
55
+ $color = '';
56
+ switch ($type) {
57
+ case 1:
58
+ $color = '#01B9FF !important';
59
+ break;
60
+ case 2:
61
+ $color = '#28a745 !important';
62
+ break;
63
+ case 3:
64
+ $color = '#dc3545 !important';
65
+ break;
66
+ }
67
+
68
+ $style = 'style="border-color:'.$color.';"';
69
+ $priority = $this->getPriority();
70
+ $message = $this->getMessage();
71
+ $btnHtml = $this->getCloseBtnById($id);
72
+ $content = '<div class="sgpb-single-notification-wrapper">
73
+ <div class="sgpb-single-notification"'.$style.'>
74
+ <span class="dashicons dashicons-no-alt sgpb-hide-notification-at-all" data-id="'.$id.'"></span>
75
+ '.$message.'
76
+ </div>
77
+ <div class="sgpb-single-notification-close-btn">
78
+ '.$btnHtml.'
79
+ </div>
80
+ </div>';
81
+
82
+ return $content;
83
+ }
84
+
85
+ public function getCloseBtnById($id)
86
+ {
87
+ $dismissedNotification = SGPBNotificationCenter::getAllDismissedNotifications();
88
+ if (isset($dismissedNotification[$id])) {
89
+ return '<button data-id="'.$id.'" class="button dismiss sgpb-activate-notification-js"><span class="dashicons dashicons-hidden"></span></button>';
90
+ }
91
+
92
+ return '<button data-id="'.$id.'" class="button dismiss sgpb-dismiss-notification-js"><span class="dashicons dashicons-visibility"></span></button>';
93
+ }
94
+ }
com/classes/NotificationCenter.php CHANGED
@@ -1,292 +1,292 @@
1
- <?php
2
- namespace sgpb;
3
- use sgpb\AdminHelper;
4
-
5
- class SGPBNotificationCenter
6
- {
7
- private $requestUrl = SG_POPUP_BUILDER_NOTIFICATIONS_URL;
8
- private $cronTimeout = 'daily';
9
-
10
- public function __construct()
11
- {
12
- $this->addActions();
13
- $this->activateCron();
14
- }
15
-
16
- public function addActions()
17
- {
18
- add_filter('sgpbCronTimeoutSettings', array($this, 'cronAddMinutes'), 10, 1);
19
- add_action('sgpbGetNotifications', array($this, 'updateNotificationsArray'));
20
- add_action('wp_ajax_sgpb_dismiss_notification', array($this, 'dismissNotification'));
21
- add_action('wp_ajax_sgpb_remove_notification', array($this, 'removeNotification'));
22
- add_action('wp_ajax_sgpb_reactivate_notification', array($this, 'reactivateNotification'));
23
- add_action('admin_head', array($this, 'menuItemCounter'));
24
- }
25
-
26
- public function menuItemCounter()
27
- {
28
- $count = count(self::getAllActiveNotifications(true));
29
- $hidden = '';
30
- if (empty($count)) {
31
- $hidden = ' sgpb-hide-add-button';
32
- }
33
- echo "<script>
34
- jQuery(document).ready(function() {
35
- jQuery('.sgpb-menu-item-notification').remove();
36
- jQuery('.dashicons-menu-icon-sgpb').next().append('<span class=\"sgpb-menu-item-notification".$hidden."\">".$count."</span>');
37
- });
38
- </script>";
39
- }
40
-
41
- public function setCronTimeout($cronTimeout)
42
- {
43
- $this->cronTimeout = $cronTimeout;
44
- }
45
-
46
- public function getCronTimeout()
47
- {
48
- return $this->cronTimeout;
49
- }
50
-
51
- public function setRequestUrl($requestUrl)
52
- {
53
- $this->requestUrl = $requestUrl;
54
- }
55
-
56
- public function getRequestUrl()
57
- {
58
- return $this->requestUrl;
59
- }
60
-
61
- public function updateNotificationsArray()
62
- {
63
- $requestUrl = $this->getRequestUrl();
64
- $content = AdminHelper::getFileFromURL($requestUrl);
65
- $content = json_decode($content, true);
66
- $content = apply_filters('sgpbExtraNotifications', $content);
67
- // check later
68
- /*if (empty($content)) {
69
- update_option('sgpb-all-dismissed-notifications', array());
70
- }*/
71
- $content = json_encode($content);
72
- update_option('sgpb-all-notifications-data', $content);
73
- }
74
-
75
- public function sortNotifications($allNotifications)
76
- {
77
- $allNotifications = json_decode($allNotifications, true);
78
- if (empty($allNotifications)) {
79
- $allNotifications = array();
80
- }
81
- $dismissed = self::getAllDismissedNotifications();
82
- // for the first time dismissed and active arrays should be empty
83
- if (empty($dismissed) && empty($active)) {
84
- $notifications = array();
85
- foreach ($allNotifications as $notification) {
86
- $id = $notification['id'];
87
- $notifications[$id] = $id;
88
- }
89
- update_option('sgpb-all-active-notifications', json_encode($notifications));
90
- }
91
- }
92
-
93
- public function cronAddMinutes($schedules)
94
- {
95
- $schedules['sgpb_notifications'] = array(
96
- 'interval' => SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL * 3600,
97
- 'display' => __('Twice Daily', SG_POPUP_TEXT_DOMAIN)
98
- );
99
-
100
- return $schedules;
101
- }
102
-
103
- public static function getAllActiveNotifications($hideDismissed = false)
104
- {
105
- $activeNotifications = array();
106
- $notifications = get_option('sgpb-all-notifications-data');
107
- $notifications = json_decode($notifications, true);
108
- if (empty($notifications)) {
109
- return array();
110
- }
111
- asort($notifications);
112
-
113
- $dismissedNotifications = get_option('sgpb-all-dismissed-notifications');
114
- $dismissedNotifications = json_decode($dismissedNotifications, true);
115
- $extensions = AdminHelper::getAllExtensions();
116
- $extensionsKeys = wp_list_pluck($extensions['active'], 'key');
117
- foreach ($notifications as $notification) {
118
- $id = @$notification['id'];
119
-
120
- if (isset($notification['hideFor'])) {
121
- $hideForExtensions = explode(',', $notification['hideFor']);
122
- $arraysIntersect = array_intersect($extensionsKeys, $hideForExtensions);
123
-
124
- // If only one condition -> free, single extension, bundle
125
- if (count($hideForExtensions) == 1) {
126
- // Free
127
- if ($notification['hideFor'] == SGPB_POPUP_PKG_FREE && empty($extensionsKeys) && !class_exists('SGPBActivatorPlugin')) {
128
- continue;
129
- }
130
- // Single extension
131
- else if (in_array($notification['hideFor'], $extensionsKeys)) {
132
- continue;
133
- }
134
- // Pro, if it is a free user
135
- else if ($notification['hideFor'] == 'pro' && count($extensionsKeys) >= 1) {
136
- continue;
137
- }
138
- // Bundle
139
- else if ($notification['hideFor'] == 'bundle') {
140
- if (class_exists('SGPBActivatorPlugin') || count($extensionsKeys) >= 10) {
141
- continue;
142
- }
143
- }
144
- }
145
- // if there is even one detected extension, don’t show notification
146
- else if (count($arraysIntersect) > 0) {
147
- continue;
148
- }
149
- }
150
-
151
- if ($hideDismissed && isset($dismissedNotifications[$id])) {
152
- continue;
153
- }
154
-
155
- $activeNotifications[] = $notification;
156
- }
157
- $removedNotifications = get_option('sgpb-all-removed-notifications');
158
- $removedNotifications = json_decode($removedNotifications, true);
159
- if (empty($removedNotifications)) {
160
- return $activeNotifications;
161
- }
162
- foreach ($removedNotifications as $removedNotificationId) {
163
- foreach ($activeNotifications as $key => $activeNotification) {
164
- if ($activeNotification['id'] == $removedNotificationId) {
165
- unset($activeNotifications[$key]);
166
- }
167
- }
168
- }
169
-
170
- return $activeNotifications;
171
- }
172
-
173
- public static function getAllDismissedNotifications()
174
- {
175
- $notifications = get_option('sgpb-all-dismissed-notifications');
176
- if (empty($notifications)) {
177
- $notifications = '';
178
- }
179
-
180
- return json_decode($notifications, true);
181
- }
182
-
183
- public static function getAllRemovedNotifications()
184
- {
185
- $notifications = get_option('sgpb-all-removed-notifications');
186
- if (empty($notifications)) {
187
- $notifications = '';
188
- }
189
-
190
- return json_decode($notifications, true);
191
- }
192
-
193
- public static function displayNotifications($withoutWrapper = false)
194
- {
195
- $content = '';
196
- $allNotifications = self::getAllActiveNotifications();
197
- if (empty($allNotifications)) {
198
- return $content;
199
- }
200
-
201
- $count = count(self::getAllActiveNotifications(true));
202
-
203
- foreach ($allNotifications as $notification) {
204
- $newNotification = new Notification();
205
- $newNotification->setId($notification['id']);
206
- $newNotification->setType($notification['type']);
207
- $newNotification->setPriority($notification['priority']);
208
- $newNotification->setMessage($notification['message']);
209
- $content .= $newNotification->render();
210
- }
211
- $count = '(<span class="sgpb-notifications-count-span">'.$count.'</span>)';
212
-
213
- if ($withoutWrapper) {
214
- return $content;
215
- }
216
-
217
- $content = self::prepareHtml($content, $count);
218
-
219
- return $content;
220
- }
221
-
222
- public static function prepareHtml($content = '', $count = 0)
223
- {
224
- $content = '<div class="sgpb-each-notification-wrapper-js">'.$content.'</div>';
225
- $content = '<div class="sgpb-notification-center-wrapper">
226
- <h3><span class="dashicons dashicons-flag"></span> Notifications '.$count.'</h3>'.$content.'
227
- </div>';
228
-
229
- return $content;
230
- }
231
-
232
- public function dismissNotification()
233
- {
234
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
235
-
236
- $notificationId = sanitize_text_field($_POST['id']);
237
- $allDismissedNotifications = self::getAllDismissedNotifications();
238
- $allDismissedNotifications[$notificationId] = $notificationId;
239
- $allDismissedNotifications = json_encode($allDismissedNotifications);
240
-
241
- update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
242
- $result = array();
243
- $result['content'] = self::displayNotifications(true);
244
- $result['count'] = count(self::getAllActiveNotifications(true));
245
-
246
- echo json_encode($result);
247
- wp_die();
248
- }
249
-
250
- public function removeNotification()
251
- {
252
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
253
-
254
- $notificationId = sanitize_text_field($_POST['id']);
255
- $allRemovedNotifications = self::getAllRemovedNotifications();
256
- $allRemovedNotifications[$notificationId] = $notificationId;
257
- $allRemovedNotifications = json_encode($allRemovedNotifications);
258
-
259
- update_option('sgpb-all-removed-notifications', $allRemovedNotifications);
260
-
261
- wp_die(true);
262
- }
263
-
264
- public function reactivateNotification()
265
- {
266
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
267
-
268
- $notificationId = sanitize_text_field($_POST['id']);
269
- $allDismissedNotifications = self::getAllDismissedNotifications();
270
- if (isset($allDismissedNotifications[$notificationId])) {
271
- unset($allDismissedNotifications[$notificationId]);
272
- }
273
- $allDismissedNotifications = json_encode($allDismissedNotifications);
274
-
275
- update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
276
- $result = array();
277
- $result['content'] = self::displayNotifications(true);
278
- $result['count'] = count(self::getAllActiveNotifications(true));
279
-
280
- echo json_encode($result);
281
- wp_die();
282
- }
283
-
284
- public function activateCron()
285
- {
286
- if (!wp_next_scheduled('sgpbGetNotifications')) {
287
- wp_schedule_event(time(), 'daily', 'sgpbGetNotifications');
288
- }
289
- }
290
- }
291
-
292
- new SGPBNotificationCenter();
1
+ <?php
2
+ namespace sgpb;
3
+ use sgpb\AdminHelper;
4
+
5
+ class SGPBNotificationCenter
6
+ {
7
+ private $requestUrl = SG_POPUP_BUILDER_NOTIFICATIONS_URL;
8
+ private $cronTimeout = 'daily';
9
+
10
+ public function __construct()
11
+ {
12
+ $this->addActions();
13
+ $this->activateCron();
14
+ }
15
+
16
+ public function addActions()
17
+ {
18
+ add_filter('sgpbCronTimeoutSettings', array($this, 'cronAddMinutes'), 10, 1);
19
+ add_action('sgpbGetNotifications', array($this, 'updateNotificationsArray'));
20
+ add_action('wp_ajax_sgpb_dismiss_notification', array($this, 'dismissNotification'));
21
+ add_action('wp_ajax_sgpb_remove_notification', array($this, 'removeNotification'));
22
+ add_action('wp_ajax_sgpb_reactivate_notification', array($this, 'reactivateNotification'));
23
+ add_action('admin_head', array($this, 'menuItemCounter'));
24
+ }
25
+
26
+ public function menuItemCounter()
27
+ {
28
+ $count = count(self::getAllActiveNotifications(true));
29
+ $hidden = '';
30
+ if (empty($count)) {
31
+ $hidden = ' sgpb-hide-add-button';
32
+ }
33
+ echo "<script>
34
+ jQuery(document).ready(function() {
35
+ jQuery('.sgpb-menu-item-notification').remove();
36
+ jQuery('.dashicons-menu-icon-sgpb').next().append('<span class=\"sgpb-menu-item-notification".$hidden."\">".$count."</span>');
37
+ });
38
+ </script>";
39
+ }
40
+
41
+ public function setCronTimeout($cronTimeout)
42
+ {
43
+ $this->cronTimeout = $cronTimeout;
44
+ }
45
+
46
+ public function getCronTimeout()
47
+ {
48
+ return $this->cronTimeout;
49
+ }
50
+
51
+ public function setRequestUrl($requestUrl)
52
+ {
53
+ $this->requestUrl = $requestUrl;
54
+ }
55
+
56
+ public function getRequestUrl()
57
+ {
58
+ return $this->requestUrl;
59
+ }
60
+
61
+ public function updateNotificationsArray()
62
+ {
63
+ $requestUrl = $this->getRequestUrl();
64
+ $content = AdminHelper::getFileFromURL($requestUrl);
65
+ $content = json_decode($content, true);
66
+ $content = apply_filters('sgpbExtraNotifications', $content);
67
+ // check later
68
+ /*if (empty($content)) {
69
+ update_option('sgpb-all-dismissed-notifications', array());
70
+ }*/
71
+ $content = json_encode($content);
72
+ update_option('sgpb-all-notifications-data', $content);
73
+ }
74
+
75
+ public function sortNotifications($allNotifications)
76
+ {
77
+ $allNotifications = json_decode($allNotifications, true);
78
+ if (empty($allNotifications)) {
79
+ $allNotifications = array();
80
+ }
81
+ $dismissed = self::getAllDismissedNotifications();
82
+ // for the first time dismissed and active arrays should be empty
83
+ if (empty($dismissed) && empty($active)) {
84
+ $notifications = array();
85
+ foreach ($allNotifications as $notification) {
86
+ $id = $notification['id'];
87
+ $notifications[$id] = $id;
88
+ }
89
+ update_option('sgpb-all-active-notifications', json_encode($notifications));
90
+ }
91
+ }
92
+
93
+ public function cronAddMinutes($schedules)
94
+ {
95
+ $schedules['sgpb_notifications'] = array(
96
+ 'interval' => SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL * 3600,
97
+ 'display' => __('Twice Daily', SG_POPUP_TEXT_DOMAIN)
98
+ );
99
+
100
+ return $schedules;
101
+ }
102
+
103
+ public static function getAllActiveNotifications($hideDismissed = false)
104
+ {
105
+ $activeNotifications = array();
106
+ $notifications = get_option('sgpb-all-notifications-data');
107
+ $notifications = json_decode($notifications, true);
108
+ if (empty($notifications)) {
109
+ return array();
110
+ }
111
+ asort($notifications);
112
+
113
+ $dismissedNotifications = get_option('sgpb-all-dismissed-notifications');
114
+ $dismissedNotifications = json_decode($dismissedNotifications, true);
115
+ $extensions = AdminHelper::getAllExtensions();
116
+ $extensionsKeys = wp_list_pluck($extensions['active'], 'key');
117
+ foreach ($notifications as $notification) {
118
+ $id = @$notification['id'];
119
+
120
+ if (isset($notification['hideFor'])) {
121
+ $hideForExtensions = explode(',', $notification['hideFor']);
122
+ $arraysIntersect = array_intersect($extensionsKeys, $hideForExtensions);
123
+
124
+ // If only one condition -> free, single extension, bundle
125
+ if (count($hideForExtensions) == 1) {
126
+ // Free
127
+ if ($notification['hideFor'] == SGPB_POPUP_PKG_FREE && empty($extensionsKeys) && !class_exists('SGPBActivatorPlugin')) {
128
+ continue;
129
+ }
130
+ // Single extension
131
+ else if (in_array($notification['hideFor'], $extensionsKeys)) {
132
+ continue;
133
+ }
134
+ // Pro, if it is a free user
135
+ else if ($notification['hideFor'] == 'pro' && count($extensionsKeys) >= 1) {
136
+ continue;
137
+ }
138
+ // Bundle
139
+ else if ($notification['hideFor'] == 'bundle') {
140
+ if (class_exists('SGPBActivatorPlugin') || count($extensionsKeys) >= 10) {
141
+ continue;
142
+ }
143
+ }
144
+ }
145
+ // if there is even one detected extension, don’t show notification
146
+ else if (count($arraysIntersect) > 0) {
147
+ continue;
148
+ }
149
+ }
150
+
151
+ if ($hideDismissed && isset($dismissedNotifications[$id])) {
152
+ continue;
153
+ }
154
+
155
+ $activeNotifications[] = $notification;
156
+ }
157
+ $removedNotifications = get_option('sgpb-all-removed-notifications');
158
+ $removedNotifications = json_decode($removedNotifications, true);
159
+ if (empty($removedNotifications)) {
160
+ return $activeNotifications;
161
+ }
162
+ foreach ($removedNotifications as $removedNotificationId) {
163
+ foreach ($activeNotifications as $key => $activeNotification) {
164
+ if ($activeNotification['id'] == $removedNotificationId) {
165
+ unset($activeNotifications[$key]);
166
+ }
167
+ }
168
+ }
169
+
170
+ return $activeNotifications;
171
+ }
172
+
173
+ public static function getAllDismissedNotifications()
174
+ {
175
+ $notifications = get_option('sgpb-all-dismissed-notifications');
176
+ if (empty($notifications)) {
177
+ $notifications = '';
178
+ }
179
+
180
+ return json_decode($notifications, true);
181
+ }
182
+
183
+ public static function getAllRemovedNotifications()
184
+ {
185
+ $notifications = get_option('sgpb-all-removed-notifications');
186
+ if (empty($notifications)) {
187
+ $notifications = '';
188
+ }
189
+
190
+ return json_decode($notifications, true);
191
+ }
192
+
193
+ public static function displayNotifications($withoutWrapper = false)
194
+ {
195
+ $content = '';
196
+ $allNotifications = self::getAllActiveNotifications();
197
+ if (empty($allNotifications)) {
198
+ return $content;
199
+ }
200
+
201
+ $count = count(self::getAllActiveNotifications(true));
202
+
203
+ foreach ($allNotifications as $notification) {
204
+ $newNotification = new Notification();
205
+ $newNotification->setId($notification['id']);
206
+ $newNotification->setType($notification['type']);
207
+ $newNotification->setPriority($notification['priority']);
208
+ $newNotification->setMessage($notification['message']);
209
+ $content .= $newNotification->render();
210
+ }
211
+ $count = '(<span class="sgpb-notifications-count-span">'.$count.'</span>)';
212
+
213
+ if ($withoutWrapper) {
214
+ return $content;
215
+ }
216
+
217
+ $content = self::prepareHtml($content, $count);
218
+
219
+ return $content;
220
+ }
221
+
222
+ public static function prepareHtml($content = '', $count = 0)
223
+ {
224
+ $content = '<div class="sgpb-each-notification-wrapper-js">'.$content.'</div>';
225
+ $content = '<div class="sgpb-notification-center-wrapper">
226
+ <h3><span class="dashicons dashicons-flag"></span> Notifications '.$count.'</h3>'.$content.'
227
+ </div>';
228
+
229
+ return $content;
230
+ }
231
+
232
+ public function dismissNotification()
233
+ {
234
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
235
+
236
+ $notificationId = sanitize_text_field($_POST['id']);
237
+ $allDismissedNotifications = self::getAllDismissedNotifications();
238
+ $allDismissedNotifications[$notificationId] = $notificationId;
239
+ $allDismissedNotifications = json_encode($allDismissedNotifications);
240
+
241
+ update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
242
+ $result = array();
243
+ $result['content'] = self::displayNotifications(true);
244
+ $result['count'] = count(self::getAllActiveNotifications(true));
245
+
246
+ echo json_encode($result);
247
+ wp_die();
248
+ }
249
+
250
+ public function removeNotification()
251
+ {
252
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
253
+
254
+ $notificationId = sanitize_text_field($_POST['id']);
255
+ $allRemovedNotifications = self::getAllRemovedNotifications();
256
+ $allRemovedNotifications[$notificationId] = $notificationId;
257
+ $allRemovedNotifications = json_encode($allRemovedNotifications);
258
+
259
+ update_option('sgpb-all-removed-notifications', $allRemovedNotifications);
260
+
261
+ wp_die(true);
262
+ }
263
+
264
+ public function reactivateNotification()
265
+ {
266
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
267
+
268
+ $notificationId = sanitize_text_field($_POST['id']);
269
+ $allDismissedNotifications = self::getAllDismissedNotifications();
270
+ if (isset($allDismissedNotifications[$notificationId])) {
271
+ unset($allDismissedNotifications[$notificationId]);
272
+ }
273
+ $allDismissedNotifications = json_encode($allDismissedNotifications);
274
+
275
+ update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
276
+ $result = array();
277
+ $result['content'] = self::displayNotifications(true);
278
+ $result['count'] = count(self::getAllActiveNotifications(true));
279
+
280
+ echo json_encode($result);
281
+ wp_die();
282
+ }
283
+
284
+ public function activateCron()
285
+ {
286
+ if (!wp_next_scheduled('sgpbGetNotifications')) {
287
+ wp_schedule_event(time(), 'daily', 'sgpbGetNotifications');
288
+ }
289
+ }
290
+ }
291
+
292
+ new SGPBNotificationCenter();
com/classes/PopupChecker.php CHANGED
@@ -1,673 +1,673 @@
1
- <?php
2
- namespace sgpb;
3
- use \DateTime;
4
- use \DateTimeZone;
5
- use \ConfigDataHelper;
6
-
7
- /**
8
- * Popup checker class to check if the popup must be loaded on the current page
9
- *
10
- * @since 1.0.0
11
- *
12
- */
13
- class PopupChecker
14
- {
15
- private static $instance;
16
- private $popup;
17
- private $isGeoAjaxModeEnabled;
18
- private $post;
19
- private $isAjaxCall;
20
-
21
- public static function instance()
22
- {
23
- if (!isset(self::$instance)) {
24
- self::$instance = new self;
25
- }
26
-
27
- return self::$instance;
28
- }
29
-
30
- public function setPopup($popup)
31
- {
32
- $this->popup = $popup;
33
- }
34
-
35
- public function getPopup()
36
- {
37
- return $this->popup;
38
- }
39
-
40
- public function setPost($post)
41
- {
42
- $this->post = $post;
43
- }
44
-
45
- public function getPost()
46
- {
47
- return $this->post;
48
- }
49
-
50
- public function setPopupGeoAjaxModeActive($ajaxMode)
51
- {
52
- $this->isGeoAjaxModeEnabled = $ajaxMode;
53
- }
54
-
55
- public function getPopupGeoAjaxMode()
56
- {
57
- return $this->isGeoAjaxModeEnabled;
58
- }
59
-
60
- public function setIsAjaxCall($isAjax)
61
- {
62
- $this->isAjaxCall = $isAjax;
63
- }
64
-
65
- public function getIsAjaxCall()
66
- {
67
- return $this->isAjaxCall;
68
- }
69
-
70
- /**
71
- * It checks whether popup should be loaded on the current page.
72
- *
73
- * @since 1.0.0
74
- *
75
- * @param int $popupId popup id
76
- * @param object $post page post data
77
- * @param boolean $isAjax
78
- *
79
- * @return bool
80
- *
81
- */
82
- public function isLoadable($popup, $post, $isAjax = false)
83
- {
84
- $this->setPopup($popup);
85
- $this->setPost($post);
86
-
87
- $this->setPopupGeoAjaxModeActive($popup->getOptionValue('sgpb-enable-geo-ajax-mode'));
88
- $this->setIsAjaxCall($isAjax);
89
-
90
- $popupOptions = $popup->getOptions();
91
- $isActive = $popup->getOptionValue('sgpb-is-active', true);
92
- $saveMode = $popup->getSaveMode();
93
- $allowToLoad = $this->allowToLoad();
94
-
95
- if ($saveMode) {
96
- $allowToLoad['option_event'] = false;
97
- return $allowToLoad;
98
- }
99
-
100
- if (isset($popupOptions['sgpb-is-active'])) {
101
- $isActive = $popupOptions['sgpb-is-active'];
102
- if ($isActive) {
103
- $popup->setReportData($popup->getId());
104
- }
105
- }
106
-
107
- if (!$isActive) {
108
- $allowToLoad['option_event'] = false;
109
- }
110
-
111
- return $allowToLoad;
112
- }
113
-
114
- /**
115
- * Decides whether popup data should be loaded or not
116
- *
117
- * @since 1.0.0
118
- *
119
- * @return array
120
- *
121
- */
122
- private function allowToLoad()
123
- {
124
- $isCustomInserted = $this->isCustomInserted();
125
-
126
- $insertedModes = array(
127
- 'attr_event' => false,
128
- 'option_event' => false
129
- );
130
-
131
- if ($isCustomInserted) {
132
- $insertedModes['attr_event'] = true;
133
- }
134
-
135
- $target = $this->divideTargetData();
136
- $isPostInForbidden = $this->isPostInForbidden($target);
137
-
138
- if ($isPostInForbidden) {
139
- return $insertedModes;
140
- }
141
-
142
- if (!empty($target['forbidden']) && empty($target['permissive'])) {
143
- $conditions = $this->divideConditionsData();
144
- $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
145
- $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
146
-
147
- if ($isSatisfyForConditions === false) {
148
- return $insertedModes;
149
- }
150
- if ($this->isSatisfyForOtherConditions() === false) {
151
- return $insertedModes;
152
- }
153
- $insertedModes['option_event'] = true;
154
- }
155
-
156
- $isPermissive = $this->isPermissive($target);
157
-
158
- //If permissive for current page check conditions
159
- if ($isPermissive) {
160
- $conditions = $this->divideConditionsData();
161
- $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
162
- $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
163
-
164
- if ($isSatisfyForConditions === false) {
165
- return $insertedModes;
166
- }
167
- if ($this->isSatisfyForOtherConditions() === false) {
168
- return $insertedModes;
169
- }
170
- $insertedModes['option_event'] = $isPermissive;
171
- }
172
-
173
- return $insertedModes;
174
- }
175
-
176
- /**
177
- * check is Satisfy popup conditions
178
- *
179
- * @since 1.0.0
180
- *
181
- * @param array $conditions assoc array
182
- *
183
- * @return bool
184
- *
185
- */
186
- private function isSatisfyForConditions($conditions)
187
- {
188
- // proStartSilver
189
- // this case when selected IS NOT operator
190
- $forbiddenConditions = $conditions['forbidden'];
191
- if (!empty($forbiddenConditions)) {
192
- if (!$this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
193
- return false;
194
- }
195
- foreach ($forbiddenConditions as $forbiddenCondition) {
196
- $isForbiddenConditions = $this->isSatisfyForConditionsOptions($forbiddenCondition);
197
- if ($isForbiddenConditions) {
198
- return false;
199
- } else {
200
- return true;
201
- }
202
- }
203
- }
204
-
205
- // this case when selected IS operator
206
- $permissiveOptions = $conditions['permissive'];
207
- if (!empty($permissiveOptions)) {
208
- if (!$this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
209
- return false;
210
- }
211
- foreach ($permissiveOptions as $permissiveOption) {
212
- $isPermissiveConditions = $this->isSatisfyForConditionsOptions($permissiveOption);
213
- return $isPermissiveConditions;
214
- }
215
- }
216
- if ($this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
217
- return false;
218
- }
219
- return true;
220
- }
221
-
222
- private function isSatisfyForConditionsOptions($option)
223
- {
224
- global $post;
225
- $paramName = $option['param'];
226
- $defaultStatus = false;
227
- $isAllowedConditionFilters = array();
228
- if ($paramName == 'select_role') {
229
- return true;
230
- }
231
- if (!$defaultStatus && do_action('isAllowedForConditions', $option, $post)) {
232
- $defaultStatus = true;
233
- }
234
- $isAllowedConditionFilters = apply_filters('isAllowedConditionFilters', array($option));
235
-
236
- if (isset($isAllowedConditionFilters['status']) && $isAllowedConditionFilters['status'] === true) {
237
- $defaultStatus = true;
238
- }
239
-
240
- return $defaultStatus;
241
- }
242
-
243
- /**
244
- * Check is popup inserted via short code or class attribute
245
- *
246
- * @since 1.0.0
247
- *
248
- * @param
249
- *
250
- * @return bool
251
- *
252
- */
253
- private function isCustomInserted()
254
- {
255
- $customInsertData = $this->getCustomInsertedData();
256
- $popup = $this->getPopup();
257
- // When popup object is empty it's mean popup is not custom inserted
258
- if (empty($popup)) {
259
- return false;
260
- }
261
- $popupId = $popup->getId();
262
-
263
- return in_array($popupId, $customInsertData);
264
- }
265
-
266
- /**
267
- * Should load data in the current page
268
- *
269
- * @since 1.0.0
270
- *
271
- * @param array $target popup saved target data
272
- *
273
- * @return bool $isPermissive true => allow false => don't allow
274
- *
275
- */
276
- private function isPermissive($target)
277
- {
278
- $isPermissive = false;
279
-
280
- if (empty($target['permissive'])) {
281
- $isPermissive = false;
282
- return $isPermissive;
283
- }
284
-
285
- foreach ($target['permissive'] as $targetData) {
286
- if ($this->isSatisfyForParam($targetData)) {
287
- $isPermissive = true;
288
- break;
289
- }
290
- }
291
-
292
- return $isPermissive;
293
- }
294
-
295
- /**
296
- * Check whether the target data disallows loading the popup data on the current page
297
- *
298
- * @since 1.0.0
299
- *
300
- * @param array $target popup saved target data
301
- *
302
- * @return bool $isForbidden true => don't allow false => allow
303
- *
304
- */
305
- private function isPostInForbidden($target)
306
- {
307
- $isForbidden = false;
308
-
309
- if (empty($target['forbidden'])) {
310
- return $isForbidden;
311
- }
312
-
313
- foreach ($target['forbidden'] as $targetData) {
314
- if ($this->isSatisfyForParam($targetData)) {
315
- $isForbidden = true;
316
- break;
317
- }
318
- }
319
-
320
- return $isForbidden;
321
- }
322
-
323
- /**
324
- * Check whether the current page is corresponding to the saved target data
325
- *
326
- * @since 1.0.0
327
- *
328
- * @param array $targetData popup saved target data
329
- *
330
- * @return bool $isSatisfy
331
- *
332
- */
333
- private function isSatisfyForParam($targetData)
334
- {
335
- $isSatisfy = false;
336
- $postId = get_queried_object_id();
337
-
338
- if (empty($targetData['param'])) {
339
- return $isSatisfy;
340
- }
341
- $targetParam = $targetData['param'];
342
- $post = $this->getPost();
343
- if (isset($post) && empty($postId)) {
344
- $postId = $post->ID;
345
- }
346
-
347
- if ($targetParam == 'everywhere') {
348
- return true;
349
- }
350
- if (strpos($targetData['param'], '_all')) {
351
- $endIndex = strpos($targetData['param'], '_all');
352
- $postType = substr($targetData['param'], 0, $endIndex);
353
- $currentPostType = get_post_type($postId);
354
-
355
- if ($postType == $currentPostType) {
356
- $isSatisfy = true;
357
- }
358
- }
359
- else if (strpos($targetData['param'], '_archive')) {
360
- $currentPostType = get_post_type();
361
- if ($targetData['param'] == $currentPostType.'_archive') {
362
- if (is_post_type_archive($currentPostType)) {
363
- $isSatisfy = true;
364
- }
365
- }
366
- }
367
- else if (strpos($targetData['param'], '_selected')) {
368
- $values = array();
369
-
370
- if (!empty($targetData['value'])) {
371
- $values = array_keys($targetData['value']);
372
- }
373
-
374
- if (in_array($postId, $values)) {
375
- $isSatisfy = true;
376
- }
377
- }
378
- else if (strpos($targetData['param'], '_categories')) {
379
- $values = array();
380
- $isSatisfy = false;
381
-
382
- if (!empty($targetData['value'])) {
383
- $values = array_values($targetData['value']);
384
- }
385
-
386
- global $post;
387
- // get current all taxonomies of the current post
388
- $taxonomies = get_post_taxonomies($post);
389
- foreach ($taxonomies as $taxonomy) {
390
- // get current post all categories
391
- $terms = get_the_terms($post->ID, $taxonomy);
392
- if (!empty($terms)) {
393
- foreach ($terms as $term) {
394
- if (empty($term)) {
395
- continue;
396
- }
397
- if (in_array($term->term_id, $values)) {
398
- $isSatisfy = true;
399
- break;
400
- }
401
- }
402
- }
403
- }
404
- }
405
- else if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
406
- $selectedCustomPostTypes = array_values($targetData['value']);
407
- $currentPostType = get_post_type($postId);
408
-
409
- if (in_array($currentPostType, $selectedCustomPostTypes)) {
410
- $isSatisfy = true;
411
- }
412
- }
413
- else if ($targetData['param'] == 'post_category' && !empty($targetData['value'])) {
414
- $values = $targetData['value'];
415
- $currentPostCategories = get_the_category($postId);
416
- $currentPostType = get_post_type($postId);
417
- if (empty($currentPostCategories) && $currentPostType == 'product') {
418
- $currentPostCategories = get_the_terms($postId, 'product_cat');
419
- }
420
-
421
- foreach ($currentPostCategories as $categoryName) {
422
- if (in_array($categoryName->term_id, $values)) {
423
- $isSatisfy = true;
424
- break;
425
- }
426
-
427
- }
428
- }
429
- else if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
430
- $postTypes = $targetData['value'];
431
- foreach ($postTypes as $postType) {
432
-
433
- if ($postType == 'is_home_page') {
434
- if (is_front_page() && is_home()) {
435
- // Default homepage
436
- $isSatisfy = true;
437
- break;
438
- } else if ( is_front_page() ) {
439
- // static homepage
440
- $isSatisfy = true;
441
- break;
442
- }
443
- }
444
- else if (function_exists($postType) && $postType()) {
445
- $isSatisfy = true;
446
- break;
447
- }
448
- }
449
- }
450
- else if ($targetData['param'] == 'page_template' && !empty($targetData['value'])) {
451
- $currentPageTemplate = basename(get_page_template());
452
- if (in_array($currentPageTemplate, $targetData['value'])) {
453
- $isSatisfy = true;
454
- }
455
- }
456
- else if ($targetData['param'] == 'post_tags') {
457
- if (has_tag()) {
458
- $isSatisfy = true;
459
- }
460
- }
461
- else if ($targetData['param'] == 'post_tags_ids') {
462
- $tagsObj = wp_get_post_tags($postId);
463
- $postTagsValues = (array)@$targetData['value'];
464
- $selectedTags = array_values($postTagsValues);
465
-
466
- foreach ($tagsObj as $tagObj) {
467
- if (in_array($tagObj->slug, $selectedTags)) {
468
- $isSatisfy = true;
469
- break;
470
- }
471
- }
472
- }
473
-
474
- if (!$isSatisfy && do_action('isAllowedForTarget', $targetData, $post)) {
475
- $isSatisfy = true;
476
- }
477
-
478
- return $isSatisfy;
479
- }
480
-
481
- /**
482
- * Divide conditions data to Permissive and Forbidden
483
- *
484
- * @since 1.0.0
485
- *
486
- * @return array $popupTargetData
487
- *
488
- */
489
- private function divideConditionsData()
490
- {
491
- $popup = $this->getPopup();
492
- $conditions = $popup->getConditions();
493
- $conditions = $this->divideIntoPermissiveAndForbidden($conditions);
494
-
495
- return $conditions;
496
- }
497
- /**
498
- * Divide target data to Permissive and Forbidden
499
- *
500
- * @since 1.0.0
501
- *
502
- * @return array $popupTargetData
503
- *
504
- */
505
- public function divideTargetData()
506
- {
507
- $popup = $this->getPopup();
508
- $targetData = $popup->getTarget();
509
- return $this->divideIntoPermissiveAndForbidden($targetData);
510
- }
511
-
512
- /**
513
- * Divide the Popup target data into Permissive And Forbidden assoc array
514
- *
515
- * @since 1.0.0
516
- *
517
- * @param array $postMetaData popup saved target data
518
- *
519
- * @return array $postMetaDivideData
520
- *
521
- */
522
- public function divideIntoPermissiveAndForbidden($targetData)
523
- {
524
- $permissive = array();
525
- $forbidden = array();
526
- $permissiveOperators = array('==');
527
- $forbiddenOperators = array('!=');
528
- $permissiveOperators = apply_filters('sgpbAdditionalPermissiveOperators', $permissiveOperators);
529
- $forbiddenOperators = apply_filters('sgpbAdditionalForbiddenOperators', $forbiddenOperators);
530
- if (!empty($targetData)) {
531
- foreach ($targetData as $data) {
532
- if (empty($data['operator']) && $data['param'] != 'everywhere' && !strpos($data['param'], '_all') && $data['param'] != 'post_tags') {
533
- break;
534
- }
535
- // set by default '==' (is) value for all not specific conditions like all pages/posts/other_custom_post_types for future correct detection
536
- if ($data['param'] == 'everywhere' || strpos($data['param'], '_all') || $data['param'] == 'post_tags') {
537
- $data['operator'] = '==';
538
- }
539
- if ((isset($data['operator']) && in_array($data['operator'], $permissiveOperators))) {
540
- $permissive[] = $data;
541
- }
542
- else if (in_array($data['operator'], $forbiddenOperators)) {
543
- $forbidden[] = $data;
544
- }
545
- }
546
- }
547
-
548
- $postMetaDivideData = array(
549
- 'permissive' => $permissive,
550
- 'forbidden' => $forbidden
551
- );
552
-
553
- return $postMetaDivideData;
554
- }
555
-
556
- /**
557
- * Get custom inserted data
558
- *
559
- * @since 1.0.0
560
- *
561
- * @return array $insertedData
562
- */
563
- public function getCustomInsertedData()
564
- {
565
- $post = $this->getPost();
566
- $insertedData = array();
567
-
568
- if (isset($post)) {
569
- $insertedData = SGPopup::getCustomInsertedDataByPostId($this->getPost()->ID);
570
- }
571
-
572
- return $insertedData;
573
- }
574
-
575
- /**
576
- * Check Popup conditions
577
- *
578
- * @since 1.0.0
579
- *
580
- * @return array
581
- *
582
- */
583
- private function isSatisfyForOtherConditions()
584
- {
585
- $popup = $this->getPopup();
586
- $popupOptions = $popup->getOptions();
587
- $popupId = $popup->getId();
588
-
589
- $dontAlowOpenPopup = apply_filters('sgpbOtherConditions', array('id' => $popupId, 'popupOptions' => $popupOptions, 'popupObj' => $popup));
590
-
591
- return $dontAlowOpenPopup['status'];
592
- }
593
-
594
- public static function checkUserStatus($savedStatus)
595
- {
596
- $equalStatus = true;
597
-
598
- /*When current user status and saved options does not matched popup must not open*/
599
- if (is_user_logged_in() != (int)$savedStatus) {
600
- $equalStatus = false;
601
- }
602
-
603
- return $equalStatus;
604
- }
605
-
606
- public static function checkLanguage($popupLanguage = '')
607
- {
608
- global $post;
609
-
610
- $postId = $post->ID;
611
- if (!function_exists('wpml_get_language_information')) {
612
- return true;
613
- }
614
- $postLanguage = wpml_get_language_information($postId);
615
- if (is_wp_error($postLanguage)) {
616
- return true;
617
- }
618
- if (!empty($_GET['lang']) && ($_GET['lang'] == $popupLanguage)) {
619
- return true;
620
- }
621
- if ($postLanguage['language_code'] != $popupLanguage) {
622
- return false;
623
- }
624
-
625
- return true;
626
- }
627
-
628
- public static function checkOtherConditionsActions($args)
629
- {
630
- if (empty($args['id']) || empty($args['popupOptions'])) {
631
- return false;
632
- }
633
-
634
- $popupOptions = $args['popupOptions'];
635
-
636
- if (!empty($popupOptions['sgpb-icl_post_language'])) {
637
- $languageCompatibilty = PopupChecker::checkLanguage($popupOptions['sgpb-icl_post_language']);
638
-
639
- if ($languageCompatibilty === false) {
640
- return $languageCompatibilty;
641
- }
642
- }
643
-
644
-
645
- // proStartSilver
646
- //User status check
647
- if (!empty($popupOptions['sgpb-user-status'])) {
648
- $restrictUserStatus = PopupChecker::checkUserStatus($popupOptions['sgpb-loggedin-user']);
649
-
650
- if ($restrictUserStatus === false) {
651
- return $restrictUserStatus;
652
- }
653
- }
654
-
655
- // proEndSilver
656
-
657
- // proStartPlatinum
658
- // proEndPlatinum
659
-
660
- // checking by popup type
661
- if (!empty($popupOptions['sgpb-type'])) {
662
- $popupClassName = SGPopup::getPopupClassNameFormType($popupOptions['sgpb-type']);
663
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
664
-
665
- if (method_exists($popupClassName, 'allowToOpen')) {
666
- $allowToOpen = $popupClassName::allowToOpen($popupOptions, $args);
667
- return $allowToOpen;
668
- }
669
- }
670
-
671
- return apply_filters('checkOtherConditions', true);
672
- }
673
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \DateTime;
4
+ use \DateTimeZone;
5
+ use \ConfigDataHelper;
6
+
7
+ /**
8
+ * Popup checker class to check if the popup must be loaded on the current page
9
+ *
10
+ * @since 1.0.0
11
+ *
12
+ */
13
+ class PopupChecker
14
+ {
15
+ private static $instance;
16
+ private $popup;
17
+ private $isGeoAjaxModeEnabled;
18
+ private $post;
19
+ private $isAjaxCall;
20
+
21
+ public static function instance()
22
+ {
23
+ if (!isset(self::$instance)) {
24
+ self::$instance = new self;
25
+ }
26
+
27
+ return self::$instance;
28
+ }
29
+
30
+ public function setPopup($popup)
31
+ {
32
+ $this->popup = $popup;
33
+ }
34
+
35
+ public function getPopup()
36
+ {
37
+ return $this->popup;
38
+ }
39
+
40
+ public function setPost($post)
41
+ {
42
+ $this->post = $post;
43
+ }
44
+
45
+ public function getPost()
46
+ {
47
+ return $this->post;
48
+ }
49
+
50
+ public function setPopupGeoAjaxModeActive($ajaxMode)
51
+ {
52
+ $this->isGeoAjaxModeEnabled = $ajaxMode;
53
+ }
54
+
55
+ public function getPopupGeoAjaxMode()
56
+ {
57
+ return $this->isGeoAjaxModeEnabled;
58
+ }
59
+
60
+ public function setIsAjaxCall($isAjax)
61
+ {
62
+ $this->isAjaxCall = $isAjax;
63
+ }
64
+
65
+ public function getIsAjaxCall()
66
+ {
67
+ return $this->isAjaxCall;
68
+ }
69
+
70
+ /**
71
+ * It checks whether popup should be loaded on the current page.
72
+ *
73
+ * @since 1.0.0
74
+ *
75
+ * @param int $popupId popup id
76
+ * @param object $post page post data
77
+ * @param boolean $isAjax
78
+ *
79
+ * @return bool
80
+ *
81
+ */
82
+ public function isLoadable($popup, $post, $isAjax = false)
83
+ {
84
+ $this->setPopup($popup);
85
+ $this->setPost($post);
86
+
87
+ $this->setPopupGeoAjaxModeActive($popup->getOptionValue('sgpb-enable-geo-ajax-mode'));
88
+ $this->setIsAjaxCall($isAjax);
89
+
90
+ $popupOptions = $popup->getOptions();
91
+ $isActive = $popup->getOptionValue('sgpb-is-active', true);
92
+ $saveMode = $popup->getSaveMode();
93
+ $allowToLoad = $this->allowToLoad();
94
+
95
+ if ($saveMode) {
96
+ $allowToLoad['option_event'] = false;
97
+ return $allowToLoad;
98
+ }
99
+
100
+ if (isset($popupOptions['sgpb-is-active'])) {
101
+ $isActive = $popupOptions['sgpb-is-active'];
102
+ if ($isActive) {
103
+ $popup->setReportData($popup->getId());
104
+ }
105
+ }
106
+
107
+ if (!$isActive) {
108
+ $allowToLoad['option_event'] = false;
109
+ }
110
+
111
+ return $allowToLoad;
112
+ }
113
+
114
+ /**
115
+ * Decides whether popup data should be loaded or not
116
+ *
117
+ * @since 1.0.0
118
+ *
119
+ * @return array
120
+ *
121
+ */
122
+ private function allowToLoad()
123
+ {
124
+ $isCustomInserted = $this->isCustomInserted();
125
+
126
+ $insertedModes = array(
127
+ 'attr_event' => false,
128
+ 'option_event' => false
129
+ );
130
+
131
+ if ($isCustomInserted) {
132
+ $insertedModes['attr_event'] = true;
133
+ }
134
+
135
+ $target = $this->divideTargetData();
136
+ $isPostInForbidden = $this->isPostInForbidden($target);
137
+
138
+ if ($isPostInForbidden) {
139
+ return $insertedModes;
140
+ }
141
+
142
+ if (!empty($target['forbidden']) && empty($target['permissive'])) {
143
+ $conditions = $this->divideConditionsData();
144
+ $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
145
+ $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
146
+
147
+ if ($isSatisfyForConditions === false) {
148
+ return $insertedModes;
149
+ }
150
+ if ($this->isSatisfyForOtherConditions() === false) {
151
+ return $insertedModes;
152
+ }
153
+ $insertedModes['option_event'] = true;
154
+ }
155
+
156
+ $isPermissive = $this->isPermissive($target);
157
+
158
+ //If permissive for current page check conditions
159
+ if ($isPermissive) {
160
+ $conditions = $this->divideConditionsData();
161
+ $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
162
+ $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
163
+
164
+ if ($isSatisfyForConditions === false) {
165
+ return $insertedModes;
166
+ }
167
+ if ($this->isSatisfyForOtherConditions() === false) {
168
+ return $insertedModes;
169
+ }
170
+ $insertedModes['option_event'] = $isPermissive;
171
+ }
172
+
173
+ return $insertedModes;
174
+ }
175
+
176
+ /**
177
+ * check is Satisfy popup conditions
178
+ *
179
+ * @since 1.0.0
180
+ *
181
+ * @param array $conditions assoc array
182
+ *
183
+ * @return bool
184
+ *
185
+ */
186
+ private function isSatisfyForConditions($conditions)
187
+ {
188
+ // proStartSilver
189
+ // this case when selected IS NOT operator
190
+ $forbiddenConditions = $conditions['forbidden'];
191
+ if (!empty($forbiddenConditions)) {
192
+ if (!$this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
193
+ return false;
194
+ }
195
+ foreach ($forbiddenConditions as $forbiddenCondition) {
196
+ $isForbiddenConditions = $this->isSatisfyForConditionsOptions($forbiddenCondition);
197
+ if ($isForbiddenConditions) {
198
+ return false;
199
+ } else {
200
+ return true;
201
+ }
202
+ }
203
+ }
204
+
205
+ // this case when selected IS operator
206
+ $permissiveOptions = $conditions['permissive'];
207
+ if (!empty($permissiveOptions)) {
208
+ if (!$this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
209
+ return false;
210
+ }
211
+ foreach ($permissiveOptions as $permissiveOption) {
212
+ $isPermissiveConditions = $this->isSatisfyForConditionsOptions($permissiveOption);
213
+ return $isPermissiveConditions;
214
+ }
215
+ }
216
+ if ($this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
217
+ return false;
218
+ }
219
+ return true;
220
+ }
221
+
222
+ private function isSatisfyForConditionsOptions($option)
223
+ {
224
+ global $post;
225
+ $paramName = $option['param'];
226
+ $defaultStatus = false;
227
+ $isAllowedConditionFilters = array();
228
+ if ($paramName == 'select_role') {
229
+ return true;
230
+ }
231
+ if (!$defaultStatus && do_action('isAllowedForConditions', $option, $post)) {
232
+ $defaultStatus = true;
233
+ }
234
+ $isAllowedConditionFilters = apply_filters('isAllowedConditionFilters', array($option));
235
+
236
+ if (isset($isAllowedConditionFilters['status']) && $isAllowedConditionFilters['status'] === true) {
237
+ $defaultStatus = true;
238
+ }
239
+
240
+ return $defaultStatus;
241
+ }
242
+
243
+ /**
244
+ * Check is popup inserted via short code or class attribute
245
+ *
246
+ * @since 1.0.0
247
+ *
248
+ * @param
249
+ *
250
+ * @return bool
251
+ *
252
+ */
253
+ private function isCustomInserted()
254
+ {
255
+ $customInsertData = $this->getCustomInsertedData();
256
+ $popup = $this->getPopup();
257
+ // When popup object is empty it's mean popup is not custom inserted
258
+ if (empty($popup)) {
259
+ return false;
260
+ }
261
+ $popupId = $popup->getId();
262
+
263
+ return in_array($popupId, $customInsertData);
264
+ }
265
+
266
+ /**
267
+ * Should load data in the current page
268
+ *
269
+ * @since 1.0.0
270
+ *
271
+ * @param array $target popup saved target data
272
+ *
273
+ * @return bool $isPermissive true => allow false => don't allow
274
+ *
275
+ */
276
+ private function isPermissive($target)
277
+ {
278
+ $isPermissive = false;
279
+
280
+ if (empty($target['permissive'])) {
281
+ $isPermissive = false;
282
+ return $isPermissive;
283
+ }
284
+
285
+ foreach ($target['permissive'] as $targetData) {
286
+ if ($this->isSatisfyForParam($targetData)) {
287
+ $isPermissive = true;
288
+ break;
289
+ }
290
+ }
291
+
292
+ return $isPermissive;
293
+ }
294
+
295
+ /**
296
+ * Check whether the target data disallows loading the popup data on the current page
297
+ *
298
+ * @since 1.0.0
299
+ *
300
+ * @param array $target popup saved target data
301
+ *
302
+ * @return bool $isForbidden true => don't allow false => allow
303
+ *
304
+ */
305
+ private function isPostInForbidden($target)
306
+ {
307
+ $isForbidden = false;
308
+
309
+ if (empty($target['forbidden'])) {
310
+ return $isForbidden;
311
+ }
312
+
313
+ foreach ($target['forbidden'] as $targetData) {
314
+ if ($this->isSatisfyForParam($targetData)) {
315
+ $isForbidden = true;
316
+ break;
317
+ }
318
+ }
319
+
320
+ return $isForbidden;
321
+ }
322
+
323
+ /**
324
+ * Check whether the current page is corresponding to the saved target data
325
+ *
326
+ * @since 1.0.0
327
+ *
328
+ * @param array $targetData popup saved target data
329
+ *
330
+ * @return bool $isSatisfy
331
+ *
332
+ */
333
+ private function isSatisfyForParam($targetData)
334
+ {
335
+ $isSatisfy = false;
336
+ $postId = get_queried_object_id();
337
+
338
+ if (empty($targetData['param'])) {
339
+ return $isSatisfy;
340
+ }
341
+ $targetParam = $targetData['param'];
342
+ $post = $this->getPost();
343
+ if (isset($post) && empty($postId)) {
344
+ $postId = $post->ID;
345
+ }
346
+
347
+ if ($targetParam == 'everywhere') {
348
+ return true;
349
+ }
350
+ if (strpos($targetData['param'], '_all')) {
351
+ $endIndex = strpos($targetData['param'], '_all');
352
+ $postType = substr($targetData['param'], 0, $endIndex);
353
+ $currentPostType = get_post_type($postId);
354
+
355
+ if ($postType == $currentPostType) {
356
+ $isSatisfy = true;
357
+ }
358
+ }
359
+ else if (strpos($targetData['param'], '_archive')) {
360
+ $currentPostType = get_post_type();
361
+ if ($targetData['param'] == $currentPostType.'_archive') {
362
+ if (is_post_type_archive($currentPostType)) {
363
+ $isSatisfy = true;
364
+ }
365
+ }
366
+ }
367
+ else if (strpos($targetData['param'], '_selected')) {
368
+ $values = array();
369
+
370
+ if (!empty($targetData['value'])) {
371
+ $values = array_keys($targetData['value']);
372
+ }
373
+
374
+ if (in_array($postId, $values)) {
375
+ $isSatisfy = true;
376
+ }
377
+ }
378
+ else if (strpos($targetData['param'], '_categories')) {
379
+ $values = array();
380
+ $isSatisfy = false;
381
+
382
+ if (!empty($targetData['value'])) {
383
+ $values = array_values($targetData['value']);
384
+ }
385
+
386
+ global $post;
387
+ // get current all taxonomies of the current post
388
+ $taxonomies = get_post_taxonomies($post);
389
+ foreach ($taxonomies as $taxonomy) {
390
+ // get current post all categories
391
+ $terms = get_the_terms($post->ID, $taxonomy);
392
+ if (!empty($terms)) {
393
+ foreach ($terms as $term) {
394
+ if (empty($term)) {
395
+ continue;
396
+ }
397
+ if (in_array($term->term_id, $values)) {
398
+ $isSatisfy = true;
399
+ break;
400
+ }
401
+ }
402
+ }
403
+ }
404
+ }
405
+ else if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
406
+ $selectedCustomPostTypes = array_values($targetData['value']);
407
+ $currentPostType = get_post_type($postId);
408
+
409
+ if (in_array($currentPostType, $selectedCustomPostTypes)) {
410
+ $isSatisfy = true;
411
+ }
412
+ }
413
+ else if ($targetData['param'] == 'post_category' && !empty($targetData['value'])) {
414
+ $values = $targetData['value'];
415
+ $currentPostCategories = get_the_category($postId);
416
+ $currentPostType = get_post_type($postId);
417
+ if (empty($currentPostCategories) && $currentPostType == 'product') {
418
+ $currentPostCategories = get_the_terms($postId, 'product_cat');
419
+ }
420
+
421
+ foreach ($currentPostCategories as $categoryName) {
422
+ if (in_array($categoryName->term_id, $values)) {
423
+ $isSatisfy = true;
424
+ break;
425
+ }
426
+
427
+ }
428
+ }
429
+ else if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
430
+ $postTypes = $targetData['value'];
431
+ foreach ($postTypes as $postType) {
432
+
433
+ if ($postType == 'is_home_page') {
434
+ if (is_front_page() && is_home()) {
435
+ // Default homepage
436
+ $isSatisfy = true;
437
+ break;
438
+ } else if ( is_front_page() ) {
439
+ // static homepage
440
+ $isSatisfy = true;
441
+ break;
442
+ }
443
+ }
444
+ else if (function_exists($postType) && $postType()) {
445
+ $isSatisfy = true;
446
+ break;
447
+ }
448
+ }
449
+ }
450
+ else if ($targetData['param'] == 'page_template' && !empty($targetData['value'])) {
451
+ $currentPageTemplate = basename(get_page_template());
452
+ if (in_array($currentPageTemplate, $targetData['value'])) {
453
+ $isSatisfy = true;
454
+ }
455
+ }
456
+ else if ($targetData['param'] == 'post_tags') {
457
+ if (has_tag()) {
458
+ $isSatisfy = true;
459
+ }
460
+ }
461
+ else if ($targetData['param'] == 'post_tags_ids') {
462
+ $tagsObj = wp_get_post_tags($postId);
463
+ $postTagsValues = (array)@$targetData['value'];
464
+ $selectedTags = array_values($postTagsValues);
465
+
466
+ foreach ($tagsObj as $tagObj) {
467
+ if (in_array($tagObj->slug, $selectedTags)) {
468
+ $isSatisfy = true;
469
+ break;
470
+ }
471
+ }
472
+ }
473
+
474
+ if (!$isSatisfy && do_action('isAllowedForTarget', $targetData, $post)) {
475
+ $isSatisfy = true;
476
+ }
477
+
478
+ return $isSatisfy;
479
+ }
480
+
481
+ /**
482
+ * Divide conditions data to Permissive and Forbidden
483
+ *
484
+ * @since 1.0.0
485
+ *
486
+ * @return array $popupTargetData
487
+ *
488
+ */
489
+ private function divideConditionsData()
490
+ {
491
+ $popup = $this->getPopup();
492
+ $conditions = $popup->getConditions();
493
+ $conditions = $this->divideIntoPermissiveAndForbidden($conditions);
494
+
495
+ return $conditions;
496
+ }
497
+ /**
498
+ * Divide target data to Permissive and Forbidden
499
+ *
500
+ * @since 1.0.0
501
+ *
502
+ * @return array $popupTargetData
503
+ *
504
+ */
505
+ public function divideTargetData()
506
+ {
507
+ $popup = $this->getPopup();
508
+ $targetData = $popup->getTarget();
509
+ return $this->divideIntoPermissiveAndForbidden($targetData);
510
+ }
511
+
512
+ /**
513
+ * Divide the Popup target data into Permissive And Forbidden assoc array
514
+ *
515
+ * @since 1.0.0
516
+ *
517
+ * @param array $postMetaData popup saved target data
518
+ *
519
+ * @return array $postMetaDivideData
520
+ *
521
+ */
522
+ public function divideIntoPermissiveAndForbidden($targetData)
523
+ {
524
+ $permissive = array();
525
+ $forbidden = array();
526
+ $permissiveOperators = array('==');
527
+ $forbiddenOperators = array('!=');
528
+ $permissiveOperators = apply_filters('sgpbAdditionalPermissiveOperators', $permissiveOperators);
529
+ $forbiddenOperators = apply_filters('sgpbAdditionalForbiddenOperators', $forbiddenOperators);
530
+ if (!empty($targetData)) {
531
+ foreach ($targetData as $data) {
532
+ if (empty($data['operator']) && $data['param'] != 'everywhere' && !strpos($data['param'], '_all') && $data['param'] != 'post_tags') {
533
+ break;
534
+ }
535
+ // set by default '==' (is) value for all not specific conditions like all pages/posts/other_custom_post_types for future correct detection
536
+ if ($data['param'] == 'everywhere' || strpos($data['param'], '_all') || $data['param'] == 'post_tags') {
537
+ $data['operator'] = '==';
538
+ }
539
+ if ((isset($data['operator']) && in_array($data['operator'], $permissiveOperators))) {
540
+ $permissive[] = $data;
541
+ }
542
+ else if (in_array($data['operator'], $forbiddenOperators)) {
543
+ $forbidden[] = $data;
544
+ }
545
+ }
546
+ }
547
+
548
+ $postMetaDivideData = array(
549
+ 'permissive' => $permissive,
550
+ 'forbidden' => $forbidden
551
+ );
552
+
553
+ return $postMetaDivideData;
554
+ }
555
+
556
+ /**
557
+ * Get custom inserted data
558
+ *
559
+ * @since 1.0.0
560
+ *
561
+ * @return array $insertedData
562
+ */
563
+ public function getCustomInsertedData()
564
+ {
565
+ $post = $this->getPost();
566
+ $insertedData = array();
567
+
568
+ if (isset($post)) {
569
+ $insertedData = SGPopup::getCustomInsertedDataByPostId($this->getPost()->ID);
570
+ }
571
+
572
+ return $insertedData;
573
+ }
574
+
575
+ /**
576
+ * Check Popup conditions
577
+ *
578
+ * @since 1.0.0
579
+ *
580
+ * @return array
581
+ *
582
+ */
583
+ private function isSatisfyForOtherConditions()
584
+ {
585
+ $popup = $this->getPopup();
586
+ $popupOptions = $popup->getOptions();
587
+ $popupId = $popup->getId();
588
+
589
+ $dontAlowOpenPopup = apply_filters('sgpbOtherConditions', array('id' => $popupId, 'popupOptions' => $popupOptions, 'popupObj' => $popup));
590
+
591
+ return $dontAlowOpenPopup['status'];
592
+ }
593
+
594
+ public static function checkUserStatus($savedStatus)
595
+ {
596
+ $equalStatus = true;
597
+
598
+ /*When current user status and saved options does not matched popup must not open*/
599
+ if (is_user_logged_in() != (int)$savedStatus) {
600
+ $equalStatus = false;
601
+ }
602
+
603
+ return $equalStatus;
604
+ }
605
+
606
+ public static function checkLanguage($popupLanguage = '')
607
+ {
608
+ global $post;
609
+
610
+ $postId = $post->ID;
611
+ if (!function_exists('wpml_get_language_information')) {
612
+ return true;
613
+ }
614
+ $postLanguage = wpml_get_language_information($postId);
615
+ if (is_wp_error($postLanguage)) {
616
+ return true;
617
+ }
618
+ if (!empty($_GET['lang']) && ($_GET['lang'] == $popupLanguage)) {
619
+ return true;
620
+ }
621
+ if ($postLanguage['language_code'] != $popupLanguage) {
622
+ return false;
623
+ }
624
+
625
+ return true;
626
+ }
627
+
628
+ public static function checkOtherConditionsActions($args)
629
+ {
630
+ if (empty($args['id']) || empty($args['popupOptions'])) {
631
+ return false;
632
+ }
633
+
634
+ $popupOptions = $args['popupOptions'];
635
+
636
+ if (!empty($popupOptions['sgpb-icl_post_language'])) {
637
+ $languageCompatibilty = PopupChecker::checkLanguage($popupOptions['sgpb-icl_post_language']);
638
+
639
+ if ($languageCompatibilty === false) {
640
+ return $languageCompatibilty;
641
+ }
642
+ }
643
+
644
+
645
+ // proStartSilver
646
+ //User status check
647
+ if (!empty($popupOptions['sgpb-user-status'])) {
648
+ $restrictUserStatus = PopupChecker::checkUserStatus($popupOptions['sgpb-loggedin-user']);
649
+
650
+ if ($restrictUserStatus === false) {
651
+ return $restrictUserStatus;
652
+ }
653
+ }
654
+
655
+ // proEndSilver
656
+
657
+ // proStartPlatinum
658
+ // proEndPlatinum
659
+
660
+ // checking by popup type
661
+ if (!empty($popupOptions['sgpb-type'])) {
662
+ $popupClassName = SGPopup::getPopupClassNameFormType($popupOptions['sgpb-type']);
663
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
664
+
665
+ if (method_exists($popupClassName, 'allowToOpen')) {
666
+ $allowToOpen = $popupClassName::allowToOpen($popupOptions, $args);
667
+ return $allowToOpen;
668
+ }
669
+ }
670
+
671
+ return apply_filters('checkOtherConditions', true);
672
+ }
673
+ }
com/classes/PopupGroupFilter.php CHANGED
@@ -1,193 +1,193 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class PopupGroupFilter
5
- {
6
- private $popups = array();
7
- private $popupGroups = array();
8
- private $hasSubPopups = array('subscription', 'contactForm');
9
-
10
- public function getHasSubPopups()
11
- {
12
- return apply_filters('sgpbHasSubPopups', $this->hasSubPopups);
13
- }
14
-
15
- public function setGroups($popupGroups)
16
- {
17
- $this->popupGroups = $popupGroups;
18
- }
19
-
20
- public function getGroups()
21
- {
22
- return $this->popupGroups;
23
- }
24
-
25
- public function insertGroup($groupName,$group)
26
- {
27
- $this->popupGroups[$groupName] = $group;
28
- }
29
-
30
- public function setPopups($popups)
31
- {
32
- $this->popups = $popups;
33
- }
34
-
35
- public function getPopups()
36
- {
37
- return $this->popups;
38
- }
39
-
40
- public function filter()
41
- {
42
- $splitedGroups = $this->splitToGroups();
43
-
44
- // When does not have any groups, then there is no need do filter
45
- if (empty($splitedGroups)) {
46
- return $this->filteredResults();
47
- }
48
- $groups = $this->filterGroups();
49
-
50
- if (empty($groups)) {
51
- return $this->filteredResults();
52
- }
53
- $unionPopups = $this->unionGroups();
54
-
55
- if (empty($unionPopups)) {
56
- return $this->filteredResults();
57
- }
58
- $this->extendPopups();
59
-
60
- return $this->filteredResults();
61
- }
62
-
63
- private function filteredResults()
64
- {
65
- $popups = $this->getPopups();
66
-
67
- if (empty($popups)) {
68
- return $popups;
69
- }
70
- $filteredResults = $this->filterByOrder();
71
-
72
- return $filteredResults;
73
- }
74
-
75
- public function filterByOrder()
76
- {
77
- $popups = $this->getPopups();
78
- $popupsByKeyOrder = array();
79
-
80
- foreach ($popups as $popup) {
81
- if (!$popup instanceof SGPopup) {
82
- continue;
83
- }
84
- $orderId = $popup->getOptionValue('sgpb-popup-order');
85
- $popupsByKeyOrder[$orderId][] = $popup;
86
- }
87
- krsort($popupsByKeyOrder);
88
- $orderPopups = array();
89
- foreach ($popupsByKeyOrder as $value) {
90
- $size = sizeof($value);
91
- if ($size == 1) {
92
- $orderPopups[] = $value[0];
93
- continue;
94
- }
95
-
96
- foreach ($value as $insideValue) {
97
- $orderPopups[] = $insideValue;
98
- }
99
-
100
- }
101
- $orderPopups = array_values($orderPopups);
102
-
103
- $this->setPopups($orderPopups);
104
-
105
- return $orderPopups;
106
- }
107
-
108
- public function splitToGroups()
109
- {
110
- $popups = $this->getPopups();
111
- $groups = array();
112
-
113
- if (empty($popups)) {
114
- return $popups;
115
- }
116
-
117
- $staticPopups = $popups;
118
-
119
- $groups['staticPopups'] = $staticPopups;
120
-
121
- $this->setGroups($groups);
122
-
123
- return $popups;
124
- }
125
-
126
- private function filterGroups()
127
- {
128
- $groups = $this->getGroups();
129
-
130
- $this->setGroups($groups);
131
-
132
- return $groups;
133
- }
134
-
135
- private function filterRandomPopups($groups)
136
- {
137
- $randomPopups = $groups['randomPopups'];
138
- $randomPopupKey = array_rand($randomPopups, 1);
139
- $randomPopup = $randomPopups[$randomPopupKey];
140
- // $randomPopup converted to array
141
- $groups['randomPopups'] = array($randomPopup);
142
-
143
- return $groups;
144
- }
145
-
146
- public function unionGroups()
147
- {
148
- $groups = $this->getGroups();
149
- $popups = array();
150
-
151
- $groupsPopups = array_values($groups);
152
- foreach ($groupsPopups as $groupsPopup) {
153
- $popups = array_merge($popups, $groupsPopup);
154
- }
155
-
156
- $this->setPopups($popups);
157
-
158
- return $popups;
159
- }
160
-
161
- private function extendPopups()
162
- {
163
- $popups = $this->getPopups();
164
- $insidePopups = array();
165
-
166
- if (empty($popups)) {
167
- return $popups;
168
- }
169
-
170
- $hasSubPopups = $this->getHasSubPopups();
171
-
172
- foreach ($popups as $popup) {
173
- if (empty($popup)) {
174
- continue;
175
- }
176
- $popupType = $popup->getType();
177
- $insidePopups = $popup->popupShortcodesInsidePopup();
178
- if (!empty($insidePopups)) {
179
- $popups = array_merge($popups, $insidePopups);
180
- }
181
-
182
- $subPopups = $popup->getSubPopupObj();
183
-
184
- if (!empty($subPopups)) {
185
- $popups = array_merge($popups, $subPopups);
186
- }
187
- }
188
-
189
- $this->setPopups($popups);
190
-
191
- return $popups;
192
- }
193
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class PopupGroupFilter
5
+ {
6
+ private $popups = array();
7
+ private $popupGroups = array();
8
+ private $hasSubPopups = array('subscription', 'contactForm');
9
+
10
+ public function getHasSubPopups()
11
+ {
12
+ return apply_filters('sgpbHasSubPopups', $this->hasSubPopups);
13
+ }
14
+
15
+ public function setGroups($popupGroups)
16
+ {
17
+ $this->popupGroups = $popupGroups;
18
+ }
19
+
20
+ public function getGroups()
21
+ {
22
+ return $this->popupGroups;
23
+ }
24
+
25
+ public function insertGroup($groupName,$group)
26
+ {
27
+ $this->popupGroups[$groupName] = $group;
28
+ }
29
+
30
+ public function setPopups($popups)
31
+ {
32
+ $this->popups = $popups;
33
+ }
34
+
35
+ public function getPopups()
36
+ {
37
+ return $this->popups;
38
+ }
39
+
40
+ public function filter()
41
+ {
42
+ $splitedGroups = $this->splitToGroups();
43
+
44
+ // When does not have any groups, then there is no need do filter
45
+ if (empty($splitedGroups)) {
46
+ return $this->filteredResults();
47
+ }
48
+ $groups = $this->filterGroups();
49
+
50
+ if (empty($groups)) {
51
+ return $this->filteredResults();
52
+ }
53
+ $unionPopups = $this->unionGroups();
54
+
55
+ if (empty($unionPopups)) {
56
+ return $this->filteredResults();
57
+ }
58
+ $this->extendPopups();
59
+
60
+ return $this->filteredResults();
61
+ }
62
+
63
+ private function filteredResults()
64
+ {
65
+ $popups = $this->getPopups();
66
+
67
+ if (empty($popups)) {
68
+ return $popups;
69
+ }
70
+ $filteredResults = $this->filterByOrder();
71
+
72
+ return $filteredResults;
73
+ }
74
+
75
+ public function filterByOrder()
76
+ {
77
+ $popups = $this->getPopups();
78
+ $popupsByKeyOrder = array();
79
+
80
+ foreach ($popups as $popup) {
81
+ if (!$popup instanceof SGPopup) {
82
+ continue;
83
+ }
84
+ $orderId = $popup->getOptionValue('sgpb-popup-order');
85
+ $popupsByKeyOrder[$orderId][] = $popup;
86
+ }
87
+ krsort($popupsByKeyOrder);
88
+ $orderPopups = array();
89
+ foreach ($popupsByKeyOrder as $value) {
90
+ $size = sizeof($value);
91
+ if ($size == 1) {
92
+ $orderPopups[] = $value[0];
93
+ continue;
94
+ }
95
+
96
+ foreach ($value as $insideValue) {
97
+ $orderPopups[] = $insideValue;
98
+ }
99
+
100
+ }
101
+ $orderPopups = array_values($orderPopups);
102
+
103
+ $this->setPopups($orderPopups);
104
+
105
+ return $orderPopups;
106
+ }
107
+
108
+ public function splitToGroups()
109
+ {
110
+ $popups = $this->getPopups();
111
+ $groups = array();
112
+
113
+ if (empty($popups)) {
114
+ return $popups;
115
+ }
116
+
117
+ $staticPopups = $popups;
118
+
119
+ $groups['staticPopups'] = $staticPopups;
120
+
121
+ $this->setGroups($groups);
122
+
123
+ return $popups;
124
+ }
125
+
126
+ private function filterGroups()
127
+ {
128
+ $groups = $this->getGroups();
129
+
130
+ $this->setGroups($groups);
131
+
132
+ return $groups;
133
+ }
134
+
135
+ private function filterRandomPopups($groups)
136
+ {
137
+ $randomPopups = $groups['randomPopups'];
138
+ $randomPopupKey = array_rand($randomPopups, 1);
139
+ $randomPopup = $randomPopups[$randomPopupKey];
140
+ // $randomPopup converted to array
141
+ $groups['randomPopups'] = array($randomPopup);
142
+
143
+ return $groups;
144
+ }
145
+
146
+ public function unionGroups()
147
+ {
148
+ $groups = $this->getGroups();
149
+ $popups = array();
150
+
151
+ $groupsPopups = array_values($groups);
152
+ foreach ($groupsPopups as $groupsPopup) {
153
+ $popups = array_merge($popups, $groupsPopup);
154
+ }
155
+
156
+ $this->setPopups($popups);
157
+
158
+ return $popups;
159
+ }
160
+
161
+ private function extendPopups()
162
+ {
163
+ $popups = $this->getPopups();
164
+ $insidePopups = array();
165
+
166
+ if (empty($popups)) {
167
+ return $popups;
168
+ }
169
+
170
+ $hasSubPopups = $this->getHasSubPopups();
171
+
172
+ foreach ($popups as $popup) {
173
+ if (empty($popup)) {
174
+ continue;
175
+ }
176
+ $popupType = $popup->getType();
177
+ $insidePopups = $popup->popupShortcodesInsidePopup();
178
+ if (!empty($insidePopups)) {
179
+ $popups = array_merge($popups, $insidePopups);
180
+ }
181
+
182
+ $subPopups = $popup->getSubPopupObj();
183
+
184
+ if (!empty($subPopups)) {
185
+ $popups = array_merge($popups, $subPopups);
186
+ }
187
+ }
188
+
189
+ $this->setPopups($popups);
190
+
191
+ return $popups;
192
+ }
193
+ }
com/classes/PopupInstaller.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
- namespace sgpb;
3
- class PopupInstaller
4
- {
5
-
6
  }
1
+ <?php
2
+ namespace sgpb;
3
+ class PopupInstaller
4
+ {
5
+
6
  }
com/classes/PopupLoader.php CHANGED
@@ -1,181 +1,181 @@
1
- <?php
2
- namespace sgpb;
3
- use \WP_Query;
4
-
5
- class PopupLoader
6
- {
7
- private static $instance;
8
- private $loadablePopups = array();
9
- private $loadablePopupsIds = array();
10
-
11
- private function __construct()
12
- {
13
- require_once(ABSPATH.'wp-admin/includes/plugin.php');
14
- }
15
-
16
- public static function instance() {
17
-
18
- if (!isset(self::$instance)) {
19
- self::$instance = new self;
20
- }
21
-
22
- return self::$instance;
23
- }
24
-
25
- public function setLoadablePopupsIds($loadablePopupsIds)
26
- {
27
- $this->loadablePopupsIds = $loadablePopupsIds;
28
- }
29
-
30
- public function getLoadablePopupsIds()
31
- {
32
- return $this->loadablePopupsIds;
33
- }
34
-
35
- public function addLoadablePopup($popupObj)
36
- {
37
- $this->loadablePopups[] = $popupObj;
38
- }
39
-
40
- public function setLoadablePopups($loadablePopups)
41
- {
42
- $this->loadablePopups = $loadablePopups;
43
- }
44
-
45
- public function getLoadablePopups()
46
- {
47
- return $this->loadablePopups;
48
- }
49
-
50
- public function addPopupFromUrl($popupsToLoad)
51
- {
52
- global $wp;
53
- $currentUrl = home_url( $wp->request );
54
- $currentUrl = strpos($currentUrl, '/popupbuilder/');
55
- if (isset($_GET['sg_popup_id']) || isset($_GET['sg_popup_preview_id']) || $currentUrl !== false) {
56
- $args = array();
57
- $previewPopups = array();
58
- $getterId = isset($_GET['sg_popup_id']) ? (int)$_GET['sg_popup_id'] : 0;
59
- $previewedPopupId = isset($_GET['sg_popup_preview_id']) ? (int)$_GET['sg_popup_preview_id'] : 0;
60
- if (isset($_GET['sg_popup_preview_id'])) {
61
- $getterId = $previewedPopupId;
62
- $args['is-preview'] = true;
63
- }
64
- if (function_exists('sgpb\sgpGetCorrectPopupId')) {
65
- $getterId = sgpGetCorrectPopupId($getterId);
66
- }
67
- if ($currentUrl !== false) {
68
- $getterId = $previewedPopupId;
69
- if (isset($_GET['preview_id'])) {
70
- $getterId = (int)$_GET['preview_id'];
71
- }
72
- }
73
-
74
- $popupFromUrl = SGPopup::find($getterId, $args);
75
- if (!empty($popupFromUrl)) {
76
- global $SGPB_DATA_CONFIG_ARRAY;
77
- $defaultEvent = array();
78
- $customDelay = $popupFromUrl->getOptionValue('sgpb-popup-delay');
79
- $defaultEvent[] = $SGPB_DATA_CONFIG_ARRAY['events']['initialData'][0];
80
- $defaultEvent[0]['value'] = 0;
81
- if ($customDelay) {
82
- $defaultEvent[0]['value'] = $customDelay;
83
- }
84
- $popupFromUrl->setEvents($defaultEvent);
85
- $popupsToLoad[] = $popupFromUrl;
86
- $previewPopups[] = $popupFromUrl;
87
- if (isset($_GET['sg_popup_preview_id'])) {
88
- $popupsToLoad = $previewPopups;
89
- }
90
- }
91
- }
92
-
93
- return $popupsToLoad;
94
- }
95
-
96
- public function loadPopups()
97
- {
98
- $foundPopup = array();
99
- if (is_preview()) {
100
- global $post;
101
- $foundPopup = $post;
102
- }
103
- if (!empty($foundPopup)) {
104
- global $SGPB_DATA_CONFIG_ARRAY;
105
- if (@$foundPopup->post_type == SG_POPUP_POST_TYPE) {
106
- $events = $SGPB_DATA_CONFIG_ARRAY['events']['initialData'][0];
107
- $targets = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
108
- // for any targets preview popup should open
109
- if (!empty($targets[0][0])) {
110
- $targets[0][0]['param'] = 'post_all';
111
- }
112
-
113
- $popup = SGPopup::find($foundPopup);
114
- if (empty($popup)) {
115
- return;
116
- }
117
- $popup->setTarget($targets);
118
- $popup->setEvents($events);
119
-
120
- $this->addLoadablePopup($popup);
121
- $this->doGroupFiltersPopups();
122
- $popups = $this->getLoadablePopups();
123
- $scriptsLoader = new ScriptsLoader();
124
- $scriptsLoader->setLoadablePopups($popups);
125
- $scriptsLoader->loadToFooter();
126
- return;
127
-
128
- }
129
- }
130
-
131
- $popupBuilderPosts = new WP_Query(
132
- array(
133
- 'post_type' => SG_POPUP_POST_TYPE,
134
- 'posts_per_page' => -1
135
- )
136
- );
137
-
138
- // We check all the popups one by one to realize whether they might be loaded or not.
139
- while ($popupBuilderPosts->have_posts()) {
140
- $popupBuilderPosts->next_post();
141
- $popupPost = $popupBuilderPosts->post;
142
- $popup = SGPopup::find($popupPost);
143
- if (empty($popup) || !is_object($popup)) {
144
- continue;
145
- }
146
-
147
- if (($popup->getOptions()['sgpb-is-active'] && $popup->allowToLoad()) || (is_preview() && get_post_type() == SG_POPUP_POST_TYPE)) {
148
- $this->addLoadablePopup($popup);
149
- }
150
- }
151
-
152
- $this->doGroupFiltersPopups();
153
- $popups = $this->getLoadablePopups();
154
-
155
- $scriptsLoader = new ScriptsLoader();
156
- $scriptsLoader->setLoadablePopups($popups);
157
- $scriptsLoader->loadToFooter();
158
- }
159
- public function loadPopupAjax($popup)
160
- {
161
- $scriptsLoader = new ScriptsLoader();
162
- $scriptsLoader->setLoadablePopups([$popup]);
163
- $scriptsLoader->setIsAjax(true);
164
- $scriptsLoader->loadToFooter(true);
165
- $data = [
166
- 'scriptsAndStyles' => $scriptsLoader->getScriptsAndStylesForAjax(),
167
- 'footerContent' => $scriptsLoader->getFooterContentAjax(),
168
- ];
169
- return $data;
170
- }
171
-
172
- private function doGroupFiltersPopups()
173
- {
174
- $popups = $this->getLoadablePopups();
175
- $popups = $this->addPopupFromUrl($popups);
176
- $groupObj = new PopupGroupFilter();
177
- $groupObj->setPopups($popups);
178
- $popups = $groupObj->filter();
179
- $this->setLoadablePopups($popups);
180
- }
181
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \WP_Query;
4
+
5
+ class PopupLoader
6
+ {
7
+ private static $instance;
8
+ private $loadablePopups = array();
9
+ private $loadablePopupsIds = array();
10
+
11
+ private function __construct()
12
+ {
13
+ require_once(ABSPATH.'wp-admin/includes/plugin.php');
14
+ }
15
+
16
+ public static function instance() {
17
+
18
+ if (!isset(self::$instance)) {
19
+ self::$instance = new self;
20
+ }
21
+
22
+ return self::$instance;
23
+ }
24
+
25
+ public function setLoadablePopupsIds($loadablePopupsIds)
26
+ {
27
+ $this->loadablePopupsIds = $loadablePopupsIds;
28
+ }
29
+
30
+ public function getLoadablePopupsIds()
31
+ {
32
+ return $this->loadablePopupsIds;
33
+ }
34
+
35
+ public function addLoadablePopup($popupObj)
36
+ {
37
+ $this->loadablePopups[] = $popupObj;
38
+ }
39
+
40
+ public function setLoadablePopups($loadablePopups)
41
+ {
42
+ $this->loadablePopups = $loadablePopups;
43
+ }
44
+
45
+ public function getLoadablePopups()
46
+ {
47
+ return $this->loadablePopups;
48
+ }
49
+
50
+ public function addPopupFromUrl($popupsToLoad)
51
+ {
52
+ global $wp;
53
+ $currentUrl = home_url( $wp->request );
54
+ $currentUrl = strpos($currentUrl, '/popupbuilder/');
55
+ if (isset($_GET['sg_popup_id']) || isset($_GET['sg_popup_preview_id']) || $currentUrl !== false) {
56
+ $args = array();
57
+ $previewPopups = array();
58
+ $getterId = isset($_GET['sg_popup_id']) ? (int)$_GET['sg_popup_id'] : 0;
59
+ $previewedPopupId = isset($_GET['sg_popup_preview_id']) ? (int)$_GET['sg_popup_preview_id'] : 0;
60
+ if (isset($_GET['sg_popup_preview_id'])) {
61
+ $getterId = $previewedPopupId;
62
+ $args['is-preview'] = true;
63
+ }
64
+ if (function_exists('sgpb\sgpGetCorrectPopupId')) {
65
+ $getterId = sgpGetCorrectPopupId($getterId);
66
+ }
67
+ if ($currentUrl !== false) {
68
+ $getterId = $previewedPopupId;
69
+ if (isset($_GET['preview_id'])) {
70
+ $getterId = (int)$_GET['preview_id'];
71
+ }
72
+ }
73
+
74
+ $popupFromUrl = SGPopup::find($getterId, $args);
75
+ if (!empty($popupFromUrl)) {
76
+ global $SGPB_DATA_CONFIG_ARRAY;
77
+ $defaultEvent = array();
78
+ $customDelay = $popupFromUrl->getOptionValue('sgpb-popup-delay');
79
+ $defaultEvent[] = $SGPB_DATA_CONFIG_ARRAY['events']['initialData'][0];
80
+ $defaultEvent[0]['value'] = 0;
81
+ if ($customDelay) {
82
+ $defaultEvent[0]['value'] = $customDelay;
83
+ }
84
+ $popupFromUrl->setEvents($defaultEvent);
85
+ $popupsToLoad[] = $popupFromUrl;
86
+ $previewPopups[] = $popupFromUrl;
87
+ if (isset($_GET['sg_popup_preview_id'])) {
88
+ $popupsToLoad = $previewPopups;
89
+ }
90
+ }
91
+ }
92
+
93
+ return $popupsToLoad;
94
+ }
95
+
96
+ public function loadPopups()
97
+ {
98
+ $foundPopup = array();
99
+ if (is_preview()) {
100
+ global $post;
101
+ $foundPopup = $post;
102
+ }
103
+ if (!empty($foundPopup)) {
104
+ global $SGPB_DATA_CONFIG_ARRAY;
105
+ if (@$foundPopup->post_type == SG_POPUP_POST_TYPE) {
106
+ $events = $SGPB_DATA_CONFIG_ARRAY['events']['initialData'][0];
107
+ $targets = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
108
+ // for any targets preview popup should open
109
+ if (!empty($targets[0][0])) {
110
+ $targets[0][0]['param'] = 'post_all';
111
+ }
112
+
113
+ $popup = SGPopup::find($foundPopup);
114
+ if (empty($popup)) {
115
+ return;
116
+ }
117
+ $popup->setTarget($targets);
118
+ $popup->setEvents($events);
119
+
120
+ $this->addLoadablePopup($popup);
121
+ $this->doGroupFiltersPopups();
122
+ $popups = $this->getLoadablePopups();
123
+ $scriptsLoader = new ScriptsLoader();
124
+ $scriptsLoader->setLoadablePopups($popups);
125
+ $scriptsLoader->loadToFooter();
126
+ return;
127
+
128
+ }
129
+ }
130
+
131
+ $popupBuilderPosts = new WP_Query(
132
+ array(
133
+ 'post_type' => SG_POPUP_POST_TYPE,
134
+ 'posts_per_page' => -1
135
+ )
136
+ );
137
+
138
+ // We check all the popups one by one to realize whether they might be loaded or not.
139
+ while ($popupBuilderPosts->have_posts()) {
140
+ $popupBuilderPosts->next_post();
141
+ $popupPost = $popupBuilderPosts->post;
142
+ $popup = SGPopup::find($popupPost);
143
+ if (empty($popup) || !is_object($popup)) {
144
+ continue;
145
+ }
146
+
147
+ if (($popup->getOptions()['sgpb-is-active'] && $popup->allowToLoad()) || (is_preview() && get_post_type() == SG_POPUP_POST_TYPE)) {
148
+ $this->addLoadablePopup($popup);
149
+ }
150
+ }
151
+
152
+ $this->doGroupFiltersPopups();
153
+ $popups = $this->getLoadablePopups();
154
+
155
+ $scriptsLoader = new ScriptsLoader();
156
+ $scriptsLoader->setLoadablePopups($popups);
157
+ $scriptsLoader->loadToFooter();
158
+ }
159
+ public function loadPopupAjax($popup)
160
+ {
161
+ $scriptsLoader = new ScriptsLoader();
162
+ $scriptsLoader->setLoadablePopups([$popup]);
163
+ $scriptsLoader->setIsAjax(true);
164
+ $scriptsLoader->loadToFooter(true);
165
+ $data = [
166
+ 'scriptsAndStyles' => $scriptsLoader->getScriptsAndStylesForAjax(),
167
+ 'footerContent' => $scriptsLoader->getFooterContentAjax(),
168
+ ];
169
+ return $data;
170
+ }
171
+
172
+ private function doGroupFiltersPopups()
173
+ {
174
+ $popups = $this->getLoadablePopups();
175
+ $popups = $this->addPopupFromUrl($popups);
176
+ $groupObj = new PopupGroupFilter();
177
+ $groupObj->setPopups($popups);
178
+ $popups = $groupObj->filter();
179
+ $this->setLoadablePopups($popups);
180
+ }
181
+ }
com/classes/PopupType.php CHANGED
@@ -1,37 +1,37 @@
1
- <?php
2
- namespace sgpb;
3
- class PopupType
4
- {
5
- private $available = false;
6
- private $name = '';
7
- private $accessLevel = 1;
8
-
9
- public function setName($name)
10
- {
11
- $this->name = $name;
12
- }
13
- public function getName()
14
- {
15
- return $this->name;
16
- }
17
-
18
- public function setAvailable($available)
19
- {
20
- $this->available = $available;
21
- }
22
-
23
- public function isAvailable()
24
- {
25
- return $this->available;
26
- }
27
-
28
- public function setAccessLevel($accessLevel)
29
- {
30
- $this->accessLevel = $accessLevel;
31
- }
32
-
33
- public function getAccessLevel()
34
- {
35
- return $this->accessLevel;
36
- }
37
  }
1
+ <?php
2
+ namespace sgpb;
3
+ class PopupType
4
+ {
5
+ private $available = false;
6
+ private $name = '';
7
+ private $accessLevel = 1;
8
+
9
+ public function setName($name)
10
+ {
11
+ $this->name = $name;
12
+ }
13
+ public function getName()
14
+ {
15
+ return $this->name;
16
+ }
17
+
18
+ public function setAvailable($available)
19
+ {
20
+ $this->available = $available;
21
+ }
22
+
23
+ public function isAvailable()
24
+ {
25
+ return $this->available;
26
+ }
27
+
28
+ public function setAccessLevel($accessLevel)
29
+ {
30
+ $this->accessLevel = $accessLevel;
31
+ }
32
+
33
+ public function getAccessLevel()
34
+ {
35
+ return $this->accessLevel;
36
+ }
37
  }
com/classes/RegisterPostType.php CHANGED
@@ -1,478 +1,478 @@
1
- <?php
2
- namespace sgpb;
3
- use \SgpbDataConfig;
4
- use \SgpbPopupConfig;
5
- class RegisterPostType
6
- {
7
- private $popupTypeObj;
8
- private $popupType;
9
- private $popupId;
10
-
11
- public function setPopupType($popupType)
12
- {
13
- $this->popupType = $popupType;
14
- }
15
-
16
- public function getPopupType()
17
- {
18
- return $this->popupType;
19
- }
20
-
21
- public function setPopupId($popupId)
22
- {
23
- $this->popupId = $popupId;
24
- }
25
-
26
- public function getPopupId()
27
- {
28
- return $this->popupId;
29
- }
30
-
31
- public function __construct()
32
- {
33
- if (!AdminHelper::showMenuForCurrentUser()) {
34
- return false;
35
- }
36
- // its need here to an apply filters for add popup types needed data
37
- SgpbPopupConfig::popupTypesInit();
38
- $this->init();
39
- // Call init data configs apply filters
40
- SgpbDataConfig::init();
41
-
42
- return true;
43
- }
44
-
45
- public function setPopupTypeObj($popupTypeObj)
46
- {
47
- $this->popupTypeObj = $popupTypeObj;
48
- }
49
-
50
- public function getPopupTypeObj()
51
- {
52
- return $this->popupTypeObj;
53
- }
54
-
55
- public function getPostTypeArgs()
56
- {
57
- $labels = $this->getPostTypeLabels();
58
-
59
- $args = array(
60
- 'labels' => $labels,
61
- 'description' => __('Description.', 'your-plugin-textdomain'),
62
- // Exclude_from_search
63
- 'exclude_from_search' => true,
64
- 'public' => true,
65
- 'has_archive' => false,
66
- // Where to show the post type in the admin menu
67
- 'show_ui' => true,
68
- 'query_var' => false,
69
- 'rewrite' => array('slug' => SG_POPUP_POST_TYPE),
70
- 'map_meta_cap' => true,
71
- 'capability_type' => array('sgpb_popup', 'sgpb_popups'),
72
- 'menu_position' => 10,
73
- 'supports' => apply_filters('sgpbPostTypeSupport', array('title', 'editor')),
74
- 'menu_icon' => 'dashicons-menu-icon-sgpb',
75
- 'show_in_rest' => true
76
- );
77
-
78
- if (is_admin()) {
79
- $args['capability_type'] = 'post';
80
- }
81
-
82
- return $args;
83
- }
84
-
85
- public function getPostTypeLabels()
86
- {
87
- $count = SGPBNotificationCenter::getAllActiveNotifications();
88
- $count = '';
89
- $labels = array(
90
- 'name' => _x('Popup Builder', 'post type general name', SG_POPUP_TEXT_DOMAIN),
91
- 'singular_name' => _x('Popup', 'post type singular name', SG_POPUP_TEXT_DOMAIN),
92
- 'menu_name' => _x('Popup Builder', 'admin menu', SG_POPUP_TEXT_DOMAIN).$count,
93
- 'name_admin_bar' => _x('Popup', 'add new on admin bar', SG_POPUP_TEXT_DOMAIN),
94
- 'add_new' => _x('Add New', 'Popup', SG_POPUP_TEXT_DOMAIN),
95
- 'add_new_item' => __('Add New Popup', SG_POPUP_TEXT_DOMAIN),
96
- 'new_item' => __('New Popup', SG_POPUP_TEXT_DOMAIN),
97
- 'edit_item' => __('Edit Popup', SG_POPUP_TEXT_DOMAIN),
98
- 'view_item' => __('View Popup', SG_POPUP_TEXT_DOMAIN),
99
- 'all_items' => __('All Popups', SG_POPUP_TEXT_DOMAIN),
100
- 'search_items' => __('Search', SG_POPUP_TEXT_DOMAIN),
101
- 'parent_item_colon' => __('Parent Popups:', SG_POPUP_TEXT_DOMAIN),
102
- 'not_found' => __('No popups found.', SG_POPUP_TEXT_DOMAIN),
103
- 'not_found_in_trash' => __('No popups found in Trash.', SG_POPUP_TEXT_DOMAIN)
104
- );
105
-
106
- return $labels;
107
- }
108
-
109
- public function postTypeSupportForPopupTypes($supports)
110
- {
111
- $popupType = $this->getPopupTypeName();
112
- $typePath = $this->getPopupTypePathFormPopupType($popupType);
113
- $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
114
-
115
- if (!file_exists($typePath.$popupClassName.'.php')) {
116
- return $supports;
117
- }
118
-
119
- require_once($typePath.$popupClassName.'.php');
120
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
121
-
122
- // We need to remove wyswyg editor for some popup types and that’s why we are doing this check.
123
- if (method_exists($popupClassName, 'getPopupTypeSupports')) {
124
- $supports = $popupClassName::getPopupTypeSupports();
125
- }
126
-
127
- return $supports;
128
- }
129
-
130
- public function init()
131
- {
132
- add_filter('sgpbPostTypeSupport', array($this, 'postTypeSupportForPopupTypes'), 1, 1);
133
- $postType = SG_POPUP_POST_TYPE;
134
- $args = $this->getPostTypeArgs();
135
-
136
- register_post_type($postType, $args);
137
-
138
- $this->createPopupObjFromPopupType();
139
- }
140
-
141
- private function createPopupObjFromPopupType()
142
- {
143
- $popupId = 0;
144
-
145
- if (!empty($_GET['post'])) {
146
- $popupId = (int)$_GET['post'];
147
- }
148
-
149
- $popupType = $this->getPopupTypeName();
150
- $this->setPopupType($popupType);
151
- $this->setPopupId($popupId);
152
-
153
- $this->createPopupObj();
154
- }
155
-
156
- private function getPopupTypeName()
157
- {
158
- $popupType = 'html';
159
-
160
- /*
161
- * First, we try to find the popup type with the post id then,
162
- * if the post id doesn't exist, we try to find it with $_GET['sgpb_type']
163
- */
164
- if (!empty($_GET['post'])) {
165
- $popupId = (int)$_GET['post'];
166
- $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
167
- if (!empty($popupOptionsData['sgpb-type'])) {
168
- $popupType = $popupOptionsData['sgpb-type'];
169
- }
170
- }
171
- else if (!empty($_GET['sgpb_type'])) {
172
- $popupType = sanitize_text_field($_GET['sgpb_type']);
173
- }
174
-
175
- return $popupType;
176
- }
177
-
178
- private function getPopupClassNameFromPopupType($popupType)
179
- {
180
- $popupName = ucfirst(strtolower($popupType));
181
- $popupClassName = $popupName.'Popup';
182
-
183
- return $popupClassName;
184
- }
185
-
186
- private function getPopupTypePathFormPopupType($popupType)
187
- {
188
- global $SGPB_POPUP_TYPES;
189
- $typePath = '';
190
-
191
- if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
192
- $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
193
- }
194
-
195
- return $typePath;
196
- }
197
-
198
- public function createPopupObj()
199
- {
200
- $popupId = $this->getPopupId();
201
- $popupType = $this->getPopupType();
202
- $typePath = $this->getPopupTypePathFormPopupType($popupType);
203
- $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
204
-
205
- if (!file_exists($typePath.$popupClassName.'.php')) {
206
- die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
207
- }
208
- require_once($typePath.$popupClassName.'.php');
209
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
210
- $popupTypeObj = new $popupClassName();
211
- $popupTypeObj->setId($popupId);
212
- $popupTypeObj->setType($popupType);
213
- $this->setPopupTypeObj($popupTypeObj);
214
-
215
- $popupTypeMainView = $popupTypeObj->getPopupTypeMainView();
216
- $popupTypeViewData = $popupTypeObj->getPopupTypeOptionsView();
217
-
218
- if (!empty($popupTypeMainView)) {
219
- add_filter('sgpbAdditionalMetaboxes', array($this, 'sgpbPopupTypeMainViewMetaboxes'), 1, 1);
220
- //add_action('add_meta_boxes', array($this, 'popupTypeMain'));
221
- }
222
- if (!empty($popupTypeViewData)) {
223
- //add_action('add_meta_boxes', array($this, 'popupTypeOptions'));
224
- add_filter('sgpbAdditionalMetaboxes', array($this, 'sgpbPopupTypeOptionsViewMetaboxes'), 1, 1);
225
- }
226
- if ($popupType == 'subscription') {
227
- add_action('add_meta_boxes', array($this, 'rightBannerMetabox'));
228
- }
229
- }
230
-
231
- public function rightBannerMetabox()
232
- {
233
- $banner = AdminHelper::getRightMetaboxBannerText();
234
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
235
- if ($banner == '' || $isSubscriptionPlusActive) {
236
- return;
237
- }
238
- add_meta_box(
239
- 'popupTypeRightBannerView',
240
- __('News', SG_POPUP_TEXT_DOMAIN),
241
- array($this, 'popupTypeRightBannerView'),
242
- SG_POPUP_POST_TYPE,
243
- 'side',
244
- 'low'
245
- );
246
- }
247
-
248
- public function sgpbPopupTypeMainViewMetaboxes($metaboxes)
249
- {
250
- $popupTypeObj = $this->getPopupTypeObj();
251
- $optionsView = $popupTypeObj->getPopupTypeMainView();
252
- $typeView = array();
253
-
254
- $metaboxes['popupTypeMainView'] = array(
255
- 'key' => 'popupTypeMainView',
256
- 'displayName' => __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
257
- 'filePath' => $optionsView['filePath'],
258
- 'short_description' => $optionsView['short_description'],
259
- SG_POPUP_POST_TYPE,
260
- 'normal',
261
- 'high'
262
- );
263
-
264
- return $metaboxes;
265
- }
266
-
267
- public function popupTypeMain()
268
- {
269
- $popupTypeObj = $this->getPopupTypeObj();
270
- $optionsView = $popupTypeObj->getPopupTypeMainView();
271
- add_meta_box(
272
- 'popupTypeMainView',
273
- __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
274
- array($this, 'popupTypeMainView'),
275
- SG_POPUP_POST_TYPE,
276
- 'normal',
277
- 'high'
278
- );
279
- }
280
-
281
- public function sgpbPopupTypeOptionsViewMetaboxes($metaboxes)
282
- {
283
- $popupTypeObj = $this->getPopupTypeObj();
284
- $optionsView = $popupTypeObj->getPopupTypeOptionsView();
285
-
286
- $metaboxes['popupTypeOptionsView'] = array(
287
- 'key' => 'popupTypeOptionsView',
288
- 'displayName' => __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
289
- 'short_description' => $optionsView['short_description'],
290
- 'filePath' => $optionsView['filePath'],
291
- SG_POPUP_POST_TYPE,
292
- 'normal',
293
- 'high'
294
- );
295
-
296
- return $metaboxes;
297
- }
298
-
299
- public function popupTypeOptions()
300
- {
301
- $popupTypeObj = $this->getPopupTypeObj();
302
- $optionsView = $popupTypeObj->getPopupTypeOptionsView();
303
- add_meta_box(
304
- 'popupTypeOptionsView',
305
- __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
306
- array($this, 'popupTypeOptionsView'),
307
- SG_POPUP_POST_TYPE,
308
- 'normal',
309
- 'high'
310
- );
311
- }
312
-
313
- public function supportLinks()
314
- {
315
- add_submenu_page(
316
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
317
- __('Settings', SG_POPUP_TEXT_DOMAIN),
318
- __('Settings', SG_POPUP_TEXT_DOMAIN),
319
- 'manage_options',
320
- SG_POPUP_SETTINGS_PAGE,
321
- array($this, 'settings')
322
- );
323
-
324
- add_submenu_page(
325
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
326
- __('Extend', SG_POPUP_TEXT_DOMAIN),
327
- __('Extend', SG_POPUP_TEXT_DOMAIN),
328
- 'sgpb_manage_options',
329
- SG_POPUP_EXTEND_PAGE,
330
- array($this, 'extendLink')
331
- );
332
-
333
- add_submenu_page(
334
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
335
- __('Support', SG_POPUP_TEXT_DOMAIN),
336
- __('Support', SG_POPUP_TEXT_DOMAIN),
337
- 'sgpb_manage_options',
338
- SG_POPUP_SUPPORT_PAGE,
339
- array($this, 'supportLink')
340
- );
341
- }
342
-
343
- public function addSubMenu()
344
- {
345
- add_submenu_page(
346
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
347
- __('Add New', SG_POPUP_TEXT_DOMAIN),
348
- __('Add New', SG_POPUP_TEXT_DOMAIN),
349
- 'sgpb_manage_options',
350
- SG_POPUP_POST_TYPE,
351
- array($this, 'popupTypesPage')
352
- );
353
-
354
- add_submenu_page(
355
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
356
- __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
357
- __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
358
- 'sgpb_manage_options',
359
- SG_POPUP_SUBSCRIBERS_PAGE,
360
- array($this, 'subscribersPage')
361
- );
362
-
363
- add_submenu_page(
364
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
365
- __('Newsletter', SG_POPUP_TEXT_DOMAIN),
366
- __('Newsletter', SG_POPUP_TEXT_DOMAIN),
367
- 'sgpb_manage_options',
368
- SG_POPUP_NEWSLETTER_PAGE,
369
- array($this, 'newsletter')
370
- );
371
- }
372
-
373
- public function supportLink()
374
- {
375
- wp_redirect(SG_POPUP_SUPPORT_URL);
376
- }
377
-
378
- public function extendLink()
379
- {
380
- wp_redirect(SG_POPUP_EXTENSIONS_URL);
381
- }
382
-
383
- public function addOptionsMetaBox()
384
- {
385
- add_meta_box(
386
- 'optionsMetaboxView',
387
- __('Advanced', SG_POPUP_TEXT_DOMAIN),
388
- array($this, 'optionsMetaboxView'),
389
- SG_POPUP_POST_TYPE,
390
- 'normal',
391
- 'low'
392
- );
393
- }
394
-
395
- public function addPopupMetaboxes()
396
- {
397
- $additionalMetaboxes = apply_filters('sgpbAdditionalMetaboxes', array());
398
-
399
- if (empty($additionalMetaboxes)) {
400
- return false;
401
- }
402
-
403
-
404
- $context = 'normal';
405
- $priority = 'high';
406
- $key = 'allMetaboxesView';
407
- $metabox = $additionalMetaboxes['allMetaboxesView'];
408
- $popupTypeObj = $this->getPopupTypeObj();
409
- $filepath = $metabox['filePath'];
410
-
411
- add_meta_box(
412
- $key,
413
- __($metabox['displayName'], SG_POPUP_TEXT_DOMAIN),
414
- function() use ($filepath, $popupTypeObj) {
415
- require_once $filepath;
416
- },
417
- SG_POPUP_POST_TYPE,
418
- $context,
419
- $priority
420
- );
421
-
422
- remove_meta_box('popup-categoriesdiv', SG_POPUP_POST_TYPE, 'side');
423
-
424
- return true;
425
- }
426
-
427
- public function popupTypesPage()
428
- {
429
- if (file_exists(SG_POPUP_VIEWS_PATH.'popupTypes.php')) {
430
- require_once(SG_POPUP_VIEWS_PATH.'popupTypes.php');
431
- }
432
- }
433
-
434
- public function subscribersPage()
435
- {
436
- if (file_exists(SG_POPUP_VIEWS_PATH.'subscribers.php')) {
437
- require_once(SG_POPUP_VIEWS_PATH . 'subscribers.php');
438
- }
439
- }
440
-
441
- public function settings()
442
- {
443
- if (file_exists(SG_POPUP_VIEWS_PATH.'settings.php')) {
444
- require_once(SG_POPUP_VIEWS_PATH.'settings.php');
445
- }
446
- }
447
-
448
- public function newsletter()
449
- {
450
- if (file_exists(SG_POPUP_VIEWS_PATH.'newsletter.php')) {
451
- require_once(SG_POPUP_VIEWS_PATH.'newsletter.php');
452
- }
453
- }
454
-
455
- public function popupTypeOptionsView()
456
- {
457
- $popupTypeObj = $this->getPopupTypeObj();
458
- $optionsView = $popupTypeObj->getPopupTypeOptionsView();
459
- if (file_exists($optionsView['filePath'])) {
460
- require_once($optionsView['filePath']);
461
- }
462
- }
463
-
464
- public function popupTypeMainView()
465
- {
466
- $popupTypeObj = $this->getPopupTypeObj();
467
- $optionsView = $popupTypeObj->getPopupTypeMainView();
468
- if (file_exists($optionsView['filePath'])) {
469
- require_once($optionsView['filePath']);
470
- }
471
- }
472
-
473
- public function popupTypeRightBannerView()
474
- {
475
- $banner = AdminHelper::getRightMetaboxBannerText();
476
- echo $banner;
477
- }
478
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \SgpbDataConfig;
4
+ use \SgpbPopupConfig;
5
+ class RegisterPostType
6
+ {
7
+ private $popupTypeObj;
8
+ private $popupType;
9
+ private $popupId;
10
+
11
+ public function setPopupType($popupType)
12
+ {
13
+ $this->popupType = $popupType;
14
+ }
15
+
16
+ public function getPopupType()
17
+ {
18
+ return $this->popupType;
19
+ }
20
+
21
+ public function setPopupId($popupId)
22
+ {
23
+ $this->popupId = $popupId;
24
+ }
25
+
26
+ public function getPopupId()
27
+ {
28
+ return $this->popupId;
29
+ }
30
+
31
+ public function __construct()
32
+ {
33
+ if (!AdminHelper::showMenuForCurrentUser()) {
34
+ return false;
35
+ }
36
+ // its need here to an apply filters for add popup types needed data
37
+ SgpbPopupConfig::popupTypesInit();
38
+ $this->init();
39
+ // Call init data configs apply filters
40
+ SgpbDataConfig::init();
41
+
42
+ return true;
43
+ }
44
+
45
+ public function setPopupTypeObj($popupTypeObj)
46
+ {
47
+ $this->popupTypeObj = $popupTypeObj;
48
+ }
49
+
50
+ public function getPopupTypeObj()
51
+ {
52
+ return $this->popupTypeObj;
53
+ }
54
+
55
+ public function getPostTypeArgs()
56
+ {
57
+ $labels = $this->getPostTypeLabels();
58
+
59
+ $args = array(
60
+ 'labels' => $labels,
61
+ 'description' => __('Description.', 'your-plugin-textdomain'),
62
+ // Exclude_from_search
63
+ 'exclude_from_search' => true,
64
+ 'public' => true,
65
+ 'has_archive' => false,
66
+ // Where to show the post type in the admin menu
67
+ 'show_ui' => true,
68
+ 'query_var' => false,
69
+ 'rewrite' => array('slug' => SG_POPUP_POST_TYPE),
70
+ 'map_meta_cap' => true,
71
+ 'capability_type' => array('sgpb_popup', 'sgpb_popups'),
72
+ 'menu_position' => 10,
73
+ 'supports' => apply_filters('sgpbPostTypeSupport', array('title', 'editor')),
74
+ 'menu_icon' => 'dashicons-menu-icon-sgpb',
75
+ 'show_in_rest' => true
76
+ );
77
+
78
+ if (is_admin()) {
79
+ $args['capability_type'] = 'post';
80
+ }
81
+
82
+ return $args;
83
+ }
84
+
85
+ public function getPostTypeLabels()
86
+ {
87
+ $count = SGPBNotificationCenter::getAllActiveNotifications();
88
+ $count = '';
89
+ $labels = array(
90
+ 'name' => _x('Popup Builder', 'post type general name', SG_POPUP_TEXT_DOMAIN),
91
+ 'singular_name' => _x('Popup', 'post type singular name', SG_POPUP_TEXT_DOMAIN),
92
+ 'menu_name' => _x('Popup Builder', 'admin menu', SG_POPUP_TEXT_DOMAIN).$count,
93
+ 'name_admin_bar' => _x('Popup', 'add new on admin bar', SG_POPUP_TEXT_DOMAIN),
94
+ 'add_new' => _x('Add New', 'Popup', SG_POPUP_TEXT_DOMAIN),
95
+ 'add_new_item' => __('Add New Popup', SG_POPUP_TEXT_DOMAIN),
96
+ 'new_item' => __('New Popup', SG_POPUP_TEXT_DOMAIN),
97
+ 'edit_item' => __('Edit Popup', SG_POPUP_TEXT_DOMAIN),
98
+ 'view_item' => __('View Popup', SG_POPUP_TEXT_DOMAIN),
99
+ 'all_items' => __('All Popups', SG_POPUP_TEXT_DOMAIN),
100
+ 'search_items' => __('Search', SG_POPUP_TEXT_DOMAIN),
101
+ 'parent_item_colon' => __('Parent Popups:', SG_POPUP_TEXT_DOMAIN),
102
+ 'not_found' => __('No popups found.', SG_POPUP_TEXT_DOMAIN),
103
+ 'not_found_in_trash' => __('No popups found in Trash.', SG_POPUP_TEXT_DOMAIN)
104
+ );
105
+
106
+ return $labels;
107
+ }
108
+
109
+ public function postTypeSupportForPopupTypes($supports)
110
+ {
111
+ $popupType = $this->getPopupTypeName();
112
+ $typePath = $this->getPopupTypePathFormPopupType($popupType);
113
+ $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
114
+
115
+ if (!file_exists($typePath.$popupClassName.'.php')) {
116
+ return $supports;
117
+ }
118
+
119
+ require_once($typePath.$popupClassName.'.php');
120
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
121
+
122
+ // We need to remove wyswyg editor for some popup types and that’s why we are doing this check.
123
+ if (method_exists($popupClassName, 'getPopupTypeSupports')) {
124
+ $supports = $popupClassName::getPopupTypeSupports();
125
+ }
126
+
127
+ return $supports;
128
+ }
129
+
130
+ public function init()
131
+ {
132
+ add_filter('sgpbPostTypeSupport', array($this, 'postTypeSupportForPopupTypes'), 1, 1);
133
+ $postType = SG_POPUP_POST_TYPE;
134
+ $args = $this->getPostTypeArgs();
135
+
136
+ register_post_type($postType, $args);
137
+
138
+ $this->createPopupObjFromPopupType();
139
+ }
140
+
141
+ private function createPopupObjFromPopupType()
142
+ {
143
+ $popupId = 0;
144
+
145
+ if (!empty($_GET['post'])) {
146
+ $popupId = (int)$_GET['post'];
147
+ }
148
+
149
+ $popupType = $this->getPopupTypeName();
150
+ $this->setPopupType($popupType);
151
+ $this->setPopupId($popupId);
152
+
153
+ $this->createPopupObj();
154
+ }
155
+
156
+ private function getPopupTypeName()
157
+ {
158
+ $popupType = 'html';
159
+
160
+ /*
161
+ * First, we try to find the popup type with the post id then,
162
+ * if the post id doesn't exist, we try to find it with $_GET['sgpb_type']
163
+ */
164
+ if (!empty($_GET['post'])) {
165
+ $popupId = (int)$_GET['post'];
166
+ $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
167
+ if (!empty($popupOptionsData['sgpb-type'])) {
168
+ $popupType = $popupOptionsData['sgpb-type'];
169
+ }
170
+ }
171
+ else if (!empty($_GET['sgpb_type'])) {
172
+ $popupType = sanitize_text_field($_GET['sgpb_type']);
173
+ }
174
+
175
+ return $popupType;
176
+ }
177
+
178
+ private function getPopupClassNameFromPopupType($popupType)
179
+ {
180
+ $popupName = ucfirst(strtolower($popupType));
181
+ $popupClassName = $popupName.'Popup';
182
+
183
+ return $popupClassName;
184
+ }
185
+
186
+ private function getPopupTypePathFormPopupType($popupType)
187
+ {
188
+ global $SGPB_POPUP_TYPES;
189
+ $typePath = '';
190
+
191
+ if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
192
+ $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
193
+ }
194
+
195
+ return $typePath;
196
+ }
197
+
198
+ public function createPopupObj()
199
+ {
200
+ $popupId = $this->getPopupId();
201
+ $popupType = $this->getPopupType();
202
+ $typePath = $this->getPopupTypePathFormPopupType($popupType);
203
+ $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
204
+
205
+ if (!file_exists($typePath.$popupClassName.'.php')) {
206
+ die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
207
+ }
208
+ require_once($typePath.$popupClassName.'.php');
209
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
210
+ $popupTypeObj = new $popupClassName();
211
+ $popupTypeObj->setId($popupId);
212
+ $popupTypeObj->setType($popupType);
213
+ $this->setPopupTypeObj($popupTypeObj);
214
+
215
+ $popupTypeMainView = $popupTypeObj->getPopupTypeMainView();
216
+ $popupTypeViewData = $popupTypeObj->getPopupTypeOptionsView();
217
+
218
+ if (!empty($popupTypeMainView)) {
219
+ add_filter('sgpbAdditionalMetaboxes', array($this, 'sgpbPopupTypeMainViewMetaboxes'), 1, 1);
220
+ //add_action('add_meta_boxes', array($this, 'popupTypeMain'));
221
+ }
222
+ if (!empty($popupTypeViewData)) {
223
+ //add_action('add_meta_boxes', array($this, 'popupTypeOptions'));
224
+ add_filter('sgpbAdditionalMetaboxes', array($this, 'sgpbPopupTypeOptionsViewMetaboxes'), 1, 1);
225
+ }
226
+ if ($popupType == 'subscription') {
227
+ add_action('add_meta_boxes', array($this, 'rightBannerMetabox'));
228
+ }
229
+ }
230
+
231
+ public function rightBannerMetabox()
232
+ {
233
+ $banner = AdminHelper::getRightMetaboxBannerText();
234
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
235
+ if ($banner == '' || $isSubscriptionPlusActive) {
236
+ return;
237
+ }
238
+ add_meta_box(
239
+ 'popupTypeRightBannerView',
240
+ __('News', SG_POPUP_TEXT_DOMAIN),
241
+ array($this, 'popupTypeRightBannerView'),
242
+ SG_POPUP_POST_TYPE,
243
+ 'side',
244
+ 'low'
245
+ );
246
+ }
247
+
248
+ public function sgpbPopupTypeMainViewMetaboxes($metaboxes)
249
+ {
250
+ $popupTypeObj = $this->getPopupTypeObj();
251
+ $optionsView = $popupTypeObj->getPopupTypeMainView();
252
+ $typeView = array();
253
+
254
+ $metaboxes['popupTypeMainView'] = array(
255
+ 'key' => 'popupTypeMainView',
256
+ 'displayName' => __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
257
+ 'filePath' => $optionsView['filePath'],
258
+ 'short_description' => $optionsView['short_description'],
259
+ SG_POPUP_POST_TYPE,
260
+ 'normal',
261
+ 'high'
262
+ );
263
+
264
+ return $metaboxes;
265
+ }
266
+
267
+ public function popupTypeMain()
268
+ {
269
+ $popupTypeObj = $this->getPopupTypeObj();
270
+ $optionsView = $popupTypeObj->getPopupTypeMainView();
271
+ add_meta_box(
272
+ 'popupTypeMainView',
273
+ __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
274
+ array($this, 'popupTypeMainView'),
275
+ SG_POPUP_POST_TYPE,
276
+ 'normal',
277
+ 'high'
278
+ );
279
+ }
280
+
281
+ public function sgpbPopupTypeOptionsViewMetaboxes($metaboxes)
282
+ {
283
+ $popupTypeObj = $this->getPopupTypeObj();
284
+ $optionsView = $popupTypeObj->getPopupTypeOptionsView();
285
+
286
+ $metaboxes['popupTypeOptionsView'] = array(
287
+ 'key' => 'popupTypeOptionsView',
288
+ 'displayName' => __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
289
+ 'short_description' => $optionsView['short_description'],
290
+ 'filePath' => $optionsView['filePath'],
291
+ SG_POPUP_POST_TYPE,
292
+ 'normal',
293
+ 'high'
294
+ );
295
+
296
+ return $metaboxes;
297
+ }
298
+
299
+ public function popupTypeOptions()
300
+ {
301
+ $popupTypeObj = $this->getPopupTypeObj();
302
+ $optionsView = $popupTypeObj->getPopupTypeOptionsView();
303
+ add_meta_box(
304
+ 'popupTypeOptionsView',
305
+ __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
306
+ array($this, 'popupTypeOptionsView'),
307
+ SG_POPUP_POST_TYPE,
308
+ 'normal',
309
+ 'high'
310
+ );
311
+ }
312
+
313
+ public function supportLinks()
314
+ {
315
+ add_submenu_page(
316
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
317
+ __('Settings', SG_POPUP_TEXT_DOMAIN),
318
+ __('Settings', SG_POPUP_TEXT_DOMAIN),
319
+ 'manage_options',
320
+ SG_POPUP_SETTINGS_PAGE,
321
+ array($this, 'settings')
322
+ );
323
+
324
+ add_submenu_page(
325
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
326
+ __('Extend', SG_POPUP_TEXT_DOMAIN),
327
+ __('Extend', SG_POPUP_TEXT_DOMAIN),
328
+ 'sgpb_manage_options',
329
+ SG_POPUP_EXTEND_PAGE,
330
+ array($this, 'extendLink')
331
+ );
332
+
333
+ add_submenu_page(
334
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
335
+ __('Support', SG_POPUP_TEXT_DOMAIN),
336
+ __('Support', SG_POPUP_TEXT_DOMAIN),
337
+ 'sgpb_manage_options',
338
+ SG_POPUP_SUPPORT_PAGE,
339
+ array($this, 'supportLink')
340
+ );
341
+ }
342
+
343
+ public function addSubMenu()
344
+ {
345
+ add_submenu_page(
346
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
347
+ __('Add New', SG_POPUP_TEXT_DOMAIN),
348
+ __('Add New', SG_POPUP_TEXT_DOMAIN),
349
+ 'sgpb_manage_options',
350
+ SG_POPUP_POST_TYPE,
351
+ array($this, 'popupTypesPage')
352
+ );
353
+
354
+ add_submenu_page(
355
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
356
+ __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
357
+ __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
358
+ 'sgpb_manage_options',
359
+ SG_POPUP_SUBSCRIBERS_PAGE,
360
+ array($this, 'subscribersPage')
361
+ );
362
+
363
+ add_submenu_page(
364
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
365
+ __('Newsletter', SG_POPUP_TEXT_DOMAIN),
366
+ __('Newsletter', SG_POPUP_TEXT_DOMAIN),
367
+ 'sgpb_manage_options',
368
+ SG_POPUP_NEWSLETTER_PAGE,
369
+ array($this, 'newsletter')
370
+ );
371
+ }
372
+
373
+ public function supportLink()
374
+ {
375
+ wp_redirect(SG_POPUP_SUPPORT_URL);
376
+ }
377
+
378
+ public function extendLink()
379
+ {
380
+ wp_redirect(SG_POPUP_EXTENSIONS_URL);
381
+ }
382
+
383
+ public function addOptionsMetaBox()
384
+ {
385
+ add_meta_box(
386
+ 'optionsMetaboxView',
387
+ __('Advanced', SG_POPUP_TEXT_DOMAIN),
388
+ array($this, 'optionsMetaboxView'),
389
+ SG_POPUP_POST_TYPE,
390
+ 'normal',
391
+ 'low'
392
+ );
393
+ }
394
+
395
+ public function addPopupMetaboxes()
396
+ {
397
+ $additionalMetaboxes = apply_filters('sgpbAdditionalMetaboxes', array());
398
+
399
+ if (empty($additionalMetaboxes)) {
400
+ return false;
401
+ }
402
+
403
+
404
+ $context = 'normal';
405
+ $priority = 'high';
406
+ $key = 'allMetaboxesView';
407
+ $metabox = $additionalMetaboxes['allMetaboxesView'];
408
+ $popupTypeObj = $this->getPopupTypeObj();
409
+ $filepath = $metabox['filePath'];
410
+
411
+ add_meta_box(
412
+ $key,
413
+ __($metabox['displayName'], SG_POPUP_TEXT_DOMAIN),
414
+ function() use ($filepath, $popupTypeObj) {
415
+ require_once $filepath;
416
+ },
417
+ SG_POPUP_POST_TYPE,
418
+ $context,
419
+ $priority
420
+ );
421
+
422
+ remove_meta_box('popup-categoriesdiv', SG_POPUP_POST_TYPE, 'side');
423
+
424
+ return true;
425
+ }
426
+
427
+ public function popupTypesPage()
428
+ {
429
+ if (file_exists(SG_POPUP_VIEWS_PATH.'popupTypes.php')) {
430
+ require_once(SG_POPUP_VIEWS_PATH.'popupTypes.php');
431
+ }
432
+ }
433
+
434
+ public function subscribersPage()
435
+ {
436
+ if (file_exists(SG_POPUP_VIEWS_PATH.'subscribers.php')) {
437
+ require_once(SG_POPUP_VIEWS_PATH . 'subscribers.php');
438
+ }
439
+ }
440
+
441
+ public function settings()
442
+ {
443
+ if (file_exists(SG_POPUP_VIEWS_PATH.'settings.php')) {
444
+ require_once(SG_POPUP_VIEWS_PATH.'settings.php');
445
+ }
446
+ }
447
+
448
+ public function newsletter()
449
+ {
450
+ if (file_exists(SG_POPUP_VIEWS_PATH.'newsletter.php')) {
451
+ require_once(SG_POPUP_VIEWS_PATH.'newsletter.php');
452
+ }
453
+ }
454
+
455
+ public function popupTypeOptionsView()
456
+ {
457
+ $popupTypeObj = $this->getPopupTypeObj();
458
+ $optionsView = $popupTypeObj->getPopupTypeOptionsView();
459
+ if (file_exists($optionsView['filePath'])) {
460
+ require_once($optionsView['filePath']);
461
+ }
462
+ }
463
+
464
+ public function popupTypeMainView()
465
+ {
466
+ $popupTypeObj = $this->getPopupTypeObj();
467
+ $optionsView = $popupTypeObj->getPopupTypeMainView();
468
+ if (file_exists($optionsView['filePath'])) {
469
+ require_once($optionsView['filePath']);
470
+ }
471
+ }
472
+
473
+ public function popupTypeRightBannerView()
474
+ {
475
+ $banner = AdminHelper::getRightMetaboxBannerText();
476
+ echo $banner;
477
+ }
478
+ }
com/classes/SGPBRequirementsChecker.php CHANGED
@@ -1,16 +1,16 @@
1
- <?php
2
- class SGPBRequirementsChecker
3
- {
4
- public static function init()
5
- {
6
- self::checkPhpVersion();
7
- }
8
-
9
- public static function checkPhpVersion()
10
- {
11
- if (version_compare(PHP_VERSION, SG_POPUP_MINIMUM_PHP_VERSION, '<')) {
12
- wp_die('Popup Builder plugin requires PHP version >= '.SG_POPUP_MINIMUM_PHP_VERSION.' version required. You server using PHP version = '.PHP_VERSION);
13
- }
14
- }
15
- }
16
-
1
+ <?php
2
+ class SGPBRequirementsChecker
3
+ {
4
+ public static function init()
5
+ {
6
+ self::checkPhpVersion();
7
+ }
8
+
9
+ public static function checkPhpVersion()
10
+ {
11
+ if (version_compare(PHP_VERSION, SG_POPUP_MINIMUM_PHP_VERSION, '<')) {
12
+ wp_die('Popup Builder plugin requires PHP version >= '.SG_POPUP_MINIMUM_PHP_VERSION.' version required. You server using PHP version = '.PHP_VERSION);
13
+ }
14
+ }
15
+ }
16
+
com/classes/ScriptsLoader.php CHANGED
@@ -1,406 +1,406 @@
1
- <?php
2
-
3
- namespace sgpb;
4
-
5
- // load popups data's from popups object
6
- class ScriptsLoader
7
- {
8
- // all loadable popups objects
9
- private $loadablePopups = array();
10
- private $isAdmin = false;
11
- private $isAjax = false;
12
- private $scriptsAndStylesForAjax;
13
- private $footerContentAjax;
14
- private static $alreadyLoadedPopups = array();
15
-
16
- public function setLoadablePopups($loadablePopups)
17
- {
18
- $this->loadablePopups = $loadablePopups;
19
- }
20
-
21
- public function getLoadablePopups()
22
- {
23
- return apply_filters('sgpbLoadablePopups', $this->loadablePopups);
24
- }
25
-
26
- public function setIsAdmin($isAdmin)
27
- {
28
- $this->isAdmin = $isAdmin;
29
- }
30
-
31
- public function getIsAdmin()
32
- {
33
- return $this->isAdmin;
34
- }
35
-
36
- /* for ajax calls */
37
- public function setIsAjax($isAjax)
38
- {
39
- $this->isAjax = $isAjax;
40
- }
41
-
42
- public function getIsAjax()
43
- {
44
- return $this->isAjax;
45
- }
46
-
47
- public function setFooterContentAjax($footerContentAjax)
48
- {
49
- $this->footerContentAjax = $footerContentAjax;
50
- }
51
-
52
- public function getFooterContentAjax()
53
- {
54
- return $this->footerContentAjax;
55
- }
56
-
57
- /**
58
- * Get encoded popup options
59
- *
60
- * @since 3.0.4
61
- *
62
- * @param object $popup
63
- *
64
- * @return array|mixed|string|void $popupOptions
65
- */
66
- private function getEncodedOptionsFromPopup($popup)
67
- {
68
- $extraOptions = $popup->getExtraRenderOptions();
69
- $popupOptions = $popup->getOptions();
70
- $popupOptions = apply_filters('sgpbPopupRenderOptions', $popupOptions);
71
- $popupCondition = $popup->getConditions();
72
-
73
- $popupOptions = array_merge($popupOptions, $extraOptions);
74
- $popupOptions['sgpbConditions'] = apply_filters('sgpbRenderCondtions', $popupCondition);
75
- // These two lines have been added in order to not use the json_econde and to support PHP 5.3 version.
76
- $popupOptions = AdminHelper::serializeData($popupOptions);
77
- $popupOptions = base64_encode($popupOptions);
78
-
79
- return $popupOptions;
80
- }
81
-
82
- // load popup scripts and styles and add popup data to the footer
83
- public function loadToFooter($isFromAjax = false)
84
- {
85
- $popups = $this->getLoadablePopups();
86
- $currentPostType = AdminHelper::getCurrentPostType();
87
- global $wp;
88
- $currentUrl = home_url( $wp->request );
89
- $currentUrl = strpos($currentUrl, '/popupbuilder/');
90
-
91
- // during preview wp request is empty that is why we check query_string
92
- if (is_preview()) {
93
- $currentUrl = strrpos($wp->query_string, 'popupbuilder');
94
- }
95
-
96
- if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
97
- return false;
98
- }
99
-
100
- if (empty($popups)) {
101
- return false;
102
- }
103
-
104
- global $post;
105
- $postId = 0;
106
-
107
- if (!empty($post)) {
108
- $postId = $post->ID;
109
- }
110
-
111
- if ($this->getIsAdmin()) {
112
- $this->loadToAdmin();
113
- return true;
114
- }
115
- $footerContentAjax = '';
116
-
117
- foreach ($popups as $popup) {
118
- $isActive = $popup->isActive();
119
- if (!$isActive) {
120
- continue;
121
- }
122
-
123
- $popupId = $popup->getId();
124
-
125
- $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
126
-
127
- $events = $popup->getPopupAllEvents($postId, $popupId, $popup);
128
-
129
- // if popup's data has already loaded into the page with the same event
130
- if (isset(self::$alreadyLoadedPopups[$popupId])) {
131
- if (self::$alreadyLoadedPopups[$popupId] == $events) {
132
- continue;
133
- }
134
- }
135
- foreach ($events as $event) {
136
- if (isset($event['param'])) {
137
- if (isset(self::$alreadyLoadedPopups[$popupId])) {
138
- if (self::$alreadyLoadedPopups[$popupId] == $event['param']) {
139
- continue;
140
- }
141
- }
142
- }
143
- }
144
-
145
- self::$alreadyLoadedPopups[$popupId] = $events;
146
- $events = json_encode($events);
147
- $currentUseOptions = $popup->getOptions();
148
- $extraContent = apply_filters('sgpbPopupExtraData', $popupId, $currentUseOptions);
149
-
150
- $popupOptions = $this->getEncodedOptionsFromPopup($popup);
151
- $popupOptions = apply_filters('sgpbLoadToFooterOptions', $popupOptions);
152
- if ($isFromAjax) {
153
- $footerPopupContent = '<div class="sgpb-main-popup-data-container-'.$popupId.'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
154
- <div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
155
- <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
156
- </div>
157
- </div>';
158
- $footerPopupContent .= $extraContent;
159
- $footerContentAjax .= $footerPopupContent;
160
- } else {
161
- add_action('wp_footer', function() use ($popupId, $events, $popupOptions, $popupContent, $extraContent) {
162
- $footerPopupContent = '<div class="sgpb-main-popup-data-container-'.$popupId.'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
163
- <div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
164
- <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
165
- </div>
166
- </div>';
167
- $footerPopupContent .= $extraContent;
168
- echo $footerPopupContent;
169
- });
170
- }
171
- }
172
-
173
- $this->includeScripts();
174
- $this->includeStyles();
175
- if ($isFromAjax){
176
- $this->setFooterContentAjax($footerContentAjax);
177
- }
178
- }
179
-
180
- public function loadToAdmin()
181
- {
182
- $popups = $this->getLoadablePopups();
183
-
184
- foreach ($popups as $popup) {
185
- $popupId = $popup->getId();
186
-
187
- $events = array();
188
-
189
- $events = json_encode($events);
190
-
191
- $popupOptions = $this->getEncodedOptionsFromPopup($popup);
192
-
193
- $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
194
-
195
- add_action('admin_footer', function() use ($popupId, $events, $popupOptions, $popupContent) {
196
- $footerPopupContent = '<div style="position:absolute;top: -999999999999999999999px;">
197
- <div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
198
- <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
199
- </div>
200
- </div>';
201
-
202
- echo $footerPopupContent;
203
- });
204
- }
205
- $this->includeScripts();
206
- $this->includeStyles();
207
-
208
- }
209
-
210
- private function includeScripts()
211
- {
212
- global $post;
213
- global $wp_version;
214
- $popups = $this->getLoadablePopups();
215
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
216
-
217
- if (!$registeredPlugins) {
218
- return;
219
- }
220
- $registeredPlugins = json_decode($registeredPlugins, true);
221
-
222
- if (empty($registeredPlugins)) {
223
- return;
224
- }
225
-
226
- foreach ($registeredPlugins as $pluginName => $pluginData) {
227
-
228
- if (!is_plugin_active($pluginName)) {
229
- continue;
230
- }
231
-
232
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
233
- continue;
234
- }
235
- $classPath = $pluginData['classPath'];
236
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
237
-
238
- if (!file_exists($classPath)) {
239
- continue;
240
- }
241
-
242
- require_once($classPath);
243
-
244
- $classObj = new $pluginData['className']();
245
-
246
- if (!$classObj instanceof \SgpbIPopupExtension) {
247
- continue;
248
- }
249
-
250
- $scriptData = $classObj->getFrontendScripts(
251
- $post, array(
252
- 'popups' => $popups
253
- )
254
- );
255
-
256
- $scripts[] = $scriptData;
257
- }
258
-
259
- if (empty($scripts)) {
260
- return;
261
- }
262
- if ($this->getIsAjax()){
263
- $this->scriptsAndStylesForAjax['scripts'] = $scripts;
264
- }
265
- foreach ($scripts as $script) {
266
- if (empty($script['jsFiles'])) {
267
- continue;
268
- }
269
-
270
- foreach ($script['jsFiles'] as $jsFile) {
271
-
272
- if (empty($jsFile['folderUrl'])) {
273
- wp_enqueue_script(@$jsFile['filename']);
274
- continue;
275
- }
276
-
277
- $dirUrl = $jsFile['folderUrl'];
278
- $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
279
- $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
280
- $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
281
-
282
- ScriptsIncluder::registerScript($jsFile['filename'], array(
283
- 'dirUrl' => $dirUrl,
284
- 'dep' => $dep,
285
- 'ver' => $ver,
286
- 'inFooter' => $inFooter
287
- )
288
- );
289
- ScriptsIncluder::enqueueScript($jsFile['filename']);
290
- }
291
-
292
- if (empty($script['localizeData'])) {
293
- continue;
294
- }
295
-
296
- $localizeData = $script['localizeData'];
297
-
298
- if (!empty($localizeData[0])) {
299
- foreach ($localizeData as $valueData) {
300
- if (empty($valueData)) {
301
- continue;
302
-
303
- }
304
- if (version_compare($wp_version, '4.5', '>')){
305
- /* after wp 4.5 version */
306
- ScriptsIncluder::addInlineScripts($valueData['handle'], 'var '.$valueData['name'].' = ' .json_encode($valueData['data']));
307
- } else {
308
- /* since wp 4.5 version */
309
- ScriptsIncluder::localizeScript($valueData['handle'], $valueData['name'], $valueData['data']);
310
- }
311
-
312
- }
313
- }
314
- }
315
- }
316
-
317
- private function includeStyles()
318
- {
319
- global $post;
320
- $styles = array();
321
- $popups = $this->getLoadablePopups();
322
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
323
-
324
- if (!$registeredPlugins) {
325
- return;
326
- }
327
- $registeredPlugins = json_decode($registeredPlugins, true);
328
-
329
- if (empty($registeredPlugins)) {
330
- return;
331
- }
332
-
333
- foreach ($registeredPlugins as $pluginName => $pluginData) {
334
-
335
- if (!is_plugin_active($pluginName)) {
336
- continue;
337
- }
338
-
339
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
340
- continue;
341
- }
342
-
343
- $classPath = $pluginData['classPath'];
344
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
345
-
346
- if (!file_exists($classPath)) {
347
- continue;
348
- }
349
-
350
- require_once($classPath);
351
-
352
- $classObj = new $pluginData['className']();
353
-
354
- if (!$classObj instanceof \SgpbIPopupExtension) {
355
- continue;
356
- }
357
-
358
- $scriptData = $classObj->getFrontendStyles(
359
- $post , array(
360
- 'popups' => $popups
361
- )
362
- );
363
-
364
- $styles[] = $scriptData;
365
- }
366
-
367
- if (empty($styles)) {
368
- return;
369
- }
370
- if ($this->getIsAjax()){
371
- $this->scriptsAndStylesForAjax['styles'] = $styles;
372
- }
373
- foreach ($styles as $style) {
374
-
375
- if (empty($style['cssFiles'])) {
376
- continue;
377
- }
378
-
379
- foreach ($style['cssFiles'] as $cssFile) {
380
-
381
- if (empty($cssFile['folderUrl'])) {
382
- ScriptsIncluder::enqueueStyle($cssFile['filename']);
383
- continue;
384
- }
385
-
386
- $dirUrl = $cssFile['folderUrl'];
387
- $dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
388
- $ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
389
- $inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';
390
-
391
- ScriptsIncluder::registerStyle($cssFile['filename'], array(
392
- 'dirUrl' => $dirUrl,
393
- 'dep' => $dep,
394
- 'ver' => $ver,
395
- 'inFooter' => $inFooter
396
- )
397
- );
398
- ScriptsIncluder::enqueueStyle($cssFile['filename']);
399
- }
400
- }
401
- }
402
-
403
- public function getScriptsAndStylesForAjax() {
404
- return $this->scriptsAndStylesForAjax;
405
- }
406
- }
1
+ <?php
2
+
3
+ namespace sgpb;
4
+
5
+ // load popups data's from popups object
6
+ class ScriptsLoader
7
+ {
8
+ // all loadable popups objects
9
+ private $loadablePopups = array();
10
+ private $isAdmin = false;
11
+ private $isAjax = false;
12
+ private $scriptsAndStylesForAjax;
13
+ private $footerContentAjax;
14
+ private static $alreadyLoadedPopups = array();
15
+
16
+ public function setLoadablePopups($loadablePopups)
17
+ {
18
+ $this->loadablePopups = $loadablePopups;
19
+ }
20
+
21
+ public function getLoadablePopups()
22
+ {
23
+ return apply_filters('sgpbLoadablePopups', $this->loadablePopups);
24
+ }
25
+
26
+ public function setIsAdmin($isAdmin)
27
+ {
28
+ $this->isAdmin = $isAdmin;
29
+ }
30
+
31
+ public function getIsAdmin()
32
+ {
33
+ return $this->isAdmin;
34
+ }
35
+
36
+ /* for ajax calls */
37
+ public function setIsAjax($isAjax)
38
+ {
39
+ $this->isAjax = $isAjax;
40
+ }
41
+
42
+ public function getIsAjax()
43
+ {
44
+ return $this->isAjax;
45
+ }
46
+
47
+ public function setFooterContentAjax($footerContentAjax)
48
+ {
49
+ $this->footerContentAjax = $footerContentAjax;
50
+ }
51
+
52
+ public function getFooterContentAjax()
53
+ {
54
+ return $this->footerContentAjax;
55
+ }
56
+
57
+ /**
58
+ * Get encoded popup options
59
+ *
60
+ * @since 3.0.4
61
+ *
62
+ * @param object $popup
63
+ *
64
+ * @return array|mixed|string|void $popupOptions
65
+ */
66
+ private function getEncodedOptionsFromPopup($popup)
67
+ {
68
+ $extraOptions = $popup->getExtraRenderOptions();
69
+ $popupOptions = $popup->getOptions();
70
+ $popupOptions = apply_filters('sgpbPopupRenderOptions', $popupOptions);
71
+ $popupCondition = $popup->getConditions();
72
+
73
+ $popupOptions = array_merge($popupOptions, $extraOptions);
74
+ $popupOptions['sgpbConditions'] = apply_filters('sgpbRenderCondtions', $popupCondition);
75
+ // These two lines have been added in order to not use the json_econde and to support PHP 5.3 version.
76
+ $popupOptions = AdminHelper::serializeData($popupOptions);
77
+ $popupOptions = base64_encode($popupOptions);
78
+
79
+ return $popupOptions;
80
+ }
81
+
82
+ // load popup scripts and styles and add popup data to the footer
83
+ public function loadToFooter($isFromAjax = false)
84
+ {
85
+ $popups = $this->getLoadablePopups();
86
+ $currentPostType = AdminHelper::getCurrentPostType();
87
+ global $wp;
88
+ $currentUrl = home_url( $wp->request );
89
+ $currentUrl = strpos($currentUrl, '/popupbuilder/');
90
+
91
+ // during preview wp request is empty that is why we check query_string
92
+ if (is_preview()) {
93
+ $currentUrl = strrpos($wp->query_string, 'popupbuilder');
94
+ }
95
+
96
+ if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
97
+ return false;
98
+ }
99
+
100
+ if (empty($popups)) {
101
+ return false;
102
+ }
103
+
104
+ global $post;
105
+ $postId = 0;
106
+
107
+ if (!empty($post)) {
108
+ $postId = $post->ID;
109
+ }
110
+
111
+ if ($this->getIsAdmin()) {
112
+ $this->loadToAdmin();
113
+ return true;
114
+ }
115
+ $footerContentAjax = '';
116
+
117
+ foreach ($popups as $popup) {
118
+ $isActive = $popup->isActive();
119
+ if (!$isActive) {
120
+ continue;
121
+ }
122
+
123
+ $popupId = $popup->getId();
124
+
125
+ $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
126
+
127
+ $events = $popup->getPopupAllEvents($postId, $popupId, $popup);
128
+
129
+ // if popup's data has already loaded into the page with the same event
130
+ if (isset(self::$alreadyLoadedPopups[$popupId])) {
131
+ if (self::$alreadyLoadedPopups[$popupId] == $events) {
132
+ continue;
133
+ }
134
+ }
135
+ foreach ($events as $event) {
136
+ if (isset($event['param'])) {
137
+ if (isset(self::$alreadyLoadedPopups[$popupId])) {
138
+ if (self::$alreadyLoadedPopups[$popupId] == $event['param']) {
139
+ continue;
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ self::$alreadyLoadedPopups[$popupId] = $events;
146
+ $events = json_encode($events);
147
+ $currentUseOptions = $popup->getOptions();
148
+ $extraContent = apply_filters('sgpbPopupExtraData', $popupId, $currentUseOptions);
149
+
150
+ $popupOptions = $this->getEncodedOptionsFromPopup($popup);
151
+ $popupOptions = apply_filters('sgpbLoadToFooterOptions', $popupOptions);
152
+ if ($isFromAjax) {
153
+ $footerPopupContent = '<div class="sgpb-main-popup-data-container-'.$popupId.'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
154
+ <div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
155
+ <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
156
+ </div>
157
+ </div>';
158
+ $footerPopupContent .= $extraContent;
159
+ $footerContentAjax .= $footerPopupContent;
160
+ } else {
161
+ add_action('wp_footer', function() use ($popupId, $events, $popupOptions, $popupContent, $extraContent) {
162
+ $footerPopupContent = '<div class="sgpb-main-popup-data-container-'.$popupId.'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
163
+ <div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
164
+ <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
165
+ </div>
166
+ </div>';
167
+ $footerPopupContent .= $extraContent;
168
+ echo $footerPopupContent;
169
+ });
170
+ }
171
+ }
172
+
173
+ $this->includeScripts();
174
+ $this->includeStyles();
175
+ if ($isFromAjax){
176
+ $this->setFooterContentAjax($footerContentAjax);
177
+ }
178
+ }
179
+
180
+ public function loadToAdmin()
181
+ {
182
+ $popups = $this->getLoadablePopups();
183
+
184
+ foreach ($popups as $popup) {
185
+ $popupId = $popup->getId();
186
+
187
+ $events = array();
188
+
189
+ $events = json_encode($events);
190
+
191
+ $popupOptions = $this->getEncodedOptionsFromPopup($popup);
192
+
193
+ $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
194
+
195
+ add_action('admin_footer', function() use ($popupId, $events, $popupOptions, $popupContent) {
196
+ $footerPopupContent = '<div style="position:absolute;top: -999999999999999999999px;">
197
+ <div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
198
+ <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
199
+ </div>
200
+ </div>';
201
+
202
+ echo $footerPopupContent;
203
+ });
204
+ }
205
+ $this->includeScripts();
206
+ $this->includeStyles();
207
+
208
+ }
209
+
210
+ private function includeScripts()
211
+ {
212
+ global $post;
213
+ global $wp_version;
214
+ $popups = $this->getLoadablePopups();
215
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
216
+
217
+ if (!$registeredPlugins) {
218
+ return;
219
+ }
220
+ $registeredPlugins = json_decode($registeredPlugins, true);
221
+
222
+ if (empty($registeredPlugins)) {
223
+ return;
224
+ }
225
+
226
+ foreach ($registeredPlugins as $pluginName => $pluginData) {
227
+
228
+ if (!is_plugin_active($pluginName)) {
229
+ continue;
230
+ }
231
+
232
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
233
+ continue;
234
+ }
235
+ $classPath = $pluginData['classPath'];
236
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
237
+
238
+ if (!file_exists($classPath)) {
239
+ continue;
240
+ }
241
+
242
+ require_once($classPath);
243
+
244
+ $classObj = new $pluginData['className']();
245
+
246
+ if (!$classObj instanceof \SgpbIPopupExtension) {
247
+ continue;
248
+ }
249
+
250
+ $scriptData = $classObj->getFrontendScripts(
251
+ $post, array(
252
+ 'popups' => $popups
253
+ )
254
+ );
255
+
256
+ $scripts[] = $scriptData;
257
+ }
258
+
259
+ if (empty($scripts)) {
260
+ return;
261
+ }
262
+ if ($this->getIsAjax()){
263
+ $this->scriptsAndStylesForAjax['scripts'] = $scripts;
264
+ }
265
+ foreach ($scripts as $script) {
266
+ if (empty($script['jsFiles'])) {
267
+ continue;
268
+ }
269
+
270
+ foreach ($script['jsFiles'] as $jsFile) {
271
+
272
+ if (empty($jsFile['folderUrl'])) {
273
+ wp_enqueue_script(@$jsFile['filename']);
274
+ continue;
275
+ }
276
+
277
+ $dirUrl = $jsFile['folderUrl'];
278
+ $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
279
+ $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
280
+ $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
281
+
282
+ ScriptsIncluder::registerScript($jsFile['filename'], array(
283
+ 'dirUrl' => $dirUrl,
284
+ 'dep' => $dep,
285
+ 'ver' => $ver,
286
+ 'inFooter' => $inFooter
287
+ )
288
+ );
289
+ ScriptsIncluder::enqueueScript($jsFile['filename']);
290
+ }
291
+
292
+ if (empty($script['localizeData'])) {
293
+ continue;
294
+ }
295
+
296
+ $localizeData = $script['localizeData'];
297
+
298
+ if (!empty($localizeData[0])) {
299
+ foreach ($localizeData as $valueData) {
300
+ if (empty($valueData)) {
301
+ continue;
302
+
303
+ }
304
+ if (version_compare($wp_version, '4.5', '>')){
305
+ /* after wp 4.5 version */
306
+ ScriptsIncluder::addInlineScripts($valueData['handle'], 'var '.$valueData['name'].' = ' .json_encode($valueData['data']).';');
307
+ } else {
308
+ /* since wp 4.5 version */
309
+ ScriptsIncluder::localizeScript($valueData['handle'], $valueData['name'], $valueData['data']);
310
+ }
311
+
312
+ }
313
+ }
314
+ }
315
+ }
316
+
317
+ private function includeStyles()
318
+ {
319
+ global $post;
320
+ $styles = array();
321
+ $popups = $this->getLoadablePopups();
322
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
323
+
324
+ if (!$registeredPlugins) {
325
+ return;
326
+ }
327
+ $registeredPlugins = json_decode($registeredPlugins, true);
328
+
329
+ if (empty($registeredPlugins)) {
330
+ return;
331
+ }
332
+
333
+ foreach ($registeredPlugins as $pluginName => $pluginData) {
334
+
335
+ if (!is_plugin_active($pluginName)) {
336
+ continue;
337
+ }
338
+
339
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
340
+ continue;
341
+ }
342
+
343
+ $classPath = $pluginData['classPath'];
344
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
345
+
346
+ if (!file_exists($classPath)) {
347
+ continue;
348
+ }
349
+
350
+ require_once($classPath);
351
+
352
+ $classObj = new $pluginData['className']();
353
+
354
+ if (!$classObj instanceof \SgpbIPopupExtension) {
355
+ continue;
356
+ }
357
+
358
+ $scriptData = $classObj->getFrontendStyles(
359
+ $post , array(
360
+ 'popups' => $popups
361
+ )
362
+ );
363
+
364
+ $styles[] = $scriptData;
365
+ }
366
+
367
+ if (empty($styles)) {
368
+ return;
369
+ }
370
+ if ($this->getIsAjax()){
371
+ $this->scriptsAndStylesForAjax['styles'] = $styles;
372
+ }
373
+ foreach ($styles as $style) {
374
+
375
+ if (empty($style['cssFiles'])) {
376
+ continue;
377
+ }
378
+
379
+ foreach ($style['cssFiles'] as $cssFile) {
380
+
381
+ if (empty($cssFile['folderUrl'])) {
382
+ ScriptsIncluder::enqueueStyle($cssFile['filename']);
383
+ continue;
384
+ }
385
+
386
+ $dirUrl = $cssFile['folderUrl'];
387
+ $dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
388
+ $ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
389
+ $inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';
390
+
391
+ ScriptsIncluder::registerStyle($cssFile['filename'], array(
392
+ 'dirUrl' => $dirUrl,
393
+ 'dep' => $dep,
394
+ 'ver' => $ver,
395
+ 'inFooter' => $inFooter
396
+ )
397
+ );
398
+ ScriptsIncluder::enqueueStyle($cssFile['filename']);
399
+ }
400
+ }
401
+ }
402
+
403
+ public function getScriptsAndStylesForAjax() {
404
+ return $this->scriptsAndStylesForAjax;
405
+ }
406
+ }
com/classes/Style.php CHANGED
@@ -1,120 +1,120 @@
1
- <?php
2
- namespace sgpb;
3
- /**
4
- * Popup Builder Style
5
- *
6
- * @since 2.5.6
7
- *
8
- * detect and include popup styles to the admin pages
9
- *
10
- */
11
- class Style
12
- {
13
- public static function enqueueStyles($hook)
14
- {
15
- global $post;
16
- global $post_type;
17
- $pageName = $hook;
18
- $styles = array();
19
- $popupType = AdminHelper::getCurrentPopupType();
20
- $currentPostType = AdminHelper::getCurrentPostType();
21
-
22
- if($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
23
- $pageName = 'popupType';
24
- }
25
- else if (($hook == 'post-new.php' || $hook == 'post.php') && $currentPostType == SG_POPUP_POST_TYPE) {
26
- $pageName = 'editpage';
27
- }
28
- else if ($hook == 'edit.php' && !empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
29
- $pageName = 'popupspage';
30
- }
31
- else if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SUBSCRIBERS_PAGE) {
32
- $pageName = SG_POPUP_SUBSCRIBERS_PAGE;
33
- }
34
-
35
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
36
-
37
- if (!$registeredPlugins) {
38
- return;
39
- }
40
-
41
- $registeredPlugins = json_decode($registeredPlugins, true);
42
-
43
- if (empty($registeredPlugins)) {
44
- return;
45
- }
46
-
47
- foreach ($registeredPlugins as $pluginName => $pluginData) {
48
-
49
- if (!is_plugin_active($pluginName)) {
50
- continue;
51
- }
52
-
53
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
54
- continue;
55
- }
56
-
57
- $classPath = $pluginData['classPath'];
58
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
59
-
60
- if (!file_exists($classPath)) {
61
- continue;
62
- }
63
- require_once($classPath);
64
-
65
- if (!class_exists($pluginData['className'])) {
66
- continue;
67
- }
68
-
69
- $classObj = new $pluginData['className']();
70
-
71
- if (!$classObj instanceof \SgpbIPopupExtension) {
72
- continue;
73
- }
74
- $args = array(
75
- 'popupType' => $popupType
76
- );
77
- $styleData = $classObj->getStyles($pageName , $args);
78
- if (!empty($styleData['cssFiles'])) {
79
- $styles[] = $styleData;
80
- }
81
- }
82
-
83
- if (empty($styles)) {
84
- return;
85
- }
86
-
87
- foreach ($styles as $style) {
88
-
89
- if (empty($style['cssFiles'])) {
90
- continue;
91
- }
92
-
93
- foreach ($style['cssFiles'] as $cssFile) {
94
-
95
- if (empty($cssFile['folderUrl'])) {
96
- ScriptsIncluder::enqueueStyle($cssFile['filename']);
97
- continue;
98
- }
99
-
100
- $dirUrl = $cssFile['folderUrl'];
101
- $dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
102
- $ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
103
- $inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';;
104
-
105
- ScriptsIncluder::registerStyle($cssFile['filename'], array(
106
- 'dirUrl'=> $dirUrl,
107
- 'dep' => $dep,
108
- 'ver' => $ver,
109
- 'inFooter' => $inFooter
110
- )
111
- );
112
- ScriptsIncluder::enqueueStyle($cssFile['filename']);
113
- }
114
- }
115
-
116
- if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
117
- ScriptsIncluder::enqueueStyle('popupAdminStyles.css');
118
- }
119
- }
120
- }
1
+ <?php
2
+ namespace sgpb;
3
+ /**
4
+ * Popup Builder Style
5
+ *
6
+ * @since 2.5.6
7
+ *
8
+ * detect and include popup styles to the admin pages
9
+ *
10
+ */
11
+ class Style
12
+ {
13
+ public static function enqueueStyles($hook)
14
+ {
15
+ global $post;
16
+ global $post_type;
17
+ $pageName = $hook;
18
+ $styles = array();
19
+ $popupType = AdminHelper::getCurrentPopupType();
20
+ $currentPostType = AdminHelper::getCurrentPostType();
21
+
22
+ if($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
23
+ $pageName = 'popupType';
24
+ }
25
+ else if (($hook == 'post-new.php' || $hook == 'post.php') && $currentPostType == SG_POPUP_POST_TYPE) {
26
+ $pageName = 'editpage';
27
+ }
28
+ else if ($hook == 'edit.php' && !empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
29
+ $pageName = 'popupspage';
30
+ }
31
+ else if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SUBSCRIBERS_PAGE) {
32
+ $pageName = SG_POPUP_SUBSCRIBERS_PAGE;
33
+ }
34
+
35
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
36
+
37
+ if (!$registeredPlugins) {
38
+ return;
39
+ }
40
+
41
+ $registeredPlugins = json_decode($registeredPlugins, true);
42
+
43
+ if (empty($registeredPlugins)) {
44
+ return;
45
+ }
46
+
47
+ foreach ($registeredPlugins as $pluginName => $pluginData) {
48
+
49
+ if (!is_plugin_active($pluginName)) {
50
+ continue;
51
+ }
52
+
53
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
54
+ continue;
55
+ }
56
+
57
+ $classPath = $pluginData['classPath'];
58
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
59
+
60
+ if (!file_exists($classPath)) {
61
+ continue;
62
+ }
63
+ require_once($classPath);
64
+
65
+ if (!class_exists($pluginData['className'])) {
66
+ continue;
67
+ }
68
+
69
+ $classObj = new $pluginData['className']();
70
+
71
+ if (!$classObj instanceof \SgpbIPopupExtension) {
72
+ continue;
73
+ }
74
+ $args = array(
75
+ 'popupType' => $popupType
76
+ );
77
+ $styleData = $classObj->getStyles($pageName , $args);
78
+ if (!empty($styleData['cssFiles'])) {
79
+ $styles[] = $styleData;
80
+ }
81
+ }
82
+
83
+ if (empty($styles)) {
84
+ return;
85
+ }
86
+
87
+ foreach ($styles as $style) {
88
+
89
+ if (empty($style['cssFiles'])) {
90
+ continue;
91
+ }
92
+
93
+ foreach ($style['cssFiles'] as $cssFile) {
94
+
95
+ if (empty($cssFile['folderUrl'])) {
96
+ ScriptsIncluder::enqueueStyle($cssFile['filename']);
97
+ continue;
98
+ }
99
+
100
+ $dirUrl = $cssFile['folderUrl'];
101
+ $dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
102
+ $ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
103
+ $inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';;
104
+
105
+ ScriptsIncluder::registerStyle($cssFile['filename'], array(
106
+ 'dirUrl'=> $dirUrl,
107
+ 'dep' => $dep,
108
+ 'ver' => $ver,
109
+ 'inFooter' => $inFooter
110
+ )
111
+ );
112
+ ScriptsIncluder::enqueueStyle($cssFile['filename']);
113
+ }
114
+ }
115
+
116
+ if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
117
+ ScriptsIncluder::enqueueStyle('popupAdminStyles.css');
118
+ }
119
+ }
120
+ }
com/classes/Updates.php CHANGED
@@ -1,203 +1,203 @@
1
- <?php
2
- namespace sgpb;
3
-
4
-
5
- class Updates
6
- {
7
- private $licenses = array();
8
- private $licenseClass;
9
-
10
- public function setLicenses($licenses)
11
- {
12
- $this->licenses = $licenses;
13
- }
14
-
15
- public function getLicenses()
16
- {
17
- return $this->licenses;
18
- }
19
-
20
- public function __construct()
21
- {
22
- $this->licenseClass = new License();
23
- $this->init();
24
- }
25
-
26
- private function init()
27
- {
28
- $this->setLicenses($this->licenseClass->getLicenses());
29
- $licenses = $this->getLicenses();
30
-
31
- if (empty($licenses)) {
32
- return false;
33
- }
34
- add_action('admin_menu', array($this, 'menu'), 22);
35
- add_action('admin_init', array($this, 'sgpbActivateLicense'));
36
- add_action('admin_notices', array($this, 'sgpbAdminNotices'));
37
-
38
- return true;
39
- }
40
-
41
- public function menu()
42
- {
43
- add_submenu_page('edit.php?post_type='.SG_POPUP_POST_TYPE, __('License', SG_POPUP_TEXT_DOMAIN), __('License', SG_POPUP_TEXT_DOMAIN), 'sgpb_manage_options', SGPB_POPUP_LICENSE, array($this, 'pluginLicense'));
44
- }
45
-
46
- public function sanitizeLicense($new)
47
- {
48
- $old = get_option('sgpb-license-key-'.$this->licenseKey);
49
-
50
- if ($old && $old != $new) {
51
- delete_option('sgpb-license-status-'.$this->licenseKey); // new license has been entered, so must reactivate
52
- }
53
- update_option('sgpb-license-key-'.$this->licenseKey, $new);
54
-
55
- return $new;
56
- }
57
-
58
- public function pluginLicense()
59
- {
60
- require_once(SG_POPUP_VIEWS_PATH.'license.php');
61
- }
62
-
63
- public function sgpbActivateLicense()
64
- {
65
- $licenses = $this->getLicenses();
66
-
67
- foreach ($licenses as $license) {
68
- $key = @$license['key'];
69
- $itemId = @$license['itemId'];
70
- $itemName = @$license['itemName'];
71
- $storeURL = @$license['storeURL'];
72
- $this->licenseKey = $key;
73
-
74
- if (isset($_POST['sgpb-license-key-'.$key])) {
75
- $this->sanitizeLicense($_POST['sgpb-license-key-'.$key]);
76
- }
77
-
78
- // listen for our activate button to be clicked
79
- if (isset($_POST['sgpb-license-activate-'.$key])) {
80
- // run a quick security check
81
- if (!check_admin_referer('sgpb_nonce', 'sgpb_nonce')) {
82
- return; // get out if we didn't click the Activate button
83
- }
84
- // retrieve the license from the database
85
- $license = trim(get_option('sgpb-license-key-'.$key));
86
- // data to send in our API request
87
- $apiParams = array(
88
- 'edd_action' => 'activate_license',
89
- 'license' => $license,
90
- 'item_id' => $itemId, // The ID of the item in EDD
91
- 'url' => home_url()
92
- );
93
- // Call the custom API.
94
- $response = wp_remote_post($storeURL, array('timeout' => 15, 'sslverify' => false, 'body' => $apiParams));
95
- // make sure the response came back okay
96
- if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
97
- $errorMessage = $response->get_error_message();
98
- $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
99
- }
100
- else {
101
- $licenseData = json_decode(wp_remote_retrieve_body($response));
102
- if (false === $licenseData->success) {
103
- switch ($licenseData->error) {
104
- case 'expired' :
105
- $message = sprintf(
106
- __('Your license key expired on %s.', SG_POPUP_TEXT_DOMAIN),
107
- date_i18n(get_option('date_format'), strtotime($licenseData->expires, current_time('timestamp')))
108
- );
109
- break;
110
- case 'revoked' :
111
- $message = __('Your license key has been disabled.', SG_POPUP_TEXT_DOMAIN);
112
- break;
113
- case 'missing' :
114
- $message = __('Invalid license.', SG_POPUP_TEXT_DOMAIN);
115
- break;
116
- case 'invalid' :
117
- case 'site_inactive' :
118
- $message = __('Your license is not active for this URL.',SG_POPUP_TEXT_DOMAIN);
119
- break;
120
- case 'item_name_mismatch' :
121
- $message = sprintf(__('This appears to be an invalid license key for %s.', SG_POPUP_TEXT_DOMAIN), $itemName);
122
- break;
123
- case 'no_activations_left' :
124
- $message = __('You\'ve already used the permitted number of this license key!', SG_POPUP_TEXT_DOMAIN);
125
- break;
126
- default :
127
- $message = __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
128
- break;
129
- }
130
- }
131
- }
132
- // Check if anything passed on a message constituting a failure
133
- if (!empty($message)) {
134
- $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
135
- $redirect = add_query_arg(array('sl_activation' => 'false', 'message' => urlencode($message)), $baseUrl);
136
- wp_redirect($redirect);
137
- exit();
138
- }
139
- // $licenseData->license will be either "valid" or "invalid"
140
- update_option('sgpb-license-status-'.$key, $licenseData->license);
141
- $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
142
- // all available extensions have active license status
143
- if (empty($hasInactiveExtensions)) {
144
- // and if we don't have inactive extensions, remove option, until new one activation
145
- delete_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
146
- }
147
- wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
148
- exit();
149
- }
150
-
151
- if (isset($_POST['sgpb-license-deactivate'.$key])) {
152
- $license = trim(get_option('sgpb-license-key-'.$key));
153
- // data to send in our API request
154
- $apiParams = array(
155
- 'edd_action' => 'deactivate_license',
156
- 'license' => $license,
157
- 'item_id' => $itemId, // The ID of the item in EDD
158
- 'url' => home_url()
159
- );
160
- $home = home_url();
161
- // Send the remote request
162
- $response = wp_remote_post($storeURL, array('body' => $apiParams, 'timeout' => 15, 'sslverify' => false));
163
- if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
164
- $errorMessage = $response->get_error_message();
165
- $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
166
- $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
167
- $redirect = add_query_arg(array('message' => urlencode($message)), $baseUrl);
168
- wp_redirect($redirect);
169
- exit();
170
- }
171
- else {
172
- $status = false;
173
- $licenseData = json_decode(wp_remote_retrieve_body($response));
174
- if (isset($licenseData->success)) {
175
- $status = $licenseData->success;
176
- }
177
- update_option('sgpb-license-status-'.$key, $status);
178
- update_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
179
- wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
180
- exit();
181
- }
182
- }
183
- }
184
- }
185
-
186
- public function sgpbAdminNotices()
187
- {
188
- if (isset($_GET['sl_activation']) && !empty($_GET['message'])) {
189
- switch ($_GET['sl_activation']) {
190
- case 'false':
191
- $message = urldecode($_GET['message']);
192
- ?>
193
- <div class="error">
194
- <h3><?php echo $message; ?></h3>
195
- </div>
196
- <?php
197
- break;
198
- case 'true':
199
- break;
200
- }
201
- }
202
- }
203
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+
5
+ class Updates
6
+ {
7
+ private $licenses = array();
8
+ private $licenseClass;
9
+
10
+ public function setLicenses($licenses)
11
+ {
12
+ $this->licenses = $licenses;
13
+ }
14
+
15
+ public function getLicenses()
16
+ {
17
+ return $this->licenses;
18
+ }
19
+
20
+ public function __construct()
21
+ {
22
+ $this->licenseClass = new License();
23
+ $this->init();
24
+ }
25
+
26
+ private function init()
27
+ {
28
+ $this->setLicenses($this->licenseClass->getLicenses());
29
+ $licenses = $this->getLicenses();
30
+
31
+ if (empty($licenses)) {
32
+ return false;
33
+ }
34
+ add_action('admin_menu', array($this, 'menu'), 22);
35
+ add_action('admin_init', array($this, 'sgpbActivateLicense'));
36
+ add_action('admin_notices', array($this, 'sgpbAdminNotices'));
37
+
38
+ return true;
39
+ }
40
+
41
+ public function menu()
42
+ {
43
+ add_submenu_page('edit.php?post_type='.SG_POPUP_POST_TYPE, __('License', SG_POPUP_TEXT_DOMAIN), __('License', SG_POPUP_TEXT_DOMAIN), 'sgpb_manage_options', SGPB_POPUP_LICENSE, array($this, 'pluginLicense'));
44
+ }
45
+
46
+ public function sanitizeLicense($new)
47
+ {
48
+ $old = get_option('sgpb-license-key-'.$this->licenseKey);
49
+
50
+ if ($old && $old != $new) {
51
+ delete_option('sgpb-license-status-'.$this->licenseKey); // new license has been entered, so must reactivate
52
+ }
53
+ update_option('sgpb-license-key-'.$this->licenseKey, $new);
54
+
55
+ return $new;
56
+ }
57
+
58
+ public function pluginLicense()
59
+ {
60
+ require_once(SG_POPUP_VIEWS_PATH.'license.php');
61
+ }
62
+
63
+ public function sgpbActivateLicense()
64
+ {
65
+ $licenses = $this->getLicenses();
66
+
67
+ foreach ($licenses as $license) {
68
+ $key = @$license['key'];
69
+ $itemId = @$license['itemId'];
70
+ $itemName = @$license['itemName'];
71
+ $storeURL = @$license['storeURL'];
72
+ $this->licenseKey = $key;
73
+
74
+ if (isset($_POST['sgpb-license-key-'.$key])) {
75
+ $this->sanitizeLicense($_POST['sgpb-license-key-'.$key]);
76
+ }
77
+
78
+ // listen for our activate button to be clicked
79
+ if (isset($_POST['sgpb-license-activate-'.$key])) {
80
+ // run a quick security check
81
+ if (!check_admin_referer('sgpb_nonce', 'sgpb_nonce')) {
82
+ return; // get out if we didn't click the Activate button
83
+ }
84
+ // retrieve the license from the database
85
+ $license = trim(get_option('sgpb-license-key-'.$key));
86
+ // data to send in our API request
87
+ $apiParams = array(
88
+ 'edd_action' => 'activate_license',
89
+ 'license' => $license,
90
+ 'item_id' => $itemId, // The ID of the item in EDD
91
+ 'url' => home_url()
92
+ );
93
+ // Call the custom API.
94
+ $response = wp_remote_post($storeURL, array('timeout' => 15, 'sslverify' => false, 'body' => $apiParams));
95
+ // make sure the response came back okay
96
+ if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
97
+ $errorMessage = $response->get_error_message();
98
+ $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
99
+ }
100
+ else {
101
+ $licenseData = json_decode(wp_remote_retrieve_body($response));
102
+ if (false === $licenseData->success) {
103
+ switch ($licenseData->error) {
104
+ case 'expired' :
105
+ $message = sprintf(
106
+ __('Your license key expired on %s.', SG_POPUP_TEXT_DOMAIN),
107
+ date_i18n(get_option('date_format'), strtotime($licenseData->expires, current_time('timestamp')))
108
+ );
109
+ break;
110
+ case 'revoked' :
111
+ $message = __('Your license key has been disabled.', SG_POPUP_TEXT_DOMAIN);
112
+ break;
113
+ case 'missing' :
114
+ $message = __('Invalid license.', SG_POPUP_TEXT_DOMAIN);
115
+ break;
116
+ case 'invalid' :
117
+ case 'site_inactive' :
118
+ $message = __('Your license is not active for this URL.',SG_POPUP_TEXT_DOMAIN);
119
+ break;
120
+ case 'item_name_mismatch' :
121
+ $message = sprintf(__('This appears to be an invalid license key for %s.', SG_POPUP_TEXT_DOMAIN), $itemName);
122
+ break;
123
+ case 'no_activations_left' :
124
+ $message = __('You\'ve already used the permitted number of this license key!', SG_POPUP_TEXT_DOMAIN);
125
+ break;
126
+ default :
127
+ $message = __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
128
+ break;
129
+ }
130
+ }
131
+ }
132
+ // Check if anything passed on a message constituting a failure
133
+ if (!empty($message)) {
134
+ $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
135
+ $redirect = add_query_arg(array('sl_activation' => 'false', 'message' => urlencode($message)), $baseUrl);
136
+ wp_redirect($redirect);
137
+ exit();
138
+ }
139
+ // $licenseData->license will be either "valid" or "invalid"
140
+ update_option('sgpb-license-status-'.$key, $licenseData->license);
141
+ $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
142
+ // all available extensions have active license status
143
+ if (empty($hasInactiveExtensions)) {
144
+ // and if we don't have inactive extensions, remove option, until new one activation
145
+ delete_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
146
+ }
147
+ wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
148
+ exit();
149
+ }
150
+
151
+ if (isset($_POST['sgpb-license-deactivate'.$key])) {
152
+ $license = trim(get_option('sgpb-license-key-'.$key));
153
+ // data to send in our API request
154
+ $apiParams = array(
155
+ 'edd_action' => 'deactivate_license',
156
+ 'license' => $license,
157
+ 'item_id' => $itemId, // The ID of the item in EDD
158
+ 'url' => home_url()
159
+ );
160
+ $home = home_url();
161
+ // Send the remote request
162
+ $response = wp_remote_post($storeURL, array('body' => $apiParams, 'timeout' => 15, 'sslverify' => false));
163
+ if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
164
+ $errorMessage = $response->get_error_message();
165
+ $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
166
+ $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
167
+ $redirect = add_query_arg(array('message' => urlencode($message)), $baseUrl);
168
+ wp_redirect($redirect);
169
+ exit();
170
+ }
171
+ else {
172
+ $status = false;
173
+ $licenseData = json_decode(wp_remote_retrieve_body($response));
174
+ if (isset($licenseData->success)) {
175
+ $status = $licenseData->success;
176
+ }
177
+ update_option('sgpb-license-status-'.$key, $status);
178
+ update_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
179
+ wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
180
+ exit();
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ public function sgpbAdminNotices()
187
+ {
188
+ if (isset($_GET['sl_activation']) && !empty($_GET['message'])) {
189
+ switch ($_GET['sl_activation']) {
190
+ case 'false':
191
+ $message = urldecode($_GET['message']);
192
+ ?>
193
+ <div class="error">
194
+ <h3><?php echo $message; ?></h3>
195
+ </div>
196
+ <?php
197
+ break;
198
+ case 'true':
199
+ break;
200
+ }
201
+ }
202
+ }
203
+ }
com/classes/_detection/SgpbPopupVersionDetection.php CHANGED
@@ -1,136 +1,136 @@
1
- <?php
2
-
3
- namespace sgpb;
4
-
5
-
6
- class SgpbPopupVersionDetection
7
- {
8
- public static function compareVersions()
9
- {
10
- if(!self::checkIfIsOnPopupPage()) // check if user is in popup builder page (only admin pages)
11
- {
12
- return [];
13
- }
14
- wp_update_plugins(); // Check for plugin updates.
15
- $plugin_info = get_site_transient("update_plugins"); // get plugins to update
16
- $registeredPlugins = AdminHelper::getAllExtensions(); // getting active PopupBuilder plugins
17
- $hasOldPlugin = [];
18
-
19
- foreach($registeredPlugins["active"] as $plugin) {
20
- $pluginData = get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin["pluginKey"]); // getting plugin registered data
21
- $plugin["name"] = $pluginData["Name"]; // setting name in plugin array! this is for frontend to show full name
22
- $plugin_slug = null;
23
- if ($plugin["pluginKey"] === 'popupbuilder-edd/PopupBuilderEdd.php') {
24
- if (empty($plugin_info->response[$plugin["pluginKey"]])) {
25
- $plugin["pluginKey"] = str_replace("\\","/",WP_PLUGIN_DIR).'/'.$plugin["pluginKey"];
26
- }
27
- }
28
- if(isset($plugin_info->response[$plugin["pluginKey"]])) {
29
- $plugin_slug = $plugin_info->response[$plugin["pluginKey"]]->slug; // getting current slug generated by wordpress without slug will not update the plugin
30
- }
31
- /* this logic will work only < stable versions */
32
- if(version_compare($plugin["stable_version"], $pluginData["Version"], ">")) {
33
- $hasLicense = self::getLicenseOfPlugin($plugin);
34
- $hasOldPlugin[] = [
35
- "plugin" => $plugin,
36
- "message" => self::pluginUpdateMessage("extensions"),
37
- "license" => $hasLicense,
38
- "slug" => $plugin_slug,
39
- ];
40
- }
41
- }
42
- $filteredByLicense = self::pluginUpdateMessage(self::filterPluginsByLicense($hasOldPlugin));
43
-
44
- return $filteredByLicense;
45
- }
46
-
47
- private static function pluginUpdateMessage($filteredByLicense)
48
- {
49
- if(empty($filteredByLicense)) {
50
- return [];
51
- }
52
- $headerMessage = empty($filteredByLicense["autoUpdate"]) ? 'You use major updated version of Popup Builder' : 'Updating active Popup Builder extensions';
53
- $adminLicenseUrl = admin_url("edit.php?post_type=".SG_POPUP_POST_TYPE."&page=".SGPB_POPUP_LICENSE);
54
-
55
- $modalData = [
56
- "header" => '<h3 class="sgpb-modal-detection-header">'.$headerMessage.'</h3>',
57
- "logo" => SG_POPUP_IMG_URL.'sgpbLogo.png',
58
- "manualMessage" => '<p class="sgpb-text-center">As you don’t have updates for the extensions listed below, you will have issues using the plugin.
59
- <br>Please do the following in order to use the plugin properly:</p>
60
- <p class="sgpb-margin-top-10 sgpb-text-center" style="font-style: italic">If you don’t have an active license, purchase a new one.</p>
61
- <p class="sgpb-text-center">OR</p>
62
- <p class="sgpb-text-center" style="font-style: italic">If you have an active license, add its license code <a href="'.$adminLicenseUrl.'">here</a>.</p>',
63
- "footerMessage" => '<p class="sgpb-modal-footer-message sgpb-margin-top-30 sgpb-text-center" style="font-style: italic">You can download the previous version of Popup Builder Plugin from <a href="https://downloads.wordpress.org/plugin/popup-builder.3.83.zip">here</a>.</p>'
64
- ];
65
-
66
- return array(
67
- "modalData" => $modalData,
68
- "autoUpdate" => empty($filteredByLicense['autoUpdate']) ? [] : $filteredByLicense['autoUpdate'],
69
- "manualUpdate" => empty($filteredByLicense['manualUpdate']) ? [] : $filteredByLicense['manualUpdate'],
70
- );
71
- }
72
-
73
- private static function checkIfIsOnPopupPage()
74
- {
75
- if("popupbuilder_page_license" === get_current_screen()->id) {
76
- return false;
77
- }
78
- switch(get_current_screen()->post_type) {
79
- case SG_POPUP_POST_TYPE:
80
- case "sgpbtemplate":
81
- case "sgpbautoresponder":
82
- return true;
83
- default:
84
- return false;
85
- }
86
- }
87
-
88
- private static function getLicenseOfPlugin($oldPlugins)
89
- {
90
-
91
- $licenseClass = new License();
92
- $licenses = $licenseClass->getLicenses();
93
-
94
- foreach($licenses as $license) {
95
- if(false === array_search($license['file'], $oldPlugins) && 'POPUP_EDD' !== $license['key']) {
96
- continue;
97
- }
98
- if ('POPUP_EDD' !== $license['key'] && false === array_search(str_replace("\\","/",$license['file']), $oldPlugins)) {
99
- continue;
100
- }
101
-
102
- $key = @$license["key"];
103
- $licenseKey = trim(get_option("sgpb-license-key-".$key));
104
- $status = get_option("sgpb-license-status-".$key);
105
- $license["option_key"] = $licenseKey;
106
- $license["option_status"] = $status;
107
- if($status == false || $status != "valid") {
108
- return false;
109
- }
110
-
111
- return $license;
112
- }
113
-
114
- return false;
115
- }
116
-
117
- private static function filterPluginsByLicense($extensions)
118
- {
119
- if(empty($extensions)) {
120
- return [];
121
- }
122
- $extensionsToUpdateNow = array_filter($extensions, function($extension){
123
- return $extension["license"] !== false;
124
- });
125
- $extensionsToUpdate = array_filter($extensions, function($extension){
126
- return $extension["license"] == false;
127
- });
128
-
129
- wp_enqueue_script("updates");
130
-
131
- return [
132
- "autoUpdate" => array_values($extensionsToUpdateNow),
133
- "manualUpdate" => array_values($extensionsToUpdate)
134
- ];
135
- }
136
- }
1
+ <?php
2
+
3
+ namespace sgpb;
4
+
5
+
6
+ class SgpbPopupVersionDetection
7
+ {
8
+ public static function compareVersions()
9
+ {
10
+ if(!self::checkIfIsOnPopupPage()) // check if user is in popup builder page (only admin pages)
11
+ {
12
+ return [];
13
+ }
14
+ wp_update_plugins(); // Check for plugin updates.
15
+ $plugin_info = get_site_transient("update_plugins"); // get plugins to update
16
+ $registeredPlugins = AdminHelper::getAllExtensions(); // getting active PopupBuilder plugins
17
+ $hasOldPlugin = [];
18
+
19
+ foreach($registeredPlugins["active"] as $plugin) {
20
+ $pluginData = get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin["pluginKey"]); // getting plugin registered data
21
+ $plugin["name"] = $pluginData["Name"]; // setting name in plugin array! this is for frontend to show full name
22
+ $plugin_slug = null;
23
+ if ($plugin["pluginKey"] === 'popupbuilder-edd/PopupBuilderEdd.php') {
24
+ if (empty($plugin_info->response[$plugin["pluginKey"]])) {
25
+ $plugin["pluginKey"] = str_replace("\\","/",WP_PLUGIN_DIR).'/'.$plugin["pluginKey"];
26
+ }
27
+ }
28
+ if(isset($plugin_info->response[$plugin["pluginKey"]])) {
29
+ $plugin_slug = $plugin_info->response[$plugin["pluginKey"]]->slug; // getting current slug generated by wordpress without slug will not update the plugin
30
+ }
31
+ /* this logic will work only < stable versions */
32
+ if(version_compare($plugin["stable_version"], $pluginData["Version"], ">")) {
33
+ $hasLicense = self::getLicenseOfPlugin($plugin);
34
+ $hasOldPlugin[] = [
35
+ "plugin" => $plugin,
36
+ "message" => self::pluginUpdateMessage("extensions"),
37
+ "license" => $hasLicense,
38
+ "slug" => $plugin_slug,
39
+ ];
40
+ }
41
+ }
42
+ $filteredByLicense = self::pluginUpdateMessage(self::filterPluginsByLicense($hasOldPlugin));
43
+
44
+ return $filteredByLicense;
45
+ }
46
+
47
+ private static function pluginUpdateMessage($filteredByLicense)
48
+ {
49
+ if(empty($filteredByLicense)) {
50
+ return [];
51
+ }
52
+ $headerMessage = empty($filteredByLicense["autoUpdate"]) ? 'You use major updated version of Popup Builder' : 'Updating active Popup Builder extensions';
53
+ $adminLicenseUrl = admin_url("edit.php?post_type=".SG_POPUP_POST_TYPE."&page=".SGPB_POPUP_LICENSE);
54
+
55
+ $modalData = [
56
+ "header" => '<h3 class="sgpb-modal-detection-header">'.$headerMessage.'</h3>',
57
+ "logo" => SG_POPUP_IMG_URL.'sgpbLogo.png',
58
+ "manualMessage" => '<p class="sgpb-text-center">As you don’t have updates for the extensions listed below, you will have issues using the plugin.
59
+ <br>Please do the following in order to use the plugin properly:</p>
60
+ <p class="sgpb-margin-top-10 sgpb-text-center" style="font-style: italic">If you don’t have an active license, purchase a new one.</p>
61
+ <p class="sgpb-text-center">OR</p>
62
+ <p class="sgpb-text-center" style="font-style: italic">If you have an active license, add its license code <a href="'.$adminLicenseUrl.'">here</a>.</p>',
63
+ "footerMessage" => '<p class="sgpb-modal-footer-message sgpb-margin-top-30 sgpb-text-center" style="font-style: italic">You can download the previous version of Popup Builder Plugin from <a href="https://downloads.wordpress.org/plugin/popup-builder.3.83.zip">here</a>.</p>'
64
+ ];
65
+
66
+ return array(
67
+ "modalData" => $modalData,
68
+ "autoUpdate" => empty($filteredByLicense['autoUpdate']) ? [] : $filteredByLicense['autoUpdate'],
69
+ "manualUpdate" => empty($filteredByLicense['manualUpdate']) ? [] : $filteredByLicense['manualUpdate'],
70
+ );
71
+ }
72
+
73
+ private static function checkIfIsOnPopupPage()
74
+ {
75
+ if("popupbuilder_page_license" === get_current_screen()->id) {
76
+ return false;
77
+ }
78
+ switch(get_current_screen()->post_type) {
79
+ case SG_POPUP_POST_TYPE:
80
+ case "sgpbtemplate":
81
+ case "sgpbautoresponder":
82
+ return true;
83
+ default:
84
+ return false;
85
+ }
86
+ }
87
+
88
+ private static function getLicenseOfPlugin($oldPlugins)
89
+ {
90
+
91
+ $licenseClass = new License();
92
+ $licenses = $licenseClass->getLicenses();
93
+
94
+ foreach($licenses as $license) {
95
+ if(false === array_search($license['file'], $oldPlugins) && 'POPUP_EDD' !== $license['key']) {
96
+ continue;
97
+ }
98
+ if ('POPUP_EDD' !== $license['key'] && false === array_search(str_replace("\\","/",$license['file']), $oldPlugins)) {
99
+ continue;
100
+ }
101
+
102
+ $key = @$license["key"];
103
+ $licenseKey = trim(get_option("sgpb-license-key-".$key));
104
+ $status = get_option("sgpb-license-status-".$key);
105
+ $license["option_key"] = $licenseKey;
106
+ $license["option_status"] = $status;
107
+ if($status == false || $status != "valid") {
108
+ return false;
109
+ }
110
+
111
+ return $license;
112
+ }
113
+
114
+ return false;
115
+ }
116
+
117
+ private static function filterPluginsByLicense($extensions)
118
+ {
119
+ if(empty($extensions)) {
120
+ return [];
121
+ }
122
+ $extensionsToUpdateNow = array_filter($extensions, function($extension){
123
+ return $extension["license"] !== false;
124
+ });
125
+ $extensionsToUpdate = array_filter($extensions, function($extension){
126
+ return $extension["license"] == false;
127
+ });
128
+
129
+ wp_enqueue_script("updates");
130
+
131
+ return [
132
+ "autoUpdate" => array_values($extensionsToUpdateNow),
133
+ "manualUpdate" => array_values($extensionsToUpdate)
134
+ ];
135
+ }
136
+ }
com/classes/components/Menu.php CHANGED
@@ -1,232 +1,232 @@
1
- <?php
2
-
3
- namespace sgpb;
4
-
5
- /**
6
- * Class SGPBMenu
7
- * @package sgpb
8
- */
9
- class SGPBMenu
10
- {
11
- /**
12
- * Singleton variable to save menu locations.
13
- * @var
14
- */
15
- public static $navMenuLocations;
16
-
17
- /**
18
- * Singleton variable to save menu items on which popup is set.
19
- * @var
20
- */
21
- public static $navMenuItems;
22
-
23
- /**
24
- * Menu constructor.
25
- */
26
- public function __construct()
27
- {
28
- $this->init();
29
- }
30
-
31
- /**
32
- * Initialize actions and filters.
33
- */
34
- public function init()
35
- {
36
- add_action('wp_nav_menu_item_custom_fields', array($this, 'fields'), 10, 4);
37
- add_action('wp_update_nav_menu_item', array($this, 'save'), 10, 2);
38
-
39
- add_filter('nav_menu_css_class', array($this, 'addPopupTriggeringClass'), 10, 2);
40
- add_filter('wp_setup_nav_menu_item', array($this, 'addCustomNavFields'));
41
- add_filter('sgpbLoadablePopups', array($this, 'addPopupToLoad'));
42
- }
43
-
44
- /**
45
- * @param $classes
46
- * @param $menuItem
47
- * @return mixed
48
- */
49
- public function addPopupTriggeringClass($classes, $menuItem)
50
- {
51
- $popupId = $menuItem->sgpbPopupId;
52
- if ($popupId && !in_array('sg-popup-id-'.$popupId, $classes)) {
53
- array_push($classes, 'sg-popup-id-'.$popupId);
54
- }
55
-
56
- return $classes;
57
- }
58
-
59
- /**
60
- * @param $popups
61
- * @return mixed
62
- */
63
- public function addPopupToLoad($popups) {
64
- $registeredMenus = $this->getNavMenuLocations();
65
- /* Will only return menu items on which popup is set */
66
- $menuItems = $this->getNavMenuItemsWithPopup($registeredMenus);
67
-
68
- foreach ($menuItems as $menuItem) {
69
- $menuPopupId = (int)$menuItem->sgpbPopupId;
70
-
71
- /* As $menuItems contains only menu items on which popup is set
72
- we can check if the popup should load on current page or not */
73
- $popup = $this->shouldLoadPopupForMenuItem($menuPopupId, $popups);
74
- if (!$popup) {
75
- $popup = SGPopup::find($menuPopupId);
76
- if (!$popup instanceof SGPopup) continue;
77
- /* We could set param everywhere as popup was not suppose to load on current page.
78
- We could also load popup to current requested page but to avoid any confusion
79
- it will be better to use everywhere */
80
- // $popup->setTarget(array(
81
- // array('param' => 'everywhere')
82
- // ));
83
- $popups[] = $popup;
84
- }
85
-
86
- $popupOpeningEvents = $popup->getEvents();
87
-
88
- /* If the popup is setup inside the menu but there is no onclick event we will add manually */
89
- if (!$this->inMultiDimArray('click', $popupOpeningEvents)) {
90
- $popup->setEvents(array('param' => 'click', 'value' => ''));
91
- }
92
- /* if the popup is set on menu item we don't need any limitation */
93
- //$this->disablePopupLimitation($popup);
94
- }
95
-
96
- return $popups;
97
- }
98
-
99
- /**
100
- * @param $popup
101
- */
102
- private function disablePopupLimitation(&$popup)
103
- {
104
- $popupOptions = $popup->getOptions();
105
- unset($popupOptions['sgpb-show-popup-same-user']);
106
- $popup->setOptions($popupOptions);
107
- }
108
-
109
- /**
110
- * @param $item
111
- * @param $array
112
- * @return false|int
113
- */
114
- private function inMultiDimArray($item , $array){
115
- return preg_match('/"'.preg_quote($item, '/').'"/i' , json_encode($array));
116
- }
117
-
118
- /**
119
- * @param $menuPopupId
120
- * @param $popups
121
- * @return false|mixed
122
- */
123
- private function shouldLoadPopupForMenuItem($menuPopupId, &$popups) {
124
- foreach ($popups as $popup) {
125
- $popupId = $popup->getId();
126
- /* Menu item contains popup with current id and the popup is loaded */
127
- if ($menuPopupId == $popupId) {
128
- return $popup;
129
- }
130
- }
131
- return false;
132
- }
133
-
134
- /**
135
- * @param false $forceUpdate
136
- * @return array
137
- */
138
- public function getNavMenuLocations($forceUpdate = false)
139
- {
140
- if (!isset(self::$navMenuLocations) && !$forceUpdate) {
141
- self::$navMenuLocations = get_nav_menu_locations();
142
- }
143
-
144
- return isset(self::$navMenuLocations) ? self::$navMenuLocations : array();
145
- }
146
-
147
- /**
148
- * @param array $navMenuLocations
149
- * @param false $forceUpdate
150
- * @return array of menu items where popup is set
151
- */
152
- public function getNavMenuItemsWithPopup($navMenuLocations = array(), $forceUpdate = false)
153
- {
154
- if (!isset(self::$navMenuItems) && !$forceUpdate) {
155
- foreach ($navMenuLocations as $menuName => $menuId) {
156
- $menuItems = wp_get_nav_menu_items($menuId);
157
-
158
- if (!empty($menuItems)) {
159
- foreach ($menuItems as $menuItem) {
160
- $popupId = $menuItem->sgpbPopupId;
161
- if ($popupId > 0) {
162
- self::$navMenuItems[] = $menuItem;
163
- }
164
- }
165
- }
166
- }
167
- }
168
-
169
- return isset(self::$navMenuItems) ? self::$navMenuItems : array();
170
- }
171
-
172
- /**
173
- * @param $menu_item
174
- * @return mixed
175
- */
176
- public function addCustomNavFields($menuItem)
177
- {
178
- $menuItem->sgpbPopupId = get_post_meta($menuItem->ID, '_menu_sgpb_popup_id', true);
179
- return $menuItem;
180
- }
181
-
182
- /**
183
- * @return array of popup objects
184
- */
185
- public static function getPopups()
186
- {
187
- return SGPopup::getAllPopups();
188
- }
189
-
190
- /**
191
- * Adds custom fields to the menu item editor.
192
- *
193
- * @param $itemId
194
- * @param $item
195
- * @param $depth
196
- * @param $args
197
- */
198
- public function fields($itemId, $item, $depth, $args)
199
- { ?>
200
- <div class="description description-wide">
201
- <label for="edit-menu-item-pb-<?php echo $item->ID; ?>">
202
- <?php _e('Select a Popup', SG_POPUP_TEXT_DOMAIN); ?><br/>
203
- <select class="widefat" name="menu-item-pb[<?php echo $item->ID; ?>][popup]"
204
- id="edit-menu-item-pb-<?php echo $item->ID; ?>">
205
- <option value=""></option>
206
- <?php foreach (self::getPopups() as $popup) : ?>
207
- <option value="<?php echo $popup->getId(); ?>" <?php selected($popup->getId(), (int)get_post_meta($itemId, '_menu_sgpb_popup_id', true)); ?>>
208
- <?php echo esc_html($popup->getTitle()); ?>
209
- </option>
210
- <?php endforeach; ?>
211
- </select>
212
- <span class="description"><?php _e('Open a popup once this item is clicked.', SG_POPUP_TEXT_DOMAIN); ?></span>
213
- </label>
214
- </div>
215
- <?php
216
- }
217
-
218
- /**
219
- * Processes the saving of menu items.
220
- *
221
- * @param $menu_id
222
- * @param $item_id
223
- */
224
- public function save($menu_id, $item_id)
225
- {
226
- delete_post_meta($item_id, '_menu_sgpb_popup_id');
227
- if (isset($_POST['menu-item-pb'][$item_id]['popup'])) {
228
- $popupId = (int)$_POST['menu-item-pb'][$item_id]['popup'];
229
- update_post_meta($item_id, '_menu_sgpb_popup_id', $popupId);
230
- }
231
- }
232
- }
1
+ <?php
2
+
3
+ namespace sgpb;
4
+
5
+ /**
6
+ * Class SGPBMenu
7
+ * @package sgpb
8
+ */
9
+ class SGPBMenu
10
+ {
11
+ /**
12
+ * Singleton variable to save menu locations.
13
+ * @var
14
+ */
15
+ public static $navMenuLocations;
16
+
17
+ /**
18
+ * Singleton variable to save menu items on which popup is set.
19
+ * @var
20
+ */
21
+ public static $navMenuItems;
22
+
23
+ /**
24
+ * Menu constructor.
25
+ */
26
+ public function __construct()
27
+ {
28
+ $this->init();
29
+ }
30
+
31
+ /**
32
+ * Initialize actions and filters.
33
+ */
34
+ public function init()
35
+ {
36
+ add_action('wp_nav_menu_item_custom_fields', array($this, 'fields'), 10, 4);
37
+ add_action('wp_update_nav_menu_item', array($this, 'save'), 10, 2);
38
+
39
+ add_filter('nav_menu_css_class', array($this, 'addPopupTriggeringClass'), 10, 2);
40
+ add_filter('wp_setup_nav_menu_item', array($this, 'addCustomNavFields'));
41
+ add_filter('sgpbLoadablePopups', array($this, 'addPopupToLoad'));
42
+ }
43
+
44
+ /**
45
+ * @param $classes
46
+ * @param $menuItem
47
+ * @return mixed
48
+ */
49
+ public function addPopupTriggeringClass($classes, $menuItem)
50
+ {
51
+ $popupId = $menuItem->sgpbPopupId;
52
+ if ($popupId && !in_array('sg-popup-id-'.$popupId, $classes)) {
53
+ array_push($classes, 'sg-popup-id-'.$popupId);
54
+ }
55
+
56
+ return $classes;
57
+ }
58
+
59
+ /**
60
+ * @param $popups
61
+ * @return mixed
62
+ */
63
+ public function addPopupToLoad($popups) {
64
+ $registeredMenus = $this->getNavMenuLocations();
65
+ /* Will only return menu items on which popup is set */
66
+ $menuItems = $this->getNavMenuItemsWithPopup($registeredMenus);
67
+
68
+ foreach ($menuItems as $menuItem) {
69
+ $menuPopupId = (int)$menuItem->sgpbPopupId;
70
+
71
+ /* As $menuItems contains only menu items on which popup is set
72
+ we can check if the popup should load on current page or not */
73
+ $popup = $this->shouldLoadPopupForMenuItem($menuPopupId, $popups);
74
+ if (!$popup) {
75
+ $popup = SGPopup::find($menuPopupId);
76
+ if (!$popup instanceof SGPopup) continue;
77
+ /* We could set param everywhere as popup was not suppose to load on current page.
78
+ We could also load popup to current requested page but to avoid any confusion
79
+ it will be better to use everywhere */
80
+ // $popup->setTarget(array(
81
+ // array('param' => 'everywhere')
82
+ // ));
83
+ $popups[] = $popup;
84
+ }
85
+
86
+ $popupOpeningEvents = $popup->getEvents();
87
+
88
+ /* If the popup is setup inside the menu but there is no onclick event we will add manually */
89
+ if (!$this->inMultiDimArray('click', $popupOpeningEvents)) {
90
+ $popup->setEvents(array('param' => 'click', 'value' => ''));
91
+ }
92
+ /* if the popup is set on menu item we don't need any limitation */
93
+ //$this->disablePopupLimitation($popup);
94
+ }
95
+
96
+ return $popups;
97
+ }
98
+
99
+ /**
100
+ * @param $popup
101
+ */
102
+ private function disablePopupLimitation(&$popup)
103
+ {
104
+ $popupOptions = $popup->getOptions();
105
+ unset($popupOptions['sgpb-show-popup-same-user']);
106
+ $popup->setOptions($popupOptions);
107
+ }
108
+
109
+ /**
110
+ * @param $item
111
+ * @param $array
112
+ * @return false|int
113
+ */
114
+ private function inMultiDimArray($item , $array){
115
+ return preg_match('/"'.preg_quote($item, '/').'"/i' , json_encode($array));
116
+ }
117
+
118
+ /**
119
+ * @param $menuPopupId
120
+ * @param $popups
121
+ * @return false|mixed
122
+ */
123
+ private function shouldLoadPopupForMenuItem($menuPopupId, &$popups) {
124
+ foreach ($popups as $popup) {
125
+ $popupId = $popup->getId();
126
+ /* Menu item contains popup with current id and the popup is loaded */
127
+ if ($menuPopupId == $popupId) {
128
+ return $popup;
129
+ }
130
+ }
131
+ return false;
132
+ }
133
+
134
+ /**
135
+ * @param false $forceUpdate
136
+ * @return array
137
+ */
138
+ public function getNavMenuLocations($forceUpdate = false)
139
+ {
140
+ if (!isset(self::$navMenuLocations) && !$forceUpdate) {
141
+ self::$navMenuLocations = get_nav_menu_locations();
142
+ }
143
+
144
+ return isset(self::$navMenuLocations) ? self::$navMenuLocations : array();
145
+ }
146
+
147
+ /**
148
+ * @param array $navMenuLocations
149
+ * @param false $forceUpdate
150
+ * @return array of menu items where popup is set
151
+ */
152
+ public function getNavMenuItemsWithPopup($navMenuLocations = array(), $forceUpdate = false)
153
+ {
154
+ if (!isset(self::$navMenuItems) && !$forceUpdate) {
155
+ foreach ($navMenuLocations as $menuName => $menuId) {
156
+ $menuItems = wp_get_nav_menu_items($menuId);
157
+
158
+ if (!empty($menuItems)) {
159
+ foreach ($menuItems as $menuItem) {
160
+ $popupId = $menuItem->sgpbPopupId;
161
+ if ($popupId > 0) {
162
+ self::$navMenuItems[] = $menuItem;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ return isset(self::$navMenuItems) ? self::$navMenuItems : array();
170
+ }
171
+
172
+ /**
173
+ * @param $menu_item
174
+ * @return mixed
175
+ */
176
+ public function addCustomNavFields($menuItem)
177
+ {
178
+ $menuItem->sgpbPopupId = get_post_meta($menuItem->ID, '_menu_sgpb_popup_id', true);
179
+ return $menuItem;
180
+ }
181
+
182
+ /**
183
+ * @return array of popup objects
184
+ */
185
+ public static function getPopups()
186
+ {
187
+ return SGPopup::getAllPopups();
188
+ }
189
+
190
+ /**
191
+ * Adds custom fields to the menu item editor.
192
+ *
193
+ * @param $itemId
194
+ * @param $item
195
+ * @param $depth
196
+ * @param $args
197
+ */
198
+ public function fields($itemId, $item, $depth, $args)
199
+ { ?>
200
+ <div class="description description-wide">
201
+ <label for="edit-menu-item-pb-<?php echo $item->ID; ?>">
202
+ <?php _e('Select a Popup', SG_POPUP_TEXT_DOMAIN); ?><br/>
203
+ <select class="widefat" name="menu-item-pb[<?php echo $item->ID; ?>][popup]"
204
+ id="edit-menu-item-pb-<?php echo $item->ID; ?>">
205
+ <option value=""></option>
206
+ <?php foreach (self::getPopups() as $popup) : ?>
207
+ <option value="<?php echo $popup->getId(); ?>" <?php selected($popup->getId(), (int)get_post_meta($itemId, '_menu_sgpb_popup_id', true)); ?>>
208
+ <?php echo esc_html($popup->getTitle()); ?>
209
+ </option>
210
+ <?php endforeach; ?>
211
+ </select>
212
+ <span class="description"><?php _e('Open a popup once this item is clicked.', SG_POPUP_TEXT_DOMAIN); ?></span>
213
+ </label>
214
+ </div>
215
+ <?php
216
+ }
217
+
218
+ /**
219
+ * Processes the saving of menu items.
220
+ *
221
+ * @param $menu_id
222
+ * @param $item_id
223
+ */
224
+ public function save($menu_id, $item_id)
225
+ {
226
+ delete_post_meta($item_id, '_menu_sgpb_popup_id');
227
+ if (isset($_POST['menu-item-pb'][$item_id]['popup'])) {
228
+ $popupId = (int)$_POST['menu-item-pb'][$item_id]['popup'];
229
+ update_post_meta($item_id, '_menu_sgpb_popup_id', $popupId);
230
+ }
231
+ }
232
+ }
com/classes/dataTable/Subscribers.php CHANGED
@@ -1,206 +1,206 @@
1
- <?php
2
- require_once(SG_POPUP_CLASSES_PATH.'/Ajax.php');
3
- require_once(SG_POPUP_HELPERS_PATH.'AdminHelper.php');
4
-
5
- use sgpb\SGPopup;
6
- use sgpb\AdminHelper;
7
- use sgpbDataTable\SGPBTable;
8
- use sgpb\SubscriptionPopup;
9
-
10
- class Subscribers extends SGPBTable
11
- {
12
- public function __construct()
13
- {
14
- global $wpdb;
15
- parent::__construct('sgpbAllSubscribers');
16
-
17
- $this->setRowsPerPage(SGPB_APP_POPUP_TABLE_LIMIT);
18
- $this->setTablename($wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME);
19
-
20
- $columns = array(
21
- $this->tablename.'.id',
22
- 'firstName',
23
- 'lastName',
24
- 'email',
25
- 'cDate',
26
- 'subscriptionType'
27
- );
28
-
29
- $selectAllCheckbox = '<div class="sgpb-wrapper checkbox-wrapper">
30
- <input class="subs-bulk" type="checkbox" id="checkbox-all">
31
- <label class="checkboxLabel" for="checkbox-all"></label>
32
- </div>';
33
-
34
- $displayColumns = array(
35
- 'bulk' => $selectAllCheckbox,
36
- 'id' => 'ID',
37
- 'firstName' => __('First name', SG_POPUP_TEXT_DOMAIN),
38
- 'lastName' => __('Last name', SG_POPUP_TEXT_DOMAIN),
39
- 'email' => __('Email', SG_POPUP_TEXT_DOMAIN),
40
- 'cDate' => __('Date', SG_POPUP_TEXT_DOMAIN),
41
- 'subscriptionType' => __('Popup', SG_POPUP_TEXT_DOMAIN)
42
- //'options' => __('Actions', SG_POPUP_TEXT_DOMAIN)
43
- );
44
-
45
- $filterColumnsDisplaySettings = array(
46
- 'columns' => $columns,
47
- 'displayColumns' => $displayColumns
48
- );
49
-
50
- $filterColumnsDisplaySettings = apply_filters('sgpbAlterColumnIntoSubscribers', $filterColumnsDisplaySettings);
51
-
52
- $this->setColumns(@$filterColumnsDisplaySettings['columns']);
53
- $this->setDisplayColumns(@$filterColumnsDisplaySettings['displayColumns']);
54
- $this->setSortableColumns(array(
55
- 'id' => array('id', false),
56
- 'firstName' => array('firstName', true),
57
- 'lastName' => array('lastName', true),
58
- 'email' => array('email', true),
59
- 'cDate' => array('cDate', true),
60
- 'subscriptionType' => array('subscriptionType', true),
61
- $this->setInitialSort(array(
62
- 'id' => 'DESC'
63
- ))
64
- ));
65
- }
66
-
67
- public function customizeRow(&$row)
68
- {
69
- $popupId = (int)$row[5];
70
- $row = apply_filters('sgpbEditSubscribersTableRowValues', $row, $popupId);
71
- $row[6] = get_the_title($popupId);
72
- $row[5] = $row[4];
73
- $row[4] = $row[3];
74
- $row[3] = $row[2];
75
- $row[2] = $row[1];
76
- $row[1] = $row[0];
77
-
78
- // show date more user friendly
79
- $row[5] = date('d F Y', strtotime($row[5]));
80
-
81
- $id = $row[0];
82
- $row[0] = '<div class="sgpb-wrapper checkbox-wrapper">
83
- <input class="subs-delete-checkbox" type="checkbox" id="checkbox-'.esc_attr($id).'" data-delete-id="'.esc_attr($id).'">
84
- <label class="checkboxLabel" for="checkbox-'.esc_attr($id).'"></label>
85
- </div>';
86
- }
87
-
88
- public function customizeQuery(&$query)
89
- {
90
- $query = AdminHelper::subscribersRelatedQuery($query);
91
- }
92
-
93
- public function getNavPopupsConditions()
94
- {
95
- $subscriptionPopups = SubscriptionPopup::getAllSubscriptionForms();
96
- $list = '';
97
- $selectedPopup = '';
98
-
99
- if (isset($_GET['sgpb-subscription-popup-id'])) {
100
- $selectedPopup = (int)$_GET['sgpb-subscription-popup-id'];
101
- }
102
-
103
- ob_start();
104
- ?>
105
- <input type="hidden" class="sgpb-subscription-popup-id" name="sgpb-subscription-popup-id" value="<?php echo $selectedPopup;?>">
106
- <input type="hidden" name="page" value="<?php echo SG_POPUP_SUBSCRIBERS_PAGE; ?>" >
107
-
108
- <select class="select__select sgpb-margin-right-10" name="sgpb-subscription-popup" id="sgpb-subscription-popup">
109
- <?php
110
- $list .= '<option value="all">'.__('All', SG_POPUP_TEXT_DOMAIN).'</option>';
111
- foreach ($subscriptionPopups as $popupId => $popupTitle) {
112
- if ($selectedPopup == $popupId) {
113
- $selected = ' selected';
114
- }
115
- else {
116
- $selected = '';
117
- }
118
- $list .= '<option value="'.esc_attr($popupId).'"'.$selected.'>'.$popupTitle.'</option>';
119
- }
120
- echo $list;
121
- ?>
122
- </select>
123
- <?php
124
- $content = ob_get_contents();
125
- ob_end_clean();
126
-
127
- return $content;
128
- }
129
-
130
- public function getNavDateConditions() {
131
- $subscribersDates = SubscriptionPopup::getAllSubscribersDate();
132
- $uniqueDates = array();
133
-
134
- foreach ($subscribersDates as $arr) {
135
- $uniqueDates[] = $arr;
136
- }
137
- $uniqueDates = array_unique($uniqueDates, SORT_REGULAR);
138
-
139
- $selectedDate = '';
140
- $dateList = '';
141
- $selected = '';
142
-
143
- if (isset($_GET['sgpb-subscribers-date'])) {
144
- $selectedDate = esc_attr($_GET['sgpb-subscribers-date']);
145
- }
146
-
147
- ob_start();
148
- ?>
149
- <input type="hidden" class="sgpb-subscribers-date" name="sgpb-subscribers-date" value="<?php echo $selectedDate;?>">
150
- <select class="select__select sgpb-margin-right-10" name="sgpb-subscribers-dates" id="sgpb-subscribers-dates">
151
- <?php
152
- $gotDateList = '<option value="all">'.__('All dates', SG_POPUP_TEXT_DOMAIN).'</option>';
153
- foreach ($uniqueDates as $date) {
154
- if ($selectedDate == $date['date-value']) {
155
- $selected = ' selected';
156
- }
157
- else {
158
- $selected = '';
159
- }
160
- $gotDateList .= '<option value="'.$date['date-value'].'"'.$selected.'>'.$date['date-title'].'</option>';
161
- }
162
- if (empty($subscribersDates)) {
163
- $gotDateList = '<option value="'.@$date['date-value'].'"'.$selected.'>'.__('Date', SG_POPUP_TEXT_DOMAIN).'</option>';
164
- }
165
- echo $dateList.$gotDateList;
166
- ?>
167
- </select>
168
- <?php
169
- $content = ob_get_contents();
170
- ob_end_clean();
171
-
172
- return $content;
173
- }
174
-
175
- // parent class method overriding
176
- public function extra_tablenav($which)
177
- {
178
- $isVisibleExtraNav = $this->getIsVisibleExtraNav();
179
-
180
- if (!$isVisibleExtraNav) {
181
- return '';
182
- }
183
- ?>
184
- <div class="sgpb-display-flex sgpb-justify-content-between actions">
185
- <div>
186
- <label class="screen-reader-text" for="sgpb-subscription-popup"><?php _e('Filter by popup', SG_POPUP_TEXT_DOMAIN)?></label>
187
- <?php echo $this->getNavPopupsConditions(); ?>
188
- <label class="screen-reader-text" for="sgpb-subscribers-dates"><?php _e('Filter by date', SG_POPUP_TEXT_DOMAIN)?></label>
189
- <?php echo $this->getNavDateConditions(); ?>
190
- <input name="filter_action" id="post-query-submit" class="buttonGroup__button buttonGroup__button_blueBg buttonGroup__button_unrounded" value="<?php _e('Filter', SG_POPUP_TEXT_DOMAIN)?>" type="submit">
191
- </div>
192
- <div>
193
- <?php
194
- if ($which == 'top') {
195
- ?>
196
- <button type="button" class="sgpb-btn sgpb-btn-danger sgpb-btn-disabled sgpb-btn--rounded sg-subs-delete-button" data-ajaxNonce="<?php echo SG_AJAX_NONCE;?>">
197
- <?php _e('Delete subscriber(s)', SG_POPUP_TEXT_DOMAIN)?>
198
- </button>
199
- <?php
200
- }
201
- ?>
202
- </div>
203
- </div>
204
- <?php
205
- }
206
- }
1
+ <?php
2
+ require_once(SG_POPUP_CLASSES_PATH.'/Ajax.php');
3
+ require_once(SG_POPUP_HELPERS_PATH.'AdminHelper.php');
4
+
5
+ use sgpb\SGPopup;
6
+ use sgpb\AdminHelper;
7
+ use sgpbDataTable\SGPBTable;
8
+ use sgpb\SubscriptionPopup;
9
+
10
+ class Subscribers extends SGPBTable
11
+ {
12
+ public function __construct()
13
+ {
14
+ global $wpdb;
15
+ parent::__construct('sgpbAllSubscribers');
16
+
17
+ $this->setRowsPerPage(SGPB_APP_POPUP_TABLE_LIMIT);
18
+ $this->setTablename($wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME);
19
+
20
+ $columns = array(
21
+ $this->tablename.'.id',
22
+ 'firstName',
23
+ 'lastName',
24
+ 'email',
25
+ 'cDate',
26
+ 'subscriptionType'
27
+ );
28
+
29
+ $selectAllCheckbox = '<div class="sgpb-wrapper checkbox-wrapper">
30
+ <input class="subs-bulk" type="checkbox" id="checkbox-all">
31
+ <label class="checkboxLabel" for="checkbox-all"></label>
32
+ </div>';
33
+
34
+ $displayColumns = array(
35
+ 'bulk' => $selectAllCheckbox,
36
+ 'id' => 'ID',
37
+ 'firstName' => __('First name', SG_POPUP_TEXT_DOMAIN),
38
+ 'lastName' => __('Last name', SG_POPUP_TEXT_DOMAIN),
39
+ 'email' => __('Email', SG_POPUP_TEXT_DOMAIN),
40
+ 'cDate' => __('Date', SG_POPUP_TEXT_DOMAIN),
41
+ 'subscriptionType' => __('Popup', SG_POPUP_TEXT_DOMAIN)
42
+ //'options' => __('Actions', SG_POPUP_TEXT_DOMAIN)
43
+ );
44
+
45
+ $filterColumnsDisplaySettings = array(
46
+ 'columns' => $columns,
47
+ 'displayColumns' => $displayColumns
48
+ );
49
+
50
+ $filterColumnsDisplaySettings = apply_filters('sgpbAlterColumnIntoSubscribers', $filterColumnsDisplaySettings);
51
+
52
+ $this->setColumns(@$filterColumnsDisplaySettings['columns']);
53
+ $this->setDisplayColumns(@$filterColumnsDisplaySettings['displayColumns']);
54
+ $this->setSortableColumns(array(
55
+ 'id' => array('id', false),
56
+ 'firstName' => array('firstName', true),
57
+ 'lastName' => array('lastName', true),
58
+ 'email' => array('email', true),
59
+ 'cDate' => array('cDate', true),
60
+ 'subscriptionType' => array('subscriptionType', true),
61
+ $this->setInitialSort(array(
62
+ 'id' => 'DESC'
63
+ ))
64
+ ));
65
+ }
66
+
67
+ public function customizeRow(&$row)
68
+ {
69
+ $popupId = (int)$row[5];
70
+ $row = apply_filters('sgpbEditSubscribersTableRowValues', $row, $popupId);
71
+ $row[6] = get_the_title($popupId);
72
+ $row[5] = $row[4];
73
+ $row[4] = $row[3];
74
+ $row[3] = $row[2];
75
+ $row[2] = $row[1];
76
+ $row[1] = $row[0];
77
+
78
+ // show date more user friendly
79
+ $row[5] = date('d F Y', strtotime($row[5]));
80
+
81
+ $id = $row[0];
82
+ $row[0] = '<div class="sgpb-wrapper checkbox-wrapper">
83
+ <input class="subs-delete-checkbox" type="checkbox" id="checkbox-'.esc_attr($id).'" data-delete-id="'.esc_attr($id).'">
84
+ <label class="checkboxLabel" for="checkbox-'.esc_attr($id).'"></label>
85
+ </div>';
86
+ }
87
+
88
+ public function customizeQuery(&$query)
89
+ {
90
+ $query = AdminHelper::subscribersRelatedQuery($query);
91
+ }
92
+
93
+ public function getNavPopupsConditions()
94
+ {
95
+ $subscriptionPopups = SubscriptionPopup::getAllSubscriptionForms();
96
+ $list = '';
97
+ $selectedPopup = '';
98
+
99
+ if (isset($_GET['sgpb-subscription-popup-id'])) {
100
+ $selectedPopup = (int)$_GET['sgpb-subscription-popup-id'];
101
+ }
102
+
103
+ ob_start();
104
+ ?>
105
+ <input type="hidden" class="sgpb-subscription-popup-id" name="sgpb-subscription-popup-id" value="<?php echo $selectedPopup;?>">
106
+ <input type="hidden" name="page" value="<?php echo SG_POPUP_SUBSCRIBERS_PAGE; ?>" >
107
+
108
+ <select class="select__select sgpb-margin-right-10" name="sgpb-subscription-popup" id="sgpb-subscription-popup">
109
+ <?php
110
+ $list .= '<option value="all">'.__('All', SG_POPUP_TEXT_DOMAIN).'</option>';
111
+ foreach ($subscriptionPopups as $popupId => $popupTitle) {
112
+ if ($selectedPopup == $popupId) {
113
+ $selected = ' selected';
114
+ }
115
+ else {
116
+ $selected = '';
117
+ }
118
+ $list .= '<option value="'.esc_attr($popupId).'"'.$selected.'>'.$popupTitle.'</option>';
119
+ }
120
+ echo $list;
121
+ ?>
122
+ </select>
123
+ <?php
124
+ $content = ob_get_contents();
125
+ ob_end_clean();
126
+
127
+ return $content;
128
+ }
129
+
130
+ public function getNavDateConditions() {
131
+ $subscribersDates = SubscriptionPopup::getAllSubscribersDate();
132
+ $uniqueDates = array();
133
+
134
+ foreach ($subscribersDates as $arr) {
135
+ $uniqueDates[] = $arr;
136
+ }
137
+ $uniqueDates = array_unique($uniqueDates, SORT_REGULAR);
138
+
139
+ $selectedDate = '';
140
+ $dateList = '';
141
+ $selected = '';
142
+
143
+ if (isset($_GET['sgpb-subscribers-date'])) {
144
+ $selectedDate = esc_attr($_GET['sgpb-subscribers-date']);
145
+ }
146
+
147
+ ob_start();
148
+ ?>
149
+ <input type="hidden" class="sgpb-subscribers-date" name="sgpb-subscribers-date" value="<?php echo $selectedDate;?>">
150
+ <select class="select__select sgpb-margin-right-10" name="sgpb-subscribers-dates" id="sgpb-subscribers-dates">
151
+ <?php
152
+ $gotDateList = '<option value="all">'.__('All dates', SG_POPUP_TEXT_DOMAIN).'</option>';
153
+ foreach ($uniqueDates as $date) {
154
+ if ($selectedDate == $date['date-value']) {
155
+ $selected = ' selected';
156
+ }
157
+ else {
158
+ $selected = '';
159
+ }
160
+ $gotDateList .= '<option value="'.$date['date-value'].'"'.$selected.'>'.$date['date-title'].'</option>';
161
+ }
162
+ if (empty($subscribersDates)) {
163
+ $gotDateList = '<option value="'.@$date['date-value'].'"'.$selected.'>'.__('Date', SG_POPUP_TEXT_DOMAIN).'</option>';
164
+ }
165
+ echo $dateList.$gotDateList;
166
+ ?>
167
+ </select>
168
+ <?php
169
+ $content = ob_get_contents();
170
+ ob_end_clean();
171
+
172
+ return $content;
173
+ }
174
+
175
+ // parent class method overriding
176
+ public function extra_tablenav($which)
177
+ {
178
+ $isVisibleExtraNav = $this->getIsVisibleExtraNav();
179
+
180
+ if (!$isVisibleExtraNav) {
181
+ return '';
182
+ }
183
+ ?>
184
+ <div class="sgpb-display-flex sgpb-justify-content-between actions">
185
+ <div>
186
+ <label class="screen-reader-text" for="sgpb-subscription-popup"><?php _e('Filter by popup', SG_POPUP_TEXT_DOMAIN)?></label>
187
+ <?php echo $this->getNavPopupsConditions(); ?>
188
+ <label class="screen-reader-text" for="sgpb-subscribers-dates"><?php _e('Filter by date', SG_POPUP_TEXT_DOMAIN)?></label>
189
+ <?php echo $this->getNavDateConditions(); ?>
190
+ <input name="filter_action" id="post-query-submit" class="buttonGroup__button buttonGroup__button_blueBg buttonGroup__button_unrounded" value="<?php _e('Filter', SG_POPUP_TEXT_DOMAIN)?>" type="submit">
191
+ </div>
192
+ <div>
193
+ <?php
194
+ if ($which == 'top') {
195
+ ?>
196
+ <button type="button" class="sgpb-btn sgpb-btn-danger sgpb-btn-disabled sgpb-btn--rounded sg-subs-delete-button" data-ajaxNonce="<?php echo SG_AJAX_NONCE;?>">
197
+ <?php _e('Delete subscriber(s)', SG_POPUP_TEXT_DOMAIN)?>
198
+ </button>
199
+ <?php
200
+ }
201
+ ?>
202
+ </div>
203
+ </div>
204
+ <?php
205
+ }
206
+ }
com/classes/extension/SgpbIPopupExtension.php CHANGED
@@ -1,10 +1,10 @@
1
- <?php
2
- interface SgpbIPopupExtension
3
- {
4
- /*It's Admin scripts*/
5
- public function getScripts($page, $data);
6
- public function getStyles($page, $data);
7
- /*It's frontend scripts*/
8
- public function getFrontendScripts($page, $data);
9
- public function getFrontendStyles($page, $data);
10
  }
1
+ <?php
2
+ interface SgpbIPopupExtension
3
+ {
4
+ /*It's Admin scripts*/
5
+ public function getScripts($page, $data);
6
+ public function getStyles($page, $data);
7
+ /*It's frontend scripts*/
8
+ public function getFrontendScripts($page, $data);
9
+ public function getFrontendStyles($page, $data);
10
  }
com/classes/extension/SgpbPopupExtension.php CHANGED
@@ -1,358 +1,358 @@
1
- <?php
2
-
3
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbIPopupExtension.php');
4
- use sgpb\AdminHelper;
5
- use \sgpb\SgpbPopupVersionDetection;
6
-
7
- if (class_exists('SgpbPopupExtension')) {
8
- return false;
9
- }
10
-
11
- class SgpbPopupExtension implements SgpbIPopupExtension
12
- {
13
- public function getNewsletterPageKey()
14
- {
15
- return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_NEWSLETTER_PAGE;
16
- }
17
-
18
- public function getSettingsPageKey()
19
- {
20
- return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SETTINGS_PAGE;
21
- }
22
-
23
- public function getScripts($pageName, $data)
24
- {
25
- $jsFiles = array();
26
- $localizeData = array();
27
- $translatedData = ConfigDataHelper::getJsLocalizedData();
28
- $currentPostType = AdminHelper::getCurrentPostType();
29
- $newsletterPage = $this->getNewsletterPageKey();
30
- $settingsPage = $this->getSettingsPageKey();
31
-
32
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'ExtensionsNotification.js', 'dep' => array('jquery'));
33
- $localizeData[] = array(
34
- 'handle' => 'ExtensionsNotification.js',
35
- 'name' => 'SGPB_JS_EXTENSIONS_PARAMS',
36
- 'data' => array(
37
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
38
- 'popupPostType' => SG_POPUP_POST_TYPE,
39
- 'extendPage' => SG_POPUP_EXTEND_PAGE,
40
- 'supportUrl' => SG_POPUP_SUPPORT_URL,
41
- 'allExtensionsUrl' => SG_POPUP_ALL_EXTENSIONS_URL,
42
- 'supportPage' => SG_POPUP_SUPPORT_PAGE,
43
- 'reviewUrl' => SG_POPUP_RATE_US_URL
44
- )
45
- );
46
-
47
- $allowPages = array(
48
- 'popupType',
49
- 'editpage',
50
- 'popupspage',
51
- 'popupbuilder_page_license',
52
- $newsletterPage,
53
- $settingsPage
54
- );
55
-
56
- if ($pageName == $newsletterPage) {
57
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Newsletter.js');
58
- }
59
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js', 'dep' => array('jquery'));
60
- $localizeData[] = array(
61
- 'handle' => 'Banner.js',
62
- 'name' => 'SGPB_JS_PARAMS',
63
- 'data' => array(
64
- 'url' => admin_url('admin-ajax.php'),
65
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
66
- )
67
- );
68
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'gutenbergBlock.min.js');
69
-
70
- $localizeData[] = array(
71
- 'handle' => 'gutenbergBlock.min.js',
72
- 'name' => 'SGPB_GUTENBERG_PARAMS',
73
- 'data' => array(
74
- 'allPopups' => AdminHelper::getGutenbergPopupsIdAndTitle(),
75
- 'allEvents' => AdminHelper::getGutenbergPopupsEvents(),
76
- 'title' => __('Popup Builder', SG_POPUP_TEXT_DOMAIN),
77
- 'description' => __('This block will help you to add Popup Builder’s shortcode inside the page content', SG_POPUP_TEXT_DOMAIN),
78
- 'i18n'=> array(
79
- 'title' => __( 'WPForms', 'wpforms-lite' ),
80
- 'description' => __( 'Select and display one of your forms.', 'wpforms-lite' ),
81
- 'form_keyword' => __( 'form', 'wpforms-lite' ),
82
- 'form_select' => __( 'Select Popup', 'wpforms-lite' ),
83
- 'form_settings' => __( 'Form Settings', 'wpforms-lite' ),
84
- 'form_selected' => __( 'Form', 'wpforms-lite' ),
85
- 'show_title' => __( 'Show Title', 'wpforms-lite' ),
86
- 'show_description' => __( 'Show Description', 'wpforms-lite' ),
87
- ),
88
- 'logo_url' => SG_POPUP_IMG_URL.'bannerLogo.png',
89
- 'logo_classname' => 'sgpb-gutenberg-logo',
90
- 'clickText' => __('Click me', SG_POPUP_TEXT_DOMAIN)
91
- )
92
- );
93
-
94
- if (in_array($pageName, $allowPages) || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE) {
95
- $jsFiles[] = array('folderUrl'=> '', 'filename' => 'wp-color-picker');
96
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
97
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
98
-
99
-
100
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'bootstrap.min.js');
101
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgPopupRangeSlider.js');
102
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Backend.js');
103
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'FloatingButton.js', 'dep' => array('Backend.js'),);
104
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'NotificationCenter.js');
105
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js');
106
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
107
-
108
- $localizeData[] = array(
109
- 'handle' => 'Backend.js',
110
- 'name' => 'SGPB_JS_PARAMS',
111
- 'data' => array(
112
- 'url' => admin_url('admin-ajax.php'),
113
- 'postUrl' => SG_POPUP_ADMIN_URL.'admin-post.php',
114
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
115
- )
116
- );
117
-
118
- $localizeData[] = array(
119
- 'handle' => 'sgpbSelect2.js',
120
- 'name' => 'SGPB_JS_PACKAGES',
121
- 'data' => array(
122
- 'packages' => array(
123
- 'current' => SGPB_POPUP_PKG,
124
- 'free' => SGPB_POPUP_PKG_FREE,
125
- 'silver' => SGPB_POPUP_PKG_SILVER,
126
- 'gold' => SGPB_POPUP_PKG_GOLD,
127
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
128
- ),
129
- 'extensions' => array(
130
- 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
131
- 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
132
- ),
133
- 'proEvents' => apply_filters('sgpbProEvents', array('inactivity', 'onScroll'))
134
- )
135
- );
136
-
137
- $localizeData[] = array(
138
- 'handle' => 'Backend.js',
139
- 'name' => 'SGPB_JS_LOCALIZATION',
140
- 'data' => $translatedData
141
- );
142
-
143
- $localizeData[] = array(
144
- 'handle' => 'Popup.js',
145
- 'name' => 'sgpbPublicUrl',
146
- 'data' => SG_POPUP_PUBLIC_URL
147
- );
148
- }
149
- else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
150
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js', 'dep' => '', 'ver' => '3.86', 'inFooter' => '');
151
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
152
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Subscribers.js');
153
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js');
154
-
155
- $localizeData[] = array(
156
- 'handle' => 'Subscribers.js',
157
- 'name' => 'SGPB_JS_PARAMS',
158
- 'data' => array(
159
- 'url' => admin_url('admin-ajax.php'),
160
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
161
- 'packages' => array(
162
- 'current' => SGPB_POPUP_PKG,
163
- 'silver' => SGPB_POPUP_PKG_SILVER,
164
- 'gold' => SGPB_POPUP_PKG_GOLD,
165
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
166
- )
167
- )
168
- );
169
-
170
- $localizeData[] = array(
171
- 'handle' => 'sgpbSelect2.js',
172
- 'name' => 'SGPB_JS_PACKAGES',
173
- 'data' => array(
174
- 'packages' => array(
175
- 'current' => SGPB_POPUP_PKG,
176
- 'free' => SGPB_POPUP_PKG_FREE,
177
- 'silver' => SGPB_POPUP_PKG_SILVER,
178
- 'gold' => SGPB_POPUP_PKG_GOLD,
179
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
180
- )
181
- )
182
- );
183
-
184
- $localizeData[] = array(
185
- 'handle' => 'Subscribers.js',
186
- 'name' => 'SGPB_JS_ADMIN_URL',
187
- 'data' => array(
188
- 'url' => SG_POPUP_ADMIN_URL.'admin-post.php',
189
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
190
- )
191
- );
192
-
193
- $localizeData[] = array(
194
- 'handle' => 'Subscribers.js',
195
- 'name' => 'SGPB_JS_LOCALIZATION',
196
- 'data' => $translatedData
197
- );
198
-
199
- $localizeData[] = array(
200
- 'handle' => 'Banner.js',
201
- 'name' => 'SGPB_JS_PARAMS',
202
- 'data' => array(
203
- 'url' => admin_url('admin-ajax.php'),
204
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
205
- )
206
- );
207
- }
208
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Modals.js');
209
- if (count($versionDetection = SgpbPopupVersionDetection::compareVersions())) {
210
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbDetect.js');
211
- $localizeData[] = array(
212
- 'handle' => 'sgpbDetect.js',
213
- 'name' => 'SGPB_JS_DETECTIONS',
214
- 'data' => $versionDetection
215
- );
216
- }
217
-
218
- $scriptData = array(
219
- 'jsFiles' => apply_filters('sgpbAdminJsFiles', $jsFiles),
220
- 'localizeData' => apply_filters('sgpbAdminJsLocalizedData', $localizeData)
221
- );
222
-
223
- $scriptData = apply_filters('sgpbAdminJs', $scriptData);
224
-
225
- return $scriptData;
226
- }
227
-
228
- public function getStyles($pageName, $data)
229
- {
230
- $cssFiles = array();
231
- $newsletterPage = $this->getNewsletterPageKey();
232
- $settingsPage = $this->getSettingsPageKey();
233
-
234
- $allowPages = array(
235
- 'popupType',
236
- 'editpage',
237
- 'popupspage',
238
- 'popupbuilder_page_license',
239
- $newsletterPage,
240
- $settingsPage
241
- );
242
- if (in_array($pageName, $allowPages)) {
243
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'jquery.dateTimePicker.min.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
244
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
245
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
246
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
247
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
248
- $cssFiles[] = array('folderUrl' => '', 'filename' => 'wp-color-picker');
249
- }
250
- else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
251
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
252
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
253
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
254
-
255
- }
256
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgpb-modal.css', 'dep' => array(), 'ver' => rand(1, 10000), 'inFooter' => false);
257
-
258
- $cssData = array(
259
- 'cssFiles' => apply_filters('sgpbAdminCssFiles', $cssFiles)
260
- );
261
- return $cssData;
262
- }
263
-
264
- public function getFrontendScripts($page, $popupObjs)
265
- {
266
- $translatedData = ConfigDataHelper::getJsLocalizedData();
267
- $jsFiles = array();
268
- $localizeData = array();
269
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js', 'dep' => array('jquery'));
270
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js', 'dep' => array('Popup.js'));
271
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilder.js', 'dep' => array('PopupConfig.js'));
272
- if (SGPB_POPUP_PKG >= SGPB_POPUP_PKG_SILVER) {
273
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilderProFunctionality.js', 'dep' => array('jquery'));
274
- }
275
-
276
- $localizeData[] = array(
277
- 'handle' => 'PopupBuilder.js',
278
- 'name' => 'SGPB_POPUP_PARAMS',
279
- 'data' => array(
280
- 'popupTypeAgeRestriction' => SGPB_POPUP_TYPE_RESTRICTION,
281
- 'defaultThemeImages' => array(
282
- 1 => AdminHelper::defaultButtonImage('sgpb-theme-1'),
283
- 2 => AdminHelper::defaultButtonImage('sgpb-theme-2'),
284
- 3 => AdminHelper::defaultButtonImage('sgpb-theme-3'),
285
- 5 => AdminHelper::defaultButtonImage('sgpb-theme-5'),
286
- 6 => AdminHelper::defaultButtonImage('sgpb-theme-6')
287
- ),
288
- 'homePageUrl' => get_home_url().'/',
289
- 'isPreview' => isset($_GET['sg_popup_preview_id']),
290
- 'convertedIdsReverse' => AdminHelper::getReverseConvertIds(),
291
- 'dontShowPopupExpireTime' => SGPB_DONT_SHOW_POPUP_EXPIRY,
292
- 'conditionalJsClasses' => apply_filters('sgpbConditionalJsClasses', array()),
293
- 'disableAnalyticsGeneral' => AdminHelper::getOption('sgpb-enable-debug-mode')
294
- )
295
- );
296
-
297
- $localizeData[] = array(
298
- 'handle' => 'PopupBuilder.js',
299
- 'name' => 'SGPB_JS_PACKAGES',
300
- 'data' => array(
301
- 'packages' => array(
302
- 'current' => SGPB_POPUP_PKG,
303
- 'free' => SGPB_POPUP_PKG_FREE,
304
- 'silver' => SGPB_POPUP_PKG_SILVER,
305
- 'gold' => SGPB_POPUP_PKG_GOLD,
306
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
307
- ),
308
- 'extensions' => array(
309
- 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
310
- 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
311
- )
312
- )
313
- );
314
-
315
- $localizeData[] = array(
316
- 'handle' => 'Popup.js',
317
- 'name' => 'sgpbPublicUrl',
318
- 'data' => SG_POPUP_PUBLIC_URL
319
- );
320
-
321
- $localizeData[] = array(
322
- 'handle' => 'Popup.js',
323
- 'name' => 'SGPB_JS_LOCALIZATION',
324
- 'data' => $translatedData
325
- );
326
-
327
- $localizeData[] = array(
328
- 'handle' => 'PopupBuilder.js',
329
- 'name' => 'SGPB_JS_PARAMS',
330
- 'data' => array(
331
- 'ajaxUrl' => admin_url('admin-ajax.php'),
332
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
333
- )
334
- );
335
-
336
- $scriptData = array(
337
- 'jsFiles' => apply_filters('sgpbFrontendJsFiles', $jsFiles),
338
- 'localizeData' => apply_filters('sgpbFrontendJsLocalizedData', $localizeData)
339
- );
340
-
341
- $scriptData = apply_filters('sgpbFrontendJs', $scriptData);
342
-
343
- return $scriptData;
344
- }
345
-
346
- public function getFrontendStyles($page, $data)
347
- {
348
- $cssFiles = array();
349
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
350
-
351
- $cssData = array(
352
- 'cssFiles' => apply_filters('sgpbFrontendCssFiles', $cssFiles)
353
- );
354
-
355
- return $cssData;
356
- }
357
-
358
- }
1
+ <?php
2
+
3
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbIPopupExtension.php');
4
+ use sgpb\AdminHelper;
5
+ use \sgpb\SgpbPopupVersionDetection;
6
+
7
+ if (class_exists('SgpbPopupExtension')) {
8
+ return false;
9
+ }
10
+
11
+ class SgpbPopupExtension implements SgpbIPopupExtension
12
+ {
13
+ public function getNewsletterPageKey()
14
+ {
15
+ return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_NEWSLETTER_PAGE;
16
+ }
17
+
18
+ public function getSettingsPageKey()
19
+ {
20
+ return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SETTINGS_PAGE;
21
+ }
22
+
23
+ public function getScripts($pageName, $data)
24
+ {
25
+ $jsFiles = array();
26
+ $localizeData = array();
27
+ $translatedData = ConfigDataHelper::getJsLocalizedData();
28
+ $currentPostType = AdminHelper::getCurrentPostType();
29
+ $newsletterPage = $this->getNewsletterPageKey();
30
+ $settingsPage = $this->getSettingsPageKey();
31
+
32
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'ExtensionsNotification.js', 'dep' => array('jquery'));
33
+ $localizeData[] = array(
34
+ 'handle' => 'ExtensionsNotification.js',
35
+ 'name' => 'SGPB_JS_EXTENSIONS_PARAMS',
36
+ 'data' => array(
37
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
38
+ 'popupPostType' => SG_POPUP_POST_TYPE,
39
+ 'extendPage' => SG_POPUP_EXTEND_PAGE,
40
+ 'supportUrl' => SG_POPUP_SUPPORT_URL,
41
+ 'allExtensionsUrl' => SG_POPUP_ALL_EXTENSIONS_URL,
42
+ 'supportPage' => SG_POPUP_SUPPORT_PAGE,
43
+ 'reviewUrl' => SG_POPUP_RATE_US_URL
44
+ )
45
+ );
46
+
47
+ $allowPages = array(
48
+ 'popupType',
49
+ 'editpage',
50
+ 'popupspage',
51
+ 'popupbuilder_page_license',
52
+ $newsletterPage,
53
+ $settingsPage
54
+ );
55
+
56
+ if ($pageName == $newsletterPage) {
57
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Newsletter.js');
58
+ }
59
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js', 'dep' => array('jquery'));
60
+ $localizeData[] = array(
61
+ 'handle' => 'Banner.js',
62
+ 'name' => 'SGPB_JS_PARAMS',
63
+ 'data' => array(
64
+ 'url' => admin_url('admin-ajax.php'),
65
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
66
+ )
67
+ );
68
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'gutenbergBlock.min.js');
69
+
70
+ $localizeData[] = array(
71
+ 'handle' => 'gutenbergBlock.min.js',
72
+ 'name' => 'SGPB_GUTENBERG_PARAMS',
73
+ 'data' => array(
74
+ 'allPopups' => AdminHelper::getGutenbergPopupsIdAndTitle(),
75
+ 'allEvents' => AdminHelper::getGutenbergPopupsEvents(),
76
+ 'title' => __('Popup Builder', SG_POPUP_TEXT_DOMAIN),
77
+ 'description' => __('This block will help you to add Popup Builder’s shortcode inside the page content', SG_POPUP_TEXT_DOMAIN),
78
+ 'i18n'=> array(
79
+ 'title' => __( 'WPForms', 'wpforms-lite' ),
80
+ 'description' => __( 'Select and display one of your forms.', 'wpforms-lite' ),
81
+ 'form_keyword' => __( 'form', 'wpforms-lite' ),
82
+ 'form_select' => __( 'Select Popup', 'wpforms-lite' ),
83
+ 'form_settings' => __( 'Form Settings', 'wpforms-lite' ),
84
+ 'form_selected' => __( 'Form', 'wpforms-lite' ),
85
+ 'show_title' => __( 'Show Title', 'wpforms-lite' ),
86
+ 'show_description' => __( 'Show Description', 'wpforms-lite' ),
87
+ ),
88
+ 'logo_url' => SG_POPUP_IMG_URL.'bannerLogo.png',
89
+ 'logo_classname' => 'sgpb-gutenberg-logo',
90
+ 'clickText' => __('Click me', SG_POPUP_TEXT_DOMAIN)
91
+ )
92
+ );
93
+
94
+ if (in_array($pageName, $allowPages) || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE) {
95
+ $jsFiles[] = array('folderUrl'=> '', 'filename' => 'wp-color-picker');
96
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
97
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
98
+
99
+
100
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'bootstrap.min.js');
101
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgPopupRangeSlider.js');
102
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Backend.js');
103
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'FloatingButton.js', 'dep' => array('Backend.js'),);
104
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'NotificationCenter.js');
105
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js');
106
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
107
+
108
+ $localizeData[] = array(
109
+ 'handle' => 'Backend.js',
110
+ 'name' => 'SGPB_JS_PARAMS',
111
+ 'data' => array(
112
+ 'url' => admin_url('admin-ajax.php'),
113
+ 'postUrl' => SG_POPUP_ADMIN_URL.'admin-post.php',
114
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
115
+ )
116
+ );
117
+
118
+ $localizeData[] = array(
119
+ 'handle' => 'sgpbSelect2.js',
120
+ 'name' => 'SGPB_JS_PACKAGES',
121
+ 'data' => array(
122
+ 'packages' => array(
123
+ 'current' => SGPB_POPUP_PKG,
124
+ 'free' => SGPB_POPUP_PKG_FREE,
125
+ 'silver' => SGPB_POPUP_PKG_SILVER,
126
+ 'gold' => SGPB_POPUP_PKG_GOLD,
127
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
128
+ ),
129
+ 'extensions' => array(
130
+ 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
131
+ 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
132
+ ),
133
+ 'proEvents' => apply_filters('sgpbProEvents', array('inactivity', 'onScroll'))
134
+ )
135
+ );
136
+
137
+ $localizeData[] = array(
138
+ 'handle' => 'Backend.js',
139
+ 'name' => 'SGPB_JS_LOCALIZATION',
140
+ 'data' => $translatedData
141
+ );
142
+
143
+ $localizeData[] = array(
144
+ 'handle' => 'Popup.js',
145
+ 'name' => 'sgpbPublicUrl',
146
+ 'data' => SG_POPUP_PUBLIC_URL
147
+ );
148
+ }
149
+ else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
150
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js', 'dep' => '', 'ver' => '3.86', 'inFooter' => '');
151
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
152
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Subscribers.js');
153
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js');
154
+
155
+ $localizeData[] = array(
156
+ 'handle' => 'Subscribers.js',
157
+ 'name' => 'SGPB_JS_PARAMS',
158
+ 'data' => array(
159
+ 'url' => admin_url('admin-ajax.php'),
160
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
161
+ 'packages' => array(
162
+ 'current' => SGPB_POPUP_PKG,
163
+ 'silver' => SGPB_POPUP_PKG_SILVER,
164
+ 'gold' => SGPB_POPUP_PKG_GOLD,
165
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
166
+ )
167
+ )
168
+ );
169
+
170
+ $localizeData[] = array(
171
+ 'handle' => 'sgpbSelect2.js',
172
+ 'name' => 'SGPB_JS_PACKAGES',
173
+ 'data' => array(
174
+ 'packages' => array(
175
+ 'current' => SGPB_POPUP_PKG,
176
+ 'free' => SGPB_POPUP_PKG_FREE,
177
+ 'silver' => SGPB_POPUP_PKG_SILVER,
178
+ 'gold' => SGPB_POPUP_PKG_GOLD,
179
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
180
+ )
181
+ )
182
+ );
183
+
184
+ $localizeData[] = array(
185
+ 'handle' => 'Subscribers.js',
186
+ 'name' => 'SGPB_JS_ADMIN_URL',
187
+ 'data' => array(
188
+ 'url' => SG_POPUP_ADMIN_URL.'admin-post.php',
189
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
190
+ )
191
+ );
192
+
193
+ $localizeData[] = array(
194
+ 'handle' => 'Subscribers.js',
195
+ 'name' => 'SGPB_JS_LOCALIZATION',
196
+ 'data' => $translatedData
197
+ );
198
+
199
+ $localizeData[] = array(
200
+ 'handle' => 'Banner.js',
201
+ 'name' => 'SGPB_JS_PARAMS',
202
+ 'data' => array(
203
+ 'url' => admin_url('admin-ajax.php'),
204
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
205
+ )
206
+ );
207
+ }
208
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Modals.js');
209
+ if (count($versionDetection = SgpbPopupVersionDetection::compareVersions())) {
210
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbDetect.js');
211
+ $localizeData[] = array(
212
+ 'handle' => 'sgpbDetect.js',
213
+ 'name' => 'SGPB_JS_DETECTIONS',
214
+ 'data' => $versionDetection
215
+ );
216
+ }
217
+
218
+ $scriptData = array(
219
+ 'jsFiles' => apply_filters('sgpbAdminJsFiles', $jsFiles),
220
+ 'localizeData' => apply_filters('sgpbAdminJsLocalizedData', $localizeData)
221
+ );
222
+
223
+ $scriptData = apply_filters('sgpbAdminJs', $scriptData);
224
+
225
+ return $scriptData;
226
+ }
227
+
228
+ public function getStyles($pageName, $data)
229
+ {
230
+ $cssFiles = array();
231
+ $newsletterPage = $this->getNewsletterPageKey();
232
+ $settingsPage = $this->getSettingsPageKey();
233
+
234
+ $allowPages = array(
235
+ 'popupType',
236
+ 'editpage',
237
+ 'popupspage',
238
+ 'popupbuilder_page_license',
239
+ $newsletterPage,
240
+ $settingsPage
241
+ );
242
+ if (in_array($pageName, $allowPages)) {
243
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'jquery.dateTimePicker.min.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
244
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
245
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
246
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
247
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => rand(1, 1000), 'inFooter' => false);
248
+ $cssFiles[] = array('folderUrl' => '', 'filename' => 'wp-color-picker');
249
+ }
250
+ else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
251
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
252
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
253
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
254
+
255
+ }
256
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgpb-modal.css', 'dep' => array(), 'ver' => rand(1, 10000), 'inFooter' => false);
257
+
258
+ $cssData = array(
259
+ 'cssFiles' => apply_filters('sgpbAdminCssFiles', $cssFiles)
260
+ );
261
+ return $cssData;
262
+ }
263
+
264
+ public function getFrontendScripts($page, $popupObjs)
265
+ {
266
+ $translatedData = ConfigDataHelper::getJsLocalizedData();
267
+ $jsFiles = array();
268
+ $localizeData = array();
269
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js', 'dep' => array('jquery'));
270
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js', 'dep' => array('Popup.js'));
271
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilder.js', 'dep' => array('PopupConfig.js'));
272
+ if (SGPB_POPUP_PKG >= SGPB_POPUP_PKG_SILVER) {
273
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilderProFunctionality.js', 'dep' => array('jquery'));
274
+ }
275
+
276
+ $localizeData[] = array(
277
+ 'handle' => 'PopupBuilder.js',
278
+ 'name' => 'SGPB_POPUP_PARAMS',
279
+ 'data' => array(
280
+ 'popupTypeAgeRestriction' => SGPB_POPUP_TYPE_RESTRICTION,
281
+ 'defaultThemeImages' => array(
282
+ 1 => AdminHelper::defaultButtonImage('sgpb-theme-1'),
283
+ 2 => AdminHelper::defaultButtonImage('sgpb-theme-2'),
284
+ 3 => AdminHelper::defaultButtonImage('sgpb-theme-3'),
285
+ 5 => AdminHelper::defaultButtonImage('sgpb-theme-5'),
286
+ 6 => AdminHelper::defaultButtonImage('sgpb-theme-6')
287
+ ),
288
+ 'homePageUrl' => get_home_url().'/',
289
+ 'isPreview' => isset($_GET['sg_popup_preview_id']),
290
+ 'convertedIdsReverse' => AdminHelper::getReverseConvertIds(),
291
+ 'dontShowPopupExpireTime' => SGPB_DONT_SHOW_POPUP_EXPIRY,
292
+ 'conditionalJsClasses' => apply_filters('sgpbConditionalJsClasses', array()),
293
+ 'disableAnalyticsGeneral' => AdminHelper::getOption('sgpb-enable-debug-mode')
294
+ )
295
+ );
296
+
297
+ $localizeData[] = array(
298
+ 'handle' => 'PopupBuilder.js',
299
+ 'name' => 'SGPB_JS_PACKAGES',
300
+ 'data' => array(
301
+ 'packages' => array(
302
+ 'current' => SGPB_POPUP_PKG,
303
+ 'free' => SGPB_POPUP_PKG_FREE,
304
+ 'silver' => SGPB_POPUP_PKG_SILVER,
305
+ 'gold' => SGPB_POPUP_PKG_GOLD,
306
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
307
+ ),
308
+ 'extensions' => array(
309
+ 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
310
+ 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
311
+ )
312
+ )
313
+ );
314
+
315
+ $localizeData[] = array(
316
+ 'handle' => 'Popup.js',
317
+ 'name' => 'sgpbPublicUrl',
318
+ 'data' => SG_POPUP_PUBLIC_URL
319
+ );
320
+
321
+ $localizeData[] = array(
322
+ 'handle' => 'Popup.js',
323
+ 'name' => 'SGPB_JS_LOCALIZATION',
324
+ 'data' => $translatedData
325
+ );
326
+
327
+ $localizeData[] = array(
328
+ 'handle' => 'PopupBuilder.js',
329
+ 'name' => 'SGPB_JS_PARAMS',
330
+ 'data' => array(
331
+ 'ajaxUrl' => admin_url('admin-ajax.php'),
332
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
333
+ )
334
+ );
335
+
336
+ $scriptData = array(
337
+ 'jsFiles' => apply_filters('sgpbFrontendJsFiles', $jsFiles),
338
+ 'localizeData' => apply_filters('sgpbFrontendJsLocalizedData', $localizeData)
339
+ );
340
+
341
+ $scriptData = apply_filters('sgpbFrontendJs', $scriptData);
342
+
343
+ return $scriptData;
344
+ }
345
+
346
+ public function getFrontendStyles($page, $data)
347
+ {
348
+ $cssFiles = array();
349
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
350
+
351
+ $cssData = array(
352
+ 'cssFiles' => apply_filters('sgpbFrontendCssFiles', $cssFiles)
353
+ );
354
+
355
+ return $cssData;
356
+ }
357
+
358
+ }
com/classes/extension/SgpbPopupExtensionActivator.php CHANGED
@@ -1,108 +1,108 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class PopupExtensionActivator
5
- {
6
- public function activate()
7
- {
8
- $extensions = get_option('sgpbExtensionsInfo');
9
-
10
- if (empty($extensions)) {
11
- return false;
12
- }
13
-
14
- foreach ($extensions as $folderName => $extension) {
15
- if (empty($extension['key'])) {
16
- continue;
17
- }
18
- $key = $extension['key'];
19
-
20
- if ($folderName == 'popupbuilder-woocommerce') {
21
- $key = $folderName.'/popupbuilderWoocommerce.php';
22
- }
23
- else if ($folderName == 'popupbuilder-restriction') {
24
- $key = $folderName.'/PopupBuilderAgerestriction.php';
25
- }
26
- else if ($folderName == 'popupbuilder-aweber') {
27
- $key = $folderName.'/PopupBuilderAWeber.php';
28
- }
29
- else if ($folderName == 'popupbuilder-adblock') {
30
- $key = $folderName.'/PopupBuilderAdBlock.php';
31
- }
32
-
33
- activate_plugin($key);
34
- }
35
-
36
- return true;
37
- }
38
-
39
- private function getExtensionsInfo()
40
- {
41
- $extensionsInfo = array();
42
- if (!file_exists(SG_POPUP_BUILDER_PATH.'extensions')) {
43
- return $extensionsInfo;
44
- }
45
- $it = new \RecursiveDirectoryIterator(SG_POPUP_BUILDER_PATH.'extensions', \RecursiveDirectoryIterator::SKIP_DOTS);
46
-
47
-
48
- foreach ($it as $path => $fileInfo) {
49
- if (empty($fileInfo)) {
50
- continue;
51
- }
52
- $extensionFolderName = $fileInfo->getFilename();
53
- $extensionMainFile = $this->getExtensionMainFile($extensionFolderName);
54
- $extensionKey = $extensionFolderName.'/'.$extensionMainFile;
55
-
56
- $extensionsInfo[$extensionFolderName] = array('key' => $extensionKey, 'mainFileName' => $extensionMainFile);
57
- }
58
-
59
- return $extensionsInfo;
60
- }
61
-
62
- public function install()
63
- {
64
- $extensionsInfo = $this->getExtensionsInfo();
65
-
66
- if (!get_option('sgpbExtensionsInfo')) {
67
- update_option('sgpbExtensionsInfo', $extensionsInfo);
68
- }
69
- $this->moveExtensionToPluginsSection($extensionsInfo);
70
- }
71
-
72
- private function moveExtensionToPluginsSection($extensionsInfo)
73
- {
74
- foreach ($extensionsInfo as $extensionFolder => $extensionsDetail) {
75
- $passedExtension = WP_PLUGIN_DIR.DIRECTORY_SEPARATOR.$extensionFolder.DIRECTORY_SEPARATOR;
76
- $originalExtension = SG_POPUP_BUILDER_PATH.'extensions'.DIRECTORY_SEPARATOR.$extensionFolder.DIRECTORY_SEPARATOR;
77
- @rename($originalExtension,$passedExtension);
78
- }
79
- }
80
-
81
- private function getExtensionMainFile($folderName)
82
- {
83
- if (empty($folderName)) {
84
- return '';
85
- }
86
-
87
- $explodedData = explode('-', $folderName);
88
-
89
- if (empty($explodedData)) {
90
- return '';
91
- }
92
- $explodedData = array_filter(array_values($explodedData), array($this, 'ucifirstElements'));
93
- $fileName = implode('', $explodedData);
94
-
95
- return $fileName.'.php';
96
- }
97
-
98
- private function ucifirstElements(&$element)
99
- {
100
- if ($element == 'popupbuilder') {
101
- $element = 'PopupBuilder';
102
- return $element;
103
- }
104
- $element = ucfirst($element);
105
-
106
- return $element;
107
- }
108
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class PopupExtensionActivator
5
+ {
6
+ public function activate()
7
+ {
8
+ $extensions = get_option('sgpbExtensionsInfo');
9
+
10
+ if (empty($extensions)) {
11
+ return false;
12
+ }
13
+
14
+ foreach ($extensions as $folderName => $extension) {
15
+ if (empty($extension['key'])) {
16
+ continue;
17
+ }
18
+ $key = $extension['key'];
19
+
20
+ if ($folderName == 'popupbuilder-woocommerce') {
21
+ $key = $folderName.'/popupbuilderWoocommerce.php';
22
+ }
23
+ else if ($folderName == 'popupbuilder-restriction') {
24
+ $key = $folderName.'/PopupBuilderAgerestriction.php';
25
+ }
26
+ else if ($folderName == 'popupbuilder-aweber') {
27
+ $key = $folderName.'/PopupBuilderAWeber.php';
28
+ }
29
+ else if ($folderName == 'popupbuilder-adblock') {
30
+ $key = $folderName.'/PopupBuilderAdBlock.php';
31
+ }
32
+
33
+ activate_plugin($key);
34
+ }
35
+
36
+ return true;
37
+ }
38
+
39
+ private function getExtensionsInfo()
40
+ {
41
+ $extensionsInfo = array();
42
+ if (!file_exists(SG_POPUP_BUILDER_PATH.'extensions')) {
43
+ return $extensionsInfo;
44
+ }
45
+ $it = new \RecursiveDirectoryIterator(SG_POPUP_BUILDER_PATH.'extensions', \RecursiveDirectoryIterator::SKIP_DOTS);
46
+
47
+
48
+ foreach ($it as $path => $fileInfo) {
49
+ if (empty($fileInfo)) {
50
+ continue;
51
+ }
52
+ $extensionFolderName = $fileInfo->getFilename();
53
+ $extensionMainFile = $this->getExtensionMainFile($extensionFolderName);
54
+ $extensionKey = $extensionFolderName.'/'.$extensionMainFile;
55
+
56
+ $extensionsInfo[$extensionFolderName] = array('key' => $extensionKey, 'mainFileName' => $extensionMainFile);
57
+ }
58
+
59
+ return $extensionsInfo;
60
+ }
61
+
62
+ public function install()
63
+ {
64
+ $extensionsInfo = $this->getExtensionsInfo();
65
+
66
+ if (!get_option('sgpbExtensionsInfo')) {
67
+ update_option('sgpbExtensionsInfo', $extensionsInfo);
68
+ }
69
+ $this->moveExtensionToPluginsSection($extensionsInfo);
70
+ }
71
+
72
+ private function moveExtensionToPluginsSection($extensionsInfo)
73
+ {
74
+ foreach ($extensionsInfo as $extensionFolder => $extensionsDetail) {
75
+ $passedExtension = WP_PLUGIN_DIR.DIRECTORY_SEPARATOR.$extensionFolder.DIRECTORY_SEPARATOR;
76
+ $originalExtension = SG_POPUP_BUILDER_PATH.'extensions'.DIRECTORY_SEPARATOR.$extensionFolder.DIRECTORY_SEPARATOR;
77
+ @rename($originalExtension,$passedExtension);
78
+ }
79
+ }
80
+
81
+ private function getExtensionMainFile($folderName)
82
+ {
83
+ if (empty($folderName)) {
84
+ return '';
85
+ }
86
+
87
+ $explodedData = explode('-', $folderName);
88
+
89
+ if (empty($explodedData)) {
90
+ return '';
91
+ }
92
+ $explodedData = array_filter(array_values($explodedData), array($this, 'ucifirstElements'));
93
+ $fileName = implode('', $explodedData);
94
+
95
+ return $fileName.'.php';
96
+ }
97
+
98
+ private function ucifirstElements(&$element)
99
+ {
100
+ if ($element == 'popupbuilder') {
101
+ $element = 'PopupBuilder';
102
+ return $element;
103
+ }
104
+ $element = ucfirst($element);
105
+
106
+ return $element;
107
+ }
108
+ }
com/classes/extension/SgpbPopupExtensionRegister.php CHANGED
@@ -1,120 +1,120 @@
1
- <?php
2
- use sgpb\AdminHelper;
3
-
4
- class SgpbPopupExtensionRegister
5
- {
6
- public static function register($pluginName, $classPath, $className, $options = array())
7
- {
8
- if (is_multisite() && is_network_admin()) {
9
- global $wp_version;
10
-
11
- if ($wp_version > '4.6.0') {
12
- $blogs = get_sites();
13
- }
14
- else {
15
- $blogs = wp_get_sites();
16
- }
17
-
18
- foreach ($blogs as $blog) {
19
- /* $blog -> List of WP_Site objects for wp > 4.6 otherwise, an associative array of WP_Site data as arrays. */
20
- $blogId = is_object($blog)?$blog->blog_id:$blog['blog_id'];
21
- switch_to_blog($blogId);
22
- }
23
- return;
24
- }
25
-
26
- self::registerPlugin($pluginName, $classPath, $className, $options);
27
- }
28
-
29
- private static function registerPlugin($pluginName, $classPath, $className, $options = array())
30
- {
31
- $registeredData = array();
32
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
33
-
34
- if (!empty($registeredPlugins)) {
35
- $registeredData = $registeredPlugins;
36
- $registeredData = json_decode($registeredData, true);
37
- }
38
-
39
- if (empty($classPath) || empty($className)) {
40
- if(!empty($registeredData[$pluginName])) {
41
- /*Delete the plugin from the registered plugins' list if the class name or the class path is empty.*/
42
- unset($registeredData[$pluginName]);
43
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
44
- }
45
-
46
- return;
47
- }
48
- $classPath = str_replace(SG_POPUP_PLUGIN_PATH, '', $classPath);
49
- $pluginData['classPath'] = $classPath;
50
- $pluginData['className'] = $className;
51
- $pluginData['options'] = $options;
52
-
53
- $registeredData[$pluginName] = $pluginData;
54
- $registeredData = json_encode($registeredData);
55
-
56
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
57
- // it seems we have an inactive extension now
58
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
59
-
60
- do_action('sgpb_extension_activation_hook', $pluginData);
61
- }
62
-
63
- private static function isPluginActive($plugin)
64
- {
65
- $activePlugins = (array)AdminHelper::getOption('active_plugins', array(1));
66
- return in_array($plugin, $activePlugins, true);
67
- }
68
-
69
- public static function remove($pluginName)
70
- {
71
- if (is_multisite() && is_network_admin()) {
72
- global $wp_version;
73
-
74
- if ($wp_version > '4.6.0') {
75
- $blogs = get_sites();
76
- }
77
- else {
78
- $blogs = wp_get_sites();
79
- }
80
-
81
- foreach ($blogs as $blog) {
82
- /* $blog -> List of WP_Site objects for wp > 4.6 otherwise, an associative array of WP_Site data as arrays. */
83
- $blogId = is_object($blog)?$blog->blog_id:$blog['blog_id'];
84
- switch_to_blog($blogId);
85
- if (!self::isPluginActive($pluginName)) {
86
- self::removePlugin($pluginName);
87
- }
88
- restore_current_blog();
89
- }
90
- return;
91
- }
92
-
93
- self::removePlugin($pluginName);
94
- }
95
-
96
- private static function removePlugin($pluginName)
97
- {
98
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
99
-
100
- if (!$registeredPlugins) {
101
- return false;
102
- }
103
-
104
- $registeredData = json_decode($registeredPlugins, true);
105
-
106
- if(empty($registeredData)) {
107
- return false;
108
- }
109
-
110
- if (empty($registeredData[$pluginName])) {
111
- return false;
112
- }
113
- unset($registeredData[$pluginName]);
114
- $registeredData = json_encode($registeredData);
115
-
116
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
117
-
118
- return true;
119
- }
120
- }
1
+ <?php
2
+ use sgpb\AdminHelper;
3
+
4
+ class SgpbPopupExtensionRegister
5
+ {
6
+ public static function register($pluginName, $classPath, $className, $options = array())
7
+ {
8
+ if (is_multisite() && is_network_admin()) {
9
+ global $wp_version;
10
+
11
+ if ($wp_version > '4.6.0') {
12
+ $blogs = get_sites();
13
+ }
14
+ else {
15
+ $blogs = wp_get_sites();
16
+ }
17
+
18
+ foreach ($blogs as $blog) {
19
+ /* $blog -> List of WP_Site objects for wp > 4.6 otherwise, an associative array of WP_Site data as arrays. */
20
+ $blogId = is_object($blog)?$blog->blog_id:$blog['blog_id'];
21
+ switch_to_blog($blogId);
22
+ }
23
+ return;
24
+ }
25
+
26
+ self::registerPlugin($pluginName, $classPath, $className, $options);
27
+ }
28
+
29
+ private static function registerPlugin($pluginName, $classPath, $className, $options = array())
30
+ {
31
+ $registeredData = array();
32
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
33
+
34
+ if (!empty($registeredPlugins)) {
35
+ $registeredData = $registeredPlugins;
36
+ $registeredData = json_decode($registeredData, true);
37
+ }
38
+
39
+ if (empty($classPath) || empty($className)) {
40
+ if(!empty($registeredData[$pluginName])) {
41
+ /*Delete the plugin from the registered plugins' list if the class name or the class path is empty.*/
42
+ unset($registeredData[$pluginName]);
43
+ AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
44
+ }
45
+
46
+ return;
47
+ }
48
+ $classPath = str_replace(SG_POPUP_PLUGIN_PATH, '', $classPath);
49
+ $pluginData['classPath'] = $classPath;
50
+ $pluginData['className'] = $className;
51
+ $pluginData['options'] = $options;
52
+
53
+ $registeredData[$pluginName] = $pluginData;
54
+ $registeredData = json_encode($registeredData);
55
+
56
+ AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
57
+ // it seems we have an inactive extension now
58
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
59
+
60
+ do_action('sgpb_extension_activation_hook', $pluginData);
61
+ }
62
+
63
+ private static function isPluginActive($plugin)
64
+ {
65
+ $activePlugins = (array)AdminHelper::getOption('active_plugins', array(1));
66
+ return in_array($plugin, $activePlugins, true);
67
+ }
68
+
69
+ public static function remove($pluginName)
70
+ {
71
+ if (is_multisite() && is_network_admin()) {
72
+ global $wp_version;
73
+
74
+ if ($wp_version > '4.6.0') {
75
+ $blogs = get_sites();
76
+ }
77
+ else {
78
+ $blogs = wp_get_sites();
79
+ }
80
+
81
+ foreach ($blogs as $blog) {
82
+ /* $blog -> List of WP_Site objects for wp > 4.6 otherwise, an associative array of WP_Site data as arrays. */
83
+ $blogId = is_object($blog)?$blog->blog_id:$blog['blog_id'];
84
+ switch_to_blog($blogId);
85
+ if (!self::isPluginActive($pluginName)) {
86
+ self::removePlugin($pluginName);
87
+ }
88
+ restore_current_blog();
89
+ }
90
+ return;
91
+ }
92
+
93
+ self::removePlugin($pluginName);
94
+ }
95
+
96
+ private static function removePlugin($pluginName)
97
+ {
98
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
99
+
100
+ if (!$registeredPlugins) {
101
+ return false;
102
+ }
103
+
104
+ $registeredData = json_decode($registeredPlugins, true);
105
+
106
+ if(empty($registeredData)) {
107
+ return false;
108
+ }
109
+
110
+ if (empty($registeredData[$pluginName])) {
111
+ return false;
112
+ }
113
+ unset($registeredData[$pluginName]);
114
+ $registeredData = json_encode($registeredData);
115
+
116
+ AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
117
+
118
+ return true;
119
+ }
120
+ }
com/classes/popups/FblikePopup.php CHANGED
@@ -1,114 +1,114 @@
1
- <?php
2
- namespace sgpb;
3
- require_once(dirname(__FILE__).'/SGPopup.php');
4
-
5
- class FblikePopup extends SGPopup
6
- {
7
- public function getOptionValue($optionName, $forceDefaultValue = false)
8
- {
9
- return parent::getOptionValue($optionName, $forceDefaultValue);
10
- }
11
-
12
- public function getPopupTypeOptionsView()
13
- {
14
- return array(
15
- 'filePath' => SG_POPUP_TYPE_OPTIONS_PATH.'facebook.php',
16
- 'metaboxTitle' => 'Facebook Settings',
17
- 'short_description' => 'Select your Facebook page URL for liking and sharing it'
18
- );
19
- }
20
-
21
- private function getScripts()
22
- {
23
- /*get WordPress localization name*/
24
- $locale = $this->getSiteLocale();
25
- ob_start();
26
- ?>
27
- <script>
28
- jQuery(window).on('sgpbDidOpen', function (e) {
29
- var sgpbOldCB = window.fbAsyncInit;
30
- window.fbAsyncInit = function () {
31
- if (typeof sgpbOldCB === 'function') {
32
- sgpbOldCB();
33
- }
34
- FB.init({
35
- appId: <?php echo SGPB_FACEBOOK_APP_ID;?>
36
- });
37
- };
38
- (function(d, s, id) {
39
- var js, fjs = d.getElementsByTagName(s)[0];
40
- if (d.getElementById(id)) return;
41
- js = d.createElement(s); js.id = id;
42
- js.src = 'https://connect.facebook.net/<?php echo $locale;?>/all.js#xfbml=1&version=v2.11&appId=<?php echo SGPB_FACEBOOK_APP_ID;?>';
43
- fjs.parentNode.insertBefore(js, fjs);
44
- }(document, 'script', 'facebook-jssdk'));
45
- });
46
- </script>
47
- <?php
48
- $scripts = ob_get_contents();
49
- ob_get_clean();
50
-
51
- return $scripts;
52
- }
53
-
54
- private function getButtonConfig($shareUrl, $layout, $shareButtonStatus)
55
- {
56
- ob_start();
57
- ?>
58
- <div class='sg-fb-buttons-wrapper sgpb-fb-wrapper-<?php echo $layout;?>'>
59
- <div class="fb-like"
60
- data-href="<?php echo $shareUrl; ?>"
61
- data-layout="<?php echo $layout; ?>"
62
- data-action="like"
63
- data-size="small"
64
- data-show-faces="true"
65
- data-share="<?php echo $shareButtonStatus; ?>">
66
- </div>
67
- </div>
68
- <?php
69
- $buttonConfig = ob_get_contents();
70
- ob_get_clean();
71
-
72
- return $buttonConfig;
73
- }
74
-
75
- private function getFblikeContent()
76
- {
77
- $options = $this->getOptions();
78
- $shareUrl = $options['sgpb-fblike-like-url'];
79
- $layout = $options['sgpb-fblike-layout'];
80
- $shareButtonStatus = true;
81
- if (!empty($options['sgpb-fblike-dont-show-share-button'])) {
82
- $shareButtonStatus = false;
83
- }
84
-
85
- $scripts = $this->getScripts();
86
- $buttonConfig = $this->getButtonConfig($shareUrl, $layout, $shareButtonStatus);
87
- ob_start();
88
- ?>
89
- <div id="sg-facebook-like">
90
- <div id="fb-root"></div>
91
- <?php echo $buttonConfig; ?>
92
- <?php echo $scripts; ?>
93
- </div>
94
- <?php
95
- $content = ob_get_contents();
96
- ob_get_clean();
97
-
98
- return $content;
99
- }
100
-
101
- public function getPopupTypeContent()
102
- {
103
- $fbLikeContent = $this->getFblikeContent();
104
- $popupContent = $this->getContent();
105
- $popupContent .= $fbLikeContent;
106
-
107
- return $popupContent;
108
- }
109
-
110
- public function getExtraRenderOptions()
111
- {
112
- return array();
113
- }
114
- }
1
+ <?php
2
+ namespace sgpb;
3
+ require_once(dirname(__FILE__).'/SGPopup.php');
4
+
5
+ class FblikePopup extends SGPopup
6
+ {
7
+ public function getOptionValue($optionName, $forceDefaultValue = false)
8
+ {
9
+ return parent::getOptionValue($optionName, $forceDefaultValue);
10
+ }
11
+
12
+ public function getPopupTypeOptionsView()
13
+ {
14
+ return array(
15
+ 'filePath' => SG_POPUP_TYPE_OPTIONS_PATH.'facebook.php',
16
+ 'metaboxTitle' => 'Facebook Settings',
17
+ 'short_description' => 'Select your Facebook page URL for liking and sharing it'
18
+ );
19
+ }
20
+
21
+ private function getScripts()
22
+ {
23
+ /*get WordPress localization name*/
24
+ $locale = $this->getSiteLocale();
25
+ ob_start();
26
+ ?>
27
+ <script>
28
+ jQuery(window).on('sgpbDidOpen', function (e) {
29
+ var sgpbOldCB = window.fbAsyncInit;
30
+ window.fbAsyncInit = function () {
31
+ if (typeof sgpbOldCB === 'function') {
32
+ sgpbOldCB();
33
+ }
34
+ FB.init({
35
+ appId: <?php echo SGPB_FACEBOOK_APP_ID;?>
36
+ });
37
+ };
38
+ (function(d, s, id) {
39
+ var js, fjs = d.getElementsByTagName(s)[0];
40
+ if (d.getElementById(id)) return;
41
+ js = d.createElement(s); js.id = id;
42
+ js.src = 'https://connect.facebook.net/<?php echo $locale;?>/all.js#xfbml=1&version=v2.11&appId=<?php echo SGPB_FACEBOOK_APP_ID;?>';
43
+ fjs.parentNode.insertBefore(js, fjs);
44
+ }(document, 'script', 'facebook-jssdk'));
45
+ });
46
+ </script>
47
+ <?php
48
+ $scripts = ob_get_contents();
49
+ ob_get_clean();
50
+
51
+ return $scripts;
52
+ }
53
+
54
+ private function getButtonConfig($shareUrl, $layout, $shareButtonStatus)
55
+ {
56
+ ob_start();
57
+ ?>
58
+ <div class='sg-fb-buttons-wrapper sgpb-fb-wrapper-<?php echo $layout;?>'>
59
+ <div class="fb-like"
60
+ data-href="<?php echo $shareUrl; ?>"
61
+ data-layout="<?php echo $layout; ?>"
62
+ data-action="like"
63
+ data-size="small"
64
+ data-show-faces="true"
65
+ data-share="<?php echo $shareButtonStatus; ?>">
66
+ </div>
67
+ </div>
68
+ <?php
69
+ $buttonConfig = ob_get_contents();
70
+ ob_get_clean();
71
+
72
+ return $buttonConfig;
73
+ }
74
+
75
+ private function getFblikeContent()
76
+ {
77
+ $options = $this->getOptions();
78
+ $shareUrl = $options['sgpb-fblike-like-url'];
79
+ $layout = $options['sgpb-fblike-layout'];
80
+ $shareButtonStatus = true;
81
+ if (!empty($options['sgpb-fblike-dont-show-share-button'])) {
82
+ $shareButtonStatus = false;
83
+ }
84
+
85
+ $scripts = $this->getScripts();
86
+ $buttonConfig = $this->getButtonConfig($shareUrl, $layout, $shareButtonStatus);
87
+ ob_start();
88
+ ?>
89
+ <div id="sg-facebook-like">
90
+ <div id="fb-root"></div>
91
+ <?php echo $buttonConfig; ?>
92
+ <?php echo $scripts; ?>
93
+ </div>
94
+ <?php
95
+ $content = ob_get_contents();
96
+ ob_get_clean();
97
+
98
+ return $content;
99
+ }
100
+
101
+ public function getPopupTypeContent()
102
+ {
103
+ $fbLikeContent = $this->getFblikeContent();
104
+ $popupContent = $this->getContent();
105
+ $popupContent .= $fbLikeContent;
106
+
107
+ return $popupContent;
108
+ }
109
+
110
+ public function getExtraRenderOptions()
111
+ {
112
+ return array();
113
+ }
114
+ }
com/classes/popups/HtmlPopup.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- namespace sgpb;
3
- require_once(dirname(__FILE__).'/SGPopup.php') ;
4
- class HtmlPopup extends SGPopup
5
- {
6
-
7
- public function getOptionValue($optionName, $forceDefaultValue = false)
8
- {
9
- return parent::getOptionValue($optionName, $forceDefaultValue);
10
- }
11
-
12
- public function getPopupTypeOptionsView()
13
- {
14
- return array();
15
- }
16
-
17
- public function getPopupTypeMainView()
18
- {
19
- return array();
20
- }
21
-
22
- public function getPopupTypeContent()
23
- {
24
- $htmlContent = '';
25
- $popupContent = $this->getContent();
26
- $htmlContent .= '<div class="sgpb-main-html-content-wrapper">';
27
- $htmlContent .= $popupContent;
28
- $htmlContent .= '</div>';
29
-
30
- return $htmlContent;
31
- }
32
-
33
- public function getExtraRenderOptions()
34
- {
35
- return array();
36
- }
37
- }
38
-
1
+ <?php
2
+ namespace sgpb;
3
+ require_once(dirname(__FILE__).'/SGPopup.php') ;
4
+ class HtmlPopup extends SGPopup
5
+ {
6
+
7
+ public function getOptionValue($optionName, $forceDefaultValue = false)
8
+ {
9
+ return parent::getOptionValue($optionName, $forceDefaultValue);
10
+ }
11
+
12
+ public function getPopupTypeOptionsView()
13
+ {
14
+ return array();
15
+ }
16
+
17
+ public function getPopupTypeMainView()
18
+ {
19
+ return array();
20
+ }
21
+
22
+ public function getPopupTypeContent()
23
+ {
24
+ $htmlContent = '';
25
+ $popupContent = $this->getContent();
26
+ $htmlContent .= '<div class="sgpb-main-html-content-wrapper">';
27
+ $htmlContent .= $popupContent;
28
+ $htmlContent .= '</div>';
29
+
30
+ return $htmlContent;
31
+ }
32
+
33
+ public function getExtraRenderOptions()
34
+ {
35
+ return array();
36
+ }
37
+ }
38
+
com/classes/popups/ImagePopup.php CHANGED
@@ -1,90 +1,90 @@
1
- <?php
2
- namespace sgpb;
3
- require_once(dirname(__FILE__).'/SGPopup.php');
4
-
5
- class ImagePopup extends SGPopup
6
- {
7
- public function save()
8
- {
9
- $imageData = '';
10
- $savedImageUrl = '';
11
- $data = $this->getSanitizedData();
12
- $imageUrl = @$data['sgpb-image-url'];
13
- $savedPopup = $this->getSavedPopup();
14
-
15
- if (is_object($savedPopup)) {
16
- $imageData = $savedPopup->getOptionvalue('sgpb-image-data');
17
- $savedImageUrl = $savedPopup->getOptionValue('sgpb-image-url');
18
- }
19
-
20
- $data['sgpb-image-url'] = $imageUrl;
21
- $this->setSanitizedData($data);
22
-
23
- parent::save();
24
- }
25
-
26
- public function getOptionValue($optionName, $forceDefaultValue = false)
27
- {
28
- return parent::getOptionValue($optionName, $forceDefaultValue);
29
- }
30
-
31
- public function getPopupTypeOptionsView()
32
- {
33
- return array(
34
- 'filePath' => SG_POPUP_TYPE_MAIN_PATH.'image.php',
35
- 'metaboxTitle' => 'Image Settings',
36
- 'short_description' => 'Upload your feature image for the popup'
37
- );
38
- }
39
-
40
- public function getRemoveOptions()
41
- {
42
-
43
- // Where 1 mean this options must not show for this popup type
44
- $removeOptions = array(
45
- 'sgpb-reopen-after-form-submission' => 1,
46
- 'sgpb-background-image' => 1,
47
- 'sgpb-background-image-mode' => 1,
48
- 'sgpb-force-rtl' => 1,
49
- 'sgpb-content-padding' => 1
50
- );
51
- $parentOptions = parent::getRemoveOptions();
52
- if ($this->getType() != 'image') {
53
- return $parentOptions;
54
- }
55
-
56
- return $removeOptions + $parentOptions;
57
- }
58
-
59
- public function getPopupTypeMainView()
60
- {
61
- return array();
62
- }
63
-
64
- /**
65
- * It returns what the current post supports (for example: title, editor, etc...)
66
- *
67
- * @since 1.0.0
68
- *
69
- * @return array
70
- */
71
- public static function getPopupTypeSupports()
72
- {
73
- return array('title');
74
- }
75
-
76
- public function getPopupTypeContent()
77
- {
78
- $id = $this->getId();
79
- $imageUrl = $this->getOptionValue('sgpb-image-url');
80
-
81
- $imageAltText = AdminHelper::getImageAltTextByUrl($imageUrl);
82
-
83
- return '<img width="1" height="1" class="sgpb-preloaded-image-'.$id.'" alt="'.$imageAltText.'" src="'.$imageUrl.'" style="position:absolute;right:9999999999999px;">';
84
- }
85
-
86
- public function getExtraRenderOptions()
87
- {
88
- return array();
89
- }
90
- }
1
+ <?php
2
+ namespace sgpb;
3
+ require_once(dirname(__FILE__).'/SGPopup.php');
4
+
5
+ class ImagePopup extends SGPopup
6
+ {
7
+ public function save()
8
+ {
9
+ $imageData = '';
10
+ $savedImageUrl = '';
11
+ $data = $this->getSanitizedData();
12
+ $imageUrl = @$data['sgpb-image-url'];
13
+ $savedPopup = $this->getSavedPopup();
14
+
15
+ if (is_object($savedPopup)) {
16
+ $imageData = $savedPopup->getOptionvalue('sgpb-image-data');
17
+ $savedImageUrl = $savedPopup->getOptionValue('sgpb-image-url');
18
+ }
19
+
20
+ $data['sgpb-image-url'] = $imageUrl;
21
+ $this->setSanitizedData($data);
22
+
23
+ parent::save();
24
+ }
25
+
26
+ public function getOptionValue($optionName, $forceDefaultValue = false)
27
+ {
28
+ return parent::getOptionValue($optionName, $forceDefaultValue);
29
+ }
30
+
31
+ public function getPopupTypeOptionsView()
32
+ {
33
+ return array(
34
+ 'filePath' => SG_POPUP_TYPE_MAIN_PATH.'image.php',
35
+ 'metaboxTitle' => 'Image Settings',
36
+ 'short_description' => 'Upload your feature image for the popup'
37
+ );
38
+ }
39
+
40
+ public function getRemoveOptions()
41
+ {
42
+
43
+ // Where 1 mean this options must not show for this popup type
44
+ $removeOptions = array(
45
+ 'sgpb-reopen-after-form-submission' => 1,
46
+ 'sgpb-background-image' => 1,
47
+ 'sgpb-background-image-mode' => 1,
48
+ 'sgpb-force-rtl' => 1,
49
+ 'sgpb-content-padding' => 1
50
+ );
51
+ $parentOptions = parent::getRemoveOptions();
52
+ if ($this->getType() != 'image') {
53
+ return $parentOptions;
54
+ }
55
+
56
+ return $removeOptions + $parentOptions;
57
+ }
58
+
59
+ public function getPopupTypeMainView()
60
+ {
61
+ return array();
62
+ }
63
+
64
+ /**
65
+ * It returns what the current post supports (for example: title, editor, etc...)
66
+ *
67
+ * @since 1.0.0
68
+ *
69
+ * @return array
70
+ */
71
+ public static function getPopupTypeSupports()
72
+ {
73
+ return array('title');
74
+ }
75
+
76
+ public function getPopupTypeContent()
77
+ {
78
+ $id = $this->getId();
79
+ $imageUrl = $this->getOptionValue('sgpb-image-url');
80
+
81
+ $imageAltText = AdminHelper::getImageAltTextByUrl($imageUrl);
82
+
83
+ return '<img width="1" height="1" class="sgpb-preloaded-image-'.$id.'" alt="'.$imageAltText.'" src="'.$imageUrl.'" style="position:absolute;right:9999999999999px;">';
84
+ }
85
+
86
+ public function getExtraRenderOptions()
87
+ {
88
+ return array();
89
+ }
90
+ }
com/classes/popups/PopupData.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- class PopupData
5
- {
6
- private static $popupData = array();
7
-
8
- private function __construct()
9
- {
10
- }
11
-
12
- public static function getPopupDataById($popupId, $saveMode = '')
13
- {
14
- if (!isset(self::$popupData[$popupId])) {
15
- self::$popupData[$popupId] = SGPopup::getSavedData($popupId, $saveMode);
16
- }
17
-
18
- return self::$popupData[$popupId];
19
- }
20
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ class PopupData
5
+ {
6
+ private static $popupData = array();
7
+
8
+ private function __construct()
9
+ {
10
+ }
11
+
12
+ public static function getPopupDataById($popupId, $saveMode = '')
13
+ {
14
+ if (!isset(self::$popupData[$popupId])) {
15
+ self::$popupData[$popupId] = SGPopup::getSavedData($popupId, $saveMode);
16
+ }
17
+
18
+ return self::$popupData[$popupId];
19
+ }
20
+ }
com/classes/popups/SGPopup.php CHANGED
@@ -1,1749 +1,1749 @@
1
- <?php
2
- namespace sgpb;
3
- use \ConfigDataHelper;
4
- use \WP_Post;
5
-
6
- if (class_exists("sgpb\SGPopup")) {
7
- return;
8
- }
9
-
10
- abstract class SGPopup
11
- {
12
- protected $type;
13
-
14
- private $sanitizedData;
15
- private $postData = array();
16
- private $id;
17
- private $title;
18
- private $content;
19
- private $target;
20
- private $conditions;
21
- private $events = array();
22
- private $options;
23
- private $loadableModes;
24
- private $saveMode = '';
25
- private $savedPopup = false;
26
-
27
-
28
- public function setId($id)
29
- {
30
- $this->id = $id;
31
- }
32
-
33
- public function getId()
34
- {
35
- return (int)$this->id;
36
- }
37
-
38
- public function setTitle($title)
39
- {
40
- $this->title = $title;
41
- }
42
-
43
- public function getTitle()
44
- {
45
- return $this->title;
46
- }
47
-
48
- public function setType($type)
49
- {
50
- $this->type = $type;
51
- }
52
-
53
- public function getType()
54
- {
55
- return $this->type;
56
- }
57
-
58
- public function setTarget($target)
59
- {
60
- $this->target = $target;
61
- }
62
-
63
- public function getTarget()
64
- {
65
- return $this->target;
66
- }
67
-
68
- public function setEvents($events)
69
- {
70
- $this->events = $events;
71
- }
72
-
73
- public function getEvents()
74
- {
75
- return $this->events;
76
- }
77
-
78
- public function setConditions($conditions)
79
- {
80
- $this->conditions = $conditions;
81
- }
82
-
83
- public function getConditions()
84
- {
85
- return $this->conditions;
86
- }
87
-
88
- public function setOptions($options)
89
- {
90
- $this->options = $options;
91
- }
92
-
93
- public function getOptions()
94
- {
95
- return $this->options;
96
- }
97
-
98
- public function setLoadableModes($loadableModes)
99
- {
100
- $this->loadableModes = $loadableModes;
101
- }
102
-
103
- public function getLoadableModes()
104
- {
105
- return $this->loadableModes;
106
- }
107
-
108
- public function setSaveMode($saveMode)
109
- {
110
- $this->saveMode = $saveMode;
111
- }
112
-
113
- public function getSaveMode()
114
- {
115
- return $this->saveMode;
116
- }
117
-
118
- public function setSavedPopup($savedPopup)
119
- {
120
- $this->savedPopup = $savedPopup;
121
- }
122
-
123
- public function getSavedPopup()
124
- {
125
- return $this->savedPopup;
126
- }
127
-
128
- public function setContent($content)
129
- {
130
- $this->content = $content;
131
- }
132
-
133
- public function setSavedPopupById($popupId)
134
- {
135
- $popup = SGPopup::find($popupId);
136
- if (is_object($popup)) {
137
- $this->setSavedPopup($popup);
138
- }
139
- }
140
-
141
- public function setReportData($popupId)
142
- {
143
- $events = $this->getEvents();
144
- $options = $this->getOptions();
145
- $targets = $this->getTarget();
146
- $conditions = $this->getConditions();
147
- do_action('sgpbDebugReportUpdate', 'options', $options, $popupId);
148
- do_action('sgpbDebugReportUpdate', 'events', $events, $popupId);
149
- do_action('sgpbDebugReportUpdate', 'targets', $targets, $popupId);
150
- do_action('sgpbDebugReportUpdate', 'conditions', $conditions, $popupId);
151
- }
152
-
153
- public function getPopupAllEvents($postId, $popupId, $popupObj = false)
154
- {
155
- $events = array();
156
-
157
- $loadableModes = $this->getLoadableModes();
158
-
159
- if (isset($loadableModes['attr_event'])) {
160
- $customEvents = SGPopup::getPostPopupCustomEvent($postId, $popupId);
161
- $events = array_merge($events, $customEvents);
162
- }
163
-
164
- if (isset($loadableModes['option_event']) || is_null($loadableModes)) {
165
- $optionEvents = $this->getEvents();
166
- if (!is_array($optionEvents)) {
167
- $optionEvents = array();
168
- }
169
- $events = array_merge($events, $optionEvents);
170
- }
171
-
172
- if (!empty($popupObj->getOptionValue('sgpb-enable-floating-button'))) {
173
- $events[] = array('param' => 'setByCssClass', 'hiddenOption' => array());
174
- }
175
-
176
- return apply_filters('sgpbPopupEvents', $events, $popupObj);
177
- }
178
-
179
- public function getContent()
180
- {
181
- $postId = $this->getId();
182
-
183
- if (!AdminHelper::hasBlocks($this->content)) {
184
- $popupContent = wpautop($this->content);
185
- } else {
186
- $popupContent = $this->content;
187
- }
188
-
189
- $editorContent = AdminHelper::checkEditorByPopupId($postId);
190
- if (!empty($editorContent)) {
191
- if (class_exists('Vc_Manager')) {
192
- $popupContent .= $editorContent;
193
- }
194
- else {
195
- $popupContent = $editorContent;
196
- }
197
- }
198
-
199
- return $popupContent;
200
- }
201
-
202
- public function setPostData($postData)
203
- {
204
- $this->postData = apply_filters('sgpbSavedPostData', $postData);
205
- }
206
-
207
- public function getPostData()
208
- {
209
- return $this->postData;
210
- }
211
-
212
- public function getPopupTypeContent()
213
- {
214
- return $this->getContent();
215
- }
216
-
217
- public function insertIntoSanitizedData($sanitizedData)
218
- {
219
- if (!empty($sanitizedData)) {
220
- $this->sanitizedData[$sanitizedData['name']] = $sanitizedData['value'];
221
- }
222
- }
223
-
224
- abstract public function getExtraRenderOptions();
225
-
226
- public function setSanitizedData($sanitizedData)
227
- {
228
- $this->sanitizedData = $sanitizedData;
229
- }
230
-
231
- public function getSanitizedData()
232
- {
233
- return $this->sanitizedData;
234
- }
235
-
236
- /**
237
- * Find popup and create this object
238
- *
239
- * @since 1.0.0
240
- *
241
- * @param object|int $popup
242
- *
243
- * @return object|false $obj
244
- */
245
- public static function find($popup, $args = array())
246
- {
247
- if (isset($_GET['sg_popup_preview_id'])) {
248
- $args['is-preview'] = true;
249
- }
250
- // If the popup is object get data from object otherwise we find needed data from WordPress functions
251
- if ($popup instanceof WP_Post) {
252
- $status = $popup->post_status;
253
- $title = $popup->post_title;
254
- $popupContent = $popup->post_content;
255
- $popupId = $popup->ID;
256
- }
257
- else {
258
- $popupId = $popup;
259
- $popupPost = get_post($popupId);
260
- if (empty($popupPost)) {
261
- return false;
262
- }
263
- $title = get_the_title($popupId);
264
- $status = get_post_status($popupId);
265
- $popupContent = $popupPost->post_content;
266
- }
267
- $allowedStatus = array('publish', 'draft');
268
-
269
- if (!empty($args['status'])) {
270
- $allowedStatus = $args['status'];
271
- }
272
-
273
- if (!isset($args['checkActivePopupType']) && !in_array($status, $allowedStatus)) {
274
- return $status;
275
- }
276
- $saveMode = '';
277
- global $post;
278
- if ((@is_preview() && $post->ID == $popupId) || isset($args['preview'])) {
279
- $saveMode = '_preview';
280
- }
281
- if (isset($args['is-preview'])) {
282
- $saveMode = '_preview';
283
- }
284
- if (isset($args['insidePopup']) && $args['insidePopup'] == 'on') {
285
- $saveMode = '';
286
- }
287
- $currentPost = get_post($popupId);
288
- $currentPostStatus = $currentPost->post_status;
289
- if ($currentPostStatus == 'draft') {
290
- $saveMode = '_preview';
291
- }
292
-
293
- $savedData = array();
294
- if (file_exists(dirname(__FILE__).'/PopupData.php')) {
295
- require_once(dirname(__FILE__).'/PopupData.php');
296
- $savedData = PopupData::getPopupDataById($popupId, $saveMode);
297
- }
298
- $savedData = apply_filters('sgpbPopupSavedData', $savedData);
299
-
300
- if (empty($savedData)) {
301
- return false;
302
- }
303
-
304
- $type = 'html';
305
- if (isset($savedData['sgpb-type'])) {
306
- $type = $savedData['sgpb-type'];
307
- }
308
-
309
- $popupClassName = self::getPopupClassNameFormType($type);
310
- $typePath = self::getPopupTypeClassPath($type);
311
- if (!file_exists($typePath.$popupClassName.'.php')) {
312
- return false;
313
- }
314
- require_once($typePath.$popupClassName.'.php');
315
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
316
-
317
- $obj = new $popupClassName();
318
- $obj->setId($popupId);
319
- $obj->setType($type);
320
- $obj->setTitle($title);
321
- $obj->setContent($popupContent);
322
-
323
- if (!empty($savedData['sgpb-target'][0])) {
324
- $obj->setTarget($savedData['sgpb-target'][0]);
325
- }
326
- unset($savedData['sgpb-target']);
327
- if (!empty($savedData['sgpb-events'][0])) {
328
- $events = self::shapeEventsToOneArray($savedData['sgpb-events'][0]);
329
- $obj->setEvents($events);
330
- }
331
- unset($savedData['sgpb-events']);
332
- if (!empty($savedData['sgpb-conditions'][0])) {
333
- $obj->setConditions($savedData['sgpb-conditions'][0]);
334
- }
335
- unset($savedData['sgpb-conditions']);
336
-
337
- $obj->setOptions($savedData);
338
-
339
- return $obj;
340
- }
341
-
342
- private static function shapeEventsToOneArray($events)
343
- {
344
- $eventsData = array();
345
- if (!empty($events)) {
346
- foreach ($events as $event) {
347
- if (empty($event['hiddenOption'])) {
348
- $eventsData[] = $event;
349
- continue;
350
- }
351
- $hiddenOptions = $event['hiddenOption'];
352
- unset($event['hiddenOption']);
353
- $eventsData[] = $event + $hiddenOptions;
354
- }
355
- }
356
-
357
- return apply_filters('sgpbEventsToOneArray', $eventsData);
358
- }
359
-
360
- public static function getPopupClassNameFormType($type)
361
- {
362
- $popupName = ucfirst(strtolower($type));
363
- $popupClassName = $popupName.'Popup';
364
-
365
- return apply_filters('sgpbPopupClassNameFromType', $popupClassName);
366
- }
367
-
368
- public static function getPopupTypeClassPath($type)
369
- {
370
- global $SGPB_POPUP_TYPES;
371
- $typePaths = $SGPB_POPUP_TYPES['typePath'];
372
-
373
- if (empty($typePaths[$type])) {
374
- return SG_POPUP_CLASSES_POPUPS_PATH;
375
- }
376
-
377
- return $typePaths[$type];
378
- }
379
-
380
- public function sanitizeValueByType($value, $type)
381
- {
382
- switch ($type) {
383
- case 'string':
384
- if (is_array($value)) {
385
- $sanitizedValue = $this->recursiveSanitizeTextField($value);
386
- }
387
- else {
388
- $sanitizedValue = htmlspecialchars($value);
389
- }
390
- break;
391
- case 'text':
392
- $sanitizedValue = htmlspecialchars($value);
393
- break;
394
- case 'array':
395
- $sanitizedValue = $this->recursiveSanitizeTextField($value);
396
- break;
397
- case 'email':
398
- $sanitizedValue = sanitize_email($value);
399
- break;
400
- case 'sgpb':
401
- $sanitizedValue = $this->recursiveHtmlSpecialchars($value);
402
- break;
403
- default:
404
- $sanitizedValue = sanitize_text_field($value);
405
- break;
406
- }
407
-
408
- return $sanitizedValue;
409
- }
410
-
411
- public function recursiveSanitizeTextField($array)
412
- {
413
- if (!is_array($array)) {
414
- return $array;
415
- }
416
-
417
- foreach ($array as $key => &$value) {
418
- if (is_array($value)) {
419
- $value = $this->recursiveSanitizeTextField($value);
420
- }
421
- else {
422
- /*get simple field type and do sanitization*/
423
- $defaultData = $this->getDefaultDataByName($key);
424
- if (empty($defaultData['type'])) {
425
- $defaultData['type'] = 'string';
426
- }
427
- $value = $this->sanitizeValueByType($value, $defaultData['type']);
428
- }
429
- }
430
-
431
- return $array;
432
- }
433
-
434
- public function recursiveHtmlSpecialchars($array)
435
- {
436
- if (!is_array($array)) {
437
- return $array;
438
- }
439
-
440
- foreach ($array as $key => &$value) {
441
- if (is_array($value)) {
442
- $value = $this->recursiveHtmlSpecialchars($value);
443
- }
444
- else {
445
- $value = htmlspecialchars($value);
446
- }
447
- }
448
-
449
- return $array;
450
- }
451
-
452
- public static function parsePopupDataFromData($data)
453
- {
454
- $popupData = array();
455
- $data = apply_filters('sgpbFilterOptionsBeforeSaving', $data);
456
-
457
- foreach ($data as $key => $value) {
458
- if (strpos($key, 'sgpb') === 0) {
459
- $popupData[$key] = $value;
460
- }
461
- if (is_array($value) && isset($value['name']) && strpos($value['name'], 'sgpb') === 0) {
462
- $popupData[$value['name']] = $value['value'];
463
- }
464
- else if (is_array($value) && isset($value['name']) && strpos($value['name'], 'post_ID') === 0) {
465
- $popupData['sgpb-post-id'] = $value['value'];
466
- }
467
- }
468
-
469
- return $popupData;
470
- }
471
-
472
- public static function create($data = array(), $saveMode = '', $firstTime = 0)
473
- {
474
- $obj = new static();
475
- $obj->setSaveMode($saveMode);
476
- $additionalData = $obj->addAdditionalSettings($data, $obj);
477
- $data = array_merge($data, $additionalData);
478
- $data = apply_filters('sgpbAdvancedOptionsDefaultValues', $data);
479
- foreach ($data as $name => $value) {
480
- if (strpos($name, 'sgpb') === 0) {
481
- $defaultData = $obj->getDefaultDataByName($name);
482
- if (empty($defaultData['type'])) {
483
- $defaultData['type'] = 'string';
484
- }
485
- $sanitizedValue = $obj->sanitizeValueByType($value, $defaultData['type']);
486
- $obj->insertIntoSanitizedData(array('name' => $name,'value' => $sanitizedValue));
487
- }
488
- }
489
-
490
- $obj->setSavedPopupById($data['sgpb-post-id']);
491
- $result = $obj->save();
492
-
493
- $result = apply_filters('sgpbPopupCreateResult', $result);
494
-
495
- if ($result) {
496
- return $obj;
497
- }
498
-
499
- return $result;
500
- }
501
-
502
- public function save()
503
- {
504
- $this->convertImagesToData();
505
- $data = $this->getSanitizedData();
506
- $popupId = $data['sgpb-post-id'];
507
-
508
- $this->setId($popupId);
509
-
510
- if (!empty($data['sgpb-target'])) {
511
- $this->setTarget($data['sgpb-target']);
512
- /*remove from popup options because it's useless to save it twice*/
513
- unset($data['sgpb-target']);
514
- }
515
- if (!empty($data['sgpb-conditions'])) {
516
- $this->setConditions($data['sgpb-conditions']);
517
- unset($data['sgpb-conditions']);
518
- }
519
- if (!empty($data['sgpb-events'])) {
520
- $this->setEvents($data['sgpb-events']);
521
- unset($data['sgpb-events']);
522
- }
523
- $data = $this->customScriptsSave($data);
524
- $this->setOptions($data);
525
-
526
- $targets = $this->targetSave();
527
- $events = $this->eventsSave();
528
- $options = $this->popupOptionsSave();
529
-
530
- return ($targets && $events && $options);
531
- }
532
-
533
- public function convertImagesToData()
534
- {
535
- $buttonImageData = '';
536
- $savedImageUrl = '';
537
- $savedContentBackgroundImageUrl = '';
538
- $contentBackgroundImageData = '';
539
-
540
- $data = $this->getSanitizedData();
541
- $buttonImageUrl = @$data['sgpb-button-image'];
542
- $contentBackgroundImageUrl = @$data['sgpb-background-image'];
543
-
544
- $savedPopup = $this->getSavedPopup();
545
-
546
- if (is_object($savedPopup)) {
547
- $buttonImageData = $savedPopup->getOptionvalue('sgpb-button-image-data');
548
- $savedImageUrl = $savedPopup->getOptionValue('sgpb-button-image');
549
- $contentBackgroundImageData = $savedPopup->getOptionValue('sgpb-background-image-data');
550
- $savedContentBackgroundImageUrl = $savedPopup->getOptionValue('sgpb-background-image');
551
- }
552
-
553
- if ($buttonImageUrl != $savedImageUrl) {
554
- $buttonImageData = AdminHelper::getImageDataFromUrl($buttonImageUrl, true);
555
- }
556
- if ($contentBackgroundImageUrl != $savedContentBackgroundImageUrl) {
557
- $contentBackgroundImageData = AdminHelper::getImageDataFromUrl($contentBackgroundImageUrl);
558
- }
559
-
560
- $data['sgpb-button-image-data'] = $buttonImageData;
561
- $data['sgpb-background-image-data'] = $contentBackgroundImageData;
562
-
563
- $data = apply_filters('sgpbConvertImagesToData', $data);
564
- $this->setSanitizedData($data);
565
- }
566
-
567
- private function customScriptsSave($data)
568
- {
569
- $popupId = $this->getId();
570
- $popupContent = $this->getContent();
571
-
572
- $defaultData = ConfigDataHelper::defaultData();
573
- $defaultDataJs = $defaultData['customEditorContent']['js']['helperText'];
574
- $defaultDataCss = $defaultData['customEditorContent']['css']['oldDefaultValue'];
575
-
576
- $finalData = array('js' => array(), 'css' => array());
577
- $alreadySavedData = get_post_meta($popupId, 'sg_popup_scripts', true);
578
-
579
- // get styles
580
- $finalData['css'] = $data['sgpb-css-editor'];
581
- $defaultDataCss = $defaultDataCss[0];
582
-
583
- $defaultDataCss = preg_replace('/\s/', '', $defaultDataCss);
584
- $temp = preg_replace('/\s/', '', $finalData['css']);
585
-
586
- unset($data['sgpb-css-editor']);
587
-
588
- if ($temp == $defaultDataCss) {
589
- unset($finalData['css']);
590
- }
591
-
592
- // get scripts
593
- foreach ($defaultDataJs as $key => $value) {
594
- if ($data['sgpb-'.$key] == '') {
595
- unset($data['sgpb-'.$key]);
596
- continue;
597
- }
598
- if ($key == 'ShouldOpen' || $key == 'ShouldClose') {
599
- $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
600
- continue;
601
- }
602
- $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
603
- unset($data['sgpb-'.$key]);
604
- }
605
-
606
- if ($alreadySavedData == $finalData) {
607
- return $data;
608
- }
609
-
610
- array_walk_recursive($finalData, function(&$element){
611
- $element = str_replace(array("\r\n"), "\n", $element);
612
- });
613
-
614
- update_post_meta($popupId, 'sg_popup_scripts', $finalData);
615
-
616
- return $data;
617
- }
618
-
619
- private function targetSave()
620
- {
621
- global $SGPB_DATA_CONFIG_ARRAY;
622
- $saveMode = $this->getSaveMode();
623
- $popupId = $this->getId();
624
- $targetData = $this->getTarget();
625
- $conditionsData = $this->getConditions();
626
-
627
- $targetConfig = $SGPB_DATA_CONFIG_ARRAY['target'];
628
- $paramsData = $targetConfig['paramsData'];
629
- $attrs = $targetConfig['attrs'];
630
- $popupTarget = array();
631
- if (empty($targetData)) {
632
- return array();
633
- }
634
-
635
- foreach ($targetData as $groupId => $groupData) {
636
- foreach ($groupData as $ruleId => $ruleData) {
637
-
638
- if (empty($ruleData['value']) && !is_null($paramsData[$ruleData['param']])) {
639
- $targetData[$groupId][$ruleId]['value'] = '';
640
- }
641
- if (isset($ruleData['value']) && is_array($ruleData['value'])) {
642
- $valueAttrs = $attrs[$ruleData['param']]['htmlAttrs'];
643
- $postType = $valueAttrs['data-value-param'];
644
- $isNotPostType = '';
645
- if (isset($valueAttrs['isNotPostType'])) {
646
- $isNotPostType = $valueAttrs['isNotPostType'];
647
- }
648
-
649
- if (empty($valueAttrs['isNotPostType'])) {
650
- $isNotPostType = false;
651
- }
652
-
653
- /*
654
- * $isNotPostType => false must search inside post types post
655
- * $isNotPostType => true must save array data
656
- * */
657
- if (!$isNotPostType) {
658
- $args = array(
659
- 'post__in' => array_values($ruleData['value']),
660
- 'posts_per_page' => 100,
661
- 'post_type' => $postType
662
- );
663
-
664
- $searchResults = ConfigDataHelper::getPostTypeData($args);
665
-
666
- $targetData[$groupId][$ruleId]['value'] = $searchResults;
667
- }
668
- }
669
- }
670
- }
671
-
672
- $popupTarget['sgpb-target'] = $targetData;
673
- $popupTarget['sgpb-conditions'] = apply_filters('sgpbSaveConditions', $conditionsData);
674
-
675
- $alreadySavedTargets = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
676
- if ($alreadySavedTargets === $popupTarget) {
677
- return true;
678
- }
679
-
680
- $popupTarget = apply_filters('sgpbPopupTargetMetaData', $popupTarget);
681
-
682
- return update_post_meta($popupId, 'sg_popup_target'.$saveMode, $popupTarget);
683
- }
684
-
685
- private function eventsSave()
686
- {
687
- global $SGPB_DATA_CONFIG_ARRAY;
688
-
689
- $eventsData = $this->getEvents();
690
- $popupId = $this->getId();
691
- $saveMode = $this->getSaveMode();
692
- $popupEvents = array();
693
- $eventsFromPopup = array();
694
-
695
- foreach ($eventsData as $groupId => $groupData) {
696
- $currentRuleData = array();
697
- foreach ($groupData as $ruleId => $ruleData) {
698
-
699
- $hiddenOptions = array();
700
- $currentData = array();
701
- foreach ($ruleData as $name => $value) {
702
- if ($name == 'param' || $name == 'value' || $name == 'operator') {
703
- $currentData[$name] = $value;
704
- }
705
- else {
706
- $hiddenOptions[$name] = $value;
707
- }
708
- }
709
- $currentData['hiddenOption'] = $hiddenOptions;
710
- $currentRuleData[$ruleId] = $currentData;
711
- }
712
- $eventsFromPopup[$groupId] = $currentRuleData;
713
- }
714
-
715
- $popupEvents['formPopup'] = $eventsFromPopup;
716
- $alreadySavedEvents = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
717
- if ($alreadySavedEvents === $eventsFromPopup) {
718
- return true;
719
- }
720
-
721
- $eventsFromPopup = apply_filters('sgpbPopupEventsMetadata', $eventsFromPopup);
722
-
723
- return update_post_meta($popupId, 'sg_popup_events'.$saveMode, $eventsFromPopup);
724
- }
725
-
726
- private function popupOptionsSave()
727
- {
728
- $popupOptions = $this->getOptions();
729
- $popupOptions = apply_filters('sgpbSavePopupOptions', $popupOptions);
730
- //special code added for "Behavior After Special Events" section
731
- //todo: remove in the future if possible
732
- $specialBehaviors = array();
733
- if (!empty($popupOptions['sgpb-behavior-after-special-events'])) {
734
- $specialBehaviors = $popupOptions['sgpb-behavior-after-special-events'];
735
- }
736
- if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
737
- foreach ($specialBehaviors as $groupId => $groupRow) {
738
- foreach ($groupRow as $ruleId => $ruleRow) {
739
- if (!empty($ruleRow['operator']) && $ruleRow['operator'] == 'open-popup') {
740
- $args = array(
741
- 'post__in' => array($ruleRow['value']),
742
- 'posts_per_page' => 10,
743
- 'post_type' => SG_POPUP_POST_TYPE
744
- );
745
-
746
- $searchResults = ConfigDataHelper::getPostTypeData($args);
747
- $popupOptions['sgpb-behavior-after-special-events'][$groupId][$ruleId]['value'] = $searchResults;
748
- }
749
- }
750
- }
751
- }
752
-
753
- $popupId = $this->getId();
754
- $saveMode = $this->getSaveMode();
755
-
756
- $alreadySavedOptions = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
757
- if ($alreadySavedOptions === $popupOptions) {
758
- return true;
759
- }
760
-
761
- $popupOptions = apply_filters('sgpbPopupSavedOptionsMetaData', $popupOptions);
762
-
763
- return update_post_meta($popupId, 'sg_popup_options'.$saveMode, $popupOptions);
764
- }
765
-
766
- public function getOptionValue($optionName, $forceDefaultValue = false)
767
- {
768
- require_once(dirname(__FILE__).'/PopupData.php');
769
- $savedData = PopupData::getPopupDataById($this->getId());
770
- $this->setPostData($savedData);
771
-
772
- return $this->getOptionValueFromSavedData($optionName, $forceDefaultValue);
773
- }
774
-
775
- public function getOptionValueFromSavedData($optionName, $forceDefaultValue = false)
776
- {
777
- $defaultData = $this->getDefaultDataByName($optionName);
778
- $savedData = $this->getPostData();
779
-
780
- $optionValue = null;
781
-
782
- if (empty($defaultData['type'])) {
783
- $defaultData['type'] = 'string';
784
- }
785
-
786
- if (!empty($savedData)) { //edit mode
787
- if (isset($savedData[$optionName])) { //option exists in the database
788
- $optionValue = $savedData[$optionName];
789
- }
790
- /* if it's a checkbox, it may not exist in the db
791
- * if we don't care about it's existance, return empty string
792
- * otherwise, go for it's default value
793
- */
794
- else if ($defaultData['type'] == 'checkbox' && !$forceDefaultValue) {
795
- $optionValue = '';
796
- }
797
- }
798
-
799
- if ($optionValue === null && !empty($defaultData['defaultValue'])) {
800
- $optionValue = $defaultData['defaultValue'];
801
- }
802
-
803
- if ($defaultData['type'] == 'checkbox') {
804
- $optionValue = $this->boolToChecked($optionValue);
805
- }
806
-
807
- if ($defaultData['type'] == 'number' && $optionValue == 0) {
808
- $optionValue = 0;
809
- }
810
-
811
- return $optionValue;
812
- }
813
-
814
- public static function getSavedData($popupId, $saveMode = '')
815
- {
816
- $popupSavedData = array();
817
- $events = self::getEventsDataById($popupId, $saveMode);
818
- $targetData = self::getTargetDataById($popupId, $saveMode);
819
-
820
- if (!empty($events)) {
821
- $popupSavedData['sgpb-events'] = self::getEventsDataById($popupId, $saveMode);
822
- }
823
- if (!empty($targetData)) {
824
- if (!empty($targetData['sgpb-target'])) {
825
- $popupSavedData['sgpb-target'] = $targetData['sgpb-target'];
826
- }
827
- if (!empty($targetData['sgpb-conditions'])) {
828
- // for the after x pages option backward compatibility
829
- $targetData['sgpb-conditions'] = apply_filters('sgpbAdvancedTargetingSavedData', $targetData['sgpb-conditions'], $popupId);
830
- $popupSavedData['sgpb-conditions'] = $targetData['sgpb-conditions'];
831
- }
832
- }
833
-
834
- $popupOptions = self::getPopupOptionsById($popupId, $saveMode);
835
- if (is_array($popupOptions) && is_array($popupSavedData)) {
836
- $popupSavedData = array_merge($popupSavedData, $popupOptions);
837
- }
838
-
839
- return $popupSavedData;
840
- }
841
-
842
- public static function getEventsDataById($popupId, $saveMode = '')
843
- {
844
- $eventsData = array();
845
- if (get_post_meta($popupId, 'sg_popup_events'.$saveMode, true)) {
846
- $eventsData = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
847
- }
848
-
849
- return $eventsData;
850
- }
851
-
852
- public static function getTargetDataById($popupId, $saveMode = '')
853
- {
854
- $targetData = array();
855
-
856
- if (get_post_meta($popupId, 'sg_popup_target'.$saveMode, true)) {
857
- $targetData = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
858
- }
859
-
860
- return $targetData;
861
- }
862
-
863
- public static function getPopupOptionsById($popupId, $saveMode = '')
864
- {
865
- $currentPost = get_post($popupId);
866
-
867
- if (!empty($currentPost) && $currentPost->post_status == 'draft') {
868
- $saveMode = '_preview';
869
- }
870
- $optionsData = array();
871
- if (get_post_meta($popupId, 'sg_popup_options'.$saveMode, true)) {
872
- $optionsData = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
873
- }
874
-
875
- return $optionsData;
876
- }
877
-
878
- public function getDefaultDataByName($optionName)
879
- {
880
- global $SGPB_OPTIONS;
881
- if (empty($SGPB_OPTIONS)) {
882
- return array();
883
- }
884
-
885
- foreach ($SGPB_OPTIONS as $option) {
886
- if ($option['name'] == $optionName) {
887
- return $option;
888
- }
889
- }
890
-
891
- return array();
892
- }
893
-
894
- /**
895
- * Get option default option value
896
- *
897
- * @param string $optionName
898
- *
899
- * @since 1.0.0
900
- *
901
- * @return string
902
- *
903
- */
904
- public function getOptionDefaultValue($optionName)
905
- {
906
- // return config data array by name
907
- $optionData = $this->getDefaultDataByName($optionName);
908
-
909
- if (empty($optionData)) {
910
- return '';
911
- }
912
-
913
- return $optionData['defaultValue'];
914
- }
915
-
916
- /**
917
- * Changing default options form changing options by name
918
- *
919
- * @since 1.0.0
920
- *
921
- * @param array $defaultOptions
922
- * @param array $changingOptions
923
- *
924
- * @return array $defaultOptions
925
- */
926
- public function changeDefaultOptionsByNames($defaultOptions, $changingOptions)
927
- {
928
- if (empty($defaultOptions) || empty($changingOptions)) {
929
- return $defaultOptions;
930
- }
931
- $changingOptionsNames = array_keys($changingOptions);
932
-
933
- foreach ($defaultOptions as $key => $defaultOption) {
934
- $defaultOptionName = $defaultOption['name'];
935
- if (in_array($defaultOptionName, $changingOptionsNames)) {
936
- $defaultOptions[$key] = $changingOptions[$defaultOptionName];
937
- }
938
- }
939
-
940
- return $defaultOptions;
941
- }
942
-
943
- /**
944
- * Returns separate popup types Free or Pro
945
- *
946
- * @since 2.5.6
947
- *
948
- * @return array $popupTypesObj
949
- */
950
- public static function getPopupTypes()
951
- {
952
- global $SGPB_POPUP_TYPES;
953
- $popupTypesObj = array();
954
- $popupTypes = $SGPB_POPUP_TYPES['typeName'];
955
-
956
- foreach ($popupTypes as $popupType => $level) {
957
-
958
- if (empty($level)) {
959
- $level = SGPB_POPUP_PKG_FREE;
960
- }
961
-
962
- $popupTypeObj = new PopupType();
963
- $popupTypeObj->setName($popupType);
964
- $popupTypeObj->setAccessLevel($level);
965
-
966
- if (SGPB_POPUP_PKG >= $level) {
967
- $popupTypeObj->setAvailable(true);
968
- }
969
- $popupTypesObj[] = $popupTypeObj;
970
- }
971
-
972
- return $popupTypesObj;
973
- }
974
-
975
- public static function savePopupsFromContentClasses($content, $post)
976
- {
977
- $postId = $post->ID;
978
- $clickClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-id-');
979
- $targetData = array();
980
- $eventsData = array();
981
-
982
- if (!empty($clickClassIds)) {
983
- foreach ($clickClassIds as $id) {
984
- $id = apply_filters('sgpbConvertedPopupId', $id);
985
- if (empty($eventsData[$postId][$id])) {
986
- $eventsData[$postId][$id] = array('click');
987
- }
988
- else {
989
- $eventsData[$postId][$id][] = 'click';
990
- }
991
-
992
- if (empty($targetData[$postId])) {
993
- $targetData[$postId] = array($id);
994
- }
995
- else {
996
- $targetData[$postId][] = $id;
997
- }
998
- }
999
- }
1000
-
1001
- $iframeClassIs = self::getStringNextNumbersByReg($content, 'sg-iframe-popup-');
1002
-
1003
- if (!empty($iframeClassIs)) {
1004
- foreach ($iframeClassIs as $id) {
1005
- $id = apply_filters('sgpbConvertedPopupId', $id);
1006
- $popupObj = self::find($id);
1007
-
1008
- if (empty($popupObj)) {
1009
- continue;
1010
- }
1011
-
1012
- // this event should work only for iframe popup type
1013
- if ($popupObj->getType() != 'iframe') {
1014
- continue;
1015
- }
1016
-
1017
- if (empty($eventsData[$postId][$id])) {
1018
- $eventsData[$postId][$id] = array('iframe');
1019
- }
1020
- else {
1021
- $eventsData[$postId][$id][] = 'iframe';
1022
- }
1023
-
1024
- if (empty($targetData[$postId])) {
1025
- $targetData[$postId] = array($id);
1026
- }
1027
- else {
1028
- $targetData[$postId][] = $id;
1029
- }
1030
- }
1031
- }
1032
-
1033
- $confirmClassIds = self::getStringNextNumbersByReg($content, 'sg-confirm-popup-');
1034
-
1035
- if (!empty($confirmClassIds)) {
1036
- foreach ($confirmClassIds as $id) {
1037
- $id = apply_filters('sgpbConvertedPopupId', $id);
1038
- if (empty($eventsData[$postId][$id])) {
1039
- $eventsData[$postId][$id] = array('confirm');
1040
- }
1041
- else {
1042
- $eventsData[$postId][$id][] = 'confirm';
1043
- }
1044
-
1045
- if (empty($targetData[$postId])) {
1046
- $targetData[$postId] = array($id);
1047
- }
1048
- else {
1049
- $targetData[$postId][] = $id;
1050
- }
1051
- }
1052
- }
1053
-
1054
- $hoverClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-hover-');
1055
-
1056
- if (!empty($hoverClassIds)) {
1057
- foreach ($hoverClassIds as $id) {
1058
- $id = apply_filters('sgpbConvertedPopupId', $id);
1059
- if (empty($eventsData[$postId][$id])) {
1060
- $eventsData[$postId][$id] = array('hover');
1061
- }
1062
- else {
1063
- $eventsData[$postId][$id][] = 'hover';
1064
- }
1065
-
1066
- if (empty($targetData[$postId])) {
1067
- $targetData[$postId] = array($id);
1068
- }
1069
- else {
1070
- $targetData[$postId][] = $id;
1071
- }
1072
- }
1073
- }
1074
-
1075
- $targetData = apply_filters('sgpbPopupTargetData', $targetData);
1076
- $eventsData = apply_filters('sgpbPopupEventsData', $eventsData);
1077
-
1078
- self::saveToTargetFromPage($targetData);
1079
- self::saveToEventsFromPage($eventsData);
1080
- }
1081
-
1082
- public static function getStringNextNumbersByReg($content, $key)
1083
- {
1084
- $result = array();
1085
- preg_match_all("/(?<=$key)(\d+)/", $content, $ids);
1086
-
1087
- if (!empty($ids[0])) {
1088
- $result = $ids[0];
1089
- }
1090
-
1091
- return $result;
1092
- }
1093
-
1094
- private static function saveToTargetAndEvents($popupsShortcodsInPostPage, $postId)
1095
- {
1096
- if (empty($popupsShortcodsInPostPage)) {
1097
- return false;
1098
- }
1099
- $customEvents = array();
1100
- $customPopups = array();
1101
-
1102
- foreach ($popupsShortcodsInPostPage as $shortcodesData) {
1103
- $popupId = apply_filters('sgpbConvertedPopupId', $shortcodesData['id']);
1104
-
1105
- $args = array(
1106
- 'post_type' => SG_POPUP_POST_TYPE,
1107
- 'post__in' => array($popupId)
1108
- );
1109
- $postById = ConfigDataHelper::getPostTypeData($args);
1110
- //When target data does not exist
1111
- if (empty($postById)) {
1112
- continue;
1113
- }
1114
-
1115
- // collect custom inserted popups
1116
- if (empty($customPopups[$postId])) {
1117
- $customPopups[$postId] = array($popupId);
1118
- }
1119
- else {
1120
- $customPopups[$postId][] = $popupId;
1121
- }
1122
-
1123
- // collect custom inserted popups events
1124
- if (empty($shortcodesData['event'])) {
1125
- $eventName = 'onload';
1126
- }
1127
- else {
1128
- $eventName = $shortcodesData['event'];
1129
- }
1130
-
1131
- if ($eventName == 'onload') {
1132
- $eventName = 'attr'.$eventName;
1133
- }
1134
- $currentEventData = array(
1135
- 'param' => $eventName
1136
- );
1137
-
1138
- if (empty($customEvents[$postId][$popupId])) {
1139
- $customEvents[$postId][$popupId] = array($currentEventData);
1140
- }
1141
- else {
1142
- $customEvents[$postId][$popupId][] = $currentEventData;
1143
- }
1144
- }
1145
-
1146
- self::saveToTargetFromPage($customPopups);
1147
- self::saveToEventsFromPage($customEvents);
1148
-
1149
- return true;
1150
- }
1151
-
1152
- public static function getPostPopupCustomEvent($postId, $popupId)
1153
- {
1154
- $events = array();
1155
-
1156
- $customEventsData = self::getCustomInsertedPopupEventsByPostId($postId);
1157
-
1158
- if (!empty($customEventsData[$popupId])) {
1159
- $events = $customEventsData[$popupId];
1160
- }
1161
-
1162
- return $events;
1163
- }
1164
-
1165
- /**
1166
- * Save popup to custom events from pages
1167
- *
1168
- * @since 1.0.0
1169
- *
1170
- * @param array $customEvents
1171
- *
1172
- * @return bool
1173
- *
1174
- */
1175
- public static function saveToEventsFromPage($customEvents)
1176
- {
1177
- if (empty($customEvents)) {
1178
- return false;
1179
- }
1180
-
1181
- foreach ($customEvents as $postId => $popupsData) {
1182
- $savedCustomEvents = self::getCustomInsertedPopupEventsByPostId($postId);
1183
- $result = AdminHelper::arrayMergeSameKeys($popupsData, $savedCustomEvents);
1184
-
1185
- if (!$result) {
1186
- return $result;
1187
- }
1188
- update_post_meta($postId, 'sgpb_popup_events_custom', $result);
1189
- }
1190
-
1191
- return true;
1192
- }
1193
-
1194
- public static function getCustomInsertedPopupEventsByPostId($postId)
1195
- {
1196
- $eventsData = array();
1197
- $postMetaData = get_post_meta($postId, 'sgpb_popup_events_custom', true);
1198
-
1199
- if (!empty($postMetaData)) {
1200
- $eventsData = $postMetaData;
1201
- }
1202
-
1203
- return $eventsData;
1204
- }
1205
-
1206
- /**
1207
- * Save popup to custom targets from pages
1208
- *
1209
- * @since 1.0.0
1210
- *
1211
- * @param array $customPopups
1212
- *
1213
- * @return void
1214
- *
1215
- */
1216
- public static function saveToTargetFromPage($customPopups)
1217
- {
1218
- if (!empty($customPopups)) {
1219
- foreach ($customPopups as $postId => $popups) {
1220
- $alreadySavedPopups = self::getCustomInsertedDataByPostId($postId);
1221
- $popups = array_merge($popups, $alreadySavedPopups);
1222
- update_post_meta($postId, 'sg_popup_target_custom', $popups);
1223
- }
1224
- }
1225
- }
1226
-
1227
- /**
1228
- * Get popup custom targes form saved data
1229
- *
1230
- * @since 1.0.0
1231
- *
1232
- * @param int $postId
1233
- *
1234
- * @return array $postData
1235
- */
1236
- public static function getCustomInsertedDataByPostId($postId)
1237
- {
1238
- $postData = array();
1239
- $postMetaData = get_post_meta($postId, 'sg_popup_target_custom');
1240
-
1241
- if (!empty($postMetaData[0])) {
1242
- $postData = $postMetaData[0];
1243
- }
1244
-
1245
- return $postData;
1246
- }
1247
-
1248
- public static function getPopupShortcodeMatchesFromContent($content)
1249
- {
1250
- $result = false;
1251
- $pattern = get_shortcode_regex();
1252
-
1253
- if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1254
- && !empty($matches)
1255
- && is_array($matches)
1256
- && array_key_exists( 2, $matches )
1257
- && in_array('sg_popup', $matches[2])
1258
- )
1259
- {
1260
- $result = $matches;
1261
- }
1262
-
1263
- return $result;
1264
- }
1265
-
1266
- public static function renderPopupContentShortcode($content, $popupId, $event, $args)
1267
- {
1268
- ob_start();
1269
- $wrap = 'a';
1270
- if (!empty($args['wrap'])) {
1271
- if ($args['wrap'] == $wrap) {
1272
- $args['href'] = 'javascript:void(0)';
1273
- }
1274
- $wrap = $args['wrap'];
1275
- }
1276
- unset($args['wrap']);
1277
- unset($args['event']);
1278
- unset($args['id']);
1279
- $attr = AdminHelper::createAttrs($args);
1280
- ?>
1281
- <<?php echo $wrap; ?>
1282
- <?php if ($wrap == 'a') : ?>
1283
- href="javascript:void(0)"
1284
- <?php endif ?>
1285
- class="sgpb-show-popup <?php echo 'sgpb-popup-id-'.$popupId; ?>"
1286
- data-sgpbpopupid="<?php echo esc_attr($popupId); ?>"
1287
- data-popup-event="<?php echo $event; ?>"
1288
- <?php echo $attr; ?>>
1289
- <?php echo $content; ?>
1290
- </<?php echo $wrap; ?>>
1291
- <?php
1292
-
1293
- $shortcodeContent = ob_get_contents();
1294
- ob_get_clean();
1295
-
1296
- return $shortcodeContent;
1297
- }
1298
-
1299
- private static function collectInsidePopupShortcodes($content)
1300
- {
1301
- $pattern = get_shortcode_regex();
1302
- $options = array();
1303
- if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1304
- && !empty($matches)
1305
- && is_array($matches)
1306
- && array_key_exists( 2, $matches )
1307
- && in_array('sg_popup', $matches[2])
1308
- )
1309
- {
1310
- foreach ($matches[0] as $key => $value) {
1311
- //return current shortcode all attrs as assoc array
1312
- $attrs = shortcode_parse_atts($matches[3][$key]);
1313
- $currentAttrs = array();
1314
- if (!empty($attrs['id'])) {
1315
- $currentAttrs['id'] = $attrs['id'];
1316
- }
1317
- if (!empty($attrs['insidepopup'])) {
1318
- $currentAttrs['insidepopup'] = $attrs['insidepopup'];
1319
- }
1320
- if (empty($attrs['insidepopup']) || (!empty($attrs['insidepopup']) && $attrs['insidepopup'] != 'on')) {
1321
- continue;
1322
- }
1323
-
1324
- $options[$currentAttrs['id']] = $value;
1325
- }
1326
- }
1327
-
1328
- return apply_filters('sgpbPopupInsideShortcodes', $options);
1329
- }
1330
-
1331
- /**
1332
- * Collect all popups by taxonomy slug
1333
- *
1334
- * @since 1.0.0
1335
- *
1336
- * @param string $popupTermSlug category slug name
1337
- *
1338
- * @return array $popupIds random popups id
1339
- *
1340
- */
1341
- public static function getPopupsByTermSlug($popupTermSlug)
1342
- {
1343
- $popupIds = array();
1344
-
1345
- $termPopups = get_transient(SGPB_TRANSIENT_POPUPS_TERMS);
1346
- if ($termPopups === false) {
1347
- $termPopups = get_posts(
1348
- array(
1349
- 'post_type' => 'popupbuilder',
1350
- 'numberposts' => -1,
1351
- 'tax_query' => array(
1352
- array(
1353
- 'taxonomy' => SG_POPUP_CATEGORY_TAXONOMY,
1354
- 'field' => 'slug',
1355
- 'terms' => $popupTermSlug
1356
- )
1357
- )
1358
- )
1359
- );
1360
- set_transient(SGPB_TRANSIENT_POPUPS_TERMS, $termPopups, SGPB_TRANSIENT_TIMEOUT_WEEK);
1361
- }
1362
-
1363
- if (empty($termPopups)) {
1364
- return $popupIds;
1365
- }
1366
-
1367
- foreach ($termPopups as $termPopup) {
1368
- $popupIds[] = $termPopup->ID;
1369
- }
1370
-
1371
- return $popupIds;
1372
- }
1373
-
1374
- public function boolToChecked($var)
1375
- {
1376
- return ($var?'checked':'');
1377
- }
1378
-
1379
- /**
1380
- * Delete custom inserted data
1381
- *
1382
- * @since 1.0.0
1383
- *
1384
- * @param int $postId current post page id
1385
- *
1386
- * @return void
1387
- *
1388
- */
1389
- public static function deletePostCustomInsertedData($postId)
1390
- {
1391
- delete_post_meta($postId, 'sg_popup_target_custom');
1392
- }
1393
-
1394
- /**
1395
- * Delete custom inserted events
1396
- *
1397
- * @since 1.0.0
1398
- *
1399
- * @param int $postId current post page id
1400
- *
1401
- * @return void
1402
- *
1403
- */
1404
- public static function deletePostCustomInsertedEvents($postId)
1405
- {
1406
- delete_post_meta($postId, 'sgpb_popup_events_custom');
1407
- }
1408
-
1409
- /**
1410
- * If popup Type does not have getPopupTypeOptions method
1411
- * it's tell popup does not have custom options
1412
- *
1413
- * @since 1.0.0
1414
- *
1415
- * @return bool
1416
- *
1417
- */
1418
- public function getPopupTypeOptionsView()
1419
- {
1420
- return false;
1421
- }
1422
-
1423
- /**
1424
- * If popup Type does not have getPopupTypeOptions method
1425
- * it's tell popup does not have custom options
1426
- *
1427
- * @since 1.0.0
1428
- *
1429
- * @return bool
1430
- *
1431
- */
1432
- public function getPopupTypeMainView()
1433
- {
1434
- return false;
1435
- }
1436
-
1437
- /**
1438
- * Remove popup option from admin view by option name
1439
- *
1440
- * @since 1.0.0
1441
- *
1442
- * @return array $removedOptions
1443
- *
1444
- */
1445
- public function getRemoveOptions()
1446
- {
1447
- $removeOptions = array();
1448
-
1449
- return apply_filters('sgpbRemoveOptions', $removeOptions);
1450
- }
1451
-
1452
- public static function createPopupTypeObjById($popupId)
1453
- {
1454
- global $SGPB_POPUP_TYPES;
1455
- $typePath = '';
1456
- $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
1457
- if (empty($popupOptionsData)) {
1458
- return false;
1459
- }
1460
- $popupType = $popupOptionsData['sgpb-type'];
1461
- $popupName = ucfirst(strtolower($popupType));
1462
- $popupClassName = $popupName.'Popup';
1463
-
1464
- if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
1465
- $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
1466
- }
1467
-
1468
- if (!file_exists($typePath.$popupClassName.'.php')) {
1469
- wp_die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
1470
- }
1471
- require_once($typePath.$popupClassName.'.php');
1472
-
1473
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
1474
- $popupTypeObj = new $popupClassName();
1475
- $popupTypeObj->setId($popupId);
1476
-
1477
- return $popupTypeObj;
1478
- }
1479
-
1480
- /**
1481
- * if child class does not have this function we call parent function to not get any errors
1482
- *
1483
- * @since 1.0.0
1484
- *
1485
- * @return array
1486
- *
1487
- */
1488
- public static function getTablesSql()
1489
- {
1490
- return array();
1491
- }
1492
-
1493
- /**
1494
- * if child class does not have this function we call parent function to not get any errors
1495
- *
1496
- * @since 1.0.0
1497
- *
1498
- * @return array
1499
- *
1500
- */
1501
- public static function getTableNames()
1502
- {
1503
- return array();
1504
- }
1505
-
1506
- /**
1507
- *
1508
- * Get WordPress localization name
1509
- *
1510
- * @since 1.0.0
1511
- *
1512
- * @return string
1513
- *
1514
- */
1515
- public function getSiteLocale()
1516
- {
1517
- $locale = get_bloginfo('language');
1518
- $locale = str_replace('-', '_', $locale);
1519
-
1520
- return $locale;
1521
- }
1522
-
1523
- public function addAdditionalSettings($postData = array(), $obj = null)
1524
- {
1525
- return array();
1526
- }
1527
-
1528
- public function allowToLoad()
1529
- {
1530
- global $post;
1531
-
1532
- $popupChecker = PopupChecker::instance();
1533
- $loadableModes = $popupChecker->isLoadable($this, $post);
1534
- $this->setLoadableModes($loadableModes);
1535
-
1536
- return ($loadableModes['attr_event'] || $loadableModes['option_event']);
1537
- }
1538
-
1539
- public function allowToLoadAJAX()
1540
- {
1541
- global $post;
1542
-
1543
- $popupChecker = PopupChecker::instance();
1544
- $loadableModes = $popupChecker->isLoadable($this, $post, true);
1545
- $this->setLoadableModes($loadableModes);
1546
-
1547
- return ($loadableModes['attr_event'] || $loadableModes['option_event']);
1548
- }
1549
-
1550
- public static function getAllPopups($filters = array())
1551
- {
1552
- $args = array(
1553
- 'post_type' => SG_POPUP_POST_TYPE
1554
- );
1555
- $allPopups = array();
1556
- $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1557
-
1558
- if (empty($allPostData)) {
1559
- return $allPopups;
1560
- }
1561
-
1562
- foreach ($allPostData->posts as $postData) {
1563
- if (empty($postData)) {
1564
- continue;
1565
- }
1566
-
1567
- $popup = self::find($postData->ID, $args);
1568
- if (empty($popup) || !($popup instanceof SGPopup)) {
1569
- continue;
1570
- }
1571
- $type = @$popup->getType();
1572
-
1573
- if (isset($filters['type'])) {
1574
- if (is_array($filters['type'])) {
1575
- if (!in_array($type, $filters['type'])) {
1576
- continue;
1577
- }
1578
- }
1579
- else if ($type != $filters['type']) {
1580
- continue;
1581
- }
1582
- }
1583
- $allPopups[] = $popup;
1584
- }
1585
-
1586
- return $allPopups;
1587
- }
1588
-
1589
- public function getPopupsIdAndTitle()
1590
- {
1591
- $allPopups = SGPopup::getAllPopups();
1592
- $popupIdTitles = array();
1593
-
1594
- if (empty($allPopups)) {
1595
- return $popupIdTitles;
1596
- }
1597
- $currentPopupId = $this->getId();
1598
-
1599
- foreach ($allPopups as $popup) {
1600
- if (empty($popup)) {
1601
- continue;
1602
- }
1603
- $id = $popup->getId();
1604
-
1605
- if ($id == $currentPopupId) {
1606
- continue;
1607
- }
1608
-
1609
- $title = $popup->getTitle();
1610
- $type = $popup->getType();
1611
-
1612
- $popupIdTitles[$id] = $title.' - '.$type;
1613
- }
1614
-
1615
- return $popupIdTitles;
1616
- }
1617
-
1618
- public function getSubPopupObj()
1619
- {
1620
- $subPopups = array();
1621
- $options = $this->getOptions();
1622
-
1623
- $specialBehaviors = @$options['sgpb-behavior-after-special-events'];
1624
- if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
1625
- foreach ($specialBehaviors as $behavior) {
1626
- foreach ($behavior as $row) {
1627
- if (!empty($row['param']) && $row['param'] == SGPB_CONTACT_FORM_7_BEHAVIOR_KEY) {
1628
- if (!empty($row['operator']) && $row['operator'] == 'open-popup') {
1629
- if (!empty($row['value'])) {
1630
- $popupId = key($row['value']);
1631
- $subPopupObj = self::find((int)$popupId);
1632
- if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
1633
- $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
1634
- $subPopups[] = $subPopupObj;
1635
- }
1636
- }
1637
- }
1638
- }
1639
- }
1640
- }
1641
- }
1642
-
1643
- return $subPopups;
1644
- }
1645
-
1646
- public static function doInsideShortcode($insideShortcode)
1647
- {
1648
- return do_shortcode($insideShortcode);
1649
- }
1650
-
1651
- public function popupShortcodesInsidePopup()
1652
- {
1653
- $popups = array();
1654
- $args = array('insidePopup' => 'on');
1655
- $popupContent = $this->getContent();
1656
- $parentTarget = $this->getTarget();
1657
- $insidePopupShortcodes = self::collectInsidePopupShortcodes($popupContent);
1658
- if (empty($insidePopupShortcodes)) {
1659
- return $popups;
1660
- }
1661
- foreach ($insidePopupShortcodes as $insidePopupId => $insidePopupShortcode) {
1662
- $insidePopupId = (int)$insidePopupId;
1663
- if (!$insidePopupId) {
1664
- continue;
1665
- }
1666
- // true = find inside popup
1667
- $insidePopup = self::find($insidePopupId, $args);
1668
- if (empty($insidePopup) || $insidePopup == 'trash' || $insidePopup == 'inherit') {
1669
- continue;
1670
- }
1671
- $events = array('insideclick');
1672
- $insidePopup->setEvents($events);
1673
- $popups[$insidePopupId] = $insidePopup;
1674
- }
1675
-
1676
- $popupContent = self::doInsideShortcode($popupContent);
1677
- $this->setContent($popupContent);
1678
-
1679
- return $popups;
1680
- }
1681
-
1682
- public function getPopupOpeningCountById($popupId)
1683
- {
1684
- global $wpdb;
1685
-
1686
- $allCount = 0;
1687
- $popupsCounterData = get_option('SgpbCounter');
1688
- $popupCountFromAnalyticsData = 0;
1689
- $tableName = $wpdb->prefix.'sgpb_analytics';
1690
- if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
1691
- $popupCountFromAnalyticsData = self::getAnalyticsDataByPopupId($popupId);
1692
- }
1693
- if (isset($popupsCounterData[$popupId])) {
1694
- $allCount += $popupsCounterData[$popupId];
1695
- }
1696
- $allCount += $popupCountFromAnalyticsData;
1697
-
1698
- return $allCount;
1699
- }
1700
-
1701
- public static function getAnalyticsDataByPopupId($popupId)
1702
- {
1703
- global $wpdb;
1704
- // 7, 12, 13 => exclude close, subscription success, contact success events
1705
- $stmt = $wpdb->prepare('SELECT COUNT(*) FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
1706
- $popupAnalyticsData = $wpdb->get_var($stmt);
1707
- return $popupAnalyticsData;
1708
- }
1709
-
1710
- public static function deleteAnalyticsDataByPopupId($popupId)
1711
- {
1712
- global $wpdb;
1713
- $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13) LIMIT 100', $popupId);
1714
- $wpdb->query($prepareSql);
1715
- }
1716
-
1717
- public static function getActivePopupsQueryString()
1718
- {
1719
- $activePopupsQuery = '';
1720
- $args = array(
1721
- 'post_type' => SG_POPUP_POST_TYPE,
1722
- 'post_status' => array('trash', 'publish')
1723
- );
1724
- if (!class_exists('ConfigDataHelper')) {
1725
- return $activePopupsQuery;
1726
- }
1727
- $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1728
- $args['checkActivePopupType'] = true;
1729
- $allPopups = $allPostData->posts;
1730
- foreach ($allPopups as $post) {
1731
- $id = $post->ID;
1732
- $popup = self::find($id, $args);
1733
- if (empty($popup)) {
1734
- $activePopupsQuery .= $id.', ';
1735
- }
1736
- }
1737
- if ($activePopupsQuery != '') {
1738
- $activePopupsQuery = ' AND ID NOT IN ('.$activePopupsQuery.')';
1739
- $activePopupsQuery = str_replace(', )', ') ', $activePopupsQuery);
1740
- }
1741
-
1742
- return $activePopupsQuery;
1743
- }
1744
-
1745
- public function isActive()
1746
- {
1747
- return $this->getOptionValue('sgpb-is-active', true);
1748
- }
1749
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \ConfigDataHelper;
4
+ use \WP_Post;
5
+
6
+ if (class_exists("sgpb\SGPopup")) {
7
+ return;
8
+ }
9
+
10
+ abstract class SGPopup
11
+ {
12
+ protected $type;
13
+
14
+ private $sanitizedData;
15
+ private $postData = array();
16
+ private $id;
17
+ private $title;
18
+ private $content;
19
+ private $target;
20
+ private $conditions;
21
+ private $events = array();
22
+ private $options;
23
+ private $loadableModes;
24
+ private $saveMode = '';
25
+ private $savedPopup = false;
26
+
27
+
28
+ public function setId($id)
29
+ {
30
+ $this->id = $id;
31
+ }
32
+
33
+ public function getId()
34
+ {
35
+ return (int)$this->id;
36
+ }
37
+
38
+ public function setTitle($title)
39
+ {
40
+ $this->title = $title;
41
+ }
42
+
43
+ public function getTitle()
44
+ {
45
+ return $this->title;
46
+ }
47
+
48
+ public function setType($type)
49
+ {
50
+ $this->type = $type;
51
+ }
52
+
53
+ public function getType()
54
+ {
55
+ return $this->type;
56
+ }
57
+
58
+ public function setTarget($target)
59
+ {
60
+ $this->target = $target;
61
+ }
62
+
63
+ public function getTarget()
64
+ {
65
+ return $this->target;
66
+ }
67
+
68
+ public function setEvents($events)
69
+ {
70
+ $this->events = $events;
71
+ }
72
+
73
+ public function getEvents()
74
+ {
75
+ return $this->events;
76
+ }
77
+
78
+ public function setConditions($conditions)
79
+ {
80
+ $this->conditions = $conditions;
81
+ }
82
+
83
+ public function getConditions()
84
+ {
85
+ return $this->conditions;
86
+ }
87
+
88
+ public function setOptions($options)
89
+ {
90
+ $this->options = $options;
91
+ }
92
+
93
+ public function getOptions()
94
+ {
95
+ return $this->options;
96
+ }
97
+
98
+ public function setLoadableModes($loadableModes)
99
+ {
100
+ $this->loadableModes = $loadableModes;
101
+ }
102
+
103
+ public function getLoadableModes()
104
+ {
105
+ return $this->loadableModes;
106
+ }
107
+
108
+ public function setSaveMode($saveMode)
109
+ {
110
+ $this->saveMode = $saveMode;
111
+ }
112
+
113
+ public function getSaveMode()
114
+ {
115
+ return $this->saveMode;
116
+ }
117
+
118
+ public function setSavedPopup($savedPopup)
119
+ {
120
+ $this->savedPopup = $savedPopup;
121
+ }
122
+
123
+ public function getSavedPopup()
124
+ {
125
+ return $this->savedPopup;
126
+ }
127
+
128
+ public function setContent($content)
129
+ {
130
+ $this->content = $content;
131
+ }
132
+
133
+ public function setSavedPopupById($popupId)
134
+ {
135
+ $popup = SGPopup::find($popupId);
136
+ if (is_object($popup)) {
137
+ $this->setSavedPopup($popup);
138
+ }
139
+ }
140
+
141
+ public function setReportData($popupId)
142
+ {
143
+ $events = $this->getEvents();
144
+ $options = $this->getOptions();
145
+ $targets = $this->getTarget();
146
+ $conditions = $this->getConditions();
147
+ do_action('sgpbDebugReportUpdate', 'options', $options, $popupId);
148
+ do_action('sgpbDebugReportUpdate', 'events', $events, $popupId);
149
+ do_action('sgpbDebugReportUpdate', 'targets', $targets, $popupId);
150
+ do_action('sgpbDebugReportUpdate', 'conditions', $conditions, $popupId);
151
+ }
152
+
153
+ public function getPopupAllEvents($postId, $popupId, $popupObj = false)
154
+ {
155
+ $events = array();
156
+
157
+ $loadableModes = $this->getLoadableModes();
158
+
159
+ if (isset($loadableModes['attr_event'])) {
160
+ $customEvents = SGPopup::getPostPopupCustomEvent($postId, $popupId);
161
+ $events = array_merge($events, $customEvents);
162
+ }
163
+
164
+ if (isset($loadableModes['option_event']) || is_null($loadableModes)) {
165
+ $optionEvents = $this->getEvents();
166
+ if (!is_array($optionEvents)) {
167
+ $optionEvents = array();
168
+ }
169
+ $events = array_merge($events, $optionEvents);
170
+ }
171
+
172
+ if (!empty($popupObj->getOptionValue('sgpb-enable-floating-button'))) {
173
+ $events[] = array('param' => 'setByCssClass', 'hiddenOption' => array());
174
+ }
175
+
176
+ return apply_filters('sgpbPopupEvents', $events, $popupObj);
177
+ }
178
+
179
+ public function getContent()
180
+ {
181
+ $postId = $this->getId();
182
+
183
+ if (!AdminHelper::hasBlocks($this->content)) {
184
+ $popupContent = wpautop($this->content);
185
+ } else {
186
+ $popupContent = $this->content;
187
+ }
188
+
189
+ $editorContent = AdminHelper::checkEditorByPopupId($postId);
190
+ if (!empty($editorContent)) {
191
+ if (class_exists('Vc_Manager')) {
192
+ $popupContent .= $editorContent;
193
+ }
194
+ else {
195
+ $popupContent = $editorContent;
196
+ }
197
+ }
198
+
199
+ return $popupContent;
200
+ }
201
+
202
+ public function setPostData($postData)
203
+ {
204
+ $this->postData = apply_filters('sgpbSavedPostData', $postData);
205
+ }
206
+
207
+ public function getPostData()
208
+ {
209
+ return $this->postData;
210
+ }
211
+
212
+ public function getPopupTypeContent()
213
+ {
214
+ return $this->getContent();
215
+ }
216
+
217
+ public function insertIntoSanitizedData($sanitizedData)
218
+ {
219
+ if (!empty($sanitizedData)) {
220
+ $this->sanitizedData[$sanitizedData['name']] = $sanitizedData['value'];
221
+ }
222
+ }
223
+
224
+ abstract public function getExtraRenderOptions();
225
+
226
+ public function setSanitizedData($sanitizedData)
227
+ {
228
+ $this->sanitizedData = $sanitizedData;
229
+ }
230
+
231
+ public function getSanitizedData()
232
+ {
233
+ return $this->sanitizedData;
234
+ }
235
+
236
+ /**
237
+ * Find popup and create this object
238
+ *
239
+ * @since 1.0.0
240
+ *
241
+ * @param object|int $popup
242
+ *
243
+ * @return object|false $obj
244
+ */
245
+ public static function find($popup, $args = array())
246
+ {
247
+ if (isset($_GET['sg_popup_preview_id'])) {
248
+ $args['is-preview'] = true;
249
+ }
250
+ // If the popup is object get data from object otherwise we find needed data from WordPress functions
251
+ if ($popup instanceof WP_Post) {
252
+ $status = $popup->post_status;
253
+ $title = $popup->post_title;
254
+ $popupContent = $popup->post_content;
255
+ $popupId = $popup->ID;
256
+ }
257
+ else {
258
+ $popupId = $popup;
259
+ $popupPost = get_post($popupId);
260
+ if (empty($popupPost)) {
261
+ return false;
262
+ }
263
+ $title = get_the_title($popupId);
264
+ $status = get_post_status($popupId);
265
+ $popupContent = $popupPost->post_content;
266
+ }
267
+ $allowedStatus = array('publish', 'draft');
268
+
269
+ if (!empty($args['status'])) {
270
+ $allowedStatus = $args['status'];
271
+ }
272
+
273
+ if (!isset($args['checkActivePopupType']) && !in_array($status, $allowedStatus)) {
274
+ return $status;
275
+ }
276
+ $saveMode = '';
277
+ global $post;
278
+ if ((@is_preview() && $post->ID == $popupId) || isset($args['preview'])) {
279
+ $saveMode = '_preview';
280
+ }
281
+ if (isset($args['is-preview'])) {
282
+ $saveMode = '_preview';
283
+ }
284
+ if (isset($args['insidePopup']) && $args['insidePopup'] == 'on') {
285
+ $saveMode = '';
286
+ }
287
+ $currentPost = get_post($popupId);
288
+ $currentPostStatus = $currentPost->post_status;
289
+ if ($currentPostStatus == 'draft') {
290
+ $saveMode = '_preview';
291
+ }
292
+
293
+ $savedData = array();
294
+ if (file_exists(dirname(__FILE__).'/PopupData.php')) {
295
+ require_once(dirname(__FILE__).'/PopupData.php');
296
+ $savedData = PopupData::getPopupDataById($popupId, $saveMode);
297
+ }
298
+ $savedData = apply_filters('sgpbPopupSavedData', $savedData);
299
+
300
+ if (empty($savedData)) {
301
+ return false;
302
+ }
303
+
304
+ $type = 'html';
305
+ if (isset($savedData['sgpb-type'])) {
306
+ $type = $savedData['sgpb-type'];
307
+ }
308
+
309
+ $popupClassName = self::getPopupClassNameFormType($type);
310
+ $typePath = self::getPopupTypeClassPath($type);
311
+ if (!file_exists($typePath.$popupClassName.'.php')) {
312
+ return false;
313
+ }
314
+ require_once($typePath.$popupClassName.'.php');
315
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
316
+
317
+ $obj = new $popupClassName();
318
+ $obj->setId($popupId);
319
+ $obj->setType($type);
320
+ $obj->setTitle($title);
321
+ $obj->setContent($popupContent);
322
+
323
+ if (!empty($savedData['sgpb-target'][0])) {
324
+ $obj->setTarget($savedData['sgpb-target'][0]);
325
+ }
326
+ unset($savedData['sgpb-target']);
327
+ if (!empty($savedData['sgpb-events'][0])) {
328
+ $events = self::shapeEventsToOneArray($savedData['sgpb-events'][0]);
329
+ $obj->setEvents($events);
330
+ }
331
+ unset($savedData['sgpb-events']);
332
+ if (!empty($savedData['sgpb-conditions'][0])) {
333
+ $obj->setConditions($savedData['sgpb-conditions'][0]);
334
+ }
335
+ unset($savedData['sgpb-conditions']);
336
+
337
+ $obj->setOptions($savedData);
338
+
339
+ return $obj;
340
+ }
341
+
342
+ private static function shapeEventsToOneArray($events)
343
+ {
344
+ $eventsData = array();
345
+ if (!empty($events)) {
346
+ foreach ($events as $event) {
347
+ if (empty($event['hiddenOption'])) {
348
+ $eventsData[] = $event;
349
+ continue;
350
+ }
351
+ $hiddenOptions = $event['hiddenOption'];
352
+ unset($event['hiddenOption']);
353
+ $eventsData[] = $event + $hiddenOptions;
354
+ }
355
+ }
356
+
357
+ return apply_filters('sgpbEventsToOneArray', $eventsData);
358
+ }
359
+
360
+ public static function getPopupClassNameFormType($type)
361
+ {
362
+ $popupName = ucfirst(strtolower($type));
363
+ $popupClassName = $popupName.'Popup';
364
+
365
+ return apply_filters('sgpbPopupClassNameFromType', $popupClassName);
366
+ }
367
+
368
+ public static function getPopupTypeClassPath($type)
369
+ {
370
+ global $SGPB_POPUP_TYPES;
371
+ $typePaths = $SGPB_POPUP_TYPES['typePath'];
372
+
373
+ if (empty($typePaths[$type])) {
374
+ return SG_POPUP_CLASSES_POPUPS_PATH;
375
+ }
376
+
377
+ return $typePaths[$type];
378
+ }
379
+
380
+ public function sanitizeValueByType($value, $type)
381
+ {
382
+ switch ($type) {
383
+ case 'string':
384
+ if (is_array($value)) {
385
+ $sanitizedValue = $this->recursiveSanitizeTextField($value);
386
+ }
387
+ else {
388
+ $sanitizedValue = htmlspecialchars($value);
389
+ }
390
+ break;
391
+ case 'text':
392
+ $sanitizedValue = htmlspecialchars($value);
393
+ break;
394
+ case 'array':
395
+ $sanitizedValue = $this->recursiveSanitizeTextField($value);
396
+ break;
397
+ case 'email':
398
+ $sanitizedValue = sanitize_email($value);
399
+ break;
400
+ case 'sgpb':
401
+ $sanitizedValue = $this->recursiveHtmlSpecialchars($value);
402
+ break;
403
+ default:
404
+ $sanitizedValue = sanitize_text_field($value);
405
+ break;
406
+ }
407
+
408
+ return $sanitizedValue;
409
+ }
410
+
411
+ public function recursiveSanitizeTextField($array)
412
+ {
413
+ if (!is_array($array)) {
414
+ return $array;
415
+ }
416
+
417
+ foreach ($array as $key => &$value) {
418
+ if (is_array($value)) {
419
+ $value = $this->recursiveSanitizeTextField($value);
420
+ }
421
+ else {
422
+ /*get simple field type and do sanitization*/
423
+ $defaultData = $this->getDefaultDataByName($key);
424
+ if (empty($defaultData['type'])) {
425
+ $defaultData['type'] = 'string';
426
+ }
427
+ $value = $this->sanitizeValueByType($value, $defaultData['type']);
428
+ }
429
+ }
430
+
431
+ return $array;
432
+ }
433
+
434
+ public function recursiveHtmlSpecialchars($array)
435
+ {
436
+ if (!is_array($array)) {
437
+ return $array;
438
+ }
439
+
440
+ foreach ($array as $key => &$value) {
441
+ if (is_array($value)) {
442
+ $value = $this->recursiveHtmlSpecialchars($value);
443
+ }
444
+ else {
445
+ $value = htmlspecialchars($value);
446
+ }
447
+ }
448
+
449
+ return $array;
450
+ }
451
+
452
+ public static function parsePopupDataFromData($data)
453
+ {
454
+ $popupData = array();
455
+ $data = apply_filters('sgpbFilterOptionsBeforeSaving', $data);
456
+
457
+ foreach ($data as $key => $value) {
458
+ if (strpos($key, 'sgpb') === 0) {
459
+ $popupData[$key] = $value;
460
+ }
461
+ if (is_array($value) && isset($value['name']) && strpos($value['name'], 'sgpb') === 0) {
462
+ $popupData[$value['name']] = $value['value'];
463
+ }
464
+ else if (is_array($value) && isset($value['name']) && strpos($value['name'], 'post_ID') === 0) {
465
+ $popupData['sgpb-post-id'] = $value['value'];
466
+ }
467
+ }
468
+
469
+ return $popupData;
470
+ }
471
+
472
+ public static function create($data = array(), $saveMode = '', $firstTime = 0)
473
+ {
474
+ $obj = new static();
475
+ $obj->setSaveMode($saveMode);
476
+ $additionalData = $obj->addAdditionalSettings($data, $obj);
477
+ $data = array_merge($data, $additionalData);
478
+ $data = apply_filters('sgpbAdvancedOptionsDefaultValues', $data);
479
+ foreach ($data as $name => $value) {
480
+ if (strpos($name, 'sgpb') === 0) {
481
+ $defaultData = $obj->getDefaultDataByName($name);
482
+ if (empty($defaultData['type'])) {
483
+ $defaultData['type'] = 'string';
484
+ }
485
+ $sanitizedValue = $obj->sanitizeValueByType($value, $defaultData['type']);
486
+ $obj->insertIntoSanitizedData(array('name' => $name,'value' => $sanitizedValue));
487
+ }
488
+ }
489
+
490
+ $obj->setSavedPopupById($data['sgpb-post-id']);
491
+ $result = $obj->save();
492
+
493
+ $result = apply_filters('sgpbPopupCreateResult', $result);
494
+
495
+ if ($result) {
496
+ return $obj;
497
+ }
498
+
499
+ return $result;
500
+ }
501
+
502
+ public function save()
503
+ {
504
+ $this->convertImagesToData();
505
+ $data = $this->getSanitizedData();
506
+ $popupId = $data['sgpb-post-id'];
507
+
508
+ $this->setId($popupId);
509
+
510
+ if (!empty($data['sgpb-target'])) {
511
+ $this->setTarget($data['sgpb-target']);
512
+ /*remove from popup options because it's useless to save it twice*/
513
+ unset($data['sgpb-target']);
514
+ }
515
+ if (!empty($data['sgpb-conditions'])) {
516
+ $this->setConditions($data['sgpb-conditions']);
517
+ unset($data['sgpb-conditions']);
518
+ }
519
+ if (!empty($data['sgpb-events'])) {
520
+ $this->setEvents($data['sgpb-events']);
521
+ unset($data['sgpb-events']);
522
+ }
523
+ $data = $this->customScriptsSave($data);
524
+ $this->setOptions($data);
525
+
526
+ $targets = $this->targetSave();
527
+ $events = $this->eventsSave();
528
+ $options = $this->popupOptionsSave();
529
+
530
+ return ($targets && $events && $options);
531
+ }
532
+
533
+ public function convertImagesToData()
534
+ {
535
+ $buttonImageData = '';
536
+ $savedImageUrl = '';
537
+ $savedContentBackgroundImageUrl = '';
538
+ $contentBackgroundImageData = '';
539
+
540
+ $data = $this->getSanitizedData();
541
+ $buttonImageUrl = @$data['sgpb-button-image'];
542
+ $contentBackgroundImageUrl = @$data['sgpb-background-image'];
543
+
544
+ $savedPopup = $this->getSavedPopup();
545
+
546
+ if (is_object($savedPopup)) {
547
+ $buttonImageData = $savedPopup->getOptionvalue('sgpb-button-image-data');
548
+ $savedImageUrl = $savedPopup->getOptionValue('sgpb-button-image');
549
+ $contentBackgroundImageData = $savedPopup->getOptionValue('sgpb-background-image-data');
550
+ $savedContentBackgroundImageUrl = $savedPopup->getOptionValue('sgpb-background-image');
551
+ }
552
+
553
+ if ($buttonImageUrl != $savedImageUrl) {
554
+ $buttonImageData = AdminHelper::getImageDataFromUrl($buttonImageUrl, true);
555
+ }
556
+ if ($contentBackgroundImageUrl != $savedContentBackgroundImageUrl) {
557
+ $contentBackgroundImageData = AdminHelper::getImageDataFromUrl($contentBackgroundImageUrl);
558
+ }
559
+
560
+ $data['sgpb-button-image-data'] = $buttonImageData;
561
+ $data['sgpb-background-image-data'] = $contentBackgroundImageData;
562
+
563
+ $data = apply_filters('sgpbConvertImagesToData', $data);
564
+ $this->setSanitizedData($data);
565
+ }
566
+
567
+ private function customScriptsSave($data)
568
+ {
569
+ $popupId = $this->getId();
570
+ $popupContent = $this->getContent();
571
+
572
+ $defaultData = ConfigDataHelper::defaultData();
573
+ $defaultDataJs = $defaultData['customEditorContent']['js']['helperText'];
574
+ $defaultDataCss = $defaultData['customEditorContent']['css']['oldDefaultValue'];
575
+
576
+ $finalData = array('js' => array(), 'css' => array());
577
+ $alreadySavedData = get_post_meta($popupId, 'sg_popup_scripts', true);
578
+
579
+ // get styles
580
+ $finalData['css'] = $data['sgpb-css-editor'];
581
+ $defaultDataCss = $defaultDataCss[0];
582
+
583
+ $defaultDataCss = preg_replace('/\s/', '', $defaultDataCss);
584
+ $temp = preg_replace('/\s/', '', $finalData['css']);
585
+
586
+ unset($data['sgpb-css-editor']);
587
+
588
+ if ($temp == $defaultDataCss) {
589
+ unset($finalData['css']);
590
+ }
591
+
592
+ // get scripts
593
+ foreach ($defaultDataJs as $key => $value) {
594
+ if ($data['sgpb-'.$key] == '') {
595
+ unset($data['sgpb-'.$key]);
596
+ continue;
597
+ }
598
+ if ($key == 'ShouldOpen' || $key == 'ShouldClose') {
599
+ $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
600
+ continue;
601
+ }
602
+ $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
603
+ unset($data['sgpb-'.$key]);
604
+ }
605
+
606
+ if ($alreadySavedData == $finalData) {
607
+ return $data;
608
+ }
609
+
610
+ array_walk_recursive($finalData, function(&$element){
611
+ $element = str_replace(array("\r\n"), "\n", $element);
612
+ });
613
+
614
+ update_post_meta($popupId, 'sg_popup_scripts', $finalData);
615
+
616
+ return $data;
617
+ }
618
+
619
+ private function targetSave()
620
+ {
621
+ global $SGPB_DATA_CONFIG_ARRAY;
622
+ $saveMode = $this->getSaveMode();
623
+ $popupId = $this->getId();
624
+ $targetData = $this->getTarget();
625
+ $conditionsData = $this->getConditions();
626
+
627
+ $targetConfig = $SGPB_DATA_CONFIG_ARRAY['target'];
628
+ $paramsData = $targetConfig['paramsData'];
629
+ $attrs = $targetConfig['attrs'];
630
+ $popupTarget = array();
631
+ if (empty($targetData)) {
632
+ return array();
633
+ }
634
+
635
+ foreach ($targetData as $groupId => $groupData) {
636
+ foreach ($groupData as $ruleId => $ruleData) {
637
+
638
+ if (empty($ruleData['value']) && !is_null($paramsData[$ruleData['param']])) {
639
+ $targetData[$groupId][$ruleId]['value'] = '';
640
+ }
641
+ if (isset($ruleData['value']) && is_array($ruleData['value'])) {
642
+ $valueAttrs = $attrs[$ruleData['param']]['htmlAttrs'];
643
+ $postType = $valueAttrs['data-value-param'];
644
+ $isNotPostType = '';
645
+ if (isset($valueAttrs['isNotPostType'])) {
646
+ $isNotPostType = $valueAttrs['isNotPostType'];
647
+ }
648
+
649
+ if (empty($valueAttrs['isNotPostType'])) {
650
+ $isNotPostType = false;
651
+ }
652
+
653
+ /*
654
+ * $isNotPostType => false must search inside post types post
655
+ * $isNotPostType => true must save array data
656
+ * */
657
+ if (!$isNotPostType) {
658
+ $args = array(
659
+ 'post__in' => array_values($ruleData['value']),
660
+ 'posts_per_page' => 100,
661
+ 'post_type' => $postType
662
+ );
663
+
664
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
665
+
666
+ $targetData[$groupId][$ruleId]['value'] = $searchResults;
667
+ }
668
+ }
669
+ }
670
+ }
671
+
672
+ $popupTarget['sgpb-target'] = $targetData;
673
+ $popupTarget['sgpb-conditions'] = apply_filters('sgpbSaveConditions', $conditionsData);
674
+
675
+ $alreadySavedTargets = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
676
+ if ($alreadySavedTargets === $popupTarget) {
677
+ return true;
678
+ }
679
+
680
+ $popupTarget = apply_filters('sgpbPopupTargetMetaData', $popupTarget);
681
+
682
+ return update_post_meta($popupId, 'sg_popup_target'.$saveMode, $popupTarget);
683
+ }
684
+
685
+ private function eventsSave()
686
+ {
687
+ global $SGPB_DATA_CONFIG_ARRAY;
688
+
689
+ $eventsData = $this->getEvents();
690
+ $popupId = $this->getId();
691
+ $saveMode = $this->getSaveMode();
692
+ $popupEvents = array();
693
+ $eventsFromPopup = array();
694
+
695
+ foreach ($eventsData as $groupId => $groupData) {
696
+ $currentRuleData = array();
697
+ foreach ($groupData as $ruleId => $ruleData) {
698
+
699
+ $hiddenOptions = array();
700
+ $currentData = array();
701
+ foreach ($ruleData as $name => $value) {
702
+ if ($name == 'param' || $name == 'value' || $name == 'operator') {
703
+ $currentData[$name] = $value;
704
+ }
705
+ else {
706
+ $hiddenOptions[$name] = $value;
707
+ }
708
+ }
709
+ $currentData['hiddenOption'] = $hiddenOptions;
710
+ $currentRuleData[$ruleId] = $currentData;
711
+ }
712
+ $eventsFromPopup[$groupId] = $currentRuleData;
713
+ }
714
+
715
+ $popupEvents['formPopup'] = $eventsFromPopup;
716
+ $alreadySavedEvents = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
717
+ if ($alreadySavedEvents === $eventsFromPopup) {
718
+ return true;
719
+ }
720
+
721
+ $eventsFromPopup = apply_filters('sgpbPopupEventsMetadata', $eventsFromPopup);
722
+
723
+ return update_post_meta($popupId, 'sg_popup_events'.$saveMode, $eventsFromPopup);
724
+ }
725
+
726
+ private function popupOptionsSave()
727
+ {
728
+ $popupOptions = $this->getOptions();
729
+ $popupOptions = apply_filters('sgpbSavePopupOptions', $popupOptions);
730
+ //special code added for "Behavior After Special Events" section
731
+ //todo: remove in the future if possible
732
+ $specialBehaviors = array();
733
+ if (!empty($popupOptions['sgpb-behavior-after-special-events'])) {
734
+ $specialBehaviors = $popupOptions['sgpb-behavior-after-special-events'];
735
+ }
736
+ if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
737
+ foreach ($specialBehaviors as $groupId => $groupRow) {
738
+ foreach ($groupRow as $ruleId => $ruleRow) {
739
+ if (!empty($ruleRow['operator']) && $ruleRow['operator'] == 'open-popup') {
740
+ $args = array(
741
+ 'post__in' => array($ruleRow['value']),
742
+ 'posts_per_page' => 10,
743
+ 'post_type' => SG_POPUP_POST_TYPE
744
+ );
745
+
746
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
747
+ $popupOptions['sgpb-behavior-after-special-events'][$groupId][$ruleId]['value'] = $searchResults;
748
+ }
749
+ }
750
+ }
751
+ }
752
+
753
+ $popupId = $this->getId();
754
+ $saveMode = $this->getSaveMode();
755
+
756
+ $alreadySavedOptions = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
757
+ if ($alreadySavedOptions === $popupOptions) {
758
+ return true;
759
+ }
760
+
761
+ $popupOptions = apply_filters('sgpbPopupSavedOptionsMetaData', $popupOptions);
762
+
763
+ return update_post_meta($popupId, 'sg_popup_options'.$saveMode, $popupOptions);
764
+ }
765
+
766
+ public function getOptionValue($optionName, $forceDefaultValue = false)
767
+ {
768
+ require_once(dirname(__FILE__).'/PopupData.php');
769
+ $savedData = PopupData::getPopupDataById($this->getId());
770
+ $this->setPostData($savedData);
771
+
772
+ return $this->getOptionValueFromSavedData($optionName, $forceDefaultValue);
773
+ }
774
+
775
+ public function getOptionValueFromSavedData($optionName, $forceDefaultValue = false)
776
+ {
777
+ $defaultData = $this->getDefaultDataByName($optionName);
778
+ $savedData = $this->getPostData();
779
+
780
+ $optionValue = null;
781
+
782
+ if (empty($defaultData['type'])) {
783
+ $defaultData['type'] = 'string';
784
+ }
785
+
786
+ if (!empty($savedData)) { //edit mode
787
+ if (isset($savedData[$optionName])) { //option exists in the database
788
+ $optionValue = $savedData[$optionName];
789
+ }
790
+ /* if it's a checkbox, it may not exist in the db
791
+ * if we don't care about it's existance, return empty string
792
+ * otherwise, go for it's default value
793
+ */
794
+ else if ($defaultData['type'] == 'checkbox' && !$forceDefaultValue) {
795
+ $optionValue = '';
796
+ }
797
+ }
798
+
799
+ if ($optionValue === null && !empty($defaultData['defaultValue'])) {
800
+ $optionValue = $defaultData['defaultValue'];
801
+ }
802
+
803
+ if ($defaultData['type'] == 'checkbox') {
804
+ $optionValue = $this->boolToChecked($optionValue);
805
+ }
806
+
807
+ if ($defaultData['type'] == 'number' && $optionValue == 0) {
808
+ $optionValue = 0;
809
+ }
810
+
811
+ return $optionValue;
812
+ }
813
+
814
+ public static function getSavedData($popupId, $saveMode = '')
815
+ {
816
+ $popupSavedData = array();
817
+ $events = self::getEventsDataById($popupId, $saveMode);
818
+ $targetData = self::getTargetDataById($popupId, $saveMode);
819
+
820
+ if (!empty($events)) {
821
+ $popupSavedData['sgpb-events'] = self::getEventsDataById($popupId, $saveMode);
822
+ }
823
+ if (!empty($targetData)) {
824
+ if (!empty($targetData['sgpb-target'])) {
825
+ $popupSavedData['sgpb-target'] = $targetData['sgpb-target'];
826
+ }
827
+ if (!empty($targetData['sgpb-conditions'])) {
828
+ // for the after x pages option backward compatibility
829
+ $targetData['sgpb-conditions'] = apply_filters('sgpbAdvancedTargetingSavedData', $targetData['sgpb-conditions'], $popupId);
830
+ $popupSavedData['sgpb-conditions'] = $targetData['sgpb-conditions'];
831
+ }
832
+ }
833
+
834
+ $popupOptions = self::getPopupOptionsById($popupId, $saveMode);
835
+ if (is_array($popupOptions) && is_array($popupSavedData)) {
836
+ $popupSavedData = array_merge($popupSavedData, $popupOptions);
837
+ }
838
+
839
+ return $popupSavedData;
840
+ }
841
+
842
+ public static function getEventsDataById($popupId, $saveMode = '')
843
+ {
844
+ $eventsData = array();
845
+ if (get_post_meta($popupId, 'sg_popup_events'.$saveMode, true)) {
846
+ $eventsData = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
847
+ }
848
+
849
+ return $eventsData;
850
+ }
851
+
852
+ public static function getTargetDataById($popupId, $saveMode = '')
853
+ {
854
+ $targetData = array();
855
+
856
+ if (get_post_meta($popupId, 'sg_popup_target'.$saveMode, true)) {
857
+ $targetData = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
858
+ }
859
+
860
+ return $targetData;
861
+ }
862
+
863
+ public static function getPopupOptionsById($popupId, $saveMode = '')
864
+ {
865
+ $currentPost = get_post($popupId);
866
+
867
+ if (!empty($currentPost) && $currentPost->post_status == 'draft') {
868
+ $saveMode = '_preview';
869
+ }
870
+ $optionsData = array();
871
+ if (get_post_meta($popupId, 'sg_popup_options'.$saveMode, true)) {
872
+ $optionsData = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
873
+ }
874
+
875
+ return $optionsData;
876
+ }
877
+
878
+ public function getDefaultDataByName($optionName)
879
+ {
880
+ global $SGPB_OPTIONS;
881
+ if (empty($SGPB_OPTIONS)) {
882
+ return array();
883
+ }
884
+
885
+ foreach ($SGPB_OPTIONS as $option) {
886
+ if ($option['name'] == $optionName) {
887
+ return $option;
888
+ }
889
+ }
890
+
891
+ return array();
892
+ }
893
+
894
+ /**
895
+ * Get option default option value
896
+ *
897
+ * @param string $optionName
898
+ *
899
+ * @since 1.0.0
900
+ *
901
+ * @return string
902
+ *
903
+ */
904
+ public function getOptionDefaultValue($optionName)
905
+ {
906
+ // return config data array by name
907
+ $optionData = $this->getDefaultDataByName($optionName);
908
+
909
+ if (empty($optionData)) {
910
+ return '';
911
+ }
912
+
913
+ return $optionData['defaultValue'];
914
+ }
915
+
916
+ /**
917
+ * Changing default options form changing options by name
918
+ *
919
+ * @since 1.0.0
920
+ *
921
+ * @param array $defaultOptions
922
+ * @param array $changingOptions
923
+ *
924
+ * @return array $defaultOptions
925
+ */
926
+ public function changeDefaultOptionsByNames($defaultOptions, $changingOptions)
927
+ {
928
+ if (empty($defaultOptions) || empty($changingOptions)) {
929
+ return $defaultOptions;
930
+ }
931
+ $changingOptionsNames = array_keys($changingOptions);
932
+
933
+ foreach ($defaultOptions as $key => $defaultOption) {
934
+ $defaultOptionName = $defaultOption['name'];
935
+ if (in_array($defaultOptionName, $changingOptionsNames)) {
936
+ $defaultOptions[$key] = $changingOptions[$defaultOptionName];
937
+ }
938
+ }
939
+
940
+ return $defaultOptions;
941
+ }
942
+
943
+ /**
944
+ * Returns separate popup types Free or Pro
945
+ *
946
+ * @since 2.5.6
947
+ *
948
+ * @return array $popupTypesObj
949
+ */
950
+ public static function getPopupTypes()
951
+ {
952
+ global $SGPB_POPUP_TYPES;
953
+ $popupTypesObj = array();
954
+ $popupTypes = $SGPB_POPUP_TYPES['typeName'];
955
+
956
+ foreach ($popupTypes as $popupType => $level) {
957
+
958
+ if (empty($level)) {
959
+ $level = SGPB_POPUP_PKG_FREE;
960
+ }
961
+
962
+ $popupTypeObj = new PopupType();
963
+ $popupTypeObj->setName($popupType);
964
+ $popupTypeObj->setAccessLevel($level);
965
+
966
+ if (SGPB_POPUP_PKG >= $level) {
967
+ $popupTypeObj->setAvailable(true);
968
+ }
969
+ $popupTypesObj[] = $popupTypeObj;
970
+ }
971
+
972
+ return $popupTypesObj;
973
+ }
974
+
975
+ public static function savePopupsFromContentClasses($content, $post)
976
+ {
977
+ $postId = $post->ID;
978
+ $clickClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-id-');
979
+ $targetData = array();
980
+ $eventsData = array();
981
+
982
+ if (!empty($clickClassIds)) {
983
+ foreach ($clickClassIds as $id) {
984
+ $id = apply_filters('sgpbConvertedPopupId', $id);
985
+ if (empty($eventsData[$postId][$id])) {
986
+ $eventsData[$postId][$id] = array('click');
987
+ }
988
+ else {
989
+ $eventsData[$postId][$id][] = 'click';
990
+ }
991
+
992
+ if (empty($targetData[$postId])) {
993
+ $targetData[$postId] = array($id);
994
+ }
995
+ else {
996
+ $targetData[$postId][] = $id;
997
+ }
998
+ }
999
+ }
1000
+
1001
+ $iframeClassIs = self::getStringNextNumbersByReg($content, 'sg-iframe-popup-');
1002
+
1003
+ if (!empty($iframeClassIs)) {
1004
+ foreach ($iframeClassIs as $id) {
1005
+ $id = apply_filters('sgpbConvertedPopupId', $id);
1006
+ $popupObj = self::find($id);
1007
+
1008
+ if (empty($popupObj)) {
1009
+ continue;
1010
+ }
1011
+
1012
+ // this event should work only for iframe popup type
1013
+ if ($popupObj->getType() != 'iframe') {
1014
+ continue;
1015
+ }
1016
+
1017
+ if (empty($eventsData[$postId][$id])) {
1018
+ $eventsData[$postId][$id] = array('iframe');
1019
+ }
1020
+ else {
1021
+ $eventsData[$postId][$id][] = 'iframe';
1022
+ }
1023
+
1024
+ if (empty($targetData[$postId])) {
1025
+ $targetData[$postId] = array($id);
1026
+ }
1027
+ else {
1028
+ $targetData[$postId][] = $id;
1029
+ }
1030
+ }
1031
+ }
1032
+
1033
+ $confirmClassIds = self::getStringNextNumbersByReg($content, 'sg-confirm-popup-');
1034
+
1035
+ if (!empty($confirmClassIds)) {
1036
+ foreach ($confirmClassIds as $id) {
1037
+ $id = apply_filters('sgpbConvertedPopupId', $id);
1038
+ if (empty($eventsData[$postId][$id])) {
1039
+ $eventsData[$postId][$id] = array('confirm');
1040
+ }
1041
+ else {
1042
+ $eventsData[$postId][$id][] = 'confirm';
1043
+ }
1044
+
1045
+ if (empty($targetData[$postId])) {
1046
+ $targetData[$postId] = array($id);
1047
+ }
1048
+ else {
1049
+ $targetData[$postId][] = $id;
1050
+ }
1051
+ }
1052
+ }
1053
+
1054
+ $hoverClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-hover-');
1055
+
1056
+ if (!empty($hoverClassIds)) {
1057
+ foreach ($hoverClassIds as $id) {
1058
+ $id = apply_filters('sgpbConvertedPopupId', $id);
1059
+ if (empty($eventsData[$postId][$id])) {
1060
+ $eventsData[$postId][$id] = array('hover');
1061
+ }
1062
+ else {
1063
+ $eventsData[$postId][$id][] = 'hover';
1064
+ }
1065
+
1066
+ if (empty($targetData[$postId])) {
1067
+ $targetData[$postId] = array($id);
1068
+ }
1069
+ else {
1070
+ $targetData[$postId][] = $id;
1071
+ }
1072
+ }
1073
+ }
1074
+
1075
+ $targetData = apply_filters('sgpbPopupTargetData', $targetData);
1076
+ $eventsData = apply_filters('sgpbPopupEventsData', $eventsData);
1077
+
1078
+ self::saveToTargetFromPage($targetData);
1079
+ self::saveToEventsFromPage($eventsData);
1080
+ }
1081
+
1082
+ public static function getStringNextNumbersByReg($content, $key)
1083
+ {
1084
+ $result = array();
1085
+ preg_match_all("/(?<=$key)(\d+)/", $content, $ids);
1086
+
1087
+ if (!empty($ids[0])) {
1088
+ $result = $ids[0];
1089
+ }
1090
+
1091
+ return $result;
1092
+ }
1093
+
1094
+ private static function saveToTargetAndEvents($popupsShortcodsInPostPage, $postId)
1095
+ {
1096
+ if (empty($popupsShortcodsInPostPage)) {
1097
+ return false;
1098
+ }
1099
+ $customEvents = array();
1100
+ $customPopups = array();
1101
+
1102
+ foreach ($popupsShortcodsInPostPage as $shortcodesData) {
1103
+ $popupId = apply_filters('sgpbConvertedPopupId', $shortcodesData['id']);
1104
+
1105
+ $args = array(
1106
+ 'post_type' => SG_POPUP_POST_TYPE,
1107
+ 'post__in' => array($popupId)
1108
+ );
1109
+ $postById = ConfigDataHelper::getPostTypeData($args);
1110
+ //When target data does not exist
1111
+ if (empty($postById)) {
1112
+ continue;
1113
+ }
1114
+
1115
+ // collect custom inserted popups
1116
+ if (empty($customPopups[$postId])) {
1117
+ $customPopups[$postId] = array($popupId);
1118
+ }
1119
+ else {
1120
+ $customPopups[$postId][] = $popupId;
1121
+ }
1122
+
1123
+ // collect custom inserted popups events
1124
+ if (empty($shortcodesData['event'])) {
1125
+ $eventName = 'onload';
1126
+ }
1127
+ else {
1128
+ $eventName = $shortcodesData['event'];
1129
+ }
1130
+
1131
+ if ($eventName == 'onload') {
1132
+ $eventName = 'attr'.$eventName;
1133
+ }
1134
+ $currentEventData = array(
1135
+ 'param' => $eventName
1136
+ );
1137
+
1138
+ if (empty($customEvents[$postId][$popupId])) {
1139
+ $customEvents[$postId][$popupId] = array($currentEventData);
1140
+ }
1141
+ else {
1142
+ $customEvents[$postId][$popupId][] = $currentEventData;
1143
+ }
1144
+ }
1145
+
1146
+ self::saveToTargetFromPage($customPopups);
1147
+ self::saveToEventsFromPage($customEvents);
1148
+
1149
+ return true;
1150
+ }
1151
+
1152
+ public static function getPostPopupCustomEvent($postId, $popupId)
1153
+ {
1154
+ $events = array();
1155
+
1156
+ $customEventsData = self::getCustomInsertedPopupEventsByPostId($postId);
1157
+
1158
+ if (!empty($customEventsData[$popupId])) {
1159
+ $events = $customEventsData[$popupId];
1160
+ }
1161
+
1162
+ return $events;
1163
+ }
1164
+
1165
+ /**
1166
+ * Save popup to custom events from pages
1167
+ *
1168
+ * @since 1.0.0
1169
+ *
1170
+ * @param array $customEvents
1171
+ *
1172
+ * @return bool
1173
+ *
1174
+ */
1175
+ public static function saveToEventsFromPage($customEvents)
1176
+ {
1177
+ if (empty($customEvents)) {
1178
+ return false;
1179
+ }
1180
+
1181
+ foreach ($customEvents as $postId => $popupsData) {
1182
+ $savedCustomEvents = self::getCustomInsertedPopupEventsByPostId($postId);
1183
+ $result = AdminHelper::arrayMergeSameKeys($popupsData, $savedCustomEvents);
1184
+
1185
+ if (!$result) {
1186
+ return $result;
1187
+ }
1188
+ update_post_meta($postId, 'sgpb_popup_events_custom', $result);
1189
+ }
1190
+
1191
+ return true;
1192
+ }
1193
+
1194
+ public static function getCustomInsertedPopupEventsByPostId($postId)
1195
+ {
1196
+ $eventsData = array();
1197
+ $postMetaData = get_post_meta($postId, 'sgpb_popup_events_custom', true);
1198
+
1199
+ if (!empty($postMetaData)) {
1200
+ $eventsData = $postMetaData;
1201
+ }
1202
+
1203
+ return $eventsData;
1204
+ }
1205
+
1206
+ /**
1207
+ * Save popup to custom targets from pages
1208
+ *
1209
+ * @since 1.0.0
1210
+ *
1211
+ * @param array $customPopups
1212
+ *
1213
+ * @return void
1214
+ *
1215
+ */
1216
+ public static function saveToTargetFromPage($customPopups)
1217
+ {
1218
+ if (!empty($customPopups)) {
1219
+ foreach ($customPopups as $postId => $popups) {
1220
+ $alreadySavedPopups = self::getCustomInsertedDataByPostId($postId);
1221
+ $popups = array_merge($popups, $alreadySavedPopups);
1222
+ update_post_meta($postId, 'sg_popup_target_custom', $popups);
1223
+ }
1224
+ }
1225
+ }
1226
+
1227
+ /**
1228
+ * Get popup custom targes form saved data
1229
+ *
1230
+ * @since 1.0.0
1231
+ *
1232
+ * @param int $postId
1233
+ *
1234
+ * @return array $postData
1235
+ */
1236
+ public static function getCustomInsertedDataByPostId($postId)
1237
+ {
1238
+ $postData = array();
1239
+ $postMetaData = get_post_meta($postId, 'sg_popup_target_custom');
1240
+
1241
+ if (!empty($postMetaData[0])) {
1242
+ $postData = $postMetaData[0];
1243
+ }
1244
+
1245
+ return $postData;
1246
+ }
1247
+
1248
+ public static function getPopupShortcodeMatchesFromContent($content)
1249
+ {
1250
+ $result = false;
1251
+ $pattern = get_shortcode_regex();
1252
+
1253
+ if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1254
+ && !empty($matches)
1255
+ && is_array($matches)
1256
+ && array_key_exists( 2, $matches )
1257
+ && in_array('sg_popup', $matches[2])
1258
+ )
1259
+ {
1260
+ $result = $matches;
1261
+ }
1262
+
1263
+ return $result;
1264
+ }
1265
+
1266
+ public static function renderPopupContentShortcode($content, $popupId, $event, $args)
1267
+ {
1268
+ ob_start();
1269
+ $wrap = 'a';
1270
+ if (!empty($args['wrap'])) {
1271
+ if ($args['wrap'] == $wrap) {
1272
+ $args['href'] = 'javascript:void(0)';
1273
+ }
1274
+ $wrap = $args['wrap'];
1275
+ }
1276
+ unset($args['wrap']);
1277
+ unset($args['event']);
1278
+ unset($args['id']);
1279
+ $attr = AdminHelper::createAttrs($args);
1280
+ ?>
1281
+ <<?php echo $wrap; ?>
1282
+ <?php if ($wrap == 'a') : ?>
1283
+ href="javascript:void(0)"
1284
+ <?php endif ?>
1285
+ class="sgpb-show-popup <?php echo 'sgpb-popup-id-'.$popupId; ?>"
1286
+ data-sgpbpopupid="<?php echo esc_attr($popupId); ?>"
1287
+ data-popup-event="<?php echo $event; ?>"
1288
+ <?php echo $attr; ?>>
1289
+ <?php echo $content; ?>
1290
+ </<?php echo $wrap; ?>>
1291
+ <?php
1292
+
1293
+ $shortcodeContent = ob_get_contents();
1294
+ ob_get_clean();
1295
+
1296
+ return $shortcodeContent;
1297
+ }
1298
+
1299
+ private static function collectInsidePopupShortcodes($content)
1300
+ {
1301
+ $pattern = get_shortcode_regex();
1302
+ $options = array();
1303
+ if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1304
+ && !empty($matches)
1305
+ && is_array($matches)
1306
+ && array_key_exists( 2, $matches )
1307
+ && in_array('sg_popup', $matches[2])
1308
+ )
1309
+ {
1310
+ foreach ($matches[0] as $key => $value) {
1311
+ //return current shortcode all attrs as assoc array
1312
+ $attrs = shortcode_parse_atts($matches[3][$key]);
1313
+ $currentAttrs = array();
1314
+ if (!empty($attrs['id'])) {
1315
+ $currentAttrs['id'] = $attrs['id'];
1316
+ }
1317
+ if (!empty($attrs['insidepopup'])) {
1318
+ $currentAttrs['insidepopup'] = $attrs['insidepopup'];
1319
+ }
1320
+ if (empty($attrs['insidepopup']) || (!empty($attrs['insidepopup']) && $attrs['insidepopup'] != 'on')) {
1321
+ continue;
1322
+ }
1323
+
1324
+ $options[$currentAttrs['id']] = $value;
1325
+ }
1326
+ }
1327
+
1328
+ return apply_filters('sgpbPopupInsideShortcodes', $options);
1329
+ }
1330
+
1331
+ /**
1332
+ * Collect all popups by taxonomy slug
1333
+ *
1334
+ * @since 1.0.0
1335
+ *
1336
+ * @param string $popupTermSlug category slug name
1337
+ *
1338
+ * @return array $popupIds random popups id
1339
+ *
1340
+ */
1341
+ public static function getPopupsByTermSlug($popupTermSlug)
1342
+ {
1343
+ $popupIds = array();
1344
+
1345
+ $termPopups = get_transient(SGPB_TRANSIENT_POPUPS_TERMS);
1346
+ if ($termPopups === false) {
1347
+ $termPopups = get_posts(
1348
+ array(
1349
+ 'post_type' => 'popupbuilder',
1350
+ 'numberposts' => -1,
1351
+ 'tax_query' => array(
1352
+ array(
1353
+ 'taxonomy' => SG_POPUP_CATEGORY_TAXONOMY,
1354
+ 'field' => 'slug',
1355
+ 'terms' => $popupTermSlug
1356
+ )
1357
+ )
1358
+ )
1359
+ );
1360
+ set_transient(SGPB_TRANSIENT_POPUPS_TERMS, $termPopups, SGPB_TRANSIENT_TIMEOUT_WEEK);
1361
+ }
1362
+
1363
+ if (empty($termPopups)) {
1364
+ return $popupIds;
1365
+ }
1366
+
1367
+ foreach ($termPopups as $termPopup) {
1368
+ $popupIds[] = $termPopup->ID;
1369
+ }
1370
+
1371
+ return $popupIds;
1372
+ }
1373
+
1374
+ public function boolToChecked($var)
1375
+ {
1376
+ return ($var?'checked':'');
1377
+ }
1378
+
1379
+ /**
1380
+ * Delete custom inserted data
1381
+ *
1382
+ * @since 1.0.0
1383
+ *
1384
+ * @param int $postId current post page id
1385
+ *
1386
+ * @return void
1387
+ *
1388
+ */
1389
+ public static function deletePostCustomInsertedData($postId)
1390
+ {
1391
+ delete_post_meta($postId, 'sg_popup_target_custom');
1392
+ }
1393
+
1394
+ /**
1395
+ * Delete custom inserted events
1396
+ *
1397
+ * @since 1.0.0
1398
+ *
1399
+ * @param int $postId current post page id
1400
+ *
1401
+ * @return void
1402
+ *
1403
+ */
1404
+ public static function deletePostCustomInsertedEvents($postId)
1405
+ {
1406
+ delete_post_meta($postId, 'sgpb_popup_events_custom');
1407
+ }
1408
+
1409
+ /**
1410
+ * If popup Type does not have getPopupTypeOptions method
1411
+ * it's tell popup does not have custom options
1412
+ *
1413
+ * @since 1.0.0
1414
+ *
1415
+ * @return bool
1416
+ *
1417
+ */
1418
+ public function getPopupTypeOptionsView()
1419
+ {
1420
+ return false;
1421
+ }
1422
+
1423
+ /**
1424
+ * If popup Type does not have getPopupTypeOptions method
1425
+ * it's tell popup does not have custom options
1426
+ *
1427
+ * @since 1.0.0
1428
+ *
1429
+ * @return bool
1430
+ *
1431
+ */
1432
+ public function getPopupTypeMainView()
1433
+ {
1434
+ return false;
1435
+ }
1436
+
1437
+ /**
1438
+ * Remove popup option from admin view by option name
1439
+ *
1440
+ * @since 1.0.0
1441
+ *
1442
+ * @return array $removedOptions
1443
+ *
1444
+ */
1445
+ public function getRemoveOptions()
1446
+ {
1447
+ $removeOptions = array();
1448
+
1449
+ return apply_filters('sgpbRemoveOptions', $removeOptions);
1450
+ }
1451
+
1452
+ public static function createPopupTypeObjById($popupId)
1453
+ {
1454
+ global $SGPB_POPUP_TYPES;
1455
+ $typePath = '';
1456
+ $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
1457
+ if (empty($popupOptionsData)) {
1458
+ return false;
1459
+ }
1460
+ $popupType = $popupOptionsData['sgpb-type'];
1461
+ $popupName = ucfirst(strtolower($popupType));
1462
+ $popupClassName = $popupName.'Popup';
1463
+
1464
+ if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
1465
+ $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
1466
+ }
1467
+
1468
+ if (!file_exists($typePath.$popupClassName.'.php')) {
1469
+ wp_die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
1470
+ }
1471
+ require_once($typePath.$popupClassName.'.php');
1472
+
1473
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
1474
+ $popupTypeObj = new $popupClassName();
1475
+ $popupTypeObj->setId($popupId);
1476
+
1477
+ return $popupTypeObj;
1478
+ }
1479
+
1480
+ /**
1481
+ * if child class does not have this function we call parent function to not get any errors
1482
+ *
1483
+ * @since 1.0.0
1484
+ *
1485
+ * @return array
1486
+ *
1487
+ */
1488
+ public static function getTablesSql()
1489
+ {
1490
+ return array();
1491
+ }
1492
+
1493
+ /**
1494
+ * if child class does not have this function we call parent function to not get any errors
1495
+ *
1496
+ * @since 1.0.0
1497
+ *
1498
+ * @return array
1499
+ *
1500
+ */
1501
+ public static function getTableNames()
1502
+ {
1503
+ return array();
1504
+ }
1505
+
1506
+ /**
1507
+ *
1508
+ * Get WordPress localization name
1509
+ *
1510
+ * @since 1.0.0
1511
+ *
1512
+ * @return string
1513
+ *
1514
+ */
1515
+ public function getSiteLocale()
1516
+ {
1517
+ $locale = get_bloginfo('language');
1518
+ $locale = str_replace('-', '_', $locale);
1519
+
1520
+ return $locale;
1521
+ }
1522
+
1523
+ public function addAdditionalSettings($postData = array(), $obj = null)
1524
+ {
1525
+ return array();
1526
+ }
1527
+
1528
+ public function allowToLoad()
1529
+ {
1530
+ global $post;
1531
+
1532
+ $popupChecker = PopupChecker::instance();
1533
+ $loadableModes = $popupChecker->isLoadable($this, $post);
1534
+ $this->setLoadableModes($loadableModes);
1535
+
1536
+ return ($loadableModes['attr_event'] || $loadableModes['option_event']);
1537
+ }
1538
+
1539
+ public function allowToLoadAJAX()
1540
+ {
1541
+ global $post;
1542
+
1543
+ $popupChecker = PopupChecker::instance();
1544
+ $loadableModes = $popupChecker->isLoadable($this, $post, true);
1545
+ $this->setLoadableModes($loadableModes);
1546
+
1547
+ return ($loadableModes['attr_event'] || $loadableModes['option_event']);
1548
+ }
1549
+
1550
+ public static function getAllPopups($filters = array())
1551
+ {
1552
+ $args = array(
1553
+ 'post_type' => SG_POPUP_POST_TYPE
1554
+ );
1555
+ $allPopups = array();
1556
+ $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1557
+
1558
+ if (empty($allPostData)) {
1559
+ return $allPopups;
1560
+ }
1561
+
1562
+ foreach ($allPostData->posts as $postData) {
1563
+ if (empty($postData)) {
1564
+ continue;
1565
+ }
1566
+
1567
+ $popup = self::find($postData->ID, $args);
1568
+ if (empty($popup) || !($popup instanceof SGPopup)) {
1569
+ continue;
1570
+ }
1571
+ $type = @$popup->getType();
1572
+
1573
+ if (isset($filters['type'])) {
1574
+ if (is_array($filters['type'])) {
1575
+ if (!in_array($type, $filters['type'])) {
1576
+ continue;
1577
+ }
1578
+ }
1579
+ else if ($type != $filters['type']) {
1580
+ continue;
1581
+ }
1582
+ }
1583
+ $allPopups[] = $popup;
1584
+ }
1585
+
1586
+ return $allPopups;
1587
+ }
1588
+
1589
+ public function getPopupsIdAndTitle()
1590
+ {
1591
+ $allPopups = SGPopup::getAllPopups();
1592
+ $popupIdTitles = array();
1593
+
1594
+ if (empty($allPopups)) {
1595
+ return $popupIdTitles;
1596
+ }
1597
+ $currentPopupId = $this->getId();
1598
+
1599
+ foreach ($allPopups as $popup) {
1600
+ if (empty($popup)) {
1601
+ continue;
1602
+ }
1603
+ $id = $popup->getId();
1604
+
1605
+ if ($id == $currentPopupId) {
1606
+ continue;
1607
+ }
1608
+
1609
+ $title = $popup->getTitle();
1610
+ $type = $popup->getType();
1611
+
1612
+ $popupIdTitles[$id] = $title.' - '.$type;
1613
+ }
1614
+
1615
+ return $popupIdTitles;
1616
+ }
1617
+
1618
+ public function getSubPopupObj()
1619
+ {
1620
+ $subPopups = array();
1621
+ $options = $this->getOptions();
1622
+
1623
+ $specialBehaviors = @$options['sgpb-behavior-after-special-events'];
1624
+ if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
1625
+ foreach ($specialBehaviors as $behavior) {
1626
+ foreach ($behavior as $row) {
1627
+ if (!empty($row['param']) && $row['param'] == SGPB_CONTACT_FORM_7_BEHAVIOR_KEY) {
1628
+ if (!empty($row['operator']) && $row['operator'] == 'open-popup') {
1629
+ if (!empty($row['value'])) {
1630
+ $popupId = key($row['value']);
1631
+ $subPopupObj = self::find((int)$popupId);
1632
+ if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
1633
+ $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
1634
+ $subPopups[] = $subPopupObj;
1635
+ }
1636
+ }
1637
+ }
1638
+ }
1639
+ }
1640
+ }
1641
+ }
1642
+
1643
+ return $subPopups;
1644
+ }
1645
+
1646
+ public static function doInsideShortcode($insideShortcode)
1647
+ {
1648
+ return do_shortcode($insideShortcode);
1649
+ }
1650
+
1651
+ public function popupShortcodesInsidePopup()
1652
+ {
1653
+ $popups = array();
1654
+ $args = array('insidePopup' => 'on');
1655
+ $popupContent = $this->getContent();
1656
+ $parentTarget = $this->getTarget();
1657
+ $insidePopupShortcodes = self::collectInsidePopupShortcodes($popupContent);
1658
+ if (empty($insidePopupShortcodes)) {
1659
+ return $popups;
1660
+ }
1661
+ foreach ($insidePopupShortcodes as $insidePopupId => $insidePopupShortcode) {
1662
+ $insidePopupId = (int)$insidePopupId;
1663
+ if (!$insidePopupId) {
1664
+ continue;
1665
+ }
1666
+ // true = find inside popup
1667
+ $insidePopup = self::find($insidePopupId, $args);
1668
+ if (empty($insidePopup) || $insidePopup == 'trash' || $insidePopup == 'inherit') {
1669
+ continue;
1670
+ }
1671
+ $events = array('insideclick');
1672
+ $insidePopup->setEvents($events);
1673
+ $popups[$insidePopupId] = $insidePopup;
1674
+ }
1675
+
1676
+ $popupContent = self::doInsideShortcode($popupContent);
1677
+ $this->setContent($popupContent);
1678
+
1679
+ return $popups;
1680
+ }
1681
+
1682
+ public function getPopupOpeningCountById($popupId)
1683
+ {
1684
+ global $wpdb;
1685
+
1686
+ $allCount = 0;
1687
+ $popupsCounterData = get_option('SgpbCounter');
1688
+ $popupCountFromAnalyticsData = 0;
1689
+ $tableName = $wpdb->prefix.'sgpb_analytics';
1690
+ if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
1691
+ $popupCountFromAnalyticsData = self::getAnalyticsDataByPopupId($popupId);
1692
+ }
1693
+ if (isset($popupsCounterData[$popupId])) {
1694
+ $allCount += $popupsCounterData[$popupId];
1695
+ }
1696
+ $allCount += $popupCountFromAnalyticsData;
1697
+
1698
+ return $allCount;
1699
+ }
1700
+
1701
+ public static function getAnalyticsDataByPopupId($popupId)
1702
+ {
1703
+ global $wpdb;
1704
+ // 7, 12, 13 => exclude close, subscription success, contact success events
1705
+ $stmt = $wpdb->prepare('SELECT COUNT(*) FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
1706
+ $popupAnalyticsData = $wpdb->get_var($stmt);
1707
+ return $popupAnalyticsData;
1708
+ }
1709
+
1710
+ public static function deleteAnalyticsDataByPopupId($popupId)
1711
+ {
1712
+ global $wpdb;
1713
+ $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13) LIMIT 100', $popupId);
1714
+ $wpdb->query($prepareSql);
1715
+ }
1716
+
1717
+ public static function getActivePopupsQueryString()
1718
+ {
1719
+ $activePopupsQuery = '';
1720
+ $args = array(
1721
+ 'post_type' => SG_POPUP_POST_TYPE,
1722
+ 'post_status' => array('trash', 'publish')
1723
+ );
1724
+ if (!class_exists('ConfigDataHelper')) {
1725
+ return $activePopupsQuery;
1726
+ }
1727
+ $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1728
+ $args['checkActivePopupType'] = true;
1729
+ $allPopups = $allPostData->posts;
1730
+ foreach ($allPopups as $post) {
1731
+ $id = $post->ID;
1732
+ $popup = self::find($id, $args);
1733
+ if (empty($popup)) {
1734
+ $activePopupsQuery .= $id.', ';
1735
+ }
1736
+ }
1737
+ if ($activePopupsQuery != '') {
1738
+ $activePopupsQuery = ' AND ID NOT IN ('.$activePopupsQuery.')';
1739
+ $activePopupsQuery = str_replace(', )', ') ', $activePopupsQuery);
1740
+ }
1741
+
1742
+ return $activePopupsQuery;
1743
+ }
1744
+
1745
+ public function isActive()
1746
+ {
1747
+ return $this->getOptionValue('sgpb-is-active', true);
1748
+ }
1749
+ }
com/classes/popups/SubscriptionPopup.php CHANGED
@@ -1,688 +1,688 @@
1
- <?php
2
- namespace sgpb;
3
- require_once(dirname(__FILE__).'/SGPopup.php');
4
- require_once(ABSPATH.'wp-admin/includes/plugin.php');
5
-
6
- class SubscriptionPopup extends SGPopup
7
- {
8
- private $data;
9
- private $formContent = '';
10
-
11
- public function __construct()
12
- {
13
- add_filter('sgpbPopupRenderOptions', array($this, 'renderOptions'), 12, 1);
14
- add_filter('sgpbAdminJsFiles', array($this, 'adminJsFilter'), 1, 1);
15
- add_filter('sgpbAdminCssFiles', array($this, 'adminCssFilter'), 1, 1);
16
- add_filter('sgpbSubscriptionForm', array($this, 'subscriptionForm'), 1, 1);
17
- }
18
-
19
- private function frontendFilters()
20
- {
21
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
22
-
23
- if (!$isSubscriptionPlusActive) {
24
- add_filter('sgpbFrontendJsFiles', array($this, 'frontJsFilter'), 1, 1);
25
- }
26
- add_filter('sgpbFrontendCssFiles', array($this, 'frontCssFilter'), 1, 1);
27
- }
28
-
29
- public function setData($data)
30
- {
31
- $this->data = $data;
32
- }
33
-
34
- public function getData()
35
- {
36
- return $this->data;
37
- }
38
-
39
- public function setFormContent($formContent)
40
- {
41
- $this->formContent = $formContent;
42
- }
43
-
44
- public function getFormContent()
45
- {
46
- return $this->formContent;
47
- }
48
-
49
- public static function getTablesSql()
50
- {
51
- $tablesSql = array();
52
- $dbEngine = Functions::getDatabaseEngine();
53
-
54
- $tablesSql[] = SGPB_SUBSCRIBERS_TABLE_NAME.' (
55
- `id` int(12) NOT NULL AUTO_INCREMENT,
56
- `firstName` varchar(255),
57
- `lastName` varchar(255),
58
- `email` varchar(255),
59
- `subscriptionType` int(12),
60
- `cDate` date,
61
- `status` varchar(255),
62
- `unsubscribed` int(11) default 0,
63
- PRIMARY KEY (id)
64
- ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;';
65
-
66
- $tablesSql[] = SGPB_SUBSCRIBERS_ERROR_TABLE_NAME.' (
67
- `id` int(12) NOT NULL AUTO_INCREMENT,
68
- `firstName` varchar(255),
69
- `popupType` varchar(255),
70
- `email` varchar(255),
71
- `date` varchar(255),
72
- PRIMARY KEY (id)
73
- ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;';
74
-
75
- return $tablesSql;
76
- }
77
-
78
- /**
79
- * Return Subscription popup type need all table names
80
- *
81
- * @since 1.0.0
82
- *
83
- * @return array $table names
84
- *
85
- */
86
- public static function getTableNames()
87
- {
88
- $tableNames = array(
89
- SGPB_SUBSCRIBERS_TABLE_NAME,
90
- SGPB_SUBSCRIBERS_ERROR_TABLE_NAME
91
- );
92
-
93
- return $tableNames;
94
- }
95
-
96
- public function frontJsFilter($jsFiles)
97
- {
98
- $jsFiles[] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Subscription.js');
99
- $jsFiles[] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Validate.js');
100
-
101
- return $jsFiles;
102
- }
103
-
104
- public function adminJsFilter($jsFiles)
105
- {
106
- $jsFiles[] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Subscription.js');
107
-
108
- return $jsFiles;
109
- }
110
-
111
- public function adminCssFilter($cssFiles)
112
- {
113
- $cssFiles[] = array(
114
- 'folderUrl' => SG_POPUP_CSS_URL,
115
- 'filename' => 'ResetFormStyle.css'
116
- );
117
- $cssFiles[] = array(
118
- 'folderUrl' => SG_POPUP_CSS_URL,
119
- 'filename' => 'SubscriptionForm.css'
120
- );
121
-
122
- return $cssFiles;
123
- }
124
-
125
- public function frontCssFilter($cssFiles)
126
- {
127
- $cssFiles[] = array(
128
- 'folderUrl' => SG_POPUP_CSS_URL,
129
- 'filename' => 'ResetFormStyle.css',
130
- 'inFooter' => true
131
- );
132
- $cssFiles[] = array(
133
- 'folderUrl' => SG_POPUP_CSS_URL,
134
- 'filename' => 'SubscriptionForm.css',
135
- 'inFooter' => true
136
- );
137
-
138
- return $cssFiles;
139
- }
140
-
141
- public function addAdditionalSettings($postData = array(), $obj = null)
142
- {
143
- $this->setData($postData);
144
- $this->setPostData($postData);
145
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
146
-
147
- if (!$isSubscriptionPlusActive) {
148
- $postData['sgpb-subs-fields'] = $this->createFormFieldsData();
149
- }
150
-
151
- return $postData;
152
- }
153
-
154
- public function setSubsFormData($formId)
155
- {
156
- $savedData = array();
157
-
158
- if (!empty($formId)) {
159
- $savedData = SGPopup::getSavedData($formId);
160
- }
161
-
162
- $this->setData($savedData);
163
- }
164
-
165
- private function getFieldValue($optionName)
166
- {
167
- $optionValue = '';
168
- $postData = $this->getPostData();
169
-
170
- if (!empty($postData[$optionName])) {
171
- return $postData[$optionName];
172
- }
173
-
174
- $defaultData = $this->getDefaultDataByName($optionName);
175
-
176
- // when Saved data does not exist we try find inside default values
177
- if (empty($postData) && !empty($defaultData)) {
178
- return $defaultData['defaultValue'];
179
- }
180
-
181
- return $optionValue;
182
- }
183
-
184
- /**
185
- * Create form fields data
186
- *
187
- * @since 1.0.0
188
- *
189
- * @return array $formData
190
- */
191
- public function createFormFieldsData()
192
- {
193
- $formData = array();
194
- $inputStyles = array();
195
- $submitStyles = array();
196
- $emailPlaceholder = $this->getFieldValue('sgpb-subs-email-placeholder');
197
- if ($this->getFieldValue('sgpb-subs-text-width')) {
198
- $inputWidth = $this->getFieldValue('sgpb-subs-text-width');
199
- $inputStyles['width'] = AdminHelper::getCSSSafeSize($inputWidth);
200
- }
201
- if ($this->getFieldValue('sgpb-subs-text-height')) {
202
- $inputHeight = $this->getFieldValue('sgpb-subs-text-height');
203
- $inputStyles['height'] = AdminHelper::getCSSSafeSize($inputHeight);
204
- }
205
- if ($this->getFieldValue('sgpb-subs-text-border-width')) {
206
- $inputBorderWidth = $this->getFieldValue('sgpb-subs-text-border-width');
207
- $inputStyles['border-width'] = AdminHelper::getCSSSafeSize($inputBorderWidth);
208
- }
209
- if ($this->getFieldValue('sgpb-subs-text-border-color')) {
210
- $inputStyles['border-color'] = $this->getFieldValue('sgpb-subs-text-border-color');
211
- }
212
- if ($this->getFieldValue('sgpb-subs-text-bg-color')) {
213
- $inputStyles['background-color'] = $this->getFieldValue('sgpb-subs-text-bg-color');
214
- }
215
- if ($this->getFieldValue('sgpb-subs-text-color')) {
216
- $inputStyles['color'] = $this->getFieldValue('sgpb-subs-text-color');
217
- }
218
- $inputStyles['autocomplete'] = 'off';
219
-
220
- if ($this->getFieldValue('sgpb-subs-btn-width')) {
221
- $submitWidth = $this->getFieldValue('sgpb-subs-btn-width');
222
- $submitStyles['width'] = AdminHelper::getCSSSafeSize($submitWidth);
223
- }
224
- if ($this->getFieldValue('sgpb-subs-btn-height')) {
225
- $submitHeight = $this->getFieldValue('sgpb-subs-btn-height');
226
- $submitStyles['height'] = AdminHelper::getCSSSafeSize($submitHeight);
227
- }
228
- if ($this->getFieldValue('sgpb-subs-btn-bg-color')) {
229
- $submitStyles['background-color'] = $this->getFieldValue('sgpb-subs-btn-bg-color').' !important';
230
- }
231
- if ($this->getFieldValue('sgpb-subs-btn-text-color')) {
232
- $submitStyles['color'] = $this->getFieldValue('sgpb-subs-btn-text-color');
233
- }
234
- if ($this->getFieldValue('sgpb-subs-btn-border-radius')) {
235
- $submitStyles['border-radius'] = AdminHelper::getCSSSafeSize($this->getFieldValue('sgpb-subs-btn-border-radius')).' !important';
236
- }
237
- if ($this->getFieldValue('sgpb-subs-btn-border-width')) {
238
- $submitStyles['border-width'] = AdminHelper::getCSSSafeSize($this->getFieldValue('sgpb-subs-btn-border-width')).' !important';
239
- }
240
- if ($this->getFieldValue('sgpb-subs-btn-border-color')) {
241
- $submitStyles['border-color'] = $this->getFieldValue('sgpb-subs-btn-border-color').' !important';
242
- }
243
- $submitStyles['text-transform'] = 'none !important';
244
- $submitStyles['border-style'] = 'solid';
245
-
246
- $formData['email'] = array(
247
- 'isShow' => true,
248
- 'attrs' => array(
249
- 'type' => 'email',
250
- 'data-required' => true,
251
- 'name' => 'sgpb-subs-email',
252
- 'placeholder' => $emailPlaceholder,
253
- 'class' => 'js-subs-text-inputs js-subs-email-input',
254
- 'data-error-message-class' => 'sgpb-subs-email-error-message'
255
- ),
256
- 'style' => $inputStyles,
257
- 'errorMessageBoxStyles' => isset($inputStyles["width"]) ?$inputStyles["width"] : ''
258
- );
259
-
260
- $firstNamePlaceholder = $this->getFieldValue('sgpb-subs-first-placeholder');
261
- $firstNameRequired = $this->getOptionValueFromSavedData('sgpb-subs-first-name-required');
262
- $firstNameRequired = (!empty($firstNameRequired)) ? true : false;
263
- $isShow = ($this->getFieldValue('sgpb-subs-first-name-status')) ? true : false;
264
-
265
- $formData['first-name'] = array(
266
- 'isShow' => $isShow,
267
- 'attrs' => array(
268
- 'type' => 'text',
269
- 'data-required' => $firstNameRequired,
270
- 'name' => 'sgpb-subs-first-name',
271
- 'placeholder' => $firstNamePlaceholder,
272
- 'class' => 'js-subs-text-inputs js-subs-first-name-input',
273
- 'data-error-message-class' => 'sgpb-subs-first-name-error-message'
274
- ),
275
- 'style' => $inputStyles,
276
- 'errorMessageBoxStyles' => isset($inputStyles['width']) ? $inputStyles['width'] : ''
277
- );
278
-
279
- $lastNamePlaceholder = $this->getFieldValue('sgpb-subs-last-placeholder');
280
- $lastNameRequired = $this->getOptionValueFromSavedData('sgpb-subs-last-name-required');
281
- $lastNameRequired = (!empty($lastNameRequired)) ? true : false;
282
- $isShow = ($this->getFieldValue('sgpb-subs-last-name-status')) ? true : false;
283
-
284
- $formData['last-name'] = array(
285
- 'isShow' => $isShow,
286
- 'attrs' => array(
287
- 'type' => 'text',
288
- 'data-required' => $lastNameRequired,
289
- 'name' => 'sgpb-subs-last-name',
290
- 'placeholder' => $lastNamePlaceholder,
291
- 'class' => 'js-subs-text-inputs js-subs-last-name-input',
292
- 'data-error-message-class' => 'sgpb-subs-last-name-error-message'
293
- ),
294
- 'style' => $inputStyles,
295
- 'errorMessageBoxStyles' => isset($inputStyles['width']) ? $inputStyles['width'] : ''
296
- );
297
-
298
- /* GDPR checkbox */
299
- $gdprLabel = $this->getOptionValueFromSavedData('sgpb-subs-gdpr-label');
300
- $gdprRequired = ($this->getOptionValueFromSavedData('sgpb-subs-gdpr-status')) ? true : false;
301
- $isShow = ($this->getOptionValueFromSavedData('sgpb-subs-gdpr-status')) ? true : false;
302
-
303
- $formData['gdpr'] = array(
304
- 'isShow' => $isShow,
305
- 'attrs' => array(
306
- 'type' => 'customCheckbox',
307
- 'data-required' => $gdprRequired,
308
- 'name' => 'sgpb-subs-gdpr',
309
- 'class' => 'js-subs-gdpr-inputs js-subs-gdpr-label',
310
- 'id' => 'sgpb-gdpr-field-label',
311
- 'data-error-message-class' => 'sgpb-gdpr-error-message'
312
- ),
313
- 'style' => array('width' => isset($inputWidth)? $inputWidth :''),
314
- 'label' => $gdprLabel,
315
- 'text' => $this->getFieldValue('sgpb-subs-gdpr-text'),
316
- 'errorMessageBoxStyles' => isset($inputStyles['width'])?$inputStyles['width']:''
317
- );
318
- /* GDPR checkbox */
319
-
320
- $hiddenChecker['position'] = 'absolute';
321
- // For protected bots and spams
322
- $hiddenChecker['left'] = '-5000px';
323
- $hiddenChecker['padding'] = '0';
324
- $formData['hidden-checker'] = array(
325
- 'isShow' => false,
326
- 'attrs' => array(
327
- 'type' => 'hidden',
328
- 'data-required' => false,
329
- 'name' => 'sgpb-subs-hidden-checker',
330
- 'value' => '',
331
- 'class' => 'js-subs-text-inputs js-subs-last-name-input'
332
- ),
333
- 'style' => $hiddenChecker
334
- );
335
-
336
- $submitTitle = $this->getFieldValue('sgpb-subs-btn-title');
337
- $progressTitle = $this->getFieldValue('sgpb-subs-btn-progress-title');
338
- $formData['submit'] = array(
339
- 'isShow' => true,
340
- 'attrs' => array(
341
- 'type' => 'submit',
342
- 'name' => 'sgpb-subs-submit',
343
- 'value' => $submitTitle,
344
- 'data-title' => $submitTitle,
345
- 'data-progress-title' => $progressTitle,
346
- 'class' => 'js-subs-submit-btn'
347
- ),
348
- 'style' => $submitStyles
349
- );
350
-
351
- return $formData;
352
- }
353
-
354
- /**
355
- * Create validation obj for jQuery validate
356
- *
357
- * @since 1.0.0
358
- *
359
- * @param array $subsFields
360
- * @param array $validationMessages
361
- *
362
- * @return string
363
- */
364
- private function createValidateObj($subsFields, $validationMessages)
365
- {
366
- $validateObj = '';
367
- $id = $this->getId();
368
- $requiredMessage = $this->getOptionValue('sgpb-subs-validation-message');
369
- $emailMessage = $this->getOptionValue('sgpb-subs-invalid-message');
370
-
371
- if (empty($subsFields)) {
372
- return $validateObj;
373
- }
374
-
375
- if (empty($emailMessage)) {
376
- $emailMessage = SGPB_SUBSCRIPTION_EMAIL_MESSAGE;
377
- }
378
-
379
- if (empty($requiredMessage)) {
380
- $requiredMessage = SGPB_SUBSCRIPTION_VALIDATION_MESSAGE;
381
- }
382
-
383
- $rules = 'rules: { ';
384
- $messages = 'messages: { ';
385
-
386
- $validateObj = 'var sgpbSubsValidateObj'.$id.' = { ';
387
- foreach ($subsFields as $subsField) {
388
-
389
- if (empty($subsField['attrs'])) {
390
- continue;
391
- }
392
-
393
- $attrs = $subsField['attrs'];
394
- $type = 'text';
395
- $name = '';
396
- $required = false;
397
-
398
- if (!empty($attrs['type'])) {
399
- $type = $attrs['type'];
400
- }
401
- if (!empty($attrs['name'])) {
402
- $name = $attrs['name'];
403
- }
404
- if (!empty($attrs['data-required'])) {
405
- $required = $attrs['data-required'];
406
- }
407
-
408
- if ($type == 'email') {
409
- $rules .= '"'.$name.'": {required: true, email: true},';
410
- $messages .= '"'.$name.'": {
411
- "required": "'.$requiredMessage.'",
412
- "email": "'.$emailMessage.'"
413
- },';
414
- continue;
415
- }
416
-
417
- if (!$required) {
418
- continue;
419
- }
420
-
421
- $messages .= '"'.$name.'": "'.$requiredMessage.'",';
422
- $rules .= '"'.$name.'" : "required",';
423
-
424
- }
425
- $rules = rtrim($rules, ',');
426
- $messages = rtrim($messages, ',');
427
-
428
- $rules .= '},';
429
- $messages .= '}';
430
-
431
- $validateObj .= $rules;
432
- $validateObj .= $messages;
433
-
434
- $validateObj .= '};';
435
-
436
- return $validateObj;
437
- }
438
-
439
- private function getSubscriptionValidationScripts($validateObj)
440
- {
441
- $script = '<script type="text/javascript">';
442
- $script .= $validateObj;
443
- $script .= '</script>';
444
-
445
- return $script;
446
- }
447
-
448
- public function getFormCustomStyles($styleData)
449
- {
450
- $placeholderColor = $styleData['placeholderColor'];
451
- $formBackgroundColor = $this->getFieldValue('sgpb-subs-form-bg-color');
452
- $formPadding = $this->getFieldValue('sgpb-subs-form-padding');
453
- $formBackgroundOpacity = $this->getFieldValue('sgpb-subs-form-bg-opacity');
454
- $popupId = $this->getId();
455
- if (isset($styleData['formBackgroundOpacity'])) {
456
- $formBackgroundOpacity = $styleData['formBackgroundOpacity'];
457
- }
458
- if (isset($styleData['formColor'])) {
459
- $formBackgroundColor = $styleData['formColor'];
460
- }
461
- if (isset($styleData['formPadding'])) {
462
- $formPadding = $styleData['formPadding'];
463
- }
464
- $formBackgroundColor = AdminHelper::hexToRgba($formBackgroundColor, $formBackgroundOpacity);
465
-
466
- ob_start();
467
- ?>
468
- <style type="text/css">
469
- .sgpb-subs-form-<?php echo $popupId; ?> {background-color: <?php echo $formBackgroundColor; ?>;padding: <?php echo $formPadding.'px'; ?>}
470
- .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs::-webkit-input-placeholder {color: <?php echo $placeholderColor; ?>;font-weight: lighter;}
471
- .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs::-moz-placeholder {color:<?php echo $placeholderColor; ?>;font-weight: lighter;}
472
- .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs:-ms-input-placeholder {color:<?php echo $placeholderColor; ?>;font-weight: lighter;} /* ie */
473
- .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs:-moz-placeholder {color:<?php echo $placeholderColor; ?>;font-weight: lighter;}
474
- .sgpb-subs-form-<?php echo $popupId; ?> input[type="checkbox"] {-webkit-appearance: checkbox;!important}
475
- .sgpb-subs-form-<?php echo $popupId; ?> input[type="checkbox"]:before {content: none!important; }
476
- </style>
477
- <?php
478
- $styles = ob_get_contents();
479
- ob_get_clean();
480
-
481
- return $styles;
482
- }
483
-
484
- public function getOptionValue($optionName, $forceDefaultValue = false)
485
- {
486
- return parent::getOptionValue($optionName, $forceDefaultValue);
487
- }
488
-
489
- public function getPopupTypeOptionsView()
490
- {
491
- $optionsViewData = array(
492
- 'filePath' => SG_POPUP_TYPE_OPTIONS_PATH . 'subscription.php',
493
- 'metaboxTitle' => 'Subscription Settings',
494
- 'short_description' => 'Create subscription form, customize the fields and styles'
495
- );
496
-
497
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
498
-
499
- if ($isSubscriptionPlusActive) {
500
- return array();
501
- }
502
-
503
- return $optionsViewData;
504
- }
505
-
506
- private function getSubscriptionForm($subsFields)
507
- {
508
- $popupId = $this->getId();
509
- $form = '<div class="sgpb-subs-form-'.$popupId.' sgpb-subscription-form">';
510
- $form .= $this->getFormMessages();
511
- $form .= Functions::renderForm($subsFields);
512
- $form .= '</div>';
513
-
514
- return $form;
515
- }
516
-
517
- private function getFormMessages()
518
- {
519
- $successMessage = $this->getOptionValue('sgpb-subs-success-message');
520
- $errorMessage = $this->getOptionValue('sgpb-subs-error-message');
521
- if (empty($errorMessage)) {
522
- $errorMessage = SGPB_SUBSCRIPTION_ERROR_MESSAGE;
523
- }
524
- ob_start();
525
- ?>
526
- <div class="subs-form-messages sgpb-alert sgpb-alert-success sg-hide-element">
527
- <p><?php echo $successMessage; ?></p>
528
- </div>
529
- <div class="subs-form-messages sgpb-alert sgpb-alert-danger sg-hide-element">
530
- <p><?php echo $errorMessage; ?></p>
531
- </div>
532
- <?php
533
- $messages = ob_get_contents();
534
- ob_end_clean();
535
-
536
- return $messages;
537
- }
538
-
539
- public function renderOptions($options)
540
- {
541
- // for old popups
542
- if (isset($options['sgpb-subs-success-popup']) && function_exists('sgpb\sgpGetCorrectPopupId')) {
543
- $options['sgpb-subs-success-popup'] = sgpGetCorrectPopupId($options['sgpb-subs-success-popup']);
544
- }
545
-
546
- return $options;
547
- }
548
-
549
- public function getPopupTypeContent()
550
- {
551
- $this->frontendFilters();
552
-
553
- apply_filters('sgpbSubscriptionForm', $this);
554
- $popupContent = $this->getContent();
555
- $formContent = $this->getFormContent();
556
- $showToTop = $this->getOptionValue('sgpb-subs-show-form-to-top');
557
- $content = $popupContent.$formContent;
558
-
559
- if ($showToTop) {
560
- $content = $formContent.$popupContent;
561
- }
562
- return $content;
563
- }
564
-
565
- public function subscriptionForm($popupObj)
566
- {
567
- if (!is_object($popupObj)) {
568
- return '';
569
- }
570
- $popupContent = '';
571
- $popupOptions = $popupObj->getOptions();
572
- $subsFields = $popupObj->getOptionValue('sgpb-subs-fields');
573
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
574
-
575
- if (empty($subsFields) || !$isSubscriptionPlusActive) {
576
- $subsFields = $popupObj->createFormFieldsData();
577
- }
578
-
579
- $subsRequiredMessages = '';
580
- if (!empty($popupOptions['sgpb-subs-validation-message'])) {
581
- $subsRequiredMessages = $popupOptions['sgpb-subs-validation-message'];
582
- }
583
-
584
- $validationMessages = array(
585
- 'requiredMessage' => $subsRequiredMessages
586
- );
587
-
588
- $styleData = array(
589
- 'placeholderColor' => $popupOptions['sgpb-subs-text-placeholder-color'],
590
- 'formColor' => $popupOptions['sgpb-subs-form-bg-color'],
591
- 'formPadding' => isset($popupOptions['sgpb-subs-form-padding'])?$popupOptions['sgpb-subs-form-padding']:'',
592
- 'formBackgroundOpacity' => isset($popupOptions['sgpb-subs-form-bg-opacity'])?$popupOptions['sgpb-subs-form-bg-opacity']:''
593
- );
594
-
595
- $validateScript = $popupObj->createValidateObj($subsFields, $validationMessages);
596
- $popupContent .= $popupObj->getSubscriptionForm($subsFields);
597
- $popupContent .= $popupObj->getSubscriptionValidationScripts($validateScript);
598
- $popupContent .= $popupObj->getFormCustomStyles($styleData);
599
-
600
- $popupObj->setFormContent($popupContent);
601
-
602
- return $popupObj;
603
- }
604
-
605
- public function getSubPopupObj()
606
- {
607
- $options = $this->getOptions();
608
- $subPopups = parent::getSubPopupObj();
609
- if ($options['sgpb-subs-success-behavior'] == 'openPopup') {
610
- $subPopupId = (!empty($options['sgpb-subs-success-popup'])) ? (int)$options['sgpb-subs-success-popup']: null;
611
-
612
- if (empty($subPopupId)) {
613
- return $subPopups;
614
- }
615
-
616
- // for old popups
617
- if (function_exists('sgpb\sgpGetCorrectPopupId')) {
618
- $subPopupId = sgpGetCorrectPopupId($subPopupId);
619
- }
620
-
621
- $subPopupObj = SGPopup::find($subPopupId);
622
- if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
623
- // We remove all events because this popup will be open after successful subscription
624
- $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
625
- $subPopups[] = $subPopupObj;
626
- }
627
- }
628
-
629
- return $subPopups;
630
- }
631
-
632
- public function getExtraRenderOptions()
633
- {
634
- return array();
635
- }
636
-
637
- public static function getSubscribersCount()
638
- {
639
- global $wpdb;
640
- $count = $wpdb->get_var('SELECT COUNT(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME);
641
-
642
- return (int)$count;
643
- }
644
-
645
- public static function getAllSubscriptions()
646
- {
647
- $popupArgs = array();
648
- $popupArgs['type'][] = 'subscription';
649
-
650
- $popupArgs = apply_filters('sgpbGetAllSubscriptionArgs', $popupArgs);
651
- $allPopups = SGPopup::getAllPopups($popupArgs);
652
-
653
- return $allPopups;
654
- }
655
-
656
- public static function getAllSubscriptionForms()
657
- {
658
- $subsFormList = array();
659
- $subscriptionForms = self::getAllSubscriptions();
660
-
661
- foreach ($subscriptionForms as $subscriptionForm) {
662
- $title = $subscriptionForm->getTitle();
663
- $id = $subscriptionForm->getId();
664
- if ($title == '') {
665
- $title = '('.__('no title', SG_POPUP_TEXT_DOMAIN).')';
666
- }
667
- $subsFormList[$id] = $title;
668
- }
669
-
670
- return $subsFormList;
671
- }
672
-
673
- public static function getAllSubscribersDate()
674
- {
675
- $subsDateList = array();
676
- global $wpdb;
677
- $subscriptionPopups = $wpdb->get_results('SELECT id, cDate FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME, ARRAY_A);
678
-
679
- foreach ($subscriptionPopups as $subscriptionForm) {
680
- $id = $subscriptionForm['id'];
681
- $date = substr($subscriptionForm['cDate'], 0, 7);
682
- $subsDateList[$id]['date-value'] = $date;
683
- $subsDateList[$id]['date-title'] = AdminHelper::getFormattedDate($date);
684
- }
685
-
686
- return $subsDateList;
687
- }
688
- }
1
+ <?php
2
+ namespace sgpb;
3
+ require_once(dirname(__FILE__).'/SGPopup.php');
4
+ require_once(ABSPATH.'wp-admin/includes/plugin.php');
5
+
6
+ class SubscriptionPopup extends SGPopup
7
+ {
8
+ private $data;
9
+ private $formContent = '';
10
+
11
+ public function __construct()
12
+ {
13
+ add_filter('sgpbPopupRenderOptions', array($this, 'renderOptions'), 12, 1);
14
+ add_filter('sgpbAdminJsFiles', array($this, 'adminJsFilter'), 1, 1);
15
+ add_filter('sgpbAdminCssFiles', array($this, 'adminCssFilter'), 1, 1);
16
+ add_filter('sgpbSubscriptionForm', array($this, 'subscriptionForm'), 1, 1);
17
+ }
18
+
19
+ private function frontendFilters()
20
+ {
21
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
22
+
23
+ if (!$isSubscriptionPlusActive) {
24
+ add_filter('sgpbFrontendJsFiles', array($this, 'frontJsFilter'), 1, 1);
25
+ }
26
+ add_filter('sgpbFrontendCssFiles', array($this, 'frontCssFilter'), 1, 1);
27
+ }
28
+
29
+ public function setData($data)
30
+ {
31
+ $this->data = $data;
32
+ }
33
+
34
+ public function getData()
35
+ {
36
+ return $this->data;
37
+ }
38
+
39
+ public function setFormContent($formContent)
40
+ {
41
+ $this->formContent = $formContent;
42
+ }
43
+
44
+ public function getFormContent()
45
+ {
46
+ return $this->formContent;
47
+ }
48
+
49
+ public static function getTablesSql()
50
+ {
51
+ $tablesSql = array();
52
+ $dbEngine = Functions::getDatabaseEngine();
53
+
54
+ $tablesSql[] = SGPB_SUBSCRIBERS_TABLE_NAME.' (
55
+ `id` int(12) NOT NULL AUTO_INCREMENT,
56
+ `firstName` varchar(255),
57
+ `lastName` varchar(255),
58
+ `email` varchar(255),
59
+ `subscriptionType` int(12),
60
+ `cDate` date,
61
+ `status` varchar(255),
62
+ `unsubscribed` int(11) default 0,
63
+ PRIMARY KEY (id)
64
+ ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;';
65
+
66
+ $tablesSql[] = SGPB_SUBSCRIBERS_ERROR_TABLE_NAME.' (
67
+ `id` int(12) NOT NULL AUTO_INCREMENT,
68
+ `firstName` varchar(255),
69
+ `popupType` varchar(255),
70
+ `email` varchar(255),
71
+ `date` varchar(255),
72
+ PRIMARY KEY (id)
73
+ ) ENGINE='.$dbEngine.' DEFAULT CHARSET=utf8;';
74
+
75
+ return $tablesSql;
76
+ }
77
+
78
+ /**
79
+ * Return Subscription popup type need all table names
80
+ *
81
+ * @since 1.0.0
82
+ *
83
+ * @return array $table names
84
+ *
85
+ */
86
+ public static function getTableNames()
87
+ {
88
+ $tableNames = array(
89
+ SGPB_SUBSCRIBERS_TABLE_NAME,
90
+ SGPB_SUBSCRIBERS_ERROR_TABLE_NAME
91
+ );
92
+
93
+ return $tableNames;
94
+ }
95
+
96
+ public function frontJsFilter($jsFiles)
97
+ {
98
+ $jsFiles[] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Subscription.js');
99
+ $jsFiles[] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Validate.js');
100
+
101
+ return $jsFiles;
102
+ }
103
+
104
+ public function adminJsFilter($jsFiles)
105
+ {
106
+ $jsFiles[] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Subscription.js');
107
+
108
+ return $jsFiles;
109
+ }
110
+
111
+ public function adminCssFilter($cssFiles)
112
+ {
113
+ $cssFiles[] = array(
114
+ 'folderUrl' => SG_POPUP_CSS_URL,
115
+ 'filename' => 'ResetFormStyle.css'
116
+ );
117
+ $cssFiles[] = array(
118
+ 'folderUrl' => SG_POPUP_CSS_URL,
119
+ 'filename' => 'SubscriptionForm.css'
120
+ );
121
+
122
+ return $cssFiles;
123
+ }
124
+
125
+ public function frontCssFilter($cssFiles)
126
+ {
127
+ $cssFiles[] = array(
128
+ 'folderUrl' => SG_POPUP_CSS_URL,
129
+ 'filename' => 'ResetFormStyle.css',
130
+ 'inFooter' => true
131
+ );
132
+ $cssFiles[] = array(
133
+ 'folderUrl' => SG_POPUP_CSS_URL,
134
+ 'filename' => 'SubscriptionForm.css',
135
+ 'inFooter' => true
136
+ );
137
+
138
+ return $cssFiles;
139
+ }
140
+
141
+ public function addAdditionalSettings($postData = array(), $obj = null)
142
+ {
143
+ $this->setData($postData);
144
+ $this->setPostData($postData);
145
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
146
+
147
+ if (!$isSubscriptionPlusActive) {
148
+ $postData['sgpb-subs-fields'] = $this->createFormFieldsData();
149
+ }
150
+
151
+ return $postData;
152
+ }
153
+
154
+ public function setSubsFormData($formId)
155
+ {
156
+ $savedData = array();
157
+
158
+ if (!empty($formId)) {
159
+ $savedData = SGPopup::getSavedData($formId);
160
+ }
161
+
162
+ $this->setData($savedData);
163
+ }
164
+
165
+ private function getFieldValue($optionName)
166
+ {
167
+ $optionValue = '';
168
+ $postData = $this->getPostData();
169
+
170
+ if (!empty($postData[$optionName])) {
171
+ return $postData[$optionName];
172
+ }
173
+
174
+ $defaultData = $this->getDefaultDataByName($optionName);
175
+
176
+ // when Saved data does not exist we try find inside default values
177
+ if (empty($postData) && !empty($defaultData)) {
178
+ return $defaultData['defaultValue'];
179
+ }
180
+
181
+ return $optionValue;
182
+ }
183
+
184
+ /**
185
+ * Create form fields data
186
+ *
187
+ * @since 1.0.0
188
+ *
189
+ * @return array $formData
190
+ */
191
+ public function createFormFieldsData()
192
+ {
193
+ $formData = array();
194
+ $inputStyles = array();
195
+ $submitStyles = array();
196
+ $emailPlaceholder = $this->getFieldValue('sgpb-subs-email-placeholder');
197
+ if ($this->getFieldValue('sgpb-subs-text-width')) {
198
+ $inputWidth = $this->getFieldValue('sgpb-subs-text-width');
199
+ $inputStyles['width'] = AdminHelper::getCSSSafeSize($inputWidth);
200
+ }
201
+ if ($this->getFieldValue('sgpb-subs-text-height')) {
202
+ $inputHeight = $this->getFieldValue('sgpb-subs-text-height');
203
+ $inputStyles['height'] = AdminHelper::getCSSSafeSize($inputHeight);
204
+ }
205
+ if ($this->getFieldValue('sgpb-subs-text-border-width')) {
206
+ $inputBorderWidth = $this->getFieldValue('sgpb-subs-text-border-width');
207
+ $inputStyles['border-width'] = AdminHelper::getCSSSafeSize($inputBorderWidth);
208
+ }
209
+ if ($this->getFieldValue('sgpb-subs-text-border-color')) {
210
+ $inputStyles['border-color'] = $this->getFieldValue('sgpb-subs-text-border-color');
211
+ }
212
+ if ($this->getFieldValue('sgpb-subs-text-bg-color')) {
213
+ $inputStyles['background-color'] = $this->getFieldValue('sgpb-subs-text-bg-color');
214
+ }
215
+ if ($this->getFieldValue('sgpb-subs-text-color')) {
216
+ $inputStyles['color'] = $this->getFieldValue('sgpb-subs-text-color');
217
+ }
218
+ $inputStyles['autocomplete'] = 'off';
219
+
220
+ if ($this->getFieldValue('sgpb-subs-btn-width')) {
221
+ $submitWidth = $this->getFieldValue('sgpb-subs-btn-width');
222
+ $submitStyles['width'] = AdminHelper::getCSSSafeSize($submitWidth);
223
+ }
224
+ if ($this->getFieldValue('sgpb-subs-btn-height')) {
225
+ $submitHeight = $this->getFieldValue('sgpb-subs-btn-height');
226
+ $submitStyles['height'] = AdminHelper::getCSSSafeSize($submitHeight);
227
+ }
228
+ if ($this->getFieldValue('sgpb-subs-btn-bg-color')) {
229
+ $submitStyles['background-color'] = $this->getFieldValue('sgpb-subs-btn-bg-color').' !important';
230
+ }
231
+ if ($this->getFieldValue('sgpb-subs-btn-text-color')) {
232
+ $submitStyles['color'] = $this->getFieldValue('sgpb-subs-btn-text-color');
233
+ }
234
+ if ($this->getFieldValue('sgpb-subs-btn-border-radius')) {
235
+ $submitStyles['border-radius'] = AdminHelper::getCSSSafeSize($this->getFieldValue('sgpb-subs-btn-border-radius')).' !important';
236
+ }
237
+ if ($this->getFieldValue('sgpb-subs-btn-border-width')) {
238
+ $submitStyles['border-width'] = AdminHelper::getCSSSafeSize($this->getFieldValue('sgpb-subs-btn-border-width')).' !important';
239
+ }
240
+ if ($this->getFieldValue('sgpb-subs-btn-border-color')) {
241
+ $submitStyles['border-color'] = $this->getFieldValue('sgpb-subs-btn-border-color').' !important';
242
+ }
243
+ $submitStyles['text-transform'] = 'none !important';
244
+ $submitStyles['border-style'] = 'solid';
245
+
246
+ $formData['email'] = array(
247
+ 'isShow' => true,
248
+ 'attrs' => array(
249
+ 'type' => 'email',
250
+ 'data-required' => true,
251
+ 'name' => 'sgpb-subs-email',
252
+ 'placeholder' => $emailPlaceholder,
253
+ 'class' => 'js-subs-text-inputs js-subs-email-input',
254
+ 'data-error-message-class' => 'sgpb-subs-email-error-message'
255
+ ),
256
+ 'style' => $inputStyles,
257
+ 'errorMessageBoxStyles' => isset($inputStyles["width"]) ?$inputStyles["width"] : ''
258
+ );
259
+
260
+ $firstNamePlaceholder = $this->getFieldValue('sgpb-subs-first-placeholder');
261
+ $firstNameRequired = $this->getOptionValueFromSavedData('sgpb-subs-first-name-required');
262
+ $firstNameRequired = (!empty($firstNameRequired)) ? true : false;
263
+ $isShow = ($this->getFieldValue('sgpb-subs-first-name-status')) ? true : false;
264
+
265
+ $formData['first-name'] = array(
266
+ 'isShow' => $isShow,
267
+ 'attrs' => array(
268
+ 'type' => 'text',
269
+ 'data-required' => $firstNameRequired,
270
+ 'name' => 'sgpb-subs-first-name',
271
+ 'placeholder' => $firstNamePlaceholder,
272
+ 'class' => 'js-subs-text-inputs js-subs-first-name-input',
273
+ 'data-error-message-class' => 'sgpb-subs-first-name-error-message'
274
+ ),
275
+ 'style' => $inputStyles,
276
+ 'errorMessageBoxStyles' => isset($inputStyles['width']) ? $inputStyles['width'] : ''
277
+ );
278
+
279
+ $lastNamePlaceholder = $this->getFieldValue('sgpb-subs-last-placeholder');
280
+ $lastNameRequired = $this->getOptionValueFromSavedData('sgpb-subs-last-name-required');
281
+ $lastNameRequired = (!empty($lastNameRequired)) ? true : false;
282
+ $isShow = ($this->getFieldValue('sgpb-subs-last-name-status')) ? true : false;
283
+
284
+ $formData['last-name'] = array(
285
+ 'isShow' => $isShow,
286
+ 'attrs' => array(
287
+ 'type' => 'text',
288
+ 'data-required' => $lastNameRequired,
289
+ 'name' => 'sgpb-subs-last-name',
290
+ 'placeholder' => $lastNamePlaceholder,
291
+ 'class' => 'js-subs-text-inputs js-subs-last-name-input',
292
+ 'data-error-message-class' => 'sgpb-subs-last-name-error-message'
293
+ ),
294
+ 'style' => $inputStyles,
295
+ 'errorMessageBoxStyles' => isset($inputStyles['width']) ? $inputStyles['width'] : ''
296
+ );
297
+
298
+ /* GDPR checkbox */
299
+ $gdprLabel = $this->getOptionValueFromSavedData('sgpb-subs-gdpr-label');
300
+ $gdprRequired = ($this->getOptionValueFromSavedData('sgpb-subs-gdpr-status')) ? true : false;
301
+ $isShow = ($this->getOptionValueFromSavedData('sgpb-subs-gdpr-status')) ? true : false;
302
+
303
+ $formData['gdpr'] = array(
304
+ 'isShow' => $isShow,
305
+ 'attrs' => array(
306
+ 'type' => 'customCheckbox',
307
+ 'data-required' => $gdprRequired,
308
+ 'name' => 'sgpb-subs-gdpr',
309
+ 'class' => 'js-subs-gdpr-inputs js-subs-gdpr-label',
310
+ 'id' => 'sgpb-gdpr-field-label',
311
+ 'data-error-message-class' => 'sgpb-gdpr-error-message'
312
+ ),
313
+ 'style' => array('width' => isset($inputWidth)? $inputWidth :''),
314
+ 'label' => $gdprLabel,
315
+ 'text' => $this->getFieldValue('sgpb-subs-gdpr-text'),
316
+ 'errorMessageBoxStyles' => isset($inputStyles['width'])?$inputStyles['width']:''
317
+ );
318
+ /* GDPR checkbox */
319
+
320
+ $hiddenChecker['position'] = 'absolute';
321
+ // For protected bots and spams
322
+ $hiddenChecker['left'] = '-5000px';
323
+ $hiddenChecker['padding'] = '0';
324
+ $formData['hidden-checker'] = array(
325
+ 'isShow' => false,
326
+ 'attrs' => array(
327
+ 'type' => 'hidden',
328
+ 'data-required' => false,
329
+ 'name' => 'sgpb-subs-hidden-checker',
330
+ 'value' => '',
331
+ 'class' => 'js-subs-text-inputs js-subs-last-name-input'
332
+ ),
333
+ 'style' => $hiddenChecker
334
+ );
335
+
336
+ $submitTitle = $this->getFieldValue('sgpb-subs-btn-title');
337
+ $progressTitle = $this->getFieldValue('sgpb-subs-btn-progress-title');
338
+ $formData['submit'] = array(
339
+ 'isShow' => true,
340
+ 'attrs' => array(
341
+ 'type' => 'submit',
342
+ 'name' => 'sgpb-subs-submit',
343
+ 'value' => $submitTitle,
344
+ 'data-title' => $submitTitle,
345
+ 'data-progress-title' => $progressTitle,
346
+ 'class' => 'js-subs-submit-btn'
347
+ ),
348
+ 'style' => $submitStyles
349
+ );
350
+
351
+ return $formData;
352
+ }
353
+
354
+ /**
355
+ * Create validation obj for jQuery validate
356
+ *
357
+ * @since 1.0.0
358
+ *
359
+ * @param array $subsFields
360
+ * @param array $validationMessages
361
+ *
362
+ * @return string
363
+ */
364
+ private function createValidateObj($subsFields, $validationMessages)
365
+ {
366
+ $validateObj = '';
367
+ $id = $this->getId();
368
+ $requiredMessage = $this->getOptionValue('sgpb-subs-validation-message');
369
+ $emailMessage = $this->getOptionValue('sgpb-subs-invalid-message');
370
+
371
+ if (empty($subsFields)) {
372
+ return $validateObj;
373
+ }
374
+
375
+ if (empty($emailMessage)) {
376
+ $emailMessage = SGPB_SUBSCRIPTION_EMAIL_MESSAGE;
377
+ }
378
+
379
+ if (empty($requiredMessage)) {
380
+ $requiredMessage = SGPB_SUBSCRIPTION_VALIDATION_MESSAGE;
381
+ }
382
+
383
+ $rules = 'rules: { ';
384
+ $messages = 'messages: { ';
385
+
386
+ $validateObj = 'var sgpbSubsValidateObj'.$id.' = { ';
387
+ foreach ($subsFields as $subsField) {
388
+
389
+ if (empty($subsField['attrs'])) {
390
+ continue;
391
+ }
392
+
393
+ $attrs = $subsField['attrs'];
394
+ $type = 'text';
395
+ $name = '';
396
+ $required = false;
397
+
398
+ if (!empty($attrs['type'])) {
399
+ $type = $attrs['type'];
400
+ }
401
+ if (!empty($attrs['name'])) {
402
+ $name = $attrs['name'];
403
+ }
404
+ if (!empty($attrs['data-required'])) {
405
+ $required = $attrs['data-required'];
406
+ }
407
+
408
+ if ($type == 'email') {
409
+ $rules .= '"'.$name.'": {required: true, email: true},';
410
+ $messages .= '"'.$name.'": {
411
+ "required": "'.$requiredMessage.'",
412
+ "email": "'.$emailMessage.'"
413
+ },';
414
+ continue;
415
+ }
416
+
417
+ if (!$required) {
418
+ continue;
419
+ }
420
+
421
+ $messages .= '"'.$name.'": "'.$requiredMessage.'",';
422
+ $rules .= '"'.$name.'" : "required",';
423
+
424
+ }
425
+ $rules = rtrim($rules, ',');
426
+ $messages = rtrim($messages, ',');
427
+
428
+ $rules .= '},';
429
+ $messages .= '}';
430
+
431
+ $validateObj .= $rules;
432
+ $validateObj .= $messages;
433
+
434
+ $validateObj .= '};';
435
+
436
+ return $validateObj;
437
+ }
438
+
439
+ private function getSubscriptionValidationScripts($validateObj)
440
+ {
441
+ $script = '<script type="text/javascript">';
442
+ $script .= $validateObj;
443
+ $script .= '</script>';
444
+
445
+ return $script;
446
+ }
447
+
448
+ public function getFormCustomStyles($styleData)
449
+ {
450
+ $placeholderColor = $styleData['placeholderColor'];
451
+ $formBackgroundColor = $this->getFieldValue('sgpb-subs-form-bg-color');
452
+ $formPadding = $this->getFieldValue('sgpb-subs-form-padding');
453
+ $formBackgroundOpacity = $this->getFieldValue('sgpb-subs-form-bg-opacity');
454
+ $popupId = $this->getId();
455
+ if (isset($styleData['formBackgroundOpacity'])) {
456
+ $formBackgroundOpacity = $styleData['formBackgroundOpacity'];
457
+ }
458
+ if (isset($styleData['formColor'])) {
459
+ $formBackgroundColor = $styleData['formColor'];
460
+ }
461
+ if (isset($styleData['formPadding'])) {
462
+ $formPadding = $styleData['formPadding'];
463
+ }
464
+ $formBackgroundColor = AdminHelper::hexToRgba($formBackgroundColor, $formBackgroundOpacity);
465
+
466
+ ob_start();
467
+ ?>
468
+ <style type="text/css">
469
+ .sgpb-subs-form-<?php echo $popupId; ?> {background-color: <?php echo $formBackgroundColor; ?>;padding: <?php echo $formPadding.'px'; ?>}
470
+ .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs::-webkit-input-placeholder {color: <?php echo $placeholderColor; ?>;font-weight: lighter;}
471
+ .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs::-moz-placeholder {color:<?php echo $placeholderColor; ?>;font-weight: lighter;}
472
+ .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs:-ms-input-placeholder {color:<?php echo $placeholderColor; ?>;font-weight: lighter;} /* ie */
473
+ .sgpb-subs-form-<?php echo $popupId; ?> .js-subs-text-inputs:-moz-placeholder {color:<?php echo $placeholderColor; ?>;font-weight: lighter;}
474
+ .sgpb-subs-form-<?php echo $popupId; ?> input[type="checkbox"] {-webkit-appearance: checkbox;!important}
475
+ .sgpb-subs-form-<?php echo $popupId; ?> input[type="checkbox"]:before {content: none!important; }
476
+ </style>
477
+ <?php
478
+ $styles = ob_get_contents();
479
+ ob_get_clean();
480
+
481
+ return $styles;
482
+ }
483
+
484
+ public function getOptionValue($optionName, $forceDefaultValue = false)
485
+ {
486
+ return parent::getOptionValue($optionName, $forceDefaultValue);
487
+ }
488
+
489
+ public function getPopupTypeOptionsView()
490
+ {
491
+ $optionsViewData = array(
492
+ 'filePath' => SG_POPUP_TYPE_OPTIONS_PATH . 'subscription.php',
493
+ 'metaboxTitle' => 'Subscription Settings',
494
+ 'short_description' => 'Create subscription form, customize the fields and styles'
495
+ );
496
+
497
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
498
+
499
+ if ($isSubscriptionPlusActive) {
500
+ return array();
501
+ }
502
+
503
+ return $optionsViewData;
504
+ }
505
+
506
+ private function getSubscriptionForm($subsFields)
507
+ {
508
+ $popupId = $this->getId();
509
+ $form = '<div class="sgpb-subs-form-'.$popupId.' sgpb-subscription-form">';
510
+ $form .= $this->getFormMessages();
511
+ $form .= Functions::renderForm($subsFields);
512
+ $form .= '</div>';
513
+
514
+ return $form;
515
+ }
516
+
517
+ private function getFormMessages()
518
+ {
519
+ $successMessage = $this->getOptionValue('sgpb-subs-success-message');
520
+ $errorMessage = $this->getOptionValue('sgpb-subs-error-message');
521
+ if (empty($errorMessage)) {
522
+ $errorMessage = SGPB_SUBSCRIPTION_ERROR_MESSAGE;
523
+ }
524
+ ob_start();
525
+ ?>
526
+ <div class="subs-form-messages sgpb-alert sgpb-alert-success sg-hide-element">
527
+ <p><?php echo $successMessage; ?></p>
528
+ </div>
529
+ <div class="subs-form-messages sgpb-alert sgpb-alert-danger sg-hide-element">
530
+ <p><?php echo $errorMessage; ?></p>
531
+ </div>
532
+ <?php
533
+ $messages = ob_get_contents();
534
+ ob_end_clean();
535
+
536
+ return $messages;
537
+ }
538
+
539
+ public function renderOptions($options)
540
+ {
541
+ // for old popups
542
+ if (isset($options['sgpb-subs-success-popup']) && function_exists('sgpb\sgpGetCorrectPopupId')) {
543
+ $options['sgpb-subs-success-popup'] = sgpGetCorrectPopupId($options['sgpb-subs-success-popup']);
544
+ }
545
+
546
+ return $options;
547
+ }
548
+
549
+ public function getPopupTypeContent()
550
+ {
551
+ $this->frontendFilters();
552
+
553
+ apply_filters('sgpbSubscriptionForm', $this);
554
+ $popupContent = $this->getContent();
555
+ $formContent = $this->getFormContent();
556
+ $showToTop = $this->getOptionValue('sgpb-subs-show-form-to-top');
557
+ $content = $popupContent.$formContent;
558
+
559
+ if ($showToTop) {
560
+ $content = $formContent.$popupContent;
561
+ }
562
+ return $content;
563
+ }
564
+
565
+ public function subscriptionForm($popupObj)
566
+ {
567
+ if (!is_object($popupObj)) {
568
+ return '';
569
+ }
570
+ $popupContent = '';
571
+ $popupOptions = $popupObj->getOptions();
572
+ $subsFields = $popupObj->getOptionValue('sgpb-subs-fields');
573
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
574
+
575
+ if (empty($subsFields) || !$isSubscriptionPlusActive) {
576
+ $subsFields = $popupObj->createFormFieldsData();
577
+ }
578
+
579
+ $subsRequiredMessages = '';
580
+ if (!empty($popupOptions['sgpb-subs-validation-message'])) {
581
+ $subsRequiredMessages = $popupOptions['sgpb-subs-validation-message'];
582
+ }
583
+
584
+ $validationMessages = array(
585
+ 'requiredMessage' => $subsRequiredMessages
586
+ );
587
+
588
+ $styleData = array(
589
+ 'placeholderColor' => $popupOptions['sgpb-subs-text-placeholder-color'],
590
+ 'formColor' => $popupOptions['sgpb-subs-form-bg-color'],
591
+ 'formPadding' => isset($popupOptions['sgpb-subs-form-padding'])?$popupOptions['sgpb-subs-form-padding']:'',
592
+ 'formBackgroundOpacity' => isset($popupOptions['sgpb-subs-form-bg-opacity'])?$popupOptions['sgpb-subs-form-bg-opacity']:''
593
+ );
594
+
595
+ $validateScript = $popupObj->createValidateObj($subsFields, $validationMessages);
596
+ $popupContent .= $popupObj->getSubscriptionForm($subsFields);
597
+ $popupContent .= $popupObj->getSubscriptionValidationScripts($validateScript);
598
+ $popupContent .= $popupObj->getFormCustomStyles($styleData);
599
+
600
+ $popupObj->setFormContent($popupContent);
601
+
602
+ return $popupObj;
603
+ }
604
+
605
+ public function getSubPopupObj()
606
+ {
607
+ $options = $this->getOptions();
608
+ $subPopups = parent::getSubPopupObj();
609
+ if ($options['sgpb-subs-success-behavior'] == 'openPopup') {
610
+ $subPopupId = (!empty($options['sgpb-subs-success-popup'])) ? (int)$options['sgpb-subs-success-popup']: null;
611
+
612
+ if (empty($subPopupId)) {
613
+ return $subPopups;
614
+ }
615
+
616
+ // for old popups
617
+ if (function_exists('sgpb\sgpGetCorrectPopupId')) {
618
+ $subPopupId = sgpGetCorrectPopupId($subPopupId);
619
+ }
620
+
621
+ $subPopupObj = SGPopup::find($subPopupId);
622
+ if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
623
+ // We remove all events because this popup will be open after successful subscription
624
+ $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
625
+ $subPopups[] = $subPopupObj;
626
+ }
627
+ }
628
+
629
+ return $subPopups;
630
+ }
631
+
632
+ public function getExtraRenderOptions()
633
+ {
634
+ return array();
635
+ }
636
+
637
+ public static function getSubscribersCount()
638
+ {
639
+ global $wpdb;
640
+ $count = $wpdb->get_var('SELECT COUNT(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME);
641
+
642
+ return (int)$count;
643
+ }
644
+
645
+ public static function getAllSubscriptions()
646
+ {
647
+ $popupArgs = array();
648
+ $popupArgs['type'][] = 'subscription';
649
+
650
+ $popupArgs = apply_filters('sgpbGetAllSubscriptionArgs', $popupArgs);
651
+ $allPopups = SGPopup::getAllPopups($popupArgs);
652
+
653
+ return $allPopups;
654
+ }
655
+
656
+ public static function getAllSubscriptionForms()
657
+ {
658
+ $subsFormList = array();
659
+ $subscriptionForms = self::getAllSubscriptions();
660
+
661
+ foreach ($subscriptionForms as $subscriptionForm) {
662
+ $title = $subscriptionForm->getTitle();
663
+ $id = $subscriptionForm->getId();
664
+ if ($title == '') {
665
+ $title = '('.__('no title', SG_POPUP_TEXT_DOMAIN).')';
666
+ }
667
+ $subsFormList[$id] = $title;
668
+ }
669
+
670
+ return $subsFormList;
671
+ }
672
+
673
+ public static function getAllSubscribersDate()
674
+ {
675
+ $subsDateList = array();
676
+ global $wpdb;
677
+ $subscriptionPopups = $wpdb->get_results('SELECT id, cDate FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME, ARRAY_A);
678
+
679
+ foreach ($subscriptionPopups as $subscriptionForm) {
680
+ $id = $subscriptionForm['id'];
681
+ $date = substr($subscriptionForm['cDate'], 0, 7);
682
+ $subsDateList[$id]['date-value'] = $date;
683
+ $subsDateList[$id]['date-title'] = AdminHelper::getFormattedDate($date);
684
+ }
685
+
686
+ return $subsDateList;
687
+ }
688
+ }
com/config/config.php CHANGED
@@ -1,176 +1,176 @@
1
- <?php
2
-
3
- class SgpbPopupConfig
4
- {
5
- public static function addDefine($name, $value)
6
- {
7
- if (!defined($name)) {
8
- define($name, $value);
9
- }
10
- }
11
-
12
- public static function init()
13
- {
14
- self::addDefine('SGPB_POPUP_FREE_MIN_VERSION', '3.0.2');
15
- self::addDefine('SGPB_POPUP_PRO_MIN_VERSION', '4.0');
16
-
17
- self::addDefine('SGPB_POPUP_PKG_FREE', 1);
18
- self::addDefine('SGPB_POPUP_PKG_SILVER', 2);
19
- self::addDefine('SGPB_POPUP_PKG_GOLD', 3);
20
- self::addDefine('SGPB_POPUP_PKG_PLATINUM', 4);
21
- self::addDefine('SG_POPUP_PRO_URL', 'https://popup-builder.com/#prices');
22
- self::addDefine('SG_POPUP_BUNDLE_URL', 'https://popup-builder.com/bundle/');
23
- self::addDefine('SG_POPUP_EXTENSIONS_URL', 'https://popup-builder.com/#extensions');
24
- self::addDefine('SG_POPUP_SUPPORT_URL', 'https://wordpress.org/support/plugin/popup-builder');
25
- self::addDefine('SG_POPUP_TICKET_URL', 'https://help.popup-builder.com');
26
- self::addDefine('SG_POPUP_RATE_US_URL', 'https://wordpress.org/support/plugin/popup-builder/reviews/');
27
- self::addDefine('SG_POPUP_IFRAME_URL', 'https://popup-builder.com/downloads/iframe/');
28
- self::addDefine('SG_POPUP_SCROLL_URL', 'https://popup-builder.com/downloads/scroll/');
29
- self::addDefine('SG_POPUP_AD_BLOCK_URL', 'https://popup-builder.com/downloads/adblock/');
30
- self::addDefine('SG_POPUP_ANALYTICS_URL', 'https://popup-builder.com/downloads/analytics/');
31
- self::addDefine('SG_POPUP_EXIT_INTENT_URL', 'https://popup-builder.com/downloads/exit-intent/');
32
- self::addDefine('SG_POPUP_MAILCHIMP_URL', 'https://popup-builder.com/downloads/mailchimp/');
33
- self::addDefine('SG_POPUP_AWEBER_URL', 'https://popup-builder.com/downloads/aweber/');
34
- self::addDefine('SG_POPUP_WOOCOMMERCE_URL', 'https://popup-builder.com/downloads/woocommerce/');
35
- self::addDefine('SG_POPUP_RECENT_SALES_URL', 'https://popup-builder.com/downloads/recent-sales/');
36
- self::addDefine('SG_POPUP_VIDEO_URL', 'https://popup-builder.com/downloads/video/');
37
- self::addDefine('SG_POPUP_SOCIAL_URL', 'https://popup-builder.com/downloads/social/');
38
- self::addDefine('SG_POPUP_COUNTDOWN_URL', 'https://popup-builder.com/downloads/countdown/');
39
- self::addDefine('SG_POPUP_RESTRICTION_URL', 'https://popup-builder.com/downloads/yes-no-button-popup/');
40
- self::addDefine('SG_POPUP_CONTACT_FORM_URL', 'https://popup-builder.com/downloads/contact-popup/');
41
- self::addDefine('SG_POPUP_INACTIVITY_URL', 'https://popup-builder.com/downloads/inactivity/');
42
- self::addDefine('SG_POPUP_SCHEDULING_URL', 'https://popup-builder.com/downloads/scheduling/');
43
- self::addDefine('SG_POPUP_GEO_TARGETING_URL', 'https://popup-builder.com/downloads/geo-targeting/');
44
- self::addDefine('SG_POPUP_RANDOM_URL', 'https://popup-builder.com/downloads/random/');
45
- self::addDefine('SG_POPUP_ADVANCED_CLOSING_URL', 'https://popup-builder.com/downloads/advanced-closing/');
46
- self::addDefine('SG_POPUP_ADVANCED_TARGETING_URL', 'https://popup-builder.com/downloads/advanced-targeting/');
47
- self::addDefine('SG_POPUP_ALL_EXTENSIONS_URL', 'https://popup-builder.com/downloads/category/extensions/');
48
- self::addDefine('SG_POPUP_LOGIN_URL', 'https://popup-builder.com/downloads/login-popup/');
49
- self::addDefine('SG_POPUP_REGISTRATION_URL', 'https://popup-builder.com/downloads/registration-popup/');
50
- self::addDefine('SG_POPUP_SUBSCRIPTION_PLUS_URL', 'https://popup-builder.com/downloads/subscription-plus-popup/');
51
- self::addDefine('SG_POPUP_PUSH_NOTIFICATION_URL', 'https://popup-builder.com/downloads/web-push-notification-popup/');
52
- self::addDefine('SGPB_EDD_PLUGIN_URL', 'https://popup-builder.com/downloads/easy-digital-downloads-edd-popup/');
53
- self::addDefine('SGPB_PDF_PLUGIN_URL', 'https://popup-builder.com/downloads/pdf-popup/');
54
- self::addDefine('SGPB_GAMIFICATION_PLUGIN_URL', 'https://popup-builder.com/downloads/pick-a-gift-popup/');
55
- self::addDefine('SGPB_AGE_VERIFICATION_PLUGIN_URL', 'https://popup-builder.com/downloads/age-restriction-popup/');
56
- self::addDefine('SG_POPUP_ADMIN_URL', admin_url());
57
- self::addDefine('SG_POPUP_BUILDER_URL', plugins_url().'/'.SG_POPUP_FOLDER_NAME.'/');
58
- self::addDefine('SG_POPUP_PLUGIN_PATH', WP_PLUGIN_DIR.'/');
59
- self::addDefine('SG_POPUP_BUILDER_PATH', SG_POPUP_PLUGIN_PATH.SG_POPUP_FOLDER_NAME.'/');
60
- self::addDefine('SG_POPUP_COM_PATH', SG_POPUP_BUILDER_PATH.'com/');
61
- self::addDefine('SG_POPUP_CONFIG_PATH', SG_POPUP_COM_PATH.'config/');
62
- self::addDefine('SG_POPUP_PUBLIC_PATH', SG_POPUP_BUILDER_PATH.'public/');
63
- self::addDefine('SG_POPUP_CLASSES_PATH', SG_POPUP_COM_PATH.'classes/');
64
- self::addDefine('SG_POPUP_COMPONENTS_PATH', SG_POPUP_CLASSES_PATH.'components/');
65
- self::addDefine('SG_POPUP_DATA_TABLES_PATH', SG_POPUP_CLASSES_PATH.'dataTable/');
66
- self::addDefine('SG_POPUP_CLASSES_POPUPS_PATH', SG_POPUP_CLASSES_PATH.'popups/');
67
- self::addDefine('SG_POPUP_EXTENSION_PATH', SG_POPUP_CLASSES_PATH.'extension/');
68
- self::addDefine('SGPB_POPUP_DETECTION_PATH', SG_POPUP_CLASSES_PATH.'_detection/');
69
- self::addDefine('SG_POPUP_LIBS_PATH', SG_POPUP_COM_PATH.'libs/');
70
- self::addDefine('SG_POPUP_HELPERS_PATH', SG_POPUP_COM_PATH.'helpers/');
71
- self::addDefine('SG_POPUP_JS_PATH', SG_POPUP_PUBLIC_PATH.'js/');
72
- self::addDefine('SG_POPUP_CSS_PATH', SG_POPUP_PUBLIC_PATH.'css/');
73
- self::addDefine('SG_POPUP_VIEWS_PATH', SG_POPUP_PUBLIC_PATH.'views/');
74
- self::addDefine('SG_POPUP_TYPE_OPTIONS_PATH', SG_POPUP_VIEWS_PATH.'options/');
75
- self::addDefine('SG_POPUP_TYPE_MAIN_PATH', SG_POPUP_VIEWS_PATH.'main/');
76
- self::addDefine('SG_POPUP_PUBLIC_URL', SG_POPUP_BUILDER_URL.'public/');
77
- self::addDefine('SG_POPUP_JS_URL', SG_POPUP_PUBLIC_URL.'js/');
78
- self::addDefine('SG_POPUP_CSS_URL', SG_POPUP_PUBLIC_URL.'css/');
79
- self::addDefine('SG_POPUP_IMG_URL', SG_POPUP_PUBLIC_URL.'img/');
80
- self::addDefine('SG_POPUP_SOUND_URL', SG_POPUP_PUBLIC_URL.'sound/');
81
- self::addDefine('SG_POPUP_VIEWS_URL', SG_POPUP_PUBLIC_URL.'views/');
82
- self::addDefine('SG_POPUP_EMAIL_TEMPLATES_URL', SG_POPUP_VIEWS_URL.'emailTemplates/');
83
- self::addDefine('SG_POPUP_DEFAULT_TIME_ZONE', 'UTC');
84
- self::addDefine('SG_POPUP_CATEGORY_TAXONOMY', 'popup-categories');
85
- self::addDefine('SG_POPUP_MINIMUM_PHP_VERSION', '5.3.3');
86
- self::addDefine('SG_POPUP_POST_TYPE', 'popupbuilder');
87
- self::addDefine('SG_POPUP_NEWSLETTER_PAGE', 'sgpbNewsletter');
88
- self::addDefine('SG_POPUP_SETTINGS_PAGE', 'sgpbSettings');
89
- self::addDefine('SG_POPUP_SUBSCRIBERS_PAGE', 'sgpbSubscribers');
90
- self::addDefine('SG_POPUP_SUPPORT_PAGE', 'sgpbSupport');
91
- self::addDefine('SGPB_POPUP_LICENSE', 'license');
92
- self::addDefine('SG_POPUP_EXTEND_PAGE', 'extend');
93
- self::addDefine('SGPB_FILTER_REPEAT_INTERVAL', 50);
94
- self::addDefine('SG_POPUP_TEXT_DOMAIN', 'popup-builder');
95
- self::addDefine('SG_POPUP_STORE_URL', 'https://popup-builder.com/');
96
- self::addDefine('SG_POPUP_AUTHOR', 'Sygnoos');
97
- self::addDefine('SG_POPUP_KEY', 'POPUP_BUILDER');
98
- self::addDefine('SG_AJAX_NONCE', 'popupBuilderAjaxNonce');
99
- self::addDefine('SG_CONDITION_FIRST_RULE', 0);
100
- self::addDefine('SGPB_AJAX_STATUS_FALSE', 0);
101
- self::addDefine('SGPB_AJAX_STATUS_TRUE', 1);
102
- self::addDefine('SGPB_SUBSCRIBERS_TABLE_NAME', 'sgpb_subscribers');
103
- self::addDefine('SGPB_POSTS_TABLE_NAME', 'posts');
104
- self::addDefine('SGPB_APP_POPUP_TABLE_LIMIT', 10);
105
- self::addDefine('SGPB_SUBSCRIBERS_ERROR_TABLE_NAME', 'sgpb_subscription_error_log');
106
- self::addDefine('SGPB_CRON_REPEAT_INTERVAL', 1);
107
- self::addDefine('SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL', 12); /* Hours */
108
- self::addDefine('SGPB_METABOX_BANNER_CRON_TEXT_URL', 'https://popup-builder.com/sgpb-banner.php?banner=sidebar1');
109
- self::addDefine('SGPB_FACEBOOK_APP_ID', 540547196484707);
110
- self::addDefine('SGPB_POPUP_TYPE_RESTRICTION', 'ageRestriction');
111
- self::addDefine('SGPB_POPUP_DEFAULT_SOUND', 'popupOpenSound.wav');
112
- self::addDefine('SGPB_POPUP_EXTENSIONS_PATH', SG_POPUP_COM_PATH.'extensions/');
113
- self::addDefine('SG_POPUP_BUILDER_NOTIFICATIONS_URL', 'https://popup-builder.com/notifications.json');
114
- self::addDefine('SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY', 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php');
115
- self::addDefine('SGPB_DONT_SHOW_POPUP_EXPIRY', 365);
116
- self::addDefine('SGPB_CONTACT_FORM_7_BEHAVIOR_KEY', 'contact-form-7');
117
- self::addDefine('SGPB_CSS_CLASS_ACTIONS_KEY', 'setByCssClass');
118
- self::addDefine('SGPB_CLICK_ACTION_KEY', 'setByClick');
119
- self::addDefine('SGPB_HOVER_ACTION_KEY', 'setByHover');
120
- self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_SHOW', 1);
121
- self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_HIDE', 2);
122
- self::addDefine('SGPB_POPUP_SCHEDULING_EXTENSION_KEY', 'popupbuilder-scheduling/PopupBuilderScheduling.php');
123
- self::addDefine('SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY', 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php');
124
- self::addDefine('SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY', 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php');
125
- self::addDefine('SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY', 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php');
126
- self::addDefine('SGPB_ASK_REVIEW_POPUP_COUNT', 80);
127
- self::addDefine('SGPB_REVIEW_POPUP_PERIOD', 30);
128
- self::addDefine('SGPB_POPUP_EXPORT_FILE_NAME', 'PopupBuilderPopups.xml');
129
- self::addDefine('SG_POPUP_AUTORESPONDER_POST_TYPE', 'sgpbautoresponder');
130
- self::addDefine('SG_POPUP_TEMPLATE_POST_TYPE', 'sgpbtemplate');
131
- self::addDefine('SGPB_INACTIVE_EXTENSIONS', 'inactivePBExtensions');
132
- self::addDefine('SGPB_POPUP_LICENSE_SCREEN', SG_POPUP_POST_TYPE.'_page_'.SGPB_POPUP_LICENSE);
133
- self::addDefine('SGPB_SUBSCRIPTION_ERROR_MESSAGE', __('There was an error while trying to send your request. Please try again', SG_POPUP_TEXT_DOMAIN).'.');
134
- self::addDefine('SGPB_SUBSCRIPTION_VALIDATION_MESSAGE', __('This field is required', SG_POPUP_TEXT_DOMAIN).'.');
135
- self::addDefine('SGPB_SUBSCRIPTION_EMAIL_MESSAGE', __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
136
- self::addDefine('SGPB_TRANSIENT_TIMEOUT_HOUR', 60 * MINUTE_IN_SECONDS);
137
- self::addDefine('SGPB_TRANSIENT_TIMEOUT_DAY', 24 * HOUR_IN_SECONDS);
138
- self::addDefine('SGPB_TRANSIENT_TIMEOUT_WEEK', 7 * DAY_IN_SECONDS);
139
- self::addDefine('SGPB_TRANSIENT_POPUPS_LOAD', 'sgpbLoadPopups');
140
- self::addDefine('SGPB_TRANSIENT_POPUPS_TERMS', 'sgpbGetPopupsByTermSlug');
141
- self::addDefine('SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES', 'sgpbGetPostsAllCategories');
142
- self::addDefine('SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED', 'sgpbModifiedRegisteredPluginsPaths2');
143
- self::addDefine('SGPB_POPUP_BUILDER_REGISTERED_PLUGINS', 'sgpbPopupBuilderRegisteredPlugins');
144
- self::addDefine('SGPB_RATE_US_NOTIFICATION_ID', 'sgpbMainRateUsNotification');
145
- self::addDefine('SGPB_SUPPORT_BANNER_NOTIFICATION_ID', 'sgpbMainSupportBanner');
146
- self::popupTypesInit();
147
- }
148
-
149
- public static function popupTypesInit()
150
- {
151
- global $SGPB_POPUP_TYPES;
152
-
153
- $SGPB_POPUP_TYPES['typeName'] = apply_filters('sgpbAddPopupType', array(
154
- 'image' => SGPB_POPUP_PKG_FREE,
155
- 'html' => SGPB_POPUP_PKG_FREE,
156
- 'fblike' => SGPB_POPUP_PKG_FREE,
157
- 'subscription' => SGPB_POPUP_PKG_FREE
158
- ));
159
-
160
- $SGPB_POPUP_TYPES['typePath'] = apply_filters('sgpbAddPopupTypePath', array(
161
- 'image' => SG_POPUP_CLASSES_POPUPS_PATH,
162
- 'html' => SG_POPUP_CLASSES_POPUPS_PATH,
163
- 'fblike' => SG_POPUP_CLASSES_POPUPS_PATH,
164
- 'subscription' => SG_POPUP_CLASSES_POPUPS_PATH
165
- ));
166
-
167
- $SGPB_POPUP_TYPES['typeLabels'] = apply_filters('sgpbAddPopupTypeLabels', array(
168
- 'image' => __('Image', SG_POPUP_TEXT_DOMAIN),
169
- 'html' => __('HTML', SG_POPUP_TEXT_DOMAIN),
170
- 'fblike' => __('Facebook', SG_POPUP_TEXT_DOMAIN),
171
- 'subscription' => __('Subscription', SG_POPUP_TEXT_DOMAIN)
172
- ));
173
- }
174
- }
175
-
176
- SgpbPopupConfig::init();
1
+ <?php
2
+
3
+ class SgpbPopupConfig
4
+ {
5
+ public static function addDefine($name, $value)
6
+ {
7
+ if (!defined($name)) {
8
+ define($name, $value);
9
+ }
10
+ }
11
+
12
+ public static function init()
13
+ {
14
+ self::addDefine('SGPB_POPUP_FREE_MIN_VERSION', '3.0.2');
15
+ self::addDefine('SGPB_POPUP_PRO_MIN_VERSION', '4.0');
16
+
17
+ self::addDefine('SGPB_POPUP_PKG_FREE', 1);
18
+ self::addDefine('SGPB_POPUP_PKG_SILVER', 2);
19
+ self::addDefine('SGPB_POPUP_PKG_GOLD', 3);
20
+ self::addDefine('SGPB_POPUP_PKG_PLATINUM', 4);
21
+ self::addDefine('SG_POPUP_PRO_URL', 'https://popup-builder.com/#prices');
22
+ self::addDefine('SG_POPUP_BUNDLE_URL', 'https://popup-builder.com/bundle/');
23
+ self::addDefine('SG_POPUP_EXTENSIONS_URL', 'https://popup-builder.com/#extensions');
24
+ self::addDefine('SG_POPUP_SUPPORT_URL', 'https://wordpress.org/support/plugin/popup-builder');
25
+ self::addDefine('SG_POPUP_TICKET_URL', 'https://help.popup-builder.com');
26
+ self::addDefine('SG_POPUP_RATE_US_URL', 'https://wordpress.org/support/plugin/popup-builder/reviews/');
27
+ self::addDefine('SG_POPUP_IFRAME_URL', 'https://popup-builder.com/downloads/iframe/');
28
+ self::addDefine('SG_POPUP_SCROLL_URL', 'https://popup-builder.com/downloads/scroll/');
29
+ self::addDefine('SG_POPUP_AD_BLOCK_URL', 'https://popup-builder.com/downloads/adblock/');
30
+ self::addDefine('SG_POPUP_ANALYTICS_URL', 'https://popup-builder.com/downloads/analytics/');
31
+ self::addDefine('SG_POPUP_EXIT_INTENT_URL', 'https://popup-builder.com/downloads/exit-intent/');
32
+ self::addDefine('SG_POPUP_MAILCHIMP_URL', 'https://popup-builder.com/downloads/mailchimp/');
33
+ self::addDefine('SG_POPUP_AWEBER_URL', 'https://popup-builder.com/downloads/aweber/');
34
+ self::addDefine('SG_POPUP_WOOCOMMERCE_URL', 'https://popup-builder.com/downloads/woocommerce/');
35
+ self::addDefine('SG_POPUP_RECENT_SALES_URL', 'https://popup-builder.com/downloads/recent-sales/');
36
+ self::addDefine('SG_POPUP_VIDEO_URL', 'https://popup-builder.com/downloads/video/');
37
+ self::addDefine('SG_POPUP_SOCIAL_URL', 'https://popup-builder.com/downloads/social/');
38
+ self::addDefine('SG_POPUP_COUNTDOWN_URL', 'https://popup-builder.com/downloads/countdown/');
39
+ self::addDefine('SG_POPUP_RESTRICTION_URL', 'https://popup-builder.com/downloads/yes-no-button-popup/');
40
+ self::addDefine('SG_POPUP_CONTACT_FORM_URL', 'https://popup-builder.com/downloads/contact-popup/');
41
+ self::addDefine('SG_POPUP_INACTIVITY_URL', 'https://popup-builder.com/downloads/inactivity/');
42
+ self::addDefine('SG_POPUP_SCHEDULING_URL', 'https://popup-builder.com/downloads/scheduling/');
43
+ self::addDefine('SG_POPUP_GEO_TARGETING_URL', 'https://popup-builder.com/downloads/geo-targeting/');
44
+ self::addDefine('SG_POPUP_RANDOM_URL', 'https://popup-builder.com/downloads/random/');
45
+ self::addDefine('SG_POPUP_ADVANCED_CLOSING_URL', 'https://popup-builder.com/downloads/advanced-closing/');
46
+ self::addDefine('SG_POPUP_ADVANCED_TARGETING_URL', 'https://popup-builder.com/downloads/advanced-targeting/');
47
+ self::addDefine('SG_POPUP_ALL_EXTENSIONS_URL', 'https://popup-builder.com/downloads/category/extensions/');
48
+ self::addDefine('SG_POPUP_LOGIN_URL', 'https://popup-builder.com/downloads/login-popup/');
49
+ self::addDefine('SG_POPUP_REGISTRATION_URL', 'https://popup-builder.com/downloads/registration-popup/');
50
+ self::addDefine('SG_POPUP_SUBSCRIPTION_PLUS_URL', 'https://popup-builder.com/downloads/subscription-plus-popup/');
51
+ self::addDefine('SG_POPUP_PUSH_NOTIFICATION_URL', 'https://popup-builder.com/downloads/web-push-notification-popup/');
52
+ self::addDefine('SGPB_EDD_PLUGIN_URL', 'https://popup-builder.com/downloads/easy-digital-downloads-edd-popup/');
53
+ self::addDefine('SGPB_PDF_PLUGIN_URL', 'https://popup-builder.com/downloads/pdf-popup/');
54
+ self::addDefine('SGPB_GAMIFICATION_PLUGIN_URL', 'https://popup-builder.com/downloads/pick-a-gift-popup/');
55
+ self::addDefine('SGPB_AGE_VERIFICATION_PLUGIN_URL', 'https://popup-builder.com/downloads/age-restriction-popup/');
56
+ self::addDefine('SG_POPUP_ADMIN_URL', admin_url());
57
+ self::addDefine('SG_POPUP_BUILDER_URL', plugins_url().'/'.SG_POPUP_FOLDER_NAME.'/');
58
+ self::addDefine('SG_POPUP_PLUGIN_PATH', WP_PLUGIN_DIR.'/');
59
+ self::addDefine('SG_POPUP_BUILDER_PATH', SG_POPUP_PLUGIN_PATH.SG_POPUP_FOLDER_NAME.'/');
60
+ self::addDefine('SG_POPUP_COM_PATH', SG_POPUP_BUILDER_PATH.'com/');
61
+ self::addDefine('SG_POPUP_CONFIG_PATH', SG_POPUP_COM_PATH.'config/');
62
+ self::addDefine('SG_POPUP_PUBLIC_PATH', SG_POPUP_BUILDER_PATH.'public/');
63
+ self::addDefine('SG_POPUP_CLASSES_PATH', SG_POPUP_COM_PATH.'classes/');
64
+ self::addDefine('SG_POPUP_COMPONENTS_PATH', SG_POPUP_CLASSES_PATH.'components/');
65
+ self::addDefine('SG_POPUP_DATA_TABLES_PATH', SG_POPUP_CLASSES_PATH.'dataTable/');
66
+ self::addDefine('SG_POPUP_CLASSES_POPUPS_PATH', SG_POPUP_CLASSES_PATH.'popups/');
67
+ self::addDefine('SG_POPUP_EXTENSION_PATH', SG_POPUP_CLASSES_PATH.'extension/');
68
+ self::addDefine('SGPB_POPUP_DETECTION_PATH', SG_POPUP_CLASSES_PATH.'_detection/');
69
+ self::addDefine('SG_POPUP_LIBS_PATH', SG_POPUP_COM_PATH.'libs/');
70
+ self::addDefine('SG_POPUP_HELPERS_PATH', SG_POPUP_COM_PATH.'helpers/');
71
+ self::addDefine('SG_POPUP_JS_PATH', SG_POPUP_PUBLIC_PATH.'js/');
72
+ self::addDefine('SG_POPUP_CSS_PATH', SG_POPUP_PUBLIC_PATH.'css/');
73
+ self::addDefine('SG_POPUP_VIEWS_PATH', SG_POPUP_PUBLIC_PATH.'views/');
74
+ self::addDefine('SG_POPUP_TYPE_OPTIONS_PATH', SG_POPUP_VIEWS_PATH.'options/');
75
+ self::addDefine('SG_POPUP_TYPE_MAIN_PATH', SG_POPUP_VIEWS_PATH.'main/');
76
+ self::addDefine('SG_POPUP_PUBLIC_URL', SG_POPUP_BUILDER_URL.'public/');
77
+ self::addDefine('SG_POPUP_JS_URL', SG_POPUP_PUBLIC_URL.'js/');
78
+ self::addDefine('SG_POPUP_CSS_URL', SG_POPUP_PUBLIC_URL.'css/');
79
+ self::addDefine('SG_POPUP_IMG_URL', SG_POPUP_PUBLIC_URL.'img/');
80
+ self::addDefine('SG_POPUP_SOUND_URL', SG_POPUP_PUBLIC_URL.'sound/');
81
+ self::addDefine('SG_POPUP_VIEWS_URL', SG_POPUP_PUBLIC_URL.'views/');
82
+ self::addDefine('SG_POPUP_EMAIL_TEMPLATES_URL', SG_POPUP_VIEWS_URL.'emailTemplates/');
83
+ self::addDefine('SG_POPUP_DEFAULT_TIME_ZONE', 'UTC');
84
+ self::addDefine('SG_POPUP_CATEGORY_TAXONOMY', 'popup-categories');
85
+ self::addDefine('SG_POPUP_MINIMUM_PHP_VERSION', '5.3.3');
86
+ self::addDefine('SG_POPUP_POST_TYPE', 'popupbuilder');
87
+ self::addDefine('SG_POPUP_NEWSLETTER_PAGE', 'sgpbNewsletter');
88
+ self::addDefine('SG_POPUP_SETTINGS_PAGE', 'sgpbSettings');
89
+ self::addDefine('SG_POPUP_SUBSCRIBERS_PAGE', 'sgpbSubscribers');
90
+ self::addDefine('SG_POPUP_SUPPORT_PAGE', 'sgpbSupport');
91
+ self::addDefine('SGPB_POPUP_LICENSE', 'license');
92
+ self::addDefine('SG_POPUP_EXTEND_PAGE', 'extend');
93
+ self::addDefine('SGPB_FILTER_REPEAT_INTERVAL', 50);
94
+ self::addDefine('SG_POPUP_TEXT_DOMAIN', 'popup-builder');
95
+ self::addDefine('SG_POPUP_STORE_URL', 'https://popup-builder.com/');
96
+ self::addDefine('SG_POPUP_AUTHOR', 'Sygnoos');
97
+ self::addDefine('SG_POPUP_KEY', 'POPUP_BUILDER');
98
+ self::addDefine('SG_AJAX_NONCE', 'popupBuilderAjaxNonce');
99
+ self::addDefine('SG_CONDITION_FIRST_RULE', 0);
100
+ self::addDefine('SGPB_AJAX_STATUS_FALSE', 0);
101
+ self::addDefine('SGPB_AJAX_STATUS_TRUE', 1);
102
+ self::addDefine('SGPB_SUBSCRIBERS_TABLE_NAME', 'sgpb_subscribers');
103
+ self::addDefine('SGPB_POSTS_TABLE_NAME', 'posts');
104
+ self::addDefine('SGPB_APP_POPUP_TABLE_LIMIT', 10);
105
+ self::addDefine('SGPB_SUBSCRIBERS_ERROR_TABLE_NAME', 'sgpb_subscription_error_log');
106
+ self::addDefine('SGPB_CRON_REPEAT_INTERVAL', 1);
107
+ self::addDefine('SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL', 12); /* Hours */
108
+ self::addDefine('SGPB_METABOX_BANNER_CRON_TEXT_URL', 'https://popup-builder.com/sgpb-banner.php?banner=sidebar1');
109
+ self::addDefine('SGPB_FACEBOOK_APP_ID', 540547196484707);
110
+ self::addDefine('SGPB_POPUP_TYPE_RESTRICTION', 'ageRestriction');
111
+ self::addDefine('SGPB_POPUP_DEFAULT_SOUND', 'popupOpenSound.wav');
112
+ self::addDefine('SGPB_POPUP_EXTENSIONS_PATH', SG_POPUP_COM_PATH.'extensions/');
113
+ self::addDefine('SG_POPUP_BUILDER_NOTIFICATIONS_URL', 'https://popup-builder.com/notifications.json');
114
+ self::addDefine('SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY', 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php');
115
+ self::addDefine('SGPB_DONT_SHOW_POPUP_EXPIRY', 365);
116
+ self::addDefine('SGPB_CONTACT_FORM_7_BEHAVIOR_KEY', 'contact-form-7');
117
+ self::addDefine('SGPB_CSS_CLASS_ACTIONS_KEY', 'setByCssClass');
118
+ self::addDefine('SGPB_CLICK_ACTION_KEY', 'setByClick');
119
+ self::addDefine('SGPB_HOVER_ACTION_KEY', 'setByHover');
120
+ self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_SHOW', 1);
121
+ self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_HIDE', 2);
122
+ self::addDefine('SGPB_POPUP_SCHEDULING_EXTENSION_KEY', 'popupbuilder-scheduling/PopupBuilderScheduling.php');
123
+ self::addDefine('SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY', 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php');
124
+ self::addDefine('SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY', 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php');
125
+ self::addDefine('SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY', 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php');
126
+ self::addDefine('SGPB_ASK_REVIEW_POPUP_COUNT', 80);
127
+ self::addDefine('SGPB_REVIEW_POPUP_PERIOD', 30);
128
+ self::addDefine('SGPB_POPUP_EXPORT_FILE_NAME', 'PopupBuilderPopups.xml');
129
+ self::addDefine('SG_POPUP_AUTORESPONDER_POST_TYPE', 'sgpbautoresponder');
130
+ self::addDefine('SG_POPUP_TEMPLATE_POST_TYPE', 'sgpbtemplate');
131
+ self::addDefine('SGPB_INACTIVE_EXTENSIONS', 'inactivePBExtensions');
132
+ self::addDefine('SGPB_POPUP_LICENSE_SCREEN', SG_POPUP_POST_TYPE.'_page_'.SGPB_POPUP_LICENSE);
133
+ self::addDefine('SGPB_SUBSCRIPTION_ERROR_MESSAGE', __('There was an error while trying to send your request. Please try again', SG_POPUP_TEXT_DOMAIN).'.');
134
+ self::addDefine('SGPB_SUBSCRIPTION_VALIDATION_MESSAGE', __('This field is required', SG_POPUP_TEXT_DOMAIN).'.');
135
+ self::addDefine('SGPB_SUBSCRIPTION_EMAIL_MESSAGE', __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
136
+ self::addDefine('SGPB_TRANSIENT_TIMEOUT_HOUR', 60 * MINUTE_IN_SECONDS);
137
+ self::addDefine('SGPB_TRANSIENT_TIMEOUT_DAY', 24 * HOUR_IN_SECONDS);
138
+ self::addDefine('SGPB_TRANSIENT_TIMEOUT_WEEK', 7 * DAY_IN_SECONDS);
139
+ self::addDefine('SGPB_TRANSIENT_POPUPS_LOAD', 'sgpbLoadPopups');
140
+ self::addDefine('SGPB_TRANSIENT_POPUPS_TERMS', 'sgpbGetPopupsByTermSlug');
141
+ self::addDefine('SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES', 'sgpbGetPostsAllCategories');
142
+ self::addDefine('SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED', 'sgpbModifiedRegisteredPluginsPaths2');
143
+ self::addDefine('SGPB_POPUP_BUILDER_REGISTERED_PLUGINS', 'sgpbPopupBuilderRegisteredPlugins');
144
+ self::addDefine('SGPB_RATE_US_NOTIFICATION_ID', 'sgpbMainRateUsNotification');
145
+ self::addDefine('SGPB_SUPPORT_BANNER_NOTIFICATION_ID', 'sgpbMainSupportBanner');
146
+ self::popupTypesInit();
147
+ }
148
+
149
+ public static function popupTypesInit()
150
+ {
151
+ global $SGPB_POPUP_TYPES;
152
+
153
+ $SGPB_POPUP_TYPES['typeName'] = apply_filters('sgpbAddPopupType', array(
154
+ 'image' => SGPB_POPUP_PKG_FREE,
155
+ 'html' => SGPB_POPUP_PKG_FREE,
156
+ 'fblike' => SGPB_POPUP_PKG_FREE,
157
+ 'subscription' => SGPB_POPUP_PKG_FREE
158
+ ));
159
+
160
+ $SGPB_POPUP_TYPES['typePath'] = apply_filters('sgpbAddPopupTypePath', array(
161
+ 'image' => SG_POPUP_CLASSES_POPUPS_PATH,
162
+ 'html' => SG_POPUP_CLASSES_POPUPS_PATH,
163
+ 'fblike' => SG_POPUP_CLASSES_POPUPS_PATH,
164
+ 'subscription' => SG_POPUP_CLASSES_POPUPS_PATH
165
+ ));
166
+
167
+ $SGPB_POPUP_TYPES['typeLabels'] = apply_filters('sgpbAddPopupTypeLabels', array(
168
+ 'image' => __('Image', SG_POPUP_TEXT_DOMAIN),
169
+ 'html' => __('HTML', SG_POPUP_TEXT_DOMAIN),
170
+ 'fblike' => __('Facebook', SG_POPUP_TEXT_DOMAIN),
171
+ 'subscription' => __('Subscription', SG_POPUP_TEXT_DOMAIN)
172
+ ));
173
+ }
174
+ }
175
+
176
+ SgpbPopupConfig::init();
com/config/configPackage.php CHANGED
@@ -1,8 +1,8 @@
1
- <?php
2
- if (!defined('ABSPATH')) {
3
- exit();
4
- }
5
-
6
- define('SG_POPUP_VERSION', '4.0.3');
7
- define('SGPB_POPUP_PKG', SGPB_POPUP_PKG_FREE);
8
- define('POPUP_BUILDER_BASENAME', 'popupbuilder-platinum/popup-builder.php');
1
+ <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit();
4
+ }
5
+
6
+ define('SG_POPUP_VERSION', '4.0.4');
7
+ define('SGPB_POPUP_PKG', SGPB_POPUP_PKG_FREE);
8
+ define('POPUP_BUILDER_BASENAME', 'popupbuilder-platinum/popup-builder.php');
com/config/dataConfig.php CHANGED
@@ -1,1033 +1,1033 @@
1
- <?php
2
- require_once(SG_POPUP_HELPERS_PATH.'ConfigDataHelper.php');
3
- use sgpb\PopupBuilderActivePackage;
4
- class SgpbDataConfig
5
- {
6
- public static function init()
7
- {
8
- self::addFilters();
9
- self::conditionInit();
10
- self::transientConfig();
11
- self::popupDefaultOptions();
12
- }
13
-
14
- public static function conditionInit()
15
- {
16
- global $SGPB_DATA_CONFIG_ARRAY;
17
-
18
- /*Target condition config*/
19
- $targetData = array('param' => 'Pages', 'operator' => 'Is not', 'value' => 'Value');
20
- $targetElementTypes = array(
21
- 'param' => 'select',
22
- 'operator' => 'select',
23
- 'value' => 'select',
24
- 'post_selected' => 'select',
25
- 'page_selected' => 'select',
26
- 'post_type' => 'select',
27
- 'post_category' => 'select',
28
- 'page_type' => 'select',
29
- 'page_template' => 'select',
30
- 'post_tags_ids' => 'select'
31
- );
32
-
33
- $targetParams = array(
34
- 'not_rule' => __('Select rule', SG_POPUP_TEXT_DOMAIN),
35
- 'everywhere' => __('Everywhere', SG_POPUP_TEXT_DOMAIN),
36
- 'Post' => array(
37
- 'post_all' => __('All posts', SG_POPUP_TEXT_DOMAIN),
38
- 'post_selected' => __('Selected posts', SG_POPUP_TEXT_DOMAIN),
39
- 'post_type' => __('Post type', SG_POPUP_TEXT_DOMAIN),
40
- 'post_category' => __('Post category', SG_POPUP_TEXT_DOMAIN)
41
- ),
42
- 'Page' => array(
43
- 'page_all' => __('All pages', SG_POPUP_TEXT_DOMAIN),
44
- 'page_selected' => __('Selected pages', SG_POPUP_TEXT_DOMAIN),
45
- 'page_type' => __('Page type', SG_POPUP_TEXT_DOMAIN),
46
- 'page_template' => __('Page template', SG_POPUP_TEXT_DOMAIN)
47
- ),
48
- 'Tags' => array(
49
- 'post_tags' => __('All tags', SG_POPUP_TEXT_DOMAIN),
50
- 'post_tags_ids' => __('Selected tags', SG_POPUP_TEXT_DOMAIN)
51
- )
52
- );
53
-
54
- $targetOperators = array(
55
- array('operator' => 'add', 'name' => __('Add', SG_POPUP_TEXT_DOMAIN)),
56
- array('operator' => 'delete', 'name' => __('Delete', SG_POPUP_TEXT_DOMAIN))
57
- );
58
-
59
- $targetDataOperator = array(
60
- '==' => __('Is', SG_POPUP_TEXT_DOMAIN),
61
- '!=' => __('Is not', SG_POPUP_TEXT_DOMAIN)
62
- );
63
- $targetInitialData = array(
64
- array('param' => 'everywhere')
65
- );
66
-
67
- $targetDataParams['param'] = apply_filters('sgPopupTargetParams', $targetParams);
68
- $targetDataParams['operator'] = apply_filters('sgPopupTargetOperator', $targetDataOperator);
69
- $targetDataParams['post_selected'] = apply_filters('sgPopupTargetPostData', array());
70
- $targetDataParams['page_selected'] = apply_filters('sgPopupTargetPageSelected', array());
71
- $targetDataParams['post_type'] = apply_filters('sgPopupTargetPostType', ConfigDataHelper::getAllCustomPostTypes());
72
- $targetDataParams['post_category'] = apply_filters('sgPopupTargetPostCategory', ConfigDataHelper::getPostsAllCategories());
73
- $targetDataParams['page_type'] = apply_filters('sgPopupTargetPageType', ConfigDataHelper::getPageTypes());
74
- $targetDataParams['page_template'] = apply_filters('sgPopupPageTemplates', array());
75
- $targetDataParams['post_tags_ids'] = apply_filters('sgPopupTags', ConfigDataHelper::getAllTags());
76
- $targetDataParams['everywhere'] = null;
77
- $targetDataParams['not_rule'] = null;
78
- $targetDataParams['post_all'] = null;
79
- $targetDataParams['page_all'] = null;
80
- $targetDataParams['post_tags'] = null;
81
-
82
- $targetAttrs = array(
83
- 'param' => array(
84
- 'htmlAttrs' => array(
85
- 'class' => 'js-sg-select2 js-select-basic',
86
- 'data-select-class' => 'js-select-basic',
87
- 'data-select-type' => 'basic',
88
- 'autocomplete' => 'off'
89
- ),
90
- 'infoAttrs' => array(
91
- 'label' => 'Display rule',
92
- 'info' => __('Specify where the popup should be shown on your site.', SG_POPUP_TEXT_DOMAIN)
93
- )
94
-
95
- ),
96
- 'operator' => array(
97
- 'htmlAttrs' => array(
98
- 'class' => 'js-sg-select2 js-select-basic',
99
- 'data-select-class' => 'js-select-basic',
100
- 'data-select-type' => 'basic'
101
- ),
102
- 'infoAttrs' => array(
103
- 'label' => 'Is or is not',
104
- 'info' => __('Allow or Disallow popup showing for the selected rule.', SG_POPUP_TEXT_DOMAIN)
105
- )
106
- ),
107
- 'post_selected' => array(
108
- 'htmlAttrs' => array(
109
- 'class' => 'js-sg-select2 js-select-ajax',
110
- 'data-select-class' => 'js-select-ajax',
111
- 'data-select-type' => 'ajax',
112
- 'data-value-param' => 'post',
113
- 'multiple' => 'multiple'
114
- ),
115
- 'infoAttrs' => array(
116
- 'label' => 'Select Your Posts',
117
- 'info' => __('Select your specific posts where the popup should be shown.', SG_POPUP_TEXT_DOMAIN)
118
- )
119
- ),
120
- 'page_selected' => array(
121
- 'htmlAttrs' => array(
122
- 'class' => 'js-sg-select2 js-select-ajax',
123
- 'data-select-class' => 'js-select-ajax',
124
- 'data-select-type' => 'ajax',
125
- 'data-value-param' => 'page',
126
- 'multiple' => 'multiple'
127
- ),
128
- 'infoAttrs' => array(
129
- 'label' => 'Select Your Pages',
130
- 'info' => __('Select the pages on your site where the specific popup will be shown.', SG_POPUP_TEXT_DOMAIN)
131
- )
132
- ),
133
- 'post_type' => array(
134
- 'htmlAttrs' => array(
135
- 'class' => 'js-sg-select2 js-select-ajax',
136
- 'data-select-class' => 'js-select-ajax',
137
- 'data-select-type' => 'multiple',
138
- 'data-value-param' => 'postTypes',
139
- 'isNotPostType' => true,
140
- 'multiple' => 'multiple'
141
- ),
142
- 'infoAttrs' => array(
143
- 'label' => 'Select Your post types',
144
- 'info' => __('Specify the post types on your site to show the popup.', SG_POPUP_TEXT_DOMAIN)
145
- )
146
- ),
147
- 'post_category' => array(
148
- 'htmlAttrs' => array(
149
- 'class' => 'js-sg-select2 js-select-ajax',
150
- 'data-select-class' => 'js-select-ajax',
151
- 'data-select-type' => 'multiple',
152
- 'data-value-param' => 'postCategories',
153
- 'isNotPostType' => true,
154
- 'multiple' => 'multiple'
155
- ),
156
- 'infoAttrs' => array(
157
- 'label' => 'Select post categories',
158
- 'info' => __('Select the post categories on which the popup should be shown.', SG_POPUP_TEXT_DOMAIN)
159
- )
160
- ),
161
- 'page_type' => array(
162
- 'htmlAttrs' => array(
163
- 'class' => 'js-sg-select2 js-select-ajax',
164
- 'data-select-class' => 'js-select-ajax',
165
- 'data-select-type' => 'multiple',
166
- 'data-value-param' => 'postCategories',
167
- 'isNotPostType' => true,
168
- 'multiple' => 'multiple'
169
- ),
170
- 'infoAttrs' => array(
171
- 'label' => 'Select specific page types',
172
- 'info' => __('Specify the page types where the popup will be shown.', SG_POPUP_TEXT_DOMAIN)
173
- )
174
- ),
175
- 'page_template' => array(
176
- 'htmlAttrs' => array(
177
- 'class' => 'js-sg-select2 js-select-ajax',
178
- 'data-select-class' => 'js-select-ajax',
179
- 'data-select-type' => 'multiple',
180
- 'data-value-param' => 'pageTemplate',
181
- 'isNotPostType' => true,
182
- 'multiple' => 'multiple'
183
- ),
184
- 'infoAttrs' => array(
185
- 'label' => 'Select page template',
186
- 'info' => __('Select the page templates on which the popup will be shown.', SG_POPUP_TEXT_DOMAIN)
187
- )
188
- ),
189
- 'post_tags_ids' => array(
190
- 'htmlAttrs' => array(
191
- 'class' => 'js-sg-select2 js-select-ajax',
192
- 'data-select-class' => 'js-select-ajax',
193
- 'data-select-type' => 'multiple',
194
- 'data-value-param' => 'postTags',
195
- 'isNotPostType' => true,
196
- 'multiple' => 'multiple'
197
- ),
198
- 'infoAttrs' => array(
199
- 'label' => 'Select tags',
200
- 'info' => __('Select the tags on your site for popup showing', SG_POPUP_TEXT_DOMAIN)
201
- )
202
- )
203
- );
204
-
205
- $popupTarget['columns'] = apply_filters('sgPopupTargetColumns', $targetData);
206
- $popupTarget['columnTypes'] = apply_filters('sgPopupTargetTypes', $targetElementTypes);
207
- $popupTarget['paramsData'] = apply_filters('sgPopupTargetData', $targetDataParams);
208
- $popupTarget['initialData'] = apply_filters('sgPopupTargetInitialData', $targetInitialData);
209
- $popupTarget['operators'] = apply_filters('sgpbPopupEventsOperators', $targetOperators);
210
- $popupTarget['attrs'] = apply_filters('sgPopupTargetAttrs', $targetAttrs);
211
-
212
- $SGPB_DATA_CONFIG_ARRAY['target'] = $popupTarget;
213
-
214
- /*Target condition config*/
215
-
216
- /*
217
- *
218
- * Events data
219
- *
220
- **/
221
- $eventsData = array('param' => 'Event name', 'value' => 'Delay');
222
- $hiddenOptionData = array();
223
-
224
- $eventsRowTypes = array(
225
- 'param' => 'select',
226
- 'operator' => 'select',
227
- 'value' => 'text',
228
- 'load' => 'number',
229
- 'repetitive' => 'checkbox',
230
- 'repetitivePeriod' => 'text',
231
- SGPB_CLICK_ACTION_KEY => 'select',
232
- 'clickActionCustomClass' => 'text',
233
- 'hoverActionCustomClass' => 'text',
234
- 'defaultClickClassName' => 'conditionalText',
235
- 'defaultHoverClassName' => 'conditionalText'
236
- );
237
-
238
- $params = array(
239
- 'load' => 'On load',
240
- SGPB_CSS_CLASS_ACTIONS_KEY => __('Set by CSS class', SG_POPUP_TEXT_DOMAIN),
241
- SGPB_CLICK_ACTION_KEY => __('On Click', SG_POPUP_TEXT_DOMAIN),
242
- SGPB_HOVER_ACTION_KEY => __('On Hover', SG_POPUP_TEXT_DOMAIN),
243
- 'inactivity' => __('Inactivity', SG_POPUP_TEXT_DOMAIN),
244
- 'onScroll' => __('On Scroll', SG_POPUP_TEXT_DOMAIN)
245
- );
246
-
247
- $hiddenOptionData['load'] = array(
248
- 'options' => array(
249
- 'repetitive' => 'Repetitive popup'
250
- )
251
- );
252
-
253
- $onLoadData = 0;
254
-
255
- $eventsDataParams['param'] = $params;
256
- $eventsDataParams['operator'] = array();
257
- $eventsDataParams['load'] = $onLoadData;
258
- $eventsDataParams['clickActionCustomClass'] = '';
259
- $eventsDataParams['hoverActionCustomClass'] = '';
260
- $eventsDataParams['defaultClickClassName'] = 'sg-popup-id-';
261
- $eventsDataParams['defaultHoverClassName'] = 'sg-popup-hover-';
262
- $eventsDataParams[SGPB_CSS_CLASS_ACTIONS_KEY] = null;
263
- $eventsDataParams[SGPB_CLICK_ACTION_KEY.'Operator'] = ConfigDataHelper::getClickActionOptions();
264
- $eventsDataParams[SGPB_HOVER_ACTION_KEY.'Operator'] = ConfigDataHelper::getHoverActionOptions();
265
- /*Hidden params data*/
266
- $eventsDataParams['repetitive'] = '';
267
- $eventsDataParams['repetitivePeriod'] = 0;
268
-
269
- $eventOperators = array(
270
- array('operator' => 'add', 'name' => 'Add'),
271
- array('operator' => 'edit', 'name' => 'Edit'),
272
- array('operator' => 'delete', 'name' => 'Delete')
273
- );
274
-
275
- $eventsInitialData = array(
276
- array('param' => 'load', 'value' => '', 'hiddenOption' => array())
277
- );
278
-
279
- $eventsAttrs = array(
280
- 'param' => array(
281
- 'htmlAttrs' => array(
282
- 'class' => 'js-sg-select2 js-select-basic sgpb-selectbox-settings',
283
- 'data-select-class' => 'js-select-basic',
284
- 'data-select-type' => 'basic'
285
- ),
286
- 'infoAttrs' => array(
287
- 'label' => 'Event',
288
- 'info' => __('Select when the popup should appear on the page.', SG_POPUP_TEXT_DOMAIN)
289
- )
290
- ),
291
- 'operator' => array(
292
- 'htmlAttrs' => array(
293
- 'class' => 'js-sg-select2 js-select-basic',
294
- 'data-select-class' => 'js-select-basic',
295
- 'data-select-type' => 'basic'
296
- ),
297
- 'infoAttrs' => array(
298
- 'label' => 'Options',
299
- 'info' => __('Select the condition for the current event.', SG_POPUP_TEXT_DOMAIN)
300
- )
301
- ),
302
- 'load' => array(
303
- 'htmlAttrs' => array('class' => 'js-sg-onload-text formItem__input formItem__input_select2_num_input', 'placeholder' => __('default custom delay will be used', SG_POPUP_TEXT_DOMAIN), 'min' => 0),
304
- 'infoAttrs' => array(
305
- 'label' => 'Delay',
306
- 'info' => __('Specify how long the popup appearance should be delayed after loading the page (in sec).', SG_POPUP_TEXT_DOMAIN)
307
- )
308
- ),
309
- SGPB_CLICK_ACTION_KEY => array(
310
- 'htmlAttrs' => array(
311
- 'class' => 'js-sg-select2 js-select-basic formItem__input formItem__input_select2_num_input',
312
- 'data-select-class' => 'js-select-basic',
313
- 'data-select-type' => 'basic'
314
- ),
315
- 'infoAttrs' => array(
316
- 'label' => 'Click Event',
317
- 'info' => __('Specify the part of the page, in percentages, where the popup should appear after scrolling.', SG_POPUP_TEXT_DOMAIN)
318
- )
319
- ),
320
- SGPB_HOVER_ACTION_KEY => array(
321
- 'htmlAttrs' => array(
322
- 'class' => 'js-sg-select2 js-select-basic formItem__input formItem__input_select2_num_input',
323
- 'data-select-class' => 'js-select-basic',
324
- 'data-select-type' => 'basic'
325
- ),
326
- 'infoAttrs' => array(
327
- 'label' => 'Hover Event',
328
- 'info' => __('Specify the part of the page, in percentages, where the popup should appear after scrolling.', SG_POPUP_TEXT_DOMAIN)
329
- )
330
- ),
331
- 'clickActionCustomClass' => array(
332
- 'htmlAttrs' => array('class' => 'js-sg-inactivity-text formItem__input formItem__input_select2_num_input', 'min' => 0),
333
- 'infoAttrs' => array(
334
- 'label' => 'Custom Class',
335
- 'info' => __('Add the CSS class name of your HTML element which will trigger this popup after click.', SG_POPUP_TEXT_DOMAIN)
336
- )
337
- ),
338
- 'hoverActionCustomClass' => array(
339
- 'htmlAttrs' => array('class' => 'js-sg-inactivity-text formItem__input formItem__input_select2_num_input', 'min' => 0),
340
- 'infoAttrs' => array(
341
- 'label' => 'Custom Class',
342
- 'info' => __('Add the CSS class name of your HTML element which will trigger this popup after click.', SG_POPUP_TEXT_DOMAIN)
343
- )
344
- ),
345
- 'defaultClickClassName' => array(
346
- 'htmlAttrs' => array(
347
- 'class' => 'js-sg-click-event formItem__input formItem__input_select2_num_input',
348
- 'min' => 0,
349
- 'readonly' => '',
350
- 'value' => 'sg-popup-id-',
351
- 'beforeSaveLabel' => __('Please save popup to generate class name.', SG_POPUP_TEXT_DOMAIN)
352
- ),
353
- 'infoAttrs' => array(
354
- 'label' => 'Default Class',
355
- 'info' => __('Add the following CSS class into your HTML element.', SG_POPUP_TEXT_DOMAIN)
356
- )
357
- ),
358
- 'defaultHoverClassName' => array(
359
- 'htmlAttrs' => array(
360
- 'class' => 'js-sg-hover-event formItem__input formItem__input_select2_num_input',
361
- 'min' => 0,
362
- 'readonly' => '',
363
- 'value' => 'sg-popup-hover-',
364
- 'beforeSaveLabel' => __('Please save popup to generate class name.', SG_POPUP_TEXT_DOMAIN)
365
- ),
366
- 'infoAttrs' => array(
367
- 'label' => 'Default Class',
368
- 'info' => __('Add the following CSS class into your HTML element.', SG_POPUP_TEXT_DOMAIN)
369
- )
370
- ),
371
- 'repetitive' => array(
372
- 'htmlAttrs' => array(
373
- 'class' => 'sgpb-popup-option sgpb-popup-accordion',
374
- 'data-name' => 'repetitive',
375
- 'autocomplete' => 'off'
376
- ),
377
- 'infoAttrs' => array(
378
- 'label' => 'Repetitive open popup',
379
- 'info' => __('If this option is enabled the same popup will open up after every X seconds you have defined (after closing it).', SG_POPUP_TEXT_DOMAIN)
380
- ),
381
- 'childOptions' => array('repetitivePeriod')
382
- ),
383
- 'repetitivePeriod' => array(
384
- 'htmlAttrs' => array(
385
- 'class' => 'sgpb-popup-option',
386
- 'autocomplete' => 'off'
387
- ),
388
- 'infoAttrs' => array(
389
- 'label' => 'period',
390
- 'info' => __('This is info', SG_POPUP_TEXT_DOMAIN)
391
- )
392
- )
393
- );
394
-
395
- $popupEvents['columns'] = apply_filters('sgPopupEventColumns', $eventsData);
396
- $popupEvents['columnTypes'] = apply_filters('sgPopupEventTypes', $eventsRowTypes);
397
- $popupEvents['paramsData'] = apply_filters('sgPopupEventsData', $eventsDataParams);
398
- $popupEvents['initialData'] = apply_filters('sgPopupEventsInitialData', $eventsInitialData);
399
- $popupEvents['operators'] = apply_filters('sgPopupEventOperators', $eventOperators);
400
- $popupEvents['hiddenOptionData'] = apply_filters('sgEventsHiddenData', $hiddenOptionData);
401
- $popupEvents['attrs'] = apply_filters('sgPopupEventAttrs', $eventsAttrs);
402
-
403
- $popupEvents['specialDefaultOperator'] = apply_filters('sgPopupEventsOperators', ' ');
404
- $popupEvents['operatorAllowInConditions'] = apply_filters('sgPopupEventsOperatorAllowInConditions', array(SGPB_CLICK_ACTION_KEY, SGPB_HOVER_ACTION_KEY));
405
-
406
- $SGPB_DATA_CONFIG_ARRAY['events'] = $popupEvents;
407
-
408
- /*Target condition config*/
409
- $targetData = array('param' => 'Pages', 'operator' => 'Is not', 'value' => 'Value');
410
- $targetElementTypes = array(
411
- 'param' => 'select',
412
- 'operator' => 'select',
413
- 'value' => 'select',
414
- 'select_role' => 'select',
415
- );
416
-
417
- $targetParams = array(
418
- 'select_role' => __('Select role', SG_POPUP_TEXT_DOMAIN)
419
- );
420
-
421
- $targetOperators = array(
422
- array('operator' => 'add', 'name' => __('Add', SG_POPUP_TEXT_DOMAIN)),
423
- array('operator' => 'delete', 'name' => __('Delete', SG_POPUP_TEXT_DOMAIN))
424
- );
425
-
426
- $targetDataOperator = array(
427
- '==' => __('Is', SG_POPUP_TEXT_DOMAIN),
428
- '!=' => __('Is not', SG_POPUP_TEXT_DOMAIN)
429
- );
430
-
431
- $targetInitialData = array(
432
- array('param' => 'select_role', 'operator' => '==', 'value' => '')
433
- );
434
-
435
- $targetDataParams['param'] = apply_filters('sgpbPopupSpecialEventsParams', $targetParams);
436
- $targetDataParams['operator'] = apply_filters('sgpbPopupConditionsOperator', $targetDataOperator);
437
-
438
- $targetDataParams['select_role'] = null;
439
-
440
- $targetAttrs = array(
441
- 'param' => array(
442
- 'htmlAttrs' => array(
443
- 'class' => 'js-sg-select2 js-select-basic sgpb-selectbox-settings',
444
- 'data-select-class' => 'js-select-basic',
445
- 'data-select-type' => 'basic',
446
- 'autocomplete' => 'off'
447
- ),
448
- 'infoAttrs' => array(
449
- 'label' => 'Condition',
450
- 'info' => __('Target visitors to show the popup by different conditions.', SG_POPUP_TEXT_DOMAIN)
451
- )
452
- ),
453
- 'operator' => array(
454
- 'htmlAttrs' => array(
455
- 'class' => 'js-sg-select2 js-select-basic',
456
- 'data-select-class' => 'js-select-basic',
457
- 'data-select-type' => 'basic'
458
- ),
459
- 'infoAttrs' => array(
460
- 'label' => 'Rule',
461
- 'info' => __('Allow or Disallow popup showing for the selected conditions.', SG_POPUP_TEXT_DOMAIN)
462
- )
463
- )
464
- );
465
-
466
- $popupConditions['columns'] = apply_filters('sgPopupConditionsColumns', $targetData);
467
- $popupConditions['columnTypes'] = apply_filters('sgPopupConditionsTypes', $targetElementTypes);
468
- $popupConditions['paramsData'] = apply_filters('sgPopupConditionsData', $targetDataParams);
469
- $popupConditions['initialData'] = apply_filters('sgPopupConditionsInitialData', $targetInitialData);
470
- $popupConditions['operators'] = apply_filters('sgPopupConditionsOperators', $targetOperators);
471
- $popupConditions['attrs'] = apply_filters('sgPopupConditionsAttrs', $targetAttrs);
472
-
473
- $popupConditions['specialDefaultOperator'] = apply_filters('sgPopupConditionsOperators', $targetDataOperator);
474
- $popupConditions['operatorAllowInConditions'] = apply_filters('sgPopupConditionsOperatorAllowInConditions', array());
475
-
476
- $SGPB_DATA_CONFIG_ARRAY['conditions'] = $popupConditions;
477
-
478
- $SGPB_DATA_CONFIG_ARRAY['behavior-after-special-events'] = self::getBehaviorAfterSpecialEventsConfig();
479
- $SGPB_DATA_CONFIG_ARRAY = apply_filters('sgpbConfigArray', $SGPB_DATA_CONFIG_ARRAY);
480
- /*Target condition config*/
481
- }
482
-
483
- public static function allFreeExtensionsKeys()
484
- {
485
- $keys = array();
486
-
487
- return $keys;
488
- }
489
-
490
- public static function allExtensionsKeys()
491
- {
492
- $keys = array();
493
- $keys[] = array(
494
- 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN),
495
- 'version' => '3.0',
496
- 'stable_version' => '3.0',
497
- 'pluginKey' => 'popupbuilder-adblock/PopupBuilderAdBlock.php',
498
- 'key' => 'sgpbAdBlock',
499
- 'url' => SG_POPUP_AD_BLOCK_URL
500
- );
501
- $keys[] = array(
502
- 'label' => __('Advanced Closing', SG_POPUP_TEXT_DOMAIN),
503
- 'version' => '2.0',
504
- 'stable_version' => '2.0',
505
- 'pluginKey' => 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php',
506
- 'key' => 'advancedClosing',
507
- 'url' => SG_POPUP_ADVANCED_CLOSING_URL
508
- );
509
- $keys[] = array(
510
- 'label' => __('Advanced Targeting', SG_POPUP_TEXT_DOMAIN),
511
- 'version' => '3.0',
512
- 'stable_version' => '3.0',
513
- 'pluginKey' => 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php',
514
- 'key' => 'sgpbAdvancedTargeting',
515
- 'url' => SG_POPUP_ADVANCED_TARGETING_URL
516
- );
517
- $keys[] = array(
518
- 'label' => __('Age Restriction', SG_POPUP_TEXT_DOMAIN),
519
- 'version' => '2.0',
520
- 'stable_version' => '2.0',
521
- 'pluginKey' => 'popupbuilder-age-verification/PopupBuilderAgeverification.php',
522
- 'key' => 'ageVerification',
523
- 'url' => SGPB_AGE_VERIFICATION_PLUGIN_URL
524
- );
525
- $keys[] = array(
526
- 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN),
527
- 'version' => '4.0',
528
- 'stable_version' => '4.0',
529
- 'pluginKey' => 'popupbuilder-analytics/PopupBuilderAnalytics.php',
530
- 'key' => 'sgpbAnalitics',
531
- 'url' => SG_POPUP_ANALYTICS_URL
532
- );
533
- $keys[] = array(
534
- 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN),
535
- 'version' => '3.0',
536
- 'stable_version' => '3.0',
537
- 'pluginKey' => 'popupbuilder-aweber/PopupBuilderAWeber.php',
538
- 'key' => 'sgpbAWeber',
539
- 'url' => SG_POPUP_AWEBER_URL
540
- );
541
- $keys[] = array(
542
- 'label' => __('Contact Form', SG_POPUP_TEXT_DOMAIN),
543
- 'version' => '3.0',
544
- 'stable_version' => '3.0',
545
- 'pluginKey' => 'popupbuilder-contact-form/PopupBuilderContactForm.php',
546
- 'key' => 'contactForm',
547
- 'url' => SG_POPUP_CONTACT_FORM_URL
548
- );
549
- $keys[] = array(
550
- 'label' => __('Countdown', SG_POPUP_TEXT_DOMAIN),
551
- 'version' => '3.0',
552
- 'stable_version' => '3.0',
553
- 'pluginKey' => 'popupbuilder-countdown/PopupBuilderCountdown.php',
554
- 'key' => 'countdown',
555
- 'url' => SG_POPUP_COUNTDOWN_URL
556
- );
557
- $keys[] = array(
558
- 'label' => __('EDD', SG_POPUP_TEXT_DOMAIN),
559
- 'version' => '2.0',
560
- 'stable_version' => '2.0',
561
- 'pluginKey' => 'popupbuilder-edd/PopupBuilderEdd.php',
562
- 'key' => 'edd',
563
- 'url' => SGPB_EDD_PLUGIN_URL
564
- );
565
- $keys[] = array(
566
- 'label' => __('Exit Intent',SG_POPUP_TEXT_DOMAIN),
567
- 'version' => '4.0',
568
- 'stable_version' => '4.0',
569
- 'pluginKey' => 'popupbuilder-exit-intent/PopupBuilderExitIntent.php',
570
- 'key' => 'sgpbExitIntent',
571
- 'url' => SG_POPUP_EXIT_INTENT_URL
572
- );
573
- $keys[] = array(
574
- 'label' => __('Gamification', SG_POPUP_TEXT_DOMAIN),
575
- 'version' => '2.0',
576
- 'stable_version' => '2.0',
577
- 'pluginKey' => 'popupbuilder-gamification/PopupBuilderGamification.php',
578
- 'key' => 'gamification',
579
- 'url' => SGPB_GAMIFICATION_PLUGIN_URL
580
- );
581
- $keys[] = array(
582
- 'label' => __('Geo Targeting', SG_POPUP_TEXT_DOMAIN),
583
- 'version' => '3.0',
584
- 'stable_version' => '3.0',
585
- 'pluginKey' => 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php',
586
- 'key' => 'geo-targeting',
587
- 'url' => SG_POPUP_GEO_TARGETING_URL
588
- );
589
- $keys[] = array(
590
- 'label' => __('Iframe', SG_POPUP_TEXT_DOMAIN),
591
- 'version' => '2.0',
592
- 'stable_version' => '2.0',
593
- 'pluginKey' => 'popupbuilder-iframe/PopupBuilderIframe.php',
594
- 'key' => 'iframe',
595
- 'url' => SG_POPUP_IFRAME_URL
596
- );
597
- $keys[] = array(
598
- 'label' => __('Inactivity', SG_POPUP_TEXT_DOMAIN),
599
- 'version' => '2.0',
600
- 'stable_version' => '2.0',
601
- 'pluginKey' => 'popupbuilder-inactivity/PopupBuilderInactivity.php',
602
- 'key' => 'sgpbInactivity',
603
- 'url' => SG_POPUP_INACTIVITY_URL
604
- );
605
- $keys[] = array(
606
- 'label' => __('Log In', SG_POPUP_TEXT_DOMAIN),
607
- 'version' => '3.0',
608
- 'stable_version' => '3.0',
609
- 'pluginKey' => 'popupbuilder-login/PopupBuilderLogin.php',
610
- 'key' => 'login',
611
- 'url' => SG_POPUP_LOGIN_URL
612
- );
613
- $keys[] = array(
614
- 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN),
615
- 'version' => '4.0',
616
- 'stable_version' => '4.0',
617
- 'pluginKey' => 'popupbuilder-mailchimp/PopupBuilderMailchimp.php',
618
- 'key' => 'sgpbMailchimp',
619
- 'url' => SG_POPUP_MAILCHIMP_URL
620
- );
621
- $keys[] = array(
622
- 'label' => __('PDF', SG_POPUP_TEXT_DOMAIN),
623
- 'version' => '2.0',
624
- 'stable_version' => '2.0',
625
- 'pluginKey' => 'popupbuilder-pdf/PopupBuilderPdf.php',
626
- 'key' => 'pdf',
627
- 'url' => SGPB_PDF_PLUGIN_URL
628
- );
629
- $keys[] = array(
630
- 'label' => __('Push Notification', SG_POPUP_TEXT_DOMAIN),
631
- 'version' => '2.0',
632
- 'stable_version' => '2.0',
633
- 'pluginKey' => 'popupbuilder-push-notification/PopupBuilderPushNotification.php',
634
- 'key' => 'pushNotification',
635
- 'url' => SG_POPUP_PUSH_NOTIFICATION_URL
636
- );
637
- $keys[] = array(
638
- 'label' => __('Random', SG_POPUP_TEXT_DOMAIN),
639
- 'version' => '2.0',
640
- 'stable_version' => '2.0',
641
- 'pluginKey' => 'popupbuilder-random/PopupBuilderRandom.php',
642
- 'key' => 'sgpbRandom',
643
- 'url' => SG_POPUP_RANDOM_URL
644
- );
645
- $keys[] = array(
646
- 'label' => __('Recent Sales', SG_POPUP_TEXT_DOMAIN),
647
- 'version' => '2.0',
648
- 'stable_version' => '2.0',
649
- 'pluginKey' => 'popupbuilder-recent-sales/PopupBuilderRecentSales.php',
650
- 'key' => 'sgpbRecentSales',
651
- 'url' => SG_POPUP_RECENT_SALES_URL
652
- );
653
- $keys[] = array(
654
- 'label' => __('Registration', SG_POPUP_TEXT_DOMAIN),
655
- 'version' => '2.0',
656
- 'stable_version' => '2.0',
657
- 'pluginKey' => 'popupbuilder-registration/PopupBuilderRegistration.php',
658
- 'key' => 'registration',
659
- 'url' => SG_POPUP_REGISTRATION_URL
660
- );
661
- $keys[] = array(
662
- 'label' => __('Restriction', SG_POPUP_TEXT_DOMAIN),
663
- 'version' => '3.0',
664
- 'stable_version' => '3.0',
665
- 'pluginKey' => 'popupbuilder-restriction/PopupBuilderAgerestriction.php',
666
- 'key' => 'ageRestriction',
667
- 'url' => SG_POPUP_RESTRICTION_URL
668
- );
669
- $keys[] = array(
670
- 'label' => __('Scheduling', SG_POPUP_TEXT_DOMAIN),
671
- 'version' => '2.0',
672
- 'stable_version' => '2.0',
673
- 'pluginKey' => 'popupbuilder-scheduling/PopupBuilderScheduling.php',
674
- 'key' => 'scheduling',
675
- 'url' => SG_POPUP_SCHEDULING_URL
676
- );
677
- $keys[] = array(
678
- 'label' => __('Scroll', SG_POPUP_TEXT_DOMAIN),
679
- 'version' => '3.0',
680
- 'stable_version' => '3.0',
681
- 'pluginKey' => 'popupbuilder-scroll/PopupBuilderScroll.php',
682
- 'key' => 'sgpbScroll',
683
- 'url' => SG_POPUP_SCROLL_URL
684
- );
685
- $keys[] = array(
686
- 'label' => __('Social', SG_POPUP_TEXT_DOMAIN),
687
- 'version' => '2.0',
688
- 'stable_version' => '2.0',
689
- 'pluginKey' => 'popupbuilder-social/PopupBuilderSocial.php',
690
- 'key' => 'social',
691
- 'url' => SG_POPUP_SOCIAL_URL
692
- );
693
- $keys[] = array(
694
- 'label' => __('Subscription Plus', SG_POPUP_TEXT_DOMAIN),
695
- 'version' => '4.0',
696
- 'stable_version' => '4.0',
697
- 'pluginKey' => 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php',
698
- 'key' => 'subscriptionPlus',
699
- 'url' => SG_POPUP_SUBSCRIPTION_PLUS_URL
700
- );
701
- $keys[] = array(
702
- 'label' => __('Video', SG_POPUP_TEXT_DOMAIN),
703
- 'version' => '2.0',
704
- 'stable_version' => '2.0',
705
- 'pluginKey' => 'popupbuilder-video/PopupBuilderVideo.php',
706
- 'key' => 'video',
707
- 'url' => SG_POPUP_VIDEO_URL
708
- );
709
- $keys[] = array(
710
- 'label' => __('WooCommerce', SG_POPUP_TEXT_DOMAIN),
711
- 'version' => '3.0',
712
- 'stable_version' => '3.0',
713
- 'pluginKey' => 'popupbuilder-woocommerce/popupbuilderWoocommerce.php',
714
- 'key' => 'sgpbWOO',
715
- 'url' => SG_POPUP_WOOCOMMERCE_URL
716
- );
717
-
718
- return apply_filters('sgpbExtensionsKeys', $keys);
719
- }
720
-
721
- private static function getBehaviorAfterSpecialEventsConfig()
722
- {
723
- $columns = array(
724
- 'param' => 'Event',
725
- 'operator' => 'Behavior',
726
- 'value' => 'Value'
727
- );
728
-
729
- $columnTypes = array(
730
- 'param' => 'select',
731
- 'operator' => 'select',
732
- 'value' => 'select',
733
- 'select_event' => 'select',
734
- 'select_behavior' => 'select',
735
- 'redirect-url' => 'url',
736
- 'open-popup' => 'select',
737
- 'close-popup' => 'number'
738
- );
739
-
740
- $params = array(
741
- 'param' => array(
742
- 'select_event' => __('Select event', SG_POPUP_TEXT_DOMAIN),
743
- __('Special events', SG_POPUP_TEXT_DOMAIN) => array(
744
- SGPB_CONTACT_FORM_7_BEHAVIOR_KEY => __('Contact Form 7 submission', SG_POPUP_TEXT_DOMAIN)
745
- )
746
- ),
747
- 'operator' => array(
748
- 'select_behavior' => __('Select behavior', SG_POPUP_TEXT_DOMAIN),
749
- __('Behaviors', SG_POPUP_TEXT_DOMAIN) => array(
750
- 'redirect-url' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN),
751
- 'open-popup' => __('Open another popup', SG_POPUP_TEXT_DOMAIN),
752
- 'close-popup' => __('Close current popup', SG_POPUP_TEXT_DOMAIN)
753
- )
754
- ),
755
- 'redirect-url' => '',
756
- 'open-popup' => array(),
757
- 'close-popup' => '',
758
- 'select_event' => null,
759
- 'select_behavior' => null
760
- );
761
-
762
- $initialData = array(
763
- array(
764
- 'param' => 'select_event',
765
- 'operator' => ''
766
- )
767
- );
768
-
769
- $attrs = array(
770
- 'param' => array(
771
- 'htmlAttrs' => array(
772
- 'class' => 'js-sg-select2 js-select-basic',
773
- 'data-select-class' => 'js-select-basic',
774
- 'data-select-type' => 'basic'
775
- ),
776
- 'infoAttrs' => array(
777
- 'label' => __('Event', SG_POPUP_TEXT_DOMAIN),
778
- 'info' => __('Select the special event you want to catch.', SG_POPUP_TEXT_DOMAIN)
779
- )
780
- ),
781
- 'operator' => array(
782
- 'htmlAttrs' => array(
783
- 'class' => 'js-sg-select2 js-select-basic',
784
- 'data-select-class' => 'js-select-basic',
785
- 'data-select-type' => 'basic'
786
- ),
787
- 'infoAttrs' => array(
788
- 'label' => __('Behavior', SG_POPUP_TEXT_DOMAIN),
789
- 'info' => __('Select what should happen after the special event.', SG_POPUP_TEXT_DOMAIN)
790
- )
791
- ),
792
- 'redirect-url' => array(
793
- 'htmlAttrs' => array(
794
- 'class' => 'sg-full-width formItem__input formItem__input_select2_num_input',
795
- 'placeholder' => 'https://www.example.com',
796
- 'required' => 'required'
797
- ),
798
- 'infoAttrs' => array(
799
- 'label' => __('URL', SG_POPUP_TEXT_DOMAIN),
800
- 'info' => __('Enter the URL of the page should be redirected to.', SG_POPUP_TEXT_DOMAIN)
801
- )
802
- ),
803
- 'open-popup' => array(
804
- 'htmlAttrs' => array(
805
- 'class' => 'js-sg-select2 js-select-ajax',
806
- 'data-select-class' => 'js-select-ajax',
807
- 'data-select-type' => 'ajax',
808
- 'data-value-param' => SG_POPUP_POST_TYPE,
809
- 'required' => 'required'
810
- ),
811
- 'infoAttrs' => array(
812
- 'label' => __('Select popup', SG_POPUP_TEXT_DOMAIN),
813
- 'info' => __('Select the popup that should be opened.', SG_POPUP_TEXT_DOMAIN)
814
- )
815
- ),
816
- 'close-popup' => array(
817
- 'htmlAttrs' => array(
818
- 'class' => 'sg-full-width formItem__input formItem__input_select2_num_input',
819
- 'required' => 'required',
820
- 'value' => 0,
821
- 'min' => 0
822
- ),
823
- 'infoAttrs' => array(
824
- 'label' => __('Delay', SG_POPUP_TEXT_DOMAIN),
825
- 'info' => __('After how many seconds the popup should close.', SG_POPUP_TEXT_DOMAIN)
826
- )
827
- )
828
- );
829
-
830
- $config = array();
831
- $config['columns'] = apply_filters('sgPopupSpecialEventsColumns', $columns);
832
- $config['columnTypes'] = apply_filters('sgPopupSpecialEventsColumnTypes', $columnTypes);
833
- $config['paramsData'] = apply_filters('sgPopupSpecialEventsParams', $params);
834
- $config['initialData'] = apply_filters('sgPopupSpecialEventsInitialData', $initialData);
835
- $config['attrs'] = apply_filters('sgPopupSpecialEventsAttrs', $attrs);
836
- $config['operators'] = apply_filters('sgpbPopupSpecialEventsOperators', array());
837
- $config['specialDefaultOperator'] = apply_filters('sgpbPopupSpecialEventsDefaultOperators', ' ');
838
-
839
- return $config;
840
- }
841
-
842
- public static function popupDefaultOptions()
843
- {
844
- global $SGPB_OPTIONS;
845
- global $SGPB_DATA_CONFIG_ARRAY;
846
-
847
- $targetDefaultValue = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
848
-
849
- $eventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['events']['initialData']);
850
- $conditionsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['conditions']['initialData']);
851
- $specialEventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['behavior-after-special-events']['initialData']);
852
-
853
- $options = array();
854
-
855
- $options[] = array('name' => 'sgpb-target', 'type' => 'array', 'defaultValue' => $targetDefaultValue);
856
- $options[] = array('name' => 'sgpb-events', 'type' => 'array', 'defaultValue' => $eventsDefaultData);
857
- $options[] = array('name' => 'sgpb-conditions', 'type' => 'array', 'defaultValue' => $conditionsDefaultData, 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
858
- $options[] = array('name' => 'sgpb-behavior-after-special-events', 'type' => 'array', 'defaultValue' => $specialEventsDefaultData);
859
- $options[] = array('name' => 'sgpb-type', 'type' => 'text', 'defaultValue' => 'html');
860
- $options[] = array('name' => 'sgpb-popup-counting-disabled', 'type' => 'checkbox', 'defaultValue' => '');
861
- $options[] = array('name' => 'sgpb-esc-key', 'type' => 'checkbox', 'defaultValue' => 'on');
862
- $options[] = array('name' => 'sgpb-enable-close-button', 'type' => 'checkbox', 'defaultValue' => 'on');
863
- $options[] = array('name' => 'sgpb-enable-content-scrolling', 'type' => 'checkbox', 'defaultValue' => 'on');
864
- $options[] = array('name' => 'sgpb-overlay-click', 'type' => 'checkbox', 'defaultValue' => 'on');
865
- $options[] = array('name' => 'sgpb-content-click', 'type' => 'checkbox', 'defaultValue' => '');
866
- $options[] = array('name' => 'sgpb-subs-hide-subs-users', 'type' => 'checkbox', 'defaultValue' => 'on');
867
- $options[] = array('name' => 'sgpb-content-click-behavior', 'type' => 'text', 'defaultValue' => 'close');
868
- $options[] = array('name' => 'sgpb-click-redirect-to-url', 'type' => 'text', 'defaultValue' => '');
869
- $options[] = array('name' => 'sgpb-redirect-to-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
870
- $options[] = array('name' => 'sgpb-copy-to-clipboard-text', 'type' => 'text', 'defaultValue' => '');
871
- $options[] = array('name' => 'sgpb-copy-to-clipboard-close-popup', 'type' => 'checkbox', 'defaultValue' => 'on');
872
- $options[] = array('name' => 'sgpb-copy-to-clipboard-alert', 'type' => 'checkbox', 'defaultValue' => 'on');
873
- $options[] = array('name' => 'sgpb-copy-to-clipboard-message', 'type' => 'text', 'defaultValue' => __('Copied to Clipboard!', SG_POPUP_TEXT_DOMAIN));
874
- $options[] = array('name' => 'sgpb-disable-popup-closing', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
875
- $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => 'responsiveMode');
876
- $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => '100');
877
- $options[] = array('name' => 'sgpb-width', 'type' => 'text', 'defaultValue' => '640px');
878
- $options[] = array('name' => 'sgpb-height', 'type' => 'text', 'defaultValue' => '480px');
879
- $options[] = array('name' => 'sgpb-max-width', 'type' => 'text', 'defaultValue' => '');
880
- $options[] = array('name' => 'sgpb-max-height', 'type' => 'text', 'defaultValue' => '');
881
- $options[] = array('name' => 'sgpb-min-width', 'type' => 'text', 'defaultValue' => '120px');
882
- $options[] = array('name' => 'sgpb-min-height', 'type' => 'text', 'defaultValue' => '');
883
- $options[] = array('name' => 'sgpb-popup-timer-status', 'type' => 'checkbox', 'defaultValue' => '');
884
- $options[] = array('name' => 'sgpb-popup-start-timer', 'type' => 'text', 'defaultValue' => '');
885
- $options[] = array('name' => 'sgpb-popup-end-timer', 'type' => 'text', 'defaultValue' => '');
886
- $options[] = array('name' => 'sgpb-popup-fixed', 'type' => 'checkbox', 'defaultValue' => '');
887
- $options[] = array('name' => 'sgpb-popup-fixed-position', 'type' => 'text', 'defaultValue' => '');
888
- $options[] = array('name' => 'sgpb-popup-delay', 'type' => 'text', 'defaultValue' => '0');
889
- $options[] = array('name' => 'sgpb-popup-order', 'type' => 'text', 'defaultValue' => '0');
890
- $options[] = array('name' => 'sgpb-disable-page-scrolling', 'type' => 'checkbox', 'defaultValue' => '');
891
- $options[] = array('name' => 'sgpb-content-padding', 'type' => 'text', 'defaultValue' => 7);
892
- $options[] = array('name' => 'sgpb-popup-z-index', 'type' => 'text', 'defaultValue' => 9999);
893
- $options[] = array('name' => 'sgpb-content-custom-class', 'type' => 'text', 'defaultValue' => 'sg-popup-content');
894
- $options[] = array('name' => 'sgpb-close-after-page-scroll', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
895
- $options[] = array('name' => 'sgpb-auto-close', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
896
- $options[] = array('name' => 'sgpb-auto-close-time', 'type' => 'number', 'defaultValue' => 0);
897
- $options[] = array('name' => 'sgpb-reopen-after-form-submission', 'type' => 'checkbox', 'defaultValue' => '');
898
- $options[] = array('name' => 'sgpb-open-sound', 'type' => 'checkbox', 'defaultValue' => '');
899
- $options[] = array('name' => 'sgpb-sound-url', 'type' => 'text', 'defaultValue' => SG_POPUP_SOUND_URL.SGPB_POPUP_DEFAULT_SOUND);
900
- $options[] = array('name' => 'sgpb-open-animation', 'type' => 'checkbox', 'defaultValue' => '');
901
- $options[] = array('name' => 'sgpb-close-animation', 'type' => 'checkbox', 'defaultValue' => '');
902
- $options[] = array('name' => 'sgpb-open-animation-speed', 'type' => 'text', 'defaultValue' => 1);
903
- $options[] = array('name' => 'sgpb-close-animation-speed', 'type' => 'text', 'defaultValue' => 1);
904
- $options[] = array('name' => 'sgpb-popup-themes', 'type' => 'text', 'defaultValue' => 'sgpb-theme-1');
905
- $options[] = array('name' => 'sgpb-enable-popup-overlay', 'type' => 'checkbox', 'defaultValue' => 'on', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
906
- $options[] = array('name' => 'sgpb-overlay-custom-class', 'type' => 'text', 'defaultValue' => 'sgpb-popup-overlay');
907
- $options[] = array('name' => 'sgpb-overlay-color', 'type' => 'text', 'defaultValue' => '');
908
- $options[] = array('name' => 'sgpb-background-color', 'type' => 'text', 'defaultValue' => '');
909
- $options[] = array('name' => 'sgpb-overlay-opacity', 'type' => 'text', 'defaultValue' => 0.8);
910
- $options[] = array('name' => 'sgpb-content-opacity', 'type' => 'text', 'defaultValue' => 0.8);
911
- $options[] = array('name' => 'sgpb-background-image', 'type' => 'text', 'defaultValue' => '');
912
- $options[] = array('name' => 'sgpb-show-background', 'type' => 'checkbox', 'defaultValue' => '');
913
- $options[] = array('name' => 'sgpb-force-rtl', 'type' => 'checkbox', 'defaultValue' => '');
914
- $options[] = array('name' => 'sgpb-disable-border', 'type' => 'checkbox', 'defaultValue' => '');
915
- $options[] = array('name' => 'sgpb-background-image-mode', 'type' => 'text', 'defaultValue' => 'no-repeat');
916
- $options[] = array('name' => 'sgpb-image-url', 'type' => 'text', 'defaultValue' => '');
917
- $options[] = array('name' => 'sgpb-close-button-delay', 'type' => 'number', 'defaultValue' => 0);
918
- $options[] = array('name' => 'sgpb-button-position-bottom', 'type' => 'number', 'defaultValue' => 9);
919
- $options[] = array('name' => 'sgpb-button-position-right', 'type' => 'number', 'defaultValue' => 9);
920
- $options[] = array('name' => 'sgpb-button-image', 'type' => 'text', 'defaultValue' => '');
921
- $options[] = array('name' => 'sgpb-button-image-width', 'type' => 'text', 'defaultValue' => 21);
922
- $options[] = array('name' => 'sgpb-button-image-height', 'type' => 'text', 'defaultValue' => 21);
923
- $options[] = array('name' => 'sgpb-is-active', 'type' => 'checkbox', 'defaultValue' => 'on');
924
- $options[] = array('name' => 'sgpb-subs-form-bg-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
925
- $options[] = array('name' => 'sgpb-subs-form-bg-opacity', 'type' => 'text', 'defaultValue' => 0.8);
926
- $options[] = array('name' => 'sgpb-subs-form-padding', 'type' => 'number', 'defaultValue' => 2);
927
- $options[] = array('name' => 'sgpb-subs-email-placeholder', 'type' => 'text', 'defaultValue' => __('Email *', SG_POPUP_TEXT_DOMAIN));
928
- $options[] = array('name' => 'sgpb-subs-first-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
929
- $options[] = array('name' => 'sgpb-subs-first-placeholder', 'type' => 'text', 'defaultValue' => __('First name', SG_POPUP_TEXT_DOMAIN));
930
- $options[] = array('name' => 'sgpb-subs-first-name-required', 'type' => 'checkbox', 'defaultValue' => '');
931
- $options[] = array('name' => 'sgpb-subs-last-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
932
- $options[] = array('name' => 'sgpb-subs-last-placeholder', 'type' => 'text', 'defaultValue' => __('Last name', SG_POPUP_TEXT_DOMAIN));
933
- $options[] = array('name' => 'sgpb-subs-last-name-required', 'type' => 'checkbox', 'defaultValue' => '');
934
- $options[] = array('name' => 'sgpb-subs-validation-message', 'type' => 'text', 'defaultValue' => __('This field is required.', SG_POPUP_TEXT_DOMAIN));
935
- $options[] = array('name' => 'sgpb-subs-text-width', 'type' => 'text', 'defaultValue' => '300px');
936
- $options[] = array('name' => 'sgpb-subs-text-height', 'type' => 'text', 'defaultValue' => '40px');
937
- $options[] = array('name' => 'sgpb-subs-text-border-width', 'type' => 'text', 'defaultValue' => '2px');
938
- $options[] = array('name' => 'sgpb-subs-text-border-color', 'type' => 'text', 'defaultValue' => '#e8e8e8');
939
- $options[] = array('name' => 'sgpb-subs-text-bg-color', 'type' => 'text', 'defaultValue' => '#f1f1f1');
940
- $options[] = array('name' => 'sgpb-subs-text-color', 'type' => 'text', 'defaultValue' => '#000000');
941
- $options[] = array('name' => 'sgpb-subs-text-placeholder-color', 'type' => 'text', 'defaultValue' => '#757575');
942
- $options[] = array('name' => 'sgpb-subs-btn-width', 'type' => 'text', 'defaultValue' => '300px');
943
- $options[] = array('name' => 'sgpb-subs-btn-height', 'type' => 'text', 'defaultValue' => '40px');
944
- $options[] = array('name' => 'sgpb-subs-btn-border-radius', 'type' => 'text', 'defaultValue' => '4px');
945
- $options[] = array('name' => 'sgpb-subs-btn-border-width', 'type' => 'text', 'defaultValue' => '0px');
946
- $options[] = array('name' => 'sgpb-subs-btn-border-color', 'type' => 'text', 'defaultValue' => '#007fe1');
947
- $options[] = array('name' => 'sgpb-subs-btn-title', 'type' => 'text', 'defaultValue' => __('Subscribe', SG_POPUP_TEXT_DOMAIN));
948
- $options[] = array('name' => 'sgpb-subs-btn-progress-title', 'type' => 'text', 'defaultValue' => __('Please wait...', SG_POPUP_TEXT_DOMAIN));
949
- $options[] = array('name' => 'sgpb-subs-btn-bg-color', 'type' => 'text', 'defaultValue' => '#007fe1');
950
- $options[] = array('name' => 'sgpb-subs-btn-text-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
951
- $options[] = array('name' => 'sgpb-subs-error-message', 'type' => 'text', 'defaultValue' => SGPB_SUBSCRIPTION_ERROR_MESSAGE);
952
- $options[] = array('name' => 'sgpb-subs-invalid-message', 'type' => 'text', 'defaultValue' => __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
953
- $options[] = array('name' => 'sgpb-subs-success-behavior', 'type' => 'text', 'defaultValue' => 'showMessage');
954
- $options[] = array('name' => 'sgpb-subs-success-message', 'type' => 'text', 'defaultValue' => __('You have successfully subscribed to the newsletter', SG_POPUP_TEXT_DOMAIN));
955
- $options[] = array('name' => 'sgpb-subs-success-redirect-URL', 'type' => 'text', 'defaultValue' => '');
956
- $options[] = array('name' => 'sgpb-subs-success-redirect-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
957
- $options[] = array('name' => 'sgpb-subs-gdpr-status', 'type' => 'checkbox', 'defaultValue' => '');
958
- $options[] = array('name' => 'sgpb-subs-show-form-to-top', 'type' => 'checkbox', 'defaultValue' => '');
959
- $options[] = array('name' => 'sgpb-subs-gdpr-label', 'type' => 'text', 'defaultValue' => __('Accept Terms', SG_POPUP_TEXT_DOMAIN));
960
- $options[] = array('name' => 'sgpb-subs-gdpr-text', 'type' => 'text', 'defaultValue' => __(get_bloginfo().' will use the information you provide on this form to be in touch with you and to provide updates and marketing.', SG_POPUP_TEXT_DOMAIN));
961
- $options[] = array('name' => 'sgpb-subs-fields', 'type' => 'sgpb', 'defaultValue' => '');
962
- $options[] = array('name' => 'sgpb-fblike-like-url', 'type' => 'text', 'defaultValue' => '');
963
- $options[] = array('name' => 'sgpb-fblike-layout', 'type' => 'text', 'defaultValue' => 'standard');
964
- $options[] = array('name' => 'sgpb-fblike-dont-show-share-button', 'type' => 'checkbox', 'defaultValue' => '');
965
- $options[] = array('name' => 'sgpb-border-color', 'type' => 'text', 'defaultValue' => '#000000');
966
- $options[] = array('name' => 'sgpb-border-radius', 'type' => 'text', 'defaultValue' => 0);
967
- $options[] = array('name' => 'sgpb-show-popup-same-user', 'type' => 'checkbox', 'defaultValue' => '');
968
- $options[] = array('name' => 'sgpb-show-popup-same-user-count', 'type' => 'number', 'defaultValue' => 1);
969
- $options[] = array('name' => 'sgpb-show-popup-same-user-expiry', 'type' => 'number', 'defaultValue' => 1);
970
- $options[] = array('name' => 'sgpb-show-popup-same-user-page-level', 'type' => 'checkbox', 'defaultValue' => '');
971
-
972
- $options[] = array('name' => 'sgpb-enable-floating-button', 'type' => 'checkbox', 'defaultValue' => '');
973
- $options[] = array('name' => 'sgpb-floating-button-style', 'type' => 'text', 'defaultValue' => 'corner');
974
- $options[] = array('name' => 'sgpb-floating-button-position', 'type' => 'text', 'defaultValue' => 'bottom-right');
975
- $options[] = array('name' => 'sgpb-floating-button-position-top', 'type' => 'text', 'defaultValue' => '40');
976
- $options[] = array('name' => 'sgpb-floating-button-position-right', 'type' => 'text', 'defaultValue' => '50');
977
- $options[] = array('name' => 'sgpb-floating-button-font-size', 'type' => 'number', 'defaultValue' => 16);
978
- $options[] = array('name' => 'sgpb-floating-button-border-size', 'type' => 'number', 'defaultValue' => 5);
979
- $options[] = array('name' => 'sgpb-floating-button-border-radius', 'type' => 'number', 'defaultValue' => 5);
980
- $options[] = array('name' => 'sgpb-floating-button-border-color', 'type' => 'text', 'defaultValue' => '#5263eb');
981
- $options[] = array('name' => 'sgpb-floating-button-bg-color', 'type' => 'text', 'defaultValue' => '#5263eb');
982
- $options[] = array('name' => 'sgpb-floating-button-text-color', 'type' => 'text', 'defaultValue' => '#ffffff');
983
- $options[] = array('name' => 'sgpb-floating-button-text', 'type' => 'text', 'defaultValue' => __('Click it!'));
984
-
985
- $SGPB_OPTIONS = apply_filters('sgpbPopupDefaultOptions', $options);
986
- }
987
-
988
- public static function getOldExtensionsInfo()
989
- {
990
- $data = array(
991
- array(
992
- 'folderName' => 'popup-builder-ad-block',
993
- 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN)
994
- ),
995
- array(
996
- 'folderName' => 'popup-builder-analytics',
997
- 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN)
998
- ),
999
- array(
1000
- 'folderName' => 'popup-builder-exit-intent',
1001
- 'label' => __('Exit intent', SG_POPUP_TEXT_DOMAIN)
1002
- ),
1003
- array(
1004
- 'folderName' => 'popup-builder-mailchimp',
1005
- 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN)
1006
- ),
1007
- array(
1008
- 'folderName' => 'popup-builder-aweber',
1009
- 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN)
1010
- )
1011
- );
1012
-
1013
- return $data;
1014
- }
1015
-
1016
- public static function addFilters()
1017
- {
1018
- ConfigDataHelper::addFilters();
1019
- }
1020
-
1021
- public static function transientConfig()
1022
- {
1023
- global $SGPB_TRANSIENT_CONFIG;
1024
-
1025
- $SGPB_TRANSIENT_CONFIG = array(
1026
- SGPB_TRANSIENT_POPUPS_LOAD,
1027
- SGPB_TRANSIENT_POPUPS_TERMS,
1028
- SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES
1029
- );
1030
-
1031
- $SGPB_TRANSIENT_CONFIG = apply_filters('sgpbAllTransients', $SGPB_TRANSIENT_CONFIG);
1032
- }
1033
- }
1
+ <?php
2
+ require_once(SG_POPUP_HELPERS_PATH.'ConfigDataHelper.php');
3
+ use sgpb\PopupBuilderActivePackage;
4
+ class SgpbDataConfig
5
+ {
6
+ public static function init()
7
+ {
8
+ self::addFilters();
9
+ self::conditionInit();
10
+ self::transientConfig();
11
+ self::popupDefaultOptions();
12
+ }
13
+
14
+ public static function conditionInit()
15
+ {
16
+ global $SGPB_DATA_CONFIG_ARRAY;
17
+
18
+ /*Target condition config*/
19
+ $targetData = array('param' => 'Pages', 'operator' => 'Is not', 'value' => 'Value');
20
+ $targetElementTypes = array(
21
+ 'param' => 'select',
22
+ 'operator' => 'select',
23
+ 'value' => 'select',
24
+ 'post_selected' => 'select',
25
+ 'page_selected' => 'select',
26
+ 'post_type' => 'select',
27
+ 'post_category' => 'select',
28
+ 'page_type' => 'select',
29
+ 'page_template' => 'select',
30
+ 'post_tags_ids' => 'select'
31
+ );
32
+
33
+ $targetParams = array(
34
+ 'not_rule' => __('Select rule', SG_POPUP_TEXT_DOMAIN),
35
+ 'everywhere' => __('Everywhere', SG_POPUP_TEXT_DOMAIN),
36
+ 'Post' => array(
37
+ 'post_all' => __('All posts', SG_POPUP_TEXT_DOMAIN),
38
+ 'post_selected' => __('Selected posts', SG_POPUP_TEXT_DOMAIN),
39
+ 'post_type' => __('Post type', SG_POPUP_TEXT_DOMAIN),
40
+ 'post_category' => __('Post category', SG_POPUP_TEXT_DOMAIN)
41
+ ),
42
+ 'Page' => array(
43
+ 'page_all' => __('All pages', SG_POPUP_TEXT_DOMAIN),
44
+ 'page_selected' => __('Selected pages', SG_POPUP_TEXT_DOMAIN),
45
+ 'page_type' => __('Page type', SG_POPUP_TEXT_DOMAIN),
46
+ 'page_template' => __('Page template', SG_POPUP_TEXT_DOMAIN)
47
+ ),
48
+ 'Tags' => array(
49
+ 'post_tags' => __('All tags', SG_POPUP_TEXT_DOMAIN),
50
+ 'post_tags_ids' => __('Selected tags', SG_POPUP_TEXT_DOMAIN)
51
+ )
52
+ );
53
+
54
+ $targetOperators = array(
55
+ array('operator' => 'add', 'name' => __('Add', SG_POPUP_TEXT_DOMAIN)),
56
+ array('operator' => 'delete', 'name' => __('Delete', SG_POPUP_TEXT_DOMAIN))
57
+ );
58
+
59
+ $targetDataOperator = array(
60
+ '==' => __('Is', SG_POPUP_TEXT_DOMAIN),
61
+ '!=' => __('Is not', SG_POPUP_TEXT_DOMAIN)
62
+ );
63
+ $targetInitialData = array(
64
+ array('param' => 'everywhere')
65
+ );
66
+
67
+ $targetDataParams['param'] = apply_filters('sgPopupTargetParams', $targetParams);
68
+ $targetDataParams['operator'] = apply_filters('sgPopupTargetOperator', $targetDataOperator);
69
+ $targetDataParams['post_selected'] = apply_filters('sgPopupTargetPostData', array());
70
+ $targetDataParams['page_selected'] = apply_filters('sgPopupTargetPageSelected', array());
71
+ $targetDataParams['post_type'] = apply_filters('sgPopupTargetPostType', ConfigDataHelper::getAllCustomPostTypes());
72
+ $targetDataParams['post_category'] = apply_filters('sgPopupTargetPostCategory', ConfigDataHelper::getPostsAllCategories());
73
+ $targetDataParams['page_type'] = apply_filters('sgPopupTargetPageType', ConfigDataHelper::getPageTypes());
74
+ $targetDataParams['page_template'] = apply_filters('sgPopupPageTemplates', array());
75
+ $targetDataParams['post_tags_ids'] = apply_filters('sgPopupTags', ConfigDataHelper::getAllTags());
76
+ $targetDataParams['everywhere'] = null;
77
+ $targetDataParams['not_rule'] = null;
78
+ $targetDataParams['post_all'] = null;
79
+ $targetDataParams['page_all'] = null;
80
+ $targetDataParams['post_tags'] = null;
81
+
82
+ $targetAttrs = array(
83
+ 'param' => array(
84
+ 'htmlAttrs' => array(
85
+ 'class' => 'js-sg-select2 js-select-basic',
86
+ 'data-select-class' => 'js-select-basic',
87
+ 'data-select-type' => 'basic',
88
+ 'autocomplete' => 'off'
89
+ ),
90
+ 'infoAttrs' => array(
91
+ 'label' => 'Display rule',
92
+ 'info' => __('Specify where the popup should be shown on your site.', SG_POPUP_TEXT_DOMAIN)
93
+ )
94
+
95
+ ),
96
+ 'operator' => array(
97
+ 'htmlAttrs' => array(
98
+ 'class' => 'js-sg-select2 js-select-basic',
99
+ 'data-select-class' => 'js-select-basic',
100
+ 'data-select-type' => 'basic'
101
+ ),
102
+ 'infoAttrs' => array(
103
+ 'label' => 'Is or is not',
104
+ 'info' => __('Allow or Disallow popup showing for the selected rule.', SG_POPUP_TEXT_DOMAIN)
105
+ )
106
+ ),
107
+ 'post_selected' => array(
108
+ 'htmlAttrs' => array(
109
+ 'class' => 'js-sg-select2 js-select-ajax',
110
+ 'data-select-class' => 'js-select-ajax',
111
+ 'data-select-type' => 'ajax',
112
+ 'data-value-param' => 'post',
113
+ 'multiple' => 'multiple'
114
+ ),
115
+ 'infoAttrs' => array(
116
+ 'label' => 'Select Your Posts',
117
+ 'info' => __('Select your specific posts where the popup should be shown.', SG_POPUP_TEXT_DOMAIN)
118
+ )
119
+ ),
120
+ 'page_selected' => array(
121
+ 'htmlAttrs' => array(
122
+ 'class' => 'js-sg-select2 js-select-ajax',
123
+ 'data-select-class' => 'js-select-ajax',
124
+ 'data-select-type' => 'ajax',
125
+ 'data-value-param' => 'page',
126
+ 'multiple' => 'multiple'
127
+ ),
128
+ 'infoAttrs' => array(
129
+ 'label' => 'Select Your Pages',
130
+ 'info' => __('Select the pages on your site where the specific popup will be shown.', SG_POPUP_TEXT_DOMAIN)
131
+ )
132
+ ),
133
+ 'post_type' => array(
134
+ 'htmlAttrs' => array(
135
+ 'class' => 'js-sg-select2 js-select-ajax',
136
+ 'data-select-class' => 'js-select-ajax',
137
+ 'data-select-type' => 'multiple',
138
+ 'data-value-param' => 'postTypes',
139
+ 'isNotPostType' => true,
140
+ 'multiple' => 'multiple'
141
+ ),
142
+ 'infoAttrs' => array(
143
+ 'label' => 'Select Your post types',
144
+ 'info' => __('Specify the post types on your site to show the popup.', SG_POPUP_TEXT_DOMAIN)
145
+ )
146
+ ),
147
+ 'post_category' => array(
148
+ 'htmlAttrs' => array(
149
+ 'class' => 'js-sg-select2 js-select-ajax',
150
+ 'data-select-class' => 'js-select-ajax',
151
+ 'data-select-type' => 'multiple',
152
+ 'data-value-param' => 'postCategories',
153
+ 'isNotPostType' => true,
154
+ 'multiple' => 'multiple'
155
+ ),
156
+ 'infoAttrs' => array(
157
+ 'label' => 'Select post categories',
158
+ 'info' => __('Select the post categories on which the popup should be shown.', SG_POPUP_TEXT_DOMAIN)
159
+ )
160
+ ),
161
+ 'page_type' => array(
162
+ 'htmlAttrs' => array(
163
+ 'class' => 'js-sg-select2 js-select-ajax',
164
+ 'data-select-class' => 'js-select-ajax',
165
+ 'data-select-type' => 'multiple',
166
+ 'data-value-param' => 'postCategories',
167
+ 'isNotPostType' => true,
168
+ 'multiple' => 'multiple'
169
+ ),
170
+ 'infoAttrs' => array(
171
+ 'label' => 'Select specific page types',
172
+ 'info' => __('Specify the page types where the popup will be shown.', SG_POPUP_TEXT_DOMAIN)
173
+ )
174
+ ),
175
+ 'page_template' => array(
176
+ 'htmlAttrs' => array(
177
+ 'class' => 'js-sg-select2 js-select-ajax',
178
+ 'data-select-class' => 'js-select-ajax',
179
+ 'data-select-type' => 'multiple',
180
+ 'data-value-param' => 'pageTemplate',
181
+ 'isNotPostType' => true,
182
+ 'multiple' => 'multiple'
183
+ ),
184
+ 'infoAttrs' => array(
185
+ 'label' => 'Select page template',
186
+ 'info' => __('Select the page templates on which the popup will be shown.', SG_POPUP_TEXT_DOMAIN)
187
+ )
188
+ ),
189
+ 'post_tags_ids' => array(
190
+ 'htmlAttrs' => array(
191
+ 'class' => 'js-sg-select2 js-select-ajax',
192
+ 'data-select-class' => 'js-select-ajax',
193
+ 'data-select-type' => 'multiple',
194
+ 'data-value-param' => 'postTags',
195
+ 'isNotPostType' => true,
196
+ 'multiple' => 'multiple'
197
+ ),
198
+ 'infoAttrs' => array(
199
+ 'label' => 'Select tags',
200
+ 'info' => __('Select the tags on your site for popup showing', SG_POPUP_TEXT_DOMAIN)
201
+ )
202
+ )
203
+ );
204
+
205
+ $popupTarget['columns'] = apply_filters('sgPopupTargetColumns', $targetData);
206
+ $popupTarget['columnTypes'] = apply_filters('sgPopupTargetTypes', $targetElementTypes);
207
+ $popupTarget['paramsData'] = apply_filters('sgPopupTargetData', $targetDataParams);
208
+ $popupTarget['initialData'] = apply_filters('sgPopupTargetInitialData', $targetInitialData);
209
+ $popupTarget['operators'] = apply_filters('sgpbPopupEventsOperators', $targetOperators);
210
+ $popupTarget['attrs'] = apply_filters('sgPopupTargetAttrs', $targetAttrs);
211
+
212
+ $SGPB_DATA_CONFIG_ARRAY['target'] = $popupTarget;
213
+
214
+ /*Target condition config*/
215
+
216
+ /*
217
+ *
218
+ * Events data
219
+ *
220
+ **/
221
+ $eventsData = array('param' => 'Event name', 'value' => 'Delay');
222
+ $hiddenOptionData = array();
223
+
224
+ $eventsRowTypes = array(
225
+ 'param' => 'select',
226
+ 'operator' => 'select',
227
+ 'value' => 'text',
228
+ 'load' => 'number',
229
+ 'repetitive' => 'checkbox',
230
+ 'repetitivePeriod' => 'text',
231
+ SGPB_CLICK_ACTION_KEY => 'select',
232
+ 'clickActionCustomClass' => 'text',
233
+ 'hoverActionCustomClass' => 'text',
234
+ 'defaultClickClassName' => 'conditionalText',
235
+ 'defaultHoverClassName' => 'conditionalText'
236
+ );
237
+
238
+ $params = array(
239
+ 'load' => 'On load',
240
+ SGPB_CSS_CLASS_ACTIONS_KEY => __('Set by CSS class', SG_POPUP_TEXT_DOMAIN),
241
+ SGPB_CLICK_ACTION_KEY => __('On Click', SG_POPUP_TEXT_DOMAIN),
242
+ SGPB_HOVER_ACTION_KEY => __('On Hover', SG_POPUP_TEXT_DOMAIN),
243
+ 'inactivity' => __('Inactivity', SG_POPUP_TEXT_DOMAIN),
244
+ 'onScroll' => __('On Scroll', SG_POPUP_TEXT_DOMAIN)
245
+ );
246
+
247
+ $hiddenOptionData['load'] = array(
248
+ 'options' => array(
249
+ 'repetitive' => 'Repetitive popup'
250
+ )
251
+ );
252
+
253
+ $onLoadData = 0;
254
+
255
+ $eventsDataParams['param'] = $params;
256
+ $eventsDataParams['operator'] = array();
257
+ $eventsDataParams['load'] = $onLoadData;
258
+ $eventsDataParams['clickActionCustomClass'] = '';
259
+ $eventsDataParams['hoverActionCustomClass'] = '';
260
+ $eventsDataParams['defaultClickClassName'] = 'sg-popup-id-';
261
+ $eventsDataParams['defaultHoverClassName'] = 'sg-popup-hover-';
262
+ $eventsDataParams[SGPB_CSS_CLASS_ACTIONS_KEY] = null;
263
+ $eventsDataParams[SGPB_CLICK_ACTION_KEY.'Operator'] = ConfigDataHelper::getClickActionOptions();
264
+ $eventsDataParams[SGPB_HOVER_ACTION_KEY.'Operator'] = ConfigDataHelper::getHoverActionOptions();
265
+ /*Hidden params data*/
266
+ $eventsDataParams['repetitive'] = '';
267
+ $eventsDataParams['repetitivePeriod'] = 0;
268
+
269
+ $eventOperators = array(
270
+ array('operator' => 'add', 'name' => 'Add'),
271
+ array('operator' => 'edit', 'name' => 'Edit'),
272
+ array('operator' => 'delete', 'name' => 'Delete')
273
+ );
274
+
275
+ $eventsInitialData = array(
276
+ array('param' => 'load', 'value' => '', 'hiddenOption' => array())
277
+ );
278
+
279
+ $eventsAttrs = array(
280
+ 'param' => array(
281
+ 'htmlAttrs' => array(
282
+ 'class' => 'js-sg-select2 js-select-basic sgpb-selectbox-settings',
283
+ 'data-select-class' => 'js-select-basic',
284
+ 'data-select-type' => 'basic'
285
+ ),
286
+ 'infoAttrs' => array(
287
+ 'label' => 'Event',
288
+ 'info' => __('Select when the popup should appear on the page.', SG_POPUP_TEXT_DOMAIN)
289
+ )
290
+ ),
291
+ 'operator' => array(
292
+ 'htmlAttrs' => array(
293
+ 'class' => 'js-sg-select2 js-select-basic',
294
+ 'data-select-class' => 'js-select-basic',
295
+ 'data-select-type' => 'basic'
296
+ ),
297
+ 'infoAttrs' => array(
298
+ 'label' => 'Options',
299
+ 'info' => __('Select the condition for the current event.', SG_POPUP_TEXT_DOMAIN)
300
+ )
301
+ ),
302
+ 'load' => array(
303
+ 'htmlAttrs' => array('class' => 'js-sg-onload-text formItem__input formItem__input_select2_num_input', 'placeholder' => __('default custom delay will be used', SG_POPUP_TEXT_DOMAIN), 'min' => 0),
304
+ 'infoAttrs' => array(
305
+ 'label' => 'Delay',
306
+ 'info' => __('Specify how long the popup appearance should be delayed after loading the page (in sec).', SG_POPUP_TEXT_DOMAIN)
307
+ )
308
+ ),
309
+ SGPB_CLICK_ACTION_KEY => array(
310
+ 'htmlAttrs' => array(
311
+ 'class' => 'js-sg-select2 js-select-basic formItem__input formItem__input_select2_num_input',
312
+ 'data-select-class' => 'js-select-basic',
313
+ 'data-select-type' => 'basic'
314
+ ),
315
+ 'infoAttrs' => array(
316
+ 'label' => 'Click Event',
317
+ 'info' => __('Specify the part of the page, in percentages, where the popup should appear after scrolling.', SG_POPUP_TEXT_DOMAIN)
318
+ )
319
+ ),
320
+ SGPB_HOVER_ACTION_KEY => array(
321
+ 'htmlAttrs' => array(
322
+ 'class' => 'js-sg-select2 js-select-basic formItem__input formItem__input_select2_num_input',
323
+ 'data-select-class' => 'js-select-basic',
324
+ 'data-select-type' => 'basic'
325
+ ),
326
+ 'infoAttrs' => array(
327
+ 'label' => 'Hover Event',
328
+ 'info' => __('Specify the part of the page, in percentages, where the popup should appear after scrolling.', SG_POPUP_TEXT_DOMAIN)
329
+ )
330
+ ),
331
+ 'clickActionCustomClass' => array(
332
+ 'htmlAttrs' => array('class' => 'js-sg-inactivity-text formItem__input formItem__input_select2_num_input', 'min' => 0),
333
+ 'infoAttrs' => array(
334
+ 'label' => 'Custom Class',
335
+ 'info' => __('Add the CSS class name of your HTML element which will trigger this popup after click.', SG_POPUP_TEXT_DOMAIN)
336
+ )
337
+ ),
338
+ 'hoverActionCustomClass' => array(
339
+ 'htmlAttrs' => array('class' => 'js-sg-inactivity-text formItem__input formItem__input_select2_num_input', 'min' => 0),
340
+ 'infoAttrs' => array(
341
+ 'label' => 'Custom Class',
342
+ 'info' => __('Add the CSS class name of your HTML element which will trigger this popup after click.', SG_POPUP_TEXT_DOMAIN)
343
+ )
344
+ ),
345
+ 'defaultClickClassName' => array(
346
+ 'htmlAttrs' => array(
347
+ 'class' => 'js-sg-click-event formItem__input formItem__input_select2_num_input',
348
+ 'min' => 0,
349
+ 'readonly' => '',
350
+ 'value' => 'sg-popup-id-',
351
+ 'beforeSaveLabel' => __('Please save popup to generate class name.', SG_POPUP_TEXT_DOMAIN)
352
+ ),
353
+ 'infoAttrs' => array(
354
+ 'label' => 'Default Class',
355
+ 'info' => __('Add the following CSS class into your HTML element.', SG_POPUP_TEXT_DOMAIN)
356
+ )
357
+ ),
358
+ 'defaultHoverClassName' => array(
359
+ 'htmlAttrs' => array(
360
+ 'class' => 'js-sg-hover-event formItem__input formItem__input_select2_num_input',
361
+ 'min' => 0,
362
+ 'readonly' => '',
363
+ 'value' => 'sg-popup-hover-',
364
+ 'beforeSaveLabel' => __('Please save popup to generate class name.', SG_POPUP_TEXT_DOMAIN)
365
+ ),
366
+ 'infoAttrs' => array(
367
+ 'label' => 'Default Class',
368
+ 'info' => __('Add the following CSS class into your HTML element.', SG_POPUP_TEXT_DOMAIN)
369
+ )
370
+ ),
371
+ 'repetitive' => array(
372
+ 'htmlAttrs' => array(
373
+ 'class' => 'sgpb-popup-option sgpb-popup-accordion',
374
+ 'data-name' => 'repetitive',
375
+ 'autocomplete' => 'off'
376
+ ),
377
+ 'infoAttrs' => array(
378
+ 'label' => 'Repetitive open popup',
379
+ 'info' => __('If this option is enabled the same popup will open up after every X seconds you have defined (after closing it).', SG_POPUP_TEXT_DOMAIN)
380
+ ),
381
+ 'childOptions' => array('repetitivePeriod')
382
+ ),
383
+ 'repetitivePeriod' => array(
384
+ 'htmlAttrs' => array(
385
+ 'class' => 'sgpb-popup-option',
386
+ 'autocomplete' => 'off'
387
+ ),
388
+ 'infoAttrs' => array(
389
+ 'label' => 'period',
390
+ 'info' => __('This is info', SG_POPUP_TEXT_DOMAIN)
391
+ )
392
+ )
393
+ );
394
+
395
+ $popupEvents['columns'] = apply_filters('sgPopupEventColumns', $eventsData);
396
+ $popupEvents['columnTypes'] = apply_filters('sgPopupEventTypes', $eventsRowTypes);
397
+ $popupEvents['paramsData'] = apply_filters('sgPopupEventsData', $eventsDataParams);
398
+ $popupEvents['initialData'] = apply_filters('sgPopupEventsInitialData', $eventsInitialData);
399
+ $popupEvents['operators'] = apply_filters('sgPopupEventOperators', $eventOperators);
400
+ $popupEvents['hiddenOptionData'] = apply_filters('sgEventsHiddenData', $hiddenOptionData);
401
+ $popupEvents['attrs'] = apply_filters('sgPopupEventAttrs', $eventsAttrs);
402
+
403
+ $popupEvents['specialDefaultOperator'] = apply_filters('sgPopupEventsOperators', ' ');
404
+ $popupEvents['operatorAllowInConditions'] = apply_filters('sgPopupEventsOperatorAllowInConditions', array(SGPB_CLICK_ACTION_KEY, SGPB_HOVER_ACTION_KEY));
405
+
406
+ $SGPB_DATA_CONFIG_ARRAY['events'] = $popupEvents;
407
+
408
+ /*Target condition config*/
409
+ $targetData = array('param' => 'Pages', 'operator' => 'Is not', 'value' => 'Value');
410
+ $targetElementTypes = array(
411
+ 'param' => 'select',
412
+ 'operator' => 'select',
413
+ 'value' => 'select',
414
+ 'select_role' => 'select',
415
+ );
416
+
417
+ $targetParams = array(
418
+ 'select_role' => __('Select role', SG_POPUP_TEXT_DOMAIN)
419
+ );
420
+
421
+ $targetOperators = array(
422
+ array('operator' => 'add', 'name' => __('Add', SG_POPUP_TEXT_DOMAIN)),
423
+ array('operator' => 'delete', 'name' => __('Delete', SG_POPUP_TEXT_DOMAIN))
424
+ );
425
+
426
+ $targetDataOperator = array(
427
+ '==' => __('Is', SG_POPUP_TEXT_DOMAIN),
428
+ '!=' => __('Is not', SG_POPUP_TEXT_DOMAIN)
429
+ );
430
+
431
+ $targetInitialData = array(
432
+ array('param' => 'select_role', 'operator' => '==', 'value' => '')
433
+ );
434
+
435
+ $targetDataParams['param'] = apply_filters('sgpbPopupSpecialEventsParams', $targetParams);
436
+ $targetDataParams['operator'] = apply_filters('sgpbPopupConditionsOperator', $targetDataOperator);
437
+
438
+ $targetDataParams['select_role'] = null;
439
+
440
+ $targetAttrs = array(
441
+ 'param' => array(
442
+ 'htmlAttrs' => array(
443
+ 'class' => 'js-sg-select2 js-select-basic sgpb-selectbox-settings',
444
+ 'data-select-class' => 'js-select-basic',
445
+ 'data-select-type' => 'basic',
446
+ 'autocomplete' => 'off'
447
+ ),
448
+ 'infoAttrs' => array(
449
+ 'label' => 'Condition',
450
+ 'info' => __('Target visitors to show the popup by different conditions.', SG_POPUP_TEXT_DOMAIN)
451
+ )
452
+ ),
453
+ 'operator' => array(
454
+ 'htmlAttrs' => array(
455
+ 'class' => 'js-sg-select2 js-select-basic',
456
+ 'data-select-class' => 'js-select-basic',
457
+ 'data-select-type' => 'basic'
458
+ ),
459
+ 'infoAttrs' => array(
460
+ 'label' => 'Rule',
461
+ 'info' => __('Allow or Disallow popup showing for the selected conditions.', SG_POPUP_TEXT_DOMAIN)
462
+ )
463
+ )
464
+ );
465
+
466
+ $popupConditions['columns'] = apply_filters('sgPopupConditionsColumns', $targetData);
467
+ $popupConditions['columnTypes'] = apply_filters('sgPopupConditionsTypes', $targetElementTypes);
468
+ $popupConditions['paramsData'] = apply_filters('sgPopupConditionsData', $targetDataParams);
469
+ $popupConditions['initialData'] = apply_filters('sgPopupConditionsInitialData', $targetInitialData);
470
+ $popupConditions['operators'] = apply_filters('sgPopupConditionsOperators', $targetOperators);
471
+ $popupConditions['attrs'] = apply_filters('sgPopupConditionsAttrs', $targetAttrs);
472
+
473
+ $popupConditions['specialDefaultOperator'] = apply_filters('sgPopupConditionsOperators', $targetDataOperator);
474
+ $popupConditions['operatorAllowInConditions'] = apply_filters('sgPopupConditionsOperatorAllowInConditions', array());
475
+
476
+ $SGPB_DATA_CONFIG_ARRAY['conditions'] = $popupConditions;
477
+
478
+ $SGPB_DATA_CONFIG_ARRAY['behavior-after-special-events'] = self::getBehaviorAfterSpecialEventsConfig();
479
+ $SGPB_DATA_CONFIG_ARRAY = apply_filters('sgpbConfigArray', $SGPB_DATA_CONFIG_ARRAY);
480
+ /*Target condition config*/
481
+ }
482
+
483
+ public static function allFreeExtensionsKeys()
484
+ {
485
+ $keys = array();
486
+
487
+ return $keys;
488
+ }
489
+
490
+ public static function allExtensionsKeys()
491
+ {
492
+ $keys = array();
493
+ $keys[] = array(
494
+ 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN),
495
+ 'version' => '3.0',
496
+ 'stable_version' => '3.0',
497
+ 'pluginKey' => 'popupbuilder-adblock/PopupBuilderAdBlock.php',
498
+ 'key' => 'sgpbAdBlock',
499
+ 'url' => SG_POPUP_AD_BLOCK_URL
500
+ );
501
+ $keys[] = array(
502
+ 'label' => __('Advanced Closing', SG_POPUP_TEXT_DOMAIN),
503
+ 'version' => '2.0',
504
+ 'stable_version' => '2.0',
505
+ 'pluginKey' => 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php',
506
+ 'key' => 'advancedClosing',
507
+ 'url' => SG_POPUP_ADVANCED_CLOSING_URL
508
+ );
509
+ $keys[] = array(
510
+ 'label' => __('Advanced Targeting', SG_POPUP_TEXT_DOMAIN),
511
+ 'version' => '3.0',
512
+ 'stable_version' => '3.0',
513
+ 'pluginKey' => 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php',
514
+ 'key' => 'sgpbAdvancedTargeting',
515
+ 'url' => SG_POPUP_ADVANCED_TARGETING_URL
516
+ );
517
+ $keys[] = array(
518
+ 'label' => __('Age Restriction', SG_POPUP_TEXT_DOMAIN),
519
+ 'version' => '2.0',
520
+ 'stable_version' => '2.0',
521
+ 'pluginKey' => 'popupbuilder-age-verification/PopupBuilderAgeverification.php',
522
+ 'key' => 'ageVerification',
523
+ 'url' => SGPB_AGE_VERIFICATION_PLUGIN_URL
524
+ );
525
+ $keys[] = array(
526
+ 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN),
527
+ 'version' => '4.0',
528
+ 'stable_version' => '4.0',
529
+ 'pluginKey' => 'popupbuilder-analytics/PopupBuilderAnalytics.php',
530
+ 'key' => 'sgpbAnalitics',
531
+ 'url' => SG_POPUP_ANALYTICS_URL
532
+ );
533
+ $keys[] = array(
534
+ 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN),
535
+ 'version' => '3.0',
536
+ 'stable_version' => '3.0',
537
+ 'pluginKey' => 'popupbuilder-aweber/PopupBuilderAWeber.php',
538
+ 'key' => 'sgpbAWeber',
539
+ 'url' => SG_POPUP_AWEBER_URL
540
+ );
541
+ $keys[] = array(
542
+ 'label' => __('Contact Form', SG_POPUP_TEXT_DOMAIN),
543
+ 'version' => '3.0',
544
+ 'stable_version' => '3.0',
545
+ 'pluginKey' => 'popupbuilder-contact-form/PopupBuilderContactForm.php',
546
+ 'key' => 'contactForm',
547
+ 'url' => SG_POPUP_CONTACT_FORM_URL
548
+ );
549
+ $keys[] = array(
550
+ 'label' => __('Countdown', SG_POPUP_TEXT_DOMAIN),
551
+ 'version' => '3.0',
552
+ 'stable_version' => '3.0',
553
+ 'pluginKey' => 'popupbuilder-countdown/PopupBuilderCountdown.php',
554
+ 'key' => 'countdown',
555
+ 'url' => SG_POPUP_COUNTDOWN_URL
556
+ );
557
+ $keys[] = array(
558
+ 'label' => __('EDD', SG_POPUP_TEXT_DOMAIN),
559
+ 'version' => '2.0',
560
+ 'stable_version' => '2.0',
561
+ 'pluginKey' => 'popupbuilder-edd/PopupBuilderEdd.php',
562
+ 'key' => 'edd',
563
+ 'url' => SGPB_EDD_PLUGIN_URL
564
+ );
565
+ $keys[] = array(
566
+ 'label' => __('Exit Intent',SG_POPUP_TEXT_DOMAIN),
567
+ 'version' => '4.0',
568
+ 'stable_version' => '4.0',
569
+ 'pluginKey' => 'popupbuilder-exit-intent/PopupBuilderExitIntent.php',
570
+ 'key' => 'sgpbExitIntent',
571
+ 'url' => SG_POPUP_EXIT_INTENT_URL
572
+ );
573
+ $keys[] = array(
574
+ 'label' => __('Gamification', SG_POPUP_TEXT_DOMAIN),
575
+ 'version' => '2.0',
576
+ 'stable_version' => '2.0',
577
+ 'pluginKey' => 'popupbuilder-gamification/PopupBuilderGamification.php',
578
+ 'key' => 'gamification',
579
+ 'url' => SGPB_GAMIFICATION_PLUGIN_URL
580
+ );
581
+ $keys[] = array(
582
+ 'label' => __('Geo Targeting', SG_POPUP_TEXT_DOMAIN),
583
+ 'version' => '3.0',
584
+ 'stable_version' => '3.0',
585
+ 'pluginKey' => 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php',
586
+ 'key' => 'geo-targeting',
587
+ 'url' => SG_POPUP_GEO_TARGETING_URL
588
+ );
589
+ $keys[] = array(
590
+ 'label' => __('Iframe', SG_POPUP_TEXT_DOMAIN),
591
+ 'version' => '2.0',
592
+ 'stable_version' => '2.0',
593
+ 'pluginKey' => 'popupbuilder-iframe/PopupBuilderIframe.php',
594
+ 'key' => 'iframe',
595
+ 'url' => SG_POPUP_IFRAME_URL
596
+ );
597
+ $keys[] = array(
598
+ 'label' => __('Inactivity', SG_POPUP_TEXT_DOMAIN),
599
+ 'version' => '2.0',
600
+ 'stable_version' => '2.0',
601
+ 'pluginKey' => 'popupbuilder-inactivity/PopupBuilderInactivity.php',
602
+ 'key' => 'sgpbInactivity',
603
+ 'url' => SG_POPUP_INACTIVITY_URL
604
+ );
605
+ $keys[] = array(
606
+ 'label' => __('Log In', SG_POPUP_TEXT_DOMAIN),
607
+ 'version' => '3.0',
608
+ 'stable_version' => '3.0',
609
+ 'pluginKey' => 'popupbuilder-login/PopupBuilderLogin.php',
610
+ 'key' => 'login',
611
+ 'url' => SG_POPUP_LOGIN_URL
612
+ );
613
+ $keys[] = array(
614
+ 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN),
615
+ 'version' => '4.0',
616
+ 'stable_version' => '4.0',
617
+ 'pluginKey' => 'popupbuilder-mailchimp/PopupBuilderMailchimp.php',
618
+ 'key' => 'sgpbMailchimp',
619
+ 'url' => SG_POPUP_MAILCHIMP_URL
620
+ );
621
+ $keys[] = array(
622
+ 'label' => __('PDF', SG_POPUP_TEXT_DOMAIN),
623
+ 'version' => '2.0',
624
+ 'stable_version' => '2.0',
625
+ 'pluginKey' => 'popupbuilder-pdf/PopupBuilderPdf.php',
626
+ 'key' => 'pdf',
627
+ 'url' => SGPB_PDF_PLUGIN_URL
628
+ );
629
+ $keys[] = array(
630
+ 'label' => __('Push Notification', SG_POPUP_TEXT_DOMAIN),
631
+ 'version' => '2.0',
632
+ 'stable_version' => '2.0',
633
+ 'pluginKey' => 'popupbuilder-push-notification/PopupBuilderPushNotification.php',
634
+ 'key' => 'pushNotification',
635
+ 'url' => SG_POPUP_PUSH_NOTIFICATION_URL
636
+ );
637
+ $keys[] = array(
638
+ 'label' => __('Random', SG_POPUP_TEXT_DOMAIN),
639
+ 'version' => '2.0',
640
+ 'stable_version' => '2.0',
641
+ 'pluginKey' => 'popupbuilder-random/PopupBuilderRandom.php',
642
+ 'key' => 'sgpbRandom',
643
+ 'url' => SG_POPUP_RANDOM_URL
644
+ );
645
+ $keys[] = array(
646
+ 'label' => __('Recent Sales', SG_POPUP_TEXT_DOMAIN),
647
+ 'version' => '2.0',
648
+ 'stable_version' => '2.0',
649
+ 'pluginKey' => 'popupbuilder-recent-sales/PopupBuilderRecentSales.php',
650
+ 'key' => 'sgpbRecentSales',
651
+ 'url' => SG_POPUP_RECENT_SALES_URL
652
+ );
653
+ $keys[] = array(
654
+ 'label' => __('Registration', SG_POPUP_TEXT_DOMAIN),
655
+ 'version' => '2.0',
656
+ 'stable_version' => '2.0',
657
+ 'pluginKey' => 'popupbuilder-registration/PopupBuilderRegistration.php',
658
+ 'key' => 'registration',
659
+ 'url' => SG_POPUP_REGISTRATION_URL
660
+ );
661
+ $keys[] = array(
662
+ 'label' => __('Restriction', SG_POPUP_TEXT_DOMAIN),
663
+ 'version' => '3.0',
664
+ 'stable_version' => '3.0',
665
+ 'pluginKey' => 'popupbuilder-restriction/PopupBuilderAgerestriction.php',
666
+ 'key' => 'ageRestriction',
667
+ 'url' => SG_POPUP_RESTRICTION_URL
668
+ );
669
+ $keys[] = array(
670
+ 'label' => __('Scheduling', SG_POPUP_TEXT_DOMAIN),
671
+ 'version' => '2.0',
672
+ 'stable_version' => '2.0',
673
+ 'pluginKey' => 'popupbuilder-scheduling/PopupBuilderScheduling.php',
674
+ 'key' => 'scheduling',
675
+ 'url' => SG_POPUP_SCHEDULING_URL
676
+ );
677
+ $keys[] = array(
678
+ 'label' => __('Scroll', SG_POPUP_TEXT_DOMAIN),
679
+ 'version' => '3.0',
680
+ 'stable_version' => '3.0',
681
+ 'pluginKey' => 'popupbuilder-scroll/PopupBuilderScroll.php',
682
+ 'key' => 'sgpbScroll',
683
+ 'url' => SG_POPUP_SCROLL_URL
684
+ );
685
+ $keys[] = array(
686
+ 'label' => __('Social', SG_POPUP_TEXT_DOMAIN),
687
+ 'version' => '2.0',
688
+ 'stable_version' => '2.0',
689
+ 'pluginKey' => 'popupbuilder-social/PopupBuilderSocial.php',
690
+ 'key' => 'social',
691
+ 'url' => SG_POPUP_SOCIAL_URL
692
+ );
693
+ $keys[] = array(
694
+ 'label' => __('Subscription Plus', SG_POPUP_TEXT_DOMAIN),
695
+ 'version' => '4.0',
696
+ 'stable_version' => '4.0',
697
+ 'pluginKey' => 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php',
698
+ 'key' => 'subscriptionPlus',
699
+ 'url' => SG_POPUP_SUBSCRIPTION_PLUS_URL
700
+ );
701
+ $keys[] = array(
702
+ 'label' => __('Video', SG_POPUP_TEXT_DOMAIN),
703
+ 'version' => '2.0',
704
+ 'stable_version' => '2.0',
705
+ 'pluginKey' => 'popupbuilder-video/PopupBuilderVideo.php',
706
+ 'key' => 'video',
707
+ 'url' => SG_POPUP_VIDEO_URL
708
+ );
709
+ $keys[] = array(
710
+ 'label' => __('WooCommerce', SG_POPUP_TEXT_DOMAIN),
711
+ 'version' => '3.0',
712
+ 'stable_version' => '3.0',
713
+ 'pluginKey' => 'popupbuilder-woocommerce/popupbuilderWoocommerce.php',
714
+ 'key' => 'sgpbWOO',
715
+ 'url' => SG_POPUP_WOOCOMMERCE_URL
716
+ );
717
+
718
+ return apply_filters('sgpbExtensionsKeys', $keys);
719
+ }
720
+
721
+ private static function getBehaviorAfterSpecialEventsConfig()
722
+ {
723
+ $columns = array(
724
+ 'param' => 'Event',
725
+ 'operator' => 'Behavior',
726
+ 'value' => 'Value'
727
+ );
728
+
729
+ $columnTypes = array(
730
+ 'param' => 'select',
731
+ 'operator' => 'select',
732
+ 'value' => 'select',
733
+ 'select_event' => 'select',
734
+ 'select_behavior' => 'select',
735
+ 'redirect-url' => 'url',
736
+ 'open-popup' => 'select',
737
+ 'close-popup' => 'number'
738
+ );
739
+
740
+ $params = array(
741
+ 'param' => array(
742
+ 'select_event' => __('Select event', SG_POPUP_TEXT_DOMAIN),
743
+ __('Special events', SG_POPUP_TEXT_DOMAIN) => array(
744
+ SGPB_CONTACT_FORM_7_BEHAVIOR_KEY => __('Contact Form 7 submission', SG_POPUP_TEXT_DOMAIN)
745
+ )
746
+ ),
747
+ 'operator' => array(
748
+ 'select_behavior' => __('Select behavior', SG_POPUP_TEXT_DOMAIN),
749
+ __('Behaviors', SG_POPUP_TEXT_DOMAIN) => array(
750
+ 'redirect-url' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN),
751
+ 'open-popup' => __('Open another popup', SG_POPUP_TEXT_DOMAIN),
752
+ 'close-popup' => __('Close current popup', SG_POPUP_TEXT_DOMAIN)
753
+ )
754
+ ),
755
+ 'redirect-url' => '',
756
+ 'open-popup' => array(),
757
+ 'close-popup' => '',
758
+ 'select_event' => null,
759
+ 'select_behavior' => null
760
+ );
761
+
762
+ $initialData = array(
763
+ array(
764
+ 'param' => 'select_event',
765
+ 'operator' => ''
766
+ )
767
+ );
768
+
769
+ $attrs = array(
770
+ 'param' => array(
771
+ 'htmlAttrs' => array(
772
+ 'class' => 'js-sg-select2 js-select-basic',
773
+ 'data-select-class' => 'js-select-basic',
774
+ 'data-select-type' => 'basic'
775
+ ),
776
+ 'infoAttrs' => array(
777
+ 'label' => __('Event', SG_POPUP_TEXT_DOMAIN),
778
+ 'info' => __('Select the special event you want to catch.', SG_POPUP_TEXT_DOMAIN)
779
+ )
780
+ ),
781
+ 'operator' => array(
782
+ 'htmlAttrs' => array(
783
+ 'class' => 'js-sg-select2 js-select-basic',
784
+ 'data-select-class' => 'js-select-basic',
785
+ 'data-select-type' => 'basic'
786
+ ),
787
+ 'infoAttrs' => array(
788
+ 'label' => __('Behavior', SG_POPUP_TEXT_DOMAIN),
789
+ 'info' => __('Select what should happen after the special event.', SG_POPUP_TEXT_DOMAIN)
790
+ )
791
+ ),
792
+ 'redirect-url' => array(
793
+ 'htmlAttrs' => array(
794
+ 'class' => 'sg-full-width formItem__input formItem__input_select2_num_input',
795
+ 'placeholder' => 'https://www.example.com',
796
+ 'required' => 'required'
797
+ ),
798
+ 'infoAttrs' => array(
799
+ 'label' => __('URL', SG_POPUP_TEXT_DOMAIN),
800
+ 'info' => __('Enter the URL of the page should be redirected to.', SG_POPUP_TEXT_DOMAIN)
801
+ )
802
+ ),
803
+ 'open-popup' => array(
804
+ 'htmlAttrs' => array(
805
+ 'class' => 'js-sg-select2 js-select-ajax',
806
+ 'data-select-class' => 'js-select-ajax',
807
+ 'data-select-type' => 'ajax',
808
+ 'data-value-param' => SG_POPUP_POST_TYPE,
809
+ 'required' => 'required'
810
+ ),
811
+ 'infoAttrs' => array(
812
+ 'label' => __('Select popup', SG_POPUP_TEXT_DOMAIN),
813
+ 'info' => __('Select the popup that should be opened.', SG_POPUP_TEXT_DOMAIN)
814
+ )
815
+ ),
816
+ 'close-popup' => array(
817
+ 'htmlAttrs' => array(
818
+ 'class' => 'sg-full-width formItem__input formItem__input_select2_num_input',
819
+ 'required' => 'required',
820
+ 'value' => 0,
821
+ 'min' => 0
822
+ ),
823
+ 'infoAttrs' => array(
824
+ 'label' => __('Delay', SG_POPUP_TEXT_DOMAIN),
825
+ 'info' => __('After how many seconds the popup should close.', SG_POPUP_TEXT_DOMAIN)
826
+ )
827
+ )
828
+ );
829
+
830
+ $config = array();
831
+ $config['columns'] = apply_filters('sgPopupSpecialEventsColumns', $columns);
832
+ $config['columnTypes'] = apply_filters('sgPopupSpecialEventsColumnTypes', $columnTypes);
833
+ $config['paramsData'] = apply_filters('sgPopupSpecialEventsParams', $params);
834
+ $config['initialData'] = apply_filters('sgPopupSpecialEventsInitialData', $initialData);
835
+ $config['attrs'] = apply_filters('sgPopupSpecialEventsAttrs', $attrs);
836
+ $config['operators'] = apply_filters('sgpbPopupSpecialEventsOperators', array());
837
+ $config['specialDefaultOperator'] = apply_filters('sgpbPopupSpecialEventsDefaultOperators', ' ');
838
+
839
+ return $config;
840
+ }
841
+
842
+ public static function popupDefaultOptions()
843
+ {
844
+ global $SGPB_OPTIONS;
845
+ global $SGPB_DATA_CONFIG_ARRAY;
846
+
847
+ $targetDefaultValue = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
848
+
849
+ $eventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['events']['initialData']);
850
+ $conditionsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['conditions']['initialData']);
851
+ $specialEventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['behavior-after-special-events']['initialData']);
852
+
853
+ $options = array();
854
+
855
+ $options[] = array('name' => 'sgpb-target', 'type' => 'array', 'defaultValue' => $targetDefaultValue);
856
+ $options[] = array('name' => 'sgpb-events', 'type' => 'array', 'defaultValue' => $eventsDefaultData);
857
+ $options[] = array('name' => 'sgpb-conditions', 'type' => 'array', 'defaultValue' => $conditionsDefaultData, 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
858
+ $options[] = array('name' => 'sgpb-behavior-after-special-events', 'type' => 'array', 'defaultValue' => $specialEventsDefaultData);
859
+ $options[] = array('name' => 'sgpb-type', 'type' => 'text', 'defaultValue' => 'html');
860
+ $options[] = array('name' => 'sgpb-popup-counting-disabled', 'type' => 'checkbox', 'defaultValue' => '');
861
+ $options[] = array('name' => 'sgpb-esc-key', 'type' => 'checkbox', 'defaultValue' => 'on');
862
+ $options[] = array('name' => 'sgpb-enable-close-button', 'type' => 'checkbox', 'defaultValue' => 'on');
863
+ $options[] = array('name' => 'sgpb-enable-content-scrolling', 'type' => 'checkbox', 'defaultValue' => 'on');
864
+ $options[] = array('name' => 'sgpb-overlay-click', 'type' => 'checkbox', 'defaultValue' => 'on');
865
+ $options[] = array('name' => 'sgpb-content-click', 'type' => 'checkbox', 'defaultValue' => '');
866
+ $options[] = array('name' => 'sgpb-subs-hide-subs-users', 'type' => 'checkbox', 'defaultValue' => 'on');
867
+ $options[] = array('name' => 'sgpb-content-click-behavior', 'type' => 'text', 'defaultValue' => 'close');
868
+ $options[] = array('name' => 'sgpb-click-redirect-to-url', 'type' => 'text', 'defaultValue' => '');
869
+ $options[] = array('name' => 'sgpb-redirect-to-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
870
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-text', 'type' => 'text', 'defaultValue' => '');
871
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-close-popup', 'type' => 'checkbox', 'defaultValue' => 'on');
872
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-alert', 'type' => 'checkbox', 'defaultValue' => 'on');
873
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-message', 'type' => 'text', 'defaultValue' => __('Copied to Clipboard!', SG_POPUP_TEXT_DOMAIN));
874
+ $options[] = array('name' => 'sgpb-disable-popup-closing', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
875
+ $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => 'responsiveMode');
876
+ $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => '100');
877
+ $options[] = array('name' => 'sgpb-width', 'type' => 'text', 'defaultValue' => '640px');
878
+ $options[] = array('name' => 'sgpb-height', 'type' => 'text', 'defaultValue' => '480px');
879
+ $options[] = array('name' => 'sgpb-max-width', 'type' => 'text', 'defaultValue' => '');
880
+ $options[] = array('name' => 'sgpb-max-height', 'type' => 'text', 'defaultValue' => '');
881
+ $options[] = array('name' => 'sgpb-min-width', 'type' => 'text', 'defaultValue' => '120px');
882
+ $options[] = array('name' => 'sgpb-min-height', 'type' => 'text', 'defaultValue' => '');
883
+ $options[] = array('name' => 'sgpb-popup-timer-status', 'type' => 'checkbox', 'defaultValue' => '');
884
+ $options[] = array('name' => 'sgpb-popup-start-timer', 'type' => 'text', 'defaultValue' => '');
885
+ $options[] = array('name' => 'sgpb-popup-end-timer', 'type' => 'text', 'defaultValue' => '');
886
+ $options[] = array('name' => 'sgpb-popup-fixed', 'type' => 'checkbox', 'defaultValue' => '');
887
+ $options[] = array('name' => 'sgpb-popup-fixed-position', 'type' => 'text', 'defaultValue' => '');
888
+ $options[] = array('name' => 'sgpb-popup-delay', 'type' => 'text', 'defaultValue' => '0');
889
+ $options[] = array('name' => 'sgpb-popup-order', 'type' => 'text', 'defaultValue' => '0');
890
+ $options[] = array('name' => 'sgpb-disable-page-scrolling', 'type' => 'checkbox', 'defaultValue' => '');
891
+ $options[] = array('name' => 'sgpb-content-padding', 'type' => 'text', 'defaultValue' => 7);
892
+ $options[] = array('name' => 'sgpb-popup-z-index', 'type' => 'text', 'defaultValue' => 9999);
893
+ $options[] = array('name' => 'sgpb-content-custom-class', 'type' => 'text', 'defaultValue' => 'sg-popup-content');
894
+ $options[] = array('name' => 'sgpb-close-after-page-scroll', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
895
+ $options[] = array('name' => 'sgpb-auto-close', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
896
+ $options[] = array('name' => 'sgpb-auto-close-time', 'type' => 'number', 'defaultValue' => 0);
897
+ $options[] = array('name' => 'sgpb-reopen-after-form-submission', 'type' => 'checkbox', 'defaultValue' => '');
898
+ $options[] = array('name' => 'sgpb-open-sound', 'type' => 'checkbox', 'defaultValue' => '');
899
+ $options[] = array('name' => 'sgpb-sound-url', 'type' => 'text', 'defaultValue' => SG_POPUP_SOUND_URL.SGPB_POPUP_DEFAULT_SOUND);
900
+ $options[] = array('name' => 'sgpb-open-animation', 'type' => 'checkbox', 'defaultValue' => '');
901
+ $options[] = array('name' => 'sgpb-close-animation', 'type' => 'checkbox', 'defaultValue' => '');
902
+ $options[] = array('name' => 'sgpb-open-animation-speed', 'type' => 'text', 'defaultValue' => 1);
903
+ $options[] = array('name' => 'sgpb-close-animation-speed', 'type' => 'text', 'defaultValue' => 1);
904
+ $options[] = array('name' => 'sgpb-popup-themes', 'type' => 'text', 'defaultValue' => 'sgpb-theme-1');
905
+ $options[] = array('name' => 'sgpb-enable-popup-overlay', 'type' => 'checkbox', 'defaultValue' => 'on', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
906
+ $options[] = array('name' => 'sgpb-overlay-custom-class', 'type' => 'text', 'defaultValue' => 'sgpb-popup-overlay');
907
+ $options[] = array('name' => 'sgpb-overlay-color', 'type' => 'text', 'defaultValue' => '');
908
+ $options[] = array('name' => 'sgpb-background-color', 'type' => 'text', 'defaultValue' => '');
909
+ $options[] = array('name' => 'sgpb-overlay-opacity', 'type' => 'text', 'defaultValue' => 0.8);
910
+ $options[] = array('name' => 'sgpb-content-opacity', 'type' => 'text', 'defaultValue' => 0.8);
911
+ $options[] = array('name' => 'sgpb-background-image', 'type' => 'text', 'defaultValue' => '');
912
+ $options[] = array('name' => 'sgpb-show-background', 'type' => 'checkbox', 'defaultValue' => '');
913
+ $options[] = array('name' => 'sgpb-force-rtl', 'type' => 'checkbox', 'defaultValue' => '');
914
+ $options[] = array('name' => 'sgpb-disable-border', 'type' => 'checkbox', 'defaultValue' => '');
915
+ $options[] = array('name' => 'sgpb-background-image-mode', 'type' => 'text', 'defaultValue' => 'no-repeat');
916
+ $options[] = array('name' => 'sgpb-image-url', 'type' => 'text', 'defaultValue' => '');
917
+ $options[] = array('name' => 'sgpb-close-button-delay', 'type' => 'number', 'defaultValue' => 0);
918
+ $options[] = array('name' => 'sgpb-button-position-bottom', 'type' => 'number', 'defaultValue' => 9);
919
+ $options[] = array('name' => 'sgpb-button-position-right', 'type' => 'number', 'defaultValue' => 9);
920
+ $options[] = array('name' => 'sgpb-button-image', 'type' => 'text', 'defaultValue' => '');
921
+ $options[] = array('name' => 'sgpb-button-image-width', 'type' => 'text', 'defaultValue' => 21);
922
+ $options[] = array('name' => 'sgpb-button-image-height', 'type' => 'text', 'defaultValue' => 21);
923
+ $options[] = array('name' => 'sgpb-is-active', 'type' => 'checkbox', 'defaultValue' => 'on');
924
+ $options[] = array('name' => 'sgpb-subs-form-bg-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
925
+ $options[] = array('name' => 'sgpb-subs-form-bg-opacity', 'type' => 'text', 'defaultValue' => 0.8);
926
+ $options[] = array('name' => 'sgpb-subs-form-padding', 'type' => 'number', 'defaultValue' => 2);
927
+ $options[] = array('name' => 'sgpb-subs-email-placeholder', 'type' => 'text', 'defaultValue' => __('Email *', SG_POPUP_TEXT_DOMAIN));
928
+ $options[] = array('name' => 'sgpb-subs-first-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
929
+ $options[] = array('name' => 'sgpb-subs-first-placeholder', 'type' => 'text', 'defaultValue' => __('First name', SG_POPUP_TEXT_DOMAIN));
930
+ $options[] = array('name' => 'sgpb-subs-first-name-required', 'type' => 'checkbox', 'defaultValue' => '');
931
+ $options[] = array('name' => 'sgpb-subs-last-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
932
+ $options[] = array('name' => 'sgpb-subs-last-placeholder', 'type' => 'text', 'defaultValue' => __('Last name', SG_POPUP_TEXT_DOMAIN));
933
+ $options[] = array('name' => 'sgpb-subs-last-name-required', 'type' => 'checkbox', 'defaultValue' => '');
934
+ $options[] = array('name' => 'sgpb-subs-validation-message', 'type' => 'text', 'defaultValue' => __('This field is required.', SG_POPUP_TEXT_DOMAIN));
935
+ $options[] = array('name' => 'sgpb-subs-text-width', 'type' => 'text', 'defaultValue' => '300px');
936
+ $options[] = array('name' => 'sgpb-subs-text-height', 'type' => 'text', 'defaultValue' => '40px');
937
+ $options[] = array('name' => 'sgpb-subs-text-border-width', 'type' => 'text', 'defaultValue' => '2px');
938
+ $options[] = array('name' => 'sgpb-subs-text-border-color', 'type' => 'text', 'defaultValue' => '#e8e8e8');
939
+ $options[] = array('name' => 'sgpb-subs-text-bg-color', 'type' => 'text', 'defaultValue' => '#f1f1f1');
940
+ $options[] = array('name' => 'sgpb-subs-text-color', 'type' => 'text', 'defaultValue' => '#000000');
941
+ $options[] = array('name' => 'sgpb-subs-text-placeholder-color', 'type' => 'text', 'defaultValue' => '#757575');
942
+ $options[] = array('name' => 'sgpb-subs-btn-width', 'type' => 'text', 'defaultValue' => '300px');
943
+ $options[] = array('name' => 'sgpb-subs-btn-height', 'type' => 'text', 'defaultValue' => '40px');
944
+ $options[] = array('name' => 'sgpb-subs-btn-border-radius', 'type' => 'text', 'defaultValue' => '4px');
945
+ $options[] = array('name' => 'sgpb-subs-btn-border-width', 'type' => 'text', 'defaultValue' => '0px');
946
+ $options[] = array('name' => 'sgpb-subs-btn-border-color', 'type' => 'text', 'defaultValue' => '#007fe1');
947
+ $options[] = array('name' => 'sgpb-subs-btn-title', 'type' => 'text', 'defaultValue' => __('Subscribe', SG_POPUP_TEXT_DOMAIN));
948
+ $options[] = array('name' => 'sgpb-subs-btn-progress-title', 'type' => 'text', 'defaultValue' => __('Please wait...', SG_POPUP_TEXT_DOMAIN));
949
+ $options[] = array('name' => 'sgpb-subs-btn-bg-color', 'type' => 'text', 'defaultValue' => '#007fe1');
950
+ $options[] = array('name' => 'sgpb-subs-btn-text-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
951
+ $options[] = array('name' => 'sgpb-subs-error-message', 'type' => 'text', 'defaultValue' => SGPB_SUBSCRIPTION_ERROR_MESSAGE);
952
+ $options[] = array('name' => 'sgpb-subs-invalid-message', 'type' => 'text', 'defaultValue' => __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
953
+ $options[] = array('name' => 'sgpb-subs-success-behavior', 'type' => 'text', 'defaultValue' => 'showMessage');
954
+ $options[] = array('name' => 'sgpb-subs-success-message', 'type' => 'text', 'defaultValue' => __('You have successfully subscribed to the newsletter', SG_POPUP_TEXT_DOMAIN));
955
+ $options[] = array('name' => 'sgpb-subs-success-redirect-URL', 'type' => 'text', 'defaultValue' => '');
956
+ $options[] = array('name' => 'sgpb-subs-success-redirect-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
957
+ $options[] = array('name' => 'sgpb-subs-gdpr-status', 'type' => 'checkbox', 'defaultValue' => '');
958
+ $options[] = array('name' => 'sgpb-subs-show-form-to-top', 'type' => 'checkbox', 'defaultValue' => '');
959
+ $options[] = array('name' => 'sgpb-subs-gdpr-label', 'type' => 'text', 'defaultValue' => __('Accept Terms', SG_POPUP_TEXT_DOMAIN));
960
+ $options[] = array('name' => 'sgpb-subs-gdpr-text', 'type' => 'text', 'defaultValue' => __(get_bloginfo().' will use the information you provide on this form to be in touch with you and to provide updates and marketing.', SG_POPUP_TEXT_DOMAIN));
961
+ $options[] = array('name' => 'sgpb-subs-fields', 'type' => 'sgpb', 'defaultValue' => '');
962
+ $options[] = array('name' => 'sgpb-fblike-like-url', 'type' => 'text', 'defaultValue' => '');
963
+ $options[] = array('name' => 'sgpb-fblike-layout', 'type' => 'text', 'defaultValue' => 'standard');
964
+ $options[] = array('name' => 'sgpb-fblike-dont-show-share-button', 'type' => 'checkbox', 'defaultValue' => '');
965
+ $options[] = array('name' => 'sgpb-border-color', 'type' => 'text', 'defaultValue' => '#000000');
966
+ $options[] = array('name' => 'sgpb-border-radius', 'type' => 'text', 'defaultValue' => 0);
967
+ $options[] = array('name' => 'sgpb-show-popup-same-user', 'type' => 'checkbox', 'defaultValue' => '');
968
+ $options[] = array('name' => 'sgpb-show-popup-same-user-count', 'type' => 'number', 'defaultValue' => 1);
969
+ $options[] = array('name' => 'sgpb-show-popup-same-user-expiry', 'type' => 'number', 'defaultValue' => 1);
970
+ $options[] = array('name' => 'sgpb-show-popup-same-user-page-level', 'type' => 'checkbox', 'defaultValue' => '');
971
+
972
+ $options[] = array('name' => 'sgpb-enable-floating-button', 'type' => 'checkbox', 'defaultValue' => '');
973
+ $options[] = array('name' => 'sgpb-floating-button-style', 'type' => 'text', 'defaultValue' => 'corner');
974
+ $options[] = array('name' => 'sgpb-floating-button-position', 'type' => 'text', 'defaultValue' => 'bottom-right');
975
+ $options[] = array('name' => 'sgpb-floating-button-position-top', 'type' => 'text', 'defaultValue' => '40');
976
+ $options[] = array('name' => 'sgpb-floating-button-position-right', 'type' => 'text', 'defaultValue' => '50');
977
+ $options[] = array('name' => 'sgpb-floating-button-font-size', 'type' => 'number', 'defaultValue' => 16);
978
+ $options[] = array('name' => 'sgpb-floating-button-border-size', 'type' => 'number', 'defaultValue' => 5);
979
+ $options[] = array('name' => 'sgpb-floating-button-border-radius', 'type' => 'number', 'defaultValue' => 5);
980
+ $options[] = array('name' => 'sgpb-floating-button-border-color', 'type' => 'text', 'defaultValue' => '#5263eb');
981
+ $options[] = array('name' => 'sgpb-floating-button-bg-color', 'type' => 'text', 'defaultValue' => '#5263eb');
982
+ $options[] = array('name' => 'sgpb-floating-button-text-color', 'type' => 'text', 'defaultValue' => '#ffffff');
983
+ $options[] = array('name' => 'sgpb-floating-button-text', 'type' => 'text', 'defaultValue' => __('Click it!'));
984
+
985
+ $SGPB_OPTIONS = apply_filters('sgpbPopupDefaultOptions', $options);
986
+ }
987
+
988
+ public static function getOldExtensionsInfo()
989
+ {
990
+ $data = array(
991
+ array(
992
+ 'folderName' => 'popup-builder-ad-block',
993
+ 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN)
994
+ ),
995
+ array(
996
+ 'folderName' => 'popup-builder-analytics',
997
+ 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN)
998
+ ),
999
+ array(
1000
+ 'folderName' => 'popup-builder-exit-intent',
1001
+ 'label' => __('Exit intent', SG_POPUP_TEXT_DOMAIN)
1002
+ ),
1003
+ array(
1004
+ 'folderName' => 'popup-builder-mailchimp',
1005
+ 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN)
1006
+ ),
1007
+ array(
1008
+ 'folderName' => 'popup-builder-aweber',
1009
+ 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN)
1010
+ )
1011
+ );
1012
+
1013
+ return $data;
1014
+ }
1015
+
1016
+ public static function addFilters()
1017
+ {
1018
+ ConfigDataHelper::addFilters();
1019
+ }
1020
+
1021
+ public static function transientConfig()
1022
+ {
1023
+ global $SGPB_TRANSIENT_CONFIG;
1024
+
1025
+ $SGPB_TRANSIENT_CONFIG = array(
1026
+ SGPB_TRANSIENT_POPUPS_LOAD,
1027
+ SGPB_TRANSIENT_POPUPS_TERMS,
1028
+ SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES
1029
+ );
1030
+
1031
+ $SGPB_TRANSIENT_CONFIG = apply_filters('sgpbAllTransients', $SGPB_TRANSIENT_CONFIG);
1032
+ }
1033
+ }
com/helpers/AdminHelper.php CHANGED
@@ -1,2126 +1,2126 @@
1
- <?php
2
- namespace sgpb;
3
- use \DateTime;
4
- use \DateTimeZone;
5
- use \SgpbDataConfig;
6
- use \Elementor;
7
- use sgpbsubscriptionplus\SubscriptionPlusAdminHelper;
8
-
9
- class AdminHelper
10
- {
11
- /**
12
- * Get extension options data which are included inside the free version
13
- *
14
- * @since 3.0.8
15
- *
16
- * @return assoc array $extensionOptions
17
- */
18
- public static function getExtensionAvaliabilityOptions()
19
- {
20
- $extensionOptions = array();
21
- // advanced closing option
22
- $extensionOptions[SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY] = array(
23
- 'sgpb-close-after-page-scroll',
24
- 'sgpb-auto-close',
25
- 'sgpb-enable-popup-overlay',
26
- 'sgpb-disable-popup-closing'
27
- );
28
- // schedule extension
29
- $extensionOptions[SGPB_POPUP_SCHEDULING_EXTENSION_KEY] = array(
30
- 'otherConditionsMetaBoxView'
31
- );
32
- // geo targeting extension
33
- $extensionOptions[SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY] = array(
34
- 'popupConditionsSection'
35
- );
36
- // advanced targeting extension
37
- $extensionOptions[SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY] = array(
38
- 'popupConditionsSection'
39
- );
40
-
41
- return $extensionOptions;
42
- }
43
-
44
- public static function getPopupTypesPageURL()
45
- {
46
- return admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_POST_TYPE);
47
- }
48
-
49
- public static function getSettingsURL($args = array())
50
- {
51
- $url = admin_url('/edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
52
-
53
- return self::addArgsToURl($url, $args);
54
- }
55
-
56
- public static function getPopupExportURL()
57
- {
58
- $exportURL = admin_url('export.php');
59
- $url = add_query_arg(array(
60
- 'download' => true,
61
- 'content' => SG_POPUP_POST_TYPE,
62
- 'sgpbExportAction' => 1
63
- ), $exportURL);
64
-
65
- return $url;
66
- }
67
-
68
- public static function addArgsToURl($url, $args = array())
69
- {
70
- $resultURl = add_query_arg($args, $url);
71
-
72
- return $resultURl;
73
- }
74
-
75
- public static function buildCreatePopupUrl($popupType)
76
- {
77
- $isAvailable = $popupType->isAvailable();
78
- $name = $popupType->getName();
79
-
80
- $popupUrl = SG_POPUP_ADMIN_URL.'post-new.php?post_type='.SG_POPUP_POST_TYPE.'&sgpb_type='.$name;
81
-
82
- if (!$isAvailable) {
83
- $popupUrl = SG_POPUP_PRO_URL;
84
- }
85
-
86
- return $popupUrl;
87
- }
88
-
89
- public static function getPopupThumbClass($popupType)
90
- {
91
- $isAvailable = $popupType->isAvailable();
92
- $name = $popupType->getName();
93
-
94
- $popupTypeClassName = $name.'-popup';
95
-
96
- if (!$isAvailable) {
97
- $popupTypeClassName .= '-pro';
98
- }
99
-
100
- return $popupTypeClassName;
101
- }
102
-
103
- public static function createSelectBox($data, $selectedValue, $attrs)
104
- {
105
- $attrString = '';
106
- $selected = '';
107
- $selectBoxCloseTag = '</select>';
108
-
109
- if (!empty($attrs) && isset($attrs)) {
110
-
111
- foreach ($attrs as $attrName => $attrValue) {
112
- $attrString .= ''.$attrName.'="'.$attrValue.'" ';
113
- }
114
- }
115
-
116
- $selectBox = '<select '.$attrString.'>';
117
- if (empty($data) || !is_array($data)) {
118
- $selectBox .= $selectBoxCloseTag;
119
- return $selectBox;
120
- }
121
-
122
- foreach ($data as $value => $label) {
123
- // When is multiSelect
124
- if (is_array($selectedValue)) {
125
- $isSelected = in_array($value, $selectedValue);
126
- if ($isSelected) {
127
- $selected = 'selected';
128
- }
129
- }
130
- else if ($selectedValue == $value) {
131
- $selected = 'selected';
132
- }
133
- else if (is_array($value) && in_array($selectedValue, $value)) {
134
- $selected = 'selected';
135
- }
136
-
137
- if (is_array($label)) {
138
- $selectBox .= '<optgroup label="'.$value.'">';
139
- foreach ($label as $key => $optionLabel) {
140
- $selected = '';
141
- if (is_array($selectedValue)) {
142
- $isSelected = in_array($key, $selectedValue);
143
- if ($isSelected) {
144
- $selected = 'selected';
145
- }
146
- }
147
- else if ($selectedValue == $key) {
148
- $selected = 'selected';
149
- }
150
- else if (is_array($key) && in_array($selectedValue, $key)) {
151
- $selected = 'selected';
152
- }
153
-
154
- $selectBox .= '<option value="'.$key.'" '.$selected.'>'.$optionLabel.'</option>';
155
- }
156
- $selectBox .= '</optgroup>';
157
- }
158
- else {
159
- $selectBox .= '<option value="'.$value.'" '.$selected.'>'.$label.'</option>';
160
- }
161
-
162
- $selected = '';
163
- }
164
-
165
- $selectBox .= $selectBoxCloseTag;
166
-
167
- return $selectBox;
168
- }
169
-
170
- public static function createInput($data, $selectedValue, $attrs)
171
- {
172
- $attrString = '';
173
- $savedData = $data;
174
-
175
- if (isset($selectedValue)) {
176
- $savedData = $selectedValue;
177
- }
178
- if (empty($savedData)) {
179
- $savedData = '';
180
- }
181
-
182
- if (!empty($attrs) && isset($attrs)) {
183
-
184
- foreach ($attrs as $attrName => $attrValue) {
185
- if ($attrName == 'class') {
186
- $attrValue .= '';
187
- }
188
- $attrString .= ''.$attrName.'="'.$attrValue.'" ';
189
- }
190
- }
191
-
192
- $input = "<input $attrString value=\"".esc_attr($savedData)."\">";
193
-
194
- return $input;
195
- }
196
-
197
- public static function createCheckBox($data, $selectedValue, $attrs)
198
- {
199
- $attrString = '';
200
- $checked = '';
201
-
202
- if (!empty($selectedValue)) {
203
- $checked = 'checked';
204
- }
205
- if (!empty($attrs) && isset($attrs)) {
206
-
207
- foreach ($attrs as $attrName => $attrValue) {
208
- $attrString .= ''.$attrName.'="'.$attrValue.'" ';
209
- }
210
- }
211
-
212
- $input = "<input $attrString $checked>";
213
-
214
- return $input;
215
- }
216
-
217
- public static function createRadioButtons($elements, $name, $selectedInput, $lineMode = false, $extraHtmlAfterInput = '')
218
- {
219
- $str = '';
220
-
221
- foreach ($elements as $key => $element) {
222
- $value = '';
223
- $checked = '';
224
- $stringWithlabel = '';
225
- $labelClasses = '';
226
- $stringLabel = '';
227
-
228
- if (isset($element['value'])) {
229
- $value = $element['value'];
230
- }
231
- if (isset($element['label_class'])) {
232
- $labelClasses = 'class="'.$element['label_class'].'"';
233
- $stringLabel = '<span class="sgpb-margin-bottom-10">'.esc_attr($value).'</span>';
234
- }
235
-
236
- if (is_array($element) && $element['value'] == $selectedInput) {
237
- $checked = 'checked';
238
- }
239
- else if (!is_array($element) && $element == $selectedInput) {
240
- $checked = 'checked';
241
- }
242
- $attrStr = '';
243
- if (isset($element['data-attributes'])) {
244
- foreach ($element['data-attributes'] as $attrKey => $dataValue) {
245
- $attrStr .= $attrKey.'="'.esc_attr($dataValue).'" ';
246
- }
247
- }
248
- if (!empty($extraHtmlAfterInput)) {
249
- if ($extraHtmlAfterInput == 'img') {
250
- $extraHtmlAfterInput = '<img src="">';
251
- }
252
- else if ($extraHtmlAfterInput == 'bg_img') {
253
- $extraHtmlAfterInput = '<span class="sgpb-popup-theme-img sgpb-margin-x-7"></span>';
254
- }
255
- }
256
-
257
- if ($lineMode) {
258
- if (!empty($extraHtmlAfterInput)) {
259
- $str .= '<label '.$labelClasses.'><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>'.$extraHtmlAfterInput.$stringLabel.'</label>';
260
- }
261
- else {
262
- $str .= '<input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>';
263
- }
264
- }
265
- else {
266
- $str .= '<div class="row form-group">';
267
- $str .= '<label class="col-md-5 control-label">'.__($element['title'], SG_POPUP_TEXT_DOMAIN).'</label>';
268
- $str .= '<div class="col-sm-7"><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' autocomplete="off">'.$extraHtmlAfterInput.'</div>';
269
- $str .= '</div>';
270
- }
271
- }
272
-
273
- echo $str;
274
- }
275
-
276
- public static function getDateObjFromDate($dueDate, $timezone = 'America/Los_Angeles', $format = 'Y-m-d H:i:s')
277
- {
278
- $dateObj = new DateTime($dueDate, new DateTimeZone($timezone));
279
- $dateObj->format($format);
280
-
281
- return $dateObj;
282
- }
283
-
284
- /**
285
- * Serialize data
286
- *
287
- * @since 1.0.0
288
- *
289
- * @param array $data
290
- *
291
- * @return string $serializedData
292
- */
293
- public static function serializeData($data = array())
294
- {
295
- $serializedData = serialize($data);
296
-
297
- return $serializedData;
298
- }
299
-
300
- /**
301
- * Get correct size to use it safely inside CSS rules
302
- *
303
- * @since 1.0.0
304
- *
305
- * @param string $dimension
306
- *
307
- * @return string $size
308
- */
309
- public static function getCSSSafeSize($dimension)
310
- {
311
- if (empty($dimension)) {
312
- return 'inherit';
313
- }
314
-
315
- $size = (int)$dimension.'px';
316
- // If user write dimension in px or % we give that dimension to target otherwise the default value will be px
317
- if (strpos($dimension, '%') || strpos($dimension, 'px')) {
318
- $size = $dimension;
319
- }
320
-
321
- return $size;
322
- }
323
-
324
- public static function deleteSubscriptionPopupSubscribers($popupId)
325
- {
326
- global $wpdb;
327
-
328
- $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE subscriptionType = %s', $popupId);
329
- $wpdb->query($prepareSql);
330
- }
331
-
332
- public static function subscribersRelatedQuery($query = '', $additionalColumn = '')
333
- {
334
- global $wpdb;
335
- $subscribersTablename = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
336
- $postsTablename = $wpdb->prefix.SGPB_POSTS_TABLE_NAME;
337
-
338
- if ($query == '') {
339
- $query = 'SELECT firstName, lastName, email, cDate, '.$additionalColumn.' '.$postsTablename.'.post_title AS subscriptionTitle FROM '.$subscribersTablename.' ';
340
- }
341
-
342
- $searchQuery = ' unsubscribed <> 1';
343
- $filterCriteria = '';
344
-
345
- $query .= ' LEFT JOIN '.$postsTablename.' ON '.$postsTablename.'.ID='.$subscribersTablename.'.subscriptionType';
346
-
347
- if (isset($_GET['sgpb-subscription-popup-id']) && !empty($_GET['sgpb-subscription-popup-id'])) {
348
- $filterCriteria = esc_sql($_GET['sgpb-subscription-popup-id']);
349
- if ($filterCriteria != 'all') {
350
- $searchQuery .= " AND (subscriptionType = $filterCriteria)";
351
- }
352
- }
353
- if ($filterCriteria != '' && $filterCriteria != 'all' && isset($_GET['s']) && !empty($_GET['s'])) {
354
- $searchQuery .= ' AND ';
355
- }
356
- if (isset($_GET['s']) && !empty($_GET['s'])) {
357
- $searchCriteria = esc_sql($_GET['s']);
358
- $lastPartOfTheQuery = substr($searchQuery, -5);
359
- if (strpos($lastPartOfTheQuery, 'AND') <= 0) {
360
- $searchQuery .= ' AND ';
361
- }
362
- $searchQuery .= "(firstName LIKE '%$searchCriteria%' or lastName LIKE '%$searchCriteria%' or email LIKE '%$searchCriteria%' or $postsTablename.post_title LIKE '%$searchCriteria%')";
363
- }
364
- if (isset($_GET['sgpb-subscribers-date']) && !empty($_GET['sgpb-subscribers-date'])) {
365
- $filterCriteria = esc_sql($_GET['sgpb-subscribers-date']);
366
- if ($filterCriteria != 'all') {
367
- if ($searchQuery != '') {
368
- $searchQuery .= ' AND ';
369
- }
370
- $searchQuery .= " cDate LIKE '$filterCriteria%'";
371
- }
372
- }
373
- if ($searchQuery != '') {
374
- $query .= " WHERE $searchQuery";
375
- }
376
-
377
- return $query;
378
- }
379
-
380
- public static function themeRelatedSettings($popupId, $buttonPosition, $theme)
381
- {
382
- if ($popupId) {
383
- if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
384
- if (!isset($buttonPosition)) {
385
- $buttonPosition = 'bottomRight';
386
- }
387
- }
388
- else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
389
- if (!isset($buttonPosition)) {
390
- $buttonPosition = 'topRight';
391
- }
392
- }
393
- }
394
- else {
395
- if (isset($theme)) {
396
- if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
397
- $buttonPosition = 'bottomRight';
398
- }
399
- else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
400
- $buttonPosition = 'topRight';
401
- }
402
- }
403
- else {
404
- /* by default set position for the first theme */
405
- $buttonPosition = 'bottomRight';
406
- }
407
- }
408
-
409
- return $buttonPosition;
410
- }
411
-
412
- /**
413
- * Create html attrs
414
- *
415
- * @since 1.0.0
416
- *
417
- * @param array $attrs
418
- *
419
- * @return string $attrStr
420
- */
421
- public static function createAttrs($attrs)
422
- {
423
- $attrStr = '';
424
-
425
- if (empty($attrs)) {
426
- return $attrStr;
427
- }
428
-
429
- foreach ($attrs as $attrKey => $attrValue) {
430
- $attrStr .= $attrKey.'="'.$attrValue.'" ';
431
- }
432
-
433
- return $attrStr;
434
- }
435
-
436
- public static function getFormattedDate($date)
437
- {
438
- $date = strtotime($date);
439
- $month = date('F', $date);
440
- $year = date('Y', $date);
441
-
442
- return $month.' '.$year;
443
- }
444
-
445
- public static function defaultButtonImage($theme, $closeImage = '')
446
- {
447
- $currentPostType = self::getCurrentPopupType();
448
- if (defined('SGPB_POPUP_TYPE_RECENT_SALES') && $currentPostType == SGPB_POPUP_TYPE_RECENT_SALES) {
449
- $theme = 'sgpb-theme-6';
450
- }
451
- // if no image, set default by theme
452
- if ($closeImage == '') {
453
- if ($theme == 'sgpb-theme-1' || !$theme) {
454
- $closeImage = SG_POPUP_IMG_URL.'theme_1/close.png';
455
- }
456
- else if ($theme == 'sgpb-theme-2') {
457
- $closeImage = SG_POPUP_IMG_URL.'theme_2/close.png';
458
- }
459
- else if ($theme == 'sgpb-theme-3') {
460
- $closeImage = SG_POPUP_IMG_URL.'theme_3/close.png';
461
- }
462
- else if ($theme == 'sgpb-theme-5') {
463
- $closeImage = SG_POPUP_IMG_URL.'theme_5/close.png';
464
- }
465
- else if ($theme == 'sgpb-theme-6') {
466
- $closeImage = SG_POPUP_IMG_URL.'theme_6/close.png';
467
- }
468
- }
469
- else {
470
- $closeImage = self::getImageDataFromUrl($closeImage);
471
- }
472
-
473
- return $closeImage;
474
- }
475
-
476
- public static function getPopupPostAllowedUserRoles()
477
- {
478
- $userSavedRoles = get_option('sgpb-user-roles');
479
-
480
- if (empty($userSavedRoles) || !is_array($userSavedRoles)) {
481
- $userSavedRoles = array('administrator');
482
- }
483
- else {
484
- array_push($userSavedRoles, 'administrator');
485
- }
486
-
487
- return $userSavedRoles;
488
- }
489
-
490
- public static function showMenuForCurrentUser()
491
- {
492
- return self::userCanAccessTo();
493
- }
494
-
495
- public static function getPopupsIdAndTitle($excludesPopups = array())
496
- {
497
- $allPopups = SGPopup::getAllPopups();
498
- $popupIdTitles = array();
499
-
500
- if (empty($allPopups)) {
501
- return $popupIdTitles;
502
- }
503
-
504
- foreach ($allPopups as $popup) {
505
- if (empty($popup)) {
506
- continue;
507
- }
508
-
509
- $id = $popup->getId();
510
- $title = $popup->getTitle();
511
- $type = $popup->getType();
512
-
513
- if (!empty($excludesPopups)) {
514
- foreach ($excludesPopups as $excludesPopupId) {
515
- if ($excludesPopupId != $id) {
516
- $popupIdTitles[$id] = $title.' - '.$type;
517
- }
518
- }
519
- }
520
- else {
521
- $popupIdTitles[$id] = $title.' - '.$type;
522
- }
523
- }
524
-
525
- return $popupIdTitles;
526
- }
527
-
528
- /**
529
- * Merge two array and merge same key values to same array
530
- *
531
- * @since 1.0.0
532
- *
533
- * @param array $array1
534
- * @param array $array2
535
- *
536
- * @return array|bool
537
- *
538
- */
539
- public static function arrayMergeSameKeys($array1, $array2)
540
- {
541
- if (empty($array1)) {
542
- return array();
543
- }
544
-
545
- $modified = false;
546
- $array3 = array();
547
- foreach ($array1 as $key => $value) {
548
- if (isset($array2[$key]) && is_array($array2[$key])) {
549
- $arrDifference = array_diff($array2[$key], $array1[$key]);
550
- if (empty($arrDifference)) {
551
- continue;
552
- }
553
-
554
- $modified = true;
555
- $array3[$key] = array_merge($array2[$key], $array1[$key]);
556
- unset($array2[$key]);
557
- continue;
558
- }
559
-
560
- $modified = true;
561
- $array3[$key] = $value;
562
- }
563
-
564
- // when there are no values
565
- if (!$modified) {
566
- return $modified;
567
- }
568
-
569
- return $array2 + $array3;
570
- }
571
-
572
- public static function getCurrentUserRole()
573
- {
574
- $role = array('administrator');
575
-
576
- if (is_multisite()) {
577
-
578
- $getUsersObj = get_users(
579
- array(
580
- 'blog_id' => get_current_blog_id(),
581
- 'search' => get_current_user_id()
582
- )
583
- );
584
-
585
- if (!empty($getUsersObj[0])) {
586
- $roles = $getUsersObj[0]->roles;
587
-
588
- if (is_array($roles) && !empty($roles)) {
589
- $role = array_merge($role, $getUsersObj[0]->roles);
590
- }
591
- }
592
-
593
- return $role;
594
- }
595
-
596
- global $current_user;
597
- if (!empty($current_user)) {
598
- $role = $current_user->roles;
599
- }
600
-
601
- return $role;
602
- }
603
-
604
- public static function hexToRgba($color, $opacity = false)
605
- {
606
- $default = 'rgb(0,0,0)';
607
-
608
- //Return default if no color provided
609
- if (empty($color)) {
610
- return $default;
611
- }
612
-
613
- //Sanitize $color if "#" is provided
614
- if ($color[0] == '#') {
615
- $color = substr($color, 1);
616
- }
617
-
618
- //Check if color has 6 or 3 characters and get values
619
- if (strlen($color) == 6) {
620
- $hex = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);
621
- }
622
- else if (strlen($color) == 3) {
623
- $hex = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
624
- }
625
- else {
626
- return $default;
627
- }
628
-
629
- //Convert hexadec to rgb
630
- $rgb = array_map('hexdec', $hex);
631
-
632
- //Check if opacity is set(rgba or rgb)
633
- if ($opacity !== false) {
634
- if (abs($opacity) > 1) {
635
- $opacity = 1.0;
636
- }
637
- $output = 'rgba('.implode(',', $rgb).','.$opacity.')';
638
- }
639
- else {
640
- $output = 'rgb('.implode(',', $rgb).')';
641
- }
642
-
643
- //Return rgb(a) color string
644
- return $output;
645
- }
646
-
647
- public static function getAllActiveExtensions()
648
- {
649
- $extensions = SgpbDataConfig::getOldExtensionsInfo();
650
- $labels = array();
651
-
652
- foreach ($extensions as $extension) {
653
- if (file_exists(WP_PLUGIN_DIR.'/'.$extension['folderName'])) {
654
- $labels[] = $extension['label'];
655
- }
656
- }
657
-
658
- return $labels;
659
- }
660
-
661
- public static function renderExtensionsContent()
662
- {
663
- $extensions = self::getAllActiveExtensions();
664
- ob_start();
665
- ?>
666
- <p class="sgpb-extension-notice-close">x</p>
667
- <div class="sgpb-extensions-list-wrapper">
668
- <div class="sgpb-notice-header">
669
- <h3><?php _e('Popup Builder plugin has been successfully updated', SG_POPUP_TEXT_DOMAIN); ?></h3>
670
- <h4><?php _e('The following extensions need to be updated manually', SG_POPUP_TEXT_DOMAIN); ?></h4>
671
- </div>
672
- <ul class="sgpb-extensions-list">
673
- <?php foreach ($extensions as $extensionName): ?>
674
- <a target="_blank" href="https://popup-builder.com/forms/control-panel/"><li><?php echo $extensionName; ?></li></a>
675
- <?php endforeach; ?>
676
- </ul>
677
- </div>
678
- <p class="sgpb-extension-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN)?></p>
679
- <?php
680
- $content = ob_get_contents();
681
- ob_get_clean();
682
-
683
- return $content;
684
- }
685
-
686
- public static function getReverseConvertIds()
687
- {
688
- $idsMappingSaved = get_option('sgpbConvertedIds');
689
- $ids = array();
690
-
691
- if ($idsMappingSaved) {
692
- $ids = $idsMappingSaved;
693
- }
694
-
695
- return array_flip($ids);
696
- }
697
-
698
- public static function getAllFreeExtensions()
699
- {
700
- $allExtensions = SgpbDataConfig::allFreeExtensionsKeys();
701
-
702
- $notActiveExtensions = array();
703
- $activeExtensions = array();
704
-
705
- foreach ($allExtensions as $extension) {
706
- if (!is_plugin_active($extension['pluginKey'])) {
707
- $notActiveExtensions[] = $extension;
708
- }
709
- else {
710
- $activeExtensions[] = $extension;
711
- }
712
- }
713
-
714
- $divideExtension = array(
715
- 'noActive' => $notActiveExtensions,
716
- 'active' => $activeExtensions
717
- );
718
-
719
- return $divideExtension;
720
- }
721
-
722
- public static function getAllExtensions()
723
- {
724
- $allExtensions = SgpbDataConfig::allExtensionsKeys();
725
-
726
- $notActiveExtensions = array();
727
- $activeExtensions = array();
728
-
729
- foreach ($allExtensions as $extension) {
730
- if (!is_plugin_active($extension['pluginKey'])) {
731
- $notActiveExtensions[] = $extension;
732
- }
733
- else {
734
- $activeExtensions[] = $extension;
735
- }
736
- }
737
-
738
- $divideExtension = array(
739
- 'noActive' => $notActiveExtensions,
740
- 'active' => $activeExtensions
741
- );
742
-
743
- return $divideExtension;
744
- }
745
-
746
- public static function renderAlertProblem()
747
- {
748
- ob_start();
749
- ?>
750
- <div id="welcome-panel" class="update-nag sgpb-alert-problem">
751
- <div class="welcome-panel-content">
752
- <p class="sgpb-problem-notice-close">x</p>
753
- <div class="sgpb-alert-problem-text-wrapper">
754
- <h3><?php _e('Popup Builder plugin has been updated to the new version 3.', SG_POPUP_TEXT_DOMAIN); ?></h3>
755
- <h5><?php _e('A lot of changes and improvements have been made.', SG_POPUP_TEXT_DOMAIN); ?></h5>
756
- <h5><?php _e('In case of any issues, please contact us <a href="<?php echo SG_POPUP_TICKET_URL; ?>" target="_blank">here</a>.', SG_POPUP_TEXT_DOMAIN); ?></h5>
757
- </div>
758
- <p class="sgpb-problem-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN); ?></p>
759
- </div>
760
- </div>
761
- <?php
762
- $content = ob_get_clean();
763
-
764
- return $content;
765
- }
766
-
767
- public static function getTaxonomyBySlug($slug = '')
768
- {
769
- $allTerms = get_terms(array('hide_empty' => false));
770
-
771
- $result = array();
772
- if (empty($allTerms)) {
773
- return $result;
774
- }
775
- if ($slug == '') {
776
- return $allTerms;
777
- }
778
- foreach ($allTerms as $term) {
779
- if ($term->slug == $slug) {
780
- return $term;
781
- }
782
- }
783
- }
784
-
785
- public static function getCurrentPopupType()
786
- {
787
- $type = '';
788
- if (!empty($_GET['sgpb_type'])) {
789
- $type = $_GET['sgpb_type'];
790
- }
791
-
792
- $currentPostType = self::getCurrentPostType();
793
-
794
- if ($currentPostType == SG_POPUP_POST_TYPE && !empty($_GET['post'])) {
795
- $popupObj = SGPopup::find($_GET['post']);
796
- if (is_object($popupObj)) {
797
- $type = $popupObj->getType();
798
- }
799
- }
800
-
801
- return $type;
802
- }
803
-
804
- public static function getCurrentPostType()
805
- {
806
- global $post_type;
807
- global $post;
808
- $currentPostType = '';
809
-
810
- if (is_object($post)) {
811
- $currentPostType = $post->post_type;
812
- }
813
-
814
- // in some themes global $post returns null
815
- if (empty($currentPostType)) {
816
- $currentPostType = $post_type;
817
- }
818
-
819
- if (empty($currentPostType) && !empty($_GET['post'])) {
820
- $currentPostType = get_post_type($_GET['post']);
821
- }
822
-
823
- return $currentPostType;
824
- }
825
-
826
- /**
827
- * Get image encoded data from URL
828
- *
829
- * @param $imageUrl
830
- * @param $shouldNotConvertBase64
831
- *
832
- * @return string
833
- */
834
-
835
- public static function getImageDataFromUrl($imageUrl, $shouldNotConvertBase64 = false)
836
- {
837
- $remoteData = wp_remote_get($imageUrl);
838
- if (is_wp_error($remoteData) && $shouldNotConvertBase64) {
839
- return SG_POPUP_IMG_URL.'NoImage.png';
840
- }
841
-
842
- if (!$shouldNotConvertBase64) {
843
- $imageData = wp_remote_retrieve_body($remoteData);
844
- $imageUrl = base64_encode($imageData);
845
- }
846
-
847
- return $imageUrl;
848
- }
849
-
850
- public static function deleteUserFromSubscribers($params = array())
851
- {
852
- global $wpdb;
853
-
854
- $email = '';
855
- $popup = '';
856
- $noSubscriber = true;
857
-
858
- if (isset($params['email'])) {
859
- $email = $params['email'];
860
- }
861
- if (isset($params['popup'])) {
862
- $popup = $params['popup'];
863
- }
864
-
865
- $prepareSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s && subscriptionType = %s', $email, $popup);
866
- $res = $wpdb->get_row($prepareSql, ARRAY_A);
867
- if (!isset($res['id'])) {
868
- $noSubscriber = false;
869
- }
870
- $params['subscriberId'] = $res['id'];
871
-
872
- $subscriber = self::subscriberExists($params);
873
- if ($subscriber && $noSubscriber) {
874
- self::deleteSubscriber($params);
875
- }
876
- else if (!$noSubscriber) {
877
- _e('<span>Oops, something went wrong, please try again or contact the administrator to check more info.</span>', SG_POPUP_TEXT_DOMAIN);
878
- wp_die();
879
- }
880
- }
881
-
882
- public static function subscriberExists($params = array())
883
- {
884
- if (empty($params)) {
885
- return false;
886
- }
887
-
888
- $receivedToken = $params['token'];
889
- $realToken = md5($params['subscriberId'].$params['email']);
890
- if ($receivedToken == $realToken) {
891
- return true;
892
- }
893
-
894
- }
895
-
896
- public static function deleteSubscriber($params = array())
897
- {
898
- global $wpdb;
899
- $homeUrl = get_home_url();
900
-
901
- if (empty($params)) {
902
- return false;
903
- }
904
- // send email to admin about user unsubscription
905
- self::sendEmailAboutUnsubscribe($params);
906
-
907
- $prepareSql = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET unsubscribed = 1 WHERE id = %s ', $params['subscriberId']);
908
- $wpdb->query($prepareSql);
909
-
910
- _e('<span>You have successfully unsubscribed. <a href="'.esc_attr($homeUrl).'">click here</a> to go to the home page.</span>', SG_POPUP_TEXT_DOMAIN);
911
- wp_die();
912
- }
913
-
914
- public static function sendEmailAboutUnsubscribe($params = array())
915
- {
916
- if (empty($params)) {
917
- return false;
918
- }
919
-
920
- $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
921
- $receiverEmail = get_bloginfo('admin_email');
922
- $userEmail = $params['email'];
923
- $emailTitle = __('Unsubscription', SG_POPUP_TEXT_DOMAIN);
924
- $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
925
- $subscriptionFormTitle = get_the_title($subscriptionFormId);
926
-
927
- $message = __('User with '.$userEmail.' email has unsubscribed from '.$subscriptionFormTitle.' mail list', SG_POPUP_TEXT_DOMAIN);
928
-
929
- $headers = 'MIME-Version: 1.0'."\r\n";
930
- $headers .= 'From: WordPress Popup Builder'."\r\n";
931
- $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
932
-
933
- wp_mail($receiverEmail, $emailTitle, $message, $headers);
934
- }
935
-
936
- public static function addUnsubscribeColumn()
937
- {
938
- global $wpdb;
939
-
940
- $sql = 'ALTER TABLE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' ADD COLUMN unsubscribed INT NOT NULL DEFAULT 0 ';
941
- $wpdb->query($sql);
942
- }
943
-
944
- public static function isPluginActive($key)
945
- {
946
- $allExtensions = SgpbDataConfig::allExtensionsKeys();
947
- $isActive = false;
948
- foreach ($allExtensions as $extension) {
949
- if (isset($extension['key']) && $extension['key'] == $key) {
950
- if (is_plugin_active($extension['pluginKey'])) {
951
- $isActive = true;
952
- return $isActive;
953
- }
954
- }
955
- }
956
-
957
- return $isActive;
958
- }
959
-
960
- public static function supportBannerNotification()
961
- {
962
- $content = '<div class="sgpb-support-notification-wrapper sgpb-wrapper"><h4 class="sgpb-support-notification-title">'.__('Need some help?', SG_POPUP_TEXT_DOMAIN).'</h4>';
963
- $content .= '<h4 class="sgpb-support-notification-title">'.__('Let us know what you think.', SG_POPUP_TEXT_DOMAIN).'</h4>';
964
- $content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_RATE_US_URL.'"><span class="dashicons sgpb-dashicons-heart sgpb-info-text-white"></span><span class="sg-info-text">'.__('Rate Us', SG_POPUP_TEXT_DOMAIN).'</span></a>';
965
- $content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_TICKET_URL.'"><span class="dashicons sgpb-dashicons-megaphone sgpb-info-text-white"></span>'.__('Support Potal', SG_POPUP_TEXT_DOMAIN).'</a>';
966
- $content .= '<a class="btn btn-info" target="_blank" href="https://wordpress.org/support/plugin/popup-builder"><span class="dashicons sgpb-dashicons-admin-plugins sgpb-info-text-white"></span>'.__('Support Forum', SG_POPUP_TEXT_DOMAIN).'</a>';
967
- $content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_STORE_URL.'"><span class="dashicons sgpb-dashicons-editor-help sgpb-info-text-white"></span>'.__('LIVE chat', SG_POPUP_TEXT_DOMAIN).'</a>';
968
- $content .= '<a class="btn btn-info" target="_blank" href="mailto:support@popup-builder.com?subject=Hello"><span class="dashicons sgpb-dashicons-email-alt sgpb-info-text-white"></span>'.__('Email', SG_POPUP_TEXT_DOMAIN).'</a></div>';
969
- $content .= '<div class="sgpb-support-notification-dont-show">'.__('Bored of this?').'<a class="sgpb-dont-show-again-support-notification" href="javascript:void(0)">'.__(' Press here ').'</a>'.__('and we will not show it again!').'</div>';
970
-
971
- return $content;
972
- }
973
-
974
- public static function getMaxOpenDaysMessage()
975
- {
976
- $getUsageDays = self::getPopupUsageDays();
977
- $firstHeader = __('<h1 class="sgpb-review-h1"><strong class="sgrb-review-strong">This is great!</strong> We have noticed that you are using Popup Builder plugin on your site for '.$getUsageDays.' days, we are thankful for that.</h1>', SG_POPUP_TEXT_DOMAIN);
978
- $popupContent = self::getMaxOpenPopupContent($firstHeader, 'days');
979
-
980
- return $popupContent;
981
- }
982
-
983
- public static function getPopupUsageDays()
984
- {
985
- $installDate = get_option('SGPBInstallDate');
986
-
987
- $timeDate = new \DateTime('now');
988
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
989
- $diff = $timeNow-$installDate;
990
- $days = floor($diff/(60*60*24));
991
-
992
- return $days;
993
- }
994
-
995
- public static function getMaxOpenPopupContent($firstHeader, $type)
996
- {
997
- ob_start();
998
- ?>
999
- <style>
1000
- .sgpb-buttons-wrapper .press{
1001
- box-sizing:border-box;
1002
- cursor:pointer;
1003
- display:inline-block;
1004
- font-size:1em;
1005
- margin:0;
1006
- padding:0.5em 0.75em;
1007
- text-decoration:none;
1008
- transition:background 0.15s linear
1009
- }
1010
- .sgpb-buttons-wrapper .press-grey {
1011
- background-color:#9E9E9E;
1012
- border:2px solid #9E9E9E;
1013
- color: #FFF;
1014
- }
1015
- .sgpb-buttons-wrapper .press-lightblue {
1016
- background-color:#03A9F4;
1017
- border:2px solid #03A9F4;
1018
- color: #FFF;
1019
- }
1020
- .sgpb-buttons-wrapper {
1021
- text-align: center;
1022
- }
1023
- .sgpb-review-wrapper{
1024
- text-align: center;
1025
- padding: 20px;
1026
- }
1027
- .sgpb-review-wrapper p {
1028
- color: black;
1029
- }
1030
- .sgpb-review-h1 {
1031
- font-size: 22px;
1032
- font-weight: normal;
1033
- line-height: 1.384;
1034
- }
1035
- .sgrb-review-h2{
1036
- font-size: 20px;
1037
- font-weight: normal;
1038
- }
1039
- :root {
1040
- --main-bg-color: #1ac6ff;
1041
- }
1042
- .sgrb-review-strong{
1043
- color: var(--main-bg-color);
1044
- }
1045
- .sgrb-review-mt20{
1046
- margin-top: 20px
1047
- }
1048
- </style>
1049
- <div class="sgpb-review-wrapper">
1050
- <div class="sgpb-review-description">
1051
- <?php echo $firstHeader; ?>
1052
- <h2 class="sgrb-review-h2"><?php _e('This is really great for your website score.', SG_POPUP_TEXT_DOMAIN); ?></h2>
1053
- <p class="sgrb-review-mt20"><?php _e('Have your input in the development of our plugin, and we’ll provide better conversions for your site!<br /> Leave your 5-star positive review and help us go further to the perfection!', SG_POPUP_TEXT_DOMAIN); ?></p>
1054
- </div>
1055
- <div class="sgpb-buttons-wrapper">
1056
- <button class="press press-grey sgpb-button-1 sgpb-close-promo-notification" data-action="sg-already-did-review"><?php _e('I already did', SG_POPUP_TEXT_DOMAIN); ?></button>
1057
- <button class="press press-lightblue sgpb-button-3 sgpb-close-promo-notification" data-action="sg-you-worth-it"><?php _e('You worth it!', SG_POPUP_TEXT_DOMAIN); ?></button>
1058
- <button class="press press-grey sgpb-button-2 sgpb-close-promo-notification" data-action="sg-show-popup-period" data-message-type="<?php echo $type; ?>"><?php _e('Maybe later', SG_POPUP_TEXT_DOMAIN); ?></button></div>
1059
- <div> </div>
1060
- </div>
1061
- <?php
1062
- $popupContent = ob_get_clean();
1063
-
1064
- return $popupContent;
1065
- }
1066
-
1067
- public static function shouldOpenReviewPopupForDays()
1068
- {
1069
- $shouldOpen = true;
1070
- $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1071
- $periodNextTime = get_option('SGPBOpenNextTime');
1072
- /*if (!$dontShowAgain) {
1073
- return true;
1074
- }
1075
- else {
1076
- return false;
1077
- }*/
1078
- // When period next time does not exits it means the user is old
1079
- if (!$periodNextTime) {
1080
- $usageDays = self::getPopupMainTableCreationDate();
1081
- update_option('SGPBUsageDays', $usageDays);
1082
- if (!defined('SGPB_REVIEW_POPUP_PERIOD')) {
1083
- define('SGPB_REVIEW_POPUP_PERIOD', '500');
1084
- }
1085
- // For old users
1086
- if (defined('SGPB_REVIEW_POPUP_PERIOD') && $usageDays > SGPB_REVIEW_POPUP_PERIOD && !$dontShowAgain) {
1087
- return $shouldOpen;
1088
- }
1089
- $remainingDays = SGPB_REVIEW_POPUP_PERIOD - $usageDays;
1090
-
1091
- $popupTimeZone = \ConfigDataHelper::getDefaultTimezone();
1092
- $timeDate = new DateTime('now', new DateTimeZone($popupTimeZone));
1093
- $timeDate->modify('+'.$remainingDays.' day');
1094
-
1095
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
1096
- update_option('SGPBOpenNextTime', $timeNow);
1097
-
1098
- return false;
1099
- }
1100
-
1101
- $currentData = new \DateTime('now');
1102
- $timeNow = $currentData->format('Y-m-d H:i:s');
1103
- $timeNow = strtotime($timeNow);
1104
-
1105
- if ($periodNextTime > $timeNow) {
1106
- $shouldOpen = false;
1107
- }
1108
-
1109
- return $shouldOpen;
1110
- }
1111
-
1112
- public static function getPopupMainTableCreationDate()
1113
- {
1114
- global $wpdb;
1115
-
1116
- $query = $wpdb->prepare('SELECT table_name, create_time FROM information_schema.tables WHERE table_schema=%s AND table_name=%s', DB_NAME, $wpdb->prefix.'sgpb_subscribers');
1117
- $results = $wpdb->get_results($query, ARRAY_A);
1118
- if (empty($results)) {
1119
- return 0;
1120
- }
1121
-
1122
- $createTime = $results[0]['create_time'];
1123
- $createTime = strtotime($createTime);
1124
- update_option('SGPBInstallDate', $createTime);
1125
- $diff = time() - $createTime;
1126
- $days = floor($diff/(60*60*24));
1127
-
1128
- return $days;
1129
- }
1130
-
1131
- public static function shouldOpenForMaxOpenPopupMessage()
1132
- {
1133
- $counterMaxPopup = self::getMaxOpenPopupId();
1134
-
1135
- if (empty($counterMaxPopup)) {
1136
- return false;
1137
- }
1138
- $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1139
- $maxCountDefine = get_option('SGPBMaxOpenCount');
1140
-
1141
- if (!$maxCountDefine) {
1142
- $maxCountDefine = SGPB_ASK_REVIEW_POPUP_COUNT;
1143
- }
1144
-
1145
- return $counterMaxPopup['maxCount'] >= $maxCountDefine && !$dontShowAgain;
1146
- }
1147
-
1148
- public static function getMaxOpenPopupId()
1149
- {
1150
- $popupsCounterData = get_option('SgpbCounter');
1151
- if (!$popupsCounterData) {
1152
- return 0;
1153
- }
1154
-
1155
- $counters = array_values($popupsCounterData);
1156
- $maxCount = max($counters);
1157
- $popupId = array_search($maxCount, $popupsCounterData);
1158
-
1159
- $maxPopupData = array(
1160
- 'popupId' => $popupId,
1161
- 'maxCount' => $maxCount
1162
- );
1163
-
1164
- return $maxPopupData;
1165
- }
1166
-
1167
- public static function getMaxOpenPopupsMessage()
1168
- {
1169
- $counterMaxPopup = self::getMaxOpenPopupId();
1170
- $maxCountDefine = get_option('SGPBMaxOpenCount');
1171
- $popupTitle = get_the_title($counterMaxPopup['popupId']);
1172
-
1173
- if (!empty($counterMaxPopup['maxCount'])) {
1174
- $maxCountDefine = $counterMaxPopup['maxCount'];
1175
- }
1176
-
1177
- $firstHeader = __('<h1 class="sgpb-review-h1"><strong class="sgrb-review-strong">Awesome news!</strong> <b>Popup Builder</b> plugin helped you to share your message via <strong class="sgrb-review-strong">'.$popupTitle.'</strong> popup with your visitors for <strong class="sgrb-review-strong">'.$maxCountDefine.' times!</strong></h1>', SG_POPUP_TEXT_DOMAIN);
1178
- $popupContent = self::getMaxOpenPopupContent($firstHeader, 'count');
1179
-
1180
- return $popupContent;
1181
- }
1182
-
1183
- /**
1184
- * Get email headers
1185
- *
1186
- * @since 3.1.0
1187
- *
1188
- * @param email $fromEmail
1189
- * @param array $args
1190
- *
1191
- * @return string $headers
1192
- */
1193
- public static function getEmailHeader($fromEmail, $args = array())
1194
- {
1195
- $contentType = 'text/html';
1196
- $charset = 'UTF-8';
1197
- $blogInfo = get_bloginfo();
1198
-
1199
- if (!empty($args['contentType'])) {
1200
- $contentType = $args['contentType'];
1201
- }
1202
- if (!empty($args['charset'])) {
1203
- $charset = $args['charset'];
1204
- }
1205
- $headers = 'MIME-Version: 1.0'."\r\n";
1206
- $headers .= 'From: "'.$blogInfo.'" <'.$fromEmail.'>'."\r\n";
1207
- $headers .= 'Content-type: '.$contentType.'; charset='.$charset.''."\r\n"; //set UTF-8
1208
-
1209
- return $headers;
1210
- }
1211
-
1212
- /**
1213
- * Get file content from URL
1214
- *
1215
- * @since 3.1.0
1216
- *
1217
- * @param $url
1218
- *
1219
- * @return string
1220
- */
1221
- public static function getFileFromURL($url)
1222
- {
1223
- $data = '';
1224
- $remoteData = wp_remote_get($url);
1225
-
1226
- if (is_wp_error($remoteData)) {
1227
- return $data;
1228
- }
1229
-
1230
- $data = wp_remote_retrieve_body($remoteData);
1231
-
1232
- return $data;
1233
- }
1234
-
1235
- public static function getRightMetaboxBannerText()
1236
- {
1237
- $bannerText = get_option('sgpb-metabox-banner-remote-get');
1238
-
1239
- return $bannerText;
1240
- }
1241
-
1242
- public static function getGutenbergPopupsIdAndTitle($excludesPopups = array())
1243
- {
1244
- $allPopups = SGPopup::getAllPopups();
1245
- $popupIdTitles = array();
1246
-
1247
- if (empty($allPopups)) {
1248
- return $popupIdTitles;
1249
- }
1250
-
1251
- foreach ($allPopups as $popup) {
1252
- if (empty($popup)) {
1253
- continue;
1254
- }
1255
-
1256
- $id = $popup->getId();
1257
- $title = $popup->getTitle();
1258
- $type = $popup->getType();
1259
-
1260
- if (!empty($excludesPopups)) {
1261
- foreach ($excludesPopups as $excludesPopupId) {
1262
- if ($excludesPopupId != $id) {
1263
- $array = array();
1264
- $array['id'] = $id;
1265
- $array['title'] = $title.' - '.$type;
1266
- $popupIdTitles[] = $array;
1267
- }
1268
- }
1269
- }
1270
- else {
1271
- $array = array();
1272
- $array['id'] = $id;
1273
- $array['title'] = $title.' - '.$type;
1274
- $popupIdTitles[] = $array;
1275
- }
1276
- }
1277
-
1278
- return $popupIdTitles;
1279
- }
1280
-
1281
- public static function getGutenbergPopupsEvents()
1282
- {
1283
- $data = array(
1284
- array('value' => '', 'title' => __('Select Event', SG_POPUP_TEXT_DOMAIN)),
1285
- array('value' => 'inherit', 'title' => __('Inherit', SG_POPUP_TEXT_DOMAIN)),
1286
- array('value' => 'onLoad', 'title' => __('On load', SG_POPUP_TEXT_DOMAIN)),
1287
- array('value' => 'click', 'title' => __('On click', SG_POPUP_TEXT_DOMAIN)),
1288
- array('value' => 'hover', 'title' => __('On hover', SG_POPUP_TEXT_DOMAIN))
1289
- );
1290
-
1291
- return $data;
1292
- }
1293
-
1294
- public static function checkEditorByPopupId($popupId)
1295
- {
1296
- $popupContent = '';
1297
- if (class_exists('\Elementor\Plugin')) {
1298
- $elementorContent = get_post_meta($popupId, '_elementor_edit_mode', true);
1299
- if (!empty($elementorContent) && $elementorContent == 'builder') {
1300
- $popupContent = Elementor\Plugin::instance()->frontend->get_builder_content_for_display($popupId);
1301
- }
1302
- }
1303
- else if (class_exists('Vc_Manager')) {
1304
- $stylesAndScripts = self::renderWPBakeryScriptsAndStyles($popupId);
1305
- $popupContent .= '<style>'.$stylesAndScripts.'</style>';
1306
- }
1307
-
1308
- return $popupContent;
1309
- }
1310
-
1311
- public static function renderWPBakeryScriptsAndStyles($popupId = 0)
1312
- {
1313
- return get_post_meta($popupId, '_wpb_shortcodes_custom_css', true);
1314
- }
1315
-
1316
- /**
1317
- * countdown popup, convert date to seconds
1318
- *
1319
- * @param $dueDate
1320
- * @param $timezone
1321
- * @return false|int|string
1322
- */
1323
- public static function dateToSeconds($dueDate, $timezone)
1324
- {
1325
- if (empty($timezone)) {
1326
- return '';
1327
- }
1328
-
1329
- $dateObj = self::getDateObjFromDate('now', $timezone);
1330
- $timeNow = @strtotime($dateObj);
1331
- $seconds = @strtotime($dueDate)-$timeNow;
1332
- if ($seconds < 0) {
1333
- $seconds = 0;
1334
- }
1335
-
1336
- return $seconds;
1337
- }
1338
-
1339
- /**
1340
- * Get site protocol
1341
- *
1342
- * @since 1.0.0
1343
- *
1344
- * @return string $protocol
1345
- *
1346
- */
1347
- public static function getSiteProtocol()
1348
- {
1349
- $protocol = 'http';
1350
-
1351
- if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
1352
- $protocol = 'https';
1353
- }
1354
-
1355
- return $protocol;
1356
- }
1357
-
1358
- public static function findSubscribersByEmail($subscriberEmail = '', $list = 0)
1359
- {
1360
- global $wpdb;
1361
- $subscriber = array();
1362
-
1363
- $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d ', $subscriberEmail, $list);
1364
- $subscriber = $wpdb->get_row($prepareSql, ARRAY_A);
1365
- if (!$list) {
1366
- $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s ', $subscriberEmail);
1367
- $subscriber = $wpdb->get_results($prepareSql, ARRAY_A);
1368
- }
1369
-
1370
- return $subscriber;
1371
- }
1372
-
1373
- /**
1374
- * Update option
1375
- *
1376
- * @since 3.1.9
1377
- *
1378
- * @return void
1379
- */
1380
- public static function updateOption($optionKey, $optionValue)
1381
- {
1382
- update_option($optionKey, $optionValue);
1383
- }
1384
-
1385
- public static function getOption($optionKey, $default = false)
1386
- {
1387
- return get_option($optionKey, $default);
1388
- }
1389
-
1390
- public static function deleteOption($optionKey)
1391
- {
1392
- delete_option($optionKey);
1393
- }
1394
-
1395
- /**
1396
- * It's change popup registered plugins static paths to dynamic
1397
- *
1398
- * @since 3.1.9
1399
- *
1400
- * @return bool where true mean modified false mean there is not need modification
1401
- */
1402
- public static function makeRegisteredPluginsStaticPathsToDynamic()
1403
- {
1404
- // remove old outdated option sgpbModifiedRegisteredPluginsPaths
1405
- delete_option('sgpbModifiedRegisteredPluginsPaths');
1406
- delete_option('SG_POPUP_BUILDER_REGISTERED_PLUGINS');
1407
- $hasModifiedPaths = AdminHelper::getOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED);
1408
- if ($hasModifiedPaths) {
1409
- return false;
1410
- }
1411
- else {
1412
- Installer::registerPlugin();
1413
- }
1414
- AdminHelper::updateOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED, 1);
1415
-
1416
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1417
- if (empty($registeredPlugins)) {
1418
- return false;
1419
- }
1420
-
1421
- $registeredPlugins = json_decode($registeredPlugins, true);
1422
- if (empty($registeredPlugins)) {
1423
- return false;
1424
- }
1425
-
1426
- foreach ($registeredPlugins as $key => $registeredPlugin) {
1427
- if (empty($registeredPlugin['classPath'])) {
1428
- continue;
1429
- }
1430
- $registeredPlugins[$key]['classPath'] = str_replace(WP_PLUGIN_DIR, '', $registeredPlugin['classPath']);
1431
- if (!empty($registeredPlugin['options']['licence']['file'])) {
1432
- $registeredPlugins[$key]['options']['licence']['file'] = $registeredPlugin['options']['licence']['file'];
1433
- }
1434
- }
1435
- $registeredPlugins = json_encode($registeredPlugins);
1436
-
1437
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredPlugins);
1438
- return true;
1439
- }
1440
-
1441
- public static function hasInactiveExtensions()
1442
- {
1443
- $hasInactiveExtensions = false;
1444
- $allRegiseredPBPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1445
- $allRegiseredPBPlugins = @json_decode($allRegiseredPBPlugins, true);
1446
- if (empty($allRegiseredPBPlugins)) {
1447
- return $hasInactiveExtensions;
1448
- }
1449
-
1450
- foreach ($allRegiseredPBPlugins as $pluginPath => $registeredPlugin) {
1451
- if (!isset($registeredPlugin['options']['licence']['key'])) {
1452
- continue;
1453
- }
1454
- if (!isset($registeredPlugin['options']['licence']['file'])) {
1455
- continue;
1456
- }
1457
- $extensionKey = $registeredPlugin['options']['licence']['file'];
1458
- $isPluginActive = is_plugin_active($extensionKey);
1459
- $pluginKey = $registeredPlugin['options']['licence']['key'];
1460
- $isValidLicense = get_option('sgpb-license-status-'.$pluginKey);
1461
-
1462
- // if we even have at least one inactive extension, we don't need to check remaining extensions
1463
- if ($isValidLicense != 'valid' && $isPluginActive) {
1464
- $hasInactiveExtensions = true;
1465
- break;
1466
- }
1467
- }
1468
-
1469
- return $hasInactiveExtensions;
1470
- }
1471
-
1472
- public static function getSubscriptionColumnsById($id)
1473
- {
1474
- $popup = SGPopup::find($id);
1475
- if (empty($popup) || !is_object($popup)) {
1476
- return array();
1477
- }
1478
- $freeSavedOptions = $popup->getOptionValue('sgpb-subs-fields');
1479
-
1480
- if (!empty($freeSavedOptions)) {
1481
- return array('firstName' => 'First name','lastName' => 'Last name', 'email' => 'Email', 'date' => 'Date');
1482
- }
1483
- $formFieldsJson = $popup->getOptionValue('sgpb-subscription-fields-json');
1484
- if (!empty($formFieldsJson)) {
1485
- $data = apply_filters('sgpbGetSubscriptionLabels', array(), $popup);
1486
- $data['date'] = 'Date';
1487
- return $data;
1488
- }
1489
-
1490
- return array();
1491
- }
1492
-
1493
- public static function getCustomFormFieldsByPopupId($popupId)
1494
- {
1495
- if (!class_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper')) {
1496
- return array();
1497
- }
1498
-
1499
- if (method_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper', 'getCustomFormFieldsByPopupId')) {
1500
- return SubscriptionPlusAdminHelper::getCustomFormFieldsByPopupId($popupId);
1501
- }
1502
-
1503
- return array();
1504
- }
1505
-
1506
- public static function removeAllNonPrintableCharacters($title, $defaultValue)
1507
- {
1508
- $titleRes = $title;
1509
- $pattern = '/[\\\^£$%&*()}{@#~?><>,|=_+¬-]/u';
1510
- $title = preg_replace($pattern, '', $title);
1511
- $title = mb_ereg_replace($pattern, '', $title);
1512
- $title = htmlspecialchars($title, ENT_IGNORE, 'UTF-8');
1513
- $result = str_replace(' ', '', $title);
1514
- if (empty($result)) {
1515
- $titleRes = $defaultValue;
1516
- }
1517
-
1518
- return $titleRes;
1519
- }
1520
-
1521
- public static function renderCustomScripts($popupId)
1522
- {
1523
- $finalResult = '';
1524
- $postMeta = get_post_meta($popupId, 'sg_popup_scripts', true);
1525
- if (empty($postMeta)) {
1526
- return '';
1527
- }
1528
- $defaultData = \ConfigDataHelper::defaultData();
1529
-
1530
- // get scripts
1531
- if (!isset($postMeta['js'])) {
1532
- $postMeta['js'] = array();
1533
- }
1534
- $jsPostMeta = $postMeta['js'];
1535
- $jsDefaultData = $defaultData['customEditorContent']['js']['helperText'];
1536
- $suspiciousStrings = array('document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode', '<!--', '-->');
1537
- $finalContent = '';
1538
- $suspiciousStringFound = false;
1539
- if (!empty($jsPostMeta)) {
1540
- $customScripts = '<script id="sgpb-custom-script-'.$popupId.'">';
1541
- foreach ($jsDefaultData as $key => $value) {
1542
- $eventName = 'sgpb'.$key;
1543
- if ((!isset($jsPostMeta['sgpb-'.$key]) || empty($jsPostMeta['sgpb-'.$key])) || $key == 'ShouldOpen' || $key == 'ShouldClose') {
1544
- continue;
1545
- }
1546
- $content = @$jsPostMeta['sgpb-'.$key];
1547
- $content = str_replace('popupId', $popupId, $content);
1548
- $content = str_replace("<", "&lt;", $content);
1549
- $content = str_replace(">", "&gt;", $content);
1550
- foreach ($suspiciousStrings as $string) {
1551
- if (strpos($content, $string)) {
1552
- $suspiciousStringFound = true;
1553
- break;
1554
- }
1555
- }
1556
- if ($suspiciousStringFound) {
1557
- break;
1558
- }
1559
- $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
1560
-
1561
- $finalContent .= 'jQuery(document).ready(function(){';
1562
- $finalContent .= 'sgAddEvent(window, "'.$eventName.'", function(e) {';
1563
- $finalContent .= 'if (e.detail.popupId == "'.$popupId.'") {';
1564
- $finalContent .= $content;
1565
- $finalContent .= '};';
1566
- $finalContent .= '});';
1567
- $finalContent .= '});';
1568
- }
1569
- $customScripts .= $finalContent;
1570
- $customScripts .= '</script>';
1571
- if (empty($finalContent)) {
1572
- $customScripts = '';
1573
- }
1574
- $finalResult .= $customScripts;
1575
- }
1576
-
1577
- // get styles
1578
- if (isset($postMeta['css'])) {
1579
- $cssPostMeta = $postMeta['css'];
1580
- }
1581
- $finalContent = '';
1582
- if (!empty($cssPostMeta)) {
1583
- $customStyles = '<style id="sgpb-custom-style-'.$popupId.'">';
1584
- $finalContent = str_replace('popupId', $popupId, $cssPostMeta);
1585
- $finalContent = html_entity_decode($finalContent, ENT_QUOTES, 'UTF-8');
1586
-
1587
- $customStyles .= $finalContent;
1588
- $customStyles .= '</style>';
1589
- $finalResult .= $customStyles;
1590
- }
1591
-
1592
-
1593
- return $finalResult;
1594
- }
1595
-
1596
- public static function removeSelectedTypeOptions($type)
1597
- {
1598
- switch ($type) {
1599
- case 'cron':
1600
- $crons = _get_cron_array();
1601
- foreach ($crons as $key => $value) {
1602
- foreach ($value as $key => $body) {
1603
- if (strstr($key, 'sgpb')) {
1604
- wp_clear_scheduled_hook($key);
1605
- }
1606
- }
1607
- }
1608
- break;
1609
- }
1610
- }
1611
-
1612
- public static function getSystemInfoText() {
1613
- global $wpdb;
1614
-
1615
- $browser = self::getBrowser();
1616
-
1617
- // Get theme info
1618
- if (get_bloginfo('version') < '3.4') {
1619
- $themeData = wp_get_theme(get_stylesheet_directory().'/style.css');
1620
- $theme = $themeData['Name'].' '.$themeData['Version'];
1621
- }
1622
- else {
1623
- $themeData = wp_get_theme();
1624
- $theme = $themeData->Name.' '.$themeData->Version;
1625
- }
1626
-
1627
- // Try to identify the hosting provider
1628
- $host = self::getHost();
1629
-
1630
- $systemInfoContent = '### Start System Info ###'."\n\n";
1631
-
1632
- // Start with the basics...
1633
- $systemInfoContent .= '-- Site Info'."\n\n";
1634
- $systemInfoContent .= 'Site URL: '.site_url()."\n";
1635
- $systemInfoContent .= 'Home URL: '.home_url()."\n";
1636
- $systemInfoContent .= 'Multisite: '.(is_multisite() ? 'Yes' : 'No')."\n";
1637
-
1638
- // Can we determine the site's host?
1639
- if ($host) {
1640
- $systemInfoContent .= "\n".'-- Hosting Provider'."\n\n";
1641
- $systemInfoContent .= 'Host: '.$host."\n";
1642
- }
1643
-
1644
- // The local users' browser information, handled by the Browser class
1645
- $systemInfoContent .= "\n".'-- User Browser'."\n\n";
1646
- $systemInfoContent .= $browser;
1647
-
1648
- // WordPress configuration
1649
- $systemInfoContent .= "\n".'-- WordPress Configuration'."\n\n";
1650
- $systemInfoContent .= 'Version: '.get_bloginfo('version')."\n";
1651
- $systemInfoContent .= 'Language: '.(defined('WPLANG') && WPLANG ? WPLANG : 'en_US')."\n";
1652
- $systemInfoContent .= 'Permalink Structure: '.(get_option('permalink_structure') ? get_option('permalink_structure') : 'Default')."\n";
1653
- $systemInfoContent .= 'Active Theme: '.$theme."\n";
1654
- $systemInfoContent .= 'Show On Front: '.get_option('show_on_front')."\n";
1655
-
1656
- // Only show page specs if frontpage is set to 'page'
1657
- if (get_option('show_on_front') == 'page') {
1658
- $frontPageId = get_option('page_on_front');
1659
- $blogPageId = get_option('page_for_posts');
1660
-
1661
- $systemInfoContent .= 'Page On Front: '.($frontPageId != 0 ? get_the_title($frontPageId).' (#'.$frontPageId.')' : 'Unset')."\n";
1662
- $systemInfoContent .= 'Page For Posts: '.($blogPageId != 0 ? get_the_title($blogPageId).' (#'.$blogPageId.')' : 'Unset')."\n";
1663
- }
1664
-
1665
- $systemInfoContent .= 'Table Prefix: '.'Prefix: '.$wpdb->prefix.' Length: '.strlen($wpdb->prefix ).' Status: '.( strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable')."\n";
1666
- $systemInfoContent .= 'WP_DEBUG: '.(defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set')."\n";
1667
- $systemInfoContent .= 'Memory Limit: '.WP_MEMORY_LIMIT."\n";
1668
- $systemInfoContent .= 'Registered Post Stati: '.implode(', ', get_post_stati())."\n";
1669
-
1670
- // Must-use plugins
1671
- $muplugins = get_mu_plugins();
1672
- if ($muplugins && count($muplugins)) {
1673
- $systemInfoContent .= "\n".'-- Must-Use Plugins'."\n\n";
1674
-
1675
- foreach ($muplugins as $plugin => $plugin_data) {
1676
- $systemInfoContent .= $plugin_data['Name'].': '.$plugin_data['Version']."\n";
1677
- }
1678
- }
1679
-
1680
- $registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1681
- $registered = json_decode($registered, true);
1682
-
1683
- if (empty($registered)) {
1684
- return false;
1685
- }
1686
- // remove free package data, we don't need it
1687
- array_shift($registered);
1688
-
1689
- $systemInfoContent .= "\n".'-- Popup Builder License Data'."\n\n";
1690
- if (!empty($registered)) {
1691
- foreach ($registered as $singleExntensionData) {
1692
- if (empty($singleExntensionData['options'])) {
1693
- continue;
1694
- }
1695
-
1696
- $key = $singleExntensionData['options']['licence']['key'];
1697
- $name = $singleExntensionData['options']['licence']['itemName'];
1698
- $licenseKey = __('No license');
1699
- if (!empty($key)) {
1700
- $licenseKey = self::getOption('sgpb-license-key-'.$key);
1701
- }
1702
- $licenseStatus = 'Inactive';
1703
- if (self::getOption('sgpb-license-status-'.$key) == 'valid') {
1704
- $licenseStatus = 'Active';
1705
- }
1706
-
1707
- $systemInfoContent .= 'Name: '.$name."\n";
1708
- $systemInfoContent .= 'License key: '.$licenseKey."\n";
1709
- $systemInfoContent .= 'License status: '.$licenseStatus."\n";
1710
- $systemInfoContent .= "\n";
1711
- }
1712
- }
1713
-
1714
- $systemInfoContent .= "\n".'-- All created Popups'."\n\n";
1715
- $allPopups = self::getPopupsIdAndTitle();
1716
- $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
1717
- foreach ($allPopups as $id => $popupTitleType) {
1718
- $popup = SGPopup::find($id, $args);
1719
- $popupStatus = ($popup->getOptionValue('sgpb-is-active')) ? 'Enabled' : 'Disabled';
1720
- $systemInfoContent .= 'Id: '.$id."\n";
1721
- $systemInfoContent .= 'Title: '.get_the_title($id)."\n";
1722
- $systemInfoContent .= 'Type: '.$popup->getOptionValue('sgpb-type')."\n";
1723
- $systemInfoContent .= 'Status: '.$popupStatus."\n";
1724
- $systemInfoContent .= "\n";
1725
- }
1726
-
1727
- // WordPress active plugins
1728
- $systemInfoContent .= "\n".'-- WordPress Active Plugins'."\n\n";
1729
-
1730
- $plugins = get_plugins();
1731
- $activePlugins = get_option('active_plugins', array());
1732
- foreach ($plugins as $pluginPath => $plugin) {
1733
-
1734
- if (! in_array($pluginPath, $activePlugins)) {
1735
- continue;
1736
- }
1737
-
1738
- $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1739
- }
1740
- // WordPress inactive plugins
1741
- $systemInfoContent .= "\n".'-- WordPress Inactive Plugins'."\n\n";
1742
-
1743
- foreach ($plugins as $pluginPath => $plugin) {
1744
- if (in_array($pluginPath, $activePlugins)) {
1745
- continue;
1746
- }
1747
- $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1748
- }
1749
-
1750
- if (is_multisite()) {
1751
- // WordPress Multisite active plugins
1752
- $systemInfoContent .= "\n".'-- Network Active Plugins'."\n\n";
1753
-
1754
- $plugins = wp_get_active_network_plugins();
1755
- $activePlugins = get_site_option('active_sitewide_plugins', array());
1756
-
1757
- foreach ($plugins as $pluginPath) {
1758
- $plugin_base = plugin_basename($pluginPath);
1759
-
1760
- if (! array_key_exists($plugin_base, $activePlugins)) {
1761
- continue;
1762
- }
1763
-
1764
- $plugin = get_plugin_data($pluginPath);
1765
- $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1766
- }
1767
- }
1768
-
1769
- // Server configuration (really just versioning)
1770
- $systemInfoContent .= "\n".'-- Webserver Configuration'."\n\n";
1771
- $systemInfoContent .= 'PHP Version: '.PHP_VERSION."\n";
1772
- $systemInfoContent .= 'MySQL Version: '.$wpdb->db_version()."\n";
1773
- $systemInfoContent .= 'Webserver Info: '.$_SERVER['SERVER_SOFTWARE']."\n";
1774
-
1775
- // PHP configs... now we're getting to the important stuff
1776
- $systemInfoContent .= "\n".'-- PHP Configuration'."\n\n";
1777
- $systemInfoContent .= 'Memory Limit: '.ini_get('memory_limit')."\n";
1778
- $systemInfoContent .= 'Upload Max Size: '.ini_get('upload_max_filesize')."\n";
1779
- $systemInfoContent .= 'Post Max Size: '.ini_get('post_max_size')."\n";
1780
- $systemInfoContent .= 'Upload Max Filesize: '.ini_get('upload_max_filesize')."\n";
1781
- $systemInfoContent .= 'Time Limit: '.ini_get('max_execution_time')."\n";
1782
- $systemInfoContent .= 'Max Input Vars: '.ini_get('max_input_vars')."\n";
1783
- $systemInfoContent .= 'Display Errors: '.(ini_get('display_errors') ? 'On ('.ini_get('display_errors').')' : 'N/A')."\n";
1784
-
1785
- // PHP extensions and such
1786
- $systemInfoContent .= "\n".'-- PHP Extensions'."\n\n";
1787
- $systemInfoContent .= 'cURL: '.(function_exists('curl_init') ? 'Supported' : 'Not Supported')."\n";
1788
- $systemInfoContent .= 'fsockopen: '.(function_exists('fsockopen') ? 'Supported' : 'Not Supported')."\n";
1789
- $systemInfoContent .= 'SOAP Client: '.(class_exists('SoapClient') ? 'Installed' : 'Not Installed')."\n";
1790
- $systemInfoContent .= 'Suhosin: '.(extension_loaded('suhosin') ? 'Installed' : 'Not Installed')."\n";
1791
-
1792
- // Session stuff
1793
- $systemInfoContent .= "\n".'-- Session Configuration'."\n\n";
1794
- $systemInfoContent .= 'Session: '.(isset($_SESSION ) ? 'Enabled' : 'Disabled')."\n";
1795
-
1796
- // The rest of this is only relevant is session is enabled
1797
- if (isset($_SESSION)) {
1798
- $systemInfoContent .= 'Session Name: '.esc_html( ini_get('session.name'))."\n";
1799
- $systemInfoContent .= 'Cookie Path: '.esc_html( ini_get('session.cookie_path'))."\n";
1800
- $systemInfoContent .= 'Save Path: '.esc_html( ini_get('session.save_path'))."\n";
1801
- $systemInfoContent .= 'Use Cookies: '.(ini_get('session.use_cookies') ? 'On' : 'Off')."\n";
1802
- $systemInfoContent .= 'Use Only Cookies: '.(ini_get('session.use_only_cookies') ? 'On' : 'Off')."\n";
1803
- }
1804
-
1805
- $systemInfoContent = apply_filters('sgpbSystemInformation', $systemInfoContent);
1806
-
1807
- $systemInfoContent .= "\n".'### End System Info ###';
1808
-
1809
- return $systemInfoContent;
1810
- }
1811
-
1812
- public static function getHost()
1813
- {
1814
- if (defined('WPE_APIKEY')) {
1815
- return 'WP Engine';
1816
- }
1817
- else if (defined('PAGELYBIN')) {
1818
- return 'Pagely';
1819
- }
1820
- else if (DB_HOST == 'localhost:/tmp/mysql5.sock') {
1821
- return 'ICDSoft';
1822
- }
1823
- else if (DB_HOST == 'mysqlv5') {
1824
- return 'NetworkSolutions';
1825
- }
1826
- else if (strpos(DB_HOST, 'ipagemysql.com') !== false) {
1827
- return 'iPage';
1828
- }
1829
- else if (strpos(DB_HOST, 'ipowermysql.com') !== false) {
1830
- return 'IPower';
1831
- }
1832
- else if (strpos(DB_HOST, '.gridserver.com') !== false) {
1833
- return 'MediaTemple Grid';
1834
- }
1835
- else if (strpos(DB_HOST, '.pair.com') !== false) {
1836
- return 'pair Networks';
1837
- }
1838
- else if (strpos(DB_HOST, '.stabletransit.com') !== false) {
1839
- return 'Rackspace Cloud';
1840
- }
1841
- else if (strpos(DB_HOST, '.sysfix.eu') !== false) {
1842
- return 'SysFix.eu Power Hosting';
1843
- }
1844
- else if (strpos($_SERVER['SERVER_NAME'], 'Flywheel') !== false) {
1845
- return 'Flywheel';
1846
- }
1847
- else {
1848
- // Adding a general fallback for data gathering
1849
- return 'DBH: '.DB_HOST.', SRV: '.$_SERVER['SERVER_NAME'];
1850
- }
1851
- }
1852
-
1853
- public static function getBrowser()
1854
- {
1855
- $uAgent = 'Unknown';
1856
- if (isset($_SERVER['HTTP_USER_AGENT'])) {
1857
- $uAgent = $_SERVER['HTTP_USER_AGENT'];
1858
- }
1859
- $bname = $platform = $ub = $version = 'Unknown';
1860
- $browserInfoContent = '';
1861
-
1862
- //First get the platform?
1863
- if (preg_match('/linux/i', $uAgent)) {
1864
- $platform = 'Linux';
1865
- }
1866
- else if (preg_match('/macintosh|mac os x/i', $uAgent)) {
1867
- $platform = 'Apple';
1868
- }
1869
- else if (preg_match('/windows|win32/i', $uAgent)) {
1870
- $platform = 'Windows';
1871
- }
1872
-
1873
- if (preg_match('/MSIE/i',$uAgent) && !preg_match('/Opera/i',$uAgent)) {
1874
- $bname = 'Internet Explorer';
1875
- $ub = 'MSIE';
1876
- }
1877
- else if (preg_match('/Firefox/i',$uAgent)) {
1878
- $bname = 'Mozilla Firefox';
1879
- $ub = 'Firefox';
1880
- }
1881
- else if (preg_match('/OPR/i',$uAgent)) {
1882
- $bname = 'Opera';
1883
- $ub = 'Opera';
1884
- }
1885
- else if (preg_match('/Chrome/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1886
- $bname = 'Google Chrome';
1887
- $ub = 'Chrome';
1888
- }
1889
- else if (preg_match('/Safari/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1890
- $bname = 'Apple Safari';
1891
- $ub = 'Safari';
1892
- }
1893
- else if (preg_match('/Netscape/i',$uAgent)) {
1894
- $bname = 'Netscape';
1895
- $ub = 'Netscape';
1896
- }
1897
- else if (preg_match('/Edge/i',$uAgent)) {
1898
- $bname = 'Edge';
1899
- $ub = 'Edge';
1900
- }
1901
- else if (preg_match('/Trident/i',$uAgent)) {
1902
- $bname = 'Internet Explorer';
1903
- $ub = 'MSIE';
1904
- }
1905
-
1906
- // finally get the correct version number
1907
- $known = array('Version', $ub, 'other');
1908
- $pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
1909
- $matches = array();
1910
- preg_match_all($pattern, $uAgent, $matches);
1911
-
1912
- // see how many we have
1913
- $i = count($matches['browser']);
1914
- //we will have two since we are not using 'other' argument yet
1915
- if ($i != 1) {
1916
- //see if version is before or after the name
1917
- if (strripos($uAgent,"Version") < strripos($uAgent,$ub)) {
1918
- $version= $matches['version'][0];
1919
- }
1920
- else {
1921
- $version= $matches['version'][1];
1922
- }
1923
- }
1924
- else {
1925
- $version= $matches['version'][0];
1926
- }
1927
-
1928
- // check if we have a number
1929
- if ($version == null || $version == "") {$version = "?" ;}
1930
-
1931
- $browserInfoContent .= 'Platform: '.$platform."\n";
1932
- $browserInfoContent .= 'Browser Name: '.$bname."\n";
1933
- $browserInfoContent .= 'Browser Version: '.$version."\n";
1934
- $browserInfoContent .= 'User Agent: '.$uAgent."\n";
1935
-
1936
- return $browserInfoContent;
1937
- }
1938
-
1939
- // checking user roles capability to do actions
1940
- public static function userCanAccessTo()
1941
- {
1942
- // if this is not admin side screen we don't need to check roles and capabilities
1943
- if (!is_admin()) {
1944
- return true;
1945
- }
1946
-
1947
- $allow = false;
1948
-
1949
- $savedUserRolesInPopup = self::getPopupPostAllowedUserRoles();
1950
- $currentUserRole = self::getCurrentUserRole();
1951
-
1952
- // we need to check if there are any intersections between saved user roles and current user
1953
- $hasIntersection = array_intersect($currentUserRole, $savedUserRolesInPopup);
1954
- if (!empty($hasIntersection)) {
1955
- $allow = true;
1956
- }
1957
-
1958
- return $allow;
1959
- }
1960
-
1961
- public static function filterUserCapabilitiesForTheUserRoles($hook = 'save')
1962
- {
1963
- global $wp_roles;
1964
-
1965
- $allAvailableWpRoles = $wp_roles->roles;
1966
- $savedUserRoles = get_option('sgpb-user-roles');
1967
- // we need to remove from all roles, either when deactivating the plugin and when there is no saved roles
1968
- if (empty($savedUserRoles) || $hook == 'deactivate') {
1969
- $savedUserRoles = array();
1970
- }
1971
- $rolesToBeRestricted = array();
1972
- // selected user roles, which have access to the PB
1973
- foreach ($allAvailableWpRoles as $allAvailableWpRole) {
1974
- if (isset($allAvailableWpRole['name']) && in_array(lcfirst($allAvailableWpRole['name']), $savedUserRoles)) {
1975
- $indexToUnset = lcfirst($allAvailableWpRole['name']);
1976
- continue;
1977
- }
1978
- $rolesToBeRestricted[] = lcfirst($allAvailableWpRole['name']);
1979
- }
1980
-
1981
- $caps = array(
1982
- 'read_private_sgpb_popups',
1983
- 'edit_sgpb_popup',
1984
- 'edit_sgpb_popups',
1985
- 'edit_others_sgpb_popups',
1986
- 'edit_published_sgpb_popups',
1987
- 'publish_sgpb_popups',
1988
- 'delete_sgpb_popups',
1989
- 'delete_published_posts',
1990
- 'delete_others_sgpb_popups',
1991
- 'delete_private_sgpb_popups',
1992
- 'delete_private_sgpb_popup',
1993
- 'delete_published_sgpb_popups',
1994
- 'sgpb_manage_options',
1995
- 'manage_popup_terms',
1996
- 'manage_popup_categories_terms'
1997
- );
1998
-
1999
- if ($hook == 'activate') {
2000
- $rolesToBeRestricted = $savedUserRoles;
2001
- }
2002
- foreach ($rolesToBeRestricted as $roleToBeRestricted) {
2003
- if ($roleToBeRestricted == 'administrator' || $roleToBeRestricted == 'admin') {
2004
- continue;
2005
- }
2006
- foreach ($caps as $cap) {
2007
- // only for the activation hook we need to add our capabilities back
2008
- if ($hook == 'activate') {
2009
- $wp_roles->add_cap($roleToBeRestricted, $cap);
2010
- }
2011
- else {
2012
- $wp_roles->remove_cap($roleToBeRestricted, $cap);
2013
- }
2014
- }
2015
- }
2016
- }
2017
-
2018
- public static function removeUnnecessaryCodeFromPopups()
2019
- {
2020
- $alreadyClearded = self::getOption('sgpb-unnecessary-scripts-removed-1');
2021
- if ($alreadyClearded) {
2022
- return true;
2023
- }
2024
-
2025
- global $wpdb;
2026
- $getAllDataSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.'posts WHERE post_type = %s', SG_POPUP_POST_TYPE);
2027
- $popupsId = $wpdb->get_results($getAllDataSql, ARRAY_A);
2028
- if (empty($popupsId)) {
2029
- return true;
2030
- }
2031
- foreach ($popupsId as $popupId) {
2032
- if (empty($popupId['id'])) {
2033
- continue;
2034
- }
2035
- $id = $popupId['id'];
2036
- $customScripts = get_post_meta($id, 'sg_popup_scripts', true);
2037
- if (empty($customScripts)) {
2038
- continue;
2039
- }
2040
- if (isset($customScripts['js'])) {
2041
- unset($customScripts['js']);
2042
- update_post_meta($id, 'sg_popup_scripts', $customScripts);
2043
- }
2044
- }
2045
-
2046
- self::updateOption('sgpb-unnecessary-scripts-removed-1', 1);
2047
- }
2048
-
2049
- public static function sendTestNewsletter($newsletterData = array())
2050
- {
2051
- $mailSubject = $newsletterData['newsletterSubject'];
2052
- $fromEmail = $newsletterData['fromEmail'];
2053
- $emailMessage = $newsletterData['messageBody'];
2054
- $blogInfo = get_bloginfo();
2055
- $headers = array(
2056
- 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
2057
- 'MIME-Version: 1.0' ,
2058
- 'Content-type: text/html; charset=UTF-8'
2059
- );
2060
-
2061
- $emails = get_option('admin_email');
2062
- if (!empty($newsletterData['testSendingEmails'])) {
2063
- $emails = $newsletterData['testSendingEmails'];
2064
- $emails = str_replace(' ', '', $emails);
2065
-
2066
- $receiverEmailsArray = array();
2067
- $emails = explode(',', $emails);
2068
- foreach ($emails as $mail) {
2069
- if (is_email($mail)) {
2070
- $receiverEmailsArray[] = $mail;
2071
- }
2072
- }
2073
- $emails = $receiverEmailsArray;
2074
- }
2075
-
2076
- $mailStatus = wp_mail($emails, $mailSubject, $emailMessage, $headers);
2077
-
2078
- wp_die($newsletterData['testSendingStatus']);
2079
- }
2080
-
2081
- // wp uploaded images
2082
- public static function getImageAltTextByUrl($imageUrl = '')
2083
- {
2084
- $imageId = attachment_url_to_postid($imageUrl);
2085
- $altText = get_post_meta($imageId, '_wp_attachment_image_alt', true);
2086
-
2087
- return $altText;
2088
- }
2089
-
2090
- public static function hasBlocks($content)
2091
- {
2092
- if (function_exists('has_blocks')) {
2093
- return has_blocks($content);
2094
- }
2095
-
2096
- return false !== strpos( (string) $content, '<!-- wp:' );
2097
- }
2098
- /**
2099
- * Retrieve duplicate post link for post.
2100
- *
2101
- * @param int $id Optional. Post ID.
2102
- * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
2103
- * @return string
2104
- */
2105
- public static function popupGetClonePostLink($id = 0, $context = 'display')
2106
- {
2107
- if (!$post = get_post($id)) {
2108
- return;
2109
- }
2110
- $actionName = "popupSaveAsNew";
2111
-
2112
- if ('display' == $context) {
2113
- $action = '?action='.$actionName.'&amp;post='.$post->ID;
2114
- } else {
2115
- $action = '?action='.$actionName.'&post='.$post->ID;
2116
- }
2117
-
2118
- $postTypeObject = get_post_type_object($post->post_type);
2119
-
2120
- if (!$postTypeObject) {
2121
- return;
2122
- }
2123
-
2124
- return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
2125
- }
2126
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \DateTime;
4
+ use \DateTimeZone;
5
+ use \SgpbDataConfig;
6
+ use \Elementor;
7
+ use sgpbsubscriptionplus\SubscriptionPlusAdminHelper;
8
+
9
+ class AdminHelper
10
+ {
11
+ /**
12
+ * Get extension options data which are included inside the free version
13
+ *
14
+ * @since 3.0.8
15
+ *
16
+ * @return assoc array $extensionOptions
17
+ */
18
+ public static function getExtensionAvaliabilityOptions()
19
+ {
20
+ $extensionOptions = array();
21
+ // advanced closing option
22
+ $extensionOptions[SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY] = array(
23
+ 'sgpb-close-after-page-scroll',
24
+ 'sgpb-auto-close',
25
+ 'sgpb-enable-popup-overlay',
26
+ 'sgpb-disable-popup-closing'
27
+ );
28
+ // schedule extension
29
+ $extensionOptions[SGPB_POPUP_SCHEDULING_EXTENSION_KEY] = array(
30
+ 'otherConditionsMetaBoxView'
31
+ );
32
+ // geo targeting extension
33
+ $extensionOptions[SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY] = array(
34
+ 'popupConditionsSection'
35
+ );
36
+ // advanced targeting extension
37
+ $extensionOptions[SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY] = array(
38
+ 'popupConditionsSection'
39
+ );
40
+
41
+ return $extensionOptions;
42
+ }
43
+
44
+ public static function getPopupTypesPageURL()
45
+ {
46
+ return admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_POST_TYPE);
47
+ }
48
+
49
+ public static function getSettingsURL($args = array())
50
+ {
51
+ $url = admin_url('/edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
52
+
53
+ return self::addArgsToURl($url, $args);
54
+ }
55
+
56
+ public static function getPopupExportURL()
57
+ {
58
+ $exportURL = admin_url('export.php');
59
+ $url = add_query_arg(array(
60
+ 'download' => true,
61
+ 'content' => SG_POPUP_POST_TYPE,
62
+ 'sgpbExportAction' => 1
63
+ ), $exportURL);
64
+
65
+ return $url;
66
+ }
67
+
68
+ public static function addArgsToURl($url, $args = array())
69
+ {
70
+ $resultURl = add_query_arg($args, $url);
71
+
72
+ return $resultURl;
73
+ }
74
+
75
+ public static function buildCreatePopupUrl($popupType)
76
+ {
77
+ $isAvailable = $popupType->isAvailable();
78
+ $name = $popupType->getName();
79
+
80
+ $popupUrl = SG_POPUP_ADMIN_URL.'post-new.php?post_type='.SG_POPUP_POST_TYPE.'&sgpb_type='.$name;
81
+
82
+ if (!$isAvailable) {
83
+ $popupUrl = SG_POPUP_PRO_URL;
84
+ }
85
+
86
+ return $popupUrl;
87
+ }
88
+
89
+ public static function getPopupThumbClass($popupType)
90
+ {
91
+ $isAvailable = $popupType->isAvailable();
92
+ $name = $popupType->getName();
93
+
94
+ $popupTypeClassName = $name.'-popup';
95
+
96
+ if (!$isAvailable) {
97
+ $popupTypeClassName .= '-pro';
98
+ }
99
+
100
+ return $popupTypeClassName;
101
+ }
102
+
103
+ public static function createSelectBox($data, $selectedValue, $attrs)
104
+ {
105
+ $attrString = '';
106
+ $selected = '';
107
+ $selectBoxCloseTag = '</select>';
108
+
109
+ if (!empty($attrs) && isset($attrs)) {
110
+
111
+ foreach ($attrs as $attrName => $attrValue) {
112
+ $attrString .= ''.$attrName.'="'.$attrValue.'" ';
113
+ }
114
+ }
115
+
116
+ $selectBox = '<select '.$attrString.'>';
117
+ if (empty($data) || !is_array($data)) {
118
+ $selectBox .= $selectBoxCloseTag;
119
+ return $selectBox;
120
+ }
121
+
122
+ foreach ($data as $value => $label) {
123
+ // When is multiSelect
124
+ if (is_array($selectedValue)) {
125
+ $isSelected = in_array($value, $selectedValue);
126
+ if ($isSelected) {
127
+ $selected = 'selected';
128
+ }
129
+ }
130
+ else if ($selectedValue == $value) {
131
+ $selected = 'selected';
132
+ }
133
+ else if (is_array($value) && in_array($selectedValue, $value)) {
134
+ $selected = 'selected';
135
+ }
136
+
137
+ if (is_array($label)) {
138
+ $selectBox .= '<optgroup label="'.$value.'">';
139
+ foreach ($label as $key => $optionLabel) {
140
+ $selected = '';
141
+ if (is_array($selectedValue)) {
142
+ $isSelected = in_array($key, $selectedValue);
143
+ if ($isSelected) {
144
+ $selected = 'selected';
145
+ }
146
+ }
147
+ else if ($selectedValue == $key) {
148
+ $selected = 'selected';
149
+ }
150
+ else if (is_array($key) && in_array($selectedValue, $key)) {
151
+ $selected = 'selected';
152
+ }
153
+
154
+ $selectBox .= '<option value="'.$key.'" '.$selected.'>'.$optionLabel.'</option>';
155
+ }
156
+ $selectBox .= '</optgroup>';
157
+ }
158
+ else {
159
+ $selectBox .= '<option value="'.$value.'" '.$selected.'>'.$label.'</option>';
160
+ }
161
+
162
+ $selected = '';
163
+ }
164
+
165
+ $selectBox .= $selectBoxCloseTag;
166
+
167
+ return $selectBox;
168
+ }
169
+
170
+ public static function createInput($data, $selectedValue, $attrs)
171
+ {
172
+ $attrString = '';
173
+ $savedData = $data;
174
+
175
+ if (isset($selectedValue)) {
176
+ $savedData = $selectedValue;
177
+ }
178
+ if (empty($savedData)) {
179
+ $savedData = '';
180
+ }
181
+
182
+ if (!empty($attrs) && isset($attrs)) {
183
+
184
+ foreach ($attrs as $attrName => $attrValue) {
185
+ if ($attrName == 'class') {
186
+ $attrValue .= '';
187
+ }
188
+ $attrString .= ''.$attrName.'="'.$attrValue.'" ';
189
+ }
190
+ }
191
+
192
+ $input = "<input $attrString value=\"".esc_attr($savedData)."\">";
193
+
194
+ return $input;
195
+ }
196
+
197
+ public static function createCheckBox($data, $selectedValue, $attrs)
198
+ {
199
+ $attrString = '';
200
+ $checked = '';
201
+
202
+ if (!empty($selectedValue)) {
203
+ $checked = 'checked';
204
+ }
205
+ if (!empty($attrs) && isset($attrs)) {
206
+
207
+ foreach ($attrs as $attrName => $attrValue) {
208
+ $attrString .= ''.$attrName.'="'.$attrValue.'" ';
209
+ }
210
+ }
211
+
212
+ $input = "<input $attrString $checked>";
213
+
214
+ return $input;
215
+ }
216
+
217
+ public static function createRadioButtons($elements, $name, $selectedInput, $lineMode = false, $extraHtmlAfterInput = '')
218
+ {
219
+ $str = '';
220
+
221
+ foreach ($elements as $key => $element) {
222
+ $value = '';
223
+ $checked = '';
224
+ $stringWithlabel = '';
225
+ $labelClasses = '';
226
+ $stringLabel = '';
227
+
228
+ if (isset($element['value'])) {
229
+ $value = $element['value'];
230
+ }
231
+ if (isset($element['label_class'])) {
232
+ $labelClasses = 'class="'.$element['label_class'].'"';
233
+ $stringLabel = '<span class="sgpb-margin-bottom-10">'.esc_attr($value).'</span>';
234
+ }
235
+
236
+ if (is_array($element) && $element['value'] == $selectedInput) {
237
+ $checked = 'checked';
238
+ }
239
+ else if (!is_array($element) && $element == $selectedInput) {
240
+ $checked = 'checked';
241
+ }
242
+ $attrStr = '';
243
+ if (isset($element['data-attributes'])) {
244
+ foreach ($element['data-attributes'] as $attrKey => $dataValue) {
245
+ $attrStr .= $attrKey.'="'.esc_attr($dataValue).'" ';
246
+ }
247
+ }
248
+ if (!empty($extraHtmlAfterInput)) {
249
+ if ($extraHtmlAfterInput == 'img') {
250
+ $extraHtmlAfterInput = '<img src="">';
251
+ }
252
+ else if ($extraHtmlAfterInput == 'bg_img') {
253
+ $extraHtmlAfterInput = '<span class="sgpb-popup-theme-img sgpb-margin-x-7"></span>';
254
+ }
255
+ }
256
+
257
+ if ($lineMode) {
258
+ if (!empty($extraHtmlAfterInput)) {
259
+ $str .= '<label '.$labelClasses.'><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>'.$extraHtmlAfterInput.$stringLabel.'</label>';
260
+ }
261
+ else {
262
+ $str .= '<input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>';
263
+ }
264
+ }
265
+ else {
266
+ $str .= '<div class="row form-group">';
267
+ $str .= '<label class="col-md-5 control-label">'.__($element['title'], SG_POPUP_TEXT_DOMAIN).'</label>';
268
+ $str .= '<div class="col-sm-7"><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' autocomplete="off">'.$extraHtmlAfterInput.'</div>';
269
+ $str .= '</div>';
270
+ }
271
+ }
272
+
273
+ echo $str;
274
+ }
275
+
276
+ public static function getDateObjFromDate($dueDate, $timezone = 'America/Los_Angeles', $format = 'Y-m-d H:i:s')
277
+ {
278
+ $dateObj = new DateTime($dueDate, new DateTimeZone($timezone));
279
+ $dateObj->format($format);
280
+
281
+ return $dateObj;
282
+ }
283
+
284
+ /**
285
+ * Serialize data
286
+ *
287
+ * @since 1.0.0
288
+ *
289
+ * @param array $data
290
+ *
291
+ * @return string $serializedData
292
+ */
293
+ public static function serializeData($data = array())
294
+ {
295
+ $serializedData = serialize($data);
296
+
297
+ return $serializedData;
298
+ }
299
+
300
+ /**
301
+ * Get correct size to use it safely inside CSS rules
302
+ *
303
+ * @since 1.0.0
304
+ *
305
+ * @param string $dimension
306
+ *
307
+ * @return string $size
308
+ */
309
+ public static function getCSSSafeSize($dimension)
310
+ {
311
+ if (empty($dimension)) {
312
+ return 'inherit';
313
+ }
314
+
315
+ $size = (int)$dimension.'px';
316
+ // If user write dimension in px or % we give that dimension to target otherwise the default value will be px
317
+ if (strpos($dimension, '%') || strpos($dimension, 'px')) {
318
+ $size = $dimension;
319
+ }
320
+
321
+ return $size;
322
+ }
323
+
324
+ public static function deleteSubscriptionPopupSubscribers($popupId)
325
+ {
326
+ global $wpdb;
327
+
328
+ $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE subscriptionType = %s', $popupId);
329
+ $wpdb->query($prepareSql);
330
+ }
331
+
332
+ public static function subscribersRelatedQuery($query = '', $additionalColumn = '')
333
+ {
334
+ global $wpdb;
335
+ $subscribersTablename = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
336
+ $postsTablename = $wpdb->prefix.SGPB_POSTS_TABLE_NAME;
337
+
338
+ if ($query == '') {
339
+ $query = 'SELECT firstName, lastName, email, cDate, '.$additionalColumn.' '.$postsTablename.'.post_title AS subscriptionTitle FROM '.$subscribersTablename.' ';
340
+ }
341
+
342
+ $searchQuery = ' unsubscribed <> 1';
343
+ $filterCriteria = '';
344
+
345
+ $query .= ' LEFT JOIN '.$postsTablename.' ON '.$postsTablename.'.ID='.$subscribersTablename.'.subscriptionType';
346
+
347
+ if (isset($_GET['sgpb-subscription-popup-id']) && !empty($_GET['sgpb-subscription-popup-id'])) {
348
+ $filterCriteria = esc_sql($_GET['sgpb-subscription-popup-id']);
349
+ if ($filterCriteria != 'all') {
350
+ $searchQuery .= " AND (subscriptionType = $filterCriteria)";
351
+ }
352
+ }
353
+ if ($filterCriteria != '' && $filterCriteria != 'all' && isset($_GET['s']) && !empty($_GET['s'])) {
354
+ $searchQuery .= ' AND ';
355
+ }
356
+ if (isset($_GET['s']) && !empty($_GET['s'])) {
357
+ $searchCriteria = esc_sql($_GET['s']);
358
+ $lastPartOfTheQuery = substr($searchQuery, -5);
359
+ if (strpos($lastPartOfTheQuery, 'AND') <= 0) {
360
+ $searchQuery .= ' AND ';
361
+ }
362
+ $searchQuery .= "(firstName LIKE '%$searchCriteria%' or lastName LIKE '%$searchCriteria%' or email LIKE '%$searchCriteria%' or $postsTablename.post_title LIKE '%$searchCriteria%')";
363
+ }
364
+ if (isset($_GET['sgpb-subscribers-date']) && !empty($_GET['sgpb-subscribers-date'])) {
365
+ $filterCriteria = esc_sql($_GET['sgpb-subscribers-date']);
366
+ if ($filterCriteria != 'all') {
367
+ if ($searchQuery != '') {
368
+ $searchQuery .= ' AND ';
369
+ }
370
+ $searchQuery .= " cDate LIKE '$filterCriteria%'";
371
+ }
372
+ }
373
+ if ($searchQuery != '') {
374
+ $query .= " WHERE $searchQuery";
375
+ }
376
+
377
+ return $query;
378
+ }
379
+
380
+ public static function themeRelatedSettings($popupId, $buttonPosition, $theme)
381
+ {
382
+ if ($popupId) {
383
+ if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
384
+ if (!isset($buttonPosition)) {
385
+ $buttonPosition = 'bottomRight';
386
+ }
387
+ }
388
+ else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
389
+ if (!isset($buttonPosition)) {
390
+ $buttonPosition = 'topRight';
391
+ }
392
+ }
393
+ }
394
+ else {
395
+ if (isset($theme)) {
396
+ if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
397
+ $buttonPosition = 'bottomRight';
398
+ }
399
+ else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
400
+ $buttonPosition = 'topRight';
401
+ }
402
+ }
403
+ else {
404
+ /* by default set position for the first theme */
405
+ $buttonPosition = 'bottomRight';
406
+ }
407
+ }
408
+
409
+ return $buttonPosition;
410
+ }
411
+
412
+ /**
413
+ * Create html attrs
414
+ *
415
+ * @since 1.0.0
416
+ *
417
+ * @param array $attrs
418
+ *
419
+ * @return string $attrStr
420
+ */
421
+ public static function createAttrs($attrs)
422
+ {
423
+ $attrStr = '';
424
+
425
+ if (empty($attrs)) {
426
+ return $attrStr;
427
+ }
428
+
429
+ foreach ($attrs as $attrKey => $attrValue) {
430
+ $attrStr .= $attrKey.'="'.$attrValue.'" ';
431
+ }
432
+
433
+ return $attrStr;
434
+ }
435
+
436
+ public static function getFormattedDate($date)
437
+ {
438
+ $date = strtotime($date);
439
+ $month = date('F', $date);
440
+ $year = date('Y', $date);
441
+
442
+ return $month.' '.$year;
443
+ }
444
+
445
+ public static function defaultButtonImage($theme, $closeImage = '')
446
+ {
447
+ $currentPostType = self::getCurrentPopupType();
448
+ if (defined('SGPB_POPUP_TYPE_RECENT_SALES') && $currentPostType == SGPB_POPUP_TYPE_RECENT_SALES) {
449
+ $theme = 'sgpb-theme-6';
450
+ }
451
+ // if no image, set default by theme
452
+ if ($closeImage == '') {
453
+ if ($theme == 'sgpb-theme-1' || !$theme) {
454
+ $closeImage = SG_POPUP_IMG_URL.'theme_1/close.png';
455
+ }
456
+ else if ($theme == 'sgpb-theme-2') {
457
+ $closeImage = SG_POPUP_IMG_URL.'theme_2/close.png';
458
+ }
459
+ else if ($theme == 'sgpb-theme-3') {
460
+ $closeImage = SG_POPUP_IMG_URL.'theme_3/close.png';
461
+ }
462
+ else if ($theme == 'sgpb-theme-5') {
463
+ $closeImage = SG_POPUP_IMG_URL.'theme_5/close.png';
464
+ }
465
+ else if ($theme == 'sgpb-theme-6') {
466
+ $closeImage = SG_POPUP_IMG_URL.'theme_6/close.png';
467
+ }
468
+ }
469
+ else {
470
+ $closeImage = self::getImageDataFromUrl($closeImage);
471
+ }
472
+
473
+ return $closeImage;
474
+ }
475
+
476
+ public static function getPopupPostAllowedUserRoles()
477
+ {
478
+ $userSavedRoles = get_option('sgpb-user-roles');
479
+
480
+ if (empty($userSavedRoles) || !is_array($userSavedRoles)) {
481
+ $userSavedRoles = array('administrator');
482
+ }
483
+ else {
484
+ array_push($userSavedRoles, 'administrator');
485
+ }
486
+
487
+ return $userSavedRoles;
488
+ }
489
+
490
+ public static function showMenuForCurrentUser()
491
+ {
492
+ return self::userCanAccessTo();
493
+ }
494
+
495
+ public static function getPopupsIdAndTitle($excludesPopups = array())
496
+ {
497
+ $allPopups = SGPopup::getAllPopups();
498
+ $popupIdTitles = array();
499
+
500
+ if (empty($allPopups)) {
501
+ return $popupIdTitles;
502
+ }
503
+
504
+ foreach ($allPopups as $popup) {
505
+ if (empty($popup)) {
506
+ continue;
507
+ }
508
+
509
+ $id = $popup->getId();
510
+ $title = $popup->getTitle();
511
+ $type = $popup->getType();
512
+
513
+ if (!empty($excludesPopups)) {
514
+ foreach ($excludesPopups as $excludesPopupId) {
515
+ if ($excludesPopupId != $id) {
516
+ $popupIdTitles[$id] = $title.' - '.$type;
517
+ }
518
+ }
519
+ }
520
+ else {
521
+ $popupIdTitles[$id] = $title.' - '.$type;
522
+ }
523
+ }
524
+
525
+ return $popupIdTitles;
526
+ }
527
+
528
+ /**
529
+ * Merge two array and merge same key values to same array
530
+ *
531
+ * @since 1.0.0
532
+ *
533
+ * @param array $array1
534
+ * @param array $array2
535
+ *
536
+ * @return array|bool
537
+ *
538
+ */
539
+ public static function arrayMergeSameKeys($array1, $array2)
540
+ {
541
+ if (empty($array1)) {
542
+ return array();
543
+ }
544
+
545
+ $modified = false;
546
+ $array3 = array();
547
+ foreach ($array1 as $key => $value) {
548
+ if (isset($array2[$key]) && is_array($array2[$key])) {
549
+ $arrDifference = array_diff($array2[$key], $array1[$key]);
550
+ if (empty($arrDifference)) {
551
+ continue;
552
+ }
553
+
554
+ $modified = true;
555
+ $array3[$key] = array_merge($array2[$key], $array1[$key]);
556
+ unset($array2[$key]);
557
+ continue;
558
+ }
559
+
560
+ $modified = true;
561
+ $array3[$key] = $value;
562
+ }
563
+
564
+ // when there are no values
565
+ if (!$modified) {
566
+ return $modified;
567
+ }
568
+
569
+ return $array2 + $array3;
570
+ }
571
+
572
+ public static function getCurrentUserRole()
573
+ {
574
+ $role = array('administrator');
575
+
576
+ if (is_multisite()) {
577
+
578
+ $getUsersObj = get_users(
579
+ array(
580
+ 'blog_id' => get_current_blog_id(),
581
+ 'search' => get_current_user_id()
582
+ )
583
+ );
584
+
585
+ if (!empty($getUsersObj[0])) {
586
+ $roles = $getUsersObj[0]->roles;
587
+
588
+ if (is_array($roles) && !empty($roles)) {
589
+ $role = array_merge($role, $getUsersObj[0]->roles);
590
+ }
591
+ }
592
+
593
+ return $role;
594
+ }
595
+
596
+ global $current_user;
597
+ if (!empty($current_user)) {
598
+ $role = $current_user->roles;
599
+ }
600
+
601
+ return $role;
602
+ }
603
+
604
+ public static function hexToRgba($color, $opacity = false)
605
+ {
606
+ $default = 'rgb(0,0,0)';
607
+
608
+ //Return default if no color provided
609
+ if (empty($color)) {
610
+ return $default;
611
+ }
612
+
613
+ //Sanitize $color if "#" is provided
614
+ if ($color[0] == '#') {
615
+ $color = substr($color, 1);
616
+ }
617
+
618
+ //Check if color has 6 or 3 characters and get values
619
+ if (strlen($color) == 6) {
620
+ $hex = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);
621
+ }
622
+ else if (strlen($color) == 3) {
623
+ $hex = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
624
+ }
625
+ else {
626
+ return $default;
627
+ }
628
+
629
+ //Convert hexadec to rgb
630
+ $rgb = array_map('hexdec', $hex);
631
+
632
+ //Check if opacity is set(rgba or rgb)
633
+ if ($opacity !== false) {
634
+ if (abs($opacity) > 1) {
635
+ $opacity = 1.0;
636
+ }
637
+ $output = 'rgba('.implode(',', $rgb).','.$opacity.')';
638
+ }
639
+ else {
640
+ $output = 'rgb('.implode(',', $rgb).')';
641
+ }
642
+
643
+ //Return rgb(a) color string
644
+ return $output;
645
+ }
646
+
647
+ public static function getAllActiveExtensions()
648
+ {
649
+ $extensions = SgpbDataConfig::getOldExtensionsInfo();
650
+ $labels = array();
651
+
652
+ foreach ($extensions as $extension) {
653
+ if (file_exists(WP_PLUGIN_DIR.'/'.$extension['folderName'])) {
654
+ $labels[] = $extension['label'];
655
+ }
656
+ }
657
+
658
+ return $labels;
659
+ }
660
+
661
+ public static function renderExtensionsContent()
662
+ {
663
+ $extensions = self::getAllActiveExtensions();
664
+ ob_start();
665
+ ?>
666
+ <p class="sgpb-extension-notice-close">x</p>
667
+ <div class="sgpb-extensions-list-wrapper">
668
+ <div class="sgpb-notice-header">
669
+ <h3><?php _e('Popup Builder plugin has been successfully updated', SG_POPUP_TEXT_DOMAIN); ?></h3>
670
+ <h4><?php _e('The following extensions need to be updated manually', SG_POPUP_TEXT_DOMAIN); ?></h4>
671
+ </div>
672
+ <ul class="sgpb-extensions-list">
673
+ <?php foreach ($extensions as $extensionName): ?>
674
+ <a target="_blank" href="https://popup-builder.com/forms/control-panel/"><li><?php echo $extensionName; ?></li></a>
675
+ <?php endforeach; ?>
676
+ </ul>
677
+ </div>
678
+ <p class="sgpb-extension-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN)?></p>
679
+ <?php
680
+ $content = ob_get_contents();
681
+ ob_get_clean();
682
+
683
+ return $content;
684
+ }
685
+
686
+ public static function getReverseConvertIds()
687
+ {
688
+ $idsMappingSaved = get_option('sgpbConvertedIds');
689
+ $ids = array();
690
+
691
+ if ($idsMappingSaved) {
692
+ $ids = $idsMappingSaved;
693
+ }
694
+
695
+ return array_flip($ids);
696
+ }
697
+
698
+ public static function getAllFreeExtensions()
699
+ {
700
+ $allExtensions = SgpbDataConfig::allFreeExtensionsKeys();
701
+
702
+ $notActiveExtensions = array();
703
+ $activeExtensions = array();
704
+
705
+ foreach ($allExtensions as $extension) {
706
+ if (!is_plugin_active($extension['pluginKey'])) {
707
+ $notActiveExtensions[] = $extension;
708
+ }
709
+ else {
710
+ $activeExtensions[] = $extension;
711
+ }
712
+ }
713
+
714
+ $divideExtension = array(
715
+ 'noActive' => $notActiveExtensions,
716
+ 'active' => $activeExtensions
717
+ );
718
+
719
+ return $divideExtension;
720
+ }
721
+
722
+ public static function getAllExtensions()
723
+ {
724
+ $allExtensions = SgpbDataConfig::allExtensionsKeys();
725
+
726
+ $notActiveExtensions = array();
727
+ $activeExtensions = array();
728
+
729
+ foreach ($allExtensions as $extension) {
730
+ if (!is_plugin_active($extension['pluginKey'])) {
731
+ $notActiveExtensions[] = $extension;
732
+ }
733
+ else {
734
+ $activeExtensions[] = $extension;
735
+ }
736
+ }
737
+
738
+ $divideExtension = array(
739
+ 'noActive' => $notActiveExtensions,
740
+ 'active' => $activeExtensions
741
+ );
742
+
743
+ return $divideExtension;
744
+ }
745
+
746
+ public static function renderAlertProblem()
747
+ {
748
+ ob_start();
749
+ ?>
750
+ <div id="welcome-panel" class="update-nag sgpb-alert-problem">
751
+ <div class="welcome-panel-content">
752
+ <p class="sgpb-problem-notice-close">x</p>
753
+ <div class="sgpb-alert-problem-text-wrapper">
754
+ <h3><?php _e('Popup Builder plugin has been updated to the new version 3.', SG_POPUP_TEXT_DOMAIN); ?></h3>
755
+ <h5><?php _e('A lot of changes and improvements have been made.', SG_POPUP_TEXT_DOMAIN); ?></h5>
756
+ <h5><?php _e('In case of any issues, please contact us <a href="<?php echo SG_POPUP_TICKET_URL; ?>" target="_blank">here</a>.', SG_POPUP_TEXT_DOMAIN); ?></h5>
757
+ </div>
758
+ <p class="sgpb-problem-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN); ?></p>
759
+ </div>
760
+ </div>
761
+ <?php
762
+ $content = ob_get_clean();
763
+
764
+ return $content;
765
+ }
766
+
767
+ public static function getTaxonomyBySlug($slug = '')
768
+ {
769
+ $allTerms = get_terms(array('hide_empty' => false));
770
+
771
+ $result = array();
772
+ if (empty($allTerms)) {
773
+ return $result;
774
+ }
775
+ if ($slug == '') {
776
+ return $allTerms;
777
+ }
778
+ foreach ($allTerms as $term) {
779
+ if ($term->slug == $slug) {
780
+ return $term;
781
+ }
782
+ }
783
+ }
784
+
785
+ public static function getCurrentPopupType()
786
+ {
787
+ $type = '';
788
+ if (!empty($_GET['sgpb_type'])) {
789
+ $type = $_GET['sgpb_type'];
790
+ }
791
+
792
+ $currentPostType = self::getCurrentPostType();
793
+
794
+ if ($currentPostType == SG_POPUP_POST_TYPE && !empty($_GET['post'])) {
795
+ $popupObj = SGPopup::find($_GET['post']);
796
+ if (is_object($popupObj)) {
797
+ $type = $popupObj->getType();
798
+ }
799
+ }
800
+
801
+ return $type;
802
+ }
803
+
804
+ public static function getCurrentPostType()
805
+ {
806
+ global $post_type;
807
+ global $post;
808
+ $currentPostType = '';
809
+
810
+ if (is_object($post)) {
811
+ $currentPostType = $post->post_type;
812
+ }
813
+
814
+ // in some themes global $post returns null
815
+ if (empty($currentPostType)) {
816
+ $currentPostType = $post_type;
817
+ }
818
+
819
+ if (empty($currentPostType) && !empty($_GET['post'])) {
820
+ $currentPostType = get_post_type($_GET['post']);
821
+ }
822
+
823
+ return $currentPostType;
824
+ }
825
+
826
+ /**
827
+ * Get image encoded data from URL
828
+ *
829
+ * @param $imageUrl
830
+ * @param $shouldNotConvertBase64
831
+ *
832
+ * @return string
833
+ */
834
+
835
+ public static function getImageDataFromUrl($imageUrl, $shouldNotConvertBase64 = false)
836
+ {
837
+ $remoteData = wp_remote_get($imageUrl);
838
+ if (is_wp_error($remoteData) && $shouldNotConvertBase64) {
839
+ return SG_POPUP_IMG_URL.'NoImage.png';
840
+ }
841
+
842
+ if (!$shouldNotConvertBase64) {
843
+ $imageData = wp_remote_retrieve_body($remoteData);
844
+ $imageUrl = base64_encode($imageData);
845
+ }
846
+
847
+ return $imageUrl;
848
+ }
849
+
850
+ public static function deleteUserFromSubscribers($params = array())
851
+ {
852
+ global $wpdb;
853
+
854
+ $email = '';
855
+ $popup = '';
856
+ $noSubscriber = true;
857
+
858
+ if (isset($params['email'])) {
859
+ $email = $params['email'];
860
+ }
861
+ if (isset($params['popup'])) {
862
+ $popup = $params['popup'];
863
+ }
864
+
865
+ $prepareSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s && subscriptionType = %s', $email, $popup);
866
+ $res = $wpdb->get_row($prepareSql, ARRAY_A);
867
+ if (!isset($res['id'])) {
868
+ $noSubscriber = false;
869
+ }
870
+ $params['subscriberId'] = $res['id'];
871
+
872
+ $subscriber = self::subscriberExists($params);
873
+ if ($subscriber && $noSubscriber) {
874
+ self::deleteSubscriber($params);
875
+ }
876
+ else if (!$noSubscriber) {
877
+ _e('<span>Oops, something went wrong, please try again or contact the administrator to check more info.</span>', SG_POPUP_TEXT_DOMAIN);
878
+ wp_die();
879
+ }
880
+ }
881
+
882
+ public static function subscriberExists($params = array())
883
+ {
884
+ if (empty($params)) {
885
+ return false;
886
+ }
887
+
888
+ $receivedToken = $params['token'];
889
+ $realToken = md5($params['subscriberId'].$params['email']);
890
+ if ($receivedToken == $realToken) {
891
+ return true;
892
+ }
893
+
894
+ }
895
+
896
+ public static function deleteSubscriber($params = array())
897
+ {
898
+ global $wpdb;
899
+ $homeUrl = get_home_url();
900
+
901
+ if (empty($params)) {
902
+ return false;
903
+ }
904
+ // send email to admin about user unsubscription
905
+ self::sendEmailAboutUnsubscribe($params);
906
+
907
+ $prepareSql = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET unsubscribed = 1 WHERE id = %s ', $params['subscriberId']);
908
+ $wpdb->query($prepareSql);
909
+
910
+ _e('<span>You have successfully unsubscribed. <a href="'.esc_attr($homeUrl).'">click here</a> to go to the home page.</span>', SG_POPUP_TEXT_DOMAIN);
911
+ wp_die();
912
+ }
913
+
914
+ public static function sendEmailAboutUnsubscribe($params = array())
915
+ {
916
+ if (empty($params)) {
917
+ return false;
918
+ }
919
+
920
+ $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
921
+ $receiverEmail = get_bloginfo('admin_email');
922
+ $userEmail = $params['email'];
923
+ $emailTitle = __('Unsubscription', SG_POPUP_TEXT_DOMAIN);
924
+ $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
925
+ $subscriptionFormTitle = get_the_title($subscriptionFormId);
926
+
927
+ $message = __('User with '.$userEmail.' email has unsubscribed from '.$subscriptionFormTitle.' mail list', SG_POPUP_TEXT_DOMAIN);
928
+
929
+ $headers = 'MIME-Version: 1.0'."\r\n";
930
+ $headers .= 'From: WordPress Popup Builder'."\r\n";
931
+ $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
932
+
933
+ wp_mail($receiverEmail, $emailTitle, $message, $headers);
934
+ }
935
+
936
+ public static function addUnsubscribeColumn()
937
+ {
938
+ global $wpdb;
939
+
940
+ $sql = 'ALTER TABLE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' ADD COLUMN unsubscribed INT NOT NULL DEFAULT 0 ';
941
+ $wpdb->query($sql);
942
+ }
943
+
944
+ public static function isPluginActive($key)
945
+ {
946
+ $allExtensions = SgpbDataConfig::allExtensionsKeys();
947
+ $isActive = false;
948
+ foreach ($allExtensions as $extension) {
949
+ if (isset($extension['key']) && $extension['key'] == $key) {
950
+ if (is_plugin_active($extension['pluginKey'])) {
951
+ $isActive = true;
952
+ return $isActive;
953
+ }
954
+ }
955
+ }
956
+
957
+ return $isActive;
958
+ }
959
+
960
+ public static function supportBannerNotification()
961
+ {
962
+ $content = '<div class="sgpb-support-notification-wrapper sgpb-wrapper"><h4 class="sgpb-support-notification-title">'.__('Need some help?', SG_POPUP_TEXT_DOMAIN).'</h4>';
963
+ $content .= '<h4 class="sgpb-support-notification-title">'.__('Let us know what you think.', SG_POPUP_TEXT_DOMAIN).'</h4>';
964
+ $content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_RATE_US_URL.'"><span class="dashicons sgpb-dashicons-heart sgpb-info-text-white"></span><span class="sg-info-text">'.__('Rate Us', SG_POPUP_TEXT_DOMAIN).'</span></a>';
965
+ $content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_TICKET_URL.'"><span class="dashicons sgpb-dashicons-megaphone sgpb-info-text-white"></span>'.__('Support Potal', SG_POPUP_TEXT_DOMAIN).'</a>';
966
+ $content .= '<a class="btn btn-info" target="_blank" href="https://wordpress.org/support/plugin/popup-builder"><span class="dashicons sgpb-dashicons-admin-plugins sgpb-info-text-white"></span>'.__('Support Forum', SG_POPUP_TEXT_DOMAIN).'</a>';
967
+ $content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_STORE_URL.'"><span class="dashicons sgpb-dashicons-editor-help sgpb-info-text-white"></span>'.__('LIVE chat', SG_POPUP_TEXT_DOMAIN).'</a>';
968
+ $content .= '<a class="btn btn-info" target="_blank" href="mailto:support@popup-builder.com?subject=Hello"><span class="dashicons sgpb-dashicons-email-alt sgpb-info-text-white"></span>'.__('Email', SG_POPUP_TEXT_DOMAIN).'</a></div>';
969
+ $content .= '<div class="sgpb-support-notification-dont-show">'.__('Bored of this?').'<a class="sgpb-dont-show-again-support-notification" href="javascript:void(0)">'.__(' Press here ').'</a>'.__('and we will not show it again!').'</div>';
970
+
971
+ return $content;
972
+ }
973
+
974
+ public static function getMaxOpenDaysMessage()
975
+ {
976
+ $getUsageDays = self::getPopupUsageDays();
977
+ $firstHeader = __('<h1 class="sgpb-review-h1"><strong class="sgrb-review-strong">This is great!</strong> We have noticed that you are using Popup Builder plugin on your site for '.$getUsageDays.' days, we are thankful for that.</h1>', SG_POPUP_TEXT_DOMAIN);
978
+ $popupContent = self::getMaxOpenPopupContent($firstHeader, 'days');
979
+
980
+ return $popupContent;
981
+ }
982
+
983
+ public static function getPopupUsageDays()
984
+ {
985
+ $installDate = get_option('SGPBInstallDate');
986
+
987
+ $timeDate = new \DateTime('now');
988
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
989
+ $diff = $timeNow-$installDate;
990
+ $days = floor($diff/(60*60*24));
991
+
992
+ return $days;
993
+ }
994
+
995
+ public static function getMaxOpenPopupContent($firstHeader, $type)
996
+ {
997
+ ob_start();
998
+ ?>
999
+ <style>
1000
+ .sgpb-buttons-wrapper .press{
1001
+ box-sizing:border-box;
1002
+ cursor:pointer;
1003
+ display:inline-block;
1004
+ font-size:1em;
1005
+ margin:0;
1006
+ padding:0.5em 0.75em;
1007
+ text-decoration:none;
1008
+ transition:background 0.15s linear
1009
+ }
1010
+ .sgpb-buttons-wrapper .press-grey {
1011
+ background-color:#9E9E9E;
1012
+ border:2px solid #9E9E9E;
1013
+ color: #FFF;
1014
+ }
1015
+ .sgpb-buttons-wrapper .press-lightblue {
1016
+ background-color:#03A9F4;
1017
+ border:2px solid #03A9F4;
1018
+ color: #FFF;
1019
+ }
1020
+ .sgpb-buttons-wrapper {
1021
+ text-align: center;
1022
+ }
1023
+ .sgpb-review-wrapper{
1024
+ text-align: center;
1025
+ padding: 20px;
1026
+ }
1027
+ .sgpb-review-wrapper p {
1028
+ color: black;
1029
+ }
1030
+ .sgpb-review-h1 {
1031
+ font-size: 22px;
1032
+ font-weight: normal;
1033
+ line-height: 1.384;
1034
+ }
1035
+ .sgrb-review-h2{
1036
+ font-size: 20px;
1037
+ font-weight: normal;
1038
+ }
1039
+ :root {
1040
+ --main-bg-color: #1ac6ff;
1041
+ }
1042
+ .sgrb-review-strong{
1043
+ color: var(--main-bg-color);
1044
+ }
1045
+ .sgrb-review-mt20{
1046
+ margin-top: 20px
1047
+ }
1048
+ </style>
1049
+ <div class="sgpb-review-wrapper">
1050
+ <div class="sgpb-review-description">
1051
+ <?php echo $firstHeader; ?>
1052
+ <h2 class="sgrb-review-h2"><?php _e('This is really great for your website score.', SG_POPUP_TEXT_DOMAIN); ?></h2>
1053
+ <p class="sgrb-review-mt20"><?php _e('Have your input in the development of our plugin, and we’ll provide better conversions for your site!<br /> Leave your 5-star positive review and help us go further to the perfection!', SG_POPUP_TEXT_DOMAIN); ?></p>
1054
+ </div>
1055
+ <div class="sgpb-buttons-wrapper">
1056
+ <button class="press press-grey sgpb-button-1 sgpb-close-promo-notification" data-action="sg-already-did-review"><?php _e('I already did', SG_POPUP_TEXT_DOMAIN); ?></button>
1057
+ <button class="press press-lightblue sgpb-button-3 sgpb-close-promo-notification" data-action="sg-you-worth-it"><?php _e('You worth it!', SG_POPUP_TEXT_DOMAIN); ?></button>
1058
+ <button class="press press-grey sgpb-button-2 sgpb-close-promo-notification" data-action="sg-show-popup-period" data-message-type="<?php echo $type; ?>"><?php _e('Maybe later', SG_POPUP_TEXT_DOMAIN); ?></button></div>
1059
+ <div> </div>
1060
+ </div>
1061
+ <?php
1062
+ $popupContent = ob_get_clean();
1063
+
1064
+ return $popupContent;
1065
+ }
1066
+
1067
+ public static function shouldOpenReviewPopupForDays()
1068
+ {
1069
+ $shouldOpen = true;
1070
+ $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1071
+ $periodNextTime = get_option('SGPBOpenNextTime');
1072
+ /*if (!$dontShowAgain) {
1073
+ return true;
1074
+ }
1075
+ else {
1076
+ return false;
1077
+ }*/
1078
+ // When period next time does not exits it means the user is old
1079
+ if (!$periodNextTime) {
1080
+ $usageDays = self::getPopupMainTableCreationDate();
1081
+ update_option('SGPBUsageDays', $usageDays);
1082
+ if (!defined('SGPB_REVIEW_POPUP_PERIOD')) {
1083
+ define('SGPB_REVIEW_POPUP_PERIOD', '500');
1084
+ }
1085
+ // For old users
1086
+ if (defined('SGPB_REVIEW_POPUP_PERIOD') && $usageDays > SGPB_REVIEW_POPUP_PERIOD && !$dontShowAgain) {
1087
+ return $shouldOpen;
1088
+ }
1089
+ $remainingDays = SGPB_REVIEW_POPUP_PERIOD - $usageDays;
1090
+
1091
+ $popupTimeZone = \ConfigDataHelper::getDefaultTimezone();
1092
+ $timeDate = new DateTime('now', new DateTimeZone($popupTimeZone));
1093
+ $timeDate->modify('+'.$remainingDays.' day');
1094
+
1095
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
1096
+ update_option('SGPBOpenNextTime', $timeNow);
1097
+
1098
+ return false;
1099
+ }
1100
+
1101
+ $currentData = new \DateTime('now');
1102
+ $timeNow = $currentData->format('Y-m-d H:i:s');
1103
+ $timeNow = strtotime($timeNow);
1104
+
1105
+ if ($periodNextTime > $timeNow) {
1106
+ $shouldOpen = false;
1107
+ }
1108
+
1109
+ return $shouldOpen;
1110
+ }
1111
+
1112
+ public static function getPopupMainTableCreationDate()
1113
+ {
1114
+ global $wpdb;
1115
+
1116
+ $query = $wpdb->prepare('SELECT table_name, create_time FROM information_schema.tables WHERE table_schema=%s AND table_name=%s', DB_NAME, $wpdb->prefix.'sgpb_subscribers');
1117
+ $results = $wpdb->get_results($query, ARRAY_A);
1118
+ if (empty($results)) {
1119
+ return 0;
1120
+ }
1121
+
1122
+ $createTime = $results[0]['create_time'];
1123
+ $createTime = strtotime($createTime);
1124
+ update_option('SGPBInstallDate', $createTime);
1125
+ $diff = time() - $createTime;
1126
+ $days = floor($diff/(60*60*24));
1127
+
1128
+ return $days;
1129
+ }
1130
+
1131
+ public static function shouldOpenForMaxOpenPopupMessage()
1132
+ {
1133
+ $counterMaxPopup = self::getMaxOpenPopupId();
1134
+
1135
+ if (empty($counterMaxPopup)) {
1136
+ return false;
1137
+ }
1138
+ $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1139
+ $maxCountDefine = get_option('SGPBMaxOpenCount');
1140
+
1141
+ if (!$maxCountDefine) {
1142
+ $maxCountDefine = SGPB_ASK_REVIEW_POPUP_COUNT;
1143
+ }
1144
+
1145
+ return $counterMaxPopup['maxCount'] >= $maxCountDefine && !$dontShowAgain;
1146
+ }
1147
+
1148
+ public static function getMaxOpenPopupId()
1149
+ {
1150
+ $popupsCounterData = get_option('SgpbCounter');
1151
+ if (!$popupsCounterData) {
1152
+ return 0;
1153
+ }
1154
+
1155
+ $counters = array_values($popupsCounterData);
1156
+ $maxCount = max($counters);
1157
+ $popupId = array_search($maxCount, $popupsCounterData);
1158
+
1159
+ $maxPopupData = array(
1160
+ 'popupId' => $popupId,
1161
+ 'maxCount' => $maxCount
1162
+ );
1163
+
1164
+ return $maxPopupData;
1165
+ }
1166
+
1167
+ public static function getMaxOpenPopupsMessage()
1168
+ {
1169
+ $counterMaxPopup = self::getMaxOpenPopupId();
1170
+ $maxCountDefine = get_option('SGPBMaxOpenCount');
1171
+ $popupTitle = get_the_title($counterMaxPopup['popupId']);
1172
+
1173
+ if (!empty($counterMaxPopup['maxCount'])) {
1174
+ $maxCountDefine = $counterMaxPopup['maxCount'];
1175
+ }
1176
+
1177
+ $firstHeader = __('<h1 class="sgpb-review-h1"><strong class="sgrb-review-strong">Awesome news!</strong> <b>Popup Builder</b> plugin helped you to share your message via <strong class="sgrb-review-strong">'.$popupTitle.'</strong> popup with your visitors for <strong class="sgrb-review-strong">'.$maxCountDefine.' times!</strong></h1>', SG_POPUP_TEXT_DOMAIN);
1178
+ $popupContent = self::getMaxOpenPopupContent($firstHeader, 'count');
1179
+
1180
+ return $popupContent;
1181
+ }
1182
+
1183
+ /**
1184
+ * Get email headers
1185
+ *
1186
+ * @since 3.1.0
1187
+ *
1188
+ * @param email $fromEmail
1189
+ * @param array $args
1190
+ *
1191
+ * @return string $headers
1192
+ */
1193
+ public static function getEmailHeader($fromEmail, $args = array())
1194
+ {
1195
+ $contentType = 'text/html';
1196
+ $charset = 'UTF-8';
1197
+ $blogInfo = get_bloginfo();
1198
+
1199
+ if (!empty($args['contentType'])) {
1200
+ $contentType = $args['contentType'];
1201
+ }
1202
+ if (!empty($args['charset'])) {
1203
+ $charset = $args['charset'];
1204
+ }
1205
+ $headers = 'MIME-Version: 1.0'."\r\n";
1206
+ $headers .= 'From: "'.$blogInfo.'" <'.$fromEmail.'>'."\r\n";
1207
+ $headers .= 'Content-type: '.$contentType.'; charset='.$charset.''."\r\n"; //set UTF-8
1208
+
1209
+ return $headers;
1210
+ }
1211
+
1212
+ /**
1213
+ * Get file content from URL
1214
+ *
1215
+ * @since 3.1.0
1216
+ *
1217
+ * @param $url
1218
+ *
1219
+ * @return string
1220
+ */
1221
+ public static function getFileFromURL($url)
1222
+ {
1223
+ $data = '';
1224
+ $remoteData = wp_remote_get($url);
1225
+
1226
+ if (is_wp_error($remoteData)) {
1227
+ return $data;
1228
+ }
1229
+
1230
+ $data = wp_remote_retrieve_body($remoteData);
1231
+
1232
+ return $data;
1233
+ }
1234
+
1235
+ public static function getRightMetaboxBannerText()
1236
+ {
1237
+ $bannerText = get_option('sgpb-metabox-banner-remote-get');
1238
+
1239
+ return $bannerText;
1240
+ }
1241
+
1242
+ public static function getGutenbergPopupsIdAndTitle($excludesPopups = array())
1243
+ {
1244
+ $allPopups = SGPopup::getAllPopups();
1245
+ $popupIdTitles = array();
1246
+
1247
+ if (empty($allPopups)) {
1248
+ return $popupIdTitles;
1249
+ }
1250
+
1251
+ foreach ($allPopups as $popup) {
1252
+ if (empty($popup)) {
1253
+ continue;
1254
+ }
1255
+
1256
+ $id = $popup->getId();
1257
+ $title = $popup->getTitle();
1258
+ $type = $popup->getType();
1259
+
1260
+ if (!empty($excludesPopups)) {
1261
+ foreach ($excludesPopups as $excludesPopupId) {
1262
+ if ($excludesPopupId != $id) {
1263
+ $array = array();
1264
+ $array['id'] = $id;
1265
+ $array['title'] = $title.' - '.$type;
1266
+ $popupIdTitles[] = $array;
1267
+ }
1268
+ }
1269
+ }
1270
+ else {
1271
+ $array = array();
1272
+ $array['id'] = $id;
1273
+ $array['title'] = $title.' - '.$type;
1274
+ $popupIdTitles[] = $array;
1275
+ }
1276
+ }
1277
+
1278
+ return $popupIdTitles;
1279
+ }
1280
+
1281
+ public static function getGutenbergPopupsEvents()
1282
+ {
1283
+ $data = array(
1284
+ array('value' => '', 'title' => __('Select Event', SG_POPUP_TEXT_DOMAIN)),
1285
+ array('value' => 'inherit', 'title' => __('Inherit', SG_POPUP_TEXT_DOMAIN)),
1286
+ array('value' => 'onLoad', 'title' => __('On load', SG_POPUP_TEXT_DOMAIN)),
1287
+ array('value' => 'click', 'title' => __('On click', SG_POPUP_TEXT_DOMAIN)),
1288
+ array('value' => 'hover', 'title' => __('On hover', SG_POPUP_TEXT_DOMAIN))
1289
+ );
1290
+
1291
+ return $data;
1292
+ }
1293
+
1294
+ public static function checkEditorByPopupId($popupId)
1295
+ {
1296
+ $popupContent = '';
1297
+ if (class_exists('\Elementor\Plugin')) {
1298
+ $elementorContent = get_post_meta($popupId, '_elementor_edit_mode', true);
1299
+ if (!empty($elementorContent) && $elementorContent == 'builder') {
1300
+ $popupContent = Elementor\Plugin::instance()->frontend->get_builder_content_for_display($popupId);
1301
+ }
1302
+ }
1303
+ else if (class_exists('Vc_Manager')) {
1304
+ $stylesAndScripts = self::renderWPBakeryScriptsAndStyles($popupId);
1305
+ $popupContent .= '<style>'.$stylesAndScripts.'</style>';
1306
+ }
1307
+
1308
+ return $popupContent;
1309
+ }
1310
+
1311
+ public static function renderWPBakeryScriptsAndStyles($popupId = 0)
1312
+ {
1313
+ return get_post_meta($popupId, '_wpb_shortcodes_custom_css', true);
1314
+ }
1315
+
1316
+ /**
1317
+ * countdown popup, convert date to seconds
1318
+ *
1319
+ * @param $dueDate
1320
+ * @param $timezone
1321
+ * @return false|int|string
1322
+ */
1323
+ public static function dateToSeconds($dueDate, $timezone)
1324
+ {
1325
+ if (empty($timezone)) {
1326
+ return '';
1327
+ }
1328
+
1329
+ $dateObj = self::getDateObjFromDate('now', $timezone);
1330
+ $timeNow = @strtotime($dateObj);
1331
+ $seconds = @strtotime($dueDate)-$timeNow;
1332
+ if ($seconds < 0) {
1333
+ $seconds = 0;
1334
+ }
1335
+
1336
+ return $seconds;
1337
+ }
1338
+
1339
+ /**
1340
+ * Get site protocol
1341
+ *
1342
+ * @since 1.0.0
1343
+ *
1344
+ * @return string $protocol
1345
+ *
1346
+ */
1347
+ public static function getSiteProtocol()
1348
+ {
1349
+ $protocol = 'http';
1350
+
1351
+ if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
1352
+ $protocol = 'https';
1353
+ }
1354
+
1355
+ return $protocol;
1356
+ }
1357
+
1358
+ public static function findSubscribersByEmail($subscriberEmail = '', $list = 0)
1359
+ {
1360
+ global $wpdb;
1361
+ $subscriber = array();
1362
+
1363
+ $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d ', $subscriberEmail, $list);
1364
+ $subscriber = $wpdb->get_row($prepareSql, ARRAY_A);
1365
+ if (!$list) {
1366
+ $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s ', $subscriberEmail);
1367
+ $subscriber = $wpdb->get_results($prepareSql, ARRAY_A);
1368
+ }
1369
+
1370
+ return $subscriber;
1371
+ }
1372
+
1373
+ /**
1374
+ * Update option
1375
+ *
1376
+ * @since 3.1.9
1377
+ *
1378
+ * @return void
1379
+ */
1380
+ public static function updateOption($optionKey, $optionValue)
1381
+ {
1382
+ update_option($optionKey, $optionValue);
1383
+ }
1384
+
1385
+ public static function getOption($optionKey, $default = false)
1386
+ {
1387
+ return get_option($optionKey, $default);
1388
+ }
1389
+
1390
+ public static function deleteOption($optionKey)
1391
+ {
1392
+ delete_option($optionKey);
1393
+ }
1394
+
1395
+ /**
1396
+ * It's change popup registered plugins static paths to dynamic
1397
+ *
1398
+ * @since 3.1.9
1399
+ *
1400
+ * @return bool where true mean modified false mean there is not need modification
1401
+ */
1402
+ public static function makeRegisteredPluginsStaticPathsToDynamic()
1403
+ {
1404
+ // remove old outdated option sgpbModifiedRegisteredPluginsPaths
1405
+ delete_option('sgpbModifiedRegisteredPluginsPaths');
1406
+ delete_option('SG_POPUP_BUILDER_REGISTERED_PLUGINS');
1407
+ $hasModifiedPaths = AdminHelper::getOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED);
1408
+ if ($hasModifiedPaths) {
1409
+ return false;
1410
+ }
1411
+ else {
1412
+ Installer::registerPlugin();
1413
+ }
1414
+ AdminHelper::updateOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED, 1);
1415
+
1416
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1417
+ if (empty($registeredPlugins)) {
1418
+ return false;
1419
+ }
1420
+
1421
+ $registeredPlugins = json_decode($registeredPlugins, true);
1422
+ if (empty($registeredPlugins)) {
1423
+ return false;
1424
+ }
1425
+
1426
+ foreach ($registeredPlugins as $key => $registeredPlugin) {
1427
+ if (empty($registeredPlugin['classPath'])) {
1428
+ continue;
1429
+ }
1430
+ $registeredPlugins[$key]['classPath'] = str_replace(WP_PLUGIN_DIR, '', $registeredPlugin['classPath']);
1431
+ if (!empty($registeredPlugin['options']['licence']['file'])) {
1432
+ $registeredPlugins[$key]['options']['licence']['file'] = $registeredPlugin['options']['licence']['file'];
1433
+ }
1434
+ }
1435
+ $registeredPlugins = json_encode($registeredPlugins);
1436
+
1437
+ AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredPlugins);
1438
+ return true;
1439
+ }
1440
+
1441
+ public static function hasInactiveExtensions()
1442
+ {
1443
+ $hasInactiveExtensions = false;
1444
+ $allRegiseredPBPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1445
+ $allRegiseredPBPlugins = @json_decode($allRegiseredPBPlugins, true);
1446
+ if (empty($allRegiseredPBPlugins)) {
1447
+ return $hasInactiveExtensions;
1448
+ }
1449
+
1450
+ foreach ($allRegiseredPBPlugins as $pluginPath => $registeredPlugin) {
1451
+ if (!isset($registeredPlugin['options']['licence']['key'])) {
1452
+ continue;
1453
+ }
1454
+ if (!isset($registeredPlugin['options']['licence']['file'])) {
1455
+ continue;
1456
+ }
1457
+ $extensionKey = $registeredPlugin['options']['licence']['file'];
1458
+ $isPluginActive = is_plugin_active($extensionKey);
1459
+ $pluginKey = $registeredPlugin['options']['licence']['key'];
1460
+ $isValidLicense = get_option('sgpb-license-status-'.$pluginKey);
1461
+
1462
+ // if we even have at least one inactive extension, we don't need to check remaining extensions
1463
+ if ($isValidLicense != 'valid' && $isPluginActive) {
1464
+ $hasInactiveExtensions = true;
1465
+ break;
1466
+ }
1467
+ }
1468
+
1469
+ return $hasInactiveExtensions;
1470
+ }
1471
+
1472
+ public static function getSubscriptionColumnsById($id)
1473
+ {
1474
+ $popup = SGPopup::find($id);
1475
+ if (empty($popup) || !is_object($popup)) {
1476
+ return array();
1477
+ }
1478
+ $freeSavedOptions = $popup->getOptionValue('sgpb-subs-fields');
1479
+
1480
+ if (!empty($freeSavedOptions)) {
1481
+ return array('firstName' => 'First name','lastName' => 'Last name', 'email' => 'Email', 'date' => 'Date');
1482
+ }
1483
+ $formFieldsJson = $popup->getOptionValue('sgpb-subscription-fields-json');
1484
+ if (!empty($formFieldsJson)) {
1485
+ $data = apply_filters('sgpbGetSubscriptionLabels', array(), $popup);
1486
+ $data['date'] = 'Date';
1487
+ return $data;
1488
+ }
1489
+
1490
+ return array();
1491
+ }
1492
+
1493
+ public static function getCustomFormFieldsByPopupId($popupId)
1494
+ {
1495
+ if (!class_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper')) {
1496
+ return array();
1497
+ }
1498
+
1499
+ if (method_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper', 'getCustomFormFieldsByPopupId')) {
1500
+ return SubscriptionPlusAdminHelper::getCustomFormFieldsByPopupId($popupId);
1501
+ }
1502
+
1503
+ return array();
1504
+ }
1505
+
1506
+ public static function removeAllNonPrintableCharacters($title, $defaultValue)
1507
+ {
1508
+ $titleRes = $title;
1509
+ $pattern = '/[\\\^£$%&*()}{@#~?><>,|=_+¬-]/u';
1510
+ $title = preg_replace($pattern, '', $title);
1511
+ $title = mb_ereg_replace($pattern, '', $title);
1512
+ $title = htmlspecialchars($title, ENT_IGNORE, 'UTF-8');
1513
+ $result = str_replace(' ', '', $title);
1514
+ if (empty($result)) {
1515
+ $titleRes = $defaultValue;
1516
+ }
1517
+
1518
+ return $titleRes;
1519
+ }
1520
+
1521
+ public static function renderCustomScripts($popupId)
1522
+ {
1523
+ $finalResult = '';
1524
+ $postMeta = get_post_meta($popupId, 'sg_popup_scripts', true);
1525
+ if (empty($postMeta)) {
1526
+ return '';
1527
+ }
1528
+ $defaultData = \ConfigDataHelper::defaultData();
1529
+
1530
+ // get scripts
1531
+ if (!isset($postMeta['js'])) {
1532
+ $postMeta['js'] = array();
1533
+ }
1534
+ $jsPostMeta = $postMeta['js'];
1535
+ $jsDefaultData = $defaultData['customEditorContent']['js']['helperText'];
1536
+ $suspiciousStrings = array('document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode', '<!--', '-->');
1537
+ $finalContent = '';
1538
+ $suspiciousStringFound = false;
1539
+ if (!empty($jsPostMeta)) {
1540
+ $customScripts = '<script id="sgpb-custom-script-'.$popupId.'">';
1541
+ foreach ($jsDefaultData as $key => $value) {
1542
+ $eventName = 'sgpb'.$key;
1543
+ if ((!isset($jsPostMeta['sgpb-'.$key]) || empty($jsPostMeta['sgpb-'.$key])) || $key == 'ShouldOpen' || $key == 'ShouldClose') {
1544
+ continue;
1545
+ }
1546
+ $content = @$jsPostMeta['sgpb-'.$key];
1547
+ $content = str_replace('popupId', $popupId, $content);
1548
+ $content = str_replace("<", "&lt;", $content);
1549
+ $content = str_replace(">", "&gt;", $content);
1550
+ foreach ($suspiciousStrings as $string) {
1551
+ if (strpos($content, $string)) {
1552
+ $suspiciousStringFound = true;
1553
+ break;
1554
+ }
1555
+ }
1556
+ if ($suspiciousStringFound) {
1557
+ break;
1558
+ }
1559
+ $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
1560
+
1561
+ $finalContent .= 'jQuery(document).ready(function(){';
1562
+ $finalContent .= 'sgAddEvent(window, "'.$eventName.'", function(e) {';
1563
+ $finalContent .= 'if (e.detail.popupId == "'.$popupId.'") {';
1564
+ $finalContent .= $content;
1565
+ $finalContent .= '};';
1566
+ $finalContent .= '});';
1567
+ $finalContent .= '});';
1568
+ }
1569
+ $customScripts .= $finalContent;
1570
+ $customScripts .= '</script>';
1571
+ if (empty($finalContent)) {
1572
+ $customScripts = '';
1573
+ }
1574
+ $finalResult .= $customScripts;
1575
+ }
1576
+
1577
+ // get styles
1578
+ if (isset($postMeta['css'])) {
1579
+ $cssPostMeta = $postMeta['css'];
1580
+ }
1581
+ $finalContent = '';
1582
+ if (!empty($cssPostMeta)) {
1583
+ $customStyles = '<style id="sgpb-custom-style-'.$popupId.'">';
1584
+ $finalContent = str_replace('popupId', $popupId, $cssPostMeta);
1585
+ $finalContent = html_entity_decode($finalContent, ENT_QUOTES, 'UTF-8');
1586
+
1587
+ $customStyles .= $finalContent;
1588
+ $customStyles .= '</style>';
1589
+ $finalResult .= $customStyles;
1590
+ }
1591
+
1592
+
1593
+ return $finalResult;
1594
+ }
1595
+
1596
+ public static function removeSelectedTypeOptions($type)
1597
+ {
1598
+ switch ($type) {
1599
+ case 'cron':
1600
+ $crons = _get_cron_array();
1601
+ foreach ($crons as $key => $value) {
1602
+ foreach ($value as $key => $body) {
1603
+ if (strstr($key, 'sgpb')) {
1604
+ wp_clear_scheduled_hook($key);
1605
+ }
1606
+ }
1607
+ }
1608
+ break;
1609
+ }
1610
+ }
1611
+
1612
+ public static function getSystemInfoText() {
1613
+ global $wpdb;
1614
+
1615
+ $browser = self::getBrowser();
1616
+
1617
+ // Get theme info
1618
+ if (get_bloginfo('version') < '3.4') {
1619
+ $themeData = wp_get_theme(get_stylesheet_directory().'/style.css');
1620
+ $theme = $themeData['Name'].' '.$themeData['Version'];
1621
+ }
1622
+ else {
1623
+ $themeData = wp_get_theme();
1624
+ $theme = $themeData->Name.' '.$themeData->Version;
1625
+ }
1626
+
1627
+ // Try to identify the hosting provider
1628
+ $host = self::getHost();
1629
+
1630
+ $systemInfoContent = '### Start System Info ###'."\n\n";
1631
+
1632
+ // Start with the basics...
1633
+ $systemInfoContent .= '-- Site Info'."\n\n";
1634
+ $systemInfoContent .= 'Site URL: '.site_url()."\n";
1635
+ $systemInfoContent .= 'Home URL: '.home_url()."\n";
1636
+ $systemInfoContent .= 'Multisite: '.(is_multisite() ? 'Yes' : 'No')."\n";
1637
+
1638
+ // Can we determine the site's host?
1639
+ if ($host) {
1640
+ $systemInfoContent .= "\n".'-- Hosting Provider'."\n\n";
1641
+ $systemInfoContent .= 'Host: '.$host."\n";
1642
+ }
1643
+
1644
+ // The local users' browser information, handled by the Browser class
1645
+ $systemInfoContent .= "\n".'-- User Browser'."\n\n";
1646
+ $systemInfoContent .= $browser;
1647
+
1648
+ // WordPress configuration
1649
+ $systemInfoContent .= "\n".'-- WordPress Configuration'."\n\n";
1650
+ $systemInfoContent .= 'Version: '.get_bloginfo('version')."\n";
1651
+ $systemInfoContent .= 'Language: '.(defined('WPLANG') && WPLANG ? WPLANG : 'en_US')."\n";
1652
+ $systemInfoContent .= 'Permalink Structure: '.(get_option('permalink_structure') ? get_option('permalink_structure') : 'Default')."\n";
1653
+ $systemInfoContent .= 'Active Theme: '.$theme."\n";
1654
+ $systemInfoContent .= 'Show On Front: '.get_option('show_on_front')."\n";
1655
+
1656
+ // Only show page specs if frontpage is set to 'page'
1657
+ if (get_option('show_on_front') == 'page') {
1658
+ $frontPageId = get_option('page_on_front');
1659
+ $blogPageId = get_option('page_for_posts');
1660
+
1661
+ $systemInfoContent .= 'Page On Front: '.($frontPageId != 0 ? get_the_title($frontPageId).' (#'.$frontPageId.')' : 'Unset')."\n";
1662
+ $systemInfoContent .= 'Page For Posts: '.($blogPageId != 0 ? get_the_title($blogPageId).' (#'.$blogPageId.')' : 'Unset')."\n";
1663
+ }
1664
+
1665
+ $systemInfoContent .= 'Table Prefix: '.'Prefix: '.$wpdb->prefix.' Length: '.strlen($wpdb->prefix ).' Status: '.( strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable')."\n";
1666
+ $systemInfoContent .= 'WP_DEBUG: '.(defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set')."\n";
1667
+ $systemInfoContent .= 'Memory Limit: '.WP_MEMORY_LIMIT."\n";
1668
+ $systemInfoContent .= 'Registered Post Stati: '.implode(', ', get_post_stati())."\n";
1669
+
1670
+ // Must-use plugins
1671
+ $muplugins = get_mu_plugins();
1672
+ if ($muplugins && count($muplugins)) {
1673
+ $systemInfoContent .= "\n".'-- Must-Use Plugins'."\n\n";
1674
+
1675
+ foreach ($muplugins as $plugin => $plugin_data) {
1676
+ $systemInfoContent .= $plugin_data['Name'].': '.$plugin_data['Version']."\n";
1677
+ }
1678
+ }
1679
+
1680
+ $registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1681
+ $registered = json_decode($registered, true);
1682
+
1683
+ if (empty($registered)) {
1684
+ return false;
1685
+ }
1686
+ // remove free package data, we don't need it
1687
+ array_shift($registered);
1688
+
1689
+ $systemInfoContent .= "\n".'-- Popup Builder License Data'."\n\n";
1690
+ if (!empty($registered)) {
1691
+ foreach ($registered as $singleExntensionData) {
1692
+ if (empty($singleExntensionData['options'])) {
1693
+ continue;
1694
+ }
1695
+
1696
+ $key = $singleExntensionData['options']['licence']['key'];
1697
+ $name = $singleExntensionData['options']['licence']['itemName'];
1698
+ $licenseKey = __('No license');
1699
+ if (!empty($key)) {
1700
+ $licenseKey = self::getOption('sgpb-license-key-'.$key);
1701
+ }
1702
+ $licenseStatus = 'Inactive';
1703
+ if (self::getOption('sgpb-license-status-'.$key) == 'valid') {
1704
+ $licenseStatus = 'Active';
1705
+ }
1706
+
1707
+ $systemInfoContent .= 'Name: '.$name."\n";
1708
+ $systemInfoContent .= 'License key: '.$licenseKey."\n";
1709
+ $systemInfoContent .= 'License status: '.$licenseStatus."\n";
1710
+ $systemInfoContent .= "\n";
1711
+ }
1712
+ }
1713
+
1714
+ $systemInfoContent .= "\n".'-- All created Popups'."\n\n";
1715
+ $allPopups = self::getPopupsIdAndTitle();
1716
+ $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
1717
+ foreach ($allPopups as $id => $popupTitleType) {
1718
+ $popup = SGPopup::find($id, $args);
1719
+ $popupStatus = ($popup->getOptionValue('sgpb-is-active')) ? 'Enabled' : 'Disabled';
1720
+ $systemInfoContent .= 'Id: '.$id."\n";
1721
+ $systemInfoContent .= 'Title: '.get_the_title($id)."\n";
1722
+ $systemInfoContent .= 'Type: '.$popup->getOptionValue('sgpb-type')."\n";
1723
+ $systemInfoContent .= 'Status: '.$popupStatus."\n";
1724
+ $systemInfoContent .= "\n";
1725
+ }
1726
+
1727
+ // WordPress active plugins
1728
+ $systemInfoContent .= "\n".'-- WordPress Active Plugins'."\n\n";
1729
+
1730
+ $plugins = get_plugins();
1731
+ $activePlugins = get_option('active_plugins', array());
1732
+ foreach ($plugins as $pluginPath => $plugin) {
1733
+
1734
+ if (! in_array($pluginPath, $activePlugins)) {
1735
+ continue;
1736
+ }
1737
+
1738
+ $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1739
+ }
1740
+ // WordPress inactive plugins
1741
+ $systemInfoContent .= "\n".'-- WordPress Inactive Plugins'."\n\n";
1742
+
1743
+ foreach ($plugins as $pluginPath => $plugin) {
1744
+ if (in_array($pluginPath, $activePlugins)) {
1745
+ continue;
1746
+ }
1747
+ $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1748
+ }
1749
+
1750
+ if (is_multisite()) {
1751
+ // WordPress Multisite active plugins
1752
+ $systemInfoContent .= "\n".'-- Network Active Plugins'."\n\n";
1753
+
1754
+ $plugins = wp_get_active_network_plugins();
1755
+ $activePlugins = get_site_option('active_sitewide_plugins', array());
1756
+
1757
+ foreach ($plugins as $pluginPath) {
1758
+ $plugin_base = plugin_basename($pluginPath);
1759
+
1760
+ if (! array_key_exists($plugin_base, $activePlugins)) {
1761
+ continue;
1762
+ }
1763
+
1764
+ $plugin = get_plugin_data($pluginPath);
1765
+ $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1766
+ }
1767
+ }
1768
+
1769
+ // Server configuration (really just versioning)
1770
+ $systemInfoContent .= "\n".'-- Webserver Configuration'."\n\n";
1771
+ $systemInfoContent .= 'PHP Version: '.PHP_VERSION."\n";
1772
+ $systemInfoContent .= 'MySQL Version: '.$wpdb->db_version()."\n";
1773
+ $systemInfoContent .= 'Webserver Info: '.$_SERVER['SERVER_SOFTWARE']."\n";
1774
+
1775
+ // PHP configs... now we're getting to the important stuff
1776
+ $systemInfoContent .= "\n".'-- PHP Configuration'."\n\n";
1777
+ $systemInfoContent .= 'Memory Limit: '.ini_get('memory_limit')."\n";
1778
+ $systemInfoContent .= 'Upload Max Size: '.ini_get('upload_max_filesize')."\n";
1779
+ $systemInfoContent .= 'Post Max Size: '.ini_get('post_max_size')."\n";
1780
+ $systemInfoContent .= 'Upload Max Filesize: '.ini_get('upload_max_filesize')."\n";
1781
+ $systemInfoContent .= 'Time Limit: '.ini_get('max_execution_time')."\n";
1782
+ $systemInfoContent .= 'Max Input Vars: '.ini_get('max_input_vars')."\n";
1783
+ $systemInfoContent .= 'Display Errors: '.(ini_get('display_errors') ? 'On ('.ini_get('display_errors').')' : 'N/A')."\n";
1784
+
1785
+ // PHP extensions and such
1786
+ $systemInfoContent .= "\n".'-- PHP Extensions'."\n\n";
1787
+ $systemInfoContent .= 'cURL: '.(function_exists('curl_init') ? 'Supported' : 'Not Supported')."\n";
1788
+ $systemInfoContent .= 'fsockopen: '.(function_exists('fsockopen') ? 'Supported' : 'Not Supported')."\n";
1789
+ $systemInfoContent .= 'SOAP Client: '.(class_exists('SoapClient') ? 'Installed' : 'Not Installed')."\n";
1790
+ $systemInfoContent .= 'Suhosin: '.(extension_loaded('suhosin') ? 'Installed' : 'Not Installed')."\n";
1791
+
1792
+ // Session stuff
1793
+ $systemInfoContent .= "\n".'-- Session Configuration'."\n\n";
1794
+ $systemInfoContent .= 'Session: '.(isset($_SESSION ) ? 'Enabled' : 'Disabled')."\n";
1795
+
1796
+ // The rest of this is only relevant is session is enabled
1797
+ if (isset($_SESSION)) {
1798
+ $systemInfoContent .= 'Session Name: '.esc_html( ini_get('session.name'))."\n";
1799
+ $systemInfoContent .= 'Cookie Path: '.esc_html( ini_get('session.cookie_path'))."\n";
1800
+ $systemInfoContent .= 'Save Path: '.esc_html( ini_get('session.save_path'))."\n";
1801
+ $systemInfoContent .= 'Use Cookies: '.(ini_get('session.use_cookies') ? 'On' : 'Off')."\n";
1802
+ $systemInfoContent .= 'Use Only Cookies: '.(ini_get('session.use_only_cookies') ? 'On' : 'Off')."\n";
1803
+ }
1804
+
1805
+ $systemInfoContent = apply_filters('sgpbSystemInformation', $systemInfoContent);
1806
+
1807
+ $systemInfoContent .= "\n".'### End System Info ###';
1808
+
1809
+ return $systemInfoContent;
1810
+ }
1811
+
1812
+ public static function getHost()
1813
+ {
1814
+ if (defined('WPE_APIKEY')) {
1815
+ return 'WP Engine';
1816
+ }
1817
+ else if (defined('PAGELYBIN')) {
1818
+ return 'Pagely';
1819
+ }
1820
+ else if (DB_HOST == 'localhost:/tmp/mysql5.sock') {
1821
+ return 'ICDSoft';
1822
+ }
1823
+ else if (DB_HOST == 'mysqlv5') {
1824
+ return 'NetworkSolutions';
1825
+ }
1826
+ else if (strpos(DB_HOST, 'ipagemysql.com') !== false) {
1827
+ return 'iPage';
1828
+ }
1829
+ else if (strpos(DB_HOST, 'ipowermysql.com') !== false) {
1830
+ return 'IPower';
1831
+ }
1832
+ else if (strpos(DB_HOST, '.gridserver.com') !== false) {
1833
+ return 'MediaTemple Grid';
1834
+ }
1835
+ else if (strpos(DB_HOST, '.pair.com') !== false) {
1836
+ return 'pair Networks';
1837
+ }
1838
+ else if (strpos(DB_HOST, '.stabletransit.com') !== false) {
1839
+ return 'Rackspace Cloud';
1840
+ }
1841
+ else if (strpos(DB_HOST, '.sysfix.eu') !== false) {
1842
+ return 'SysFix.eu Power Hosting';
1843
+ }
1844
+ else if (strpos($_SERVER['SERVER_NAME'], 'Flywheel') !== false) {
1845
+ return 'Flywheel';
1846
+ }
1847
+ else {
1848
+ // Adding a general fallback for data gathering
1849
+ return 'DBH: '.DB_HOST.', SRV: '.$_SERVER['SERVER_NAME'];
1850
+ }
1851
+ }
1852
+
1853
+ public static function getBrowser()
1854
+ {
1855
+ $uAgent = 'Unknown';
1856
+ if (isset($_SERVER['HTTP_USER_AGENT'])) {
1857
+ $uAgent = $_SERVER['HTTP_USER_AGENT'];
1858
+ }
1859
+ $bname = $platform = $ub = $version = 'Unknown';
1860
+ $browserInfoContent = '';
1861
+
1862
+ //First get the platform?
1863
+ if (preg_match('/linux/i', $uAgent)) {
1864
+ $platform = 'Linux';
1865
+ }
1866
+ else if (preg_match('/macintosh|mac os x/i', $uAgent)) {
1867
+ $platform = 'Apple';
1868
+ }
1869
+ else if (preg_match('/windows|win32/i', $uAgent)) {
1870
+ $platform = 'Windows';
1871
+ }
1872
+
1873
+ if (preg_match('/MSIE/i',$uAgent) && !preg_match('/Opera/i',$uAgent)) {
1874
+ $bname = 'Internet Explorer';
1875
+ $ub = 'MSIE';
1876
+ }
1877
+ else if (preg_match('/Firefox/i',$uAgent)) {
1878
+ $bname = 'Mozilla Firefox';
1879
+ $ub = 'Firefox';
1880
+ }
1881
+ else if (preg_match('/OPR/i',$uAgent)) {
1882
+ $bname = 'Opera';
1883
+ $ub = 'Opera';
1884
+ }
1885
+ else if (preg_match('/Chrome/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1886
+ $bname = 'Google Chrome';
1887
+ $ub = 'Chrome';
1888
+ }
1889
+ else if (preg_match('/Safari/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1890
+ $bname = 'Apple Safari';
1891
+ $ub = 'Safari';
1892
+ }
1893
+ else if (preg_match('/Netscape/i',$uAgent)) {
1894
+ $bname = 'Netscape';
1895
+ $ub = 'Netscape';
1896
+ }
1897
+ else if (preg_match('/Edge/i',$uAgent)) {
1898
+ $bname = 'Edge';
1899
+ $ub = 'Edge';
1900
+ }
1901
+ else if (preg_match('/Trident/i',$uAgent)) {
1902
+ $bname = 'Internet Explorer';
1903
+ $ub = 'MSIE';
1904
+ }
1905
+
1906
+ // finally get the correct version number
1907
+ $known = array('Version', $ub, 'other');
1908
+ $pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
1909
+ $matches = array();
1910
+ preg_match_all($pattern, $uAgent, $matches);
1911
+
1912
+ // see how many we have
1913
+ $i = count($matches['browser']);
1914
+ //we will have two since we are not using 'other' argument yet
1915
+ if ($i != 1) {
1916
+ //see if version is before or after the name
1917
+ if (strripos($uAgent,"Version") < strripos($uAgent,$ub)) {
1918
+ $version= $matches['version'][0];
1919
+ }
1920
+ else {
1921
+ $version= $matches['version'][1];
1922
+ }
1923
+ }
1924
+ else {
1925
+ $version= $matches['version'][0];
1926
+ }
1927
+
1928
+ // check if we have a number
1929
+ if ($version == null || $version == "") {$version = "?" ;}
1930
+
1931
+ $browserInfoContent .= 'Platform: '.$platform."\n";
1932
+ $browserInfoContent .= 'Browser Name: '.$bname."\n";
1933
+ $browserInfoContent .= 'Browser Version: '.$version."\n";
1934
+ $browserInfoContent .= 'User Agent: '.$uAgent."\n";
1935
+
1936
+ return $browserInfoContent;
1937
+ }
1938
+
1939
+ // checking user roles capability to do actions
1940
+ public static function userCanAccessTo()
1941
+ {
1942
+ // if this is not admin side screen we don't need to check roles and capabilities
1943
+ if (!is_admin()) {
1944
+ return true;
1945
+ }
1946
+
1947
+ $allow = false;
1948
+
1949
+ $savedUserRolesInPopup = self::getPopupPostAllowedUserRoles();
1950
+ $currentUserRole = self::getCurrentUserRole();
1951
+
1952
+ // we need to check if there are any intersections between saved user roles and current user
1953
+ $hasIntersection = array_intersect($currentUserRole, $savedUserRolesInPopup);
1954
+ if (!empty($hasIntersection)) {
1955
+ $allow = true;
1956
+ }
1957
+
1958
+ return $allow;
1959
+ }
1960
+
1961
+ public static function filterUserCapabilitiesForTheUserRoles($hook = 'save')
1962
+ {
1963
+ global $wp_roles;
1964
+
1965
+ $allAvailableWpRoles = $wp_roles->roles;
1966
+ $savedUserRoles = get_option('sgpb-user-roles');
1967
+ // we need to remove from all roles, either when deactivating the plugin and when there is no saved roles
1968
+ if (empty($savedUserRoles) || $hook == 'deactivate') {
1969
+ $savedUserRoles = array();
1970
+ }
1971
+ $rolesToBeRestricted = array();
1972
+ // selected user roles, which have access to the PB
1973
+ foreach ($allAvailableWpRoles as $allAvailableWpRole) {
1974
+ if (isset($allAvailableWpRole['name']) && in_array(lcfirst($allAvailableWpRole['name']), $savedUserRoles)) {
1975
+ $indexToUnset = lcfirst($allAvailableWpRole['name']);
1976
+ continue;
1977
+ }
1978
+ $rolesToBeRestricted[] = lcfirst($allAvailableWpRole['name']);
1979
+ }
1980
+
1981
+ $caps = array(
1982
+ 'read_private_sgpb_popups',
1983
+ 'edit_sgpb_popup',
1984
+ 'edit_sgpb_popups',
1985
+ 'edit_others_sgpb_popups',
1986
+ 'edit_published_sgpb_popups',
1987
+ 'publish_sgpb_popups',
1988
+ 'delete_sgpb_popups',
1989
+ 'delete_published_posts',
1990
+ 'delete_others_sgpb_popups',
1991
+ 'delete_private_sgpb_popups',
1992
+ 'delete_private_sgpb_popup',
1993
+ 'delete_published_sgpb_popups',
1994
+ 'sgpb_manage_options',
1995
+ 'manage_popup_terms',
1996
+ 'manage_popup_categories_terms'
1997
+ );
1998
+
1999
+ if ($hook == 'activate') {
2000
+ $rolesToBeRestricted = $savedUserRoles;
2001
+ }
2002
+ foreach ($rolesToBeRestricted as $roleToBeRestricted) {
2003
+ if ($roleToBeRestricted == 'administrator' || $roleToBeRestricted == 'admin') {
2004
+ continue;
2005
+ }
2006
+ foreach ($caps as $cap) {
2007
+ // only for the activation hook we need to add our capabilities back
2008
+ if ($hook == 'activate') {
2009
+ $wp_roles->add_cap($roleToBeRestricted, $cap);
2010
+ }
2011
+ else {
2012
+ $wp_roles->remove_cap($roleToBeRestricted, $cap);
2013
+ }
2014
+ }
2015
+ }
2016
+ }
2017
+
2018
+ public static function removeUnnecessaryCodeFromPopups()
2019
+ {
2020
+ $alreadyClearded = self::getOption('sgpb-unnecessary-scripts-removed-1');
2021
+ if ($alreadyClearded) {
2022
+ return true;
2023
+ }
2024
+
2025
+ global $wpdb;
2026
+ $getAllDataSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.'posts WHERE post_type = %s', SG_POPUP_POST_TYPE);
2027
+ $popupsId = $wpdb->get_results($getAllDataSql, ARRAY_A);
2028
+ if (empty($popupsId)) {
2029
+ return true;
2030
+ }
2031
+ foreach ($popupsId as $popupId) {
2032
+ if (empty($popupId['id'])) {
2033
+ continue;
2034
+ }
2035
+ $id = $popupId['id'];
2036
+ $customScripts = get_post_meta($id, 'sg_popup_scripts', true);
2037
+ if (empty($customScripts)) {
2038
+ continue;
2039
+ }
2040
+ if (isset($customScripts['js'])) {
2041
+ unset($customScripts['js']);
2042
+ update_post_meta($id, 'sg_popup_scripts', $customScripts);
2043
+ }
2044
+ }
2045
+
2046
+ self::updateOption('sgpb-unnecessary-scripts-removed-1', 1);
2047
+ }
2048
+
2049
+ public static function sendTestNewsletter($newsletterData = array())
2050
+ {
2051
+ $mailSubject = $newsletterData['newsletterSubject'];
2052
+ $fromEmail = $newsletterData['fromEmail'];
2053
+ $emailMessage = $newsletterData['messageBody'];
2054
+ $blogInfo = get_bloginfo();
2055
+ $headers = array(
2056
+ 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
2057
+ 'MIME-Version: 1.0' ,
2058
+ 'Content-type: text/html; charset=UTF-8'
2059
+ );
2060
+
2061
+ $emails = get_option('admin_email');
2062
+ if (!empty($newsletterData['testSendingEmails'])) {
2063
+ $emails = $newsletterData['testSendingEmails'];
2064
+ $emails = str_replace(' ', '', $emails);
2065
+
2066
+ $receiverEmailsArray = array();
2067
+ $emails = explode(',', $emails);
2068
+ foreach ($emails as $mail) {
2069
+ if (is_email($mail)) {
2070
+ $receiverEmailsArray[] = $mail;
2071
+ }
2072
+ }
2073
+ $emails = $receiverEmailsArray;
2074
+ }
2075
+
2076
+ $mailStatus = wp_mail($emails, $mailSubject, $emailMessage, $headers);
2077
+
2078
+ wp_die($newsletterData['testSendingStatus']);
2079
+ }
2080
+
2081
+ // wp uploaded images
2082
+ public static function getImageAltTextByUrl($imageUrl = '')
2083
+ {
2084
+ $imageId = attachment_url_to_postid($imageUrl);
2085
+ $altText = get_post_meta($imageId, '_wp_attachment_image_alt', true);
2086
+
2087
+ return $altText;
2088
+ }
2089
+
2090
+ public static function hasBlocks($content)
2091
+ {
2092
+ if (function_exists('has_blocks')) {
2093
+ return has_blocks($content);
2094
+ }
2095
+
2096
+ return false !== strpos( (string) $content, '<!-- wp:' );
2097
+ }
2098
+ /**
2099
+ * Retrieve duplicate post link for post.
2100
+ *
2101
+ * @param int $id Optional. Post ID.
2102
+ * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
2103
+ * @return string
2104
+ */
2105
+ public static function popupGetClonePostLink($id = 0, $context = 'display')
2106
+ {
2107
+ if (!$post = get_post($id)) {
2108
+ return;
2109
+ }
2110
+ $actionName = "popupSaveAsNew";
2111
+
2112
+ if ('display' == $context) {
2113
+ $action = '?action='.$actionName.'&amp;post='.$post->ID;
2114
+ } else {
2115
+ $action = '?action='.$actionName.'&post='.$post->ID;
2116
+ }
2117
+
2118
+ $postTypeObject = get_post_type_object($post->post_type);
2119
+
2120
+ if (!$postTypeObject) {
2121
+ return;
2122
+ }
2123
+
2124
+ return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
2125
+ }
2126
+ }
com/helpers/ConfigDataHelper.php CHANGED
@@ -1,1227 +1,1227 @@
1
- <?php
2
- class ConfigDataHelper
3
- {
4
- public static $customPostType;
5
-
6
- public static function getPostTypeData($args = array())
7
- {
8
- $query = self::getQueryDataByArgs($args);
9
-
10
- $posts = array();
11
- foreach ($query->posts as $post) {
12
- $posts[$post->ID] = $post->post_title;
13
- }
14
-
15
- return $posts;
16
- }
17
-
18
- public static function getQueryDataByArgs($args = array())
19
- {
20
- $defaultArgs = array(
21
- 'offset' => '',
22
- 'orderby' => 'date',
23
- 'order' => 'DESC',
24
- 'post_status' => 'publish',
25
- 'suppress_filters' => true,
26
- 'post_type' => 'post',
27
- 'posts_per_page' => 1000
28
- );
29
- $args = wp_parse_args($args, $defaultArgs);
30
- $query = new WP_Query($args);
31
-
32
- return $query;
33
- }
34
-
35
- public static function getAllCustomPosts()
36
- {
37
- $args = array(
38
- 'public' => true,
39
- '_builtin' => false
40
- );
41
-
42
- $allCustomPosts = get_post_types($args);
43
-
44
- if (isset($allCustomPosts[SG_POPUP_POST_TYPE])) {
45
- unset($allCustomPosts[SG_POPUP_POST_TYPE]);
46
- }
47
-
48
- return $allCustomPosts;
49
- }
50
-
51
- public static function addFilters()
52
- {
53
- self::addPostTypeToFilters();
54
- }
55
-
56
- private static function addPostTypeToFilters()
57
- {
58
- add_filter('sgPopupTargetParams', array(__CLASS__, 'addPopupTargetParams'), 1, 1);
59
- add_filter('sgPopupTargetData', array(__CLASS__, 'addPopupTargetData'), 1, 1);
60
- add_filter('sgPopupTargetTypes', array(__CLASS__, 'addPopupTargetTypes'), 1, 1);
61
- add_filter('sgPopupTargetAttrs', array(__CLASS__, 'addPopupTargetAttrs'), 1, 1);
62
- add_filter('sgPopupPageTemplates', array(__CLASS__, 'addPopupPageTemplates'), 1, 1);
63
- }
64
-
65
- public static function addPopupTargetParams($targetParams)
66
- {
67
- $allCustomPostTypes = self::getAllCustomPosts();
68
- // for conditions, to exclude other post types, tags etc.
69
- if (isset($targetParams['select_role'])) {
70
- return $targetParams;
71
- }
72
-
73
- foreach ($allCustomPostTypes as $customPostType) {
74
- $targetParams[$customPostType] = array(
75
- $customPostType.'_all' => 'All '.ucfirst($customPostType).'s',
76
- $customPostType.'_archive' => 'Archives '.ucfirst($customPostType).'s',
77
- $customPostType.'_selected' => 'Select '.ucfirst($customPostType).'s',
78
- $customPostType.'_categories' => 'Select '.ucfirst($customPostType).' categories'
79
- );
80
- }
81
-
82
- return $targetParams;
83
- }
84
-
85
- public static function addPopupTargetData($targetData)
86
- {
87
- $allCustomPostTypes = self::getAllCustomPosts();
88
-
89
- foreach ($allCustomPostTypes as $customPostType) {
90
- $targetData[$customPostType.'_all'] = null;
91
- $targetData[$customPostType.'_selected'] = '';
92
- $targetData[$customPostType.'_categories'] = self::getCustomPostCategories($customPostType);
93
- }
94
-
95
- return $targetData;
96
- }
97
-
98
- public static function getCustomPostCategories($postTypeName)
99
- {
100
- $taxonomyObjects = get_object_taxonomies($postTypeName);
101
- if ($postTypeName == 'product') {
102
- $taxonomyObjects = array('product_cat');
103
- }
104
- $categories = self::getPostsAllCategories($postTypeName, $taxonomyObjects);
105
-
106
- return $categories;
107
- }
108
-
109
- public static function addPopupTargetTypes($targetTypes)
110
- {
111
- $allCustomPostTypes = self::getAllCustomPosts();
112
-
113
- foreach ($allCustomPostTypes as $customPostType) {
114
- $targetTypes[$customPostType.'_selected'] = 'select';
115
- $targetTypes[$customPostType.'_categories'] = 'select';
116
- }
117
-
118
- return $targetTypes;
119
- }
120
-
121
- public static function addPopupTargetAttrs($targetAttrs)
122
- {
123
- $allCustomPostTypes = self::getAllCustomPosts();
124
-
125
- foreach ($allCustomPostTypes as $customPostType) {
126
- $targetAttrs[$customPostType.'_selected']['htmlAttrs'] = array('class' => 'js-sg-select2 js-select-ajax', 'data-select-class' => 'js-select-ajax', 'data-select-type' => 'ajax', 'data-value-param' => $customPostType, 'multiple' => 'multiple');
127
- $targetAttrs[$customPostType.'_selected']['infoAttrs'] = array('label' => __('Select ', SG_POPUP_TEXT_DOMAIN).$customPostType);
128
-
129
- $targetAttrs[$customPostType.'_categories']['htmlAttrs'] = array('class' => 'js-sg-select2 js-select-ajax', 'data-select-class' => 'js-select-ajax', 'isNotPostType' => true, 'data-value-param' => $customPostType, 'multiple' => 'multiple');
130
- $targetAttrs[$customPostType.'_categories']['infoAttrs'] = array('label' => __('Select ', SG_POPUP_TEXT_DOMAIN).$customPostType.' categories');
131
- }
132
-
133
- return $targetAttrs;
134
- }
135
-
136
- public static function addPopupPageTemplates($templates)
137
- {
138
- $pageTemplates = self::getPageTemplates();
139
-
140
- $pageTemplates += $templates;
141
-
142
- return $pageTemplates;
143
- }
144
-
145
- public static function getAllCustomPostTypes()
146
- {
147
- $args = array(
148
- 'public' => true,
149
- '_builtin' => false
150
- );
151
-
152
- $allCustomPosts = get_post_types($args);
153
- if (!empty($allCustomPosts[SG_POPUP_POST_TYPE])) {
154
- unset($allCustomPosts[SG_POPUP_POST_TYPE]);
155
- }
156
-
157
- return $allCustomPosts;
158
- }
159
-
160
- public static function getPostsAllCategories($postType = 'post', $taxonomies = array())
161
- {
162
- $cats = get_transient(SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES);
163
- if ($cats === false) {
164
- $cats = get_terms(
165
- array(
166
- 'taxonomy' => $taxonomies,
167
- 'hide_empty' => false,
168
- 'type' => $postType,
169
- 'orderby' => 'name',
170
- 'order' => 'ASC'
171
- )
172
- );
173
- set_transient(SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES, $cats, SGPB_TRANSIENT_TIMEOUT_WEEK);
174
- }
175
-
176
- $supportedTaxonomies = array('category');
177
- if (!empty($taxonomies)) {
178
- $supportedTaxonomies = $taxonomies;
179
- }
180
-
181
- $catsParams = array();
182
- foreach ($cats as $cat) {
183
- if (isset($cat->taxonomy)) {
184
- if (!in_array($cat->taxonomy, $supportedTaxonomies)) {
185
- continue;
186
- }
187
- }
188
- $id = $cat->term_id;
189
- $name = $cat->name;
190
- $catsParams[$id] = $name;
191
- }
192
-
193
- return $catsParams;
194
- }
195
-
196
- public static function getPageTypes()
197
- {
198
- $postTypes = array();
199
-
200
- $postTypes['is_home_page'] = __('Home Page', SG_POPUP_TEXT_DOMAIN);
201
- $postTypes['is_home'] = __('Posts Page', SG_POPUP_TEXT_DOMAIN);
202
- $postTypes['is_search'] = __('Search Pages', SG_POPUP_TEXT_DOMAIN);
203
- $postTypes['is_404'] = __('404 Pages', SG_POPUP_TEXT_DOMAIN);
204
- if (function_exists('is_shop')) {
205
- $postTypes['is_shop'] = __('Shop Page', SG_POPUP_TEXT_DOMAIN);
206
- }
207
- if (function_exists('is_archive')) {
208
- $postTypes['is_archive'] = __('Archive Page', SG_POPUP_TEXT_DOMAIN);
209
- }
210
-
211
- return $postTypes;
212
- }
213
-
214
- public static function getPageTemplates()
215
- {
216
- $pageTemplates = array(
217
- 'page.php' => __('Default Template', SG_POPUP_TEXT_DOMAIN)
218
- );
219
-
220
- $templates = wp_get_theme()->get_page_templates();
221
- if (empty($templates)) {
222
- return $pageTemplates;
223
- }
224
-
225
- foreach ($templates as $key => $value) {
226
- $pageTemplates[$key] = $value;
227
- }
228
-
229
- return $pageTemplates;
230
- }
231
-
232
- public static function getAllTags()
233
- {
234
- $allTags = array();
235
- $tags = get_tags(array(
236
- 'hide_empty' => false
237
- ));
238
-
239
- foreach ($tags as $tag) {
240
- $allTags[$tag->slug] = $tag->name;
241
- }
242
-
243
- return $allTags;
244
- }
245
-
246
- public static function defaultData()
247
- {
248
- $data = array();
249
-
250
- $data['contentClickOptions'] = array(
251
- 'template' => array(
252
- 'fieldWrapperAttr' => array(
253
- 'class' => 'col-md-7 sgpb-choice-option-wrapper'
254
- ),
255
- 'labelAttr' => array(
256
- 'class' => 'formItem__title'
257
- ),
258
- 'groupWrapperAttr' => array(
259
- 'class' => 'subFormItem sgpb-choice-wrapper formItem'
260
- )
261
- ),
262
- 'buttonPosition' => 'right',
263
- 'nextNewLine' => true,
264
- 'fields' => array(
265
- array(
266
- 'attr' => array(
267
- 'type' => 'radio',
268
- 'name' => 'sgpb-content-click-behavior',
269
- 'value' => 'close'
270
- ),
271
- 'label' => array(
272
- 'name' => __('Close Popup', SG_POPUP_TEXT_DOMAIN).':'
273
- )
274
- ),
275
- array(
276
- 'attr' => array(
277
- 'type' => 'radio',
278
- 'name' => 'sgpb-content-click-behavior',
279
- 'data-attr-href' => 'content-click-redirect',
280
- 'value' => 'redirect'
281
- ),
282
- 'label' => array(
283
- 'name' => __('Redirect', SG_POPUP_TEXT_DOMAIN).':'
284
- )
285
- ),
286
- array(
287
- 'attr' => array(
288
- 'type' => 'radio',
289
- 'name' => 'sgpb-content-click-behavior',
290
- 'data-attr-href' => 'content-copy-to-clipboard',
291
- 'value' => 'copy'
292
- ),
293
- 'label' => array(
294
- 'name' => __('Copy to clipboard', SG_POPUP_TEXT_DOMAIN).':'
295
- )
296
- )
297
- )
298
- );
299
-
300
- $data['customEditorContent'] = array(
301
- 'js' => array(
302
- 'helperText' => array(
303
- 'ShouldOpen' => '<b>Opening events:</b><br><br><b>#1</b> Add the code you want to run <b>before</b> the popup opening. This will be a condition for opening the popup, that is processed and defined before the popup opening. If the return value is <b>"true"</b> then the popup will open, if the value is <b>"false"</b> the popup won\'t open.',
304
- 'WillOpen' => '<b>#2</b> Add the code you want to run <b>before</b> the popup opens. This will be the code that will work in the process of opening the popup. <b>true/false</b> conditions will not work in this phase.',
305
- 'DidOpen' => '<b>#3</b> Add the code you want to run <b>after</b> the popup opens. This code will work when the popup is already open on the page.',
306
- 'ShouldClose' => '<b>Closing events:</b><br><br><b>#1</b> Add the code that will be fired <b>before</b> the popup closes. This will be a condition for the popup closing. If the return value is <b>"true"</b> then the popup will close, if the value is <b>"false"</b> the popup won\'t close.',
307
- 'WillClose' => '<b>#2</b> Add the code you want to run <b>before</b> the popup closes. This will be the code that will work in the process of closing the popup. <b>true/false</b> conditions will not work in this phase.',
308
- 'DidClose' => '<b>#3</b> Add the code you want to run <b>after</b> the popup closes. This code will work when the popup is already closed on the page.'
309
- ),
310
- 'description' => array(
311
- '<span class="formItem__text">
312
- '.__('If you need the popup id number in the custom code, you may use the following variable to get the ID:', SG_POPUP_TEXT_DOMAIN).'
313
- <b>popupId</b>
314
- </span>'
315
- )
316
- ),
317
- 'css' => array(
318
- // we need this oldDefaultValue for the backward compatibility
319
- 'oldDefaultValue' => array(
320
- '/*popup content wrapper*/'."\n".
321
- '.sgpb-content-popupId {'."\n\n".'}'."\n\n".
322
-
323
- '/*overlay*/'."\n".
324
- '.sgpb-popup-overlay-popupId {'."\n\n".'}'."\n\n".
325
-
326
- '/*popup wrapper*/'."\n".
327
- '.sgpb-popup-builder-content-popupId {'."\n\n".'}'."\n\n"
328
- ),
329
- 'helperText' => array(
330
- '<br>/*popup content wrapper*/',
331
- '.sgpb-content-popupId',
332
- '<br>/*overlay*/',
333
- '.sgpb-popup-overlay-popupId',
334
- '<br>/*popup wrapper*/',
335
- '.sgpb-popup-builder-content-popupId'
336
- ),
337
- 'description' => array(
338
- '<span class="formItem__text">
339
- '.__('If you need the popup id number in the custom code, you may use the following variable to get the ID:', SG_POPUP_TEXT_DOMAIN).'
340
- <b>popupId</b>
341
- </span>'
342
- )
343
- )
344
- );
345
-
346
- $data['htmlCustomButtonArgs'] = array(
347
- 'template' => array(
348
- 'fieldWrapperAttr' => array(
349
- 'class' => 'col-md-6 sgpb-choice-option-wrapper'
350
- ),
351
- 'labelAttr' => array(
352
- 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
353
- ),
354
- 'groupWrapperAttr' => array(
355
- 'class' => 'row form-group sgpb-choice-wrapper'
356
- )
357
- ),
358
- 'buttonPosition' => 'right',
359
- 'nextNewLine' => true,
360
- 'fields' => array(
361
- array(
362
- 'attr' => array(
363
- 'type' => 'radio',
364
- 'name' => 'sgpb-custom-button',
365
- 'class' => 'custom-button-copy-to-clipboard',
366
- 'data-attr-href' => 'sgpb-custom-button-copy',
367
- 'value' => 'copyToClipBoard'
368
- ),
369
- 'label' => array(
370
- 'name' => __('Copy to clipboard', SG_POPUP_TEXT_DOMAIN).':'
371
- )
372
- ),
373
- array(
374
- 'attr' => array(
375
- 'type' => 'radio',
376
- 'name' => 'sgpb-custom-button',
377
- 'class' => 'custom-button-copy-to-clipboard',
378
- 'data-attr-href' => 'sgpb-custom-button-redirect-to-URL',
379
- 'value' => 'redirectToURL'
380
- ),
381
- 'label' => array(
382
- 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
383
- )
384
- ),
385
- array(
386
- 'attr' => array(
387
- 'type' => 'radio',
388
- 'name' => 'sgpb-custom-button',
389
- 'class' => 'subs-success-open-popup',
390
- 'data-attr-href' => 'sgpb-custom-button-open-popup',
391
- 'value' => 'openPopup'
392
- ),
393
- 'label' => array(
394
- 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
395
- )
396
- ),
397
- array(
398
- 'attr' => array(
399
- 'type' => 'radio',
400
- 'name' => 'sgpb-custom-button',
401
- 'class' => 'sgpb-custom-button-hide-popup',
402
- 'value' => 'hidePopup'
403
- ),
404
- 'label' => array(
405
- 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
406
- )
407
- )
408
- )
409
- );
410
-
411
- $data['popupDimensions'] = array(
412
- 'template' => array(
413
- 'fieldWrapperAttr' => array(
414
- 'class' => 'col-md-7 sgpb-choice-option-wrapper'
415
- ),
416
- 'labelAttr' => array(
417
- 'class' => 'formItem__title'
418
- ),
419
- 'groupWrapperAttr' => array(
420
- 'class' => 'subFormItem sgpb-choice-wrapper sgpb-display-flex sgpb-align-item-center formItem'
421
- )
422
- ),
423
- 'buttonPosition' => 'right',
424
- 'nextNewLine' => true,
425
- 'fields' => array(
426
- array(
427
- 'attr' => array(
428
- 'type' => 'radio',
429
- 'name' => 'sgpb-popup-dimension-mode',
430
- 'class' => 'test class',
431
- 'data-attr-href' => 'responsive-dimension-wrapper',
432
- 'value' => 'responsiveMode'
433
- ),
434
- 'label' => array(
435
- 'name' => __('Responsive mode', SG_POPUP_TEXT_DOMAIN).':',
436
- 'info' => __('The sizes of the popup will be counted automatically, according to the content size of the popup. You can select the size in percentages, with this mode, to specify the size on the screen', SG_POPUP_TEXT_DOMAIN).'.'
437
- )
438
- ),
439
- array(
440
- 'attr' => array(
441
- 'type' => 'radio',
442
- 'name' => 'sgpb-popup-dimension-mode',
443
- 'class' => 'test class',
444
- 'data-attr-href' => 'custom-dimension-wrapper',
445
- 'value' => 'customMode'
446
- ),
447
- 'label' => array(
448
- 'name' => __('Custom mode', SG_POPUP_TEXT_DOMAIN).':',
449
- 'info' => __('Add your own custom dimensions for the popup to get the exact sizing for your popup', SG_POPUP_TEXT_DOMAIN).'.'
450
- )
451
- )
452
- )
453
- );
454
-
455
- $data['theme'] = array(
456
- array(
457
- 'value' => 'sgpb-theme-1',
458
- 'data-attributes' => array(
459
- 'class' => 'js-sgpb-popup-themes sgpb-popup-theme-1',
460
- 'data-popup-theme-number' => 1
461
- )
462
- ),
463
- array(
464
- 'value' => 'sgpb-theme-2',
465
- 'data-attributes' => array(
466
- 'class' => 'js-sgpb-popup-themes sgpb-popup-theme-2',
467
- 'data-popup-theme-number' => 2
468
- )
469
- ),
470
- array(
471
- 'value' => 'sgpb-theme-3',
472
- 'data-attributes' => array(
473
- 'class' => 'js-sgpb-popup-themes sgpb-popup-theme-3',
474
- 'data-popup-theme-number' => 3
475
- )
476
- ),
477
- array(
478
- 'value' => 'sgpb-theme-4',
479
- 'data-attributes' => array(
480
- 'class' => 'js-sgpb-popup-themes sgpb-popup-theme-4',
481
- 'data-popup-theme-number' => 4
482
- )
483
- ),
484
- array(
485
- 'value' => 'sgpb-theme-5',
486
- 'data-attributes' => array(
487
- 'class' => 'js-sgpb-popup-themes sgpb-popup-theme-5',
488
- 'data-popup-theme-number' => 5
489
- )
490
- ),
491
- array(
492
- 'value' => 'sgpb-theme-6',
493
- 'data-attributes' => array(
494
- 'class' => 'js-sgpb-popup-themes sgpb-popup-theme-6',
495
- 'data-popup-theme-number' => 6
496
- )
497
- )
498
- );
499
-
500
- $data['responsiveDimensions'] = array(
501
- 'auto' => __('Auto', SG_POPUP_TEXT_DOMAIN),
502
- '10' => '10%',
503
- '20' => '20%',
504
- '30' => '30%',
505
- '40' => '40%',
506
- '50' => '50%',
507
- '60' => '60%',
508
- '70' => '70%',
509
- '80' => '80%',
510
- '90' => '90%',
511
- '100' => '100%',
512
- 'fullScreen' => __('Full screen', SG_POPUP_TEXT_DOMAIN)
513
- );
514
-
515
- $data['freeConditionsAdvancedTargeting'] = array(
516
- 'devices' => __('Devices', SG_POPUP_TEXT_DOMAIN),
517
- 'user-status' => __('User Status', SG_POPUP_TEXT_DOMAIN),
518
- 'after-x' => __('After x pages visit', SG_POPUP_TEXT_DOMAIN),
519
- 'user-role' => __('User Role', SG_POPUP_TEXT_DOMAIN),
520
- 'detect-by-url' => __('Referral URL detection', SG_POPUP_TEXT_DOMAIN),
521
- 'cookie-detection' => __('Cookie Detection', SG_POPUP_TEXT_DOMAIN),
522
- 'operation-system' => __('Operating System', SG_POPUP_TEXT_DOMAIN),
523
- 'browser-detection' => __('Web Browser', SG_POPUP_TEXT_DOMAIN),
524
- 'query-string' => __('URL Query String', SG_POPUP_TEXT_DOMAIN)
525
- );
526
-
527
- $data['freeConditionsGeoTargeting'] = array(
528
- 'countries' => __('Countries', SG_POPUP_TEXT_DOMAIN),
529
- 'cities' => __('Cities', SG_POPUP_TEXT_DOMAIN),
530
- 'states' => __('States', SG_POPUP_TEXT_DOMAIN),
531
- 'visitor-ip' => __('Visitor IP', SG_POPUP_TEXT_DOMAIN)
532
- );
533
-
534
- $data['closeButtonPositions'] = array(
535
- 'topLeft' => __('top-left', SG_POPUP_TEXT_DOMAIN),
536
- 'topRight' => __('top-right', SG_POPUP_TEXT_DOMAIN),
537
- 'bottomLeft' => __('bottom-left', SG_POPUP_TEXT_DOMAIN),
538
- 'bottomRight' => __('bottom-right', SG_POPUP_TEXT_DOMAIN)
539
- );
540
-
541
- $data['closeButtonPositionsFirstTheme'] = array(
542
- 'bottomLeft' => __('bottom-left', SG_POPUP_TEXT_DOMAIN),
543
- 'bottomRight' => __('bottom-right', SG_POPUP_TEXT_DOMAIN)
544
- );
545
-
546
- $data['pxPercent'] = array(
547
- 'px' => 'px',
548
- '%' => '%'
549
- );
550
-
551
- $data['countdownFormat'] = array(
552
- SG_COUNTDOWN_COUNTER_SECONDS_SHOW => 'DD:HH:MM:SS',
553
- SG_COUNTDOWN_COUNTER_SECONDS_HIDE => 'DD:HH:MM'
554
- );
555
-
556
- $data['countdownTimezone'] = self::getPopupTimeZone();
557
-
558
- $data['countdownLanguage'] = array(
559
- 'English' => 'English',
560
- 'German' => 'Deutsche',
561
- 'Spanish' => 'Español',
562
- 'Arabic' => 'عربى',
563
- 'Italian' => 'Italiano',
564
- 'Dutch' => 'Dutch',
565
- 'Norwegian' => 'Norsk',
566
- 'Portuguese' => 'Português',
567
- 'Russian' => 'Русский',
568
- 'Swedish' => 'Svenska',
569
- 'Czech' => 'Čeština',
570
- 'Chinese' => '中文'
571
- );
572
-
573
- $data['weekDaysArray'] = array(
574
- 'Mon' => __('Monday', SG_POPUP_TEXT_DOMAIN),
575
- 'Tue' => __('Tuesday', SG_POPUP_TEXT_DOMAIN),
576
- 'Wed' => __('Wednesday', SG_POPUP_TEXT_DOMAIN),
577
- 'Thu' => __('Thursday', SG_POPUP_TEXT_DOMAIN),
578
- 'Fri' => __('Friday', SG_POPUP_TEXT_DOMAIN),
579
- 'Sat' => __('Saturday', SG_POPUP_TEXT_DOMAIN),
580
- 'Sun' => __('Sunday', SG_POPUP_TEXT_DOMAIN)
581
- );
582
-
583
- $data['messageResize'] = array(
584
- 'both' => __('Both', SG_POPUP_TEXT_DOMAIN),
585
- 'horizontal' => __('Horizontal', SG_POPUP_TEXT_DOMAIN),
586
- 'vertical' => __('Vertical', SG_POPUP_TEXT_DOMAIN),
587
- 'none' => __('None', SG_POPUP_TEXT_DOMAIN),
588
- 'inherit' => __('Inherit', SG_POPUP_TEXT_DOMAIN)
589
- );
590
-
591
- $data['social