[ Index ]
 

Code source de SPIP 1.8.3

Accédez au Source d'autres logiciels libres | Soutenez Angelica Josefina !

title

Body

[fermer]

/ecrire/ -> inc_export.php3 (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2005                                                *
   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  
  14  //
  15  // Ce fichier ne sera execute qu'une fois
  16  if (defined("_ECRIRE_INC_EXPORT")) return;
  17  define("_ECRIRE_INC_EXPORT", "1");
  18  
  19  
  20  
  21  $GLOBALS['version_archive'] = '1.2';
  22  
  23  
  24  // Conversion timestamp MySQL (format ascii) en Unix (format integer)
  25  function mysql_timestamp_to_time($maj)
  26  {
  27      $t_an = substr($maj, 0, 4);
  28      $t_mois = substr($maj, 4, 2);
  29      $t_jour = substr($maj, 6, 2);
  30      $t_h = substr($maj, 8, 2);
  31      $t_min = substr($maj, 10, 2);
  32      $t_sec = substr($maj, 12, 2);
  33      return mktime ($t_h, $t_min, $t_sec, $t_mois, $t_jour, $t_an, 0);
  34  }
  35  
  36  function build_begin_tag($tag) {
  37      return "<$tag>";
  38  }
  39  
  40  function build_end_tag($tag) {
  41      return "</$tag>";
  42  }
  43  
  44  // Conversion texte -> xml (ajout d'entites)
  45  function text_to_xml($string) {
  46      return str_replace('<', '&lt;', str_replace('&', '&amp;', $string));
  47  }
  48  
  49  
  50  //
  51  // Exportation generique d'objets (fichier ou retour de fonction)
  52  //
  53  function export_objets($query, $type, $file = 0, $gz = false, $etape_en_cours="", $etape_actuelle="", $nom_etape="") {
  54      global $debut_limit;
  55      if ($etape_en_cours < 1 OR $etape_en_cours == $etape_actuelle){
  56          if ($etape_en_cours > 0) {
  57              echo "<li><b>$nom_etape</b>";
  58          }
  59      
  60          $result = spip_query($query);
  61  
  62          if ($etape_en_cours > 0){
  63              if ($type == "forum"){
  64                  $total = spip_num_rows($result);
  65                  if ($total > 5000){
  66                      $result = spip_query($query." LIMIT $debut_limit, 5000");
  67                      $debut_limit = $debut_limit + 5000;
  68                      if ($debut_limit > $total) {
  69                          $debut_limit = 0;
  70                          echo " "._T('info_tous_resultats_enregistres');
  71                      }
  72                      else {
  73                          echo " "._T('info_premier_resultat', array('debut_limit' => $debut_limit, 'total' => $total));
  74                      }
  75                  } 
  76                  else {
  77                      $debut_limit = 0;
  78                  }
  79              }
  80              if ($type == "article"){
  81                  $total = spip_num_rows($result);
  82                  if ($total > 500){
  83                      $result = spip_query($query." LIMIT $debut_limit, 500");
  84                      $debut_limit = $debut_limit + 500;
  85                      if ($debut_limit > $total) {
  86                          $debut_limit = 0;
  87                          echo " "._T('info_tous_resultats_enregistres');
  88                      }
  89                      else {
  90                          echo " "._T('info_premier_resultat_sur', array('debut_limit' => $debut_limit, 'total' => $total));
  91                      }
  92                  } 
  93                  else {
  94                      $debut_limit = 0;
  95                  }
  96              }
  97          
  98          }
  99          
 100          $_fputs = ($gz) ? gzputs : fputs;
 101          $nfields = mysql_num_fields($result);
 102          // Recuperer les noms des champs
 103          for ($i = 0; $i < $nfields; ++$i) $fields[$i] = mysql_field_name($result, $i);
 104          while ($row = spip_fetch_array($result)) {
 105              $string .= build_begin_tag($type) . "\n";
 106              // Exporter les champs de la table
 107              for ($i = 0; $i < $nfields; ++$i) {
 108                  $string .= '<'.$fields[$i].'>' . text_to_xml($row[$i]) . '</'.$fields[$i].'>' . "\n";
 109              }
 110              // Exporter les relations
 111              if ($type == 'article') {
 112                  $query = 'SELECT id_auteur FROM spip_auteurs_articles WHERE id_article='.$row[0];
 113                  $res2 = spip_query($query);
 114                  while($row2 = spip_fetch_array($res2)) {
 115                      $string .= '<lien:auteur>' . $row2['id_auteur'] . '</lien:auteur>' . "\n";
 116                  }
 117                  spip_free_result($res2);
 118                  $query = 'SELECT id_document FROM spip_documents_articles WHERE id_article='.$row[0];
 119                  $res2 = spip_query($query);
 120                  while($row2 = spip_fetch_array($res2)) {
 121                      $string .= '<lien:document>' . $row2['id_document'] . '</lien:document>' . "\n";
 122                  }
 123                  spip_free_result($res2);
 124              }
 125              else if ($type == 'message') {
 126                  $query = 'SELECT id_auteur FROM spip_auteurs_messages WHERE id_message='.$row[0];
 127                  $res2 = spip_query($query);
 128                  while($row2 = spip_fetch_array($res2)) {
 129                      $string .= '<lien:auteur>' . $row2['id_auteur'] . '</lien:auteur>' . "\n";
 130                  }
 131                  spip_free_result($res2);
 132              }
 133              else if ($type == 'breve') {
 134                  $query = 'SELECT id_document FROM spip_documents_breves WHERE id_breve='.$row[0];
 135                  $res2 = spip_query($query);
 136                  while($row2 = spip_fetch_array($res2)) {
 137                      $string .= '<lien:document>' . $row2['id_document'] . '</lien:document>' . "\n";
 138                  }
 139                  spip_free_result($res2);
 140              }
 141              else if ($type == 'rubrique') {
 142                  $query = 'SELECT id_document FROM spip_documents_rubriques WHERE id_rubrique='.$row[0];
 143                  $res2 = spip_query($query);
 144                  while($row2 = spip_fetch_array($res2)) {
 145                      $string .= '<lien:document>' . $row2['id_document'] . '</lien:document>' . "\n";
 146                  }
 147                  spip_free_result($res2);
 148                  $query = 'SELECT id_auteur FROM spip_auteurs_rubriques WHERE id_rubrique='.$row[0];
 149                  $res2 = spip_query($query);
 150                  while($row2 = spip_fetch_array($res2)) {
 151                      $string .= '<lien:auteur>' . $row2['id_auteur'] . '</lien:auteur>' . "\n";
 152                  }
 153                  spip_free_result($res2);
 154              }
 155              else if ($type == 'auteur') {
 156                  $query = 'SELECT id_rubrique FROM spip_auteurs_rubriques WHERE id_auteur='.$row[0];
 157                  $res2 = spip_query($query);
 158                  while($row2 = spip_fetch_array($res2)) {
 159                      $string .= '<lien:rubrique>' . $row2['id_rubrique'] . '</lien:rubrique>' . "\n";
 160                  }
 161                  spip_free_result($res2);
 162              }
 163              else if ($type == 'mot') {
 164                  $query = 'SELECT id_article FROM spip_mots_articles WHERE id_mot='.$row[0];
 165                  $res2 = spip_query($query);
 166                  while($row2 = spip_fetch_array($res2)) {
 167                      $string .= '<lien:article>' . $row2['id_article'] . '</lien:article>' . "\n";
 168                  }
 169                  spip_free_result($res2);
 170                  $query = 'SELECT id_breve FROM spip_mots_breves WHERE id_mot='.$row[0];
 171                  $res2 = spip_query($query);
 172                  while($row2 = spip_fetch_array($res2)) {
 173                      $string .= '<lien:breve>' . $row2['id_breve'] . '</lien:breve>' . "\n";
 174                  }
 175                  spip_free_result($res2);
 176                  $query = 'SELECT id_forum FROM spip_mots_forum WHERE id_mot='.$row[0];
 177                  $res3 = spip_query($query);
 178                  while($row3 = spip_fetch_array($res3)) {
 179                      $string .= '<lien:forum>' . $row3['id_forum'] . '</lien:forum>' . "\n";
 180                  }
 181                  spip_free_result($res3);
 182                  $query = 'SELECT id_rubrique FROM spip_mots_rubriques WHERE id_mot='.$row[0];
 183                  $res4 = spip_query($query);
 184                  while($row4 = spip_fetch_array($res4)) {
 185                      $string .= '<lien:rubrique>' . $row4['id_rubrique'] . '</lien:rubrique>' . "\n";
 186                  }
 187                  spip_free_result($res4);
 188                  $query = 'SELECT id_syndic FROM spip_mots_syndic WHERE id_mot='.$row[0];
 189                  $res4 = spip_query($query);
 190                  while($row4 = spip_fetch_array($res4)) {
 191                      $string .= '<lien:syndic>' . $row4['id_syndic'] . '</lien:syndic>' . "\n";
 192                  }
 193                  spip_free_result($res4);
 194              }
 195              $string .= build_end_tag($type) . "\n\n";
 196              if ($file) {
 197                  $_fputs($file, $string);
 198                  $string = '';
 199              }
 200          }
 201          spip_free_result($result);
 202          if (!$file) return $string;
 203      }
 204      else if ($etape_actuelle < $etape_en_cours) {
 205          echo "<li> $nom_etape";
 206      } else {
 207          echo "<li> <font color='#999999'>$nom_etape</font>";
 208      }
 209  }
 210  
 211  
 212  
 213  ?>


Généré le : Thu Feb 22 22:27:47 2007 par Balluche grâce à PHPXref 0.7