You are here

function theme_biblio_alpha_line in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 includes/biblio_theme.inc \theme_biblio_alpha_line()
  2. 6 biblio_theme.inc \theme_biblio_alpha_line()
  3. 7.2 includes/biblio.theme.inc \theme_biblio_alpha_line()

This function creates a string of letters (A - Z), which depending on the sorting are either linked to author or title filters i.e. clicking on the A when in the listing is sorted by authors will bring up a list of all the entries where the first character of the primary authors last name is "A".

Parameters

$type: either "author or title"

Return value

a chunk of HTML code as described above

3 theme calls to theme_biblio_alpha_line()
biblio_page_header in includes/biblio.pages.inc
_biblio_format_author_page in includes/biblio.pages.inc
_biblio_format_keyword_page in includes/biblio.pages.inc

File

includes/biblio_theme.inc, line 1166

Code

function theme_biblio_alpha_line($variables) {
  $type = $variables['type'];
  $all = '';
  $uri = drupal_parse_url(request_path());

  // Replace path in case we are in a multi-language environment, otherwise we end up with double language prefixes.
  $languages = language_list('enabled');
  if (isset($languages[1])) {
    $path_parts = empty($uri['path']) ? array() : explode('/', $uri['path']);
    foreach ($languages[1] as $code => $lang) {
      if ($path_parts[0] == $code) {
        array_shift($path_parts);
        break;
      }
    }
    $uri['path'] = implode('/', $path_parts);
  }
  $uri['attributes'] = array(
    'rel' => 'nofollow',
  );
  $all_uri = $uri;
  $current = '';
  switch ($type) {
    case 'authors':
      $filter = 'author';
      $current = isset($uri['query']['f']['author']) ? $uri['query']['f']['author'] : '';
      unset($all_uri['query']['f']['author']);
      break;
    case 'keywords':
    case 'keyword':
      $filter = 'keyword';
      $current = isset($uri['query']['f']['keyword']) ? $uri['query']['f']['keyword'] : '';
      unset($all_uri['query']['f']['keyword']);
      break;
    case 'author':
      $current = isset($uri['query']['f']['ag']) ? $uri['query']['f']['ag'] : '';
      $filter = 'ag';
      if (!isset($uri['query']['s'])) {
        $uri['query']['s'] = 'author';
      }
      unset($all_uri['query']['f']['ag']);
      break;
    case 'title':
      $current = isset($uri['query']['f']['tg']) ? $uri['query']['f']['tg'] : '';
      $filter = 'tg';
      unset($all_uri['query']['f']['tg']);
      break;
    default:
  }
  $output = '<div class="biblio-alpha-line">';

  // @todo for Cyrillic use 1040 to 1071... e.g. &#1068;.
  for ($i = 65; $i <= 90; $i++) {
    if ($i == ord($current)) {
      $output .= '<b>[' . chr($i) . ']</b>&nbsp;';
    }
    else {
      $uri['query']['f'][$filter] = chr($i);
      $output .= l(chr($i), $uri['path'], $uri) . '&nbsp;';
    }
  }
  if ($current) {
    if (empty($all_uri['query']['f'])) {
      unset($all_uri['query']['f']);
    }
    $output .= '&nbsp;&nbsp;' . '[' . l(t('Show ALL'), $all_uri['path'], $all_uri) . ']';
  }
  $output .= '</div>';
  return $output;
}