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
46 public $feed_version;
47
51 private $_format = '';
55 private $_urlRSS;
59 private $_language;
63 private $_generator;
67 private $_copyright;
71 private $_lastbuilddate;
75 private $_imageurl;
79 private $_link;
83 private $_title;
87 private $_description;
91 private $_lastfetchdate; // Last successful fetch
95 private $_rssarray = array();
96
100 private $current_namespace;
101
102 public $items = array();
106 public $current_item = array();
110 public $channel = array();
114 public $textinput = array();
118 public $image = array();
119
123 private $initem;
127 private $intextinput;
131 private $incontent;
135 private $inimage;
139 private $inchannel;
140
144 public $stack = array(); // parser stack
148 private $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
149
150
156 public function __construct($db)
157 {
158 $this->db = $db;
159 }
160
166 public function getFormat()
167 {
168 return $this->_format;
169 }
170
176 public function getUrlRss()
177 {
178 return $this->_urlRSS;
179 }
185 public function getLanguage()
186 {
187 return $this->_language;
188 }
194 public function getGenerator()
195 {
196 return $this->_generator;
197 }
203 public function getCopyright()
204 {
205 return $this->_copyright;
206 }
212 public function getLastBuildDate()
213 {
214 return $this->_lastbuilddate;
215 }
221 public function getImageUrl()
222 {
223 return $this->_imageurl;
224 }
230 public function getLink()
231 {
232 return $this->_link;
233 }
239 public function getTitle()
240 {
241 return $this->_title;
242 }
248 public function getDescription()
249 {
250 return $this->_description;
251 }
257 public function getLastFetchDate()
258 {
259 return $this->_lastfetchdate;
260 }
266 public function getItems()
267 {
268 return $this->_rssarray;
269 }
270
280 public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
281 {
282 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
283 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
284
285 $rss = '';
286 $str = ''; // This will contain content of feed
287
288 // Check parameters
289 if (!dol_is_url($urlRSS)) {
290 $this->error = "ErrorBadUrl";
291 return -1;
292 }
293
294 $this->_urlRSS = $urlRSS;
295 $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, '3'); // Force md5 hash (does not contain special chars)
296 $newmask = '0644';
297
298 //dol_syslog("RssParser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
299 $nowgmt = dol_now();
300
301 // Search into cache
302 $foundintocache = 0;
303 if ($cachedelay > 0 && $cachedir) {
304 $filedate = dol_filemtime($newpathofdestfile);
305 if ($filedate >= ($nowgmt - $cachedelay)) {
306 //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
307 $foundintocache = 1;
308
309 $this->_lastfetchdate = $filedate;
310 } else {
311 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.");
312 }
313 }
314
315 // Load file into $str
316 if ($foundintocache) { // Cache file found and is not too old
317 $str = file_get_contents($newpathofdestfile);
318 } else {
319 try {
320 $result = getURLContent($this->_urlRSS, 'GET', '', 1, array(), array('http', 'https'), 0);
321
322 if (!empty($result['content'])) {
323 $str = $result['content'];
324 } elseif (!empty($result['curl_error_msg'])) {
325 $this->error = 'Error retrieving URL '.$this->_urlRSS.' - '.$result['curl_error_msg'];
326 return -1;
327 }
328 } catch (Exception $e) {
329 $this->error = 'Error retrieving URL '.$this->_urlRSS.' - '.$e->getMessage();
330 return -2;
331 }
332 }
333
334 if ($str !== false) {
335 // Convert $str into xml
336 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
337 //print 'xx'.LIBXML_NOCDATA;
338 libxml_use_internal_errors(false);
339 if (LIBXML_VERSION < 20900) {
340 // Avoid load of external entities (security problem).
341 // Required only if LIBXML_VERSION < 20900
342 // @phan-suppress-next-line PhanDeprecatedFunctionInternal
343 libxml_disable_entity_loader(true);
344 }
345
346 $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
347 } else {
348 if (!function_exists('xml_parser_create')) {
349 $this->error = 'Function xml_parser_create are not supported by your PHP';
350 return -1;
351 }
352
353 try {
354 // @phan-suppress-next-line PhanTypeMismatchArgumentInternalProbablyReal
355 $xmlparser = xml_parser_create(null);
356
357 xml_parser_set_option($xmlparser, XML_OPTION_CASE_FOLDING, 0);
358 xml_parser_set_option($xmlparser, XML_OPTION_SKIP_WHITE, 1);
359 xml_parser_set_option($xmlparser, XML_OPTION_TARGET_ENCODING, "UTF-8");
360 //xml_set_external_entity_ref_handler($xmlparser, 'extEntHandler'); // Seems to have no effect even when function extEntHandler exists.
361
362 if (!is_resource($xmlparser) && !is_object($xmlparser)) {
363 $this->error = "ErrorFailedToCreateParser";
364 return -1;
365 }
366
367 xml_set_object($xmlparser, $this);
368 // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
369 xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element'); // @phpstan-ignore-line
370 // @phan-suppress-next-line PhanUndeclaredFunctionInCallable
371 xml_set_character_data_handler($xmlparser, 'feed_cdata'); // @phpstan-ignore-line
372
373 $status = xml_parse($xmlparser, $str, false);
374
375 xml_parser_free($xmlparser);
376
377 $rss = $this;
378 //var_dump($status.' '.$rss->_format);exit;
379 } catch (Exception $e) {
380 $rss = null;
381 }
382 }
383 }
384
385 // If $rss loaded
386 if ($rss) {
387 // Save file into cache
388 if (empty($foundintocache) && $cachedir) {
389 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
390 if (!dol_is_dir($cachedir)) {
391 dol_mkdir($cachedir);
392 }
393 $fp = fopen($newpathofdestfile, 'w');
394 if ($fp) {
395 fwrite($fp, $str);
396 fclose($fp);
397 dolChmod($newpathofdestfile);
398
399 $this->_lastfetchdate = $nowgmt;
400 } else {
401 print 'Error, failed to open file '.$newpathofdestfile.' for write';
402 }
403 }
404
405 unset($str); // Free memory
406
407 if (empty($rss->_format)) { // If format not detected automatically
408 $rss->_format = 'rss';
409 if (empty($rss->channel)) {
410 $rss->_format = 'atom';
411 }
412 }
413
414 $items = array();
415
416 // Save description entries
417 if ($rss->_format == 'rss') {
418 //var_dump($rss);
419 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
420 if (!empty($rss->channel->language)) {
421 $this->_language = sanitizeVal((string) $rss->channel->language);
422 }
423 if (!empty($rss->channel->generator)) {
424 $this->_generator = sanitizeVal((string) $rss->channel->generator);
425 }
426 if (!empty($rss->channel->copyright)) {
427 $this->_copyright = sanitizeVal((string) $rss->channel->copyright);
428 }
429 if (!empty($rss->channel->lastbuilddate)) {
430 $this->_lastbuilddate = sanitizeVal((string) $rss->channel->lastbuilddate);
431 }
432 if (!empty($rss->channel->image->url[0])) {
433 $this->_imageurl = sanitizeVal((string) $rss->channel->image->url[0]);
434 }
435 if (!empty($rss->channel->link)) {
436 $this->_link = sanitizeVal((string) $rss->channel->link);
437 }
438 if (!empty($rss->channel->title)) {
439 $this->_title = sanitizeVal((string) $rss->channel->title);
440 }
441 if (!empty($rss->channel->description)) {
442 $this->_description = sanitizeVal((string) $rss->channel->description);
443 }
444 } else {
445 //var_dump($rss->channel);
446 if (!empty($rss->channel['language'])) {
447 $this->_language = sanitizeVal((string) $rss->channel['language']);
448 }
449 if (!empty($rss->channel['generator'])) {
450 $this->_generator = sanitizeVal((string) $rss->channel['generator']);
451 }
452 if (!empty($rss->channel['copyright'])) {
453 $this->_copyright = sanitizeVal((string) $rss->channel['copyright']);
454 }
455 if (!empty($rss->channel['lastbuilddate'])) {
456 $this->_lastbuilddate = sanitizeVal((string) $rss->channel['lastbuilddate']);
457 }
458 if (!empty($rss->image['url'])) {
459 $this->_imageurl = sanitizeVal((string) $rss->image['url']);
460 }
461 if (!empty($rss->channel['link'])) {
462 $this->_link = sanitizeVal((string) $rss->channel['link']);
463 }
464 if (!empty($rss->channel['title'])) {
465 $this->_title = sanitizeVal((string) $rss->channel['title']);
466 }
467 if (!empty($rss->channel['description'])) {
468 $this->_description = sanitizeVal((string) $rss->channel['description']);
469 }
470 }
471
472 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
473 $items = $rss->channel->item; // With simplexml
474 } else {
475 $items = $rss->items; // With xmlparse
476 }
477 //var_dump($items);exit;
478 } elseif ($rss->_format == 'atom') {
479 //var_dump($rss);
480 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
481 if (!empty($rss->generator)) {
482 $this->_generator = sanitizeVal((string) $rss->generator);
483 }
484 if (!empty($rss->lastbuilddate)) {
485 $this->_lastbuilddate = sanitizeVal((string) $rss->modified);
486 }
487 if (!empty($rss->link->href)) {
488 $this->_link = sanitizeVal((string) $rss->link->href);
489 }
490 if (!empty($rss->title)) {
491 $this->_title = sanitizeVal((string) $rss->title);
492 }
493 if (!empty($rss->description)) {
494 $this->_description = sanitizeVal((string) $rss->description);
495 }
496 } else {
497 //if (!empty($rss->channel['rss_language'])) $this->_language = (string) $rss->channel['rss_language'];
498 if (!empty($rss->channel['generator'])) {
499 $this->_generator = sanitizeVal((string) $rss->channel['generator']);
500 }
501 //if (!empty($rss->channel['rss_copyright'])) $this->_copyright = (string) $rss->channel['rss_copyright'];
502 if (!empty($rss->channel['modified'])) {
503 $this->_lastbuilddate = sanitizeVal((string) $rss->channel['modified']);
504 }
505 //if (!empty($rss->image['rss_url'])) $this->_imageurl = (string) $rss->image['rss_url'];
506 if (!empty($rss->channel['link'])) {
507 $this->_link = sanitizeVal((string) $rss->channel['link']);
508 }
509 if (!empty($rss->channel['title'])) {
510 $this->_title = sanitizeVal((string) $rss->channel['title']);
511 }
512 //if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
513
514 if (!empty($rss->channel)) {
515 $this->_imageurl = sanitizeVal($this->getAtomImageUrl($rss->channel));
516 }
517 }
518 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
519 $tmprss = xml2php($rss);
520 $items = $tmprss['entry'];
521 } else {
522 // With simplexml
523 $items = $rss->items; // With xmlparse
524 }
525 //var_dump($items);exit;
526 }
527
528 $i = 0;
529
530 // Loop on each record
531 if (is_array($items)) {
532 foreach ($items as $item) {
533 //var_dump($item);exit;
534 if ($rss->_format == 'rss') {
535 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
536 $itemLink = sanitizeVal((string) $item->link);
537 $itemTitle = sanitizeVal((string) $item->title);
538 $itemDescription = sanitizeVal((string) $item->description);
539 $itemPubDate = sanitizeVal((string) $item->pubDate);
540 $itemId = '';
541 $itemAuthor = '';
542 } else {
543 $itemLink = sanitizeVal((string) $item['link']);
544 $itemTitle = sanitizeVal((string) $item['title']);
545 $itemDescription = sanitizeVal((string) $item['description']);
546 $itemPubDate = sanitizeVal((string) $item['pubdate']);
547 $itemId = sanitizeVal((string) $item['guid']);
548 $itemAuthor = sanitizeVal((string) ($item['author'] ?? ''));
549 }
550
551 // Loop on each category
552 $itemCategory = array();
553 if (!empty($item->category) && is_array($item->category)) {
554 foreach ($item->category as $cat) {
555 $itemCategory[] = (string) $cat;
556 }
557 }
558 } elseif ($rss->_format == 'atom') {
559 $itemLink = (isset($item['link']) ? sanitizeVal((string) $item['link']) : '');
560 $itemTitle = sanitizeVal((string) $item['title']);
561 $itemDescription = sanitizeVal($this->getAtomItemDescription($item));
562 $itemPubDate = sanitizeVal((string) $item['created']);
563 $itemId = sanitizeVal((string) $item['id']);
564 $itemAuthor = sanitizeVal((string) ($item['author'] ? $item['author'] : $item['author_name']));
565 $itemCategory = array();
566 } else {
567 $itemLink = '';
568 $itemTitle = '';
569 $itemDescription = '';
570 $itemPubDate = '';
571 $itemId = '';
572 $itemAuthor = '';
573 $itemCategory = array();
574 print 'ErrorBadFeedFormat';
575 }
576
577 // Add record to result array
578 $this->_rssarray[$i] = array(
579 'link' => $itemLink,
580 'title' => $itemTitle,
581 'description' => $itemDescription,
582 'pubDate' => $itemPubDate,
583 'category' => $itemCategory,
584 'id' => $itemId,
585 'author' => $itemAuthor
586 );
587 //var_dump($this->_rssarray);
588
589 $i++;
590
591 if ($i > $maxNb) {
592 break; // We get all records we want
593 }
594 }
595 }
596
597 return 1;
598 } else {
599 $this->error = 'ErrorFailedToLoadRSSFile';
600 return -1;
601 }
602 }
603
604
605
606 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
615 public function feed_start_element($p, $element, $attrs)
616 {
617 // phpcs:enable
618 $el = $element = strtolower($element);
619 $attrs = array_change_key_case($attrs, CASE_LOWER);
620
621 // check for a namespace, and split if found
622 $ns = false;
623 if (strpos($element, ':')) {
624 list($ns, $el) = explode(':', $element, 2);
625 }
626 if ($ns and $ns != 'rdf') {
627 $this->current_namespace = $ns;
628 }
629
630 // if feed type isn't set, then this is first element of feed identify feed from root element
631 if (empty($this->_format)) {
632 if ($el == 'rdf') {
633 $this->_format = 'rss';
634 $this->feed_version = '1.0';
635 } elseif ($el == 'rss') {
636 $this->_format = 'rss';
637 $this->feed_version = $attrs['version'];
638 } elseif ($el == 'feed') {
639 $this->_format = 'atom';
640 $this->feed_version = $attrs['version'];
641 $this->inchannel = true;
642 }
643 return;
644 }
645
646 if ($el == 'channel') {
647 $this->inchannel = true;
648 } elseif ($el == 'item' || $el == 'entry') {
649 $this->initem = true;
650 if (isset($attrs['rdf:about'])) {
651 $this->current_item['about'] = $attrs['rdf:about'];
652 }
653 } elseif ($this->_format == 'rss' && $this->current_namespace == '' && $el == 'textinput') {
654 // if we're in the default namespace of an RSS feed,
655 // record textinput or image fields
656 $this->intextinput = true;
657 } elseif ($this->_format == 'rss' && $this->current_namespace == '' && $el == 'image') {
658 $this->inimage = true;
659 } elseif ($this->_format == 'atom' && in_array($el, $this->_CONTENT_CONSTRUCTS)) {
660 // handle atom content constructs
661 // avoid clashing w/ RSS mod_content
662 if ($el == 'content') {
663 $el = 'atom_content';
664 }
665
666 $this->incontent = $el;
667 } elseif ($this->_format == 'atom' && $this->incontent) {
668 // if inside an Atom content construct (e.g. content or summary) field treat tags as text
669 // if tags are inlined, then flatten
670 $attrs_str = implode(' ', array_map('rss_map_attrs', array_keys($attrs), array_values($attrs)));
671
672 $this->append_content("<$element $attrs_str>");
673
674 array_unshift($this->stack, $el);
675 } elseif ($this->_format == 'atom' && $el == 'link') {
676 // Atom support many links per containing element.
677 // Magpie treats link elements of type rel='alternate'
678 // as being equivalent to RSS's simple link element.
679 if (isset($attrs['rel']) && $attrs['rel'] == 'alternate') {
680 $link_el = 'link';
681 } elseif (!isset($attrs['rel'])) {
682 $link_el = 'link';
683 } else {
684 $link_el = 'link_'.$attrs['rel'];
685 }
686
687 $this->append($link_el, $attrs['href']);
688 } else {
689 // set stack[0] to current element
690 array_unshift($this->stack, $el);
691 }
692 }
693
694
695 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
703 public function feed_cdata($p, $text)
704 {
705 // phpcs:enable
706 if ($this->_format == 'atom' and $this->incontent) {
707 $this->append_content($text);
708 } else {
709 $current_el = implode('_', array_reverse($this->stack));
710 $this->append($current_el, $text);
711 }
712 }
713
714 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
722 public function feed_end_element($p, $el)
723 {
724 // phpcs:enable
725 $el = strtolower($el);
726
727 if ($el == 'item' or $el == 'entry') {
728 $this->items[] = $this->current_item;
729 $this->current_item = array();
730 $this->initem = false;
731 } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput') {
732 $this->intextinput = false;
733 } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image') {
734 $this->inimage = false;
735 } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS)) {
736 $this->incontent = false;
737 } elseif ($el == 'channel' or $el == 'feed') {
738 $this->inchannel = false;
739 } elseif ($this->_format == 'atom' and $this->incontent) {
740 // balance tags properly
741 // note: i don't think this is actually necessary
742 if ($this->stack[0] == $el) {
743 $this->append_content("</$el>");
744 } else {
745 $this->append_content("<$el />");
746 }
747
748 array_shift($this->stack);
749 } else {
750 array_shift($this->stack);
751 }
752
753 $this->current_namespace = false;
754 }
755
756
764 public function concat(&$str1, $str2 = "")
765 {
766 if (!isset($str1)) {
767 $str1 = "";
768 }
769 $str1 .= $str2;
770 return $str1;
771 }
772
773 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
780 public function append_content($text)
781 {
782 // phpcs:enable
783 if (!empty($this->initem)) {
784 $this->concat($this->current_item[$this->incontent], $text);
785 } elseif (!empty($this->inchannel)) {
786 $this->concat($this->channel[$this->incontent], $text);
787 }
788 }
789
797 public function append($el, $text)
798 {
799 if (!$el) {
800 return;
801 }
802 if (!empty($this->current_namespace)) {
803 if (!empty($this->initem)) {
804 $this->concat($this->current_item[$this->current_namespace][$el], $text);
805 } elseif (!empty($this->inchannel)) {
806 $this->concat($this->channel[$this->current_namespace][$el], $text);
807 } elseif (!empty($this->intextinput)) {
808 $this->concat($this->textinput[$this->current_namespace][$el], $text);
809 } elseif (!empty($this->inimage)) {
810 $this->concat($this->image[$this->current_namespace][$el], $text);
811 }
812 } else {
813 if (!empty($this->initem)) {
814 $this->concat($this->current_item[$el], $text);
815 } elseif (!empty($this->intextinput)) {
816 $this->concat($this->textinput[$el], $text);
817 } elseif (!empty($this->inimage)) {
818 $this->concat($this->image[$el], $text);
819 } elseif (!empty($this->inchannel)) {
820 $this->concat($this->channel[$el], $text);
821 }
822 }
823 }
824
832 private function getAtomItemDescription(array $item, $maxlength = 500)
833 {
834 $result = "";
835
836 if (isset($item['summary'])) {
837 $result = $item['summary'];
838 } elseif (isset($item['atom_content'])) {
839 $result = $item['atom_content'];
840 }
841
842 // remove all HTML elements that can possible break the maximum size of a tooltip,
843 // like headings, image, video etc. and allow only simple style elements
844 $result = strip_tags($result, "<br><p><ul><ol><li>");
845
846 $result = str_replace("\n", "", $result);
847
848 if (strlen($result) > $maxlength) {
849 $result = substr($result, 0, $maxlength);
850 $result .= "...";
851 }
852
853 return $result;
854 }
855
862 private function getAtomImageUrl(array $feed)
863 {
864 if (isset($feed['icon'])) {
865 return $feed['logo'];
866 }
867
868 if (isset($feed['icon'])) {
869 return $feed['logo'];
870 }
871
872 if (isset($feed['webfeeds:logo'])) {
873 return $feed['webfeeds:logo'];
874 }
875
876 if (isset($feed['webfeeds:icon'])) {
877 return $feed['webfeeds:icon'];
878 }
879
880 if (isset($feed['webfeeds:wordmark'])) {
881 return $feed['webfeeds:wordmark'];
882 }
883
884 return "";
885 }
886}
887
888/*
889 * A method for the xml_set_external_entity_ref_handler()
890 *
891 * @param XMLParser $parser
892 * @param string $ent
893 * @param string|false $base
894 * @param string $sysID
895 * @param string|false $pubID
896 * @return bool
897function extEntHandler($parser, $ent, $base, $sysID, $pubID) {
898 print 'extEntHandler ran';
899 return true;
900}
901*/
902
910function rss_map_attrs($k, $v)
911{
912 return "$k=\"$v\"";
913}
914
921function xml2php($xml)
922{
923 $threads = 0;
924 $tab = false;
925 $array = array();
926 foreach ($xml->children() as $key => $value) {
927 '@phan-var-force SimpleXMLElement $value';
928 $child = xml2php($value);
929
930 //To deal with the attributes
931 foreach ($value->attributes() as $ak => $av) {
932 $child[$ak] = (string) $av;
933 }
934
935 //Let see if the new child is not in the array
936 if ($tab === false && array_key_exists($key, $array)) {
937 //If this element is already in the array we will create an indexed array
938 $tmp = $array[$key];
939 $array[$key] = null;
940 $array[$key][] = $tmp;
941 $array[$key][] = $child;
942 $tab = true;
943 } elseif ($tab === true) {
944 //Add an element in an existing array
945 $array[$key][] = $child;
946 } else {
947 //Add a simple element
948 $array[$key] = $child;
949 }
950
951 $threads++;
952 }
953
954
955 if ($threads == 0) {
956 return (string) $xml;
957 }
958
959 return $array;
960}
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 a 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.