PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Joomla/Twitter/Profile.php

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