Subversion Repositories SvarDOS

Rev

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