| 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\Util\IpTool; |
| 10 |
use BitCode\BitForm\Core\Form\FormHandler; |
| 11 |
use BitCode\BitForm\Core\Util\FileDownloadProvider; |
| 12 |
use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 13 |
|
| 14 |
class Admin_Bar |
| 15 |
{ |
| 16 |
public function register() |
| 17 |
{ |
| 18 |
add_action('in_admin_header', array($this, 'AdminNotices')); |
| 19 |
add_action('admin_menu', array($this, 'AdminMenu')); |
| 20 |
add_action('admin_enqueue_scripts', array($this, 'AdminAssets')); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
* Register the admin menu |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public function AdminMenu() |
| 30 |
{ |
| 31 |
global $submenu; |
| 32 |
|
| 33 |
|
| 34 |
$capability = apply_filters('bitforms_form_access_capability', 'manage_options'); |
| 35 |
add_menu_page(__('Bit Form - wordpress form builder and database management system', 'bitform'), 'Bit Form', $capability, 'bitform', array($this, 'RootPage'), 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 163 163"><defs/><path fill="#13233c" 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); |
| 36 |
|
| 37 |
if (current_user_can($capability)) { |
| 38 |
$submenu['bitform'][] = array(__('All Forms', 'bitform'), $capability, 'admin.php?page=bitform#/'); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Load the asset libraries |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function AdminAssets($current_screen) |
| 48 |
{ |
| 49 |
if (!strpos($current_screen, 'bitform')) { |
| 50 |
return; |
| 51 |
} |
| 52 |
$parsed_url = parse_url(get_admin_url()); |
| 53 |
$site_url = $parsed_url['scheme'] . "://" . $parsed_url['host']; |
| 54 |
$site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port']; |
| 55 |
$base_path_admin = str_replace($site_url, null, get_admin_url()); |
| 56 |
wp_enqueue_script( |
| 57 |
'bitforms-vendors', |
| 58 |
BITFORMS_ASSET_URI . '/js/vendors-main.js', |
| 59 |
null, |
| 60 |
BITFORMS_VERSION, |
| 61 |
true |
| 62 |
); |
| 63 |
wp_enqueue_script( |
| 64 |
'bitforms-runtime', |
| 65 |
BITFORMS_ASSET_URI . '/js/runtime.js', |
| 66 |
null, |
| 67 |
BITFORMS_VERSION, |
| 68 |
true |
| 69 |
); |
| 70 |
wp_enqueue_script( |
| 71 |
'bitforms-file', |
| 72 |
BITFORMS_ASSET_URI . '/js/bitforms-file.js', |
| 73 |
array('bitforms-vendors', 'bitforms-runtime'), |
| 74 |
BITFORMS_VERSION, |
| 75 |
true |
| 76 |
); |
| 77 |
wp_enqueue_script( |
| 78 |
'bitforms-admin-script', |
| 79 |
BITFORMS_ASSET_URI . '/js/index.js', |
| 80 |
array('bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'), |
| 81 |
BITFORMS_VERSION, |
| 82 |
true |
| 83 |
); |
| 84 |
wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', null, false, true); |
| 85 |
|
| 86 |
if (!wp_script_is('media-upload')) { |
| 87 |
wp_enqueue_media(); |
| 88 |
} |
| 89 |
|
| 90 |
$plugin_path = BITFORMS_ASSET_URI; |
| 91 |
|
| 92 |
|
| 93 |
echo "<link rel='icon' type='image/svg+xml' href='{$plugin_path}/img/logo.svg' /> |
| 94 |
<link rel='alternate icon' type='image/png' href='{$plugin_path}/img/logo-256.png' /> |
| 95 |
<link rel='manifest' href='{$plugin_path}/js/manifest.json' /> |
| 96 |
<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'> |
| 97 |
<link rel='apple-touch-icon' href='{$plugin_path}/img/logo-256.png' /> |
| 98 |
<meta name='theme-color' content='#13233c' /> |
| 99 |
<meta name='description' content='Bit Form | Fast Modern Form builder for Wordpress' /> |
| 100 |
<meta name='keywords' content='Fast WP form, Bitform, Fast Modern Form builder for Wordpress'>"; |
| 101 |
|
| 102 |
wp_enqueue_style( |
| 103 |
'bitforms-styles', |
| 104 |
BITFORMS_ASSET_URI . '/css/bitforms.css', |
| 105 |
null, |
| 106 |
BITFORMS_VERSION, |
| 107 |
'screen' |
| 108 |
); |
| 109 |
|
| 110 |
wp_enqueue_style( |
| 111 |
'bitforms-components-styles', |
| 112 |
BITFORMS_ASSET_URI . '/css/components.css', |
| 113 |
null, |
| 114 |
BITFORMS_VERSION, |
| 115 |
'screen' |
| 116 |
); |
| 117 |
$formHandler = FormHandler::getInstance(); |
| 118 |
$all_forms = $formHandler->admin->getAllForm(); |
| 119 |
$urlQuery = parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY); |
| 120 |
$baseDLURL = FileDownloadProvider::getBaseDownloadURL(); |
| 121 |
$baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&'; |
| 122 |
$ipTool = new IpTool(); |
| 123 |
$user_details = $ipTool->getUserDetail(); |
| 124 |
$integrationHandler = new IntegrationHandler(0, $user_details); |
| 125 |
$allFormIntegrations = $integrationHandler->getAllIntegration('app'); |
| 126 |
$allFormSettings = array(); |
| 127 |
if (!is_wp_error($allFormIntegrations)) { |
| 128 |
foreach ($allFormIntegrations as $integration) { |
| 129 |
if (!is_null($integration->integration_type)) { |
| 130 |
$integrationDetails = json_decode($integration->integration_details); |
| 131 |
$integrationDetails->id = $integration->id; |
| 132 |
$allFormSettings[$integration->integration_type] = $integrationDetails; |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
$users = get_users(['fields' => ['user_nicename', 'user_email']]); |
| 138 |
$userMail = []; |
| 139 |
foreach ($users as $key => $value) { |
| 140 |
$userMail[$key]['label'] = !empty($value->user_nicename) ? $value->user_nicename : ''; |
| 141 |
$userMail[$key]['value'] = !empty($value->user_email) ? $value->user_email : ''; |
| 142 |
} |
| 143 |
$bitforms = apply_filters( |
| 144 |
'bitforms_localized_script', |
| 145 |
array( |
| 146 |
'nonce' => wp_create_nonce('bitforms_save'), |
| 147 |
'isPro' => false, |
| 148 |
'assetsURL' => BITFORMS_ASSET_URI, |
| 149 |
'baseURL' => $base_path_admin . 'admin.php?page=bitform#', |
| 150 |
'baseDLURL' => $baseDLURL, |
| 151 |
'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles', |
| 152 |
'ajaxURL' => admin_url('admin-ajax.php'), |
| 153 |
'allForms' => is_wp_error($all_forms) ? null : $all_forms, |
| 154 |
'allFormSettings' => $allFormSettings, |
| 155 |
'userMail' => !empty($userMail) ? $userMail : [], |
| 156 |
'dateFormat' => get_option('date_format'), |
| 157 |
'timeFormat' => get_option('time_format'), |
| 158 |
'timeZone' => wp_timezone_string(), |
| 159 |
) |
| 160 |
); |
| 161 |
wp_localize_script('bitforms-admin-script', 'bits', $bitforms); |
| 162 |
wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages'); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Bitforms apps-root id provider |
| 167 |
* @return void |
| 168 |
*/ |
| 169 |
public function RootPage() |
| 170 |
{ |
| 171 |
require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php'; |
| 172 |
} |
| 173 |
|
| 174 |
public function AdminNotices() |
| 175 |
{ |
| 176 |
remove_all_actions('admin_notices'); |
| 177 |
remove_all_actions('all_admin_notices'); |
| 178 |
} |
| 179 |
} |
| 180 |
|