php require_once config php require_once rss conf php mysql_connect db

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
require_once "../config.php";
require_once "rss.conf.php";
mysql_connect($db_host,$db_username,$db_password) or
die("Could not connect to DB server");
mysql_select_db($db_name) or
die("Could not select db");
mysql_query("SET NAMES '".str_replace('-','',$channelCharset)."'");
$data = <<<IDSTR
<?xml version="1.0" encoding="{$channelCharset}" ?>
<rss version="2.0">
<channel>
<title>{$channelTitle}</title>
<link>{$baseUrl}/</link>
<description>{$channelDescription}</description>
<language>{$channelLanguage}</language>
<copyright>{$channelCopyright}</copyright>
<pubDate>{$channelPubDate}</pubDate>
<generator>{$channelGenerator}</generator>
<ttl>{$channelTtl}</ttl>
#items#
</channel>
</rss>
IDSTR;
$item = '
<item>
<title>[#post_author] #forum_name#: #topic_name# </title>
<link>#base_url#/viewtopic.php?pid=#post_number##p#post_number#</link>
<description>#post_content#</description>
<comments>#base_url#/post.php?tid=#topic_number#&amp;qid=#post_number#</comments>
<guid isPermaLink="true">#base_url#/viewtopic.php?pid=#post_number##p#post_number#</guid>
<pubDate>#post_time#</pubDate>
</item>
';
function do_query($condition_sql, $limit, $order) {
global $db_prefix;
$result = mysql_query("
SELECT
p.id AS post_number,
p.message AS post_content,
p.posted AS post_time,
p.poster AS post_author,
t.subject AS topic_name,
t.id AS topic_number,
f.forum_name AS forum_name
FROM {$db_prefix}posts p
LEFT JOIN {$db_prefix}topics t ON t.id = p.topic_id
LEFT JOIN {$db_prefix}forums f ON f.id = t.forum_id
LEFT JOIN {$db_prefix}forum_perms fp ON fp.forum_id = f.id AND fp.group_id = 3
WHERE
( fp.read_forum = 1 OR fp.read_forum IS NULL ) AND t.moved_to IS NULL {$condition_sql}
ORDER BY p.posted {$order}
LIMIT {$limit}
") or die("Mysql error: ".mysql_error());
$posts = array();
while($row = mysql_fetch_assoc($result)) {
$posts[] = $row;
}
return $posts;
}
if ( isset($_GET['fids']) and strlen($_GET['fids']) ) {
$fids = explode(",",@$_GET['fids']);
$fids = array_map("intval",$fids);
}
$posts = array();
$sql = "";
if ( sizeof($fids) ) {
$sql = " AND f.id IN (".implode(",",$fids).")";
}
if ( ! isset($_GET['onlytopics']) ) {
$posts = do_query($sql, $channelSize, 'DESC');
} else {
$result = mysql_query("
SELECT t.id
FROM {$db_prefix}topics t
LEFT JOIN {$db_prefix}forums f ON f.id = t.forum_id
LEFT JOIN {$db_prefix}forum_perms fp ON fp.forum_id = f.id AND fp.group_id = 3
WHERE
( fp.read_forum = 1 OR fp.read_forum IS NULL ) AND t.moved_to IS NULL {$sql}
ORDER BY t.posted DESC
LIMIT {$channelSize}
") or die("mysql error: ".mysql_error());
$tids = array();
while($row = mysql_fetch_assoc($result)) {
$tids[] = $row['id'];
}
foreach($tids as $_ => $tid) {
$sql = " AND t.id = ".$tid;
$local_posts = do_query($sql, 1, 'ASC');
$post = $local_posts[0];
$posts[] = $post;
}
}
$item_data = "";
foreach( $posts as $_ => $iter ) {
$tail = ( $itemDescriptionLength < strlen($iter['post_content']) ) ? "..." : "";
if ('utf-8' == strtolower($channelCharset)) {
mb_internal_encoding('utf-8');
$c = mb_substr($iter['post_content'],0,$itemDescriptionLength).$tail;
} else {
$c = substr($iter['post_content'],0,$itemDescriptionLength).$tail;
}
$c = preg_replace('{(\[quote[^\[]*\])}si',"\n".'\1',$c);
$c = preg_replace('{\[/quote\]}si',"[/quote]\n",$c);
$c = nl2br($c);
$iter['post_content'] = $c;
$iter = array_map("htmlspecialchars",$iter);
$iter['post_content'] = "[ ".$iter['post_author']." ] ".$iter['post_content'];
$iter['post_time'] = gmdate('r',$iter['post_time']);
$item_data = $item_data.
str_replace(
array(
'#post_author',
'#post_time#','#topic_number#','#post_content#',
'#post_number#','#forum_name#','#topic_name#',
'#base_url#'),
array(
$iter['post_author'],
$iter['post_time'],$iter['topic_number'],$iter['post_content'],
$iter['post_number'],$iter['forum_name'],$iter['topic_name'],
$baseUrl),
$item
);
}
$data = str_replace('#items#',$item_data,$data);
header("Content-Type: application/rss+xml; charset={$channelCharset}");
print $data;
?>