[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/inc/ -> import_1_2.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  
  15  // pour le support des vieux dump
  16  // http://doc.spip.org/@inc_import_1_2_dist
  17  function inc_import_1_2_dist($f, $request, $gz='fread') {
  18    global $import_ok;
  19      static $field_desc = array ();
  20  
  21      static $tables, $a_importer;
  22      if (!$tables) {
  23          $init = $request['init'];
  24          $a_importer = $init($request);
  25          $tables = array(
  26          'article' => 'spip_articles',
  27          'auteur' => 'spip_auteurs',
  28          'breve' => 'spip_breves',
  29          'document' => 'spip_documents',
  30          'forum' => 'spip_forum',
  31          'groupe_mots' => 'spip_groupes_mots',
  32          'message' => 'spip_messages',
  33          'mot' => 'spip_mots',
  34          'petition' => 'spip_petitions',
  35          'rubrique' => 'spip_rubriques',
  36          'signature' => 'spip_signatures',
  37          'syndic' => 'spip_syndic',
  38          'syndic_article' => 'spip_syndic_articles',
  39          'type_document' => 'spip_types_documents'
  40          );
  41      }
  42      $import_ok = false;
  43      $b = false;
  44      // Lire le type d'objet
  45      if (!($type = xml_fetch_tag($f, $b, $gz))) return false;
  46      if ($type == '/SPIP') return !($import_ok = true);
  47      $id = "id_$type";
  48      $id_objet = 0;
  49  
  50      $table = isset($tables[$type]) ? $tables[$type] : $type;
  51      if (in_array($table, $a_importer) AND !isset($field_desc[$table])) {
  52          // recuperer la description de la table pour connaitre ses champs valides
  53          list($nom,$desc) = description_table($table);
  54  
  55          if (isset($desc['field']))
  56              $field_desc[$table] = $desc['field'];
  57          else
  58              $field_desc[$table] = NULL;
  59      }
  60      $fields = $field_desc[$table];
  61  
  62      $char = $GLOBALS['meta']['charset_insertion'];
  63      if ($char == $GLOBALS['meta']['charset_restauration']) $char = '';
  64  
  65      $values = array();
  66      // Lire les champs de l'objet
  67      for (;;) {
  68          $b = false;
  69          if (!($col = xml_fetch_tag($f, $b, $gz))) return false;
  70          if ($col == '/'.$type) break;
  71          $value = true;
  72          if (!xml_fetch_tag($f, $value, $gz)) return false;
  73          if (substr($col, 0, 5) == 'lien:') {
  74              $type_lien = substr($col, 5);
  75              $liens[$type_lien][] = '('.$id_objet.','.$value.')';
  76          }
  77          else if ($col != 'maj') {
  78              // tentative de restauration d'une base sauvegardee avec le champ 'images' ; d'experience, ca arrive...
  79              // mieux vaut accepter que canner silencieusement...
  80              if (($type == 'article') && ($col == 'images'))
  81              {
  82                  if ($value) {        // ne pas afficher de message si on a un champ suppl mais vide
  83                      echo "--><br /><span style='color: red; font-weight: bold;'>"._T('avis_erreur_sauvegarde', array('type' => $type, 'id_objet' => $id_objet))."</span>\n<span style='color: black'>"._T('avis_colonne_inexistante', array('col' => $col));
  84                      if ($col == 'images') echo _T('info_verifier_image');
  85                      echo "</span>\n<!--";
  86                      $GLOBALS['erreur_restauration'] = true;
  87                  }
  88              }
  89              else if ($fields==NULL or isset($fields[$col])) {
  90                  if ($char) 
  91                      $value = importer_charset($value, $charset);
  92                  $values[$col] = $value;
  93                  if ($col == $id) $id_objet = $value;
  94              }
  95          }
  96      }
  97     if ($values) {
  98      if (!spip_query("REPLACE $table (" . join(',', array_keys($values)) . ') VALUES (' . join(',', array_map('_q', $values)) . ')')) {
  99          echo "--><br /><span style='color: red; font-weight: bold;'>"._T('avis_erreur_mysql')."</span>\n<span style='color: black'><tt>".spip_sql_error()."</tt></span>\n<!--";
 100          $GLOBALS['erreur_restauration'] = true;
 101      }
 102  
 103      if ($type == 'article') {
 104          spip_query("DELETE FROM spip_auteurs_articles WHERE id_article=$id_objet");
 105          spip_query("DELETE FROM spip_documents_articles WHERE id_article=$id_objet");
 106      }
 107      else if ($type == 'rubrique') {
 108          spip_query("DELETE FROM spip_auteurs_rubriques WHERE id_rubrique=$id_objet");
 109          spip_query("DELETE FROM spip_documents_rubriques WHERE id_rubrique=$id_objet");
 110      }
 111      else if ($type == 'breve') {
 112          spip_query("DELETE FROM spip_documents_breves WHERE id_breve=$id_objet");
 113      }
 114      else if ($type == 'mot') {
 115          spip_query("DELETE FROM spip_mots_articles WHERE id_mot=$id_objet");
 116          spip_query("DELETE FROM spip_mots_breves WHERE id_mot=$id_objet");
 117          spip_query("DELETE FROM spip_mots_forum WHERE id_mot=$id_objet");
 118          spip_query("DELETE FROM spip_mots_rubriques WHERE id_mot=$id_objet");
 119          spip_query("DELETE FROM spip_mots_syndic WHERE id_mot=$id_objet");
 120      }
 121      else if ($type == 'auteur') {
 122          spip_query("DELETE FROM spip_auteurs_rubriques WHERE id_auteur=$id_objet");
 123      }
 124      else if ($type == 'message') {
 125          spip_query("DELETE FROM spip_auteurs_messages WHERE id_message=$id_objet");
 126      }
 127      if ($liens) {
 128          reset($liens);
 129          while (list($type_lien, $t) = each($liens)) {
 130              if ($type == 'auteur' OR $type == 'mot' OR $type == 'document')
 131                  if ($type_lien == 'syndic' OR $type_lien == 'forum') $table_lien = 'spip_'.$type.'s_'.$type_lien;
 132                  else $table_lien = 'spip_'.$type.'s_'.$type_lien.'s';
 133              else
 134                  $table_lien = 'spip_'.$type_lien.'s_'.$type.'s';
 135              spip_abstract_insert($table_lien, "($id, id_$type_lien)", join(',', $t));
 136          }
 137      }
 138     }
 139     return $import_ok = "    ";
 140  }
 141  
 142  ?>


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