2008-01-30 20:33:16 +00:00
|
|
|
|
<?php
|
2006-12-02 04:36:16 +00:00
|
|
|
|
/*
|
|
|
|
|
+ ----------------------------------------------------------------------------+
|
|
|
|
|
| e107 website system
|
|
|
|
|
|
|
|
|
|
|
| <EFBFBD>Steve Dunstan 2001-2002
|
|
|
|
|
| http://e107.org
|
|
|
|
|
| jalist@e107.org
|
|
|
|
|
|
|
|
|
|
|
| Released under the terms and conditions of the
|
|
|
|
|
| GNU General Public License (http://gnu.org).
|
|
|
|
|
|
|
|
|
|
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/xml_class.php,v $
|
2008-01-30 20:33:16 +00:00
|
|
|
|
| $Revision: 1.4 $
|
|
|
|
|
| $Date: 2008-01-30 20:33:16 $
|
|
|
|
|
| $Author: secretr $
|
2006-12-02 04:36:16 +00:00
|
|
|
|
+----------------------------------------------------------------------------+
|
|
|
|
|
*/
|
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
class xmlClass
|
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
|
var $xmlFileContents;
|
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
function getRemoteFile($address)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if(function_exists('file_get_contents'))
|
|
|
|
|
{
|
|
|
|
|
if($data = file_get_contents($address))
|
|
|
|
|
{
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
if(function_exists("curl_init"))
|
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$cu = curl_init ();
|
2006-12-02 04:36:16 +00:00
|
|
|
|
curl_setopt($cu, CURLOPT_URL, $address);
|
|
|
|
|
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
curl_setopt ($cu, CURLOPT_HEADER, 0);
|
|
|
|
|
curl_setopt ($cu, CURLOPT_TIMEOUT, 10);
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$this->xmlFileContents = curl_exec($cu);
|
2006-12-02 04:36:16 +00:00
|
|
|
|
if (curl_error($cu))
|
|
|
|
|
{
|
|
|
|
|
$this -> error = "Error: ".curl_errno($cu).", ".curl_error($cu);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
curl_close ($cu);
|
2008-01-20 04:46:35 +00:00
|
|
|
|
return $this->xmlFileContents;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ini_get("allow_url_fopen"))
|
|
|
|
|
{
|
|
|
|
|
if(!$remote = @fopen ($address, "r"))
|
|
|
|
|
{
|
|
|
|
|
$this -> error = "Unable to open remote XML file.";
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$tmp = parse_url($address);
|
|
|
|
|
if(!$remote = fsockopen ($tmp['host'], 80 ,$errno, $errstr, 10))
|
|
|
|
|
{
|
|
|
|
|
$this -> error = "Unable to open remote XML file.";
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
socket_set_timeout($remote, 10);
|
|
|
|
|
fputs($remote, "GET ".$headline_url." HTTP/1.0\r\n\r\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this -> xmlFileContents = "";
|
|
|
|
|
while (!feof($remote))
|
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$this->xmlFileContents .= fgets ($remote, 4096);
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
fclose ($remote);
|
2008-01-20 04:46:35 +00:00
|
|
|
|
return $this->xmlFileContents;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
function parseXml($xml='')
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if($xml == '' && $this->xmlFileContents)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$xml = $this->xmlFileContents;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if(!$xml)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
return false;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$xml = simplexml_load_string($xml);
|
|
|
|
|
if(is_object($xml))
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$xml = (array)$xml;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$xml = $this->xml_convert_to_array($xml);
|
|
|
|
|
return $xml;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
function xml_convert_to_array($xml)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if(is_array($xml))
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
foreach($xml as $k => $v)
|
|
|
|
|
{
|
|
|
|
|
if(is_object($v))
|
|
|
|
|
{
|
|
|
|
|
$v = (array)$v;
|
|
|
|
|
}
|
|
|
|
|
$xml[$k] = $this->xml_convert_to_array($v);
|
|
|
|
|
}
|
|
|
|
|
if(count($xml) == 1 && isset($xml[0]))
|
|
|
|
|
{
|
|
|
|
|
$xml = $xml[0];
|
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
return $xml;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
function loadXMLfile($fname='', $parse = false)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
|
|
|
|
|
if($fname == '')
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
return false;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$xml = false;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if(strpos($filename, '://') !== false)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
$this->getRemoteFile($fname);
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
else
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if($xml = file_get_contents($fname))
|
|
|
|
|
{
|
|
|
|
|
$this->xmlFileContents = $xml;
|
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if($this->xmlFileContents)
|
2006-12-02 04:36:16 +00:00
|
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
|
if($parse == true)
|
|
|
|
|
{
|
|
|
|
|
return $this->parseXML();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return $this->xmlFileContents;
|
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
return false;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-30 20:33:16 +00:00
|
|
|
|
}
|
|
|
|
|
?>
|