You are here

function cleanpager_theme_pager_link in Clean Pagination 7

Same name and namespace in other branches
  1. 6 cleanpager.module \cleanpager_theme_pager_link()

Override theme for a pager link

1 string reference to 'cleanpager_theme_pager_link'
cleanpager_theme_registry_alter in ./cleanpager.module
Implementation of hook_theme_registry_alter().

File

./cleanpager.module, line 233

Code

function cleanpager_theme_pager_link($variables) {
  $text = $variables['text'];
  $page_new = $variables['page_new'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $attributes = $variables['attributes'];
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
    $parameters['page'] = $new_page;
  }
  $cleanpage = cleanpager_check_match();
  if ($cleanpage) {
    unset($parameters['page']);
  }
  $query = array();
  if (count($parameters)) {
    $query = drupal_get_query_parameters($parameters, array());
  }
  if ($query_pager = pager_get_query_parameters()) {
    $query = array_merge($query, $query_pager);
  }

  // Set each pager link title
  if (!isset($attributes['title'])) {
    static $titles = NULL;
    if (!isset($titles)) {
      $titles = array(
        t('« first') => t('Go to first page'),
        t('‹ previous') => t('Go to previous page'),
        t('next ›') => t('Go to next page'),
        t('last »') => t('Go to last page'),
      );
    }
    if (isset($titles[$text])) {
      $attributes['title'] = $titles[$text];
    }
    elseif (is_numeric($text)) {
      $attributes['title'] = t('Go to page @number', array(
        '@number' => $text,
      ));
    }
  }
  $q = _cleanpager_get_q();
  if ($cleanpage) {
    $q = cleanpager_path();
    if (drupal_is_front_page()) {
      $cleanpage = '';
    }
    else {

      // Use the aliased path.
      $cleanpage = drupal_get_path_alias($cleanpage);
    }
    if (variable_get('cleanpager_use_additional_path', TRUE)) {
      $cleanpage .= ($cleanpage ? '/' : '') . CLEANPAGER_ADDITIONAL_PATH_VARIABLE;
    }
  }
  else {
    unset($cleanpage);
  }

  // If we're on the front page, don't add in the path. For example,
  // use page/1 instead of node/page/1.
  if (drupal_is_front_page()) {
    $q = '';
  }
  else {

    // Use the aliased path if there is one.
    $q = drupal_get_path_alias($q);
  }

  // Store the original text in case it's modified and it's used down
  // below to add rel and previous.
  $original_text = $text;
  if (isset($new_page) && isset($cleanpage) && $page_new[$element] > 0) {
    if (variable_get('cleanpager_use_seo_links', '') == 1) {
      $text = 'Visit ' . $q . ' Page ' . $text;
    }
    $link = array(
      'title' => $text,
      'href' => $cleanpage . ($cleanpage ? '/' : '') . $new_page . (variable_get('cleanpager_add_trailing', FALSE) ? '/' : ''),
      'attributes' => $attributes,
      'query' => count($query) ? $query : NULL,
    );
  }
  else {
    $link = array(
      'title' => $text,
      'href' => $q . ($q && variable_get('cleanpager_add_trailing', FALSE) ? '/' : ''),
      'attributes' => $attributes,
      'query' => count($query) ? $query : NULL,
    );
  }
  if (variable_get('cleanpager_add_rel_link', FALSE)) {

    // Pagination with rel=“next” and rel=“prev”. Does not support well multiple
    // pagers on the same page - it will create relnext and relprev links
    // in header for that case only for the first pager that is rendered.
    static $rel_prev = FALSE, $rel_next = FALSE;
    if (!$rel_prev && $original_text == t('‹ previous')) {
      $rel_prev = TRUE;
      drupal_add_html_head_link(array(
        'rel' => 'prev',
        'href' => url($link['href'], array(
          'query' => $link['query'],
          'absolute' => TRUE,
        )),
      ));
    }
    if (!$rel_next && $original_text == t('next ›')) {
      $rel_next = TRUE;
      drupal_add_html_head_link(array(
        'rel' => 'next',
        'href' => url($link['href'], array(
          'query' => $link['query'],
          'absolute' => TRUE,
        )),
      ));
    }
  }

  // Check if an array or the html should be returned.
  if (!isset($variables['return_link_array'])) {
    global $theme_key;
    $themes = list_themes();
    $variables['return_link_array'] = _cleanpager_is_array_theme($themes, $theme_key);
  }
  if ($variables['return_link_array']) {
    return $link;
  }
  return l($link['title'], $link['href'], array(
    'attributes' => $link['attributes'],
    'query' => $link['query'],
  ));
}