Solved

RSS: MM_XSLTransform error using GoDaddy

Posted on 2009-07-09
3
884 Views
Last Modified: 2013-11-19
I'm having a big problem with running an RSS newsfeed on my site, using GoDaddy as a host. From what I'm reading, GoDaddy seems to have a big problem with this, but all of the fixes I've tried have resulted in different errors or no changes at all.
The code was working perfectly fine on my personal server, the error only showed up when I uploaded it to GoDaddy:
MM_XSLTransform error.
The server could not perform the XSL transformation because an XSLT processor for PHP could not be found. Contact your server administrator and ask them to install an XSLT processor for PHP.

I am running on a GoDaddy Linux account NOT a Windows hosing account.

I've put the code for all the related pages below with comments to separate the pages.

Note: this is my very first time putting RSS on a site, so please keep that in mind!

/********************************* cnn_news.inc *******************************************/
<?php
$mm_xsl2 = new MM_XSLTransform();
$mm_xsl2->setXML("http://rss.cnn.com/rss/cnn_topstories.rss");
$mm_xsl2->setXSL("cnn_top_stories.xsl");
echo $mm_xsl2->Transform();
?>
//
//
//
 
/********************************* cnn_top_stories.xsl *******************************************/
<?php
$mm_xsl2 = new MM_XSLTransform();
$mm_xsl2->setXML("http://rss.cnn.com/rss/cnn_topstories.rss");
$mm_xsl2->setXSL("cnn_top_stories.xsl");
echo $mm_xsl2->Transform();
?>
<?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="http://rss.cnn.com/rss/cnn_topstories.rss" --><!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   "&#160;">
	<!ENTITY copy   "&#169;">
	<!ENTITY reg    "&#174;">
	<!ENTITY trade  "&#8482;">
	<!ENTITY mdash  "&#8212;">
	<!ENTITY ldquo  "&#8220;">
	<!ENTITY rdquo  "&#8221;"> 
	<!ENTITY pound  "&#163;">
	<!ENTITY yen    "&#165;">
	<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xmlns:thespringbox="http://www.thespringbox.com/dtds/thespringbox-1.0.dtd" xmlns:atom10="http://www.w3.org/2005/Atom">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="rss/channel/item">
  <xsl:if test="position() &lt;= 4">
    <h3><a href="{link}"><xsl:value-of select="title"/></a></h3>
    <p><xsl:value-of select="description" disable-output-escaping="yes"/></p>
  </xsl:if>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
//
//
//
 
/********************************* MM_XSLTransform.class.php *******************************************/
<?php
// MM_XSLTransform version: 0.6.3
 
// TODO: 
// maybe use socket connection instead of fopen url (check for timeout and status codes)
// if dom functions exists but xslt functions do not, prompt to install?
class MM_XSLTransform {
	
	var $xmlname;
	var $xslname;
	var $params;
	
	var $processor;
	
	var $myError;
	var $e;
	
	function MM_XSLTransform() {
		$this->params = array();
		$this->e = array(
											  	
// MM_XSLTransform errors 	
	'MM_GEN_ERROR' =>  'MM_XSLTransform error.<br>',
	'MM_NO_PROCESSOR_ERROR' =>  'The server could not perform the XSL transformation because an XSLT processor for PHP could not be found. Contact your server administrator and ask them to install an XSLT processor for PHP.',
	'MM_XML_EMPTY_ERROR' =>  'The XML source cannot be empty.',
	'MM_XSL_EMPTY_ERROR' =>  'The XSLT source cannot be empty.',
	'MM_OPEN_REMOTE_ERROR' =>  'Error opening %s.',
	'MM_HTTPS_OPEN_ERROR' =>  'Error opening %s. Possible causes are incorrect URL or lack of support for OpenSSL.',
	'MM_HTTPS_NOT_SUPPORTED_ERROR' =>  'Error opening %s. HTTPS protocol is supported starting from PHP 4.3.0.',
	'MM_OPEN_FILE_ERROR' =>  'The specified file %s could not be found.',
	'MM_FILE_NOT_READABLE_ERROR' =>  'The specified file %s is not readable.',
	'MM_INVALID_XML_ERROR' =>  '%s is not a valid XML document.<br>',
	'MM_CHECK_VALID_SAB_ERROR' =>  ' in file %s<br>',
	'MM_CHECK_VALID_D4_TAG_ERROR' =>  ' tag %s,',
	'MM_CHECK_VALID_D4_ERROR' =>  'Check%s line %s, column %s in file %s.<br>',
	'MM_CHECK_VALID_D5_ERROR' =>  ' in file %s.<br>',
	'MM_TRANSFORMATION_ERROR' =>  'Transformation Error.<br>',
	'MM_TRANSFORM_SAB_ERROR' =>  ' in file %s<br>',
	'MM_TRANSFORM_D4_ERROR' =>  ' in file %s<br>',
	'MM_TRANSFORM_D5_ERROR' =>  ' in file %s<br>',
// /MM_XSLTransform errors
 
		'' => ''
		);
	}
	
