You are here

function path_redirect_admin in Path redirect 5

Render a list of redirects for the main admin page.

1 string reference to 'path_redirect_admin'
path_redirect_menu in ./path_redirect.module
Implementation of hook_menu

File

./path_redirect.module, line 144

Code

function path_redirect_admin() {
  $header = array(
    array(
      'data' => t('From'),
      'field' => 'path',
      'sort' => 'asc',
    ),
    array(
      'data' => t('To'),
      'field' => 'redirect',
    ),
    array(
      'data' => t('Type'),
      'field' => 'type',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => '2',
    ),
  );
  $result = pager_query('SELECT rid, path, redirect, query, fragment, type FROM {path_redirect}' . tablesort_sql($header), 50);
  $rows = array();
  while ($r = db_fetch_object($result)) {
    $redirect = url($r->redirect, $r->query ? $r->query : NULL, $r->fragment ? $r->fragment : NULL, TRUE);
    $rows[] = array(
      // @todo: Revise the following messy, confusing line.
      l($r->path, preg_replace('/\\?.*/', '', $r->path), array(), strstr($r->path, '?') ? preg_replace('/.*\\?/', '', $r->path) : NULL),
      l($redirect, $redirect),
      $r->type,
      l(t('edit'), 'admin/build/path-redirect/edit/' . $r->rid),
      l(t('delete'), 'admin/build/path-redirect/delete/' . $r->rid),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No redirects have been added.'),
        'colspan' => '5',
      ),
    );
  }
  $output = theme('table', $header, $rows, array(
    'class' => 'path-redirects',
  ));
  $output .= '<p>' . l(t('Add redirect'), 'admin/build/path-redirect/add') . '</p>';
  $output .= theme('pager');
  return $output;
}