Module Drupal de pagination
Le 26 mai 2008, à 8:10 par Ulhume...
Un module de pagination. J'avais fauché les sources je ne sais plus où et les avait modifiées.
<?php
/**
* filter to set up page numbers for multiple page articles,
* based on suggestions by Prometheus6 on http://drupal.org/node/23362#comment-40580
* @file pagination.module
* @author Kitt Hodsden http://kitt.hodsden.com/
* @license Creative Commons BY-NC-SA, http://creativecommons.org/licenses/by-nc-sa/2.0/
* @license GNU GPL v2
*/
/**
* help hook
*/
function pagination_help
($section) {
switch ($section) {
case 'admin/modules#description':
return t
("Handles splitting long nodes into several pages, allowing for full node view also.");
}
}
/**
* settings hook
*/
function pagination_settings
() {
// set up the params via pageNo URL variable or URL directly
$o = form_textfield
(t
('Text before page links'), 'pagination_pre', variable_get
('pagination_pre', 'Go to page: '), 30, 255, t
('Text displayed before the pagination links'));
$o .= form_textfield
(t
('Previous page'), 'pagination_prev', variable_get
('pagination_prev', 'previous'), 30, 255, t
('Previous page link text'));
$o .= form_textfield
(t
('Next page'), 'pagination_next', variable_get
('pagination_next', 'next'), 30, 255, t
('Next page link text'));
$o .= form_textfield
(t
('Single page text'), 'pagination_single', variable_get
('pagination_single', 'single page'), 30, 255, t
('Single page link text'));
$o .= form_textfield
(t
('Pagination break pattern'), 'pagination_break', variable_get
('pagination_break', '<!--pagebreak-->'), 30, 255, t
('Pattern to break pages on, defaults to <!--pagebreak-->, which requires "Full HTML" input filter'));
return $o;
}
/**
* nodeapi hook
*/
function pagination_nodeapi
(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'alter':
/*
* see if the page is being printed, some themes use &print in URLs for printing,
* the print.module uses /print at the end of the node url (node/#/print), use substr
* in case PCRE not available (though, taxonomy uses preg_match, so should be okay)
*/
$not_printing = true;
if (isset($_GET['print']) || substr($_GET['q'], -6, 6) == '/print') {
$not_printing = false;
}
if (($page === true) && $not_printing) {
// get the break pattern
$breakpattern = variable_get
('pagination_break', '<!--pagebreak-->');
// explode the body on the <!--pagebreak--> tag
$pages = explode($breakpattern, $node->body);
// if more than one page, generate the links on the bottom
if (count($pages) > 1) {
// process only if the user doesn't want all the pages
$p=$_GET['q'];
$pos=strpos($p,"page_");
if ($pos)
{
$pageNo=substr($p,$pos+5);
}
$totalPages = count($pages);
// check we're not too far or too few
if (!isset($pageNo) || empty($pageNo)) {
$pageNo = 1;
}
if ($pageNo > $totalPages) {
$pageNo = $totalPages;
}
if ($pageNo != 'all') {
$basepage = "node/".$node->nid;
for($i = 1; $i <= $totalPages; $i++) {
if ($pageNo != $i) {
$links .= l
($i, $basepage.'/view/page_' . $i, array()) . ' ';
} else {
$links .= $i . ' ';
}
}
$prev = (($pageNo - 1) < 1) ?
1 : ($pageNo - 1);
$next = (($pageNo + 1) > $totalPages) ?
$totalPages : ($pageNo + 1);
if ($pageNo > 1) {
$x = variable_get
('pagination_prev', 'Page Precedente');
if ($x != '') {
$links = l
($x, $basepage.'/view/page_' . $prev, array()) . ' | ' . $links;
}
}
if ($pageNo < $totalPages) {
$x = variable_get
('pagination_next', 'Page Suivante');
if ($x != '') {
$links .= ' | ' . l
($x, $basepage.'/view/page_'.$next, array());
}
}
$node->body=$pages[($pageNo - 1)] . '' . variable_get
('pagination_pre', 'Aller a:') . $links . ' | ' . l
(variable_get
('pagination_single', 'Une seule page'), $basepage.'/view/page_all', array());
} // end check for ALL param
} // end check for > 1 page to display
} // end check if we're on a page
break;
} // end switch
}
?>
Poster un nouveau commentaire