/inc/class.search.php

http://php-twitter.googlecode.com/ · PHP · 122 lines · 60 code · 9 blank · 53 comment · 6 complexity · 298add3d7f50e948e57b522118442599 MD5 · raw file

  1. <?php
  2. /**
  3. * Twitter Search
  4. *
  5. * @package php-twitter 2.0
  6. * @subpackage search
  7. * @author Aaron Brazell
  8. **/
  9. class Twitter_Search extends Twitter {
  10. /**
  11. * Setup Twitter client connection details
  12. *
  13. * Ensure you set a user agent, whether via the constructor or by assigning a value to the property directly.
  14. * Also, if you are not running this from the Eastern timezone, be sure to set your proper timezone.
  15. *
  16. * @access public
  17. * @since 2.0
  18. * @return Twitter_Search
  19. */
  20. public function __construct( $username = null, $password = null, $user_agent = null, $headers = null, $timezone = 'America/New_York', $debug = false)
  21. {
  22. parent::__construct($username, $password, $user_agent, $headers, $timezone);
  23. }
  24. /**
  25. * Perform a search
  26. *
  27. * Pass an array of optional parameters (key => value) Possible parameters are:
  28. * - callback: Returns data in JSONP format using the specified callback
  29. * - lang: Restricts tweets to the designated language. Reference http://en.wikipedia.org/wiki/ISO_639-1
  30. * - locale: Twitter currently supports ja (Japan) or en (English). English is default if omitted
  31. * - rpp: Results per page. Maximum of 100 (default)
  32. * - page: The page number of results. Twitter only returns 1500 results per query. Default is 1
  33. * - since_id: Returns tweets with IDs greater than the specified number
  34. * - geocode: Returns tweets within a specified radius of lat/long coordinates. Designate as a value lat,long,rad
  35. * - show_user: Returns results with username prepended to tweets. Default is false
  36. *
  37. * @access public
  38. * @since 2.0
  39. * @return object
  40. */
  41. public function search( $query )
  42. {
  43. $this->api_url = 'http://search.twitter.com/search.' . $this->type;
  44. if( is_string( $query ) )
  45. {
  46. $newquery['q'] = $query;
  47. $query = $newquery;
  48. }
  49. $defaults = array(
  50. 'lang' => 'en',
  51. 'rpp' => 100,
  52. 'q' => ''
  53. );
  54. $args = wp_parse_args( $query, $defaults );
  55. // Limit query to 140 URL encoded charachters per Twitter
  56. $query_string = substr( $this->_glue( $args ), 0, 140 );
  57. return $this->_get( $this->api_url . $query_string );
  58. }
  59. /**
  60. * Retrieves top 10 trending topics
  61. *
  62. * @access public
  63. * @since 2.0
  64. * @param null/string $scope current/daily/weekly
  65. * @param boolean $include_hashtags determines whether to filter out hashtags in results. Default is false
  66. * @param boolean/string $date a formatted string like YYYY-MM-DD. If omitted, the current date is used
  67. * @return object
  68. */
  69. public function trends( $scope = 'current', $include_hashtags = false, $date = false )
  70. {
  71. switch( $scope )
  72. {
  73. case 'current' :
  74. $url_scope = '/current';
  75. $qs = array();
  76. $qs['exclude'] = 'hashtags';
  77. break;
  78. case 'daily' :
  79. $url_scope = '/daily';
  80. $qs = array();
  81. if( $include_hashtags )
  82. $qs['exclude'] = 'hashtags';
  83. if( !$date )
  84. $qs['date'] = date('Y-m-d');
  85. break;
  86. case 'weekly' :
  87. $url_scope = '/weekly';
  88. if( $include_hashtags )
  89. $qs['exclude'] = 'hashtags';
  90. if( !$date )
  91. $qs['date'] = date('Y-m-d');
  92. break;
  93. default :
  94. $url_scope = '';
  95. break;
  96. }
  97. $this->api_url = 'http://search.twitter.com/trends' . $url_scope . '.' . $this->type;
  98. if( $qs )
  99. $this->api_url = $this->api_url . $this->_glue( $qs );
  100. return $this->_get( $this->api_url );
  101. }
  102. /**
  103. * Destroys the object
  104. *
  105. * @access public
  106. * @since 2.0
  107. * @return null
  108. */
  109. public function __destruct() {}
  110. }
  111. class summize extends Twitter_Search {
  112. # Deprecated - Use Twitter_Search class instead
  113. }