<?php
error_reporting(0);
date_default_timezone_set("America/Managua"); /* Zona horaria para la fecha de las noticias */
$chars = 250; /* Número de caracteres en la descripción de cada noticia */
$query = "Nicaragua"; /* Término de busqueda en que se relacionarán las noticias */
$ned = "ni"; /* Localización en que se relacionarán las noticias */
$hl = "ni"; /* Lenguaje en que se relacionarán las noticias */
$gnd = "news.google.com.mx"; /* URL de Google Noticias con nombre de dominio según país */
function fechaesp($texto) {
$fechaesp = array(
'Monday' => 'Lunes',
'Tuesday' => 'Martes',
'Wednesday' => 'Miércoles',
'Thursday' => 'Jueves',
'Friday' => 'Viernes',
'Saturday' => 'Sábado',
'Sunday' => 'Domingo',
'January' => 'Enero',
'February' => 'Febrero',
'March' => 'Marzo',
'April' => 'Abril',
'May' => 'Mayo',
'June' => 'Junio',
'July' => 'Julio',
'August' => 'Agosto',
'September' => 'Septiembre',
'October' => 'Octubre',
'November' => 'Noviembre',
'December ' => 'Diciembre'
);
foreach($fechaesp as $a => $b) $texto = str_replace($a,$b,$texto);
return $texto;
}
?>
<html>
<head>
<title>Noticias <?php echo $query ?></title>
<style type="text/css">
.newsarticle {
font-size:14px;
margin-bottom: 30px;
width: 500px;
}
.newsarticle div {
font-size:14px;
}
.newsarticle h5 {
margin:0;
font-weight: 400;
color:#888888;
}
a.rmorelink, a.rmorelink:visited {
font-size:12px;
color: #555555;
text-decoration:none;
float:right;
text-transform:uppercase;
}
a.rmorelink:hover {
color: #000000;
}
</style>
</head>
<body>
<?php
$news = simplexml_load_file('http://'.$gnd.'/news/feeds?pz=1&cf=all&ned='.$ned.'&hl='.$hl.'&q='.$query.'&output=rss'); /* URL del Feed RRS de Google Noticias */
$feeds = array();
$i = 0;
foreach ($news->channel->item as $item)
{
if ($i < 10) {
preg_match('@src="([^"]+)"@', $item->description, $match);
$parts = explode('<font size="-1">', $item->description);
$feeds[$i]['title'] = mb_convert_encoding((string) $item->title, "HTML-ENTITIES", "UTF-8");
$feeds[$i]['link'] = (string) $item->link;
$feeds[$i]['link'] = preg_replace('#http://news.google.com(.*?)url=(.*?)#s', '',$feeds[$i]['link']);
$feeds[$i]['image'] = $match[1];
$feeds[$i]['image'] = str_replace('//', 'http://', $feeds[$i]['image']);
$feeds[$i]['story'] = mb_convert_encoding(strip_tags($parts[2]), "HTML-ENTITIES", "UTF-8");
$stringCut = substr($feeds[$i]['story'], 0, $chars);
$feeds[$i]['story'] = substr($stringCut, 0, strrpos($stringCut, ' ')).' ...<br /><a class="rmorelink" href="'.$feeds[$i]['link'].'">Leer Más »</a>';
$feeds[$i]['date'] = (string) $item->pubDate;
$feeds[$i]['date'] = date("l, d F o g:i A", strtotime($feeds[$i]['date']));
$feeds[$i]['date'] = fechaesp($feeds[$i]['date']);
echo '<div class="newsarticle"><a href="';
print($feeds[$i]['link']);
echo '" taget="_blank"><b>';
print($feeds[$i]['title']);
echo '</b></a><br /><h5>';
print($feeds[$i]['date']);
echo '</h5><div>';
echo '<img src="'.$feeds[$i]['image'].'" />';
print($feeds[$i]['story']);
echo '</div></div>';
$i++;
}
}
?>
</body>
</html>