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

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