Subversion Repositories SvarDOS

Rev

Rev 1229 | Go to most recent revision | Details | 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;
100
  $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3', SQLITE3_OPEN_READONLY);
101
  if (! $db) {
102
    echo "SQL ERROR: ACCESS DENIED\n";
103
    return false;
104
  }
105
  $sqlres = $db->query('SELECT thread, msgid, author FROM rss ORDER BY msgid DESC, thread DESC LIMIT 100;');
106
  if (! $sqlres) {
107
    echo "SQL ERROR: QUERY FAILED\n";
108
    return false;
109
  }
110
 
111
  header('content-type: application/rss+xml');
112
 
113
  echo '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
114
  echo '<rss version="2.0">' . "\n";
115
  echo "<channel>\n";
116
  echo "<title>Forum Ul Warré</title>\n";
117
  echo "<link>https://ulwarre.pl/forum/</link>\n";
118
  echo "<description>Forum na temat ula ojca Warré</description>\n";
119
 
120
  while ($row = $sqlres->fetchArray()) {
121
    $rawtitle = file_get_contents($DATADIR . 'threads/' . $row['thread'] . '/title.txt');
122
    if (empty($rawtitle)) continue;
123
    $title = htmlspecialchars($rawtitle, ENT_XML1, 'UTF-8');
124
    $author = htmlspecialchars($row['author'], ENT_XML1, 'UTF-8');
125
    $link = "https://ulwarre.pl/forum/{$row['thread']}#{$row['msgid']}";
126
    echo "<item>\n";
127
    echo "<title>{$author} napisał(a) wiadomość w wątku '{$title}'</title>\n";
128
    echo "<link>{$link}</link>\n";
129
    echo "<description>{$author} napisał(a) wiadomość w wątku '{$title}'</description>\n";
130
    echo "<pubDate>" . date('r', $row['msgid']) . "</pubDate>\n";
131
    echo "<guid>{$link}</guid>\n";
132
    echo "</item>\n";
133
  }
134
  $db->close();
135
 
136
  echo "</channel>\n";
137
  echo "</rss>\n";
138
  return true;
139
}
140
 
141
 
142
function formularz($thread = '') {
143
  global $STR;
144
  global $LANG;
145
 
146
  if (empty($thread)) {
147
    echo '<form class="minibb" method="POST" action="' . selfurl() . '#title" id="formularz">' . "\n";
148
    echo '<input type="hidden" name="action" value="createthread">' . "\n";
149
  } else {
150
    echo '<form class="minibb" method="POST" action="' . selfurl() . '" id="formularz">' . "\n";
151
    echo '<input type="hidden" name="action" value="newpost">' . "\n";
152
    echo '<input type="hidden" name="thread" value="' . $thread . '">' . "\n";
153
  }
154
 
155
  echo '<div class="minibb-formfields">' . "\n";
156
  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";
157
  if (empty($thread)) {
158
    echo '<div class="minibb-formlabelgroup" style="width: 100%;">' . "\n";
159
    echo "<p>" . $STR[$LANG]['threadsubj'] . "</p>\n";
160
    echo '<input type="text" name="title" title="' . $STR[$LANG]['threadsubj'] . '" maxlength="64" pattern=".*[^\s].*" required>' . "\n";
161
    echo "</div>\n";
162
  }
163
  echo '<textarea name="msg" placeholder="' . $STR[$LANG]['yourmsg'] . '">' . "\n";
164
  echo '</textarea><br>' . "\n";
165
  echo '</div>' . "\n";
166
  // --- CAPTCHA ---
167
  $capid = rand(1, 5);
168
  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";
169
  echo '<input type="hidden" name="capid" value="' . $capid . '">';
170
  // ---------------
171
  echo '<div class="minibb-formbtns">';
172
  echo '<a href="' . selfurl() . '">' . $STR[$LANG]['cancel'] . '</a> <input type="submit" value="' . $STR[$LANG]['send'] . '">' . "\n";
173
  echo '</div>';
174
  echo '</form>';
175
}
176
 
177
function wyswietl_watek_w_liscie($threadid, $tytul, $lastauthor, $lastupdate) {
178
  global $NICE_URLS;
179
  global $STR;
180
  global $LANG;
181
 
182
  echo '<a href="';
183
  if (!$NICE_URLS) {
184
    echo selfurl("thread=$threadid");
185
  } else {
186
    echo $threadid;
187
  }
188
  echo '" class="minibb-threaditem">' . "\n";
189
  echo '<h2>' . htmlspecialchars($tytul) . "</h2>\n";
190
  echo '<p>' . $STR[$LANG]['latestentry'] . ' ' . htmlspecialchars($lastauthor) . ', ' . htmlspecialchars(data_dluga($lastupdate)) . "</p>\n";
191
  echo "</a>\n";
192
}
193
 
