-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.inc
235 lines (195 loc) · 8.08 KB
/
functions.inc
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
include "config.inc";
$functions = 1;
function dbconnect() {
include "config.inc";
mysql_pconnect($dbhost, $dbuname, $dbpass);
@mysql_select_db("$dbname") or die ("Unable to select database");
}
function counter() {
dbconnect();
mysql_query("UPDATE vars SET value=value+1 where name='totalhits'");
}
function cookiedecode($user) {
global $cookie;
$user = base64_decode($user);
$cookie = explode(":", $user);
return $cookie;
}
function getusrinfo($user) {
global $userinfo;
$user2 = base64_decode($user);
dbconnect();
$user3 = explode(":", $user2);
$result = mysql_query("SELECT uid, name, uname, email, femail, url, pass, storynum, umode, uorder, thold, noscore, bio, ublockon, ublock, theme, signature FROM users WHERE uname = '$user3[1]' AND pass = '$user3[2]'");
if(mysql_num_rows($result)==1) {
$userinfo = mysql_fetch_array($result);
} else {
echo "<b>A problem occured</b><br>";
}
return $userinfo;
}
function FixQuotes ($what = "") {
$what = ereg_replace("'","''",$what);
while (eregi("\\\\'", $what)) {
$what = ereg_replace("\\\\'","'",$what);
}
return $what;
}
function check_html($message) {
## TODO
return $message;
}
function filter_text($message, $strip="") {
### TODO
return check_html($text, $strip);
}
function formatTimestamp($time) {
### Should be removed as soon as possible!
global $datetime;
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
$datetime = date("l, F d, Y - h:i A", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
return($datetime);
}
function addRefer($url) {
dbconnect();
$query = "SELECT * FROM refer WHERE url = '$url'";
$result = mysql_query($query);
if ($site = mysql_fetch_object($result)) {
if ($site->status) {
$site->refers++;
$query = "UPDATE refer SET refers = '$site->refers', access_dt = '". time() ."' WHERE url = '$url'";
$result = mysql_query($query);
}
}
else {
$query = "INSERT INTO refer (url, name, refers, create_dt, access_dt) VALUES ('$url', '', '1', '". time() ."', '". time() ."')";
$result = mysql_query($query);
}
}
function displayRelatedLinks($theme, $sid = 0) {
dbconnect();
$result = mysql_query("SELECT * FROM stories WHERE sid = $sid");
if ($story = mysql_fetch_object($result)) {
### parse story for A HREF-tags:
$text = "$story->abstract $story->comments $story->article";
while ($text = stristr($text, "<A HREF=")) {
$link = substr($text, 0, strpos($text, "</a>") + 4);
$text = stristr($text, "</A>");
if (!stristr($link, "mailto:")) $content .= "<LI>$link</LI>";
}
### default related links:
$content .= " <LI>More about <A HREF=\"search.php?category=$story->category\">$story->category</A>.</LI>";
$content .= " <LI>Also by <A HREF=\"search.php?author=$story->aid\">$story->aid</A>.</LI>";
$theme->box("Related links", $content);
}
}
function displayOldHeadlines($theme) {
global $user, $cookie;
if ($cookie[3]) $result = mysql_query("SELECT sid, subject, time FROM stories ORDER BY time DESC LIMIT $cookie[3], 10");
else $result = mysql_query("SELECT sid, subject, time FROM stories ORDER BY time DESC LIMIT 10, 10");
while ($story = mysql_fetch_object($result)) {
if ($time != date("F jS", $story->time)) {
$content .= "<P><B>". date("l, F jS", $story->time) ."</B></P>";
$time = date("F jS", $story->time);
}
if ($user) {
$content .= "<LI><A HREF=\"article.php?sid=$story->sid";
if (isset($cookie[4])) { $content .= "&mode=$cookie[4]"; } else { $content .= "&mode=threaded"; }
if (isset($cookie[5])) { $content .= "&order=$cookie[5]"; } else { $content .= "&order=0"; }
if (isset($cookie[6])) { $content .= "&thold=$cookie[6]"; } else { $content .= "&thold=0"; }
$content .= "\">$story->subject</A></LI>";
}
else {
$content .= "<LI><A HREF=\"article.php?sid=$story->sid&mode=threaded&order=1&thold=0\">$story->subject</A></LI>";
}
}
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Older headlines", $content);
}
function displayNewHeadlines($theme, $num = 10) {
global $user, $cookie;
dbconnect();
$content = "";
$result = mysql_query("SELECT sid, subject FROM stories ORDER BY time DESC LIMIT $num");
while(list($sid, $subject) = mysql_fetch_row($result)) {
if ($user) {
$content .= "<LI><A HREF=\"article.php?sid=$sid";
if (isset($cookie[4])) { $content .= "&mode=$cookie[4]"; } else { $content .= "&mode=threaded"; }
if (isset($cookie[5])) { $content .= "&order=$cookie[5]"; } else { $content .= "&order=0"; }
if (isset($cookie[6])) { $content .= "&thold=$cookie[6]"; } else { $content .= "&thold=0"; }
$content .= "\">$subject</A></LI>";
}
else {
$content .= "<LI><A HREF=\"article.php?sid=$sid&mode=threaded&order=1&thold=0\">$subject</A></LI>";
}
}
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Latest headlines", $content);
}
function displayAdminblock($theme) {
$result = mysql_query("SELECT title, content FROM blocks");
while (list($title, $content) = mysql_fetch_array($result)) {
$theme->box($title, nl2br($content));
}
}
function displayUserblock($theme) {
global $cookie;
dbconnect();
if ($cookie[8]) {
$block = mysql_query("SELECT ublock FROM users WHERE uid = '$cookie[0]'");
list($content) = mysql_fetch_row($block);
$content .= "<P ALIGN=\"right\">[ <A HREF=\"account.php?op=edithome\"><FONT COLOR=\"$theme->hlcolor2\">edit</FONT></A> | <A HREF=\"account.php?op=logout\"><FONT COLOR=\"$theme->hlcolor2\">logout</FONT></A> ]</P>";
$theme->box("$cookie[1]'s box", $content);
}
}
function displayAccount($theme) {
global $user, $cookie;
if ($user) {
### Display userblock if any:
displayUserblock();
}
else {
$content = "<CENTER><FORM METHOD=\"post\" ACTION=\"account.php\">\n <P>Username:<BR><INPUT TYPE=\"text\" NAME=\"uname\" MAXLENGTH=\"50\" SIZE=\"12\"></P>\n<P>Password:<BR> <INPUT TYPE=\"password\" NAME=\"pass\" MAXLENGTH=\"25\" SIZE=\"12\"></P>\n<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Login\">\n</FORM>\n<P><A HREF=\"account.php\">Register</A> as new user.<BR><A HREF=\"account.php\">Forgot</A> your password?</P></CENTER>";
$theme->box("Login", $content);
}
}
function displayAccountSettings($theme) {
global $user;
if ($user) {
### Display account settings:
$content = "<LI><A HREF=\"account.php\">User info</A></LI>";
$content .= "<LI><A HREF=\"account.php?op=edituser\">Edit user info</A></LI>";
$content .= "<LI><A HREF=\"account.php?op=edithome\">Customize homepage</A></LI>";
$content .= "<LI><A HREF=\"account.php?op=editcomm\">Customize comments</A></LI>";
$content .= "<LI><A HREF=\"account.php?op=logout\">Logout</A></LI>";
### Decode user cookie to extract name:
$cookie = cookiedecode($user);
$theme->box("$cookie[1]'s acount", "$content");
}
}
function displayReferrals($theme, $number = 10) {
$count = 1;
dbconnect();
if ($number) {
$query = "SELECT * FROM refer ORDER BY refers DESC LIMIT $number";
$result = mysql_query($query);
}
else {
$query = "SELECT * FROM refer ORDER BY refers DESC";
$result = mysql_query($query);
}
while (($site = mysql_fetch_object($result)) && ($count <= $number)) {
if ($site->name) $rval = "$count. <A HREF=\"$site->url\">$site->name</A> ($site->refers)<BR>";
else $rval = "$count. <A HREF=\"$site->url\">$site->url</A> ($site->refers)<BR>";
$count++;
}
$theme->box("Referring sites", "$rval <P ALIGN=\"right\">[ <A HREF=\"refer.php#refer-info\"><FONT COLOR=\"$theme->hlcolor2\">info</FONT></A> | <A HREF=\"refer.php#refer-more\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>");
}
function displayPoll($theme) {
global $answer, $answer1, $answer2, $answer3, $answer4, $answer5, $answer6, $id, $method, $section, $poll, $question;
// Pass the URI and FORM parameters along to poll.php.
$box = 1;
include "poll.php";
}
?>