X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Fediter_mots.php;fp=www%2Fecrire%2Finc%2Fediter_mots.php;h=4b8ed87b7ce8ab717327d0e5e85203ce005a8d2e;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/ecrire/inc/editer_mots.php b/www/ecrire/inc/editer_mots.php new file mode 100644 index 0000000..4b8ed87 --- /dev/null +++ b/www/ecrire/inc/editer_mots.php @@ -0,0 +1,397 @@ + array( + 'operation' => 'editer_mots', + 'table' => table_objet_sql($objet), + 'id_objet' => $id_objet + ), + 'data' => null + ) + ); + } + return $reponse; +} +// http://doc.spip.org/@inserer_mot +function inserer_mot($table, $table_id, $id_objet, $id_mot) +{ + $r = sql_countsel($table, "id_mot=$id_mot AND $table_id=$id_objet"); + if (!$r) { + sql_insertq($table, array('id_mot' =>$id_mot, $table_id => $id_objet)); + return true; + } +} + + +// http://doc.spip.org/@recherche_mot_cle +function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table, $table_id, $url_base) +{ + $ou = _T('info_mot_cle_ajoute') . ' '; + if ($table == 'articles') $ou .= _T('info_l_article'); + else if ($table == 'breves') $ou .= _T('info_la_breve'); + else if ($table == 'rubriques') $ou .= _T('info_la_rubrique'); + + $result = sql_select("id_mot, titre", "spip_mots", (!$id_groupe ? '' : sql_in('id_groupe', $id_groupe))); + + $table_mots = array(); + $table_ids = array(); + while ($row = sql_fetch($result)) { + $table_ids[] = $row['id_mot']; + $table_mots[] = $row['titre']; + } + + $nouveaux_mots = array(); + $res = ''; + + foreach (preg_split("/ *[,;] */", $cherche_mots) as $cherche_mot) { + if ($cherche_mot) { + $resultat = mots_ressemblants($cherche_mot, $table_mots, $table_ids); + $res .= "
" . debut_boite_info(true); + if (!$resultat) { + $res .= ""._T('info_non_resultat', array('cherche_mot' => htmlspecialchars($cherche_mot)))."
"; + } + else if (count($resultat) == 1) { + $n = $resultat[0]; + $nouveaux_mots[] = $n; + $t = sql_getfetsel("titre", "spip_mots", "id_mot=$n"); + $res .= "" + . $ou + . ":
\n"; + } + else $res .= affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base); + + $res .= fin_boite_info(true) . "
"; + } + } + return array($res, $nouveaux_mots); +} + +// http://doc.spip.org/@afficher_mots_cles +function afficher_mots_cles($flag, $objet, $id_objet, $table, $table_id, $url) +{ + $q = array('SELECT' => "M.id_mot, M.titre, M.id_groupe", 'FROM' => "spip_mots AS M LEFT JOIN spip_mots_$table AS L ON M.id_mot=L.id_mot", 'WHERE' => "L.$table_id=$id_objet", 'ORDER BY' => "M.type, M.titre"); + + $ret = generer_url_retour($url, "$table_id=$id_objet#editer_mots-$id_objet"); + $styles = array(array('arial11',25), array('arial2'), array('arial2'), array('arial1')); + + $presenter_liste = charger_fonction('presenter_liste', 'inc'); + + // cette variable est passee par reference + // pour recevoir les valeurs du champ indique + $mots = 'id_mot'; + $a = array($flag,$id_objet, $objet, $ret, $table, $table_id, $url); + $res = $presenter_liste($q, 'editer_mots_un', $mots, $a, false, $styles); + + return array($res, $mots); +} + +// http://doc.spip.org/@editer_mots_un +function editer_mots_un($row, $own) +{ + $puce_statut = charger_fonction('puce_statut', 'inc'); + + list ($flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base) = $own; + + $id_mot = $row['id_mot']; + $titre_mot = $row['titre']; + $id_groupe = $row['id_groupe']; + + $url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret"); + + $groupe_champs = sql_fetsel("*", "spip_groupes_mots", "id_groupe = $id_groupe"); + $groupe = typo($groupe_champs['titre']); + + if (autoriser('modifier', 'groupemots', $id_groupe)) + $groupe = "$groupe"; + + $mot = "".typo($titre_mot).""; + + $retire = ''; + if ($flag_editable + AND autoriser('editermots', $objet, $id_objet, null, array('id_groupe'=>$id_groupe,'groupe_champs'=>$groupe_champs)) + ) { + $r = _T('info_retirer_mot') + . " " + . http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'"); + + $retire = ajax_action_auteur('editer_mots', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array($r,''),"&id_objet=$id_objet&objet=$objet"); + + // Changer ; si unseul, poser un petit menu + if (sql_getfetsel('unseul', 'spip_groupes_mots', 'id_groupe='.$id_groupe) + == 'oui') + $mot = formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet); + } + + $cle = $puce_statut($id_mot, 'publie', $id_groupe, 'mot'); + + return array("$cle", $mot, $groupe, $retire); +} + +// http://doc.spip.org/@formulaire_mot_remplace +function formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet) +{ + $res = sql_allfetsel("id_mot, titre", "spip_mots", "id_groupe = $id_groupe", "", "titre"); + + foreach($res as $k => $row) { + $id = $row['id_mot']; + $titre = supprimer_tags(typo($row['titre'])); + $selected = ($id == $id_mot) ? " selected='selected'" : ""; + $res[$k]= ""; + } + + $ancre = "valider_groupe_$id_groupe"; + // forcer le recalcul du noeud car on est en Ajax + $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; + + $corps = "\n\n " ; + + $t = _T('bouton_changer'); + + return ajax_action_post('editer_mots', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet",$corps, $t, " class='visible_au_chargement' id='$ancre'", "", "&id_objet=$id_objet&objet=$objet"); +} + +// int $id_objet : id_article +// array $les_mots : les mots deja apposes +// string $table : 'articles' +// string $table_id : 'id_article' +// string $url_base : 'articles' (?) +// boolean $visible : determiner si le formulaire est deplie +// string $objet : 'article' +// http://doc.spip.org/@formulaire_mots_cles +function formulaire_mots_cles($id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet) { + global $spip_lang, $spip_lang_right; + + $res = ''; + + // liste des groupes de mots contenant au moins un mot deja appose a l'objet + $id_groupes_vus = array_map('array_pop', + sql_allfetsel('DISTINCT(id_groupe)', 'spip_mots', + sql_in('id_mot', $les_mots))); + + // supprimer tous les mots ? + // a partir de 3 mots on regarde si l'ensemble des mots sont supprimables + // si oui on propose ce lien + if (count($les_mots)>= 3) { + $ok = true; + foreach ($id_groupes_vus as $id_groupe) + $ok &= autoriser('editermots', $objet, $id_objet, null, + array('id_groupe'=>$id_groupe,'groupe_champs'=>$row)); + if ($ok) + $res .= "
" + . ajax_action_auteur('editer_mots', "$id_objet,-1,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array(_T('info_retirer_mots'),''),"&id_objet=$id_objet&objet=$objet") + . "

