<?php

function getRss() {
  $tab_rss = array();
  $tab_rss["News"] = dispRssChannelNews;
  $tab_rss["Videos"] = dispRssChannelVideos;

  if (!isset($_GET['rss']) or !array_key_exists($_GET['rss'], $tab_rss))
    die("Flux RSS introuvable!");

  header('Content-type: application/rss+xml; charset=utf-8');
  echo '<?xml version="1.0" encoding="utf-8" ?>';
  echo '<rss version="2.0">';
  $tab_rss[$_GET['rss']]();
  echo '</rss>';
  }

function dispRssChannelNews() {
  $str = '<channel>';
  $str .= '<title>Actualités EPTV</title>';
  $str .= '<link>http://'.htmlspecialchars($_SERVER['HTTP_HOST']).'/?html=News</link>';
  $str .= '<description>L\'actualités d\'EPTV</description>';
  $str .= '<language>fr</language>';
  $str .= '<copyright>EPTV</copyright>';
  $str .= '<generator>Seblu RSS Generator</generator>';
  $result = getLastNews(0);
  if (mysql_num_rows($result))
    while ($news = mysql_fetch_array($result)) {
      $str .= '<item>';
      $str .= '<title>'.htmlspecialchars(strip_tags($news["news_title"])).'</title>';
      $str .= '<description>'.htmlspecialchars(strip_tags($news["news_comment"])).'</description>';
      $str .= '<pubDate>'.htmlspecialchars(date("r", strtotime($news["news_date"]))).'</pubDate>';
      $str .= '<guid>'.htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].'/?html=News#'.$news["news_id"]).'</guid>';
      $str .= '<link>'.htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].'/?html=News#'.$news["news_id"]).'</link>';
      $str .= '</item>';
    }
  $str .= '</channel>';
  echo $str;
}

function dispRssChannelVideos() {
  $str = '<channel>';
  $str .= '<title>Vidéos EPTV</title>';
  $str .= '<link>http://'.htmlspecialchars($_SERVER['HTTP_HOST']).'/?html=Videos</link>';
  $str .= '<description>Le flux des vidéos d\'EPTV</description>';
  $str .= '<language>fr</language>';
  $str .= '<copyright>EPTV</copyright>';
  $str .= '<generator>Seblu RSS Generator</generator>';
  $result = getLastVideosByTendu(0);
  if (mysql_num_rows($result))
    while ($video = mysql_fetch_array($result)) {
      $str .= '<item>';
      $str .= '<title>'.htmlspecialchars(strip_tags($video["video_name"])).'</title>';
      $str .= '<description>'.htmlspecialchars(strip_tags($video["video_comment"])).'</description>';
      $str .= '<pubDate>'.htmlspecialchars(date("r", strtotime($video["video_date"]))).'</pubDate>';
      $str .= '<guid>'.htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].'/?video='.$video["video_id"]).'</guid>';
      $str .= '<link>'.htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].'/?html=Videos&year_page='.date("Y", strtotime($video["video_date"]))).'</link>';
      $str .= '</item>';
    }
  $str .= '</channel>';
  echo $str;
}
?>
