Subversion Repositories SvarDOS

Rev

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