572 lines
		
	
	
		
			19 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			572 lines
		
	
	
		
			19 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
// $Id$
 | 
						|
 | 
						|
/**
 | 
						|
 * @file
 | 
						|
 * Content administration and module settings UI.
 | 
						|
 */
 | 
						|
 | 
						|
/**
 | 
						|
 * Menu callback: confirm rebuilding of permissions.
 | 
						|
 */
 | 
						|
function node_configure_rebuild_confirm() {
 | 
						|
  return confirm_form(array(), t('Are you sure you want to rebuild the permissions on site content?'),
 | 
						|
                  'admin/reports/status', t('This action rebuilds all permissions on site content, and may be a lengthy process. This action cannot be undone.'), t('Rebuild permissions'), t('Cancel'));
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Handler for wipe confirmation
 | 
						|
 */
 | 
						|
function node_configure_rebuild_confirm_submit($form, &$form_state) {
 | 
						|
  node_access_rebuild(TRUE);
 | 
						|
  $form_state['redirect'] = 'admin/reports/status';
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Implement hook_node_operations().
 | 
						|
 */
 | 
						|
function node_node_operations() {
 | 
						|
  $operations = array(
 | 
						|
    'publish' => array(
 | 
						|
      'label' => t('Publish'),
 | 
						|
      'callback' => 'node_mass_update',
 | 
						|
      'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED)),
 | 
						|
    ),
 | 
						|
    'unpublish' => array(
 | 
						|
      'label' => t('Unpublish'),
 | 
						|
      'callback' => 'node_mass_update',
 | 
						|
      'callback arguments' => array('updates' => array('status' => NODE_NOT_PUBLISHED)),
 | 
						|
    ),
 | 
						|
    'promote' => array(
 | 
						|
      'label' => t('Promote to front page'),
 | 
						|
      'callback' => 'node_mass_update',
 | 
						|
      'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'promote' => NODE_PROMOTED)),
 | 
						|
    ),
 | 
						|
    'demote' => array(
 | 
						|
      'label' => t('Demote from front page'),
 | 
						|
      'callback' => 'node_mass_update',
 | 
						|
      'callback arguments' => array('updates' => array('promote' => NODE_NOT_PROMOTED)),
 | 
						|
    ),
 | 
						|
    'sticky' => array(
 | 
						|
      'label' => t('Make sticky'),
 | 
						|
      'callback' => 'node_mass_update',
 | 
						|
      'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'sticky' => NODE_STICKY)),
 | 
						|
    ),
 | 
						|
    'unsticky' => array(
 | 
						|
      'label' => t('Remove stickiness'),
 | 
						|
      'callback' => 'node_mass_update',
 | 
						|
      'callback arguments' => array('updates' => array('sticky' => NODE_NOT_STICKY)),
 | 
						|
    ),
 | 
						|
    'delete' => array(
 | 
						|
      'label' => t('Delete'),
 | 
						|
      'callback' => NULL,
 | 
						|
    ),
 | 
						|
  );
 | 
						|
  return $operations;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * List node administration filters that can be applied.
 | 
						|
 */
 | 
						|
function node_filters() {
 | 
						|
  // Regular filters
 | 
						|
  $filters['status'] = array(
 | 
						|
    'title' => t('status'),
 | 
						|
    'options' => array(
 | 
						|
      '[any]' => t('any'),
 | 
						|
      'status-1' => t('published'),
 | 
						|
      'status-0' => t('not published'),
 | 
						|
      'promote-1' => t('promoted'),
 | 
						|
      'promote-0' => t('not promoted'),
 | 
						|
      'sticky-1' => t('sticky'),
 | 
						|
      'sticky-0' => t('not sticky'),
 | 
						|
    ),
 | 
						|
  );
 | 
						|
  // Include translation states if we have this module enabled
 | 
						|
  if (module_exists('translation')) {
 | 
						|
    $filters['status']['options'] += array(
 | 
						|
      'translate-0' => t('Up to date translation'),
 | 
						|
      'translate-1' => t('Outdated translation'),
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  $filters['type'] = array(
 | 
						|
    'title' => t('type'),
 | 
						|
    'options' => array(
 | 
						|
      '[any]' => t('any'),
 | 
						|
    ) + node_type_get_names(),
 | 
						|
  );
 | 
						|
 | 
						|
  // The taxonomy filter
 | 
						|
  if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
 | 
						|
    $filters['term'] = array(
 | 
						|
      'title' => t('term'),
 | 
						|
      'options' => array(
 | 
						|
        '[any]' => t('any'),
 | 
						|
      ) + $taxonomy,
 | 
						|
    );
 | 
						|
  }
 | 
						|
  // Language filter if there is a list of languages
 | 
						|
  if ($languages = module_invoke('locale', 'language_list')) {
 | 
						|
    $languages = array('' => t('Language neutral')) + $languages;
 | 
						|
    $filters['language'] = array(
 | 
						|
      'title' => t('language'),
 | 
						|
      'options' => array(
 | 
						|
        '[any]' => t('any'),
 | 
						|
      ) + $languages,
 | 
						|
    );
 | 
						|
  }
 | 
						|
  return $filters;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Apply filters for node administration filters based on session.
 | 
						|
 *
 | 
						|
 * @param $query
 | 
						|
 *   A SelectQuery to which the filters should be applied.
 | 
						|
 */
 | 
						|
function node_build_filter_query(SelectQueryInterface $query) {
 | 
						|
  // Build query
 | 
						|
  $filter_data = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
 | 
						|
  $counter = 0;
 | 
						|
  foreach ($filter_data as $index => $filter) {
 | 
						|
    list($key, $value) = $filter;
 | 
						|
    switch ($key) {
 | 
						|
      case 'term':
 | 
						|
        $index = 'tn' . $counter++;
 | 
						|
        $query->join('taxonomy_term_node', $index, "n.nid = $index.nid");
 | 
						|
        $query->condition($index . '.tid', $value);
 | 
						|
        break;
 | 
						|
      case 'status':
 | 
						|
        // Note: no exploitable hole as $key/$value have already been checked when submitted
 | 
						|
        list($key, $value) = explode('-', $value, 2);
 | 
						|
      case 'type':
 | 
						|
      case 'language':
 | 
						|
        $query->condition('n.' . $key, $value);
 | 
						|
        break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Return form for node administration filters.
 | 
						|
 */
 | 
						|
function node_filter_form() {
 | 
						|
  $session = isset($_SESSION['node_overview_filter']) ? $_SESSION['node_overview_filter'] : array();
 | 
						|
  $filters = node_filters();
 | 
						|
 | 
						|
  $i = 0;
 | 
						|
  $form['filters'] = array(
 | 
						|
    '#type' => 'fieldset',
 | 
						|
    '#title' => t('Show only items where'),
 | 
						|
    '#theme' => 'node_filters',
 | 
						|
  );
 | 
						|
  foreach ($session as $filter) {
 | 
						|
    list($type, $value) = $filter;
 | 
						|
    if ($type == 'term') {
 | 
						|
      // Load term name from DB rather than search and parse options array.
 | 
						|
      $value = module_invoke('taxonomy', 'term_load', $value);
 | 
						|
      $value = $value->name;
 | 
						|
    }
 | 
						|
    elseif ($type == 'language') {
 | 
						|
      $value = empty($value) ? t('Language neutral') : module_invoke('locale', 'language_name', $value);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
      $value = $filters[$type]['options'][$value];
 | 
						|
    }
 | 
						|
    if ($i++) {
 | 
						|
      $form['filters']['current'][] = array('#markup' => t('<em>and</em> where <strong>%type</strong> is <strong>%value</strong>', array('%type' => $filters[$type]['title'], '%value' => $value)));
 | 
						|
    }
 | 
						|
    else {
 | 
						|
      $form['filters']['current'][] = array('#markup' => t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => $filters[$type]['title'], '%value' => $value)));
 | 
						|
    }
 | 
						|
    if (in_array($type, array('type', 'language'))) {
 | 
						|
      // Remove the option if it is already being filtered on.
 | 
						|
      unset($filters[$type]);
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  foreach ($filters as $key => $filter) {
 | 
						|
    $names[$key] = $filter['title'];
 | 
						|
    $form['filters']['status'][$key] = array(
 | 
						|
      '#type' => 'select',
 | 
						|
      '#options' => $filter['options'],
 | 
						|
      '#title' => $filter['title'],
 | 
						|
      '#default_value' => '[any]',
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  $form['filters']['buttons']['submit'] = array('#type' => 'submit', '#value' => (count($session) ? t('Refine') : t('Filter')));
 | 
						|
  if (count($session)) {
 | 
						|
    $form['filters']['buttons']['undo'] = array('#type' => 'submit', '#value' => t('Undo'));
 | 
						|
    $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset'));
 | 
						|
  }
 | 
						|
 | 
						|
  drupal_add_js('misc/form.js');
 | 
						|
 | 
						|
  return $form;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Theme node administration filter form.
 | 
						|
 *
 | 
						|
 * @ingroup themeable
 | 
						|
 */
 | 
						|
function theme_node_filter_form($variables) {
 | 
						|
  $form = $variables['form'];
 | 
						|
  $output = '';
 | 
						|
 | 
						|
  $output .= '<div id="node-admin-filter">';
 | 
						|
  $output .= drupal_render($form['filters']);
 | 
						|
  $output .= '</div>';
 | 
						|
  $output .= drupal_render_children($form);
 | 
						|
  return $output;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Theme node administration filter selector.
 | 
						|
 *
 | 
						|
 * @ingroup themeable
 | 
						|
 */
 | 
						|
function theme_node_filters($variables) {
 | 
						|
  $form = $variables['form'];
 | 
						|
  $output = '';
 | 
						|
 | 
						|
  $output .= '<ul class="clearfix">';
 | 
						|
  if (!empty($form['current'])) {
 | 
						|
    foreach (element_children($form['current']) as $key) {
 | 
						|
      $output .= '<li>' . drupal_render($form['current'][$key]) . '</li>';
 | 
						|
    }
 | 
						|
  }
 | 
						|
  $output .= '</ul>';
 | 
						|
 | 
						|
  $output .= '<dl class="multiselect">' . (!empty($form['current']) ? '<dt><em>' . t('and') . '</em> ' . t('where') . '</dt>' : '');
 | 
						|
 | 
						|
  $output .= '<dd class="b">';
 | 
						|
 | 
						|
  foreach (element_children($form['status']) as $key) {
 | 
						|
    $output .= drupal_render($form['status'][$key]);
 | 
						|
  }
 | 
						|
  $output .= '</dd>';
 | 
						|
 | 
						|
  $output .= '</dl>';
 | 
						|
  $output .= '<div class="container-inline" id="node-admin-buttons">' . drupal_render($form['buttons']) . '</div>';
 | 
						|
 | 
						|
  return $output;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Process result from node administration filter form.
 | 
						|
 */
 | 
						|
function node_filter_form_submit($form, &$form_state) {
 | 
						|
  $filters = node_filters();
 | 
						|
  switch ($form_state['values']['op']) {
 | 
						|
    case t('Filter'):
 | 
						|
    case t('Refine'):
 | 
						|
      // Apply every filter that has a choice selected other than 'any'.
 | 
						|
      foreach ($filters as $filter => $options) {
 | 
						|
        if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
 | 
						|
          // Flatten the options array to accommodate hierarchical/nested options.
 | 
						|
          $flat_options = form_options_flatten($filters[$filter]['options']);
 | 
						|
          // Only accept valid selections offered on the dropdown, block bad input.
 | 
						|
          if (isset($flat_options[$form_state['values'][$filter]])) {
 | 
						|
            $_SESSION['node_overview_filter'][] = array($filter, $form_state['values'][$filter]);
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case t('Undo'):
 | 
						|
      array_pop($_SESSION['node_overview_filter']);
 | 
						|
      break;
 | 
						|
    case t('Reset'):
 | 
						|
      $_SESSION['node_overview_filter'] = array();
 | 
						|
      break;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Make mass update of nodes, changing all nodes in the $nodes array
 | 
						|
 * to update them with the field values in $updates.
 | 
						|
 *
 | 
						|
 * IMPORTANT NOTE: This function is intended to work when called
 | 
						|
 * from a form submit handler. Calling it outside of the form submission
 | 
						|
 * process may not work correctly.
 | 
						|
 *
 | 
						|
 * @param array $nodes
 | 
						|
 *   Array of node nids to update.
 | 
						|
 * @param array $updates
 | 
						|
 *   Array of key/value pairs with node field names and the
 | 
						|
 *   value to update that field to.
 | 
						|
 */
 | 
						|
function node_mass_update($nodes, $updates) {
 | 
						|
  // We use batch processing to prevent timeout when updating a large number
 | 
						|
  // of nodes.
 | 
						|
  if (count($nodes) > 10) {
 | 
						|
    $batch = array(
 | 
						|
      'operations' => array(
 | 
						|
        array('_node_mass_update_batch_process', array($nodes, $updates))
 | 
						|
      ),
 | 
						|
      'finished' => '_node_mass_update_batch_finished',
 | 
						|
      'title' => t('Processing'),
 | 
						|
      // We use a single multi-pass operation, so the default
 | 
						|
      // 'Remaining x of y operations' message will be confusing here.
 | 
						|
      'progress_message' => '',
 | 
						|
      'error_message' => t('The update has encountered an error.'),
 | 
						|
      // The operations do not live in the .module file, so we need to
 | 
						|
      // tell the batch engine which file to load before calling them.
 | 
						|
      'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
 | 
						|
    );
 | 
						|
    batch_set($batch);
 | 
						|
  }
 | 
						|
  else {
 | 
						|
    foreach ($nodes as $nid) {
 | 
						|
      _node_mass_update_helper($nid, $updates);
 | 
						|
    }
 | 
						|
    drupal_set_message(t('The update has been performed.'));
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Node Mass Update - helper function.
 | 
						|
 */
 | 
						|
function _node_mass_update_helper($nid, $updates) {
 | 
						|
  $node = node_load($nid, NULL, TRUE);
 | 
						|
  foreach ($updates as $name => $value) {
 | 
						|
    $node->$name = $value;
 | 
						|
  }
 | 
						|
  node_save($node);
 | 
						|
  return $node;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Node Mass Update Batch operation
 | 
						|
 */
 | 
						|
function _node_mass_update_batch_process($nodes, $updates, &$context) {
 | 
						|
  if (!isset($context['sandbox']['progress'])) {
 | 
						|
    $context['sandbox']['progress'] = 0;
 | 
						|
    $context['sandbox']['max'] = count($nodes);
 | 
						|
    $context['sandbox']['nodes'] = $nodes;
 | 
						|
  }
 | 
						|
 | 
						|
  // Process nodes by groups of 5.
 | 
						|
  $count = min(5, count($context['sandbox']['nodes']));
 | 
						|
  for ($i = 1; $i <= $count; $i++) {
 | 
						|
    // For each nid, load the node, reset the values, and save it.
 | 
						|
    $nid = array_shift($context['sandbox']['nodes']);
 | 
						|
    $node = _node_mass_update_helper($nid, $updates);
 | 
						|
 | 
						|
    // Store result for post-processing in the finished callback.
 | 
						|
    $context['results'][] = l($node->title[FIELD_LANGUAGE_NONE][0]['value'], 'node/' . $node->nid);
 | 
						|
 | 
						|
    // Update our progress information.
 | 
						|
    $context['sandbox']['progress']++;
 | 
						|
  }
 | 
						|
 | 
						|
  // Inform the batch engine that we are not finished,
 | 
						|
  // and provide an estimation of the completion level we reached.
 | 
						|
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
 | 
						|
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Node Mass Update Batch 'finished' callback.
 | 
						|
 */
 | 
						|
function _node_mass_update_batch_finished($success, $results, $operations) {
 | 
						|
  if ($success) {
 | 
						|
    drupal_set_message(t('The update has been performed.'));
 | 
						|
  }
 | 
						|
  else {
 | 
						|
    drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
 | 
						|
    $message = format_plural(count($results), '1 item successfully processed:', '@count items successfully processed:');
 | 
						|
    $message .= theme('item_list', array('items' => $results));
 | 
						|
    drupal_set_message($message);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Menu callback: content administration.
 | 
						|
 */
 | 
						|
function node_admin_content($form, $form_state) {
 | 
						|
  if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
 | 
						|
    return node_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['nodes']));
 | 
						|
  }
 | 
						|
  // Show the 'add new content' link.
 | 
						|
  $form['add_content'] = array(
 | 
						|
    '#access' => _node_add_access(),
 | 
						|
    '#markup' => theme('links', array('links' => array(array('title' => t('Add new content'), 'href' => 'node/add')), 'attributes' => array('class' => array('action-links')))),
 | 
						|
  );
 | 
						|
  $form[] = node_filter_form();
 | 
						|
  $form['#submit'][] = 'node_filter_form_submit';
 | 
						|
  $form['#theme'] = 'node_filter_form';
 | 
						|
  $form['admin'] = node_admin_nodes();
 | 
						|
 | 
						|
  return $form;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Form builder: Builds the node administration overview.
 | 
						|
 */
 | 
						|
function node_admin_nodes() {
 | 
						|
  // Enable language column if translation module is enabled
 | 
						|
  // or if we have any node with language.
 | 
						|
  $multilanguage = (module_exists('translation') || db_query("SELECT COUNT(*) FROM {node} WHERE language <> ''")->fetchField());
 | 
						|
 | 
						|
  // Build the sortable table header.
 | 
						|
  $header = array(
 | 
						|
    'title' => array('data' => t('Title'), 'field' => 'n.title'),
 | 
						|
    'type' => array('data' => t('Type'), 'field' => 'n.type'),
 | 
						|
    'author' => array('data' => t('Author'), 'field' => 'u.name'),
 | 
						|
    'status' => array('data' => t('Status'), 'field' => 'n.status'),
 | 
						|
    'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc')
 | 
						|
  );
 | 
						|
  if ($multilanguage) {
 | 
						|
    $header['language'] = array('data' => t('Language'), 'field' => 'n.language');
 | 
						|
  }
 | 
						|
  $header['operations'] = array('data' => t('Operations'));
 | 
						|
  
 | 
						|
  $query = db_select('node', 'n')->extend('PagerDefault')->extend('TableSort');
 | 
						|
  $query->join('users', 'u', 'n.uid = u.uid');
 | 
						|
  node_build_filter_query($query);
 | 
						|
 | 
						|
  $result = $query
 | 
						|
    ->fields('n')
 | 
						|
    ->fields('u', array('name'))
 | 
						|
    ->limit(50)
 | 
						|
    ->orderByHeader($header)
 | 
						|
    ->execute();
 | 
						|
 | 
						|
  // Build the 'Update options' form.
 | 
						|
  $form['options'] = array(
 | 
						|
    '#type' => 'fieldset',
 | 
						|
    '#title' => t('Update options'),
 | 
						|
    '#prefix' => '<div class="container-inline">',
 | 
						|
    '#suffix' => '</div>',
 | 
						|
  );
 | 
						|
  $options = array();
 | 
						|
  foreach (module_invoke_all('node_operations') as $operation => $array) {
 | 
						|
    $options[$operation] = $array['label'];
 | 
						|
  }
 | 
						|
  $form['options']['operation'] = array(
 | 
						|
    '#type' => 'select',
 | 
						|
    '#options' => $options,
 | 
						|
    '#default_value' => 'approve',
 | 
						|
  );
 | 
						|
  $options = array();
 | 
						|
  $form['options']['submit'] = array(
 | 
						|
    '#type' => 'submit',
 | 
						|
    '#value' => t('Update'),
 | 
						|
    '#submit' => array('node_admin_nodes_submit'),
 | 
						|
    '#validate' => array('node_admin_nodes_validate'),
 | 
						|
  );
 | 
						|
 | 
						|
  $languages = language_list();
 | 
						|
  $destination = drupal_get_destination();
 | 
						|
  $nodes = array();
 | 
						|
  foreach ($result as $node) {
 | 
						|
    $l_options = empty($node->language) ? array() : array('language' => $languages[$node->language]);
 | 
						|
    $options[$node->nid] = array(
 | 
						|
      'title' => l($node->title, 'node/' . $node->nid, $l_options) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
 | 
						|
      'type' =>  check_plain(node_type_get_name($node)),
 | 
						|
      'author' => theme('username', array('account' => $node)),
 | 
						|
      'status' =>  $node->status ? t('published') : t('not published'),
 | 
						|
      'changed' => format_date($node->changed, 'short'),
 | 
						|
    );
 | 
						|
    if ($multilanguage) {
 | 
						|
      $options[$node->nid]['language'] = empty($node->language) ? t('Language neutral') : t($languages[$node->language]->name);
 | 
						|
    }
 | 
						|
    $options[$node->nid]['operations'] = l(t('edit'), 'node/' . $node->nid . '/edit', array('query' => $destination));
 | 
						|
  }
 | 
						|
  $form['nodes'] = array(
 | 
						|
    '#type' => 'tableselect',
 | 
						|
    '#header' => $header,
 | 
						|
    '#options' => $options,
 | 
						|
    '#empty' => t('No content available.'),
 | 
						|
  );
 | 
						|
  $form['pager'] = array('#markup' => theme('pager', array('tags' => NULL)));
 | 
						|
  return $form;
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Validate node_admin_nodes form submissions.
 | 
						|
 *
 | 
						|
 * Check if any nodes have been selected to perform the chosen
 | 
						|
 * 'Update option' on.
 | 
						|
 */
 | 
						|
function node_admin_nodes_validate($form, &$form_state) {
 | 
						|
  // Error if there are no items to select.
 | 
						|
  if (!is_array($form_state['values']['nodes']) || !count(array_filter($form_state['values']['nodes']))) {
 | 
						|
    form_set_error('', t('No items selected.'));
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Process node_admin_nodes form submissions.
 | 
						|
 *
 | 
						|
 * Execute the chosen 'Update option' on the selected nodes.
 | 
						|
 */
 | 
						|
function node_admin_nodes_submit($form, &$form_state) {
 | 
						|
  $operations = module_invoke_all('node_operations');
 | 
						|
  $operation = $operations[$form_state['values']['operation']];
 | 
						|
  // Filter out unchecked nodes
 | 
						|
  $nodes = array_filter($form_state['values']['nodes']);
 | 
						|
  if ($function = $operation['callback']) {
 | 
						|
    // Add in callback arguments if present.
 | 
						|
    if (isset($operation['callback arguments'])) {
 | 
						|
      $args = array_merge(array($nodes), $operation['callback arguments']);
 | 
						|
    }
 | 
						|
    else {
 | 
						|
      $args = array($nodes);
 | 
						|
    }
 | 
						|
    call_user_func_array($function, $args);
 | 
						|
 | 
						|
    cache_clear_all();
 | 
						|
  }
 | 
						|
  else {
 | 
						|
    // We need to rebuild the form to go to a second step. For example, to
 | 
						|
    // show the confirmation form for the deletion of nodes.
 | 
						|
    $form_state['rebuild'] = TRUE;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
function node_multiple_delete_confirm($form, &$form_state, $nodes) {
 | 
						|
  $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
 | 
						|
  // array_filter returns only elements with TRUE values
 | 
						|
  foreach ($nodes as $nid => $value) {
 | 
						|
    $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
 | 
						|
    $form['nodes'][$nid] = array(
 | 
						|
      '#type' => 'hidden',
 | 
						|
      '#value' => $nid,
 | 
						|
      '#prefix' => '<li>',
 | 
						|
      '#suffix' => check_plain($title) . "</li>\n",
 | 
						|
    );
 | 
						|
  }
 | 
						|
  $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
 | 
						|
  $form['#submit'][] = 'node_multiple_delete_confirm_submit';
 | 
						|
  $confirm_question = format_plural(count($nodes),
 | 
						|
                                  'Are you sure you want to delete this item?',
 | 
						|
                                  'Are you sure you want to delete these items?');
 | 
						|
  return confirm_form($form,
 | 
						|
                    $confirm_question,
 | 
						|
                    'admin/content', t('This action cannot be undone.'),
 | 
						|
                    t('Delete'), t('Cancel'));
 | 
						|
}
 | 
						|
 | 
						|
function node_multiple_delete_confirm_submit($form, &$form_state) {
 | 
						|
  if ($form_state['values']['confirm']) {
 | 
						|
    node_delete_multiple(array_keys($form_state['values']['nodes']));
 | 
						|
    $count = count($form_state['values']['nodes']);
 | 
						|
    watchdog('content', 'Deleted @count posts.', array('@count' => $count));
 | 
						|
    drupal_set_message(t('Deleted @count posts.', array('@count' => $count)));
 | 
						|
  }
 | 
						|
  $form_state['redirect'] = 'admin/content';
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Implement hook_modules_installed()
 | 
						|
 */
 | 
						|
function node_modules_installed($modules) {
 | 
						|
  // Clear node type cache for node permissions.
 | 
						|
  drupal_static_reset('_node_types_build');
 | 
						|
}
 |