Posted by David Lesieur on September 13, 2009 at 4:00am
| Project: | Activity Stream |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
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.
| Attachment | Size |
|---|---|
| activitystream_twitter_user_link.patch | 1.91 KB |
Comments
#1
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
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
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
Yes, the backreference was completely useless! I'm all for the simplification.
#5
Re-rolled against 6.x-1.0, removed the backreference, filtered the output.