public static function fnUpdateTweetAjax($status, $user, $room, $tomail, $bstatus, $parent) {
		$text = 'hello world;';
		include('WikiTweet.config.php');
		$show = ($tomail==2) ? 2 : 1;
		global $wgDBprefix, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgLanguageCode, $IP, $wgServer ;
		$db = mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword);
		mysql_select_db($wgDBname,$db);

		$dbr =& wfGetDB( DB_SLAVE );
		$dbr->insert('wikitweet',array(
			'`id`'      => ''      ,
			'`text`'    => $status ,
			'`user`'    => $user   ,
			'`room`'    => $room   ,
			'`show`'    => $show   ,
			'`status`'  => $bstatus,
			'`parent`'  => $parent,
			'`lastupdatedate`' => time()
		));

		if( $parent != 0 )
		{
			// update last update date parent tweet
			$dbr->update( 'wikitweet', array('`lastupdatedate`' => time()), array('id' => $parent) ) ;
		}
		
		$dest=array('concerned'=>array(),'subscribers'=>array()); // initialisation de la liste des récepteurs
		$user_email = $wgWikiTweet['wikimail']; // initialisation du sender
		if($tomail==1 or $tomail==2 or  !$wgWikiTweet['tweetandemail']){ // si l'option tomail est à 1 ou 2 > mails directs, mentions, privés
			$res = $dbr->select('user','user_email',"user_name = '$user' ");

			if ($dbr->numRows($res) > 0){
				$row = $dbr->fetchObject($res);
				$user_email = $row->user_email;
				if ($user_email!=''){
					$status_array = split("@",$status);
					$i = -1;
					foreach($status_array as $values){
						$i += 1;
						if ($i>0){
							$values_array = split(" ",$values);
							$username = $values_array[0];
							$res2 = $dbr->select('user','user_email',"user_name = '$username' ");
							if ($dbr->numRows($res2) > 0){
								$row2 = $dbr->fetchObject($res2);
								$useremail = $row2->user_email;
								if ($useremail!='')
									array_push($dest['concerned'],$useremail);
							}
						}
					}
				}
			}
		}
		if( $tomail!=2)
		{
			// pas d'envoi de mails groupés pour les tweets privés
			// à ce stade, $dest contient les utilisateurs qui sont spécifiques au tweets, et non pas abonnés.
			$roomssons = array();
			$sql_subscriptions = '';
			// récupération des abonnés pour envoi de mail (abonnés user ou abonnés room + inherit rooms)
			foreach(WikiTweetFunctions::_getParentsRoom($room,$wgWikiTweet['inherit']) as $roomparent)
			{
				$sql_subscriptions .= " OR (wt.link = '$roomparent' AND wt.type='room')";
			}
			$sql1 = "SELECT DISTINCT {$wgDBprefix}user.user_email FROM {$wgDBprefix}user,{$wgDBprefix}wikitweet_subscription wt WHERE wt.user={$wgDBprefix}user.user_name AND ((wt.link = '$room' AND wt.type='room') or (wt.link='$user' AND wt.type='user'){$sql_subscriptions}) ;";

			$res1 = $dbr->query( $sql1, __METHOD__ );
			while( $row1 = $dbr->fetchObject( $res1 ) )
			{
				$useremail = $row1->user_email;
				array_push($dest['subscribers'],$useremail);
				$text .= $useremail.'---';
			}
		}
		$lenlist = array('concerned'=>0,'subscribers'=>0);
		foreach($dest as $desttype=>$destarray)
		{
			foreach($dest[$desttype] as $destmail){
				$lenlist[$desttype] += strlen($destmail);
				$text .= "--g:$desttype:$destmail--";
			}
		}
		$bstatus_string = ($bstatus > 1) ? ' ['.wfMsg('wikitweet-status'.$bstatus).']' : '';
		
		foreach($dest as $desttype=>$destarray)
		{
			if($lenlist[$desttype]>0){
				$room_title = (isset($wgWikiTweet['titles'][$room])) ? $room.' - '.$wgWikiTweet['titles'][$room] : $room;
				$concernsstring = ($desttype == 'concerned') ? "[".wfMsg('wikitweet-concerns')."]" : "";
				$sender = ($desttype == 'concerned') ? $wgWikiTweet['wikimail-concerns'] : $wgWikiTweet['wikimails'][$bstatus];

				$answering = '';
				if( $parent != 0 )
				{
					// en réponse au wikitweet
					$res = $dbr->select( 
						'wikitweet' , 
						'*' , 
						"`show`=1 AND `id`='$parent'",
						__METHOD__ ,
						array("ORDER BY" =>" `date` ASC", "LIMIT" => $rows)
					);
					$row = $dbr->fetchObject( $res );
					$answering = wfMsg('wikitweet-inresponseto')." \n\n".wfMsg('wikitweet-from')." @{$row->user} ({$row->date}) : {$row->text}\n";

					$res = $dbr->select( 
						'wikitweet' , 
						'*' , 
						"`show`=1 AND `parent`='$parent'",
						__METHOD__ ,
						array("ORDER BY" =>" `date` ASC", "LIMIT" => $rows)
					);
					while( $row = $dbr->fetchObject( $res ) )
					{
						$answering .= "\n\t|----\n\t| ".wfMsg('wikitweet-from')." @{$row->user} ({$row->date}) : {$row->text}";
					}
					$answering .= "\n\t|----";
				}

				WikiTweetFunctions::send( $dest[$desttype], $sender , "[WikiTweet]$bstatus_string $concernsstring  ".date('d/m H:i')." @$user (".wfMsg('wikitweet-in')." $room_title)", wfMsg('wikitweet-from')." @$user :\n----\n".$status."\n----\n\n$answering(".wfMsg('wikitweet-in')." \"$room_title\")\n\n".wfMsg('wikitweet-directlink')." $wgServer/mediawiki/index.php/{$wgWikiTweet['roomlink']}$room");
				$text .= wfMsg('wikitweet-mailsent');
			}
		}
		mysql_close(); 
		return $text;
	}
