Contents

SimpleTwitter - Insert last user posts in Twitter

A simple extensions to integrate Twitter user timeline in your wiki

How use it

<simpletwitter>username</simpletwitter>
<simpletwitter>username|count_messages|list of styles</simpletwitter>

Install

Copy source code in /extensions/SimpleTwitter.php and add in LocalSettings.php:

require_once("$IP/extensions/SimpleTwitter.php");

Source code

<?php
/**
*	Available under the GFDL (http://www.gnu.org/copyleft/fdl.html) as source code was taken
*	from  http://www.mediawiki.org/wiki/Extension:SimpleTwitter
*	Modification by Fabio Zorba
*/ 
/*********************************************************************************
*                                                                                *
* SimpleTwitter Extension by Fabio Zorba                                         *
*                                                                                *
* thanks:                                                                        *
* http://www.packtpub.com/article/integrating-twitter-and-youtube-with-mediawiki *
* http://www.twitter.com/badges                                                  *
*                                                                                *
* Tag :                                                                          *
*   <simpletwitter>username</simpletwitter>                                      *
*                                                                                *
*   <simpletwitter>username|count_messages|list of styles</simpletwitter>        *
*                                                                                *
* Copy in /extensions and add in LocalSettings.php:                              *
* require_once("$IP/extensions/SimpleTwitter.php");                              *
*                                                                                *
**********************************************************************************/
 
if( !defined( 'MEDIAWIKI' ) )
  die( -1 );
 
$wgExtensionFunctions[] = 'wfSimpleTwitter';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'SimpleTwitter',
        'description' => 'Insert last user posts in Twitter',
        'author' => 'Fabio Zorba',
        'url' => 'http://www.mediawiki.org/wiki/Extension:SimpleTwitter',
	'version' => '0.2 (beta) 20110101'
);
 
function wfSimpleTwitter() {
        global $wgParser;
        $wgParser->setHook('simpletwitter', 'renderSimpleTwitter');
}
 
# The callback function for converting the input text to HTML output
function renderSimpleTwitter ($input, $args) {
 
	list($username,$count,$divstyle) = explode('|',htmlspecialchars($input));
		$count = is_numeric($count) ? $count : 5;
 
	//Sanitizer!
	$divstyle=str_replace("<","",$divstyle);
	$divstyle=str_replace(">","",$divstyle);
	if ( $count  >  200 ) { $count=200; }
 
if ($divstyle == "")
{ $divstyle = "color:#BEB798; background: #FFF; border: 3px #BEB798 solid; margin:0; padding: 5px; width:480px; a color:#8D1425 !important;"; }
 
        $output = '
<div id="twitter_div" style="' . $divstyle . '">
 
<h2 class="sidebar-title"><img src="http://api.twitter.com/1/users/profile_image/' . $username . '.json?size=normal"> Twitter Updates</h2>
<ul id="twitter_update_list"></ul>
<a href="http://twitter.com/'.$username.'" id="twitter-link" style="display:block;text-align:right;">follow me on Twitter</a></div>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/'.$username.'.json?callback=twitterCallback2&amp;count='.
$count.'"></script>';
 
        return $output;
}
 
?>
Retrieved from "http://www.zoros.org/wiki/index.php?title=SimpleTwitter_mediawiki_extension"