Projet

Général

Profil

Paste
Télécharger (4,32 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / theme / system / pager.func.php @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * pager.func.php
5
 */
6

    
7
/**
8
 * Overrides theme_pager().
9
 */
10
function bootstrap_pager($variables) {
11
  $output = "";
12
  $items = array();
13
  $tags = $variables['tags'];
14
  $element = $variables['element'];
15
  $parameters = $variables['parameters'];
16
  $quantity = $variables['quantity'];
17

    
18
  global $pager_page_array, $pager_total;
19

    
20
  // Calculate various markers within this pager piece:
21
  // Middle is used to "center" pages around the current page.
22
  $pager_middle = ceil($quantity / 2);
23
  // Current is the page we are currently paged to.
24
  $pager_current = $pager_page_array[$element] + 1;
25
  // First is the first page listed by this pager piece (re quantity).
26
  $pager_first = $pager_current - $pager_middle + 1;
27
  // Last is the last page listed by this pager piece (re quantity).
28
  $pager_last = $pager_current + $quantity - $pager_middle;
29
  // Max is the maximum page number.
30
  $pager_max = $pager_total[$element];
31

    
32
  // Prepare for generation loop.
33
  $i = $pager_first;
34
  if ($pager_last > $pager_max) {
35
    // Adjust "center" if at end of query.
36
    $i = $i + ($pager_max - $pager_last);
37
    $pager_last = $pager_max;
38
  }
39
  if ($i <= 0) {
40
    // Adjust "center" if at start of query.
41
    $pager_last = $pager_last + (1 - $i);
42
    $i = 1;
43
  }
44

    
45
  // End of generation loop preparation.
46
  // @todo add theme setting for this.
47
  // $li_first = theme('pager_first', array(
48
  // 'text' => (isset($tags[0]) ? $tags[0] : t('first')),
49
  // 'element' => $element,
50
  // 'parameters' => $parameters,
51
  // ));
52
  $li_previous = theme('pager_previous', array(
53
    'text' => (isset($tags[1]) ? $tags[1] : t('previous')),
54
    'element' => $element,
55
    'interval' => 1,
56
    'parameters' => $parameters,
57
  ));
58
  $li_next = theme('pager_next', array(
59
    'text' => (isset($tags[3]) ? $tags[3] : t('next')),
60
    'element' => $element,
61
    'interval' => 1,
62
    'parameters' => $parameters,
63
  ));
64
  // @todo add theme setting for this.
65
  // $li_last = theme('pager_last', array(
66
  // 'text' => (isset($tags[4]) ? $tags[4] : t('last')),
67
  // 'element' => $element,
68
  // 'parameters' => $parameters,
69
  // ));
70
  if ($pager_total[$element] > 1) {
71
    // @todo add theme setting for this.
72
    // if ($li_first) {
73
    // $items[] = array(
74
    // 'class' => array('pager-first'),
75
    // 'data' => $li_first,
76
    // );
77
    // }
78
    if ($li_previous) {
79
      $items[] = array(
80
        'class' => array('prev'),
81
        'data' => $li_previous,
82
      );
83
    }
84
    // When there is more than one page, create the pager list.
85
    if ($i != $pager_max) {
86
      if ($i > 1) {
87
        $items[] = array(
88
          'class' => array('pager-ellipsis', 'disabled'),
89
          'data' => '<span>…</span>',
90
        );
91
      }
92
      // Now generate the actual pager piece.
93
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
94
        if ($i < $pager_current) {
95
          $items[] = array(
96
            // 'class' => array('pager-item'),
97
            'data' => theme('pager_previous', array(
98
              'text' => $i,
99
              'element' => $element,
100
              'interval' => ($pager_current - $i),
101
              'parameters' => $parameters,
102
            )),
103
          );
104
        }
105
        if ($i == $pager_current) {
106
          $items[] = array(
107
            // Add the active class.
108
            'class' => array('active'),
109
            'data' => l($i, '#', array('fragment' => '', 'external' => TRUE)),
110
          );
111
        }
112
        if ($i > $pager_current) {
113
          $items[] = array(
114
            'data' => theme('pager_next', array(
115
              'text' => $i,
116
              'element' => $element,
117
              'interval' => ($i - $pager_current),
118
              'parameters' => $parameters,
119
            )),
120
          );
121
        }
122
      }
123
      if ($i < $pager_max) {
124
        $items[] = array(
125
          'class' => array('pager-ellipsis', 'disabled'),
126
          'data' => '<span>…</span>',
127
        );
128
      }
129
    }
130
    // End generation.
131
    if ($li_next) {
132
      $items[] = array(
133
        'class' => array('next'),
134
        'data' => $li_next,
135
      );
136
    }
137
    // @todo add theme setting for this.
138
    // if ($li_last) {
139
    // $items[] = array(
140
    // 'class' => array('pager-last'),
141
    // 'data' => $li_last,
142
    // );
143
    // }
144
    return '<div class="text-center">' . theme('item_list', array(
145
      'items' => $items,
146
      'attributes' => array('class' => array('pagination')),
147
    )) . '</div>';
148
  }
149
  return $output;
150
}