<?php
  header("Content-Type: text/xml;charset=utf-8");
  require_once("../inet_cfgfiles/xs_start.php");

  $selectSql="
  SELECT wwwlink,eweb_name,web_name
  FROM sys_defaults 
  WHERE sys_defaults_id='1'
  ";
  $xs->errln=__LINE__ +1;
  $defaults=$xs->getRecordA($selectSql);
//$vardump.=$xs->vardump($defaults,'defaults');

// UNIX_TIMESTAMP(pubDate)
//htmlentities(strip_tags($result['body'],'ENT_QUOTES'));

  $selectSql="
  SELECT news_id,title_es,resume_es,summary_es,details_es,foto0,published_date,
  year(news.created_date) AS year
  FROM news 
  WHERE publish='1' AND TIMESTAMPDIFF(SECOND,published_date,now())>0 AND title_es !=''
  ORDER BY priority DESC,published_date DESC
  LIMIT 0,16
  ";
  $xs->errln=__LINE__ +1;
  $Result_main=$xs->getQueryA($selectSql);
//$vardump.=$xs->vardump($Result_main,'Result_main');

  $ctitle=$defaults["web_name"]." tu puerta local de entrada a internet";
  $clink="http://".$defaults["wwwlink"];
  $cpubdate=date("r",mktime("00","00","01",date("m"),date("d"),date("Y")));
  $lastBuildDate = date("r", strtotime($Result_main[0]["published_date"]));


/*
  <image>
   <title>$ctitle</title>
   <url>$rss_logo_http_scr</url>
   <link>http://www.$rss_site</link>
<width>88</width> 
<height>31</height> 
<description>News for the insurance-wise</description> 
  </image>
*/

$rss=<<<RSSOUT
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
 <channel>
  <title>$ctitle</title>
  <link>$clink</link>
  <description>Las noticias locales más recientes desde $defaults[eweb_name]</description>
  <language>es-es</language>
  <pubDate>$cpubdate</pubDate> 
  <lastBuildDate>$lastBuildDate</lastBuildDate> 
  <copyright>Copyright $defaults[eweb_name]</copyright> 
  <atom:link href="$clink/inet_feed/rss.xml" rel="self" type="application/rss+xml" />

RSSOUT;
 foreach($Result_main as $r){
 $image_src = "$clink/data_$webx/images_news/$r[year]/$r[foto0]";
 $details_link="$clink/local_news.php?sel_news_id=$r[news_id]&amp;webx=$webx&amp;lang=es&amp;doctype=2&amp;secnumber=15";
 $rssfoto = <<<RSSFOTO
&lt;a href="$details_link"&gt;&lt;img style="float:right; border:1px solid #000000; padding: 0; width: 140px;" 
   width="140" border="1" align="right" hspace="20" alt="" title="" src="$image_src" /&gt;&lt;/a&gt;&lt;br /&gt;
RSSFOTO;
 $title = $r["title_es"]; //subject line for the RSS item
 $resume = $r["resume_es"];

 $summary =  htmlspecialchars(strip_tags($r["summary_es"]));
// $description = str_replace ("&amp","&#0160;",htmlspecialchars(strip_tags($description)));
 $pubdate = date("r", strtotime($r["published_date"]));

/*
Implementation of the guid element is equally important. The RSS 2.0 standard doesn't discuss the form of the guid; it only asks the author to ensure that it is globally unique. There is no scope for the OSF GUID standard to be used within most blogging tools, so you have to formulate your own system. (I'll touch upon this again when we talk about Atom in Chapter 7.) 

For the template shown earlier, I considered various things. First, the guid's purpose is to tell applications if the entry is new or if it has changed. Second, within my own blogs I allow people to add comments to the entries. I consider this a change to the entry, so my guid must reflect this. Because this change isn't reflected in the link to the entry, the link alone isn't a good guid. So, by combining the link with the last-updated-date value, I can make a guid that is globally unique and changes when it needs to. For added measure, I add the string GUID to the front of it to prevent it from looking too much like a retrievable URL--which, of course, it isn't. Hence: 

  <guid isPermaLink="false">GUID:<$MTEntryLink$> </g<$MTEntryDate format= 
  "%a%d%b%Y%I:%M"$></guid> 
*/

 $rss.=<<<RSSOUT
  <item>
   <title>$title</title>
   <link>$details_link</link>
   <guid>$details_link</guid>
   <description>$rssfoto
 &lt;p&gt;$resume&lt;/p&gt;
 &lt;p&gt;$summary&lt;/p&gt;
   </description>
   <pubDate>$pubdate</pubDate>
  </item>

RSSOUT;

}
$rss.=<<<RSSOUT
 </channel>
</rss>

RSSOUT;

/*
<a href="http://feedvalidator.org/check.cgi?url=http%3A//www.infonerja.com/inet_feed/rss.xml"><img src="valid-rss.png" alt="[validar RSS]" title="validar RSS" /></a>
<link rel="alternate" type="application/rss+xml" title="Title of your feed (RSS 2.0)" href="url_of_feed.xml" />
*/

// file_put_contents("feed.xml",$rss);
// $rss=str_replace("feed.xml","rss.xml",$rss);
 print "$rss"
?>
