[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/exec/ -> export.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  
  14  if (!defined("_ECRIRE_INC_VERSION")) return;
  15  
  16  // Conversion timestamp MySQL (format ascii) en Unix (format integer)
  17  // http://doc.spip.org/@mysql_timestamp_to_time
  18  function mysql_timestamp_to_time($maj)
  19  {
  20      $t_an = substr($maj, 0, 4);
  21      $t_mois = substr($maj, 4, 2);
  22      $t_jour = substr($maj, 6, 2);
  23      $t_h = substr($maj, 8, 2);
  24      $t_min = substr($maj, 10, 2);
  25      $t_sec = substr($maj, 12, 2);
  26      return mktime ($t_h, $t_min, $t_sec, $t_mois, $t_jour, $t_an, 0);
  27  }
  28  
  29  
  30  
  31  // Liste un sommaire d'objets de n'importe quel type
  32  // a la condition d'etre publics et plus recents que $maj
  33  // http://doc.spip.org/@liste_objets
  34  function liste_objets($result, $type, $maj) {
  35  
  36      $res = array();
  37      if ($result)
  38        while ($row = spip_fetch_array($result)) {
  39          $t_id = $row["id_$type"];
  40          $t_statut = $row["statut"];
  41          $t_maj = mysql_timestamp_to_time($row["maj"]);
  42          if (!$maj ||
  43              ($t_maj > $maj && 
  44               (!$t_statut || $t_statut == "publie"))) {
  45            echo "$type $t_id ", ($maj ? $t_maj : ""), "\n";
  46              if ($type == "article") $res[]=$t_id;
  47          }
  48      }
  49      spip_free_result($result);
  50      return $res;
  51  }
  52  
  53  // Liste un sommaire recursif de rubriques
  54  // a condition que la mise a jour soit plus recente que $maj
  55  // http://doc.spip.org/@liste_rubriques
  56  function liste_rubriques($id_rubrique) {
  57      global $maj;
  58      static $rubriques = array();
  59      if ($id_rubrique)
  60          $result = spip_query("SELECT * FROM spip_rubriques WHERE id_rubrique='$id_rubrique'");
  61      else
  62          $result = spip_query("SELECT * FROM spip_rubriques WHERE id_parent=0");
  63  
  64      if ($result) while ($row=spip_fetch_array($result)) {
  65          $id_rubrique = $row['id_rubrique'];
  66          $id_parent = $row['id_parent'];
  67          $titre = $row['titre'];
  68          $descriptif = $row['descriptif'];
  69          $texte = $row['texte'];
  70          $rubrique_maj = mysql_timestamp_to_time($row["maj"]);
  71          if ($rubrique_maj > $maj) {
  72              echo "rubrique $id_rubrique $rubrique_maj\n";
  73          }
  74          $t_rubriques[] = $id_rubrique;
  75          $rubriques[] = $id_rubrique;
  76      }
  77      spip_free_result($result);
  78       if ($t_rubriques) {
  79           $t_rubriques = join(",", $t_rubriques);
  80          liste_rubriques(spip_query("SELECT * FROM spip_rubriques WHERE id_parent IN ($t_rubriques)"));
  81  
  82      }
  83      return $rubriques;
  84  }
  85  
  86  // http://doc.spip.org/@exec_export_dist
  87  function exec_export_dist()
  88  {
  89  
  90      global $id_rubrique, $maj;
  91      $id_rubrique = intval($id_rubrique);
  92  
  93      header("Content-Type: text/plain");
  94  
  95      $rubriques = liste_rubriques($id_rubrique);
  96  
  97      if ($rubriques) {
  98          $rubriques = join(",", $rubriques);
  99  
 100          $query = spip_query("SELECT id_article, statut, maj FROM spip_articles WHERE id_rubrique IN ($rubriques)");
 101          $articles = liste_objets($query, "article", $maj);
 102  
 103          $query = spip_query("SELECT id_breve, statut, maj FROM spip_breves WHERE id_rubrique IN ($rubriques)");
 104          liste_objets($query, "breve", $maj);
 105  
 106          if ($articles) {
 107              $articles = join(",", $articles);
 108  
 109              $query = spip_query("SELECT DISTINCT id_auteur FROM spip_auteurs_articles  WHERE id_article IN ($articles)");
 110              liste_objets($query, "auteur", 0);
 111          }
 112      }
 113  
 114  }
 115  ?>


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