Subversion Repositories SvarDOS

Rev

Rev 1231 | Rev 1242 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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