You are here

function revisioning_block in Revisioning 6.3

Same name and namespace in other branches
  1. 6.4 revisioning.module \revisioning_block()

Implementation of hook_block().

A block that may be placed on all or selected pages, alerting the user (moderator) when new content has been submitted for review. Shows titles of pending revisions as a series of links (max. number configurable). Clicking a link takes the moderator straight to the revision in question.

File

./revisioning.module, line 476
Allows the creation and modification of pre-published as well as live content while the current revision remains unchanged and publicly visible until the changes have been reviewed by a moderator.

Code

function revisioning_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':

      // Set up the defaults for the Site configuration>>Blocks page
      // Return a list of (1) block(s) and the default values
      $blocks[0]['info'] = t('Pending revisions');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      $blocks[0]['weight'] = -10;

      // top of whatever region is chosen
      $blocks[0]['custom'] = FALSE;

      // block is implemented by this module;
      return $blocks;
    case 'configure':
      $form['revisioning_block_num_pending'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum number of pending revisions displayed'),
        '#default_value' => variable_get('revisioning_block_num_pending', 5),
        '#description' => t('Note: the title of this block mentions the total number of revisions pending, which may be greater than the number of revisions displayed.'),
      );
      $form['revisioning_block_order'] = array(
        '#type' => 'radios',
        '#title' => t('Order in which pending revisions are displayed'),
        '#options' => array(
          REVISIONS_BLOCK_OLDEST_AT_TOP => t('Oldest at top'),
          REVISIONS_BLOCK_NEWEST_AT_TOP => t('Newest at top'),
        ),
        '#default_value' => variable_get('revisioning_block_order', REVISIONS_BLOCK_OLDEST_AT_TOP),
        '#description' => t('Note: order is based on revision timestamps.'),
      );
      $form['revisioning_content_summary_page'] = array(
        '#type' => 'textfield',
        '#title' => t('Page to go to when the block title is clicked'),
        '#default_value' => variable_get('revisioning_content_summary_page', ''),
        '#description' => t('When left blank this will default to %accessible_content, provided Module Grants Montior is enabled and the user has sufficient permissions. Otherwise %admin_content is used, subject to permissions. For any of this to work the above <strong>Block title</strong> field must be left blank.', array(
          '%accessible_content' => 'accessible-content',
          '%admin_content' => 'admin/content/node',
        )),
      );
      return $form;
    case 'save':
      variable_set('revisioning_block_num_pending', (int) $edit['revisioning_block_num_pending']);
      variable_set('revisioning_block_order', (int) $edit['revisioning_block_order']);
      variable_set('revisioning_content_summary_page', $edit['revisioning_content_summary_page']);
      break;
    case 'view':
      $max_nodes = variable_get('revisioning_block_num_pending', 100);
      $order = variable_get('revisioning_block_order', REVISIONS_BLOCK_OLDEST_AT_TOP) == REVISIONS_BLOCK_OLDEST_AT_TOP ? 'ASC' : 'DESC';
      $nodes = node_tools_get_nodes('update', NO_FILTER, NO_FILTER, NO_FILTER, TRUE, TRUE, $max_nodes, 'timestamp ' . $order);
      if (!empty($nodes)) {
        return _theme_revisions_pending_block($nodes);
      }
  }
}