| 1 |
<?php
|
| 2 |
// $Id: $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* menu hook
|
| 6 |
*/
|
| 7 |
function designated_author_menu($may_cache) {
|
| 8 |
if (!$may_cache) {
|
| 9 |
$items[] = array(
|
| 10 |
'path' => 'admin/settings/designated-author',
|
| 11 |
'title' => t('Designated author'),
|
| 12 |
'description' => t('Set a specific user as the author of all nodes of particular node types.'),
|
| 13 |
'callback' => 'drupal_get_form',
|
| 14 |
'callback arguments' => array('designated_author_settings'),
|
| 15 |
'access' => user_access('administer site configuration'),
|
| 16 |
'type' => MENU_NORMAL_ITEM, // optional
|
| 17 |
);
|
| 18 |
}
|
| 19 |
return $items;
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_settings().
|
| 24 |
*/
|
| 25 |
function designated_author_settings() {
|
| 26 |
$form = array();
|
| 27 |
$node_types = node_get_types('names');
|
| 28 |
$form['designated_author_node_types'] = array(
|
| 29 |
'#type' => 'checkboxes',
|
| 30 |
'#title' => t('Node types'),
|
| 31 |
'#options' => $node_types,
|
| 32 |
'#default_value' => variable_get('designated_author_node_types', array()),
|
| 33 |
'#description' => t('Choose node types that should be assigned a designated author.'),
|
| 34 |
);
|
| 35 |
$form['designated_author_uid'] = array(
|
| 36 |
'#type' => 'textfield',
|
| 37 |
'#title' => t('Designated author'),
|
| 38 |
'#maxlength' => 60,
|
| 39 |
'#autocomplete_path' => 'user/autocomplete',
|
| 40 |
'#default_value' => variable_get('designated_author_uid', ''),
|
| 41 |
'#description' =>
|
| 42 |
t('Choose user who is going to be the designated author for the node types activated above.
|
| 43 |
Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
|
| 44 |
);
|
| 45 |
return system_settings_form($form);
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_nodeapi().
|
| 50 |
*/
|
| 51 |
function designated_author_nodeapi(&$node, $op, $teaser, $page) {
|
| 52 |
switch ($op) {
|
| 53 |
case 'submit':
|
| 54 |
case 'prepare':
|
| 55 |
if ($node_types = variable_get('designated_author_node_types', FALSE)) {
|
| 56 |
if (in_array($node->type, $node_types, true)) {
|
| 57 |
$node->name = variable_get('designated_author_uid', '');
|
| 58 |
if ($account = user_load(array('name' => $node->name))) {
|
| 59 |
$node->uid = $account->uid;
|
| 60 |
}
|
| 61 |
else {
|
| 62 |
$node->uid = 0;
|
| 63 |
}
|
| 64 |
}
|
| 65 |
}
|
| 66 |
break;
|
| 67 |
}
|
| 68 |
}
|