	function setXML($xml) {
		$this->xmlname = $xml;
	}
	
	function setXSL($xsl) {
		$this->xslname = $xsl;
	}
	
	function addParameter($paramName, $paramValue) {
		$this->params[$paramName] = $paramValue;
	}
	
	
	/**
	 * error handlinmg functions
	 */
	function setError($error) {
		$this->myError = $error;
	}
	
	function hasError() {
		if (strlen(trim($this->myError)) > 0) {
			return true;
		}
		return false;
	}
	
	function getError() {
		return $this->getErrorFromCode('MM_GEN_ERROR') . $this->myError;
	}
	
		function getRawError() {
			return $this->myError;
		}
	
		function getErrorFromCode($errCode, $args = array()) {
			$error = $this->e[$errCode];
			if ( count($args) > 0 ) {
				array_unshift($args, $error);
				$error = call_user_func_array('sprintf', $args);
			}
			return $error;
		}
	/**
	 * check for valid xml / xsl processors
	 */
	function checkProcessor() {
		$extensions = get_loaded_extensions();
		if (substr(PHP_VERSION, 0, 1) == '5') {
			if ( in_array('dom', $extensions) && in_array('xsl', $extensions) && class_exists('DOMDocument') && class_exists('XSLTProcessor') ) {
				$this->processor = 'domxml5';
				return;
			}
		}
		if (substr(PHP_VERSION, 0, 1) == '4' && substr(PHP_VERSION, 2, 1) > '2') {
			if ( in_array('xslt', $extensions) && function_exists('xslt_create')) {
				$this->processor = 'sablotron';
				return;
			}
			if ( in_array('domxml', $extensions) && function_exists('domxml_open_mem') && function_exists('domxml_xslt_stylesheet') ) {
				$this->processor = 'domxml4';
				return;
			}
		}
		if (substr(PHP_VERSION, 0, 1) == '4' && substr(PHP_VERSION, 2, 1) < '3') {
			if ( in_array('xslt', $extensions) && function_exists('xslt_create')) {
				$this->processor = 'sablotron';
				return;
			}
		}
		$this->processor = 'undefined';
		$this->setError($this->getErrorFromCode('MM_NO_PROCESSOR_ERROR'));
		return;
	}
	
	/**
	 * utilities
	 */
	function util_htmlentities($content) {
		return '<pre>' . htmlentities($content) . '</pre>';
	}
	
	function util_errorHandler($errNo, $errStr, $errFile, $errLine) {
		if (!$this->hasError()) {
			$myError = $errStr;
		} else {
			$myError = $this->getRawError();
			$myError .= '<br>' . $errStr;
		}
		$this->setError($myError);
		return;
	}
	
	/**
	 * core functions
	 */
	function checkInput() {
		if (!isset($this->xmlname) || strlen(trim($this->xmlname)) == 0) {
			$this->setError($this->getErrorFromCode('MM_XML_EMPTY_ERROR'));
		}
		if (!isset($this->xslname) || strlen(trim($this->xslname)) == 0) {
			$this->setError($this->getErrorFromCode('MM_XSL_EMPTY_ERROR'));
		}
	}
	
	function isURL(&$src) {
		$url_prefixes = array('http', 'https');
		$pos = strpos($src, '://');
		
		if ( $pos !== false && in_array(strtolower(substr($src, 0, $pos)), $url_prefixes) ) {
			return true;
		}
		return false;
	}
	
