1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2011 * |
---|
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
---|
8 | * * |
---|
9 | * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
---|
10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
---|
11 | \***************************************************************************/ |
---|
12 | |
---|
13 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
14 | |
---|
15 | include_spip('inc/presentation'); |
---|
16 | include_spip('inc/actions'); |
---|
17 | include_spip('base/abstract_sql'); |
---|
18 | |
---|
19 | function filtre_objets_associes_mot_dist($id_mot,$id_groupe) { |
---|
20 | static $occurences = array(); |
---|
21 | |
---|
22 | // calculer tous les liens du groupe d'un coup |
---|
23 | if (!isset ($occurences[$id_groupe])) |
---|
24 | $occurrences[$id_groupe] = calculer_utilisations_mots($id_groupe); |
---|
25 | |
---|
26 | $associes = array(); |
---|
27 | foreach (array('article','breve','site','rubrique') as $type) { |
---|
28 | $table = table_objet($type); |
---|
29 | $nb = (isset($occurrences[$id_groupe][$table][$id_mot]) ? $occurrences[$id_groupe][$table][$id_mot] : 0); |
---|
30 | if ($nb) |
---|
31 | $associes[] = objet_afficher_nb($nb,$type); |
---|
32 | } |
---|
33 | |
---|
34 | $associes = pipeline('afficher_nombre_objets_associes_a',array('args'=>array('objet'=>'mot','id_objet'=>$id_mot),'data'=>$associes)); |
---|
35 | return $associes; |
---|
36 | |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * Calculer les nombres d'elements (articles, etc.) lies a chaque mot |
---|
41 | * |
---|
42 | * @param int $id_groupe |
---|
43 | * @return array |
---|
44 | */ |
---|
45 | function calculer_utilisations_mots($id_groupe) |
---|
46 | { |
---|
47 | $statuts = sql_in('O.statut', ($GLOBALS['connect_statut'] =="0minirezo") ? array('prepa','prop','publie') : array('prop','publie')); |
---|
48 | $retour = array(); |
---|
49 | $objets = sql_allfetsel('DISTINCT objet', array('spip_mots_liens AS L', 'spip_mots AS M'), array('L.id_mot=M.id_mot', 'M.id_groupe='.$id_groupe)); |
---|
50 | |
---|
51 | foreach($objets as $o) { |
---|
52 | $objet=$o['objet']; |
---|
53 | $_id_objet = id_table_objet($objet); |
---|
54 | $table_objet = table_objet($objet); |
---|
55 | $table_objet_sql = table_objet_sql($objet); |
---|
56 | $res = sql_allfetsel( |
---|
57 | "COUNT(*) AS cnt, L.id_mot", |
---|
58 | "spip_mots_liens AS L |
---|
59 | LEFT JOIN spip_mots AS M ON L.id_mot=M.id_mot |
---|
60 | AND L.objet=" . sql_quote($objet) . " |
---|
61 | LEFT JOIN " . $table_objet_sql . " AS O ON L.id_objet=O.$_id_objet" , |
---|
62 | "M.id_groupe=$id_groupe AND $statuts", |
---|
63 | "L.id_mot"); |
---|
64 | |
---|
65 | foreach($res as $row) { |
---|
66 | $retour[$table_objet][$row['id_mot']] = $row['cnt']; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | return $retour; |
---|
71 | } |
---|
72 | ?> |
---|