Import of recovered 0.7a

This commit is contained in:
Mike Barnes 2025-02-10 10:17:03 +11:00
commit 5d5f103a26
26 changed files with 1516 additions and 0 deletions

110
minclude/config.inc Normal file
View file

@ -0,0 +1,110 @@
<?php
// This stuff all relates to reading and parsing the configuration files.
// A lot of the code is HIDEOUS - but it does work. It needs a cleanup.
function get_config($page) {
$xml_parser = make_xml_parser("ConfigcharacterData", "ConfigstartElement",
"ConfigendElement");
if (!($fp = fopen("dong.conf", 'r'))) {
die("Could not open config file for parsing!\n");
}
// loop through the file and parse baby!
while ($data = fread($fp, 4096)) {
if (!($data = utf8_encode($data))) {
echo 'ERROR'."\n";
}
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
}
function ConfigstartElement($parser, $name, $attrs=''){
global $config_open_tags, $current_tag, $isfirst, $gotnamed, $isdefault,
$page, $isnamed, $config, $storeflag, $public, $publicflag;
$current_tag = $name;
switch($name){
case 'WEBLOG':
if ($attrs[PUBLIC]) {
$publicflag=1;
$public[TEMPNAME]=$attrs[NAME];
}
if (!$isfirst && !$gotnamed) {
$config[NAME]=$attrs[NAME];
$storeflag=1;
$isfirst=1;
}
if ($attrs[MAIN]=="true" && !$gotnamed) {
$config[NAME]=$attrs[NAME];
$storeflag=1;
}
if ($attrs[NAME] == $page) {
$isnamed=1;
$storeflag=1;
$config[NAME]=$attrs[NAME];
}
break;
default:
break;
}
}
function ConfigendElement($parser, $name, $attrs=''){
global $confg_close_tags, $isdefault, $gotnamed, $isnamed, $storeflag, $publicflag;
switch($name){
case 'WEBLOG':
$isdefault = 0;
if($isnamed == 1) {
$isnamed = 0;
$gotnamed = 1;
}
$storeflag=0;
$publicflag=0;
break;
default:
break;
}
}
function ConfigcharacterData($parser, $data) {
global $current_tag, $storeflag, $config, $public, $publicflag;
$data=chop($data);
if ($storeflag && $data) {
$config[$current_tag]=$data;
}
if ($publicflag && ($current_tag == "URL") && $data) {
if (preg_match("/\?/",$data)) {
$switchchar="&";
}
else {
$switchchar="?";
}
$public[$public[TEMPNAME]]=$data.$switchchar."mode=rss";
}
}
?>

105
minclude/misc.inc Normal file
View file

@ -0,0 +1,105 @@
<?php
// Code for parsing the config XML file
// Some global and non-user-servicable variables that really don't need to
// clutter up the index file.
$config_open_tags = array(
'WEBLOG' => '<WEBLOG>',
'SITETITLE' => '<SITETITLE>',
'DESCRIPTION' => '<DESCRIPTION>',
'ARTICLELIMIT' => '<ARTICLELIMIT>',
'RDFARTICLELIMIT' => '<RDFARTICLELIMIT>',
'URL' => '<URL>',
'EMAIL' => '<EMAIL>');
$config_close_tags = array(
'WEBLOG' => '</WEBLOG>',
'SITETITLE' => '</SITETITLE>',
'DESCRIPTION' => '</DESCRIPTION>',
'ARTICLELIMIT' => '</ARTICLELIMIT>',
'RDFARTICLELIMIT' => '</RDFARTICLELIMIT>',
'URL' => '</URL>',
'EMAIL' => '</EMAIL>');
$open_tags = array(
'CHANNEL' => '<CHANNEL>',
'ITEM' => '<ITEM>',
'TITLE' => '<TITLE>',
'LINK' => '<LINK>');
$close_tags = array(
'CHANNEL' => '</CHANNEL>',
'ITEM' => '</ITEM>',
'TITLE' => '</TITLE>',
'LINK' => '</LINK>');
function make_xml_parser($character, $startelement, $endelement) {
$xml_parser = xml_parser_create("UTF-8");
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_character_data_handler($xml_parser, $character);
xml_set_element_handler($xml_parser, $startelement, $endelement);
return $xml_parser;
}
function get_articlelist($offset, $limit) {
// Get list of all available articles
global $articledir, $showentry, $totalarticles;
$handle=opendir("$articledir");
// Skip reading the directory if we're displaying a permalink
if ($showentry) {
$articlelist[0]=$showentry;
return $articlelist;
}
// Stock $articlelist with every available article
$index=0;
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
$articlelist[$index] = "$file";
$index++;
}
}
// Set the total now
$totalarticles = sizeof($articlelist);
// Sort the article list to highest number (most recent) first
rsort ($articlelist);
// Avoid overflows if we don't have a lot of articles, or make sure
// every article is displayed if the limit is 0
if ((sizeof($articlelist) < $limit) || ($limit == 0)) {
$limit = sizeof($articlelist) - $offset;
}
for ($count=0;$count<$limit;$count++) {
$newlist[$count]=$articlelist[$count+$offset];
}
return $newlist;
}
function append_to_url($url, $option) {
if (preg_match("/\?/",$url)) {
$switchchar="&";
}
else {
$switchchar="?";
}
$url = $url.$switchchar.$option;
return $url;
}
?>

