1e36678f6f863f53110d5a1863b03301c988b8fa
[mailer.git] / inc / wrapper-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/04/2009 *
4  * ===================                          Last change: 04/04/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : wrapper-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Wrapper functions                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Wrapper-Funktionen                               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Read a given file
45 function readFromFile ($FQFN, $sqlPrepare = false) {
46         // Sanity-check if file is there (should be there, but just to make it sure)
47         if (!isFileReadable($FQFN)) {
48                 // This should not happen
49                 debug_report_bug(__FUNCTION__.': File ' . basename($FQFN) . ' is not readable!');
50         } // END - if
51
52         // Load the file
53         if (function_exists('file_get_contents')) {
54                 // Use new function
55                 $content = file_get_contents($FQFN);
56         } else {
57                 // Fall-back to implode-file chain
58                 $content = implode('', file($FQFN));
59         }
60
61         // Prepare SQL queries?
62         if ($sqlPrepare === true) {
63                 // Remove some unwanted chars
64                 $content = str_replace("\r", '', $content);
65                 $content = str_replace("\n\n", "\n", $content);
66         } // END - if
67
68         // Return the content
69         return $content;
70 }
71
72 // Writes content to a file
73 function writeToFile ($FQFN, $content, $aquireLock = false) {
74         // Is the file writeable?
75         if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
76                 // Not writeable!
77                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
78
79                 // Failed! :(
80                 return false;
81         } // END - if
82
83         // By default all is failed...
84         $return = false;
85
86         // Is the function there?
87         if (function_exists('file_put_contents')) {
88                 // With lock?
89                 if ($aquireLock === true) {
90                         // Write it directly with lock
91                         $return = file_put_contents($FQFN, $content, LOCK_EX);
92                 } else {
93                         // Write it directly
94                         $return = file_put_contents($FQFN, $content);
95                 }
96         } else {
97                 // Write it with fopen
98                 $fp = fopen($FQFN, 'w') or app_die(__FUNCTION__, __LINE__, "Cannot write file ".basename($FQFN).'!');
99
100                 // Aquire lock
101                 if ($aquireLock === true) flock($fp, LOCK_EX);
102
103                 // Write content
104                 fwrite($fp, $content);
105
106                 // Close stream
107                 fclose($fp);
108         }
109
110         // Mark it as readable
111         $GLOBALS['file_readable'][$FQFN] = true;
112
113         // Return status
114         return changeMode($FQFN, 0644);
115 }
116
117 // Clears the output buffer. This function does *NOT* backup sent content.
118 function clearOutputBuffer () {
119         // Trigger an error on failure
120         if (!ob_end_clean()) {
121                 // Failed!
122                 debug_report_bug(__FUNCTION__.': Failed to clean output buffer.');
123         } // END - if
124 }
125
126 // Encode strings
127 // @TODO Implement $compress
128 function encodeString ($str, $compress = true) {
129         $str = urlencode(base64_encode(compileUriCode($str)));
130         return $str;
131 }
132
133 // Decode strings encoded with encodeString()
134 // @TODO Implement $decompress
135 function decodeString ($str, $decompress = true) {
136         $str = compileUriCode(base64_decode(urldecode(compileUriCode($str))));
137         return $str;
138 }
139
140 // Decode entities in a nicer way
141 function decodeEntities ($str, $quote = ENT_NOQUOTES) {
142         // Decode the entities to UTF-8 now
143         $decodedString = html_entity_decode($str, $quote, 'UTF-8');
144
145         // Return decoded string
146         return $decodedString;
147 }
148
149 // Merges an array together but only if both are arrays
150 function merge_array ($array1, $array2) {
151         // Are both an array?
152         if ((!is_array($array1)) && (!is_array($array2))) {
153                 // Both are not arrays
154                 debug_report_bug(__FUNCTION__ . ': No arrays provided!');
155         } elseif (!is_array($array1)) {
156                 // Left one is not an array
157                 debug_report_bug(sprintf("[%s:%s] array1 is not an array. array != %s", __FUNCTION__, __LINE__, gettype($array1)));
158         } elseif (!is_array($array2)) {
159                 // Right one is not an array
160                 debug_report_bug(sprintf("[%s:%s] array2 is not an array. array != %s", __FUNCTION__, __LINE__, gettype($array2)));
161         }
162
163         // Merge all together
164         return array_merge($array1, $array2);
165 }
166
167 // Check if given FQFN is a readable file
168 function isFileReadable ($FQFN) {
169         // Do we have cache?
170         if (!isset($GLOBALS['file_readable'][$FQFN])) {
171                 // Check all...
172                 $GLOBALS['file_readable'][$FQFN] = ((file_exists($FQFN)) && (is_file($FQFN)) && (is_readable($FQFN)));
173         } // END - if
174
175         // Return result
176         return $GLOBALS['file_readable'][$FQFN];
177 }
178
179 // Checks wether the given FQFN is a directory and not ., .. or .svn
180 function isDirectory ($FQFN) {
181         // Do we have cache?
182         if (!isset($GLOBALS['is_directory'][$FQFN])) {
183                 // Generate baseName
184                 $baseName = basename($FQFN);
185
186                 // Check it
187                 $GLOBALS['is_directory'][$FQFN] = ((is_dir($FQFN)) && ($baseName != '.') && ($baseName != '..') && ($baseName != '.svn'));
188         } // END - if
189
190         // Return the result
191         return $GLOBALS['is_directory'][$FQFN];
192 }
193
194 // "Getter" for remote IP number
195 function detectRemoteAddr () {
196         // Get remote ip from environment
197         $remoteAddr = determineRealRemoteAddress();
198
199         // Is removeip installed?
200         if (isExtensionActive('removeip')) {
201                 // Then anonymize it
202                 $remoteAddr = getAnonymousRemoteAddress($remoteAddr);
203         } // END - if
204
205         // Return it
206         return $remoteAddr;
207 }
208
209 // "Getter" for remote hostname
210 function detectRemoteHostname () {
211         // Get remote ip from environment
212         $remoteHost = getenv('REMOTE_HOST');
213
214         // Is removeip installed?
215         if (isExtensionActive('removeip')) {
216                 // Then anonymize it
217                 $remoteHost = getAnonymousRemoteHost($remoteHost);
218         } // END - if
219
220         // Return it
221         return $remoteHost;
222 }
223
224 // "Getter" for user agent
225 function detectUserAgent ($alwaysReal = false) {
226         // Get remote ip from environment
227         $userAgent = getenv('HTTP_USER_AGENT');
228
229         // Is removeip installed?
230         if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
231                 // Then anonymize it
232                 $userAgent = getAnonymousUserAgent($userAgent);
233         } // END - if
234
235         // Return it
236         return $userAgent;
237 }
238
239 // "Getter" for referer
240 function detectReferer () {
241         // Get remote ip from environment
242         $referer = getenv('HTTP_REFERER');
243
244         // Is removeip installed?
245         if (isExtensionActive('removeip')) {
246                 // Then anonymize it
247                 $referer = getAnonymousReferer($referer);
248         } // END - if
249
250         // Return it
251         return $referer;
252 }
253
254 // "Getter" for request URI
255 function detectRequestUri () {
256         // Return it
257         return (getenv('REQUEST_URI'));
258 }
259
260 // "Getter" for query string
261 function detectQueryString () {
262         return str_replace('&', '&amp;', (getenv('QUERY_STRING')));
263 }
264
265 // Check wether we are installing
266 function isInstalling () {
267         // Determine wether we are installing
268         if (!isset($GLOBALS['mxchange_installing'])) {
269                 // Check URL (css.php/js.php need this)
270                 $GLOBALS['mxchange_installing'] = isGetRequestElementSet('installing');
271         } // END - if
272
273         // Return result
274         return $GLOBALS['mxchange_installing'];
275 }
276
277 // Check wether this script is installed
278 function isInstalled () {
279         // Do we have cache?
280         if (!isset($GLOBALS['is_installed'])) {
281                 // Determine wether this script is installed
282                 $GLOBALS['is_installed'] = (
283                 (
284                         // First is config
285                         (
286                                 (
287                                         isConfigEntrySet('MXCHANGE_INSTALLED')
288                                 ) && (
289                                         getConfig('MXCHANGE_INSTALLED') == 'Y'
290                                 )
291                         )
292                 ) || (
293                         // New config file found and loaded
294                         isIncludeReadable(getConfig('CACHE_PATH') . 'config-local.php')
295                 ) || (
296                         (
297                                 // New config file found, but not yet read
298                                 isIncludeReadable(getConfig('CACHE_PATH') . 'config-local.php')
299                         ) && (
300                                 (
301                                         // Only new config file is found
302                                         !isIncludeReadable('inc/config.php')
303                                 ) || (
304                                         // Is installation mode
305                                         !isInstalling()
306                                 )
307                         )
308                 ));
309         } // END - if
310
311         // Then use the cache
312         return $GLOBALS['is_installed'];
313 }
314
315 // Check wether an admin is registered
316 function isAdminRegistered () {
317         return ((isConfigEntrySet('ADMIN_REGISTERED')) && (getConfig('ADMIN_REGISTERED') == 'Y'));
318 }
319
320 // Checks wether the reset mode is active
321 function isResetModeEnabled () {
322         // Now simply check it
323         return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
324 }
325
326 // Checks wether the debug mode is enabled
327 function isDebugModeEnabled () {
328         // Simply check it
329         return ((isConfigEntrySet('DEBUG_MODE')) && (getConfig('DEBUG_MODE') == 'Y'));
330 }
331
332 // Checks wether we shall debug regular expressions
333 function isDebugRegExpressionEnabled () {
334         // Simply check it
335         return ((isConfigEntrySet('DEBUG_REGEX')) && (getConfig('DEBUG_REGEX') == 'Y'));
336 }
337
338 // Checks wether the cache instance is valid
339 function isCacheInstanceValid () {
340         return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
341 }
342
343 // Copies a file from source to destination and verifies if that goes fine.
344 // This function should wrap the copy() command and make a nicer debug backtrace
345 // even if there is no xdebug extension installed.
346 function copyFileVerified ($source, $dest, $chmod = '') {
347         // Failed is the default
348         $status = false;
349
350         // Is the source file there?
351         if (!isFileReadable($source)) {
352                 // Then abort here
353                 debug_report_bug('Cannot read from source file ' . basename($source) . '.');
354         } // END - if
355
356         // Is the target directory there?
357         if (!isDirectory(dirname($dest))) {
358                 // Then abort here
359                 debug_report_bug('Cannot find directory ' . str_replace(getConfig('PATH'), '', dirname($dest)) . '.');
360         } // END - if
361
362         // Now try to copy it
363         if (!copy($source, $dest)) {
364                 // Something went wrong
365                 debug_report_bug('copy() has failed to copy the file.');
366         } else {
367                 // Reset cache
368                 $GLOBALS['file_readable'][$dest] = true;
369         }
370
371         // If there are chmod rights set, apply them
372         if (!empty($chmod)) {
373                 // Try to apply them
374                 $status = changeMode($dest, $chmod);
375         } else {
376                 // All fine
377                 $status = true;
378         }
379
380         // All fine
381         return $status;
382 }
383
384 // Wrapper function for header()
385 // Send a header but checks before if we can do so
386 function sendHeader ($header) {
387         // Send the header
388         $GLOBALS['header'][] = trim($header);
389 }
390
391 // Flushes all headers
392 function flushHeaders () {
393         // Is the header already sent?
394         if (headers_sent()) {
395                 // Then abort here
396                 debug_report_bug('Headers already sent!');
397         } // END - if
398
399         // Flush all headers
400         foreach ($GLOBALS['header'] as $header) {
401                 header($header);
402         } // END - foreach
403 }
404
405 // Wrapper function for chmod()
406 // @TODO Do some more sanity check here
407 function changeMode ($FQFN, $mode) {
408         // Is the file/directory there?
409         if ((!isFileReadable($FQFN)) && (!isDirectory($FQFN))) {
410                 // Neither, so abort here
411                 debug_report_bug('Cannot chmod() on ' . basename($FQFN) . '.');
412         } // END - if
413
414         // Try to set them
415         chmod($FQFN, $mode);
416 }
417
418 // Wrapper for unlink()
419 function removeFile ($FQFN) {
420         // Is the file there?
421         if (isFileReadable($FQFN)) {
422                 // Reset cache first
423                 $GLOBALS['file_readable'][$FQFN] = false;
424
425                 // Yes, so remove it
426                 return unlink($FQFN);
427         } // END - if
428
429         // All fine if no file was removed. If we change this to 'false' or rewrite
430         // above if() block it would be to restrictive.
431         return true;
432 }
433
434 // Wrapper for $_POST['sel']
435 function countPostSelection ($element = 'sel') {
436         // Is it set?
437         if (isPostRequestElementSet($element)) {
438                 // Return counted elements
439                 return countSelection(postRequestElement($element));
440         } else {
441                 // Return zero if not found
442                 return 0;
443         }
444 }
445
446 // Checks wether the config-local.php is loaded
447 function isConfigLocalLoaded () {
448         return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
449 }
450
451 // Checks wether a nickname or userid was entered and caches the result
452 function isNicknameUsed ($userid) {
453         // Default is false
454         $isUsed = false;
455
456         // Is the cache there
457         if (isset($GLOBALS['is_nickname_used'][$userid])) {
458                 // Then use it
459                 $isUsed = $GLOBALS['is_nickname_used'][$userid];
460         } else {
461                 // Determine it
462                 $isUsed = (('' . round($userid) . '') != $userid);
463
464                 // And write it to the cache
465                 $GLOBALS['is_nickname_used'][$userid] = $isUsed;
466         }
467
468         // Return the result
469         return $isUsed;
470 }
471
472 // Getter for 'what' value
473 function getWhat () {
474         // Default is null
475         $what = null;
476
477         // Is the value set?
478         if (isWhatSet(true)) {
479                 // Then use it
480                 $what = $GLOBALS['what'];
481         } // END - if
482
483         // Return it
484         return $what;
485 }
486
487 // Setter for 'what' value
488 function setWhat ($newWhat) {
489         $GLOBALS['what'] = SQL_ESCAPE($newWhat);
490 }
491
492 // Setter for 'what' from configuration
493 function setWhatFromConfig ($configEntry) {
494         // Get 'what' from config
495         $what = getConfig($configEntry);
496
497         // Set it
498         setWhat($what);
499 }
500
501 // Checks wether what is set and optionally aborts on miss
502 function isWhatSet ($strict =  false) {
503         // Check for it
504         $isset = (isset($GLOBALS['what']));
505
506         // Should we abort here?
507         if (($strict === true) && ($isset === false)) {
508                 // Output backtrace
509                 debug_report_bug('what is empty.');
510         } // END - if
511
512         // Return it
513         return $isset;
514 }
515
516 // Getter for 'action' value
517 function getAction () {
518         // Default is null
519         $action = null;
520
521         // Is the value set?
522         if (isActionSet(true)) {
523                 // Then use it
524                 $action = $GLOBALS['action'];
525         } // END - if
526
527         // Return it
528         return $action;
529 }
530
531 // Setter for 'action' value
532 function setAction ($newAction) {
533         $GLOBALS['action'] = SQL_ESCAPE($newAction);
534 }
535
536 // Checks wether action is set and optionally aborts on miss
537 function isActionSet ($strict =  false) {
538         // Check for it
539         $isset = (isset($GLOBALS['action']));
540
541         // Should we abort here?
542         if (($strict === true) && ($isset === false)) {
543                 // Output backtrace
544                 debug_report_bug('action is empty.');
545         } // END - if
546
547         // Return it
548         return $isset;
549 }
550
551 // Getter for 'module' value
552 function getModule ($strict = true) {
553         // Default is null
554         $module = null;
555
556         // Is the value set?
557         if (isModuleSet($strict)) {
558                 // Then use it
559                 $module = $GLOBALS['module'];
560         } // END - if
561
562         // Return it
563         return $module;
564 }
565
566 // Setter for 'module' value
567 function setModule ($newModule) {
568         // Secure it and make all modules lower-case
569         $GLOBALS['module'] = SQL_ESCAPE(strtolower($newModule));
570 }
571
572 // Checks wether module is set and optionally aborts on miss
573 function isModuleSet ($strict =  false) {
574         // Check for it
575         $isset = (!empty($GLOBALS['module']));
576
577         // Should we abort here?
578         if (($strict === true) && ($isset === false)) {
579                 // Output backtrace
580                 debug_report_bug('module is empty.');
581         } // END - if
582
583         // Return it
584         return (($isset === true) && ($GLOBALS['module'] != 'unknown')) ;
585 }
586
587 // Getter for 'output_mode' value
588 function getOutputMode () {
589         // Default is null
590         $output_mode = null;
591
592         // Is the value set?
593         if (isOutputModeSet(true)) {
594                 // Then use it
595                 $output_mode = $GLOBALS['output_mode'];
596         } // END - if
597
598         // Return it
599         return $output_mode;
600 }
601
602 // Setter for 'output_mode' value
603 function setOutputMode ($newOutputMode) {
604         $GLOBALS['output_mode'] = (int) $newOutputMode;
605 }
606
607 // Checks wether output_mode is set and optionally aborts on miss
608 function isOutputModeSet ($strict =  false) {
609         // Check for it
610         $isset = (isset($GLOBALS['output_mode']));
611
612         // Should we abort here?
613         if (($strict === true) && ($isset === false)) {
614                 // Output backtrace
615                 debug_report_bug('output_mode is empty.');
616         } // END - if
617
618         // Return it
619         return $isset;
620 }
621
622 // Enables block-mode
623 function enableBlockMode ($enabled = true) {
624         $GLOBALS['block_mode'] = $enabled;
625 }
626
627 // Checks wether block-mode is enabled
628 function isBlockModeEnabled () {
629         // Abort if not set
630         if (!isset($GLOBALS['block_mode'])) {
631                 // Needs to be fixed
632                 debug_report_bug(__FUNCTION__ . ': block_mode is not set.');
633         } // END - if
634
635         // Return it
636         return $GLOBALS['block_mode'];
637 }
638
639 // Wrapper function for addPointsThroughReferalSystem()
640 function addPointsDirectly ($subject, $userid, $points) {
641         // Reset level here
642         unset($GLOBALS['ref_level']);
643
644         // Call more complicated method (due to more parameters)
645         return addPointsThroughReferalSystem($subject, $userid, $points, false, 0, false, 'direct');
646 }
647
648 // Wrapper function to redirect from member-only modules to index
649 function redirectToIndexMemberOnlyModule () {
650         // Do the redirect here
651         redirectToUrl('modules.php?module=index&amp;code=' . getCode('MODULE_MEM_ONLY') . '&amp;mod=' . getModule());
652 }
653
654 // Wrapper function for checking if extension is installed and newer or same version
655 function isExtensionInstalledAndNewer ($ext_name, $version) {
656         // Return it
657         //* DEBUG: */ print __FUNCTION__.':'.$ext_name.'=&gt;'.$version.'<br />';
658         return ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version));
659 }
660
661 // Wrapper function for checking if extension is installed and older than given version
662 function isExtensionInstalledAndOlder ($ext_name, $version) {
663         // Return it
664         //* DEBUG: */ print __FUNCTION__.':'.$ext_name.'&lt;'.$version.'<br />';
665         return ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version)));
666 }
667
668 // Set username
669 function setUsername ($userName) {
670         $GLOBALS['username'] = (string) $userName;
671 }
672
673 // Get username
674 function getUsername () {
675         return $GLOBALS['username'];
676 }
677
678 // Wrapper function for installation phase
679 function isInstallationPhase () {
680         // Do we have cache?
681         if (!isset($GLOBALS['installation_phase'])) {
682                 // Determine it
683                 $GLOBALS['installation_phase'] = ((!isInstalled()) || (isInstalling()));
684         } // END - if
685
686         // Return result
687         return $GLOBALS['installation_phase'];
688 }
689
690 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
691 function isDemoModeActive () {
692         return ((isExtensionActive('demo')) && (getSession('admin_login') == 'demo'));
693 }
694
695 // Wrapper function to redirect to de-refered URL
696 function redirectToDereferedUrl ($URL) {
697         // De-refer the URL
698         $URL = generateDerefererUrl($URL);
699
700         // Redirect to to
701         redirectToUrl($URL);
702 }
703
704 // Getter for PHP caching value
705 function getPhpCaching () {
706         return $GLOBALS['php_caching'];
707 }
708
709 // Checks wether the admin hash is set
710 function isAdminHashSet ($admin) {
711         return isset($GLOBALS['cache_array']['admin']['password'][$admin]);
712 }
713
714 // Setter for admin hash
715 function setAdminHash ($admin, $hash) {
716         $GLOBALS['cache_array']['admin']['password'][$admin] = $hash;
717 }
718
719 // Init user data array
720 function initUserData () {
721         // User id should not be zero
722         if (getCurrentUserId() < 1) debug_report_bug(__FUNCTION__.': User id is zero.');
723
724         // Init the user
725         $GLOBALS['user_data'][getCurrentUserId()] = array();
726 }
727
728 // Getter for user data
729 function getUserData ($column) {
730         // User id should not be zero
731         if (getCurrentUserId() < 1) debug_report_bug(__FUNCTION__.': User id is zero.');
732
733         // Return the value
734         return $GLOBALS['user_data'][getCurrentUserId()][$column];
735 }
736
737 // Geter for whole user data array
738 function getUserDataArray () {
739         // User id should not be zero
740         if (getCurrentUserId() < 1) debug_report_bug(__FUNCTION__.': User id is zero.');
741
742         // Get the whole array
743         return $GLOBALS['user_data'][getCurrentUserId()];
744 }
745
746 // Checks if the user data is valid, this may indicate that the user has logged
747 // in, but you should use isMember() if you want to find that out.
748 function isUserDataValid () {
749         // User id should not be zero so abort here
750         if (!isCurrentUserIdSet()) return false;
751
752         // Is the array there and filled?
753         return ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
754 }
755
756 // Setter for current userid
757 function setCurrentUserId ($userid) {
758         logDebugMessage(__FUNCTION__, __LINE__, 'userid='.$userid);
759         $GLOBALS['current_userid'] = bigintval($userid);
760 }
761
762 // Getter for current userid
763 function getCurrentUserId () {
764         // Userid must be set before it can be used
765         if (!isCurrentUserIdSet()) {
766                 // Not set
767                 debug_report_bug('User id is not set.');
768         } // END - if
769
770         // Return the userid
771         return $GLOBALS['current_userid'];
772 }
773
774 // Checks if current userid is set
775 function isCurrentUserIdSet () {
776         return isset($GLOBALS['current_userid']);
777 }
778
779 // Checks wether we are debugging template cache
780 function isDebuggingTemplateCache () {
781         return (getConfig('DEBUG_TEMPLATE_CACHE') == 'Y');
782 }
783
784 // Wrapper for fetchUserData() and getUserData() calls
785 function getFetchedUserData ($keyColumn, $userId, $valueColumn) {
786         // Default is 'guest'
787         $data = getMessage('USERNAME_GUEST');
788
789         // Can we fetch the user data?
790         if (($userId > 0) && (fetchUserData($userId, $keyColumn))) {
791                 // Now get the data back
792                 $data = getUserData($valueColumn);
793         } // END - if
794
795         // Return it
796         return $data;
797 }
798
799 // [EOF]
800 ?>