You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. //~ Include RSS Fusion
  3. require_once 'vendor/RSS-Fusion/index.php';
  4. //~ Check if conf file exist
  5. if(!array_key_exists('c', $_GET)
  6. OR !isset($_GET['c'])
  7. OR !file_exists(TL_ROOT . '/../../c/'.$_GET['c'])){
  8. exit;
  9. }
  10. $conf = TL_ROOT . '/../../c/'.$_GET['c'];
  11. //~ Update file date (file is deleted if is not updated every 30 days)
  12. touch($conf);
  13. //~ Open conf
  14. $oConf = json_decode(file_get_contents($conf));
  15. if($oConf && gettype($oConf) == 'object'){
  16. $_links = array();
  17. $_items = array();
  18. $_c = array();
  19. //~ Load feeds
  20. foreach($oConf->flux as $link){
  21. //array_push($_links, $link['flux']);
  22. $oFeeds = new FeedReader(array($link->flux));
  23. if(!is_null($oFeeds->objParseFeed)){
  24. foreach($oFeeds->objParseFeed->items as $item){
  25. if(!empty($item['link']) && !in_array($item['link'], $_c)){
  26. //~ Prevent duplicate item by link
  27. array_push($_c, $item['link']);
  28. //~ Where
  29. $_cible = explode('|', $link->where);
  30. if(count($_cible) > 1){
  31. $merge_str = "";
  32. foreach ($_cible as $cible) {
  33. $merge_str .= " ".strtolower($item[$cible]);
  34. }
  35. }else{
  36. if($_cible[0] && $_cible[0] != 'all'){
  37. $merge_str = strtolower($item[$_cible[0]]);
  38. }else{
  39. $merge_str = strtolower($item['title']." ".$item['description']." ".$item['link']);
  40. }
  41. }
  42. $_words = explode(',', $link->words);
  43. if(count($_words) && $link->words != ""){
  44. $oIsIn = $oFeeds->isInStr($merge_str, $_words);
  45. if($link->filter == 'show' && $oIsIn){
  46. //~ add
  47. array_push($_items, $item);
  48. }elseif($link->filter == 'hide' && !$oIsIn){
  49. //~ add
  50. array_push($_items, $item);
  51. }
  52. }else{
  53. //~ No "keywords", show all
  54. array_push($_items, $item);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. //~ Sort by pubdate
  61. $pub = array();
  62. foreach ($_items as $key => $row)
  63. {
  64. $pub[$key] = $row['pubdate'];
  65. }
  66. array_multisort($pub, SORT_DESC, $_items);
  67. //~ Generate RSS
  68. $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>';
  69. $rssfeed .= '<rss version="2.0">';
  70. $rssfeed .= '<channel>';
  71. $rssfeed .= '<title>'.($oConf->title && !empty($oConf->title) ? $oConf->title : 'Flux personnalisé RSS Fusion').'</title>';
  72. $rssfeed .= '<link>'.($oConf->link && !empty($oConf->link) ? $oConf->link : 'https://framagit.org/Erase/RSS-Fusion-demo').'</link>';
  73. $rssfeed .= '<description>'.($oConf->description && !empty($oConf->description) ? $oConf->description : 'Flux généré avec RSS Fusion').'</description>';
  74. if(count($_items)){
  75. foreach ($_items as $item){
  76. $rssfeed .= '<item>';
  77. $rssfeed .= '<title>'.html_entity_decode($item['title']).'</title>';
  78. $rssfeed .= '<link>'.$item['link'].'</link>';
  79. $rssfeed .= '<description><![CDATA['.$item['description'].']]></description>';
  80. $rssfeed .= '<pubDate>'.date('r', $item['pubdate']).'</pubDate>';
  81. $rssfeed .= '<category>'.$item['category'].'</category>';
  82. $rssfeed .= '<enclosure url="'.$item['enclosure'].'" />';
  83. $rssfeed .= '<permalink>'.$item['permalink'].'</permalink>';
  84. $rssfeed .= '</item>';
  85. }
  86. }
  87. $rssfeed .= '</channel>';
  88. $rssfeed .= '</rss>';
  89. //~ Return RSS content
  90. header('Content-type: application/xml');
  91. echo $rssfeed;
  92. }