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

199 lines
4.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
if (file_exists("tmp/pages/links.cache.php") && $_SERVER["SERVER_SOFTWARE"] != "")
include "tmp/pages/links.cache.php";
else
{
?>
<table><tr><td><img src='images/transparent.gif' alt='' class='icon_6' /></td><td><h1>Bookmarks</h1></td></tr></table>
<?php
if (!$file) {
$file = "/web/website/modules/bookmarks.xml";
}
$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':
$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 {
$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 ($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('É','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);
/*foreach ($txt1 as $t) {
print $t;
}*/
reset($txt2);
foreach ($txt2 as $t) {
$t=ereg_replace("{ccedil}","<22>",$t);
$t=ereg_replace("{nieu}","<22>",$t);
$t=ereg_replace("{acirc}","<22>",$t);
$t=ereg_replace("{eacute}","<22>",$t);
$t=ereg_replace("{iuml}","<22>",$t);
print $t;
}
}
?>
<hr />