From dce6cfda886ecdd461bb8fc093e27773b712c008 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 27 Feb 2009 13:33:16 -0500 Subject: [PATCH] Add support for Photos methods. (Uploading/Viewing/Dealing with Galleries etc...) --- .../lib/Horde/Service/Facebook.php | 136 -------------- .../lib/Horde/Service/Facebook/Photos.php | 205 +++++++++++++++++++++ framework/Service_Facebook/package.xml | 2 + 3 files changed, 207 insertions(+), 136 deletions(-) create mode 100644 framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook.php b/framework/Service_Facebook/lib/Horde/Service/Facebook.php index 86eac6827..e5bfae5fb 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook.php @@ -421,142 +421,6 @@ class Horde_Service_Facebook 'note_ids' => json_encode($note_ids))); } - /** - * Adds a tag with the given information to a photo. See the wiki for details: - * - * http://wiki.developers.facebook.com/index.php/Photos.addTag - * - * @param int $pid The ID of the photo to be tagged - * @param int $tag_uid The ID of the user being tagged. You must specify - * either the $tag_uid or the $tag_text parameter - * (unless $tags is specified). - * @param string $tag_text Some text identifying the person being tagged. - * You must specify either the $tag_uid or $tag_text - * parameter (unless $tags is specified). - * @param float $x The horizontal position of the tag, as a - * percentage from 0 to 100, from the left of the - * photo. - * @param float $y The vertical position of the tag, as a percentage - * from 0 to 100, from the top of the photo. - * @param array $tags (Optional) An array of maps, where each map - * can contain the tag_uid, tag_text, x, and y - * parameters defined above. If specified, the - * individual arguments are ignored. - * @param int $owner_uid (Optional) The user ID of the user whose photo - * you are tagging. If this parameter is not - * specified, then it defaults to the session user. - * - * @return bool true on success - */ - public function &photos_addTag($pid, $tag_uid, $tag_text, $x, $y, $tags, $owner_uid = 0) - { - return $this->call_method('facebook.photos.addTag', - array('pid' => $pid, - 'tag_uid' => $tag_uid, - 'tag_text' => $tag_text, - 'x' => $x, - 'y' => $y, - 'tags' => (is_array($tags)) ? json_encode($tags) : null, - 'owner_uid' => $this->get_uid($owner_uid))); - } - - /** - * Creates and returns a new album owned by the specified user or the current - * session user. - * - * @param string $name The name of the album. - * @param string $description (Optional) A description of the album. - * @param string $location (Optional) A description of the location. - * @param string $visible (Optional) A privacy setting for the album. - * One of 'friends', 'friends-of-friends', - * 'networks', or 'everyone'. Default 'everyone'. - * @param int $uid (Optional) User id for creating the album; if - * not specified, the session user is used. - * - * @return array An album object - */ - public function &photos_createAlbum($name, $description='', $location='', $visible='', $uid=0) - { - return $this->call_method('facebook.photos.createAlbum', - array('name' => $name, - 'description' => $description, - 'location' => $location, - 'visible' => $visible, - 'uid' => $this->get_uid($uid))); - } - - /** - * Returns photos according to the filters specified. - * - * @param int $subj_id (Optional) Filter by uid of user tagged in the photos. - * @param int $aid (Optional) Filter by an album, as returned by - * photos_getAlbums. - * @param string $pids (Optional) Restrict to a comma-separated list of pids - * - * Note that at least one of these parameters needs to be specified, or an - * error is returned. - * - * @return array An array of photo objects. - */ - public function &photos_get($subj_id, $aid, $pids) - { - return $this->call_method('facebook.photos.get', - array('subj_id' => $subj_id, 'aid' => $aid, 'pids' => $pids)); - } - - /** - * Returns the albums created by the given user. - * - * @param int $uid (Optional) The uid of the user whose albums you want. - * A null will return the albums of the session user. - * @param string $aids (Optional) A comma-separated list of aids to restricti - * the query. - * - * Note that at least one of the (uid, aids) parameters must be specified. - * - * @returns an array of album objects. - */ - public function &photos_getAlbums($uid, $aids) - { - return $this->call_method('facebook.photos.getAlbums', - array('uid' => $uid, - 'aids' => $aids)); - } - - /** - * Returns the tags on all photos specified. - * - * @param string $pids A list of pids to query - * - * @return array An array of photo tag objects, which include pid, - * subject uid, and two floating-point numbers (xcoord, ycoord) - * for tag pixel location. - */ - public function &photos_getTags($pids) - { - return $this->call_method('facebook.photos.getTags', array('pids' => $pids)); - } - - /** - * Uploads a photo. - * - * @param string $file The location of the photo on the local filesystem. - * @param int $aid (Optional) The album into which to upload the - * photo. - * @param string $caption (Optional) A caption for the photo. - * @param int uid (Optional) The user ID of the user whose photo you - * are uploading - * - * @return array An array of user objects - */ - public function photos_upload($file, $aid = null, $caption = null, $uid = null) - { - return $this->call_upload_method('facebook.photos.upload', - array('aid' => $aid, - 'caption' => $caption, - 'uid' => $uid), - $file); - } /** diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php new file mode 100644 index 000000000..c7b35b205 --- /dev/null +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php @@ -0,0 +1,205 @@ +_facebook->auth->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('photos.addTag requires either a uid or a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + + $params = array('pid' => $pid, + 'tag_uid' => $tag_uid, + 'tag_text' => $tag_text, + 'x' => $x, + 'y' => $y, + 'tags' => (is_array($tags)) ? json_encode($tags) : null); + if (!empty($owner_uid)) { + $params['owner_uid'] = $uid; + } + if ($skey = $this->_facebook->auth->getSessionKey()) { + $params['session_key'] = $skey; + } + + return $this->call_method('facebook.photos.addTag', $params); + } + + /** + * Creates and returns a new album owned by the specified user or the current + * session user. + * + * @param string $name The name of the album. + * @param string $description (Optional) A description of the album. + * @param string $location (Optional) A description of the location. + * @param string $visible (Optional) A privacy setting for the album. + * One of 'friends', 'friends-of-friends', + * 'networks', or 'everyone'. Default 'everyone'. + * @param int $uid (Optional) User id for creating the album; if + * not specified, the session user is used. + * + * @return array An album object + */ + public function &createAlbum($name, $description = '', $location = '', $visible = '', $uid = 0) + { + // Requires either a owner_uid or a session_key + if (empty($owner_uid) && !$this->_facebook->auth->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('photos.addTag requires either a owner_uid or a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + + $params = array('name' => $name, + 'description' => $description, + 'location' => $location, + 'visible' => $visible); + + // Yes, this method uses 'uid' while some of the others use + // 'owner_uid' - don't ask me... + if (!empty($uid)) { + $params['uid'] = $uid; + } + + if ($skey = $this->_facebook->auth->getSessionKey()) { + $params['session_key'] = $skey; + } + + return $this->call_method('facebook.photos.createAlbum', $params); + } + + /** + * Returns photos according to the filters specified. + * + * @param int $subj_id (Optional) Filter by uid of user tagged in the photos. + * @param int $aid (Optional) Filter by an album, as returned by + * photos_getAlbums. + * @param string $pids (Optional) Restrict to a comma-separated list of pids + * + * Note that at least one of these parameters needs to be specified, or an + * error is returned. + * + * @return array An array of photo objects. + */ + public function &get($subj_id, $aid, $pids) + { + // Requires a session_key + if (!$skey = $this->_facebook->auth->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('photos.addTag requires a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + return $this->call_method('facebook.photos.get', + array('subj_id' => $subj_id, + 'aid' => $aid, + 'pids' => $pids, + 'session_key' => $skey)); + } + + /** + * Returns the albums created by the given user. + * + * @param int $uid (Optional) The uid of the user whose albums you want. + * A null will return the albums of the session user. + * @param string $aids (Optional) A comma-separated list of aids to restricti + * the query. + * + * Note that at least one of the (uid, aids) parameters must be specified. + * + * @returns an array of album objects. + */ + public function &getAlbums($uid, $aids) + { + // Requires a session_key + if (!$skey = $this->_facebook->auth->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('photos.addTag requires a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + + return $this->call_method('facebook.photos.getAlbums', + array('uid' => $uid, + 'aids' => $aids, + 'session_key' => $skey)); + } + + /** + * Returns the tags on all photos specified. + * + * @param string $pids A list of pids to query + * + * @return array An array of photo tag objects, which include pid, + * subject uid, and two floating-point numbers (xcoord, ycoord) + * for tag pixel location. + */ + public function &photos_getTags($pids) + { + // Requires a session_key + if (!$skey = $this->_facebook->auth->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('photos.addTag requires a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + + return $this->call_method('facebook.photos.getTags', array('pids' => $pids, 'session_key' => $skey)); + } + + /** + * Uploads a photo. + * + * @param string $file The location of the photo on the local filesystem. + * @param int $aid (Optional) The album into which to upload the + * photo. + * @param string $caption (Optional) A caption for the photo. + * @param int uid (Optional) The user ID of the user whose photo you + * are uploading + * + * @return array An array of user objects + */ + public function photos_upload($file, $aid = null, $caption = null, $uid = null) + { + // Requires either a owner_uid or a session_key + if (empty($uid) && !$skey = $this->_facebook->auth->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('photos.addTag requires either a uid or a session_key', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + + $params = array('aid' => $aid, 'caption' => $caption); + if (!empty($uid)) { + $params['uid'] = $uid; + } + + if (!empty($skey)) { + $params['session_key'] = $skey; + } + + return $this->call_upload_method('facebook.photos.upload', $params, $file); + } + +} \ No newline at end of file diff --git a/framework/Service_Facebook/package.xml b/framework/Service_Facebook/package.xml index 4596bc9c3..25f282fc2 100644 --- a/framework/Service_Facebook/package.xml +++ b/framework/Service_Facebook/package.xml @@ -42,6 +42,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -76,6 +77,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + -- 2.11.0