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/genlinks.php

199 lines
4.6 KiB
PHP
Raw Normal View History

2023-04-30 21:28:42 +02:00
<?php
if (!$file) {
$file = "/www/website/modules/bookmarks.xml";
}
if (!$destfile) {
$destfile = "/www/website/tmp/pages/links.cache.php";
}
$depth = array();
$txt1 = array();
$txt2 = array();
$hs = -1;
$na = 0;
$nb = 0;
$open_tags = array(
'XBEL' => '<XBEL>',
'INFO' => '<INFO>',
'FOLDER' => '<FOLDER>',
'TITLE' => '<TITLE>',
'BOOKMARK' => '<BOOKMARK>',
'DESC' => '<DESC>'
);
$close_tags = array(
'XBEL' => '</XBEL>',
'INFO' => '</INFO>',
'FOLDER' => '</FOLDER>',
'TITLE' => '</TITLE>',
'BOOKMARK' => '</BOOKMARK>',
'DESC' => '</DESC>'
);
function startElement($parser, $name, $attrs) {
global $open_tags, $current_tag, $depth, $tb, $hs, $na, $txt1, $txt2;
$current_tag = $name;
$hs++;
switch($name) {
case 'XBEL':
break;
case 'FOLDER':
array_push($txt2, "<ul>\n");
if (end($depth) == 'XBEL') {
$li = sprintf("<a name='%s' />", $na++);
//array_push($txt2, $li);
}
break;
case 'BOOKMARK':
//array_push($txt2, "<ul>\n");
$tb['url'] = $attrs['HREF'];
break;
default:
break;
}
array_push($depth, $name);
}
function endElement($parser, $name) {
global $close_tags, $tb, $current_tag, $depth, $hs, $txt2;
switch($name) {
case 'XBEL':
break;
case 'FOLDER':
array_push($txt2, "</ul>\n");
break;
case 'BOOKMARK':
return_page($tb);
$tb = '';
break;
default:
break;
}
array_pop($depth);
$hs--;
}
function characterData($parser, $data) {
global $current_tag, $tb, $catID, $depth, $hs, $txt1, $txt2, $nb;
//$data = preg_replace('@&(.+?);@','{\\1}',htmlentities(utf8_decode($data)));
//$data = htmlentities(utf8_decode($data));
//print($data);
switch($current_tag) {
case 'BOOKMARK':
//if (isset($tb['bookmark']))
$tb['bookmark'] .= $data;
$current_tag = '';
break;
case 'TITLE':
$tpp = array_pop($depth);
if (end($depth) == 'FOLDER') {
if (trim($data) != '')
{
array_push($txt2, "<li><h$hs><a name='$data'>$data</a></h$hs></li>\n");
$tpp2 = array_pop($depth);
if (end($depth) == 'XBEL') {
$li = sprintf("<br /><a href=#%s>%s</a>", $nb++, $data);
array_push($txt1, $li);
}
array_push($depth, $tpp2);
}
} else {
//if (isset($tb['title']))
$tb['title'] .= $data;
$current_tag = '';
}
array_push($depth, $tpp);
break;
case 'DESC':
$tpp = array_pop($depth);
if (end($depth) == 'BOOKMARK') {
$tb['desc'] .= $data;
$current_tag = '';
}
array_push($depth, $tpp);
break;
case 'URL':
$tb['url'] .= $data;
$current_tag = '';
break;
default:
break;
}
}
function return_page() {
global $tb, $txt2;
if (isset($tb['title'])) {
$ll = sprintf(" <li><a href='%s' target='_blank'>%s</a></li>\n", $tb['url'], rtrim($tb['title']));
if (!stristr($tb['title'],"cannabi"))
array_push($txt2, $ll);
//$ll1 = sprintf(" - %s", $tb['desc']);
//array_push($txt2, $ll1);
}
}
$xml_parser = xml_parser_create($type);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
//xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'ISO-8859-1');
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
//$data = preg_replace('@&(.+?);@','{\\1}',htmlentities(utf8_decode($data)));
//print($data);
//$data = ereg_replace('&', '&amp;', $data);
$data = ereg_replace('é','{eacute}',$data);
$data = ereg_replace('ç','{ccedil}',$data);
$data = ereg_replace('è','{egrave}',$data);
$data = ereg_replace('É','E',$data);
$data = ereg_replace('â','{acirc}',$data);
$data = ereg_replace('','\'',$data);
$data = ereg_replace('ñ','{nieu}',$data);
$data = ereg_replace('ï','{iuml}',$data);
//$data = utf8_decode($data);
//echo $data;
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
reset($txt1);
reset($txt2);
$fp = fopen($destfile,"w");
fputs($fp, "\n<table><tr><td><img src='images/transparent.gif' alt='' class='icon_6' /></td><td><h1>Bookmarks</h1></td></tr></table>\n");
foreach ($txt2 as $t) {
$t=ereg_replace("{ccedil}","<EFBFBD>",$t);
$t=ereg_replace("{nieu}","<EFBFBD>",$t);
$t=ereg_replace("{acirc}","<EFBFBD>",$t);
$t=ereg_replace("{eacute}","<EFBFBD>",$t);
$t=ereg_replace("{egrave}","<EFBFBD>",$t);
$t=ereg_replace("{iuml}","<EFBFBD>",$t);
fputs($fp, $t);
}
fputs ($fp, "<div align=\"right\"><h6>(Updated ".date("M j Y").")</h6></div><br />");
//fputs ($fp, "<!-- generated on ".date("M j Y")." -->\n");
//fputs($fp,"<hr />\n");
fclose($fp);
?>