1 | <?php |
---|
2 | |
---|
3 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
4 | |
---|
5 | // Filtre pour afficher les statistiques d'un mot-clé |
---|
6 | // Code inspiré de la fonction presenter_groupe_mots_boucle dans ecrire/inc/grouper_mots.php |
---|
7 | function filtre_statistiques_mot_dist($id_mot){ |
---|
8 | include_spip('base/abstract_sql'); |
---|
9 | $texte_lie = array(); |
---|
10 | $id_mot = intval($id_mot); |
---|
11 | |
---|
12 | $na = sql_countsel('spip_mots_articles',"id_mot=$id_mot"); |
---|
13 | if ($na == 1) |
---|
14 | $texte_lie[] = _T('info_1_article'); |
---|
15 | else if ($na > 1) |
---|
16 | $texte_lie[] = $na." "._T('info_articles_02'); |
---|
17 | |
---|
18 | $nb = sql_countsel('spip_mots_breves',"id_mot=$id_mot"); |
---|
19 | if ($nb == 1) |
---|
20 | $texte_lie[] = _T('info_1_breve'); |
---|
21 | else if ($nb > 1) |
---|
22 | $texte_lie[] = $nb." "._T('info_breves_03'); |
---|
23 | |
---|
24 | $ns = sql_countsel('spip_mots_syndic',"id_mot=$id_mot"); |
---|
25 | if ($ns == 1) |
---|
26 | $texte_lie[] = _T('info_1_site'); |
---|
27 | else if ($ns > 1) |
---|
28 | $texte_lie[] = $ns." "._T('info_sites'); |
---|
29 | |
---|
30 | $nr = sql_countsel('spip_mots_rubriques',"id_mot=$id_mot"); |
---|
31 | if ($nr == 1) |
---|
32 | $texte_lie[] = _T('info_une_rubrique_02'); |
---|
33 | else if ($nr > 1) |
---|
34 | $texte_lie[] = $nr." "._T('info_rubriques_02'); |
---|
35 | |
---|
36 | $texte_lie = pipeline('afficher_nombre_objets_associes_a',array('args'=>array('objet'=>'mot','id_objet'=>$id_mot),'data'=>$texte_lie)); |
---|
37 | $texte_lie = join($texte_lie,", "); |
---|
38 | return $texte_lie; |
---|
39 | } |
---|
40 | |
---|
41 | // Critère compteur_publie |
---|
42 | // Provient de http://www.spip-contrib.net/Classer-les-articles-par-nombre-de-commentaires |
---|
43 | |
---|
44 | function critere_compteur_publie($idb, &$boucles, $crit){ |
---|
45 | $op=''; |
---|
46 | $boucle = &$boucles[$idb]; |
---|
47 | $params = $crit->param; |
---|
48 | $type = array_shift($params); |
---|
49 | $type = $type[0]->texte; |
---|
50 | if(preg_match(',^(\w+)([<>=])([0-9]+)$,',$type,$r)){ |
---|
51 | $type=$r[1]; |
---|
52 | $op=$r[2]; |
---|
53 | $op_val=$r[3]; |
---|
54 | } |
---|
55 | $type_id = 'compt.id_'.$type; |
---|
56 | $type_requete = $boucle->type_requete; |
---|
57 | $id_table = $boucle->id_table . '.' . $boucle->primary; |
---|
58 | $boucle->select[]= 'COUNT('.$type_id.') AS compteur_'.$type; |
---|
59 | $boucle->from['compt']="spip_".$type; |
---|
60 | $boucle->from_type['compt']= "LEFT"; |
---|
61 | // On passe par cette jointure pour que les articles avec 0 commentaires soient comptés |
---|
62 | // Merci notation ! |
---|
63 | $boucle->join["compt"]= array("'$boucle->id_table'","'$boucle->primary'","'$boucle->primary'","'compt.statut='.sql_quote('publie')"); |
---|
64 | $boucle->group[]=$id_table; |
---|
65 | if ($op) |
---|
66 | $boucle->having[]= array("'".$op."'", "'compteur_".$type."'",$op_val); |
---|
67 | } |
---|
68 | |
---|
69 | // On préfixe avec AVELINE pour éviter conflit avec d'autres plugins |
---|
70 | // comme afficher_objet qui définit sont propre #COMPTEUR_ARTICLES |
---|
71 | |
---|
72 | function balise_AVELINE_COMPTEUR_FORUM_dist($p) { |
---|
73 | $p->code = '$Pile[$SP][\'compteur_forum\']'; |
---|
74 | $p->interdire_scripts = false; |
---|
75 | return $p; |
---|
76 | } |
---|
77 | |
---|
78 | function balise_AVELINE_COMPTEUR_ARTICLES_dist($p) { |
---|
79 | $p->code = '$Pile[$SP][\'compteur_articles\']'; |
---|
80 | $p->interdire_scripts = false; |
---|
81 | return $p; |
---|
82 | } |
---|
83 | |
---|
84 | // Critère archives pour afficher uniquement les objets d'une date donnée, par exemple en passant à l'URL ?archives=2010-02 |
---|
85 | // Repris du plugin minical |
---|
86 | // Adapté pour gérer les évènements en cours |
---|
87 | function critere_archives($idb, &$boucles, $crit, $var_date = 'archives') { |
---|
88 | $boucle = &$boucles[$idb]; |
---|
89 | if ($boucle->id_table == 'evenements') { |
---|
90 | $boucle->where[] = |
---|
91 | array("'AND'", |
---|
92 | array("'<='", "'date_debut'", "sql_quote(archives_debut(\$Pile[0]['".$var_date."']))"), |
---|
93 | array("'>='", "'date_fin'", "sql_quote(archives_fin(\$Pile[0]['".$var_date."']))"), |
---|
94 | ); |
---|
95 | } else { |
---|
96 | $champ_date = "'" . $boucle->id_table ."." .$GLOBALS['table_date'][$boucle->type_requete] . "'"; |
---|
97 | $boucle->where[] = array( |
---|
98 | 'REGEXP', |
---|
99 | $champ_date, |
---|
100 | "sql_quote(('^' . interdire_scripts(entites_html(\$Pile[0]['".$var_date."']))))" |
---|
101 | ); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | // Tester si le critère archives est de la forme AAAA, AAAA-MM ou AAAA-MM-JJ |
---|
106 | function archives_debut($date) { |
---|
107 | if (!$date or $date=='tout') |
---|
108 | return '2038-01-19 23:59:59'; |
---|
109 | switch (count(explode('-',$date))) { |
---|
110 | case 1: |
---|
111 | return date('Y-12-31 23:59:59', strtotime($date)); |
---|
112 | break; |
---|
113 | case 2: |
---|
114 | return date('Y-m-31 23:59:59', strtotime($date)); |
---|
115 | break; |
---|
116 | case 3: |
---|
117 | return date('Y-m-d 23:59:59', strtotime($date)); |
---|
118 | break; |
---|
119 | } |
---|
120 | } |
---|
121 | function archives_fin($date) { |
---|
122 | if (!$date or $date=='tout') |
---|
123 | return '1970-01-01 00:00:00'; |
---|
124 | switch (count(explode('-',$date))) { |
---|
125 | case 1: |
---|
126 | return date('Y-01-01 00:00:00', strtotime($date)); |
---|
127 | break; |
---|
128 | case 2: |
---|
129 | return date('Y-m-01 00:00:00', strtotime($date)); |
---|
130 | break; |
---|
131 | case 3: |
---|
132 | return date('Y-m-d 00:00:00', strtotime($date)); |
---|
133 | break; |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | // Balise #ME |
---|
138 | // Source : http://www.spip-contrib.net/me-Moi-and-myself |
---|
139 | |
---|
140 | /*** |
---|
141 | * (c)James 2006, Licence GNU/GPL |
---|
142 | * |me compare un id_auteur, par exemple, |
---|
143 | * d'une boucle FORUMS avec les auteurs d'un article |
---|
144 | * et renvoie la valeur booleenne true (vrai) si on trouve |
---|
145 | * une correspondance |
---|
146 | * utilisation: |
---|
147 | * <div id="forum#ID_FORUM"[(#ID_ARTICLE|me{#ID_AUTEUR}|?{' ', ''})class="me"]> |
---|
148 | ***/ |
---|
149 | function me($id_article, $id_auteur, $sioui = true, $sinon = false) { |
---|
150 | static $deja = false; |
---|
151 | static $auteurs = array(); |
---|
152 | if(!$deja) { |
---|
153 | $r = spip_query("SELECT id_auteur |
---|
154 | FROM spip_auteurs_articles |
---|
155 | WHERE id_article=$id_article"); |
---|
156 | while($row = spip_fetch_array($r)) |
---|
157 | $auteurs[] = intval($row['id_auteur']); |
---|
158 | $deja = true; |
---|
159 | } |
---|
160 | return in_array($id_auteur, $auteurs)?$sioui:$sinon; |
---|
161 | } |
---|
162 | |
---|
163 | function balise_ME($p){ |
---|
164 | $p->code = "me(". |
---|
165 | champ_sql('id_article', $p).', '. |
---|
166 | champ_sql('id_auteur', $p).', '. |
---|
167 | "'me', '')"; |
---|
168 | return $p; |
---|
169 | } |
---|
170 | |
---|
171 | // #AVELINE_PAGINATION |
---|
172 | // S'appelle dans une noisette ainsi [<p class="pagination">(#AVELINE_PAGINATION{'debut'})</p>] ou [<p class="pagination">(#AVELINE_PAGINATION{'fin'})</p>] |
---|
173 | // Le YAML de la noisette doit contenir - 'inclure:inc-yaml/pagination.yaml' |
---|
174 | |
---|
175 | function balise_AVELINE_PAGINATION_dist($p) { |
---|
176 | $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
---|
177 | |
---|
178 | $pos = interprete_argument_balise(1,$p); |
---|
179 | |
---|
180 | $connect = $p->boucles[$b]->sql_serveur; |
---|
181 | $pas = $p->boucles[$b]->total_parties; |
---|
182 | $f_pagination = chercher_filtre('pagination'); |
---|
183 | $type = $p->boucles[$b]->modificateur['debut_nom']; |
---|
184 | $modif = ($type[0]!=="'") ? "'debut'.$type" |
---|
185 | : ("'debut" .substr($type,1)); |
---|
186 | |
---|
187 | if ($pos=="'debut'") |
---|
188 | $p->code = "(\$Pile[0]['selection']=='pagination' && (\$Pile[0]['position_pagination']=='debut' || \$Pile[0]['position_pagination']=='deux')) ? ".sprintf(CODE_PAGINATION, $f_pagination,$b, $type, $modif, $pas, true, "\$Pile[0]['style_pagination']", _q($connect), '')." : ''"; |
---|
189 | else |
---|
190 | $p->code = "(\$Pile[0]['selection']=='pagination' && (\$Pile[0]['position_pagination']=='fin' || \$Pile[0]['position_pagination']=='deux')) ? ".sprintf(CODE_PAGINATION, $f_pagination,$b, $type, $modif, $pas, true, "\$Pile[0]['style_pagination']", _q($connect), '')." : ''"; |
---|
191 | return $p; |
---|
192 | } |
---|
193 | |
---|
194 | // Critère aveline_pagination |
---|
195 | // Le YAML de la noisette doit contenir - 'inclure:inc-yaml/pagination.yaml' |
---|
196 | // Ajouter {aveline_pagination} à la boucle |
---|
197 | |
---|
198 | function critere_aveline_pagination_dist($idb, &$boucles, $crit) { |
---|
199 | $boucle = &$boucles[$idb]; |
---|
200 | // definition de la taille de la page |
---|
201 | $pas = "((\$Pile[0]['selection']=='pagination') ? \$Pile[0]['pas_pagination'] : ((\$Pile[0]['selection']=='limite') ? \$Pile[0]['limite'] : 1000000))"; |
---|
202 | // On ajoute id_noisette à la variable de pagination |
---|
203 | $type = !isset($crit->param[0][1]) ? "'$idb'.'_'.\$Pile[0]['id_noisette']" : calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
---|
204 | $debut = ($type[0]!=="'") ? "'debut'.$type" |
---|
205 | : ("'debut" .substr($type,1)); |
---|
206 | |
---|
207 | $boucle->modificateur['debut_nom'] = $type; |
---|
208 | $partie = |
---|
209 | // tester si le numero de page demande est de la forme '@yyy' |
---|
210 | 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
---|
211 | ."\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
---|
212 | ."\t\t".'$debut_boucle = $Pile[0]['. $debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$result,'._q($boucle->sql_serveur).');'."\n" |
---|
213 | ."\t\t".'if (!sql_seek($result,0,'._q($boucle->sql_serveur).")){\n" |
---|
214 | ."\t\t\t".'@sql_free($result,'._q($boucle->sql_serveur).");\n" |
---|
215 | ."\t\t\t".'$result = calculer_select($select, $from, $type, $where, $join, $groupby, $orderby, $limit, $having, $table, $id, $connect);'."\n" |
---|
216 | ."\t\t}\n" |
---|
217 | ."\t}\n" |
---|
218 | ."\t".'$debut_boucle = intval($debut_boucle)'; |
---|
219 | |
---|
220 | |
---|
221 | $boucle->total_parties = $pas; |
---|
222 | calculer_parties($boucles, $idb, $partie, 'p+'); |
---|
223 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
---|
224 | // sauf si pas de primaire, ou si primaire composee |
---|
225 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
---|
226 | $t = $boucle->id_table . '.' . $boucle->primary; |
---|
227 | if ($boucle->primary |
---|
228 | AND !preg_match('/[,\s]/',$boucle->primary) |
---|
229 | AND !in_array($t, $boucle->select)) |
---|
230 | $boucle->select[]= $t; |
---|
231 | } |
---|
232 | |
---|
233 | // Si le plugin notation n'est pas actif, on définit un critère {notation} ne faisant rien |
---|
234 | // pour ne pas avoir d'erreur avec les boucles appelant ce critère |
---|
235 | // on définit également moyenne (égal alors à id) |
---|
236 | if (!defined('_DIR_PLUGIN_NOTATION')) { |
---|
237 | function critere_notation_dist($idb, &$boucles, $crit){ |
---|
238 | $boucle = &$boucles[$idb]; |
---|
239 | $table = $boucle->id_table; |
---|
240 | $id = $boucle->primary; |
---|
241 | $boucle->select[]= "$table.$id AS moyenne"; |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | // #AVELINE_CHOIX_TRI |
---|
247 | // Le YAML de la noisette doit contenir - 'inclure:inc-yaml/choix_tri-objet.yaml' |
---|
248 | // Appel : #AVELINE_CHOIX_TRI{'objet','debut_ou_fin'} |
---|
249 | // S'utilise en conjonction avec le critère tri de Bonux |
---|
250 | // Les possibilités de tri pour chaque objet sont définis directement dans le code de la balise |
---|
251 | // pour récupérer les variables d'environnement adéquates. |
---|
252 | |
---|
253 | function balise_AVELINE_CHOIX_TRI_dist($p) { |
---|
254 | $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; |
---|
255 | |
---|
256 | // s'il n'y a pas de nom de boucle, on ne peut pas trier |
---|
257 | if ($b === '') { |
---|
258 | erreur_squelette( |
---|
259 | _T('zbug_champ_hors_boucle', |
---|
260 | array('champ' => '#TRI') |
---|
261 | ), $p->id_boucle); |
---|
262 | $p->code = "''"; |
---|
263 | return $p; |
---|
264 | } |
---|
265 | $boucle = $p->boucles[$b]; |
---|
266 | |
---|
267 | // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
---|
268 | // dans un boucle recursive ou qu'on a oublie le critere {tri} |
---|
269 | if (!isset($boucle->modificateur['tri_champ'])) { |
---|
270 | erreur_squelette( |
---|
271 | _T('zbug_tri_sans_critere', |
---|
272 | array('champ' => '#TRI') |
---|
273 | ), $p->id_boucle); |
---|
274 | $p->code = "''"; |
---|
275 | return $p; |
---|
276 | } |
---|
277 | |
---|
278 | $suffixe = $boucle->modificateur['tri_nom']; |
---|
279 | $objet = interprete_argument_balise(1,$p); |
---|
280 | $pos = interprete_argument_balise(2,$p); |
---|
281 | $tri_actuel = $boucle->modificateur['tri_champ']; |
---|
282 | $sens_actuel = $boucle->modificateur['tri_sens']; |
---|
283 | |
---|
284 | // Définir les choix possibles |
---|
285 | $choix = "array()"; |
---|
286 | if ($objet == "'article'") |
---|
287 | $choix = "array( |
---|
288 | array('affiche' => \$Pile['0']['choix_tri_titre'], 'tri' => 'titre', 'sens' => 1, 'libelle' => _T('avelinepublic:par_titre')), |
---|
289 | array('affiche' => \$Pile['0']['choix_tri_rang'], 'tri' => 'num titre', 'sens' => 1, 'libelle' => _T('avelinepublic:par_rang')), |
---|
290 | array('affiche' => \$Pile['0']['choix_tri_popularite'], 'tri' => 'popularite', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_populaires')), |
---|
291 | array('affiche' => \$Pile['0']['choix_tri_date'], 'tri' => 'date', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_recents')), |
---|
292 | array('affiche' => \$Pile['0']['choix_tri_anciens'], 'tri' => 'date', 'sens' => 1, 'libelle' => _T('avelinepublic:les_plus_anciens')), |
---|
293 | array('affiche' => \$Pile['0']['choix_tri_date_modif'], 'tri' => 'date_modif', 'sens' => -1, 'libelle' => _T('avelinepublic:modifies_recemment')), |
---|
294 | array('affiche' => \$Pile['0']['choix_tri_commentes'], 'tri' => 'compteur_forum', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_commentes')), |
---|
295 | array('affiche' => \$Pile['0']['choix_tri_visistes'], 'tri' => 'visites', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_visites')), |
---|
296 | array('affiche' => \$Pile['0']['choix_tri_note'], 'tri' => 'moyenne', 'sens' => -1, 'libelle' => _T('avelinepublic:les_mieux_notes')), |
---|
297 | array('affiche' => \$Pile['0']['recherche'], 'tri' => 'points', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_pertinents')) |
---|
298 | )"; |
---|
299 | if ($objet == "'breve'") |
---|
300 | $choix = "array( |
---|
301 | array('affiche' => \$Pile['0']['choix_tri_titre'], 'tri' => 'titre', 'sens' => 1, 'libelle' => _T('avelinepublic:par_titre')), |
---|
302 | array('affiche' => \$Pile['0']['choix_tri_rang'], 'tri' => 'num titre', 'sens' => 1, 'libelle' => _T('avelinepublic:par_rang')), |
---|
303 | array('affiche' => \$Pile['0']['choix_tri_date'], 'tri' => 'date_heure', 'sens' => -1, 'libelle' => _T('avelinepublic:b_les_plus_recentes')), |
---|
304 | array('affiche' => \$Pile['0']['choix_tri_anciens'], 'tri' => 'date_heure', 'sens' => 1, 'libelle' => _T('avelinepublic:b_les_plus_anciennes')), |
---|
305 | array('affiche' => \$Pile['0']['choix_tri_commentes'], 'tri' => 'compteur_forum', 'sens' => -1, 'libelle' => _T('avelinepublic:b_les_plus_commentees')), |
---|
306 | array('affiche' => \$Pile['0']['recherche'], 'tri' => 'points', 'sens' => -1, 'libelle' => _T('avelinepublic:b_les_plus_pertinents')) |
---|
307 | )"; |
---|
308 | if ($objet == "'auteur'") |
---|
309 | $choix = "array( |
---|
310 | array('affiche' => \$Pile['0']['choix_tri_nom'], 'tri' => 'nom', 'sens' => 1, 'libelle' => _T('avelinepublic:par_nom')), |
---|
311 | array('affiche' => \$Pile['0']['choix_tri_nb_articles'], 'tri' => 'compteur_articles', 'sens' => -1, 'libelle' => _T('avelinepublic:par_nb_articles')), |
---|
312 | array('affiche' => \$Pile['0']['recherche'], 'tri' => 'points', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_pertinentes')) |
---|
313 | )"; |
---|
314 | if ($objet == "'rubrique'") |
---|
315 | $choix = "array( |
---|
316 | array('affiche' => \$Pile['0']['choix_tri_titre'], 'tri' => 'titre', 'sens' => 1, 'libelle' => _T('avelinepublic:par_titre')), |
---|
317 | array('affiche' => \$Pile['0']['choix_tri_commentes'], 'tri' => 'compteur_forum', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_commentes')), |
---|
318 | array('affiche' => \$Pile['0']['choix_tri_date_heure'], 'tri' => 'date_heure', 'sens' => -1, 'libelle' => _T('avelinepublic:modifiees_recemment')), |
---|
319 | array('affiche' => \$Pile['0']['choix_tri_note'], 'tri' => 'moyenne', 'sens' => -1, 'libelle' => _T('avelinepublic:les_mieux_notes')), |
---|
320 | array('affiche' => \$Pile['0']['recherche'], 'tri' => 'points', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_pertinents')) |
---|
321 | )"; |
---|
322 | if ($objet == "'evenement'") |
---|
323 | $choix = "array( |
---|
324 | array('affiche' => \$Pile['0']['choix_tri_date'], 'tri' => 'date_debut', 'sens' => -1, 'libelle' => _T('avelinepublic:par_date_decroissante')), |
---|
325 | array('affiche' => \$Pile['0']['choix_tri_anciens'], 'tri' => 'date_debut', 'sens' => 1, 'libelle' => _T('avelinepublic:par_date_croissante')), |
---|
326 | array('affiche' => \$Pile['0']['choix_tri_titre'], 'tri' => 'titre', 'sens' => 1, 'libelle' => _T('avelinepublic:par_titre')), |
---|
327 | array('affiche' => \$Pile['0']['recherche'], 'tri' => 'points', 'sens' => -1, 'libelle' => _T('avelinepublic:les_plus_pertinents')) |
---|
328 | )"; |
---|
329 | |
---|
330 | $p->code = "calculer_balise_AVELINE_CHOIX_TRI($suffixe,$choix,$pos,$tri_actuel,$sens_actuel,\$Pile[0]['choix_tri'],\$Pile[0]['position_choix_tri'])"; |
---|
331 | return $p; |
---|
332 | } |
---|
333 | |
---|
334 | function calculer_balise_AVELINE_CHOIX_TRI($suffixe,$choix,$pos,$tri_actuel,$sens_actuel,$choix_tri,$position_choix_tri) { |
---|
335 | // Doit-on afficher les tri perso ? |
---|
336 | if (!$choix_tri || ($pos == 'debut' && $position_choix_tri == 'fin') || ($pos == 'fin' && $position_choix_tri == 'debut')) |
---|
337 | return ''; |
---|
338 | |
---|
339 | $retour = array(); |
---|
340 | foreach($choix as $c) { |
---|
341 | // Cas où on demande la note moyenne et que notation n'est pas activé |
---|
342 | if ($c['tri'] == 'moyenne' && !defined('_DIR_PLUGIN_NOTATION')) |
---|
343 | $c['affiche'] = ''; |
---|
344 | if ($c['affiche']) { |
---|
345 | $lien = parametre_url(self(),'tri'.$suffixe,$c['tri']); |
---|
346 | $lien = parametre_url($lien,'sens'.$suffixe,$c['sens']); |
---|
347 | $retour[] = lien_ou_expose($lien,$c['libelle'],$c['tri']==$tri_actuel && $c['sens']==$sens_actuel); |
---|
348 | } |
---|
349 | } |
---|
350 | return implode(' <span class="sep separateur">|</span> ',$retour); |
---|
351 | } |
---|
352 | |
---|
353 | // Surcharge du critère tri pour ajouter id_noisette aux variables de personnalisation du tri |
---|
354 | /** |
---|
355 | * {tri [champ_par_defaut][,sens_par_defaut][,nom_variable]} |
---|
356 | * champ_par_defaut : un champ de la table sql |
---|
357 | * sens_par_defaut : -1 ou inverse pour decroissant, 1 ou direct pour croissant |
---|
358 | * nom_variable : nom de la variable utilisee (par defaut tri_nomboucle) |
---|
359 | * |
---|
360 | * {tri titre} |
---|
361 | * {tri titre,inverse} |
---|
362 | * {tri titre,-1} |
---|
363 | * {tri titre,-1,truc} |
---|
364 | * |
---|
365 | * @param unknown_type $idb |
---|
366 | * @param unknown_type $boucles |
---|
367 | * @param unknown_type $crit |
---|
368 | */ |
---|
369 | function critere_tri($idb, &$boucles, $crit) { |
---|
370 | $boucle = &$boucles[$idb]; |
---|
371 | $id_table = $boucle->id_table; |
---|
372 | |
---|
373 | // definition du champ par defaut |
---|
374 | $_champ_defaut = !isset($crit->param[0][0]) ? "''" : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
---|
375 | $_sens_defaut = !isset($crit->param[1][0]) ? "1" : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
---|
376 | // On ajoute _id_noisette à la variable de tri |
---|
377 | $_variable = !isset($crit->param[2][0]) ? "'$idb'.'_'.\$Pile[0]['id_noisette']" : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
---|
378 | |
---|
379 | $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:$_champ_defaut)?tri_protege_champ(\$t):'')"; |
---|
380 | |
---|
381 | $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
---|
382 | $_sens ="((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:$_sens_defaut)==-1 OR \$t=='inverse')?-1:1)"; |
---|
383 | |
---|
384 | $boucle->modificateur['tri_champ'] = $_tri; |
---|
385 | $boucle->modificateur['tri_sens'] = $_sens; |
---|
386 | $boucle->modificateur['tri_nom'] = $_variable; |
---|
387 | // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
---|
388 | // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
---|
389 | $boucle->hash .= " |
---|
390 | \$senstri = ''; |
---|
391 | \$tri = $_tri; |
---|
392 | if (\$tri){ |
---|
393 | \$senstri = $_sens; |
---|
394 | \$senstri = (\$senstri<0)?' DESC':''; |
---|
395 | }; |
---|
396 | "; |
---|
397 | $field = serialize(array_keys($boucle->show['field'])); |
---|
398 | $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
---|
399 | $boucle->order[] = "tri_champ_order(\$tri,'$id_table','$field').\$senstri"; |
---|
400 | } |
---|
401 | |
---|
402 | |
---|
403 | // Critère aveline_branche |
---|
404 | // Le YAML de la noisette doit contenir - 'inclure:inc-yaml/branche-objet.yaml' |
---|
405 | // Ajouter {aveline_branche} à la boucle |
---|
406 | function critere_aveline_branche_dist($idb, &$boucles, $crit) { |
---|
407 | $boucle = &$boucles[$idb]; |
---|
408 | |
---|
409 | $id_article = calculer_argument_precedent($idb, 'id_article', $boucles); |
---|
410 | $id_syndic = calculer_argument_precedent($idb, 'id_syndic', $boucles); |
---|
411 | $id_rubrique = calculer_argument_precedent($idb, 'id_rubrique', $boucles); |
---|
412 | $id_secteur = calculer_argument_precedent($idb, 'id_secteur', $boucles); |
---|
413 | |
---|
414 | //Trouver une jointure |
---|
415 | $desc = $boucle->show; |
---|
416 | //Seulement si necessaire |
---|
417 | if (!array_key_exists('id_rubrique', $desc['field'])) { |
---|
418 | $cle_rubrique = trouver_jointure_champ('id_rubrique', $boucle); |
---|
419 | } else $cle_rubrique = $boucle->id_table; |
---|
420 | |
---|
421 | $table = $boucle->id_table; |
---|
422 | |
---|
423 | $boucle->where[] = "aveline_calcul_branche($id_article,$id_syndic,$id_rubrique, $id_secteur, $cle_rubrique, $table, \$Pile[0]['branche'], \$Pile[0]['rubrique_specifique'], \$Pile[0]['branche_specifique'], \$Pile[0]['secteur_specifique'], \$Pile[0]['article_specifique'], \$Pile[0]['site_specifique'], \$Pile[0]['filtre_rub'], \$Pile[0]['filtre_art'])"; |
---|
424 | |
---|
425 | } |
---|
426 | |
---|
427 | function aveline_calcul_branche($id_article,$id_syndic,$id_rubrique,$id_secteur,$cle_rubrique,$table, $branche,$rubrique_specifique,$branche_specifique,$secteur_specifique, $article_specifique, $site_specifique, $filtre_rub, $filtre_art) { |
---|
428 | if ($filtre_rub) { |
---|
429 | $branche = 'branche_specifique'; |
---|
430 | $branche_specifique = 'rubrique|'.$filtre_rub; |
---|
431 | } |
---|
432 | if ($filtre_art) { |
---|
433 | $branche = 'article_specifique'; |
---|
434 | $article_specifique = 'article|'.$filtre_art; |
---|
435 | } |
---|
436 | switch ($table) { |
---|
437 | case 'articles': |
---|
438 | $cle_secteur = $table; |
---|
439 | $champ_secteur = 'id_secteur'; |
---|
440 | break; |
---|
441 | case 'breves': |
---|
442 | $cle_secteur = $table; |
---|
443 | $champ_secteur = 'id_rubrique'; |
---|
444 | } |
---|
445 | switch ($branche) { |
---|
446 | case 'meme_article': |
---|
447 | return $id_article ? array('=',"$table.id_article",$id_article) : array (); |
---|
448 | break; |
---|
449 | case 'article_specifique': |
---|
450 | return $article_specifique ? sql_in("$table.id_article",picker_selected($article_specifique,'article')) : array(); |
---|
451 | break; |
---|
452 | case 'meme_site': |
---|
453 | return $id_syndic ? array('=',"$table.id_syndic",$id_syndic) : array (); |
---|
454 | break; |
---|
455 | case 'site_specifique': |
---|
456 | return $site_specifique ? sql_in("$table.id_syndic",$site_specifique) : array(); |
---|
457 | break; |
---|
458 | case 'meme_rubrique': |
---|
459 | return $id_rubrique ? array('=',"$cle_rubrique.id_rubrique",$id_rubrique) : array (); |
---|
460 | break; |
---|
461 | case 'rubrique_specifique': |
---|
462 | return $rubrique_specifique ? sql_in("$cle_rubrique.id_rubrique",picker_selected($rubrique_specifique,'rubrique')) : array(); |
---|
463 | break; |
---|
464 | case 'branche_actuelle': |
---|
465 | return $id_rubrique ? sql_in("$cle_rubrique.id_rubrique",calcul_branche_in($id_rubrique)) : array(); |
---|
466 | break; |
---|
467 | case 'branche_specifique': |
---|
468 | return $branche_specifique ? sql_in("$cle_rubrique.id_rubrique",calcul_branche_in(picker_selected($branche_specifique,'rubrique'))) : array(); |
---|
469 | break; |
---|
470 | case 'meme_secteur': |
---|
471 | return $id_secteur ? array('=',"$cle_secteur.$champ_secteur",$id_secteur) : array(); |
---|
472 | break; |
---|
473 | case 'secteur_specifique': |
---|
474 | return $secteur_specifique ? sql_in("$cle_secteur.$champ_secteur",$secteur_specifique) : array(); |
---|
475 | break; |
---|
476 | default: |
---|
477 | return array(); |
---|
478 | } |
---|
479 | } |
---|
480 | |
---|
481 | // Critère aveline_lang |
---|
482 | // Le YAML de la noisette doit contenir - 'inclure:inc-yaml/restreindre_langue.yaml'' |
---|
483 | // Ajouter {aveline_lang} à la boucle |
---|
484 | // N'appliquer qu'à des tables ayant un champ 'lang' |
---|
485 | function critere_aveline_lang_dist($idb, &$boucles, $crit) { |
---|
486 | $boucle = &$boucles[$idb]; |
---|
487 | |
---|
488 | //Trouver une jointure (pour les évènements par exemple) |
---|
489 | $desc = $boucle->show; |
---|
490 | //Seulement si necessaire |
---|
491 | if (!array_key_exists('lang', $desc['field'])) { |
---|
492 | $id_table = trouver_jointure_champ('lang', $boucle); |
---|
493 | } else $id_table = $boucle->id_table; |
---|
494 | |
---|
495 | $boucle->where[] = "aveline_calcul_lang($id_table,\$Pile[0]['restreindre_langue'],\$Pile[0]['lang'])"; |
---|
496 | } |
---|
497 | |
---|
498 | function aveline_calcul_lang($id_table,$restreindre_langue,$lang) { |
---|
499 | if ($restreindre_langue) |
---|
500 | return array('=',"$id_table.lang",sql_quote($lang)); |
---|
501 | else |
---|
502 | return array(); |
---|
503 | } |
---|
504 | |
---|
505 | |
---|
506 | // Critère aveline_exclure_objet_encours |
---|
507 | // Le YAML de la noisette doit contenir - 'inclure:inc-yaml/exclure_objet_en_cours-objet.yaml'' |
---|
508 | // Ajouter {aveline_exclure_objet_encours} à la boucle |
---|
509 | function critere_aveline_exclure_objet_encours_dist($idb, &$boucles, $crit) { |
---|
510 | $boucle = &$boucles[$idb]; |
---|
511 | $id_table = $boucle->id_table; |
---|
512 | $id_objet = $boucle->primary; |
---|
513 | |
---|
514 | $boucle->where[] = "aveline_calcul_exclure_objet($id_table,$id_objet,\$Pile[0][$id_objet],\$Pile[0]['exclure_objet_en_cours'])"; |
---|
515 | } |
---|
516 | |
---|
517 | function aveline_calcul_exclure_objet($id_table,$id_objet,$id_en_cours,$exclure_objet_en_cours) { |
---|
518 | if ($exclure_objet_en_cours) |
---|
519 | return array('!=',"$id_table.$id_objet",intval($id_en_cours)); |
---|
520 | else |
---|
521 | return array(); |
---|
522 | } |
---|
523 | |
---|
524 | // Critère aveline_selecteurs_archives_mois et aveline_selecteurs_archives_annees |
---|
525 | // Utilisée pour les sélecteurs d'archives |
---|
526 | // Balise disponible #NB_ARCHIVES |
---|
527 | function critere_aveline_selecteur_archives_mois_dist($idb, &$boucles, $crit) { |
---|
528 | $boucle = &$boucles[$idb]; |
---|
529 | $champ_date = $boucle->id_table ."." . $GLOBALS['table_date'][$boucle->type_requete]; |
---|
530 | $id_objet = $boucle->id_table ."." . $boucle->primary; |
---|
531 | $boucle->select[] = "COUNT($id_objet) AS nb_archives"; |
---|
532 | $boucle->group[] = "YEAR($champ_date)"; |
---|
533 | $boucle->group[] = "MONTH($champ_date)"; |
---|
534 | } |
---|
535 | |
---|
536 | function critere_aveline_selecteur_archives_annee_dist($idb, &$boucles, $crit) { |
---|
537 | $boucle = &$boucles[$idb]; |
---|
538 | $champ_date = $boucle->id_table ."." . $GLOBALS['table_date'][$boucle->type_requete]; |
---|
539 | $id_objet = $boucle->id_table ."." . $boucle->primary; |
---|
540 | $boucle->select[] = "COUNT($id_objet) AS nb_archives"; |
---|
541 | $boucle->group[] = "YEAR($champ_date)"; |
---|
542 | } |
---|
543 | |
---|
544 | /** Balise #NB_ARCHIVES associee aux criteres aveline_selecteur_archives_mois et aveline_selecteur_archives_annees */ |
---|
545 | function balise_NB_ARCHIVES_dist($p) { |
---|
546 | $p->code = '$Pile[$SP][\'nb_archives\']'; |
---|
547 | $p->interdire_scripts = false; |
---|
548 | return $p; |
---|
549 | } |
---|
550 | |
---|
551 | /** |
---|
552 | * Calculer l'initiale d'un nom ou d'un titre |
---|
553 | * |
---|
554 | * @param <type> $nom |
---|
555 | * @return <type> |
---|
556 | */ |
---|
557 | function aveline_initiale($nom){ |
---|
558 | return spip_substr(trim(strtoupper($nom)),0,1); |
---|
559 | } |
---|
560 | |
---|
561 | |
---|
562 | /** |
---|
563 | * Afficher l'initiale pour la navigation par lettres |
---|
564 | * adptée du plugin afficher_objets |
---|
565 | * |
---|
566 | * @staticvar string $memo |
---|
567 | * @param <type> $url |
---|
568 | * @param <type> $initiale |
---|
569 | * @param <type> $compteur |
---|
570 | * @param <type> $debut |
---|
571 | * @param <type> $pas |
---|
572 | * @return <type> |
---|
573 | */ |
---|
574 | function aveline_afficher_initiale($url,$initiale,$compteur,$debut,$pas){ |
---|
575 | static $memo = null; |
---|
576 | $res = ''; |
---|
577 | if (!$memo |
---|
578 | OR (!$initiale AND !$url) |
---|
579 | OR ($initiale!==$memo['initiale']) |
---|
580 | ){ |
---|
581 | $newcompt = intval(floor(($compteur-1)/$pas)*$pas); |
---|
582 | if ($memo){ |
---|
583 | $on = (($memo['compteur']<=$debut) |
---|
584 | AND ( |
---|
585 | $newcompt>$debut OR ($newcompt==$debut AND $newcompt==$memo['compteur']) |
---|
586 | )); |
---|
587 | $res = lien_ou_expose($memo['url'],$memo['initiale'],$on,'lien_pagination'); |
---|
588 | } |
---|
589 | if ($initiale) |
---|
590 | $memo = array('initiale'=>$initiale,'url'=>$url,'compteur'=>$newcompt); |
---|
591 | } |
---|
592 | return $res; |
---|
593 | } |
---|
594 | |
---|
595 | // Personnalisation pour Aveline |
---|
596 | // pour diriger au choix vers le lien de l'évènement ou vers la page Agenda |
---|
597 | |
---|
598 | function aveline_agenda_mini($i) { |
---|
599 | $args = func_get_args(); |
---|
600 | $une_date = array_shift($args); // une date comme balise |
---|
601 | $sinon = array_shift($args); |
---|
602 | if (!$une_date) return $sinon; |
---|
603 | $type = 'mini'; |
---|
604 | $agenda = Agenda_memo_full(0); |
---|
605 | $evt = array(); |
---|
606 | foreach (($args ? $args : array_keys($agenda)) as $k) { |
---|
607 | if (is_array($agenda[$k])) |
---|
608 | foreach($agenda[$k] as $d => $v) { |
---|
609 | if (count($v)>1) |
---|
610 | foreach ($v as $cle => $ligne) |
---|
611 | $v[0]['URL'] = generer_url_public('agenda','archives='.substr($d,0,4).'-'.substr($d,4,2).'-'.substr($d,6,2)); |
---|
612 | $evt[$d] = $evt[$d] ? (array_merge($evt[$d], $v)) : $v; |
---|
613 | } |
---|
614 | } |
---|
615 | $la_date = mktime(0, 0, 0, mois($une_date), 1, annee($une_date)); |
---|
616 | include_spip('inc/agenda'); |
---|
617 | return http_calendrier_init($la_date, $type, '', '', '', array('', $evt)); |
---|
618 | } |
---|
619 | |
---|
620 | // Filtre d'affichage de date |
---|
621 | // http://www.spip-contrib.net/Utilisation-des-filtres-de-date |
---|
622 | function filtre_aveline_affdate_dist($date, $format='affdate') { |
---|
623 | if($format==NULL) { |
---|
624 | $f_affdate = chercher_filtre('affdate'); |
---|
625 | return $f_affdate($date); |
---|
626 | } |
---|
627 | switch ($format) { |
---|
628 | case "affdate": // affiche la date sous forme de texte (1er juillet 2012) |
---|
629 | case "affdate_jourcourt": // affiche le numéro du jour et le nom du mois, si la date est dans lannée en cours (1er juillet), |
---|
630 | // si la date nest pas dans lannée en cours, on rajoute lannée (1er juillet 2010) |
---|
631 | case "affdate_court": // affiche le numéro du jour et le nom du mois (si la date est dans lannée en cours) (1er juillet), |
---|
632 | // si la date nest pas dans lannée en cours, on affiche le nom du mois et lannée (juillet 2010) |
---|
633 | case "affdate_mois_annee": // affiche seulement le mois et lannée (juillet 2012) |
---|
634 | $f_affdate = chercher_filtre($format); |
---|
635 | return $f_affdate($date); |
---|
636 | break; |
---|
637 | case "annee": // affiche uniquement l'annee (2012) |
---|
638 | $f_annee = chercher_filtre('annee'); |
---|
639 | return $f_annee($date); |
---|
640 | break; |
---|
641 | case "nom_jour_affdate": // Idem affdate précédé du nom du jour (dimanche 1er juillet 2012) |
---|
642 | $f_affdate = chercher_filtre('affdate'); |
---|
643 | $f_nom_jour = chercher_filtre('nom_jour'); |
---|
644 | return $f_nom_jour($date).' '.$f_affdate($date); |
---|
645 | break; |
---|
646 | case "numerique_slash": // affiche la date sous forme numerique avec un slash séparateur (01/07/2012) |
---|
647 | $f_annee = chercher_filtre('affdate'); |
---|
648 | return $f_annee($date,'d/m/Y'); |
---|
649 | break; |
---|
650 | case "numerique_tiret": // affiche la date sous forme numerique avec un tiret séparateur (01-07-2012) |
---|
651 | $f_annee = chercher_filtre('affdate'); |
---|
652 | return $f_annee($date,'d-m-Y'); |
---|
653 | break; |
---|
654 | default: |
---|
655 | $f_affdate = chercher_filtre('affdate'); |
---|
656 | return f_affdate($date); |
---|
657 | break; |
---|
658 | } |
---|
659 | } |
---|
660 | ?> |
---|