1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
<?php
error_reporting(E_ALL ^ E_NOTICE);
function render_news($feed_url, $showdetail, $headlinestyle, $detailstyle) {
global $show_detail, $headline_style, $detail_style, $max, $count, $insideitem, $insideimage;
$insideitem=false;
$insideimage=false;
$count = 0;
$show_detail = $showdetail;
$headline_style = $headlinestyle;
$detail_style = $detailstyle;
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = @fopen($feed_url,"r");
// or die("Error reading RSS data.");
if ($fp) {
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
} else {
echo '<span class="'. $detail_style .'">Syndicated content not available</span>';
}
// Free up memory used by the XML parser
xml_parser_free($xml_parser);
}
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title,/**/ $pubDate, $description, $link, $image, $insideimage;
if ($insideitem || $insideimage) {
$tag = $name;
}
if ($name == "ITEM" ) {
$insideitem = true;
}
if ($name == "IMAGE") {
$insideimage = true;
}
}
function endElement($parser, $name) {
global $insideitem, $tag, $title, /**/$pubDate, $description, $link, $image, $insideimage, $show_detail, $headline_style, $detail_style, $count, $max;
if ($name == "URL")
{
$insideimage=false;
$image="";
} else if ($name == "ITEM" && $count < $max) {
$count++;
printf('<a href="%s" class="lien_actu"'. $headline_style .' target="_blank"><b>%s</b></a><br>',trim($link),trim($title),/***/trim($pubDate));
if ($show_detail)
printf('<span class="texte">'. $detail_style .'%s</span><br>',trim($description));
else {
printf('<span class="texte">'. $detail_style .'%s</span><br>',trim($description));
echo "<br>";
}
$title = "";
/*******/$pubDate = "";
$description = "";
$link = "";
$insideitem = false;
} else if ($count >= $max) {
$title = "";
/*******/$pubDate = "";
$description = "";
$link = "";
$insideitem = false;
}
}
function characterData($parser, $data) {
global $insideitem, $tag, $title, /*******/$pubDate, $description, $link, $image, $insideimage;
if ($insideimage) {
switch ($tag) {
case "URL":
$image .= $data;
break;
}
}
if ($insideitem ) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
/**************/
case "PUBLICATION":
$pubDate .= $data;
break;
/************/
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
if (!is_string($link)) $link="";
$link .= $data;
break;
}
}
}
?> |
Partager