From 2523907723ba676645bc373b06d8435d6e4082f6 Mon Sep 17 00:00:00 2001 From: seek3r Date: Sat, 21 Sep 2002 08:42:46 +0000 Subject: [PATCH] needs more phpGW integrationg --- phpgwapi/inc/class.xslttemplates.php | 232 +++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 phpgwapi/inc/class.xslttemplates.php diff --git a/phpgwapi/inc/class.xslttemplates.php b/phpgwapi/inc/class.xslttemplates.php new file mode 100644 index 0000000000..4f9618158e --- /dev/null +++ b/phpgwapi/inc/class.xslttemplates.php @@ -0,0 +1,232 @@ +print = True; + } + $this->set_root($root); + } + + 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; + } + + function add_file($filename,$root='',$time=1) + { + if (!is_array($filename)) + { + if($rootdir=='') + { + $rootdir=$this->rootdir; + } + if (substr($filename, 0, 1) != '/') + { + $new_filename = $rootdir.'/'.$filename; + } + else + { + $new_filename = $filename; + } + if ($this->print && $time!=2 && $time!=4) + { + $new_filename = $new_filename.'_print'; + } + + + if (!file_exists($new_filename.'.xsl')) + { + switch($time) + { + case 2: + $new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$root); + $new_filename = $this->add_file($filename,$new_root,3); + break; + case 3: + $new_filename = $this->add_file($filename,$root,4); + break; + case 4: + $this->halt("filename: file $new_filename.xsl does not exist."); + break; + default: + if (!$this->print) + { + $new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$root); + $new_filename = $this->add_file(str_replace($root.'/','',$new_filename),$new_root,4); + } + else + { + $new_filename = $this->add_file($filename,$root,2); + } + } + } + $this->xslfiles[$filename] = $new_filename.'.xsl'; + } + else + { + reset($filename); + while(list(,$file) = each($filename)) + { + $this->add_file($file); + } + } + } + + function set_var($name, $value, $append = False) + { + if(!is_array($value) && $append) + { + $this->vars[$name] .= $value; + } + else + { + $this->vars[$name] = $value; + } + } + + function set_xml($xml, $append = False) + { + if(!$append) + { + $this->xmlvars = $xml; + } + else + { + $this->xmlvar .= $xml; + } + } + + 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) + { + $this->xsldata = ''."\n"; + $this->xsldata .= 'xsldata .= ''."\n"; + $this->xsldata .= ''."\n"; + $this->xsldata .= ']>'."\n"; + $this->xsldata .= ''."\n"; +// $this->xsldata .= ''."\n"; + $this->xsldata .= ''."\n"; + $this->xsldata .= "\t".''."\n"; + $this->xsldata .= ''."\n"; + while(list(,$xslfile) = each($this->xslfiles)) + { + $fd = fopen ($xslfile, "r"); + $this->xsldata .= fread($fd, filesize($xslfile)); + fclose ($fd); + } + $this->xsldata .= ''."\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; + } + + 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); + } + + if (!$html) die($this->xsldata."\n\n XSLT processing error: ".xslt_error($xsltproc)); + xslt_free($xsltproc); + return $html; + } + + function pparse() + { + print $this->parse(); + return False; + } + function pp() + { + return $this->pparse(); + } + } +?>