Foros del Web » Programando para Internet » PHP »

Leer varios feed intercalandolos

Estas en el tema de Leer varios feed intercalandolos en el foro de PHP en Foros del Web. Hola amigos como estais, Vereis tengo este codigo: Que lee varios feed a la vez y los muestra, la cosa es que me gustaria en ...
  #1 (permalink)  
Antiguo 11/04/2011, 12:10
 
Fecha de Ingreso: marzo-2007
Mensajes: 751
Antigüedad: 17 años, 1 mes
Puntos: 4
Leer varios feed intercalandolos

Hola amigos como estais,

Vereis tengo este codigo:

Que lee varios feed a la vez y los muestra, la cosa es que me gustaria en vez de mostrarlos en grupos los intercalase osea pusiese mezclados todos las noticias no las de un feed 1º despues las del 2º y asi, a ver si alguien se le ocurre como se podria hacer esto, o si alguien conoce algu script que hagaesta funcion pues me vendria de perlas

require_once('simplepie.inc');

// Because we're using multiple feeds, let's just set the headers here.
header('Content-type:text/html; charset=utf-8');

// These are the feeds we want to use
$feeds = array(
'http://feeds2.feedburner.com/DVHardware',
'http://news.google.com/?output=atom',
'http://rss.cnn.com/rss/cnn_topstories.rss'
);

// This array will hold the items we'll be grabbing.
$first_items = array();

// Let's go through the array, feed by feed, and store the items we want.
foreach ($feeds as $url)
{
// Use the long syntax
$feed = new SimplePie();
$feed->set_feed_url($url);
$feed->init();

// How many items per feed should we try to grab?
$items_per_feed = 5;

// As long as we're not trying to grab more items than the feed has, go through them one by one and add them to the array.
for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++)
{
$first_items[] = $feed->get_item($x);
}

// We're done with this feed, so let's release some memory.
unset($feed);
}

// We need to sort the items by date with a user-defined sorting function. Since usort() won't accept "SimplePie::sort_items", we need to wrap it in a new function.
function sort_items($a, $b)
{
return SimplePie::sort_items($a, $b);
}

// Now we can sort $first_items with our custom sorting function.
usort($first_items, "sort_items");


// Begin the (X)HTML page.
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Multifeeds Test page</title>
<link rel="stylesheet" href="simplepie.css" type="text/css" media="screen" title="SimplePie Styles" charset="utf-8" />
<style type="text/css">
div#site {
width:600px;
}
span.footnote {
white-space:nowrap;
}
h1 {
line-height:1.4em;
}
.clearBoth {
clear:both;
}
</style>
</head>
<body>
<div id="site">

<div class="chunk">
<h1>Quick-n-Dirty Multifeeds Demo</a></h1>
</div>

<?php
foreach($first_items as $item):
$feed = $item->get_feed();
?>

<div class="chunk">
<h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8'); ?></a></h4>

<?php echo $item->get_content(); ?>

<?php if ($enclosure = $item->get_enclosure()): ?>
<div>
<?php echo $enclosure->native_embed(array(
// New 'mediaplayer' attribute shows off Flash-based MP3 and FLV playback.
'mediaplayer' => '../demo/for_the_demo/mediaplayer.swf'
)); ?>
</div>
<?php endif; ?>

<p class="footnote">Source: <a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a> | <?php echo $item->get_date('j M Y | g:i a'); ?></p>
</div>

<?php endforeach; ?>

<p class="footnote">This is a test of the emergency broadcast system. This is only a test&hellip; beeeeeeeeeeeeeeeeeeeeeeeeeep!</p>

</div>


Un saludo amigos
  #2 (permalink)  
Antiguo 11/04/2011, 13:10
 
Fecha de Ingreso: marzo-2007
Mensajes: 751
Antigüedad: 17 años, 1 mes
Puntos: 4
Respuesta: Leer varios feed intercalandolos

Alguien se le ocurre algo?
  #3 (permalink)  
Antiguo 11/04/2011, 17:00
 
Fecha de Ingreso: marzo-2007
Mensajes: 751
Antigüedad: 17 años, 1 mes
Puntos: 4
Respuesta: Leer varios feed intercalandolos

Nadie se le ocurre nada amigos?
  #4 (permalink)  
Antiguo 12/04/2011, 05:59
 
Fecha de Ingreso: marzo-2007
Mensajes: 751
Antigüedad: 17 años, 1 mes
Puntos: 4
Respuesta: Leer varios feed intercalandolos

Una ayudita amigos

Etiquetas: feed
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:04.