	function getRemoteFile(&$src) {
		$fileContent = '';
		
		$pos = strpos($src, '://');
		$protocol = strtolower(substr($src, 0, $pos));
		
		// avoid protocol upper case
		$mySrc = $protocol . substr($src, $pos);
		
		$magic_quotes_runtime_orig = get_magic_quotes_runtime();
		set_magic_quotes_runtime(0);
		if (!ini_get('allow_url_fopen')) {
			$ch = curl_init();
			$timeout = 0; // set to zero for no timeout
			curl_setopt ($ch, CURLOPT_URL, $mySrc);
			curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
			$fileContent = curl_exec($ch);
			curl_close($ch);
 
			if ($protocol == 'https') {
				$this->setError($this->getErrorFromCode('MM_HTTPS_OPEN_ERROR', array($src)));
				if ( (substr(PHP_VERSION, 0, 1) < 5) && (substr(PHP_VERSION, 2, 1) < 3) ) {
					$this->setError($this->getErrorFromCode('MM_HTTPS_NOT_SUPPORTED_ERROR', array($src)));
				}
			}
		}
		set_magic_quotes_runtime($magic_quotes_runtime_orig);
		return $fileContent;
	}
	
	function getLocalFile(&$src) {
		$fileContent = '';
		
		$mySrc = realpath($src);
		
		if (!file_exists($mySrc)) {
			$this->setError($this->getErrorFromCode('MM_OPEN_FILE_ERROR', array($src)));
			return $fileContent;
		}
		
		clearstatcache();
		if (!is_readable($mySrc)) {
			$this->setError($this->getErrorFromCode('MM_FILE_NOT_READABLE_ERROR', array($src)));
			return $fileContent;
		}
		
		$magic_quotes_runtime_orig = get_magic_quotes_runtime();
		set_magic_quotes_runtime(0);
		if ($myFile = fopen($mySrc, 'rb')) {
			while ($data = fread($myFile, 4096)) {
				$fileContent .= $data;
			}
			fclose($myFile);
		}
		set_magic_quotes_runtime($magic_quotes_runtime_orig);
		return $fileContent;
	}
	
	/**
	 * wrapper
	 */
	function checkValid(&$src, &$content, $type) {
		switch ($this->processor) {
			case 'domxml5':
				return $this->checkValid_domxml5($src, $content, $type);
				break;
			case 'domxml4':
				return $this->checkValid_domxml4($src, $content, $type);
				break;
			case 'sablotron':
				return $this->checkValid_sablotron($src, $content, $type);
				break;
		}
	}
	
		function checkValid_sablotron(&$src, &$content, $type) {
			$myError = '';
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$proc = xslt_create();
			$procArguments = array('/_xml' => $content, '/_xsl' => '<?xml version="1.0" encoding="UTF-8"?'.'><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>');
			@xslt_process($proc, 'arg:/_xml', 'arg:/_xsl', NULL, $procArguments);
			$myError = xslt_error($proc);
			xslt_free($proc);
			if ( strlen(trim($myError)) > 0 ) {
				if ($type == "xml") {
					$myError = $this->getErrorFromCode('MM_INVALID_XML_ERROR', array($src)) . $myError;
				} else {
					$myError = $this->getErrorFromCode('MM_INVALID_XSL_ERROR', array($src)) . $myError;
				}
				$myError .= $this->getErrorFromCode('MM_CHECK_VALID_SAB_ERROR');
				$myError .= $this->util_htmlentities($content);
				$this->setError($myError, array($src));
			}
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			return;
		}
		
		function checkValid_domxml4(&$src, &$content, $type) {
			$errors = array();
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			// PHP > 43
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
			if ($xml = @domxml_open_mem($content, DOMXML_LOAD_PARSING, $errors)) {
				if (method_exists($xml, 'free')) {
					$xml->free();
				}
			}
			restore_error_handler();
			error_reporting($old_error_reporting);
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			if (!$xml || count($errors) > 0 || $this->hasError()) {
				if ($type == "xml") {
					$myError = $this->getErrorFromCode('MM_INVALID_XML_ERROR', array($src));
				} else {
					$myError = $this->getErrorFromCode('MM_INVALID_XSL_ERROR', array($src));
				}
				if (count($errors) == 0) {
					$myError .= $this->getRawError();
				}
				foreach ($errors as $error) {
					$tag = '';
					if (isset($error['nodename'])) {
						$tag = $this->getErrorFromCode('MM_CHECK_VALID_D4_TAG_ERROR', array($error['nodename']));
					}
					$myError .= trim($error['errormessage']) . '. ' . $this->getErrorFromCode('MM_CHECK_VALID_D4_ERROR', array($tag, $error['line'], $error['col'], $src));
				}
				$this->setError($myError . $this->util_htmlentities($content));
			}
			return;
		}
	
