| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: override_node_options.module,v 1.3 2008/11/02 15:42:00 timmillwood Exp $ |
| 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('Display published option','Display promote to front page option','Display sticky option','Display revision option','Display authored on option'); |
$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 |
} |
} |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* Implementation of hook_menu(). |
| 29 |
|
* This setups up the administration menu link. |
| 30 |
|
*/ |
| 31 |
function override_node_options_menu() { |
function override_node_options_menu() { |
| 32 |
$items = array(); |
$items = array(); |
| 33 |
$items['admin/settings/override_node_options'] = array( |
$items['admin/settings/override_node_options'] = array( |
| 41 |
return $items; |
return $items; |
| 42 |
} |
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
/** |
| 46 |
|
* Implementation of hook_admin_settings(). |
| 47 |
|
* These settings are to control the collapsed and collapsible settings. |
| 48 |
|
*/ |
| 49 |
function override_node_options_admin_settings() { |
function override_node_options_admin_settings() { |
| 50 |
if(module_exists(upload)){ |
if(module_exists(upload)){ |
| 51 |
$form['attachments'] = array( |
$form['attachments'] = array( |
| 110 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 111 |
*/ |
*/ |
| 112 |
function override_node_options_form_alter(&$form, $form_state, $form_id) { |
function override_node_options_form_alter(&$form, $form_state, $form_id) { |
|
// Allow users with 'override node publishing options' to change node |
|
|
// options. Taken from node_form_array(). |
|
|
// TODO: Once in core, remove adminster nodes check. |
|
| 113 |
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && !user_access('administer nodes')) { |
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && !user_access('administer nodes')) { |
| 114 |
$node = $form['#node']; |
$node = $form['#node']; |
| 115 |
$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); |
$form['options'] = array( |
| 116 |
if(user_access('Display published option')){ |
'#type' => 'fieldset', |
| 117 |
$form['options']['override_publishing_status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status); |
'#title' => t('Publishing options'), |
| 118 |
|
'#collapsible' => variable_get('override_node_options_collapsible', 1), |
| 119 |
|
'#collapsed' => variable_get('override_node_options_collapsed', 1), '#weight' => 25); |
| 120 |
|
|
| 121 |
|
if(user_access('override ' . $form['type']['#value'] . ' published option')){ |
| 122 |
|
$form['options']['override_publishing_status'] = array( |
| 123 |
|
'#type' => 'checkbox', |
| 124 |
|
'#title' => t('Published'), |
| 125 |
|
'#default_value' => $node->status); |
| 126 |
} |
} |
| 127 |
if(user_access('Display promote to front page option')){ |
|
| 128 |
$form['options']['override_publishing_promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote); |
if(user_access('override ' . $form['type']['#value'] . ' promote to front page option')){ |
| 129 |
|
$form['options']['override_publishing_promote'] = array( |
| 130 |
|
'#type' => 'checkbox', |
| 131 |
|
'#title' => t('Promoted to front page'), |
| 132 |
|
'#default_value' => $node->promote); |
| 133 |
} |
} |
| 134 |
if(user_access('Display sticky option')){ |
|
| 135 |
$form['options']['override_publishing_sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky); |
if(user_access('override ' . $form['type']['#value'] . ' sticky option')){ |
| 136 |
|
$form['options']['override_publishing_sticky'] = array( |
| 137 |
|
'#type' => 'checkbox', '#title' => t('Sticky at top of lists'), |
| 138 |
|
'#default_value' => $node->sticky); |
| 139 |
} |
} |
| 140 |
if(user_access('Display revision option')){ |
|
| 141 |
$form['options']['override_publishing_revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision); |
if(user_access('override ' . $form['type']['#value'] . ' revision option')){ |
| 142 |
|
$form['options']['override_publishing_revision'] = array( |
| 143 |
|
'#type' => 'checkbox', |
| 144 |
|
'#title' => t('Create new revision'), |
| 145 |
|
'#default_value' => $node->revision); |
| 146 |
} |
} |
| 147 |
if(user_access('Display authored on option')){ |
|
| 148 |
$form['options']['override_authored_on'] = array( |
$form['author'] = array( |
| 149 |
|
'#type' => 'fieldset', |
| 150 |
|
'#title' => t('Authoring information'), |
| 151 |
|
'#collapsible' => variable_get('override_node_options_collapsible', 1), |
| 152 |
|
'#collapsed' => variable_get('override_node_options_collapsed', 1), '#weight' => 20); |
| 153 |
|
|
| 154 |
|
if(user_access('override ' . $form['type']['#value'] . ' authored by option')){ |
| 155 |
|
$form['author']['override_authored_by'] = array( |
| 156 |
|
'#type' => 'textfield', |
| 157 |
|
'#title' => t('Authored by'), |
| 158 |
|
'#maxlength' => 60, |
| 159 |
|
'#default_value' => $node->name ? $node->name : '', |
| 160 |
|
'#weight' => -1, |
| 161 |
|
'#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))), |
| 162 |
|
); |
| 163 |
|
|
| 164 |
|
// User must have permission 'access user profiles' for autocomplete |
| 165 |
|
if (user_access('access user profiles')) { |
| 166 |
|
$form['author']['override_authored_by']['#autocomplete_path'] = 'user/autocomplete'; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
if(user_access('override ' . $form['type']['#value'] . ' authored on option')){ |
| 172 |
|
$form['author']['override_authored_on'] = array( |
| 173 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 174 |
'#title' => t('Authored on'), |
'#title' => t('Authored on'), |
| 175 |
'#maxlength' => 25, |
'#maxlength' => 25, |
| 211 |
'override_publishing_status' => 'status', |
'override_publishing_status' => 'status', |
| 212 |
'override_publishing_promote' => 'promote', |
'override_publishing_promote' => 'promote', |
| 213 |
'override_publishing_sticky' => 'sticky', |
'override_publishing_sticky' => 'sticky', |
| 214 |
'override_publishing_revision' => 'revision', |
'override_publishing_revision' => 'revision' |
|
|
|
| 215 |
); |
); |
| 216 |
foreach ($keys as $override_key => $real_key) { |
foreach ($keys as $override_key => $real_key) { |
| 217 |
if (isset($node->$override_key)) { |
if (isset($node->$override_key)) { |
| 218 |
$node->$real_key = $node->$override_key; |
$node->$real_key = $node->$override_key; |
| 219 |
} |
} |
| 220 |
} |
} |
| 221 |
if(user_access('Display authored on option')){ |
if(user_access('override authored on option')){ |
| 222 |
// Node creation date override |
// Node creation date override |
| 223 |
if ($node->date !== $node->override_authored_on || !empty($node->override_authored_on)) { |
if ($node->date !== $node->override_authored_on || !empty($node->override_authored_on)) { |
| 224 |
$node->created = !empty($node->override_authored_on) ? strtotime($node->override_authored_on) : time(); |
$node->created = !empty($node->override_authored_on) ? strtotime($node->override_authored_on) : time(); |
|
} |
|
| 225 |
} |
} |
| 226 |
|
} |
| 227 |
|
if ($node->name !== $node->override_authored_by) { |
| 228 |
|
if (!empty($node->override_authored_by)) { |
| 229 |
|
$account = user_load(array('name' => $node->override_authored_by)); |
| 230 |
|
$node->uid = $account->uid; |
| 231 |
|
} |
| 232 |
|
else { |
| 233 |
|
$node->uid = 0; |
| 234 |
|
} |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
} |
} |
| 240 |
break; |
break; |