| 1 |
<?php
|
| 2 |
// $Id: nodeauthor.module,v 1.3 2007/11/30 16:01:08 meba Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Nodeauthor module which displays additional author info.
|
| 7 |
*
|
| 8 |
* Nodeauthor module allows users to set their authoring information in user
|
| 9 |
* edit form. This information then displays in nodes which are enabled to.
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_help().
|
| 14 |
*/
|
| 15 |
function nodeauthor_help($section) {
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Implementation of hook_perm().
|
| 20 |
*/
|
| 21 |
|
| 22 |
function nodeauthor_perm() {
|
| 23 |
return array("edit own info", "view author info");
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_user().
|
| 28 |
*/
|
| 29 |
function nodeauthor_user($op, &$edit, &$account, $category = NULL) {
|
| 30 |
if (($op == 'form') || ($op == 'register')) {
|
| 31 |
if (user_access('edit own info', $account)) {
|
| 32 |
$form['userinfo'] = array(
|
| 33 |
'#type' => 'fieldset',
|
| 34 |
'#title' => t('Additional user info'),
|
| 35 |
'#collapsible' => TRUE,
|
| 36 |
'#collapsed' => TRUE,
|
| 37 |
'#weight' => 4,
|
| 38 |
);
|
| 39 |
$form['userinfo']['info'] = array(
|
| 40 |
'#type' => 'textarea',
|
| 41 |
'#title' => t('Short info'),
|
| 42 |
'#default_value' => $account->info,
|
| 43 |
'#description' => t('This info will be displayed in your content as "author information".')
|
| 44 |
);
|
| 45 |
$form['userinfo']['format'] = filter_form($account->format);
|
| 46 |
}
|
| 47 |
}
|
| 48 |
return $form;
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Implementation of hook_menu()
|
| 53 |
*/
|
| 54 |
function nodeauthor_menu() {
|
| 55 |
$items = array();
|
| 56 |
$items['admin/content/nodeauthor'] = array(
|
| 57 |
'title' => 'Nodeauthor',
|
| 58 |
'description' => 'Modify which node types displays nodeauthor information',
|
| 59 |
'page callback' => 'drupal_get_form',
|
| 60 |
'page arguments' => array('nodeauthor_admin_settings'),
|
| 61 |
'access arguments' => array('administer site configuration'),
|
| 62 |
);
|
| 63 |
return $items;
|
| 64 |
}
|
| 65 |
|
| 66 |
/**
|
| 67 |
* Implementation of hook_settings().
|
| 68 |
*/
|
| 69 |
function nodeauthor_admin_settings() {
|
| 70 |
$types = node_get_types();
|
| 71 |
while(list($type, $type_name) = each($types)) {
|
| 72 |
$options[$type] = $type_name->name;
|
| 73 |
}
|
| 74 |
|
| 75 |
$form['nodesettings'] = array(
|
| 76 |
'#type' => 'fieldset',
|
| 77 |
'#title' => t('Node type settings'),
|
| 78 |
'#collapsible' => TRUE,
|
| 79 |
'#collapsed' => FALSE);
|
| 80 |
$form['nodesettings']['nodes_add_info'] = array(
|
| 81 |
'#type' => 'checkboxes',
|
| 82 |
'#title' => t('Content types'),
|
| 83 |
'#default_value' => variable_get('nodes_add_info', array()),
|
| 84 |
'#options' => $options,
|
| 85 |
'#description' => t('Select node types, where additional user info will be displayed.'),
|
| 86 |
);
|
| 87 |
$form['userpictures'] = array(
|
| 88 |
'#type' => 'fieldset',
|
| 89 |
'#title' => t('User pictures'),
|
| 90 |
'#collapsible' => TRUE,
|
| 91 |
'#collapsed' => FALSE);
|
| 92 |
$form['userpictures']['showpicture'] = array(
|
| 93 |
'#type' => 'checkbox',
|
| 94 |
'#title' => t('Show user pictures'),
|
| 95 |
'#default_value' => variable_get('showpicture', 0),
|
| 96 |
'#description' => t('Show user pictures in author information?'),
|
| 97 |
);
|
| 98 |
|
| 99 |
return system_settings_form($form);
|
| 100 |
}
|
| 101 |
|
| 102 |
|
| 103 |
/**
|
| 104 |
* Implementation of hook_nodeapi().
|
| 105 |
*/
|
| 106 |
function nodeauthor_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
|
| 107 |
switch ($op) {
|
| 108 |
case 'alter':
|
| 109 |
if (user_access("view author info")) {
|
| 110 |
$allowed = variable_get('nodes_add_info', array());
|
| 111 |
if ($allowed[$node->type]) {
|
| 112 |
$user = user_load(array('uid' => $node->uid));
|
| 113 |
if (!empty($user->info)) {
|
| 114 |
// Display picture if enabled
|
| 115 |
if (variable_get('showpicture', 0) && !empty($user->picture)) {
|
| 116 |
$picture = $user->picture;
|
| 117 |
} else {
|
| 118 |
$picture = NULL;
|
| 119 |
}
|
| 120 |
$path = drupal_get_path('module', 'nodeauthor');
|
| 121 |
drupal_add_css($path . '/nodeauthor.css');
|
| 122 |
$info = check_markup($user->info, $user->format);
|
| 123 |
$node->body .= theme('authorinfo', $info, $picture);
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
break;
|
| 128 |
}
|
| 129 |
}
|
| 130 |
/**
|
| 131 |
* Implementation of hook_theme().
|
| 132 |
*/
|
| 133 |
function nodeauthor_theme() {
|
| 134 |
return array(
|
| 135 |
'authorinfo' => array(
|
| 136 |
'arguments' => array('info' => NULL, 'picture' => NULL),
|
| 137 |
),
|
| 138 |
);
|
| 139 |
}
|
| 140 |
|
| 141 |
/**
|
| 142 |
* Format node author information
|
| 143 |
*
|
| 144 |
* @ingroup themeable
|
| 145 |
*/
|
| 146 |
function theme_authorinfo($info, $picture) {
|
| 147 |
$output = "<div class=\"nodeauthor-info\"><span>" . t("About the author") . "</span>";
|
| 148 |
if (isset($picture)) {
|
| 149 |
$output .= "<div class=\"nodeauthor-pic\"><img src=\"" . file_create_url(check_plain($picture))."\" alt=\"".t("User picture")."\" /></div>";
|
| 150 |
}
|
| 151 |
$output .= $info;
|
| 152 |
$ret .= '</div>';
|
| 153 |
return $output;
|
| 154 |
}
|