<?php
global $VALTAGS;
$VALTAGS = array('title','author','link','description','pubDate','guid');
include_once('php/include/io.inc');
/* Yes. This file needs to be cleaned (and commented) up.
Also, all functions could do with error checking/handling...
*/
function unhtmlentities($string) {
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
function get_xml_entries($tag, $subtag, $filecontent, $endtag='')
{
$found = array();
if($endtag == '')
$endtag = $subtag;
preg_match_all("'<$tag>(.*?)</$tag>'si", $filecontent, $entries);
for($i = 0; $i < count($entries[1]); $i++)
{
if(preg_match_all("'<$subtag(\sisPermaLink=\".*?\")?>(.*?)</$endtag>'si", $entries[1][$i], $tmp_found))
$found[$i] = $tmp_found[2][0];
else
$found[$i] = 'null';
}
return $found;
}
/*
Sort items by 'pubDate'.
What we *should* do, of course, is cache this - so we don't
have to re-do it every page load (the same could be said for a lot
of functions).
*/
function sort_items($data_in, $lim)
{
global $VALTAGS;
$indices = array();
$data = $data_in;
$num_items = count($data['pubDate']);
for($j = 0; $j < $lim; $j++)
{
$newest = -1; $ncomp = 0;
for($i = 0; $i < $num_items; $i++)
{
if(!$j) $data['pubDate'][$i] = strtotime($data['pubDate'][$i]);
if(($newest < 0) || ($data['pubDate'][$i] > $ncomp))
{
$newest = $i;
$ncomp = $data['pubDate'][$newest];
}
}
$indices[$j] = $newest;
$data['pubDate'][$newest] = -1;
}
$data = $data_in;
for($i = 0; $i < $lim; $i++)
{
/* The bracket is a thing of beauty. */
for($j = 0; $j < count($VALTAGS); $j++)
$data_in[$VALTAGS[$j]][$i] = $data[$VALTAGS[$j]][$indices[$i]];
}
return $data_in;
}
function get_items($filename)
{
global $VALTAGS;
$parsed = array();
$filecontent = read_file($filename);
if($filecontent == '')
{
echo "Error opening/reading "$filename"!";
exit;
}
for($i = 0; $i < count($VALTAGS); $i++)
{
$parsed[$VALTAGS[$i]] = get_xml_entries('item', $VALTAGS[$i], $filecontent);
$parsed[$VALTAGS[$i]] = str_replace('&apos;',"'",$parsed[$VALTAGS[$i]]);
}
return $parsed;
}
function data_to_xml($data, $where)
{
global $VALTAGS;
$out = "\n\t\t<item>\n";
for($i = 0; $i < count($VALTAGS); $i++)
$out .= "\t\t\t<$VALTAGS[$i]>"
. ( ($where < 0) ? $data[$VALTAGS[$i]] : $data[$VALTAGS[$i]][$where] )
. "</$VALTAGS[$i]>\n";
$out .= "\t\t</item>\n";
return $out;
}
function prepare_data($data,$update_pd=1)
{
global $VALTAGS;
if($update_pd)
$data['pubDate'] = date('Y/m/d H:i:s');
for($i = 0; $i < count($VALTAGS); $i++)
$data[$VALTAGS[$i]] = htmlentities($data[$VALTAGS[$i]]);
return $data;
}
function get_relno($str)
{
if(preg_match("'.*?release_id=(\d+).*?'", $str, $found))
return $found[1];
else
return '';
}
function get_ID($data, $where)
{
if(get_relno($data['guid'][$where]) != '')
return $data['author'][$where] . '_' . get_relno($data['guid'][$where]);
$pd = $data['pubDate'][$where];
$pd = preg_replace("'\s'", '_', $pd);
$pd = preg_replace("':|/'", '', $pd);
return $data['author'][$where] . "_$pd";
}
function make_link($parsed)
{
for($i = 0; $i < count($parsed['guid']); $i++)
{
preg_match_all("'.*?(release_id=\d+).*?'", $parsed['guid'][$i], $found);
$parsed['link'][$i] = "http://sourceforge.net/project/showfiles.php?group_id=98284&". $found[1][0];
}
return $parsed;
}
function url_2_link($data, $where)
{
$desc = $data['description'][$where];
$desc = preg_replace("'\[+(.*?)\|(.*?)\]+'",
"<a href=\"\$1\" target=\"_blank\">\$2</a>", $desc);
$desc = preg_replace("'\[+(http://.*?)\]+'",
"<a href=\"\$1\" target=\"_blank\">\$1</a>",
$desc);
return $desc;
}
function data_2_html($data, $where, $template, $admin='')
{
global $VALTAGS;
$html = $template;
$data['description'][$where] = url_2_link($data, $where);
$data['description'][$where] = str_replace("\n", '<br />', $data['description'][$where]);
for($i = 0; $i < count($VALTAGS); $i++)
{
$html = unhtmlentities(str_replace("%$VALTAGS[$i]%", $data[$VALTAGS[$i]][$where], $html));
}
$html = str_replace('%ADMIN%', $admin, $html);
$html = str_replace('%ID%', get_ID($data, $where), $html);
return $html;
}
function id2pagenum($data, $id)
{
for($i = 0; $i < count($data['title']); $i++)
{
if($id == get_ID($data, $i))
return ((int)($i/10)*10);
}
return -1;
}
function modify($filename, $where, $mode, $data, $update_pd=1)
{
$out = '';
$parsed = get_items($filename);
if(!$fp = fopen($filename, 'w'))
{
echo "fopen($filename) failed!"; exit;
}
fwrite($fp, "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n\t<channel>\n");
fwrite($fp, "\t\t<title>AROS-stuff: $filename</title>\n");
fwrite($fp, "\t\t<link>http://aros-stuff.tk</link>\n");
fwrite($fp, "\t\t<generator>http://aros-stuff.sf.net/php/include/xml.inc</generator>\n");
$data = prepare_data($data, $update_pd);
for($i = 0; $i < count($parsed['title']); $i++)
{
$out = '';
if($i == $where)
{
if($mode == 'delete')
; // Do nothing
else if($mode == 'add')
$out .= data_to_xml($data, -1) . data_to_xml($parsed, $i);
else if($mode == 'modify')
$out .= data_to_xml($data, -1);
}
else
$out .= data_to_xml($parsed, $i);
fwrite($fp, $out);
}
if($mode == 'add' && $where == -1)
fwrite($fp, data_to_xml($data, -1));
fwrite($fp, "\n\t</channel>\n</rss>\n");
fclose($fp);
}
function small_parse($file, $lim, $sort=0)
{
$parsed = get_items("rss/$file.rss");
$tpl_data = read_file("templates/$file" . '_small.tmpl');
if($sort)
$parsed = sort_items($parsed, $lim);
for($i = 0; $i < count($parsed['title']) && $i < $lim; $i++)
echo data_2_html($parsed, $i, $tpl_data);
}
?>
Latest News
Latest Software
read 0.3.6
kal, 2004/04/30 07:14:24.
nroff 1.10
kal, 2004/04/22 08:29:10.
Nenscript 1.13.3
kal, 2004/04/22 08:23:53.
necho 0.2.3
kal, 2004/04/19 10:58:47.
dgrep 0.1.4
kal, 2004/04/19 10:49:42.
kal, 2004/04/30 07:14:24.
nroff 1.10
kal, 2004/04/22 08:29:10.
Nenscript 1.13.3
kal, 2004/04/22 08:23:53.
necho 0.2.3
kal, 2004/04/19 10:58:47.
dgrep 0.1.4
kal, 2004/04/19 10:49:42.
Select Theme
Links