function api_utils_flickr_ensure_token_perms(&$user, $str_perms) { $perms_map = flickr_api_authtoken_perms_map(); $flickr_user = flickr_users_get_by_user_id($user['id']); if ($perms_map[$flickr_user['token_perms']] != $str_perms) { api_output_error(999, "Insufficient Flickr API permissions"); } return $flickr_user; }
$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;
<?php include "include/init.php"; loadlib("flickr_api"); loadlib("flickr_users"); login_ensure_loggedin($_SERVER['REQUEST_URI']); $flickr_user = flickr_users_get_by_user_id($GLOBALS['cfg']['user']['id']); $crumb_key = 'flickr_auth_token'; $GLOBALS['smarty']->assign("crumb_key", $crumb_key); $perms = request_str("perms"); $perms_map = flickr_api_authtoken_perms_map(); $perms_map_str = flickr_api_authtoken_perms_map('string keys'); $GLOBALS['smarty']->assign_by_ref("perms_map", $perms_map); if (!$perms) { $perms = 'read'; } elseif (!isset($perms_map_str[$perms])) { $GLOBALS['error'] = 'invalid_perm'; $GLOBALS['smarty']->display("page_account_flickr_auth.txt"); exit; } else { } if ($flickr_user['auth_token']) { # Perms are the same; just carry on... if ($flickr_user['token_perms'] == $perms_map_str[$perms]) { $redir = get_str("redir"); if (!$redir) { $redir = $GLOBALS['cfg']['abs_root_url']; } header("location: {$redir}"); exit; }
function flickr_users_has_token_perms(&$flickr_user, $string_perms) { $flickr_perms = $flickr_user['token_perms']; $perms_map = flickr_api_authtoken_perms_map("string keys"); return $flickr_perms >= $perms_map[$string_perms] ? 1 : 0; }