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

330 lines 12.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
15 class Admin_Bar
16 {
17 private static $fonts_url = [
18 'https://fonts.googleapis.com/css2?family=Outfit:wght@100;300;400;500;600;700&display=swap&famildy=Roboto:wght@300;400;500&display=swap',
19 'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap',
20 ];
21
22 public function register()
23 {
24 add_action('in_admin_header', [$this, 'AdminNotices']);
25 add_action('admin_menu', [$this, 'AdminMenu']);
26 add_action('admin_enqueue_scripts', [$this, 'AdminAssets']);
27 add_filter('style_loader_tag', [$this, 'linkTagFilter'], 0, 3);
28 add_filter('script_loader_tag', [$this, 'scriptTagFilter'], 0, 3);
29 }
30
31 /**
32 * Register the admin menu
33 *
34 * @return void
35 */
36 public function AdminMenu()
37 {
38 global $submenu;
39
40 $capability = apply_filters('bitforms_form_access_capability', 'manage_options');
41 add_menu_page(
42 __('Bit Form - Most advanced form builder and database management system', 'bit-form'),
43 'Bit Form',
44 $capability,
45 'bitform',
46 [$this, 'RootPage'],
47 '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>'),
48 56
49 );
50 if (current_user_can($capability)) {
51 $submenu['bitform'][] = [__('All Forms', 'bit-form'), $capability, 'admin.php?page=bitform#/'];
52 }
53 }
54
55 public function getAllPages()
56 {
57 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
58 $allPages = [];
59 foreach ($pages as $pageKey => $pageDetails) {
60 $allPages[$pageKey]['title'] = $pageDetails->post_title;
61 $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
62 }
63 return $allPages;
64 }
65
66 /**
67 * Load the asset libraries
68 *
69 * @return void
70 */
71 public function AdminAssets($current_screen)
72 {
73 if (!strpos($current_screen, 'bitform')) {
74 return;
75 }
76 $parsed_url = parse_url(get_admin_url());
77 $site_url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
78 $site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port'];
79 $base_path_admin = str_replace($site_url, '', get_admin_url());
80 // loading google fonts
81 wp_enqueue_style('googleapis-BITFORM-PRECONNECT', 'https://fonts.googleapis.com');
82 wp_enqueue_style('gstatic-BITFORM-PRECONNECT-CROSSORIGIN', 'https://fonts.gstatic.com');
83 foreach (self::$fonts_url as $i => $font_url) {
84 wp_enqueue_style('bf-font-' . $i, $font_url);
85 }
86
87 if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
88 wp_enqueue_script('vite-client-helper-BITFORM-MODULE', BIT_DEV_URL . '/config/devHotModule.js', [], null);
89 wp_enqueue_script('vite-client-BITFORM-MODULE', BIT_DEV_URL . '/@vite/client', [], null);
90 wp_enqueue_script('index-BITFORM-MODULE', BIT_DEV_URL . '/main.jsx', [], null);
91 }
92
93 if (!defined('BITAPPS_DEV') || (defined('BITAPPS_DEV') && !BITAPPS_DEV)) {
94 $build_hash = file_get_contents(BITFORMS_PLUGIN_DIR_PATH . '/build-hash.txt');
95 wp_enqueue_script('index-BITFORM-MODULE', BITFORMS_ASSET_URI . "/main-{$build_hash}.js", [], null);
96 wp_enqueue_style('bf-css', BITFORMS_ASSET_URI . "/main-{$build_hash}.css");
97 }
98
99 // if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
100 // wp_enqueue_script(
101 // 'bitforms-vendors',
102 // BITFORMS_ASSET_JS_URI . '/vendors-main.js',
103 // null,
104 // BITFORMS_VERSION,
105 // true
106 // );
107 // wp_enqueue_script(
108 // 'bitforms-runtime',
109 // BITFORMS_ASSET_JS_URI . '/runtime.js',
110 // null,
111 // BITFORMS_VERSION,
112 // true
113 // );
114 // wp_enqueue_script(
115 // 'bitforms-file',
116 // BITFORMS_ASSET_JS_URI . '/bitforms-file.js',
117 // ['bitforms-vendors', 'bitforms-runtime'],
118 // BITFORMS_VERSION,
119 // true
120 // );
121 // }
122
123 if (wp_script_is('wp-i18n')) {
124 $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'];
125 } else {
126 $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file'];
127 }
128 if (!defined('BITAPPS_DEV')) {
129 wp_enqueue_script(
130 'bitforms-admin-script',
131 BITFORMS_ASSET_JS_URI . '/index.js',
132 $deps,
133 BITFORMS_VERSION,
134 true
135 );
136 }
137 wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', null, false, true);
138
139 if (!wp_script_is('media-upload')) {
140 wp_enqueue_media();
141 }
142
143 $plugin_path = BITFORMS_ASSET_URI;
144
145 echo "<meta name='theme-color' content='#13233c' />";
146
147 if (defined('BITAPPS_DEV') && !BITAPPS_DEV) {
148 wp_enqueue_style(
149 'bitforms-styles',
150 BITFORMS_ASSET_URI . '/css/bitforms.css',
151 null,
152 BITFORMS_VERSION,
153 'screen'
154 );
155
156 wp_enqueue_style(
157 'bitforms-components-styles',
158 BITFORMS_ASSET_URI . '/css/components.css',
159 null,
160 BITFORMS_VERSION,
161 'screen'
162 );
163 }
164 $formHandler = FormHandler::getInstance();
165 $all_forms = $formHandler->admin->getAllForm();
166 $urlQuery = parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
167 $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
168 $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
169 $ipTool = new IpTool();
170 $user_details = $ipTool->getUserDetail();
171 $integrationHandler = new IntegrationHandler(0, $user_details);
172 $allFormIntegrations = $integrationHandler->getAllIntegration('app');
173 $allFormSettings = [];
174 if (!is_wp_error($allFormIntegrations)) {
175 $integCount = [];
176 foreach ($allFormIntegrations as $integration) {
177 $type = $integration->integration_type;
178 if (!is_null($type)) {
179 if (!isset($integCount[$type])) {
180 $integCount[$type] = 1;
181 } else {
182 $integCount[$type] += 1;
183 }
184 }
185 }
186 foreach ($allFormIntegrations as $integration) {
187 $type = $integration->integration_type;
188 if (!is_null($type)) {
189 $integrationDetails = json_decode($integration->integration_details);
190 $integrationDetails->id = $integration->id;
191 if ($integCount[$type] > 1) {
192 if (!isset($allFormSettings[$type])) {
193 $allFormSettings[$type] = [];
194 }
195 array_push($allFormSettings[$type], $integrationDetails);
196 } else {
197 $allFormSettings[$type] = $integrationDetails;
198 }
199 }
200 }
201 }
202
203 $users = get_users(['fields' => ['ID', 'user_nicename', 'user_email', 'display_name']]);
204 $userMail = [];
205 $userNames = [];
206 foreach ($users as $key => $value) {
207 $userMail[$key]['label'] = !empty($value->display_name) ? $value->display_name : '';
208 $userMail[$key]['value'] = !empty($value->user_email) ? $value->user_email : '';
209 $userMail[$key]['id'] = $value->ID;
210 $userNames[$value->ID] = ['name' => $value->display_name, 'url' => get_edit_user_link($value->ID)];
211 }
212 $bits = [
213 'configs' => ['bf_separator' => BITFORMS_BF_SEPARATOR],
214 'nonce' => wp_create_nonce('bitforms_save'),
215 'isPro' => false,
216 'siteURL' => site_url(),
217 'assetsURL' => BITFORMS_ASSET_URI,
218 'baseURL' => $base_path_admin . 'admin.php?page=bitform#',
219 'baseDLURL' => $baseDLURL,
220 'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles',
221 'iconURL' => BITFORMS_UPLOAD_BASE_URL . '/icons',
222 'ajaxURL' => admin_url('admin-ajax.php'),
223 'allForms' => is_wp_error($all_forms) ? null : $all_forms,
224 'allPages' => is_wp_error($this->getAllPages()) ? [] : $this->getAllPages(),
225 'allFormSettings' => count($allFormSettings) > 0 ? $allFormSettings : (object)[],
226 'userMail' => !empty($userMail) ? $userMail : [],
227 'user' => (object) $userNames,
228 'dateFormat' => get_option('date_format'),
229 'timeFormat' => get_option('time_format'),
230 'timeZone' => DateTimeHelper::wp_timezone_string(),
231 'googleRedirectURL' => get_rest_url() . 'bitform/v1/google',
232 'oneDriveRedirectURL' => get_rest_url() . 'bitform/v1/oneDrive',
233 'zohoRedirectURL' => get_rest_url() . 'bitform/v1/zoho',
234 ];
235
236 $isMigratingToV2 = get_option('bitforms_migrating_to_v2', false);
237 if ($isMigratingToV2) {
238 $bits['isMigratingToV2'] = $isMigratingToV2;
239 }
240
241 if (defined('BITFORMS_VERSION')) {
242 $bits['version'] = BITFORMS_VERSION;
243 }
244
245 $changelogVersion = get_option('bitforms_changelog_version', '0.0.0');
246 $bits['changelogVersion'] = $changelogVersion;
247
248 global $wpdb;
249 $hasV1FormTable = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}bitforms_form_v1'");
250 if ($hasV1FormTable) {
251 $bits['canRollbackToV1'] = true;
252 }
253
254 $bitforms = apply_filters(
255 'bitforms_localized_script',
256 $bits
257 );
258 if ('en_US' !== get_locale() && file_exists(BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php')) {
259 include_once BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php';
260 $bitforms['translations'] = $i18n_strings;
261 }
262 wp_localize_script('index-BITFORM-MODULE', 'bits', $bitforms);
263 // !BIT_DEV && wp_localize_script('bitforms-admin-script', 'bits', $bitforms);
264 // echo !BIT_DEV ? '' : "<script>console.log(window.bits=JSON.parse('" . str_replace("'", '', json_encode($bitforms)) . "'))</script>";
265 // if (\function_exists('wp_set_script_translations'))
266 // wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages');
267 }
268
269 /**
270 * Bitforms apps-root id provider
271 * @return void
272 */
273 public function RootPage()
274 {
275 require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php';
276 }
277
278 public function AdminNotices()
279 {
280 global $plugin_page;
281 $plugin_page = null === $plugin_page ? '' : $plugin_page;
282 if (false === strpos($plugin_page, 'bitform')) {
283 return;
284 }
285 remove_all_actions('admin_notices');
286 remove_all_actions('all_admin_notices');
287 }
288
289 /**
290 * Modify style tags
291 *
292 * @param string $html link tag
293 *
294 * @return string new link tag
295 */
296 public function linkTagFilter($html, $handle, $href)
297 {
298 $newTag = $html;
299 if (preg_match('/BITFORM-PRECONNECT/', $handle)) {
300 $newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preconnect"', $newTag);
301 }
302 if (preg_match('/BITFORM-PRELOAD/', $handle)) {
303 $newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preload"', $newTag);
304 }
305 if (preg_match('/BITFORM-CROSSORIGIN/', $handle)) {
306 $newTag = preg_replace('/<link /', '<link crossorigin ', $newTag);
307 }
308 if (preg_match('/BITFORM-SCRIPT/', $handle)) {
309 $newTag = preg_replace('/<link /', '<link as="script" ', $newTag);
310 }
311 return $newTag;
312 }
313
314 /**
315 * Modify script tags
316 *
317 * @param string $html script tag
318 *
319 * @return string new script tag
320 */
321 public function scriptTagFilter($html, $handle, $href)
322 {
323 $newTag = $html;
324 if (preg_match('/BITFORM-MODULE/', $handle)) {
325 $newTag = preg_replace('/<script /', '<script type="module" ', $newTag);
326 }
327 return $newTag;
328 }
329 }
330