Rev 7 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php |
2 | |||
6 | daniel-mar | 3 | # ViaThinkSoft PHP Guestbook 2.8.3 |
4 | # (C) 2003-2023 ViaThinkSoft, Daniel Marschall |
||
4 | daniel-mar | 5 | # Licensed under the Apache 2.0 License |
2 | daniel-mar | 6 | |
7 | // Version des Gästebuchs |
||
7 | daniel-mar | 8 | $version = '2.8.3'; |
2 | daniel-mar | 9 | |
4 | daniel-mar | 10 | // START DEFAULT WERTE |
11 | |||
12 | $charset = 'ISO-8859-1'; |
||
13 | |||
14 | // Der Titel der Seite |
||
15 | $seitentitel = 'Mein Gästebuch'; |
||
16 | |||
17 | // Seitenkopf |
||
18 | $seitenkopf = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||
19 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||
20 | |||
21 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
||
22 | |||
23 | <head> |
||
24 | <meta http-equiv="Content-Type" content="text/html; charset={CHARSET}" /> |
||
25 | <title>'.htmlentities($seitentitel).' Gästebuch</title> |
||
26 | </head> |
||
27 | |||
28 | <body>'; |
||
29 | |||
30 | // Seitenfuß |
||
31 | $seitenfuss = '</body></html>'; |
||
32 | |||
33 | // Farben |
||
34 | $farbe1 = '#505080'; // Rand eines Eintrags |
||
35 | $farbe2 = '#D2DAF0'; // Eintrag Segment 2 (Text) BG |
||
36 | $farbe3 = '#A0B1E0'; // Eintrag Segment 1 (Kopfzeile) BG |
||
37 | $farbe4 = '#333333'; // Erstellungsdatum Schrift |
||
38 | $farbe5 = '#E2E7F5'; // Eintrag Segment 3 (Admin-Kommentar, optional) BG |
||
39 | $farbe6 = 'red'; // Fehlermeldung |
||
40 | $farbe7 = 'blue'; // Pflichtfeld-Stern |
||
41 | $farbe8 = 'green'; // Erfolgsmeldung |
||
42 | $farbe9 = 'black'; // Segment 1 (Kopfzeile) Text |
||
43 | $farbe10 = 'black'; // Segment 2 (Text) Text |
||
44 | $farbe11 = 'black'; // Segment 3 (Admin-Kommentar, optional) Text |
||
45 | |||
46 | // Die MySQL-Zugangsdaten |
||
47 | $mysql_server = 'localhost'; |
||
48 | $mysql_user = 'root'; |
||
49 | $mysql_pass = ''; |
||
50 | $mysql_database = 'guestbook'; |
||
51 | |||
52 | // Die Datenbanktabellennamen |
||
53 | $table_entries = 'gaestebuch_entries'; |
||
54 | $table_smileys = 'gaestebuch_smileys'; |
||
55 | |||
56 | // E-Mail-Adresse |
||
57 | $adminmail = 'your_email_address@example.com'; |
||
58 | $adminmail_cc = ''; |
||
59 | |||
60 | // Einträge pro Seite |
||
61 | $eintraege_proseite = 10; |
||
62 | |||
63 | // Vorsicht: Der Server muss autorisiert sein, eine E-Mail zu über diese Domain zu senden (SPF/DKIM) |
||
64 | $cfg_from_email = 'noreply@example.com'; |
||
65 | |||
66 | // Features |
||
67 | $cfg_feature_simple_antispam = true; |
||
68 | $cfg_automatisch_freischalten = false; |
||
69 | $cfg_unfreigeschaltete_anzegen = false; |
||
70 | $cfg_vorschau = true; |
||
71 | |||
72 | // Recaptcha - This is the most secure Captcha |
||
73 | // It also helps against "F5" spamming! |
||
74 | // Get a FREE API key here: https://www.google.com/recaptcha/admin/create |
||
75 | $cfg_recaptcha_enabled = false; |
||
76 | $cfg_recaptcha_pubkey = ''; |
||
77 | $cfg_recaptcha_privkey = ''; |
||
78 | |||
79 | // see https://daniel-lange.com/archives/66-ICQ-web-status-icons.html |
||
80 | $cfg_icq_statusicon = 5; |
||
81 | |||
82 | // ENDE DEFAULT WERTE |
||
83 | |||
2 | daniel-mar | 84 | if (!file_exists(__DIR__ . '/config/config.inc.php')) { |
85 | die('ERROR: File <b>config/config.inc.php</b> does not exist. Please create it using <b>config/config.original.inc.php</b>'); |
||
86 | } |
||
87 | require_once __DIR__ . '/config/config.inc.php'; |
||
88 | |||
89 | if ($cfg_recaptcha_enabled) $cfg_feature_simple_antispam = false; |
||
90 | |||
91 | require_once __DIR__ . '/includes/database.inc.php'; |
||
92 | verbinden(); |
||
93 | |||
94 | require_once __DIR__ . '/includes/SecureMailer.class.php'; |
||
95 | require_once __DIR__ . '/includes/ip_functions.inc.php'; |
||
96 | |||
97 | if ($cfg_recaptcha_enabled) { |
||
98 | require_once __DIR__ . '/includes/recaptcha/src/autoload.php'; |
||
99 | } |
||
100 | |||
101 | # ------------------------------ |
||
102 | |||
103 | // Funktion zum sichern von E-Mail-Adressen |
||
104 | // $crypt_linktext = 0 |
||
105 | // --> geeignet für <img>-links, da $linktext nicht in ASCII übersetzt wird! |
||
106 | // $crypt_linktext = 1 |
||
107 | // --> geeignet für text-links für höhere Sicherheit |
||
108 | |||
109 | function secure_email($email, $linktext, $crypt_linktext) { |
||
110 | $aus = ''; |
||
111 | if ($email != '') { |
||
112 | $aus .= '<script language="JavaScript" type="text/javascript"> |
||
113 | <!-- |
||
114 | document.write("<a href=\"");'."\n"; |
||
115 | |||
116 | $gesamttext = 'mailto:'.$email; |
||
117 | for ($i=0; $i<strlen($gesamttext); $i++) { |
||
118 | $aus .= ' document.write("&#'.ord(substr($gesamttext, $i, 1)).';");'."\n"; |
||
119 | } |
||
120 | |||
121 | $aus .= ' document.write("\">");'."\n"; |
||
122 | |||
123 | if ($crypt_linktext == '1') { |
||
124 | $gesamttext = $linktext; |
||
125 | for ($i=0; $i<strlen($gesamttext); $i++) { |
||
126 | $aus .= ' document.write("&#'.ord(substr($gesamttext, $i, 1)).';");'."\n"; |
||
127 | } |
||
128 | } else { |
||
129 | $gesamttext = str_replace('"', '\"', $linktext); |
||
130 | $aus .= ' document.write("'.$gesamttext.'");'; |
||
131 | } |
||
132 | |||
133 | $aus .= ' document.write("<\/a>"); |
||
134 | // --> |
||
135 | </script>'; |
||
136 | } |
||
137 | |||
138 | return $aus; |
||
139 | } |
||
140 | |||
141 | function myhtmlentities($nachricht) { |
||
142 | global $charset; |
||
143 | return htmlentities($nachricht, ENT_COMPAT | ENT_XHTML, $charset); |
||
144 | } |
||
145 | |||
146 | function parse_html($nachricht, $loc_dir = '') { |
||
147 | global $table_smileys; |
||
148 | |||
149 | // Smiley pre-parsing |
||
150 | $uid = uniqid(); |
||
4 | daniel-mar | 151 | $result = db_query("SELECT `zeichen`, `image`, `beschreibung`, `id` FROM `".db_real_escape_string($table_smileys)."` WHERE `enabled` = '1' ORDER BY `id` ASC"); |
152 | while ($row = db_fetch_object($result)) { |
||
2 | daniel-mar | 153 | # $nachricht = str_replace($row->zeichen, '<img src="images/smileys/'.$row->image.'" alt="'.myhtmlentities($row->beschreibung).'" title="'.myhtmlentities($row->beschreibung).'" />', $nachricht); |
6 | daniel-mar | 154 | $nachricht = str_replace($row->zeichen, "\nSMILEY{$uid}:".$row->id.":{$uid}YELIMS\n", $nachricht); |
2 | daniel-mar | 155 | } |
156 | |||
157 | // HTML Parsing |
||
158 | $nachricht = myhtmlentities($nachricht); |
||
159 | # Damit funktioniert wordwrap() nicht gescheit, was für den Mailverkehr wichtig ist. außerdem gibt es dann keinen umbruch in der voransicht |
||
160 | # $nachricht = str_replace(' ', ' ', $nachricht); |
||
161 | # TODO: man sollte ' '-> erst ersetzen, wenn es mehr als 1 leerzeichen ist |
||
162 | $nachricht = nl2br($nachricht); |
||
163 | $nachricht = str_replace('<br>', '<br />', $nachricht); // to be sure |
||
164 | $nachricht = str_replace('<BR>', '<br />', $nachricht); // to be sure |
||
165 | |||
166 | // Linkanalyse von phpBB |
||
167 | $nachricht = ' ' . $nachricht; |
||
168 | $nachricht = preg_replace("#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="\2://\3" target="_blank">\2://\3</a>', $nachricht); |
||
169 | $nachricht = preg_replace("#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="http://\2.\3" target="_blank">\2.\3</a>', $nachricht); |
||
170 | $nachricht = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $nachricht); |
||
171 | $nachricht = substr($nachricht, 1); |
||
172 | |||
173 | // Final smiley parsing |
||
4 | daniel-mar | 174 | $result = db_query("SELECT `zeichen`, `image`, `beschreibung`, `id` FROM `".db_real_escape_string($table_smileys)."` WHERE `enabled` = '1' ORDER BY `id` ASC"); |
175 | while ($row = db_fetch_object($result)) { |
||
6 | daniel-mar | 176 | $nachricht = str_replace("<br />\nSMILEY{$uid}:".$row->id.":{$uid}YELIMS<br />\n", '<img src="'.$loc_dir.'images/smileys/'.$row->image.'" alt="'.myhtmlentities($row->beschreibung).'" title="'.myhtmlentities($row->beschreibung).'" />', $nachricht); |
2 | daniel-mar | 177 | } |
178 | |||
179 | return $nachricht; |
||
180 | } |
||
181 | |||
182 | function anznachricht($name, $ort, $email, $home, $icq, $nachricht, $kommentar, $zeit, $datum) { |
||
183 | global $farbe1, $farbe2, $farbe3, $farbe4, $farbe5, $farbe6, $farbe7, $farbe8, $farbe9, $farbe10, $farbe11, $this_dir, $cfg_icq_statusicon; |
||
184 | |||
185 | $zzeit = explode(":", $zeit); |
||
186 | $zzeit = $zzeit[0].".".$zzeit[1]; |
||
187 | $ddatum = explode("-", $datum); |
||
188 | $ddatum = $ddatum[2].".".$ddatum[1].".".$ddatum[0]; |
||
189 | $nachricht = parse_html($nachricht, $this_dir); |
||
190 | |||
191 | echo '<table border="1" cellpadding="5" cellspacing="0" width="100%" style="border-color:'.$farbe1.';border-collapse:collapse">'; |
||
192 | echo ' <tr>'; |
||
193 | echo ' <td width="100%" bgcolor="'.$farbe3.'" style="border-color:'.$farbe1.';border-collapse:collapse">'; |
||
194 | echo ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="color:'.$farbe9.'">'; |
||
195 | echo ' <tr>'; |
||
196 | echo ' <td width="75%" align="left"><b>'.myhtmlentities($name).'</b>'; |
||
197 | if ($ort != '') echo ' aus '.myhtmlentities($ort); |
||
198 | echo '</td>'; |
||
199 | echo ' <td width="5%"> </td>'; |
||
200 | echo ' <td width="20%" align="right">'; |
||
201 | if ($email != '') { |
||
202 | echo secure_email(myhtmlentities($email), '<img src="images/email.gif" border="0" height="18" width="17" alt="E-Mail-Adresse" title="E-Mail-Adresse" />', 0); |
||
203 | } |
||
204 | if ($home != '') { |
||
205 | echo ' <a href="'.myhtmlentities($home).'" target="_blank"><img src="images/homepage.gif" border="0" height="18" width="16" alt="Homepage" title="Homepage" /></a>'; |
||
206 | } |
||
207 | if ($icq != '') { |
||
208 | echo ' <a href="https://icq.com/people/'.urlencode($icq).'" target="_blank"><img src="https://status.icq.com/online.gif?icq='.urlencode($icq).'&img='.$cfg_icq_statusicon.'" alt="Mein ICQ Status" title="Mein ICQ Status" border="0"></a></a>'; |
||
209 | } |
||
210 | echo '</td></tr></table></td></tr>'; |
||
211 | echo '<tr><td width="100%" bgcolor="'.$farbe2.'" style="color:'.$farbe10.'" align="left">'.$nachricht.'<br /><br /><font size="2" color="'.$farbe4.'">Dieser Eintrag wurde am '.$ddatum.' um '.$zzeit.' Uhr erstellt.</font></td></tr>'; |
||
212 | if ($kommentar != '') { |
||
213 | $kommentar = parse_html($kommentar, $this_dir); |
||
214 | echo '<tr><td width="100%" bgcolor="'.$farbe5.'" style="color:'.$farbe11.'" align="left"><b>Kommentar des Seiteneigentümers:</b><br /><br />'.$kommentar.'</td></tr>'; |
||
215 | } |
||
216 | echo '</table><br />'; |
||
217 | } |
||
218 | |||
219 | # -------------------------- |
||
220 | |||
221 | # http://stackoverflow.com/questions/1175096/how-to-find-out-if-you-are-using-https-without-serverhttps |
||
222 | $is_https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443); |
||
223 | |||
224 | $proto = $is_https ? 'https' : 'http'; |
||
225 | $inphp = $proto.'://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; |
||
226 | $this_dir = dirname($inphp).'/'; |
||
227 | |||
228 | $seitenkopf = str_replace('{CHARSET}', $charset, $seitenkopf); |
||
229 | echo $seitenkopf; |
||
230 | |||
231 | // Vor der Vorschau alles prüfen |
||
232 | $err_name = false; |
||
233 | $err_nachricht = false; |
||
234 | $err_icq = false; |
||
235 | $err_email = false; |
||
236 | $err_homepage = false; |
||
237 | $err_antispam = false; |
||
238 | $relfehler = ''; |
||
239 | |||
240 | $view_vorschau = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'vorschau'); |
||
241 | $view_abschicken = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'abschicken'); |
||
242 | $view_eintrag = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'eintrag'); |
||
243 | $view_freischalten = isset($_REQUEST['action']) && ($_REQUEST['action'] == 'freischalten'); |
||
244 | |||
245 | $name = (isset($_POST['name']) ? trim($_POST['name']) : ''); |
||
246 | $ort = (isset($_POST['ort']) ? trim($_POST['ort']) : ''); |
||
247 | $email = (isset($_POST['email']) ? trim($_POST['email']) : ''); |
||
248 | $homepage = (isset($_POST['homepage']) ? trim($_POST['homepage']) : ''); |
||
249 | $icq = (isset($_POST['icq']) ? trim($_POST['icq']) : ''); |
||
250 | $nachricht = (isset($_POST['nachricht']) ? trim($_POST['nachricht']) : ''); |
||
251 | $antispam = (isset($_POST['antispam']) ? trim($_POST['antispam']) : ''); |
||
252 | $kommentar = ''; |
||
253 | |||
254 | $icq = str_replace('-', '', $icq); // XXX-XXX-XXX -> XXXXXXXXX |
||
255 | |||
256 | # ----------------------------------- |
||
257 | |||
258 | function md5_valid($id, $md5_message) { |
||
259 | global $table_entries; |
||
260 | return md5($table_entries.'-'.$id.'-'.$md5_message.'-GBINT'); |
||
261 | } |
||
262 | |||
263 | # ----------------------------------- |
||
264 | |||
265 | if ($view_freischalten) { |
||
266 | $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : ''; |
||
267 | $md5 = isset($_REQUEST['md5']) ? $_REQUEST['md5'] : ''; |
||
268 | |||
269 | echo '<h1>Gästebucheintrag freischalten</h1>'; |
||
270 | |||
271 | if (($id == '') || ($md5 == '')) { |
||
272 | die('<p><font color="'.$farbe6.'">Ein Fehler ist aufgetreten. Fehler in den Parametern.</font></p>'.$seitenfuss); |
||
273 | } |
||
274 | |||
4 | daniel-mar | 275 | $result = db_query("SELECT `show`, MD5(`nachricht`) AS `md5` FROM `".db_real_escape_string($table_entries)."` WHERE `id` = '".db_real_escape_string($id)."'"); |
276 | if ($row = db_fetch_object($result)) { |
||
277 | if ($row->show == 1) { |
||
278 | echo '<p><font color="'.$farbe8.'">Eintrag ist bereits freigeschaltet!</font></p>'; |
||
2 | daniel-mar | 279 | } else { |
4 | daniel-mar | 280 | $md5_valid = md5_valid($id, $row->md5); |
281 | if (strtolower($md5) == strtolower($md5_valid)) { |
||
282 | db_query("UPDATE `".db_real_escape_string($table_entries)."` SET `show` = '1' WHERE `id` = '".db_real_escape_string($id)."'"); |
||
283 | echo '<p><font color="'.$farbe8.'">Eintrag erfolgreich freigeschaltet!</font></p>'; |
||
284 | } else { |
||
285 | echo '<p><font color="'.$farbe6.'">Keine Berechtigung, den Eintrag freizuschalten!</font></p>'; |
||
286 | } |
||
2 | daniel-mar | 287 | } |
288 | } |
||
289 | |||
290 | die($seitenfuss); |
||
291 | } |
||
292 | |||
293 | if ($cfg_feature_simple_antispam) { |
||
294 | // NG: erster block der IP adresse hinzufügen |
||
295 | $antispam_awaiting = (date('d')-15) * (2+date('m')) * 2 + 1337 + date('Y'); |
||
296 | } |
||
297 | |||
298 | if (($view_vorschau) || ($view_abschicken)) { |
||
299 | // Name prüfen |
||
300 | if ($name == '') $err_name = true; |
||
301 | |||
302 | // Nachricht prüfen |
||
303 | if ($nachricht == '') $err_nachricht = true; |
||
304 | |||
305 | // ICQ prüfen, wenn angegeben |
||
306 | if ((!preg_match('/^[0-9]+$/', $icq)) && ($icq != '')) $err_icq = true; |
||
307 | |||
308 | // E-Mail-Adresse prüfen, wenn angegeben |
||
309 | if ((!preg_match('/^[a-z0-9\.\-_\+]+@[a-z0-9\-_]+\.([a-z0-9\-_]+\.)*?[a-z]+$/is', $email)) && ($email != '')) $err_email = true; |
||
310 | |||
311 | // Homepage prüfen, wenn angegeben |
||
312 | if ($homepage != '') { |
||
313 | if (!preg_match('#^http[s]?:\/\/#i', $homepage)) { |
||
314 | $homepage = 'http://' . $homepage; |
||
315 | } |
||
316 | if (!preg_match('#^http[s]?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $homepage)) { |
||
317 | $err_homepage = true; |
||
318 | } |
||
319 | } |
||
320 | |||
321 | // AntiSpam prüfen |
||
322 | if (($cfg_feature_simple_antispam) && ($antispam != $antispam_awaiting)) $err_antispam = true; |
||
323 | |||
324 | // Fehler? |
||
325 | if (($err_name) || ($err_nachricht) || ($err_icq) || ($err_email) || ($err_homepage) || ($err_antispam)) { |
||
326 | $relfehler = '<font color="'.$farbe6.'"><u>Fehler</u>: Es wurden nicht alle Pflichtfelder ausgefüllt oder einige Felder enthalten einen Fehler!</font>'; |
||
327 | } |
||
328 | |||
329 | if (!$relfehler) { |
||
330 | $datum = date('Y-m-d'); |
||
331 | $zeit = date('H:i:s'); |
||
332 | $ip = get_real_ip(); // $_SERVER['REMOTE_ADDR']; |
||
333 | $host = gethostbyaddr($ip); |
||
334 | $whois_service = "https://whois.viathinksoft.de/whois/$ip"; |
||
335 | |||
336 | if ($view_vorschau) { |
||
337 | echo '<h1>Gästebucheintrag Vorschau</h1>'; |
||
338 | echo '<div align="center">'; |
||
339 | |||
340 | anznachricht($name, $ort, $email, $homepage, $icq, $nachricht, $kommentar, $zeit, $datum); |
||
341 | |||
342 | echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>\n"; |
||
343 | |||
344 | echo "<td>\n"; |
||
345 | echo "<form action=\"$inphp\" method=\"post\" name=\"frm2\">\n"; |
||
346 | echo "<input type=\"hidden\" name=\"action\" value=\"eintrag\" />\n"; |
||
347 | echo "<input type=\"hidden\" name=\"name\" value=\"".myhtmlentities($name)."\" />\n"; |
||
348 | echo "<input type=\"hidden\" name=\"ort\" value=\"".myhtmlentities($ort)."\" />\n"; |
||
349 | echo "<input type=\"hidden\" name=\"email\" value=\"".myhtmlentities($email)."\" />\n"; |
||
350 | echo "<input type=\"hidden\" name=\"homepage\" value=\"".myhtmlentities($homepage)."\" />\n"; |
||
351 | echo "<input type=\"hidden\" name=\"icq\" value=\"".myhtmlentities($icq)."\" />\n"; |
||
352 | echo "<input type=\"hidden\" name=\"nachricht\" value=\"".myhtmlentities($nachricht)."\" />\n"; |
||
353 | if ($cfg_feature_simple_antispam) echo "<input type=\"hidden\" name=\"antispam\" value=\"".myhtmlentities($antispam)."\" />\n"; |
||
354 | echo "<a href=\"javascript:document.frm2.submit()\"><img src=\"images/buttons/aendern.gif\" border=\"0\" height=\"31\" width=\"146\" alt=\"Ändern\" title=\"Ändern\" /></a>"; |
||
355 | echo "</form>"; |
||
356 | echo "</td>"; |
||
357 | |||
358 | echo "<td><img src=\"images/spacer.gif\" height=\"1\" width=\"30\" alt=\"\" /></td>"; |
||
359 | |||
360 | echo "<td>\n"; |
||
361 | echo "<form action=\"$inphp\" method=\"post\" name=\"frm1\">\n"; |
||
362 | echo "<input type=\"hidden\" name=\"action\" value=\"abschicken\" />\n"; |
||
363 | echo "<input type=\"hidden\" name=\"name\" value=\"".myhtmlentities($name)."\" />\n"; |
||
364 | echo "<input type=\"hidden\" name=\"ort\" value=\"".myhtmlentities($ort)."\" />\n"; |
||
365 | echo "<input type=\"hidden\" name=\"email\" value=\"".myhtmlentities($email)."\" />\n"; |
||
366 | echo "<input type=\"hidden\" name=\"homepage\" value=\"".myhtmlentities($homepage)."\" />\n"; |
||
367 | echo "<input type=\"hidden\" name=\"icq\" value=\"".myhtmlentities($icq)."\" />\n"; |
||
368 | echo "<input type=\"hidden\" name=\"nachricht\" value=\"".myhtmlentities($nachricht)."\" />\n"; |
||
369 | if ($cfg_feature_simple_antispam) echo "<input type=\"hidden\" name=\"antispam\" value=\"".myhtmlentities($antispam)."\" />\n"; |
||
370 | echo "<a href=\"javascript:document.frm1.submit()\"><img src=\"images/buttons/abschicken.gif\" border=\"0\" height=\"31\" width=\"146\" alt=\"Abschicken\" title=\"Abschicken\" /></a>"; |
||
371 | echo "</form>"; |
||
372 | echo "</td>"; |
||
373 | |||
374 | echo "</tr></table></div>\n"; |
||
375 | } elseif ($view_abschicken) { |
||
376 | $pass_final_recaptcha = true; |
||
377 | if ($cfg_recaptcha_enabled) { |
||
378 | if (!isset($_POST['g-recaptcha-response'])) { |
||
379 | $pass_final_recaptcha = false; |
||
380 | } else { |
||
381 | $recaptcha = new \ReCaptcha\ReCaptcha($cfg_recaptcha_privkey); |
||
382 | $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); |
||
383 | $pass_final_recaptcha = $resp->isSuccess(); |
||
384 | } |
||
385 | } |
||
386 | |||
387 | if (!$pass_final_recaptcha) { |
||
388 | echo '<h1>Bitte Sicherheitsfrage beantworten</h1>'; |
||
389 | echo '<p>Bitte tippen Sie den dargestellten Code ab. Dadurch wird sichergestellt dass Sie ein Mensch und kein Spam-Bot sind.</p>'; |
||
390 | |||
391 | echo "<form action=\"$inphp\" method=\"post\" name=\"frm1\">\n"; |
||
392 | |||
393 | echo '<div class="g-recaptcha" data-sitekey="'.$cfg_recaptcha_pubkey.'"></div>'; |
||
394 | echo '<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>'; |
||
395 | echo '<br>'; |
||
396 | |||
397 | echo "<input type=\"hidden\" name=\"action\" value=\"abschicken\" />\n"; |
||
398 | echo "<input type=\"hidden\" name=\"name\" value=\"".myhtmlentities($name)."\" />\n"; |
||
399 | echo "<input type=\"hidden\" name=\"ort\" value=\"".myhtmlentities($ort)."\" />\n"; |
||
400 | echo "<input type=\"hidden\" name=\"email\" value=\"".myhtmlentities($email)."\" />\n"; |
||
401 | echo "<input type=\"hidden\" name=\"homepage\" value=\"".myhtmlentities($homepage)."\" />\n"; |
||
402 | echo "<input type=\"hidden\" name=\"icq\" value=\"".myhtmlentities($icq)."\" />\n"; |
||
403 | echo "<input type=\"hidden\" name=\"nachricht\" value=\"".myhtmlentities($nachricht)."\" />\n"; |
||
404 | if ($cfg_feature_simple_antispam) echo "<input type=\"hidden\" name=\"antispam\" value=\"".myhtmlentities($antispam)."\" />\n"; |
||
405 | echo "<a href=\"javascript:document.frm1.submit()\"><img src=\"images/buttons/abschicken.gif\" border=\"0\" height=\"31\" width=\"146\" alt=\"Abschicken\" title=\"Abschicken\" /></a>"; |
||
406 | echo "</form>"; |
||
407 | } else { |
||
4 | daniel-mar | 408 | $daten = "'".db_real_escape_string($name)."'"; |
2 | daniel-mar | 409 | $felder = '`name`'; |
410 | |||
411 | if ($ort != '') { |
||
4 | daniel-mar | 412 | $daten .= ", '".db_real_escape_string($ort)."'"; |
2 | daniel-mar | 413 | $felder .= ', `ort`'; |
414 | } |
||
415 | |||
416 | if ($email != '') { |
||
4 | daniel-mar | 417 | $daten .= ", '".db_real_escape_string($email)."'"; |
2 | daniel-mar | 418 | $felder .= ', `email`'; |
419 | } |
||
420 | |||
421 | if ($homepage != '') { |
||
4 | daniel-mar | 422 | $daten .= ", '".db_real_escape_string($homepage)."'"; |
2 | daniel-mar | 423 | $felder .= ', `homepage`'; |
424 | } |
||
425 | |||
426 | if ($icq != '') { |
||
4 | daniel-mar | 427 | $daten .= ", '".db_real_escape_string($icq)."'"; |
2 | daniel-mar | 428 | $felder .= ', `icq`'; |
429 | } |
||
430 | |||
4 | daniel-mar | 431 | $daten .= ", '".db_real_escape_string("$datum $zeit")."'"; |
2 | daniel-mar | 432 | $felder .= ', `timestamp`'; |
433 | |||
4 | daniel-mar | 434 | $daten .= ", '".db_real_escape_string($ip)."'"; |
2 | daniel-mar | 435 | $felder .= ', `ip`'; |
436 | |||
4 | daniel-mar | 437 | $daten .= ", '".db_real_escape_string($nachricht)."'"; |
2 | daniel-mar | 438 | $felder .= ', `nachricht`'; |
439 | |||
440 | $show = $cfg_automatisch_freischalten ? '1' : '0'; |
||
4 | daniel-mar | 441 | $daten .= ", '".db_real_escape_string($show)."'"; |
2 | daniel-mar | 442 | $felder .= ', `show`'; |
443 | |||
4 | daniel-mar | 444 | $result = db_query("INSERT INTO `".db_real_escape_string($table_entries)."` ($felder) VALUES ($daten)"); |
445 | $id = db_insert_id(); |
||
2 | daniel-mar | 446 | |
447 | $md5 = md5($nachricht); |
||
448 | $md5_valid = md5_valid($id, $md5); |
||
449 | |||
450 | // Send mail |
||
451 | |||
452 | $ger_datum = date('d.m.Y', strtotime($datum)); |
||
453 | |||
454 | $msg_html = "<h1>".myhtmlentities($seitentitel)." - Gästebucheintrag</h1>\n"; |
||
455 | $msg_html .= "<b>Name:</b> ".myhtmlentities($name)."<br />\n"; |
||
456 | $msg_html .= "<b>E-Mail:</b> ".myhtmlentities($email)."<br />\n"; |
||
457 | $msg_html .= "<b>Ort:</b> ".myhtmlentities($ort)."<br />\n"; |
||
458 | $msg_html .= "<b>Homepage:</b> ".myhtmlentities($homepage)."<br />\n"; |
||
459 | $msg_html .= "<b>ICQ:</b> ".myhtmlentities($icq)."<br />\n"; |
||
460 | $msg_html .= "<b>Datum:</b> $ger_datum<br />\n"; |
||
461 | $msg_html .= "<b>Uhrzeit:</b> $zeit<br />\n"; |
||
462 | $msg_html .= "<br />\n"; |
||
463 | $msg_html .= "<b>Nachricht:</b> ".parse_html($nachricht, $this_dir)."<br />\n"; |
||
464 | $msg_html .= "<br />\n"; |
||
465 | $msg_html .= "<i>Datensatz Nr. $id wurde erstellt.</i><br />\n"; |
||
466 | $msg_html .= "<br />\n"; |
||
467 | $msg_html .= "<font size=\"+1\"><b>Absenderdaten:</b></font><br />\n"; |
||
468 | $msg_html .= "<br />\n"; |
||
469 | $msg_html .= "<b>IP-Adresse:</b> <a href=\"$whois_service\" target=\"_blank\">$ip</a> ($host)<br />\n"; |
||
470 | $msg_html .= "<b>Browser:</b> ".$_SERVER['HTTP_USER_AGENT']."<br />\n"; |
||
471 | $msg_html .= "<br />\n"; |
||
472 | if (!$cfg_automatisch_freischalten) { |
||
473 | $msg_html .= '<i>Klicken Sie <a href="'."$inphp?action=freischalten&id=$id&md5=".urlencode($md5_valid).'" target="_blank">hier</a>, um den Eintrag freizuschalten. Schalten Sie den Eintrag nicht frei, so bleibt er unveröffentlicht.</i><br />'."\n"; |
||
474 | } |
||
475 | |||
476 | $msg_plain = "$seitentitel - Gästebucheintrag\n\n"; |
||
477 | $msg_plain .= "Name: $name\n"; |
||
478 | $msg_plain .= "E-Mail: $email\n"; |
||
479 | $msg_plain .= "Ort: $ort\n"; |
||
480 | $msg_plain .= "Homepage: $homepage\n"; |
||
481 | $msg_plain .= "ICQ: $icq\n"; |
||
482 | $msg_plain .= "Datum: $ger_datum\n"; |
||
483 | $msg_plain .= "Uhrzeit: $zeit\n"; |
||
484 | $msg_plain .= "\n"; |
||
485 | $msg_plain .= "Nachricht: $nachricht\n"; |
||
486 | $msg_plain .= "\n"; |
||
487 | $msg_plain .= "Datensatz Nr. $id wurde erstellt.\n"; |
||
488 | $msg_plain .= "\n"; |
||
489 | $msg_plain .= "Absenderdaten:\n"; |
||
490 | $msg_plain .= "\n"; |
||
491 | $msg_plain .= "IP-Adresse: $ip ($host) - Whois-Lookup at $whois_service\n"; |
||
492 | $msg_plain .= "Browser: ".$_SERVER['HTTP_USER_AGENT']."\n"; |
||
493 | $msg_plain .= "\n"; |
||
494 | if (!$cfg_automatisch_freischalten) { |
||
495 | $msg_plain .= "Öffnen Sie $inphp?action=freischalten&id=$id&md5=".urlencode($md5_valid)." , um den Eintrag freizuschalten. Schalten Sie den Eintrag nicht frei, so bleibt er unveröffentlicht.\n"; |
||
496 | } |
||
497 | |||
498 | $h = new SecureMailer(); // Includes Anti Mail-Header-Injection |
||
499 | |||
500 | /* |
||
501 | # http://www.phpbox.de/tipsundtricks/emailsumlaute.php |
||
502 | $h->addHeader('Mime-Version', '1.0'); |
||
503 | $h->addHeader('Content-Type', 'text/html; charset='.$charset); |
||
504 | |||
505 | $h->addHeader('Content-Transfer-Encoding', 'quoted-printable'); |
||
506 | # $msg_html = wordwrap($msg_html); |
||
507 | # $msg_html = quoted_printable_encode($msg_html); |
||
508 | $msg_html = quoted_printable_encode2($msg_html); |
||
509 | */ |
||
510 | |||
511 | if ($cfg_from_email != '') { |
||
512 | $h->addHeader('From', $cfg_from_email); |
||
513 | } |
||
514 | if ($email != '') { |
||
515 | $h->addHeader('Reply-To', $email); |
||
516 | } |
||
517 | |||
4 | daniel-mar | 518 | if ($adminmail_cc != '') { |
2 | daniel-mar | 519 | $h->addHeader('CC', $adminmail_cc); |
520 | } |
||
521 | |||
522 | $h->addHeader('X-Mailer', 'PHP/'.phpversion()); |
||
523 | |||
524 | $subject = "$seitentitel - Gästebucheintrag"; |
||
525 | $subject = SecureMailer::utf8Subject($subject); |
||
526 | |||
527 | # $gesendet = $h->sendMail($adminmail, $subject, $msg_html); |
||
528 | $gesendet = $h->sendMailHTMLandPlainMultipart($adminmail, $subject, $msg_html, $msg_plain); |
||
529 | |||
530 | if (!$gesendet) { |
||
531 | echo '<p><font color="'.$farbe6.'">FEHLER BEIM SENDEN DER MAIL!</font></p>'; |
||
532 | } |
||
533 | |||
534 | if ($result) { |
||
535 | echo '<h1 align="center">Gästebucheintrag abgeschickt</h1> |
||
536 | |||
537 | <div align="center"> |
||
538 | |||
539 | <p><font color="'.$farbe8.'">Ihr Gästebucheintrag wurde erfolgreich eingetragen!</font></p> |
||
540 | |||
541 | <p>Bitte beachten Sie, dass der Eintrag erst nach einer Prüfung des Seiteninhabers freigeschaltet wird.</p> |
||
542 | |||
543 | <p><a href="'.$inphp.'"><img src="images/buttons/zurueck.gif" alt="Zurück" title="Zurück" height="31" width="146" border="0" /></a></p> |
||
544 | |||
545 | </div>'; |
||
546 | |||
547 | } else { |
||
4 | daniel-mar | 548 | echo "<p>".db_error()."</p>"; |
2 | daniel-mar | 549 | echo '<p><font color="'.$farbe6.'">Es ist ein schwerer Fehler aufgetreten. Versuchen Sie es nocheinmal.</font></p>'; |
550 | } |
||
551 | } |
||
552 | } |
||
553 | } |
||
554 | } |
||
555 | |||
556 | if ($relfehler || $view_eintrag) { |
||
557 | echo '<h1>Gästebucheintrag</h1>'; |
||
558 | |||
559 | echo '<p>Bitte füllen Sie die unteren Felder aus. Die mit <font color="'.$farbe7.'">*</font> gekennzeichneten |
||
560 | Felder müssen ausgefüllt werden! Um Missbrauch zu vermeiden, wird die |
||
561 | IP-Adresse gespeichert.'; |
||
562 | echo ' Die Einträge werden erst nach einer Prüfung veröffentlicht.'; |
||
563 | echo '</p>'; |
||
564 | |||
4 | daniel-mar | 565 | if ($relfehler != '') { |
2 | daniel-mar | 566 | echo "<p>$relfehler</p>"; |
567 | } |
||
568 | |||
569 | echo '<br /> |
||
570 | |||
571 | <form action="'.$inphp.'" method="post" name="frm"> |
||
572 | <input type="hidden" name="action" value="'.($cfg_vorschau ? 'vorschau' : 'abschicken').'" /> |
||
573 | |||
574 | <table cellspacing="0" cellpadding="0" border="0"> |
||
575 | <tr> |
||
576 | <td align="right">'; |
||
577 | |||
578 | if ($err_name) { |
||
579 | echo '<font color="'.$farbe6.'">Name *:</font>'; |
||
580 | } else { |
||
581 | echo 'Name <font color="'.$farbe7.'">*</font>:'; |
||
582 | } |
||
583 | |||
584 | echo '</td> |
||
585 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
586 | <td><input maxlength="40" size="66" name="name" value="'.$name.'" /></td> |
||
587 | </tr> |
||
588 | <tr> |
||
589 | <td align="right">Wohnort:</td> |
||
590 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
591 | <td><input maxlength="40" size="66" name="ort" value="'.$ort.'" /></td> |
||
592 | </tr> |
||
593 | <tr> |
||
594 | <td align="right">'; |
||
595 | |||
596 | if ($err_email) { |
||
597 | echo '<font color="'.$farbe6.'">E-Mail:</font>'; |
||
598 | } else { |
||
599 | echo 'E-Mail:'; |
||
600 | } |
||
601 | |||
602 | echo '</td> |
||
603 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
604 | <td><input maxlength="40" size="66" name="email" value="'.$email.'" /></td> |
||
605 | </tr> |
||
606 | <tr> |
||
607 | <td align="right">'; |
||
608 | |||
609 | if ($err_homepage) { |
||
610 | echo '<font color="'.$farbe6.'">Homepage:</font>'; |
||
611 | } else { |
||
612 | echo 'Homepage:'; |
||
613 | } |
||
614 | |||
615 | echo '</td> |
||
616 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
617 | <td><input maxlength="40" size="66" name="homepage" value="'.$homepage.'" /></td> |
||
618 | </tr> |
||
619 | <tr> |
||
620 | <td align="right">'; |
||
621 | |||
622 | if ($err_icq) { |
||
623 | echo '<font color="'.$farbe6.'">ICQ:</font>'; |
||
624 | } else { |
||
625 | echo 'ICQ:'; |
||
626 | } |
||
627 | |||
628 | echo '</td> |
||
629 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
630 | <td><input maxlength="40" size="66" name="icq" value="'.$icq.'" /></td> |
||
631 | </tr> |
||
632 | <tr> |
||
633 | <td colspan="3"> </td> |
||
634 | </tr>'; |
||
635 | |||
636 | if ($cfg_feature_simple_antispam) { |
||
637 | echo '<tr> |
||
638 | <td align="right">'; |
||
639 | |||
640 | if ($err_antispam) { |
||
641 | echo '<font color="'.$farbe6.'">Bitte <!--"-->'.$antispam_awaiting.'<!--"--> eingeben *:</font>'; |
||
642 | } else { |
||
643 | echo 'Bitte <!--"-->'.$antispam_awaiting.'<!--"--> eingeben <font color="'.$farbe7.'">*</font>:'; |
||
644 | } |
||
645 | |||
646 | echo '</td> |
||
647 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
648 | <td><input maxlength="40" size="66" name="antispam" value="'.$antispam.'" /> (AntiSpam-Frage)</td> |
||
649 | </tr> |
||
650 | |||
651 | <tr> |
||
652 | <td colspan="3"> </td> |
||
653 | </tr>'; |
||
654 | } |
||
655 | |||
656 | echo '<tr> |
||
657 | <td align="right">Smileys:</td> |
||
658 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
659 | <td><script language="JavaScript" type="text/javascript"> |
||
660 | <!-- |
||
661 | function setsmiley(smiley) { |
||
662 | frm.nachricht.value = frm.nachricht.value + smiley; |
||
663 | } |
||
664 | // --> |
||
665 | </script>'; |
||
666 | |||
4 | daniel-mar | 667 | $result = db_query("SELECT `zeichen`, `image`, `beschreibung` FROM `".db_real_escape_string($table_smileys)."` WHERE `enabled` = '1' AND `show_in_editor` = '1' ORDER BY `id` ASC"); |
668 | while ($row = db_fetch_object($result)) { |
||
2 | daniel-mar | 669 | echo "<a href=\"javascript:setsmiley(' ".addslashes(myhtmlentities($row->zeichen))." ')\">". |
670 | '<img src="images/smileys/'.$row->image.'" border="0" alt="'.myhtmlentities($row->beschreibung).'" title="'.myhtmlentities($row->beschreibung).'" /></a> '; |
||
671 | } |
||
672 | |||
673 | echo '</td> |
||
674 | </tr> |
||
675 | <tr> |
||
676 | <td colspan="3"> </td> |
||
677 | </tr> |
||
678 | <tr> |
||
679 | <td valign="top" align="right">'; |
||
680 | |||
681 | if ($err_nachricht) { |
||
682 | echo '<font color="'.$farbe6.'">Nachricht *:</font>'; |
||
683 | } else { |
||
684 | echo 'Nachricht <font color="'.$farbe7.'">*</font>:'; |
||
685 | } |
||
686 | |||
687 | echo '</td> |
||
688 | <td><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
689 | <td><textarea name="nachricht" rows="5" cols="50">'.$nachricht.'</textarea><!-- wrap="virtual" --></td> |
||
690 | </tr> |
||
691 | <tr> |
||
692 | <td colspan="2"><img src="images/spacer.gif" height="1" width="10" alt="" /></td> |
||
693 | <td><br /> |
||
694 | <a href="javascript:document.frm.submit()">'; |
||
695 | if ($cfg_vorschau) { |
||
696 | echo '<img height="31" alt="Vorschau" title="Vorschau" src="images/buttons/vorschau.gif" width="146" border="0" />'; |
||
697 | } else { |
||
698 | echo '<img src="images/buttons/abschicken.gif" border="0" height="31" width="146" alt="Abschicken" title="Abschicken" />'; |
||
699 | } |
||
700 | echo '</a> <!-- |
||
701 | <img src="images/spacer.gif" height="1" width="30" alt="" /> |
||
702 | <a href="javascript:document.frm.reset()"> |
||
703 | <img height="31" alt="Löschen" title="Löschen" src="images/buttons/loeschen.gif" width="146" border="0" /></a> |
||
704 | --> |
||
705 | </td> |
||
706 | </tr> |
||
707 | </table> |
||
708 | |||
709 | </form> |
||
710 | |||
711 | <p align="center"><a href="'.$inphp.'">Zurück zu den Einträgen</a></p>'; |
||
712 | } else if ((!$view_vorschau) && (!$view_abschicken) && (!$view_eintrag)) { |
||
713 | echo '<h1 align="center">Gästebuch</h1> |
||
714 | |||
715 | <table width="100%" border="0" cellspacing="0" cellpadding="0"> |
||
716 | <tr> |
||
717 | <td align="center">[ <a href="'.$inphp.'?action=eintrag">Neuen Eintrag hinzufügen</a> ]</td></tr></table><br />'; |
||
718 | |||
719 | $cond = ($cfg_unfreigeschaltete_anzegen) ? '' : " WHERE `show` = '1'"; |
||
720 | |||
4 | daniel-mar | 721 | $result = db_query("SELECT * FROM `".db_real_escape_string($table_entries)."`$cond"); |
722 | if ($result) $number = db_num_rows($result); else $number = 0; |
||
2 | daniel-mar | 723 | $max_page = ceil($number / $eintraege_proseite); |
724 | |||
8 | daniel-mar | 725 | $seiten = $_REQUEST['seiten'] ?? '1'; |
726 | $seiten = preg_replace('@[^0-9]@', '', $seiten); |
||
727 | if (($seiten > $max_page) || ($seiten < 0)) $seiten = '1'; |
||
2 | daniel-mar | 728 | |
4 | daniel-mar | 729 | $result = db_query("SELECT * FROM `".db_real_escape_string($table_entries)."`$cond ORDER BY `id` DESC LIMIT ".($seiten-1)*$eintraege_proseite.",".$eintraege_proseite); |
2 | daniel-mar | 730 | |
731 | $keineeintraege = true; |
||
732 | |||
733 | if ($result) { |
||
4 | daniel-mar | 734 | while ($row = db_fetch_object($result)) { |
2 | daniel-mar | 735 | $xry = explode(' ', $row->timestamp); |
736 | $datum = $xry[0]; |
||
737 | $zeit = $xry[1]; |
||
738 | anznachricht($row->name, $row->ort, $row->email, $row->homepage, $row->icq, $row->nachricht, $row->kommentar, $zeit, $datum); |
||
739 | $keineeintraege = false; |
||
740 | } |
||
741 | } |
||
742 | |||
743 | if ($keineeintraege) { |
||
744 | echo '<div align="center">Es sind keine Einträge vorhanden!</div>'; |
||
745 | } |
||
746 | |||
747 | if ((!$keineeintraege) && ($max_page != 1)) { |
||
748 | echo '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td align="center"><p class="klein2">Seite: '; |
||
749 | for ($i=1; $i<=$max_page; $i++) { |
||
750 | if ($seiten != $i) { |
||
751 | echo "<a href=\"$inphp?seiten=$i\">[$i]</a>\n"; |
||
752 | } else { |
||
753 | echo "<b>[$i]</b>\n"; |
||
754 | } |
||
755 | } |
||
756 | echo '</p></td></tr></table>'; |
||
757 | } |
||
758 | |||
759 | } |
||
760 | |||
761 | echo '<p align="center">OpenSource PHP-Gästebuch von <a href="http://www.viathinksoft.de/" target="_blank">ViaThinkSoft</a>, Version '.$version.'</p>'; |
||
762 | |||
763 | echo $seitenfuss; |
||
764 | |||
765 | # --- |
||
766 | |||
767 | // This is the only function which works with GMX. |
||
768 | // wordwrap+quoted_printable_encode does not work, since it would insert whitespaces. |
||
769 | // http://www.php.net/manual/en/function.quoted-printable-encode.php#97230 |
||
770 | function quoted_printable_encode2($input, $line_max = 75) { |
||
771 | $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
||
772 | $lines = preg_split("/(?:\r\n|\r|\n)/", $input); |
||
773 | $linebreak = "=0D=0A=\r\n"; |
||
774 | /* the linebreak also counts as characters in the mime_qp_long_line |
||
775 | * rule of spam-assassin */ |
||
776 | $line_max = $line_max - strlen($linebreak); |
||
777 | $escape = "="; |
||
778 | $output = ""; |
||
779 | $cur_conv_line = ""; |
||
780 | $length = 0; |
||
781 | $whitespace_pos = 0; |
||
782 | $addtl_chars = 0; |
||
783 | |||
784 | // iterate lines |
||
785 | for ($j=0; $j<count($lines); $j++) { |
||
786 | $line = $lines[$j]; |
||
787 | $linlen = strlen($line); |
||
788 | |||
789 | // iterate chars |
||
790 | for ($i = 0; $i < $linlen; $i++) { |
||
791 | $c = substr($line, $i, 1); |
||
792 | $dec = ord($c); |
||
793 | |||
794 | $length++; |
||
795 | |||
796 | if ($dec == 32) { |
||
797 | // space occurring at end of line, need to encode |
||
798 | if (($i == ($linlen - 1))) { |
||
799 | $c = "=20"; |
||
800 | $length += 2; |
||
801 | } |
||
802 | |||
803 | $addtl_chars = 0; |
||
804 | $whitespace_pos = $i; |
||
805 | } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { |
||
806 | $h2 = floor($dec/16); $h1 = floor($dec%16); |
||
807 | $c = $escape . $hex[$h2] . $hex[$h1]; |
||
808 | $length += 2; |
||
809 | $addtl_chars += 2; |
||
810 | } |
||
811 | |||
812 | // length for wordwrap exceeded, get a newline into the text |
||
813 | if ($length >= $line_max) { |
||
814 | $cur_conv_line .= $c; |
||
815 | |||
816 | // read only up to the whitespace for the current line |
||
817 | $whitesp_diff = $i - $whitespace_pos + $addtl_chars; |
||
818 | |||
819 | /* the text after the whitespace will have to be read |
||
820 | * again ( + any additional characters that came into |
||
821 | * existence as a result of the encoding process after the whitespace) |
||
822 | * |
||
823 | * Also, do not start at 0, if there was *no* whitespace in |
||
824 | * the whole line */ |
||
825 | if (($i + $addtl_chars) > $whitesp_diff) { |
||
826 | $output .= substr($cur_conv_line, 0, (strlen($cur_conv_line) - $whitesp_diff)) . $linebreak; |
||
827 | $i = $i - $whitesp_diff + $addtl_chars; |
||
828 | } else { |
||
829 | $output .= $cur_conv_line . $linebreak; |
||
830 | } |
||
831 | |||
832 | $cur_conv_line = ""; |
||
833 | $length = 0; |
||
834 | $whitespace_pos = 0; |
||
835 | } else { |
||
836 | // length for wordwrap not reached, continue reading |
||
837 | $cur_conv_line .= $c; |
||
838 | } |
||
839 | } // end of for |
||
840 | |||
841 | $length = 0; |
||
842 | $whitespace_pos = 0; |
||
843 | $output .= $cur_conv_line; |
||
844 | $cur_conv_line = ""; |
||
845 | |||
846 | if ($j<=count($lines)-1) { |
||
847 | $output .= $linebreak; |
||
848 | } |
||
849 | } // end for |
||
850 | |||
851 | return trim($output); |
||
852 | } // end quoted_printable_encode |