1: <?php
2: /**
3: * Friends methods for Horde_Service_Facebook
4: *
5: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
6: *
7: * @author Michael J. Rubinsky <mrubinsk@horde.org>
8: * @category Horde
9: * @package Service_Facebook
10: */
11: class Horde_Service_Facebook_Friends extends Horde_Service_Facebook_Base
12: {
13: /**
14: * Returns whether or not pairs of users are friends.
15: * Note that the Facebook friend relationship is symmetric.
16: *
17: * @param string $uids1 comma-separated list of ids (id_1, id_2,...)
18: * of some length X
19: * @param string $uids2 comma-separated list of ids (id_A, id_B,...)
20: * of SAME length X
21: *
22: * @return array An array with uid1, uid2, and bool if friends, e.g.:
23: * array(0 => array('uid1' => id_1, 'uid2' => id_A, 'are_friends' => 1),
24: * 1 => array('uid1' => id_2, 'uid2' => id_B, 'are_friends' => 0)
25: * ...)
26: * @error
27: * API_EC_PARAM_USER_ID_LIST
28: */
29: public function &areFriends($uids1, $uids2)
30: {
31: // Session key is *required*
32: if (!$skey = $this->_facebook->auth->getSessionKey()) {
33: throw new Horde_Service_Facebook_Exception(
34: 'session_key is required',
35: Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
36: }
37:
38: return $this->_facebook->callMethod(
39: 'facebook.friends.areFriends',
40: array('uids1' => $uids1,
41: 'uids2' => $uids2));
42: }
43:
44: /**
45: * Returns the friends of the current session user.
46: *
47: * @param integer $flid (Optional) Only return friends on this friend list.
48: * @param integer $uid (Optional) Return friends for this user.
49: *
50: * @return array An array of friends
51: */
52: public function &get($flid = null, $uid = null)
53: {
54: // Session key is *required*
55: if (!$skey = $this->_facebook->auth->getSessionKey()) {
56: throw new Horde_Service_Facebook_Exception(
57: 'session_key is required',
58: Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
59: }
60: $params = array();
61: if (!empty($uid)) {
62: $params['uid'] = $uid;
63: }
64: if (!empty($flid)) {
65: $params['flid'] = $flid;
66: }
67:
68: return $this->_facebook->callMethod('facebook.friends.get', $params);
69: }
70:
71: /**
72: * Returns the set of friend lists for the current session user.
73: *
74: * @return array An array of friend list objects
75: */
76: public function &getLists()
77: {
78: // Session key is *required*
79: if (!$this->_facebook->auth->getSessionKey()) {
80: throw new Horde_Service_Facebook_Exception(
81: 'session_key is required',
82: Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED);
83: }
84: return $this->_facebook->callMethod(
85: 'facebook.friends.getLists',
86: array());
87: }
88:
89: }