Diskuse

Téma: RSS čtečka

Předělal jsem HCM na aktuální verzi zobrazení RSS feedu, má to pár much, když by se někdo nudil, mohl by to fixnout.
<?php

/* --- kontrola jadra --- */
if(!defined('_core')) exit;

/* --- definice funkce modulu --- */
function _HCM_custom_rss($url,$pocet,$titulky)
{

$RSS_Content = array();

function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->textContent;

$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->textContent;

$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->textContent;

$y["title"] = $title;
$y["link"] = $link;
$y["description"] = $description;
$y["type"] = $type;

return $y;
}

function RSS_Channel($channel)
{
global $RSS_Content;

$items = $channel->getElementsByTagName("item");

// Processing channel

$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);

// Processing articles

foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}

function RSS_Retrieve($url)
{
global $RSS_Content;

$doc = new DOMDocument();
$opts = array(
'http' => array(
'user_agent' => 'PHP libxml agent',
)
);

$context = stream_context_create($opts);
libxml_set_streams_context($context);

$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
RSS_Channel($channel);
}

}

function RSS_Display($url, $size = 15, $site = 0)
{
global $RSS_Content;

$opened = false;
$page = "";
$site = (intval($site) == 0) ? 1 : 0;

RSS_Retrieve($url);
if($size > 0)
$recents = array_slice($RSS_Content, $site, $size + 1 - $site);

foreach($recents as $article)
{
$type = $article["type"];
if($type == 0)
{
if($opened == true)
{
$page .="</ul>\n";
$opened = false;
}
$page .="<b>";
}
else
{
if($opened == false)
{
$page .= "<ul>\n";
$opened = true;
}
}
$title = $article["title"];
$link = $article["link"];
$description = $article["description"];
$page .= "<li><a href=\"$link\" onclick=\"return !window.open(this.href)\">$title</a>";
if($description != false)
{
$page .= "<br>$description";
}
$page .= "</li>\n";

if($type==0)
{
$page .="</b><br />";
}

}

if($opened == true)
{
$page .="</ul>\n";
}
return $page."\n";

}
$number=(isset($pocet) ? $pocet:15);
$title=((isset($titulky) and $titulky=='true') ? true:false);
$result=RSS_Display($url,$number,$title);

return $result;

}
postZaslat odpověď

Nebyly zaslány žádné odpovědi.