function drupagram_account_save in Drupagram 6
Same name and namespace in other branches
- 7 drupagram.inc \drupagram_account_save()
Saves a InstagramUser object to {drupagram_account}
3 calls to drupagram_account_save()
- drupagram_account_form_submit in ./
drupagram.pages.inc - Implements hook_FORM_ID_submit()
- drupagram_account_list_form_submit in ./
drupagram.pages.inc - drupagram_oauth_callback_form_submit in ./
drupagram.pages.inc - Handle a Instagram OAuth return request and store the account creds in the DB. Redirects to user/%/edit/drupagram
File
- ./
drupagram.inc, line 30 - Instagram API functions
Code
function drupagram_account_save($drupagram_user, $save_auth = FALSE, $account = NULL) {
$values = (array) $drupagram_user;
if (empty($drupagram_user)) {
return FALSE;
}
$values['drupagram_id'] = $values['id'];
if ($save_auth) {
$values += $drupagram_user
->get_auth();
if (empty($account)) {
global $user;
$account = $user;
}
$values['uid'] = $account->uid;
}
$schema = drupal_get_schema('drupagram_account');
foreach ($values as $k => $v) {
if (!isset($schema['fields'][$k])) {
unset($values[$k]);
}
elseif (isset($schema['fields'][$k]['not null']) && $schema['fields'][$k]['not null'] && empty($values[$k])) {
$values[$k] = isset($schema['fields'][$k]['default']) ? drupagram_emoji($schema['fields'][$k]['default']) : '';
}
}
$drupagram_users_count = db_result(db_query("SELECT count(da.drupagram_id) FROM {drupagram_account} da WHERE da.drupagram_id = %d", $values['drupagram_id']));
$values = array_filter($values, "strlen");
$values = (object) $values;
if ($drupagram_users_count) {
drupal_write_record("drupagram_account", $values, "drupagram_id");
}
else {
drupal_write_record("drupagram_account", $values);
}
}