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