示例#1
0
require_once 'Phlickr/PhotoListIterator.php';
print "This script lets you select photos by tag and then set the taken date\n";
print "to a month-year date.\n\n";
// set up the api connection
$api = Phlickr_Api::createFrom(API_CONFIG_FILE);
$api->setCacheFilename(CACHE_FILE);
if (!$api->isAuthValid()) {
    die("invalid flickr logon");
}
// get a list of tags
print 'Enter a comma separated list of tags: ';
$tags = trim(fgets(STDIN));
// create a request to search for your photos with the tags.
$request = $api->createRequest('flickr.photos.search', array('tags' => $tags, 'tag_mode' => 'all', 'user_id' => $api->getUserId()));
// use the photo list to parse the search results
print "Searching for matching photos tagged with '{$tags}'...\n";
$pl = new Phlickr_PhotoList($request, Phlickr_PhotoList::PER_PAGE_MAX);
print "Found {$pl->getCount()} photos.\n";
print 'Year: ';
$year = (int) trim(fgets(STDIN));
print 'Month: ';
$month = (int) trim(fgets(STDIN));
print "The photo's taken date will be set to {$year}-{$month}.\n";
print "Press return to continue or CTRL+C to quit.\n";
fgets(STDIN);
$pi = new Phlickr_PhotoListIterator($pl);
foreach ($pi->getPhotos() as $p) {
    print "Changing date on '{$p->getTitle()}'...\n";
    $p->setTaken($year . '-' . $month, 4);
}
exit(0);
示例#2
0
 public function doSearch()
 {
     $search = $this->getSearchForm()->getSearch();
     $page = $this->getSearchForm()->getPage();
     $perPage = $this->getSearchForm()->getPerPage();
     $tmp = array();
     $request = $this->getPhlickr()->createRequest('flickr.photos.search', array('tags' => $search, 'tag_mode' => 'all', 'page' => $page, 'per_page' => $perPage));
     $photolist = new Phlickr_PhotoList($request, $perPage);
     $iterator = new Phlickr_PhotoListIterator($photolist);
     try {
         $cacheTable = $this->getTableCache();
         $imageTable = $this->getTableImage();
         $db = $cacheTable->getAdapter();
         $db->beginTransaction();
         $cacheRow = $cacheTable->createRow(array('search_term' => $search, 'search_time' => time()));
         $cacheRow->save();
         foreach ($iterator->current() as $photo) {
             $data = array('flickr_cache_id' => $cacheRow->id, 'api_key' => $photo->getId(), 'title' => $photo->getTitle(), 'url' => $photo->buildImgUrl(), 'page' => $page, 'per_page' => $perPage);
             $row = $imageTable->createRow($data);
             $row->save();
             $tmp[] = $data;
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
     }
     return $tmp;
 }