function api_flickr_photos_geo_correctLocation()
{
    $flickr_user = api_utils_flickr_ensure_token_perms($GLOBALS['cfg']['user'], 'write');
    $photo_id = post_int64("photo_id");
    $photo = _api_flickr_photos_geo_get_photo($photo_id);
    $old_woeid = $photo['woeid'];
    $new_woeid = post_int32("woeid");
    if (!$new_woeid) {
        api_output_error(999, "Missing WOE ID");
    }
    if ($old_woeid == $new_woeid) {
        api_output_error(999, "Nothing to correct!");
    }
    # validate WOE ID preemptively?
    $method = "flickr.photos.geo.correctLocation";
    $args = array('photo_id' => $photo['id'], 'woe_id' => $new_woeid, 'auth_token' => $flickr_user['auth_token']);
    $rsp = flickr_api_call($method, $args);
    if (!$rsp['ok']) {
        api_output_error(999, $rsp['error']);
    }
    $update = array('woeid' => $new_woeid);
    $rsp = flickr_photos_update_photo($photo, $update);
    if (!$rsp['ok']) {
        api_output_error(999, $rsp['error']);
    }
    # throw an error if this fails? feels like overkill...
    $correction = array('photo_id' => $photo['id'], 'user_id' => $photo['user_id'], 'old_woeid' => $old_woeid, 'new_woeid' => $new_woeid);
    flickr_photos_geo_corrections_create($correction);
    #
    $place = flickr_places_get_by_woeid($new_woeid);
    $out = array('photo_id' => $photo_id, 'woeid' => $new_woeid, 'place' => $place);
    api_output_ok($out);
}
function flickr_photos_import_photo($photo, $more = array())
{
    $user = flickr_users_ensure_user_account($photo['owner'], $photo['ownername']);
    if (!$user || !$user['id']) {
        return array('ok' => 0, 'error' => 'failed to retrieve user (photo owner)');
    }
    $photo = _flickr_photos_import_prepare_photo($user, $photo);
    # TO DO: error handling...
    echo "add photo {$photo['id']}\n";
    if ($_photo = flickr_photos_get_by_id($photo['id'])) {
        # TO DO: make this less stupid...
        unset($photo['id']);
        flickr_photos_update_photo($_photo, $photo);
        $photo = flickr_photos_get_by_id($_photo['id']);
    } else {
        flickr_photos_add_photo($photo);
        flickr_photos_lookup_add($photo['id'], $photo['user_id']);
    }
    flickr_photos_import_photo_files($photo, $more);
    # exif data
    # why did I do this? (20111206/straup)
    # $more = array(
    # 	'force' => 1,
    # );
    if ($hasexif = flickr_photos_exif_has_exif($photo, $more)) {
        $update = array('hasexif' => 1);
        $rsp = flickr_photos_update_photo($photo, $update);
        # technically we'll have the old last_update date
        # but that shouldn't be a problem (20111121/straup)
        if ($rsp['ok']) {
            $photo = array_merge($photo, $update);
        }
    }
    # things that depend on solr (move to a separate function?)
    if ($GLOBALS['cfg']['enable_feature_solr']) {
        flickr_photos_search_index_photo($photo);
    }
    if ($GLOBALS['cfg']['enable_feature_solr'] && $GLOBALS['cfg']['enable_feature_places']) {
        if ($photo['woeid'] && $GLOBALS['cfg']['places_prefetch_data']) {
            flickr_places_get_by_woeid($photo['woeid']);
        }
    }
    # go!
    return array('ok' => 1, 'photo' => $photo);
}
function flickr_photos_search_index_photo(&$photo, $meta = array())
{
    if (!$GLOBALS['cfg']['enable_feature_solr']) {
        return not_okay('search indexing is disabled');
    }
    if (!$meta) {
        $meta = flickr_photos_metadata_load($photo);
    }
    # really exit or just ignore all the $meta stuff below?
    if (!$meta['ok']) {
        return not_okay('failed to load photo metadata');
    }
    $meta = $meta['data']['photo'];
    $doc = array('id' => $photo['id'], 'user_id' => $photo['user_id'], 'title' => $photo['title'], 'perms' => $photo['perms'], 'datetaken' => solr_dates_prep_mysql_datetime($photo['datetaken']), 'dateupload' => solr_dates_prep_mysql_datetime($photo['dateupload']));
    $tags = array();
    $machinetags = array();
    if (isset($meta['tags']['tag'])) {
        foreach ($meta['tags']['tag'] as $tag) {
            $tags[] = $tag['raw'];
            if ($tag['machinetag']) {
                $machinetags = array_merge($machinetags, solr_machinetags_explode($tag['raw']));
            }
        }
    }
    if (count($tags)) {
        $doc['tags'] = $tags;
    }
    if (count($machinetags)) {
        $doc['machinetags'] = $machinetags;
    }
    if ($photo['hasgeo']) {
        $doc['location'] = "{$photo['latitude']},{$photo['longitude']}";
        $doc['accuracy'] = $photo['accuracy'];
        $doc['geoperms'] = $photo['geoperms'];
        $doc['geocontext'] = $photo['geocontext'];
        foreach (array('neighbourhood', 'locality', 'county', 'region', 'country', 'continent') as $place) {
            if (isset($meta['location'][$place])) {
                $doc[$place] = $meta['location'][$place]['woeid'];
            }
        }
        if ($place = flickr_places_get_by_woeid($photo['woeid'])) {
            $doc['timezone'] = $place['timezone'];
            $doc['place'] = $place['place_url'];
        }
    }
    # pull in some EXIF data (if present)
    $rsp = flickr_photos_exif_read($photo);
    if ($rsp['ok']) {
        $exif = $rsp['rows'];
        if (isset($exif['Make'])) {
            if ($make = exif_tools_scrub_string($exif['Make'])) {
                $doc['camera_make'] = ucwords($make);
            }
        }
        if (isset($exif['Model'])) {
            if ($model = exif_tools_scrub_string($exif['Model'])) {
                $doc['camera_model'] = $model;
            }
        }
        # EXIF: what else?
        if (isset($exif['FocalLength'])) {
            $doc['focal_length'] = exif_tools_rational2float($exif['FocalLength']);
        }
        if (isset($exif['ApetureValue'])) {
            $doc['apeture'] = exif_tools_rational2float($exif['ApetureValue']);
        }
        if (isset($exif['ShutterSpeedValue'])) {
            $doc['shutter_speed'] = exif_tools_rational2float($exif['ShutterSpeedValue']);
        }
        if (isset($exif['ISOSpeedRatings'])) {
            $doc['iso_speed'] = intval($exif['ISOSpeedRatings']);
        }
        # http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/GPS.html
        if (isset($exif['GPSAltitude'])) {
            $altitude = exif_tools_explode_gps_altitude($exif['GPSAltitude'], $exif['GPSAltitudeRef']);
            $doc['altitude'] = $altitude;
        }
        if (isset($exif['GPSImgDirection'])) {
            $direction = exif_tools_explode_gps_img_direction($exif['GPSImgDirection'], $exif['GPSImgDirectionRef']);
            $doc['direction'] = $direction;
        }
    }
    # go!
    $docs = array($doc);
    $rsp = solr_add($docs);
    return $rsp;
}
loadlib("flickr_photos_places");
loadlib("flickr_photos_geo");
if (!$GLOBALS['cfg']['enable_feature_solr'] || !$GLOBALS['cfg']['enable_feature_places']) {
    error_disabled();
}
$flickr_user = flickr_users_get_by_url();
$owner = users_get_by_id($flickr_user['user_id']);
$is_own = $owner['id'] == $GLOBALS['cfg']['user']['id'] ? 1 : 0;
$GLOBALS['smarty']->assign_by_ref("owner", $owner);
$GLOBALS['smarty']->assign("is_own", $is_own);
#
$woeid = get_int32("woeid");
if (!$woeid) {
    error_404();
}
$place = flickr_places_get_by_woeid($woeid);
if (!$place) {
    error_404();
}
$placetypes = flickr_places_valid_placetypes();
$hier = array();
# put this in _get_by_woeid? probably...
foreach ($placetypes as $type) {
    if (isset($place[$type])) {
        $woeid = $place[$type]['woeid'];
        $parts = explode(",", $place[$type]['_content']);
        $name = trim($parts[0]);
        $hier[] = array('woeid' => $woeid, 'placetype' => $type, 'name' => $name);
    }
}
$hier = array_reverse($hier);
Exemplo n.º 5
0
        $more = array('viewer_id' => $GLOBALS['cfg']['user']['id']);
        $bookends = flickr_photos_get_bookends($photo, $more);
    }
}
$GLOBALS['smarty']->assign_by_ref("before", $bookends['before']);
$GLOBALS['smarty']->assign_by_ref("after", $bookends['after']);
# meta, geo, etc.
# $meta = flickr_photos_metadata_load($photo);
# $GLOBALS['smarty']->assign_by_ref("metadata", $meta['data']);
$photo['can_view_geo'] = $photo['hasgeo'] && flickr_geo_permissions_can_view_photo($photo, $GLOBALS['cfg']['user']['id']) ? 1 : 0;
if ($photo['can_view_geo']) {
    $geo_perms_map = flickr_geo_permissions_map();
    $photo['str_geoperms'] = $geo_perms_map[$photo['geoperms']];
    # NOTE: this has the potential to slow things down if the
    # Flickr API is being wonky. On the other hand if you're
    # just running this for yourself (or maybe a handful of
    # friends) it shouldn't be a big deal. Also, caching.
    if ($place = flickr_places_get_by_woeid($photo['woeid'])) {
        $GLOBALS['smarty']->assign_by_ref("place", $place);
    }
}
if ($GLOBALS['cfg']['user']['id']) {
    $perms_map = flickr_api_authtoken_perms_map();
    # the currently logged in viewer
    $_flickr_user = flickr_users_get_by_user_id($GLOBALS['cfg']['user']['id']);
    $perms = $_flickr_user['token_perms'];
    $has_write_token = $perms_map[$perms] == 'write' ? 1 : 0;
    $GLOBALS['smarty']->assign('has_write_token', $has_write_token);
}
$GLOBALS['smarty']->display("page_flickr_photo.txt");
exit;