mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +02:00
Remote communication rewrite (still in progress); Experimental XML
parser (testing phase)
This commit is contained in:
@@ -271,7 +271,7 @@ class e_marketplace_adapter_wsdl extends e_marketplace_adapter_abstract
|
|||||||
* e107.org WSDL URL
|
* e107.org WSDL URL
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $wsdl = 'http://e107.org/e107_plugins/addons/service.php?wsdl';
|
protected $wsdl = 'http://e107.org/service?wsdl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Soap client instance
|
* Soap client instance
|
||||||
@@ -296,7 +296,7 @@ class e_marketplace_adapter_wsdl extends e_marketplace_adapter_abstract
|
|||||||
|
|
||||||
if(function_exists('xdebug_disable'))
|
if(function_exists('xdebug_disable'))
|
||||||
{
|
{
|
||||||
//xdebug_disable();
|
xdebug_disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +404,9 @@ class e_marketplace_adapter_xmlrpc extends e_marketplace_adapter_abstract
|
|||||||
* e107.org XML-rpc service
|
* e107.org XML-rpc service
|
||||||
* @var xmlClass
|
* @var xmlClass
|
||||||
*/
|
*/
|
||||||
protected $url = 'http://e107.org/e107_plugins/addons/xservice.php';
|
protected $url = 'http://e107.org/xservice';
|
||||||
|
|
||||||
|
protected $_forceArray = array();
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -420,7 +422,7 @@ class e_marketplace_adapter_xmlrpc extends e_marketplace_adapter_abstract
|
|||||||
$client = $this->client();
|
$client = $this->client();
|
||||||
|
|
||||||
// settings based on current method
|
// settings based on current method
|
||||||
$this->prepareClient($client);
|
$this->prepareClient($method, $client);
|
||||||
|
|
||||||
// authorization data
|
// authorization data
|
||||||
$data['auth'] = $this->getAuthKey();
|
$data['auth'] = $this->getAuthKey();
|
||||||
@@ -430,27 +432,149 @@ class e_marketplace_adapter_xmlrpc extends e_marketplace_adapter_abstract
|
|||||||
$qry = str_replace(array('s%5B', '%5D'), array('[', ']'), http_build_query($data, null, '&'));
|
$qry = str_replace(array('s%5B', '%5D'), array('[', ']'), http_build_query($data, null, '&'));
|
||||||
$url = $this->url.'?'.$qry;
|
$url = $this->url.'?'.$qry;
|
||||||
|
|
||||||
|
|
||||||
// call it
|
// call it
|
||||||
$result = $client->loadXMLfile($url,'advanced');
|
$xmlString = $client->loadXMLfile($url,false);
|
||||||
//var_dump($url, $result);
|
$result = new SimpleXMLIterator($xmlString);
|
||||||
return $result;
|
//$result = $client->loadXMLfile($url, 'advanced');
|
||||||
|
|
||||||
|
return $this->fetch($method, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetch($method, &$result)
|
public function fetch($method, &$result)
|
||||||
{
|
{
|
||||||
|
$ret = $this->parse($result);
|
||||||
|
$this->fetchParams($ret);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New experimental XML parser, will be moved to XML handlers soon
|
||||||
|
* XXX replace xmlClass::xml2array() after this one passes all tests
|
||||||
|
* @param SimpleXmlIterator $xml
|
||||||
|
* @param string $parentName parent node name - used currently for debug only
|
||||||
|
*/
|
||||||
|
public function parse($xml, $parentName = null)
|
||||||
|
{
|
||||||
|
$ret = array();
|
||||||
|
$tags = array_keys(get_object_vars($xml));
|
||||||
|
$count = $xml->count();
|
||||||
|
$tcount = count($tags);
|
||||||
|
|
||||||
|
if($count === 0)
|
||||||
|
{
|
||||||
|
$attr = (array) $xml->attributes();
|
||||||
|
if(!empty($attr))
|
||||||
|
{
|
||||||
|
$ret['@attributes'] = $attr['@attributes'];
|
||||||
|
$ret['@value'] = (string) $xml;
|
||||||
|
$ret['@value'] = trim($ret['@value']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ret = (string) $xml;
|
||||||
|
$ret = trim($ret);
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <key>
|
||||||
|
* <value />
|
||||||
|
* <value />
|
||||||
|
* </key>
|
||||||
|
*/
|
||||||
|
if($tcount === 1 && $count > 1)
|
||||||
|
{
|
||||||
|
foreach ($xml as $name => $node)
|
||||||
|
{
|
||||||
|
$_res = $this->parse($node, $name);
|
||||||
|
if(is_string($_res)) $_res = trim($res);
|
||||||
|
|
||||||
|
$ret[$name][] = $this->parse($node, $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// default
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach ($xml as $name => $node)
|
||||||
|
{
|
||||||
|
if(in_array($name, $this->_forceArray))
|
||||||
|
{
|
||||||
|
$_res = $this->parse($node, $name);
|
||||||
|
if(is_string($_res)) $_res = trim($res);
|
||||||
|
|
||||||
|
if(empty($_res)) $ret[$name] = array();
|
||||||
|
elseif(is_string($_res)) $ret[$name][] = $_res;
|
||||||
|
else $ret[$name] = $_res; //array
|
||||||
|
}
|
||||||
|
else $ret[$name] = $this->parse($node, $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$attr = (array) $xml->attributes();
|
||||||
|
if(!empty($attr))
|
||||||
|
{
|
||||||
|
$ret['@attributes'] = $attr['@attributes'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize parameters/attributes
|
||||||
|
* @param array $result parsed to array XML response data
|
||||||
|
*/
|
||||||
|
public function fetchParams(&$result)
|
||||||
|
{
|
||||||
|
foreach ($result as $tag => $data)
|
||||||
|
{
|
||||||
|
if($tag === 'params')
|
||||||
|
{
|
||||||
|
foreach ($data['param'] as $param)
|
||||||
|
{
|
||||||
|
$result[$tag][$param['@attributes']['name']] = $param['@value'];
|
||||||
|
unset($result[$tag]['param'][$i]);
|
||||||
|
}
|
||||||
|
unset($result[$tag]['param']);
|
||||||
|
}
|
||||||
|
elseif($tag === 'exception')
|
||||||
|
{
|
||||||
|
$result['exception'] = array('code' => (int) $result['exception']['@attributes']['code'], 'message' => $result['exception']['@value']);
|
||||||
|
//unset($result['exception']);
|
||||||
|
}
|
||||||
|
elseif($tag === '@attributes')
|
||||||
|
{
|
||||||
|
$result['params'] = $result['@attributes'];
|
||||||
|
unset($result['@attributes']);
|
||||||
|
}
|
||||||
|
elseif(is_array($result[$tag]))
|
||||||
|
{
|
||||||
|
$this->fetchParams($result[$tag]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $method
|
||||||
|
* @param xmlClass $client
|
||||||
|
*/
|
||||||
public function prepareClient($method, &$client)
|
public function prepareClient($method, &$client)
|
||||||
{
|
{
|
||||||
switch ($method)
|
switch ($method)
|
||||||
{
|
{
|
||||||
case 'getList':
|
case 'getList':
|
||||||
$client->setOptArrayTags('plugin');
|
$this->_forceArray = array('item', 'screenshots', 'image');
|
||||||
|
//$client->setOptArrayTags('item,screenshots,image')
|
||||||
|
// ->setOptStringTags('icon,folder,version,author,authorURL,date,compatibility,url,thumbnail,featured,livedemo,price,name,description,category,image');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return xmlClass
|
||||||
|
*/
|
||||||
public function client()
|
public function client()
|
||||||
{
|
{
|
||||||
return e107::getXml(false);
|
return e107::getXml(false);
|
||||||
|
@@ -473,7 +473,8 @@ class xmlClass
|
|||||||
* Advanced XML parser - handles tags with attributes and values
|
* Advanced XML parser - handles tags with attributes and values
|
||||||
* properly.
|
* properly.
|
||||||
* TODO - filter (see xml_convert_to_array)
|
* TODO - filter (see xml_convert_to_array)
|
||||||
*
|
* FIXME can't handle multi-dimensional associative arrays (e.g. <screnshots><image>...</image><image>...</image></screenshots> to screenshots[image] = array(...))
|
||||||
|
* XXX New parser in testing phase - see e_marketplace::parse()
|
||||||
* @param SimpleXMLElement $xml
|
* @param SimpleXMLElement $xml
|
||||||
* @param string $rec_parent used for recursive calls only
|
* @param string $rec_parent used for recursive calls only
|
||||||
* @return array
|
* @return array
|
||||||
@@ -570,7 +571,8 @@ class xmlClass
|
|||||||
else $ret[$tag] = '';
|
else $ret[$tag] = '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$count = count($xml->{$tag});
|
|
||||||
|
$count = $xml->{$tag}->count();
|
||||||
if($count >= 1) //array of elements - loop
|
if($count >= 1) //array of elements - loop
|
||||||
{
|
{
|
||||||
for ($i = 0; $i < $count; $i++)
|
for ($i = 0; $i < $count; $i++)
|
||||||
|
Reference in New Issue
Block a user