Subversion Repositories SvarDOS

Rev

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

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