194
function sprawdz_captcha($CAPARR) {
195
  //echo "<!-- capid={$CAPARR['capid']} c1={$CAPARR['c1']} c2={$CAPARR['c2']} c3={$CAPARR['c3']}-->\n";
196
  switch ($CAPARR['capid']) {
197
    case 1:
198
      if (($CAPARR['c1']) && (!$CAPARR['c2']) && (!$CAPARR['c3'])) return(true);
199
      break;
200
    case 2:
201
      if ((!$CAPARR['c1']) && ($CAPARR['c2']) && (!$CAPARR['c3'])) return(true);
202
      break;
203
    case 3:
204
      if ((!$CAPARR['c1']) && (!$CAPARR['c2']) && ($CAPARR['c3'])) return(true);
205
      break;
206
    case 4:
207
      if (($CAPARR['c1']) && (!$CAPARR['c2']) && ($CAPARR['c3'])) return(true);
208
      break;
209
    case 5:
210
      if ((!$CAPARR['c1']) && ($CAPARR['c2']) && ($CAPARR['c3'])) return(true);
211
      break;
212
  }
213
  return(false);
214
}
215
 
216
 
217
// zwraca akcję na podstawie globalnych POST lub GET
218
function getvar_action() {
219
  if (!empty($_POST['action'])) return $_POST['action'];
220
  if (!empty($_GET['action'])) return $_GET['action'];
221
  return('');
222
}
223
 
224
function getvar_thread() {
225
  if (!empty($_POST['thread'])) return intval($_POST['thread']);
226
  if (!empty($_GET['thread'])) return intval($_GET['thread']);
227
  return(-1);
228
}
229
 
230
function getvar_archiveyear() {
231
  if (!empty($_POST['arch'])) return intval($_POST['arch']);
232
  if (!empty($_GET['arch'])) return intval($_GET['arch']);
233
  return(-1);
234
}
235
 
236
 
