Birdnapper – The PHP Twitter Feed Widget

Description:

Bridnapper 1.1 allows you to display the latest tweets of a user of your choosing. The user you choose must have their Tweets public, otherwise Birdnapper will not be able to display properly.

I developed this originally for use on my WordPress blog on www.codeblink.com sidebar, but I’m sure you will be able to find many other applications for it.

Source Files: Download 1.1 ZIP | Download 1.1 RAR

Installation:

1.) Copy and paste the following into a new file called birdnapper.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<br />
function birdnapping($strUsername,$intShowTweets) {<br />
    $html_url="http://twitter.com/$strUsername";<br />
    $handle = @fopen($html_url, "r");<br />
    if ($handle) {<br />
            while (!feof($handle)) {<br />
                    $buffer = fgets($handle, 4096);<br />
                    $content=$content.$buffer;<br />
            }<br />
            fclose($handle);<br />
    }<br />
    $content=trim($content);</p>
<p> $start=strpos($content,"</p>
<div class=\"section\">"
);<br />
    $end=strpos($content,"</p>
<div id=\"pagination\">"
);<br />
    $tweets=substr($content,$start,$end-$start);</p>
<p> $arrayTweets=explode("</p>
<li"
,$tweets);</p>
<p> $tweets="";</p>
<p> $i=1;<br />
    while ($i<=$intShowTweets) {<br />
        $start=strpos($arrayTweets[$i],">")+1;<br />
        $strippedTweet=substr($arrayTweets[$i],$start,strlen($arrayTweets[$i])-$start);<br />
        $tweets.="</p>
<li>"
.$strippedTweet;<br />
        $i++;<br />
    }</p>
<p> // fix links to Twitter profiles. Twitter gives inline links<br />
    $tweets=str_replace("href=\"/","href=\"http://twitter.com/",$tweets);</p>
<p> return "</p>
<div id=\"birdnapping\">\n</p>
<ol>\n$tweets\n</ol>
<p>\n</p>
<div class=\"follow\"><a href=\"http://twitter.com/$strUsername\" target=\"_blank\">Follow $strUsername &raquo;</a></div>
<p>\n</p>
</div>
<p>"
;<br />
}<br />

3.) Create a folder called ‘birdnapper’ in your WP folder: /wp-content/plugins/ and save your birdnapper.php file there.

4.) Then copy and paste this code to display the Twitter Feed:

1
2
3
4
5
6
7
8
9
10
11
</p>
<ul>
<li>
<div class="sidebarbox">
<h2 class="widgettitle">Twitter Feed</h2>
<p> <?php include($_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/birdnapper/birdnapper.php"); ?><br />
 <?php echo birdnapping("TwitterUserName",5); ?>
 </div>
</li>
</ul>
<p>

5.) Make sure to replace ‘TwitterUserName’ with the user name of the person you wish to display Tweets from.

6.) The Birdnapper Twitter feed can be styled anyway you wish with CSS. This is the major advantage it has over an RSS feed. Here is the CSS I currently use:

1
2
3
<br />
#birdnapping span.entry-meta{ display:block; font-style:italic; font-size:smaller; }<br />
#birdnapping .follow { font-weight:bold; }<br />

In Development for Version 1.1:

  • Option to allow Birdnapper to scrape from a Twitter User or search.twitter.com using a search term.
  • Custom Filtering
    • Swearing
    • Exclude specific Twitter authors

1.1 Update

Added a line of code to fix inline links to Twitter profile pages. Links will now be external to http://twitter.com. Discovered this flaw when I checked out my Google Webmaster report!

POLL: What do you think? (Birdnapper 1.1)

View Results

Loading ... Loading ...

Please leave a comment or suggestion below!

  • http://www.codeblink.com/?p=34 CodeBlink.com Birdnapper 1.0 Twitter Widget PHP Free Open Source | CodeBlink.com

    [...] Development I have removed this and made a dedicated page to the development of this widget here: http://www.codeblink.com/?page_id=86 :add-on, addon, birdnapper, php, plug-in, plugin, twitter, [...]

  • http://www.codeblink.com/?p=112 CodeBlink.com 1.1 Update to Birdnapper | CodeBlink.com

    [...] Birdnapper now has a home of it’s on on codeblink.com here: http://www.codeblink.com/?page_id=86 [...]

  • http://www.codeblink.com/2009/04/birdnapper-11-now-available/ Birdnapper 1.1 Now Available « CodeBlink.com

    [...] now has a home of it’s on on codeblink.com here: http://www.codeblink.com/codeblink-open-source-projects/birdnapper-the-php-twitter-feed-widget/ Tagged as: add-on, addon, birdnapper, php, plug-in, plugin, twitter, widget View commentsComments [...]

  • http://www.codeblink.com/2009/04/birdnapper-twitter-widget-10-release/ Birdnapper Twitter Widget Release « CodeBlink.com

    [...] have removed this blog and made a dedicated page to the development of this widget here: http://www.codeblink.com/codeblink-open-source-projects/birdnapper-the-php-twitter-feed-widget/ Tagged as: add-on, addon, birdnapper, php, plug-in, plugin, twitter, widget View commentsComments [...]

  • http://twitter.com/kparkers Kevin Parkerson

    I have updated this widget so that it displays in an easier to read manner. Also, It's now valid with XHTML 1.0 Strict doctypes, and can be easily set to display as a series of divs, unordered list, or ordered list. I will try and contact the originator of this code in order to have him add my changes here, but in the meantime you can find the new version at:

    http://www.kevinparkerson.com/birdnapperWidget….

    Do anything you'd like with it, and post a link if you've made any worthwhile changes! Enjoy! : )

  • http://topsy.com/tb/disq.us/927zy Tweets that mention CodeBlink.com » Birdnapper – The PHP Twitter Feed Widget — Topsy.com

    [...] This post was mentioned on Twitter by Jason Rundell, Kevin Parkerson. Kevin Parkerson said: Awesome PHP twitter feed: http://www.codeblink.com/codeblink-open-source-projects/birdnapper-the-php-twitter-feed-widget/ [...]

  • http://twitter.com/jasonrundell Jason Rundell

    That's awesome Kevin! I'll try it out and make an update as soon as I get the time. I've actually had a 1.2 update on the burner for some time now and just haven't had time to fully test and update the code. I'll try to implement your changes into the update.

  • http://www.philiptoday.com/tomorrow/2010/10/onto-entertainment/ Onto Entertainment | Philip Today

    [...] page. To display tweets as a cross-fading “slide-show,” I hacked together the wonderful Birdnapper PHP script (for fetching rich tweet content) with the powerful Cycle jQuery slideshow plugin from [...]

  • Chris

    Great bit of coding. I’m having a go at using it outside WordPress.
    One thing I have noticed though is I’m getting an undefined variable for the line:
    $content=$content.$buffer;

    $content has not been set at this point hence the warning. Is there something I’m missing?

    Cheers
    Chris

  • Jason Rundell

    Hey Chris. To fix that, just add

    $content=0;

    at the beginning of the code. I guess your php.ini file is set to show all warnings. Also, it’s been a while since I made this – made it before twitter had an api – so this method of getting tweets is probably not kosher with Twitter. Just something to beware of and I need to update this post with that warning.