		function checkValid_domxml5(&$src, &$content, $type) {
			$myError = '';
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
//			$xml = DOMDocument::loadXML($content);
            $doc = new DOMDocument();
            $err = $doc->loadXML($content);
			restore_error_handler();
			error_reporting($old_error_reporting);
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			if ($this->hasError()) {
				if ($type == "xml") {
					$myError = $this->getErrorFromCode('MM_INVALID_XML_ERROR', array($src));
				} else {
					$myError = $this->getErrorFromCode('MM_INVALID_XSL_ERROR', array($src));
				}
				$myError .= $this->getRawError();
				$this->setError($myError . $this->getErrorFromCode('MM_CHECK_VALID_D5_ERROR', array($src)) . $this->util_htmlentities($content));
			}
			return;
		}
	
	/**
	 * wrapper
	 */
	function transformDocument(&$xml, &$xsl, &$params) {
		switch ($this->processor) {
			case 'domxml5':
				return $this->transformDocument_domxml5($xml, $xsl, $params);
				break;
			case 'domxml4':
				return $this->transformDocument_domxml4($xml, $xsl, $params);
				break;
			case 'sablotron':
				return $this->transformDocument_sablotron($xml, $xsl, $params);
				break;
		}
	}
	
		function transformDocument_sablotron(&$xml, &$xsl, &$params) {
			$myError = '';
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$proc = xslt_create();
			$procArguments = array('/_xml' => $xml, '/_xsl' => $xsl);
			$output = @xslt_process($proc, 'arg:/_xml', 'arg:/_xsl', NULL, $procArguments, $params);
			$myError = xslt_error($proc);
			xslt_free($proc);
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			if ( strlen(trim($myError)) > 0 ) {
				$myError = $this->getErrorFromCode('MM_TRANSFORMATION_ERROR') . $myError;
				$myError .= $this->getErrorFromCode('MM_TRANSFORM_SAB_ERROR', array($this->xslname));
				$myError .= $this->util_htmlentities($xsl);
				$this->setError($myError);
				return;
			}
			return $output;
		}
		
		function transformDocument_domxml4(&$xml, &$xsl, &$params) {
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$xmlDom = domxml_open_mem($xml);
			$xslDom = domxml_open_mem($xsl);
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
			$xslDoc = domxml_xslt_stylesheet_doc($xslDom);
			$result = $xslDoc->process($xmlDom, $params);
			restore_error_handler();
			error_reporting($old_error_reporting);
			if ($this->hasError()) {
				$myError = $this->getErrorFromCode('MM_TRANSFORMATION_ERROR');
				$myError .= $this->getRawError();
				$myError .= $this->getErrorFromCode('MM_TRANSFORM_D4_ERROR', array($this->xslname));
				$myError .= $this->util_htmlentities($xsl);
				$this->setError($myError);
				set_magic_quotes_runtime($magic_quotes_runtime_orig);
				return;
			}
			$output = $result->dump_mem();
			if (method_exists($xmlDom, 'free')) {
				$xmlDom->free();
				$xslDom->free();
				$result->free();
			}
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			return $output;
		}
	
		function transformDocument_domxml5(&$xml, &$xsl, &$params) {
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$xmlDom = new DOMDocument;
			$xslDom = new DOMDocument;
			$xmlDom->loadXML($xml);
			$xslDom->loadXML($xsl);
			$proc = new XSLTProcessor;
			foreach ($params as $key => $value) {
				$proc->setParameter('', $key, $value);
			}
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
			$proc->importStyleSheet($xslDom);
			$result = $proc->transformToDoc($xmlDom);
			restore_error_handler();
			error_reporting($old_error_reporting);
			if ($this->hasError()) {
				$myError = $this->getErrorFromCode('MM_TRANSFORMATION_ERROR');
				$myError .= $this->getRawError();
				$myError .= $this->getErrorFromCode('MM_TRANSFORM_D5_ERROR', array($this->xslname));
				$myError .= $this->util_htmlentities($xsl);
				$this->setError($myError);
				set_magic_quotes_runtime($magic_quotes_runtime_orig);
				return;
			}
			$output = $result->saveXML();
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			return $output;
		}
	