237
// funkcja która zapisuje nowe wiadomości
238
function mateuszbb_preprocess() {
239
global $TRIP_SALT;
240
global $DATADIR;
241
global $NICE_URLS;
242
global $ERRSTR; // zmienna zawierająca komunikat błędu (jeśli jakiś wystąpił)
243
global $STR;
244
global $LANG;
245
 
246
$action = getvar_action();
247
$thread = getvar_thread();
248
$archiveyear = getvar_archiveyear();
249
 
250
// negotiate language
251
$LANG = 'en'; // preselect english as default language
252
foreach (getpreflang() as $l) {
253
  if (!empty($STR[$l])) {
254
    $LANG = $l;
255
    break;
256
  }
257
}
258
 
259
// write access: check how many messages the user posted during last 24h
260
if (($action === 'createthread') || ($action === 'newpost')) {
261
   $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3');
262
   if ($db) {
263
     $db->exec('DELETE FROM ip_msg_counters24h WHERE msgid < strftime(\'%s\', \'now\') - 24*3600;');
264
     $count24h = intval($db->querySingle("SELECT count(*) FROM ip_msg_counters24h WHERE ipaddr = '{$_SERVER['REMOTE_ADDR']}'"));
265
     $db->close();
266
     if ($count24h >= 10) {
267
       $ERRSTR = "BŁĄD: Z TWOJEGO ADRESU NAPISANO JUŻ {$count24h} WIADOMOŚCI W PRZECIĄGU OSTATNICH 24H. SPRÓBUJ PONOWNIE ZA JAKIŚ CZAS.";
268
       $action = '';
269
     }
270
   }
271
}
272
 
273
// new thread creation (+switch to read thread)
274
if ($action === 'createthread') {
275
  // captcha check
276
  if (!sprawdz_captcha($_POST)) {
277
    echo "<p>BŁĄD: NIEPRAWIDŁOWE CAPTCHA</p>\n";
278
    goto DONE;
279
  }
280
  //
281
  $thread = time();
282
  if (empty($_POST['login']) || (empty($_POST['msg'])) || (empty($_POST['title']))) {
283
    echo '<p>BŁĄD: pusty nick, wiadomość lub tytuł</p>' . "\n";
284
    goto DONE;
285
  }
286
  if (!mkdir($DATADIR . 'threads/' . $thread, 0755, true)) {
287
    echo '<p>BŁĄD: nie zdołano utworzyć wątku nr ' . $thread . "</p>\n";
288
    goto DONE;
289
  }
290
  // zapisz tytuł
291
  file_put_contents($DATADIR . 'threads/' . $thread . '/title.txt', trim($_POST['title']));
292
  // ustaw co trzeba żeby zapisać wiadomość
293
  $action = 'newpost';
294
}
295
 
296
// nowy post do istniejącego wątku
297
if (($action === 'newpost') && ($thread >= 0) && (!empty($_POST['msg'])) && (!empty($_POST['login']))) {
298
  $postid = time();
299
  if (!sprawdz_captcha($_POST)) {
300
    $ERRSTR = "BŁĄD: NIEPRAWIDŁOWE CAPTCHA";
301
    goto DONE;
302
  }
303
  // nadpisz lastauthor i lastupdate
304
  $lastupdate = array('lastupdate' => $postid, 'lastauthor' => trim($_POST['login']));
305
  file_put_contents($DATADIR . 'threads/' . $thread . '/lastupdate', serialize($lastupdate));
306
  // oblicz tripkod, jeśli hasło zostało ustawione
307
  $tripsig = '';
308
  if (!empty(trim($_POST['pass']))) {
309
    $tripsig = hash('whirlpool', trim($_POST['login']) . '#' . trim($_POST['pass']) . $TRIP_SALT);
310
  }
311
  // zapisz wiadomość
312
  $msg = array('author' => trim($_POST['login']), 'ip' => $_SERVER['REMOTE_ADDR'], 'trip' => $tripsig, 'msg' => trim($_POST['msg']));
313
  file_put_contents($DATADIR . 'threads/' . $thread . '/' . $postid, serialize($msg));
314
  // zaktualizuj metadane dot. ostatniego wpisu, ostatniego autora i ilości wpisów dla tego IP w ciągu ostatniej godziny
315
  $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3');
316
  if ($db) {
317
    $db->exec('CREATE TABLE IF NOT EXISTS newest (thread INTEGER PRIMARY KEY, lastupdate INTEGER NOT NULL, lastauthor TEXT NOT NULL);');
318
    $db->exec('CREATE INDEX IF NOT EXISTS lastupdated ON newest (lastupdate);');
319
    $db->exec('CREATE TABLE IF NOT EXISTS ip_msg_counters24h (threadid INTEGER NOT NULL, msgid INTEGER NOT NULL, ipaddr TEXT NOT NULL);');
320
    $db->exec('CREATE TABLE IF NOT EXISTS rss (thread INTEGER NOT NULL, msgid INTEGER NOT NULL, author TEXT NOT NULL);');
321
    $db->exec('CREATE INDEX IF NOT EXISTS rss_msgid ON rss (msgid);');
322
    $login_escaped = $db->escapeString(trim($_POST['login']));
323
    $db->exec("INSERT OR REPLACE INTO newest (thread, lastupdate, lastauthor) VALUES ({$thread}, {$postid}, '{$login_escaped}');");
324
    $db->exec("INSERT INTO rss (thread, msgid, author) VALUES ({$thread}, {$postid}, '{$login_escaped}');");
325
    $db->exec("INSERT INTO ip_msg_counters24h (threadid, msgid, ipaddr) VALUES ({$thread}, {$postid}, '{$_SERVER['REMOTE_ADDR']}');");
326
    $db->close();
327
  } else {
328
    echo "SQL ERROR WHILE WRITING STATS\n";
329
  }
330
  // przekieruj
331
  if ($NICE_URLS) {
332
    $newurl = "{$thread}#{$postid}";
333
  } else {
334
    $newurl = selfurl("thread={$thread}") . "#{$postid}";
335
  }
336
  header("Location: {$newurl}");
337
  echo "<html><head></head><body><a href=\"{$newurl}\">KLIKNIJ TUTAJ</a></body></html>\n";
338
  exit();
339
}
340
 
341
DONE:
342
 
343
}
344
 
345
 
346
function mateuszbb_tytulwatku($id) {
347
  global $DATADIR;
348
  return file_get_contents($DATADIR . 'threads/' . $id . '/title.txt');
349
}
350
 
351
 
