PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.17.6
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.17.6
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.17.6, at includes/Admin/Admin_Bar.php

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