3 require_once dirname(__FILE__) .'/includes/utf8/utf8.php';
6 require_once dirname(__FILE__) .'/includes/php-gettext/gettext.inc';
8 T_setlocale(LC_ALL, $locale);
9 T_bindtextdomain($domain, dirname(__FILE__) .'/locales');
10 T_bind_textdomain_codeset($domain, 'UTF-8');
11 T_textdomain($domain);
14 // - direction = out: convert spaces to underscores;
15 // - direction = in: convert underscores to spaces.
16 function convertTag($tag, $direction = 'out') {
17 if ($direction == 'out') {
18 return str_replace(' ', '_', $tag);
21 return str_replace('_', ' ', $tag);
25 function filter($data, $type = NULL) {
26 if (is_string($data)) {
28 $data = stripslashes($data);
31 $data = rawurlencode($data);
34 $data = htmlspecialchars($data);
37 } else if (is_array($data)) {
38 foreach(array_keys($data) as $key) {
40 $row = filter($row, $type);
46 function getPerPageCount() {
47 global $defaultPerPage;
48 return $defaultPerPage;
51 function getSortOrder($override = NULL) {
52 global $defaultOrderBy;
54 if (isset($_GET['sort'])) {
56 } else if (isset($override)) {
59 return $defaultOrderBy;
63 function multi_array_search($needle, $haystack) {
64 if (is_array($haystack)) {
65 foreach(array_keys($haystack) as $key) {
66 $value =& $haystack[$key];
67 $result = multi_array_search($needle, $value);
68 if (is_array($result)) {
70 array_unshift($return, $key);
72 } elseif ($result == TRUE) {
79 if ($needle === $haystack) {
87 function createURL($page = '', $ending = '') {
88 global $cleanurls, $root;
89 if (!$cleanurls && $page != '') {
92 return $root . $page .'/'. $ending;
96 * Return the size of the given file in bytes
98 function file_get_filesize($filename) {
99 if (function_exists('curl_init')) {
100 $ch = curl_init($filename);
101 curl_setopt($ch, CURLOPT_NOBODY, TRUE);
102 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
103 curl_setopt($ch, CURLOPT_HEADER, TRUE);
104 $data = curl_exec($ch);
107 if (FALSE !== $data && preg_match('/Content-Length: (\d+)/', $data, $matches)) {
108 return (float)$matches[1];
115 * Determine MIME type from a filename
117 function file_get_mimetype($filename, $mapping = NULL) {
118 if (!is_array($mapping)) {
120 'ez' => 'application/andrew-inset',
121 'atom' => 'application/atom',
122 'atomcat' => 'application/atomcat+xml',
123 'atomsrv' => 'application/atomserv+xml',
124 'cap|pcap' => 'application/cap',
125 'cu' => 'application/cu-seeme',
126 'tsp' => 'application/dsptype',
127 'spl' => 'application/x-futuresplash',
128 'hta' => 'application/hta',
129 'jar' => 'application/java-archive',
130 'ser' => 'application/java-serialized-object',
131 'class' => 'application/java-vm',
132 'hqx' => 'application/mac-binhex40',
133 'cpt' => 'image/x-corelphotopaint',
134 'nb' => 'application/mathematica',
135 'mdb' => 'application/msaccess',
136 'doc|dot' => 'application/msword',
137 'bin' => 'application/octet-stream',
138 'oda' => 'application/oda',
139 'ogg|ogx' => 'application/ogg',
140 'pdf' => 'application/pdf',
141 'key' => 'application/pgp-keys',
142 'pgp' => 'application/pgp-signature',
143 'prf' => 'application/pics-rules',
144 'ps|ai|eps' => 'application/postscript',
145 'rar' => 'application/rar',
146 'rdf' => 'application/rdf+xml',
147 'rss' => 'application/rss+xml',
148 'rtf' => 'application/rtf',
149 'smi|smil' => 'application/smil',
150 'wpd' => 'application/wordperfect',
151 'wp5' => 'application/wordperfect5.1',
152 'xhtml|xht' => 'application/xhtml+xml',
153 'xml|xsl' => 'application/xml',
154 'zip' => 'application/zip',
155 'cdy' => 'application/vnd.cinderella',
156 'kml' => 'application/vnd.google-earth.kml+xml',
157 'kmz' => 'application/vnd.google-earth.kmz',
158 'xul' => 'application/vnd.mozilla.xul+xml',
159 'xls|xlb|xlt' => 'application/vnd.ms-excel',
160 'cat' => 'application/vnd.ms-pki.seccat',
161 'stl' => 'application/vnd.ms-pki.stl',
162 'ppt|pps' => 'application/vnd.ms-powerpoint',
163 'odc' => 'application/vnd.oasis.opendocument.chart',
164 'odb' => 'application/vnd.oasis.opendocument.database',
165 'odf' => 'application/vnd.oasis.opendocument.formula',
166 'odg' => 'application/vnd.oasis.opendocument.graphics',
167 'otg' => 'application/vnd.oasis.opendocument.graphics-template',
168 'odi' => 'application/vnd.oasis.opendocument.image',
169 'odp' => 'application/vnd.oasis.opendocument.presentation',
170 'otp' => 'application/vnd.oasis.opendocument.presentation-template',
171 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
172 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
173 'odt' => 'application/vnd.oasis.opendocument.text',
174 'odm' => 'application/vnd.oasis.opendocument.text-master',
175 'ott' => 'application/vnd.oasis.opendocument.text-template',
176 'oth' => 'application/vnd.oasis.opendocument.text-web',
177 'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
178 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
179 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
180 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
181 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
182 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
183 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
184 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
185 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
186 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
187 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
188 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
189 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
190 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
191 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
192 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
193 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
194 'cod' => 'application/vnd.rim.cod',
195 'mmf' => 'application/vnd.smaf',
196 'sdc' => 'application/vnd.stardivision.calc',
197 'sds' => 'application/vnd.stardivision.chart',
198 'sda' => 'application/vnd.stardivision.draw',
199 'sdd' => 'application/vnd.stardivision.impress',
200 'sdf' => 'application/vnd.stardivision.math',
201 'sdw' => 'application/vnd.stardivision.writer',
202 'sgl' => 'application/vnd.stardivision.writer-global',
203 'sxc' => 'application/vnd.sun.xml.calc',
204 'stc' => 'application/vnd.sun.xml.calc.template',
205 'sxd' => 'application/vnd.sun.xml.draw',
206 'std' => 'application/vnd.sun.xml.draw.template',
207 'sxi' => 'application/vnd.sun.xml.impress',
208 'sti' => 'application/vnd.sun.xml.impress.template',
209 'sxm' => 'application/vnd.sun.xml.math',
210 'sxw' => 'application/vnd.sun.xml.writer',
211 'sxg' => 'application/vnd.sun.xml.writer.global',
212 'stw' => 'application/vnd.sun.xml.writer.template',
213 'sis' => 'application/vnd.symbian.install',
214 'vsd' => 'application/vnd.visio',
215 'wbxml' => 'application/vnd.wap.wbxml',
216 'wmlc' => 'application/vnd.wap.wmlc',
217 'wmlsc' => 'application/vnd.wap.wmlscriptc',
218 'wk' => 'application/x-123',
219 '7z' => 'application/x-7z-compressed',
220 'abw' => 'application/x-abiword',
221 'dmg' => 'application/x-apple-diskimage',
222 'bcpio' => 'application/x-bcpio',
223 'torrent' => 'application/x-bittorrent',
224 'cab' => 'application/x-cab',
225 'cbr' => 'application/x-cbr',
226 'cbz' => 'application/x-cbz',
227 'cdf' => 'application/x-cdf',
228 'vcd' => 'application/x-cdlink',
229 'pgn' => 'application/x-chess-pgn',
230 'cpio' => 'application/x-cpio',
231 'csh' => 'text/x-csh',
232 'deb|udeb' => 'application/x-debian-package',
233 'dcr|dir|dxr' => 'application/x-director',
234 'dms' => 'application/x-dms',
235 'wad' => 'application/x-doom',
236 'dvi' => 'application/x-dvi',
237 'rhtml' => 'application/x-httpd-eruby',
238 'pages' => 'application/x-iwork-pages-sffpages',
239 'flac' => 'application/x-flac',
240 'pfa|pfb|gsf|pcf|pcf.Z' => 'application/x-font',
241 'mm' => 'application/x-freemind',
242 'gnumeric' => 'application/x-gnumeric',
243 'sgf' => 'application/x-go-sgf',
244 'gcf' => 'application/x-graphing-calculator',
245 'gtar|tgz|taz' => 'application/x-gtar',
246 'hdf' => 'application/x-hdf',
247 'phtml|pht|php' => 'application/x-httpd-php',
248 'phps' => 'application/x-httpd-php-source',
249 'php3' => 'application/x-httpd-php3',
250 'php3p' => 'application/x-httpd-php3-preprocessed',
251 'php4' => 'application/x-httpd-php4',
252 'ica' => 'application/x-ica',
253 'ins|isp' => 'application/x-internet-signup',
254 'iii' => 'application/x-iphone',
255 'iso' => 'application/x-iso9660-image',
256 'jnlp' => 'application/x-java-jnlp-file',
257 'js' => 'application/x-javascript',
258 'jmz' => 'application/x-jmol',
259 'chrt' => 'application/x-kchart',
260 'kil' => 'application/x-killustrator',
261 'skp|skd|skt|skm' => 'application/x-koan',
262 'kpr|kpt' => 'application/x-kpresenter',
263 'ksp' => 'application/x-kspread',
264 'kwd|kwt' => 'application/x-kword',
265 'latex' => 'application/x-latex',
266 'lha' => 'application/x-lha',
267 'lyx' => 'application/x-lyx',
268 'lzh' => 'application/x-lzh',
269 'lzx' => 'application/x-lzx',
270 'frm|maker|frame|fm|fb|book|fbdoc' => 'application/x-maker',
271 'mif' => 'application/x-mif',
272 'wmd' => 'application/x-ms-wmd',
273 'wmz' => 'application/x-ms-wmz',
274 'com|exe|bat|dll' => 'application/x-msdos-program',
275 'msi' => 'application/x-msi',
276 'nc' => 'application/x-netcdf',
277 'pac' => 'application/x-ns-proxy-autoconfig',
278 'nwc' => 'application/x-nwc',
279 'o' => 'application/x-object',
280 'oza' => 'application/x-oz-application',
281 'p7r' => 'application/x-pkcs7-certreqresp',
282 'crl' => 'application/x-pkcs7-crl',
283 'pyc|pyo' => 'application/x-python-code',
284 'qtl' => 'application/x-quicktimeplayer',
285 'rpm' => 'application/x-redhat-package-manager',
287 'shar' => 'application/x-shar',
288 'swf|swfl' => 'application/x-shockwave-flash',
289 'sit|sitx' => 'application/x-stuffit',
290 'sv4cpio' => 'application/x-sv4cpio',
291 'sv4crc' => 'application/x-sv4crc',
292 'tar' => 'application/x-tar',
293 'tcl' => 'application/x-tcl',
294 'gf' => 'application/x-tex-gf',
295 'pk' => 'application/x-tex-pk',
296 'texinfo|texi' => 'application/x-texinfo',
297 '~|%|bak|old|sik' => 'application/x-trash',
298 't|tr|roff' => 'application/x-troff',
299 'man' => 'application/x-troff-man',
300 'me' => 'application/x-troff-me',
301 'ms' => 'application/x-troff-ms',
302 'ustar' => 'application/x-ustar',
303 'src' => 'application/x-wais-source',
304 'wz' => 'application/x-wingz',
305 'crt' => 'application/x-x509-ca-cert',
306 'xcf' => 'application/x-xcf',
307 'fig' => 'application/x-xfig',
308 'xpi' => 'application/x-xpinstall',
309 'aac' => 'audio/aac',
310 'au|snd' => 'audio/basic',
311 'mid|midi|kar' => 'audio/midi',
312 'mpga|mpega|mp2|mp3|m4a' => 'audio/mpeg',
313 'f4a|f4b' => 'audio/mp4',
314 'm3u' => 'audio/x-mpegurl',
315 'oga|spx' => 'audio/ogg',
316 'sid' => 'audio/prs.sid',
317 'aif|aiff|aifc' => 'audio/x-aiff',
318 'gsm' => 'audio/x-gsm',
319 'wma' => 'audio/x-ms-wma',
320 'wax' => 'audio/x-ms-wax',
321 'ra|rm|ram' => 'audio/x-pn-realaudio',
322 'ra' => 'audio/x-realaudio',
323 'pls' => 'audio/x-scpls',
324 'sd2' => 'audio/x-sd2',
325 'wav' => 'audio/x-wav',
326 'alc' => 'chemical/x-alchemy',
327 'cac|cache' => 'chemical/x-cache',
328 'csf' => 'chemical/x-cache-csf',
329 'cbin|cascii|ctab' => 'chemical/x-cactvs-binary',
330 'cdx' => 'chemical/x-cdx',
331 'cer' => 'chemical/x-cerius',
332 'c3d' => 'chemical/x-chem3d',
333 'chm' => 'chemical/x-chemdraw',
334 'cif' => 'chemical/x-cif',
335 'cmdf' => 'chemical/x-cmdf',
336 'cml' => 'chemical/x-cml',
337 'cpa' => 'chemical/x-compass',
338 'bsd' => 'chemical/x-crossfire',
339 'csml|csm' => 'chemical/x-csml',
340 'ctx' => 'chemical/x-ctx',
341 'cxf|cef' => 'chemical/x-cxf',
342 'emb|embl' => 'chemical/x-embl-dl-nucleotide',
343 'spc' => 'chemical/x-galactic-spc',
344 'inp|gam|gamin' => 'chemical/x-gamess-input',
345 'fch|fchk' => 'chemical/x-gaussian-checkpoint',
346 'cub' => 'chemical/x-gaussian-cube',
347 'gau|gjc|gjf' => 'chemical/x-gaussian-input',
348 'gal' => 'chemical/x-gaussian-log',
349 'gcg' => 'chemical/x-gcg8-sequence',
350 'gen' => 'chemical/x-genbank',
351 'hin' => 'chemical/x-hin',
352 'istr|ist' => 'chemical/x-isostar',
353 'jdx|dx' => 'chemical/x-jcamp-dx',
354 'kin' => 'chemical/x-kinemage',
355 'mcm' => 'chemical/x-macmolecule',
356 'mmd|mmod' => 'chemical/x-macromodel-input',
357 'mol' => 'chemical/x-mdl-molfile',
358 'rd' => 'chemical/x-mdl-rdfile',
359 'rxn' => 'chemical/x-mdl-rxnfile',
360 'sd|sdf' => 'chemical/x-mdl-sdfile',
361 'tgf' => 'chemical/x-mdl-tgf',
362 'mcif' => 'chemical/x-mmcif',
363 'mol2' => 'chemical/x-mol2',
364 'b' => 'chemical/x-molconn-Z',
365 'gpt' => 'chemical/x-mopac-graph',
366 'mop|mopcrt|mpc|dat|zmt' => 'chemical/x-mopac-input',
367 'moo' => 'chemical/x-mopac-out',
368 'mvb' => 'chemical/x-mopac-vib',
369 'asn' => 'chemical/x-ncbi-asn1-spec',
370 'prt|ent' => 'chemical/x-ncbi-asn1-ascii',
371 'val|aso' => 'chemical/x-ncbi-asn1-binary',
372 'pdb|ent' => 'chemical/x-pdb',
373 'ros' => 'chemical/x-rosdal',
374 'sw' => 'chemical/x-swissprot',
375 'vms' => 'chemical/x-vamas-iso14976',
376 'vmd' => 'chemical/x-vmd',
377 'xtel' => 'chemical/x-xtel',
378 'xyz' => 'chemical/x-xyz',
379 'gif' => 'image/gif',
380 'ief' => 'image/ief',
381 'jpeg|jpg|jpe' => 'image/jpeg',
382 'pcx' => 'image/pcx',
383 'png' => 'image/png',
384 'svg|svgz' => 'image/svg+xml',
385 'tiff|tif' => 'image/tiff',
386 'djvu|djv' => 'image/vnd.djvu',
387 'wbmp' => 'image/vnd.wap.wbmp',
388 'ras' => 'image/x-cmu-raster',
389 'cdr' => 'image/x-coreldraw',
390 'pat' => 'image/x-coreldrawpattern',
391 'cdt' => 'image/x-coreldrawtemplate',
392 'ico' => 'image/x-icon',
393 'art' => 'image/x-jg',
394 'jng' => 'image/x-jng',
395 'bmp' => 'image/x-ms-bmp',
396 'psd' => 'image/x-photoshop',
397 'pnm' => 'image/x-portable-anymap',
398 'pbm' => 'image/x-portable-bitmap',
399 'pgm' => 'image/x-portable-graymap',
400 'ppm' => 'image/x-portable-pixmap',
401 'rgb' => 'image/x-rgb',
402 'xbm' => 'image/x-xbitmap',
403 'xpm' => 'image/x-xpixmap',
404 'xwd' => 'image/x-xwindowdump',
405 'eml' => 'message/rfc822',
406 'igs|iges' => 'model/iges',
407 'msh|mesh|silo' => 'model/mesh',
408 'wrl|vrml' => 'model/vrml',
409 'ics|icz' => 'text/calendar',
412 '323' => 'text/h323',
413 'html|htm|shtml' => 'text/html',
414 'uls' => 'text/iuls',
415 'mml' => 'text/mathml',
416 'asc|txt|text|pot' => 'text/plain',
417 'rtx' => 'text/richtext',
418 'sct|wsc' => 'text/scriptlet',
419 'tm|ts' => 'text/texmacs',
420 'tsv' => 'text/tab-separated-values',
421 'jad' => 'text/vnd.sun.j2me.app-descriptor',
422 'wml' => 'text/vnd.wap.wml',
423 'wmls' => 'text/vnd.wap.wmlscript',
424 'bib' => 'text/x-bibtex',
425 'boo' => 'text/x-boo',
426 'h++|hpp|hxx|hh' => 'text/x-c++hdr',
427 'c++|cpp|cxx|cc' => 'text/x-c++src',
428 'h' => 'text/x-chdr',
429 'htc' => 'text/x-component',
430 'c' => 'text/x-csrc',
431 'd' => 'text/x-dsrc',
432 'diff|patch' => 'text/x-diff',
433 'hs' => 'text/x-haskell',
434 'java' => 'text/x-java',
435 'lhs' => 'text/x-literate-haskell',
436 'moc' => 'text/x-moc',
437 'p|pas' => 'text/x-pascal',
438 'gcd' => 'text/x-pcs-gcd',
439 'pl|pm' => 'text/x-perl',
440 'py' => 'text/x-python',
441 'etx' => 'text/x-setext',
442 'tcl|tk' => 'text/x-tcl',
443 'tex|ltx|sty|cls' => 'text/x-tex',
444 'vcs' => 'text/x-vcalendar',
445 'vcf' => 'text/x-vcard',
446 '3gp' => 'video/3gpp',
448 'dif|dv' => 'video/dv',
449 'fli' => 'video/fli',
451 'mpeg|mpg|mpe' => 'video/mpeg',
452 'mp4|f4v|f4p' => 'video/mp4',
453 'flv' => 'video/x-flv',
454 'ogv' => 'video/ogg',
455 'qt|mov' => 'video/quicktime',
456 'mxu' => 'video/vnd.mpegurl',
457 'lsf|lsx' => 'video/x-la-asf',
458 'mng' => 'video/x-mng',
459 'asf|asx' => 'video/x-ms-asf',
460 'wm' => 'video/x-ms-wm',
461 'wmv' => 'video/x-ms-wmv',
462 'wmx' => 'video/x-ms-wmx',
463 'wvx' => 'video/x-ms-wvx',
464 'avi' => 'video/x-msvideo',
465 'm4v' => 'video/x-m4v',
466 'movie' => 'video/x-sgi-movie',
467 'ice' => 'x-conference/x-cooltalk',
468 'sisx' => 'x-epoc/x-sisx-app',
469 'vrm|vrml|wrl' => 'x-world/x-vrml',
470 'xps' => 'application/vnd.ms-xpsdocument',
473 foreach ($mapping as $ext_preg => $mime_match) {
474 if (preg_match('!\.(' . $ext_preg . ')$!i', $filename)) {
479 return 'application/octet-stream';
482 function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '', $db = NULL) {
483 if(defined('HAS_DIED'))
484 die(T_('message_die() was called multiple times.'));
485 define('HAS_DIED', 1);
489 // Get SQL error if we are debugging. Do this as soon as possible to prevent
490 // subsequent queries from overwriting the status of sql_error()
491 if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
492 $sql_error = is_null($db) ? '' : $db->sql_error();
495 if ($sql_error['message'] != '')
496 $debug_text .= '<br /><br />'. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message'];
498 if ($sql_store != '')
499 $debug_text .= '<br /><br />'. $sql_store;
501 if ($err_line != '' && $err_file != '')
502 $debug_text .= '</br /><br />'. T_('Line') .' : '. $err_line .'<br />'. T_('File') .' :'. $err_file;
506 case GENERAL_MESSAGE:
507 if ($msg_title == '')
508 $msg_title = T_('Information');
511 case CRITICAL_MESSAGE:
512 if ($msg_title == '')
513 $msg_title = T_('Critical Information');
518 $msg_text = T_('An error occured');
520 if ($msg_title == '')
521 $msg_title = T_('General Error');
525 // Critical errors mean we cannot rely on _ANY_ DB information being
526 // available so we're going to dump out a simple echo'd statement
529 $msg_text = T_('An critical error occured');
531 if ($msg_title == '')
532 $msg_title = T_('Critical Error');
536 // Add on DEBUG info if we've enabled debug mode and this is an error. This
537 // prevents debug info being output for general messages should DEBUG be
538 // set TRUE by accident (preventing confusion for the end user!)
539 if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
540 if ($debug_text != '')
541 $msg_text = $msg_text . '<br /><br /><strong>'. T_('DEBUG MODE') .'</strong>'. $debug_text;
544 echo "<html>\n<body>\n". $msg_title ."\n<br /><br />\n". $msg_text ."</body>\n</html>";