Twitter

[ Details ] [ Usage ] [ Source ] [ Example ] [ Documentation ] [ Dependancies ] [ Issues ]

Details

Macro Twitter
Author Peter H. Reiser
DateCreated 2008-04-06
LatestVersion 0.1
ConfluenceVersion 2.6.2
Description shows the latest three twitter  posts
Category Utility
This script is a quick hack - don't use it on Internet sites ... need to fix some XSS vulnerabilities

Usage

{twitter:USERNAME}

Parameter: Twitter UserName

Source

<!-- twitter message reader --> 
<script type="text/javascript" src='http://twitter.com/statuses/user_timeline/$param0 .json?callback=twitterCallback&amp;count=3&amp;named_obj'></script>
<div id="twitter-box" style="overflow: hidden; /* to hide the overflow of long urls */"> </div>
<script type="text/javascript"><!--

function relative_created_at(time_value) { // thanks to Lionel of rarsh.com for pointing out that Twitter changed their code, and this is the fix which will work in IE
var created_at_time = Date.parse(time_value.replace(" +0000",""));
var relative_time = ( arguments.length > 1 ) ? arguments[1] : new Date();
var wordy_time = parseInt(( relative_time.getTime() - created_at_time ) / 1000) + (relative_time.getTimezoneOffset()*60);
if ( wordy_time < 59 ) {
  return 'less than 1 minute ago';
  } 
  else if ( wordy_time < 119 ) { // changed because otherwise you get 30 seconds of 1 minutes ago 
  return '1 minute ago';
  } 
  else if ( wordy_time < 3000 ) { // < 50 minutes ago
  return ( parseInt( wordy_time / 60 )).toString() + ' minutes ago';
  } 
  else if ( wordy_time < 5340 ) { // < 89 minutes ago
  return '1 hour ago';
  } 
  else if ( wordy_time < 9000 ) { // < 150 minutes ago
  return 'few hours ago'; 
  }
  else if ( wordy_time < 82800 ) { // < 23 hours ago
  return 'about ' + ( parseInt( wordy_time / 3600 )).toString() + ' hours ago';
  } 
  else if ( wordy_time < 129600 ) { // < 36 hours
  return '1 day ago';
  }
  else if ( wordy_time < 172800 ) { // < 48 hours
  return '2 days ago';
  }
  else {
  return ( parseInt(wordy_time / 86400)).toString() + ' days ago';
  }
  }
  var ul = document.createElement('ul');
  for (var i=0; i < 3 && i < Twitter.posts.length; i++) {
  var post = Twitter.posts[i]; 
  var li = document.createElement('li');
  var showTwitterName = 0;
  var showTimeFirst = 1;
  if ( showTimeFirst == 1) {
  li.appendChild(document.createTextNode(' '));
  var a = document.createElement('a');
  a.setAttribute('href', 'http://twitter.com/$param0/' + 'statuses/' + post.id);
  a.setAttribute('title', '$param0 at Twitter.com');
  a.setAttribute('rel', 'nofollow');
  a.appendChild(document.createTextNode(relative_created_at(post.created_at)));
  li.appendChild(a);
  li.appendChild(document.createTextNode(' : '));
  }
  if ( showTwitterName == 1 ) {
  li.appendChild(document.createTextNode(post.user.name + ' '));
  }
  li.appendChild(document.createTextNode(post.text));
  if ( showTimeFirst == 0 ) {
  li.appendChild(document.createTextNode(' ')); 
  var a = document.createElement('a');
  a.setAttribute('href', 'http://twitter.com/$param0/' + 'statuses/' + post.id);
  a.setAttribute('rel', 'nofollow');
  a.setAttribute('title', '$param0 at Twitter.com');
  a.appendChild(document.createTextNode(relative_created_at(post.created_at)));
  li.appendChild(a); 
  li.appendChild(document.createTextNode(' : ')); 
  }
  ul.appendChild(li);
  }
  ul.setAttribute('id', 'twitter-list');
  document.getElementById('twitter-box').appendChild(ul);
  -->
</script>

Example

{twitter:peterreiser}

  • 32 minutes ago : show my son the new CE 2.0 twitter hack ...
  • 1 day ago : testing twitter update
  • 2 days ago : Measles cases in Europe .. scaring ??

Credits:

I just modified the code from:

Documentation

  • create a user macro called twitter
  • unflag "Macro has body"
  • use "Macro generates HTML markup"
  • copy code into macro
  • save
  • test it with {twitter:UserName}

Dependancies

Issues

  • security fixes
    need to fix some XSS vulnerabilities
  • need to add link check (e.g. check if twitter API is available)
  • add more parameters:
  • numbers of messages to be shown
  • follow-me=true  

Labels

twitter twitter Delete
user+macro user+macro Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.