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/modules/bookmarks.php
2023-04-30 21:50:11 +02:00

254 lines
6.7 KiB
PHP

<?php
print_r(parse_rss("/web/website/modules/bookmarks.xml"));
//************************************************
//* renvoie les titres d'un fichier backend RSS **
//************************************************
function parse_rss($filename)
{
$root = "";
global $convert;
$trans["&amp;"] = "[ampersand]";
$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 = strtr(implode("",file($root.$filename)),$trans);
else
$data = implode("",file($root.$filename));
// 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, "UTF-8");
xml_parse_into_struct($p,$data,&$vals,&$index);
xml_parser_free($p);
echo $vals[3][type];
//print_r($vals);
// parcourt et récupère les données
foreach($index as $key->$val)
{
$array = $key->$val;
$pos = $array[0];
$tag = $vals[$pos][tag];
$val = $vals[$pos][value];
echo "tag=".$tag."<br />";
if ($tag == "FOLDER")
{
echo $vals[$pos][value][TYPE];
while ($index[BOOKMARK][$index_item] != "")
{
$tag2 = $vals[$index[BOOKMARK][$index_item]+1][tag];
echo "tag2=".$tag2."<br />";
$value2 = $vals[$index[BOOKMARK][$index_item]+1][value];
echo "value2=".$value2."<br />";
$index_item++;
if ($tag2 == "TITLE")
{
$items[$cpt]["title"] = $value2;
//echo "$value2";
}
if ($tag2 == "BOOKMARK")
{
$items[$cpt++]["bookmark"] = $value2;
//echo "$value2";
}
}
}
}
return $items;
}
//*************************************************
//* renvoie les données supplémentaires d'un site *
//* à partir d'un fichier backend RSS *
//*************************************************
function get_sitedata($filename)
{
$root = "/web/website/backends/xml/";
// extrait le nom du fichier
$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ère les donné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;
}
?>