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

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