PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.4
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Admin / Admin_Bar.php

Admin_Bar.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.4, at includes/Admin/Admin_Bar.php

467 lines 18.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Admin;
4
5 /**
6 * The admin menu and page handler class
7 */
8
9 use BitCode\BitForm\Core\Form\FormHandler;
10 use BitCode\BitForm\Core\Integration\IntegrationHandler;
11 use BitCode\BitForm\Core\Integration\Integrations;
12 use BitCode\BitForm\Core\Util\DateTimeHelper;
13 use BitCode\BitForm\Core\Util\FileDownloadProvider;
14 use BitCode\BitForm\Core\Util\IpTool;
15 use BitCode\BitForm\Core\Util\Utilities;
16 use WP_Admin_Bar;
17
18 class Admin_Bar
19 {
20 private static $fonts_url = [
21 'https://fonts.googleapis.com/css2?family=Outfit:wght@100;300;400;500;600;700&display=swap&famildy=Roboto:wght@300;400;500&display=swap',
22 'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap',
23 ];
24
25 public function register()
26 {
27 add_action('in_admin_header', [$this, 'AdminNotices']);
28 add_action('admin_menu', [$this, 'AdminMenu']);
29 add_action('admin_enqueue_scripts', [$this, 'AdminAssets']);
30 add_filter('style_loader_tag', [$this, 'linkTagFilter'], 0, 3);
31 add_filter('script_loader_tag', [$this, 'scriptTagFilter'], 0, 3);
32 add_action('admin_bar_menu', [$this, 'AdminTopMenu'], 999);
33 add_action('admin_enqueue_scripts', [$this, 'bitforms_enqueue_admin_styles']);
34 }
35
36 /**
37 * Register the admin menu
38 *
39 * @return void
40 */
41 public function AdminMenu()
42 {
43 global $submenu;
44
45 $capability = apply_filters('bitforms_form_access_capability', 'manage_options');
46 $menuTitle = Utilities::isPro() ? 'Bit Form Pro' : 'Bit Form';
47 add_menu_page(
48 __('Bit Form - Most advanced form builder and entries management plugin', 'bit-form'),
49 $menuTitle,
50 $capability,
51 'bitform',
52 [$this, 'RootPage'],
53 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 163 163"><path fill="#fff" d="M106 0H57A57 57 0 000 57v49a57 57 0 0057 57h49a57 57 0 0057-57V57a57 57 0 00-57-57zM51 60v3l-1 59v12c0 5-3 8-8 6-2-1-3-4-3-6v-21-55a29 29 0 011-4 5 5 0 015-4h33a4 4 0 004-2c2-3 8-2 10-1a9 9 0 015 9 9 9 0 01-7 8c-3 1-6 0-9-3a3 3 0 00-1-1H51zm73 74c-6 5-12 6-20 6H72a8 8 0 01-4-1 5 5 0 01-2-6 5 5 0 015-3h35c11-1 20-10 21-20 0-11-8-20-18-23a6 6 0 00-1 0H78h-1v14l1 2h18a4 4 0 003-1c4-4 8-3 11-1 4 2 5 7 3 12-2 4-9 6-13 2a6 6 0 00-5-1H71c-3 0-5-2-5-6V82c0-4 1-5 5-6h17a21 21 0 0021-24c-1-9-8-16-16-18a25 25 0 00-6 0H46c-4 0-7-3-7-6s3-5 7-5h42a33 33 0 0132 23c2 11 0 20-6 29l-1 2 5 2c11 4 17 12 19 23 3 12-2 24-13 32z"/></svg>'),
54 56
55 );
56 if (current_user_can($capability)) {
57 $entriesCount = '';
58 if (self::countUnreadEntries()) {
59 $entriesCount = ' <span class="update-plugins">' . self::countUnreadEntries() . '</span>';
60 }
61
62 $submenu['bitform'][] = [__('All Forms', 'bit-form') . $entriesCount, $capability, 'admin.php?page=bitform#/'];
63 $submenu['bitform'][] = [__('Form Templates', 'bit-form') . '<span class="bf-template-new-badge">New</span>', $capability, 'admin.php?page=bitform#/form-templates'];
64 $submenu['bitform'][] = [__('App Settings', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/general'];
65 $submenu['bitform'][] = [__('Integrations', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/integrations'];
66 $submenu['bitform'][] = [__('SMTP', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/smtp'];
67 $submenu['bitform'][] = [__('PDF Setting', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/pdf'];
68 $submenu['bitform'][] = [__('CPT', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/cpt'];
69 $submenu['bitform'][] = [__('Bit Form API', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/api'];
70 $submenu['bitform'][] = [__('Payments', 'bit-form'), $capability, 'admin.php?page=bitform#/app-settings/payments'];
71 $submenu['bitform'][] = [__('Doc & Support', 'bit-form'), $capability, 'admin.php?page=bitform#/doc-support'];
72 if (!Utilities::isPro()) {
73 $submenu['bitform'][] = ['<span class="bf-pro-btn">' . __('Black Friday 74% OFF', 'bit-form') . '</span>', $capability, 'https://bit-form.com/#pricing', '_blank'];
74 }
75 }
76 }
77
78 public function AdminTopMenu(WP_Admin_Bar $wp_admin_bar)
79 {
80 $indicator = '';
81 if (self::countUnreadEntries()) {
82 $indicator = ' <div class="wp-core-ui wp-ui-notification bf-indicator-badge">' . self::countUnreadEntries() . '</div>';
83 }
84
85 $wp_admin_bar->add_node([
86 'id' => 'bitform',
87 'title' => 'Bit Form' . $indicator,
88 'href' => admin_url('admin.php?page=bitform'),
89 'meta' => [
90 'class' => 'bitform-admin-bar',
91 ],
92 ]);
93 $wp_admin_bar->add_node([
94 'id' => 'bitform-all-forms',
95 'parent' => 'bitform',
96 'title' => __('All Forms', 'bit-form') . $indicator,
97 'href' => admin_url('admin.php?page=bitform#/'),
98 ]);
99 $wp_admin_bar->add_node([
100 'id' => 'bitform-form-templates',
101 'parent' => 'bitform',
102 'title' => __('Form Templates', 'bit-form'),
103 'href' => admin_url('admin.php?page=bitform#/form-templates'),
104 ]);
105 $wp_admin_bar->add_node([
106 'id' => 'bitform-app-settings',
107 'parent' => 'bitform',
108 'title' => __('App Settings', 'bit-form'),
109 'href' => admin_url('admin.php?page=bitform#/app-settings/general'),
110 ]);
111 $wp_admin_bar->add_node([
112 'id' => 'bitform-smtp',
113 'parent' => 'bitform',
114 'title' => __('SMTP', 'bit-form'),
115 'href' => admin_url('admin.php?page=bitform#/app-settings/smtp'),
116 ]);
117 $wp_admin_bar->add_node([
118 'id' => 'bitform-pdf-setting',
119 'parent' => 'bitform',
120 'title' => __('PDF Setting', 'bit-form'),
121 'href' => admin_url('admin.php?page=bitform#/app-settings/pdf'),
122 ]);
123 $wp_admin_bar->add_node([
124 'id' => 'bitform-cpt',
125 'parent' => 'bitform',
126 'title' => __('CPT', 'bit-form'),
127 'href' => admin_url('admin.php?page=bitform#/app-settings/cpt'),
128 ]);
129 $wp_admin_bar->add_node([
130 'id' => 'bitform-api',
131 'parent' => 'bitform',
132 'title' => __('Bit Form API', 'bit-form'),
133 'href' => admin_url('admin.php?page=bitform#/app-settings/api'),
134 ]);
135 $wp_admin_bar->add_node([
136 'id' => 'bitform-payments',
137 'parent' => 'bitform',
138 'title' => __('Payments', 'bit-form'),
139 'href' => admin_url('admin.php?page=bitform#/app-settings/payments'),
140 ]);
141 }
142
143 public function getAllPages()
144 {
145 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
146 $allPages = [];
147 foreach ($pages as $pageKey => $pageDetails) {
148 $allPages[$pageKey]['title'] = $pageDetails->post_title;
149 $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
150 }
151 return $allPages;
152 }
153
154 /**
155 * Load the asset libraries
156 *
157 * @return void
158 */
159 public function AdminAssets($current_screen)
160 {
161 if (!strpos($current_screen, 'bitform')) {
162 return;
163 }
164 $parsed_url = wp_parse_url(get_admin_url());
165 $site_url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
166 $site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port'];
167 $base_path_admin = str_replace($site_url, '', get_admin_url());
168 // loading google fonts
169 wp_enqueue_style('googleapis-BITFORM-PRECONNECT', 'https://fonts.googleapis.com');
170 wp_enqueue_style('gstatic-BITFORM-PRECONNECT-CROSSORIGIN', 'https://fonts.gstatic.com');
171 foreach (self::$fonts_url as $i => $font_url) {
172 wp_enqueue_style('bf-font-' . $i, $font_url);
173 }
174
175 if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
176 wp_enqueue_script('vite-client-helper-BITFORM-MODULE', BIT_DEV_URL . '/config/devHotModule.js', [], null);
177 wp_enqueue_script('vite-client-BITFORM-MODULE', BIT_DEV_URL . '/@vite/client', [], null);
178 wp_enqueue_script('index-BITFORM-MODULE', BIT_DEV_URL . '/main.jsx', [], null);
179 }
180
181 if (!defined('BITAPPS_DEV') || (defined('BITAPPS_DEV') && !BITAPPS_DEV)) {
182 $build_hash = file_get_contents(BITFORMS_PLUGIN_DIR_PATH . '/build-hash.txt');
183 wp_enqueue_script('index-BITFORM-MODULE', BITFORMS_ASSET_URI . "/main-{$build_hash}.js", [], null);
184 wp_enqueue_style('bf-css', BITFORMS_ASSET_URI . "/main-{$build_hash}.css");
185 }
186
187 // if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
188 // wp_enqueue_script(
189 // 'bitforms-vendors',
190 // BITFORMS_ASSET_JS_URI . '/vendors-main.js',
191 // null,
192 // BITFORMS_VERSION,
193 // true
194 // );
195 // wp_enqueue_script(
196 // 'bitforms-runtime',
197 // BITFORMS_ASSET_JS_URI . '/runtime.js',
198 // null,
199 // BITFORMS_VERSION,
200 // true
201 // );
202 // wp_enqueue_script(
203 // 'bitforms-file',
204 // BITFORMS_ASSET_JS_URI . '/bitforms-file.js',
205 // ['bitforms-vendors', 'bitforms-runtime'],
206 // BITFORMS_VERSION,
207 // true
208 // );
209 // }
210
211 if (wp_script_is('wp-i18n')) {
212 $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'];
213 } else {
214 $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file'];
215 }
216 if (!defined('BITAPPS_DEV')) {
217 wp_enqueue_script(
218 'bitforms-admin-script',
219 BITFORMS_ASSET_JS_URI . '/index.js',
220 $deps,
221 BITFORMS_VERSION,
222 true
223 );
224 }
225 wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', null, false, true);
226
227 if (!wp_script_is('media-upload')) {
228 wp_enqueue_media();
229 }
230
231 $plugin_path = BITFORMS_ASSET_URI;
232
233 echo "<meta name='theme-color' content='#13233c' />";
234
235 if (defined('BITAPPS_DEV') && !BITAPPS_DEV) {
236 wp_enqueue_style(
237 'bitforms-styles',
238 BITFORMS_ASSET_URI . '/css/bitforms.css',
239 null,
240 BITFORMS_VERSION,
241 'screen'
242 );
243
244 wp_enqueue_style(
245 'bitforms-components-styles',
246 BITFORMS_ASSET_URI . '/css/components.css',
247 null,
248 BITFORMS_VERSION,
249 'screen'
250 );
251 }
252 $formHandler = FormHandler::getInstance();
253 $all_forms = $formHandler->admin->getAllForm();
254 $urlQuery = wp_parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
255 $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
256 $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
257 $ipTool = new IpTool();
258 $user_details = $ipTool->getUserDetail();
259 $integrationHandler = new IntegrationHandler(0, $user_details);
260 $allFormIntegrations = $integrationHandler->getAllIntegration('app');
261
262 $integraions = Integrations::getInstance();
263 $connectedIntegrationApps = $integraions->getConnectedIntegrationApp();
264
265 $allFormSettings = [];
266 if (!is_wp_error($allFormIntegrations)) {
267 $integCount = [];
268 foreach ($allFormIntegrations as $integration) {
269 $type = $integration->integration_type;
270 if (!is_null($type)) {
271 if (!isset($integCount[$type])) {
272 $integCount[$type] = 1;
273 } else {
274 $integCount[$type] += 1;
275 }
276 }
277 }
278 foreach ($allFormIntegrations as $integration) {
279 $type = $integration->integration_type;
280 if (!is_null($type)) {
281 $integrationDetails = json_decode($integration->integration_details);
282
283 if (!is_object($integrationDetails) || is_null($integrationDetails)) {
284 $integrationDetails = new \stdClass();
285 }
286 $integrationDetails->id = $integration->id;
287 if ($integCount[$type] > 1) {
288 if (!isset($allFormSettings[$type])) {
289 $allFormSettings[$type] = [];
290 }
291 array_push($allFormSettings[$type], $integrationDetails);
292 } else {
293 $allFormSettings[$type] = $integrationDetails;
294 }
295 }
296 }
297 }
298
299 if (!is_wp_error($connectedIntegrationApps)) {
300 $allFormSettings['connectedIntegrationApps'] = $connectedIntegrationApps;
301 }
302
303 $users = get_users(['fields' => ['ID', 'user_nicename', 'user_email', 'display_name']]);
304 $userMail = [];
305 $userNames = [];
306 foreach ($users as $key => $value) {
307 $userMail[$key]['label'] = !empty($value->display_name) ? $value->display_name : '';
308 $userMail[$key]['value'] = !empty($value->user_email) ? $value->user_email : '';
309 $userMail[$key]['id'] = $value->ID;
310 $userNames[$value->ID] = ['name' => $value->display_name, 'url' => get_edit_user_link($value->ID)];
311 }
312
313 $appSettings = get_option('bitform_app_settings', (object)[]);
314 $bits = [
315 'configs' => ['bf_separator' => BITFORMS_BF_SEPARATOR],
316 'nonce' => wp_create_nonce('bitforms_save'),
317 'isPro' => false,
318 'siteURL' => site_url(),
319 'assetsURL' => BITFORMS_ASSET_URI,
320 'baseURL' => $base_path_admin . 'admin.php?page=bitform#',
321 'baseDLURL' => $baseDLURL,
322 'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles',
323 'iconURL' => BITFORMS_UPLOAD_BASE_URL . '/icons',
324 'ajaxURL' => admin_url('admin-ajax.php'),
325 'allForms' => is_wp_error($all_forms) ? null : $all_forms,
326 'allPages' => is_wp_error($this->getAllPages()) ? [] : $this->getAllPages(),
327 'allFormSettings' => count($allFormSettings) > 0 ? $allFormSettings : (object)[],
328 'appSettings' => $appSettings,
329 'userMail' => !empty($userMail) ? $userMail : [],
330 'user' => (object) $userNames,
331 'dateFormat' => get_option('date_format'),
332 'timeFormat' => get_option('time_format'),
333 'timeZone' => DateTimeHelper::wp_timezone_string(),
334 'googleRedirectURL' => get_rest_url() . 'bitform/v1/google',
335 'oneDriveRedirectURL' => get_rest_url() . 'bitform/v1/oneDrive',
336 'zohoRedirectURL' => get_rest_url() . 'bitform/v1/zoho',
337 'userRoles' => get_editable_roles(),
338 'downloadedPdfFonts' => is_array(get_option('bitforms_pdf_fonts')) ? get_option('bitforms_pdf_fonts') : [],
339 'permission' => empty(get_option('bitforms_allow_tracking')) ? false : true,
340 'templatePath' => BITFORMS_ROOT_URI . '/static/templates',
341 'serverInfo' => ['php_version' => phpversion(), 'engine' => $_SERVER['SERVER_SOFTWARE'], 'wp_version' => get_bloginfo('version'), 'loaded_extensions' => get_loaded_extensions()],
342 ];
343
344 $isMigratingToV2 = get_option('bitforms_migrating_to_v2', false);
345 if ($isMigratingToV2) {
346 $bits['isMigratingToV2'] = $isMigratingToV2;
347 }
348
349 if (defined('BITFORMS_VERSION')) {
350 $bits['version'] = BITFORMS_VERSION;
351 }
352
353 $changelogVersion = get_option('bitforms_changelog_version', '0.0.0');
354 $bits['changelogVersion'] = $changelogVersion;
355
356 $hideAnnouncementModal = (bool) get_option('bitforms_hide_announcement', false);
357 $bits['hideAnnouncementModal'] = $hideAnnouncementModal;
358
359 $hideCashbackModal = (bool) get_option('bitforms_hide_cashback', false);
360 $bits['hideCashbackModal'] = $hideCashbackModal;
361
362 global $wpdb;
363 $hasV1FormTable = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}bitforms_form_v1'");
364 if ($hasV1FormTable) {
365 $bits['canRollbackToV1'] = true;
366 }
367
368 $bitforms = apply_filters(
369 'bitforms_localized_script',
370 $bits
371 );
372
373 $allowBitFormTranslation = apply_filters('bitforms_filter_allow_translation', true);
374 if ($allowBitFormTranslation && 'en_US' !== get_user_locale() && file_exists(BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php')) {
375 include_once BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php';
376 $bitforms['translations'] = $i18n_strings;
377
378 // Apply a filter to allow user/custom translations to modify the $bitforms translations
379 $bitforms['translations'] = apply_filters('bitform_filter_translations', $bitforms['translations']);
380 }
381 wp_localize_script('index-BITFORM-MODULE', 'bits', $bitforms);
382 // !BIT_DEV && wp_localize_script('bitforms-admin-script', 'bits', $bitforms);
383 // echo !BIT_DEV ? '' : "<script>console.log(window.bits=JSON.parse('" . str_replace("'", '', wp_json_encode($bitforms)) . "'))</script>";
384 // if (\function_exists('wp_set_script_translations'))
385 // wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages');
386 }
387
388 public function bitforms_enqueue_admin_styles()
389 {
390 wp_enqueue_style(
391 'bitforms-admin-styles',
392 BITFORMS_ROOT_URI . '/resources/admin.css',
393 [],
394 BITFORMS_VERSION,
395 'all'
396 );
397 }
398
399 /**
400 * Bitforms apps-root id provider
401 * @return void
402 */
403 public function RootPage()
404 {
405 require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php';
406 }
407
408 public function AdminNotices()
409 {
410 global $plugin_page;
411 $plugin_page = null === $plugin_page ? '' : $plugin_page;
412 if (false === strpos($plugin_page, 'bitform')) {
413 return;
414 }
415 remove_all_actions('admin_notices');
416 remove_all_actions('all_admin_notices');
417 }
418
419 /**
420 * Modify style tags
421 *
422 * @param string $html link tag
423 *
424 * @return string new link tag
425 */
426 public function linkTagFilter($html, $handle, $href)
427 {
428 $newTag = $html;
429 if (preg_match('/BITFORM-PRECONNECT/', $handle)) {
430 $newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preconnect"', $newTag);
431 }
432 if (preg_match('/BITFORM-PRELOAD/', $handle)) {
433 $newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preload"', $newTag);
434 }
435 if (preg_match('/BITFORM-CROSSORIGIN/', $handle)) {
436 $newTag = preg_replace('/<link /', '<link crossorigin ', $newTag);
437 }
438 if (preg_match('/BITFORM-SCRIPT/', $handle)) {
439 $newTag = preg_replace('/<link /', '<link as="script" ', $newTag);
440 }
441 return $newTag;
442 }
443
444 /**
445 * Modify script tags
446 *
447 * @param string $html script tag
448 *
449 * @return string new script tag
450 */
451 public function scriptTagFilter($html, $handle, $href)
452 {
453 $newTag = $html;
454 if (preg_match('/BITFORM-MODULE/', $handle)) {
455 $newTag = preg_replace('/<script /', '<script type="module" ', $newTag);
456 }
457 return $newTag;
458 }
459
460 private static function countUnreadEntries()
461 {
462 global $wpdb;
463 $unreadEntries = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}bitforms_form_entries WHERE status = 1");
464 return $unreadEntries;
465 }
466 }
467