\n"; + } + + // formulaire groupe par groupe + $ajouter =''; + $cond_mots_vus = $les_mots + ? " AND " . sql_in('id_mot', $les_mots, 'NOT') + : ''; + + define('_TRI_GROUPES_MOTS', 'titre'); + foreach(sql_allfetsel('*,' . sql_multi ("titre", $spip_lang), 'spip_groupes_mots', '', '', _TRI_GROUPES_MOTS) as $row) { + $id_groupe = $row['id_groupe']; + if (autoriser('editermots', $objet, $id_objet, null, + array('id_groupe'=>$id_groupe,'groupe_champs'=>$row)) + AND $menu = menu_mots($row, $id_groupes_vus, $cond_mots_vus)) { + list($corps, $clic) = $menu; + $ajouter .= ajax_action_post('editer_mots', + "$id_objet,,$table,$table_id,$objet", + $url_base, + "$table_id=$id_objet", + $corps, + $clic, + " class='visible_au_chargement spip_xx-small' id='valider_groupe_$id_groupe'", "", + "&id_objet=$id_objet&objet=$objet&select_groupe=$id_groupe"); + + // forcer la visibilite si au moins un mot obligatoire absent + // attention true <> 1 pour bouton_block_depliable + if ($row['obligatoire'] == 'oui' + AND !in_array($id_groupe, $id_groupes_vus)) + $visible = true; + } + } + + if ($ajouter) { + $res .= "
" + . $ajouter + ."
\n" + . "" + ._T('titre_ajouter_mot_cle') + ."
\n"; + } + + return array($visible, $res); +} + +function creer_mot($table, $id_objet, $table_id, $url_base, $mot='', $id_groupe=0) +{ + static $titres = array( + 'articles'=>'icone_creer_mot_cle', + 'breves'=>'icone_creer_mot_cle_breve', + 'rubriques'=>'icone_creer_mot_cle_rubrique', + 'sites'=>'icone_creer_mot_cle_site' + ); + + if (!($id_groupe ? + autoriser('modifier','groupemots', $id_groupe) : + autoriser('modifier','groupemots')) + ) + return ''; + + $legende = isset($titres[$table]) + ? _T($titres[$table]) + : _T('icone_creer_mot_cle'); + + $args = "new=oui&ajouter_id_article=$id_objet&table=$table&table_id=$table_id" + . (!$mot ? '' : ("&titre=".rawurlencode($mot))) + . (!$id_groupe ? '' : ("&id_groupe=".intval($id_groupe))) + . "&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet"); + + return icone_horizontale_display($legende, generer_url_ecrire("mots_edit", $args), "mot-cle-24.gif", "creer.gif", false); +} + +// http://doc.spip.org/@menu_mots +function menu_mots($row, $id_groupes_vus, $cond_mots_vus) +{ + $id_groupe = $row['id_groupe']; + + // nombre de mots dans le groupe ? + $n = sql_countsel("spip_mots", "id_groupe=$id_groupe" . $cond_mots_vus); + if (!$n) return ''; + + // mot seul, si deja present on se casse + $unseul = ($row['unseul'] == 'oui'); + if ($unseul + AND in_array($id_groupe, $id_groupes_vus)) + return ''; + + $titre = textebrut(typo($row['titre'])); + $obligatoire = ($row['obligatoire']=='oui' + AND !in_array($id_groupe, $id_groupes_vus)); + + // forcer le recalcul du noeud car on est en Ajax + $rand = rand(0,10000); # pour antifocus & ajax + $ancre = "valider_groupe_$id_groupe"; + $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';"; + $jscript2 = "if(!antifocus_mots['$rand-$id_groupe']){this.value='';antifocus_mots['$rand-$id_groupe']=true;}"; + + if (!defined('_MAX_MOTS_LISTE')) define('_MAX_MOTS_LISTE', '50'); + if ($n > _MAX_MOTS_LISTE) { + $jscript = "onfocus=\"$jscript1 $jscript2\""; + + if ($obligatoire) + $res = ""; + else if ($unseul) { + $res = ""; + } else + $res = ""; + + $res .= " "; + return array($res, _T('bouton_chercher')); + } else { + if ($obligatoire) + $style = 'width: 180px; background-color:#E86519;'; + else if ($unseul) + $style = 'width: 180px; background-color:#cccccc;'; + else + $style = 'width: 180px;'; + + $q = sql_allfetsel("id_mot, type, titre", "spip_mots", "id_groupe =$id_groupe " . $cond_mots_vus, "", "titre"); + + foreach($q as $k => $r) { + $q[$k] = ""; + } + $res = " "; + + return array($res, _T('bouton_choisir')); + } +} + +?>