You are here

function purl_admin in Persistent URL 6

Same name and namespace in other branches
  1. 7 purl.admin.inc \purl_admin()

Page callback for the purl administration page.

1 string reference to 'purl_admin'
purl_menu in ./purl.module
Implementation of hook_menu().

File

./purl.admin.inc, line 11
Admin pages for the purl module.

Code

function purl_admin() {
  global $pager_page_array, $pager_total, $pager_total_items;
  $page = isset($_GET['page']) ? $_GET['page'] : 0;
  $element = 0;
  $limit = 20;
  $providers = purl_providers();

  // Convert $page to an array, used by other functions.
  $pager_page_array = array(
    $page,
  );
  $methods = _purl_options();
  $merged = array();
  foreach (array_keys($methods) as $method) {
    foreach (purl_modifiers($method) as $value => $info) {
      $info['value'] = $value;
      $merged[] = $info;
    }
  }
  $rows = array();
  for ($i = $page * $limit; $i < ($page + 1) * $limit && $i < count($merged); $i++) {
    $rows[] = array(
      $providers[$merged[$i]['provider']]['name'],
      $merged[$i]['value'],
      $merged[$i]['id'],
      $methods[variable_get('purl_method_' . $merged[$i]['provider'], 'path')],
    );
  }

  // We calculate the total of pages as ceil(items / limit).
  $pager_total_items[$element] = count($merged);
  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
  $pager_page_array[$element] = max(0, min((int) $pager_page_array[$element], (int) $pager_total[$element] - 1));
  if ($rows) {
    $output = theme('table', array(
      t('Provider'),
      t('Modifier'),
      t('ID'),
      t('Method'),
    ), $rows);
    $output .= theme('pager');
  }
  else {
    $output = "<p>" . t('No persistent urls have been registered.') . "</p>";
  }
  return $output;
}