Link tweet author to profile on twitter.com

David Lesieur - September 13, 2009 - 04:00
Project:Activity Stream
Version:6.x-1.0-rc2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

The body of a tweet always begins with the name of its author. This patch turns this name into a link to that user's profile on twitter.com.

AttachmentSize
activitystream_twitter_user_link.patch1.91 KB

#1

akalsey - November 7, 2009 - 02:12
Status:needs review» needs work

The Twitter module strips out the author's twitter ID from the beginning of the tweet before the tweet is saved to a node.

I can't see that this patch would do anything at all.

#2

David Lesieur - November 7, 2009 - 05:05

I'm currently looking at the body of an activity stream item (through node/%/edit) after doing a fresh install of Activity Stream 1.0-rc2, and it does show the Twitter ID at the beginning of the body. The Twitter ID is not in the node title, but still is in the node body.

I see the following code in activitystream_twitter_streamapi():

$tweet['title'] = preg_replace('/^'. $userid .' /', '', $tweet['title']);

... but nothing that strips the userid from the body.

It also looks like Activity Stream never displays the body of a tweet (it shows the title instead), so in the default case the patch has no effect.
However, I'm using a view to display the bodies, bypassing functions like theme_activitystream_twitter_item(). In that case the patch can be appreciated.

#3

akalsey - November 7, 2009 - 05:05

Ahh, you're right.

I don't think the backreference in your regex is needed. In fact, the only reason we need a regex instead of just str_replace is that we only want to catch the username if it starts the string, not if it appears inside it. We're matching on a known string, so this should work:

<?php
$text
= preg_replace('/^'. $userid .':/', '<a href="http://twitter.com/'. $userid .'">'. $userid .'</a>:', $text);
?>

Eliminating the backreferences should save a tiny bit of memory.

#4

David Lesieur - November 7, 2009 - 05:10

Yes, the backreference was completely useless! I'm all for the simplification.

 
 

Drupal is a registered trademark of Dries Buytaert.