| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Display help and module information
|
| 5 |
* @param section which section of the site we're displaying help
|
| 6 |
* @return help text for section
|
| 7 |
*/
|
| 8 |
|
| 9 |
function node_adoption_help($section='') {
|
| 10 |
|
| 11 |
$output = '';
|
| 12 |
|
| 13 |
switch ($section) {
|
| 14 |
case "admin/modules#description":
|
| 15 |
$output = t("Assign orphan nodes to a user");
|
| 16 |
break;
|
| 17 |
}
|
| 18 |
|
| 19 |
return $output;
|
| 20 |
|
| 21 |
} // function node_adoption_help
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Valid permissions for this module
|
| 25 |
* @return An array of valid permissions for the node_adoption module
|
| 26 |
*/
|
| 27 |
function node_adoption_perm() {
|
| 28 |
|
| 29 |
return array('administer node_adoption');
|
| 30 |
|
| 31 |
} // function node_adoption_perm()
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Implementation of hook_menu().
|
| 35 |
*/
|
| 36 |
function node_adoption_menu($may_cache) {
|
| 37 |
global $user;
|
| 38 |
$items = array();
|
| 39 |
|
| 40 |
if ($may_cache) {
|
| 41 |
$items[] = array(
|
| 42 |
'path' => 'admin/settings/node_adoption',
|
| 43 |
'title' => t('Node Adoption'),
|
| 44 |
'description' => t('Set default node owner.'),
|
| 45 |
'callback' => 'drupal_get_form',
|
| 46 |
'callback arguments' => array('node_adoption_admin_settings'),
|
| 47 |
'access' => user_access('administer site configuration'),
|
| 48 |
'type' => MENU_NORMAL_ITEM, // optional
|
| 49 |
);
|
| 50 |
$items[] = array('path' => 'admin/content/node_adoption',
|
| 51 |
'title' => t('Node Ownership'),
|
| 52 |
'description' => t('Transfer ownership of nodes (including orphaned nodes) from one user to another.'),
|
| 53 |
'callback' => 'node_adoption_form_main',
|
| 54 |
'access' => user_access('administer node_adoption'),
|
| 55 |
'type' => MENU_NORMAL_ITEM);
|
| 56 |
}
|
| 57 |
return $items;
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Module configuration settings
|
| 62 |
* @return settings HTML or deny access
|
| 63 |
*/
|
| 64 |
function node_adoption_admin_settings() {
|
| 65 |
$result = db_query("SELECT u.uid, u.name FROM {users} u WHERE u.status = 1 ORDER BY name ASC");
|
| 66 |
while ($row = db_fetch_array($result)) {
|
| 67 |
$options[$row['uid']] = $row['name'];
|
| 68 |
}
|
| 69 |
$form['node_adoption_parent'] = array(
|
| 70 |
'#type' => 'select',
|
| 71 |
'#title' => t('Specify who will adopt orphan nodes'),
|
| 72 |
'#default_value' => variable_get('node_adoption_parent', 1),
|
| 73 |
'#options' => $options
|
| 74 |
);
|
| 75 |
return system_settings_form($form);
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Implementation of hook_user; update orphaned nodes (uid = 0) to new parent
|
| 80 |
*/
|
| 81 |
function node_adoption_user($op, &$edit, &$account) {
|
| 82 |
if($op == 'delete') {
|
| 83 |
db_query("UPDATE {node} n SET n.uid = %d WHERE n.uid = %d", variable_get('node_adoption_parent', 1), 0);
|
| 84 |
db_query("UPDATE {node_revisions} nr SET nr.uid = %d WHERE nr.uid = %d", variable_get('node_adoption_parent', 1), 0);
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
/**
|
| 89 |
* Returns a form for transferring node ownership
|
| 90 |
*
|
| 91 |
*/
|
| 92 |
function node_adoption_form_transfer() {
|
| 93 |
$result = db_query("SELECT u.uid, u.name FROM {users} u WHERE u.status = 1 ORDER BY name ASC");
|
| 94 |
while ($row = db_fetch_array($result)) {
|
| 95 |
$options[$row['uid']] = $row['name'];
|
| 96 |
}
|
| 97 |
$options[0] = 'Orphaned Nodes';
|
| 98 |
|
| 99 |
$form['from'] = array(
|
| 100 |
'#type' => 'select',
|
| 101 |
'#title' => t('Original Owner'),
|
| 102 |
'#default_value' => 0,
|
| 103 |
'#options' => $options
|
| 104 |
);
|
| 105 |
unset($options[0]);
|
| 106 |
$form['to'] = array(
|
| 107 |
'#type' => 'select',
|
| 108 |
'#title' => t('Specify who will adopt nodes'),
|
| 109 |
'#default_value' => variable_get('node_adoption_parent', 1),
|
| 110 |
'#options' => $options
|
| 111 |
);
|
| 112 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
|
| 113 |
return $form;
|
| 114 |
}
|
| 115 |
|
| 116 |
function node_adoption_form_main() {
|
| 117 |
return drupal_get_form('node_adoption_form_transfer');
|
| 118 |
}
|
| 119 |
|
| 120 |
/**
|
| 121 |
* Process forum form and container form submissions.
|
| 122 |
*/
|
| 123 |
function node_adoption_form_transfer_submit($form_id, $form_values) {
|
| 124 |
db_query("UPDATE {node} n SET n.uid = %d WHERE n.uid = %d", $form_values['to'], $form_values['from']);
|
| 125 |
db_query("UPDATE {node_revisions} nr SET nr.uid = %d WHERE nr.uid = %d", $form_values['to'], $form_values['from']);
|
| 126 |
|
| 127 |
drupal_set_message(t('Node ownership has been transferred.'));
|
| 128 |
|
| 129 |
return 'admin/content/node_adoption';
|
| 130 |
}
|
| 131 |
?>
|