phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.xslttemplates.inc.php


From: Dave Hall
Subject: [Phpgroupware-cvs] phpgwapi/inc class.xslttemplates.inc.php
Date: Sun, 09 Apr 2006 14:00:31 +0000

CVSROOT:        /cvsroot/phpgwapi
Module name:    phpgwapi
Branch:         
Changes by:     Dave Hall <address@hidden>      06/04/09 14:00:31

Modified files:
        inc            : class.xslttemplates.inc.php 

Log message:
        various fixes

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/phpgwapi/inc/class.xslttemplates.inc.php.diff?tr1=1.22&tr2=1.23&r1=text&r2=text

Patches:
Index: phpgwapi/inc/class.xslttemplates.inc.php
diff -u phpgwapi/inc/class.xslttemplates.inc.php:1.22 
phpgwapi/inc/class.xslttemplates.inc.php:1.23
--- phpgwapi/inc/class.xslttemplates.inc.php:1.22       Sat Feb 25 00:15:36 2006
+++ phpgwapi/inc/class.xslttemplates.inc.php    Sun Apr  9 14:00:31 2006
@@ -4,11 +4,11 @@
        * @author Dan Kuykendall <address@hidden>
        * @author Bettina Gille address@hidden
        * @author Ralf Becker <address@hidden>
-       * @copyright Copyright (C) 2002-2005 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @copyright Copyright (C) 2002-2006 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lpl.html GNU General Public 
License
        * @package phpgwapi
        * @subpackage gui
