phpDocumentor lodel-source-lodel-edition
[ class tree: lodel-source-lodel-edition ] [ index: lodel-source-lodel-edition ] [ all elements ]

Source for file oochargement.php

Documentation is available at oochargement.php

  1. <?php
  2. /**
  3.  * Chargement d'un document OpenOffice (via ServOO)
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14.  *
  15.  * Home page: http://www.lodel.org
  16.  *
  17.  * E-Mail: lodel@lodel.org
  18.  *
  19.  * All Rights Reserved
  20.  *
  21.  * This program is free software; you can redistribute it and/or modify
  22.  * it under the terms of the GNU General Public License as published by
  23.  * the Free Software Foundation; either version 2 of the License, or
  24.  * (at your option) any later version.
  25.  *
  26.  * This program is distributed in the hope that it will be useful,
  27.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  29.  * GNU General Public License for more details.
  30.  *
  31.  * You should have received a copy of the GNU General Public License
  32.  * along with this program; if not, write to the Free Software
  33.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34.  *
  35.  * @author Ghislain Picard
  36.  * @author Jean Lamy
  37.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  38.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  39.  * @licence http://www.gnu.org/copyleft/gpl.html
  40.  * @version CVS:$Id:
  41.  * @package lodel/source/lodel/edition
  42.  */
  43.  
  44. require_once 'siteconfig.php';
  45. require_once 'auth.php';
  46. require_once 'func.php';
  47. require_once 'utf8.php'// conversion des caracteres
  48.  
  49. if ($_POST{
  50.     $therequest &$_POST;
  51.  else {
  52.     $therequest &$_GET;
  53. }
  54.  
  55. $context['idparent']  intval($therequest['idparent']);
  56. $context['identity']  $therequest['identity'intval($therequest['identity']intval($therequest['iddocument']);
  57. $context['idtask']    $idtask intval($therequest['idtask']);
  58. $context['idtype']    intval($therequest['idtype']);
  59. $context['lodeltags'intval($therequest['lodeltags']);
  60.  
  61. if (!$context['idtask'&& !$context['identity'&& !$context['idtype']{
  62.     header("location: index.php?id="$context['idparent']);
  63.     return;
  64. }
  65.  
  66. if ($_POST['fileorigin'== 'upload' && $_FILES['file1'&& $_FILES['file1']['tmp_name'&& $_FILES['file1']['tmp_name'!= 'none'{
  67.     $file1 $_FILES['file1']['tmp_name'];
  68.     if (!is_uploaded_file($file1)) {
  69.         die(utf8_encode("Le fichier n'est pas un fichier chargé"));
  70.     }
  71.     $sourceoriginale $_FILES['file1']['name'];
  72.     $tmpdir tmpdir()// use here and later.
  73.     $source $tmpdir"/"basename($file1)'-source';
  74.     move_uploaded_file($file1$source)// move first because some provider does not allow operation in the upload dir
  75. elseif ($_POST['fileorigin'== 'serverfile' && $_POST['localfile']{
  76.     $sourceoriginale basename($_POST['localfile']);
  77.     $file1           SITEROOT'upload/'$sourceoriginale;
  78.     $tmpdir          tmpdir()// use here and later.
  79.     $source          $tmpdir"/"basename($file1)'-source';
  80.     copy($file1$source);
  81. else {
  82.     $file1           '';
  83.     $sourceoriginale '';
  84.     $source          '';
  85. }
  86.  
  87. require_once 'servoofunc.php';
  88. $client new ServOO;
  89.  
  90. if ($client->error_message{
  91.     $context['noservoo'true;
  92. else
  93.     if ($file1{
  94.         do {
  95.             // verifie que la variable file1 n'a pas ete hackee
  96.             $t time();
  97.             @chmod($source0666 octdec($GLOBALS['filemask']))
  98.  
  99.             // get the extension...it's indicative only !
  100.             preg_match("/\.(\w+)$/"$sourceoriginale$result);
  101.             $ext $result[1];
  102.  
  103.             $options array('block' => true,    'inline' => true);
  104.             $outformat $sortiexhtml 'W2L-XHTML' 'W2L-XHTMLLodel';
  105.             $xhtml $client->convertToXHTML($source$ext$outformat$tmpdir'',
  106.                                                     $optionsarray('allowextensions' => 'xhtml|jpg|png|gif'),
  107.                                                     'imagesnaming'// callback
  108.                                                     SITEROOT'docannexe/tmp'rand())// base name for the images
  109.             if ($xhtml === false{
  110.                 if (strpos($client->error_message'Not well-formed XML'!== false{
  111.                     $arr preg_split("/\n/"$client->error_message);
  112.                     $l = -3;
  113.                     foreach ($arr as $t{
  114.                         echo $l++," ",$t,"\n";
  115.                     }
  116.                     return;
  117.                 }
  118.  
  119.                 $context['error'utf8_encode("Erreur renvoyée par le ServOO: \""$client->error_message"\"");
  120.                 break;
  121.             }
  122.         if ($sortieoo || $sortiexhtml{
  123.             die(htmlentities($xhtml));
  124.         }
  125.  
  126.         $err lodelprocessing($xhtml);
  127.  
  128.         if ($err{
  129.             $context['error''error in the lodelprocessing function';
  130.             break;
  131.         }
  132.  
  133.         if ($sortiexmloo || $sortie{
  134.             die(htmlentities($xhtml));
  135.         }
  136.  
  137.         require_once 'balises.php';
  138.         $fileconverted $source'.converted';
  139.         if (!writefile($fileconverted$xhtml)) {
  140.             $context['error''unable to write converted file';
  141.             break;
  142.         }
  143.  
  144.         $row                    array();
  145.         $row['fichier']         $fileconverted;
  146.         $row['source']          $source;
  147.         $row['sourceoriginale'magic_stripslashes($sourceoriginale);
  148.         // build the import
  149.         $row['importversion']   =magic_stripslashes($convertretvar['version'])"oochargement $version;";
  150.         if ($context['identity']{
  151.             $row['identity']      $context['identity'];
  152.         else {
  153.             $row['idparent']      $context['idparent'];
  154.             $row['idtype']        $context['idtype'];
  155.         }
  156.         
  157.         require_once 'taskfunc.php';
  158.         $idtask maketask("Import $file1_name"3$row);
  159.  
  160.         header("Location: checkimport.php?idtask="$idtask);
  161.         return;
  162.     while (0)// exceptions
  163. }
  164.  
  165. $context['url''oochargement.php';
  166.  
  167. require_once 'view.php';
  168. $view &View::getView();
  169. $view->render($context'oochargement'!(bool)$_POST);
  170.  
  171.  
  172.  
  173. function imagesnaming($filename$index$uservars)
  174. {
  175.     preg_match("/\.\w+$/"$filename$result)// get extension
  176.     return $uservars"_"$index$result[0];
  177. }
  178.  
  179. function lodelprocessing(&$xhtml)
  180. {
  181.     $xhtml str_replace(array("&#39;""&apos;")array("'""'")$xhtml);
  182.     return false;
  183. }
  184.  
  185. function cleanList($text)
  186. {
  187.     $arr preg_split("/(<\/?(?:ul|ol)\b[^>]*>)/"$text-1PREG_SPLIT_DELIM_CAPTURE);
  188.     $count count($arr);
  189.     $arr[0addList($arr[0]);
  190.     $inlist 0;
  191.     $start 0;
  192.     for($i 1$i $count$i+= 2{
  193.         if ($arr[$i][1== "/"// closing
  194.             $inlist--;
  195.             if ($inlist == 0{
  196.                 $arr[$i].= "</r2r:puces>"
  197.             // end of a list
  198.         else // opening
  199.             if ($inlist == 0{
  200.                 $arr[$i"<r2r:puces>"$arr[$i];
  201.             // beginning of a list
  202.             $inlist++;
  203.         }
  204.         if ($inlist 0// in a list
  205.             $arr[$i+1preg_replace("/<\/?r2r:[^>]+>/"" "$arr[$i+1]);
  206.         else // out of any list
  207.             $arr[$i+1addList($arr[$i+1]);
  208.         }
  209.     }
  210.     $text join(""$arr);
  211.     return preg_replace("/<\/r2r:(puces?)>((?:<\/?(p|br)(?:\s[^>]*)?\/?>|\s)*)<r2r:\\1(?:\s[^>]*)?>/s"// process couple 
  212.                     ""$text);
  213. }
  214.  
  215. function addList($text)
  216. // especially for RTF file where there are some puces but no li
  217.     return preg_replace(array(
  218.                 "/<r2r:(puces?)>(.*?)<\/r2r:\\1>/"// put li
  219.                 "/<\/r2r:(puces?)>((?:<\/?(p|br)(?:\s[^>]*)?\/?>|\s)*)<r2r:\\1(?:\s[^>]*)?>/s"// process couple 
  220.                 "/(<r2r:puces?>)/",  // add ul
  221.                 "/(<\/r2r:puces?>)/" // add /ul
  222.                 ),
  223.                 array("<r2r:\\1><li>\\2</li></r2r:\\1>",
  224.                 "",
  225.                 "\\1<ul>",
  226.                 "</ul>\\1"
  227.                 )$text);
  228. }
  229. ?>

Documentation generated on Wed, 19 Sep 2007 05:07:26 +0200 by phpDocumentor 1.4.0a2