Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 1.54 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * Recupera postagens de usuários do Twitter
  3.  * @param string $user O nome do usuário
  4.  * @return &array Matriz contendo as postagens do membro
  5.  */
  6. function &getTwitterPostsByUser( $user ){
  7.         $arr = array();
  8.         $cur = null;
  9.         $xml = new XMLReader( );
  10.        
  11.         if ( $xml->open( sprintf( 'http://twitter.com/statuses/user_timeline/%s.xml' , $user ) ) ){
  12.                 while ( $xml->read() ){
  13.                         if ( $xml->nodeType == XMLReader::ELEMENT ){
  14.                                 $node = $xml->localName;
  15.                                
  16.                                 if ( $xml->read() ){
  17.                                         switch ( $node ){
  18.                                                 case 'created_at' :
  19.                                                         $cur = strtotime( $xml->value );
  20.                                                         break;
  21.                                                 case 'text' :
  22.                                                         $arr[ $cur ] = preg_replace( '/@([a-zA-Z_]+)/' , '<a href="http://twitter.com/$1">@$1</a>' , $xml->value );
  23.                                                         break;
  24.                                         }
  25.                                 }
  26.                         }
  27.                 }
  28.                
  29.                 $xml->close();
  30.                
  31.                 ksort( $arr );
  32.         } else
  33.                 throw new Exception( 'Não foi possível abrir o documento.' );
  34.        
  35.         return $arr;
  36. }