[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] api/class.xslt.php, 1.1.1.1.2.8
From: |
nomail |
Subject: |
[Phpgroupware-cvs] api/class.xslt.php, 1.1.1.1.2.8 |
Date: |
Thu, 20 May 2004 15:32:05 -0000 |
Update of /api
Modified Files:
Branch: proposal-branch
class.xslt.php
date: 2004/04/16 20:59:49; author: seek3r; state: Exp; lines: +171 -135
Log Message:
bringing savannah cvs back up to date with what we were doing on our private
cvs server. We will not be doing dev from this cvs tree
=====================================================================
No syntax errors detected in -
=====================================================================
Index: api/class.xslt.php
diff -u api/class.xslt.php:1.1.1.1.2.7 api/class.xslt.php:1.1.1.1.2.8
--- api/class.xslt.php:1.1.1.1.2.7 Tue Feb 24 18:12:20 2004
+++ api/class.xslt.php Fri Apr 16 20:59:49 2004
@@ -22,7 +22,7 @@
\**************************************************************************/
/* $Id$ */
- /* $Source$ */
+ /* $Source$ */
/*
if (!extension_loaded('xslt'))
@@ -36,89 +36,111 @@
dl('xslt.so');
}
}
-*/
+ */
+
class api_xslt
{
var $baseURI;
- var $xsl;
- var $xml;
- var $output;
- var $error;
- var $processor;
- var $client_render = False;
- var $amp = '&';
-
+ var $xsl;
+ var $xml;
+ var $output;
+ var $error;
+ var $processor;
+ var $client_render = false;
+ var $amp = '&';
+
function api_xslt()
{
- if (!extension_loaded('xslt'))
+ $old_level = error_reporting(0);
+
+ if (@extension_loaded('xslt'))
+ {
+ $this->xslt_engine = 'xslt';
+ }
+ elseif (@extension_loaded('dom-xslt'))
{
- $this->client_render = True;
+ $this->xslt_engine = 'dom-xslt';
+ }
+ else
+ {
+ $this->xslt_engine = 'none';
+ $this->client_render = true;
return;
}
+ error_reporting($old_level);
+
+ $agent = getenv('HTTP_USER_AGENT');
- /* Determine agent */
- if (ereg( 'MSIE
([0-9].[0-9]{1,2})',getenv("HTTP_USER_AGENT"),$log_version))
+ $browser = array(
+ 'agent' => 'OTHER',
+ 'ver' => 0,
+ 'platform' => 'OTHER'
+ );
+
+ /* Determine agent */
+ if (preg_match('/MSIE ([0-9].[0-9]{1,2})/',$agent,$log_version))
{
$browser['agent'] = 'IE';
$browser['ver'] = $log_version[1];
}
- elseif (ereg( 'Opera
([0-9].[0-9]{1,2})',getenv("HTTP_USER_AGENT"),$log_version))
+ elseif (preg_match('/Opera
([0-9].[0-9]{1,2})/',$agent,$log_version))
{
$browser['agent'] = 'OPERA';
$browser['ver'] = $log_version[1];
}
- elseif (ereg(
'Mozilla/([0-9].[0-9]{1,2})',getenv("HTTP_USER_AGENT"),$log_version))
+ elseif
(preg_match('/Mozilla\/([0-9].[0-9]{1,2})/',$agent,$log_version))
{
$browser['agent'] = 'MOZILLA';
$browser['ver'] = $log_version[1];
- ereg(
'Gecko/([0-9]{8})',getenv("HTTP_USER_AGENT"),$gecko_version);
+ preg_match('/Gecko\/([0-9]{8})/',$agent,$gecko_version);
$browser['gecko'] = $gecko_version[1];
}
- else
- {
- $browser['agent'] = 'OTHER';
- $browser['ver'] = 0;
- }
- /* Determine platform */
- if (strstr(getenv("HTTP_USER_AGENT"),'Win'))
- {
- $browser['platform'] = 'Win';
- }
- else if (strstr(getenv("HTTP_USER_AGENT"),'Mac'))
- {
- $browser['platform'] = 'Mac';
- }
- else if (strstr(getenv("HTTP_USER_AGENT"),'Linux'))
- {
- $browser['platform'] = 'Linux';
- }
- else if (strstr(getenv("HTTP_USER_AGENT"),'Unix'))
- {
- $browser['platform'] = 'Unix';
- }
- else
+
+ /* Determine platform */
+ if (preg_match('/(Win|Mac|Linux|Unix)/',$agent,$platform))
{
- $browser['platform'] = 'Other';
+ $browser['platform'] = $platform[1];
}
- if($browser['agent'] == 'IE' && $browser['ver'] >= 5.5)
+
+ if ($browser['agent'] == 'IE' && $browser['ver'] >= 5.5)
{
- $this->client_render = True;
+ $this->client_render = true;
}
- if($browser['agent'] == 'MOZILLA' && $browser['ver'] >= 5.0 &&
$browser['gecko'] >= 20030000)
+ if ($browser['agent'] == 'MOZILLA' && $browser['ver'] >= 5.0 &&
$browser['gecko'] >= 20030000)
{
- $this->client_render = True;
+ $this->client_render = true;
$this->amp = '&';
}
- /* use this to force output of xml */
+ // Used to force the type of rendering to use
$fxsl = get_var('fxsl', 'any', 'number', 0);
- if($fxsl == 1)
+
+ // If they force a new type, save it to the session and use
that type
+ // until its changed back
+ if ($fxsl)
+ {
+ $_SESSION['phpgw_session']['fxsl'] = $fxsl;
+ }
+
+ if (! $_SESSION['phpgw_session']['fxsl'])
{
- $this->client_render = True;
+ if ($this->client_render)
+ {
+ $_SESSION['phpgw_session']['fxsl'] = 1;
+ }
+ else
+ {
+ $_SESSION['phpgw_session']['fxsl'] = 2;
+ }
}
- elseif($fxsl == 2)
+
+ switch ($_SESSION['phpgw_session']['fxsl'])
{
- $this->client_render = False;
+ case 1:
+ $this->client_render = true;
+ break;
+ case 2:
+ $this->client_render = false;
}
}
@@ -127,151 +149,165 @@
$this->xml = $xml;
return true;
}
-
+
function set_xsl($xsl)
{
$this->xsl = $xsl;
return true;
}
-
+
function setError($txt)
- {
+ {
$this->error = $txt;
- }
-
+ }
+
function getError()
- {
- return $this->error;
- }
-
+ {
+ return $this->error;
+ }
+
function transform()
{
- $this->processor = xslt_create();
- $minor = explode(".",phpversion());
- if($minor[1] >= 1) {
- $arguments = array('/_xml' => $this->xml, '/_xsl' =>
$this->xsl);
- $result =
xslt_process($this->processor,'arg:/_xml','arg:/_xsl',NULL,$arguments);
- } else {
- xslt_process($this->xsl, $this->xml,$result);
- }
-
- if (!$result) {
- $this->setError(xslt_error($this->processor));
- xslt_free($this->processor);
- return false;
- }
- else
+ switch($this->xslt_engine)
{
- $this->output = $result;
- xslt_free($this->processor);
- return true;
+ case 'dom-xslt':
+ $xmlobj = domxml_open_mem($this->xml);
+ $xslobj = domxml_xslt_stylesheet ($this->xsl);
+ $xsl_resultobj = $xslobj->process($xmlobj);
+ $this->output =
$xslobj->result_dump_mem($xsl_resultobj);
+ return true;
+ break;
+ case 'xslt':
+ $this->processor = xslt_create();
+ $minor = explode('.',phpversion());
+ if($minor[1] >= 1) {
+ $arguments = array('/_xml' =>
$this->xml, '/_xsl' => $this->xsl);
+ $result =
xslt_process($this->processor,'arg:/_xml','arg:/_xsl',NULL,$arguments);
+ } else {
+
xslt_process($this->xsl,$this->xml,$result);
+ }
+
+ if (!$result) {
+
$this->setError(xslt_error($this->processor));
+ xslt_free($this->processor);
+ return false;
+ }
+
+ $this->output = $result;
+ xslt_free($this->processor);
+ return true;
+ break;
}
}
-
- function getOutput()
- {
+
+ function getOutput()
+ {
+ $GLOBALS['performance_timer']->start('xslt_out');
if($this->client_render)
{
return $this->xml;
}
- else
+
+ if(empty($this->output))
{
- if(empty($this->output))
- {
- $this->transform();
- }
- return $this->output;
+ $this->transform();
}
- }
-
-
+ $GLOBALS['performance_timer']->stop('xslt_out');
+ return $this->output;
+ }
+
function setup_stylesheet($xsl_files)
{
if($this->client_render)
{
/* Add the XSL files to the initial get request */
- if(!empty($GLOBALS['phpgw_data']['server']['base_url']))
+ if(!empty($GLOBALS['phpgw_data']['server']['baseurl']))
{
- $stylesheet_string =
$GLOBALS['phpgw_data']['server']['base_url'].'/';
+ $stylesheet_string =
$GLOBALS['phpgw_data']['server']['baseurl'].'/';
}
else
- {
+ {
$stylesheet_string = '';
}
-
+
$stylesheet_string .=
'index.php?op=api.xslt.get'.$this->amp.'skin='.$GLOBALS['phpgw_data']['prefs']['api.skin'];
- foreach($xsl_files as $key=>$val)
+ foreach($xsl_files as $key=>$val)
{
$stylesheet_string .=
$this->amp.'files[]='.$val;
}
header('Content-type: text/xml');
return $stylesheet_string;
}
- else
+
+ /* Generate the initial XSL file and return nothing, since PHP
is going to render anyways */
+ $this->xsl = '<?xml version="1.0"?>'."\n";
+ $this->xsl .= '<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'."\n";
+ $this->xsl .= '<xsl:output method="html" encoding="iso-8859-1"
indent="yes"/>'."\n";
+ foreach($xsl_files as $key=>$val)
{
- /* Generate the initial XSL file and return nothing,
since PHP is going to render anyways */
- $this->xsl = '<?xml version="1.0"?>'."\n";
- $this->xsl .= '<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'."\n";
- $this->xsl .= '<xsl:output method="html"
encoding="iso-8859-1" indent="yes"/>'."\n";
- foreach($xsl_files as $key=>$val)
- {
- list($app,$file) = explode('.',$val);
- $filename =
PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.$GLOBALS['phpgw_data']['prefs']['api.skin'].SEP.$file.'.xsl';
- if(!file_exists($filename) &&
$GLOBALS['phpgw_data']['prefs']['api.skin'] != 'default')
+ list($app,$file) = explode('.',$val);
+ $filename =
PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.$GLOBALS['phpgw_data']['prefs']['api.skin'].SEP.$file.'.xsl';
+ if(!file_exists($filename) &&
$GLOBALS['phpgw_data']['prefs']['api.skin'] != 'default')
+ {
+ $def_filename =
PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.'default'.SEP.$file.'.xsl';
+ if(!file_exists($def_filename))
{
- $def_filename =
PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.'default'.SEP.$file.'.xsl';
- if(file_exists($def_filename))
- {
- $filename = $def_filename;
- }
+ continue;
}
- $lines = file($filename);
- foreach ($lines as $line_num => $line)
+ $filename = $def_filename;
+ }
+ $lines = file($filename);
+ foreach ($lines as $line_num => $line)
+ {
+
if(!preg_match('/^(<\?xml)|(<?xsl:stylesheet)|(<xsl:output)$/i', $line))
{
-
if(!preg_match("/^(<\?xml)|(<?xsl:stylesheet)|(<xsl:output)$/i", $line))
- {
- $this->xsl .= $line."\n";
- }
+ $this->xsl .= $line."\n";
}
}
- $this->xsl .= '</xsl:stylesheet>';
- return '';
}
- }
-
- function get($args)
+ $this->xsl .= '</xsl:stylesheet>';
+ return '';
+ }
+
+ function get($args, $tobrowser = true)
{
header('Content-type: text/xml');
- echo '<?xml version="1.0"?>'."\n";
- echo '<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'."\n";
- //echo '<xsl:output method="html" encoding="iso-8859-1"
indent="no"/>'."\n";
- foreach($args['files'] as $key=>$val)
- {
+ $result = '<?xml version="1.0"?>'."\n";
+ $result .= '<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">'."\n";
+ //$result .= '<xsl:output method="html" encoding="iso-8859-1"
indent="no"/>'."\n";
+ foreach($args['files'] as $key=>$val)
+ {
list($app,$file) = explode('.',$val);
-
- $addline = True;
+ $addline = true;
+ $curskin = $args['skin'];
if(!file_exists(PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.$args['skin'].SEP.$file.'.xsl')
&& $args['skin'] != 'default')
{
$args['skin'] = 'default';
if(!file_exists(PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.$args['skin'].SEP.$file.'.xsl'))
{
- $addline = False;
+ $addline = false;
}
}
if($addline)
{
-
if(!empty($GLOBALS['phpgw_data']['server']['base_url']))
+
if(!empty($GLOBALS['phpgw_data']['server']['baseurl']))
{
- $baseurl =
$GLOBALS['phpgw_data']['server']['base_url'].'/';
+ $baseurl =
$GLOBALS['phpgw_data']['server']['baseurl'].'/';
}
else
- {
+ {
$baseurl = '';
}
- echo ' <xsl:include
href="'.$baseurl.$app.'/skins/'.$args['skin'].'/'.$file.'.xsl" />'."\n";
+ $result .= ' <xsl:include
href="'.$baseurl.$app.'/skins/'.$args['skin'].'/'.$file.'.xsl" />'."\n";
}
+ $args['skin'] = $curskin;
+ }
+ $result .= '</xsl:stylesheet>'."\n";
+ if(!$tobrowser)
+ {
+ return $result;
}
- echo '</xsl:stylesheet>'."\n";
- exit;
+ define('PHPGW_FINISHED', true);
+ echo $result;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] api/class.xslt.php, 1.1.1.1.2.8,
nomail <=