PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.0
3.3.1 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 All 138 releases
bit-form / v1 / includes / Admin / Admin_Bar.php

Admin_Bar.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.10.0, at v1/includes/Admin/Admin_Bar.php

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