You are here

function signature_forum_user in Signatures for Forums 5

Same name and namespace in other branches
  1. 5.2 signature_forum.module \signature_forum_user()
  2. 6 signature_forum.module \signature_forum_user()

Implementation of hook_user().

File

./signature_forum.module, line 198

Code

function signature_forum_user($op, &$edit, &$account, $category = NULL) {

  // Re-route the user signature to this module's signature table
  switch ($op) {
    case 'submit':

      // If the user has a signature set update it, otherwise create a new entry
      if (db_result(db_query('SELECT uid FROM {users_signature} WHERE uid=%d', $account->uid)) != '') {
        db_query('UPDATE {users_signature} SET signature=\'%s\' WHERE uid=%d', array(
          $edit['signature'],
          $account->uid,
        ));
      }
      else {
        db_query('INSERT INTO {users_signature} (uid, signature) VALUES (%d, \'%s\')', array(
          $account->uid,
          $edit['signature'],
        ));
      }
      unset($edit['signature']);
      break;
    case 'load':
      $signature = db_result(db_query('SELECT signature FROM {users_signature} WHERE uid=%d', $account->uid));

      // Bug #190446 OG puts $account->signature into comments
      $account->signature_forum = $signature;
      break;
    case 'validate':
      $settings = variable_get('signature_forum_settings', signature_forum_defaults());

      // If the signature contains too many lines
      if ($settings['signature_forum_line_limit'] > 0 && substr_count($edit['signature'], "\n") > $settings['signature_forum_line_limit']) {
        form_set_error('signature', t('Maximum number of !max_lines lines allowed in signature exceeded.', array(
          '!max_lines' => $settings['signature_forum_line_limit'],
        )));
      }
      break;
  }
}