Subversion Repositories SvarDOS

Rev

Rev 1223 | Rev 1230 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1223 mateusz.vi 1
<?php
2
//
3
// mateuszbb - minimalistic bulletinboard-like forum
4
// Copyright (C) 2021-2023 Mateusz Viste
5
//
6
 
7
global $TRIP_SALT;
8
global $INITYEAR;
9
global $DATADIR;
10
global $NICE_URLS;
11
global $STR;
12
global $LANG;
13
 
14
include 'mateuszbb-config.php';
15
 
16
 
17
// *** TRANSLATION STRINGS *****************************************
18
 
19
$STR = array();
20
$STR['en']['opnewthread'] = 'open a new thread';
21
$STR['en']['newthread']   = 'New thread';
22
$STR['en']['latestentry'] = 'latest entry:';
23
$STR['en']['searchterm']  = 'searched term:';
24
$STR['en']['noresults']   = 'No results';
25
$STR['en']['reply']       = 'reply';
26
$STR['en']['jumptoend']   = 'jump to end';
27
$STR['en']['listthreads'] = 'list of threads';
28
$STR['en']['author']      = 'author:';
29
$STR['en']['address']     = 'address:';
30
$STR['en']['date']        = 'date:';
31
$STR['en']['nameornick']  = 'your name or nick';
32
$STR['en']['threadsubj']  = 'subject';
33
$STR['en']['yourmsg']     = 'Your message';
34
$STR['en']['cancel']      = 'cancel';
35
$STR['en']['send']        = 'send';
36
$STR['en']['archives']    = 'archives';
37
$STR['en']['backtocur']   = 'go back to current threads';
38
$STR['en']['search']      = 'search';
39
$STR['en']['password']    = 'password';
40
$STR['en']['optional']    = 'optional';
41
$STR['en']['passhelp']    = 'Providing a password here will generate a unique digital signature on your message.';
42
$STR['en']['captcha'][1]  = 'check the FIRST box';
43
$STR['en']['captcha'][2]  = 'check the MIDDLE box';
44
$STR['en']['captcha'][3]  = 'check the LAST box';
45
$STR['en']['captcha'][4]  = 'check the FIRST and LAST boxes';
46
$STR['en']['captcha'][5]  = 'check the TWO LAST boxes';
47
 
48
$STR['pl']['opnewthread'] = 'stwórz nowy wątek';
49
$STR['pl']['newthread']   = 'Nowy wątek';
50
$STR['pl']['latestentry'] = 'ostatni wpis:';
51
$STR['pl']['searchterm']  = 'szukane wyrażenie:';
52
$STR['pl']['noresults']   = 'Brak wyników';
53
$STR['pl']['reply']       = 'odpowiedz';
54
$STR['pl']['jumptoend']   = 'skocz do końca';
55
$STR['pl']['listthreads'] = 'lista wątków';
56
$STR['pl']['author']      = 'autor:';
57
$STR['pl']['address']     = 'adres:';
58
$STR['pl']['date']        = 'data:';
59
$STR['pl']['nameornick']  = 'imię, nazwisko lub pseudonim';
60
$STR['pl']['threadsubj']  = 'tytuł wątku';
61
$STR['pl']['yourmsg']     = 'Twoja wiadomość';
62
$STR['pl']['cancel']      = 'anuluj';
63
$STR['pl']['send']        = 'wyślij';
64
$STR['pl']['archives']    = 'archiwum';
65
$STR['pl']['backtocur']   = 'powrót do bieżących wątków';
66
$STR['pl']['search']      = 'szukaj';
67
$STR['pl']['password']    = 'hasło';
68
$STR['pl']['optional']    = 'opcjonale';
69
$STR['pl']['passhelp']    = 'Podanie hasła pozwoli wygenerować unikalny podpis elektroniczny przy twojej wiadomości.';
70
$STR['pl']['captcha'][1]  = 'zaznacz PIERWSZE pole';
71
$STR['pl']['captcha'][2]  = 'zaznacz ŚRODKOWE pole';
72
$STR['pl']['captcha'][3]  = 'zaznacz OSTATNIE pole';
73
$STR['pl']['captcha'][4]  = 'zaznacz PIERWSZE i OSTATNIE pole';
74
$STR['pl']['captcha'][5]  = 'zaznacz DWA OSTATNIE pola';
75
 
