<?php header('Content-type: text/xml');
include '../utilitats/funcions.php';
include 'wp-config.php';
// ...Connect to WP database
$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if ( !$dbc ) die( 'Not Connected: ' . mysql_error());
// Select the database
$db = mysql_select_db(DB_NAME);
if (!$db) echo "There is no database: " . $db;
global $wpdb; // you may not need this part. Try with and without it
//echo $wpdb->prefix; // here is your database prefix

?>
<rss version="2.0">
<channel>
<title>Intercambia.net - trucos para ahorrar, cosas gratis, trueques, consumo y salud</title>
<description>Feed con todos los comentarios recientes del blog</description>
<link>http://intercambia.net/temas/</link>
<copyright>El material de este blog es libre para compartirlo en cualquier forma siempre que se cite la fuente</copyright>
<image>
<title>Intercambia.net</title>
<url>http://intercambia.net/disseny/cabecera2.png</url>
<link>http://intercambia.net/temas/</link>
<width>144</width>
<height>35</height>
</image>
<?php /*
$dbhost = 'localhost';
$dbname = 'intercambia';
$dbuser = 'webposible';
$dbpasswd = 'manga5jossm@r';

if (!($conecta=mysql_connect($dbhost,$dbuser,$dbpasswd)))
{
  echo "Error conectant amb la base de dades.";
  exit();
}
if (!mysql_select_db($dbname,$conecta))
{
  echo "Error sel·leccionant la base de dades.";
  exit();
}
*/
//posts publicats a elvirtual
$q="SELECT *,UNIX_TIMESTAMP(comment_date) AS pubDate
FROM wp_comments WHERE comment_approved='1' AND comment_type!='pingback' AND comment_type!='trackback' ORDER BY pubDate DESC LIMIT 0,14";
$doGet=mysql_query($q);
//echo "$q";

