CodeBlink.com Open Source Projects, Code, Rants, and other miscellany

29Apr/090

Birdnapper 1.1 Now Available

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. I discovered this flaw when I checked out my Google Webmaster report!

Birdnapper 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/

  • Share/Bookmark
29Apr/092

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
function birdnapping($strUsername,$intShowTweets) {
    $html_url="http://twitter.com/$strUsername";
    $handle = @fopen($html_url, "r");
    if ($handle) {
            while (!feof($handle)) {
                    $buffer = fgets($handle, 4096);
                    $content=$content.$buffer;
            }
            fclose($handle);
    }
    $content=trim($content);
   
    $start=strpos($content,"<div class=\"section\">");
    $end=strpos($content,"<div id=\"pagination\">");
    $tweets=substr($content,$start,$end-$start);
   
    $arrayTweets=explode("<li",$tweets);
   
    $tweets="";
   
    $i=1;
    while ($i<=$intShowTweets) {
        $start=strpos($arrayTweets[$i],">")+1;
        $strippedTweet=substr($arrayTweets[$i],$start,strlen($arrayTweets[$i])-$start);
        $tweets.="<li>".$strippedTweet;
        $i++;
    }
   
    // fix links to Twitter profiles. Twitter gives inline links
    $tweets=str_replace("href=\"/","href=\"http://twitter.com/",$tweets);
   
    return "<div id=\"birdnapping\">\n<ol>\n$tweets\n</ol>\n<div class=\"follow\"><a href=\"http://twitter.com/$strUsername\" target=\"_blank\">Follow $strUsername &raquo;</a></div>\n</div>";
}

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
<ul>
 <li>
 <div class="sidebarbox">
 <h2 class="widgettitle">Twitter Feed</h2>
 <?php include($_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/birdnapper/birdnapper.php"); ?>
 <?php echo birdnapping("TwitterUserName",5); ?>
 </div>
 </li>
</ul>

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
#birdnapping span.entry-meta{ display:block; font-style:italic; font-size:smaller; }
#birdnapping .follow { font-weight:bold; }

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!

  • Share/Bookmark
13Apr/095

Birdnapper Twitter Widget Release

I 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/

  • Share/Bookmark