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