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

Already on GitHub? Sign in to your account

Possible truncation issue #19

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

Comments

Projects
None yet
2 participants

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 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.
Contributor

alexkingorg commented Dec 30, 2013

Thanks, fixed in 959973d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment