[ 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_diff.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  /** Lib de fonctions dédiées au diff d'articles (fonctionnalité de Spip-Agora : "Historique")
  20   * @version    $Id$
  21   * @author     trivoallan
  22   */
  23  
  24  /** Renvoie la différence formattée en html entre deux articles
  25   * @param      object article      Article avant modifications
  26   * @param      object article      Article après modifications
  27   * @return     string 
  28   */
  29  function getDiffHtml ($article_from, $article_to) {
  30      checkForDependencies()or die(_T('dependance_manquante'). ' : le package PEAR Text_Diff');
  31  
  32      // Chargement des librairies nécessaires
  33      require_once("Text/Diff/Renderer.php");
  34      require_once dirname(__FILE__). '/include/diff/Renderer_Spip.php';
  35  
  36      // Computation des diffs -- on récupère une instance de Text_Diff pour chaque elément de l'article
  37      $diffs = array();
  38  
  39      if (lire_meta('articles_surtitre') == 'oui')
  40          $diffs['surtitre'] = getDiff($article_from->getSurtitre(), $article_to->getSurtitre());
  41  
  42      if (lire_meta('articles_soustitre') == 'oui')
  43          $diffs['soustitre'] = getDiff($article_from->getSousTitre(), $article_to->getSousTitre());
  44  
  45      if (lire_meta('articles_descriptif') == 'oui')
  46          $diffs['descriptif'] = getDiff($article_from->getDescriptif(), $article_to->getDescriptif());
  47  
  48      if (lire_meta('articles_chapeau') == 'oui')
  49          $diffs['chapo'] = getDiff($article_from->getChapo(), $article_to->getChapo());
  50  
  51      if (lire_meta('articles_ps') == 'oui')
  52          $diffs['ps'] = getDiff($article_from->getPs(), $article_to->getPs());
  53  
  54      $diffs['titre'] = getDiff($article_from->getTitre(), $article_to->getTitre());
  55      $diffs['texte'] = getDiff($article_from->getTexte(), $article_to->getTexte());
  56  
  57      // Site lié
  58      if ($article_from->_nomSite || $article_to->_nomSite) {
  59          $diffs['site'] = getDiff($article_from->_nomSite . '|' . $article_from->_urlSite,
  60                                   $article_to->_nomSite . '|' . $article_to->_urlSite);
  61      }
  62  
  63      // Extras
  64      if ($extras_from = $article_from->getExtra() && is_array($extras_from)) {
  65          $extras_to = unserialize($article_to->getExtra());
  66          $extras_from = unserialize($extras_from);
  67          foreach ($extras_from as $extra_k => $extra_v) {
  68              $diffs['extras'][] = getDiff("<strong>$extra_k :</strong> $extra_v",
  69                                           "<strong>$extra_k :</strong> " . $extras_to[$extra_k]. '<br />');
  70          }
  71      }
  72  
  73      // Formatage 
  74      // YUCK !
  75      $renderer = new Text_Diff_Renderer_Spip;
  76      $str = array();
  77      $GLOBALS['sa_type_data'] = 'surtitre';
  78      $str[] = is_object($diffs['surtitre']) ? $renderer->render($diffs['surtitre']) : '';
  79      $GLOBALS['sa_type_data'] = 'titre';
  80      $str[] = is_object($diffs['titre']) ? $renderer->render($diffs['titre']) : '';
  81      $str[] = '<br />';
  82      $GLOBALS['sa_type_data'] = 'descriptif';
  83      $str[] = is_object($diffs['descriptif']) ? '<p>' . $renderer->render($diffs['descriptif']). '</p>' : '';
  84      $str[] = '<br />';
  85      $GLOBALS['sa_type_data'] = 'site';
  86      $str[] = is_object($diffs['site']) ? $renderer->render($diffs['site']) : '';
  87      $GLOBALS['sa_type_data'] = 'chapo';
  88      $str[] = is_object($diffs['chapo']) ? '<p>' . $renderer->render($diffs['chapo']). '</p>' : '';
  89      $GLOBALS['sa_type_data'] = 'texte';
  90      $str[] = is_object($diffs['texte']) ? $renderer->render($diffs['texte']) : '';
  91      $GLOBALS['sa_type_data'] = 'ps';
  92      $str[] = is_object($diffs['ps']) ? '<p>' . $renderer->render($diffs['ps']). '</p>' : '';
  93      $GLOBALS['sa_type_data'] = 'extra';
  94  
  95      if (isset($diffs['extras']) && is_array($diffs['extras'])) {
  96          foreach ($diffs['extras'] as $extra) {
  97              $str[] = is_object($extra) ? $renderer->render($extra) : '';
  98          }
  99      }
 100  
 101      return implode("\n", $str);
 102  }
 103  
 104  /** Renvoie une instance de Text_Diff 
 105   * @return      object Text_Diff
 106   */
 107  function getDiff ($str_from, $str_to) {
 108      // Chargement des librairies nécessaires
 109      require_once("Text/Diff.php");
 110      $diff = new Text_Diff(explode("\n", $str_from), explode("\n", $str_to));
 111      return $diff;
 112  }
 113  
 114  /** Vérifie la présence des dépendences nécessaires au bon fonctionnement de l'appli. repompé de install.php
 115   * @todo    Rendre plus générique (liste de dépendences en paramètre) et placer dans une lib appropriée.
 116   * @return  bool
 117   */
 118  function checkForDependencies () {
 119  
 120      //Liste des fichiers du package PEAR nécessaires à l'installation d'AGORA
 121      $liste_fichier_pear = array('Text/Diff.php');
 122  
 123      //Pour l'instant il ne manque aucun fichier     
 124      $liste_fichier_manquant = NULL;
 125  
 126      //utilisation des chemins déclarés dans les options : les include_path        
 127      // gestion du PATH_SEPARATOR 
 128      if (!defined("PATH_SEPARATOR")) {
 129          if (eregi('Win', getenv('SERVER_SOFTWARE'))) {
 130              define("PATH_SEPARATOR", ";");
 131          }
 132          else {
 133              define("PATH_SEPARATOR", ':');
 134          }
 135      }
 136  
 137      //On crée la liste des chemins d'accés des fichiers
 138      $path_package = ini_get('include_path');
 139      $tableau_chemin = explode(PATH_SEPARATOR, $path_package);
 140  
 141      // Pour chaque fichier pear nécessaire, on regarde dans tous les chemins si on peut les ouvrir
 142      //On place les fichiers ouvert avec succées dans le tableau des fichier_ouvert
 143      foreach ($liste_fichier_pear as $fichier) {
 144          foreach ($tableau_chemin as $chemin) {
 145              if (substr($chemin, strlen($chemin) - 1, 1) != '/')
 146                  $chemin .= '/';
 147              if ($handler = file_exists($chemin . $fichier)) {
 148                  $fichier_ouvert[] = $fichier;
 149              }
 150          }
 151      }
 152  
 153      //On parcourt à nouveau la liste des fichiers nécessaire 
 154      //et on fait la différence avec ceux qui sont stockés dans $fichier_vouert
 155      foreach ($liste_fichier_pear as $fichier) {
 156          if (!in_array($fichier, $fichier_ouvert))
 157              $liste_fichier_manquant[] = $fichier;
 158      }
 159  
 160      return !count($liste_fichier_manquant);
 161  }
 162  
 163  /** Renvoie une ligne de tableau html comprenant une cellule par élément du tableau $tab
 164   * @param     array    $tab
 165   * @param     string   $del    type de cellule
 166   * */
 167  function ligne ($tab, $del = 'td') {
 168      $str = '<tr>';
 169  
 170      foreach ($tab as $val) {
 171          $str .= '<' . $del . '>' . $val . '</' . $del . '>';
 172      }
 173  
 174      return $str . '</tr>';
 175  }
 176  
 177  function debut_tableau () {
 178      echo '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
 179  }
 180  
 181  function fin_tableau () {
 182      echo '</table>';
 183  }
 184  ?>


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