[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/inc/ -> editer_mot.php (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2007                                                *
   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  include_spip('inc/actions');
  15  include_spip('inc/mots');
  16  
  17  // http://doc.spip.org/@inc_editer_mot_dist
  18  function inc_editer_mot_dist($objet, $id_objet, $cherche_mot, $select_groupe, $flag) {
  19      global $options, $connect_statut, $spip_lang_rtl, $spip_lang_right, $spip_lang;
  20  
  21      if (!($options == 'avancees' AND $GLOBALS['meta']["articles_mots"] != 'non'))
  22          return '';
  23  
  24      $visible = ($cherche_mot OR ($flag === 'ajax'));
  25  
  26      if ($objet == 'article') {
  27          $table_id = 'id_article';
  28          $table = 'articles';
  29          $url_base = "articles";
  30      }
  31      else if ($objet == 'breve') {
  32          $table_id = 'id_breve';
  33          $table = 'breves';
  34          $url_base = "breves_voir";
  35      }
  36      else if ($objet == 'rubrique') {
  37          $table_id = 'id_rubrique';
  38          $table = 'rubriques';
  39          $url_base = "naviguer";
  40      }
  41  
  42      else if ($objet == 'syndic') {
  43          $table_id = 'id_syndic';
  44          $table = 'syndic';
  45          $url_base = "sites";
  46      }
  47      else {
  48          spip_log("erreur dans formulaire_mots($objet, $id_objet, $cherche_mot, $select_groupe, $flag)");
  49          return '';
  50      }
  51  
  52      $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot"));
  53  
  54      if (!($nombre_mots = $cpt['n'])) {
  55          if (!$flag) return;
  56          $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM spip_groupes_mots WHERE $table = 'oui'    AND ".substr($connect_statut,1)." = 'oui'"));
  57  
  58          if (!$cpt['n']) return;
  59      }
  60  
  61      //
  62      // Preparer l'affichage
  63      //
  64  
  65      // La reponse
  66      $reponse = '';
  67      if ($flag AND $cherche_mot) {
  68          $reindexer = false;
  69          list($reponse, $nouveaux_mots) = recherche_mot_cle($cherche_mot, $select_groupe, $objet, $id_objet, $table, $table_id, $url_base);
  70          foreach($nouveaux_mots as $nouv_mot) {
  71              if ($nouv_mot!='x') {
  72                  $reindexer |= inserer_mot("spip_mots_$table", $table_id, $id_objet, $nouv_mot);
  73              }
  74          }
  75          if ($reindexer AND ($GLOBALS['meta']['activer_moteur'] == 'oui')) {
  76              include_spip("inc/indexation");
  77              marquer_indexer("spip_$table", $id_objet);
  78          }
  79      }
  80  
  81      $form = afficher_mots_cles($flag, $objet, $id_objet, $table, $table_id, $url_base, $visible);
  82  
  83      // Envoyer titre + div-id + formulaire + fin
  84      if ($flag){
  85          if ($visible)
  86              $bouton = bouton_block_visible("lesmots");
  87          else
  88              $bouton =  bouton_block_invisible("lesmots");
  89      } else $bouton = '';
  90  
  91      $bouton .= _T('titre_mots_cles').aide ("artmots");
  92  
  93      $res =  '<div>&nbsp;</div>' // place pour l'animation pendant Ajax
  94      . debut_cadre_enfonce("mot-cle-24.gif", true, "", $bouton)
  95        . $reponse
  96        . $form
  97        . fin_cadre_enfonce(true);
  98  
  99      return ajax_action_greffe("editer_mot-$id_objet", $res);
 100  }
 101  
 102  // http://doc.spip.org/@inserer_mot
 103  function inserer_mot($table, $table_id, $id_objet, $id_mot)
 104  {
 105      $result = spip_num_rows(spip_query("SELECT id_mot FROM $table WHERE id_mot=$id_mot AND $table_id=$id_objet"));
 106  
 107      if (!$result) {
 108          spip_query("INSERT INTO $table (id_mot,$table_id) VALUES ($id_mot, $id_objet)");
 109      }
 110      return $result;
 111  }
 112  
 113  
 114  // http://doc.spip.org/@recherche_mot_cle
 115  function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table, $table_id, $url_base)
 116  {
 117      if ($table == 'articles') $ou = _T('info_l_article');
 118      else if ($table == 'breves') $ou = _T('info_la_breve');
 119      else if ($table == 'rubriques') $ou = _T('info_la_rubrique');
 120  
 121      $result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe=$id_groupe");
 122  
 123      $table_mots = array();
 124      $table_ids = array();
 125      while ($row = spip_fetch_array($result)) {
 126              $table_ids[] = $row['id_mot'];
 127              $table_mots[] = $row['titre'];
 128      }
 129  
 130      $nouveaux_mots = array();
 131      $res = '';
 132  
 133      foreach (split(" *[,;] *", $cherche_mots) as $cherche_mot) {
 134        if  ($cherche_mot) {
 135          $resultat = mots_ressemblants($cherche_mot, $table_mots, $table_ids);
 136          $res .= "<p>" . debut_boite_info(true);
 137          if (!$resultat) {
 138              $res .= "<b>"._T('info_non_resultat', array('cherche_mot' => $cherche_mot))."</b><br /></p>";
 139          }
 140          else if (count($resultat) == 1) {
 141              $nouveaux_mots[] = $resultat[0];
 142              $row = spip_fetch_array(spip_query("SELECT titre FROM spip_mots WHERE id_mot=$resultat[0]"));
 143              $res .= "<b>"._T('info_mot_cle_ajoute')." $ou : </b><br /><ul>";
 144              $res .= "<li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($row['titre'])."</span></b></span></li>\n";
 145              $res .= "</ul>";
 146          }
 147          else $res .= affiche_mots_ressemblant($cherche_mot, $objet, $id_objet, $resultat, $table, $table_id, $url_base);
 148  
 149  /*        if (autoriser('modifier','groupemots',$id_groupe)) {
 150              $titre = rawurlencode($cherche_mot);
 151              $res .= "<div style='width: 200px;'>";
 152              $res .= icone_horizontale(_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&id_groupe=$id_groupe&ajouter_id_article=$id_objet&table=$table&table_id=$table_id&titre=$titre&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet")), "mot-cle-24.gif", "creer.gif", false);
 153              $res .= "</div> ";
 154          }
 155  */
 156  
 157          $res .= fin_boite_info(true) . "<p>";
 158        }
 159      }
 160      return array($res, $nouveaux_mots);
 161  }
 162  
 163  // http://doc.spip.org/@afficher_mots_cles
 164  function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id, $url_base, $visible)
 165  {
 166      global $spip_lang_rtl, $spip_lang, $spip_lang_right, $connect_statut, $connect_toutes_rubriques;
 167  
 168      $les_mots = array();
 169      $id_groupes_vus = array();
 170      $groupes_vus = array();
 171      $result = spip_query("SELECT mots.id_mot, mots.titre, mots.descriptif, mots.id_groupe FROM spip_mots AS mots, spip_mots_$table AS lien WHERE lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot ORDER BY mots.type, mots.titre");
 172      if (spip_num_rows($result) > 0) {
 173      
 174          $tableau= array();
 175          $cle = http_img_pack('petite-cle.gif', "", "width='23' height='12'");
 176          $ret = generer_url_retour($url_base, "$table_id=$id_objet#mots");
 177          while ($row = spip_fetch_array($result)) {
 178  
 179              $id_mot = $row['id_mot'];
 180              $titre_mot = $row['titre'];
 181              $descriptif_mot = $row['descriptif'];
 182              $id_groupe = $row['id_groupe'];
 183  
 184              $id_groupes_vus[] = $id_groupe;
 185              $url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret");
 186              $vals= array("<a href='$url'>$cle</a>");
 187              
 188  
 189              $row_groupe = spip_fetch_array(spip_query("SELECT titre, unseul, obligatoire, minirezo, comite FROM spip_groupes_mots WHERE id_groupe = $id_groupe"));
 190      // On recupere le typo_mot ici, et non dans le mot-cle lui-meme; sinon bug avec arabe
 191  
 192              $type_mot = typo($row_groupe['titre']);
 193              $flag_groupe = ($flag_editable AND
 194                      ((($connect_statut === '1comite') AND $row_groupe['comite'] === 'oui') OR (($connect_statut === '0minirezo') AND $row_groupe['minirezo'] === 'oui')));
 195  
 196              // Changer
 197              if (($row_groupe['unseul'] == "oui") AND $flag_groupe) {
 198                  $vals[]= formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet);
 199              } else {
 200                  $vals[]= "<a href='$url'>".typo($titre_mot)."</a>";
 201              }
 202  
 203              if ($connect_toutes_rubriques)
 204                  $vals[]= "<a href='" . generer_url_ecrire("mots_type","id_groupe=$id_groupe") . "'>$type_mot</a>";
 205  
 206              else    $vals[] = $type_mot;
 207      
 208              if ($flag_editable){
 209                  if ($flag_groupe) {
 210                      $s =  _T('info_retirer_mot')
 211                      . "&nbsp;"
 212                      . http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'");
 213                      $s = ajax_action_auteur('editer_mot', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array($s,''),"&id_objet=$id_objet&objet=$objet");
 214                  } else $s = "&nbsp;";
 215                  $vals[] = $s;
 216              } else $vals[]= "";
 217  
 218              $tableau[] = $vals;
 219      
 220              $les_mots[] = $id_mot;
 221          }
 222      
 223          $largeurs = array('25', '', '', '');
 224          $styles = array('arial11', 'arial2', 'arial2', 'arial1');
 225  
 226          $res = "\n<div class='liste'>"
 227          . "\n<table width='100%' cellpadding='3' cellspacing='0' border='0'>"
 228          . afficher_liste($largeurs, $tableau, $styles)
 229          . "</table></div>";
 230      } else $res ='';
 231  
 232      if ($flag_editable)
 233        $res .= formulaire_mots_cles($id_groupes_vus, $id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet);
 234  
 235      return $res;
 236  }
 237  
 238  // http://doc.spip.org/@formulaire_mot_remplace
 239  function formulaire_mot_remplace($id_groupe, $id_mot, $url_base, $table, $table_id, $objet, $id_objet)
 240  {
 241      $result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe = $id_groupe ORDER by titre");
 242  
 243      $s = '';
 244  
 245      while ($row_autres = spip_fetch_array($result)) {
 246          $id = $row_autres['id_mot'];
 247          $le_titre_mot = supprimer_tags(typo($row_autres['titre']));
 248          $selected = ($id == $id_mot) ? " selected='selected'" : "";
 249          $s .= "\n<option value='$id'$selected> $le_titre_mot</option>";
 250      }
 251  
 252      $ancre = "valider_groupe_$id_groupe"; 
 253      // forcer le recalcul du noeud car on est en Ajax
 254      $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';";
 255  
 256      $corps = "<select name='nouv_mot' onchange=\"$jscript1\""
 257      . " class='fondl spip_xx-small' style='width:90px;'>"
 258      . $s
 259      . "</select>" 
 260      . "<span >\n&nbsp;" ;
 261  
 262      $t =  _T('bouton_changer');
 263  
 264      return ajax_action_post('editer_mot', "$id_objet,$id_mot,$table,$table_id,$objet", $url_base, "$table_id=$id_objet",$corps, $t, " class='fondo spip_xx-small visible_au_chargement' id='$ancre'", "", "&id_objet=$id_objet&objet=$objet");
 265  }
 266  
 267  
 268  // http://doc.spip.org/@formulaire_mots_cles
 269  function formulaire_mots_cles($id_groupes_vus, $id_objet, $les_mots, $table, $table_id, $url_base, $visible, $objet) {
 270      global $connect_statut, $spip_lang, $spip_lang_right, $spip_lang_rtl;
 271  
 272      if ($les_mots) {
 273          $nombre_mots_associes = count($les_mots);
 274          $les_mots = join($les_mots, ",");
 275      } else {
 276          $les_mots = "0";
 277          $nombre_mots_associes = 0;
 278      }
 279      $cond_id_groupes_vus = "0";
 280      if ($id_groupes_vus) $cond_id_groupes_vus = join(",",$id_groupes_vus);
 281      
 282      $nb_groupes = spip_num_rows(spip_query("SELECT * FROM spip_groupes_mots WHERE $table = 'oui' AND ".substr($connect_statut,1)." = 'oui' AND obligatoire = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus)"));
 283  
 284      if ($visible)
 285          $res = debut_block_visible("lesmots");
 286      else if ($nb_groupes > 0) {
 287          $res = debut_block_visible("lesmots");
 288              // vilain hack pour redresser un triangle
 289          $couche_a_redresser = $GLOBALS['numero_block']['lesmots'];
 290          if ($GLOBALS['browser_layer'])
 291              $res .= http_script("
 292                  triangle = findObj('triangle' + $couche_a_redresser);
 293                  if (triangle) triangle.src = '" . _DIR_IMG_PACK . "deplierbas$spip_lang_rtl.gif';");
 294      } else $res = debut_block_invisible("lesmots");
 295  
 296      if ($nombre_mots_associes > 3) {
 297          $res .= "<div align='right' class='arial1'>"
 298            . ajax_action_auteur('editer_mot', "$id_objet,-1,$table,$table_id,$objet", $url_base, "$table_id=$id_objet", array(_T('info_retirer_mots'),''),"&id_objet=$id_objet&objet=$objet")
 299          . "</div><br />\n";
 300      }
 301  
 302      $result_groupes = spip_query("SELECT id_groupe,unseul,obligatoire,titre, ".creer_objet_multi ("titre", $spip_lang)." FROM spip_groupes_mots WHERE $table = 'oui' AND ".substr($connect_statut,1)." = 'oui' AND (unseul != 'oui'  OR (unseul = 'oui' AND id_groupe NOT IN ($cond_id_groupes_vus))) ORDER BY multi");
 303  
 304      // Afficher un menu par groupe de mots
 305      $ajouter ='';
 306      while ($row = spip_fetch_array($result_groupes)) {
 307          if ($menu = menu_mots($row, $id_groupes_vus, $les_mots)) {
 308              $id_groupe = $row['id_groupe'];
 309              list($corps, $clic) = $menu;
 310  
 311              $ajouter .= ajax_action_post('editer_mot',
 312                  "$id_objet,,$table,$table_id,$objet",
 313                  $url_base,
 314                  "$table_id=$id_objet",
 315                  $corps,
 316                  $clic,
 317                  " class='visible_au_chargement fondo spip_xx-small' id='valider_groupe_$id_groupe'", "",
 318                  "&id_objet=$id_objet&objet=$objet&select_groupe=$id_groupe");
 319          }
 320      }
 321      if ($ajouter) {
 322          $message = "<span class='verdana1'><b>"._T('titre_ajouter_mot_cle')."</b></span>\n";
 323          $res .= "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>"
 324              . $ajouter
 325              ."</div>\n" ;
 326      }
 327  
 328      if (autoriser('modifier','groupemots')) {
 329          $titre = _request('cherche_mot')
 330              ? "&titre=".rawurlencode(_request('cherche_mot')) : '';
 331          $bouton_ajouter = icone_horizontale(_T('icone_creer_mot_cle'), generer_url_ecrire("mots_edit","new=oui&ajouter_id_article=$id_objet&table=$table&table_id=$table_id$titre&redirect=" . generer_url_retour($url_base, "$table_id=$id_objet")), "mot-cle-24.gif", "creer.gif", false)
 332          . "\n";
 333      }
 334  
 335      if ($message OR $bouton_ajouter) {
 336          $res .= "<div style='width:170px;'>$message
 337              <br />$bouton_ajouter</div>\n";
 338      }
 339  
 340      return $res . fin_block();
 341  }
 342  
 343  
 344  // http://doc.spip.org/@menu_mots
 345  function menu_mots($row, $id_groupes_vus, $les_mots)
 346  {
 347      $rand = rand(0,10000); # pour antifocus & ajax
 348  
 349      $id_groupe = $row['id_groupe'];
 350  
 351      $result = spip_query("SELECT id_mot, type, titre FROM spip_mots WHERE id_groupe =$id_groupe " . ($les_mots ? "AND id_mot NOT IN ($les_mots) " : '') .  "ORDER BY type, titre");
 352  
 353      $n = spip_num_rows($result);
 354      if (!$n) return '';
 355  
 356      $titre = textebrut(typo($row['titre']));
 357      $titre_groupe = entites_html($titre);
 358      $unseul = $row['unseul'] == 'oui';
 359      $obligatoire = $row['obligatoire']=='oui' AND !in_array($id_groupe, $id_groupes_vus);
 360  
 361      $res = '';
 362      $ancre = "valider_groupe_$id_groupe"; 
 363  
 364      // forcer le recalcul du noeud car on est en Ajax
 365      $jscript1 = "findObj_forcer('$ancre').style.visibility='visible';";
 366      $jscript2 = "if(!antifocus_mots['$rand-$id_groupe']){this.value='';antifocus_mots['$rand-$id_groupe']=true;}";
 367  
 368      if ($n > 50) {
 369          $jscript = "onfocus=\"$jscript1 $jscript2\"";
 370  
 371          if ($obligatoire)
 372              $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; background-color:#E86519;' value=\"$titre_groupe\" size='20' $jscript />";
 373          else if ($unseul)
 374              $res .= "<input type='text' name='cherche_mot' class='fondl' style='width: 180px; background-color:#cccccc;' value=\"$titre_groupe\" size='20' $jscript />";
 375          else
 376              $res .= "<input type='text' name='cherche_mot'  class='fondl' style='width: 180px; ' value=\"$titre_groupe\" size='20' $jscript />";
 377  
 378          $res .= "<input type='hidden' name='select_groupe'  value='$id_groupe' />&nbsp;";
 379          return array($res, _T('bouton_chercher')); 
 380      } else {
 381  
 382          $jscript = "onchange=\"$jscript1\"";
 383        
 384          if ($obligatoire)
 385              $res .= "<select name='nouv_mot' size='1' style='width: 180px; background-color:#E86519;' class='fondl' $jscript>";
 386          else if ($unseul)
 387              $res .= "<select name='nouv_mot' size='1' style='width: 180px; background-color:#cccccc;' class='fondl' $jscript>";
 388          else
 389              $res .= "<select name='nouv_mot' size='1' style='width: 180px; ' class='fondl' $jscript>";
 390  
 391          $res .= "\n<option value='x' style='font-variant: small-caps;'>$titre</option>";
 392          while($row = spip_fetch_array($result)) {
 393              $res .= "\n<option value='" .$row['id_mot'] .
 394                  "'>&nbsp;&nbsp;&nbsp;" .
 395                  textebrut(typo($row['titre'])) .
 396                  "</option>";
 397          }
 398          $res .= "</select>&nbsp;";
 399          return array($res, _T('bouton_choisir'));
 400      }
 401  
 402  }
 403  ?>


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics