| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | final class FrontendHelpers |
| 8 | 8 | { |
| 9 | 9 | public static $isPageBuilder = false; |
| 10 | 10 | public static $bfFrontendFormIds = []; |
| 11 | + public static $bfFrontendViewIds = []; | |
| 11 | 12 | public static $bfFormIdsFromPost = []; |
| 13 | + public static $bfViewIdsFromPost = []; | |
| 12 | 14 | |
| 13 | 15 | public static $pageBuilderQueryParamsList = [ |
| 14 | 16 | 'et_pb_preview' => 'true', // divi |
| 15 | 17 | 'vc_editable' => 'true', // wp bakery |
| @@ -33,10 +35,14 @@ | ||
| 33 | 35 | return []; |
| 34 | 36 | } |
| 35 | 37 | $postId = $post->ID; |
| 36 | 38 | $shortcodeFormIds = []; |
| 37 | - // $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"); | |
| 38 | - $bfMetaValues = $wpdb->get_results('SELECT meta_value FROM `' . $wpdb->postmeta . "` WHERE `post_id`={$postId}"); | |
| 39 | + $bfMetaValues = $wpdb->get_results( | |
| 40 | + $wpdb->prepare( | |
| 41 | + 'SELECT meta_value FROM `' . $wpdb->postmeta . '` WHERE `post_id`=%d', | |
| 42 | + $postId | |
| 43 | + ) | |
| 44 | + ); | |
| 39 | 45 | $postContent = $post->post_content; |
| 40 | 46 | $bfMetaValues[] = (object) ['meta_value' => $postContent]; |
| 41 | 47 | foreach ($bfMetaValues as $bfShortcut) { |
| 42 | 48 | $meta_value = (is_string($bfShortcut->meta_value) && !empty($bfShortcut->meta_value)) ? $bfShortcut->meta_value : ''; |
| @@ -55,8 +61,40 @@ | ||
| 55 | 61 | |
| 56 | 62 | return $ids; |
| 57 | 63 | } |
| 58 | 64 | |
| 65 | + public static function getViewIdsFromPost() | |
| 66 | + { | |
| 67 | + global $post; | |
| 68 | + global $wpdb; | |
| 69 | + if (empty($post)) { | |
| 70 | + self::$bfViewIdsFromPost = []; | |
| 71 | + return []; | |
| 72 | + } | |
| 73 | + $postId = $post->ID; | |
| 74 | + $shortcodeViewIds = []; | |
| 75 | + $bfMetaValues = $wpdb->get_results('SELECT meta_value FROM `' . $wpdb->postmeta . "` WHERE `post_id`={$postId}"); | |
| 76 | + $postContent = $post->post_content; | |
| 77 | + | |
| 78 | + $bfMetaValues[] = (object) ['meta_value' => $postContent]; | |
| 79 | + foreach ($bfMetaValues as $bfShortcut) { | |
| 80 | + $meta_value = (is_string($bfShortcut->meta_value) && !empty($bfShortcut->meta_value)) ? $bfShortcut->meta_value : ''; | |
| 81 | + $shortcodeIds = self::getViewShortCodeIds($meta_value); | |
| 82 | + $shortcodeViewIds = array_merge($shortcodeViewIds, $shortcodeIds); | |
| 83 | + } | |
| 84 | + | |
| 85 | + self::$bfViewIdsFromPost = $shortcodeViewIds; | |
| 86 | + return $shortcodeViewIds; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public static function getViewShortCodeIds($content = '') | |
| 90 | + { | |
| 91 | + \preg_match_all("/\[bitform-view\s+id\s*=\s*('|\")\s*(\d+)\s*('|\")\]/", $content, $shortCode); | |
| 92 | + $ids = $shortCode[2]; | |
| 93 | + | |
| 94 | + return $ids; | |
| 95 | + } | |
| 96 | + | |
| 59 | 97 | public static function checkIsPageBuilder($srvr) |
| 60 | 98 | { |
| 61 | 99 | if (is_admin()) { |
| 62 | 100 | self::$isPageBuilder = true; |
| @@ -164,8 +202,16 @@ | ||
| 164 | 202 | $bfFrontendFormIds = self::$bfFrontendFormIds; |
| 165 | 203 | $bfFormIdsFromPost = self::getFormIdsFromPost(); |
| 166 | 204 | $allFormIds = array_merge($bfFrontendFormIds, $bfFormIdsFromPost); |
| 167 | 205 | return $allFormIds; |
| 206 | + } | |
| 207 | + | |
| 208 | + public static function getAllViewIdsInPage() | |
| 209 | + { | |
| 210 | + $bfFrontendViewIds = self::$bfFrontendViewIds; | |
| 211 | + $bfViewIdsFromPost = self::getViewIdsFromPost(); | |
| 212 | + $allViewIds = array_merge($bfFrontendViewIds, $bfViewIdsFromPost); | |
| 213 | + return $allViewIds; | |
| 168 | 214 | } |
| 169 | 215 | |
| 170 | 216 | public static function getAllUniqFormIdsInPage() |
| 171 | 217 | { |