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

240 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BitCode\BitForm\Admin;
3
4 /**
5 * The admin menu and page handler class
6 */
7
8 use BitCode\BitForm\Core\Form\FormHandler;
9 use BitCode\BitForm\Core\Integration\IntegrationHandler;
10 use BitCode\BitForm\Core\Util\DateTimeHelper;
11 use BitCode\BitForm\Core\Util\FileDownloadProvider;
12 use BitCode\BitForm\Core\Util\IpTool;
13
14 class Admin_Bar
15 {
16 public function register()
17 {
18 add_action('in_admin_header', [$this, 'AdminNotices']);
19 add_action('admin_menu', [$this, 'AdminMenu']);
20 add_action('admin_enqueue_scripts', [$this, 'AdminAssets']);
21 }
22
23 /**
24 * Register the admin menu
25 *
26 * @return void
27 */
28 public function AdminMenu()
29 {
30 global $submenu;
31
32 $capability = apply_filters('bitforms_form_access_capability', 'manage_options');
33 add_menu_page(__('Bit Form - wordpress form builder and database management system', 'bit-form'), 'Bit Form', $capability, 'bitform', [$this, 'RootPage'], '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>'), 56);
34
35 if (current_user_can($capability)) {
36 $submenu['bitform'][] = [__('All Forms', 'bit-form'), $capability, 'admin.php?page=bitform#/'];
37 }
38 }
39
40 public function getAllPages()
41 {
42 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
43 $allPages = [];
44 foreach ($pages as $pageKey => $pageDetails) {
45 $allPages[$pageKey]['title'] = $pageDetails->post_title;
46 $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
47 }
48 return $allPages;
49 }
50
51 /**
52 * Load the asset libraries
53 *
54 * @return void
55 */
56 public function AdminAssets($current_screen)
57 {
58 if (!strpos($current_screen, 'bitform')) {
59 return;
60 }
61 $parsed_url = parse_url(get_admin_url());
62 $site_url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
63 $site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port'];
64 $base_path_admin = str_replace($site_url, '', get_admin_url());
65
66 if (!BIT_DEV) {
67 wp_enqueue_script(
68 'bitforms-vendors',
69 BITFORMS_ASSET_JS_URI . '/vendors-main.js',
70 null,
71 BITFORMS_VERSION,
72 true
73 );
74 wp_enqueue_script(
75 'bitforms-runtime',
76 BITFORMS_ASSET_JS_URI . '/runtime.js',
77 null,
78 BITFORMS_VERSION,
79 true
80 );
81 wp_enqueue_script(
82 'bitforms-file',
83 BITFORMS_ASSET_JS_URI . '/bitforms-file.js',
84 ['bitforms-vendors', 'bitforms-runtime'],
85 BITFORMS_VERSION,
86 true
87 );
88 }
89
90 if (wp_script_is('wp-i18n')) {
91 $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'];
92 } else {
93 $deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file'];
94 }
95 if (!BIT_DEV) {
96 wp_enqueue_script(
97 'bitforms-admin-script',
98 BITFORMS_ASSET_JS_URI . '/index.js',
99 $deps,
100 BITFORMS_VERSION,
101 true
102 );
103 }
104 wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', null, false, true);
105
106 if (!wp_script_is('media-upload')) {
107 wp_enqueue_media();
108 }
109
110 $plugin_path = BITFORMS_ASSET_URI;
111
112 echo "<link rel='manifest' href='{$plugin_path}/js/manifest.json' />
113 <link rel='preconnect' href='https://fonts.gstatic.com'>
114 <link rel='stylesheet preload prefetch' type='text/css' crossorigin='anonymous' as='style' crossorigin='anonymous' href='https://fonts.googleapis.com/css2?family=Montserrat:wght@100;300;400;500;600;700;800&display=swap'>
115 <link href='https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap' rel='stylesheet'>
116 <meta name='theme-color' content='#13233c' />
117 <meta name='description' content='Bit Form | Fast Modern Form builder for Wordpress' />
118 <meta name='keywords' content='Fastest Wordpress form builder, Bitform, Fast Modern Form builder for Wordpress'>";
119
120 if (!BIT_DEV) {
121 wp_enqueue_style(
122 'bitforms-styles',
123 BITFORMS_ASSET_URI . '/css/bitforms.css',
124 null,
125 BITFORMS_VERSION,
126 'screen'
127 );
128
129 wp_enqueue_style(
130 'bitforms-components-styles',
131 BITFORMS_ASSET_URI . '/css/components.css',
132 null,
133 BITFORMS_VERSION,
134 'screen'
135 );
136 }
137 $formHandler = FormHandler::getInstance();
138 $all_forms = $formHandler->admin->getAllForm();
139 $urlQuery = parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
140 $baseDLURL = FileDownloadProvider::getBaseDownloadURL();
141 $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
142 $ipTool = new IpTool();
143 $user_details = $ipTool->getUserDetail();
144 $integrationHandler = new IntegrationHandler(0, $user_details);
145 $allFormIntegrations = $integrationHandler->getAllIntegration('app');
146 $allFormSettings = [];
147 if (!is_wp_error($allFormIntegrations)) {
148 $integCount = [];
149 foreach ($allFormIntegrations as $integration) {
150 $type = $integration->integration_type;
151 if (!is_null($type)) {
152 if (!isset($integCount[$type])) {
153 $integCount[$type] = 1;
154 } else {
155 $integCount[$type] += 1;
156 }
157 }
158 }
159 foreach ($allFormIntegrations as $integration) {
160 $type = $integration->integration_type;
161 if (!is_null($type)) {
162 $integrationDetails = json_decode($integration->integration_details);
163 $integrationDetails->id = $integration->id;
164 if ($integCount[$type] > 1) {
165 if (!isset($allFormSettings[$type])) {
166 $allFormSettings[$type] = [];
167 }
168 array_push($allFormSettings[$type], $integrationDetails);
169 } else {
170 $allFormSettings[$type] = $integrationDetails;
171 }
172 }
173 }
174 }
175
176 $users = get_users(['fields' => ['ID', 'user_nicename', 'user_email', 'display_name']]);
177 $userMail = [];
178 $userNames = [];
179 foreach ($users as $key => $value) {
180 $userMail[$key]['label'] = !empty($value->display_name) ? $value->display_name : '';
181 $userMail[$key]['value'] = !empty($value->user_email) ? $value->user_email : '';
182 $userMail[$key]['id'] = $value->ID;
183 $userNames[$value->ID] = ['name' => $value->display_name, 'url' => get_edit_user_link($value->ID)];
184 }
185 $bitforms = apply_filters(
186 'bitforms_localized_script',
187 [
188 'nonce' => wp_create_nonce('bitforms_save'),
189 'isPro' => false,
190 'siteURL' => site_url(),
191 'assetsURL' => BITFORMS_ASSET_URI,
192 'baseURL' => $base_path_admin . 'admin.php?page=bitform#',
193 'baseDLURL' => $baseDLURL,
194 'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles',
195 'ajaxURL' => admin_url('admin-ajax.php'),
196 'allForms' => is_wp_error($all_forms) ? null : $all_forms,
197 'allPages' => is_wp_error($this->getAllPages()) ? [] : $this->getAllPages(),
198 'allFormSettings' => $allFormSettings,
199 'userMail' => !empty($userMail) ? $userMail : [],
200 'user' => (object) $userNames,
201 'dateFormat' => get_option('date_format'),
202 'timeFormat' => get_option('time_format'),
203 'timeZone' => DateTimeHelper::wp_timezone_string(),
204 'googleRedirectURL' => get_rest_url() . 'bitform/v1/google',
205 'oneDriveRedirectURL' => get_rest_url() . 'bitform/v1/oneDrive',
206 'zohoRedirectURL' => get_rest_url() . 'bitform/v1/zoho',
207
208 ]
209 );
210 if (get_locale() !== 'en_US') {
211 include_once BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php';
212 $bitforms['translations'] = $bitform_i18n_strings;
213 }
214 !BIT_DEV && wp_localize_script('bitforms-admin-script', 'bits', $bitforms);
215 echo !BIT_DEV ? '' : "<script>console.log(window.bits=JSON.parse('" . str_replace("'", '', json_encode($bitforms)) . "'))</script>";
216 // if (\function_exists('wp_set_script_translations'))
217 // wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages');
218 }
219
220 /**
221 * Bitforms apps-root id provider
222 * @return void
223 */
224 public function RootPage()
225 {
226 require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php';
227 }
228
229 public function AdminNotices()
230 {
231 global $plugin_page;
232 $plugin_page = $plugin_page === null ? '' : $plugin_page;
233 if (strpos($plugin_page, 'bitform') === false) {
234 return;
235 }
236 remove_all_actions('admin_notices');
237 remove_all_actions('all_admin_notices');
238 }
239 }
240