You are here

function flickr_user in Flickr 5

Same name and namespace in other branches
  1. 6 flickr.module \flickr_user()

Implimentation of the hook_user() Add an extra field for the user to enter his flickr identifier.

File

./flickr.module, line 210

Code

function flickr_user($op, &$edit, &$account, $category = NULL) {
  if ($op == 'form') {
    if ($category == 'account') {
      $user = user_load(array(
        'uid' => $account->uid,
      ));
      $form['flickr'] = array(
        '#type' => 'fieldset',
        '#title' => t('Flickr settings'),
        '#collapsible' => FALSE,
        '#weight' => 4,
        '#tree' => FALSE,
      );
      $form['flickr']['flickr_identifier'] = array(
        '#type' => 'textfield',
        '#title' => t('Flickr identifier'),
        '#default_value' => $user->flickr['identifier'],
        '#description' => t('Enter either your Flickr username, the email address associated with your Flickr account, or your Flickr NSID. Leave this box empty to delete your Flickr page on this site.'),
        '#maxlength' => 64,
      );
      return $form;
    }
  }
  elseif ($op == 'validate') {
    if (!empty($edit['flickr_identifier'])) {
      if (!flickr_user_find_by_identifier($edit['flickr_identifier'])) {
        form_set_error('flickr_identifier', t('%ident is not a valid Flickr username, email, or NSID.', array(
          '%ident' => $edit['flickr_identifier'],
        )));
      }
    }
  }
  elseif ($op == 'insert' || $op == 'update') {
    if (isset($edit['flickr_identifier'])) {
      db_query('DELETE FROM {flickr_users} WHERE uid=%d', $account->uid);
      $user_affected = db_affected_rows();
      if (!empty($edit['flickr_identifier'])) {
        db_query("INSERT INTO {flickr_users} (uid, nsid, identifier) VALUES (%d, '%s', '%s')", $account->uid, flickr_user_find_by_identifier($edit['flickr_identifier']), $edit['flickr_identifier']);
      }
      else {
        if ($user_affected) {

          //flickr account deleted
          drupal_set_message(t("%username's Flickr page has been deleted.", array(
            '%username' => $account->name,
          )));
        }
      }
    }
    $edit['flickr_identifier'] = NULL;
  }
  elseif ($op == 'load') {
    $result = db_query('SELECT * FROM {flickr_users} WHERE uid=%d', $account->uid);
    if (db_num_rows($result) > 0) {
      $flickr_info = db_fetch_object($result);
      $account->flickr['identifier'] = $flickr_info->identifier;
      $account->flickr['nsid'] = $flickr_info->nsid;
    }
  }
  elseif ($op == 'delete') {
    db_query('DELETE FROM {flickr_users} WHERE uid=%d', $account->uid);
  }
}