コード例 #1
0
ファイル: Group.php プロジェクト: davidherzina/Phlickr
 function testFindByUrl_InvalidThrows()
 {
     try {
         $result = Phlickr_Group::findByUrl($this->api, 'http://flickr.com/groups/SOMETHING_THAT_IS_NOT_REAL/');
     } catch (Phlickr_MethodFailureException $e) {
         return;
     }
     $this->fail("An exception should have been thrown.");
 }
コード例 #2
0
ファイル: AuthedGroup.php プロジェクト: seeminglee/smldata
 function setUp()
 {
     $this->api = new Phlickr_Api(TESTING_API_KEY, TESTING_API_SECRET, TESTING_API_TOKEN);
     $this->api->setEndpointUrl('http://example.com');
     // inject the response xml into the cache...
     // ... first the login details (so it can figure out the user id)
     $this->api->addResponseToCache('flickr.auth.checkToken', $this->api->getParamsForRequest(), TESTING_RESP_OK_PREFIX . TESTING_XML_CHECKTOKEN . TESTING_RESP_SUFIX);
     // ... the full description of the group
     $this->api->addResponseToCache(Phlickr_Group::getRequestMethodName(), Phlickr_Group::getRequestMethodParams(TESTING_XML_GROUP_ID), TESTING_RESP_OK_PREFIX . TESTING_XML_GROUP_LONG . TESTING_RESP_SUFIX);
     // ... then for group pool
     $this->api->addResponseToCache('flickr.groups.pools.getPhotos', array('group_id' => TESTING_XML_GROUP_ID, 'page' => 1, 'per_page' => 10), TESTING_RESP_OK_PREFIX . TESTING_XML_GROUP_PHOTOLIST . TESTING_RESP_SUFIX);
     $this->group = new Phlickr_AuthedGroup($this->api, TESTING_XML_GROUP_ID);
 }
コード例 #3
0
ファイル: Group.php プロジェクト: ricardobar/WSClubeletro
 function setUp()
 {
     $this->api = new Phlickr_Api(TESTING_API_KEY, TESTING_API_TOKEN);
     $this->api->setEndpointUrl('http://example.com');
     // inject the response xml into the cache...
     // ... first for the full description of the group
     $this->api->addResponseToCache(Phlickr_Group::getRequestMethodName(), Phlickr_Group::getRequestMethodParams(TESTING_XML_GROUP_ID), TESTING_RESP_OK_PREFIX . TESTING_XML_GROUP_LONG . TESTING_RESP_SUFIX);
     // ... then for group pool
     $this->api->addResponseToCache('flickr.groups.pools.getPhotos', array('group_id' => TESTING_XML_GROUP_ID, 'page' => 1, 'per_page' => 10), TESTING_RESP_OK_PREFIX . TESTING_XML_GROUP_PHOTOLIST . TESTING_RESP_SUFIX);
     $this->fromId = new Phlickr_Group($this->api, TESTING_XML_GROUP_ID);
     $this->fromShortXml = new Phlickr_Group($this->api, simplexml_load_string(TESTING_XML_GROUP_SHORT));
     $this->fromLongXml = new Phlickr_Group($this->api, simplexml_load_string(TESTING_XML_GROUP_LONG));
 }
コード例 #4
0
 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();
 }
コード例 #5
0
 /**
  * Constructor.
  *
  * You can construct a group from an Id or XML.
  *
  * @param   object Phlickr_API $api
  * @param   mixed $source string Id, object SimpleXMLElement
  * @throws  Phlickr_Exception, Phlickr_ConnectionException,
  *          Phlickr_XmlParseException
  */
 function __construct(Phlickr_Api $api, $source)
 {
     parent::__construct($api, $source);
 }