/src/libraries/joomla/twitter/users.php

https://bitbucket.org/ke2083/transfans.co.uk-website · PHP · 376 lines · 166 code · 49 blank · 161 comment · 21 complexity · 7222f8f2af8c596f752b2bb1dbef9017 MD5 · raw file

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