minimalist-dong/minclude/misc.inc

105 lines
2.6 KiB
PHP

<?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;
}
?>