74bdabb41ebe084e0d508a581b993725bb2e7578
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
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 $GLOBALS['my_sites']=array();
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]))
22 return "$type-24.gif";
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");
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");
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>]";
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>]";
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').')';
56 else /* 'dispo' ou 'off' (dans le cas ancien site 'miroir') */
58 $s = "[<a href='". redirige_action_auteur('instituer_syndic',"$id-publie", _request('exec'), $redirect) . "'>"._T('info_valider_lien')."</a>]";
65 $style = " class='spip_xx-small' style='float: $spip_lang_right; padding-$spip_lang_left: 4px; color: black; '";
67 $numero = _T('info_numero_abbreviation');
70 if (!autoriser('modifier',$type,$id) OR
71 !$href = lien_editer_objet($type,$key,$id)) {
78 . _T('bouton_modifier')
81 return "<$bal$style$href><b>"
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"))
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').")"):
99 return array(typo(supprime_img($titre,'')),'');
101 // http://doc.spip.org/@afficher_titre_site
102 function afficher_titre_site($row){
103 $nom = $row['nom_site'];
105 $nom = $nom?
(strlen($nom)>1?
typo($nom):_T('info_sans_titre_2')):("("._T('info_sans_titre_2').")");
107 $s2 = " <span class='spip_xx-small'>[<a href='"
108 .$row['url_site']."'>"._T('lien_visite_site')."</a>]</span>";
110 return array($nom,$s2);
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 ?
(" <small>"._T('statut_admin_restreint')."</small>")
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'])
128 // http://doc.spip.org/@afficher_complement_objet
129 function afficher_complement_objet($type,$row){
130 if (function_exists($f = "afficher_complement_$type"))
135 // http://doc.spip.org/@afficher_complement_site
136 function afficher_complement_site($row){
137 $syndication = $row['syndication'];
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>";
144 if ($syndication == "oui" or $syndication == "off" OR $syndication == 'sus'){
145 $s .= "<div style='color: red;'>"._T('info_syndication')."</div>";
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');
156 // http://doc.spip.org/@afficher_complement_syndic_article
157 function afficher_complement_syndic_article($row){
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");
165 $aff = $my_sites[$id_syndic]['nom_site'];
166 if ($my_sites[$id_syndic]['moderation'] == 'oui')
167 $aff = "<i>$aff</i>";
169 $s = "<a href='" . generer_url_ecrire("sites","id_syndic=$id_syndic") . "'>$aff</a>";
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);
184 if (($GLOBALS['meta']['multi_rubriques'] == 'oui'
185 AND (!isset($GLOBALS['id_rubrique'])))
186 OR $GLOBALS['meta']['multi_articles'] == 'oui') {
187 $afficher_langue = true;
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 = '';
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";
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));
202 $tableau = array(); // ne sert pas ici
203 return $presenter_liste($requete, $skel, $tableau, $arg, $force, $styles, $tmp_var, $titre, icone_table($type));
206 // http://doc.spip.org/@charger_fonction_logo_if
207 function charger_fonction_logo_if()
209 global $spip_display;
211 if ($spip_display == 1 OR $spip_display == 4 OR !isset($GLOBALS['meta']['image_process']))
213 if ($GLOBALS['meta']['image_process'] == "non") return false;
214 return charger_fonction('chercher_logo', 'inc');
217 // http://doc.spip.org/@afficher_objet_boucle
218 function afficher_objet_boucle($row, $own)
220 global $connect_statut, $spip_lang_right;
221 static $chercher_logo = true;
223 list($afficher_langue, $affrub, $langue_defaut, $formater,$type,$primary) = $own;
225 $id_objet = $row[$primary];
226 if (autoriser('voir',$type,$id_objet)){
228 $date_heure = isset($row['date'])?
$row['date']:(isset($row['date_heure'])?
$row['date_heure']:"");
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;
237 $puce_statut = charger_fonction('puce_statut', 'inc');
238 $vals[] = $puce_statut($id_objet, $statut, $id_rubrique, $type);
240 list($titre,$suite) = afficher_titre_objet($type,$row);
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);
250 $flogo = "\n<span style='float: $spip_lang_right; margin-top: -2px; margin-bottom: -2px;'>$logo</span>";
255 . lien_voir_objet($type,$primary,$id_objet)
260 $vals[] = "\n<div>$flogo$titre$suite</div>";
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).")";
270 elseif ($lang != $langue_defaut)
271 $s .= " <span class='spip_xx-small' style='color: #666666' dir='$lang_dir'>".
273 ?
"(".traduire_nom_langue($lang).")"
280 $vals[] = afficher_complement_objet($type,$row);
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>";
289 if ($statut != "prop")
290 $s = affdate_jourcourt($date_heure);
292 $s .= _T('info_a_valider');
296 $vals[] = afficher_numero_edit($id_objet, $primary, $type, $row);
301 // Cas particuliers -----------------------------------------------------------------
304 // Afficher tableau d'articles
306 // http://doc.spip.org/@inc_afficher_articles_dist
307 function inc_afficher_articles_dist($titre, $requete, $formater='') {
309 if (!isset($requete['FROM'])) $requete['FROM'] = 'spip_articles AS articles';
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";
315 if (!isset($requete['GROUP BY'])) $requete['GROUP BY'] = '';
317 $cpt = sql_countsel($requete['FROM'], $requete['WHERE'], $requete['GROUP BY']);
319 if (!$cpt) return '' ;
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']);
323 $requete['SELECT'] .= ", petitions.id_article AS petition ";
325 // memorisation des arguments pour gerer l'affichage par tranche
326 // et/ou par langues.
329 $hash = sauver_requete($titre, $requete, $formater);
331 if (isset($requete['LIMIT'])) $cpt = min($requete['LIMIT'], $cpt);
332 return afficher_articles_trad($titre, $requete, $formater, $hash, $cpt);
336 // Stocke la fonction ajax dans le fichier temp pour exec=memoriser
339 // http://doc.spip.org/@sauver_requete
340 function sauver_requete($titre, $requete, $formater)
343 unset($r['ORDER BY']);
344 $hash = substr(md5(serialize($r) . $GLOBALS['meta']['gerer_trad'] . $titre), 0, 31);
347 lire_fichier(_DIR_SESSIONS
.'ajax_fonctions.txt', $ajax_fonctions);
348 $ajax_fonctions = @unserialize
($ajax_fonctions);
350 // on ajoute notre fonction
351 $v = array(time(), $titre, $requete, $formater);
352 $ajax_fonctions[$hash] = $v;
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]);
360 ecrire_fichier(_DIR_SESSIONS
.'ajax_fonctions.txt',
361 serialize($ajax_fonctions));
366 // http://doc.spip.org/@afficher_articles_trad
367 function afficher_articles_trad($titre_table, $requete, $formater, $hash, $cpt, $trad=0) {
369 global $spip_lang_right;
371 $tmp_var = 't' . substr($hash, 0, 7);
374 $formater = 'afficher_articles_trad_boucle';
375 $icone = "langues-off-12.gif";
376 $alt = _T('masquer_trad');
379 $formater = charger_fonction('formater_article', 'inc');
380 $icone = 'langues-12.gif';
381 $alt = _T('afficher_trad');
384 $texte = '<b>' . $titre_table . '</b>';
386 // Le parametre o sert a empecher le navigateur de reutiliser
387 // un cache de tranche issu d'un autre tri
389 $arg = "hash=$hash&o=" . $requete['ORDER BY'];
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));
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;
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);
408 $url_d = generer_url_ecrire('memoriser',"hash=$hash&by=date");
409 $url_d = afficher_boutons_tri($url_d, $tmp_var);
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));
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);
418 return ajax_action_greffe($tmp_var, '', $res);
421 // http://doc.spip.org/@afficher_boutons_tri
422 function afficher_boutons_tri($url, $tmp_var)
425 static $descendre = '';
428 $monter = http_img_pack('monter-16.png', '<');
429 $descendre = http_img_pack('descendre-16.png', '>');
432 $url_d = generer_onclic_ajax($url ."&order=desc", $tmp_var, 0);
433 $url_a = generer_onclic_ajax($url ."&order=asc", $tmp_var, 0);
435 return "<a href='$url'$url_d>$monter</a><a href='$url'$url_a>$descendre</a>";
438 // http://doc.spip.org/@afficher_articles_trad_boucle
439 function afficher_articles_trad_boucle($row, $own='')
441 global $spip_lang_right, $spip_display;
443 $id_article = $row['id_article'];
444 if (!autoriser('voir','article',$id_article)) return '';
446 $titre = $row['titre'];
447 $id_rubrique = $row['id_rubrique'];
448 $statut = $row['statut'];
449 $id_trad = $row['id_trad'];
450 $lang = $row['lang'];
452 $lang_dir = lang_dir($GLOBALS['lang_objet']);
453 $dates_art = $langues_art = array();
456 $res_trad = sql_select("id_article, lang, date_modif", "spip_articles", "id_trad = $id_trad AND id_trad > 0");
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;
467 // faudrait sortir ces invariants de boucle
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 = '';
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>";
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'));
490 if (!$titre) $titre = _T('ecrire:info_sans_titre');
491 if ($id_article == $id_trad) $titre = "<b>$titre</b>";
493 $h = generer_url_ecrire("articles", "id_article=$id_article");
497 . "<a href='$h' dir='$lang_dir' style=\"display:block;\">"
498 . typo(supprime_img($titre,''))
501 if ($spip_display == 4) return array($ligne);
503 $ligne .= "<a href='$h'><span class='lang_base'>$lang</span></a>";
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');
512 "<div style='float: $spip_lang_right; margin-right: -10px;'>"
517 // http://doc.spip.org/@afficher_auteurs_boucle
518 function afficher_auteurs_boucle($row, $own){
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']));
525 list($s, $mail, $nom, $w, $p) = $formater_auteur($row['id_auteur'],$row);
527 if (preg_match(',^([^>]*>)[^<]*(.*)$,', $w,$r)) {
528 $w = $r[1] . substr($row['site'],0,20) . $r[2];
534 . ((isset($row['restreint']) AND $row['restreint'])
535 ?
(" <small>"._T('statut_admin_restreint')."</small>")