[SPIP Zone] r3707 - in /_plugins_/pagination_avancee: ./ inc/ inc/modele_pagination.php mes_fonctions.php plugin.xml

Author: maieulrouquette2@tele2.fr
Date: Thu Jun 29 15:15:17 2006
New Revision: 3707

Log:
pagination_avancee

Added:
    _plugins_/pagination_avancee/
    _plugins_/pagination_avancee/inc/
    _plugins_/pagination_avancee/inc/modele_pagination.php
    _plugins_/pagination_avancee/mes_fonctions.php (with props)
    _plugins_/pagination_avancee/plugin.xml (with props)

Added: _plugins_/pagination_avancee/inc/modele_pagination.php

--- _plugins_/pagination_avancee/inc/modele_pagination.php (added)
+++ _plugins_/pagination_avancee/inc/modele_pagination.php Thu Jun 29 15:15:17 2006
@@ -0,0 +1,174 @@
+<?
+function pagination_page($total, $nom, $pas, $liste){
+static $ancres = array();
+
+ $separateur="&nbsp;| ";
+
+
+
+
+
+
+
+ $debut = 'debut'.$nom;
+
+ $pagination = array(
+ 'lien_base' => self(),
+ 'total' => $total,
+ 'position' => intval(_request($debut)),
+ 'pas' => $pas,
+ 'nombre_pages' => floor(($total-1)/$pas)+1,
+ 'page_courante' => floor(intval(_request($debut))/$pas)+1,
+ 'lien_pagination' => '<a href="@url@">@item@</a>',
+ 'lien_item_courant' => '<span class="on">@item@</span>'
+ );
+
+ $ancre='pagination'.$nom;
+
+ // n'afficher l'ancre qu'une fois
+ if (!isset($ancres[$ancre]))
+ $bloc_ancre = $ancres[$ancre] = "<a name='$ancre' id='$ancre'></a>";
+
+ // Pas de pagination
+ if ($pagination['nombre_pages']<=1)
+ return '';
+
+ // liste = false : on ne veut que l'ancre
+ if (!$liste)
+ return $bloc_ancre;
+
+ // liste = true : on retourne tout (ancre + bloc de navigation)
+
+ list ($premiere, $derniere) = calcul_bornes_pagination(
+ PAGINATION_MAX,
+ $pagination['nombre_pages'],
+ $pagination['page_courante']);
+
+ $texte = '';
+
+ if ($premiere > 2)
+ $texte .= pagination_item('',
+ '...',
+ $pagination[
+ ($i != $pagination['page_courante']) ?
+ 'lien_pagination' : 'lien_item_courant'
+ ],
+ $pagination['lien_base'], $debut, $ancre)
+ . $separateur;
+
+ if ($premiere == 2) $premiere = 1; # '...' inutile quand on peut mettre 0
+
+ for ($i = $premiere; $i<=$derniere; $i++) {
+ $num = strval(($i-1)*$pas);
+ $texte .= pagination_item($num,
+ $i,
+ $pagination[
+ ($i != $pagination['page_courante']) ?
+ 'lien_pagination' : 'lien_item_courant'
+ ],
+ $pagination['lien_base'], $debut, $ancre);
+ if ($i<$derniere) $texte .= $separateur;
+ }
+
+ if ($derniere < $pagination['nombre_pages'])
+ $texte .= $separateur.
+ pagination_item(strval(($pagination['nombre_pages']-1)*$pas),
+ '...',
+ $pagination[
+ ($i != $pagination['page_courante']) ?
+ 'lien_pagination' : 'lien_item_courant'
+ ],
+ $pagination['lien_base'], $debut, $ancre);
+
+ return $bloc_ancre.$texte;
+
+}
+
+function pagination_dist($total, $nom, $pas, $liste){
+static $ancres = array();
+
+ $separateur="&nbsp;| ";
+
+
+
+
+
+
+
+ $debut = 'debut'.$nom;
+
+ $pagination = array(
+ 'lien_base' => self(),
+ 'total' => $total,
+ 'position' => intval(_request($debut)),
+ 'pas' => $pas,
+ 'nombre_pages' => floor(($total-1)/$pas)+1,
+ 'page_courante' => floor(intval(_request($debut))/$pas)+1,
+ 'lien_pagination' => '<a href="@url@">@item@</a>',
+ 'lien_item_courant' => '<span class="on">@item@</span>'
+ );
+
+ $ancre='pagination'.$nom;
+
+ // n'afficher l'ancre qu'une fois
+ if (!isset($ancres[$ancre]))
+ $bloc_ancre = $ancres[$ancre] = "<a name='$ancre' id='$ancre'></a>";
+
+ // Pas de pagination
+ if ($pagination['nombre_pages']<=1)
+ return '';
+
+ // liste = false : on ne veut que l'ancre
+ if (!$liste)
+ return $bloc_ancre;
+
+ // liste = true : on retourne tout (ancre + bloc de navigation)
+
+ list ($premiere, $derniere) = calcul_bornes_pagination(
+ PAGINATION_MAX,
+ $pagination['nombre_pages'],
+ $pagination['page_courante']);
+
+ $texte = '';
+
+ if ($premiere > 2)
+ $texte .= pagination_item('',
+ '...',
+ $pagination[
+ ($i != $pagination['page_courante']) ?
+ 'lien_pagination' : 'lien_item_courant'
+ ],
+ $pagination['lien_base'], $debut, $ancre)
+ . $separateur;
+
+ if ($premiere == 2) $premiere = 1; # '...' inutile quand on peut mettre 0
+
+ for ($i = $premiere; $i<=$derniere; $i++) {
+ $num = strval(($i-1)*$pas);
+ $texte .= pagination_item($num,
+ $num,
+ $pagination[
+ ($i != $pagination['page_courante']) ?
+ 'lien_pagination' : 'lien_item_courant'
+ ],
+ $pagination['lien_base'], $debut, $ancre);
+ if ($i<$derniere) $texte .= $separateur;
+ }
+
+ if ($derniere < $pagination['nombre_pages'])
+ $texte .= $separateur.
+ pagination_item(strval(($pagination['nombre_pages']-1)*$pas),
+ '...',
+ $pagination[
+ ($i != $pagination['page_courante']) ?
+ 'lien_pagination' : 'lien_item_courant'
+ ],
+ $pagination['lien_base'], $debut, $ancre);
+
+ return $bloc_ancre.$texte;
+
+}
+
+
+
+?>
\ No newline at end of file

