summaryrefslogtreecommitdiff
path: root/functions.inc
blob: 340191345c951bfcc9d0c2153c66fda61d2190df (plain)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?
include "user.class.php";
include "database.inc";
include "log.inc";

session_start();

include "config.inc";
$functions = 1;

function id2story($id) {
  ### Perform query:
  $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id");
  return db_fetch_object($result);
}

function dbsave($dbase, $data, $id=0) {
  foreach ($data as $key=>$value) {
    if ($key == "passwd") { $query .= "$key=PASSWORD('". addslashes($value) ."'), "; }
    else { $query .= "$key='". addslashes($value) ."', "; }
  }
  $query = substr($query, 0, -2);
  
  if (!empty($id)) { db_query("UPDATE $dbase SET $query WHERE id=$id") or die(mysql_error()); return $id; }
  else { db_query("INSERT INTO $dbase SET $query") or die(mysql_error()); return mysql_insert_id(); }
}

function morelink_bytes($theme, $story) {
  global $user;

  ### Compose more-link:
  $morelink = "[ ";
  if ($story->article) {
    $morelink .= "<A HREF=\"discussion.php?id=$story->id";
    $morelink .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded";
    $morelink .= ($user->uorder) ? "&order=$user->uorder" : "&order=0";
    $morelink .= ($user->thold) ? "&thold=$user->thold" : "&thold=0";
    $morelink .= "\"><FONT COLOR=\"$theme->hlcolor2\"><B>read more</B></FONT></A> | $bytes bytes in body | "; 
  }
  $morelink .= "<A HREF=\"discussion.php?id=$story->id";
  $morelink .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded";
  $morelink .= ($user->uorder) ? "&order=$user->uorder" : "&order=0";
  $morelink .= ($user->thold) ? "&thold=$user->thold" : "&thold=0";
  $morelink .= "\"><FONT COLOR=\"$theme->hlcolor2\">$story->comments comments</FONT></A> ]";

  return $morelink;
}

function morelink_words($theme, $story) {
  // todo
}

function morelink_lines($theme, $story) {
  // todo
}

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) {
  $query = "SELECT * FROM refer WHERE url = '$url'";
  $result = db_query($query);

  if ($site = db_fetch_object($result)) {
    if ($site->status) {
      $site->refers++;
      $query = "UPDATE refer SET refers = '$site->refers', access_dt = '". time() ."' WHERE url = '$url'";
      $result = db_query($query);
    }
  }
  else {
    $query = "INSERT INTO refer (url, name, refers, create_dt, access_dt) VALUES ('$url', '', '1', '". time() ."', '". time() ."')";
    $result = db_query($query);
  }
}

function displayModerationResults($theme, $story) {
  global $user;

  if ($user->id && $story->id && $vote = $user->getHistory("s$story->id")) {
    $output .= "<P><B>You voted `$vote'.</B></P>\n";
    $output .= "<P>\n";
    $output .= "<B>Other people voted:</B><BR>\n";

    $result = db_query("SELECT * FROM users WHERE history LIKE '%s$story->id%'");
    while ($account = db_fetch_object($result)) {
      $output .= "<A HREF=\"account.php?op=info&uname=$account->userid\">$account->userid</A> voted `". getHistory($account->history, "s$story->id") ."'.<BR>";
    }
    
    $theme->box("Moderation results", $output);
  }
}