76
// *****************************************************************
77
 
78
 
79
function data_dluga($timestamp) {
80
  date_default_timezone_set('UTC');
81
  return(date('d.m.Y, H:i:s', $timestamp) . ' UTC');
82
}
83
 
84
 
85
// returns an array with the list of languages requested by the browser, in
86
// the order of preference
87
function getpreflang() {
88
  $res = array();
89
  if (! isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) return($res);
90
  $langlist = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
91
  foreach ($langlist as $lang) {
92
    $res[] = strtolower(substr($lang, 0, 2));
93
  }
94
  return(array_unique($res));
95
}
96
 
97
 
98
function mateuszbb_rss() {
99
  global $DATADIR;
1229 mateusz.vi 100
  global $RSS_TITLE;
101
 
1223 mateusz.vi 102
  $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3', SQLITE3_OPEN_READONLY);
103
  if (! $db) {
104
    echo "SQL ERROR: ACCESS DENIED\n";
105
    return false;
106
  }
107
  $sqlres = $db->query('SELECT thread, msgid, author FROM rss ORDER BY msgid DESC, thread DESC LIMIT 100;');
108
  if (! $sqlres) {
109
    echo "SQL ERROR: QUERY FAILED\n";
110
    return false;
111
  }
112
 
113
  header('content-type: application/rss+xml');
114
 
115
  echo '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
116
  echo '<rss version="2.0">' . "\n";
117
  echo "<channel>\n";
1229 mateusz.vi 118
  echo "<title>" . htmlspecialchars($RSS_TITLE, ENT_XML1) . "</title>\n";
119
  echo "<link>" . selfurl(). "</link>\n";
1223 mateusz.vi 120
 
121
  while ($row = $sqlres->fetchArray()) {
122
    $rawtitle = file_get_contents($DATADIR . 'threads/' . $row['thread'] . '/title.txt');
123
    if (empty($rawtitle)) continue;
124
    $title = htmlspecialchars($rawtitle, ENT_XML1, 'UTF-8');
125
    $author = htmlspecialchars($row['author'], ENT_XML1, 'UTF-8');
1229 mateusz.vi 126
    if ($NICE_URLS) {
127
      $link = selfurl();
128
      if (substr($link, -1) !== '/') $link .= '/';
129
      $link .= "{$row['thread']}";
130
    } else {
131
      $link = selfurl('thread=' . $row['thread']);
132
    }
133
    $link .= '#' . $row['msgid'];
1223 mateusz.vi 134
    echo "<item>\n";
1229 mateusz.vi 135
    echo "<title>{$author} @ '{$title}'</title>\n";
136
    echo "<link>" . htmlspecialchars($link, ENT_XML1) . "</link>\n";
137
    echo "<description>{$author} @ '{$title}'</description>\n";
1223 mateusz.vi 138
    echo "<pubDate>" . date('r', $row['msgid']) . "</pubDate>\n";
1229 mateusz.vi 139
    echo "<guid>" . htmlspecialchars($link, ENT_XML1) . "</guid>\n";
1223 mateusz.vi 140
    echo "</item>\n";
141
  }
142
  $db->close();
143
 
144
  echo "</channel>\n";
145
  echo "</rss>\n";
146
  return true;
147
}
148
 
149
 
