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 / V2 / MediaAdapter.php
custom-twitter-feeds / inc / V2 Last commit date
Adapter.php 1 month ago CtfOauthConnect.php 1 month ago MediaAdapter.php 1 month ago TweetAdapter.php 1 month ago TwitterHelperApi.php 1 month ago UserAdapter.php 1 month ago
MediaAdapter.php
84 lines
1 <?php
2
3 namespace TwitterFeed\V2;
4
5 /**
6 * Class for converting media attribute from Twitter API v1.1 to v2.
7 *
8 * @package twitter-api-v2
9 */
10 class MediaAdapter
11 {
12 /**
13 * Tweet data.
14 *
15 * @var array
16 */
17 protected $tweet;
18
19 /**
20 * Included media.
21 *
22 * @var array
23 */
24 protected $included_media;
25
26 /**
27 * Constructor.
28 *
29 * @param array $tweet Tweet data.
30 * @param array $included_media Included media data.
31 */
32 public function __construct($tweet, $included_media)
33 {
34 $this->tweet = $tweet;
35 $this->included_media = $included_media;
36 }
37
38 /**
39 * Get media keys.
40 *
41 * @return array
42 */
43 public function getMediaKeys()
44 {
45 return ! empty($this->tweet['attachments']['media_keys']) ? $this->tweet['attachments']['media_keys'] : [];
46 }
47
48 /**
49 * Convert.
50 *
51 * @return array
52 */
53 public function convert()
54 {
55 $media_array = [];
56
57 foreach ($this->getMediaKeys() as $media_key_index => $media_key_value) {
58 $media_index = array_search(
59 $this->tweet['attachments']['media_keys'][ $media_key_index ],
60 array_column($this->included_media, 'media_key')
61 );
62
63 if ($media_index !== false) {
64 $media = [
65 'media_url_https' => !empty($this->included_media[ $media_index ]['url'])
66 ? $this->included_media[ $media_index ]['url']
67 : $this->included_media[ $media_index ]['preview_image_url'],
68 'type' => $this->included_media[ $media_index ]['type'],
69 ];
70
71 if (isset($new_media['type']) && $new_media['type'] === 'video') {
72 $media['video_info'] = [
73 'variants' => $this->included_media[ $media_index ]['variants'],
74 ];
75 }
76
77 $media_array[] = $media;
78 }
79 }
80
81 return $media_array;
82 }
83 }
84