'),
56
);
if (current_user_can($capability)) {
$submenu['bitform'][] = [__('All Forms', 'bit-form'), $capability, 'admin.php?page=bitform#/'];
}
}
public function getAllPages() {
$pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
$allPages = [];
foreach ($pages as $pageKey => $pageDetails) {
$allPages[$pageKey]['title'] = $pageDetails->post_title;
$allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
}
return $allPages;
}
/**
* Load the asset libraries
*
* @return void
*/
public function AdminAssets($current_screen) {
if (!strpos($current_screen, 'bitform')) {
return;
}
$parsed_url = parse_url(get_admin_url());
$site_url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
$site_url .= empty($parsed_url['port']) ? null : ':' . $parsed_url['port'];
$base_path_admin = str_replace($site_url, null, get_admin_url());
// loading google fonts
wp_enqueue_style('googleapis-PRECONNECT', 'https://fonts.googleapis.com');
wp_enqueue_style('gstatic-PRECONNECT-CROSSORIGIN', 'https://fonts.gstatic.com');
foreach (self::$fonts_url as $i => $font_url) {
wp_enqueue_style('bf-font-' . $i, $font_url);
}
if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
wp_enqueue_script('vite-client-helper-MODULE', BIT_DEV_URL . '/config/devHotModule.js', [], null);
wp_enqueue_script('vite-client-MODULE', BIT_DEV_URL . '/@vite/client', [], null);
wp_enqueue_script('index-MODULE', BIT_DEV_URL . '/main.jsx', [], null);
}
if (!defined('BITAPPS_DEV')) {
wp_enqueue_script('index-MODULE', BITFORMS_ASSET_URI . '/main.js', [], null);
wp_enqueue_style('bf-css', BITFORMS_ASSET_URI . '/main.css');
}
// if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
// wp_enqueue_script(
// 'bitforms-vendors',
// BITFORMS_ASSET_JS_URI . '/vendors-main.js',
// null,
// BITFORMS_VERSION,
// true
// );
// wp_enqueue_script(
// 'bitforms-runtime',
// BITFORMS_ASSET_JS_URI . '/runtime.js',
// null,
// BITFORMS_VERSION,
// true
// );
// wp_enqueue_script(
// 'bitforms-file',
// BITFORMS_ASSET_JS_URI . '/bitforms-file.js',
// ['bitforms-vendors', 'bitforms-runtime'],
// BITFORMS_VERSION,
// true
// );
// }
if (wp_script_is('wp-i18n')) {
$deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file', 'wp-i18n'];
} else {
$deps = ['bitforms-vendors', 'bitforms-runtime', 'bitforms-file'];
}
if (!defined('BITAPPS_DEV')) {
wp_enqueue_script(
'bitforms-admin-script',
BITFORMS_ASSET_JS_URI . '/index.js',
$deps,
BITFORMS_VERSION,
true
);
}
wp_enqueue_script('tinymce_js', includes_url('js/tinymce/') . 'wp-tinymce.php', null, false, true);
if (!wp_script_is('media-upload')) {
wp_enqueue_media();
}
$plugin_path = BITFORMS_ASSET_URI;
echo "";
if (defined('BITAPPS_DEV') && !BITAPPS_DEV) {
wp_enqueue_style(
'bitforms-styles',
BITFORMS_ASSET_URI . '/css/bitforms.css',
null,
BITFORMS_VERSION,
'screen'
);
wp_enqueue_style(
'bitforms-components-styles',
BITFORMS_ASSET_URI . '/css/components.css',
null,
BITFORMS_VERSION,
'screen'
);
}
$formHandler = FormHandler::getInstance();
$all_forms = $formHandler->admin->getAllForm();
$urlQuery = parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY);
$baseDLURL = FileDownloadProvider::getBaseDownloadURL();
$baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&';
$ipTool = new IpTool();
$user_details = $ipTool->getUserDetail();
$integrationHandler = new IntegrationHandler(0, $user_details);
$allFormIntegrations = $integrationHandler->getAllIntegration('app');
$allFormSettings = [];
if (!is_wp_error($allFormIntegrations)) {
$integCount = [];
foreach ($allFormIntegrations as $integration) {
$type = $integration->integration_type;
if (!is_null($type)) {
if (!isset($integCount[$type])) {
$integCount[$type] = 1;
} else {
$integCount[$type] += 1;
}
}
}
foreach ($allFormIntegrations as $integration) {
$type = $integration->integration_type;
if (!is_null($type)) {
$integrationDetails = json_decode($integration->integration_details);
$integrationDetails->id = $integration->id;
if ($integCount[$type] > 1) {
if (!isset($allFormSettings[$type])) {
$allFormSettings[$type] = [];
}
array_push($allFormSettings[$type], $integrationDetails);
} else {
$allFormSettings[$type] = $integrationDetails;
}
}
}
}
$users = get_users(['fields' => ['ID', 'user_nicename', 'user_email', 'display_name']]);
$userMail = [];
$userNames = [];
foreach ($users as $key => $value) {
$userMail[$key]['label'] = !empty($value->display_name) ? $value->display_name : '';
$userMail[$key]['value'] = !empty($value->user_email) ? $value->user_email : '';
$userMail[$key]['id'] = $value->ID;
$userNames[$value->ID] = ['name' => $value->display_name, 'url' => get_edit_user_link($value->ID)];
}
$bits = [
'configs' => ['bf_separator' => BITFORMS_BF_SEPARATOR],
'nonce' => wp_create_nonce('bitforms_save'),
'isPro' => false,
'siteURL' => site_url(),
'assetsURL' => BITFORMS_ASSET_URI,
'baseURL' => $base_path_admin . 'admin.php?page=bitform#',
'baseDLURL' => $baseDLURL,
'styleURL' => BITFORMS_UPLOAD_BASE_URL . '/form-styles',
'iconURL' => BITFORMS_UPLOAD_BASE_URL . '/icons',
'ajaxURL' => admin_url('admin-ajax.php'),
'allForms' => is_wp_error($all_forms) ? null : $all_forms,
'allPages' => is_wp_error($this->getAllPages()) ? [] : $this->getAllPages(),
'allFormSettings' => $allFormSettings,
'userMail' => !empty($userMail) ? $userMail : [],
'user' => (object) $userNames,
'dateFormat' => get_option('date_format'),
'timeFormat' => get_option('time_format'),
'timeZone' => DateTimeHelper::wp_timezone_string(),
'googleRedirectURL' => get_rest_url() . 'bitform/v1/google',
'oneDriveRedirectURL' => get_rest_url() . 'bitform/v1/oneDrive',
'zohoRedirectURL' => get_rest_url() . 'bitform/v1/zoho'
];
$isMigratingToV2 = get_option('bitforms_migrating_to_v2', false);
if ($isMigratingToV2) {
$bits['isMigratingToV2'] = $isMigratingToV2;
}
global $wpdb;
$hasV1FormTable = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}bitforms_form_v1'");
if ($hasV1FormTable) {
$bits['canRollbackToV1'] = true;
}
$bitforms = apply_filters(
'bitforms_localized_script',
$bits
);
if ('en_US' !== get_locale() && file_exists(BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php')) {
include_once BITFORMS_PLUGIN_DIR_PATH . '/languages/generatedString.php';
$bitforms['translations'] = $bitform_i18n_strings;
}
wp_localize_script('index-MODULE', 'bits', $bitforms);
// !BIT_DEV && wp_localize_script('bitforms-admin-script', 'bits', $bitforms);
// echo !BIT_DEV ? '' : "";
// if (\function_exists('wp_set_script_translations'))
// wp_set_script_translations('bitforms-admin-script', 'bitform', BITFORMS_PLUGIN_DIR_PATH . 'languages');
}
/**
* Bitforms apps-root id provider
* @return void
*/
public function RootPage() {
require_once BITFORMS_PLUGIN_DIR_PATH . '/views/view-root.php';
}
public function AdminNotices() {
global $plugin_page;
$plugin_page = null === $plugin_page ? '' : $plugin_page;
if (false === strpos($plugin_page, 'bitform')) {
return;
}
remove_all_actions('admin_notices');
remove_all_actions('all_admin_notices');
}
/**
* Modify style tags
*
* @param string $html link tag
*
* @return string new link tag
*/
public function linkTagFilter($html, $handle, $href) {
$newTag = $html;
if (str_contains($handle, 'PRECONNECT')) {
$newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preconnect"', $newTag);
}
if (str_contains($handle, 'PRELOAD')) {
$newTag = preg_replace('/rel=("|\')stylesheet("|\')/', 'rel="preload"', $newTag);
}
if (str_contains($handle, 'CROSSORIGIN')) {
$newTag = preg_replace('/