twitter-feed-droplet

Ruud

in the end: yes. It shows tweets.  8-)

It is very minimal, and because it is a droplet it is very easy to position and customize the output.
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

Argos

This seems to be the same functionality as http://www.websitebakers.com/pages/modules/listings/various/wb-tweets.php, but then as a droplet. Is that correct?
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!


Ruud

#1
Some time ago I needed to add a twitter feed to a website.
I did not want to use javascript for this because for SEO purposes it is good to have changing content in the page output.
So I made a Droplet for it.

<?php 
//use [[tweet?name=mytweetname&max=5]]

if (isset($_SESSION['tweets'])) return $_SESSION['tweets']; //prevent too many calls
if (!isset($name)) return true;
if (!isset(
$max)) $max 5;

if (!
function_exists('fetch_tweets')) {
function fetch_tweets($username$maxtweets) {
$tweets simplexml_load_file("http://twitter.com/statuses/user_timeline/" $username ".rss");
$tweet_array = array();  
foreach ( $tweets->channel->item as $tweet ) { 
if ($maxtweets == 0) {
break;
} else {
$twit $tweet->description;
$twit substr(strstr($twit': '), 2strlen($twit));
$twit preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>",$twit);
$twit preg_replace("(@([a-zA-Z0-9\_]+))""<a target=\"_blank\" href=\"http://www.twitter.com/\\1\">\\0</a>"$twit);
$twit preg_replace('/(^|\s)#(\w+)/''\1<a target=\"_blank\" href="http://search.twitter.com/search?q=%23\2">#\2</a>'$twit);
$twit iconv("UTF-8"DEFAULT_CHARSET$twit);
$pubdate strtotime($tweet->pubDate); 
$propertime date(DATE_FORMAT.', '.TIME_FORMAT$pubdate);  //Customize this to your liking
$tweet_item = array('desc' => $twit,'date' => $propertime,);
array_push($tweet_array$tweet_item);
$maxtweets--;
}
}
return $tweet_array;
}
}
$mytweets fetch_tweets($name$max);
$rval '<div class="twitter-updates">';
foreach (
$mytweets as $k => $v) {
     
$rval .= '<div><p class="twitter-update">' .$v['desc']. '</p><p class="twitter-date">' .$v['date']. '</p></div>';
}
$rval .= '</div>';
$_SESSION['tweets'] = $rval;
return 
$rval;


The droplet is called like [[tweets?name=billgates&max=10]] (max is optional)

It is depending on the simplexml library. According to the PHP website this is included in the standard PHP-5 installations, so it might work on most hosts.

The tweets are loaded once per browser session. This is to prevent being banned by twitter for requesting data too much from a single IP address.

Have fun with it.

Ruud
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]