| 1 |
<?php |
<?php |
| 2 |
// $Id: override_node_options.module,v 1.1 2007/01/09 04:26:10 robroy Exp $ |
// $Id: |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 11 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 12 |
*/ |
*/ |
| 13 |
function override_node_options_perm() { |
function override_node_options_perm() { |
| 14 |
return array('override node publishing options'); |
$results = db_query("SELECT type FROM {node_type}"); |
| 15 |
|
|
| 16 |
|
while ($value = db_fetch_array($results)) { |
| 17 |
|
$perms[] = 'override ' . $value['type'] . ' published option'; |
| 18 |
|
$perms[] = 'override ' . $value['type'] . ' promote to front page option'; |
| 19 |
|
$perms[] = 'override ' . $value['type'] . ' sticky option'; |
| 20 |
|
$perms[] = 'override ' . $value['type'] . ' revision option'; |
| 21 |
|
$perms[] = 'override ' . $value['type'] . ' authored on option'; |
| 22 |
|
$perms[] = 'override ' . $value['type'] . ' authored by option'; |
| 23 |
|
} |
| 24 |
|
return $perms; |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* Implementation of hook_menu(). |
| 29 |
|
* This setups up the administration menu link. |
| 30 |
|
*/ |
| 31 |
|
function override_node_options_menu() { |
| 32 |
|
$items = array(); |
| 33 |
|
$items[] = array( |
| 34 |
|
'path' => 'admin/settings/override_node_options', |
| 35 |
|
'title' => t('Override node options'), |
| 36 |
|
'description' => t('Allow non-admins to override the default publishing options for nodes they can edit'), |
| 37 |
|
'callback' => 'drupal_get_form', |
| 38 |
|
'callback arguments' => array('override_node_options_admin_settings'), |
| 39 |
|
'access' => user_access('access administration pages'), |
| 40 |
|
'type' => MENU_NORMAL_ITEM, |
| 41 |
|
); |
| 42 |
|
|
| 43 |
|
return $items; |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
/** |
| 48 |
|
* Implementation of hook_admin_settings(). |
| 49 |
|
* These settings are to control the collapsed and collapsible settings. |
| 50 |
|
*/ |
| 51 |
|
function override_node_options_admin_settings() { |
| 52 |
|
if(module_exists(upload)){ |
| 53 |
|
$form['attachments'] = array( |
| 54 |
|
'#type' => 'fieldset', |
| 55 |
|
'#title' => t('File attachments'), |
| 56 |
|
'#description' => t('Options for the File attachments fieldset on the node form.'), |
| 57 |
|
); |
| 58 |
|
|
| 59 |
|
$form['attachments']['override_node_options_facollapsible'] = array( |
| 60 |
|
'#type' => 'checkbox', |
| 61 |
|
'#title' => t('File attachments collapsible'), |
| 62 |
|
'#default_value' => variable_get('override_node_options_facollapsible', 1), |
| 63 |
|
); |
| 64 |
|
$form['attachments']['override_node_options_facollapsed'] = array( |
| 65 |
|
'#type' => 'checkbox', |
| 66 |
|
'#title' => t('File attachments collapsed by default'), |
| 67 |
|
'#default_value' => variable_get('override_node_options_facollapsed', 1), |
| 68 |
|
); |
| 69 |
|
} |
| 70 |
|
if(module_exists(scheduler)){ |
| 71 |
|
$form['scheduler_settings'] = array( |
| 72 |
|
'#type' => 'fieldset', |
| 73 |
|
'#title' => t('Scheduler settings'), |
| 74 |
|
'#description' => t('Options for the Scheduler settings fieldset on the node form.'), |
| 75 |
|
); |
| 76 |
|
|
| 77 |
|
$form['scheduler_settings']['override_node_options_sscollapsible'] = array( |
| 78 |
|
'#type' => 'checkbox', |
| 79 |
|
'#title' => t('Scheduler settings collapsible'), |
| 80 |
|
'#default_value' => variable_get('override_node_options_sscollapsible', 1), |
| 81 |
|
); |
| 82 |
|
$form['scheduler_settings']['override_node_options_sscollapsed'] = array( |
| 83 |
|
'#type' => 'checkbox', |
| 84 |
|
'#title' => t('Scheduler settings collapsed by default'), |
| 85 |
|
'#default_value' => variable_get('override_node_options_sscollapsed', 1), |
| 86 |
|
); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
if(module_exists(comment)){ |
| 90 |
|
$form['comment_settings'] = array( |
| 91 |
|
'#type' => 'fieldset', |
| 92 |
|
'#title' => t('Comment settings'), |
| 93 |
|
'#description' => t('Options for the Comment settings fieldset on the node form.'), |
| 94 |
|
); |
| 95 |
|
|
| 96 |
|
$form['comment_settings']['override_node_options_cscollapsible'] = array( |
| 97 |
|
'#type' => 'checkbox', |
| 98 |
|
'#title' => t('Comment settings collapsible'), |
| 99 |
|
'#default_value' => variable_get('override_node_options_cscollapsible', 1), |
| 100 |
|
); |
| 101 |
|
$form['comment_settings']['override_node_options_cscollapsed'] = array( |
| 102 |
|
'#type' => 'checkbox', |
| 103 |
|
'#title' => t('Comment settings collapsed by default'), |
| 104 |
|
'#default_value' => variable_get('override_node_options_cscollapsed', 1), |
| 105 |
|
); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
if(module_exists(node)){ |
| 109 |
|
$form['authoring_information'] = array( |
| 110 |
|
'#type' => 'fieldset', |
| 111 |
|
'#title' => t('Authoring information'), |
| 112 |
|
'#description' => t('Options for the Authoring information fieldset on the node form.'), |
| 113 |
|
); |
| 114 |
|
|
| 115 |
|
$form['authoring_information']['override_node_options_aicollapsible'] = array( |
| 116 |
|
'#type' => 'checkbox', |
| 117 |
|
'#title' => t('Authoring information collapsible'), |
| 118 |
|
'#default_value' => variable_get('override_node_options_aicollapsible', 1), |
| 119 |
|
); |
| 120 |
|
$form['authoring_information']['override_node_options_aicollapsed'] = array( |
| 121 |
|
'#type' => 'checkbox', |
| 122 |
|
'#title' => t('Authoring information collapsed by default'), |
| 123 |
|
'#default_value' => variable_get('override_node_options_aicollapsed', 1), |
| 124 |
|
); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
if(module_exists(node)){ |
| 128 |
|
$form['publishing_options'] = array( |
| 129 |
|
'#type' => 'fieldset', |
| 130 |
|
'#title' => t('Publishing options'), |
| 131 |
|
'#description' => t('Options for the Publishing options fieldset on the node form.'), |
| 132 |
|
); |
| 133 |
|
|
| 134 |
|
$form['publishing_options']['override_node_options_pocollapsible'] = array( |
| 135 |
|
'#type' => 'checkbox', |
| 136 |
|
'#title' => t('Publishing options collapsible'), |
| 137 |
|
'#default_value' => variable_get('override_node_options_pocollapsible', 1), |
| 138 |
|
); |
| 139 |
|
$form['publishing_options']['override_node_options_pocollapsed'] = array( |
| 140 |
|
'#type' => 'checkbox', |
| 141 |
|
'#title' => t('Publishing options collapsed by default'), |
| 142 |
|
'#default_value' => variable_get('override_node_options_pocollapsed', 1), |
| 143 |
|
); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
return system_settings_form($form); |
| 147 |
|
|
| 148 |
} |
} |
| 149 |
|
|
| 150 |
/** |
/** |
| 151 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 152 |
*/ |
*/ |
| 153 |
function override_node_options_form_alter($form_id, &$form) { |
function override_node_options_form_alter($form_id, &$form) { |
| 154 |
// Allow users with 'override node publishing options' to change node |
|
| 155 |
// options. Taken from node_form_array(). |
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && !user_access('administer nodes')) { |
|
// TODO: Once in core, remove adminster nodes check. |
|
|
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && user_access('override node publishing options') && !user_access('administer nodes')) { |
|
| 156 |
$node = $form['#node']; |
$node = $form['#node']; |
| 157 |
$form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25); |
|
| 158 |
$form['options']['override_publishing_status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status); |
if(user_access('override ' . $form['type']['#value'] . ' published option') || user_access('override ' . $form['type']['#value'] . ' promote to front page option') || user_access('override ' . $form['type']['#value'] . ' sticky option') || user_access('override ' . $form['type']['#value'] . ' revision option')){ |
| 159 |
$form['options']['override_publishing_promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote); |
|
| 160 |
$form['options']['override_publishing_sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky); |
$form['options'] = array( |
| 161 |
$form['options']['override_publishing_revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision); |
'#type' => 'fieldset', |
| 162 |
|
'#title' => t('Publishing options'), |
| 163 |
|
'#collapsible' => variable_get('override_node_options_pocollapsible', 1), |
| 164 |
|
'#collapsed' => variable_get('override_node_options_pocollapsed', 1), '#weight' => 25); |
| 165 |
|
} |
| 166 |
|
if(user_access('override ' . $form['type']['#value'] . ' published option')){ |
| 167 |
|
$form['options']['override_publishing_status'] = array( |
| 168 |
|
'#type' => 'checkbox', |
| 169 |
|
'#title' => t('Published'), |
| 170 |
|
'#default_value' => $node->status); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
if(user_access('override ' . $form['type']['#value'] . ' promote to front page option')){ |
| 174 |
|
$form['options']['override_publishing_promote'] = array( |
| 175 |
|
'#type' => 'checkbox', |
| 176 |
|
'#title' => t('Promoted to front page'), |
| 177 |
|
'#default_value' => $node->promote); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
if(user_access('override ' . $form['type']['#value'] . ' sticky option')){ |
| 181 |
|
$form['options']['override_publishing_sticky'] = array( |
| 182 |
|
'#type' => 'checkbox', '#title' => t('Sticky at top of lists'), |
| 183 |
|
'#default_value' => $node->sticky); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
if(user_access('override ' . $form['type']['#value'] . ' revision option')){ |
| 187 |
|
$form['options']['override_publishing_revision'] = array( |
| 188 |
|
'#type' => 'checkbox', |
| 189 |
|
'#title' => t('Create new revision'), |
| 190 |
|
'#default_value' => $node->revision); |
| 191 |
|
} |
| 192 |
|
if(user_access('override ' . $form['type']['#value'] . ' authored by option') || user_access('override ' . $form['type']['#value'] . ' authored on option')){ |
| 193 |
|
$form['author'] = array( |
| 194 |
|
'#type' => 'fieldset', |
| 195 |
|
'#title' => t('Authoring information'), |
| 196 |
|
'#collapsible' => variable_get('override_node_options_aicollapsible', 1), |
| 197 |
|
'#collapsed' => variable_get('override_node_options_aicollapsed', 1), '#weight' => 20); |
| 198 |
|
} |
| 199 |
|
if(user_access('override ' . $form['type']['#value'] . ' authored by option')){ |
| 200 |
|
$form['author']['override_authored_by'] = array( |
| 201 |
|
'#type' => 'textfield', |
| 202 |
|
'#title' => t('Authored by'), |
| 203 |
|
'#maxlength' => 60, |
| 204 |
|
'#default_value' => $node->name ? $node->name : '', |
| 205 |
|
'#weight' => -1, |
| 206 |
|
'#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))), |
| 207 |
|
); |
| 208 |
|
|
| 209 |
|
// User must have permission 'access user profiles' for autocomplete |
| 210 |
|
if (user_access('access user profiles')) { |
| 211 |
|
$form['author']['override_authored_by']['#autocomplete_path'] = 'user/autocomplete'; |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
if(user_access('override ' . $form['type']['#value'] . ' authored on option')){ |
| 217 |
|
$form['author']['override_authored_on'] = array( |
| 218 |
|
'#type' => 'textfield', |
| 219 |
|
'#title' => t('Authored on'), |
| 220 |
|
'#maxlength' => 25, |
| 221 |
|
'#default_value' => $node->date, |
| 222 |
|
'#description' => t('Format: %time. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? $node->date : format_date($node->created, 'custom', 'Y-m-d H:i:s O'))), |
| 223 |
|
); |
| 224 |
|
|
| 225 |
|
} |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { |
| 229 |
|
if(module_exists(comment)){ |
| 230 |
|
$form['comment_settings']['#collapsible'] = variable_get('override_node_options_cscollapsible', 1); |
| 231 |
|
$form['comment_settings']['#collapsed'] = variable_get('override_node_options_cscollapsed', 1); |
| 232 |
|
} |
| 233 |
|
if(module_exists(node)){ |
| 234 |
|
$form['options']['#collapsible'] = variable_get('override_node_options_pocollapsible', 1); |
| 235 |
|
$form['options']['#collapsed'] = variable_get('override_node_options_pocollapsed', 1); |
| 236 |
|
} |
| 237 |
|
if(module_exists(node)){ |
| 238 |
|
$form['author']['#collapsible'] = variable_get('override_node_options_aicollapsible', 1); |
| 239 |
|
$form['author']['#collapsed'] = variable_get('override_node_options_aicollapsed', 1); |
| 240 |
|
} |
| 241 |
|
if(module_exists(upload)){ |
| 242 |
|
$form['attachments']['#collapsible'] = variable_get('override_node_options_facollapsible', 1); |
| 243 |
|
$form['attachments']['#collapsed'] = variable_get('override_node_options_facollapsed', 1); |
| 244 |
|
} |
| 245 |
|
if(module_exists(scheduler)){ |
| 246 |
|
$form['scheduler_settings']['#collapsible'] = variable_get('override_node_options_sscollapsible', 1); |
| 247 |
|
$form['scheduler_settings']['#collapsed'] = variable_get('override_node_options_sscollapsed', 1); |
| 248 |
|
} |
| 249 |
} |
} |
| 250 |
} |
} |
| 251 |
|
|
| 252 |
|
|
| 253 |
/** |
/** |
| 254 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 255 |
*/ |
*/ |
| 259 |
// Allow users with 'override node publishing options' to change node |
// Allow users with 'override node publishing options' to change node |
| 260 |
// options. |
// options. |
| 261 |
// TODO: Once in core, remove adminster nodes check. |
// TODO: Once in core, remove adminster nodes check. |
| 262 |
if (user_access('override node publishing options') && !user_access('administer nodes')) { |
if (!user_access('administer nodes')) { |
| 263 |
$keys = array( |
$keys = array( |
| 264 |
'override_publishing_status' => 'status', |
'override_publishing_status' => 'status', |
| 265 |
'override_publishing_promote' => 'promote', |
'override_publishing_promote' => 'promote', |
| 266 |
'override_publishing_sticky' => 'sticky', |
'override_publishing_sticky' => 'sticky', |
| 267 |
'override_publishing_revision' => 'revision', |
'override_publishing_revision' => 'revision' |
| 268 |
); |
); |
| 269 |
foreach ($keys as $override_key => $real_key) { |
foreach ($keys as $override_key => $real_key) { |
| 270 |
if (isset($node->$override_key)) { |
if (isset($node->$override_key)) { |
| 271 |
$node->$real_key = $node->$override_key; |
$node->$real_key = $node->$override_key; |
| 272 |
} |
} |
| 273 |
} |
} |
| 274 |
|
if(user_access('override ' . $node->type . ' authored on option')){ |
| 275 |
|
// Node creation date override |
| 276 |
|
if ($node->date !== $node->override_authored_on || !empty($node->override_authored_on)) { |
| 277 |
|
$node->created = !empty($node->override_authored_on) ? strtotime($node->override_authored_on) : time(); |
| 278 |
|
} |
| 279 |
|
} |
| 280 |
|
if(user_access('override ' . $node->type . ' authored by option')){ |
| 281 |
|
if ($node->name !== $node->override_authored_by) { |
| 282 |
|
if (!empty($node->override_authored_by)) { |
| 283 |
|
$account = user_load(array('name' => $node->override_authored_by)); |
| 284 |
|
$node->uid = $account->uid; |
| 285 |
|
} |
| 286 |
|
else { |
| 287 |
|
$node->uid = 0; |
| 288 |
|
} |
| 289 |
|
} |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
|
| 293 |
} |
} |
| 294 |
break; |
break; |
| 295 |
} |
} |