dolibarr 24.0.3
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-2026 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
105 public $items = array();
109 public $current_item = array();
113 public $channel = array();
117 public $textinput = array();
121 public $image = array();
122
126 private $initem;
130 private $intextinput;
134 private $incontent;
138 private $inimage;
142 private $inchannel;
143
147 public $stack = array(); // parser stack
151 private $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
152
153
159 public function __construct($db)
160 {
161 $this->db = $db;
162 }
163
169 public function getFormat()
170 {
171 return $this->_format;
172 }
173
179 public function getUrlRss()
180 {
181 return $this->_urlRSS;
182 }
188 public function getLanguage()
189 {
190 return $this->_language;
191 }
197 public function getGenerator()
198 {
199 return $this->_generator;
200 }
206 public function getCopyright()
207 {
208 return $this->_copyright;
209 }
215 public function getLastBuildDate()
216 {
217 return $this->_lastbuilddate;
218 }
224 public function getImageUrl()
225 {
226 return $this->_imageurl;
227 }
233 public function getLink()
234 {
235 return $this->_link;
236 }
242 public function getTitle()
243 {
244 return $this->_title;
245 }
251 public function getDescription()
252 {
253 return $this->_description;
254 }
260 public function getLastFetchDate()
261 {
262 return $this->_lastfetchdate;
263 }
269 public function getItems()
270 {
271 return $this->_rssarray;
272 }
273
283 public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
284 {
285 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
286 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
287
288 $rss = '';
289 $str = ''; // This will contain content of feed
290
291 // Check parameters
292 if (!dol_is_url($urlRSS)) {
293 $this->error = "ErrorBadUrl";
294 return -1;
295 }
296
297 $this->_urlRSS = $urlRSS;
298 $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, '3'); // Force md5 hash (does not contain special chars)
299 $newmask = '0644';
300
301 //dol_syslog("RssParser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
302 $nowgmt = dol_now();
303
304 // Search into cache
305 $foundintocache = 0;
306 if ($cachedelay > 0 && $cachedir) {
307 $filedate = dol_filemtime($newpathofdestfile);
308 if ($filedate >= ($nowgmt - $cachedelay)) {
309 //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
310 $foundintocache = 1;
311
312 $this->_lastfetchdate = $filedate;
313 } else {
314 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.");
315 }
316 }
317
318 // Load file into $str
319 if ($foundintocache) { // Cache file found and is not too old
320 $str = file_get_contents($newpathofdestfile);
321 } else {
322 try {
323 $result = getURLContent($this->_urlRSS, 'GET', '', 1, array(), array('http', 'https'), 0);
324
325 if (!empty($result['content'])) {
326 $str = $result['content'];
327 } elseif (!empty($result['curl_error_msg'])) {
328 $this->error = 'Error retrieving URL '.$this->_urlRSS.' - '.$result['curl_error_msg'];
329 return -1;
330 }
331 } catch (Exception $e) {
332 $this->error = 'Error retrieving URL '.$this->_urlRSS.' - '.$e->getMessage();
333 return -2;
334 }
335 }
336
337 if ($str !== false) {
338 // Convert $str into xml
339 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
340 //print 'xx'.LIBXML_NOCDATA;
341 libxml_use_internal_errors(false);
342 if (LIBXML_VERSION < 20900) {
343 // Avoid load of external entities (security problem).
344 // Required only if LIBXML_VERSION < 20900
345 // @phan-suppress-next-line PhanDeprecatedFunctionInternal
346 libxml_disable_entity_loader(true);
347 }
348
349 $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
350 } else {
351 if (!function_exists('xml_parser_create')) {
352 $this->error = 'Function xml_parser_create are not supported by your PHP';
353 return -1;
354 }
355
356 try {
357 // @phan-suppress-next-line PhanTypeMismatchArgumentInternalProbablyReal
358 $xmlparser = xml_parser_create(null);
359
360 xml_parser_set_option($xmlparser, XML_OPTION_CASE_FOLDING, 0);
361 xml_parser_set_option($xmlparser, XML_OPTION_SKIP_WHITE, 1);
362 xml_parser_set_option($xmlparser, XML_OPTION_TARGET_ENCODING, "UTF-8");
363 //xml_set_external_entity_ref_handler($xmlparser, 'extEntHandler'); // Seems to have no effect even when function extEntHandler exists.
364
365 if (!is_resource($xmlparser) && !is_object($xmlparser)) {
366 $this->error = "ErrorFailedToCreateParser";
367 return -1;
368 }
369
370 // Handlers given as callable arrays (xml_set_object() and handler names as strings are deprecated since PHP 8.4)
371 xml_set_element_handler($xmlparser, array($this, 'feed_start_element'), array($this, 'feed_end_element'));
372 xml_set_character_data_handler($xmlparser, array($this, 'feed_cdata'));
373
374 $status = xml_parse($xmlparser, $str, false);
375
376 if (PHP_VERSION_ID < 80000) {
377 xml_parser_free($xmlparser); // No effect since PHP 8.0, deprecated since PHP 8.5
378 }
379
380 $rss = $this;
381 //var_dump($status.' '.$rss->_format);exit;
382 } catch (Exception $e) {
383 $rss = null;
384 }
385
386 // The root element was not rss, rdf or feed (an HTML error page, an empty answer...): it is not a feed.
387 // Errors after the root element are tolerated, the items read before the error are kept.
388 if ($rss && empty($this->_format)) {
389 $rss = null; // Error ErrorFailedToLoadRSSFile, and the answer is not saved into the cache
390 }
391 }
392 }
393
394 // If $rss loaded
395 if ($rss) {
396 // Save file into cache
397 if (empty($foundintocache) && $cachedir) {
398 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
399 if (!dol_is_dir($cachedir)) {
400 dol_mkdir($cachedir);
401 }
402 $fp = fopen($newpathofdestfile, 'w');
403 if ($fp) {
404 fwrite($fp, $str);
405 fclose($fp);
406 dolChmod($newpathofdestfile);
407
408 $this->_lastfetchdate = $nowgmt;
409 } else {
410 print 'Error, failed to open file '.$newpathofdestfile.' for write';
411 }
412 }
413
414 unset($str); // Free memory
415
416 if (empty($rss->_format)) { // If format not detected automatically
417 $rss->_format = 'rss';
418 if (empty($rss->channel)) {
419 $rss->_format = 'atom';
420 }
421 }
422
423 $items = array();
424
425 // Save description entries
426 if ($rss->_format == 'rss') {
427 //var_dump($rss);
428 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
429 if (!empty($rss->channel->language)) {
430 $this->_language = sanitizeVal((string) $rss->channel->language);
431 }
432 if (!empty($rss->channel->generator)) {
433 $this->_generator = sanitizeVal((string) $rss->channel->generator);
434 }
435 if (!empty($rss->channel->copyright)) {
436 $this->_copyright = sanitizeVal((string) $rss->channel->copyright);
437 }
438 if (!empty($rss->channel->lastbuilddate)) {
439 $this->_lastbuilddate = sanitizeVal((string) $rss->channel->lastbuilddate);
440 }
441 if (!empty($rss->channel->image->url[0])) {
442 $this->_imageurl = sanitizeVal((string) $rss->channel->image->url[0]);
443 }
444 if (!empty($rss->channel->link)) {
445 $this->_link = sanitizeVal((string) $rss->channel->link);
446 }
447 if (!empty($rss->channel->title)) {
448 $this->_title = sanitizeVal((string) $rss->channel->title);
449 }
450 if (!empty($rss->channel->description)) {
451 $this->_description = sanitizeVal((string) $rss->channel->description);
452 }
453 } else {
454 //var_dump($rss->channel);
455 if (!empty($rss->channel['language'])) {
456 $this->_language = sanitizeVal((string) $rss->channel['language']);
457 }
458 if (!empty($rss->channel['generator'])) {
459 $this->_generator = sanitizeVal((string) $rss->channel['generator']);
460 }
461 if (!empty($rss->channel['copyright'])) {
462 $this->_copyright = sanitizeVal((string) $rss->channel['copyright']);
463 }
464 if (!empty($rss->channel['lastbuilddate'])) {
465 $this->_lastbuilddate = sanitizeVal((string) $rss->channel['lastbuilddate']);
466 }
467 if (!empty($rss->image['url'])) {
468 $this->_imageurl = sanitizeVal((string) $rss->image['url']);
469 }
470 if (!empty($rss->channel['link'])) {
471 $this->_link = sanitizeVal((string) $rss->channel['link']);
472 }
473 if (!empty($rss->channel['title'])) {
474 $this->_title = sanitizeVal((string) $rss->channel['title']);
475 }
476 if (!empty($rss->channel['description'])) {
477 $this->_description = sanitizeVal((string) $rss->channel['description']);
478 }
479 }
480
481 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
482 $items = $rss->channel->item; // With simplexml
483 } else {
484 $items = $rss->items; // With xmlparse
485 }
486 //var_dump($items);exit;
487 } elseif ($rss->_format == 'atom') {
488 //var_dump($rss);
489 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
490 if (!empty($rss->generator)) {
491 $this->_generator = sanitizeVal((string) $rss->generator);
492 }
493 if (!empty($rss->lastbuilddate)) {
494 $this->_lastbuilddate = sanitizeVal((string) $rss->modified);
495 }
496 if (!empty($rss->link->href)) {
497 $this->_link = sanitizeVal((string) $rss->link->href);
498 }
499 if (!empty($rss->title)) {
500 $this->_title = sanitizeVal((string) $rss->title);
501 }
502 if (!empty($rss->description)) {
503 $this->_description = sanitizeVal((string) $rss->description);
504 }
505 } else {
506 //if (!empty($rss->channel['rss_language'])) $this->_language = (string) $rss->channel['rss_language'];
507 if (!empty($rss->channel['generator'])) {
508 $this->_generator = sanitizeVal((string) $rss->channel['generator']);
509 }
510 //if (!empty($rss->channel['rss_copyright'])) $this->_copyright = (string) $rss->channel['rss_copyright'];
511 if (!empty($rss->channel['modified'])) {
512 $this->_lastbuilddate = sanitizeVal((string) $rss->channel['modified']);
513 }
514 //if (!empty($rss->image['rss_url'])) $this->_imageurl = (string) $rss->image['rss_url'];
515 if (!empty($rss->channel['link'])) {
516 $this->_link = sanitizeVal((string) $rss->channel['link']);
517 }
518 if (!empty($rss->channel['title'])) {
519 $this->_title = sanitizeVal((string) $rss->channel['title']);
520 }
521 //if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description'];
522
523 if (!empty($rss->channel)) {
524 $this->_imageurl = sanitizeVal($this->getAtomImageUrl($rss->channel));
525 }
526 }
527 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
528 $tmprss = xml2php($rss);
529 $items = $tmprss['entry'];
530 } else {
531 // With simplexml
532 $items = $rss->items; // With xmlparse
533 }
534 //var_dump($items);exit;
535 }
536
537 // The links of the feed are used as href: keep only http(s) links (a "javascript:" link would run in Dolibarr)
538 if (!empty($this->_link) && !preg_match('/^https?:\/\//i', $this->_link)) {
539 $this->_link = '';
540 }
541
542 $i = 0;
543
544 // Loop on each record
545 if (is_array($items)) {
546 foreach ($items as $item) {
547 //var_dump($item);exit;
548 if (is_array($item)) {
549 // Optional elements of an item, to avoid PHP warnings when they are missing
550 $item += array('link' => '', 'title' => '', 'description' => '', 'guid' => '', 'author' => '', 'author_name' => '');
551 }
552 if ($rss->_format == 'rss') {
553 if (getDolGlobalString('EXTERNALRSS_USE_SIMPLEXML')) {
554 $itemLink = sanitizeVal((string) $item->link);
555 $itemTitle = sanitizeVal((string) $item->title);
556 $itemDescription = sanitizeVal((string) $item->description);
557 $itemPubDate = sanitizeVal((string) $item->pubDate);
558 $itemId = '';
559 $itemAuthor = '';
560 } else {
561 $itemLink = sanitizeVal((string) $item['link']);
562 $itemTitle = sanitizeVal((string) $item['title']);
563 $itemDescription = sanitizeVal((string) $item['description']);
564 $itemPubDate = sanitizeVal((string) $item['pubdate']);
565 $itemId = sanitizeVal((string) $item['guid']);
566 $itemAuthor = sanitizeVal((string) ($item['author'] ?? ''));
567 }
568
569 // Loop on each category
570 $itemCategory = array();
571 if (!empty($item->category) && is_array($item->category)) {
572 foreach ($item->category as $cat) {
573 $itemCategory[] = (string) $cat;
574 }
575 }
576 } elseif ($rss->_format == 'atom') {
577 $itemLink = (isset($item['link']) ? sanitizeVal((string) $item['link']) : '');
578 $itemTitle = sanitizeVal((string) $item['title']);
579 $itemDescription = sanitizeVal($this->getAtomItemDescription($item));
580 $itemPubDate = sanitizeVal((string) $item['created']);
581 $itemId = sanitizeVal((string) $item['id']);
582 $itemAuthor = sanitizeVal((string) ($item['author'] ? $item['author'] : $item['author_name']));
583 $itemCategory = array();
584 } else {
585 $itemLink = '';
586 $itemTitle = '';
587 $itemDescription = '';
588 $itemPubDate = '';
589 $itemId = '';
590 $itemAuthor = '';
591 $itemCategory = array();
592 print 'ErrorBadFeedFormat';
593 }
594
595 if (!preg_match('/^https?:\/\//i', $itemLink)) {
596 $itemLink = '';
597 }
598
599 // Add record to result array
600 $this->_rssarray[$i] = array(
601 'link' => $itemLink,
602 'title' => $itemTitle,
603 'description' => $itemDescription,
604 'pubDate' => $itemPubDate,
605 'category' => $itemCategory,
606 'id' => $itemId,
607 'author' => $itemAuthor
608 );
609 //var_dump($this->_rssarray);
610
611 $i++;
612
613 if ($maxNb > 0 && $i >= $maxNb) {
614 break; // We get all records we want (0 = no limit)
615 }
616 }
617 }
618
619 return 1;
620 } else {
621 $this->error = 'ErrorFailedToLoadRSSFile';
622 return -1;
623 }
624 }
625
626
627
628 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
637 public function feed_start_element($p, $element, $attrs)
638 {
639 // phpcs:enable
640 $el = $element = strtolower($element);
641 $attrs = array_change_key_case($attrs, CASE_LOWER);
642
643 // check for a namespace, and split if found
644 $ns = false;
645 if (strpos($element, ':')) {
646 list($ns, $el) = explode(':', $element, 2);
647 }
648 if ($ns and $ns != 'rdf') {
649 $this->current_namespace = $ns;
650 }
651
652 // if feed type isn't set, then this is first element of feed identify feed from root element
653 if (empty($this->_format)) {
654 if ($el == 'rdf') {
655 $this->_format = 'rss';
656 $this->feed_version = '1.0';
657 } elseif ($el == 'rss') {
658 $this->_format = 'rss';
659 $this->feed_version = (string) ($attrs['version'] ?? '');
660 } elseif ($el == 'feed') {
661 $this->_format = 'atom';
662 $this->feed_version = (string) ($attrs['version'] ?? '');
663 $this->inchannel = true;
664 }
665 return;
666 }
667
668 if ($el == 'channel') {
669 $this->inchannel = true;
670 } elseif ($el == 'item' || $el == 'entry') {
671 $this->initem = true;
672 if (isset($attrs['rdf:about'])) {
673 $this->current_item['about'] = $attrs['rdf:about'];
674 }
675 } elseif ($this->_format == 'rss' && $this->current_namespace == '' && $el == 'textinput') {
676 // if we're in the default namespace of an RSS feed,
677 // record textinput or image fields
678 $this->intextinput = true;
679 } elseif ($this->_format == 'rss' && $this->current_namespace == '' && $el == 'image') {
680 $this->inimage = true;
681 } elseif ($this->_format == 'atom' && in_array($el, $this->_CONTENT_CONSTRUCTS)) {
682 // handle atom content constructs
683 // avoid clashing w/ RSS mod_content
684 if ($el == 'content') {
685 $el = 'atom_content';
686 }
687
688 $this->incontent = $el;
689 } elseif ($this->_format == 'atom' && $this->incontent) {
690 // if inside an Atom content construct (e.g. content or summary) field treat tags as text
691 // if tags are inlined, then flatten
692 $attrs_str = implode(' ', array_map('rss_map_attrs', array_keys($attrs), array_values($attrs)));
693
694 $this->append_content("<$element $attrs_str>");
695
696 array_unshift($this->stack, $el);
697 } elseif ($this->_format == 'atom' && $el == 'link') {
698 // Atom support many links per containing element.
699 // Magpie treats link elements of type rel='alternate'
700 // as being equivalent to RSS's simple link element.
701 if (isset($attrs['rel']) && $attrs['rel'] == 'alternate') {
702 $link_el = 'link';
703 } elseif (!isset($attrs['rel'])) {
704 $link_el = 'link';
705 } else {
706 $link_el = 'link_'.$attrs['rel'];
707 }
708
709 $this->append($link_el, $attrs['href']);
710 } else {
711 // set stack[0] to current element
712 array_unshift($this->stack, $el);
713 }
714 }
715
716
717 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
725 public function feed_cdata($p, $text)
726 {
727 // phpcs:enable
728 if ($this->_format == 'atom' and $this->incontent) {
729 $this->append_content($text);
730 } else {
731 $current_el = implode('_', array_reverse($this->stack));
732 $this->append($current_el, $text);
733 }
734 }
735
736 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
744 public function feed_end_element($p, $el)
745 {
746 // phpcs:enable
747 $el = strtolower($el);
748
749 if ($el == 'item' or $el == 'entry') {
750 $this->items[] = $this->current_item;
751 $this->current_item = array();
752 $this->initem = false;
753 } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput') {
754 $this->intextinput = false;
755 } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image') {
756 $this->inimage = false;
757 } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS)) {
758 $this->incontent = false;
759 } elseif ($el == 'channel' or $el == 'feed') {
760 $this->inchannel = false;
761 } elseif ($this->_format == 'atom' and $this->incontent) {
762 // balance tags properly
763 // note: i don't think this is actually necessary
764 if ($this->stack[0] == $el) {
765 $this->append_content("</$el>");
766 } else {
767 $this->append_content("<$el />");
768 }
769
770 array_shift($this->stack);
771 } else {
772 array_shift($this->stack);
773 }
774
775 $this->current_namespace = false;
776 }
777
778
786 public function concat(&$str1, $str2 = "")
787 {
788 if (!isset($str1)) {
789 $str1 = "";
790 }
791 $str1 .= $str2;
792 return $str1;
793 }
794
795 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
802 public function append_content($text)
803 {
804 // phpcs:enable
805 if (!empty($this->initem)) {
806 $this->concat($this->current_item[$this->incontent], $text);
807 } elseif (!empty($this->inchannel)) {
808 $this->concat($this->channel[$this->incontent], $text);
809 }
810 }
811
819 public function append($el, $text)
820 {
821 if (!$el) {
822 return;
823 }
824 if (!empty($this->current_namespace)) {
825 if (!empty($this->initem)) {
826 $this->concat($this->current_item[$this->current_namespace][$el], $text);
827 } elseif (!empty($this->inchannel)) {
828 $this->concat($this->channel[$this->current_namespace][$el], $text);
829 } elseif (!empty($this->intextinput)) {
830 $this->concat($this->textinput[$this->current_namespace][$el], $text);
831 } elseif (!empty($this->inimage)) {
832 $this->concat($this->image[$this->current_namespace][$el], $text);
833 }
834 } else {
835 if (!empty($this->initem)) {
836 // @phpstan-ignore-next-line argument.type
837 $this->concat($this->current_item[$el], $text); // @phan-suppress-current-line PhanTypeMismatchArgument
838 } elseif (!empty($this->intextinput)) {
839 // @phpstan-ignore-next-line argument.type
840 $this->concat($this->textinput[$el], $text); // @phan-suppress-current-line PhanTypeMismatchArgument
841 } elseif (!empty($this->inimage)) {
842 // @phpstan-ignore-next-line argument.type
843 $this->concat($this->image[$el], $text); // @phan-suppress-current-line PhanTypeMismatchArgument
844 } elseif (!empty($this->inchannel)) {
845 $this->concat($this->channel[$el], $text);
846 }
847 }
848 }
849
857 private function getAtomItemDescription(array $item, $maxlength = 500)
858 {
859 $result = "";
860
861 if (isset($item['summary'])) {
862 $result = $item['summary'];
863 } elseif (isset($item['atom_content'])) {
864 $result = $item['atom_content'];
865 }
866
867 // remove all HTML elements that can possible break the maximum size of a tooltip,
868 // like headings, image, video etc. and allow only simple style elements
869 $result = strip_tags($result, "<br><p><ul><ol><li>");
870
871 $result = str_replace("\n", "", $result);
872
873 if (strlen($result) > $maxlength) {
874 $result = substr($result, 0, $maxlength);
875 $result .= "...";
876 }
877
878 return $result;
879 }
880
887 private function getAtomImageUrl(array $feed)
888 {
889 if (isset($feed['icon'])) {
890 return $feed['logo'];
891 }
892
893 if (isset($feed['icon'])) {
894 return $feed['logo'];
895 }
896
897 if (isset($feed['webfeeds:logo'])) {
898 return $feed['webfeeds:logo'];
899 }
900
901 if (isset($feed['webfeeds:icon'])) {
902 return $feed['webfeeds:icon'];
903 }
904
905 if (isset($feed['webfeeds:wordmark'])) {
906 return $feed['webfeeds:wordmark'];
907 }
908
909 return "";
910 }
911}
912
920function rss_map_attrs($k, $v)
921{
922 return "$k=\"$v\"";
923}
924
931function xml2php($xml)
932{
933 $threads = 0;
934 $tab = false;
935 $array = array();
936 foreach ($xml->children() as $key => $value) {
937 '@phan-var-force SimpleXMLElement $value';
938 $child = xml2php($value);
939
940 //To deal with the attributes
941 foreach ($value->attributes() as $ak => $av) {
942 $child[$ak] = (string) $av;
943 }
944
945 //Let see if the new child is not in the array
946 if ($tab === false && array_key_exists($key, $array)) {
947 //If this element is already in the array we will create an indexed array
948 $tmp = $array[$key];
949 $array[$key] = null;
950 $array[$key][] = $tmp;
951 $array[$key][] = $child;
952 $tab = true;
953 } elseif ($tab === true) {
954 //Add an element in an existing array
955 $array[$key][] = $child;
956 } else {
957 //Add a simple element
958 $array[$key] = $child;
959 }
960
961 $threads++;
962 }
963
964
965 if ($threads == 0) {
966 return (string) $xml;
967 }
968
969 return $array;
970}
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.
dol_now($mode='gmt')
Return date for now.
dolChmod($filepath, $newmask='')
Change mod of a file.
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, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array(), $morelogsuffix='')
Function to get a content from an URL (use proxy if proxy defined).
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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, $mode=0)
Returns a hash (non reversible encryption) of a string.