Overview

Packages

  • None
  • Service
    • Facebook

Classes

  • Horde_Service_Facebook_Auth
  • Horde_Service_Facebook_Base
  • Horde_Service_Facebook_BatchRequest
  • Horde_Service_Facebook_ErrorCodes
  • Horde_Service_Facebook_Events
  • Horde_Service_Facebook_Exception
  • Horde_Service_Facebook_Fql
  • Horde_Service_Facebook_Friends
  • Horde_Service_Facebook_Groups
  • Horde_Service_Facebook_Links
  • Horde_Service_Facebook_Notes
  • Horde_Service_Facebook_Notifications
  • Horde_Service_Facebook_Photos
  • Horde_Service_Facebook_Request
  • Horde_Service_Facebook_Streams
  • Horde_Service_Facebook_Translation
  • Horde_Service_Facebook_UploadRequest
  • Horde_Service_Facebook_Users
  • Horde_Service_Facebook_Videos
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Open streams API
  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_Streams extends Horde_Service_Facebook_Base
 12: {
 13:     /**
 14:      * Get a user's stream
 15:      * http://wiki.developers.facebook.com/index.php/Stream.get
 16:      *
 17:      * Note: This requires the READ_STREAM extended permission to be added for
 18:      *       the application.
 19:      *
 20:      * @param string $viewerId  The user id or page id of the page whose stream
 21:      *                          to read.
 22:      * @param array     $sourceIds
 23:      * @param timestamp $start
 24:      * @param timestamp $end
 25:      * @param integer   $limit
 26:      * @param string    $filterKey
 27:      *
 28:      * @return mixed Method call results.
 29:      * @deprecated by the Graph API
 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:      * Get a post's comments. Note that the owner of the post that is being
 51:      * retrieved must have the application authorized.
 52:      *
 53:      * @param string $postId  The post id of the post whose comments we are
 54:      *                        retrieving.
 55:      *
 56:      * @return mixed
 57:      */
 58:     function &getComments($postId)
 59:     {
 60:         return $this->_facebook->callMethod(
 61:             'Stream.getComments', array('post_id' => $postId));
 62:     }
 63: 
 64:     /**
 65:      * Get a user's stream filter.
 66:      *
 67:      * http://wiki.developers.facebook.com/index.php/Stream.getFilters
 68:      *
 69:      * @param integer $uid  The user id of whose filters we are requesting.
 70:      *
 71:      * @return Array of filter data.
 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:      * Publish into a user's stream
 92:      *
 93:      * http://wiki.developers.facebook.com/index.php/Stream.publish
 94:      *
 95:      * @param string $message       The string of the message to post.
 96:      * @param array  $attachment    An array describing the item we are publishing
 97:      *                              see the API docs.
 98:      * @param array  $action_links  Array of action links.
 99:      * @param string $target_id     The id of user/page you are publishing to.
100:      * @param string $uid           The id of user publishing the post.
101:      * @param array  $privacy       The privacy settings for the post.
102:      * - value: (string) The privacy value for the object, specify one of
103:      *     EVERYONE, CUSTOM, ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS,
104:      *     SELF.
105:      * - friends: (string) For CUSTOM settings, this indicates which users can
106:      *     see the object. Can be one of EVERYONE, NETWORKS_FRIENDS (when the
107:      *     object can be seen by networks and friends), FRIENDS_OF_FRIENDS,
108:      *     ALL_FRIENDS, SOME_FRIENDS, SELF, or NO_FRIENDS (when the object can
109:      *     be seen by a network only).
110:      * - networks: (string) For CUSTOM settings, specify a comma-separated list
111:      *     of network IDs that can see the object, or 1 for all of a user's
112:      *     networks.
113:      * - allow: (string) When friends is set to SOME_FRIENDS, specify a
114:      *     comma-separated list of user IDs and friend list IDs that ''can'' see
115:      *     the post.
116:      * - deny: (string) When friends is set to SOME_FRIENDS, specify a
117:      *     comma-separated list of user IDs and friend list IDs that ''cannot''
118:      *     see the post.
119:      *
120:      * @return mixed
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:      * Remove a post from a user's stream
159:      *
160:      * @param string $postId  The post id
161:      * @param string $uid      The user id
162:      *
163:      * @return mixed
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:      * Add a comment to a user's post.
183:      *
184:      * @param string $postId  The post id the comment belongs to
185:      * @param string $comment  The body of the comment (text only, no HTML).
186:      * @param string $uid      The user id of the user who is posting the
187:      *                         comment.
188:      *
189:      * @return string The comment id of the posted comment.
190:      */
191:     function addComment($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:      * Remove a comment from a post.
211:      *
212:      * @param string $commentId  The comment id to remove.
213:      * @param string $uid         User id
214:      *
215:      * @return boolean
216:      */
217:     function removeComment($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:      * Add a "like" to a post.
235:      *
236:      * @param string $postId
237:      * @param string $uid
238:      *
239:      * @return mixed
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:      * Remove a "like" from a stream post.
259:      *
260:      * @param string $postId  The post id to remove a like from.
261:      * @param string $uid     The user id who the like belongs to.
262:      *
263:      * @return boolean
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: }
API documentation generated by ApiGen