7 $dsn = "dbname=".$cfg['dbname'];
8 if (isset($cfg['dbhost'])) $dsn .= " host=".$cfg['dbhost'];
9 if (isset($cfg['dbport'])) $dsn .= " port=".$cfg['dbport'];
10 if (isset($cfg['dbuser'])) $dsn .= " user=".$cfg['dbuser'];
11 if (isset($cfg['dbpass'])) $dsn .= " password=".$cfg['dbpass'];
13 $dbh = pg_pconnect ($dsn)
14 or carp("Unable to connect to SQL server");
15 pg_exec ($dbh, "SET DateStyle='ISO'");
20 function db_query($query)
25 $sth = pg_exec ($cfg['dbh'], $query);
29 error_log (pg_last_error($cfg['dbh']));
36 function db_last_id($table, $column)
38 $query = sprintf ("SELECT currval('%s_%s_seq')", $table, $column);
40 $sth = db_query ($query);
45 if (pg_num_rows($sth) == 0) {
46 error_log ("$query resulted in an empty set");
50 $row = pg_fetch_row($sth, 0);
55 // preserve <p></p>, <b></b>, <em></em>, <br>, <a href></a>
56 function string_sanitise($text)
58 $ntext = preg_replace (array('/<a\s+href=["\']?([^>"\']*)["\']?>([^<]*)<\/a>/i'),
62 $ntext = htmlspecialchars($ntext, ENT_QUOTES);
64 $ntext = preg_replace(array('/<(\/?(p|br|b|em))>/i',
65 '/\[\[([^\]]+)\]\[([^\]]+)\]\]/'),
66 array('<$1>','<a href="$1">$2</a>'),
77 $pos = strpos(strtolower($cfg['home']), strtolower($_SERVER['SERVER_NAME']));
78 $base = substr($cfg['home'], $pos+strlen($_SERVER['SERVER_NAME']));
80 $pos = strpos($_SERVER['REQUEST_URI'], "?");
82 $uri = $_SERVER['REQUEST_URI'];
84 $uri = substr($_SERVER['REQUEST_URI'], 0, $pos);
86 if (strpos($uri, $base) === 0) {
87 $cfg['path'] = substr($uri, strlen($base));
88 $pos = strrpos($cfg['path'], '/');
90 $cfg['dir'] = substr($cfg['path'], 0, $pos);
92 return str_repeat("../", substr_count($cfg['path'], "/"));
100 return isset($_SESSION['uid']);
103 function javascript_ok()
110 if ($_SESSION['javascript'] == true)
121 if (isset($_SESSION['uid']))
122 if (isset($_SESSION['robot']))
123 return $_SESSION['robot'];
125 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false ||
126 strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ||
127 strpos($_SERVER['HTTP_USER_AGENT'], 'Mediapartners-Google') !== false ||
128 strpos($_SERVER['HTTP_USER_AGENT'], 'VoilaBot') !== false ||
129 strpos($_SERVER['HTTP_USER_AGENT'], 'Gigabot/3.0') !== false ||
130 strpos($_SERVER['HTTP_USER_AGENT'], 'Speedy Spider') !== false ||
131 strpos($_SERVER['HTTP_USER_AGENT'], 'LinkWalker/2.0') !== false ||
132 strpos($_SERVER['HTTP_USER_AGENT'], 'proximic') !== false ||
133 strpos($_SERVER['HTTP_USER_AGENT'], 'Yeti/1.0') !== false ||
134 strpos($_SERVER['HTTP_USER_AGENT'], 'Eurobot/1.0') !== false ||
135 strpos($_SERVER['HTTP_USER_AGENT'], 'MnoGoSearch/') !== false ||
136 strpos($_SERVER['HTTP_USER_AGENT'], 'ia_archiver') !== false ||
137 strpos($_SERVER['HTTP_USER_AGENT'], 'Seekbot/1.0') !== false ||
138 strpos($_SERVER['HTTP_USER_AGENT'], 'MyEngines-Bot') !== false ||
139 strpos($_SERVER['HTTP_USER_AGENT'], 'larbin_') !== false ||
140 strpos($_SERVER['HTTP_USER_AGENT'], 'findlinks/1') !== false ||
141 strpos($_SERVER['HTTP_USER_AGENT'], 'holmes/3.12') !== false ||
142 strpos($_SERVER['HTTP_USER_AGENT'], 'NoteworthyBot/0.1') !== false ||
143 strpos($_SERVER['HTTP_USER_AGENT'], 'Eurosoft-Bot') !== false ||
144 strpos($_SERVER['HTTP_USER_AGENT'], 'Eurobot/1') !== false ||
145 strpos($_SERVER['HTTP_USER_AGENT'], 'Yandex') !== false ||
146 strpos($_SERVER['HTTP_USER_AGENT'], 'msnbot') !== false ||
147 strpos($_SERVER['HTTP_USER_AGENT'], 'Twiceler-0.9') !== false ||
148 strpos($_SERVER['HTTP_USER_AGENT'], 'ScoutJet') !== false ||
149 strpos($_SERVER['HTTP_USER_AGENT'], 'penthesilea/0.3') !== false ||
150 strpos($_SERVER['HTTP_USER_AGENT'], 'VisBot/2.0') !== false ||
151 strpos($_SERVER['HTTP_USER_AGENT'], 'Netluchs/Nutch-1.0') !== false ||
152 strpos($_SERVER['HTTP_USER_AGENT'], 'Yanga WorldSearch Bot') !== false ||
153 strpos($_SERVER['HTTP_USER_AGENT'], 'Semager') !== false ||
154 strpos($_SERVER['HTTP_USER_AGENT'], 'DotBot') !== false ||
155 strpos($_SERVER['HTTP_USER_AGENT'], 'Baiduspider') !== false ||
156 strpos($_SERVER['HTTP_USER_AGENT'], 'MJ12bot/') !== false ||
157 strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo-MMCrawler') !== false ||
158 strpos($_SERVER['HTTP_USER_AGENT'], 'Charlotte/1.1') !== false ||
159 strpos($_SERVER['HTTP_USER_AGENT'], 'Gaisbot/3.0') !== false ||
160 strpos($_SERVER['HTTP_USER_AGENT'], 'psbot/0.1') !== false ||
161 strpos($_SERVER['HTTP_USER_AGENT'], 'Ask Jeeves/Teoma') !== false ||
162 strpos($_SERVER['HTTP_USER_AGENT'], 'SapphireWebCrawler/Nutch') !== false ||
163 strpos($_SERVER['HTTP_USER_AGENT'], 'kalooga/KaloogaBot') !== false ||
164 strpos($_SERVER['HTTP_USER_AGENT'], 'SimilarPages/Nutch-1.0-dev') !== false ||
165 strpos($_SERVER['HTTP_USER_AGENT'], 'Cogentbot/1.') !== false ||
166 strpos($_SERVER['HTTP_USER_AGENT'], 'CatchBot/1.0') !== false ||
167 strpos($_SERVER['HTTP_USER_AGENT'], 'GingerCrawler/1.0') !== false ||
168 strpos($_SERVER['HTTP_USER_AGENT'], 'yacybot') !== false ||
169 strpos($_SERVER['HTTP_USER_AGENT'], 'www.yacy.net') !== false ||
170 strpos($_SERVER['HTTP_USER_AGENT'], 'Nutch-1.0') !== false ||
171 strpos($_SERVER['HTTP_USER_AGENT'], 'Tagoobot/3.0') !== false ||
172 strpos($_SERVER['HTTP_USER_AGENT'], 'SapphireWebCrawler/1.0') !== false ||
173 strpos($_SERVER['HTTP_USER_AGENT'], 'BotOnParade') !== false ||
174 strpos($_SERVER['HTTP_USER_AGENT'], 'SurveyBot/2.3') !== false ||
175 strpos($_SERVER['HTTP_USER_AGENT'], 'XmarksFetch/1.0') !== false ||
176 strpos($_SERVER['HTTP_USER_AGENT'], 'spbot/2.0') !== false ||
177 strpos($_SERVER['HTTP_USER_AGENT'], 'TinEye/1.1') !== false ||
178 strpos($_SERVER['HTTP_USER_AGENT'], 'TurnitinBot/2.1') !== false ||
179 strpos($_SERVER['HTTP_USER_AGENT'], 'CligooRobot/1.0') !== false ||
180 strpos($_SERVER['HTTP_USER_AGENT'], 'libwww-perl') !== false ||
181 strpos($_SERVER['HTTP_USER_AGENT'], 'Wget') !== false ||
182 strpos($_SERVER['HTTP_USER_AGENT'], 'Python-urllib') !== false ||
183 strpos($_SERVER['HTTP_USER_AGENT'], 'CamontSpider/1.0') !== false ||
184 strpos($_SERVER['HTTP_USER_AGENT'], 'TwengaBot-Discover') !== false ||
185 strpos($_SERVER['HTTP_USER_AGENT'], 'Hailoobot/1.2') !== false ||
186 strpos($_SERVER['HTTP_USER_AGENT'], 'bingbot/2.0') !== false ||
187 strpos($_SERVER['HTTP_USER_AGENT'], 'Exabot/3.0') !== false ||
188 strpos($_SERVER['HTTP_USER_AGENT'], 'spbot/2.1') !== false ||
189 strpos($_SERVER['HTTP_USER_AGENT'], 'Search17Bot/1') !== false ||
190 strpos($_SERVER['HTTP_USER_AGENT'], 'Linguee Bot') !== false ||
191 strpos($_SERVER['HTTP_USER_AGENT'], 'findlinks/2') !== false ||
192 strpos($_SERVER['HTTP_USER_AGENT'], 'SiteBot/0.1') !== false ||
193 strpos($_SERVER['HTTP_USER_AGENT'], 'Purebot/1.1') !== false ||
194 strpos($_SERVER['HTTP_USER_AGENT'], 'Ezooms/1.0') !== false ||
195 strpos($_SERVER['HTTP_USER_AGENT'], 'discobot/1.1') !== false ||
196 strpos($_SERVER['HTTP_USER_AGENT'], 'AhrefsBot/1.0') !== false ||
197 strpos($_SERVER['HTTP_USER_AGENT'], 'suggybot v0.01a') !== false ||
198 strpos($_SERVER['HTTP_USER_AGENT'], 'DomainCrawler/2.0') !== false ||
199 strpos($_SERVER['HTTP_USER_AGENT'], 'Plukkie/1.4') !== false ||
200 strpos($_SERVER['HTTP_USER_AGENT'], '/Nutch-') !== false ||
201 strpos($_SERVER['HTTP_USER_AGENT'], 'aiHitBot/1.0') !== false ||
202 strpos($_SERVER['HTTP_USER_AGENT'], 'AhrefsBot/') !== false ||
203 strpos($_SERVER['HTTP_USER_AGENT'], 'Crawler') !== false ||
204 strpos($_SERVER['HTTP_USER_AGENT'], 'Acoon') !== false ||
205 strpos($_SERVER['HTTP_USER_AGENT'], 'aiHitBot') !== false ||
206 strpos($_SERVER['HTTP_USER_AGENT'], 'SeznamBot') !== false ||
207 strpos($_SERVER['HTTP_USER_AGENT'], 'Cityreview Robot') !== false) {
208 if (isset($_SESSION['uid']))
209 $_SESSION['robot'] = true;
213 if (isset($_SESSION['uid']))
214 $_SESSION['robot'] = false;
222 if (!array_key_exists('nickname', $_SESSION))
225 error_log( $_SESSION['nickname'] === 'Joey');
226 return $_SESSION['nickname'] === 'Joey';
229 function format_info_bookmarks()
234 if (!isset($_SESSION['uid']))
237 $query = sprintf("SELECT zeitung,name FROM bookmarks " .
238 "JOIN zeitungen ON zeitungen.id = zeitung " .
240 "ORDER BY priority,name LIMIT 20",
243 $sth = db_query($query);
245 if ($sth === false || pg_num_rows ($sth) == 0)
249 for ($n=0; $n < pg_num_rows ($sth); $n++) {
250 $row = pg_fetch_array ($sth, $n);
251 $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
252 $cfg['basepath'], $row['zeitung'], $row['name']);