/libraries/joomla/facebook/event.php

https://bitbucket.org/pastor399/newcastleunifc · PHP · 523 lines · 158 code · 42 blank · 323 comment · 6 complexity · 261dd443e4e9eb5981bde19fb10c7e81 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/event/
  17. * @since 13.1
  18. */
  19. class JFacebookEvent extends JFacebookObject
  20. {
  21. /**
  22. * Method to get information about an event visible to the current user. Requires authentication.
  23. *
  24. * @param string $event The event id.
  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 getEvent($event)
  31. {
  32. return $this->get($event);
  33. }
  34. /**
  35. * Method to get the event's wall. Requires authentication.
  36. *
  37. * @param string $event The event id.
  38. * @param integer $limit The number of objects per page.
  39. * @param integer $offset The object's number on the page.
  40. * @param string $until A unix timestamp or any date accepted by strtotime.
  41. * @param string $since A unix timestamp or any date accepted by strtotime.
  42. *
  43. * @return mixed The decoded JSON response or false if the client is not authenticated.
  44. *
  45. * @since 13.1
  46. */
  47. public function getFeed($event, $limit = 0, $offset = 0, $until = null, $since = null)
  48. {
  49. return $this->getConnection($event, 'feed', '', $limit, $offset, $until, $since);
  50. }
  51. /**
  52. * Method to post a link on event's feed which the current_user is or maybe attending. Requires authentication and publish_stream permission.
  53. *
  54. * @param string $event The event id.
  55. * @param string $link Link URL.
  56. * @param string $message Link message.
  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 createLink($event, $link, $message = null)
  63. {
  64. // Set POST request parameters.
  65. $data = array();
  66. $data['link'] = $link;
  67. $data['message'] = $message;
  68. return $this->createConnection($event, 'feed', $data);
  69. }
  70. /**
  71. * Method to delete a link. Requires authentication and publish_stream permission.
  72. *
  73. * @param mixed $link The Link ID.
  74. *
  75. * @return boolean Returns true if successful, and false otherwise.
  76. *
  77. * @since 13.1
  78. */
  79. public function deleteLink($link)
  80. {
  81. return $this->deleteConnection($link);
  82. }
  83. /**
  84. * Method to post on event's wall. Message or link parameter is required. Requires authentication and publish_stream permission.
  85. *
  86. * @param string $event The event id.
  87. * @param string $message Post message.
  88. * @param string $link Post URL.
  89. * @param string $picture Post thumbnail image (can only be used if link is specified)
  90. * @param string $name Post name (can only be used if link is specified).
  91. * @param string $caption Post caption (can only be used if link is specified).
  92. * @param string $description Post description (can only be used if link is specified).
  93. * @param array $actions Post actions array of objects containing name and link.
  94. *
  95. * @return mixed The decoded JSON response or false if the client is not authenticated.
  96. *
  97. * @since 13.1
  98. */
  99. public function createPost($event, $message = null, $link = null, $picture = null, $name = null, $caption = null,
  100. $description = null, $actions = null)
  101. {
  102. // Set POST request parameters.
  103. $data = array();
  104. $data['message'] = $message;
  105. $data['link'] = $link;
  106. $data['name'] = $name;
  107. $data['caption'] = $caption;
  108. $data['description'] = $description;
  109. $data['actions'] = $actions;
  110. $data['picture'] = $picture;
  111. return $this->createConnection($event, 'feed', $data);
  112. }
  113. /**
  114. * Method to delete a post. Note: you can only delete the post if it was created by the current user.
  115. * Requires authentication and publish_stream permission.
  116. *
  117. * @param string $post The Post ID.
  118. *
  119. * @return boolean Returns true if successful, and false otherwise.
  120. *
  121. * @since 13.1
  122. */
  123. public function deletePost($post)
  124. {
  125. return $this->deleteConnection($post);
  126. }
  127. /**
  128. * Method to post a status message on behalf of the user on the event's wall. Requires authentication and publish_stream permission.
  129. *
  130. * @param string $event The event id.
  131. * @param string $message Status message content.
  132. *
  133. * @return mixed The decoded JSON response or false if the client is not authenticated.
  134. *
  135. * @since 13.1
  136. */
  137. public function createStatus($event, $message)
  138. {
  139. // Set POST request parameters.
  140. $data = array();
  141. $data['message'] = $message;
  142. return $this->createConnection($event, 'feed', $data);
  143. }
  144. /**
  145. * Method to delete a status. Note: you can only delete the post if it was created by the current user.
  146. * Requires authentication and publish_stream permission.
  147. *
  148. * @param string $status The Status ID.
  149. *
  150. * @return boolean Returns true if successful, and false otherwise.
  151. *
  152. * @since 13.1
  153. */
  154. public function deleteStatus($status)
  155. {
  156. return $this->deleteConnection($status);
  157. }
  158. /**
  159. * Method to get the list of invitees for the event. Requires authentication and user_events or friends_events permission.
  160. *
  161. * @param string $event The event id.
  162. * @param integer $limit The number of objects per page.
  163. * @param integer $offset The object's number on the page.
  164. *
  165. * @return mixed The decoded JSON response or false if the client is not authenticated.
  166. *
  167. * @since 13.1
  168. */
  169. public function getInvited($event, $limit = 0, $offset = 0)
  170. {
  171. return $this->getConnection($event, 'invited', '', $limit, $offset);
  172. }
  173. /**
  174. * Method to check if a user is invited to the event. Requires authentication and user_events or friends_events permission.
  175. *
  176. * @param string $event The event id.
  177. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  178. *
  179. * @return array The decoded JSON response or an empty array if the user is not invited.
  180. *
  181. * @since 13.1
  182. */
  183. public function isInvited($event, $user)
  184. {
  185. return $this->getConnection($event, 'invited/' . $user);
  186. }
  187. /**
  188. * Method to invite users to the event. Requires authentication and create_event permission.
  189. *
  190. * @param string $event The event id.
  191. * @param string $users Comma separated list of user ids.
  192. *
  193. * @return boolean Returns true if successful, and false otherwise.
  194. *
  195. * @since 13.1
  196. */
  197. public function createInvite($event, $users)
  198. {
  199. // Set POST request parameters.
  200. $data = array();
  201. $data['users'] = $users;
  202. return $this->createConnection($event, 'invited', $data);
  203. }
  204. /**
  205. * Method to delete a invitation. Note: you can only delete the invite if the current user is the event admin.
  206. * Requires authentication and rsvp_event permission.
  207. *
  208. * @param string $event The event id.
  209. * @param string $user The user id.
  210. *
  211. * @return boolean Returns true if successful, and false otherwise.
  212. *
  213. * @since 13.1
  214. */
  215. public function deleteInvite($event, $user)
  216. {
  217. return $this->deleteConnection($event, 'invited/' . $user);
  218. }
  219. /**
  220. * Method to get the list of attending users. Requires authentication and user_events or friends_events permission.
  221. *
  222. * @param string $event The event id.
  223. * @param integer $limit The number of objects per page.
  224. * @param integer $offset The object's number on the page.
  225. *
  226. * @return mixed The decoded JSON response or false if the client is not authenticated.
  227. *
  228. * @since 13.1
  229. */
  230. public function getAttending($event, $limit = 0, $offset = 0)
  231. {
  232. return $this->getConnection($event, 'attending', '', $limit, $offset);
  233. }
  234. /**
  235. * Method to check if a user is attending an event. Requires authentication and user_events or friends_events permission.
  236. *
  237. * @param string $event The event id.
  238. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  239. *
  240. * @return array The decoded JSON response or an empty array if the user is not invited.
  241. *
  242. * @since 13.1
  243. */
  244. public function isAttending($event, $user)
  245. {
  246. return $this->getConnection($event, 'attending/' . $user);
  247. }
  248. /**
  249. * Method to set the current user as attending. Requires authentication and rsvp_event permission.
  250. *
  251. * @param string $event The event id.
  252. *
  253. * @return boolean Returns true if successful, and false otherwise.
  254. *
  255. * @since 13.1
  256. */
  257. public function createAttending($event)
  258. {
  259. return $this->createConnection($event, 'attending');
  260. }
  261. /**
  262. * Method to get the list of maybe attending users. Requires authentication and user_events or friends_events permission.
  263. *
  264. * @param string $event The event id.
  265. * @param integer $limit The number of objects per page.
  266. * @param integer $offset The object's number on the page.
  267. *
  268. * @return mixed The decoded JSON response or false if the client is not authenticated.
  269. *
  270. * @since 13.1
  271. */
  272. public function getMaybe($event, $limit = 0, $offset = 0)
  273. {
  274. return $this->getConnection($event, 'maybe', '', $limit, $offset);
  275. }
  276. /**
  277. * Method to check if a user is maybe attending an event. Requires authentication and user_events or friends_events permission.
  278. *
  279. * @param string $event The event id.
  280. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  281. *
  282. * @return array The decoded JSON response or an empty array if the user is not invited.
  283. *
  284. * @since 13.1
  285. */
  286. public function isMaybe($event, $user)
  287. {
  288. return $this->getConnection($event, 'maybe/' . $user);
  289. }
  290. /**
  291. * Method to set the current user as maybe attending. Requires authentication and rscp_event permission.
  292. *
  293. * @param string $event The event id.
  294. *
  295. * @return boolean Returns true if successful, and false otherwise.
  296. *
  297. * @since 13.1
  298. */
  299. public function createMaybe($event)
  300. {
  301. return $this->createConnection($event, 'maybe');
  302. }
  303. /**
  304. * Method to get the list of users which declined the event. Requires authentication and user_events or friends_events permission.
  305. *
  306. * @param string $event The event id.
  307. * @param integer $limit The number of objects per page.
  308. * @param integer $offset The object's number on the page.
  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 getDeclined($event, $limit = 0, $offset = 0)
  315. {
  316. return $this->getConnection($event, 'declined', '', $limit, $offset);
  317. }
  318. /**
  319. * Method to check if a user responded 'no' to the event. Requires authentication and user_events or friends_events permission.
  320. *
  321. * @param string $event The event id.
  322. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  323. *
  324. * @return array The decoded JSON response or an empty array if the user is not invited.
  325. *
  326. * @since 13.1
  327. */
  328. public function isDeclined($event, $user)
  329. {
  330. return $this->getConnection($event, 'declined/' . $user);
  331. }
  332. /**
  333. * Method to set the current user as declined. Requires authentication and rscp_event permission.
  334. *
  335. * @param string $event The event id.
  336. *
  337. * @return boolean Returns true if successful, and false otherwise.
  338. *
  339. * @since 13.1
  340. */
  341. public function createDeclined($event)
  342. {
  343. return $this->createConnection($event, 'declined');
  344. }
  345. /**
  346. * Method to get the list of users which have not replied to the event. Requires authentication and user_events or friends_events permission.
  347. *
  348. * @param string $event The event id.
  349. * @param integer $limit The number of objects per page.
  350. * @param integer $offset The object's number on the page.
  351. *
  352. * @return mixed The decoded JSON response or false if the client is not authenticated.
  353. *
  354. * @since 13.1
  355. */
  356. public function getNoreply($event, $limit = 0, $offset = 0)
  357. {
  358. return $this->getConnection($event, 'noreply', '', $limit, $offset);
  359. }
  360. /**
  361. * Method to check if a user has not replied to the event. Requires authentication and user_events or friends_events permission.
  362. *
  363. * @param string $event The event id.
  364. * @param mixed $user Either an integer containing the user ID or a string containing the username.
  365. *
  366. * @return array The decoded JSON response or an empty array if the user is not invited.
  367. *
  368. * @since 13.1
  369. */
  370. public function isNoreply($event, $user)
  371. {
  372. return $this->getConnection($event, 'noreply/' . $user);
  373. }
  374. /**
  375. * Method to get the event's profile picture. Requires authentication and user_events or friends_events permission.
  376. *
  377. * @param string $event The event id.
  378. * @param boolean $redirect If false this will return the URL of the picture without a 302 redirect.
  379. * @param string $type To request a different photo use square | small | normal | large.
  380. *
  381. * @return string The URL to the event's profile picture.
  382. *
  383. * @since 13.1
  384. */
  385. public function getPicture($event, $redirect = true, $type = null)
  386. {
  387. $extra_fields = '';
  388. if ($redirect == false)
  389. {
  390. $extra_fields = '?redirect=false';
  391. }
  392. if ($type)
  393. {
  394. $extra_fields .= (strpos($extra_fields, '?') === false) ? '?type=' . $type : '&type=' . $type;
  395. }
  396. return $this->getConnection($event, 'picture', $extra_fields);
  397. }
  398. /**
  399. * Method to get photos published on event's wall. Requires authentication.
  400. *
  401. * @param string $event The event id.
  402. * @param integer $limit The number of objects per page.
  403. * @param integer $offset The object's number on the page.
  404. * @param string $until A unix timestamp or any date accepted by strtotime.
  405. * @param string $since A unix timestamp or any date accepted by strtotime.
  406. *
  407. * @return mixed The decoded JSON response or false if the client is not authenticated.
  408. *
  409. * @since 13.1
  410. */
  411. public function getPhotos($event, $limit = 0, $offset = 0, $until = null, $since = null)
  412. {
  413. return $this->getConnection($event, 'photos', '', $limit, $offset, $until, $since);
  414. }
  415. /**
  416. * Method to post a photo on event's wall. Requires authentication and publish_stream permission.
  417. *
  418. * @param string $event The event id.
  419. * @param string $source Path to photo.
  420. * @param string $message Photo description.
  421. *
  422. * @return mixed The decoded JSON response or false if the client is not authenticated.
  423. *
  424. * @since 13.1
  425. */
  426. public function createPhoto($event, $source, $message = null)
  427. {
  428. // Set POST request parameters.
  429. $data = array();
  430. $data[basename($source)] = '@' . realpath($source);
  431. if ($message)
  432. {
  433. $data['message'] = $message;
  434. }
  435. return $this->createConnection($event, 'photos', $data, array('Content-Type' => 'multipart/form-data'));
  436. }
  437. /**
  438. * Method to get videos published on event's wall. Requires authentication.
  439. *
  440. * @param string $event The event id.
  441. * @param integer $limit The number of objects per page.
  442. * @param integer $offset The object's number on the page.
  443. * @param string $until A unix timestamp or any date accepted by strtotime.
  444. * @param string $since A unix timestamp or any date accepted by strtotime.
  445. *
  446. * @return mixed The decoded JSON response or false if the client is not authenticated.
  447. *
  448. * @since 13.1
  449. */
  450. public function getVideos($event, $limit = 0, $offset = 0, $until = null, $since = null)
  451. {
  452. return $this->getConnection($event, 'videos', '', $limit, $offset, $until, $since);
  453. }
  454. /**
  455. * Method to post a video on event's wall. Requires authentication and publish_stream permission.
  456. *
  457. * @param string $event The event id.
  458. * @param string $source Path to photo.
  459. * @param string $title Video title.
  460. * @param string $description Video description.
  461. *
  462. * @return mixed The decoded JSON response or false if the client is not authenticated.
  463. *
  464. * @since 13.1
  465. */
  466. public function createVideo($event, $source, $title = null, $description = null)
  467. {
  468. // Set POST request parameters.
  469. $data = array();
  470. $data[basename($source)] = '@' . realpath($source);
  471. if ($title)
  472. {
  473. $data['title'] = $title;
  474. }
  475. if ($description)
  476. {
  477. $data['description'] = $description;
  478. }
  479. return $this->createConnection($event, 'videos', $data, array('Content-Type' => 'multipart/form-data'));
  480. }
  481. }