Git Product home page Git Product logo

Comments (3)

trustin avatar trustin commented on July 23, 2024

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

from wp-twitter-tools.

trustin avatar trustin commented on July 23, 2024

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.

from wp-twitter-tools.

alexkingorg avatar alexkingorg commented on July 23, 2024

Thanks, fixed in 959973d

from wp-twitter-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.