-       * @version $Id: class.xslttemplates.inc.php,v 1.22 2006/02/25 00:15:36 
skwashd Exp $
+       * @version $Id: class.xslttemplates.inc.php,v 1.23 2006/04/09 14:00:31 
skwashd Exp $
        */
 
        if( (floor(phpversion()) == 4 && !extension_loaded('xslt') )
@@ -22,7 +22,6 @@
        */
        require_once('class.xmltool.inc.php');
 
-
        /**
        * XSLT template engine
        *
@@ -39,7 +38,7 @@
                * @var array XSL files to load
                */
                var $xslfiles = Array();
-               var     $xsldata = '';
+               var $xsldata = '';
 
                /**
                * Users can set $vars which will be converted into xmldata 
before xsl processing.
@@ -53,18 +52,17 @@
 
                function xslttemplates($root = '.')
                {
+                       //FIXME Print view/mode should be handled by CSS not 
different markup
                        if(@isset($GLOBALS['phpgw_info']['flags']['printview']) 
&& $GLOBALS['phpgw_info']['flags']['printview'] == True)
                        {
                                $this->print = True;
                        }
                        $this->set_root($root);
-
                }
 
                function halt($msg)
                {
-                       echo $msg;
-                       exit;
+                       die($msg);
                }
 
                function set_root($rootdir)
@@ -84,7 +82,7 @@
                        $this->rootdir = $this->prev_rootdir;
                }
 
-               function add_file($filename,$rootdir='',$time=1)
+               function add_file($filename, $rootdir='', $time=1)
                {
                        if (!is_array($filename))
                        {
@@ -102,6 +100,7 @@
                                        $new_filename = $filename;
                                }
 
+                               //FIXME use CSS for "print mode"
                                if ($this->print && $time!=2 && $time!=4)
                                {
                                        $new_filename = $new_filename.'_print';
@@ -116,11 +115,9 @@
                                                        $new_root = 
str_replace($GLOBALS['phpgw_info']['server']['template_set'],'base',$rootdir);
                                                        
$this->add_file($filename,$new_root,3);
                                                        return;
-                                                       break;
                                                case 3:
                                                        
$this->add_file($filename,$rootdir,4);
                                                        return;
-                                                       break;
                                                case 4:
                                                        $this->halt("filename: 
file $new_filename.xsl does not exist.");
                                                        break;
@@ -145,8 +142,7 @@
                        }
                        else
                        {
-                               reset($filename);
-                               while(list(,$file) = each($filename))
+                               foreach ( $filename as $file )
                                {
                                        $this->add_file($file);
                                }
@@ -159,7 +155,7 @@
                        {
                                if (is_array($value))
                                {
-                                       while(list($key,$val) = each($value))
+                                       foreach ( $value as $key => $val )
                                        {
 
                                                if (is_array($val) && 
is_array($this->vars[$name][$key]))
@@ -208,7 +204,7 @@
 
                function xsl_parse()
                {
-                       if(count($this->xslfiles) > 0)
+                       if( is_array($this->xslfiles) && count($this->xslfiles) 
> 0)
                        {
                                $this->xsldata = '<?xml version="1.0" 
encoding="' . lang('charset') . '"?>'."\n";
                                $this->xsldata .= '<!DOCTYPE xsl:stylesheet 
['."\n";
@@ -216,24 +212,22 @@
                                $this->xsldata .= '<!ENTITY nbsp 
"&#160;">'."\n";
                                $this->xsldata .= ']>'."\n";
                                $this->xsldata .= '<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">'."\n";
-                               $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";
+                               $this->xsldata .= '<xsl:output method="xml" 
version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="yes" 
standalone="yes" media-type="application/xml+xhtml"/>'."\n";
+                               //FIXME Remove the line above and uncomment the 
one below once the main templates are converted or else it fscks validation
+                               //$this->xsldata .= '<xsl:output method="xml" 
version="1.0" encoding="utf-8" 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="application/xml+xhtml"/>'."\n";
                                $this->xsldata .= '<xsl:template 
match="/">'."\n";
                                $this->xsldata .= "\t".'<xsl:apply-templates 
select="PHPGW"/>'."\n";
                                $this->xsldata .= '</xsl:template>'."\n";
-                               reset($this->xslfiles);
-                               while(list($dummy,$xslfile) = 
each($this->xslfiles))
+                               foreach ( $this->xslfiles as $xslfile)
                                {
-//                                     echo 'XSLFILES: 
'.$dummy.'<br>'."\n".'XSL File: '.$xslfile.'<br>'."\n";
-                                       $fd = fopen ($xslfile, "r");
-                                       $this->xsldata .= fread($fd, 
filesize($xslfile));
-                                       fclose ($fd);
+                                       $this->xsldata .= "\n\n<!-- XSL File: 
{$xslfile} -->\n";
+                                       $this->xsldata .= 
file_get_contents($xslfile);
                                }
                                $this->xsldata .= '</xsl:stylesheet>'."\n";
                        }
                        else
                        {
-                               echo 'Error: No XSL files have been selected';
-                               exit;
+                               die('Error: No XSL files have been selected');
                        }
                        return $this->xsldata;
                }
@@ -257,14 +251,18 @@
 
                function list_lineno($xml)
                {
-                       $xml = explode("\n",$xml);
+                       $lines = explode("\n", $xml);
+                       unset($xml);
 
-                       echo "<pre>\n";
-                       for ($n=1; isset($xml[$n]); ++$n)
-                       {
-                               echo "$n: ".htmlentities($xml[$n])."\n";
+                       echo "<ol>\n";
+                       $i = 1;
+                       foreach ( $lines as $line )
+                       {
+                               $row = ($i % 2) ? 'row_on' : 'row_off';
+                               echo "<li class=\"{$row}\" style=\"white-space: 
pre;\">" . htmlentities($line) . "</li>\n";
+                               ++$i;
                        }
-                       echo "</pre>\n";
+                       echo "</ol>\n";
                }
 
                function parse($parsexsl = True, $parsexml = True)
@@ -282,7 +280,14 @@
 
                        $minor = explode(".",phpversion());
 
-                       if ($minor[0] == 5)
+                       if ($minor[0] == 4)
+                       {
+                               $xsltproc = xslt_create();
+                               $arguments = array('/_xml' => $this->xmldata, 
'/_xsl' => $this->xsldata);
+                               $html = 
xslt_process($xsltproc,'arg:/_xml','arg:/_xsl',NULL,$arguments);
+                               xslt_free($xsltproc);
+                       }
+                       else
                        {
                                $xml = new DOMDocument;
                                $xml->loadXML($this->xmldata);
@@ -296,22 +301,15 @@
 
                                $html =  $proc->transformToXML($xml);
                        }
-                       else
-                       {
-                               $xsltproc = xslt_create();
-                               $arguments = array('/_xml' => $this->xmldata, 
'/_xsl' => $this->xsldata);
-                               $html = 
xslt_process($xsltproc,'arg:/_xml','arg:/_xsl',NULL,$arguments);
-                               xslt_free($xsltproc);
-                       }
 
                        if (!$html)
                        {
-                               echo "<p>xml-data = ";  
$this->list_lineno($this->xmldata);
-                               echo "<p>xsl-data = "; 
$this->list_lineno($this->xsldata);
+                               echo "<h2>xml-data</h2>";  
$this->list_lineno($this->xmldata);
+                               echo "<h2>xsl-data</h2>"; 
$this->list_lineno($this->xsldata);
                                if ($minor[0] == 4)
                                {
-                               die(/*$this->xsldata.*/"\n\n XSLT processing 
error: ".xslt_error($xsltproc));
-                       }
+                                       die(/*$this->xsldata.*/"\n\n XSLT 
processing error: ".xslt_error($xsltproc));
+                               }
                        }
 
                        return $html;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]