stephenjbell

Twitter Feed - Format links, @s and #s - dotCMS

Sep 26th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #set($startWithUser = false)
  2.  
  3. #set($path = "http://twitter.com/statuses/user_timeline/$!{twitterUsername}.rss")
  4. #set($_dummy = $xmltool.read($path))
  5. #set($twitterData = $xmltool.parse($_dummy))
  6. #set($twitterDesc = $twitterData.find('channel/item/description'))
  7.  
  8.  
  9. #set($latestTweet = $twitterDesc.get(0).toString())
  10.  
  11. ## Strip off beginning username if it's not wanted
  12. #if($startWithUser != true)
  13. #set($latestTweet = $latestTweet.replaceAll("(?i)$!{twitterUsername}: ",""))
  14. #end
  15.  
  16. ## Strip off <description> tags
  17. #set($latestTweet = $latestTweet.replaceAll("<\/?description>",""))
  18.  
  19. ## Replace URL text with an actual link
  20. #set($latestTweet = $latestTweet.replaceAll("[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+","<a href='$0' target='_blank'>$0</a>"))
  21.  
  22. ## Replace "#whatever" with a link to "http://twitter.com/search?q=%23whatever"
  23. #set($latestTweet = $latestTweet.replaceAll("(?<=#)((\w+))","<a href='http://twitter.com/search\?q=%23$0' target='_blank'>$0</a>"))
  24.  
  25. ## Replace "@whoever" with a link to "http://www.twitter.com/whoever"
  26. #set($latestTweet = $latestTweet.replaceAll("(?<=@)((\w+))","<a href='http://twitter.com/$0' target='_blank'>$0</a>"))
  27.  
  28. <div class="twitterbox"><img src="/lucid/images/twitter.png" alt="Twitter" class="left pngfix" />
  29. <h2>@<a href='http://twitter.com/$!{twitterUsername}' target='_blank'>$!{twitterUsername}</a> Twitter</h2>
  30. <p>$!{latestTweet}</p>
  31. </div>
  32.  
Advertisement
Add Comment
Please, Sign In to add comment