150
function formularz($thread = '') {
151
  global $STR;
152
  global $LANG;
153
 
154
  if (empty($thread)) {
155
    echo '<form class="minibb" method="POST" action="' . selfurl() . '#title" id="formularz">' . "\n";
156
    echo '<input type="hidden" name="action" value="createthread">' . "\n";
157
  } else {
158
    echo '<form class="minibb" method="POST" action="' . selfurl() . '" id="formularz">' . "\n";
159
    echo '<input type="hidden" name="action" value="newpost">' . "\n";
160
    echo '<input type="hidden" name="thread" value="' . $thread . '">' . "\n";
161
  }
162
 
163
  echo '<div class="minibb-formfields">' . "\n";
164
  echo '<div class="minibb-formlabelgroup"><p>' . $STR[$LANG]['nameornick'] . '</p><input type="text" name="login" pattern=".*[^\s].*" minlength="1" maxlength="40" title="' . $STR[$LANG]['nameornick'] . '" required></div><div class="minibb-formlabelgroup"><p>' . $STR[$LANG]['password'] . ' (<span title="' . $STR[$LANG]['passhelp'] . '" style="text-decoration-line: underline; text-decoration-style: dotted;">' . $STR[$LANG]['optional'] . '</span>)</p><input type="password" name="pass" maxlength="40"></div>' . "\n";
165
  if (empty($thread)) {
166
    echo '<div class="minibb-formlabelgroup" style="width: 100%;">' . "\n";
167
    echo "<p>" . $STR[$LANG]['threadsubj'] . "</p>\n";
168
    echo '<input type="text" name="title" title="' . $STR[$LANG]['threadsubj'] . '" maxlength="64" pattern=".*[^\s].*" required>' . "\n";
169
    echo "</div>\n";
170
  }
171
  echo '<textarea name="msg" placeholder="' . $STR[$LANG]['yourmsg'] . '">' . "\n";
172
  echo '</textarea><br>' . "\n";
173
  echo '</div>' . "\n";
174
  // --- CAPTCHA ---
175
  $capid = rand(1, 5);
176
  echo '<div class="minibb-formcaptcha">' . $STR[$LANG]['captcha'][$capid] . ': <input type="checkbox" name=c1> <input type="checkbox" name=c2> <input type="checkbox" name=c3>' . "\n";
177
  echo '<input type="hidden" name="capid" value="' . $capid . '">';
178
  // ---------------
179
  echo '<div class="minibb-formbtns">';
180
  echo '<a href="' . selfurl() . '">' . $STR[$LANG]['cancel'] . '</a> <input type="submit" value="' . $STR[$LANG]['send'] . '">' . "\n";
181
  echo '</div>';
182
  echo '</form>';
183
}
184
 
185
function wyswietl_watek_w_liscie($threadid, $tytul, $lastauthor, $lastupdate) {
186
  global $NICE_URLS;
187
  global $STR;
188
  global $LANG;
189
 
190
  echo '<a href="';
191
  if (!$NICE_URLS) {
192
    echo selfurl("thread=$threadid");
193
  } else {
194
    echo $threadid;
195
  }
196
  echo '" class="minibb-threaditem">' . "\n";
197
  echo '<h2>' . htmlspecialchars($tytul) . "</h2>\n";
198
  echo '<p>' . $STR[$LANG]['latestentry'] . ' ' . htmlspecialchars($lastauthor) . ', ' . htmlspecialchars(data_dluga($lastupdate)) . "</p>\n";
199
  echo "</a>\n";
200
}
201
 
202
function sprawdz_captcha($CAPARR) {
203
  //echo "<!-- capid={$CAPARR['capid']} c1={$CAPARR['c1']} c2={$CAPARR['c2']} c3={$CAPARR['c3']}-->\n";
204
  switch ($CAPARR['capid']) {
205
    case 1:
206
      if (($CAPARR['c1']) && (!$CAPARR['c2']) && (!$CAPARR['c3'])) return(true);
207
      break;
208
    case 2:
209
      if ((!$CAPARR['c1']) && ($CAPARR['c2']) && (!$CAPARR['c3'])) return(true);
210
      break;
211
    case 3:
212
      if ((!$CAPARR['c1']) && (!$CAPARR['c2']) && ($CAPARR['c3'])) return(true);
213
      break;
214
    case 4:
215
      if (($CAPARR['c1']) && (!$CAPARR['c2']) && ($CAPARR['c3'])) return(true);
216
      break;
217
    case 5:
218
      if ((!$CAPARR['c1']) && ($CAPARR['c2']) && ($CAPARR['c3'])) return(true);
219
      break;
220
  }
221
  return(false);
222
}
223
 
224
 
225
// zwraca akcję na podstawie globalnych POST lub GET
226
function getvar_action() {
227
  if (!empty($_POST['action'])) return $_POST['action'];
228
  if (!empty($_GET['action'])) return $_GET['action'];
229
  return('');
230
}
231
 
