PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/twitter/users.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 375 lines | 166 code | 47 blank | 162 comment | 21 complexity | ab8102bf4d4dcc02241ffee6f2a94f25 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Twitter
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die();
  10. /**
  11. * Twitter API Users class for the Joomla Platform.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Twitter
  15. * @since 12.3
  16. */
  17. class JTwitterUsers extends JTwitterObject
  18. {
  19. /**
  20. * Method to get up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two.
  21. *
  22. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  23. * @param string $id A comma separated list of user IDs, up to 100 are allowed in a single request.
  24. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a variety of
  25. * metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  26. *
  27. * @return array The decoded JSON response
  28. *
  29. * @since 12.3
  30. * @throws RuntimeException
  31. */
  32. public function getUsersLookup($screen_name = null, $id = null, $entities = null)
  33. {
  34. // Check the rate limit for remaining hits
  35. $this->checkRateLimit('users', 'lookup');
  36. // Set user IDs and screen names.
  37. if ($id)
  38. {
  39. $data['user_id'] = $id;
  40. }
  41. if ($screen_name)
  42. {
  43. $data['screen_name'] = $screen_name;
  44. }
  45. if ($id == null && $screen_name == null)
  46. {
  47. // We don't have a valid entry
  48. throw new RuntimeException('You must specify either a comma separated list of screen names, user IDs, or a combination of the two');
  49. }
  50. // Set the API path
  51. $path = '/users/lookup.json';
  52. // Check if string_ids is specified
  53. if (!is_null($entities))
  54. {
  55. $data['include_entities'] = $entities;
  56. }
  57. // Send the request.
  58. return $this->sendRequest($path, 'POST', $data);
  59. }
  60. /**
  61. * Method to access the profile banner in various sizes for the user with the indicated screen_name.
  62. *
  63. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  64. *
  65. * @return array The decoded JSON response
  66. *
  67. * @since 12.3
  68. */
  69. public function getUserProfileBanner($user)
  70. {
  71. // Check the rate limit for remaining hits
  72. $this->checkRateLimit('users', 'profile_banner');
  73. // Set the API path
  74. $path = '/users/profile_banner.json';
  75. // Determine which type of data was passed for $user
  76. if (is_numeric($user))
  77. {
  78. $data['user_id'] = $user;
  79. }
  80. elseif (is_string($user))
  81. {
  82. $data['screen_name'] = $user;
  83. }
  84. else
  85. {
  86. // We don't have a valid entry
  87. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  88. }
  89. // Send the request.
  90. return $this->sendRequest($path, 'GET', $data);
  91. }
  92. /**
  93. * Method used to search for users
  94. *
  95. * @param string $query The search query to run against people search.
  96. * @param integer $page Specifies the page of results to retrieve.
  97. * @param integer $count The number of people to retrieve. Maximum of 20 allowed per page.
  98. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  99. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  100. *
  101. * @return array The decoded JSON response
  102. *
  103. * @since 12.3
  104. * @throws RuntimeException
  105. */
  106. public function searchUsers($query, $page = 0, $count = 0, $entities = null)
  107. {
  108. // Check the rate limit for remaining hits
  109. $this->checkRateLimit('users', 'search');
  110. $data['q'] = rawurlencode($query);
  111. // Check if page is specified.
  112. if ($page > 0 )
  113. {
  114. $data['page'] = $page;
  115. }
  116. // Check if per_page is specified
  117. if ($count > 0)
  118. {
  119. $data['count'] = $count;
  120. }
  121. // Check if entities is specified.
  122. if (!is_null($entities))
  123. {
  124. $data['include_entities'] = $entities;
  125. }
  126. // Set the API path
  127. $path = '/users/search.json';
  128. // Send the request.
  129. return $this->sendRequest($path, 'GET', $data);
  130. }
  131. /**
  132. * Method to get extended information of a given user, specified by ID or screen name as per the required id parameter.
  133. *
  134. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  135. * @param boolean $entities Set to true to return IDs as strings, false to return as integers.
  136. *
  137. * @return array The decoded JSON response
  138. *
  139. * @since 12.3
  140. * @throws RuntimeException
  141. */
  142. public function getUser($user, $entities = null)
  143. {
  144. // Check the rate limit for remaining hits
  145. $this->checkRateLimit('users', 'show');
  146. // Determine which type of data was passed for $user
  147. if (is_numeric($user))
  148. {
  149. $data['user_id'] = $user;
  150. }
  151. elseif (is_string($user))
  152. {
  153. $data['screen_name'] = $user;
  154. }
  155. else
  156. {
  157. // We don't have a valid entry
  158. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  159. }
  160. // Set the API path
  161. $path = '/users/show.json';
  162. // Check if entities is specified
  163. if (!is_null($entities))
  164. {
  165. $data['include_entities'] = $entities;
  166. }
  167. // Send the request.
  168. return $this->sendRequest($path, 'GET', $data);
  169. }
  170. /**
  171. * Method to get an array of users that the specified user can contribute to.
  172. *
  173. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  174. * @param boolean $entities Set to true to return IDs as strings, false to return as integers.
  175. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  176. *
  177. * @return array The decoded JSON response
  178. *
  179. * @since 12.3
  180. * @throws RuntimeException
  181. */
  182. public function getContributees($user, $entities = null, $skip_status = null)
  183. {
  184. // Check the rate limit for remaining hits
  185. $this->checkRateLimit('users', 'contributees');
  186. // Determine which type of data was passed for $user
  187. if (is_numeric($user))
  188. {
  189. $data['user_id'] = $user;
  190. }
  191. elseif (is_string($user))
  192. {
  193. $data['screen_name'] = $user;
  194. }
  195. else
  196. {
  197. // We don't have a valid entry
  198. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  199. }
  200. // Set the API path
  201. $path = '/users/contributees.json';
  202. // Check if entities is specified
  203. if (!is_null($entities))
  204. {
  205. $data['include_entities'] = $entities;
  206. }
  207. // Check if skip_status is specified
  208. if (!is_null($skip_status))
  209. {
  210. $data['skip_status'] = $skip_status;
  211. }
  212. // Send the request.
  213. return $this->sendRequest($path, 'GET', $data);
  214. }
  215. /**
  216. * Method to get an array of users who can contribute to the specified account.
  217. *
  218. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  219. * @param boolean $entities Set to true to return IDs as strings, false to return as integers.
  220. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  221. *
  222. * @return array The decoded JSON response
  223. *
  224. * @since 12.3
  225. * @throws RuntimeException
  226. */
  227. public function getContributors($user, $entities = null, $skip_status = null)
  228. {
  229. // Check the rate limit for remaining hits
  230. $this->checkRateLimit('users', 'contributors');
  231. // Determine which type of data was passed for $user
  232. if (is_numeric($user))
  233. {
  234. $data['user_id'] = $user;
  235. }
  236. elseif (is_string($user))
  237. {
  238. $data['screen_name'] = $user;
  239. }
  240. else
  241. {
  242. // We don't have a valid entry
  243. throw new RuntimeException('The specified username is not in the correct format; must use integer or string');
  244. }
  245. // Set the API path
  246. $path = '/users/contributors.json';
  247. // Check if entities is specified
  248. if (!is_null($entities))
  249. {
  250. $data['include_entities'] = $entities;
  251. }
  252. // Check if skip_status is specified
  253. if (!is_null($skip_status))
  254. {
  255. $data['skip_status'] = $skip_status;
  256. }
  257. // Send the request.
  258. return $this->sendRequest($path, 'GET', $data);
  259. }
  260. /**
  261. * Method access to Twitter's suggested user list.
  262. *
  263. * @param boolean $lang Restricts the suggested categories to the requested language.
  264. *
  265. * @return array The decoded JSON response
  266. *
  267. * @since 12.3
  268. */
  269. public function getSuggestions($lang = null)
  270. {
  271. // Check the rate limit for remaining hits
  272. $this->checkRateLimit('users', 'suggestions');
  273. // Set the API path
  274. $path = '/users/suggestions.json';
  275. $data = array();
  276. // Check if entities is true
  277. if ($lang)
  278. {
  279. $data['lang'] = $lang;
  280. }
  281. // Send the request.
  282. return $this->sendRequest($path, 'GET', $data);
  283. }
  284. /**
  285. * method to access the users in a given category of the Twitter suggested user list.
  286. *
  287. * @param string $slug The short name of list or a category.
  288. * @param boolean $lang Restricts the suggested categories to the requested language.
  289. *
  290. * @return array The decoded JSON response
  291. *
  292. * @since 12.3
  293. */
  294. public function getSuggestionsSlug($slug, $lang = null)
  295. {
  296. // Check the rate limit for remaining hits
  297. $this->checkRateLimit('users', 'suggestions/:slug');
  298. // Set the API path
  299. $path = '/users/suggestions/' . $slug . '.json';
  300. $data = array();
  301. // Check if entities is true
  302. if ($lang)
  303. {
  304. $data['lang'] = $lang;
  305. }
  306. // Send the request.
  307. return $this->sendRequest($path, 'GET', $data);
  308. }
  309. /**
  310. * Method to access the users in a given category of the Twitter suggested user list and return
  311. * their most recent status if they are not a protected user.
  312. *
  313. * @param string $slug The short name of list or a category.
  314. *
  315. * @return array The decoded JSON response
  316. *
  317. * @since 12.3
  318. */
  319. public function getSuggestionsSlugMembers($slug)
  320. {
  321. // Check the rate limit for remaining hits
  322. $this->checkRateLimit('users', 'suggestions/:slug/members');
  323. // Set the API path
  324. $path = '/users/suggestions/' . $slug . '/members.json';
  325. // Send the request.
  326. return $this->sendRequest($path);
  327. }
  328. }