ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/facebook/trunk/facebookapi_php5_restlib.php
(Generate patch)

Comparing facebook/trunk/facebookapi_php5_restlib.php (file contents):
Revision 952 by douglas, 2007-10-10T17:24:17-07:00 vs.
Revision 1015 by douglas, 2008-05-25T05:56:55-07:00

# Line 10 | Line 10
10   // +---------------------------------------------------------------------------+
11   // | Facebook Platform PHP5 client                                             |
12   // +---------------------------------------------------------------------------+
13 < // | Copyright (c) 2007 Facebook, Inc.                                         |
13 > // | Copyright (c) 2007-2008 Facebook, Inc.                                    |
14   // | All rights reserved.                                                      |
15   // |                                                                           |
16   // | Redistribution and use in source and binary forms, with or without        |
# Line 45 | Line 45 | class FacebookRestClient {
45    public $friends_list; // to save making the friends.get api call, this will get prepopulated on canvas pages
46    public $added;        // to save making the users.isAppAdded api call, this will get prepopulated on canvas pages
47    public $json;
48 +  public $batch_mode;
49 +  private $batch_queue;
50 +  private $call_as_apikey;
51 +
52 +  const BATCH_MODE_DEFAULT = 0;
53 +  const BATCH_MODE_SERVER_PARALLEL = 0;
54 +  const BATCH_MODE_SERIAL_ONLY = 2;
55  
56    /**
57     * Create the client.
58 <   * @param string $session_key if you haven't gotten a session key yet, leave
59 <   *                            this as null and then set it later by just
60 <   *                            directly accessing the $session_key member
58 >   * @param string $session_key if you haven't gotten a session key yet, leave
59 >   *                            this as null and then set it later by just
60 >   *                            directly accessing the $session_key member
61     *                            variable.
62     */
63    public function __construct($api_key, $secret, $session_key=null) {
64      $this->secret       = $secret;
65      $this->session_key  = $session_key;
66      $this->api_key      = $api_key;
67 +    $this->batch_mode = FacebookRestClient::BATCH_MODE_DEFAULT;
68      $this->last_call_id = 0;
69 +    $this->call_as_apikey = '';
70      $this->server_addr  = Facebook::get_facebook_url('api') . '/restserver.php';
71 <    if ($GLOBALS['facebook_config']['debug']) {
71 >    if (!empty($GLOBALS['facebook_config']['debug'])) {
72        $this->cur_id = 0;
73        ?>
74   <script type="text/javascript">
75   var types = ['params', 'xml', 'php', 'sxml'];
76 + function getStyle(elem, style) {
77 +  if (elem.getStyle) {
78 +    return elem.getStyle(style);
79 +  } else {
80 +    return elem.style[style];
81 +  }
82 + }
83 + function setStyle(elem, style, value) {
84 +  if (elem.setStyle) {
85 +    elem.setStyle(style, value);
86 +  } else {
87 +    elem.style[style] = value;
88 +  }
89 + }
90   function toggleDisplay(id, type) {
91 <  for each (var t in types) {
92 <    if (t != type || document.getElementById(t + id).style.display == 'block') {
93 <      document.getElementById(t + id).style.display = 'none';
94 <    } else {
95 <      document.getElementById(t + id).style.display = 'block';
91 >  for (var i = 0; i < types.length; i++) {
92 >    var t = types[i];
93 >    var pre = document.getElementById(t + id);
94 >    if (pre) {
95 >      if (t != type || getStyle(pre, 'display') == 'block') {
96 >        setStyle(pre, 'display', 'none');
97 >      } else {
98 >        setStyle(pre, 'display', 'block');
99 >      }
100      }
101    }
102    return false;
# Line 79 | Line 106 | function toggleDisplay(id, type) {
106      }
107    }
108  
109 +
110 +  /**
111 +   * Start a batch operation.
112 +   */
113 +  public function begin_batch() {
114 +    if($this->batch_queue !== null)
115 +    {
116 +      throw new FacebookRestClientException(FacebookAPIErrorCodes::API_EC_BATCH_ALREADY_STARTED,
117 +      FacebookAPIErrorCodes::$api_error_descriptions[FacebookAPIErrorCodes::API_EC_BATCH_ALREADY_STARTED]);
118 +    }
119 +
120 +    $this->batch_queue = array();
121 +  }
122 +
123 +  /*
124 +   * End current batch operation
125 +   */
126 +  public function end_batch() {
127 +    if($this->batch_queue === null) {
128 +      throw new FacebookRestClientException(FacebookAPIErrorCodes::API_EC_BATCH_NOT_STARTED,
129 +      FacebookAPIErrorCodes::$api_error_descriptions[FacebookAPIErrorCodes::API_EC_BATCH_NOT_STARTED]);
130 +    }
131 +
132 +    $this->execute_server_side_batch();
133 +
134 +    $this->batch_queue = null;
135 +  }
136 +
137 +
138 +  private function execute_server_side_batch() {
139 +
140 +
141 +    $item_count = count($this->batch_queue);
142 +    $method_feed = array();
143 +    foreach($this->batch_queue as $batch_item) {
144 +      $method_feed[] = $this->create_post_string($batch_item['m'], $batch_item['p']);
145 +    }
146 +
147 +    $method_feed_json = json_encode($method_feed);
148 +
149 +    $serial_only = $this->batch_mode == FacebookRestClient::BATCH_MODE_SERIAL_ONLY ;
150 +    $params = array('method_feed' => $method_feed_json, 'serial_only' => $serial_only);
151 +    if ($this->call_as_apikey) {
152 +      $params['call_as_apikey'] = $this->call_as_apikey;
153 +    }
154 +
155 +    $xml = $this->post_request('batch.run', $params);
156 +
157 +    $result = $this->convert_xml_to_result($xml, 'batch.run', $params);
158 +
159 +
160 +    if (is_array($result) && isset($result['error_code'])) {
161 +      throw new FacebookRestClientException($result['error_msg'], $result['error_code']);
162 +    }
163 +
164 +    for($i = 0; $i < $item_count; $i++) {
165 +      $batch_item = $this->batch_queue[$i];
166 +      $batch_item_result_xml = $result[$i];
167 +      $batch_item_result = $this->convert_xml_to_result($batch_item_result_xml, $batch_item['m'], $batch_item['p']);
168 +
169 +      if (is_array($batch_item_result) && isset($batch_item_result['error_code'])) {
170 +        throw new FacebookRestClientException($batch_item_result['error_msg'], $batch_item_result['error_code']);
171 +      }
172 +      $batch_item['r'] = $batch_item_result;
173 +    }
174 +  }
175 +
176 +  public function begin_permissions_mode($permissions_apikey) {
177 +    $this->call_as_apikey = $permissions_apikey;
178 +  }
179 +
180 +  public function end_permissions_mode() {
181 +    $this->call_as_apikey = '';
182 +  }
183 +
184    /**
185     * Returns the session information available after current user logs in.
186 <   * @param string $auth_token the token returned by auth_createToken or
186 >   * @param string $auth_token the token returned by auth_createToken or
187     *  passed back to your callback_url.
188 +   * @param bool   $generate_session_secret  whether the session returned should include a session secret
189 +   *
190     * @return assoc array containing session_key, uid
191     */
192 <  public function auth_getSession($auth_token) {
193 <    $result = $this->call_method('facebook.auth.getSession', array('auth_token'=>$auth_token));
194 <    $this->session_key = $result['session_key'];
195 <    if (isset($result['secret']) && $result['secret']) {
192 >  public function auth_getSession($auth_token, $generate_session_secret=false) {
193 >    //Check if we are in batch mode
194 >    if($this->batch_queue === null) {
195 >      $result = $this->call_method('facebook.auth.getSession',
196 >          array('auth_token' => $auth_token, 'generate_session_secret' => $generate_session_secret));
197 >      $this->session_key = $result['session_key'];
198 >
199 >    if (!empty($result['secret']) && !$generate_session_secret) {
200        // desktop apps have a special secret
201        $this->secret = $result['secret'];
202      }
203 <    return $result;
203 >      return $result;
204 >    }
205 >  }
206 >
207 >  /**
208 >   * Generates a session specific secret. This is for integration with client-side API calls, such as the
209 >   * JS library.
210 >   * @error API_EC_PARAM_SESSION_KEY
211 >   *        API_EC_PARAM_UNKNOWN
212 >   * @return session secret for the current promoted session
213 >   */
214 >  public function auth_promoteSession() {
215 >      return $this->call_method('facebook.auth.promoteSession', array());
216 >  }
217 >
218 >  /**
219 >   * Expires the session that is currently being used.  If this call is successful, no further calls to the
220 >   * API (which require a session) can be made until a valid session is created.
221 >   *
222 >   * @return bool  true if session expiration was successful, false otherwise
223 >   */
224 >  public function auth_expireSession() {
225 >      return $this->call_method('facebook.auth.expireSession', array());
226    }
227  
228    /**
229     * Returns events according to the filters specified.
230 <   * @param int $uid Optional: User associated with events.  
230 >   * @param int $uid Optional: User associated with events.
231     *   A null parameter will default to the session user.
232     * @param array $eids Optional: Filter by these event ids.
233     *   A null parameter will get all events for the user.
234 <   * @param int $start_time Optional: Filter with this UTC as lower bound.  
234 >   * @param int $start_time Optional: Filter with this UTC as lower bound.
235     *   A null or zero parameter indicates no lower bound.
236 <   * @param int $end_time Optional: Filter with this UTC as upper bound.
236 >   * @param int $end_time Optional: Filter with this UTC as upper bound.
237     *   A null or zero parameter indicates no upper bound.
238     * @param string $rsvp_status Optional: Only show events where the given uid
239     *   has this rsvp status.  This only works if you have specified a value for
# Line 111 | Line 241 | function toggleDisplay(id, type) {
241     *   rsvp status when filtering.
242     * @return array of events
243     */
244 <  public function events_get($uid, $eids, $start_time, $end_time, $rsvp_status) {
244 >  public function &events_get($uid, $eids, $start_time, $end_time, $rsvp_status) {
245      return $this->call_method('facebook.events.get',
246          array(
247          'uid' => $uid,
248          'eids' => $eids,
249 <        'start_time' => $start_time,
249 >        'start_time' => $start_time,
250          'end_time' => $end_time,
251          'rsvp_status' => $rsvp_status));
252    }
# Line 127 | Line 257 | function toggleDisplay(id, type) {
257     * @return assoc array of four membership lists, with keys 'attending',
258     *  'unsure', 'declined', and 'not_replied'
259     */
260 <  public function events_getMembers($eid) {
260 >  public function &events_getMembers($eid) {
261      return $this->call_method('facebook.events.getMembers',
262        array('eid' => $eid));
263    }
# Line 139 | Line 269 | function toggleDisplay(id, type) {
269     * @param string $query the query to evaluate
270     * @return generalized array representing the results
271     */
272 <  public function fql_query($query) {
272 >  public function &fql_query($query) {
273      return $this->call_method('facebook.fql.query',
274        array('query' => $query));
275    }
276  
277 <  public function feed_publishStoryToUser($title, $body,
277 >  public function &feed_publishStoryToUser($title, $body,
278                                            $image_1=null, $image_1_link=null,
279                                            $image_2=null, $image_2_link=null,
280                                            $image_3=null, $image_3_link=null,
# Line 161 | Line 291 | function toggleDisplay(id, type) {
291              'image_4' => $image_4,
292              'image_4_link' => $image_4_link));
293    }
294 <                                          
295 <  public function feed_publishActionOfUser($title, $body,
294 >
295 >  public function &feed_publishActionOfUser($title, $body,
296                                             $image_1=null, $image_1_link=null,
297                                             $image_2=null, $image_2_link=null,
298                                             $image_3=null, $image_3_link=null,
# Line 180 | Line 310 | function toggleDisplay(id, type) {
310              'image_4_link' => $image_4_link));
311    }
312  
313 <  public function feed_publishTemplatizedAction($actor_id, $title_template, $title_data,
313 >  public function &feed_publishTemplatizedAction($title_template, $title_data,
314                                                  $body_template, $body_data, $body_general,
315                                                  $image_1=null, $image_1_link=null,
316                                                  $image_2=null, $image_2_link=null,
317                                                  $image_3=null, $image_3_link=null,
318                                                  $image_4=null, $image_4_link=null,
319 <                                                $target_ids=null) {
319 >                                                $target_ids='', $page_actor_id=null) {
320      return $this->call_method('facebook.feed.publishTemplatizedAction',
321 <      array('actor_id' => $actor_id,
322 <            'title_template' => $title_template,
193 <            'title_data' => $title_data,
321 >      array('title_template' => $title_template,
322 >            'title_data' => is_array($title_data) ? json_encode($title_data) : $title_data,
323              'body_template' => $body_template,
324 <            'body_data' => $body_data,
324 >            'body_data' => is_array($body_data) ? json_encode($body_data) : $body_data,
325              'body_general' => $body_general,
326              'image_1' => $image_1,
327              'image_1_link' => $image_1_link,
# Line 202 | Line 331 | function toggleDisplay(id, type) {
331              'image_3_link' => $image_3_link,
332              'image_4' => $image_4,
333              'image_4_link' => $image_4_link,
334 <            'target_ids' => $target_ids));
334 >            'target_ids' => $target_ids,
335 >            'page_actor_id' => $page_actor_id));
336    }
337  
338    /**
# Line 212 | Line 342 | function toggleDisplay(id, type) {
342     * @param array $uids2: array of ids (id_A, id_B,...) of SAME length X
343     * @return array of uid pairs with bool, true if pair are friends, e.g.
344     *   array( 0 => array('uid1' => id_1, 'uid2' => id_A, 'are_friends' => 1),
345 <   *          1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
345 >   *          1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
346     *         ...)
347     */
348 <  public function friends_areFriends($uids1, $uids2) {
348 >  public function &friends_areFriends($uids1, $uids2) {
349      return $this->call_method('facebook.friends.areFriends',
350          array('uids1'=>$uids1, 'uids2'=>$uids2));
351    }
352 <  
352 >
353    /**
354     * Returns the friends of the current session user.
355     * @return array of friends
356     */
357 <  public function friends_get() {
357 >  public function &friends_get() {
358      if (isset($this->friends_list)) {
359        return $this->friends_list;
360      }
361      return $this->call_method('facebook.friends.get', array());
362    }
363 <  
363 >
364    /**
365     * Returns the friends of the session user, who are also users
366     * of the calling application.
367     * @return array of friends
368     */
369 <  public function friends_getAppUsers() {
369 >  public function &friends_getAppUsers() {
370      return $this->call_method('facebook.friends.getAppUsers', array());
371    }
372  
373    /**
374     * Returns groups according to the filters specified.
375 <   * @param int $uid Optional: User associated with groups.  
375 >   * @param int $uid Optional: User associated with groups.
376     *  A null parameter will default to the session user.
377     * @param array $gids Optional: group ids to query.
378     *   A null parameter will get all groups for the user.
379     * @return array of groups
380     */
381 <  public function groups_get($uid, $gids) {
381 >  public function &groups_get($uid, $gids) {
382      return $this->call_method('facebook.groups.get',
383          array(
384          'uid' => $uid,
# Line 258 | Line 388 | function toggleDisplay(id, type) {
388    /**
389     * Returns the membership list of a group
390     * @param int $gid : Group id
391 <   * @return assoc array of four membership lists, with keys
391 >   * @return assoc array of four membership lists, with keys
392     *  'members', 'admins', 'officers', and 'not_replied'
393     */
394 <  public function groups_getMembers($gid) {
394 >  public function &groups_getMembers($gid) {
395      return $this->call_method('facebook.groups.getMembers',
396        array('gid' => $gid));
397    }
398  
399    /**
400 +   * Returns cookies according to the filters specified.
401 +   * @param int $uid Required: User for which the cookies are needed.
402 +   * @param string $name Optional:
403 +   *   A null parameter will get all cookies for the user.
404 +   * @return array of cookies
405 +   */
406 +  public function data_getCookies($uid, $name) {
407 +    return $this->call_method('facebook.data.getCookies',
408 +        array(
409 +        'uid' => $uid,
410 +        'name' => $name));
411 +  }
412 +
413 +  /**
414 +   * Sets cookies according to the params specified.
415 +   * @param int $uid Required: User for which the cookies are needed.
416 +   * @param string $name Required: name of the cookie
417 +   * @param string $value Optional if expires specified and is in the past
418 +   * @param int$expires Optional
419 +   * @param string $path Optional
420 +   *
421 +   * @return bool
422 +   */
423 +  public function data_setCookie($uid, $name, $value, $expires, $path) {
424 +    return $this->call_method('facebook.data.setCookie',
425 +        array(
426 +        'uid' => $uid,
427 +        'name' => $name,
428 +        'value' => $value,
429 +        'expires' => $expires,
430 +        'path' => $path));
431 +  }
432 +
433 +  /**
434 +   * Permissions API
435 +   */
436 +
437 +  /**
438 +   * Checks API-access granted by self to the specified application
439 +   * @param string $permissions_apikey: Required
440 +   *
441 +   * @return array: API methods/namespaces which are allowed access
442 +   */
443 +  public function permissions_checkGrantedApiAccess($permissions_apikey) {
444 +    return $this->call_method('facebook.permissions.checkGrantedApiAccess',
445 +        array(
446 +        'permissions_apikey' => $permissions_apikey));
447 +  }
448 +
449 +  /**
450 +   * Checks API-access granted to self by the specified application
451 +   * @param string $permissions_apikey: Required
452 +   *
453 +   * @return array: API methods/namespaces which are allowed access
454 +   */
455 +  public function permissions_checkAvailableApiAccess($permissions_apikey) {
456 +    return $this->call_method('facebook.permissions.checkAvailableApiAccess',
457 +        array(
458 +        'permissions_apikey' => $permissions_apikey));
459 +  }
460 +
461 +  /**
462 +   * Grant API-access to the specified methods/namespaces to the specified application
463 +   * @param string $permissions_apikey: Required
464 +   * @param array(string) : Optional: API methods/namespaces to be allowed
465 +   *
466 +   * @return array: API methods/namespaces which are allowed access
467 +   */
468 +  public function permissions_grantApiAccess($permissions_apikey, $method_arr) {
469 +    return $this->call_method('facebook.permissions.grantApiAccess',
470 +        array(
471 +        'permissions_apikey' => $permissions_apikey,
472 +        'method_arr' => $method_arr));
473 +  }
474 +
475 +  /**
476 +   * Revoke API-access granted to the specified application
477 +   * @param string $permissions_apikey: Required
478 +   *
479 +   * @return bool
480 +   */
481 +  public function permissions_revokeApiAccess($permissions_apikey) {
482 +    return $this->call_method('facebook.permissions.revokeApiAccess',
483 +        array(
484 +        'permissions_apikey' => $permissions_apikey));
485 +  }
486 +
487 +  /**
488     * Returns the outstanding notifications for the session user.
489 <   * @return assoc array of
490 <   *  notification count objects for 'messages', 'pokes' and 'shares',
489 >   * @return assoc array of
490 >   *  notification count objects for 'messages', 'pokes' and 'shares',
491     *  a uid list of 'friend_requests', a gid list of 'group_invites',
492     *  and an eid list of 'event_invites'
493     */
494 <  public function notifications_get() {
494 >  public function &notifications_get() {
495      return $this->call_method('facebook.notifications.get', array());
496    }
497  
498    /**
499 <   * Sends an email notification to the specified user.
500 <   * @return string url which you should send the logged in user to to finalize the message.
499 >   * Sends a notification to the specified users.
500 >   * @return (nothing)
501     */
502 <  public function notifications_send($to_ids, $notification, $email='') {
502 >  public function &notifications_send($to_ids, $notification) {
503      return $this->call_method('facebook.notifications.send',
504 <                              array('to_ids' => $to_ids, 'notification' => $notification, 'email' => $email));
504 >                              array('to_ids' => $to_ids, 'notification' => $notification));
505    }
506  
507    /**
508 <   * Sends a request to the specified user (e.g. "you have 1 event invitation")
509 <   * @param array $to_ids   user ids to receive the request (must be friends with sender, capped at 10)
510 <   * @param string $type    type of request, e.g. "event" (as in "You have an event invitation.")
511 <   * @param string $content fbml content of the request.  really stripped down fbml - just
512 <   *                        text/names/links.  also, use the special tag <fb:req-choice url="" label="" />
513 <   *                        to specify the buttons to be included.
514 <   * @param string $image   url of an image to show beside the request
515 <   * @param bool   $invite  whether to call it an "invitation" or a "request"
516 <   * @return string url which you should send the logged in user to to finalize the message.
517 <   */
518 <  public function notifications_sendRequest($to_ids, $type, $content, $image, $invite) {
519 <    return $this->call_method('facebook.notifications.sendRequest',
520 <                              array('to_ids' => $to_ids, 'type' => $type, 'content' => $content,
521 <                                    'image' => $image, 'invite' => $invite));
508 >   * Sends an email to the specified user of the application.
509 >   * @param array $recipients : id of the recipients
510 >   * @param string $subject : subject of the email
511 >   * @param string $text : (plain text) body of the email
512 >   * @param string $fbml : fbml markup if you want an html version of the email
513 >   * @return comma separated list of successful recipients
514 >   */
515 >  public function &notifications_sendEmail($recipients, $subject, $text, $fbml) {
516 >    return $this->call_method('facebook.notifications.sendEmail',
517 >                              array('recipients' => $recipients,
518 >                                    'subject' => $subject,
519 >                                    'text' => $text,
520 >                                    'fbml' => $fbml));
521 >  }
522 >
523 >  /**
524 >   * Returns the requested info fields for the requested set of pages
525 >   * @param array $page_ids an array of page ids
526 >   * @param array $fields an array of strings describing the info fields desired
527 >   * @param int $uid   Optionally, limit results to pages of which this user is a fan.
528 >   * @param string type  limits results to a particular type of page.
529 >   * @return array of pages
530 >   */
531 >  public function &pages_getInfo($page_ids, $fields, $uid, $type) {
532 >    return $this->call_method('facebook.pages.getInfo', array('page_ids' => $page_ids, 'fields' => $fields, 'uid' => $uid, 'type' => $type));
533 >  }
534 >
535 >  /**
536 >   * Returns true if logged in user is an admin for the passed page
537 >   * @param int $page_id target page id
538 >   * @return boolean
539 >   */
540 >  public function &pages_isAdmin($page_id) {
541 >    return $this->call_method('facebook.pages.isAdmin', array('page_id' => $page_id));
542 >  }
543 >
544 >  /**
545 >   * Returns whether or not the page corresponding to the current session object has the app installed
546 >   * @return boolean
547 >   */
548 >  public function &pages_isAppAdded() {
549 >    if (isset($this->added)) {
550 >      return $this->added;
551 >    }
552 >    return $this->call_method('facebook.pages.isAppAdded', array());
553 >  }
554 >
555 >  /**
556 >   * Returns true if logged in user is a fan for the passed page
557 >   * @param int $page_id target page id
558 >   * @param int $uid user to compare.  If empty, the logged in user.
559 >   * @return bool
560 >   */
561 >  public function &pages_isFan($page_id, $uid) {
562 >    return $this->call_method('facebook.pages.isFan', array('page_id' => $page_id, 'uid' => $uid));
563    }
564  
565    /**
566     * Returns photos according to the filters specified.
567     * @param int $subj_id Optional: Filter by uid of user tagged in the photos.
568 <   * @param int $aid Optional: Filter by an album, as returned by
568 >   * @param int $aid Optional: Filter by an album, as returned by
569     *  photos_getAlbums.
570 <   * @param array $pids Optional: Restrict to a list of pids
571 <   * Note that at least one of these parameters needs to be specified, or an
570 >   * @param array $pids Optional: Restrict to a list of pids
571 >   * Note that at least one of these parameters needs to be specified, or an
572     * error is returned.
573     * @return array of photo objects.
574     */
575 <  public function photos_get($subj_id, $aid, $pids) {
576 <    return $this->call_method('facebook.photos.get',
575 >  public function &photos_get($subj_id, $aid, $pids) {
576 >    return $this->call_method('facebook.photos.get',
577        array('subj_id' => $subj_id, 'aid' => $aid, 'pids' => $pids));
578    }
579  
# Line 326 | Line 585 | function toggleDisplay(id, type) {
585     * Note that at least one of the (uid, aids) parameters must be specified.
586     * @returns an array of album objects.
587     */
588 <  public function photos_getAlbums($uid, $aids) {
589 <    return $this->call_method('facebook.photos.getAlbums',
588 >  public function &photos_getAlbums($uid, $aids) {
589 >    return $this->call_method('facebook.photos.getAlbums',
590        array('uid' => $uid,
591              'aids' => $aids));
592    }
# Line 338 | Line 597 | function toggleDisplay(id, type) {
597     * @return array of photo tag objects, with include pid, subject uid,
598     *  and two floating-point numbers (xcoord, ycoord) for tag pixel location
599     */
600 <  public function photos_getTags($pids) {
601 <    return $this->call_method('facebook.photos.getTags',
600 >  public function &photos_getTags($pids) {
601 >    return $this->call_method('facebook.photos.getTags',
602        array('pids' => $pids));
603    }
604  
605 +
606    /**
607     * Returns the requested info fields for the requested set of users
608 <   * @param array $uids an array of user ids
608 >   * @param array $uids an array of user ids
609     * @param array $fields an array of strings describing the info fields desired
610     * @return array of users
611     */
612 <  public function users_getInfo($uids, $fields) {
612 >  public function &users_getInfo($uids, $fields) {
613      return $this->call_method('facebook.users.getInfo', array('uids' => $uids, 'fields' => $fields));
614    }
615  
# Line 357 | Line 617 | function toggleDisplay(id, type) {
617     * Returns the user corresponding to the current session object.
618     * @return integer uid
619     */
620 <  public function users_getLoggedInUser(){
620 >  public function &users_getLoggedInUser() {
621      return $this->call_method('facebook.users.getLoggedInUser', array());
622    }
623  
624 <  
625 <  /**
626 <   * Returns whether or not the user corresponding to the current session object has the app installed
367 <   * @return boolean
624 >  /**
625 >   * Returns whether or not the user corresponding to the current session object has the app installed
626 >   * @return boolean
627     */
628 <  public function users_isAppAdded() {
628 >  public function &users_isAppAdded($uid=null) {
629      if (isset($this->added)) {
630        return $this->added;
631      }
632 <    return $this->call_method('facebook.users.isAppAdded', array());
632 >    return $this->call_method('facebook.users.isAppAdded', array('uid' => $uid));
633    }
634  
635    /**
636     * Sets the FBML for the profile of the user attached to this session
637 <   * @param   string   $markup     The FBML that describes the profile presence of this app for the user
637 >   * @param   string   $markup           The FBML that describes the profile presence of this app for the user
638 >   * @param   int      $uid              The user
639 >   * @param   string   $profile          Profile FBML
640 >   * @param   string   $profile_action   Profile action FBML
641 >   * @param   string   $mobile_profile   Mobile profile FBML
642     * @return  array    A list of strings describing any compile errors for the submitted FBML
643     */
644 <  public function profile_setFBML($markup, $uid = null) {
645 <    return $this->call_method('facebook.profile.setFBML', array('markup' => $markup, 'uid' => $uid));
644 >  function profile_setFBML($markup, $uid = null, $profile='', $profile_action='', $mobile_profile='') {
645 >    return $this->call_method('facebook.profile.setFBML', array('markup' => $markup,
646 >                                                                'uid' => $uid,
647 >                                                                'profile' => $profile,
648 >                                                                'profile_action' => $profile_action,
649 >                                                                'mobile_profile' => $mobile_profile));
650    }
651  
652 <  public function profile_getFBML($uid) {
652 >  public function &profile_getFBML($uid) {
653      return $this->call_method('facebook.profile.getFBML', array('uid' => $uid));
654    }
655  
656 <  public function fbml_refreshImgSrc($url) {
656 >  public function &fbml_refreshImgSrc($url) {
657      return $this->call_method('facebook.fbml.refreshImgSrc', array('url' => $url));
658    }
659  
660 <  public function fbml_refreshRefUrl($url) {
660 >  public function &fbml_refreshRefUrl($url) {
661      return $this->call_method('facebook.fbml.refreshRefUrl', array('url' => $url));
662    }
663  
664 <  public function fbml_setRefHandle($handle, $fbml) {
664 >  public function &fbml_setRefHandle($handle, $fbml) {
665      return $this->call_method('facebook.fbml.setRefHandle', array('handle' => $handle, 'fbml' => $fbml));
666    }
667  
668 +  /**
669 +   * Get all the marketplace categories
670 +   *
671 +   * @return array  A list of category names
672 +   */
673 +  function marketplace_getCategories() {
674 +    return $this->call_method('facebook.marketplace.getCategories', array());
675 +  }
676 +
677 +  /**
678 +   * Get all the marketplace subcategories for a particular category
679 +   *
680 +   * @param  category  The category for which we are pulling subcategories
681 +   * @return array     A list of subcategory names
682 +   */
683 +  function marketplace_getSubCategories($category) {
684 +    return $this->call_method('facebook.marketplace.getSubCategories', array('category' => $category));
685 +  }
686 +
687 +  /**
688 +   * Get listings by either listing_id or user
689 +   *
690 +   * @param listing_ids   An array of listing_ids (optional)
691 +   * @param uids          An array of user ids (optional)
692 +   * @return array        The data for matched listings
693 +   */
694 +  function marketplace_getListings($listing_ids, $uids) {
695 +    return $this->call_method('facebook.marketplace.getListings', array('listing_ids' => $listing_ids, 'uids' => $uids));
696 +  }
697 +
698 +  /**
699 +   * Search for Marketplace listings.  All arguments are optional, though at least
700 +   * one must be filled out to retrieve results.
701 +   *
702 +   * @param category     The category in which to search (optional)
703 +   * @param subcategory  The subcategory in which to search (optional)
704 +   * @param query        A query string (optional)
705 +   * @return array       The data for matched listings
706 +   */
707 +  function marketplace_search($category, $subcategory, $query) {
708 +    return $this->call_method('facebook.marketplace.search', array('category' => $category, 'subcategory' => $subcategory, 'query' => $query));
709 +  }
710 +
711 +  /**
712 +   * Remove a listing from Marketplace
713 +   *
714 +   * @param listing_id  The id of the listing to be removed
715 +   * @param status      'SUCCESS', 'NOT_SUCCESS', or 'DEFAULT'
716 +   * @return bool       True on success
717 +   */
718 +  function marketplace_removeListing($listing_id, $status='DEFAULT', $uid=null) {
719 +    return $this->call_method('facebook.marketplace.removeListing',
720 +                              array('listing_id'=>$listing_id,
721 +                                    'status'=>$status,
722 +                                    'uid' => $uid));
723 +  }
724 +
725 +  /**
726 +   * Create/modify a Marketplace listing for the loggedinuser
727 +   *
728 +   * @param int              listing_id   The id of a listing to be modified, 0 for a new listing.
729 +   * @param show_on_profile  bool         Should we show this listing on the user's profile
730 +   * @param listing_attrs    array        An array of the listing data
731 +   * @return                 int          The listing_id (unchanged if modifying an existing listing)
732 +   */
733 +  function marketplace_createListing($listing_id, $show_on_profile, $attrs, $uid=null) {
734 +    return $this->call_method('facebook.marketplace.createListing',
735 +                              array('listing_id'=>$listing_id,
736 +                                    'show_on_profile'=>$show_on_profile,
737 +                                    'listing_attrs'=>json_encode($attrs),
738 +                                    'uid' => $uid));
739 +  }
740 +
741 +
742 +  /////////////////////////////////////////////////////////////////////////////
743 +  // Data Store API
744 +
745 +  /**
746 +   * Set a user preference.
747 +   *
748 +   * @param  pref_id    preference identifier (0-200)
749 +   * @param  value      preferece's value
750 +   * @error
751 +   *    API_EC_DATA_DATABASE_ERROR
752 +   *    API_EC_PARAM
753 +   *    API_EC_DATA_QUOTA_EXCEEDED
754 +   *    API_EC_DATA_UNKNOWN_ERROR
755 +   */
756 +  public function &data_setUserPreference($pref_id, $value) {
757 +    return $this->call_method
758 +      ('facebook.data.setUserPreference',
759 +       array('pref_id' => $pref_id,
760 +             'value' => $value));
761 +  }
762 +
763 +  /**
764 +   * Set a user's all preferences for this application.
765 +   *
766 +   * @param  values     preferece values in an associative arrays
767 +   * @param  replace    whether to replace all existing preferences or
768 +   *                    merge into them.
769 +   * @error
770 +   *    API_EC_DATA_DATABASE_ERROR
771 +   *    API_EC_PARAM
772 +   *    API_EC_DATA_QUOTA_EXCEEDED
773 +   *    API_EC_DATA_UNKNOWN_ERROR
774 +   */
775 +  public function &data_setUserPreferences($values, $replace = false) {
776 +    return $this->call_method
777 +      ('facebook.data.setUserPreferences',
778 +       array('values' => json_encode($values),
779 +             'replace' => $replace));
780 +  }
781 +
782 +  /**
783 +   * Get a user preference.
784 +   *
785 +   * @param  pref_id    preference identifier (0-200)
786 +   * @return            preference's value
787 +   * @error
788 +   *    API_EC_DATA_DATABASE_ERROR
789 +   *    API_EC_PARAM
790 +   *    API_EC_DATA_QUOTA_EXCEEDED
791 +   *    API_EC_DATA_UNKNOWN_ERROR
792 +   */
793 +  public function &data_getUserPreference($pref_id) {
794 +    return $this->call_method
795 +      ('facebook.data.getUserPreference',
796 +       array('pref_id' => $pref_id));
797 +  }
798 +
799 +  /**
800 +   * Get a user preference.
801 +   *
802 +   * @return           preference values
803 +   * @error
804 +   *    API_EC_DATA_DATABASE_ERROR
805 +   *    API_EC_DATA_QUOTA_EXCEEDED
806 +   *    API_EC_DATA_UNKNOWN_ERROR
807 +   */
808 +  public function &data_getUserPreferences() {
809 +    return $this->call_method
810 +      ('facebook.data.getUserPreferences',
811 +       array());
812 +  }
813 +
814 +  /**
815 +   * Create a new object type.
816 +   *
817 +   * @param  name       object type's name
818 +   * @error
819 +   *    API_EC_DATA_DATABASE_ERROR
820 +   *    API_EC_DATA_OBJECT_ALREADY_EXISTS
821 +   *    API_EC_PARAM
822 +   *    API_EC_PERMISSION
823 +   *    API_EC_DATA_INVALID_OPERATION
824 +   *    API_EC_DATA_QUOTA_EXCEEDED
825 +   *    API_EC_DATA_UNKNOWN_ERROR
826 +   */
827 +  public function &data_createObjectType($name) {
828 +    return $this->call_method
829 +      ('facebook.data.createObjectType',
830 +       array('name' => $name));
831 +  }
832 +
833 +  /**
834 +   * Delete an object type.
835 +   *
836 +   * @param  obj_type       object type's name
837 +   * @error
838 +   *    API_EC_DATA_DATABASE_ERROR
839 +   *    API_EC_DATA_OBJECT_NOT_FOUND
840 +   *    API_EC_PARAM
841 +   *    API_EC_PERMISSION
842 +   *    API_EC_DATA_INVALID_OPERATION
843 +   *    API_EC_DATA_QUOTA_EXCEEDED
844 +   *    API_EC_DATA_UNKNOWN_ERROR
845 +   */
846 +  public function &data_dropObjectType($obj_type) {
847 +    return $this->call_method
848 +      ('facebook.data.dropObjectType',
849 +       array('obj_type' => $obj_type));
850 +  }
851 +
852 +  /**
853 +   * Rename an object type.
854 +   *
855 +   * @param  obj_type       object type's name
856 +   * @param  new_name       new object type's name
857 +   * @error
858 +   *    API_EC_DATA_DATABASE_ERROR
859 +   *    API_EC_DATA_OBJECT_NOT_FOUND
860 +   *    API_EC_DATA_OBJECT_ALREADY_EXISTS
861 +   *    API_EC_PARAM
862 +   *    API_EC_PERMISSION
863 +   *    API_EC_DATA_INVALID_OPERATION
864 +   *    API_EC_DATA_QUOTA_EXCEEDED
865 +   *    API_EC_DATA_UNKNOWN_ERROR
866 +   */
867 +  public function &data_renameObjectType($obj_type, $new_name) {
868 +    return $this->call_method
869 +      ('facebook.data.renameObjectType',
870 +       array('obj_type' => $obj_type,
871 +             'new_name' => $new_name));
872 +  }
873 +
874 +  /**
875 +   * Add a new property to an object type.
876 +   *
877 +   * @param  obj_type       object type's name
878 +   * @param  prop_name      name of the property to add
879 +   * @param  prop_type      1: integer; 2: string; 3: text blob
880 +   * @error
881 +   *    API_EC_DATA_DATABASE_ERROR
882 +   *    API_EC_DATA_OBJECT_ALREADY_EXISTS
883 +   *    API_EC_PARAM
884 +   *    API_EC_PERMISSION
885 +   *    API_EC_DATA_INVALID_OPERATION
886 +   *    API_EC_DATA_QUOTA_EXCEEDED
887 +   *    API_EC_DATA_UNKNOWN_ERROR
888 +   */
889 +  public function &data_defineObjectProperty($obj_type, $prop_name, $prop_type) {
890 +    return $this->call_method
891 +      ('facebook.data.defineObjectProperty',
892 +       array('obj_type' => $obj_type,
893 +             'prop_name' => $prop_name,
894 +             'prop_type' => $prop_type));
895 +  }
896 +
897 +  /**
898 +   * Remove a previously defined property from an object type.
899 +   *
900 +   * @param  obj_type      object type's name
901 +   * @param  prop_name     name of the property to remove
902 +   * @error
903 +   *    API_EC_DATA_DATABASE_ERROR
904 +   *    API_EC_DATA_OBJECT_NOT_FOUND
905 +   *    API_EC_PARAM
906 +   *    API_EC_PERMISSION
907 +   *    API_EC_DATA_INVALID_OPERATION
908 +   *    API_EC_DATA_QUOTA_EXCEEDED
909 +   *    API_EC_DATA_UNKNOWN_ERROR
910 +   */
911 +  public function &data_undefineObjectProperty($obj_type, $prop_name) {
912 +    return $this->call_method
913 +      ('facebook.data.undefineObjectProperty',
914 +       array('obj_type' => $obj_type,
915 +             'prop_name' => $prop_name));
916 +  }
917 +
918 +  /**
919 +   * Rename a previously defined property of an object type.
920 +   *
921 +   * @param  obj_type      object type's name
922 +   * @param  prop_name     name of the property to rename
923 +   * @param  new_name      new name to use
924 +   * @error
925 +   *    API_EC_DATA_DATABASE_ERROR
926 +   *    API_EC_DATA_OBJECT_NOT_FOUND
927 +   *    API_EC_DATA_OBJECT_ALREADY_EXISTS
928 +   *    API_EC_PARAM
929 +   *    API_EC_PERMISSION
930 +   *    API_EC_DATA_INVALID_OPERATION
931 +   *    API_EC_DATA_QUOTA_EXCEEDED
932 +   *    API_EC_DATA_UNKNOWN_ERROR
933 +   */
934 +  public function &data_renameObjectProperty($obj_type, $prop_name,
935 +                                            $new_name) {
936 +    return $this->call_method
937 +      ('facebook.data.renameObjectProperty',
938 +       array('obj_type' => $obj_type,
939 +             'prop_name' => $prop_name,
940 +             'new_name' => $new_name));
941 +  }
942 +
943 +  /**
944 +   * Retrieve a list of all object types that have defined for the application.
945 +   *
946 +   * @return               a list of object type names
947 +   * @error
948 +   *    API_EC_DATA_DATABASE_ERROR
949 +   *    API_EC_PERMISSION
950 +   *    API_EC_DATA_QUOTA_EXCEEDED
951 +   *    API_EC_DATA_UNKNOWN_ERROR
952 +   */
953 +  public function &data_getObjectTypes() {
954 +    return $this->call_method
955 +      ('facebook.data.getObjectTypes',
956 +       array());
957 +  }
958 +
959 +  /**
960 +   * Get definitions of all properties of an object type.
961 +   *
962 +   * @param obj_type       object type's name
963 +   * @return               pairs of property name and property types
964 +   * @error
965 +   *    API_EC_DATA_DATABASE_ERROR
966 +   *    API_EC_PARAM
967 +   *    API_EC_PERMISSION
968 +   *    API_EC_DATA_OBJECT_NOT_FOUND
969 +   *    API_EC_DATA_QUOTA_EXCEEDED
970 +   *    API_EC_DATA_UNKNOWN_ERROR
971 +   */
972 +  public function &data_getObjectType($obj_type) {
973 +    return $this->call_method
974 +      ('facebook.data.getObjectType',
975 +       array('obj_type' => $obj_type));
976 +  }
977 +
978 +  /**
979 +   * Create a new object.
980 +   *
981 +   * @param  obj_type      object type's name
982 +   * @param  properties    (optional) properties to set initially
983 +   * @return               newly created object's id
984 +   * @error
985 +   *    API_EC_DATA_DATABASE_ERROR
986 +   *    API_EC_PARAM
987 +   *    API_EC_PERMISSION
988 +   *    API_EC_DATA_INVALID_OPERATION
989 +   *    API_EC_DATA_QUOTA_EXCEEDED
990 +   *    API_EC_DATA_UNKNOWN_ERROR
991 +   */
992 +  public function &data_createObject($obj_type, $properties = null) {
993 +    return $this->call_method
994 +      ('facebook.data.createObject',
995 +       array('obj_type' => $obj_type,
996 +             'properties' => json_encode($properties)));
997 +  }
998 +
999 +  /**
1000 +   * Update an existing object.
1001 +   *
1002 +   * @param  obj_id        object's id
1003 +   * @param  properties    new properties
1004 +   * @param  replace       true for replacing existing properties; false for merging
1005 +   * @error
1006 +   *    API_EC_DATA_DATABASE_ERROR
1007 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1008 +   *    API_EC_PARAM
1009 +   *    API_EC_PERMISSION
1010 +   *    API_EC_DATA_INVALID_OPERATION
1011 +   *    API_EC_DATA_QUOTA_EXCEEDED
1012 +   *    API_EC_DATA_UNKNOWN_ERROR
1013 +   */
1014 +  public function &data_updateObject($obj_id, $properties, $replace = false) {
1015 +    return $this->call_method
1016 +      ('facebook.data.updateObject',
1017 +       array('obj_id' => $obj_id,
1018 +             'properties' => json_encode($properties),
1019 +             'replace' => $replace));
1020 +  }
1021 +
1022 +  /**
1023 +   * Delete an existing object.
1024 +   *
1025 +   * @param  obj_id        object's id
1026 +   * @error
1027 +   *    API_EC_DATA_DATABASE_ERROR
1028 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1029 +   *    API_EC_PARAM
1030 +   *    API_EC_PERMISSION
1031 +   *    API_EC_DATA_INVALID_OPERATION
1032 +   *    API_EC_DATA_QUOTA_EXCEEDED
1033 +   *    API_EC_DATA_UNKNOWN_ERROR
1034 +   */
1035 +  public function &data_deleteObject($obj_id) {
1036 +    return $this->call_method
1037 +      ('facebook.data.deleteObject',
1038 +       array('obj_id' => $obj_id));
1039 +  }
1040 +
1041 +  /**
1042 +   * Delete a list of objects.
1043 +   *
1044 +   * @param  obj_ids       objects to delete
1045 +   * @error
1046 +   *    API_EC_DATA_DATABASE_ERROR
1047 +   *    API_EC_PARAM
1048 +   *    API_EC_PERMISSION
1049 +   *    API_EC_DATA_INVALID_OPERATION
1050 +   *    API_EC_DATA_QUOTA_EXCEEDED
1051 +   *    API_EC_DATA_UNKNOWN_ERROR
1052 +   */
1053 +  public function &data_deleteObjects($obj_ids) {
1054 +    return $this->call_method
1055 +      ('facebook.data.deleteObjects',
1056 +       array('obj_ids' => json_encode($obj_ids)));
1057 +  }
1058 +
1059 +  /**
1060 +   * Get a single property value of an object.
1061 +   *
1062 +   * @param  obj_id        object's id
1063 +   * @param  prop_name     individual property's name
1064 +   * @return               individual property's value
1065 +   * @error
1066 +   *    API_EC_DATA_DATABASE_ERROR
1067 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1068 +   *    API_EC_PARAM
1069 +   *    API_EC_PERMISSION
1070 +   *    API_EC_DATA_INVALID_OPERATION
1071 +   *    API_EC_DATA_QUOTA_EXCEEDED
1072 +   *    API_EC_DATA_UNKNOWN_ERROR
1073 +   */
1074 +  public function &data_getObjectProperty($obj_id, $prop_name) {
1075 +    return $this->call_method
1076 +      ('facebook.data.getObjectProperty',
1077 +       array('obj_id' => $obj_id,
1078 +             'prop_name' => $prop_name));
1079 +  }
1080 +
1081 +  /**
1082 +   * Get properties of an object.
1083 +   *
1084 +   * @param  obj_id      object's id
1085 +   * @param  prop_names  (optional) properties to return; null for all.
1086 +   * @return             specified properties of an object
1087 +   * @error
1088 +   *    API_EC_DATA_DATABASE_ERROR
1089 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1090 +   *    API_EC_PARAM
1091 +   *    API_EC_PERMISSION
1092 +   *    API_EC_DATA_INVALID_OPERATION
1093 +   *    API_EC_DATA_QUOTA_EXCEEDED
1094 +   *    API_EC_DATA_UNKNOWN_ERROR
1095 +   */
1096 +  public function &data_getObject($obj_id, $prop_names = null) {
1097 +    return $this->call_method
1098 +      ('facebook.data.getObject',
1099 +       array('obj_id' => $obj_id,
1100 +             'prop_names' => json_encode($prop_names)));
1101 +  }
1102 +
1103 +  /**
1104 +   * Get properties of a list of objects.
1105 +   *
1106 +   * @param  obj_ids     object ids
1107 +   * @param  prop_names  (optional) properties to return; null for all.
1108 +   * @return             specified properties of an object
1109 +   * @error
1110 +   *    API_EC_DATA_DATABASE_ERROR
1111 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1112 +   *    API_EC_PARAM
1113 +   *    API_EC_PERMISSION
1114 +   *    API_EC_DATA_INVALID_OPERATION
1115 +   *    API_EC_DATA_QUOTA_EXCEEDED
1116 +   *    API_EC_DATA_UNKNOWN_ERROR
1117 +   */
1118 +  public function &data_getObjects($obj_ids, $prop_names = null) {
1119 +    return $this->call_method
1120 +      ('facebook.data.getObjects',
1121 +       array('obj_ids' => json_encode($obj_ids),
1122 +             'prop_names' => json_encode($prop_names)));
1123 +  }
1124 +
1125 +  /**
1126 +   * Set a single property value of an object.
1127 +   *
1128 +   * @param  obj_id        object's id
1129 +   * @param  prop_name     individual property's name
1130 +   * @param  prop_value    new value to set
1131 +   * @error
1132 +   *    API_EC_DATA_DATABASE_ERROR
1133 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1134 +   *    API_EC_PARAM
1135 +   *    API_EC_PERMISSION
1136 +   *    API_EC_DATA_INVALID_OPERATION
1137 +   *    API_EC_DATA_QUOTA_EXCEEDED
1138 +   *    API_EC_DATA_UNKNOWN_ERROR
1139 +   */
1140 +  public function &data_setObjectProperty($obj_id, $prop_name,
1141 +                                         $prop_value) {
1142 +    return $this->call_method
1143 +      ('facebook.data.setObjectProperty',
1144 +       array('obj_id' => $obj_id,
1145 +             'prop_name' => $prop_name,
1146 +             'prop_value' => $prop_value));
1147 +  }
1148 +
1149 +  /**
1150 +   * Read hash value by key.
1151 +   *
1152 +   * @param  obj_type      object type's name
1153 +   * @param  key           hash key
1154 +   * @param  prop_name     (optional) individual property's name
1155 +   * @return               hash value
1156 +   * @error
1157 +   *    API_EC_DATA_DATABASE_ERROR
1158 +   *    API_EC_PARAM
1159 +   *    API_EC_PERMISSION
1160 +   *    API_EC_DATA_INVALID_OPERATION
1161 +   *    API_EC_DATA_QUOTA_EXCEEDED
1162 +   *    API_EC_DATA_UNKNOWN_ERROR
1163 +   */
1164 +  public function &data_getHashValue($obj_type, $key, $prop_name = null) {
1165 +    return $this->call_method
1166 +      ('facebook.data.getHashValue',
1167 +       array('obj_type' => $obj_type,
1168 +             'key' => $key,
1169 +             'prop_name' => $prop_name));
1170 +  }
1171 +
1172 +  /**
1173 +   * Write hash value by key.
1174 +   *
1175 +   * @param  obj_type      object type's name
1176 +   * @param  key           hash key
1177 +   * @param  value         hash value
1178 +   * @param  prop_name     (optional) individual property's name
1179 +   * @error
1180 +   *    API_EC_DATA_DATABASE_ERROR
1181 +   *    API_EC_PARAM
1182 +   *    API_EC_PERMISSION
1183 +   *    API_EC_DATA_INVALID_OPERATION
1184 +   *    API_EC_DATA_QUOTA_EXCEEDED
1185 +   *    API_EC_DATA_UNKNOWN_ERROR
1186 +   */
1187 +  public function &data_setHashValue($obj_type, $key, $value, $prop_name = null) {
1188 +    return $this->call_method
1189 +      ('facebook.data.setHashValue',
1190 +       array('obj_type' => $obj_type,
1191 +             'key' => $key,
1192 +             'value' => $value,
1193 +             'prop_name' => $prop_name));
1194 +  }
1195 +
1196 +  /**
1197 +   * Increase a hash value by specified increment atomically.
1198 +   *
1199 +   * @param  obj_type      object type's name
1200 +   * @param  key           hash key
1201 +   * @param  prop_name     individual property's name
1202 +   * @param  increment     (optional) default is 1
1203 +   * @return               incremented hash value
1204 +   * @error
1205 +   *    API_EC_DATA_DATABASE_ERROR
1206 +   *    API_EC_PARAM
1207 +   *    API_EC_PERMISSION
1208 +   *    API_EC_DATA_INVALID_OPERATION
1209 +   *    API_EC_DATA_QUOTA_EXCEEDED
1210 +   *    API_EC_DATA_UNKNOWN_ERROR
1211 +   */
1212 +  public function &data_incHashValue($obj_type, $key, $prop_name, $increment = 1) {
1213 +    return $this->call_method
1214 +      ('facebook.data.incHashValue',
1215 +       array('obj_type' => $obj_type,
1216 +             'key' => $key,
1217 +             'prop_name' => $prop_name,
1218 +             'increment' => $increment));
1219 +  }
1220 +
1221 +  /**
1222 +   * Remove a hash key and its values.
1223 +   *
1224 +   * @param  obj_type    object type's name
1225 +   * @param  key         hash key
1226 +   * @error
1227 +   *    API_EC_DATA_DATABASE_ERROR
1228 +   *    API_EC_PARAM
1229 +   *    API_EC_PERMISSION
1230 +   *    API_EC_DATA_INVALID_OPERATION
1231 +   *    API_EC_DATA_QUOTA_EXCEEDED
1232 +   *    API_EC_DATA_UNKNOWN_ERROR
1233 +   */
1234 +  public function &data_removeHashKey($obj_type, $key) {
1235 +    return $this->call_method
1236 +      ('facebook.data.removeHashKey',
1237 +       array('obj_type' => $obj_type,
1238 +             'key' => $key));
1239 +  }
1240 +
1241 +  /**
1242 +   * Remove hash keys and their values.
1243 +   *
1244 +   * @param  obj_type    object type's name
1245 +   * @param  keys        hash keys
1246 +   * @error
1247 +   *    API_EC_DATA_DATABASE_ERROR
1248 +   *    API_EC_PARAM
1249 +   *    API_EC_PERMISSION
1250 +   *    API_EC_DATA_INVALID_OPERATION
1251 +   *    API_EC_DATA_QUOTA_EXCEEDED
1252 +   *    API_EC_DATA_UNKNOWN_ERROR
1253 +   */
1254 +  public function &data_removeHashKeys($obj_type, $keys) {
1255 +    return $this->call_method
1256 +      ('facebook.data.removeHashKeys',
1257 +       array('obj_type' => $obj_type,
1258 +             'keys' => json_encode($keys)));
1259 +  }
1260 +
1261 +
1262 +  /**
1263 +   * Define an object association.
1264 +   *
1265 +   * @param  name        name of this association
1266 +   * @param  assoc_type  1: one-way 2: two-way symmetric 3: two-way asymmetric
1267 +   * @param  assoc_info1 needed info about first object type
1268 +   * @param  assoc_info2 needed info about second object type
1269 +   * @param  inverse     (optional) name of reverse association
1270 +   * @error
1271 +   *    API_EC_DATA_DATABASE_ERROR
1272 +   *    API_EC_DATA_OBJECT_ALREADY_EXISTS
1273 +   *    API_EC_PARAM
1274 +   *    API_EC_PERMISSION
1275 +   *    API_EC_DATA_INVALID_OPERATION
1276 +   *    API_EC_DATA_QUOTA_EXCEEDED
1277 +   *    API_EC_DATA_UNKNOWN_ERROR
1278 +   */
1279 +  public function &data_defineAssociation($name, $assoc_type, $assoc_info1,
1280 +                                         $assoc_info2, $inverse = null) {
1281 +    return $this->call_method
1282 +      ('facebook.data.defineAssociation',
1283 +       array('name' => $name,
1284 +             'assoc_type' => $assoc_type,
1285 +             'assoc_info1' => json_encode($assoc_info1),
1286 +             'assoc_info2' => json_encode($assoc_info2),
1287 +             'inverse' => $inverse));
1288 +  }
1289 +
1290 +  /**
1291 +   * Undefine an object association.
1292 +   *
1293 +   * @param  name        name of this association
1294 +   * @error
1295 +   *    API_EC_DATA_DATABASE_ERROR
1296 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1297 +   *    API_EC_PARAM
1298 +   *    API_EC_PERMISSION
1299 +   *    API_EC_DATA_INVALID_OPERATION
1300 +   *    API_EC_DATA_QUOTA_EXCEEDED
1301 +   *    API_EC_DATA_UNKNOWN_ERROR
1302 +   */
1303 +  public function &data_undefineAssociation($name) {
1304 +    return $this->call_method
1305 +      ('facebook.data.undefineAssociation',
1306 +       array('name' => $name));
1307 +  }
1308 +
1309 +  /**
1310 +   * Rename an object association or aliases.
1311 +   *
1312 +   * @param  name        name of this association
1313 +   * @param  new_name    (optional) new name of this association
1314 +   * @param  new_alias1  (optional) new alias for object type 1
1315 +   * @param  new_alias2  (optional) new alias for object type 2
1316 +   * @error
1317 +   *    API_EC_DATA_DATABASE_ERROR
1318 +   *    API_EC_DATA_OBJECT_ALREADY_EXISTS
1319 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1320 +   *    API_EC_PARAM
1321 +   *    API_EC_PERMISSION
1322 +   *    API_EC_DATA_INVALID_OPERATION
1323 +   *    API_EC_DATA_QUOTA_EXCEEDED
1324 +   *    API_EC_DATA_UNKNOWN_ERROR
1325 +   */
1326 +  public function &data_renameAssociation($name, $new_name, $new_alias1 = null,
1327 +                                         $new_alias2 = null) {
1328 +    return $this->call_method
1329 +      ('facebook.data.renameAssociation',
1330 +       array('name' => $name,
1331 +             'new_name' => $new_name,
1332 +             'new_alias1' => $new_alias1,
1333 +             'new_alias2' => $new_alias2));
1334 +  }
1335 +
1336 +  /**
1337 +   * Get definition of an object association.
1338 +   *
1339 +   * @param  name        name of this association
1340 +   * @return             specified association
1341 +   * @error
1342 +   *    API_EC_DATA_DATABASE_ERROR
1343 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1344 +   *    API_EC_PARAM
1345 +   *    API_EC_PERMISSION
1346 +   *    API_EC_DATA_QUOTA_EXCEEDED
1347 +   *    API_EC_DATA_UNKNOWN_ERROR
1348 +   */
1349 +  public function &data_getAssociationDefinition($name) {
1350 +    return $this->call_method
1351 +      ('facebook.data.getAssociationDefinition',
1352 +       array('name' => $name));
1353 +  }
1354 +
1355 +  /**
1356 +   * Get definition of all associations.
1357 +   *
1358 +   * @return             all defined associations
1359 +   * @error
1360 +   *    API_EC_DATA_DATABASE_ERROR
1361 +   *    API_EC_PERMISSION
1362 +   *    API_EC_DATA_QUOTA_EXCEEDED
1363 +   *    API_EC_DATA_UNKNOWN_ERROR
1364 +   */
1365 +  public function &data_getAssociationDefinitions() {
1366 +    return $this->call_method
1367 +      ('facebook.data.getAssociationDefinitions',
1368 +       array());
1369 +  }
1370 +
1371 +  /**
1372 +   * Create or modify an association between two objects.
1373 +   *
1374 +   * @param  name        name of association
1375 +   * @param  obj_id1     id of first object
1376 +   * @param  obj_id2     id of second object
1377 +   * @param  data        (optional) extra string data to store
1378 +   * @param  assoc_time  (optional) extra time data; default to creation time
1379 +   * @error
1380 +   *    API_EC_DATA_DATABASE_ERROR
1381 +   *    API_EC_PARAM
1382 +   *    API_EC_PERMISSION
1383 +   *    API_EC_DATA_INVALID_OPERATION
1384 +   *    API_EC_DATA_QUOTA_EXCEEDED
1385 +   *    API_EC_DATA_UNKNOWN_ERROR
1386 +   */
1387 +  public function &data_setAssociation($name, $obj_id1, $obj_id2, $data = null,
1388 +                                      $assoc_time = null) {
1389 +    return $this->call_method
1390 +      ('facebook.data.setAssociation',
1391 +       array('name' => $name,
1392 +             'obj_id1' => $obj_id1,
1393 +             'obj_id2' => $obj_id2,
1394 +             'data' => $data,
1395 +             'assoc_time' => $assoc_time));
1396 +  }
1397 +
1398 +  /**
1399 +   * Create or modify associations between objects.
1400 +   *
1401 +   * @param  assocs      associations to set
1402 +   * @param  name        (optional) name of association
1403 +   * @error
1404 +   *    API_EC_DATA_DATABASE_ERROR
1405 +   *    API_EC_PARAM
1406 +   *    API_EC_PERMISSION
1407 +   *    API_EC_DATA_INVALID_OPERATION
1408 +   *    API_EC_DATA_QUOTA_EXCEEDED
1409 +   *    API_EC_DATA_UNKNOWN_ERROR
1410 +   */
1411 +  public function &data_setAssociations($assocs, $name = null) {
1412 +    return $this->call_method
1413 +      ('facebook.data.setAssociations',
1414 +       array('assocs' => json_encode($assocs),
1415 +             'name' => $name));
1416 +  }
1417 +
1418 +  /**
1419 +   * Remove an association between two objects.
1420 +   *
1421 +   * @param  name        name of association
1422 +   * @param  obj_id1     id of first object
1423 +   * @param  obj_id2     id of second object
1424 +   * @error
1425 +   *    API_EC_DATA_DATABASE_ERROR
1426 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1427 +   *    API_EC_PARAM
1428 +   *    API_EC_PERMISSION
1429 +   *    API_EC_DATA_QUOTA_EXCEEDED
1430 +   *    API_EC_DATA_UNKNOWN_ERROR
1431 +   */
1432 +  public function &data_removeAssociation($name, $obj_id1, $obj_id2) {
1433 +    return $this->call_method
1434 +      ('facebook.data.removeAssociation',
1435 +       array('name' => $name,
1436 +             'obj_id1' => $obj_id1,
1437 +             'obj_id2' => $obj_id2));
1438 +  }
1439 +
1440 +  /**
1441 +   * Remove associations between objects by specifying pairs of object ids.
1442 +   *
1443 +   * @param  assocs      associations to remove
1444 +   * @param  name        (optional) name of association
1445 +   * @error
1446 +   *    API_EC_DATA_DATABASE_ERROR
1447 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1448 +   *    API_EC_PARAM
1449 +   *    API_EC_PERMISSION
1450 +   *    API_EC_DATA_QUOTA_EXCEEDED
1451 +   *    API_EC_DATA_UNKNOWN_ERROR
1452 +   */
1453 +  public function &data_removeAssociations($assocs, $name = null) {
1454 +    return $this->call_method
1455 +      ('facebook.data.removeAssociations',
1456 +       array('assocs' => json_encode($assocs),
1457 +             'name' => $name));
1458 +  }
1459 +
1460 +  /**
1461 +   * Remove associations between objects by specifying one object id.
1462 +   *
1463 +   * @param  name        name of association
1464 +   * @param  obj_id      who's association to remove
1465 +   * @error
1466 +   *    API_EC_DATA_DATABASE_ERROR
1467 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1468 +   *    API_EC_PARAM
1469 +   *    API_EC_PERMISSION
1470 +   *    API_EC_DATA_INVALID_OPERATION
1471 +   *    API_EC_DATA_QUOTA_EXCEEDED
1472 +   *    API_EC_DATA_UNKNOWN_ERROR
1473 +   */
1474 +  public function &data_removeAssociatedObjects($name, $obj_id) {
1475 +    return $this->call_method
1476 +      ('facebook.data.removeAssociatedObjects',
1477 +       array('name' => $name,
1478 +             'obj_id' => $obj_id));
1479 +  }
1480 +
1481 +  /**
1482 +   * Retrieve a list of associated objects.
1483 +   *
1484 +   * @param  name        name of association
1485 +   * @param  obj_id      who's association to retrieve
1486 +   * @param  no_data     only return object ids
1487 +   * @return             associated objects
1488 +   * @error
1489 +   *    API_EC_DATA_DATABASE_ERROR
1490 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1491 +   *    API_EC_PARAM
1492 +   *    API_EC_PERMISSION
1493 +   *    API_EC_DATA_INVALID_OPERATION
1494 +   *    API_EC_DATA_QUOTA_EXCEEDED
1495 +   *    API_EC_DATA_UNKNOWN_ERROR
1496 +   */
1497 +  public function &data_getAssociatedObjects($name, $obj_id, $no_data = true) {
1498 +    return $this->call_method
1499 +      ('facebook.data.getAssociatedObjects',
1500 +       array('name' => $name,
1501 +             'obj_id' => $obj_id,
1502 +             'no_data' => $no_data));
1503 +  }
1504 +
1505 +  /**
1506 +   * Count associated objects.
1507 +   *
1508 +   * @param  name        name of association
1509 +   * @param  obj_id      who's association to retrieve
1510 +   * @return             associated object's count
1511 +   * @error
1512 +   *    API_EC_DATA_DATABASE_ERROR
1513 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1514 +   *    API_EC_PARAM
1515 +   *    API_EC_PERMISSION
1516 +   *    API_EC_DATA_INVALID_OPERATION
1517 +   *    API_EC_DATA_QUOTA_EXCEEDED
1518 +   *    API_EC_DATA_UNKNOWN_ERROR
1519 +   */
1520 +  public function &data_getAssociatedObjectCount($name, $obj_id) {
1521 +    return $this->call_method
1522 +      ('facebook.data.getAssociatedObjectCount',
1523 +       array('name' => $name,
1524 +             'obj_id' => $obj_id));
1525 +  }
1526 +
1527 +  /**
1528 +   * Get a list of associated object counts.
1529 +   *
1530 +   * @param  name        name of association
1531 +   * @param  obj_ids     whose association to retrieve
1532 +   * @return             associated object counts
1533 +   * @error
1534 +   *    API_EC_DATA_DATABASE_ERROR
1535 +   *    API_EC_DATA_OBJECT_NOT_FOUND
1536 +   *    API_EC_PARAM
1537 +   *    API_EC_PERMISSION
1538 +   *    API_EC_DATA_INVALID_OPERATION
1539 +   *    API_EC_DATA_QUOTA_EXCEEDED
1540 +   *    API_EC_DATA_UNKNOWN_ERROR
1541 +   */
1542 +  public function &data_getAssociatedObjectCounts($name, $obj_ids) {
1543 +    return $this->call_method
1544 +      ('facebook.data.getAssociatedObjectCounts',
1545 +       array('name' => $name,
1546 +             'obj_ids' => json_encode($obj_ids)));
1547 +  }
1548 +
1549 +  /**
1550 +   * Find all associations between two objects.
1551 +   *
1552 +   * @param  obj_id1     id of first object
1553 +   * @param  obj_id2     id of second object
1554 +   * @param  no_data     only return association names without data
1555 +   * @return             all associations between objects
1556 +   * @error
1557 +   *    API_EC_DATA_DATABASE_ERROR
1558 +   *    API_EC_PARAM
1559 +   *    API_EC_PERMISSION
1560 +   *    API_EC_DATA_QUOTA_EXCEEDED
1561 +   *    API_EC_DATA_UNKNOWN_ERROR
1562 +   */
1563 +  public function &data_getAssociations($obj_id1, $obj_id2, $no_data = true) {
1564 +    return $this->call_method
1565 +      ('facebook.data.getAssociations',
1566 +       array('obj_id1' => $obj_id1,
1567 +             'obj_id2' => $obj_id2,
1568 +             'no_data' => $no_data));
1569 +  }
1570 +
1571 +  /**
1572 +   * Get the properties that you have set for an app.
1573 +   *
1574 +   * @param  properties  list of properties names to fetch
1575 +   * @return             a map from property name to value
1576 +   */
1577 +  public function admin_getAppProperties($properties) {
1578 +    return json_decode($this->call_method
1579 +                       ('facebook.admin.getAppProperties',
1580 +                        array('properties' => json_encode($properties))), true);
1581 +  }
1582 +
1583 +  /**
1584 +   * Set properties for an app.
1585 +   *
1586 +   * @param  properties  a map from property names to  values
1587 +   * @return             true on success
1588 +   */
1589 +  public function admin_setAppProperties($properties) {
1590 +    return $this->call_method
1591 +      ('facebook.admin.setAppProperties',
1592 +       array('properties' => json_encode($properties)));
1593 +  }
1594 +
1595 +  /**
1596 +   * Returns the allocation limit value for a specified integration point name
1597 +   * Integration point names are defined in lib/api/karma/constants.php in the limit_map
1598 +   * @param string $integration_point_name
1599 +   * @return integration point allocation value
1600 +   */
1601 +  public function &admin_getAllocation($integration_point_name) {
1602 +    return $this->call_method('facebook.admin.getAllocation', array('integration_point_name' => $integration_point_name));
1603 +  }
1604 +
1605 +  /**
1606 +   * Returns values for the specified daily metrics for the current
1607 +   * application, in the given date range (inclusive).
1608 +   *
1609 +   * @param start_date  unix time for the start of the date range
1610 +   * @param end_date    unix time for the end of the date range
1611 +   * @param metrics     list of daily metrics to look up
1612 +   * @return            a list of the values for those metrics
1613 +   */
1614 +  public function &admin_getDailyMetrics($start_date, $end_date, $metrics) {
1615 +    return $this->call_method('admin.getDailyMetrics',
1616 +                              array('start_date' => $start_date,
1617 +                                    'end_date' => $end_date,
1618 +                                    'metrics' => json_encode($metrics)));
1619 +  }
1620 +
1621 +
1622 +
1623 +
1624    /* UTILITY FUNCTIONS */
1625  
1626 <  public function call_method($method, $params) {
1627 <    if ($this->json) {
1628 <      $json = $this->post_request($method, $params);
1629 <      # XXX: silly facebook with its invalid JSON
1630 <      $valid = preg_match('/^[\[{].*[\]}]$/', $json);
1631 <      $array = json_decode($valid ? $json : "[$json]", true);
1632 <      $result = $valid ? $array : $array[0];
1633 <    } else {
1634 <      $xml = $this->post_request($method, $params);
1635 <      $sxml = simplexml_load_string($xml);
1636 <      $result = self::convert_simplexml_to_array($sxml);
1637 <      if ($GLOBALS['facebook_config']['debug']) {
1638 <        // output the raw xml and its corresponding php object, for debugging:
1639 <        print '<div style="margin: 10px 30px; padding: 5px; border: 2px solid black; background: gray; color: white; font-size: 12px; font-weight: bold;">';
1640 <        $this->cur_id++;
1641 <        print $this->cur_id . ': Called ' . $method . ', show ' .
1642 <              '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'params\');">Params</a> | '.
1643 <              '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'xml\');">XML</a> | '.
1644 <              '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'sxml\');">SXML</a> | '.
1645 <              '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'php\');">PHP</a>';
423 <        print '<pre id="params'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($params, true).'</pre>';
424 <        print '<pre id="xml'.$this->cur_id.'" style="display: none; overflow: auto;">'.htmlspecialchars($xml).'</pre>';
425 <        print '<pre id="php'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($result, true).'</pre>';
426 <        print '<pre id="sxml'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($sxml, true).'</pre>';
427 <        print '</div>';
1626 >  public function & call_method($method, $params) {
1627 >
1628 >    //Check if we are in batch mode
1629 >    if($this->batch_queue === null) {
1630 >      if ($this->call_as_apikey) {
1631 >        $params['call_as_apikey'] = $this->call_as_apikey;
1632 >      }
1633 >      if ($this->json)
1634 >      {
1635 >        $json = $this->post_request($method, $params);
1636 >        # XXX: silly facebook with its invalid JSON
1637 >        $valid = preg_match('/^[\[{].*[\]}]$/', $json);
1638 >        $array = json_decode($valid ? $json : "[$json]", true);
1639 >        $result = $valid ? $array : $array[0];
1640 >      } else {
1641 >        $xml = $this->post_request($method, $params);
1642 >        $result = $this->convert_xml_to_result($xml, $method, $params);
1643 >      }
1644 >      if (is_array($result) && isset($result['error_code'])) {
1645 >        throw new FacebookRestClientException($result['error_msg'], $result['error_code']);
1646        }
1647      }
1648 <    if (is_array($result) && isset($result['error_code'])) {
1649 <      throw new FacebookRestClientException($result['error_msg'], $result['error_code']);
1648 >    else {
1649 >      $result = null;
1650 >      $batch_item = array('m' => $method, 'p' => $params, 'r' => & $result);
1651 >      $this->batch_queue[] = $batch_item;
1652      }
1653 +
1654      return $result;
1655    }
1656  
1657 <  public function post_request($method, $params) {
1657 >  private function convert_xml_to_result($xml, $method, $params) {
1658 >    $sxml = simplexml_load_string($xml);
1659 >    $result = self::convert_simplexml_to_array($sxml);
1660 >
1661 >
1662 >    if (!empty($GLOBALS['facebook_config']['debug'])) {
1663 >      // output the raw xml and its corresponding php object, for debugging:
1664 >      print '<div style="margin: 10px 30px; padding: 5px; border: 2px solid black; background: gray; color: white; font-size: 12px; font-weight: bold;">';
1665 >      $this->cur_id++;
1666 >      print $this->cur_id . ': Called ' . $method . ', show ' .
1667 >            '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'params\');">Params</a> | '.
1668 >            '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'xml\');">XML</a> | '.
1669 >            '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'sxml\');">SXML</a> | '.
1670 >            '<a href=# onclick="return toggleDisplay(' . $this->cur_id . ', \'php\');">PHP</a>';
1671 >      print '<pre id="params'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($params, true).'</pre>';
1672 >      print '<pre id="xml'.$this->cur_id.'" style="display: none; overflow: auto;">'.htmlspecialchars($xml).'</pre>';
1673 >      print '<pre id="php'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($result, true).'</pre>';
1674 >      print '<pre id="sxml'.$this->cur_id.'" style="display: none; overflow: auto;">'.print_r($sxml, true).'</pre>';
1675 >      print '</div>';
1676 >    }
1677 >    return $result;
1678 >  }
1679 >
1680 >
1681 >
1682 >  private function create_post_string($method, $params) {
1683      $params['method'] = $method;
1684      $params['session_key'] = $this->session_key;
1685      $params['api_key'] = $this->api_key;
# Line 453 | Line 1699 | function toggleDisplay(id, type) {
1699        $post_params[] = $key.'='.urlencode($val);
1700      }
1701      $post_params[] = 'sig='.Facebook::generate_sig($params, $this->secret);
1702 <    $post_string = implode('&', $post_params);
1702 >    return implode('&', $post_params);
1703 >  }
1704  
1705 <    if ($this->json) {
1706 <      $result = file_get_contents($this->server_addr, false, stream_context_create(
1707 <        array('http' =>
1708 <              array('method' => 'POST',
1709 <                    'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
1710 <                                'User-Agent: Facebook API PHP5 Client 1.1 (non-curl) '.phpversion()."\r\n".
464 <                                'Content-length: ' . strlen($post_string),
465 <                    'content' => $post_string))));
466 <    } elseif (function_exists('curl_init')) {
1705 >  public function post_request($method, $params) {
1706 >
1707 >    $post_string = $this->create_post_string($method, $params);
1708 >
1709 >
1710 >    if (function_exists('curl_init')) {
1711        // Use CURL if installed...
1712        $ch = curl_init();
1713        curl_setopt($ch, CURLOPT_URL, $this->server_addr);
# Line 509 | Line 1753 | function toggleDisplay(id, type) {
1753        return $arr;
1754      } else {
1755        return (string)$sxml;
1756 <    }
1756 >    }
1757    }
1758 +
1759   }
1760  
1761 +
1762   class FacebookRestClientException extends Exception {
1763   }
1764  
# Line 560 | Line 1806 | class FacebookAPIErrorCodes {
1806    const FQL_EC_UNKNOWN_FIELD = 602;
1807    const FQL_EC_UNKNOWN_TABLE = 603;
1808    const FQL_EC_NOT_INDEXABLE = 604;
1809 <
1809 >
1810 >  /**
1811 >   * DATA STORE API ERRORS
1812 >   */
1813 >  const API_EC_DATA_UNKNOWN_ERROR = 800;
1814 >  const API_EC_DATA_INVALID_OPERATION = 801;
1815 >  const API_EC_DATA_QUOTA_EXCEEDED = 802;
1816 >  const API_EC_DATA_OBJECT_NOT_FOUND = 803;
1817 >  const API_EC_DATA_OBJECT_ALREADY_EXISTS = 804;
1818 >  const API_EC_DATA_DATABASE_ERROR = 805;
1819 >
1820 >
1821 >  /*
1822 >   * Batch ERROR
1823 >   */
1824 >  const API_EC_BATCH_ALREADY_STARTED = 900;
1825 >  const API_EC_BATCH_NOT_STARTED = 901;
1826 >  const API_EC_BATCH_METHOD_NOT_ALLOWED_IN_BATCH_MODE = 902;
1827 >
1828    public static $api_error_descriptions = array(
1829        API_EC_SUCCESS           => 'Success',
1830        API_EC_UNKNOWN           => 'An unknown error occurred',
# Line 587 | Line 1851 | class FacebookAPIErrorCodes {
1851        FQL_EC_NOT_INDEXABLE     => 'FQL: Statement not indexable',
1852        FQL_EC_UNKNOWN_FUNCTION  => 'FQL: Attempted to call unknown function',
1853        FQL_EC_INVALID_PARAM     => 'FQL: Invalid parameter passed in',
1854 +      API_EC_DATA_UNKNOWN_ERROR => 'Unknown data store API error',
1855 +      API_EC_DATA_INVALID_OPERATION => 'Invalid operation',
1856 +      API_EC_DATA_QUOTA_EXCEEDED => 'Data store allowable quota was exceeded',
1857 +      API_EC_DATA_OBJECT_NOT_FOUND => 'Specified object cannot be found',
1858 +      API_EC_DATA_OBJECT_ALREADY_EXISTS => 'Specified object already exists',
1859 +      API_EC_DATA_DATABASE_ERROR => 'A database error occurred. Please try again',
1860 +      API_EC_BATCH_ALREADY_STARTED => 'begin_batch already called, please make sure to call end_batch first',
1861 +      API_EC_BATCH_NOT_STARTED => 'end_batch called before start_batch',
1862 +      API_EC_BATCH_METHOD_NOT_ALLOWED_IN_BATCH_MODE => 'this method is not allowed in batch mode',
1863    );
1864   }
592
593 $profile_field_array = array(
594    "about_me",
595    "activities",
596    "affiliations",
597    "birthday",
598    "books",
599    "current_location",
600    "education_history",
601    "first_name",
602    "hometown_location",
603    "hs_info",
604    "interests",
605    "is_app_user",
606    "last_name",
607    "meeting_for",
608    "meeting_sex",
609    "movies",
610    "music",
611    "name",
612    "notes_count",
613    "pic",
614    "pic_big",
615    "pic_small",
616    "political",
617    "profile_update_time",
618    "quotes",
619    "relationship_status",
620    "religion",
621    "sex",
622    "significant_other_id",
623    "status",
624    "timezone",
625    "tv",
626    "wall_count",
627    "work_history");
628 ?>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines