function flickr_photo_username($image_photo, &$user_name) { global $flickr_api; $user_id = $image_photo->getOwnerId(); $user = new Phlickr_User($flickr_api, $user_id); $user_name = $user->getName(); }
function testUpload_WithMeta() { $user = new Phlickr_User($this->api, $this->api->getUserId()); $oldPhotoCount = $user->getPhotoCount(); $this->uploader->setPerms(true, false, false); // upload it $result = $this->uploader->Upload(TESTING_FILE_NAME_JPG, 'testing title', 'a description', 'atag btag'); // ensure the photo count increases $user->refresh(); $this->assertEquals($oldPhotoCount + 1, $user->getPhotoCount(), 'Photocount should have increased.'); // verify the returned id $this->assertType('string', $result, 'Returned the wrong type.'); $photo = new Phlickr_Photo($this->api, $result); $this->assertNotNull($photo, "Couldn't load a photo from the result id."); $this->assertEquals('testing title', $photo->getTitle()); $this->assertEquals('a description', $photo->getDescription()); $this->assertEquals(array('atag', 'btag'), $photo->getTags()); $this->assertTrue($photo->isForPublic()); $this->assertFalse($photo->isForFriends()); $this->assertFalse($photo->isForFamily()); }
function testConstructor_FromIdConnectsAssignsId() { $fromId = new Phlickr_User($this->api, TESTING_USER_ID); $this->assertEquals($this->api, $fromId->getApi()); $this->assertEquals(TESTING_XML_USER_ID, $fromId->getId()); }
/** * Constructor. * * @param object Phlickr_Api $api This object must have valid * authentication information or an exception will be thrown. */ function __construct(Phlickr_Api $api) { assert($api->isAuthValid()); parent::__construct($api, $api->getUserId()); }
function testFindByUrl_InvalidThrows() { try { $result = Phlickr_User::findByUrl($this->api, 'http://www.flickr.com/photos/SOMETHING_THAT_IS_NOT_REAL/'); } catch (Phlickr_MethodFailureException $e) { return; } $this->fail("An exception should have been thrown."); }
<?php include_once 'Api.php'; include_once 'User.php'; $api = new Phlickr_Api("\nbf5d0953f69b3386edc3760d784955f5", "16d906ea4207bafc"); $user = Phlickr_User::findByUrl($api, 'http://flickr.com/people/drewish/'); // print out the user's name print "User: {$user->getName()}\n"; // print out their groups foreach ($user->getGroupList()->getGroups() as $group) { print "Group: {$group->getName()} ({$group->buildUrl()})\n"; } // print out their photosets foreach ($user->getPhotosetList()->getPhotosets() as $photoset) { print "Photoset: {$photoset->getTitle()} ({$photoset->buildUrl()})\n"; } // print out their 10 latest, favorite photos $photolist = $user->getFavoritePhotoList(10); foreach ($photolist->getPhotos() as $photo) { print "Favorite: {$photo->getTitle()} ({$photo->buildImgUrl()})\n"; }
/** * Get a random favorite photo from a Flickr user. * * @param string $userEmail Email address of a Flickr user * @return object Phlickr_Photo */ function getRandomFavoritePhoto($userEmail) { $api = new Phlickr_Api(FLICKR_API_KEY, FLICKR_API_SECRET); // load a saved cache file if it exists, set the expiration limit to a week. $api->setCache(Phlickr_Cache::createFrom(CACHE_FILE, 60 * 60 * 24 * 7)); // select a random favorite photo $user = Phlickr_User::findByEmail($api, $userEmail); $favlist = $user->getFavoritePhotoList(); $photo = $favlist->getRandomPhoto(); assert(!is_null($photo)); // serialize and save the cache file $api->getCache()->saveAs(CACHE_FILE); return $photo; }
public function getUserUI($subclass_user_interface = null, $force_data_refresh = false) { // Init values $html = ''; if ($this->_PhlickrAvailable) { $api = $this->getFlickrApi(); if (!is_null($api)) { // Load cache only on the User UI side if ($force_data_refresh === false) { $this->loadCacheFromDatabase(); } try { $photos = null; switch ($this->getSelectionMode()) { case self::SELECT_BY_GROUP: if ($this->getGroupId()) { $photo_pool = new Phlickr_Group($api, $this->getGroupId()); $photos = $photo_pool->getPhotoList($this->getPhotoBatchSize())->getPhotos(); } break; case self::SELECT_BY_TAGS: if ($this->getTags()) { $request = $api->createRequest('flickr.photos.search', array('tags' => $this->getTags(), 'tag_mode' => $this->getTagMode())); $photo_list = new Phlickr_PhotoList($request, $this->getPhotoBatchSize()); $photos = $photo_list->getPhotos(); } break; case self::SELECT_BY_USER: if ($this->getFlickrUserId()) { $user = new Phlickr_User($api, $this->getFlickrUserId()); $photos = $user->getPhotoList($this->getPhotoBatchSize())->getPhotos(); } break; } if (is_array($photos) && !empty($photos)) { $size = $this->getPreferredSize(); if (empty($size)) { $size = null; } // Preload authors ( this will be cached ) foreach ($photos as $cache_authors) { $author = new Phlickr_User($api, $cache_authors->getUserId()); } switch ($this->getDisplayMode()) { case self::DISPLAY_GRID: // If there's enough photo show a grid if (count($photos) >= self::GRID_X * self::GRID_Y) { $grid_photos_idx = array(); $html .= "<table>\n"; for ($i = 0; $i < self::GRID_X; $i++) { $html .= "<tr>\n"; for ($j = 0; $j < self::GRID_Y; $j++) { $photo = $photos[$i * self::GRID_X + $j]; if (is_object($photo)) { $author = new Phlickr_User($api, $photo->getUserId()); $formats = $photo->getSizes(); $html .= '<td><div class="flickr_photo"><a href="' . $photo->buildUrl() . '"><img width="' . $formats[$size][0] . '" height="' . $formats[$size][1] . '" title="[' . $author->getName() . "] " . $photo->getTitle() . '" src="' . $photo->buildImgUrl($size) . '"></a></div></td>' . "\n"; } } $html .= "</tr>\n"; } $html .= "</table>\n"; } break; case self::DISPLAY_FEATURE: // Get the last photo $photo = $photos[0]; if (is_object($photo)) { if ($this->shouldDisplayTitle()) { $title = $photo->getTitle(); if (!empty($title)) { $html .= '<div class="flickr_title"><h3>' . $photo->getTitle() . '</h3></div>' . "\n"; } } /** * @todo Find a way to display tags nicely */ /* if ($this->shouldDisplayTags()) { $tags = $photo->getTags(); if (!empty ($tags)) { $html .= '<div class="flickr_tags">'."\n"; $html .= '<h3>'._("Tags")."</h3>\n"; $html .= '<ul>'."\n"; foreach ($tags as $tag) { $url_encoded_tag = urlencode($tag); $html .= '<li><a href="http://www.flickr.com/photos/tags/'.$url_encoded_tag.'/">'.$tag.'</a></li>'."\n"; } $html .= '</ul>'."\n"; $html .= '</div>'."\n"; } }*/ /** * @todo Display author's name along with it ... */ /* foreach ($photos as $cache_authors) $author = new Phlickr_User($api, $cache_authors->getUserId()); $author = new Phlickr_User($api, $photo->getUserId()); $html .= '<div class="flickr_description"><a href="'.$author->buildUrl().'">'.$author->getName().'</a></div>'."\n"; */ //$html .= "</div>\n"; $html .= '<div class="flickr_photo_block">' . "\n"; $html .= "<div class=\"flickr_photo\"><a href=\"{$photo->buildUrl()}\"><img src=\"{$photo->buildImgUrl($size)}\" /></a></div>\n"; $html .= "</div>\n"; } break; case self::DISPLAY_FEATURE_WITH_RANDOM: break; } } else { $html .= _("No Flickr content matches the request !"); } } catch (Phlickr_ConnectionException $e) { $html .= sprintf(_("Unable to connect to Flickr API: %s"), "<pre>{$e}</pre>"); } catch (Phlickr_MethodFailureException $e) { $html .= _("Some of the request parameters provided to Flickr API are invalid."); $html .= "<br>" . $e->getMessage(); } catch (Phlickr_XmlParseException $e) { $html .= _("Unable to parse Flickr's response."); } catch (Phlickr_Exception $e) { $html .= _("Could not get content from Flickr : ") . $e; } // Overwrite cache if needed $this->writeCacheToDatabase($force_data_refresh); } } else { $html .= _("PEAR::Phlickr is not installed"); } /* Handle hyperlink clicktrough logging */ $html = $this->replaceHyperLinks($html); $this->setUserUIMainDisplayContent($html); return parent::getUserUI(); }