PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.8.1
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.8.1
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / CFF_Shortcode_Display.php
custom-facebook-feed / inc Last commit date
Admin 2 weeks ago Builder 2 weeks ago Helpers 2 weeks ago Integrations 2 weeks ago CFF_Autolink.php 2 weeks ago CFF_Blocks.php 2 weeks ago CFF_Cache.php 2 weeks ago CFF_Education.php 2 weeks ago CFF_Elementor_Base.php 2 weeks ago CFF_Elementor_Widget.php 2 weeks ago CFF_Error_Reporter.php 2 weeks ago CFF_FB_Settings.php 2 weeks ago CFF_Feed_Elementor_Control.php 2 weeks ago CFF_Feed_Locator.php 2 weeks ago CFF_Feed_Pro.php 2 weeks ago CFF_GDPR_Integrations.php 2 weeks ago CFF_Group_Posts.php 2 weeks ago CFF_HTTP_Request.php 2 weeks ago CFF_Oembed.php 2 weeks ago CFF_Parse.php 2 weeks ago CFF_Resizer.php 2 weeks ago CFF_Response.php 2 weeks ago CFF_Shortcode.php 2 weeks ago CFF_Shortcode_Display.php 2 weeks ago CFF_SiteHealth.php 2 weeks ago CFF_Utils.php 2 weeks ago CFF_View.php 2 weeks ago Custom_Facebook_Feed.php 2 weeks ago Email_Notification.php 2 weeks ago Platform_Data.php 2 weeks ago SB_Facebook_Data_Encryption.php 2 weeks ago SB_Facebook_Data_Manager.php 2 weeks ago index.php 2 weeks ago
CFF_Shortcode_Display.php
875 lines
1 <?php
2
3 /**
4 * Shortcode Display Class
5 *
6 * Contains all the functions for the diplay purposes! (Generates CSS, CSS Classes, HTML Attributes...)
7 *
8 * @since 2.19
9 */
10
11 namespace CustomFacebookFeed;
12
13 use CustomFacebookFeed\CFF_Utils;
14 use CustomFacebookFeed\CFF_Autolink;
15 use CustomFacebookFeed\CFF_Parse;
16
17 if (! defined('ABSPATH')) {
18 die('-1');
19 }
20
21 class CFF_Shortcode_Display
22 {
23 /**
24 * Ajax Loaded
25 *
26 * Check if is Ajax Loaded then put the script inside the content
27 *
28 * @since 2.19
29 */
30 public function ajax_loaded()
31 {
32 $ajax_loaded_content = '';
33 $ajax_theme = $this->atts['ajax'] === '1' ? 'on' : $this->atts['ajax'];
34 $ajax_theme = CFF_Utils::check_if_on($ajax_theme);
35 if ($ajax_theme) {
36 $cff_min = isset($_GET['sb_debug']) ? '' : '.min';
37 $cff_link_hashtags = CFF_Utils::check_if_on($this->atts['textlink']) ? 'false' : CFF_Utils::check_if_on($this->atts['linkhashtags']);
38 $ajax_loaded_content .= '<script type="text/javascript">var cfflinkhashtags = "' . $cff_link_hashtags . '";</script>';
39 $ajax_loaded_content .= '<script type="text/javascript" src="' . CFF_PLUGIN_URL . 'assets/js/cff-scripts' . $cff_min . '.js?ver=' . CFFVER . '"></script>';
40 }
41
42 return $ajax_loaded_content;
43 }
44
45
46 /**
47 * Style Compiler.
48 *
49 * Returns an array containing all the styles for the Feed
50 *
51 * @since 2.19
52 * @return String
53 */
54 public function style_compiler($style_array)
55 {
56 $style = '';
57 foreach ($style_array as $single_style) {
58 if (!empty($single_style['value']) && $single_style['value'] != '#' && $single_style['value'] != 'inherit' && $single_style['value'] !== '0') {
59 $style .= $single_style['css_name'] . ':' .
60 (isset($single_style['pref']) ? $single_style['pref'] : '') .
61 esc_attr($single_style['value']) .
62 (isset($single_style['suff']) ? $single_style['suff'] : '') .
63 ';';
64 }
65 }
66 $style = ( !empty($style) ) ? ' style="' . $style . '" ' : '';
67 return $style;
68 }
69
70 /**
71 * CSS Class Compiler .
72 *
73 * Returns custom CSS classes for the CFF list container shortcode
74 *
75 * @since 2.19
76 * @return array
77 */
78 public function feed_style_class_compiler()
79 {
80 $result = [
81 'cff_custom_class' => '',
82 'cff_feed_styles' => '',
83 'cff_feed_attributes' => ''
84 ];
85 // Set to be 100% width on mobile?
86 $cff_feed_width_resp = CFF_Utils::check_if_on($this->atts['widthresp']);
87 $cff_feed_height = CFF_Utils::get_css_distance($this->atts[ 'height' ]) ;
88
89 // Disable default CSS styles?
90 $cff_disable_styles = CFF_Utils::get_css_distance($this->atts[ 'disablestyles' ]) ;
91
92 $cff_class = $this->atts['class'];
93 // Masonry
94 $cff_cols = $this->atts['cols'];
95 $colstablet = (int)$this->atts['colstablet'];
96 $cff_cols_mobile = $this->atts['colsmobile'];
97 $cff_cols_js = $this->atts['colsjs'];
98
99 $masonry = ( intval($cff_cols) > 1 ) ? true : false;
100 $js_only = isset($cff_cols_js) ? $cff_cols_js : false;
101 if ($js_only === 'false') {
102 $js_only = false;
103 }
104
105 if ($masonry || $masonry == 'true') {
106 // $this->atts['headeroutside'] = true;
107 }
108 $masonry_classes = '';
109 if (isset($masonry)) {
110 if ($masonry === 'on' || $masonry === true || $masonry === 'true') {
111 $masonry_classes .= 'cff-masonry';
112 $masonry_classes .= ( $cff_cols != 3 ) ? sprintf(' masonry-%s-desktop', $cff_cols) : '';
113 $masonry_classes .= ( $cff_cols_mobile == 2 ) ? ' masonry-2-mobile' : '';
114 if ($cff_cols != 3) {
115 $masonry_classes .= sprintf(' masonry-%s-desktop', $cff_cols);
116 }
117 if ($cff_cols_mobile > 1) {
118 $masonry_classes .= sprintf(' masonry-%s-mobile', $cff_cols_mobile);
119 }
120 if ($colstablet > 1) {
121 $masonry_classes .= sprintf(' masonry-%s-tablet', $colstablet);
122 }
123 $masonry_classes .= ( ! $js_only ) ? ' cff-masonry-css' : ' cff-masonry-js';
124 }
125 }
126
127 $mobile_cols_class = '';
128 if (! empty($this->atts['colsmobile']) && (int)$this->atts['colsmobile'] > 0) {
129 $mobile_cols_class = ' cff-mob-cols-' . (int)$this->atts['colsmobile'];
130 }
131
132 $tablet_cols_class = '';
133 if (
134 ! empty($this->atts['colstablet'])
135 && (int)$this->atts['colstablet'] > 0
136 && (int)$this->atts['colstablet'] !== 2
137 ) {
138 $tablet_cols_class = ' cff-tab-cols-' . (int)$this->atts['colstablet'];
139 }
140
141 // If there's a class then add it here
142 $css_classes_string = '';
143
144 if (!empty($cff_class) || !empty($cff_feed_height) || !$cff_disable_styles || $cff_feed_width_resp || !empty($masonry_classes)) {
145 $css_classes_string .= ( !empty($cff_class) ) ? $cff_class : '';
146 $css_classes_string .= ( !empty($masonry_classes) ) ? $masonry_classes : '';
147 $css_classes_string .= ( !empty($cff_feed_height) ) ? ' cff-fixed-height ' : '';
148 $css_classes_string .= ( $cff_feed_width_resp ) ? ' cff-width-resp ' : '';
149 $css_classes_string .= ( !$cff_disable_styles ) ? ' cff-default-styles ' : '';
150 }
151 $css_classes_string .= $mobile_cols_class . $tablet_cols_class;
152 if (! empty($this->atts['paletteclass'])) {
153 $css_classes_string .= ' ' . $this->atts['paletteclass'];
154 }
155
156 $css_classes_string = ( !empty($css_classes_string) ) ? ' class="cff cff-list-container ' . esc_attr($css_classes_string) . '" ' : 'class="cff cff-list-container"';
157
158 $title_limit = !isset($title_limit) ? $this->atts['textlength'] : 9999;
159 $attributes_string = ' data-char="' . esc_attr($title_limit) . '" ';
160 $mobile_num = isset($this->atts['nummobile']) && (int)$this->atts['nummobile'] !== (int)$this->atts['num'] ? (int)$this->atts['nummobile'] : false;
161
162 $attributes_string .= ( $mobile_num ) ? ' data-nummobile="' . esc_attr($mobile_num) . '" data-pag-num="' . (int)$this->atts['num'] . '" ' : '';
163 if (CFF_GDPR_Integrations::doing_gdpr($this->atts)) {
164 $attributes_string .= ' data-cff-flags="gdpr" ';
165 }
166
167
168 $result = [
169 'cff_custom_class' => $css_classes_string,
170 'cff_feed_styles' => $this->get_style_attribute('feed_global'),
171 'cff_feed_attributes' => $attributes_string
172 ];
173 return $result;
174 }
175
176
177 /**
178 * Item HTML Attributes
179 *
180 * Returns the post item feed class atrribute
181 *
182 * @since 2.19
183 * @return Array
184 */
185 public function get_item_attributes($cff_post_type, $cff_album, $cff_post_bg_color_check, $cff_post_style, $cff_box_shadow, $name, $cff_post_id)
186 {
187 $item_class = 'cff-item ';
188 if ($cff_post_type == 'link') {
189 $item_class .= 'cff-link-item ';
190 } elseif ($cff_post_type == 'event') {
191 $item_class .= 'cff-timeline-event ';
192 } elseif ($cff_post_type == 'photo') {
193 $item_class .= 'cff-photo-post ';
194 } elseif ($cff_post_type == 'video') {
195 $item_class .= 'cff-video-post ';
196 } elseif ($cff_post_type == 'swf') {
197 $item_class .= 'cff-swf-post ';
198 } elseif ($cff_post_type == 'offer') {
199 $item_class .= 'cff-offer-post ';
200 } else {
201 $item_class .= 'cff-status-post ';
202 }
203
204 $item_class .= $cff_album ? 'cff-album ' : '';
205 $item_class .= ($cff_post_bg_color_check || $cff_post_style == "boxed") ? 'cff-box ' : '';
206 $item_class .= $cff_box_shadow ? 'cff-shadow ' : '';
207 $item_class .= isset($name) ? 'author-' . CFF_Utils::cff_to_slug($name) : '';
208
209
210 return [
211 'class' => 'class="' . esc_attr($item_class) . '"',
212 'id' => 'id="cff_' . esc_attr($cff_post_id) . '"',
213 'style' => $this->get_post_item_style()
214 ];
215 }
216
217 /**
218 * Item CLass Attributes
219 *
220 * Returns the post item feed style attribute
221 *
222 * @since 2.19
223 * @return String
224 */
225 public function get_post_item_style()
226 {
227 $item_style = '';
228 if ($this->atts['poststyle'] == 'regular') {
229 $item_style = ' style="border-bottom: ' . esc_attr(CFF_Utils::return_value($this->atts[ 'sepsize' ], 0) . 'px solid #' . str_replace('#', '', CFF_Utils::return_value($this->atts[ 'sepcolor' ], 'ddd'))) . ';"';
230 } elseif ($this->atts['poststyle'] == 'boxed') {
231 $item_style_array = [
232 ['css_name' => 'border-radius', 'value' => $this->atts['postcorners'] , 'suff' => 'px'],
233 ['css_name' => 'background-color', 'value' => str_replace('#', '', $this->atts['postbgcolor']), 'pref' => '#']
234 ];
235 $item_style = $this->style_compiler($item_style_array);
236 }
237 return $item_style;
238 }
239
240 /**
241 *
242 * Style Attribute
243 * Generates the Style attribute for the Feed Elements
244 *
245 * @since 2.19
246 * @return String
247 */
248 public function get_style_attribute($element)
249 {
250 $style_array = [];
251 switch ($element) {
252 case 'link_box':
253 $style_array = [
254 ['css_name' => 'border', 'value' => str_replace('#', '', $this->atts['linkbordercolor']), 'pref' => ' 1px solid #'],
255 ['css_name' => 'background-color', 'value' => str_replace('#', '', $this->atts['linkbgcolor']), 'pref' => '#']
256 ];
257 break;
258 case 'body_description':
259 $style_array = [
260 ['css_name' => 'font-size', 'value' => $this->atts['descsize'], 'suff' => 'px'],
261 ['css_name' => 'font-weight', 'value' => $this->atts['descweight']],
262 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['desccolor']), 'pref' => '#']
263 ];
264 break;
265 case 'feed_global':
266 $style_array = [
267 ['css_name' => 'width', 'value' => CFF_Utils::get_css_distance($this->atts[ 'width' ]) ],
268 ];
269 break;
270 case 'feed_wrapper_insider':
271 $style_array = [
272 ['css_name' => 'padding', 'value' => CFF_Utils::get_css_distance($this->atts[ 'padding' ]) ],
273 ['css_name' => 'height', 'value' => CFF_Utils::get_css_distance($this->atts[ 'height' ]) ],
274 ['css_name' => 'background-color', 'value' => str_replace('#', '', $this->atts[ 'bgcolor' ]), 'pref' => '#']
275 ];
276 break;
277 case 'header':
278 $style_array = [
279 ['css_name' => 'background-color', 'value' => str_replace('#', '', $this->atts['headerbg']), 'pref' => '#'],
280 ['css_name' => 'padding', 'value' => CFF_Utils::get_css_distance($this->atts['headerpadding']) ],
281 ['css_name' => 'font-size', 'value' => $this->atts['headertextsize'], 'suff' => 'px'],
282 ['css_name' => 'font-weight', 'value' => $this->atts['headertextweight']],
283 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['headertextcolor']), 'pref' => '#']
284 ];
285 break;
286 case 'header_visual':
287 $style_array = [
288 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['headertextcolor']), 'pref' => '#'],
289 ['css_name' => 'font-size', 'value' => $this->atts['headertextsize'], 'suff' => 'px'],
290 ['css_name' => 'font-weight', 'value' => $this->atts['headertextweight']]
291 ];
292 break;
293
294 case 'header_icon':
295 $style_array = [
296 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['headericoncolor']), 'pref' => '#'],
297 ['css_name' => 'font-size', 'value' => $this->atts['headericonsize'], 'suff' => 'px']
298 ];
299 break;
300
301 case 'header_bio':
302 $style_array = [
303 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['headerbiocolor']), 'pref' => '#'],
304 ['css_name' => 'font-size', 'value' => $this->atts['headerbiosize'], 'suff' => 'px']
305 ];
306 break;
307 case 'author':
308 $style_array = [
309 ['css_name' => 'font-size', 'value' => $this->atts['authorsize'], 'suff' => 'px'],
310 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['authorcolor']), 'pref' => '#']
311 ];
312 break;
313 case 'date':
314 $style_array = [
315 ['css_name' => 'font-size', 'value' => $this->atts['datesize'], 'suff' => 'px'],
316 ['css_name' => 'font-weight', 'value' => $this->atts['dateweight']],
317 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['datecolor']), 'pref' => '#']
318 ];
319 break;
320
321 case 'post_link':
322 $style_array = [
323 ['css_name' => 'font-size', 'value' => $this->atts['linksize'], 'suff' => 'px'],
324 ['css_name' => 'font-weight', 'value' => $this->atts['linkweight']],
325 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['linkcolor']), 'pref' => '#']
326 ];
327 break;
328 case 'event_title':
329 $style_array = [
330 ['css_name' => 'font-size', 'value' => $this->atts['eventtitlesize'], 'suff' => 'px'],
331 ['css_name' => 'font-weight', 'value' => $this->atts['eventtitleweight']],
332 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['eventtitlecolor']), 'pref' => '#']
333 ];
334 break;
335 case 'post_text':
336 $style_array = [
337 ['css_name' => 'font-size', 'value' => $this->atts['textsize'], 'suff' => 'px'],
338 ['css_name' => 'font-weight', 'value' => $this->atts['textweight']],
339 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts['textcolor']), 'pref' => '#']
340 ];
341 break;
342 case 'shared_cap_link':
343 $style_array = [
344 ['css_name' => 'font-size', 'value' => $this->atts[ 'linkurlsize' ], 'suff' => 'px'],
345 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts[ 'linkurlcolor' ]), 'pref' => '#']
346 ];
347 break;
348 case 'shared_desclink':
349 $style_array = [
350 ['css_name' => 'font-size', 'value' => $this->atts[ 'linkdescsize' ], 'suff' => 'px'],
351 ['css_name' => 'color', 'value' => str_replace('#', '', $this->atts[ 'linkdesccolor' ]), 'pref' => '#']
352 ];
353 break;
354 }
355
356 return $this->style_compiler($style_array);
357 }
358
359
360 /**
361 *
362 * Style Attribute
363 * Generates the Style attribute for the Feed Elements
364 *
365 * @since 2.19
366 * @return String
367 */
368 public function check_show_section($section_name)
369 {
370 $is_shown = ( CFF_Utils::stripos($this->atts[ 'include' ], $section_name) !== false ) ? true : false;
371 $is_shown = ( CFF_Utils::stripos($this->atts[ 'exclude' ], $section_name) !== false ) ? false : $is_shown;
372 return $is_shown;
373 }
374
375
376
377 /**
378 *
379 * Get Author Template Data
380 * Get Authors the data for the templates
381 *
382 * @since 2.19
383 * -----------------------------------------
384 */
385 public static function get_author_name($news)
386 {
387 return isset($news->from->name) ? str_replace('"', "", $news->from->name) : '';
388 }
389
390 public static function get_author_link_atts($news, $target, $cff_nofollow, $cff_author_styles)
391 {
392 return !isset($news->from->link) ? '' : ' href="https://facebook.com/' . $news->from->id . '" ' . $target . $cff_nofollow . ' ' . $cff_author_styles;
393 }
394
395 public static function get_author_link_el($news)
396 {
397 return !isset($news->from->link) ? 'span' : 'a';
398 }
399
400 public static function get_author_post_text_story($post_text_story = '', $cff_author_name = '')
401 {
402 if (!empty($cff_author_name) && !empty($post_text_story)) {
403 $cff_author_name_pos = strpos($post_text_story, $cff_author_name);
404 if ($cff_author_name_pos !== false) {
405 $post_text_story = substr_replace($post_text_story, '', $cff_author_name_pos, strlen($cff_author_name));
406 }
407 }
408 return $post_text_story;
409 }
410
411 public static function get_author_pic_src_class($news, $atts)
412 {
413 $cff_author_src = $cff_author_img_src = isset($news->from->picture->data->url) ? $news->from->picture->data->url : '';
414 $img_class = '';
415 if (CFF_GDPR_Integrations::doing_gdpr($atts)) {
416 $cff_author_img_src = CFF_PLUGIN_URL . '/assets/img/placeholder.png';
417 $img_class = ' cff-no-consent';
418 }
419 return [
420 'real_image' => $cff_author_src,
421 'image' => $cff_author_img_src,
422 'class' => $img_class
423 ];
424 }
425
426
427 /**
428 *
429 * Get Date Data
430 * Get Date the data for the templates
431 *
432 * @since 2.19
433 * -----------------------------------------
434 */
435 public static function get_date($options, $atts, $news)
436 {
437 $cff_date_before = isset($atts[ 'beforedate' ]) && CFF_Utils::check_if_on($atts['beforedateenabled']) ? $atts[ 'beforedate' ] : '';
438 $cff_date_after = isset($atts[ 'afterdate' ]) && CFF_Utils::check_if_on($atts['afterdateenabled']) ? $atts[ 'afterdate' ] : '';
439 // Timezone. The post date is adjusted by the timezone offset in the cff_getdate function.
440 $cff_timezone = $atts['timezone'];
441
442 // Posted ago strings
443 $cff_date_translate_strings = array(
444 'cff_translate_second' => $atts['secondtext'],
445 'cff_translate_seconds' => $atts['secondstext'],
446 'cff_translate_minute' => $atts['minutetext'],
447 'cff_translate_minutes' => $atts['minutestext'],
448 'cff_translate_hour' => $atts['hourtext'],
449 'cff_translate_hours' => $atts['hourstext'],
450 'cff_translate_day' => $atts['daytext'],
451 'cff_translate_days' => $atts['daystext'],
452 'cff_translate_week' => $atts['weektext'],
453 'cff_translate_weeks' => $atts['weekstext'],
454 'cff_translate_month' => $atts['monthtext'],
455 'cff_translate_months' => $atts['monthstext'],
456 'cff_translate_year' => $atts['yeartext'],
457 'cff_translate_years' => $atts['yearstext'],
458 'cff_translate_ago' => $atts['agotext']
459 );
460 $cff_date_formatting = $atts[ 'dateformat' ];
461 $cff_date_custom = $atts[ 'datecustom' ];
462
463 $post_time = isset($news->created_time) ? $news->created_time : '';
464 $post_time = isset($news->backdated_time) ? $news->backdated_time : $post_time; // If the post is backdated then use that as the date instead
465 return $cff_date_before . ' ' . CFF_Utils::cff_getdate(strtotime($post_time), $cff_date_formatting, $cff_date_custom, $cff_date_translate_strings, $cff_timezone) . ' ' . $cff_date_after;
466 }
467
468 /**
469 *
470 * Get Media Link Data
471 * Get the Media link data for the templates
472 *
473 * @since 2.19
474 * -----------------------------------------
475 */
476 public static function get_media_link_text($atts, $cff_post_type, $cff_album)
477 {
478 $cff_translate_photo_text = CFF_Utils::return_value($atts['phototext'], esc_html__('Photo', 'custom-facebook-feed'));
479 $cff_translate_video_text = CFF_Utils::return_value($atts['videotext'], esc_html__('Video', 'custom-facebook-feed'));
480 return ( $cff_post_type == 'photo' || $cff_album ) ? $cff_translate_photo_text : $cff_translate_video_text;
481 }
482
483 public static function get_media_link_icon($cff_post_type, $cff_album)
484 {
485 return ( $cff_post_type == 'photo' || $cff_album ) ? 'picture-o fa-image' : 'video-camera fa-video';
486 }
487
488
489 /**
490 *
491 * Get Post Link Data
492 * Get the Post link data for the templates
493 *
494 * @since 2.19
495 * -----------------------------------------
496 */
497 public static function get_post_link_social_links($link, $cff_post_text_to_share)
498 {
499 return [
500 'facebook' => [
501 'icon' => 'facebook-square',
502 'text' => esc_html__('Share on Facebook', 'custom-facebook-feed'),
503 'share_link' => 'https://www.facebook.com/sharer/sharer.php?u=' . urlencode($link)
504 ],
505 'twitter' => [
506 'icon' => 'twitter',
507 'text' => esc_html__('Share on Twitter', 'custom-facebook-feed'),
508 'share_link' => 'https://twitter.com/intent/tweet?text=' . urlencode($link)
509 ],
510 'linkedin' => [
511 'icon' => 'linkedin',
512 'text' => esc_html__('Share on LinkedIn', 'custom-facebook-feed'),
513 'share_link' => 'https://www.linkedin.com/shareArticle?mini=true&amp;url=' . urlencode($link) . '&amp;title=' . rawurlencode(strip_tags($cff_post_text_to_share))
514 ],
515 'email' => [
516 'icon' => 'envelope',
517 'text' => esc_html__('Share by Email', 'custom-facebook-feed'),
518 'share_link' => 'mailto:?subject=Facebook&amp;body=' . urlencode($link) . '%20-%20' . rawurlencode(strip_tags($cff_post_text_to_share))
519 ]
520 ];
521 }
522
523 public static function get_post_link_text_to_share($cff_post_text = '')
524 {
525 $cff_post_text_to_share = '';
526 if (!empty($cff_post_text) && strpos($cff_post_text, '<span class="cff-expand">') !== false) {
527 $cff_post_text_to_share = explode('<span class="cff-expand">', $cff_post_text);
528 if (is_array($cff_post_text_to_share)) {
529 $cff_post_text_to_share = $cff_post_text_to_share[0];
530 }
531 }
532 return $cff_post_text_to_share;
533 }
534
535 public static function get_post_link_text_link($atts, $cff_post_type)
536 {
537 $cff_facebook_link_text = $atts[ 'facebooklinktext' ];
538 $link_text = ($cff_facebook_link_text != '' && !empty($cff_facebook_link_text)) ? $cff_facebook_link_text : esc_html__('View on Facebook', 'custom-facebook-feed');
539 // If it's an offer post then change the text
540 if ($cff_post_type == 'offer') {
541 $link_text = esc_html__('View Offer', 'custom-facebook-feed');
542 }
543 return $link_text;
544 }
545
546 public static function get_post_link_fb_share_text($atts)
547 {
548 return ( $atts[ 'sharelinktext' ] ) ? $atts[ 'sharelinktext' ] : esc_html__('Share', 'custom-facebook-feed');
549 }
550
551
552 /**
553 *
554 * Get Post Text Data
555 * Get the Post text data for the templates
556 *
557 * @since 2.19
558 * -----------------------------------------
559 */
560 public static function get_post_text_title_format($atts)
561 {
562 return ( empty($atts[ 'textformat' ]) || $atts[ 'textformat' ] == 'p' ) ? 'div' : sanitize_key($atts[ 'textformat' ]);
563 }
564
565 public static function get_post_text_link($cff_post_type, $this_class, $link, $PostID)
566 {
567 return ( $cff_post_type == 'link' || $cff_post_type == 'video' ) ? "https://www.facebook.com/" . $this_class->page_id . "/posts/" . $PostID[1] : $link;
568 }
569
570 public static function get_post_text_contenttext($post_text, $cff_linebreak_el, $cff_title_link)
571 {
572 // Replace line breaks in text (needed for IE8 and to prevent lost line breaks in HTML minification)
573 $post_text = preg_replace("/\r\n|\r|\n/", $cff_linebreak_el, $post_text);
574 // If the text is wrapped in a link then don't hyperlink any text within
575 if ($cff_title_link) :
576 // Remove links from text
577 $result = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $post_text);
578 return CFF_Utils::cff_wrap_span($result) . ' ';
579 else :
580 return CFF_Autolink::cff_autolink($post_text);
581 endif;
582 }
583
584 public static function get_post_text_call_to_actions($atts, $news, $cff_title_styles, $cff_posttext_link_color, $cff_nofollow_referrer)
585 {
586 // Add a call to action button if included
587 if (isset($news->call_to_action->value->link)) {
588 $cff_cta_link = $news->call_to_action->value->link;
589
590 if ($cff_cta_link[0] == '/') {
591 $cff_cta_link = 'https://facebook.com' . $cff_cta_link;
592 } else {
593 // If it doesn't start with 'http' then add it otherwise the link doesn't work. Don't do this if it's a tel num.
594 if (strpos($cff_cta_link, 'http') === false && strpos($cff_cta_link, 'tel:') === false) {
595 $cff_cta_link = 'https://' . $cff_cta_link;
596 }
597 }
598
599 $cff_button_type = $news->call_to_action->type;
600
601 switch ($cff_button_type) {
602 case 'SHOP_NOW':
603 $cff_cta_button_text = CFF_Utils::return_value($atts['shopnowtext'], 'Shop Now');
604 break;
605 case 'MESSAGE_PAGE':
606 $cff_cta_button_text = CFF_Utils::return_value($atts['messagepage'], 'Message Page');
607 break;
608 case 'LEARN_MORE':
609 $cff_cta_button_text = CFF_Utils::return_value($atts['learnmoretext'], 'Learn More');
610 break;
611 default:
612 $cff_cta_button_text = ucwords(strtolower(str_replace('_', ' ', $cff_button_type)));
613 }
614
615 $cff_app_link = isset($news->call_to_action->value->app_link) ? $news->call_to_action->value->app_link : '';
616
617 // Set the message page cta to use the default messenger link as the API can sometimes send an invalid link
618 if ($cff_button_type == 'MESSAGE_PAGE') {
619 $cff_cta_link = 'https://m.me/' . $news->from->id;
620 }
621
622 // Add the button to the post if the text isn't "NO_BUTTON"
623 if ($cff_button_type != 'NO_BUTTON') :
624 ?>
625 <p class="cff-cta-link" <?php echo $cff_title_styles ?>><a href="<?php echo esc_url($cff_cta_link) ?>" target="_blank" data-app-link="<?php echo $cff_app_link ?>" style="color: #<?php echo $cff_posttext_link_color ?>;" <?php echo $cff_nofollow_referrer ?> ><?php echo $cff_cta_button_text ?></a></p>
626 <?php
627 endif;
628 }
629 }
630
631
632 /**
633 *
634 * Get Shared Link Data
635 * Get the Shared Link data for the templates
636 *
637 * @since 2.19
638 * -----------------------------------------
639 */
640 public static function get_shared_link_caption($news)
641 {
642 $cff_link_caption = '';
643 if (!empty($news->link)) {
644 $cff_link_caption = htmlentities($news->link, ENT_QUOTES, 'UTF-8');
645 $cff_link_caption_parts = explode('/', $cff_link_caption);
646 if (isset($cff_link_caption_parts[2])) {
647 $cff_link_caption = $cff_link_caption_parts[2];
648 }
649 }
650 return $cff_link_caption;
651 }
652
653 public static function get_shared_link_title_format($atts)
654 {
655 return ( empty($atts[ 'linktitleformat' ]) ) ? 'p' : $atts[ 'linktitleformat' ];
656 }
657
658 public static function get_shared_link_title_styles($atts)
659 {
660 return ( !empty($atts[ 'linktitlesize' ]) && $atts[ 'linktitlesize' ] != 'inherit' ) ? 'style="font-size:' . $atts[ 'linktitlesize' ] . 'px;"' : '';
661 }
662
663
664 public static function get_shared_link_description_text($body_limit, $description_text, $cff_title_link, $cff_posttext_link_color)
665 {
666 // Truncate desc
667 if (!empty($body_limit) && !empty($description_text)) {
668 if (strlen($description_text) > $body_limit) {
669 $description_text = substr($description_text, 0, $body_limit) . '...';
670 }
671 }
672 if ($cff_title_link) {
673 } else {
674 $description_text = CFF_Autolink::cff_autolink(htmlspecialchars($description_text), $link_color = $cff_posttext_link_color);
675 }
676 return $description_text;
677 }
678
679 public static function get_shared_link_description($cff_title_link, $description_text)
680 {
681 $cff_link_description = '';
682 if ($cff_title_link) {
683 $cff_link_description = CFF_Utils::cff_wrap_span(htmlspecialchars($description_text));
684 } else {
685 $cff_link_description = nl2br($description_text);
686 }
687 return $cff_link_description ;
688 }
689
690
691
692 /**
693 *
694 * Get Error Message Data
695 * Get the error message data for the templates
696 *
697 * @since 2.19
698 * -----------------------------------------
699 */
700 public static function get_error_check($page_id, $user_id, $access_token)
701 {
702 $cff_ppca_check_error = false;
703 if (! get_user_meta($user_id, 'cff_ppca_check_notice_dismiss')) {
704 $cff_posts_json_url = 'https://graph.facebook.com/v8.0/' . $page_id . '/posts?limit=1&access_token=' . $access_token;
705 $transient_name = 'cff_ppca_' . substr($page_id, 0, 5) . substr($page_id, strlen($page_id) - 5, 5) . '_' . substr($access_token, 15, 10);
706 $cff_cache_time = 1;
707 $cache_seconds = YEAR_IN_SECONDS;
708 $cff_ppca_check = CFF_Utils::cff_get_set_cache($cff_posts_json_url, $transient_name, $cff_cache_time, $cache_seconds, '', true, $access_token, $backup = false);
709 $cff_ppca_check_json = json_decode($cff_ppca_check);
710
711 if (isset($cff_ppca_check_json->error) && strpos($cff_ppca_check_json->error->message, 'Public Content Access') !== false) {
712 $cff_ppca_check_error = true;
713 }
714 }
715 return $cff_ppca_check_error;
716 }
717
718 public static function get_error_message_cap()
719 {
720 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
721 $cap = apply_filters('cff_settings_pages_capability', $cap);
722 return $cap;
723 }
724
725 public static function get_error_check_ppca($FBdata)
726 {
727 // Is it a PPCA error from the API?
728 return ( isset($FBdata->error->message) && strpos($FBdata->error->message, 'Public Content Access') !== false ) ? true : false;
729 }
730
731
732
733 /**
734 *
735 * Get Likebox Data
736 * Get the likebox data for the templates
737 *
738 * @since 2.19
739 * -----------------------------------------
740 */
741 public static function get_likebox_height($atts, $cff_like_box_small_header, $cff_like_box_faces)
742 {
743 $cff_likebox_height = $atts[ 'likeboxheight' ];
744 $cff_likebox_height = preg_replace('/px$/', '', $cff_likebox_height);
745 // Calculate the like box height
746 $cff_likebox_height = 130;
747 if ($cff_like_box_small_header == 'true') {
748 $cff_likebox_height = 70;
749 }
750 if ($cff_like_box_faces == 'true') {
751 $cff_likebox_height = 214;
752 }
753 if ($cff_like_box_small_header == 'true' && $cff_like_box_faces == 'true') {
754 $cff_likebox_height = 154;
755 }
756 return $cff_likebox_height;
757 }
758
759
760 public static function get_likebox_width($atts)
761 {
762 $cff_likebox_custom_width = isset($atts[ 'likeboxcustomwidth' ]) ? CFF_Utils::check_if_on($atts[ 'likeboxcustomwidth' ]) : false;
763 $cff_likebox_width = $cff_likebox_custom_width && isset($atts[ 'likeboxwidth' ]) && !empty($atts[ 'likeboxwidth' ]) ? $atts[ 'likeboxwidth' ] : 300;
764 return $cff_likebox_width;
765 }
766
767 public static function get_likebox_classes($atts)
768 {
769 return "cff-likebox" . ( CFF_Utils::check_if_on($atts[ 'likeboxoutside' ]) ? " cff-outside" : '' ) . ( $atts[ 'likeboxpos' ] == 'top' ? ' cff-top' : ' cff-bottom' );
770 }
771
772 public static function get_likebox_tag($atts)
773 {
774 return ( $atts[ 'likeboxpos' ] == 'top') ? 'section' : 'div';
775 }
776
777
778 /**
779 *
780 * Get Header Data
781 * Get the Header data for the templates
782 *
783 * @since 2.19
784 * -----------------------------------------
785 */
786 public static function get_header_txt_classes($cff_header_outside)
787 {
788 return ($cff_header_outside) ? " cff-outside" : '';
789 }
790
791
792 public static function get_header_parts($atts)
793 {
794 if (!empty($atts['headerinc']) || !empty($atts['headerexclude'])) {
795 if (!empty($atts['headerinc'])) {
796 $header_inc = explode(',', str_replace(' ', '', strtolower($atts['headerinc'])));
797 $cff_header_cover = in_array('cover', $header_inc, true);
798 $cff_header_name = in_array('name', $header_inc, true);
799 $cff_header_bio = in_array('about', $header_inc, true);
800 } else {
801 $header_exc = explode(',', str_replace(' ', '', strtolower($atts['headerexclude'])));
802 $cff_header_cover = ! in_array('cover', $header_exc, true);
803 $cff_header_name = ! in_array('name', $header_exc, true);
804 $cff_header_bio = ! in_array('about', $header_exc, true);
805 }
806 } else {
807 $cff_header_cover = CFF_Utils::check_if_on($atts['headercover']);
808 $cff_header_name = CFF_Utils::check_if_on($atts['headername']);
809 $cff_header_bio = CFF_Utils::check_if_on($atts['headerbio']);
810 }
811
812 return [
813 'cover' => $cff_header_cover,
814 'name' => $cff_header_name,
815 'bio' => $cff_header_bio
816 ];
817 }
818
819 public static function get_header_height_style($atts)
820 {
821 $cff_header_cover_height = ! empty($atts['headercoverheight']) ? (int)$atts['headercoverheight'] : 300;
822 $header_hero_style = $cff_header_cover_height !== 300 ? ' style="height: ' . $cff_header_cover_height . 'px";' : '';
823 return $header_hero_style;
824 }
825
826 public static function get_header_font_size($atts)
827 {
828 return !empty($atts['headertextsize']) ? 'style="font-size:' . esc_attr($atts['headertextsize']) . 'px;"' : '';
829 }
830
831 public static function get_header_link($header_data, $page_id)
832 {
833 $link = CFF_Parse::get_link($header_data);
834 if ($link == 'https://facebook.com') {
835 $link .= '/' . $page_id;
836 }
837 return $link;
838 }
839
840 public static function avatar_src($header_data, $atts)
841 {
842 if (CFF_GDPR_Integrations::doing_gdpr($atts)) {
843 return trailingslashit(CFF_PLUGIN_URL) . 'assets/img/placeholder.png';
844 }
845 return CFF_Parse::get_avatar($header_data);
846 }
847
848 public static function cover_image_src($header_data, $atts)
849 {
850 if (CFF_GDPR_Integrations::doing_gdpr($atts)) {
851 return trailingslashit(CFF_PLUGIN_URL) . 'assets/img/placeholder.png';
852 }
853 return CFF_Parse::get_cover_source($header_data);
854 }
855
856 /*
857 *
858 * PRINT THE GDPR NTOCE FOR ADMINS IN THE FRON END
859 *
860 */
861 public static function print_gdpr_notice($element_name, $custom_class = '')
862 {
863 if (! is_user_logged_in() || ! current_user_can('edit_posts')) {
864 return;
865 }
866 ?>
867 <div class="cff-gdpr-notice <?php echo $custom_class; ?>">
868 <i class="fa fa-lock" aria-hidden="true"></i>
869 <?php echo esc_html__('This notice is visible to admins only.', 'custom-facebook-feed') ?><br/>
870 <?php echo $element_name . ' ' . esc_html__('disabled due to GDPR setting.', 'custom-facebook-feed') ?> <a href="<?php echo esc_url(admin_url('admin.php?page=cff-style&tab=misc')); ?>"><?php echo esc_html__('Click here', 'custom-facebook-feed') ?></a> <?php echo esc_html__('for more info.', 'custom-facebook-feed') ?>
871 </div>
872 <?php
873 }
874 }
875