/libraries/joomla/facebook/user.php

https://bitbucket.org/pastor399/newcastleunifc · PHP · 991 lines · 287 code · 71 blank · 633 comment · 12 complexity · 69f688d1b9afd42c5a9e304780213a94 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Facebook
  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. * Facebook API User class for the Joomla Platform.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Facebook
  15. *
  16. * @see http://developers.facebook.com/docs/reference/api/user/
  17. * @since 13.1
  18. */
  19. class JFacebookUser extends JFacebookObject
  20. {
  21. /**
  22. * Method to get the specified user's details. Authentication is required only for some fields.
  23. *
  24. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  25. *
  26. * @return mixed The decoded JSON response or false if the client is not authenticated.
  27. *
  28. * @since 13.1
  29. */
  30. public function getUser($user)
  31. {
  32. return $this->get($user);
  33. }
  34. /**
  35. * Method to get the specified user's friends. Requires authentication.
  36. *
  37. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  38. * @param integer $limit The number of objects per page.
  39. * @param integer $offset The object's number on the page.
  40. *
  41. * @return mixed The decoded JSON response or false if the client is not authenticated.
  42. *
  43. * @since 13.1
  44. */
  45. public function getFriends($user, $limit = 0, $offset = 0)
  46. {
  47. return $this->getConnection($user, 'friends', '', $limit, $offset);
  48. }
  49. /**
  50. * Method to get the user's incoming friend requests. Requires authentication and read_requests permission.
  51. *
  52. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  53. * @param integer $limit The number of objects per page.
  54. * @param integer $offset The object's number on the page.
  55. * @param string $until A unix timestamp or any date accepted by strtotime.
  56. * @param string $since A unix timestamp or any date accepted by strtotime.
  57. *
  58. * @return mixed The decoded JSON response or false if the client is not authenticated.
  59. *
  60. * @since 13.1
  61. */
  62. public function getFriendRequests($user, $limit = 0, $offset = 0, $until = null, $since = null)
  63. {
  64. return $this->getConnection($user, 'friendrequests', '', $limit, $offset, $until, $since);
  65. }
  66. /**
  67. * Method to get the user's friend lists. Requires authentication and read_friendlists permission.
  68. *
  69. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  70. * @param integer $limit The number of objects per page.
  71. * @param integer $offset The object's number on the page.
  72. * @param string $until A unix timestamp or any date accepted by strtotime.
  73. * @param string $since A unix timestamp or any date accepted by strtotime.
  74. *
  75. * @return mixed The decoded JSON response or false if the client is not authenticated.
  76. *
  77. * @since 13.1
  78. */
  79. public function getFriendLists($user, $limit = 0, $offset = 0, $until = null, $since = null)
  80. {
  81. return $this->getConnection($user, 'friendlists', '', $limit, $offset, $until, $since);
  82. }
  83. /**
  84. * Method to get the user's wall. Requires authentication and read_stream permission.
  85. *
  86. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  87. * @param integer $limit The number of objects per page.
  88. * @param integer $offset The object's number on the page.
  89. * @param string $until A unix timestamp or any date accepted by strtotime.
  90. * @param string $since A unix timestamp or any date accepted by strtotime.
  91. *
  92. * @return mixed The decoded JSON response or false if the client is not authenticated.
  93. *
  94. * @since 13.1
  95. */
  96. public function getFeed($user, $limit = 0, $offset = 0, $until = null, $since = null)
  97. {
  98. return $this->getConnection($user, 'feed', '', $limit, $offset, $until, $since);
  99. }
  100. /**
  101. * Method to get the user's news feed. Requires authentication and read_stream permission.
  102. *
  103. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  104. * @param string $filter User's stream filter.
  105. * @param boolean $location Retreive only posts with a location attached.
  106. * @param integer $limit The number of objects per page.
  107. * @param integer $offset The object's number on the page.
  108. * @param string $until A unix timestamp or any date accepted by strtotime.
  109. * @param string $since A unix timestamp or any date accepted by strtotime.
  110. *
  111. * @return mixed The decoded JSON response or false if the client is not authenticated.
  112. *
  113. * @since 13.1
  114. */
  115. public function getHome($user, $filter = null, $location = false, $limit = 0, $offset = 0, $until = null, $since = null)
  116. {
  117. $extra_fields = '';
  118. if ($filter != null)
  119. {
  120. $extra_fields = '?filter=' . $filter;
  121. }
  122. if ($location == true)
  123. {
  124. $extra_fields .= (strpos($extra_fields, '?') === false) ? '?with=location' : '&with=location';
  125. }
  126. return $this->getConnection($user, 'home', $extra_fields, $limit, $offset, $until, $since);
  127. }
  128. /**
  129. * Method to see if a user is a friend of the current user. Requires authentication.
  130. *
  131. * @param mixed $current_user Either an integer containing the user ID or a string containing the username for the current user.
  132. * @param mixed $user Either an integer containing the user ID or a string containing the username for the user.
  133. *
  134. * @return mixed The decoded JSON response or false if the client is not authenticated.
  135. *
  136. * @since 13.1
  137. */
  138. public function hasFriend($current_user, $user)
  139. {
  140. return $this->getConnection($current_user, 'friends/' . $user);
  141. }
  142. /**
  143. * Method to get mutual friends of one user and the current user. Requires authentication.
  144. *
  145. * @param mixed $current_user Either an integer containing the user ID or a string containing the username for the current user.
  146. * @param mixed $user Either an integer containing the user ID or a string containing the username for the user.
  147. * @param integer $limit The number of objects per page.
  148. * @param integer $offset The object's number on the page.
  149. *
  150. * @return mixed The decoded JSON response or false if the client is not authenticated.
  151. *
  152. * @since 13.1
  153. */
  154. public function getMutualFriends($current_user, $user, $limit = 0, $offset = 0)
  155. {
  156. return $this->getConnection($current_user, 'mutualfriends/' . $user, '', $limit, $offset);
  157. }
  158. /**
  159. * Method to get the user's profile picture. Requires authentication.
  160. *
  161. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  162. * @param boolean $redirect If false this will return the URL of the profile picture without a 302 redirect.
  163. * @param string $type To request a different photo use square | small | normal | large.
  164. *
  165. * @return string The URL to the user's profile picture.
  166. *
  167. * @since 13.1
  168. */
  169. public function getPicture($user, $redirect = true, $type = null)
  170. {
  171. $extra_fields = '';
  172. if ($redirect == false)
  173. {
  174. $extra_fields = '?redirect=false';
  175. }
  176. if ($type != null)
  177. {
  178. $extra_fields .= (strpos($extra_fields, '?') === false) ? '?type=' . $type : '&type=' . $type;
  179. }
  180. return $this->getConnection($user, 'picture', $extra_fields);
  181. }
  182. /**
  183. * Method to get the user's family relationships. Requires authentication and user_relationships permission..
  184. *
  185. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  186. * @param integer $limit The number of objects per page.
  187. * @param integer $offset The object's number on the page.
  188. *
  189. * @return mixed The decoded JSON response or false if the client is not authenticated.
  190. *
  191. * @since 13.1
  192. */
  193. public function getFamily($user, $limit = 0, $offset = 0)
  194. {
  195. return $this->getConnection($user, 'family', '', $limit, $offset);
  196. }
  197. /**
  198. * Method to get the user's notifications. Requires authentication and manage_notifications permission.
  199. *
  200. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  201. * @param boolean $read Enables you to see notifications that the user has already read.
  202. * @param integer $limit The number of objects per page.
  203. * @param integer $offset The object's number on the page.
  204. * @param string $until A unix timestamp or any date accepted by strtotime.
  205. * @param string $since A unix timestamp or any date accepted by strtotime.
  206. *
  207. * @return mixed The decoded JSON response or false if the client is not authenticated.
  208. *
  209. * @since 13.1
  210. */
  211. public function getNotifications($user, $read = null, $limit = 0, $offset = 0, $until = null, $since = null)
  212. {
  213. if ($read == true)
  214. {
  215. $read = '?include_read=1';
  216. }
  217. // Send the request.
  218. return $this->getConnection($user, 'notifications', $read, $limit, $offset, $until, $since);
  219. }
  220. /**
  221. * Method to mark a notification as read. Requires authentication and manage_notifications permission.
  222. *
  223. * @param string $notification The notification id.
  224. *
  225. * @return boolean Returns true if successful, and false otherwise.
  226. *
  227. * @since 13.1
  228. */
  229. public function updateNotification($notification)
  230. {
  231. $data['unread'] = 0;
  232. return $this->createConnection($notification, null, $data);
  233. }
  234. /**
  235. * Method to get the user's permissions. Requires authentication.
  236. *
  237. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  238. * @param integer $limit The number of objects per page.
  239. * @param integer $offset The object's number on the page.
  240. *
  241. * @return mixed The decoded JSON response or false if the client is not authenticated.
  242. *
  243. * @since 13.1
  244. */
  245. public function getPermissions($user, $limit = 0, $offset = 0)
  246. {
  247. return $this->getConnection($user, 'permissions', '', $limit, $offset);
  248. }
  249. /**
  250. * Method to revoke a specific permission on behalf of a user. Requires authentication.
  251. *
  252. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  253. * @param string $permission The permission to revoke. If none specified, then this will de-authorize the application completely.
  254. *
  255. * @return mixed The decoded JSON response or false if the client is not authenticated.
  256. *
  257. * @since 13.1
  258. */
  259. public function deletePermission($user, $permission = '')
  260. {
  261. return $this->deleteConnection($user, 'permissions', '?permission=' . $permission);
  262. }
  263. /**
  264. * Method to get the user's albums. Requires authentication and user_photos or friends_photos permission.
  265. *
  266. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  267. * @param integer $limit The number of objects per page.
  268. * @param integer $offset The object's number on the page.
  269. * @param string $until A unix timestamp or any date accepted by strtotime.
  270. * @param string $since A unix timestamp or any date accepted by strtotime.
  271. *
  272. * @return mixed The decoded JSON response or false if the client is not authenticated.
  273. *
  274. * @since 13.1
  275. */
  276. public function getAlbums($user, $limit = 0, $offset = 0, $until = null, $since = null)
  277. {
  278. return $this->getConnection($user, 'albums', '', $limit, $offset, $until, $since);
  279. }
  280. /**
  281. * Method to create an album for a user. Requires authentication and publish_stream permission.
  282. *
  283. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  284. * @param string $name Album name.
  285. * @param string $description Album description.
  286. * @param json $privacy A JSON-encoded object that defines the privacy setting for the album.
  287. *
  288. * @return mixed The decoded JSON response or false if the client is not authenticated.
  289. *
  290. * @since 13.1
  291. */
  292. public function createAlbum($user, $name, $description = null, $privacy = null)
  293. {
  294. // Set POST request parameters.
  295. $data = array();
  296. $data['name'] = $name;
  297. $data['description'] = $description;
  298. $data['privacy'] = $privacy;
  299. return $this->createConnection($user, 'albums', $data);
  300. }
  301. /**
  302. * Method to get the user's checkins. Requires authentication and user_checkins or friends_checkins permission
  303. *
  304. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  305. * @param integer $limit The number of objects per page.
  306. * @param integer $offset The object's number on the page.
  307. * @param string $until A unix timestamp or any date accepted by strtotime.
  308. * @param string $since A unix timestamp or any date accepted by strtotime.
  309. *
  310. * @return mixed The decoded JSON response or false if the client is not authenticated.
  311. *
  312. * @since 13.1
  313. */
  314. public function getCheckins($user, $limit = 0, $offset = 0, $until = null, $since = null)
  315. {
  316. return $this->getConnection($user, 'checkins', '', $limit, $offset, $until, $since);
  317. }
  318. /**
  319. * Method to create a checkin for a user. Requires authentication and publish_checkins permission.
  320. *
  321. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  322. * @param string $place Id of the Place Page.
  323. * @param string $coordinates A JSON-encoded string containing latitute and longitude.
  324. * @param string $tags Comma separated list of USER_IDs.
  325. * @param string $message A message to add to the checkin.
  326. * @param string $link A link to add to the checkin.
  327. * @param string $picture A picture to add to the checkin.
  328. *
  329. * @return mixed The decoded JSON response or false if the client is not authenticated.
  330. *
  331. * @since 13.1
  332. */
  333. public function createCheckin($user, $place, $coordinates, $tags = null, $message = null, $link = null, $picture = null)
  334. {
  335. // Set POST request parameters.
  336. $data = array();
  337. $data['place'] = $place;
  338. $data['coordinates'] = $coordinates;
  339. $data['tags'] = $tags;
  340. $data['message'] = $message;
  341. $data['link'] = $link;
  342. $data['picture'] = $picture;
  343. return $this->createConnection($user, 'checkins', $data);
  344. }
  345. /**
  346. * Method to get the user's likes. Requires authentication and user_likes or friends_likes permission.
  347. *
  348. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  349. * @param integer $limit The number of objects per page.
  350. * @param integer $offset The object's number on the page.
  351. * @param string $until A unix timestamp or any date accepted by strtotime.
  352. * @param string $since A unix timestamp or any date accepted by strtotime.
  353. *
  354. * @return mixed The decoded JSON response or false if the client is not authenticated.
  355. *
  356. * @since 13.1
  357. */
  358. public function getLikes($user, $limit = 0, $offset = 0, $until = null, $since = null)
  359. {
  360. return $this->getConnection($user, 'likes', '', $limit, $offset, $until, $since);
  361. }
  362. /**
  363. * Method to see if a user likes a specific Page. Requires authentication.
  364. *
  365. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  366. * @param string $page Facebook ID of the Page.
  367. *
  368. * @return mixed The decoded JSON response or false if the client is not authenticated.
  369. *
  370. * @since 13.1
  371. */
  372. public function likesPage($user, $page)
  373. {
  374. return $this->getConnection($user, 'likes/' . $page);
  375. }
  376. /**
  377. * Method to get the current user's events. Requires authentication and user_events or friends_events permission.
  378. *
  379. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  380. * @param integer $limit The number of objects per page.
  381. * @param integer $offset The object's number on the page.
  382. * @param string $until A unix timestamp or any date accepted by strtotime.
  383. * @param string $since A unix timestamp or any date accepted by strtotime.
  384. *
  385. * @return mixed The decoded JSON response or false if the client is not authenticated.
  386. *
  387. * @since 13.1
  388. */
  389. public function getEvents($user, $limit = 0, $offset = 0, $until = null, $since = null)
  390. {
  391. return $this->getConnection($user, 'events', '', $limit, $offset, $until, $since);
  392. }
  393. /**
  394. * Method to create an event for a user. Requires authentication create_event permission.
  395. *
  396. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  397. * @param string $name Event name.
  398. * @param string $start_time Event start time as UNIX timestamp.
  399. * @param string $end_time Event end time as UNIX timestamp.
  400. * @param string $description Event description.
  401. * @param string $location Event location.
  402. * @param string $location_id Facebook Place ID of the place the Event is taking place.
  403. * @param string $privacy_type Event privacy setting, a string containing 'OPEN' (default), 'CLOSED', or 'SECRET'.
  404. *
  405. * @return mixed The decoded JSON response or false if the client is not authenticated.
  406. *
  407. * @since 13.1
  408. */
  409. public function createEvent($user, $name, $start_time, $end_time = null, $description = null,
  410. $location = null, $location_id = null, $privacy_type = null)
  411. {
  412. // Set POST request parameters.
  413. $data = array();
  414. $data['start_time'] = $start_time;
  415. $data['name'] = $name;
  416. $data['end_time'] = $end_time;
  417. $data['description'] = $description;
  418. $data['location'] = $location;
  419. $data['location_id'] = $location_id;
  420. $data['privacy_type'] = $privacy_type;
  421. return $this->createConnection($user, 'events', $data);
  422. }
  423. /**
  424. * Method to edit an event. Requires authentication create_event permission.
  425. *
  426. * @param mixed $event Event ID.
  427. * @param string $name Event name.
  428. * @param string $start_time Event start time as UNIX timestamp.
  429. * @param string $end_time Event end time as UNIX timestamp.
  430. * @param string $description Event description.
  431. * @param string $location Event location.
  432. * @param string $location_id Facebook Place ID of the place the Event is taking place.
  433. * @param string $privacy_type Event privacy setting, a string containing 'OPEN' (default), 'CLOSED', or 'SECRET'.
  434. *
  435. * @return mixed The decoded JSON response or false if the client is not authenticated.
  436. *
  437. * @since 13.1
  438. */
  439. public function editEvent($event, $name = null, $start_time = null, $end_time = null, $description = null,
  440. $location = null, $location_id = null, $privacy_type = null)
  441. {
  442. // Set POST request parameters.
  443. $data = array();
  444. $data['start_time'] = $start_time;
  445. $data['name'] = $name;
  446. $data['end_time'] = $end_time;
  447. $data['description'] = $description;
  448. $data['location'] = $location;
  449. $data['location_id'] = $location_id;
  450. $data['privacy_type'] = $privacy_type;
  451. return $this->createConnection($event, null, $data);
  452. }
  453. /**
  454. * Method to delete an event. Note: you can only delete the event if it was created by the same app. Requires authentication create_event permission.
  455. *
  456. * @param string $event Event ID.
  457. *
  458. * @return boolean Returns true if successful, and false otherwise.
  459. *
  460. * @since 13.1
  461. */
  462. public function deleteEvent($event)
  463. {
  464. return $this->deleteConnection($event);
  465. }
  466. /**
  467. * Method to get the groups that the user belongs to. Requires authentication and user_groups or friends_groups permission.
  468. *
  469. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  470. * @param integer $limit The number of objects per page.
  471. * @param integer $offset The object's number on the page.
  472. *
  473. * @return mixed The decoded JSON response or false if the client is not authenticated.
  474. *
  475. * @since 13.1
  476. */
  477. public function getGroups($user, $limit = 0, $offset = 0)
  478. {
  479. return $this->getConnection($user, 'groups', '', $limit, $offset);
  480. }
  481. /**
  482. * Method to get the user's posted links. Requires authentication and user_groups or friends_groups permission.
  483. *
  484. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  485. * @param integer $limit The number of objects per page.
  486. * @param integer $offset The object's number on the page.
  487. * @param string $until A unix timestamp or any date accepted by strtotime.
  488. * @param string $since A unix timestamp or any date accepted by strtotime.
  489. *
  490. * @return mixed The decoded JSON response or false if the client is not authenticated.
  491. *
  492. * @since 13.1
  493. */
  494. public function getLinks($user, $limit = 0, $offset = 0, $until = null, $since = null)
  495. {
  496. return $this->getConnection($user, 'links', '', $limit, $offset, $until, $since);
  497. }
  498. /**
  499. * Method to post a link on user's feed. Requires authentication and publish_stream permission.
  500. *
  501. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  502. * @param string $link Link URL.
  503. * @param strin $message Link message.
  504. *
  505. * @return mixed The decoded JSON response or false if the client is not authenticated.
  506. *
  507. * @since 13.1
  508. */
  509. public function createLink($user, $link, $message = null)
  510. {
  511. // Set POST request parameters.
  512. $data = array();
  513. $data['link'] = $link;
  514. $data['message'] = $message;
  515. return $this->createConnection($user, 'feed', $data);
  516. }
  517. /**
  518. * Method to delete a link. Requires authentication and publish_stream permission.
  519. *
  520. * @param mixed $link The Link ID.
  521. *
  522. * @return boolean Returns true if successful, and false otherwise.
  523. *
  524. * @since 13.1
  525. */
  526. public function deleteLink($link)
  527. {
  528. return $this->deleteConnection($link);
  529. }
  530. /**
  531. * Method to get the user's notes. Requires authentication and user_groups or friends_groups permission.
  532. *
  533. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  534. * @param integer $limit The number of objects per page.
  535. * @param integer $offset The object's number on the page.
  536. * @param string $until A unix timestamp or any date accepted by strtotime.
  537. * @param string $since A unix timestamp or any date accepted by strtotime.
  538. *
  539. * @return mixed The decoded JSON response or false if the client is not authenticated.
  540. *
  541. * @since 13.1
  542. */
  543. public function getNotes($user, $limit = 0, $offset = 0, $until = null, $since = null)
  544. {
  545. return $this->getConnection($user, 'notes', '', $limit, $offset, $until, $since);
  546. }
  547. /**
  548. * Method to create a note on the behalf of the user.
  549. * Requires authentication and publish_stream permission, user_groups or friends_groups permission.
  550. *
  551. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  552. * @param string $subject The subject of the note.
  553. * @param string $message Note content.
  554. *
  555. * @return mixed The decoded JSON response or false if the client is not authenticated.
  556. *
  557. * @since 13.1
  558. */
  559. public function createNote($user, $subject, $message)
  560. {
  561. // Set POST request parameters.
  562. $data = array();
  563. $data['subject'] = $subject;
  564. $data['message'] = $message;
  565. return $this->createConnection($user, 'notes', $data);
  566. }
  567. /**
  568. * Method to get the user's photos. Requires authentication and user_groups or friends_groups permission.
  569. *
  570. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  571. * @param integer $limit The number of objects per page.
  572. * @param integer $offset The object's number on the page.
  573. * @param string $until A unix timestamp or any date accepted by strtotime.
  574. * @param string $since A unix timestamp or any date accepted by strtotime.
  575. *
  576. * @return mixed The decoded JSON response or false if the client is not authenticated.
  577. *
  578. * @since 13.1
  579. */
  580. public function getPhotos($user, $limit = 0, $offset = 0, $until = null, $since = null)
  581. {
  582. return $this->getConnection($user, 'photos', '', $limit, $offset, $until, $since);
  583. }
  584. /**
  585. * Method to post a photo on user's wall. Requires authentication and publish_stream permission, user_groups or friends_groups permission.
  586. *
  587. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  588. * @param string $source Path to photo.
  589. * @param string $message Photo description.
  590. * @param string $place Facebook ID of the place associated with the photo.
  591. * @param boolean $no_story If set to 1, optionally suppresses the feed story that is automatically
  592. * generated on a user’s profile when they upload a photo using your application.
  593. *
  594. * @return mixed The decoded JSON response or false if the client is not authenticated.
  595. *
  596. * @since 13.1
  597. */
  598. public function createPhoto($user, $source, $message = null, $place = null, $no_story = null)
  599. {
  600. // Set POST request parameters.
  601. $data = array();
  602. $data[basename($source)] = '@' . realpath($source);
  603. $data['message'] = $message;
  604. $data['place'] = $place;
  605. $data['no_story'] = $no_story;
  606. return $this->createConnection($user, 'photos', $data, array('Content-Type' => 'multipart/form-data'));
  607. }
  608. /**
  609. * Method to get the user's posts. Requires authentication and read_stream permission for non-public posts.
  610. *
  611. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  612. * @param boolean $location Retreive only posts with a location attached.
  613. * @param integer $limit The number of objects per page.
  614. * @param integer $offset The object's number on the page.
  615. * @param string $until A unix timestamp or any date accepted by strtotime.
  616. * @param string $since A unix timestamp or any date accepted by strtotime.
  617. *
  618. * @return mixed The decoded JSON response or false if the client is not authenticated.
  619. *
  620. * @since 13.1
  621. */
  622. public function getPosts($user, $location = false, $limit = 0, $offset = 0, $until = null, $since = null)
  623. {
  624. if ($location == true)
  625. {
  626. $location = '?with=location';
  627. }
  628. // Send the request.
  629. return $this->getConnection($user, 'posts', $location, $limit, $offset, $until, $since);
  630. }
  631. /**
  632. * Method to post on a user's wall. Message or link parameter is required. Requires authentication and publish_stream permission.
  633. *
  634. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  635. * @param string $message Post message.
  636. * @param string $link Post URL.
  637. * @param string $picture Post thumbnail image (can only be used if link is specified)
  638. * @param string $name Post name (can only be used if link is specified).
  639. * @param string $caption Post caption (can only be used if link is specified).
  640. * @param string $description Post description (can only be used if link is specified).
  641. * @param array $actions Post actions array of objects containing name and link.
  642. * @param string $place Facebook Page ID of the location associated with this Post.
  643. * @param string $tags Comma-separated list of Facebook IDs of people tagged in this Post.
  644. * For example: 1207059,701732. You cannot specify this field without also specifying a place.
  645. * @param string $privacy Post privacy settings (can only be specified if the Timeline being posted
  646. * on belongs to the User creating the Post).
  647. * @param string $object_attachment Facebook ID for an existing picture in the User's photo albums to use as the thumbnail image.
  648. * The User must be the owner of the photo, and the photo cannot be part of a message attachment.
  649. *
  650. * @return mixed The decoded JSON response or false if the client is not authenticated.
  651. *
  652. * @since 13.1
  653. */
  654. public function createPost($user, $message = null, $link = null, $picture = null, $name = null, $caption = null,
  655. $description = null, $actions = null, $place = null, $tags = null, $privacy = null, $object_attachment = null)
  656. {
  657. // Set POST request parameters.
  658. $data = array();
  659. $data['message'] = $message;
  660. $data['link'] = $link;
  661. $data['name'] = $name;
  662. $data['caption'] = $caption;
  663. $data['description'] = $description;
  664. $data['actions'] = $actions;
  665. $data['place'] = $place;
  666. $data['tags'] = $tags;
  667. $data['privacy'] = $privacy;
  668. $data['object_attachment'] = $object_attachment;
  669. $data['picture'] = $picture;
  670. return $this->createConnection($user, 'feed', $data);
  671. }
  672. /**
  673. * Method to delete a post. Note: you can only delete the post if it was created by the current user. Requires authentication
  674. *
  675. * @param string $post The Post ID.
  676. *
  677. * @return mixed The decoded JSON response or false if the client is not authenticated.
  678. *
  679. * @since 13.1
  680. */
  681. public function deletePost($post)
  682. {
  683. return $this->deleteConnection($post);
  684. }
  685. /**
  686. * Method to get the user's statuses. Requires authentication read_stream permission.
  687. *
  688. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  689. * @param integer $limit The number of objects per page.
  690. * @param integer $offset The object's number on the page.
  691. * @param string $until A unix timestamp or any date accepted by strtotime.
  692. * @param string $since A unix timestamp or any date accepted by strtotime.
  693. *
  694. * @return mixed The decoded JSON response or false if the client is not authenticated.
  695. *
  696. * @since 13.1
  697. */
  698. public function getStatuses($user, $limit = 0, $offset = 0, $until = null, $since = null)
  699. {
  700. return $this->getConnection($user, 'statuses', '', $limit, $offset, $until, $since);
  701. }
  702. /**
  703. * Method to post a status message on behalf of the user. Requires authentication publish_stream permission.
  704. *
  705. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  706. * @param string $message Status message content.
  707. *
  708. * @return mixed The decoded JSON response or false if the client is not authenticated.
  709. *
  710. * @since 13.1
  711. */
  712. public function createStatus($user, $message)
  713. {
  714. // Set POST request parameters.
  715. $data = array();
  716. $data['message'] = $message;
  717. return $this->createConnection($user, 'feed', $data);
  718. }
  719. /**
  720. * Method to delete a status. Note: you can only delete the post if it was created by the current user.
  721. * Requires authentication publish_stream permission.
  722. *
  723. * @param string $status The Status ID.
  724. *
  725. * @return mixed The decoded JSON response or false if the client is not authenticated.
  726. *
  727. * @since 13.1
  728. */
  729. public function deleteStatus($status)
  730. {
  731. return $this->deleteConnection($status);
  732. }
  733. /**
  734. * Method to get the videos the user has been tagged in. Requires authentication and user_videos or friends_videos permission.
  735. *
  736. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  737. * @param integer $limit The number of objects per page.
  738. * @param integer $offset The object's number on the page.
  739. * @param string $until A unix timestamp or any date accepted by strtotime.
  740. * @param string $since A unix timestamp or any date accepted by strtotime.
  741. *
  742. * @return mixed The decoded JSON response or false if the client is not authenticated.
  743. *
  744. * @since 13.1
  745. */
  746. public function getVideos($user, $limit = 0, $offset = 0, $until = null, $since = null)
  747. {
  748. return $this->getConnection($user, 'videos', '', $limit, $offset, $until, $since);
  749. }
  750. /**
  751. * Method to post a video on behalf of the user. Requires authentication and publish_stream permission.
  752. *
  753. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  754. * @param string $source Path to video.
  755. * @param string $title Video title.
  756. * @param string $description Video description.
  757. *
  758. * @return mixed The decoded JSON response or false if the client is not authenticated.
  759. *
  760. * @since 13.1
  761. */
  762. public function createVideo($user, $source, $title = null, $description = null)
  763. {
  764. // Set POST request parameters.
  765. $data = array();
  766. $data[basename($source)] = '@' . realpath($source);
  767. $data['title'] = $title;
  768. $data['description'] = $description;
  769. return $this->createConnection($user, 'videos', $data, array('Content-Type' => 'multipart/form-data'));
  770. }
  771. /**
  772. * Method to get the posts the user has been tagged in. Requires authentication and user_videos or friends_videos permission.
  773. *
  774. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  775. * @param integer $limit The number of objects per page.
  776. * @param integer $offset The object's number on the page.
  777. * @param string $until A unix timestamp or any date accepted by strtotime.
  778. * @param string $since A unix timestamp or any date accepted by strtotime.
  779. *
  780. * @return mixed The decoded JSON response or false if the client is not authenticated.
  781. *
  782. * @since 13.1
  783. */
  784. public function getTagged($user, $limit = 0, $offset = 0, $until = null, $since = null)
  785. {
  786. return $this->getConnection($user, 'tagged', '', $limit, $offset, $until, $since);
  787. }
  788. /**
  789. * Method to get the activities listed on the user's profile. Requires authentication and user_activities or friends_activities permission.
  790. *
  791. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  792. * @param integer $limit The number of objects per page.
  793. * @param integer $offset The object's number on the page.
  794. * @param string $until A unix timestamp or any date accepted by strtotime.
  795. * @param string $since A unix timestamp or any date accepted by strtotime.
  796. *
  797. * @return mixed The decoded JSON response or false if the client is not authenticated.
  798. *
  799. * @since 13.1
  800. */
  801. public function getActivities($user, $limit = 0, $offset = 0, $until = null, $since = null)
  802. {
  803. return $this->getConnection($user, 'activities', '', $limit, $offset, $until, $since);
  804. }
  805. /**
  806. * Method to get the books listed on the user's profile. Requires authentication and user_likes or friends_likes permission.
  807. *
  808. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  809. * @param integer $limit The number of objects per page.
  810. * @param integer $offset The object's number on the page.
  811. * @param string $until A unix timestamp or any date accepted by strtotime.
  812. * @param string $since A unix timestamp or any date accepted by strtotime.
  813. *
  814. * @return mixed The decoded JSON response or false if the client is not authenticated.
  815. *
  816. * @since 13.1
  817. */
  818. public function getBooks($user, $limit = 0, $offset = 0, $until = null, $since = null)
  819. {
  820. return $this->getConnection($user, 'books', '', $limit, $offset, $until, $since);
  821. }
  822. /**
  823. * Method to get the interests listed on the user's profile. Requires authentication.
  824. *
  825. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  826. * @param integer $limit The number of objects per page.
  827. * @param integer $offset The object's number on the page.
  828. * @param string $until A unix timestamp or any date accepted by strtotime.
  829. * @param string $since A unix timestamp or any date accepted by strtotime.
  830. *
  831. * @return mixed The decoded JSON response or false if the client is not authenticated.
  832. *
  833. * @since 13.1
  834. */
  835. public function getInterests($user, $limit = 0, $offset = 0, $until = null, $since = null)
  836. {
  837. return $this->getConnection($user, 'interests', '', $limit, $offset, $until, $since);
  838. }
  839. /**
  840. * Method to get the movies listed on the user's profile. Requires authentication and user_likes or friends_likes permission.
  841. *
  842. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  843. * @param integer $limit The number of objects per page.
  844. * @param integer $offset The object's number on the page.
  845. * @param string $until A unix timestamp or any date accepted by strtotime.
  846. * @param string $since A unix timestamp or any date accepted by strtotime.
  847. *
  848. * @return mixed The decoded JSON response or false if the client is not authenticated.
  849. *
  850. * @since 13.1
  851. */
  852. public function getMovies($user, $limit = 0, $offset = 0, $until = null, $since = null)
  853. {
  854. return $this->getConnection($user, 'movies', '', $limit, $offset, $until, $since);
  855. }
  856. /**
  857. * Method to get the television listed on the user's profile. Requires authentication and user_likes or friends_likes permission.
  858. *
  859. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  860. * @param integer $limit The number of objects per page.
  861. * @param integer $offset The object's number on the page.
  862. * @param string $until A unix timestamp or any date accepted by strtotime.
  863. * @param string $since A unix timestamp or any date accepted by strtotime.
  864. *
  865. * @return mixed The decoded JSON response or false if the client is not authenticated.
  866. *
  867. * @since 13.1
  868. */
  869. public function getTelevision($user, $limit = 0, $offset = 0, $until = null, $since = null)
  870. {
  871. return $this->getConnection($user, 'television', '', $limit, $offset, $until, $since);
  872. }
  873. /**
  874. * Method to get the music listed on the user's profile. Requires authentication user_likes or friends_likes permission.
  875. *
  876. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  877. * @param integer $limit The number of objects per page.
  878. * @param integer $offset The object's number on the page.
  879. * @param string $until A unix timestamp or any date accepted by strtotime.
  880. * @param string $since A unix timestamp or any date accepted by strtotime.
  881. *
  882. * @return mixed The decoded JSON response or false if the client is not authenticated.
  883. *
  884. * @since 13.1
  885. */
  886. public function getMusic($user, $limit = 0, $offset = 0, $until = null, $since = null)
  887. {
  888. return $this->getConnection($user, 'music', '', $limit, $offset, $until, $since);
  889. }
  890. /**
  891. * Method to get the user's subscribers. Requires authentication and user_subscriptions or friends_subscriptions permission.
  892. *
  893. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  894. * @param integer $limit The number of objects per page.
  895. * @param integer $offset The object's number on the page.
  896. *
  897. * @return mixed The decoded JSON response or false if the client is not authenticated.
  898. *
  899. * @since 13.1
  900. */
  901. public function getSubscribers($user, $limit = 0, $offset = 0)
  902. {
  903. return $this->getConnection($user, 'subscribers', '', $limit, $offset);
  904. }
  905. /**
  906. * Method to get the people the user is subscribed to. Requires authentication and user_subscriptions or friends_subscriptions permission.
  907. *
  908. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  909. * @param integer $limit The number of objects per page.
  910. * @param integer $offset The object's number on the page.
  911. *
  912. * @return mixed The decoded JSON response or false if the client is not authenticated.
  913. *
  914. * @since 13.1
  915. */
  916. public function getSubscribedTo($user, $limit = 0, $offset = 0)
  917. {
  918. return $this->getConnection($user, 'subscribedto', '', $limit, $offset);
  919. }
  920. }