Untypo
[infodrom.org/www.zeitungsliste.de] / lib / info.inc
1 <?php
2
3 function info_searchform()
4 {
5   global $cfg;
6   global $zlist;
7
8   $replace = array('basepath' => $cfg['basepath'],
9                    'keyword' => $zlist['keyword']);
10
11   return load_javascript('searchform.js') . load_template('searchform.html', $replace);
12 }
13
14 function info_new()
15 {
16   global $cfg;
17
18   if ($cfg['path'] == 'reply.html' ||
19       $cfg['path'] == 'topic.html' ||
20       $cfg['path'] == 'new.html' ||
21       $cfg['dir'] == 'zeitung')
22     return;
23
24   $query = "SELECT name,id FROM zeitungen " .
25            "WHERE changed > now() - interval '3 months' AND deleted IS false " .
26            "ORDER BY changed DESC limit 10";
27
28   $sth = db_query($query);
29
30   if (pg_num_rows ($sth) == 0)
31     return;
32
33   $ret = '<h3>Neu aufgenommen</h3>';
34   $ret .= '<p><ul>';
35   for ($n=0; $n < pg_num_rows ($sth); $n++) {
36     $row = pg_fetch_array ($sth, $n);
37     $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
38                     $cfg['basepath'], $row['id'], $row['name']);
39   }
40   $ret .= '</ul></p>';
41
42   return $ret;
43 }
44
45 function info_topten()
46 {
47   global $cfg;
48
49   $query = "SELECT zeitung,name,sum(counter) as counter FROM hits " .
50            "INNER JOIN zeitungen ON id = zeitung " .
51            "WHERE deleted IS false " .
52            "GROUP BY zeitung,name ORDER BY counter DESC LIMIT 10";
53
54   $sth = db_query($query) or carp("info_topten");
55
56   if (pg_num_rows ($sth) == 0)
57     return;
58
59   $ret = '<h3>Top 10</h3>';
60   $ret .= '<p><ul>';
61   for ($n=0; $n < pg_num_rows ($sth); $n++) {
62     $row = pg_fetch_array ($sth, $n);
63     $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
64                     $cfg['basepath'], $row['zeitung'], $row['name']);
65   }
66   $ret .= '</ul></p>';
67
68   return $ret;
69 }
70
71 function info_hitlist()
72 {
73   global $cfg;
74   global $_SESSION;
75
76   if (!isset($_SESSION['uid']))
77     return info_topten();
78
79   $query = sprintf("SELECT zeitung,name,counter FROM hits " .
80                    "INNER JOIN zeitungen ON id = zeitung " .
81                    "WHERE deleted IS false AND uid = %d " .
82                    "ORDER BY counter DESC LIMIT 10", $_SESSION['uid']);
83
84   $sth = db_query($query) or carp("info_topten");
85
86   if (pg_num_rows ($sth) == 0)
87     return info_topten();
88
89   $ret = '<h3>Favoriten</h3>';
90   $ret .= '<p><ul>';
91   for ($n=0; $n < pg_num_rows ($sth); $n++) {
92     $row = pg_fetch_array ($sth, $n);
93     $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
94                     $cfg['basepath'], $row['zeitung'], $row['name']);
95   }
96   $ret .= '</ul></p>';
97
98   return $ret;
99 }
100
101 function info_tags()
102 {
103   global $cfg;
104   global $zlist;
105
106   if (!isset($zlist['zid']))
107     return;
108
109   $query = sprintf("SELECT id,tagname,count(uid) AS count " .
110                    "FROM tags JOIN zeitung_tags ON tag = id " .
111                    "WHERE zeitung = %d GROUP BY id,tagname " .
112                    "ORDER BY lower(tagname)",
113                    $zlist['zid']);
114
115   $sth = db_query($query);
116
117   if (pg_num_rows ($sth) == 0)
118     return;
119
120   $ret = '<h3>Tags</h3>';
121   $ret .= '<p class="tagcloud">';
122   for ($n=0; $n < pg_num_rows ($sth); $n++) {
123     $row = pg_fetch_array ($sth, $n);
124
125     $ret .= sprintf('<span class="tag%d"><a href="%stag/%s.html">%s</a></span> ',
126                     tag_class($row['count']), $cfg['basepath'],
127                     urlencode($row['tagname']), $row['tagname']);
128   }
129   $ret .= '</p>';
130
131   return $ret;
132 }
133
134 function info_tagcloud()
135 {
136   global $cfg;
137   global $zlist;
138   global $_SESSION;
139
140   if (!isset($zlist['zid']))
141     return;
142
143   if (!is_numeric($_SESSION['uid']))
144     return;
145
146   $query = sprintf("SELECT id,tagname FROM tags " .
147                    "JOIN zeitung_tags ON tag = id " .
148                    "WHERE zeitung = %d AND uid = %d " .
149                    "ORDER BY lower(tagname)",
150                    $zlist['zid'], $_SESSION['uid']);
151
152   $sth = db_query($query);
153
154   if (pg_num_rows ($sth) == 0)
155     return info_tags();
156
157   $ret = '<h3>Persönliche Tags</h3>';
158   $ret .= '<p class="tagcloud">';
159   for ($n=0; $n < pg_num_rows ($sth); $n++) {
160     $row = pg_fetch_array ($sth, $n);
161
162     $ret .= sprintf('<span class="tag0"><a href="%stag/%s.html">%s</a></span> ',
163                     $cfg['basepath'],
164                     $row['tagname'], $row['tagname']);
165   }
166   $ret .= '</p>';
167
168   return $ret;
169 }
170
171 function info_archive($zid)
172 {
173   global $cfg;
174
175   $query = sprintf('SELECT count(*) FROM topics '.
176                    'WHERE zeitung = %d AND archived IS true',
177                    $zid);
178
179   $sth = db_query($query);
180
181   $row = pg_fetch_array($sth, 0);
182
183   if ($row[0] > 0)
184     return sprintf('<img src="%sarchive.gif" width="27" height="20" alt="">&nbsp;' .
185                    '<a href="%sarchiv/%d.html"><strong>Archiv</strong></a>',
186                    $cfg['basepath'], $cfg['basepath'], $zid);
187
188     return false;
189 }
190
191 function info_actions()
192 {
193   global $cfg;
194   global $zlist;
195   global $_SESSION;
196
197   $title = array('edit' => 'Stammdaten dieser Zeitung bearbeiten',
198                  'tags' => 'Persönliche Tags zur Zeitung hinzufügen oder löschen',
199                  'add' => 'Neue Zeitung oder Magazin aufnehmen',
200                  'newtopic' => 'Neue Diskussion zu dieser Zeitung beginnen',
201                  'bookmark' => 'Lesezeichen zu dieser Zeitung setzen',
202                  'bookmarks' => 'Persönliche Lesezeichen verwalten',
203                  );
204
205   $actions = array();
206   $ret = '';
207
208   if (isset($_SESSION['uid']) && $cfg['path'] == 'options.html')
209     $actions[] = sprintf('<img src="%spasswd.gif" width="27" height="23" alt="">&nbsp;' .
210                          '<a href="%spasswd.html"><strong>Passwort ändern</strong></a>',
211                          $cfg['basepath'], $cfg['basepath']);
212
213   if (($cfg['dir'] == 'zeitung' || $cfg['dir'] == 'archiv' || $cfg['dir'] == 'topic' ) &&
214       isset($zlist['zid'])) {
215     if (isset($_SESSION['uid']))
216       $actions[] = sprintf('<img src="%stag.gif" width="27" height="25" alt="">&nbsp;' .
217                            '<a href="%stags.html?zeitung=%d" title="%s"><strong>Tags verwalten</strong></a>',
218                            $cfg['basepath'], $cfg['basepath'], $zlist['zid'],
219                            $title['tags']);
220     else
221       $actions[] = sprintf('<img src="%stag.gif" width="27" height="25" alt="">&nbsp;' .
222                            '<a href="%slogin.html?from=tags" title="%s"><strong>Tags verwalten</strong></a>',
223                            $cfg['basepath'], $cfg['basepath'], $title['tags']);
224   }
225
226   if ($cfg['dir'] == 'zeitung' && isset($_SESSION['uid'])) {
227     if (javascript_ok()) {
228       
229       $ret .= load_javascript('bookmarks.js');
230       $link = sprintf('href="%sbookmark.html" onclick="return bookmark_action(\'add\',%d);"',
231                       $cfg['basepath'], $zlist['zid']);
232     } else
233       $link = sprintf('href="%sbookmark.html?zeitung=%d"', $cfg['basepath'], $zlist['zid']);
234
235     $actions[] = sprintf('<img src="%sadd.gif" width="27" height="24" alt="">&nbsp;' .
236                          '<a %s title="%s"><strong>Lesezeichen setzen</strong></a>',
237                          $cfg['basepath'], $link,
238                          $title['bookmark']);
239   }
240
241   if ($cfg['path'] == 'options.html' && isset($_SESSION['uid']))
242     $actions[] = sprintf('<img src="%sbookmarks.gif" width="27" height="21" alt="">&nbsp;' .
243                          '<a href="%sbookmark.html" title="%s"><strong>Lesezeichen verwalten</strong></a>',
244                          $cfg['basepath'], $cfg['basepath'],
245                          $title['bookmarks']);
246
247   if ($cfg['dir'] == 'zeitung' && isset($zlist['zid'])) {
248     if (isset($_SESSION['uid']))
249       $actions[] = sprintf('<img src="%sedit.gif" width="27" height="26" alt="">&nbsp;' .
250                            '<a href="%sedit.html?zeitung=%d" title="%s"><strong>Bearbeiten</strong></a>',
251                            $cfg['basepath'], $cfg['basepath'], $zlist['zid'],
252                            $title['edit']);
253     else
254       $actions[] = sprintf('<img src="%sedit.gif" width="27" height="26" alt="">&nbsp;' .
255                            '<a href="%slogin.html?from=edit" title="%s"><strong>Bearbeiten</strong></a>',
256                            $cfg['basepath'], $cfg['basepath'],
257                            $title['edit']);
258   }
259
260   if ($zlist['page'] == 'index' ||
261       $cfg['dir'] == 'zeitung' ||
262       $cfg['dir'] == 'tag') {
263     if (isset($_SESSION['uid']))
264       $actions[] = sprintf('<img src="%snewspaper.gif" width="27" height="25" alt="">&nbsp;' .
265                            '<a href="%snew.html" title="%s"><strong>Neue Zeitung</strong></a>',
266                            $cfg['basepath'], $cfg['basepath'], $title['add']);
267     else
268       $actions[] = sprintf('<img src="%snewspaper.gif" width="27" height="25" alt="">&nbsp;' .
269                            '<a href="%slogin.html?from=new" title="%s"><strong>Neue Zeitung</strong></a>',
270                            $cfg['basepath'], $cfg['basepath'], $title['add']);
271   }
272
273   if ($zlist['notopic'] === true)
274     $text = 'Diskussion';
275   else
276     $text = 'Neues Thema';
277
278   if (($cfg['dir'] == 'zeitung' || $cfg['dir'] == 'archiv') && isset($zlist['zid'])) {
279     if (isset($_SESSION['uid']))
280       $actions[] = sprintf('<img src="%snewtopic.gif" width="27" height="20" alt="">&nbsp;' .
281                            '<a href="%stopic.html?zeitung=%d" title="%s"><strong>%s</strong></a>',
282                            $cfg['basepath'], $cfg['basepath'], $zlist['zid'],
283                            $title['newtopic'], $text);
284     else
285       $actions[] = sprintf('<img src="%snewtopic.gif" width="27" height="20" alt="">&nbsp;' .
286                            '<a href="%slogin.html?from=zeitung" title="%s"><strong>%s</strong></a>',
287                            $cfg['basepath'], $cfg['basepath'], $title['newtopic'], $text);
288   }
289
290   if ($cfg['dir'] == 'zeitung' && isset($zlist['zid'])) {
291     $try = info_archive($zlist['zid']);
292     if ($try !== false)
293       $actions[] = $try;
294   }
295
296   if ($actions) {
297     $ret .= '<p><ul class="action">';
298     foreach ($actions as $row)
299       $ret .= '<li>' . $row . '</li>';
300     $ret .= '</ul></p>';
301   }
302
303   return $ret;
304 }
305
306 function info_bookmarks()
307 {
308   global $cfg;
309   global $_SESSION;
310
311   if (!isset($_SESSION['uid']))
312     return;
313
314   if ($cfg['path'] == 'bookmark.html')
315     return;
316
317   $try = format_info_bookmarks();
318
319   if ($try === false)
320     return;
321
322   $ret = '<h3>Lesezeichen</h3>';
323   $ret .= '<div id="bookmarks">';
324   $ret .= $try;
325   $ret .= '</div>';
326
327   return $ret;
328 }
329
330
331 ?>