PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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 2.10.2 All 137 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.13, at includes/Admin/Admin_Bar.php

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