232
function getvar_thread() {
233
  if (!empty($_POST['thread'])) return intval($_POST['thread']);
234
  if (!empty($_GET['thread'])) return intval($_GET['thread']);
235
  return(-1);
236
}
237
 
238
function getvar_archiveyear() {
239
  if (!empty($_POST['arch'])) return intval($_POST['arch']);
240
  if (!empty($_GET['arch'])) return intval($_GET['arch']);
241
  return(-1);
242
}
243
 
244
 
245
// funkcja która zapisuje nowe wiadomości
246
function mateuszbb_preprocess() {
247
global $TRIP_SALT;
248
global $DATADIR;
249
global $NICE_URLS;
250
global $ERRSTR; // zmienna zawierająca komunikat błędu (jeśli jakiś wystąpił)
251
global $STR;
252
global $LANG;
253
 
254
$action = getvar_action();
255
$thread = getvar_thread();
256
$archiveyear = getvar_archiveyear();
257
 
258
// negotiate language
259
$LANG = 'en'; // preselect english as default language
260
foreach (getpreflang() as $l) {
261
  if (!empty($STR[$l])) {
262
    $LANG = $l;
263
    break;
264
  }
265
}
266
 
267
// write access: check how many messages the user posted during last 24h
268
if (($action === 'createthread') || ($action === 'newpost')) {
269
   $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3');
270
   if ($db) {
271
     $db->exec('DELETE FROM ip_msg_counters24h WHERE msgid < strftime(\'%s\', \'now\') - 24*3600;');
272
     $count24h = intval($db->querySingle("SELECT count(*) FROM ip_msg_counters24h WHERE ipaddr = '{$_SERVER['REMOTE_ADDR']}'"));
273
     $db->close();
274
     if ($count24h >= 10) {
275
       $ERRSTR = "BŁĄD: Z TWOJEGO ADRESU NAPISANO JUŻ {$count24h} WIADOMOŚCI W PRZECIĄGU OSTATNICH 24H. SPRÓBUJ PONOWNIE ZA JAKIŚ CZAS.";
276
       $action = '';
277
     }
278
   }
279
}
280
 
281
// new thread creation (+switch to read thread)
282
if ($action === 'createthread') {
283
  // captcha check
284
  if (!sprawdz_captcha($_POST)) {
285
    echo "<p>BŁĄD: NIEPRAWIDŁOWE CAPTCHA</p>\n";
286
    goto DONE;
287
  }
288
  //
289
  $thread = time();
290
  if (empty($_POST['login']) || (empty($_POST['msg'])) || (empty($_POST['title']))) {
291
    echo '<p>BŁĄD: pusty nick, wiadomość lub tytuł</p>' . "\n";
292
    goto DONE;
293
  }
294
  if (!mkdir($DATADIR . 'threads/' . $thread, 0755, true)) {
295
    echo '<p>BŁĄD: nie zdołano utworzyć wątku nr ' . $thread . "</p>\n";
296
    goto DONE;
297
  }
298
  // zapisz tytuł
299
  file_put_contents($DATADIR . 'threads/' . $thread . '/title.txt', trim($_POST['title']));
300
  // ustaw co trzeba żeby zapisać wiadomość
301
  $action = 'newpost';
302
}
303
 
304
// nowy post do istniejącego wątku
305
if (($action === 'newpost') && ($thread >= 0) && (!empty($_POST['msg'])) && (!empty($_POST['login']))) {
306
  $postid = time();
307
  if (!sprawdz_captcha($_POST)) {
308
    $ERRSTR = "BŁĄD: NIEPRAWIDŁOWE CAPTCHA";
309
    goto DONE;
310
  }
311
  // nadpisz lastauthor i lastupdate
312
  $lastupdate = array('lastupdate' => $postid, 'lastauthor' => trim($_POST['login']));
313
  file_put_contents($DATADIR . 'threads/' . $thread . '/lastupdate', serialize($lastupdate));
314
  // oblicz tripkod, jeśli hasło zostało ustawione
315
  $tripsig = '';
316
  if (!empty(trim($_POST['pass']))) {
317
    $tripsig = hash('whirlpool', trim($_POST['login']) . '#' . trim($_POST['pass']) . $TRIP_SALT);
318
  }
319
  // zapisz wiadomość
320
  $msg = array('author' => trim($_POST['login']), 'ip' => $_SERVER['REMOTE_ADDR'], 'trip' => $tripsig, 'msg' => trim($_POST['msg']));
321
  file_put_contents($DATADIR . 'threads/' . $thread . '/' . $postid, serialize($msg));
322
  // zaktualizuj metadane dot. ostatniego wpisu, ostatniego autora i ilości wpisów dla tego IP w ciągu ostatniej godziny
323
  $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3');
324
  if ($db) {
325
    $db->exec('CREATE TABLE IF NOT EXISTS newest (thread INTEGER PRIMARY KEY, lastupdate INTEGER NOT NULL, lastauthor TEXT NOT NULL);');
326
    $db->exec('CREATE INDEX IF NOT EXISTS lastupdated ON newest (lastupdate);');
327
    $db->exec('CREATE TABLE IF NOT EXISTS ip_msg_counters24h (threadid INTEGER NOT NULL, msgid INTEGER NOT NULL, ipaddr TEXT NOT NULL);');
328
    $db->exec('CREATE TABLE IF NOT EXISTS rss (thread INTEGER NOT NULL, msgid INTEGER NOT NULL, author TEXT NOT NULL);');
329
    $db->exec('CREATE INDEX IF NOT EXISTS rss_msgid ON rss (msgid);');
330
    $login_escaped = $db->escapeString(trim($_POST['login']));
331
    $db->exec("INSERT OR REPLACE INTO newest (thread, lastupdate, lastauthor) VALUES ({$thread}, {$postid}, '{$login_escaped}');");
332
    $db->exec("INSERT INTO rss (thread, msgid, author) VALUES ({$thread}, {$postid}, '{$login_escaped}');");
333
    $db->exec("INSERT INTO ip_msg_counters24h (threadid, msgid, ipaddr) VALUES ({$thread}, {$postid}, '{$_SERVER['REMOTE_ADDR']}');");
334
    $db->close();
335
  } else {
336
    echo "SQL ERROR WHILE WRITING STATS\n";
337
  }
338
  // przekieruj
339
  if ($NICE_URLS) {
340
    $newurl = "{$thread}#{$postid}";
341
  } else {
342
    $newurl = selfurl("thread={$thread}") . "#{$postid}";
343
  }
344
  header("Location: {$newurl}");
345
  echo "<html><head></head><body><a href=\"{$newurl}\">KLIKNIJ TUTAJ</a></body></html>\n";
346
  exit();
347
}
348
 
349
DONE:
350
 
351
}
352
 