61
minclude/rss-export.inc Normal file
View file

@ -0,0 +1,61 @@
<?php
function rssexport() {
global $articledir, $config, $switchchar;
print"<?"; ?>xml version="1.0"?>
<rss version="0.92">
<channel>
<?php
echo"
<title>$config[SITETITLE]</title>
<link>$config[URL]</link>
<description>$config[DESCRIPTION]</description>
<language>$config[LANGUAGE]</language>
<webmaster>$config[EMAIL]</webmaster>
";
$articlelist=get_articlelist(0, $config[RDFARTICLELIMIT]);
// Avoid overflows if we don't have a lot of articles
if (sizeof($articlelist) < $config[RDFARTICLELIMIT]) {
$config[RDFARTICLELIMIT] = sizeof($articlelist);
}
// Main content loop starts here
for ($index=0;$index < $config[RDFARTICLELIMIT];$index++) {
$bodytext="";
$workfile="$articledir/$articlelist[$index]";
$articlefile=fopen ($workfile, "r");
$headline = chop(fgets($articlefile, 300));
// Throw away the first blank line ...
$toss = chop(fgets($articlefile, 300));
while (!feof ($articlefile)) {
$oneline = chop(fgets($articlefile, 300));
$oneline = preg_replace("|##(.*)#(.*)##|U", "\\1", $oneline);
if (preg_match("|^%%|", $oneline)) {
$oneline = preg_replace("|%%(.*)%%|U", "&lt;image: \\1&gt;", $oneline);
}
if (!$oneline) { // Only export the first paragraph
break;
}
$oneline = $oneline." ";
$bodytext = $bodytext.$oneline;
$bodytext = strip_tags("$bodytext");
$link=$config[URL].$switchchar."showentry=".$articlelist[$index];
}
print "\t<item>\n";
print "\t\t<title>$headline</title>\n";
print "\t\t<description>$bodytext</description>\n";
print "\t\t<link><![CDATA[$link]]></link>\n";
print "\t</item>\n\n";
fclose ($articlefile);
} // Main content loop ends
print "</channel>\n</rss>";
}
?>

111
minclude/rss-import.inc Normal file
View file

@ -0,0 +1,111 @@
<?php
// Stuff for RDF parsing - based on code originally from
// http://www.phpbuilder.com/columns/joe20000907.php3
function startElement($parser, $name, $attrs=''){
global $open_tags, $current_tag, $initem, $index;
$current_tag = $name;
switch($name){
case 'ITEM':
$initem=1;
break;
default:
break;
}
}
function endElement($parser, $name, $attrs=''){
global $close_tags, $current_tag, $initem, $index;
switch($name){
case 'ITEM':
$index++;
$initem = 0;
break;
default:
break;
}
}
function characterData($parser, $data) {
global $current_tag, $initem, $links, $titles, $channelurl, $channeltitle, $index;
switch($current_tag){
case 'TITLE':
if (!$initem && chop($data) != "") {
$channeltitle = $data;
}
else {
$titles[$index] = $data;
}
$current_tag = '';
break;
case 'LINK':
if ($initem) {
$links[$index] = $data;
}
else {
$channelurl = $data;
}
$current_tag = '';
break;
default:
break;
}
}
function grab_headlines($xml_file) {
global $index, $channeltitle, $channelurl, $links, $titles;
$index=0;
$xml_parser = make_xml_parser("characterData", "startElement","endElement");
//$xml_parser = xml_parser_create("UTF-8");
//xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
//xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
//if (!xml_set_element_handler($xml_parser, 'startElement','endElement')){
// die("Failed to set element handler!\n");
// }
//xml_set_character_data_handler($xml_parser, 'characterData');
if (!($fp = fopen($xml_file, 'r'))) {
die("Could not open $xml_file for parsing!\n");
}
// loop through the file and parse baby!
while ($data = fread($fp, 4096)) {
if (!($data = utf8_encode($data))) {
echo 'ERROR'."\n";
}
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
//if (sizeof($titles) > $limit
//Output the title of the Channel ($channelname, $channelurl)
print"<p class=\"menusubhead\"><a href=\"$channelurl\">$channeltitle</a></p>\n";
//Output the links ($links[x], $titles[x])
for ($count=0;$count<$index;$count++) {
if ($links[$count] == "" || $links[$count] == "\n") {
$links[$count] = $channelurl;
}
print"<p class=\"menuoption\"><a href=\"$links[$count]\" class=\"linkurl\">$titles[$count]</a>\n";
}
xml_parser_free($xml_parser);
}
?>