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