function flickr_geo_permissions_photos_where($owner_id, $viewer_id = 0) { if ($owner_id == $viewer_id) { return ''; } $perms_map = flickr_geo_permissions_map('string keys'); if ($viewer_id == 0) { $perms = array($perms_map['public']); } else { if ($contact = flickr_contacts_get_contact($owner_id, $viewer_id)) { $rel_map = flickr_contacts_relationship_map(); $str_rel = $rel_map[$contact['rel']]; $perms = array($perms_map['public'], $perms_map['contacts']); if ($str_rel == 'friends') { $perms[] = $perms_map['friends']; $perms[] = $perms_map['friends and family']; } else { if ($str_rel == 'family') { $perms[] = $perms_map['family']; $perms[] = $perms_map['friends and family']; } else { } } } else { $perms = array($perms_map['public']); } } return $perms; }
function flickr_geobookmarks_import_for_nsid($nsid, $more = array()) { $flickr_user = flickr_users_get_by_nsid($nsid); $user = users_get_by_id($flickr_user['user_id']); if (!$user) { return not_okay("Not a valid user"); } $flickr_user = flickr_users_get_by_user_id($user['id']); $method = 'flickr.people.geoBookmarks.getList'; $args = array('auth_token' => $flickr_user['auth_token']); $rsp = flickr_api_call($method, $args); if (!$rsp['ok']) { return $rsp; } if (!$rsp['rsp']['bookmarks']['count']) { return okay(); } $bookmarks = array(); # mark everything as private for now since none of that stuff # got turned on before I left, sad face... (20120217/straup) $geo_perms = flickr_geo_permissions_map("string keys"); $geo_private = $geo_perms['private']; foreach ($rsp['rsp']['bookmarks']['bookmark'] as $bm) { $bm['user_id'] = $user['id']; $bm['name'] = $bm['label']; $bm['geocontext'] = $bm['context']; $bm['geoperms'] = $geo_private; $bm['woeid'] = 0; unset($bm['label']); unset($bm['pretty_name']); unset($bm['context']); $geo_method = 'flickr.places.findByLatLon'; $geo_args = array('lat' => $bm['latitude'], 'lon' => $bm['longitude'], 'accuracy' => $bm['accuracy']); $geo_rsp = flickr_api_call($geo_method, $geo_args); if ($geo_rsp['ok']) { # I still miss xpath... $bm['woeid'] = $geo_rsp['rsp']['places']['place'][0]['woeid']; } $bookmarks[] = $bm; } $rsp = flickr_geobookmarks_purge_for_user($user); if (!$rsp['ok']) { return $rsp; } $count = 0; foreach ($bookmarks as $bm) { $rsp = flickr_geobookmarks_add($bm); $count += $rsp['ok']; } return okay(array('count_imported' => $count)); }
function _flickr_photos_import_prepare_photo(&$user, $photo) { $photo['user_id'] = $user['id']; unset($photo['owner']); unset($photo['ownername']); $fmt = "Y-m-d H:i:s"; $photo['dateupload'] = gmdate($fmt, $photo['dateupload']); $ispublic = $photo['ispublic'] ? 1 : 0; $isfamily = $photo['isfamily'] ? 1 : 0; $isfriend = $photo['isfriend'] ? 1 : 0; $perms_map = flickr_photos_permissions_map("string keys"); if ($ispublic) { $perms = $perms_map['public']; } else { if ($isfamily && $isfriend) { $perms = $perms_map['friends and family']; } else { if ($isfamily) { $perms = $perms_map['family']; } else { if ($isfriend) { $perms = $perms_map['friends']; } else { $perms = $perms_map['private']; } } } } $photo['perms'] = $perms; # echo "{$photo['id']} perms:{$perms} public:{$ispublic} friend:{$isfriend} family:{$isfamily}\n"; unset($photo['ispublic']); unset($photo['isfamily']); unset($photo['isfriend']); # media (status) $photo['media'] = $photo['media'] == 'photo' ? 0 : 1; unset($photo['media_status']); # Strictly speaking, I am probably most responsible for # the need to do this. I'm sorry... (20111121/straup) $photo['hasgeo'] = $photo['accuracy'] ? 1 : 0; if (!$photo['hasgeo']) { unset($photo['latitude']); unset($photo['longitude']); unset($photo['accuracy']); } if ($photo['hasgeo']) { $geo_perms_map = flickr_geo_permissions_map("string keys"); if ($photo['geo_is_public']) { $geoperms = $geo_perms_map['public']; } else { if ($photo['geo_is_contact']) { $geoperms = $geo_perms_map['contacts']; } else { if ($photo['geo_is_family'] && $photo['geo_is_friend']) { $geoperms = $geo_perms_map['friends and family']; } else { if ($photo['geo_is_friend']) { $geoperms = $geo_perms_map['friends']; } else { if ($photo['geo_is_family']) { $geoperms = $geo_perms_map['family']; } else { $geoperms = $geo_perms_map['private']; } } } } } $photo['geoperms'] = $geoperms; $photo['geocontext'] = $photo['context']; unset($photo['place_id']); unset($photo['geo_is_family']); unset($photo['geo_is_friend']); unset($photo['geo_is_contact']); unset($photo['geo_is_public']); } if (isset($photo['context'])) { unset($photo['context']); } if (isset($photo['date_faved'])) { unset($photo['date_faved']); } return $photo; }
} else { if ($context == 'place') { # please write me } else { $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;