Jump to content
Fórum Script Brasil
  • 0

Ordenar vários xml externos na mesma página php


rubensxxx4

Question

Bom dia, moçada estou com um script que lista itens de vários rss/xml externos, porém quero ordenar os itens (dos vários rss) como se fossem uma so lista. A ordenação poderia ser por qualquer critério (atributo do item rss) que eu queira, tipo title, category...

Já pesquisei e testei vários scripts na web e aqui do fórum e nenhum atendeu completamente!

O script:

<?php  

//header("Content-Type: text/html; charset=UTF-8");

// configurações do banco de dados
$con = mysql_connect("xxx","xxx","xxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
  mysql_select_db("xxx", $con);
  
  $criterio  = $_GET["criterio"];
  
  if(empty($criterio)){
  $criterio = "category";
  }


   $id_channel = $_GET["id_channel"];
   
   $Tipo_usuario = $_COOKIE["Tipo_usuario"];
$id_usuario = $_COOKIE["id_usuario"];

   if(empty($id_channel)){ 
   $seletor = mysql_query("Select * From Editor_channels where tipo = 1 UNION SELECT * FROM Editor_channels where IDautor_usuario = $id_usuario order by '$criterio'", $con); 
   } else {
   $seletor = mysql_query("SELECT * FROM Editor_channels where id_channel = '$id_channel' order by '$criterio'", $con); 
   }
   while ($row = mysql_fetch_array($seletor)) {
   $fonte_url  = $row['linkxml'];
  
   if(empty($fonte_url)){ 
   $fonte_url = "http://rss.terra.com.br/0,,EI1,00.xml";
   }
   
   
   
   #carrega o arquivo XML e retornando um Array
$xml = simplexml_load_file($fonte_url);

// para cada registro desse arquivo...
   foreach ($xml->channel as $channel) {
   
   // puxa valores do xml e passa para variaveis
   $Ctitle = $channel->title;
   $Clink = $channel->link;
   $Cdescription = $channel->description;
   $Clanguage = $channel->language;
   $CpubDate = $channel->pubDate;
   $Ccategory = $channel->category;
   $Cimage = $channel->image->url;
  
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Fontes</title>
<link href="stylex.css" media="all" rel="stylesheet" type="text/css" />

<style type="text/css">
body, html {margin:0; padding:0; border:0; height:100%; background-color:#FFFFFF /* Re-sets IE to "zero" for these values */
</style>


<style type="text/css">


a:link { color: #333; font-size:11px; font-weight:bold; text-decoration:none}
a:visited { color: #333; text-decoration: none; font-size:10px; font-weight:normal}
a:hover { color: #666; text-decoration: none; }
a:active { color: #333; font-size:10px; font-weight:bold}
</style>

</head>

<body>

<?php
#lendo cada nó item e atribuindo à variavel $item
          
foreach($xml->channel->item as $item)
{ 

  $descricao = utf8_decode($item->category);
  $data =  $item->pubDate;
  $titulocanal = utf8_decode($Ctitle);
  $tituloitem = utf8_decode($item->title);
  $linkfeed = $item->link;
  $linkfeed2 = str_replace("http://", "", "$linkfeed");
  

        echo "<table width=\"560\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
  <tr align=\"center\">
    <td width=\"45\"><div align=\"center\">&nbsp;</div></td>
    <td width=\"202\"><div align=\"center\"><a href=\"frame4.php?linkfeed=$linkfeed2\" target=\"Feed\" alt=\"$tituloitem\" title=\"$tituloitem\">" .substr($tituloitem, 0, 30). "</a></div></td>
    <td width=\"79\"><div align=\"center\"><a href=\"$item->link\" target=\"Feed\">" .date('d/m/Y', strtotime($data)). "</a></div></td>
    <td width=\"120\"><div align=\"center\"><a href=\"$item->link\" target=\"Feed\" alt=\"$descricao\" title=\"$descricao\">".substr($descricao, 0, 15)."</a></div></td>
    <td width=\"120\"><div align=\"center\"><a href=\"$item->link\" target=\"Feed\" alt=\"$titulocanal\" title=\"$titulocanal\">".substr($titulocanal, 0, 15)."</a></div></td>
  </tr>
   <tr align=\"center\">
  <td>&nbsp;</td>
    <td >&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
        <td>&nbsp;</td>
  </tr>
</table>";
}
} } 
?>

</body>
</html>

Alguém sabe?

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...