| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Util; |
| 4 |
|
| 5 |
final class FrontendHelpers { |
| 6 |
public static $pageBuilderList = [ |
| 7 |
'action' => 'elementor', // elementor |
| 8 |
'vcv-action' => 'frontend', // visual composer |
| 9 |
'fl_builder' => '', // beaver builder |
| 10 |
'action' => 'in-front-editor', // brizy |
| 11 |
'ct_builder' => 'true', // oxygen |
| 12 |
'breakdance' => 'builder', // breakdance |
| 13 |
'lc_action_launch_editing' => '1', // live canvas |
| 14 |
'vc_action' => 'vc_inline', // wp bakery |
| 15 |
'et_fb' => '1', // divi |
| 16 |
'et_pb_preview' => 'true', // divi |
| 17 |
'bricks' => 'run', // bricks |
| 18 |
'action' => 'architect', // thrive architect |
| 19 |
'page' => 'livecomposer_editor', // live composer |
| 20 |
]; |
| 21 |
|
| 22 |
public static function getFormIdsFromPost() { |
| 23 |
global $post; |
| 24 |
global $wpdb; |
| 25 |
global $bfUniqFormIds; |
| 26 |
|
| 27 |
if (empty($post)) { |
| 28 |
$bfUniqFormIds = []; |
| 29 |
return; |
| 30 |
}; |
| 31 |
$postId = $post->ID; |
| 32 |
$formsIds = []; |
| 33 |
// $bfMetaValues = $wpdb->get_results("SELECT pmt1.meta_value FROM wp_postmeta pmt1 LEFT OUTER JOIN wp_postmeta pmt2 ON (pmt1.meta_id < pmt2.meta_id AND pmt1.meta_key = pmt2.meta_key) WHERE pmt2.meta_id IS NULL AND pmt1.post_id = {$postId} AND pmt1.meta_value LIKE '%[bitform%' ORDER BY pmt1.meta_id DESC"); |
| 34 |
$bfMetaValues = $wpdb->get_results('SELECT meta_value FROM `' . $wpdb->postmeta . "` WHERE `post_id`={$post->ID} AND meta_value LIKE '%[bitform id=%'"); |
| 35 |
$postContent = $post->post_content; |
| 36 |
$bfMetaValues[] = (object) ['meta_value' => $postContent]; |
| 37 |
foreach ($bfMetaValues as $bfShortcut) { |
| 38 |
$meta_value = $bfShortcut->meta_value; |
| 39 |
$meta_value = str_replace('\\', '', $meta_value); |
| 40 |
\preg_match_all("/\[bitform\s+id\s*=\s*('|\")\s*(\d+)\s*('|\")\]/", $meta_value, $shortCode); |
| 41 |
$shortCodes = $shortCode[2]; |
| 42 |
if (!empty($shortCodes)) { |
| 43 |
$formsIds = array_merge($formsIds, $shortCodes); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
$bfUniqFormIds = array_unique($formsIds); |
| 48 |
|
| 49 |
return $bfUniqFormIds; |
| 50 |
} |
| 51 |
|
| 52 |
public static function isPageBuilder() { |
| 53 |
global $bfMultipleFormsExists; |
| 54 |
global $isPageBuilder; |
| 55 |
|
| 56 |
$current_url = $_SERVER['REQUEST_URI']; |
| 57 |
$isAdminSide = false !== strpos($current_url, '/wp-admin/'); |
| 58 |
|
| 59 |
$isPageBuilder = get_transient('is_page_builder'); |
| 60 |
$isPageBuilderSessionExists = false !== $isPageBuilder; |
| 61 |
if ($isAdminSide) { |
| 62 |
$isPageBuilder = true; |
| 63 |
} |
| 64 |
|
| 65 |
if ($isPageBuilder) { |
| 66 |
$bfMultipleFormsExists = true; |
| 67 |
return true; |
| 68 |
} |
| 69 |
|
| 70 |
if ($isPageBuilderSessionExists) { |
| 71 |
set_transient('is_page_builder', $isPageBuilder); |
| 72 |
} |
| 73 |
|
| 74 |
self::getFormIdsFromPost(); |
| 75 |
global $bfUniqFormIds; |
| 76 |
$bfMultipleFormsExists = $isPageBuilder ? true : count($bfUniqFormIds) > 1; |
| 77 |
return $isPageBuilder; |
| 78 |
} |
| 79 |
|
| 80 |
public static function parseQueryParams($url) { |
| 81 |
$url_components = parse_url($url); |
| 82 |
if (isset($url_components['query'])) { |
| 83 |
parse_str($url_components['query'], $queryParams); |
| 84 |
return $queryParams; |
| 85 |
} |
| 86 |
return []; |
| 87 |
} |
| 88 |
|
| 89 |
public static function handleBfFormIdsSession($formId = null) { |
| 90 |
global $bfFrontendFormIds; |
| 91 |
$bfFrontendFormIds = get_transient('bf_frontend_form_ids'); |
| 92 |
if (empty($bfFrontendFormIds)) { |
| 93 |
$bfFrontendFormIds = []; |
| 94 |
} |
| 95 |
if (is_null($formId)) { |
| 96 |
return $bfFrontendFormIds; |
| 97 |
} |
| 98 |
$bfFrontendFormIds[] = $formId; |
| 99 |
set_transient('bf_frontend_form_ids', $bfFrontendFormIds); |
| 100 |
} |
| 101 |
} |
| 102 |
|