3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2010 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined("_ECRIRE_INC_VERSION")) return;
15 include_spip('inc/presentation');
17 // Constante pour le nombre d'auteurs par page.
18 @define
('MAX_AUTEURS_PAR_PAGE', 30);
19 @define
('AUTEURS_MIN_REDAC', "0minirezo,1comite,5poubelle");
20 @define
('AUTEURS_DEFAUT', '');
21 // decommenter cette ligne et commenter la precedente
22 // pour que l'affichage par defaut soit les visiteurs
23 #@define('AUTEURS_DEFAUT', '!');
25 // http://doc.spip.org/@exec_auteurs_dist
26 function exec_visiteurs_dist()
28 $tri = preg_replace('/\W/', '', _request('tri'));
29 if (!$tri) $tri='nom';
30 $statut = _request('statut');
31 if (!$statut) $statut = "!" . AUTEURS_MIN_REDAC
;
32 $debut = intval(_request('debut'));
35 if ($cherche = _request('recherche')) {
36 include_spip('inc/rechercher');
37 $tables = liste_des_champs();
38 $tables = array('auteur'=>$tables['auteur']);
39 $recherche = recherche_en_base($cherche, $tables,array('toutvoir'=>true));
40 if ($recherche['auteur'])
41 $recherche = sql_in('aut.id_auteur', array_keys($recherche['auteur']));
43 $recherche = "aut.id_auteur=0"; // rien trouve !
46 $form = formulaire_recherche("auteurs",(($s=_request('statut'))?
"<input type='hidden' name='statut' value='$s' />":""));
47 exec_auteurs_args($statut, $tri, $debut, $recherche,$form, $cherche);
51 // http://doc.spip.org/@exec_auteurs_args
52 function exec_auteurs_args($statut, $tri, $debut, $recherche=NULL, $trouve='', $cherche='')
54 if ($recherche !=='') {
55 list($auteurs, $lettre, $nombre_auteurs, $debut) =
56 lettres_d_auteurs(requete_auteurs($tri, $statut, $recherche), $debut, MAX_AUTEURS_PAR_PAGE, $tri);
59 $recherche = auteurs_tranches(afficher_n_auteurs($auteurs), $debut, $lettre, $tri, $statut, MAX_AUTEURS_PAR_PAGE, $nombre_auteurs,$cherche);
63 $recherche = "<h3>". _T('info_resultat_recherche')." «$cherche»</h3>" . $recherche;
65 $recherche = "<h3>". _T('info_recherche_auteur_zero',array('cherche_auteur'=>$cherche))."</h3>" . $recherche;
71 ajax_retour($recherche); //ecrire en id='auteurs' ci-dessous
74 pipeline('exec_init',array('args'=>array('exec'=>'auteurs'),'data'=>''));
76 $visiteurs = !statut_min_redac($statut);
77 $commencer_page = charger_fonction('commencer_page', 'inc');
79 $visiteurs ?
_T('info_visiteurs') : _T('info_auteurs'),
80 "auteurs","redacteurs");
82 echo bandeau_auteurs($tri, $visiteurs);
84 echo $trouve, "<div class='nettoyeur'></div>";
87 $contexte['nb'] = MAX_AUTEURS_PAR_PAGE
;
88 if (substr($statut,0,1)!=='!')
89 $contexte['statut'] = explode(',',$statut);
91 $statut = substr($statut,1);
92 $statut = explode(',',$statut);
93 $statut = sql_allfetsel('DISTINCT statut','spip_auteurs',sql_in('statut',$statut,'NOT'));
94 $contexte['statut'] = array_map('reset',$statut);
97 if ($GLOBALS['visiteur_session']['statut']=='0minirezo'){
98 // n'exclure que les articles a la poubelle des compteurs
99 $contexte['filtre_statut_articles'] = array('poubelle');
102 // exclure les articles a la poubelle, en redac ou refuse des compteurs
103 $contexte['filtre_statut_articles'] = array('prepa','poubelle','refuse');
106 $lister_objets = charger_fonction('lister_objets','inc');
107 echo $lister_objets('auteurs',$contexte);
109 # echo "<div id='auteurs'>", $recherche, "</div>";
110 echo pipeline('affiche_milieu',array('args'=>array('exec'=>'auteurs'),'data'=>''));
111 echo fin_gauche(), fin_page();
115 // http://doc.spip.org/@bandeau_auteurs
116 function bandeau_auteurs($tri, $visiteurs)
118 global $connect_id_auteur, $connect_statut, $connect_toutes_rubriques;
120 $ret = debut_gauche("auteurs",true) . debut_boite_info(true);
123 $ret .= "\n<p class='arial1'>"._T('info_gauche_visiteurs_enregistres'). '</p>';
125 $ret .= "\n<p class='arial1'>"._T('info_gauche_auteurs'). '</p>';
127 if ($connect_statut == '0minirezo')
128 $ret .= "\n<p class='arial1'>". _T('info_gauche_auteurs_exterieurs') . '</p>';
130 $ret .= fin_boite_info(true);
132 $ret .= pipeline('affiche_gauche',array('args'=>array('exec'=>'auteurs'),'data'=>''));
134 if ($connect_statut == '0minirezo') {
136 if ($connect_toutes_rubriques)
137 $res = icone_horizontale(_T('icone_creer_nouvel_auteur'), generer_url_ecrire("auteur_infos", 'new=oui'), "auteur-24.gif", "creer.gif", false);
140 $res .= icone_horizontale(_T('icone_informations_personnelles'), generer_url_ecrire("auteur_infos","id_auteur=$connect_id_auteur"), "fiche-perso-24.gif","rien.gif", false);
142 if (avoir_visiteurs(true)) {
144 $res .= icone_horizontale (_T('icone_afficher_auteurs'), generer_url_ecrire("auteurs"), "auteur-24.gif", "", false);
146 $res .= icone_horizontale (_T('icone_afficher_visiteurs'), generer_url_ecrire("visiteurs"), "auteur-24.gif", "", false);
148 $ret .= bloc_des_raccourcis($res);
150 $ret .= creer_colonne_droite('auteurs',true);
151 $ret .= pipeline('affiche_droite',array('args'=>array('exec'=>'auteurs'),'data'=>''));
152 $ret .= debut_droite('',true);
155 $ret .= gros_titre($visiteurs ?
_T('info_visiteurs') : _T('info_auteurs'),'',false);
160 // http://doc.spip.org/@statut_min_redac
161 function statut_min_redac($statut)
164 ||
(strpos($statut, "0minirezo")!==false)
165 ||
(strpos($statut, "1comite")!==false);
167 return $statut[0] =='!' ?
!$x : $x;
170 // http://doc.spip.org/@lettres_d_auteurs
171 function lettres_d_auteurs($query, $debut, $max_par_page, $tri)
173 $auteurs = $lettre = array();
174 $lettres_nombre_auteurs = 0;
177 $query = sql_select($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY'], $query['ORDER BY']);
179 while ($auteur = sql_fetch($query)) {
180 if ($nombre_auteurs>=$debut AND $nombre_auteurs<$debut+
$max_par_page) {
181 $auteur['restreint'] = sql_countsel("spip_auteurs_rubriques", "id_auteur=".$auteur['id_auteur']);
183 $auteurs[] = $auteur;
187 $premiere_lettre = strtoupper(spip_substr(corriger_typo($auteur['nom']),0,1));
188 if ($premiere_lettre != $lettre_prec) {
189 $lettre[$premiere_lettre] = $nombre_auteurs;
191 $lettre_prec = $premiere_lettre;
195 return array($auteurs, $lettre, $nombre_auteurs, $debut);
198 // http://doc.spip.org/@auteurs_tranches
199 function auteurs_tranches($auteurs, $debut, $lettre, $tri, $statut, $max_par_page, $nombre_auteurs, $cherche='')
201 global $spip_lang_right;
203 $arg = ($statut ?
("&statut=" .urlencode($statut)) : '')
204 . ($cherche ?
("&recherche=" . urlencode($cherche)) : '');
206 $res ="\n<tr class='titrem'>"
207 . "\n<th style='width: 20px'>";
210 $res .= http_img_pack('admin-12.gif','', " class='lang'");
212 $t = _T('lien_trier_statut');
213 $res .= auteurs_href(http_img_pack('admin-12.gif', $t, "class='lang'"),"tri=statut$arg", " title=\"$t\"");
216 $res .= "</th><th style='width: 20px'></th><th>";
219 $res .= '<b>'._T('info_nom').'</b>';
221 $res .= auteurs_href(_T('info_nom'), "tri=nom$arg", " title='"._T('lien_trier_nom'). "'");
226 $res .= '<b>'._T('info_site').'</b>';
228 $res .= auteurs_href(_T('info_site'), "tri=site$arg", " title='"._T('info_site'). "'");
232 $col = statut_min_redac($statut) ?
_T('info_articles') : _T('message') ;
235 $res .= '<b>' . $col .'</b>';
237 $res .= auteurs_href($col, "tri=nombre$arg", " title=\""._T('lien_trier_nombre_articles'). '"');
239 $res .= "</th></tr>\n";
241 if ($nombre_auteurs > $max_par_page) {
242 $res .= "\n<tr class='' ><td colspan='5'><div class='arial1 tranches'>";
244 for ($j=0; $j < $nombre_auteurs; $j+
=$max_par_page) {
245 if ($j > 0) $res .= " | ";
250 $res .= auteurs_href($j, "tri=$tri$arg&debut=$j");
252 $res .= auteurs_href('0', "tri=$tri$arg");
253 if ($debut > $j AND $debut < $j+
$max_par_page){
254 $res .= " | <b>$debut</b>";
259 $res .= "</div><div>\n";
261 foreach ($lettre as $key => $val) {
263 $res .= "<b>$key</b>\n";
265 if ($debut>$val_prev && $debut<$val)
266 $res .= "<b>..</b> ";
267 $res .= auteurs_href($key, "tri=$tri$arg&debut=$val") . "\n";
271 $res .= "</div></td></tr>\n";
276 $debut_suivant = $debut +
$max_par_page;
277 if ($debut_suivant < $nombre_auteurs OR $debut > 0) {
278 $nav = "\n<table id='bas' style='width: 100%' border='0'>"
279 . "\n<tr class=''><td align='left'>";
282 $debut_prec = max($debut - $max_par_page, 0);
283 $nav .= auteurs_href('<<<',"tri=$tri&debut=$debut_prec$arg");
285 $nav .= "</td><td style='text-align: $spip_lang_right'>";
286 if ($debut_suivant < $nombre_auteurs) {
287 $nav .= auteurs_href('>>>',"tri=$tri&debut=$debut_suivant&$arg");
289 $nav .= "</td></tr></table>\n";
292 return debut_cadre('liste','auteur-24.gif','','','lesauteurs')
293 . "\n<br /><table class='arial2' cellpadding='2' cellspacing='0' style='width: 100%; border: 0px;'>\n"
301 // http://doc.spip.org/@auteurs_href
302 function auteurs_href($clic, $args='', $att='')
304 $h = generer_url_ecrire('auteurs', $args);
307 if (_SPIP_AJAX
=== 1 )
308 $att .= ("\nonclick=" . ajax_action_declencheur($h,$a));
310 return "<a href='$h#$a'$att>$clic</a>";
314 // http://doc.spip.org/@requete_auteurs
315 function requete_auteurs($tri, $statut, $recherche=NULL)
317 global $connect_statut, $spip_lang, $connect_id_auteur;
320 // Construire la requete
323 // si on n'est pas minirezo, ignorer les auteurs sans article
324 // sauf les admins, toujours visibles.
326 // limiter les statuts affiches
327 if ($connect_statut == '0minirezo') {
328 if ($statut[0]=='!') {
329 $statut = substr($statut,1); $not = "NOT";
331 $visit = !statut_min_redac($statut);
332 $statut = preg_split('/\W+/', $statut);
333 $sql_visible = sql_in("aut.statut", $statut, $not);
336 aut.statut = '0minirezo'
337 OR aut.id_auteur=$connect_id_auteur
338 OR " . sql_in('art.statut', array('prop', 'publie'))
347 (strpos($sql_visible,'art.statut')?
("LEFT JOIN spip_auteurs_articles AS lien ON aut.id_auteur=lien.id_auteur" . " LEFT JOIN spip_articles AS art ON (lien.id_article = art.id_article)"):"");
352 $sql_sel = "COUNT(lien.id_article) AS compteur";
353 $sql_order = 'compteur DESC, unom';
355 "LEFT JOIN spip_forum AS lien ON aut.id_auteur=lien.id_auteur"
356 : ("LEFT JOIN spip_auteurs_articles AS lien ON aut.id_auteur=lien.id_auteur"
357 . (strpos($sql_visible,'art.statut')?
" LEFT JOIN spip_articles AS art ON (lien.id_article = art.id_article)":""));
361 $sql_order = 'site, unom';
365 $sql_order = 'statut, unom';
370 $sql_sel = sql_multi ("nom", $spip_lang);
371 $sql_order = "multi";
374 // La requete de base est tres sympa
375 // (pour les visiteurs, ca postule que les messages concernent des articles)
376 return array('SELECT' =>
379 "aut.id_auteur AS id_auteur",
380 "aut.statut AS statut",
381 "aut.nom_site AS site",
383 "UPPER(aut.nom) AS unom",
384 $sql_sel),array('',null)),
385 'FROM' => "spip_auteurs AS aut $join",
386 'WHERE' => $sql_visible . ($recherche
389 'GROUP BY' => "aut.statut, aut.nom_site, aut.nom, aut.id_auteur",
390 'ORDER BY' => $sql_order);
393 // http://doc.spip.org/@afficher_n_auteurs
394 function afficher_n_auteurs($auteurs) {
397 $formater_auteur = charger_fonction('formater_auteur', 'inc');
398 foreach ($auteurs as $row) {
400 list($s, $mail, $nom, $w, $p) = $formater_auteur($row['id_auteur']);
402 $res .= "\n<tr class='tr_liste'>"
405 . "</td><td class='arial1'>"
407 . "</td><td class='verdana1'>"
409 . ((isset($row['restreint']) AND $row['restreint'])
410 ?
(" <small>"._T('statut_admin_restreint')."</small>")
412 ."</td><td class='arial1'>"
414 . "</td><td class='arial1'>"