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

Source for file generateform.php

Documentation is available at generateform.php

  1. <?php
  2. /**
  3.  * Fichier utilitaire pour la génération des formulaires
  4.  *
  5.  * Ce fichier permet de générer les formulaires d'édition de la partie administration de Lodel.
  6.  * Il se base sur le fichier init-site.xml (qui contient la description des tables et des champs
  7.  * et sur le fichier forms.xsl qui est une feuille de style XSLT.
  8.  *
  9.  * Ce script est ŕ lancer en ligne de commande
  10.  *
  11.  * PHP versions 4 et 5
  12.  *
  13.  * LODEL - Logiciel d'Edition ELectronique.
  14.  *
  15.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  16.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  17.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  18.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  19.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  20.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  21.  *
  22.  * Home page: http://www.lodel.org
  23.  *
  24.  * E-Mail: lodel@lodel.org
  25.  *
  26.  * All Rights Reserved
  27.  *
  28.  * This program is free software; you can redistribute it and/or modify
  29.  * it under the terms of the GNU General Public License as published by
  30.  * the Free Software Foundation; either version 2 of the License, or
  31.  * (at your option) any later version.
  32.  *
  33.  * This program is distributed in the hope that it will be useful,
  34.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36.  * GNU General Public License for more details.
  37.  *
  38.  * You should have received a copy of the GNU General Public License
  39.  * along with this program; if not, write to the Free Software
  40.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  41.  *
  42.  * @author Ghislain Picard
  43.  * @author Jean Lamy
  44.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  45.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  46.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  47.  * @licence http://www.gnu.org/copyleft/gpl.html
  48.  * @version CVS:$Id:
  49.  * @package lodel/install
  50.  */
  51.  
  52. /*
  53.  Requires PHP5, uses included XSL extension (to be enabled).
  54.  To be used in PHP4 scripts using XSLT extension.
  55.  Allows PHP4/XSLT scripts to run on PHP5/XSL
  56.  
  57.  Typical use:
  58.  {
  59.   if (version_compare(PHP_VERSION,'5','>=')&&extension_loaded('xsl'))
  60.    require_once('xslt-php4-to-php5.php');
  61.  }
  62.  
  63.  Version 0.5, 2006-08-06, http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
  64.  
  65.  ------------------------------------------------------------------
  66.  Written by Alexandre Alapetite, http://alexandre.alapetite.net/cv/
  67.  
  68. Copyright 2004-2006, Licence: Creative Commons "Attribution-ShareAlike 2.0 France" BY-SA (FR),
  69.  http://creativecommons.org/licenses/by-sa/2.0/fr/
  70.  http://alexandre.alapetite.net/divers/apropos/#by-sa
  71.  - Attribution. You must give the original author credit
  72.  - Share Alike. If you alter, transform, or build upon this work,
  73.    you may distribute the resulting work only under a license identical to this one
  74.    (Can be included in GPL/LGPL projects)
  75.  - The French law is authoritative
  76.  - Any of these conditions can be waived if you get permission from Alexandre Alapetite
  77.  - Please send to Alexandre Alapetite the modifications you make,
  78.    in order to improve this file for the benefit of everybody
  79.  
  80.  If you want to distribute this code, please do it as a link to:
  81.  http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
  82. */
  83. // compatibilité PHP5
  84. $xslArgs=null;
  85. function xslt_create({return new xsltprocessor();}
  86. function xslt_errno($xh{return 7;}
  87. function xslt_error($xh{return '?';}
  88. function xslt_free($xh{unset($xh);}
  89. function xslt_process($xh,$xmlcontainer,$xslcontainer,$resultcontainer=null,$arguments=array(),$parameters=array())
  90. {//See also: http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/
  91.  //Based on: http://www.php.net/manual/ref.xsl.php#45415
  92.  $xml=new DOMDocument();
  93.  $basedir=$xh->getParameter('sablotron','xslt_base_dir');
  94.  if ($basedir && ($workdir=getcwd()))
  95.   chdir($basedir);
  96.  if (substr($xmlcontainer,0,4)=='arg:')
  97.   $xml->loadXML($arguments[substr($xmlcontainer,4)]);
  98.  else $xml->load($xmlcontainer);
  99.  $xsl=new DOMDocument();
  100.  if (substr($xslcontainer,0,4)=='arg:')
  101.   $xsl_=&$arguments[substr($xslcontainer,4)];
  102.  else $xsl_=file_get_contents($xslcontainer);
  103.  $xsl->loadXML(str_replace('arg:/','arg://',$xsl_));
  104.  $xh->importStyleSheet($xsl);
  105.  global $xslArgs;
  106.  $xslArgs=$arguments;
  107.  foreach ($parameters as $param=>$value)
  108.   $xh->setParameter('',$param,$value);
  109.  $result=$xh->transformToXML($xml);
  110.  if (isset($resultcontainer))
  111.   file_put_contents($resultcontainer,$result)
  112.  if ($basedir && $workdir)
  113.   chdir($workdir);
  114.  if (isset($resultcontainer))
  115.   return true;
  116.  else return $result;
  117. }
  118. function xslt_set_base($xh,$base{$xh->setParameter('sablotron','xslt_base_dir',str_replace('file://','',$base));}
  119. function xslt_set_encoding($xh,$encoding{//Manual encoding, or use xsl:output @encoding in XSL document
  120. function xslt_set_error_handler($xh,$handler{}
  121.  
  122. {
  123.  public $position;
  124.  private $xslArg;
  125.  function stream_eof({return $this->position>=strlen($this->xslArg);}
  126.  function stream_open($path,$mode,$options,&$opened_path)
  127.  {
  128.   $this->position=0;
  129.   $url=parse_url($path);
  130.   $varname=$url['host'];
  131.   global $xslArgs;
  132.   if (isset($xslArgs['/'.$varname]))
  133.    $this->xslArg=&$xslArgs['/'.$varname];
  134.   elseif (isset($xslArgs[$varname]))
  135.    $this->xslArg=&$xslArgs[$varname];
  136.   else return false;
  137.   return true;
  138.  }
  139.  function stream_read($count)
  140.  {
  141.   $ret=substr($this->xslArg,$this->position,$count);
  142.   $this->position+=strlen($ret);
  143.   return $ret;
  144.  }
  145.  function stream_tell({return $this->position;}
  146.  function url_stat({return array();}
  147. }
  148.  
  149. stream_wrapper_register('arg','xslt_arg_stream');
  150.  
  151. // début script
  152. require_once 'generatefunc.php';
  153.  
  154. $xsltproc xslt_create();
  155.  
  156. xslt_set_encoding($xsltproc'ISO-8859-1');
  157. $xmlpath=".";
  158. $tplpath="../src/lodel/admin/tpl";
  159. $tables=array("persontypes",
  160.           "entrytypes",
  161.           "types","classes",
  162.           "tablefields",
  163.           "indextablefields"// vtable
  164.           "tablefieldgroups",
  165.           "users",
  166.           "usergroups",
  167.           "translations",
  168.           "options",
  169.           "optiongroups",
  170.           "characterstyles",
  171.           "internalstyles",
  172.           "translations",
  173.         "texts",
  174.         "restricted_users"
  175.                 );
  176. foreach ($tables as $table{
  177.   echo "table=$table\n";
  178.   $parameters=array(
  179.             "table"=>$table
  180.             );
  181.  
  182.   $html =
  183.     xslt_process($xsltproc"$xmlpath/init-site.xml""$xmlpath/forms.xsl"NULLNULL,$parameters);
  184.  
  185.  
  186.   $html=str_replace(array("<phptag>","</phptag>",
  187.               "[#POSTACTION]","<ELSE></ELSE>",
  188.               "<br>"),
  189.             array("<"."?php ","?".">",
  190.               '<'.'?php echo basename($_SERVER[\'PHP_SELF\']); ?'.'>',"<ELSE/>",
  191.               "<br />"
  192.               ),$html
  193.             );
  194.  
  195.   if (empty($html)) {
  196.     die('XSLT processing error: 'xslt_error($xsltproc));
  197.   }
  198.  
  199.  
  200.   $beginre='<!--\[\s*begin\{form\}[^\n]+?\]-->';
  201.   $endre='<!--\[\s*end\{form\}[^\n]+?\]-->';
  202.  
  203.   $filename=$tplpath."/edit_$table.html";
  204.   replaceInFile($filename,$beginre,$endre,$html);
  205. }
  206.  
  207. xslt_free($xsltproc);
  208. ?>

Documentation generated on Thu, 19 Jun 2008 05:07:48 +0200 by phpDocumentor 1.4.0a2