You are here

function _pagerer_get_adaptive_pages in Pagerer 7

Return an array of 'pages' using an adaptive logic.

Parameters

array $variables: theme's variables

array $markers: precalculated markers for the pager

array $pages: array of pages already enlisted, to prevent override

int $l: adaptive lock to left page

int $r: adaptive lock to right page

int $x: adaptive center lock for neighborhood

Return value

array associative array of pages, with key = page and value an array having 'text' and 'interval' (the offset from current page) keys/values; a key 'progressive' set to TRUE is also added as a marker

1 call to _pagerer_get_adaptive_pages()
_pagerer_theme_handler in ./pagerer.module
Pagerer's theme handler.

File

./pagerer.module, line 1562
Pagerer

Code

function _pagerer_get_adaptive_pages($variables, $markers, &$pages, $l, $r, $x) {
  $c = $markers['pager_current'] - 1;
  $m = $markers['pager_max'] - 1;
  $x = is_null($x) ? $c : $x;

  // Space on the left of the holding marker.
  $sl = $x - $l;

  // Space on the right of the holding marker.
  $sr = $r - $x;

  // Half of the maximum space either side to calculate from.
  $m = max($sl, $sr) / 2;
  for ($i = 0; $i < 2; $i++) {
    $off = intval($m * pow(0.5, $i));

    // Pages on the left.
    $p = $x - $off;
    if ($p > $l and $p < $c and !isset($pages[$p]) and !(isset($pages[$p - 1]) or isset($pages[$p + 1]))) {
      $pages[$p]['progressive'] = TRUE;
      $pages[$p]['interval'] = $p - $c;
      list($pages[$p]['text'], $pages[$p]['text_title']) = _pagerer_get_page_text($variables, $markers, $p - $c, 'page', $variables['progr_links']);
    }

    // Pages on the right.
    $p = $x + $off;
    if ($p < $r and $p > $c and !isset($pages[$p]) and !(isset($pages[$p - 1]) or isset($pages[$p + 1]))) {
      $pages[$p]['progressive'] = TRUE;
      $pages[$p]['interval'] = $p - $c;
      list($pages[$p]['text'], $pages[$p]['text_title']) = _pagerer_get_page_text($variables, $markers, $p - $c, 'page', $variables['progr_links']);
    }
  }
  return $pages;
}