PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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