phpDocumentor lodel-logic
[ class tree: lodel-logic ] [ index: lodel-logic ] [ all elements ]

Source for file class.xml.php

Documentation is available at class.xml.php

  1. <?php
  2. /**
  3.  * Logique des fonctionnalités XML
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Home page: http://www.lodel.org
  10.  * E-Mail: lodel@lodel.org
  11.  *
  12.  * All Rights Reserved
  13.  *
  14.  * This program is free software; you can redistribute it and/or modify
  15.  * it under the terms of the GNU General Public License as published by
  16.  * the Free Software Foundation; either version 2 of the License, or
  17.  * (at your option) any later version.
  18.  *
  19.  * This program is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  * GNU General Public License for more details.
  23.  *
  24.  * You should have received a copy of the GNU General Public License
  25.  * along with this program; if not, write to the Free Software
  26.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  *
  28.  * @package lodel/logic
  29.  * @author Ghislain Picard
  30.  * @author Jean Lamy
  31.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  32.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  33.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  34.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  35.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  36.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  37.  * @licence http://www.gnu.org/copyleft/gpl.html
  38.  * @since Fichier ajouté depuis la version 0.8
  39.  * @version CVS:$Id: class.xml.php 4006 2007-10-05 11:53:41Z malafosse $
  40.  */
  41.  
  42. /**
  43.  * Classe de logique des fonctionnalités XML
  44.  * 
  45.  * @package lodel/logic
  46.  * @author Ghislain Picard
  47.  * @author Jean Lamy
  48.  * @copyright 2001-2002, Ghislain Picard, Marin Dacos
  49.  * @copyright 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  50.  * @copyright 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  51.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  52.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  53.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  54.  * @licence http://www.gnu.org/copyleft/gpl.html
  55.  * @since Classe ajouté depuis la version 0.8
  56.  * @see logic.php
  57.  */
  58. class XMLLogic extends Logic {
  59.  
  60.     /** 
  61.     * Constructor
  62.     */
  63.     function XMLLogic ({
  64.         $this->Logic ("translations");
  65.     }
  66.     
  67.     /**
  68.     * Generate the XML for an entity.
  69.     * Must have context['id'] given
  70.     */
  71.     function generateXMLAction (&$context&$error{
  72.  
  73.         if (!$context['id'])
  74.             die ('ERROR : no id given. Id attribute is required to generate XML file');
  75.  
  76.         global $db;
  77.         $id=$context['id'];
  78.         //check if the given id is OK
  79.         $row $db->getOne(lq("SELECT 1 FROM #_TP_objects WHERE id='$idAND class='entities'"));
  80.         if (!$row{//if the object is not an entity do not generate XML
  81.             header ("Location: not-found.html")return;
  82.         }
  83.         $row $db->getRow(lq("SELECT e.id,t.type,t.class FROM #_TP_entities as e, #_TP_types as t WHERE e.id='$idAND e.idtype=t.id"));
  84.         if (!$rowdie("Error. Type and Class unknown for this entity");
  85.         
  86.         $context['class'$class $row['class'];
  87.         $context['type'$row['type'];
  88.         $context['identity'$id;
  89.  
  90.         require_once ("xmlfunc.php");
  91.         $context['contents'=  $contents calculateXML ($context);
  92.         // !! BEWARE !!
  93.         // validation shall be implemented in ServOO first. The code here comes from the 0.7 and is not adapted to the lodel 0.8 and higher.
  94.         //
  95.     // validation needed
  96. //    if ($context['valid']) {
  97. //      $contents .= $contents;
  98. //      $tmpdir = tmpdir ();
  99. //      $tmpfile = tempnam ($tmpdir, "lodelxml_");
  100. //      writefile($tmpfile.".xml",$contents);
  101. //      $contents=calculateXMLSchema ($context);
  102. //      writefile ($tmpfile.".xsd", $contents);
  103. //      if ($zipcmd && $zipcmd!="pclzip") { // ZIP command
  104. //    $errfile=$tmpfile.".err";
  105. //    system($zipcmd." $tmpfile.zip $tmpfile.xsd $tmpfile.xml  1>&2 2>$errfile");
  106. //    if (filesize($errfile)>0) 
  107. //      die ("ERROR: $errormsg<br />".str_replace ("\n","<br>", htmlentities (@join ("", @file ($errfile)))));
  108. //    @unlink("$tmpfile.err");
  109. //      }    else {// PCLZIP library. 
  110. //    require ("pclzip.lib.php");
  111. //    $archive = new PclZip ($tmpfile.".zip");
  112. //    $v_list = $archive->create (array($tmpfile.".xsd", $tmpfile.".xml"));
  113. //    if ($v_list == 0) die ("ERROR : ".$archive->errorInfo(true));
  114. //      }
  115. //      require ("servoofunc.php");
  116. //      $client = new ServOO ();
  117. //      if ($client->error_message) {
  118. //          if ($context['url']) $error['url']='+';
  119. //          if ($context['username'])$error['username']='+';
  120. //          if ($context['passwd']) $error['passwd']='+';
  121. //      }
  122. //      $ret = $client->validateXML("","");
  123. //      echo "ret=$ret";
  124. //      if ($ret=="noservoo") 
  125. //    $ret="Aucun ServOO n'est configur&eacute; pour r&eacute;aliser la conversion. " .
  126. //      "Vous pouvez faire la configuration dans les options du site (Administrer/Options)";
  127. //  
  128. //      @unlink ($tmpfile.".zip");
  129. //      $context['reponse'] = str_replace ("\n","<br />", htmlentities($ret));
  130. //      require_once ("calcul-page.php");
  131. //      calcul_page ($context,"xml-valid");
  132. //      exit (0);
  133. //    }    else 
  134.         if ($context['view'])    {
  135.             return "_ok";
  136.         else  {// "download"
  137.             download ("""$class-$id.xml"$contents);
  138.         }
  139.     }
  140.     /**
  141.     * Generate the XSD Schema for a class
  142.     * Must have context['class'] given
  143.     */
  144.     function generateXSDAction (&$context&$error{
  145.         
  146.         if (!$context['class'])
  147.             die ('ERROR: no class given. Class attribute is required to generate XSD Schema');
  148.         require('xmlfunc.php');
  149.         //verif if the given class is OK
  150.         global $db;
  151.         $class $context['class'];
  152.         $row $db->getOne (lq ("SELECT id FROM #_TP_classes WHERE class='$class'"));
  153.         if (!$row{
  154.             header ("Location: not-found.html")return;
  155.         }
  156.         $originalname $context['site']'-'.$context['class']'-schema-xml.xsd';
  157.         $ret calculateXMLSchema ($context);
  158.         download (""$originalname$ret);
  159.     }
  160. }
  161. ?>

Documentation generated on Thu, 24 Jul 2008 05:08:24 +0200 by phpDocumentor 1.4.0a2