You are here

function user_revision_overview in User Revision 7

Same name and namespace in other branches
  1. 7.2 user_revision.pages.inc \user_revision_overview()

Generate an overview table of older revisions of a user.

1 string reference to 'user_revision_overview'
user_revision_menu in ./user_revision.module
Implements hook_menu().

File

./user_revision.pages.inc, line 11
UI pages for revisions, copy-paste from node.pages.inc.

Code

function user_revision_overview($viewed_user) {
  global $user;
  drupal_set_title(t('Revisions for %title', array(
    '%title' => $viewed_user->name,
  )), PASS_THROUGH);
  $header = array(
    t('Revision'),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $revisions = user_revision_list($viewed_user);
  $rows = array();
  $revert_permission = FALSE;
  $delete_permission = FALSE;
  if ($user->uid == $viewed_user->uid) {
    if (user_access('revert own user revisions') || user_access('revert user revisions')) {
      $revert_permission = TRUE;
    }
    if (user_access('delete own user revisions') || user_access('delete user revisions')) {
      $delete_permission = TRUE;
    }
  }
  else {
    if (user_access('revert user revisions')) {
      $revert_permission = TRUE;
    }
    if (user_access('delete user revisions')) {
      $delete_permission = TRUE;
    }
  }
  foreach ($revisions as $revision) {
    $row = array();
    $operations = array();
    if ($revision->current_vid > 0) {
      $row[] = array(
        'data' => t('!date by !username', array(
          '!date' => l(format_date($revision->timestamp, 'short'), "user/{$viewed_user->uid}"),
          '!username' => theme('username', array(
            'account' => $revision,
          )),
        )) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
        'class' => array(
          'revision-current',
        ),
      );
      $operations[] = array(
        'data' => drupal_placeholder(t('current revision')),
        'class' => array(
          'revision-current',
        ),
        'colspan' => 2,
      );
    }
    else {
      $row[] = t('!date by !username', array(
        '!date' => l(format_date($revision->timestamp, 'short'), "user/{$viewed_user->uid}/revisions/{$revision->vid}/view"),
        '!username' => theme('username', array(
          'account' => $revision,
        )),
      )) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : '');
      if ($revert_permission) {
        $operations[] = l(t('revert'), "user/{$viewed_user->uid}/revisions/{$revision->vid}/revert");
      }
      else {

        // Empty row for theming purposes.
        $operations[] = "";
      }
      if ($delete_permission) {
        $operations[] = l(t('delete'), "user/{$viewed_user->uid}/revisions/{$revision->vid}/delete");
      }
      else {

        // Empty row for theming purposes.
        $operations[] = "";
      }
    }
    $rows[] = array_merge($row, $operations);
  }
  $build['user_revisions_table'] = array(
    '#theme' => 'table',
    '#rows' => $rows,
    '#header' => $header,
  );
  return $build;
}