	function Transform() {
		
		$this->checkProcessor();
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$this->checkInput();
		if ($this->hasError()) {
			return $this->getError();
		}
		
		if ($this->isURL($this->xmlname)) {
			$xml = $this->getRemoteFile($this->xmlname);
		} else {
			$xml = $this->getLocalFile($this->xmlname);
		}
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$xsl = $this->getLocalFile($this->xslname);
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$this->checkValid($this->xmlname, $xml, 'xml');
		if ($this->hasError()) {
			return $this->getError();
		}
		$this->checkValid($this->xslname, $xsl, 'xsl');
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$output = $this->transformDocument($xml, $xsl, $this->params);
		if ($this->hasError()) {
			return $this->getError();
		}
		
		return $output;
	}
}
 
?>

Open in new window

0
Comment
Question by:kentcommunications
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:kentcommunications
ID: 24817167
I just realized, for "MM_XSLTransform.class.php" I used the wrong version of the code. Here is the correct version for MM_XSLTransform.class.php
<?php
// MM_XSLTransform version: 0.6.3
 
// TODO: 
// maybe use socket connection instead of fopen url (check for timeout and status codes)
// if dom functions exists but xslt functions do not, prompt to install?
class MM_XSLTransform {
	
	var $xmlname;
	var $xslname;
	var $params;
	
	var $processor;
	
	var $myError;
	var $e;
	
	function MM_XSLTransform() {
		$this->params = array();
		$this->e = array(
											  	
// MM_XSLTransform errors 	
	'MM_GEN_ERROR' =>  'MM_XSLTransform error.<br>',
	'MM_NO_PROCESSOR_ERROR' =>  'The server could not perform the XSL transformation because an XSLT processor for PHP could not be found. Contact your server administrator and ask them to install an XSLT processor for PHP.',
	'MM_XML_EMPTY_ERROR' =>  'The XML source cannot be empty.',
	'MM_XSL_EMPTY_ERROR' =>  'The XSLT source cannot be empty.',
	'MM_OPEN_REMOTE_ERROR' =>  'Error opening %s.',
	'MM_HTTPS_OPEN_ERROR' =>  'Error opening %s. Possible causes are incorrect URL or lack of support for OpenSSL.',
	'MM_HTTPS_NOT_SUPPORTED_ERROR' =>  'Error opening %s. HTTPS protocol is supported starting from PHP 4.3.0.',
	'MM_OPEN_FILE_ERROR' =>  'The specified file %s could not be found.',
	'MM_FILE_NOT_READABLE_ERROR' =>  'The specified file %s is not readable.',
	'MM_INVALID_XML_ERROR' =>  '%s is not a valid XML document.<br>',
	'MM_CHECK_VALID_SAB_ERROR' =>  ' in file %s<br>',
	'MM_CHECK_VALID_D4_TAG_ERROR' =>  ' tag %s,',
	'MM_CHECK_VALID_D4_ERROR' =>  'Check%s line %s, column %s in file %s.<br>',
	'MM_CHECK_VALID_D5_ERROR' =>  ' in file %s.<br>',
	'MM_TRANSFORMATION_ERROR' =>  'Transformation Error.<br>',
	'MM_TRANSFORM_SAB_ERROR' =>  ' in file %s<br>',
	'MM_TRANSFORM_D4_ERROR' =>  ' in file %s<br>',
	'MM_TRANSFORM_D5_ERROR' =>  ' in file %s<br>',
// /MM_XSLTransform errors
 
		'' => ''
		);
	}
	
	function setXML($xml) {
		$this->xmlname = $xml;
	}
	
	function setXSL($xsl) {
		$this->xslname = $xsl;
	}
	
	function addParameter($paramName, $paramValue) {
		$this->params[$paramName] = $paramValue;
	}
	
	
	/**
	 * error handlinmg functions
	 */
	function setError($error) {
		$this->myError = $error;
	}
	
	function hasError() {
		if (strlen(trim($this->myError)) > 0) {
			return true;
		}
		return false;
	}
	
	function getError() {
		return $this->getErrorFromCode('MM_GEN_ERROR') . $this->myError;
	}
	
		function getRawError() {
			return $this->myError;
		}
	
