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