PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/class/rssparser.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 775 lines | 509 code | 74 blank | 192 comment | 119 complexity | f0d0574f7f32e941b80c3ea9d3209156 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2011-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/class/rssparser.class.php
  19. * \ingroup core
  20. * \brief File of class to parse RSS feeds
  21. */
  22. /**
  23. * Class to parse RSS files
  24. */
  25. class RssParser
  26. {
  27. var $db;
  28. var $error;
  29. private $_format='';
  30. private $_urlRSS;
  31. private $_language;
  32. private $_generator;
  33. private $_copyright;
  34. private $_lastbuilddate;
  35. private $_imageurl;
  36. private $_link;
  37. private $_title;
  38. private $_description;
  39. private $_lastfetchdate; // Last successful fetch
  40. private $_rssarray=array();
  41. // For parsing with xmlparser
  42. var $stack = array(); // parser stack
  43. var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
  44. /**
  45. * Constructor
  46. *
  47. * @param DoliDB $db Database handler
  48. */
  49. public function __construct($db = '')
  50. {
  51. $this->db=$db;
  52. }
  53. /**
  54. * getFormat
  55. *
  56. * @return string
  57. */
  58. public function getFormat()
  59. {
  60. return $this->_format;
  61. }
  62. /**
  63. * getUrlRss
  64. *
  65. * @return string
  66. */
  67. public function getUrlRss()
  68. {
  69. return $this->_urlRSS;
  70. }
  71. /**
  72. * getLanguage
  73. *
  74. * @return string
  75. */
  76. public function getLanguage()
  77. {
  78. return $this->_language;
  79. }
  80. /**
  81. * getGenerator
  82. *
  83. * @return string
  84. */
  85. public function getGenerator()
  86. {
  87. return $this->_generator;
  88. }
  89. /**
  90. * getCopyright
  91. *
  92. * @return string
  93. */
  94. public function getCopyright()
  95. {
  96. return $this->_copyright;
  97. }
  98. /**
  99. * getLastBuildDate
  100. *
  101. * @return string
  102. */
  103. public function getLastBuildDate()
  104. {
  105. return $this->_lastbuilddate;
  106. }
  107. /**
  108. * getImageUrl
  109. *
  110. * @return string
  111. */
  112. public function getImageUrl()
  113. {
  114. return $this->_imageurl;
  115. }
  116. /**
  117. * getLink
  118. *
  119. * @return string
  120. */
  121. public function getLink()
  122. {
  123. return $this->_link;
  124. }
  125. /**
  126. * getTitle
  127. *
  128. * @return string
  129. */
  130. public function getTitle()
  131. {
  132. return $this->_title;
  133. }
  134. /**
  135. * getDescription
  136. *
  137. * @return string
  138. */
  139. public function getDescription()
  140. {
  141. return $this->_description;
  142. }
  143. /**
  144. * getLastFetchDate
  145. *
  146. * @return string
  147. */
  148. public function getLastFetchDate()
  149. {
  150. return $this->_lastfetchdate;
  151. }
  152. /**
  153. * getItems
  154. *
  155. * @return string
  156. */
  157. public function getItems()
  158. {
  159. return $this->_rssarray;
  160. }
  161. /**
  162. * Parse rss URL
  163. *
  164. * @param string $urlRSS Url to parse
  165. * @param int $maxNb Max nb of records to get (0 for no limit)
  166. * @param int $cachedelay 0=No cache, nb of seconds we accept cache files (cachedir must also be defined)
  167. * @param strnig $cachedir Directory where to save cache file
  168. * @return int <0 if KO, >0 if OK
  169. */
  170. public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
  171. {
  172. global $conf;
  173. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  174. $str=''; // This will contain content of feed
  175. // Check parameters
  176. if (! dol_is_url($urlRSS))
  177. {
  178. $this->error="ErrorBadUrl";
  179. return -1;
  180. }
  181. $this->_urlRSS = $urlRSS;
  182. $newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS);
  183. $newmask='0644';
  184. //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
  185. $nowgmt = dol_now();
  186. // Search into cache
  187. $foundintocache=0;
  188. if ($cachedelay > 0 && $cachedir)
  189. {
  190. $filedate=dol_filemtime($newpathofdestfile);
  191. if ($filedate >= ($nowgmt - $cachedelay))
  192. {
  193. //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
  194. $foundintocache=1;
  195. $this->_lastfetchdate=$filedate;
  196. }
  197. else
  198. {
  199. dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
  200. }
  201. }
  202. // Load file into $str
  203. if ($foundintocache) // Cache file found and is not too old
  204. {
  205. $str = file_get_contents($newpathofdestfile);
  206. }
  207. else
  208. {
  209. try {
  210. ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
  211. ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
  212. ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
  213. $opts = array('http'=>array('method'=>"GET"));
  214. if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
  215. if (! empty($conf->global->MAIN_PROXY_USE)) $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
  216. //var_dump($opts);exit;
  217. $context = stream_context_create($opts);
  218. // FIXME avoid error if no connection
  219. $str = file_get_contents($this->_urlRSS, false, $context);
  220. }
  221. catch (Exception $e) {
  222. print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
  223. }
  224. }
  225. // Convert $str into xml
  226. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
  227. {
  228. //print 'xx'.LIBXML_NOCDATA;
  229. libxml_use_internal_errors(false);
  230. $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
  231. }
  232. else
  233. {
  234. $xmlparser=xml_parser_create('');
  235. if (!is_resource($xmlparser)) {
  236. $this->error="ErrorFailedToCreateParser"; return -1;
  237. }
  238. xml_set_object($xmlparser, $this);
  239. xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element');
  240. xml_set_character_data_handler($xmlparser, 'feed_cdata');
  241. $status = xml_parse($xmlparser, $str);
  242. xml_parser_free($xmlparser);
  243. $rss=$this;
  244. //var_dump($rss->_format);exit;
  245. }
  246. // If $rss loaded
  247. if ($rss)
  248. {
  249. // Save file into cache
  250. if (empty($foundintocache) && $cachedir)
  251. {
  252. dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is saved onto disk.");
  253. if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
  254. $fp = fopen($newpathofdestfile, 'w');
  255. fwrite($fp, $str);
  256. fclose($fp);
  257. if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
  258. @chmod($newpathofdestfile, octdec($newmask));
  259. $this->_lastfetchdate=$nowgmt;
  260. }
  261. unset($str); // Free memory
  262. if (empty($rss->_format)) // If format not detected automatically
  263. {
  264. $rss->_format='rss';
  265. if (empty($rss->channel)) $rss->_format='atom';
  266. }
  267. $items=array();
  268. // Save description entries
  269. if ($rss->_format == 'rss')
  270. {
  271. //var_dump($rss);
  272. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
  273. {
  274. if (!empty($rss->channel->language)) $this->_language = (string) $rss->channel->language;
  275. if (!empty($rss->channel->generator)) $this->_generator = (string) $rss->channel->generator;
  276. if (!empty($rss->channel->copyright)) $this->_copyright = (string) $rss->channel->copyright;
  277. if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
  278. if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
  279. if (!empty($rss->channel->link)) $this->_link = (string) $rss->channel->link;
  280. if (!empty($rss->channel->title)) $this->_title = (string) $rss->channel->title;
  281. if (!empty($rss->channel->description)) $this->_description = (string) $rss->channel->description;
  282. }
  283. else
  284. {
  285. //var_dump($rss->channel);
  286. if (!empty($rss->channel['language'])) $this->_language = (string) $rss->channel['language'];
  287. if (!empty($rss->channel['generator'])) $this->_generator = (string) $rss->channel['generator'];
  288. if (!empty($rss->channel['copyright'])) $this->_copyright = (string) $rss->channel['copyright'];
  289. if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
  290. if (!empty($rss->image['url'])) $this->_imageurl = (string) $rss->image['url'];
  291. if (!empty($rss->channel['link'])) $this->_link = (string) $rss->channel['link'];
  292. if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title'];
  293. if (!empty($rss->channel['description'])) $this->_description = (string) $rss->channel['description'];
  294. }
  295. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item; // With simplexml
  296. else $items=$rss->items; // With xmlparse
  297. //var_dump($items);exit;
  298. }
  299. else if ($rss->_format == 'atom')
  300. {
  301. //var_dump($rss);
  302. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
  303. {
  304. if (!empty($rss->generator)) $this->_generator = (string) $rss->generator;
  305. if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
  306. if (!empty($rss->link->href)) $this->_link = (string) $rss->link->href;
  307. if (!empty($rss->title)) $this->_title = (string) $rss->title;
  308. if (!empty($rss->description)) $this->_description = (string) $rss->description;
  309. }
  310. else
  311. {
  312. //if (!empty($rss->channel['rss_language'])) $this->_language = (string) $rss->channel['rss_language'];
  313. if (!empty($rss->channel['generator'])) $this->_generator = (string) $rss->channel['generator'];
  314. //if (!empty($rss->channel['rss_copyright'])) $this->_copyright = (string) $rss->channel['rss_copyright'];
  315. if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
  316. //if (!empty($rss->image['rss_url'])) $this->_imageurl = (string) $rss->image['rss_url'];
  317. if (!empty($rss->channel['link'])) $this->_link = (string) $rss->channel['link'];
  318. if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title'];
  319. //if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
  320. }
  321. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
  322. $tmprss=xml2php($rss); $items=$tmprss['entry'];
  323. } // With simplexml
  324. else $items=$rss->items; // With xmlparse
  325. //var_dump($items);exit;
  326. }
  327. $i = 0;
  328. // Loop on each record
  329. if (is_array($items))
  330. {
  331. foreach($items as $item)
  332. {
  333. //var_dump($item);exit;
  334. if ($rss->_format == 'rss')
  335. {
  336. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
  337. {
  338. $itemLink = (string) $item->link;
  339. $itemTitle = (string) $item->title;
  340. $itemDescription = (string) $item->description;
  341. $itemPubDate = (string) $item->pubDate;
  342. $itemId = '';
  343. $itemAuthor = '';
  344. }
  345. else
  346. {
  347. $itemLink = (string) $item['link'];
  348. $itemTitle = (string) $item['title'];
  349. $itemDescription = (string) $item['description'];
  350. $itemPubDate = (string) $item['pubdate'];
  351. $itemId = (string) $item['guid'];
  352. $itemAuthor = (string) $item['author'];
  353. }
  354. // Loop on each category
  355. $itemCategory=array();
  356. if (is_array($item->category))
  357. {
  358. foreach ($item->category as $cat)
  359. {
  360. $itemCategory[] = (string) $cat;
  361. }
  362. }
  363. }
  364. else if ($rss->_format == 'atom')
  365. {
  366. if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
  367. {
  368. $itemLink = (string) $item['link']['href'];
  369. $itemTitle = (string) $item['title'];
  370. $itemDescription = (string) $item['summary'];
  371. $itemPubDate = (string) $item['created'];
  372. $itemId = (string) $item['id'];
  373. $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
  374. }
  375. else
  376. {
  377. $itemLink = (string) $item['link']['href'];
  378. $itemTitle = (string) $item['title'];
  379. $itemDescription = (string) $item['summary'];
  380. $itemPubDate = (string) $item['created'];
  381. $itemId = (string) $item['id'];
  382. $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
  383. }
  384. }
  385. else print 'ErrorBadFeedFormat';
  386. // Add record to result array
  387. $this->_rssarray[$i] = array(
  388. 'link'=>$itemLink,
  389. 'title'=>$itemTitle,
  390. 'description'=>$itemDescription,
  391. 'pubDate'=>$itemPubDate,
  392. 'category'=>$itemCategory,
  393. 'id'=>$itemId,
  394. 'author'=>$itemAuthor);
  395. //var_dump($this->_rssarray);
  396. $i++;
  397. if ($i > $maxNb) break; // We get all records we want
  398. }
  399. }
  400. return 1;
  401. }
  402. else
  403. {
  404. $this->error='ErrorFailedToLoadRSSFile';
  405. return -1;
  406. }
  407. }
  408. /**
  409. * Triggered when opened tag is found
  410. *
  411. * @param string $p Start
  412. * @param string $element Tag
  413. * @param array &$attrs Attributes of tags
  414. * @return void
  415. */
  416. function feed_start_element($p, $element, &$attrs)
  417. {
  418. $el = $element = strtolower($element);
  419. $attrs = array_change_key_case($attrs, CASE_LOWER);
  420. // check for a namespace, and split if found
  421. $ns = false;
  422. if (strpos($element, ':'))
  423. {
  424. list($ns, $el) = explode(':', $element, 2);
  425. }
  426. if ( $ns and $ns != 'rdf' )
  427. {
  428. $this->current_namespace = $ns;
  429. }
  430. // if feed type isn't set, then this is first element of feed identify feed from root element
  431. if (empty($this->_format))
  432. {
  433. if ( $el == 'rdf' ) {
  434. $this->_format = 'rss';
  435. $this->feed_version = '1.0';
  436. }
  437. elseif ( $el == 'rss' ) {
  438. $this->_format = 'rss';
  439. $this->feed_version = $attrs['version'];
  440. }
  441. elseif ( $el == 'feed' ) {
  442. $this->_format = 'atom';
  443. $this->feed_version = $attrs['version'];
  444. $this->inchannel = true;
  445. }
  446. return;
  447. }
  448. if ( $el == 'channel' )
  449. {
  450. $this->inchannel = true;
  451. }
  452. elseif ($el == 'item' or $el == 'entry' )
  453. {
  454. $this->initem = true;
  455. if ( isset($attrs['rdf:about']) ) {
  456. $this->current_item['about'] = $attrs['rdf:about'];
  457. }
  458. }
  459. // if we're in the default namespace of an RSS feed,
  460. // record textinput or image fields
  461. elseif (
  462. $this->_format == 'rss' and
  463. $this->current_namespace == '' and
  464. $el == 'textinput' )
  465. {
  466. $this->intextinput = true;
  467. }
  468. elseif (
  469. $this->_format == 'rss' and
  470. $this->current_namespace == '' and
  471. $el == 'image' )
  472. {
  473. $this->inimage = true;
  474. }
  475. // handle atom content constructs
  476. elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
  477. {
  478. // avoid clashing w/ RSS mod_content
  479. if ($el == 'content' ) {
  480. $el = 'atom_content';
  481. }
  482. $this->incontent = $el;
  483. }
  484. // if inside an Atom content construct (e.g. content or summary) field treat tags as text
  485. elseif ($this->_format == 'atom' and $this->incontent )
  486. {
  487. // if tags are inlined, then flatten
  488. $attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs)));
  489. $this->append_content("<$element $attrs_str>");
  490. array_unshift($this->stack, $el);
  491. }
  492. // Atom support many links per containging element.
  493. // Magpie treats link elements of type rel='alternate'
  494. // as being equivalent to RSS's simple link element.
  495. //
  496. elseif ($this->_format == 'atom' and $el == 'link' )
  497. {
  498. if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' )
  499. {
  500. $link_el = 'link';
  501. }
  502. else {
  503. $link_el = 'link_' . $attrs['rel'];
  504. }
  505. $this->append($link_el, $attrs['href']);
  506. }
  507. // set stack[0] to current element
  508. else {
  509. array_unshift($this->stack, $el);
  510. }
  511. }
  512. /**
  513. * Triggered when CDATA is found
  514. *
  515. * @param string $p P
  516. * @param string $text Tag
  517. * @return void
  518. */
  519. function feed_cdata($p, $text)
  520. {
  521. if ($this->_format == 'atom' and $this->incontent)
  522. {
  523. $this->append_content($text);
  524. }
  525. else
  526. {
  527. $current_el = join('_', array_reverse($this->stack));
  528. $this->append($current_el, $text);
  529. }
  530. }
  531. /**
  532. * Triggered when closed tag is found
  533. *
  534. * @param string $p P
  535. * @param string $el Tag
  536. * @return void
  537. */
  538. function feed_end_element($p, $el)
  539. {
  540. $el = strtolower($el);
  541. if ($el == 'item' or $el == 'entry')
  542. {
  543. $this->items[] = $this->current_item;
  544. $this->current_item = array();
  545. $this->initem = false;
  546. }
  547. elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
  548. {
  549. $this->intextinput = false;
  550. }
  551. elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
  552. {
  553. $this->inimage = false;
  554. }
  555. elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
  556. {
  557. $this->incontent = false;
  558. }
  559. elseif ($el == 'channel' or $el == 'feed' )
  560. {
  561. $this->inchannel = false;
  562. }
  563. elseif ($this->_format == 'atom' and $this->incontent ) {
  564. // balance tags properly
  565. // note: i don't think this is actually neccessary
  566. if ( $this->stack[0] == $el )
  567. {
  568. $this->append_content("</$el>");
  569. }
  570. else {
  571. $this->append_content("<$el />");
  572. }
  573. array_shift($this->stack);
  574. }
  575. else {
  576. array_shift($this->stack);
  577. }
  578. $this->current_namespace = false;
  579. }
  580. /**
  581. * To concat 2 string with no warning if an operand is not defined
  582. *
  583. * @param string &$str1 Str1
  584. * @param string $str2 Str2
  585. * @return string String cancatenated
  586. */
  587. function concat(&$str1, $str2="")
  588. {
  589. if (!isset($str1) ) {
  590. $str1="";
  591. }
  592. $str1 .= $str2;
  593. }
  594. /**
  595. * Enter description here ...
  596. *
  597. * @param string $text Text
  598. * @return void
  599. */
  600. function append_content($text)
  601. {
  602. if ( $this->initem ) {
  603. $this->concat($this->current_item[ $this->incontent ], $text);
  604. }
  605. elseif ( $this->inchannel ) {
  606. $this->concat($this->channel[ $this->incontent ], $text);
  607. }
  608. }
  609. /**
  610. * smart append - field and namespace aware
  611. *
  612. * @param string $el El
  613. * @param string $text Text
  614. * @return void
  615. */
  616. function append($el, $text)
  617. {
  618. if (!$el) {
  619. return;
  620. }
  621. if ( $this->current_namespace )
  622. {
  623. if ( $this->initem ) {
  624. $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
  625. }
  626. elseif ($this->inchannel) {
  627. $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
  628. }
  629. elseif ($this->intextinput) {
  630. $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
  631. }
  632. elseif ($this->inimage) {
  633. $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
  634. }
  635. }
  636. else {
  637. if ( $this->initem ) {
  638. $this->concat($this->current_item[ $el ], $text);
  639. }
  640. elseif ($this->intextinput) {
  641. $this->concat($this->textinput[ $el ], $text);
  642. }
  643. elseif ($this->inimage) {
  644. $this->concat($this->image[ $el ], $text);
  645. }
  646. elseif ($this->inchannel) {
  647. $this->concat($this->channel[ $el ], $text);
  648. }
  649. }
  650. }
  651. }
  652. /**
  653. * Function to convert an XML object into an array
  654. *
  655. * @param string $xml Xml
  656. * @return void
  657. */
  658. function xml2php($xml)
  659. {
  660. $fils = 0;
  661. $tab = false;
  662. $array = array();
  663. foreach($xml->children() as $key => $value)
  664. {
  665. $child = xml2php($value);
  666. //To deal with the attributes
  667. foreach($value->attributes() as $ak=>$av)
  668. {
  669. $child[$ak] = (string) $av;
  670. }
  671. //Let see if the new child is not in the array
  672. if($tab==false && in_array($key,array_keys($array)))
  673. {
  674. //If this element is already in the array we will create an indexed array
  675. $tmp = $array[$key];
  676. $array[$key] = NULL;
  677. $array[$key][] = $tmp;
  678. $array[$key][] = $child;
  679. $tab = true;
  680. }
  681. elseif($tab == true)
  682. {
  683. //Add an element in an existing array
  684. $array[$key][] = $child;
  685. }
  686. else
  687. {
  688. //Add a simple element
  689. $array[$key] = $child;
  690. }
  691. $fils++;
  692. }
  693. if($fils==0)
  694. {
  695. return (string) $xml;
  696. }
  697. return $array;
  698. }
  699. ?>