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