Popup Builder – Responsive WordPress Pop up - Version 3.74

Version Description

Current Version of Popup Builder is 3.74

Download this release

Release Info

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

Code changes from version 3.73 to 3.74

Files changed (40) hide show
  1. PopupBuilderInit.php +110 -110
  2. com/boot.php +11 -11
  3. com/classes/Actions.php +1312 -1312
  4. com/classes/Ajax.php +711 -711
  5. com/classes/ConditionBuilder.php +246 -246
  6. com/classes/ConditionCreator.php +660 -660
  7. com/classes/ConvertToNewVersion.php +1274 -1274
  8. com/classes/Feedback.php +146 -146
  9. com/classes/Filters.php +859 -859
  10. com/classes/Installer.php +331 -331
  11. com/classes/Javascript.php +123 -123
  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 +641 -641
  16. com/classes/PopupGroupFilter.php +193 -193
  17. com/classes/PopupInstaller.php +5 -5
  18. com/classes/PopupLoader.php +168 -168
  19. com/classes/PopupType.php +36 -36
  20. com/classes/RegisterPostType.php +489 -489
  21. com/classes/SGPBRequirementsChecker.php +16 -16
  22. com/classes/ScriptsLoader.php +344 -344
  23. com/classes/Style.php +120 -120
  24. com/classes/Updates.php +258 -258
  25. com/classes/dataTable/Subscribers.php +166 -166
  26. com/classes/extension/SgpbIPopupExtension.php +9 -9
  27. com/classes/extension/SgpbPopupExtension.php +344 -344
  28. com/classes/extension/SgpbPopupExtensionActivator.php +108 -108
  29. com/classes/extension/SgpbPopupExtensionRegister.php +118 -102
  30. com/classes/popups/FblikePopup.php +113 -113
  31. com/classes/popups/HtmlPopup.php +38 -38
  32. com/classes/popups/ImagePopup.php +89 -89
  33. com/classes/popups/PopupData.php +20 -20
  34. com/classes/popups/SGPopup.php +1723 -1723
  35. com/classes/popups/SubscriptionPopup.php +685 -685
  36. com/config/config.php +173 -173
  37. com/config/configPackage.php +8 -8
  38. com/config/dataConfig.php +978 -978
  39. com/helpers/AdminHelper.php +2070 -2070
  40. com/helpers/ConfigDataHelper.php +979 -1253
PopupBuilderInit.php CHANGED
@@ -1,110 +1,110 @@
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
- }
38
-
39
- private function includeData()
40
- {
41
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
42
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionActivator.php');
43
- require_once(SG_POPUP_CLASSES_PATH.'Installer.php');
44
- require_once(SG_POPUP_HELPERS_PATH.'AdminHelper.php');
45
- require_once(SG_POPUP_HELPERS_PATH.'Functions.php');
46
- require_once(SG_POPUP_HELPERS_PATH.'ScriptsIncluder.php');
47
- require_once(SG_POPUP_HELPERS_PATH.'PopupBuilderActivePackage.php');
48
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php');
49
- require_once(SG_POPUP_HELPERS_PATH.'MultipleChoiceButton.php');
50
- require_once(SG_POPUP_CLASSES_PATH.'ConditionBuilder.php');
51
- require_once(SG_POPUP_CLASSES_PATH.'ConditionCreator.php');
52
- require_once(SG_POPUP_CLASSES_POPUPS_PATH.'SGPopup.php');
53
- require_once(SG_POPUP_CLASSES_PATH.'ScriptsLoader.php');
54
- require_once(SG_POPUP_CLASSES_PATH.'PopupGroupFilter.php');
55
- require_once(SG_POPUP_CLASSES_PATH.'PopupChecker.php');
56
- require_once(SG_POPUP_CLASSES_PATH.'PopupLoader.php');
57
- require_once(SG_POPUP_CLASSES_PATH.'PopupType.php');
58
- require_once(SG_POPUP_CLASSES_PATH.'MediaButton.php');
59
- require_once(SG_POPUP_CLASSES_PATH.'Style.php');
60
- require_once(SG_POPUP_CLASSES_PATH.'Javascript.php');
61
- require_once(SG_POPUP_CLASSES_PATH.'PopupInstaller.php');
62
- require_once(SG_POPUP_CLASSES_PATH.'RegisterPostType.php');
63
- require_once(SG_POPUP_CLASSES_PATH.'Ajax.php');
64
- require_once(SG_POPUP_CLASSES_PATH.'ConvertToNewVersion.php');
65
- require_once(SG_POPUP_LIBS_PATH.'Reports.php');
66
- require_once(SG_POPUP_CLASSES_PATH.'Filters.php');
67
- require_once(SG_POPUP_CLASSES_PATH.'Actions.php');
68
- require_once(SG_POPUP_LIBS_PATH.'Table.php');
69
- require_once(SG_POPUP_CLASSES_PATH.'Updates.php');
70
- require_once(SG_POPUP_CLASSES_PATH.'NotificationCenter.php');
71
- require_once(SG_POPUP_CLASSES_PATH.'Notification.php');
72
- require_once(SG_POPUP_CLASSES_PATH.'Feedback.php');
73
- }
74
-
75
- public function actions()
76
- {
77
- $this->actions = new Actions();
78
- }
79
-
80
- public function filters()
81
- {
82
- $this->filters = new Filters();
83
- }
84
-
85
- private function registerHooks()
86
- {
87
- register_activation_hook(SG_POPUP_FILE_NAME, array($this, 'activate'));
88
- register_deactivation_hook(SG_POPUP_FILE_NAME, array($this, 'deactivate'));
89
- }
90
-
91
- public function activate()
92
- {
93
- Installer::install();
94
- Installer::registerPlugin();
95
- AdminHelper::filterUserCapabilitiesForTheUserRoles('activate');
96
- }
97
-
98
- public function deactivate()
99
- {
100
- Functions::clearAllTransients();
101
- AdminHelper::removeSelectedTypeOptions('cron');
102
- AdminHelper::filterUserCapabilitiesForTheUserRoles('deactivate');
103
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
104
- $pluginName = SG_POPUP_FILE_NAME;
105
- // remove AWeber extension from registered extensions
106
- SgpbPopupExtensionRegister::remove($pluginName);
107
- }
108
- }
109
-
110
- 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
+ }
38
+
39
+ private function includeData()
40
+ {
41
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
42
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionActivator.php');
43
+ require_once(SG_POPUP_CLASSES_PATH.'Installer.php');
44
+ require_once(SG_POPUP_HELPERS_PATH.'AdminHelper.php');
45
+ require_once(SG_POPUP_HELPERS_PATH.'Functions.php');
46
+ require_once(SG_POPUP_HELPERS_PATH.'ScriptsIncluder.php');
47
+ require_once(SG_POPUP_HELPERS_PATH.'PopupBuilderActivePackage.php');
48
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php');
49
+ require_once(SG_POPUP_HELPERS_PATH.'MultipleChoiceButton.php');
50
+ require_once(SG_POPUP_CLASSES_PATH.'ConditionBuilder.php');
51
+ require_once(SG_POPUP_CLASSES_PATH.'ConditionCreator.php');
52
+ require_once(SG_POPUP_CLASSES_POPUPS_PATH.'SGPopup.php');
53
+ require_once(SG_POPUP_CLASSES_PATH.'ScriptsLoader.php');
54
+ require_once(SG_POPUP_CLASSES_PATH.'PopupGroupFilter.php');
55
+ require_once(SG_POPUP_CLASSES_PATH.'PopupChecker.php');
56
+ require_once(SG_POPUP_CLASSES_PATH.'PopupLoader.php');
57
+ require_once(SG_POPUP_CLASSES_PATH.'PopupType.php');
58
+ require_once(SG_POPUP_CLASSES_PATH.'MediaButton.php');
59
+ require_once(SG_POPUP_CLASSES_PATH.'Style.php');
60
+ require_once(SG_POPUP_CLASSES_PATH.'Javascript.php');
61
+ require_once(SG_POPUP_CLASSES_PATH.'PopupInstaller.php');
62
+ require_once(SG_POPUP_CLASSES_PATH.'RegisterPostType.php');
63
+ require_once(SG_POPUP_CLASSES_PATH.'Ajax.php');
64
+ require_once(SG_POPUP_CLASSES_PATH.'ConvertToNewVersion.php');
65
+ require_once(SG_POPUP_LIBS_PATH.'Reports.php');
66
+ require_once(SG_POPUP_CLASSES_PATH.'Filters.php');
67
+ require_once(SG_POPUP_CLASSES_PATH.'Actions.php');
68
+ require_once(SG_POPUP_LIBS_PATH.'Table.php');
69
+ require_once(SG_POPUP_CLASSES_PATH.'Updates.php');
70
+ require_once(SG_POPUP_CLASSES_PATH.'NotificationCenter.php');
71
+ require_once(SG_POPUP_CLASSES_PATH.'Notification.php');
72
+ require_once(SG_POPUP_CLASSES_PATH.'Feedback.php');
73
+ }
74
+
75
+ public function actions()
76
+ {
77
+ $this->actions = new Actions();
78
+ }
79
+
80
+ public function filters()
81
+ {
82
+ $this->filters = new Filters();
83
+ }
84
+
85
+ private function registerHooks()
86
+ {
87
+ register_activation_hook(SG_POPUP_FILE_NAME, array($this, 'activate'));
88
+ register_deactivation_hook(SG_POPUP_FILE_NAME, array($this, 'deactivate'));
89
+ }
90
+
91
+ public function activate()
92
+ {
93
+ Installer::install();
94
+ Installer::registerPlugin();
95
+ AdminHelper::filterUserCapabilitiesForTheUserRoles('activate');
96
+ }
97
+
98
+ public function deactivate()
99
+ {
100
+ Functions::clearAllTransients();
101
+ AdminHelper::removeSelectedTypeOptions('cron');
102
+ AdminHelper::filterUserCapabilitiesForTheUserRoles('deactivate');
103
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbPopupExtensionRegister.php');
104
+ $pluginName = SG_POPUP_FILE_NAME;
105
+ // remove AWeber extension from registered extensions
106
+ SgpbPopupExtensionRegister::remove($pluginName);
107
+ }
108
+ }
109
+
110
+ 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,1312 +1,1312 @@
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('admin_menu', array($this, 'addSubMenu'));
22
- add_action('admin_menu', array($this, 'supportLinks'), 999);
23
- add_action('admin_head', array($this, 'showPreviewButtonAfterPopupPublish'));
24
- add_action('admin_enqueue_scripts', array($this, 'adminLoadPopups'));
25
- add_action('admin_action_popupSaveAsNew', array($this, 'popupSaveAsNew'));
26
- add_action('admin_post_csv_file', array($this, 'getSubscribersCsvFile'));
27
- add_action('admin_post_sgpb_system_info', array($this, 'getSystemInfoFile'));
28
- add_action('admin_post_sgpbSaveSettings', array($this, 'saveSettings'), 10, 1);
29
- add_action('admin_init', array($this, 'userRolesCaps'));
30
- add_action('admin_notices', array($this, 'pluginNotices'));
31
- add_action('admin_init', array($this, 'pluginLoaded'));
32
- add_action('transition_post_status', array($this, 'deletePopup'), 100, 3);
33
- // activate extensions
34
- add_action('wp_before_admin_bar_render', array($this, 'pluginActivated'), 10, 2);
35
- add_action('admin_head', array($this, 'hidePageBuilderEditButtons'));
36
- add_action('admin_head', array($this, 'hidePublishingActions'));
37
- add_action('add_meta_boxes', array($this, 'popupMetaboxes'), 100);
38
- add_filter('post_updated_messages', array($this, 'popupPublishedMessage'), 1, 1);
39
- add_action('before_delete_post', array($this, 'deleteSubscribersWithPopup'), 1, 1);
40
- add_action('sgpb_duplicate_post', array($this, 'popupCopyPostMetaInfo'), 10, 2);
41
- add_filter('get_sample_permalink_html', array($this, 'removePostPermalink'), 1, 1);
42
- add_action('manage_'.SG_POPUP_POST_TYPE.'_posts_custom_column' , array($this, 'popupsTableColumnsValues'), 10, 2);
43
- add_action('media_buttons', array($this, 'popupMediaButton'));
44
- add_filter('mce_external_plugins', array($this, 'editorButton'), 1, 1);
45
- add_action('admin_enqueue_scripts', array('sgpb\Style', 'enqueueStyles'));
46
- add_action('admin_enqueue_scripts', array('sgpb\Javascript', 'enqueueScripts'));
47
- // this action for popup options saving and popup builder classes save ex from post and page
48
- add_action('save_post', array($this, 'savePost'), 100, 3);
49
- add_action('wp_enqueue_scripts', array($this, 'enqueuePopupBuilderScripts'));
50
- add_filter('sgpbOtherConditions', array($this ,'conditionsSatisfy'), 11, 1);
51
- add_shortcode('sg_popup', array($this, 'popupShortcode'));
52
- add_filter('cron_schedules', array($this, 'cronAddMinutes'), 10, 1);
53
- add_action('sgpb_send_newsletter', array($this, 'newsletterSendEmail'), 10, 1);
54
- add_action('sgpbGetBannerContentOnce', array($this, 'getBannerContent'), 10, 1);
55
- add_action('plugins_loaded', array($this, 'loadTextDomain'));
56
- // for change admin popup list order
57
- add_action('pre_get_posts', array($this, 'preGetPosts'));
58
- add_action('template_redirect', array($this, 'redirectFromPopupPage'));
59
- add_filter('views_edit-popupbuilder', array($this, 'mainActionButtons'), 10, 1);
60
- add_action('wpml_loaded', array($this, 'wpmlRelatedActions'));
61
- new SGPBFeedback();
62
- new SGPBReports();
63
- new Ajax();
64
- }
65
-
66
- public function wpmlRelatedActions()
67
- {
68
- // The actions below will be executed right after WPML is fully configured and loaded.
69
- add_action('admin_head', array($this, 'removeUnneededMetaboxesFromPopups'), 10);
70
- }
71
-
72
- public function removeUnneededMetaboxesFromPopups()
73
- {
74
- if (isset($_GET['post_type']) && $_GET['post_type'] == SG_POPUP_POST_TYPE) {
75
- $exlcudeTrPopupTypes = array(
76
- 'image',
77
- 'video',
78
- 'iframe',
79
- 'recentSales',
80
- 'pdf'
81
- );
82
- $exlcudeTrPopupTypes = apply_filters('sgpbNoMcePopupTypes', $exlcudeTrPopupTypes);
83
- if (isset($_GET['sgpb_type']) && in_array($_GET['sgpb_type'], $exlcudeTrPopupTypes)) {
84
- remove_meta_box('icl_div', SG_POPUP_POST_TYPE, 'side');
85
- }
86
- }
87
- }
88
-
89
- public function deletePopup($newStatus, $oldStatus, $post)
90
- {
91
- $currentPostType = AdminHelper::getCurrentPostType();
92
-
93
- if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
94
- Functions::clearAllTransients();
95
- }
96
- }
97
-
98
- public function showPreviewButtonAfterPopupPublish()
99
- {
100
- $currentPostType = AdminHelper::getCurrentPostType();
101
- if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
102
- echo '<style>
103
- #save-post {
104
- display:none !important;
105
- }
106
- </style>';
107
- }
108
- }
109
-
110
- public function inactiveExtensionNotice()
111
- {
112
- $screen = '';
113
- $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
114
- if ($dontShowLicenseBanner) {
115
- return $screen;
116
- }
117
- $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
118
- $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
119
- if (!$inactive) {
120
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
121
- if ($hasInactiveExtensions) {
122
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
123
- $inactive = 'inactive';
124
- }
125
-
126
- }
127
- $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
128
- $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
129
- if (function_exists('get_current_screen')) {
130
- $screen = get_current_screen();
131
- $screenId = $screen->id;
132
- if ($screenId == SGPB_POPUP_LICENSE_SCREEN) {
133
- $partOfContent = '';
134
- }
135
- }
136
-
137
- if ($hasInactiveExtensions && $inactive == 'inactive') {
138
- $content = '';
139
- ob_start();
140
- ?>
141
- <div id="welcome-panel" class="update-nag sgpb-extensions-notices sgpb-license-notice">
142
- <div class="welcome-panel-content">
143
- <b><?php _e('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN) ?></b>
144
- <br>
145
- <br>
146
- <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>
147
- <b><?php echo $partOfContent; ?></b>
148
- </div>
149
- <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>
150
- <span class="sgpb-dont-show-again-license-notice"><?php _e('Don\'t show again.', SG_POPUP_TEXT_DOMAIN); ?></span>
151
- </div>
152
- <?php
153
- $content = ob_get_clean();
154
-
155
- echo $content;
156
- return true;
157
- }
158
- }
159
-
160
- public function hidePublishingActions() {
161
- $currentPostType = AdminHelper::getCurrentPostType();
162
- if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
163
- return false;
164
- }
165
-
166
- echo '<style>
167
- #misc-publishing-actions .edit-post-status,
168
- #misc-publishing-actions .edit-timestamp,
169
- #misc-publishing-actions .edit-visibility {
170
- display:none !important;
171
- }
172
- </style>';
173
- }
174
-
175
- public function hidePageBuilderEditButtons($postId = 0, $post = array())
176
- {
177
- $currentPostType = AdminHelper::getCurrentPostType();
178
- if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
179
- return false;
180
- }
181
- $excludedPopupTypesFromPageBuildersFunctionality = array(
182
- 'image'
183
- );
184
-
185
- $excludedPopupTypesFromPageBuildersFunctionality = apply_filters('sgpbHidePageBuilderEditButtons', $excludedPopupTypesFromPageBuildersFunctionality);
186
-
187
- $popupType = AdminHelper::getCurrentPopupType();
188
- if (in_array($popupType, $excludedPopupTypesFromPageBuildersFunctionality)) {
189
- echo '<style>
190
- #elementor-switch-mode, #elementor-editor {
191
- display:none !important;
192
- }
193
- </style>';
194
- }
195
- }
196
-
197
- public function getBannerContent()
198
- {
199
- // right metabox banner content
200
- $metaboxBannerContent = AdminHelper::getFileFromURL(SGPB_METABOX_BANNER_CRON_TEXT_URL);
201
- update_option('sgpb-metabox-banner-remote-get', $metaboxBannerContent);
202
-
203
- return true;
204
- }
205
-
206
- public function wpInit()
207
- {
208
- require_once(ABSPATH.'wp-admin/includes/screen.php');
209
- if (!wp_next_scheduled('sgpbGetBannerContentOnce')) {
210
- wp_schedule_event(time(), 'sgpb_banners', 'sgpbGetBannerContentOnce');
211
- }
212
- }
213
-
214
- public function mainActionButtons($views)
215
- {
216
- require_once(SG_POPUP_VIEWS_PATH.'mainActionButtons.php');
217
-
218
- return $views;
219
- }
220
-
221
- /**
222
- * Loads the plugin language files
223
- */
224
- public function loadTextDomain()
225
- {
226
- $popupBuilderLangDir = SG_POPUP_BUILDER_PATH.'/languages/';
227
- $popupBuilderLangDir = apply_filters('popupBuilderLanguagesDirectory', $popupBuilderLangDir);
228
-
229
- $locale = apply_filters('sgpbPluginLocale', get_locale(), SG_POPUP_TEXT_DOMAIN);
230
- $mofile = sprintf('%1$s-%2$s.mo', SG_POPUP_TEXT_DOMAIN, $locale);
231
-
232
- $mofileLocal = $popupBuilderLangDir.$mofile;
233
-
234
- if (file_exists($mofileLocal)) {
235
- // Look in local /wp-content/plugins/popup-builder/languages/ folder
236
- load_textdomain(SG_POPUP_TEXT_DOMAIN, $mofileLocal);
237
- }
238
- else {
239
- // Load the default language files
240
- load_plugin_textdomain(SG_POPUP_TEXT_DOMAIN, false, $popupBuilderLangDir);
241
- }
242
-
243
- }
244
-
245
- public function redirectFromPopupPage()
246
- {
247
- global $post;
248
- $currentPostType = '';
249
-
250
- if (is_object($post)) {
251
- $currentPostType = @$post->post_type;
252
- }
253
- // in some themes global $post returns null
254
- if (empty($currentPostType)) {
255
- global $post_type;
256
- $currentPostType = $post_type;
257
- }
258
- // for editing popup content via page builders on backend
259
- if (!isset($_GET) || empty($_GET)) {
260
- if (!is_admin() && SG_POPUP_POST_TYPE == $currentPostType && !is_preview()) {
261
- // it's for seo optimization
262
- status_header(301);
263
- $homeURL = home_url();
264
- wp_redirect($homeURL);
265
- exit();
266
- }
267
- }
268
- }
269
-
270
- public function preGetPosts($query)
271
- {
272
- if (!is_admin() || !isset($_GET['post_type']) || $_GET['post_type'] != SG_POPUP_POST_TYPE) {
273
- return false;
274
- }
275
-
276
- // change default order by id and desc
277
- if (!isset($_GET['orderby'])) {
278
- $query->set('orderby', 'ID');
279
- $query->set('order', 'desc');
280
- }
281
- $query = apply_filters('sgpbPreGetPosts', $query);
282
-
283
- return true;
284
- }
285
-
286
- public function pluginNotices()
287
- {
288
- if (function_exists('get_current_screen')) {
289
- $screen = get_current_screen();
290
- $screenId = $screen->id;
291
- if ($screenId == 'edit-popupbuilder') {
292
- $notificationsObj = new SGPBNotificationCenter();
293
- echo $notificationsObj->displayNotifications();
294
- }
295
- }
296
- $extensions = AdminHelper::getAllActiveExtensions();
297
- $updated = get_option('sgpb_extensions_updated');
298
-
299
- $content = '';
300
-
301
- // if popup builder has the old version
302
- if (!get_option('SG_POPUP_VERSION')) {
303
- return $content;
304
- }
305
-
306
- $alertProblem = get_option('sgpb_alert_problems');
307
- // for old users show alert about problems
308
- if (!$alertProblem) {
309
- echo AdminHelper::renderAlertProblem();
310
- }
311
-
312
- // Don't show the banner if there's not any extension of Popup Builder or if the user has clicked "don't show"
313
- if (empty($extensions) || $updated) {
314
- return $content;
315
- }
316
-
317
- ob_start();
318
- ?>
319
- <div id="welcome-panel" class="update-nag sgpb-extensions-notices">
320
- <div class="welcome-panel-content">
321
- <?php echo AdminHelper::renderExtensionsContent(); ?>
322
- </div>
323
- </div>
324
- <?php
325
- $content = ob_get_clean();
326
-
327
- echo $content;
328
- return true;
329
- }
330
-
331
- private function registerImporter()
332
- {
333
- require_once SG_POPUP_LIBS_PATH.'Importer.php';
334
- $importer = new WP_Import();
335
- register_importer(SG_POPUP_POST_TYPE, SG_POPUP_POST_TYPE, __('Importer', SG_POPUP_TEXT_DOMAIN), array($importer, 'dispatch'));
336
- }
337
-
338
- public function pluginLoaded()
339
- {
340
- $this->registerImporter();
341
- $versionPopup = get_option('SG_POPUP_VERSION');
342
- $convert = get_option('sgpbConvertToNewVersion');
343
- $unsubscribeColumnFixed = get_option('sgpbUnsubscribeColumnFixed');
344
- AdminHelper::makeRegisteredPluginsStaticPathsToDynamic();
345
-
346
- if (!$unsubscribeColumnFixed) {
347
- AdminHelper::addUnsubscribeColumn();
348
- update_option('sgpbUnsubscribeColumnFixed', 1);
349
- delete_option('sgpbUnsubscribeColumn');
350
- }
351
-
352
- if ($versionPopup && !$convert) {
353
- update_option('sgpbConvertToNewVersion', 1);
354
- ConvertToNewVersion::convert();
355
- Installer::registerPlugin();
356
- }
357
- }
358
-
359
- public function popupMediaButton()
360
- {
361
- if (!$this->mediaButton) {
362
- $this->mediaButton = true;
363
- self::enqueueScriptsForPageBuilders();
364
- if (function_exists('get_current_screen')) {
365
- $screen = get_current_screen();
366
- if (!empty($screen)) {
367
- echo new MediaButton();
368
- }
369
- }
370
- }
371
- }
372
-
373
- public function editorButton($plugins)
374
- {
375
- if (empty($this->mediaButton)) {
376
- $this->mediaButton = true;
377
- add_action('admin_footer', function() {
378
- self::enqueueScriptsForPageBuilders();
379
- echo new MediaButton(false);
380
- });
381
- }
382
-
383
- return $plugins;
384
- }
385
-
386
- public static function enqueueScriptsForPageBuilders()
387
- {
388
- require_once(ABSPATH.'wp-admin/includes/screen.php');
389
- global $post;
390
- if (function_exists('get_current_screen')) {
391
- $screen = get_current_screen();
392
- if ((!empty($screen->id) && $screen->id == SG_POPUP_POST_TYPE) || !empty($post)) {
393
- if (!isset($_GET['fl_builder'])) {
394
- Javascript::enqueueScripts('post-new.php');
395
- Style::enqueueStyles('post-new.php');
396
- }
397
- }
398
- }
399
- else if (isset($_GET['fl_builder'])) {
400
- Javascript::enqueueScripts('post-new.php');
401
- Style::enqueueStyles('post-new.php');
402
- }
403
- }
404
-
405
- public function userRolesCaps()
406
- {
407
- $userSavedRoles = get_option('sgpb-user-roles');
408
-
409
- if (!$userSavedRoles) {
410
- $userSavedRoles = array('administrator');
411
- }
412
- else {
413
- array_push($userSavedRoles, 'administrator');
414
- }
415
-
416
- foreach ($userSavedRoles as $theRole) {
417
- $role = get_role($theRole);
418
- if (empty($role)) {
419
- continue;
420
- }
421
-
422
- $role->add_cap('read');
423
- $role->add_cap('read_post');
424
- $role->add_cap('read_private_sgpb_popups');
425
- $role->add_cap('edit_sgpb_popup');
426
- $role->add_cap('edit_sgpb_popups');
427
- $role->add_cap('edit_others_sgpb_popups');
428
- $role->add_cap('edit_published_sgpb_popups');
429
- $role->add_cap('publish_sgpb_popups');
430
- $role->add_cap('delete_sgpb_popups');
431
- $role->add_cap('delete_published_posts');
432
- $role->add_cap('delete_others_sgpb_popups');
433
- $role->add_cap('delete_private_sgpb_popups');
434
- $role->add_cap('delete_private_sgpb_popup');
435
- $role->add_cap('delete_published_sgpb_popups');
436
-
437
- // For popup builder sub-menus and terms
438
- $role->add_cap('sgpb_manage_options');
439
- $role->add_cap('manage_popup_terms');
440
- $role->add_cap('manage_popup_categories_terms');
441
- $role = apply_filters('sgpbUserRoleCap', $role);
442
- }
443
-
444
- return true;
445
- }
446
-
447
- public function pluginActivated()
448
- {
449
- if (!get_option('sgpbActivateExtensions') && SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
450
- $obj = new PopupExtensionActivator();
451
- $obj->activate();
452
- update_option('sgpbActivateExtensions', 1);
453
- }
454
- }
455
-
456
- public function popupShortcode($args, $content)
457
- {
458
- if (empty($args) || empty($args['id'])) {
459
- return $content;
460
- }
461
-
462
- $oldShortcode = isset($args['event']) && $args['event'] === 'onload';
463
- $isInherit = isset($args['event']) && $args['event'] == 'inherit';
464
- $event = '';
465
-
466
- $shortcodeContent = '';
467
- $argsId = $popupId = (int)$args['id'];
468
-
469
- // for old popups
470
- if (function_exists('sgpb\sgpGetCorrectPopupId')) {
471
- $popupId = sgpGetCorrectPopupId($popupId);
472
- }
473
-
474
- $popup = SGPopup::find($popupId);
475
- $popup = apply_filters('sgpbShortCodePopupObj', $popup);
476
-
477
- $event = preg_replace('/on/', '', @$args['event']);
478
- // when popup does not exists or popup post status it's not publish ex when popup in trash
479
- if (empty($popup) || (!is_object($popup) && $popup != 'publish')) {
480
- return $content;
481
- }
482
- $alreadySavedEvents = $popup->getEvents();
483
- $loadableMode = $popup->getLoadableModes();
484
-
485
- if (!isset($args['event']) && isset($args['insidepopup'])) {
486
- unset($args['insidepopup']);
487
- $event = 'insideclick';
488
- $insideShortcodeKey = $popupId.$event;
489
-
490
- // for prevent infinity chain
491
- if (is_array($this->insideShortcodes) && in_array($insideShortcodeKey, $this->insideShortcodes)) {
492
- $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
493
-
494
- return $shortcodeContent;
495
- }
496
- $this->insideShortcodes[] = $insideShortcodeKey;
497
- }
498
- // if no event attribute is set, or old shortcode
499
- if (!isset($args['event']) || $oldShortcode || $isInherit) {
500
- $loadableMode = $popup->getLoadableModes();
501
- if (!empty($content)) {
502
- $alreadySavedEvents = false;
503
- }
504
- // for old popup, after the update, there aren't any events
505
- if (empty($alreadySavedEvents)) {
506
- $event = '';
507
- if (!empty($content)) {
508
- $event = 'click';
509
- }
510
- if (!empty($args['event'])) {
511
- $event = $args['event'];
512
- }
513
- $event = preg_replace('/on/', '', $event);
514
- $popup->setEvents(array($event));
515
- }
516
- if (empty($loadableMode)) {
517
- $loadableMode = array();
518
- }
519
- $loadableMode['option_event'] = true;
520
- }
521
- else {
522
- $event = $args['event'];
523
- $event = preg_replace('/on/', '', $event);
524
- $popup->setEvents(array($event));
525
- }
526
-
527
- $popup->setLoadableModes($loadableMode);
528
- $scriptsLoader = new ScriptsLoader();
529
- $loadablePopups = array($popup);
530
- $groupObj = new PopupGroupFilter();
531
- $groupObj->setPopups(array($popup));
532
- $loadablePopups = $groupObj->filter();
533
- $scriptsLoader->setLoadablePopups($loadablePopups);
534
- $scriptsLoader->loadToFooter();
535
-
536
- if (!empty($content)) {
537
- $matches = SGPopup::getPopupShortcodeMatchesFromContent($content);
538
- if (!empty($matches)) {
539
- foreach ($matches[0] as $key => $value) {
540
- $attrs = shortcode_parse_atts($matches[3][$key]);
541
- if (empty($attrs['id'])) {
542
- continue;
543
- }
544
- $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $attrs['id'], $attrs['event'], $attrs);
545
- break;
546
- }
547
- }
548
- }
549
-
550
- if (isset($event) && $event != 'onload' && !empty($content)) {
551
- $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
552
- }
553
- $shortcodeContent = apply_filters('sgpbPopupShortCodeContent', $shortcodeContent);
554
-
555
- return do_shortcode($shortcodeContent);
556
- }
557
-
558
- public function deleteSubscribersWithPopup($postId)
559
- {
560
- global $post_type;
561
-
562
- if ($post_type == SG_POPUP_POST_TYPE) {
563
- AdminHelper::deleteSubscriptionPopupSubscribers($postId);
564
- }
565
- }
566
-
567
- public function cronAddMinutes($schedules)
568
- {
569
- $schedules['sgpb_newsletter_send_every_minute'] = array(
570
- 'interval' => SGPB_CRON_REPEAT_INTERVAL * 60,
571
- 'display' => __('Once Every Minute', SG_POPUP_TEXT_DOMAIN)
572
- );
573
-
574
- $schedules['sgpb_banners'] = array(
575
- 'interval' => SGPB_TRANSIENT_TIMEOUT_WEEK,
576
- 'display' => __('Once Every Week', SG_POPUP_TEXT_DOMAIN)
577
- );
578
-
579
- $schedules = apply_filters('sgpbCronTimeoutSettings', $schedules);
580
-
581
- return $schedules;
582
- }
583
-
584
- public function newsletterSendEmail()
585
- {
586
- global $wpdb;
587
- $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
588
-
589
- if (empty($newsletterOptions)) {
590
- wp_clear_scheduled_hook('sgpb_send_newsletter');
591
- }
592
- $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
593
- $subscriptionFormTitle = get_the_title($subscriptionFormId);
594
- $emailsInFlow = (int)$newsletterOptions['emailsInFlow'];
595
- $mailSubject = $newsletterOptions['newsletterSubject'];
596
- $fromEmail = $newsletterOptions['fromEmail'];
597
- $emailMessage = $newsletterOptions['messageBody'];
598
-
599
- $allAvailableShortcodes = array();
600
- $allAvailableShortcodes['patternFirstName'] = '/\[First name]/';
601
- $allAvailableShortcodes['patternLastName'] = '/\[Last name]/';
602
- $allAvailableShortcodes['patternBlogName'] = '/\[Blog name]/';
603
- $allAvailableShortcodes['patternUserName'] = '/\[User name]/';
604
- $allAvailableShortcodes['patternUnsubscribe'] = '';
605
-
606
- $pattern = "/\[(\[?)(Unsubscribe)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/";
607
- preg_match($pattern, $emailMessage, $matches);
608
- $title = __('Unsubscribe', SG_POPUP_TEXT_DOMAIN);
609
- if ($matches) {
610
- $patternUnsubscribe = $matches[0];
611
- // If user didn't change anything inside the [unsubscribe] shortcode $matches[2] will be equal to 'Unsubscribe'
612
- if ($matches[2] == 'Unsubscribe') {
613
- $pattern = '/\s(\w+?)="(.+?)"]/';
614
- preg_match($pattern, $matches[0], $matchesTitle);
615
- if (!empty($matchesTitle[2])) {
616
- $title = AdminHelper::removeAllNonPrintableCharacters($matchesTitle[2], 'Unsubscribe');
617
- }
618
- }
619
- $allAvailableShortcodes['patternUnsubscribe'] = $patternUnsubscribe;
620
- }
621
-
622
- // When email is not valid we don't continue
623
- if (!preg_match('/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/', $fromEmail)) {
624
- wp_clear_scheduled_hook('sgpb_send_newsletter');
625
- return false;
626
- }
627
-
628
- $selectionQuery = 'SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
629
- $selectionQuery = apply_filters('sgpbUserSelectionQuery', $selectionQuery);
630
- $sql = $wpdb->prepare($selectionQuery .' and subscriptionType = %d limit 1', $subscriptionFormId);
631
-
632
- $result = $wpdb->get_row($sql, ARRAY_A);
633
- $currentStateEmailId = (int)$result['id'];
634
- $getTotalSql = $wpdb->prepare('SELECT count(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE unsubscribed = 0 and subscriptionType = %d', $subscriptionFormId);
635
- $totalSubscribers = $wpdb->get_var($getTotalSql);
636
-
637
- // $currentStateEmailId == 0 when all emails status = 1
638
- if ($currentStateEmailId == 0) {
639
- // Clear schedule hook
640
- $headers = 'MIME-Version: 1.0'."\r\n";
641
- $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n";
642
- $successTotal = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
643
- if (!$successTotal) {
644
- $successTotal = 0;
645
- }
646
- $failedTotal = $totalSubscribers - $successTotal;
647
-
648
- $emailMessageCustom = __('Your mail list %s delivered successfully!
649
- %d of the %d emails succeeded, %d failed.
650
- For more details, please download log file inside the plugin.
651
- This email was generated via Popup Builder plugin.', SG_POPUP_TEXT_DOMAIN);
652
- $emailMessageCustom = sprintf($emailMessageCustom, $subscriptionFormTitle, $successTotal, $totalSubscribers, $failedTotal);
653
-
654
- wp_mail($fromEmail, $subscriptionFormTitle.' list has been successfully delivered!', $emailMessageCustom, $headers);
655
- delete_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
656
- wp_clear_scheduled_hook('sgpb_send_newsletter');
657
- return;
658
- }
659
-
660
- $getAllDataSql = 'SELECT id, firstName, lastName, email FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
661
- $getAllDataSql = apply_filters('sgpbUserSelectionQuery', $getAllDataSql);
662
- $getAllDataSql = $wpdb->prepare($getAllDataSql .' and id >= %d and subscriptionType = %s limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
663
- $subscribers = $wpdb->get_results($getAllDataSql, ARRAY_A);
664
-
665
- $subscribers = apply_filters('sgpNewsletterSendingSubscribers', $subscribers);
666
-
667
- $blogInfo = get_bloginfo();
668
- $headers = array(
669
- 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
670
- 'MIME-Version: 1.0' ,
671
- 'Content-type: text/html; charset=UTF-8'
672
- );
673
-
674
- foreach ($subscribers as $subscriber) {
675
- $replacementId = $subscriber['id'];
676
- $allAvailableShortcodes = apply_filters('sgpbNewsletterShortcodes', $allAvailableShortcodes, $subscriptionFormId, $replacementId);
677
- $replacementFirstName = $subscriber['firstName'];
678
- $replacementLastName = $subscriber['lastName'];
679
- $replacementBlogName = $newsletterOptions['blogname'];
680
- $replacementUserName = $newsletterOptions['username'];
681
- $replacementEmail = $subscriber['email'];
682
- $replacementUnsubscribe = get_home_url();
683
- $replacementUnsubscribe .= '?sgpbUnsubscribe='.md5($replacementId.$replacementEmail);
684
- $replacementUnsubscribe .= '&email='.$subscriber['email'];
685
- $replacementUnsubscribe .= '&popup='.$subscriptionFormId;
686
- $replacementUnsubscribe = '<br><a href="'.$replacementUnsubscribe.'">'.$title.'</a>';
687
-
688
- // Replace First name and Last name from email message
689
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternFirstName'], $replacementFirstName, $emailMessage);
690
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternLastName'], $replacementLastName, $emailMessageCustom);
691
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternBlogName'], $replacementBlogName, $emailMessageCustom);
692
- $emailMessageCustom = preg_replace($allAvailableShortcodes['patternUserName'], $replacementUserName, $emailMessageCustom);
693
- $emailMessageCustom = str_replace($allAvailableShortcodes['patternUnsubscribe'], $replacementUnsubscribe, $emailMessageCustom);
694
- if (!empty($allAvailableShortcodes['extraShortcodesWithValues'])) {
695
- $customFields = $allAvailableShortcodes['extraShortcodesWithValues'];
696
- foreach ($customFields as $customFieldKey => $customFieldValue) {
697
- $finalShortcode = '/\['.$customFieldKey.']/';
698
- $emailMessageCustom = preg_replace($finalShortcode, $customFieldValue, $emailMessageCustom);
699
- }
700
- }
701
- $emailMessageCustom = stripslashes($emailMessageCustom);
702
-
703
- $emailMessageCustom = apply_filters('sgpNewsletterSendingMessage', $emailMessageCustom);
704
- $mailStatus = wp_mail($subscriber['email'], $mailSubject, $emailMessageCustom, $headers);
705
- if (!$mailStatus) {
706
- $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'));
707
- $wpdb->query($errorLogSql);
708
- continue;
709
- }
710
-
711
- $successCount = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
712
- if (!$successCount) {
713
- update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, 1);
714
- }
715
- else {
716
- update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, ++$successCount);
717
- }
718
- }
719
- // Update the status of all the sent mails
720
- $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 1 where id >= %d and subscriptionType = %d limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
721
- $wpdb->query($updateStatusQuery);
722
- }
723
-
724
- private function unsubscribe($params = array())
725
- {
726
- AdminHelper::deleteUserFromSubscribers($params);
727
- }
728
-
729
- public function enqueuePopupBuilderScripts()
730
- {
731
- // for old popups
732
- if (get_option('SG_POPUP_VERSION')) {
733
- ConvertToNewVersion::saveCustomInserted();
734
- }
735
-
736
- $popupLoaderObj = PopupLoader::instance();
737
- if (is_object($popupLoaderObj)) {
738
- $popupLoaderObj->loadPopups();
739
- }
740
- }
741
-
742
- public function adminLoadPopups($hook)
743
- {
744
- $allowedPages = array();
745
- $allowedPages = apply_filters('sgpbAdminLoadedPages', $allowedPages);
746
-
747
- if (!empty($allowedPages) && is_array($allowedPages) && in_array($hook, $allowedPages)) {
748
- $scriptsLoader = new ScriptsLoader();
749
- $scriptsLoader->setIsAdmin(true);
750
- $scriptsLoader->loadToFooter();
751
- }
752
- }
753
-
754
- public function postTypeInit()
755
- {
756
- if (isset($_POST['sgpb-is-preview']) && $_POST['sgpb-is-preview'] == 1) {
757
- $postId = $_POST['post_ID'];
758
- $post = get_post($postId);
759
- $this->savePost($postId, $post, false);
760
- }
761
- $adminUrl = admin_url();
762
-
763
- if (isset($_GET['page']) && $_GET['page'] == 'PopupBuilder') {
764
- _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);
765
- wp_die();
766
- }
767
-
768
- $unsubscribeArgs = $this->collectUnsubscriberArgs();
769
- if (!empty($unsubscribeArgs)) {
770
- $this->unsubscribe($unsubscribeArgs);
771
- }
772
-
773
- AdminHelper::removeUnnecessaryCodeFromPopups();
774
-
775
- $this->customPostTypeObj = new RegisterPostType();
776
- }
777
-
778
- public function collectUnsubscriberArgs()
779
- {
780
- if (!isset($_GET['sgpbUnsubscribe'])) {
781
- return false;
782
- }
783
- $args = array();
784
- if (isset($_GET['sgpbUnsubscribe'])) {
785
- $args['token'] = $_GET['sgpbUnsubscribe'];
786
- }
787
- if (isset($_GET['email'])) {
788
- $args['email'] = $_GET['email'];
789
- }
790
- if (isset($_GET['popup'])) {
791
- $args['popup'] = $_GET['popup'];
792
- }
793
-
794
- return $args;
795
- }
796
-
797
- public function addSubMenu()
798
- {
799
- // We need to check license keys and statuses before adding new menu "License" item
800
- new Updates();
801
-
802
- $this->customPostTypeObj->addSubMenu();
803
- }
804
-
805
- public function supportLinks()
806
- {
807
- if (SGPB_POPUP_PKG == SGPB_POPUP_PKG_FREE) {
808
- if (method_exists($this->customPostTypeObj, 'supportLinks')) {
809
- $this->customPostTypeObj->supportLinks();
810
- }
811
- }
812
- }
813
-
814
- public function popupMetaboxes()
815
- {
816
- $this->customPostTypeObj->addPopupMetaboxes();
817
- }
818
-
819
- public function savePost($postId = 0, $post = array(), $update = false)
820
- {
821
- $allowToAction = AdminHelper::userCanAccessTo();
822
- Functions::clearAllTransients();
823
- $postData = SGPopup::parsePopupDataFromData($_POST);
824
- $saveMode = '';
825
- $postData['sgpb-post-id'] = $postId;
826
- // If preview mode
827
- if (isset($postData['sgpb-is-preview']) && $postData['sgpb-is-preview'] == 1) {
828
- $saveMode = '_preview';
829
- SgpbPopupConfig::popupTypesInit();
830
- SgpbDataConfig::init();
831
- // published popup
832
- if (empty($post)) {
833
- global $post;
834
- $postId = $post->ID;
835
- }
836
- if ($post->post_status != 'draft') {
837
- $posts = array();
838
- $popupContent = $post->post_content;
839
-
840
- $query = new WP_Query(
841
- array(
842
- 'post_parent' => $postId,
843
- 'posts_per_page' => - 1,
844
- 'post_type' => 'revision',
845
- 'post_status' => 'inherit'
846
- )
847
- );
848
- $query = apply_filters('sgpbSavePostQuery', $query);
849
-
850
- while ($query->have_posts()) {
851
- $query->the_post();
852
- if (empty($posts)) {
853
- $posts[] = $post;
854
- }
855
- }
856
- if (!empty($posts[0])) {
857
- $popup = $posts[0];
858
- $popupContent = $popup->post_content;
859
- }
860
- }
861
- }
862
-
863
-
864
- if (empty($post)) {
865
- $saveMode = '';
866
- }
867
- /* In preview mode saveMode should be true*/
868
- if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
869
- if (!$allowToAction) {
870
- wp_redirect(get_home_url());
871
- exit();
872
- }
873
- if (!empty($postData['sgpb-type'])) {
874
- $popupType = $postData['sgpb-type'];
875
- $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
876
- $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
877
- require_once($popupClassPath.$popupClassName.'.php');
878
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
879
-
880
- $popupClassName::create($postData, $saveMode, 1);
881
- }
882
- }
883
- else {
884
- $content = get_post_field('post_content', $postId);
885
- SGPopup::deletePostCustomInsertedData($postId);
886
- SGPopup::deletePostCustomInsertedEvents($postId);
887
- /*We detect all the popups that were inserted as a custom ones, in the content.*/
888
- SGPopup::savePopupsFromContentClasses($content, $post);
889
- }
890
- }
891
-
892
- /**
893
- * Check Popup is satisfy for popup condition
894
- *
895
- * @param array $args
896
- *
897
- * @return array
898
- *
899
- *@since 1.0.0
900
- *
901
- */
902
- public function conditionsSatisfy($args = array())
903
- {
904
- if (isset($args['status']) && $args['status'] === false) {
905
- return $args;
906
- }
907
- $args['status'] = PopupChecker::checkOtherConditionsActions($args);
908
-
909
- return $args;
910
- }
911
-
912
- public function popupsTableColumnsValues($column, $postId)
913
- {
914
- $postId = (int)$postId;// Convert to int for security reasons
915
- $switchButton = '';
916
- $isActive = '';
917
- global $post_type;
918
- if ($postId) {
919
- $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
920
- $popup = SGPopup::find($postId, $args);
921
- }
922
-
923
- if (empty($popup) && $post_type == SG_POPUP_POST_TYPE) {
924
- return false;
925
- }
926
-
927
- if ($column == 'shortcode') {
928
- echo '<input type="text" onfocus="this.select();" readonly value="[sg_popup id='.$postId.']" class="large-text code">';
929
- }
930
- if ($column == 'className') {
931
- echo '<input type="text" onfocus="this.select();" readonly value="sg-popup-id-'.esc_attr($postId).'" class="large-text code">';
932
- }
933
- else if ($column == 'counter') {
934
- $count = $popup->getPopupOpeningCountById($postId);
935
- echo '<div class="sgpb-counter-wrapper"><div class="sgpb-dashboard-popup-count-wrapper">'.$count.'</div>'.'<input onclick="SGPBBackend.resetCount('.$postId.', true);" type="button" name="" class="button sgpb-reset-count-btn" value="'.__('reset', SG_POPUP_TEXT_DOMAIN).'"></div>';
936
- }
937
- else if ($column == 'type') {
938
- global $SGPB_POPUP_TYPES;
939
- $type = $popup->getType();
940
- if (isset($SGPB_POPUP_TYPES['typeLabels'][$type])) {
941
- $type = $SGPB_POPUP_TYPES['typeLabels'][$type];
942
- }
943
- echo $type;
944
- }
945
- else if ($column == 'onOff') {
946
- $popupPostStatus = get_post_status($postId);
947
- if ($popupPostStatus == 'publish' || $popupPostStatus == 'draft') {
948
- $isActive = $popup->getOptionValue('sgpb-is-active', true);
949
- }
950
- $switchButton .= '<label class="sgpb-switch">';
951
- $switchButton .= '<input class="sg-switch-checkbox" data-switch-id="'.$postId.'" type="checkbox" '.$isActive.'>';
952
- $switchButton .= '<div class="sgpb-slider sgpb-round"></div>';
953
- $switchButton .= '</label>';
954
- echo $switchButton;
955
- }
956
- }
957
-
958
- /*
959
- * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
960
- * then redirects to the post list
961
- */
962
- public function popupSaveAsNew($status = '')
963
- {
964
- if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'popupSaveAsNew' == $_REQUEST['action']))) {
965
- wp_die(esc_html__('No post to duplicate has been supplied!', SG_POPUP_TEXT_DOMAIN));
966
- }
967
- // Get the original post
968
- $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
969
-
970
- check_admin_referer('duplicate-post_'.$id);
971
-
972
- $post = get_post($id);
973
-
974
- // Copy the post and insert it
975
- if (isset($post) && $post != null) {
976
- $newId = $this->popupCreateDuplicate($post, $status);
977
- $postType = $post->post_type;
978
-
979
- if ($status == '') {
980
- $sendBack = wp_get_referer();
981
- if (!$sendBack ||
982
- strpos($sendBack, 'post.php') !== false ||
983
- strpos($sendBack, 'post-new.php') !== false) {
984
- if ('attachment' == $postType) {
985
- $sendBack = admin_url('upload.php');
986
- }
987
- else {
988
- $sendBack = admin_url('edit.php');
989
- if (!empty($postType)) {
990
- $sendBack = add_query_arg('post_type', $postType, $sendBack);
991
- }
992
- }
993
- }
994
- else {
995
- $sendBack = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'cloned', 'ids'), $sendBack);
996
- }
997
- // Redirect to the post list screen
998
- wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), $sendBack));
999
- }
1000
- else {
1001
- // Redirect to the edit screen for the new draft post
1002
- wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), admin_url('post.php?action=edit&post='.$newId)));
1003
- }
1004
- exit;
1005
-
1006
- }
1007
- else {
1008
- wp_die(esc_html__('Copy creation failed, could not find original:', SG_POPUP_TEXT_DOMAIN).' '.htmlspecialchars($id));
1009
- }
1010
- }
1011
-
1012
- /**
1013
- * Create a duplicate from a post
1014
- */
1015
- public function popupCreateDuplicate($post, $status = '', $parent_id = '')
1016
- {
1017
- $newPostStatus = (empty($status))? $post->post_status: $status;
1018
-
1019
- if ($post->post_type != 'attachment') {
1020
- $title = $post->post_title;
1021
- if ($title == '') {
1022
- // empty title
1023
- $title = __('(no title) (clone)');
1024
- }
1025
- else {
1026
- $title .= ' '.__('(clone)');
1027
- }
1028
-
1029
- if ('publish' == $newPostStatus || 'future' == $newPostStatus) {
1030
- // check if the user has the right capability
1031
- if (is_post_type_hierarchical($post->post_type)) {
1032
- if (!current_user_can('publish_pages')) {
1033
- $newPostStatus = 'pending';
1034
- }
1035
- }
1036
- else {
1037
- if (!current_user_can('publish_posts')) {
1038
- $newPostStatus = 'pending';
1039
- }
1040
- }
1041
- }
1042
- }
1043
-
1044
- $newPostAuthor = wp_get_current_user();
1045
- $newPostAuthorId = $newPostAuthor->ID;
1046
- // check if the user has the right capability
1047
- if (is_post_type_hierarchical($post->post_type)) {
1048
- if (current_user_can('edit_others_pages')) {
1049
- $newPostAuthorId = $post->post_author;
1050
- }
1051
- }
1052
- else {
1053
- if (current_user_can('edit_others_posts')) {
1054
- $newPostAuthorId = $post->post_author;
1055
- }
1056
- }
1057
-
1058
- $newPost = array(
1059
- 'menu_order' => $post->menu_order,
1060
- 'comment_status' => $post->comment_status,
1061
- 'ping_status' => $post->ping_status,
1062
- 'post_author' => $newPostAuthorId,
1063
- 'post_content' => $post->post_content,
1064
- 'post_content_filtered' => $post->post_content_filtered,
1065
- 'post_excerpt' => $post->post_excerpt,
1066
- 'post_mime_type' => $post->post_mime_type,
1067
- 'post_parent' => $newPostParent = empty($parent_id)? $post->post_parent : $parent_id,
1068
- 'post_password' => $post->post_password,
1069
- 'post_status' => $newPostStatus,
1070
- 'post_title' => $title,
1071
- 'post_type' => $post->post_type,
1072
- );
1073
-
1074
- $newPost['post_date'] = $newPostDate = $post->post_date;
1075
- $newPost['post_date_gmt'] = get_gmt_from_date($newPostDate);
1076
- $newPostId = wp_insert_post(wp_slash($newPost));
1077
-
1078
- // If the copy is published or scheduled, we have to set a proper slug.
1079
- if ($newPostStatus == 'publish' || $newPostStatus == 'future') {
1080
- $postName = $post->post_name;
1081
- $postName = wp_unique_post_slug($postName, $newPostId, $newPostStatus, $post->post_type, $newPostParent);
1082
-
1083
- $newPost = array();
1084
- $newPost['ID'] = $newPostId;
1085
- $newPost['post_name'] = $postName;
1086
-
1087
- // Update the post into the database
1088
- wp_update_post(wp_slash($newPost));
1089
- }
1090
-
1091
- // If you have written a plugin which uses non-WP database tables to save
1092
- // information about a post you can hook this action to dupe that data.
1093
- if ($post->post_type == 'page' || is_post_type_hierarchical($post->post_type)) {
1094
- do_action('dp_duplicate_page', $newPostId, $post, $status);
1095
- }
1096
- else {
1097
- do_action('sgpb_duplicate_post', $newPostId, $post, $status);
1098
- }
1099
-
1100
- delete_post_meta($newPostId, '_sgpb_original');
1101
- add_post_meta($newPostId, '_sgpb_original', $post->ID);
1102
-
1103
- return $newPostId;
1104
- }
1105
-
1106
- /**
1107
- * Copy the meta information of a post to another post
1108
- */
1109
- public function popupCopyPostMetaInfo($newId, $post)
1110
- {
1111
- $postMetaKeys = get_post_custom_keys($post->ID);
1112
- $metaBlacklist = '';
1113
-
1114
- if (empty($postMetaKeys) || !is_array($postMetaKeys)) {
1115
- return;
1116
- }
1117
- $metaBlacklist = explode(',', $metaBlacklist);
1118
- $metaBlacklist = array_filter($metaBlacklist);
1119
- $metaBlacklist = array_map('trim', $metaBlacklist);
1120
- $metaBlacklist[] = '_edit_lock';
1121
- $metaBlacklist[] = '_edit_last';
1122
- $metaBlacklist[] = '_wp_page_template';
1123
- $metaBlacklist[] = '_thumbnail_id';
1124
-
1125
- $metaBlacklist = apply_filters('duplicate_post_blacklist_filter' , $metaBlacklist);
1126
-
1127
- $metaBlacklistString = '('.implode(')|(',$metaBlacklist).')';
1128
- $metaKeys = array();
1129
-
1130
- if (strpos($metaBlacklistString, '*') !== false) {
1131
- $metaBlacklistString = str_replace(array('*'), array('[a-zA-Z0-9_]*'), $metaBlacklistString);
1132
-
1133
- foreach ($postMetaKeys as $metaKey) {
1134
- if (!preg_match('#^'.$metaBlacklistString.'$#', $metaKey)) {
1135
- $metaKeys[] = $metaKey;
1136
- }
1137
- }
1138
- }
1139
- else {
1140
- $metaKeys = array_diff($postMetaKeys, $metaBlacklist);
1141
- }
1142
-
1143
- $metaKeys = apply_filters('duplicate_post_meta_keys_filter', $metaKeys);
1144
-
1145
- foreach ($metaKeys as $metaKey) {
1146
- $metaValues = get_post_custom_values($metaKey, $post->ID);
1147
- foreach ($metaValues as $metaValue) {
1148
- $metaValue = maybe_unserialize($metaValue);
1149
- if (is_array($metaValue)) {
1150
- $metaValue['sgpb-post-id'] = $newId;
1151
- }
1152
- add_post_meta($newId, $metaKey, $this->popupWpSlash($metaValue));
1153
- }
1154
- }
1155
- }
1156
-
1157
- public function popupAddSlashesDeep($value)
1158
- {
1159
- if (function_exists('map_deep')) {
1160
- return map_deep($value, array($this, 'popupAddSlashesToStringsOnly'));
1161
- }
1162
- else {
1163
- return wp_slash($value);
1164
- }
1165
- }
1166
-
1167
- public function popupAddSlashesToStringsOnly($value)
1168
- {
1169
- return is_string($value) ? addslashes($value) : $value;
1170
- }
1171
-
1172
- public function popupWpSlash($value)
1173
- {
1174
- return $this->popupAddSlashesDeep($value);
1175
- }
1176
-
1177
- public function removePostPermalink($args)
1178
- {
1179
- global $post_type;
1180
-
1181
- if ($post_type == SG_POPUP_POST_TYPE && is_admin()) {
1182
- // hide permalink for popupbuilder post type
1183
- return '';
1184
- }
1185
-
1186
- return $args;
1187
- }
1188
-
1189
- // remove link ( e.g.: (View post) ), from popup updated/published message
1190
- public function popupPublishedMessage($messages)
1191
- {
1192
- global $post_type;
1193
-
1194
- if ($post_type == SG_POPUP_POST_TYPE) {
1195
- // post(popup) updated
1196
- if (isset($messages['post'][1])) {
1197
- $messages['post'][1] = __('Popup updated.', SG_POPUP_TEXT_DOMAIN);
1198
- }
1199
- // post(popup) published
1200
- if (isset($messages['post'][6])) {
1201
- $messages['post'][6] = __('Popup published.', SG_POPUP_TEXT_DOMAIN);
1202
- }
1203
- }
1204
- $messages = apply_filters('sgpbPostUpdateMessage', $messages);
1205
-
1206
- return $messages;
1207
- }
1208
-
1209
- public function getSubscribersCsvFile()
1210
- {
1211
- global $wpdb;
1212
- $allowToAction = AdminHelper::userCanAccessTo();
1213
- if (!$allowToAction) {
1214
- wp_redirect(get_home_url());
1215
- exit();
1216
- }
1217
-
1218
- $query = AdminHelper::subscribersRelatedQuery();
1219
- if (isset($_GET['orderby']) && !empty($_GET['orderby'])) {
1220
- if (isset($_GET['order']) && !empty($_GET['order'])) {
1221
- $query .= ' ORDER BY '.esc_sql($_GET['orderby']).' '.esc_sql($_GET['order']);
1222
- }
1223
- }
1224
- $content = '';
1225
- $exportTypeQuery = '';
1226
- $rows = array('first name', 'last name', 'email', 'date', 'popup');
1227
- foreach ($rows as $value) {
1228
- $content .= $value;
1229
- if ($value != 'popup') {
1230
- $content .= ',';
1231
- }
1232
- }
1233
- $content .= "\n";
1234
- $subscribers = $wpdb->get_results($query, ARRAY_A);
1235
-
1236
- $subscribers = apply_filters('sgpbSubscribersCsv', $subscribers);
1237
-
1238
- foreach($subscribers as $values) {
1239
- foreach ($values as $key => $value) {
1240
- $content .= $value;
1241
- if ($key != 'subscriptionTitle') {
1242
- $content .= ',';
1243
- }
1244
- }
1245
- $content .= "\n";
1246
- }
1247
-
1248
- $content = apply_filters('sgpbSubscribersContent', $content);
1249
-
1250
- header('Pragma: public');
1251
- header('Expires: 0');
1252
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1253
- header('Cache-Control: private', false);
1254
- header('Content-Type: application/octet-stream');
1255
- header('Content-Disposition: attachment; filename=subscribersList.csv;');
1256
- header('Content-Transfer-Encoding: binary');
1257
- echo $content;
1258
- }
1259
-
1260
- public function getSystemInfoFile()
1261
- {
1262
- $allowToAction = AdminHelper::userCanAccessTo();
1263
- if (!$allowToAction) {
1264
- return false;
1265
- }
1266
-
1267
- $content = AdminHelper::getSystemInfoText();
1268
-
1269
- header('Pragma: public');
1270
- header('Expires: 0');
1271
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1272
- header('Cache-Control: private', false);
1273
- header('Content-Type: application/octet-stream');
1274
- header('Content-Disposition: attachment; filename=popupBuilderSystemInfo.txt;');
1275
- header('Content-Transfer-Encoding: binary');
1276
-
1277
- echo $content;
1278
- }
1279
-
1280
- public function saveSettings()
1281
- {
1282
- $allowToAction = AdminHelper::userCanAccessTo();
1283
- if (!$allowToAction) {
1284
- wp_redirect(get_home_url());
1285
- exit();
1286
- }
1287
-
1288
- $postData = $_POST;
1289
- $deleteData = 0;
1290
- $enableDebugMode = 0;
1291
-
1292
- if (isset($postData['sgpb-dont-delete-data'])) {
1293
- $deleteData = 1;
1294
- }
1295
- if (isset($postData['sgpb-enable-debug-mode'])) {
1296
- $enableDebugMode = 1;
1297
- }
1298
- if (isset($postData['sgpb-disable-analytics-general'])) {
1299
- $disableAnalytics = 1;
1300
- }
1301
- $userRoles = @$postData['sgpb-user-roles'];
1302
-
1303
- update_option('sgpb-user-roles', $userRoles);
1304
- update_option('sgpb-dont-delete-data', $deleteData);
1305
- update_option('sgpb-enable-debug-mode', $enableDebugMode);
1306
- update_option('sgpb-disable-analytics-general', $disableAnalytics);
1307
-
1308
- AdminHelper::filterUserCapabilitiesForTheUserRoles('save');
1309
-
1310
- wp_redirect(admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
1311
- }
1312
- }
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('admin_menu', array($this, 'addSubMenu'));
22
+ add_action('admin_menu', array($this, 'supportLinks'), 999);
23
+ add_action('admin_head', array($this, 'showPreviewButtonAfterPopupPublish'));
24
+ add_action('admin_enqueue_scripts', array($this, 'adminLoadPopups'));
25
+ add_action('admin_action_popupSaveAsNew', array($this, 'popupSaveAsNew'));
26
+ add_action('admin_post_csv_file', array($this, 'getSubscribersCsvFile'));
27
+ add_action('admin_post_sgpb_system_info', array($this, 'getSystemInfoFile'));
28
+ add_action('admin_post_sgpbSaveSettings', array($this, 'saveSettings'), 10, 1);
29
+ add_action('admin_init', array($this, 'userRolesCaps'));
30
+ add_action('admin_notices', array($this, 'pluginNotices'));
31
+ add_action('admin_init', array($this, 'pluginLoaded'));
32
+ add_action('transition_post_status', array($this, 'deletePopup'), 100, 3);
33
+ // activate extensions
34
+ add_action('wp_before_admin_bar_render', array($this, 'pluginActivated'), 10, 2);
35
+ add_action('admin_head', array($this, 'hidePageBuilderEditButtons'));
36
+ add_action('admin_head', array($this, 'hidePublishingActions'));
37
+ add_action('add_meta_boxes', array($this, 'popupMetaboxes'), 100);
38
+ add_filter('post_updated_messages', array($this, 'popupPublishedMessage'), 1, 1);
39
+ add_action('before_delete_post', array($this, 'deleteSubscribersWithPopup'), 1, 1);
40
+ add_action('sgpb_duplicate_post', array($this, 'popupCopyPostMetaInfo'), 10, 2);
41
+ add_filter('get_sample_permalink_html', array($this, 'removePostPermalink'), 1, 1);
42
+ add_action('manage_'.SG_POPUP_POST_TYPE.'_posts_custom_column' , array($this, 'popupsTableColumnsValues'), 10, 2);
43
+ add_action('media_buttons', array($this, 'popupMediaButton'));
44
+ add_filter('mce_external_plugins', array($this, 'editorButton'), 1, 1);
45
+ add_action('admin_enqueue_scripts', array('sgpb\Style', 'enqueueStyles'));
46
+ add_action('admin_enqueue_scripts', array('sgpb\Javascript', 'enqueueScripts'));
47
+ // this action for popup options saving and popup builder classes save ex from post and page
48
+ add_action('save_post', array($this, 'savePost'), 100, 3);
49
+ add_action('wp_enqueue_scripts', array($this, 'enqueuePopupBuilderScripts'));
50
+ add_filter('sgpbOtherConditions', array($this ,'conditionsSatisfy'), 11, 1);
51
+ add_shortcode('sg_popup', array($this, 'popupShortcode'));
52
+ add_filter('cron_schedules', array($this, 'cronAddMinutes'), 10, 1);
53
+ add_action('sgpb_send_newsletter', array($this, 'newsletterSendEmail'), 10, 1);
54
+ add_action('sgpbGetBannerContentOnce', array($this, 'getBannerContent'), 10, 1);
55
+ add_action('plugins_loaded', array($this, 'loadTextDomain'));
56
+ // for change admin popup list order
57
+ add_action('pre_get_posts', array($this, 'preGetPosts'));
58
+ add_action('template_redirect', array($this, 'redirectFromPopupPage'));
59
+ add_filter('views_edit-popupbuilder', array($this, 'mainActionButtons'), 10, 1);
60
+ add_action('wpml_loaded', array($this, 'wpmlRelatedActions'));
61
+ new SGPBFeedback();
62
+ new SGPBReports();
63
+ new Ajax();
64
+ }
65
+
66
+ public function wpmlRelatedActions()
67
+ {
68
+ // The actions below will be executed right after WPML is fully configured and loaded.
69
+ add_action('admin_head', array($this, 'removeUnneededMetaboxesFromPopups'), 10);
70
+ }
71
+
72
+ public function removeUnneededMetaboxesFromPopups()
73
+ {
74
+ if (isset($_GET['post_type']) && $_GET['post_type'] == SG_POPUP_POST_TYPE) {
75
+ $exlcudeTrPopupTypes = array(
76
+ 'image',
77
+ 'video',
78
+ 'iframe',
79
+ 'recentSales',
80
+ 'pdf'
81
+ );
82
+ $exlcudeTrPopupTypes = apply_filters('sgpbNoMcePopupTypes', $exlcudeTrPopupTypes);
83
+ if (isset($_GET['sgpb_type']) && in_array($_GET['sgpb_type'], $exlcudeTrPopupTypes)) {
84
+ remove_meta_box('icl_div', SG_POPUP_POST_TYPE, 'side');
85
+ }
86
+ }
87
+ }
88
+
89
+ public function deletePopup($newStatus, $oldStatus, $post)
90
+ {
91
+ $currentPostType = AdminHelper::getCurrentPostType();
92
+
93
+ if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
94
+ Functions::clearAllTransients();
95
+ }
96
+ }
97
+
98
+ public function showPreviewButtonAfterPopupPublish()
99
+ {
100
+ $currentPostType = AdminHelper::getCurrentPostType();
101
+ if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
102
+ echo '<style>
103
+ #save-post {
104
+ display:none !important;
105
+ }
106
+ </style>';
107
+ }
108
+ }
109
+
110
+ public function inactiveExtensionNotice()
111
+ {
112
+ $screen = '';
113
+ $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
114
+ if ($dontShowLicenseBanner) {
115
+ return $screen;
116
+ }
117
+ $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
118
+ $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
119
+ if (!$inactive) {
120
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
121
+ if ($hasInactiveExtensions) {
122
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
123
+ $inactive = 'inactive';
124
+ }
125
+
126
+ }
127
+ $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
128
+ $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
129
+ if (function_exists('get_current_screen')) {
130
+ $screen = get_current_screen();
131
+ $screenId = $screen->id;
132
+ if ($screenId == SGPB_POPUP_LICENSE_SCREEN) {
133
+ $partOfContent = '';
134
+ }
135
+ }
136
+
137
+ if ($hasInactiveExtensions && $inactive == 'inactive') {
138
+ $content = '';
139
+ ob_start();
140
+ ?>
141
+ <div id="welcome-panel" class="update-nag sgpb-extensions-notices sgpb-license-notice">
142
+ <div class="welcome-panel-content">
143
+ <b><?php _e('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN) ?></b>
144
+ <br>
145
+ <br>
146
+ <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>
147
+ <b><?php echo $partOfContent; ?></b>
148
+ </div>
149
+ <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>
150
+ <span class="sgpb-dont-show-again-license-notice"><?php _e('Don\'t show again.', SG_POPUP_TEXT_DOMAIN); ?></span>
151
+ </div>
152
+ <?php
153
+ $content = ob_get_clean();
154
+
155
+ echo $content;
156
+ return true;
157
+ }
158
+ }
159
+
160
+ public function hidePublishingActions() {
161
+ $currentPostType = AdminHelper::getCurrentPostType();
162
+ if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
163
+ return false;
164
+ }
165
+
166
+ echo '<style>
167
+ #misc-publishing-actions .edit-post-status,
168
+ #misc-publishing-actions .edit-timestamp,
169
+ #misc-publishing-actions .edit-visibility {
170
+ display:none !important;
171
+ }
172
+ </style>';
173
+ }
174
+
175
+ public function hidePageBuilderEditButtons($postId = 0, $post = array())
176
+ {
177
+ $currentPostType = AdminHelper::getCurrentPostType();
178
+ if (empty($currentPostType) || $currentPostType != SG_POPUP_POST_TYPE) {
179
+ return false;
180
+ }
181
+ $excludedPopupTypesFromPageBuildersFunctionality = array(
182
+ 'image'
183
+ );
184
+
185
+ $excludedPopupTypesFromPageBuildersFunctionality = apply_filters('sgpbHidePageBuilderEditButtons', $excludedPopupTypesFromPageBuildersFunctionality);
186
+
187
+ $popupType = AdminHelper::getCurrentPopupType();
188
+ if (in_array($popupType, $excludedPopupTypesFromPageBuildersFunctionality)) {
189
+ echo '<style>
190
+ #elementor-switch-mode, #elementor-editor {
191
+ display:none !important;
192
+ }
193
+ </style>';
194
+ }
195
+ }
196
+
197
+ public function getBannerContent()
198
+ {
199
+ // right metabox banner content
200
+ $metaboxBannerContent = AdminHelper::getFileFromURL(SGPB_METABOX_BANNER_CRON_TEXT_URL);
201
+ update_option('sgpb-metabox-banner-remote-get', $metaboxBannerContent);
202
+
203
+ return true;
204
+ }
205
+
206
+ public function wpInit()
207
+ {
208
+ require_once(ABSPATH.'wp-admin/includes/screen.php');
209
+ if (!wp_next_scheduled('sgpbGetBannerContentOnce')) {
210
+ wp_schedule_event(time(), 'sgpb_banners', 'sgpbGetBannerContentOnce');
211
+ }
212
+ }
213
+
214
+ public function mainActionButtons($views)
215
+ {
216
+ require_once(SG_POPUP_VIEWS_PATH.'mainActionButtons.php');
217
+
218
+ return $views;
219
+ }
220
+
221
+ /**
222
+ * Loads the plugin language files
223
+ */
224
+ public function loadTextDomain()
225
+ {
226
+ $popupBuilderLangDir = SG_POPUP_BUILDER_PATH.'/languages/';
227
+ $popupBuilderLangDir = apply_filters('popupBuilderLanguagesDirectory', $popupBuilderLangDir);
228
+
229
+ $locale = apply_filters('sgpbPluginLocale', get_locale(), SG_POPUP_TEXT_DOMAIN);
230
+ $mofile = sprintf('%1$s-%2$s.mo', SG_POPUP_TEXT_DOMAIN, $locale);
231
+
232
+ $mofileLocal = $popupBuilderLangDir.$mofile;
233
+
234
+ if (file_exists($mofileLocal)) {
235
+ // Look in local /wp-content/plugins/popup-builder/languages/ folder
236
+ load_textdomain(SG_POPUP_TEXT_DOMAIN, $mofileLocal);
237
+ }
238
+ else {
239
+ // Load the default language files
240
+ load_plugin_textdomain(SG_POPUP_TEXT_DOMAIN, false, $popupBuilderLangDir);
241
+ }
242
+
243
+ }
244
+
245
+ public function redirectFromPopupPage()
246
+ {
247
+ global $post;
248
+ $currentPostType = '';
249
+
250
+ if (is_object($post)) {
251
+ $currentPostType = @$post->post_type;
252
+ }
253
+ // in some themes global $post returns null
254
+ if (empty($currentPostType)) {
255
+ global $post_type;
256
+ $currentPostType = $post_type;
257
+ }
258
+ // for editing popup content via page builders on backend
259
+ if (!isset($_GET) || empty($_GET)) {
260
+ if (!is_admin() && SG_POPUP_POST_TYPE == $currentPostType && !is_preview()) {
261
+ // it's for seo optimization
262
+ status_header(301);
263
+ $homeURL = home_url();
264
+ wp_redirect($homeURL);
265
+ exit();
266
+ }
267
+ }
268
+ }
269
+
270
+ public function preGetPosts($query)
271
+ {
272
+ if (!is_admin() || !isset($_GET['post_type']) || $_GET['post_type'] != SG_POPUP_POST_TYPE) {
273
+ return false;
274
+ }
275
+
276
+ // change default order by id and desc
277
+ if (!isset($_GET['orderby'])) {
278
+ $query->set('orderby', 'ID');
279
+ $query->set('order', 'desc');
280
+ }
281
+ $query = apply_filters('sgpbPreGetPosts', $query);
282
+
283
+ return true;
284
+ }
285
+
286
+ public function pluginNotices()
287
+ {
288
+ if (function_exists('get_current_screen')) {
289
+ $screen = get_current_screen();
290
+ $screenId = $screen->id;
291
+ if ($screenId == 'edit-popupbuilder') {
292
+ $notificationsObj = new SGPBNotificationCenter();
293
+ echo $notificationsObj->displayNotifications();
294
+ }
295
+ }
296
+ $extensions = AdminHelper::getAllActiveExtensions();
297
+ $updated = get_option('sgpb_extensions_updated');
298
+
299
+ $content = '';
300
+
301
+ // if popup builder has the old version
302
+ if (!get_option('SG_POPUP_VERSION')) {
303
+ return $content;
304
+ }
305
+
306
+ $alertProblem = get_option('sgpb_alert_problems');
307
+ // for old users show alert about problems
308
+ if (!$alertProblem) {
309
+ echo AdminHelper::renderAlertProblem();
310
+ }
311
+
312
+ // Don't show the banner if there's not any extension of Popup Builder or if the user has clicked "don't show"
313
+ if (empty($extensions) || $updated) {
314
+ return $content;
315
+ }
316
+
317
+ ob_start();
318
+ ?>
319
+ <div id="welcome-panel" class="update-nag sgpb-extensions-notices">
320
+ <div class="welcome-panel-content">
321
+ <?php echo AdminHelper::renderExtensionsContent(); ?>
322
+ </div>
323
+ </div>
324
+ <?php
325
+ $content = ob_get_clean();
326
+
327
+ echo $content;
328
+ return true;
329
+ }
330
+
331
+ private function registerImporter()
332
+ {
333
+ require_once SG_POPUP_LIBS_PATH.'Importer.php';
334
+ $importer = new WP_Import();
335
+ register_importer(SG_POPUP_POST_TYPE, SG_POPUP_POST_TYPE, __('Importer', SG_POPUP_TEXT_DOMAIN), array($importer, 'dispatch'));
336
+ }
337
+
338
+ public function pluginLoaded()
339
+ {
340
+ $this->registerImporter();
341
+ $versionPopup = get_option('SG_POPUP_VERSION');
342
+ $convert = get_option('sgpbConvertToNewVersion');
343
+ $unsubscribeColumnFixed = get_option('sgpbUnsubscribeColumnFixed');
344
+ AdminHelper::makeRegisteredPluginsStaticPathsToDynamic();
345
+
346
+ if (!$unsubscribeColumnFixed) {
347
+ AdminHelper::addUnsubscribeColumn();
348
+ update_option('sgpbUnsubscribeColumnFixed', 1);
349
+ delete_option('sgpbUnsubscribeColumn');
350
+ }
351
+
352
+ if ($versionPopup && !$convert) {
353
+ update_option('sgpbConvertToNewVersion', 1);
354
+ ConvertToNewVersion::convert();
355
+ Installer::registerPlugin();
356
+ }
357
+ }
358
+
359
+ public function popupMediaButton()
360
+ {
361
+ if (!$this->mediaButton) {
362
+ $this->mediaButton = true;
363
+ self::enqueueScriptsForPageBuilders();
364
+ if (function_exists('get_current_screen')) {
365
+ $screen = get_current_screen();
366
+ if (!empty($screen)) {
367
+ echo new MediaButton();
368
+ }
369
+ }
370
+ }
371
+ }
372
+
373
+ public function editorButton($plugins)
374
+ {
375
+ if (empty($this->mediaButton)) {
376
+ $this->mediaButton = true;
377
+ add_action('admin_footer', function() {
378
+ self::enqueueScriptsForPageBuilders();
379
+ echo new MediaButton(false);
380
+ });
381
+ }
382
+
383
+ return $plugins;
384
+ }
385
+
386
+ public static function enqueueScriptsForPageBuilders()
387
+ {
388
+ require_once(ABSPATH.'wp-admin/includes/screen.php');
389
+ global $post;
390
+ if (function_exists('get_current_screen')) {
391
+ $screen = get_current_screen();
392
+ if ((!empty($screen->id) && $screen->id == SG_POPUP_POST_TYPE) || !empty($post)) {
393
+ if (!isset($_GET['fl_builder'])) {
394
+ Javascript::enqueueScripts('post-new.php');
395
+ Style::enqueueStyles('post-new.php');
396
+ }
397
+ }
398
+ }
399
+ else if (isset($_GET['fl_builder'])) {
400
+ Javascript::enqueueScripts('post-new.php');
401
+ Style::enqueueStyles('post-new.php');
402
+ }
403
+ }
404
+
405
+ public function userRolesCaps()
406
+ {
407
+ $userSavedRoles = get_option('sgpb-user-roles');
408
+
409
+ if (!$userSavedRoles) {
410
+ $userSavedRoles = array('administrator');
411
+ }
412
+ else {
413
+ array_push($userSavedRoles, 'administrator');
414
+ }
415
+
416
+ foreach ($userSavedRoles as $theRole) {
417
+ $role = get_role($theRole);
418
+ if (empty($role)) {
419
+ continue;
420
+ }
421
+
422
+ $role->add_cap('read');
423
+ $role->add_cap('read_post');
424
+ $role->add_cap('read_private_sgpb_popups');
425
+ $role->add_cap('edit_sgpb_popup');
426
+ $role->add_cap('edit_sgpb_popups');
427
+ $role->add_cap('edit_others_sgpb_popups');
428
+ $role->add_cap('edit_published_sgpb_popups');
429
+ $role->add_cap('publish_sgpb_popups');
430
+ $role->add_cap('delete_sgpb_popups');
431
+ $role->add_cap('delete_published_posts');
432
+ $role->add_cap('delete_others_sgpb_popups');
433
+ $role->add_cap('delete_private_sgpb_popups');
434
+ $role->add_cap('delete_private_sgpb_popup');
435
+ $role->add_cap('delete_published_sgpb_popups');
436
+
437
+ // For popup builder sub-menus and terms
438
+ $role->add_cap('sgpb_manage_options');
439
+ $role->add_cap('manage_popup_terms');
440
+ $role->add_cap('manage_popup_categories_terms');
441
+ $role = apply_filters('sgpbUserRoleCap', $role);
442
+ }
443
+
444
+ return true;
445
+ }
446
+
447
+ public function pluginActivated()
448
+ {
449
+ if (!get_option('sgpbActivateExtensions') && SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
450
+ $obj = new PopupExtensionActivator();
451
+ $obj->activate();
452
+ update_option('sgpbActivateExtensions', 1);
453
+ }
454
+ }
455
+
456
+ public function popupShortcode($args, $content)
457
+ {
458
+ if (empty($args) || empty($args['id'])) {
459
+ return $content;
460
+ }
461
+
462
+ $oldShortcode = isset($args['event']) && $args['event'] === 'onload';
463
+ $isInherit = isset($args['event']) && $args['event'] == 'inherit';
464
+ $event = '';
465
+
466
+ $shortcodeContent = '';
467
+ $argsId = $popupId = (int)$args['id'];
468
+
469
+ // for old popups
470
+ if (function_exists('sgpb\sgpGetCorrectPopupId')) {
471
+ $popupId = sgpGetCorrectPopupId($popupId);
472
+ }
473
+
474
+ $popup = SGPopup::find($popupId);
475
+ $popup = apply_filters('sgpbShortCodePopupObj', $popup);
476
+
477
+ $event = preg_replace('/on/', '', @$args['event']);
478
+ // when popup does not exists or popup post status it's not publish ex when popup in trash
479
+ if (empty($popup) || (!is_object($popup) && $popup != 'publish')) {
480
+ return $content;
481
+ }
482
+ $alreadySavedEvents = $popup->getEvents();
483
+ $loadableMode = $popup->getLoadableModes();
484
+
485
+ if (!isset($args['event']) && isset($args['insidepopup'])) {
486
+ unset($args['insidepopup']);
487
+ $event = 'insideclick';
488
+ $insideShortcodeKey = $popupId.$event;
489
+
490
+ // for prevent infinity chain
491
+ if (is_array($this->insideShortcodes) && in_array($insideShortcodeKey, $this->insideShortcodes)) {
492
+ $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
493
+
494
+ return $shortcodeContent;
495
+ }
496
+ $this->insideShortcodes[] = $insideShortcodeKey;
497
+ }
498
+ // if no event attribute is set, or old shortcode
499
+ if (!isset($args['event']) || $oldShortcode || $isInherit) {
500
+ $loadableMode = $popup->getLoadableModes();
501
+ if (!empty($content)) {
502
+ $alreadySavedEvents = false;
503
+ }
504
+ // for old popup, after the update, there aren't any events
505
+ if (empty($alreadySavedEvents)) {
506
+ $event = '';
507
+ if (!empty($content)) {
508
+ $event = 'click';
509
+ }
510
+ if (!empty($args['event'])) {
511
+ $event = $args['event'];
512
+ }
513
+ $event = preg_replace('/on/', '', $event);
514
+ $popup->setEvents(array($event));
515
+ }
516
+ if (empty($loadableMode)) {
517
+ $loadableMode = array();
518
+ }
519
+ $loadableMode['option_event'] = true;
520
+ }
521
+ else {
522
+ $event = $args['event'];
523
+ $event = preg_replace('/on/', '', $event);
524
+ $popup->setEvents(array($event));
525
+ }
526
+
527
+ $popup->setLoadableModes($loadableMode);
528
+ $scriptsLoader = new ScriptsLoader();
529
+ $loadablePopups = array($popup);
530
+ $groupObj = new PopupGroupFilter();
531
+ $groupObj->setPopups(array($popup));
532
+ $loadablePopups = $groupObj->filter();
533
+ $scriptsLoader->setLoadablePopups($loadablePopups);
534
+ $scriptsLoader->loadToFooter();
535
+
536
+ if (!empty($content)) {
537
+ $matches = SGPopup::getPopupShortcodeMatchesFromContent($content);
538
+ if (!empty($matches)) {
539
+ foreach ($matches[0] as $key => $value) {
540
+ $attrs = shortcode_parse_atts($matches[3][$key]);
541
+ if (empty($attrs['id'])) {
542
+ continue;
543
+ }
544
+ $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $attrs['id'], $attrs['event'], $attrs);
545
+ break;
546
+ }
547
+ }
548
+ }
549
+
550
+ if (isset($event) && $event != 'onload' && !empty($content)) {
551
+ $shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
552
+ }
553
+ $shortcodeContent = apply_filters('sgpbPopupShortCodeContent', $shortcodeContent);
554
+
555
+ return do_shortcode($shortcodeContent);
556
+ }
557
+
558
+ public function deleteSubscribersWithPopup($postId)
559
+ {
560
+ global $post_type;
561
+
562
+ if ($post_type == SG_POPUP_POST_TYPE) {
563
+ AdminHelper::deleteSubscriptionPopupSubscribers($postId);
564
+ }
565
+ }
566
+
567
+ public function cronAddMinutes($schedules)
568
+ {
569
+ $schedules['sgpb_newsletter_send_every_minute'] = array(
570
+ 'interval' => SGPB_CRON_REPEAT_INTERVAL * 60,
571
+ 'display' => __('Once Every Minute', SG_POPUP_TEXT_DOMAIN)
572
+ );
573
+
574
+ $schedules['sgpb_banners'] = array(
575
+ 'interval' => SGPB_TRANSIENT_TIMEOUT_WEEK,
576
+ 'display' => __('Once Every Week', SG_POPUP_TEXT_DOMAIN)
577
+ );
578
+
579
+ $schedules = apply_filters('sgpbCronTimeoutSettings', $schedules);
580
+
581
+ return $schedules;
582
+ }
583
+
584
+ public function newsletterSendEmail()
585
+ {
586
+ global $wpdb;
587
+ $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
588
+
589
+ if (empty($newsletterOptions)) {
590
+ wp_clear_scheduled_hook('sgpb_send_newsletter');
591
+ }
592
+ $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
593
+ $subscriptionFormTitle = get_the_title($subscriptionFormId);
594
+ $emailsInFlow = (int)$newsletterOptions['emailsInFlow'];
595
+ $mailSubject = $newsletterOptions['newsletterSubject'];
596
+ $fromEmail = $newsletterOptions['fromEmail'];
597
+ $emailMessage = $newsletterOptions['messageBody'];
598
+
599
+ $allAvailableShortcodes = array();
600
+ $allAvailableShortcodes['patternFirstName'] = '/\[First name]/';
601
+ $allAvailableShortcodes['patternLastName'] = '/\[Last name]/';
602
+ $allAvailableShortcodes['patternBlogName'] = '/\[Blog name]/';
603
+ $allAvailableShortcodes['patternUserName'] = '/\[User name]/';
604
+ $allAvailableShortcodes['patternUnsubscribe'] = '';
605
+
606
+ $pattern = "/\[(\[?)(Unsubscribe)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/";
607
+ preg_match($pattern, $emailMessage, $matches);
608
+ $title = __('Unsubscribe', SG_POPUP_TEXT_DOMAIN);
609
+ if ($matches) {
610
+ $patternUnsubscribe = $matches[0];
611
+ // If user didn't change anything inside the [unsubscribe] shortcode $matches[2] will be equal to 'Unsubscribe'
612
+ if ($matches[2] == 'Unsubscribe') {
613
+ $pattern = '/\s(\w+?)="(.+?)"]/';
614
+ preg_match($pattern, $matches[0], $matchesTitle);
615
+ if (!empty($matchesTitle[2])) {
616
+ $title = AdminHelper::removeAllNonPrintableCharacters($matchesTitle[2], 'Unsubscribe');
617
+ }
618
+ }
619
+ $allAvailableShortcodes['patternUnsubscribe'] = $patternUnsubscribe;
620
+ }
621
+
622
+ // When email is not valid we don't continue
623
+ if (!preg_match('/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/', $fromEmail)) {
624
+ wp_clear_scheduled_hook('sgpb_send_newsletter');
625
+ return false;
626
+ }
627
+
628
+ $selectionQuery = 'SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
629
+ $selectionQuery = apply_filters('sgpbUserSelectionQuery', $selectionQuery);
630
+ $sql = $wpdb->prepare($selectionQuery .' and subscriptionType = %d limit 1', $subscriptionFormId);
631
+
632
+ $result = $wpdb->get_row($sql, ARRAY_A);
633
+ $currentStateEmailId = (int)$result['id'];
634
+ $getTotalSql = $wpdb->prepare('SELECT count(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE unsubscribed = 0 and subscriptionType = %d', $subscriptionFormId);
635
+ $totalSubscribers = $wpdb->get_var($getTotalSql);
636
+
637
+ // $currentStateEmailId == 0 when all emails status = 1
638
+ if ($currentStateEmailId == 0) {
639
+ // Clear schedule hook
640
+ $headers = 'MIME-Version: 1.0'."\r\n";
641
+ $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n";
642
+ $successTotal = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
643
+ if (!$successTotal) {
644
+ $successTotal = 0;
645
+ }
646
+ $failedTotal = $totalSubscribers - $successTotal;
647
+
648
+ $emailMessageCustom = __('Your mail list %s delivered successfully!
649
+ %d of the %d emails succeeded, %d failed.
650
+ For more details, please download log file inside the plugin.
651
+ This email was generated via Popup Builder plugin.', SG_POPUP_TEXT_DOMAIN);
652
+ $emailMessageCustom = sprintf($emailMessageCustom, $subscriptionFormTitle, $successTotal, $totalSubscribers, $failedTotal);
653
+
654
+ wp_mail($fromEmail, $subscriptionFormTitle.' list has been successfully delivered!', $emailMessageCustom, $headers);
655
+ delete_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
656
+ wp_clear_scheduled_hook('sgpb_send_newsletter');
657
+ return;
658
+ }
659
+
660
+ $getAllDataSql = 'SELECT id, firstName, lastName, email FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
661
+ $getAllDataSql = apply_filters('sgpbUserSelectionQuery', $getAllDataSql);
662
+ $getAllDataSql = $wpdb->prepare($getAllDataSql .' and id >= %d and subscriptionType = %s limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
663
+ $subscribers = $wpdb->get_results($getAllDataSql, ARRAY_A);
664
+
665
+ $subscribers = apply_filters('sgpNewsletterSendingSubscribers', $subscribers);
666
+
667
+ $blogInfo = get_bloginfo();
668
+ $headers = array(
669
+ 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
670
+ 'MIME-Version: 1.0' ,
671
+ 'Content-type: text/html; charset=UTF-8'
672
+ );
673
+
674
+ foreach ($subscribers as $subscriber) {
675
+ $replacementId = $subscriber['id'];
676
+ $allAvailableShortcodes = apply_filters('sgpbNewsletterShortcodes', $allAvailableShortcodes, $subscriptionFormId, $replacementId);
677
+ $replacementFirstName = $subscriber['firstName'];
678
+ $replacementLastName = $subscriber['lastName'];
679
+ $replacementBlogName = $newsletterOptions['blogname'];
680
+ $replacementUserName = $newsletterOptions['username'];
681
+ $replacementEmail = $subscriber['email'];
682
+ $replacementUnsubscribe = get_home_url();
683
+ $replacementUnsubscribe .= '?sgpbUnsubscribe='.md5($replacementId.$replacementEmail);
684
+ $replacementUnsubscribe .= '&email='.$subscriber['email'];
685
+ $replacementUnsubscribe .= '&popup='.$subscriptionFormId;
686
+ $replacementUnsubscribe = '<br><a href="'.$replacementUnsubscribe.'">'.$title.'</a>';
687
+
688
+ // Replace First name and Last name from email message
689
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternFirstName'], $replacementFirstName, $emailMessage);
690
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternLastName'], $replacementLastName, $emailMessageCustom);
691
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternBlogName'], $replacementBlogName, $emailMessageCustom);
692
+ $emailMessageCustom = preg_replace($allAvailableShortcodes['patternUserName'], $replacementUserName, $emailMessageCustom);
693
+ $emailMessageCustom = str_replace($allAvailableShortcodes['patternUnsubscribe'], $replacementUnsubscribe, $emailMessageCustom);
694
+ if (!empty($allAvailableShortcodes['extraShortcodesWithValues'])) {
695
+ $customFields = $allAvailableShortcodes['extraShortcodesWithValues'];
696
+ foreach ($customFields as $customFieldKey => $customFieldValue) {
697
+ $finalShortcode = '/\['.$customFieldKey.']/';
698
+ $emailMessageCustom = preg_replace($finalShortcode, $customFieldValue, $emailMessageCustom);
699
+ }
700
+ }
701
+ $emailMessageCustom = stripslashes($emailMessageCustom);
702
+
703
+ $emailMessageCustom = apply_filters('sgpNewsletterSendingMessage', $emailMessageCustom);
704
+ $mailStatus = wp_mail($subscriber['email'], $mailSubject, $emailMessageCustom, $headers);
705
+ if (!$mailStatus) {
706
+ $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'));
707
+ $wpdb->query($errorLogSql);
708
+ continue;
709
+ }
710
+
711
+ $successCount = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
712
+ if (!$successCount) {
713
+ update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, 1);
714
+ }
715
+ else {
716
+ update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, ++$successCount);
717
+ }
718
+ }
719
+ // Update the status of all the sent mails
720
+ $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 1 where id >= %d and subscriptionType = %d limit %d', $currentStateEmailId, $subscriptionFormId, $emailsInFlow);
721
+ $wpdb->query($updateStatusQuery);
722
+ }
723
+
724
+ private function unsubscribe($params = array())
725
+ {
726
+ AdminHelper::deleteUserFromSubscribers($params);
727
+ }
728
+
729
+ public function enqueuePopupBuilderScripts()
730
+ {
731
+ // for old popups
732
+ if (get_option('SG_POPUP_VERSION')) {
733
+ ConvertToNewVersion::saveCustomInserted();
734
+ }
735
+
736
+ $popupLoaderObj = PopupLoader::instance();
737
+ if (is_object($popupLoaderObj)) {
738
+ $popupLoaderObj->loadPopups();
739
+ }
740
+ }
741
+
742
+ public function adminLoadPopups($hook)
743
+ {
744
+ $allowedPages = array();
745
+ $allowedPages = apply_filters('sgpbAdminLoadedPages', $allowedPages);
746
+
747
+ if (!empty($allowedPages) && is_array($allowedPages) && in_array($hook, $allowedPages)) {
748
+ $scriptsLoader = new ScriptsLoader();
749
+ $scriptsLoader->setIsAdmin(true);
750
+ $scriptsLoader->loadToFooter();
751
+ }
752
+ }
753
+
754
+ public function postTypeInit()
755
+ {
756
+ if (isset($_POST['sgpb-is-preview']) && $_POST['sgpb-is-preview'] == 1) {
757
+ $postId = $_POST['post_ID'];
758
+ $post = get_post($postId);
759
+ $this->savePost($postId, $post, false);
760
+ }
761
+ $adminUrl = admin_url();
762
+
763
+ if (isset($_GET['page']) && $_GET['page'] == 'PopupBuilder') {
764
+ _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);
765
+ wp_die();
766
+ }
767
+
768
+ $unsubscribeArgs = $this->collectUnsubscriberArgs();
769
+ if (!empty($unsubscribeArgs)) {
770
+ $this->unsubscribe($unsubscribeArgs);
771
+ }
772
+
773
+ AdminHelper::removeUnnecessaryCodeFromPopups();
774
+
775
+ $this->customPostTypeObj = new RegisterPostType();
776
+ }
777
+
778
+ public function collectUnsubscriberArgs()
779
+ {
780
+ if (!isset($_GET['sgpbUnsubscribe'])) {
781
+ return false;
782
+ }
783
+ $args = array();
784
+ if (isset($_GET['sgpbUnsubscribe'])) {
785
+ $args['token'] = $_GET['sgpbUnsubscribe'];
786
+ }
787
+ if (isset($_GET['email'])) {
788
+ $args['email'] = $_GET['email'];
789
+ }
790
+ if (isset($_GET['popup'])) {
791
+ $args['popup'] = $_GET['popup'];
792
+ }
793
+
794
+ return $args;
795
+ }
796
+
797
+ public function addSubMenu()
798
+ {
799
+ // We need to check license keys and statuses before adding new menu "License" item
800
+ new Updates();
801
+
802
+ $this->customPostTypeObj->addSubMenu();
803
+ }
804
+
805
+ public function supportLinks()
806
+ {
807
+ if (SGPB_POPUP_PKG == SGPB_POPUP_PKG_FREE) {
808
+ if (method_exists($this->customPostTypeObj, 'supportLinks')) {
809
+ $this->customPostTypeObj->supportLinks();
810
+ }
811
+ }
812
+ }
813
+
814
+ public function popupMetaboxes()
815
+ {
816
+ $this->customPostTypeObj->addPopupMetaboxes();
817
+ }
818
+
819
+ public function savePost($postId = 0, $post = array(), $update = false)
820
+ {
821
+ $allowToAction = AdminHelper::userCanAccessTo();
822
+ Functions::clearAllTransients();
823
+ $postData = SGPopup::parsePopupDataFromData($_POST);
824
+ $saveMode = '';
825
+ $postData['sgpb-post-id'] = $postId;
826
+ // If preview mode
827
+ if (isset($postData['sgpb-is-preview']) && $postData['sgpb-is-preview'] == 1) {
828
+ $saveMode = '_preview';
829
+ SgpbPopupConfig::popupTypesInit();
830
+ SgpbDataConfig::init();
831
+ // published popup
832
+ if (empty($post)) {
833
+ global $post;
834
+ $postId = $post->ID;
835
+ }
836
+ if ($post->post_status != 'draft') {
837
+ $posts = array();
838
+ $popupContent = $post->post_content;
839
+
840
+ $query = new WP_Query(
841
+ array(
842
+ 'post_parent' => $postId,
843
+ 'posts_per_page' => - 1,
844
+ 'post_type' => 'revision',
845
+ 'post_status' => 'inherit'
846
+ )
847
+ );
848
+ $query = apply_filters('sgpbSavePostQuery', $query);
849
+
850
+ while ($query->have_posts()) {
851
+ $query->the_post();
852
+ if (empty($posts)) {
853
+ $posts[] = $post;
854
+ }
855
+ }
856
+ if (!empty($posts[0])) {
857
+ $popup = $posts[0];
858
+ $popupContent = $popup->post_content;
859
+ }
860
+ }
861
+ }
862
+
863
+
864
+ if (empty($post)) {
865
+ $saveMode = '';
866
+ }
867
+ /* In preview mode saveMode should be true*/
868
+ if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
869
+ if (!$allowToAction) {
870
+ wp_redirect(get_home_url());
871
+ exit();
872
+ }
873
+ if (!empty($postData['sgpb-type'])) {
874
+ $popupType = $postData['sgpb-type'];
875
+ $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
876
+ $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
877
+ require_once($popupClassPath.$popupClassName.'.php');
878
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
879
+
880
+ $popupClassName::create($postData, $saveMode, 1);
881
+ }
882
+ }
883
+ else {
884
+ $content = get_post_field('post_content', $postId);
885
+ SGPopup::deletePostCustomInsertedData($postId);
886
+ SGPopup::deletePostCustomInsertedEvents($postId);
887
+ /*We detect all the popups that were inserted as a custom ones, in the content.*/
888
+ SGPopup::savePopupsFromContentClasses($content, $post);
889
+ }
890
+ }
891
+
892
+ /**
893
+ * Check Popup is satisfy for popup condition
894
+ *
895
+ * @param array $args
896
+ *
897
+ * @return array
898
+ *
899
+ *@since 1.0.0
900
+ *
901
+ */
902
+ public function conditionsSatisfy($args = array())
903
+ {
904
+ if (isset($args['status']) && $args['status'] === false) {
905
+ return $args;
906
+ }
907
+ $args['status'] = PopupChecker::checkOtherConditionsActions($args);
908
+
909
+ return $args;
910
+ }
911
+
912
+ public function popupsTableColumnsValues($column, $postId)
913
+ {
914
+ $postId = (int)$postId;// Convert to int for security reasons
915
+ $switchButton = '';
916
+ $isActive = '';
917
+ global $post_type;
918
+ if ($postId) {
919
+ $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
920
+ $popup = SGPopup::find($postId, $args);
921
+ }
922
+
923
+ if (empty($popup) && $post_type == SG_POPUP_POST_TYPE) {
924
+ return false;
925
+ }
926
+
927
+ if ($column == 'shortcode') {
928
+ echo '<input type="text" onfocus="this.select();" readonly value="[sg_popup id='.$postId.']" class="large-text code">';
929
+ }
930
+ if ($column == 'className') {
931
+ echo '<input type="text" onfocus="this.select();" readonly value="sg-popup-id-'.esc_attr($postId).'" class="large-text code">';
932
+ }
933
+ else if ($column == 'counter') {
934
+ $count = $popup->getPopupOpeningCountById($postId);
935
+ echo '<div class="sgpb-counter-wrapper"><div class="sgpb-dashboard-popup-count-wrapper">'.$count.'</div>'.'<input onclick="SGPBBackend.resetCount('.$postId.', true);" type="button" name="" class="button sgpb-reset-count-btn" value="'.__('reset', SG_POPUP_TEXT_DOMAIN).'"></div>';
936
+ }
937
+ else if ($column == 'type') {
938
+ global $SGPB_POPUP_TYPES;
939
+ $type = $popup->getType();
940
+ if (isset($SGPB_POPUP_TYPES['typeLabels'][$type])) {
941
+ $type = $SGPB_POPUP_TYPES['typeLabels'][$type];
942
+ }
943
+ echo $type;
944
+ }
945
+ else if ($column == 'onOff') {
946
+ $popupPostStatus = get_post_status($postId);
947
+ if ($popupPostStatus == 'publish' || $popupPostStatus == 'draft') {
948
+ $isActive = $popup->getOptionValue('sgpb-is-active', true);
949
+ }
950
+ $switchButton .= '<label class="sgpb-switch">';
951
+ $switchButton .= '<input class="sg-switch-checkbox" data-switch-id="'.$postId.'" type="checkbox" '.$isActive.'>';
952
+ $switchButton .= '<div class="sgpb-slider sgpb-round"></div>';
953
+ $switchButton .= '</label>';
954
+ echo $switchButton;
955
+ }
956
+ }
957
+
958
+ /*
959
+ * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
960
+ * then redirects to the post list
961
+ */
962
+ public function popupSaveAsNew($status = '')
963
+ {
964
+ if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'popupSaveAsNew' == $_REQUEST['action']))) {
965
+ wp_die(esc_html__('No post to duplicate has been supplied!', SG_POPUP_TEXT_DOMAIN));
966
+ }
967
+ // Get the original post
968
+ $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
969
+
970
+ check_admin_referer('duplicate-post_'.$id);
971
+
972
+ $post = get_post($id);
973
+
974
+ // Copy the post and insert it
975
+ if (isset($post) && $post != null) {
976
+ $newId = $this->popupCreateDuplicate($post, $status);
977
+ $postType = $post->post_type;
978
+
979
+ if ($status == '') {
980
+ $sendBack = wp_get_referer();
981
+ if (!$sendBack ||
982
+ strpos($sendBack, 'post.php') !== false ||
983
+ strpos($sendBack, 'post-new.php') !== false) {
984
+ if ('attachment' == $postType) {
985
+ $sendBack = admin_url('upload.php');
986
+ }
987
+ else {
988
+ $sendBack = admin_url('edit.php');
989
+ if (!empty($postType)) {
990
+ $sendBack = add_query_arg('post_type', $postType, $sendBack);
991
+ }
992
+ }
993
+ }
994
+ else {
995
+ $sendBack = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'cloned', 'ids'), $sendBack);
996
+ }
997
+ // Redirect to the post list screen
998
+ wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), $sendBack));
999
+ }
1000
+ else {
1001
+ // Redirect to the edit screen for the new draft post
1002
+ wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), admin_url('post.php?action=edit&post='.$newId)));
1003
+ }
1004
+ exit;
1005
+
1006
+ }
1007
+ else {
1008
+ wp_die(esc_html__('Copy creation failed, could not find original:', SG_POPUP_TEXT_DOMAIN).' '.htmlspecialchars($id));
1009
+ }
1010
+ }
1011
+
1012
+ /**
1013
+ * Create a duplicate from a post
1014
+ */
1015
+ public function popupCreateDuplicate($post, $status = '', $parent_id = '')
1016
+ {
1017
+ $newPostStatus = (empty($status))? $post->post_status: $status;
1018
+
1019
+ if ($post->post_type != 'attachment') {
1020
+ $title = $post->post_title;
1021
+ if ($title == '') {
1022
+ // empty title
1023
+ $title = __('(no title) (clone)');
1024
+ }
1025
+ else {
1026
+ $title .= ' '.__('(clone)');
1027
+ }
1028
+
1029
+ if ('publish' == $newPostStatus || 'future' == $newPostStatus) {
1030
+ // check if the user has the right capability
1031
+ if (is_post_type_hierarchical($post->post_type)) {
1032
+ if (!current_user_can('publish_pages')) {
1033
+ $newPostStatus = 'pending';
1034
+ }
1035
+ }
1036
+ else {
1037
+ if (!current_user_can('publish_posts')) {
1038
+ $newPostStatus = 'pending';
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+
1044
+ $newPostAuthor = wp_get_current_user();
1045
+ $newPostAuthorId = $newPostAuthor->ID;
1046
+ // check if the user has the right capability
1047
+ if (is_post_type_hierarchical($post->post_type)) {
1048
+ if (current_user_can('edit_others_pages')) {
1049
+ $newPostAuthorId = $post->post_author;
1050
+ }
1051
+ }
1052
+ else {
1053
+ if (current_user_can('edit_others_posts')) {
1054
+ $newPostAuthorId = $post->post_author;
1055
+ }
1056
+ }
1057
+
1058
+ $newPost = array(
1059
+ 'menu_order' => $post->menu_order,
1060
+ 'comment_status' => $post->comment_status,
1061
+ 'ping_status' => $post->ping_status,
1062
+ 'post_author' => $newPostAuthorId,
1063
+ 'post_content' => $post->post_content,
1064
+ 'post_content_filtered' => $post->post_content_filtered,
1065
+ 'post_excerpt' => $post->post_excerpt,
1066
+ 'post_mime_type' => $post->post_mime_type,
1067
+ 'post_parent' => $newPostParent = empty($parent_id)? $post->post_parent : $parent_id,
1068
+ 'post_password' => $post->post_password,
1069
+ 'post_status' => $newPostStatus,
1070
+ 'post_title' => $title,
1071
+ 'post_type' => $post->post_type,
1072
+ );
1073
+
1074
+ $newPost['post_date'] = $newPostDate = $post->post_date;
1075
+ $newPost['post_date_gmt'] = get_gmt_from_date($newPostDate);
1076
+ $newPostId = wp_insert_post(wp_slash($newPost));
1077
+
1078
+ // If the copy is published or scheduled, we have to set a proper slug.
1079
+ if ($newPostStatus == 'publish' || $newPostStatus == 'future') {
1080
+ $postName = $post->post_name;
1081
+ $postName = wp_unique_post_slug($postName, $newPostId, $newPostStatus, $post->post_type, $newPostParent);
1082
+
1083
+ $newPost = array();
1084
+ $newPost['ID'] = $newPostId;
1085
+ $newPost['post_name'] = $postName;
1086
+
1087
+ // Update the post into the database
1088
+ wp_update_post(wp_slash($newPost));
1089
+ }
1090
+
1091
+ // If you have written a plugin which uses non-WP database tables to save
1092
+ // information about a post you can hook this action to dupe that data.
1093
+ if ($post->post_type == 'page' || is_post_type_hierarchical($post->post_type)) {
1094
+ do_action('dp_duplicate_page', $newPostId, $post, $status);
1095
+ }
1096
+ else {
1097
+ do_action('sgpb_duplicate_post', $newPostId, $post, $status);
1098
+ }
1099
+
1100
+ delete_post_meta($newPostId, '_sgpb_original');
1101
+ add_post_meta($newPostId, '_sgpb_original', $post->ID);
1102
+
1103
+ return $newPostId;
1104
+ }
1105
+
1106
+ /**
1107
+ * Copy the meta information of a post to another post
1108
+ */
1109
+ public function popupCopyPostMetaInfo($newId, $post)
1110
+ {
1111
+ $postMetaKeys = get_post_custom_keys($post->ID);
1112
+ $metaBlacklist = '';
1113
+
1114
+ if (empty($postMetaKeys) || !is_array($postMetaKeys)) {
1115
+ return;
1116
+ }
1117
+ $metaBlacklist = explode(',', $metaBlacklist);
1118
+ $metaBlacklist = array_filter($metaBlacklist);
1119
+ $metaBlacklist = array_map('trim', $metaBlacklist);
1120
+ $metaBlacklist[] = '_edit_lock';
1121
+ $metaBlacklist[] = '_edit_last';
1122
+ $metaBlacklist[] = '_wp_page_template';
1123
+ $metaBlacklist[] = '_thumbnail_id';
1124
+
1125
+ $metaBlacklist = apply_filters('duplicate_post_blacklist_filter' , $metaBlacklist);
1126
+
1127
+ $metaBlacklistString = '('.implode(')|(',$metaBlacklist).')';
1128
+ $metaKeys = array();
1129
+
1130
+ if (strpos($metaBlacklistString, '*') !== false) {
1131
+ $metaBlacklistString = str_replace(array('*'), array('[a-zA-Z0-9_]*'), $metaBlacklistString);
1132
+
1133
+ foreach ($postMetaKeys as $metaKey) {
1134
+ if (!preg_match('#^'.$metaBlacklistString.'$#', $metaKey)) {
1135
+ $metaKeys[] = $metaKey;
1136
+ }
1137
+ }
1138
+ }
1139
+ else {
1140
+ $metaKeys = array_diff($postMetaKeys, $metaBlacklist);
1141
+ }
1142
+
1143
+ $metaKeys = apply_filters('duplicate_post_meta_keys_filter', $metaKeys);
1144
+
1145
+ foreach ($metaKeys as $metaKey) {
1146
+ $metaValues = get_post_custom_values($metaKey, $post->ID);
1147
+ foreach ($metaValues as $metaValue) {
1148
+ $metaValue = maybe_unserialize($metaValue);
1149
+ if (is_array($metaValue)) {
1150
+ $metaValue['sgpb-post-id'] = $newId;
1151
+ }
1152
+ add_post_meta($newId, $metaKey, $this->popupWpSlash($metaValue));
1153
+ }
1154
+ }
1155
+ }
1156
+
1157
+ public function popupAddSlashesDeep($value)
1158
+ {
1159
+ if (function_exists('map_deep')) {
1160
+ return map_deep($value, array($this, 'popupAddSlashesToStringsOnly'));
1161
+ }
1162
+ else {
1163
+ return wp_slash($value);
1164
+ }
1165
+ }
1166
+
1167
+ public function popupAddSlashesToStringsOnly($value)
1168
+ {
1169
+ return is_string($value) ? addslashes($value) : $value;
1170
+ }
1171
+
1172
+ public function popupWpSlash($value)
1173
+ {
1174
+ return $this->popupAddSlashesDeep($value);
1175
+ }
1176
+
1177
+ public function removePostPermalink($args)
1178
+ {
1179
+ global $post_type;
1180
+
1181
+ if ($post_type == SG_POPUP_POST_TYPE && is_admin()) {
1182
+ // hide permalink for popupbuilder post type
1183
+ return '';
1184
+ }
1185
+
1186
+ return $args;
1187
+ }
1188
+
1189
+ // remove link ( e.g.: (View post) ), from popup updated/published message
1190
+ public function popupPublishedMessage($messages)
1191
+ {
1192
+ global $post_type;
1193
+
1194
+ if ($post_type == SG_POPUP_POST_TYPE) {
1195
+ // post(popup) updated
1196
+ if (isset($messages['post'][1])) {
1197
+ $messages['post'][1] = __('Popup updated.', SG_POPUP_TEXT_DOMAIN);
1198
+ }
1199
+ // post(popup) published
1200
+ if (isset($messages['post'][6])) {
1201
+ $messages['post'][6] = __('Popup published.', SG_POPUP_TEXT_DOMAIN);
1202
+ }
1203
+ }
1204
+ $messages = apply_filters('sgpbPostUpdateMessage', $messages);
1205
+
1206
+ return $messages;
1207
+ }
1208
+
1209
+ public function getSubscribersCsvFile()
1210
+ {
1211
+ global $wpdb;
1212
+ $allowToAction = AdminHelper::userCanAccessTo();
1213
+ if (!$allowToAction) {
1214
+ wp_redirect(get_home_url());
1215
+ exit();
1216
+ }
1217
+
1218
+ $query = AdminHelper::subscribersRelatedQuery();
1219
+ if (isset($_GET['orderby']) && !empty($_GET['orderby'])) {
1220
+ if (isset($_GET['order']) && !empty($_GET['order'])) {
1221
+ $query .= ' ORDER BY '.esc_sql($_GET['orderby']).' '.esc_sql($_GET['order']);
1222
+ }
1223
+ }
1224
+ $content = '';
1225
+ $exportTypeQuery = '';
1226
+ $rows = array('first name', 'last name', 'email', 'date', 'popup');
1227
+ foreach ($rows as $value) {
1228
+ $content .= $value;
1229
+ if ($value != 'popup') {
1230
+ $content .= ',';
1231
+ }
1232
+ }
1233
+ $content .= "\n";
1234
+ $subscribers = $wpdb->get_results($query, ARRAY_A);
1235
+
1236
+ $subscribers = apply_filters('sgpbSubscribersCsv', $subscribers);
1237
+
1238
+ foreach($subscribers as $values) {
1239
+ foreach ($values as $key => $value) {
1240
+ $content .= $value;
1241
+ if ($key != 'subscriptionTitle') {
1242
+ $content .= ',';
1243
+ }
1244
+ }
1245
+ $content .= "\n";
1246
+ }
1247
+
1248
+ $content = apply_filters('sgpbSubscribersContent', $content);
1249
+
1250
+ header('Pragma: public');
1251
+ header('Expires: 0');
1252
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1253
+ header('Cache-Control: private', false);
1254
+ header('Content-Type: application/octet-stream');
1255
+ header('Content-Disposition: attachment; filename=subscribersList.csv;');
1256
+ header('Content-Transfer-Encoding: binary');
1257
+ echo $content;
1258
+ }
1259
+
1260
+ public function getSystemInfoFile()
1261
+ {
1262
+ $allowToAction = AdminHelper::userCanAccessTo();
1263
+ if (!$allowToAction) {
1264
+ return false;
1265
+ }
1266
+
1267
+ $content = AdminHelper::getSystemInfoText();
1268
+
1269
+ header('Pragma: public');
1270
+ header('Expires: 0');
1271
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1272
+ header('Cache-Control: private', false);
1273
+ header('Content-Type: application/octet-stream');
1274
+ header('Content-Disposition: attachment; filename=popupBuilderSystemInfo.txt;');
1275
+ header('Content-Transfer-Encoding: binary');
1276
+
1277
+ echo $content;
1278
+ }
1279
+
1280
+ public function saveSettings()
1281
+ {
1282
+ $allowToAction = AdminHelper::userCanAccessTo();
1283
+ if (!$allowToAction) {
1284
+ wp_redirect(get_home_url());
1285
+ exit();
1286
+ }
1287
+
1288
+ $postData = $_POST;
1289
+ $deleteData = 0;
1290
+ $enableDebugMode = 0;
1291
+
1292
+ if (isset($postData['sgpb-dont-delete-data'])) {
1293
+ $deleteData = 1;
1294
+ }
1295
+ if (isset($postData['sgpb-enable-debug-mode'])) {
1296
+ $enableDebugMode = 1;
1297
+ }
1298
+ if (isset($postData['sgpb-disable-analytics-general'])) {
1299
+ $disableAnalytics = 1;
1300
+ }
1301
+ $userRoles = @$postData['sgpb-user-roles'];
1302
+
1303
+ update_option('sgpb-user-roles', $userRoles);
1304
+ update_option('sgpb-dont-delete-data', $deleteData);
1305
+ update_option('sgpb-enable-debug-mode', $enableDebugMode);
1306
+ update_option('sgpb-disable-analytics-general', $disableAnalytics);
1307
+
1308
+ AdminHelper::filterUserCapabilitiesForTheUserRoles('save');
1309
+
1310
+ wp_redirect(admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
1311
+ }
1312
+ }
com/classes/Ajax.php CHANGED
@@ -1,711 +1,711 @@
1
- <?php
2
- namespace sgpb;
3
- use \ConfigDataHelper;
4
-
5
- class Ajax
6
- {
7
- private $postData;
8
-
9
- public function __construct()
10
- {
11
- $this->actions();
12
- }
13
-
14
- public function setPostData($postData)
15
- {
16
- $this->postData = $postData;
17
- }
18
-
19
- public function getPostData()
20
- {
21
- return $this->postData;
22
- }
23
-
24
- /**
25
- * Return ajax param form post data by key
26
- *
27
- * @since 1.0.0
28
- *
29
- * @param string $key
30
- *
31
- * @return string $value
32
- */
33
- public function getValueFromPost($key)
34
- {
35
- $postData = $this->getPostData();
36
- $value = '';
37
-
38
- if (!empty($postData[$key])) {
39
- $value = $postData[$key];
40
- }
41
-
42
- return $value;
43
- }
44
-
45
- public function actions()
46
- {
47
- add_action('wp_ajax_sgpb_send_to_open_counter', array($this, 'addToCounter'));
48
- add_action('wp_ajax_nopriv_sgpb_send_to_open_counter', array($this, 'addToCounter'));
49
-
50
- add_action('wp_ajax_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
51
- add_action('wp_ajax_nopriv_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
52
-
53
- add_action('wp_ajax_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
54
- add_action('wp_ajax_nopriv_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
55
-
56
- $allowToAction = AdminHelper::userCanAccessTo();
57
-
58
- if ($allowToAction) {
59
- add_action('wp_ajax_add_condition_group_row', array($this, 'addConditionGroupRow'));
60
- add_action('wp_ajax_add_condition_rule_row', array($this, 'addConditionRuleRow'));
61
- add_action('wp_ajax_change_condition_rule_row', array($this, 'changeConditionRuleRow'));
62
- add_action('wp_ajax_select2_search_data', array($this, 'select2SearchData'));
63
- add_action('wp_ajax_change_popup_status', array($this, 'changePopupStatus'));
64
- // proStartGold
65
- add_action('wp_ajax_check_same_origin', array($this, 'checkSameOrigin'));
66
- // proEndGold
67
- add_action('wp_ajax_sgpb_subscribers_delete', array($this, 'deleteSubscribers'));
68
- add_action('wp_ajax_sgpb_add_subscribers', array($this, 'addSubscribers'));
69
- add_action('wp_ajax_sgpb_import_subscribers', array($this, 'importSubscribers'));
70
- add_action('wp_ajax_sgpb_save_imported_subscribers', array($this, 'saveImportedSubscribers'));
71
- add_action('wp_ajax_sgpb_send_newsletter', array($this, 'sendNewsletter'));
72
- add_action('wp_ajax_sgpb_change_review_popup_show_period', array($this, 'changeReviewPopupPeriod'));
73
- add_action('wp_ajax_sgpb_dont_show_review_popup', array($this, 'dontShowReviewPopup'));
74
- add_action('wp_ajax_sgpb_close_banner', array($this, 'closeMainRateUsBanner'));
75
- add_action('wp_ajax_sgpb_close_license_notice', array($this, 'closeLicenseNoticeBanner'));
76
- add_action('wp_ajax_sgpb_hide_ask_review_popup', array($this, 'dontShowAskReviewBanner'));
77
- add_action('wp_ajax_sgpb_reset_popup_opening_count', array($this, 'resetPopupOpeningCount'));
78
- /*Extension notification panel*/
79
- add_action('wp_ajax_sgpb_dont_show_extension_panel', array($this, 'extensionNotificationPanel'));
80
- add_action('wp_ajax_sgpb_dont_show_problem_alert', array($this, 'dontShowProblemAlert'));
81
- // autosave
82
- add_action('wp_ajax_sgpb_autosave', array($this, 'sgpbAutosave'));
83
- }
84
- }
85
-
86
- public function sgpbAutosave()
87
- {
88
- $allowToAction = AdminHelper::userCanAccessTo();
89
- if (!$allowToAction) {
90
- wp_die('');
91
- }
92
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
93
-
94
- $popupId = @(int)$_POST['post_ID'];
95
- $postStatus = get_post_status($popupId);
96
- if ($postStatus == 'publish') {
97
- wp_die('');
98
- }
99
-
100
- if (!isset($_POST['allPopupData'])) {
101
- wp_die(true);
102
- }
103
- $popupData = SGPopup::parsePopupDataFromData($_POST['allPopupData']);
104
- do_action('save_post_popupbuilder');
105
- $popupType = $popupData['sgpb-type'];
106
- $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
107
- $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
108
- if (file_exists($popupClassPath.$popupClassName.'.php')) {
109
- require_once($popupClassPath.$popupClassName.'.php');
110
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
111
- $popupClassName::create($popupData, '_preview', 1);
112
- }
113
-
114
- wp_die();
115
- }
116
-
117
- public function dontShowReviewPopup()
118
- {
119
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
120
- update_option('SGPBCloseReviewPopup-notification', true);
121
- do_action('sgpbGetNotifications');
122
- wp_die();
123
- }
124
-
125
- public function changeReviewPopupPeriod()
126
- {
127
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
128
- $messageType = sanitize_text_field($_POST['messageType']);
129
-
130
- if ($messageType == 'count') {
131
- $maxPopupCount = get_option('SGPBMaxOpenCount');
132
- if (!$maxPopupCount) {
133
- $maxPopupCount = SGPB_ASK_REVIEW_POPUP_COUNT;
134
- }
135
- $maxPopupData = AdminHelper::getMaxOpenPopupId();
136
- if (!empty($maxPopupData['maxCount'])) {
137
- $maxPopupCount = $maxPopupData['maxCount'];
138
- }
139
-
140
- $maxPopupCount += SGPB_ASK_REVIEW_POPUP_COUNT;
141
- update_option('SGPBMaxOpenCount', $maxPopupCount);
142
- wp_die();
143
- }
144
-
145
- $popupTimeZone = get_option('timezone_string');
146
- if (!$popupTimeZone) {
147
- $popupTimeZone = SG_POPUP_DEFAULT_TIME_ZONE;
148
- }
149
- $timeDate = new \DateTime('now', new \DateTimeZone($popupTimeZone));
150
- $timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
151
-
152
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
153
- update_option('SGPBOpenNextTime', $timeNow);
154
- $usageDays = get_option('SGPBUsageDays');
155
- $usageDays += SGPB_REVIEW_POPUP_PERIOD;
156
- update_option('SGPBUsageDays', $usageDays);
157
- wp_die();
158
- }
159
-
160
- public function resetPopupOpeningCount()
161
- {
162
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
163
-
164
- global $wpdb;
165
-
166
- $tableName = $wpdb->prefix.'sgpb_analytics';
167
- $popupId = (int)$_POST['popupId'];
168
- $allPopupsCount = get_option('SgpbCounter');
169
- if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
170
- SGPopup::deleteAnalyticsDataByPopupId($popupId);
171
- }
172
- if (empty($allPopupsCount)) {
173
- echo SGPB_AJAX_STATUS_FALSE;
174
- wp_die();
175
- }
176
- if (isset($allPopupsCount[$popupId])) {
177
- $allPopupsCount[$popupId] = 0;
178
- }
179
-
180
- // 7, 12, 13 => exclude close, subscription success, contact success events
181
- $stmt = $wpdb->prepare(' DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
182
- $popupAnalyticsData = $wpdb->get_var($stmt);
183
-
184
- update_option('SgpbCounter', $allPopupsCount);
185
-
186
- }
187
-
188
- public function dontShowAskReviewBanner()
189
- {
190
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
191
- update_option('sgpbDontShowAskReviewBanner', 1);
192
- echo SGPB_AJAX_STATUS_TRUE;
193
- wp_die();
194
- }
195
-
196
- public function dontShowProblemAlert()
197
- {
198
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
199
- update_option('sgpb_alert_problems', 1);
200
- echo SGPB_AJAX_STATUS_TRUE;
201
- wp_die();
202
- }
203
-
204
- public function extensionNotificationPanel()
205
- {
206
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
207
- update_option('sgpb_extensions_updated', 1);
208
- echo SGPB_AJAX_STATUS_TRUE;
209
- wp_die();
210
- }
211
-
212
- public function closeMainRateUsBanner()
213
- {
214
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
215
- update_option('sgpb-hide-support-banner', 1);
216
- do_action('sgpbGetNotifications');
217
- wp_die();
218
- }
219
-
220
- public function closeLicenseNoticeBanner()
221
- {
222
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
223
- update_option('sgpb-hide-license-notice-banner', 1);
224
- wp_die();
225
- }
226
-
227
- public function addToCounter()
228
- {
229
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
230
-
231
- $popupParams = $_POST['params'];
232
- if (isset($_GET['sg_popup_preview_id'])) {
233
- wp_die();
234
- }
235
- $popupsIdCollection = $popupParams['popupsIdCollection'];
236
-
237
- $popupsCounterData = get_option('SgpbCounter');
238
-
239
- if ($popupsCounterData === false) {
240
- $popupsCounterData = array();
241
- }
242
-
243
- if (!empty($popupsIdCollection)) {
244
- foreach ($popupsIdCollection as $popupId => $popupCount) {
245
- if (empty($popupsCounterData[$popupId])) {
246
- $popupsCounterData[$popupId] = 0;
247
- }
248
- $popupsCounterData[$popupId] += $popupCount;
249
- }
250
- }
251
-
252
- update_option('SgpbCounter', $popupsCounterData);
253
- wp_die();
254
- }
255
-
256
- public function deleteSubscribers()
257
- {
258
- global $wpdb;
259
-
260
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
261
-
262
- $subscribersId = array_map('sanitize_text_field', $_POST['subscribersId']);
263
-
264
- foreach ($subscribersId as $subscriberId) {
265
- $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE id = %d', $subscriberId);
266
- $wpdb->query($prepareSql);
267
- }
268
- }
269
-
270
- public function addSubscribers()
271
- {
272
- global $wpdb;
273
-
274
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
275
- $status = SGPB_AJAX_STATUS_FALSE;
276
- $firstName = sanitize_text_field($_POST['firstName']);
277
- $lastName = sanitize_text_field($_POST['lastName']);
278
- $email = sanitize_text_field($_POST['email']);
279
- $date = date('Y-m-d');
280
- $subscriptionPopupsId = array_map('sanitize_text_field', $_POST['popups']);
281
-
282
- foreach ($subscriptionPopupsId as $subscriptionPopupId) {
283
- $selectSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d', $email, $subscriptionPopupId);
284
- $res = $wpdb->get_row($selectSql, ARRAY_A);
285
- // add new subscriber
286
- if (empty($res)) {
287
- $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);
288
- $res = $wpdb->query($sql);
289
- }
290
- // edit existing
291
- else {
292
- $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']);
293
- $wpdb->query($sql);
294
- $res = 1;
295
- }
296
-
297
- if ($res) {
298
- $status = SGPB_AJAX_STATUS_TRUE;
299
- }
300
- }
301
-
302
- echo $status;
303
- wp_die();
304
- }
305
-
306
- public function importSubscribers()
307
- {
308
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
309
- $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
310
- $fileURL = sanitize_text_field($_POST['importListURL']);
311
- ob_start();
312
- require_once SG_POPUP_VIEWS_PATH.'importConfigView.php';
313
- $content = ob_get_contents();
314
- ob_end_clean();
315
-
316
- echo $content;
317
- wp_die();
318
- }
319
-
320
- public function saveImportedSubscribers()
321
- {
322
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
323
- @ini_set('auto_detect_line_endings', '1');
324
- $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
325
- $fileURL = sanitize_text_field($_POST['importListURL']);
326
- $mapping = $_POST['namesMapping'];
327
-
328
- $fileContent = AdminHelper::getFileFromURL($fileURL);
329
- $csvFileArray = array_map('str_getcsv', file($fileURL));
330
-
331
- $header = $csvFileArray[0];
332
- unset($csvFileArray[0]);
333
- $subscriptionPlusContent = apply_filters('sgpbImportToSubscriptionList', $csvFileArray, $mapping, $formId);
334
-
335
- // -1 it's mean saved from Subscription Plus
336
- if ($subscriptionPlusContent != -1) {
337
- foreach ($csvFileArray as $csvData) {
338
- global $wpdb;
339
- $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
340
- $sql = $wpdb->prepare('SELECT submittedData FROM '.$subscribersTableName);
341
- if (!empty($mapping['date'])) {
342
- $date = $csvData[$mapping['date']];
343
- $date = date('Y-m-d', strtotime($date));
344
- }
345
- if ($sql) {
346
- $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);
347
- }
348
- else {
349
- $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, '');
350
- }
351
-
352
- $wpdb->query($sql);
353
- }
354
- }
355
-
356
- echo SGPB_AJAX_STATUS_TRUE;
357
- wp_die();
358
- }
359
-
360
- public function sendNewsletter()
361
- {
362
- $allowToAction = AdminHelper::userCanAccessTo();
363
- if (!$allowToAction) {
364
- wp_redirect(get_home_url());
365
- exit();
366
- }
367
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
368
- global $wpdb;
369
-
370
- $newsletterData = stripslashes_deep($_POST['newsletterData']);
371
- if (isset($newsletterData['testSendingStatus']) && $newsletterData['testSendingStatus'] == 'test') {
372
- AdminHelper::sendTestNewsletter($newsletterData);
373
- }
374
- $subscriptionFormId = (int)$newsletterData['subscriptionFormId'];
375
-
376
- $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 0 WHERE subscriptionType = %d', $subscriptionFormId);
377
- $wpdb->query($updateStatusQuery);
378
- $newsletterData['blogname'] = get_bloginfo('name');
379
- $newsletterData['username'] = wp_get_current_user()->user_login;
380
- update_option('SGPB_NEWSLETTER_DATA', $newsletterData);
381
-
382
- wp_schedule_event(time(), 'sgpb_newsletter_send_every_minute', 'sgpb_send_newsletter');
383
- wp_die();
384
- }
385
-
386
- // proStartGold
387
- public function checkSameOrigin()
388
- {
389
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
390
-
391
- $url = esc_url($_POST['iframeUrl']);
392
- $status = SGPB_AJAX_STATUS_FALSE;
393
-
394
- $remoteGet = wp_remote_get($url);
395
-
396
- if (is_array($remoteGet) && !empty($remoteGet['headers']['x-frame-options'])) {
397
- $siteUrl = esc_url($_POST['siteUrl']);
398
- $xFrameOptions = $remoteGet['headers']['x-frame-options'];
399
- $mayNotShow = false;
400
-
401
- if ($xFrameOptions == 'deny') {
402
- $mayNotShow = true;
403
- }
404
- else if ($xFrameOptions == 'SAMEORIGIN') {
405
- if (strpos($url, $siteUrl) === false) {
406
- $mayNotShow = true;
407
- }
408
- }
409
- else {
410
- if (strpos($xFrameOptions, $siteUrl) === false) {
411
- $mayNotShow = true;;
412
- }
413
- }
414
-
415
- if ($mayNotShow) {
416
- echo $status;
417
- wp_die();
418
- }
419
- }
420
-
421
- // $remoteGet['response']['code'] < 400 it's mean correct status
422
- if (is_array($remoteGet) && isset($remoteGet['response']['code']) && $remoteGet['response']['code'] < 400) {
423
- $status = SGPB_AJAX_STATUS_TRUE;
424
- }
425
-
426
- echo $status;
427
- wp_die();
428
- }
429
- // proEndGold
430
-
431
- public function changePopupStatus()
432
- {
433
- $popupId = (int)$_POST['popupId'];
434
- $obj = SGPopup::find($popupId);
435
- $isDraft = '';
436
- $postStatus = get_post_status($popupId);
437
- if ($postStatus == 'draft') {
438
- $isDraft = '_preview';
439
- }
440
-
441
- if (!$obj) {
442
- wp_die(SGPB_AJAX_STATUS_FALSE);
443
- }
444
- $options = $obj->getOptions();
445
- $options['sgpb-is-active'] = sanitize_text_field($_POST['popupStatus']);
446
-
447
- unset($options['sgpb-conditions']);
448
- update_post_meta($popupId, 'sg_popup_options'.$isDraft, $options);
449
-
450
- wp_die($popupId);
451
- }
452
-
453
- public function subscriptionSubmission()
454
- {
455
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
456
- $this->setPostData($_POST);
457
- $submissionData = $this->getValueFromPost('formData');
458
- $popupPostId = (int)$this->getValueFromPost('popupPostId');
459
-
460
- parse_str($submissionData, $formData);
461
-
462
- if (empty($formData)) {
463
- echo SGPB_AJAX_STATUS_FALSE;
464
- wp_die();
465
- }
466
-
467
- $hiddenChecker = sanitize_text_field($formData['sgpb-subs-hidden-checker']);
468
-
469
- // this check is made to protect ourselves from bot
470
- if (!empty($hiddenChecker)) {
471
- echo 'Bot';
472
- wp_die();
473
- }
474
- global $wpdb;
475
-
476
- $status = SGPB_AJAX_STATUS_FALSE;
477
- $date = date('Y-m-d');
478
- $email = sanitize_email($formData['sgpb-subs-email']);
479
- $firstName = sanitize_text_field($formData['sgpb-subs-first-name']);
480
- $lastName = sanitize_text_field($formData['sgpb-subs-last-name']);
481
-
482
- $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
483
-
484
- $getSubscriberQuery = $wpdb->prepare('SELECT id FROM '.$subscribersTableName.' WHERE email = %s AND subscriptionType = %d', $email, $popupPostId);
485
- $list = $wpdb->get_row($getSubscriberQuery, ARRAY_A);
486
-
487
- // When subscriber does not exist we insert to subscribers table otherwise we update user info
488
- if (empty($list['id'])) {
489
- $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType) VALUES (%s, %s, %s, %s, %d) ', $firstName, $lastName, $email, $date, $popupPostId);
490
- $res = $wpdb->query($sql);
491
- }
492
- else {
493
- $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']);
494
- $wpdb->query($sql);
495
- $res = 1;
496
- }
497
- if ($res) {
498
- $status = SGPB_AJAX_STATUS_TRUE;
499
- }
500
-
501
- echo $status;
502
- wp_die();
503
- }
504
-
505
- public function sgpbSubsciptionFormSubmittedAction()
506
- {
507
- check_ajax_referer(SG_AJAX_NONCE, 'nonce');
508
- $this->setPostData($_POST);
509
-
510
- $submissionData = $this->getValueFromPost('formData');
511
- $popupPostId = (int)$this->getValueFromPost('popupPostId');
512
- parse_str($submissionData, $formData);
513
- if (empty($_POST)) {
514
- echo SGPB_AJAX_STATUS_FALSE;
515
- wp_die();
516
- }
517
- $email = sanitize_email($_POST['emailValue']);
518
- $firstName = sanitize_text_field($_POST['firstNameValue']);
519
- $lastName = sanitize_text_field($_POST['lastNameValue']);
520
- $userData = array(
521
- 'email' => $email,
522
- 'firstName' => $firstName,
523
- 'lastName' => $lastName
524
- );
525
- $this->sendSuccessEmails($popupPostId, $userData);
526
- do_action('sgpbProcessAfterSuccessfulSubmission', $popupPostId, $userData);
527
- }
528
-
529
- public function sendSuccessEmails($popupPostId, $subscriptionDetails)
530
- {
531
- global $wpdb;
532
- $popup = SGPopup::find($popupPostId);
533
-
534
- if (!is_object($popup)) {
535
- return false;
536
- }
537
- $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
538
-
539
- $getSubscriberCountQuery = $wpdb->prepare('SELECT COUNT(id) as countIds FROM '.$subscribersTableName.' WHERE subscriptionType = %d', $popupPostId);
540
- $count = $wpdb->get_row($getSubscriberCountQuery, ARRAY_A);
541
-
542
- $popupOptions = $popup->getOptions();
543
- $adminUserName = 'admin';
544
-
545
- $adminEmail = get_option('admin_email');
546
- $userData = @get_user_by_email($adminEmail);
547
-
548
- if (!empty($userData)) {
549
- $adminUserName = $userData->display_name;
550
- }
551
-
552
- $newSubscriberEmailHeader = AdminHelper::getEmailHeader($adminEmail);
553
- $takeReviewAfterFirstSubscription = get_option('sgpb-new-subscriber');
554
-
555
- if ($count['countIds'] == 1 && !$takeReviewAfterFirstSubscription) {
556
- // take review
557
- update_option('sgpb-new-subscriber', 1);
558
- $newSubscriberEmailTitle = __('Congrats! You have already 1 subscriber!', SG_POPUP_TEXT_DOMAIN);
559
- $reviewEmailTemplate = AdminHelper::getFileFromURL(SG_POPUP_EMAIL_TEMPLATES_URL.'takeReviewAfterSubscribe.html');
560
- $reviewEmailTemplate = preg_replace('/\[adminUserName]/', $adminUserName, $reviewEmailTemplate);
561
- $sendStatus = wp_mail($adminEmail, $newSubscriberEmailTitle, $reviewEmailTemplate, $newSubscriberEmailHeader); //return true or false
562
- }
563
- }
564
-
565
- public function select2SearchData()
566
- {
567
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
568
-
569
- $postTypeName = sanitize_text_field($_POST['searchKey']);
570
- $search = sanitize_text_field($_POST['searchTerm']);
571
- $searchResults = $this->selectFromPost($postTypeName, $search);
572
-
573
- if (isset($_POST['searchCallback'])) {
574
- $searchCallback = sanitize_text_field($_POST['searchCallback']);
575
- $searchResults = apply_filters('sgpbSearchAdditionalData', $search, array());
576
- }
577
-
578
- if (empty($searchResults)) {
579
- $results['items'] = array();
580
- }
581
-
582
- /*Selected custom post type convert for select2 format*/
583
- foreach ($searchResults as $id => $name) {
584
- $results['items'][] = array(
585
- 'id' => $id,
586
- 'text' => $name
587
- );
588
- }
589
-
590
- echo json_encode($results);
591
- wp_die();
592
- }
593
-
594
- private function selectFromPost($postTypeName, $search)
595
- {
596
- $args = array(
597
- 's' => $search,
598
- 'post__in' => ! empty( $_REQUEST['include'] ) ? array_map( 'intval', $_REQUEST['include'] ) : null,
599
- 'page' => ! empty( $_REQUEST['page'] ) ? absint( $_REQUEST['page'] ) : null,
600
- 'posts_per_page' => 100,
601
- 'post_type' => $postTypeName
602
- );
603
- $searchResults = ConfigDataHelper::getPostTypeData($args);
604
-
605
- return $searchResults;
606
- }
607
-
608
- public function addConditionGroupRow()
609
- {
610
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
611
- global $SGPB_DATA_CONFIG_ARRAY;
612
-
613
- $groupId = (int)$_POST['groupId'];
614
- $targetType = sanitize_text_field($_POST['conditionName']);
615
- $addedObj = array();
616
-
617
- $builderObj = new ConditionBuilder();
618
-
619
- $builderObj->setGroupId($groupId);
620
- $builderObj->setRuleId(SG_CONDITION_FIRST_RULE);
621
- $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
622
- $builderObj->setConditionName($targetType);
623
- $addedObj[] = $builderObj;
624
-
625
- $creator = new ConditionCreator($addedObj);
626
- echo $creator->render();
627
- wp_die();
628
- }
629
-
630
- public function addConditionRuleRow()
631
- {
632
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
633
- $data = '';
634
- global $SGPB_DATA_CONFIG_ARRAY;
635
- $targetType = sanitize_text_field($_POST['conditionName']);
636
- $builderObj = new ConditionBuilder();
637
-
638
- $groupId = (int)$_POST['groupId'];
639
- $ruleId = (int)$_POST['ruleId'];
640
-
641
- $builderObj->setGroupId($groupId);
642
- $builderObj->setRuleId($ruleId);
643
- $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
644
- $builderObj->setConditionName($targetType);
645
-
646
- $data .= ConditionCreator::createConditionRuleRow($builderObj);
647
-
648
- echo $data;
649
- wp_die();
650
- }
651
-
652
- public function changeConditionRuleRow()
653
- {
654
- check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
655
- $data = '';
656
- global $SGPB_DATA_CONFIG_ARRAY;
657
-
658
- $targetType = sanitize_text_field($_POST['conditionName']);
659
- $builderObj = new ConditionBuilder();
660
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$targetType];
661
- $groupId = (int)$_POST['groupId'];
662
- $ruleId = (int)$_POST['ruleId'];
663
- $popupId = (int)$_POST['popupId'];
664
- $paramName = sanitize_text_field($_POST['paramName']);
665
-
666
- $savedData = array(
667
- 'param' => $paramName
668
- );
669
-
670
- if ($targetType == 'target' || $targetType == 'conditions') {
671
- $savedData['operator'] = '==';
672
- }
673
- else if ($conditionConfig['specialDefaultOperator']) {
674
- $savedData['operator'] = $paramName;
675
- }
676
-
677
- if (!empty($_POST['paramValue'])) {
678
- $savedData['tempParam'] = sanitize_text_field($_POST['paramValue']);
679
- $savedData['operator'] = $paramName;
680
- }
681
- // change operator value related to condition value
682
- if (!empty($conditionConfig['operatorAllowInConditions']) && in_array($paramName, $conditionConfig['operatorAllowInConditions'])) {
683
- $conditionConfig['paramsData']['operator'] = array();
684
-
685
- if (!empty($conditionConfig['paramsData'][$paramName.'Operator'])) {
686
- $operatorData = $conditionConfig['paramsData'][$paramName.'Operator'];
687
- $SGPB_DATA_CONFIG_ARRAY[$targetType]['paramsData']['operator'] = $operatorData;
688
- // change take value related to condition value
689
- $operatorDataKeys = array_keys($operatorData);
690
- if (!empty($operatorDataKeys[0])) {
691
- $savedData['operator'] = $operatorDataKeys[0];
692
- $builderObj->setTakeValueFrom('operator');
693
- }
694
- }
695
- }
696
- // by default set empty value for users' role (adv. tar.)
697
- $savedData['value'] = array();
698
- $savedData['hiddenOption'] = @$conditionConfig['hiddenOptionData'][$paramName];
699
-
700
- $builderObj->setPopupId($popupId);
701
- $builderObj->setGroupId($groupId);
702
- $builderObj->setRuleId($ruleId);
703
- $builderObj->setSavedData($savedData);
704
- $builderObj->setConditionName($targetType);
705
-
706
- $data .= ConditionCreator::createConditionRuleRow($builderObj);
707
-
708
- echo $data;
709
- wp_die();
710
- }
711
- }
1
+ <?php
2
+ namespace sgpb;
3
+ use \ConfigDataHelper;
4
+
5
+ class Ajax
6
+ {
7
+ private $postData;
8
+
9
+ public function __construct()
10
+ {
11
+ $this->actions();
12
+ }
13
+
14
+ public function setPostData($postData)
15
+ {
16
+ $this->postData = $postData;
17
+ }
18
+
19
+ public function getPostData()
20
+ {
21
+ return $this->postData;
22
+ }
23
+
24
+ /**
25
+ * Return ajax param form post data by key
26
+ *
27
+ * @since 1.0.0
28
+ *
29
+ * @param string $key
30
+ *
31
+ * @return string $value
32
+ */
33
+ public function getValueFromPost($key)
34
+ {
35
+ $postData = $this->getPostData();
36
+ $value = '';
37
+
38
+ if (!empty($postData[$key])) {
39
+ $value = $postData[$key];
40
+ }
41
+
42
+ return $value;
43
+ }
44
+
45
+ public function actions()
46
+ {
47
+ add_action('wp_ajax_sgpb_send_to_open_counter', array($this, 'addToCounter'));
48
+ add_action('wp_ajax_nopriv_sgpb_send_to_open_counter', array($this, 'addToCounter'));
49
+
50
+ add_action('wp_ajax_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
51
+ add_action('wp_ajax_nopriv_sgpb_process_after_submission', array($this, 'sgpbSubsciptionFormSubmittedAction'));
52
+
53
+ add_action('wp_ajax_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
54
+ add_action('wp_ajax_nopriv_sgpb_subscription_submission', array($this, 'subscriptionSubmission'));
55
+
56
+ $allowToAction = AdminHelper::userCanAccessTo();
57
+
58
+ if ($allowToAction) {
59
+ add_action('wp_ajax_add_condition_group_row', array($this, 'addConditionGroupRow'));
60
+ add_action('wp_ajax_add_condition_rule_row', array($this, 'addConditionRuleRow'));
61
+ add_action('wp_ajax_change_condition_rule_row', array($this, 'changeConditionRuleRow'));
62
+ add_action('wp_ajax_select2_search_data', array($this, 'select2SearchData'));
63
+ add_action('wp_ajax_change_popup_status', array($this, 'changePopupStatus'));
64
+ // proStartGold
65
+ add_action('wp_ajax_check_same_origin', array($this, 'checkSameOrigin'));
66
+ // proEndGold
67
+ add_action('wp_ajax_sgpb_subscribers_delete', array($this, 'deleteSubscribers'));
68
+ add_action('wp_ajax_sgpb_add_subscribers', array($this, 'addSubscribers'));
69
+ add_action('wp_ajax_sgpb_import_subscribers', array($this, 'importSubscribers'));
70
+ add_action('wp_ajax_sgpb_save_imported_subscribers', array($this, 'saveImportedSubscribers'));
71
+ add_action('wp_ajax_sgpb_send_newsletter', array($this, 'sendNewsletter'));
72
+ add_action('wp_ajax_sgpb_change_review_popup_show_period', array($this, 'changeReviewPopupPeriod'));
73
+ add_action('wp_ajax_sgpb_dont_show_review_popup', array($this, 'dontShowReviewPopup'));
74
+ add_action('wp_ajax_sgpb_close_banner', array($this, 'closeMainRateUsBanner'));
75
+ add_action('wp_ajax_sgpb_close_license_notice', array($this, 'closeLicenseNoticeBanner'));
76
+ add_action('wp_ajax_sgpb_hide_ask_review_popup', array($this, 'dontShowAskReviewBanner'));
77
+ add_action('wp_ajax_sgpb_reset_popup_opening_count', array($this, 'resetPopupOpeningCount'));
78
+ /*Extension notification panel*/
79
+ add_action('wp_ajax_sgpb_dont_show_extension_panel', array($this, 'extensionNotificationPanel'));
80
+ add_action('wp_ajax_sgpb_dont_show_problem_alert', array($this, 'dontShowProblemAlert'));
81
+ // autosave
82
+ add_action('wp_ajax_sgpb_autosave', array($this, 'sgpbAutosave'));
83
+ }
84
+ }
85
+
86
+ public function sgpbAutosave()
87
+ {
88
+ $allowToAction = AdminHelper::userCanAccessTo();
89
+ if (!$allowToAction) {
90
+ wp_die('');
91
+ }
92
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
93
+
94
+ $popupId = @(int)$_POST['post_ID'];
95
+ $postStatus = get_post_status($popupId);
96
+ if ($postStatus == 'publish') {
97
+ wp_die('');
98
+ }
99
+
100
+ if (!isset($_POST['allPopupData'])) {
101
+ wp_die(true);
102
+ }
103
+ $popupData = SGPopup::parsePopupDataFromData($_POST['allPopupData']);
104
+ do_action('save_post_popupbuilder');
105
+ $popupType = $popupData['sgpb-type'];
106
+ $popupClassName = SGPopup::getPopupClassNameFormType($popupType);
107
+ $popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
108
+ if (file_exists($popupClassPath.$popupClassName.'.php')) {
109
+ require_once($popupClassPath.$popupClassName.'.php');
110
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
111
+ $popupClassName::create($popupData, '_preview', 1);
112
+ }
113
+
114
+ wp_die();
115
+ }
116
+
117
+ public function dontShowReviewPopup()
118
+ {
119
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
120
+ update_option('SGPBCloseReviewPopup-notification', true);
121
+ do_action('sgpbGetNotifications');
122
+ wp_die();
123
+ }
124
+
125
+ public function changeReviewPopupPeriod()
126
+ {
127
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
128
+ $messageType = sanitize_text_field($_POST['messageType']);
129
+
130
+ if ($messageType == 'count') {
131
+ $maxPopupCount = get_option('SGPBMaxOpenCount');
132
+ if (!$maxPopupCount) {
133
+ $maxPopupCount = SGPB_ASK_REVIEW_POPUP_COUNT;
134
+ }
135
+ $maxPopupData = AdminHelper::getMaxOpenPopupId();
136
+ if (!empty($maxPopupData['maxCount'])) {
137
+ $maxPopupCount = $maxPopupData['maxCount'];
138
+ }
139
+
140
+ $maxPopupCount += SGPB_ASK_REVIEW_POPUP_COUNT;
141
+ update_option('SGPBMaxOpenCount', $maxPopupCount);
142
+ wp_die();
143
+ }
144
+
145
+ $popupTimeZone = get_option('timezone_string');
146
+ if (!$popupTimeZone) {
147
+ $popupTimeZone = SG_POPUP_DEFAULT_TIME_ZONE;
148
+ }
149
+ $timeDate = new \DateTime('now', new \DateTimeZone($popupTimeZone));
150
+ $timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
151
+
152
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
153
+ update_option('SGPBOpenNextTime', $timeNow);
154
+ $usageDays = get_option('SGPBUsageDays');
155
+ $usageDays += SGPB_REVIEW_POPUP_PERIOD;
156
+ update_option('SGPBUsageDays', $usageDays);
157
+ wp_die();
158
+ }
159
+
160
+ public function resetPopupOpeningCount()
161
+ {
162
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
163
+
164
+ global $wpdb;
165
+
166
+ $tableName = $wpdb->prefix.'sgpb_analytics';
167
+ $popupId = (int)$_POST['popupId'];
168
+ $allPopupsCount = get_option('SgpbCounter');
169
+ if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
170
+ SGPopup::deleteAnalyticsDataByPopupId($popupId);
171
+ }
172
+ if (empty($allPopupsCount)) {
173
+ echo SGPB_AJAX_STATUS_FALSE;
174
+ wp_die();
175
+ }
176
+ if (isset($allPopupsCount[$popupId])) {
177
+ $allPopupsCount[$popupId] = 0;
178
+ }
179
+
180
+ // 7, 12, 13 => exclude close, subscription success, contact success events
181
+ $stmt = $wpdb->prepare(' DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
182
+ $popupAnalyticsData = $wpdb->get_var($stmt);
183
+
184
+ update_option('SgpbCounter', $allPopupsCount);
185
+
186
+ }
187
+
188
+ public function dontShowAskReviewBanner()
189
+ {
190
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
191
+ update_option('sgpbDontShowAskReviewBanner', 1);
192
+ echo SGPB_AJAX_STATUS_TRUE;
193
+ wp_die();
194
+ }
195
+
196
+ public function dontShowProblemAlert()
197
+ {
198
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
199
+ update_option('sgpb_alert_problems', 1);
200
+ echo SGPB_AJAX_STATUS_TRUE;
201
+ wp_die();
202
+ }
203
+
204
+ public function extensionNotificationPanel()
205
+ {
206
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
207
+ update_option('sgpb_extensions_updated', 1);
208
+ echo SGPB_AJAX_STATUS_TRUE;
209
+ wp_die();
210
+ }
211
+
212
+ public function closeMainRateUsBanner()
213
+ {
214
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
215
+ update_option('sgpb-hide-support-banner', 1);
216
+ do_action('sgpbGetNotifications');
217
+ wp_die();
218
+ }
219
+
220
+ public function closeLicenseNoticeBanner()
221
+ {
222
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
223
+ update_option('sgpb-hide-license-notice-banner', 1);
224
+ wp_die();
225
+ }
226
+
227
+ public function addToCounter()
228
+ {
229
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
230
+
231
+ $popupParams = $_POST['params'];
232
+ if (isset($_GET['sg_popup_preview_id'])) {
233
+ wp_die();
234
+ }
235
+ $popupsIdCollection = $popupParams['popupsIdCollection'];
236
+
237
+ $popupsCounterData = get_option('SgpbCounter');
238
+
239
+ if ($popupsCounterData === false) {
240
+ $popupsCounterData = array();
241
+ }
242
+
243
+ if (!empty($popupsIdCollection)) {
244
+ foreach ($popupsIdCollection as $popupId => $popupCount) {
245
+ if (empty($popupsCounterData[$popupId])) {
246
+ $popupsCounterData[$popupId] = 0;
247
+ }
248
+ $popupsCounterData[$popupId] += $popupCount;
249
+ }
250
+ }
251
+
252
+ update_option('SgpbCounter', $popupsCounterData);
253
+ wp_die();
254
+ }
255
+
256
+ public function deleteSubscribers()
257
+ {
258
+ global $wpdb;
259
+
260
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
261
+
262
+ $subscribersId = array_map('sanitize_text_field', $_POST['subscribersId']);
263
+
264
+ foreach ($subscribersId as $subscriberId) {
265
+ $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE id = %d', $subscriberId);
266
+ $wpdb->query($prepareSql);
267
+ }
268
+ }
269
+
270
+ public function addSubscribers()
271
+ {
272
+ global $wpdb;
273
+
274
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
275
+ $status = SGPB_AJAX_STATUS_FALSE;
276
+ $firstName = sanitize_text_field($_POST['firstName']);
277
+ $lastName = sanitize_text_field($_POST['lastName']);
278
+ $email = sanitize_text_field($_POST['email']);
279
+ $date = date('Y-m-d');
280
+ $subscriptionPopupsId = array_map('sanitize_text_field', $_POST['popups']);
281
+
282
+ foreach ($subscriptionPopupsId as $subscriptionPopupId) {
283
+ $selectSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d', $email, $subscriptionPopupId);
284
+ $res = $wpdb->get_row($selectSql, ARRAY_A);
285
+ // add new subscriber
286
+ if (empty($res)) {
287
+ $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);
288
+ $res = $wpdb->query($sql);
289
+ }
290
+ // edit existing
291
+ else {
292
+ $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']);
293
+ $wpdb->query($sql);
294
+ $res = 1;
295
+ }
296
+
297
+ if ($res) {
298
+ $status = SGPB_AJAX_STATUS_TRUE;
299
+ }
300
+ }
301
+
302
+ echo $status;
303
+ wp_die();
304
+ }
305
+
306
+ public function importSubscribers()
307
+ {
308
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
309
+ $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
310
+ $fileURL = sanitize_text_field($_POST['importListURL']);
311
+ ob_start();
312
+ require_once SG_POPUP_VIEWS_PATH.'importConfigView.php';
313
+ $content = ob_get_contents();
314
+ ob_end_clean();
315
+
316
+ echo $content;
317
+ wp_die();
318
+ }
319
+
320
+ public function saveImportedSubscribers()
321
+ {
322
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
323
+ @ini_set('auto_detect_line_endings', '1');
324
+ $formId = (int)sanitize_text_field($_POST['popupSubscriptionList']);
325
+ $fileURL = sanitize_text_field($_POST['importListURL']);
326
+ $mapping = $_POST['namesMapping'];
327
+
328
+ $fileContent = AdminHelper::getFileFromURL($fileURL);
329
+ $csvFileArray = array_map('str_getcsv', file($fileURL));
330
+
331
+ $header = $csvFileArray[0];
332
+ unset($csvFileArray[0]);
333
+ $subscriptionPlusContent = apply_filters('sgpbImportToSubscriptionList', $csvFileArray, $mapping, $formId);
334
+
335
+ // -1 it's mean saved from Subscription Plus
336
+ if ($subscriptionPlusContent != -1) {
337
+ foreach ($csvFileArray as $csvData) {
338
+ global $wpdb;
339
+ $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
340
+ $sql = $wpdb->prepare('SELECT submittedData FROM '.$subscribersTableName);
341
+ if (!empty($mapping['date'])) {
342
+ $date = $csvData[$mapping['date']];
343
+ $date = date('Y-m-d', strtotime($date));
344
+ }
345
+ if ($sql) {
346
+ $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);
347
+ }
348
+ else {
349
+ $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, '');
350
+ }
351
+
352
+ $wpdb->query($sql);
353
+ }
354
+ }
355
+
356
+ echo SGPB_AJAX_STATUS_TRUE;
357
+ wp_die();
358
+ }
359
+
360
+ public function sendNewsletter()
361
+ {
362
+ $allowToAction = AdminHelper::userCanAccessTo();
363
+ if (!$allowToAction) {
364
+ wp_redirect(get_home_url());
365
+ exit();
366
+ }
367
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
368
+ global $wpdb;
369
+
370
+ $newsletterData = stripslashes_deep($_POST['newsletterData']);
371
+ if (isset($newsletterData['testSendingStatus']) && $newsletterData['testSendingStatus'] == 'test') {
372
+ AdminHelper::sendTestNewsletter($newsletterData);
373
+ }
374
+ $subscriptionFormId = (int)$newsletterData['subscriptionFormId'];
375
+
376
+ $updateStatusQuery = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET status = 0 WHERE subscriptionType = %d', $subscriptionFormId);
377
+ $wpdb->query($updateStatusQuery);
378
+ $newsletterData['blogname'] = get_bloginfo('name');
379
+ $newsletterData['username'] = wp_get_current_user()->user_login;
380
+ update_option('SGPB_NEWSLETTER_DATA', $newsletterData);
381
+
382
+ wp_schedule_event(time(), 'sgpb_newsletter_send_every_minute', 'sgpb_send_newsletter');
383
+ wp_die();
384
+ }
385
+
386
+ // proStartGold
387
+ public function checkSameOrigin()
388
+ {
389
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
390
+
391
+ $url = esc_url($_POST['iframeUrl']);
392
+ $status = SGPB_AJAX_STATUS_FALSE;
393
+
394
+ $remoteGet = wp_remote_get($url);
395
+
396
+ if (is_array($remoteGet) && !empty($remoteGet['headers']['x-frame-options'])) {
397
+ $siteUrl = esc_url($_POST['siteUrl']);
398
+ $xFrameOptions = $remoteGet['headers']['x-frame-options'];
399
+ $mayNotShow = false;
400
+
401
+ if ($xFrameOptions == 'deny') {
402
+ $mayNotShow = true;
403
+ }
404
+ else if ($xFrameOptions == 'SAMEORIGIN') {
405
+ if (strpos($url, $siteUrl) === false) {
406
+ $mayNotShow = true;
407
+ }
408
+ }
409
+ else {
410
+ if (strpos($xFrameOptions, $siteUrl) === false) {
411
+ $mayNotShow = true;;
412
+ }
413
+ }
414
+
415
+ if ($mayNotShow) {
416
+ echo $status;
417
+ wp_die();
418
+ }
419
+ }
420
+
421
+ // $remoteGet['response']['code'] < 400 it's mean correct status
422
+ if (is_array($remoteGet) && isset($remoteGet['response']['code']) && $remoteGet['response']['code'] < 400) {
423
+ $status = SGPB_AJAX_STATUS_TRUE;
424
+ }
425
+
426
+ echo $status;
427
+ wp_die();
428
+ }
429
+ // proEndGold
430
+
431
+ public function changePopupStatus()
432
+ {
433
+ $popupId = (int)$_POST['popupId'];
434
+ $obj = SGPopup::find($popupId);
435
+ $isDraft = '';
436
+ $postStatus = get_post_status($popupId);
437
+ if ($postStatus == 'draft') {
438
+ $isDraft = '_preview';
439
+ }
440
+
441
+ if (!$obj) {
442
+ wp_die(SGPB_AJAX_STATUS_FALSE);
443
+ }
444
+ $options = $obj->getOptions();
445
+ $options['sgpb-is-active'] = sanitize_text_field($_POST['popupStatus']);
446
+
447
+ unset($options['sgpb-conditions']);
448
+ update_post_meta($popupId, 'sg_popup_options'.$isDraft, $options);
449
+
450
+ wp_die($popupId);
451
+ }
452
+
453
+ public function subscriptionSubmission()
454
+ {
455
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
456
+ $this->setPostData($_POST);
457
+ $submissionData = $this->getValueFromPost('formData');
458
+ $popupPostId = (int)$this->getValueFromPost('popupPostId');
459
+
460
+ parse_str($submissionData, $formData);
461
+
462
+ if (empty($formData)) {
463
+ echo SGPB_AJAX_STATUS_FALSE;
464
+ wp_die();
465
+ }
466
+
467
+ $hiddenChecker = sanitize_text_field($formData['sgpb-subs-hidden-checker']);
468
+
469
+ // this check is made to protect ourselves from bot
470
+ if (!empty($hiddenChecker)) {
471
+ echo 'Bot';
472
+ wp_die();
473
+ }
474
+ global $wpdb;
475
+
476
+ $status = SGPB_AJAX_STATUS_FALSE;
477
+ $date = date('Y-m-d');
478
+ $email = sanitize_email($formData['sgpb-subs-email']);
479
+ $firstName = sanitize_text_field($formData['sgpb-subs-first-name']);
480
+ $lastName = sanitize_text_field($formData['sgpb-subs-last-name']);
481
+
482
+ $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
483
+
484
+ $getSubscriberQuery = $wpdb->prepare('SELECT id FROM '.$subscribersTableName.' WHERE email = %s AND subscriptionType = %d', $email, $popupPostId);
485
+ $list = $wpdb->get_row($getSubscriberQuery, ARRAY_A);
486
+
487
+ // When subscriber does not exist we insert to subscribers table otherwise we update user info
488
+ if (empty($list['id'])) {
489
+ $sql = $wpdb->prepare('INSERT INTO '.$subscribersTableName.' (firstName, lastName, email, cDate, subscriptionType) VALUES (%s, %s, %s, %s, %d) ', $firstName, $lastName, $email, $date, $popupPostId);
490
+ $res = $wpdb->query($sql);
491
+ }
492
+ else {
493
+ $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']);
494
+ $wpdb->query($sql);
495
+ $res = 1;
496
+ }
497
+ if ($res) {
498
+ $status = SGPB_AJAX_STATUS_TRUE;
499
+ }
500
+
501
+ echo $status;
502
+ wp_die();
503
+ }
504
+
505
+ public function sgpbSubsciptionFormSubmittedAction()
506
+ {
507
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce');
508
+ $this->setPostData($_POST);
509
+
510
+ $submissionData = $this->getValueFromPost('formData');
511
+ $popupPostId = (int)$this->getValueFromPost('popupPostId');
512
+ parse_str($submissionData, $formData);
513
+ if (empty($_POST)) {
514
+ echo SGPB_AJAX_STATUS_FALSE;
515
+ wp_die();
516
+ }
517
+ $email = sanitize_email($_POST['emailValue']);
518
+ $firstName = sanitize_text_field($_POST['firstNameValue']);
519
+ $lastName = sanitize_text_field($_POST['lastNameValue']);
520
+ $userData = array(
521
+ 'email' => $email,
522
+ 'firstName' => $firstName,
523
+ 'lastName' => $lastName
524
+ );
525
+ $this->sendSuccessEmails($popupPostId, $userData);
526
+ do_action('sgpbProcessAfterSuccessfulSubmission', $popupPostId, $userData);
527
+ }
528
+
529
+ public function sendSuccessEmails($popupPostId, $subscriptionDetails)
530
+ {
531
+ global $wpdb;
532
+ $popup = SGPopup::find($popupPostId);
533
+
534
+ if (!is_object($popup)) {
535
+ return false;
536
+ }
537
+ $subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
538
+
539
+ $getSubscriberCountQuery = $wpdb->prepare('SELECT COUNT(id) as countIds FROM '.$subscribersTableName.' WHERE subscriptionType = %d', $popupPostId);
540
+ $count = $wpdb->get_row($getSubscriberCountQuery, ARRAY_A);
541
+
542
+ $popupOptions = $popup->getOptions();
543
+ $adminUserName = 'admin';
544
+
545
+ $adminEmail = get_option('admin_email');
546
+ $userData = @get_user_by('email', $adminEmail);
547
+
548
+ if (!empty($userData)) {
549
+ $adminUserName = $userData->display_name;
550
+ }
551
+
552
+ $newSubscriberEmailHeader = AdminHelper::getEmailHeader($adminEmail);
553
+ $takeReviewAfterFirstSubscription = get_option('sgpb-new-subscriber');
554
+
555
+ if ($count['countIds'] == 1 && !$takeReviewAfterFirstSubscription) {
556
+ // take review
557
+ update_option('sgpb-new-subscriber', 1);
558
+ $newSubscriberEmailTitle = __('Congrats! You have already 1 subscriber!', SG_POPUP_TEXT_DOMAIN);
559
+ $reviewEmailTemplate = AdminHelper::getFileFromURL(SG_POPUP_EMAIL_TEMPLATES_URL.'takeReviewAfterSubscribe.html');
560
+ $reviewEmailTemplate = preg_replace('/\[adminUserName]/', $adminUserName, $reviewEmailTemplate);
561
+ $sendStatus = wp_mail($adminEmail, $newSubscriberEmailTitle, $reviewEmailTemplate, $newSubscriberEmailHeader); //return true or false
562
+ }
563
+ }
564
+
565
+ public function select2SearchData()
566
+ {
567
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
568
+
569
+ $postTypeName = sanitize_text_field($_POST['searchKey']);
570
+ $search = sanitize_text_field($_POST['searchTerm']);
571
+ $searchResults = $this->selectFromPost($postTypeName, $search);
572
+
573
+ if (isset($_POST['searchCallback'])) {
574
+ $searchCallback = sanitize_text_field($_POST['searchCallback']);
575
+ $searchResults = apply_filters('sgpbSearchAdditionalData', $search, array());
576
+ }
577
+
578
+ if (empty($searchResults)) {
579
+ $results['items'] = array();
580
+ }
581
+
582
+ /*Selected custom post type convert for select2 format*/
583
+ foreach ($searchResults as $id => $name) {
584
+ $results['items'][] = array(
585
+ 'id' => $id,
586
+ 'text' => $name
587
+ );
588
+ }
589
+
590
+ echo json_encode($results);
591
+ wp_die();
592
+ }
593
+
594
+ private function selectFromPost($postTypeName, $search)
595
+ {
596
+ $args = array(
597
+ 's' => $search,
598
+ 'post__in' => ! empty( $_REQUEST['include'] ) ? array_map( 'intval', $_REQUEST['include'] ) : null,
599
+ 'page' => ! empty( $_REQUEST['page'] ) ? absint( $_REQUEST['page'] ) : null,
600
+ 'posts_per_page' => 100,
601
+ 'post_type' => $postTypeName
602
+ );
603
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
604
+
605
+ return $searchResults;
606
+ }
607
+
608
+ public function addConditionGroupRow()
609
+ {
610
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
611
+ global $SGPB_DATA_CONFIG_ARRAY;
612
+
613
+ $groupId = (int)$_POST['groupId'];
614
+ $targetType = sanitize_text_field($_POST['conditionName']);
615
+ $addedObj = array();
616
+
617
+ $builderObj = new ConditionBuilder();
618
+
619
+ $builderObj->setGroupId($groupId);
620
+ $builderObj->setRuleId(SG_CONDITION_FIRST_RULE);
621
+ $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
622
+ $builderObj->setConditionName($targetType);
623
+ $addedObj[] = $builderObj;
624
+
625
+ $creator = new ConditionCreator($addedObj);
626
+ echo $creator->render();
627
+ wp_die();
628
+ }
629
+
630
+ public function addConditionRuleRow()
631
+ {
632
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
633
+ $data = '';
634
+ global $SGPB_DATA_CONFIG_ARRAY;
635
+ $targetType = sanitize_text_field($_POST['conditionName']);
636
+ $builderObj = new ConditionBuilder();
637
+
638
+ $groupId = (int)$_POST['groupId'];
639
+ $ruleId = (int)$_POST['ruleId'];
640
+
641
+ $builderObj->setGroupId($groupId);
642
+ $builderObj->setRuleId($ruleId);
643
+ $builderObj->setSavedData($SGPB_DATA_CONFIG_ARRAY[$targetType]['initialData'][0]);
644
+ $builderObj->setConditionName($targetType);
645
+
646
+ $data .= ConditionCreator::createConditionRuleRow($builderObj);
647
+
648
+ echo $data;
649
+ wp_die();
650
+ }
651
+
652
+ public function changeConditionRuleRow()
653
+ {
654
+ check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
655
+ $data = '';
656
+ global $SGPB_DATA_CONFIG_ARRAY;
657
+
658
+ $targetType = sanitize_text_field($_POST['conditionName']);
659
+ $builderObj = new ConditionBuilder();
660
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$targetType];
661
+ $groupId = (int)$_POST['groupId'];
662
+ $ruleId = (int)$_POST['ruleId'];
663
+ $popupId = (int)$_POST['popupId'];
664
+ $paramName = sanitize_text_field($_POST['paramName']);
665
+
666
+ $savedData = array(
667
+ 'param' => $paramName
668
+ );
669
+
670
+ if ($targetType == 'target' || $targetType == 'conditions') {
671
+ $savedData['operator'] = '==';
672
+ }
673
+ else if ($conditionConfig['specialDefaultOperator']) {
674
+ $savedData['operator'] = $paramName;
675
+ }
676
+
677
+ if (!empty($_POST['paramValue'])) {
678
+ $savedData['tempParam'] = sanitize_text_field($_POST['paramValue']);
679
+ $savedData['operator'] = $paramName;
680
+ }
681
+ // change operator value related to condition value
682
+ if (!empty($conditionConfig['operatorAllowInConditions']) && in_array($paramName, $conditionConfig['operatorAllowInConditions'])) {
683
+ $conditionConfig['paramsData']['operator'] = array();
684
+
685
+ if (!empty($conditionConfig['paramsData'][$paramName.'Operator'])) {
686
+ $operatorData = $conditionConfig['paramsData'][$paramName.'Operator'];
687
+ $SGPB_DATA_CONFIG_ARRAY[$targetType]['paramsData']['operator'] = $operatorData;
688
+ // change take value related to condition value
689
+ $operatorDataKeys = array_keys($operatorData);
690
+ if (!empty($operatorDataKeys[0])) {
691
+ $savedData['operator'] = $operatorDataKeys[0];
692
+ $builderObj->setTakeValueFrom('operator');
693
+ }
694
+ }
695
+ }
696
+ // by default set empty value for users' role (adv. tar.)
697
+ $savedData['value'] = array();
698
+ $savedData['hiddenOption'] = @$conditionConfig['hiddenOptionData'][$paramName];
699
+
700
+ $builderObj->setPopupId($popupId);
701
+ $builderObj->setGroupId($groupId);
702
+ $builderObj->setRuleId($ruleId);
703
+ $builderObj->setSavedData($savedData);
704
+ $builderObj->setConditionName($targetType);
705
+
706
+ $data .= ConditionCreator::createConditionRuleRow($builderObj);
707
+
708
+ echo $data;
709
+ wp_die();
710
+ }
711
+ }
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,660 +1,660 @@
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="sg-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="sg-target-rule sg-target-rule-<?php echo $conditionDataObj->getRuleId(); ?> sgpb-event-row" data-rule-id="<?php echo $conditionDataObj->getRuleId(); ?>">
85
- <div class="row">
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) ? 'sg-hide-condition-row' : $showRowStatusClass;
106
- ?>
107
- <?php if ($conditionName != 'hiddenOption'): ?>
108
- <div data-condition-name="<?php echo $conditionName;?>" class="<?php echo 'col-sm-3 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="sg-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
-
197
- if (empty($operatorsData)) {
198
- return $operatorsHtml;
199
- }
200
-
201
- foreach ($operatorsData as $operator) {
202
- $identificatorClass = '';
203
- $style = '';
204
- if (!isset($eventsData['hiddenOptionData'])) {
205
- continue;
206
- }
207
- $saveData = $conditionDataObj->getSavedData();
208
- if (empty($saveData['hiddenOption']) && $operator['name'] == 'Edit' && $saveData["param"] != 'load') {
209
- continue;
210
- }
211
- if ($operator['operator'] == 'edit') {
212
- $identificatorClass = $idHiddenDiv;
213
- $eventButtonClasses = 'btn btn-success btn-xs';
214
- $eventButtonWrapperClass = 'col-sm-2 ';
215
- }
216
- if ($operator['operator'] == 'add') {
217
- $eventButtonClasses = 'btn btn-primary btn-xs';
218
- $eventButtonWrapperClass = 'col-sm-2 ';
219
- $style = '';
220
- //Don't show add button if it's not for last element
221
- if ($groupId < $groupTotal) {
222
- $style = 'style="display: none;"';
223
- }
224
- }
225
- if ($operator['operator'] == 'delete') {
226
- $eventButtonClasses = 'btn btn-danger btn-xs';
227
- $eventButtonWrapperClass = 'col-sm-1 ';
228
- }
229
- if ($operator['name'] == 'Edit') {
230
- $operator['name'] = 'Settings';
231
- }
232
-
233
- $operatorsHtml .= '<div class="'.$eventButtonWrapperClass.'sg-rules-'.$operator['operator'].'-button-wrapper sgpb-static-padding-top" '.$style.'>';
234
- $operatorsHtml .= '<a href="javascript:void(0)" class="sg-rules-'.$operator['operator'].'-rule '.$eventButtonClasses.'" data-id="'.$identificatorClass.'"><span>'.__(' '.$operator['name'], SG_POPUP_TEXT_DOMAIN).'</span></a>';
235
- $operatorsHtml .= '</div>';
236
- }
237
-
238
- return $operatorsHtml;
239
- }
240
-
241
- public static function createConditionElement($conditionDataObj, $ruleName)
242
- {
243
- //more code added because of the lack of abstraction
244
- //todo: remove ASAP if possible
245
- $sData = $conditionDataObj->getSavedData();
246
- if ($ruleName == 'param' && !empty($sData['tempParam'])) {
247
- $sData['param'] = $sData['tempParam'];
248
- $newObj = clone $conditionDataObj;
249
- $newObj->setSavedData($sData);
250
- $conditionDataObj = $newObj;
251
- }
252
-
253
- $element = '';
254
-
255
- $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
256
- $elementHeader = self::createRuleHeader($ruleElementData);
257
- $field = self::createRuleField($ruleElementData);
258
- $element .= $elementHeader;
259
- $element .= $field;
260
-
261
- return $element;
262
- }
263
-
264
- public static function createConditionField($conditionDataObj, $ruleName)
265
- {
266
- $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
267
-
268
- return self::createRuleField($ruleElementData);
269
- }
270
-
271
- public static function createConditionFieldHeader($conditionDataObj, $ruleName)
272
- {
273
- $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
274
-
275
- return self::createRuleHeader($ruleElementData);
276
- }
277
-
278
- public static function optionLabelSupplement($conditionDataObj, $ruleName)
279
- {
280
- global $SGPB_DATA_CONFIG_ARRAY;
281
- $conditionName = $conditionDataObj->getConditionName();
282
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
283
- $attrs = $conditionConfig['attrs'][$ruleName];
284
-
285
- if (isset($attrs['infoAttrs']['rightLabel'])) {
286
- $labelData = $attrs['infoAttrs']['rightLabel'];
287
- $value = $labelData['value'];
288
- $classes = $labelData['classes'];
289
- return '<span class="'.esc_attr($classes).'">'.$value.'</span>';
290
- }
291
-
292
- return '';
293
- }
294
-
295
- private static function getRuleElementData($conditionDataObj, $ruleName = '')
296
- {
297
- global $SGPB_DATA_CONFIG_ARRAY;
298
- $ruleElementData = array();
299
- $savedParam = '';
300
- $conditionName = $conditionDataObj->getConditionName();
301
- $saveData = $conditionDataObj->getSavedData();
302
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
303
- $rulesType = $conditionConfig['columnTypes'];
304
- $paramsData = $conditionConfig['paramsData'];
305
-
306
- $attrs = $conditionConfig['attrs'];
307
-
308
- if (!empty($saveData[$ruleName])) {
309
- $savedParam = $saveData[$ruleName];
310
- }
311
- else if (!empty($saveData['hiddenOption']) && isset($saveData['hiddenOption'][$ruleName])) {
312
- $savedParam = $saveData['hiddenOption'][$ruleName];
313
- }
314
-
315
- $ruleElementData['ruleName'] = $ruleName;
316
- if ($ruleName == 'value' && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
317
- $index = $conditionDataObj->getTakeValueFrom();
318
- $ruleName = $saveData[$index];
319
- }
320
-
321
- $type = array();
322
- if (!empty($rulesType[$ruleName])) {
323
- $type = $rulesType[$ruleName];
324
- }
325
- $data = array();
326
- if (!empty($paramsData[$ruleName])) {
327
- $data = $paramsData[$ruleName];
328
- }
329
-
330
- // if exists customOperator it takes the custom one
331
- if ($ruleName == 'operator' && !empty($paramsData['customOperator'])) {
332
- $data = $paramsData['customOperator'];
333
- }
334
-
335
- $optionAttr = array();
336
- if (!empty($attrs[$ruleName])) {
337
- $optionAttr = $attrs[$ruleName];
338
- }
339
-
340
- $attr = array();
341
-
342
- if (!empty($optionAttr['htmlAttrs'])) {
343
- $attr = $optionAttr['htmlAttrs'];
344
- }
345
-
346
- $ruleElementData['type'] = $type;
347
- $ruleElementData['data'] = apply_filters('sgpb'.$ruleName.'ConditionCreator', $data, $saveData);
348
- $ruleElementData['saved'] = $savedParam;
349
- $ruleElementData['attr'] = $attr;
350
- $ruleElementData['conditionDataObj'] = $conditionDataObj;
351
-
352
- return $ruleElementData;
353
- }
354
-
355
- private static function createRuleHeader($ruleElementData)
356
- {
357
- return self::createElementHeader($ruleElementData);
358
- }
359
-
360
- public static function createRuleField($ruleElementData)
361
- {
362
- $attr = array();
363
- $type = $ruleElementData['type'];
364
- $conditionObj = $ruleElementData['conditionDataObj'];
365
-
366
- $name = 'sgpb-'.$conditionObj->getConditionName().'['.$conditionObj->getGroupId().']['.$conditionObj->getRuleId().']['.$ruleElementData['ruleName'].']';
367
- $attr['name'] = $name;
368
-
369
- if (is_array($ruleElementData['attr'])) {
370
- $attr += $ruleElementData['attr'];
371
- $attr['data-rule-id'] = $conditionObj->getRuleId();
372
- }
373
- $rowField = '';
374
-
375
- switch($type) {
376
-
377
- case 'select':
378
- if (!empty($attr['multiple'])) {
379
- $attr['name'] .= '[]';
380
- }
381
- $savedData = $ruleElementData['saved'];
382
-
383
- if (empty($ruleElementData['data'])) {
384
- $ruleElementData['data'] = $ruleElementData['saved'];
385
- $savedData = array();
386
-
387
- if (!empty($ruleElementData['saved'])) {
388
- $savedData = array_keys($ruleElementData['saved']);
389
- }
390
- }
391
-
392
- $rowField .= AdminHelper::createSelectBox($ruleElementData['data'], $savedData, $attr);
393
- break;
394
- case 'text':
395
- case 'url':
396
- case 'number':
397
- $attr['type'] = $type;
398
-
399
- //this is done to override the initial input value
400
- if (!empty($ruleElementData['saved'])) {
401
- $attr['value'] = esc_attr($ruleElementData['saved']);
402
- }
403
-
404
- $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'], $attr);
405
- break;
406
- case 'checkbox':
407
- $attr['type'] = $type;
408
- $rowField .= AdminHelper::createCheckBox($ruleElementData['data'], $ruleElementData['saved'], $attr);
409
- break;
410
- case 'conditionalText':
411
- $popupId = self::getPopupId($conditionObj);
412
- if(!empty($popupId)) {
413
- $attr['value'] = $attr['value'].$popupId;
414
- $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'].$popupId, $attr);
415
- }
416
- else {
417
- $rowField .= '<div class="sgpb-show-alert-before-save">'.$attr['beforeSaveLabel'].'</div>';
418
- }
419
- break;
420
- }
421
-
422
- return $rowField;
423
- }
424
-
425
- public static function getPopupId($conditionObj)
426
- {
427
- $popupId = 0;
428
- $conditionPopupId = $conditionObj->getPopupId();
429
-
430
- if (!empty($conditionPopupId)) {
431
- $popupId = $conditionObj->getPopupId();
432
- }
433
- else if(!empty($_GET['post'])) {
434
- $popupId = $_GET['post'];
435
- }
436
-
437
- return $popupId;
438
- }
439
-
440
- public static function createElementHeader($ruleElementData)
441
- {
442
- $labelAttributes = '';
443
- $info = '';
444
- $conditionObj = $ruleElementData['conditionDataObj'];
445
- $conditionName = $conditionObj->getConditionName();
446
- $ruleName = $ruleElementData['ruleName'];
447
- global $SGPB_DATA_CONFIG_ARRAY;
448
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
449
- $conditionAttrs = $conditionConfig['attrs'];
450
-
451
- $saveData = $conditionObj->getSavedData();
452
- $optionTitle = $ruleName;
453
- $titleKey = $ruleName;
454
-
455
-
456
- if ($ruleName == 'value' && !empty($saveData[$conditionObj->getTakeValueFrom()])) {
457
- $titleKey = $saveData[$conditionObj->getTakeValueFrom()];
458
- }
459
-
460
- if (!empty($conditionAttrs[$titleKey])) {
461
- $optionAttrs = $conditionAttrs[$titleKey];
462
- if (!empty($optionAttrs['infoAttrs'])) {
463
- // $conditionName => events, conditions, targets...
464
- // $ruleName => param, operator, value (1-st, 2-nd, 3-rd columns)
465
- $optionAttrs = apply_filters('sgpb'.$conditionName.$ruleName.'Param', $optionAttrs, $saveData);
466
- $optionTitle = $optionAttrs['infoAttrs']['label'];
467
- if (!empty($optionAttrs['infoAttrs']['labelAttrs'])) {
468
- $labelAttributes = AdminHelper::createAttrs($optionAttrs['infoAttrs']['labelAttrs']);
469
- }
470
- }
471
- }
472
- if (isset($optionAttrs['infoAttrs']['info']) && $optionAttrs['infoAttrs']['info']) {
473
- $info .= '<span class="dashicons dashicons-editor-help sgpb-info-icon sgpb-info-icon-align"></span>';
474
- $info .= '<span class="infoSelectRepeat samefontStyle sgpb-info-text">'.$optionAttrs['infoAttrs']['info'].'</span>';
475
- }
476
-
477
- return "<label $labelAttributes>$optionTitle</label>$info";
478
- }
479
-
480
- public static function getHiddenDataContent($conditionDataObj)
481
- {
482
- global $SGPB_DATA_CONFIG_ARRAY;
483
- $savedData = $conditionDataObj->getSavedData();
484
- $conditionName = $savedData['param'];
485
- $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
486
- $hiddenOptions = $eventsData['hiddenOptionData'];
487
- $ruleId = $conditionDataObj->getRuleId();
488
- if (empty($hiddenOptions[$conditionName])) {
489
- return __('No Data', SG_POPUP_TEXT_DOMAIN);
490
- }
491
-
492
- $hiddenOptionsData = $hiddenOptions[$conditionName];
493
-
494
- $tabs = array_keys($hiddenOptionsData);
495
- ob_start();
496
- ?>
497
-
498
- <div class="sgpb-wrapper">
499
- <div class="tab">
500
- <?php
501
- $activeTab = '';
502
- if (!empty($tabs[0])) {
503
- $activeTab = $tabs[0];
504
- }
505
- ?>
506
- <?php foreach ($tabs as $tab): ?>
507
- <?php
508
- $activeClassName = '';
509
- if ($activeTab == $tab) {
510
- $activeClassName = 'sgpb-active';
511
- }
512
- ?>
513
- <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>
514
- <?php endforeach;?>
515
- </div>
516
- <?php echo self::createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId); ?>
517
- <div class="modal-footer">
518
- <button type="button" class="sgpb-no-button events-option-close btn btn-default btn-sm" href="#"><?php _e('Cancel', SG_POPUP_TEXT_DOMAIN); ?></button>
519
- <button class="btn btn-primary btn-sm sgpb-popup-option-save"><?php _e('Save', SG_POPUP_TEXT_DOMAIN); ?></button>
520
- </div>
521
- </div>
522
- <?php
523
- $hiddenPopupContent = ob_get_contents();
524
- ob_end_clean();
525
-
526
- return $hiddenPopupContent;
527
- }
528
-
529
- private static function createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId)
530
- {
531
- ob_start();
532
- ?>
533
- <?php foreach ($hiddenOptionsData as $key => $hiddenData): ?>
534
- <div id="<?php echo $key.'-'.$ruleId; ?>" class="sgpb-tab-content-<?php echo $ruleId;?>">
535
- <div id="<?php echo $key; ?>" class="sgpb-tab-content-options">
536
- <?php foreach ($hiddenData as $name => $label): ?>
537
- <?php
538
- $hiddenOptionsView = self::optionLabelSupplement($conditionDataObj, $name);
539
- $colMdValue = 6;
540
- if (!empty($hiddenOptionsView)) {
541
- $colMdValue = 2;
542
- }
543
- ?>
544
- <div class="row form-group">
545
- <div class="col-md-6">
546
- <?php echo self::createConditionFieldHeader($conditionDataObj, $name); ?>
547
- </div>
548
- <div class="col-md-<?php echo $colMdValue; ?>">
549
- <?php echo self::createConditionField($conditionDataObj, $name); ?>
550
- </div>
551
- <?php if (!empty($hiddenOptionsView)): ?>
552
- <div class="col-md-4">
553
- <?php echo $hiddenOptionsView; ?>
554
- </div>
555
- <?php endif; ?>
556
- </div>
557
- <?php endforeach; ?>
558
- </div>
559
- </div>
560
- <?php endforeach;?>
561
- <?php
562
- $hiddenPopupContent = ob_get_contents();
563
- ob_end_clean();
564
-
565
- return $hiddenPopupContent;
566
- }
567
-
568
- public static function hiddenSubOptionsView($parentOptionName, $conditionDataObj)
569
- {
570
- $subOptionsContent = '';
571
- $subOptions = self::getHiddenOptionSubOptions($parentOptionName);
572
- if (!empty($subOptions)) {
573
- $subOptionsContent = self::createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions);
574
- }
575
-
576
- return $subOptionsContent;
577
- }
578
-
579
- private static function createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions)
580
- {
581
- $name = $parentOptionName;
582
- ob_start();
583
- ?>
584
- <div class="row <?php echo 'sgpb-popup-hidden-content-'.$name.'-'.$conditionDataObj->getRuleId().'-wrapper'?> form-group">
585
- <?php foreach ($subOptions as $subOption): ?>
586
- <div class="col-md-6">
587
- <?php echo self::createConditionFieldHeader($conditionDataObj, $subOption); ?>
588
- </div>
589
- <div class="col-md-6">
590
- <?php echo self::createConditionField($conditionDataObj, $subOption); ?>
591
- </div>
592
- <?php echo self::hiddenSubOptionsView($subOption, $conditionDataObj)?>
593
- <?php endforeach;?>
594
- </div>
595
- <?php
596
- $hiddenPopupContent = ob_get_contents();
597
- ob_end_clean();
598
-
599
- return $hiddenPopupContent;
600
- }
601
-
602
- public static function getHiddenOptionSubOptions($optionName)
603
- {
604
- global $SGPB_DATA_CONFIG_ARRAY;
605
- $childOptionNames = array();
606
- $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
607
- $targetDataAttrs = $eventsData['attrs'];
608
-
609
- if (empty($targetDataAttrs[$optionName])) {
610
- return $childOptionNames;
611
- }
612
-
613
- if (empty($targetDataAttrs[$optionName]['childOptions'])) {
614
- return $childOptionNames;
615
- }
616
- $childOptionNames = $targetDataAttrs[$optionName]['childOptions'];
617
-
618
- return $childOptionNames;
619
- }
620
-
621
- private static function getParamRowHideStatus($conditionDataObj, $ruleName)
622
- {
623
- global $SGPB_DATA_CONFIG_ARRAY;
624
- if ($ruleName == 'hiddenOption') {
625
- return '';
626
- }
627
- $status = false;
628
- $conditionName = $conditionDataObj->getConditionName();
629
- $saveData = $conditionDataObj->getSavedData();
630
- $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
631
- $paramsData = array();
632
- if (!empty($conditionConfig['paramsData'])) {
633
- $paramsData = $conditionConfig['paramsData'];
634
- }
635
-
636
- $ruleElementData['ruleName'] = $ruleName;
637
- if ($ruleName == 'value' && !empty($saveData) && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
638
- $ruleName = $saveData[$conditionDataObj->getTakeValueFrom()];
639
- }
640
- if ((!isset($paramsData[$ruleName]) && empty($paramsData[$ruleName])) || is_null($paramsData[$ruleName])) {
641
- $status = true;
642
- }
643
-
644
- return $status;
645
- }
646
-
647
- public function targetHeader($targetName = '')
648
- {
649
- global $SGPB_DATA_CONFIG_ARRAY;
650
- $data = $SGPB_DATA_CONFIG_ARRAY[$targetName];
651
- $columnLabels = $data['columns'];
652
- $header = '<div class="sg-target-header-wrapper">';
653
-
654
- foreach ($columnLabels as $key => $columnLabel) {
655
- $header .= '<div class="sg-col-md">'.$columnLabel.'</div>';
656
- }
657
- $header .= '</div>';
658
- return $header;
659
- }
660
- }
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="sg-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="sg-target-rule sg-target-rule-<?php echo $conditionDataObj->getRuleId(); ?> sgpb-event-row" data-rule-id="<?php echo $conditionDataObj->getRuleId(); ?>">
85
+ <div class="row">
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) ? 'sg-hide-condition-row' : $showRowStatusClass;
106
+ ?>
107
+ <?php if ($conditionName != 'hiddenOption'): ?>
108
+ <div data-condition-name="<?php echo $conditionName;?>" class="<?php echo 'col-sm-3 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="sg-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
+
197
+ if (empty($operatorsData)) {
198
+ return $operatorsHtml;
199
+ }
200
+
201
+ foreach ($operatorsData as $operator) {
202
+ $identificatorClass = '';
203
+ $style = '';
204
+ if (!isset($eventsData['hiddenOptionData'])) {
205
+ continue;
206
+ }
207
+ $saveData = $conditionDataObj->getSavedData();
208
+ if (empty($saveData['hiddenOption']) && $operator['name'] == 'Edit' && $saveData["param"] != 'load') {
209
+ continue;
210
+ }
211
+ if ($operator['operator'] == 'edit') {
212
+ $identificatorClass = $idHiddenDiv;
213
+ $eventButtonClasses = 'btn btn-success btn-xs';
214
+ $eventButtonWrapperClass = 'col-sm-2 ';
215
+ }
216
+ if ($operator['operator'] == 'add') {
217
+ $eventButtonClasses = 'btn btn-primary btn-xs';
218
+ $eventButtonWrapperClass = 'col-sm-2 ';
219
+ $style = '';
220
+ //Don't show add button if it's not for last element
221
+ if ($groupId < $groupTotal) {
222
+ $style = 'style="display: none;"';
223
+ }
224
+ }
225
+ if ($operator['operator'] == 'delete') {
226
+ $eventButtonClasses = 'btn btn-danger btn-xs';
227
+ $eventButtonWrapperClass = 'col-sm-1 ';
228
+ }
229
+ if ($operator['name'] == 'Edit') {
230
+ $operator['name'] = 'Settings';
231
+ }
232
+
233
+ $operatorsHtml .= '<div class="'.$eventButtonWrapperClass.'sg-rules-'.$operator['operator'].'-button-wrapper sgpb-static-padding-top" '.$style.'>';
234
+ $operatorsHtml .= '<a href="javascript:void(0)" class="sg-rules-'.$operator['operator'].'-rule '.$eventButtonClasses.'" data-id="'.$identificatorClass.'"><span>'.__(' '.$operator['name'], SG_POPUP_TEXT_DOMAIN).'</span></a>';
235
+ $operatorsHtml .= '</div>';
236
+ }
237
+
238
+ return $operatorsHtml;
239
+ }
240
+
241
+ public static function createConditionElement($conditionDataObj, $ruleName)
242
+ {
243
+ //more code added because of the lack of abstraction
244
+ //todo: remove ASAP if possible
245
+ $sData = $conditionDataObj->getSavedData();
246
+ if ($ruleName == 'param' && !empty($sData['tempParam'])) {
247
+ $sData['param'] = $sData['tempParam'];
248
+ $newObj = clone $conditionDataObj;
249
+ $newObj->setSavedData($sData);
250
+ $conditionDataObj = $newObj;
251
+ }
252
+
253
+ $element = '';
254
+
255
+ $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
256
+ $elementHeader = self::createRuleHeader($ruleElementData);
257
+ $field = self::createRuleField($ruleElementData);
258
+ $element .= $elementHeader;
259
+ $element .= $field;
260
+
261
+ return $element;
262
+ }
263
+
264
+ public static function createConditionField($conditionDataObj, $ruleName)
265
+ {
266
+ $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
267
+
268
+ return self::createRuleField($ruleElementData);
269
+ }
270
+
271
+ public static function createConditionFieldHeader($conditionDataObj, $ruleName)
272
+ {
273
+ $ruleElementData = self::getRuleElementData($conditionDataObj, $ruleName);
274
+
275
+ return self::createRuleHeader($ruleElementData);
276
+ }
277
+
278
+ public static function optionLabelSupplement($conditionDataObj, $ruleName)
279
+ {
280
+ global $SGPB_DATA_CONFIG_ARRAY;
281
+ $conditionName = $conditionDataObj->getConditionName();
282
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
283
+ $attrs = $conditionConfig['attrs'][$ruleName];
284
+
285
+ if (isset($attrs['infoAttrs']['rightLabel'])) {
286
+ $labelData = $attrs['infoAttrs']['rightLabel'];
287
+ $value = $labelData['value'];
288
+ $classes = $labelData['classes'];
289
+ return '<span class="'.esc_attr($classes).'">'.$value.'</span>';
290
+ }
291
+
292
+ return '';
293
+ }
294
+
295
+ private static function getRuleElementData($conditionDataObj, $ruleName = '')
296
+ {
297
+ global $SGPB_DATA_CONFIG_ARRAY;
298
+ $ruleElementData = array();
299
+ $savedParam = '';
300
+ $conditionName = $conditionDataObj->getConditionName();
301
+ $saveData = $conditionDataObj->getSavedData();
302
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
303
+ $rulesType = $conditionConfig['columnTypes'];
304
+ $paramsData = $conditionConfig['paramsData'];
305
+
306
+ $attrs = $conditionConfig['attrs'];
307
+
308
+ if (!empty($saveData[$ruleName])) {
309
+ $savedParam = $saveData[$ruleName];
310
+ }
311
+ else if (!empty($saveData['hiddenOption']) && isset($saveData['hiddenOption'][$ruleName])) {
312
+ $savedParam = $saveData['hiddenOption'][$ruleName];
313
+ }
314
+
315
+ $ruleElementData['ruleName'] = $ruleName;
316
+ if ($ruleName == 'value' && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
317
+ $index = $conditionDataObj->getTakeValueFrom();
318
+ $ruleName = $saveData[$index];
319
+ }
320
+
321
+ $type = array();
322
+ if (!empty($rulesType[$ruleName])) {
323
+ $type = $rulesType[$ruleName];
324
+ }
325
+ $data = array();
326
+ if (!empty($paramsData[$ruleName])) {
327
+ $data = $paramsData[$ruleName];
328
+ }
329
+
330
+ // if exists customOperator it takes the custom one
331
+ if ($ruleName == 'operator' && !empty($paramsData['customOperator'])) {
332
+ $data = $paramsData['customOperator'];
333
+ }
334
+
335
+ $optionAttr = array();
336
+ if (!empty($attrs[$ruleName])) {
337
+ $optionAttr = $attrs[$ruleName];
338
+ }
339
+
340
+ $attr = array();
341
+
342
+ if (!empty($optionAttr['htmlAttrs'])) {
343
+ $attr = $optionAttr['htmlAttrs'];
344
+ }
345
+
346
+ $ruleElementData['type'] = $type;
347
+ $ruleElementData['data'] = apply_filters('sgpb'.$ruleName.'ConditionCreator', $data, $saveData);
348
+ $ruleElementData['saved'] = $savedParam;
349
+ $ruleElementData['attr'] = $attr;
350
+ $ruleElementData['conditionDataObj'] = $conditionDataObj;
351
+
352
+ return $ruleElementData;
353
+ }
354
+
355
+ private static function createRuleHeader($ruleElementData)
356
+ {
357
+ return self::createElementHeader($ruleElementData);
358
+ }
359
+
360
+ public static function createRuleField($ruleElementData)
361
+ {
362
+ $attr = array();
363
+ $type = $ruleElementData['type'];
364
+ $conditionObj = $ruleElementData['conditionDataObj'];
365
+
366
+ $name = 'sgpb-'.$conditionObj->getConditionName().'['.$conditionObj->getGroupId().']['.$conditionObj->getRuleId().']['.$ruleElementData['ruleName'].']';
367
+ $attr['name'] = $name;
368
+
369
+ if (is_array($ruleElementData['attr'])) {
370
+ $attr += $ruleElementData['attr'];
371
+ $attr['data-rule-id'] = $conditionObj->getRuleId();
372
+ }
373
+ $rowField = '';
374
+
375
+ switch($type) {
376
+
377
+ case 'select':
378
+ if (!empty($attr['multiple'])) {
379
+ $attr['name'] .= '[]';
380
+ }
381
+ $savedData = $ruleElementData['saved'];
382
+
383
+ if (empty($ruleElementData['data'])) {
384
+ $ruleElementData['data'] = $ruleElementData['saved'];
385
+ $savedData = array();
386
+
387
+ if (!empty($ruleElementData['saved'])) {
388
+ $savedData = array_keys($ruleElementData['saved']);
389
+ }
390
+ }
391
+
392
+ $rowField .= AdminHelper::createSelectBox($ruleElementData['data'], $savedData, $attr);
393
+ break;
394
+ case 'text':
395
+ case 'url':
396
+ case 'number':
397
+ $attr['type'] = $type;
398
+
399
+ //this is done to override the initial input value
400
+ if (!empty($ruleElementData['saved'])) {
401
+ $attr['value'] = esc_attr($ruleElementData['saved']);
402
+ }
403
+
404
+ $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'], $attr);
405
+ break;
406
+ case 'checkbox':
407
+ $attr['type'] = $type;
408
+ $rowField .= AdminHelper::createCheckBox($ruleElementData['data'], $ruleElementData['saved'], $attr);
409
+ break;
410
+ case 'conditionalText':
411
+ $popupId = self::getPopupId($conditionObj);
412
+ if(!empty($popupId)) {
413
+ $attr['value'] = $attr['value'].$popupId;
414
+ $rowField .= AdminHelper::createInput($ruleElementData['data'], $ruleElementData['saved'].$popupId, $attr);
415
+ }
416
+ else {
417
+ $rowField .= '<div class="sgpb-show-alert-before-save">'.$attr['beforeSaveLabel'].'</div>';
418
+ }
419
+ break;
420
+ }
421
+
422
+ return $rowField;
423
+ }
424
+
425
+ public static function getPopupId($conditionObj)
426
+ {
427
+ $popupId = 0;
428
+ $conditionPopupId = $conditionObj->getPopupId();
429
+
430
+ if (!empty($conditionPopupId)) {
431
+ $popupId = $conditionObj->getPopupId();
432
+ }
433
+ else if(!empty($_GET['post'])) {
434
+ $popupId = $_GET['post'];
435
+ }
436
+
437
+ return $popupId;
438
+ }
439
+
440
+ public static function createElementHeader($ruleElementData)
441
+ {
442
+ $labelAttributes = '';
443
+ $info = '';
444
+ $conditionObj = $ruleElementData['conditionDataObj'];
445
+ $conditionName = $conditionObj->getConditionName();
446
+ $ruleName = $ruleElementData['ruleName'];
447
+ global $SGPB_DATA_CONFIG_ARRAY;
448
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
449
+ $conditionAttrs = $conditionConfig['attrs'];
450
+
451
+ $saveData = $conditionObj->getSavedData();
452
+ $optionTitle = $ruleName;
453
+ $titleKey = $ruleName;
454
+
455
+
456
+ if ($ruleName == 'value' && !empty($saveData[$conditionObj->getTakeValueFrom()])) {
457
+ $titleKey = $saveData[$conditionObj->getTakeValueFrom()];
458
+ }
459
+
460
+ if (!empty($conditionAttrs[$titleKey])) {
461
+ $optionAttrs = $conditionAttrs[$titleKey];
462
+ if (!empty($optionAttrs['infoAttrs'])) {
463
+ // $conditionName => events, conditions, targets...
464
+ // $ruleName => param, operator, value (1-st, 2-nd, 3-rd columns)
465
+ $optionAttrs = apply_filters('sgpb'.$conditionName.$ruleName.'Param', $optionAttrs, $saveData);
466
+ $optionTitle = $optionAttrs['infoAttrs']['label'];
467
+ if (!empty($optionAttrs['infoAttrs']['labelAttrs'])) {
468
+ $labelAttributes = AdminHelper::createAttrs($optionAttrs['infoAttrs']['labelAttrs']);
469
+ }
470
+ }
471
+ }
472
+ if (isset($optionAttrs['infoAttrs']['info']) && $optionAttrs['infoAttrs']['info']) {
473
+ $info .= '<span class="dashicons dashicons-editor-help sgpb-info-icon sgpb-info-icon-align"></span>';
474
+ $info .= '<span class="infoSelectRepeat samefontStyle sgpb-info-text">'.$optionAttrs['infoAttrs']['info'].'</span>';
475
+ }
476
+
477
+ return "<label $labelAttributes>$optionTitle</label>$info";
478
+ }
479
+
480
+ public static function getHiddenDataContent($conditionDataObj)
481
+ {
482
+ global $SGPB_DATA_CONFIG_ARRAY;
483
+ $savedData = $conditionDataObj->getSavedData();
484
+ $conditionName = $savedData['param'];
485
+ $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
486
+ $hiddenOptions = $eventsData['hiddenOptionData'];
487
+ $ruleId = $conditionDataObj->getRuleId();
488
+ if (empty($hiddenOptions[$conditionName])) {
489
+ return __('No Data', SG_POPUP_TEXT_DOMAIN);
490
+ }
491
+
492
+ $hiddenOptionsData = $hiddenOptions[$conditionName];
493
+
494
+ $tabs = array_keys($hiddenOptionsData);
495
+ ob_start();
496
+ ?>
497
+
498
+ <div class="sgpb-wrapper">
499
+ <div class="tab">
500
+ <?php
501
+ $activeTab = '';
502
+ if (!empty($tabs[0])) {
503
+ $activeTab = $tabs[0];
504
+ }
505
+ ?>
506
+ <?php foreach ($tabs as $tab): ?>
507
+ <?php
508
+ $activeClassName = '';
509
+ if ($activeTab == $tab) {
510
+ $activeClassName = 'sgpb-active';
511
+ }
512
+ ?>
513
+ <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>
514
+ <?php endforeach;?>
515
+ </div>
516
+ <?php echo self::createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId); ?>
517
+ <div class="modal-footer">
518
+ <button type="button" class="sgpb-no-button events-option-close btn btn-default btn-sm" href="#"><?php _e('Cancel', SG_POPUP_TEXT_DOMAIN); ?></button>
519
+ <button class="btn btn-primary btn-sm sgpb-popup-option-save"><?php _e('Save', SG_POPUP_TEXT_DOMAIN); ?></button>
520
+ </div>
521
+ </div>
522
+ <?php
523
+ $hiddenPopupContent = ob_get_contents();
524
+ ob_end_clean();
525
+
526
+ return $hiddenPopupContent;
527
+ }
528
+
529
+ private static function createHiddenFields($hiddenOptionsData, $conditionDataObj, $ruleId)
530
+ {
531
+ ob_start();
532
+ ?>
533
+ <?php foreach ($hiddenOptionsData as $key => $hiddenData): ?>
534
+ <div id="<?php echo $key.'-'.$ruleId; ?>" class="sgpb-tab-content-<?php echo $ruleId;?>">
535
+ <div id="<?php echo $key; ?>" class="sgpb-tab-content-options">
536
+ <?php foreach ($hiddenData as $name => $label): ?>
537
+ <?php
538
+ $hiddenOptionsView = self::optionLabelSupplement($conditionDataObj, $name);
539
+ $colMdValue = 6;
540
+ if (!empty($hiddenOptionsView)) {
541
+ $colMdValue = 2;
542
+ }
543
+ ?>
544
+ <div class="row form-group">
545
+ <div class="col-md-6">
546
+ <?php echo self::createConditionFieldHeader($conditionDataObj, $name); ?>
547
+ </div>
548
+ <div class="col-md-<?php echo $colMdValue; ?>">
549
+ <?php echo self::createConditionField($conditionDataObj, $name); ?>
550
+ </div>
551
+ <?php if (!empty($hiddenOptionsView)): ?>
552
+ <div class="col-md-4">
553
+ <?php echo $hiddenOptionsView; ?>
554
+ </div>
555
+ <?php endif; ?>
556
+ </div>
557
+ <?php endforeach; ?>
558
+ </div>
559
+ </div>
560
+ <?php endforeach;?>
561
+ <?php
562
+ $hiddenPopupContent = ob_get_contents();
563
+ ob_end_clean();
564
+
565
+ return $hiddenPopupContent;
566
+ }
567
+
568
+ public static function hiddenSubOptionsView($parentOptionName, $conditionDataObj)
569
+ {
570
+ $subOptionsContent = '';
571
+ $subOptions = self::getHiddenOptionSubOptions($parentOptionName);
572
+ if (!empty($subOptions)) {
573
+ $subOptionsContent = self::createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions);
574
+ }
575
+
576
+ return $subOptionsContent;
577
+ }
578
+
579
+ private static function createHiddenSubOptions($parentOptionName, $conditionDataObj, $subOptions)
580
+ {
581
+ $name = $parentOptionName;
582
+ ob_start();
583
+ ?>
584
+ <div class="row <?php echo 'sgpb-popup-hidden-content-'.$name.'-'.$conditionDataObj->getRuleId().'-wrapper'?> form-group">
585
+ <?php foreach ($subOptions as $subOption): ?>
586
+ <div class="col-md-6">
587
+ <?php echo self::createConditionFieldHeader($conditionDataObj, $subOption); ?>
588
+ </div>
589
+ <div class="col-md-6">
590
+ <?php echo self::createConditionField($conditionDataObj, $subOption); ?>
591
+ </div>
592
+ <?php echo self::hiddenSubOptionsView($subOption, $conditionDataObj)?>
593
+ <?php endforeach;?>
594
+ </div>
595
+ <?php
596
+ $hiddenPopupContent = ob_get_contents();
597
+ ob_end_clean();
598
+
599
+ return $hiddenPopupContent;
600
+ }
601
+
602
+ public static function getHiddenOptionSubOptions($optionName)
603
+ {
604
+ global $SGPB_DATA_CONFIG_ARRAY;
605
+ $childOptionNames = array();
606
+ $eventsData = $SGPB_DATA_CONFIG_ARRAY['events'];
607
+ $targetDataAttrs = $eventsData['attrs'];
608
+
609
+ if (empty($targetDataAttrs[$optionName])) {
610
+ return $childOptionNames;
611
+ }
612
+
613
+ if (empty($targetDataAttrs[$optionName]['childOptions'])) {
614
+ return $childOptionNames;
615
+ }
616
+ $childOptionNames = $targetDataAttrs[$optionName]['childOptions'];
617
+
618
+ return $childOptionNames;
619
+ }
620
+
621
+ private static function getParamRowHideStatus($conditionDataObj, $ruleName)
622
+ {
623
+ global $SGPB_DATA_CONFIG_ARRAY;
624
+ if ($ruleName == 'hiddenOption') {
625
+ return '';
626
+ }
627
+ $status = false;
628
+ $conditionName = $conditionDataObj->getConditionName();
629
+ $saveData = $conditionDataObj->getSavedData();
630
+ $conditionConfig = $SGPB_DATA_CONFIG_ARRAY[$conditionName];
631
+ $paramsData = array();
632
+ if (!empty($conditionConfig['paramsData'])) {
633
+ $paramsData = $conditionConfig['paramsData'];
634
+ }
635
+
636
+ $ruleElementData['ruleName'] = $ruleName;
637
+ if ($ruleName == 'value' && !empty($saveData) && !empty($saveData[$conditionDataObj->getTakeValueFrom()])) {
638
+ $ruleName = $saveData[$conditionDataObj->getTakeValueFrom()];
639
+ }
640
+ if ((!isset($paramsData[$ruleName]) && empty($paramsData[$ruleName])) || is_null($paramsData[$ruleName])) {
641
+ $status = true;
642
+ }
643
+
644
+ return $status;
645
+ }
646
+
647
+ public function targetHeader($targetName = '')
648
+ {
649
+ global $SGPB_DATA_CONFIG_ARRAY;
650
+ $data = $SGPB_DATA_CONFIG_ARRAY[$targetName];
651
+ $columnLabels = $data['columns'];
652
+ $header = '<div class="sg-target-header-wrapper">';
653
+
654
+ foreach ($columnLabels as $key => $columnLabel) {
655
+ $header .= '<div class="sg-col-md">'.$columnLabel.'</div>';
656
+ }
657
+ $header .= '</div>';
658
+ return $header;
659
+ }
660
+ }
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">
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">
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,859 +1,859 @@
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 = '';
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') || strstr($popupOptions['sgpb-floating-button-position'], 'bottom')) {
94
- $buttonStyles .= 'right: '.$popupOptions['sgpb-floating-button-position-right'].'%;';
95
- }
96
- else if (strstr($popupOptions['sgpb-floating-button-position'], 'left') || strstr($popupOptions['sgpb-floating-button-position'], 'right')) {
97
- $buttonStyles .= 'top: '.$popupOptions['sgpb-floating-button-position-top'].'%;';
98
- }
99
- }
100
-
101
- if (isset($popupOptions['sgpb-floating-button-font-size'])) {
102
- $buttonStyles .= 'font-size: '.$popupOptions['sgpb-floating-button-font-size'].'px;';
103
- }
104
- if (isset($popupOptions['sgpb-floating-button-border-size'])) {
105
- $buttonStyles .= 'border-width: '.$popupOptions['sgpb-floating-button-border-size'].'px;';
106
- $buttonStyles .= 'border-style: solid;';
107
- }
108
- if (isset($popupOptions['sgpb-floating-button-border-radius'])) {
109
- $buttonStyles .= 'border-radius: '.$popupOptions['sgpb-floating-button-border-radius'].'px;';
110
- }
111
- if (isset($popupOptions['sgpb-floating-button-border-color'])) {
112
- $buttonStyles .= 'border-color: '.$popupOptions['sgpb-floating-button-border-color'].';';
113
- }
114
- if (isset($popupOptions['sgpb-floating-button-bg-color'])) {
115
- $buttonStyles .= 'background-color: '.$popupOptions['sgpb-floating-button-bg-color'].';';
116
- }
117
- if (isset($popupOptions['sgpb-floating-button-text-color'])) {
118
- $buttonStyles .= 'color: '.$popupOptions['sgpb-floating-button-text-color'].';';
119
- }
120
-
121
- $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>';
122
-
123
- echo $floatingButton;
124
- }
125
-
126
- public function filterOptionsBeforeSaving($unfilteredData = array())
127
- {
128
- $externalOptions = array(
129
- 'icl_post_language' => 'sgpb-icl_post_language'
130
- );
131
-
132
- foreach ($externalOptions as $optionKey => $value) {
133
- if (isset($unfilteredData[$optionKey])) {
134
- $unfilteredData[$value] = $unfilteredData[$optionKey];
135
- // 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"
136
- }
137
- }
138
-
139
- return $unfilteredData;
140
- }
141
-
142
- public function userSelectionQueryAddExtraAttributes($query)
143
- {
144
- $query .= ' status = 0 and unsubscribed = 0';
145
-
146
- return $query;
147
- }
148
-
149
- public function excludeRankMath($exclude, $type)
150
- {
151
- if ($type == SG_POPUP_POST_TYPE) {
152
- $exclude = true;
153
- }
154
-
155
- return $exclude;
156
- }
157
-
158
- public function pluginRowMetas($pluginMeta, $pluginFile, $pluginData, $status)
159
- {
160
- if (empty($pluginFile)) {
161
- return $pluginMeta;
162
- }
163
-
164
- $allExtensions = \SgpbDataConfig::allExtensionsKeys();
165
- $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
166
- $allExtensions[] = SG_POPUP_FILE_NAME;
167
-
168
- $rowMeta = array(
169
- 'rateus' => '<a href="'.SG_POPUP_RATE_US_URL.'" target="_blank">'.esc_html__('Rate us', SG_POPUP_TEXT_DOMAIN).'</a>',
170
- 'support' => '<a href="'.SG_POPUP_SUPPORT_URL.'" target="_blank">'.esc_html__('Support', SG_POPUP_TEXT_DOMAIN).'</a>'
171
- );
172
-
173
- if (in_array($pluginFile, $allExtensions)) {
174
- $pluginMeta = array_merge($pluginMeta, $rowMeta);
175
- }
176
-
177
- return $pluginMeta;
178
- }
179
-
180
- public function pluginActionLinks($actions, $pluginFile, $pluginData, $context)
181
- {
182
- if (empty($pluginFile)) {
183
- return $actions;
184
- }
185
-
186
- $allExtensions = \SgpbDataConfig::allExtensionsKeys();
187
- $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
188
- $allExtensions[] = SG_POPUP_FILE_NAME;
189
-
190
- $settingPageUrl = admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE;
191
-
192
- $links = array(
193
- 'settings' => '<a href="'.$settingPageUrl.'" target="_blank">'.esc_html__('Settings', SG_POPUP_TEXT_DOMAIN).'</a>',
194
- 'docs' => '<a href="'.SG_POPUP_TICKET_URL.'" target="_blank">'.esc_html__('Docs', SG_POPUP_TEXT_DOMAIN).'</a>'
195
- );
196
-
197
- if (in_array($pluginFile, $allExtensions)) {
198
- if ($pluginFile == SG_POPUP_FILE_NAME) {
199
- $getActiveExtensions = AdminHelper::getAllExtensions();
200
- if (empty($getActiveExtensions['active'])) {
201
- $links['upgrade'] = '<a style="color: #4364eb;" href="'.SG_POPUP_BUNDLE_URL.'" target="_blank">'.esc_html__('Upgrade', SG_POPUP_TEXT_DOMAIN).'</a>';
202
- }
203
- }
204
- $actions = array_merge($links, $actions);
205
- }
206
-
207
- return $actions;
208
- }
209
-
210
- public function systemInformation($infoContent)
211
- {
212
-
213
- $infoContent .= 'Platform: '.@$platform . "\n";
214
- $infoContent .= 'Browser Name: '.@$bname . "\n";
215
- $infoContent .= 'Browser Version: '.@$version . "\n";
216
- $infoContent .= 'User Agent: '.@$uAgent . "\n";
217
-
218
- return $infoContent;
219
- }
220
-
221
- public function popupContentLoadToPage($content, $popupId)
222
- {
223
- $customScripts = AdminHelper::renderCustomScripts($popupId);
224
- $content .= $customScripts;
225
-
226
- return $content;
227
- }
228
-
229
- public function sgpbExtraNotifications($notifications = array())
230
- {
231
- $license = self::licenseNotification();
232
- if (!empty($license)) {
233
- $notifications[] = $license;
234
- }
235
-
236
- $promotional = self::promotionalNotifications();
237
- if (!empty($promotional)) {
238
- $notifications[] = $promotional;
239
- }
240
-
241
- $supportBanner = self::supportBannerNotifcations();
242
- if (!empty($supportBanner)) {
243
- $notifications[] = $supportBanner;
244
- }
245
-
246
- return $notifications;
247
- }
248
-
249
- public static function supportBannerNotifcations()
250
- {
251
- $hideSupportBanner = get_option('sgpb-hide-support-banner');
252
- if (!empty($hideSupportBanner)) {
253
- return array();
254
- }
255
- $message = AdminHelper::supportBannerNotification();
256
- $notification['id'] = SGPB_SUPPORT_BANNER_NOTIFICATION_ID;
257
- $notification['priority'] = 1;
258
- $notification['type'] = 1;
259
- $notification['message'] = $message;
260
-
261
- return $notification;
262
- }
263
-
264
- public static function promotionalNotifications()
265
- {
266
- $alreadyDone = get_option('SGPBCloseReviewPopup-notification');
267
- if (!empty($alreadyDone)) {
268
- return array();
269
- }
270
- $id = SGPB_RATE_US_NOTIFICATION_ID;
271
- $type = 1;
272
- $priority = 1;
273
-
274
- $maxOpenPopupStatus = AdminHelper::shouldOpenForMaxOpenPopupMessage();
275
- // popup opening count notification
276
- if ($maxOpenPopupStatus) {
277
- $message = AdminHelper::getMaxOpenPopupsMessage();
278
- }
279
-
280
- $shouldOpenForDays = AdminHelper::shouldOpenReviewPopupForDays();
281
- if ($shouldOpenForDays && !$maxOpenPopupStatus) {
282
- $message = AdminHelper::getMaxOpenDaysMessage();
283
- }
284
- if (empty($message)) {
285
- return array();
286
- }
287
-
288
- $alternateNotification['priority'] = $priority;
289
- $alternateNotification['type'] = $type;
290
- $alternateNotification['id'] = $id;
291
- $alternateNotification['message'] = $message;
292
-
293
- return $alternateNotification;
294
- }
295
-
296
- public function licenseNotification()
297
- {
298
- $inactiveExtensionNotice = array();
299
- $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
300
- if ($dontShowLicenseBanner) {
301
- return $notifications;
302
- }
303
-
304
- $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
305
- $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
306
-
307
- if (!$inactive) {
308
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
309
- if ($hasInactiveExtensions) {
310
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
311
- $inactive = 'inactive';
312
- }
313
-
314
- }
315
-
316
- if ($hasInactiveExtensions && $inactive == 'inactive') {
317
- $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
318
- $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
319
- $message = '<b>'.__('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN).'</b>';
320
- $message .= '<br>';
321
- $message .= '<br>';
322
- $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>';
323
- $message .= '<b>'.$partOfContent.'</b>';
324
-
325
- $inactiveExtensionNotice['priority'] = 1;
326
- $inactiveExtensionNotice['type'] = 2;
327
- $inactiveExtensionNotice['id'] = 'sgpbMainActiveInactiveLicense';
328
- $inactiveExtensionNotice['message'] = $message;
329
- }
330
-
331
- return $inactiveExtensionNotice;
332
- }
333
-
334
- public function excludeSitemapsYoast($exclude = false, $postType)
335
- {
336
- $postTypeObject = get_post_type_object($postType);
337
- if (!is_object($postTypeObject)) {
338
- return $exclude;
339
- }
340
-
341
- if ($postTypeObject->public === false || $postType == SG_POPUP_POST_TYPE) {
342
- return true;
343
- }
344
-
345
- return $exclude;
346
- }
347
-
348
- public function defaultAdvancedOptionsValues($options = array())
349
- {
350
- $enablePopupOverlay = PopupBuilderActivePackage::canUseOption('sgpb-enable-popup-overlay');
351
- if (!$enablePopupOverlay) {
352
- $options['sgpb-enable-popup-overlay'] = 'on';
353
- }
354
-
355
- return $options;
356
- }
357
-
358
- public function excludePostToShowPrepare()
359
- {
360
- SgpbPopupConfig::popupTypesInit();
361
- $queryString = SGPopup::getActivePopupsQueryString();
362
- $this->setQueryString($queryString);
363
- add_filter('posts_where' , array($this, 'excludePostsToShow'), 10, 1);
364
- }
365
-
366
- public function exportFileName($fileName)
367
- {
368
- if (!empty($_GET['sgpbExportAction'])) {
369
- return SGPB_POPUP_EXPORT_FILE_NAME;
370
- }
371
-
372
- return $fileName;
373
- }
374
-
375
- public function filterOption($filterOption)
376
- {
377
- $extensionOptionsData = AdminHelper::getExtensionAvaliabilityOptions();
378
-
379
- if (empty($extensionOptionsData)) {
380
- return $filterOption;
381
- }
382
-
383
- foreach ($extensionOptionsData as $extensionKey => $extensionOptions) {
384
- $isAdvancedClosingActive = is_plugin_active($extensionKey);
385
- if (isset($filterOption['name']) && !$isAdvancedClosingActive) {
386
- $name = $filterOption['name'];
387
-
388
- if (in_array($name, $extensionOptions)) {
389
- $filterOption['status'] = false;
390
- }
391
- }
392
- }
393
-
394
- return $filterOption;
395
- }
396
-
397
- public function metaboxes($metaboxes)
398
- {
399
- $otherConditionsProLabel = '';
400
- $otherConditionsCanBeUsed = PopupBuilderActivePackage::canUseSection('popupOtherConditionsSection');
401
- if (!$otherConditionsCanBeUsed) {
402
- $otherConditionsProLabel .= '<a href="'.SG_POPUP_SCHEDULING_URL.'" target="_blank" class="sgpb-pro-label-metabox">';
403
- $otherConditionsProLabel .= __('UNLOCK OPTION', SG_POPUP_TEXT_DOMAIN).'</a>';
404
- }
405
- $metaboxes['targetMetaboxView'] = array(
406
- 'key' => 'targetMetaboxView',
407
- 'displayName' => 'Popup Display Rules',
408
- 'filePath' => SG_POPUP_VIEWS_PATH.'targetView.php',
409
- 'priority' => 'high'
410
- );
411
-
412
- $metaboxes['eventsMetaboxView'] = array(
413
- 'key' => 'eventsMetaboxView',
414
- 'displayName' => 'Popup Events',
415
- 'filePath' => SG_POPUP_VIEWS_PATH.'eventsView.php',
416
- 'priority' => 'high'
417
- );
418
-
419
- $metaboxes['conditionsMetaboxView'] = array(
420
- 'key' => 'conditionsMetaboxView',
421
- 'displayName' => 'Popup Conditions',
422
- 'filePath' => SG_POPUP_VIEWS_PATH.'conditionsView.php',
423
- 'priority' => 'high'
424
- );
425
-
426
- $metaboxes['behaviorAfterSpecialEventsMetaboxView'] = array(
427
- 'key' => 'behaviorAfterSpecialEventsMetaboxView',
428
- 'displayName' => 'Behavior After Special Events',
429
- 'filePath' => SG_POPUP_VIEWS_PATH.'behaviorAfterSpecialEventsView.php',
430
- 'priority' => 'high'
431
- );
432
-
433
- $metaboxes['popupDesignMetaBoxView'] = array(
434
- 'key' => 'popupDesignMetaBoxView',
435
- 'displayName' => 'Design',
436
- 'filePath' => SG_POPUP_VIEWS_PATH.'popupDesignView.php',
437
- 'priority' => 'high'
438
- );
439
-
440
- $metaboxes['closeSettings'] = array(
441
- 'key' => 'closeSettings',
442
- 'displayName' => 'Close Settings',
443
- 'filePath' => SG_POPUP_VIEWS_PATH.'closeSettingsView.php',
444
- 'priority' => 'high'
445
- );
446
-
447
- $metaboxes['spgdimension'] = array(
448
- 'key' => 'spgdimension',
449
- 'displayName' => 'Dimensions',
450
- 'filePath' => SG_POPUP_VIEWS_PATH.'dimensionsView.php',
451
- 'priority' => 'high'
452
- );
453
-
454
- $metaboxes['optionsMetaboxView'] = array(
455
- 'key' => 'optionsMetaboxView',
456
- 'displayName' => 'Popup Options',
457
- 'filePath' => SG_POPUP_VIEWS_PATH.'optionsView.php',
458
- 'priority' => 'high'
459
- );
460
-
461
- $metaboxes['otherConditionsMetaBoxView'] = array(
462
- 'key' => 'otherConditionsMetaBoxView',
463
- 'displayName' => 'Popup Additional Conditions'.$otherConditionsProLabel,
464
- 'filePath' => SG_POPUP_VIEWS_PATH.'otherConditionsView.php',
465
- 'priority' => 'high'
466
- );
467
-
468
- $metaboxes['customCssJs'] = array(
469
- 'key' => 'customCssJs',
470
- 'displayName' => 'Custom JS or CSS',
471
- 'filePath' => SG_POPUP_VIEWS_PATH.'customEditor.php',
472
- 'priority' => 'low'
473
- );
474
-
475
- $metaboxes['floatingButton'] = array(
476
- 'key' => 'floatingButton',
477
- 'displayName' => 'Floating Button',
478
- 'filePath' => SG_POPUP_VIEWS_PATH.'floatingButton.php',
479
- 'context' => 'side',
480
- 'priority' => 'high'
481
- );
482
-
483
- $metaboxes['popupOpeningCounter'] = array(
484
- 'key' => 'popupOpeningCounter',
485
- 'displayName' => 'Popup statistics',
486
- 'filePath' => SG_POPUP_VIEWS_PATH.'popupOpeningCounter.php',
487
- 'context' => 'side',
488
- 'priority' => 'low'
489
- );
490
-
491
- return $metaboxes;
492
- }
493
-
494
- public function popupEvents($events)
495
- {
496
- foreach ($events as $eventKey => $eventData) {
497
- if (isset($eventData['param'])) {
498
- if ($eventData['param'] == SGPB_CSS_CLASS_ACTIONS_KEY) {
499
- unset($events[$eventKey]);
500
- $events[] = array('param' => 'click');
501
- $events[] = array('param' => 'hover');
502
- $events[] = array('param' => 'confirm');
503
- }
504
- else if ($eventData['param'] == SGPB_CLICK_ACTION_KEY) {
505
- $events[$eventKey]['param'] = 'click';
506
- }
507
- else if ($eventData['param'] == SGPB_HOVER_ACTION_KEY) {
508
- $events[$eventKey]['param'] = 'hover';
509
- }
510
- }
511
- }
512
-
513
- return $events;
514
- }
515
-
516
- public function savedPostData($postData)
517
- {
518
- // for old popups here we change already saved old popup id
519
- if (isset($postData['sgpb-mailchimp-success-popup'])) {
520
- // sgpGetCorrectPopupId it's a temporary function and it will be removed in future
521
- if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
522
- $postData['sgpb-mailchimp-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-mailchimp-success-popup']);
523
- }
524
- }
525
- // for old popups here we change already saved old popup id
526
- if (isset($postData['sgpb-aweber-success-popup'])) {
527
- if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
528
- $postData['sgpb-aweber-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-aweber-success-popup']);
529
- }
530
- }
531
-
532
- return $postData;
533
- }
534
-
535
- public function removeAddNewSubmenu()
536
- {
537
- //we don't need the default add new, since we are using our custom page for it
538
- $page = remove_submenu_page(
539
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
540
- 'post-new.php?post_type='.SG_POPUP_POST_TYPE
541
- );
542
- }
543
-
544
- public function maybeShortenEddFilename($return, $package)
545
- {
546
- if (strpos($package, SG_POPUP_STORE_URL) !== false) {
547
- add_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 100, 2);
548
- }
549
- return $return;
550
- }
551
-
552
- public function shortenEddFilename($filename, $ext)
553
- {
554
- $filename = substr($filename, 0, 20).$ext;
555
- remove_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 10);
556
- return $filename;
557
- }
558
-
559
- public function editPopupPreviewLink($previewLink = '', $post = array())
560
- {
561
- if (!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) {
562
- $popupId = $post->ID;
563
- $targets = get_post_meta($popupId, 'sg_popup_target_preview', true);
564
- if (empty($targets['sgpb-target'][0])) {
565
- return $previewLink .= '/?sg_popup_preview_id='.$popupId;
566
- }
567
- $targetParams = @$targets['sgpb-target'][0][0]['param'];
568
- if ((!empty($targetParams) && $targetParams == 'not_rule') || empty($targetParams)) {
569
- $previewLink = home_url();
570
- $previewLink .= '/?sg_popup_preview_id='.$popupId;
571
-
572
- return $previewLink;
573
- }
574
- foreach ($targets['sgpb-target'][0] as $targetKey => $targetValue) {
575
- if (!isset($targetValue['operator']) || $targetValue['operator'] == '!=') {
576
- continue;
577
- }
578
- $previewLink = self::getPopupPreviewLink($targetValue, $popupId);
579
- $previewLink .= '/?sg_popup_preview_id='.$popupId;
580
- }
581
- }
582
-
583
- return $previewLink;
584
- }
585
-
586
- public static function getPopupPreviewLink($targetData, $popupId)
587
- {
588
- $previewLink = home_url();
589
-
590
- if (empty($targetData['param'])) {
591
- return $previewLink;
592
- }
593
- $targetParam = $targetData['param'];
594
-
595
- if ($targetParam == 'everywhere') {
596
- return $previewLink;
597
- }
598
-
599
- $args = array(
600
- 'orderby' => 'rand'
601
- );
602
-
603
- // posts
604
- if (strpos($targetData['param'], '_all')) {
605
- if ($targetData['param'] == 'post_all') {
606
- $args['post_type'] = 'post';
607
- }
608
- if ($targetData['param'] == 'page_all') {
609
- $args['post_type'] = 'page';
610
- }
611
- }
612
- if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
613
- $args['post_type'] = $targetData['value'];
614
- }
615
- if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
616
- $pageTypes = $targetData['value'];
617
- foreach ($pageTypes as $pageType) {
618
-
619
- if ($pageType == 'is_home_page') {
620
- if (is_front_page() && is_home()) {
621
- // default homepage
622
- return get_home_url();
623
- }
624
- else if (is_front_page()) {
625
- // static homepage
626
- return get_home_url();
627
- }
628
- }
629
- else if (function_exists($pageType)) {
630
- if ($pageType == 'is_home') {
631
- return get_home_url();
632
- }
633
- else if ($pageType == 'is_search') {
634
- return get_search_link();
635
- }
636
- else if ($pageType == 'is_shop') {
637
- return get_home_url().'/shop/';
638
- }
639
- }
640
- }
641
- }
642
- if (isset($args['post_type'])) {
643
- $the_query = new WP_Query($args);
644
- foreach ($the_query->posts as $post) {
645
- $postId = $post->ID;
646
- if (get_permalink($postId)) {
647
- return get_permalink($postId);
648
- }
649
- }
650
- }
651
- // selected post/page/custom_post_types...
652
- if (strpos($targetData['param'], '_selected') && !empty($targetData['value'])) {
653
- $value = array_keys($targetData['value']);
654
- if (!empty($value[0])) {
655
- if (get_permalink($value[0])) {
656
- return get_permalink($value[0]);
657
- }
658
- }
659
- }
660
- if (strpos($targetData['param'], '_archive') && !empty($targetData['value'])) {
661
- $value = array_keys($targetData['value']);
662
- if (!empty($value[0])) {
663
- if (get_permalink($value[0])) {
664
- return get_permalink($value[0]);
665
- }
666
- }
667
- }
668
-
669
- return $previewLink;
670
- }
671
-
672
- public function excludePostsToShow($where)
673
- {
674
- if (function_exists('is_admin') && is_admin()) {
675
- if (!function_exists('get_current_screen')) {
676
- return $where;
677
- }
678
-
679
- $screen = get_current_screen();
680
- if (empty($screen)) {
681
- return $where;
682
- }
683
-
684
- $postType = $screen->post_type;
685
- if ($postType == SG_POPUP_POST_TYPE &&
686
- $screen instanceof \WP_Screen &&
687
- $screen->id === 'edit-popupbuilder') {
688
- if (class_exists('sgpb\SGPopup')) {
689
- $activePopupsQuery = $this->getQueryString();
690
- if ($activePopupsQuery && $activePopupsQuery != '') {
691
- $where .= $activePopupsQuery;
692
- }
693
- }
694
- }
695
- }
696
-
697
- return $where;
698
- }
699
-
700
- public function clearContentPreviewMode($content)
701
- {
702
- global $post_type;
703
-
704
- if (is_preview() && $post_type == SG_POPUP_POST_TYPE) {
705
- $content = '';
706
- }
707
-
708
- return $content;
709
- }
710
-
711
- public function filterPopupContent($content, $popupId)
712
- {
713
- preg_match_all('/<iframe.*?src="(.*?)".*?<\/iframe>/', $content, $matches);
714
- /*$finalContent = '';*/
715
- // $matches[0] array contain iframes stings
716
- // $matches[1] array contain iframes URLs
717
- if (empty($matches) && empty($matches[0]) && empty($matches[1])) {
718
- return $content;
719
- }
720
- $urls = $matches[1];
721
-
722
- foreach ($matches[0] as $key => $iframe) {
723
- if (empty($urls[$key])) {
724
- continue;
725
- }
726
-
727
- $pos = strpos($iframe, $urls[$key]);
728
-
729
- if ($pos === false) {
730
- continue;
731
- }
732
-
733
- $content = str_replace(' src="'.$urls[$key].'"', ' src="" data-attr-src="'.esc_attr($urls[$key]).'"', $content);
734
- }
735
- if (function_exists('do_blocks')) {
736
- $content = do_blocks($content);
737
- }
738
-
739
- return do_shortcode($content);
740
- }
741
-
742
- public function addNewPostUrl($url, $path)
743
- {
744
- if ($path == 'post-new.php?post_type='.SG_POPUP_POST_TYPE) {
745
- $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);
746
- }
747
-
748
- return $url;
749
- }
750
-
751
- public function popupsTableColumns($columns)
752
- {
753
- unset($columns['date']);
754
-
755
- $additionalItems = array();
756
- $additionalItems['counter'] = __('Views', SG_POPUP_TEXT_DOMAIN);
757
- $additionalItems['onOff'] = __('Enabled (show popup)', SG_POPUP_TEXT_DOMAIN);
758
- $additionalItems['type'] = __('Type', SG_POPUP_TEXT_DOMAIN);
759
- $additionalItems['shortcode'] = __('Shortcode', SG_POPUP_TEXT_DOMAIN);
760
- $additionalItems['className'] = __('Class', SG_POPUP_TEXT_DOMAIN);
761
-
762
- return $columns + $additionalItems;
763
- }
764
-
765
- /**
766
- * Function to add/hide links from popups dataTable row
767
- */
768
- public function quickRowLinksManager($actions, $post)
769
- {
770
- global $post_type;
771
-
772
- if ($post_type != SG_POPUP_POST_TYPE) {
773
- return $actions;
774
- }
775
- // remove quick edit link
776
- unset($actions['inline hide-if-no-js']);
777
- // remove view link
778
- unset($actions['view']);
779
-
780
- $actions['clone'] = '<a href="'.$this->popupGetClonePostLink($post->ID , 'display', false).'" title="';
781
- $actions['clone'] .= esc_attr__("Clone this item", SG_POPUP_TEXT_DOMAIN);
782
- $actions['clone'] .= '">'. esc_html__('Clone', SG_POPUP_TEXT_DOMAIN).'</a>';
783
-
784
- return $actions;
785
- }
786
-
787
- /**
788
- * Retrieve duplicate post link for post.
789
- *
790
- * @param int $id Optional. Post ID.
791
- * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
792
- * @return string
793
- */
794
- public function popupGetClonePostLink($id = 0, $context = 'display')
795
- {
796
- if (!$post = get_post($id)) {
797
- return;
798
- }
799
- $actionName = "popupSaveAsNew";
800
-
801
- if ('display' == $context) {
802
- $action = '?action='.$actionName.'&amp;post='.$post->ID;
803
- } else {
804
- $action = '?action='.$actionName.'&post='.$post->ID;
805
- }
806
-
807
- $postTypeObject = get_post_type_object($post->post_type);
808
-
809
- if (!$postTypeObject) {
810
- return;
811
- }
812
-
813
- return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
814
- }
815
-
816
- /* media button scripts */
817
- public function adminJsFilter($jsFiles)
818
- {
819
- $allowToShow = MediaButton::allowToShow();
820
- if ($allowToShow) {
821
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
822
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
823
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Popup.js');
824
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
825
- $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'MediaButton.js');
826
-
827
- $jsFiles['localizeData'][] = array(
828
- 'handle' => 'Popup.js',
829
- 'name' => 'sgpbPublicUrl',
830
- 'data' => SG_POPUP_PUBLIC_URL
831
- );
832
-
833
- $jsFiles['localizeData'][] = array(
834
- 'handle' => 'MediaButton.js',
835
- 'name' => 'mediaButtonParams',
836
- 'data' => array(
837
- 'currentPostType' => get_post_type(),
838
- 'popupBuilderPostType' => SG_POPUP_POST_TYPE,
839
- 'ajaxUrl' => admin_url('admin-ajax.php'),
840
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
841
- )
842
- );
843
- }
844
-
845
- return $jsFiles;
846
- }
847
-
848
- /* media button styles */
849
- public function sgpbAdminCssFiles($cssFiles)
850
- {
851
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
852
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
853
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
854
-
855
- return $cssFiles;
856
- }
857
- }
858
-
859
-
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 = '';
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') || strstr($popupOptions['sgpb-floating-button-position'], 'bottom')) {
94
+ $buttonStyles .= 'right: '.$popupOptions['sgpb-floating-button-position-right'].'%;';
95
+ }
96
+ else if (strstr($popupOptions['sgpb-floating-button-position'], 'left') || strstr($popupOptions['sgpb-floating-button-position'], 'right')) {
97
+ $buttonStyles .= 'top: '.$popupOptions['sgpb-floating-button-position-top'].'%;';
98
+ }
99
+ }
100
+
101
+ if (isset($popupOptions['sgpb-floating-button-font-size'])) {
102
+ $buttonStyles .= 'font-size: '.$popupOptions['sgpb-floating-button-font-size'].'px;';
103
+ }
104
+ if (isset($popupOptions['sgpb-floating-button-border-size'])) {
105
+ $buttonStyles .= 'border-width: '.$popupOptions['sgpb-floating-button-border-size'].'px;';
106
+ $buttonStyles .= 'border-style: solid;';
107
+ }
108
+ if (isset($popupOptions['sgpb-floating-button-border-radius'])) {
109
+ $buttonStyles .= 'border-radius: '.$popupOptions['sgpb-floating-button-border-radius'].'px;';
110
+ }
111
+ if (isset($popupOptions['sgpb-floating-button-border-color'])) {
112
+ $buttonStyles .= 'border-color: '.$popupOptions['sgpb-floating-button-border-color'].';';
113
+ }
114
+ if (isset($popupOptions['sgpb-floating-button-bg-color'])) {
115
+ $buttonStyles .= 'background-color: '.$popupOptions['sgpb-floating-button-bg-color'].';';
116
+ }
117
+ if (isset($popupOptions['sgpb-floating-button-text-color'])) {
118
+ $buttonStyles .= 'color: '.$popupOptions['sgpb-floating-button-text-color'].';';
119
+ }
120
+
121
+ $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>';
122
+
123
+ echo $floatingButton;
124
+ }
125
+
126
+ public function filterOptionsBeforeSaving($unfilteredData = array())
127
+ {
128
+ $externalOptions = array(
129
+ 'icl_post_language' => 'sgpb-icl_post_language'
130
+ );
131
+
132
+ foreach ($externalOptions as $optionKey => $value) {
133
+ if (isset($unfilteredData[$optionKey])) {
134
+ $unfilteredData[$value] = $unfilteredData[$optionKey];
135
+ // 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"
136
+ }
137
+ }
138
+
139
+ return $unfilteredData;
140
+ }
141
+
142
+ public function userSelectionQueryAddExtraAttributes($query)
143
+ {
144
+ $query .= ' status = 0 and unsubscribed = 0';
145
+
146
+ return $query;
147
+ }
148
+
149
+ public function excludeRankMath($exclude, $type)
150
+ {
151
+ if ($type == SG_POPUP_POST_TYPE) {
152
+ $exclude = true;
153
+ }
154
+
155
+ return $exclude;
156
+ }
157
+
158
+ public function pluginRowMetas($pluginMeta, $pluginFile, $pluginData, $status)
159
+ {
160
+ if (empty($pluginFile)) {
161
+ return $pluginMeta;
162
+ }
163
+
164
+ $allExtensions = \SgpbDataConfig::allExtensionsKeys();
165
+ $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
166
+ $allExtensions[] = SG_POPUP_FILE_NAME;
167
+
168
+ $rowMeta = array(
169
+ 'rateus' => '<a href="'.SG_POPUP_RATE_US_URL.'" target="_blank">'.esc_html__('Rate us', SG_POPUP_TEXT_DOMAIN).'</a>',
170
+ 'support' => '<a href="'.SG_POPUP_SUPPORT_URL.'" target="_blank">'.esc_html__('Support', SG_POPUP_TEXT_DOMAIN).'</a>'
171
+ );
172
+
173
+ if (in_array($pluginFile, $allExtensions)) {
174
+ $pluginMeta = array_merge($pluginMeta, $rowMeta);
175
+ }
176
+
177
+ return $pluginMeta;
178
+ }
179
+
180
+ public function pluginActionLinks($actions, $pluginFile, $pluginData, $context)
181
+ {
182
+ if (empty($pluginFile)) {
183
+ return $actions;
184
+ }
185
+
186
+ $allExtensions = \SgpbDataConfig::allExtensionsKeys();
187
+ $allExtensions = wp_list_pluck($allExtensions, 'pluginKey');
188
+ $allExtensions[] = SG_POPUP_FILE_NAME;
189
+
190
+ $settingPageUrl = admin_url().'edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE;
191
+
192
+ $links = array(
193
+ 'settings' => '<a href="'.$settingPageUrl.'" target="_blank">'.esc_html__('Settings', SG_POPUP_TEXT_DOMAIN).'</a>',
194
+ 'docs' => '<a href="'.SG_POPUP_TICKET_URL.'" target="_blank">'.esc_html__('Docs', SG_POPUP_TEXT_DOMAIN).'</a>'
195
+ );
196
+
197
+ if (in_array($pluginFile, $allExtensions)) {
198
+ if ($pluginFile == SG_POPUP_FILE_NAME) {
199
+ $getActiveExtensions = AdminHelper::getAllExtensions();
200
+ if (empty($getActiveExtensions['active'])) {
201
+ $links['upgrade'] = '<a style="color: #4364eb;" href="'.SG_POPUP_BUNDLE_URL.'" target="_blank">'.esc_html__('Upgrade', SG_POPUP_TEXT_DOMAIN).'</a>';
202
+ }
203
+ }
204
+ $actions = array_merge($links, $actions);
205
+ }
206
+
207
+ return $actions;
208
+ }
209
+
210
+ public function systemInformation($infoContent)
211
+ {
212
+
213
+ $infoContent .= 'Platform: '.@$platform . "\n";
214
+ $infoContent .= 'Browser Name: '.@$bname . "\n";
215
+ $infoContent .= 'Browser Version: '.@$version . "\n";
216
+ $infoContent .= 'User Agent: '.@$uAgent . "\n";
217
+
218
+ return $infoContent;
219
+ }
220
+
221
+ public function popupContentLoadToPage($content, $popupId)
222
+ {
223
+ $customScripts = AdminHelper::renderCustomScripts($popupId);
224
+ $content .= $customScripts;
225
+
226
+ return $content;
227
+ }
228
+
229
+ public function sgpbExtraNotifications($notifications = array())
230
+ {
231
+ $license = self::licenseNotification();
232
+ if (!empty($license)) {
233
+ $notifications[] = $license;
234
+ }
235
+
236
+ $promotional = self::promotionalNotifications();
237
+ if (!empty($promotional)) {
238
+ $notifications[] = $promotional;
239
+ }
240
+
241
+ $supportBanner = self::supportBannerNotifcations();
242
+ if (!empty($supportBanner)) {
243
+ $notifications[] = $supportBanner;
244
+ }
245
+
246
+ return $notifications;
247
+ }
248
+
249
+ public static function supportBannerNotifcations()
250
+ {
251
+ $hideSupportBanner = get_option('sgpb-hide-support-banner');
252
+ if (!empty($hideSupportBanner)) {
253
+ return array();
254
+ }
255
+ $message = AdminHelper::supportBannerNotification();
256
+ $notification['id'] = SGPB_SUPPORT_BANNER_NOTIFICATION_ID;
257
+ $notification['priority'] = 1;
258
+ $notification['type'] = 1;
259
+ $notification['message'] = $message;
260
+
261
+ return $notification;
262
+ }
263
+
264
+ public static function promotionalNotifications()
265
+ {
266
+ $alreadyDone = get_option('SGPBCloseReviewPopup-notification');
267
+ if (!empty($alreadyDone)) {
268
+ return array();
269
+ }
270
+ $id = SGPB_RATE_US_NOTIFICATION_ID;
271
+ $type = 1;
272
+ $priority = 1;
273
+
274
+ $maxOpenPopupStatus = AdminHelper::shouldOpenForMaxOpenPopupMessage();
275
+ // popup opening count notification
276
+ if ($maxOpenPopupStatus) {
277
+ $message = AdminHelper::getMaxOpenPopupsMessage();
278
+ }
279
+
280
+ $shouldOpenForDays = AdminHelper::shouldOpenReviewPopupForDays();
281
+ if ($shouldOpenForDays && !$maxOpenPopupStatus) {
282
+ $message = AdminHelper::getMaxOpenDaysMessage();
283
+ }
284
+ if (empty($message)) {
285
+ return array();
286
+ }
287
+
288
+ $alternateNotification['priority'] = $priority;
289
+ $alternateNotification['type'] = $type;
290
+ $alternateNotification['id'] = $id;
291
+ $alternateNotification['message'] = $message;
292
+
293
+ return $alternateNotification;
294
+ }
295
+
296
+ public function licenseNotification()
297
+ {
298
+ $inactiveExtensionNotice = array();
299
+ $dontShowLicenseBanner = get_option('sgpb-hide-license-notice-banner');
300
+ if ($dontShowLicenseBanner) {
301
+ return $notifications;
302
+ }
303
+
304
+ $inactive = AdminHelper::getOption('SGPB_INACTIVE_EXTENSIONS');
305
+ $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
306
+
307
+ if (!$inactive) {
308
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 1);
309
+ if ($hasInactiveExtensions) {
310
+ AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
311
+ $inactive = 'inactive';
312
+ }
313
+
314
+ }
315
+
316
+ if ($hasInactiveExtensions && $inactive == 'inactive') {
317
+ $licenseSectionUrl = menu_page_url(SGPB_POPUP_LICENSE, false);
318
+ $partOfContent = '<br><br>'.__('<a href="'.$licenseSectionUrl.'">Follow the link</a> to finalize the activation.', SG_POPUP_TEXT_DOMAIN);
319
+ $message = '<b>'.__('Thank you for choosing our plugin!', SG_POPUP_TEXT_DOMAIN).'</b>';
320
+ $message .= '<br>';
321
+ $message .= '<br>';
322
+ $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>';
323
+ $message .= '<b>'.$partOfContent.'</b>';
324
+
325
+ $inactiveExtensionNotice['priority'] = 1;
326
+ $inactiveExtensionNotice['type'] = 2;
327
+ $inactiveExtensionNotice['id'] = 'sgpbMainActiveInactiveLicense';
328
+ $inactiveExtensionNotice['message'] = $message;
329
+ }
330
+
331
+ return $inactiveExtensionNotice;
332
+ }
333
+
334
+ public function excludeSitemapsYoast($exclude = false, $postType)
335
+ {
336
+ $postTypeObject = get_post_type_object($postType);
337
+ if (!is_object($postTypeObject)) {
338
+ return $exclude;
339
+ }
340
+
341
+ if ($postTypeObject->public === false || $postType == SG_POPUP_POST_TYPE) {
342
+ return true;
343
+ }
344
+
345
+ return $exclude;
346
+ }
347
+
348
+ public function defaultAdvancedOptionsValues($options = array())
349
+ {
350
+ $enablePopupOverlay = PopupBuilderActivePackage::canUseOption('sgpb-enable-popup-overlay');
351
+ if (!$enablePopupOverlay) {
352
+ $options['sgpb-enable-popup-overlay'] = 'on';
353
+ }
354
+
355
+ return $options;
356
+ }
357
+
358
+ public function excludePostToShowPrepare()
359
+ {
360
+ SgpbPopupConfig::popupTypesInit();
361
+ $queryString = SGPopup::getActivePopupsQueryString();
362
+ $this->setQueryString($queryString);
363
+ add_filter('posts_where' , array($this, 'excludePostsToShow'), 10, 1);
364
+ }
365
+
366
+ public function exportFileName($fileName)
367
+ {
368
+ if (!empty($_GET['sgpbExportAction'])) {
369
+ return SGPB_POPUP_EXPORT_FILE_NAME;
370
+ }
371
+
372
+ return $fileName;
373
+ }
374
+
375
+ public function filterOption($filterOption)
376
+ {
377
+ $extensionOptionsData = AdminHelper::getExtensionAvaliabilityOptions();
378
+
379
+ if (empty($extensionOptionsData)) {
380
+ return $filterOption;
381
+ }
382
+
383
+ foreach ($extensionOptionsData as $extensionKey => $extensionOptions) {
384
+ $isAdvancedClosingActive = is_plugin_active($extensionKey);
385
+ if (isset($filterOption['name']) && !$isAdvancedClosingActive) {
386
+ $name = $filterOption['name'];
387
+
388
+ if (in_array($name, $extensionOptions)) {
389
+ $filterOption['status'] = false;
390
+ }
391
+ }
392
+ }
393
+
394
+ return $filterOption;
395
+ }
396
+
397
+ public function metaboxes($metaboxes)
398
+ {
399
+ $otherConditionsProLabel = '';
400
+ $otherConditionsCanBeUsed = PopupBuilderActivePackage::canUseSection('popupOtherConditionsSection');
401
+ if (!$otherConditionsCanBeUsed) {
402
+ $otherConditionsProLabel .= '<a href="'.SG_POPUP_SCHEDULING_URL.'" target="_blank" class="sgpb-pro-label-metabox">';
403
+ $otherConditionsProLabel .= __('UNLOCK OPTION', SG_POPUP_TEXT_DOMAIN).'</a>';
404
+ }
405
+ $metaboxes['targetMetaboxView'] = array(
406
+ 'key' => 'targetMetaboxView',
407
+ 'displayName' => 'Popup Display Rules',
408
+ 'filePath' => SG_POPUP_VIEWS_PATH.'targetView.php',
409
+ 'priority' => 'high'
410
+ );
411
+
412
+ $metaboxes['eventsMetaboxView'] = array(
413
+ 'key' => 'eventsMetaboxView',
414
+ 'displayName' => 'Popup Events',
415
+ 'filePath' => SG_POPUP_VIEWS_PATH.'eventsView.php',
416
+ 'priority' => 'high'
417
+ );
418
+
419
+ $metaboxes['conditionsMetaboxView'] = array(
420
+ 'key' => 'conditionsMetaboxView',
421
+ 'displayName' => 'Popup Conditions',
422
+ 'filePath' => SG_POPUP_VIEWS_PATH.'conditionsView.php',
423
+ 'priority' => 'high'
424
+ );
425
+
426
+ $metaboxes['behaviorAfterSpecialEventsMetaboxView'] = array(
427
+ 'key' => 'behaviorAfterSpecialEventsMetaboxView',
428
+ 'displayName' => 'Behavior After Special Events',
429
+ 'filePath' => SG_POPUP_VIEWS_PATH.'behaviorAfterSpecialEventsView.php',
430
+ 'priority' => 'high'
431
+ );
432
+
433
+ $metaboxes['popupDesignMetaBoxView'] = array(
434
+ 'key' => 'popupDesignMetaBoxView',
435
+ 'displayName' => 'Design',
436
+ 'filePath' => SG_POPUP_VIEWS_PATH.'popupDesignView.php',
437
+ 'priority' => 'high'
438
+ );
439
+
440
+ $metaboxes['closeSettings'] = array(
441
+ 'key' => 'closeSettings',
442
+ 'displayName' => 'Close Settings',
443
+ 'filePath' => SG_POPUP_VIEWS_PATH.'closeSettingsView.php',
444
+ 'priority' => 'high'
445
+ );
446
+
447
+ $metaboxes['spgdimension'] = array(
448
+ 'key' => 'spgdimension',
449
+ 'displayName' => 'Dimensions',
450
+ 'filePath' => SG_POPUP_VIEWS_PATH.'dimensionsView.php',
451
+ 'priority' => 'high'
452
+ );
453
+
454
+ $metaboxes['optionsMetaboxView'] = array(
455
+ 'key' => 'optionsMetaboxView',
456
+ 'displayName' => 'Popup Options',
457
+ 'filePath' => SG_POPUP_VIEWS_PATH.'optionsView.php',
458
+ 'priority' => 'high'
459
+ );
460
+
461
+ $metaboxes['otherConditionsMetaBoxView'] = array(
462
+ 'key' => 'otherConditionsMetaBoxView',
463
+ 'displayName' => 'Popup Additional Conditions'.$otherConditionsProLabel,
464
+ 'filePath' => SG_POPUP_VIEWS_PATH.'otherConditionsView.php',
465
+ 'priority' => 'high'
466
+ );
467
+
468
+ $metaboxes['customCssJs'] = array(
469
+ 'key' => 'customCssJs',
470
+ 'displayName' => 'Custom JS or CSS',
471
+ 'filePath' => SG_POPUP_VIEWS_PATH.'customEditor.php',
472
+ 'priority' => 'low'
473
+ );
474
+
475
+ $metaboxes['floatingButton'] = array(
476
+ 'key' => 'floatingButton',
477
+ 'displayName' => 'Floating Button',
478
+ 'filePath' => SG_POPUP_VIEWS_PATH.'floatingButton.php',
479
+ 'context' => 'side',
480
+ 'priority' => 'high'
481
+ );
482
+
483
+ $metaboxes['popupOpeningCounter'] = array(
484
+ 'key' => 'popupOpeningCounter',
485
+ 'displayName' => 'Popup statistics',
486
+ 'filePath' => SG_POPUP_VIEWS_PATH.'popupOpeningCounter.php',
487
+ 'context' => 'side',
488
+ 'priority' => 'low'
489
+ );
490
+
491
+ return $metaboxes;
492
+ }
493
+
494
+ public function popupEvents($events)
495
+ {
496
+ foreach ($events as $eventKey => $eventData) {
497
+ if (isset($eventData['param'])) {
498
+ if ($eventData['param'] == SGPB_CSS_CLASS_ACTIONS_KEY) {
499
+ unset($events[$eventKey]);
500
+ $events[] = array('param' => 'click');
501
+ $events[] = array('param' => 'hover');
502
+ $events[] = array('param' => 'confirm');
503
+ }
504
+ else if ($eventData['param'] == SGPB_CLICK_ACTION_KEY) {
505
+ $events[$eventKey]['param'] = 'click';
506
+ }
507
+ else if ($eventData['param'] == SGPB_HOVER_ACTION_KEY) {
508
+ $events[$eventKey]['param'] = 'hover';
509
+ }
510
+ }
511
+ }
512
+
513
+ return $events;
514
+ }
515
+
516
+ public function savedPostData($postData)
517
+ {
518
+ // for old popups here we change already saved old popup id
519
+ if (isset($postData['sgpb-mailchimp-success-popup'])) {
520
+ // sgpGetCorrectPopupId it's a temporary function and it will be removed in future
521
+ if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
522
+ $postData['sgpb-mailchimp-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-mailchimp-success-popup']);
523
+ }
524
+ }
525
+ // for old popups here we change already saved old popup id
526
+ if (isset($postData['sgpb-aweber-success-popup'])) {
527
+ if (function_exists(__NAMESPACE__.'\sgpGetCorrectPopupId')) {
528
+ $postData['sgpb-aweber-success-popup'] = sgpGetCorrectPopupId($postData['sgpb-aweber-success-popup']);
529
+ }
530
+ }
531
+
532
+ return $postData;
533
+ }
534
+
535
+ public function removeAddNewSubmenu()
536
+ {
537
+ //we don't need the default add new, since we are using our custom page for it
538
+ $page = remove_submenu_page(
539
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
540
+ 'post-new.php?post_type='.SG_POPUP_POST_TYPE
541
+ );
542
+ }
543
+
544
+ public function maybeShortenEddFilename($return, $package)
545
+ {
546
+ if (strpos($package, SG_POPUP_STORE_URL) !== false) {
547
+ add_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 100, 2);
548
+ }
549
+ return $return;
550
+ }
551
+
552
+ public function shortenEddFilename($filename, $ext)
553
+ {
554
+ $filename = substr($filename, 0, 20).$ext;
555
+ remove_filter('wp_unique_filename', array($this, 'shortenEddFilename'), 10);
556
+ return $filename;
557
+ }
558
+
559
+ public function editPopupPreviewLink($previewLink = '', $post = array())
560
+ {
561
+ if (!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) {
562
+ $popupId = $post->ID;
563
+ $targets = get_post_meta($popupId, 'sg_popup_target_preview', true);
564
+ if (empty($targets['sgpb-target'][0])) {
565
+ return $previewLink .= '/?sg_popup_preview_id='.$popupId;
566
+ }
567
+ $targetParams = @$targets['sgpb-target'][0][0]['param'];
568
+ if ((!empty($targetParams) && $targetParams == 'not_rule') || empty($targetParams)) {
569
+ $previewLink = home_url();
570
+ $previewLink .= '/?sg_popup_preview_id='.$popupId;
571
+
572
+ return $previewLink;
573
+ }
574
+ foreach ($targets['sgpb-target'][0] as $targetKey => $targetValue) {
575
+ if (!isset($targetValue['operator']) || $targetValue['operator'] == '!=') {
576
+ continue;
577
+ }
578
+ $previewLink = self::getPopupPreviewLink($targetValue, $popupId);
579
+ $previewLink .= '/?sg_popup_preview_id='.$popupId;
580
+ }
581
+ }
582
+
583
+ return $previewLink;
584
+ }
585
+
586
+ public static function getPopupPreviewLink($targetData, $popupId)
587
+ {
588
+ $previewLink = home_url();
589
+
590
+ if (empty($targetData['param'])) {
591
+ return $previewLink;
592
+ }
593
+ $targetParam = $targetData['param'];
594
+
595
+ if ($targetParam == 'everywhere') {
596
+ return $previewLink;
597
+ }
598
+
599
+ $args = array(
600
+ 'orderby' => 'rand'
601
+ );
602
+
603
+ // posts
604
+ if (strpos($targetData['param'], '_all')) {
605
+ if ($targetData['param'] == 'post_all') {
606
+ $args['post_type'] = 'post';
607
+ }
608
+ if ($targetData['param'] == 'page_all') {
609
+ $args['post_type'] = 'page';
610
+ }
611
+ }
612
+ if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
613
+ $args['post_type'] = $targetData['value'];
614
+ }
615
+ if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
616
+ $pageTypes = $targetData['value'];
617
+ foreach ($pageTypes as $pageType) {
618
+
619
+ if ($pageType == 'is_home_page') {
620
+ if (is_front_page() && is_home()) {
621
+ // default homepage
622
+ return get_home_url();
623
+ }
624
+ else if (is_front_page()) {
625
+ // static homepage
626
+ return get_home_url();
627
+ }
628
+ }
629
+ else if (function_exists($pageType)) {
630
+ if ($pageType == 'is_home') {
631
+ return get_home_url();
632
+ }
633
+ else if ($pageType == 'is_search') {
634
+ return get_search_link();
635
+ }
636
+ else if ($pageType == 'is_shop') {
637
+ return get_home_url().'/shop/';
638
+ }
639
+ }
640
+ }
641
+ }
642
+ if (isset($args['post_type'])) {
643
+ $the_query = new WP_Query($args);
644
+ foreach ($the_query->posts as $post) {
645
+ $postId = $post->ID;
646
+ if (get_permalink($postId)) {
647
+ return get_permalink($postId);
648
+ }
649
+ }
650
+ }
651
+ // selected post/page/custom_post_types...
652
+ if (strpos($targetData['param'], '_selected') && !empty($targetData['value'])) {
653
+ $value = array_keys($targetData['value']);
654
+ if (!empty($value[0])) {
655
+ if (get_permalink($value[0])) {
656
+ return get_permalink($value[0]);
657
+ }
658
+ }
659
+ }
660
+ if (strpos($targetData['param'], '_archive') && !empty($targetData['value'])) {
661
+ $value = array_keys($targetData['value']);
662
+ if (!empty($value[0])) {
663
+ if (get_permalink($value[0])) {
664
+ return get_permalink($value[0]);
665
+ }
666
+ }
667
+ }
668
+
669
+ return $previewLink;
670
+ }
671
+
672
+ public function excludePostsToShow($where)
673
+ {
674
+ if (function_exists('is_admin') && is_admin()) {
675
+ if (!function_exists('get_current_screen')) {
676
+ return $where;
677
+ }
678
+
679
+ $screen = get_current_screen();
680
+ if (empty($screen)) {
681
+ return $where;
682
+ }
683
+
684
+ $postType = $screen->post_type;
685
+ if ($postType == SG_POPUP_POST_TYPE &&
686
+ $screen instanceof \WP_Screen &&
687
+ $screen->id === 'edit-popupbuilder') {
688
+ if (class_exists('sgpb\SGPopup')) {
689
+ $activePopupsQuery = $this->getQueryString();
690
+ if ($activePopupsQuery && $activePopupsQuery != '') {
691
+ $where .= $activePopupsQuery;
692
+ }
693
+ }
694
+ }
695
+ }
696
+
697
+ return $where;
698
+ }
699
+
700
+ public function clearContentPreviewMode($content)
701
+ {
702
+ global $post_type;
703
+
704
+ if (is_preview() && $post_type == SG_POPUP_POST_TYPE) {
705
+ $content = '';
706
+ }
707
+
708
+ return $content;
709
+ }
710
+
711
+ public function filterPopupContent($content, $popupId)
712
+ {
713
+ preg_match_all('/<iframe.*?src="(.*?)".*?<\/iframe>/', $content, $matches);
714
+ /*$finalContent = '';*/
715
+ // $matches[0] array contain iframes stings
716
+ // $matches[1] array contain iframes URLs
717
+ if (empty($matches) && empty($matches[0]) && empty($matches[1])) {
718
+ return $content;
719
+ }
720
+ $urls = $matches[1];
721
+
722
+ foreach ($matches[0] as $key => $iframe) {
723
+ if (empty($urls[$key])) {
724
+ continue;
725
+ }
726
+
727
+ $pos = strpos($iframe, $urls[$key]);
728
+
729
+ if ($pos === false) {
730
+ continue;
731
+ }
732
+
733
+ $content = str_replace(' src="'.$urls[$key].'"', ' src="" data-attr-src="'.esc_attr($urls[$key]).'"', $content);
734
+ }
735
+ if (function_exists('do_blocks')) {
736
+ $content = do_blocks($content);
737
+ }
738
+
739
+ return do_shortcode($content);
740
+ }
741
+
742
+ public function addNewPostUrl($url, $path)
743
+ {
744
+ if ($path == 'post-new.php?post_type='.SG_POPUP_POST_TYPE) {
745
+ $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);
746
+ }
747
+
748
+ return $url;
749
+ }
750
+
751
+ public function popupsTableColumns($columns)
752
+ {
753
+ unset($columns['date']);
754
+
755
+ $additionalItems = array();
756
+ $additionalItems['counter'] = __('Views', SG_POPUP_TEXT_DOMAIN);
757
+ $additionalItems['onOff'] = __('Enabled (show popup)', SG_POPUP_TEXT_DOMAIN);
758
+ $additionalItems['type'] = __('Type', SG_POPUP_TEXT_DOMAIN);
759
+ $additionalItems['shortcode'] = __('Shortcode', SG_POPUP_TEXT_DOMAIN);
760
+ $additionalItems['className'] = __('Class', SG_POPUP_TEXT_DOMAIN);
761
+
762
+ return $columns + $additionalItems;
763
+ }
764
+
765
+ /**
766
+ * Function to add/hide links from popups dataTable row
767
+ */
768
+ public function quickRowLinksManager($actions, $post)
769
+ {
770
+ global $post_type;
771
+
772
+ if ($post_type != SG_POPUP_POST_TYPE) {
773
+ return $actions;
774
+ }
775
+ // remove quick edit link
776
+ unset($actions['inline hide-if-no-js']);
777
+ // remove view link
778
+ unset($actions['view']);
779
+
780
+ $actions['clone'] = '<a href="'.$this->popupGetClonePostLink($post->ID , 'display', false).'" title="';
781
+ $actions['clone'] .= esc_attr__("Clone this item", SG_POPUP_TEXT_DOMAIN);
782
+ $actions['clone'] .= '">'. esc_html__('Clone', SG_POPUP_TEXT_DOMAIN).'</a>';
783
+
784
+ return $actions;
785
+ }
786
+
787
+ /**
788
+ * Retrieve duplicate post link for post.
789
+ *
790
+ * @param int $id Optional. Post ID.
791
+ * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
792
+ * @return string
793
+ */
794
+ public function popupGetClonePostLink($id = 0, $context = 'display')
795
+ {
796
+ if (!$post = get_post($id)) {
797
+ return;
798
+ }
799
+ $actionName = "popupSaveAsNew";
800
+
801
+ if ('display' == $context) {
802
+ $action = '?action='.$actionName.'&amp;post='.$post->ID;
803
+ } else {
804
+ $action = '?action='.$actionName.'&post='.$post->ID;
805
+ }
806
+
807
+ $postTypeObject = get_post_type_object($post->post_type);
808
+
809
+ if (!$postTypeObject) {
810
+ return;
811
+ }
812
+
813
+ return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
814
+ }
815
+
816
+ /* media button scripts */
817
+ public function adminJsFilter($jsFiles)
818
+ {
819
+ $allowToShow = MediaButton::allowToShow();
820
+ if ($allowToShow) {
821
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
822
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
823
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'Popup.js');
824
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
825
+ $jsFiles['jsFiles'][] = array('folderUrl' => SG_POPUP_JS_URL, 'filename' => 'MediaButton.js');
826
+
827
+ $jsFiles['localizeData'][] = array(
828
+ 'handle' => 'Popup.js',
829
+ 'name' => 'sgpbPublicUrl',
830
+ 'data' => SG_POPUP_PUBLIC_URL
831
+ );
832
+
833
+ $jsFiles['localizeData'][] = array(
834
+ 'handle' => 'MediaButton.js',
835
+ 'name' => 'mediaButtonParams',
836
+ 'data' => array(
837
+ 'currentPostType' => get_post_type(),
838
+ 'popupBuilderPostType' => SG_POPUP_POST_TYPE,
839
+ 'ajaxUrl' => admin_url('admin-ajax.php'),
840
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
841
+ )
842
+ );
843
+ }
844
+
845
+ return $jsFiles;
846
+ }
847
+
848
+ /* media button styles */
849
+ public function sgpbAdminCssFiles($cssFiles)
850
+ {
851
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
852
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
853
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
854
+
855
+ return $cssFiles;
856
+ }
857
+ }
858
+
859
+
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 = "'.$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,123 +1,123 @@
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
- $pageName = $hook;
16
- $scripts = array();
17
- $popupType = AdminHelper::getCurrentPopupType();
18
- $currentPostType = AdminHelper::getCurrentPostType();
19
-
20
- if($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
21
- $pageName = 'popupType';
22
- }
23
- else if(($hook == 'post-new.php' || $hook == 'post.php') && $currentPostType == SG_POPUP_POST_TYPE) {
24
- $pageName = 'editpage';
25
- }
26
- else if($hook == 'edit.php' && !empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
27
- $pageName = 'popupspage';
28
- }
29
- else if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SUBSCRIBERS_PAGE) {
30
- $pageName = SG_POPUP_SUBSCRIBERS_PAGE;
31
- }
32
-
33
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
34
-
35
- if(!$registeredPlugins) {
36
- return;
37
- }
38
- $registeredPlugins = json_decode($registeredPlugins, true);
39
-
40
- if(empty($registeredPlugins)) {
41
- return;
42
- }
43
-
44
- wp_enqueue_media();
45
-
46
- foreach($registeredPlugins as $pluginName => $pluginData) {
47
-
48
- if (!is_plugin_active($pluginName)) {
49
- continue;
50
- }
51
-
52
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
53
- continue;
54
- }
55
- $classPath = $pluginData['classPath'];
56
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
57
-
58
- if (!file_exists($classPath)) {
59
- continue;
60
- }
61
-
62
- require_once($classPath);
63
-
64
- if (!class_exists($pluginData['className'])) {
65
- continue;
66
- }
67
-
68
- $classObj = new $pluginData['className']();
69
-
70
- if(!$classObj instanceof \SgpbIPopupExtension) {
71
- continue;
72
- }
73
- $args = array(
74
- 'popupType' => $popupType
75
- );
76
- $scriptData = $classObj->getScripts($pageName , $args);
77
-
78
- $scripts[] = $scriptData;
79
- }
80
-
81
- if(empty($scripts)) {
82
- return;
83
- }
84
-
85
- foreach($scripts as $script) {
86
- if(empty($script['jsFiles'])) {
87
- continue;
88
- }
89
-
90
- foreach($script['jsFiles'] as $jsFile) {
91
-
92
- if(empty($jsFile['folderUrl'])) {
93
- wp_enqueue_script($jsFile['filename']);
94
- continue;
95
- }
96
-
97
- $dirUrl = $jsFile['folderUrl'];
98
- $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
99
- $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
100
- $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
101
-
102
- ScriptsIncluder::registerScript($jsFile['filename'], array(
103
- 'dirUrl'=> $dirUrl,
104
- 'dep' => $dep,
105
- 'ver' => $ver,
106
- 'inFooter' => $inFooter
107
- )
108
- );
109
- ScriptsIncluder::enqueueScript($jsFile['filename']);
110
- }
111
-
112
- if(empty($script['localizeData'])) {
113
- continue;
114
- }
115
-
116
- $localizeDatas = $script['localizeData'];
117
-
118
- foreach($localizeDatas as $localizeData) {
119
- ScriptsIncluder::localizeScript($localizeData['handle'], $localizeData['name'], $localizeData['data']);
120
- }
121
- }
122
- }
123
- }
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
+ $pageName = $hook;
16
+ $scripts = array();
17
+ $popupType = AdminHelper::getCurrentPopupType();
18
+ $currentPostType = AdminHelper::getCurrentPostType();
19
+
20
+ if($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_POST_TYPE) {
21
+ $pageName = 'popupType';
22
+ }
23
+ else if(($hook == 'post-new.php' || $hook == 'post.php') && $currentPostType == SG_POPUP_POST_TYPE) {
24
+ $pageName = 'editpage';
25
+ }
26
+ else if($hook == 'edit.php' && !empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
27
+ $pageName = 'popupspage';
28
+ }
29
+ else if ($hook == SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SUBSCRIBERS_PAGE) {
30
+ $pageName = SG_POPUP_SUBSCRIBERS_PAGE;
31
+ }
32
+
33
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
34
+
35
+ if(!$registeredPlugins) {
36
+ return;
37
+ }
38
+ $registeredPlugins = json_decode($registeredPlugins, true);
39
+
40
+ if(empty($registeredPlugins)) {
41
+ return;
42
+ }
43
+
44
+ wp_enqueue_media();
45
+
46
+ foreach($registeredPlugins as $pluginName => $pluginData) {
47
+
48
+ if (!is_plugin_active($pluginName)) {
49
+ continue;
50
+ }
51
+
52
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
53
+ continue;
54
+ }
55
+ $classPath = $pluginData['classPath'];
56
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
57
+
58
+ if (!file_exists($classPath)) {
59
+ continue;
60
+ }
61
+
62
+ require_once($classPath);
63
+
64
+ if (!class_exists($pluginData['className'])) {
65
+ continue;
66
+ }
67
+
68
+ $classObj = new $pluginData['className']();
69
+
70
+ if(!$classObj instanceof \SgpbIPopupExtension) {
71
+ continue;
72
+ }
73
+ $args = array(
74
+ 'popupType' => $popupType
75
+ );
76
+ $scriptData = $classObj->getScripts($pageName , $args);
77
+
78
+ $scripts[] = $scriptData;
79
+ }
80
+
81
+ if(empty($scripts)) {
82
+ return;
83
+ }
84
+
85
+ foreach($scripts as $script) {
86
+ if(empty($script['jsFiles'])) {
87
+ continue;
88
+ }
89
+
90
+ foreach($script['jsFiles'] as $jsFile) {
91
+
92
+ if(empty($jsFile['folderUrl'])) {
93
+ wp_enqueue_script($jsFile['filename']);
94
+ continue;
95
+ }
96
+
97
+ $dirUrl = $jsFile['folderUrl'];
98
+ $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
99
+ $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
100
+ $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
101
+
102
+ ScriptsIncluder::registerScript($jsFile['filename'], array(
103
+ 'dirUrl'=> $dirUrl,
104
+ 'dep' => $dep,
105
+ 'ver' => $ver,
106
+ 'inFooter' => $inFooter
107
+ )
108
+ );
109
+ ScriptsIncluder::enqueueScript($jsFile['filename']);
110
+ }
111
+
112
+ if(empty($script['localizeData'])) {
113
+ continue;
114
+ }
115
+
116
+ $localizeDatas = $script['localizeData'];
117
+
118
+ foreach($localizeDatas as $localizeData) {
119
+ ScriptsIncluder::localizeScript($localizeData['handle'], $localizeData['name'], $localizeData['data']);
120
+ }
121
+ }
122
+ }
123
+ }
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 * 60,
97
- 'display' => __('Once a day', 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 * 60,
97
+ 'display' => __('Once a day', 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,641 +1,641 @@
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 $post;
18
-
19
- public static function instance()
20
- {
21
- if (!isset(self::$instance)) {
22
- self::$instance = new self;
23
- }
24
-
25
- return self::$instance;
26
- }
27
-
28
- public function setPopup($popup)
29
- {
30
- $this->popup = $popup;
31
- }
32
-
33
- public function getPopup()
34
- {
35
- return $this->popup;
36
- }
37
-
38
- public function setPost($post)
39
- {
40
- $this->post = $post;
41
- }
42
-
43
- public function getPost()
44
- {
45
- return $this->post;
46
- }
47
-
48
- /**
49
- * It checks whether popup should be loaded on the current page.
50
- *
51
- * @since 1.0.0
52
- *
53
- * @param int $popupId popup id
54
- * @param object $post page post data
55
- *
56
- * @return bool
57
- *
58
- */
59
- public function isLoadable($popup, $post)
60
- {
61
- $this->setPopup($popup);
62
- $this->setPost($post);
63
-
64
- $popupOptions = $popup->getOptions();
65
- $isActive = $popup->getOptionValue('sgpb-is-active', true);
66
- $saveMode = $popup->getSaveMode();
67
- $allowToLoad = $this->allowToLoad();
68
-
69
- if ($saveMode) {
70
- $allowToLoad['option_event'] = false;
71
- return $allowToLoad;
72
- }
73
-
74
- if (isset($popupOptions['sgpb-is-active'])) {
75
- $isActive = $popupOptions['sgpb-is-active'];
76
- if ($isActive) {
77
- $popup->setReportData($popup->getId());
78
- }
79
- }
80
-
81
- if (!$isActive) {
82
- $allowToLoad['option_event'] = false;
83
- }
84
-
85
- return $allowToLoad;
86
- }
87
-
88
- /**
89
- * Decides whether popup data should be loaded or not
90
- *
91
- * @since 1.0.0
92
- *
93
- * @return array
94
- *
95
- */
96
- private function allowToLoad()
97
- {
98
- $isCustomInserted = $this->isCustomInserted();
99
-
100
- $insertedModes = array(
101
- 'attr_event' => false,
102
- 'option_event' => false
103
- );
104
-
105
- if ($isCustomInserted) {
106
- $insertedModes['attr_event'] = true;
107
- }
108
-
109
- $target = $this->divideTargetData();
110
- $isPostInForbidden = $this->isPostInForbidden($target);
111
-
112
- if ($isPostInForbidden) {
113
- return $insertedModes;
114
- }
115
-
116
- if (!empty($target['forbidden']) && empty($target['permissive'])) {
117
- $conditions = $this->divideConditionsData();
118
- $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
119
- $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
120
-
121
- if ($isSatisfyForConditions === false) {
122
- return $insertedModes;
123
- }
124
- if ($this->isSatisfyForOtherConditions() === false) {
125
- return $insertedModes;
126
- }
127
- $insertedModes['option_event'] = true;
128
- }
129
-
130
- $isPermissive = $this->isPermissive($target);
131
-
132
- //If permissive for current page check conditions
133
- if ($isPermissive) {
134
- $conditions = $this->divideConditionsData();
135
- $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
136
- $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
137
-
138
- if ($isSatisfyForConditions === false) {
139
- return $insertedModes;
140
- }
141
- if ($this->isSatisfyForOtherConditions() === false) {
142
- return $insertedModes;
143
- }
144
- $insertedModes['option_event'] = $isPermissive;
145
- }
146
-
147
- return $insertedModes;
148
- }
149
-
150
- /**
151
- * check is Satisfy popup conditions
152
- *
153
- * @since 1.0.0
154
- *
155
- * @param array $conditions assoc array
156
- *
157
- * @return bool
158
- *
159
- */
160
- private function isSatisfyForConditions($conditions)
161
- {
162
- // proStartSilver
163
- $forbiddenConditions = $conditions['forbidden'];
164
- if (!empty($forbiddenConditions)) {
165
- foreach ($forbiddenConditions as $forbiddenCondition) {
166
- $isForbiddenConditions = $this->isSatisfyForConditionsOptions($forbiddenCondition);
167
- //If $isForbiddenConditions popup does not open
168
- if ($isForbiddenConditions) {
169
- return false;
170
- }
171
- }
172
- }
173
-
174
- $permissiveOptions = $conditions['permissive'];
175
- if (!empty($permissiveOptions)) {
176
- foreach ($permissiveOptions as $permissiveOption) {
177
- $isPermissiveConditions = $this->isSatisfyForConditionsOptions($permissiveOption);
178
- if (!$isPermissiveConditions) {
179
- return $isPermissiveConditions;
180
- }
181
-
182
- }
183
- }
184
-
185
-
186
-
187
- return true;
188
- }
189
-
190
- private function isSatisfyForConditionsOptions($option)
191
- {
192
- global $post;
193
- $paramName = $option['param'];
194
- $defaultStatus = false;
195
- $isAllowedConditionFilters = array();
196
- if ($paramName == 'select_role') {
197
- return true;
198
- }
199
- if (!$defaultStatus && do_action('isAllowedForConditions', $option, $post)) {
200
- $defaultStatus = true;
201
- }
202
-
203
- $isAllowedConditionFilters = apply_filters('isAllowedConditionFilters', array($option));
204
- if (isset($isAllowedConditionFilters['status']) && $isAllowedConditionFilters['status'] === true) {
205
- $defaultStatus = true;
206
- }
207
-
208
- return $defaultStatus;
209
- }
210
-
211
- /**
212
- * Check is popup inserted via short code or class attribute
213
- *
214
- * @since 1.0.0
215
- *
216
- * @param
217
- *
218
- * @return bool
219
- *
220
- */
221
- private function isCustomInserted()
222
- {
223
- $customInsertData = $this->getCustomInsertedData();
224
- $popup = $this->getPopup();
225
- // When popup object is empty it's mean popup is not custom inserted
226
- if (empty($popup)) {
227
- return false;
228
- }
229
- $popupId = $popup->getId();
230
-
231
- return in_array($popupId, $customInsertData);
232
- }
233
-
234
- /**
235
- * Should load data in the current page
236
- *
237
- * @since 1.0.0
238
- *
239
- * @param array $target popup saved target data
240
- *
241
- * @return bool $isPermissive true => allow false => don't allow
242
- *
243
- */
244
- private function isPermissive($target)
245
- {
246
- $isPermissive = false;
247
-
248
- if (empty($target['permissive'])) {
249
- $isPermissive = false;
250
- return $isPermissive;
251
- }
252
-
253
- foreach ($target['permissive'] as $targetData) {
254
- if ($this->isSatisfyForParam($targetData)) {
255
- $isPermissive = true;
256
- break;
257
- }
258
- }
259
-
260
- return $isPermissive;
261
- }
262
-
263
- /**
264
- * Check whether the target data disallows loading the popup data on the current page
265
- *
266
- * @since 1.0.0
267
- *
268
- * @param array $target popup saved target data
269
- *
270
- * @return bool $isForbidden true => don't allow false => allow
271
- *
272
- */
273
- private function isPostInForbidden($target)
274
- {
275
- $isForbidden = false;
276
-
277
- if (empty($target['forbidden'])) {
278
- return $isForbidden;
279
- }
280
-
281
- foreach ($target['forbidden'] as $targetData) {
282
- if ($this->isSatisfyForParam($targetData)) {
283
- $isForbidden = true;
284
- break;
285
- }
286
- }
287
-
288
- return $isForbidden;
289
- }
290
-
291
- /**
292
- * Check whether the current page is corresponding to the saved target data
293
- *
294
- * @since 1.0.0
295
- *
296
- * @param array $targetData popup saved target data
297
- *
298
- * @return bool $isSatisfy
299
- *
300
- */
301
- private function isSatisfyForParam($targetData)
302
- {
303
- $isSatisfy = false;
304
- $postId = get_queried_object_id();
305
-
306
- if (empty($targetData['param'])) {
307
- return $isSatisfy;
308
- }
309
- $targetParam = $targetData['param'];
310
- $post = $this->getPost();
311
- if (isset($post) && empty($postId)) {
312
- $postId = $post->ID;
313
- }
314
-
315
- if ($targetParam == 'everywhere') {
316
- return true;
317
- }
318
- if (strpos($targetData['param'], '_all')) {
319
- $endIndex = strpos($targetData['param'], '_all');
320
- $postType = substr($targetData['param'], 0, $endIndex);
321
- $currentPostType = get_post_type($postId);
322
-
323
- if ($postType == $currentPostType) {
324
- $isSatisfy = true;
325
- }
326
- }
327
- else if (strpos($targetData['param'], '_archive')) {
328
- $currentPostType = get_post_type();
329
- if ($targetData['param'] == $currentPostType.'_archive') {
330
- if (is_post_type_archive($currentPostType)) {
331
- $isSatisfy = true;
332
- }
333
- }
334
- }
335
- else if (strpos($targetData['param'], '_selected')) {
336
- $values = array();
337
-
338
- if (!empty($targetData['value'])) {
339
- $values = array_keys($targetData['value']);
340
- }
341
-
342
- if (in_array($postId, $values)) {
343
- $isSatisfy = true;
344
- }
345
- }
346
- else if (strpos($targetData['param'], '_categories')) {
347
- $values = array();
348
- $isSatisfy = false;
349
-
350
- if (!empty($targetData['value'])) {
351
- $values = array_values($targetData['value']);
352
- }
353
-
354
- global $post;
355
- // get current all taxonomies of the current post
356
- $taxonomies = get_post_taxonomies($post);
357
- foreach ($taxonomies as $taxonomy) {
358
- // get current post all categories
359
- $terms = get_the_terms($post->ID, $taxonomy);
360
- if (!empty($terms)) {
361
- foreach ($terms as $term) {
362
- if (empty($term)) {
363
- continue;
364
- }
365
- if (in_array($term->term_id, $values)) {
366
- $isSatisfy = true;
367
- break;
368
- }
369
- }
370
- }
371
- }
372
- }
373
- else if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
374
- $selectedCustomPostTypes = array_values($targetData['value']);
375
- $currentPostType = get_post_type($postId);
376
-
377
- if (in_array($currentPostType, $selectedCustomPostTypes)) {
378
- $isSatisfy = true;
379
- }
380
- }
381
- else if ($targetData['param'] == 'post_category' && !empty($targetData['value'])) {
382
- $values = $targetData['value'];
383
- $currentPostCategories = get_the_category($postId);
384
- $currentPostType = get_post_type($postId);
385
- if (empty($currentPostCategories) && $currentPostType == 'product') {
386
- $currentPostCategories = get_the_terms($postId, 'product_cat');
387
- }
388
-
389
- foreach ($currentPostCategories as $categoryName) {
390
- if (in_array($categoryName->term_id, $values)) {
391
- $isSatisfy = true;
392
- break;
393
- }
394
-
395
- }
396
- }
397
- else if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
398
- $postTypes = $targetData['value'];
399
- foreach ($postTypes as $postType) {
400
-
401
- if ($postType == 'is_home_page') {
402
- if (is_front_page() && is_home()) {
403
- // Default homepage
404
- $isSatisfy = true;
405
- break;
406
- } else if ( is_front_page() ) {
407
- // static homepage
408
- $isSatisfy = true;
409
- break;
410
- }
411
- }
412
- else if (function_exists($postType) && $postType()) {
413
- $isSatisfy = true;
414
- break;
415
- }
416
- }
417
- }
418
- else if ($targetData['param'] == 'page_template' && !empty($targetData['value'])) {
419
- $currentPageTemplate = basename(get_page_template());
420
- if (in_array($currentPageTemplate, $targetData['value'])) {
421
- $isSatisfy = true;
422
- }
423
- }
424
- else if ($targetData['param'] == 'post_tags') {
425
- if (has_tag()) {
426
- $isSatisfy = true;
427
- }
428
- }
429
- else if ($targetData['param'] == 'post_tags_ids') {
430
- $tagsObj = wp_get_post_tags($postId);
431
- $postTagsValues = (array)@$targetData['value'];
432
- $selectedTags = array_values($postTagsValues);
433
-
434
- foreach ($tagsObj as $tagObj) {
435
- if (in_array($tagObj->slug, $selectedTags)) {
436
- $isSatisfy = true;
437
- break;
438
- }
439
- }
440
- }
441
-
442
- if (!$isSatisfy && do_action('isAllowedForTarget', $targetData, $post)) {
443
- $isSatisfy = true;
444
- }
445
-
446
- return $isSatisfy;
447
- }
448
-
449
- /**
450
- * Divide conditions data to Permissive and Forbidden
451
- *
452
- * @since 1.0.0
453
- *
454
- * @return array $popupTargetData
455
- *
456
- */
457
- private function divideConditionsData()
458
- {
459
- $popup = $this->getPopup();
460
- $conditions = $popup->getConditions();
461
- $conditions = $this->divideIntoPermissiveAndForbidden($conditions);
462
-
463
- return $conditions;
464
- }
465
- /**
466
- * Divide target data to Permissive and Forbidden
467
- *
468
- * @since 1.0.0
469
- *
470
- * @return array $popupTargetData
471
- *
472
- */
473
- public function divideTargetData()
474
- {
475
- $popup = $this->getPopup();
476
- $targetData = $popup->getTarget();
477
- return $this->divideIntoPermissiveAndForbidden($targetData);
478
- }
479
-
480
- /**
481
- * Divide the Popup target data into Permissive And Forbidden assoc array
482
- *
483
- * @since 1.0.0
484
- *
485
- * @param array $postMetaData popup saved target data
486
- *
487
- * @return array $postMetaDivideData
488
- *
489
- */
490
- public function divideIntoPermissiveAndForbidden($targetData)
491
- {
492
- $permissive = array();
493
- $forbidden = array();
494
- $permissiveOperators = array('==');
495
- $forbiddenOperators = array('!=');
496
- $permissiveOperators = apply_filters('sgpbAdditionalPermissiveOperators', $permissiveOperators);
497
- $forbiddenOperators = apply_filters('sgpbAdditionalForbiddenOperators', $forbiddenOperators);
498
- if (!empty($targetData)) {
499
- foreach ($targetData as $data) {
500
- if (empty($data['operator']) && $data['param'] != 'everywhere' && !strpos($data['param'], '_all') && $data['param'] != 'post_tags') {
501
- break;
502
- }
503
- // set by default '==' (is) value for all not specific conditions like all pages/posts/other_custom_post_types for future correct detection
504
- if ($data['param'] == 'everywhere' || strpos($data['param'], '_all') || $data['param'] == 'post_tags') {
505
- $data['operator'] = '==';
506
- }
507
- if ((isset($data['operator']) && in_array($data['operator'], $permissiveOperators))) {
508
- $permissive[] = $data;
509
- }
510
- else if (in_array($data['operator'], $forbiddenOperators)) {
511
- $forbidden[] = $data;
512
- }
513
- }
514
- }
515
-
516
- $postMetaDivideData = array(
517
- 'permissive' => $permissive,
518
- 'forbidden' => $forbidden
519
- );
520
-
521
- return $postMetaDivideData;
522
- }
523
-
524
- /**
525
- * Get custom inserted data
526
- *
527
- * @since 1.0.0
528
- *
529
- * @return array $insertedData
530
- */
531
- public function getCustomInsertedData()
532
- {
533
- $post = $this->getPost();
534
- $insertedData = array();
535
-
536
- if (isset($post)) {
537
- $insertedData = SGPopup::getCustomInsertedDataByPostId($this->getPost()->ID);
538
- }
539
-
540
- return $insertedData;
541
- }
542
-
543
- /**
544
- * Check Popup conditions
545
- *
546
- * @since 1.0.0
547
- *
548
- * @return array
549
- *
550
- */
551
- private function isSatisfyForOtherConditions()
552
- {
553
- $popup = $this->getPopup();
554
- $popupOptions = $popup->getOptions();
555
- $popupId = $popup->getId();
556
-
557
- $dontAlowOpenPopup = apply_filters('sgpbOtherConditions', array('id' => $popupId, 'popupOptions' => $popupOptions, 'popupObj' => $popup));
558
-
559
- return $dontAlowOpenPopup['status'];
560
- }
561
-
562
- public static function checkUserStatus($savedStatus)
563
- {
564
- $equalStatus = true;
565
-
566
- /*When current user status and saved options does not matched popup must not open*/
567
- if (is_user_logged_in() != (int)$savedStatus) {
568
- $equalStatus = false;
569
- }
570
-
571
- return $equalStatus;
572
- }
573
-
574
- public static function checkLanguage($popupLanguage = '')
575
- {
576
- global $post;
577
-
578
- $postId = $post->ID;
579
- if (!function_exists('wpml_get_language_information')) {
580
- return true;
581
- }
582
- $postLanguage = wpml_get_language_information($postId);
583
- if (is_wp_error($postLanguage)) {
584
- return true;
585
- }
586
- if (!empty($_GET['lang']) && ($_GET['lang'] == $popupLanguage)) {
587
- return true;
588
- }
589
- if ($postLanguage['language_code'] != $popupLanguage) {
590
- return false;
591
- }
592
-
593
- return true;
594
- }
595
-
596
- public static function checkOtherConditionsActions($args)
597
- {
598
- if (empty($args['id']) || empty($args['popupOptions'])) {
599
- return false;
600
- }
601
-
602
- $popupOptions = $args['popupOptions'];
603
-
604
- if (!empty($popupOptions['sgpb-icl_post_language'])) {
605
- $languageCompatibilty = PopupChecker::checkLanguage($popupOptions['sgpb-icl_post_language']);
606
-
607
- if ($languageCompatibilty === false) {
608
- return $languageCompatibilty;
609
- }
610
- }
611
-
612
-
613
- // proStartSilver
614
- //User status check
615
- if (!empty($popupOptions['sgpb-user-status'])) {
616
- $restrictUserStatus = PopupChecker::checkUserStatus($popupOptions['sgpb-loggedin-user']);
617
-
618
- if ($restrictUserStatus === false) {
619
- return $restrictUserStatus;
620
- }
621
- }
622
-
623
- // proEndSilver
624
-
625
- // proStartPlatinum
626
- // proEndPlatinum
627
-
628
- // checking by popup type
629
- if (!empty($popupOptions['sgpb-type'])) {
630
- $popupClassName = SGPopup::getPopupClassNameFormType($popupOptions['sgpb-type']);
631
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
632
-
633
- if (method_exists($popupClassName, 'allowToOpen')) {
634
- $allowToOpen = $popupClassName::allowToOpen($popupOptions, $args);
635
- return $allowToOpen;
636
- }
637
- }
638
-
639
- return apply_filters('checkOtherConditions', true);
640
- }
641
- }
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 $post;
18
+
19
+ public static function instance()
20
+ {
21
+ if (!isset(self::$instance)) {
22
+ self::$instance = new self;
23
+ }
24
+
25
+ return self::$instance;
26
+ }
27
+
28
+ public function setPopup($popup)
29
+ {
30
+ $this->popup = $popup;
31
+ }
32
+
33
+ public function getPopup()
34
+ {
35
+ return $this->popup;
36
+ }
37
+
38
+ public function setPost($post)
39
+ {
40
+ $this->post = $post;
41
+ }
42
+
43
+ public function getPost()
44
+ {
45
+ return $this->post;
46
+ }
47
+
48
+ /**
49
+ * It checks whether popup should be loaded on the current page.
50
+ *
51
+ * @since 1.0.0
52
+ *
53
+ * @param int $popupId popup id
54
+ * @param object $post page post data
55
+ *
56
+ * @return bool
57
+ *
58
+ */
59
+ public function isLoadable($popup, $post)
60
+ {
61
+ $this->setPopup($popup);
62
+ $this->setPost($post);
63
+
64
+ $popupOptions = $popup->getOptions();
65
+ $isActive = $popup->getOptionValue('sgpb-is-active', true);
66
+ $saveMode = $popup->getSaveMode();
67
+ $allowToLoad = $this->allowToLoad();
68
+
69
+ if ($saveMode) {
70
+ $allowToLoad['option_event'] = false;
71
+ return $allowToLoad;
72
+ }
73
+
74
+ if (isset($popupOptions['sgpb-is-active'])) {
75
+ $isActive = $popupOptions['sgpb-is-active'];
76
+ if ($isActive) {
77
+ $popup->setReportData($popup->getId());
78
+ }
79
+ }
80
+
81
+ if (!$isActive) {
82
+ $allowToLoad['option_event'] = false;
83
+ }
84
+
85
+ return $allowToLoad;
86
+ }
87
+
88
+ /**
89
+ * Decides whether popup data should be loaded or not
90
+ *
91
+ * @since 1.0.0
92
+ *
93
+ * @return array
94
+ *
95
+ */
96
+ private function allowToLoad()
97
+ {
98
+ $isCustomInserted = $this->isCustomInserted();
99
+
100
+ $insertedModes = array(
101
+ 'attr_event' => false,
102
+ 'option_event' => false
103
+ );
104
+
105
+ if ($isCustomInserted) {
106
+ $insertedModes['attr_event'] = true;
107
+ }
108
+
109
+ $target = $this->divideTargetData();
110
+ $isPostInForbidden = $this->isPostInForbidden($target);
111
+
112
+ if ($isPostInForbidden) {
113
+ return $insertedModes;
114
+ }
115
+
116
+ if (!empty($target['forbidden']) && empty($target['permissive'])) {
117
+ $conditions = $this->divideConditionsData();
118
+ $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
119
+ $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
120
+
121
+ if ($isSatisfyForConditions === false) {
122
+ return $insertedModes;
123
+ }
124
+ if ($this->isSatisfyForOtherConditions() === false) {
125
+ return $insertedModes;
126
+ }
127
+ $insertedModes['option_event'] = true;
128
+ }
129
+
130
+ $isPermissive = $this->isPermissive($target);
131
+
132
+ //If permissive for current page check conditions
133
+ if ($isPermissive) {
134
+ $conditions = $this->divideConditionsData();
135
+ $conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
136
+ $isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
137
+
138
+ if ($isSatisfyForConditions === false) {
139
+ return $insertedModes;
140
+ }
141
+ if ($this->isSatisfyForOtherConditions() === false) {
142
+ return $insertedModes;
143
+ }
144
+ $insertedModes['option_event'] = $isPermissive;
145
+ }
146
+
147
+ return $insertedModes;
148
+ }
149
+
150
+ /**
151
+ * check is Satisfy popup conditions
152
+ *
153
+ * @since 1.0.0
154
+ *
155
+ * @param array $conditions assoc array
156
+ *
157
+ * @return bool
158
+ *
159
+ */
160
+ private function isSatisfyForConditions($conditions)
161
+ {
162
+ // proStartSilver
163
+ $forbiddenConditions = $conditions['forbidden'];
164
+ if (!empty($forbiddenConditions)) {
165
+ foreach ($forbiddenConditions as $forbiddenCondition) {
166
+ $isForbiddenConditions = $this->isSatisfyForConditionsOptions($forbiddenCondition);
167
+ //If $isForbiddenConditions popup does not open
168
+ if ($isForbiddenConditions) {
169
+ return false;
170
+ }
171
+ }
172
+ }
173
+
174
+ $permissiveOptions = $conditions['permissive'];
175
+ if (!empty($permissiveOptions)) {
176
+ foreach ($permissiveOptions as $permissiveOption) {
177
+ $isPermissiveConditions = $this->isSatisfyForConditionsOptions($permissiveOption);
178
+ if (!$isPermissiveConditions) {
179
+ return $isPermissiveConditions;
180
+ }
181
+
182
+ }
183
+ }
184
+
185
+
186
+
187
+ return true;
188
+ }
189
+
190
+ private function isSatisfyForConditionsOptions($option)
191
+ {
192
+ global $post;
193
+ $paramName = $option['param'];
194
+ $defaultStatus = false;
195
+ $isAllowedConditionFilters = array();
196
+ if ($paramName == 'select_role') {
197
+ return true;
198
+ }
199
+ if (!$defaultStatus && do_action('isAllowedForConditions', $option, $post)) {
200
+ $defaultStatus = true;
201
+ }
202
+
203
+ $isAllowedConditionFilters = apply_filters('isAllowedConditionFilters', array($option));
204
+ if (isset($isAllowedConditionFilters['status']) && $isAllowedConditionFilters['status'] === true) {
205
+ $defaultStatus = true;
206
+ }
207
+
208
+ return $defaultStatus;
209
+ }
210
+
211
+ /**
212
+ * Check is popup inserted via short code or class attribute
213
+ *
214
+ * @since 1.0.0
215
+ *
216
+ * @param
217
+ *
218
+ * @return bool
219
+ *
220
+ */
221
+ private function isCustomInserted()
222
+ {
223
+ $customInsertData = $this->getCustomInsertedData();
224
+ $popup = $this->getPopup();
225
+ // When popup object is empty it's mean popup is not custom inserted
226
+ if (empty($popup)) {
227
+ return false;
228
+ }
229
+ $popupId = $popup->getId();
230
+
231
+ return in_array($popupId, $customInsertData);
232
+ }
233
+
234
+ /**
235
+ * Should load data in the current page
236
+ *
237
+ * @since 1.0.0
238
+ *
239
+ * @param array $target popup saved target data
240
+ *
241
+ * @return bool $isPermissive true => allow false => don't allow
242
+ *
243
+ */
244
+ private function isPermissive($target)
245
+ {
246
+ $isPermissive = false;
247
+
248
+ if (empty($target['permissive'])) {
249
+ $isPermissive = false;
250
+ return $isPermissive;
251
+ }
252
+
253
+ foreach ($target['permissive'] as $targetData) {
254
+ if ($this->isSatisfyForParam($targetData)) {
255
+ $isPermissive = true;
256
+ break;
257
+ }
258
+ }
259
+
260
+ return $isPermissive;
261
+ }
262
+
263
+ /**
264
+ * Check whether the target data disallows loading the popup data on the current page
265
+ *
266
+ * @since 1.0.0
267
+ *
268
+ * @param array $target popup saved target data
269
+ *
270
+ * @return bool $isForbidden true => don't allow false => allow
271
+ *
272
+ */
273
+ private function isPostInForbidden($target)
274
+ {
275
+ $isForbidden = false;
276
+
277
+ if (empty($target['forbidden'])) {
278
+ return $isForbidden;
279
+ }
280
+
281
+ foreach ($target['forbidden'] as $targetData) {
282
+ if ($this->isSatisfyForParam($targetData)) {
283
+ $isForbidden = true;
284
+ break;
285
+ }
286
+ }
287
+
288
+ return $isForbidden;
289
+ }
290
+
291
+ /**
292
+ * Check whether the current page is corresponding to the saved target data
293
+ *
294
+ * @since 1.0.0
295
+ *
296
+ * @param array $targetData popup saved target data
297
+ *
298
+ * @return bool $isSatisfy
299
+ *
300
+ */
301
+ private function isSatisfyForParam($targetData)
302
+ {
303
+ $isSatisfy = false;
304
+ $postId = get_queried_object_id();
305
+
306
+ if (empty($targetData['param'])) {
307
+ return $isSatisfy;
308
+ }
309
+ $targetParam = $targetData['param'];
310
+ $post = $this->getPost();
311
+ if (isset($post) && empty($postId)) {
312
+ $postId = $post->ID;
313
+ }
314
+
315
+ if ($targetParam == 'everywhere') {
316
+ return true;
317
+ }
318
+ if (strpos($targetData['param'], '_all')) {
319
+ $endIndex = strpos($targetData['param'], '_all');
320
+ $postType = substr($targetData['param'], 0, $endIndex);
321
+ $currentPostType = get_post_type($postId);
322
+
323
+ if ($postType == $currentPostType) {
324
+ $isSatisfy = true;
325
+ }
326
+ }
327
+ else if (strpos($targetData['param'], '_archive')) {
328
+ $currentPostType = get_post_type();
329
+ if ($targetData['param'] == $currentPostType.'_archive') {
330
+ if (is_post_type_archive($currentPostType)) {
331
+ $isSatisfy = true;
332
+ }
333
+ }
334
+ }
335
+ else if (strpos($targetData['param'], '_selected')) {
336
+ $values = array();
337
+
338
+ if (!empty($targetData['value'])) {
339
+ $values = array_keys($targetData['value']);
340
+ }
341
+
342
+ if (in_array($postId, $values)) {
343
+ $isSatisfy = true;
344
+ }
345
+ }
346
+ else if (strpos($targetData['param'], '_categories')) {
347
+ $values = array();
348
+ $isSatisfy = false;
349
+
350
+ if (!empty($targetData['value'])) {
351
+ $values = array_values($targetData['value']);
352
+ }
353
+
354
+ global $post;
355
+ // get current all taxonomies of the current post
356
+ $taxonomies = get_post_taxonomies($post);
357
+ foreach ($taxonomies as $taxonomy) {
358
+ // get current post all categories
359
+ $terms = get_the_terms($post->ID, $taxonomy);
360
+ if (!empty($terms)) {
361
+ foreach ($terms as $term) {
362
+ if (empty($term)) {
363
+ continue;
364
+ }
365
+ if (in_array($term->term_id, $values)) {
366
+ $isSatisfy = true;
367
+ break;
368
+ }
369
+ }
370
+ }
371
+ }
372
+ }
373
+ else if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
374
+ $selectedCustomPostTypes = array_values($targetData['value']);
375
+ $currentPostType = get_post_type($postId);
376
+
377
+ if (in_array($currentPostType, $selectedCustomPostTypes)) {
378
+ $isSatisfy = true;
379
+ }
380
+ }
381
+ else if ($targetData['param'] == 'post_category' && !empty($targetData['value'])) {
382
+ $values = $targetData['value'];
383
+ $currentPostCategories = get_the_category($postId);
384
+ $currentPostType = get_post_type($postId);
385
+ if (empty($currentPostCategories) && $currentPostType == 'product') {
386
+ $currentPostCategories = get_the_terms($postId, 'product_cat');
387
+ }
388
+
389
+ foreach ($currentPostCategories as $categoryName) {
390
+ if (in_array($categoryName->term_id, $values)) {
391
+ $isSatisfy = true;
392
+ break;
393
+ }
394
+
395
+ }
396
+ }
397
+ else if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
398
+ $postTypes = $targetData['value'];
399
+ foreach ($postTypes as $postType) {
400
+
401
+ if ($postType == 'is_home_page') {
402
+ if (is_front_page() && is_home()) {
403
+ // Default homepage
404
+ $isSatisfy = true;
405
+ break;
406
+ } else if ( is_front_page() ) {
407
+ // static homepage
408
+ $isSatisfy = true;
409
+ break;
410
+ }
411
+ }
412
+ else if (function_exists($postType) && $postType()) {
413
+ $isSatisfy = true;
414
+ break;
415
+ }
416
+ }
417
+ }
418
+ else if ($targetData['param'] == 'page_template' && !empty($targetData['value'])) {
419
+ $currentPageTemplate = basename(get_page_template());
420
+ if (in_array($currentPageTemplate, $targetData['value'])) {
421
+ $isSatisfy = true;
422
+ }
423
+ }
424
+ else if ($targetData['param'] == 'post_tags') {
425
+ if (has_tag()) {
426
+ $isSatisfy = true;
427
+ }
428
+ }
429
+ else if ($targetData['param'] == 'post_tags_ids') {
430
+ $tagsObj = wp_get_post_tags($postId);
431
+ $postTagsValues = (array)@$targetData['value'];
432
+ $selectedTags = array_values($postTagsValues);
433
+
434
+ foreach ($tagsObj as $tagObj) {
435
+ if (in_array($tagObj->slug, $selectedTags)) {
436
+ $isSatisfy = true;
437
+ break;
438
+ }
439
+ }
440
+ }
441
+
442
+ if (!$isSatisfy && do_action('isAllowedForTarget', $targetData, $post)) {
443
+ $isSatisfy = true;
444
+ }
445
+
446
+ return $isSatisfy;
447
+ }
448
+
449
+ /**
450
+ * Divide conditions data to Permissive and Forbidden
451
+ *
452
+ * @since 1.0.0
453
+ *
454
+ * @return array $popupTargetData
455
+ *
456
+ */
457
+ private function divideConditionsData()
458
+ {
459
+ $popup = $this->getPopup();
460
+ $conditions = $popup->getConditions();
461
+ $conditions = $this->divideIntoPermissiveAndForbidden($conditions);
462
+
463
+ return $conditions;
464
+ }
465
+ /**
466
+ * Divide target data to Permissive and Forbidden
467
+ *
468
+ * @since 1.0.0
469
+ *
470
+ * @return array $popupTargetData
471
+ *
472
+ */
473
+ public function divideTargetData()
474
+ {
475
+ $popup = $this->getPopup();
476
+ $targetData = $popup->getTarget();
477
+ return $this->divideIntoPermissiveAndForbidden($targetData);
478
+ }
479
+
480
+ /**
481
+ * Divide the Popup target data into Permissive And Forbidden assoc array
482
+ *
483
+ * @since 1.0.0
484
+ *
485
+ * @param array $postMetaData popup saved target data
486
+ *
487
+ * @return array $postMetaDivideData
488
+ *
489
+ */
490
+ public function divideIntoPermissiveAndForbidden($targetData)
491
+ {
492
+ $permissive = array();
493
+ $forbidden = array();
494
+ $permissiveOperators = array('==');
495
+ $forbiddenOperators = array('!=');
496
+ $permissiveOperators = apply_filters('sgpbAdditionalPermissiveOperators', $permissiveOperators);
497
+ $forbiddenOperators = apply_filters('sgpbAdditionalForbiddenOperators', $forbiddenOperators);
498
+ if (!empty($targetData)) {
499
+ foreach ($targetData as $data) {
500
+ if (empty($data['operator']) && $data['param'] != 'everywhere' && !strpos($data['param'], '_all') && $data['param'] != 'post_tags') {
501
+ break;
502
+ }
503
+ // set by default '==' (is) value for all not specific conditions like all pages/posts/other_custom_post_types for future correct detection
504
+ if ($data['param'] == 'everywhere' || strpos($data['param'], '_all') || $data['param'] == 'post_tags') {
505
+ $data['operator'] = '==';
506
+ }
507
+ if ((isset($data['operator']) && in_array($data['operator'], $permissiveOperators))) {
508
+ $permissive[] = $data;
509
+ }
510
+ else if (in_array($data['operator'], $forbiddenOperators)) {
511
+ $forbidden[] = $data;
512
+ }
513
+ }
514
+ }
515
+
516
+ $postMetaDivideData = array(
517
+ 'permissive' => $permissive,
518
+ 'forbidden' => $forbidden
519
+ );
520
+
521
+ return $postMetaDivideData;
522
+ }
523
+
524
+ /**
525
+ * Get custom inserted data
526
+ *
527
+ * @since 1.0.0
528
+ *
529
+ * @return array $insertedData
530
+ */
531
+ public function getCustomInsertedData()
532
+ {
533
+ $post = $this->getPost();
534
+ $insertedData = array();
535
+
536
+ if (isset($post)) {
537
+ $insertedData = SGPopup::getCustomInsertedDataByPostId($this->getPost()->ID);
538
+ }
539
+
540
+ return $insertedData;
541
+ }
542
+
543
+ /**
544
+ * Check Popup conditions
545
+ *
546
+ * @since 1.0.0
547
+ *
548
+ * @return array
549
+ *
550
+ */
551
+ private function isSatisfyForOtherConditions()
552
+ {
553
+ $popup = $this->getPopup();
554
+ $popupOptions = $popup->getOptions();
555
+ $popupId = $popup->getId();
556
+
557
+ $dontAlowOpenPopup = apply_filters('sgpbOtherConditions', array('id' => $popupId, 'popupOptions' => $popupOptions, 'popupObj' => $popup));
558
+
559
+ return $dontAlowOpenPopup['status'];
560
+ }
561
+
562
+ public static function checkUserStatus($savedStatus)
563
+ {
564
+ $equalStatus = true;
565
+
566
+ /*When current user status and saved options does not matched popup must not open*/
567
+ if (is_user_logged_in() != (int)$savedStatus) {
568
+ $equalStatus = false;
569
+ }
570
+
571
+ return $equalStatus;
572
+ }
573
+
574
+ public static function checkLanguage($popupLanguage = '')
575
+ {
576
+ global $post;
577
+
578
+ $postId = $post->ID;
579
+ if (!function_exists('wpml_get_language_information')) {
580
+ return true;
581
+ }
582
+ $postLanguage = wpml_get_language_information($postId);
583
+ if (is_wp_error($postLanguage)) {
584
+ return true;
585
+ }
586
+ if (!empty($_GET['lang']) && ($_GET['lang'] == $popupLanguage)) {
587
+ return true;
588
+ }
589
+ if ($postLanguage['language_code'] != $popupLanguage) {
590
+ return false;
591
+ }
592
+
593
+ return true;
594
+ }
595
+
596
+ public static function checkOtherConditionsActions($args)
597
+ {
598
+ if (empty($args['id']) || empty($args['popupOptions'])) {
599
+ return false;
600
+ }
601
+
602
+ $popupOptions = $args['popupOptions'];
603
+
604
+ if (!empty($popupOptions['sgpb-icl_post_language'])) {
605
+ $languageCompatibilty = PopupChecker::checkLanguage($popupOptions['sgpb-icl_post_language']);
606
+
607
+ if ($languageCompatibilty === false) {
608
+ return $languageCompatibilty;
609
+ }
610
+ }
611
+
612
+
613
+ // proStartSilver
614
+ //User status check
615
+ if (!empty($popupOptions['sgpb-user-status'])) {
616
+ $restrictUserStatus = PopupChecker::checkUserStatus($popupOptions['sgpb-loggedin-user']);
617
+
618
+ if ($restrictUserStatus === false) {
619
+ return $restrictUserStatus;
620
+ }
621
+ }
622
+
623
+ // proEndSilver
624
+
625
+ // proStartPlatinum
626
+ // proEndPlatinum
627
+
628
+ // checking by popup type
629
+ if (!empty($popupOptions['sgpb-type'])) {
630
+ $popupClassName = SGPopup::getPopupClassNameFormType($popupOptions['sgpb-type']);
631
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
632
+
633
+ if (method_exists($popupClassName, 'allowToOpen')) {
634
+ $allowToOpen = $popupClassName::allowToOpen($popupOptions, $args);
635
+ return $allowToOpen;
636
+ }
637
+ }
638
+
639
+ return apply_filters('checkOtherConditions', true);
640
+ }
641
+ }
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,168 +1,168 @@
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' => 100
135
- )
136
- );
137
- // We check all the popups one by one to realize whether they might be loaded or not.
138
- while ($popupBuilderPosts->have_posts()) {
139
- $popupBuilderPosts->next_post();
140
- $popupPost = $popupBuilderPosts->post;
141
- $popup = SGPopup::find($popupPost);
142
- if (empty($popup) || !is_object($popup)) {
143
- continue;
144
- }
145
- if ($popup->allowToLoad() || (is_preview() && get_post_type() == SG_POPUP_POST_TYPE)) {
146
- $this->addLoadablePopup($popup);
147
- }
148
- }
149
-
150
-
151
- $this->doGroupFiltersPopups();
152
- $popups = $this->getLoadablePopups();
153
-
154
- $scriptsLoader = new ScriptsLoader();
155
- $scriptsLoader->setLoadablePopups($popups);
156
- $scriptsLoader->loadToFooter();
157
- }
158
-
159
- private function doGroupFiltersPopups()
160
- {
161
- $popups = $this->getLoadablePopups();
162
- $popups = $this->addPopupFromUrl($popups);
163
- $groupObj = new PopupGroupFilter();
164
- $groupObj->setPopups($popups);
165
- $popups = $groupObj->filter();
166
- $this->setLoadablePopups($popups);
167
- }
168
- }
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' => 100
135
+ )
136
+ );
137
+ // We check all the popups one by one to realize whether they might be loaded or not.
138
+ while ($popupBuilderPosts->have_posts()) {
139
+ $popupBuilderPosts->next_post();
140
+ $popupPost = $popupBuilderPosts->post;
141
+ $popup = SGPopup::find($popupPost);
142
+ if (empty($popup) || !is_object($popup)) {
143
+ continue;
144
+ }
145
+ if ($popup->allowToLoad() || (is_preview() && get_post_type() == SG_POPUP_POST_TYPE)) {
146
+ $this->addLoadablePopup($popup);
147
+ }
148
+ }
149
+
150
+
151
+ $this->doGroupFiltersPopups();
152
+ $popups = $this->getLoadablePopups();
153
+
154
+ $scriptsLoader = new ScriptsLoader();
155
+ $scriptsLoader->setLoadablePopups($popups);
156
+ $scriptsLoader->loadToFooter();
157
+ }
158
+
159
+ private function doGroupFiltersPopups()
160
+ {
161
+ $popups = $this->getLoadablePopups();
162
+ $popups = $this->addPopupFromUrl($popups);
163
+ $groupObj = new PopupGroupFilter();
164
+ $groupObj->setPopups($popups);
165
+ $popups = $groupObj->filter();
166
+ $this->setLoadablePopups($popups);
167
+ }
168
+ }
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,489 +1,489 @@
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 Popups', 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 registerTaxonomy()
110
- {
111
- $labels = array(
112
- 'name' => _x('Categories', 'taxonomy general name', SG_POPUP_TEXT_DOMAIN),
113
- 'singular_name' => _x('Categories', 'taxonomy singular name', SG_POPUP_TEXT_DOMAIN),
114
- 'search_items' => __('Search Categories', SG_POPUP_TEXT_DOMAIN),
115
- 'popular_items' => __('Popular Categories', SG_POPUP_TEXT_DOMAIN),
116
- 'all_items' => __('All Categories', SG_POPUP_TEXT_DOMAIN),
117
- 'parent_item' => null,
118
- 'parent_item_colon' => null,
119
- 'edit_item' => __('Edit Category', SG_POPUP_TEXT_DOMAIN),
120
- 'update_item' => __('Update Category', SG_POPUP_TEXT_DOMAIN),
121
- 'add_new_item' => __('Add New Category', SG_POPUP_TEXT_DOMAIN),
122
- 'new_item_name' => __('New Category Name', SG_POPUP_TEXT_DOMAIN),
123
- 'separate_items_with_commas' => __('Separate Categories with commas', SG_POPUP_TEXT_DOMAIN),
124
- 'add_or_remove_items' => __('Add or remove Categories', SG_POPUP_TEXT_DOMAIN),
125
- 'choose_from_most_used' => __('Choose from the most used Categories', SG_POPUP_TEXT_DOMAIN),
126
- 'not_found' => __('No Categories found.', SG_POPUP_TEXT_DOMAIN),
127
- 'menu_name' => __('Categories', SG_POPUP_TEXT_DOMAIN),
128
- );
129
-
130
- $args = array(
131
- 'hierarchical' => true,
132
- 'labels' => $labels,
133
- 'show_ui' => true,
134
- 'show_admin_column' => true,
135
- 'sort' => 12,
136
- 'update_count_callback' => '_update_post_term_count',
137
- 'query_var' => true,
138
- 'show_in_rest' => true,
139
- 'capabilities' => array(
140
- 'manage_terms' => 'manage_popup_categories_terms',
141
- 'edit_terms' => 'manage_popup_categories_terms',
142
- 'assign_terms' => 'manage_popup_categories_terms',
143
- 'delete_terms' => 'manage_popup_categories_terms'
144
- )
145
- );
146
-
147
- register_taxonomy(SG_POPUP_CATEGORY_TAXONOMY, SG_POPUP_POST_TYPE, $args);
148
- register_taxonomy_for_object_type(SG_POPUP_CATEGORY_TAXONOMY, SG_POPUP_POST_TYPE);
149
- }
150
-
151
- public function postTypeSupportForPopupTypes($supports)
152
- {
153
- $popupType = $this->getPopupTypeName();
154
- $typePath = $this->getPopupTypePathFormPopupType($popupType);
155
- $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
156
-
157
- if (!file_exists($typePath.$popupClassName.'.php')) {
158
- return $supports;
159
- }
160
-
161
- require_once($typePath.$popupClassName.'.php');
162
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
163
-
164
- // We need to remove wyswyg editor for some popup types and that’s why we are doing this check.
165
- if (method_exists($popupClassName, 'getPopupTypeSupports')) {
166
- $supports = $popupClassName::getPopupTypeSupports();
167
- }
168
-
169
- return $supports;
170
- }
171
-
172
- public function init()
173
- {
174
- add_filter('sgpbPostTypeSupport', array($this, 'postTypeSupportForPopupTypes'), 1, 1);
175
- $postType = SG_POPUP_POST_TYPE;
176
- $args = $this->getPostTypeArgs();
177
-
178
- register_post_type($postType, $args);
179
-
180
- $this->createPopupObjFromPopupType();
181
- $this->registerTaxonomy();
182
- }
183
-
184
- private function createPopupObjFromPopupType()
185
- {
186
- $popupId = 0;
187
-
188
- if (!empty($_GET['post'])) {
189
- $popupId = (int)$_GET['post'];
190
- }
191
-
192
- $popupType = $this->getPopupTypeName();
193
- $this->setPopupType($popupType);
194
- $this->setPopupId($popupId);
195
-
196
- $this->createPopupObj();
197
- }
198
-
199
- private function getPopupTypeName()
200
- {
201
- $popupType = 'html';
202
-
203
- /*
204
- * First, we try to find the popup type with the post id then,
205
- * if the post id doesn't exist, we try to find it with $_GET['sgpb_type']
206
- */
207
- if (!empty($_GET['post'])) {
208
- $popupId = $_GET['post'];
209
- $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
210
- if (!empty($popupOptionsData['sgpb-type'])) {
211
- $popupType = $popupOptionsData['sgpb-type'];
212
- }
213
- }
214
- else if (!empty($_GET['sgpb_type'])) {
215
- $popupType = $_GET['sgpb_type'];
216
- }
217
-
218
- return $popupType;
219
- }
220
-
221
- private function getPopupClassNameFromPopupType($popupType)
222
- {
223
- $popupName = ucfirst(strtolower($popupType));
224
- $popupClassName = $popupName.'Popup';
225
-
226
- return $popupClassName;
227
- }
228
-
229
- private function getPopupTypePathFormPopupType($popupType)
230
- {
231
- global $SGPB_POPUP_TYPES;
232
- $typePath = '';
233
-
234
- if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
235
- $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
236
- }
237
-
238
- return $typePath;
239
- }
240
-
241
- public function createPopupObj()
242
- {
243
- $popupId = $this->getPopupId();
244
- $popupType = $this->getPopupType();
245
- $typePath = $this->getPopupTypePathFormPopupType($popupType);
246
- $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
247
-
248
- if (!file_exists($typePath.$popupClassName.'.php')) {
249
- die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
250
- }
251
- require_once($typePath.$popupClassName.'.php');
252
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
253
- $popupTypeObj = new $popupClassName();
254
- $popupTypeObj->setId($popupId);
255
- $popupTypeObj->setType($popupType);
256
- $this->setPopupTypeObj($popupTypeObj);
257
-
258
- $popupTypeMainView = $popupTypeObj->getPopupTypeMainView();
259
- $popupTypeViewData = $popupTypeObj->getPopupTypeOptionsView();
260
-
261
- if (!empty($popupTypeMainView)) {
262
- add_action('add_meta_boxes', array($this, 'popupTypeMain'));
263
- }
264
- if (!empty($popupTypeViewData)) {
265
- add_action('add_meta_boxes', array($this, 'popupTypeOptions'));
266
- }
267
- if ($popupType == 'subscription') {
268
- add_action('add_meta_boxes', array($this, 'rightBannerMetabox'));
269
- }
270
- }
271
-
272
- public function rightBannerMetabox()
273
- {
274
- $banner = AdminHelper::getRightMetaboxBannerText();
275
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
276
- if ($banner == '' || $isSubscriptionPlusActive) {
277
- return;
278
- }
279
- add_meta_box(
280
- 'popupTypeRightBannerView',
281
- __('News', SG_POPUP_TEXT_DOMAIN),
282
- array($this, 'popupTypeRightBannerView'),
283
- SG_POPUP_POST_TYPE,
284
- 'side',
285
- 'low'
286
- );
287
- }
288
-
289
- public function popupTypeMain()
290
- {
291
- $popupTypeObj = $this->getPopupTypeObj();
292
- $optionsView = $popupTypeObj->getPopupTypeMainView();
293
- add_meta_box(
294
- 'popupTypeMainView',
295
- __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
296
- array($this, 'popupTypeMainView'),
297
- SG_POPUP_POST_TYPE,
298
- 'normal',
299
- 'high'
300
- );
301
- }
302
-
303
- public function popupTypeOptions()
304
- {
305
- $popupTypeObj = $this->getPopupTypeObj();
306
- $optionsView = $popupTypeObj->getPopupTypeOptionsView();
307
- add_meta_box(
308
- 'popupTypeOptionsView',
309
- __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
310
- array($this, 'popupTypeOptionsView'),
311
- SG_POPUP_POST_TYPE,
312
- 'normal',
313
- 'high'
314
- );
315
- }
316
-
317
- public function supportLinks()
318
- {
319
- add_submenu_page(
320
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
321
- __('Settings', SG_POPUP_TEXT_DOMAIN),
322
- __('Settings', SG_POPUP_TEXT_DOMAIN),
323
- 'manage_options',
324
- SG_POPUP_SETTINGS_PAGE,
325
- array($this, 'settings')
326
- );
327
-
328
- add_submenu_page(
329
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
330
- __('Extend', SG_POPUP_TEXT_DOMAIN),
331
- __('Extend', SG_POPUP_TEXT_DOMAIN),
332
- 'sgpb_manage_options',
333
- SG_POPUP_EXTEND_PAGE,
334
- array($this, 'extendLink')
335
- );
336
-
337
- add_submenu_page(
338
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
339
- __('Support', SG_POPUP_TEXT_DOMAIN),
340
- __('Support', SG_POPUP_TEXT_DOMAIN),
341
- 'sgpb_manage_options',
342
- SG_POPUP_SUPPORT_PAGE,
343
- array($this, 'supportLink')
344
- );
345
- }
346
-
347
- public function addSubMenu()
348
- {
349
- add_submenu_page(
350
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
351
- __('Add New', SG_POPUP_TEXT_DOMAIN),
352
- __('Add New', SG_POPUP_TEXT_DOMAIN),
353
- 'sgpb_manage_options',
354
- SG_POPUP_POST_TYPE,
355
- array($this, 'popupTypesPage')
356
- );
357
-
358
- add_submenu_page(
359
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
360
- __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
361
- __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
362
- 'sgpb_manage_options',
363
- SG_POPUP_SUBSCRIBERS_PAGE,
364
- array($this, 'subscribersPage')
365
- );
366
-
367
- add_submenu_page(
368
- 'edit.php?post_type='.SG_POPUP_POST_TYPE,
369
- __('Newsletter', SG_POPUP_TEXT_DOMAIN),
370
- __('Newsletter', SG_POPUP_TEXT_DOMAIN),
371
- 'sgpb_manage_options',
372
- SG_POPUP_NEWSLETTER_PAGE,
373
- array($this, 'newsletter')
374
- );
375
- }
376
-
377
- public function supportLink()
378
- {
379
- wp_redirect(SG_POPUP_SUPPORT_URL);
380
- }
381
-
382
- public function extendLink()
383
- {
384
- wp_redirect(SG_POPUP_EXTENSIONS_URL);
385
- }
386
-
387
- public function addOptionsMetaBox()
388
- {
389
- add_meta_box(
390
- 'optionsMetaboxView',
391
- __('Popup Options', SG_POPUP_TEXT_DOMAIN),
392
- array($this, 'optionsMetaboxView'),
393
- SG_POPUP_POST_TYPE,
394
- 'normal',
395
- 'low'
396
- );
397
- }
398
-
399
- public function addPopupMetaboxes()
400
- {
401
- $additionalMetaboxes = apply_filters('sgpbAdditionalMetaboxes', array());
402
-
403
- if (empty($additionalMetaboxes)) {
404
- return false;
405
- }
406
-
407
- foreach ($additionalMetaboxes as $additionalMetabox) {
408
- if (empty($additionalMetabox)) {
409
- continue;
410
- }
411
- $context = 'normal';
412
- $priority = 'low';
413
- $filepath = $additionalMetabox['filePath'];
414
- $popupTypeObj = $this->getPopupTypeObj();
415
-
416
- if (!empty($additionalMetabox['context'])) {
417
- $context = $additionalMetabox['context'];
418
- }
419
- if (!empty($additionalMetabox['priority'])) {
420
- $priority = $additionalMetabox['priority'];
421
- }
422
-
423
- add_meta_box(
424
- $additionalMetabox['key'],
425
- __($additionalMetabox['displayName'], SG_POPUP_TEXT_DOMAIN),
426
- function() use ($filepath, $popupTypeObj) {
427
- require_once $filepath;
428
- },
429
- SG_POPUP_POST_TYPE,
430
- $context,
431
- $priority
432
- );
433
- }
434
-
435
- return true;
436
- }
437
-
438
- public function popupTypesPage()
439
- {
440
- if (file_exists(SG_POPUP_VIEWS_PATH.'popupTypes.php')) {
441
- require_once(SG_POPUP_VIEWS_PATH.'popupTypes.php');
442
- }
443
- }
444
-
445
- public function subscribersPage()
446
- {
447
- if (file_exists(SG_POPUP_VIEWS_PATH.'subscribers.php')) {
448
- require_once(SG_POPUP_VIEWS_PATH . 'subscribers.php');
449
- }
450
- }
451
-
452
- public function settings()
453
- {
454
- if (file_exists(SG_POPUP_VIEWS_PATH.'settings.php')) {
455
- require_once(SG_POPUP_VIEWS_PATH.'settings.php');
456
- }
457
- }
458
-
459
- public function newsletter()
460
- {
461
- if (file_exists(SG_POPUP_VIEWS_PATH.'newsletter.php')) {
462
- require_once(SG_POPUP_VIEWS_PATH.'newsletter.php');
463
- }
464
- }
465
-
466
- public function popupTypeOptionsView()
467
- {
468
- $popupTypeObj = $this->getPopupTypeObj();
469
- $optionsView = $popupTypeObj->getPopupTypeOptionsView();
470
- if (file_exists($optionsView['filePath'])) {
471
- require_once($optionsView['filePath']);
472
- }
473
- }
474
-
475
- public function popupTypeMainView()
476
- {
477
- $popupTypeObj = $this->getPopupTypeObj();
478
- $optionsView = $popupTypeObj->getPopupTypeMainView();
479
- if (file_exists($optionsView['filePath'])) {
480
- require_once($optionsView['filePath']);
481
- }
482
- }
483
-
484
- public function popupTypeRightBannerView()
485
- {
486
- $banner = AdminHelper::getRightMetaboxBannerText();
487
- echo $banner;
488
- }
489
- }
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 Popups', 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 registerTaxonomy()
110
+ {
111
+ $labels = array(
112
+ 'name' => _x('Categories', 'taxonomy general name', SG_POPUP_TEXT_DOMAIN),
113
+ 'singular_name' => _x('Categories', 'taxonomy singular name', SG_POPUP_TEXT_DOMAIN),
114
+ 'search_items' => __('Search Categories', SG_POPUP_TEXT_DOMAIN),
115
+ 'popular_items' => __('Popular Categories', SG_POPUP_TEXT_DOMAIN),
116
+ 'all_items' => __('All Categories', SG_POPUP_TEXT_DOMAIN),
117
+ 'parent_item' => null,
118
+ 'parent_item_colon' => null,
119
+ 'edit_item' => __('Edit Category', SG_POPUP_TEXT_DOMAIN),
120
+ 'update_item' => __('Update Category', SG_POPUP_TEXT_DOMAIN),
121
+ 'add_new_item' => __('Add New Category', SG_POPUP_TEXT_DOMAIN),
122
+ 'new_item_name' => __('New Category Name', SG_POPUP_TEXT_DOMAIN),
123
+ 'separate_items_with_commas' => __('Separate Categories with commas', SG_POPUP_TEXT_DOMAIN),
124
+ 'add_or_remove_items' => __('Add or remove Categories', SG_POPUP_TEXT_DOMAIN),
125
+ 'choose_from_most_used' => __('Choose from the most used Categories', SG_POPUP_TEXT_DOMAIN),
126
+ 'not_found' => __('No Categories found.', SG_POPUP_TEXT_DOMAIN),
127
+ 'menu_name' => __('Categories', SG_POPUP_TEXT_DOMAIN),
128
+ );
129
+
130
+ $args = array(
131
+ 'hierarchical' => true,
132
+ 'labels' => $labels,
133
+ 'show_ui' => true,
134
+ 'show_admin_column' => true,
135
+ 'sort' => 12,
136
+ 'update_count_callback' => '_update_post_term_count',
137
+ 'query_var' => true,
138
+ 'show_in_rest' => true,
139
+ 'capabilities' => array(
140
+ 'manage_terms' => 'manage_popup_categories_terms',
141
+ 'edit_terms' => 'manage_popup_categories_terms',
142
+ 'assign_terms' => 'manage_popup_categories_terms',
143
+ 'delete_terms' => 'manage_popup_categories_terms'
144
+ )
145
+ );
146
+
147
+ register_taxonomy(SG_POPUP_CATEGORY_TAXONOMY, SG_POPUP_POST_TYPE, $args);
148
+ register_taxonomy_for_object_type(SG_POPUP_CATEGORY_TAXONOMY, SG_POPUP_POST_TYPE);
149
+ }
150
+
151
+ public function postTypeSupportForPopupTypes($supports)
152
+ {
153
+ $popupType = $this->getPopupTypeName();
154
+ $typePath = $this->getPopupTypePathFormPopupType($popupType);
155
+ $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
156
+
157
+ if (!file_exists($typePath.$popupClassName.'.php')) {
158
+ return $supports;
159
+ }
160
+
161
+ require_once($typePath.$popupClassName.'.php');
162
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
163
+
164
+ // We need to remove wyswyg editor for some popup types and that’s why we are doing this check.
165
+ if (method_exists($popupClassName, 'getPopupTypeSupports')) {
166
+ $supports = $popupClassName::getPopupTypeSupports();
167
+ }
168
+
169
+ return $supports;
170
+ }
171
+
172
+ public function init()
173
+ {
174
+ add_filter('sgpbPostTypeSupport', array($this, 'postTypeSupportForPopupTypes'), 1, 1);
175
+ $postType = SG_POPUP_POST_TYPE;
176
+ $args = $this->getPostTypeArgs();
177
+
178
+ register_post_type($postType, $args);
179
+
180
+ $this->createPopupObjFromPopupType();
181
+ $this->registerTaxonomy();
182
+ }
183
+
184
+ private function createPopupObjFromPopupType()
185
+ {
186
+ $popupId = 0;
187
+
188
+ if (!empty($_GET['post'])) {
189
+ $popupId = (int)$_GET['post'];
190
+ }
191
+
192
+ $popupType = $this->getPopupTypeName();
193
+ $this->setPopupType($popupType);
194
+ $this->setPopupId($popupId);
195
+
196
+ $this->createPopupObj();
197
+ }
198
+
199
+ private function getPopupTypeName()
200
+ {
201
+ $popupType = 'html';
202
+
203
+ /*
204
+ * First, we try to find the popup type with the post id then,
205
+ * if the post id doesn't exist, we try to find it with $_GET['sgpb_type']
206
+ */
207
+ if (!empty($_GET['post'])) {
208
+ $popupId = $_GET['post'];
209
+ $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
210
+ if (!empty($popupOptionsData['sgpb-type'])) {
211
+ $popupType = $popupOptionsData['sgpb-type'];
212
+ }
213
+ }
214
+ else if (!empty($_GET['sgpb_type'])) {
215
+ $popupType = $_GET['sgpb_type'];
216
+ }
217
+
218
+ return $popupType;
219
+ }
220
+
221
+ private function getPopupClassNameFromPopupType($popupType)
222
+ {
223
+ $popupName = ucfirst(strtolower($popupType));
224
+ $popupClassName = $popupName.'Popup';
225
+
226
+ return $popupClassName;
227
+ }
228
+
229
+ private function getPopupTypePathFormPopupType($popupType)
230
+ {
231
+ global $SGPB_POPUP_TYPES;
232
+ $typePath = '';
233
+
234
+ if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
235
+ $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
236
+ }
237
+
238
+ return $typePath;
239
+ }
240
+
241
+ public function createPopupObj()
242
+ {
243
+ $popupId = $this->getPopupId();
244
+ $popupType = $this->getPopupType();
245
+ $typePath = $this->getPopupTypePathFormPopupType($popupType);
246
+ $popupClassName = $this->getPopupClassNameFromPopupType($popupType);
247
+
248
+ if (!file_exists($typePath.$popupClassName.'.php')) {
249
+ die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
250
+ }
251
+ require_once($typePath.$popupClassName.'.php');
252
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
253
+ $popupTypeObj = new $popupClassName();
254
+ $popupTypeObj->setId($popupId);
255
+ $popupTypeObj->setType($popupType);
256
+ $this->setPopupTypeObj($popupTypeObj);
257
+
258
+ $popupTypeMainView = $popupTypeObj->getPopupTypeMainView();
259
+ $popupTypeViewData = $popupTypeObj->getPopupTypeOptionsView();
260
+
261
+ if (!empty($popupTypeMainView)) {
262
+ add_action('add_meta_boxes', array($this, 'popupTypeMain'));
263
+ }
264
+ if (!empty($popupTypeViewData)) {
265
+ add_action('add_meta_boxes', array($this, 'popupTypeOptions'));
266
+ }
267
+ if ($popupType == 'subscription') {
268
+ add_action('add_meta_boxes', array($this, 'rightBannerMetabox'));
269
+ }
270
+ }
271
+
272
+ public function rightBannerMetabox()
273
+ {
274
+ $banner = AdminHelper::getRightMetaboxBannerText();
275
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
276
+ if ($banner == '' || $isSubscriptionPlusActive) {
277
+ return;
278
+ }
279
+ add_meta_box(
280
+ 'popupTypeRightBannerView',
281
+ __('News', SG_POPUP_TEXT_DOMAIN),
282
+ array($this, 'popupTypeRightBannerView'),
283
+ SG_POPUP_POST_TYPE,
284
+ 'side',
285
+ 'low'
286
+ );
287
+ }
288
+
289
+ public function popupTypeMain()
290
+ {
291
+ $popupTypeObj = $this->getPopupTypeObj();
292
+ $optionsView = $popupTypeObj->getPopupTypeMainView();
293
+ add_meta_box(
294
+ 'popupTypeMainView',
295
+ __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
296
+ array($this, 'popupTypeMainView'),
297
+ SG_POPUP_POST_TYPE,
298
+ 'normal',
299
+ 'high'
300
+ );
301
+ }
302
+
303
+ public function popupTypeOptions()
304
+ {
305
+ $popupTypeObj = $this->getPopupTypeObj();
306
+ $optionsView = $popupTypeObj->getPopupTypeOptionsView();
307
+ add_meta_box(
308
+ 'popupTypeOptionsView',
309
+ __($optionsView['metaboxTitle'], SG_POPUP_TEXT_DOMAIN),
310
+ array($this, 'popupTypeOptionsView'),
311
+ SG_POPUP_POST_TYPE,
312
+ 'normal',
313
+ 'high'
314
+ );
315
+ }
316
+
317
+ public function supportLinks()
318
+ {
319
+ add_submenu_page(
320
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
321
+ __('Settings', SG_POPUP_TEXT_DOMAIN),
322
+ __('Settings', SG_POPUP_TEXT_DOMAIN),
323
+ 'manage_options',
324
+ SG_POPUP_SETTINGS_PAGE,
325
+ array($this, 'settings')
326
+ );
327
+
328
+ add_submenu_page(
329
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
330
+ __('Extend', SG_POPUP_TEXT_DOMAIN),
331
+ __('Extend', SG_POPUP_TEXT_DOMAIN),
332
+ 'sgpb_manage_options',
333
+ SG_POPUP_EXTEND_PAGE,
334
+ array($this, 'extendLink')
335
+ );
336
+
337
+ add_submenu_page(
338
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
339
+ __('Support', SG_POPUP_TEXT_DOMAIN),
340
+ __('Support', SG_POPUP_TEXT_DOMAIN),
341
+ 'sgpb_manage_options',
342
+ SG_POPUP_SUPPORT_PAGE,
343
+ array($this, 'supportLink')
344
+ );
345
+ }
346
+
347
+ public function addSubMenu()
348
+ {
349
+ add_submenu_page(
350
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
351
+ __('Add New', SG_POPUP_TEXT_DOMAIN),
352
+ __('Add New', SG_POPUP_TEXT_DOMAIN),
353
+ 'sgpb_manage_options',
354
+ SG_POPUP_POST_TYPE,
355
+ array($this, 'popupTypesPage')
356
+ );
357
+
358
+ add_submenu_page(
359
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
360
+ __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
361
+ __('All Subscribers', SG_POPUP_TEXT_DOMAIN),
362
+ 'sgpb_manage_options',
363
+ SG_POPUP_SUBSCRIBERS_PAGE,
364
+ array($this, 'subscribersPage')
365
+ );
366
+
367
+ add_submenu_page(
368
+ 'edit.php?post_type='.SG_POPUP_POST_TYPE,
369
+ __('Newsletter', SG_POPUP_TEXT_DOMAIN),
370
+ __('Newsletter', SG_POPUP_TEXT_DOMAIN),
371
+ 'sgpb_manage_options',
372
+ SG_POPUP_NEWSLETTER_PAGE,
373
+ array($this, 'newsletter')
374
+ );
375
+ }
376
+
377
+ public function supportLink()
378
+ {
379
+ wp_redirect(SG_POPUP_SUPPORT_URL);
380
+ }
381
+
382
+ public function extendLink()
383
+ {
384
+ wp_redirect(SG_POPUP_EXTENSIONS_URL);
385
+ }
386
+
387
+ public function addOptionsMetaBox()
388
+ {
389
+ add_meta_box(
390
+ 'optionsMetaboxView',
391
+ __('Popup Options', SG_POPUP_TEXT_DOMAIN),
392
+ array($this, 'optionsMetaboxView'),
393
+ SG_POPUP_POST_TYPE,
394
+ 'normal',
395
+ 'low'
396
+ );
397
+ }
398
+
399
+ public function addPopupMetaboxes()
400
+ {
401
+ $additionalMetaboxes = apply_filters('sgpbAdditionalMetaboxes', array());
402
+
403
+ if (empty($additionalMetaboxes)) {
404
+ return false;
405
+ }
406
+
407
+ foreach ($additionalMetaboxes as $additionalMetabox) {
408
+ if (empty($additionalMetabox)) {
409
+ continue;
410
+ }
411
+ $context = 'normal';
412
+ $priority = 'low';
413
+ $filepath = $additionalMetabox['filePath'];
414
+ $popupTypeObj = $this->getPopupTypeObj();
415
+
416
+ if (!empty($additionalMetabox['context'])) {
417
+ $context = $additionalMetabox['context'];
418
+ }
419
+ if (!empty($additionalMetabox['priority'])) {
420
+ $priority = $additionalMetabox['priority'];
421
+ }
422
+
423
+ add_meta_box(
424
+ $additionalMetabox['key'],
425
+ __($additionalMetabox['displayName'], SG_POPUP_TEXT_DOMAIN),
426
+ function() use ($filepath, $popupTypeObj) {
427
+ require_once $filepath;
428
+ },
429
+ SG_POPUP_POST_TYPE,
430
+ $context,
431
+ $priority
432
+ );
433
+ }
434
+
435
+ return true;
436
+ }
437
+
438
+ public function popupTypesPage()
439
+ {
440
+ if (file_exists(SG_POPUP_VIEWS_PATH.'popupTypes.php')) {
441
+ require_once(SG_POPUP_VIEWS_PATH.'popupTypes.php');
442
+ }
443
+ }
444
+
445
+ public function subscribersPage()
446
+ {
447
+ if (file_exists(SG_POPUP_VIEWS_PATH.'subscribers.php')) {
448
+ require_once(SG_POPUP_VIEWS_PATH . 'subscribers.php');
449
+ }
450
+ }
451
+
452
+ public function settings()
453
+ {
454
+ if (file_exists(SG_POPUP_VIEWS_PATH.'settings.php')) {
455
+ require_once(SG_POPUP_VIEWS_PATH.'settings.php');
456
+ }
457
+ }
458
+
459
+ public function newsletter()
460
+ {
461
+ if (file_exists(SG_POPUP_VIEWS_PATH.'newsletter.php')) {
462
+ require_once(SG_POPUP_VIEWS_PATH.'newsletter.php');
463
+ }
464
+ }
465
+
466
+ public function popupTypeOptionsView()
467
+ {
468
+ $popupTypeObj = $this->getPopupTypeObj();
469
+ $optionsView = $popupTypeObj->getPopupTypeOptionsView();
470
+ if (file_exists($optionsView['filePath'])) {
471
+ require_once($optionsView['filePath']);
472
+ }
473
+ }
474
+
475
+ public function popupTypeMainView()
476
+ {
477
+ $popupTypeObj = $this->getPopupTypeObj();
478
+ $optionsView = $popupTypeObj->getPopupTypeMainView();
479
+ if (file_exists($optionsView['filePath'])) {
480
+ require_once($optionsView['filePath']);
481
+ }
482
+ }
483
+
484
+ public function popupTypeRightBannerView()
485
+ {
486
+ $banner = AdminHelper::getRightMetaboxBannerText();
487
+ echo $banner;
488
+ }
489
+ }
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,344 +1,344 @@
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 static $alreadyLoadedPopups = array();
12
-
13
- public function setLoadablePopups($loadablePopups)
14
- {
15
- $this->loadablePopups = $loadablePopups;
16
- }
17
-
18
- public function getLoadablePopups()
19
- {
20
- return apply_filters('sgpbLoadablePopups', $this->loadablePopups);
21
- }
22
-
23
- public function setIsAdmin($isAdmin)
24
- {
25
- $this->isAdmin = $isAdmin;
26
- }
27
-
28
- public function getIsAdmin()
29
- {
30
- return $this->isAdmin;
31
- }
32
-
33
- /**
34
- * Get encoded popup options
35
- *
36
- * @since 3.0.4
37
- *
38
- * @param object $popup
39
- *
40
- * @return array|mixed|string|void $popupOptions
41
- */
42
- private function getEncodedOptionsFromPopup($popup)
43
- {
44
- $extraOptions = $popup->getExtraRenderOptions();
45
- $popupOptions = $popup->getOptions();
46
- $popupOptions = apply_filters('sgpbPopupRenderOptions', $popupOptions);
47
- $popupCondition = $popup->getConditions();
48
-
49
- $popupOptions = array_merge($popupOptions, $extraOptions);
50
- $popupOptions['sgpbConditions'] = apply_filters('sgpbRenderCondtions', $popupCondition);
51
- // These two lines have been added in order to not use the json_econde and to support PHP 5.3 version.
52
- $popupOptions = AdminHelper::serializeData($popupOptions);
53
- $popupOptions = base64_encode($popupOptions);
54
-
55
- return $popupOptions;
56
- }
57
-
58
- // load popup scripts and styles and add popup data to the footer
59
- public function loadToFooter()
60
- {
61
- $alreadyLoadedPopups = array();
62
- $popups = $this->getLoadablePopups();
63
- $currentPostType = AdminHelper::getCurrentPostType();
64
- $postId = 0;
65
- global $wp;
66
- $currentUrl = home_url( $wp->request );
67
- $currentUrl = strpos($currentUrl, '/popupbuilder/');
68
- if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
69
- return false;
70
- }
71
-
72
- if (empty($popups)) {
73
- return false;
74
- }
75
-
76
- global $post;
77
- $postId = 0;
78
-
79
- if (!empty($post)) {
80
- $postId = $post->ID;
81
- }
82
-
83
- if ($this->getIsAdmin()) {
84
- $this->loadToAdmin();
85
- return true;
86
- }
87
-
88
- foreach ($popups as $popup) {
89
- $popupId = $popup->getId();
90
-
91
- $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
92
-
93
- $events = $popup->getPopupAllEvents($postId, $popupId, $popup);
94
-
95
- // if popup's data has already loaded into the page with the same event
96
- if (isset(self::$alreadyLoadedPopups[$popupId])) {
97
- if (self::$alreadyLoadedPopups[$popupId] == $events) {
98
- continue;
99
- }
100
- }
101
- foreach ($events as $event) {
102
- if (isset($event['param'])) {
103
- if (isset(self::$alreadyLoadedPopups[$popupId])) {
104
- if (self::$alreadyLoadedPopups[$popupId] == $event['param']) {
105
- continue;
106
- }
107
- }
108
- }
109
- }
110
-
111
- self::$alreadyLoadedPopups[$popupId] = $events;
112
- $events = json_encode($events);
113
- $currentUseOptions = $popup->getOptions();
114
- $extraContent = apply_filters('sgpbPopupExtraData', $popupId, $currentUseOptions);
115
-
116
- $popupOptions = $this->getEncodedOptionsFromPopup($popup);
117
- $popupOptions = apply_filters('sgpbLoadToFooterOptions', $popupOptions);
118
- add_action('wp_footer', function() use ($popupId, $events, $popupOptions, $popupContent, $extraContent) {
119
- $footerPopupContent = '<div class="sgpb-main-popup-data-container-'.$popupId.'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
120
- <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).'">
121
- <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
122
- </div>
123
- </div>';
124
- $footerPopupContent .= $extraContent;
125
- echo $footerPopupContent;
126
- });
127
- }
128
-
129
- $this->includeScripts();
130
- $this->includeStyles();
131
- }
132
-
133
- public function loadToAdmin()
134
- {
135
- $popups = $this->getLoadablePopups();
136
-
137
- foreach ($popups as $popup) {
138
- $popupId = $popup->getId();
139
-
140
- $events = array();
141
-
142
- $events = json_encode($events);
143
-
144
- $popupOptions = $this->getEncodedOptionsFromPopup($popup);
145
-
146
- $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
147
-
148
- add_action('admin_footer', function() use ($popupId, $events, $popupOptions, $popupContent) {
149
- $footerPopupContent = '<div style="position:absolute;top: -999999999999999999999px;">
150
- <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).'">
151
- <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
152
- </div>
153
- </div>';
154
-
155
- echo $footerPopupContent;
156
- });
157
- }
158
- $this->includeScripts();
159
- $this->includeStyles();
160
-
161
- }
162
-
163
- private function includeScripts()
164
- {
165
- global $post;
166
- $popups = $this->getLoadablePopups();
167
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
168
-
169
- if (!$registeredPlugins) {
170
- return;
171
- }
172
- $registeredPlugins = json_decode($registeredPlugins, true);
173
-
174
- if (empty($registeredPlugins)) {
175
- return;
176
- }
177
-
178
- foreach ($registeredPlugins as $pluginName => $pluginData) {
179
-
180
- if (!is_plugin_active($pluginName)) {
181
- continue;
182
- }
183
-
184
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
185
- continue;
186
- }
187
- $classPath = $pluginData['classPath'];
188
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
189
-
190
- if (!file_exists($classPath)) {
191
- continue;
192
- }
193
-
194
- require_once($classPath);
195
-
196
- $classObj = new $pluginData['className']();
197
-
198
- if (!$classObj instanceof \SgpbIPopupExtension) {
199
- continue;
200
- }
201
-
202
- $scriptData = $classObj->getFrontendScripts(
203
- $post, array(
204
- 'popups' => $popups
205
- )
206
- );
207
-
208
- $scripts[] = $scriptData;
209
- }
210
-
211
- if (empty($scripts)) {
212
- return;
213
- }
214
-
215
- foreach ($scripts as $script) {
216
- if (empty($script['jsFiles'])) {
217
- continue;
218
- }
219
-
220
- foreach ($script['jsFiles'] as $jsFile) {
221
-
222
- if (empty($jsFile['folderUrl'])) {
223
- wp_enqueue_script(@$jsFile['filename']);
224
- continue;
225
- }
226
-
227
- $dirUrl = $jsFile['folderUrl'];
228
- $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
229
- $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
230
- $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
231
-
232
- ScriptsIncluder::registerScript($jsFile['filename'], array(
233
- 'dirUrl' => $dirUrl,
234
- 'dep' => $dep,
235
- 'ver' => $ver,
236
- 'inFooter' => $inFooter
237
- )
238
- );
239
- ScriptsIncluder::enqueueScript($jsFile['filename']);
240
- }
241
-
242
- if (empty($script['localizeData'])) {
243
- continue;
244
- }
245
-
246
- $localizeData = $script['localizeData'];
247
-
248
- if (!empty($localizeData[0])) {
249
- foreach ($localizeData as $valueData) {
250
- if (empty($valueData)) {
251
- continue;
252
-
253
- }
254
-
255
- ScriptsIncluder::localizeScript($valueData['handle'], $valueData['name'], $valueData['data']);
256
- }
257
- }
258
- }
259
- }
260
-
261
- private function includeStyles()
262
- {
263
- global $post;
264
- $styles = array();
265
- $popups = $this->getLoadablePopups();
266
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
267
-
268
- if (!$registeredPlugins) {
269
- return;
270
- }
271
- $registeredPlugins = json_decode($registeredPlugins, true);
272
-
273
- if (empty($registeredPlugins)) {
274
- return;
275
- }
276
-
277
- foreach ($registeredPlugins as $pluginName => $pluginData) {
278
-
279
- if (!is_plugin_active($pluginName)) {
280
- continue;
281
- }
282
-
283
- if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
284
- continue;
285
- }
286
-
287
- $classPath = $pluginData['classPath'];
288
- $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
289
-
290
- if (!file_exists($classPath)) {
291
- continue;
292
- }
293
-
294
- require_once($classPath);
295
-
296
- $classObj = new $pluginData['className']();
297
-
298
- if (!$classObj instanceof \SgpbIPopupExtension) {
299
- continue;
300
- }
301
-
302
- $scriptData = $classObj->getFrontendStyles(
303
- $post , array(
304
- 'popups' => $popups
305
- )
306
- );
307
-
308
- $styles[] = $scriptData;
309
- }
310
-
311
- if (empty($styles)) {
312
- return;
313
- }
314
-
315
- foreach ($styles as $style) {
316
-
317
- if (empty($style['cssFiles'])) {
318
- continue;
319
- }
320
-
321
- foreach ($style['cssFiles'] as $cssFile) {
322
-
323
- if (empty($cssFile['folderUrl'])) {
324
- ScriptsIncluder::enqueueStyle($cssFile['filename']);
325
- continue;
326
- }
327
-
328
- $dirUrl = $cssFile['folderUrl'];
329
- $dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
330
- $ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
331
- $inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';
332
-
333
- ScriptsIncluder::registerStyle($cssFile['filename'], array(
334
- 'dirUrl' => $dirUrl,
335
- 'dep' => $dep,
336
- 'ver' => $ver,
337
- 'inFooter' => $inFooter
338
- )
339
- );
340
- ScriptsIncluder::enqueueStyle($cssFile['filename']);
341
- }
342
- }
343
- }
344
- }
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 static $alreadyLoadedPopups = array();
12
+
13
+ public function setLoadablePopups($loadablePopups)
14
+ {
15
+ $this->loadablePopups = $loadablePopups;
16
+ }
17
+
18
+ public function getLoadablePopups()
19
+ {
20
+ return apply_filters('sgpbLoadablePopups', $this->loadablePopups);
21
+ }
22
+
23
+ public function setIsAdmin($isAdmin)
24
+ {
25
+ $this->isAdmin = $isAdmin;
26
+ }
27
+
28
+ public function getIsAdmin()
29
+ {
30
+ return $this->isAdmin;
31
+ }
32
+
33
+ /**
34
+ * Get encoded popup options
35
+ *
36
+ * @since 3.0.4
37
+ *
38
+ * @param object $popup
39
+ *
40
+ * @return array|mixed|string|void $popupOptions
41
+ */
42
+ private function getEncodedOptionsFromPopup($popup)
43
+ {
44
+ $extraOptions = $popup->getExtraRenderOptions();
45
+ $popupOptions = $popup->getOptions();
46
+ $popupOptions = apply_filters('sgpbPopupRenderOptions', $popupOptions);
47
+ $popupCondition = $popup->getConditions();
48
+
49
+ $popupOptions = array_merge($popupOptions, $extraOptions);
50
+ $popupOptions['sgpbConditions'] = apply_filters('sgpbRenderCondtions', $popupCondition);
51
+ // These two lines have been added in order to not use the json_econde and to support PHP 5.3 version.
52
+ $popupOptions = AdminHelper::serializeData($popupOptions);
53
+ $popupOptions = base64_encode($popupOptions);
54
+
55
+ return $popupOptions;
56
+ }
57
+
58
+ // load popup scripts and styles and add popup data to the footer
59
+ public function loadToFooter()
60
+ {
61
+ $alreadyLoadedPopups = array();
62
+ $popups = $this->getLoadablePopups();
63
+ $currentPostType = AdminHelper::getCurrentPostType();
64
+ $postId = 0;
65
+ global $wp;
66
+ $currentUrl = home_url( $wp->request );
67
+ $currentUrl = strpos($currentUrl, '/popupbuilder/');
68
+ if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
69
+ return false;
70
+ }
71
+
72
+ if (empty($popups)) {
73
+ return false;
74
+ }
75
+
76
+ global $post;
77
+ $postId = 0;
78
+
79
+ if (!empty($post)) {
80
+ $postId = $post->ID;
81
+ }
82
+
83
+ if ($this->getIsAdmin()) {
84
+ $this->loadToAdmin();
85
+ return true;
86
+ }
87
+
88
+ foreach ($popups as $popup) {
89
+ $popupId = $popup->getId();
90
+
91
+ $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
92
+
93
+ $events = $popup->getPopupAllEvents($postId, $popupId, $popup);
94
+
95
+ // if popup's data has already loaded into the page with the same event
96
+ if (isset(self::$alreadyLoadedPopups[$popupId])) {
97
+ if (self::$alreadyLoadedPopups[$popupId] == $events) {
98
+ continue;
99
+ }
100
+ }
101
+ foreach ($events as $event) {
102
+ if (isset($event['param'])) {
103
+ if (isset(self::$alreadyLoadedPopups[$popupId])) {
104
+ if (self::$alreadyLoadedPopups[$popupId] == $event['param']) {
105
+ continue;
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ self::$alreadyLoadedPopups[$popupId] = $events;
112
+ $events = json_encode($events);
113
+ $currentUseOptions = $popup->getOptions();
114
+ $extraContent = apply_filters('sgpbPopupExtraData', $popupId, $currentUseOptions);
115
+
116
+ $popupOptions = $this->getEncodedOptionsFromPopup($popup);
117
+ $popupOptions = apply_filters('sgpbLoadToFooterOptions', $popupOptions);
118
+ add_action('wp_footer', function() use ($popupId, $events, $popupOptions, $popupContent, $extraContent) {
119
+ $footerPopupContent = '<div class="sgpb-main-popup-data-container-'.$popupId.'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
120
+ <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).'">
121
+ <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
122
+ </div>
123
+ </div>';
124
+ $footerPopupContent .= $extraContent;
125
+ echo $footerPopupContent;
126
+ });
127
+ }
128
+
129
+ $this->includeScripts();
130
+ $this->includeStyles();
131
+ }
132
+
133
+ public function loadToAdmin()
134
+ {
135
+ $popups = $this->getLoadablePopups();
136
+
137
+ foreach ($popups as $popup) {
138
+ $popupId = $popup->getId();
139
+
140
+ $events = array();
141
+
142
+ $events = json_encode($events);
143
+
144
+ $popupOptions = $this->getEncodedOptionsFromPopup($popup);
145
+
146
+ $popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
147
+
148
+ add_action('admin_footer', function() use ($popupId, $events, $popupOptions, $popupContent) {
149
+ $footerPopupContent = '<div style="position:absolute;top: -999999999999999999999px;">
150
+ <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).'">
151
+ <div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
152
+ </div>
153
+ </div>';
154
+
155
+ echo $footerPopupContent;
156
+ });
157
+ }
158
+ $this->includeScripts();
159
+ $this->includeStyles();
160
+
161
+ }
162
+
163
+ private function includeScripts()
164
+ {
165
+ global $post;
166
+ $popups = $this->getLoadablePopups();
167
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
168
+
169
+ if (!$registeredPlugins) {
170
+ return;
171
+ }
172
+ $registeredPlugins = json_decode($registeredPlugins, true);
173
+
174
+ if (empty($registeredPlugins)) {
175
+ return;
176
+ }
177
+
178
+ foreach ($registeredPlugins as $pluginName => $pluginData) {
179
+
180
+ if (!is_plugin_active($pluginName)) {
181
+ continue;
182
+ }
183
+
184
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
185
+ continue;
186
+ }
187
+ $classPath = $pluginData['classPath'];
188
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
189
+
190
+ if (!file_exists($classPath)) {
191
+ continue;
192
+ }
193
+
194
+ require_once($classPath);
195
+
196
+ $classObj = new $pluginData['className']();
197
+
198
+ if (!$classObj instanceof \SgpbIPopupExtension) {
199
+ continue;
200
+ }
201
+
202
+ $scriptData = $classObj->getFrontendScripts(
203
+ $post, array(
204
+ 'popups' => $popups
205
+ )
206
+ );
207
+
208
+ $scripts[] = $scriptData;
209
+ }
210
+
211
+ if (empty($scripts)) {
212
+ return;
213
+ }
214
+
215
+ foreach ($scripts as $script) {
216
+ if (empty($script['jsFiles'])) {
217
+ continue;
218
+ }
219
+
220
+ foreach ($script['jsFiles'] as $jsFile) {
221
+
222
+ if (empty($jsFile['folderUrl'])) {
223
+ wp_enqueue_script(@$jsFile['filename']);
224
+ continue;
225
+ }
226
+
227
+ $dirUrl = $jsFile['folderUrl'];
228
+ $dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
229
+ $ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
230
+ $inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
231
+
232
+ ScriptsIncluder::registerScript($jsFile['filename'], array(
233
+ 'dirUrl' => $dirUrl,
234
+ 'dep' => $dep,
235
+ 'ver' => $ver,
236
+ 'inFooter' => $inFooter
237
+ )
238
+ );
239
+ ScriptsIncluder::enqueueScript($jsFile['filename']);
240
+ }
241
+
242
+ if (empty($script['localizeData'])) {
243
+ continue;
244
+ }
245
+
246
+ $localizeData = $script['localizeData'];
247
+
248
+ if (!empty($localizeData[0])) {
249
+ foreach ($localizeData as $valueData) {
250
+ if (empty($valueData)) {
251
+ continue;
252
+
253
+ }
254
+
255
+ ScriptsIncluder::localizeScript($valueData['handle'], $valueData['name'], $valueData['data']);
256
+ }
257
+ }
258
+ }
259
+ }
260
+
261
+ private function includeStyles()
262
+ {
263
+ global $post;
264
+ $styles = array();
265
+ $popups = $this->getLoadablePopups();
266
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
267
+
268
+ if (!$registeredPlugins) {
269
+ return;
270
+ }
271
+ $registeredPlugins = json_decode($registeredPlugins, true);
272
+
273
+ if (empty($registeredPlugins)) {
274
+ return;
275
+ }
276
+
277
+ foreach ($registeredPlugins as $pluginName => $pluginData) {
278
+
279
+ if (!is_plugin_active($pluginName)) {
280
+ continue;
281
+ }
282
+
283
+ if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
284
+ continue;
285
+ }
286
+
287
+ $classPath = $pluginData['classPath'];
288
+ $classPath = SG_POPUP_PLUGIN_PATH.$classPath;
289
+
290
+ if (!file_exists($classPath)) {
291
+ continue;
292
+ }
293
+
294
+ require_once($classPath);
295
+
296
+ $classObj = new $pluginData['className']();
297
+
298
+ if (!$classObj instanceof \SgpbIPopupExtension) {
299
+ continue;
300
+ }
301
+
302
+ $scriptData = $classObj->getFrontendStyles(
303
+ $post , array(
304
+ 'popups' => $popups
305
+ )
306
+ );
307
+
308
+ $styles[] = $scriptData;
309
+ }
310
+
311
+ if (empty($styles)) {
312
+ return;
313
+ }
314
+
315
+ foreach ($styles as $style) {
316
+
317
+ if (empty($style['cssFiles'])) {
318
+ continue;
319
+ }
320
+
321
+ foreach ($style['cssFiles'] as $cssFile) {
322
+
323
+ if (empty($cssFile['folderUrl'])) {
324
+ ScriptsIncluder::enqueueStyle($cssFile['filename']);
325
+ continue;
326
+ }
327
+
328
+ $dirUrl = $cssFile['folderUrl'];
329
+ $dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
330
+ $ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
331
+ $inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';
332
+
333
+ ScriptsIncluder::registerStyle($cssFile['filename'], array(
334
+ 'dirUrl' => $dirUrl,
335
+ 'dep' => $dep,
336
+ 'ver' => $ver,
337
+ 'inFooter' => $inFooter
338
+ )
339
+ );
340
+ ScriptsIncluder::enqueueStyle($cssFile['filename']);
341
+ }
342
+ }
343
+ }
344
+ }
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,258 +1,258 @@
1
- <?php
2
- namespace sgpb;
3
-
4
- if (!class_exists('sgpb\EDD_SL_Plugin_Updater')) {
5
- // load our custom updater if it doesn't already exist
6
- require_once(SG_POPUP_LIBS_PATH .'EDD_SL_Plugin_Updater.php');
7
- }
8
-
9
- class Updates
10
- {
11
- private $licenses = array();
12
-
13
- public function setLicenses($licenses)
14
- {
15
- $this->licenses = $licenses;
16
- }
17
-
18
- public function getLicenses()
19
- {
20
- return $this->licenses;
21
- }
22
-
23
- public function __construct()
24
- {
25
- $this->init();
26
- }
27
-
28
- public function setRegisterdExtensionsLicenses()
29
- {
30
- $registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
31
- $registered = json_decode($registered, true);
32
-
33
- if (empty($registered)) {
34
- return false;
35
- }
36
- $licenses = array();
37
- foreach ($registered as $register) {
38
-
39
- if (empty($register['options']['licence'])) {
40
- continue;
41
- }
42
-
43
- $licenses[] = $register['options']['licence'];
44
- }
45
-
46
- $this->setLicenses($licenses);
47
-
48
- return true;
49
- }
50
-
51
- private function init()
52
- {
53
- $this->setRegisterdExtensionsLicenses();
54
- $licenses = $this->getLicenses();
55
-
56
- if (empty($licenses)) {
57
- return false;
58
- }
59
- add_action('admin_menu', array($this, 'menu'), 22);
60
- add_action('admin_init', array($this, 'sgpbActivateLicense'));
61
- add_action('admin_notices', array($this, 'sgpbAdminNotices'));
62
-
63
- $licenses = $this->getLicenses();
64
-
65
- foreach ($licenses as $license) {
66
- $key = @$license['key'];
67
- $storeURL = @$license['storeURL'];
68
- $pluginMainFilePath = @$license['file'];
69
- $pluginMainFilePath = SG_POPUP_PLUGIN_PATH.$pluginMainFilePath;
70
-
71
- $licenseKey = trim(get_option('sgpb-license-key-'.$key));
72
- $status = get_option('sgpb-license-status-'.$key);
73
-
74
- if ($status == false || $status != 'valid') {
75
- continue;
76
- }
77
-
78
- $version = @constant('SG_VERSION_'.$key);
79
-
80
- // If the version of the extension is not found, update will not possibly be shown
81
- if(empty($version)) {
82
- continue;
83
- }
84
- $sgpbUpdater = new EDD_SL_Plugin_Updater($storeURL, $pluginMainFilePath, array(
85
- 'version' => $version, // current version number
86
- 'license' => $licenseKey, // license key (used get_option above to retrieve from DB)
87
- 'item_id' => $license['itemId'], // id of this plugin
88
- 'author' => $license['autor'], // author of this plugin
89
- 'beta' => false // set to true if you wish customers to receive update notifications of beta releases
90
- ));
91
- }
92
-
93
- return true;
94
- }
95
-
96
- public function menu()
97
- {
98
- 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'));
99
- }
100
-
101
- public function sanitizeLicense($new)
102
- {
103
- $old = get_option('sgpb-license-key-'.$this->licenseKey);
104
-
105
- if ($old && $old != $new) {
106
- delete_option('sgpb-license-status-'.$this->licenseKey); // new license has been entered, so must reactivate
107
- }
108
- update_option('sgpb-license-key-'.$this->licenseKey, $new);
109
-
110
- return $new;
111
- }
112
-
113
- public function pluginLicense()
114
- {
115
- require_once(SG_POPUP_VIEWS_PATH.'license.php');
116
- }
117
-
118
- public function sgpbActivateLicense()
119
- {
120
- $licenses = $this->getLicenses();
121
-
122
- foreach ($licenses as $license) {
123
- $key = @$license['key'];
124
- $itemId = @$license['itemId'];
125
- $itemName = @$license['itemName'];
126
- $storeURL = @$license['storeURL'];
127
- $this->licenseKey = $key;
128
-
129
- if (isset($_POST['sgpb-license-key-'.$key])) {
130
- $this->sanitizeLicense($_POST['sgpb-license-key-'.$key]);
131
- }
132
-
133
- // listen for our activate button to be clicked
134
- if (isset($_POST['sgpb-license-activate-'.$key])) {
135
- // run a quick security check
136
- if (!check_admin_referer('sgpb_nonce', 'sgpb_nonce')) {
137
- return; // get out if we didn't click the Activate button
138
- }
139
- // retrieve the license from the database
140
- $license = trim(get_option('sgpb-license-key-'.$key));
141
- // data to send in our API request
142
- $apiParams = array(
143
- 'edd_action' => 'activate_license',
144
- 'license' => $license,
145
- 'item_id' => $itemId, // The ID of the item in EDD
146
- 'url' => home_url()
147
- );
148
- // Call the custom API.
149
- $response = wp_remote_post($storeURL, array('timeout' => 15, 'sslverify' => false, 'body' => $apiParams));
150
- // make sure the response came back okay
151
- if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
152
- $errorMessage = $response->get_error_message();
153
- $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
154
- }
155
- else {
156
- $licenseData = json_decode(wp_remote_retrieve_body($response));
157
- if (false === $licenseData->success) {
158
- switch ($licenseData->error) {
159
- case 'expired' :
160
- $message = sprintf(
161
- __('Your license key expired on %s.', SG_POPUP_TEXT_DOMAIN),
162
- date_i18n(get_option('date_format'), strtotime($licenseData->expires, current_time('timestamp')))
163
- );
164
- break;
165
- case 'revoked' :
166
- $message = __('Your license key has been disabled.', SG_POPUP_TEXT_DOMAIN);
167
- break;
168
- case 'missing' :
169
- $message = __('Invalid license.', SG_POPUP_TEXT_DOMAIN);
170
- break;
171
- case 'invalid' :
172
- case 'site_inactive' :
173
- $message = __('Your license is not active for this URL.',SG_POPUP_TEXT_DOMAIN);
174
- break;
175
- case 'item_name_mismatch' :
176
- $message = sprintf(__('This appears to be an invalid license key for %s.', SG_POPUP_TEXT_DOMAIN), $itemName);
177
- break;
178
- case 'no_activations_left' :
179
- $message = __('You\'ve already used the permitted number of this license key!', SG_POPUP_TEXT_DOMAIN);
180
- break;
181
- default :
182
- $message = __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
183
- break;
184
- }
185
- }
186
- }
187
- // Check if anything passed on a message constituting a failure
188
- if (!empty($message)) {
189
- $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
190
- $redirect = add_query_arg(array('sl_activation' => 'false', 'message' => urlencode($message)), $baseUrl);
191
- wp_redirect($redirect);
192
- exit();
193
- }
194
- // $licenseData->license will be either "valid" or "invalid"
195
- update_option('sgpb-license-status-'.$key, $licenseData->license);
196
- $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
197
- // all available extensions have active license status
198
- if (empty($hasInactiveExtensions)) {
199
- // and if we don't have inactive extensions, remove option, until new one activation
200
- delete_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
201
- }
202
- wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
203
- exit();
204
- }
205
-
206
- if (isset($_POST['sgpb-license-deactivate'.$key])) {
207
- $license = trim(get_option('sgpb-license-key-'.$key));
208
- // data to send in our API request
209
- $apiParams = array(
210
- 'edd_action' => 'deactivate_license',
211
- 'license' => $license,
212
- 'item_id' => $itemId, // The ID of the item in EDD
213
- 'url' => home_url()
214
- );
215
- $home = home_url();
216
- // Send the remote request
217
- $response = wp_remote_post($storeURL, array('body' => $apiParams, 'timeout' => 15, 'sslverify' => false));
218
- if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
219
- $errorMessage = $response->get_error_message();
220
- $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
221
- $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
222
- $redirect = add_query_arg(array('message' => urlencode($message)), $baseUrl);
223
- wp_redirect($redirect);
224
- exit();
225
- }
226
- else {
227
- $status = false;
228
- $licenseData = json_decode(wp_remote_retrieve_body($response));
229
- if (isset($licenseData->success)) {
230
- $status = $licenseData->success;
231
- }
232
- update_option('sgpb-license-status-'.$key, $status);
233
- update_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
234
- wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
235
- exit();
236
- }
237
- }
238
- }
239
- }
240
-
241
- public function sgpbAdminNotices()
242
- {
243
- if (isset($_GET['sl_activation']) && !empty($_GET['message'])) {
244
- switch ($_GET['sl_activation']) {
245
- case 'false':
246
- $message = urldecode($_GET['message']);
247
- ?>
248
- <div class="error">
249
- <h3><?php echo $message; ?></h3>
250
- </div>
251
- <?php
252
- break;
253
- case 'true':
254
- break;
255
- }
256
- }
257
- }
258
- }
1
+ <?php
2
+ namespace sgpb;
3
+
4
+ if (!class_exists('sgpb\EDD_SL_Plugin_Updater')) {
5
+ // load our custom updater if it doesn't already exist
6
+ require_once(SG_POPUP_LIBS_PATH .'EDD_SL_Plugin_Updater.php');
7
+ }
8
+
9
+ class Updates
10
+ {
11
+ private $licenses = array();
12
+
13
+ public function setLicenses($licenses)
14
+ {
15
+ $this->licenses = $licenses;
16
+ }
17
+
18
+ public function getLicenses()
19
+ {
20
+ return $this->licenses;
21
+ }
22
+
23
+ public function __construct()
24
+ {
25
+ $this->init();
26
+ }
27
+
28
+ public function setRegisterdExtensionsLicenses()
29
+ {
30
+ $registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
31
+ $registered = json_decode($registered, true);
32
+
33
+ if (empty($registered)) {
34
+ return false;
35
+ }
36
+ $licenses = array();
37
+ foreach ($registered as $register) {
38
+
39
+ if (empty($register['options']['licence'])) {
40
+ continue;
41
+ }
42
+
43
+ $licenses[] = $register['options']['licence'];
44
+ }
45
+
46
+ $this->setLicenses($licenses);
47
+
48
+ return true;
49
+ }
50
+
51
+ private function init()
52
+ {
53
+ $this->setRegisterdExtensionsLicenses();
54
+ $licenses = $this->getLicenses();
55
+
56
+ if (empty($licenses)) {
57
+ return false;
58
+ }
59
+ add_action('admin_menu', array($this, 'menu'), 22);
60
+ add_action('admin_init', array($this, 'sgpbActivateLicense'));
61
+ add_action('admin_notices', array($this, 'sgpbAdminNotices'));
62
+
63
+ $licenses = $this->getLicenses();
64
+
65
+ foreach ($licenses as $license) {
66
+ $key = @$license['key'];
67
+ $storeURL = @$license['storeURL'];
68
+ $pluginMainFilePath = @$license['file'];
69
+ $pluginMainFilePath = SG_POPUP_PLUGIN_PATH.$pluginMainFilePath;
70
+
71
+ $licenseKey = trim(get_option('sgpb-license-key-'.$key));
72
+ $status = get_option('sgpb-license-status-'.$key);
73
+
74
+ if ($status == false || $status != 'valid') {
75
+ continue;
76
+ }
77
+
78
+ $version = @constant('SG_VERSION_'.$key);
79
+
80
+ // If the version of the extension is not found, update will not possibly be shown
81
+ if(empty($version)) {
82
+ continue;
83
+ }
84
+ $sgpbUpdater = new EDD_SL_Plugin_Updater($storeURL, $pluginMainFilePath, array(
85
+ 'version' => $version, // current version number
86
+ 'license' => $licenseKey, // license key (used get_option above to retrieve from DB)
87
+ 'item_id' => $license['itemId'], // id of this plugin
88
+ 'author' => $license['autor'], // author of this plugin
89
+ 'beta' => false // set to true if you wish customers to receive update notifications of beta releases
90
+ ));
91
+ }
92
+
93
+ return true;
94
+ }
95
+
96
+ public function menu()
97
+ {
98
+ 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'));
99
+ }
100
+
101
+ public function sanitizeLicense($new)
102
+ {
103
+ $old = get_option('sgpb-license-key-'.$this->licenseKey);
104
+
105
+ if ($old && $old != $new) {
106
+ delete_option('sgpb-license-status-'.$this->licenseKey); // new license has been entered, so must reactivate
107
+ }
108
+ update_option('sgpb-license-key-'.$this->licenseKey, $new);
109
+
110
+ return $new;
111
+ }
112
+
113
+ public function pluginLicense()
114
+ {
115
+ require_once(SG_POPUP_VIEWS_PATH.'license.php');
116
+ }
117
+
118
+ public function sgpbActivateLicense()
119
+ {
120
+ $licenses = $this->getLicenses();
121
+
122
+ foreach ($licenses as $license) {
123
+ $key = @$license['key'];
124
+ $itemId = @$license['itemId'];
125
+ $itemName = @$license['itemName'];
126
+ $storeURL = @$license['storeURL'];
127
+ $this->licenseKey = $key;
128
+
129
+ if (isset($_POST['sgpb-license-key-'.$key])) {
130
+ $this->sanitizeLicense($_POST['sgpb-license-key-'.$key]);
131
+ }
132
+
133
+ // listen for our activate button to be clicked
134
+ if (isset($_POST['sgpb-license-activate-'.$key])) {
135
+ // run a quick security check
136
+ if (!check_admin_referer('sgpb_nonce', 'sgpb_nonce')) {
137
+ return; // get out if we didn't click the Activate button
138
+ }
139
+ // retrieve the license from the database
140
+ $license = trim(get_option('sgpb-license-key-'.$key));
141
+ // data to send in our API request
142
+ $apiParams = array(
143
+ 'edd_action' => 'activate_license',
144
+ 'license' => $license,
145
+ 'item_id' => $itemId, // The ID of the item in EDD
146
+ 'url' => home_url()
147
+ );
148
+ // Call the custom API.
149
+ $response = wp_remote_post($storeURL, array('timeout' => 15, 'sslverify' => false, 'body' => $apiParams));
150
+ // make sure the response came back okay
151
+ if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
152
+ $errorMessage = $response->get_error_message();
153
+ $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
154
+ }
155
+ else {
156
+ $licenseData = json_decode(wp_remote_retrieve_body($response));
157
+ if (false === $licenseData->success) {
158
+ switch ($licenseData->error) {
159
+ case 'expired' :
160
+ $message = sprintf(
161
+ __('Your license key expired on %s.', SG_POPUP_TEXT_DOMAIN),
162
+ date_i18n(get_option('date_format'), strtotime($licenseData->expires, current_time('timestamp')))
163
+ );
164
+ break;
165
+ case 'revoked' :
166
+ $message = __('Your license key has been disabled.', SG_POPUP_TEXT_DOMAIN);
167
+ break;
168
+ case 'missing' :
169
+ $message = __('Invalid license.', SG_POPUP_TEXT_DOMAIN);
170
+ break;
171
+ case 'invalid' :
172
+ case 'site_inactive' :
173
+ $message = __('Your license is not active for this URL.',SG_POPUP_TEXT_DOMAIN);
174
+ break;
175
+ case 'item_name_mismatch' :
176
+ $message = sprintf(__('This appears to be an invalid license key for %s.', SG_POPUP_TEXT_DOMAIN), $itemName);
177
+ break;
178
+ case 'no_activations_left' :
179
+ $message = __('You\'ve already used the permitted number of this license key!', SG_POPUP_TEXT_DOMAIN);
180
+ break;
181
+ default :
182
+ $message = __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ // Check if anything passed on a message constituting a failure
188
+ if (!empty($message)) {
189
+ $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
190
+ $redirect = add_query_arg(array('sl_activation' => 'false', 'message' => urlencode($message)), $baseUrl);
191
+ wp_redirect($redirect);
192
+ exit();
193
+ }
194
+ // $licenseData->license will be either "valid" or "invalid"
195
+ update_option('sgpb-license-status-'.$key, $licenseData->license);
196
+ $hasInactiveExtensions = AdminHelper::hasInactiveExtensions();
197
+ // all available extensions have active license status
198
+ if (empty($hasInactiveExtensions)) {
199
+ // and if we don't have inactive extensions, remove option, until new one activation
200
+ delete_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
201
+ }
202
+ wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
203
+ exit();
204
+ }
205
+
206
+ if (isset($_POST['sgpb-license-deactivate'.$key])) {
207
+ $license = trim(get_option('sgpb-license-key-'.$key));
208
+ // data to send in our API request
209
+ $apiParams = array(
210
+ 'edd_action' => 'deactivate_license',
211
+ 'license' => $license,
212
+ 'item_id' => $itemId, // The ID of the item in EDD
213
+ 'url' => home_url()
214
+ );
215
+ $home = home_url();
216
+ // Send the remote request
217
+ $response = wp_remote_post($storeURL, array('body' => $apiParams, 'timeout' => 15, 'sslverify' => false));
218
+ if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
219
+ $errorMessage = $response->get_error_message();
220
+ $message = (is_wp_error($response) && ! empty($errorMessage)) ? $errorMessage : __('An error occurred, please try again.', SG_POPUP_TEXT_DOMAIN);
221
+ $baseUrl = admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE);
222
+ $redirect = add_query_arg(array('message' => urlencode($message)), $baseUrl);
223
+ wp_redirect($redirect);
224
+ exit();
225
+ }
226
+ else {
227
+ $status = false;
228
+ $licenseData = json_decode(wp_remote_retrieve_body($response));
229
+ if (isset($licenseData->success)) {
230
+ $status = $licenseData->success;
231
+ }
232
+ update_option('sgpb-license-status-'.$key, $status);
233
+ update_option('SGPB_INACTIVE_EXTENSIONS', 'inactive');
234
+ wp_redirect(admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SGPB_POPUP_LICENSE));
235
+ exit();
236
+ }
237
+ }
238
+ }
239
+ }
240
+
241
+ public function sgpbAdminNotices()
242
+ {
243
+ if (isset($_GET['sl_activation']) && !empty($_GET['message'])) {
244
+ switch ($_GET['sl_activation']) {
245
+ case 'false':
246
+ $message = urldecode($_GET['message']);
247
+ ?>
248
+ <div class="error">
249
+ <h3><?php echo $message; ?></h3>
250
+ </div>
251
+ <?php
252
+ break;
253
+ case 'true':
254
+ break;
255
+ }
256
+ }
257
+ }
258
+ }
com/classes/dataTable/Subscribers.php CHANGED
@@ -1,166 +1,166 @@
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('');
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
- $displayColumns = array(
30
- 'bulk'=>'<input class="subs-bulk" type="checkbox" autocomplete="off">',
31
- 'id' => 'ID',
32
- 'firstName' => __('First name', SG_POPUP_TEXT_DOMAIN),
33
- 'lastName' => __('Last name', SG_POPUP_TEXT_DOMAIN),
34
- 'email' => __('Email', SG_POPUP_TEXT_DOMAIN),
35
- 'cDate' => __('Date', SG_POPUP_TEXT_DOMAIN),
36
- 'subscriptionType' => __('Popup', SG_POPUP_TEXT_DOMAIN)
37
- );
38
-
39
- $filterColumnsDisplaySettings = array(
40
- 'columns' => $columns,
41
- 'displayColumns' => $displayColumns
42
- );
43
-
44
- $filterColumnsDisplaySettings = apply_filters('sgpbAlterColumnIntoSubscribers', $filterColumnsDisplaySettings);
45
-
46
- $this->setColumns(@$filterColumnsDisplaySettings['columns']);
47
- $this->setDisplayColumns(@$filterColumnsDisplaySettings['displayColumns']);
48
- $this->setSortableColumns(array(
49
- 'id' => array('id', false),
50
- 'firstName' => array('firstName', true),
51
- 'lastName' => array('lastName', true),
52
- 'email' => array('email', true),
53
- 'cDate' => array('cDate', true),
54
- 'subscriptionType' => array('subscriptionType', true),
55
- $this->setInitialSort(array(
56
- 'id' => 'DESC'
57
- ))
58
- ));
59
- }
60
-
61
- public function customizeRow(&$row)
62
- {
63
- $popupId = (int)$row[5];
64
- $row = apply_filters('sgpbEditSubscribersTableRowValues', $row, $popupId);
65
- $row[6] = get_the_title($popupId);
66
- $row[5] = $row[4];
67
- $row[4] = $row[3];
68
- $row[3] = $row[2];
69
- $row[2] = $row[1];
70
- $row[1] = $row[0];
71
-
72
- // show date more user friendly
73
- $row[5] = date('d F Y', strtotime($row[5]));
74
-
75
- $id = $row[0];
76
- $row[0] = '<input type="checkbox" class="subs-delete-checkbox" data-delete-id="'.esc_attr($id).'">';
77
- }
78
-
79
- public function customizeQuery(&$query)
80
- {
81
- $query = AdminHelper::subscribersRelatedQuery($query);
82
- }
83
-
84
- public function getNavPopupsConditions()
85
- {
86
- $subscriptionPopups = SubscriptionPopup::getAllSubscriptionForms();
87
- $list = '';
88
- $selectedPopup = '';
89
-
90
- if (isset($_GET['sgpb-subscription-popup-id'])) {
91
- $selectedPopup = (int)$_GET['sgpb-subscription-popup-id'];
92
- }
93
-
94
- ob_start();
95
- ?>
96
- <input type="hidden" class="sgpb-subscription-popup-id" name="sgpb-subscription-popup-id" value="<?php echo $selectedPopup;?>">
97
- <input type="hidden" name="page" value="<?php echo SG_POPUP_SUBSCRIBERS_PAGE; ?>" >
98
-
99
- <select name="sgpb-subscription-popup" id="sgpb-subscription-popup">
100
- <?php
101
- $list .= '<option value="all">'.__('All', SG_POPUP_TEXT_DOMAIN).'</option>';
102
- foreach ($subscriptionPopups as $popupId => $popupTitle) {
103
- if ($selectedPopup == $popupId) {
104
- $selected = ' selected';
105
- }
106
- else {
107
- $selected = '';
108
- }
109
- $list .= '<option value="'.esc_attr($popupId).'"'.$selected.'>'.$popupTitle.'</option>';
110
- }
111
- echo $list;
112
- ?>
113
- </select>
114
-
115
- <?php
116
- $content = ob_get_contents();
117
- ob_end_clean();
118
-
119
- return $content;
120
- }
121
-
122
- public function getNavDateConditions() {
123
- $subscribersDates = SubscriptionPopup::getAllSubscribersDate();
124
- $uniqueDates = array();
125
-
126
- foreach ($subscribersDates as $arr) {
127
- $uniqueDates[] = $arr;
128
- }
129
- $uniqueDates = array_unique($uniqueDates, SORT_REGULAR);
130
-
131
- $selectedDate = '';
132
- $dateList = '';
133
- $selected = '';
134
-
135
- if (isset($_GET['sgpb-subscribers-date'])) {
136
- $selectedDate = esc_sql($_GET['sgpb-subscribers-date']);
137
- }
138
-
139
- ob_start();
140
- ?>
141
- <input type="hidden" class="sgpb-subscribers-date" name="sgpb-subscribers-date" value="<?php echo $selectedDate;?>">
142
- <select name="sgpb-subscribers-dates" id="sgpb-subscribers-dates">
143
- <?php
144
- $gotDateList = '<option value="all">'.__('All dates', SG_POPUP_TEXT_DOMAIN).'</option>';
145
- foreach ($uniqueDates as $date) {
146
- if ($selectedDate == $date['date-value']) {
147
- $selected = ' selected';
148
- }
149
- else {
150
- $selected = '';
151
- }
152
- $gotDateList .= '<option value="'.$date['date-value'].'"'.$selected.'>'.$date['date-title'].'</option>';
153
- }
154
- if (empty($subscribersDates)) {
155
- $gotDateList = '<option value="'.@$date['date-value'].'"'.$selected.'>'.__('Date', SG_POPUP_TEXT_DOMAIN).'</option>';
156
- }
157
- echo $dateList.$gotDateList;
158
- ?>
159
- </select>
160
- <?php
161
- $content = ob_get_contents();
162
- ob_end_clean();
163
-
164
- return $content;
165
- }
166
- }
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('');
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
+ $displayColumns = array(
30
+ 'bulk'=>'<input class="subs-bulk" type="checkbox" autocomplete="off">',
31
+ 'id' => 'ID',
32
+ 'firstName' => __('First name', SG_POPUP_TEXT_DOMAIN),
33
+ 'lastName' => __('Last name', SG_POPUP_TEXT_DOMAIN),
34
+ 'email' => __('Email', SG_POPUP_TEXT_DOMAIN),
35
+ 'cDate' => __('Date', SG_POPUP_TEXT_DOMAIN),
36
+ 'subscriptionType' => __('Popup', SG_POPUP_TEXT_DOMAIN)
37
+ );
38
+
39
+ $filterColumnsDisplaySettings = array(
40
+ 'columns' => $columns,
41
+ 'displayColumns' => $displayColumns
42
+ );
43
+
44
+ $filterColumnsDisplaySettings = apply_filters('sgpbAlterColumnIntoSubscribers', $filterColumnsDisplaySettings);
45
+
46
+ $this->setColumns(@$filterColumnsDisplaySettings['columns']);
47
+ $this->setDisplayColumns(@$filterColumnsDisplaySettings['displayColumns']);
48
+ $this->setSortableColumns(array(
49
+ 'id' => array('id', false),
50
+ 'firstName' => array('firstName', true),
51
+ 'lastName' => array('lastName', true),
52
+ 'email' => array('email', true),
53
+ 'cDate' => array('cDate', true),
54
+ 'subscriptionType' => array('subscriptionType', true),
55
+ $this->setInitialSort(array(
56
+ 'id' => 'DESC'
57
+ ))
58
+ ));
59
+ }
60
+
61
+ public function customizeRow(&$row)
62
+ {
63
+ $popupId = (int)$row[5];
64
+ $row = apply_filters('sgpbEditSubscribersTableRowValues', $row, $popupId);
65
+ $row[6] = get_the_title($popupId);
66
+ $row[5] = $row[4];
67
+ $row[4] = $row[3];
68
+ $row[3] = $row[2];
69
+ $row[2] = $row[1];
70
+ $row[1] = $row[0];
71
+
72
+ // show date more user friendly
73
+ $row[5] = date('d F Y', strtotime($row[5]));
74
+
75
+ $id = $row[0];
76
+ $row[0] = '<input type="checkbox" class="subs-delete-checkbox" data-delete-id="'.esc_attr($id).'">';
77
+ }
78
+
79
+ public function customizeQuery(&$query)
80
+ {
81
+ $query = AdminHelper::subscribersRelatedQuery($query);
82
+ }
83
+
84
+ public function getNavPopupsConditions()
85
+ {
86
+ $subscriptionPopups = SubscriptionPopup::getAllSubscriptionForms();
87
+ $list = '';
88
+ $selectedPopup = '';
89
+
90
+ if (isset($_GET['sgpb-subscription-popup-id'])) {
91
+ $selectedPopup = (int)$_GET['sgpb-subscription-popup-id'];
92
+ }
93
+
94
+ ob_start();
95
+ ?>
96
+ <input type="hidden" class="sgpb-subscription-popup-id" name="sgpb-subscription-popup-id" value="<?php echo $selectedPopup;?>">
97
+ <input type="hidden" name="page" value="<?php echo SG_POPUP_SUBSCRIBERS_PAGE; ?>" >
98
+
99
+ <select name="sgpb-subscription-popup" id="sgpb-subscription-popup">
100
+ <?php
101
+ $list .= '<option value="all">'.__('All', SG_POPUP_TEXT_DOMAIN).'</option>';
102
+ foreach ($subscriptionPopups as $popupId => $popupTitle) {
103
+ if ($selectedPopup == $popupId) {
104
+ $selected = ' selected';
105
+ }
106
+ else {
107
+ $selected = '';
108
+ }
109
+ $list .= '<option value="'.esc_attr($popupId).'"'.$selected.'>'.$popupTitle.'</option>';
110
+ }
111
+ echo $list;
112
+ ?>
113
+ </select>
114
+
115
+ <?php
116
+ $content = ob_get_contents();
117
+ ob_end_clean();
118
+
119
+ return $content;
120
+ }
121
+
122
+ public function getNavDateConditions() {
123
+ $subscribersDates = SubscriptionPopup::getAllSubscribersDate();
124
+ $uniqueDates = array();
125
+
126
+ foreach ($subscribersDates as $arr) {
127
+ $uniqueDates[] = $arr;
128
+ }
129
+ $uniqueDates = array_unique($uniqueDates, SORT_REGULAR);
130
+
131
+ $selectedDate = '';
132
+ $dateList = '';
133
+ $selected = '';
134
+
135
+ if (isset($_GET['sgpb-subscribers-date'])) {
136
+ $selectedDate = esc_attr($_GET['sgpb-subscribers-date']);
137
+ }
138
+
139
+ ob_start();
140
+ ?>
141
+ <input type="hidden" class="sgpb-subscribers-date" name="sgpb-subscribers-date" value="<?php echo $selectedDate;?>">
142
+ <select name="sgpb-subscribers-dates" id="sgpb-subscribers-dates">
143
+ <?php
144
+ $gotDateList = '<option value="all">'.__('All dates', SG_POPUP_TEXT_DOMAIN).'</option>';
145
+ foreach ($uniqueDates as $date) {
146
+ if ($selectedDate == $date['date-value']) {
147
+ $selected = ' selected';
148
+ }
149
+ else {
150
+ $selected = '';
151
+ }
152
+ $gotDateList .= '<option value="'.$date['date-value'].'"'.$selected.'>'.$date['date-title'].'</option>';
153
+ }
154
+ if (empty($subscribersDates)) {
155
+ $gotDateList = '<option value="'.@$date['date-value'].'"'.$selected.'>'.__('Date', SG_POPUP_TEXT_DOMAIN).'</option>';
156
+ }
157
+ echo $dateList.$gotDateList;
158
+ ?>
159
+ </select>
160
+ <?php
161
+ $content = ob_get_contents();
162
+ ob_end_clean();
163
+
164
+ return $content;
165
+ }
166
+ }
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,344 +1,344 @@
1
- <?php
2
-
3
- require_once(SG_POPUP_EXTENSION_PATH.'SgpbIPopupExtension.php');
4
- use sgpb\AdminHelper;
5
- if (class_exists('SgpbPopupExtension')) {
6
- return false;
7
- }
8
-
9
- class SgpbPopupExtension implements SgpbIPopupExtension
10
- {
11
- public function getNewsletterPageKey()
12
- {
13
- return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_NEWSLETTER_PAGE;
14
- }
15
-
16
- public function getSettingsPageKey()
17
- {
18
- return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SETTINGS_PAGE;
19
- }
20
-
21
- public function getScripts($pageName, $data)
22
- {
23
- $jsFiles = array();
24
- $localizeData = array();
25
- $translatedData = ConfigDataHelper::getJsLocalizedData();
26
- $currentPostType = AdminHelper::getCurrentPostType();
27
- $newsletterPage = $this->getNewsletterPageKey();
28
- $settingsPage = $this->getSettingsPageKey();
29
-
30
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'ExtensionsNotification.js', 'dep' => array('jquery'));
31
- $localizeData[] = array(
32
- 'handle' => 'ExtensionsNotification.js',
33
- 'name' => 'SGPB_JS_EXTENSIONS_PARAMS',
34
- 'data' => array(
35
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
36
- 'popupPostType' => SG_POPUP_POST_TYPE,
37
- 'extendPage' => SG_POPUP_EXTEND_PAGE,
38
- 'supportUrl' => SG_POPUP_SUPPORT_URL,
39
- 'allExtensionsUrl' => SG_POPUP_ALL_EXTENSIONS_URL,
40
- 'supportPage' => SG_POPUP_SUPPORT_PAGE,
41
- 'reviewUrl' => SG_POPUP_RATE_US_URL
42
- )
43
- );
44
-
45
- $allowPages = array(
46
- 'popupType',
47
- 'editpage',
48
- 'popupspage',
49
- $newsletterPage,
50
- $settingsPage
51
- );
52
-
53
- if ($pageName == $newsletterPage) {
54
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Newsletter.js');
55
- }
56
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js', 'dep' => array('jquery'));
57
- $localizeData[] = array(
58
- 'handle' => 'Banner.js',
59
- 'name' => 'SGPB_JS_PARAMS',
60
- 'data' => array(
61
- 'url' => admin_url('admin-ajax.php'),
62
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
63
- )
64
- );
65
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'gutenbergBlock.min.js');
66
-
67
- $localizeData[] = array(
68
- 'handle' => 'gutenbergBlock.min.js',
69
- 'name' => 'SGPB_GUTENBERG_PARAMS',
70
- 'data' => array(
71
- 'allPopups' => AdminHelper::getGutenbergPopupsIdAndTitle(),
72
- 'allEvents' => AdminHelper::getGutenbergPopupsEvents(),
73
- 'title' => __('Popup Builder', SG_POPUP_TEXT_DOMAIN),
74
- 'description' => __('This block will help you to add Popup Builder’s shortcode inside the page content', SG_POPUP_TEXT_DOMAIN),
75
- 'i18n'=> array(
76
- 'title' => __( 'WPForms', 'wpforms-lite' ),
77
- 'description' => __( 'Select and display one of your forms.', 'wpforms-lite' ),
78
- 'form_keyword' => __( 'form', 'wpforms-lite' ),
79
- 'form_select' => __( 'Select Popup', 'wpforms-lite' ),
80
- 'form_settings' => __( 'Form Settings', 'wpforms-lite' ),
81
- 'form_selected' => __( 'Form', 'wpforms-lite' ),
82
- 'show_title' => __( 'Show Title', 'wpforms-lite' ),
83
- 'show_description' => __( 'Show Description', 'wpforms-lite' ),
84
- ),
85
- 'logo_url' => SG_POPUP_IMG_URL.'bannerLogo.png',
86
- 'logo_classname' => 'sgpb-gutenberg-logo',
87
- 'clickText' => __('Click me', SG_POPUP_TEXT_DOMAIN)
88
- )
89
- );
90
-
91
- if (in_array($pageName, $allowPages) || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE) {
92
- $jsFiles[] = array('folderUrl'=> '', 'filename' => 'wp-color-picker');
93
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
94
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
95
-
96
-
97
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'bootstrap.min.js');
98
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgPopupRangeSlider.js');
99
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Backend.js');
100
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'FloatingButton.js', 'dep' => array('Backend.js'),);
101
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'NotificationCenter.js');
102
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js');
103
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
104
-
105
- $localizeData[] = array(
106
- 'handle' => 'Backend.js',
107
- 'name' => 'SGPB_JS_PARAMS',
108
- 'data' => array(
109
- 'url' => admin_url('admin-ajax.php'),
110
- 'postUrl' => SG_POPUP_ADMIN_URL.'admin-post.php',
111
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
112
- )
113
- );
114
-
115
- $localizeData[] = array(
116
- 'handle' => 'sgpbSelect2.js',
117
- 'name' => 'SGPB_JS_PACKAGES',
118
- 'data' => array(
119
- 'packages' => array(
120
- 'current' => SGPB_POPUP_PKG,
121
- 'free' => SGPB_POPUP_PKG_FREE,
122
- 'silver' => SGPB_POPUP_PKG_SILVER,
123
- 'gold' => SGPB_POPUP_PKG_GOLD,
124
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
125
- ),
126
- 'extensions' => array(
127
- 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
128
- 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
129
- ),
130
- 'proEvents' => apply_filters('sgpbProEvents', array('inactivity', 'onScroll'))
131
- )
132
- );
133
-
134
- $localizeData[] = array(
135
- 'handle' => 'Backend.js',
136
- 'name' => 'SGPB_JS_LOCALIZATION',
137
- 'data' => $translatedData
138
- );
139
-
140
- $localizeData[] = array(
141
- 'handle' => 'Popup.js',
142
- 'name' => 'sgpbPublicUrl',
143
- 'data' => SG_POPUP_PUBLIC_URL
144
- );
145
- }
146
- else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
147
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js', 'dep' => '', 'ver' => '3.86', 'inFooter' => '');
148
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
149
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Subscribers.js');
150
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js');
151
-
152
- $localizeData[] = array(
153
- 'handle' => 'Subscribers.js',
154
- 'name' => 'SGPB_JS_PARAMS',
155
- 'data' => array(
156
- 'url' => admin_url('admin-ajax.php'),
157
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
158
- 'packages' => array(
159
- 'current' => SGPB_POPUP_PKG,
160
- 'silver' => SGPB_POPUP_PKG_SILVER,
161
- 'gold' => SGPB_POPUP_PKG_GOLD,
162
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
163
- )
164
- )
165
- );
166
-
167
- $localizeData[] = array(
168
- 'handle' => 'sgpbSelect2.js',
169
- 'name' => 'SGPB_JS_PACKAGES',
170
- 'data' => array(
171
- 'packages' => array(
172
- 'current' => SGPB_POPUP_PKG,
173
- 'free' => SGPB_POPUP_PKG_FREE,
174
- 'silver' => SGPB_POPUP_PKG_SILVER,
175
- 'gold' => SGPB_POPUP_PKG_GOLD,
176
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
177
- )
178
- )
179
- );
180
-
181
- $localizeData[] = array(
182
- 'handle' => 'Subscribers.js',
183
- 'name' => 'SGPB_JS_ADMIN_URL',
184
- 'data' => array(
185
- 'url' => SG_POPUP_ADMIN_URL.'admin-post.php',
186
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
187
- )
188
- );
189
-
190
- $localizeData[] = array(
191
- 'handle' => 'Subscribers.js',
192
- 'name' => 'SGPB_JS_LOCALIZATION',
193
- 'data' => $translatedData
194
- );
195
-
196
- $localizeData[] = array(
197
- 'handle' => 'Banner.js',
198
- 'name' => 'SGPB_JS_PARAMS',
199
- 'data' => array(
200
- 'url' => admin_url('admin-ajax.php'),
201
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
202
- )
203
- );
204
- }
205
-
206
- $scriptData = array(
207
- 'jsFiles' => apply_filters('sgpbAdminJsFiles', $jsFiles),
208
- 'localizeData' => apply_filters('sgpbAdminJsLocalizedData', $localizeData)
209
- );
210
-
211
- $scriptData = apply_filters('sgpbAdminJs', $scriptData);
212
-
213
- return $scriptData;
214
- }
215
-
216
- public function getStyles($pageName, $data)
217
- {
218
- $cssFiles = array();
219
- $newsletterPage = $this->getNewsletterPageKey();
220
- $settingsPage = $this->getSettingsPageKey();
221
-
222
- $allowPages = array(
223
- 'popupType',
224
- 'editpage',
225
- 'popupspage',
226
- $newsletterPage,
227
- $settingsPage
228
- );
229
-
230
- if (in_array($pageName, $allowPages)) {
231
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'jquery.dateTimePicker.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
232
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
233
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
234
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
235
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgPopupRangeSlider.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
236
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
237
- $cssFiles[] = array('folderUrl' => '', 'filename' => 'wp-color-picker');
238
- }
239
- else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
240
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
241
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
242
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
243
- }
244
-
245
- $cssData = array(
246
- 'cssFiles' => apply_filters('sgpbAdminCssFiles', $cssFiles)
247
- );
248
- return $cssData;
249
- }
250
-
251
- public function getFrontendScripts($page, $popupObjs)
252
- {
253
- $translatedData = ConfigDataHelper::getJsLocalizedData();
254
- $jsFiles = array();
255
- $localizeData = array();
256
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js', 'dep' => array('jquery'));
257
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js', 'dep' => array('Popup.js'));
258
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilder.js', 'dep' => array('PopupConfig.js'));
259
- if (SGPB_POPUP_PKG >= SGPB_POPUP_PKG_SILVER) {
260
- $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilderProFunctionality.js', 'dep' => array('jquery'));
261
- }
262
-
263
- $localizeData[] = array(
264
- 'handle' => 'PopupBuilder.js',
265
- 'name' => 'SGPB_POPUP_PARAMS',
266
- 'data' => array(
267
- 'popupTypeAgeRestriction' => SGPB_POPUP_TYPE_RESTRICTION,
268
- 'defaultThemeImages' => array(
269
- 1 => AdminHelper::defaultButtonImage('sgpb-theme-1'),
270
- 2 => AdminHelper::defaultButtonImage('sgpb-theme-2'),
271
- 3 => AdminHelper::defaultButtonImage('sgpb-theme-3'),
272
- 5 => AdminHelper::defaultButtonImage('sgpb-theme-5'),
273
- 6 => AdminHelper::defaultButtonImage('sgpb-theme-6')
274
- ),
275
- 'homePageUrl' => get_home_url().'/',
276
- 'isPreview' => isset($_GET['sg_popup_preview_id']),
277
- 'convertedIdsReverse' => AdminHelper::getReverseConvertIds(),
278
- 'dontShowPopupExpireTime' => SGPB_DONT_SHOW_POPUP_EXPIRY,
279
- 'conditionalJsClasses' => apply_filters('sgpbConditionalJsClasses', array()),
280
- 'disableAnalyticsGeneral' => AdminHelper::getOption('sgpb-enable-debug-mode')
281
- )
282
- );
283
-
284
- $localizeData[] = array(
285
- 'handle' => 'PopupBuilder.js',
286
- 'name' => 'SGPB_JS_PACKAGES',
287
- 'data' => array(
288
- 'packages' => array(
289
- 'current' => SGPB_POPUP_PKG,
290
- 'free' => SGPB_POPUP_PKG_FREE,
291
- 'silver' => SGPB_POPUP_PKG_SILVER,
292
- 'gold' => SGPB_POPUP_PKG_GOLD,
293
- 'platinum' => SGPB_POPUP_PKG_PLATINUM
294
- ),
295
- 'extensions' => array(
296
- 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
297
- 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
298
- )
299
- )
300
- );
301
-
302
- $localizeData[] = array(
303
- 'handle' => 'Popup.js',
304
- 'name' => 'sgpbPublicUrl',
305
- 'data' => SG_POPUP_PUBLIC_URL
306
- );
307
-
308
- $localizeData[] = array(
309
- 'handle' => 'Popup.js',
310
- 'name' => 'SGPB_JS_LOCALIZATION',
311
- 'data' => $translatedData
312
- );
313
-
314
- $localizeData[] = array(
315
- 'handle' => 'PopupBuilder.js',
316
- 'name' => 'SGPB_JS_PARAMS',
317
- 'data' => array(
318
- 'ajaxUrl' => admin_url('admin-ajax.php'),
319
- 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
320
- )
321
- );
322
-
323
- $scriptData = array(
324
- 'jsFiles' => apply_filters('sgpbFrontendJsFiles', $jsFiles),
325
- 'localizeData' => apply_filters('sgpbFrontendJsLocalizedData', $localizeData)
326
- );
327
-
328
- $scriptData = apply_filters('sgpbFrontendJs', $scriptData);
329
-
330
- return $scriptData;
331
- }
332
-
333
- public function getFrontendStyles($page, $data)
334
- {
335
- $cssFiles = array();
336
- $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
337
-
338
- $cssData = array(
339
- 'cssFiles' => apply_filters('sgpbFrontendCssFiles', $cssFiles)
340
- );
341
-
342
- return $cssData;
343
- }
344
- }
1
+ <?php
2
+
3
+ require_once(SG_POPUP_EXTENSION_PATH.'SgpbIPopupExtension.php');
4
+ use sgpb\AdminHelper;
5
+ if (class_exists('SgpbPopupExtension')) {
6
+ return false;
7
+ }
8
+
9
+ class SgpbPopupExtension implements SgpbIPopupExtension
10
+ {
11
+ public function getNewsletterPageKey()
12
+ {
13
+ return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_NEWSLETTER_PAGE;
14
+ }
15
+
16
+ public function getSettingsPageKey()
17
+ {
18
+ return SG_POPUP_POST_TYPE.'_page_'.SG_POPUP_SETTINGS_PAGE;
19
+ }
20
+
21
+ public function getScripts($pageName, $data)
22
+ {
23
+ $jsFiles = array();
24
+ $localizeData = array();
25
+ $translatedData = ConfigDataHelper::getJsLocalizedData();
26
+ $currentPostType = AdminHelper::getCurrentPostType();
27
+ $newsletterPage = $this->getNewsletterPageKey();
28
+ $settingsPage = $this->getSettingsPageKey();
29
+
30
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'ExtensionsNotification.js', 'dep' => array('jquery'));
31
+ $localizeData[] = array(
32
+ 'handle' => 'ExtensionsNotification.js',
33
+ 'name' => 'SGPB_JS_EXTENSIONS_PARAMS',
34
+ 'data' => array(
35
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
36
+ 'popupPostType' => SG_POPUP_POST_TYPE,
37
+ 'extendPage' => SG_POPUP_EXTEND_PAGE,
38
+ 'supportUrl' => SG_POPUP_SUPPORT_URL,
39
+ 'allExtensionsUrl' => SG_POPUP_ALL_EXTENSIONS_URL,
40
+ 'supportPage' => SG_POPUP_SUPPORT_PAGE,
41
+ 'reviewUrl' => SG_POPUP_RATE_US_URL
42
+ )
43
+ );
44
+
45
+ $allowPages = array(
46
+ 'popupType',
47
+ 'editpage',
48
+ 'popupspage',
49
+ $newsletterPage,
50
+ $settingsPage
51
+ );
52
+
53
+ if ($pageName == $newsletterPage) {
54
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Newsletter.js');
55
+ }
56
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js', 'dep' => array('jquery'));
57
+ $localizeData[] = array(
58
+ 'handle' => 'Banner.js',
59
+ 'name' => 'SGPB_JS_PARAMS',
60
+ 'data' => array(
61
+ 'url' => admin_url('admin-ajax.php'),
62
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
63
+ )
64
+ );
65
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'gutenbergBlock.min.js');
66
+
67
+ $localizeData[] = array(
68
+ 'handle' => 'gutenbergBlock.min.js',
69
+ 'name' => 'SGPB_GUTENBERG_PARAMS',
70
+ 'data' => array(
71
+ 'allPopups' => AdminHelper::getGutenbergPopupsIdAndTitle(),
72
+ 'allEvents' => AdminHelper::getGutenbergPopupsEvents(),
73
+ 'title' => __('Popup Builder', SG_POPUP_TEXT_DOMAIN),
74
+ 'description' => __('This block will help you to add Popup Builder’s shortcode inside the page content', SG_POPUP_TEXT_DOMAIN),
75
+ 'i18n'=> array(
76
+ 'title' => __( 'WPForms', 'wpforms-lite' ),
77
+ 'description' => __( 'Select and display one of your forms.', 'wpforms-lite' ),
78
+ 'form_keyword' => __( 'form', 'wpforms-lite' ),
79
+ 'form_select' => __( 'Select Popup', 'wpforms-lite' ),
80
+ 'form_settings' => __( 'Form Settings', 'wpforms-lite' ),
81
+ 'form_selected' => __( 'Form', 'wpforms-lite' ),
82
+ 'show_title' => __( 'Show Title', 'wpforms-lite' ),
83
+ 'show_description' => __( 'Show Description', 'wpforms-lite' ),
84
+ ),
85
+ 'logo_url' => SG_POPUP_IMG_URL.'bannerLogo.png',
86
+ 'logo_classname' => 'sgpb-gutenberg-logo',
87
+ 'clickText' => __('Click me', SG_POPUP_TEXT_DOMAIN)
88
+ )
89
+ );
90
+
91
+ if (in_array($pageName, $allowPages) || $currentPostType == SG_POPUP_AUTORESPONDER_POST_TYPE) {
92
+ $jsFiles[] = array('folderUrl'=> '', 'filename' => 'wp-color-picker');
93
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js');
94
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
95
+
96
+
97
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'bootstrap.min.js');
98
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgPopupRangeSlider.js');
99
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Backend.js');
100
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'FloatingButton.js', 'dep' => array('Backend.js'),);
101
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'NotificationCenter.js');
102
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js');
103
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js');
104
+
105
+ $localizeData[] = array(
106
+ 'handle' => 'Backend.js',
107
+ 'name' => 'SGPB_JS_PARAMS',
108
+ 'data' => array(
109
+ 'url' => admin_url('admin-ajax.php'),
110
+ 'postUrl' => SG_POPUP_ADMIN_URL.'admin-post.php',
111
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
112
+ )
113
+ );
114
+
115
+ $localizeData[] = array(
116
+ 'handle' => 'sgpbSelect2.js',
117
+ 'name' => 'SGPB_JS_PACKAGES',
118
+ 'data' => array(
119
+ 'packages' => array(
120
+ 'current' => SGPB_POPUP_PKG,
121
+ 'free' => SGPB_POPUP_PKG_FREE,
122
+ 'silver' => SGPB_POPUP_PKG_SILVER,
123
+ 'gold' => SGPB_POPUP_PKG_GOLD,
124
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
125
+ ),
126
+ 'extensions' => array(
127
+ 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
128
+ 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
129
+ ),
130
+ 'proEvents' => apply_filters('sgpbProEvents', array('inactivity', 'onScroll'))
131
+ )
132
+ );
133
+
134
+ $localizeData[] = array(
135
+ 'handle' => 'Backend.js',
136
+ 'name' => 'SGPB_JS_LOCALIZATION',
137
+ 'data' => $translatedData
138
+ );
139
+
140
+ $localizeData[] = array(
141
+ 'handle' => 'Popup.js',
142
+ 'name' => 'sgpbPublicUrl',
143
+ 'data' => SG_POPUP_PUBLIC_URL
144
+ );
145
+ }
146
+ else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
147
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'select2.min.js', 'dep' => '', 'ver' => '3.86', 'inFooter' => '');
148
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'sgpbSelect2.js');
149
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Subscribers.js');
150
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Banner.js');
151
+
152
+ $localizeData[] = array(
153
+ 'handle' => 'Subscribers.js',
154
+ 'name' => 'SGPB_JS_PARAMS',
155
+ 'data' => array(
156
+ 'url' => admin_url('admin-ajax.php'),
157
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE),
158
+ 'packages' => array(
159
+ 'current' => SGPB_POPUP_PKG,
160
+ 'silver' => SGPB_POPUP_PKG_SILVER,
161
+ 'gold' => SGPB_POPUP_PKG_GOLD,
162
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
163
+ )
164
+ )
165
+ );
166
+
167
+ $localizeData[] = array(
168
+ 'handle' => 'sgpbSelect2.js',
169
+ 'name' => 'SGPB_JS_PACKAGES',
170
+ 'data' => array(
171
+ 'packages' => array(
172
+ 'current' => SGPB_POPUP_PKG,
173
+ 'free' => SGPB_POPUP_PKG_FREE,
174
+ 'silver' => SGPB_POPUP_PKG_SILVER,
175
+ 'gold' => SGPB_POPUP_PKG_GOLD,
176
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
177
+ )
178
+ )
179
+ );
180
+
181
+ $localizeData[] = array(
182
+ 'handle' => 'Subscribers.js',
183
+ 'name' => 'SGPB_JS_ADMIN_URL',
184
+ 'data' => array(
185
+ 'url' => SG_POPUP_ADMIN_URL.'admin-post.php',
186
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
187
+ )
188
+ );
189
+
190
+ $localizeData[] = array(
191
+ 'handle' => 'Subscribers.js',
192
+ 'name' => 'SGPB_JS_LOCALIZATION',
193
+ 'data' => $translatedData
194
+ );
195
+
196
+ $localizeData[] = array(
197
+ 'handle' => 'Banner.js',
198
+ 'name' => 'SGPB_JS_PARAMS',
199
+ 'data' => array(
200
+ 'url' => admin_url('admin-ajax.php'),
201
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
202
+ )
203
+ );
204
+ }
205
+
206
+ $scriptData = array(
207
+ 'jsFiles' => apply_filters('sgpbAdminJsFiles', $jsFiles),
208
+ 'localizeData' => apply_filters('sgpbAdminJsLocalizedData', $localizeData)
209
+ );
210
+
211
+ $scriptData = apply_filters('sgpbAdminJs', $scriptData);
212
+
213
+ return $scriptData;
214
+ }
215
+
216
+ public function getStyles($pageName, $data)
217
+ {
218
+ $cssFiles = array();
219
+ $newsletterPage = $this->getNewsletterPageKey();
220
+ $settingsPage = $this->getSettingsPageKey();
221
+
222
+ $allowPages = array(
223
+ 'popupType',
224
+ 'editpage',
225
+ 'popupspage',
226
+ $newsletterPage,
227
+ $settingsPage
228
+ );
229
+
230
+ if (in_array($pageName, $allowPages)) {
231
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'jquery.dateTimePicker.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
232
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
233
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
234
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
235
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgPopupRangeSlider.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
236
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
237
+ $cssFiles[] = array('folderUrl' => '', 'filename' => 'wp-color-picker');
238
+ }
239
+ else if ($pageName == SG_POPUP_SUBSCRIBERS_PAGE) {
240
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'sgbp-bootstrap.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
241
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'popupAdminStyles.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
242
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'select2.min.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
243
+ }
244
+
245
+ $cssData = array(
246
+ 'cssFiles' => apply_filters('sgpbAdminCssFiles', $cssFiles)
247
+ );
248
+ return $cssData;
249
+ }
250
+
251
+ public function getFrontendScripts($page, $popupObjs)
252
+ {
253
+ $translatedData = ConfigDataHelper::getJsLocalizedData();
254
+ $jsFiles = array();
255
+ $localizeData = array();
256
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'Popup.js', 'dep' => array('jquery'));
257
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupConfig.js', 'dep' => array('Popup.js'));
258
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilder.js', 'dep' => array('PopupConfig.js'));
259
+ if (SGPB_POPUP_PKG >= SGPB_POPUP_PKG_SILVER) {
260
+ $jsFiles[] = array('folderUrl'=> SG_POPUP_JS_URL, 'filename' => 'PopupBuilderProFunctionality.js', 'dep' => array('jquery'));
261
+ }
262
+
263
+ $localizeData[] = array(
264
+ 'handle' => 'PopupBuilder.js',
265
+ 'name' => 'SGPB_POPUP_PARAMS',
266
+ 'data' => array(
267
+ 'popupTypeAgeRestriction' => SGPB_POPUP_TYPE_RESTRICTION,
268
+ 'defaultThemeImages' => array(
269
+ 1 => AdminHelper::defaultButtonImage('sgpb-theme-1'),
270
+ 2 => AdminHelper::defaultButtonImage('sgpb-theme-2'),
271
+ 3 => AdminHelper::defaultButtonImage('sgpb-theme-3'),
272
+ 5 => AdminHelper::defaultButtonImage('sgpb-theme-5'),
273
+ 6 => AdminHelper::defaultButtonImage('sgpb-theme-6')
274
+ ),
275
+ 'homePageUrl' => get_home_url().'/',
276
+ 'isPreview' => isset($_GET['sg_popup_preview_id']),
277
+ 'convertedIdsReverse' => AdminHelper::getReverseConvertIds(),
278
+ 'dontShowPopupExpireTime' => SGPB_DONT_SHOW_POPUP_EXPIRY,
279
+ 'conditionalJsClasses' => apply_filters('sgpbConditionalJsClasses', array()),
280
+ 'disableAnalyticsGeneral' => AdminHelper::getOption('sgpb-enable-debug-mode')
281
+ )
282
+ );
283
+
284
+ $localizeData[] = array(
285
+ 'handle' => 'PopupBuilder.js',
286
+ 'name' => 'SGPB_JS_PACKAGES',
287
+ 'data' => array(
288
+ 'packages' => array(
289
+ 'current' => SGPB_POPUP_PKG,
290
+ 'free' => SGPB_POPUP_PKG_FREE,
291
+ 'silver' => SGPB_POPUP_PKG_SILVER,
292
+ 'gold' => SGPB_POPUP_PKG_GOLD,
293
+ 'platinum' => SGPB_POPUP_PKG_PLATINUM
294
+ ),
295
+ 'extensions' => array(
296
+ 'geo-targeting' => AdminHelper::isPluginActive('geo-targeting'),
297
+ 'advanced-closing' => AdminHelper::isPluginActive('advancedClosing')
298
+ )
299
+ )
300
+ );
301
+
302
+ $localizeData[] = array(
303
+ 'handle' => 'Popup.js',
304
+ 'name' => 'sgpbPublicUrl',
305
+ 'data' => SG_POPUP_PUBLIC_URL
306
+ );
307
+
308
+ $localizeData[] = array(
309
+ 'handle' => 'Popup.js',
310
+ 'name' => 'SGPB_JS_LOCALIZATION',
311
+ 'data' => $translatedData
312
+ );
313
+
314
+ $localizeData[] = array(
315
+ 'handle' => 'PopupBuilder.js',
316
+ 'name' => 'SGPB_JS_PARAMS',
317
+ 'data' => array(
318
+ 'ajaxUrl' => admin_url('admin-ajax.php'),
319
+ 'nonce' => wp_create_nonce(SG_AJAX_NONCE)
320
+ )
321
+ );
322
+
323
+ $scriptData = array(
324
+ 'jsFiles' => apply_filters('sgpbFrontendJsFiles', $jsFiles),
325
+ 'localizeData' => apply_filters('sgpbFrontendJsLocalizedData', $localizeData)
326
+ );
327
+
328
+ $scriptData = apply_filters('sgpbFrontendJs', $scriptData);
329
+
330
+ return $scriptData;
331
+ }
332
+
333
+ public function getFrontendStyles($page, $data)
334
+ {
335
+ $cssFiles = array();
336
+ $cssFiles[] = array('folderUrl' => SG_POPUP_CSS_URL, 'filename' => 'theme.css', 'dep' => array(), 'ver' => SG_POPUP_VERSION, 'inFooter' => false);
337
+
338
+ $cssData = array(
339
+ 'cssFiles' => apply_filters('sgpbFrontendCssFiles', $cssFiles)
340
+ );
341
+
342
+ return $cssData;
343
+ }
344
+ }
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,102 +1,118 @@
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
- $blogs = wp_get_sites();
10
- foreach ($blogs as $blog) {
11
- switch_to_blog($blog['blog_id']);
12
- self::registerPlugin($pluginName, $classPath, $className, $options);
13
- restore_current_blog();
14
- }
15
- return;
16
- }
17
-
18
- self::registerPlugin($pluginName, $classPath, $className, $options);
19
- }
20
-
21
- private static function registerPlugin($pluginName, $classPath, $className, $options = array())
22
- {
23
- $registeredData = array();
24
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
25
-
26
- if (!empty($registeredPlugins)) {
27
- $registeredData = $registeredPlugins;
28
- $registeredData = json_decode($registeredData, true);
29
- }
30
-
31
- if (empty($classPath) || empty($className)) {
32
- if(!empty($registeredData[$pluginName])) {
33
- /*Delete the plugin from the registered plugins' list if the class name or the class path is empty.*/
34
- unset($registeredData[$pluginName]);
35
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
36
- }
37
-
38
- return;
39
- }
40
- $classPath = str_replace(SG_POPUP_PLUGIN_PATH, '', $classPath);
41
- $pluginData['classPath'] = $classPath;
42
- $pluginData['className'] = $className;
43
- $pluginData['options'] = $options;
44
-
45
- $registeredData[$pluginName] = $pluginData;
46
- $registeredData = json_encode($registeredData);
47
-
48
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
49
- // it seems we have an inactive extension now
50
- AdminHelper::updateOption('SGPB_INACTIVE_EXTENSIONS', 'inactive');
51
-
52
- do_action('sgpb_extension_activation_hook', $pluginData);
53
- }
54
-
55
- private static function isPluginActive($plugin)
56
- {
57
- $activePlugins = (array)AdminHelper::getOption('active_plugins', array(1));
58
- return in_array($plugin, $activePlugins, true);
59
- }
60
-
61
- public static function remove($pluginName)
62
- {
63
- if (is_multisite() && is_network_admin()) {
64
- $blogs = wp_get_sites();
65
- foreach ($blogs as $blog) {
66
- switch_to_blog($blog['blog_id']);
67
- if (!self::isPluginActive($pluginName)) {
68
- self::removePlugin($pluginName);
69
- }
70
- restore_current_blog();
71
- }
72
- return;
73
- }
74
-
75
- self::removePlugin($pluginName);
76
- }
77
-
78
- private static function removePlugin($pluginName)
79
- {
80
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
81
-
82
- if (!$registeredPlugins) {
83
- return false;
84
- }
85
-
86
- $registeredData = json_decode($registeredPlugins, true);
87
-
88
- if(empty($registeredData)) {
89
- return false;
90
- }
91
-
92
- if (empty($registeredData[$pluginName])) {
93
- return false;
94
- }
95
- unset($registeredData[$pluginName]);
96
- $registeredData = json_encode($registeredData);
97
-
98
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
99
-
100
- return true;
101
- }
102
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ switch_to_blog($blog['blog_id']);
20
+ self::registerPlugin($pluginName, $classPath, $className, $options);
21
+ restore_current_blog();
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
+ switch_to_blog($blog['blog_id']);
83
+ if (!self::isPluginActive($pluginName)) {
84
+ self::removePlugin($pluginName);
85
+ }
86
+ restore_current_blog();
87
+ }
88
+ return;
89
+ }
90
+
91
+ self::removePlugin($pluginName);
92
+ }
93
+
94
+ private static function removePlugin($pluginName)
95
+ {
96
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
97
+
98
+ if (!$registeredPlugins) {
99
+ return false;
100
+ }
101
+
102
+ $registeredData = json_decode($registeredPlugins, true);
103
+
104
+ if(empty($registeredData)) {
105
+ return false;
106
+ }
107
+
108
+ if (empty($registeredData[$pluginName])) {
109
+ return false;
110
+ }
111
+ unset($registeredData[$pluginName]);
112
+ $registeredData = json_encode($registeredData);
113
+
114
+ AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredData);
115
+
116
+ return true;
117
+ }
118
+ }
com/classes/popups/FblikePopup.php CHANGED
@@ -1,113 +1,113 @@
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 Options'
17
- );
18
- }
19
-
20
- private function getScripts()
21
- {
22
- /*get WordPress localization name*/
23
- $locale = $this->getSiteLocale();
24
- ob_start();
25
- ?>
26
- <script>
27
- jQuery(window).on('sgpbDidOpen', function (e) {
28
- var sgpbOldCB = window.fbAsyncInit;
29
- window.fbAsyncInit = function () {
30
- if (typeof sgpbOldCB === 'function') {
31
- sgpbOldCB();
32
- }
33
- FB.init({
34
- appId: <?php echo SGPB_FACEBOOK_APP_ID;?>
35
- });
36
- };
37
- (function(d, s, id) {
38
- var js, fjs = d.getElementsByTagName(s)[0];
39
- if (d.getElementById(id)) return;
40
- js = d.createElement(s); js.id = id;
41
- js.src = 'https://connect.facebook.net/<?php echo $locale;?>/all.js#xfbml=1&version=v2.11&appId=<?php echo SGPB_FACEBOOK_APP_ID;?>';
42
- fjs.parentNode.insertBefore(js, fjs);
43
- }(document, 'script', 'facebook-jssdk'));
44
- });
45
- </script>
46
- <?php
47
- $scripts = ob_get_contents();
48
- ob_get_clean();
49
-
50
- return $scripts;
51
- }
52
-
53
- private function getButtonConfig($shareUrl, $layout, $shareButtonStatus)
54
- {
55
- ob_start();
56
- ?>
57
- <div class='sg-fb-buttons-wrapper sgpb-fb-wrapper-<?php echo $layout;?>'>
58
- <div class="fb-like"
59
- data-href="<?php echo $shareUrl; ?>"
60
- data-layout="<?php echo $layout; ?>"
61
- data-action="like"
62
- data-size="small"
63
- data-show-faces="true"
64
- data-share="<?php echo $shareButtonStatus; ?>">
65
- </div>
66
- </div>
67
- <?php
68
- $buttonConfig = ob_get_contents();
69
- ob_get_clean();
70
-
71
- return $buttonConfig;
72
- }
73
-
74
- private function getFblikeContent()
75
- {
76
- $options = $this->getOptions();
77
- $shareUrl = $options['sgpb-fblike-like-url'];
78
- $layout = $options['sgpb-fblike-layout'];
79
- $shareButtonStatus = true;
80
- if (!empty($options['sgpb-fblike-dont-show-share-button'])) {
81
- $shareButtonStatus = false;
82
- }
83
-
84
- $scripts = $this->getScripts();
85
- $buttonConfig = $this->getButtonConfig($shareUrl, $layout, $shareButtonStatus);
86
- ob_start();
87
- ?>
88
- <div id="sg-facebook-like">
89
- <div id="fb-root"></div>
90
- <?php echo $buttonConfig; ?>
91
- <?php echo $scripts; ?>
92
- </div>
93
- <?php
94
- $content = ob_get_contents();
95
- ob_get_clean();
96
-
97
- return $content;
98
- }
99
-
100
- public function getPopupTypeContent()
101
- {
102
- $fbLikeContent = $this->getFblikeContent();
103
- $popupContent = $this->getContent();
104
- $popupContent .= $fbLikeContent;
105
-
106
- return $popupContent;
107
- }
108
-
109
- public function getExtraRenderOptions()
110
- {
111
- return array();
112
- }
113
- }
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 Options'
17
+ );
18
+ }
19
+
20
+ private function getScripts()
21
+ {
22
+ /*get WordPress localization name*/
23
+ $locale = $this->getSiteLocale();
24
+ ob_start();
25
+ ?>
26
+ <script>
27
+ jQuery(window).on('sgpbDidOpen', function (e) {
28
+ var sgpbOldCB = window.fbAsyncInit;
29
+ window.fbAsyncInit = function () {
30
+ if (typeof sgpbOldCB === 'function') {
31
+ sgpbOldCB();
32
+ }
33
+ FB.init({
34
+ appId: <?php echo SGPB_FACEBOOK_APP_ID;?>
35
+ });
36
+ };
37
+ (function(d, s, id) {
38
+ var js, fjs = d.getElementsByTagName(s)[0];
39
+ if (d.getElementById(id)) return;
40
+ js = d.createElement(s); js.id = id;
41
+ js.src = 'https://connect.facebook.net/<?php echo $locale;?>/all.js#xfbml=1&version=v2.11&appId=<?php echo SGPB_FACEBOOK_APP_ID;?>';
42
+ fjs.parentNode.insertBefore(js, fjs);
43
+ }(document, 'script', 'facebook-jssdk'));
44
+ });
45
+ </script>
46
+ <?php
47
+ $scripts = ob_get_contents();
48
+ ob_get_clean();
49
+
50
+ return $scripts;
51
+ }
52
+
53
+ private function getButtonConfig($shareUrl, $layout, $shareButtonStatus)
54
+ {
55
+ ob_start();
56
+ ?>
57
+ <div class='sg-fb-buttons-wrapper sgpb-fb-wrapper-<?php echo $layout;?>'>
58
+ <div class="fb-like"
59
+ data-href="<?php echo $shareUrl; ?>"
60
+ data-layout="<?php echo $layout; ?>"
61
+ data-action="like"
62
+ data-size="small"
63
+ data-show-faces="true"
64
+ data-share="<?php echo $shareButtonStatus; ?>">
65
+ </div>
66
+ </div>
67
+ <?php
68
+ $buttonConfig = ob_get_contents();
69
+ ob_get_clean();
70
+
71
+ return $buttonConfig;
72
+ }
73
+
74
+ private function getFblikeContent()
75
+ {
76
+ $options = $this->getOptions();
77
+ $shareUrl = $options['sgpb-fblike-like-url'];
78
+ $layout = $options['sgpb-fblike-layout'];
79
+ $shareButtonStatus = true;
80
+ if (!empty($options['sgpb-fblike-dont-show-share-button'])) {
81
+ $shareButtonStatus = false;
82
+ }
83
+
84
+ $scripts = $this->getScripts();
85
+ $buttonConfig = $this->getButtonConfig($shareUrl, $layout, $shareButtonStatus);
86
+ ob_start();
87
+ ?>
88
+ <div id="sg-facebook-like">
89
+ <div id="fb-root"></div>
90
+ <?php echo $buttonConfig; ?>
91
+ <?php echo $scripts; ?>
92
+ </div>
93
+ <?php
94
+ $content = ob_get_contents();
95
+ ob_get_clean();
96
+
97
+ return $content;
98
+ }
99
+
100
+ public function getPopupTypeContent()
101
+ {
102
+ $fbLikeContent = $this->getFblikeContent();
103
+ $popupContent = $this->getContent();
104
+ $popupContent .= $fbLikeContent;
105
+
106
+ return $popupContent;
107
+ }
108
+
109
+ public function getExtraRenderOptions()
110
+ {
111
+ return array();
112
+ }
113
+ }
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,89 +1,89 @@
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
- }
35
-
36
- public function getRemoveOptions()
37
- {
38
-
39
- // Where 1 mean this options must not show for this popup type
40
- $removeOptions = array(
41
- 'sgpb-reopen-after-form-submission' => 1,
42
- 'sgpb-background-image' => 1,
43
- 'sgpb-background-image-mode' => 1,
44
- 'sgpb-force-rtl' => 1,
45
- 'sgpb-content-padding' => 1
46
- );
47
- $parentOptions = parent::getRemoveOptions();
48
- if ($this->getType() != 'image') {
49
- return $parentOptions;
50
- }
51
-
52
- return $removeOptions + $parentOptions;
53
- }
54
-
55
- public function getPopupTypeMainView()
56
- {
57
- return array(
58
- 'filePath' => SG_POPUP_TYPE_MAIN_PATH.'image.php',
59
- 'metaboxTitle' => 'Image Popup Main Options'
60
- );
61
- }
62
-
63
- /**
64
- * It returns what the current post supports (for example: title, editor, etc...)
65
- *
66
- * @since 1.0.0
67
- *
68
- * @return array
69
- */
70
- public static function getPopupTypeSupports()
71
- {
72
- return array('title');
73
- }
74
-
75
- public function getPopupTypeContent()
76
- {
77
- $id = $this->getId();
78
- $imageUrl = $this->getOptionValue('sgpb-image-url');
79
-
80
- $imageAltText = AdminHelper::getImageAltTextByUrl($imageUrl);
81
-
82
- return '<img width="1" height="1" class="sgpb-preloaded-image-'.$id.'" alt="'.$imageAltText.'" src="'.$imageUrl.'" style="position:absolute;right:9999999999999px;">';
83
- }
84
-
85
- public function getExtraRenderOptions()
86
- {
87
- return array();
88
- }
89
- }
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
+ }
35
+
36
+ public function getRemoveOptions()
37
+ {
38
+
39
+ // Where 1 mean this options must not show for this popup type
40
+ $removeOptions = array(
41
+ 'sgpb-reopen-after-form-submission' => 1,
42
+ 'sgpb-background-image' => 1,
43
+ 'sgpb-background-image-mode' => 1,
44
+ 'sgpb-force-rtl' => 1,
45
+ 'sgpb-content-padding' => 1
46
+ );
47
+ $parentOptions = parent::getRemoveOptions();
48
+ if ($this->getType() != 'image') {
49
+ return $parentOptions;
50
+ }
51
+
52
+ return $removeOptions + $parentOptions;
53
+ }
54
+
55
+ public function getPopupTypeMainView()
56
+ {
57
+ return array(
58
+ 'filePath' => SG_POPUP_TYPE_MAIN_PATH.'image.php',
59
+ 'metaboxTitle' => 'Image Popup Main Options'
60
+ );
61
+ }
62
+
63
+ /**
64
+ * It returns what the current post supports (for example: title, editor, etc...)
65
+ *
66
+ * @since 1.0.0
67
+ *
68
+ * @return array
69
+ */
70
+ public static function getPopupTypeSupports()
71
+ {
72
+ return array('title');
73
+ }
74
+
75
+ public function getPopupTypeContent()
76
+ {
77
+ $id = $this->getId();
78
+ $imageUrl = $this->getOptionValue('sgpb-image-url');
79
+
80
+ $imageAltText = AdminHelper::getImageAltTextByUrl($imageUrl);
81
+
82
+ return '<img width="1" height="1" class="sgpb-preloaded-image-'.$id.'" alt="'.$imageAltText.'" src="'.$imageUrl.'" style="position:absolute;right:9999999999999px;">';
83
+ }
84
+
85
+ public function getExtraRenderOptions()
86
+ {
87
+ return array();
88
+ }
89
+ }
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,1723 +1,1723 @@
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
- $popupContent = wpautop($this->content);
183
- $editorContent = AdminHelper::checkEditorByPopupId($postId);
184
- if (!empty($editorContent)) {
185
- if (class_exists('Vc_Manager')) {
186
- $popupContent .= $editorContent;
187
- }
188
- else {
189
- $popupContent = $editorContent;
190
- }
191
- }
192
-
193
- return $popupContent;
194
- }
195
-
196
- public function setPostData($postData)
197
- {
198
- $this->postData = apply_filters('sgpbSavedPostData', $postData);
199
- }
200
-
201
- public function getPostData()
202
- {
203
- return $this->postData;
204
- }
205
-
206
- public function getPopupTypeContent()
207
- {
208
- return $this->getContent();
209
- }
210
-
211
- public function insertIntoSanitizedData($sanitizedData)
212
- {
213
- if (!empty($sanitizedData)) {
214
- $this->sanitizedData[$sanitizedData['name']] = $sanitizedData['value'];
215
- }
216
- }
217
-
218
- abstract public function getExtraRenderOptions();
219
-
220
- public function setSanitizedData($sanitizedData)
221
- {
222
- $this->sanitizedData = $sanitizedData;
223
- }
224
-
225
- public function getSanitizedData()
226
- {
227
- return $this->sanitizedData;
228
- }
229
-
230
- /**
231
- * Find popup and create this object
232
- *
233
- * @since 1.0.0
234
- *
235
- * @param object|int $popup
236
- *
237
- * @return object|false $obj
238
- */
239
- public static function find($popup, $args = array())
240
- {
241
- if (isset($_GET['sg_popup_preview_id'])) {
242
- $args['is-preview'] = true;
243
- }
244
- // If the popup is object get data from object otherwise we find needed data from WordPress functions
245
- if ($popup instanceof WP_Post) {
246
- $status = $popup->post_status;
247
- $title = $popup->post_title;
248
- $popupContent = $popup->post_content;
249
- $popupId = $popup->ID;
250
- }
251
- else {
252
- $popupId = $popup;
253
- $popupPost = get_post($popupId);
254
- if (empty($popupPost)) {
255
- return false;
256
- }
257
- $title = get_the_title($popupId);
258
- $status = get_post_status($popupId);
259
- $popupContent = $popupPost->post_content;
260
- }
261
- $allowedStatus = array('publish', 'draft');
262
-
263
- if (!empty($args['status'])) {
264
- $allowedStatus = $args['status'];
265
- }
266
-
267
- if (!isset($args['checkActivePopupType']) && !in_array($status, $allowedStatus)) {
268
- return $status;
269
- }
270
- $saveMode = '';
271
- global $post;
272
- if ((@is_preview() && $post->ID == $popupId) || isset($args['preview'])) {
273
- $saveMode = '_preview';
274
- }
275
- if (isset($args['is-preview'])) {
276
- $saveMode = '_preview';
277
- }
278
- if (isset($args['insidePopup']) && $args['insidePopup'] == 'on') {
279
- $saveMode = '';
280
- }
281
- $currentPost = get_post($popupId);
282
- $currentPostStatus = $currentPost->post_status;
283
- if ($currentPostStatus == 'draft') {
284
- $saveMode = '_preview';
285
- }
286
-
287
- $savedData = array();
288
- if (file_exists(dirname(__FILE__).'/PopupData.php')) {
289
- require_once(dirname(__FILE__).'/PopupData.php');
290
- $savedData = PopupData::getPopupDataById($popupId, $saveMode);
291
- }
292
- $savedData = apply_filters('sgpbPopupSavedData', $savedData);
293
-
294
- if (empty($savedData)) {
295
- return false;
296
- }
297
-
298
- $type = 'html';
299
- if (isset($savedData['sgpb-type'])) {
300
- $type = $savedData['sgpb-type'];
301
- }
302
-
303
- $popupClassName = self::getPopupClassNameFormType($type);
304
- $typePath = self::getPopupTypeClassPath($type);
305
- if (!file_exists($typePath.$popupClassName.'.php')) {
306
- return false;
307
- }
308
- require_once($typePath.$popupClassName.'.php');
309
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
310
-
311
- $obj = new $popupClassName();
312
- $obj->setId($popupId);
313
- $obj->setType($type);
314
- $obj->setTitle($title);
315
- $obj->setContent($popupContent);
316
-
317
- if (!empty($savedData['sgpb-target'][0])) {
318
- $obj->setTarget($savedData['sgpb-target'][0]);
319
- }
320
- unset($savedData['sgpb-target']);
321
- if (!empty($savedData['sgpb-events'][0])) {
322
- $events = self::shapeEventsToOneArray($savedData['sgpb-events'][0]);
323
- $obj->setEvents($events);
324
- }
325
- unset($savedData['sgpb-events']);
326
- if (!empty($savedData['sgpb-conditions'][0])) {
327
- $obj->setConditions($savedData['sgpb-conditions'][0]);
328
- }
329
- unset($savedData['sgpb-conditions']);
330
-
331
- $obj->setOptions($savedData);
332
-
333
- return $obj;
334
- }
335
-
336
- private static function shapeEventsToOneArray($events)
337
- {
338
- $eventsData = array();
339
- if (!empty($events)) {
340
- foreach ($events as $event) {
341
- if (empty($event['hiddenOption'])) {
342
- $eventsData[] = $event;
343
- continue;
344
- }
345
- $hiddenOptions = $event['hiddenOption'];
346
- unset($event['hiddenOption']);
347
- $eventsData[] = $event + $hiddenOptions;
348
- }
349
- }
350
-
351
- return apply_filters('sgpbEventsToOneArray', $eventsData);
352
- }
353
-
354
- public static function getPopupClassNameFormType($type)
355
- {
356
- $popupName = ucfirst(strtolower($type));
357
- $popupClassName = $popupName.'Popup';
358
-
359
- return apply_filters('sgpbPopupClassNameFromType', $popupClassName);
360
- }
361
-
362
- public static function getPopupTypeClassPath($type)
363
- {
364
- global $SGPB_POPUP_TYPES;
365
- $typePaths = $SGPB_POPUP_TYPES['typePath'];
366
-
367
- if (empty($typePaths[$type])) {
368
- return SG_POPUP_CLASSES_POPUPS_PATH;
369
- }
370
-
371
- return $typePaths[$type];
372
- }
373
-
374
- public function sanitizeValueByType($value, $type)
375
- {
376
- switch ($type) {
377
- case 'string':
378
- if (is_array($value)) {
379
- $sanitizedValue = $this->recursiveSanitizeTextField($value);
380
- }
381
- else {
382
- $sanitizedValue = htmlspecialchars($value);
383
- }
384
- break;
385
- case 'text':
386
- $sanitizedValue = htmlspecialchars($value);
387
- break;
388
- case 'array':
389
- $sanitizedValue = $this->recursiveSanitizeTextField($value);
390
- break;
391
- case 'email':
392
- $sanitizedValue = sanitize_email($value);
393
- break;
394
- case 'sgpb':
395
- $sanitizedValue = $this->recursiveHtmlSpecialchars($value);
396
- break;
397
- default:
398
- $sanitizedValue = sanitize_text_field($value);
399
- break;
400
- }
401
-
402
- return $sanitizedValue;
403
- }
404
-
405
- public function recursiveSanitizeTextField($array)
406
- {
407
- if (!is_array($array)) {
408
- return $array;
409
- }
410
-
411
- foreach ($array as $key => &$value) {
412
- if (is_array($value)) {
413
- $value = $this->recursiveSanitizeTextField($value);
414
- }
415
- else {
416
- /*get simple field type and do sanitization*/
417
- $defaultData = $this->getDefaultDataByName($key);
418
- if (empty($defaultData['type'])) {
419
- $defaultData['type'] = 'string';
420
- }
421
- $value = $this->sanitizeValueByType($value, $defaultData['type']);
422
- }
423
- }
424
-
425
- return $array;
426
- }
427
-
428
- public function recursiveHtmlSpecialchars($array)
429
- {
430
- if (!is_array($array)) {
431
- return $array;
432
- }
433
-
434
- foreach ($array as $key => &$value) {
435
- if (is_array($value)) {
436
- $value = $this->recursiveHtmlSpecialchars($value);
437
- }
438
- else {
439
- $value = htmlspecialchars($value);
440
- }
441
- }
442
-
443
- return $array;
444
- }
445
-
446
- public static function parsePopupDataFromData($data)
447
- {
448
- $popupData = array();
449
- $data = apply_filters('sgpbFilterOptionsBeforeSaving', $data);
450
-
451
- foreach ($data as $key => $value) {
452
- if (strpos($key, 'sgpb') === 0) {
453
- $popupData[$key] = $value;
454
- }
455
- if (is_array($value) && isset($value['name']) && strpos($value['name'], 'sgpb') === 0) {
456
- $popupData[$value['name']] = $value['value'];
457
- }
458
- else if (is_array($value) && isset($value['name']) && strpos($value['name'], 'post_ID') === 0) {
459
- $popupData['sgpb-post-id'] = $value['value'];
460
- }
461
- }
462
-
463
- return $popupData;
464
- }
465
-
466
- public static function create($data = array(), $saveMode = '', $firstTime = 0)
467
- {
468
- $obj = new static();
469
- $obj->setSaveMode($saveMode);
470
- $additionalData = $obj->addAdditionalSettings($data, $obj);
471
- $data = array_merge($data, $additionalData);
472
- $data = apply_filters('sgpbAdvancedOptionsDefaultValues', $data);
473
- foreach ($data as $name => $value) {
474
- if (strpos($name, 'sgpb') === 0) {
475
- $defaultData = $obj->getDefaultDataByName($name);
476
- if (empty($defaultData['type'])) {
477
- $defaultData['type'] = 'string';
478
- }
479
- $sanitizedValue = $obj->sanitizeValueByType($value, $defaultData['type']);
480
- $obj->insertIntoSanitizedData(array('name' => $name,'value' => $sanitizedValue));
481
- }
482
- }
483
-
484
- $obj->setSavedPopupById($data['sgpb-post-id']);
485
- $result = $obj->save();
486
-
487
- $result = apply_filters('sgpbPopupCreateResult', $result);
488
-
489
- if ($result) {
490
- return $obj;
491
- }
492
-
493
- return $result;
494
- }
495
-
496
- public function save()
497
- {
498
- $this->convertImagesToData();
499
- $data = $this->getSanitizedData();
500
- $popupId = $data['sgpb-post-id'];
501
-
502
- $this->setId($popupId);
503
-
504
- if (!empty($data['sgpb-target'])) {
505
- $this->setTarget($data['sgpb-target']);
506
- /*remove from popup options because it's useless to save it twice*/
507
- unset($data['sgpb-target']);
508
- }
509
- if (!empty($data['sgpb-conditions'])) {
510
- $this->setConditions($data['sgpb-conditions']);
511
- unset($data['sgpb-conditions']);
512
- }
513
- if (!empty($data['sgpb-events'])) {
514
- $this->setEvents($data['sgpb-events']);
515
- unset($data['sgpb-events']);
516
- }
517
- $data = $this->customScriptsSave($data);
518
- $this->setOptions($data);
519
-
520
- $targets = $this->targetSave();
521
- $events = $this->eventsSave();
522
- $options = $this->popupOptionsSave();
523
-
524
- return ($targets && $events && $options);
525
- }
526
-
527
- public function convertImagesToData()
528
- {
529
- $buttonImageData = '';
530
- $savedImageUrl = '';
531
- $savedContentBackgroundImageUrl = '';
532
- $contentBackgroundImageData = '';
533
-
534
- $data = $this->getSanitizedData();
535
- $buttonImageUrl = @$data['sgpb-button-image'];
536
- $contentBackgroundImageUrl = @$data['sgpb-background-image'];
537
-
538
- $savedPopup = $this->getSavedPopup();
539
-
540
- if (is_object($savedPopup)) {
541
- $buttonImageData = $savedPopup->getOptionvalue('sgpb-button-image-data');
542
- $savedImageUrl = $savedPopup->getOptionValue('sgpb-button-image');
543
- $contentBackgroundImageData = $savedPopup->getOptionValue('sgpb-background-image-data');
544
- $savedContentBackgroundImageUrl = $savedPopup->getOptionValue('sgpb-background-image');
545
- }
546
-
547
- if ($buttonImageUrl != $savedImageUrl) {
548
- $buttonImageData = AdminHelper::getImageDataFromUrl($buttonImageUrl, true);
549
- }
550
- if ($contentBackgroundImageUrl != $savedContentBackgroundImageUrl) {
551
- $contentBackgroundImageData = AdminHelper::getImageDataFromUrl($contentBackgroundImageUrl);
552
- }
553
-
554
- $data['sgpb-button-image-data'] = $buttonImageData;
555
- $data['sgpb-background-image-data'] = $contentBackgroundImageData;
556
-
557
- $data = apply_filters('sgpbConvertImagesToData', $data);
558
- $this->setSanitizedData($data);
559
- }
560
-
561
- private function customScriptsSave($data)
562
- {
563
- $popupId = $this->getId();
564
- $popupContent = $this->getContent();
565
-
566
- $defaultData = ConfigDataHelper::defaultData();
567
- $defaultDataJs = $defaultData['customEditorContent']['js']['helperText'];
568
- $defaultDataCss = $defaultData['customEditorContent']['css']['oldDefaultValue'];
569
-
570
- $finalData = array('js' => array(), 'css' => array());
571
- $alreadySavedData = get_post_meta($popupId, 'sg_popup_scripts', true);
572
-
573
- // get styles
574
- $finalData['css'] = $data['sgpb-css-editor'];
575
- $defaultDataCss = $defaultDataCss[0];
576
-
577
- $defaultDataCss = preg_replace('/\s/', '', $defaultDataCss);
578
- $temp = preg_replace('/\s/', '', $finalData['css']);
579
-
580
- unset($data['sgpb-css-editor']);
581
-
582
- if ($temp == $defaultDataCss) {
583
- unset($finalData['css']);
584
- }
585
-
586
- // get scripts
587
- foreach ($defaultDataJs as $key => $value) {
588
- if ($data['sgpb-'.$key] == '') {
589
- unset($data['sgpb-'.$key]);
590
- continue;
591
- }
592
- if ($key == 'ShouldOpen' || $key == 'ShouldClose') {
593
- $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
594
- continue;
595
- }
596
- $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
597
- unset($data['sgpb-'.$key]);
598
- }
599
-
600
- if ($alreadySavedData == $finalData) {
601
- return $data;
602
- }
603
-
604
- update_post_meta($popupId, 'sg_popup_scripts', $finalData);
605
-
606
- return $data;
607
- }
608
-
609
- private function targetSave()
610
- {
611
- global $SGPB_DATA_CONFIG_ARRAY;
612
- $saveMode = $this->getSaveMode();
613
- $popupId = $this->getId();
614
- $targetData = $this->getTarget();
615
- $conditionsData = $this->getConditions();
616
-
617
- $targetConfig = $SGPB_DATA_CONFIG_ARRAY['target'];
618
- $paramsData = $targetConfig['paramsData'];
619
- $attrs = $targetConfig['attrs'];
620
- $popupTarget = array();
621
- if (empty($targetData)) {
622
- return array();
623
- }
624
-
625
- foreach ($targetData as $groupId => $groupData) {
626
- foreach ($groupData as $ruleId => $ruleData) {
627
-
628
- if (empty($ruleData['value']) && !is_null($paramsData[$ruleData['param']])) {
629
- $targetData[$groupId][$ruleId]['value'] = '';
630
- }
631
- if (isset($ruleData['value']) && is_array($ruleData['value'])) {
632
- $valueAttrs = $attrs[$ruleData['param']]['htmlAttrs'];
633
- $postType = $valueAttrs['data-value-param'];
634
- $isNotPostType = '';
635
- if (isset($valueAttrs['isNotPostType'])) {
636
- $isNotPostType = $valueAttrs['isNotPostType'];
637
- }
638
-
639
- if (empty($valueAttrs['isNotPostType'])) {
640
- $isNotPostType = false;
641
- }
642
-
643
- /*
644
- * $isNotPostType => false must search inside post types post
645
- * $isNotPostType => true must save array data
646
- * */
647
- if (!$isNotPostType) {
648
- $args = array(
649
- 'post__in' => array_values($ruleData['value']),
650
- 'posts_per_page' => 100,
651
- 'post_type' => $postType
652
- );
653
-
654
- $searchResults = ConfigDataHelper::getPostTypeData($args);
655
-
656
- $targetData[$groupId][$ruleId]['value'] = $searchResults;
657
- }
658
- }
659
- }
660
- }
661
-
662
- $popupTarget['sgpb-target'] = $targetData;
663
- $popupTarget['sgpb-conditions'] = apply_filters('sgpbSaveConditions', $conditionsData);
664
-
665
- $alreadySavedTargets = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
666
- if ($alreadySavedTargets === $popupTarget) {
667
- return true;
668
- }
669
-
670
- $popupTarget = apply_filters('sgpbPopupTargetMetaData', $popupTarget);
671
-
672
- return update_post_meta($popupId, 'sg_popup_target'.$saveMode, $popupTarget);
673
- }
674
-
675
- private function eventsSave()
676
- {
677
- global $SGPB_DATA_CONFIG_ARRAY;
678
-
679
- $eventsData = $this->getEvents();
680
- $popupId = $this->getId();
681
- $saveMode = $this->getSaveMode();
682
- $popupEvents = array();
683
- $eventsFromPopup = array();
684
-
685
- foreach ($eventsData as $groupId => $groupData) {
686
- $currentRuleData = array();
687
- foreach ($groupData as $ruleId => $ruleData) {
688
-
689
- $hiddenOptions = array();
690
- $currentData = array();
691
- foreach ($ruleData as $name => $value) {
692
- if ($name == 'param' || $name == 'value' || $name == 'operator') {
693
- $currentData[$name] = $value;
694
- }
695
- else {
696
- $hiddenOptions[$name] = $value;
697
- }
698
- }
699
- $currentData['hiddenOption'] = $hiddenOptions;
700
- $currentRuleData[$ruleId] = $currentData;
701
- }
702
- $eventsFromPopup[$groupId] = $currentRuleData;
703
- }
704
-
705
- $popupEvents['formPopup'] = $eventsFromPopup;
706
- $alreadySavedEvents = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
707
- if ($alreadySavedEvents === $eventsFromPopup) {
708
- return true;
709
- }
710
-
711
- $eventsFromPopup = apply_filters('sgpbPopupEventsMetadata', $eventsFromPopup);
712
-
713
- return update_post_meta($popupId, 'sg_popup_events'.$saveMode, $eventsFromPopup);
714
- }
715
-
716
- private function popupOptionsSave()
717
- {
718
- $popupOptions = $this->getOptions();
719
- $popupOptions = apply_filters('sgpbSavePopupOptions', $popupOptions);
720
- //special code added for "Behavior After Special Events" section
721
- //todo: remove in the future if possible
722
- $specialBehaviors = array();
723
- if (!empty($popupOptions['sgpb-behavior-after-special-events'])) {
724
- $specialBehaviors = $popupOptions['sgpb-behavior-after-special-events'];
725
- }
726
- if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
727
- foreach ($specialBehaviors as $groupId => $groupRow) {
728
- foreach ($groupRow as $ruleId => $ruleRow) {
729
- if (!empty($ruleRow['operator']) && $ruleRow['operator'] == 'open-popup') {
730
- $args = array(
731
- 'post__in' => array($ruleRow['value']),
732
- 'posts_per_page' => 10,
733
- 'post_type' => SG_POPUP_POST_TYPE
734
- );
735
-
736
- $searchResults = ConfigDataHelper::getPostTypeData($args);
737
- $popupOptions['sgpb-behavior-after-special-events'][$groupId][$ruleId]['value'] = $searchResults;
738
- }
739
- }
740
- }
741
- }
742
-
743
- $popupId = $this->getId();
744
- $saveMode = $this->getSaveMode();
745
-
746
- $alreadySavedOptions = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
747
- if ($alreadySavedOptions === $popupOptions) {
748
- return true;
749
- }
750
-
751
- $popupOptions = apply_filters('sgpbPopupSavedOptionsMetaData', $popupOptions);
752
-
753
- return update_post_meta($popupId, 'sg_popup_options'.$saveMode, $popupOptions);
754
- }
755
-
756
- public function getOptionValue($optionName, $forceDefaultValue = false)
757
- {
758
- require_once(dirname(__FILE__).'/PopupData.php');
759
- $savedData = PopupData::getPopupDataById($this->getId());
760
- $this->setPostData($savedData);
761
-
762
- return $this->getOptionValueFromSavedData($optionName, $forceDefaultValue);
763
- }
764
-
765
- public function getOptionValueFromSavedData($optionName, $forceDefaultValue = false)
766
- {
767
- $defaultData = $this->getDefaultDataByName($optionName);
768
- $savedData = $this->getPostData();
769
-
770
- $optionValue = null;
771
-
772
- if (empty($defaultData['type'])) {
773
- $defaultData['type'] = 'string';
774
- }
775
-
776
- if (!empty($savedData)) { //edit mode
777
- if (isset($savedData[$optionName])) { //option exists in the database
778
- $optionValue = $savedData[$optionName];
779
- }
780
- /* if it's a checkbox, it may not exist in the db
781
- * if we don't care about it's existance, return empty string
782
- * otherwise, go for it's default value
783
- */
784
- else if ($defaultData['type'] == 'checkbox' && !$forceDefaultValue) {
785
- $optionValue = '';
786
- }
787
- }
788
-
789
- if ($optionValue === null && !empty($defaultData['defaultValue'])) {
790
- $optionValue = $defaultData['defaultValue'];
791
- }
792
-
793
- if ($defaultData['type'] == 'checkbox') {
794
- $optionValue = $this->boolToChecked($optionValue);
795
- }
796
-
797
- if ($defaultData['type'] == 'number' && $optionValue == 0) {
798
- $optionValue = 0;
799
- }
800
-
801
- return $optionValue;
802
- }
803
-
804
- public static function getSavedData($popupId, $saveMode = '')
805
- {
806
- $popupSavedData = array();
807
- $events = self::getEventsDataById($popupId, $saveMode);
808
- $targetData = self::getTargetDataById($popupId, $saveMode);
809
-
810
- if (!empty($events)) {
811
- $popupSavedData['sgpb-events'] = self::getEventsDataById($popupId, $saveMode);
812
- }
813
- if (!empty($targetData)) {
814
- if (!empty($targetData['sgpb-target'])) {
815
- $popupSavedData['sgpb-target'] = $targetData['sgpb-target'];
816
- }
817
- if (!empty($targetData['sgpb-conditions'])) {
818
- // for the after x pages option backward compatibility
819
- $targetData['sgpb-conditions'] = apply_filters('sgpbAdvancedTargetingSavedData', $targetData['sgpb-conditions'], $popupId);
820
- $popupSavedData['sgpb-conditions'] = $targetData['sgpb-conditions'];
821
- }
822
- }
823
-
824
- $popupOptions = self::getPopupOptionsById($popupId, $saveMode);
825
- if (is_array($popupOptions) && is_array($popupSavedData)) {
826
- $popupSavedData = array_merge($popupSavedData, $popupOptions);
827
- }
828
-
829
- return $popupSavedData;
830
- }
831
-
832
- public static function getEventsDataById($popupId, $saveMode = '')
833
- {
834
- $eventsData = array();
835
- if (get_post_meta($popupId, 'sg_popup_events'.$saveMode, true)) {
836
- $eventsData = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
837
- }
838
-
839
- return $eventsData;
840
- }
841
-
842
- public static function getTargetDataById($popupId, $saveMode = '')
843
- {
844
- $targetData = array();
845
-
846
- if (get_post_meta($popupId, 'sg_popup_target'.$saveMode, true)) {
847
- $targetData = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
848
- }
849
-
850
- return $targetData;
851
- }
852
-
853
- public static function getPopupOptionsById($popupId, $saveMode = '')
854
- {
855
- $currentPost = get_post($popupId);
856
-
857
- if (!empty($currentPost) && $currentPost->post_status == 'draft') {
858
- $saveMode = '_preview';
859
- }
860
- $optionsData = array();
861
- if (get_post_meta($popupId, 'sg_popup_options'.$saveMode, true)) {
862
- $optionsData = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
863
- }
864
-
865
- return $optionsData;
866
- }
867
-
868
- public function getDefaultDataByName($optionName)
869
- {
870
- global $SGPB_OPTIONS;
871
- if (empty($SGPB_OPTIONS)) {
872
- return array();
873
- }
874
-
875
- foreach ($SGPB_OPTIONS as $option) {
876
- if ($option['name'] == $optionName) {
877
- return $option;
878
- }
879
- }
880
-
881
- return array();
882
- }
883
-
884
- /**
885
- * Get option default option value
886
- *
887
- * @param string $optionName
888
- *
889
- * @since 1.0.0
890
- *
891
- * @return string
892
- *
893
- */
894
- public function getOptionDefaultValue($optionName)
895
- {
896
- // return config data array by name
897
- $optionData = $this->getDefaultDataByName($optionName);
898
-
899
- if (empty($optionData)) {
900
- return '';
901
- }
902
-
903
- return $optionData['defaultValue'];
904
- }
905
-
906
- /**
907
- * Changing default options form changing options by name
908
- *
909
- * @since 1.0.0
910
- *
911
- * @param array $defaultOptions
912
- * @param array $changingOptions
913
- *
914
- * @return array $defaultOptions
915
- */
916
- public function changeDefaultOptionsByNames($defaultOptions, $changingOptions)
917
- {
918
- if (empty($defaultOptions) || empty($changingOptions)) {
919
- return $defaultOptions;
920
- }
921
- $changingOptionsNames = array_keys($changingOptions);
922
-
923
- foreach ($defaultOptions as $key => $defaultOption) {
924
- $defaultOptionName = $defaultOption['name'];
925
- if (in_array($defaultOptionName, $changingOptionsNames)) {
926
- $defaultOptions[$key] = $changingOptions[$defaultOptionName];
927
- }
928
- }
929
-
930
- return $defaultOptions;
931
- }
932
-
933
- /**
934
- * Returns separate popup types Free or Pro
935
- *
936
- * @since 2.5.6
937
- *
938
- * @return array $popupTypesObj
939
- */
940
- public static function getPopupTypes()
941
- {
942
- global $SGPB_POPUP_TYPES;
943
- $popupTypesObj = array();
944
- $popupTypes = $SGPB_POPUP_TYPES['typeName'];
945
-
946
- foreach ($popupTypes as $popupType => $level) {
947
-
948
- if (empty($level)) {
949
- $level = SGPB_POPUP_PKG_FREE;
950
- }
951
-
952
- $popupTypeObj = new PopupType();
953
- $popupTypeObj->setName($popupType);
954
- $popupTypeObj->setAccessLevel($level);
955
-
956
- if (SGPB_POPUP_PKG >= $level) {
957
- $popupTypeObj->setAvailable(true);
958
- }
959
- $popupTypesObj[] = $popupTypeObj;
960
- }
961
-
962
- return $popupTypesObj;
963
- }
964
-
965
- public static function savePopupsFromContentClasses($content, $post)
966
- {
967
- $postId = $post->ID;
968
- $clickClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-id-');
969
- $targetData = array();
970
- $eventsData = array();
971
-
972
- if (!empty($clickClassIds)) {
973
- foreach ($clickClassIds as $id) {
974
- $id = apply_filters('sgpbConvertedPopupId', $id);
975
- if (empty($eventsData[$postId][$id])) {
976
- $eventsData[$postId][$id] = array('click');
977
- }
978
- else {
979
- $eventsData[$postId][$id][] = 'click';
980
- }
981
-
982
- if (empty($targetData[$postId])) {
983
- $targetData[$postId] = array($id);
984
- }
985
- else {
986
- $targetData[$postId][] = $id;
987
- }
988
- }
989
- }
990
-
991
- $iframeClassIs = self::getStringNextNumbersByReg($content, 'sg-iframe-popup-');
992
-
993
- if (!empty($iframeClassIs)) {
994
- foreach ($iframeClassIs as $id) {
995
- $id = apply_filters('sgpbConvertedPopupId', $id);
996
- $popupObj = self::find($id);
997
-
998
- if (empty($popupObj)) {
999
- continue;
1000
- }
1001
-
1002
- // this event should work only for iframe popup type
1003
- if ($popupObj->getType() != 'iframe') {
1004
- continue;
1005
- }
1006
-
1007
- if (empty($eventsData[$postId][$id])) {
1008
- $eventsData[$postId][$id] = array('iframe');
1009
- }
1010
- else {
1011
- $eventsData[$postId][$id][] = 'iframe';
1012
- }
1013
-
1014
- if (empty($targetData[$postId])) {
1015
- $targetData[$postId] = array($id);
1016
- }
1017
- else {
1018
- $targetData[$postId][] = $id;
1019
- }
1020
- }
1021
- }
1022
-
1023
- $confirmClassIds = self::getStringNextNumbersByReg($content, 'sg-confirm-popup-');
1024
-
1025
- if (!empty($confirmClassIds)) {
1026
- foreach ($confirmClassIds as $id) {
1027
- $id = apply_filters('sgpbConvertedPopupId', $id);
1028
- if (empty($eventsData[$postId][$id])) {
1029
- $eventsData[$postId][$id] = array('confirm');
1030
- }
1031
- else {
1032
- $eventsData[$postId][$id][] = 'confirm';
1033
- }
1034
-
1035
- if (empty($targetData[$postId])) {
1036
- $targetData[$postId] = array($id);
1037
- }
1038
- else {
1039
- $targetData[$postId][] = $id;
1040
- }
1041
- }
1042
- }
1043
-
1044
- $hoverClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-hover-');
1045
-
1046
- if (!empty($hoverClassIds)) {
1047
- foreach ($hoverClassIds as $id) {
1048
- $id = apply_filters('sgpbConvertedPopupId', $id);
1049
- if (empty($eventsData[$postId][$id])) {
1050
- $eventsData[$postId][$id] = array('hover');
1051
- }
1052
- else {
1053
- $eventsData[$postId][$id][] = 'hover';
1054
- }
1055
-
1056
- if (empty($targetData[$postId])) {
1057
- $targetData[$postId] = array($id);
1058
- }
1059
- else {
1060
- $targetData[$postId][] = $id;
1061
- }
1062
- }
1063
- }
1064
-
1065
- $targetData = apply_filters('sgpbPopupTargetData', $targetData);
1066
- $eventsData = apply_filters('sgpbPopupEventsData', $eventsData);
1067
-
1068
- self::saveToTargetFromPage($targetData);
1069
- self::saveToEventsFromPage($eventsData);
1070
- }
1071
-
1072
- public static function getStringNextNumbersByReg($content, $key)
1073
- {
1074
- $result = array();
1075
- preg_match_all("/(?<=$key)(\d+)/", $content, $ids);
1076
-
1077
- if (!empty($ids[0])) {
1078
- $result = $ids[0];
1079
- }
1080
-
1081
- return $result;
1082
- }
1083
-
1084
- private static function saveToTargetAndEvents($popupsShortcodsInPostPage, $postId)
1085
- {
1086
- if (empty($popupsShortcodsInPostPage)) {
1087
- return false;
1088
- }
1089
- $customEvents = array();
1090
- $customPopups = array();
1091
-
1092
- foreach ($popupsShortcodsInPostPage as $shortcodesData) {
1093
- $popupId = apply_filters('sgpbConvertedPopupId', $shortcodesData['id']);
1094
-
1095
- $args = array(
1096
- 'post_type' => SG_POPUP_POST_TYPE,
1097
- 'post__in' => array($popupId)
1098
- );
1099
- $postById = ConfigDataHelper::getPostTypeData($args);
1100
- //When target data does not exist
1101
- if (empty($postById)) {
1102
- continue;
1103
- }
1104
-
1105
- // collect custom inserted popups
1106
- if (empty($customPopups[$postId])) {
1107
- $customPopups[$postId] = array($popupId);
1108
- }
1109
- else {
1110
- $customPopups[$postId][] = $popupId;
1111
- }
1112
-
1113
- // collect custom inserted popups events
1114
- if (empty($shortcodesData['event'])) {
1115
- $eventName = 'onload';
1116
- }
1117
- else {
1118
- $eventName = $shortcodesData['event'];
1119
- }
1120
-
1121
- if ($eventName == 'onload') {
1122
- $eventName = 'attr'.$eventName;
1123
- }
1124
- $currentEventData = array(
1125
- 'param' => $eventName
1126
- );
1127
-
1128
- if (empty($customEvents[$postId][$popupId])) {
1129
- $customEvents[$postId][$popupId] = array($currentEventData);
1130
- }
1131
- else {
1132
- $customEvents[$postId][$popupId][] = $currentEventData;
1133
- }
1134
- }
1135
-
1136
- self::saveToTargetFromPage($customPopups);
1137
- self::saveToEventsFromPage($customEvents);
1138
-
1139
- return true;
1140
- }
1141
-
1142
- public static function getPostPopupCustomEvent($postId, $popupId)
1143
- {
1144
- $events = array();
1145
-
1146
- $customEventsData = self::getCustomInsertedPopupEventsByPostId($postId);
1147
-
1148
- if (!empty($customEventsData[$popupId])) {
1149
- $events = $customEventsData[$popupId];
1150
- }
1151
-
1152
- return $events;
1153
- }
1154
-
1155
- /**
1156
- * Save popup to custom events from pages
1157
- *
1158
- * @since 1.0.0
1159
- *
1160
- * @param array $customEvents
1161
- *
1162
- * @return bool
1163
- *
1164
- */
1165
- public static function saveToEventsFromPage($customEvents)
1166
- {
1167
- if (empty($customEvents)) {
1168
- return false;
1169
- }
1170
-
1171
- foreach ($customEvents as $postId => $popupsData) {
1172
- $savedCustomEvents = self::getCustomInsertedPopupEventsByPostId($postId);
1173
- $result = AdminHelper::arrayMergeSameKeys($popupsData, $savedCustomEvents);
1174
-
1175
- if (!$result) {
1176
- return $result;
1177
- }
1178
- update_post_meta($postId, 'sgpb_popup_events_custom', $result);
1179
- }
1180
-
1181
- return true;
1182
- }
1183
-
1184
- public static function getCustomInsertedPopupEventsByPostId($postId)
1185
- {
1186
- $eventsData = array();
1187
- $postMetaData = get_post_meta($postId, 'sgpb_popup_events_custom', true);
1188
-
1189
- if (!empty($postMetaData)) {
1190
- $eventsData = $postMetaData;
1191
- }
1192
-
1193
- return $eventsData;
1194
- }
1195
-
1196
- /**
1197
- * Save popup to custom targets from pages
1198
- *
1199
- * @since 1.0.0
1200
- *
1201
- * @param array $customPopups
1202
- *
1203
- * @return void
1204
- *
1205
- */
1206
- public static function saveToTargetFromPage($customPopups)
1207
- {
1208
- if (!empty($customPopups)) {
1209
- foreach ($customPopups as $postId => $popups) {
1210
- $alreadySavedPopups = self::getCustomInsertedDataByPostId($postId);
1211
- $popups = array_merge($popups, $alreadySavedPopups);
1212
- update_post_meta($postId, 'sg_popup_target_custom', $popups);
1213
- }
1214
- }
1215
- }
1216
-
1217
- /**
1218
- * Get popup custom targes form saved data
1219
- *
1220
- * @since 1.0.0
1221
- *
1222
- * @param int $postId
1223
- *
1224
- * @return array $postData
1225
- */
1226
- public static function getCustomInsertedDataByPostId($postId)
1227
- {
1228
- $postData = array();
1229
- $postMetaData = get_post_meta($postId, 'sg_popup_target_custom');
1230
-
1231
- if (!empty($postMetaData[0])) {
1232
- $postData = $postMetaData[0];
1233
- }
1234
-
1235
- return $postData;
1236
- }
1237
-
1238
- public static function getPopupShortcodeMatchesFromContent($content)
1239
- {
1240
- $result = false;
1241
- $pattern = get_shortcode_regex();
1242
-
1243
- if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1244
- && !empty($matches)
1245
- && is_array($matches)
1246
- && array_key_exists( 2, $matches )
1247
- && in_array('sg_popup', $matches[2])
1248
- )
1249
- {
1250
- $result = $matches;
1251
- }
1252
-
1253
- return $result;
1254
- }
1255
-
1256
- public static function renderPopupContentShortcode($content, $popupId, $event, $args)
1257
- {
1258
- ob_start();
1259
- $wrap = 'a';
1260
- if (!empty($args['wrap'])) {
1261
- if ($args['wrap'] == $wrap) {
1262
- $args['href'] = 'javascript:void(0)';
1263
- }
1264
- $wrap = $args['wrap'];
1265
- }
1266
- unset($args['wrap']);
1267
- unset($args['event']);
1268
- unset($args['id']);
1269
- $attr = AdminHelper::createAttrs($args);
1270
- ?>
1271
- <<?php echo $wrap; ?>
1272
- <?php if ($wrap == 'a') : ?>
1273
- href="javascript:void(0)"
1274
- <?php endif ?>
1275
- class="sg-show-popup <?php echo 'sgpb-popup-id-'.$popupId; ?>"
1276
- data-sgpbpopupid="<?php echo esc_attr($popupId); ?>"
1277
- data-popup-event="<?php echo $event; ?>"
1278
- <?php echo $attr; ?>>
1279
- <?php echo $content; ?>
1280
- </<?php echo $wrap; ?>>
1281
- <?php
1282
-
1283
- $shortcodeContent = ob_get_contents();
1284
- ob_get_clean();
1285
-
1286
- return $shortcodeContent;
1287
- }
1288
-
1289
- private static function collectInsidePopupShortcodes($content)
1290
- {
1291
- $pattern = get_shortcode_regex();
1292
- $options = array();
1293
- if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1294
- && !empty($matches)
1295
- && is_array($matches)
1296
- && array_key_exists( 2, $matches )
1297
- && in_array('sg_popup', $matches[2])
1298
- )
1299
- {
1300
- foreach ($matches[0] as $key => $value) {
1301
- //return current shortcode all attrs as assoc array
1302
- $attrs = shortcode_parse_atts($matches[3][$key]);
1303
- $currentAttrs = array();
1304
- if (!empty($attrs['id'])) {
1305
- $currentAttrs['id'] = $attrs['id'];
1306
- }
1307
- if (!empty($attrs['insidepopup'])) {
1308
- $currentAttrs['insidepopup'] = $attrs['insidepopup'];
1309
- }
1310
- if (empty($attrs['insidepopup']) || (!empty($attrs['insidepopup']) && $attrs['insidepopup'] != 'on')) {
1311
- continue;
1312
- }
1313
-
1314
- $options[$currentAttrs['id']] = $value;
1315
- }
1316
- }
1317
-
1318
- return apply_filters('sgpbPopupInsideShortcodes', $options);
1319
- }
1320
-
1321
- /**
1322
- * Collect all popups by taxonomy slug
1323
- *
1324
- * @since 1.0.0
1325
- *
1326
- * @param string $popupTermSlug category slug name
1327
- *
1328
- * @return array $popupIds random popups id
1329
- *
1330
- */
1331
- public static function getPopupsByTermSlug($popupTermSlug)
1332
- {
1333
- $popupIds = array();
1334
-
1335
- $termPopups = get_transient(SGPB_TRANSIENT_POPUPS_TERMS);
1336
- if ($termPopups === false) {
1337
- $termPopups = get_posts(
1338
- array(
1339
- 'post_type' => 'popupbuilder',
1340
- 'numberposts' => -1,
1341
- 'tax_query' => array(
1342
- array(
1343
- 'taxonomy' => SG_POPUP_CATEGORY_TAXONOMY,
1344
- 'field' => 'slug',
1345
- 'terms' => $popupTermSlug
1346
- )
1347
- )
1348
- )
1349
- );
1350
- set_transient(SGPB_TRANSIENT_POPUPS_TERMS, $termPopups, SGPB_TRANSIENT_TIMEOUT_WEEK);
1351
- }
1352
-
1353
- if (empty($termPopups)) {
1354
- return $popupIds;
1355
- }
1356
-
1357
- foreach ($termPopups as $termPopup) {
1358
- $popupIds[] = $termPopup->ID;
1359
- }
1360
-
1361
- return $popupIds;
1362
- }
1363
-
1364
- public function boolToChecked($var)
1365
- {
1366
- return ($var?'checked':'');
1367
- }
1368
-
1369
- /**
1370
- * Delete custom inserted data
1371
- *
1372
- * @since 1.0.0
1373
- *
1374
- * @param int $postId current post page id
1375
- *
1376
- * @return void
1377
- *
1378
- */
1379
- public static function deletePostCustomInsertedData($postId)
1380
- {
1381
- delete_post_meta($postId, 'sg_popup_target_custom');
1382
- }
1383
-
1384
- /**
1385
- * Delete custom inserted events
1386
- *
1387
- * @since 1.0.0
1388
- *
1389
- * @param int $postId current post page id
1390
- *
1391
- * @return void
1392
- *
1393
- */
1394
- public static function deletePostCustomInsertedEvents($postId)
1395
- {
1396
- delete_post_meta($postId, 'sgpb_popup_events_custom');
1397
- }
1398
-
1399
- /**
1400
- * If popup Type does not have getPopupTypeOptions method
1401
- * it's tell popup does not have custom options
1402
- *
1403
- * @since 1.0.0
1404
- *
1405
- * @return bool
1406
- *
1407
- */
1408
- public function getPopupTypeOptionsView()
1409
- {
1410
- return false;
1411
- }
1412
-
1413
- /**
1414
- * If popup Type does not have getPopupTypeOptions method
1415
- * it's tell popup does not have custom options
1416
- *
1417
- * @since 1.0.0
1418
- *
1419
- * @return bool
1420
- *
1421
- */
1422
- public function getPopupTypeMainView()
1423
- {
1424
- return false;
1425
- }
1426
-
1427
- /**
1428
- * Remove popup option from admin view by option name
1429
- *
1430
- * @since 1.0.0
1431
- *
1432
- * @return array $removedOptions
1433
- *
1434
- */
1435
- public function getRemoveOptions()
1436
- {
1437
- $removeOptions = array();
1438
-
1439
- return apply_filters('sgpbRemoveOptions', $removeOptions);
1440
- }
1441
-
1442
- public static function createPopupTypeObjById($popupId)
1443
- {
1444
- global $SGPB_POPUP_TYPES;
1445
- $typePath = '';
1446
- $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
1447
- if (empty($popupOptionsData)) {
1448
- return false;
1449
- }
1450
- $popupType = $popupOptionsData['sgpb-type'];
1451
- $popupName = ucfirst(strtolower($popupType));
1452
- $popupClassName = $popupName.'Popup';
1453
-
1454
- if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
1455
- $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
1456
- }
1457
-
1458
- if (!file_exists($typePath.$popupClassName.'.php')) {
1459
- wp_die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
1460
- }
1461
- require_once($typePath.$popupClassName.'.php');
1462
-
1463
- $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
1464
- $popupTypeObj = new $popupClassName();
1465
- $popupTypeObj->setId($popupId);
1466
-
1467
- return $popupTypeObj;
1468
- }
1469
-
1470
- /**
1471
- * if child class does not have this function we call parent function to not get any errors
1472
- *
1473
- * @since 1.0.0
1474
- *
1475
- * @return array
1476
- *
1477
- */
1478
- public static function getTablesSql()
1479
- {
1480
- return array();
1481
- }
1482
-
1483
- /**
1484
- * if child class does not have this function we call parent function to not get any errors
1485
- *
1486
- * @since 1.0.0
1487
- *
1488
- * @return array
1489
- *
1490
- */
1491
- public static function getTableNames()
1492
- {
1493
- return array();
1494
- }
1495
-
1496
- /**
1497
- *
1498
- * Get WordPress localization name
1499
- *
1500
- * @since 1.0.0
1501
- *
1502
- * @return string
1503
- *
1504
- */
1505
- public function getSiteLocale()
1506
- {
1507
- $locale = get_bloginfo('language');
1508
- $locale = str_replace('-', '_', $locale);
1509
-
1510
- return $locale;
1511
- }
1512
-
1513
- public function addAdditionalSettings($postData = array(), $obj = null)
1514
- {
1515
- return array();
1516
- }
1517
-
1518
- public function allowToLoad()
1519
- {
1520
- global $post;
1521
-
1522
- $popupChecker = PopupChecker::instance();
1523
- $loadableModes = $popupChecker->isLoadable($this, $post);
1524
- $this->setLoadableModes($loadableModes);
1525
-
1526
- return ($loadableModes['attr_event'] || $loadableModes['option_event']);
1527
- }
1528
-
1529
- public static function getAllPopups($filters = array())
1530
- {
1531
- $args = array(
1532
- 'post_type' => SG_POPUP_POST_TYPE
1533
- );
1534
- $allPopups = array();
1535
- $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1536
-
1537
- if (empty($allPostData)) {
1538
- return $allPopups;
1539
- }
1540
-
1541
- foreach ($allPostData->posts as $postData) {
1542
- if (empty($postData)) {
1543
- continue;
1544
- }
1545
-
1546
- $popup = self::find($postData->ID, $args);
1547
- if (empty($popup) || !($popup instanceof SGPopup)) {
1548
- continue;
1549
- }
1550
- $type = @$popup->getType();
1551
-
1552
- if (isset($filters['type'])) {
1553
- if (is_array($filters['type'])) {
1554
- if (!in_array($type, $filters['type'])) {
1555
- continue;
1556
- }
1557
- }
1558
- else if ($type != $filters['type']) {
1559
- continue;
1560
- }
1561
- }
1562
- $allPopups[] = $popup;
1563
- }
1564
-
1565
- return $allPopups;
1566
- }
1567
-
1568
- public function getPopupsIdAndTitle()
1569
- {
1570
- $allPopups = SGPopup::getAllPopups();
1571
- $popupIdTitles = array();
1572
-
1573
- if (empty($allPopups)) {
1574
- return $popupIdTitles;
1575
- }
1576
- $currentPopupId = $this->getId();
1577
-
1578
- foreach ($allPopups as $popup) {
1579
- if (empty($popup)) {
1580
- continue;
1581
- }
1582
- $id = $popup->getId();
1583
-
1584
- if ($id == $currentPopupId) {
1585
- continue;
1586
- }
1587
-
1588
- $title = $popup->getTitle();
1589
- $type = $popup->getType();
1590
-
1591
- $popupIdTitles[$id] = $title.' - '.$type;
1592
- }
1593
-
1594
- return $popupIdTitles;
1595
- }
1596
-
1597
- public function getSubPopupObj()
1598
- {
1599
- $subPopups = array();
1600
- $options = $this->getOptions();
1601
-
1602
- $specialBehaviors = @$options['sgpb-behavior-after-special-events'];
1603
- if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
1604
- foreach ($specialBehaviors as $behavior) {
1605
- foreach ($behavior as $row) {
1606
- if (!empty($row['param']) && $row['param'] == SGPB_CONTACT_FORM_7_BEHAVIOR_KEY) {
1607
- if (!empty($row['operator']) && $row['operator'] == 'open-popup') {
1608
- if (!empty($row['value'])) {
1609
- $popupId = key($row['value']);
1610
- $subPopupObj = self::find((int)$popupId);
1611
- if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
1612
- $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
1613
- $subPopups[] = $subPopupObj;
1614
- }
1615
- }
1616
- }
1617
- }
1618
- }
1619
- }
1620
- }
1621
-
1622
- return $subPopups;
1623
- }
1624
-
1625
- public static function doInsideShortcode($insideShortcode)
1626
- {
1627
- return do_shortcode($insideShortcode);
1628
- }
1629
-
1630
- public function popupShortcodesInsidePopup()
1631
- {
1632
- $popups = array();
1633
- $args = array('insidePopup' => 'on');
1634
- $popupContent = $this->getContent();
1635
- $parentTarget = $this->getTarget();
1636
- $insidePopupShortcodes = self::collectInsidePopupShortcodes($popupContent);
1637
- if (empty($insidePopupShortcodes)) {
1638
- return $popups;
1639
- }
1640
- foreach ($insidePopupShortcodes as $insidePopupId => $insidePopupShortcode) {
1641
- $insidePopupId = (int)$insidePopupId;
1642
- if (!$insidePopupId) {
1643
- continue;
1644
- }
1645
- // true = find inside popup
1646
- $insidePopup = self::find($insidePopupId, $args);
1647
- if (empty($insidePopup) || $insidePopup == 'trash' || $insidePopup == 'inherit') {
1648
- continue;
1649
- }
1650
- $events = array('insideclick');
1651
- $insidePopup->setEvents($events);
1652
- $popups[$insidePopupId] = $insidePopup;
1653
- }
1654
-
1655
- $popupContent = self::doInsideShortcode($popupContent);
1656
- $this->setContent($popupContent);
1657
-
1658
- return $popups;
1659
- }
1660
-
1661
- public function getPopupOpeningCountById($popupId)
1662
- {
1663
- global $wpdb;
1664
-
1665
- $allCount = 0;
1666
- $popupsCounterData = get_option('SgpbCounter');
1667
- $popupCountFromAnalyticsData = 0;
1668
- $tableName = $wpdb->prefix.'sgpb_analytics';
1669
- if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
1670
- $popupCountFromAnalyticsData = self::getAnalyticsDataByPopupId($popupId);
1671
- }
1672
- if (isset($popupsCounterData[$popupId])) {
1673
- $allCount += $popupsCounterData[$popupId];
1674
- }
1675
- $allCount += $popupCountFromAnalyticsData;
1676
-
1677
- return $allCount;
1678
- }
1679
-
1680
- public static function getAnalyticsDataByPopupId($popupId)
1681
- {
1682
- global $wpdb;
1683
- // 7, 12, 13 => exclude close, subscription success, contact success events
1684
- $stmt = $wpdb->prepare('SELECT COUNT(*) FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
1685
- $popupAnalyticsData = $wpdb->get_var($stmt);
1686
- return $popupAnalyticsData;
1687
- }
1688
-
1689
- public static function deleteAnalyticsDataByPopupId($popupId)
1690
- {
1691
- global $wpdb;
1692
- $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13) LIMIT 100', $popupId);
1693
- $wpdb->query($prepareSql);
1694
- }
1695
-
1696
- public static function getActivePopupsQueryString()
1697
- {
1698
- $activePopupsQuery = '';
1699
- $args = array(
1700
- 'post_type' => SG_POPUP_POST_TYPE,
1701
- 'post_status' => array('trash', 'publish')
1702
- );
1703
- if (!class_exists('ConfigDataHelper')) {
1704
- return $activePopupsQuery;
1705
- }
1706
- $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1707
- $args['checkActivePopupType'] = true;
1708
- $allPopups = $allPostData->posts;
1709
- foreach ($allPopups as $post) {
1710
- $id = $post->ID;
1711
- $popup = self::find($id, $args);
1712
- if (empty($popup)) {
1713
- $activePopupsQuery .= $id.', ';
1714
- }
1715
- }
1716
- if ($activePopupsQuery != '') {
1717
- $activePopupsQuery = ' AND ID NOT IN ('.$activePopupsQuery.')';
1718
- $activePopupsQuery = str_replace(', )', ') ', $activePopupsQuery);
1719
- }
1720
-
1721
- return $activePopupsQuery;
1722
- }
1723
- }
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
+ $popupContent = wpautop($this->content);
183
+ $editorContent = AdminHelper::checkEditorByPopupId($postId);
184
+ if (!empty($editorContent)) {
185
+ if (class_exists('Vc_Manager')) {
186
+ $popupContent .= $editorContent;
187
+ }
188
+ else {
189
+ $popupContent = $editorContent;
190
+ }
191
+ }
192
+
193
+ return $popupContent;
194
+ }
195
+
196
+ public function setPostData($postData)
197
+ {
198
+ $this->postData = apply_filters('sgpbSavedPostData', $postData);
199
+ }
200
+
201
+ public function getPostData()
202
+ {
203
+ return $this->postData;
204
+ }
205
+
206
+ public function getPopupTypeContent()
207
+ {
208
+ return $this->getContent();
209
+ }
210
+
211
+ public function insertIntoSanitizedData($sanitizedData)
212
+ {
213
+ if (!empty($sanitizedData)) {
214
+ $this->sanitizedData[$sanitizedData['name']] = $sanitizedData['value'];
215
+ }
216
+ }
217
+
218
+ abstract public function getExtraRenderOptions();
219
+
220
+ public function setSanitizedData($sanitizedData)
221
+ {
222
+ $this->sanitizedData = $sanitizedData;
223
+ }
224
+
225
+ public function getSanitizedData()
226
+ {
227
+ return $this->sanitizedData;
228
+ }
229
+
230
+ /**
231
+ * Find popup and create this object
232
+ *
233
+ * @since 1.0.0
234
+ *
235
+ * @param object|int $popup
236
+ *
237
+ * @return object|false $obj
238
+ */
239
+ public static function find($popup, $args = array())
240
+ {
241
+ if (isset($_GET['sg_popup_preview_id'])) {
242
+ $args['is-preview'] = true;
243
+ }
244
+ // If the popup is object get data from object otherwise we find needed data from WordPress functions
245
+ if ($popup instanceof WP_Post) {
246
+ $status = $popup->post_status;
247
+ $title = $popup->post_title;
248
+ $popupContent = $popup->post_content;
249
+ $popupId = $popup->ID;
250
+ }
251
+ else {
252
+ $popupId = $popup;
253
+ $popupPost = get_post($popupId);
254
+ if (empty($popupPost)) {
255
+ return false;
256
+ }
257
+ $title = get_the_title($popupId);
258
+ $status = get_post_status($popupId);
259
+ $popupContent = $popupPost->post_content;
260
+ }
261
+ $allowedStatus = array('publish', 'draft');
262
+
263
+ if (!empty($args['status'])) {
264
+ $allowedStatus = $args['status'];
265
+ }
266
+
267
+ if (!isset($args['checkActivePopupType']) && !in_array($status, $allowedStatus)) {
268
+ return $status;
269
+ }
270
+ $saveMode = '';
271
+ global $post;
272
+ if ((@is_preview() && $post->ID == $popupId) || isset($args['preview'])) {
273
+ $saveMode = '_preview';
274
+ }
275
+ if (isset($args['is-preview'])) {
276
+ $saveMode = '_preview';
277
+ }
278
+ if (isset($args['insidePopup']) && $args['insidePopup'] == 'on') {
279
+ $saveMode = '';
280
+ }
281
+ $currentPost = get_post($popupId);
282
+ $currentPostStatus = $currentPost->post_status;
283
+ if ($currentPostStatus == 'draft') {
284
+ $saveMode = '_preview';
285
+ }
286
+
287
+ $savedData = array();
288
+ if (file_exists(dirname(__FILE__).'/PopupData.php')) {
289
+ require_once(dirname(__FILE__).'/PopupData.php');
290
+ $savedData = PopupData::getPopupDataById($popupId, $saveMode);
291
+ }
292
+ $savedData = apply_filters('sgpbPopupSavedData', $savedData);
293
+
294
+ if (empty($savedData)) {
295
+ return false;
296
+ }
297
+
298
+ $type = 'html';
299
+ if (isset($savedData['sgpb-type'])) {
300
+ $type = $savedData['sgpb-type'];
301
+ }
302
+
303
+ $popupClassName = self::getPopupClassNameFormType($type);
304
+ $typePath = self::getPopupTypeClassPath($type);
305
+ if (!file_exists($typePath.$popupClassName.'.php')) {
306
+ return false;
307
+ }
308
+ require_once($typePath.$popupClassName.'.php');
309
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
310
+
311
+ $obj = new $popupClassName();
312
+ $obj->setId($popupId);
313
+ $obj->setType($type);
314
+ $obj->setTitle($title);
315
+ $obj->setContent($popupContent);
316
+
317
+ if (!empty($savedData['sgpb-target'][0])) {
318
+ $obj->setTarget($savedData['sgpb-target'][0]);
319
+ }
320
+ unset($savedData['sgpb-target']);
321
+ if (!empty($savedData['sgpb-events'][0])) {
322
+ $events = self::shapeEventsToOneArray($savedData['sgpb-events'][0]);
323
+ $obj->setEvents($events);
324
+ }
325
+ unset($savedData['sgpb-events']);
326
+ if (!empty($savedData['sgpb-conditions'][0])) {
327
+ $obj->setConditions($savedData['sgpb-conditions'][0]);
328
+ }
329
+ unset($savedData['sgpb-conditions']);
330
+
331
+ $obj->setOptions($savedData);
332
+
333
+ return $obj;
334
+ }
335
+
336
+ private static function shapeEventsToOneArray($events)
337
+ {
338
+ $eventsData = array();
339
+ if (!empty($events)) {
340
+ foreach ($events as $event) {
341
+ if (empty($event['hiddenOption'])) {
342
+ $eventsData[] = $event;
343
+ continue;
344
+ }
345
+ $hiddenOptions = $event['hiddenOption'];
346
+ unset($event['hiddenOption']);
347
+ $eventsData[] = $event + $hiddenOptions;
348
+ }
349
+ }
350
+
351
+ return apply_filters('sgpbEventsToOneArray', $eventsData);
352
+ }
353
+
354
+ public static function getPopupClassNameFormType($type)
355
+ {
356
+ $popupName = ucfirst(strtolower($type));
357
+ $popupClassName = $popupName.'Popup';
358
+
359
+ return apply_filters('sgpbPopupClassNameFromType', $popupClassName);
360
+ }
361
+
362
+ public static function getPopupTypeClassPath($type)
363
+ {
364
+ global $SGPB_POPUP_TYPES;
365
+ $typePaths = $SGPB_POPUP_TYPES['typePath'];
366
+
367
+ if (empty($typePaths[$type])) {
368
+ return SG_POPUP_CLASSES_POPUPS_PATH;
369
+ }
370
+
371
+ return $typePaths[$type];
372
+ }
373
+
374
+ public function sanitizeValueByType($value, $type)
375
+ {
376
+ switch ($type) {
377
+ case 'string':
378
+ if (is_array($value)) {
379
+ $sanitizedValue = $this->recursiveSanitizeTextField($value);
380
+ }
381
+ else {
382
+ $sanitizedValue = htmlspecialchars($value);
383
+ }
384
+ break;
385
+ case 'text':
386
+ $sanitizedValue = htmlspecialchars($value);
387
+ break;
388
+ case 'array':
389
+ $sanitizedValue = $this->recursiveSanitizeTextField($value);
390
+ break;
391
+ case 'email':
392
+ $sanitizedValue = sanitize_email($value);
393
+ break;
394
+ case 'sgpb':
395
+ $sanitizedValue = $this->recursiveHtmlSpecialchars($value);
396
+ break;
397
+ default:
398
+ $sanitizedValue = sanitize_text_field($value);
399
+ break;
400
+ }
401
+
402
+ return $sanitizedValue;
403
+ }
404
+
405
+ public function recursiveSanitizeTextField($array)
406
+ {
407
+ if (!is_array($array)) {
408
+ return $array;
409
+ }
410
+
411
+ foreach ($array as $key => &$value) {
412
+ if (is_array($value)) {
413
+ $value = $this->recursiveSanitizeTextField($value);
414
+ }
415
+ else {
416
+ /*get simple field type and do sanitization*/
417
+ $defaultData = $this->getDefaultDataByName($key);
418
+ if (empty($defaultData['type'])) {
419
+ $defaultData['type'] = 'string';
420
+ }
421
+ $value = $this->sanitizeValueByType($value, $defaultData['type']);
422
+ }
423
+ }
424
+
425
+ return $array;
426
+ }
427
+
428
+ public function recursiveHtmlSpecialchars($array)
429
+ {
430
+ if (!is_array($array)) {
431
+ return $array;
432
+ }
433
+
434
+ foreach ($array as $key => &$value) {
435
+ if (is_array($value)) {
436
+ $value = $this->recursiveHtmlSpecialchars($value);
437
+ }
438
+ else {
439
+ $value = htmlspecialchars($value);
440
+ }
441
+ }
442
+
443
+ return $array;
444
+ }
445
+
446
+ public static function parsePopupDataFromData($data)
447
+ {
448
+ $popupData = array();
449
+ $data = apply_filters('sgpbFilterOptionsBeforeSaving', $data);
450
+
451
+ foreach ($data as $key => $value) {
452
+ if (strpos($key, 'sgpb') === 0) {
453
+ $popupData[$key] = $value;
454
+ }
455
+ if (is_array($value) && isset($value['name']) && strpos($value['name'], 'sgpb') === 0) {
456
+ $popupData[$value['name']] = $value['value'];
457
+ }
458
+ else if (is_array($value) && isset($value['name']) && strpos($value['name'], 'post_ID') === 0) {
459
+ $popupData['sgpb-post-id'] = $value['value'];
460
+ }
461
+ }
462
+
463
+ return $popupData;
464
+ }
465
+
466
+ public static function create($data = array(), $saveMode = '', $firstTime = 0)
467
+ {
468
+ $obj = new static();
469
+ $obj->setSaveMode($saveMode);
470
+ $additionalData = $obj->addAdditionalSettings($data, $obj);
471
+ $data = array_merge($data, $additionalData);
472
+ $data = apply_filters('sgpbAdvancedOptionsDefaultValues', $data);
473
+ foreach ($data as $name => $value) {
474
+ if (strpos($name, 'sgpb') === 0) {
475
+ $defaultData = $obj->getDefaultDataByName($name);
476
+ if (empty($defaultData['type'])) {
477
+ $defaultData['type'] = 'string';
478
+ }
479
+ $sanitizedValue = $obj->sanitizeValueByType($value, $defaultData['type']);
480
+ $obj->insertIntoSanitizedData(array('name' => $name,'value' => $sanitizedValue));
481
+ }
482
+ }
483
+
484
+ $obj->setSavedPopupById($data['sgpb-post-id']);
485
+ $result = $obj->save();
486
+
487
+ $result = apply_filters('sgpbPopupCreateResult', $result);
488
+
489
+ if ($result) {
490
+ return $obj;
491
+ }
492
+
493
+ return $result;
494
+ }
495
+
496
+ public function save()
497
+ {
498
+ $this->convertImagesToData();
499
+ $data = $this->getSanitizedData();
500
+ $popupId = $data['sgpb-post-id'];
501
+
502
+ $this->setId($popupId);
503
+
504
+ if (!empty($data['sgpb-target'])) {
505
+ $this->setTarget($data['sgpb-target']);
506
+ /*remove from popup options because it's useless to save it twice*/
507
+ unset($data['sgpb-target']);
508
+ }
509
+ if (!empty($data['sgpb-conditions'])) {
510
+ $this->setConditions($data['sgpb-conditions']);
511
+ unset($data['sgpb-conditions']);
512
+ }
513
+ if (!empty($data['sgpb-events'])) {
514
+ $this->setEvents($data['sgpb-events']);
515
+ unset($data['sgpb-events']);
516
+ }
517
+ $data = $this->customScriptsSave($data);
518
+ $this->setOptions($data);
519
+
520
+ $targets = $this->targetSave();
521
+ $events = $this->eventsSave();
522
+ $options = $this->popupOptionsSave();
523
+
524
+ return ($targets && $events && $options);
525
+ }
526
+
527
+ public function convertImagesToData()
528
+ {
529
+ $buttonImageData = '';
530
+ $savedImageUrl = '';
531
+ $savedContentBackgroundImageUrl = '';
532
+ $contentBackgroundImageData = '';
533
+
534
+ $data = $this->getSanitizedData();
535
+ $buttonImageUrl = @$data['sgpb-button-image'];
536
+ $contentBackgroundImageUrl = @$data['sgpb-background-image'];
537
+
538
+ $savedPopup = $this->getSavedPopup();
539
+
540
+ if (is_object($savedPopup)) {
541
+ $buttonImageData = $savedPopup->getOptionvalue('sgpb-button-image-data');
542
+ $savedImageUrl = $savedPopup->getOptionValue('sgpb-button-image');
543
+ $contentBackgroundImageData = $savedPopup->getOptionValue('sgpb-background-image-data');
544
+ $savedContentBackgroundImageUrl = $savedPopup->getOptionValue('sgpb-background-image');
545
+ }
546
+
547
+ if ($buttonImageUrl != $savedImageUrl) {
548
+ $buttonImageData = AdminHelper::getImageDataFromUrl($buttonImageUrl, true);
549
+ }
550
+ if ($contentBackgroundImageUrl != $savedContentBackgroundImageUrl) {
551
+ $contentBackgroundImageData = AdminHelper::getImageDataFromUrl($contentBackgroundImageUrl);
552
+ }
553
+
554
+ $data['sgpb-button-image-data'] = $buttonImageData;
555
+ $data['sgpb-background-image-data'] = $contentBackgroundImageData;
556
+
557
+ $data = apply_filters('sgpbConvertImagesToData', $data);
558
+ $this->setSanitizedData($data);
559
+ }
560
+
561
+ private function customScriptsSave($data)
562
+ {
563
+ $popupId = $this->getId();
564
+ $popupContent = $this->getContent();
565
+
566
+ $defaultData = ConfigDataHelper::defaultData();
567
+ $defaultDataJs = $defaultData['customEditorContent']['js']['helperText'];
568
+ $defaultDataCss = $defaultData['customEditorContent']['css']['oldDefaultValue'];
569
+
570
+ $finalData = array('js' => array(), 'css' => array());
571
+ $alreadySavedData = get_post_meta($popupId, 'sg_popup_scripts', true);
572
+
573
+ // get styles
574
+ $finalData['css'] = $data['sgpb-css-editor'];
575
+ $defaultDataCss = $defaultDataCss[0];
576
+
577
+ $defaultDataCss = preg_replace('/\s/', '', $defaultDataCss);
578
+ $temp = preg_replace('/\s/', '', $finalData['css']);
579
+
580
+ unset($data['sgpb-css-editor']);
581
+
582
+ if ($temp == $defaultDataCss) {
583
+ unset($finalData['css']);
584
+ }
585
+
586
+ // get scripts
587
+ foreach ($defaultDataJs as $key => $value) {
588
+ if ($data['sgpb-'.$key] == '') {
589
+ unset($data['sgpb-'.$key]);
590
+ continue;
591
+ }
592
+ if ($key == 'ShouldOpen' || $key == 'ShouldClose') {
593
+ $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
594
+ continue;
595
+ }
596
+ $finalData['js']['sgpb-'.$key] = $data['sgpb-'.$key];
597
+ unset($data['sgpb-'.$key]);
598
+ }
599
+
600
+ if ($alreadySavedData == $finalData) {
601
+ return $data;
602
+ }
603
+
604
+ update_post_meta($popupId, 'sg_popup_scripts', $finalData);
605
+
606
+ return $data;
607
+ }
608
+
609
+ private function targetSave()
610
+ {
611
+ global $SGPB_DATA_CONFIG_ARRAY;
612
+ $saveMode = $this->getSaveMode();
613
+ $popupId = $this->getId();
614
+ $targetData = $this->getTarget();
615
+ $conditionsData = $this->getConditions();
616
+
617
+ $targetConfig = $SGPB_DATA_CONFIG_ARRAY['target'];
618
+ $paramsData = $targetConfig['paramsData'];
619
+ $attrs = $targetConfig['attrs'];
620
+ $popupTarget = array();
621
+ if (empty($targetData)) {
622
+ return array();
623
+ }
624
+
625
+ foreach ($targetData as $groupId => $groupData) {
626
+ foreach ($groupData as $ruleId => $ruleData) {
627
+
628
+ if (empty($ruleData['value']) && !is_null($paramsData[$ruleData['param']])) {
629
+ $targetData[$groupId][$ruleId]['value'] = '';
630
+ }
631
+ if (isset($ruleData['value']) && is_array($ruleData['value'])) {
632
+ $valueAttrs = $attrs[$ruleData['param']]['htmlAttrs'];
633
+ $postType = $valueAttrs['data-value-param'];
634
+ $isNotPostType = '';
635
+ if (isset($valueAttrs['isNotPostType'])) {
636
+ $isNotPostType = $valueAttrs['isNotPostType'];
637
+ }
638
+
639
+ if (empty($valueAttrs['isNotPostType'])) {
640
+ $isNotPostType = false;
641
+ }
642
+
643
+ /*
644
+ * $isNotPostType => false must search inside post types post
645
+ * $isNotPostType => true must save array data
646
+ * */
647
+ if (!$isNotPostType) {
648
+ $args = array(
649
+ 'post__in' => array_values($ruleData['value']),
650
+ 'posts_per_page' => 100,
651
+ 'post_type' => $postType
652
+ );
653
+
654
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
655
+
656
+ $targetData[$groupId][$ruleId]['value'] = $searchResults;
657
+ }
658
+ }
659
+ }
660
+ }
661
+
662
+ $popupTarget['sgpb-target'] = $targetData;
663
+ $popupTarget['sgpb-conditions'] = apply_filters('sgpbSaveConditions', $conditionsData);
664
+
665
+ $alreadySavedTargets = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
666
+ if ($alreadySavedTargets === $popupTarget) {
667
+ return true;
668
+ }
669
+
670
+ $popupTarget = apply_filters('sgpbPopupTargetMetaData', $popupTarget);
671
+
672
+ return update_post_meta($popupId, 'sg_popup_target'.$saveMode, $popupTarget);
673
+ }
674
+
675
+ private function eventsSave()
676
+ {
677
+ global $SGPB_DATA_CONFIG_ARRAY;
678
+
679
+ $eventsData = $this->getEvents();
680
+ $popupId = $this->getId();
681
+ $saveMode = $this->getSaveMode();
682
+ $popupEvents = array();
683
+ $eventsFromPopup = array();
684
+
685
+ foreach ($eventsData as $groupId => $groupData) {
686
+ $currentRuleData = array();
687
+ foreach ($groupData as $ruleId => $ruleData) {
688
+
689
+ $hiddenOptions = array();
690
+ $currentData = array();
691
+ foreach ($ruleData as $name => $value) {
692
+ if ($name == 'param' || $name == 'value' || $name == 'operator') {
693
+ $currentData[$name] = $value;
694
+ }
695
+ else {
696
+ $hiddenOptions[$name] = $value;
697
+ }
698
+ }
699
+ $currentData['hiddenOption'] = $hiddenOptions;
700
+ $currentRuleData[$ruleId] = $currentData;
701
+ }
702
+ $eventsFromPopup[$groupId] = $currentRuleData;
703
+ }
704
+
705
+ $popupEvents['formPopup'] = $eventsFromPopup;
706
+ $alreadySavedEvents = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
707
+ if ($alreadySavedEvents === $eventsFromPopup) {
708
+ return true;
709
+ }
710
+
711
+ $eventsFromPopup = apply_filters('sgpbPopupEventsMetadata', $eventsFromPopup);
712
+
713
+ return update_post_meta($popupId, 'sg_popup_events'.$saveMode, $eventsFromPopup);
714
+ }
715
+
716
+ private function popupOptionsSave()
717
+ {
718
+ $popupOptions = $this->getOptions();
719
+ $popupOptions = apply_filters('sgpbSavePopupOptions', $popupOptions);
720
+ //special code added for "Behavior After Special Events" section
721
+ //todo: remove in the future if possible
722
+ $specialBehaviors = array();
723
+ if (!empty($popupOptions['sgpb-behavior-after-special-events'])) {
724
+ $specialBehaviors = $popupOptions['sgpb-behavior-after-special-events'];
725
+ }
726
+ if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
727
+ foreach ($specialBehaviors as $groupId => $groupRow) {
728
+ foreach ($groupRow as $ruleId => $ruleRow) {
729
+ if (!empty($ruleRow['operator']) && $ruleRow['operator'] == 'open-popup') {
730
+ $args = array(
731
+ 'post__in' => array($ruleRow['value']),
732
+ 'posts_per_page' => 10,
733
+ 'post_type' => SG_POPUP_POST_TYPE
734
+ );
735
+
736
+ $searchResults = ConfigDataHelper::getPostTypeData($args);
737
+ $popupOptions['sgpb-behavior-after-special-events'][$groupId][$ruleId]['value'] = $searchResults;
738
+ }
739
+ }
740
+ }
741
+ }
742
+
743
+ $popupId = $this->getId();
744
+ $saveMode = $this->getSaveMode();
745
+
746
+ $alreadySavedOptions = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
747
+ if ($alreadySavedOptions === $popupOptions) {
748
+ return true;
749
+ }
750
+
751
+ $popupOptions = apply_filters('sgpbPopupSavedOptionsMetaData', $popupOptions);
752
+
753
+ return update_post_meta($popupId, 'sg_popup_options'.$saveMode, $popupOptions);
754
+ }
755
+
756
+ public function getOptionValue($optionName, $forceDefaultValue = false)
757
+ {
758
+ require_once(dirname(__FILE__).'/PopupData.php');
759
+ $savedData = PopupData::getPopupDataById($this->getId());
760
+ $this->setPostData($savedData);
761
+
762
+ return $this->getOptionValueFromSavedData($optionName, $forceDefaultValue);
763
+ }
764
+
765
+ public function getOptionValueFromSavedData($optionName, $forceDefaultValue = false)
766
+ {
767
+ $defaultData = $this->getDefaultDataByName($optionName);
768
+ $savedData = $this->getPostData();
769
+
770
+ $optionValue = null;
771
+
772
+ if (empty($defaultData['type'])) {
773
+ $defaultData['type'] = 'string';
774
+ }
775
+
776
+ if (!empty($savedData)) { //edit mode
777
+ if (isset($savedData[$optionName])) { //option exists in the database
778
+ $optionValue = $savedData[$optionName];
779
+ }
780
+ /* if it's a checkbox, it may not exist in the db
781
+ * if we don't care about it's existance, return empty string
782
+ * otherwise, go for it's default value
783
+ */
784
+ else if ($defaultData['type'] == 'checkbox' && !$forceDefaultValue) {
785
+ $optionValue = '';
786
+ }
787
+ }
788
+
789
+ if ($optionValue === null && !empty($defaultData['defaultValue'])) {
790
+ $optionValue = $defaultData['defaultValue'];
791
+ }
792
+
793
+ if ($defaultData['type'] == 'checkbox') {
794
+ $optionValue = $this->boolToChecked($optionValue);
795
+ }
796
+
797
+ if ($defaultData['type'] == 'number' && $optionValue == 0) {
798
+ $optionValue = 0;
799
+ }
800
+
801
+ return $optionValue;
802
+ }
803
+
804
+ public static function getSavedData($popupId, $saveMode = '')
805
+ {
806
+ $popupSavedData = array();
807
+ $events = self::getEventsDataById($popupId, $saveMode);
808
+ $targetData = self::getTargetDataById($popupId, $saveMode);
809
+
810
+ if (!empty($events)) {
811
+ $popupSavedData['sgpb-events'] = self::getEventsDataById($popupId, $saveMode);
812
+ }
813
+ if (!empty($targetData)) {
814
+ if (!empty($targetData['sgpb-target'])) {
815
+ $popupSavedData['sgpb-target'] = $targetData['sgpb-target'];
816
+ }
817
+ if (!empty($targetData['sgpb-conditions'])) {
818
+ // for the after x pages option backward compatibility
819
+ $targetData['sgpb-conditions'] = apply_filters('sgpbAdvancedTargetingSavedData', $targetData['sgpb-conditions'], $popupId);
820
+ $popupSavedData['sgpb-conditions'] = $targetData['sgpb-conditions'];
821
+ }
822
+ }
823
+
824
+ $popupOptions = self::getPopupOptionsById($popupId, $saveMode);
825
+ if (is_array($popupOptions) && is_array($popupSavedData)) {
826
+ $popupSavedData = array_merge($popupSavedData, $popupOptions);
827
+ }
828
+
829
+ return $popupSavedData;
830
+ }
831
+
832
+ public static function getEventsDataById($popupId, $saveMode = '')
833
+ {
834
+ $eventsData = array();
835
+ if (get_post_meta($popupId, 'sg_popup_events'.$saveMode, true)) {
836
+ $eventsData = get_post_meta($popupId, 'sg_popup_events'.$saveMode, true);
837
+ }
838
+
839
+ return $eventsData;
840
+ }
841
+
842
+ public static function getTargetDataById($popupId, $saveMode = '')
843
+ {
844
+ $targetData = array();
845
+
846
+ if (get_post_meta($popupId, 'sg_popup_target'.$saveMode, true)) {
847
+ $targetData = get_post_meta($popupId, 'sg_popup_target'.$saveMode, true);
848
+ }
849
+
850
+ return $targetData;
851
+ }
852
+
853
+ public static function getPopupOptionsById($popupId, $saveMode = '')
854
+ {
855
+ $currentPost = get_post($popupId);
856
+
857
+ if (!empty($currentPost) && $currentPost->post_status == 'draft') {
858
+ $saveMode = '_preview';
859
+ }
860
+ $optionsData = array();
861
+ if (get_post_meta($popupId, 'sg_popup_options'.$saveMode, true)) {
862
+ $optionsData = get_post_meta($popupId, 'sg_popup_options'.$saveMode, true);
863
+ }
864
+
865
+ return $optionsData;
866
+ }
867
+
868
+ public function getDefaultDataByName($optionName)
869
+ {
870
+ global $SGPB_OPTIONS;
871
+ if (empty($SGPB_OPTIONS)) {
872
+ return array();
873
+ }
874
+
875
+ foreach ($SGPB_OPTIONS as $option) {
876
+ if ($option['name'] == $optionName) {
877
+ return $option;
878
+ }
879
+ }
880
+
881
+ return array();
882
+ }
883
+
884
+ /**
885
+ * Get option default option value
886
+ *
887
+ * @param string $optionName
888
+ *
889
+ * @since 1.0.0
890
+ *
891
+ * @return string
892
+ *
893
+ */
894
+ public function getOptionDefaultValue($optionName)
895
+ {
896
+ // return config data array by name
897
+ $optionData = $this->getDefaultDataByName($optionName);
898
+
899
+ if (empty($optionData)) {
900
+ return '';
901
+ }
902
+
903
+ return $optionData['defaultValue'];
904
+ }
905
+
906
+ /**
907
+ * Changing default options form changing options by name
908
+ *
909
+ * @since 1.0.0
910
+ *
911
+ * @param array $defaultOptions
912
+ * @param array $changingOptions
913
+ *
914
+ * @return array $defaultOptions
915
+ */
916
+ public function changeDefaultOptionsByNames($defaultOptions, $changingOptions)
917
+ {
918
+ if (empty($defaultOptions) || empty($changingOptions)) {
919
+ return $defaultOptions;
920
+ }
921
+ $changingOptionsNames = array_keys($changingOptions);
922
+
923
+ foreach ($defaultOptions as $key => $defaultOption) {
924
+ $defaultOptionName = $defaultOption['name'];
925
+ if (in_array($defaultOptionName, $changingOptionsNames)) {
926
+ $defaultOptions[$key] = $changingOptions[$defaultOptionName];
927
+ }
928
+ }
929
+
930
+ return $defaultOptions;
931
+ }
932
+
933
+ /**
934
+ * Returns separate popup types Free or Pro
935
+ *
936
+ * @since 2.5.6
937
+ *
938
+ * @return array $popupTypesObj
939
+ */
940
+ public static function getPopupTypes()
941
+ {
942
+ global $SGPB_POPUP_TYPES;
943
+ $popupTypesObj = array();
944
+ $popupTypes = $SGPB_POPUP_TYPES['typeName'];
945
+
946
+ foreach ($popupTypes as $popupType => $level) {
947
+
948
+ if (empty($level)) {
949
+ $level = SGPB_POPUP_PKG_FREE;
950
+ }
951
+
952
+ $popupTypeObj = new PopupType();
953
+ $popupTypeObj->setName($popupType);
954
+ $popupTypeObj->setAccessLevel($level);
955
+
956
+ if (SGPB_POPUP_PKG >= $level) {
957
+ $popupTypeObj->setAvailable(true);
958
+ }
959
+ $popupTypesObj[] = $popupTypeObj;
960
+ }
961
+
962
+ return $popupTypesObj;
963
+ }
964
+
965
+ public static function savePopupsFromContentClasses($content, $post)
966
+ {
967
+ $postId = $post->ID;
968
+ $clickClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-id-');
969
+ $targetData = array();
970
+ $eventsData = array();
971
+
972
+ if (!empty($clickClassIds)) {
973
+ foreach ($clickClassIds as $id) {
974
+ $id = apply_filters('sgpbConvertedPopupId', $id);
975
+ if (empty($eventsData[$postId][$id])) {
976
+ $eventsData[$postId][$id] = array('click');
977
+ }
978
+ else {
979
+ $eventsData[$postId][$id][] = 'click';
980
+ }
981
+
982
+ if (empty($targetData[$postId])) {
983
+ $targetData[$postId] = array($id);
984
+ }
985
+ else {
986
+ $targetData[$postId][] = $id;
987
+ }
988
+ }
989
+ }
990
+
991
+ $iframeClassIs = self::getStringNextNumbersByReg($content, 'sg-iframe-popup-');
992
+
993
+ if (!empty($iframeClassIs)) {
994
+ foreach ($iframeClassIs as $id) {
995
+ $id = apply_filters('sgpbConvertedPopupId', $id);
996
+ $popupObj = self::find($id);
997
+
998
+ if (empty($popupObj)) {
999
+ continue;
1000
+ }
1001
+
1002
+ // this event should work only for iframe popup type
1003
+ if ($popupObj->getType() != 'iframe') {
1004
+ continue;
1005
+ }
1006
+
1007
+ if (empty($eventsData[$postId][$id])) {
1008
+ $eventsData[$postId][$id] = array('iframe');
1009
+ }
1010
+ else {
1011
+ $eventsData[$postId][$id][] = 'iframe';
1012
+ }
1013
+
1014
+ if (empty($targetData[$postId])) {
1015
+ $targetData[$postId] = array($id);
1016
+ }
1017
+ else {
1018
+ $targetData[$postId][] = $id;
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ $confirmClassIds = self::getStringNextNumbersByReg($content, 'sg-confirm-popup-');
1024
+
1025
+ if (!empty($confirmClassIds)) {
1026
+ foreach ($confirmClassIds as $id) {
1027
+ $id = apply_filters('sgpbConvertedPopupId', $id);
1028
+ if (empty($eventsData[$postId][$id])) {
1029
+ $eventsData[$postId][$id] = array('confirm');
1030
+ }
1031
+ else {
1032
+ $eventsData[$postId][$id][] = 'confirm';
1033
+ }
1034
+
1035
+ if (empty($targetData[$postId])) {
1036
+ $targetData[$postId] = array($id);
1037
+ }
1038
+ else {
1039
+ $targetData[$postId][] = $id;
1040
+ }
1041
+ }
1042
+ }
1043
+
1044
+ $hoverClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-hover-');
1045
+
1046
+ if (!empty($hoverClassIds)) {
1047
+ foreach ($hoverClassIds as $id) {
1048
+ $id = apply_filters('sgpbConvertedPopupId', $id);
1049
+ if (empty($eventsData[$postId][$id])) {
1050
+ $eventsData[$postId][$id] = array('hover');
1051
+ }
1052
+ else {
1053
+ $eventsData[$postId][$id][] = 'hover';
1054
+ }
1055
+
1056
+ if (empty($targetData[$postId])) {
1057
+ $targetData[$postId] = array($id);
1058
+ }
1059
+ else {
1060
+ $targetData[$postId][] = $id;
1061
+ }
1062
+ }
1063
+ }
1064
+
1065
+ $targetData = apply_filters('sgpbPopupTargetData', $targetData);
1066
+ $eventsData = apply_filters('sgpbPopupEventsData', $eventsData);
1067
+
1068
+ self::saveToTargetFromPage($targetData);
1069
+ self::saveToEventsFromPage($eventsData);
1070
+ }
1071
+
1072
+ public static function getStringNextNumbersByReg($content, $key)
1073
+ {
1074
+ $result = array();
1075
+ preg_match_all("/(?<=$key)(\d+)/", $content, $ids);
1076
+
1077
+ if (!empty($ids[0])) {
1078
+ $result = $ids[0];
1079
+ }
1080
+
1081
+ return $result;
1082
+ }
1083
+
1084
+ private static function saveToTargetAndEvents($popupsShortcodsInPostPage, $postId)
1085
+ {
1086
+ if (empty($popupsShortcodsInPostPage)) {
1087
+ return false;
1088
+ }
1089
+ $customEvents = array();
1090
+ $customPopups = array();
1091
+
1092
+ foreach ($popupsShortcodsInPostPage as $shortcodesData) {
1093
+ $popupId = apply_filters('sgpbConvertedPopupId', $shortcodesData['id']);
1094
+
1095
+ $args = array(
1096
+ 'post_type' => SG_POPUP_POST_TYPE,
1097
+ 'post__in' => array($popupId)
1098
+ );
1099
+ $postById = ConfigDataHelper::getPostTypeData($args);
1100
+ //When target data does not exist
1101
+ if (empty($postById)) {
1102
+ continue;
1103
+ }
1104
+
1105
+ // collect custom inserted popups
1106
+ if (empty($customPopups[$postId])) {
1107
+ $customPopups[$postId] = array($popupId);
1108
+ }
1109
+ else {
1110
+ $customPopups[$postId][] = $popupId;
1111
+ }
1112
+
1113
+ // collect custom inserted popups events
1114
+ if (empty($shortcodesData['event'])) {
1115
+ $eventName = 'onload';
1116
+ }
1117
+ else {
1118
+ $eventName = $shortcodesData['event'];
1119
+ }
1120
+
1121
+ if ($eventName == 'onload') {
1122
+ $eventName = 'attr'.$eventName;
1123
+ }
1124
+ $currentEventData = array(
1125
+ 'param' => $eventName
1126
+ );
1127
+
1128
+ if (empty($customEvents[$postId][$popupId])) {
1129
+ $customEvents[$postId][$popupId] = array($currentEventData);
1130
+ }
1131
+ else {
1132
+ $customEvents[$postId][$popupId][] = $currentEventData;
1133
+ }
1134
+ }
1135
+
1136
+ self::saveToTargetFromPage($customPopups);
1137
+ self::saveToEventsFromPage($customEvents);
1138
+
1139
+ return true;
1140
+ }
1141
+
1142
+ public static function getPostPopupCustomEvent($postId, $popupId)
1143
+ {
1144
+ $events = array();
1145
+
1146
+ $customEventsData = self::getCustomInsertedPopupEventsByPostId($postId);
1147
+
1148
+ if (!empty($customEventsData[$popupId])) {
1149
+ $events = $customEventsData[$popupId];
1150
+ }
1151
+
1152
+ return $events;
1153
+ }
1154
+
1155
+ /**
1156
+ * Save popup to custom events from pages
1157
+ *
1158
+ * @since 1.0.0
1159
+ *
1160
+ * @param array $customEvents
1161
+ *
1162
+ * @return bool
1163
+ *
1164
+ */
1165
+ public static function saveToEventsFromPage($customEvents)
1166
+ {
1167
+ if (empty($customEvents)) {
1168
+ return false;
1169
+ }
1170
+
1171
+ foreach ($customEvents as $postId => $popupsData) {
1172
+ $savedCustomEvents = self::getCustomInsertedPopupEventsByPostId($postId);
1173
+ $result = AdminHelper::arrayMergeSameKeys($popupsData, $savedCustomEvents);
1174
+
1175
+ if (!$result) {
1176
+ return $result;
1177
+ }
1178
+ update_post_meta($postId, 'sgpb_popup_events_custom', $result);
1179
+ }
1180
+
1181
+ return true;
1182
+ }
1183
+
1184
+ public static function getCustomInsertedPopupEventsByPostId($postId)
1185
+ {
1186
+ $eventsData = array();
1187
+ $postMetaData = get_post_meta($postId, 'sgpb_popup_events_custom', true);
1188
+
1189
+ if (!empty($postMetaData)) {
1190
+ $eventsData = $postMetaData;
1191
+ }
1192
+
1193
+ return $eventsData;
1194
+ }
1195
+
1196
+ /**
1197
+ * Save popup to custom targets from pages
1198
+ *
1199
+ * @since 1.0.0
1200
+ *
1201
+ * @param array $customPopups
1202
+ *
1203
+ * @return void
1204
+ *
1205
+ */
1206
+ public static function saveToTargetFromPage($customPopups)
1207
+ {
1208
+ if (!empty($customPopups)) {
1209
+ foreach ($customPopups as $postId => $popups) {
1210
+ $alreadySavedPopups = self::getCustomInsertedDataByPostId($postId);
1211
+ $popups = array_merge($popups, $alreadySavedPopups);
1212
+ update_post_meta($postId, 'sg_popup_target_custom', $popups);
1213
+ }
1214
+ }
1215
+ }
1216
+
1217
+ /**
1218
+ * Get popup custom targes form saved data
1219
+ *
1220
+ * @since 1.0.0
1221
+ *
1222
+ * @param int $postId
1223
+ *
1224
+ * @return array $postData
1225
+ */
1226
+ public static function getCustomInsertedDataByPostId($postId)
1227
+ {
1228
+ $postData = array();
1229
+ $postMetaData = get_post_meta($postId, 'sg_popup_target_custom');
1230
+
1231
+ if (!empty($postMetaData[0])) {
1232
+ $postData = $postMetaData[0];
1233
+ }
1234
+
1235
+ return $postData;
1236
+ }
1237
+
1238
+ public static function getPopupShortcodeMatchesFromContent($content)
1239
+ {
1240
+ $result = false;
1241
+ $pattern = get_shortcode_regex();
1242
+
1243
+ if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1244
+ && !empty($matches)
1245
+ && is_array($matches)
1246
+ && array_key_exists( 2, $matches )
1247
+ && in_array('sg_popup', $matches[2])
1248
+ )
1249
+ {
1250
+ $result = $matches;
1251
+ }
1252
+
1253
+ return $result;
1254
+ }
1255
+
1256
+ public static function renderPopupContentShortcode($content, $popupId, $event, $args)
1257
+ {
1258
+ ob_start();
1259
+ $wrap = 'a';
1260
+ if (!empty($args['wrap'])) {
1261
+ if ($args['wrap'] == $wrap) {
1262
+ $args['href'] = 'javascript:void(0)';
1263
+ }
1264
+ $wrap = $args['wrap'];
1265
+ }
1266
+ unset($args['wrap']);
1267
+ unset($args['event']);
1268
+ unset($args['id']);
1269
+ $attr = AdminHelper::createAttrs($args);
1270
+ ?>
1271
+ <<?php echo $wrap; ?>
1272
+ <?php if ($wrap == 'a') : ?>
1273
+ href="javascript:void(0)"
1274
+ <?php endif ?>
1275
+ class="sg-show-popup <?php echo 'sgpb-popup-id-'.$popupId; ?>"
1276
+ data-sgpbpopupid="<?php echo esc_attr($popupId); ?>"
1277
+ data-popup-event="<?php echo $event; ?>"
1278
+ <?php echo $attr; ?>>
1279
+ <?php echo $content; ?>
1280
+ </<?php echo $wrap; ?>>
1281
+ <?php
1282
+
1283
+ $shortcodeContent = ob_get_contents();
1284
+ ob_get_clean();
1285
+
1286
+ return $shortcodeContent;
1287
+ }
1288
+
1289
+ private static function collectInsidePopupShortcodes($content)
1290
+ {
1291
+ $pattern = get_shortcode_regex();
1292
+ $options = array();
1293
+ if (preg_match_all('/'.$pattern.'/s', $content, $matches)
1294
+ && !empty($matches)
1295
+ && is_array($matches)
1296
+ && array_key_exists( 2, $matches )
1297
+ && in_array('sg_popup', $matches[2])
1298
+ )
1299
+ {
1300
+ foreach ($matches[0] as $key => $value) {
1301
+ //return current shortcode all attrs as assoc array
1302
+ $attrs = shortcode_parse_atts($matches[3][$key]);
1303
+ $currentAttrs = array();
1304
+ if (!empty($attrs['id'])) {
1305
+ $currentAttrs['id'] = $attrs['id'];
1306
+ }
1307
+ if (!empty($attrs['insidepopup'])) {
1308
+ $currentAttrs['insidepopup'] = $attrs['insidepopup'];
1309
+ }
1310
+ if (empty($attrs['insidepopup']) || (!empty($attrs['insidepopup']) && $attrs['insidepopup'] != 'on')) {
1311
+ continue;
1312
+ }
1313
+
1314
+ $options[$currentAttrs['id']] = $value;
1315
+ }
1316
+ }
1317
+
1318
+ return apply_filters('sgpbPopupInsideShortcodes', $options);
1319
+ }
1320
+
1321
+ /**
1322
+ * Collect all popups by taxonomy slug
1323
+ *
1324
+ * @since 1.0.0
1325
+ *
1326
+ * @param string $popupTermSlug category slug name
1327
+ *
1328
+ * @return array $popupIds random popups id
1329
+ *
1330
+ */
1331
+ public static function getPopupsByTermSlug($popupTermSlug)
1332
+ {
1333
+ $popupIds = array();
1334
+
1335
+ $termPopups = get_transient(SGPB_TRANSIENT_POPUPS_TERMS);
1336
+ if ($termPopups === false) {
1337
+ $termPopups = get_posts(
1338
+ array(
1339
+ 'post_type' => 'popupbuilder',
1340
+ 'numberposts' => -1,
1341
+ 'tax_query' => array(
1342
+ array(
1343
+ 'taxonomy' => SG_POPUP_CATEGORY_TAXONOMY,
1344
+ 'field' => 'slug',
1345
+ 'terms' => $popupTermSlug
1346
+ )
1347
+ )
1348
+ )
1349
+ );
1350
+ set_transient(SGPB_TRANSIENT_POPUPS_TERMS, $termPopups, SGPB_TRANSIENT_TIMEOUT_WEEK);
1351
+ }
1352
+
1353
+ if (empty($termPopups)) {
1354
+ return $popupIds;
1355
+ }
1356
+
1357
+ foreach ($termPopups as $termPopup) {
1358
+ $popupIds[] = $termPopup->ID;
1359
+ }
1360
+
1361
+ return $popupIds;
1362
+ }
1363
+
1364
+ public function boolToChecked($var)
1365
+ {
1366
+ return ($var?'checked':'');
1367
+ }
1368
+
1369
+ /**
1370
+ * Delete custom inserted data
1371
+ *
1372
+ * @since 1.0.0
1373
+ *
1374
+ * @param int $postId current post page id
1375
+ *
1376
+ * @return void
1377
+ *
1378
+ */
1379
+ public static function deletePostCustomInsertedData($postId)
1380
+ {
1381
+ delete_post_meta($postId, 'sg_popup_target_custom');
1382
+ }
1383
+
1384
+ /**
1385
+ * Delete custom inserted events
1386
+ *
1387
+ * @since 1.0.0
1388
+ *
1389
+ * @param int $postId current post page id
1390
+ *
1391
+ * @return void
1392
+ *
1393
+ */
1394
+ public static function deletePostCustomInsertedEvents($postId)
1395
+ {
1396
+ delete_post_meta($postId, 'sgpb_popup_events_custom');
1397
+ }
1398
+
1399
+ /**
1400
+ * If popup Type does not have getPopupTypeOptions method
1401
+ * it's tell popup does not have custom options
1402
+ *
1403
+ * @since 1.0.0
1404
+ *
1405
+ * @return bool
1406
+ *
1407
+ */
1408
+ public function getPopupTypeOptionsView()
1409
+ {
1410
+ return false;
1411
+ }
1412
+
1413
+ /**
1414
+ * If popup Type does not have getPopupTypeOptions method
1415
+ * it's tell popup does not have custom options
1416
+ *
1417
+ * @since 1.0.0
1418
+ *
1419
+ * @return bool
1420
+ *
1421
+ */
1422
+ public function getPopupTypeMainView()
1423
+ {
1424
+ return false;
1425
+ }
1426
+
1427
+ /**
1428
+ * Remove popup option from admin view by option name
1429
+ *
1430
+ * @since 1.0.0
1431
+ *
1432
+ * @return array $removedOptions
1433
+ *
1434
+ */
1435
+ public function getRemoveOptions()
1436
+ {
1437
+ $removeOptions = array();
1438
+
1439
+ return apply_filters('sgpbRemoveOptions', $removeOptions);
1440
+ }
1441
+
1442
+ public static function createPopupTypeObjById($popupId)
1443
+ {
1444
+ global $SGPB_POPUP_TYPES;
1445
+ $typePath = '';
1446
+ $popupOptionsData = SGPopup::getPopupOptionsById($popupId);
1447
+ if (empty($popupOptionsData)) {
1448
+ return false;
1449
+ }
1450
+ $popupType = $popupOptionsData['sgpb-type'];
1451
+ $popupName = ucfirst(strtolower($popupType));
1452
+ $popupClassName = $popupName.'Popup';
1453
+
1454
+ if (!empty($SGPB_POPUP_TYPES['typePath'][$popupType])) {
1455
+ $typePath = $SGPB_POPUP_TYPES['typePath'][$popupType];
1456
+ }
1457
+
1458
+ if (!file_exists($typePath.$popupClassName.'.php')) {
1459
+ wp_die(__('Popup class does not exist', SG_POPUP_TEXT_DOMAIN));
1460
+ }
1461
+ require_once($typePath.$popupClassName.'.php');
1462
+
1463
+ $popupClassName = __NAMESPACE__.'\\'.$popupClassName;
1464
+ $popupTypeObj = new $popupClassName();
1465
+ $popupTypeObj->setId($popupId);
1466
+
1467
+ return $popupTypeObj;
1468
+ }
1469
+
1470
+ /**
1471
+ * if child class does not have this function we call parent function to not get any errors
1472
+ *
1473
+ * @since 1.0.0
1474
+ *
1475
+ * @return array
1476
+ *
1477
+ */
1478
+ public static function getTablesSql()
1479
+ {
1480
+ return array();
1481
+ }
1482
+
1483
+ /**
1484
+ * if child class does not have this function we call parent function to not get any errors
1485
+ *
1486
+ * @since 1.0.0
1487
+ *
1488
+ * @return array
1489
+ *
1490
+ */
1491
+ public static function getTableNames()
1492
+ {
1493
+ return array();
1494
+ }
1495
+
1496
+ /**
1497
+ *
1498
+ * Get WordPress localization name
1499
+ *
1500
+ * @since 1.0.0
1501
+ *
1502
+ * @return string
1503
+ *
1504
+ */
1505
+ public function getSiteLocale()
1506
+ {
1507
+ $locale = get_bloginfo('language');
1508
+ $locale = str_replace('-', '_', $locale);
1509
+
1510
+ return $locale;
1511
+ }
1512
+
1513
+ public function addAdditionalSettings($postData = array(), $obj = null)
1514
+ {
1515
+ return array();
1516
+ }
1517
+
1518
+ public function allowToLoad()
1519
+ {
1520
+ global $post;
1521
+
1522
+ $popupChecker = PopupChecker::instance();
1523
+ $loadableModes = $popupChecker->isLoadable($this, $post);
1524
+ $this->setLoadableModes($loadableModes);
1525
+
1526
+ return ($loadableModes['attr_event'] || $loadableModes['option_event']);
1527
+ }
1528
+
1529
+ public static function getAllPopups($filters = array())
1530
+ {
1531
+ $args = array(
1532
+ 'post_type' => SG_POPUP_POST_TYPE
1533
+ );
1534
+ $allPopups = array();
1535
+ $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1536
+
1537
+ if (empty($allPostData)) {
1538
+ return $allPopups;
1539
+ }
1540
+
1541
+ foreach ($allPostData->posts as $postData) {
1542
+ if (empty($postData)) {
1543
+ continue;
1544
+ }
1545
+
1546
+ $popup = self::find($postData->ID, $args);
1547
+ if (empty($popup) || !($popup instanceof SGPopup)) {
1548
+ continue;
1549
+ }
1550
+ $type = @$popup->getType();
1551
+
1552
+ if (isset($filters['type'])) {
1553
+ if (is_array($filters['type'])) {
1554
+ if (!in_array($type, $filters['type'])) {
1555
+ continue;
1556
+ }
1557
+ }
1558
+ else if ($type != $filters['type']) {
1559
+ continue;
1560
+ }
1561
+ }
1562
+ $allPopups[] = $popup;
1563
+ }
1564
+
1565
+ return $allPopups;
1566
+ }
1567
+
1568
+ public function getPopupsIdAndTitle()
1569
+ {
1570
+ $allPopups = SGPopup::getAllPopups();
1571
+ $popupIdTitles = array();
1572
+
1573
+ if (empty($allPopups)) {
1574
+ return $popupIdTitles;
1575
+ }
1576
+ $currentPopupId = $this->getId();
1577
+
1578
+ foreach ($allPopups as $popup) {
1579
+ if (empty($popup)) {
1580
+ continue;
1581
+ }
1582
+ $id = $popup->getId();
1583
+
1584
+ if ($id == $currentPopupId) {
1585
+ continue;
1586
+ }
1587
+
1588
+ $title = $popup->getTitle();
1589
+ $type = $popup->getType();
1590
+
1591
+ $popupIdTitles[$id] = $title.' - '.$type;
1592
+ }
1593
+
1594
+ return $popupIdTitles;
1595
+ }
1596
+
1597
+ public function getSubPopupObj()
1598
+ {
1599
+ $subPopups = array();
1600
+ $options = $this->getOptions();
1601
+
1602
+ $specialBehaviors = @$options['sgpb-behavior-after-special-events'];
1603
+ if (!empty($specialBehaviors) && is_array($specialBehaviors)) {
1604
+ foreach ($specialBehaviors as $behavior) {
1605
+ foreach ($behavior as $row) {
1606
+ if (!empty($row['param']) && $row['param'] == SGPB_CONTACT_FORM_7_BEHAVIOR_KEY) {
1607
+ if (!empty($row['operator']) && $row['operator'] == 'open-popup') {
1608
+ if (!empty($row['value'])) {
1609
+ $popupId = key($row['value']);
1610
+ $subPopupObj = self::find((int)$popupId);
1611
+ if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
1612
+ $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
1613
+ $subPopups[] = $subPopupObj;
1614
+ }
1615
+ }
1616
+ }
1617
+ }
1618
+ }
1619
+ }
1620
+ }
1621
+
1622
+ return $subPopups;
1623
+ }
1624
+
1625
+ public static function doInsideShortcode($insideShortcode)
1626
+ {
1627
+ return do_shortcode($insideShortcode);
1628
+ }
1629
+
1630
+ public function popupShortcodesInsidePopup()
1631
+ {
1632
+ $popups = array();
1633
+ $args = array('insidePopup' => 'on');
1634
+ $popupContent = $this->getContent();
1635
+ $parentTarget = $this->getTarget();
1636
+ $insidePopupShortcodes = self::collectInsidePopupShortcodes($popupContent);
1637
+ if (empty($insidePopupShortcodes)) {
1638
+ return $popups;
1639
+ }
1640
+ foreach ($insidePopupShortcodes as $insidePopupId => $insidePopupShortcode) {
1641
+ $insidePopupId = (int)$insidePopupId;
1642
+ if (!$insidePopupId) {
1643
+ continue;
1644
+ }
1645
+ // true = find inside popup
1646
+ $insidePopup = self::find($insidePopupId, $args);
1647
+ if (empty($insidePopup) || $insidePopup == 'trash' || $insidePopup == 'inherit') {
1648
+ continue;
1649
+ }
1650
+ $events = array('insideclick');
1651
+ $insidePopup->setEvents($events);
1652
+ $popups[$insidePopupId] = $insidePopup;
1653
+ }
1654
+
1655
+ $popupContent = self::doInsideShortcode($popupContent);
1656
+ $this->setContent($popupContent);
1657
+
1658
+ return $popups;
1659
+ }
1660
+
1661
+ public function getPopupOpeningCountById($popupId)
1662
+ {
1663
+ global $wpdb;
1664
+
1665
+ $allCount = 0;
1666
+ $popupsCounterData = get_option('SgpbCounter');
1667
+ $popupCountFromAnalyticsData = 0;
1668
+ $tableName = $wpdb->prefix.'sgpb_analytics';
1669
+ if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
1670
+ $popupCountFromAnalyticsData = self::getAnalyticsDataByPopupId($popupId);
1671
+ }
1672
+ if (isset($popupsCounterData[$popupId])) {
1673
+ $allCount += $popupsCounterData[$popupId];
1674
+ }
1675
+ $allCount += $popupCountFromAnalyticsData;
1676
+
1677
+ return $allCount;
1678
+ }
1679
+
1680
+ public static function getAnalyticsDataByPopupId($popupId)
1681
+ {
1682
+ global $wpdb;
1683
+ // 7, 12, 13 => exclude close, subscription success, contact success events
1684
+ $stmt = $wpdb->prepare('SELECT COUNT(*) FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13)', $popupId);
1685
+ $popupAnalyticsData = $wpdb->get_var($stmt);
1686
+ return $popupAnalyticsData;
1687
+ }
1688
+
1689
+ public static function deleteAnalyticsDataByPopupId($popupId)
1690
+ {
1691
+ global $wpdb;
1692
+ $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.'sgpb_analytics WHERE target_id = %d AND event_id NOT IN (7, 12, 13) LIMIT 100', $popupId);
1693
+ $wpdb->query($prepareSql);
1694
+ }
1695
+
1696
+ public static function getActivePopupsQueryString()
1697
+ {
1698
+ $activePopupsQuery = '';
1699
+ $args = array(
1700
+ 'post_type' => SG_POPUP_POST_TYPE,
1701
+ 'post_status' => array('trash', 'publish')
1702
+ );
1703
+ if (!class_exists('ConfigDataHelper')) {
1704
+ return $activePopupsQuery;
1705
+ }
1706
+ $allPostData = ConfigDataHelper::getQueryDataByArgs($args);
1707
+ $args['checkActivePopupType'] = true;
1708
+ $allPopups = $allPostData->posts;
1709
+ foreach ($allPopups as $post) {
1710
+ $id = $post->ID;
1711
+ $popup = self::find($id, $args);
1712
+ if (empty($popup)) {
1713
+ $activePopupsQuery .= $id.', ';
1714
+ }
1715
+ }
1716
+ if ($activePopupsQuery != '') {
1717
+ $activePopupsQuery = ' AND ID NOT IN ('.$activePopupsQuery.')';
1718
+ $activePopupsQuery = str_replace(', )', ') ', $activePopupsQuery);
1719
+ }
1720
+
1721
+ return $activePopupsQuery;
1722
+ }
1723
+ }
com/classes/popups/SubscriptionPopup.php CHANGED
@@ -1,685 +1,685 @@
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' => $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' => $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' => $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' => $inputWidth),
314
- 'label' => $gdprLabel,
315
- 'text' => $this->getFieldValue('sgpb-subs-gdpr-text'),
316
- 'errorMessageBoxStyles' => $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
- </style>
475
- <?php
476
- $styles = ob_get_contents();
477
- ob_get_clean();
478
-
479
- return $styles;
480
- }
481
-
482
- public function getOptionValue($optionName, $forceDefaultValue = false)
483
- {
484
- return parent::getOptionValue($optionName, $forceDefaultValue);
485
- }
486
-
487
- public function getPopupTypeOptionsView()
488
- {
489
- $optionsViewData = array(
490
- 'filePath' => SG_POPUP_TYPE_OPTIONS_PATH . 'subscription.php',
491
- 'metaboxTitle' => 'Subscription Options'
492
- );
493
-
494
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
495
-
496
- if ($isSubscriptionPlusActive) {
497
- return array();
498
- }
499
-
500
- return $optionsViewData;
501
- }
502
-
503
- private function getSubscriptionForm($subsFields)
504
- {
505
- $popupId = $this->getId();
506
- $form = '<div class="sgpb-subs-form-'.$popupId.' sgpb-subscription-form">';
507
- $form .= $this->getFormMessages();
508
- $form .= Functions::renderForm($subsFields);
509
- $form .= '</div>';
510
-
511
- return $form;
512
- }
513
-
514
- private function getFormMessages()
515
- {
516
- $successMessage = $this->getOptionValue('sgpb-subs-success-message');
517
- $errorMessage = $this->getOptionValue('sgpb-subs-error-message');
518
- if (empty($errorMessage)) {
519
- $errorMessage = SGPB_SUBSCRIPTION_ERROR_MESSAGE;
520
- }
521
- ob_start();
522
- ?>
523
- <div class="subs-form-messages sgpb-alert sgpb-alert-success sg-hide-element">
524
- <p><?php echo $successMessage; ?></p>
525
- </div>
526
- <div class="subs-form-messages sgpb-alert sgpb-alert-danger sg-hide-element">
527
- <p><?php echo $errorMessage; ?></p>
528
- </div>
529
- <?php
530
- $messages = ob_get_contents();
531
- ob_end_clean();
532
-
533
- return $messages;
534
- }
535
-
536
- public function renderOptions($options)
537
- {
538
- // for old popups
539
- if (isset($options['sgpb-subs-success-popup']) && function_exists('sgpb\sgpGetCorrectPopupId')) {
540
- $options['sgpb-subs-success-popup'] = sgpGetCorrectPopupId($options['sgpb-subs-success-popup']);
541
- }
542
-
543
- return $options;
544
- }
545
-
546
- public function getPopupTypeContent()
547
- {
548
- $this->frontendFilters();
549
-
550
- apply_filters('sgpbSubscriptionForm', $this);
551
- $popupContent = $this->getContent();
552
- $formContent = $this->getFormContent();
553
- $showToTop = $this->getOptionValue('sgpb-subs-show-form-to-top');
554
- $content = $popupContent.$formContent;
555
-
556
- if ($showToTop) {
557
- $content = $formContent.$popupContent;
558
- }
559
- return $content;
560
- }
561
-
562
- public function subscriptionForm($popupObj)
563
- {
564
- if (!is_object($popupObj)) {
565
- return '';
566
- }
567
- $popupContent = '';
568
- $popupOptions = $popupObj->getOptions();
569
- $subsFields = $popupObj->getOptionValue('sgpb-subs-fields');
570
- $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
571
-
572
- if (empty($subsFields) || !$isSubscriptionPlusActive) {
573
- $subsFields = $popupObj->createFormFieldsData();
574
- }
575
-
576
- $subsRequiredMessages = '';
577
- if (!empty($popupOptions['sgpb-subs-validation-message'])) {
578
- $subsRequiredMessages = $popupOptions['sgpb-subs-validation-message'];
579
- }
580
-
581
- $validationMessages = array(
582
- 'requiredMessage' => $subsRequiredMessages
583
- );
584
-
585
- $styleData = array(
586
- 'placeholderColor' => $popupOptions['sgpb-subs-text-placeholder-color'],
587
- 'formColor' => $popupOptions['sgpb-subs-form-bg-color'],
588
- 'formPadding' => @$popupOptions['sgpb-subs-form-padding'],
589
- 'formBackgroundOpacity' => @$popupOptions['sgpb-subs-form-bg-opacity']
590
- );
591
-
592
- $validateScript = $popupObj->createValidateObj($subsFields, $validationMessages);
593
- $popupContent .= $popupObj->getSubscriptionForm($subsFields);
594
- $popupContent .= $popupObj->getSubscriptionValidationScripts($validateScript);
595
- $popupContent .= $popupObj->getFormCustomStyles($styleData);
596
-
597
- $popupObj->setFormContent($popupContent);
598
-
599
- return $popupObj;
600
- }
601
-
602
- public function getSubPopupObj()
603
- {
604
- $options = $this->getOptions();
605
- $subPopups = parent::getSubPopupObj();
606
- if ($options['sgpb-subs-success-behavior'] == 'openPopup') {
607
- $subPopupId = (!empty($options['sgpb-subs-success-popup'])) ? (int)$options['sgpb-subs-success-popup']: null;
608
-
609
- if (empty($subPopupId)) {
610
- return $subPopups;
611
- }
612
-
613
- // for old popups
614
- if (function_exists('sgpb\sgpGetCorrectPopupId')) {
615
- $subPopupId = sgpGetCorrectPopupId($subPopupId);
616
- }
617
-
618
- $subPopupObj = SGPopup::find($subPopupId);
619
- if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
620
- // We remove all events because this popup will be open after successful subscription
621
- $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
622
- $subPopups[] = $subPopupObj;
623
- }
624
- }
625
-
626
- return $subPopups;
627
- }
628
-
629
- public function getExtraRenderOptions()
630
- {
631
- return array();
632
- }
633
-
634
- public static function getSubscribersCount()
635
- {
636
- global $wpdb;
637
- $count = $wpdb->get_var('SELECT COUNT(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME);
638
-
639
- return (int)$count;
640
- }
641
-
642
- public static function getAllSubscriptions()
643
- {
644
- $popupArgs = array();
645
- $popupArgs['type'][] = 'subscription';
646
-
647
- $popupArgs = apply_filters('sgpbGetAllSubscriptionArgs', $popupArgs);
648
- $allPopups = SGPopup::getAllPopups($popupArgs);
649
-
650
- return $allPopups;
651
- }
652
-
653
- public static function getAllSubscriptionForms()
654
- {
655
- $subsFormList = array();
656
- $subscriptionForms = self::getAllSubscriptions();
657
-
658
- foreach ($subscriptionForms as $subscriptionForm) {
659
- $title = $subscriptionForm->getTitle();
660
- $id = $subscriptionForm->getId();
661
- if ($title == '') {
662
- $title = '('.__('no title', SG_POPUP_TEXT_DOMAIN).')';
663
- }
664
- $subsFormList[$id] = $title;
665
- }
666
-
667
- return $subsFormList;
668
- }
669
-
670
- public static function getAllSubscribersDate()
671
- {
672
- $subsDateList = array();
673
- global $wpdb;
674
- $subscriptionPopups = $wpdb->get_results('SELECT id, cDate FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME, ARRAY_A);
675
-
676
- foreach ($subscriptionPopups as $subscriptionForm) {
677
- $id = $subscriptionForm['id'];
678
- $date = substr($subscriptionForm['cDate'], 0, 7);
679
- $subsDateList[$id]['date-value'] = $date;
680
- $subsDateList[$id]['date-title'] = AdminHelper::getFormattedDate($date);
681
- }
682
-
683
- return $subsDateList;
684
- }
685
- }
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' => $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' => $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' => $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' => $inputWidth),
314
+ 'label' => $gdprLabel,
315
+ 'text' => $this->getFieldValue('sgpb-subs-gdpr-text'),
316
+ 'errorMessageBoxStyles' => $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
+ </style>
475
+ <?php
476
+ $styles = ob_get_contents();
477
+ ob_get_clean();
478
+
479
+ return $styles;
480
+ }
481
+
482
+ public function getOptionValue($optionName, $forceDefaultValue = false)
483
+ {
484
+ return parent::getOptionValue($optionName, $forceDefaultValue);
485
+ }
486
+
487
+ public function getPopupTypeOptionsView()
488
+ {
489
+ $optionsViewData = array(
490
+ 'filePath' => SG_POPUP_TYPE_OPTIONS_PATH . 'subscription.php',
491
+ 'metaboxTitle' => 'Subscription Options'
492
+ );
493
+
494
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
495
+
496
+ if ($isSubscriptionPlusActive) {
497
+ return array();
498
+ }
499
+
500
+ return $optionsViewData;
501
+ }
502
+
503
+ private function getSubscriptionForm($subsFields)
504
+ {
505
+ $popupId = $this->getId();
506
+ $form = '<div class="sgpb-subs-form-'.$popupId.' sgpb-subscription-form">';
507
+ $form .= $this->getFormMessages();
508
+ $form .= Functions::renderForm($subsFields);
509
+ $form .= '</div>';
510
+
511
+ return $form;
512
+ }
513
+
514
+ private function getFormMessages()
515
+ {
516
+ $successMessage = $this->getOptionValue('sgpb-subs-success-message');
517
+ $errorMessage = $this->getOptionValue('sgpb-subs-error-message');
518
+ if (empty($errorMessage)) {
519
+ $errorMessage = SGPB_SUBSCRIPTION_ERROR_MESSAGE;
520
+ }
521
+ ob_start();
522
+ ?>
523
+ <div class="subs-form-messages sgpb-alert sgpb-alert-success sg-hide-element">
524
+ <p><?php echo $successMessage; ?></p>
525
+ </div>
526
+ <div class="subs-form-messages sgpb-alert sgpb-alert-danger sg-hide-element">
527
+ <p><?php echo $errorMessage; ?></p>
528
+ </div>
529
+ <?php
530
+ $messages = ob_get_contents();
531
+ ob_end_clean();
532
+
533
+ return $messages;
534
+ }
535
+
536
+ public function renderOptions($options)
537
+ {
538
+ // for old popups
539
+ if (isset($options['sgpb-subs-success-popup']) && function_exists('sgpb\sgpGetCorrectPopupId')) {
540
+ $options['sgpb-subs-success-popup'] = sgpGetCorrectPopupId($options['sgpb-subs-success-popup']);
541
+ }
542
+
543
+ return $options;
544
+ }
545
+
546
+ public function getPopupTypeContent()
547
+ {
548
+ $this->frontendFilters();
549
+
550
+ apply_filters('sgpbSubscriptionForm', $this);
551
+ $popupContent = $this->getContent();
552
+ $formContent = $this->getFormContent();
553
+ $showToTop = $this->getOptionValue('sgpb-subs-show-form-to-top');
554
+ $content = $popupContent.$formContent;
555
+
556
+ if ($showToTop) {
557
+ $content = $formContent.$popupContent;
558
+ }
559
+ return $content;
560
+ }
561
+
562
+ public function subscriptionForm($popupObj)
563
+ {
564
+ if (!is_object($popupObj)) {
565
+ return '';
566
+ }
567
+ $popupContent = '';
568
+ $popupOptions = $popupObj->getOptions();
569
+ $subsFields = $popupObj->getOptionValue('sgpb-subs-fields');
570
+ $isSubscriptionPlusActive = is_plugin_active(SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY);
571
+
572
+ if (empty($subsFields) || !$isSubscriptionPlusActive) {
573
+ $subsFields = $popupObj->createFormFieldsData();
574
+ }
575
+
576
+ $subsRequiredMessages = '';
577
+ if (!empty($popupOptions['sgpb-subs-validation-message'])) {
578
+ $subsRequiredMessages = $popupOptions['sgpb-subs-validation-message'];
579
+ }
580
+
581
+ $validationMessages = array(
582
+ 'requiredMessage' => $subsRequiredMessages
583
+ );
584
+
585
+ $styleData = array(
586
+ 'placeholderColor' => $popupOptions['sgpb-subs-text-placeholder-color'],
587
+ 'formColor' => $popupOptions['sgpb-subs-form-bg-color'],
588
+ 'formPadding' => @$popupOptions['sgpb-subs-form-padding'],
589
+ 'formBackgroundOpacity' => @$popupOptions['sgpb-subs-form-bg-opacity']
590
+ );
591
+
592
+ $validateScript = $popupObj->createValidateObj($subsFields, $validationMessages);
593
+ $popupContent .= $popupObj->getSubscriptionForm($subsFields);
594
+ $popupContent .= $popupObj->getSubscriptionValidationScripts($validateScript);
595
+ $popupContent .= $popupObj->getFormCustomStyles($styleData);
596
+
597
+ $popupObj->setFormContent($popupContent);
598
+
599
+ return $popupObj;
600
+ }
601
+
602
+ public function getSubPopupObj()
603
+ {
604
+ $options = $this->getOptions();
605
+ $subPopups = parent::getSubPopupObj();
606
+ if ($options['sgpb-subs-success-behavior'] == 'openPopup') {
607
+ $subPopupId = (!empty($options['sgpb-subs-success-popup'])) ? (int)$options['sgpb-subs-success-popup']: null;
608
+
609
+ if (empty($subPopupId)) {
610
+ return $subPopups;
611
+ }
612
+
613
+ // for old popups
614
+ if (function_exists('sgpb\sgpGetCorrectPopupId')) {
615
+ $subPopupId = sgpGetCorrectPopupId($subPopupId);
616
+ }
617
+
618
+ $subPopupObj = SGPopup::find($subPopupId);
619
+ if (!empty($subPopupObj) && ($subPopupObj instanceof SGPopup)) {
620
+ // We remove all events because this popup will be open after successful subscription
621
+ $subPopupObj->setEvents(array('param' => 'click', 'value' => ''));
622
+ $subPopups[] = $subPopupObj;
623
+ }
624
+ }
625
+
626
+ return $subPopups;
627
+ }
628
+
629
+ public function getExtraRenderOptions()
630
+ {
631
+ return array();
632
+ }
633
+
634
+ public static function getSubscribersCount()
635
+ {
636
+ global $wpdb;
637
+ $count = $wpdb->get_var('SELECT COUNT(*) FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME);
638
+
639
+ return (int)$count;
640
+ }
641
+
642
+ public static function getAllSubscriptions()
643
+ {
644
+ $popupArgs = array();
645
+ $popupArgs['type'][] = 'subscription';
646
+
647
+ $popupArgs = apply_filters('sgpbGetAllSubscriptionArgs', $popupArgs);
648
+ $allPopups = SGPopup::getAllPopups($popupArgs);
649
+
650
+ return $allPopups;
651
+ }
652
+
653
+ public static function getAllSubscriptionForms()
654
+ {
655
+ $subsFormList = array();
656
+ $subscriptionForms = self::getAllSubscriptions();
657
+
658
+ foreach ($subscriptionForms as $subscriptionForm) {
659
+ $title = $subscriptionForm->getTitle();
660
+ $id = $subscriptionForm->getId();
661
+ if ($title == '') {
662
+ $title = '('.__('no title', SG_POPUP_TEXT_DOMAIN).')';
663
+ }
664
+ $subsFormList[$id] = $title;
665
+ }
666
+
667
+ return $subsFormList;
668
+ }
669
+
670
+ public static function getAllSubscribersDate()
671
+ {
672
+ $subsDateList = array();
673
+ global $wpdb;
674
+ $subscriptionPopups = $wpdb->get_results('SELECT id, cDate FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME, ARRAY_A);
675
+
676
+ foreach ($subscriptionPopups as $subscriptionForm) {
677
+ $id = $subscriptionForm['id'];
678
+ $date = substr($subscriptionForm['cDate'], 0, 7);
679
+ $subsDateList[$id]['date-value'] = $date;
680
+ $subsDateList[$id]['date-title'] = AdminHelper::getFormattedDate($date);
681
+ }
682
+
683
+ return $subsDateList;
684
+ }
685
+ }
com/config/config.php CHANGED
@@ -1,173 +1,173 @@
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', 'http://bit.ly/sgpbPluginSource');
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_DATA_TABLES_PATH', SG_POPUP_CLASSES_PATH.'dataTable/');
65
- self::addDefine('SG_POPUP_CLASSES_POPUPS_PATH', SG_POPUP_CLASSES_PATH.'popups/');
66
- self::addDefine('SG_POPUP_EXTENSION_PATH', SG_POPUP_CLASSES_PATH.'extension/');
67
- self::addDefine('SG_POPUP_LIBS_PATH', SG_POPUP_COM_PATH.'libs/');
68
- self::addDefine('SG_POPUP_HELPERS_PATH', SG_POPUP_COM_PATH.'helpers/');
69
- self::addDefine('SG_POPUP_JS_PATH', SG_POPUP_PUBLIC_PATH.'js/');
70
- self::addDefine('SG_POPUP_CSS_PATH', SG_POPUP_PUBLIC_PATH.'css/');
71
- self::addDefine('SG_POPUP_VIEWS_PATH', SG_POPUP_PUBLIC_PATH.'views/');
72
- self::addDefine('SG_POPUP_TYPE_OPTIONS_PATH', SG_POPUP_VIEWS_PATH.'options/');
73
- self::addDefine('SG_POPUP_TYPE_MAIN_PATH', SG_POPUP_VIEWS_PATH.'main/');
74
- self::addDefine('SG_POPUP_PUBLIC_URL', SG_POPUP_BUILDER_URL.'public/');
75
- self::addDefine('SG_POPUP_JS_URL', SG_POPUP_PUBLIC_URL.'js/');
76
- self::addDefine('SG_POPUP_CSS_URL', SG_POPUP_PUBLIC_URL.'css/');
77
- self::addDefine('SG_POPUP_IMG_URL', SG_POPUP_PUBLIC_URL.'img/');
78
- self::addDefine('SG_POPUP_SOUND_URL', SG_POPUP_PUBLIC_URL.'sound/');
79
- self::addDefine('SG_POPUP_VIEWS_URL', SG_POPUP_PUBLIC_URL.'views/');
80
- self::addDefine('SG_POPUP_EMAIL_TEMPLATES_URL', SG_POPUP_VIEWS_URL.'emailTemplates/');
81
- self::addDefine('SG_POPUP_DEFAULT_TIME_ZONE', 'UTC');
82
- self::addDefine('SG_POPUP_CATEGORY_TAXONOMY', 'popup-categories');
83
- self::addDefine('SG_POPUP_MINIMUM_PHP_VERSION', '5.3.3');
84
- self::addDefine('SG_POPUP_POST_TYPE', 'popupbuilder');
85
- self::addDefine('SG_POPUP_NEWSLETTER_PAGE', 'sgpbNewsletter');
86
- self::addDefine('SG_POPUP_SETTINGS_PAGE', 'sgpbSettings');
87
- self::addDefine('SG_POPUP_SUBSCRIBERS_PAGE', 'sgpbSubscribers');
88
- self::addDefine('SG_POPUP_SUPPORT_PAGE', 'sgpbSupport');
89
- self::addDefine('SGPB_POPUP_LICENSE', 'license');
90
- self::addDefine('SG_POPUP_EXTEND_PAGE', 'extend');
91
- self::addDefine('SGPB_FILTER_REPEAT_INTERVAL', 50);
92
- self::addDefine('SG_POPUP_TEXT_DOMAIN', 'popup-builder');
93
- self::addDefine('SG_POPUP_STORE_URL', 'https://popup-builder.com/');
94
- self::addDefine('SG_POPUP_AUTHOR', 'Sygnoos');
95
- self::addDefine('SG_POPUP_KEY', 'POPUP_BUILDER');
96
- self::addDefine('SG_AJAX_NONCE', 'popupBuilderAjaxNonce');
97
- self::addDefine('SG_CONDITION_FIRST_RULE', 0);
98
- self::addDefine('SGPB_AJAX_STATUS_FALSE', 0);
99
- self::addDefine('SGPB_AJAX_STATUS_TRUE', 1);
100
- self::addDefine('SGPB_SUBSCRIBERS_TABLE_NAME', 'sgpb_subscribers');
101
- self::addDefine('SGPB_POSTS_TABLE_NAME', 'posts');
102
- self::addDefine('SGPB_APP_POPUP_TABLE_LIMIT', 15);
103
- self::addDefine('SGPB_SUBSCRIBERS_ERROR_TABLE_NAME', 'sgpb_subscription_error_log');
104
- self::addDefine('SGPB_CRON_REPEAT_INTERVAL', 1);
105
- self::addDefine('SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL', 1);
106
- self::addDefine('SGPB_METABOX_BANNER_CRON_TEXT_URL', 'https://popup-builder.com/sgpb-banner.php?banner=sidebar1');
107
- self::addDefine('SGPB_FACEBOOK_APP_ID', 540547196484707);
108
- self::addDefine('SGPB_POPUP_TYPE_RESTRICTION', 'ageRestriction');
109
- self::addDefine('SGPB_POPUP_DEFAULT_SOUND', 'popupOpenSound.wav');
110
- self::addDefine('SGPB_POPUP_EXTENSIONS_PATH', SG_POPUP_COM_PATH.'extensions/');
111
- self::addDefine('SG_POPUP_BUILDER_NOTIFICATIONS_URL', 'https://popup-builder.com/notifications.json');
112
- self::addDefine('SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY', 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php');
113
- self::addDefine('SGPB_DONT_SHOW_POPUP_EXPIRY', 365);
114
- self::addDefine('SGPB_CONTACT_FORM_7_BEHAVIOR_KEY', 'contact-form-7');
115
- self::addDefine('SGPB_CSS_CLASS_ACTIONS_KEY', 'setByCssClass');
116
- self::addDefine('SGPB_CLICK_ACTION_KEY', 'setByClick');
117
- self::addDefine('SGPB_HOVER_ACTION_KEY', 'setByHover');
118
- self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_SHOW', 1);
119
- self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_HIDE', 2);
120
- self::addDefine('SGPB_POPUP_SCHEDULING_EXTENSION_KEY', 'popupbuilder-scheduling/PopupBuilderScheduling.php');
121
- self::addDefine('SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY', 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php');
122
- self::addDefine('SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY', 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php');
123
- self::addDefine('SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY', 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php');
124
- self::addDefine('SGPB_ASK_REVIEW_POPUP_COUNT', 80);
125
- self::addDefine('SGPB_REVIEW_POPUP_PERIOD', 30);
126
- self::addDefine('SGPB_POPUP_EXPORT_FILE_NAME', 'PopupBuilderPopups.xml');
127
- self::addDefine('SG_POPUP_AUTORESPONDER_POST_TYPE', 'sgpbautoresponder');
128
- self::addDefine('SGPB_INACTIVE_EXTENSIONS', 'inactivePBExtensions');
129
- self::addDefine('SGPB_POPUP_LICENSE_SCREEN', SG_POPUP_POST_TYPE.'_page_'.SGPB_POPUP_LICENSE);
130
- self::addDefine('SGPB_SUBSCRIPTION_ERROR_MESSAGE', __('There was an error while trying to send your request. Please try again', SG_POPUP_TEXT_DOMAIN).'.');
131
- self::addDefine('SGPB_SUBSCRIPTION_VALIDATION_MESSAGE', __('This field is required', SG_POPUP_TEXT_DOMAIN).'.');
132
- self::addDefine('SGPB_SUBSCRIPTION_EMAIL_MESSAGE', __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
133
- self::addDefine('SGPB_TRANSIENT_TIMEOUT_HOUR', 60 * MINUTE_IN_SECONDS);
134
- self::addDefine('SGPB_TRANSIENT_TIMEOUT_DAY', 24 * HOUR_IN_SECONDS);
135
- self::addDefine('SGPB_TRANSIENT_TIMEOUT_WEEK', 7 * DAY_IN_SECONDS);
136
- self::addDefine('SGPB_TRANSIENT_POPUPS_LOAD', 'sgpbLoadPopups');
137
- self::addDefine('SGPB_TRANSIENT_POPUPS_TERMS', 'sgpbGetPopupsByTermSlug');
138
- self::addDefine('SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES', 'sgpbGetPostsAllCategories');
139
- self::addDefine('SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED', 'sgpbModifiedRegisteredPluginsPaths2');
140
- self::addDefine('SGPB_POPUP_BUILDER_REGISTERED_PLUGINS', 'sgpbPopupBuilderRegisteredPlugins');
141
- self::addDefine('SGPB_RATE_US_NOTIFICATION_ID', 'sgpbMainRateUsNotification');
142
- self::addDefine('SGPB_SUPPORT_BANNER_NOTIFICATION_ID', 'sgpbMainSupportBanner');
143
- self::popupTypesInit();
144
- }
145
-
146
- public static function popupTypesInit()
147
- {
148
- global $SGPB_POPUP_TYPES;
149
-
150
- $SGPB_POPUP_TYPES['typeName'] = apply_filters('sgpbAddPopupType', array(
151
- 'image' => SGPB_POPUP_PKG_FREE,
152
- 'html' => SGPB_POPUP_PKG_FREE,
153
- 'fblike' => SGPB_POPUP_PKG_FREE,
154
- 'subscription' => SGPB_POPUP_PKG_FREE
155
- ));
156
-
157
- $SGPB_POPUP_TYPES['typePath'] = apply_filters('sgpbAddPopupTypePath', array(
158
- 'image' => SG_POPUP_CLASSES_POPUPS_PATH,
159
- 'html' => SG_POPUP_CLASSES_POPUPS_PATH,
160
- 'fblike' => SG_POPUP_CLASSES_POPUPS_PATH,
161
- 'subscription' => SG_POPUP_CLASSES_POPUPS_PATH
162
- ));
163
-
164
- $SGPB_POPUP_TYPES['typeLabels'] = apply_filters('sgpbAddPopupTypeLabels', array(
165
- 'image' => __('Image', SG_POPUP_TEXT_DOMAIN),
166
- 'html' => __('HTML', SG_POPUP_TEXT_DOMAIN),
167
- 'fblike' => __('Facebook', SG_POPUP_TEXT_DOMAIN),
168
- 'subscription' => __('Subscription', SG_POPUP_TEXT_DOMAIN)
169
- ));
170
- }
171
- }
172
-
173
- 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', 'http://bit.ly/sgpbPluginSource');
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_DATA_TABLES_PATH', SG_POPUP_CLASSES_PATH.'dataTable/');
65
+ self::addDefine('SG_POPUP_CLASSES_POPUPS_PATH', SG_POPUP_CLASSES_PATH.'popups/');
66
+ self::addDefine('SG_POPUP_EXTENSION_PATH', SG_POPUP_CLASSES_PATH.'extension/');
67
+ self::addDefine('SG_POPUP_LIBS_PATH', SG_POPUP_COM_PATH.'libs/');
68
+ self::addDefine('SG_POPUP_HELPERS_PATH', SG_POPUP_COM_PATH.'helpers/');
69
+ self::addDefine('SG_POPUP_JS_PATH', SG_POPUP_PUBLIC_PATH.'js/');
70
+ self::addDefine('SG_POPUP_CSS_PATH', SG_POPUP_PUBLIC_PATH.'css/');
71
+ self::addDefine('SG_POPUP_VIEWS_PATH', SG_POPUP_PUBLIC_PATH.'views/');
72
+ self::addDefine('SG_POPUP_TYPE_OPTIONS_PATH', SG_POPUP_VIEWS_PATH.'options/');
73
+ self::addDefine('SG_POPUP_TYPE_MAIN_PATH', SG_POPUP_VIEWS_PATH.'main/');
74
+ self::addDefine('SG_POPUP_PUBLIC_URL', SG_POPUP_BUILDER_URL.'public/');
75
+ self::addDefine('SG_POPUP_JS_URL', SG_POPUP_PUBLIC_URL.'js/');
76
+ self::addDefine('SG_POPUP_CSS_URL', SG_POPUP_PUBLIC_URL.'css/');
77
+ self::addDefine('SG_POPUP_IMG_URL', SG_POPUP_PUBLIC_URL.'img/');
78
+ self::addDefine('SG_POPUP_SOUND_URL', SG_POPUP_PUBLIC_URL.'sound/');
79
+ self::addDefine('SG_POPUP_VIEWS_URL', SG_POPUP_PUBLIC_URL.'views/');
80
+ self::addDefine('SG_POPUP_EMAIL_TEMPLATES_URL', SG_POPUP_VIEWS_URL.'emailTemplates/');
81
+ self::addDefine('SG_POPUP_DEFAULT_TIME_ZONE', 'UTC');
82
+ self::addDefine('SG_POPUP_CATEGORY_TAXONOMY', 'popup-categories');
83
+ self::addDefine('SG_POPUP_MINIMUM_PHP_VERSION', '5.3.3');
84
+ self::addDefine('SG_POPUP_POST_TYPE', 'popupbuilder');
85
+ self::addDefine('SG_POPUP_NEWSLETTER_PAGE', 'sgpbNewsletter');
86
+ self::addDefine('SG_POPUP_SETTINGS_PAGE', 'sgpbSettings');
87
+ self::addDefine('SG_POPUP_SUBSCRIBERS_PAGE', 'sgpbSubscribers');
88
+ self::addDefine('SG_POPUP_SUPPORT_PAGE', 'sgpbSupport');
89
+ self::addDefine('SGPB_POPUP_LICENSE', 'license');
90
+ self::addDefine('SG_POPUP_EXTEND_PAGE', 'extend');
91
+ self::addDefine('SGPB_FILTER_REPEAT_INTERVAL', 50);
92
+ self::addDefine('SG_POPUP_TEXT_DOMAIN', 'popup-builder');
93
+ self::addDefine('SG_POPUP_STORE_URL', 'https://popup-builder.com/');
94
+ self::addDefine('SG_POPUP_AUTHOR', 'Sygnoos');
95
+ self::addDefine('SG_POPUP_KEY', 'POPUP_BUILDER');
96
+ self::addDefine('SG_AJAX_NONCE', 'popupBuilderAjaxNonce');
97
+ self::addDefine('SG_CONDITION_FIRST_RULE', 0);
98
+ self::addDefine('SGPB_AJAX_STATUS_FALSE', 0);
99
+ self::addDefine('SGPB_AJAX_STATUS_TRUE', 1);
100
+ self::addDefine('SGPB_SUBSCRIBERS_TABLE_NAME', 'sgpb_subscribers');
101
+ self::addDefine('SGPB_POSTS_TABLE_NAME', 'posts');
102
+ self::addDefine('SGPB_APP_POPUP_TABLE_LIMIT', 15);
103
+ self::addDefine('SGPB_SUBSCRIBERS_ERROR_TABLE_NAME', 'sgpb_subscription_error_log');
104
+ self::addDefine('SGPB_CRON_REPEAT_INTERVAL', 1);
105
+ self::addDefine('SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL', 1);
106
+ self::addDefine('SGPB_METABOX_BANNER_CRON_TEXT_URL', 'https://popup-builder.com/sgpb-banner.php?banner=sidebar1');
107
+ self::addDefine('SGPB_FACEBOOK_APP_ID', 540547196484707);
108
+ self::addDefine('SGPB_POPUP_TYPE_RESTRICTION', 'ageRestriction');
109
+ self::addDefine('SGPB_POPUP_DEFAULT_SOUND', 'popupOpenSound.wav');
110
+ self::addDefine('SGPB_POPUP_EXTENSIONS_PATH', SG_POPUP_COM_PATH.'extensions/');
111
+ self::addDefine('SG_POPUP_BUILDER_NOTIFICATIONS_URL', 'https://popup-builder.com/notifications.json');
112
+ self::addDefine('SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY', 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php');
113
+ self::addDefine('SGPB_DONT_SHOW_POPUP_EXPIRY', 365);
114
+ self::addDefine('SGPB_CONTACT_FORM_7_BEHAVIOR_KEY', 'contact-form-7');
115
+ self::addDefine('SGPB_CSS_CLASS_ACTIONS_KEY', 'setByCssClass');
116
+ self::addDefine('SGPB_CLICK_ACTION_KEY', 'setByClick');
117
+ self::addDefine('SGPB_HOVER_ACTION_KEY', 'setByHover');
118
+ self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_SHOW', 1);
119
+ self::addDefine('SG_COUNTDOWN_COUNTER_SECONDS_HIDE', 2);
120
+ self::addDefine('SGPB_POPUP_SCHEDULING_EXTENSION_KEY', 'popupbuilder-scheduling/PopupBuilderScheduling.php');
121
+ self::addDefine('SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY', 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php');
122
+ self::addDefine('SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY', 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php');
123
+ self::addDefine('SGPB_POPUP_SUBSCRIPTION_PLUS_EXTENSION_KEY', 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php');
124
+ self::addDefine('SGPB_ASK_REVIEW_POPUP_COUNT', 80);
125
+ self::addDefine('SGPB_REVIEW_POPUP_PERIOD', 30);
126
+ self::addDefine('SGPB_POPUP_EXPORT_FILE_NAME', 'PopupBuilderPopups.xml');
127
+ self::addDefine('SG_POPUP_AUTORESPONDER_POST_TYPE', 'sgpbautoresponder');
128
+ self::addDefine('SGPB_INACTIVE_EXTENSIONS', 'inactivePBExtensions');
129
+ self::addDefine('SGPB_POPUP_LICENSE_SCREEN', SG_POPUP_POST_TYPE.'_page_'.SGPB_POPUP_LICENSE);
130
+ self::addDefine('SGPB_SUBSCRIPTION_ERROR_MESSAGE', __('There was an error while trying to send your request. Please try again', SG_POPUP_TEXT_DOMAIN).'.');
131
+ self::addDefine('SGPB_SUBSCRIPTION_VALIDATION_MESSAGE', __('This field is required', SG_POPUP_TEXT_DOMAIN).'.');
132
+ self::addDefine('SGPB_SUBSCRIPTION_EMAIL_MESSAGE', __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
133
+ self::addDefine('SGPB_TRANSIENT_TIMEOUT_HOUR', 60 * MINUTE_IN_SECONDS);
134
+ self::addDefine('SGPB_TRANSIENT_TIMEOUT_DAY', 24 * HOUR_IN_SECONDS);
135
+ self::addDefine('SGPB_TRANSIENT_TIMEOUT_WEEK', 7 * DAY_IN_SECONDS);
136
+ self::addDefine('SGPB_TRANSIENT_POPUPS_LOAD', 'sgpbLoadPopups');
137
+ self::addDefine('SGPB_TRANSIENT_POPUPS_TERMS', 'sgpbGetPopupsByTermSlug');
138
+ self::addDefine('SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES', 'sgpbGetPostsAllCategories');
139
+ self::addDefine('SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED', 'sgpbModifiedRegisteredPluginsPaths2');
140
+ self::addDefine('SGPB_POPUP_BUILDER_REGISTERED_PLUGINS', 'sgpbPopupBuilderRegisteredPlugins');
141
+ self::addDefine('SGPB_RATE_US_NOTIFICATION_ID', 'sgpbMainRateUsNotification');
142
+ self::addDefine('SGPB_SUPPORT_BANNER_NOTIFICATION_ID', 'sgpbMainSupportBanner');
143
+ self::popupTypesInit();
144
+ }
145
+
146
+ public static function popupTypesInit()
147
+ {
148
+ global $SGPB_POPUP_TYPES;
149
+
150
+ $SGPB_POPUP_TYPES['typeName'] = apply_filters('sgpbAddPopupType', array(
151
+ 'image' => SGPB_POPUP_PKG_FREE,
152
+ 'html' => SGPB_POPUP_PKG_FREE,
153
+ 'fblike' => SGPB_POPUP_PKG_FREE,
154
+ 'subscription' => SGPB_POPUP_PKG_FREE
155
+ ));
156
+
157
+ $SGPB_POPUP_TYPES['typePath'] = apply_filters('sgpbAddPopupTypePath', array(
158
+ 'image' => SG_POPUP_CLASSES_POPUPS_PATH,
159
+ 'html' => SG_POPUP_CLASSES_POPUPS_PATH,
160
+ 'fblike' => SG_POPUP_CLASSES_POPUPS_PATH,
161
+ 'subscription' => SG_POPUP_CLASSES_POPUPS_PATH
162
+ ));
163
+
164
+ $SGPB_POPUP_TYPES['typeLabels'] = apply_filters('sgpbAddPopupTypeLabels', array(
165
+ 'image' => __('Image', SG_POPUP_TEXT_DOMAIN),
166
+ 'html' => __('HTML', SG_POPUP_TEXT_DOMAIN),
167
+ 'fblike' => __('Facebook', SG_POPUP_TEXT_DOMAIN),
168
+ 'subscription' => __('Subscription', SG_POPUP_TEXT_DOMAIN)
169
+ ));
170
+ }
171
+ }
172
+
173
+ 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', '3.73');
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', '3.74');
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,978 +1,978 @@
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', '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',
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',
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', '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', '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',
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',
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
-
494
- $keys[] = array(
495
- 'label' => __('Age Restriction', SG_POPUP_TEXT_DOMAIN),
496
- 'pluginKey' => 'popupbuilder-age-verification/PopupBuilderAgeverification.php',
497
- 'key' => 'ageVerification',
498
- 'url' => SGPB_AGE_VERIFICATION_PLUGIN_URL
499
- );
500
- $keys[] = array(
501
- 'label' => __('Gamification', SG_POPUP_TEXT_DOMAIN),
502
- 'pluginKey' => 'popupbuilder-gamification/PopupBuilderGamification.php',
503
- 'key' => 'gamification',
504
- 'url' => SGPB_GAMIFICATION_PLUGIN_URL
505
- );
506
- $keys[] = array(
507
- 'label' => __('PDF', SG_POPUP_TEXT_DOMAIN),
508
- 'pluginKey' => 'popupbuilder-pdf/PopupBuilderPdf.php',
509
- 'key' => 'pdf',
510
- 'url' => SGPB_PDF_PLUGIN_URL
511
- );
512
- $keys[] = array(
513
- 'label' => __('Push Notification', SG_POPUP_TEXT_DOMAIN),
514
- 'pluginKey' => 'popupbuilder-push-notification/PopupBuilderPushNotification.php',
515
- 'key' => 'pushNotification',
516
- 'url' => SG_POPUP_PUSH_NOTIFICATION_URL
517
- );
518
- $keys[] = array(
519
- 'label' => __('EDD', SG_POPUP_TEXT_DOMAIN),
520
- 'pluginKey' => 'popupbuilder-edd/PopupBuilderEdd.php',
521
- 'key' => 'edd',
522
- 'url' => SGPB_EDD_PLUGIN_URL
523
- );
524
- $keys[] = array(
525
- 'label' => __('Scheduling', SG_POPUP_TEXT_DOMAIN),
526
- 'pluginKey' => 'popupbuilder-scheduling/PopupBuilderScheduling.php',
527
- 'key' => 'scheduling',
528
- 'url' => SG_POPUP_SCHEDULING_URL
529
- );
530
- $keys[] = array(
531
- 'label' => __('Geo Targeting', SG_POPUP_TEXT_DOMAIN),
532
- 'pluginKey' => 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php',
533
- 'key' => 'geo-targeting',
534
- 'url' => SG_POPUP_GEO_TARGETING_URL
535
- );
536
- $keys[] = array(
537
- 'label' => __('Iframe', SG_POPUP_TEXT_DOMAIN),
538
- 'pluginKey' => 'popupbuilder-iframe/PopupBuilderIframe.php',
539
- 'key' => 'iframe',
540
- 'url' => SG_POPUP_IFRAME_URL
541
- );
542
- $keys[] = array(
543
- 'label' => __('Social', SG_POPUP_TEXT_DOMAIN),
544
- 'pluginKey' => 'popupbuilder-social/PopupBuilderSocial.php',
545
- 'key' => 'social',
546
- 'url' => SG_POPUP_SOCIAL_URL
547
- );
548
- $keys[] = array(
549
- 'label' => __('Video', SG_POPUP_TEXT_DOMAIN),
550
- 'pluginKey' => 'popupbuilder-video/PopupBuilderVideo.php',
551
- 'key' => 'video',
552
- 'url' => SG_POPUP_VIDEO_URL
553
- );
554
- $keys[] = array(
555
- 'label' => __('Countdown', SG_POPUP_TEXT_DOMAIN),
556
- 'pluginKey' => 'popupbuilder-countdown/PopupBuilderCountdown.php',
557
- 'key' => 'countdown',
558
- 'url' => SG_POPUP_COUNTDOWN_URL
559
- );
560
- $keys[] = array(
561
- 'label' => __('Restriction', SG_POPUP_TEXT_DOMAIN),
562
- 'pluginKey' => 'popupbuilder-restriction/PopupBuilderAgerestriction.php',
563
- 'key' => 'ageRestriction',
564
- 'url' => SG_POPUP_RESTRICTION_URL
565
- );
566
- $keys[] = array(
567
- 'label' => __('Contact Form', SG_POPUP_TEXT_DOMAIN),
568
- 'pluginKey' => 'popupbuilder-contact-form/PopupBuilderContactForm.php',
569
- 'key' => 'contactForm',
570
- 'url' => SG_POPUP_CONTACT_FORM_URL
571
- );
572
- $keys[] = array(
573
- 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN),
574
- 'pluginKey' => 'popupbuilder-adblock/PopupBuilderAdBlock.php',
575
- 'key' => 'sgpbAdBlock',
576
- 'url' => SG_POPUP_AD_BLOCK_URL
577
- );
578
- $keys[] = array(
579
- 'label' => __('Scroll', SG_POPUP_TEXT_DOMAIN),
580
- 'pluginKey' => 'popupbuilder-scroll/PopupBuilderScroll.php',
581
- 'key' => 'sgpbScroll',
582
- 'url' => SG_POPUP_SCROLL_URL
583
- );
584
- $keys[] = array(
585
- 'label' => __('Advanced Closing', SG_POPUP_TEXT_DOMAIN),
586
- 'pluginKey' => 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php',
587
- 'key' => 'advancedClosing',
588
- 'url' => SG_POPUP_ADVANCED_CLOSING_URL
589
- );
590
- $keys[] = array(
591
- 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN),
592
- 'pluginKey' => 'popupbuilder-analytics/PopupBuilderAnalytics.php',
593
- 'key' => 'sgpbAnalitics',
594
- 'url' => SG_POPUP_ANALYTICS_URL
595
- );
596
- $keys[] = array(
597
- 'label' => __('Inactivity', SG_POPUP_TEXT_DOMAIN),
598
- 'pluginKey' => 'popupbuilder-inactivity/PopupBuilderInactivity.php',
599
- 'key' => 'sgpbInactivity',
600
- 'url' => SG_POPUP_INACTIVITY_URL
601
- );
602
- $keys[] = array(
603
- 'label' => __('Exit Intent',SG_POPUP_TEXT_DOMAIN),
604
- 'pluginKey' => 'popupbuilder-exit-intent/PopupBuilderExitIntent.php',
605
- 'key' => 'sgpbExitIntent',
606
- 'url' => SG_POPUP_EXIT_INTENT_URL
607
- );
608
- $keys[] = array(
609
- 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN),
610
- 'pluginKey' => 'popupbuilder-mailchimp/PopupBuilderMailchimp.php',
611
- 'key' => 'sgpbMailchimp',
612
- 'url' => SG_POPUP_MAILCHIMP_URL
613
- );
614
- $keys[] = array(
615
- 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN),
616
- 'pluginKey' => 'popupbuilder-aweber/PopupBuilderAWeber.php',
617
- 'key' => 'sgpbAWeber',
618
- 'url' => SG_POPUP_AWEBER_URL
619
- );
620
- $keys[] = array(
621
- 'label' => __('Random', SG_POPUP_TEXT_DOMAIN),
622
- 'pluginKey' => 'popupbuilder-random/PopupBuilderRandom.php',
623
- 'key' => 'sgpbRandom',
624
- 'url' => SG_POPUP_RANDOM_URL
625
- );
626
- $keys[] = array(
627
- 'label' => __('WooCommerce', SG_POPUP_TEXT_DOMAIN),
628
- 'pluginKey' => 'popupbuilder-woocommerce/popupbuilderWoocommerce.php',
629
- 'key' => 'sgpbWOO',
630
- 'url' => SG_POPUP_WOOCOMMERCE_URL
631
- );
632
- $keys[] = array(
633
- 'label' => __('Recent Sales', SG_POPUP_TEXT_DOMAIN),
634
- 'pluginKey' => 'popupbuilder-recent-sales/PopupBuilderRecentSales.php',
635
- 'key' => 'sgpbRecentSales',
636
- 'url' => SG_POPUP_RECENT_SALES_URL
637
- );
638
- $keys[] = array(
639
- 'label' => __('Advanced Targeting', SG_POPUP_TEXT_DOMAIN),
640
- 'pluginKey' => 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php',
641
- 'key' => 'sgpbAdvancedTargeting',
642
- 'url' => SG_POPUP_ADVANCED_TARGETING_URL
643
- );
644
- $keys[] = array(
645
- 'label' => __('Log In', SG_POPUP_TEXT_DOMAIN),
646
- 'pluginKey' => 'popupbuilder-login/PopupBuilderLogin.php',
647
- 'key' => 'login',
648
- 'url' => SG_POPUP_LOGIN_URL
649
- );
650
- $keys[] = array(
651
- 'label' => __('Registration', SG_POPUP_TEXT_DOMAIN),
652
- 'pluginKey' => 'popupbuilder-registration/PopupBuilderRegistration.php',
653
- 'key' => 'registration',
654
- 'url' => SG_POPUP_REGISTRATION_URL
655
- );
656
- $keys[] = array(
657
- 'label' => __('Subscription Plus', SG_POPUP_TEXT_DOMAIN),
658
- 'pluginKey' => 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php',
659
- 'key' => 'subscriptionPlus',
660
- 'url' => SG_POPUP_SUBSCRIPTION_PLUS_URL
661
- );
662
-
663
- return apply_filters('sgpbExtensionsKeys', $keys);
664
- }
665
-
666
- private static function getBehaviorAfterSpecialEventsConfig()
667
- {
668
- $columns = array(
669
- 'param' => 'Event',
670
- 'operator' => 'Behavior',
671
- 'value' => 'Value'
672
- );
673
-
674
- $columnTypes = array(
675
- 'param' => 'select',
676
- 'operator' => 'select',
677
- 'value' => 'select',
678
- 'select_event' => 'select',
679
- 'select_behavior' => 'select',
680
- 'redirect-url' => 'url',
681
- 'open-popup' => 'select',
682
- 'close-popup' => 'number'
683
- );
684
-
685
- $params = array(
686
- 'param' => array(
687
- 'select_event' => __('Select event', SG_POPUP_TEXT_DOMAIN),
688
- __('Special events', SG_POPUP_TEXT_DOMAIN) => array(
689
- SGPB_CONTACT_FORM_7_BEHAVIOR_KEY => __('Contact Form 7 submission', SG_POPUP_TEXT_DOMAIN)
690
- )
691
- ),
692
- 'operator' => array(
693
- 'select_behavior' => __('Select behavior', SG_POPUP_TEXT_DOMAIN),
694
- __('Behaviors', SG_POPUP_TEXT_DOMAIN) => array(
695
- 'redirect-url' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN),
696
- 'open-popup' => __('Open another popup', SG_POPUP_TEXT_DOMAIN),
697
- 'close-popup' => __('Close current popup', SG_POPUP_TEXT_DOMAIN)
698
- )
699
- ),
700
- 'redirect-url' => '',
701
- 'open-popup' => array(),
702
- 'close-popup' => '',
703
- 'select_event' => null,
704
- 'select_behavior' => null
705
- );
706
-
707
- $initialData = array(
708
- array(
709
- 'param' => 'select_event',
710
- 'operator' => ''
711
- )
712
- );
713
-
714
- $attrs = array(
715
- 'param' => array(
716
- 'htmlAttrs' => array(
717
- 'class' => 'js-sg-select2 js-select-basic',
718
- 'data-select-class' => 'js-select-basic',
719
- 'data-select-type' => 'basic'
720
- ),
721
- 'infoAttrs' => array(
722
- 'label' => __('Event', SG_POPUP_TEXT_DOMAIN),
723
- 'info' => __('Select the special event you want to catch.', SG_POPUP_TEXT_DOMAIN)
724
- )
725
- ),
726
- 'operator' => array(
727
- 'htmlAttrs' => array(
728
- 'class' => 'js-sg-select2 js-select-basic',
729
- 'data-select-class' => 'js-select-basic',
730
- 'data-select-type' => 'basic'
731
- ),
732
- 'infoAttrs' => array(
733
- 'label' => __('Behavior', SG_POPUP_TEXT_DOMAIN),
734
- 'info' => __('Select what should happen after the special event.', SG_POPUP_TEXT_DOMAIN)
735
- )
736
- ),
737
- 'redirect-url' => array(
738
- 'htmlAttrs' => array(
739
- 'class' => 'sg-full-width',
740
- 'placeholder' => 'https://www.example.com',
741
- 'required' => 'required'
742
- ),
743
- 'infoAttrs' => array(
744
- 'label' => __('URL', SG_POPUP_TEXT_DOMAIN),
745
- 'info' => __('Enter the URL of the page should be redirected to.', SG_POPUP_TEXT_DOMAIN)
746
- )
747
- ),
748
- 'open-popup' => array(
749
- 'htmlAttrs' => array(
750
- 'class' => 'js-sg-select2 js-select-ajax',
751
- 'data-select-class' => 'js-select-ajax',
752
- 'data-select-type' => 'ajax',
753
- 'data-value-param' => SG_POPUP_POST_TYPE,
754
- 'required' => 'required'
755
- ),
756
- 'infoAttrs' => array(
757
- 'label' => __('Select popup', SG_POPUP_TEXT_DOMAIN),
758
- 'info' => __('Select the popup that should be opened.', SG_POPUP_TEXT_DOMAIN)
759
- )
760
- ),
761
- 'close-popup' => array(
762
- 'htmlAttrs' => array(
763
- 'class' => 'sg-full-width',
764
- 'required' => 'required',
765
- 'value' => 0,
766
- 'min' => 0
767
- ),
768
- 'infoAttrs' => array(
769
- 'label' => __('Delay', SG_POPUP_TEXT_DOMAIN),
770
- 'info' => __('After how many seconds the popup should close.', SG_POPUP_TEXT_DOMAIN)
771
- )
772
- )
773
- );
774
-
775
- $config = array();
776
- $config['columns'] = apply_filters('sgPopupSpecialEventsColumns', $columns);
777
- $config['columnTypes'] = apply_filters('sgPopupSpecialEventsColumnTypes', $columnTypes);
778
- $config['paramsData'] = apply_filters('sgPopupSpecialEventsParams', $params);
779
- $config['initialData'] = apply_filters('sgPopupSpecialEventsInitialData', $initialData);
780
- $config['attrs'] = apply_filters('sgPopupSpecialEventsAttrs', $attrs);
781
- $config['operators'] = apply_filters('sgpbPopupSpecialEventsOperators', array());
782
- $config['specialDefaultOperator'] = apply_filters('sgpbPopupSpecialEventsDefaultOperators', ' ');
783
-
784
- return $config;
785
- }
786
-
787
- public static function popupDefaultOptions()
788
- {
789
- global $SGPB_OPTIONS;
790
- global $SGPB_DATA_CONFIG_ARRAY;
791
-
792
- $targetDefaultValue = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
793
-
794
- $eventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['events']['initialData']);
795
- $conditionsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['conditions']['initialData']);
796
- $specialEventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['behavior-after-special-events']['initialData']);
797
-
798
- $options = array();
799
-
800
- $options[] = array('name' => 'sgpb-target', 'type' => 'array', 'defaultValue' => $targetDefaultValue);
801
- $options[] = array('name' => 'sgpb-events', 'type' => 'array', 'defaultValue' => $eventsDefaultData);
802
- $options[] = array('name' => 'sgpb-conditions', 'type' => 'array', 'defaultValue' => $conditionsDefaultData, 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
803
- $options[] = array('name' => 'sgpb-behavior-after-special-events', 'type' => 'array', 'defaultValue' => $specialEventsDefaultData);
804
- $options[] = array('name' => 'sgpb-type', 'type' => 'text', 'defaultValue' => 'html');
805
- $options[] = array('name' => 'sgpb-popup-counting-disabled', 'type' => 'checkbox', 'defaultValue' => '');
806
- $options[] = array('name' => 'sgpb-esc-key', 'type' => 'checkbox', 'defaultValue' => 'on');
807
- $options[] = array('name' => 'sgpb-enable-close-button', 'type' => 'checkbox', 'defaultValue' => 'on');
808
- $options[] = array('name' => 'sgpb-enable-content-scrolling', 'type' => 'checkbox', 'defaultValue' => 'on');
809
- $options[] = array('name' => 'sgpb-overlay-click', 'type' => 'checkbox', 'defaultValue' => 'on');
810
- $options[] = array('name' => 'sgpb-content-click', 'type' => 'checkbox', 'defaultValue' => '');
811
- $options[] = array('name' => 'sgpb-subs-hide-subs-users', 'type' => 'checkbox', 'defaultValue' => 'on');
812
- $options[] = array('name' => 'sgpb-content-click-behavior', 'type' => 'text', 'defaultValue' => 'close');
813
- $options[] = array('name' => 'sgpb-click-redirect-to-url', 'type' => 'text', 'defaultValue' => '');
814
- $options[] = array('name' => 'sgpb-redirect-to-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
815
- $options[] = array('name' => 'sgpb-copy-to-clipboard-text', 'type' => 'text', 'defaultValue' => '');
816
- $options[] = array('name' => 'sgpb-copy-to-clipboard-close-popup', 'type' => 'checkbox', 'defaultValue' => 'on');
817
- $options[] = array('name' => 'sgpb-copy-to-clipboard-alert', 'type' => 'checkbox', 'defaultValue' => 'on');
818
- $options[] = array('name' => 'sgpb-copy-to-clipboard-message', 'type' => 'text', 'defaultValue' => __('Copied to Clipboard!', SG_POPUP_TEXT_DOMAIN));
819
- $options[] = array('name' => 'sgpb-disable-popup-closing', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
820
- $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => 'responsiveMode');
821
- $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => '100');
822
- $options[] = array('name' => 'sgpb-width', 'type' => 'text', 'defaultValue' => '640px');
823
- $options[] = array('name' => 'sgpb-height', 'type' => 'text', 'defaultValue' => '480px');
824
- $options[] = array('name' => 'sgpb-max-width', 'type' => 'text', 'defaultValue' => '');
825
- $options[] = array('name' => 'sgpb-max-height', 'type' => 'text', 'defaultValue' => '');
826
- $options[] = array('name' => 'sgpb-min-width', 'type' => 'text', 'defaultValue' => '120');
827
- $options[] = array('name' => 'sgpb-min-height', 'type' => 'text', 'defaultValue' => '');
828
- $options[] = array('name' => 'sgpb-popup-timer-status', 'type' => 'checkbox', 'defaultValue' => '');
829
- $options[] = array('name' => 'sgpb-popup-start-timer', 'type' => 'text', 'defaultValue' => '');
830
- $options[] = array('name' => 'sgpb-popup-end-timer', 'type' => 'text', 'defaultValue' => '');
831
- $options[] = array('name' => 'sgpb-popup-fixed', 'type' => 'checkbox', 'defaultValue' => '');
832
- $options[] = array('name' => 'sgpb-popup-fixed-position', 'type' => 'text', 'defaultValue' => '');
833
- $options[] = array('name' => 'sgpb-popup-delay', 'type' => 'text', 'defaultValue' => '0');
834
- $options[] = array('name' => 'sgpb-popup-order', 'type' => 'text', 'defaultValue' => '0');
835
- $options[] = array('name' => 'sgpb-disable-page-scrolling', 'type' => 'checkbox', 'defaultValue' => '');
836
- $options[] = array('name' => 'sgpb-content-padding', 'type' => 'text', 'defaultValue' => 7);
837
- $options[] = array('name' => 'sgpb-popup-z-index', 'type' => 'text', 'defaultValue' => 9999);
838
- $options[] = array('name' => 'sgpb-content-custom-class', 'type' => 'text', 'defaultValue' => 'sg-popup-content');
839
- $options[] = array('name' => 'sgpb-close-after-page-scroll', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
840
- $options[] = array('name' => 'sgpb-auto-close', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
841
- $options[] = array('name' => 'sgpb-auto-close-time', 'type' => 'number', 'defaultValue' => 0);
842
- $options[] = array('name' => 'sgpb-reopen-after-form-submission', 'type' => 'checkbox', 'defaultValue' => '');
843
- $options[] = array('name' => 'sgpb-open-sound', 'type' => 'checkbox', 'defaultValue' => '');
844
- $options[] = array('name' => 'sgpb-sound-url', 'type' => 'text', 'defaultValue' => SG_POPUP_SOUND_URL.SGPB_POPUP_DEFAULT_SOUND);
845
- $options[] = array('name' => 'sgpb-open-animation', 'type' => 'checkbox', 'defaultValue' => '');
846
- $options[] = array('name' => 'sgpb-close-animation', 'type' => 'checkbox', 'defaultValue' => '');
847
- $options[] = array('name' => 'sgpb-open-animation-speed', 'type' => 'text', 'defaultValue' => 1);
848
- $options[] = array('name' => 'sgpb-close-animation-speed', 'type' => 'text', 'defaultValue' => 1);
849
- $options[] = array('name' => 'sgpb-popup-themes', 'type' => 'text', 'defaultValue' => 'sgpb-theme-1');
850
- $options[] = array('name' => 'sgpb-enable-popup-overlay', 'type' => 'checkbox', 'defaultValue' => 'on', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
851
- $options[] = array('name' => 'sgpb-overlay-custom-class', 'type' => 'text', 'defaultValue' => 'sgpb-popup-overlay');
852
- $options[] = array('name' => 'sgpb-overlay-color', 'type' => 'text', 'defaultValue' => '');
853
- $options[] = array('name' => 'sgpb-background-color', 'type' => 'text', 'defaultValue' => '');
854
- $options[] = array('name' => 'sgpb-overlay-opacity', 'type' => 'text', 'defaultValue' => 0.8);
855
- $options[] = array('name' => 'sgpb-content-opacity', 'type' => 'text', 'defaultValue' => 0.8);
856
- $options[] = array('name' => 'sgpb-background-image', 'type' => 'text', 'defaultValue' => '');
857
- $options[] = array('name' => 'sgpb-show-background', 'type' => 'checkbox', 'defaultValue' => '');
858
- $options[] = array('name' => 'sgpb-force-rtl', 'type' => 'checkbox', 'defaultValue' => '');
859
- $options[] = array('name' => 'sgpb-disable-border', 'type' => 'checkbox', 'defaultValue' => '');
860
- $options[] = array('name' => 'sgpb-background-image-mode', 'type' => 'text', 'defaultValue' => 'no-repeat');
861
- $options[] = array('name' => 'sgpb-image-url', 'type' => 'text', 'defaultValue' => '');
862
- $options[] = array('name' => 'sgpb-close-button-delay', 'type' => 'number', 'defaultValue' => 0);
863
- $options[] = array('name' => 'sgpb-button-position-bottom', 'type' => 'number', 'defaultValue' => 9);
864
- $options[] = array('name' => 'sgpb-button-position-right', 'type' => 'number', 'defaultValue' => 9);
865
- $options[] = array('name' => 'sgpb-button-image', 'type' => 'text', 'defaultValue' => '');
866
- $options[] = array('name' => 'sgpb-button-image-width', 'type' => 'text', 'defaultValue' => 21);
867
- $options[] = array('name' => 'sgpb-button-image-height', 'type' => 'text', 'defaultValue' => 21);
868
- $options[] = array('name' => 'sgpb-is-active', 'type' => 'checkbox', 'defaultValue' => 'on');
869
- $options[] = array('name' => 'sgpb-subs-form-bg-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
870
- $options[] = array('name' => 'sgpb-subs-form-bg-opacity', 'type' => 'text', 'defaultValue' => 0.8);
871
- $options[] = array('name' => 'sgpb-subs-form-padding', 'type' => 'number', 'defaultValue' => 2);
872
- $options[] = array('name' => 'sgpb-subs-email-placeholder', 'type' => 'text', 'defaultValue' => __('Email *', SG_POPUP_TEXT_DOMAIN));
873
- $options[] = array('name' => 'sgpb-subs-first-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
874
- $options[] = array('name' => 'sgpb-subs-first-placeholder', 'type' => 'text', 'defaultValue' => __('First name', SG_POPUP_TEXT_DOMAIN));
875
- $options[] = array('name' => 'sgpb-subs-first-name-required', 'type' => 'checkbox', 'defaultValue' => '');
876
- $options[] = array('name' => 'sgpb-subs-last-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
877
- $options[] = array('name' => 'sgpb-subs-last-placeholder', 'type' => 'text', 'defaultValue' => __('Last name', SG_POPUP_TEXT_DOMAIN));
878
- $options[] = array('name' => 'sgpb-subs-last-name-required', 'type' => 'checkbox', 'defaultValue' => '');
879
- $options[] = array('name' => 'sgpb-subs-validation-message', 'type' => 'text', 'defaultValue' => __('This field is required.', SG_POPUP_TEXT_DOMAIN));
880
- $options[] = array('name' => 'sgpb-subs-text-width', 'type' => 'text', 'defaultValue' => '300px');
881
- $options[] = array('name' => 'sgpb-subs-text-height', 'type' => 'text', 'defaultValue' => '40px');
882
- $options[] = array('name' => 'sgpb-subs-text-border-width', 'type' => 'text', 'defaultValue' => '2px');
883
- $options[] = array('name' => 'sgpb-subs-text-border-color', 'type' => 'text', 'defaultValue' => '#CCCCCC');
884
- $options[] = array('name' => 'sgpb-subs-text-bg-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
885
- $options[] = array('name' => 'sgpb-subs-text-color', 'type' => 'text', 'defaultValue' => '#000000');
886
- $options[] = array('name' => 'sgpb-subs-text-placeholder-color', 'type' => 'text', 'defaultValue' => '#CCCCCC');
887
- $options[] = array('name' => 'sgpb-subs-btn-width', 'type' => 'text', 'defaultValue' => '300px');
888
- $options[] = array('name' => 'sgpb-subs-btn-height', 'type' => 'text', 'defaultValue' => '40px');
889
- $options[] = array('name' => 'sgpb-subs-btn-border-radius', 'type' => 'text', 'defaultValue' => '4px');
890
- $options[] = array('name' => 'sgpb-subs-btn-border-width', 'type' => 'text', 'defaultValue' => '0px');
891
- $options[] = array('name' => 'sgpb-subs-btn-border-color', 'type' => 'text', 'defaultValue' => '#4CAF50');
892
- $options[] = array('name' => 'sgpb-subs-btn-title', 'type' => 'text', 'defaultValue' => __('Subscribe', SG_POPUP_TEXT_DOMAIN));
893
- $options[] = array('name' => 'sgpb-subs-btn-progress-title', 'type' => 'text', 'defaultValue' => __('Please wait...', SG_POPUP_TEXT_DOMAIN));
894
- $options[] = array('name' => 'sgpb-subs-btn-bg-color', 'type' => 'text', 'defaultValue' => '#4CAF50');
895
- $options[] = array('name' => 'sgpb-subs-btn-text-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
896
- $options[] = array('name' => 'sgpb-subs-error-message', 'type' => 'text', 'defaultValue' => SGPB_SUBSCRIPTION_ERROR_MESSAGE);
897
- $options[] = array('name' => 'sgpb-subs-invalid-message', 'type' => 'text', 'defaultValue' => __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
898
- $options[] = array('name' => 'sgpb-subs-success-behavior', 'type' => 'text', 'defaultValue' => 'showMessage');
899
- $options[] = array('name' => 'sgpb-subs-success-message', 'type' => 'text', 'defaultValue' => __('You have successfully subscribed to the newsletter', SG_POPUP_TEXT_DOMAIN));
900
- $options[] = array('name' => 'sgpb-subs-success-redirect-URL', 'type' => 'text', 'defaultValue' => '');
901
- $options[] = array('name' => 'sgpb-subs-success-redirect-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
902
- $options[] = array('name' => 'sgpb-subs-gdpr-status', 'type' => 'checkbox', 'defaultValue' => '');
903
- $options[] = array('name' => 'sgpb-subs-show-form-to-top', 'type' => 'checkbox', 'defaultValue' => '');
904
- $options[] = array('name' => 'sgpb-subs-gdpr-label', 'type' => 'text', 'defaultValue' => __('Accept Terms', SG_POPUP_TEXT_DOMAIN));
905
- $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));
906
- $options[] = array('name' => 'sgpb-subs-fields', 'type' => 'sgpb', 'defaultValue' => '');
907
- $options[] = array('name' => 'sgpb-fblike-like-url', 'type' => 'text', 'defaultValue' => '');
908
- $options[] = array('name' => 'sgpb-fblike-layout', 'type' => 'text', 'defaultValue' => 'standard');
909
- $options[] = array('name' => 'sgpb-fblike-dont-show-share-button', 'type' => 'checkbox', 'defaultValue' => '');
910
- $options[] = array('name' => 'sgpb-border-color', 'type' => 'text', 'defaultValue' => '#000000');
911
- $options[] = array('name' => 'sgpb-border-radius', 'type' => 'text', 'defaultValue' => 0);
912
- $options[] = array('name' => 'sgpb-show-popup-same-user', 'type' => 'checkbox', 'defaultValue' => '');
913
- $options[] = array('name' => 'sgpb-show-popup-same-user-count', 'type' => 'number', 'defaultValue' => 1);
914
- $options[] = array('name' => 'sgpb-show-popup-same-user-expiry', 'type' => 'number', 'defaultValue' => 1);
915
- $options[] = array('name' => 'sgpb-show-popup-same-user-page-level', 'type' => 'checkbox', 'defaultValue' => '');
916
-
917
- $options[] = array('name' => 'sgpb-enable-floating-button', 'type' => 'checkbox', 'defaultValue' => '');
918
- $options[] = array('name' => 'sgpb-floating-button-style', 'type' => 'text', 'defaultValue' => 'corner');
919
- $options[] = array('name' => 'sgpb-floating-button-position', 'type' => 'text', 'defaultValue' => 'bottom-right');
920
- $options[] = array('name' => 'sgpb-floating-button-position-top', 'type' => 'text', 'defaultValue' => '40');
921
- $options[] = array('name' => 'sgpb-floating-button-position-right', 'type' => 'text', 'defaultValue' => '50');
922
- $options[] = array('name' => 'sgpb-floating-button-font-size', 'type' => 'number', 'defaultValue' => 16);
923
- $options[] = array('name' => 'sgpb-floating-button-border-size', 'type' => 'number', 'defaultValue' => 5);
924
- $options[] = array('name' => 'sgpb-floating-button-border-radius', 'type' => 'number', 'defaultValue' => 5);
925
- $options[] = array('name' => 'sgpb-floating-button-border-color', 'type' => 'text', 'defaultValue' => '#5263eb');
926
- $options[] = array('name' => 'sgpb-floating-button-bg-color', 'type' => 'text', 'defaultValue' => '#5263eb');
927
- $options[] = array('name' => 'sgpb-floating-button-text-color', 'type' => 'text', 'defaultValue' => '#ffffff');
928
- $options[] = array('name' => 'sgpb-floating-button-text', 'type' => 'text', 'defaultValue' => __('Click it!'));
929
-
930
- $SGPB_OPTIONS = apply_filters('sgpbPopupDefaultOptions', $options);
931
- }
932
-
933
- public static function getOldExtensionsInfo()
934
- {
935
- $data = array(
936
- array(
937
- 'folderName' => 'popup-builder-ad-block',
938
- 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN)
939
- ),
940
- array(
941
- 'folderName' => 'popup-builder-analytics',
942
- 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN)
943
- ),
944
- array(
945
- 'folderName' => 'popup-builder-exit-intent',
946
- 'label' => __('Exit intent', SG_POPUP_TEXT_DOMAIN)
947
- ),
948
- array(
949
- 'folderName' => 'popup-builder-mailchimp',
950
- 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN)
951
- ),
952
- array(
953
- 'folderName' => 'popup-builder-aweber',
954
- 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN)
955
- )
956
- );
957
-
958
- return $data;
959
- }
960
-
961
- public static function addFilters()
962
- {
963
- ConfigDataHelper::addFilters();
964
- }
965
-
966
- public static function transientConfig()
967
- {
968
- global $SGPB_TRANSIENT_CONFIG;
969
-
970
- $SGPB_TRANSIENT_CONFIG = array(
971
- SGPB_TRANSIENT_POPUPS_LOAD,
972
- SGPB_TRANSIENT_POPUPS_TERMS,
973
- SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES
974
- );
975
-
976
- $SGPB_TRANSIENT_CONFIG = apply_filters('sgpbAllTransients', $SGPB_TRANSIENT_CONFIG);
977
- }
978
- }
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', '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',
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',
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', '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', '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',
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',
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
+
494
+ $keys[] = array(
495
+ 'label' => __('Age Restriction', SG_POPUP_TEXT_DOMAIN),
496
+ 'pluginKey' => 'popupbuilder-age-verification/PopupBuilderAgeverification.php',
497
+ 'key' => 'ageVerification',
498
+ 'url' => SGPB_AGE_VERIFICATION_PLUGIN_URL
499
+ );
500
+ $keys[] = array(
501
+ 'label' => __('Gamification', SG_POPUP_TEXT_DOMAIN),
502
+ 'pluginKey' => 'popupbuilder-gamification/PopupBuilderGamification.php',
503
+ 'key' => 'gamification',
504
+ 'url' => SGPB_GAMIFICATION_PLUGIN_URL
505
+ );
506
+ $keys[] = array(
507
+ 'label' => __('PDF', SG_POPUP_TEXT_DOMAIN),
508
+ 'pluginKey' => 'popupbuilder-pdf/PopupBuilderPdf.php',
509
+ 'key' => 'pdf',
510
+ 'url' => SGPB_PDF_PLUGIN_URL
511
+ );
512
+ $keys[] = array(
513
+ 'label' => __('Push Notification', SG_POPUP_TEXT_DOMAIN),
514
+ 'pluginKey' => 'popupbuilder-push-notification/PopupBuilderPushNotification.php',
515
+ 'key' => 'pushNotification',
516
+ 'url' => SG_POPUP_PUSH_NOTIFICATION_URL
517
+ );
518
+ $keys[] = array(
519
+ 'label' => __('EDD', SG_POPUP_TEXT_DOMAIN),
520
+ 'pluginKey' => 'popupbuilder-edd/PopupBuilderEdd.php',
521
+ 'key' => 'edd',
522
+ 'url' => SGPB_EDD_PLUGIN_URL
523
+ );
524
+ $keys[] = array(
525
+ 'label' => __('Scheduling', SG_POPUP_TEXT_DOMAIN),
526
+ 'pluginKey' => 'popupbuilder-scheduling/PopupBuilderScheduling.php',
527
+ 'key' => 'scheduling',
528
+ 'url' => SG_POPUP_SCHEDULING_URL
529
+ );
530
+ $keys[] = array(
531
+ 'label' => __('Geo Targeting', SG_POPUP_TEXT_DOMAIN),
532
+ 'pluginKey' => 'popupbuilder-geo-targeting/PopupBuilderGeoTargeting.php',
533
+ 'key' => 'geo-targeting',
534
+ 'url' => SG_POPUP_GEO_TARGETING_URL
535
+ );
536
+ $keys[] = array(
537
+ 'label' => __('Iframe', SG_POPUP_TEXT_DOMAIN),
538
+ 'pluginKey' => 'popupbuilder-iframe/PopupBuilderIframe.php',
539
+ 'key' => 'iframe',
540
+ 'url' => SG_POPUP_IFRAME_URL
541
+ );
542
+ $keys[] = array(
543
+ 'label' => __('Social', SG_POPUP_TEXT_DOMAIN),
544
+ 'pluginKey' => 'popupbuilder-social/PopupBuilderSocial.php',
545
+ 'key' => 'social',
546
+ 'url' => SG_POPUP_SOCIAL_URL
547
+ );
548
+ $keys[] = array(
549
+ 'label' => __('Video', SG_POPUP_TEXT_DOMAIN),
550
+ 'pluginKey' => 'popupbuilder-video/PopupBuilderVideo.php',
551
+ 'key' => 'video',
552
+ 'url' => SG_POPUP_VIDEO_URL
553
+ );
554
+ $keys[] = array(
555
+ 'label' => __('Countdown', SG_POPUP_TEXT_DOMAIN),
556
+ 'pluginKey' => 'popupbuilder-countdown/PopupBuilderCountdown.php',
557
+ 'key' => 'countdown',
558
+ 'url' => SG_POPUP_COUNTDOWN_URL
559
+ );
560
+ $keys[] = array(
561
+ 'label' => __('Restriction', SG_POPUP_TEXT_DOMAIN),
562
+ 'pluginKey' => 'popupbuilder-restriction/PopupBuilderAgerestriction.php',
563
+ 'key' => 'ageRestriction',
564
+ 'url' => SG_POPUP_RESTRICTION_URL
565
+ );
566
+ $keys[] = array(
567
+ 'label' => __('Contact Form', SG_POPUP_TEXT_DOMAIN),
568
+ 'pluginKey' => 'popupbuilder-contact-form/PopupBuilderContactForm.php',
569
+ 'key' => 'contactForm',
570
+ 'url' => SG_POPUP_CONTACT_FORM_URL
571
+ );
572
+ $keys[] = array(
573
+ 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN),
574
+ 'pluginKey' => 'popupbuilder-adblock/PopupBuilderAdBlock.php',
575
+ 'key' => 'sgpbAdBlock',
576
+ 'url' => SG_POPUP_AD_BLOCK_URL
577
+ );
578
+ $keys[] = array(
579
+ 'label' => __('Scroll', SG_POPUP_TEXT_DOMAIN),
580
+ 'pluginKey' => 'popupbuilder-scroll/PopupBuilderScroll.php',
581
+ 'key' => 'sgpbScroll',
582
+ 'url' => SG_POPUP_SCROLL_URL
583
+ );
584
+ $keys[] = array(
585
+ 'label' => __('Advanced Closing', SG_POPUP_TEXT_DOMAIN),
586
+ 'pluginKey' => 'popupbuilder-advanced-closing/PopupBuilderAdvancedClosing.php',
587
+ 'key' => 'advancedClosing',
588
+ 'url' => SG_POPUP_ADVANCED_CLOSING_URL
589
+ );
590
+ $keys[] = array(
591
+ 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN),
592
+ 'pluginKey' => 'popupbuilder-analytics/PopupBuilderAnalytics.php',
593
+ 'key' => 'sgpbAnalitics',
594
+ 'url' => SG_POPUP_ANALYTICS_URL
595
+ );
596
+ $keys[] = array(
597
+ 'label' => __('Inactivity', SG_POPUP_TEXT_DOMAIN),
598
+ 'pluginKey' => 'popupbuilder-inactivity/PopupBuilderInactivity.php',
599
+ 'key' => 'sgpbInactivity',
600
+ 'url' => SG_POPUP_INACTIVITY_URL
601
+ );
602
+ $keys[] = array(
603
+ 'label' => __('Exit Intent',SG_POPUP_TEXT_DOMAIN),
604
+ 'pluginKey' => 'popupbuilder-exit-intent/PopupBuilderExitIntent.php',
605
+ 'key' => 'sgpbExitIntent',
606
+ 'url' => SG_POPUP_EXIT_INTENT_URL
607
+ );
608
+ $keys[] = array(
609
+ 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN),
610
+ 'pluginKey' => 'popupbuilder-mailchimp/PopupBuilderMailchimp.php',
611
+ 'key' => 'sgpbMailchimp',
612
+ 'url' => SG_POPUP_MAILCHIMP_URL
613
+ );
614
+ $keys[] = array(
615
+ 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN),
616
+ 'pluginKey' => 'popupbuilder-aweber/PopupBuilderAWeber.php',
617
+ 'key' => 'sgpbAWeber',
618
+ 'url' => SG_POPUP_AWEBER_URL
619
+ );
620
+ $keys[] = array(
621
+ 'label' => __('Random', SG_POPUP_TEXT_DOMAIN),
622
+ 'pluginKey' => 'popupbuilder-random/PopupBuilderRandom.php',
623
+ 'key' => 'sgpbRandom',
624
+ 'url' => SG_POPUP_RANDOM_URL
625
+ );
626
+ $keys[] = array(
627
+ 'label' => __('WooCommerce', SG_POPUP_TEXT_DOMAIN),
628
+ 'pluginKey' => 'popupbuilder-woocommerce/popupbuilderWoocommerce.php',
629
+ 'key' => 'sgpbWOO',
630
+ 'url' => SG_POPUP_WOOCOMMERCE_URL
631
+ );
632
+ $keys[] = array(
633
+ 'label' => __('Recent Sales', SG_POPUP_TEXT_DOMAIN),
634
+ 'pluginKey' => 'popupbuilder-recent-sales/PopupBuilderRecentSales.php',
635
+ 'key' => 'sgpbRecentSales',
636
+ 'url' => SG_POPUP_RECENT_SALES_URL
637
+ );
638
+ $keys[] = array(
639
+ 'label' => __('Advanced Targeting', SG_POPUP_TEXT_DOMAIN),
640
+ 'pluginKey' => 'popupbuilder-advanced-targeting/PopupBuilderAdvancedTargeting.php',
641
+ 'key' => 'sgpbAdvancedTargeting',
642
+ 'url' => SG_POPUP_ADVANCED_TARGETING_URL
643
+ );
644
+ $keys[] = array(
645
+ 'label' => __('Log In', SG_POPUP_TEXT_DOMAIN),
646
+ 'pluginKey' => 'popupbuilder-login/PopupBuilderLogin.php',
647
+ 'key' => 'login',
648
+ 'url' => SG_POPUP_LOGIN_URL
649
+ );
650
+ $keys[] = array(
651
+ 'label' => __('Registration', SG_POPUP_TEXT_DOMAIN),
652
+ 'pluginKey' => 'popupbuilder-registration/PopupBuilderRegistration.php',
653
+ 'key' => 'registration',
654
+ 'url' => SG_POPUP_REGISTRATION_URL
655
+ );
656
+ $keys[] = array(
657
+ 'label' => __('Subscription Plus', SG_POPUP_TEXT_DOMAIN),
658
+ 'pluginKey' => 'popupbuilder-subscription-plus/PopupBuilderSubscriptionPlus.php',
659
+ 'key' => 'subscriptionPlus',
660
+ 'url' => SG_POPUP_SUBSCRIPTION_PLUS_URL
661
+ );
662
+
663
+ return apply_filters('sgpbExtensionsKeys', $keys);
664
+ }
665
+
666
+ private static function getBehaviorAfterSpecialEventsConfig()
667
+ {
668
+ $columns = array(
669
+ 'param' => 'Event',
670
+ 'operator' => 'Behavior',
671
+ 'value' => 'Value'
672
+ );
673
+
674
+ $columnTypes = array(
675
+ 'param' => 'select',
676
+ 'operator' => 'select',
677
+ 'value' => 'select',
678
+ 'select_event' => 'select',
679
+ 'select_behavior' => 'select',
680
+ 'redirect-url' => 'url',
681
+ 'open-popup' => 'select',
682
+ 'close-popup' => 'number'
683
+ );
684
+
685
+ $params = array(
686
+ 'param' => array(
687
+ 'select_event' => __('Select event', SG_POPUP_TEXT_DOMAIN),
688
+ __('Special events', SG_POPUP_TEXT_DOMAIN) => array(
689
+ SGPB_CONTACT_FORM_7_BEHAVIOR_KEY => __('Contact Form 7 submission', SG_POPUP_TEXT_DOMAIN)
690
+ )
691
+ ),
692
+ 'operator' => array(
693
+ 'select_behavior' => __('Select behavior', SG_POPUP_TEXT_DOMAIN),
694
+ __('Behaviors', SG_POPUP_TEXT_DOMAIN) => array(
695
+ 'redirect-url' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN),
696
+ 'open-popup' => __('Open another popup', SG_POPUP_TEXT_DOMAIN),
697
+ 'close-popup' => __('Close current popup', SG_POPUP_TEXT_DOMAIN)
698
+ )
699
+ ),
700
+ 'redirect-url' => '',
701
+ 'open-popup' => array(),
702
+ 'close-popup' => '',
703
+ 'select_event' => null,
704
+ 'select_behavior' => null
705
+ );
706
+
707
+ $initialData = array(
708
+ array(
709
+ 'param' => 'select_event',
710
+ 'operator' => ''
711
+ )
712
+ );
713
+
714
+ $attrs = array(
715
+ 'param' => array(
716
+ 'htmlAttrs' => array(
717
+ 'class' => 'js-sg-select2 js-select-basic',
718
+ 'data-select-class' => 'js-select-basic',
719
+ 'data-select-type' => 'basic'
720
+ ),
721
+ 'infoAttrs' => array(
722
+ 'label' => __('Event', SG_POPUP_TEXT_DOMAIN),
723
+ 'info' => __('Select the special event you want to catch.', SG_POPUP_TEXT_DOMAIN)
724
+ )
725
+ ),
726
+ 'operator' => array(
727
+ 'htmlAttrs' => array(
728
+ 'class' => 'js-sg-select2 js-select-basic',
729
+ 'data-select-class' => 'js-select-basic',
730
+ 'data-select-type' => 'basic'
731
+ ),
732
+ 'infoAttrs' => array(
733
+ 'label' => __('Behavior', SG_POPUP_TEXT_DOMAIN),
734
+ 'info' => __('Select what should happen after the special event.', SG_POPUP_TEXT_DOMAIN)
735
+ )
736
+ ),
737
+ 'redirect-url' => array(
738
+ 'htmlAttrs' => array(
739
+ 'class' => 'sg-full-width',
740
+ 'placeholder' => 'https://www.example.com',
741
+ 'required' => 'required'
742
+ ),
743
+ 'infoAttrs' => array(
744
+ 'label' => __('URL', SG_POPUP_TEXT_DOMAIN),
745
+ 'info' => __('Enter the URL of the page should be redirected to.', SG_POPUP_TEXT_DOMAIN)
746
+ )
747
+ ),
748
+ 'open-popup' => array(
749
+ 'htmlAttrs' => array(
750
+ 'class' => 'js-sg-select2 js-select-ajax',
751
+ 'data-select-class' => 'js-select-ajax',
752
+ 'data-select-type' => 'ajax',
753
+ 'data-value-param' => SG_POPUP_POST_TYPE,
754
+ 'required' => 'required'
755
+ ),
756
+ 'infoAttrs' => array(
757
+ 'label' => __('Select popup', SG_POPUP_TEXT_DOMAIN),
758
+ 'info' => __('Select the popup that should be opened.', SG_POPUP_TEXT_DOMAIN)
759
+ )
760
+ ),
761
+ 'close-popup' => array(
762
+ 'htmlAttrs' => array(
763
+ 'class' => 'sg-full-width',
764
+ 'required' => 'required',
765
+ 'value' => 0,
766
+ 'min' => 0
767
+ ),
768
+ 'infoAttrs' => array(
769
+ 'label' => __('Delay', SG_POPUP_TEXT_DOMAIN),
770
+ 'info' => __('After how many seconds the popup should close.', SG_POPUP_TEXT_DOMAIN)
771
+ )
772
+ )
773
+ );
774
+
775
+ $config = array();
776
+ $config['columns'] = apply_filters('sgPopupSpecialEventsColumns', $columns);
777
+ $config['columnTypes'] = apply_filters('sgPopupSpecialEventsColumnTypes', $columnTypes);
778
+ $config['paramsData'] = apply_filters('sgPopupSpecialEventsParams', $params);
779
+ $config['initialData'] = apply_filters('sgPopupSpecialEventsInitialData', $initialData);
780
+ $config['attrs'] = apply_filters('sgPopupSpecialEventsAttrs', $attrs);
781
+ $config['operators'] = apply_filters('sgpbPopupSpecialEventsOperators', array());
782
+ $config['specialDefaultOperator'] = apply_filters('sgpbPopupSpecialEventsDefaultOperators', ' ');
783
+
784
+ return $config;
785
+ }
786
+
787
+ public static function popupDefaultOptions()
788
+ {
789
+ global $SGPB_OPTIONS;
790
+ global $SGPB_DATA_CONFIG_ARRAY;
791
+
792
+ $targetDefaultValue = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
793
+
794
+ $eventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['events']['initialData']);
795
+ $conditionsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['conditions']['initialData']);
796
+ $specialEventsDefaultData = array($SGPB_DATA_CONFIG_ARRAY['behavior-after-special-events']['initialData']);
797
+
798
+ $options = array();
799
+
800
+ $options[] = array('name' => 'sgpb-target', 'type' => 'array', 'defaultValue' => $targetDefaultValue);
801
+ $options[] = array('name' => 'sgpb-events', 'type' => 'array', 'defaultValue' => $eventsDefaultData);
802
+ $options[] = array('name' => 'sgpb-conditions', 'type' => 'array', 'defaultValue' => $conditionsDefaultData, 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
803
+ $options[] = array('name' => 'sgpb-behavior-after-special-events', 'type' => 'array', 'defaultValue' => $specialEventsDefaultData);
804
+ $options[] = array('name' => 'sgpb-type', 'type' => 'text', 'defaultValue' => 'html');
805
+ $options[] = array('name' => 'sgpb-popup-counting-disabled', 'type' => 'checkbox', 'defaultValue' => '');
806
+ $options[] = array('name' => 'sgpb-esc-key', 'type' => 'checkbox', 'defaultValue' => 'on');
807
+ $options[] = array('name' => 'sgpb-enable-close-button', 'type' => 'checkbox', 'defaultValue' => 'on');
808
+ $options[] = array('name' => 'sgpb-enable-content-scrolling', 'type' => 'checkbox', 'defaultValue' => 'on');
809
+ $options[] = array('name' => 'sgpb-overlay-click', 'type' => 'checkbox', 'defaultValue' => 'on');
810
+ $options[] = array('name' => 'sgpb-content-click', 'type' => 'checkbox', 'defaultValue' => '');
811
+ $options[] = array('name' => 'sgpb-subs-hide-subs-users', 'type' => 'checkbox', 'defaultValue' => 'on');
812
+ $options[] = array('name' => 'sgpb-content-click-behavior', 'type' => 'text', 'defaultValue' => 'close');
813
+ $options[] = array('name' => 'sgpb-click-redirect-to-url', 'type' => 'text', 'defaultValue' => '');
814
+ $options[] = array('name' => 'sgpb-redirect-to-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
815
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-text', 'type' => 'text', 'defaultValue' => '');
816
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-close-popup', 'type' => 'checkbox', 'defaultValue' => 'on');
817
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-alert', 'type' => 'checkbox', 'defaultValue' => 'on');
818
+ $options[] = array('name' => 'sgpb-copy-to-clipboard-message', 'type' => 'text', 'defaultValue' => __('Copied to Clipboard!', SG_POPUP_TEXT_DOMAIN));
819
+ $options[] = array('name' => 'sgpb-disable-popup-closing', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
820
+ $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => 'responsiveMode');
821
+ $options[] = array('name' => 'sgpb-popup-dimension-mode', 'type' => 'text', 'defaultValue' => '100');
822
+ $options[] = array('name' => 'sgpb-width', 'type' => 'text', 'defaultValue' => '640px');
823
+ $options[] = array('name' => 'sgpb-height', 'type' => 'text', 'defaultValue' => '480px');
824
+ $options[] = array('name' => 'sgpb-max-width', 'type' => 'text', 'defaultValue' => '');
825
+ $options[] = array('name' => 'sgpb-max-height', 'type' => 'text', 'defaultValue' => '');
826
+ $options[] = array('name' => 'sgpb-min-width', 'type' => 'text', 'defaultValue' => '120');
827
+ $options[] = array('name' => 'sgpb-min-height', 'type' => 'text', 'defaultValue' => '');
828
+ $options[] = array('name' => 'sgpb-popup-timer-status', 'type' => 'checkbox', 'defaultValue' => '');
829
+ $options[] = array('name' => 'sgpb-popup-start-timer', 'type' => 'text', 'defaultValue' => '');
830
+ $options[] = array('name' => 'sgpb-popup-end-timer', 'type' => 'text', 'defaultValue' => '');
831
+ $options[] = array('name' => 'sgpb-popup-fixed', 'type' => 'checkbox', 'defaultValue' => '');
832
+ $options[] = array('name' => 'sgpb-popup-fixed-position', 'type' => 'text', 'defaultValue' => '');
833
+ $options[] = array('name' => 'sgpb-popup-delay', 'type' => 'text', 'defaultValue' => '0');
834
+ $options[] = array('name' => 'sgpb-popup-order', 'type' => 'text', 'defaultValue' => '0');
835
+ $options[] = array('name' => 'sgpb-disable-page-scrolling', 'type' => 'checkbox', 'defaultValue' => '');
836
+ $options[] = array('name' => 'sgpb-content-padding', 'type' => 'text', 'defaultValue' => 7);
837
+ $options[] = array('name' => 'sgpb-popup-z-index', 'type' => 'text', 'defaultValue' => 9999);
838
+ $options[] = array('name' => 'sgpb-content-custom-class', 'type' => 'text', 'defaultValue' => 'sg-popup-content');
839
+ $options[] = array('name' => 'sgpb-close-after-page-scroll', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
840
+ $options[] = array('name' => 'sgpb-auto-close', 'type' => 'checkbox', 'defaultValue' => '', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
841
+ $options[] = array('name' => 'sgpb-auto-close-time', 'type' => 'number', 'defaultValue' => 0);
842
+ $options[] = array('name' => 'sgpb-reopen-after-form-submission', 'type' => 'checkbox', 'defaultValue' => '');
843
+ $options[] = array('name' => 'sgpb-open-sound', 'type' => 'checkbox', 'defaultValue' => '');
844
+ $options[] = array('name' => 'sgpb-sound-url', 'type' => 'text', 'defaultValue' => SG_POPUP_SOUND_URL.SGPB_POPUP_DEFAULT_SOUND);
845
+ $options[] = array('name' => 'sgpb-open-animation', 'type' => 'checkbox', 'defaultValue' => '');
846
+ $options[] = array('name' => 'sgpb-close-animation', 'type' => 'checkbox', 'defaultValue' => '');
847
+ $options[] = array('name' => 'sgpb-open-animation-speed', 'type' => 'text', 'defaultValue' => 1);
848
+ $options[] = array('name' => 'sgpb-close-animation-speed', 'type' => 'text', 'defaultValue' => 1);
849
+ $options[] = array('name' => 'sgpb-popup-themes', 'type' => 'text', 'defaultValue' => 'sgpb-theme-1');
850
+ $options[] = array('name' => 'sgpb-enable-popup-overlay', 'type' => 'checkbox', 'defaultValue' => 'on', 'min-version' => SGPB_POPUP_PRO_MIN_VERSION, 'min-pkg' => SGPB_POPUP_PKG_SILVER);
851
+ $options[] = array('name' => 'sgpb-overlay-custom-class', 'type' => 'text', 'defaultValue' => 'sgpb-popup-overlay');
852
+ $options[] = array('name' => 'sgpb-overlay-color', 'type' => 'text', 'defaultValue' => '');
853
+ $options[] = array('name' => 'sgpb-background-color', 'type' => 'text', 'defaultValue' => '');
854
+ $options[] = array('name' => 'sgpb-overlay-opacity', 'type' => 'text', 'defaultValue' => 0.8);
855
+ $options[] = array('name' => 'sgpb-content-opacity', 'type' => 'text', 'defaultValue' => 0.8);
856
+ $options[] = array('name' => 'sgpb-background-image', 'type' => 'text', 'defaultValue' => '');
857
+ $options[] = array('name' => 'sgpb-show-background', 'type' => 'checkbox', 'defaultValue' => '');
858
+ $options[] = array('name' => 'sgpb-force-rtl', 'type' => 'checkbox', 'defaultValue' => '');
859
+ $options[] = array('name' => 'sgpb-disable-border', 'type' => 'checkbox', 'defaultValue' => '');
860
+ $options[] = array('name' => 'sgpb-background-image-mode', 'type' => 'text', 'defaultValue' => 'no-repeat');
861
+ $options[] = array('name' => 'sgpb-image-url', 'type' => 'text', 'defaultValue' => '');
862
+ $options[] = array('name' => 'sgpb-close-button-delay', 'type' => 'number', 'defaultValue' => 0);
863
+ $options[] = array('name' => 'sgpb-button-position-bottom', 'type' => 'number', 'defaultValue' => 9);
864
+ $options[] = array('name' => 'sgpb-button-position-right', 'type' => 'number', 'defaultValue' => 9);
865
+ $options[] = array('name' => 'sgpb-button-image', 'type' => 'text', 'defaultValue' => '');
866
+ $options[] = array('name' => 'sgpb-button-image-width', 'type' => 'text', 'defaultValue' => 21);
867
+ $options[] = array('name' => 'sgpb-button-image-height', 'type' => 'text', 'defaultValue' => 21);
868
+ $options[] = array('name' => 'sgpb-is-active', 'type' => 'checkbox', 'defaultValue' => 'on');
869
+ $options[] = array('name' => 'sgpb-subs-form-bg-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
870
+ $options[] = array('name' => 'sgpb-subs-form-bg-opacity', 'type' => 'text', 'defaultValue' => 0.8);
871
+ $options[] = array('name' => 'sgpb-subs-form-padding', 'type' => 'number', 'defaultValue' => 2);
872
+ $options[] = array('name' => 'sgpb-subs-email-placeholder', 'type' => 'text', 'defaultValue' => __('Email *', SG_POPUP_TEXT_DOMAIN));
873
+ $options[] = array('name' => 'sgpb-subs-first-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
874
+ $options[] = array('name' => 'sgpb-subs-first-placeholder', 'type' => 'text', 'defaultValue' => __('First name', SG_POPUP_TEXT_DOMAIN));
875
+ $options[] = array('name' => 'sgpb-subs-first-name-required', 'type' => 'checkbox', 'defaultValue' => '');
876
+ $options[] = array('name' => 'sgpb-subs-last-name-status', 'type' => 'checkbox', 'defaultValue' => 'on');
877
+ $options[] = array('name' => 'sgpb-subs-last-placeholder', 'type' => 'text', 'defaultValue' => __('Last name', SG_POPUP_TEXT_DOMAIN));
878
+ $options[] = array('name' => 'sgpb-subs-last-name-required', 'type' => 'checkbox', 'defaultValue' => '');
879
+ $options[] = array('name' => 'sgpb-subs-validation-message', 'type' => 'text', 'defaultValue' => __('This field is required.', SG_POPUP_TEXT_DOMAIN));
880
+ $options[] = array('name' => 'sgpb-subs-text-width', 'type' => 'text', 'defaultValue' => '300px');
881
+ $options[] = array('name' => 'sgpb-subs-text-height', 'type' => 'text', 'defaultValue' => '40px');
882
+ $options[] = array('name' => 'sgpb-subs-text-border-width', 'type' => 'text', 'defaultValue' => '2px');
883
+ $options[] = array('name' => 'sgpb-subs-text-border-color', 'type' => 'text', 'defaultValue' => '#CCCCCC');
884
+ $options[] = array('name' => 'sgpb-subs-text-bg-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
885
+ $options[] = array('name' => 'sgpb-subs-text-color', 'type' => 'text', 'defaultValue' => '#000000');
886
+ $options[] = array('name' => 'sgpb-subs-text-placeholder-color', 'type' => 'text', 'defaultValue' => '#CCCCCC');
887
+ $options[] = array('name' => 'sgpb-subs-btn-width', 'type' => 'text', 'defaultValue' => '300px');
888
+ $options[] = array('name' => 'sgpb-subs-btn-height', 'type' => 'text', 'defaultValue' => '40px');
889
+ $options[] = array('name' => 'sgpb-subs-btn-border-radius', 'type' => 'text', 'defaultValue' => '4px');
890
+ $options[] = array('name' => 'sgpb-subs-btn-border-width', 'type' => 'text', 'defaultValue' => '0px');
891
+ $options[] = array('name' => 'sgpb-subs-btn-border-color', 'type' => 'text', 'defaultValue' => '#4CAF50');
892
+ $options[] = array('name' => 'sgpb-subs-btn-title', 'type' => 'text', 'defaultValue' => __('Subscribe', SG_POPUP_TEXT_DOMAIN));
893
+ $options[] = array('name' => 'sgpb-subs-btn-progress-title', 'type' => 'text', 'defaultValue' => __('Please wait...', SG_POPUP_TEXT_DOMAIN));
894
+ $options[] = array('name' => 'sgpb-subs-btn-bg-color', 'type' => 'text', 'defaultValue' => '#4CAF50');
895
+ $options[] = array('name' => 'sgpb-subs-btn-text-color', 'type' => 'text', 'defaultValue' => '#FFFFFF');
896
+ $options[] = array('name' => 'sgpb-subs-error-message', 'type' => 'text', 'defaultValue' => SGPB_SUBSCRIPTION_ERROR_MESSAGE);
897
+ $options[] = array('name' => 'sgpb-subs-invalid-message', 'type' => 'text', 'defaultValue' => __('Please enter a valid email address', SG_POPUP_TEXT_DOMAIN).'.');
898
+ $options[] = array('name' => 'sgpb-subs-success-behavior', 'type' => 'text', 'defaultValue' => 'showMessage');
899
+ $options[] = array('name' => 'sgpb-subs-success-message', 'type' => 'text', 'defaultValue' => __('You have successfully subscribed to the newsletter', SG_POPUP_TEXT_DOMAIN));
900
+ $options[] = array('name' => 'sgpb-subs-success-redirect-URL', 'type' => 'text', 'defaultValue' => '');
901
+ $options[] = array('name' => 'sgpb-subs-success-redirect-new-tab', 'type' => 'checkbox', 'defaultValue' => '');
902
+ $options[] = array('name' => 'sgpb-subs-gdpr-status', 'type' => 'checkbox', 'defaultValue' => '');
903
+ $options[] = array('name' => 'sgpb-subs-show-form-to-top', 'type' => 'checkbox', 'defaultValue' => '');
904
+ $options[] = array('name' => 'sgpb-subs-gdpr-label', 'type' => 'text', 'defaultValue' => __('Accept Terms', SG_POPUP_TEXT_DOMAIN));
905
+ $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));
906
+ $options[] = array('name' => 'sgpb-subs-fields', 'type' => 'sgpb', 'defaultValue' => '');
907
+ $options[] = array('name' => 'sgpb-fblike-like-url', 'type' => 'text', 'defaultValue' => '');
908
+ $options[] = array('name' => 'sgpb-fblike-layout', 'type' => 'text', 'defaultValue' => 'standard');
909
+ $options[] = array('name' => 'sgpb-fblike-dont-show-share-button', 'type' => 'checkbox', 'defaultValue' => '');
910
+ $options[] = array('name' => 'sgpb-border-color', 'type' => 'text', 'defaultValue' => '#000000');
911
+ $options[] = array('name' => 'sgpb-border-radius', 'type' => 'text', 'defaultValue' => 0);
912
+ $options[] = array('name' => 'sgpb-show-popup-same-user', 'type' => 'checkbox', 'defaultValue' => '');
913
+ $options[] = array('name' => 'sgpb-show-popup-same-user-count', 'type' => 'number', 'defaultValue' => 1);
914
+ $options[] = array('name' => 'sgpb-show-popup-same-user-expiry', 'type' => 'number', 'defaultValue' => 1);
915
+ $options[] = array('name' => 'sgpb-show-popup-same-user-page-level', 'type' => 'checkbox', 'defaultValue' => '');
916
+
917
+ $options[] = array('name' => 'sgpb-enable-floating-button', 'type' => 'checkbox', 'defaultValue' => '');
918
+ $options[] = array('name' => 'sgpb-floating-button-style', 'type' => 'text', 'defaultValue' => 'corner');
919
+ $options[] = array('name' => 'sgpb-floating-button-position', 'type' => 'text', 'defaultValue' => 'bottom-right');
920
+ $options[] = array('name' => 'sgpb-floating-button-position-top', 'type' => 'text', 'defaultValue' => '40');
921
+ $options[] = array('name' => 'sgpb-floating-button-position-right', 'type' => 'text', 'defaultValue' => '50');
922
+ $options[] = array('name' => 'sgpb-floating-button-font-size', 'type' => 'number', 'defaultValue' => 16);
923
+ $options[] = array('name' => 'sgpb-floating-button-border-size', 'type' => 'number', 'defaultValue' => 5);
924
+ $options[] = array('name' => 'sgpb-floating-button-border-radius', 'type' => 'number', 'defaultValue' => 5);
925
+ $options[] = array('name' => 'sgpb-floating-button-border-color', 'type' => 'text', 'defaultValue' => '#5263eb');
926
+ $options[] = array('name' => 'sgpb-floating-button-bg-color', 'type' => 'text', 'defaultValue' => '#5263eb');
927
+ $options[] = array('name' => 'sgpb-floating-button-text-color', 'type' => 'text', 'defaultValue' => '#ffffff');
928
+ $options[] = array('name' => 'sgpb-floating-button-text', 'type' => 'text', 'defaultValue' => __('Click it!'));
929
+
930
+ $SGPB_OPTIONS = apply_filters('sgpbPopupDefaultOptions', $options);
931
+ }
932
+
933
+ public static function getOldExtensionsInfo()
934
+ {
935
+ $data = array(
936
+ array(
937
+ 'folderName' => 'popup-builder-ad-block',
938
+ 'label' => __('AdBlock', SG_POPUP_TEXT_DOMAIN)
939
+ ),
940
+ array(
941
+ 'folderName' => 'popup-builder-analytics',
942
+ 'label' => __('Analytics', SG_POPUP_TEXT_DOMAIN)
943
+ ),
944
+ array(
945
+ 'folderName' => 'popup-builder-exit-intent',
946
+ 'label' => __('Exit intent', SG_POPUP_TEXT_DOMAIN)
947
+ ),
948
+ array(
949
+ 'folderName' => 'popup-builder-mailchimp',
950
+ 'label' => __('Mailchimp', SG_POPUP_TEXT_DOMAIN)
951
+ ),
952
+ array(
953
+ 'folderName' => 'popup-builder-aweber',
954
+ 'label' => __('AWeber', SG_POPUP_TEXT_DOMAIN)
955
+ )
956
+ );
957
+
958
+ return $data;
959
+ }
960
+
961
+ public static function addFilters()
962
+ {
963
+ ConfigDataHelper::addFilters();
964
+ }
965
+
966
+ public static function transientConfig()
967
+ {
968
+ global $SGPB_TRANSIENT_CONFIG;
969
+
970
+ $SGPB_TRANSIENT_CONFIG = array(
971
+ SGPB_TRANSIENT_POPUPS_LOAD,
972
+ SGPB_TRANSIENT_POPUPS_TERMS,
973
+ SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES
974
+ );
975
+
976
+ $SGPB_TRANSIENT_CONFIG = apply_filters('sgpbAllTransients', $SGPB_TRANSIENT_CONFIG);
977
+ }
978
+ }
com/helpers/AdminHelper.php CHANGED
@@ -1,2070 +1,2070 @@
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 .= ' sgpb-full-width-events form-control';
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)
218
- {
219
- $str = '';
220
-
221
- foreach ($elements as $key => $element) {
222
- $value = '';
223
- $checked = '';
224
-
225
- if (isset($element['value'])) {
226
- $value = $element['value'];
227
- }
228
- if ($element['value'] == $selectedInput) {
229
- $checked = 'checked';
230
- }
231
- $attrStr = '';
232
- if (isset($element['data-attributes'])) {
233
- foreach ($element['data-attributes'] as $attrKey => $dataValue) {
234
- $attrStr .= $attrKey.'="'.esc_attr($dataValue).'" ';
235
- }
236
- }
237
-
238
- if ($lineMode) {
239
- $str .= '<input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>';
240
- }
241
- else {
242
- $str .= '<div class="row form-group">';
243
- $str .= '<label class="col-md-5 control-label">'.__($element['title'], SG_POPUP_TEXT_DOMAIN).'</label>';
244
- $str .= '<div class="col-sm-7"><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' autocomplete="off"></div>';
245
- $str .= '</div>';
246
- }
247
- }
248
-
249
- echo $str;
250
- }
251
-
252
- public static function getDateObjFromDate($dueDate, $timezone = 'America/Los_Angeles', $format = 'Y-m-d H:i:s')
253
- {
254
- $dateObj = new DateTime($dueDate, new DateTimeZone($timezone));
255
- $dateObj->format($format);
256
-
257
- return $dateObj;
258
- }
259
-
260
- /**
261
- * Serialize data
262
- *
263
- * @since 1.0.0
264
- *
265
- * @param array $data
266
- *
267
- * @return string $serializedData
268
- */
269
- public static function serializeData($data = array())
270
- {
271
- $serializedData = serialize($data);
272
-
273
- return $serializedData;
274
- }
275
-
276
- /**
277
- * Get correct size to use it safely inside CSS rules
278
- *
279
- * @since 1.0.0
280
- *
281
- * @param string $dimension
282
- *
283
- * @return string $size
284
- */
285
- public static function getCSSSafeSize($dimension)
286
- {
287
- if (empty($dimension)) {
288
- return 'inherit';
289
- }
290
-
291
- $size = (int)$dimension.'px';
292
- // If user write dimension in px or % we give that dimension to target otherwise the default value will be px
293
- if (strpos($dimension, '%') || strpos($dimension, 'px')) {
294
- $size = $dimension;
295
- }
296
-
297
- return $size;
298
- }
299
-
300
- public static function deleteSubscriptionPopupSubscribers($popupId)
301
- {
302
- global $wpdb;
303
-
304
- $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE subscriptionType = %s', $popupId);
305
- $wpdb->query($prepareSql);
306
- }
307
-
308
- public static function subscribersRelatedQuery($query = '', $additionalColumn = '')
309
- {
310
- global $wpdb;
311
- $subscribersTablename = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
312
- $postsTablename = $wpdb->prefix.SGPB_POSTS_TABLE_NAME;
313
-
314
- if ($query == '') {
315
- $query = 'SELECT firstName, lastName, email, cDate, '.$additionalColumn.' '.$postsTablename.'.post_title AS subscriptionTitle FROM '.$subscribersTablename.' ';
316
- }
317
-
318
- $searchQuery = ' unsubscribed <> 1';
319
- $filterCriteria = '';
320
-
321
- $query .= ' LEFT JOIN '.$postsTablename.' ON '.$postsTablename.'.ID='.$subscribersTablename.'.subscriptionType';
322
-
323
- if (isset($_GET['sgpb-subscription-popup-id']) && !empty($_GET['sgpb-subscription-popup-id'])) {
324
- $filterCriteria = esc_sql($_GET['sgpb-subscription-popup-id']);
325
- if ($filterCriteria != 'all') {
326
- $searchQuery .= " AND (subscriptionType = $filterCriteria)";
327
- }
328
- }
329
- if ($filterCriteria != '' && $filterCriteria != 'all' && isset($_GET['s']) && !empty($_GET['s'])) {
330
- $searchQuery .= ' AND ';
331
- }
332
- if (isset($_GET['s']) && !empty($_GET['s'])) {
333
- $searchCriteria = esc_sql($_GET['s']);
334
- $lastPartOfTheQuery = substr($searchQuery, -5);
335
- if (strpos($lastPartOfTheQuery, 'AND') <= 0) {
336
- $searchQuery .= ' AND ';
337
- }
338
- $searchQuery .= "(firstName LIKE '%$searchCriteria%' or lastName LIKE '%$searchCriteria%' or email LIKE '%$searchCriteria%' or $postsTablename.post_title LIKE '%$searchCriteria%')";
339
- }
340
- if (isset($_GET['sgpb-subscribers-date']) && !empty($_GET['sgpb-subscribers-date'])) {
341
- $filterCriteria = esc_sql($_GET['sgpb-subscribers-date']);
342
- if ($filterCriteria != 'all') {
343
- if ($searchQuery != '') {
344
- $searchQuery .= ' AND ';
345
- }
346
- $searchQuery .= " cDate LIKE '$filterCriteria%'";
347
- }
348
- }
349
- if ($searchQuery != '') {
350
- $query .= " WHERE $searchQuery";
351
- }
352
-
353
- return $query;
354
- }
355
-
356
- public static function themeRelatedSettings($popupId, $buttonPosition, $theme)
357
- {
358
- if ($popupId) {
359
- if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
360
- if (!isset($buttonPosition)) {
361
- $buttonPosition = 'bottomRight';
362
- }
363
- }
364
- else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
365
- if (!isset($buttonPosition)) {
366
- $buttonPosition = 'topRight';
367
- }
368
- }
369
- }
370
- else {
371
- if (isset($theme)) {
372
- if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
373
- $buttonPosition = 'bottomRight';
374
- }
375
- else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
376
- $buttonPosition = 'topRight';
377
- }
378
- }
379
- else {
380
- /* by default set position for the first theme */
381
- $buttonPosition = 'bottomRight';
382
- }
383
- }
384
-
385
- return $buttonPosition;
386
- }
387
-
388
- /**
389
- * Create html attrs
390
- *
391
- * @since 1.0.0
392
- *
393
- * @param array $attrs
394
- *
395
- * @return string $attrStr
396
- */
397
- public static function createAttrs($attrs)
398
- {
399
- $attrStr = '';
400
-
401
- if (empty($attrs)) {
402
- return $attrStr;
403
- }
404
-
405
- foreach ($attrs as $attrKey => $attrValue) {
406
- $attrStr .= $attrKey.'="'.$attrValue.'" ';
407
- }
408
-
409
- return $attrStr;
410
- }
411
-
412
- public static function getFormattedDate($date)
413
- {
414
- $date = strtotime($date);
415
- $month = date('F', $date);
416
- $year = date('Y', $date);
417
-
418
- return $month.' '.$year;
419
- }
420
-
421
- public static function defaultButtonImage($theme, $closeImage = '')
422
- {
423
- $currentPostType = self::getCurrentPopupType();
424
- if (defined('SGPB_POPUP_TYPE_RECENT_SALES') && $currentPostType == SGPB_POPUP_TYPE_RECENT_SALES) {
425
- $theme = 'sgpb-theme-6';
426
- }
427
- // if no image, set default by theme
428
- if ($closeImage == '') {
429
- if ($theme == 'sgpb-theme-1' || !$theme) {
430
- $closeImage = SG_POPUP_IMG_URL.'theme_1/close.png';
431
- }
432
- else if ($theme == 'sgpb-theme-2') {
433
- $closeImage = SG_POPUP_IMG_URL.'theme_2/close.png';
434
- }
435
- else if ($theme == 'sgpb-theme-3') {
436
- $closeImage = SG_POPUP_IMG_URL.'theme_3/close.png';
437
- }
438
- else if ($theme == 'sgpb-theme-5') {
439
- $closeImage = SG_POPUP_IMG_URL.'theme_5/close.png';
440
- }
441
- else if ($theme == 'sgpb-theme-6') {
442
- $closeImage = SG_POPUP_IMG_URL.'theme_6/close.png';
443
- }
444
- }
445
- else {
446
- $closeImage = self::getImageDataFromUrl($closeImage);
447
- }
448
-
449
- return $closeImage;
450
- }
451
-
452
- public static function getPopupPostAllowedUserRoles()
453
- {
454
- $userSavedRoles = get_option('sgpb-user-roles');
455
-
456
- if (empty($userSavedRoles) || !is_array($userSavedRoles)) {
457
- $userSavedRoles = array('administrator');
458
- }
459
- else {
460
- array_push($userSavedRoles, 'administrator');
461
- }
462
-
463
- return $userSavedRoles;
464
- }
465
-
466
- public static function showMenuForCurrentUser()
467
- {
468
- return self::userCanAccessTo();
469
- }
470
-
471
- public static function getPopupsIdAndTitle($excludesPopups = array())
472
- {
473
- $allPopups = SGPopup::getAllPopups();
474
- $popupIdTitles = array();
475
-
476
- if (empty($allPopups)) {
477
- return $popupIdTitles;
478
- }
479
-
480
- foreach ($allPopups as $popup) {
481
- if (empty($popup)) {
482
- continue;
483
- }
484
-
485
- $id = $popup->getId();
486
- $title = $popup->getTitle();
487
- $type = $popup->getType();
488
-
489
- if (!empty($excludesPopups)) {
490
- foreach ($excludesPopups as $excludesPopupId) {
491
- if ($excludesPopupId != $id) {
492
- $popupIdTitles[$id] = $title.' - '.$type;
493
- }
494
- }
495
- }
496
- else {
497
- $popupIdTitles[$id] = $title.' - '.$type;
498
- }
499
- }
500
-
501
- return $popupIdTitles;
502
- }
503
-
504
- /**
505
- * Merge two array and merge same key values to same array
506
- *
507
- * @since 1.0.0
508
- *
509
- * @param array $array1
510
- * @param array $array2
511
- *
512
- * @return array|bool
513
- *
514
- */
515
- public static function arrayMergeSameKeys($array1, $array2)
516
- {
517
- if (empty($array1)) {
518
- return array();
519
- }
520
-
521
- $modified = false;
522
- $array3 = array();
523
- foreach ($array1 as $key => $value) {
524
- if (isset($array2[$key]) && is_array($array2[$key])) {
525
- $arrDifference = array_diff($array2[$key], $array1[$key]);
526
- if (empty($arrDifference)) {
527
- continue;
528
- }
529
-
530
- $modified = true;
531
- $array3[$key] = array_merge($array2[$key], $array1[$key]);
532
- unset($array2[$key]);
533
- continue;
534
- }
535
-
536
- $modified = true;
537
- $array3[$key] = $value;
538
- }
539
-
540
- // when there are no values
541
- if (!$modified) {
542
- return $modified;
543
- }
544
-
545
- return $array2 + $array3;
546
- }
547
-
548
- public static function getCurrentUserRole()
549
- {
550
- $role = array('administrator');
551
-
552
- if (is_multisite()) {
553
-
554
- $getUsersObj = get_users(
555
- array(
556
- 'blog_id' => get_current_blog_id(),
557
- 'search' => get_current_user_id()
558
- )
559
- );
560
-
561
- if (!empty($getUsersObj[0])) {
562
- $roles = $getUsersObj[0]->roles;
563
-
564
- if (is_array($roles) && !empty($roles)) {
565
- $role = array_merge($role, $getUsersObj[0]->roles);
566
- }
567
- }
568
-
569
- return $role;
570
- }
571
-
572
- global $currentUser;
573
- if (!empty($currentUser)) {
574
- $userRoleName = $currentUser->roles;
575
- $role = $userRoleName;
576
- }
577
- else {
578
- global $current_user;
579
- if ($current_user) {
580
- $currentUser = wp_get_current_user();
581
- $role = $currentUser->roles;
582
- }
583
- }
584
-
585
- return $role;
586
- }
587
-
588
- public static function hexToRgba($color, $opacity = false)
589
- {
590
- $default = 'rgb(0,0,0)';
591
-
592
- //Return default if no color provided
593
- if (empty($color)) {
594
- return $default;
595
- }
596
-
597
- //Sanitize $color if "#" is provided
598
- if ($color[0] == '#') {
599
- $color = substr($color, 1);
600
- }
601
-
602
- //Check if color has 6 or 3 characters and get values
603
- if (strlen($color) == 6) {
604
- $hex = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);
605
- }
606
- else if (strlen($color) == 3) {
607
- $hex = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
608
- }
609
- else {
610
- return $default;
611
- }
612
-
613
- //Convert hexadec to rgb
614
- $rgb = array_map('hexdec', $hex);
615
-
616
- //Check if opacity is set(rgba or rgb)
617
- if ($opacity !== false) {
618
- if (abs($opacity) > 1) {
619
- $opacity = 1.0;
620
- }
621
- $output = 'rgba('.implode(',', $rgb).','.$opacity.')';
622
- }
623
- else {
624
- $output = 'rgb('.implode(',', $rgb).')';
625
- }
626
-
627
- //Return rgb(a) color string
628
- return $output;
629
- }
630
-
631
- public static function getAllActiveExtensions()
632
- {
633
- $extensions = SgpbDataConfig::getOldExtensionsInfo();
634
- $labels = array();
635
-
636
- foreach ($extensions as $extension) {
637
- if (file_exists(WP_PLUGIN_DIR.'/'.$extension['folderName'])) {
638
- $labels[] = $extension['label'];
639
- }
640
- }
641
-
642
- return $labels;
643
- }
644
-
645
- public static function renderExtensionsContent()
646
- {
647
- $extensions = self::getAllActiveExtensions();
648
- ob_start();
649
- ?>
650
- <p class="sgpb-extension-notice-close">x</p>
651
- <div class="sgpb-extensions-list-wrapper">
652
- <div class="sgpb-notice-header">
653
- <h3><?php _e('Popup Builder plugin has been successfully updated', SG_POPUP_TEXT_DOMAIN); ?></h3>
654
- <h4><?php _e('The following extensions need to be updated manually', SG_POPUP_TEXT_DOMAIN); ?></h4>
655
- </div>
656
- <ul class="sgpb-extensions-list">
657
- <?php foreach ($extensions as $extensionName): ?>
658
- <a target="_blank" href="https://popup-builder.com/forms/control-panel/"><li><?php echo $extensionName; ?></li></a>
659
- <?php endforeach; ?>
660
- </ul>
661
- </div>
662
- <p class="sgpb-extension-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN)?></p>
663
- <?php
664
- $content = ob_get_contents();
665
- ob_get_clean();
666
-
667
- return $content;
668
- }
669
-
670
- public static function getReverseConvertIds()
671
- {
672
- $idsMappingSaved = get_option('sgpbConvertedIds');
673
- $ids = array();
674
-
675
- if ($idsMappingSaved) {
676
- $ids = $idsMappingSaved;
677
- }
678
-
679
- return array_flip($ids);
680
- }
681
-
682
- public static function getAllFreeExtensions()
683
- {
684
- $allExtensions = SgpbDataConfig::allFreeExtensionsKeys();
685
-
686
- $notActiveExtensions = array();
687
- $activeExtensions = array();
688
-
689
- foreach ($allExtensions as $extension) {
690
- if (!is_plugin_active($extension['pluginKey'])) {
691
- $notActiveExtensions[] = $extension;
692
- }
693
- else {
694
- $activeExtensions[] = $extension;
695
- }
696
- }
697
-
698
- $divideExtension = array(
699
- 'noActive' => $notActiveExtensions,
700
- 'active' => $activeExtensions
701
- );
702
-
703
- return $divideExtension;
704
- }
705
-
706
- public static function getAllExtensions()
707
- {
708
- $allExtensions = SgpbDataConfig::allExtensionsKeys();
709
-
710
- $notActiveExtensions = array();
711
- $activeExtensions = array();
712
-
713
- foreach ($allExtensions as $extension) {
714
- if (!is_plugin_active($extension['pluginKey'])) {
715
- $notActiveExtensions[] = $extension;
716
- }
717
- else {
718
- $activeExtensions[] = $extension;
719
- }
720
- }
721
-
722
- $divideExtension = array(
723
- 'noActive' => $notActiveExtensions,
724
- 'active' => $activeExtensions
725
- );
726
-
727
- return $divideExtension;
728
- }
729
-
730
- public static function renderAlertProblem()
731
- {
732
- ob_start();
733
- ?>
734
- <div id="welcome-panel" class="update-nag sgpb-alert-problem">
735
- <div class="welcome-panel-content">
736
- <p class="sgpb-problem-notice-close">x</p>
737
- <div class="sgpb-alert-problem-text-wrapper">
738
- <h3><?php _e('Popup Builder plugin has been updated to the new version 3.', SG_POPUP_TEXT_DOMAIN); ?></h3>
739
- <h5><?php _e('A lot of changes and improvements have been made.', SG_POPUP_TEXT_DOMAIN); ?></h5>
740
- <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>
741
- </div>
742
- <p class="sgpb-problem-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN); ?></p>
743
- </div>
744
- </div>
745
- <?php
746
- $content = ob_get_clean();
747
-
748
- return $content;
749
- }
750
-
751
- public static function getTaxonomyBySlug($slug = '')
752
- {
753
- $allTerms = get_terms(array('hide_empty' => false));
754
-
755
- $result = array();
756
- if (empty($allTerms)) {
757
- return $result;
758
- }
759
- if ($slug == '') {
760
- return $allTerms;
761
- }
762
- foreach ($allTerms as $term) {
763
- if ($term->slug == $slug) {
764
- return $term;
765
- }
766
- }
767
- }
768
-
769
- public static function getCurrentPopupType()
770
- {
771
- $type = '';
772
- if (!empty($_GET['sgpb_type'])) {
773
- $type = $_GET['sgpb_type'];
774
- }
775
-
776
- $currentPostType = self::getCurrentPostType();
777
-
778
- if ($currentPostType == SG_POPUP_POST_TYPE && !empty($_GET['post'])) {
779
- $popupObj = SGPopup::find($_GET['post']);
780
- if (is_object($popupObj)) {
781
- $type = $popupObj->getType();
782
- }
783
- }
784
-
785
- return $type;
786
- }
787
-
788
- public static function getCurrentPostType()
789
- {
790
- global $post_type;
791
- global $post;
792
- $currentPostType = '';
793
-
794
- if (is_object($post)) {
795
- $currentPostType = $post->post_type;
796
- }
797
-
798
- // in some themes global $post returns null
799
- if (empty($currentPostType)) {
800
- $currentPostType = $post_type;
801
- }
802
-
803
- if (empty($currentPostType) && !empty($_GET['post'])) {
804
- $currentPostType = get_post_type($_GET['post']);
805
- }
806
-
807
- return $currentPostType;
808
- }
809
-
810
- /**
811
- * Get image encoded data from URL
812
- *
813
- * @param $imageUrl
814
- * @param $shouldNotConvertBase64
815
- *
816
- * @return string
817
- */
818
-
819
- public static function getImageDataFromUrl($imageUrl, $shouldNotConvertBase64 = false)
820
- {
821
- $remoteData = wp_remote_get($imageUrl);
822
- if (is_wp_error($remoteData) && $shouldNotConvertBase64) {
823
- return SG_POPUP_IMG_URL.'NoImage.png';
824
- }
825
-
826
- if (!$shouldNotConvertBase64) {
827
- $imageData = wp_remote_retrieve_body($remoteData);
828
- $imageUrl = base64_encode($imageData);
829
- }
830
-
831
- return $imageUrl;
832
- }
833
-
834
- public static function deleteUserFromSubscribers($params = array())
835
- {
836
- global $wpdb;
837
-
838
- $email = '';
839
- $popup = '';
840
- $noSubscriber = true;
841
-
842
- if (isset($params['email'])) {
843
- $email = $params['email'];
844
- }
845
- if (isset($params['popup'])) {
846
- $popup = $params['popup'];
847
- }
848
-
849
- $prepareSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s && subscriptionType = %s', $email, $popup);
850
- $res = $wpdb->get_row($prepareSql, ARRAY_A);
851
- if (!isset($res['id'])) {
852
- $noSubscriber = false;
853
- }
854
- $params['subscriberId'] = $res['id'];
855
-
856
- $subscriber = self::subscriberExists($params);
857
- if ($subscriber && $noSubscriber) {
858
- self::deleteSubscriber($params);
859
- }
860
- else if (!$noSubscriber) {
861
- _e('<span>Oops, something went wrong, please try again or contact the administrator to check more info.</span>', SG_POPUP_TEXT_DOMAIN);
862
- wp_die();
863
- }
864
- }
865
-
866
- public static function subscriberExists($params = array())
867
- {
868
- if (empty($params)) {
869
- return false;
870
- }
871
-
872
- $receivedToken = $params['token'];
873
- $realToken = md5($params['subscriberId'].$params['email']);
874
- if ($receivedToken == $realToken) {
875
- return true;
876
- }
877
-
878
- }
879
-
880
- public static function deleteSubscriber($params = array())
881
- {
882
- global $wpdb;
883
- $homeUrl = get_home_url();
884
-
885
- if (empty($params)) {
886
- return false;
887
- }
888
- // send email to admin about user unsubscription
889
- self::sendEmailAboutUnsubscribe($params);
890
-
891
- $prepareSql = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET unsubscribed = 1 WHERE id = %s ', $params['subscriberId']);
892
- $wpdb->query($prepareSql);
893
-
894
- _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);
895
- wp_die();
896
- }
897
-
898
- public static function sendEmailAboutUnsubscribe($params = array())
899
- {
900
- if (empty($params)) {
901
- return false;
902
- }
903
-
904
- $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
905
- $receiverEmail = get_bloginfo('admin_email');
906
- $userEmail = $params['email'];
907
- $emailTitle = __('Unsubscription', SG_POPUP_TEXT_DOMAIN);
908
- $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
909
- $subscriptionFormTitle = get_the_title($subscriptionFormId);
910
-
911
- $message = __('User with '.$userEmail.' email has unsubscribed from '.$subscriptionFormTitle.' mail list', SG_POPUP_TEXT_DOMAIN);
912
-
913
- $headers = 'MIME-Version: 1.0'."\r\n";
914
- $headers .= 'From: WordPress Popup Builder'."\r\n";
915
- $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
916
-
917
- wp_mail($receiverEmail, $emailTitle, $message, $headers);
918
- }
919
-
920
- public static function addUnsubscribeColumn()
921
- {
922
- global $wpdb;
923
-
924
- $sql = 'ALTER TABLE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' ADD COLUMN unsubscribed INT NOT NULL DEFAULT 0 ';
925
- $wpdb->query($sql);
926
- }
927
-
928
- public static function isPluginActive($key)
929
- {
930
- $allExtensions = SgpbDataConfig::allExtensionsKeys();
931
- $isActive = false;
932
- foreach ($allExtensions as $extension) {
933
- if (isset($extension['key']) && $extension['key'] == $key) {
934
- if (is_plugin_active($extension['pluginKey'])) {
935
- $isActive = true;
936
- return $isActive;
937
- }
938
- }
939
- }
940
-
941
- return $isActive;
942
- }
943
-
944
- public static function supportBannerNotification()
945
- {
946
- $content = '<div class="sgpb-support-notification-wrapper sgpb-wrapper"><h4 class="sgpb-support-notification-title">'.__('Need some help?', SG_POPUP_TEXT_DOMAIN).'</h4>';
947
- $content .= '<h4 class="sgpb-support-notification-title">'.__('Let us know what you think.', SG_POPUP_TEXT_DOMAIN).'</h4>';
948
- $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>';
949
- $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>';
950
- $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>';
951
- $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>';
952
- $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>';
953
- $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>';
954
-
955
- return $content;
956
- }
957
-
958
- public static function getMaxOpenDaysMessage()
959
- {
960
- $getUsageDays = self::getPopupUsageDays();
961
- $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);
962
- $popupContent = self::getMaxOpenPopupContent($firstHeader, 'days');
963
-
964
- return $popupContent;
965
- }
966
-
967
- public static function getPopupUsageDays()
968
- {
969
- $installDate = get_option('SGPBInstallDate');
970
-
971
- $timeDate = new \DateTime('now');
972
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
973
- $diff = $timeNow-$installDate;
974
- $days = floor($diff/(60*60*24));
975
-
976
- return $days;
977
- }
978
-
979
- public static function getMaxOpenPopupContent($firstHeader, $type)
980
- {
981
- ob_start();
982
- ?>
983
- <style>
984
- .sgpb-buttons-wrapper .press{
985
- box-sizing:border-box;
986
- cursor:pointer;
987
- display:inline-block;
988
- font-size:1em;
989
- margin:0;
990
- padding:0.5em 0.75em;
991
- text-decoration:none;
992
- transition:background 0.15s linear
993
- }
994
- .sgpb-buttons-wrapper .press-grey {
995
- background-color:#9E9E9E;
996
- border:2px solid #9E9E9E;
997
- color: #FFF;
998
- }
999
- .sgpb-buttons-wrapper .press-lightblue {
1000
- background-color:#03A9F4;
1001
- border:2px solid #03A9F4;
1002
- color: #FFF;
1003
- }
1004
- .sgpb-buttons-wrapper {
1005
- text-align: center;
1006
- }
1007
- .sgpb-review-wrapper{
1008
- text-align: center;
1009
- padding: 20px;
1010
- }
1011
- .sgpb-review-wrapper p {
1012
- color: black;
1013
- }
1014
- .sgpb-review-h1 {
1015
- font-size: 22px;
1016
- font-weight: normal;
1017
- line-height: 1.384;
1018
- }
1019
- .sgrb-review-h2{
1020
- font-size: 20px;
1021
- font-weight: normal;
1022
- }
1023
- :root {
1024
- --main-bg-color: #1ac6ff;
1025
- }
1026
- .sgrb-review-strong{
1027
- color: var(--main-bg-color);
1028
- }
1029
- .sgrb-review-mt20{
1030
- margin-top: 20px
1031
- }
1032
- </style>
1033
- <div class="sgpb-review-wrapper">
1034
- <div class="sgpb-review-description">
1035
- <?php echo $firstHeader; ?>
1036
- <h2 class="sgrb-review-h2"><?php _e('This is really great for your website score.', SG_POPUP_TEXT_DOMAIN); ?></h2>
1037
- <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>
1038
- </div>
1039
- <div class="sgpb-buttons-wrapper">
1040
- <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>
1041
- <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>
1042
- <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>
1043
- <div> </div>
1044
- </div>
1045
- <?php
1046
- $popupContent = ob_get_clean();
1047
-
1048
- return $popupContent;
1049
- }
1050
-
1051
- public static function shouldOpenReviewPopupForDays()
1052
- {
1053
- $shouldOpen = true;
1054
- $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1055
- $periodNextTime = get_option('SGPBOpenNextTime');
1056
- /*if (!$dontShowAgain) {
1057
- return true;
1058
- }
1059
- else {
1060
- return false;
1061
- }*/
1062
- // When period next time does not exits it means the user is old
1063
- if (!$periodNextTime) {
1064
- $usageDays = self::getPopupMainTableCreationDate();
1065
- update_option('SGPBUsageDays', $usageDays);
1066
- if (!defined('SGPB_REVIEW_POPUP_PERIOD')) {
1067
- define('SGPB_REVIEW_POPUP_PERIOD', '500');
1068
- }
1069
- // For old users
1070
- if (defined('SGPB_REVIEW_POPUP_PERIOD') && $usageDays > SGPB_REVIEW_POPUP_PERIOD && !$dontShowAgain) {
1071
- return $shouldOpen;
1072
- }
1073
- $remainingDays = SGPB_REVIEW_POPUP_PERIOD - $usageDays;
1074
-
1075
- $popupTimeZone = \ConfigDataHelper::getDefaultTimezone();
1076
- $timeDate = new DateTime('now', new DateTimeZone($popupTimeZone));
1077
- $timeDate->modify('+'.$remainingDays.' day');
1078
-
1079
- $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
1080
- update_option('SGPBOpenNextTime', $timeNow);
1081
-
1082
- return false;
1083
- }
1084
-
1085
- $currentData = new \DateTime('now');
1086
- $timeNow = $currentData->format('Y-m-d H:i:s');
1087
- $timeNow = strtotime($timeNow);
1088
-
1089
- if ($periodNextTime > $timeNow) {
1090
- $shouldOpen = false;
1091
- }
1092
-
1093
- return $shouldOpen;
1094
- }
1095
-
1096
- public static function getPopupMainTableCreationDate()
1097
- {
1098
- global $wpdb;
1099
-
1100
- $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');
1101
- $results = $wpdb->get_results($query, ARRAY_A);
1102
- if (empty($results)) {
1103
- return 0;
1104
- }
1105
-
1106
- $createTime = $results[0]['create_time'];
1107
- $createTime = strtotime($createTime);
1108
- update_option('SGPBInstallDate', $createTime);
1109
- $diff = time() - $createTime;
1110
- $days = floor($diff/(60*60*24));
1111
-
1112
- return $days;
1113
- }
1114
-
1115
- public static function shouldOpenForMaxOpenPopupMessage()
1116
- {
1117
- $counterMaxPopup = self::getMaxOpenPopupId();
1118
-
1119
- if (empty($counterMaxPopup)) {
1120
- return false;
1121
- }
1122
- $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1123
- $maxCountDefine = get_option('SGPBMaxOpenCount');
1124
-
1125
- if (!$maxCountDefine) {
1126
- $maxCountDefine = SGPB_ASK_REVIEW_POPUP_COUNT;
1127
- }
1128
-
1129
- return $counterMaxPopup['maxCount'] >= $maxCountDefine && !$dontShowAgain;
1130
- }
1131
-
1132
- public static function getMaxOpenPopupId()
1133
- {
1134
- $popupsCounterData = get_option('SgpbCounter');
1135
- if (!$popupsCounterData) {
1136
- return 0;
1137
- }
1138
-
1139
- $counters = array_values($popupsCounterData);
1140
- $maxCount = max($counters);
1141
- $popupId = array_search($maxCount, $popupsCounterData);
1142
-
1143
- $maxPopupData = array(
1144
- 'popupId' => $popupId,
1145
- 'maxCount' => $maxCount
1146
- );
1147
-
1148
- return $maxPopupData;
1149
- }
1150
-
1151
- public static function getMaxOpenPopupsMessage()
1152
- {
1153
- $counterMaxPopup = self::getMaxOpenPopupId();
1154
- $maxCountDefine = get_option('SGPBMaxOpenCount');
1155
- $popupTitle = get_the_title($counterMaxPopup['popupId']);
1156
-
1157
- if (!empty($counterMaxPopup['maxCount'])) {
1158
- $maxCountDefine = $counterMaxPopup['maxCount'];
1159
- }
1160
-
1161
- $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);
1162
- $popupContent = self::getMaxOpenPopupContent($firstHeader, 'count');
1163
-
1164
- return $popupContent;
1165
- }
1166
-
1167
- /**
1168
- * Get email headers
1169
- *
1170
- * @since 3.1.0
1171
- *
1172
- * @param email $fromEmail
1173
- * @param array $args
1174
- *
1175
- * @return string $headers
1176
- */
1177
- public static function getEmailHeader($fromEmail, $args = array())
1178
- {
1179
- $contentType = 'text/html';
1180
- $charset = 'UTF-8';
1181
- $blogInfo = get_bloginfo();
1182
-
1183
- if (!empty($args['contentType'])) {
1184
- $contentType = $args['contentType'];
1185
- }
1186
- if (!empty($args['charset'])) {
1187
- $charset = $args['charset'];
1188
- }
1189
-
1190
- $headers = 'MIME-Version: 1.0'."\r\n";
1191
- $headers .= 'From: "'.$blogInfo.'" <'.$fromEmail.'>'."\r\n";
1192
- $headers .= 'Content-type: '.$contentType.'; charset='.$charset.''."\r\n"; //set UTF-8
1193
-
1194
- return $headers;
1195
- }
1196
-
1197
- /**
1198
- * Get file content from URL
1199
- *
1200
- * @since 3.1.0
1201
- *
1202
- * @param $url
1203
- *
1204
- * @return string
1205
- */
1206
- public static function getFileFromURL($url)
1207
- {
1208
- $data = '';
1209
- $remoteData = wp_remote_get($url);
1210
-
1211
- if (is_wp_error($remoteData)) {
1212
- return $data;
1213
- }
1214
-
1215
- $data = wp_remote_retrieve_body($remoteData);
1216
-
1217
- return $data;
1218
- }
1219
-
1220
- public static function getRightMetaboxBannerText()
1221
- {
1222
- $bannerText = get_option('sgpb-metabox-banner-remote-get');
1223
-
1224
- return $bannerText;
1225
- }
1226
-
1227
- public static function getGutenbergPopupsIdAndTitle($excludesPopups = array())
1228
- {
1229
- $allPopups = SGPopup::getAllPopups();
1230
- $popupIdTitles = array();
1231
-
1232
- if (empty($allPopups)) {
1233
- return $popupIdTitles;
1234
- }
1235
-
1236
- foreach ($allPopups as $popup) {
1237
- if (empty($popup)) {
1238
- continue;
1239
- }
1240
-
1241
- $id = $popup->getId();
1242
- $title = $popup->getTitle();
1243
- $type = $popup->getType();
1244
-
1245
- if (!empty($excludesPopups)) {
1246
- foreach ($excludesPopups as $excludesPopupId) {
1247
- if ($excludesPopupId != $id) {
1248
- $array = array();
1249
- $array['id'] = $id;
1250
- $array['title'] = $title.' - '.$type;
1251
- $popupIdTitles[] = $array;
1252
- }
1253
- }
1254
- }
1255
- else {
1256
- $array = array();
1257
- $array['id'] = $id;
1258
- $array['title'] = $title.' - '.$type;
1259
- $popupIdTitles[] = $array;
1260
- }
1261
- }
1262
-
1263
- return $popupIdTitles;
1264
- }
1265
-
1266
- public static function getGutenbergPopupsEvents()
1267
- {
1268
- $data = array(
1269
- array('value' => '', 'title' => __('Select Event', SG_POPUP_TEXT_DOMAIN)),
1270
- array('value' => 'inherit', 'title' => __('Inherit', SG_POPUP_TEXT_DOMAIN)),
1271
- array('value' => 'onLoad', 'title' => __('On load', SG_POPUP_TEXT_DOMAIN)),
1272
- array('value' => 'click', 'title' => __('On click', SG_POPUP_TEXT_DOMAIN)),
1273
- array('value' => 'hover', 'title' => __('On hover', SG_POPUP_TEXT_DOMAIN))
1274
- );
1275
-
1276
- return $data;
1277
- }
1278
-
1279
- public static function checkEditorByPopupId($popupId)
1280
- {
1281
- $popupContent = '';
1282
- if (class_exists('\Elementor\Plugin')) {
1283
- $elementorContent = get_post_meta($popupId, '_elementor_edit_mode', true);
1284
- if (!empty($elementorContent) && $elementorContent == 'builder') {
1285
- $popupContent = Elementor\Plugin::instance()->frontend->get_builder_content_for_display($popupId);
1286
- }
1287
- }
1288
- else if (class_exists('Vc_Manager')) {
1289
- $stylesAndScripts = self::renderWPBakeryScriptsAndStyles($popupId);
1290
- $popupContent .= '<style>'.$stylesAndScripts.'</style>';
1291
- }
1292
-
1293
- return $popupContent;
1294
- }
1295
-
1296
- public static function renderWPBakeryScriptsAndStyles($popupId = 0)
1297
- {
1298
- return get_post_meta($popupId, '_wpb_shortcodes_custom_css', true);
1299
- }
1300
-
1301
- /**
1302
- * countdown popup, convert date to seconds
1303
- *
1304
- * @param $dueDate
1305
- * @param $timezone
1306
- * @return false|int|string
1307
- */
1308
- public static function dateToSeconds($dueDate, $timezone)
1309
- {
1310
- if (empty($timezone)) {
1311
- return '';
1312
- }
1313
-
1314
- $dateObj = self::getDateObjFromDate('now', $timezone);
1315
- $timeNow = @strtotime($dateObj);
1316
- $seconds = @strtotime($dueDate)-$timeNow;
1317
- if ($seconds < 0) {
1318
- $seconds = 0;
1319
- }
1320
-
1321
- return $seconds;
1322
- }
1323
-
1324
- /**
1325
- * Get site protocol
1326
- *
1327
- * @since 1.0.0
1328
- *
1329
- * @return string $protocol
1330
- *
1331
- */
1332
- public static function getSiteProtocol()
1333
- {
1334
- $protocol = 'http';
1335
-
1336
- if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
1337
- $protocol = 'https';
1338
- }
1339
-
1340
- return $protocol;
1341
- }
1342
-
1343
- public static function findSubscribersByEmail($subscriberEmail = '', $list = 0)
1344
- {
1345
- global $wpdb;
1346
- $subscriber = array();
1347
-
1348
- $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d ', $subscriberEmail, $list);
1349
- $subscriber = $wpdb->get_row($prepareSql, ARRAY_A);
1350
- if (!$list) {
1351
- $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s ', $subscriberEmail);
1352
- $subscriber = $wpdb->get_results($prepareSql, ARRAY_A);
1353
- }
1354
-
1355
- return $subscriber;
1356
- }
1357
-
1358
- /**
1359
- * Update option
1360
- *
1361
- * @since 3.1.9
1362
- *
1363
- * @return void
1364
- */
1365
- public static function updateOption($optionKey, $optionValue)
1366
- {
1367
- update_option($optionKey, $optionValue);
1368
- }
1369
-
1370
- public static function getOption($optionKey, $default = false)
1371
- {
1372
- return get_option($optionKey, $default);
1373
- }
1374
-
1375
- public static function deleteOption($optionKey)
1376
- {
1377
- delete_option($optionKey);
1378
- }
1379
-
1380
- /**
1381
- * It's change popup registered plugins static paths to dynamic
1382
- *
1383
- * @since 3.1.9
1384
- *
1385
- * @return bool where true mean modified false mean there is not need modification
1386
- */
1387
- public static function makeRegisteredPluginsStaticPathsToDynamic()
1388
- {
1389
- // remove old outdated option sgpbModifiedRegisteredPluginsPaths
1390
- delete_option('sgpbModifiedRegisteredPluginsPaths');
1391
- delete_option('SG_POPUP_BUILDER_REGISTERED_PLUGINS');
1392
- $hasModifiedPaths = AdminHelper::getOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED);
1393
- if ($hasModifiedPaths) {
1394
- return false;
1395
- }
1396
- else {
1397
- Installer::registerPlugin();
1398
- }
1399
- AdminHelper::updateOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED, 1);
1400
-
1401
- $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1402
- if (empty($registeredPlugins)) {
1403
- return false;
1404
- }
1405
-
1406
- $registeredPlugins = json_decode($registeredPlugins, true);
1407
- if (empty($registeredPlugins)) {
1408
- return false;
1409
- }
1410
-
1411
- foreach ($registeredPlugins as $key => $registeredPlugin) {
1412
- if (empty($registeredPlugin['classPath'])) {
1413
- continue;
1414
- }
1415
- $registeredPlugins[$key]['classPath'] = str_replace(WP_PLUGIN_DIR, '', $registeredPlugin['classPath']);
1416
- if (!empty($registeredPlugin['options']['licence']['file'])) {
1417
- $registeredPlugins[$key]['options']['licence']['file'] = $registeredPlugin['options']['licence']['file'];
1418
- }
1419
- }
1420
- $registeredPlugins = json_encode($registeredPlugins);
1421
-
1422
- AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredPlugins);
1423
- return true;
1424
- }
1425
-
1426
- public static function hasInactiveExtensions()
1427
- {
1428
- $hasInactiveExtensions = false;
1429
- $allRegiseredPBPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1430
- $allRegiseredPBPlugins = @json_decode($allRegiseredPBPlugins, true);
1431
- if (empty($allRegiseredPBPlugins)) {
1432
- return $hasInactiveExtensions;
1433
- }
1434
-
1435
- foreach ($allRegiseredPBPlugins as $pluginPath => $registeredPlugin) {
1436
- if (!isset($registeredPlugin['options']['licence']['key'])) {
1437
- continue;
1438
- }
1439
- if (!isset($registeredPlugin['options']['licence']['file'])) {
1440
- continue;
1441
- }
1442
- $extensionKey = $registeredPlugin['options']['licence']['file'];
1443
- $isPluginActive = is_plugin_active($extensionKey);
1444
- $pluginKey = $registeredPlugin['options']['licence']['key'];
1445
- $isValidLicense = get_option('sgpb-license-status-'.$pluginKey);
1446
-
1447
- // if we even have at least one inactive extension, we don't need to check remaining extensions
1448
- if ($isValidLicense != 'valid' && $isPluginActive) {
1449
- $hasInactiveExtensions = true;
1450
- break;
1451
- }
1452
- }
1453
-
1454
- return $hasInactiveExtensions;
1455
- }
1456
-
1457
- public static function getSubscriptionColumnsById($id)
1458
- {
1459
- $popup = SGPopup::find($id);
1460
- if (empty($popup) || !is_object($popup)) {
1461
- return array();
1462
- }
1463
- $freeSavedOptions = $popup->getOptionValue('sgpb-subs-fields');
1464
-
1465
- if (!empty($freeSavedOptions)) {
1466
- return array('firstName' => 'First name','lastName' => 'Last name', 'email' => 'Email', 'date' => 'Date');
1467
- }
1468
- $formFieldsJson = $popup->getOptionValue('sgpb-subscription-fields-json');
1469
- if (!empty($formFieldsJson)) {
1470
- $data = apply_filters('sgpbGetSubscriptionLabels', array(), $popup);
1471
- $data['date'] = 'Date';
1472
- return $data;
1473
- }
1474
-
1475
- return array();
1476
- }
1477
-
1478
- public static function getCustomFormFieldsByPopupId($popupId)
1479
- {
1480
- if (!class_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper')) {
1481
- return array();
1482
- }
1483
-
1484
- if (method_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper', 'getCustomFormFieldsByPopupId')) {
1485
- return SubscriptionPlusAdminHelper::getCustomFormFieldsByPopupId($popupId);
1486
- }
1487
-
1488
- return array();
1489
- }
1490
-
1491
- public static function removeAllNonPrintableCharacters($title, $defaultValue)
1492
- {
1493
- $titleRes = $title;
1494
- $pattern = '/[\\\^£$%&*()}{@#~?><>,|=_+¬-]/u';
1495
- $title = preg_replace($pattern, '', $title);
1496
- $title = mb_ereg_replace($pattern, '', $title);
1497
- $title = htmlspecialchars($title, ENT_IGNORE, 'UTF-8');
1498
- $result = str_replace(' ', '', $title);
1499
- if (empty($result)) {
1500
- $titleRes = $defaultValue;
1501
- }
1502
-
1503
- return $titleRes;
1504
- }
1505
-
1506
- public static function renderCustomScripts($popupId)
1507
- {
1508
- $finalResult = '';
1509
- $postMeta = get_post_meta($popupId, 'sg_popup_scripts', true);
1510
- if (empty($postMeta)) {
1511
- return '';
1512
- }
1513
- $defaultData = \ConfigDataHelper::defaultData();
1514
-
1515
- // get scripts
1516
- if (!isset($postMeta['js'])) {
1517
- $postMeta['js'] = array();
1518
- }
1519
- $jsPostMeta = $postMeta['js'];
1520
- $jsDefaultData = $defaultData['customEditorContent']['js']['helperText'];
1521
- $suspiciousStrings = array('document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode', '<!--', '-->');
1522
- $finalContent = '';
1523
- $suspiciousStringFound = false;
1524
- if (!empty($jsPostMeta)) {
1525
- $customScripts = '<script id="sgpb-custom-script-'.$popupId.'">';
1526
- foreach ($jsDefaultData as $key => $value) {
1527
- $eventName = 'sgpb'.$key;
1528
- if ((!isset($jsPostMeta['sgpb-'.$key]) || empty($jsPostMeta['sgpb-'.$key])) || $key == 'ShouldOpen' || $key == 'ShouldClose') {
1529
- continue;
1530
- }
1531
- $content = @$jsPostMeta['sgpb-'.$key];
1532
- $content = str_replace('popupId', $popupId, $content);
1533
- $content = str_replace("<", "&lt;", $content);
1534
- $content = str_replace(">", "&gt;", $content);
1535
- foreach ($suspiciousStrings as $string) {
1536
- if (strpos($content, $string)) {
1537
- $suspiciousStringFound = true;
1538
- break;
1539
- }
1540
- }
1541
- if ($suspiciousStringFound) {
1542
- break;
1543
- }
1544
- $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
1545
-
1546
- $finalContent .= 'jQuery(document).ready(function(){';
1547
- $finalContent .= 'sgAddEvent(window, "'.$eventName.'", function(e) {';
1548
- $finalContent .= 'if (e.detail.popupId == "'.$popupId.'") {';
1549
- $finalContent .= $content;
1550
- $finalContent .= '};';
1551
- $finalContent .= '});';
1552
- $finalContent .= '});';
1553
- }
1554
- $customScripts .= $finalContent;
1555
- $customScripts .= '</script>';
1556
- if (empty($finalContent)) {
1557
- $customScripts = '';
1558
- }
1559
- $finalResult .= $customScripts;
1560
- }
1561
-
1562
- // get styles
1563
- if (isset($postMeta['css'])) {
1564
- $cssPostMeta = $postMeta['css'];
1565
- }
1566
- $finalContent = '';
1567
- if (!empty($cssPostMeta)) {
1568
- $customStyles = '<style id="sgpb-custom-style-'.$popupId.'">';
1569
- $finalContent = str_replace('popupId', $popupId, $cssPostMeta);
1570
- $finalContent = html_entity_decode($finalContent, ENT_QUOTES, 'UTF-8');
1571
-
1572
- $customStyles .= $finalContent;
1573
- $customStyles .= '</style>';
1574
- $finalResult .= $customStyles;
1575
- }
1576
-
1577
-
1578
- return $finalResult;
1579
- }
1580
-
1581
- public static function removeSelectedTypeOptions($type)
1582
- {
1583
- switch ($type) {
1584
- case 'cron':
1585
- $crons = _get_cron_array();
1586
- foreach ($crons as $key => $value) {
1587
- foreach ($value as $key => $body) {
1588
- if (strstr($key, 'sgpb')) {
1589
- wp_clear_scheduled_hook($key);
1590
- }
1591
- }
1592
- }
1593
- break;
1594
- }
1595
- }
1596
-
1597
- public static function getSystemInfoText() {
1598
- global $wpdb;
1599
-
1600
- $browser = self::getBrowser();
1601
-
1602
- // Get theme info
1603
- if (get_bloginfo('version') < '3.4') {
1604
- $themeData = wp_get_theme(get_stylesheet_directory().'/style.css');
1605
- $theme = $themeData['Name'].' '.$themeData['Version'];
1606
- }
1607
- else {
1608
- $themeData = wp_get_theme();
1609
- $theme = $themeData->Name.' '.$themeData->Version;
1610
- }
1611
-
1612
- // Try to identify the hosting provider
1613
- $host = self::getHost();
1614
-
1615
- $systemInfoContent = '### Start System Info ###'."\n\n";
1616
-
1617
- // Start with the basics...
1618
- $systemInfoContent .= '-- Site Info'."\n\n";
1619
- $systemInfoContent .= 'Site URL: '.site_url()."\n";
1620
- $systemInfoContent .= 'Home URL: '.home_url()."\n";
1621
- $systemInfoContent .= 'Multisite: '.(is_multisite() ? 'Yes' : 'No')."\n";
1622
-
1623
- // Can we determine the site's host?
1624
- if ($host) {
1625
- $systemInfoContent .= "\n".'-- Hosting Provider'."\n\n";
1626
- $systemInfoContent .= 'Host: '.$host."\n";
1627
- }
1628
-
1629
- // The local users' browser information, handled by the Browser class
1630
- $systemInfoContent .= "\n".'-- User Browser'."\n\n";
1631
- $systemInfoContent .= $browser;
1632
-
1633
- // WordPress configuration
1634
- $systemInfoContent .= "\n".'-- WordPress Configuration'."\n\n";
1635
- $systemInfoContent .= 'Version: '.get_bloginfo('version')."\n";
1636
- $systemInfoContent .= 'Language: '.(defined('WPLANG') && WPLANG ? WPLANG : 'en_US')."\n";
1637
- $systemInfoContent .= 'Permalink Structure: '.(get_option('permalink_structure') ? get_option('permalink_structure') : 'Default')."\n";
1638
- $systemInfoContent .= 'Active Theme: '.$theme."\n";
1639
- $systemInfoContent .= 'Show On Front: '.get_option('show_on_front')."\n";
1640
-
1641
- // Only show page specs if frontpage is set to 'page'
1642
- if (get_option('show_on_front') == 'page') {
1643
- $frontPageId = get_option('page_on_front');
1644
- $blogPageId = get_option('page_for_posts');
1645
-
1646
- $systemInfoContent .= 'Page On Front: '.($frontPageId != 0 ? get_the_title($frontPageId).' (#'.$frontPageId.')' : 'Unset')."\n";
1647
- $systemInfoContent .= 'Page For Posts: '.($blogPageId != 0 ? get_the_title($blogPageId).' (#'.$blogPageId.')' : 'Unset')."\n";
1648
- }
1649
-
1650
- $systemInfoContent .= 'Table Prefix: '.'Prefix: '.$wpdb->prefix.' Length: '.strlen($wpdb->prefix ).' Status: '.( strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable')."\n";
1651
- $systemInfoContent .= 'WP_DEBUG: '.(defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set')."\n";
1652
- $systemInfoContent .= 'Memory Limit: '.WP_MEMORY_LIMIT."\n";
1653
- $systemInfoContent .= 'Registered Post Stati: '.implode(', ', get_post_stati())."\n";
1654
-
1655
- // Must-use plugins
1656
- $muplugins = get_mu_plugins();
1657
- if ($muplugins && count($muplugins)) {
1658
- $systemInfoContent .= "\n".'-- Must-Use Plugins'."\n\n";
1659
-
1660
- foreach ($muplugins as $plugin => $plugin_data) {
1661
- $systemInfoContent .= $plugin_data['Name'].': '.$plugin_data['Version']."\n";
1662
- }
1663
- }
1664
-
1665
- $registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1666
- $registered = json_decode($registered, true);
1667
-
1668
- if (empty($registered)) {
1669
- return false;
1670
- }
1671
- // remove free package data, we don't need it
1672
- array_shift($registered);
1673
-
1674
- $systemInfoContent .= "\n".'-- Popup Builder License Data'."\n\n";
1675
- if (!empty($registered)) {
1676
- foreach ($registered as $singleExntensionData) {
1677
- $key = $singleExntensionData['options']['licence']['key'];
1678
- $name = $singleExntensionData['options']['licence']['itemName'];
1679
- $licenseKey = __('No license');
1680
- if (!empty($key)) {
1681
- $licenseKey = self::getOption('sgpb-license-key-'.$key);
1682
- }
1683
- $licenseStatus = 'Inactive';
1684
- if (self::getOption('sgpb-license-status-'.$key) == 'valid') {
1685
- $licenseStatus = 'Active';
1686
- }
1687
-
1688
- $systemInfoContent .= 'Name: '.$name."\n";
1689
- $systemInfoContent .= 'License key: '.$licenseKey."\n";
1690
- $systemInfoContent .= 'License status: '.$licenseStatus."\n";
1691
- $systemInfoContent .= "\n";
1692
- }
1693
- }
1694
-
1695
- $systemInfoContent .= "\n".'-- All created Popups'."\n\n";
1696
- $allPopups = self::getPopupsIdAndTitle();
1697
- $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
1698
- foreach ($allPopups as $id => $popupTitleType) {
1699
- $popup = SGPopup::find($id, $args);
1700
- $popupStatus = ($popup->getOptionValue('sgpb-is-active')) ? 'Enabled' : 'Disabled';
1701
- $systemInfoContent .= 'Id: '.$id."\n";
1702
- $systemInfoContent .= 'Title: '.get_the_title($id)."\n";
1703
- $systemInfoContent .= 'Type: '.$popup->getOptionValue('sgpb-type')."\n";
1704
- $systemInfoContent .= 'Status: '.$popupStatus."\n";
1705
- $systemInfoContent .= "\n";
1706
- }
1707
-
1708
- // WordPress active plugins
1709
- $systemInfoContent .= "\n".'-- WordPress Active Plugins'."\n\n";
1710
-
1711
- $plugins = get_plugins();
1712
- $activePlugins = get_option('active_plugins', array());
1713
- foreach ($plugins as $pluginPath => $plugin) {
1714
-
1715
- if (! in_array($pluginPath, $activePlugins)) {
1716
- continue;
1717
- }
1718
-
1719
- $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1720
- }
1721
- // WordPress inactive plugins
1722
- $systemInfoContent .= "\n".'-- WordPress Inactive Plugins'."\n\n";
1723
-
1724
- foreach ($plugins as $pluginPath => $plugin) {
1725
- if (in_array($pluginPath, $activePlugins)) {
1726
- continue;
1727
- }
1728
- $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1729
- }
1730
-
1731
- if (is_multisite()) {
1732
- // WordPress Multisite active plugins
1733
- $systemInfoContent .= "\n".'-- Network Active Plugins'."\n\n";
1734
-
1735
- $plugins = wp_get_active_network_plugins();
1736
- $activePlugins = get_site_option('active_sitewide_plugins', array());
1737
-
1738
- foreach ($plugins as $pluginPath) {
1739
- $plugin_base = plugin_basename($pluginPath);
1740
-
1741
- if (! array_key_exists($plugin_base, $activePlugins)) {
1742
- continue;
1743
- }
1744
-
1745
- $plugin = get_plugin_data($pluginPath);
1746
- $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1747
- }
1748
- }
1749
-
1750
- // Server configuration (really just versioning)
1751
- $systemInfoContent .= "\n".'-- Webserver Configuration'."\n\n";
1752
- $systemInfoContent .= 'PHP Version: '.PHP_VERSION."\n";
1753
- $systemInfoContent .= 'MySQL Version: '.$wpdb->db_version()."\n";
1754
- $systemInfoContent .= 'Webserver Info: '.$_SERVER['SERVER_SOFTWARE']."\n";
1755
-
1756
- // PHP configs... now we're getting to the important stuff
1757
- $systemInfoContent .= "\n".'-- PHP Configuration'."\n\n";
1758
- $systemInfoContent .= 'Memory Limit: '.ini_get('memory_limit')."\n";
1759
- $systemInfoContent .= 'Upload Max Size: '.ini_get('upload_max_filesize')."\n";
1760
- $systemInfoContent .= 'Post Max Size: '.ini_get('post_max_size')."\n";
1761
- $systemInfoContent .= 'Upload Max Filesize: '.ini_get('upload_max_filesize')."\n";
1762
- $systemInfoContent .= 'Time Limit: '.ini_get('max_execution_time')."\n";
1763
- $systemInfoContent .= 'Max Input Vars: '.ini_get('max_input_vars')."\n";
1764
- $systemInfoContent .= 'Display Errors: '.(ini_get('display_errors') ? 'On ('.ini_get('display_errors').')' : 'N/A')."\n";
1765
-
1766
- // PHP extensions and such
1767
- $systemInfoContent .= "\n".'-- PHP Extensions'."\n\n";
1768
- $systemInfoContent .= 'cURL: '.(function_exists('curl_init') ? 'Supported' : 'Not Supported')."\n";
1769
- $systemInfoContent .= 'fsockopen: '.(function_exists('fsockopen') ? 'Supported' : 'Not Supported')."\n";
1770
- $systemInfoContent .= 'SOAP Client: '.(class_exists('SoapClient') ? 'Installed' : 'Not Installed')."\n";
1771
- $systemInfoContent .= 'Suhosin: '.(extension_loaded('suhosin') ? 'Installed' : 'Not Installed')."\n";
1772
-
1773
- // Session stuff
1774
- $systemInfoContent .= "\n".'-- Session Configuration'."\n\n";
1775
- $systemInfoContent .= 'Session: '.(isset($_SESSION ) ? 'Enabled' : 'Disabled')."\n";
1776
-
1777
- // The rest of this is only relevant is session is enabled
1778
- if (isset($_SESSION)) {
1779
- $systemInfoContent .= 'Session Name: '.esc_html( ini_get('session.name'))."\n";
1780
- $systemInfoContent .= 'Cookie Path: '.esc_html( ini_get('session.cookie_path'))."\n";
1781
- $systemInfoContent .= 'Save Path: '.esc_html( ini_get('session.save_path'))."\n";
1782
- $systemInfoContent .= 'Use Cookies: '.(ini_get('session.use_cookies') ? 'On' : 'Off')."\n";
1783
- $systemInfoContent .= 'Use Only Cookies: '.(ini_get('session.use_only_cookies') ? 'On' : 'Off')."\n";
1784
- }
1785
-
1786
- $systemInfoContent = apply_filters('sgpbSystemInformation', $systemInfoContent);
1787
-
1788
- $systemInfoContent .= "\n".'### End System Info ###';
1789
-
1790
- return $systemInfoContent;
1791
- }
1792
-
1793
- public static function getHost()
1794
- {
1795
- if (defined('WPE_APIKEY')) {
1796
- return 'WP Engine';
1797
- }
1798
- else if (defined('PAGELYBIN')) {
1799
- return 'Pagely';
1800
- }
1801
- else if (DB_HOST == 'localhost:/tmp/mysql5.sock') {
1802
- return 'ICDSoft';
1803
- }
1804
- else if (DB_HOST == 'mysqlv5') {
1805
- return 'NetworkSolutions';
1806
- }
1807
- else if (strpos(DB_HOST, 'ipagemysql.com') !== false) {
1808
- return 'iPage';
1809
- }
1810
- else if (strpos(DB_HOST, 'ipowermysql.com') !== false) {
1811
- return 'IPower';
1812
- }
1813
- else if (strpos(DB_HOST, '.gridserver.com') !== false) {
1814
- return 'MediaTemple Grid';
1815
- }
1816
- else if (strpos(DB_HOST, '.pair.com') !== false) {
1817
- return 'pair Networks';
1818
- }
1819
- else if (strpos(DB_HOST, '.stabletransit.com') !== false) {
1820
- return 'Rackspace Cloud';
1821
- }
1822
- else if (strpos(DB_HOST, '.sysfix.eu') !== false) {
1823
- return 'SysFix.eu Power Hosting';
1824
- }
1825
- else if (strpos($_SERVER['SERVER_NAME'], 'Flywheel') !== false) {
1826
- return 'Flywheel';
1827
- }
1828
- else {
1829
- // Adding a general fallback for data gathering
1830
- return 'DBH: '.DB_HOST.', SRV: '.$_SERVER['SERVER_NAME'];
1831
- }
1832
- }
1833
-
1834
- public static function getBrowser()
1835
- {
1836
- $uAgent = 'Unknown';
1837
- if (isset($_SERVER['HTTP_USER_AGENT'])) {
1838
- $uAgent = $_SERVER['HTTP_USER_AGENT'];
1839
- }
1840
- $bname = $platform = $ub = $version = 'Unknown';
1841
- $browserInfoContent = '';
1842
-
1843
- //First get the platform?
1844
- if (preg_match('/linux/i', $uAgent)) {
1845
- $platform = 'Linux';
1846
- }
1847
- else if (preg_match('/macintosh|mac os x/i', $uAgent)) {
1848
- $platform = 'Apple';
1849
- }
1850
- else if (preg_match('/windows|win32/i', $uAgent)) {
1851
- $platform = 'Windows';
1852
- }
1853
-
1854
- if (preg_match('/MSIE/i',$uAgent) && !preg_match('/Opera/i',$uAgent)) {
1855
- $bname = 'Internet Explorer';
1856
- $ub = 'MSIE';
1857
- }
1858
- else if (preg_match('/Firefox/i',$uAgent)) {
1859
- $bname = 'Mozilla Firefox';
1860
- $ub = 'Firefox';
1861
- }
1862
- else if (preg_match('/OPR/i',$uAgent)) {
1863
- $bname = 'Opera';
1864
- $ub = 'Opera';
1865
- }
1866
- else if (preg_match('/Chrome/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1867
- $bname = 'Google Chrome';
1868
- $ub = 'Chrome';
1869
- }
1870
- else if (preg_match('/Safari/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1871
- $bname = 'Apple Safari';
1872
- $ub = 'Safari';
1873
- }
1874
- else if (preg_match('/Netscape/i',$uAgent)) {
1875
- $bname = 'Netscape';
1876
- $ub = 'Netscape';
1877
- }
1878
- else if (preg_match('/Edge/i',$uAgent)) {
1879
- $bname = 'Edge';
1880
- $ub = 'Edge';
1881
- }
1882
- else if (preg_match('/Trident/i',$uAgent)) {
1883
- $bname = 'Internet Explorer';
1884
- $ub = 'MSIE';
1885
- }
1886
-
1887
- // finally get the correct version number
1888
- $known = array('Version', $ub, 'other');
1889
- $pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
1890
- $matches = array();
1891
- preg_match_all($pattern, $uAgent, $matches);
1892
-
1893
- // see how many we have
1894
- $i = count($matches['browser']);
1895
- //we will have two since we are not using 'other' argument yet
1896
- if ($i != 1) {
1897
- //see if version is before or after the name
1898
- if (strripos($uAgent,"Version") < strripos($uAgent,$ub)) {
1899
- $version= $matches['version'][0];
1900
- }
1901
- else {
1902
- $version= $matches['version'][1];
1903
- }
1904
- }
1905
- else {
1906
- $version= $matches['version'][0];
1907
- }
1908
-
1909
- // check if we have a number
1910
- if ($version == null || $version == "") {$version = "?" ;}
1911
-
1912
- $browserInfoContent .= 'Platform: '.$platform."\n";
1913
- $browserInfoContent .= 'Browser Name: '.$bname."\n";
1914
- $browserInfoContent .= 'Browser Version: '.$version."\n";
1915
- $browserInfoContent .= 'User Agent: '.$uAgent."\n";
1916
-
1917
- return $browserInfoContent;
1918
- }
1919
-
1920
- // checking user roles capability to do actions
1921
- public static function userCanAccessTo()
1922
- {
1923
- // if this is not admin side screen we don't need to check roles and capabilities
1924
- if (!is_admin()) {
1925
- return true;
1926
- }
1927
-
1928
- $allow = false;
1929
-
1930
- $savedUserRolesInPopup = self::getPopupPostAllowedUserRoles();
1931
- $currentUserRole = self::getCurrentUserRole();
1932
-
1933
- // we need to check if there are any intersections between saved user roles and current user
1934
- $hasIntersection = array_intersect($currentUserRole, $savedUserRolesInPopup);
1935
- if (!empty($hasIntersection)) {
1936
- $allow = true;
1937
- }
1938
-
1939
- return $allow;
1940
- }
1941
-
1942
- public static function filterUserCapabilitiesForTheUserRoles($hook = 'save')
1943
- {
1944
- global $wp_roles;
1945
-
1946
- $allAvailableWpRoles = $wp_roles->roles;
1947
- $savedUserRoles = get_option('sgpb-user-roles');
1948
- // we need to remove from all roles, either when deactivating the plugin and when there is no saved roles
1949
- if (empty($savedUserRoles) || $hook == 'deactivate') {
1950
- $savedUserRoles = array();
1951
- }
1952
- $rolesToBeRestricted = array();
1953
- // selected user roles, which have access to the PB
1954
- foreach ($allAvailableWpRoles as $allAvailableWpRole) {
1955
- if (isset($allAvailableWpRole['name']) && in_array(lcfirst($allAvailableWpRole['name']), $savedUserRoles)) {
1956
- $indexToUnset = lcfirst($allAvailableWpRole['name']);
1957
- continue;
1958
- }
1959
- $rolesToBeRestricted[] = lcfirst($allAvailableWpRole['name']);
1960
- }
1961
-
1962
- $caps = array(
1963
- 'read_private_sgpb_popups',
1964
- 'edit_sgpb_popup',
1965
- 'edit_sgpb_popups',
1966
- 'edit_others_sgpb_popups',
1967
- 'edit_published_sgpb_popups',
1968
- 'publish_sgpb_popups',
1969
- 'delete_sgpb_popups',
1970
- 'delete_published_posts',
1971
- 'delete_others_sgpb_popups',
1972
- 'delete_private_sgpb_popups',
1973
- 'delete_private_sgpb_popup',
1974
- 'delete_published_sgpb_popups',
1975
- 'sgpb_manage_options',
1976
- 'manage_popup_terms',
1977
- 'manage_popup_categories_terms'
1978
- );
1979
-
1980
- if ($hook == 'activate') {
1981
- $rolesToBeRestricted = $savedUserRoles;
1982
- }
1983
- foreach ($rolesToBeRestricted as $roleToBeRestricted) {
1984
- if ($roleToBeRestricted == 'administrator' || $roleToBeRestricted == 'admin') {
1985
- continue;
1986
- }
1987
- foreach ($caps as $cap) {
1988
- // only for the activation hook we need to add our capabilities back
1989
- if ($hook == 'activate') {
1990
- $wp_roles->add_cap($roleToBeRestricted, $cap);
1991
- }
1992
- else {
1993
- $wp_roles->remove_cap($roleToBeRestricted, $cap);
1994
- }
1995
- }
1996
- }
1997
- }
1998
-
1999
- public static function removeUnnecessaryCodeFromPopups()
2000
- {
2001
- $alreadyClearded = self::getOption('sgpb-unnecessary-scripts-removed-1');
2002
- if ($alreadyClearded) {
2003
- return true;
2004
- }
2005
-
2006
- global $wpdb;
2007
- $getAllDataSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.'posts WHERE post_type = %s', SG_POPUP_POST_TYPE);
2008
- $popupsId = $wpdb->get_results($getAllDataSql, ARRAY_A);
2009
- if (empty($popupsId)) {
2010
- return true;
2011
- }
2012
- foreach ($popupsId as $popupId) {
2013
- if (empty($popupId['id'])) {
2014
- continue;
2015
- }
2016
- $id = $popupId['id'];
2017
- $customScripts = get_post_meta($id, 'sg_popup_scripts', true);
2018
- if (empty($customScripts)) {
2019
- continue;
2020
- }
2021
- if (isset($customScripts['js'])) {
2022
- unset($customScripts['js']);
2023
- update_post_meta($id, 'sg_popup_scripts', $customScripts);
2024
- }
2025
- }
2026
-
2027
- self::updateOption('sgpb-unnecessary-scripts-removed-1', 1);
2028
- }
2029
-
2030
- public static function sendTestNewsletter($newsletterData = array())
2031
- {
2032
- $mailSubject = $newsletterData['newsletterSubject'];
2033
- $fromEmail = $newsletterData['fromEmail'];
2034
- $emailMessage = $newsletterData['messageBody'];
2035
- $blogInfo = get_bloginfo();
2036
- $headers = array(
2037
- 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
2038
- 'MIME-Version: 1.0' ,
2039
- 'Content-type: text/html; charset=UTF-8'
2040
- );
2041
-
2042
- $emails = get_option('admin_email');
2043
- if (!empty($newsletterData['testSendingEmails'])) {
2044
- $emails = $newsletterData['testSendingEmails'];
2045
- $emails = str_replace(' ', '', $emails);
2046
-
2047
- $receiverEmailsArray = array();
2048
- $emails = explode(',', $emails);
2049
- foreach ($emails as $mail) {
2050
- if (is_email($mail)) {
2051
- $receiverEmailsArray[] = $mail;
2052
- }
2053
- }
2054
- $emails = $receiverEmailsArray;
2055
- }
2056
-
2057
- $mailStatus = wp_mail($emails, $mailSubject, $emailMessage, $headers);
2058
-
2059
- wp_die($newsletterData['testSendingStatus']);
2060
- }
2061
-
2062
- // wp uploaded images
2063
- public static function getImageAltTextByUrl($imageUrl = '')
2064
- {
2065
- $imageId = attachment_url_to_postid($imageUrl);
2066
- $altText = get_post_meta($imageId, '_wp_attachment_image_alt', true);
2067
-
2068
- return $altText;
2069
- }
2070
- }
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 .= ' sgpb-full-width-events form-control';
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)
218
+ {
219
+ $str = '';
220
+
221
+ foreach ($elements as $key => $element) {
222
+ $value = '';
223
+ $checked = '';
224
+
225
+ if (isset($element['value'])) {
226
+ $value = $element['value'];
227
+ }
228
+ if ($element['value'] == $selectedInput) {
229
+ $checked = 'checked';
230
+ }
231
+ $attrStr = '';
232
+ if (isset($element['data-attributes'])) {
233
+ foreach ($element['data-attributes'] as $attrKey => $dataValue) {
234
+ $attrStr .= $attrKey.'="'.esc_attr($dataValue).'" ';
235
+ }
236
+ }
237
+
238
+ if ($lineMode) {
239
+ $str .= '<input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>';
240
+ }
241
+ else {
242
+ $str .= '<div class="row form-group">';
243
+ $str .= '<label class="col-md-5 control-label">'.__($element['title'], SG_POPUP_TEXT_DOMAIN).'</label>';
244
+ $str .= '<div class="col-sm-7"><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' autocomplete="off"></div>';
245
+ $str .= '</div>';
246
+ }
247
+ }
248
+
249
+ echo $str;
250
+ }
251
+
252
+ public static function getDateObjFromDate($dueDate, $timezone = 'America/Los_Angeles', $format = 'Y-m-d H:i:s')
253
+ {
254
+ $dateObj = new DateTime($dueDate, new DateTimeZone($timezone));
255
+ $dateObj->format($format);
256
+
257
+ return $dateObj;
258
+ }
259
+
260
+ /**
261
+ * Serialize data
262
+ *
263
+ * @since 1.0.0
264
+ *
265
+ * @param array $data
266
+ *
267
+ * @return string $serializedData
268
+ */
269
+ public static function serializeData($data = array())
270
+ {
271
+ $serializedData = serialize($data);
272
+
273
+ return $serializedData;
274
+ }
275
+
276
+ /**
277
+ * Get correct size to use it safely inside CSS rules
278
+ *
279
+ * @since 1.0.0
280
+ *
281
+ * @param string $dimension
282
+ *
283
+ * @return string $size
284
+ */
285
+ public static function getCSSSafeSize($dimension)
286
+ {
287
+ if (empty($dimension)) {
288
+ return 'inherit';
289
+ }
290
+
291
+ $size = (int)$dimension.'px';
292
+ // If user write dimension in px or % we give that dimension to target otherwise the default value will be px
293
+ if (strpos($dimension, '%') || strpos($dimension, 'px')) {
294
+ $size = $dimension;
295
+ }
296
+
297
+ return $size;
298
+ }
299
+
300
+ public static function deleteSubscriptionPopupSubscribers($popupId)
301
+ {
302
+ global $wpdb;
303
+
304
+ $prepareSql = $wpdb->prepare('DELETE FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE subscriptionType = %s', $popupId);
305
+ $wpdb->query($prepareSql);
306
+ }
307
+
308
+ public static function subscribersRelatedQuery($query = '', $additionalColumn = '')
309
+ {
310
+ global $wpdb;
311
+ $subscribersTablename = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
312
+ $postsTablename = $wpdb->prefix.SGPB_POSTS_TABLE_NAME;
313
+
314
+ if ($query == '') {
315
+ $query = 'SELECT firstName, lastName, email, cDate, '.$additionalColumn.' '.$postsTablename.'.post_title AS subscriptionTitle FROM '.$subscribersTablename.' ';
316
+ }
317
+
318
+ $searchQuery = ' unsubscribed <> 1';
319
+ $filterCriteria = '';
320
+
321
+ $query .= ' LEFT JOIN '.$postsTablename.' ON '.$postsTablename.'.ID='.$subscribersTablename.'.subscriptionType';
322
+
323
+ if (isset($_GET['sgpb-subscription-popup-id']) && !empty($_GET['sgpb-subscription-popup-id'])) {
324
+ $filterCriteria = esc_sql($_GET['sgpb-subscription-popup-id']);
325
+ if ($filterCriteria != 'all') {
326
+ $searchQuery .= " AND (subscriptionType = $filterCriteria)";
327
+ }
328
+ }
329
+ if ($filterCriteria != '' && $filterCriteria != 'all' && isset($_GET['s']) && !empty($_GET['s'])) {
330
+ $searchQuery .= ' AND ';
331
+ }
332
+ if (isset($_GET['s']) && !empty($_GET['s'])) {
333
+ $searchCriteria = esc_sql($_GET['s']);
334
+ $lastPartOfTheQuery = substr($searchQuery, -5);
335
+ if (strpos($lastPartOfTheQuery, 'AND') <= 0) {
336
+ $searchQuery .= ' AND ';
337
+ }
338
+ $searchQuery .= "(firstName LIKE '%$searchCriteria%' or lastName LIKE '%$searchCriteria%' or email LIKE '%$searchCriteria%' or $postsTablename.post_title LIKE '%$searchCriteria%')";
339
+ }
340
+ if (isset($_GET['sgpb-subscribers-date']) && !empty($_GET['sgpb-subscribers-date'])) {
341
+ $filterCriteria = esc_sql($_GET['sgpb-subscribers-date']);
342
+ if ($filterCriteria != 'all') {
343
+ if ($searchQuery != '') {
344
+ $searchQuery .= ' AND ';
345
+ }
346
+ $searchQuery .= " cDate LIKE '$filterCriteria%'";
347
+ }
348
+ }
349
+ if ($searchQuery != '') {
350
+ $query .= " WHERE $searchQuery";
351
+ }
352
+
353
+ return $query;
354
+ }
355
+
356
+ public static function themeRelatedSettings($popupId, $buttonPosition, $theme)
357
+ {
358
+ if ($popupId) {
359
+ if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
360
+ if (!isset($buttonPosition)) {
361
+ $buttonPosition = 'bottomRight';
362
+ }
363
+ }
364
+ else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
365
+ if (!isset($buttonPosition)) {
366
+ $buttonPosition = 'topRight';
367
+ }
368
+ }
369
+ }
370
+ else {
371
+ if (isset($theme)) {
372
+ if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
373
+ $buttonPosition = 'bottomRight';
374
+ }
375
+ else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
376
+ $buttonPosition = 'topRight';
377
+ }
378
+ }
379
+ else {
380
+ /* by default set position for the first theme */
381
+ $buttonPosition = 'bottomRight';
382
+ }
383
+ }
384
+
385
+ return $buttonPosition;
386
+ }
387
+
388
+ /**
389
+ * Create html attrs
390
+ *
391
+ * @since 1.0.0
392
+ *
393
+ * @param array $attrs
394
+ *
395
+ * @return string $attrStr
396
+ */
397
+ public static function createAttrs($attrs)
398
+ {
399
+ $attrStr = '';
400
+
401
+ if (empty($attrs)) {
402
+ return $attrStr;
403
+ }
404
+
405
+ foreach ($attrs as $attrKey => $attrValue) {
406
+ $attrStr .= $attrKey.'="'.$attrValue.'" ';
407
+ }
408
+
409
+ return $attrStr;
410
+ }
411
+
412
+ public static function getFormattedDate($date)
413
+ {
414
+ $date = strtotime($date);
415
+ $month = date('F', $date);
416
+ $year = date('Y', $date);
417
+
418
+ return $month.' '.$year;
419
+ }
420
+
421
+ public static function defaultButtonImage($theme, $closeImage = '')
422
+ {
423
+ $currentPostType = self::getCurrentPopupType();
424
+ if (defined('SGPB_POPUP_TYPE_RECENT_SALES') && $currentPostType == SGPB_POPUP_TYPE_RECENT_SALES) {
425
+ $theme = 'sgpb-theme-6';
426
+ }
427
+ // if no image, set default by theme
428
+ if ($closeImage == '') {
429
+ if ($theme == 'sgpb-theme-1' || !$theme) {
430
+ $closeImage = SG_POPUP_IMG_URL.'theme_1/close.png';
431
+ }
432
+ else if ($theme == 'sgpb-theme-2') {
433
+ $closeImage = SG_POPUP_IMG_URL.'theme_2/close.png';
434
+ }
435
+ else if ($theme == 'sgpb-theme-3') {
436
+ $closeImage = SG_POPUP_IMG_URL.'theme_3/close.png';
437
+ }
438
+ else if ($theme == 'sgpb-theme-5') {
439
+ $closeImage = SG_POPUP_IMG_URL.'theme_5/close.png';
440
+ }
441
+ else if ($theme == 'sgpb-theme-6') {
442
+ $closeImage = SG_POPUP_IMG_URL.'theme_6/close.png';
443
+ }
444
+ }
445
+ else {
446
+ $closeImage = self::getImageDataFromUrl($closeImage);
447
+ }
448
+
449
+ return $closeImage;
450
+ }
451
+
452
+ public static function getPopupPostAllowedUserRoles()
453
+ {
454
+ $userSavedRoles = get_option('sgpb-user-roles');
455
+
456
+ if (empty($userSavedRoles) || !is_array($userSavedRoles)) {
457
+ $userSavedRoles = array('administrator');
458
+ }
459
+ else {
460
+ array_push($userSavedRoles, 'administrator');
461
+ }
462
+
463
+ return $userSavedRoles;
464
+ }
465
+
466
+ public static function showMenuForCurrentUser()
467
+ {
468
+ return self::userCanAccessTo();
469
+ }
470
+
471
+ public static function getPopupsIdAndTitle($excludesPopups = array())
472
+ {
473
+ $allPopups = SGPopup::getAllPopups();
474
+ $popupIdTitles = array();
475
+
476
+ if (empty($allPopups)) {
477
+ return $popupIdTitles;
478
+ }
479
+
480
+ foreach ($allPopups as $popup) {
481
+ if (empty($popup)) {
482
+ continue;
483
+ }
484
+
485
+ $id = $popup->getId();
486
+ $title = $popup->getTitle();
487
+ $type = $popup->getType();
488
+
489
+ if (!empty($excludesPopups)) {
490
+ foreach ($excludesPopups as $excludesPopupId) {
491
+ if ($excludesPopupId != $id) {
492
+ $popupIdTitles[$id] = $title.' - '.$type;
493
+ }
494
+ }
495
+ }
496
+ else {
497
+ $popupIdTitles[$id] = $title.' - '.$type;
498
+ }
499
+ }
500
+
501
+ return $popupIdTitles;
502
+ }
503
+
504
+ /**
505
+ * Merge two array and merge same key values to same array
506
+ *
507
+ * @since 1.0.0
508
+ *
509
+ * @param array $array1
510
+ * @param array $array2
511
+ *
512
+ * @return array|bool
513
+ *
514
+ */
515
+ public static function arrayMergeSameKeys($array1, $array2)
516
+ {
517
+ if (empty($array1)) {
518
+ return array();
519
+ }
520
+
521
+ $modified = false;
522
+ $array3 = array();
523
+ foreach ($array1 as $key => $value) {
524
+ if (isset($array2[$key]) && is_array($array2[$key])) {
525
+ $arrDifference = array_diff($array2[$key], $array1[$key]);
526
+ if (empty($arrDifference)) {
527
+ continue;
528
+ }
529
+
530
+ $modified = true;
531
+ $array3[$key] = array_merge($array2[$key], $array1[$key]);
532
+ unset($array2[$key]);
533
+ continue;
534
+ }
535
+
536
+ $modified = true;
537
+ $array3[$key] = $value;
538
+ }
539
+
540
+ // when there are no values
541
+ if (!$modified) {
542
+ return $modified;
543
+ }
544
+
545
+ return $array2 + $array3;
546
+ }
547
+
548
+ public static function getCurrentUserRole()
549
+ {
550
+ $role = array('administrator');
551
+
552
+ if (is_multisite()) {
553
+
554
+ $getUsersObj = get_users(
555
+ array(
556
+ 'blog_id' => get_current_blog_id(),
557
+ 'search' => get_current_user_id()
558
+ )
559
+ );
560
+
561
+ if (!empty($getUsersObj[0])) {
562
+ $roles = $getUsersObj[0]->roles;
563
+
564
+ if (is_array($roles) && !empty($roles)) {
565
+ $role = array_merge($role, $getUsersObj[0]->roles);
566
+ }
567
+ }
568
+
569
+ return $role;
570
+ }
571
+
572
+ global $currentUser;
573
+ if (!empty($currentUser)) {
574
+ $userRoleName = $currentUser->roles;
575
+ $role = $userRoleName;
576
+ }
577
+ else {
578
+ global $current_user;
579
+ if ($current_user) {
580
+ $currentUser = wp_get_current_user();
581
+ $role = $currentUser->roles;
582
+ }
583
+ }
584
+
585
+ return $role;
586
+ }
587
+
588
+ public static function hexToRgba($color, $opacity = false)
589
+ {
590
+ $default = 'rgb(0,0,0)';
591
+
592
+ //Return default if no color provided
593
+ if (empty($color)) {
594
+ return $default;
595
+ }
596
+
597
+ //Sanitize $color if "#" is provided
598
+ if ($color[0] == '#') {
599
+ $color = substr($color, 1);
600
+ }
601
+
602
+ //Check if color has 6 or 3 characters and get values
603
+ if (strlen($color) == 6) {
604
+ $hex = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);
605
+ }
606
+ else if (strlen($color) == 3) {
607
+ $hex = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
608
+ }
609
+ else {
610
+ return $default;
611
+ }
612
+
613
+ //Convert hexadec to rgb
614
+ $rgb = array_map('hexdec', $hex);
615
+
616
+ //Check if opacity is set(rgba or rgb)
617
+ if ($opacity !== false) {
618
+ if (abs($opacity) > 1) {
619
+ $opacity = 1.0;
620
+ }
621
+ $output = 'rgba('.implode(',', $rgb).','.$opacity.')';
622
+ }
623
+ else {
624
+ $output = 'rgb('.implode(',', $rgb).')';
625
+ }
626
+
627
+ //Return rgb(a) color string
628
+ return $output;
629
+ }
630
+
631
+ public static function getAllActiveExtensions()
632
+ {
633
+ $extensions = SgpbDataConfig::getOldExtensionsInfo();
634
+ $labels = array();
635
+
636
+ foreach ($extensions as $extension) {
637
+ if (file_exists(WP_PLUGIN_DIR.'/'.$extension['folderName'])) {
638
+ $labels[] = $extension['label'];
639
+ }
640
+ }
641
+
642
+ return $labels;
643
+ }
644
+
645
+ public static function renderExtensionsContent()
646
+ {
647
+ $extensions = self::getAllActiveExtensions();
648
+ ob_start();
649
+ ?>
650
+ <p class="sgpb-extension-notice-close">x</p>
651
+ <div class="sgpb-extensions-list-wrapper">
652
+ <div class="sgpb-notice-header">
653
+ <h3><?php _e('Popup Builder plugin has been successfully updated', SG_POPUP_TEXT_DOMAIN); ?></h3>
654
+ <h4><?php _e('The following extensions need to be updated manually', SG_POPUP_TEXT_DOMAIN); ?></h4>
655
+ </div>
656
+ <ul class="sgpb-extensions-list">
657
+ <?php foreach ($extensions as $extensionName): ?>
658
+ <a target="_blank" href="https://popup-builder.com/forms/control-panel/"><li><?php echo $extensionName; ?></li></a>
659
+ <?php endforeach; ?>
660
+ </ul>
661
+ </div>
662
+ <p class="sgpb-extension-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN)?></p>
663
+ <?php
664
+ $content = ob_get_contents();
665
+ ob_get_clean();
666
+
667
+ return $content;
668
+ }
669
+
670
+ public static function getReverseConvertIds()
671
+ {
672
+ $idsMappingSaved = get_option('sgpbConvertedIds');
673
+ $ids = array();
674
+
675
+ if ($idsMappingSaved) {
676
+ $ids = $idsMappingSaved;
677
+ }
678
+
679
+ return array_flip($ids);
680
+ }
681
+
682
+ public static function getAllFreeExtensions()
683
+ {
684
+ $allExtensions = SgpbDataConfig::allFreeExtensionsKeys();
685
+
686
+ $notActiveExtensions = array();
687
+ $activeExtensions = array();
688
+
689
+ foreach ($allExtensions as $extension) {
690
+ if (!is_plugin_active($extension['pluginKey'])) {
691
+ $notActiveExtensions[] = $extension;
692
+ }
693
+ else {
694
+ $activeExtensions[] = $extension;
695
+ }
696
+ }
697
+
698
+ $divideExtension = array(
699
+ 'noActive' => $notActiveExtensions,
700
+ 'active' => $activeExtensions
701
+ );
702
+
703
+ return $divideExtension;
704
+ }
705
+
706
+ public static function getAllExtensions()
707
+ {
708
+ $allExtensions = SgpbDataConfig::allExtensionsKeys();
709
+
710
+ $notActiveExtensions = array();
711
+ $activeExtensions = array();
712
+
713
+ foreach ($allExtensions as $extension) {
714
+ if (!is_plugin_active($extension['pluginKey'])) {
715
+ $notActiveExtensions[] = $extension;
716
+ }
717
+ else {
718
+ $activeExtensions[] = $extension;
719
+ }
720
+ }
721
+
722
+ $divideExtension = array(
723
+ 'noActive' => $notActiveExtensions,
724
+ 'active' => $activeExtensions
725
+ );
726
+
727
+ return $divideExtension;
728
+ }
729
+
730
+ public static function renderAlertProblem()
731
+ {
732
+ ob_start();
733
+ ?>
734
+ <div id="welcome-panel" class="update-nag sgpb-alert-problem">
735
+ <div class="welcome-panel-content">
736
+ <p class="sgpb-problem-notice-close">x</p>
737
+ <div class="sgpb-alert-problem-text-wrapper">
738
+ <h3><?php _e('Popup Builder plugin has been updated to the new version 3.', SG_POPUP_TEXT_DOMAIN); ?></h3>
739
+ <h5><?php _e('A lot of changes and improvements have been made.', SG_POPUP_TEXT_DOMAIN); ?></h5>
740
+ <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>
741
+ </div>
742
+ <p class="sgpb-problem-notice-dont-show"><?php _e('Don\'t show again', SG_POPUP_TEXT_DOMAIN); ?></p>
743
+ </div>
744
+ </div>
745
+ <?php
746
+ $content = ob_get_clean();
747
+
748
+ return $content;
749
+ }
750
+
751
+ public static function getTaxonomyBySlug($slug = '')
752
+ {
753
+ $allTerms = get_terms(array('hide_empty' => false));
754
+
755
+ $result = array();
756
+ if (empty($allTerms)) {
757
+ return $result;
758
+ }
759
+ if ($slug == '') {
760
+ return $allTerms;
761
+ }
762
+ foreach ($allTerms as $term) {
763
+ if ($term->slug == $slug) {
764
+ return $term;
765
+ }
766
+ }
767
+ }
768
+
769
+ public static function getCurrentPopupType()
770
+ {
771
+ $type = '';
772
+ if (!empty($_GET['sgpb_type'])) {
773
+ $type = $_GET['sgpb_type'];
774
+ }
775
+
776
+ $currentPostType = self::getCurrentPostType();
777
+
778
+ if ($currentPostType == SG_POPUP_POST_TYPE && !empty($_GET['post'])) {
779
+ $popupObj = SGPopup::find($_GET['post']);
780
+ if (is_object($popupObj)) {
781
+ $type = $popupObj->getType();
782
+ }
783
+ }
784
+
785
+ return $type;
786
+ }
787
+
788
+ public static function getCurrentPostType()
789
+ {
790
+ global $post_type;
791
+ global $post;
792
+ $currentPostType = '';
793
+
794
+ if (is_object($post)) {
795
+ $currentPostType = $post->post_type;
796
+ }
797
+
798
+ // in some themes global $post returns null
799
+ if (empty($currentPostType)) {
800
+ $currentPostType = $post_type;
801
+ }
802
+
803
+ if (empty($currentPostType) && !empty($_GET['post'])) {
804
+ $currentPostType = get_post_type($_GET['post']);
805
+ }
806
+
807
+ return $currentPostType;
808
+ }
809
+
810
+ /**
811
+ * Get image encoded data from URL
812
+ *
813
+ * @param $imageUrl
814
+ * @param $shouldNotConvertBase64
815
+ *
816
+ * @return string
817
+ */
818
+
819
+ public static function getImageDataFromUrl($imageUrl, $shouldNotConvertBase64 = false)
820
+ {
821
+ $remoteData = wp_remote_get($imageUrl);
822
+ if (is_wp_error($remoteData) && $shouldNotConvertBase64) {
823
+ return SG_POPUP_IMG_URL.'NoImage.png';
824
+ }
825
+
826
+ if (!$shouldNotConvertBase64) {
827
+ $imageData = wp_remote_retrieve_body($remoteData);
828
+ $imageUrl = base64_encode($imageData);
829
+ }
830
+
831
+ return $imageUrl;
832
+ }
833
+
834
+ public static function deleteUserFromSubscribers($params = array())
835
+ {
836
+ global $wpdb;
837
+
838
+ $email = '';
839
+ $popup = '';
840
+ $noSubscriber = true;
841
+
842
+ if (isset($params['email'])) {
843
+ $email = $params['email'];
844
+ }
845
+ if (isset($params['popup'])) {
846
+ $popup = $params['popup'];
847
+ }
848
+
849
+ $prepareSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s && subscriptionType = %s', $email, $popup);
850
+ $res = $wpdb->get_row($prepareSql, ARRAY_A);
851
+ if (!isset($res['id'])) {
852
+ $noSubscriber = false;
853
+ }
854
+ $params['subscriberId'] = $res['id'];
855
+
856
+ $subscriber = self::subscriberExists($params);
857
+ if ($subscriber && $noSubscriber) {
858
+ self::deleteSubscriber($params);
859
+ }
860
+ else if (!$noSubscriber) {
861
+ _e('<span>Oops, something went wrong, please try again or contact the administrator to check more info.</span>', SG_POPUP_TEXT_DOMAIN);
862
+ wp_die();
863
+ }
864
+ }
865
+
866
+ public static function subscriberExists($params = array())
867
+ {
868
+ if (empty($params)) {
869
+ return false;
870
+ }
871
+
872
+ $receivedToken = $params['token'];
873
+ $realToken = md5($params['subscriberId'].$params['email']);
874
+ if ($receivedToken == $realToken) {
875
+ return true;
876
+ }
877
+
878
+ }
879
+
880
+ public static function deleteSubscriber($params = array())
881
+ {
882
+ global $wpdb;
883
+ $homeUrl = get_home_url();
884
+
885
+ if (empty($params)) {
886
+ return false;
887
+ }
888
+ // send email to admin about user unsubscription
889
+ self::sendEmailAboutUnsubscribe($params);
890
+
891
+ $prepareSql = $wpdb->prepare('UPDATE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' SET unsubscribed = 1 WHERE id = %s ', $params['subscriberId']);
892
+ $wpdb->query($prepareSql);
893
+
894
+ _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);
895
+ wp_die();
896
+ }
897
+
898
+ public static function sendEmailAboutUnsubscribe($params = array())
899
+ {
900
+ if (empty($params)) {
901
+ return false;
902
+ }
903
+
904
+ $newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
905
+ $receiverEmail = get_bloginfo('admin_email');
906
+ $userEmail = $params['email'];
907
+ $emailTitle = __('Unsubscription', SG_POPUP_TEXT_DOMAIN);
908
+ $subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
909
+ $subscriptionFormTitle = get_the_title($subscriptionFormId);
910
+
911
+ $message = __('User with '.$userEmail.' email has unsubscribed from '.$subscriptionFormTitle.' mail list', SG_POPUP_TEXT_DOMAIN);
912
+
913
+ $headers = 'MIME-Version: 1.0'."\r\n";
914
+ $headers .= 'From: WordPress Popup Builder'."\r\n";
915
+ $headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
916
+
917
+ wp_mail($receiverEmail, $emailTitle, $message, $headers);
918
+ }
919
+
920
+ public static function addUnsubscribeColumn()
921
+ {
922
+ global $wpdb;
923
+
924
+ $sql = 'ALTER TABLE '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' ADD COLUMN unsubscribed INT NOT NULL DEFAULT 0 ';
925
+ $wpdb->query($sql);
926
+ }
927
+
928
+ public static function isPluginActive($key)
929
+ {
930
+ $allExtensions = SgpbDataConfig::allExtensionsKeys();
931
+ $isActive = false;
932
+ foreach ($allExtensions as $extension) {
933
+ if (isset($extension['key']) && $extension['key'] == $key) {
934
+ if (is_plugin_active($extension['pluginKey'])) {
935
+ $isActive = true;
936
+ return $isActive;
937
+ }
938
+ }
939
+ }
940
+
941
+ return $isActive;
942
+ }
943
+
944
+ public static function supportBannerNotification()
945
+ {
946
+ $content = '<div class="sgpb-support-notification-wrapper sgpb-wrapper"><h4 class="sgpb-support-notification-title">'.__('Need some help?', SG_POPUP_TEXT_DOMAIN).'</h4>';
947
+ $content .= '<h4 class="sgpb-support-notification-title">'.__('Let us know what you think.', SG_POPUP_TEXT_DOMAIN).'</h4>';
948
+ $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>';
949
+ $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>';
950
+ $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>';
951
+ $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>';
952
+ $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>';
953
+ $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>';
954
+
955
+ return $content;
956
+ }
957
+
958
+ public static function getMaxOpenDaysMessage()
959
+ {
960
+ $getUsageDays = self::getPopupUsageDays();
961
+ $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);
962
+ $popupContent = self::getMaxOpenPopupContent($firstHeader, 'days');
963
+
964
+ return $popupContent;
965
+ }
966
+
967
+ public static function getPopupUsageDays()
968
+ {
969
+ $installDate = get_option('SGPBInstallDate');
970
+
971
+ $timeDate = new \DateTime('now');
972
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
973
+ $diff = $timeNow-$installDate;
974
+ $days = floor($diff/(60*60*24));
975
+
976
+ return $days;
977
+ }
978
+
979
+ public static function getMaxOpenPopupContent($firstHeader, $type)
980
+ {
981
+ ob_start();
982
+ ?>
983
+ <style>
984
+ .sgpb-buttons-wrapper .press{
985
+ box-sizing:border-box;
986
+ cursor:pointer;
987
+ display:inline-block;
988
+ font-size:1em;
989
+ margin:0;
990
+ padding:0.5em 0.75em;
991
+ text-decoration:none;
992
+ transition:background 0.15s linear
993
+ }
994
+ .sgpb-buttons-wrapper .press-grey {
995
+ background-color:#9E9E9E;
996
+ border:2px solid #9E9E9E;
997
+ color: #FFF;
998
+ }
999
+ .sgpb-buttons-wrapper .press-lightblue {
1000
+ background-color:#03A9F4;
1001
+ border:2px solid #03A9F4;
1002
+ color: #FFF;
1003
+ }
1004
+ .sgpb-buttons-wrapper {
1005
+ text-align: center;
1006
+ }
1007
+ .sgpb-review-wrapper{
1008
+ text-align: center;
1009
+ padding: 20px;
1010
+ }
1011
+ .sgpb-review-wrapper p {
1012
+ color: black;
1013
+ }
1014
+ .sgpb-review-h1 {
1015
+ font-size: 22px;
1016
+ font-weight: normal;
1017
+ line-height: 1.384;
1018
+ }
1019
+ .sgrb-review-h2{
1020
+ font-size: 20px;
1021
+ font-weight: normal;
1022
+ }
1023
+ :root {
1024
+ --main-bg-color: #1ac6ff;
1025
+ }
1026
+ .sgrb-review-strong{
1027
+ color: var(--main-bg-color);
1028
+ }
1029
+ .sgrb-review-mt20{
1030
+ margin-top: 20px
1031
+ }
1032
+ </style>
1033
+ <div class="sgpb-review-wrapper">
1034
+ <div class="sgpb-review-description">
1035
+ <?php echo $firstHeader; ?>
1036
+ <h2 class="sgrb-review-h2"><?php _e('This is really great for your website score.', SG_POPUP_TEXT_DOMAIN); ?></h2>
1037
+ <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>
1038
+ </div>
1039
+ <div class="sgpb-buttons-wrapper">
1040
+ <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>
1041
+ <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>
1042
+ <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>
1043
+ <div> </div>
1044
+ </div>
1045
+ <?php
1046
+ $popupContent = ob_get_clean();
1047
+
1048
+ return $popupContent;
1049
+ }
1050
+
1051
+ public static function shouldOpenReviewPopupForDays()
1052
+ {
1053
+ $shouldOpen = true;
1054
+ $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1055
+ $periodNextTime = get_option('SGPBOpenNextTime');
1056
+ /*if (!$dontShowAgain) {
1057
+ return true;
1058
+ }
1059
+ else {
1060
+ return false;
1061
+ }*/
1062
+ // When period next time does not exits it means the user is old
1063
+ if (!$periodNextTime) {
1064
+ $usageDays = self::getPopupMainTableCreationDate();
1065
+ update_option('SGPBUsageDays', $usageDays);
1066
+ if (!defined('SGPB_REVIEW_POPUP_PERIOD')) {
1067
+ define('SGPB_REVIEW_POPUP_PERIOD', '500');
1068
+ }
1069
+ // For old users
1070
+ if (defined('SGPB_REVIEW_POPUP_PERIOD') && $usageDays > SGPB_REVIEW_POPUP_PERIOD && !$dontShowAgain) {
1071
+ return $shouldOpen;
1072
+ }
1073
+ $remainingDays = SGPB_REVIEW_POPUP_PERIOD - $usageDays;
1074
+
1075
+ $popupTimeZone = \ConfigDataHelper::getDefaultTimezone();
1076
+ $timeDate = new DateTime('now', new DateTimeZone($popupTimeZone));
1077
+ $timeDate->modify('+'.$remainingDays.' day');
1078
+
1079
+ $timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
1080
+ update_option('SGPBOpenNextTime', $timeNow);
1081
+
1082
+ return false;
1083
+ }
1084
+
1085
+ $currentData = new \DateTime('now');
1086
+ $timeNow = $currentData->format('Y-m-d H:i:s');
1087
+ $timeNow = strtotime($timeNow);
1088
+
1089
+ if ($periodNextTime > $timeNow) {
1090
+ $shouldOpen = false;
1091
+ }
1092
+
1093
+ return $shouldOpen;
1094
+ }
1095
+
1096
+ public static function getPopupMainTableCreationDate()
1097
+ {
1098
+ global $wpdb;
1099
+
1100
+ $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');
1101
+ $results = $wpdb->get_results($query, ARRAY_A);
1102
+ if (empty($results)) {
1103
+ return 0;
1104
+ }
1105
+
1106
+ $createTime = $results[0]['create_time'];
1107
+ $createTime = strtotime($createTime);
1108
+ update_option('SGPBInstallDate', $createTime);
1109
+ $diff = time() - $createTime;
1110
+ $days = floor($diff/(60*60*24));
1111
+
1112
+ return $days;
1113
+ }
1114
+
1115
+ public static function shouldOpenForMaxOpenPopupMessage()
1116
+ {
1117
+ $counterMaxPopup = self::getMaxOpenPopupId();
1118
+
1119
+ if (empty($counterMaxPopup)) {
1120
+ return false;
1121
+ }
1122
+ $dontShowAgain = get_option('SGPBCloseReviewPopup-notification');
1123
+ $maxCountDefine = get_option('SGPBMaxOpenCount');
1124
+
1125
+ if (!$maxCountDefine) {
1126
+ $maxCountDefine = SGPB_ASK_REVIEW_POPUP_COUNT;
1127
+ }
1128
+
1129
+ return $counterMaxPopup['maxCount'] >= $maxCountDefine && !$dontShowAgain;
1130
+ }
1131
+
1132
+ public static function getMaxOpenPopupId()
1133
+ {
1134
+ $popupsCounterData = get_option('SgpbCounter');
1135
+ if (!$popupsCounterData) {
1136
+ return 0;
1137
+ }
1138
+
1139
+ $counters = array_values($popupsCounterData);
1140
+ $maxCount = max($counters);
1141
+ $popupId = array_search($maxCount, $popupsCounterData);
1142
+
1143
+ $maxPopupData = array(
1144
+ 'popupId' => $popupId,
1145
+ 'maxCount' => $maxCount
1146
+ );
1147
+
1148
+ return $maxPopupData;
1149
+ }
1150
+
1151
+ public static function getMaxOpenPopupsMessage()
1152
+ {
1153
+ $counterMaxPopup = self::getMaxOpenPopupId();
1154
+ $maxCountDefine = get_option('SGPBMaxOpenCount');
1155
+ $popupTitle = get_the_title($counterMaxPopup['popupId']);
1156
+
1157
+ if (!empty($counterMaxPopup['maxCount'])) {
1158
+ $maxCountDefine = $counterMaxPopup['maxCount'];
1159
+ }
1160
+
1161
+ $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);
1162
+ $popupContent = self::getMaxOpenPopupContent($firstHeader, 'count');
1163
+
1164
+ return $popupContent;
1165
+ }
1166
+
1167
+ /**
1168
+ * Get email headers
1169
+ *
1170
+ * @since 3.1.0
1171
+ *
1172
+ * @param email $fromEmail
1173
+ * @param array $args
1174
+ *
1175
+ * @return string $headers
1176
+ */
1177
+ public static function getEmailHeader($fromEmail, $args = array())
1178
+ {
1179
+ $contentType = 'text/html';
1180
+ $charset = 'UTF-8';
1181
+ $blogInfo = get_bloginfo();
1182
+
1183
+ if (!empty($args['contentType'])) {
1184
+ $contentType = $args['contentType'];
1185
+ }
1186
+ if (!empty($args['charset'])) {
1187
+ $charset = $args['charset'];
1188
+ }
1189
+
1190
+ $headers = 'MIME-Version: 1.0'."\r\n";
1191
+ $headers .= 'From: "'.$blogInfo.'" <'.$fromEmail.'>'."\r\n";
1192
+ $headers .= 'Content-type: '.$contentType.'; charset='.$charset.''."\r\n"; //set UTF-8
1193
+
1194
+ return $headers;
1195
+ }
1196
+
1197
+ /**
1198
+ * Get file content from URL
1199
+ *
1200
+ * @since 3.1.0
1201
+ *
1202
+ * @param $url
1203
+ *
1204
+ * @return string
1205
+ */
1206
+ public static function getFileFromURL($url)
1207
+ {
1208
+ $data = '';
1209
+ $remoteData = wp_remote_get($url);
1210
+
1211
+ if (is_wp_error($remoteData)) {
1212
+ return $data;
1213
+ }
1214
+
1215
+ $data = wp_remote_retrieve_body($remoteData);
1216
+
1217
+ return $data;
1218
+ }
1219
+
1220
+ public static function getRightMetaboxBannerText()
1221
+ {
1222
+ $bannerText = get_option('sgpb-metabox-banner-remote-get');
1223
+
1224
+ return $bannerText;
1225
+ }
1226
+
1227
+ public static function getGutenbergPopupsIdAndTitle($excludesPopups = array())
1228
+ {
1229
+ $allPopups = SGPopup::getAllPopups();
1230
+ $popupIdTitles = array();
1231
+
1232
+ if (empty($allPopups)) {
1233
+ return $popupIdTitles;
1234
+ }
1235
+
1236
+ foreach ($allPopups as $popup) {
1237
+ if (empty($popup)) {
1238
+ continue;
1239
+ }
1240
+
1241
+ $id = $popup->getId();
1242
+ $title = $popup->getTitle();
1243
+ $type = $popup->getType();
1244
+
1245
+ if (!empty($excludesPopups)) {
1246
+ foreach ($excludesPopups as $excludesPopupId) {
1247
+ if ($excludesPopupId != $id) {
1248
+ $array = array();
1249
+ $array['id'] = $id;
1250
+ $array['title'] = $title.' - '.$type;
1251
+ $popupIdTitles[] = $array;
1252
+ }
1253
+ }
1254
+ }
1255
+ else {
1256
+ $array = array();
1257
+ $array['id'] = $id;
1258
+ $array['title'] = $title.' - '.$type;
1259
+ $popupIdTitles[] = $array;
1260
+ }
1261
+ }
1262
+
1263
+ return $popupIdTitles;
1264
+ }
1265
+
1266
+ public static function getGutenbergPopupsEvents()
1267
+ {
1268
+ $data = array(
1269
+ array('value' => '', 'title' => __('Select Event', SG_POPUP_TEXT_DOMAIN)),
1270
+ array('value' => 'inherit', 'title' => __('Inherit', SG_POPUP_TEXT_DOMAIN)),
1271
+ array('value' => 'onLoad', 'title' => __('On load', SG_POPUP_TEXT_DOMAIN)),
1272
+ array('value' => 'click', 'title' => __('On click', SG_POPUP_TEXT_DOMAIN)),
1273
+ array('value' => 'hover', 'title' => __('On hover', SG_POPUP_TEXT_DOMAIN))
1274
+ );
1275
+
1276
+ return $data;
1277
+ }
1278
+
1279
+ public static function checkEditorByPopupId($popupId)
1280
+ {
1281
+ $popupContent = '';
1282
+ if (class_exists('\Elementor\Plugin')) {
1283
+ $elementorContent = get_post_meta($popupId, '_elementor_edit_mode', true);
1284
+ if (!empty($elementorContent) && $elementorContent == 'builder') {
1285
+ $popupContent = Elementor\Plugin::instance()->frontend->get_builder_content_for_display($popupId);
1286
+ }
1287
+ }
1288
+ else if (class_exists('Vc_Manager')) {
1289
+ $stylesAndScripts = self::renderWPBakeryScriptsAndStyles($popupId);
1290
+ $popupContent .= '<style>'.$stylesAndScripts.'</style>';
1291
+ }
1292
+
1293
+ return $popupContent;
1294
+ }
1295
+
1296
+ public static function renderWPBakeryScriptsAndStyles($popupId = 0)
1297
+ {
1298
+ return get_post_meta($popupId, '_wpb_shortcodes_custom_css', true);
1299
+ }
1300
+
1301
+ /**
1302
+ * countdown popup, convert date to seconds
1303
+ *
1304
+ * @param $dueDate
1305
+ * @param $timezone
1306
+ * @return false|int|string
1307
+ */
1308
+ public static function dateToSeconds($dueDate, $timezone)
1309
+ {
1310
+ if (empty($timezone)) {
1311
+ return '';
1312
+ }
1313
+
1314
+ $dateObj = self::getDateObjFromDate('now', $timezone);
1315
+ $timeNow = @strtotime($dateObj);
1316
+ $seconds = @strtotime($dueDate)-$timeNow;
1317
+ if ($seconds < 0) {
1318
+ $seconds = 0;
1319
+ }
1320
+
1321
+ return $seconds;
1322
+ }
1323
+
1324
+ /**
1325
+ * Get site protocol
1326
+ *
1327
+ * @since 1.0.0
1328
+ *
1329
+ * @return string $protocol
1330
+ *
1331
+ */
1332
+ public static function getSiteProtocol()
1333
+ {
1334
+ $protocol = 'http';
1335
+
1336
+ if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
1337
+ $protocol = 'https';
1338
+ }
1339
+
1340
+ return $protocol;
1341
+ }
1342
+
1343
+ public static function findSubscribersByEmail($subscriberEmail = '', $list = 0)
1344
+ {
1345
+ global $wpdb;
1346
+ $subscriber = array();
1347
+
1348
+ $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s AND subscriptionType = %d ', $subscriberEmail, $list);
1349
+ $subscriber = $wpdb->get_row($prepareSql, ARRAY_A);
1350
+ if (!$list) {
1351
+ $prepareSql = $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE email = %s ', $subscriberEmail);
1352
+ $subscriber = $wpdb->get_results($prepareSql, ARRAY_A);
1353
+ }
1354
+
1355
+ return $subscriber;
1356
+ }
1357
+
1358
+ /**
1359
+ * Update option
1360
+ *
1361
+ * @since 3.1.9
1362
+ *
1363
+ * @return void
1364
+ */
1365
+ public static function updateOption($optionKey, $optionValue)
1366
+ {
1367
+ update_option($optionKey, $optionValue);
1368
+ }
1369
+
1370
+ public static function getOption($optionKey, $default = false)
1371
+ {
1372
+ return get_option($optionKey, $default);
1373
+ }
1374
+
1375
+ public static function deleteOption($optionKey)
1376
+ {
1377
+ delete_option($optionKey);
1378
+ }
1379
+
1380
+ /**
1381
+ * It's change popup registered plugins static paths to dynamic
1382
+ *
1383
+ * @since 3.1.9
1384
+ *
1385
+ * @return bool where true mean modified false mean there is not need modification
1386
+ */
1387
+ public static function makeRegisteredPluginsStaticPathsToDynamic()
1388
+ {
1389
+ // remove old outdated option sgpbModifiedRegisteredPluginsPaths
1390
+ delete_option('sgpbModifiedRegisteredPluginsPaths');
1391
+ delete_option('SG_POPUP_BUILDER_REGISTERED_PLUGINS');
1392
+ $hasModifiedPaths = AdminHelper::getOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED);
1393
+ if ($hasModifiedPaths) {
1394
+ return false;
1395
+ }
1396
+ else {
1397
+ Installer::registerPlugin();
1398
+ }
1399
+ AdminHelper::updateOption(SGPB_REGISTERED_PLUGINS_PATHS_MODIFIED, 1);
1400
+
1401
+ $registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1402
+ if (empty($registeredPlugins)) {
1403
+ return false;
1404
+ }
1405
+
1406
+ $registeredPlugins = json_decode($registeredPlugins, true);
1407
+ if (empty($registeredPlugins)) {
1408
+ return false;
1409
+ }
1410
+
1411
+ foreach ($registeredPlugins as $key => $registeredPlugin) {
1412
+ if (empty($registeredPlugin['classPath'])) {
1413
+ continue;
1414
+ }
1415
+ $registeredPlugins[$key]['classPath'] = str_replace(WP_PLUGIN_DIR, '', $registeredPlugin['classPath']);
1416
+ if (!empty($registeredPlugin['options']['licence']['file'])) {
1417
+ $registeredPlugins[$key]['options']['licence']['file'] = $registeredPlugin['options']['licence']['file'];
1418
+ }
1419
+ }
1420
+ $registeredPlugins = json_encode($registeredPlugins);
1421
+
1422
+ AdminHelper::updateOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS, $registeredPlugins);
1423
+ return true;
1424
+ }
1425
+
1426
+ public static function hasInactiveExtensions()
1427
+ {
1428
+ $hasInactiveExtensions = false;
1429
+ $allRegiseredPBPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1430
+ $allRegiseredPBPlugins = @json_decode($allRegiseredPBPlugins, true);
1431
+ if (empty($allRegiseredPBPlugins)) {
1432
+ return $hasInactiveExtensions;
1433
+ }
1434
+
1435
+ foreach ($allRegiseredPBPlugins as $pluginPath => $registeredPlugin) {
1436
+ if (!isset($registeredPlugin['options']['licence']['key'])) {
1437
+ continue;
1438
+ }
1439
+ if (!isset($registeredPlugin['options']['licence']['file'])) {
1440
+ continue;
1441
+ }
1442
+ $extensionKey = $registeredPlugin['options']['licence']['file'];
1443
+ $isPluginActive = is_plugin_active($extensionKey);
1444
+ $pluginKey = $registeredPlugin['options']['licence']['key'];
1445
+ $isValidLicense = get_option('sgpb-license-status-'.$pluginKey);
1446
+
1447
+ // if we even have at least one inactive extension, we don't need to check remaining extensions
1448
+ if ($isValidLicense != 'valid' && $isPluginActive) {
1449
+ $hasInactiveExtensions = true;
1450
+ break;
1451
+ }
1452
+ }
1453
+
1454
+ return $hasInactiveExtensions;
1455
+ }
1456
+
1457
+ public static function getSubscriptionColumnsById($id)
1458
+ {
1459
+ $popup = SGPopup::find($id);
1460
+ if (empty($popup) || !is_object($popup)) {
1461
+ return array();
1462
+ }
1463
+ $freeSavedOptions = $popup->getOptionValue('sgpb-subs-fields');
1464
+
1465
+ if (!empty($freeSavedOptions)) {
1466
+ return array('firstName' => 'First name','lastName' => 'Last name', 'email' => 'Email', 'date' => 'Date');
1467
+ }
1468
+ $formFieldsJson = $popup->getOptionValue('sgpb-subscription-fields-json');
1469
+ if (!empty($formFieldsJson)) {
1470
+ $data = apply_filters('sgpbGetSubscriptionLabels', array(), $popup);
1471
+ $data['date'] = 'Date';
1472
+ return $data;
1473
+ }
1474
+
1475
+ return array();
1476
+ }
1477
+
1478
+ public static function getCustomFormFieldsByPopupId($popupId)
1479
+ {
1480
+ if (!class_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper')) {
1481
+ return array();
1482
+ }
1483
+
1484
+ if (method_exists('sgpbsubscriptionplus\SubscriptionPlusAdminHelper', 'getCustomFormFieldsByPopupId')) {
1485
+ return SubscriptionPlusAdminHelper::getCustomFormFieldsByPopupId($popupId);
1486
+ }
1487
+
1488
+ return array();
1489
+ }
1490
+
1491
+ public static function removeAllNonPrintableCharacters($title, $defaultValue)
1492
+ {
1493
+ $titleRes = $title;
1494
+ $pattern = '/[\\\^£$%&*()}{@#~?><>,|=_+¬-]/u';
1495
+ $title = preg_replace($pattern, '', $title);
1496
+ $title = mb_ereg_replace($pattern, '', $title);
1497
+ $title = htmlspecialchars($title, ENT_IGNORE, 'UTF-8');
1498
+ $result = str_replace(' ', '', $title);
1499
+ if (empty($result)) {
1500
+ $titleRes = $defaultValue;
1501
+ }
1502
+
1503
+ return $titleRes;
1504
+ }
1505
+
1506
+ public static function renderCustomScripts($popupId)
1507
+ {
1508
+ $finalResult = '';
1509
+ $postMeta = get_post_meta($popupId, 'sg_popup_scripts', true);
1510
+ if (empty($postMeta)) {
1511
+ return '';
1512
+ }
1513
+ $defaultData = \ConfigDataHelper::defaultData();
1514
+
1515
+ // get scripts
1516
+ if (!isset($postMeta['js'])) {
1517
+ $postMeta['js'] = array();
1518
+ }
1519
+ $jsPostMeta = $postMeta['js'];
1520
+ $jsDefaultData = $defaultData['customEditorContent']['js']['helperText'];
1521
+ $suspiciousStrings = array('document.createElement', 'createElement', 'String.fromCharCode', 'fromCharCode', '<!--', '-->');
1522
+ $finalContent = '';
1523
+ $suspiciousStringFound = false;
1524
+ if (!empty($jsPostMeta)) {
1525
+ $customScripts = '<script id="sgpb-custom-script-'.$popupId.'">';
1526
+ foreach ($jsDefaultData as $key => $value) {
1527
+ $eventName = 'sgpb'.$key;
1528
+ if ((!isset($jsPostMeta['sgpb-'.$key]) || empty($jsPostMeta['sgpb-'.$key])) || $key == 'ShouldOpen' || $key == 'ShouldClose') {
1529
+ continue;
1530
+ }
1531
+ $content = @$jsPostMeta['sgpb-'.$key];
1532
+ $content = str_replace('popupId', $popupId, $content);
1533
+ $content = str_replace("<", "&lt;", $content);
1534
+ $content = str_replace(">", "&gt;", $content);
1535
+ foreach ($suspiciousStrings as $string) {
1536
+ if (strpos($content, $string)) {
1537
+ $suspiciousStringFound = true;
1538
+ break;
1539
+ }
1540
+ }
1541
+ if ($suspiciousStringFound) {
1542
+ break;
1543
+ }
1544
+ $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
1545
+
1546
+ $finalContent .= 'jQuery(document).ready(function(){';
1547
+ $finalContent .= 'sgAddEvent(window, "'.$eventName.'", function(e) {';
1548
+ $finalContent .= 'if (e.detail.popupId == "'.$popupId.'") {';
1549
+ $finalContent .= $content;
1550
+ $finalContent .= '};';
1551
+ $finalContent .= '});';
1552
+ $finalContent .= '});';
1553
+ }
1554
+ $customScripts .= $finalContent;
1555
+ $customScripts .= '</script>';
1556
+ if (empty($finalContent)) {
1557
+ $customScripts = '';
1558
+ }
1559
+ $finalResult .= $customScripts;
1560
+ }
1561
+
1562
+ // get styles
1563
+ if (isset($postMeta['css'])) {
1564
+ $cssPostMeta = $postMeta['css'];
1565
+ }
1566
+ $finalContent = '';
1567
+ if (!empty($cssPostMeta)) {
1568
+ $customStyles = '<style id="sgpb-custom-style-'.$popupId.'">';
1569
+ $finalContent = str_replace('popupId', $popupId, $cssPostMeta);
1570
+ $finalContent = html_entity_decode($finalContent, ENT_QUOTES, 'UTF-8');
1571
+
1572
+ $customStyles .= $finalContent;
1573
+ $customStyles .= '</style>';
1574
+ $finalResult .= $customStyles;
1575
+ }
1576
+
1577
+
1578
+ return $finalResult;
1579
+ }
1580
+
1581
+ public static function removeSelectedTypeOptions($type)
1582
+ {
1583
+ switch ($type) {
1584
+ case 'cron':
1585
+ $crons = _get_cron_array();
1586
+ foreach ($crons as $key => $value) {
1587
+ foreach ($value as $key => $body) {
1588
+ if (strstr($key, 'sgpb')) {
1589
+ wp_clear_scheduled_hook($key);
1590
+ }
1591
+ }
1592
+ }
1593
+ break;
1594
+ }
1595
+ }
1596
+
1597
+ public static function getSystemInfoText() {
1598
+ global $wpdb;
1599
+
1600
+ $browser = self::getBrowser();
1601
+
1602
+ // Get theme info
1603
+ if (get_bloginfo('version') < '3.4') {
1604
+ $themeData = wp_get_theme(get_stylesheet_directory().'/style.css');
1605
+ $theme = $themeData['Name'].' '.$themeData['Version'];
1606
+ }
1607
+ else {
1608
+ $themeData = wp_get_theme();
1609
+ $theme = $themeData->Name.' '.$themeData->Version;
1610
+ }
1611
+
1612
+ // Try to identify the hosting provider
1613
+ $host = self::getHost();
1614
+
1615
+ $systemInfoContent = '### Start System Info ###'."\n\n";
1616
+
1617
+ // Start with the basics...
1618
+ $systemInfoContent .= '-- Site Info'."\n\n";
1619
+ $systemInfoContent .= 'Site URL: '.site_url()."\n";
1620
+ $systemInfoContent .= 'Home URL: '.home_url()."\n";
1621
+ $systemInfoContent .= 'Multisite: '.(is_multisite() ? 'Yes' : 'No')."\n";
1622
+
1623
+ // Can we determine the site's host?
1624
+ if ($host) {
1625
+ $systemInfoContent .= "\n".'-- Hosting Provider'."\n\n";
1626
+ $systemInfoContent .= 'Host: '.$host."\n";
1627
+ }
1628
+
1629
+ // The local users' browser information, handled by the Browser class
1630
+ $systemInfoContent .= "\n".'-- User Browser'."\n\n";
1631
+ $systemInfoContent .= $browser;
1632
+
1633
+ // WordPress configuration
1634
+ $systemInfoContent .= "\n".'-- WordPress Configuration'."\n\n";
1635
+ $systemInfoContent .= 'Version: '.get_bloginfo('version')."\n";
1636
+ $systemInfoContent .= 'Language: '.(defined('WPLANG') && WPLANG ? WPLANG : 'en_US')."\n";
1637
+ $systemInfoContent .= 'Permalink Structure: '.(get_option('permalink_structure') ? get_option('permalink_structure') : 'Default')."\n";
1638
+ $systemInfoContent .= 'Active Theme: '.$theme."\n";
1639
+ $systemInfoContent .= 'Show On Front: '.get_option('show_on_front')."\n";
1640
+
1641
+ // Only show page specs if frontpage is set to 'page'
1642
+ if (get_option('show_on_front') == 'page') {
1643
+ $frontPageId = get_option('page_on_front');
1644
+ $blogPageId = get_option('page_for_posts');
1645
+
1646
+ $systemInfoContent .= 'Page On Front: '.($frontPageId != 0 ? get_the_title($frontPageId).' (#'.$frontPageId.')' : 'Unset')."\n";
1647
+ $systemInfoContent .= 'Page For Posts: '.($blogPageId != 0 ? get_the_title($blogPageId).' (#'.$blogPageId.')' : 'Unset')."\n";
1648
+ }
1649
+
1650
+ $systemInfoContent .= 'Table Prefix: '.'Prefix: '.$wpdb->prefix.' Length: '.strlen($wpdb->prefix ).' Status: '.( strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable')."\n";
1651
+ $systemInfoContent .= 'WP_DEBUG: '.(defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set')."\n";
1652
+ $systemInfoContent .= 'Memory Limit: '.WP_MEMORY_LIMIT."\n";
1653
+ $systemInfoContent .= 'Registered Post Stati: '.implode(', ', get_post_stati())."\n";
1654
+
1655
+ // Must-use plugins
1656
+ $muplugins = get_mu_plugins();
1657
+ if ($muplugins && count($muplugins)) {
1658
+ $systemInfoContent .= "\n".'-- Must-Use Plugins'."\n\n";
1659
+
1660
+ foreach ($muplugins as $plugin => $plugin_data) {
1661
+ $systemInfoContent .= $plugin_data['Name'].': '.$plugin_data['Version']."\n";
1662
+ }
1663
+ }
1664
+
1665
+ $registered = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
1666
+ $registered = json_decode($registered, true);
1667
+
1668
+ if (empty($registered)) {
1669
+ return false;
1670
+ }
1671
+ // remove free package data, we don't need it
1672
+ array_shift($registered);
1673
+
1674
+ $systemInfoContent .= "\n".'-- Popup Builder License Data'."\n\n";
1675
+ if (!empty($registered)) {
1676
+ foreach ($registered as $singleExntensionData) {
1677
+ $key = $singleExntensionData['options']['licence']['key'];
1678
+ $name = $singleExntensionData['options']['licence']['itemName'];
1679
+ $licenseKey = __('No license');
1680
+ if (!empty($key)) {
1681
+ $licenseKey = self::getOption('sgpb-license-key-'.$key);
1682
+ }
1683
+ $licenseStatus = 'Inactive';
1684
+ if (self::getOption('sgpb-license-status-'.$key) == 'valid') {
1685
+ $licenseStatus = 'Active';
1686
+ }
1687
+
1688
+ $systemInfoContent .= 'Name: '.$name."\n";
1689
+ $systemInfoContent .= 'License key: '.$licenseKey."\n";
1690
+ $systemInfoContent .= 'License status: '.$licenseStatus."\n";
1691
+ $systemInfoContent .= "\n";
1692
+ }
1693
+ }
1694
+
1695
+ $systemInfoContent .= "\n".'-- All created Popups'."\n\n";
1696
+ $allPopups = self::getPopupsIdAndTitle();
1697
+ $args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
1698
+ foreach ($allPopups as $id => $popupTitleType) {
1699
+ $popup = SGPopup::find($id, $args);
1700
+ $popupStatus = ($popup->getOptionValue('sgpb-is-active')) ? 'Enabled' : 'Disabled';
1701
+ $systemInfoContent .= 'Id: '.$id."\n";
1702
+ $systemInfoContent .= 'Title: '.get_the_title($id)."\n";
1703
+ $systemInfoContent .= 'Type: '.$popup->getOptionValue('sgpb-type')."\n";
1704
+ $systemInfoContent .= 'Status: '.$popupStatus."\n";
1705
+ $systemInfoContent .= "\n";
1706
+ }
1707
+
1708
+ // WordPress active plugins
1709
+ $systemInfoContent .= "\n".'-- WordPress Active Plugins'."\n\n";
1710
+
1711
+ $plugins = get_plugins();
1712
+ $activePlugins = get_option('active_plugins', array());
1713
+ foreach ($plugins as $pluginPath => $plugin) {
1714
+
1715
+ if (! in_array($pluginPath, $activePlugins)) {
1716
+ continue;
1717
+ }
1718
+
1719
+ $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1720
+ }
1721
+ // WordPress inactive plugins
1722
+ $systemInfoContent .= "\n".'-- WordPress Inactive Plugins'."\n\n";
1723
+
1724
+ foreach ($plugins as $pluginPath => $plugin) {
1725
+ if (in_array($pluginPath, $activePlugins)) {
1726
+ continue;
1727
+ }
1728
+ $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1729
+ }
1730
+
1731
+ if (is_multisite()) {
1732
+ // WordPress Multisite active plugins
1733
+ $systemInfoContent .= "\n".'-- Network Active Plugins'."\n\n";
1734
+
1735
+ $plugins = wp_get_active_network_plugins();
1736
+ $activePlugins = get_site_option('active_sitewide_plugins', array());
1737
+
1738
+ foreach ($plugins as $pluginPath) {
1739
+ $plugin_base = plugin_basename($pluginPath);
1740
+
1741
+ if (! array_key_exists($plugin_base, $activePlugins)) {
1742
+ continue;
1743
+ }
1744
+
1745
+ $plugin = get_plugin_data($pluginPath);
1746
+ $systemInfoContent .= $plugin['Name'].': '.$plugin['Version']."\n";
1747
+ }
1748
+ }
1749
+
1750
+ // Server configuration (really just versioning)
1751
+ $systemInfoContent .= "\n".'-- Webserver Configuration'."\n\n";
1752
+ $systemInfoContent .= 'PHP Version: '.PHP_VERSION."\n";
1753
+ $systemInfoContent .= 'MySQL Version: '.$wpdb->db_version()."\n";
1754
+ $systemInfoContent .= 'Webserver Info: '.$_SERVER['SERVER_SOFTWARE']."\n";
1755
+
1756
+ // PHP configs... now we're getting to the important stuff
1757
+ $systemInfoContent .= "\n".'-- PHP Configuration'."\n\n";
1758
+ $systemInfoContent .= 'Memory Limit: '.ini_get('memory_limit')."\n";
1759
+ $systemInfoContent .= 'Upload Max Size: '.ini_get('upload_max_filesize')."\n";
1760
+ $systemInfoContent .= 'Post Max Size: '.ini_get('post_max_size')."\n";
1761
+ $systemInfoContent .= 'Upload Max Filesize: '.ini_get('upload_max_filesize')."\n";
1762
+ $systemInfoContent .= 'Time Limit: '.ini_get('max_execution_time')."\n";
1763
+ $systemInfoContent .= 'Max Input Vars: '.ini_get('max_input_vars')."\n";
1764
+ $systemInfoContent .= 'Display Errors: '.(ini_get('display_errors') ? 'On ('.ini_get('display_errors').')' : 'N/A')."\n";
1765
+
1766
+ // PHP extensions and such
1767
+ $systemInfoContent .= "\n".'-- PHP Extensions'."\n\n";
1768
+ $systemInfoContent .= 'cURL: '.(function_exists('curl_init') ? 'Supported' : 'Not Supported')."\n";
1769
+ $systemInfoContent .= 'fsockopen: '.(function_exists('fsockopen') ? 'Supported' : 'Not Supported')."\n";
1770
+ $systemInfoContent .= 'SOAP Client: '.(class_exists('SoapClient') ? 'Installed' : 'Not Installed')."\n";
1771
+ $systemInfoContent .= 'Suhosin: '.(extension_loaded('suhosin') ? 'Installed' : 'Not Installed')."\n";
1772
+
1773
+ // Session stuff
1774
+ $systemInfoContent .= "\n".'-- Session Configuration'."\n\n";
1775
+ $systemInfoContent .= 'Session: '.(isset($_SESSION ) ? 'Enabled' : 'Disabled')."\n";
1776
+
1777
+ // The rest of this is only relevant is session is enabled
1778
+ if (isset($_SESSION)) {
1779
+ $systemInfoContent .= 'Session Name: '.esc_html( ini_get('session.name'))."\n";
1780
+ $systemInfoContent .= 'Cookie Path: '.esc_html( ini_get('session.cookie_path'))."\n";
1781
+ $systemInfoContent .= 'Save Path: '.esc_html( ini_get('session.save_path'))."\n";
1782
+ $systemInfoContent .= 'Use Cookies: '.(ini_get('session.use_cookies') ? 'On' : 'Off')."\n";
1783
+ $systemInfoContent .= 'Use Only Cookies: '.(ini_get('session.use_only_cookies') ? 'On' : 'Off')."\n";
1784
+ }
1785
+
1786
+ $systemInfoContent = apply_filters('sgpbSystemInformation', $systemInfoContent);
1787
+
1788
+ $systemInfoContent .= "\n".'### End System Info ###';
1789
+
1790
+ return $systemInfoContent;
1791
+ }
1792
+
1793
+ public static function getHost()
1794
+ {
1795
+ if (defined('WPE_APIKEY')) {
1796
+ return 'WP Engine';
1797
+ }
1798
+ else if (defined('PAGELYBIN')) {
1799
+ return 'Pagely';
1800
+ }
1801
+ else if (DB_HOST == 'localhost:/tmp/mysql5.sock') {
1802
+ return 'ICDSoft';
1803
+ }
1804
+ else if (DB_HOST == 'mysqlv5') {
1805
+ return 'NetworkSolutions';
1806
+ }
1807
+ else if (strpos(DB_HOST, 'ipagemysql.com') !== false) {
1808
+ return 'iPage';
1809
+ }
1810
+ else if (strpos(DB_HOST, 'ipowermysql.com') !== false) {
1811
+ return 'IPower';
1812
+ }
1813
+ else if (strpos(DB_HOST, '.gridserver.com') !== false) {
1814
+ return 'MediaTemple Grid';
1815
+ }
1816
+ else if (strpos(DB_HOST, '.pair.com') !== false) {
1817
+ return 'pair Networks';
1818
+ }
1819
+ else if (strpos(DB_HOST, '.stabletransit.com') !== false) {
1820
+ return 'Rackspace Cloud';
1821
+ }
1822
+ else if (strpos(DB_HOST, '.sysfix.eu') !== false) {
1823
+ return 'SysFix.eu Power Hosting';
1824
+ }
1825
+ else if (strpos($_SERVER['SERVER_NAME'], 'Flywheel') !== false) {
1826
+ return 'Flywheel';
1827
+ }
1828
+ else {
1829
+ // Adding a general fallback for data gathering
1830
+ return 'DBH: '.DB_HOST.', SRV: '.$_SERVER['SERVER_NAME'];
1831
+ }
1832
+ }
1833
+
1834
+ public static function getBrowser()
1835
+ {
1836
+ $uAgent = 'Unknown';
1837
+ if (isset($_SERVER['HTTP_USER_AGENT'])) {
1838
+ $uAgent = $_SERVER['HTTP_USER_AGENT'];
1839
+ }
1840
+ $bname = $platform = $ub = $version = 'Unknown';
1841
+ $browserInfoContent = '';
1842
+
1843
+ //First get the platform?
1844
+ if (preg_match('/linux/i', $uAgent)) {
1845
+ $platform = 'Linux';
1846
+ }
1847
+ else if (preg_match('/macintosh|mac os x/i', $uAgent)) {
1848
+ $platform = 'Apple';
1849
+ }
1850
+ else if (preg_match('/windows|win32/i', $uAgent)) {
1851
+ $platform = 'Windows';
1852
+ }
1853
+
1854
+ if (preg_match('/MSIE/i',$uAgent) && !preg_match('/Opera/i',$uAgent)) {
1855
+ $bname = 'Internet Explorer';
1856
+ $ub = 'MSIE';
1857
+ }
1858
+ else if (preg_match('/Firefox/i',$uAgent)) {
1859
+ $bname = 'Mozilla Firefox';
1860
+ $ub = 'Firefox';
1861
+ }
1862
+ else if (preg_match('/OPR/i',$uAgent)) {
1863
+ $bname = 'Opera';
1864
+ $ub = 'Opera';
1865
+ }
1866
+ else if (preg_match('/Chrome/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1867
+ $bname = 'Google Chrome';
1868
+ $ub = 'Chrome';
1869
+ }
1870
+ else if (preg_match('/Safari/i',$uAgent) && !preg_match('/Edge/i',$uAgent)) {
1871
+ $bname = 'Apple Safari';
1872
+ $ub = 'Safari';
1873
+ }
1874
+ else if (preg_match('/Netscape/i',$uAgent)) {
1875
+ $bname = 'Netscape';
1876
+ $ub = 'Netscape';
1877
+ }
1878
+ else if (preg_match('/Edge/i',$uAgent)) {
1879
+ $bname = 'Edge';
1880
+ $ub = 'Edge';
1881
+ }
1882
+ else if (preg_match('/Trident/i',$uAgent)) {
1883
+ $bname = 'Internet Explorer';
1884
+ $ub = 'MSIE';
1885
+ }
1886
+
1887
+ // finally get the correct version number
1888
+ $known = array('Version', $ub, 'other');
1889
+ $pattern = '#(?<browser>'.implode('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
1890
+ $matches = array();
1891
+ preg_match_all($pattern, $uAgent, $matches);
1892
+
1893
+ // see how many we have
1894
+ $i = count($matches['browser']);
1895
+ //we will have two since we are not using 'other' argument yet
1896
+ if ($i != 1) {
1897
+ //see if version is before or after the name
1898
+ if (strripos($uAgent,"Version") < strripos($uAgent,$ub)) {
1899
+ $version= $matches['version'][0];
1900
+ }
1901
+ else {
1902
+ $version= $matches['version'][1];
1903
+ }
1904
+ }
1905
+ else {
1906
+ $version= $matches['version'][0];
1907
+ }
1908
+
1909
+ // check if we have a number
1910
+ if ($version == null || $version == "") {$version = "?" ;}
1911
+
1912
+ $browserInfoContent .= 'Platform: '.$platform."\n";
1913
+ $browserInfoContent .= 'Browser Name: '.$bname."\n";
1914
+ $browserInfoContent .= 'Browser Version: '.$version."\n";
1915
+ $browserInfoContent .= 'User Agent: '.$uAgent."\n";
1916
+
1917
+ return $browserInfoContent;
1918
+ }
1919
+
1920
+ // checking user roles capability to do actions
1921
+ public static function userCanAccessTo()
1922
+ {
1923
+ // if this is not admin side screen we don't need to check roles and capabilities
1924
+ if (!is_admin()) {
1925
+ return true;
1926
+ }
1927
+
1928
+ $allow = false;
1929
+
1930
+ $savedUserRolesInPopup = self::getPopupPostAllowedUserRoles();
1931
+ $currentUserRole = self::getCurrentUserRole();
1932
+
1933
+ // we need to check if there are any intersections between saved user roles and current user
1934
+ $hasIntersection = array_intersect($currentUserRole, $savedUserRolesInPopup);
1935
+ if (!empty($hasIntersection)) {
1936
+ $allow = true;
1937
+ }
1938
+
1939
+ return $allow;
1940
+ }
1941
+
1942
+ public static function filterUserCapabilitiesForTheUserRoles($hook = 'save')
1943
+ {
1944
+ global $wp_roles;
1945
+
1946
+ $allAvailableWpRoles = $wp_roles->roles;
1947
+ $savedUserRoles = get_option('sgpb-user-roles');
1948
+ // we need to remove from all roles, either when deactivating the plugin and when there is no saved roles
1949
+ if (empty($savedUserRoles) || $hook == 'deactivate') {
1950
+ $savedUserRoles = array();
1951
+ }
1952
+ $rolesToBeRestricted = array();
1953
+ // selected user roles, which have access to the PB
1954
+ foreach ($allAvailableWpRoles as $allAvailableWpRole) {
1955
+ if (isset($allAvailableWpRole['name']) && in_array(lcfirst($allAvailableWpRole['name']), $savedUserRoles)) {
1956
+ $indexToUnset = lcfirst($allAvailableWpRole['name']);
1957
+ continue;
1958
+ }
1959
+ $rolesToBeRestricted[] = lcfirst($allAvailableWpRole['name']);
1960
+ }
1961
+
1962
+ $caps = array(
1963
+ 'read_private_sgpb_popups',
1964
+ 'edit_sgpb_popup',
1965
+ 'edit_sgpb_popups',
1966
+ 'edit_others_sgpb_popups',
1967
+ 'edit_published_sgpb_popups',
1968
+ 'publish_sgpb_popups',
1969
+ 'delete_sgpb_popups',
1970
+ 'delete_published_posts',
1971
+ 'delete_others_sgpb_popups',
1972
+ 'delete_private_sgpb_popups',
1973
+ 'delete_private_sgpb_popup',
1974
+ 'delete_published_sgpb_popups',
1975
+ 'sgpb_manage_options',
1976
+ 'manage_popup_terms',
1977
+ 'manage_popup_categories_terms'
1978
+ );
1979
+
1980
+ if ($hook == 'activate') {
1981
+ $rolesToBeRestricted = $savedUserRoles;
1982
+ }
1983
+ foreach ($rolesToBeRestricted as $roleToBeRestricted) {
1984
+ if ($roleToBeRestricted == 'administrator' || $roleToBeRestricted == 'admin') {
1985
+ continue;
1986
+ }
1987
+ foreach ($caps as $cap) {
1988
+ // only for the activation hook we need to add our capabilities back
1989
+ if ($hook == 'activate') {
1990
+ $wp_roles->add_cap($roleToBeRestricted, $cap);
1991
+ }
1992
+ else {
1993
+ $wp_roles->remove_cap($roleToBeRestricted, $cap);
1994
+ }
1995
+ }
1996
+ }
1997
+ }
1998
+
1999
+ public static function removeUnnecessaryCodeFromPopups()
2000
+ {
2001
+ $alreadyClearded = self::getOption('sgpb-unnecessary-scripts-removed-1');
2002
+ if ($alreadyClearded) {
2003
+ return true;
2004
+ }
2005
+
2006
+ global $wpdb;
2007
+ $getAllDataSql = $wpdb->prepare('SELECT id FROM '.$wpdb->prefix.'posts WHERE post_type = %s', SG_POPUP_POST_TYPE);
2008
+ $popupsId = $wpdb->get_results($getAllDataSql, ARRAY_A);
2009
+ if (empty($popupsId)) {
2010
+ return true;
2011
+ }
2012
+ foreach ($popupsId as $popupId) {
2013
+ if (empty($popupId['id'])) {
2014
+ continue;
2015
+ }
2016
+ $id = $popupId['id'];
2017
+ $customScripts = get_post_meta($id, 'sg_popup_scripts', true);
2018
+ if (empty($customScripts)) {
2019
+ continue;
2020
+ }
2021
+ if (isset($customScripts['js'])) {
2022
+ unset($customScripts['js']);
2023
+ update_post_meta($id, 'sg_popup_scripts', $customScripts);
2024
+ }
2025
+ }
2026
+
2027
+ self::updateOption('sgpb-unnecessary-scripts-removed-1', 1);
2028
+ }
2029
+
2030
+ public static function sendTestNewsletter($newsletterData = array())
2031
+ {
2032
+ $mailSubject = $newsletterData['newsletterSubject'];
2033
+ $fromEmail = $newsletterData['fromEmail'];
2034
+ $emailMessage = $newsletterData['messageBody'];
2035
+ $blogInfo = get_bloginfo();
2036
+ $headers = array(
2037
+ 'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
2038
+ 'MIME-Version: 1.0' ,
2039
+ 'Content-type: text/html; charset=UTF-8'
2040
+ );
2041
+
2042
+ $emails = get_option('admin_email');
2043
+ if (!empty($newsletterData['testSendingEmails'])) {
2044
+ $emails = $newsletterData['testSendingEmails'];
2045
+ $emails = str_replace(' ', '', $emails);
2046
+
2047
+ $receiverEmailsArray = array();
2048
+ $emails = explode(',', $emails);
2049
+ foreach ($emails as $mail) {
2050
+ if (is_email($mail)) {
2051
+ $receiverEmailsArray[] = $mail;
2052
+ }
2053
+ }
2054
+ $emails = $receiverEmailsArray;
2055
+ }
2056
+
2057
+ $mailStatus = wp_mail($emails, $mailSubject, $emailMessage, $headers);
2058
+
2059
+ wp_die($newsletterData['testSendingStatus']);
2060
+ }
2061
+
2062
+ // wp uploaded images
2063
+ public static function getImageAltTextByUrl($imageUrl = '')
2064
+ {
2065
+ $imageId = attachment_url_to_postid($imageUrl);
2066
+ $altText = get_post_meta($imageId, '_wp_attachment_image_alt', true);
2067
+
2068
+ return $altText;
2069
+ }
2070
+ }
com/helpers/ConfigDataHelper.php CHANGED
@@ -1,1253 +1,1253 @@
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' => 'col-md-5 sgpb-choice-option-wrapper sgpb-sub-option-label'
257
- ),
258
- 'groupWrapperAttr' => array(
259
- 'class' => 'row form-group sgpb-choice-wrapper'
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
- __('If you need the popup id number in the custom code, you may use the following variable to get the ID: <code>popupId</code>', SG_POPUP_TEXT_DOMAIN)
312
- )
313
- ),
314
- 'css' => array(
315
- // we need this oldDefaultValue for the backward compatibility
316
- 'oldDefaultValue' => array(
317
- '/*popup content wrapper*/'."\n".
318
- '.sgpb-content-popupId {'."\n\n".'}'."\n\n".
319
-
320
- '/*overlay*/'."\n".
321
- '.sgpb-popup-overlay-popupId {'."\n\n".'}'."\n\n".
322
-
323
- '/*popup wrapper*/'."\n".
324
- '.sgpb-popup-builder-content-popupId {'."\n\n".'}'."\n\n"
325
- ),
326
- 'description' => array(
327
- __('If you need the popup id number in the custom code, you may use the following variable to get the ID: <code>popupId</code>', SG_POPUP_TEXT_DOMAIN),
328
- '<br>/*popup content wrapper*/',
329
- '.sgpb-content-popupId',
330
- '<br>/*overlay*/',
331
- '.sgpb-popup-overlay-popupId',
332
- '<br>/*popup wrapper*/',
333
- '.sgpb-popup-builder-content-popupId'
334
- )
335
- )
336
- );
337
-
338
- $data['htmlCustomButtonArgs'] = array(
339
- 'template' => array(
340
- 'fieldWrapperAttr' => array(
341
- 'class' => 'col-md-6 sgpb-choice-option-wrapper'
342
- ),
343
- 'labelAttr' => array(
344
- 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
345
- ),
346
- 'groupWrapperAttr' => array(
347
- 'class' => 'row form-group sgpb-choice-wrapper'
348
- )
349
- ),
350
- 'buttonPosition' => 'right',
351
- 'nextNewLine' => true,
352
- 'fields' => array(
353
- array(
354
- 'attr' => array(
355
- 'type' => 'radio',
356
- 'name' => 'sgpb-custom-button',
357
- 'class' => 'custom-button-copy-to-clipboard',
358
- 'data-attr-href' => 'sgpb-custom-button-copy',
359
- 'value' => 'copyToClipBoard'
360
- ),
361
- 'label' => array(
362
- 'name' => __('Copy to clipboard', SG_POPUP_TEXT_DOMAIN).':'
363
- )
364
- ),
365
- array(
366
- 'attr' => array(
367
- 'type' => 'radio',
368
- 'name' => 'sgpb-custom-button',
369
- 'class' => 'custom-button-copy-to-clipboard',
370
- 'data-attr-href' => 'sgpb-custom-button-redirect-to-URL',
371
- 'value' => 'redirectToURL'
372
- ),
373
- 'label' => array(
374
- 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
375
- )
376
- ),
377
- array(
378
- 'attr' => array(
379
- 'type' => 'radio',
380
- 'name' => 'sgpb-custom-button',
381
- 'class' => 'subs-success-open-popup',
382
- 'data-attr-href' => 'sgpb-custom-button-open-popup',
383
- 'value' => 'openPopup'
384
- ),
385
- 'label' => array(
386
- 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
387
- )
388
- ),
389
- array(
390
- 'attr' => array(
391
- 'type' => 'radio',
392
- 'name' => 'sgpb-custom-button',
393
- 'class' => 'sgpb-custom-button-hide-popup',
394
- 'value' => 'hidePopup'
395
- ),
396
- 'label' => array(
397
- 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
398
- )
399
- )
400
- )
401
- );
402
-
403
- $data['popupDimensions'] = array(
404
- 'template' => array(
405
- 'fieldWrapperAttr' => array(
406
- 'class' => 'col-md-7 sgpb-choice-option-wrapper'
407
- ),
408
- 'labelAttr' => array(
409
- 'class' => 'col-md-5 sgpb-choice-option-wrapper'
410
- ),
411
- 'groupWrapperAttr' => array(
412
- 'class' => 'row form-group sgpb-choice-wrapper'
413
- )
414
- ),
415
- 'buttonPosition' => 'right',
416
- 'nextNewLine' => true,
417
- 'fields' => array(
418
- array(
419
- 'attr' => array(
420
- 'type' => 'radio',
421
- 'name' => 'sgpb-popup-dimension-mode',
422
- 'class' => 'test class',
423
- 'data-attr-href' => 'responsive-dimension-wrapper',
424
- 'value' => 'responsiveMode'
425
- ),
426
- 'label' => array(
427
- 'name' => __('Responsive mode', SG_POPUP_TEXT_DOMAIN).':',
428
- '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).'.'
429
- )
430
- ),
431
- array(
432
- 'attr' => array(
433
- 'type' => 'radio',
434
- 'name' => 'sgpb-popup-dimension-mode',
435
- 'class' => 'test class',
436
- 'data-attr-href' => 'custom-dimension-wrapper',
437
- 'value' => 'customMode'
438
- ),
439
- 'label' => array(
440
- 'name' => __('Custom mode', SG_POPUP_TEXT_DOMAIN).':',
441
- 'info' => __('Add your own custom dimensions for the popup to get the exact sizing for your popup', SG_POPUP_TEXT_DOMAIN).'.'
442
- )
443
- )
444
- )
445
- );
446
-
447
- $data['theme'] = array(
448
- array(
449
- 'value' => 'sgpb-theme-1',
450
- 'data-attributes' => array(
451
- 'class' => 'js-sgpb-popup-themes',
452
- 'data-popup-theme-number' => 1
453
- )
454
- ),
455
- array(
456
- 'value' => 'sgpb-theme-2',
457
- 'data-attributes' => array(
458
- 'class' => 'js-sgpb-popup-themes',
459
- 'data-popup-theme-number' => 2
460
- )
461
- ),
462
- array(
463
- 'value' => 'sgpb-theme-3',
464
- 'data-attributes' => array(
465
- 'class' => 'js-sgpb-popup-themes',
466
- 'data-popup-theme-number' => 3
467
- )
468
- ),
469
- array(
470
- 'value' => 'sgpb-theme-4',
471
- 'data-attributes' => array(
472
- 'class' => 'js-sgpb-popup-themes',
473
- 'data-popup-theme-number' => 4
474
- )
475
- ),
476
- array(
477
- 'value' => 'sgpb-theme-5',
478
- 'data-attributes' => array(
479
- 'class' => 'js-sgpb-popup-themes',
480
- 'data-popup-theme-number' => 5
481
- )
482
- ),
483
- array(
484
- 'value' => 'sgpb-theme-6',
485
- 'data-attributes' => array(
486
- 'class' => 'js-sgpb-popup-themes',
487
- 'data-popup-theme-number' => 6
488
- )
489
- )
490
- );
491
-
492
- $data['responsiveDimensions'] = array(
493
- 'auto' => __('Auto', SG_POPUP_TEXT_DOMAIN),
494
- '10' => '10%',
495
- '20' => '20%',
496
- '30' => '30%',
497
- '40' => '40%',
498
- '50' => '50%',
499
- '60' => '60%',
500
- '70' => '70%',
501
- '80' => '80%',
502
- '90' => '90%',
503
- '100' => '100%',
504
- 'fullScreen' => __('Full screen', SG_POPUP_TEXT_DOMAIN)
505
- );
506
-
507
- $data['freeConditions'] = array(
508
- 'devices' => __('Devices', SG_POPUP_TEXT_DOMAIN),
509
- 'user-status' => __('User Status', SG_POPUP_TEXT_DOMAIN),
510
- 'after-x' => __('After x pages visit', SG_POPUP_TEXT_DOMAIN),
511
- 'user-role' => __('User Role', SG_POPUP_TEXT_DOMAIN),
512
- 'countries' => __('Countries', SG_POPUP_TEXT_DOMAIN),
513
- 'detect-by-url' => __('Detect by URL', SG_POPUP_TEXT_DOMAIN),
514
- 'cookie-detection' => __('Cookie Detection', SG_POPUP_TEXT_DOMAIN),
515
- 'operation-system' => __('Operating System', SG_POPUP_TEXT_DOMAIN),
516
- 'browser-detection' => __('Web Browser', SG_POPUP_TEXT_DOMAIN)
517
- );
518
-
519
- $data['closeButtonPositions'] = array(
520
- 'topLeft' => __('top-left', SG_POPUP_TEXT_DOMAIN),
521
- 'topRight' => __('top-right', SG_POPUP_TEXT_DOMAIN),
522
- 'bottomLeft' => __('bottom-left', SG_POPUP_TEXT_DOMAIN),
523
- 'bottomRight' => __('bottom-right', SG_POPUP_TEXT_DOMAIN)
524
- );
525
-
526
- $data['closeButtonPositionsFirstTheme'] = array(
527
- 'bottomLeft' => __('bottom-left', SG_POPUP_TEXT_DOMAIN),
528
- 'bottomRight' => __('bottom-right', SG_POPUP_TEXT_DOMAIN)
529
- );
530
-
531
- $data['pxPercent'] = array(
532
- 'px' => 'px',
533
- '%' => '%'
534
- );
535
-
536
- $data['countdownFormat'] = array(
537
- SG_COUNTDOWN_COUNTER_SECONDS_SHOW => 'DD:HH:MM:SS',
538
- SG_COUNTDOWN_COUNTER_SECONDS_HIDE => 'DD:HH:MM'
539
- );
540
-
541
- $data['countdownTimezone'] = self::getPopupTimeZone();
542
-
543
- $data['countdownLanguage'] = array(
544
- 'English' => 'English',
545
- 'German' => 'Deutsche',
546
- 'Spanish' => 'Español',
547
- 'Arabic' => 'عربى',
548
- 'Italian' => 'Italiano',
549
- 'Dutch' => 'Dutch',
550
- 'Norwegian' => 'Norsk',
551
- 'Portuguese' => 'Português',
552
- 'Russian' => 'Русский',
553
- 'Swedish' => 'Svenska',
554
- 'Czech' => 'Čeština',
555
- 'Chinese' => '中文'
556
- );
557
-
558
- $data['weekDaysArray'] = array(
559
- 'Mon' => __('Monday', SG_POPUP_TEXT_DOMAIN),
560
- 'Tue' => __('Tuesday', SG_POPUP_TEXT_DOMAIN),
561
- 'Wed' => __('Wednesday', SG_POPUP_TEXT_DOMAIN),
562
- 'Thu' => __('Thursday', SG_POPUP_TEXT_DOMAIN),
563
- 'Fri' => __('Friday', SG_POPUP_TEXT_DOMAIN),
564
- 'Sat' => __('Saturday', SG_POPUP_TEXT_DOMAIN),
565
- 'Sun' => __('Sunday', SG_POPUP_TEXT_DOMAIN)
566
- );
567
-
568
- $data['messageResize'] = array(
569
- 'both' => __('Both', SG_POPUP_TEXT_DOMAIN),
570
- 'horizontal' => __('Horizontal', SG_POPUP_TEXT_DOMAIN),
571
- 'vertical' => __('Vertical', SG_POPUP_TEXT_DOMAIN),
572
- 'none' => __('None', SG_POPUP_TEXT_DOMAIN),
573
- 'inherit' => __('Inherit', SG_POPUP_TEXT_DOMAIN)
574
- );
575
-
576
- $data['socialShareOptions'] = array(
577
- 'template' => array(
578
- 'fieldWrapperAttr' => array(
579
- 'class' => 'col-md-7 sgpb-choice-option-wrapper'
580
- ),
581
- 'labelAttr' => array(
582
- 'class' => 'col-md-5 sgpb-choice-option-wrapper'
583
- ),
584
- 'groupWrapperAttr' => array(
585
- 'class' => 'row form-group sgpb-choice-wrapper'
586
- )
587
- ),
588
- 'buttonPosition' => 'right',
589
- 'nextNewLine' => true,
590
- 'fields' => array(
591
- array(
592
- 'attr' => array(
593
- 'type' => 'radio',
594
- 'name' => 'sgpb-social-share-url-type',
595
- 'class' => 'sgpb-share-url-type',
596
- 'data-attr-href' => '',
597
- 'value' => 'activeUrl'
598
- ),
599
- 'label' => array(
600
- 'name' => __('Use active URL', SG_POPUP_TEXT_DOMAIN).':'
601
- )
602
- ),
603
- array(
604
- 'attr' => array(
605
- 'type' => 'radio',
606
- 'name' => 'sgpb-social-share-url-type',
607
- 'class' => 'sgpb-share-url-type',
608
- 'data-attr-href' => 'sgpb-social-share-url-wrapper',
609
- 'value' => 'shareUrl'
610
- ),
611
- 'label' => array(
612
- 'name' => __('Share URL', SG_POPUP_TEXT_DOMAIN).':'
613
- )
614
- )
615
- )
616
- );
617
-
618
- $data['countdownDateFormat'] = array(
619
- 'template' => array(
620
- 'fieldWrapperAttr' => array(
621
- 'class' => 'col-md-5 sgpb-choice-option-wrapper'
622
- ),
623
- 'labelAttr' => array(
624
- 'class' => 'col-md-5 sgpb-choice-option-wrapper sgpb-sub-option-label'
625
- ),
626
- 'groupWrapperAttr' => array(
627
- 'class' => 'row form-group sgpb-choice-wrapper'
628
- )
629
- ),
630
- 'buttonPosition' => 'right',
631
- 'nextNewLine' => true,
632
- 'fields' => array(
633
- array(
634
- 'attr' => array(
635
- 'type' => 'radio',
636
- 'name' => 'sgpb-countdown-date-format',
637
- 'class' => 'sgpb-countdown-date-format-from-date',
638
- 'data-attr-href' => 'sgpb-countdown-date-format-from-date',
639
- 'value' => 'date'
640
- ),
641
- 'label' => array(
642
- 'name' => __('Due Date', SG_POPUP_TEXT_DOMAIN).':'
643
- )
644
- ),
645
- array(
646
- 'attr' => array(
647
- 'type' => 'radio',
648
- 'name' => 'sgpb-countdown-date-format',
649
- 'class' => 'sgpb-countdown-date-format-from-date',
650
- 'data-attr-href' => 'sgpb-countdown-date-format-from-input',
651
- 'value' => 'input'
652
- ),
653
- 'label' => array(
654
- 'name' => __('Timer', SG_POPUP_TEXT_DOMAIN).':'
655
- )
656
- )
657
- )
658
- );
659
-
660
- $data['contactFormSuccessBehavior'] = array(
661
- 'template' => array(
662
- 'fieldWrapperAttr' => array(
663
- 'class' => 'col-md-6 sgpb-choice-option-wrapper'
664
- ),
665
- 'labelAttr' => array(
666
- 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
667
- ),
668
- 'groupWrapperAttr' => array(
669
- 'class' => 'row form-group sgpb-choice-wrapper'
670
- )
671
- ),
672
- 'buttonPosition' => 'right',
673
- 'nextNewLine' => true,
674
- 'fields' => array(
675
- array(
676
- 'attr' => array(
677
- 'type' => 'radio',
678
- 'name' => 'sgpb-contact-success-behavior',
679
- 'class' => 'contact-success-message',
680
- 'data-attr-href' => 'contact-show-success-message',
681
- 'value' => 'showMessage'
682
- ),
683
- 'label' => array(
684
- 'name' => __('Success message', SG_POPUP_TEXT_DOMAIN).':'
685
- )
686
- ),
687
- array(
688
- 'attr' => array(
689
- 'type' => 'radio',
690
- 'name' => 'sgpb-contact-success-behavior',
691
- 'class' => 'contact-redirect-to-URL ok-ggoel',
692
- 'data-attr-href' => 'contact-redirect-to-URL',
693
- 'value' => 'redirectToURL'
694
- ),
695
- 'label' => array(
696
- 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
697
- )
698
- ),
699
- array(
700
- 'attr' => array(
701
- 'type' => 'radio',
702
- 'name' => 'sgpb-contact-success-behavior',
703
- 'class' => 'contact-success-open-popup',
704
- 'data-attr-href' => 'contact-open-popup',
705
- 'value' => 'openPopup'
706
- ),
707
- 'label' => array(
708
- 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
709
- )
710
- ),
711
- array(
712
- 'attr' => array(
713
- 'type' => 'radio',
714
- 'name' => 'sgpb-contact-success-behavior',
715
- 'class' => 'contact-hide-popup',
716
- 'value' => 'hidePopup'
717
- ),
718
- 'label' => array(
719
- 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
720
- )
721
- )
722
- )
723
- );
724
-
725
- $data['socialShareTheme'] = array(
726
- 'flat' => __('Flat', SG_POPUP_TEXT_DOMAIN),
727
- 'classic' => __('Classic', SG_POPUP_TEXT_DOMAIN),
728
- 'minima' => __('Minima', SG_POPUP_TEXT_DOMAIN),
729
- 'plain' => __('Plain', SG_POPUP_TEXT_DOMAIN)
730
- );
731
-
732
- $data['socialThemeSizes'] = array(
733
- '8' => '8',
734
- '10' => '10',
735
- '12' => '12',
736
- '14' => '14',
737
- '16' => '16',
738
- '18' => '18',
739
- '20' => '20',
740
- '24' => '24'
741
- );
742
-
743
- $data['socialThemeShereCount'] = array(
744
- 'true' => __('True', SG_POPUP_TEXT_DOMAIN),
745
- 'false' => __('False', SG_POPUP_TEXT_DOMAIN),
746
- 'inside' => __('Inside', SG_POPUP_TEXT_DOMAIN)
747
- );
748
-
749
- $data['popupInsertEventTypes'] = array(
750
- 'inherit' => __('Inherit', SG_POPUP_TEXT_DOMAIN),
751
- 'onLoad' => __('On load', SG_POPUP_TEXT_DOMAIN),
752
- 'click' => __('On click', SG_POPUP_TEXT_DOMAIN),
753
- 'hover' => __('On hover', SG_POPUP_TEXT_DOMAIN)
754
- );
755
-
756
- $data['subscriptionSuccessBehavior'] = array(
757
- 'template' => array(
758
- 'fieldWrapperAttr' => array(
759
- 'class' => 'col-md-6 sgpb-choice-option-wrapper'
760
- ),
761
- 'labelAttr' => array(
762
- 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
763
- ),
764
- 'groupWrapperAttr' => array(
765
- 'class' => 'row form-group sgpb-choice-wrapper'
766
- )
767
- ),
768
- 'buttonPosition' => 'right',
769
- 'nextNewLine' => true,
770
- 'fields' => array(
771
- array(
772
- 'attr' => array(
773
- 'type' => 'radio',
774
- 'name' => 'sgpb-subs-success-behavior',
775
- 'class' => 'subs-success-message',
776
- 'data-attr-href' => 'subs-show-success-message',
777
- 'value' => 'showMessage'
778
- ),
779
- 'label' => array(
780
- 'name' => __('Success message', SG_POPUP_TEXT_DOMAIN).':'
781
- )
782
- ),
783
- array(
784
- 'attr' => array(
785
- 'type' => 'radio',
786
- 'name' => 'sgpb-subs-success-behavior',
787
- 'class' => 'subs-redirect-to-URL',
788
- 'data-attr-href' => 'subs-redirect-to-URL',
789
- 'value' => 'redirectToURL'
790
- ),
791
- 'label' => array(
792
- 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
793
- )
794
- ),
795
- array(
796
- 'attr' => array(
797
- 'type' => 'radio',
798
- 'name' => 'sgpb-subs-success-behavior',
799
- 'class' => 'subs-success-open-popup',
800
- 'data-attr-href' => 'subs-open-popup',
801
- 'value' => 'openPopup'
802
- ),
803
- 'label' => array(
804
- 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
805
- )
806
- ),
807
- array(
808
- 'attr' => array(
809
- 'type' => 'radio',
810
- 'name' => 'sgpb-subs-success-behavior',
811
- 'class' => 'subs-hide-popup',
812
- 'value' => 'hidePopup'
813
- ),
814
- 'label' => array(
815
- 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
816
- )
817
- )
818
- )
819
- );
820
-
821
- $data['buttonsType'] = array(
822
- 'standard' => __('Standard', SG_POPUP_TEXT_DOMAIN),
823
- 'box_count' => __('Box with count', SG_POPUP_TEXT_DOMAIN),
824
- 'button_count' => __('Button with count', SG_POPUP_TEXT_DOMAIN),
825
- 'button' => __('Button', SG_POPUP_TEXT_DOMAIN)
826
- );
827
-
828
- $data['backroundImageModes'] = array(
829
- 'no-repeat' => __('None', SG_POPUP_TEXT_DOMAIN),
830
- 'cover' => __('Cover', SG_POPUP_TEXT_DOMAIN),
831
- 'contain' => __('Contain', SG_POPUP_TEXT_DOMAIN),
832
- 'repeat' => __('Repeat', SG_POPUP_TEXT_DOMAIN)
833
- );
834
-
835
- $data['openAnimationEfects'] = array(
836
- 'No effect' => __('None', SG_POPUP_TEXT_DOMAIN),
837
- 'sgpb-flip' => __('Flip', SG_POPUP_TEXT_DOMAIN),
838
- 'sgpb-shake' => __('Shake', SG_POPUP_TEXT_DOMAIN),
839
- 'sgpb-wobble' => __('Wobble', SG_POPUP_TEXT_DOMAIN),
840
- 'sgpb-swing' => __('Swing', SG_POPUP_TEXT_DOMAIN),
841
- 'sgpb-flash' => __('Flash', SG_POPUP_TEXT_DOMAIN),
842
- 'sgpb-bounce' => __('Bounce', SG_POPUP_TEXT_DOMAIN),
843
- 'sgpb-bounceInRight' => __('BounceInRight', SG_POPUP_TEXT_DOMAIN),
844
- 'sgpb-bounceIn' => __('BounceIn', SG_POPUP_TEXT_DOMAIN),
845
- 'sgpb-pulse' => __('Pulse', SG_POPUP_TEXT_DOMAIN),
846
- 'sgpb-rubberBand' => __('RubberBand', SG_POPUP_TEXT_DOMAIN),
847
- 'sgpb-tada' => __('Tada', SG_POPUP_TEXT_DOMAIN),
848
- 'sgpb-slideInUp' => __('SlideInUp', SG_POPUP_TEXT_DOMAIN),
849
- 'sgpb-jello' => __('Jello', SG_POPUP_TEXT_DOMAIN),
850
- 'sgpb-rotateIn' => __('RotateIn', SG_POPUP_TEXT_DOMAIN),
851
- 'sgpb-fadeIn' => __('FadeIn', SG_POPUP_TEXT_DOMAIN)
852
- );
853
-
854
- $data['closeAnimationEfects'] = array(
855
- 'No effect' => __('None', SG_POPUP_TEXT_DOMAIN),
856
- 'sgpb-flipInX' => __('Flip', SG_POPUP_TEXT_DOMAIN),
857
- 'sgpb-shake' => __('Shake', SG_POPUP_TEXT_DOMAIN),
858
- 'sgpb-wobble' => __('Wobble', SG_POPUP_TEXT_DOMAIN),
859
- 'sgpb-swing' => __('Swing', SG_POPUP_TEXT_DOMAIN),
860
- 'sgpb-flash' => __('Flash', SG_POPUP_TEXT_DOMAIN),
861
- 'sgpb-bounce' => __('Bounce', SG_POPUP_TEXT_DOMAIN),
862
- 'sgpb-bounceOutLeft' => __('BounceOutLeft', SG_POPUP_TEXT_DOMAIN),
863
- 'sgpb-bounceOut' => __('BounceOut', SG_POPUP_TEXT_DOMAIN),
864
- 'sgpb-pulse' => __('Pulse', SG_POPUP_TEXT_DOMAIN),
865
- 'sgpb-rubberBand' => __('RubberBand', SG_POPUP_TEXT_DOMAIN),
866
- 'sgpb-tada' => __('Tada', SG_POPUP_TEXT_DOMAIN),
867
- 'sgpb-slideOutUp' => __('SlideOutUp', SG_POPUP_TEXT_DOMAIN),
868
- 'sgpb-jello' => __('Jello', SG_POPUP_TEXT_DOMAIN),
869
- 'sgpb-rotateOut' => __('RotateOut', SG_POPUP_TEXT_DOMAIN),
870
- 'sgpb-fadeOut' => __('FadeOut', SG_POPUP_TEXT_DOMAIN)
871
- );
872
-
873
- $data['floatingButtonPositionsCorner'] = array(
874
- 'top-left' => __('Top left', SG_POPUP_TEXT_DOMAIN),
875
- 'top-right' => __('Top right', SG_POPUP_TEXT_DOMAIN),
876
- 'bottom-left' => __('Bottom left', SG_POPUP_TEXT_DOMAIN),
877
- 'bottom-right' => __('Bottom right', SG_POPUP_TEXT_DOMAIN)
878
- );
879
-
880
- $data['floatingButtonPositionsBasic'] = array(
881
- 'top-left' => __('Top left', SG_POPUP_TEXT_DOMAIN),
882
- 'top-right' => __('Top right', SG_POPUP_TEXT_DOMAIN),
883
- 'bottom-left' => __('Bottom left', SG_POPUP_TEXT_DOMAIN),
884
- 'bottom-right' => __('Bottom right', SG_POPUP_TEXT_DOMAIN),
885
- 'top-center' => __('Top center', SG_POPUP_TEXT_DOMAIN),
886
- 'bottom-center' => __('Bottom center', SG_POPUP_TEXT_DOMAIN),
887
- 'right-center' => __('Right center', SG_POPUP_TEXT_DOMAIN),
888
- 'left-center' => __('Left center', SG_POPUP_TEXT_DOMAIN)
889
- );
890
-
891
- $data['floatingButtonStyle'] = array(
892
- 'corner' => __('Corner', SG_POPUP_TEXT_DOMAIN),
893
- 'basic' => __('Basic', SG_POPUP_TEXT_DOMAIN)
894
- );
895
-
896
- $data['userRoles'] = self::getAllUserRoles();
897
-
898
- return $data;
899
- }
900
-
901
- public static function getAllUserRoles()
902
- {
903
- $rulesArray = array();
904
- if (!function_exists('get_editable_roles')){
905
- return $rulesArray;
906
- }
907
-
908
- $roles = get_editable_roles();
909
- foreach ($roles as $roleName => $roleInfo) {
910
- if ($roleName == 'administrator') {
911
- continue;
912
- }
913
- $rulesArray[$roleName] = $roleName;
914
- }
915
-
916
- return $rulesArray;
917
- }
918
-
919
- public static function getClickActionOptions()
920
- {
921
- $settings = array(
922
- 'defaultClickClassName' => __('Default', SG_POPUP_TEXT_DOMAIN),
923
- 'clickActionCustomClass' => __('Custom class', SG_POPUP_TEXT_DOMAIN)
924
- );
925
-
926
- return $settings;
927
- }
928
-
929
- public static function getHoverActionOptions()
930
- {
931
- $settings = array(
932
- 'defaultHoverClassName' => __('Default', SG_POPUP_TEXT_DOMAIN),
933
- 'hoverActionCustomClass' => __('Custom class', SG_POPUP_TEXT_DOMAIN)
934
- );
935
-
936
- return $settings;
937
- }
938
-
939
- // proStartSilver
940
- public static function getPopupDefaultTimeZone()
941
- {
942
- $timeZone = get_option('timezone_string');
943
- if (!$timeZone) {
944
- $timeZone = SG_POPUP_DEFAULT_TIME_ZONE;
945
- }
946
-
947
- return $timeZone;
948
- }
949
- // proEndSilver
950
-
951
- // proStartGold
952
- public static function getPopupTimeZone()
953
- {
954
- return array(
955
- 'Pacific/Midway' => '(GMT-11:00) Midway',
956
- 'Pacific/Niue' => '(GMT-11:00) Niue',
957
- 'Pacific/Pago_Pago' => '(GMT-11:00) Pago Pago',
958
- 'Pacific/Honolulu' => '(GMT-10:00) Hawaii Time',
959
- 'Pacific/Rarotonga' => '(GMT-10:00) Rarotonga',
960
- 'Pacific/Tahiti' => '(GMT-10:00) Tahiti',
961
- 'Pacific/Marquesas' => '(GMT-09:30) Marquesas',
962
- 'America/Anchorage' => '(GMT-09:00) Alaska Time',
963
- 'Pacific/Gambier' => '(GMT-09:00) Gambier',
964
- 'America/Los_Angeles' => '(GMT-08:00) Pacific Time',
965
- 'America/Tijuana' => '(GMT-08:00) Pacific Time - Tijuana',
966
- 'America/Vancouver' => '(GMT-08:00) Pacific Time - Vancouver',
967
- 'America/Whitehorse' => '(GMT-08:00) Pacific Time - Whitehorse',
968
- 'Pacific/Pitcairn' => '(GMT-08:00) Pitcairn',
969
- 'America/Dawson_Creek' => '(GMT-07:00) Mountain Time - Dawson Creek',
970
- 'America/Denver' => '(GMT-07:00) Mountain Time',
971
- 'America/Edmonton' => '(GMT-07:00) Mountain Time - Edmonton',
972
- 'America/Hermosillo' => '(GMT-07:00) Mountain Time - Hermosillo',
973
- 'America/Mazatlan' => '(GMT-07:00) Mountain Time - Chihuahua, Mazatlan',
974
- 'America/Phoenix' => '(GMT-07:00) Mountain Time - Arizona',
975
- 'America/Yellowknife' => '(GMT-07:00) Mountain Time - Yellowknife',
976
- 'America/Belize' => '(GMT-06:00) Belize',
977
- 'America/Chicago' => '(GMT-06:00) Central Time',
978
- 'America/Costa_Rica' => '(GMT-06:00) Costa Rica',
979
- 'America/El_Salvador' => '(GMT-06:00) El Salvador',
980
- 'America/Guatemala' => '(GMT-06:00) Guatemala',
981
- 'America/Managua' => '(GMT-06:00) Managua',
982
- 'America/Mexico_City' => '(GMT-06:00) Central Time - Mexico City',
983
- 'America/Regina' => '(GMT-06:00) Central Time - Regina',
984
- 'America/Tegucigalpa' => '(GMT-06:00) Central Time - Tegucigalpa',
985
- 'America/Winnipeg' => '(GMT-06:00) Central Time - Winnipeg',
986
- 'Pacific/Easter' => '(GMT-06:00) Easter Island',
987
- 'Pacific/Galapagos' => '(GMT-06:00) Galapagos',
988
- 'America/Bogota' => '(GMT-05:00) Bogota',
989
- 'America/Cayman' => '(GMT-05:00) Cayman',
990
- 'America/Guayaquil' => '(GMT-05:00) Guayaquil',
991
- 'America/Havana' => '(GMT-05:00) Havana',
992
- 'America/Iqaluit' => '(GMT-05:00) Eastern Time - Iqaluit',
993
- 'America/Jamaica' => '(GMT-05:00) Jamaica',
994
- 'America/Lima' => '(GMT-05:00) Lima',
995
- 'America/Montreal' => '(GMT-05:00) Eastern Time - Montreal',
996
- 'America/Nassau' => '(GMT-05:00) Nassau',
997
- 'America/New_York' => '(GMT-05:00) Eastern Time',
998
- 'America/Panama' => '(GMT-05:00) Panama',
999
- 'America/Port-au-Prince' => '(GMT-05:00) Port-au-Prince',
1000
- 'America/Rio_Branco' => '(GMT-05:00) Rio Branco',
1001
- 'America/Toronto' => '(GMT-05:00) Eastern Time - Toronto',
1002
- 'America/Caracas' => '(GMT-04:30) Caracas',
1003
- 'America/Antigua' => '(GMT-04:00) Antigua',
1004
- 'America/Asuncion' => '(GMT-04:00) Asuncion',
1005
- 'America/Barbados' => '(GMT-04:00) Barbados',
1006
- 'America/Boa_Vista' => '(GMT-04:00) Boa Vista',
1007
- 'America/Campo_Grande' => '(GMT-04:00) Campo Grande',
1008
- 'America/Cuiaba' => '(GMT-04:00) Cuiaba',
1009
- 'America/Curacao' => '(GMT-04:00) Curacao',
1010
- 'America/Grand_Turk' => '(GMT-04:00) Grand Turk',
1011
- 'America/Guyana' => '(GMT-04:00) Guyana',
1012
- 'America/Halifax' => '(GMT-04:00) Atlantic Time - Halifax',
1013
- 'America/La_Paz' => '(GMT-04:00) La Paz',
1014
- 'America/Manaus' => '(GMT-04:00) Manaus',
1015
- 'America/Martinique' => '(GMT-04:00) Martinique',
1016
- 'America/Port_of_Spain' => '(GMT-04:00) Port of Spain',
1017
- 'America/Porto_Velho' => '(GMT-04:00) Porto Velho',
1018
- 'America/Puerto_Rico' => '(GMT-04:00) Puerto Rico',
1019
- 'America/Santiago' => '(GMT-04:00) Santiago',
1020
- 'America/Santo_Domingo' => '(GMT-04:00) Santo Domingo',
1021
- 'America/Thule' => '(GMT-04:00) Thule',
1022
- 'Antarctica/Palmer' => '(GMT-04:00) Palmer',
1023
- 'Atlantic/Bermuda' => '(GMT-04:00) Bermuda',
1024
- 'America/St_Johns' => '(GMT-03:30) Newfoundland Time - St. Johns',
1025
- 'America/Araguaina' => '(GMT-03:00) Araguaina',
1026
- 'America/Argentina/Buenos_Aires' => '(GMT-03:00) Buenos Aires',
1027
- 'America/Bahia' => '(GMT-03:00) Salvador',
1028
- 'America/Belem' => '(GMT-03:00) Belem',
1029
- 'America/Cayenne' => '(GMT-03:00) Cayenne',
1030
- 'America/Fortaleza' => '(GMT-03:00) Fortaleza',
1031
- 'America/Godthab' => '(GMT-03:00) Godthab',
1032
- 'America/Maceio' => '(GMT-03:00) Maceio',
1033
- 'America/Miquelon' => '(GMT-03:00) Miquelon',
1034
- 'America/Montevideo' => '(GMT-03:00) Montevideo',
1035
- 'America/Paramaribo' => '(GMT-03:00) Paramaribo',
1036
- 'America/Recife' => '(GMT-03:00) Recife',
1037
- 'America/Sao_Paulo' => '(GMT-03:00) Sao Paulo',
1038
- 'Antarctica/Rothera' => '(GMT-03:00) Rothera',
1039
- 'Atlantic/Stanley' => '(GMT-03:00) Stanley',
1040
- 'America/Noronha' => '(GMT-02:00) Noronha',
1041
- 'Atlantic/South_Georgia' => '(GMT-02:00) South Georgia',
1042
- 'America/Scoresbysund' => '(GMT-01:00) Scoresbysund',
1043
- 'Atlantic/Azores' => '(GMT-01:00) Azores',
1044
- 'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde',
1045
- 'Africa/Abidjan' => '(GMT+00:00) Abidjan',
1046
- 'Africa/Accra' => '(GMT+00:00) Accra',
1047
- 'Africa/Bissau' => '(GMT+00:00) Bissau',
1048
- 'Africa/Casablanca' => '(GMT+00:00) Casablanca',
1049
- 'Africa/El_Aaiun' => '(GMT+00:00) El Aaiun',
1050
- 'Africa/Monrovia' => '(GMT+00:00) Monrovia',
1051
- 'America/Danmarkshavn' => '(GMT+00:00) Danmarkshavn',
1052
- 'Atlantic/Canary' => '(GMT+00:00) Canary Islands',
1053
- 'Atlantic/Faroe' => '(GMT+00:00) Faeroe',
1054
- 'Atlantic/Reykjavik' => '(GMT+00:00) Reykjavik',
1055
- 'Etc/GMT' => '(GMT+00:00) GMT (no daylight saving)',
1056
- 'Europe/Dublin' => '(GMT+00:00) Dublin',
1057
- 'Europe/Lisbon' => '(GMT+00:00) Lisbon',
1058
- 'Europe/London' => '(GMT+00:00) London',
1059
- 'Africa/Algiers' => '(GMT+01:00) Algiers',
1060
- 'Africa/Ceuta' => '(GMT+01:00) Ceuta',
1061
- 'Africa/Lagos' => '(GMT+01:00) Lagos',
1062
- 'Africa/Ndjamena' => '(GMT+01:00) Ndjamena',
1063
- 'Africa/Tunis' => '(GMT+01:00) Tunis',
1064
- 'Africa/Windhoek' => '(GMT+01:00) Windhoek',
1065
- 'Europe/Amsterdam' => '(GMT+01:00) Amsterdam',
1066
- 'Europe/Andorra' => '(GMT+01:00) Andorra',
1067
- 'Europe/Belgrade' => '(GMT+01:00) Central European Time - Belgrade',
1068
- 'Europe/Berlin' => '(GMT+01:00) Berlin',
1069
- 'Europe/Brussels' => '(GMT+01:00) Brussels',
1070
- 'Europe/Budapest' => '(GMT+01:00) Budapest',
1071
- 'Europe/Copenhagen' => '(GMT+01:00) Copenhagen',
1072
- 'Europe/Gibraltar' => '(GMT+01:00) Gibraltar',
1073
- 'Europe/Luxembourg' => '(GMT+01:00) Luxembourg',
1074
- 'Europe/Madrid' => '(GMT+01:00) Madrid',
1075
- 'Europe/Malta' => '(GMT+01:00) Malta',
1076
- 'Europe/Monaco' => '(GMT+01:00) Monaco',
1077
- 'Europe/Oslo' => '(GMT+01:00) Oslo',
1078
- 'Europe/Paris' => '(GMT+01:00) Paris',
1079
- 'Europe/Prague' => '(GMT+01:00) Central European Time - Prague',
1080
- 'Europe/Rome' => '(GMT+01:00) Rome',
1081
- 'Europe/Stockholm' => '(GMT+01:00) Stockholm',
1082
- 'Europe/Tirane' => '(GMT+01:00) Tirane',
1083
- 'Europe/Vienna' => '(GMT+01:00) Vienna',
1084
- 'Europe/Warsaw' => '(GMT+01:00) Warsaw',
1085
- 'Europe/Zurich' => '(GMT+01:00) Zurich',
1086
- 'Africa/Cairo' => '(GMT+02:00) Cairo',
1087
- 'Africa/Johannesburg' => '(GMT+02:00) Johannesburg',
1088
- 'Africa/Maputo' => '(GMT+02:00) Maputo',
1089
- 'Africa/Tripoli' => '(GMT+02:00) Tripoli',
1090
- 'Asia/Amman' => '(GMT+02:00) Amman',
1091
- 'Asia/Beirut' => '(GMT+02:00) Beirut',
1092
- 'Asia/Damascus' => '(GMT+02:00) Damascus',
1093
- 'Asia/Gaza' => '(GMT+02:00) Gaza',
1094
- 'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
1095
- 'Asia/Nicosia' => '(GMT+02:00) Nicosia',
1096
- 'Europe/Athens' => '(GMT+02:00) Athens',
1097
- 'Europe/Bucharest' => '(GMT+02:00) Bucharest',
1098
- 'Europe/Chisinau' => '(GMT+02:00) Chisinau',
1099
- 'Europe/Helsinki' => '(GMT+02:00) Helsinki',
1100
- 'Europe/Istanbul' => '(GMT+02:00) Istanbul',
1101
- 'Europe/Kaliningrad' => '(GMT+02:00) Moscow-01 - Kaliningrad',
1102
- 'Europe/Kiev' => '(GMT+02:00) Kiev',
1103
- 'Europe/Riga' => '(GMT+02:00) Riga',
1104
- 'Europe/Sofia' => '(GMT+02:00) Sofia',
1105
- 'Europe/Tallinn' => '(GMT+02:00) Tallinn',
1106
- 'Europe/Vilnius' => '(GMT+02:00) Vilnius',
1107
- 'Africa/Addis_Ababa' => '(GMT+03:00) Addis Ababa',
1108
- 'Africa/Asmara' => '(GMT+03:00) Asmera',
1109
- 'Africa/Dar_es_Salaam' => '(GMT+03:00) Dar es Salaam',
1110
- 'Africa/Djibouti' => '(GMT+03:00) Djibouti',
1111
- 'Africa/Kampala' => '(GMT+03:00) Kampala',
1112
- 'Africa/Khartoum' => '(GMT+03:00) Khartoum',
1113
- 'Africa/Mogadishu' => '(GMT+03:00) Mogadishu',
1114
- 'Africa/Nairobi' => '(GMT+03:00) Nairobi',
1115
- 'Antarctica/Syowa' => '(GMT+03:00) Syowa',
1116
- 'Asia/Aden' => '(GMT+03:00) Aden',
1117
- 'Asia/Baghdad' => '(GMT+03:00) Baghdad',
1118
- 'Asia/Bahrain' => '(GMT+03:00) Bahrain',
1119
- 'Asia/Kuwait' => '(GMT+03:00) Kuwait',
1120
- 'Asia/Qatar' => '(GMT+03:00) Qatar',
1121
- 'Asia/Riyadh' => '(GMT+03:00) Riyadh',
1122
- 'Europe/Minsk' => '(GMT+03:00) Minsk',
1123
- 'Europe/Moscow' => '(GMT+03:00) Moscow+00',
1124
- 'Indian/Antananarivo' => '(GMT+03:00) Antananarivo',
1125
- 'Indian/Comoro' => '(GMT+03:00) Comoro',
1126
- 'Indian/Mayotte' => '(GMT+03:00) Mayotte',
1127
- 'Asia/Tehran' => '(GMT+03:30) Tehran',
1128
- 'Asia/Baku' => '(GMT+04:00) Baku',
1129
- 'Asia/Dubai' => '(GMT+04:00) Dubai',
1130
- 'Asia/Muscat' => '(GMT+04:00) Muscat',
1131
- 'Asia/Tbilisi' => '(GMT+04:00) Tbilisi',
1132
- 'Asia/Yerevan' => '(GMT+04:00) Yerevan',
1133
- 'Europe/Samara' => '(GMT+04:00) Moscow+00 - Samara',
1134
- 'Indian/Mahe' => '(GMT+04:00) Mahe',
1135
- 'Indian/Mauritius' => '(GMT+04:00) Mauritius',
1136
- 'Indian/Reunion' => '(GMT+04:00) Reunion',
1137
- 'Asia/Kabul' => '(GMT+04:30) Kabul',
1138
- 'Antarctica/Mawson' => '(GMT+05:00) Mawson',
1139
- 'Asia/Aqtau' => '(GMT+05:00) Aqtau',
1140
- 'Asia/Aqtobe' => '(GMT+05:00) Aqtobe',
1141
- 'Asia/Ashgabat' => '(GMT+05:00) Ashgabat',
1142
- 'Asia/Dushanbe' => '(GMT+05:00) Dushanbe',
1143
- 'Asia/Karachi' => '(GMT+05:00) Karachi',
1144
- 'Asia/Tashkent' => '(GMT+05:00) Tashkent',
1145
- 'Asia/Yekaterinburg' => '(GMT+05:00) Moscow+02 - Yekaterinburg',
1146
- 'Indian/Kerguelen' => '(GMT+05:00) Kerguelen',
1147
- 'Indian/Maldives' => '(GMT+05:00) Maldives',
1148
- 'Asia/Calcutta' => '(GMT+05:30) India Standard Time',
1149
- 'Asia/Colombo' => '(GMT+05:30) Colombo',
1150
- 'Asia/Katmandu' => '(GMT+05:45) Katmandu',
1151
- 'Antarctica/Vostok' => '(GMT+06:00) Vostok',
1152
- 'Asia/Almaty' => '(GMT+06:00) Almaty',
1153
- 'Asia/Bishkek' => '(GMT+06:00) Bishkek',
1154
- 'Asia/Dhaka' => '(GMT+06:00) Dhaka',
1155
- 'Asia/Omsk' => '(GMT+06:00) Moscow+03 - Omsk, Novosibirsk',
1156
- 'Asia/Thimphu' => '(GMT+06:00) Thimphu',
1157
- 'Indian/Chagos' => '(GMT+06:00) Chagos',
1158
- 'Asia/Rangoon' => '(GMT+06:30) Rangoon',
1159
- 'Indian/Cocos' => '(GMT+06:30) Cocos',
1160
- 'Antarctica/Davis' => '(GMT+07:00) Davis',
1161
- 'Asia/Bangkok' => '(GMT+07:00) Bangkok',
1162
- 'Asia/Hovd' => '(GMT+07:00) Hovd',
1163
- 'Asia/Jakarta' => '(GMT+07:00) Jakarta',
1164
- 'Asia/Krasnoyarsk' => '(GMT+07:00) Moscow+04 - Krasnoyarsk',
1165
- 'Asia/Saigon' => '(GMT+07:00) Hanoi',
1166
- 'Indian/Christmas' => '(GMT+07:00) Christmas',
1167
- 'Antarctica/Casey' => '(GMT+08:00) Casey',
1168
- 'Asia/Brunei' => '(GMT+08:00) Brunei',
1169
- 'Asia/Choibalsan' => '(GMT+08:00) Choibalsan',
1170
- 'Asia/Hong_Kong' => '(GMT+08:00) Hong Kong',
1171
- 'Asia/Irkutsk' => '(GMT+08:00) Moscow+05 - Irkutsk',
1172
- 'Asia/Kuala_Lumpur' => '(GMT+08:00) Kuala Lumpur',
1173
- 'Asia/Macau' => '(GMT+08:00) Macau',
1174
- 'Asia/Makassar' => '(GMT+08:00) Makassar',
1175
- 'Asia/Manila' => '(GMT+08:00) Manila',
1176
- 'Asia/Shanghai' => '(GMT+08:00) China Time - Beijing',
1177
- 'Asia/Singapore' => '(GMT+08:00) Singapore',
1178
- 'Asia/Taipei' => '(GMT+08:00) Taipei',
1179
- 'Asia/Ulaanbaatar' => '(GMT+08:00) Ulaanbaatar',
1180
- 'Australia/Perth' => '(GMT+08:00) Western Time - Perth',
1181
- 'Asia/Dili' => '(GMT+09:00) Dili',
1182
- 'Asia/Jayapura' => '(GMT+09:00) Jayapura',
1183
- 'Asia/Pyongyang' => '(GMT+09:00) Pyongyang',
1184
- 'Asia/Seoul' => '(GMT+09:00) Seoul',
1185
- 'Asia/Tokyo' => '(GMT+09:00) Tokyo',
1186
- 'Asia/Yakutsk' => '(GMT+09:00) Moscow+06 - Yakutsk',
1187
- 'Pacific/Palau' => '(GMT+09:00) Palau',
1188
- 'Australia/Adelaide' => '(GMT+09:30) Central Time - Adelaide',
1189
- 'Australia/Darwin' => '(GMT+09:30) Central Time - Darwin',
1190
- 'Antarctica/DumontDUrville' => '(GMT+10:00) Dumont D\'Urville',
1191
- 'Asia/Magadan' => '(GMT+10:00) Moscow+08 - Magadan',
1192
- 'Asia/Vladivostok' => '(GMT+10:00) Moscow+07 - Yuzhno-Sakhalinsk',
1193
- 'Australia/Brisbane' => '(GMT+10:00) Eastern Time - Brisbane',
1194
- 'Australia/Hobart' => '(GMT+10:00) Eastern Time - Hobart',
1195
- 'Australia/Sydney' => '(GMT+10:00) Eastern Time - Melbourne, Sydney',
1196
- 'Pacific/Chuuk' => '(GMT+10:00) Truk',
1197
- 'Pacific/Guam' => '(GMT+10:00) Guam',
1198
- 'Pacific/Port_Moresby' => '(GMT+10:00) Port Moresby',
1199
- 'Pacific/Saipan' => '(GMT+10:00) Saipan',
1200
- 'Pacific/Efate' => '(GMT+11:00) Efate',
1201
- 'Pacific/Guadalcanal' => '(GMT+11:00) Guadalcanal',
1202
- 'Pacific/Kosrae' => '(GMT+11:00) Kosrae',
1203
- 'Pacific/Noumea' => '(GMT+11:00) Noumea',
1204
- 'Pacific/Pohnpei' => '(GMT+11:00) Ponape',
1205
- 'Pacific/Norfolk' => '(GMT+11:30) Norfolk',
1206
- 'Asia/Kamchatka' => '(GMT+12:00) Moscow+08 - Petropavlovsk-Kamchatskiy',
1207
- 'Pacific/Auckland' => '(GMT+12:00) Auckland',
1208
- 'Pacific/Fiji' => '(GMT+12:00) Fiji',
1209
- 'Pacific/Funafuti' => '(GMT+12:00) Funafuti',
1210
- 'Pacific/Kwajalein' => '(GMT+12:00) Kwajalein',
1211
- 'Pacific/Majuro' => '(GMT+12:00) Majuro',
1212
- 'Pacific/Nauru' => '(GMT+12:00) Nauru',
1213
- 'Pacific/Tarawa' => '(GMT+12:00) Tarawa',
1214
- 'Pacific/Wake' => '(GMT+12:00) Wake',
1215
- 'Pacific/Wallis' => '(GMT+12:00) Wallis',
1216
- 'Pacific/Apia' => '(GMT+13:00) Apia',
1217
- 'Pacific/Enderbury' => '(GMT+13:00) Enderbury',
1218
- 'Pacific/Fakaofo' => '(GMT+13:00) Fakaofo',
1219
- 'Pacific/Tongatapu' => '(GMT+13:00) Tongatapu',
1220
- 'Pacific/Kiritimati' => '(GMT+14:00) Kiritimati'
1221
- );
1222
- }
1223
-
1224
- public static function getJsLocalizedData()
1225
- {
1226
- $translatedData = array(
1227
- 'imageSupportAlertMessage' => __('Only image files supported', SG_POPUP_TEXT_DOMAIN),
1228
- 'areYouSure' => __('Are you sure?', SG_POPUP_TEXT_DOMAIN),
1229
- 'addButtonSpinner' => __('Add', SG_POPUP_TEXT_DOMAIN),
1230
- 'audioSupportAlertMessage' => __('Only audio files supported (e.g.: mp3, wav, m4a, ogg)', SG_POPUP_TEXT_DOMAIN),
1231
- 'publishPopupBeforeElementor' => __('Please, publish the popup before starting to use Elementor with it!', SG_POPUP_TEXT_DOMAIN),
1232
- 'publishPopupBeforeDivi' => __('Please, publish the popup before starting to use Divi Builder with it!', SG_POPUP_TEXT_DOMAIN),
1233
- 'closeButtonAltText' => __('Close', SG_POPUP_TEXT_DOMAIN)
1234
- );
1235
-
1236
- return $translatedData;
1237
- }
1238
-
1239
- public static function getCurrentDateTime()
1240
- {
1241
- return date('Y-m-d H:i', strtotime(' +1 day'));
1242
- }
1243
-
1244
- public static function getDefaultTimezone()
1245
- {
1246
- $timezone = get_option('timezone_string');
1247
- if (!$timezone) {
1248
- $timezone = 'America/New_York';
1249
- }
1250
-
1251
- return $timezone;
1252
- }
1253
- }
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' => 'col-md-5 sgpb-choice-option-wrapper sgpb-sub-option-label'
257
+ ),
258
+ 'groupWrapperAttr' => array(
259
+ 'class' => 'row form-group sgpb-choice-wrapper'
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
+ __('If you need the popup id number in the custom code, you may use the following variable to get the ID: <code>popupId</code>', SG_POPUP_TEXT_DOMAIN)
312
+ )
313
+ ),
314
+ 'css' => array(
315
+ // we need this oldDefaultValue for the backward compatibility
316
+ 'oldDefaultValue' => array(
317
+ '/*popup content wrapper*/'."\n".
318
+ '.sgpb-content-popupId {'."\n\n".'}'."\n\n".
319
+
320
+ '/*overlay*/'."\n".
321
+ '.sgpb-popup-overlay-popupId {'."\n\n".'}'."\n\n".
322
+
323
+ '/*popup wrapper*/'."\n".
324
+ '.sgpb-popup-builder-content-popupId {'."\n\n".'}'."\n\n"
325
+ ),
326
+ 'description' => array(
327
+ __('If you need the popup id number in the custom code, you may use the following variable to get the ID: <code>popupId</code>', SG_POPUP_TEXT_DOMAIN),
328
+ '<br>/*popup content wrapper*/',
329
+ '.sgpb-content-popupId',
330
+ '<br>/*overlay*/',
331
+ '.sgpb-popup-overlay-popupId',
332
+ '<br>/*popup wrapper*/',
333
+ '.sgpb-popup-builder-content-popupId'
334
+ )
335
+ )
336
+ );
337
+
338
+ $data['htmlCustomButtonArgs'] = array(
339
+ 'template' => array(
340
+ 'fieldWrapperAttr' => array(
341
+ 'class' => 'col-md-6 sgpb-choice-option-wrapper'
342
+ ),
343
+ 'labelAttr' => array(
344
+ 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
345
+ ),
346
+ 'groupWrapperAttr' => array(
347
+ 'class' => 'row form-group sgpb-choice-wrapper'
348
+ )
349
+ ),
350
+ 'buttonPosition' => 'right',
351
+ 'nextNewLine' => true,
352
+ 'fields' => array(
353
+ array(
354
+ 'attr' => array(
355
+ 'type' => 'radio',
356
+ 'name' => 'sgpb-custom-button',
357
+ 'class' => 'custom-button-copy-to-clipboard',
358
+ 'data-attr-href' => 'sgpb-custom-button-copy',
359
+ 'value' => 'copyToClipBoard'
360
+ ),
361
+ 'label' => array(
362
+ 'name' => __('Copy to clipboard', SG_POPUP_TEXT_DOMAIN).':'
363
+ )
364
+ ),
365
+ array(
366
+ 'attr' => array(
367
+ 'type' => 'radio',
368
+ 'name' => 'sgpb-custom-button',
369
+ 'class' => 'custom-button-copy-to-clipboard',
370
+ 'data-attr-href' => 'sgpb-custom-button-redirect-to-URL',
371
+ 'value' => 'redirectToURL'
372
+ ),
373
+ 'label' => array(
374
+ 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
375
+ )
376
+ ),
377
+ array(
378
+ 'attr' => array(
379
+ 'type' => 'radio',
380
+ 'name' => 'sgpb-custom-button',
381
+ 'class' => 'subs-success-open-popup',
382
+ 'data-attr-href' => 'sgpb-custom-button-open-popup',
383
+ 'value' => 'openPopup'
384
+ ),
385
+ 'label' => array(
386
+ 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
387
+ )
388
+ ),
389
+ array(
390
+ 'attr' => array(
391
+ 'type' => 'radio',
392
+ 'name' => 'sgpb-custom-button',
393
+ 'class' => 'sgpb-custom-button-hide-popup',
394
+ 'value' => 'hidePopup'
395
+ ),
396
+ 'label' => array(
397
+ 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
398
+ )
399
+ )
400
+ )
401
+ );
402
+
403
+ $data['popupDimensions'] = array(
404
+ 'template' => array(
405
+ 'fieldWrapperAttr' => array(
406
+ 'class' => 'col-md-7 sgpb-choice-option-wrapper'
407
+ ),
408
+ 'labelAttr' => array(
409
+ 'class' => 'col-md-5 sgpb-choice-option-wrapper'
410
+ ),
411
+ 'groupWrapperAttr' => array(
412
+ 'class' => 'row form-group sgpb-choice-wrapper'
413
+ )
414
+ ),
415
+ 'buttonPosition' => 'right',
416
+ 'nextNewLine' => true,
417
+ 'fields' => array(
418
+ array(
419
+ 'attr' => array(
420
+ 'type' => 'radio',
421
+ 'name' => 'sgpb-popup-dimension-mode',
422
+ 'class' => 'test class',
423
+ 'data-attr-href' => 'responsive-dimension-wrapper',
424
+ 'value' => 'responsiveMode'
425
+ ),
426
+ 'label' => array(
427
+ 'name' => __('Responsive mode', SG_POPUP_TEXT_DOMAIN).':',
428
+ '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).'.'
429
+ )
430
+ ),
431
+ array(
432
+ 'attr' => array(
433
+ 'type' => 'radio',
434
+ 'name' => 'sgpb-popup-dimension-mode',
435
+ 'class' => 'test class',
436
+ 'data-attr-href' => 'custom-dimension-wrapper',
437
+ 'value' => 'customMode'
438
+ ),
439
+ 'label' => array(
440
+ 'name' => __('Custom mode', SG_POPUP_TEXT_DOMAIN).':',
441
+ 'info' => __('Add your own custom dimensions for the popup to get the exact sizing for your popup', SG_POPUP_TEXT_DOMAIN).'.'
442
+ )
443
+ )
444
+ )
445
+ );
446
+
447
+ $data['theme'] = array(
448
+ array(
449
+ 'value' => 'sgpb-theme-1',
450
+ 'data-attributes' => array(
451
+ 'class' => 'js-sgpb-popup-themes',
452
+ 'data-popup-theme-number' => 1
453
+ )
454
+ ),
455
+ array(
456
+ 'value' => 'sgpb-theme-2',
457
+ 'data-attributes' => array(
458
+ 'class' => 'js-sgpb-popup-themes',
459
+ 'data-popup-theme-number' => 2
460
+ )
461
+ ),
462
+ array(
463
+ 'value' => 'sgpb-theme-3',
464
+ 'data-attributes' => array(
465
+ 'class' => 'js-sgpb-popup-themes',
466
+ 'data-popup-theme-number' => 3
467
+ )
468
+ ),
469
+ array(
470
+ 'value' => 'sgpb-theme-4',
471
+ 'data-attributes' => array(
472
+ 'class' => 'js-sgpb-popup-themes',
473
+ 'data-popup-theme-number' => 4
474
+ )
475
+ ),
476
+ array(
477
+ 'value' => 'sgpb-theme-5',
478
+ 'data-attributes' => array(
479
+ 'class' => 'js-sgpb-popup-themes',
480
+ 'data-popup-theme-number' => 5
481
+ )
482
+ ),
483
+ array(
484
+ 'value' => 'sgpb-theme-6',
485
+ 'data-attributes' => array(
486
+ 'class' => 'js-sgpb-popup-themes',
487
+ 'data-popup-theme-number' => 6
488
+ )
489
+ )
490
+ );
491
+
492
+ $data['responsiveDimensions'] = array(
493
+ 'auto' => __('Auto', SG_POPUP_TEXT_DOMAIN),
494
+ '10' => '10%',
495
+ '20' => '20%',
496
+ '30' => '30%',
497
+ '40' => '40%',
498
+ '50' => '50%',
499
+ '60' => '60%',
500
+ '70' => '70%',
501
+ '80' => '80%',
502
+ '90' => '90%',
503
+ '100' => '100%',
504
+ 'fullScreen' => __('Full screen', SG_POPUP_TEXT_DOMAIN)
505
+ );
506
+
507
+ $data['freeConditions'] = array(
508
+ 'devices' => __('Devices', SG_POPUP_TEXT_DOMAIN),
509
+ 'user-status' => __('User Status', SG_POPUP_TEXT_DOMAIN),
510
+ 'after-x' => __('After x pages visit', SG_POPUP_TEXT_DOMAIN),
511
+ 'user-role' => __('User Role', SG_POPUP_TEXT_DOMAIN),
512
+ 'countries' => __('Countries', SG_POPUP_TEXT_DOMAIN),
513
+ 'detect-by-url' => __('Detect by URL', SG_POPUP_TEXT_DOMAIN),
514
+ 'cookie-detection' => __('Cookie Detection', SG_POPUP_TEXT_DOMAIN),
515
+ 'operation-system' => __('Operating System', SG_POPUP_TEXT_DOMAIN),
516
+ 'browser-detection' => __('Web Browser', SG_POPUP_TEXT_DOMAIN)
517
+ );
518
+
519
+ $data['closeButtonPositions'] = array(
520
+ 'topLeft' => __('top-left', SG_POPUP_TEXT_DOMAIN),
521
+ 'topRight' => __('top-right', SG_POPUP_TEXT_DOMAIN),
522
+ 'bottomLeft' => __('bottom-left', SG_POPUP_TEXT_DOMAIN),
523
+ 'bottomRight' => __('bottom-right', SG_POPUP_TEXT_DOMAIN)
524
+ );
525
+
526
+ $data['closeButtonPositionsFirstTheme'] = array(
527
+ 'bottomLeft' => __('bottom-left', SG_POPUP_TEXT_DOMAIN),
528
+ 'bottomRight' => __('bottom-right', SG_POPUP_TEXT_DOMAIN)
529
+ );
530
+
531
+ $data['pxPercent'] = array(
532
+ 'px' => 'px',
533
+ '%' => '%'
534
+ );
535
+
536
+ $data['countdownFormat'] = array(
537
+ SG_COUNTDOWN_COUNTER_SECONDS_SHOW => 'DD:HH:MM:SS',
538
+ SG_COUNTDOWN_COUNTER_SECONDS_HIDE => 'DD:HH:MM'
539
+ );
540
+
541
+ $data['countdownTimezone'] = self::getPopupTimeZone();
542
+
543
+ $data['countdownLanguage'] = array(
544
+ 'English' => 'English',
545
+ 'German' => 'Deutsche',
546
+ 'Spanish' => 'Español',
547
+ 'Arabic' => 'عربى',
548
+ 'Italian' => 'Italiano',
549
+ 'Dutch' => 'Dutch',
550
+ 'Norwegian' => 'Norsk',
551
+ 'Portuguese' => 'Português',
552
+ 'Russian' => 'Русский',
553
+ 'Swedish' => 'Svenska',
554
+ 'Czech' => 'Čeština',
555
+ 'Chinese' => '中文'
556
+ );
557
+
558
+ $data['weekDaysArray'] = array(
559
+ 'Mon' => __('Monday', SG_POPUP_TEXT_DOMAIN),
560
+ 'Tue' => __('Tuesday', SG_POPUP_TEXT_DOMAIN),
561
+ 'Wed' => __('Wednesday', SG_POPUP_TEXT_DOMAIN),
562
+ 'Thu' => __('Thursday', SG_POPUP_TEXT_DOMAIN),
563
+ 'Fri' => __('Friday', SG_POPUP_TEXT_DOMAIN),
564
+ 'Sat' => __('Saturday', SG_POPUP_TEXT_DOMAIN),
565
+ 'Sun' => __('Sunday', SG_POPUP_TEXT_DOMAIN)
566
+ );
567
+
568
+ $data['messageResize'] = array(
569
+ 'both' => __('Both', SG_POPUP_TEXT_DOMAIN),
570
+ 'horizontal' => __('Horizontal', SG_POPUP_TEXT_DOMAIN),
571
+ 'vertical' => __('Vertical', SG_POPUP_TEXT_DOMAIN),
572
+ 'none' => __('None', SG_POPUP_TEXT_DOMAIN),
573
+ 'inherit' => __('Inherit', SG_POPUP_TEXT_DOMAIN)
574
+ );
575
+
576
+ $data['socialShareOptions'] = array(
577
+ 'template' => array(
578
+ 'fieldWrapperAttr' => array(
579
+ 'class' => 'col-md-7 sgpb-choice-option-wrapper'
580
+ ),
581
+ 'labelAttr' => array(
582
+ 'class' => 'col-md-5 sgpb-choice-option-wrapper'
583
+ ),
584
+ 'groupWrapperAttr' => array(
585
+ 'class' => 'row form-group sgpb-choice-wrapper'
586
+ )
587
+ ),
588
+ 'buttonPosition' => 'right',
589
+ 'nextNewLine' => true,
590
+ 'fields' => array(
591
+ array(
592
+ 'attr' => array(
593
+ 'type' => 'radio',
594
+ 'name' => 'sgpb-social-share-url-type',
595
+ 'class' => 'sgpb-share-url-type',
596
+ 'data-attr-href' => '',
597
+ 'value' => 'activeUrl'
598
+ ),
599
+ 'label' => array(
600
+ 'name' => __('Use active URL', SG_POPUP_TEXT_DOMAIN).':'
601
+ )
602
+ ),
603
+ array(
604
+ 'attr' => array(
605
+ 'type' => 'radio',
606
+ 'name' => 'sgpb-social-share-url-type',
607
+ 'class' => 'sgpb-share-url-type',
608
+ 'data-attr-href' => 'sgpb-social-share-url-wrapper',
609
+ 'value' => 'shareUrl'
610
+ ),
611
+ 'label' => array(
612
+ 'name' => __('Share URL', SG_POPUP_TEXT_DOMAIN).':'
613
+ )
614
+ )
615
+ )
616
+ );
617
+
618
+ $data['countdownDateFormat'] = array(
619
+ 'template' => array(
620
+ 'fieldWrapperAttr' => array(
621
+ 'class' => 'col-md-5 sgpb-choice-option-wrapper'
622
+ ),
623
+ 'labelAttr' => array(
624
+ 'class' => 'col-md-5 sgpb-choice-option-wrapper sgpb-sub-option-label'
625
+ ),
626
+ 'groupWrapperAttr' => array(
627
+ 'class' => 'row form-group sgpb-choice-wrapper'
628
+ )
629
+ ),
630
+ 'buttonPosition' => 'right',
631
+ 'nextNewLine' => true,
632
+ 'fields' => array(
633
+ array(
634
+ 'attr' => array(
635
+ 'type' => 'radio',
636
+ 'name' => 'sgpb-countdown-date-format',
637
+ 'class' => 'sgpb-countdown-date-format-from-date',
638
+ 'data-attr-href' => 'sgpb-countdown-date-format-from-date',
639
+ 'value' => 'date'
640
+ ),
641
+ 'label' => array(
642
+ 'name' => __('Due Date', SG_POPUP_TEXT_DOMAIN).':'
643
+ )
644
+ ),
645
+ array(
646
+ 'attr' => array(
647
+ 'type' => 'radio',
648
+ 'name' => 'sgpb-countdown-date-format',
649
+ 'class' => 'sgpb-countdown-date-format-from-date',
650
+ 'data-attr-href' => 'sgpb-countdown-date-format-from-input',
651
+ 'value' => 'input'
652
+ ),
653
+ 'label' => array(
654
+ 'name' => __('Timer', SG_POPUP_TEXT_DOMAIN).':'
655
+ )
656
+ )
657
+ )
658
+ );
659
+
660
+ $data['contactFormSuccessBehavior'] = array(
661
+ 'template' => array(
662
+ 'fieldWrapperAttr' => array(
663
+ 'class' => 'col-md-6 sgpb-choice-option-wrapper'
664
+ ),
665
+ 'labelAttr' => array(
666
+ 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
667
+ ),
668
+ 'groupWrapperAttr' => array(
669
+ 'class' => 'row form-group sgpb-choice-wrapper'
670
+ )
671
+ ),
672
+ 'buttonPosition' => 'right',
673
+ 'nextNewLine' => true,
674
+ 'fields' => array(
675
+ array(
676
+ 'attr' => array(
677
+ 'type' => 'radio',
678
+ 'name' => 'sgpb-contact-success-behavior',
679
+ 'class' => 'contact-success-message',
680
+ 'data-attr-href' => 'contact-show-success-message',
681
+ 'value' => 'showMessage'
682
+ ),
683
+ 'label' => array(
684
+ 'name' => __('Success message', SG_POPUP_TEXT_DOMAIN).':'
685
+ )
686
+ ),
687
+ array(
688
+ 'attr' => array(
689
+ 'type' => 'radio',
690
+ 'name' => 'sgpb-contact-success-behavior',
691
+ 'class' => 'contact-redirect-to-URL ok-ggoel',
692
+ 'data-attr-href' => 'contact-redirect-to-URL',
693
+ 'value' => 'redirectToURL'
694
+ ),
695
+ 'label' => array(
696
+ 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
697
+ )
698
+ ),
699
+ array(
700
+ 'attr' => array(
701
+ 'type' => 'radio',
702
+ 'name' => 'sgpb-contact-success-behavior',
703
+ 'class' => 'contact-success-open-popup',
704
+ 'data-attr-href' => 'contact-open-popup',
705
+ 'value' => 'openPopup'
706
+ ),
707
+ 'label' => array(
708
+ 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
709
+ )
710
+ ),
711
+ array(
712
+ 'attr' => array(
713
+ 'type' => 'radio',
714
+ 'name' => 'sgpb-contact-success-behavior',
715
+ 'class' => 'contact-hide-popup',
716
+ 'value' => 'hidePopup'
717
+ ),
718
+ 'label' => array(
719
+ 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
720
+ )
721
+ )
722
+ )
723
+ );
724
+
725
+ $data['socialShareTheme'] = array(
726
+ 'flat' => __('Flat', SG_POPUP_TEXT_DOMAIN),
727
+ 'classic' => __('Classic', SG_POPUP_TEXT_DOMAIN),
728
+ 'minima' => __('Minima', SG_POPUP_TEXT_DOMAIN),
729
+ 'plain' => __('Plain', SG_POPUP_TEXT_DOMAIN)
730
+ );
731
+
732
+ $data['socialThemeSizes'] = array(
733
+ '8' => '8',
734
+ '10' => '10',
735
+ '12' => '12',
736
+ '14' => '14',
737
+ '16' => '16',
738
+ '18' => '18',
739
+ '20' => '20',
740
+ '24' => '24'
741
+ );
742
+
743
+ $data['socialThemeShereCount'] = array(
744
+ 'true' => __('True', SG_POPUP_TEXT_DOMAIN),
745
+ 'false' => __('False', SG_POPUP_TEXT_DOMAIN),
746
+ 'inside' => __('Inside', SG_POPUP_TEXT_DOMAIN)
747
+ );
748
+
749
+ $data['popupInsertEventTypes'] = array(
750
+ 'inherit' => __('Inherit', SG_POPUP_TEXT_DOMAIN),
751
+ 'onLoad' => __('On load', SG_POPUP_TEXT_DOMAIN),
752
+ 'click' => __('On click', SG_POPUP_TEXT_DOMAIN),
753
+ 'hover' => __('On hover', SG_POPUP_TEXT_DOMAIN)
754
+ );
755
+
756
+ $data['subscriptionSuccessBehavior'] = array(
757
+ 'template' => array(
758
+ 'fieldWrapperAttr' => array(
759
+ 'class' => 'col-md-6 sgpb-choice-option-wrapper'
760
+ ),
761
+ 'labelAttr' => array(
762
+ 'class' => 'col-md-6 sgpb-choice-option-wrapper sgpb-sub-option-label'
763
+ ),
764
+ 'groupWrapperAttr' => array(
765
+ 'class' => 'row form-group sgpb-choice-wrapper'
766
+ )
767
+ ),
768
+ 'buttonPosition' => 'right',
769
+ 'nextNewLine' => true,
770
+ 'fields' => array(
771
+ array(
772
+ 'attr' => array(
773
+ 'type' => 'radio',
774
+ 'name' => 'sgpb-subs-success-behavior',
775
+ 'class' => 'subs-success-message',
776
+ 'data-attr-href' => 'subs-show-success-message',
777
+ 'value' => 'showMessage'
778
+ ),
779
+ 'label' => array(
780
+ 'name' => __('Success message', SG_POPUP_TEXT_DOMAIN).':'
781
+ )
782
+ ),
783
+ array(
784
+ 'attr' => array(
785
+ 'type' => 'radio',
786
+ 'name' => 'sgpb-subs-success-behavior',
787
+ 'class' => 'subs-redirect-to-URL',
788
+ 'data-attr-href' => 'subs-redirect-to-URL',
789
+ 'value' => 'redirectToURL'
790
+ ),
791
+ 'label' => array(
792
+ 'name' => __('Redirect to URL', SG_POPUP_TEXT_DOMAIN).':'
793
+ )
794
+ ),
795
+ array(
796
+ 'attr' => array(
797
+ 'type' => 'radio',
798
+ 'name' => 'sgpb-subs-success-behavior',
799
+ 'class' => 'subs-success-open-popup',
800
+ 'data-attr-href' => 'subs-open-popup',
801
+ 'value' => 'openPopup'
802
+ ),
803
+ 'label' => array(
804
+ 'name' => __('Open popup', SG_POPUP_TEXT_DOMAIN).':'
805
+ )
806
+ ),
807
+ array(
808
+ 'attr' => array(
809
+ 'type' => 'radio',
810
+ 'name' => 'sgpb-subs-success-behavior',
811
+ 'class' => 'subs-hide-popup',
812
+ 'value' => 'hidePopup'
813
+ ),
814
+ 'label' => array(
815
+ 'name' => __('Hide popup', SG_POPUP_TEXT_DOMAIN).':'
816
+ )
817
+ )
818
+ )
819
+ );
820
+
821
+ $data['buttonsType'] = array(
822
+ 'standard' => __('Standard', SG_POPUP_TEXT_DOMAIN),
823
+ 'box_count' => __('Box with count', SG_POPUP_TEXT_DOMAIN),
824
+ 'button_count' => __('Button with count', SG_POPUP_TEXT_DOMAIN),
825
+ 'button' => __('Button', SG_POPUP_TEXT_DOMAIN)
826
+ );
827
+
828
+ $data['backroundImageModes'] = array(
829
+ 'no-repeat' => __('None', SG_POPUP_TEXT_DOMAIN),
830
+ 'cover' => __('Cover', SG_POPUP_TEXT_DOMAIN),
831
+ 'contain' => __('Contain', SG_POPUP_TEXT_DOMAIN),
832
+ 'repeat' => __('Repeat', SG_POPUP_TEXT_DOMAIN)
833
+ );
834
+
835
+ $data['openAnimationEfects'] = array(
836
+ 'No effect' => __('None', SG_POPUP_TEXT_DOMAIN),
837
+ 'sgpb-flip' => __('Flip', SG_POPUP_TEXT_DOMAIN),
838
+ 'sgpb-shake' => __('Shake', SG_POPUP_TEXT_DOMAIN),
839
+ 'sgpb-wobble' => __('Wobble', SG_POPUP_TEXT_DOMAIN),
840
+ 'sgpb-swing' => __('Swing', SG_POPUP_TEXT_DOMAIN),
841
+ 'sgpb-flash' => __('Flash', SG_POPUP_TEXT_DOMAIN),
842
+ 'sgpb-bounce' => __('Bounce', SG_POPUP_TEXT_DOMAIN),
843
+ 'sgpb-bounceInRight' => __('BounceInRight', SG_POPUP_TEXT_DOMAIN),
844
+ 'sgpb-bounceIn' => __('BounceIn', SG_POPUP_TEXT_DOMAIN),
845
+ 'sgpb-pulse' => __('Pulse', SG_POPUP_TEXT_DOMAIN),
846
+ 'sgpb-rubberBand' => __('RubberBand', SG_POPUP_TEXT_DOMAIN),
847
+ 'sgpb-tada' => __('Tada', SG_POPUP_TEXT_DOMAIN),
848
+ 'sgpb-slideInUp' => __('SlideInUp', SG_POPUP_TEXT_DOMAIN),
849
+ 'sgpb-jello' => __('Jello', SG_POPUP_TEXT_DOMAIN),
850
+ 'sgpb-rotateIn' => __('RotateIn', SG_POPUP_TEXT_DOMAIN),
851
+ 'sgpb-fadeIn' => __('FadeIn', SG_POPUP_TEXT_DOMAIN)
852
+ );
853
+
854
+ $data['closeAnimationEfects'] = array(
855
+ 'No effect' => __('None', SG_POPUP_TEXT_DOMAIN),
856
+ 'sgpb-flipInX' => __('Flip', SG_POPUP_TEXT_DOMAIN),
857
+ 'sgpb-shake' => __('Shake', SG_POPUP_TEXT_DOMAIN),
858
+ 'sgpb-wobble' => __('Wobble', SG_POPUP_TEXT_DOMAIN),
859
+ 'sgpb-swing' => __('Swing', SG_POPUP_TEXT_DOMAIN),
860
+ 'sgpb-flash' => __('Flash', SG_POPUP_TEXT_DOMAIN),
861
+ 'sgpb-bounce' => __('Bounce', SG_POPUP_TEXT_DOMAIN),
862
+ 'sgpb-bounceOutLeft' => __('BounceOutLeft', SG_POPUP_TEXT_DOMAIN),
863
+ 'sgpb-bounceOut' => __('BounceOut', SG_POPUP_TEXT_DOMAIN),
864
+ 'sgpb-pulse' => __('Pulse', SG_POPUP_TEXT_DOMAIN),
865
+ 'sgpb-rubberBand' => __('RubberBand', SG_POPUP_TEXT_DOMAIN),
866
+ 'sgpb-tada' => __('Tada', SG_POPUP_TEXT_DOMAIN),
867
+ 'sgpb-slideOutUp' => __('SlideOutUp', SG_POPUP_TEXT_DOMAIN),
868
+ 'sgpb-jello' => __('Jello', SG_POPUP_TEXT_DOMAIN),
869
+ 'sgpb-rotateOut' => __('RotateOut', SG_POPUP_TEXT_DOMAIN),
870
+ 'sgpb-fadeOut' => __('FadeOut', SG_POPUP_TEXT_DOMAIN)
871
+ );
872
+
873
+ $data['floatingButtonPositionsCorner'] = array(
874
+ 'top-left' => __('Top left', SG_POPUP_TEXT_DOMAIN),
875
+ 'top-right' => __('Top right', SG_POPUP_TEXT_DOMAIN),
876
+ 'bottom-left' => __('Bottom left', SG_POPUP_TEXT_DOMAIN),
877
+ 'bottom-right' => __('Bottom right', SG_POPUP_TEXT_DOMAIN)
878
+ );
879
+
880
+ $data['floatingButtonPositionsBasic'] = array(
881
+ 'top-left' => __('Top left', SG_POPUP_TEXT_DOMAIN),
882
+ 'top-right' => __('Top right', SG_POPUP_TEXT_DOMAIN),
883
+ 'bottom-left' => __('Bottom left', SG_POPUP_TEXT_DOMAIN),
884
+ 'bottom-right' => __('Bottom right', SG_POPUP_TEXT_DOMAIN),
885
+ 'top-center' => __('Top center', SG_POPUP_TEXT_DOMAIN),
886
+ 'bottom-center' => __('Bottom center', SG_POPUP_TEXT_DOMAIN),
887
+ 'right-center' => __('Right center', SG_POPUP_TEXT_DOMAIN),
888
+ 'left-center' => __('Left center', SG_POPUP_TEXT_DOMAIN)
889
+ );
890
+
891
+ $data['floatingButtonStyle'] = array(
892
+ 'corner' => __('Corner', SG_POPUP_TEXT_DOMAIN),
893
+ 'basic' => __('Basic', SG_POPUP_TEXT_DOMAIN)
894
+ );
895
+
896
+ $data['userRoles'] = self::getAllUserRoles();
897
+
898
+ return $data;
899
+ }
900
+
901
+ public static function getAllUserRoles()
902
+ {
903
+ $rulesArray = array();
904
+ if (!function_exists('get_editable_roles')){
905
+ return $rulesArray;
906
+ }
907
+
908
+ $roles = get_editable_roles();
909
+ foreach ($roles as $roleName => $roleInfo) {
910
+ if ($roleName == 'administrator') {
911
+ continue;
912
+ }
913
+ $rulesArray[$roleName] = $roleName;
914
+ }
915
+
916
+ return $rulesArray;
917
+ }
918
+
919
+ public static function getClickActionOptions()
920
+ {
921
+ $settings = array(
922
+ 'defaultClickClassName' => __('Default', SG_POPUP_TEXT_DOMAIN),
923
+ 'clickActionCustomClass' => __('Custom class', SG_POPUP_TEXT_DOMAIN)
924
+ );
925
+
926
+ return $settings;
927
+ }
928
+
929
+ public static function getHoverActionOptions()
930
+ {
931
+ $settings = array(
932
+ 'defaultHoverClassName' => __('Default', SG_POPUP_TEXT_DOMAIN),
933
+ 'hoverActionCustomClass' => __('Custom class', SG_POPUP_TEXT_DOMAIN)
934
+ );
935
+
936
+ return $settings;
937
+ }
938
+
939
+ // proStartSilver
940
+ public static function getPopupDefaultTimeZone()
941
+ {
942
+ $timeZone = get_option('timezone_string');
943
+ if (!$timeZone) {
944
+ $timeZone = SG_POPUP_DEFAULT_TIME_ZONE;
945
+ }
946
+
947
+ return $timeZone;
948
+ }
949
+ // proEndSilver
950
+
951
+ // proStartGold
952
+ public static function getPopupTimeZone()
953
+ {
954
+ return array(
955
+ 'Pacific/Midway' => '(GMT-11:00) Midway',
956
+ 'Pacific/Niue' => '(GMT-11:00) Niue',
957
+ 'Pacific/Pago_Pago' => '(GMT-11:00) Pago Pago',
958
+ 'Pacific/Honolulu' => '(GMT-10:00) Hawaii Time',
959
+ 'Pacific/Rarotonga' => '(GMT-10:00) Rarotonga',
960
+ 'Pacific/Tahiti' => '(GMT-10:00) Tahiti',
961
+ 'Pacific/Marquesas' => '(GMT-09:30) Marquesas',
962
+ 'America/Anchorage' => '(GMT-09:00) Alaska Time',
963
+ 'Pacific/Gambier' => '(GMT-09:00) Gambier',
964
+ 'America/Los_Angeles' => '(GMT-08:00) Pacific Time',
965
+ 'America/Tijuana' => '(GMT-08:00) Pacific Time - Tijuana',
966
+ 'America/Vancouver' => '(GMT-08:00) Pacific Time - Vancouver',
967
+ 'America/Whitehorse' => '(GMT-08:00) Pacific Time - Whitehorse',
968
+ 'Pacific/Pitcairn' => '(GMT-08:00) Pitcairn',
969
+ 'America/Dawson_Creek' => '(GMT-07:00) Mountain Time - Dawson Creek',
970
+ 'America/Denver' => '(GMT-07:00) Mountain Time',
971
+ 'America/Edmonton' => '(GMT-07:00) Mountain Time - Edmonton',
972
+ 'America/Hermosillo' => '(GMT-07:00) Mountain Time - Hermosillo',
973
+ 'America/Mazatlan' => '(GMT-07:00) Mountain Time - Chihuahua, Mazatlan',
974
+ 'America/Phoenix' => '(GMT-07:00) Mountain Time - Arizona',
975
+ 'America/Yellowknife' => '(GMT-07:00) Mountain Time - Yellowknife',
976
+ 'America/Belize' => '(GMT-06:00) Belize',
977
+ 'America/Chicago' => '(GMT-06:00) Central Time',
978
+ 'America/Costa_Rica' => '(GMT-06:00) Costa Rica',
979
+ 'America/El_Salvador' => '(GMT-06:00) El Salvador',