function wikiTweeterRender($input, $args, $parser)
{
	tableCheck();
	// Imports
	global $wgOut;
	global $wgUser;
	global $ableToTweet;
	include("WikiTweet.config.php");
	global $wgScriptPath;
	global $wgDBprefix;
	// Profiling
	wfProfileIn('wikiTweeter::Render');

	// Disable the cache, otherwise the cloud will only update
	// itself when a user edits and saves the page.
	$parser->disableCache();
	
	$dbr =& wfGetDB( DB_SLAVE );
	$res = $dbr->select('wikitweet','distinct(`user`)',false,__METHOD__,false);

	$avatarlist = '';
	while ($row = $dbr->fetchObject($res))
	{
		// Pull out the fields
		$user = $row->user;
		// determine AVATAR path
		$avatar_parse = $parser->parse("[[image:$user.png]]",$parser->mTitle, $parser->mOptions,true, false)->getText();
		$avatar = '';
		if (strstr($avatar_parse, 'src') == ''){
			$avatar_parse = $parser->parse("[[image:$user.jpg]]",$parser->mTitle, $parser->mOptions,true, false)->getText();
		}
		if (strstr($avatar_parse, 'src') == ''){
			//$avatar_parse = $parser->parse("[[image:Default.tweet.png]]",$parser->mTitle, $parser->mOptions,true, false)->getText();
			$avatar_parse = 'src="'.$wgScriptPath.'/extensions/WikiTweet/images/default_avatar.png"';
		}
		if (strstr($avatar_parse, 'src') != ''){
			$pos_src = strpos($avatar_parse,'src');
			$avatar = substr($avatar_parse,$pos_src+5);
			$pos_guill = strpos($avatar,'"');
			$avatar = substr($avatar,0,$pos_guill);
		}
		// Check Avatar table
		$res2 = $dbr->select('wikitweet_avatar','*',"user='******' ','_',mysql_real_escape_string($user))."' ",__METHOD__,false);
		if ($dbr->numRows( $res2 ) == 0){
				$res4 = $dbr->insert('wikitweet_avatar',array('`id`'=>'','`user`'=>str_replace(' ','_',mysql_real_escape_string($user)),'`avatar`'=>$avatar));
			}
			else {
				$res5 = $dbr->update('wikitweet_avatar',array('avatar'=>$avatar),array('user'=>str_replace(' ','_',mysql_real_escape_string($user))));
			}
	}
	$class  = (isset($args["class"])) ? $args["class"] : "wiki-tweets";
	$size   = (isset($args["size"]))  ? $args["size"]  : "normal"     ;
	$rows   = (isset($args["rows"]))  ? $args["rows"]  : $wgWikiTweet["rows"]         ;
	$room   = (isset($args["room"]))  ? $args["room"]  : "main"       ;
	$allowstatus = (isset($args["status"]))  ? true  : false ;
	$alertslevel = (isset($args["alertslevel"]))  ? $args["alertslevel"]  : "1" ;


	// [GRAPH]
	$text = '';
	if($alertslevel=="2")
	{
		$res2 = $dbr->select('wikitweet_alerts','*',false,__METHOD__,array('ORDER BY' => '`timestamp` DESC'));
		$chd_attention = '';
		$chd_alert     = '';
		$chxl = '';
		$max = 20;
		$i = 0;
		$alertsarray = array();
		$sum_max = 0;
		while($row2= $dbr->fetchObject($res2)){
			$i += 1;
			if($i<=$max){
				$alertsarray[$row2->date] = array($row2->attention,$row2->alert);
				if(intval($row2->attention)+intval($row2->alert)>$sum_max){
					$sum_max = intval($row2->attention)+intval($row2->alert)+1;
				}
				$chd_attention .= $row2->attention.',';
				$chd_alert     .= $row2->alert.',';
				$chxl = '|'.$row2->date.'h'.$chxl;
			}
		}

		$chd_attention = substr($chd_attention, 0, -1);
		$chd_alert = substr($chd_alert, 0, -1);
		$text .="<h2>".wfMsg('wikitweet-hourly')."</h2>
		<p style='text-align:center;'><img src='https://chart.googleapis.com/chart?chs=300x400&amp;
			cht=bhs&amp;
			chco=FF9933,FF0000&amp;
			chds=0,$sum_max&amp;
			chxt=y&amp;
			chts=000000,15&amp;
			chd=t:$chd_attention|$chd_alert&amp;
			chbh=r,.6&amp;
			chm=N,000000,0,,12,,c|N,000000,1,,12,,c&amp;
			chxl=0:$chxl
			'></p>";

		if (false) {
			// NOT YET IMPLEMENTED
			$text .= "<h2>".wfMsg('wikitweet-perperson')."</h2>";
				
			$res3 = $dbr->select('wikitweet_alerts_persons','*','`timestamp` IN (SELECT MAX(`timestamp`) FROM '.$dbr->tableName('wikitweet_alerts_persons').')',__METHOD__);

			$chd_attention = '';
			$chd_alert     = '';
			$chxl = '';
			$sum_max = 0;
			while($row3 = $dbr->fetchObject($res3)){
				if(intval($row3->attention)+intval($row3->alert)>$sum_max){
					$sum_max = intval($row3->attention)+intval($row3->alert)+1;
				}
				$chd_attention .= $row3->attention.',';
				$chd_alert     .= $row3->alert.',';
				$chxl = '|'.$row3->username.$chxl;
			}

			$chd_attention = substr($chd_attention, 0, -1);
			$chd_alert = substr($chd_alert, 0, -1);
			$text .="
			<p style='text-align:center;'><img src='https://chart.googleapis.com/chart?chs=300x400&amp;
				cht=bhs&amp;
				chco=FF9933,FF0000&amp;
				chds=0,$sum_max&amp;
				chxt=y&amp;
				chts=000000,15&amp;
				chd=t:$chd_attention|$chd_alert&amp;
				chbh=r,.6&amp;
				chm=N,000000,0,,12,,c|N,000000,1,,12,,c&amp;
				chxl=0:$chxl
				'></p>";
		}
	}

	// [/GRAPH]

	// $uniqueid = md5($room);
	$uniqueid = rand(1,9999);
	$text  .= "<div class='$class'". (($args["style"]) ? " style='" . $args["style"]. "'" : '').">";
	$room_subscribe_text = "<a class='room_subscribe handmouse' uniqueid='$uniqueid' style='display:none;'>".wfMsg('wikitweet-subscribe')."</a><a class='room_unsubscribe handmouse' uniqueid='$uniqueid'>".wfMsg('wikitweet-unsubscribe')."</a>";
	if($room!='main'){
		$res6 = $dbr->select(
			'wikitweet_subscription',
			'*',
			array(
				"user='******' ",
				"link='".mysql_real_escape_string($room)."' ",
				"type='room' "
			),
			__METHOD__,false
		);
		if ($dbr->numRows( $res6 ) == 0){
			$room_subscribe_text = "<a class='room_subscribe handmouse' uniqueid='$uniqueid'>".wfMsg('wikitweet-subscribe')."</a><a  style='display:none;' class='room_unsubscribe handmouse' uniqueid='$uniqueid'>".wfMsg('wikitweet-unsubscribe')."</a>";
		}
		$text .= "<p>".wfMsg('wikitweet-intheroom')." <b>$room</b> (<span id='id_room_subscribe_$uniqueid'>$room_subscribe_text<span id='tempimg_$uniqueid'></span></span>)</p>";
	}
	
	$text .= '<form class="status_update_form" uniqueid="'.$uniqueid.'" style="'.(($alertslevel!='1') ? 'display:none;' : '').'">';
	$text .= '<INPUT type=hidden NAME="alertslevel" value="'.$alertslevel.'"/>';
	if ($wgUser->isLoggedIn() or $wgWikiTweet['allowDisconnected']){
		$text .= '
			<table width=100%>
				<tr><td width=95%>
					<textarea tabindex="1" autocomplete="off" accesskey="u" name="status" id="status" rows="3" cols="40"></textarea>
				</td>
				<td width=5%>
					<div class="stringlength"> <span>500</span></div>
				</td></tr>
			</table>';
			if ( $allowstatus )
			{
				$text .= '	
							<label>'.wfMsg('wikitweet-status').'</label>
							<select name="bstatus" size="1">
								<option selected="" value="0">'.wfMsg('wikitweet-status0').'</option>
								<option value="1">'.wfMsg('wikitweet-status1').'</option>
								<option value="2">'.wfMsg('wikitweet-status2').'</option>
								<option value="3">'.wfMsg('wikitweet-status3').'</option>
							</select><br/>' ;
			}
			else
			{
				$text .= '<input type=hidden value="1" name="bstatus"/>';
			}
			$text .= '<input type=submit name=submit value="'.wfMsg('wikitweet-submit').'" onclick="return false" uniqueid="'.$uniqueid.'"/>';
			if($wgWikiTweet['allowAnonymous']){
				$text .= '<INPUT type=submit name=submitanonymously value="'.wfMsg('wikitweet-anonymous').'" onclick="return false" style="font-size:0.8em;" uniqueid="'.$uniqueid.'" />';
			}
			if (in_array($wgUser->getName(), $wgWikiTweet['informers']))
			{
				$text .= '<input type=submit name=submitbyinformer value="'.wfMsg('wikitweet-inform').'" onclick="return false" style="font-size:0.8em;" uniqueid="'.$uniqueid.'" />';
			}
			if($wgWikiTweet['tweetandemail']){
				$text .= '<input type=submit name=submitandmail value="'.wfMsg('wikitweet-submitandmail').'" onclick="return false" style="display:none;font-size:0.8em;" uniqueid="'.$uniqueid.'"/>';
			}
			$text .= '<input type=submit name=submitprivate value="'.wfMsg('wikitweet-private').'" onclick="return false" style="display:none;font-size:0.8em;" uniqueid="'.$uniqueid.'"/>';
			
			$text .= '<img class="img_loader" src="'.$wgScriptPath.'/extensions/WikiTweet/images/ajax-loader-mini.gif" style ="padding: 0 5px 0 5px;display:none;"/>';
	}
	else{
		$text.="<p>".wfMsg('wikitweet-pleaselogin')."</p>";
	}
	$text .= '<input type=hidden value="'.$wgUser->getName().'" name="user"/>
				<input type=hidden value="'.$size.'" name="size"/>
				<input type=hidden value="'.$rows.'" name="rows"/>
				<input type=hidden value="'.$room.'" name="room"/>
			</form>';

	$text .= '<script type="text/javascript" src="'.$wgScriptPath.'/extensions/WikiTweet/jquery.js"></script>';
	
	$text .= '<script type="text/javascript" src="'.$wgScriptPath.'/extensions/WikiTweet/popup.js"></script>';
	$text .= '<link rel="stylesheet" type="text/css" href="'.$wgScriptPath.'/extensions/WikiTweet/popup.css" media="screen" />';
	$text .= '<link rel="stylesheet" type="text/css" href="'.$wgScriptPath.'/extensions/WikiTweet/WikiTweet.css" media="screen" />';
	$text .= '<script type="text/javascript">wgScriptPath = "'.$wgScriptPath.'";</script>';
	$text .= '<script type="text/javascript">var refreshTime='.$wgWikiTweet['refreshTime'].';</script>';
	$text .= '<script type="text/javascript">var InformerUser="******";</script>';
	$text .= '<script type="text/javascript">var AnonymousUser="******";</script>';
	$text .= '<script type="text/javascript" src="'.$wgScriptPath.'/extensions/WikiTweet/WikiTweet.js"></script>';
	$text .= '<script type="text/javascript" src="'.$wgScriptPath.'/extensions/WikiTweet/WikiTweet2.js"></script>';
	$text .= '<script type="text/javascript">$(document).ready(function() {gettweets("'.$uniqueid.'");});</script>';

	$roomssons = array();
	$sql_subscriptions = '';
	foreach(WikiTweetFunctions::_getParentsRoom($room,$wgWikiTweet['inherit']) as $roomparent)
	{
		$sql_subscriptions .= " OR (wt.link = '$roomparent' AND wt.type='room')";
	}
	$sql1 = "SELECT DISTINCT {$wgDBprefix}user.user_real_name,{$wgDBprefix}user.user_name FROM {$wgDBprefix}user,{$wgDBprefix}wikitweet_subscription wt WHERE wt.user={$wgDBprefix}user.user_name AND ((wt.link = '$room' AND wt.type='room'){$sql_subscriptions}) ;";
	$res1 = $dbr->query( $sql1, __METHOD__ );  
	$text .= "<p><b>".wfMsg('wikitweet-subscribers')."</b>  ";
	while($row1 = $dbr->fetchObject($res1)){
		$user_real_name = $row1->user_real_name;
		$text .= " <a href = '$wgScriptPath/index.php/Utilisateur:{$row1->user_name}'>{$row1->user_real_name}</a>, ";
	}
	$text = substr($text, 0, -2);
	$text .= "</p>";


	$text .= "<a href = '$wgScriptPath/index.php/".wfMsg('wikitweet-name')."'>".wfMsg('wikitweet-moretweets')."</a><br/>\n";
	$text .= "<div id='lasttweets_$uniqueid' class='lasttweets' uniqueid='$uniqueid'>\n";
	$text .= "</div>\n";
	$text .= "<a href = '$wgScriptPath/index.php/".wfMsg('wikitweet-name')."'>".wfMsg('wikitweet-name')."</a> ".wfMsg('wikitweet-infoajax')."<br/>\n";
	
	$text .= "</div>\n";
	
	// Finish up and return the results
	wfProfileOut('wikiTweeter::Render');
	return $text;
}
	public static function _getParentsRoom($i__room,$i__array)
	{
		$o__room_parents = array();
		foreach($i__array as $l__room_key=>$l__room_childs)
		{
			foreach($l__room_childs as $l__room_child)
			{
				if($l__room_child == $i__room)
				{
					$o__room_parents[] = $l__room_key;
					$o__room_parents = array_merge($o__room_parents,WikiTweetFunctions::_getParentsRoom($l__room_key,$i__array));
					break;
				}
			}
		}
		return $o__room_parents;
	}