-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxslt.inc.php
More file actions
121 lines (104 loc) · 3.23 KB
/
Copy pathxslt.inc.php
File metadata and controls
121 lines (104 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
/*
* freepbx-misdn -- mISDN module for FreePBX
*
* Copyright (C) 2006, Thomas Liske.
*
* Thomas Liske <thomas.liske@beronet.com>
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
define('XSLTPROC', '/usr/bin/xsltproc');
/* The XSLT Functions API is not available in PHP 5 - emulate it
* using the new XSL Functions API (if available).
*
* This is taken from the PHP Manual user comments.
*/
if (class_exists('XsltProcessor') && !function_exists('xslt_create')) {
function xslt_create() {
return new XsltProcessor();
}
function xslt_process($xsltproc, $xml_arg, $xsl_arg, $xslcontainer = null, $args = null, $params = null) {
$xml = new DomDocument;
if (substr($xml_arg,0,4) == 'arg:') {
$xml_arg = str_replace('arg:', '', $xml_arg);
$xml->loadXML($args[$xml_arg]);
}
else
$xsl->load($xml_arg);
$xsl = new DomDocument;
if (substr($xsl_arg,0,4) == 'arg:') {
$xsl_arg = str_replace('arg:', '', $xsl_arg);
$xsl->loadXML($args[$xsl_arg]);
}
else
$xsl->load($xsl_arg);
$xsltproc->importStyleSheet($xsl);
if ($params) {
foreach ($params as $param => $value) {
$xsltproc->setParameter("", $param, $value);
}
}
$processed = $xsltproc->transformToXML($xml);
if ($xslcontainer) {
return @file_put_contents($xslcontainer, $processed);
} else {
return $processed;
}
}
function xslt_free($xsltproc) {
unset($xsltproc);
}
}
/* Maybe there is no XSL Functions API nor the XSLT Functions API available,
* so fallback running xsltproc from command line if possible */
if (!function_exists('xslt_create') && is_executable(XSLTPROC)) {
function xslt_create() {
return 1;
}
function xslt_process($xsltproc, $xml_arg, $xsl_arg, $xslcontainer = null, $args = null, $params = null) {
if (substr($xml_arg,0,4) == 'arg:') {
$xml_arg = str_replace('arg:', '', $xml_arg);
$xmlfile = tempnam("/tmp", 'xml');
file_put_contents($xmlfile, $args[$xml_arg]);
}
else
$xmlfile = $xml_arg;
if (substr($xsl_arg,0,4) == 'arg:') {
$xsl_arg = str_replace('arg:', '', $xsl_arg);
$xslfile = tempnam("/tmp", 'xsl');
file_put_contents($xslfile, $args[$xsl_arg]);
}
else
$xslfile = $xsl_arg;
$_params = '';
if ($params) {
foreach ($params as $param => $value) {
$_params .= ' --param "'.EscapeShellCmd($param).'" "'.EscapeShellCmd($value).'"';
}
}
$processed = '';
$fd = popen(XSLTPROC."$_params \"".EscapeShellCmd($xslfile).'" "'.EscapeShellCmd($xmlfile).'" 2> /dev/null', 'r');
while($line = fgets($fd)) $processed .= $line;
pclose($fd);
if ($xml_arg != $xmlfile)
unlink($xmlfile);
if ($xsl_arg != $xslfile)
unlink($xslfile);
if ($xslcontainer) {
return @file_put_contents($xslcontainer, $processed);
} else {
return $processed;
}
}
function xslt_free($xsltproc) {
}
}