| 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'); |
return array('Display published option','Display promote to front page option','Display sticky option','Display revision option','Display authored on option'); |
| 15 |
|
} |
| 16 |
|
|
| 17 |
|
function override_node_options_menu() { |
| 18 |
|
$items = array(); |
| 19 |
|
$items['admin/settings/override_node_options'] = array( |
| 20 |
|
'title' => t('Override node options'), |
| 21 |
|
'description' => t('Allow non-admins to override the default publishing options for nodes they can edit'), |
| 22 |
|
'page callback' => 'drupal_get_form', |
| 23 |
|
'page arguments' => array('override_node_options_admin_settings'), |
| 24 |
|
'access arguments' => array('access administration pages'), |
| 25 |
|
'type' => MENU_NORMAL_ITEM, |
| 26 |
|
); |
| 27 |
|
return $items; |
| 28 |
|
} |
| 29 |
|
|
| 30 |
|
function override_node_options_admin_settings() { |
| 31 |
|
if(module_exists(upload)){ |
| 32 |
|
$form['attachments'] = array( |
| 33 |
|
'#type' => 'fieldset', |
| 34 |
|
'#title' => t('File attachments'), |
| 35 |
|
'#description' => t('Options for the File attachments fieldset on the node form.'), |
| 36 |
|
); |
| 37 |
|
|
| 38 |
|
$form['attachments']['override_node_options_facollapsible'] = array( |
| 39 |
|
'#type' => 'checkbox', |
| 40 |
|
'#title' => t('File attachments collapsible'), |
| 41 |
|
'#default_value' => variable_get('override_node_options_facollapsible', 1), |
| 42 |
|
); |
| 43 |
|
$form['attachments']['override_node_options_facollapsed'] = array( |
| 44 |
|
'#type' => 'checkbox', |
| 45 |
|
'#title' => t('File attachments collapsed by default'), |
| 46 |
|
'#default_value' => variable_get('override_node_options_facollapsed', 1), |
| 47 |
|
); |
| 48 |
|
} |
| 49 |
|
if(module_exists(scheduler)){ |
| 50 |
|
$form['scheduler_settings'] = array( |
| 51 |
|
'#type' => 'fieldset', |
| 52 |
|
'#title' => t('Scheduler settings'), |
| 53 |
|
'#description' => t('Options for the Scheduler settings fieldset on the node form.'), |
| 54 |
|
); |
| 55 |
|
|
| 56 |
|
$form['scheduler_settings']['override_node_options_sscollapsible'] = array( |
| 57 |
|
'#type' => 'checkbox', |
| 58 |
|
'#title' => t('Scheduler settings collapsible'), |
| 59 |
|
'#default_value' => variable_get('override_node_options_sscollapsible', 1), |
| 60 |
|
); |
| 61 |
|
$form['scheduler_settings']['override_node_options_sscollapsed'] = array( |
| 62 |
|
'#type' => 'checkbox', |
| 63 |
|
'#title' => t('Scheduler settings collapsed by default'), |
| 64 |
|
'#default_value' => variable_get('override_node_options_sscollapsed', 1), |
| 65 |
|
); |
| 66 |
|
} |
| 67 |
|
if(module_exists(node)){ |
| 68 |
|
$form['publishing_options'] = array( |
| 69 |
|
'#type' => 'fieldset', |
| 70 |
|
'#title' => t('Publishing options'), |
| 71 |
|
'#description' => t('Options for the Publishing options fieldset on the node form.'), |
| 72 |
|
); |
| 73 |
|
|
| 74 |
|
$form['publishing_options']['override_node_options_pocollapsible'] = array( |
| 75 |
|
'#type' => 'checkbox', |
| 76 |
|
'#title' => t('Publishing options collapsible'), |
| 77 |
|
'#default_value' => variable_get('override_node_options_pocollapsible', 1), |
| 78 |
|
); |
| 79 |
|
$form['publishing_options']['override_node_options_pocollapsed'] = array( |
| 80 |
|
'#type' => 'checkbox', |
| 81 |
|
'#title' => t('Publishing options collapsed by default'), |
| 82 |
|
'#default_value' => variable_get('override_node_options_pocollapsed', 1), |
| 83 |
|
); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
return system_settings_form($form); |
| 87 |
|
|
| 88 |
} |
} |
| 89 |
|
|
| 90 |
/** |
/** |
| 91 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 92 |
*/ |
*/ |
| 93 |
function override_node_options_form_alter($form_id, &$form) { |
function override_node_options_form_alter(&$form, $form_state, $form_id) { |
| 94 |
// Allow users with 'override node publishing options' to change node |
// Allow users with 'override node publishing options' to change node |
| 95 |
// options. Taken from node_form_array(). |
// options. Taken from node_form_array(). |
| 96 |
// TODO: Once in core, remove adminster nodes check. |
// TODO: Once in core, remove adminster nodes check. |
| 97 |
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && user_access('override node publishing options') && !user_access('administer nodes')) { |
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && !user_access('administer nodes')) { |
| 98 |
$node = $form['#node']; |
$node = $form['#node']; |
| 99 |
$form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25); |
$form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => variable_get('override_node_options_collapsible', 1), '#collapsed' => variable_get('override_node_options_collapsed', 1), '#weight' => 25); |
| 100 |
|
if(user_access('Display published option')){ |
| 101 |
$form['options']['override_publishing_status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status); |
$form['options']['override_publishing_status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status); |
| 102 |
|
} |
| 103 |
|
if(user_access('Display promote to front page option')){ |
| 104 |
$form['options']['override_publishing_promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote); |
$form['options']['override_publishing_promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote); |
| 105 |
|
} |
| 106 |
|
if(user_access('Display sticky option')){ |
| 107 |
$form['options']['override_publishing_sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky); |
$form['options']['override_publishing_sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky); |
| 108 |
|
} |
| 109 |
|
if(user_access('Display revision option')){ |
| 110 |
$form['options']['override_publishing_revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision); |
$form['options']['override_publishing_revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision); |
| 111 |
|
} |
| 112 |
|
if(user_access('Display authored on option')){ |
| 113 |
|
$form['options']['override_authored_on'] = array( |
| 114 |
|
'#type' => 'textfield', |
| 115 |
|
'#title' => t('Authored on'), |
| 116 |
|
'#maxlength' => 25, |
| 117 |
|
'#default_value' => $node->date, |
| 118 |
|
'#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'))), |
| 119 |
|
); |
| 120 |
|
|
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { |
| 125 |
|
if(module_exists(node)){ |
| 126 |
|
$form['options']['#collapsible'] = variable_get('override_node_options_pocollapsible', 1); |
| 127 |
|
$form['options']['#collapsed'] = variable_get('override_node_options_pocollapsed', 1); |
| 128 |
|
} |
| 129 |
|
if(module_exists(upload)){ |
| 130 |
|
$form['attachments']['#collapsible'] = variable_get('override_node_options_facollapsible', 1); |
| 131 |
|
$form['attachments']['#collapsed'] = variable_get('override_node_options_facollapsed', 1); |
| 132 |
|
} |
| 133 |
|
if(module_exists(scheduler)){ |
| 134 |
|
$form['scheduler_settings']['#collapsible'] = variable_get('override_node_options_sscollapsible', 1); |
| 135 |
|
$form['scheduler_settings']['#collapsed'] = variable_get('override_node_options_sscollapsed', 1); |
| 136 |
|
} |
| 137 |
} |
} |
| 138 |
} |
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
/** |
/** |
| 142 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 143 |
*/ |
*/ |
| 144 |
function override_node_options_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
function override_node_options_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
| 145 |
switch ($op) { |
switch ($op) { |
| 146 |
case 'submit': |
case 'presave': |
| 147 |
// Allow users with 'override node publishing options' to change node |
// Allow users with 'override node publishing options' to change node |
| 148 |
// options. |
// options. |
| 149 |
// TODO: Once in core, remove adminster nodes check. |
// TODO: Once in core, remove adminster nodes check. |
| 150 |
if (user_access('override node publishing options') && !user_access('administer nodes')) { |
if (!user_access('administer nodes')) { |
| 151 |
$keys = array( |
$keys = array( |
| 152 |
'override_publishing_status' => 'status', |
'override_publishing_status' => 'status', |
| 153 |
'override_publishing_promote' => 'promote', |
'override_publishing_promote' => 'promote', |
| 154 |
'override_publishing_sticky' => 'sticky', |
'override_publishing_sticky' => 'sticky', |
| 155 |
'override_publishing_revision' => 'revision', |
'override_publishing_revision' => 'revision', |
| 156 |
|
|
| 157 |
); |
); |
| 158 |
foreach ($keys as $override_key => $real_key) { |
foreach ($keys as $override_key => $real_key) { |
| 159 |
if (isset($node->$override_key)) { |
if (isset($node->$override_key)) { |
| 160 |
$node->$real_key = $node->$override_key; |
$node->$real_key = $node->$override_key; |
| 161 |
} |
} |
| 162 |
} |
} |
| 163 |
|
if(user_access('Display authored on option')){ |
| 164 |
|
// Node creation date override |
| 165 |
|
if ($node->date !== $node->override_authored_on || !empty($node->override_authored_on)) { |
| 166 |
|
$node->created = !empty($node->override_authored_on) ? strtotime($node->override_authored_on) : time(); |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
|
| 170 |
} |
} |
| 171 |
break; |
break; |
| 172 |
} |
} |