1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Horde_Service_Facebook_Streams extends Horde_Service_Facebook_Base
12: {
13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:
31: function &get($viewerId = '', $sourceIds = array(), $start = '', $end = '',
32: $limit = '', $filterKey = '')
33: {
34: if (empty($viewerId) && !$session_key = $this->_facebook->auth->getSessionKey()) {
35: throw new Horde_Service_Facebook_Exception(
36: 'Streams.publish requires either a uid or a session_key',
37: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
38: }
39: $params = array('viewer_id' => $viewerId,
40: 'source_ids' => $sourceIds,
41: 'start_time' => $start,
42: 'end_time' => $end,
43: 'filter_key' => $filterKey,
44: 'limit' => $limit);
45:
46: return $this->_facebook->callMethod('Stream.get', $params);
47: }
48:
49: 50: 51: 52: 53: 54: 55: 56: 57:
58: function &getComments($postId)
59: {
60: return $this->_facebook->callMethod(
61: 'Stream.getComments', array('post_id' => $postId));
62: }
63:
64: 65: 66: 67: 68: 69: 70: 71: 72:
73: function getFilters($uid = '')
74: {
75: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
76: throw new Horde_Service_Facebook_Exception(
77: 'Streams.getFilters requires either a uid or a session_key',
78: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
79: }
80:
81: if (!empty($uid)) {
82: $params = array('uid' => $uid);
83: } else {
84: $params = array();
85: }
86:
87: return $this->_facebook->callMethod('Streams.getFilters', $params);
88: }
89:
90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121:
122: function publish($message = '', $attachment = array(), $action_links = '',
123: $target_id = '', $uid = '', $privacy = array())
124: {
125: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
126: throw new Horde_Service_Facebook_Exception(
127: 'Streams.publish requires either a uid or a session_key',
128: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
129: }
130:
131: $params = array('message' => $message,
132: 'action_links' => $action_links,
133: 'target_id' => $target_id);
134: if (!empty($uid)) {
135: $params['uid'] = $uid;
136: }
137: if (!empty($attachment)) {
138: $params['attachment'] = json_encode($attachment);
139: }
140: if (!empty($privacy)) {
141: $privacy_object = new stdClass;
142: if (isset($privacy['value'])) {
143: $privacy_object->value = $privacy['value'];
144: } else {
145: $privacy_object->value = 'EVERYONE';
146: }
147: foreach (array('friends', 'networks', 'allow', 'deny') as $setting) {
148: if (isset($privacy[$setting])) {
149: $privacy_object->{$setting} = $privacy[$setting];
150: }
151: }
152: $params['privacy'] = json_encode($privacy_object);
153: }
154: return $this->_facebook->callMethod('Stream.publish', $params);
155: }
156:
157: 158: 159: 160: 161: 162: 163: 164:
165: function remove($postId, $uid = '')
166: {
167: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
168: throw new Horde_Service_Facebook_Exception(
169: 'Streams.remove requires either a uid or a session_key',
170: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
171: }
172:
173: $params = array('post_id' => $postId);
174: if (!empty($uid)) {
175: $params['uid'] = $uid;
176: }
177:
178: return $this->_facebook->callMethod('Stream.remove', $params);
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188: 189: 190:
191: function ($postId, $comment, $uid = '')
192: {
193: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
194: throw new Horde_Service_Facebook_Exception(
195: 'Streams.addComment requires either a uid or a session_key',
196: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
197: }
198:
199: $params = array('post_id' => $postId,
200: 'comment' => $comment);
201:
202: if (!empty($uid)) {
203: $params['uid'] = $uid;
204: }
205:
206: return $this->_facebook->callMethod('Stream.addComment', $params);
207: }
208:
209: 210: 211: 212: 213: 214: 215: 216:
217: function ($commentId, $uid = '')
218: {
219: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
220: throw new Horde_Service_Facebook_Exception(
221: 'Streams.removeComment requires either a uid or a session_key',
222: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
223: }
224:
225: $params = array('comment_id' => $commentId);
226: if (!empty($uid)) {
227: $params['uid'] = $uid;
228: }
229:
230: return $this->_facebook->callMethod('Stream.removeComment', $params);
231: }
232:
233: 234: 235: 236: 237: 238: 239: 240:
241: function addLike($postId, $uid = '')
242: {
243: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
244: throw new Horde_Service_Facebook_Exception(
245: 'Streams.addLike requires either a uid or a session_key',
246: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
247: }
248:
249: $params = array('post_id' => $postId);
250: if (!empty($uid)) {
251: $params['uid'] = $uid;
252: }
253:
254: return $this->_facebook->callMethod('Stream.addLike', $params);
255: }
256:
257: 258: 259: 260: 261: 262: 263: 264:
265: function removeLike($postId, $uid = '')
266: {
267: if (empty($uid) && !$session_key = $this->_facebook->auth->getSessionKey()) {
268: throw new Horde_Service_Facebook_Exception(
269: 'Streams.removeLike requires either a uid or a session_key',
270: Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY);
271: }
272:
273: $params = array('post_id' => $postId);
274: if (!empty($uid)) {
275: $params['uid'] = $uid;
276: }
277:
278: return $this->_facebook->callMethod('Stream.removeLike', $params);
279: }
280:
281: }