[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/inc/ -> suivi_versions.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  include_spip('inc/revisions');
  16  include_spip('inc/diff');
  17  
  18  // http://doc.spip.org/@afficher_para_modifies
  19  function afficher_para_modifies ($texte, $court = false) {
  20      // Limiter la taille de l'affichage
  21      if ($court) $max = 200;
  22      else $max = 2000;
  23      
  24      $paras = explode ("\n",$texte);
  25      for ($i = 0; $i < count($paras) AND strlen($texte_ret) < $max; $i++) {
  26          if (strpos($paras[$i], '"diff-')) $texte_ret .= $paras[$i]."\n\n";
  27  #        if (strlen($texte_ret) > $max) $texte_ret .= '(...)';
  28      }
  29      $texte = $texte_ret;
  30      return $texte;
  31  }
  32  
  33  // http://doc.spip.org/@afficher_suivi_versions
  34  function afficher_suivi_versions ($debut = 0, $id_secteur = 0, $uniq_auteur = false, $lang = "", $court = false, $rss = false) {
  35      global $dir_lang;
  36      
  37      $nb_aff = 10;
  38      $champs = array('surtitre', 'titre', 'soustitre', 'descriptif', 'nom_site', 'url_site', 'chapo', 'texte', 'ps');
  39  
  40      if ($uniq_auteur) {
  41          $req_where = " AND articles.statut IN ('prepa','prop','publie')"; 
  42          $req_where .= " AND versions.id_auteur = $uniq_auteur";
  43      } else {
  44          $req_where = " AND articles.statut IN ('prop','publie')";
  45      }
  46      
  47      if (strlen($lang) > 0)
  48          $req_where .= " AND articles.lang=" . _q($lang);
  49  
  50      if ($id_secteur > 0)
  51          $req_where .= " AND articles.id_secteur = ".intval($id_secteur);
  52  
  53      $req_where = "versions.id_article = articles.id_article AND versions.id_version > 1 $req_where";
  54  
  55      $result = spip_query("SELECT versions.*, articles.statut, articles.titre FROM spip_versions AS versions, spip_articles AS articles WHERE $req_where ORDER BY versions.date DESC LIMIT $debut, $nb_aff");
  56  
  57      if (spip_num_rows($result) > 0) {
  58  
  59          $revisions = '';
  60  
  61          // Afficher l'entete de la boite
  62          if (!$rss) {
  63              $titre_table =  '<b>' . _T('icone_suivi_revisions').aide('suivimodif')  . '</b>';
  64              if ($court)
  65                  $titre_table = afficher_plus(generer_url_ecrire("suivi_revisions"))
  66                  . $titre_table;
  67  
  68              $revisions .= "\n<div style='height: 12px;'></div>";
  69              $revisions .= "\n<div class='liste'>";
  70              $revisions .= bandeau_titre_boite2($titre_table, "historique-24.gif", "white", "black", false);
  71      
  72              $total = spip_num_rows(spip_query("SELECT versions.*, articles.statut, articles.titre FROM spip_versions AS versions, spip_articles AS articles WHERE $req_where LIMIT 0, 149"));
  73          
  74              if ($total > $nb_aff) {
  75                  $nb_tranches = ceil($total / $nb_aff);
  76              
  77                  $revisions .= "\n<div class='arial2' style='background-color: #dddddd; padding: 5px;'>";
  78          
  79                  for ($i = 0; $i < $nb_tranches; $i++) {
  80                      if ($i > 0) $revisions .= " | ";
  81                      if ($i*$nb_aff == $debut) $revisions .= "<b>";
  82                      else {
  83                        $next = ($i * $nb_aff);
  84  $revisions .= "<a href='".generer_url_ecrire('suivi_revisions', "debut=$next&id_secteur=$id_secteur&id_auteur=$uniq_auteur&lang_choisie=$lang")."'>";
  85                      }
  86                      $revisions .= (($i * $nb_aff) + 1);
  87                      if ($i*$nb_aff == $debut) $revisions .= "</b>";
  88                      else $revisions .= "</a>";
  89                  }
  90                  $revisions .= "</div>";
  91              }
  92          }
  93  
  94          // Afficher les 10 elements
  95          while ($row = spip_fetch_array($result)) {
  96              $id_version = $row['id_version'];
  97              $id_auteur = $row['id_auteur'];
  98              $date = $row['date'];
  99              $id_article = $row['id_article'];
 100              if (autoriser('voir','article',$id_article)){
 101                  $statut = $row['statut'];
 102                  $titre = typo($row['titre']);
 103                  
 104                  // l'id_auteur peut etre un numero IP (edition anonyme)
 105                  if ($id_auteur == intval($id_auteur)
 106                  AND $row_auteur = spip_fetch_array(spip_query("SELECT nom,email FROM spip_auteurs    WHERE id_auteur = '".addslashes($id_auteur)."'"))) {
 107                      $nom = typo($row_auteur["nom"]);
 108                      $email = $row_auteur['email'];
 109                  } else {
 110                      $nom = $id_auteur;
 111                      $email = '';
 112                  }
 113          
 114                  if (!$rss) {
 115                      $logo_statut = "puce-".puce_statut($statut).".gif";
 116                      $revisions .= "\n<div class='tr_liste' style='padding: 5px; border-top: 1px solid #aaaaaa;'>";
 117          
 118                      $revisions .= "<span class='arial2'>";
 119                      if (!$court) $revisions .= bouton_block_visible("$id_version-$id_article-$id_auteur");
 120                      $revisions .= "<img src='" . _DIR_IMG_PACK . "$logo_statut' alt=' ' />&nbsp;";
 121                      $revisions .= "<a class='$statut' style='font-weight: bold;' href='" . generer_url_ecrire("articles_versions","id_article=$id_article") . "'>$titre</a>";
 122                      $revisions .= "</span>";
 123                      $revisions .= "<span class='arial1'$dir_lang>";
 124                      $revisions .= " ".date_relative($date)." "; # laisser un peu de privacy aux redacteurs
 125                      if (strlen($nom)>0) $revisions .= "($nom)";
 126                      $revisions .= "</span>";
 127                  } else {
 128                      $item = array(
 129                          'title' => $titre,
 130                          'url' => generer_url_ecrire("articles_versions","id_article=$id_article&id_version=$id_version"),
 131                          'date' => $date,
 132                          'author' => $nom,
 133                          'email' => $email
 134                      );
 135                  }
 136      
 137                  // "court" n'affiche pas les modifs
 138                  if (!$court) {
 139                      $textes = revision_comparee($id_article, $id_version, 'diff');
 140                      if (!$rss)
 141                          $revisions .= debut_block_visible("$id_version-$id_article-$id_auteur");
 142      
 143                      if (is_array($textes))
 144                      foreach ($textes as $var => $t) {
 145                          if (strlen($t) > 0) {
 146                              if (!$rss) $revisions .= "<blockquote class='serif1'>";
 147                              $aff = propre_diff($t);
 148                              if ($GLOBALS['les_notes']) {
 149                                  $aff .= '<p>'.$GLOBALS['les_notes'];
 150                                  $GLOBALS['les_notes'] = '';
 151                              }
 152                              if (!$rss) {
 153                                  $revisions .= $aff;
 154                                  $revisions .= "</blockquote>";
 155                              } else
 156                                  $item['description'] = $aff;
 157                          }
 158                      }
 159                      if (!$rss) $revisions .= fin_block();
 160                  }
 161                  
 162                  if (!$rss) $revisions .= "</div>";
 163      
 164                  if ($rss)
 165                      $items[] = $item;
 166              }
 167          }        
 168          if (!$rss) $revisions .= "</div>";
 169      }
 170  
 171      if ($rss)
 172          return $items;
 173      else return $revisions;
 174  }
 175  
 176  // retourne un array() des champs modifies a la version id_version
 177  // le format =
 178  //    - diff => seulement les modifs (suivi_revisions)
 179  //    - apercu => idem, mais en plus tres cout s'il y en a bcp
 180  //    - complet => tout, avec surlignage des modifications (articles_versions)
 181  // http://doc.spip.org/@revision_comparee
 182  function revision_comparee($id_article, $id_version, $format='diff', $id_diff=NULL) {
 183      include_spip('inc/diff');
 184  
 185      // chercher le numero de la version precedente
 186      if (!$id_diff) {
 187          $result_diff = spip_query("SELECT id_version FROM spip_versions WHERE id_article=$id_article AND id_version<$id_version ORDER BY id_version DESC LIMIT 0,1");
 188          if ($result_diff) {
 189              $row_diff = spip_fetch_array($result_diff);
 190              $id_diff = $row_diff['id_version'];
 191          }
 192      }
 193  
 194      if ($id_version && $id_diff) {
 195  
 196          // si l'ordre est inverse, on remet a l'endroit
 197          if ($id_diff > $id_version) {
 198              $t = $id_version;
 199              $id_version = $id_diff;
 200              $id_diff = $t;
 201          }
 202  
 203          $old = recuperer_version($id_article, $id_diff);
 204          $new = recuperer_version($id_article, $id_version);
 205  
 206          $textes = array();
 207  
 208          // Mode "diff": on ne s'interesse qu'aux champs presents dans $new
 209          // Mode "complet": on veut afficher tous les champs
 210          switch ($format) {
 211              case 'complet':
 212                  $champs = array('surtitre', 'titre', 'soustitre', 'descriptif', 'nom_site', 'url_site', 'chapo', 'texte', 'ps');
 213                  break;
 214              case 'diff':
 215              case 'apercu':
 216              default:
 217                  $champs = array_keys($new);
 218                  break;
 219          }
 220  
 221          foreach ($champs as $champ) {
 222              // si la version precedente est partielle,
 223              // il faut remonter dans le temps
 224              $id_ref = $id_diff-1;
 225              while (!isset($old[$champ])
 226              AND $id_ref>0) {
 227                  $prev = recuperer_version($id_article, $id_ref--);
 228                  if (isset($prev[$champ]))
 229                      $old[$champ] = $prev[$champ];
 230              }
 231              if (!strlen($new[$champ]) && !strlen($old[$champ])) continue;
 232  
 233              // si on n'a que le vieux, ou que le nouveau, on ne
 234              // l'affiche qu'en mode "complet"
 235              if ($format == 'complet')
 236                  $textes[$champ] = strlen($new[$champ])
 237                      ? $new[$champ] : $old[$champ];
 238  
 239              // si on a les deux, le diff nous interesse, plus ou moins court
 240              if (isset($new[$champ])
 241              AND isset($old[$champ])) {
 242                  $diff = new Diff(new DiffTexte);
 243                  $n = preparer_diff($new[$champ]);
 244                  $o = preparer_diff($old[$champ]);
 245                  $textes[$champ] = afficher_diff($diff->comparer($n,$o));
 246  
 247                  if ($format == 'diff' OR $format == 'apercu')
 248                      $textes[$champ] = afficher_para_modifies($textes[$champ], ($format == 'apercu'));
 249              }
 250          }
 251      }
 252  
 253      // que donner par defaut ? (par exemple si id_version=1)
 254      if (!$textes)
 255          $textes = recuperer_version($id_article, $id_version);
 256  
 257      return $textes;
 258  }
 259  
 260  ?>


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