contact-forms
1 year ago
contact-forms.php
1 year ago
fluent-booking.php
10 months ago
index.php
1 month ago
newsletters.php
1 year ago
recommendation-page-post-type.php
1 year ago
recommendations-trait.php
3 months ago
siteleads.php
3 months ago
recommendations-trait.php
201 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Kubio\Blocks; |
| 5 | |
| 6 | use IlluminateAgnostic\Arr\Support\Arr; |
| 7 | use Kubio\AssetsDependencyInjector; |
| 8 | use Kubio\Core\LodashBasic; |
| 9 | use Kubio\Core\Utils; |
| 10 | |
| 11 | trait RecommendationsTrait { |
| 12 | |
| 13 | |
| 14 | public function getRecommendationLinkAttributes() { |
| 15 | $link = $this->getAttribute( 'link' ); |
| 16 | $linkType = $this->getAttribute( 'linkType' ); |
| 17 | $newsletter = $this->getAttribute( 'recommendation.newsletter' ); |
| 18 | $recommendation = $this->getAttribute( 'recommendation' ); |
| 19 | |
| 20 | switch ( $linkType ) { |
| 21 | case 'phone': |
| 22 | $phoneNrOld = $this->getAttribute( 'recommendation.bubbleChat.phone.phoneNr' ); |
| 23 | $phoneNr = $this->getAttribute( 'recommendation.siteleads.phone.phoneNr' ); |
| 24 | |
| 25 | if(!empty($phoneNrOld) && empty($phoneNr)) { |
| 26 | $phoneNr = $phoneNrOld; |
| 27 | } |
| 28 | $linkValue = '#'; |
| 29 | if ( ! empty( $phoneNr ) ) { |
| 30 | $linkValue = 'tel:' . $phoneNr; |
| 31 | } |
| 32 | |
| 33 | $attributes = Utils::getLinkAttributes( |
| 34 | array( |
| 35 | 'value' => $linkValue, |
| 36 | 'typeOpenLink' => 'sameWindow', |
| 37 | ) |
| 38 | ); |
| 39 | break; |
| 40 | case 'whatsapp': |
| 41 | $phoneNrOld = $this->getAttribute( 'recommendation.bubbleChat.whatsapp.phoneNr' ); |
| 42 | $phoneNr = $this->getAttribute( 'recommendation.siteleads.whatsapp.phoneNr' ); |
| 43 | |
| 44 | if(!empty($phoneNrOld) && empty($phoneNr)) { |
| 45 | $phoneNr = $phoneNrOld; |
| 46 | } |
| 47 | if ( ! empty( $phoneNr ) ) { |
| 48 | $linkValue = 'https://wa.me/' . $phoneNr; |
| 49 | $attributes = Utils::getLinkAttributes( |
| 50 | array( |
| 51 | 'value' => $linkValue, |
| 52 | 'typeOpenLink' => 'newWindow', |
| 53 | ) |
| 54 | ); |
| 55 | } else { |
| 56 | $attributes = Utils::getLinkAttributes( |
| 57 | array( |
| 58 | 'value' => '', |
| 59 | 'typeOpenLink' => 'sameWindow', |
| 60 | ) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | break; |
| 65 | case 'newsletter': |
| 66 | $newsletterId = LodashBasic::get( $newsletter, 'id' ); |
| 67 | |
| 68 | $attributes = Utils::getLinkAttributes( |
| 69 | array( |
| 70 | 'value' => '', |
| 71 | 'typeOpenLink' => 'sameWindow', |
| 72 | ) |
| 73 | ); |
| 74 | |
| 75 | if ( ! empty( $newsletterId ) ) { |
| 76 | $attributes[ "data-kubio-email-capture-popup-$newsletterId" ] = '1'; |
| 77 | } |
| 78 | |
| 79 | break; |
| 80 | case 'contact-form': |
| 81 | $id = Arr::get( $recommendation, 'contactForm.recommendationPageId' ); |
| 82 | |
| 83 | $attributes = Utils::getLinkAttributes( |
| 84 | array( |
| 85 | 'value' => '', |
| 86 | 'typeOpenLink' => 'sameWindow', |
| 87 | ) |
| 88 | ); |
| 89 | |
| 90 | if ( ! empty( $id ) ) { |
| 91 | $attributes['data-open-recommendation-page-iframe-in-lightbox'] = $this->getRecommendationPageIdForOpenIframeLightbox( $id ); |
| 92 | } |
| 93 | break; |
| 94 | case 'fluent-booking': |
| 95 | $id = Arr::get( $recommendation, 'fluentBooking.recommendationPageId' ); |
| 96 | |
| 97 | $attributes = Utils::getLinkAttributes( |
| 98 | array( |
| 99 | 'value' => '', |
| 100 | 'typeOpenLink' => 'sameWindow', |
| 101 | ) |
| 102 | ); |
| 103 | |
| 104 | if ( ! empty( $id ) ) { |
| 105 | $attributes['data-open-recommendation-page-iframe-in-lightbox'] = $this->getRecommendationPageIdForOpenIframeLightbox( $id ); |
| 106 | } |
| 107 | |
| 108 | break; |
| 109 | |
| 110 | default: |
| 111 | $attributes = Utils::getLinkAttributes( $link ); |
| 112 | |
| 113 | } |
| 114 | |
| 115 | if ( $this->shouldDisplayAsFancyBoxForRecommendations() ) { |
| 116 | $attributes['data-type'] = $this->getAttribute( 'link.lightboxMedia' ); |
| 117 | AssetsDependencyInjector::injectKubioFrontendStyleDependencies( 'fancybox' ); |
| 118 | AssetsDependencyInjector::injectKubioScriptDependencies( 'fancybox' ); |
| 119 | } |
| 120 | |
| 121 | return $attributes; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | public function getRecommendationPageIframeHtml() { |
| 127 | $linkType = $this->getAttribute( 'linkType' ); |
| 128 | $recommendation = $this->getAttribute( 'recommendation' ); |
| 129 | |
| 130 | $supported_link_types = array( 'contact-form', 'fluent-booking' ); |
| 131 | if ( ! in_array( $linkType, $supported_link_types ) ) { |
| 132 | return null; |
| 133 | } |
| 134 | |
| 135 | $recommendation_page_id = null; |
| 136 | switch ( $linkType ) { |
| 137 | case 'contact-form': |
| 138 | $recommendation_page_id = Arr::get( $recommendation, 'contactForm.recommendationPageId' ); |
| 139 | |
| 140 | break; |
| 141 | case 'fluent-booking': |
| 142 | $recommendation_page_id = Arr::get( $recommendation, 'fluentBooking.recommendationPageId' ); |
| 143 | |
| 144 | break; |
| 145 | |
| 146 | } |
| 147 | |
| 148 | if ( empty( $recommendation_page_id ) ) { |
| 149 | return null; |
| 150 | } |
| 151 | $recommendation_page_url = get_permalink( $recommendation_page_id ); |
| 152 | |
| 153 | if ( empty( $recommendation_page_url ) ) { |
| 154 | return null; |
| 155 | } |
| 156 | |
| 157 | $iframe_wrapper_id = $this->getRecommendationPageIdForOpenIframeLightbox( $recommendation_page_id ); |
| 158 | |
| 159 | ob_start(); |
| 160 | ?> |
| 161 | <div class="kubio-recommendation-page-iframe__wrapper" |
| 162 | id="<?php echo esc_attr( $iframe_wrapper_id ); ?>" |
| 163 | |
| 164 | > |
| 165 | <span class="kubio-recommendation-page-iframe__close"> |
| 166 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"> |
| 167 | <!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--> |
| 168 | <path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z"/> |
| 169 | </svg> |
| 170 | </span> |
| 171 | <iframe src="<?php echo esc_url( $recommendation_page_url ); ?>" ></iframe> |
| 172 | </div> |
| 173 | <?php |
| 174 | $inner_html = ob_get_clean(); |
| 175 | return array( |
| 176 | 'innerHTML' => $inner_html, |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | public function shouldDisplayAsFancyBoxForRecommendations() { |
| 181 | $openType = $this->getAttribute( 'link.typeOpenLink' ); |
| 182 | |
| 183 | return $openType === 'lightbox'; |
| 184 | } |
| 185 | |
| 186 | public function getRecommendationPageIdForOpenIframeLightbox( $id ) { |
| 187 | $linkType = $this->getAttribute( 'linkType' ); |
| 188 | |
| 189 | switch ( $linkType ) { |
| 190 | case 'contact-form': |
| 191 | case 'fluent-booking': |
| 192 | $iframeId = "kubio-recommendation-page-{$id}"; |
| 193 | break; |
| 194 | default: |
| 195 | return null; |
| 196 | } |
| 197 | |
| 198 | return $iframeId; |
| 199 | } |
| 200 | } |
| 201 |