		function getErrorFromCode($errCode, $args = array()) {
			$error = $this->e[$errCode];
			if ( count($args) > 0 ) {
				array_unshift($args, $error);
				$error = call_user_func_array('sprintf', $args);
			}
			return $error;
		}
	/**
	 * check for valid xml / xsl processors
	 */
	function checkProcessor() {
		$extensions = get_loaded_extensions();
		if (substr(PHP_VERSION, 0, 1) == '5') {
			if ( in_array('dom', $extensions) && in_array('xsl', $extensions) && class_exists('DOMDocument') && class_exists('XSLTProcessor') ) {
				$this->processor = 'domxml5';
				return;
			}
		}
		if (substr(PHP_VERSION, 0, 1) == '4' && substr(PHP_VERSION, 2, 1) > '2') {
			if ( in_array('xslt', $extensions) && function_exists('xslt_create')) {
				$this->processor = 'sablotron';
				return;
			}
			if ( in_array('domxml', $extensions) && function_exists('domxml_open_mem') && function_exists('domxml_xslt_stylesheet') ) {
				$this->processor = 'domxml4';
				return;
			}
		}
		if (substr(PHP_VERSION, 0, 1) == '4' && substr(PHP_VERSION, 2, 1) < '3') {
			if ( in_array('xslt', $extensions) && function_exists('xslt_create')) {
				$this->processor = 'sablotron';
				return;
			}
		}
		$this->processor = 'undefined';
		$this->setError($this->getErrorFromCode('MM_NO_PROCESSOR_ERROR'));
		return;
	}
	
	/**
	 * utilities
	 */
	function util_htmlentities($content) {
		return '<pre>' . htmlentities($content) . '</pre>';
	}
	
	function util_errorHandler($errNo, $errStr, $errFile, $errLine) {
		if (!$this->hasError()) {
			$myError = $errStr;
		} else {
			$myError = $this->getRawError();
			$myError .= '<br>' . $errStr;
		}
		$this->setError($myError);
		return;
	}
	
	/**
	 * core functions
	 */
	function checkInput() {
		if (!isset($this->xmlname) || strlen(trim($this->xmlname)) == 0) {
			$this->setError($this->getErrorFromCode('MM_XML_EMPTY_ERROR'));
		}
		if (!isset($this->xslname) || strlen(trim($this->xslname)) == 0) {
			$this->setError($this->getErrorFromCode('MM_XSL_EMPTY_ERROR'));
		}
	}
	
	function isURL(&$src) {
		$url_prefixes = array('http', 'https');
		$pos = strpos($src, '://');
		
		if ( $pos !== false && in_array(strtolower(substr($src, 0, $pos)), $url_prefixes) ) {
			return true;
		}
		return false;
	}
	
	function getRemoteFile(&$src) {
		$fileContent = '';
		
		$pos = strpos($src, '://');
		$protocol = strtolower(substr($src, 0, $pos));
		
		// avoid protocol upper case
		$mySrc = $protocol . substr($src, $pos);
		
		$magic_quotes_runtime_orig = get_magic_quotes_runtime();
		set_magic_quotes_runtime(0);
		if (!ini_get('allow_url_fopen')) {
			$ch = curl_init();
			$timeout = 0; // set to zero for no timeout
			curl_setopt ($ch, CURLOPT_URL, $mySrc);
			curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
			$fileContent = curl_exec($ch);
			curl_close($ch);
 
			if ($protocol == 'https') {
				$this->setError($this->getErrorFromCode('MM_HTTPS_OPEN_ERROR', array($src)));
				if ( (substr(PHP_VERSION, 0, 1) < 5) && (substr(PHP_VERSION, 2, 1) < 3) ) {
					$this->setError($this->getErrorFromCode('MM_HTTPS_NOT_SUPPORTED_ERROR', array($src)));
				}
			}
		}
		set_magic_quotes_runtime($magic_quotes_runtime_orig);
		return $fileContent;
	}
	
	function getLocalFile(&$src) {
		$fileContent = '';
		
		$mySrc = realpath($src);
		
		if (!file_exists($mySrc)) {
			$this->setError($this->getErrorFromCode('MM_OPEN_FILE_ERROR', array($src)));
			return $fileContent;
		}
		
		clearstatcache();
		if (!is_readable($mySrc)) {
			$this->setError($this->getErrorFromCode('MM_FILE_NOT_READABLE_ERROR', array($src)));
			return $fileContent;
		}
		
		$magic_quotes_runtime_orig = get_magic_quotes_runtime();
		set_magic_quotes_runtime(0);
		if ($myFile = fopen($mySrc, 'rb')) {
			while ($data = fread($myFile, 4096)) {
				$fileContent .= $data;
			}
			fclose($myFile);
		}
		set_magic_quotes_runtime($magic_quotes_runtime_orig);
		return $fileContent;
	}
	
