[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / afficher_objets.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
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 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 $GLOBALS['my_sites']=array();
16
17 // http://doc.spip.org/@icone_table
18 function icone_table($type){
19 $derog = array('document'=> 'doc-24.gif', 'mot'=>'mot-cle-24.gif','syndic_article'=>'site-24.gif', 'message' => 'messagerie-24.gif', 'groupes_mot'=>'mot-cle-24.gif');
20 if (isset($derog[$type]))
21 return $derog[$type];
22 return "$type-24.gif";
23 }
24
25 // http://doc.spip.org/@lien_editer_objet
26 function lien_editer_objet($type,$key,$id){
27 return $type == 'document' ? '' : generer_url_ecrire($type . "s_edit","$key=$id");
28 }
29
30 // http://doc.spip.org/@lien_voir_objet
31 function lien_voir_objet($type,$key,$id){
32 if ($type == 'document') return generer_url_entite($id, 'document');
33 $exec = array('article'=>'articles','breve'=>'breves_voir','rubrique'=>'naviguer','mot'=>'mots_edit', 'signature'=>'controle_petition');
34 $exec = isset($exec[$type])?$exec[$type]:$type . "s";
35 return generer_url_ecrire($exec,"$key=$id");
36 }
37
38 // http://doc.spip.org/@afficher_numero_edit
39 function afficher_numero_edit($id, $key, $type,$row=NULL) {
40 global $spip_lang_right, $spip_lang_left,$my_sites;
41 static $numero , $style='' ;
42 if ($type=='syndic_article') {
43 $redirect = _request('id_syndic') ? 'id_syndic='._request('id_syndic') : '';
44 if (autoriser('modifier',$type,$id)) {
45 if ($row['statut'] == "publie"){
46 $s = "[<a href='". redirige_action_auteur('instituer_syndic',"$id-refuse", _request('exec'), $redirect) . "'><span style='color: black'>"._T('info_bloquer_lien')."</span></a>]";
47
48 }
49 else if ($row['statut'] == "refuse"){
50 $s = "[<a href='". redirige_action_auteur('instituer_syndic',"$id-publie", _request('exec'), $redirect) . "'>"._T('info_retablir_lien')."</a>]";
51 }
52 else if ($row['statut'] == "off"
53 AND isset($my_sites[$id]['miroir']) AND $my_sites[$id]['miroir'] == 'oui') {
54 $s = '('._T('syndic_lien_obsolete').')';
55 }
56 else /* 'dispo' ou 'off' (dans le cas ancien site 'miroir') */
57 {
58 $s = "[<a href='". redirige_action_auteur('instituer_syndic',"$id-publie", _request('exec'), $redirect) . "'>"._T('info_valider_lien')."</a>]";
59 }
60 return $s;
61 }
62 }
63
64 if (!$style) {
65 $style = " class='spip_xx-small' style='float: $spip_lang_right; padding-$spip_lang_left: 4px; color: black; '";
66
67 $numero = _T('info_numero_abbreviation');
68 }
69
70 if (!autoriser('modifier',$type,$id) OR
71 !$href = lien_editer_objet($type,$key,$id)) {
72 $bal ='span';
73 } else {
74 $bal = 'a';
75 $href = "\nhref='"
76 . $href
77 . "' title='"
78 . _T('bouton_modifier')
79 . "'";
80 }
81 return "<$bal$style$href><b>"
82 . $numero
83 . $id
84 . "</b></$bal>";
85 }
86
87 // libelle du titre de l'objet :
88 // la partie du titre a afficher dans un lien
89 // puis la partie hors lien
90 // http://doc.spip.org/@afficher_titre_objet
91 function afficher_titre_objet($type,$row){
92 if (function_exists($f = "afficher_titre_$type"))
93 return $f($row);
94
95 $titre = isset($row['titre'])?sinon($row['titre'], "("._T('info_sans_titre_2').")"):
96 (isset($row['nom'])?sinon($row['nom'], "("._T('info_sans_titre_2').")"):
97 (isset($row['nom_email'])?sinon($row['nom_email'], "("._T('info_sans_titre_2').")"):
98 ""));
99 return array(typo(supprime_img($titre,'')),'');
100 }
101 // http://doc.spip.org/@afficher_titre_site
102 function afficher_titre_site($row){
103 $nom = $row['nom_site'];
104
105 $nom = $nom?(strlen($nom)>1?typo($nom):_T('info_sans_titre_2')):("("._T('info_sans_titre_2').")");
106
107 $s2 = "&nbsp;&nbsp; <span class='spip_xx-small'>[<a href='"
108 .$row['url_site']."'>"._T('lien_visite_site')."</a>]</span>";
109
110 return array($nom,$s2);
111 }
112 // http://doc.spip.org/@afficher_titre_auteur
113 function afficher_titre_auteur($row){
114 return array($row['nom'],
115 ((isset($row['restreint']) AND $row['restreint'])
116 ? (" &nbsp;<small>"._T('statut_admin_restreint')."</small>")
117 : ''));
118 }
119
120 // http://doc.spip.org/@afficher_titre_syndic_article
121 function afficher_titre_syndic_article($row){
122 return array('', recuperer_fond(
123 'prive/contenu/syndic_article',
124 array('id' => $row['id_syndic_article'])
125 ));
126 }
127
128 // http://doc.spip.org/@afficher_complement_objet
129 function afficher_complement_objet($type,$row){
130 if (function_exists($f = "afficher_complement_$type"))
131 return $f($row);
132 return "";
133 }
134
135 // http://doc.spip.org/@afficher_complement_site
136 function afficher_complement_site($row){
137 $syndication = $row['syndication'];
138 $s = "";
139 if ($syndication == 'off' OR $syndication == 'sus') {
140 $s .= "<div style='color: red;'>"
141 . http_img_pack('puce-orange-anim.gif', $syndication, "class='puce'",_T('info_panne_site_syndique'))
142 . " "._T('info_probleme_grave')." </div>";
143 }
144 if ($syndication == "oui" or $syndication == "off" OR $syndication == 'sus'){
145 $s .= "<div style='color: red;'>"._T('info_syndication')."</div>";
146 }
147 if ($syndication == "oui" OR $syndication == "off" OR $syndication == "sus") {
148 $id_syndic = $row['id_syndic'];
149 $total_art = sql_countsel("spip_syndic_articles", "id_syndic=$id_syndic");
150 $s .= " " . $total_art . " " . _T('info_syndication_articles');
151 } else {
152 $s .= "&nbsp;";
153 }
154 return $s;
155 }
156 // http://doc.spip.org/@afficher_complement_syndic_article
157 function afficher_complement_syndic_article($row){
158 global $my_sites;
159 if ($GLOBALS['exec'] != 'sites') {
160 $id_syndic = $row['id_syndic'];
161 // $my_sites cache les resultats des requetes sur les sites
162 if (!isset($my_sites[$id_syndic]))
163 $my_sites[$id_syndic] = sql_fetsel("nom_site, moderation, miroir", "spip_syndic", "id_syndic=$id_syndic");
164
165 $aff = $my_sites[$id_syndic]['nom_site'];
166 if ($my_sites[$id_syndic]['moderation'] == 'oui')
167 $aff = "<i>$aff</i>";
168
169 $s = "<a href='" . generer_url_ecrire("sites","id_syndic=$id_syndic") . "'>$aff</a>";
170
171 return $s;
172 }
173 return "";
174 }
175
176 // affichage des liste d'objets
177 // Cas generique, utilise pour tout sauf article
178 // http://doc.spip.org/@inc_afficher_objets_dist
179 function inc_afficher_objets_dist($type, $titre,$requete,$formater='', $force=false){
180 if ($afficher = charger_fonction("afficher_{$type}s",'inc',true)){
181 return $afficher($titre,$requete,$formater);
182 }
183
184 if (($GLOBALS['meta']['multi_rubriques'] == 'oui'
185 AND (!isset($GLOBALS['id_rubrique'])))
186 OR $GLOBALS['meta']['multi_articles'] == 'oui') {
187 $afficher_langue = true;
188
189 if (isset($GLOBALS['langue_rubrique'])) $langue_defaut = $GLOBALS['langue_rubrique'];
190 else $langue_defaut = $GLOBALS['meta']['langue_site'];
191 } else $afficher_langue = $langue_defaut = '';
192
193 $arg = array($afficher_langue, false, $langue_defaut, $formater, $type,id_table_objet($type));
194 if (!function_exists($skel = "afficher_{$type}s_boucle")){
195 $skel = "afficher_objet_boucle";
196 }
197
198 $presenter_liste = charger_fonction('presenter_liste', 'inc');
199 $tmp_var = 't_' . substr(md5(join('', $requete)), 0, 4);
200 $styles = array(array('arial11', 7), array('arial11'), array('arial1'), array('arial1'), array('arial1 centered', 100), array('arial1', 38));
201
202 $tableau = array(); // ne sert pas ici
203 return $presenter_liste($requete, $skel, $tableau, $arg, $force, $styles, $tmp_var, $titre, icone_table($type));
204 }
205
206 // http://doc.spip.org/@charger_fonction_logo_if
207 function charger_fonction_logo_if()
208 {
209 global $spip_display;
210
211 if ($spip_display == 1 OR $spip_display == 4 OR !isset($GLOBALS['meta']['image_process']))
212 return false;
213 if ($GLOBALS['meta']['image_process'] == "non") return false;
214 return charger_fonction('chercher_logo', 'inc');
215 }
216
217 // http://doc.spip.org/@afficher_objet_boucle
218 function afficher_objet_boucle($row, $own)
219 {
220 global $connect_statut, $spip_lang_right;
221 static $chercher_logo = true;
222
223 list($afficher_langue, $affrub, $langue_defaut, $formater,$type,$primary) = $own;
224 $vals = array();
225 $id_objet = $row[$primary];
226 if (autoriser('voir',$type,$id_objet)){
227
228 $date_heure = isset($row['date'])?$row['date']:(isset($row['date_heure'])?$row['date_heure']:"");
229
230 $statut = isset($row['statut'])?$row['statut']:"";
231 if (isset($row['lang']))
232 changer_typo($lang = $row['lang']);
233 else $lang = $langue_defaut;
234 $lang_dir = lang_dir($lang);
235 $id_rubrique = isset($row['id_rubrique'])?$row['id_rubrique']:0;
236
237 $puce_statut = charger_fonction('puce_statut', 'inc');
238 $vals[] = $puce_statut($id_objet, $statut, $id_rubrique, $type);
239
240 list($titre,$suite) = afficher_titre_objet($type,$row);
241 $flogo = '';
242 if ($chercher_logo) {
243 if ($chercher_logo !== true
244 OR $chercher_logo = charger_fonction_logo_if())
245 if ($logo = $chercher_logo($id_objet, $primary, 'on')) {
246 list($fid, $dir, $nom, $format) = $logo;
247 include_spip('inc/filtres_images_mini');
248 $logo = image_reduire("<img src='$fid' alt='' />", 26, 20);
249 if ($logo)
250 $flogo = "\n<span style='float: $spip_lang_right; margin-top: -2px; margin-bottom: -2px;'>$logo</span>";
251 }
252 }
253 if ($titre) {
254 $titre = "<a href='"
255 . lien_voir_objet($type,$primary,$id_objet)
256 . "'>"
257 . $titre
258 . "</a>";
259 }
260 $vals[] = "\n<div>$flogo$titre$suite</div>";
261
262 $s = "";
263 if ($afficher_langue){
264 if (isset($row['langue_choisie'])){
265 $s .= " <span class='spip_xx-small' style='color: #666666' dir='$lang_dir'>";
266 if ($row['langue_choisie'] == "oui") $s .= "<b>".traduire_nom_langue($lang)."</b>";
267 else $s .= "(".traduire_nom_langue($lang).")";
268 $s .= "</span>";
269 }
270 elseif ($lang != $langue_defaut)
271 $s .= " <span class='spip_xx-small' style='color: #666666' dir='$lang_dir'>".
272 ($lang
273 ? "(".traduire_nom_langue($lang).")"
274 : ''
275 )
276 ."</span>";
277 }
278 $vals[] = $s;
279
280 $vals[] = afficher_complement_objet($type,$row);
281
282 $s = "";
283 if ($affrub && $id_rubrique) {
284 $rub = sql_fetsel("id_rubrique, titre", "spip_rubriques", "id_rubrique=$id_rubrique");
285 $id_rubrique = $rub['id_rubrique'];
286 $s .= "<a href='" . generer_url_ecrire("naviguer","id_rubrique=$id_rubrique") . "' style=\"display:block;\">".typo($rub['titre'])."</a>";
287 } else
288 if ($statut){
289 if ($statut != "prop")
290 $s = affdate_jourcourt($date_heure);
291 else
292 $s .= _T('info_a_valider');
293 }
294 $vals[] = $s;
295
296 $vals[] = afficher_numero_edit($id_objet, $primary, $type, $row);
297 }
298 return $vals;
299 }
300
301 // Cas particuliers -----------------------------------------------------------------
302
303 //
304 // Afficher tableau d'articles
305 //
306 // http://doc.spip.org/@inc_afficher_articles_dist
307 function inc_afficher_articles_dist($titre, $requete, $formater='') {
308
309 if (!isset($requete['FROM'])) $requete['FROM'] = 'spip_articles AS articles';
310
311 if (!isset($requete['SELECT'])) {
312 $requete['SELECT'] = "articles.id_article, articles.titre, articles.id_rubrique, articles.statut, articles.date, articles.lang, articles.id_trad, articles.descriptif";
313 }
314
315 if (!isset($requete['GROUP BY'])) $requete['GROUP BY'] = '';
316
317 $cpt = sql_countsel($requete['FROM'], $requete['WHERE'], $requete['GROUP BY']);
318
319 if (!$cpt) return '' ;
320
321 $requete['FROM'] = preg_replace("/(spip_articles(\s+AS\s+\w+)?)/i", "\\1 LEFT JOIN spip_petitions AS petitions ON articles.id_article=petitions.id_article", $requete['FROM']);
322
323 $requete['SELECT'] .= ", petitions.id_article AS petition ";
324
325 // memorisation des arguments pour gerer l'affichage par tranche
326 // et/ou par langues.
327
328
329 $hash = sauver_requete($titre, $requete, $formater);
330
331 if (isset($requete['LIMIT'])) $cpt = min($requete['LIMIT'], $cpt);
332 return afficher_articles_trad($titre, $requete, $formater, $hash, $cpt);
333 }
334
335 //
336 // Stocke la fonction ajax dans le fichier temp pour exec=memoriser
337 //
338
339 // http://doc.spip.org/@sauver_requete
340 function sauver_requete($titre, $requete, $formater)
341 {
342 $r = $requete;
343 unset($r['ORDER BY']);
344 $hash = substr(md5(serialize($r) . $GLOBALS['meta']['gerer_trad'] . $titre), 0, 31);
345
346 // on lit l'existant
347 lire_fichier(_DIR_SESSIONS.'ajax_fonctions.txt', $ajax_fonctions);
348 $ajax_fonctions = @unserialize($ajax_fonctions);
349
350 // on ajoute notre fonction
351 $v = array(time(), $titre, $requete, $formater);
352 $ajax_fonctions[$hash] = $v;
353
354 // supprime les fonctions trop vieilles
355 foreach ($ajax_fonctions as $h => $fonc)
356 if (time() - $fonc[0] > 48*3600)
357 unset($ajax_fonctions[$h]);
358
359 // enregistre
360 ecrire_fichier(_DIR_SESSIONS.'ajax_fonctions.txt',
361 serialize($ajax_fonctions));
362
363 return $hash;
364
365 }
366 // http://doc.spip.org/@afficher_articles_trad
367 function afficher_articles_trad($titre_table, $requete, $formater, $hash, $cpt, $trad=0) {
368
369 global $spip_lang_right;
370
371 $tmp_var = 't' . substr($hash, 0, 7);
372
373 if ($trad) {
374 $formater = 'afficher_articles_trad_boucle';
375 $icone = "langues-off-12.gif";
376 $alt = _T('masquer_trad');
377 } else {
378 if (!$formater)
379 $formater = charger_fonction('formater_article', 'inc');
380 $icone = 'langues-12.gif';
381 $alt = _T('afficher_trad');
382 }
383
384 $texte = '<b>' . $titre_table . '</b>';
385
386 // Le parametre o sert a empecher le navigateur de reutiliser
387 // un cache de tranche issu d'un autre tri
388
389 $arg = "hash=$hash&o=" . $requete['ORDER BY'];
390
391 /*
392 // DESACTIVE CAR AJOUTE UNE COMPLEXITE INUTILE -- A REVOIR
393 // le micro "afficher les traductions"
394 if (($GLOBALS['meta']['gerer_trad'] == "oui")) {
395 $url = generer_url_ecrire('memoriser',"$arg&trad=" . (1-$trad));
396 $texte =
397 "\n<span style='float: $spip_lang_right;'><a href=\"#\""
398 . generer_onclic_ajax($url, $tmp_var, 0)
399 . "><img\nsrc='". chemin_image($icone) ."' alt='$alt' title='$alt' /></a></span>" . $texte;
400 }
401 */
402
403 /*
404 // DESACTIVE CAR AJOUTE UNE COMPLEXITE INUTILE -- A REVOIR
405 $url_t = generer_url_ecrire('memoriser',"hash=$hash&by=0%2Btitre,titre");
406 $url_t = afficher_boutons_tri($url_t, $tmp_var);
407
408 $url_d = generer_url_ecrire('memoriser',"hash=$hash&by=date");
409 $url_d = afficher_boutons_tri($url_d, $tmp_var);
410 */
411 $url_t = $url_d = '';
412 $presenter_liste = charger_fonction('presenter_liste', 'inc');
413 $styles = array(array('', 11), array('verdana12','', $url_t), array('arial1', 80), array('arial1', 100, $url_d), array('arial1', 50));
414 $tableau = array();
415 $url = generer_url_ecrire('memoriser', "$arg&trad=$trad");
416 $res = $presenter_liste($requete, $formater, $tableau, array(), false, $styles, $tmp_var, $texte, "article-24.gif", $url, $cpt);
417
418 return ajax_action_greffe($tmp_var, '', $res);
419 }
420
421 // http://doc.spip.org/@afficher_boutons_tri
422 function afficher_boutons_tri($url, $tmp_var)
423 {
424 static $monter = '';
425 static $descendre = '';
426
427 if (!$monter) {
428 $monter = http_img_pack('monter-16.png', '<');
429 $descendre = http_img_pack('descendre-16.png', '>');
430 }
431
432 $url_d = generer_onclic_ajax($url ."&amp;order=desc", $tmp_var, 0);
433 $url_a = generer_onclic_ajax($url ."&amp;order=asc", $tmp_var, 0);
434
435 return "<a href='$url'$url_d>$monter</a><a href='$url'$url_a>$descendre</a>";
436 }
437
438 // http://doc.spip.org/@afficher_articles_trad_boucle
439 function afficher_articles_trad_boucle($row, $own='')
440 {
441 global $spip_lang_right, $spip_display;
442
443 $id_article = $row['id_article'];
444 if (!autoriser('voir','article',$id_article)) return '';
445
446 $titre = $row['titre'];
447 $id_rubrique = $row['id_rubrique'];
448 $statut = $row['statut'];
449 $id_trad = $row['id_trad'];
450 $lang = $row['lang'];
451
452 $lang_dir = lang_dir($GLOBALS['lang_objet']);
453 $dates_art = $langues_art = array();
454 $ligne = "";
455
456 $res_trad = sql_select("id_article, lang, date_modif", "spip_articles", "id_trad = $id_trad AND id_trad > 0");
457
458 while ($row_trad = sql_fetch($res_trad)) {
459 $id_article_trad = $row_trad["id_article"];
460 $lang_trad = $row_trad["lang"];
461 $date = $row_trad['date_modif'];
462 $dates_art[$lang_trad] = $date;
463 $langues_art[$lang_trad] = $id_article_trad;
464 if ($id_article_trad == $id_trad) $date_ref = $date;
465 }
466
467 // faudrait sortir ces invariants de boucle
468
469 if (($GLOBALS['meta']['multi_rubriques'] == 'oui' AND (!isset($GLOBALS['id_rubrique']))) OR $GLOBALS['meta']['multi_articles'] == 'oui') {
470 $langue_defaut = isset($GLOBALS['langue_rubrique'])
471 ? $GLOBALS['meta']['langue_site']
472 : $GLOBALS['langue_rubrique'];
473 if ($lang != $langue_defaut)
474 $afficher_langue = " <span class='spip_xx-small' style='color: #666666' dir='$lang_dir'>(".traduire_nom_langue($lang).")</span>";
475 } else $afficher_langue = '';
476
477 foreach(explode(',', $GLOBALS['meta']['langues_multilingue']) as $k){
478 if (isset($langues_art[$k]) AND $langues_art[$k]<> $id_trad){
479 $h = generer_url_ecrire("articles", "id_article=".$langues_art[$k]);
480 $style = strtotime($dates_art[$k]) < strtotime($date_ref);
481 $style = $style ? 'claire' : 'foncee';
482 $ligne .= "<a href='$h' class='$style'>$k</a>";
483 }
484 }
485
486 if (acces_restreint_rubrique($id_rubrique))
487 $img = http_img_pack("admin-12.gif", _T('titre_image_administrateur'), "width='12' height='12'", _T('titre_image_admin_article'));
488 else $img = '';
489
490 if (!$titre) $titre = _T('ecrire:info_sans_titre');
491 if ($id_article == $id_trad) $titre = "<b>$titre</b>";
492
493 $h = generer_url_ecrire("articles", "id_article=$id_article");
494
495 $titre = "\n<div>"
496 . $img
497 . "<a href='$h' dir='$lang_dir' style=\"display:block;\">"
498 . typo(supprime_img($titre,''))
499 . "</a></div>";
500
501 if ($spip_display == 4) return array($ligne);
502
503 $ligne .= "<a href='$h'><span class='lang_base'>$lang</span></a>";
504
505 // La petite puce de changement de statut
506 $puce_statut = charger_fonction('puce_statut', 'inc');
507 $puce = $puce_statut($id_article, $statut, $id_rubrique,'article');
508
509 return array($puce,
510 $titre,
511 $afficher_langue,
512 "<div style='float: $spip_lang_right; margin-right: -10px;'>"
513 . $ligne
514 . "</div>");
515 }
516
517 // http://doc.spip.org/@afficher_auteurs_boucle
518 function afficher_auteurs_boucle($row, $own){
519 $vals = array();
520 list($afficher_langue, $affrub, $langue_defaut, $formater,$type,$primary) = $own;
521 $formater_auteur = $formater ? $formater : charger_fonction('formater_auteur', 'inc');
522 if ($row['statut'] == '0minirezo')
523 $row['restreint'] = sql_countsel('spip_auteurs_rubriques', "id_auteur=".intval($row['id_auteur']));
524
525 list($s, $mail, $nom, $w, $p) = $formater_auteur($row['id_auteur'],$row);
526 if ($w) {
527 if (preg_match(',^([^>]*>)[^<]*(.*)$,', $w,$r)) {
528 $w = $r[1] . substr($row['site'],0,20) . $r[2];
529 }
530 }
531 $vals[] = $s;
532 $vals[] = $mail;
533 $vals[] = $nom
534 . ((isset($row['restreint']) AND $row['restreint'])
535 ? (" &nbsp;<small>"._T('statut_admin_restreint')."</small>")
536 : '');
537 $vals[] = $w;
538 $vals[] = $p;
539 return $vals;
540 }
541 ?>