while($result = mysql_fetch_array($doGet)){

  $s="SELECT post_title, ID, guid FROM wp_posts WHERE ID='$result[comment_post_ID]'";
  $c=mysql_query($s);
  $f=mysql_fetch_array($c);
  $titol=$f['post_title'];

//comment_author
//comment_author_url

$titol=utf8_to_unicode($titol);
$titol=unicode_to_entities_preserving_ascii($titol);
$titol=htmlentities(strip_tags( $titol,'ENT_QUOTES'));

$text=$result['comment_content'];

//$text=utf8_to_unicode($t);
//echo $text;
//text= $result['comment_content'];
if ($result[comment_author_url]!=""){
  $text="Comentario de &lt;b&gt;&lt;a href=$result[comment_author_url]&gt;$result[comment_author]&lt;/a&gt;&lt;/b&gt;:&lt;br&gt;&lt;br&gt;".$text;
}else{
  $text="Comentario de &lt;b&gt;$result[comment_author]&lt;/b&gt;:&lt;br&gt;&lt;br&gt;".$text;
}
//$text=unicode_to_entities_preserving_ascii($text);
$text=utf8_decode($text);
$text=htmlentities(strip_tags( $text,'ENT_QUOTES'));

//echo "$text";
//echo "--";

$idz=$result['comment_ID'];
$urlpost=$f['guid'];

$urlpost2=$f[guid]."#comment-".$result[comment_ID];

$titol=str_replace("&amp;ntilde;", "ñ", $titol);
$titol=str_replace("&amp;Ntilde;", "Ñ", $titol);
$titol=str_replace("&amp;aacute;", "á", $titol);
$titol=str_replace("&amp;eacute;", "é", $titol);
$titol=str_replace("&amp;iacute;", "í", $titol);
$titol=str_replace("&amp;oacute;", "ó", $titol);
$titol=str_replace("&amp;uacute;", "ú", $titol);
$titol=str_replace("&amp;Aacute;", "Á", $titol);
$titol=str_replace("&amp;Eacute;", "É", $titol);
$titol=str_replace("&amp;Iacute;", "Í", $titol);
$titol=str_replace("&amp;Oacute;", "Ó", $titol);
$titol=str_replace("&amp;Uacute;", "Ú", $titol);


$text=str_replace("&amp;ntilde;", "ñ", $text);
$text=str_replace("&amp;Ntilde;", "Ñ", $text);
$text=str_replace("&amp;aacute;", "á", $text);
$text=str_replace("&amp;eacute;", "é", $text);
$text=str_replace("&amp;iacute;", "í", $text);
$text=str_replace("&amp;oacute;", "ó", $text);
$text=str_replace("&amp;uacute;", "ú", $text);
$text=str_replace("&amp;Aacute;", "Á", $text);
$text=str_replace("&amp;Eacute;", "É", $text);
$text=str_replace("&amp;Iacute;", "Í", $text);
$text=str_replace("&amp;Oacute;", "Ó", $text);
$text=str_replace("&amp;Uacute;", "Ú", $text);
$text=str_replace("&amp;ntilde;", "ñ", $text);
$text=str_replace("&amp;Ntilde;", "Ñ", $text);

/*$text=str_replace("&amp;#255;", "á", $text);
$text=str_replace("&amp;#233;", "é", $text);
$text=str_replace("&amp;#237;", "í", $text);
$text=str_replace("&amp;#243;", "ó", $text);
$text=str_replace("&amp;#250;", "ú", $text);
$text=str_replace("&amp;Aacute;", "Á", $text);
$text=str_replace("&amp;Eacute;", "É", $text);
$text=str_replace("&amp;Iacute;", "Í", $text);
$text=str_replace("&amp;Oacute;", "Ó", $text);
$text=str_replace("&amp;Uacute;", "Ú", $text);*/

$titol=str_replace("&amp;#241;", "ñ", $titol);
$titol=str_replace("&amp;#57;", "Ñ", $titol);
$titol=str_replace("&amp;#225;", "á", $titol);
$titol=str_replace("&amp;#233;", "é", $titol);
$titol=str_replace("&amp;#237;", "í", $titol);
$titol=str_replace("&amp;#243;", "ó", $titol);
$titol=str_replace("&amp;#250;", "ú", $titol);
$titol=str_replace("&amp;#41;", "Á", $titol);
$titol=str_replace("&amp;#49;", "É", $titol);
$titol=str_replace("&amp;#53;", "Í", $titol);
$titol=str_replace("&amp;#211;", "Ó", $titol);
$titol=str_replace("&amp;#62;", "Ú", $titol);

$text=str_replace("&amp;#241;", "ñ", $text);
$text=str_replace("&amp;#57;", "Ñ", $text);
$text=str_replace("&amp;#225;", "á", $text);
$text=str_replace("&amp;#233;", "é", $text);
$text=str_replace("&amp;#237;", "í", $text);
$text=str_replace("&amp;#243;", "ó", $text);
$text=str_replace("&amp;#250;", "ú", $text);
$text=str_replace("&amp;#41;", "Á", $text);
$text=str_replace("&amp;#49;", "É", $text);
$text=str_replace("&amp;#53;", "Í", $text);
$text=str_replace("&amp;#211;", "Ó", $text);
$text=str_replace("&amp;#62;", "Ú", $text);


$text=str_replace("&ntilde;", "ñ", $text);
$text=str_replace("&Ntilde", "Ñ", $text);
$text=str_replace("&aacute;", "á", $text);
$text=str_replace("&eacute;", "é", $text);
$text=str_replace("&iacute;", "í",$text);
$text=str_replace("&oacute;", "ó",$text);
$text=str_replace("&uacute;", "ú",$text);
$text=str_replace("&Aacute;", "Á", $text);
$text=str_replace("&Eacute;", "É", $text);
$text=str_replace("&Iacute;", "Í", $text);
$text=str_replace("&Oacute;", "Ó", $text);
$text=str_replace("&Uacute;", "Ú", $text);
$text=str_replace("&iquest;", "¿", $text);



//if ($result['post_type']=="page"){$p="page_id=".$idz;}else{$p="p=".$idz;}

//if ($result['post_type']=="page"){$p="page_id=".$idz;}else{$p="p=".$idz;}


//$titol20=ereg_replace(' ', '%20', $titol);
$titol20=urlencode($titol);


?>
     <item>
	<guid><?php echo $urlpost2; ?></guid>
        <title> <?php echo $titol; ?></title>
        <description> <?php echo $text; ?></description>
        <link><?php echo $urlpost; ?></link>
        <pubDate><?php echo strftime( "%a, %d %b %Y %T %z" , $result['pubDate']); ?></pubDate>
	<comments><?php echo $urlpost;?>#comment</comments>
     </item>  
<?php
}
?>
</channel>
</rss>
