PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.6.3
Kubio AI Page Builder v2.6.3
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / recommendations / recommendations-trait.php
kubio / lib / recommendations Last commit date
contact-forms 1 year ago bubble-chat.php 1 year ago contact-forms.php 1 year ago fluent-booking.php 1 year ago index.php 1 year ago newsletters.php 1 year ago recommendation-page-post-type.php 1 year ago recommendations-trait.php 1 year ago
recommendations-trait.php
193 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 $phoneNr = $this->getAttribute( 'recommendation.bubbleChat.phone.phoneNr' );
23
24 $linkValue = '#';
25 if ( ! empty( $phoneNr ) ) {
26 $linkValue = 'tel:' . $phoneNr;
27 }
28
29 $attributes = Utils::getLinkAttributes(
30 array(
31 'value' => $linkValue,
32 'typeOpenLink' => 'sameWindow',
33 )
34 );
35 break;
36 case 'whatsapp':
37 $phoneNr = $this->getAttribute( 'recommendation.bubbleChat.whatsapp.phoneNr' );
38
39 if ( ! empty( $phoneNr ) ) {
40 $linkValue = 'https://wa.me/' . $phoneNr;
41 $attributes = Utils::getLinkAttributes(
42 array(
43 'value' => $linkValue,
44 'typeOpenLink' => 'newWindow',
45 )
46 );
47 } else {
48 $attributes = Utils::getLinkAttributes(
49 array(
50 'value' => '',
51 'typeOpenLink' => 'sameWindow',
52 )
53 );
54 }
55
56 break;
57 case 'newsletter':
58 $newsletterId = LodashBasic::get( $newsletter, 'id' );
59
60 $attributes = Utils::getLinkAttributes(
61 array(
62 'value' => '',
63 'typeOpenLink' => 'sameWindow',
64 )
65 );
66
67 if ( ! empty( $newsletterId ) ) {
68 $attributes[ "data-kubio-email-capture-popup-$newsletterId" ] = '1';
69 }
70
71 break;
72 case 'contact-form':
73 $id = Arr::get( $recommendation, 'contactForm.recommendationPageId' );
74
75 $attributes = Utils::getLinkAttributes(
76 array(
77 'value' => '',
78 'typeOpenLink' => 'sameWindow',
79 )
80 );
81
82 if ( ! empty( $id ) ) {
83 $attributes['data-open-recommendation-page-iframe-in-lightbox'] = $this->getRecommendationPageIdForOpenIframeLightbox( $id );
84 }
85 break;
86 case 'fluent-booking':
87 $id = Arr::get( $recommendation, 'fluentBooking.recommendationPageId' );
88
89 $attributes = Utils::getLinkAttributes(
90 array(
91 'value' => '',
92 'typeOpenLink' => 'sameWindow',
93 )
94 );
95
96 if ( ! empty( $id ) ) {
97 $attributes['data-open-recommendation-page-iframe-in-lightbox'] = $this->getRecommendationPageIdForOpenIframeLightbox( $id );
98 }
99
100 break;
101
102 default:
103 $attributes = Utils::getLinkAttributes( $link );
104
105 }
106
107 if ( $this->shouldDisplayAsFancyBoxForRecommendations() ) {
108 $attributes['data-type'] = $this->getAttribute( 'link.lightboxMedia' );
109 AssetsDependencyInjector::injectKubioFrontendStyleDependencies( 'fancybox' );
110 AssetsDependencyInjector::injectKubioScriptDependencies( 'fancybox' );
111 }
112
113 return $attributes;
114 }
115
116
117
118 public function getRecommendationPageIframeHtml() {
119 $linkType = $this->getAttribute( 'linkType' );
120 $recommendation = $this->getAttribute( 'recommendation' );
121
122 $supported_link_types = array( 'contact-form', 'fluent-booking' );
123 if ( ! in_array( $linkType, $supported_link_types ) ) {
124 return null;
125 }
126
127 $recommendation_page_id = null;
128 switch ( $linkType ) {
129 case 'contact-form':
130 $recommendation_page_id = Arr::get( $recommendation, 'contactForm.recommendationPageId' );
131
132 break;
133 case 'fluent-booking':
134 $recommendation_page_id = Arr::get( $recommendation, 'fluentBooking.recommendationPageId' );
135
136 break;
137
138 }
139
140 if ( empty( $recommendation_page_id ) ) {
141 return null;
142 }
143 $recommendation_page_url = get_permalink( $recommendation_page_id );
144
145 if ( empty( $recommendation_page_url ) ) {
146 return null;
147 }
148
149 $iframe_wrapper_id = $this->getRecommendationPageIdForOpenIframeLightbox( $recommendation_page_id );
150
151 ob_start();
152 ?>
153 <div class="kubio-recommendation-page-iframe__wrapper"
154 id="<?php echo esc_attr( $iframe_wrapper_id ); ?>"
155
156 >
157 <span class="kubio-recommendation-page-iframe__close">
158 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512">
159 <!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.-->
160 <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"/>
161 </svg>
162 </span>
163 <iframe src="<?php echo esc_url( $recommendation_page_url ); ?>" ></iframe>
164 </div>
165 <?php
166 $inner_html = ob_get_clean();
167 return array(
168 'innerHTML' => $inner_html,
169 );
170 }
171
172 public function shouldDisplayAsFancyBoxForRecommendations() {
173 $openType = $this->getAttribute( 'link.typeOpenLink' );
174
175 return $openType === 'lightbox';
176 }
177
178 public function getRecommendationPageIdForOpenIframeLightbox( $id ) {
179 $linkType = $this->getAttribute( 'linkType' );
180
181 switch ( $linkType ) {
182 case 'contact-form':
183 case 'fluent-booking':
184 $iframeId = "kubio-recommendation-page-{$id}";
185 break;
186 default:
187 return null;
188 }
189
190 return $iframeId;
191 }
192 }
193