Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible truncation issue #19

Closed
alexkingorg opened this issue Nov 13, 2012 · 3 comments
Closed

Possible truncation issue #19

alexkingorg opened this issue Nov 13, 2012 · 3 comments

Comments

@alexkingorg
Copy link
Contributor

http://wordpress.org/support/topic/incomplete-twitt-is-inserted-to-the-db?replies=2

@trustin
Copy link

trustin commented Oct 4, 2013

When I retweet this: https://twitter.com/nrjeon/status/385997195335303168
The URL at the end of the tweet is truncated.

@trustin
Copy link

trustin commented Oct 4, 2013

The following patch fixes the problem:

diff -urN a/classes/aktt_tweet.php b/classes/aktt_tweet.php
--- a/classes/aktt_tweet.php    2013-10-05 01:18:26.000000000 +0900
+++ b/classes/aktt_tweet.php    2013-10-05 01:19:38.000000000 +0900
@@ -90,6 +90,9 @@
     * @return string
     */
    public function content() {
+                if ($this->is_native_retweet()) {
+           return $this->data->retweeted_status->text;
+       }
        if (isset($this->data) && isset($this->data->text)) {
            return $this->data->text;
        }
@@ -141,7 +144,11 @@
     * @return string
     */
    public function hashtags() {
-       return (isset($this->data) && isset($this->data->entities) ? $this->data->entities->hashtags : array());
+       if ($this->is_native_retweet()) {
+           return (isset($this->data->retweeted_status->entities) ? $this->data->retweeted_status->entities->hashtags : array());
+       } else {
+           return (isset($this->data) && isset($this->data->entities) ? $this->data->entities->hashtags : array());
+       }
    }

    /**
@@ -150,7 +157,11 @@
     * @return string
     */
    public function mentions() {
-       return (isset($this->data) && isset($this->data->entities) ? $this->data->entities->user_mentions : array());
+       if ($this->is_native_retweet()) {
+           return (isset($this->data->retweeted_status->entities) ? $this->data->retweeted_status->entities->user_mentions : array());
+       } else {
+           return (isset($this->data) && isset($this->data->entities) ? $this->data->entities->user_mentions : array());
+       }
    }

    /**
@@ -159,7 +170,11 @@
     * @return string
     */
    public function urls() {
-       return (isset($this->data) && isset($this->data->entities) ? $this->data->entities->urls : array());
+       if ($this->is_native_retweet()) {
+           return (isset($this->data->retweeted_status->entities) ? $this->data->retweeted_status->entities->urls : array());
+       } else {
+           return (isset($this->data) && isset($this->data->entities) ? $this->data->entities->urls : array());
+       }
    }

    /**
@@ -287,12 +302,22 @@


    /**
-    * Is this a retweet?
+    * Is this a native retweet?
+    *
+    * @return bool
+    */
+   function is_native_retweet() {
+       return (bool) (isset($this->data) && !empty($this->data->retweeted_status));
+   }
+
+
+   /**
+    * Is this a retweet? (This includes both native and non-native retweets.)
     *
     * @return bool
     */
    function is_retweet() {
-       return (bool) (AKTT::substr($this->content(), 0, 2) == 'RT' || !empty($this->data->retweeted_status));
+       return (bool) (AKTT::substr($this->content(), 0, 2) == 'RT' || $this->is_native_retweet());
    }


@@ -366,6 +391,12 @@
            $str = AKTT::substr_replace($str, $entity['replace'], $start, ($end - $start));
            $diff += AKTT::strlen($entity['replace']) - ($end - $start);
        }
+
+       if ($this->is_native_retweet()) {
+           $orig_screen_name = $this->data->retweeted_status->user->screen_name;
+           $str = 'RT '.AKTT::profile_link($orig_screen_name).': '.$str;
+       }
+
        return $str;
    }

The patch basically does:

  • Add is_native_retweet() method
  • Make urls(), mentions(), hashtags(), and content() get the entities and text from data->retweeted_status in case of a native retweet
  • Make link_entities() prepend "RT @username: " in case of a native retweet to mimic a non-native retweet at rendering time.

@alexkingorg
Copy link
Contributor Author

Thanks, fixed in 959973d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants