Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function getSubscribedDelegates(){
}

public function initFunctionManager($context){
$Manager = new FunctionManager(&$context);
$Manager = new FunctionManager($context);
$Manager->createDelegate();
$Manager->createStream();
}
}
}
109 changes: 62 additions & 47 deletions lib/class.exslfunction.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
<?php
<?php

class EXSLFunction{
private $fn_name;
private $fn_handle;
private $fn_namespace;
private $fn_declaration;
private $fn_xslfunction;
class EXSLFunction
{
private $fn_name;
private $fn_handle;
private $fn_namespace;
private $fn_declaration;
private $fn_xslfunction;


public function __construct($strName, $strURI, $strHandle = NULL){
$this->fn_name = $strName;
$this->fn_namespace = $strURI;
if (!$strHandle) { $this->fn_handle = $strName;} else {$this->fn_handle = $strHandle;}
}


public function getDeclarations($prefix) {
$strDeclaration = "xmlns:" . $prefix . "='" . $this->fn_namespace ."'";
$this->fn_declaration = $strDeclaration;
return $this->fn_declaration;
}

public function getFunction($prefix) {
$reflector = new ReflectionMethod($this->fn_name);
//handle parameters
$params = $reflector->getParameters();
$strParams = '';
$strPassParams = '';
foreach( $params as $param) {
$strParams .= '<xsl:param name="' . $param->getName() . '" />';
if ($param->isArray()) {
// function wants a DomDocument (which comes wrapped in an array)
$strPassParams .= 'exsl:node-set($' . $param->getName() . ")";
} else {
$strPassParams .= '$' . $param->getName();
}
if ($param != end($params)) {$strPassParams .= ',';}
public function __construct($strName, $strURI, $strHandle = null){
$this->fn_name = $strName;
$this->fn_namespace = $strURI;
if( !$strHandle ){
$this->fn_handle = $strName;
}

$strFunction = '<func:function name="' . $prefix . ":" . $this->fn_handle . '" xmlns:func="http://exslt.org/functions" >'
. $strParams .
'<func:result>
<xsl:copy-of select="php:function(\'' . $this->fn_name . '\',' . $strPassParams . ')" />
</func:result>
</func:function>';

$this->fn_xslfunction = $strFunction;
return $this->fn_xslfunction;
else{
$this->fn_handle = $strHandle;
}
}


public function getDeclarations($prefix){
$strDeclaration = "xmlns:".$prefix."='".$this->fn_namespace."'";
$this->fn_declaration = $strDeclaration;
return $this->fn_declaration;
}

public function getFunction($prefix){
$reflector = new ReflectionMethod($this->fn_name);

//handle parameters
$params = $reflector->getParameters();
$strParams = '';
$strPassParams = '';

foreach($params as $param){
$strParams .= '<xsl:param name="'.$param->getName().'"/>';

if( $param->isArray() ){
// function wants a DomDocument (which comes wrapped in an array)
$strPassParams .= 'exsl:node-set($'.$param->getName().")";
}
else{
$strPassParams .= '$'.$param->getName();
}

if( $param != end( $params ) ){
$strPassParams .= ',';
}
}

$strFunction =
'<func:function name="'.$prefix.":".$this->fn_handle.'" xmlns:func="http://exslt.org/functions">'
.$strParams.
'<func:result>
<xsl:copy-of select="php:function(\''.$this->fn_name.'\','.$strPassParams.')" />
</func:result>
</func:function>';

$this->fn_xslfunction = $strFunction;

return $this->fn_xslfunction;
}

}

}
125 changes: 65 additions & 60 deletions lib/class.functionmanager.php
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
<?php
require_once('class.exslfunction.php');

class FunctionManager {
private $functions = array();
private $page;

require_once('class.exslfunction.php');

function __construct($context) {
$this->page = $context['page'];
class FunctionManager
{
private $functions = array();
private $page;

}

public function createDelegate() {
// Create Delegate

Symphony::ExtensionManager()->notifyMembers(
'ManageEXSLFunctions', '/frontend/', array('manager' => &$this)
function __construct($context){
$this->page = $context['page'];
}

public function createDelegate(){
Symphony::ExtensionManager()->notifyMembers( 'ManageEXSLFunctions', '/frontend/', array(
'manager' => &$this
) );
}


public function createStream(){
// Register Stream Wrapper
stream_wrapper_register( "efm", "XslTemplateLoaderStream" );
$exsl = $this->getFunctions();
$opts = array(
'efm' => array(
'namespaces' => $exsl['declarations'],
'functions' => $exsl['functions']
//'functions' => print_r($exsl)
)
);
}


public function createStream() {
// Register Stream Wrapper
stream_wrapper_register("efm", "XslTemplateLoaderStream");
$exsl = $this->getFunctions();
$opts = array(
'efm' => array(
'namespaces' => $exsl['declarations'],
'functions' => $exsl['functions']
//'functions' => print_r($exsl)
)
);
$streamContext = stream_context_create($opts);
libxml_set_streams_context($streamContext);
}


// For use in subscribed delegates
public function addFunction($strName, $strURI, $strHandle = NULL){
//Register function with PHP
$this->page->registerPHPFunction($strName);

//Create a new EXSL function object
$function = new EXSLFunction($strName, $strURI, $strHandle);

//Add to Manager's function array, which groups by namespace URI
$this->functions[$strURI][] = $function;
}


private function getFunctions(){
$strFunctions = "";
$strDeclarations = "";
$i = 0;
foreach ($this->functions as $namespace){
$prefix = 'fn' . $i;
$strDeclarations .= $namespace[0]->getDeclarations($prefix); //Get the declaration from the first EXSL object in the array
foreach ($namespace as $function){
$strFunctions .= $function->getFunction($prefix);
$streamContext = stream_context_create( $opts );

libxml_set_streams_context( $streamContext );
}


// For use in subscribed delegates
public function addFunction($strName, $strURI, $strHandle = null){
//Register function with PHP
$this->page->registerPHPFunction( $strName );

//Create a new EXSL function object
$function = new EXSLFunction($strName, $strURI, $strHandle);

//Add to Manager's function array, which groups by namespace URI
$this->functions[$strURI][] = $function;
}


private function getFunctions(){
$strFunctions = "";
$strDeclarations = "";
$i = 0;

foreach($this->functions as $namespace){
$prefix = 'fn'.$i;

$strDeclarations .= $namespace[0]->getDeclarations( $prefix ); //Get the declaration from the first EXSL object in the array

foreach($namespace as $function){
$strFunctions .= $function->getFunction( $prefix );
}

$i++;
}
$i++;

return array('declarations' => $strDeclarations, 'functions' => $strFunctions);

}
return array ('declarations' => $strDeclarations, 'functions' => $strFunctions);

}


}

}
84 changes: 42 additions & 42 deletions lib/class.functionstream.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
<?php
class XslTemplateLoaderStream{
var $position = 0;
var $template = null;

function stream_open($path, $mode, $options, &$opened_path)
{
$context_array = stream_context_get_options($this->context);
//$output = implode($options);
$url = parse_url($path);
switch ($url['host']) {
case "functions":
<?php
class XslTemplateLoaderStream
{

var $position = 0;
var $template = null;

function stream_open($path, $mode, $options, &$opened_path){
$context_array = stream_context_get_options( $this->context );
//$output = implode($options);
$url = parse_url( $path );
switch( $url['host'] ){

case "functions":
$this->template = '<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:func="http://exslt.org/functions"
xmlns:exsl="http://exslt.org/common"
xmlns:php="http://php.net/xsl"'
. $context_array['efm']['namespaces'] .'
extension-element-prefixes="func php" >'
. $context_array['efm']['functions'] .'
xmlns:php="http://php.net/xsl"
'.$context_array['efm']['namespaces'].'
extension-element-prefixes="func php" >
'.$context_array['efm']['functions'].'
</xsl:stylesheet>';
break;
break;
}

return true;
}

return true;
}
function stream_read($count)
{
$ret = substr($this->template, $this->position, $count);
$this->position += $count;
return $ret;
}
function stream_write($data)
{
return 0;
}
function url_stat(){
return array();

}
function stream_eof()
{
return true;
}

}

function stream_read($count){
$ret = substr( $this->template, $this->position, $count );
$this->position += $count;
return $ret;
}

function stream_write($data){
return 0;
}

function url_stat(){
return array();
}

function stream_eof(){
return true;
}

}