[FEATURE] Use internal link generation for usernames 42/26742/3
authorNicole Cordes <cordes@cps-it.de>
Mon, 13 Jan 2014 10:18:18 +0000 (11:18 +0100)
committerNicole Cordes <typo3@cordes.co>
Mon, 13 Jan 2014 10:43:00 +0000 (11:43 +0100)
The Twitter api provides information according to mentioned users in a
tweet. Those usernames are wrapped with a link to their Twitter profile
within internal tweet handling.

Change-Id: Ie72210561696f46d024d5f8a0d3cac8ae301eaef
Reviewed-on: https://review.typo3.org/26742
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Classes/Domain/Repository/TweetRepository.php
Configuration/TypoScript/Main/constants.txt
Configuration/TypoScript/Main/setup.txt

index aedd802..9ffae38 100644 (file)
@@ -139,6 +139,11 @@ class Tx_WtTwitter_Domain_Repository_TweetRepository {
                return $tweets;
        }
 
+       /**
+        * @param $settings
+        * @param NULL $response
+        * @return array
+        */
        public function getListsFromUser($settings, &$response = NULL) {
                $lists = array();
                $this->settings = $settings;
@@ -307,6 +312,7 @@ class Tx_WtTwitter_Domain_Repository_TweetRepository {
                $this->addOldUserInformation($tweets);
                $this->rewriteIncludedLinks($tweets);
                $this->linkHashtags($tweets);
+               $this->linkUsernames($tweets);
        }
 
        /**
@@ -374,4 +380,26 @@ class Tx_WtTwitter_Domain_Repository_TweetRepository {
                }
        }
 
+       /**
+        * @param array $tweets
+        * @return void
+        */
+       protected function linkUsernames(&$tweets) {
+               if (is_array($tweets) && !empty($this->settings['linkUsernames'])) {
+                       foreach ($tweets as $tweet) {
+                               if ($tweet->entities && $tweet->entities->user_mentions && is_array($tweet->entities->user_mentions)) {
+                                       foreach ($tweet->entities->user_mentions as $username) {
+                                               $screenName = '@' . $username->screen_name;
+                                               $typolinkConfiguration = array(
+                                                       'parameter' => 'https://twitter.com/' . rawurlencode($username->screen_name),
+                                               );
+                                               $tweet->text = str_replace($screenName, $this->contentObject->typolink($screenName, $typolinkConfiguration), $tweet->text);
+                                       }
+                                       unset($username);
+                               }
+                       }
+                       unset($tweet);
+               }
+       }
+
 }
\ No newline at end of file
index ea0679e..2b5c883 100644 (file)
@@ -30,6 +30,9 @@ plugin.wttwitter {
        # cat=plugin.wt_twitter//0130; type=boolean; label= Inserts links for used hashtags
        main.linkHashtags = 1
 
+       # cat=plugin.wt_twitter//0120; type=boolean; label= Inserts links for usernames
+       main.linkUsernames = 1
+
        # cat=plugin.wt_twitter//9999; type=boolean; label= Debug Mode: Enable or disable some debug output
        debug = 0
 
index b321666..2cd8e92 100644 (file)
@@ -15,6 +15,7 @@ plugin.tx_wttwitter {
                        excludeReplies = {$plugin.wttwitter.main.excludeReplies}
                        rewriteLinks = {$plugin.wttwitter.main.rewriteLinks}
                        linkHashtags = {$plugin.wttwitter.main.linkHashtags}
+                       linkUsernames = {$plugin.wttwitter.main.linkUsernames}
                        debug = {$plugin.wttwitter.debug}
 
                        # Tweet Fields (Feed in a loop like text, link, etc..)