I know this topic has been posted before, but a co-worker and I pulled together a way to add a Twitter feed to a site using getFeed, then use output modifiers to remove the original account name from the tweets, and restore the clickable links, account names, and hashtags.
First, make a chunk called
get_twitter_feed. Note that it uses property placeholders for the account and number of tweets, and has a ":replace" output modifier (to remove the original account name from the tweets).
NOTE: the forums keep formatting the &url= property as a link and removing formatted placeholders... It should only read
&url=`http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=accountplaceholder`
<ul>
[[getFeed:replace=`[[+account]]: ==`?
&url=`http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=[[+account]]`
&limit=`[[+tweetcount]]`
&tpl=`general_twitter_tpl`
]]
</ul>
Call the chunk as follows. The output modifier requires the name to be case-sensitive as it appears on Twitter. For example, &account=`cnn` will pull the @cnn feed, but not remove the account name since it appears in the feed as "CNN".
[[$get_twitter_feed? &account=`TwitterHandle` &tweetcount=`3`]]
Make a tpl chunk to format the tweets pulled from the RSS feed. I've called it
general_twitter_tpl. On the description, there is an output modifier called "twitter-parser" on the description placeholder.
<li>
<div class="twitter_item">
<p>[[+description:twitter-parser]]</p>
<p class="small"><a href="[[+link]]">[[+date_timestamp:date:ago]]</a></p>
</div><!-- end twitter_item -->
</li>
Finally, create a new snippet to be used as an output modifier. Name the snippet
twitter-parser.
<?php
//Parses links: http://stackoverflow.com/questions/3329859/add-links-to-php-that-pulls-latest-tweet-from-twitter-account
// properly formatted URLs
$urls = "/(((http[s]?:\/\/)|(www\.))?(([a-z][-a-z0-9]+\.)?[a-z][-a-z0-9]+\.[a-z]+(\.[a-z]{2,2})?)\/?[a-z0-9._\/~#&=;%+?-]+[a-z0-9\/#=?]{1,1})/is";
$input = preg_replace($urls, " <a href='$1'>$1</a>", $input);
// URLs without protocols
$input = preg_replace("/href=\"www/", "href=\"http://www", $input);
//Parses accounts
$input = preg_replace('/ (@([-a-zA-Z0-9_]+)(:)?)/',' <a href="http://twitter.com/$2" target="_blank" rel="nofollow">@$2</a>',$input);
//Parses hashtag
$input = preg_replace('/(#([-a-zA-Z0-9_]+)(:)?)/','<a href="http://twitter.com/search/$2" target="_blank" rel="nofollow">#$2</a>',$input);
return $input;
?>
This should result in a clean unordered list with the specified number of tweets, and clickable links for links, account names, and hashtags.
[ed. note: [email protected] last edited this post 14 years, 5 months ago.]