Removed @deprecated from CSS inline/PHP output
[mailer.git] / inc / template-functions.php
index 4b6420a59f013706ed0e545a6329842f5762200a..9d8412562c1ec72d02d08e28957a32ab5531a8ae 100644 (file)
@@ -144,7 +144,7 @@ function outputHtml ($htmlCode = NULL, $newLine = TRUE) {
                                reportBug(__FUNCTION__, __LINE__, '<strong>{--FATAL_ERROR--}:</strong> {--NO_RENDER_DIRECT--}');
                                break;
                } // END - switch
-       } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['http_header'])) || (count($GLOBALS['http_header']) == 0)) && (!isRawOutputMode())) {
+       } elseif ((getPhpCaching() == 'on') && (!isFilledArray($GLOBALS['http_header'])) && (!isRawOutputMode())) {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getPhpCaching()=' . getPhpCaching() . ',isset(http_header)=' . intval(isset($GLOBALS['http_header'])) . ',getScriptOutputMode()=' . getScriptOutputMode() . '');
                // Output cached HTML code
                $GLOBALS['__output'] = ob_get_contents();
@@ -322,17 +322,17 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC
                $template = strtolower($template);
 
                // Base directory
-               $basePath = sprintf("%stemplates/%s/html/", getPath(), getLanguage());
+               $basePath = getTemplateBasePath('html');
                $extraPath = detectExtraTemplatePath('html', $template);
 
                // Generate FQFN
-               $FQFN = $basePath . $extraPath . $template . '.tpl';
+               $FQFN = $basePath . '/' . $extraPath . $template . '.tpl';
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Template ' . $template . ' is solved to FQFN=' . $FQFN);
 
                // Does the special template exists?
                if (!isFileReadable($FQFN)) {
                        // Reset to default template
-                       $FQFN = $basePath . $template . '.tpl';
+                       $FQFN = $basePath . '/' . $template . '.tpl';
                } // END - if
 
                // Now does the final template exists?
@@ -509,18 +509,18 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
                unset($GLOBALS['template_eval']['email'][$template]);
        } elseif (!isset($GLOBALS['template_eval']['email'][$template])) {
                // Base directory
-               $basePath = sprintf("%stemplates/%s/emails/", getPath(), getLanguage());
+               $basePath = getTemplateBasePath('emails');
 
                // Detect extra path
                $extraPath = detectExtraTemplatePath('email', $template);
 
                // Generate full FQFN
-               $FQFN = $basePath . $extraPath . $template . '.tpl';
+               $FQFN = $basePath . '/' . $extraPath . $template . '.tpl';
 
                // Does the special template exists?
                if (!isFileReadable($FQFN)) {
                        // Reset to default template
-                       $FQFN = $basePath . $template . '.tpl';
+                       $FQFN = $basePath . '/' . $template . '.tpl';
                } // END - if
 
                // Now does the final template exists?
@@ -562,6 +562,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
                // Eval the code
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - BEFORE EVAL');
                //* DEBUG: */ print('<pre>'.htmlentities($GLOBALS['template_eval']['email'][$template]).'</pre>');
+               //* DEBUG: */ die('<pre>'.print_r($content, TRUE).'</pre><pre>'.htmlentities($GLOBALS['template_eval']['email'][$template]).'</pre>');
                eval($GLOBALS['template_eval']['email'][$template]);
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - AFTER EVAL');
        } // END - if
