Index: override_node_options.module
===================================================================
--- override_node_options.module (revision 154)
+++ override_node_options.module (working copy)
@@ -1,5 +1,5 @@
'Control which node publishing overrides users have.',
+ 'title' => 'Override Node Options',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('override_node_options_admin_settings'),
+ 'access arguments' => array('administer site configuration'),
+ );
+
+ return $items;
+}
+
+/**
* Implementation of hook_form_alter().
*/
-function override_node_options_form_alter($form_id, &$form) {
+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.
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && user_access('override node publishing options') && !user_access('administer nodes')) {
$node = $form['#node'];
- $form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25);
- $form['options']['override_publishing_status'] = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status);
- $form['options']['override_publishing_promote'] = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote);
- $form['options']['override_publishing_sticky'] = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky);
- $form['options']['override_publishing_revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
+
+ $publish_overrides = variable_get('override_node_options_publishing', 0);
+ $author_overrides = variable_get('override_node_options_author', 0);
+
+ $options = array(
+ 'status' => array('title' => t('Published'), 'default_value' => $node->status),
+ 'promote' => array('title' => t('Promoted to front page'), 'default_value' => $node->promote),
+ 'sticky' => array('title' => t('Sticky at top of lists'), 'default_value' => $node->sticky),
+ 'revision' => array('title' => t('Create new revision'), 'default_value' => $node->revision),
+ );
+
+ // Check to make sure at least one option was specified by admin
+ if (is_array($publish_overrides)) {
+ $form['options'] = array('#type' => 'fieldset', '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25);
+ foreach ($publish_overrides as $key => $value) {
+ if ($value) {
+ $form['options']['override_publishing_'.$key] = array('#type' => 'checkbox', '#title' => $options[$key]['title'], '#default_value' => $options[$key]['default_value']);
+ }
+ }
+ }
+
+ if (is_array($author_overrides)) {
+ $form['author'] = array('#type' => 'fieldset', '#title' => t('Authoring information'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 20);
+ if ($author_overrides['name']) {
+ global $user;
+ $form['author']['override_author_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Authored by'),
+ '#maxlength' => 60,
+ '#default_value' => $node->name ? $node->name : '',
+ '#weight' => -1,
+ '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
+ );
+ // User must have permission 'access user profiles' for autocomplete
+ if (user_access('access user profiles')) {
+ $form['author']['override_author_name']['#autocomplete_path'] = 'user/autocomplete';
+ }
+
+ }
+ if ($author_overrides['date']) {
+ $form['author']['override_author_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Authored on'),
+ '#maxlength' => 25,
+ '#default_value' => $node->date,
+ '#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'))),
+ );
+ }
+ }
}
}
@@ -36,9 +95,8 @@
*/
function override_node_options_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
- case 'submit':
- // Allow users with 'override node publishing options' to change node
- // options.
+ case 'presave':
+ // Allow users with 'override node publishing options' to change node publishing options.
// TODO: Once in core, remove adminster nodes check.
if (user_access('override node publishing options') && !user_access('administer nodes')) {
$keys = array(
@@ -47,12 +105,62 @@
'override_publishing_sticky' => 'sticky',
'override_publishing_revision' => 'revision',
);
+ // Publishing options
foreach ($keys as $override_key => $real_key) {
if (isset($node->$override_key)) {
$node->$real_key = $node->$override_key;
}
}
+ // Node creation date override
+ if ($node->date !== $node->override_author_date || !empty($node->override_author_date)) {
+ $node->created = !empty($node->override_author_date) ? strtotime($node->override_author_date) : time();
+ }
+ // Node author override
+ if ($node->name !== $node->override_author_name) {
+ if (!empty($node->override_author_name)) {
+ $account = user_load(array('name' => $node->override_author_name));
+ $node->uid = $account->uid;
+ }
+ else {
+ $node->uid = 0;
+ }
+ }
+
}
break;
}
}
+
+/**
+ * Admin settings form
+ */
+function override_node_options_admin_settings() {
+ $options = array(
+ 'status' => t('Published'),
+ 'promote' => t('Promoted to front page'),
+ 'sticky' => t('Sticky at top of lists'),
+ 'revision' => t('Create new revision'),
+ );
+
+ $author = array(
+ 'name' => t('Authored by'),
+ 'date' => t('Authored on'),
+ );
+
+ $form['override_node_options_publishing'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Available publishing overrides'),
+ '#default_value' => variable_get('override_node_options_publishing', $options),
+ '#options' => $options,
+ '#description' => t('Check only those publishing options you want users to be able to override. This setting applies to all users with roles including the permission override node publishing options.')
+ );
+ $form['override_node_options_author'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Available author overrides'),
+ '#default_value' => variable_get('override_node_options_author', $author),
+ '#options' => $author,
+ '#description' => t('Check only those authoring options you want users to be able to override. This setting applies to all users with roles including the permission override node publishing options. Grant with care! If you allow users to change the author, they may need permissions that allow them to edit \'any\' given content type - otherwise they can lock themselves out of their own nodes.')
+ );
+
+ return system_settings_form($form);
+}
\ No newline at end of file
Index: override_node_options.info
===================================================================
--- override_node_options.info (revision 154)
+++ override_node_options.info (working copy)
@@ -1,3 +1,4 @@
-; $Id: override_node_options.info,v 1.2.2.1 2007/06/18 23:06:56 dww Exp $
+; $Id:$
name = Override Node Publishing Options
description = "Allow non-admins to override the default publishing options for nodes they can edit."
+core = 6.x