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 / TweetAdapter.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
TweetAdapter.php
73 lines
1 <?php
2
3 /**
4 * Class for converting tweet sub attribute from Twitter API v1.1 to v2.
5 *
6 * @package twitter-api-v2
7 */
8
9 namespace TwitterFeed\V2;
10
11 // Don't load directly.
12 if (! defined('ABSPATH')) {
13 die('-1');
14 }
15
16 /**
17 * TweetAdapter class.
18 */
19 class TweetAdapter extends Adapter {
20 /**
21 * Get mapped fields.
22 *
23 * @return string[]
24 */
25 public function getMappedFields()
26 {
27 return [
28 'id_str' => 'id',
29 'conversation_id' => 'conversation_id_str',
30 ];
31 }
32
33 /**
34 * Remove retweet prefix.
35 *
36 * @param string $text Tweet text.
37 *
38 * @return string
39 */
40 public function removeRetweetPrefix($text)
41 {
42 if (strpos($text, 'RT') !== 0) {
43 return $text;
44 }
45
46 preg_match('/^RT\s*@[^:]*:(.*)/s', $text, $matches);
47
48 if (! isset($matches[1])) {
49 return $text;
50 }
51
52 return $matches[1];
53 }
54
55 /**
56 * Convert entity from v1.1 to v2 format.
57 *
58 * @param array $entity Entity.
59 *
60 * @return array
61 */
62 public function convert($entity)
63 {
64 $entity['text'] = $this->removeRetweetPrefix($entity['text']);
65
66 if (isset($entity['retweeted_status']['text'])) {
67 $entity['retweeted_status']['text'] = $this->removeRetweetPrefix($entity['retweeted_status']['text']);
68 }
69
70 return parent::convert($entity);
71 }
72 }
73