You are here

function block_revisions_overview in Block Revisions 7

Same name and namespace in other branches
  1. 6 block_revisions.admin.inc \block_revisions_overview()

Menu callback for the revisions overview page.

This page lists all the revisions for a specific custom block.

1 string reference to 'block_revisions_overview'
block_revisions_menu in ./block_revisions.module
Implements hook_menu().

File

./block_revisions.admin.inc, line 88
Admin functions and page callbacks for the Block Revisions module.

Code

function block_revisions_overview($delta) {
  $output = '';

  // Fetch information about the block and the current revision from the database.
  $block = db_query('SELECT b.info, b.timestamp, b.uid FROM {block_custom} b WHERE b.bid = :bid', array(
    ':bid' => $delta,
  ))
    ->fetchObject();

  // Set the title for the page.
  drupal_set_title(t("Revisions for '%title' block", array(
    '%title' => $block->info,
  )), PASS_THROUGH);

  // Fetch a list of revisions for this custom block from the database.
  $revisions = block_revision_list($delta);
  $latest_revision = reset($revisions);

  // By comparing the timestamp of the block with the timestamp of the
  // most recent revision, we can determine if the block was altered
  // after that revision was created. If it is, warn the user that
  // the most recent revision differs from the actual block content.
  if ($block->timestamp !== $latest_revision->timestamp) {
    $account = array_shift(user_load_multiple(array(
      $block->uid,
    )));
    drupal_set_message(t('Warning: the block has been altered since the most recent revision. The latest, non-versioned, edit was made by !username on %timestamp.', array(
      '!username' => theme('username', array(
        'account' => $account,
      )),
      '%timestamp' => format_date($block->timestamp),
    )), 'warning');
  }
  $header = array(
    t('Revision'),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $rows = array();
  foreach ($revisions as $revision) {
    $row = array();
    $operations = array();
    $row[] = array(
      'data' => t('!date by !username', array(
        '!date' => format_date($revision->timestamp, 'short'),
        '!username' => theme('username', array(
          'account' => $revision,
        )),
      )) . ($revision->log != '' ? '<p class="revision-log">' . check_plain($revision->log) . '</p>' : ''),
    );
    if ($revision->vid == 0) {
      $operations[] = array(
        'data' => drupal_placeholder(t('current revision')),
        'class' => 'revision-current',
        'colspan' => 2,
      );
      $row[0]['class'] = 'revision-current';
    }
    else {
      $operations[] = l(t('revert'), "admin/structure/block/revisions/revert/{$delta}/{$revision->vid}");
      $operations[] = l(t('delete'), "admin/structure/block/revisions/delete/{$delta}/{$revision->vid}");
    }
    $rows[] = array_merge($row, $operations);
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  return $output;
}