353
 
354
function mateuszbb_tytulwatku($id) {
355
  global $DATADIR;
356
  return file_get_contents($DATADIR . 'threads/' . $id . '/title.txt');
357
}
358
 
359
 
360
// wyświetlanie UI itd
361
function mateuszbb_start() {
362
global $TRIP_SALT;
363
global $ERRSTR;
364
global $DATADIR;
365
global $INITYEAR;
366
global $LANG;
367
global $STR;
368
global $NICE_URLS;
369
global $SEARCH_API_URL;
370
 
371
// read global variables
372
$action = getvar_action();
373
$thread = getvar_thread();
374
$archiveyear = getvar_archiveyear();
375
 
376
// wyświetl błąd, jeśli jakiś wystąpił w mateuszbb_preprocess()
377
if (!empty($ERRSTR)) {
378
  echo "<p class=\"minibb-errstr\">{$ERRSTR}</p>\n";
379
  $action = '';
380
  echo '<p><a href="./">Wróć do głównej strony</a></p>' . "\n";
381
  goto DONE;
382
}
383
 
384
// szukanie
385
if (isset($_POST['szukaj']) && (!empty(trim($_POST['szukaj'])))) {
386
  $q = trim($_POST['szukaj']);
387
  $query = $SEARCH_API_URL . urlencode($q);
388
  echo '<p>' . $STR[$LANG]['searchterm'] . ' ' . htmlentities($q) . '</p>';
389
  $results = file_get_contents($query);
390
  $resarr = json_decode($results, true)['items'];
391
 
392
  $licznik = 0;
393
  foreach ($resarr as $r) {
394
    if (mb_substr($r['link'], -1) === '/') continue;
395
    echo '<a href=' . $r['link'] . ' class="minibb-searchresult">';
396
    echo "<div><h1>{$r['title']}</h1><p>{$r['htmlSnippet']}</p></div></a>\n";
397
    $licznik++;
398
  }
399
 
400
  if ($licznik == 0) echo "<p>" . $STR[$LANG]['noresults'] . "</p>\n";
401
 
402
  goto DONE;
403
}
404
 
405
// new thread form
406
if ($action === 'newthread') {
407
  echo '<h2 class="minibb-threadtitle">' . $STR[$LANG]['newthread'] . '</h2>' . "\n";
408
  formularz();
409
  goto DONE;
410
}
411
 
412
// zobacz listę wątków
413
if ((empty($action)) && ($thread < 0) && ($archiveyear <= 0)) {
414
  echo '<div class="minibb-toolbar" style="justify-content: space-between;">';
415
  echo '<form action="' . selfurl() . '" method="POST"><input type="text" name="szukaj" placeholder="' . $STR[$LANG]['search'] . '"></form>';
416
  echo '<a href="' . selfurl('action=newthread') . '#formularz">' . $STR[$LANG]['opnewthread'] . '</a>';
417
  echo "</div>\n";
418
  $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3', SQLITE3_OPEN_READONLY);
419
  if ($db) {
420
    $sqlres = $db->query('SELECT thread, lastupdate, lastauthor FROM newest ORDER BY lastupdate DESC LIMIT 30;');
421
    if (!$sqlres) {
422
      echo "SQL ERROR\n";
423
    } else {
424
      while ($row = $sqlres->fetchArray()) {
425
        $title = mateuszbb_tytulwatku($row['thread']);
426
        if (empty($title)) {
427
          echo "<!-- BŁĄD: nie zdołano załadować wątku nr {$row['thread']} -->\n";
428
          continue;
429
        }
430
        wyswietl_watek_w_liscie($row['thread'], $title, $row['lastauthor'], $row['lastupdate']);
431
      }
432
    }
433
    $db->close();
434
  } else {
435
    echo "<p>BŁĄD DOSTĘPU DO BAZY DANYCH</p>";
436
  }
437
 
438
  echo '<div style="display: flex; justify-content: space-between; font-size: 0.9em; opacity: 0.8; margin: 0.6em 0.5em 0 0.5em;">' . "\n";
439
  echo '<div>' . $STR[$LANG]['archives'] . ':';
440
  for ($y = $INITYEAR; $y <= intval(gmdate('Y')); $y++) {
441
    if ($NICE_URLS) {
442
      echo " <a href=\"{$y}\">{$y}</a>";
443
    } else {
444
      echo ' <a href="' . selfurl("arch={$y}") . '">' . $y . '</a>';
445
    }
446
  }
447
  echo "</div>\n";
448
  echo '<a href="rss.php"><img style="height: 1em;" src="mateuszbb_rss.svg"></a>' . "\n";
449
  echo "</div>\n";
450
 
451
  // display the main page footer if any is defined
452
  if (file_exists('mateuszforum-mainfooter.htm')) {
453
    readfile('mateuszbb-mainfooter.htm');
454
  }
455
 
456
  goto DONE;
457
}
458
 
459
// wyświetl archiwum
460
if ($archiveyear > 0) {
461
  echo '<div class="minibb-toolbar" id="title"><a href="' . selfurl() . '">' . $STR[$LANG]['backtocur'] . '</a></div>' . "\n";
462
  echo "<h1>" . $STR[$LANG]['archives'] . " {$archiveyear}</h1>\n";
463
  $threads = scandir($DATADIR . 'threads/', SCANDIR_SORT_ASCENDING);
464
  foreach ($threads as $t) {
465
    if (!preg_match('/^[0-9][0-9]*$/', $t)) continue; // skip anything that is not a thread id
466
    if (intval(gmdate('Y', $t)) != $archiveyear) continue; // skip threads out of the targeted year
467
    $title = file_get_contents($DATADIR . 'threads/' . $t . '/title.txt');
468
    $link = $t;
469
    if (! $NICE_URLS) $link = selfurl("thread={$t}");
470
    echo '<span style="font-family: monospace;">[' . gmdate("Y-m-d", $t) . "]</span> <a href=\"{$link}\">{$title}</a><br>\n";
471
  }
472
  goto DONE;
473
}
474
 
475
// zobacz wątek
476
if ((empty($action)) && ($thread >= 0)) {
477
  // załaduj listę postów (i zapamiętaj ostatnią pozycję)
478
  $listapostow = scandir($DATADIR . 'threads/' . $thread . '/');
479
  // usuń pozycje które nie są żadnym msgid (np. title.txt) i zapamiętaj ostatni msgid
480
  $posty = array();
481
  foreach ($listapostow as $p) {
482
    if (!preg_match('/^[0-9][0-9]*$/', $p)) continue; // skip anything that is not a messageid
483
    $posty[] = $p;
484
    $ostatnipost = $p;
485
  }
486
  // toolbar (ostatni wątek / odpowiedz / powrót do forum)
487
  echo '<div class="minibb-toolbar" id="title">';
488
  echo '<a href="#' . $ostatnipost . '">' . $STR[$LANG]['jumptoend'] . '</a> <a href="#formularz">' . $STR[$LANG]['reply'] . '</a> <a href="' . selfurl() . '">' . $STR[$LANG]['listthreads'] . '</a></div>' . "\n";
489
  // wyświetl tytuł wątku
490
  echo '<h2 class="minibb-threadtitle">' . htmlspecialchars(file_get_contents($DATADIR . 'threads/' . $thread . '/title.txt')) . "</h2>\n";
491
  // wyświetl listę wątków
492
  foreach ($posty as $p) {
493
    $msg = unserialize(file_get_contents($DATADIR . 'threads/' . $thread . '/' . $p));
494
    echo '<div class="minibb-post" id="' . $p . '">' . "\n";
495
    echo '<div class="minibb-postheader"><a href="#' . $p . '" style="text-decoration: inherit; color: inherit;"><div class="minibb-postauthor">' . "\n";
496
    echo $STR[$LANG]['author'] . ' ' . htmlspecialchars($msg['author']) . "<br>\n";
497
    echo $STR[$LANG]['address'] . ' ' . htmlspecialchars($msg['ip']) . "<br>\n";
498
    echo $STR[$LANG]['date'] . ' ' . htmlspecialchars(data_dluga($p)) . "</div></a>\n";
499
    if (!empty($msg['trip'])) {
500
      echo '<div class="minibb-trip">';
501
      echo chunk_split($msg['trip'], 16, "\n");
502
      echo "</div>\n";
503
    }
504
    echo "</div>\n";
505
 
506
    // symbole html
507
    $bodyprocessed = htmlspecialchars($msg['msg']);
508
 
509
    // dodaj podgląd pod linki do obrazków, ale tylko jeśli link jest sam w linijce
510
    $bodyprocessed = preg_replace('~^(http[s]?://[^<>[:space:]]+[[:alnum:]/]\.(jpg|png))($|[\r\n])~m', "$1\n<img src=\"$1\">\n", $bodyprocessed);
511
 
512
    // olinkuj linki
513
    $bodyprocessed = preg_replace("~([^\"]|^)(http[s]?://[^<>[:space:]]+[[:alnum:]/])~", "$1<a href=\"$2\">$2</a>", $bodyprocessed);
514
 
515
    // oflaguj cytaty (linijki zaczynające się od ">")
516
    $bodyprocessed = preg_replace('/^(&gt; .*)[\r]?\n/m', '<blockquote>$1</blockquote>', $bodyprocessed);
517
 
518
    echo '<div class="minibb-postbody">' . $bodyprocessed . '</div>' . "\n";
519
    echo "</div>\n";
520
  }
521
  // formularz odpowiedzi i do domu
522
  formularz($thread);
523
  goto DONE;
524
}
525
 
526
DONE:
527
}
528
?>