<?php
/**
* Entier Studio
*
* LICENSE
*
* Copyright 2006 Entier Studio team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package entier.framework
* @copyright Copyright (c) 2006 Entier Studio team. All rights reserved.
* @version $Id: xslt.transform.php 110 2008-02-11 05:49:24Z yannromefort $
*/
//-----------------------------------------------------------------------------
// namespace
if (!defined("DefXSLTTransform")) {
//-------------------------------------------------------------------------
// Define
define("DefXSLTTransform", "1");
//-------------------------------------------------------------------------
// Version
/*
* by Alexandre Alapetite on 2004-09-12; updated on 2006-08-06
*/
if (@version_compare(PHP_VERSION, '5', '>=') && @extension_loaded('xsl'))
@require_once (FRAMEWORK_DIR . "helpers/xslt.helper.php"); //Load the PHP5 converter
//-------------------------------------------------------------------------
// Class
class XSLTTransform {
//---------------------------------------------------------------------
// Attributes
/**
* Transform source
* @var string
* @see XSLTTransform
* @see setTransformSource
*/
var $m_sourceFile = NULL;
/**
* Transform script
* @var string
* @see XSLTTransform
* @see setTransformScript
*/
var $m_scriptFile = NULL;
/**
* Transform output
* @var string
* @see getTransformOutput
*/
var $m_OutputText = NULL;
/**
* Transform errors
* @var array
* @see errorSet
*/
var $m_errorSet = array();
/**
* Transform last error
* @var integer
* @see errorSet
*/
var $m_lastError;
//---------------------------------------------------------------------
// Constructor
/**
*
* @param string
* @param string
*
*/
function XSLTTransform($source = NULL, $script = NULL) {
//
if (!is_null($source))
$this->setTransformSource($source);
//
if (!is_null($script))
$this->setTransformScript($script);
}
//-------------------------------------------------------------------------
// Properties
/**
*
* @param string Transform source
* @return boolean Not empty flag
*/
function setTransformSource($source) {
//
if (empty($source))
return (false);
//
$this->m_sourceFile = $source;
//
return (true);
}
/**
*
* @param string Transform script
* @return boolean Not empty flag
*/
function setTransformScript($script) {
//
if (empty($script)) return (false);
//
$this->m_scriptFile = $script;
//
return (true);
}
/**
*
* @return string Transform output
*/
function getTransformOutput() {
//
return ($this->m_OutputText);
}
/**
*
* @return array Transform errors
*/
function errorSet() {
//
return ($this->m_errorSet);
}
/*
* @return integer
*/
function errorCount() {
if (is_array($this->m_errorSet))
return (count($this->m_errorSet));
return (0);
}
/*
* @return integer
*/
function lastError() {
return ($this->m_lastError);
}
//---------------------------------------------------------------------
// Methods
/**
*
* @param array name="parameters"
*
* @return string
*/
function render($parameters = NULL) {
return ($this->output($parameters));
}
/**
*
* @param array name="parameters"
* @param array name="parameters"
* @param array name="parameters"
*
* @return string
*/
function output($parameters = NULL, $print = false, $compress = false) {
//
$source = $this->m_sourceFile;
$script = $this->m_scriptFile;
if (empty($source) || empty($script))
return (false);
//
unset($this->m_errorSet);
$this->m_errorSet = array();
$this->m_lastError = 0;
//
$processor = @xslt_create();
//
$arguments = array(
'/_xml' => $source,
'/_xsl' => $script
);
//
if (!is_null($parameters))
$output = @xslt_process($processor, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments, $parameters);
else
$output = @xslt_process($processor, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
//
$output = trim($output);
//
if (empty($output)) {
//
$error = @xslt_error($processor);
$errno = @xslt_errno($processor);
//
$this->m_lastError = $errno;
$this->m_errorSet[$errno] = $error;
}
//
@xslt_free($processor);
//
if (empty($output))
return (false);
//
if ($print == true) {
if ($compress == true) {
@ob_start("ob_gzhandler");
print $output;
@ob_end_flush();
} else print $output;
} else $this->m_OutputText = $output;
//
return (true);
}
};
// Class
//-------------------------------------------------------------------------
}
// namespace
//-----------------------------------------------------------------------------
?>