Added: _plugins_/pagination_avancee/mes_fonctions.php

--- _plugins_/pagination_avancee/mes_fonctions.php (added)
+++ _plugins_/pagination_avancee/mes_fonctions.php Thu Jun 29 15:15:17 2006
@@ -0,0 +1,59 @@
+<?
+
+include_spip('inc/modele_pagination');
+function balise_PAGINATION($p, $liste='true') {
+ #nouvel_balise
+ $modele=$p->param[0][1][0]->texte;
+
+
+ if (gettype($modele)=="NULL"){
+ $modele = "dist";
+ ;}
+
+
+
+
+
+
+ #dist#
+ $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere'];
+ // s'il n'y a pas de nom de boucle, on ne peut pas paginer
+ if ($b === '') {
+ erreur_squelette(
+ _T('zbug_champ_hors_boucle',
+ array('champ' => '#PAGINATION')
+ ), $p->id_boucle);
+ $p->code = "''";
+ return $p;
+ }
+
+ // s'il n'y a pas de total_parties, c'est qu'on se trouve
+ // dans un boucle recurive ou qu'on a oublie le critere {pagination}
+ if (!$p->boucles[$b]->total_parties) {
+ erreur_squelette(
+ _L('zbug_xx: #PAGINATION sans critere {pagination}
+ ou employe dans une boucle recursive',
+ array('champ' => '#PAGINATION')
+ ), $p->id_boucle);
+ $p->code = "''";
+ return $p;
+ }
+
+ $p->boucles[$b]->numrows = true;
+
+ $p->code = "pagination(
(isset(\$Numrows['$b']['grand_total']) ?
\$Numrows['$b']['grand_total'] : \$Numrows['$b']['total']
), '$b', "
. $p->boucles[$b]->total_parties
. ", $liste,'$modele')";
+
+
+ $p->interdire_scripts = false;
+ return $p;
+}
+
+
+function pagination($total, $nom, $pas, $liste = true,$modele="dist") {
+
+ return call_user_func("pagination_".$modele,$total, $nom, $pas, $liste);
+}
+
+
+
+?>
\ No newline at end of file

Propchange: _plugins_/pagination_avancee/mes_fonctions.php
------------------------------------------------------------------------------
    svn:executable =

Added: _plugins_/pagination_avancee/plugin.xml

--- _plugins_/pagination_avancee/plugin.xml (added)
+++ _plugins_/pagination_avancee/plugin.xml Thu Jun 29 15:15:17 2006
@@ -0,0 +1 @@
+<plugin>
        <nom> <!-- Nom du plugin -->
        pagination_avancee
        </nom>
        <auteur> <!-- Auteur du plugin -->
        maieul
        </auteur>
        <version>
        0.1
        </version>
        <etat>
        dev
        </etat>
        <description>
        Le seul plugin spip au monde qui ne fait rien, mais qui le fait bien !
        </description>
       
        <fonctions> <!-- fichier charge a chaque recalul de page -->
        mes_fonctions.php
        </fonctions>
        <!-- classe d'implementation : espace de nommage qui prefixera les appels de fonction
        sur le mode Rien::
        ainsi les fonctions hors espace de nommage ne peuvent etre appelees
        ce parametre est obligatoire et doit etre non vide
        -->
        <prefix>
        Rien
        </prefix>
        <!-- Definitions des fonctions qui s'inserent dans les pipelines -->
        
        <!-- Le parametre action est facultatif : en son absence la methode de la classe portant le nom du pipeline est appelee. Le parametre inclure est facultatif. -->
</plugin>
\ No newline at end of file

Propchange: _plugins_/pagination_avancee/plugin.xml
------------------------------------------------------------------------------
    svn:executable =