@@ -677,17 +678,20 @@ function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) {
        //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Second regex gave ' . count($matches[0]) . ' matches.');
 
        // Are some matches found?
-       if ((count($matches) > 0) && (count($matches[0]) > 0)) {
+       if ((isFilledArray($matches)) && (isFilledArray($matches[0]))) {
                // Replace all matches
                $matchesFound = array();
                foreach ($matches[0] as $key => $match) {
                        // Fuzzy look has failed by default
                        $fuzzyFound = FALSE;
 
+                       // "Cache" match length
+                       $matchLength = strlen($match);
+
                        // Fuzzy look on match if already found
                        foreach ($matchesFound as $found => $set) {
                                // Get test part
-                               $test = substr($found, 0, strlen($match));
+                               $test = substr($found, 0, $matchLength);
 
                                // Does this entry exist?
                                //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'found=' . $found . ',match=' . $match . ',set=' . $set);
@@ -734,7 +738,7 @@ function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) {
        preg_match_all('/\$([a-z_A-Z\[\]]){0,}/', $code, $matches);
 
        // Are some matches found?
-       if ((count($matches) > 0) && (count($matches[0]) > 0)) {
+       if ((isFilledArray($matches)) && (isFilledArray($matches[0]))) {
                // Scan all matches for not $content
                foreach ($matches[0] as $match) {
                        // Trim match
@@ -855,20 +859,20 @@ function addSelectionBox ($type, $default, $prefix = '', $id = NULL, $class = 'f
 
                case 'ho': // Hours
                        for ($idx = 0; $idx <= 23; $idx++) {
-                               if (strlen($idx) == 1) $idx = 0 . $idx;
-                               $OUT .= '<option value="' . $idx . '"';
-                               if ($default == $idx) $OUT .= ' selected="selected"';
-                               $OUT .= '>' . $idx . '</option>';
+                               $padded = padLeftZero($idx);
+                               $OUT .= '<option value="' . $padded . '"';
+                               if ($default == $padded) $OUT .= ' selected="selected"';
+                               $OUT .= '>' . $padded . '</option>';
                        } // END - for
                        break;
 
                case 'mi': // Minutes
                case 'se': // Seconds
                        for ($idx = 0; $idx <= 59; $idx+=5) {
-                               if (strlen($idx) == 1) $idx = 0 . $idx;
-                               $OUT .= '<option value="' . $idx . '"';
-                               if ($default == $idx) $OUT .= ' selected="selected"';
-                               $OUT .= '>' . $idx . '</option>';
+                               $padded = padLeftZero($idx);
+                               $OUT .= '<option value="' . $padded . '"';
+                               if ($default == $padded) $OUT .= ' selected="selected"';
+                               $OUT .= '>' . $padded . '</option>';
                        } // END - for
                        break;
 
@@ -900,7 +904,7 @@ function generateImageOrCode ($img_code, $headerSent = TRUE) {
        }
 
        // Load image
-       $img = sprintf("%s/theme/%s/images/code_bg.%s",
+       $img = sprintf('%s/theme/%s/images/code_bg.%s',
                getPath(),
                getCurrentTheme(),
                getImgType()
@@ -920,7 +924,7 @@ function generateImageOrCode ($img_code, $headerSent = TRUE) {
                } // END - switch
        } else {
                // Silently log the error
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image-type %s in theme %s not found.", getImgType(), getCurrentTheme()));
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf('File for image-type %s in theme %s not found.', getImgType(), getCurrentTheme()));
                return;
        }
 
@@ -1267,7 +1271,7 @@ function reportBug ($file, $line, $message = '', $sendEmail = TRUE) {
        // Is this already called?
        if (isset($GLOBALS[__FUNCTION__])) {
                // Other backtrace
-               print '[' . $file . ':' . $line . ':] ' . __FUNCTION__ . ' has already died! Message:' . $message . '<br />Backtrace:<pre>';
+               print '[' . $file . ':' . $line . ':] ' . __FUNCTION__ . '() has already died! Message:' . $message . '<br />Backtrace:<pre>';
                debug_print_backtrace();
                die('</pre>');
        } // END - if
@@ -1300,7 +1304,7 @@ function reportBug ($file, $line, $message = '', $sendEmail = TRUE) {
        $debug .= '<div class="para">Thank you for finding bugs.</div>';
 
        // Send an email? (e.g. not wanted for evaluation errors)
-       if (($sendEmail === TRUE) && (!isInstallationPhase())) {
+       if (($sendEmail === TRUE) && (!isInstaller()) && (isAdminRegistered())) {
                // Prepare content
                $content = array(
                        'message'   => trim($message),
@@ -1311,10 +1315,28 @@ function reportBug ($file, $line, $message = '', $sendEmail = TRUE) {
                sendAdminNotification('{--REPORT_BUG_SUBJECT--}', 'admin_report_bug', $content);
        } // END - if
 
-       // Is there HTML/CSS/AJAX mode?
-       if (((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode())) && (isDebugModeEnabled())) {
+       // Is there HTML/CSS/AJAX mode while debug-mode is enabled?
+       if ((isDebugModeEnabled()) && ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode()))) {
                // And abort here
                app_exit($file, $line, $debug);
+       } elseif (isAjaxOutputMode()) {
+               // Load include (again?)
+               loadIncludeOnce('inc/ajax-functions.php');
+
+               // Init AJAX
+               initAjax();
+
+               // Set HTTP status to 500 again
+               setHttpStatus('500 Internal Server Error');
+
+               // Is AJAX output mode, then output message as JSON
+               setAjaxReplyContent($debug);
+
+               // Send it out to browser
+               sendAjaxContent(TRUE);
+
+               // Include footer
+               loadIncludeOnce('inc/footer.php');
        } else {
                // Raw/image output mode and all other modes doesn't work well with text ...
                die();
@@ -1702,12 +1724,12 @@ function sendModeMails ($mod, $modes) {
                                                                break;
 
                                                        case 'password': // Password was changed
-                                                               $content['message'] = '{--MEMBER_CHANGED_PASS--}' . PHP_EOL;
+                                                               $content['message'] = '{--MEMBER_CHANGED_PASSWORD--}' . PHP_EOL;
                                                                break;
 
                                                        default:
-                                                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode));
-                                                               $content['message'] = '{--MEMBER_UNKNOWN_MODE--}' . ': ' . $mode . PHP_EOL . PHP_EOL;
+                                                               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown mode %s detected.', $mode));
+                                                               $content['message'] = '{%message,MEMBER_UNKNOWN_MODE=' .  $mode . '%}' . PHP_EOL . PHP_EOL;
                                                                break;
                                                } // END - switch
                                        } // END - foreach
@@ -1726,23 +1748,23 @@ function sendModeMails ($mod, $modes) {
                                        if (isAdminNotificationEnabled()) {
                                                // The admin needs to be notified about a profile change
                                                $message_admin = 'admin_mydata_notify';
-                                               $sub_adm   = '{--ADMIN_CHANGED_DATA--}';
+                                               $subjectAdmin   = '{--ADMIN_CHANGED_DATA_SUBJECT--}';
                                        } else {
                                                // No mail to admin
                                                $message_admin = '';
-                                               $sub_adm   = '';
+                                               $subjectAdmin  = '';
                                        }
 
                                        // Set subject lines
-                                       $sub_mem = '{--MEMBER_CHANGED_DATA--}';
+                                       $subjectMember = '{--MEMBER_CHANGED_DATA--}';
 
                                        // Output success message
                                        $content['message'] = '<span class="message">{--MEMBER_MYDATA_MAIL_SENT--}</span>';
                                        break;
 
                                default: // Unsupported module!
-                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod));
-                                       $content['message'] = '<span class="bad">{--UNKNOWN_MODULE--}</span>';
+                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unsupported module %s detected.', $mod));
+                                       $content['message'] = '<span class="bad">{%message,UNKNOWN_MODULE=' . $mod . '%}</span>';
                                        break;
                        } // END - switch
                } else {
@@ -1755,15 +1777,15 @@ function sendModeMails ($mod, $modes) {
        }
 
        // Send email to user if required
-       if ((!empty($sub_mem)) && (!empty($message)) && (!empty($content['userid']))) {
+       if ((!empty($subjectMember)) && (!empty($message)) && (!empty($content['userid']))) {
                // Send member mail
-               sendEmail($content['userid'], $sub_mem, $message);
+               sendEmail($content['userid'], $subjectMember, $message);
        } // END - if
 
        // Send only if no other error has occured
-       if ((!empty($sub_adm)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) {
+       if ((!empty($subjectAdmin)) && (!empty($message_admin)) && (isAdminNotificationEnabled())) {
                // Send admin mail
-               sendAdminNotification($sub_adm, $message_admin, $content, getMemberId());
+               sendAdminNotification($subjectAdmin, $message_admin, $content, getMemberId());
        } elseif (isAdminNotificationEnabled()) {
                // Cannot send mails to admin!
                $content['message'] = '{--CANNOT_SEND_ADMIN_MAILS--}';
@@ -1778,6 +1800,9 @@ function sendModeMails ($mod, $modes) {
 
 // Generates a 'selection box' from given array
 function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
+       // options must be an array
+       assert(is_array($options));
+
        // Default is empty
        $addKey = '';
 
@@ -2150,7 +2175,7 @@ function doTemplateExtensionRegistrationLink ($templateName, $clear, $ext_name)
                $OUT = '<span title="{--ADMIN_EXTENSION_IS_DEPRECATED_TITLE--}">---</span>';
        } elseif (isExtensionProductive($ext_name)) {
                // Productive code
-               $OUT = '<a title="{--ADMIN_REGISTER_EXTENSION_TITLE--}" href="{%url=modules.php?module=admin&amp;what=extensions&amp;register_ext=' . $ext_name . '%}">{--ADMIN_REGISTER_EXTENSION--}</a>';
+               $OUT = '<a title="{--ADMIN_TASK_REGISTER_EXTENSION_TITLE--}" href="{%url=modules.php?module=admin&amp;what=extensions&amp;register_ext=' . $ext_name . '%}">{--ADMIN_TASK_REGISTER_EXTENSION--}</a>';
        }
 
        // Return code
@@ -2362,5 +2387,39 @@ function doTemplateMetaFavIcon ($templateName, $clear = FALSE) {
        return $out;
 }
 
+// "Getter" for template base path
+function getTemplateBasePath ($part) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$part])) {
+               // "Build" path
+               $GLOBALS[__FUNCTION__][$part] = sprintf('%stemplates/%s/%s', getPath(), getLanguage(), $part);
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$part];
+}
+
+// Removes comments with @DEPRECATED
+function removeDeprecatedComment ($output) {
+       // Explode it into pieces ... ;)
+       $lines = explode(chr(10), $output);
+
+       // Walk through all
+       $return = '';
+       foreach ($lines as $line) {
+               // Is there a @DEPRECATED?
+               if (isInString('@DEPRECATED', $line)) {
+                       // Ignore this line
+                       continue;
+               } // END - if
+
+               // Add it
+               $return .= $line . chr(13);
+       } // END - foreach
+
+       // Returned cleaned content
+       return $return;
+}
+
 // [EOF]
 ?>