Index: modr8_admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8_admin.inc,v retrieving revision 1.2.2.11 diff -u -r1.2.2.11 modr8_admin.inc --- modr8_admin.inc 13 Dec 2007 00:58:46 -0000 1.2.2.11 +++ modr8_admin.inc 15 Jan 2008 20:51:25 -0000 @@ -29,6 +29,49 @@ '#options' => $period, '#description' => t('The time log entries should be kept. Older entries will be automatically discarded. Requires crontab.') ); + + $form['taxonomy'] = array( + '#type' => 'fieldset', + '#title' => t('Moderated taxonomy vocabularies'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('Vocabularies selected below will appear on the content moderation form, allowing moderators to change terms within these vocabularies while approving content.'), + '#access' => module_exists('taxonomy'), + ); + + $options = array(); + foreach ((array)module_invoke('taxonomy', 'get_vocabularies') as $vid => $vocabulary) { + $options[$vid] = $vocabulary->name; + } + + $form['taxonomy']['modr8_vocabularies'] = array( + '#type' => 'checkboxes', + '#options' => $options, + '#default_value' => variable_get('modr8_vocabularies', array()), + '#access' => module_exists('taxonomy'), + ); + + $form['content'] = array( + '#type' => 'fieldset', + '#title' => t('Moderated CCK fields'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('Fields selected below will appear on the content moderation form, allowing moderators to change the user-submitted value of a field while approving content.'), + '#access' => module_exists('content'), + ); + + $options = array(); + foreach ((array)module_invoke('content', 'fields') as $key => $field) { + $options[$key] = $field['field_name']; + } + + $form['content']['modr8_content_fields'] = array( + '#type' => 'checkboxes', + '#options' => $options, + '#default_value' => variable_get('modr8_content_fields', array()), + '#access' => module_exists('content'), + ); + $form['text'] = array( '#type' => 'fieldset', '#title' => t('E-mail'), @@ -182,6 +225,66 @@ '#type' => 'value', '#value' => node_get_types('name', $node), ); + + // Add taxonomy to moderation. + if (module_exists('taxonomy')) { + // Create a dummy form for adding taxonomy vocabularies. + $taxonomy_subform = array( + '#node' => $node, + 'type' => array('#value' => $node->type), + ); + taxonomy_form_alter($node->type .'_node_form', $taxonomy_subform); + unset($taxonomy_subform['type']); + + // Reduce added vocabularies to moderation enabled only. + $vocabularies = taxonomy_get_vocabularies($node->type); + $enabled_vocabularies = variable_get('modr8_vocabularies', array()); + foreach ($vocabularies as $vid => $vocabulary) { + if (!$enabled_vocabularies[$vid]) { + // Change the disabled vocabularies to #type = value to maintain the value on submit. + if (isset($taxonomy_subform['taxonomy'][$vid])) { + $taxonomy_subform['taxonomy'][$vid]['#type'] = 'value'; + $taxonomy_subform['taxonomy'][$vid]['#value'] = $taxonomy_subform['taxonomy'][$vid]['#default_value']; + unset($taxonomy_subform['taxonomy'][$vid]['#theme']); + } + if (isset($taxonomy_subform['taxonomy']['tags'][$vid])) { + $taxonomy_subform['taxonomy']['tags'][$vid]['#type'] = 'value'; + $taxonomy_subform['taxonomy']['tags'][$vid]['#value'] = $taxonomy_subform['taxonomy']['tags'][$vid]['#default_value']; + } + } + } + + // Add the custom form for this node. + $form[$node->nid]['taxonomy'] = $taxonomy_subform; + } + + // Add content fields to moderation. + if (module_exists('content')) { + // Create a dummy form for adding content fields. + $content_subform = array( + '#node' => $node, + 'type' => array('#value' => $node->type), + ); + content_form_alter($node->type .'_node_form', $content_subform); + unset($content_subform['type']); + + // Reduce added fields to moderation enabled only. + $fields = content_fields(NULL, $node->type); + $enabled_fields = variable_get('modr8_content_fields', array()); + foreach ($fields as $key => $field) { + if (!$enabled_fields[$key] && isset($content_subform[$key])) { + unset($content_subform[$key]); // Remove from the displayed form. + unset($content_subform['#node']->$key); // Remove from the node to avoid submit processing. + } + } + + // Put into a value field to have the node accessible during submit. + $content_subform['node'] = array('#type' => 'value', '#value' => $content_subform['#node']); + + // Add the custom form for this node. + $form[$node->nid]['content'] = $content_subform; + } + } $form['submit'] = array( '#type' => 'submit', @@ -207,7 +310,7 @@ $note_field = drupal_render($form[$key]['note']); } $row[] = array( - 'data' => drupal_render($form[$key]['ops']) . $note_field, + 'data' => drupal_render($form[$key]['ops']) . drupal_render($form[$key]['taxonomy']) . drupal_render($form[$key]['content']) . $note_field, 'style' => 'vertical-align:top;' ); $preview = $form[$key]['preview']['#value']; @@ -245,6 +348,26 @@ } db_query('UPDATE {node} SET moderate = 0 '. $publish .' WHERE nid = %d', $nid); drupal_set_message(t('The %type with title %title has been approved.', array('%title' => $values['title'], '%type' => $values['type']))); + + if (module_exists('taxonomy')) { + taxonomy_node_save($nid, $values['taxonomy']['taxonomy']); + } + + if (module_exists('content')) { + $fields = content_fields(); + $enabled_fields = variable_get('modr8_content_fields', array('field_image_reference' => 1, 'field_quality_rating' => 1)); + $node = $values['content']['node']; + + // Update each changed field with the new value set by moderator. + foreach ($fields as $key => $field) { + if ($enabled_fields[$key] && isset($values['content'][$key])) { + $node->$key = $values['content'][$key]; + } + } + content_submit($node); + content_update($node); + } + cache_clear_all(); modr8_log_action('approve', $nid, $values, $message); break;