n/oldblog
Archived
1
0
Fork 0
This repository has been archived on 2024-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
oldblog/include/rssparser.old.inc.php

278 lines
7.2 KiB
PHP
Raw Normal View History

2023-04-30 21:28:42 +02:00
<?php
//************************************************
//* renvoie les titres d'un fichier backend RSS **
//************************************************
function parse_rss($filename)
{
$root = "/web/website/backends/xml/";
global $convert;
$trans["&amp;"] = "[ampersand]";
$trans["& "] = "[ampersand]";
$trans["<EFBFBD>"] = "[agrave]";
$trans["<EFBFBD>"] = "[eacute]";
$trans["<EFBFBD>"] = "[egrave]";
$trans["<EFBFBD>"] = "[ecirc]";
$trans["<EFBFBD>"] = "[icirc]";
$trans["<EFBFBD>"] = "[ugrave]";
$trans["<EFBFBD>"] = "[ccedil]";
$trans[">"] = ">\n";
// php5 ne d<>tecte pas les encodages XML (bug??)
//$trans["iso-8859-15"] = "iso-8859-1";
//$trans["UTF-8"] = "iso-8859-1";
if (isset($convert) && $convert="on")
$data = utf8_decode(strtr(implode("",file($root.$filename)),$trans));
else
$data = implode("",file($root.$filename));
//$data = html_entity_decode($data);
// initialise les compteurs
$cpt = 0;
$index_item = 0;
// parse le fichier et remplit les tableaux
$p = xml_parser_create("");
xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, "iso-8859-1");
xml_parse_into_struct($p,$data,&$vals,&$index);
xml_parse_into_struct($p,$data,$vals,$index);
xml_parser_free($p);
// parcourt et r<>cup<75>re les donn<6E>es
foreach($index as $key->$val)
{
$array = $key->$val;
$pos = $array[0];
$tag = $vals[$pos][tag];
$val = $vals[$pos][value];
if ($tag == "ITEM")
{
while ($index[ITEM][$index_item] != "")
{
$tag2 = $vals[$index[ITEM][$index_item]+1][tag];
$value2 = $vals[$index[ITEM][$index_item]+1][value];
$index_item++;
if ($tag2 == "TITLE")
{
$items[$cpt]["title"] = $value2;
// echo "$value2";
}
if ($tag2 == "LINK")
$items[$cpt++]["link"] = $value2;
}
}
}
return $items;
}
function parse_rss2($filename)
{
$root = "/web/website/backends/xml/";
$xml = simplexml_load_file($root.$filename);
$cpt = 0;
foreach($xml->channel->item as $news)
{
$items[$cpt]["title"] = utf8_decode((string) $news->title);
$items[$cpt++]["link"] = $news->link;
//echo '<a href="'.$news->link.'">', utf8_decode((string) $news->title), '</a><br />';
}
return $items;
}
//*************************************************
//* renvoie les donn<6E>es suppl<70>mentaires d'un site *
//* <20> partir d'un fichier backend RSS *
//*************************************************
function get_sitedata($filename)
{
$root = "/web/website/backends/xml/";
// extrait le nom du fichier
if (file_exists($root.$filename))
$data = implode("",file($root.$filename));
// initialise les compteurs
$index_textinput = 0;
$sitedata["language"] = "";
/*********************** partie parser **********************/
// parse le fichier et remplit les tableaux
$p = xml_parser_create();
xml_parse_into_struct($p,$data,&$vals,&$index);
xml_parser_free($p);
// parcourt et r<>cup<75>re les donn<6E>es
foreach($index as $key->$val)
{
$array = $key->$val;
$pos = $array[0];
$tag = $vals[$pos][tag];
$val = htmlspecialchars($vals[$pos][value]);
if ($tag == "RSS")
{
$sitedata["rss_ver"] = $vals[$index[RSS][$pos]][attributes][VERSION];
}
else if ($tag == "TITLE")
{
$sitedata["title_site"] = utf8_decode($val);
$index_title++;
}
else if ($tag == "LINK")
{
$sitedata["link_site"] = $val;
$index_link++;
}
else if ($tag == "DESCRIPTION")
{
$sitedata["description"] = $val;
}
else if ($tag == "LANGUAGE")
{
$sitedata["language"] = $val;
}
else if ($tag == "IMAGE")
{
$sitedata["image_title"] = $vals[$index[TITLE][$index_title]][value];
$index_link++;
}
else if ($tag == "URL")
{
$sitedata["image_url"] = $val;
}
else if ($tag == "WIDTH")
{
$sitedata["image_width"] = $val;
}
else if ($tag == "HEIGHT")
{
$sitedata["image_height"] = $val;
}
else if ($tag == "TEXTINPUT")
{
while ($index[TEXTINPUT][$index_textinput] != "")
{
$tag2 = $vals[$index[TEXTINPUT][$index_textinput]+1][tag];
$value2 = $vals[$index[TEXTINPUT][$index_textinput]+1][value];
$index_textinput++;
if ($tag2 == "TITLE")
{
$sitedata["textinput_title"] = $value2;
}
else if ($tag2 == "DESCRIPTION")
{
$sitedata["textinput_description"] = $value2;
}
else if ($tag2 == "NAME")
{
$sitedata["textinput_name"] = $value2;
}
else if ($tag2 == "LINK")
{
$sitedata["textinput_link"] = $value2;
}
}
}
else
{}
}
return $sitedata;
}
//***********************************************
//* renvoie les titres d'un fichier backend TXT *
//***********************************************
//* forme la plus simple: *
//***********************************************
//* %% *
//* title *
//* link *
//* %% *
//***********************************************
function parse_text_1($filename)
{
$data = file($filename);
while($data[$index] != "")
{
if (!strchr("%",$data[$index]))
{
$items[$index]["title"] = $data[$index];
$items[$index]["link"] = $data[$index++];
}
else $index++;
}
return $items;
}
//**************************************
//* renvoie les titres d'une page HTML *
//**************************************
function parse_html($filename,$regs)
{
$index=$index_item=0;
$data = file($filename);
ereg($regs,$data[$index],$result);
while($data[$index++] != "")
{
ereg($regs,$data[$index],$result);
if ($result[1] != "")
{
if (strchr($result[1],"http://"))
$item[$index_item]["link"] = strtok(urldecode($result[1]),"\"");
else
$item[$index_item]["link"] = $url_site.strtok(urldecode($result[1]),"\"");
$result[1]="";
}
if ($result[2] != "")
{
$item[$index_item++]["title"] = html2ascii($result[2]);
$result[2] = "";
}
}
return $item;
}
function parse_html2($data,$regs)
{
$index=$index_item=0;
ereg($regs,$data[$index],$result);
while($data[$index++] != "")
{
ereg($regs,$data[$index],$result);
if ($result[1] != "")
{
$item[$index_item]["link"] = strtok(urldecode($result[1]),"\"");
$result[1]="";
}
if ($result[2] != "")
{
$item[$index_item++]["title"] = $result[2];
$result[2] = "";
}
}
return $item;
}
?>