Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrap contacts import in to the general flickr_backups bucket; rename …
…get_contacts as backup_contacts
- Loading branch information
1 parent
a81f49f
commit 8ac8b7f
Showing
5 changed files
with
211 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
$root = dirname(dirname(__FILE__)); | ||
ini_set("include_path", "{$root}/www:{$root}/www/include"); | ||
|
||
# | ||
|
||
include("include/init.php"); | ||
loadlib("flickr_backups"); | ||
|
||
foreach (flickr_backups_users() as $user){ | ||
$rsp = flickr_backups_get_contacts($user); | ||
dumper($rsp); | ||
} | ||
|
||
exit(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
loadlib("flickr_api"); | ||
loadlib("flickr_users"); | ||
loadlib("flickr_contacts"); | ||
loadlib("random"); | ||
|
||
################################################################# | ||
|
||
function flickr_contacts_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 array( | ||
'ok' => 0, | ||
'error' => 'not a valid user', | ||
); | ||
} | ||
|
||
$method = 'flickr.contacts.getList'; | ||
$count_contacts = 0; | ||
|
||
$args = array( | ||
'auth_token' => $flickr_user['auth_token'], | ||
'per_page' => 100, | ||
'page' => 1, | ||
); | ||
|
||
$pages = null; | ||
|
||
while ((! isset($pages)) || ($pages >= $args['page'])){ | ||
|
||
$rsp = flickr_api_call($method, $args); | ||
|
||
if (! $rsp){ | ||
return array( | ||
'ok' => 0, | ||
'error' => 'The Flickr API is wigging out...', | ||
); | ||
} | ||
|
||
if (! isset($pages)){ | ||
$pages = $rsp['rsp']['contacts']['pages']; | ||
} | ||
|
||
$contacts = $rsp['rsp']['contacts']['contact']; | ||
|
||
if (! is_array($contacts)){ | ||
return array( | ||
'ok' => 0, | ||
'error' => 'The Flickr API did not return any contacts', | ||
); | ||
} | ||
|
||
foreach ($contacts as $contact){ | ||
|
||
$contact_nsid = $contact['nsid']; | ||
$contact_username = $contact['username']; | ||
|
||
$flickr_contact = flickr_users_get_by_nsid($contact_nsid); | ||
|
||
if (! $flickr_contact){ | ||
|
||
$password = random_string(32); | ||
|
||
$user_contact = users_create_user(array( | ||
"username" => $contact_username, | ||
"email" => "{$contact_username}@donotsend-flickr.com", | ||
"password" => $password, | ||
)); | ||
|
||
$flickr_contact = flickr_users_create_user(array( | ||
'user_id' => $user_contact['id'], | ||
'nsid' => $contact_nsid, | ||
# note the lack of an auth_token | ||
)); | ||
} | ||
|
||
$rel = flickr_contacts_calculate_relationship($contact); | ||
|
||
$insert = array( | ||
'user_id' => $user['id'], | ||
'contact_id' => $flickr_contact['user_id'], | ||
'rel' => $rel, | ||
); | ||
|
||
$contact = flickr_contacts_add_contact($insert); | ||
$count_contacts ++; | ||
} | ||
|
||
$args['page'] += 1; | ||
} | ||
|
||
return array( | ||
'ok' => 1, | ||
'count_imported' => $count_contacts, | ||
); | ||
} | ||
|
||
################################################################# | ||
|
||
?> |