taylorwitt.com
01100010 01101100 01101111 01100111

Implementing a PHP Wrapper on Twitter’s API for a MediaWiki Site

April 6th 2010 in Uncategorized

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 –>




required



required - won't be displayed


Your Comment:

This was the most challenging aspect of creating my Wiki site on Search Engine Optimization (SEO). After installing other Twitter Feed widgets and extensions, none of which worked correctly, I then read an article (http://mediawiki2u.com/wp-content/uploads/2008/11/mediawiki-skins-design-sample-chapter-chapter-8-social-netwo.pdf) on adding JavaScript provided by Twitter (at www.twitter.com/badges) directly to the html source (in the case of MediaWiki, then [...]

Previous Entry