function signature_forum_user in Signatures for Forums 6
Same name and namespace in other branches
- 5.2 signature_forum.module \signature_forum_user()
- 5 signature_forum.module \signature_forum_user()
Implementation of hook_user().
File
- ./
signature_forum.module, line 320 - Tweaks signatures in ways inspired by other traditional forum software:
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':
// Check if the signature is set in the form
// (#276349 - Signature deleted when editing profile).
if (!isset($edit['signature'])) {
break;
}
// 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)) != FALSE) {
db_query("UPDATE {users_signature} SET signature = '%s', status = %d WHERE uid = %d", array(
$edit['signature'],
$edit['signature_default_status'],
$account->uid,
));
}
else {
db_query("INSERT INTO {users_signature} (uid, signature, status) VALUES (%d, '%s', %d)", array(
$account->uid,
$edit['signature'],
$edit['signature_default_status'],
));
}
unset($edit['signature']);
break;
case 'load':
$signature = db_fetch_object(db_query("SELECT signature, status FROM {users_signature} WHERE uid = %d", $account->uid));
// Bug #190446 OG puts $account->signature into comments
$account->signature_forum = isset($signature->signature) ? $signature->signature : '';
$account->signature_default_status = isset($signature->status) ? $signature->status : 1;
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'],
)));
}
if ($settings['signature_forum_char_limit'] > 0 && drupal_strlen($edit['signature']) > $settings['signature_forum_char_limit']) {
form_set_error('signature', t('Maximum number of @max_chars characters allowed in signature exceeded.', array(
'@max_chars' => $settings['signature_forum_char_limit'],
)));
}
break;
}
}