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(); }
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(); }