function _get_nsid($flickr_user, $more = array()) { # TO DO: put this all in a function somewhere and # call/queue it when a user signs up... # As db_main:Users $user = users_get_by_id($flickr_user['user_id']); if (!$user) { return; } $method = 'flickr.people.getInfo'; $args = array('user_id' => $flickr_user['nsid']); $ret = flickr_api_call($method, $args); if (!$ret['ok']) { dumper($args); dumper($ret); return; } $rsp = $ret['rsp']['person']; $path_alias = $rsp['path_alias']; $username = $rsp['username']['_content']; echo "[{$user['id']}] path alias: {$path_alias} screen name: {$username}\n"; if ($path_alias != $flickr_user['path_alias']) { $update = array('path_alias' => $path_alias); $rsp = flickr_users_update_user($flickr_user, $update); echo "[{$user['id']}] update path alias: {$rsp['ok']}\n"; # just let this fail silently if there's a duplicate flickr_users_path_aliases_create($user, $path_alias); } if ($username != $user['username']) { $update = array('username' => $username); $rsp = users_update_user($user, $update); echo "[{$user['id']}] update username: {$rsp['ok']}\n"; } }
function set_path_alias($flickr_user, $more = array()) { if ($flickr_user['path_alias'] == '') { return; } $user = users_get_by_id($flickr_user['user_id']); flickr_users_path_aliases_create($user, $flickr_user['path_alias']); }
function flickr_users_create_user($flickr_user) { $hash = array(); foreach ($flickr_user as $k => $v) { $hash[$k] = AddSlashes($v); } $rsp = db_insert('FlickrUsers', $hash); if (!$rsp['ok']) { return null; } # hey look! this is parallel-flickr specific and not part # of flamework-flickrapp (20111202/straup) # just add the path_alias to the FlickrUsersPathAliases # table even if the feature flag is disabled so that it # will do the right thing if/when it is enabled. # (20111202/straup) if ($flickr_user['path_alias']) { loadlib("flickr_users_path_aliases"); $user = users_get_by_id($flickr_user['user_id']); $rsp = flickr_users_path_aliases_create($user, $flickr_user['path_alias']); # Okay, so this (mysql's duplicate key (1062) error) means that a # parallel-flickr user has managed to change their path alias to be # the same as something that a person on flickr chose *after* the # local user changed their path alias. So, because parallel-flickr # is not meant to be a global mirror of the entirety of flickr we're # going to flag the record for $flickr_user and update lib_flickr_urls # to only ever use that user's NSID when building URLs. This is not # a perfect solution in that if you did a GET on the path_alias in # question it would redirect to the local user who "stole" the path # alias from the (newer) flickr user but in a perverse kind of way it # is the right thing to do. But only if path_alias redirects are enabled # which is why we always store what flickr tells us against the FlickrUsers # table. (20111202/straup) if (!$rsp['ok'] && $rsp['error_code'] == 1062) { $alias = flickr_users_path_aliases_get_by_alias($flickr_user['path_alias']); # unless of course the two users are the same, which shouldn't # ever happen but that's what makes life interesting, right? if ($alias['user_id'] != $flickr_user['user_id']) { $update = array('path_alias_taken_by' => $alias['user_id']); $update_rsp = flickr_users_update_user($flickr_user, $update); # note the caching below if ($update_rsp['ok']) { $flickr_user = array_merge($flickr_user, $update); } } } } $cache_key = "flickr_user_{$flickr_user['nsid']}"; cache_set($cache_key, $flickr_user, "cache locally"); $cache_key = "flickr_user_{$flickr_user['user_id']}"; cache_set($cache_key, $flickr_user, "cache locally"); return $flickr_user; }
$crumb_ok = crumb_check($crumb_key); if ($crumb_ok) { $ok = 1; $new_alias = post_str("path_alias"); $new_alias = filter_strict($new_alias); $new_alias = trim($new_alias); if (!$new_alias) { $GLOBALS['smarty']->assign("error", "invalid alias"); $ok = 0; } if ($ok && !flickr_users_path_aliases_is_available($new_alias)) { $GLOBALS['smarty']->assign("error", "alias taken"); $ok = 0; } if ($ok) { if (post_str("confirm")) { $rsp = flickr_users_path_aliases_create($GLOBALS['cfg']['user'], $new_alias); if (!$rsp['ok']) { $GLOBALS['smarty']->assign("error", "db error"); $ok = 0; } } else { $GLOBALS['smarty']->assign("step", "confirm"); $GLOBALS['smarty']->assign("path_alias", $new_alias); } } } $aliases = flickr_users_path_aliases_for_user($GLOBALS['cfg']['user']); $GLOBALS['smarty']->assign_by_ref("aliases", $aliases['rows']); $GLOBALS['smarty']->display("page_account_path_aliases.txt"); exit;