Limitaremos el número de conexiones a Twitter, accediendo como máximo una vez cada hora.
Pasado ese tiempo actualizaremos el valor en nuestro “cache_archivo”.

<?php
function twitter_contador($nombreusuario) {

	$cache_archivo = CACHEDIR . 'twitter_contador' . md5 ( $nombreusuario );

	if (is_file ( $cache_archivo ) == false) $cache_tiempo = strtotime ( '1978-09-04 13:10' );
	else $cache_tiempo = filemtime ( $cache_archivo );

	$tiempo_actual = strtotime ( date ( 'Y-m-d H:i:s' ) );
	$tiempo_diferencia = $tiempo_actual - $cache_tiempo;
	$tiempo_recarga = 3600; // mínimo de segundos antes de volver a realizar la conexión a twitter

	if ($tiempo_diferencia > $tiempo_recarga) {
		$xml = file_get_contents ( 'http://twitter.com/users/show/' . $nombreusuario );
		$perfil = new SimpleXMLElement ( $xml );
		$contador = $perfil->followers_count;
		if (is_file ( $cache_archivo ) == true) unlink ( $cache_archivo );
		touch ( $cache_archivo ); // momento de modificación cambiado a la hora actual
		file_put_contents ( $cache_archivo, strval ( $contador ) );
		return strval ( $contador );
	}
	else {
		$contador = file_get_contents ( $cache_archivo );
		return strval ( $contador );
	}
}
echo twitter_contador('PlasmikMedia');
?>
 
<?php
function twitter_feed($username) {
	$feedurl = "http://search.twitter.com/search.atom?q=from:".$username."&rpp=1";
	$feed = file_get_contents($feedurl);
	$s1 = explode("<content type=\"html\">", $feed);
	$s2 = explode("</content>", $s1[1]);

	$tweet = $s2[0];
	$tweet = str_replace("&lt;", "<", $tweet);
	$tweet = str_replace("&gt;", ">", $tweet);

	return $tweet;
}
echo twitter_feed("PlasmikMedia");
?>
 

Plasmik joins the social networking world and invites you to the new facebook page. Act as a means to “communicate and stay in contact” with all people who love everything about multimedia, programming, design and graphic arts in general.

See you there!


Facebook Page

 
Copyright © 2012 · All Rights Reserved · PLASMIK · RSS Feed · Acceder
plasmik