dolibarr 21.0.0-alpha
rssparser.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// @phan-file-suppress PhanPluginPHPDocInWrongComment
27
32{
36 public $db;
37
41 public $error = '';
42
43 public $feed_version;
44
45 private $_format = '';
46 private $_urlRSS;
47 private $_language;
48 private $_generator;
49 private $_copyright;
50 private $_lastbuilddate;
51 private $_imageurl;
52 private $_link;
53 private $_title;
54 private $_description;
55 private $_lastfetchdate; // Last successful fetch
56 private $_rssarray = array();
57
58 private $current_namespace;
59 public $items = array();
60 public $current_item = array();
61 public $channel = array();
62 public $textinput = array();
63 public $image = array();
64
65 private $initem;
66 private $intextinput;
67 private $incontent;
68 private $inimage;
69 private $inchannel;
70
71 // For parsing with xmlparser
72 public $stack = array(); // parser stack
73 private $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
74
75
81 public function __construct($db)
82 {
83 $this->db = $db;
84 }
85
91 public function getFormat()
92 {
93 return $this->_format;
94 }
95
101 public function getUrlRss()
102 {
103 return $this->_urlRSS;
104 }
110 public function getLanguage()
111 {
112 return $this->_language;
113 }
119 public function getGenerator()
120 {
121 return $this->_generator;
122 }
128 public function getCopyright()
129 {
130 return $this->_copyright;
131 }
137 public function getLastBuildDate()
138 {
139 return $this->_lastbuilddate;
140 }
146 public function getImageUrl()
147 {
148 return $this->_imageurl;
149 }
155 public function getLink()
156 {
157 return $this->_link;
158 }
164 public function getTitle()
165 {
166 return $this->_title;
167 }
173 public function getDescription()
174 {
175 return $this->_description;
176 }
182 public function getLastFetchDate()
183 {
184 return $this->_lastfetchdate;
185 }
191 public function getItems()
192 {
193 return $this->_rssarray;
194 }
195
205 public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
206 {
207 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
208 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
209
210 $rss = '';
211 $str = ''; // This will contain content of feed
212
213 // Check parameters
214 if (!dol_is_url($urlRSS)) {
215 $this->error = "ErrorBadUrl";
216 return -1;
217 }
218
219 $this->_urlRSS = $urlRSS;
220 $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, 3); // Force md5 hash (does not contain special chars)
221 $newmask = '0644';
222
223 //dol_syslog("RssParser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
224 $nowgmt = dol_now();
225
226 // Search into cache
227 $foundintocache = 0;
228 if ($cachedelay > 0 && $cachedir) {
229 $filedate = dol_filemtime($newpathofdestfile);
230 if ($filedate >= ($nowgmt - $cachedelay)) {
231 //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
232 $foundintocache = 1;
233
234 $this->_lastfetchdate = $filedate;
235 } else {
236 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
237 }
238 }
239
240 // Load file into $str
241 if ($foundintocache) { // Cache file found and is not too old
242 $str = file_get_contents($newpathofdestfile);
243 } else {
244 try {
245 $result = getURLContent($this->_urlRSS, 'GET', '', 1, array(), array('http', 'https'), 0);
246
247 if (!empty($result['content'])) {
248 $str = $result['content'];
249 } elseif (!empty($result['curl_error_msg'])) {
250 $this->error = 'Error retrieving URL '.$this->_urlRSS.' - '.$result['curl_error_msg'];
251 return -1;
252 }
253 } catch (Exception $e) {
254 $this->error = 'Error retrieving URL '.$this->_urlRSS.' - '.$e->getMessage();
255 return -2;
256 }
257 }
258
259 if ($str !== false) {
260 // Convert $str into xml
261 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
262 //print 'xx'.LIBXML_NOCDATA;
263 libxml_use_internal_errors(false);
264 if (LIBXML_VERSION < 20900) {
265 // Avoid load of external entities (security problem).
266 // Required only if LIBXML_VERSION < 20900
267 // @phan-suppress-next-line PhanDeprecatedFunctionInternal
268 libxml_disable_entity_loader(true);
269 }
270
271 $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
272 } else {
273 if (!function_exists('xml_parser_create')) {
274 $this->error = 'Function xml_parser_create are not supported by your PHP';
275 return -1;
276 }
277
278 try {
279 // @phan-suppress-next-line PhanTypeMismatchArgumentInternalProbablyReal
280 $xmlparser = xml_parser_create(null);
281
282 xml_parser_set_option($xmlparser, XML_OPTION_CASE_FOLDING, 0);
283 xml_parser_set_option($xmlparser, XML_OPTION_SKIP_WHITE, 1);
284 xml_parser_set_option($xmlparser, XML_OPTION_TARGET_ENCODING, "UTF-8");
285 //xml_set_external_entity_ref_handler($xmlparser, 'extEntHandler'); // Seems to have no effect even when function extEntHandler exists.
286
287 if (!is_resource($xmlparser) && !is_object($xmlparser)) {
288 $this->error = "ErrorFailedToCreateParser";
289 return -1;
290 }
291
292 xml_set_object($xmlparser, $this);
293 // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
294 xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element'); // @phpstan-ignore-line
295 // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
296 xml_set_character_data_handler($xmlparser, 'feed_cdata'); // @phpstan-ignore-line
297
298 $status = xml_parse($xmlparser, $str, false);
299
300 xml_parser_free($xmlparser);
301
302 $rss = $this;
303 //var_dump($status.' '.$rss->_format);exit;
304 } catch (Exception $e) {
305 $rss = null;
306 }
307 }
308 }
309
310 // If $rss loaded
311 if ($rss) {
312 // Save file into cache
313 if (empty($foundintocache) && $cachedir) {
314 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
315 if (!dol_is_dir($cachedir)) {
316 dol_mkdir($cachedir);
317 }
318 $fp = fopen($newpathofdestfile, 'w');
319 if ($fp) {
320 fwrite($fp, $str);
321 fclose($fp);
322 dolChmod($newpathofdestfile);
323
324 $this->_lastfetchdate = $nowgmt;
325 } else {
326 print 'Error, failed to open file '.$newpathofdestfile.' for write';
327 }
328 }
329
330 unset($str); // Free memory
331
332 if (empty($rss->_format)) { // If format not detected automatically
333 $rss->_format = 'rss';
334 if (empty($rss->channel)) {
335 $rss->_format = 'atom';
336 }
337 }
338
339 $items = array();
340
341 // Save description entries
342 if ($rss->_format == 'rss') {
343 //var_dump($rss);
344 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
345 if (!empty($rss->channel->language)) {
346 $this->_language = sanitizeVal((string) $rss->channel->language);
347 }
348 if (!empty($rss->channel->generator)) {
349 $this->_generator = sanitizeVal((string) $rss->channel->generator);
350 }
351 if (!empty($rss->channel->copyright)) {
352 $this->_copyright = sanitizeVal((string) $rss->channel->copyright);
353 }
354 if (!empty($rss->channel->lastbuilddate)) {
355 $this->_lastbuilddate = sanitizeVal((string) $rss->channel->lastbuilddate);
356 }
357 if (!empty($rss->channel->image->url[0])) {
358 $this->_imageurl = sanitizeVal((string) $rss->channel->image->url[0]);
359 }
360 if (!empty($rss->channel->link)) {
361 $this->_link = sanitizeVal((string) $rss->channel->link);
362 }
363 if (!empty($rss->channel->title)) {
364 $this->_title = sanitizeVal((string) $rss->channel->title);
365 }
366 if (!empty($rss->channel->description)) {
367 $this->_description = sanitizeVal((string) $rss->channel->description);
368 }
369 } else {
370 //var_dump($rss->channel);
371 if (!empty($rss->channel['language'])) {
372 $this->_language = sanitizeVal((string) $rss->channel['language']);
373 }
374 if (!empty($rss->channel['generator'])) {
375 $this->_generator = sanitizeVal((string) $rss->channel['generator']);
376 }
377 if (!empty($rss->channel['copyright'])) {
378 $this->_copyright = sanitizeVal((string) $rss->channel['copyright']);
379 }
380 if (!empty($rss->channel['lastbuilddate'])) {
381 $this->_lastbuilddate = sanitizeVal((string) $rss->channel['lastbuilddate']);
382 }
383 if (!empty($rss->image['url'])) {
384 $this->_imageurl = sanitizeVal((string) $rss->image['url']);
385 }
386 if (!empty($rss->channel['link'])) {
387 $this->_link = sanitizeVal((string) $rss->channel['link']);
388 }
389 if (!empty($rss->channel['title'])) {
390 $this->_title = sanitizeVal((string) $rss->channel['title']);
391 }
392 if (!empty($rss->channel['description'])) {
393 $this->_description = sanitizeVal((string) $rss->channel['description']);
394 }
395 }
396
397 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
398 $items = $rss->channel->item; // With simplexml
399 } else {
400 $items = $rss->items; // With xmlparse
401 }
402 //var_dump($items);exit;
403 } elseif ($rss->_format == 'atom') {
404 //var_dump($rss);
405 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
406 if (!empty($rss->generator)) {
407 $this->_generator = sanitizeVal((string) $rss->generator);
408 }
409 if (!empty($rss->lastbuilddate)) {
410 $this->_lastbuilddate = sanitizeVal((string) $rss->modified);
411 }
412 if (!empty($rss->link->href)) {
413 $this->_link = sanitizeVal((string) $rss->link->href);
414 }
415 if (!empty($rss->title)) {
416 $this->_title = sanitizeVal((string) $rss->title);
417 }
418 if (!empty($rss->description)) {
419 $this->_description = sanitizeVal((string) $rss->description);
420 }
421 } else {
422 //if (!empty($rss->channel['rss_language'])) $this->_language = (string) $rss->channel['rss_language'];
423 if (!empty($rss->channel['generator'])) {
424 $this->_generator = sanitizeVal((string) $rss->channel['generator']);
425 }
426 //if (!empty($rss->channel['rss_copyright'])) $this->_copyright = (string) $rss->channel['rss_copyright'];
427 if (!empty($rss->channel['modified'])) {
428 $this->_lastbuilddate = sanitizeVal((string) $rss->channel['modified']);
429 }
430 //if (!empty($rss->image['rss_url'])) $this->_imageurl = (string) $rss->image['rss_url'];
431 if (!empty($rss->channel['link'])) {
432 $this->_link = sanitizeVal((string) $rss->channel['link']);
433 }
434 if (!empty($rss->channel['title'])) {
435 $this->_title = sanitizeVal((string) $rss->channel['title']);
436 }
437 //if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
438
439 if (!empty($rss->channel)) {
440 $this->_imageurl = sanitizeVal($this->getAtomImageUrl($rss->channel));
441 }
442 }
443 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
444 $tmprss = xml2php($rss);
445 $items = $tmprss['entry'];
446 } else {
447 // With simplexml
448 $items = $rss->items; // With xmlparse
449 }
450 //var_dump($items);exit;
451 }
452
453 $i = 0;
454
455 // Loop on each record
456 if (is_array($items)) {
457 foreach ($items as $item) {
458 //var_dump($item);exit;
459 if ($rss->_format == 'rss') {
460 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
461 $itemLink = sanitizeVal((string) $item->link);
462 $itemTitle = sanitizeVal((string) $item->title);
463 $itemDescription = sanitizeVal((string) $item->description);
464 $itemPubDate = sanitizeVal((string) $item->pubDate);
465 $itemId = '';
466 $itemAuthor = '';
467 } else {
468 $itemLink = sanitizeVal((string) $item['link']);
469 $itemTitle = sanitizeVal((string) $item['title']);
470 $itemDescription = sanitizeVal((string) $item['description']);
471 $itemPubDate = sanitizeVal((string) $item['pubdate']);
472 $itemId = sanitizeVal((string) $item['guid']);
473 $itemAuthor = sanitizeVal((string) ($item['author'] ?? ''));
474 }
475
476 // Loop on each category
477 $itemCategory = array();
478 if (!empty($item->category) && is_array($item->category)) {
479 foreach ($item->category as $cat) {
480 $itemCategory[] = (string) $cat;
481 }
482 }
483 } elseif ($rss->_format == 'atom') {
484 $itemLink = (isset($item['link']) ? sanitizeVal((string) $item['link']) : '');
485 $itemTitle = sanitizeVal((string) $item['title']);
486 $itemDescription = sanitizeVal($this->getAtomItemDescription($item));
487 $itemPubDate = sanitizeVal((string) $item['created']);
488 $itemId = sanitizeVal((string) $item['id']);
489 $itemAuthor = sanitizeVal((string) ($item['author'] ? $item['author'] : $item['author_name']));
490 $itemCategory = array();
491 } else {
492 $itemLink = '';
493 $itemTitle = '';
494 $itemDescription = '';
495 $itemPubDate = '';
496 $itemId = '';
497 $itemAuthor = '';
498 $itemCategory = array();
499 print 'ErrorBadFeedFormat';
500 }
501
502 // Add record to result array
503 $this->_rssarray[$i] = array(
504 'link' => $itemLink,
505 'title' => $itemTitle,
506 'description' => $itemDescription,
507 'pubDate' => $itemPubDate,
508 'category' => $itemCategory,
509 'id' => $itemId,
510 'author' => $itemAuthor
511 );
512 //var_dump($this->_rssarray);
513
514 $i++;
515
516 if ($i > $maxNb) {
517 break; // We get all records we want
518 }
519 }
520 }
521
522 return 1;
523 } else {
524 $this->error = 'ErrorFailedToLoadRSSFile';
525 return -1;
526 }
527 }
528
529
530
531 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
540 public function feed_start_element($p, $element, $attrs)
541 {
542 // phpcs:enable
543 $el = $element = strtolower($element);
544 $attrs = array_change_key_case($attrs, CASE_LOWER);
545
546 // check for a namespace, and split if found
547 $ns = false;
548 if (strpos($element, ':')) {
549 list($ns, $el) = explode(':', $element, 2);
550 }
551 if ($ns and $ns != 'rdf') {
552 $this->current_namespace = $ns;
553 }
554
555 // if feed type isn't set, then this is first element of feed identify feed from root element
556 if (empty($this->_format)) {
557 if ($el == 'rdf') {
558 $this->_format = 'rss';
559 $this->feed_version = '1.0';
560 } elseif ($el == 'rss') {
561 $this->_format = 'rss';
562 $this->feed_version = $attrs['version'];
563 } elseif ($el == 'feed') {
564 $this->_format = 'atom';
565 $this->feed_version = $attrs['version'];
566 $this->inchannel = true;
567 }
568 return;
569 }
570
571 if ($el == 'channel') {
572 $this->inchannel = true;
573 } elseif ($el == 'item' || $el == 'entry') {
574 $this->initem = true;
575 if (isset($attrs['rdf:about'])) {
576 $this->current_item['about'] = $attrs['rdf:about'];
577 }
578 } elseif ($this->_format == 'rss' && $this->current_namespace == '' && $el == 'textinput') {
579 // if we're in the default namespace of an RSS feed,
580 // record textinput or image fields
581 $this->intextinput = true;
582 } elseif ($this->_format == 'rss' && $this->current_namespace == '' && $el == 'image') {
583 $this->inimage = true;
584 } elseif ($this->_format == 'atom' && in_array($el, $this->_CONTENT_CONSTRUCTS)) {
585 // handle atom content constructs
586 // avoid clashing w/ RSS mod_content
587 if ($el == 'content') {
588 $el = 'atom_content';
589 }
590
591 $this->incontent = $el;
592 } elseif ($this->_format == 'atom' && $this->incontent) {
593 // if inside an Atom content construct (e.g. content or summary) field treat tags as text
594 // if tags are inlined, then flatten
595 $attrs_str = implode(' ', array_map('rss_map_attrs', array_keys($attrs), array_values($attrs)));
596
597 $this->append_content("<$element $attrs_str>");
598
599 array_unshift($this->stack, $el);
600 } elseif ($this->_format == 'atom' && $el == 'link') {
601 // Atom support many links per containing element.
602 // Magpie treats link elements of type rel='alternate'
603 // as being equivalent to RSS's simple link element.
604 if (isset($attrs['rel']) && $attrs['rel'] == 'alternate') {
605 $link_el = 'link';
606 } elseif (!isset($attrs['rel'])) {
607 $link_el = 'link';
608 } else {
609 $link_el = 'link_'.$attrs['rel'];
610 }
611
612 $this->append($link_el, $attrs['href']);
613 } else {
614 // set stack[0] to current element
615 array_unshift($this->stack, $el);
616 }
617 }
618
619
620 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
628 public function feed_cdata($p, $text)
629 {
630 // phpcs:enable
631 if ($this->_format == 'atom' and $this->incontent) {
632 $this->append_content($text);
633 } else {
634 $current_el = implode('_', array_reverse($this->stack));
635 $this->append($current_el, $text);
636 }
637 }
638
639 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
647 public function feed_end_element($p, $el)
648 {
649 // phpcs:enable
650 $el = strtolower($el);
651
652 if ($el == 'item' or $el == 'entry') {
653 $this->items[] = $this->current_item;
654 $this->current_item = array();
655 $this->initem = false;
656 } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput') {
657 $this->intextinput = false;
658 } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image') {
659 $this->inimage = false;
660 } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS)) {
661 $this->incontent = false;
662 } elseif ($el == 'channel' or $el == 'feed') {
663 $this->inchannel = false;
664 } elseif ($this->_format == 'atom' and $this->incontent) {
665 // balance tags properly
666 // note: i don't think this is actually necessary
667 if ($this->stack[0] == $el) {
668 $this->append_content("</$el>");
669 } else {
670 $this->append_content("<$el />");
671 }
672
673 array_shift($this->stack);
674 } else {
675 array_shift($this->stack);
676 }
677
678 $this->current_namespace = false;
679 }
680
681
689 public function concat(&$str1, $str2 = "")
690 {
691 if (!isset($str1)) {
692 $str1 = "";
693 }
694 $str1 .= $str2;
695 return $str1;
696 }
697
698 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
705 public function append_content($text)
706 {
707 // phpcs:enable
708 if (!empty($this->initem)) {
709 $this->concat($this->current_item[$this->incontent], $text);
710 } elseif (!empty($this->inchannel)) {
711 $this->concat($this->channel[$this->incontent], $text);
712 }
713 }
714
722 public function append($el, $text)
723 {
724 if (!$el) {
725 return;
726 }
727 if (!empty($this->current_namespace)) {
728 if (!empty($this->initem)) {
729 $this->concat($this->current_item[$this->current_namespace][$el], $text);
730 } elseif (!empty($this->inchannel)) {
731 $this->concat($this->channel[$this->current_namespace][$el], $text);
732 } elseif (!empty($this->intextinput)) {
733 $this->concat($this->textinput[$this->current_namespace][$el], $text);
734 } elseif (!empty($this->inimage)) {
735 $this->concat($this->image[$this->current_namespace][$el], $text);
736 }
737 } else {
738 if (!empty($this->initem)) {
739 $this->concat($this->current_item[$el], $text);
740 } elseif (!empty($this->intextinput)) {
741 $this->concat($this->textinput[$el], $text);
742 } elseif (!empty($this->inimage)) {
743 $this->concat($this->image[$el], $text);
744 } elseif (!empty($this->inchannel)) {
745 $this->concat($this->channel[$el], $text);
746 }
747 }
748 }
749
757 private function getAtomItemDescription(array $item, $maxlength = 500)
758 {
759 $result = "";
760
761 if (isset($item['summary'])) {
762 $result = $item['summary'];
763 } elseif (isset($item['atom_content'])) {
764 $result = $item['atom_content'];
765 }
766
767 // remove all HTML elements that can possible break the maximum size of a tooltip,
768 // like headings, image, video etc. and allow only simple style elements
769 $result = strip_tags($result, "<br><p><ul><ol><li>");
770
771 $result = str_replace("\n", "", $result);
772
773 if (strlen($result) > $maxlength) {
774 $result = substr($result, 0, $maxlength);
775 $result .= "...";
776 }
777
778 return $result;
779 }
780
787 private function getAtomImageUrl(array $feed)
788 {
789 if (isset($feed['icon'])) {
790 return $feed['logo'];
791 }
792
793 if (isset($feed['icon'])) {
794 return $feed['logo'];
795 }
796
797 if (isset($feed['webfeeds:logo'])) {
798 return $feed['webfeeds:logo'];
799 }
800
801 if (isset($feed['webfeeds:icon'])) {
802 return $feed['webfeeds:icon'];
803 }
804
805 if (isset($feed['webfeeds:wordmark'])) {
806 return $feed['webfeeds:wordmark'];
807 }
808
809 return "";
810 }
811}
812
813/*
814 * A method for the xml_set_external_entity_ref_handler()
815 *
816 * @param XMLParser $parser
817 * @param string $ent
818 * @param string|false $base
819 * @param string $sysID
820 * @param string|false $pubID
821 * @return bool
822function extEntHandler($parser, $ent, $base, $sysID, $pubID) {
823 print 'extEntHandler ran';
824 return true;
825}
826*/
827
835function rss_map_attrs($k, $v)
836{
837 return "$k=\"$v\"";
838}
839
846function xml2php($xml)
847{
848 $threads = 0;
849 $tab = false;
850 $array = array();
851 foreach ($xml->children() as $key => $value) {
852 $child = xml2php($value);
853
854 //To deal with the attributes
855 foreach ($value->attributes() as $ak => $av) {
856 $child[$ak] = (string) $av;
857 }
858
859 //Let see if the new child is not in the array
860 if ($tab === false && in_array($key, array_keys($array))) {
861 //If this element is already in the array we will create an indexed array
862 $tmp = $array[$key];
863 $array[$key] = null;
864 $array[$key][] = $tmp;
865 $array[$key][] = $child;
866 $tab = true;
867 } elseif ($tab === true) {
868 //Add an element in an existing array
869 $array[$key][] = $child;
870 } else {
871 //Add a simple element
872 $array[$key] = $child;
873 }
874
875 $threads++;
876 }
877
878
879 if ($threads == 0) {
880 return (string) $xml;
881 }
882
883 return $array;
884}
Class to parse RSS files.
feed_start_element($p, $element, $attrs)
Triggered when opened tag is found.
getAtomItemDescription(array $item, $maxlength=500)
Return a description/summary for one item from a ATOM feed.
concat(&$str1, $str2="")
To concat 2 strings with no warning if an operand is not defined.
getImageUrl()
getImageUrl
feed_end_element($p, $el)
Triggered when closed tag is found.
__construct($db)
Constructor.
getLanguage()
getLanguage
getTitle()
getTitle
getLastBuildDate()
getLastBuildDate
getItems()
getItems
getLink()
getLink
getGenerator()
getGenerator
getCopyright()
getCopyright
feed_cdata($p, $text)
Triggered when CDATA is found.
getLastFetchDate()
getLastFetchDate
getUrlRss()
getUrlRss
parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
Parse rss URL.
append_content($text)
Enter description here ...
append($el, $text)
smart append - field and namespace aware
getDescription()
getDescription
getFormat()
getFormat
getAtomImageUrl(array $feed)
Return a URL to a image of the given ATOM feed.
dol_is_url($uri)
Return if path is an URI (the name of the method is misleading).
dol_filemtime($pathoffile)
Return time of a file.
dol_is_dir($folder)
Test if filename is a directory.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
xml2php($xml)
Function to convert an XML object into an array.
rss_map_attrs($k, $v)
Function to convert an XML object into an array.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.