function displayRelatedLinks($theme, $story) {
  ### Parse story for <A HREF="">-tags:
  $text = stripslashes("$story->abstract $story->updates $story->article");
  while ($text = stristr($text, "<A HREF=")) {
    $link = substr($text, 0, strpos(strtolower($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=". urlencode($story->category) ."\">$story->category</A>.</LI>";
  $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>";

  $theme->box("Related links", $content);
}

function displayOldHeadlines($theme, $num = 10) {
  global $user;
  
  if ($user->storynum) $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $user->storynum, $num");
  else $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $num, $num");

  while ($story = db_fetch_object($result)) {    
    if ($time != date("F jS", $story->timestamp)) {
      $content .= "<P><B>". date("l, F jS", $story->timestamp) ."</B></P>";
      $time = date("F jS", $story->timestamp);
    }

    if ($user->userid) {
      $content .= "<LI><A HREF=\"discussion.php?id=$story->id";
      $content .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded";
      $content .= ($user->uorder) ? "&order=$user->uorder" : "&order=0";
      $content .= ($user->thold) ? "&thold=$user->thold" : "&thold=0";
      $content .= "\">$story->subject</A></LI>";
    }
    else {
      $content .= "<LI><A HREF=\"discussion.php?id=$story->id&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;

  $content = "";
  $result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num");
  while ($story = db_fetch_object($result)) {    
    if ($user->userid) {
      $content .= "<LI><A HREF=\"discussion.php?id=$story->id";
      $content .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded";
      $content .= ($user->uorder) ? "&order=$user->uorder" : "&order=0";
      $content .= ($user->thold) ? "&thold=$user->thold" : "&thold=0";
      $content .= "\">$story->subject</A></LI>";
    }
    else {
      $content .= "<LI><A HREF=\"discussion.php?id=$story->id&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("Latest headlines", $content);
}

function displayAdminblock($theme) {
  $result = db_query("SELECT title, content FROM blocks");
  while (list($title, $content) = mysql_fetch_array($result)) {
    $theme->box($title, nl2br($content));
  }
}

function displayUserblock($theme) {
  global $user;

  if ($user && $user->ublockon) {
    $content .= "<P ALIGN=\"right\">[ <A HREF=\"account.php?op=edithome\"><FONT COLOR=\"$theme->hlcolor2\">edit</FONT></A> | <A HREF=\"account.php?op=discussion\"><FONT COLOR=\"$theme->hlcolor2\">Track comments</FONT></A> | <A HREF=\"account.php?op=logout\"><FONT COLOR=\"$theme->hlcolor2\">logout</FONT></A>]</P>";
    $theme->box("$user->userid's box", $user->content);
  }
}

function displayLogin($theme) {
  global $user;
  
  if ($user && $user->userid) { 
    ### Display userblock if any:
    displayUserblock();
  }
  else {
    $content  = "<CENTER><FORM METHOD=\"post\" ACTION=\"account.php\">\n";
    $content .= "<P>Username:<BR><INPUT NAME=userid MAXLENGTH=50 SIZE=12></P>\n";
    $content .= "<P>Password:<BR> <INPUT TYPE=password NAME=passwd MAXLENGTH=25 SIZE=12></P>\n";
    $content .= "<INPUT TYPE=submit NAME=op VALUE=\"Login\">\n";
    $content .= "</FORM>\n";
    $content .= "<P><A HREF=\"account.php?op=new\">Register</A> as new user.<BR><A HREF=\"account.php?op=forgot\">Forgot</A> your password?</P></CENTER>";
    $theme->box("Login", $content);
  }
}

function displayCalendar($theme, $date) {
  include "calendar.class.php";
  $calendar = new calendar($date);
  $theme->box("Browse archives", $calendar->display());
}

function displayAccount($theme) {
  global $user;
  
  if ($user && $user->userid) { 

    function submission_number() {
      $result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
      return ($result) ? mysql_result($result, 0) : 0;
    }

    ### Display account settings:
    $content  = "<LI><A HREF=\"account.php\">view your information</A></LI>";
    $content .= "<LI><A HREF=\"account.php?op=user\">edit your information</A></LI>";
    $content .= "<LI><A HREF=\"account.php?op=page\">customize your page</A></LI>";
    $content .= "<LI><A HREF=\"account.php?op=discussion\">track your comments</A></LI>";
    $content .= "<LI><A HREF=\"submission.php\">moderate submissions</A> (<FONT COLOR=\"red\">". submission_number() ."</FONT>)</LI>";
    $content .= "<LI><A HREF=\"account.php?op=logout\">logout</A></LI>";

    $theme->box("$user->userid's account", "$content");
  }
}

function displayReferrals($theme, $number = 10) {
  $count = 1;

  if ($number) {
    $query = "SELECT * FROM refer ORDER BY refers DESC LIMIT $number";
    $result = db_query($query);
  }
  else {
    $query = "SELECT * FROM refer ORDER BY refers DESC";
    $result = db_query($query);
  }
  
  while (($site = db_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";
}
?>