Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
search.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Twitter
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die();
11 
12 /**
13  * Twitter API Search class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Twitter
17  * @since 12.3
18  */
20 {
21  /**
22  * Method to get tweets that match a specified query.
23  *
24  * @param string $query Search query. Should be URL encoded. Queries will be limited by complexity.
25  * @param string $callback If supplied, the response will use the JSONP format with a callback of the given name
26  * @param string $geocode Returns tweets by users located within a given radius of the given latitude/longitude. The parameter value is
27  * specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers).
28  * @param string $lang Restricts tweets to the given language, given by an ISO 639-1 code.
29  * @param string $locale Specify the language of the query you are sending (only ja is currently effective). This is intended for
30  * language-specific clients and the default should work in the majority of cases.
31  * @param string $result_type Specifies what type of search results you would prefer to receive. The current default is "mixed."
32  * @param integer $count The number of tweets to return per page, up to a maximum of 100. Defaults to 15.
33  * @param string $until Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
34  * @param integer $since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
35  * @param integer $max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
36  * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
37  * variety of metadata about the tweet in a discrete structure, including: urls, media and hashtags.
38  *
39  * @return array The decoded JSON response
40  *
41  * @since 12.3
42  */
43  public function search($query, $callback = null, $geocode = null, $lang = null, $locale = null, $result_type = null, $count = 15,
44  $until = null, $since_id = 0, $max_id = 0, $entities = null)
45  {
46  // Check the rate limit for remaining hits
47  $this->checkRateLimit('search', 'tweets');
48 
49  // Set the API path
50  $path = '/search/tweets.json';
51 
52  // Set query parameter.
53  $data['q'] = rawurlencode($query);
54 
55  // Check if callback is specified.
56  if ($callback)
57  {
58  $data['callback'] = $callback;
59  }
60 
61  // Check if geocode is specified.
62  if ($geocode)
63  {
64  $data['geocode'] = $geocode;
65  }
66 
67  // Check if lang is specified.
68  if ($lang)
69  {
70  $data['lang'] = $lang;
71  }
72 
73  // Check if locale is specified.
74  if ($locale)
75  {
76  $data['locale'] = $locale;
77  }
78 
79  // Check if result_type is specified.
80  if ($result_type)
81  {
82  $data['result_type'] = $result_type;
83  }
84 
85  // Check if count is specified.
86  if ($count != 15)
87  {
88  $data['count'] = $count;
89  }
90 
91  // Check if until is specified.
92  if ($until)
93  {
94  $data['until'] = $until;
95  }
96 
97  // Check if since_id is specified.
98  if ($since_id > 0)
99  {
100  $data['since_id'] = $since_id;
101  }
102 
103  // Check if max_id is specified.
104  if ($max_id > 0)
105  {
106  $data['max_id'] = $max_id;
107  }
108 
109  // Check if entities is specified.
110  if (!is_null($entities))
111  {
112  $data['include_entities'] = $entities;
113  }
114 
115  // Send the request.
116  return $this->sendRequest($path, 'GET', $data);
117  }
118 
119  /**
120  * Method to get the authenticated user's saved search queries.
121  *
122  * @return array The decoded JSON response
123  *
124  * @since 12.3
125  */
126  public function getSavedSearches()
127  {
128  // Check the rate limit for remaining hits
129  $this->checkRateLimit('saved_searches', 'list');
130 
131  // Set the API path
132  $path = '/saved_searches/list.json';
133 
134  // Send the request.
135  return $this->sendRequest($path);
136  }
137 
138  /**
139  * Method to get the information for the saved search represented by the given id.
140  *
141  * @param integer $id The ID of the saved search.
142  *
143  * @return array The decoded JSON response
144  *
145  * @since 12.3
146  */
147  public function getSavedSearchesById($id)
148  {
149  // Check the rate limit for remaining hits
150  $this->checkRateLimit('saved_searches', 'show/:id');
151 
152  // Set the API path
153  $path = '/saved_searches/show/' . $id . '.json';
154 
155  // Send the request.
156  return $this->sendRequest($path);
157  }
158 
159  /**
160  * Method to create a new saved search for the authenticated user.
161  *
162  * @param string $query The query of the search the user would like to save.
163  *
164  * @return array The decoded JSON response
165  *
166  * @since 12.3
167  */
168  public function createSavedSearch($query)
169  {
170  // Set the API path
171  $path = '/saved_searches/create.json';
172 
173  // Set POST request data
174  $data['query'] = rawurlencode($query);
175 
176  // Send the request.
177  return $this->sendRequest($path, 'POST', $data);
178  }
179 
180  /**
181  * Method to delete a saved search for the authenticating user.
182  *
183  * @param integer $id The ID of the saved search.
184  *
185  * @return array The decoded JSON response
186  *
187  * @since 12.3
188  */
189  public function deleteSavedSearch($id)
190  {
191  // Check the rate limit for remaining hits
192  $this->checkRateLimit('saved_searches', 'destroy/:id');
193 
194  // Set the API path
195  $path = '/saved_searches/destroy/' . $id . '.json';
196 
197  // Send the request.
198  return $this->sendRequest($path, 'POST');
199  }
200 }