Beispiel #1
0
 function download($groupId)
 {
     $maxPages = 2;
     $info = $this->flickrLatex->request('flickr.groups.getInfo', ['group_id' => $groupId]);
     if (!isset($info->group)) {
         echo "Unable to get group info for group {$groupId} -- returned was:\n";
         print_r($info);
         exit(1);
     }
     $title = $info->group->name->_content;
     echo "====== Downloading photos for group: {$title} ======\n";
     // Loop through all pages of photos for this group.
     $photoData = array();
     $page = 1;
     while ($page) {
         $photos = $this->flickrLatex->request('flickr.groups.pools.getPhotos', ['group_id' => $groupId, 'page' => $page, 'per_page' => 500]);
         echo "Getting page {$page} of " . $photos->photos->pages . "\n";
         // Get all these photos.
         foreach ($photos->photos->photo as $photo) {
             $photoDatum = $this->flickrLatex->singlePhoto($photo->id);
             $photoData[uniqid($photoDatum['date_taken'])] = $photoDatum;
         }
         if ($page < min($photos->photos->pages, $maxPages)) {
             $page++;
         } else {
             $page = false;
         }
     }
     ksort($photoData);
     // Output LaTeX file.
     $dataDir = $this->dataDir;
     ob_start();
     require $this->templateDir . '/album.php';
     $latex = ob_get_clean();
     $albumDir = $this->dataDir . '/albums/' . $groupId;
     if (!is_dir($albumDir)) {
         mkdir($albumDir, 0755, true);
     }
     file_put_contents($albumDir . '/album.tex', $latex);
 }
Beispiel #2
0
<?php 
use Samwilson\FlickrLatex\FlickrLatex;
use Samwilson\FlickrLatex\Group;
echo "Please report bugs at https://github.com/samwilson/flickr-latex\n";
if (php_sapi_name() !== 'cli') {
    echo "This file should be run from the command line.\n";
    exit(1);
}
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/config.php';
// Check config variables.
if (!is_array($groups)) {
    echo "You must set the '\$groups' variable in config.php\n";
    exit(1);
}
$flickrLatex = new FlickrLatex(__DIR__ . '/data', $apiKey, $apiSecret);
// See if we need to authorize.
if (!$flickrLatex->authorized()) {
    $flickrService = $flickrLatex->getService();
    // Fetch the request-token.
    $requestToken = $flickrService->requestRequestToken();
    $url = $flickrService->getAuthorizationUri(['oauth_token' => $requestToken->getRequestToken(), 'perms' => 'read']);
    echo "Please go to this URL to authorize this applicaiton:\n{$url}\n";
    // Flickr says, at this point:
    // "You have successfully authorized the application Flickr Latex to use your credentials.
    // You should now type this code into the application:"
    echo "Paste the 9-digit code (with or without hyphens) here: ";
    $verifier = preg_replace('/[^0-9]/', '', fgets(fopen('php://stdin', 'r')));
    // Fetch the access-token, for saving to data/token.json
    $accessToken = $flickrService->requestAccessToken($requestToken, $verifier, $requestToken->getAccessTokenSecret());
    $flickrLatex->setStoredCredentials($accessToken);