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