1 | <?php |
---|
2 | |
---|
3 | include_spip('inc/texte'); |
---|
4 | include_spip('inc/layer'); |
---|
5 | include_spip("inc/presentation"); |
---|
6 | // A�do JSJ |
---|
7 | // V0.03 |
---|
8 | // |
---|
9 | define ("MODO_AUTOCLAVE","auto"); // on /off Modo prefijado para el plugin palabra clave: Automático, Manual= s�bot�utoclave |
---|
10 | define ("ESTADO_NUEVAS","on"); // on /off Define el estado para nuevas palabra clave encontradas |
---|
11 | define ("PARCIAL_NUEVAS","on"); // on /off Define el estado para nuevas palabra clave encontradas solo parcialmente |
---|
12 | define ("HEREDADAS","heredada"); // Define la clase para las palabras heredadas de las secciones padre del art�lo |
---|
13 | define ("ESTADO_HEREDADAS","on"); // on /off Define el estado para las palabra clave marcadas en secciones padre del art�lo |
---|
14 | define ("EDITAR_HEREDADAS","on"); // on /off Define el si el estado para las palabra clave heredadas (procedenes de ls secciones ascendentes) son editables o mantiene el estado prefijado con ESTADO_HEREDADAS. Ajuste del adminitsrador |
---|
15 | |
---|
16 | |
---|
17 | $p=explode(basename(_DIR_PLUGINS)."/",str_replace('\\','/',realpath(dirname(__FILE__)))); |
---|
18 | define('_DIR_PLUGIN_AUTO_CLAVE',(_DIR_PLUGINS.end($p))); |
---|
19 | |
---|
20 | function build_checkbox($name, $editable, $value='') |
---|
21 | { |
---|
22 | $checkbox_string="<input type='checkbox' "; |
---|
23 | if($editable=="off") { |
---|
24 | $checkbox_string.=" name='off-".$name."' onclick='return false' "; // checkbox no editable y off |
---|
25 | } |
---|
26 | else { |
---|
27 | $checkbox_string.=" name='".$name."' checked='checked' "; // checkbox editable y marcada on |
---|
28 | } |
---|
29 | |
---|
30 | $checkbox_string.= "value='".$value."' /> "; |
---|
31 | return $checkbox_string; |
---|
32 | } |
---|
33 | |
---|
34 | function autoclaves_cabecera_grupo($grupo, $numerogrupo) { |
---|
35 | $grupo = "<b>$grupo-$numerogrupo</b><input type='radio' name='todas$numerogrupo' value='$numerogrupo-on' checked='checked' '-' id='todas$numerogrupo'>" ._T('autoclaves:todas') ."<input type='radio' name='todas$numerogrupo' value='$numerogrupo-off' id='ninguna$numerogrupo'>" ._T('autoclaves:ninguna') .'<br />'; |
---|
36 | return $grupo; |
---|
37 | } |
---|
38 | |
---|
39 | function autoclaves_palabras($palabra, $numerogrupo, $numeropalabra, $tipo) { |
---|
40 | $editable = ($tipo == "previa") ? "off" : "on" ; // no editable si es una palabra ya existente en el art�lo |
---|
41 | $palabra = '<div class=' .$tipo .'>' .build_checkbox('palabras[]', $editable, $numeropalabra) .$palabra .'</div>'; |
---|
42 | return $palabra; |
---|
43 | } |
---|
44 | |
---|
45 | function autoclaves_heredadas($palabra, $numerogrupo, $numeropalabra) { |
---|
46 | $activo = "off" ; |
---|
47 | $palabra = '<div class=' .HEREDADAS .'>' .build_checkbox($palabra, $activo) .$palabra .'</div>'; |
---|
48 | return $palabra; |
---|
49 | } |
---|
50 | |
---|
51 | // http://leadnetwork.nordpasdecalais.fr/squelette/fonctionadm.html |
---|
52 | // http://osdir.com/ml/web.spip.zone.cvs/2006-12/msg00467.html |
---|
53 | // http://osdir.com/ml/web.spip.zone.cvs/2006-12/msg00467.html |
---|
54 | // |
---|
55 | |
---|
56 | function autoclaves_leer_palabras($ret) |
---|
57 | { |
---|
58 | // Lee todas las palabras, clasificadas por el (n�) grupo |
---|
59 | // Recoge el n� y t�lo del grupo, id_groupe y type, as�omo n� y texto de cada palabra clave |
---|
60 | $ret .= " --- leer palabras <br />"; |
---|
61 | $r = spip_query("SELECT id_mot, titre, id_groupe, type FROM spip_mots ORDER BY id_groupe"); |
---|
62 | while($o = spip_fetch_array($r)) |
---|
63 | { |
---|
64 | $ret .= $o[id_groupe] .'-'.$o[type] .'=' .$o[id_mot] .'-'.$o[titre].'<br />'; |
---|
65 | $palabras[]=$row['titre']; |
---|
66 | $palabras[]=$row['id_mot']; |
---|
67 | $palabras[]=$row['id_groupe']; |
---|
68 | $palabras[]=$row['type']; |
---|
69 | $palabras[]=$row['id_groupe']; |
---|
70 | } |
---|
71 | return $ret; |
---|
72 | } |
---|
73 | |
---|
74 | function autoclaves_definirspan($letexte) { |
---|
75 | $letexte = preg_replace('`<ac_(.*)>(.*)</ac_\1>`iU', '<span class="ac_$1">$2</span>', $letexte); |
---|
76 | return $letexte; |
---|
77 | } |
---|
78 | |
---|
79 | function autoclaves_inclurecss($flux) { |
---|
80 | $flux .= '<!-- plugin auto_claves v1 -->'."\n"; |
---|
81 | $flux .= '<link href="'. _DIR_PLUGIN_AUTO_CLAVE .'/auto_claves.css" rel="stylesheet" type="text/css" />'."\n"; |
---|
82 | $flux .= '<script src="'. _DIR_PLUGIN_AUTO_CLAVE .'/check.js" type="text/javascript"></script>'."\n"; |
---|
83 | // plugins/auto_claves/ s�en parte p�a |
---|
84 | // ../plugins/auto_claves/ mal en p�a |
---|
85 | // /spip/plugins/auto_claves/ OK en parte privada y privada |
---|
86 | // $flux .= '<link href="'.'/spip/plugins/auto_claves/'.'auto_claves.css" rel="stylesheet" type="text/css" />'."\n"; |
---|
87 | $flux .= '<!-- /plugin auto_claves -->'."\n"; |
---|
88 | return $flux; |
---|
89 | } |
---|
90 | |
---|
91 | function autoclaves_affiche_droite($arguments) { |
---|
92 | // global $connect_statut, $connect_toutes_rubriques, $connect_id_rubrique; |
---|
93 | global $connect_statut, $connect_toutes_rubriques; |
---|
94 | if(_request('exec') == 'articles') { |
---|
95 | |
---|
96 | //busco las palabras claves encontradas |
---|
97 | $id_art = intval($arguments['args']['id_article']); |
---|
98 | $palabras = autoclaves_buscar_mots($id_art); |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | $to_ret = ''; |
---|
103 | $to_ret .= '<div> </div>'; |
---|
104 | $to_ret .= '<div class="bandeau_rubriques" style="z-index: 1;">'; |
---|
105 | $to_ret .= "<div style='position: relative;'>"; |
---|
106 | $to_ret .= "<div style='position: absolute; top: -12px; $spip_lang_left: 3px;'> |
---|
107 | <img src=\""._DIR_PLUGIN_AUTO_CLAVE."/img/updown.png\"/></div>"; |
---|
108 | $to_ret .= "<div style='background-color: white; color: black; padding: 3px; padding-$spip_lang_left: 30px; border-bottom: 1px solid #444444;' class='verdana2'><b>"._T('autoclaves:palabras_clave')."</b></div>"; |
---|
109 | $to_ret .= "</div>"; |
---|
110 | |
---|
111 | $to_ret .= '<div class="plan-articles">'; |
---|
112 | $to_ret .= '<div id="lista_auto_claves"><form action="?exec=addclaves" method="post" name="myform">'; |
---|
113 | $to_ret .= '<b>' ._T('autoclaves:Selec_loc'). '</b> '. count($palabras).'<br/>'; /* /XX<br />'; */ |
---|
114 | |
---|
115 | $to_ret .= _T('autoclaves:claves') ."<input type='radio' name='todosc' value='todost' id='todos1c' checked='CHECKED' onclick='checkAll(\"palabras[]\")'>" ._T('autoclaves:todas') ."<input type='radio' name='todosc' value='ningunot' id='todos1c' onclick='uncheckAll(\"palabras[]\")'>" ._T('autoclaves:ninguna') .'<br />'; |
---|
116 | |
---|
117 | /* $to_ret .= _T('autoclaves:claves') ."<input type='radio' name='todosc' value='todost' '-' id='todos1c' CHECKED>" ._T('autoclaves:todas') ."<input type='radio' name='todosc' value='ningunot' '-' id='todos1c'>" ._T('autoclaves:ninguna') .'<br />'; */ |
---|
118 | |
---|
119 | |
---|
120 | foreach($palabras as $palabra) { |
---|
121 | $to_ret .= autoclaves_palabras($palabra['titre'], $palabra['id_groupe'], $palabra['id'], $palabra['previa']); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | $arguments['data'] .= $to_ret ; |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | // Leer datos actuales |
---|
131 | /* |
---|
132 | |
---|
133 | if (($connect_statut == '0minirezo') AND $connect_toutes_rubriques) { |
---|
134 | if($arguments['args']['exec'] == 'articles') { |
---|
135 | $arguments['data'] .= autoclaves_boite_tri_mots($arguments['args']['id_article'],'articles','id_article','articles'); |
---|
136 | } |
---|
137 | else if($arguments['args']['exec'] == 'naviguer') { |
---|
138 | $arguments['data'] .= autoclaves_boite_tri_mots($arguments['args']['id_rubrique'],'rubriques','id_rubrique','naviguer'); |
---|
139 | } |
---|
140 | else if($arguments['args']['exec'] == 'auteurs_edit') { |
---|
141 | $arguments['data'] .= autoclaves_boite_tri_mots($arguments['args']['id_auteur'],'auteurs','id_auteur','auteurs_edit'); |
---|
142 | } |
---|
143 | else if($arguments['args']['exec'] == 'mots_edit') { |
---|
144 | $arguments['data'] .= icone(_T('trimots:titre_page',array('objets' => _T('public:articles'))),generer_url_ecrire('tri_mots','objet=articles&ident_objet=id_article&id_mot='.$arguments['args']['id_mot'].'&retour='.urlencode(generer_url_ecrire('mots_edit',"id_mot=".$arguments['args']['id_mot']))), '../'._DIR_PLUGIN_AUTO_CLAVE.'/img/updown.png', "rien.gif"); |
---|
145 | $arguments['data'] .= icone(_T('trimots:titre_page',array('objets' => _T('public:rubriques'))),generer_url_ecrire('tri_mots','objet=rubriques&ident_objet=id_rubrique&id_mot='.$arguments['args']['id_mot'].'&retour\ |
---|
146 | ='.urlencode(generer_url_ecrire('mots_edit',"id_mot=".$arguments['args']['id_mot']))), '../'._DIR_PLUGIN_AUTO_CLAVE.'/img/updown.png', "rien.gif"); |
---|
147 | } |
---|
148 | } |
---|
149 | */ |
---|
150 | |
---|
151 | $arguments['data'] .= "<input type='hidden' name='id_article' value='".$id_art."' />"; |
---|
152 | $arguments['data'] .= "<input type='hidden' name='exec' value='".$id_art."' />"; |
---|
153 | $arguments['data'] .= "<br /> <input type='submit' name='Valider' value='"._T('bouton_valider')."' class='fondo'>"; |
---|
154 | $arguments['data'] .= '</div>'; |
---|
155 | $arguments['data'] .= '</div></div>'; |
---|
156 | $arguments['data'] .= "\n" ; |
---|
157 | |
---|
158 | // fin_cadre(true); |
---|
159 | |
---|
160 | // $arguments['data'] .= $to_ret; |
---|
161 | |
---|
162 | } |
---|
163 | return $arguments; |
---|
164 | } |
---|
165 | |
---|
166 | function autoclaves_boite_tri_mots($id,$objet,$id_objet,$retour) { |
---|
167 | global $spip_lang_left; |
---|
168 | include_spip('base/abstract_sql'); |
---|
169 | // $installe = unserialize(lire_meta('TriMots:installe')); |
---|
170 | $from = array("spip_mots_$objet as lien",'spip_mots as mots'); |
---|
171 | $select = array('lien.id_mot','mots.titre','mots.id_groupe','mots.type'); |
---|
172 | $where = array('lien.id_mot=mots.id_mot',"lien.$id_objet=$id"); |
---|
173 | $un_mot = false; |
---|
174 | |
---|
175 | $palabras=array(); |
---|
176 | |
---|
177 | $rez = spip_abstract_select($select,$from,$where); |
---|
178 | while($row = spip_abstract_fetch($rez)) { |
---|
179 | $to_ret .= autoclaves_palabras($row['titre'].'='.$row['id_mot'] .'-:'.$row['id_groupe'].'--'.$row['type'], $row['id_groupe'], $row['id_mot'], "previa"); |
---|
180 | $palabras[]=$row['titre']; |
---|
181 | $palabras[]=$row['id_mot']; |
---|
182 | $palabras[]=$row['id_groupe']; |
---|
183 | $palabras[]=$row['type']; |
---|
184 | $palabras[]=$row['id_groupe']; |
---|
185 | |
---|
186 | $un_mot =true; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | $from = array('spip_articles'); |
---|
191 | $select = array('id_rubrique'); |
---|
192 | $where = array("id_article="._request('id_article')); |
---|
193 | |
---|
194 | $row = spip_abstract_fetch(spip_abstract_select($select,$from,$where)); |
---|
195 | $id_rubrique = $row['id_rubrique']; |
---|
196 | |
---|
197 | // $to_ret .= '<div class=' .HEREDADAS .'>' ." Sección=" .$id_rubrique .'</div>'; |
---|
198 | |
---|
199 | $from = array("spip_mots_rubriques as lien",'spip_mots as mots'); |
---|
200 | $select = array('lien.id_mot','mots.titre','mots.id_groupe','mots.type'); |
---|
201 | $where = array('lien.id_rubrique=$id_rubrique',"mot.id_mot=lien.$id_mot"); |
---|
202 | $row = spip_abstract_select($select,$from,$where); |
---|
203 | |
---|
204 | // $to_ret .= '<div class=' .HEREDADAS .'>' .build_checkbox($row['titre'] ."#" .$row['id_mot'] ." heredada", "on") ." S=".$id_rubrique ."#" .$row['id_mot'] .$row['type'] .$row['titre'] .'</div>'; |
---|
205 | |
---|
206 | $result = spip_query("SELECT id_mot, id_rubrique FROM spip_mots_rubriques WHERE id_rubrique=$id_rubrique"); |
---|
207 | if ($row = spip_fetch_array($result)) |
---|
208 | $type = (corriger_caracteres($row['id_mot'])); |
---|
209 | else $type = (corriger_caracteres($type)); |
---|
210 | |
---|
211 | $to_ret .= '<div class=' .HEREDADAS .'>' .build_checkbox($row['id_mot'] .$type .' heredada', "on") .$row['titre'] ."#" .$row['id_mot'] ."#" .$type ." S2=".$id_rubrique .'</div>'; |
---|
212 | |
---|
213 | |
---|
214 | // Distinction unique / multiple selon le parametrage du groupe de mots |
---|
215 | $id_groupe = $id_rubrique ; |
---|
216 | $query = "SELECT unseul FROM spip_mots_rubriques WHERE id_groupe=$id_rubrique"; |
---|
217 | $row = spip_fetch_array(spip_query($query)); |
---|
218 | $multiple = ($row['unseul'] != 'oui'); |
---|
219 | |
---|
220 | |
---|
221 | // Recuperer les choix |
---|
222 | $query = "SELECT id_mot, id_rubrique FROM spip_mots_rubriques WHERE id_rubrique=$id_rubrique"; |
---|
223 | $result = spip_query($query); |
---|
224 | $liste = array(); |
---|
225 | while ($row = spip_fetch_array($result)) { |
---|
226 | $id_mot = $row['id_mot']; |
---|
227 | // $titre = $row['titre']; |
---|
228 | // $liste[$id_mot] = $titre; |
---|
229 | $titre = $row['titre']; |
---|
230 | $liste[$id_mot] = $titre; |
---|
231 | $to_ret .= '<div class=' .HEREDADAS .'>' .build_checkbox($row['id_mot'].' heredada', "on") ."-" .$row['id_mot'] ."-S3=" .$id_rubrique .'</div>'; |
---|
232 | } |
---|
233 | |
---|
234 | |
---|
235 | // Recuperer les choix |
---|
236 | $query = "SELECT r.id_mot, r.id_rubrique, mots.titre, mots.id_groupe, mots.type FROM spip_mots_rubriques AS r, spip_mots as mots WHERE r.id_rubrique=$id_rubrique, mot.id_mot=r.id_mot"; |
---|
237 | $result = spip_query($query); |
---|
238 | $liste = array(); |
---|
239 | while ($row = spip_fetch_array($result)) { |
---|
240 | $id_mot = $row['id_mot']; |
---|
241 | $titre = $row['titre']; |
---|
242 | // $liste[$id_mot] = $titre; |
---|
243 | $titre = $row['titre']; |
---|
244 | $liste[$id_mot] = $titre; |
---|
245 | $to_ret .= '<div class=' .HEREDADAS .'>' .build_checkbox($row['id_mot']." heredada", "on") ."-" .$row['id_mot'] .$row['titre'] ."-S4=" .$id_rubrique .'</div>'; |
---|
246 | } |
---|
247 | |
---|
248 | // Listar las palabra claves |
---|
249 | // $to_ret .= autoclaves_leer_palabras($id_rubrique); |
---|
250 | |
---|
251 | |
---|
252 | if($un_mot) |
---|
253 | return $to_ret; |
---|
254 | else |
---|
255 | return ''; |
---|
256 | } |
---|
257 | |
---|
258 | function autoclaves_boite_auto_claves($id_article) { |
---|
259 | global $spip_lang_left,$connect_id_auteur; |
---|
260 | |
---|
261 | include_spip('base/abstract_sql'); |
---|
262 | $to_ret .= '<div> </div>'; |
---|
263 | $to_ret .= '<div class="bandeau_rubriques" style="z-index: 1;">'; |
---|
264 | $to_ret .= "<div style='position: relative;'>"; |
---|
265 | $to_ret .= "<div style='position: absolute; top: -12px; $spip_lang_left: 3px;'> |
---|
266 | <img src=\""._DIR_PLUGIN_AUTO_CLAVE."/img/updown.png\"/></div>"; |
---|
267 | $to_ret .= "<div style='background-color: white; color: black; padding: 3px; padding-$spip_lang_left: 30px; border-bottom: 1px solid #444444;' class='verdana2'><b>"._T('autoclaves:palabras_clave')."</b></div>"; |
---|
268 | $to_ret .= "</div>"; |
---|
269 | |
---|
270 | $to_ret .= '<div class="plan-articles" id="lista_tri_auto_claves">'; |
---|
271 | $to_ret .= '<div id="lista_auto_claves">'; |
---|
272 | |
---|
273 | $to_ret .= '</div>'; |
---|
274 | $to_ret .= '</div></div>'; |
---|
275 | return $to_ret; |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | function autoclaves_buscar_mots($id_article, $id_groupe_mot = '') { |
---|
280 | /* dado un articulo, busca todas las palabras claves mencionadas en su texto y devuelve un array. */ |
---|
281 | |
---|
282 | /*original code from |
---|
283 | http://trac.rezo.net/trac/spip-zone/browser/_plugins_/_test_/definitions_mots/definitions_mes_fonctions.php */ |
---|
284 | |
---|
285 | $query = "SELECT surtitre, titre,soustitre,descriptif, chapo, texte, ps FROM spip_articles WHERE id_article=$id_article"; |
---|
286 | |
---|
287 | $result_article = spip_query($query); |
---|
288 | |
---|
289 | $article = spip_fetch_array($result_article); |
---|
290 | $palabras = array(); |
---|
291 | $ids = array(); |
---|
292 | |
---|
293 | foreach($article as $text){ |
---|
294 | |
---|
295 | |
---|
296 | if ($id_groupe_mot == '') |
---|
297 | $result = spip_query("SELECT id_mot, id_groupe, titre from spip_mots"); |
---|
298 | else |
---|
299 | $result = spip_query("SELECT id_mot, id_groupe, titre from spip_mots WHERE id_groupe=$id_groupe_mot"); |
---|
300 | |
---|
301 | while( $row = spip_fetch_array($result)) |
---|
302 | { |
---|
303 | if (stripos($text,$row['titre']) !== false) |
---|
304 | { |
---|
305 | |
---|
306 | $id_mot = $row['id_mot']; |
---|
307 | |
---|
308 | if(!in_array($row['id_mot'],$ids) ){ //check for duplicated |
---|
309 | |
---|
310 | |
---|
311 | if( spip_num_rows(spip_query("SELECT * FROM spip_mots_articles WHERE id_mot=$id_mot AND id_article = $id_article"))>=1){ |
---|
312 | $previa = "previa"; |
---|
313 | }else{ |
---|
314 | $previa = ""; |
---|
315 | } |
---|
316 | |
---|
317 | |
---|
318 | $ids[] = $row['id_mot']; |
---|
319 | $palabras[] = array("id" => $row['id_mot'], "id_groupe" => $row['id_groupe'], "titre" => $row['titre'], "previa"=>$previa); |
---|
320 | } |
---|
321 | }//end stripos |
---|
322 | |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | return $palabras; |
---|
327 | |
---|
328 | } |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | |
---|
334 | ?> |
---|