352
// wyświetlanie UI itd
353
function mateuszbb_start() {
354
global $TRIP_SALT;
355
global $ERRSTR;
356
global $DATADIR;
357
global $INITYEAR;
358
global $LANG;
359
global $STR;
360
global $NICE_URLS;
361
global $SEARCH_API_URL;
362
 
363
// read global variables
364
$action = getvar_action();
365
$thread = getvar_thread();
366
$archiveyear = getvar_archiveyear();
367
 
368
// wyświetl błąd, jeśli jakiś wystąpił w mateuszbb_preprocess()
369
if (!empty($ERRSTR)) {
370
  echo "<p class=\"minibb-errstr\">{$ERRSTR}</p>\n";
371
  $action = '';
372
  echo '<p><a href="./">Wróć do głównej strony</a></p>' . "\n";
373
  goto DONE;
374
}
375
 
376
// szukanie
377
if (isset($_POST['szukaj']) && (!empty(trim($_POST['szukaj'])))) {
378
  $q = trim($_POST['szukaj']);
379
  $query = $SEARCH_API_URL . urlencode($q);
380
  echo '<p>' . $STR[$LANG]['searchterm'] . ' ' . htmlentities($q) . '</p>';
381
  $results = file_get_contents($query);
382
  $resarr = json_decode($results, true)['items'];
383
 
384
  $licznik = 0;
385
  foreach ($resarr as $r) {
386
    if (mb_substr($r['link'], -1) === '/') continue;
387
    echo '<a href=' . $r['link'] . ' class="minibb-searchresult">';
388
    echo "<div><h1>{$r['title']}</h1><p>{$r['htmlSnippet']}</p></div></a>\n";
389
    $licznik++;
390
  }
391
 
392
  if ($licznik == 0) echo "<p>" . $STR[$LANG]['noresults'] . "</p>\n";
393
 
394
  goto DONE;
395
}
396
 
397
// new thread form
398
if ($action === 'newthread') {
399
  echo '<h2 class="minibb-threadtitle">' . $STR[$LANG]['newthread'] . '</h2>' . "\n";
400
  formularz();
401
  goto DONE;
402
}
403
 
404
// zobacz listę wątków
405
if ((empty($action)) && ($thread < 0) && ($archiveyear <= 0)) {
406
  echo '<div class="minibb-toolbar" style="justify-content: space-between;">';
407
  echo '<form action="' . selfurl() . '" method="POST"><input type="text" name="szukaj" placeholder="' . $STR[$LANG]['search'] . '"></form>';
408
  echo '<a href="' . selfurl('action=newthread') . '#formularz">' . $STR[$LANG]['opnewthread'] . '</a>';
409
  echo "</div>\n";
410
  $db = new SQLite3($DATADIR . 'mateuszbb.sqlite3', SQLITE3_OPEN_READONLY);
411
  if ($db) {
412
    $sqlres = $db->query('SELECT thread, lastupdate, lastauthor FROM newest ORDER BY lastupdate DESC LIMIT 30;');
413
    if (!$sqlres) {
414
      echo "SQL ERROR\n";
415
    } else {
416
      while ($row = $sqlres->fetchArray()) {
417
        $title = mateuszbb_tytulwatku($row['thread']);
418
        if (empty($title)) {
419
          echo "<!-- BŁĄD: nie zdołano załadować wątku nr {$row['thread']} -->\n";
420
          continue;
421
        }
422
        wyswietl_watek_w_liscie($row['thread'], $title, $row['lastauthor'], $row['lastupdate']);
423
      }
424
    }
425
    $db->close();
426
  } else {
427
    echo "<p>BŁĄD DOSTĘPU DO BAZY DANYCH</p>";
428
  }
429
 
430
  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";
431
  echo '<div>' . $STR[$LANG]['archives'] . ':';
432
  for ($y = $INITYEAR; $y <= intval(gmdate('Y')); $y++) {
433
    if ($NICE_URLS) {
434
      echo " <a href=\"{$y}\">{$y}</a>";
435
    } else {
436
      echo ' <a href="' . selfurl("arch={$y}") . '">' . $y . '</a>';
437
    }
438
  }
439
  echo "</div>\n";
440
  echo '<a href="rss.php"><img style="height: 1em;" src="mateuszbb_rss.svg"></a>' . "\n";
441
  echo "</div>\n";
442
 
443
  // display the main page footer if any is defined
444
  if (file_exists('mateuszforum-mainfooter.htm')) {
445
    readfile('mateuszbb-mainfooter.htm');
446
  }
447
 
448
  goto DONE;
449
}
450
 
451
// wyświetl archiwum
452
if ($archiveyear > 0) {
453
  echo '<div class="minibb-toolbar" id="title"><a href="' . selfurl() . '">' . $STR[$LANG]['backtocur'] . '</a></div>' . "\n";
454
  echo "<h1>" . $STR[$LANG]['archives'] . " {$archiveyear}</h1>\n";
455
  $threads = scandir($DATADIR . 'threads/', SCANDIR_SORT_ASCENDING);
456
  foreach ($threads as $t) {
457
    if (!preg_match('/^[0-9][0-9]*$/', $t)) continue; // skip anything that is not a thread id
458
    if (intval(gmdate('Y', $t)) != $archiveyear) continue; // skip threads out of the targeted year
459
    $title = file_get_contents($DATADIR . 'threads/' . $t . '/title.txt');
460
    $link = $t;
461
    if (! $NICE_URLS) $link = selfurl("thread={$t}");
462
    echo '<span style="font-family: monospace;">[' . gmdate("Y-m-d", $t) . "]</span> <a href=\"{$link}\">{$title}</a><br>\n";
463
  }
464
  goto DONE;
465
}
466
 
467
// zobacz wątek
468
if ((empty($action)) && ($thread >= 0)) {
469
  // załaduj listę postów (i zapamiętaj ostatnią pozycję)
470
  $listapostow = scandir($DATADIR . 'threads/' . $thread . '/');
471
  // usuń pozycje które nie są żadnym msgid (np. title.txt) i zapamiętaj ostatni msgid
472
  $posty = array();
473
  foreach ($listapostow as $p) {
474
    if (!preg_match('/^[0-9][0-9]*$/', $p)) continue; // skip anything that is not a messageid
475
    $posty[] = $p;
476
    $ostatnipost = $p;
477
  }
478
  // toolbar (ostatni wątek / odpowiedz / powrót do forum)
479
  echo '<div class="minibb-toolbar" id="title">';
480
  echo '<a href="#' . $ostatnipost . '">' . $STR[$LANG]['jumptoend'] . '</a> <a href="#formularz">' . $STR[$LANG]['reply'] . '</a> <a href="' . selfurl() . '">' . $STR[$LANG]['listthreads'] . '</a></div>' . "\n";
481
  // wyświetl tytuł wątku
482
  echo '<h2 class="minibb-threadtitle">' . htmlspecialchars(file_get_contents($DATADIR . 'threads/' . $thread . '/title.txt')) . "</h2>\n";
483
  // wyświetl listę wątków
484
  foreach ($posty as $p) {
485
    $msg = unserialize(file_get_contents($DATADIR . 'threads/' . $thread . '/' . $p));
486
    echo '<div class="minibb-post" id="' . $p . '">' . "\n";
487
    echo '<div class="minibb-postheader"><a href="#' . $p . '" style="text-decoration: inherit; color: inherit;"><div class="minibb-postauthor">' . "\n";
488
    echo $STR[$LANG]['author'] . ' ' . htmlspecialchars($msg['author']) . "<br>\n";
489
    echo $STR[$LANG]['address'] . ' ' . htmlspecialchars($msg['ip']) . "<br>\n";
490
    echo $STR[$LANG]['date'] . ' ' . htmlspecialchars(data_dluga($p)) . "</div></a>\n";
491
    if (!empty($msg['trip'])) {
492
      echo '<div class="minibb-trip">';
493
      echo chunk_split($msg['trip'], 16, "\n");
494
      echo "</div>\n";
495
    }
496
    echo "</div>\n";
497
 
498
    // symbole html
499
    $bodyprocessed = htmlspecialchars($msg['msg']);
500
 
501
    // dodaj podgląd pod linki do obrazków, ale tylko jeśli link jest sam w linijce
502
    $bodyprocessed = preg_replace('~^(http[s]?://[^<>[:space:]]+[[:alnum:]/]\.(jpg|png))($|[\r\n])~m', "$1\n<img src=\"$1\">\n", $bodyprocessed);
503
 
504
    // olinkuj linki
505
    $bodyprocessed = preg_replace("~([^\"]|^)(http[s]?://[^<>[:space:]]+[[:alnum:]/])~", "$1<a href=\"$2\">$2</a>", $bodyprocessed);
506
 
507
    // oflaguj cytaty (linijki zaczynające się od ">")
508
    $bodyprocessed = preg_replace('/^(&gt; .*)[\r]?\n/m', '<blockquote>$1</blockquote>', $bodyprocessed);
509
 
510
    echo '<div class="minibb-postbody">' . $bodyprocessed . '</div>' . "\n";
511
    echo "</div>\n";
512
  }
513
  // formularz odpowiedzi i do domu
514
  formularz($thread);
515
  goto DONE;
516
}
517
 
518
DONE:
519
}
520
?>