Untypo
[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   global $_POST;
28   global $_SERVER;
29
30   $ret .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
31   $ret .= '<html lang="de">';
32   $ret .= '<head>';
33   if (isset($zlist['newspaper']))
34     $ret .= sprintf('<title>Zeitungsliste: %s</title>', $zlist['newspaper']);
35   elseif (isset($zlist['tag']))
36     $ret .= sprintf('<title>Zeitungsliste: Tag %s</title>', $zlist['tag']);
37   else
38     $ret .= '<title>Zeitungsliste</title>';
39   $ret .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
40   $ret .= '<meta name="Author" content="joey@infodrom.org (Joey Schulze)">';
41   $ret .= '<meta name="Language" content="de">';
42   
43   if ($zlist['page'] == 'index') {
44     $ret .= '<meta name="Keywords" content="Zeitung, Zeitungen, Liste, Zeitungsliste, Online-Zeitungen, Zeitungen im Web, Forum, Community, '.
45       'Liste aller Zeitungen">';
46     $ret .= sprintf('<link rel="alternate" type="application/rss+xml" title="Zeitungen" href="%szeitungen.rdf">', $cfg['basepath']);
47   } elseif ($cfg['dir'] == 'zeitung') {
48     $ret .= '<meta name="Keywords" content="Zeitung, Zeitungsliste, Online-Zeitung, Zeitung im Web, Forum, Community, '.
49       $zlist['newspaper'] . ', ' . $zlist['city'] . '">';
50   }
51
52   if (is_spider())
53     $ret .= '<meta name="Robots" content="index,follow">';
54   $ret .= '<meta name="Copyright" content="(c) 2008 Information & Consulting">';
55   $ret .= sprintf('<link href="%smain.css" rel="stylesheet" type="text/css">', $cfg['basepath']);
56   $ret .= sprintf('<link rel="icon" href="%sfavicon.ico" type="image/x-icon">', $cfg['basepath']);
57   $ret .= sprintf('<link rel="shortcut icon" href="%sfavicon.ico" type="image/x-icon">', $cfg['basepath']);
58
59   if (isset($zlist['redirect']))
60     $ret .= sprintf('<meta http-equiv="refresh" content="7; URL=%s%s">',
61                     $cfg['home'], $zlist['redirect']);
62
63   $ret .= '</head>';
64
65   if (javascript_ok()) {
66     $ret .= sprintf('<script type="text/javascript" src="%szlist.js"></script>', $cfg['basepath']);
67     $ret .= sprintf('<script type="text/javascript">var zlist_urlbase = "%s";</script>', $cfg['basepath']);
68   }
69
70   $ret .= '<body>';
71   $ret .= '<div class="banner"><h1 class="none"><a href="http://www.debian.org/">Zeitungen online im Netz</a></h1></div>';
72
73   $ret .= '<div class="status">';
74
75   $ret .= '<div class="homestatus"><a href="'.$cfg['home'].'">Home</a>';
76   if ($cfg['path'] != 'contact.html')
77     $ret .= sprintf('&nbsp;&nbsp;&nbsp;<a href="%scontact.html">Kontakt</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' => 'Mister Wong',
134                            'icon' => 'link_misterwong.gif',
135                            'link' => 'http://www.mister-wong.de/index.php?action=addurl&amp;bm_url=@url@&amp;bm_description=@title@'),
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' => 'Google Bookmarks',
140                            'icon' => 'link_google.gif',
141                            'link' => 'http://www.google.com/bookmarks/mark?op=add&amp;hl=de&amp;bkmk=@url@&amp;title=@title@'),
142                      array('text' => 'Yahoo Web',
143                            'icon' => 'link_yahoo.gif',
144                            'link' => 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=@url@&amp;t=@title@'),
145                      array('text' => 'Technorati',
146                            'icon' => 'link_technorati.gif',
147                            'link' => 'http://technorati.com/faves?add=@url@'),
148                      array('text' => 'Digg it',
149                            'icon' => 'link_digg.gif',
150                            'link' => 'http://digg.com/submit?phase=2&amp;url=@url@&amp;title=@title@'),
151                      array('text' => 'Yigg',
152                            'icon' => 'link_yigg.gif',
153                            'link' => 'http://yigg.de/neu?action=addurl&amp;exturl=@url@&amp;exttitle=@title@'),
154                      array('text' => 'Taggle',
155                            'icon' => 'link_taggle.gif',
156                            'link' => 'http://taggle.de/addLinkDetails?mAddress=@url@&amp;title=B@title@&amp;submitted=Weiter'),
157                      array('text' => 'Linkarena',
158                            'icon' => 'link_linkarena.gif',
159                            'link' => 'http://www.linkarena.com/linkadd.php?linkName=@title@&amp;linkURL=@url@'),
160                      array('text' => 'OneView',
161                            'icon' => 'link_oneview.gif',
162                            'link' => 'http://www.oneview.de/quickadd/neu/addBookmark.jsf?URL=@url@&amp;title=@title@'),
163                      array('text' => 'folk it',
164                            'icon' => 'link_folkd.gif',
165                            'link' => 'http://www.folkd.com/submit/@url@'),
166                      array('text' => 'Facebook',
167                            'icon' => 'link_facebook.gif',
168                            'link' => 'http://www.facebook.com/sharer.php?u=@url@&amp;title=@title@'),
169                      array('text' => 'Blinklist',
170                            'icon' => 'link_blinklist.gif',
171                            'link' => 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url=@url@&Description=@title@'),
172                      array('text' => 'Furl',
173                            'icon' => 'link_furl.gif',
174                            'link' => 'http://www.furl.net/storeIt.jsp?t=@title@&u=@url@'),
175                      array('text' => 'Reddit',
176                            'icon' => 'link_reddit.gif',
177                            'link' => 'http://reddit.com/submit?url=@url@&title=@title@'),
178                      array('text' => 'Spurl',
179                            'icon' => 'link_spurl.gif',
180                            'link' => 'http://www.spurl.net/spurl.php?url=@url@&title=@title@'),
181                      array('text' => 'Shadows',
182                            'icon' => 'link_shadows.gif',
183                            'link' => 'http://www.shadows.com/features/tcr.htm?url=@url@&title=@title@'),
184                      array('text' => 'newsvine',
185                            'icon' => 'link_newsvine.gif',
186                            'link' => 'http://www.newsvine.com/_wine/save?popoff=1&u=@url@&tags=&blurb=@title@'),
187                      array('text' => 'CXWeb',
188                            'icon' => 'link_cxweb.gif',
189                            'link' => 'http://www.cxweb.de/login/?action=add&amp;address=@url@&amp;title=@title@'),
190                      array('text' => 'Simpy',
191                            'icon' => 'link_simpy.gif',
192                            'link' => 'http://www.simpy.com/simpy/LinkAdd.do?title=@title@&amp;href=@url@'),
193                      array('text' => 'Ma.Gnolia',
194                            'icon' => 'link_magnolia.gif',
195                            'link' => 'http://ma.gnolia.com/bookmarklet/add?url=@url@&amp;title=@title@&amp;description=&amp;tags='),
196                      array('text' => 'StumbleUpon',
197                            'icon' => 'link_stumbleupon.gif',
198                            'link' => 'http://www.stumbleupon.com/submit?url=@url@&amp;title=@title@'),
199                      array('text' => 'linksilo.de',
200                            'icon' => 'link_linksilo.gif',
201                            'link' => 'http://www.linksilo.de/index.php?area=bookmarks&amp;func=bookmark_new&amp;addurl=@url@&amp;addtitle=@title@'),
202                      array('text' => 'bookmarks.cc',
203                            'icon' => 'link_bookmarkscc.gif',
204                            'link' => 'http://www.bookmarks.cc/bookmarken.php?action=neu&amp;url=@url@&amp;title=@title@'),
205                      );
206
207   $url = $cfg['home'] . $rel;
208
209   $ret = '<div class="social_bookmarks">Lesezeichen: ';
210
211   foreach ($bookmarks as $bm) {
212     $ret .= sprintf('<a href="%s" title="%s"><img src="%sbookmarks/%s" width="16" height="16" alt="%s" name="%s" border="0"></a>',
213                     str_replace(array('@url@', '@title@'),
214                                 array(htmlspecialchars($url), htmlspecialchars($title)),
215                                 $bm['link']),
216                     $bm['text'],
217                     $cfg['basepath'], $bm['icon'], $bm['text'], $bm['text']);
218   }
219
220   $ret .= '</div>';
221
222   return $ret;
223 }
224
225 /*
226  * Add links to the main page for web spider so that they get the entire database
227  */
228 function layout_sitemap()
229 {
230   global $_SESSION;
231   global $_SERVER;
232   global $cfg;
233
234   if (!is_spider())
235     header('Location: ' . $cfg['home']);
236
237   $ret = '<h1>Sitemap der Zeitungsliste</h1>';
238
239   $query = 'SELECT tagname FROM tags ORDER BY lower(tagname)';
240
241   $sth = db_query($query);
242
243   if ($sth !== false && pg_num_rows($sth) > 0) {
244     $ret .= '<h3>User-Tags (Merkmale)</h3>';
245     $ret .= '<ul class="gold">';
246
247     for ($i=0; $i < pg_num_rows($sth); $i++) {
248       $row = pg_fetch_array($sth, $i);
249
250       $ret .= sprintf('<li><a href="%stag/%s.html">%s</a></li>',
251                       $cfg['basepath'], urlencode($row['tagname']),
252                       $row['tagname']);
253     }
254
255     $ret .= '</ul>';
256   }
257
258   $query = 'SELECT id,name,city FROM zeitungen WHERE deleted IS false ORDER BY name';
259
260   $sth = db_query($query);
261
262   if ($sth !== false && pg_num_rows($sth) > 0) {
263     $ret .= '<h3>Zeitungen und Magazine</h3>';
264     $ret .= '<ul class="gold">';
265     for ($i=0; $i < pg_num_rows($sth); $i++) {
266       $row = pg_fetch_array($sth, $i);
267
268       $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a>, %s</li>',
269                       $cfg['basepath'], $row['id'], $row['name'], $row['city']);
270     }
271     $ret .= '</ul>';
272   }
273
274   $query = 'SELECT id,topic FROM topics ORDER BY created';
275
276   $sth = db_query($query);
277
278   if ($sth !== false && pg_num_rows($sth) > 0) {
279     $ret .= '<h3>Diskussionen</h3>';
280     $ret .= '<ul class="gold">';
281     for ($i=0; $i < pg_num_rows($sth); $i++) {
282       $row = pg_fetch_array($sth, $i);
283
284       $ret .= sprintf('<li><a href="%stopic/%d.html">%s</a></li>',
285                       $cfg['basepath'], $row['id'], $row['topic']);
286     }
287     $ret .= '</ul>';
288   }
289
290   return $ret;
291 }
292
293 function layout_showpaper($archived=false)
294 {
295   global $_GET;
296   global $zlist;
297
298   if (!isset($_GET['zeitung']) || !is_numeric($_GET['zeitung']))
299     $ret = warning('Keine Zeitung oder Magazin gefunden.');
300   else {
301     $zid = $_GET['zeitung'];
302     $details = format_newspaper($zid, true);
303     if ($details === false)
304       $ret .= warning('Keine Zeitung oder Magazin gefunden.');
305     else {
306       $zlist['zid'] = $zid;
307       $ret .= $details;
308       if (!$archived) {
309         hits_inc ($zid);
310         $ret .= format_board($zid);
311       } else {
312         $ret .= format_board($zid, $archived);
313       }
314       $ret .= layout_bookmarks(sprintf('zeitung/%d.html', $zid), $zlist['newspaper']);
315     }
316   }
317
318   return $ret;
319 }
320
321 function layout_archive()
322 {
323   global $zlist;
324   global $_GET;
325   global $cfg;
326
327   if (!isset($_GET['archiv']) || !is_numeric($_GET['archiv']))
328     $ret = warning('Keine Zeitung oder Magazin gefunden.');
329   else {
330     $zid = $_GET['archiv'];
331     $details = format_newspaper($zid, true);
332     if ($details === false)
333       $ret .= warning('Keine Zeitung oder Magazin gefunden.');
334     else {
335       $zlist['zid'] = $zid;
336       $ret .= $details;
337
338       $query = sprintf('SELECT id,topic FROM topics ' .
339                        'WHERE zeitung = %d ORDER BY created DESC',
340                        $_GET['archiv']);
341
342       $sth = db_query($query);
343
344       if (!$sth || pg_num_rows ($sth) == 0)
345         $ret .= warning('Kein Archiv gefunden.');
346       else {
347         $ret .= '<p><ul class="gold">';
348         for ($i=0; $i < pg_num_rows ($sth); $i++) {
349           $row = pg_fetch_array($sth, $i);
350           $ret .= sprintf('<li><a href="%stopic/%d.html">%s</a></li>',
351                           $cfg['basepath'], $row['id'], $row['topic']);
352         }
353         $ret .= '</ul></p>';
354       }
355     }
356   }
357
358   return $ret;
359 }
360
361 function layout_showtag()
362 {
363   global $cfg;
364   global $zlist;
365   global $_GET;
366
367   if (!isset($_GET['tag']))
368     $ret = warning('Keine derartiges Merkmal gefunden.');
369   else {
370     $tagname = $_GET['tag'];
371     $ret .= '<h3>Merkmal <span class="tag">' . $tagname . '</span></h3>';
372
373     $query = sprintf("SELECT zeitungen.id,name,count(uid) AS count FROM zeitungen " .
374                      "JOIN zeitung_tags ON zeitung = id " .
375                      "JOIN tags ON tag = tags.id " .
376                      "WHERE tagname = '%s' " .
377                      "GROUP BY zeitungen.id,name ORDER BY count DESC",
378                      pg_escape_string($tagname));
379
380     $sth = db_query($query);
381
382     $zlist['tag'] = htmlspecialchars($tagname);
383     if (!$sth || pg_num_rows ($sth) == 0) {
384       $ret .= warning('Keine Zeitungen oder Magazine mit diesem Merkmal gefunden.');
385       unset($zlist['newspaper']);
386     } else {
387       $headlines = array('Mäßige','Mittelmäßige','Gute','Häufige','Häufigste');
388       $oldtag = -1;
389
390       for ($i=0; $i < pg_num_rows ($sth); $i++) {
391         $row = pg_fetch_array ($sth, $i);
392         $tag = tag_class($row['count']);
393
394         if ($oldtag != $tag) {
395           if ($oldtag != -1)
396             $ret .= '</ul>';
397           $ret .= sprintf('<h3 class="tag%d">%s Bewertungen</h3>', $tag, $headlines[$tag]);
398           $ret .= '<ul class="gold">';
399           $oldtag = $tag;       
400         }
401
402         $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
403                         $cfg['basepath'], $row['id'], $row['name'], $row['city']);
404       }
405       $ret .= '</ul>';
406
407       $ret .= layout_bookmarks(sprintf('tag/%s.html', htmlspecialchars($tagname)), 'Merkmal '.$tagname);
408     }
409   }
410
411   return $ret;
412 }
413
414 function layout_topic()
415 {
416   global $zlist;
417   global $_GET;
418
419   if  (!isset($_GET['topic']) || !is_numeric($_GET['topic']))
420     $ret = warning('Keine passende Diskussion gefunden.');
421   else {
422     $discussion = format_topic($_GET['topic']);
423
424     if (isset($zlist['zid'])) {
425       $ret .= format_newspaper($zlist['zid'], true);
426
427       if ($zlist['archived'])
428         $ret .= '<h3>Abgeschlossene Diskussion</h3>';
429       else
430         $ret .= '<h3>Diskussion</h3>';
431     }
432     $ret .= $discussion;
433     if (isset($zlist['zid']))
434       $ret .= layout_bookmarks(sprintf('topic/%d.html', $zlist['zid']), $zlist['topic']);
435   }
436
437   return $ret;
438 }
439
440 function notfound()
441 {
442   header("HTTP/1.0 404 Not Found");
443
444   return warning('Diese Seite existiert nicht!');
445 }
446
447 function contact_send($topic, $email, $body)
448 {
449   global $cfg;
450   global $_SESSION;
451   global $_SERVER;
452
453   $header = array();
454   if (!empty($email)) {
455     if (isset($_SESSION['uid']))
456       $header[] = sprintf('Reply-To: %s <%s>',
457                           strlen($_SESSION['realname'])?$_SESSION['realname']:$_SESSION['nickname'],
458                           $email);
459     else
460       $header[] = 'Reply-To: ' . $email;
461   }
462
463   $body .= "\n\n"
464     ."HTTP_USER_AGENT: " . $_SERVER['HTTP_USER_AGENT'] . "\n"
465     ."REMOTE_ADDR    : " . $_SERVER['REMOTE_ADDR'] . "\n";
466
467   if (isset($_SESSION['uid']))
468     $body .= "Nickname       : " . $_SESSION['nickname'] . "\n";
469
470   $subject = str_replace(array('<', '>', '(', ')', '$', '/', '%', '\\', '#', ';', '&'), '', $topic);
471
472   sendmail($cfg['mailto'], '', $subject, $body, $header);
473 }
474
475 function process_contact()
476 {
477   global $_SERVER;
478   global $_POST;
479
480   if ($_SERVER['REQUEST_METHOD'] == 'POST') {
481     if (empty($_POST['topic']))
482       $ret = warning('Sie haben keinen Titel für die Nachricht angegeben!');
483     elseif (empty($_POST['body']))
484       $ret = warning('Sie haben keinen Text der Nachricht angegeben!');
485     elseif (!empty($_POST['email']) && !is_valid_email_address($_POST['email']))
486       $ret = warning('Die angegebene Mail-Adresse ist ungültig.');
487     else {
488       contact_send($_POST['topic'], $_POST['email'], $_POST['body']);
489       $ret = information('Die Nachricht wurde an den Chef geschickt.');
490       $ret .= '<p>Die Bearbeitung kann eine Weile dauern.  Wenn Sie eine '.
491         'Antwort erwarten, sollte diese in den nächsten Tagen an die von '.
492         'Ihnen angegebene Adresse geschickt werden.</p>';
493       return $ret;
494     }
495     $replace = array('topic' => $_POST['topic'],
496                      'email' => $_POST['email'],
497                      'body' => $_POST['body']);
498   } elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
499     if (isset($_SESSION['email']))
500       $replace = array('email' => $_SESSION['email']);
501     else
502       $replace = array();
503   }
504
505   return load_javascript('contact.js') . load_template('contact.html', $replace);
506 }
507
508 ?>