PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/twitter/profile.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 348 lines | 157 code | 52 blank | 139 comment | 27 complexity | 584396d25c3ef8e305d827f58e0c934c 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 Profile class for the Joomla Platform.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Twitter
  15. * @since 12.3
  16. */
  17. class JTwitterProfile extends JTwitterObject
  18. {
  19. /**
  20. * Method to et values that users are able to set under the "Account" tab of their settings page.
  21. *
  22. * @param string $name Full name associated with the profile. Maximum of 20 characters.
  23. * @param string $url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
  24. * @param string $location The city or country describing where the user of the account is located. The contents are not normalized
  25. * or geocoded in any way. Maximum of 30 characters.
  26. * @param string $description A description of the user owning the account. Maximum of 160 characters.
  27. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  28. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  29. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  30. *
  31. * @return array The decoded JSON response
  32. *
  33. * @since 12.3
  34. */
  35. public function updateProfile($name = null, $url = null, $location = null, $description = null, $entities = null, $skip_status = null)
  36. {
  37. // Check the rate limit for remaining hits
  38. $this->checkRateLimit('account', 'update_profile');
  39. $data = array();
  40. // Check if name is specified.
  41. if ($name)
  42. {
  43. $data['name'] = $name;
  44. }
  45. // Check if url is specified.
  46. if ($url)
  47. {
  48. $data['url'] = $url;
  49. }
  50. // Check if location is specified.
  51. if ($location)
  52. {
  53. $data['location'] = $location;
  54. }
  55. // Check if description is specified.
  56. if ($description)
  57. {
  58. $data['description'] = $description;
  59. }
  60. // Check if entities is specified.
  61. if (!is_null($entities))
  62. {
  63. $data['include_entities'] = $entities;
  64. }
  65. // Check if skip_status is specified.
  66. if (!is_null($skip_status))
  67. {
  68. $data['skip_status'] = $skip_status;
  69. }
  70. // Set the API path
  71. $path = '/account/update_profile.json';
  72. // Send the request.
  73. return $this->sendRequest($path, 'POST', $data);
  74. }
  75. /**
  76. * Method to update the authenticating user's profile background image. This method can also be used to enable or disable the profile
  77. * background image.
  78. *
  79. * @param string $image The background image for the profile.
  80. * @param boolean $tile Whether or not to tile the background image.
  81. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  82. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  83. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  84. * @param boolean $use Determines whether to display the profile background image or not.
  85. *
  86. * @return array The decoded JSON response
  87. *
  88. * @since 12.3
  89. */
  90. public function updateProfileBackgroundImage($image = null, $tile = false, $entities = null, $skip_status = null, $use = false)
  91. {
  92. // Check the rate limit for remaining hits
  93. $this->checkRateLimit('account', 'update_profile_background_image');
  94. $data = array();
  95. // Check if image is specified.
  96. if ($image)
  97. {
  98. $data['image'] = "@{$image}";
  99. }
  100. // Check if url is true.
  101. if ($tile)
  102. {
  103. $data['tile'] = $tile;
  104. }
  105. // Check if entities is specified.
  106. if (!is_null($entities))
  107. {
  108. $data['include_entities'] = $entities;
  109. }
  110. // Check if skip_status is specified.
  111. if (!is_null($skip_status))
  112. {
  113. $data['skip_status'] = $skip_status;
  114. }
  115. // Check if use is true.
  116. if ($use)
  117. {
  118. $data['use'] = $use;
  119. }
  120. // Set the API path
  121. $path = '/account/update_profile_background_image.json';
  122. $header = array('Content-Type' => 'multipart/form-data', 'Expect' => '');
  123. // Send the request.
  124. return $this->sendRequest($path, 'POST', $data, $header);
  125. }
  126. /**
  127. * Method to update the authenticating user's profile image.
  128. *
  129. * @param string $image The background image for the profile.
  130. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  131. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  132. * @param boolean $skip_status When set to either true, t or 1 statuses will not be included in the returned user objects.
  133. *
  134. * @return array The decoded JSON response
  135. *
  136. * @since 12.3
  137. */
  138. public function updateProfileImage($image = null, $entities = null, $skip_status = null)
  139. {
  140. // Check the rate limit for remaining hits
  141. $this->checkRateLimit('account', 'update_profile_image');
  142. $data = array();
  143. // Check if image is specified.
  144. if ($image)
  145. {
  146. $data['image'] = "@{$image}";
  147. }
  148. // Check if entities is specified.
  149. if (!is_null($entities))
  150. {
  151. $data['include_entities'] = $entities;
  152. }
  153. // Check if skip_status is specified.
  154. if (!is_null($skip_status))
  155. {
  156. $data['skip_status'] = $skip_status;
  157. }
  158. // Set the API path
  159. $path = '/account/update_profile_image.json';
  160. $header = array('Content-Type' => 'multipart/form-data', 'Expect' => '');
  161. // Send the request.
  162. return $this->sendRequest($path, 'POST', $data, $header);
  163. }
  164. /**
  165. * Method to set one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com.
  166. *
  167. * @param string $background Profile background color.
  168. * @param string $link Profile link color.
  169. * @param string $sidebar_border Profile sidebar's border color.
  170. * @param string $sidebar_fill Profile sidebar's fill color.
  171. * @param string $text Profile text color.
  172. * @param boolean $entities When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  173. * variety of metadata about the tweet in a discreet structure, including: user_mentions, urls, and hashtags.
  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 12.3
  179. */
  180. public function updateProfileColors($background = null, $link = null, $sidebar_border = null, $sidebar_fill = null, $text = null,
  181. $entities = null, $skip_status = null)
  182. {
  183. // Check the rate limit for remaining hits
  184. $this->checkRateLimit('account', 'update_profile_colors');
  185. $data = array();
  186. // Check if background is specified.
  187. if ($background)
  188. {
  189. $data['profile_background_color'] = $background;
  190. }
  191. // Check if link is specified.
  192. if ($link)
  193. {
  194. $data['profile_link_color'] = $link;
  195. }
  196. // Check if sidebar_border is specified.
  197. if ($sidebar_border)
  198. {
  199. $data['profile_sidebar_border_color'] = $sidebar_border;
  200. }
  201. // Check if sidebar_fill is specified.
  202. if ($sidebar_fill)
  203. {
  204. $data['profile_sidebar_fill_color'] = $sidebar_fill;
  205. }
  206. // Check if text is specified.
  207. if ($text)
  208. {
  209. $data['profile_text_color'] = $text;
  210. }
  211. // Check if entities is specified.
  212. if (!is_null($entities))
  213. {
  214. $data['include_entities'] = $entities;
  215. }
  216. // Check if skip_status is true.
  217. if (!is_null($skip_status))
  218. {
  219. $data['skip_status'] = $skip_status;
  220. }
  221. // Set the API path
  222. $path = '/account/update_profile_colors.json';
  223. // Send the request.
  224. return $this->sendRequest($path, 'POST', $data);
  225. }
  226. /**
  227. * Method to get the settings (including current trend, geo and sleep time information) for the authenticating user.
  228. *
  229. * @return array The decoded JSON response
  230. *
  231. * @since 12.3
  232. */
  233. public function getSettings()
  234. {
  235. // Check the rate limit for remaining hits
  236. $this->checkRateLimit('account', 'settings');
  237. // Set the API path
  238. $path = '/account/settings.json';
  239. // Send the request.
  240. return $this->sendRequest($path);
  241. }
  242. /**
  243. * Method to update the authenticating user's settings.
  244. *
  245. * @param integer $location The Yahoo! Where On Earth ID to use as the user's default trend location.
  246. * @param boolean $sleep_time When set to true, t or 1, will enable sleep time for the user.
  247. * @param integer $start_sleep The hour that sleep time should begin if it is enabled.
  248. * @param integer $end_sleep The hour that sleep time should end if it is enabled.
  249. * @param string $time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the
  250. * Rails TimeZone names.
  251. * @param string $lang The language which Twitter should render in for this user.
  252. *
  253. * @return array The decoded JSON response
  254. *
  255. * @since 12.3
  256. */
  257. public function updateSettings($location = null, $sleep_time = false, $start_sleep = null, $end_sleep = null,
  258. $time_zone = null, $lang = null)
  259. {
  260. $data = array();
  261. // Check if location is specified.
  262. if ($location)
  263. {
  264. $data['trend_location_woeid '] = $location;
  265. }
  266. // Check if sleep_time is true.
  267. if ($sleep_time)
  268. {
  269. $data['sleep_time_enabled'] = $sleep_time;
  270. }
  271. // Check if start_sleep is specified.
  272. if ($start_sleep)
  273. {
  274. $data['start_sleep_time'] = $start_sleep;
  275. }
  276. // Check if end_sleep is specified.
  277. if ($end_sleep)
  278. {
  279. $data['end_sleep_time'] = $end_sleep;
  280. }
  281. // Check if time_zone is specified.
  282. if ($time_zone)
  283. {
  284. $data['time_zone'] = $time_zone;
  285. }
  286. // Check if lang is specified.
  287. if ($lang)
  288. {
  289. $data['lang'] = $lang;
  290. }
  291. // Set the API path
  292. $path = '/account/settings.json';
  293. // Send the request.
  294. return $this->sendRequest($path, 'POST', $data);
  295. }
  296. }