[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/ -> inc_liens.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  // Ce fichier ne sera execute qu'une fois
  20  if (defined('_ECRIRE_INC_LIENS'))
  21      return;
  22  
  23  define('_ECRIRE_INC_LIENS', 1);
  24  
  25  include_ecrire  ('inc_texte.php');
  26  require_once("DB.php");
  27  require_once  'include/bd/metier.php';
  28  require_once  'include/bd/parameters.php';
  29  
  30  // Met a jour la table spip_liens
  31  // qui sert a referencer les liens internes
  32  function update_liens ($contenu, $contenant) {
  33      $liens = array();
  34  
  35      // Echapper les <a href>, <html>...< /html>, <code>...< /code>
  36      list($contenu, $tmp) = echappe_html($contenu, 'SOURCEPROPRE');
  37      // Corriger HTML
  38      $contenu = eregi_replace("</?p>", "\n\n\n", $contenu);
  39  
  40      // Raccourcis typographiques des liens internes
  41      $types_liens = array('ar' => 'art', 'ru' => 'rub', 'br' => 'bre', 
  42                           'au' => 'aut', 'mo' => 'mot', 'si' => 'sit',
  43                           'im' => 'img', 'do' => 'doc');
  44      $regexp = "\[([^][]*)->(>?)([^]]*)\]";
  45      $texte_a_voir = $contenu;
  46      $texte_vu = '';
  47  
  48      while (ereg($regexp, $texte_a_voir, $regs)) {
  49          $lien_url = trim($regs[3]);
  50  
  51          if (ereg("^(art(icle)?|rub(rique)?|br(.ve)?|aut(eur)?|mot|site|doc(ument)?|im(age|g))? *([[:digit:]]+)$",
  52                   $lien_url,
  53                   $match)) {
  54              $id_lien = $match[8];
  55              $type_lien = $types_liens[substr($match[1]. 'ar', 0, 2)];
  56              $lien = $type_lien . '-' . $id_lien;
  57              $liens[] = array('type' => 'interne', 'valeur' => $lien);
  58          }
  59          else {
  60              $liens[] = array('type' => 'externe', 'valeur' => $lien_url);
  61          }
  62  
  63          $zetexte = split($regexp, $texte_a_voir, 2);
  64          $texte_vu .= typo($zetexte[0]). $insert;
  65          $texte_a_voir = $zetexte[1];
  66      }
  67  
  68      $contenu = $texte_vu . typo($texte_a_voir); // typo de la queue du texte
  69  
  70      // Raccourcis typo des images et documents joints
  71      while (eregi("<(IMG|DOC|EMB)([0-9]+)(\|[^>]+)?>", $contenu, $match)) {
  72          $tag = quotemeta($match[0]);
  73          $type_lien = strtolower($match[1]);
  74          $id_lien = $match[2];
  75          $lien = $type_lien . '-' . $id_lien;
  76          $liens[] = array('type' => 'interne', 'valeur' => $lien);
  77          $contenu = str_replace($tag, '', $contenu);
  78      }
  79  
  80      if (count($liens) > 0) {
  81          $dbMetier = new BD_metier;
  82          $dbMetier->setDbParameters($GLOBALS['bd_params']);
  83          $db = $dbMetier->_getDB();
  84          $db->query("DELETE FROM " . $GLOBALS['table_prefix']. "_liens WHERE contenant = '" . $contenant . "'");
  85          reset ($liens);
  86          while (list(, $lien) = each($liens)) {
  87              $db->query("INSERT INTO " . $GLOBALS['table_prefix']. "_liens (contenant, lien_" . $lien['type']. ") " .
  88                          "VALUES ('" . $contenant . "', '" . $lien['valeur']. "')");
  89          }
  90      }
  91  
  92      return count($liens);
  93  }
  94  
  95  // Affiche une boite qui liste les liens internes 
  96  // pointant vers la page courante
  97  function afficher_liens ($lien_interne) {
  98      global $connect_id_auteur, $connect_statut;
  99      global $couleur_claire;
 100  
 101      $dbMetier = new BD_metier;
 102      $dbMetier->setDbParameters($GLOBALS['bd_params']);
 103      $db = $dbMetier->_getDB();
 104  
 105      // Y'a t'il des liens vers cet élément ?
 106      // contrib S Petit
 107      $nbLiens = $db->getOne("SELECT COUNT(*) AS nb FROM " . $GLOBALS['table_prefix']. "_liens WHERE lien_interne = '" . $lien_interne . "'");
 108      //$nbLiens = $db->getOne("SELECT COUNT(*) nb FROM ".$GLOBALS['table_prefix']."_liens WHERE lien_interne = '".$lien_interne."'");
 109      // fin contrib 
 110      if ($nbLiens > 0) {
 111          // Affichage du cadre
 112          echo '<a name="liens" id="liens"></a>';
 113          echo debut_cadre_enfonce('liens-24.gif');
 114          echo '<table border="0" cellspacing="0" cellpadding="3" width="100%">'.
 115               '<tr><td bgcolor="#EEEECC">';
 116          echo '<font size="2" face="Georgia,Garamond,Times,serif"><strong>'._T('liens_internes').'</strong></font>';
 117          echo aide('liens_internes');
 118          echo '</td></tr></table><br />';
 119  
 120          $typesLiens = array(
 121              'rub' => array(
 122                  'table' => $GLOBALS['table_prefix'].'_rubriques',
 123                  'key_field' => 'id_rubrique',
 124                  'label_field' => 'titre',
 125                  'label' => 'liens_depuis_rubriques',
 126                  'url' => 'naviguer.php?coll=%s'
 127              ),
 128              'art' => array(
 129                  'table' => $GLOBALS['table_prefix'].'_articles',
 130                  'key_field' => 'id_article',
 131                  'label_field' => 'titre',
 132                  'label' => 'liens_depuis_articles',
 133                  'url' => 'articles.php?id_article=%s'
 134              ),
 135              'bre' => array(
 136                  'table' => $GLOBALS['table_prefix'].'_breves',
 137                  'key_field' => 'id_breve',
 138                  'label_field' => 'titre',
 139                  'label' => 'liens_depuis_breves',
 140                  'url' => 'breves_voir.php?id_breve=%s'
 141              )
 142          );
 143          $ifond = 0;
 144  
 145          while (list($code, $data) = each($typesLiens)) {
 146              $result = $db->query("SELECT contenant " .
 147                                   "FROM ".$GLOBALS['table_prefix']."_liens " .
 148                                   "WHERE lien_interne = '".$lien_interne."' " .
 149                                   "AND contenant LIKE '".$code."-%'");
 150              if ($result->numRows() > 0) {
 151                  echo '<br /><font face="Verdana,Arial,Helvetica,sans-serif" size="2"><strong>'.
 152                       _T($data['label']).'&nbsp; </strong></font><br />';
 153                  echo '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
 154                  while ($row = $result->fetchRow()) {
 155                      ereg("-([0-9]+)$", $row['contenant'], $regs);
 156                      $id_contenant = $regs[1];
 157  
 158                      // contrib S Petit
 159                      $titre = $db->getOne("SELECT ".$data['label_field']." AS titre " .
 160                                           "FROM ".$data['table']." " .
 161                                           "WHERE ".$data['key_field']." = ".$id_contenant);
 162                      //$titre = $db->getOne("SELECT ".$data['label_field']." titre FROM ".$data['table']." WHERE ".$data['key_field']." = ".$id_contenant);
 163                      // fin contrib 
 164                      $ifond = $ifond ^ 1;
 165                      $couleur = ($ifond) ? '#FFFFFF' : $couleur_claire;
 166                      echo '<tr bgcolor="'.$couleur.'" width="100%">';
 167                      echo '<td class="arial2"><a href="'.sprintf($data['url'], $id_contenant).'">'.$titre.'</a></td>';
 168                      echo '</tr>';
 169                  }
 170                  echo "</table>\n";
 171              }
 172          }
 173  
 174          fin_cadre_enfonce();
 175      }
 176  }
 177  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7