| 1 |
robroy |
1.1 |
<?php
|
| 2 |
robroy |
1.2 |
// $Id: override_node_options.module,v 1.1 2007/01/09 04:26:10 robroy Exp $
|
| 3 |
robroy |
1.1 |
|
| 4 |
|
|
/**
|
| 5 |
|
|
* @file
|
| 6 |
|
|
* Allow users to override the default publishing options for nodes they can
|
| 7 |
|
|
* edit without giving them the 'administer nodes' permission.
|
| 8 |
|
|
*/
|
| 9 |
|
|
|
| 10 |
|
|
/**
|
| 11 |
|
|
* Implementation of hook_perm().
|
| 12 |
|
|
*/
|
| 13 |
|
|
function override_node_options_perm() {
|
| 14 |
|
|
return array('override node publishing options');
|
| 15 |
|
|
}
|
| 16 |
|
|
|
| 17 |
|
|
/**
|
| 18 |
|
|
* Implementation of hook_form_alter().
|
| 19 |
|
|
*/
|
| 20 |
|
|
function override_node_options_form_alter($form_id, &$form) {
|
| 21 |
|
|
// Allow users with 'override node publishing options' to change node
|
| 22 |
|
|
// options. Taken from node_form_array().
|
| 23 |
|
|
// TODO: Once in core, remove adminster nodes check.
|
| 24 |
|
|
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && user_access('override node publishing options') && !user_access('administer nodes')) {
|
| 25 |
|
|
$node = $form['#node'];
|
| 26 |
|
|
$form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25);
|
| 27 |
|
|
$form['options']['override_publishing_status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status);
|
| 28 |
|
|
$form['options']['override_publishing_promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote);
|
| 29 |
|
|
$form['options']['override_publishing_sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky);
|
| 30 |
|
|
$form['options']['override_publishing_revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
|
| 31 |
|
|
}
|
| 32 |
|
|
}
|
| 33 |
|
|
|
| 34 |
|
|
/**
|
| 35 |
|
|
* Implementation of hook_nodeapi().
|
| 36 |
|
|
*/
|
| 37 |
|
|
function override_node_options_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
| 38 |
|
|
switch ($op) {
|
| 39 |
|
|
case 'submit':
|
| 40 |
|
|
// Allow users with 'override node publishing options' to change node
|
| 41 |
|
|
// options.
|
| 42 |
|
|
// TODO: Once in core, remove adminster nodes check.
|
| 43 |
|
|
if (user_access('override node publishing options') && !user_access('administer nodes')) {
|
| 44 |
|
|
$keys = array(
|
| 45 |
|
|
'override_publishing_status' => 'status',
|
| 46 |
|
|
'override_publishing_promote' => 'promote',
|
| 47 |
|
|
'override_publishing_sticky' => 'sticky',
|
| 48 |
|
|
'override_publishing_revision' => 'revision',
|
| 49 |
|
|
);
|
| 50 |
|
|
foreach ($keys as $override_key => $real_key) {
|
| 51 |
|
|
if (isset($node->$override_key)) {
|
| 52 |
|
|
$node->$real_key = $node->$override_key;
|
| 53 |
|
|
}
|
| 54 |
|
|
}
|
| 55 |
|
|
}
|
| 56 |
|
|
break;
|
| 57 |
|
|
}
|
| 58 |
|
|
}
|