- Rewrites to use more the userid than the actual email address when sending
[mailer.git] / inc / template-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              : template-functions.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Template functions                               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Template-Funktionen                              *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Wrapper until we merged to the EL branch
44 function preCompileCode ($code, $template = '', $compiled = false, $full = true, $overwrite = false) {
45         return compileCode($code, false, true, $full);
46 }
47
48 // Setter for 'is_template_html'
49 function enableTemplateHtml ($enable = true) {
50         $GLOBALS['is_template_html'] = (bool) $enable;
51 }
52
53 // Checks wether the template is HTML or not by previously set flag
54 // Default: true
55 function isTemplateHtml () {
56         // Is the output_mode other than 0 (HTML), then no comments are enabled
57         if (!isHtmlOutputMode()) {
58                 // No HTML
59                 return false;
60         } else {
61                 // Maybe HTML?
62                 return $GLOBALS['is_template_html'];
63         }
64 }
65
66 // Wrapper for writing debug informations to the browser
67 function debugOutput ($message) {
68         outputHtml('<div class="debug_message">' . $message . '</div>');
69 }
70
71 // "Fixes" an empty string into three dashes (use for templates)
72 function fixEmptyContentToDashes ($str) {
73         // Trim the string
74         $str = trim($str);
75
76         // Is the string empty?
77         if (empty($str)) {
78                 $str = '---';
79         } // END - if
80
81         // Return string
82         return $str;
83 }
84
85 // Init color switch
86 function initTemplateColorSwitch ($template) {
87         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'INIT:' . $template);
88         $GLOBALS['color_switch'][$template] = 2;
89 }
90
91 // "Getter" for color switch code
92 function getColorSwitchCode ($template) {
93         // Prepare the code
94         $code = "{DQUOTE} . doTemplateColorSwitch('" . $template . "', false, false) . {DQUOTE}";
95
96         // And return it
97         return $code;
98 }
99
100 // Output HTML code directly or 'render' it. You addionally switch the new-line character off
101 function outputHtml ($htmlCode, $newLine = true) {
102         // Init output
103         if (!isset($GLOBALS['output'])) {
104                 $GLOBALS['output'] = '';
105         } // END - if
106
107         // Do we have HTML-Code here?
108         if (!empty($htmlCode)) {
109                 // Yes, so we handle it as you have configured
110                 switch (getOutputMode()) {
111                         case 'render':
112                                 // That's why you don't need any \n at the end of your HTML code... :-)
113                                 if (getPhpCaching() == 'on') {
114                                         // Output into PHP's internal buffer
115                                         outputRawCode($htmlCode);
116
117                                         // That's why you don't need any \n at the end of your HTML code... :-)
118                                         if ($newLine === true) print("\n");
119                                 } else {
120                                         // Render mode for old or lame servers...
121                                         $GLOBALS['output'] .= $htmlCode;
122
123                                         // That's why you don't need any \n at the end of your HTML code... :-)
124                                         if ($newLine === true) $GLOBALS['output'] .= "\n";
125                                 }
126                                 break;
127
128                         case 'direct':
129                                 // If we are switching from render to direct output rendered code
130                                 if ((!empty($GLOBALS['output'])) && (getPhpCaching() != 'on')) { outputRawCode($GLOBALS['output']); $GLOBALS['output'] = ''; }
131
132                                 // The same as above... ^
133                                 outputRawCode($htmlCode);
134                                 if ($newLine === true) print("\n");
135                                 break;
136
137                         default:
138                                 // Huh, something goes wrong or maybe you have edited config.php ???
139                                 debug_report_bug(__FUNCTION__, __LINE__, '<strong>{--FATAL_ERROR--}:</strong> {--NO_RENDER_DIRECT--}');
140                                 break;
141                 } // END - switch
142         } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['header'])) || (count($GLOBALS['header']) == 0))) {
143                 // Output cached HTML code
144                 $GLOBALS['output'] = ob_get_contents();
145
146                 // Clear output buffer for later output if output is found
147                 if (!empty($GLOBALS['output'])) {
148                         clearOutputBuffer();
149                 } // END - if
150
151                 // Send all HTTP headers
152                 sendHttpHeaders();
153
154                 // Compile and run finished rendered HTML code
155                 compileFinalOutput();
156
157                 // Output code here, DO NOT REMOVE! ;-)
158                 outputRawCode($GLOBALS['output']);
159         } elseif ((getOutputMode() == 'render') && (!empty($GLOBALS['output']))) {
160                 // Send all HTTP headers
161                 sendHttpHeaders();
162
163                 // Compile and run finished rendered HTML code
164                 compileFinalOutput();
165
166                 // Output code here, DO NOT REMOVE! ;-)
167                 outputRawCode($GLOBALS['output']);
168         } else {
169                 // And flush all headers
170                 flushHeaders();
171         }
172 }
173
174 // Compiles the final output
175 function compileFinalOutput () {
176         // Add page header and footer
177         addPageHeaderFooter();
178
179         // Do the final compilation
180         $GLOBALS['output'] = doFinalCompilation($GLOBALS['output']);
181
182         // Extension 'rewrite' installed?
183         if ((isExtensionActive('rewrite')) && (!isCssOutputMode())) {
184                 $GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
185         } // END - if
186
187         // Compress it?
188         /**
189          * @TODO On some pages this is buggy
190         if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
191                 // Compress it for HTTP gzip
192                 $GLOBALS['output'] = gzencode($GLOBALS['output'], 9);
193
194                 // Add header
195                 sendHeader('Content-Encoding: gzip');
196         } elseif (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('deflate', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
197                 // Compress it for HTTP deflate
198                 $GLOBALS['output'] = gzcompress($GLOBALS['output'], 9);
199
200                 // Add header
201                 sendHeader('Content-Encoding: deflate');
202         }
203         */
204
205         // Add final length
206         sendHeader('Content-Length: ' . strlen($GLOBALS['output']));
207
208         // Flush all headers
209         flushHeaders();
210 }
211
212 // Main compilation loop
213 function doFinalCompilation ($code, $insertComments = true, $enableCodes = true) {
214         // Insert comments? (Only valid with HTML templates, of course)
215         enableTemplateHtml($insertComments);
216
217         // Init counter
218         $count = 0;
219
220         // Compile all out
221         while (((strpos($code, '{--') !== false) || (strpos($code, '{DQUOTE}') !== false) || (strpos($code, '{?') !== false) || (strpos($code, '{%') !== false)) && ($count < 7)) {
222                 // Init common variables
223                 $content = array();
224                 $newContent = '';
225
226                 // Compile it
227                 //* DEBUG: */ debugOutput('<pre>'.linenumberCode($code).'</pre>');
228                 $eval = '$newContent = "' . str_replace('{DQUOTE}', '"', compileCode(escapeQuotes($code), false, true, $enableCodes)) . '";';
229                 //* DEBUG: */ if (!$insertComments) print('EVAL=<pre>'.linenumberCode($eval).'</pre>');
230                 eval($eval);
231                 //* DEBUG: */ if (!$insertComments) print('NEW=<pre>'.linenumberCode($newContent).'</pre>');
232                 //* DEBUG: */ die('<pre>'.encodeEntities($newContent).'</pre>');
233
234                 // Was that eval okay?
235                 if (empty($newContent)) {
236                         // Something went wrong!
237                         debug_report_bug(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
238                 } // END - if
239
240                 // Use it again
241                 $code = $newContent;
242
243                 // Count round
244                 $count++;
245         } // END - while
246
247         // Return the compiled code
248         return $code;
249 }
250
251 // Output the raw HTML code
252 function outputRawCode ($htmlCode) {
253         // Output stripped HTML code to avoid broken JavaScript code, etc.
254         print(str_replace('{BACK}', "\\", $htmlCode));
255
256         // Flush the output if only getPhpCaching() is not 'on'
257         if (getPhpCaching() != 'on') {
258                 // Flush it
259                 flush();
260         } // END - if
261 }
262
263 // Load a template file and return it's content (only it's name; do not use ' or ")
264 function loadTemplate ($template, $return = false, $content = array(), $compileCode = true) {
265         // @TODO Remove this sanity-check if all is fine
266         if (!is_bool($return)) debug_report_bug(__FUNCTION__, __LINE__, 'return is not bool (' . gettype($return) . ')');
267
268         // Set current template
269         $GLOBALS['current_template'] = $template;
270
271         // Do we have cache?
272         if ((!isDebuggingTemplateCache()) && (isTemplateCached($template))) {
273                 // Evaluate the cache
274                 eval(readTemplateCache($template));
275         } elseif (!isset($GLOBALS['template_eval'][$template])) {
276                 // Make all template names lowercase
277                 $template = strtolower($template);
278
279                 // Init some data
280                 $ret = '';
281
282                 // Base directory
283                 $basePath = sprintf("%stemplates/%s/html/", getPath(), getLanguage());
284                 $extraPath = detectExtraTemplatePath($template);
285
286                 // Generate FQFN
287                 $FQFN = $basePath . $extraPath . $template . '.tpl';
288
289                 // Does the special template exists?
290                 if (!isFileReadable($FQFN)) {
291                         // Reset to default template
292                         $FQFN = $basePath . $template . '.tpl';
293                 } // END - if
294
295                 // Now does the final template exists?
296                 if (isFileReadable($FQFN)) {
297                         // Count the template load
298                         incrementConfigEntry('num_templates');
299
300                         // The local file does exists so we load it. :)
301                         $GLOBALS['tpl_content'][$template] = readFromFile($FQFN);
302
303                         // Do we have to compile the code?
304                         $ret = '';
305                         if ((strpos($GLOBALS['tpl_content'][$template], '$') !== false) || (strpos($GLOBALS['tpl_content'][$template], '{--') !== false) || (strpos($GLOBALS['tpl_content'][$template], '{?') !== false) || (strpos($GLOBALS['tpl_content'][$template], '{%') !== false)) {
306                                 // Normal HTML output?
307                                 if (isHtmlOutputMode()) {
308                                         // Add surrounding HTML comments to help finding bugs faster
309                                         $ret = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['tpl_content'][$template] . '<!-- Template ' . $template . ' - End //-->';
310
311                                         // Prepare eval() command
312                                         $GLOBALS['template_eval'][$template] = '$ret = "' . getColorSwitchCode($template) . compileCode(escapeQuotes($ret), false, true, true, $compileCode) . '";';
313                                 } elseif (substr($template, 0, 3) == 'js_') {
314                                         // JavaScripts don't like entities and timings
315                                         $GLOBALS['template_eval'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['tpl_content'][$template]), false, true, true, $compileCode) . '");';
316                                 } else {
317                                         // Prepare eval() command, other output doesn't like entities, maybe
318                                         $GLOBALS['template_eval'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'][$template]), false, true, true, $compileCode) . '");';
319                                 }
320                         } else {
321                                 // Add surrounding HTML comments to help finding bugs faster
322                                 $ret = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['tpl_content'][$template] . '<!-- Template ' . $template . ' - End //-->';
323                                 $GLOBALS['template_eval'][$template] = '$ret = "' . getColorSwitchCode($template) . compileRawCode(escapeQuotes($ret), false, true, true, $compileCode) . '";';
324                         } // END - if
325                 } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
326                         // Only admins shall see this warning or when installation mode is active
327                         $ret = '<div class="para">
328         <span class="notice">{--TEMPLATE_404--}</span>
329 </div>
330 <div class="para">
331         (' . $template . ')
332 </div>
333 <div class="para">
334         {--TEMPLATE_CONTENT--}:
335         <pre>' . print_r($content, true) . '</pre>
336 </div>';
337                 } else {
338                         // No file!
339                         $GLOBALS['template_eval'][$template] = '404';
340                 }
341         }
342
343         // Code set?
344         if ((isset($GLOBALS['template_eval'][$template])) && ($GLOBALS['template_eval'][$template] != '404')) {
345                 // Eval the code
346                 eval($GLOBALS['template_eval'][$template]);
347         } // END - if
348
349         // Do we have some content to output or return?
350         if (!empty($ret)) {
351                 // Not empty so let's put it out! ;)
352                 if ($return === true) {
353                         // Return the HTML code
354                         return $ret;
355                 } else {
356                         // Output directly
357                         outputHtml($ret);
358                 }
359         } elseif (isDebugModeEnabled()) {
360                 // Warning, empty output!
361                 return 'E:' . $template . ',content=<pre>' . print_r($content, true) . '</pre>';
362         }
363 }
364
365 // Detects the extra template path from given template name
366 function detectExtraTemplatePath ($template) {
367         // Default is empty
368         $extraPath = '';
369
370         // Do we have cache?
371         if (!isset($GLOBALS['extra_path'][$template])) {
372                 // Check for admin/guest/member/etc. templates
373                 if (substr($template, 0, 6) == 'admin_') {
374                         // Admin template found
375                         $extraPath = 'admin/';
376                 } elseif (substr($template, 0, 6) == 'guest_') {
377                         // Guest template found
378                         $extraPath = 'guest/';
379                 } elseif (substr($template, 0, 7) == 'member_') {
380                         // Member template found
381                         $extraPath = 'member/';
382                 } elseif (substr($template, 0, 7) == 'select_') {
383                         // Selection template found
384                         $extraPath = 'select/';
385                 } elseif (substr($template, 0, 8) == 'install_') {
386                         // Installation template found
387                         $extraPath = 'install/';
388                 } elseif (substr($template, 0, 4) == 'ext_') {
389                         // Extension template found
390                         $extraPath = 'ext/';
391                 } elseif (substr($template, 0, 3) == 'la_') {
392                         // 'Logical-area' template found
393                         $extraPath = 'la/';
394                 } elseif (substr($template, 0, 3) == 'js_') {
395                         // JavaScript template found
396                         $extraPath = 'js/';
397                 } elseif (substr($template, 0, 5) == 'menu_') {
398                         // Menu template found
399                         $extraPath = 'menu/';
400                 } else {
401                         // Test for extension
402                         $test = substr($template, 0, strpos($template, '_'));
403
404                         // Probe for valid extension name
405                         if (isExtensionNameValid($test)) {
406                                 // Set extra path to extension's name
407                                 $extraPath = $test . '/';
408                         } // END - if
409                 }
410
411                 // Store it in cache
412                 $GLOBALS['extra_path'][$template] = $extraPath;
413         } // END - if
414
415         // Return result
416         return $GLOBALS['extra_path'][$template];
417 }
418
419 // Loads an email template and compiles it
420 function loadEmailTemplate ($template, $content = array(), $userid = '0', $loadUserData = true) {
421         global $DATA;
422
423         // Make sure all template names are lowercase!
424         $template = strtolower($template);
425
426         // Is content an array?
427         if (is_array($content)) {
428                 // Add expiration to array
429                 if ((isConfigEntrySet('auto_purge')) && (getAutoPurge() == '0')) {
430                         // Will never expire!
431                         $content['expiration'] = '{--MAIL_WILL_NEVER_EXPIRE--}';
432                 } elseif (isConfigEntrySet('auto_purge')) {
433                         // Create nice date string
434                         $content['expiration'] = '{%config,createFancyTime=auto_purge%}';
435                 } else {
436                         // Missing entry
437                         $content['expiration'] = '{--MAIL_NO_CONFIG_AUTO_PURGE--}';
438                 }
439         } // END - if
440
441         // Load user's data
442         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UID={$userid},template={$template},content[]=".gettype($content));
443         if ((isValidUserId($userid)) && (is_array($content))) {
444                 // If nickname extension is installed, fetch nickname as well
445                 if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
446                         // Load by nickname
447                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NICKNAME!<br />");
448                         fetchUserData($userid, 'nickname');
449                 } elseif (isNicknameUsed($userid)) {
450                         // Non-number characters entered but no ext-nickname found
451                         debug_report_bug(__FUNCTION__, __LINE__, 'userid=' . $userid . ': is no id number and ext-nickname is gone.');
452                 } else {
453                         // Load by userid
454                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NO-NICK!<br />");
455                         fetchUserData($userid);
456                 }
457
458                 // Merge data if valid
459                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - PRE<br />");
460                 if ((isUserDataValid()) && ($loadUserData === true)) {
461                         // It is valid
462                         $content = merge_array($content, getUserDataArray());
463
464                         // But we don't like hashed passwords be mailed
465                         unset($content['password']);
466                 } // END - if
467
468                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - AFTER<br />");
469         } // END - if
470
471         // Base directory
472         $basePath = sprintf("%stemplates/%s/emails/", getPath(), getLanguage());
473
474         // Detect extra path
475         $extraPath = detectExtraTemplatePath($template);
476
477         // Generate full FQFN
478         $FQFN = $basePath . $extraPath . $template . '.tpl';
479
480         // Does the special template exists?
481         if (!isFileReadable($FQFN)) {
482                 // Reset to default template
483                 $FQFN = $basePath . $template . '.tpl';
484         } // END - if
485
486         // Now does the final template exists?
487         $newContent = '';
488         if (isFileReadable($FQFN)) {
489                 // The local file does exists so we load it. :)
490                 $GLOBALS['tpl_content'][$template] = readFromFile($FQFN);
491
492                 // Run code
493                 $GLOBALS['tpl_content'][$template] = '$newContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'][$template])) . '");';
494                 eval($GLOBALS['tpl_content'][$template]);
495         } elseif (!empty($template)) {
496                 // Template file not found
497                 $newContent = '<div class="para">
498         {--TEMPLATE_404--}: ' . $template . '
499 </div>
500 <div class="para">
501         {--TEMPLATE_CONTENT--}:
502         <pre>' . print_r($content, true) . '</pre>
503         {--TEMPLATE_DATA--}:
504         <pre>' . print_r($DATA, true) . '</pre>
505 </div>';
506
507                 // Debug mode not active? Then remove the HTML tags
508                 if (!isDebugModeEnabled()) {
509                         // Remove HTML tags
510                         $newContent = secureString($newContent);
511                 } // END - if
512         } else {
513                 // No template name supplied!
514                 $newContent = '{--NO_TEMPLATE_SUPPLIED--}';
515         }
516
517         // Is there some content?
518         if (empty($newContent)) {
519                 // Compiling failed
520                 $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['tpl_content'][$template];
521
522                 // Add last error if the required function exists
523                 if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
524         } // END - if
525
526         // Remove content and data
527         unset($content);
528         unset($DATA);
529
530         // Return content
531         return $newContent;
532 }
533
534 // "Getter" for menu CSS classes, mainly used in templates
535 function getMenuCssClasses ($data) {
536         // $data needs to be converted into an array
537         $content = explode('|', $data);
538
539         // Non-existent index 2 will happen in menu blocks
540         if (!isset($content[2])) $content[2] = '';
541
542         // Re-construct the array: 0=visible,1=locked,2=prefix
543         $content['visible'] = $content[0];
544         $content['locked']  = $content[1];
545
546         // Call our "translator" function
547         $content = translateMenuVisibleLocked($content, $content[2]);
548
549         // Return CSS classes
550         return ($content['visible_css'] . ' ' . $content['locked_css']);
551 }
552
553 // Generate XHTML code for the CAPTCHA
554 function generateCaptchaCode ($code, $type, $type, $userid) {
555         return '<img border="0" alt="Code ' . $code . '" src="{%url=mailid_top.php?userid=' . $userid . '&amp;' . $type . '=' . $type . '&amp;mode=img&amp;code=' . $code . '%}" />';
556 }
557
558 // Compiles the given HTML/mail code
559 function compileCode ($code, $simple = false, $constants = true, $full = true, $compileCode = true) {
560         // Is the code a string or should we not compile?
561         if ((!is_string($code)) || ($compileCode === false)) {
562                 // Silently return it
563                 return $code;
564         } // END - if
565
566         // Start couting
567         $startCompile = microtime(true);
568
569         // Comile the code
570         $code = compileRawCode($code, $simple, $constants, $full);
571
572         // Get timing
573         $compiled = microtime(true);
574
575         // Add timing if enabled
576         if (isTemplateHtml()) {
577                 // Add timing, this should be disabled in
578                 $code .= '<!-- Compilation time: ' . (($compiled - $startCompile) * 1000). 'ms //-->';
579         } // END - if
580
581         // Return compiled code
582         return $code;
583 }
584
585 // Compiles the code (use compileCode() only for HTML because of the comments)
586 // @TODO $simple/$constants are deprecated
587 function compileRawCode ($code, $simple = false, $constants = true, $full = true, $compileCode = true) {
588         // Is the code a string or shall we not compile?
589         if ((!is_string($code)) || ($compileCode === false)) {
590                 // Silently return it
591                 return $code;
592         } // END - if
593
594         // Init replacement-array with smaller set of security characters
595         $secChars = $GLOBALS['url_chars'];
596
597         // Select full set of chars to replace when we e.g. want to compile URLs
598         if ($full === true) {
599                 $secChars = $GLOBALS['security_chars'];
600         } // END - if
601
602         // Compile more through a filter
603         $code = runFilterChain('compile_code', $code);
604
605         // Compile message strings
606         $code = str_replace('{--', '{%message,', str_replace('--}', '%}', $code));
607
608         // Compile QUOT and other non-HTML codes
609         $code = str_replace($secChars['to'], $secChars['from'], $code);
610
611         // Find $content[bla][blub] entries
612         // @TODO Do only use $content and deprecate $GLOBALS and $DATA in templates
613         preg_match_all('/\$(content|GLOBALS|DATA)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
614
615         // Are some matches found?
616         if ((count($matches) > 0) && (count($matches[0]) > 0)) {
617                 // Replace all matches
618                 $matchesFound = array();
619                 foreach ($matches[0] as $key => $match) {
620                         // Fuzzy look has failed by default
621                         $fuzzyFound = false;
622
623                         // Fuzzy look on match if already found
624                         foreach ($matchesFound as $found => $set) {
625                                 // Get test part
626                                 $test = substr($found, 0, strlen($match));
627
628                                 // Does this entry exist?
629                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "found={$found},match={$match},set={$set}<br />");
630                                 if ($test == $match) {
631                                         // Match found
632                                         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "fuzzyFound!<br />");
633                                         $fuzzyFound = true;
634                                         break;
635                                 } // END - if
636                         } // END - foreach
637
638                         // Skip this entry?
639                         if ($fuzzyFound === true) continue;
640
641                         // Take all string elements
642                         if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key.'_' . $matches[4][$key]]))) {
643                                 // Replace it in the code
644                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "key={$key},match={$match}<br />");
645                                 $newMatch = str_replace('[', "['", str_replace(']', "']", $match));
646                                 $code = str_replace($match, '".' . $newMatch . '."', $code);
647                                 $matchesFound[$key . '_' . $matches[4][$key]] = 1;
648                                 $matchesFound[$match] = 1;
649                         } elseif (!isset($matchesFound[$match])) {
650                                 // Not yet replaced!
651                                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "match={$match}<br />");
652                                 $code = str_replace($match, '".' . $match . '."', $code);
653                                 $matchesFound[$match] = 1;
654                         }
655                 } // END - foreach
656         } // END - if
657
658         // Return it
659         return $code;
660 }
661
662 //
663 function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 'form_select') {
664         $OUT = '';
665
666         if ($type == 'yn') {
667                 // This is a yes/no selection only!
668                 if ($id > 0) $prefix .= '[' . $id . ']';
669                 $OUT .= '<select name="' . $prefix . '" class="' . $class . '" size="1">';
670         } else {
671                 // Begin with regular selection box here
672                 if (!empty($prefix)) $prefix .= '_';
673                 $type2 = $type;
674                 if ($id > 0) $type2 .= '[' . $id . ']';
675                 $OUT .= '<select name="' . strtolower($prefix . $type2) . '" class="' . $class . '" size="1">';
676         }
677
678         switch ($type) {
679                 case 'day': // Day
680                         for ($idx = 1; $idx < 32; $idx++) {
681                                 $OUT .= '<option value="' . $idx . '"';
682                                 if ($default == $idx) $OUT .= ' selected="selected"';
683                                 $OUT .= '>' . $idx . '</option>';
684                         } // END - for
685                         break;
686
687                 case 'month': // Month
688                         foreach ($GLOBALS['month_descr'] as $idx => $descr) {
689                                 $OUT .= '<option value="' . $idx . '"';
690                                 if ($default == $idx) $OUT .= ' selected="selected"';
691                                 $OUT .= '>' . $descr . '</option>';
692                         } // END - for
693                         break;
694
695                 case 'year': // Year
696                         // Get current year
697                         $year = getYear();
698
699                         // Use configured min age or fixed?
700                         if (isExtensionInstalledAndNewer('other', '0.2.1')) {
701                                 // Configured
702                                 $startYear = $year - getConfig('min_age');
703                         } else {
704                                 // Fixed 16 years
705                                 $startYear = $year - 16;
706                         }
707
708                         // Calculate earliest year (100 years old people can still enter Internet???)
709                         $minYear = $year - 100;
710
711                         // Check if the default value is larger than minimum and bigger than actual year
712                         if (($default > $minYear) && ($default >= $year)) {
713                                 for ($idx = $year; $idx < ($year + 11); $idx++) {
714                                         $OUT .= '<option value="' . $idx . '"';
715                                         if ($default == $idx) $OUT .= ' selected="selected"';
716                                         $OUT .= '>' . $idx . '</option>';
717                                 } // END - for
718                         } elseif ($default == -1) {
719                                 // Current year minus 1
720                                 for ($idx = $startYear; $idx <= ($year + 1); $idx++) {
721                                         $OUT .= '<option value="' . $idx . '">' . $idx . '</option>';
722                                 } // END - for
723                         } else {
724                                 // Get current year and subtract the configured minimum age
725                                 $OUT .= '<option value="' . ($minYear - 1) . '">&lt;' . $minYear . '</option>';
726                                 // Calculate earliest year depending on extension version
727                                 if (isExtensionInstalledAndNewer('other', '0.2.1')) {
728                                         // Use configured minimum age
729                                         $year = getYear() - getConfig('min_age');
730                                 } else {
731                                         // Use fixed 16 years age
732                                         $year = getYear() - 16;
733                                 }
734
735                                 // Construct year selection list
736                                 for ($idx = $minYear; $idx <= $year; $idx++) {
737                                         $OUT .= '<option value="' . $idx . '"';
738                                         if ($default == $idx) $OUT .= ' selected="selected"';
739                                         $OUT .= '>' . $idx . '</option>';
740                                 } // END - for
741                         }
742                         break;
743
744                 case 'sec':
745                 case 'min':
746                         for ($idx = 0; $idx < 60; $idx+=5) {
747                                 if (strlen($idx) == 1) $idx = '0' . $idx;
748                                 $OUT .= '<option value="' . $idx . '"';
749                                 if ($default == $idx) $OUT .= ' selected="selected"';
750                                 $OUT .= '>' . $idx . '</option>';
751                         } // END - for
752                         break;
753
754                 case 'hour':
755                         for ($idx = 0; $idx < 24; $idx++) {
756                                 if (strlen($idx) == 1) $idx = '0' . $idx;
757                                 $OUT .= '<option value="' . $idx . '"';
758                                 if ($default == $idx) $OUT .= ' selected="selected"';
759                                 $OUT .= '>' . $idx . '</option>';
760                         } // END - for
761                         break;
762
763                 case 'yn':
764                         $OUT .= '<option value="Y"';
765                         if ($default == 'Y') $OUT .= ' selected="selected"';
766                         $OUT .= '>{--YES--}</option><option value="N"';
767                         if ($default != 'Y') $OUT .= ' selected="selected"';
768                         $OUT .= '>{--NO--}</option>';
769                         break;
770         }
771         $OUT .= '</select>';
772         return $OUT;
773 }
774
775 // Insert the code in $img_code into jpeg or PNG image
776 function generateImageOrCode ($img_code, $headerSent = true) {
777         // Is the code size oversized or shouldn't we display it?
778         if ((strlen($img_code) > 6) || (empty($img_code)) || (getCodeLength() == '0')) {
779                 // Stop execution of function here because of over-sized code length
780                 debug_report_bug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getCodeLength());
781         } elseif ($headerSent === false) {
782                 // Return an HTML code here
783                 return '<img src="{%url=img.php?code=' . $img_code . '%}" alt="Image" />';
784         }
785
786         // Load image
787         $img = sprintf("%s/theme/%s/images/code_bg.%s",
788                 getPath(),
789                 getCurrentTheme(),
790                 getImgType()
791         );
792
793         // Is it readable?
794         if (isFileReadable($img)) {
795                 // Switch image type
796                 switch (getImgType()) {
797                         case 'jpg': // Okay, load image and hide all errors
798                                 $image = imagecreatefromjpeg($img);
799                                 break;
800
801                         case 'png': // Okay, load image and hide all errors
802                                 $image = imagecreatefrompng($img);
803                                 break;
804                 } // END - switch
805         } else {
806                 // Silently log the error
807                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image-type %s in theme %s not found.", getImgType(), getCurrentTheme()));
808                 return;
809         }
810
811         // Generate text color (red/green/blue; 0 = dark, 255 = bright)
812         $text_color = imagecolorallocate($image, 0, 0, 0);
813
814         // Insert code into image
815         imagestring($image, 5, 14, 2, $img_code, $text_color);
816
817         // Return to browser
818         setContentType('image/' . getImgType());
819
820         // Output image with matching image factory
821         switch (getImgType()) {
822                 case 'jpg': imagejpeg($image); break;
823                 case 'png': imagepng($image);  break;
824         } // END - switch
825
826         // Remove image from memory
827         imagedestroy($image);
828 }
829
830 // Create selection box or array of splitted timestamp
831 function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $return_array=false) {
832         // Do not continue if ONE_DAY is absend
833         if (!isConfigEntrySet('ONE_DAY')) {
834                 // And return the timestamp itself or empty array
835                 if ($return_array === true) {
836                         return array();
837                 } else {
838                         return $timestamp;
839                 }
840         } // END - if
841
842         // Calculate 2-seconds timestamp
843         $stamp = round($timestamp);
844         //* DEBUG: */ debugOutput('*' . $stamp .'/' . $timestamp . '*');
845
846         // Do we have a leap year?
847         $SWITCH = '0';
848         $TEST = getYear() / 4;
849         $M1 = getMonth();
850         $M2 = getMonth(time() + $timestamp);
851
852         // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
853         if ((floor($TEST) == $TEST) && ($M1 == '02') && ($M2 > '02'))  {
854                 $SWITCH = getOneDay();
855         } // END - switch
856
857         // First of all years...
858         $Y = abs(floor($timestamp / (31536000 + $SWITCH)));
859         //* DEBUG: */ debugOutput('Y=' . $Y);
860         // Next months...
861         $M = abs(floor($timestamp / 2628000 - $Y * 12));
862         //* DEBUG: */ debugOutput('M=' . $M);
863         // Next weeks
864         $W = abs(floor($timestamp / 604800 - $Y * ((365 + $SWITCH / getOneDay()) / 7) - ($M / 12 * (365 + $SWITCH / getOneDay()) / 7)));
865         //* DEBUG: */ debugOutput('W=' . $W);
866         // Next days...
867         $D = abs(floor($timestamp / 86400 - $Y * (365 + $SWITCH / getOneDay()) - ($M / 12 * (365 + $SWITCH / getOneDay())) - $W * 7));
868         //* DEBUG: */ debugOutput('D=' . $D);
869         // Next hours...
870         $h = abs(floor($timestamp / 3600 - $Y * (365 + $SWITCH / getOneDay()) * 24 - ($M / 12 * (365 + $SWITCH / getOneDay()) * 24) - $W * 7 * 24 - $D * 24));
871         //* DEBUG: */ debugOutput('h=' . $h);
872         // Next minutes..
873         $m = abs(floor($timestamp / 60 - $Y * (365 + $SWITCH / getOneDay()) * 24 * 60 - ($M / 12 * (365 + $SWITCH / getOneDay()) * 24 * 60) - $W * 7 * 24 * 60 - $D * 24 * 60 - $h * 60));
874         //* DEBUG: */ debugOutput('m=' . $m);
875         // And at last seconds...
876         $s = abs(floor($timestamp - $Y * (365 + $SWITCH / getOneDay()) * 24 * 3600 - ($M / 12 * (365 + $SWITCH / getOneDay()) * 24 * 3600) - $W * 7 * 24 * 3600 - $D * 24 * 3600 - $h * 3600 - $m * 60));
877         //* DEBUG: */ debugOutput('s=' . $s);
878
879         // Is seconds zero and time is < 60 seconds?
880         if (($s == '0') && ($timestamp < 60)) {
881                 // Fix seconds
882                 $s = round($timestamp);
883         } // END - if
884
885         //
886         // Now we convert them in seconds...
887         //
888         if ($return_array) {
889                 // Just put all data in an array for later use
890                 $OUT = array(
891                         'YEARS'   => $Y,
892                         'MONTHS'  => $M,
893                         'WEEKS'   => $W,
894                         'DAYS'    => $D,
895                         'HOURS'   => $h,
896                         'MINUTES' => $m,
897                         'SECONDS' => $s
898                 );
899         } else {
900                 // Generate table
901                 $OUT  = '<div align="' . $align . '">';
902                 $OUT .= '<table border="0" cellspacing="0" cellpadding="0" class="timebox_table dashed">';
903                 $OUT .= '<tr>';
904
905                 if (isInString('Y', $display) || (empty($display))) {
906                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_YEARS--}</strong></td>';
907                 } // END - if
908
909                 if (isInString('M', $display) || (empty($display))) {
910                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MONTHS--}</strong></td>';
911                 } // END - if
912
913                 if (isInString('W', $display) || (empty($display))) {
914                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_WEEKS--}</strong></td>';
915                 } // END - if
916
917                 if (isInString('D', $display) || (empty($display))) {
918                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_DAYS--}</strong></td>';
919                 } // END - if
920
921                 if (isInString('h', $display) || (empty($display))) {
922                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_HOURS--}</strong></td>';
923                 } // END - if
924
925                 if (isInString('m', $display) || (empty($display))) {
926                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MINUTES--}</strong></td>';
927                 } // END - if
928
929                 if (isInString('s', $display) || (empty($display))) {
930                         $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_SECONDS--}</strong></td>';
931                 } // END - if
932
933                 $OUT .= '</tr>';
934                 $OUT .= '<tr>';
935
936                 if (isInString('Y', $display) || (empty($display))) {
937                         // Generate year selection
938                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_ye" size="1">';
939                         for ($idx = 0; $idx <= 10; $idx++) {
940                                 $OUT .= '<option class="mini_select" value="' . $idx . '"';
941                                 if ($idx == $Y) $OUT .= ' selected="selected"';
942                                 $OUT .= '>' . $idx . '</option>';
943                         } // END - for
944                         $OUT .= '</select></td>';
945                 } else {
946                         $OUT .= '<input type="hidden" name="' . $prefix . '_ye" value="0" />';
947                 }
948
949                 if (isInString('M', $display) || (empty($display))) {
950                         // Generate month selection
951                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_mo" size="1">';
952                         for ($idx = 0; $idx <= 11; $idx++) {
953                                 $OUT .= '  <option class="mini_select" value="' . $idx . '"';
954                                 if ($idx == $M) $OUT .= ' selected="selected"';
955                                 $OUT .= '>' . $idx . '</option>';
956                         } // END - for
957                         $OUT .= '</select></td>';
958                 } else {
959                         $OUT .= '<input type="hidden" name="' . $prefix . '_mo" value="0" />';
960                 }
961
962                 if (isInString('W', $display) || (empty($display))) {
963                         // Generate week selection
964                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_we" size="1">';
965                         for ($idx = 0; $idx <= 4; $idx++) {
966                                 $OUT .= '  <option class="mini_select" value="' . $idx . '"';
967                                 if ($idx == $W) $OUT .= ' selected="selected"';
968                                 $OUT .= '>' . $idx . '</option>';
969                         } // END - for
970                         $OUT .= '</select></td>';
971                 } else {
972                         $OUT .= '<input type="hidden" name="' . $prefix . '_we" value="0" />';
973                 }
974
975                 if (isInString('D', $display) || (empty($display))) {
976                         // Generate day selection
977                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_da" size="1">';
978                         for ($idx = 0; $idx <= 31; $idx++) {
979                                 $OUT .= '  <option class="mini_select" value="' . $idx . '"';
980                                 if ($idx == $D) $OUT .= ' selected="selected"';
981                                 $OUT .= '>' . $idx . '</option>';
982                         } // END - for
983                         $OUT .= '</select></td>';
984                 } else {
985                         $OUT .= '<input type="hidden" name="' . $prefix . '_da" value="0" />';
986                 }
987
988                 if (isInString('h', $display) || (empty($display))) {
989                         // Generate hour selection
990                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_ho" size="1">';
991                         for ($idx = 0; $idx <= 23; $idx++) {
992                                 $OUT .= '  <option class="mini_select" value="' . $idx . '"';
993                                 if ($idx == $h) $OUT .= ' selected="selected"';
994                                 $OUT .= '>' . $idx . '</option>';
995                         } // END - for
996                         $OUT .= '</select></td>';
997                 } else {
998                         $OUT .= '<input type="hidden" name="' . $prefix . '_ho" value="0" />';
999                 }
1000
1001                 if (isInString('m', $display) || (empty($display))) {
1002                         // Generate minute selection
1003                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_mi" size="1">';
1004                         for ($idx = 0; $idx <= 59; $idx++) {
1005                                 $OUT .= '  <option class="mini_select" value="' . $idx . '"';
1006                                 if ($idx == $m) $OUT .= ' selected="selected"';
1007                                 $OUT .= '>' . $idx . '</option>';
1008                         } // END - for
1009                         $OUT .= '</select></td>';
1010                 } else {
1011                         $OUT .= '<input type="hidden" name="' . $prefix . '_mi" value="0" />';
1012                 }
1013
1014                 if (isInString('s', $display) || (empty($display))) {
1015                         // Generate second selection
1016                         $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_se" size="1">';
1017                         for ($idx = 0; $idx <= 59; $idx++) {
1018                                 $OUT .= '  <option class="mini_select" value="' . $idx . '"';
1019                                 if ($idx == $s) $OUT .= ' selected="selected"';
1020                                 $OUT .= '>' . $idx . '</option>';
1021                         } // END - for
1022                         $OUT .= '</select></td>';
1023                 } else {
1024                         $OUT .= '<input type="hidden" name="' . $prefix . '_se" value="0" />';
1025                 }
1026                 $OUT .= '</tr>';
1027                 $OUT .= '</table>';
1028                 $OUT .= '</div>';
1029         }
1030
1031         // Return generated HTML code
1032         return $OUT;
1033 }
1034
1035 // Generate a list of administrative links to a given userid
1036 function generateMemberAdminActionLinks ($userid) {
1037         // Make sure userid is a number
1038         if ($userid != bigintval($userid)) {
1039                 debug_report_bug(__FUNCTION__, __LINE__, 'userid is not a number!');
1040         } // END - if
1041
1042         // Define all main targets
1043         $targetArray = array('del_user', 'edit_user', 'lock_user', 'add_points', 'sub_points');
1044
1045         // Get user status
1046         $status = getFetchedUserData('userid', $userid, 'status');
1047
1048         // Begin of navigation links
1049         $OUT = '[';
1050
1051         foreach ($targetArray as $tar) {
1052                 $OUT .= '<span class="admin_user_link"><a href="{%url=modules.php?module=admin&amp;what=' . $tar . '&amp;userid=' . $userid . '%}" title="{--ADMIN_USER_ACTION_LINK_';
1053                 //* DEBUG: */ debugOutput('*' . $tar.'/' . $status.'*');
1054                 if (($tar == 'lock_user') && ($status == 'LOCKED')) {
1055                         // Locked accounts shall be unlocked
1056                         $OUT .= 'UNLOCK_USER';
1057                 } elseif ($tar == 'del_user') {
1058                         // @TODO Deprecate this thing
1059                         $OUT .= 'DELETE_USER';
1060                 } else {
1061                         // All other status is fine
1062                         $OUT .= strtoupper($tar);
1063                 }
1064                 $OUT .= '_TITLE--}">{--ADMIN_USER_ACTION_LINK_';
1065                 if (($tar == 'lock_user') && ($status == 'LOCKED')) {
1066                         // Locked accounts shall be unlocked
1067                         $OUT .= 'UNLOCK_USER';
1068                 } elseif ($tar == 'del_user') {
1069                         // @TODO Deprecate this thing
1070                         $OUT .= 'DELETE_USER';
1071                 } else {
1072                         // All other status is fine
1073                         $OUT .= strtoupper($tar);
1074                 }
1075                 $OUT .= '--}</a></span>|';
1076         } // END - foreach
1077
1078         // Finish navigation link
1079         $OUT = substr($OUT, 0, -1) . ']';
1080
1081         // Return string
1082         return $OUT;
1083 }
1084
1085 // Generate an email link
1086 function generateEmailLink ($email, $table = 'admins') {
1087         // Default email link (INSECURE! Spammer can read this by harvester programs)
1088         $EMAIL = 'mailto:' . $email;
1089
1090         // Check for several extensions
1091         if ((isExtensionActive('admins')) && ($table == 'admins')) {
1092                 // Create email link for contacting admin in guest area
1093                 $EMAIL = generateAdminEmailLink($email);
1094         } elseif ((isExtensionInstalledAndNewer('user', '0.3.3')) && ($table == 'user_data')) {
1095                 // Create email link for contacting a member within admin area (or later in other areas, too?)
1096                 $EMAIL = generateUserEmailLink($email);
1097         } elseif ((isExtensionActive('sponsor')) && ($table == 'sponsor_data')) {
1098                 // Create email link to contact sponsor within admin area (or like the link above?)
1099                 $EMAIL = generateSponsorEmailLink($email);
1100         }
1101
1102         // Shall I close the link when there is no admin?
1103         if ((!isAdmin()) && ($EMAIL == $email)) $EMAIL = '#'; // Closed!
1104
1105         // Return email link
1106         return $EMAIL;
1107 }
1108
1109 // Output error messages in a fasioned way and die...
1110 function app_die ($F, $L, $message) {
1111         // Check if Script is already dieing and not let it kill itself another 1000 times
1112         if (isset($GLOBALS['app_died'])) {
1113                 // Script tried to kill itself twice
1114                 die('[' . __FUNCTION__ . ':' . __LINE__ . ']: Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
1115         } // END - if
1116
1117         // Make sure, that the script realy realy diese here and now
1118         $GLOBALS['app_died'] = true;
1119
1120         // Set content type as text/html
1121         setContentType('text/html');
1122
1123         // Load header
1124         loadIncludeOnce('inc/header.php');
1125
1126         // Rewrite message for output
1127         $message = sprintf(getMessage('MAILER_HAS_DIED'), basename($F), $L, $message);
1128
1129         // Load the message template
1130         loadTemplate('app_die_message', false, $message);
1131
1132         // Load footer
1133         loadIncludeOnce('inc/footer.php');
1134 }
1135
1136 // Display parsing time and number of SQL queries in footer
1137 function displayParsingTime () {
1138         // Is the timer started?
1139         if (!isset($GLOBALS['startTime'])) {
1140                 // Abort here
1141                 return false;
1142         } // END - if
1143
1144         // Get end time
1145         $endTime = microtime(true);
1146
1147         // "Explode" both times
1148         $start = explode(' ', $GLOBALS['startTime']);
1149         $end = explode(' ', $endTime);
1150         $runTime = $end[0] - $start[0];
1151         if ($runTime < 0) {
1152                 $runTime = '0';
1153         } // END - if
1154
1155         // Prepare output
1156         // @TODO This can be easily moved out after the merge from EL branch to this is complete
1157         $content = array(
1158                 'run_time' => $runTime,
1159                 'sql_time' => (getConfig('sql_time') * 1000),
1160         );
1161
1162         // Load the template
1163         $GLOBALS['page_footer'] .= loadTemplate('show_timings', true, $content);
1164 }
1165
1166 // Output a debug backtrace to the user
1167 function debug_report_bug ($F, $L, $message = '', $sendEmail = true) {
1168         // Is this already called?
1169         if (isset($GLOBALS[__FUNCTION__])) {
1170                 // Other backtrace
1171                 print 'Message:' . $message . '<br />Backtrace:<pre>';
1172                 debug_print_backtrace();
1173                 die('</pre>');
1174         } // END - if
1175
1176         // Set this function as called
1177         $GLOBALS[__FUNCTION__] = true;
1178
1179         // Init message
1180         $debug = '';
1181
1182         // Is the optional message set?
1183         if (!empty($message)) {
1184                 // Use and log it
1185                 $debug = sprintf("Note: %s<br />\n",
1186                         $message
1187                 );
1188
1189                 // @TODO Add a little more infos here
1190                 logDebugMessage($F, $L, strip_tags($message));
1191         } // END - if
1192
1193         // Add output
1194         $debug .= 'Please report this bug at <a title="Direct link to the bug-tracker" href="http://bugs.mxchange.org" rel="external" target="_blank">http://bugs.mxchange.org</a> and include the logfile from <strong>' . str_replace(getPath(), '', getCachePath()) . 'debug.log</strong> in your report (you can now attach files):<pre>';
1195         $debug .= debug_get_printable_backtrace();
1196         $debug .= '</pre>';
1197         $debug .= '<div class="para">Request-URI: ' . getRequestUri() . '</div>';
1198         $debug .= '<div class="para">Thank you for finding bugs.</div>';
1199
1200         // Send an email? (e.g. not wanted for evaluation errors)
1201         if (($sendEmail === true) && (!isInstallationPhase())) {
1202                 // Prepare content
1203                 $content = array(
1204                         'message'   => trim($message),
1205                         'backtrace' => trim(debug_get_mailable_backtrace())
1206                 );
1207
1208                 // Send email to webmaster
1209                 sendAdminNotification('{--DEBUG_REPORT_BUG_SUBJECT--}', 'admin_report_bug', $content);
1210         } // END - if
1211
1212         // And abort here
1213         app_die($F, $L, $debug);
1214 }
1215
1216 // Compile characters which are allowed in URLs
1217 function compileUriCode ($code, $simple = true) {
1218         // Compile constants
1219         if ($simple === false) $code = str_replace('{--', '".', str_replace('--}', '."', $code));
1220
1221         // Compile QUOT and other non-HTML codes
1222         $code = str_replace('{DOT}', '.',
1223                 str_replace('{SLASH}', '/',
1224                 str_replace('{QUOT}', "'",
1225                 str_replace('{DOLLAR}', '$',
1226                 str_replace('{OPEN_ANCHOR}', '(',
1227                 str_replace('{CLOSE_ANCHOR}', ')',
1228                 str_replace('{OPEN_SQR}', '[',
1229                 str_replace('{CLOSE_SQR}', ']',
1230                 str_replace('{PER}', '%',
1231                 $code
1232         )))))))));
1233
1234         // Return compiled code
1235         return $code;
1236 }
1237
1238 // Handle message codes from URL
1239 function handleCodeMessage () {
1240         if (isGetRequestParameterSet('code')) {
1241                 // Default extension is 'unknown'
1242                 $ext = 'unknown';
1243
1244                 // Is extension given?
1245                 if (isGetRequestParameterSet('ext')) {
1246                         $ext = getRequestParameter('ext');
1247                 } // END - if
1248
1249                 // Convert the 'code' parameter from URL to a human-readable message
1250                 $message = getMessageFromErrorCode(getRequestParameter('code'));
1251
1252                 // Load message template
1253                 loadTemplate('message', false, $message);
1254         } // END - if
1255 }
1256
1257 // Generates a 'extension foo out-dated' message
1258 function generateExtensionOutdatedMessage ($ext_name, $ext_ver) {
1259         // Is the extension empty?
1260         if (empty($ext_name)) {
1261                 // This should not happen
1262                 debug_report_bug(__FUNCTION__, __LINE__, 'Parameter ext is empty. This should not happen.');
1263         } // END - if
1264
1265         // Default message
1266         $message = '{%message,EXTENSION_PROBLEM_EXTENSION_OUTDATED=' . $ext_name . '%}';
1267
1268         // Is an admin logged in?
1269         if (isAdmin()) {
1270                 // Then output admin message
1271                 $message = sprintf(getMessage('ADMIN_EXTENSION_PROBLEM_EXTENSION_INACTIVE'), $ext_name, $ext_name, $ext_ver);
1272         } // END - if
1273
1274         // Return prepared message
1275         return $message;
1276 }
1277
1278 // Generates a 'extension foo inactive' message
1279 function generateExtensionInactiveMessage ($ext_name) {
1280         // Is the extension empty?
1281         if (empty($ext_name)) {
1282                 // This should not happen
1283                 debug_report_bug(__FUNCTION__, __LINE__, 'Parameter ext is empty. This should not happen.');
1284         } // END - if
1285
1286         // Default message
1287         $message = '{%message,EXTENSION_PROBLEM_EXTENSION_INACTIVE=' . $ext_name . '%}';
1288
1289         // Is an admin logged in?
1290         if (isAdmin()) {
1291                 // Then output admin message
1292                 $message = '{%message,ADMIN_EXTENSION_PROBLEM_EXTENSION_INACTIVE=' . $ext_name . '%}';
1293         } // END - if
1294
1295         // Return prepared message
1296         return $message;
1297 }
1298
1299 // Generates a 'extension foo not installed' message
1300 function generateExtensionNotInstalledMessage ($ext_name) {
1301         // Is the extension empty?
1302         if (empty($ext_name)) {
1303                 // This should not happen
1304                 debug_report_bug(__FUNCTION__, __LINE__, 'Parameter ext is empty. This should not happen.');
1305         } // END - if
1306
1307         // Default message
1308         $message = '{%message,EXTENSION_PROBLEM_EXTENSION_NOT_INSTALLED=' . $ext_name . '%}';
1309
1310         // Is an admin logged in?
1311         if (isAdmin()) {
1312                 // Then output admin message
1313                 $message = '{%message,ADMIN_EXTENSION_PROBLEM_EXTENSION_NOT_INSTALLED=' . $ext_name . '%}';
1314         } // END - if
1315
1316         // Return prepared message
1317         return $message;
1318 }
1319
1320 // Generates a message depending on if the extension is not installed or not
1321 // just activated
1322 function generateExtensionInactiveNotInstalledMessage ($ext_name) {
1323         // Init message
1324         $message = '';
1325
1326         // Is the extension not installed or just deactivated?
1327         switch (isExtensionInstalled($ext_name)) {
1328                 case true; // Deactivated!
1329                         $message = generateExtensionInactiveMessage($ext_name);
1330                         break;
1331
1332                 case false; // Not installed!
1333                         $message = generateExtensionNotInstalledMessage($ext_name);
1334                         break;
1335
1336                 default: // Should not happen!
1337                         logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid state of extension %s detected.", $ext_name));
1338                         $message = sprintf("Invalid state of extension %s detected.", $ext_name);
1339                         break;
1340         } // END - switch
1341
1342         // Return the message
1343         return $message;
1344 }
1345
1346 // Print code with line numbers
1347 function linenumberCode ($code)    {
1348         if (!is_array($code)) $codeE = explode("\n", $code); else $codeE = $code;
1349         $count_lines = count($codeE);
1350
1351         $r = 'Line | Code:<br />';
1352         foreach ($codeE as $line => $c) {
1353                 $r .= '<div class="line"><span class="linenum">';
1354                 if ($count_lines == 1) {
1355                         $r .= 1;
1356                 } else {
1357                         $r .= ($line == ($count_lines - 1)) ? '' : ($line+1);
1358                 }
1359                 $r .= '</span>|';
1360
1361                 // Add code
1362                 $r .= '<span class="linetext">' . encodeEntities($c) . '</span></div>';
1363         } // END - foreach
1364
1365         return '<div class="code">' . $r . '</div>';
1366 }
1367
1368 // Determines the right page title
1369 function determinePageTitle () {
1370         // Config and database connection valid?
1371         if ((isConfigLocalLoaded()) && (isConfigurationLoaded()) && (SQL_IS_LINK_UP()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
1372                 // Init title
1373                 $TITLE = '';
1374
1375                 // Title decoration enabled?
1376                 if ((isTitleDecorationEnabled()) && (getConfig('title_left') != '')) $TITLE .= trim(getConfig('title_left')) . ' ';
1377
1378                 // Do we have some extra title?
1379                 if (isExtraTitleSet()) {
1380                         // Then prepent it
1381                         $TITLE .= getExtraTitle() . ' by ';
1382                 } // END - if
1383
1384                 // Add main title
1385                 $TITLE .= getMainTitle();
1386
1387                 // Add title of module? (middle decoration will also be added!)
1388                 if ((isModuleTitleEnabled()) || ((!isWhatSet()) && (!isActionSet())) || (getModule() == 'admin')) {
1389                         $TITLE .= ' ' . trim(getConfig('title_middle')) . ' {DQUOTE} . getModuleTitle(getModule()) . {DQUOTE}';
1390                 } // END - if
1391
1392                 // Add title from what file
1393                 $mode = '';
1394                 if (getModule() == 'login') $mode = 'member';
1395                 elseif (getModule() == 'index') $mode = 'guest';
1396                 if ((!empty($mode)) && (isWhatTitleEnabled())) $TITLE .= ' ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu($mode, getWhat());
1397
1398                 // Add title decorations? (right)
1399                 if ((isTitleDecorationEnabled()) && (getConfig('title_right') != '')) $TITLE .= ' ' . trim(getConfig('title_right'));
1400
1401                 // Remember title in constant for the template
1402                 $pageTitle = $TITLE;
1403         } elseif ((isInstalled()) && (isAdminRegistered())) {
1404                 // Installed, admin registered but no ext-sql_patches
1405                 $pageTitle = '[-- ' . getMainTitle() . ' - ' . getModuleTitle(getModule()) . ' --]';
1406         } elseif ((isInstalled()) && (!isAdminRegistered())) {
1407                 // Installed but no admin registered
1408                 $pageTitle = '{--INSTALLER_OF_MAILER_NO_ADMIN--}';
1409         } elseif ((!isInstalled()) || (!isAdminRegistered())) {
1410                 // Installation mode
1411                 $pageTitle = '{--INSTALLER_OF_MAILER--}';
1412         } else {
1413                 // Configuration not found
1414                 $pageTitle = '{--NO_CONFIG_FOUND_TITLE--}';
1415
1416                 // Do not add the fatal message in installation mode
1417                 if ((!isInstalling()) && (!isConfigurationLoaded())) addFatalMessage(__FUNCTION__, __LINE__, '{--NO_CONFIG_FOUND--}');
1418         }
1419
1420         // Return title
1421         return decodeEntities($pageTitle);
1422 }
1423
1424 // Checks wethere there is a cache file there. This function is cached.
1425 function isTemplateCached ($template) {
1426         // Do we have cached this result?
1427         if (!isset($GLOBALS['template_cache'][$template])) {
1428                 // Generate FQFN
1429                 $FQFN = generateCacheFqfn($template);
1430
1431                 // Is it there?
1432                 $GLOBALS['template_cache'][$template] = isFileReadable($FQFN);
1433         } // END - if
1434
1435         // Return it
1436         return $GLOBALS['template_cache'][$template];
1437 }
1438
1439 // Flushes non-flushed template cache to disk
1440 function flushTemplateCache ($template, $eval) {
1441         // Is this cache flushed?
1442         if ((isDebuggingTemplateCache() === false) && (isTemplateCached($template) === false) && ($eval != '404')) {
1443                 // Generate FQFN
1444                 $FQFN = generateCacheFqfn($template);
1445
1446                 // And flush it
1447                 writeToFile($FQFN, $eval, true);
1448         } // END - if
1449 }
1450
1451 // Reads a template cache
1452 function readTemplateCache ($template) {
1453         // Check it again
1454         if ((isDebuggingTemplateCache()) || (!isTemplateCached($template))) {
1455                 // This should not happen
1456                 debug_report_bug('Wether debugging of template cache is enabled or template ' . $template . ' is not cached while expected.');
1457         } // END - if
1458
1459         // Is it cached?
1460         if (!isset($GLOBALS['template_eval'][$template])) {
1461                 // Generate FQFN
1462                 $FQFN = generateCacheFqfn($template);
1463
1464                 // And read from it
1465                 $GLOBALS['template_eval'][$template] = readFromFile($FQFN);
1466         } // END - if
1467
1468         // And return it
1469         return $GLOBALS['template_eval'][$template];
1470 }
1471
1472 // Escapes quotes (default is only double-quotes)
1473 function escapeQuotes ($str, $single = false) {
1474         // Should we escape all?
1475         if ($single === true) {
1476                 // Escape all (including null)
1477                 $str = addslashes($str);
1478         } else {
1479                 // Remove escaping of single quotes
1480                 $str = str_replace("\\'", "'", $str);
1481
1482                 // Escape only double-quotes but prevent double-quoting
1483                 $str = str_replace("\\\\", "\\", str_replace('"', "\\\"", $str));
1484         }
1485
1486         // Return the escaped string
1487         return $str;
1488 }
1489
1490 // Escapes the JavaScript code, prevents \r and \n becoming char 10/13
1491 function escapeJavaScriptQuotes ($str) {
1492         // Replace all double-quotes and secure back-ticks
1493         $str = str_replace('"', '\"', str_replace("\\", '{BACK}', $str));
1494
1495         // Return it
1496         return $str;
1497 }
1498
1499 // Send out mails depending on the 'mod/modes' combination
1500 // @TODO Lame description for this function
1501 function sendModeMails ($mod, $modes) {
1502         // Init user data
1503         $content = array ();
1504
1505         // Load hash
1506         if (fetchUserData(getMemberId())) {
1507                 // Extract salt from cookie
1508                 $salt = substr(getSession('u_hash'), 0, -40);
1509
1510                 // Now let's compare passwords
1511                 $hash = encodeHashForCookie(getUserData('password'));
1512
1513                 // Does the hash match or should we change it?
1514                 if (($hash == getSession('u_hash')) || (postRequestParameter('pass1') == postRequestParameter('pass2'))) {
1515                         // Load the data
1516                         $content = getUserDataArray();
1517
1518                         // Clear/init the content variable
1519                         $content['message'] = '';
1520
1521                         // Which mail?
1522                         // @TODO Move this in a filter
1523                         switch ($mod) {
1524                                 case 'mydata':
1525                                         foreach ($modes as $mode) {
1526                                                 switch ($mode) {
1527                                                         case 'normal': break; // Do not add any special lines
1528                                                         case 'email': // Email was changed!
1529                                                                 $content['message'] = '{--MEMBER_CHANGED_EMAIL--}' . ': ' . postRequestParameter('old_email') . "\n";
1530                                                                 break;
1531
1532                                                         case 'password': // Password was changed
1533                                                                 $content['message'] = '{--MEMBER_CHANGED_PASS--}' . "\n";
1534                                                                 break;
1535
1536                                                         default:
1537                                                                 logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode));
1538                                                                 $content['message'] = '{--MEMBER_UNKNOWN_MODE--}' . ': ' . $mode . "\n\n";
1539                                                                 break;
1540                                                 } // END - switch
1541                                         } // END - foreach
1542
1543                                         if (isExtensionActive('country')) {
1544                                                 // Replace code with description
1545                                                 $content['country'] = generateCountryInfo(postRequestParameter('country_code'));
1546                                         } // END - if
1547
1548                                         // Merge content with data from POST
1549                                         $content = merge_array($content, postRequestArray());
1550
1551                                         // Load template
1552                                         $message = loadEmailTemplate('member_mydata_notify', $content, getMemberId());
1553
1554                                         if (isAdminNotificationEnabled()) {
1555                                                 // The admin needs to be notified about a profile change
1556                                                 $message_admin = 'admin_mydata_notify';
1557                                                 $sub_adm   = '{--ADMIN_CHANGED_DATA--}';
1558                                         } else {
1559                                                 // No mail to admin
1560                                                 $message_admin = '';
1561                                                 $sub_adm   = '';
1562                                         }
1563
1564                                         // Set subject lines
1565                                         $sub_mem = '{--MEMBER_CHANGED_DATA--}';
1566
1567                                         // Output success message
1568                                         $content['message'] = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
1569                                         break;
1570
1571                                 default: // Unsupported module!
1572                                         logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod));
1573                                         $content['message'] = '<span class="notice">{--UNKNOWN_MODULE--}</span>';
1574                                         break;
1575                         } // END - switch
1576                 } else {
1577                         // Passwords mismatch
1578                         $content['message'] = '<span class="notice">{--MEMBER_PASSWORD_ERROR--}</span>';
1579                 }
1580         } else {
1581                 // Could not load profile
1582                 $content['message'] = '<span class="notice">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>';
1583         }
1584
1585         // Send email to user if required
1586         if ((!empty($sub_mem)) && (!empty($message)) && (!empty($content['userid']))) {
1587                 // Send member mail
1588                 sendEmail($content['userid'], $sub_mem, $message);
1589         } // END - if
1590
1591         // Send only if no other error has occured
1592         if ((!empty($sub_adm)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) {
1593                 // Send admin mail
1594                 sendAdminNotification($sub_adm, $message_admin, $content, getMemberId());
1595         } elseif (isAdminNotificationEnabled()) {
1596                 // Cannot send mails to admin!
1597                 $content['message'] = '{--CANNOT_SEND_ADMIN_MAILS--}';
1598         } else {
1599                 // No mail to admin
1600                 $content['message'] = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
1601         }
1602
1603         // Load template
1604         displayMessage($content['message']);
1605 }
1606
1607 // Generates a 'selection box' from given array
1608 function generateSelectionBoxFromArray (array $options, $name, $optionValue, $optionContent = '', $extraName = '') {
1609         // Start the output
1610         $OUT = '<select name="' . $name . '" size="1" class="form_select">
1611 <option value="X" disabled="disabled">{--PLEASE_SELECT--}</option>';
1612
1613         // Walk through all options
1614         foreach ($options as $option) {
1615                 // Add the <option> entry from ...
1616                 if (empty($optionContent)) {
1617                         // ... template
1618                         $OUT .= loadTemplate('select_' . $name . $extraName . '_option', true, $option);
1619                 } else {
1620                         // ... direct HTML code
1621                         $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
1622                 }
1623         } // END - foreach
1624
1625         // Finish selection box
1626         $OUT .= '</select>';
1627
1628         // Prepare output
1629         $content = array(
1630                 'selection_box' => $OUT,
1631         );
1632
1633         // Load template and return it
1634         return loadTemplate('select_' . $name . $extraName . '_box', true, $content);
1635 }
1636
1637 // Prepares the header for HTML output
1638 function loadHtmlHeader () {
1639         // Run two filters:
1640         // 1.) pre_page_header (mainly loads the page_header template and includes
1641         //     meta description)
1642         runFilterChain('pre_page_header');
1643
1644         // Here can be something be added, but normally one of the two filters
1645         // around this line should do the job for you.
1646
1647         // 2.) post_page_header (mainly to load stylesheet, extra JavaScripts and
1648         //     to close the head-tag)
1649         // Include more header data here
1650         runFilterChain('post_page_header');
1651 }
1652
1653 // Adds page header and footer to output array element
1654 function addPageHeaderFooter () {
1655         // Init output
1656         $OUT = '';
1657
1658         // Add them all together. This is maybe to simple
1659         foreach (array('page_header', 'output', 'page_footer') as $pagePart) {
1660                 // Add page part if set
1661                 if (isset($GLOBALS[$pagePart])) $OUT .= $GLOBALS[$pagePart];
1662         } // END - foreach
1663
1664         // Transfer $OUT to 'output'
1665         $GLOBALS['output'] = $OUT;
1666 }
1667
1668 // Generates meta description for current module and 'what' value
1669 function generateMetaDescriptionCode () {
1670         // Only include from guest area and if sql_patches has correct version
1671         if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
1672                 // Construct dynamic description
1673                 $DESCR = '{?MAIN_TITLE?} ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat());
1674
1675                 // Output it directly
1676                 $GLOBALS['page_header'] .= '<meta name="description" content="' . $DESCR . '" />';
1677         } // END - if
1678
1679         // Remove depth
1680         unset($GLOBALS['ref_level']);
1681 }
1682
1683 // Generates an FQFN for template cache from the given template name
1684 function generateCacheFqfn ($template, $mode = 'html') {
1685         // Is this cached?
1686         if (!isset($GLOBALS['template_cache_fqfn'][$template])) {
1687                 // Generate the FQFN
1688                 $GLOBALS['template_cache_fqfn'][$template] = sprintf(
1689                         "%s_compiled/%s/%s.tpl.cache",
1690                         getCachePath(),
1691                         $mode,
1692                         $template
1693                 );
1694         } // END - if
1695
1696         // Return it
1697         return $GLOBALS['template_cache_fqfn'][$template];
1698 }
1699
1700 // "Fixes" null or empty string to count of dashes
1701 function fixNullEmptyToDashes ($str, $num) {
1702         // Use str as default
1703         $return = $str;
1704
1705         // Is it empty?
1706         if ((is_null($str)) || (trim($str) == '')) {
1707                 // Set it
1708                 $return = str_repeat('-', $num);
1709         } // END - if
1710
1711         // Return final string
1712         return $return;
1713 }
1714
1715 // Translates the "pool type" into human-readable
1716 function translatePoolType ($type) {
1717         // Return "translation"
1718         return sprintf("{--POOL_TYPE_%s--}", strtoupper($type));
1719 }
1720
1721 // Displays given message in admin_settings_saved template
1722 function displayMessage ($message, $return = false) {
1723         // Load the template
1724         return loadTemplate('admin_settings_saved', $return, $message);
1725 }
1726
1727 // Generates a selection box for (maybe) given gender
1728 function generateGenderSelectionBox ($selectedGender = '') {
1729         // Start the HTML code
1730         $out  = '<select name="gender" size="1" class="form_select">';
1731
1732         // Add the options
1733         $out .= generateOptionList('/ARRAY/', array('M', 'F', 'C'), array('{--GENDER_M--}', '{--GENDER_F--}', '{--GENDER_C--}'), $selectedGender);
1734
1735         // Finish HTML code
1736         $out .= '</select>';
1737
1738         // Return the code
1739         return $out;
1740 }
1741
1742 //-----------------------------------------------------------------------------
1743 //                      Template helper functions for EL
1744 //-----------------------------------------------------------------------------
1745
1746 // Color-switch helper function
1747 function doTemplateColorSwitch ($template, $clear = false, $return = true) {
1748         // Is it there?
1749         if (!isset($GLOBALS['color_switch'][$template])) {
1750                 // Initialize it
1751                 initTemplateColorSwitch($template);
1752         } elseif ($clear === false) {
1753                 // Switch color if called from loadTemplate()
1754                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SWITCH:' . $template);
1755                 $GLOBALS['color_switch'][$template] = 3 - $GLOBALS['color_switch'][$template];
1756         }
1757
1758         // Return CSS class name
1759         if ($return === true) {
1760                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'RETURN:' . $template . '=' . $GLOBALS['color_switch'][$template]);
1761                 return 'switch_sw' . $GLOBALS['color_switch'][$template];
1762         } // END - if
1763 }
1764
1765 // Helper function for extension registration link
1766 function doTemplateExtensionRegistrationLink ($template, $dummy, $ext_name) {
1767         // Default is all non-productive
1768         $OUT = '<em style="cursor:help" class="notice" title="{%message,ADMIN_EXTENSION_IS_NON_PRODUCTIVE_LINK_TITLE=' . $ext_name . '%}">{--ADMIN_EXTENSION_IS_NON_PRODUCTIVE_LINK--}</em>';
1769
1770         // Is the given extension non-productive?
1771         if (isExtensionProductive($ext_name)) {
1772                 // Productive code
1773                 $OUT = '<a title="{--ADMIN_REGISTER_EXTENSION_TITLE--}" href="{%url=modules.php?module=admin&amp;what=extensions&amp;reg_ext=' . $ext_name . '%}">{--ADMIN_REGISTER_EXTENSION--}</a>';
1774         } // END - if
1775
1776         // Return code
1777         return $OUT;
1778 }
1779
1780 // Helper function to create bonus mail admin links
1781 function doTemplateAdminBonusMailLinks ($template, $bonusId) {
1782         // Call the inner function
1783         return generateAdminMailLinks('bid', $bonusId);
1784 }
1785
1786 // Helper function to create member mail admin links
1787 function doTemplateAdminMemberMailLinks ($template, $mailId) {
1788         // Call the inner function
1789         return generateAdminMailLinks('mid', $mailId);
1790 }
1791
1792 // [EOF]
1793 ?>