Guest User

Untitled

a guest
May 10th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment