| 1 |
<?php
|
| 2 |
// $Id: contactlink.module,v 1.5 2007/12/06 09:27:12 mikeyp Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_link().
|
| 6 |
*/
|
| 7 |
function contactlink_link($type, $object = 0, $main = 0) {
|
| 8 |
global $user;
|
| 9 |
$links = array();
|
| 10 |
// Only show link to authenticated users, because user contact
|
| 11 |
// is not available to anonymous users.
|
| 12 |
if ($user->uid && in_array($type, array('node', 'comment')) && ($type != 'node' || variable_get('contactlink_'. $object->type, 1)) && $account = user_load(array('uid' => $object->uid))) {
|
| 13 |
if ($account->contact && ($account->uid != $user->uid)) {
|
| 14 |
$links['contactlink'] = array(
|
| 15 |
'title' => t('Contact the author'),
|
| 16 |
'href' => "user/$object->uid/contact",
|
| 17 |
'attributes' => array('title' => t('Email the author via the contact form.')),
|
| 18 |
);
|
| 19 |
}
|
| 20 |
}
|
| 21 |
return $links;
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_form_alter().
|
| 26 |
*/
|
| 27 |
function contactlink_form_alter(&$form, $form_state, $form_id) {
|
| 28 |
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
|
| 29 |
$form['workflow']['contactlink'] = array(
|
| 30 |
'#type' => 'radios',
|
| 31 |
'#title' => t('Show "contact the author" link for this content type'),
|
| 32 |
'#default_value' => variable_get('contactlink_'. $form['#node_type']->type, 1),
|
| 33 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 34 |
);
|
| 35 |
}
|
| 36 |
}
|