[FEATURE] Improve the integration of links 39/26739/4
authorNicole Cordes <cordes@cps-it.de>
Fri, 10 Jan 2014 12:54:24 +0000 (13:54 +0100)
committerNicole Cordes <typo3@cordes.co>
Mon, 13 Jan 2014 13:33:16 +0000 (14:33 +0100)
Add option to choose how links are displayed in tweet. You can choose
between a short form or the whole link. Additionally the generation of
links is moved within the internal tweet handling.

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

index 9ffae38..dc81d63 100644 (file)
@@ -311,6 +311,7 @@ class Tx_WtTwitter_Domain_Repository_TweetRepository {
                $this->sliceArray($tweets, $this->settings['limit']);
                $this->addOldUserInformation($tweets);
                $this->rewriteIncludedLinks($tweets);
+               $this->linkUrls($tweets);
                $this->linkHashtags($tweets);
                $this->linkUsernames($tweets);
        }
@@ -341,15 +342,31 @@ class Tx_WtTwitter_Domain_Repository_TweetRepository {
        }
 
        /**
+        * @param object $url
+        * @return string
+        */
+       protected function getVisibleUrl($url) {
+               switch ($this->settings['rewriteLinks']) {
+                       case 'short':
+                               return $url->display_url;
+                       case 'extended':
+                               return $url->expanded_url;
+                       default:
+                               return $url->url;
+               }
+       }
+
+       /**
         * @param array $tweets
         * @return void
         */
-       protected function rewriteIncludedLinks(array $tweets) {
-               if (!empty($this->settings['rewriteLinks'])) {
+       protected function rewriteIncludedLinks($tweets) {
+               if (is_array($tweets) && $this->settings['rewriteLinks'] != 'leave') {
                        foreach ($tweets as $tweet) {
                                if ($tweet->entities && $tweet->entities->urls && is_array($tweet->entities->urls)) {
                                        foreach ($tweet->entities->urls as $url) {
-                                               $tweet->text = str_replace($url->url, $url->expanded_url, $tweet->text);
+                                               $newUrl = $this->getVisibleUrl($url);
+                                               $tweet->text = str_replace($url->url, $newUrl, $tweet->text);
                                        }
                                        unset($url);
                                }
@@ -362,6 +379,28 @@ class Tx_WtTwitter_Domain_Repository_TweetRepository {
         * @param array $tweets
         * @return void
         */
+       protected function linkUrls(&$tweets) {
+               if (is_array($tweets) && !empty($this->settings['linkUrls'])) {
+                       foreach ($tweets as $tweet) {
+                               if ($tweet->entities && $tweet->entities->urls && is_array($tweet->entities->urls)) {
+                                       foreach ($tweet->entities->urls as $url) {
+                                               $urlInText = $this->getVisibleUrl($url);
+                                               $typolinkConfiguration = array(
+                                                       'parameter' => $url->expanded_url,
+                                               );
+                                               $tweet->text = str_replace($urlInText, $this->contentObject->typolink($urlInText, $typolinkConfiguration), $tweet->text);
+                                       }
+                                       unset($url);
+                               }
+                       }
+               }
+               unset($tweet);
+       }
+
+       /**
+        * @param array $tweets
+        * @return void
+        */
        protected function linkHashtags(&$tweets) {
                if (is_array($tweets) && !empty($this->settings['linkHashtags'])) {
                        foreach ($tweets as $tweet) {
index 2b5c883..fbd29b2 100644 (file)
@@ -25,12 +25,16 @@ plugin.wttwitter {
        # cat=plugin.wt_twitter//0100; type=boolean; label= Exclude replies: Filter replies from tweets - only if mode is showOwn (e.g. 1)
        main.excludeReplies = 0
 
-       # cat=plugin.wt_twitter//0110; type=boolean; label= Rewrite links: Rewrites the twitter links with the original ones
-       main.rewriteLinks = 0
+       # cat=plugin.wt_twitter//0110; type=options[leave,short,extended]; label= Rewrite links: Rewrites the twitter links with the original ones
+       main.rewriteLinks = leave
+
+       # cat=plugin.wt_twitter//0120; type=boolean; label= Inserts links for used urls
+       main.linkUrls = 1
+
        # 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
+       # cat=plugin.wt_twitter//0140; 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
index 2cd8e92..24369d3 100644 (file)
@@ -14,6 +14,7 @@ plugin.tx_wttwitter {
                        showRetweets = {$plugin.wttwitter.main.showRetweets}
                        excludeReplies = {$plugin.wttwitter.main.excludeReplies}
                        rewriteLinks = {$plugin.wttwitter.main.rewriteLinks}
+                       linkUrls =  {$plugin.wttwitter.main.linkUrls}
                        linkHashtags = {$plugin.wttwitter.main.linkHashtags}
                        linkUsernames = {$plugin.wttwitter.main.linkUsernames}
                        debug = {$plugin.wttwitter.debug}