function flickr_photos_exif_has_exif(&$photo, $more = array())
{
    if (isset($photo['hasexif']) && !isset($more['force'])) {
        return $photo['hasexif'];
    }
    $rsp = flickr_photos_exif_read($photo);
    return $rsp['ok'];
}
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;
}
include "include/init.php";
loadlib("flickr_photos");
loadlib("flickr_photos_exif");
# ensure logged in; parse out photo url
$photo_id = get_int64("id");
$path = get_str("path");
$url = "/photos/{$path}/{$photo_id}/";
login_ensure_loggedin($url);
#
$photo = flickr_photos_get_by_id($photo_id);
if (!$photo['id']) {
    error_404();
}
if ($photo['user_id'] != $GLOBALS['cfg']['user']['id']) {
    error_403();
}
if ($photo['deleted']) {
    $GLOBALS['smarty']->display("page_photo_deleted.txt");
    exit;
}
$GLOBALS['smarty']->assign_by_ref("photo", $photo);
#
$rsp = flickr_photos_exif_read($photo);
if ($rsp['ok']) {
    $GLOBALS['smarty']->assign_by_ref("exif", $rsp['rows']);
} else {
    $GLOBALS['smarty']->assign("error", $rsp['error']);
}
$GLOBALS['smarty']->display("page_flickr_photo_exif.txt");
exit;