	/**
	 * wrapper
	 */
	function checkValid(&$src, &$content, $type) {
		switch ($this->processor) {
			case 'domxml5':
				return $this->checkValid_domxml5($src, $content, $type);
				break;
			case 'domxml4':
				return $this->checkValid_domxml4($src, $content, $type);
				break;
			case 'sablotron':
				return $this->checkValid_sablotron($src, $content, $type);
				break;
		}
	}
	
		function checkValid_sablotron(&$src, &$content, $type) {
			$myError = '';
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$proc = xslt_create();
			$procArguments = array('/_xml' => $content, '/_xsl' => '<?xml version="1.0" encoding="UTF-8"?'.'><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>');
			@xslt_process($proc, 'arg:/_xml', 'arg:/_xsl', NULL, $procArguments);
			$myError = xslt_error($proc);
			xslt_free($proc);
			if ( strlen(trim($myError)) > 0 ) {
				if ($type == "xml") {
					$myError = $this->getErrorFromCode('MM_INVALID_XML_ERROR', array($src)) . $myError;
				} else {
					$myError = $this->getErrorFromCode('MM_INVALID_XSL_ERROR', array($src)) . $myError;
				}
				$myError .= $this->getErrorFromCode('MM_CHECK_VALID_SAB_ERROR');
				$myError .= $this->util_htmlentities($content);
				$this->setError($myError, array($src));
			}
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			return;
		}
		
		function checkValid_domxml4(&$src, &$content, $type) {
			$errors = array();
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			// PHP > 43
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
			if ($xml = @domxml_open_mem($content, DOMXML_LOAD_PARSING, $errors)) {
				if (method_exists($xml, 'free')) {
					$xml->free();
				}
			}
			restore_error_handler();
			error_reporting($old_error_reporting);
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			if (!$xml || count($errors) > 0 || $this->hasError()) {
				if ($type == "xml") {
					$myError = $this->getErrorFromCode('MM_INVALID_XML_ERROR', array($src));
				} else {
					$myError = $this->getErrorFromCode('MM_INVALID_XSL_ERROR', array($src));
				}
				if (count($errors) == 0) {
					$myError .= $this->getRawError();
				}
				foreach ($errors as $error) {
					$tag = '';
					if (isset($error['nodename'])) {
						$tag = $this->getErrorFromCode('MM_CHECK_VALID_D4_TAG_ERROR', array($error['nodename']));
					}
					$myError .= trim($error['errormessage']) . '. ' . $this->getErrorFromCode('MM_CHECK_VALID_D4_ERROR', array($tag, $error['line'], $error['col'], $src));
				}
				$this->setError($myError . $this->util_htmlentities($content));
			}
			return;
		}
	
		function checkValid_domxml5(&$src, &$content, $type) {
			$myError = '';
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
//			$xml = DOMDocument::loadXML($content);
            $doc = new DOMDocument();
            $err = $doc->loadXML($content);
			restore_error_handler();
			error_reporting($old_error_reporting);
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			if ($this->hasError()) {
				if ($type == "xml") {
					$myError = $this->getErrorFromCode('MM_INVALID_XML_ERROR', array($src));
				} else {
					$myError = $this->getErrorFromCode('MM_INVALID_XSL_ERROR', array($src));
				}
				$myError .= $this->getRawError();
				$this->setError($myError . $this->getErrorFromCode('MM_CHECK_VALID_D5_ERROR', array($src)) . $this->util_htmlentities($content));
			}
			return;
		}
	
	/**
	 * wrapper
	 */
	function transformDocument(&$xml, &$xsl, &$params) {
		switch ($this->processor) {
			case 'domxml5':
				return $this->transformDocument_domxml5($xml, $xsl, $params);
				break;
			case 'domxml4':
				return $this->transformDocument_domxml4($xml, $xsl, $params);
				break;
			case 'sablotron':
				return $this->transformDocument_sablotron($xml, $xsl, $params);
				break;
		}
	}
	
