-
Notifications
You must be signed in to change notification settings - Fork 1
/
xml.php
82 lines (69 loc) · 3.03 KB
/
xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
//XML FEED PAGE
//header("Content-type: text/xml charset=utf8");
require_once("./includes/upb.initialize.php");
require_once('./includes/class/posts.class.php');
$xml = "<?xml version=\"1.0\"?>";
$xml .= "<rss version=\"2.0\"><channel>";
if (!isset($_GET["id"]) || !ctype_digit($_GET["id"])) die("Invalid Forum ID");
//if (!isset($_GET["t_id"]) || !ctype_digit($_GET["t_id"])) die("Invalid Topic ID");
$fRec = $tdb->get("forums", $_GET["id"]);
//if ((int)$_COOKIE["power_env"] < $fRec[0]["view"]) die("You do not have enough Power to view this topic");
$posts_tdb = new posts(DB_DIR."/", "posts.tdb");
$posts_tdb->setFp("topics", $_GET['id']."_topics");
$posts_tdb->setFp("posts", $_GET["id"]);
$posts_tdb->set_forum($fRec);
if (!isset($_GET['t_id'])) {
$tRecs = $posts_tdb->listRec('topics', 1, -1);
$xml .= "<title>".xml_clean($fRec[0]['forum'])."</title>
<link>".xml_clean($_SERVER['HTTP_REFERER'])."</link>
<description>".xml_clean($fRec[0]['des'])."</description>
<language>en-us</language>";
$posts_tdb->set_topic($tRecs);
foreach ($tRecs as $key => $tRec) {
$first_comma = strpos($tRec['p_ids'], ',');
if($first_comma === false) $first_comma = strlen($tRec['p_ids']);
$first_post_id = substr($tRec['p_ids'], 0, $first_comma);
$post = $posts_tdb->get('posts', $first_post_id);
if($post === false)
$post = array('message'=>array('Unavailable'));
$url= "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$replace = "viewtopic.php?id=".$_GET['id']."&t_id=".$tRec['id'];
$newurl = str_replace('xml.php',$replace,$url);
$xml .= "<item>
<title>".xml_clean($tRec['subject'])."</title>
<link>".xml_clean($newurl)."</link>
<description>".xml_clean(format_text(filterLanguage($post[0]['message'])))."</description>
<guid isPermaLink=\"false\">".xml_clean($url)."</guid>
</item>";
}
$xml .= "</channel></rss>";
} else {
$tRecs = $posts_tdb->get("topics", $_GET["t_id"]);
$desc = $tRecs[0]['subject'];
$posts_tdb->set_topic($tRecs);
$pRecs = $posts_tdb->getPosts("posts");
$url= "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$replace = "viewtopic.php?id=".$_GET['id']."&t_id=".$_GET['t_id'];
$newurl = str_replace('xml.php',$replace,$url);
$xml .= "<title>".xml_clean($desc)."</title>
<link>".xml_clean($_SERVER['HTTP_REFERER'])."</link>
<description>Topic of ".xml_clean($desc)."</description>
<language>en-us</language>";
foreach ($pRecs as $key => $pRec) {
$newurl = str_replace('xml.php',$replace,$url);
$newurl .= '&page='.$pRec['page']."#".$pRec['id'];
$xml .= "<item>
<title>Post by ".xml_clean($pRec['user_name'])." on ".xml_clean(gmdate("M d, Y @ g:i:s a", user_date($pRec["date"])))."</title>
<link>".xml_clean($newurl)."</link>
<description>".xml_clean(format_text(filterLanguage($pRec['message'])))."</description>
<guid isPermaLink=\"false\">".xml_clean($url)."</guid>
</item>";
}
$xml .= "</channel></rss>";
}
if(!headers_sent()) {
header("Content-type:application/rss+xml;charset=utf-8");
echo $xml;
}
?>