Implementing a PHP Wrapper on Twitter’s API for a MediaWiki Site
After using Twitter’s badge utility (which generates the html/flash code for you) I realized that it would only return my own Tweets rather than displaying all timeline Tweets for a search result (in this case ‘#SEO’). So I found an article (http://carsonified.com/blog/dev/how-to-get-started-with-the-twitter-api/) which describes a PHP wrapper for Twitter’s API that would allow me to add a new class (class.twitter.php) and embed the necessary PHP and HTML directly into the MediaWiki skin PHP file. Below is the code that was added to get the Twitter #SEO search feed into the left sidebar of the wiki:
<!– MW:Twitter Portlets –>
<div class=’generated-sidebar block’ id=’p-Twitter’>
<h2>Twitter Updates (#SEO)</h2>
<?php
$t = new twitter;
$s = new summize;
$data = $s->search(‘#SEO’,5);
$data = $data->results;
?>
<ul class=’menu’>
<?php foreach($data as $d){ ?>
<div STYLE=”word-wrap: break-word”>
<li”>
<img src=”<?php echo $d->profile_image_url; ?>” alt=”" />
<?php echo preg_replace(‘/(^|\s)@(\w+)/’,'\1<a href=”http://twitter.com/\2″>@\2</a>’, $d->text); ?>
<em>by</em>
<a href=”http://twitter.com/<?php echo $d->from_user; ?>”><?php echo $d->from_user; ?></a>
<?php echo $d->created_at; ?> <em>from</em>
<?php echo html_entity_decode($d->source); ?>
</li>
</div>
<?php } ?>
</ul>
<br>
<a href=”http://twitter.com/SEO_Chatter” id=”twitter-link” style=”display:block;text-align:right;”>follow me on Twitter</a>
</div>
</div><!– pBody –>
</div><!– Twitter portlet –>