2002-09-21 10:42:46 +02:00
|
|
|
<?php
|
2002-09-28 17:20:20 +02:00
|
|
|
|
|
|
|
if (!extension_loaded('xslt'))
|
|
|
|
{
|
|
|
|
if (PHP_OS == 'Windows' || PHP_OS == 'OS/2')
|
|
|
|
{
|
|
|
|
dl('php_xslt.dll');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dl('xslt.so');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-21 10:42:46 +02:00
|
|
|
require_once('class.xmltool.inc.php');
|
2002-09-22 00:00:07 +02:00
|
|
|
|
|
|
|
class xslttemplates
|
2002-09-21 10:42:46 +02:00
|
|
|
{
|
|
|
|
var $rootdir = '';
|
|
|
|
var $prev_rootdir = '';
|
|
|
|
|
|
|
|
/* The xslfiles will be loaded up and merged into $xsldata */
|
|
|
|
var $xslfiles = Array();
|
|
|
|
var $xsldata = '';
|
|
|
|
|
|
|
|
/* Users can set $vars which will be converted into xmldata before xsl processing */
|
|
|
|
/* Or they can generate their own XML data and set it directly when they have */
|
|
|
|
/* need for a more robust schema */
|
|
|
|
var $vars = Array();
|
|
|
|
var $xmlvars = Array();
|
|
|
|
var $xmldata = '';
|
|
|
|
|
2002-09-22 00:00:07 +02:00
|
|
|
function xslttemplates($root = '.')
|
2002-09-21 10:42:46 +02:00
|
|
|
{
|
|
|
|
if(@isset($GLOBALS['phpgw_info']['flags']['printview']) && $GLOBALS['phpgw_info']['flags']['printview'] == True)
|
|
|
|
{
|
|
|
|
$this->print = True;
|
|
|
|
}
|
|
|
|
$this->set_root($root);
|
|
|
|
}
|
2002-09-22 00:00:07 +02:00
|
|
|
|
2002-09-23 01:03:57 +02:00
|
|
|
function halt($msg)
|
|
|
|
{
|
|
|
|
echo $msg;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2002-09-21 10:42:46 +02:00
|
|
|
function set_root($rootdir)
|
|
|
|
{
|
|
|
|
if (!is_dir($rootdir))
|
|
|
|
{
|
|
|
|
$this->halt('set_root: '.$rootdir.' is not a directory.');
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$this->prev_rootdir = $this->rootdir;
|
|
|
|
$this->rootdir = $rootdir;
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_root()
|
|
|
|
{
|
|
|
|
$this->rootdir = $this->prev_rootdir;
|
|
|
|
}
|
|
|
|
|
2002-09-23 04:35:25 +02:00
|
|
|
function add_file($filename,$rootdir='',$time=1)
|
2002-09-21 10:42:46 +02:00
|
|
|
{
|
|
|
|
if (!is_array($filename))
|
|
|
|
{
|
|
|
|
if($rootdir=='')
|
|
|
|
{
|
|
|
|
$rootdir=$this->rootdir;
|
|
|
|
}
|
2002-09-23 04:35:25 +02:00
|
|
|
|
2002-09-21 10:42:46 +02:00
|
|
|
if (substr($filename, 0, 1) != '/')
|
|
|
|
{
|
|
|
|
$new_filename = $rootdir.'/'.$filename;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$new_filename = $filename;
|
|
|
|
}
|
2002-09-23 04:35:25 +02:00
|
|
|
|
2002-09-21 10:42:46 +02:00
|
|
|
if ($this->print && $time!=2 && $time!=4)
|
|
|
|
{
|
|
|
|
$new_filename = $new_filename.'_print';
|
|
|
|
}
|
|
|
|
|
2002-09-23 04:35:25 +02:00
|
|
|
// echo 'Rootdir: '.$rootdir.'<br>'."\n".'Filename: '.$filename.'<br>'."\n".'New Filename: '.$new_filename.'<br>'."\n";
|
2002-09-21 10:42:46 +02:00
|
|
|
if (!file_exists($new_filename.'.xsl'))
|
|
|
|
{
|
|
|
|
switch($time)
|
|
|
|
{
|
|
|
|
case 2:
|
2002-09-23 04:35:25 +02:00
|
|
|
$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$rootdir);
|
|
|
|
$this->add_file($filename,$new_root,3);
|
|
|
|
return;
|
2002-09-21 10:42:46 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2002-09-23 04:35:25 +02:00
|
|
|
$this->add_file($filename,$rootdir,4);
|
|
|
|
return;
|
2002-09-21 10:42:46 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
$this->halt("filename: file $new_filename.xsl does not exist.");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!$this->print)
|
|
|
|
{
|
2002-09-23 04:35:25 +02:00
|
|
|
$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$rootdir);
|
|
|
|
$this->add_file($filename,$new_root,4);
|
|
|
|
return;
|
2002-09-21 10:42:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-09-23 04:35:25 +02:00
|
|
|
$this->add_file($filename,$rootdir,2);
|
|
|
|
return;
|
2002-09-21 10:42:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-23 04:35:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->xslfiles[$filename] = $new_filename.'.xsl';
|
|
|
|
}
|
2002-09-21 10:42:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reset($filename);
|
|
|
|
while(list(,$file) = each($filename))
|
|
|
|
{
|
|
|
|
$this->add_file($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_var($name, $value, $append = False)
|
|
|
|
{
|
2002-10-25 05:04:28 +02:00
|
|
|
if($append)
|
2002-09-21 10:42:46 +02:00
|
|
|
{
|
2002-10-25 05:04:28 +02:00
|
|
|
//_debug_array($value);
|
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
while(list($key,$val) = each($value))
|
|
|
|
{
|
|
|
|
$this->vars[$name][$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
2002-09-21 10:42:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->vars[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_xml($xml, $append = False)
|
|
|
|
{
|
|
|
|
if(!$append)
|
|
|
|
{
|
|
|
|
$this->xmlvars = $xml;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-09-23 04:35:25 +02:00
|
|
|
$this->xmlvars .= $xml;
|
2002-09-21 10:42:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_var($name)
|
|
|
|
{
|
|
|
|
return $this->vars[$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_vars()
|
|
|
|
{
|
|
|
|
return $this->vars;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_xml()
|
|
|
|
{
|
|
|
|
return $this->xmlvars;
|
|
|
|
}
|
|
|
|
|
|
|
|
function xsl_parse()
|
|
|
|
{
|
|
|
|
if(count($this->xslfiles) > 0)
|
|
|
|
{
|
2002-10-19 02:17:02 +02:00
|
|
|
$this->xsldata = '<?xml version="1.0" encoding="' . lang('charset') . '"?>'."\n";
|
2002-09-21 10:42:46 +02:00
|
|
|
$this->xsldata .= '<!DOCTYPE xsl:stylesheet ['."\n";
|
|
|
|
$this->xsldata .= '<!ENTITY nl " ">'."\n";
|
|
|
|
$this->xsldata .= '<!ENTITY nbsp " ">'."\n";
|
|
|
|
$this->xsldata .= ']>'."\n";
|
|
|
|
$this->xsldata .= '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'."\n";
|
2002-10-19 02:17:02 +02:00
|
|
|
$this->xsldata .= '<xsl:output method="html" version="1.0" encoding="' . lang('charset') . '" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C/DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" standalone="yes" media-type="text/html"/>'."\n";
|
2002-09-21 10:42:46 +02:00
|
|
|
$this->xsldata .= '<xsl:template match="/">'."\n";
|
|
|
|
$this->xsldata .= "\t".'<xsl:apply-templates select="PHPGW"/>'."\n";
|
|
|
|
$this->xsldata .= '</xsl:template>'."\n";
|
2002-09-23 04:35:25 +02:00
|
|
|
reset($this->xslfiles);
|
|
|
|
while(list($dummy,$xslfile) = each($this->xslfiles))
|
2002-09-21 10:42:46 +02:00
|
|
|
{
|
2002-09-23 04:35:25 +02:00
|
|
|
// echo 'XSLFILES: '.$dummy.'<br>'."\n".'XSL File: '.$xslfile.'<br>'."\n";
|
2002-09-21 10:42:46 +02:00
|
|
|
$fd = fopen ($xslfile, "r");
|
|
|
|
$this->xsldata .= fread($fd, filesize($xslfile));
|
|
|
|
fclose ($fd);
|
|
|
|
}
|
|
|
|
$this->xsldata .= '</xsl:stylesheet>'."\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo 'Error: No XSL files have been selected';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
return $this->xsldata;
|
|
|
|
}
|
|
|
|
|
|
|
|
function xml_parse()
|
|
|
|
{
|
|
|
|
$this->xmldata = '';
|
|
|
|
$xmlvars = $this->xmlvars;
|
|
|
|
|
|
|
|
$xmldata = $this->vars;
|
|
|
|
|
|
|
|
/* auto generate xml based on vars */
|
|
|
|
|
|
|
|
while(list($key,$value) = each($xmlvars))
|
|
|
|
{
|
|
|
|
$xmldata[$key] = $value;
|
|
|
|
}
|
|
|
|
//$tmpxml_object = var2xml('PHPGW',$xmldata);
|
|
|
|
//$this->xmldata = $tmpxml_object->dump_mem();
|
|
|
|
//return $this->xmldata;
|
|
|
|
$this->xmldata = var2xml('PHPGW',$xmldata);
|
|
|
|
return $this->xmldata;
|
|
|
|
}
|
2002-10-25 05:04:28 +02:00
|
|
|
|
2002-10-02 02:44:22 +02:00
|
|
|
function list_lineno($xml)
|
|
|
|
{
|
|
|
|
$xml = explode("\n",$xml);
|
|
|
|
|
|
|
|
echo "<pre>\n";
|
|
|
|
for ($n=1; isset($xml[$n]); ++$n)
|
|
|
|
{
|
|
|
|
echo "$n: ".htmlentities($xml[$n])."\n";
|
|
|
|
}
|
|
|
|
echo "</pre>\n";
|
|
|
|
}
|
|
|
|
|
2002-09-21 10:42:46 +02:00
|
|
|
function parse($parsexsl = True, $parsexml = True)
|
|
|
|
{
|
|
|
|
if($parsexsl)
|
|
|
|
{
|
|
|
|
$this->xsl_parse();
|
|
|
|
}
|
|
|
|
if($parsexml)
|
|
|
|
{
|
|
|
|
$this->xml_parse();
|
|
|
|
}
|
|
|
|
$xsltproc = xslt_create();
|
|
|
|
|
|
|
|
$minor = explode(".",phpversion());
|
|
|
|
if($minor[1] >= 1) // PHP 4.1.x -- preferred
|
|
|
|
{
|
|
|
|
$arguments = array('/_xml' => $this->xmldata, '/_xsl' => $this->xsldata);
|
|
|
|
$html = xslt_process($xsltproc,'arg:/_xml','arg:/_xsl',NULL,$arguments);
|
|
|
|
}
|
|
|
|
else // PHP 4.0.6 -- works okay
|
|
|
|
{
|
|
|
|
xslt_process($this->xsldata, $this->xmldata,$html);
|
|
|
|
}
|
2002-10-02 02:44:22 +02:00
|
|
|
if (!$html)
|
|
|
|
{
|
|
|
|
echo "<p>xml-data = "; $this->list_lineno($this->xmldata);
|
|
|
|
echo "<p>xsl-data = "; $this->list_lineno($this->xsldata);
|
|
|
|
die(/*$this->xsldata.*/"\n\n XSLT processing error: ".xslt_error($xsltproc));
|
|
|
|
}
|
2002-09-21 10:42:46 +02:00
|
|
|
xslt_free($xsltproc);
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function pparse()
|
|
|
|
{
|
|
|
|
print $this->parse();
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
function pp()
|
|
|
|
{
|
|
|
|
return $this->pparse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|