コード例 #1
0
ファイル: flickrthumbnails.php プロジェクト: ukd1/thinktank
function flickrthumbnails_crawl()
{
    global $THINKTANK_CFG;
    global $db;
    global $conn;
    if (isset($THINKTANK_CFG['flickr_api_key']) && $THINKTANK_CFG['flickr_api_key'] != '') {
        $logger = new Logger($THINKTANK_CFG['log_location']);
        $fa = new FlickrAPIAccessor($THINKTANK_CFG['flickr_api_key'], $logger);
        $ldao = new LinkDAO($db, $logger);
        $flickrlinkstoexpand = $ldao->getLinksToExpandByURL('http://flic.kr/');
        if (count($flickrlinkstoexpand > 0)) {
            $logger->logStatus(count($flickrlinkstoexpand) . " Flickr links to expand", "Flickr Plugin");
        } else {
            $logger->logStatus("No Flickr links to expand", "Flickr Plugin");
        }
        foreach ($flickrlinkstoexpand as $fl) {
            $eurl = $fa->getFlickrPhotoSource($fl);
            if ($eurl["expanded_url"] != '') {
                $ldao->saveExpandedUrl($fl, $eurl["expanded_url"], '', 1);
            } elseif ($eurl["error"] != '') {
                $ldao->saveExpansionError($fl, $eurl["error"]);
            }
        }
        $logger->close();
        # Close logging
    }
}
コード例 #2
0
ファイル: linkdao_test.php プロジェクト: ukd1/thinktank
 function testSaveExpandedUrl()
 {
     $ldao = new LinkDAO($this->db, $this->logger);
     $linkstoexpand = $ldao->getLinksToExpand();
     $link = $linkstoexpand[0];
     $ldao->saveExpandedUrl($link, "http://expandedurl.com");
     $updatedlink = $ldao->getLinkByUrl($link);
     $this->assertEqual($updatedlink->expanded_url, "http://expandedurl.com");
     $ldao->saveExpandedUrl($link, "http://expandedurl1.com", 'my title');
     $updatedlink = $ldao->getLinkByUrl($link);
     $this->assertEqual($updatedlink->expanded_url, "http://expandedurl1.com");
     $this->assertEqual($updatedlink->title, "my title");
     $ldao->saveExpandedUrl($link, "http://expandedurl2.com", 'my title1', 1);
     $updatedlink = $ldao->getLinkByUrl($link);
     $this->assertEqual($updatedlink->expanded_url, "http://expandedurl2.com");
     $this->assertEqual($updatedlink->title, "my title1");
     $this->assertTrue($updatedlink->is_image);
 }
コード例 #3
0
 /**
  * Expand shortened Flickr links to image thumbnails if Flickr API key is set.
  * @param $api_key Flickr API key
  * @param $flickr_link Flickr URL
  */
 public function expandFlickrThumbnail($api_key, $flickr_link, $original_link)
 {
     $flickr_api = new FlickrAPIAccessor($api_key);
     $photo_details = $flickr_api->getFlickrPhotoSource($flickr_link);
     if ($photo_details["image_src"] != '') {
         //@TODO Make another Flickr API call to get the photo title & description and save to tu_links
         $this->link_dao->saveExpandedUrl($original_link, $flickr_link, '', $photo_details["image_src"]);
     } elseif ($photo_details["error"] != '') {
         $this->link_dao->saveExpansionError($original_link, $photo_details["error"]);
     }
 }