function flickr_photos_import_photo_files_s3(&$photo, $more = array())
{
    loadlib('storage_s3');
    $flickr_urls = _flickr_photos_import_flickr_urls($photo, $more);
    $orig = storage_s3_path_photo($photo, 'o', $more);
    $small = storage_s3_path_photo($photo, 'z', $more);
    $req = array();
    $meta = array();
    if ($more['force'] || !storage_s3_file_exists($small)) {
        $req[] = $flickr_urls['small'];
    }
    if ($more['force'] || !storage_s3_file_exists($orig)) {
        log_debug('flickr', "flickr orig: " . $flickr_urls['orig']);
        $req[] = $flickr_urls['orig'];
    }
    $info = str_replace("_o.{$photo['originalformat']}", "_i.json", $orig);
    $comments = str_replace("_o.{$photo['originalformat']}", "_c.json", $orig);
    if (!isset($more['skip_meta'])) {
        $meta = _flickr_photos_import_flickr_meta_urls($photo, $more);
        foreach ($meta as $k => $v) {
            $req[] = $v;
        }
    }
    # now go!
    # fetch all the bits using http_multi()
    log_debug('import', "multi-fetch count: " . count($req));
    if ($count = count($req)) {
        list($multi, $failed) = _flickr_photos_import_do_fetch_multi($req);
    }
    log_debug('import', "fetch success count: " . count($multi));
    foreach ($multi as $rsp) {
        log_debug('import', "ok: " . $rsp['url']);
    }
    foreach ($failed as $rsp) {
        log_debug('import', "failed: " . $rsp['url']);
    }
    loadlib('mime_type');
    $sent = array();
    foreach ($multi as $rsp) {
        $id = '';
        if ($rsp['url'] == $flickr_urls['orig']) {
            $id = $orig;
        } elseif ($rsp['url'] == $flickr_urls['small']) {
            $id = $small;
        } elseif ($rsp['url'] == $meta['info']) {
            $id = $info;
            $more['type'] = 'application/json';
        } elseif ($rsp['url'] == $meta['comments']) {
            $id = $comments;
            $more['type'] = 'application/json';
        }
        if ($id) {
            $sent[] = storage_s3_file_store($id, $rsp['body'], $more);
        }
    }
    foreach ($sent as $rsp) {
        if ($rsp['ok']) {
            log_debug('s3', 'ok put ' . $rsp['url']);
        } else {
            log_debug('s3', 'failed put ' . $rsp['url']);
        }
    }
}
예제 #2
0
function storage_s3_url_photo($photo, $size = 'z', $more = array())
{
    $path = storage_s3_path_photo($photo, $size, $more);
    return s3_unsigned_object_url(storage_s3_bucket(), $path);
}