Add simple spambot barrier
[infodrom.org/www.zeitungsliste.de] / lib / layout.inc
1 <?php
2
3 include_once('extern/rfc822.php');
4
5 function warning($text)
6 {
7   global $cfg;
8   $ret = '<p class="warn"><img src="'.$cfg['basepath'].
9     'achtung.gif" width="33" height="32" alt="Achtung!">&nbsp;&nbsp;';
10   $ret .= $text .'</p>';
11   return $ret;
12 }
13
14 function information($text)
15 {
16   global $cfg;
17   $ret = '<p class="info"><img src="'.$cfg['basepath'].
18     'information.gif" width="31" height="31" alt="Info">&nbsp;&nbsp;';
19   $ret .= $text .'</p>';
20   return $ret;
21 }
22
23 function pageheader()
24 {
25   global $cfg;
26   global $zlist;
27
28   $ret .= '<!DOCTYPE html">';
29   $ret .= '<html lang="de">';
30   $ret .= '<head>';
31   if (isset($zlist['newspaper']))
32     $ret .= sprintf('<title>Zeitungsliste: %s</title>', $zlist['newspaper']);
33   elseif (isset($zlist['tag']))
34     $ret .= sprintf('<title>Zeitungsliste: Tag %s</title>', $zlist['tag']);
35   else
36     $ret .= '<title>Zeitungsliste</title>';
37   header('Content-Type: text/html; charset=UTF-8');
38   $ret .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
39   $ret .= '<meta name="Author" content="joey@infodrom.org (Joey Schulze)">';
40   $ret .= '<meta name="Language" content="de">';
41   
42   if ($zlist['page'] == 'index') {
43     $ret .= '<meta name="Keywords" content="Zeitung, Zeitungen, Liste, Zeitungsliste, Online-Zeitungen, Zeitungen im Web, Forum, Community, '.
44       'Liste aller Zeitungen">';
45     $ret .= sprintf('<link rel="alternate" type="application/rss+xml" title="Zeitungen" href="%szeitungen.rdf">', $cfg['basepath']);
46   } elseif ($cfg['dir'] == 'zeitung') {
47     $ret .= '<meta name="Keywords" content="Zeitung, Zeitungsliste, Online-Zeitung, Zeitung im Web, Forum, Community, '.
48       $zlist['newspaper'] . ', ' . $zlist['city'] . '">';
49   }
50
51   if (is_spider())
52     $ret .= '<meta name="Robots" content="index,follow">';
53   $ret .= '<meta name="Copyright" content="(c) 2018 Information & Consulting">';
54   $ret .= sprintf('<link href="%smain.css" rel="stylesheet" type="text/css">', $cfg['basepath']);
55   $ret .= sprintf('<link rel="icon" href="%sfavicon.ico" type="image/x-icon">', $cfg['basepath']);
56   $ret .= sprintf('<link rel="shortcut icon" href="%sfavicon.ico" type="image/x-icon">', $cfg['basepath']);
57
58   if (isset($zlist['redirect']))
59     $ret .= sprintf('<meta http-equiv="refresh" content="7; URL=%s%s">',
60                     $cfg['home'], $zlist['redirect']);
61
62   $ret .= '</head>';
63
64   if (javascript_ok()) {
65     $ret .= sprintf('<script type="text/javascript" src="%szlist.js"></script>', $cfg['basepath']);
66     $ret .= sprintf('<script type="text/javascript">var zlist_urlbase = "%s";</script>', $cfg['basepath']);
67   }
68
69   $ret .= '<body>';
70   $ret .= '<div class="banner"><h1 class="none"><a href="http://www.debian.org/">Zeitungen online im Netz</a></h1></div>';
71
72   $ret .= '<div class="status">';
73
74   $ret .= '<div class="homestatus"><a href="'.$cfg['home'].'">Home</a>';
75   if ($cfg['path'] != 'contact.html')
76     $ret .= sprintf('&nbsp;&nbsp;&nbsp;<a href="%scontact.html">Kontakt</a>', $cfg['basepath']);
77   if ($cfg['path'] != 'datenschutz.html')
78     $ret .= sprintf('&nbsp;&nbsp;&nbsp;<a href="%sdatenschutz.html">Datenschutz</a>', $cfg['basepath']);
79   if (is_admin() && $cfg['path'] != 'admin.html')
80     $ret .= sprintf('&nbsp;&nbsp;&nbsp;<a href="%sadmin/index.html">Admin</a>', $cfg['basepath']);
81   if (is_spider())
82     $ret .= sprintf('&nbsp;&nbsp;&nbsp;<a href="%ssitemap.html">Sitemap</a>', $cfg['basepath']);
83   $ret .= '</div>';
84
85   if (logged_in()) {
86     if ($cfg['path'] != "logout.html") {
87       $ret .= '<div class="logstatus">';
88       if ($cfg['path'] != "options.html")
89         $ret .= sprintf('<a href="%soptions.html">Einstellungen</a>&nbsp;&nbsp;&nbsp;',
90                         $cfg['basepath']);
91       $ret .= sprintf('<a href="%slogout.html">Abmelden</a>',
92                       $cfg['basepath']);
93       $ret .= '</div>';
94     }
95   } else {
96     if (($cfg['path'] != "login.html" && $cfg['path'] != "activate.html") ||
97         ($cfg['path'] == 'login.html' && isset($_POST['sendnew'])))
98       $ret .= sprintf('<div class="logstatus"><a href="%slogin.html">Anmelden</a></div>',
99                       $cfg['basepath']);
100   }
101   $ret .= sprintf('<div class="userstatus">%s</div>', userstatus());
102   $ret .= '</div>';
103
104   $ret .= '<div class="page">';
105   if ($_SERVER['SERVER_NAME'] == 'www.zeitungsliste.de' && javascript_ok())
106     $ret .= "\n" . load_template('addsense.js');
107
108   return $ret;
109 }
110
111 function layout_page($body)
112 {
113   global $zlist;
114
115   $ret = '<div class="info">';
116   if (is_array($zlist['info'])) {
117     include_once('info.inc');
118     foreach ($zlist['info'] as $func)
119       $ret .= $func();
120   }
121
122   $ret .= '</div>';
123
124   $ret .= '<div class="main">';
125   $ret .= $body;
126   $ret .= '</div>';
127   return $ret;
128 }
129
130 function layout_bookmarks($rel, $title)
131 {
132   global $cfg;
133
134   // Mehr auf http://www.bikeshops.de/Bikeshops/BikeGuide/BikeGuideWertgarantie.asp
135   $bookmarks = array(
136                      array('text' => 'Delicious',
137                            'icon' => 'link_delicious.gif',
138                            'link' => 'http://del.icio.us/post?v=4&amp;noui&amp;url=@url@&amp;title=@title@'),
139                      array('text' => 'Digg it',
140                            'icon' => 'link_digg.gif',
141                            'link' => 'http://digg.com/submit?phase=2&amp;url=@url@&amp;title=@title@'),
142                      array('text' => 'folk it',
143                            'icon' => 'link_folkd.gif',
144                            'link' => 'http://www.folkd.com/submit/@url@'),
145                      array('text' => 'Reddit',
146                            'icon' => 'link_reddit.gif',
147                            'link' => 'http://reddit.com/submit?url=@url@&title=@title@'),
148                      array('text' => 'Spurl',
149                            'icon' => 'link_spurl.gif',
150                            'link' => 'http://www.spurl.net/spurl.php?url=@url@&title=@title@'),
151                      array('text' => 'StumbleUpon',
152                            'icon' => 'link_stumbleupon.gif',
153                            'link' => 'http://www.stumbleupon.com/submit?url=@url@&amp;title=@title@'),
154                      array('text' => 'linksilo.de',
155                            'icon' => 'link_linksilo.gif',
156                            'link' => 'http://www.linksilo.de/index.php?area=bookmarks&amp;func=bookmark_new&amp;addurl=@url@&amp;addtitle=@title@'),
157                      );
158
159   $url = $cfg['home'] . $rel;
160
161   $ret = '<div class="social_bookmarks">Lesezeichen: ';
162
163   foreach ($bookmarks as $bm) {
164     $ret .= sprintf('<a href="%s" title="%s"><img src="%sbookmarks/%s" width="16" height="16" alt="%s" name="%s" border="0"></a>',
165                     str_replace(array('@url@', '@title@'),
166                                 array(htmlspecialchars($url), htmlspecialchars($title)),
167                                 $bm['link']),
168                     $bm['text'],
169                     $cfg['basepath'], $bm['icon'], $bm['text'], $bm['text']);
170   }
171
172   $ret .= '</div>';
173
174   return $ret;
175 }
176
177 /*
178  * Add links to the main page for web spider so that they get the entire database
179  */
180 function layout_sitemap()
181 {
182   global $cfg;
183
184   if (!is_spider())
185     header('Location: ' . $cfg['home']);
186
187   $ret = '<h1>Sitemap der Zeitungsliste</h1>';
188
189   $query = 'SELECT tagname FROM tags ORDER BY lower(tagname)';
190
191   $sth = db_query($query);
192
193   if ($sth !== false && pg_num_rows($sth) > 0) {
194     $ret .= '<h3>User-Tags (Merkmale)</h3>';
195     $ret .= '<ul class="gold">';
196
197     for ($i=0; $i < pg_num_rows($sth); $i++) {
198       $row = pg_fetch_array($sth, $i);
199
200       $ret .= sprintf('<li><a href="%stag/%s.html">%s</a></li>',
201                       $cfg['basepath'], urlencode($row['tagname']),
202                       $row['tagname']);
203     }
204
205     $ret .= '</ul>';
206   }
207
208   $query = 'SELECT id,name,city FROM zeitungen WHERE deleted IS false ORDER BY name';
209
210   $sth = db_query($query);
211
212   if ($sth !== false && pg_num_rows($sth) > 0) {
213     $ret .= '<h3>Zeitungen und Magazine</h3>';
214     $ret .= '<ul class="gold">';
215     for ($i=0; $i < pg_num_rows($sth); $i++) {
216       $row = pg_fetch_array($sth, $i);
217
218       $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a>, %s</li>',
219                       $cfg['basepath'], $row['id'], $row['name'], $row['city']);
220     }
221     $ret .= '</ul>';
222   }
223
224   $query = 'SELECT id,topic FROM topics ORDER BY created';
225
226   $sth = db_query($query);
227
228   if ($sth !== false && pg_num_rows($sth) > 0) {
229     $ret .= '<h3>Diskussionen</h3>';
230     $ret .= '<ul class="gold">';
231     for ($i=0; $i < pg_num_rows($sth); $i++) {
232       $row = pg_fetch_array($sth, $i);
233
234       $ret .= sprintf('<li><a href="%stopic/%d.html">%s</a></li>',
235                       $cfg['basepath'], $row['id'], $row['topic']);
236     }
237     $ret .= '</ul>';
238   }
239
240   return $ret;
241 }
242
243 function layout_showpaper($archived=false)
244 {
245   global $zlist;
246
247   if (!isset($_GET['zeitung']) || !is_numeric($_GET['zeitung']))
248     $ret = warning('Keine Zeitung oder Magazin gefunden.');
249   else {
250     $zid = $_GET['zeitung'];
251     $details = format_newspaper($zid, true);
252     if ($details === false)
253       $ret .= warning('Keine Zeitung oder Magazin gefunden.');
254     else {
255       $zlist['zid'] = $zid;
256       $ret .= $details;
257       if (!$archived) {
258         hits_inc ($zid);
259         $ret .= format_board($zid);
260       } else {
261         $ret .= format_board($zid, $archived);
262       }
263       $ret .= layout_bookmarks(sprintf('zeitung/%d.html', $zid), $zlist['newspaper']);
264     }
265   }
266
267   return $ret;
268 }
269
270 function layout_archive()
271 {
272   global $zlist;
273   global $cfg;
274
275   if (!isset($_GET['archiv']) || !is_numeric($_GET['archiv']))
276     $ret = warning('Keine Zeitung oder Magazin gefunden.');
277   else {
278     $zid = $_GET['archiv'];
279     $details = format_newspaper($zid, true);
280     if ($details === false)
281       $ret .= warning('Keine Zeitung oder Magazin gefunden.');
282     else {
283       $zlist['zid'] = $zid;
284       $ret .= $details;
285
286       $query = sprintf('SELECT id,topic FROM topics ' .
287                        'WHERE zeitung = %d ORDER BY created DESC',
288                        $_GET['archiv']);
289
290       $sth = db_query($query);
291
292       if (!$sth || pg_num_rows ($sth) == 0)
293         $ret .= warning('Kein Archiv gefunden.');
294       else {
295         $ret .= '<p><ul class="gold">';
296         for ($i=0; $i < pg_num_rows ($sth); $i++) {
297           $row = pg_fetch_array($sth, $i);
298           $ret .= sprintf('<li><a href="%stopic/%d.html">%s</a></li>',
299                           $cfg['basepath'], $row['id'], $row['topic']);
300         }
301         $ret .= '</ul></p>';
302       }
303     }
304   }
305
306   return $ret;
307 }
308
309 function layout_showtag()
310 {
311   global $cfg;
312   global $zlist;
313
314   if (!isset($_GET['tag']))
315     $ret = warning('Keine derartiges Merkmal gefunden.');
316   else {
317     $tagname = $_GET['tag'];
318     $ret .= '<h3>Merkmal <span class="tag">' . $tagname . '</span></h3>';
319
320     $query = sprintf("SELECT zeitungen.id,name,count(uid) AS count FROM zeitungen " .
321                      "JOIN zeitung_tags ON zeitung = id " .
322                      "JOIN tags ON tag = tags.id " .
323                      "WHERE tagname = '%s' " .
324                      "GROUP BY zeitungen.id,name ORDER BY count DESC",
325                      pg_escape_string($tagname));
326
327     $sth = db_query($query);
328
329     $zlist['tag'] = htmlspecialchars($tagname);
330     if (!$sth || pg_num_rows ($sth) == 0) {
331       $ret .= warning('Keine Zeitungen oder Magazine mit diesem Merkmal gefunden.');
332       unset($zlist['newspaper']);
333     } else {
334       $headlines = array('Mäßige','Mittelmäßige','Gute','Häufige','Häufigste');
335       $oldtag = -1;
336
337       for ($i=0; $i < pg_num_rows ($sth); $i++) {
338         $row = pg_fetch_array ($sth, $i);
339         $tag = tag_class($row['count']);
340
341         if ($oldtag != $tag) {
342           if ($oldtag != -1)
343             $ret .= '</ul>';
344           $ret .= sprintf('<h3 class="tag%d">%s Bewertungen</h3>', $tag, $headlines[$tag]);
345           $ret .= '<ul class="gold">';
346           $oldtag = $tag;       
347         }
348
349         $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
350                         $cfg['basepath'], $row['id'], $row['name'], $row['city']);
351       }
352       $ret .= '</ul>';
353
354       $ret .= layout_bookmarks(sprintf('tag/%s.html', htmlspecialchars($tagname)), 'Merkmal '.$tagname);
355     }
356   }
357
358   return $ret;
359 }
360
361 function layout_topic()
362 {
363   global $zlist;
364
365   if  (!isset($_GET['topic']) || !is_numeric($_GET['topic']))
366     $ret = warning('Keine passende Diskussion gefunden.');
367   else {
368     $discussion = format_topic($_GET['topic']);
369
370     if (isset($zlist['zid'])) {
371       $ret .= format_newspaper($zlist['zid'], true);
372
373       if ($zlist['archived'])
374         $ret .= '<h3>Abgeschlossene Diskussion</h3>';
375       else
376         $ret .= '<h3>Diskussion</h3>';
377     }
378     $ret .= $discussion;
379     if (isset($zlist['zid']))
380       $ret .= layout_bookmarks(sprintf('topic/%d.html', $zlist['zid']), $zlist['topic']);
381   }
382
383   return $ret;
384 }
385
386 function notfound()
387 {
388   header("HTTP/1.0 404 Not Found");
389
390   return warning('Diese Seite existiert nicht!');
391 }
392
393 function contact_send($topic, $email, $body)
394 {
395   global $cfg;
396
397   $header = array();
398   if (!empty($email)) {
399     if (isset($_SESSION['uid']))
400       $header[] = sprintf('Reply-To: %s <%s>',
401                           strlen($_SESSION['realname'])?$_SESSION['realname']:$_SESSION['nickname'],
402                           $email);
403     else
404       $header[] = 'Reply-To: ' . $email;
405   }
406
407   $body .= "\n\n"
408     ."HTTP_USER_AGENT: " . $_SERVER['HTTP_USER_AGENT'] . "\n"
409     ."REMOTE_ADDR    : " . $_SERVER['REMOTE_ADDR'] . "\n";
410
411   if (isset($_SESSION['uid']))
412     $body .= "Nickname       : " . $_SESSION['nickname'] . "\n";
413
414   $subject = str_replace(array('<', '>', '(', ')', '$', '/', '%', '\\', '#', ';', '&'), '', $topic);
415
416   sendmail($cfg['mailto'], '', $subject, $body, $header);
417 }
418
419 function process_contact()
420 {
421   if ($_SERVER['REQUEST_METHOD'] == 'POST') {
422     if (empty($_POST['topic']))
423       return warning('Sie haben keinen Titel für die Nachricht angegeben!');
424     elseif (empty($_POST['body']))
425       return warning('Sie haben keinen Text der Nachricht angegeben!');
426     elseif (!empty($_POST['email']) && !is_valid_email_address($_POST['email']))
427       return warning('Die angegebene Mail-Adresse ist ungültig.');
428     elseif (intval($_POST['pivot']) != intval(date('m')))
429       return warning('Die Testfrage ist falsch beantwortet.');
430     else {
431       contact_send($_POST['topic'], $_POST['email'], $_POST['body']);
432       $ret = information('Die Nachricht wurde an den Chef geschickt.');
433       $ret .= '<p>Die Bearbeitung kann eine Weile dauern.  Wenn Sie eine '.
434         'Antwort erwarten, sollte diese in den nächsten Tagen an die von '.
435         'Ihnen angegebene Adresse geschickt werden.</p>';
436       return $ret;
437     }
438     $replace = array('topic' => $_POST['topic'],
439                      'email' => $_POST['email'],
440                      'body' => $_POST['body']);
441   } elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
442     if (isset($_SESSION['email']))
443       $replace = array('email' => $_SESSION['email']);
444     else
445       $replace = array();
446   }
447
448   return load_javascript('contact.js') . load_template('contact.html', $replace);
449 }