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_Parse.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_Parse.php
552 lines
1 <?php
2 /**
3 * Class CTF_Parse
4 *
5 *
6 * @since 2.0
7 */
8 namespace TwitterFeed;
9
10 use TwitterFeed\CtfFeed;
11 use TwitterFeed\V2\CtfOauthConnect;
12 use TwitterFeed\CTF_GDPR_Integrations;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 die( '-1' );
16 }
17
18 class CTF_Parse{
19
20
21 /**
22 * Get Tweet ID
23 *
24 * @since 2.0
25 */
26 public static function get_tweet_id( $data ) {
27 return $data['id_str'];
28 }
29
30 public static function get_post_id( $data ) {
31 return $data['id_str'];
32 }
33
34 /**
35 * Get Tweet Author User name
36 *
37 * @since 2.0
38 */
39 public static function get_user_name( $data ) {
40 if ( ! empty( $data['screen_name'] ) ) {
41 return $data['screen_name'];
42 }
43 if ( ! empty( $data['user']['screen_name'] ) ) {
44 return $data['user']['screen_name'];
45 }
46 return '';
47 }
48
49 /**
50 * Get Tweet Author Name
51 *
52 * @since 2.0
53 */
54 public static function get_author_name( $data ) {
55 return strtolower( $data['user']['name'] );
56 }
57
58 /**
59 * Get Tweet Author Name
60 *
61 * @since 2.0
62 */
63 public static function get_display_author_name( $data ) {
64 return $data['user']['name'];
65 }
66
67 /**
68 * Get Tweet Author Screen Name
69 *
70 * @since 2.0
71 */
72 public static function get_author_screen_name( $data ) {
73 if ( ! empty( $data['user'] ) ) {
74 if ( is_array( $data['user'] ) ) {
75 return strtolower( $data['user']['screen_name'] );
76 } else {
77 return strtolower( $data['user'] );
78 }
79 }
80 if ( ! empty( $data['screen_name'] ) ) {
81 return strtolower( $data['screen_name'] );
82 }
83 return '';
84 }
85
86 public static function get_quoted_name( $data ) {
87 return $data['user']['name'];
88 }
89
90 public static function get_quoted_screen_name( $data ) {
91 return $data['user']['screen_name'];
92 }
93
94 /**
95 * Get Tweet Verified
96 *
97 * @since 2.0
98 */
99 public static function get_quoted_verified( $data ) {
100 return $data['user']['verified'];
101 }
102
103
104 /**
105 * Get Tweet Post
106 *
107 * @since 2.0
108 */
109 public static function get_post($tweet_set) {
110 if ( isset( $tweet_set['retweeted_status'] ) ) {
111 return $tweet_set['retweeted_status'];
112 } else {
113 return $tweet_set;
114 }
115 }
116
117 /**
118 * Get Tweet Avatar URL
119 *
120 * @since 2.0
121 */
122 public static function get_avatar_url( $post, $feed_options ) {
123 if ( CTF_GDPR_Integrations::doing_gdpr( $feed_options ) ) {
124 return trailingslashit( CTF_PLUGIN_URL ) . 'img/placeholder.png';
125 }
126
127 return self::get_avatar( $post );
128 }
129
130 /**
131 * Get Tweet Avatar
132 *
133 * @since 2.0
134 */
135 public static function get_avatar( $data ) {
136 if ( isset( $data['retweeted_status'] ) ) {
137 return $data['retweeted_status']['user']['profile_image_url_https'];
138 } elseif ( isset( $data['user'] ) ) {
139 return $data['user']['profile_image_url_https'];
140 } elseif ( isset( $data['profile_image_url_https'] ) ) {
141 return $data['profile_image_url_https'];
142 }
143 return '';
144 }
145
146 /**
147 * Get Tweet UTS Offset
148 *
149 * @since 2.0
150 */
151 public static function get_utc_offset ( $data ) {
152 if ( empty( $data['user']['utc_offset'] ) ) {
153 return 0;
154 }
155 return $data['user']['utc_offset'];
156 }
157
158 /**
159 * Get Tweet Original TimeStamp
160 *
161 * @since 2.0
162 */
163 public static function get_original_timestamp( $data ) {
164 return $data['created_at'];
165 }
166
167 /**
168 * Get Tweet Author Verified
169 *
170 * @since 2.0
171 */
172 public static function get_verified ( $data ) {
173 return $data['user']['verified'];
174 }
175
176
177 /**
178 * Get Generic Header Text
179 *
180 * @since 2.0
181 */
182 public static function get_generic_header_text( $data ) {
183 if ( $data['type'] === 'search' || $data['type'] === 'hashtag' ) {
184 $using_custom = $data['headertext'] != '';
185 $raw_header_text = $using_custom ? $data['headertext'] : $data['feed_term'];
186
187 //List multiple terms
188 $hashtags = explode(" OR ", $data['feed_term'] ?? '');
189 if ( ! $using_custom ) {
190 $default_header_text = '';
191 $h_index = 0;
192 foreach ( $hashtags as $hashtag ) {
193 if( $h_index > 0 ) $default_header_text .= ', ';
194 $default_header_text .= $hashtag;
195 $h_index++;
196 }
197 } else {
198 $default_header_text = $data['headertext'];
199 }
200
201 $default_header_text = str_replace( ' -filter:retweets', '', $default_header_text );
202
203
204 return $default_header_text;
205
206 } else {
207 $default_header_text = 'Twitter';
208 // $url_part = $data['screenname']; //Need to get screenname here
209 return $default_header_text;
210 }
211
212 //Header for combined feed types
213 if ( ! empty( $data['feed_types_and_terms'] ) ) {
214 if ( $data['headertext'] != '' ) {
215 $default_header_text = $data['headertext'];
216
217 if ( $data['feed_types_and_terms'][0][0] === 'search' || $data['feed_types_and_terms'][0][0] === 'hashtag' ) {
218 $raw_header_text = $data['feed_types_and_terms'][0][1];
219 }
220
221 return $default_header_text;
222
223 } else {
224 $default_header_text = '';
225 $i_term = 0;
226 foreach ( $data['feed_types_and_terms'] as $feed_set ) {
227 if ( $feed_set[0] == 'lists' ) {
228 $default_header_text .= '';
229 } else {
230 if ( $i_term > 0 ) {
231 $default_header_text .= ', ';
232 }
233 if ( $feed_set[0] == 'usertimeline' ) {
234 $default_header_text .= '@';
235 }
236 $default_header_text .= $feed_set[1];
237 }
238 $i_term++;
239 }
240 }
241
242 if ( empty( $default_header_text ) ) {
243 return $default_header_text = 'Twitter';
244 }
245
246 }
247 }
248
249
250 /**
251 * Get Generic Header URL
252 *
253 * @since 2.0
254 */
255 public static function get_generic_header_url ( $data ) {
256 $hashtags = isset($data['feed_term']) ? explode(" OR ", $data['feed_term']) : '';
257 if ( $data['type'] === 'search' || $data['type'] === 'hashtag' ) {
258 if ( $data['type'] === 'hashtag' ) {
259 $url_part = 'hashtag/' . str_replace("#", "", $hashtags[0]);
260 } else {
261 $url_part = 'search?q=' . rawurlencode( str_replace( array( ', ', "'" ), array( ' OR ', '"' ), $data['feed_term'] ) );
262 }
263
264 return $url_part;
265 }
266
267 if ( ! empty( $data['feed_types_and_terms'] ) ) {
268 if ( $data['feed_types_and_terms'][0][0] === 'search' || $data['feed_types_and_terms'][0][0] === 'hashtag' ) {
269 $raw_header_text = $data['feed_types_and_terms'][0][1];
270 //List multiple terms
271 $hashtags = explode( " OR ", $data['feed_types_and_terms'][0][1] );
272
273 if ( $data['feed_types_and_terms'][0][0] === 'hashtag' ) {
274 $url_part = 'hashtag/' . str_replace( "#", "", $hashtags[0] );
275
276 return $url_part;
277 } else {
278 $url_part = 'search?q=' . rawurlencode( str_replace( array( ', ', "'" ), array(
279 ' OR ',
280 '"'
281 ), $data['feed_types_and_terms'][0][1] ) );
282
283 return $url_part;
284 }
285 }
286 }
287
288 }
289
290
291 /**
292 * Get Header Text
293 *
294 * @since 2.0
295 */
296 public static function get_header_text( $header_info, $feed_options ) {
297 if ( empty( $header_info ) || ! is_array( $header_info ) ) {
298 return '';
299 }
300
301 if ( $feed_options['headertext'] !== '' ) {
302 $header_text = $feed_options['headertext'];
303 return $header_text;
304 } else {
305 $header_text = $header_info['name'];
306 return $header_text;
307 }
308 }
309
310
311 /**
312 * Get Header Description
313 *
314 * @since 2.0
315 */
316 public static function get_header_description( $data ) {
317 return $data['description'];
318 }
319
320
321
322 /**
323 * Get User Header JSON info
324 *
325 * @since 2.0
326 */
327 public static function get_user_header_json( $data, $post_info ) {
328 $type = ! empty( $data['type'] ) ? $data['type'] : 'usertimeline';
329
330 $types_and_terms = isset($data['feed_types_and_terms']) ? $data['feed_types_and_terms'] : [];
331
332 $timelines_included = array();
333 foreach ( $types_and_terms as $type_and_term ) {
334 if ( $type_and_term[0] === 'usertimeline' ) {
335 $timelines_included[] = str_replace( '@', '', strtolower( $type_and_term[1] ) );
336 }
337 }
338
339 if ( $type === 'usertimeline' ) {
340 if ( ! empty( $post_info[0]['user'] ) ) {
341 return $post_info[0]['user'];
342 }
343
344 }
345
346 return array();
347 }
348
349
350 /**
351 * Get User Header Avatar
352 *
353 * @since 2.0
354 */
355 public static function get_header_avatar( $data, $feed_options = array() ) {
356 $settings = ctf_get_database_settings();
357 if ( CTF_GDPR_Integrations::doing_gdpr( $settings ) ) {
358 $avatar = trailingslashit( CTF_PLUGIN_URL ) . 'img/placeholder.png';
359 } else {
360 $avatar = $data['profile_image_url_https'];
361 }
362
363 return $avatar;
364 }
365
366 public static function get_quoted_tc( $data ) {
367
368 $quoted = false;
369
370 // check for quoted
371 if ( isset( $data['quoted_status'] ) ) {
372 $quoted = $data['quoted_status'];
373 return $quoted;
374 } else {
375 unset( $quoted );
376 }
377
378 }
379
380 public static function get_quoted_media( $data, $num_media ) {
381 //Quoted Tweets Media
382 $quoted_media = [];
383
384 if ( isset( $data['extended_entities']['media'] ) ) {
385
386 $num_media = count( $data['extended_entities']['media'] );
387 for( $ii = 0; $ii < $num_media; $ii++ ) {
388 if ( $data['extended_entities']['media'][$ii]['type'] == 'video' || $data['extended_entities']['media'][$ii]['type'] == 'animated_gif' ) {
389 $quoted_media[$ii]['url'] = $data['extended_entities']['media'][$ii]['video_info']['variants'][$ii]['url'];
390 } else {
391 $quoted_media[$ii]['url'] = $data['extended_entities']['media'][$ii]['media_url_https'];
392 }
393 $quoted_media[$ii]['type'] = $data['extended_entities']['media'][$ii]['type'];
394 if ( $quoted_media[$ii]['type'] == 'video' ) {
395 $quoted_media[$ii]['video_atts'] = 'controls';
396 } elseif ( $quoted_media[$ii]['type'] == 'animated_gif' ) {
397 $quoted_media[$ii]['video_atts'] = 'controls loop autoplay muted';
398 }
399 $quoted_media[$ii]['poster'] = $data['extended_entities']['media'][$ii]['media_url_https'];
400 }
401
402 } elseif ( isset( $data['entities']['media'] ) ) {
403
404 $num_media = count( $data['entities']['media'] );
405 for( $ii = 0; $ii < $num_media; $ii++ ) {
406 if ( $data['entities']['media'][$ii]['type'] == 'video' || $data['entities']['media'][$ii]['type'] == 'animated_gif' ) {
407 $quoted_media[$ii]['url'] = $data['entities']['media'][$ii]['video_info']['variants'][$ii]['url'];
408 } else {
409 $quoted_media[$ii]['url'] = $data['entities']['media'][$ii]['media_url_https'];
410 }
411 $quoted_media[$ii]['type'] = $data['entities']['media'][$ii]['type'];
412 if ( $quoted_media[$ii]['type'] == 'video' ) {
413 $quoted_media[$ii]['video_atts'] = 'controls';
414 } elseif ( $quoted_media[$ii]['type'] == 'animated_gif' ) {
415 $quoted_media[$ii]['video_atts'] = 'controls loop autoplay muted';
416 }
417 $quoted_media[$ii]['poster'] = $data['entities']['media'][$ii]['media_url_https'];
418 }
419
420 }
421
422 return $quoted_media;
423 }
424
425 /**
426 * Get Feed Classes
427 *
428 * @since 2.0
429 */
430 public static function get_feed_classes( $feed_options, $check_for_duplicates, $feed_id = false) {
431 if( ctf_doing_customizer( $feed_options ) ){
432 return ' :class="$parent.getFeedClasses()" ';
433 }else{
434 $ctf_feed_classes = 'ctf ctf-type-' . CTF_Parse::get_feed_type( $feed_options );
435 $ctf_feed_classes .= \ctf_should_rebrand_to_x() ? ' ctf-rebranded' : '';
436 $ctf_feed_classes .= ($feed_id !== false ) ? ' ctf-feed-' . $feed_id : '';
437 $ctf_feed_classes .= ' ' . $feed_options['class'] . ' ctf-styles';
438 $ctf_feed_classes .= ($feed_options['layout']) ? ' ctf-' . $feed_options['layout']: '';
439 $ctf_feed_classes .= ( isset( $feed_options['tweetpoststyle'] ) ) ? ' ctf-' . $feed_options['tweetpoststyle'] . '-style' : '';
440 if ( ! empty( $feed_options['height'] ) ) $ctf_feed_classes .= ' ctf-fixed-height';
441 $ctf_feed_classes .= $feed_options['width_mobile_no_fixed'] ? ' ctf-width-resp' : '';
442 if ( $check_for_duplicates ) { $ctf_feed_classes .= ' ctf-no-duplicates'; }
443 if( isset($feed_options['colorpalette']) && $feed_options['colorpalette'] !== 'inherit' && $feed_id !== false ){
444 $feed_id_class = $feed_options['colorpalette'] === 'custom' ? ('_' . $feed_id) : '';
445 $ctf_feed_classes .= ' ctf_palette_' . $feed_options['colorpalette'] . $feed_id_class;
446 }
447 $ctf_feed_classes = apply_filters( 'ctf_feed_classes', $ctf_feed_classes );
448 return 'class=" ' . $ctf_feed_classes .'" ';
449 }
450
451 }
452
453 public static function get_tweet_count( $data ) {
454
455 if ( isset( $data['statuses'] ) && is_array( $data['statuses'] ) ) {
456 $tweet_count = count( $data['statuses'] );
457 } elseif ( is_array( $data ) ) {
458 $tweet_count = count( $data );
459 } else {
460 $tweet_count = 0;
461 }
462
463 return $tweet_count;
464 }
465 /**
466 * Get Feed Type
467 *
468 * @since 2.0
469 */
470 public static function get_feed_type( $feed_options ) {
471 $ctf_feed_type = ! empty ( $feed_options['type'] ) ? $feed_options['type'] : 'multiple';
472 return $ctf_feed_type;
473 }
474
475 public static function get_retweet_count( $data ) {
476 if ( isset( $data['retweeted_status']['retweet_count'] ) ) {
477 return $data['retweeted_status']['retweet_count'];
478 } else {
479 return $data['retweet_count'];
480 }
481 }
482
483 public static function get_favorite_count( $data ) {
484 if ( isset( $data['retweeted_status']['favorite_count'] ) ) {
485 return $data['retweeted_status']['favorite_count'];
486 } else {
487 return $data['favorite_count'];
488 }
489 }
490
491 /**
492 * Get Global Twitter Feed CSS
493 *
494 * @since 2.0
495 * @return array
496 */
497 public static function parse_css_style ( $css_array ) {
498 $style = '';
499 $color_elements = [
500 'color',
501 'background',
502 'background-color'
503 ];
504
505 $size_elements = [
506 'border-radius',
507 'height',
508 'width',
509 'font-size',
510 'margin',
511 'margin-top',
512 'margin-bottom',
513 'margin-left',
514 'margin-right',
515 'padding',
516 'padding-top',
517 'padding-bottom',
518 'padding-left',
519 'padding-right'
520 ];
521
522 $border_elements = [
523 'border',
524 'border-top',
525 'border-bottom',
526 'border-left',
527 'border-right'
528 ];
529
530 foreach ($css_array as $element) {
531 $items_css = '';
532 if( isset( $element['properties'] ) ){
533 foreach ($element['properties'] as $property => $item) {
534 if( in_array( $property, $color_elements) && !empty( $item['value'] ) && $item['value'] !== '#' ){
535 $items_css .= $property . ':' . stripcslashes($item['value']) . ( isset( $item['important'] ) ? '!important;' : ';' );
536 }
537 if( in_array( $property, $size_elements) && !empty( $item['value'] ) && $item['value'] !== '0' && $item['value'] !== 'inherit' ){
538 $items_css .= $property . ':' . stripcslashes($item['value']) . ( isset( $item['unit'] ) ? $item['unit'] : 'px' ) . ( isset( $item['important'] ) ? '!important;' : ';' );
539 }
540 if( in_array( $property, $border_elements) && !empty( $item['size'] ) && $item['size'] !== '0' && !empty( $item['color'] ) && $item['color'] !== '#' ){
541 $items_css .= $property . ':' . stripcslashes($item['size']) . 'px ' . ( isset( $item['style'] ) ? $item['style'] : 'solid' ) . ' ' . stripcslashes($item['color']) . ( isset( $item['important'] ) ? '!important;' : ';' );
542 }
543 }
544 $style .= !empty($items_css) ? $element['selector'] . '{'.$items_css .'}' : '';
545 }
546 }
547
548 return $style;
549 }
550
551 }
552