PluginProbe ʕ •ᴥ•ʔ
Custom Twitter Feeds – A Tweets Widget or X Feed Widget / 2.7.0
Custom Twitter Feeds – A Tweets Widget or X Feed Widget v2.7.0
2.8.0 2.7.0 2.6.1 2.6.0 1.0 1.0.1 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.4 1.4.1 1.5 1.5.1 1.6 1.6.1 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1 2.1.1 2.1.2 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.5.4 2.5.5 trunk
custom-twitter-feeds / inc / CTF_Display_Elements.php
custom-twitter-feeds / inc Last commit date
Admin 1 month ago Builder 1 month ago Integrations 1 month ago SmashTwitter 1 month ago UsageTracking 1 month ago V2 1 month ago blocks 1 month ago CTF_Display_Elements.php 1 month ago CTF_Feed.php 1 month ago CTF_Feed_Locator.php 1 month ago CTF_GDPR_Integrations.php 1 month ago CTF_Parse.php 1 month ago CTF_Settings.php 1 month ago CtfAdmin.php 1 month ago CtfCache.php 1 month ago CtfFeed.php 1 month ago CtfOauthConnect.php 1 month ago SB_Twitter_Cron_Updater.php 1 month ago admin-hooks.php 1 month ago ctf-functions.php 1 month ago notices.php 1 month ago widget.php 1 month ago
CTF_Display_Elements.php
545 lines
1 <?php
2 /**
3 * Class CTF_Display_Elements
4 *
5 *
6 * @since 2.0
7 */
8 namespace TwitterFeed;
9 use TwitterFeed\Builder\CTF_Feed_Builder;
10 if ( ! defined( 'ABSPATH' ) ) {
11 die( '-1' );
12 }
13
14 class CTF_Display_Elements {
15
16 /**
17 * Get Feed Item CSS Classes
18 *
19 * @since 2.0
20 */
21 public static function get_item_classes( $data, $feed_options, $i ) {
22 $data = $data[$i];
23
24 $tweet_classes = 'ctf-item ctf-author-' . CTF_Parse::get_author_screen_name( $data ) .' ctf-new';
25 $tweet_classes .= ( !ctf_show( 'avatar', $feed_options ) ) ? ' ctf-hide-avatar' : '';
26 $tweet_classes = apply_filters( 'ctf_tweet_classes', $tweet_classes );
27
28 $tweet_classes .= isset( $data['retweeted_status'] ) ? ' ctf-retweet' : '';
29 $tweet_classes .= isset( $data['quoted_status'] ) ? ' ctf-quoted' : '';
30 $tweet_classes = ' class="' . $tweet_classes . '" ';
31 if( ctf_doing_customizer($feed_options) ){
32 $tweet_classes .= ' :class="!$parent.valueIsEnabled($parent.customizerFeedData.settings.include_avatar) ? \'ctf-hide-avatar\' : \'\'" ';
33 }
34 return $tweet_classes;
35 }
36
37
38 /**
39 * Get Tweet Retweet Attribute
40 *
41 * @since 2.0
42 */
43 public static function get_retweet_attr( $post, $check_duplicates ) {
44 if( isset( $post['retweeted_status'] ) && $check_duplicates ) {
45 return ' data-ctfretweetid="'.$post['retweeted_status']['id_str'].'"';
46 }
47 return '';
48 }
49
50 /**
51 * Get Tweet Quoted Media Text
52 *
53 * @since 2.0
54 */
55 public static function get_quoted_media_text( $post, $feed_options ) {
56 $quoted_media_text = '';
57 if(!$feed_options['is_legacy'] || ($feed_options['is_legacy'] && ctf_show( 'placeholder', $feed_options ))){
58 if ( isset( $post['quoted_status'] ) ) {
59 $quoted = $post['quoted_status'];
60
61 if ( ( isset( $quoted['extended_entities']['media'][0] ) || isset( $quoted['entities']['media'][0] ) ) && ctf_show( 'placeholder', $feed_options ) ) {
62 $quoted_media = isset( $quoted['extended_entities']['media'] ) ? $quoted['extended_entities']['media'] : $quoted['entities']['media'];
63 $quoted_media_count = count( $quoted_media );
64 switch ( $quoted_media[0]['type'] ) {
65 case 'video':
66 case 'animated_gif':
67 $quoted_media_text .= '<span class="ctf-quoted-tweet-text-media-wrap">' . ctf_get_fa_el( 'fa-file-video-o' ) . '</span>';
68 break;
69 default:
70 if ( $quoted_media_count > 1 ) {
71 $quoted_media_text .= '<span class="ctf-quoted-tweet-text-media-wrap ctf-multi-media-icon">' . $quoted_media_count . ctf_get_fa_el( 'fa-picture-o' ) . '</span>';
72 } else {
73 $quoted_media_text .= '<span class="ctf-quoted-tweet-text-media-wrap">' . ctf_get_fa_el( 'fa-picture-o' ) . '</span>';
74 }
75 break;
76 }
77 } else {
78 unset( $quoted_media );
79 }
80 }
81 return $quoted_media_text;
82 }
83
84 }
85
86 /**
87 * Get Tweet Post media TExt
88 *
89 * @since 2.0
90 */
91 public static function get_post_media_text( $post, $feed_options, $type = 'text' ) {
92 $post_media_text = '';
93 $post_media_count = 0;
94 if ( ( isset( $post['extended_entities']['media'][0] ) || isset( $post['entities']['media'][0] ) ) ) {
95 $post_media = isset( $post['extended_entities']['media'] ) ? $post['extended_entities']['media'] : $post['entities']['media'];
96 $post_media_count = count( $post_media );
97 switch ( $post_media[0]['type'] ) {
98 case 'video':
99 case 'animated_gif':
100 $post_media_text .= ctf_get_fa_el( 'fa-file-video-o' );
101 break;
102 default:
103 if ( $post_media_count > 1 ) {
104 $post_media_text .= $post_media_count . ctf_get_fa_el( 'fa-picture-o' );
105 } else {
106 $post_media_text .= ctf_get_fa_el( 'fa-picture-o' );
107 }
108 break;
109 }
110 } else {
111 unset( $post_media );
112 return '';
113 }
114 $html = ($type == 'text') ? $post_media_text : $post_media_count;
115 $multi_class = $post_media_count > 1 ? ' ctf-multi-media-icon' : '';
116
117 if ( $feed_options['linktexttotwitter'] ) {
118 return $html;
119 } elseif ( $feed_options['disablelinks'] ) {
120 $return = '<span class="ctf-tweet-text-media-wrap'.$multi_class.'">' . $html . '</span>';
121 } else {
122 $return = '</p><a href="https://twitter.com/' . $post['user']['screen_name'] . '/status/' . $post['id_str'] . '" target="_blank" rel="noopener noreferrer" class="ctf-tweet-text-media-wrap'.$multi_class.'">' . $html . '</a>';
123 }
124
125 return $return;
126 }
127 /**
128 * Display Feed Header
129 *
130 * @param array $settings
131 *
132 * @return string
133 *
134 * @since 2.0
135 */
136 public static function display_header( $feed_options, $tweet_set ){
137 if ( empty( $tweet_set ) || (isset( $tweet_set[0] ) && is_string( $tweet_set[0] ) && $tweet_set[0] === 'error') ) {
138 return;
139 }
140 if( ctf_doing_customizer( $feed_options ) ){
141 $header_template = 'header-generic';
142 if ( $feed_options['type'] === 'usertimeline' || $feed_options['type'] === 'mentionstimeline' || $feed_options['type'] === 'hometimeline' ) {
143 $header_template = 'header';
144 }
145 include ctf_get_feed_template_part( $header_template, $feed_options );
146 include ctf_get_feed_template_part( 'header-text', $feed_options );
147 }else{
148 include ctf_get_feed_template_part( CTF_Display_Elements::header_type( $feed_options ), $feed_options );
149 }
150 }
151
152 public static function header_type( $feed_options ) {
153 $header_template = 'header-generic';
154 if ( $feed_options['type'] === 'usertimeline' || $feed_options['type'] === 'mentionstimeline' || $feed_options['type'] === 'hometimeline' ) {
155 $header_template = 'header';
156 }
157
158 if( isset( $feed_options['headerstyle'] ) && $feed_options['headerstyle'] == 'text'){
159 $header_template = 'header-text';
160 }
161
162 return $header_template;
163 }
164
165 /**
166 * Should Show Element
167 *
168 * @param array $settings
169 * @param string $setting_name
170 * @param bool $custom_condition
171 *
172 * @return string
173 *
174 * @since 2.0
175 */
176 public static function should_show_element_vue( $settings, $setting_name, $custom_condition = false ) {
177 $customizer = ctf_doing_customizer( $settings );
178 if ( $customizer ) {
179 return ' v-if="$parent.valueIsEnabled($parent.customizerFeedData.settings.' . $setting_name . ')' . ( $custom_condition != false ? $custom_condition : '' ) . '" ';
180 }
181 return '';
182 }
183
184 /**
185 * Should Print HTML
186 *
187 * @param bool $customizer
188 * @param string $content
189 *
190 * @return string
191 *
192 * @since 2.0
193 */
194 public static function should_print_element_vue( $customizer, $content ) {
195 if ( $customizer ) {
196 return ' v-html="' . $content . '" ';
197 }
198 return '';
199 }
200
201 /**
202 * Should Print HTML
203 *
204 * @param bool $customizer
205 * @param string $condition
206 *
207 * @return string
208 *
209 * @since 2.0
210 */
211 public static function create_condition_vue( $customizer, $condition ) {
212 if ( $customizer ) {
213 return ' v-if="' . $condition . '" ';
214 }
215 return '';
216 }
217
218 /**
219 * Should Show Print HTML
220 *
221 * @param bool $customizer
222 * @param string $condition
223 *
224 * @return string
225 *
226 * @since 2.0
227 */
228 public static function create_condition_show_vue( $customizer, $condition ) {
229 if ( $customizer ) {
230 return ' v-show="' . $condition . '" ';
231 }
232 return '';
233 }
234
235 /**
236 * Print Element HTML Attribute
237 *
238 * @param bool $customizer
239 * @param array $args
240 *
241 * @return string
242 *
243 * @since 2.0
244 */
245 public static function print_element_attribute( $customizer, $args ) {
246 if ( $customizer ) {
247 return ' :' . $args['attr'] . '="' . $args['vue_content'] . '"';
248 }
249 if( ( isset( $args['php_condition'] ) && $args['php_condition'] ) || !isset( $args['php_condition'] ) ){
250 return ' ' . $args['attr'] . '="' . $args['php_content'] . '"';
251 }
252 }
253
254 /**
255 * Print Element HTML Attribute
256 *
257 * @param bool $customizer
258 * @param array $args
259 *
260 * @return string
261 *
262 * @since 2.0
263 */
264 public static function get_element_attribute( $element, $settings ) {
265 $customizer = ctf_doing_customizer( $settings );
266 if( $customizer ){
267 switch ($element) {
268 case 'author':
269 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_author)');
270 break;
271 case 'avatar':
272 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_author) && $parent.valueIsEnabled($parent.customizerFeedData.settings.include_avatar)');
273 break;
274 case 'author_text':
275 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_author) && $parent.valueIsEnabled($parent.customizerFeedData.settings.include_author_text)');
276 break;
277 case 'date':
278 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_date)');
279 break;
280 case 'logo':
281 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_logo)');
282 break;
283 case 'text_and_link':
284 return CTF_Display_Elements::create_condition_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_text) && $parent.valueIsEnabled($parent.customizerFeedData.settings.linktexttotwitter)');
285 break;
286 case 'text_no_link':
287 return CTF_Display_Elements::create_condition_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_text) && !$parent.valueIsEnabled($parent.customizerFeedData.settings.linktexttotwitter)');
288 break;
289 case 'linkbox':
290 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_linkbox)');
291 break;
292 case 'media':
293 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_media)');
294 break;
295 case 'repliedto':
296 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_replied_to)');
297 break;
298 case 'retweeter':
299 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_retweeter)');
300 break;
301 case 'loadmore':
302 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showbutton) && $parent.customizerFeedData.settings.layout !== \'carousel\' ') . ' ' . CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.customizerFeedData.settings.buttontext' );
303 break;
304 case 'headerbio':
305 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showbio)');
306 break;
307 case 'header':
308 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showheader) && $parent.customizerFeedData.settings.headerstyle === \'standard\' ');
309 break;
310 case 'header-text':
311 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showheader) && $parent.customizerFeedData.settings.headerstyle === \'text\' ') . ' ' . CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.customizerFeedData.settings.customheadertext' );
312 break;
313 case 'actions':
314 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_actions)');
315 break;
316 case 'viewtwitterlink':
317 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.viewtwitterlink)');
318 break;
319 case 'viewtwitterlink_text':
320 return CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.customizerFeedData.settings.twitterlinktext' );
321 break;
322 case 'twitter_cards':
323 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.customizerFeedData.settings.include_twittercards' );
324 break;
325 case 'linkto':
326 return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.customizerFeedData.settings.linktexttotwitter' );
327 break;
328
329 }
330 }
331
332 return '';
333 }
334
335
336 /**
337 * Should Show Element
338 *
339 * @param array $settings
340 * @param string $setting_name
341 * @param bool $custom_condition
342 *
343 * @return string
344 *
345 * @since 2.0
346 */
347 public static function get_feed_container_data_attributes( $settings, $feed_id, $twitter_feed_id ) {
348 $customizer = ctf_doing_customizer( $settings );
349
350 $atts = CTF_Display_Elements::print_element_attribute(
351 $customizer,
352 array(
353 'attr' => 'data-ctfdisablelinks',
354 'vue_content' => '$parent.customizerFeedData.settings.disablelinks',
355 'php_content' => self::cast_boolean($settings['disablelinks']) ? 'true' : 'false',
356 )
357 );
358
359 $atts .= CTF_Display_Elements::print_element_attribute(
360 $customizer,
361 array(
362 'attr' => 'data-ctflinktextcolor',
363 'vue_content' => '$parent.customizerFeedData.settings.linktextcolor',
364 'php_content' => $settings['linktextcolor'],
365 )
366 );
367 /*
368
369 $atts .= CTF_Display_Elements::print_element_attribute(
370 $customizer,
371 array(
372 'attr' => 'data-ctfscrolloffset',
373 'vue_content' => '$parent.valueIsEnabled($parent.customizerFeedData.settings.autoscroll) ? $parent.customizerFeedData.settings.autoscrolldistance : false',
374 'php_condition' => CTF_Feed_Builder::check_if_on( $settings['autoscroll'] ),
375 'php_content' => $settings['autoscrolldistance'],
376 )
377 );
378 */
379 /*
380 */
381
382 $atts .= CTF_Display_Elements::print_element_attribute(
383 $customizer,
384 array(
385 'attr' => 'data-boxshadow',
386 'vue_content' => ' $parent.customizerFeedData.settings.tweetpoststyle === \'boxed\' && $parent.valueIsEnabled($parent.customizerFeedData.settings.tweetboxshadow) ? \'true\' : \'false\' ',
387 'php_condition' => $settings['tweetpoststyle'] === 'boxed' && CTF_Feed_Builder::check_if_on( $settings['tweetboxshadow'] ),
388 'php_content' => "true",
389 )
390 );
391 $atts .= CTF_Display_Elements::print_element_attribute(
392 $customizer,
393 array(
394 'attr' => 'data-header-size',
395 'vue_content' => '$parent.customizerFeedData.settings.customheadersize',
396 'php_content' => $settings['customheadersize'],
397 )
398 );
399
400 //Global Feed Atts
401 $atts .= ' data-feedid="' . esc_attr($feed_id) . '" data-postid="' . esc_attr(get_the_ID()) . '" ';
402 if ( ! empty( $settings['feed'] ) ) {
403 $atts .= ' data-feed="' . esc_attr($settings['feed']) . '"';
404 }
405 $flags = array();
406 $dbsettings = ctf_get_database_settings();
407
408 if ( CTF_GDPR_Integrations::doing_gdpr( $dbsettings ) ) {
409 $flags[] = 'gdpr';
410 }
411 if ( !is_admin() && CTF_Feed_Locator::should_do_ajax_locating( $twitter_feed_id , get_the_ID() ) ) {
412 $flags[] = 'locator';
413 }
414 if (!empty($flags)) {
415 $atts .= ' data-ctf-flags="' . implode(',', $flags) . '"';
416 }
417
418 return $atts;
419 }
420
421
422 public static function cast_boolean( $value ) {
423 if ( $value === 'true' || $value === true || $value === 'on' ) {
424 return true;
425 }
426 return false;
427 }
428
429
430 /**
431 * Get Post Date TExt Attribure
432 *
433 *
434 * @return string
435 *
436 * @since 2.0
437 */
438 public static function get_post_date_attr($created_at, $settings ) {
439 $customizer = ctf_doing_customizer( $settings );
440 return CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.printDate(\''.$created_at.'\')' );
441 }
442 /**
443 * Some characters in captions are breaking the customizer.
444 *
445 * @param $caption
446 *
447 * @return mixed
448 */
449 public static function sanitize_caption( $caption ) {
450 $caption = str_replace( array( "'" ), '`', $caption );
451 $caption = str_replace( '&amp;', '&', $caption );
452 $caption = str_replace( '&lt;', '<', $caption );
453 $caption = str_replace( '&gt;', '>', $caption );
454 $caption = str_replace( '&quot;', '"', $caption );
455 $caption = str_replace( '&#039;', '/', $caption );
456 $caption = str_replace( '&#92;', '\/', $caption );
457
458 $caption = str_replace( array( "\r", "\n" ), '<br>', $caption );
459 $caption = str_replace( '&lt;br /&gt;', '<br>', nl2br( $caption ) );
460
461 return $caption;
462 }
463 /**
464 * Get Post Text Attributes
465 *
466 *
467 * @return string
468 *
469 * @since 2.0
470 */
471 public static function get_post_text_attr( $post_text, $settings, $post_id ) {
472 $customizer = ctf_doing_customizer( $settings );
473 if( $customizer ){
474 $post_text = self::sanitize_caption( $post_text );
475 return ' v-html="$parent.getPostText(\'' . htmlspecialchars( $post_text ) . '\', ' . $post_id . ')"';
476 }
477 return '';
478 }
479
480 public static function post_text( $post, $feed_options ) {
481 $text = isset($post['text']) ? $post['text'] : (isset($post['full_text']) ? $post['full_text'] : '');
482 $post_text = apply_filters( 'ctf_tweet_text', $text, $feed_options, $post );
483
484 return $post_text;
485 }
486
487 /**
488 * Get Post Text
489 *
490 *
491 * @return string
492 *
493 * @since 2.0
494 */
495 public static function get_post_text( $feed_options, $post_text, $post_id, $author_screen_name, $post_media_text ) {
496 $customizer = ctf_doing_customizer( $feed_options );
497 $post_text_attr = CTF_Display_Elements::get_post_text_attr( $post_text, $feed_options, $post_id );
498 $text_and_link_attr = CTF_Display_Elements::get_element_attribute( 'text_and_link', $feed_options );
499 $text_no_link_attr = CTF_Display_Elements::get_element_attribute( 'text_no_link', $feed_options );
500 if( !$customizer ){
501 if( $feed_options['linktexttotwitter'] ){ ?>
502 <a class="ctf-tweet-text-link" href="<?php echo esc_url( 'https://twitter.com/' . $author_screen_name . '/status/' .$post_id ) ?>" target = "_blank" rel = "noopener noreferrer">
503 <?php } ?>
504 <p class="ctf-tweet-text">
505 <?php echo wp_kses_post( nl2br( $post_text ) ) ?>
506 <?php
507 if(!$feed_options['is_legacy'] || ($feed_options['is_legacy'] && ctf_show( 'placeholder', $feed_options ))){
508 echo $post_media_text;
509 }
510 ?>
511 </p>
512 <?php if( $feed_options['linktexttotwitter'] ){ ?>
513 </a>
514 <?php } ?>
515 <?php
516 }else{
517 ?>
518 <a class="ctf-tweet-text-link" <?php echo $text_and_link_attr; ?> href="<?php echo esc_url( 'https://twitter.com/' . $author_screen_name . '/status/' .$post_id ) ?>" target = "_blank" rel = "noopener noreferrer">
519 <p class="ctf-tweet-text" <?php echo $post_text_attr; ?>></p>
520 </a>
521 <p class="ctf-tweet-text" <?php echo $text_no_link_attr; ?> <?php echo $post_text_attr; ?>><?php echo wp_kses_post( nl2br( $post_text ) ) ?></p>
522 <?php
523 if(!$feed_options['is_legacy'] || ($feed_options['is_legacy'] && ctf_show( 'placeholder', $feed_options ))){
524 echo $post_media_text;
525 }
526 ?>
527 <?php
528 }
529 }
530
531 public static function get_ajax_code( $feed_options ) {
532 $json_array = array(
533 'ajax_url' => admin_url( 'admin-ajax.php' ),
534 'font_method' => 'svg',
535 'placeholder' => trailingslashit( CTF_PLUGIN_URL ) . 'img/placeholder.png'
536 );
537 return '<script> var ctfOptions = ' . ctf_json_encode( $json_array ) . '</script><script type="text/javascript" src="'. CTF_JS_URL .'"></script>';
538 }
539
540 public static function display_action_links( $feed_options ) {
541 return ctf_show( 'actions', $feed_options ) || (isset($feed_options['is_legacy']) && $feed_options['is_legacy'] == true);
542 }
543
544 }
545