1 | <?php |
---|
2 | if (!defined('_ECRIRE_INC_VERSION')) return; |
---|
3 | /* |
---|
4 | * +----------------------------------+ |
---|
5 | * Nom du Filtre : Sommaire de l'article |
---|
6 | * +----------------------------------+ |
---|
7 | * Date : dimanche 9 février 2003 |
---|
8 | * Auteur : Noplay (noplay@altern.org) |
---|
9 | * +-------------------------------------+ |
---|
10 | * Fonctions de ce filtre : |
---|
11 | * Cette modification permet d'afficher le sommaire de son article |
---|
12 | * généré dynamiquement à partir du texte de l'article. Vous pouvez naviguer |
---|
13 | * dans l'article en cliquant sur les titres du sommaire. |
---|
14 | * |
---|
15 | * Tous ce qui ce trouve entre {{{ et }}} est considéré comme un titre à ajouter au sommaire de l'article. |
---|
16 | * +-------------------------------------+ |
---|
17 | * |
---|
18 | * Pour toute suggestion, remarque, proposition d'ajout |
---|
19 | * reportez-vous au forum de l'article : |
---|
20 | * http://www.spip-contrib.net/spip.php?article76 |
---|
21 | */ |
---|
22 | function sc_sommaire_article($texte,$istxt=0) |
---|
23 | { |
---|
24 | // Conversion des intertitres d'enluminures type {ß{titre}ß} |
---|
25 | // ou ß est un nombre en intertitres avec des étoiles type {{{* (avec ß étoiles) |
---|
26 | // {1{ sera converti en {{{* ; {2{ sera converti en {{{** ; etc. |
---|
27 | $texte=preg_replace_callback ("/(\{(\d)\{)(.*?)(\}\\2\})/", |
---|
28 | create_function ( |
---|
29 | '$matches', |
---|
30 | 'return "{{{".str_repeat("*",$matches[2]).$matches[3]."}}}";' |
---|
31 | ), |
---|
32 | $texte); |
---|
33 | |
---|
34 | preg_match_all("|\{\{\{([*]*?)(.*)(\}\}\})|U", $texte, $regs); |
---|
35 | |
---|
36 | |
---|
37 | $nb=1; |
---|
38 | $lastniveau=0; |
---|
39 | if ($istxt==0) { |
---|
40 | $texte=''; |
---|
41 | for($j=0;$j<count($regs[2]);$j++) { |
---|
42 | $niveau=strlen($regs[1][$j]); |
---|
43 | if ($niveau===0) {$niveau=1;} |
---|
44 | if ($niveau==$lastniveau) { |
---|
45 | $texte.="</li>\n"; |
---|
46 | } |
---|
47 | if ($niveau>$lastniveau) { |
---|
48 | $texte.="<ul>"; |
---|
49 | $lastniveau=$niveau; |
---|
50 | } |
---|
51 | if ($niveau<$lastniveau) { |
---|
52 | $texte.="</li>\n"; |
---|
53 | for($ulli=$niveau;$ulli<$lastniveau;$ulli++) { |
---|
54 | $texte.="</ul></li>\n"; |
---|
55 | } |
---|
56 | $lastniveau=$niveau; |
---|
57 | } |
---|
58 | |
---|
59 | $texte.="<li><a href=\"#sommaire_".$nb."\">".$regs[2][$j]."</a>"; |
---|
60 | $nb++; |
---|
61 | } |
---|
62 | for($j=0;$j<$niveau;$j++) { |
---|
63 | $texte.="</li></ul>\n"; |
---|
64 | } |
---|
65 | |
---|
66 | if ($nb>1) { |
---|
67 | $texte="<a name='SommaireAutomatique'></a>".$texte; |
---|
68 | } |
---|
69 | |
---|
70 | } else { |
---|
71 | $texte=""; |
---|
72 | for($j=0;$j<count($regs[2]);$j++) |
---|
73 | { |
---|
74 | $niveau=strlen($regs[1][$j]); |
---|
75 | if ($niveau===0) {$niveau=1;} |
---|
76 | if ($niveau===1) { $puce="\n- ";} |
---|
77 | if ($niveau===2) { $puce=" · ";} |
---|
78 | if ($niveau===3) { $puce=" × ";} |
---|
79 | if ($niveau===4) { $puce=" ° ";} |
---|
80 | if ($niveau===5) { $puce=" ¤ ";} |
---|
81 | $texte.=$puce.$regs[2][$j]."\n"; |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|
85 | return $texte; |
---|
86 | } |
---|
87 | |
---|
88 | function sc_sommaire_ancre($texte) |
---|
89 | { |
---|
90 | $retoursommaire = _T('soyezcreateurs:retoursommaire'); |
---|
91 | |
---|
92 | $texte = preg_replace("|(<h[23456][^>]*>)(.*)(<\/h[23456]>)|U","<p class='retoursommaire'><a href='#SommaireAutomatique'>".$retoursommaire."</a></p><a name=\"sommaire_#NB_TITRE_DE_MON_ARTICLE#\"></a>$1$2$3", $texte); |
---|
93 | |
---|
94 | $array = explode("#NB_TITRE_DE_MON_ARTICLE#" , $texte); |
---|
95 | $res =count($array); |
---|
96 | $i =1; |
---|
97 | $texte=$array[0]; |
---|
98 | while($i<$res) |
---|
99 | { |
---|
100 | $texte.=$i.$array[$i]; |
---|
101 | $i++; |
---|
102 | } |
---|
103 | if ($i>1) { |
---|
104 | $texte.="<p class='retoursommaire'><a href='#SommaireAutomatique'>".$retoursommaire."</a></p>"; |
---|
105 | } |
---|
106 | return $texte; |
---|
107 | } |
---|
108 | //Fin filtre sommaire de l'article |
---|
109 | |
---|
110 | function sc_prepareNLtexte($texte) { |
---|
111 | // Remplace tous les liens |
---|
112 | while (eregi("<a href=['\"]([^'\">]+)['\"][^>]*>([^<]+)</a>", $texte, $regs)) { |
---|
113 | $cleanReg1 = ereg_replace("\\?", "\?", $regs[1]); |
---|
114 | $cleanReg1 = ereg_replace("\\+", "\+", $cleanReg1); |
---|
115 | $cleanReg2 = ereg_replace("\\?", "\?", $regs[2]); |
---|
116 | $cleanReg2 = ereg_replace("\\+", "\+", $cleanReg2); |
---|
117 | if ($regs[1] == $regs[2]) { |
---|
118 | $texte = eregi_replace("<a href=['\"]".$cleanReg1."['\"][^>]*>".$cleanReg1."</a>", $regs[1], $texte); |
---|
119 | } else { |
---|
120 | if ($regs[1] == str_replace(" ?","?",$regs[2])) { |
---|
121 | $texte = eregi_replace("<a href=['\"]".$cleanReg1."['\"][^>]*>".$cleanReg2."</a>", $regs[1], $texte); |
---|
122 | } else { |
---|
123 | $texte = eregi_replace("<a href=['\"]".$cleanReg1."['\"][^>]*>".$cleanReg2."</a>", str_replace(" ?","?",$regs[2])." (".$regs[1].")", $texte); |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | $texte = preg_replace("|(<h[2]>)(.*)(<\/h[2]>)|U","<br /><br />----------------------------------------------------------------------<br />$1$2$3<br />----------------------------------------------------------------------<br />", $texte); |
---|
128 | $texte = preg_replace("|(<h[3456]>)(.*)(<\/h[3456]>)|U","<br />···· $1$2$3 ····", $texte); |
---|
129 | $texte = ereg_replace ('<li[^>]>', "\n".'-', $texte); |
---|
130 | $texte = ereg_replace ('’', '\'', $texte); |
---|
131 | $texte = ereg_replace ('«', '"', $texte); |
---|
132 | $texte = ereg_replace ('»', '"', $texte); |
---|
133 | $texte = ereg_replace ('&', '&', $texte); |
---|
134 | $texte = textebrut($texte); |
---|
135 | $texte = wordwrap($texte, 70, "\n"); |
---|
136 | return $texte; |
---|
137 | } |
---|
138 | |
---|
139 | function sc_nettoyer_marqueur($texte) { |
---|
140 | include_spip('inc/charsets'); |
---|
141 | $texte=translitteration($texte); |
---|
142 | // Enlève la conversion caractères spéciaux HTML |
---|
143 | $trans_tbl = get_html_translation_table (HTML_ENTITIES); |
---|
144 | $trans_tbl = array_flip ($trans_tbl); |
---|
145 | $texte=strtr ($texte, $trans_tbl); |
---|
146 | $accents = |
---|
147 | /* A */ chr(192).chr(193).chr(194).chr(195).chr(196).chr(197). |
---|
148 | /* a */ chr(224).chr(225).chr(226).chr(227).chr(228).chr(229). |
---|
149 | /* O */ chr(210).chr(211).chr(212).chr(213).chr(214).chr(216). |
---|
150 | /* o */ chr(242).chr(243).chr(244).chr(245).chr(246).chr(248). |
---|
151 | /* E */ chr(200).chr(201).chr(202).chr(203). |
---|
152 | /* e */ chr(232).chr(233).chr(234).chr(235). |
---|
153 | /* Cc */ chr(199).chr(231). |
---|
154 | /* I */ chr(204).chr(205).chr(206).chr(207). |
---|
155 | /* i */ chr(236).chr(237).chr(238).chr(239). |
---|
156 | /* U */ chr(217).chr(218).chr(219).chr(220). |
---|
157 | /* u */ chr(249).chr(250).chr(251).chr(252). |
---|
158 | /* yNn */ chr(255).chr(209).chr(241); |
---|
159 | $texte = preg_replace("#<[^<]*>#", "", $texte); |
---|
160 | $texte = preg_replace("#[^A-Za-z0-9]#", "_", strtr($texte,$accents,"AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn")); |
---|
161 | $texte = preg_replace("#Â #", "_", $texte); |
---|
162 | $texte = preg_replace("#\s#", "_", $texte); |
---|
163 | $texte = preg_replace("#_+#", "_", $texte); |
---|
164 | return strtolower($texte); |
---|
165 | } |
---|
166 | |
---|
167 | /* à appliquer au #TEXTE de forum */ |
---|
168 | function sc_anti_glouton($texte) { |
---|
169 | $regexp = '|<a href=["\x27]([^"\x27]+)["\x27][^>]*>([^<]+)</a>|i'; |
---|
170 | $replace = "\${2} [\${1}]"; |
---|
171 | $texte = preg_replace($regexp, $replace, $texte); |
---|
172 | return $texte; |
---|
173 | } |
---|
174 | |
---|
175 | function sc_replace($texte,$search,$replace) { |
---|
176 | return trim(str_replace($search,$replace,$texte)); |
---|
177 | } |
---|
178 | |
---|
179 | function sc_NewLine2str($texte) { |
---|
180 | return str_replace('"','\"',str_replace("\r",'',str_replace("\n",'\n',$texte))); |
---|
181 | } |
---|
182 | |
---|
183 | function sc_DateAdd($d=null, $v, $f="Y-m-d"){ |
---|
184 | return date($f,strtotime($v." days",strtotime($d))); |
---|
185 | } |
---|
186 | |
---|
187 | function sc_annee_scolaire($ladate) { |
---|
188 | if ($ladate=='') return ''; |
---|
189 | $annee = annee($ladate); |
---|
190 | $mois = mois($ladate); |
---|
191 | if ($mois <= 8) $annee -= 1; |
---|
192 | return $annee; |
---|
193 | } |
---|
194 | |
---|
195 | function sc_garder_body($texte) { |
---|
196 | $texte = eregi_replace('^.*<body[^>]*>', '', $texte); |
---|
197 | $texte = eregi_replace('</body>.*$', '', $texte); |
---|
198 | $texte = eregi_replace('^.*<!-- CutHere -->', '', $texte); |
---|
199 | $texte = eregi_replace('<!-- /CutHere -->.*$', '', $texte); |
---|
200 | return $texte; |
---|
201 | } |
---|
202 | |
---|
203 | /* Permet dans un texte de faire [->refsite12] qui fera un lien vers la page du site en cours décrivant ce site (et non pas un lien direct vers le site de destination) */ |
---|
204 | function generer_url_refsite($id, $args, $ancre) { |
---|
205 | return array('site', $id); |
---|
206 | } |
---|
207 | |
---|
208 | /* Transforme un texte en lien raccourcis SPIP et calcule le résultat */ |
---|
209 | function sc_texte2urlspip($url) { |
---|
210 | return expanser_liens('[->'.$url.']'); |
---|
211 | } |
---|
212 | |
---|
213 | function sc_trouver_corr_un ($id_article) { |
---|
214 | $row = sql_fetsel('spip_articles.id_article, spip_articles.titre', |
---|
215 | 'spip_articles', |
---|
216 | "id_article=$id_article"); |
---|
217 | return $row; |
---|
218 | } |
---|
219 | function sc_trouver_corr_pl ($id_article) { |
---|
220 | $row = sql_fetsel( |
---|
221 | 'spip_articles.id_article, spip_rubriques.titre, spip_rubriques.id_rubrique, spip_rubriques.id_secteur', |
---|
222 | 'spip_articles LEFT JOIN spip_rubriques ON spip_rubriques.id_rubrique = spip_articles.id_rubrique', |
---|
223 | "id_article=$id_article"); |
---|
224 | return $row; |
---|
225 | } |
---|
226 | function sc_decoder_date ($date_d, $date_e, $horaire='oui', $mode=false, $court=false) { |
---|
227 | if($mode == 'skel') { |
---|
228 | $date_d = date_ical($date_d); |
---|
229 | $date_e = date_ical($date_e); |
---|
230 | } |
---|
231 | $debut = array(); |
---|
232 | $debut['annee'] = substr($date_d, 0, 4); |
---|
233 | $debut['mois'] = substr($date_d, 4, 2); |
---|
234 | $debut['jour'] = substr($date_d, 6, 2); |
---|
235 | $debut['heure'] = substr($date_d, 9, 2); |
---|
236 | $debut['minutes'] = substr($date_d, 11, 2); |
---|
237 | $debut['secondes'] = substr($date_d, 13, 2); |
---|
238 | $debut['mois_fr'] = sc_get_mois($debut['mois']); |
---|
239 | $debut['jour_fr'] = (sc_get_jour(mktime($debut['heure'], $debut['minutes'], $debut['secondes'], $debut['mois'], $debut['jour'], $debut['annee']))); |
---|
240 | $fin = array(); |
---|
241 | $fin['annee'] = substr($date_e, 0, 4); |
---|
242 | $fin['mois'] = substr($date_e, 4, 2); |
---|
243 | $fin['jour'] = substr($date_e, 6, 2); |
---|
244 | $fin['heure'] = substr($date_e, 9, 2); |
---|
245 | $fin['minutes'] = substr($date_e, 11, 2); |
---|
246 | $fin['secondes'] = substr($date_e, 13, 2); |
---|
247 | $fin['mois_fr'] = sc_get_mois($fin['mois']); |
---|
248 | $fin['jour_fr'] = sc_get_jour(mktime($fin['heure'], $fin['minutes'], $fin['secondes'], $fin['mois'], $fin['jour'], $fin['annee'])); |
---|
249 | $get_same = sc_same_day($debut, $fin); |
---|
250 | if ($get_same) { |
---|
251 | if ($court == 'oui') { |
---|
252 | $resultat = '<acronym title="'. ucfirst($debut['jour_fr']).'" class="spip_acronym">'. ucfirst(substr($debut['jour_fr'],0,2)).'</acronym> '.$debut['jour'].' '; |
---|
253 | } |
---|
254 | else { |
---|
255 | if (intval($debut['jour']) < 10) |
---|
256 | $debut['jour'] = substr($debut['jour'], 1, 1); |
---|
257 | if ($horaire=='oui') { |
---|
258 | $comd = $debut['heure'].$debut['minutes']; |
---|
259 | $comf = $fin['heure'].$fin['minutes']; |
---|
260 | if ($comd == $comf) { |
---|
261 | $resultat = _T('soyezcreateurs:agenda_sd_h', array( |
---|
262 | 'djour_l' => ($debut['jour_fr']), |
---|
263 | 'djour' => $debut['jour'], |
---|
264 | 'dmois_l' => $debut['mois_fr'], |
---|
265 | 'dannee' => $debut['annee'], |
---|
266 | 'dheure' => $debut['heure'], |
---|
267 | 'dminutes' => $debut['minutes'], |
---|
268 | ) |
---|
269 | ); |
---|
270 | } |
---|
271 | else { |
---|
272 | $resultat = _T('soyezcreateurs:agenda_sd', array( |
---|
273 | 'djour_l' => $debut['jour_fr'], |
---|
274 | 'djour' => $debut['jour'], |
---|
275 | 'dmois_l' => $debut['mois_fr'], |
---|
276 | 'dannee' => $debut['annee'], |
---|
277 | 'dheure' => $debut['heure'], |
---|
278 | 'dminutes' => $debut['minutes'], |
---|
279 | 'fheure' => $fin['heure'], |
---|
280 | 'fminutes' => $fin['minutes'] |
---|
281 | ) |
---|
282 | ); |
---|
283 | } |
---|
284 | } else { |
---|
285 | $resultat = _T('soyezcreateurs:agenda_sd_notime', array( |
---|
286 | 'djour_l' => ($debut['jour_fr']), |
---|
287 | 'djour' => $debut['jour'], |
---|
288 | 'dmois_l' => $debut['mois_fr'], |
---|
289 | 'dannee' => $debut['annee'] |
---|
290 | ) |
---|
291 | ); |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | else if (!$get_same) { |
---|
296 | if ($court == 'oui') { |
---|
297 | $resultat = '<acronym title="'. ucfirst($debut['jour_fr']).'" class="spip_acronym">'. ucfirst(substr($debut['jour_fr'],0,2)).'</acronym> '.$debut['jour']; |
---|
298 | $resultat .= ' – <acronym title="'.$fin['jour_fr'].'" class="spip_acronym">'.substr($fin['jour_fr'],0,2).'</acronym> '.$fin['jour']; |
---|
299 | if ($fin['annee'] != $debut['annee']) { |
---|
300 | $resultat .= ' '.$fin['mois_fr'].' '.$fin['annee'].' '; |
---|
301 | } else if ($fin['mois'] != $debut['mois']) { |
---|
302 | $resultat .= ' '.$fin['mois_fr'].' '; |
---|
303 | } else { |
---|
304 | $resultat .= ' '; |
---|
305 | } |
---|
306 | } |
---|
307 | else { |
---|
308 | if (intval($debut['jour']) < 10) |
---|
309 | $debut['jour'] = substr($debut['jour'], 1, 1); |
---|
310 | if (intval($fin['jour']) < 10) |
---|
311 | $fin['jour'] = substr($fin['jour'], 1, 1); |
---|
312 | if ($horaire=='oui') { |
---|
313 | $resultat = _T('soyezcreateurs:agenda_fsd', array( |
---|
314 | 'djour_l' => ($debut['jour_fr']), |
---|
315 | 'djour' => $debut['jour'], |
---|
316 | 'dmois_l' => $debut['mois_fr'], |
---|
317 | 'dannee' => $debut['annee'], |
---|
318 | 'dheure' => $debut['heure'], |
---|
319 | 'dminutes' => $debut['minutes'], |
---|
320 | 'fjour_l' => $fin['jour_fr'], |
---|
321 | 'fjour' => $fin['jour'], |
---|
322 | 'fmois_l' => $fin['mois_fr'], |
---|
323 | 'fannee' => $fin['annee'], |
---|
324 | 'fheure' => $fin['heure'], |
---|
325 | 'fminutes' => $fin['minutes'] |
---|
326 | ) |
---|
327 | ); |
---|
328 | } else { |
---|
329 | $resultat = _T('soyezcreateurs:agenda_fsd_notime', array( |
---|
330 | 'djour_l' => ($debut['jour_fr']), |
---|
331 | 'djour' => $debut['jour'], |
---|
332 | 'dmois_l' => $debut['mois_fr'], |
---|
333 | 'dannee' => $debut['annee'], |
---|
334 | 'fjour_l' => $fin['jour_fr'], |
---|
335 | 'fjour' => $fin['jour'], |
---|
336 | 'fmois_l' => $fin['mois_fr'], |
---|
337 | 'fannee' => $fin['annee'] |
---|
338 | ) |
---|
339 | ); |
---|
340 | } |
---|
341 | } |
---|
342 | } |
---|
343 | return $resultat; |
---|
344 | } |
---|
345 | function sc_same_day ($debut, $fin) { |
---|
346 | $start = mktime(0, 0, 0, $debut['mois'], $debut['jour'], $debut['annee']); |
---|
347 | $end = mktime(0, 0, 0, $fin['mois'], $fin['jour'], $fin['annee']); |
---|
348 | if ($start == $end) |
---|
349 | return true; |
---|
350 | else if ($start != $end) |
---|
351 | return false; |
---|
352 | } |
---|
353 | function sc_get_mois ($nb) { |
---|
354 | $mois["01"] = _T('date_mois_1'); |
---|
355 | $mois["02"] = _T('date_mois_2'); |
---|
356 | $mois["03"] = _T('date_mois_3'); |
---|
357 | $mois["04"] = _T('date_mois_4'); |
---|
358 | $mois["05"] = _T('date_mois_5'); |
---|
359 | $mois["06"] = _T('date_mois_6'); |
---|
360 | $mois["07"] = _T('date_mois_7'); |
---|
361 | $mois["08"] = _T('date_mois_8'); |
---|
362 | $mois["09"] = _T('date_mois_9'); |
---|
363 | $mois["10"] = _T('date_mois_10'); |
---|
364 | $mois["11"] = _T('date_mois_11'); |
---|
365 | $mois["12"] = _T('date_mois_12'); |
---|
366 | return $mois[$nb]; |
---|
367 | } |
---|
368 | function sc_get_jour ($nb) { |
---|
369 | $nb = intval($nb); |
---|
370 | $j = date("w", $nb); |
---|
371 | $jour["0"] = _T('date_jour_1'); |
---|
372 | $jour["1"] = _T('date_jour_2'); |
---|
373 | $jour["2"] = _T('date_jour_3'); |
---|
374 | $jour["3"] = _T('date_jour_4'); |
---|
375 | $jour["4"] = _T('date_jour_5'); |
---|
376 | $jour["5"] = _T('date_jour_6'); |
---|
377 | $jour["6"] = _T('date_jour_7'); |
---|
378 | return $jour[$j]; |
---|
379 | } |
---|
380 | function sc_agenda_mini($i) { |
---|
381 | $args = func_get_args(); |
---|
382 | $une_date = array_shift($args); // une date comme balise |
---|
383 | $sinon = array_shift($args); |
---|
384 | if (!$une_date) return $sinon; |
---|
385 | $type = 'sc_mini'; |
---|
386 | $agenda = sc_Agenda_memo_full(0); |
---|
387 | $evt = array(); |
---|
388 | foreach (($args ? $args : array_keys($agenda)) as $k) { |
---|
389 | if (is_array($agenda[$k])) |
---|
390 | foreach($agenda[$k] as $d => $v) { |
---|
391 | $evt[$d] = $evt[$d] ? (array_merge($evt[$d], $v)) : $v; |
---|
392 | } |
---|
393 | } |
---|
394 | $la_date = mktime(0, 0, 0, mois($une_date), 1, annee($une_date)); |
---|
395 | include_spip('inc/agenda'); |
---|
396 | return http_calendrier_init($la_date, $type, '', '', '', array('', $evt)); |
---|
397 | } |
---|
398 | function sc_agenda_grand($i) { |
---|
399 | $args = func_get_args(); |
---|
400 | $une_date = array_shift($args); // une date comme balise |
---|
401 | $sinon = array_shift($args); |
---|
402 | if (!$une_date) return $sinon; |
---|
403 | $type = 'sc_grand'; |
---|
404 | $agenda = sc_Agenda_memo_full(0); |
---|
405 | $evt = array(); |
---|
406 | foreach (($args ? $args : array_keys($agenda)) as $k) { |
---|
407 | if (is_array($agenda[$k])) |
---|
408 | foreach($agenda[$k] as $d => $v) { |
---|
409 | $evt[$d] = $evt[$d] ? (array_merge($evt[$d], $v)) : $v; |
---|
410 | } |
---|
411 | } |
---|
412 | $la_date = mktime(0, 0, 0, mois($une_date), 1, annee($une_date)); |
---|
413 | include_spip('inc/agenda'); |
---|
414 | return http_calendrier_init($la_date, $type, '', '', '', array('', $evt)); |
---|
415 | } |
---|
416 | function sc_generer_ligne_agenda($jour, $amj, $evts, $type, $agenda) { |
---|
417 | //definissons le retour en un tableau |
---|
418 | $aff = array(); |
---|
419 | //s'il y a un/des evenement(s) |
---|
420 | if ($evts) { |
---|
421 | $nb_elmts= @count($evts); |
---|
422 | //s'il y a plus d'un evenements |
---|
423 | if ($nb_elmts>1){ |
---|
424 | if ($agenda == 'mini') { |
---|
425 | $row = sc_trouver_corr_pl($evts[0]['ID']); |
---|
426 | $date_debut = $evts[0]['LIENJOUR']; |
---|
427 | $id_rub = intval($row['id_secteur']); |
---|
428 | $titre_rub = supprimer_numero(extraire_multi($row['titre'])); |
---|
429 | $url = generer_url_public('agenda_calendrier', array('id_rubrique'=>$id_rub,'date_ev'=>$date_debut)); |
---|
430 | $url_javascript = generer_url_public('agenda_calendrier_dyn', array('id_rubrique'=>$id_rub,'date_ev'=>$date_debut)); |
---|
431 | $aff['ligne'] = "<a href='".$url."' title='".supprimer_tags(typo($titre_rub))." ("._T('agenda:voir_evenements_rubrique').")' onclick=\"event.preventDefault();window.location.href='".$url_javascript."';\">".intval($jour)."</a>"; |
---|
432 | } |
---|
433 | foreach($evts as $key => $ev) { |
---|
434 | if ($agenda == 'grand') { |
---|
435 | if ($key == 0) { |
---|
436 | $aff['ligne'] .= intval($jour); |
---|
437 | $aff['ligne'] .= '<div class="odd">'; |
---|
438 | $row = sc_trouver_corr_pl($ev['ID']); |
---|
439 | $row2 = sc_trouver_corr_un($ev['ID']); |
---|
440 | $aff['ligne'] .= '<strong>'.supprimer_numero(typo(extraire_multi($row['titre']))).'</strong> : '; |
---|
441 | $url = generer_url_entite($row2['id_article'], 'article'); |
---|
442 | if (supprimer_tags(typo($ev['SUMMARY'])) == supprimer_numero(typo(extraire_multi($row2['titre'])))) |
---|
443 | $aff['ligne'] .= "<a href='".$url."'>".$ev['SUMMARY']."</a>"; |
---|
444 | else |
---|
445 | $aff['ligne'] .= "<a href='".$url."'>".supprimer_numero(typo(extraire_multi($row2['titre'])))." : ".$ev['SUMMARY']."</a>"; |
---|
446 | $aff['ligne'] .= '</div>'; |
---|
447 | } |
---|
448 | else { |
---|
449 | $aff['ligne'] .= '<div>'; |
---|
450 | $row = sc_trouver_corr_pl($ev['ID']); |
---|
451 | $row2 = sc_trouver_corr_un($ev['ID']); |
---|
452 | $aff['ligne'] .= "<strong>".supprimer_numero(typo(extraire_multi($row['titre'])))."</strong> : "; |
---|
453 | $url = generer_url_entite($row2['id_article'], 'article'); |
---|
454 | if (supprimer_tags(typo($ev['SUMMARY'])) == supprimer_numero(extraire_multi(typo($row2['titre'])))) |
---|
455 | $aff['ligne'] .= "<a href='".$url."'>".$ev['SUMMARY']."</a>"; |
---|
456 | else |
---|
457 | $aff['ligne'] .= "<a href='".$url."'>".supprimer_numero(typo(extraire_multi($row2['titre'])))." : ".$ev['SUMMARY']."</a>"; |
---|
458 | $aff['ligne'] .= '</div>'; |
---|
459 | } |
---|
460 | } |
---|
461 | } |
---|
462 | $aff['class']= $type.' events'; |
---|
463 | } |
---|
464 | //s'il n'y a qu'un evenement |
---|
465 | else{ |
---|
466 | if ($agenda == 'grand') { |
---|
467 | $aff['ligne'] .= intval($jour); |
---|
468 | $aff['ligne'] .= '<div class="odd">'; |
---|
469 | $row = sc_trouver_corr_pl($evts[0]['ID']); |
---|
470 | $row2 = sc_trouver_corr_un($evts[0]['ID']); |
---|
471 | $aff['ligne'] .= '<strong>'.supprimer_numero(typo(extraire_multi($row['titre']))).'</strong> : '; |
---|
472 | $url = generer_url_entite($row2['id_article'], 'article'); |
---|
473 | if (supprimer_tags(typo($evts[0]['SUMMARY'])) == supprimer_numero(typo(extraire_multi($row2['titre'])))) |
---|
474 | $aff['ligne'] .= "<a href='".$url."'>".$evts[0]['SUMMARY']."</a>"; |
---|
475 | else |
---|
476 | $aff['ligne'] .= "<a href='".$url."'>".supprimer_numero(typo(extraire_multi($row2['titre'])))." : ".$evts[0]['SUMMARY']."</a>"; |
---|
477 | $aff['ligne'] .= '</div>'; |
---|
478 | } |
---|
479 | else if ($agenda == 'mini') { |
---|
480 | $row = sc_trouver_corr_un($evts[0]['ID']); |
---|
481 | $url = generer_url_entite($row['id_article'], 'article'); |
---|
482 | $info = sc_decoder_date($evts[0]['DTSTART'], $evts[0]['DTEND'], $evts[0]['HORAIRE']); |
---|
483 | if (supprimer_tags(typo($evts[0]['SUMMARY'])) == supprimer_numero(typo(extraire_multi($row['titre'])))) |
---|
484 | $title = supprimer_numero(typo(extraire_multi($row['titre'])))." - ".$info; |
---|
485 | else |
---|
486 | $title = supprimer_numero(typo(extraire_multi($row['titre'])))." : ".$evts[0]['SUMMARY']." - ".$info; |
---|
487 | $aff['ligne'] = "<a href='".$url."' title='".supprimer_tags(typo($title))."'>".intval($jour)."</a>"; |
---|
488 | } |
---|
489 | $aff['class']= $type.' event'; |
---|
490 | } |
---|
491 | } |
---|
492 | //s'il n'y a rien |
---|
493 | else { |
---|
494 | $aff['ligne'] = intval($jour); |
---|
495 | $aff['class'] = $type; |
---|
496 | } |
---|
497 | return $aff; |
---|
498 | } |
---|
499 | function http_calendrier_sc_grand($annee, $mois, $jour, $echelle, $partie_cal, $script, $ancre, $evt) { |
---|
500 | list($sansduree, $evenements, $premier_jour, $dernier_jour) = $evt; |
---|
501 | |
---|
502 | if ($sansduree) |
---|
503 | foreach($sansduree as $d => $r) { |
---|
504 | $evenements[$d] = !$evenements[$d] ? $r : |
---|
505 | array_merge($evenements[$d], $r); |
---|
506 | } |
---|
507 | |
---|
508 | if (!$premier_jour) $premier_jour = '01'; |
---|
509 | if (!$dernier_jour) { |
---|
510 | $dernier_jour = 31; |
---|
511 | while (!(checkdate($mois,$dernier_jour,$annee))) $dernier_jour--; |
---|
512 | } |
---|
513 | |
---|
514 | // affichage du debut de semaine hors periode |
---|
515 | $ligne = ''; |
---|
516 | $debut = date("w",mktime(1,1,1,$mois,$premier_jour,$annee)); |
---|
517 | for ($i=$debut ? $debut : 7;$i>1;$i--) { |
---|
518 | $mois_t_precedent = mktime(1,1,1,$mois-1,1,$annee); |
---|
519 | $jour_mois_precedent = date('t', $mois_t_precedent)+2-$i; |
---|
520 | $mois_precedent = date("m",$mois_t_precedent); |
---|
521 | $annee_en_cours = date("Y",$nom); |
---|
522 | $amj = date("Y",$mois_t_precedent) . $mois_precedent . $jour_mois_precedent; |
---|
523 | $evts = $evenements[$amj]; |
---|
524 | $aff = sc_generer_ligne_agenda($jour_mois_precedent, $amj, $evts, 'agendanotthismonth', 'grand'); |
---|
525 | $ligne .= '<td valign="top" class="'.$aff['class'].'">'.$aff['ligne'].'</td>'; |
---|
526 | } |
---|
527 | //mois en cours |
---|
528 | $total = ''; |
---|
529 | for ($j=$premier_jour; $j<=$dernier_jour; $j++) { |
---|
530 | $nom = mktime(1,1,1,$mois,$j,$annee); |
---|
531 | $jour = date("d",$nom); |
---|
532 | $jour_semaine = date("w",$nom); |
---|
533 | $mois_en_cours = date("m",$nom); |
---|
534 | $annee_en_cours = date("Y",$nom); |
---|
535 | $amj = date("Y",$nom) . $mois_en_cours . $jour; |
---|
536 | if ($jour_semaine==1 AND $ligne != '') { |
---|
537 | $total .= "\n<tr>$ligne\n</tr>"; |
---|
538 | $ligne = ''; |
---|
539 | } |
---|
540 | $evts = $evenements[$amj]; |
---|
541 | $aff = sc_generer_ligne_agenda($jour, $amj, $evts, 'agendathismonth', 'grand'); |
---|
542 | $ligne .= '<td valign="top" class="'.($amj == date("Ymd")?"agendathisday": $aff['class']).'">' . $aff['ligne'] . '</td>'; |
---|
543 | } |
---|
544 | $jour_mois_suivant=0; |
---|
545 | // affichage de la fin de semaine hors periode |
---|
546 | for($j=$jour_semaine ? $jour_semaine : 7; $j<7; $j++) { |
---|
547 | $nom = mktime(1,1,1,$mois+1,$j,$annee); |
---|
548 | $jour = date("d",$nom); |
---|
549 | $jour_semaine = date("w",$nom); |
---|
550 | $mois_suivant = date("m",$nom); |
---|
551 | $annee_en_cours = date("Y",$nom); |
---|
552 | $amj = date("Y",$nom) . $mois_suivant . '0'.$jour_mois_suivant++; |
---|
553 | $evts = $evenements[$amj]; |
---|
554 | $aff = sc_generer_ligne_agenda($jour_mois_suivant, $amj, $evts, 'agendanotthismonth', 'grand'); |
---|
555 | $ligne .= '<td valign="top" class="'.$aff['class'].'">'.$aff['ligne'].'</td>'; |
---|
556 | } |
---|
557 | |
---|
558 | return $total . ($ligne ? "\n<tr>$ligne\n</tr>" : ''); |
---|
559 | } |
---|
560 | |
---|
561 | |
---|
562 | function http_calendrier_sc_mini($annee, $mois, $jour, $echelle, $partie_cal, $script, $ancre, $evt) { |
---|
563 | list($sansduree, $evenements, $premier_jour, $dernier_jour) = $evt; |
---|
564 | |
---|
565 | if ($sansduree) |
---|
566 | foreach($sansduree as $d => $r) { |
---|
567 | $evenements[$d] = !$evenements[$d] ? $r : |
---|
568 | array_merge($evenements[$d], $r); |
---|
569 | } |
---|
570 | |
---|
571 | if (!$premier_jour) $premier_jour = '01'; |
---|
572 | if (!$dernier_jour) { |
---|
573 | $dernier_jour = 31; |
---|
574 | while (!(checkdate($mois,$dernier_jour,$annee))) $dernier_jour--; |
---|
575 | } |
---|
576 | |
---|
577 | // affichage du debut de semaine hors periode |
---|
578 | $ligne = ''; |
---|
579 | $debut = date("w",mktime(1,1,1,$mois,$premier_jour,$annee)); |
---|
580 | for ($i=$debut ? $debut : 7;$i>1;$i--) { |
---|
581 | $mois_t_precedent = mktime(1,1,1,$mois-1,1,$annee); |
---|
582 | $jour_mois_precedent = date('t', $mois_t_precedent)+2-$i; |
---|
583 | $mois_precedent = date("m",$mois_t_precedent); |
---|
584 | $annee_en_cours = date("Y",$nom); |
---|
585 | $amj = date("Y",$mois_t_precedent) . $mois_precedent . $jour_mois_precedent; |
---|
586 | $evts = $evenements[$amj]; |
---|
587 | $aff = sc_generer_ligne_agenda($jour_mois_precedent, $amj, $evts, 'agendanotthismonth', 'mini'); |
---|
588 | $ligne .= '<td class="'.$aff['class'].'">'.$aff['ligne'].'</td>'; |
---|
589 | } |
---|
590 | //mois en cours |
---|
591 | $total = ''; |
---|
592 | for ($j=$premier_jour; $j<=$dernier_jour; $j++) { |
---|
593 | $nom = mktime(1,1,1,$mois,$j,$annee); |
---|
594 | $jour = date("d",$nom); |
---|
595 | $jour_semaine = date("w",$nom); |
---|
596 | $mois_en_cours = date("m",$nom); |
---|
597 | $annee_en_cours = date("Y",$nom); |
---|
598 | $amj = date("Y",$nom) . $mois_en_cours . $jour; |
---|
599 | |
---|
600 | if ($jour_semaine==1 AND $ligne != '') { |
---|
601 | $total .= "\n<tr>$ligne\n</tr>"; |
---|
602 | $ligne = ''; |
---|
603 | } |
---|
604 | |
---|
605 | $evts = $evenements[$amj]; |
---|
606 | $aff = sc_generer_ligne_agenda($jour, $amj, $evts, 'agendathismonth', 'mini'); |
---|
607 | $ligne .= '<td class="'.($amj == date("Ymd")?"agendathisday": $aff['class']).'">' . $aff['ligne'] . '</td>'; |
---|
608 | } |
---|
609 | $jour_mois_suivant=1; |
---|
610 | // affichage de la fin de semaine hors periode |
---|
611 | for($j=$jour_semaine ? $jour_semaine : 7; $j<7; $j++) { |
---|
612 | $nom = mktime(1,1,1,$mois+1,$j,$annee); |
---|
613 | $jour = date("d",$nom); |
---|
614 | $jour_semaine = date("w",$nom); |
---|
615 | $mois_suivant = date("m",$nom); |
---|
616 | $annee_en_cours = date("Y",$nom); |
---|
617 | $amj = date("Y",$nom) . $mois_suivant . '0'.$jour_mois_suivant; |
---|
618 | $evts = $evenements[$amj]; |
---|
619 | $aff = sc_generer_ligne_agenda($jour_mois_suivant++, $amj, $evts, 'agendanotthismonth', 'mini'); |
---|
620 | $ligne .= '<td class="'.$aff['class'].'">'.$aff['ligne'].'</td>'; |
---|
621 | } |
---|
622 | |
---|
623 | return $total . ($ligne ? "\n<tr>$ligne\n</tr>" : ''); |
---|
624 | } |
---|
625 | function sc_agenda_memo_full($date_deb=0, $date_fin=0 , $titre='', $descriptif='', $lieu='', $url='', $horaire='oui', $cal='') |
---|
626 | { |
---|
627 | static $agenda = array(); |
---|
628 | if (!$date_deb) { |
---|
629 | $res = $agenda; |
---|
630 | $agenda=array(); |
---|
631 | return $res; |
---|
632 | } |
---|
633 | $url=str_replace("&","&",$url); |
---|
634 | |
---|
635 | $idatedeb = date_ical($date_deb); |
---|
636 | $idatefin = date_ical($date_fin); |
---|
637 | $vidatefin = date_ical($date_fin); |
---|
638 | $cal = trim($cal); // func_get_args (filtre alterner) rajoute \n !!!! |
---|
639 | $startday1=explode(' ',$date_deb); |
---|
640 | $startday1=$startday1['0'].' 00:00:00'; |
---|
641 | $ts_startday1=strtotime($startday1); |
---|
642 | $ts_date_fin=strtotime($date_fin); |
---|
643 | $maxdays=365; |
---|
644 | while (($ts_startday1<=$ts_date_fin)&&($maxdays-->0)) |
---|
645 | { |
---|
646 | $day=date('Y-m-d H:i:s',$ts_startday1); |
---|
647 | $lienjour=date('Y-m-d',$ts_startday1); |
---|
648 | $agenda[$cal][(date_anneemoisjour($day))][] = array( |
---|
649 | 'CATEGORIES' => $cal, |
---|
650 | 'DTSTART' => $idatedeb, |
---|
651 | 'DTEND' => $vidatefin, |
---|
652 | 'DESCRIPTION' => $descriptif, |
---|
653 | 'SUMMARY' => supprimer_numero(typo(extraire_multi($titre))), |
---|
654 | 'HORAIRE' => $horaire, |
---|
655 | 'LOCATION' => $lieu, |
---|
656 | 'ID' => $url, |
---|
657 | 'LIENJOUR' => $lienjour); |
---|
658 | $ts_startday1 += 26*3600; // le jour suivant : +26 h pour gerer les changements d'heure |
---|
659 | $ts_startday1 = mktime(0, 0, 0, date("m",$ts_startday1), |
---|
660 | date("d",$ts_startday1), date("Y",$ts_startday1)); // et remise a zero de l'heure |
---|
661 | } |
---|
662 | // toujours retourner vide pour qu'il ne se passe rien |
---|
663 | return ""; |
---|
664 | } |
---|
665 | |
---|
666 | function js2PhpTime($jsdate){ |
---|
667 | if(preg_match('@(\d+)/(\d+)/(\d+)\s+(\d+):(\d+)@', $jsdate, $matches)==1){ |
---|
668 | $ret = mktime($matches[4], $matches[5], 0, $matches[1], $matches[2], $matches[3]); |
---|
669 | }else if(preg_match('@(\d+)/(\d+)/(\d+)@', $jsdate, $matches)==1){ |
---|
670 | $ret = mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]); |
---|
671 | } |
---|
672 | return $ret; |
---|
673 | } |
---|
674 | |
---|
675 | function php2JsTime($phpDate){ |
---|
676 | return date("m/d/Y H:i", $phpDate); |
---|
677 | } |
---|
678 | |
---|
679 | function php2MySqlTime($phpDate){ |
---|
680 | return date("Y-m-d H:i:s", $phpDate); |
---|
681 | } |
---|
682 | |
---|
683 | function mySql2PhpTime($sqlDate){ |
---|
684 | $arr = date_parse($sqlDate); |
---|
685 | return mktime($arr["hour"],$arr["minute"],$arr["second"],$arr["month"],$arr["day"],$arr["year"]); |
---|
686 | } |
---|
687 | |
---|
688 | function sc_wdcalendar_json($day, $type) { |
---|
689 | $phpTime = js2PhpTime($day); |
---|
690 | |
---|
691 | switch($type){ |
---|
692 | case "month": |
---|
693 | $st = mktime(0, 0, 0, date("m", $phpTime), 1, date("Y", $phpTime)); |
---|
694 | $et = mktime(0, 0, -1, date("m", $phpTime)+1, 1, date("Y", $phpTime)); |
---|
695 | break; |
---|
696 | case "week": |
---|
697 | //suppose first day of a week is monday |
---|
698 | $monday = date("d", $phpTime) - date('N', $phpTime) + 1; |
---|
699 | //echo date('N', $phpTime); |
---|
700 | $st = mktime(0,0,0,date("m", $phpTime), $monday, date("Y", $phpTime)); |
---|
701 | $et = mktime(0,0,-1,date("m", $phpTime), $monday+7, date("Y", $phpTime)); |
---|
702 | break; |
---|
703 | case "day": |
---|
704 | $st = mktime(0, 0, 0, date("m", $phpTime), date("d", $phpTime), date("Y", $phpTime)); |
---|
705 | $et = mktime(0, 0, -1, date("m", $phpTime), date("d", $phpTime)+1, date("Y", $phpTime)); |
---|
706 | break; |
---|
707 | } |
---|
708 | |
---|
709 | $ret = array(); |
---|
710 | $ret['events'] = array(); |
---|
711 | $ret["issort"] =true; |
---|
712 | $ret["start"] = php2JsTime($st); |
---|
713 | $ret["end"] = php2JsTime($et); |
---|
714 | $ret['error'] = null; |
---|
715 | |
---|
716 | $where = array( |
---|
717 | "date_debut between '".php2MySqlTime($st)."' and '".php2MySqlTime($et)."'", |
---|
718 | ); |
---|
719 | if($resultats = sql_select('*', "spip_evenements", $where)) { |
---|
720 | while($row = sql_fetch($resultats)) { |
---|
721 | |
---|
722 | $date_debut = intval(date('Ymd',mySql2PhpTime($row['date_debut']))); |
---|
723 | $date_fin = intval(date('Ymd',mySql2PhpTime($row['date_fin']))); |
---|
724 | |
---|
725 | if($date_fin > $date_debut OR $row['horaire'] == 'non') { |
---|
726 | $AllTheDay = 1; |
---|
727 | } else $AllTheDay = 0; |
---|
728 | |
---|
729 | $colorEvent = intval($row['id_evenement'])%13; |
---|
730 | |
---|
731 | $ret['events'][] = array( |
---|
732 | intval($row['id_evenement']), |
---|
733 | unicode2charset(html2unicode(supprimer_tags(supprimer_numero(typo(extraire_multi($row['titre'])))))), |
---|
734 | php2JsTime(mySql2PhpTime($row['date_debut'])), |
---|
735 | php2JsTime(mySql2PhpTime($row['date_fin'])), |
---|
736 | 0, |
---|
737 | $AllTheDay, //more than one day event |
---|
738 | 0,//Recurring event, |
---|
739 | $colorEvent, //color |
---|
740 | 0,//editable |
---|
741 | unicode2charset(html2unicode(supprimer_tags(supprimer_numero(typo(extraire_multi($row['lieu'])))))), //lieu |
---|
742 | urlencode_1738(generer_url_entite(intval($row['id_article']), 'article')) //url article spip //$attends |
---|
743 | ); |
---|
744 | } |
---|
745 | } |
---|
746 | |
---|
747 | // return print_r($ret,1); |
---|
748 | |
---|
749 | return json_encode($ret); |
---|
750 | } |
---|
751 | |
---|
752 | function balise_ARTICLE_URL_dist($p) { |
---|
753 | if (!is_array($p->param)) |
---|
754 | $p->param=array(); |
---|
755 | |
---|
756 | // Produire le premier argument {article_url} |
---|
757 | $texte = new Texte; |
---|
758 | $texte->type='texte'; |
---|
759 | $texte->texte='article_url'; |
---|
760 | $param = array(0=>NULL, 1=>array(0=>$texte)); |
---|
761 | array_unshift($p->param, $param); |
---|
762 | |
---|
763 | // Transformer les filtres en arguments |
---|
764 | for ($i=1; $i<count($p->param); $i++) { |
---|
765 | if ($p->param[$i][0]) { |
---|
766 | if (!strstr($p->param[$i][0], '=')) |
---|
767 | break;# on a rencontre un vrai filtre, c'est fini |
---|
768 | $texte = new Texte; |
---|
769 | $texte->type='texte'; |
---|
770 | $texte->texte=$p->param[$i][0]; |
---|
771 | $param = array(0=>$texte); |
---|
772 | $p->param[$i][1] = $param; |
---|
773 | $p->param[$i][0] = NULL; |
---|
774 | } |
---|
775 | } |
---|
776 | |
---|
777 | // Appeler la balise #MODELE{article_url}{arguments} |
---|
778 | if (!function_exists($f = 'balise_modele')) |
---|
779 | $f = 'balise_modele_dist'; |
---|
780 | return $f($p); |
---|
781 | } |
---|
782 | |
---|
783 | |
---|
784 | @define('_MOT_MASQUER', 'Archives'); |
---|
785 | |
---|
786 | // ajoute le critere {archive x} |
---|
787 | function critere_archive_dist($idb, &$boucles, $crit) { |
---|
788 | static $id_mot; |
---|
789 | static $liste_rubriques; |
---|
790 | static $liste_articles; |
---|
791 | $boucle = &$boucles[$idb]; |
---|
792 | $id_table = $boucle->id_table; |
---|
793 | $marchive = $id_table .'.archive'; |
---|
794 | |
---|
795 | $boucle->modificateur['criteres']['archive'] = true; |
---|
796 | $not = $crit->not; |
---|
797 | |
---|
798 | // Cas de la boucle ARTICLES |
---|
799 | if ($boucle->type_requete == 'articles') { |
---|
800 | $art = $boucle->id_table . '.id_article'; |
---|
801 | $boucle->from['zzzma'] = 'spip_mots_articles'; |
---|
802 | $boucle->from['zzzm'] = 'spip_mots'; |
---|
803 | $boucle->join['zzzma'] = array("'articles'","'id_article'"); |
---|
804 | $boucle->join['zzzm'] = array("'zzzma'","'id_mot'"); |
---|
805 | if ($not) { |
---|
806 | $boucle->where[] = array("'NOT'", |
---|
807 | array("'IN'", "'articles.id_article'", |
---|
808 | array("'SELF'", "'articles.id_article'", |
---|
809 | array("'='", "'zzzm.titre'", "sql_quote(_MOT_MASQUER)")))); |
---|
810 | |
---|
811 | $boucle->where[] = masquer_articles_accessibles_where($art,'NOT '); |
---|
812 | } else { |
---|
813 | $boucle->where[] = array("''", |
---|
814 | array("'IN'", "'articles.id_article'", |
---|
815 | array("'SELF'", "'articles.id_article'", |
---|
816 | array("'='", "'zzzm.titre'", "sql_quote(_MOT_MASQUER)"))), |
---|
817 | array("'OR'", |
---|
818 | masquer_articles_accessibles_where($art,''))); |
---|
819 | } |
---|
820 | } |
---|
821 | } |
---|
822 | |
---|
823 | /** |
---|
824 | * Renvoyer le code de la condition where pour la liste des rubriques masquées |
---|
825 | * |
---|
826 | * @param string $primary |
---|
827 | * @return string |
---|
828 | */ |
---|
829 | function masquer_rubriques_where($primary, $_publique=''){ |
---|
830 | # hack : on utilise zzz pour eviter que l'optimiseur ne confonde avec un morceau de la requete principale |
---|
831 | return "array('NOT IN','$primary','('.sql_get_select('zzzr.id_rubrique','spip_mots_rubriques as zzzr, spip_mots as zzzm',\"zzzr.id_mot=zzzm.id_mot AND zzzm.titre=".sql_quote(_MOT_MASQUER)."\",'','','','',\$connect).')')"; |
---|
832 | } |
---|
833 | |
---|
834 | /** |
---|
835 | * Renvoyer le code de la condition where pour la liste des rubriques accessibles |
---|
836 | * |
---|
837 | * @param string $primary |
---|
838 | * @return string |
---|
839 | */ |
---|
840 | function masquer_rubriques_accessibles_where($primary,$not='NOT', $_publique=''){ |
---|
841 | return "sql_in('$primary','".implode(',', masquer_liste_rubriques($_publique))."', '$not')"; |
---|
842 | } |
---|
843 | |
---|
844 | /** |
---|
845 | * liste des rubriques masquer, directement ou par heritage. |
---|
846 | * |
---|
847 | * @param int/string $id_zone |
---|
848 | * @return array |
---|
849 | */ |
---|
850 | function masquer_liste_rubriques($publique=true){ |
---|
851 | // cache static |
---|
852 | static $liste_rubriques = array(); |
---|
853 | include_spip('inc/rubriques'); |
---|
854 | $liste_rubriques = masquer_liste_rub_direct(); |
---|
855 | if (!count($liste_rubriques)) |
---|
856 | return $liste_rubriques; |
---|
857 | $liste_rubriques = calcul_branche_in(join(',',$liste_rubriques)); |
---|
858 | if (!strlen($liste_rubriques)) |
---|
859 | return array(); |
---|
860 | $liste_rubriques = explode(',',$liste_rubriques); |
---|
861 | return $liste_rubriques; |
---|
862 | } |
---|
863 | |
---|
864 | /** |
---|
865 | * liste des rubriques masquer directement. |
---|
866 | * |
---|
867 | * @return array |
---|
868 | */ |
---|
869 | function masquer_liste_rub_direct(){ |
---|
870 | $liste_rubriques=array(); |
---|
871 | // liste des rubriques directement masquer |
---|
872 | $where = array(); |
---|
873 | include_spip('base/abstract_sql'); |
---|
874 | $liste_rubriques = sql_allfetsel('id_rubrique','spip_mots_rubriques AS mr INNER JOIN spip_mots AS m ON mr.id_mot=m.id_mot','m.titre='.sql_quote(_MOT_MASQUER)); |
---|
875 | $liste_rubriques = array_map('reset',$liste_rubriques); |
---|
876 | $liste_rubriques = array_unique($liste_rubriques); |
---|
877 | return $liste_rubriques; |
---|
878 | } |
---|
879 | |
---|
880 | /** |
---|
881 | * Renvoyer la condition where pour la liste des articles masquer |
---|
882 | * |
---|
883 | * @param string $primary |
---|
884 | * @return string |
---|
885 | */ |
---|
886 | function masquer_articles_accessibles_where($primary, $critnot='', $_publique=''){ |
---|
887 | # hack : on utilise zzz pour eviter que l'optimiseur ne confonde avec un morceau de la requete principale |
---|
888 | return "array('$critnot IN','$primary','('.sql_get_select('zzza.id_article','spip_articles as zzza',".masquer_rubriques_accessibles_where('zzza.id_rubrique','',$_publique).",'','','','',\$connect).')')"; |
---|
889 | } |
---|
890 | |
---|
891 | /** |
---|
892 | * Renvoyer la condition where pour la liste des articles masquer |
---|
893 | * |
---|
894 | * @param string $primary |
---|
895 | * @return string |
---|
896 | */ |
---|
897 | function masquer_articles_where($primary, $_publique=''){ |
---|
898 | # hack : on utilise zzz pour eviter que l'optimiseur ne confonde avec un morceau de la requete principale |
---|
899 | return "array('<>','$primary','('.sql_get_select('zzza.id_article','spip_articles as zzza, spip_mots_articles as sma',".masquer_rubriques_accessibles_where('zzza.id_rubrique','',$_publique).",'','','','',\$connect).')')"; |
---|
900 | } |
---|
901 | |
---|
902 | /** Plugin Dictionnaires **/ |
---|
903 | /* |
---|
904 | * Fonction de remplacement par défaut pour les termes trouvés dans les textes |
---|
905 | */ |
---|
906 | function dictionnaires_remplacer_defaut($mot, $definition){ |
---|
907 | return $mot |
---|
908 | .'<sup><a href="' |
---|
909 | .($definition['url']?$definition['url']:generer_url_public('sigles', 'id_dictionnaire='.$definition['id_dictionnaire'].'#sigle'.$definition['id_definition'])) |
---|
910 | .'" title="'._T('definition:titre_definition').': '.couper(trim(attribut_html(supprimer_tags(typo($definition['texte'])))),80).'">' |
---|
911 | .'?' |
---|
912 | .'</a></sup>'; |
---|
913 | } |
---|
914 | |
---|
915 | /* |
---|
916 | * Fonction de remplacement par défaut pour les abbréviations trouvées dans les textes |
---|
917 | * Ceci est un EXEMPLE montrant qu'on peut mettre un truc différent pour un type de définition précis |
---|
918 | * Mais ce code est une MAUVAISE PRATIQUE en accessibilité |
---|
919 | * (car seuls les gens avec des yeux valides et un pointeur de souris ont accès à l'information) |
---|
920 | */ |
---|
921 | function dictionnaires_remplacer_abbr($mot, $definition){ |
---|
922 | return '<abbr title="'.couper(trim(attribut_html(supprimer_tags(typo($definition['texte'])))),80).'">'.$mot.'</abbr>'; |
---|
923 | /* Pas de texte rajouté après : pose problème sur |couper et |attribut_html |
---|
924 | .'<sup><a href="' |
---|
925 | .($definition['url']?$definition['url']:generer_url_public('sigles', 'id_dictionnaire='.$definition['id_dictionnaire'].'&type=abbr#sigle'.$definition['id_definition'])) |
---|
926 | .'" title="'._T('definition:titre_definition').': '.couper(trim(attribut_html(supprimer_tags(typo($definition['texte'])))),80).'">' |
---|
927 | .'?' |
---|
928 | .'</a></sup>'; |
---|
929 | */ |
---|
930 | } |
---|
931 | |
---|
932 | ?> |
---|