function flickr_photos_import_photo($photo, $more = array()) { log_info("get ready to import a photo..."); $user = flickr_users_ensure_user_account($photo['owner'], $photo['ownername']); if (!$user || !$user['id']) { return not_okay("failed to retrieve user (photo owner)"); } $photo = _flickr_photos_import_prepare_photo($user, $photo); # log_info("photo..." . var_export($photo, 1)); # TO DO: error handling... if ($_photo = flickr_photos_get_by_id($photo['id'])) { log_info("update photo {$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 { log_info("add photo {$photo['id']}"); $rsp = flickr_photos_add_photo($photo); if (!$rsp['ok']) { log_info("FAILED to add photo {$photo['id']} :" . var_export($rsp, 1)); return $rsp; } 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 okay(array('photo' => $photo)); }
function check_photo($row, $more = array()) { $photo = flickr_photos_get_by_id($row['id']); $more = array('force' => 1); $hasexif = flickr_photos_exif_has_exif($photo, $more); # echo "photo {$photo['id']} has exif: {$hasexif}\n"; if ($hasexif) { $update = array('hasexif' => 1); $rsp = flickr_photos_update_photo($photo, $update); if (!$rsp['ok']) { echo "ack! failed to update {$photo['id']}: {$rsp['error']}\n"; } } }
function flickr_photos_search(&$query, $more = array()) { if (!$GLOBALS['cfg']['enable_feature_solr']) { return not_okay('search indexing is disabled'); } # OMGWTF: When sorting by date_taken|posted the results # are basically anything but sorted. It's unclear to me # whether this is a known Lucene thing or ... what? I # suppose it might make sense to store dates as INTs but # then we lose the ability to do date facteing, for calendar # pages sometime in the future. So for now we'll just sort # by photo ID since it accomplishes the same thing... # (20111121/straup) # # see also: http://phatness.com/2009/11/sorting-by-date-with-solr/ $defaults = array('viewer_id' => 0, 'sort' => 'id desc'); $more = array_merge($defaults, $more); $q = solr_utils_hash2query($query, " AND "); $params = array('q' => $q, 'sort' => $more['sort']); $owner_id = isset($query['user_id']) ? $query['user_id'] : 0; if ($fq = _flickr_photos_search_perms_fq($owner_id, $more['viewer_id'], $more)) { $params['fq'] = $fq; } $rsp = solr_select($params, $more); if (!$rsp['ok']) { return $rsp; } $photos = array(); foreach ($rsp['rows'] as $row) { $photo = flickr_photos_get_by_id($row['id']); $can_view_geo = $photo['hasgeo'] && flickr_geo_permissions_can_view_photo($photo, $more['viewer_id']) ? 1 : 0; $photo['can_view_geo'] = $can_view_geo; $photos[] = $photo; } $rsp['rows'] = $photos; return $rsp; }
function index_photo($row, $more = array()) { $photo = flickr_photos_get_by_id($row['id']); $rsp = flickr_photos_search_index_photo($photo); }
<?php include "include/init.php"; loadlib("flickr_photos"); loadlib("flickr_photos_metadata"); loadlib("flickr_photos_permissions"); loadlib("flickr_geo_permissions"); loadlib("flickr_users"); loadlib("flickr_urls"); loadlib("flickr_places"); $photo_id = get_int64("id"); if (!$photo_id) { error_404(); } $photo = flickr_photos_get_by_id($photo_id); if (!$photo['id']) { error_404(); } # This is two things. One, a quick and dirty hack to ensure # that we display a notice if the path alias (on Flickr) has # been taken by a local user. See notes in flickr_users_get_by_url # and note that we are explicitly setting the "do not 404" flag # here. Two, make sure the photo is actually owned by the user # pointed to by the path alias or NSID. (20111203/straup) $flickr_user = flickr_users_get_by_url(0); if ($flickr_user['user_id'] != $photo['user_id']) { error_404(); } if ($photo['deleted']) { $GLOBALS['smarty']->display("page_photo_deleted.txt"); exit;
if ($by_flickr_user = flickr_users_get_by_path_alias($by_alias)) { $more['by_owner'] = users_get_by_id($by_flickr_user['user_id']); } } else { if ($by_nsid = get_str("by_nsid")) { if ($by_flickr_user = flickr_users_get_by_nsid($by_nsid)) { $more['by_owner'] = users_get_by_id($by_flickr_user['user_id']); } } else { } } $by_owner = isset($more['by_owner']) ? $more['by_owner'] : null; $faves = flickr_faves_for_user($owner, $more); $photos = array(); foreach ($faves['rows'] as $f) { $photo = flickr_photos_get_by_id($f['photo_id']); $photo['owner'] = users_get_by_id($photo['user_id']); # quick hack until perms are denormalized into the FlickrFaves table $photo['canview'] = flickr_photos_permissions_can_view_photo($photo, $viewer['id']); # going to leave this disable until I figure out what to # do about reciprical contacts hoohah... if ($is_own) { $photo['canview'] = 1; } $photos[] = $photo; } $GLOBALS['smarty']->assign_by_ref("owner", $owner); $GLOBALS['smarty']->assign_by_ref("by_owner", $by_owner); $GLOBALS['smarty']->assign_by_ref("photos", $photos); $pagination_url = flickr_urls_faves_user($owner, $by_owner); $GLOBALS['smarty']->assign("pagination_url", $pagination_url);
function _api_flickr_photos_geo_get_photo($photo_id, $ensure_is_own = 1) { if (!$photo_id) { api_output_error(999, "Missing photo ID"); } $photo = flickr_photos_get_by_id($photo_id); if (!$photo['id']) { api_output_error(999, "Invalid photo ID"); } if ($ensure_is_own && $photo['user_id'] != $GLOBALS['cfg']['user']['id']) { api_output_error(999, "Insufficient permissions"); } if (!$photo['hasgeo']) { api_output_error(999, "Photo is not geotagged"); } return $photo; }
function flickr_photos_for_user(&$user, $more = array()) { $defaults = array('viewer_id' => 0); $more = array_merge($defaults, $more); $cluster_id = $user['cluster_id']; $enc_user = AddSlashes($user['id']); $extra = array(); if ($perms = flickr_photos_permissions_photos_where($user['id'], $more['viewer_id'])) { $str_perms = implode(",", $perms); $extra[] = "perms IN ({$str_perms})"; } $extra = implode(" AND ", $extra); if (strlen($extra)) { $extra = " AND {$extra}"; } $sql = "SELECT * FROM FlickrPhotos WHERE user_id='{$enc_user}' {$extra} ORDER BY dateupload DESC"; if (isset($more['with'])) { # Here, we are asking for a the page which a particular photo occurs in a person's stream, which # means we'll be passing in the determining the page number ourselves. We do this by figuring out # how many photos are before this one in the stream and then dividing. $photo = flickr_photos_get_by_id($more['with']); $can_see_photo = $photo ? flickr_photos_permissions_can_view_photo($photo, $GLOBALS['cfg']['user']['id']) : false; if ($can_see_photo) { # The only reason we need this is for spill messing with per-page amounts $pagination_more = $more; $pagination_more['just_pagination'] = 1; $pagination = db_fetch_paginated_users($cluster_id, $sql, $pagination_more); $offset_where = " AND dateupload >= '{$photo['dateupload']}'"; $offset_sql = "SELECT COUNT(*) FROM FlickrPhotos WHERE user_id='{$enc_user}' {$extra} {$offset_where} ORDER BY dateupload DESC"; $ret = db_fetch_users($cluster_id, $offset_sql); if ($ret['ok']) { $offset_count = intval(array_pop($ret['rows'][0])); $per_page = isset($more['per_page']) ? max(1, $more['per_page']) : $GLOBALS['cfg']['pagination_per_page']; $page = ceil($offset_count / $per_page); if ($page > $pagination['page_count']) { $page--; } $more['page'] = $page; } } } return db_fetch_paginated_users($cluster_id, $sql, $more); }