		function transformDocument_sablotron(&$xml, &$xsl, &$params) {
			$myError = '';
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$proc = xslt_create();
			$procArguments = array('/_xml' => $xml, '/_xsl' => $xsl);
			$output = @xslt_process($proc, 'arg:/_xml', 'arg:/_xsl', NULL, $procArguments, $params);
			$myError = xslt_error($proc);
			xslt_free($proc);
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			if ( strlen(trim($myError)) > 0 ) {
				$myError = $this->getErrorFromCode('MM_TRANSFORMATION_ERROR') . $myError;
				$myError .= $this->getErrorFromCode('MM_TRANSFORM_SAB_ERROR', array($this->xslname));
				$myError .= $this->util_htmlentities($xsl);
				$this->setError($myError);
				return;
			}
			return $output;
		}
		
		function transformDocument_domxml4(&$xml, &$xsl, &$params) {
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$xmlDom = domxml_open_mem($xml);
			$xslDom = domxml_open_mem($xsl);
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
			$xslDoc = domxml_xslt_stylesheet_doc($xslDom);
			$result = $xslDoc->process($xmlDom, $params);
			restore_error_handler();
			error_reporting($old_error_reporting);
			if ($this->hasError()) {
				$myError = $this->getErrorFromCode('MM_TRANSFORMATION_ERROR');
				$myError .= $this->getRawError();
				$myError .= $this->getErrorFromCode('MM_TRANSFORM_D4_ERROR', array($this->xslname));
				$myError .= $this->util_htmlentities($xsl);
				$this->setError($myError);
				set_magic_quotes_runtime($magic_quotes_runtime_orig);
				return;
			}
			$output = $result->dump_mem();
			if (method_exists($xmlDom, 'free')) {
				$xmlDom->free();
				$xslDom->free();
				$result->free();
			}
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			return $output;
		}
	
		function transformDocument_domxml5(&$xml, &$xsl, &$params) {
			$magic_quotes_runtime_orig = get_magic_quotes_runtime();
			set_magic_quotes_runtime(0);
			$xmlDom = new DOMDocument;
			$xslDom = new DOMDocument;
			$xmlDom->loadXML($xml);
			$xslDom->loadXML($xsl);
			$proc = new XSLTProcessor;
			foreach ($params as $key => $value) {
				$proc->setParameter('', $key, $value);
			}
			$old_error_reporting = error_reporting(E_ALL);
			//$old_error_handler = set_error_handler(array(&$this, 'util_errorHandler'));
			$proc->importStyleSheet($xslDom);
			$result = $proc->transformToDoc($xmlDom);
			restore_error_handler();
			error_reporting($old_error_reporting);
			if ($this->hasError()) {
				$myError = $this->getErrorFromCode('MM_TRANSFORMATION_ERROR');
				$myError .= $this->getRawError();
				$myError .= $this->getErrorFromCode('MM_TRANSFORM_D5_ERROR', array($this->xslname));
				$myError .= $this->util_htmlentities($xsl);
				$this->setError($myError);
				set_magic_quotes_runtime($magic_quotes_runtime_orig);
				return;
			}
			$output = $result->saveXML();
			set_magic_quotes_runtime($magic_quotes_runtime_orig);
			return $output;
		}
	
	function Transform() {
		
		$this->checkProcessor();
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$this->checkInput();
		if ($this->hasError()) {
			return $this->getError();
		}
		
		if ($this->isURL($this->xmlname)) {
			$xml = $this->getRemoteFile($this->xmlname);
		} else {
			$xml = $this->getLocalFile($this->xmlname);
		}
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$xsl = $this->getLocalFile($this->xslname);
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$this->checkValid($this->xmlname, $xml, 'xml');
		if ($this->hasError()) {
			return $this->getError();
		}
		$this->checkValid($this->xslname, $xsl, 'xsl');
		if ($this->hasError()) {
			return $this->getError();
		}
		
		$output = $this->transformDocument($xml, $xsl, $this->params);
		if ($this->hasError()) {
			return $this->getError();
		}
		
		return $output;
	}
}
 
?>

Open in new window

0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24818529
Well, I may not be able to help very much, but I could not help laughing out loud at "a Windows hosing account" - exactly my experience with Windows on GoDaddy!

;-)

Have you used phpinfo() to see if there are any XSL modules installed?  On my server, I have this:

'--with-xsl=/opt/xslt/'

XSL       enabled
libxslt Version       1.1.24
libxslt compiled against libxml Version       2.7.2
EXSLT       enabled
libexslt Version       1.1.24
0
 

Author Closing Comment

by:kentcommunications
ID: 31601765
Had to contact GoDaddy and get them to fix it from their end. thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question