summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStein Magne Bjorklund2017-06-21 00:02:37 (GMT)
committerStein Magne Bjorklund2017-06-21 00:32:14 (GMT)
commit628d70fa3f906c43e3e5decc783f7bedcd44a0e0 (patch)
tree567b4e2b425bb31f864f9f4baea0a1e145ba8652
parentabbd7fc3d7b298f6f0d86e198c80ba34b49d1767 (diff)
Issue #1490012 by steinmb: Locate user id by photo or sets/albums.
After Flickr include the users name and not the user id in the url is it probably more accurate to locate the user id by checking the photo or album/photoset.
-rw-r--r--includes/media_flickr.utilities.inc41
1 files changed, 27 insertions, 14 deletions
diff --git a/includes/media_flickr.utilities.inc b/includes/media_flickr.utilities.inc
index 9096d18..924f2a9 100644
--- a/includes/media_flickr.utilities.inc
+++ b/includes/media_flickr.utilities.inc
@@ -202,23 +202,33 @@ function _media_flickr_photoset_exists($photoset_id) {
/**
* Find user ID based on Flickr user name.
*
- * @param $user_name
+ * @param array $parts
*
- * @return mixed
+ * @return string user NSID
+ * Return Flickr NSID. If nothing found, returns FALSE.
*/
-function _media_flickr_get_user_id($user_name) {
- $info = _media_flickr_sets_request('flickr.people.getInfo', array('user_id' => $user_name));
+function _media_flickr_get_user_id($parts) {
+ $user_id = '';
- if ($info && ($info['@attributes']['stat'] != 'fail')) {
- return $user_name;
+ if (isset($parts['p'])) {
+ $media_id = $parts['p'];
+ $media_info = _media_flickr_sets_request('flickr.photos.getInfo',
+ ['photo_id' => $media_id]);
+ if ($media_info['@attributes']['stat'] != 'fail') {
+ $user_id = $media_info['photo']['owner']['@attributes']['nsid'];
+ }
}
- elseif ($info['err']['@attributes']['code'] == 1) {
- // See if we were passed a username instead.
- $info = _media_flickr_sets_request('flickr.people.findByUsername', array('username' => $user_name));
- if ($info && $info['@attributes']['stat'] != 'fail') {
- return $info['user']['@attributes']['id'];
+
+ if (isset($parts['s'])) {
+ $media_id = $parts['s'];
+ $media_info = _media_flickr_sets_request('flickr.photosets.getInfo',
+ ['photoset_id' => $media_id]);
+ if ($media_info['@attributes']['stat'] != 'fail') {
+ $user_id = $media_info['photoset']['@attributes']['owner'];
}
}
+
+ return $user_id;
}
/**
@@ -227,13 +237,16 @@ function _media_flickr_get_user_id($user_name) {
* @return string
*/
function _media_flickr_build_uri($parts) {
+ $user_name = '';
if (isset($parts['u'])) {
$user_name = $parts['u'];
- $user_id = _media_flickr_get_user_id($user_name);
- $parts['u'] = isset($user_id) ? $user_id : $parts['u'];
+ $user_id = _media_flickr_get_user_id($parts);
+ if ($user_id) {
+ $parts['u'] = isset($user_id) ? $user_id : $parts['u'];
+ }
}
- if (isset($parts['u'])) {
+ if ($user_name) {
if (isset($parts['p'])) {
$uri = file_stream_wrapper_uri_normalize('flickr://u/' . $parts['u'] . "/p/" . $parts['p']);
if (_media_flickr_photo_exists($parts['p'])) {