]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Workaround for missing function, this will be better in 0.3.0
[mailer.git] / inc / functions.php
index 73928d96981e3554f082e5b24f1428cacbf8afe1..6aedaf61bf7035fc788aab0b4f89739475093129 100644 (file)
@@ -169,7 +169,7 @@ function compileFinalOutput () {
                // Was that eval okay?
                if (empty($newContent)) {
                        // Something went wrong!
-                       debug_report_bug('Evaluation error:<pre>' . linenumberCode($eval) . '</pre>');
+                       debug_report_bug('Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
                } // END - if
                $GLOBALS['output'] = $newContent;
 
@@ -400,7 +400,7 @@ function detectExtraTemplatePath ($template) {
 }
 
 // Loads an email template and compiles it
-function loadEmailTemplate ($template, $content = array(), $UID = '0') {
+function loadEmailTemplate ($template, $content = array(), $userid = '0') {
        global $DATA;
 
        // Make sure all template names are lowercase!
@@ -409,53 +409,33 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
        // Default 'nickname' if extension is not installed
        $nick = '---';
 
-       // Prepare IP number and User Agent
-       $REMOTE_ADDR     = detectRemoteAddr();
-       $HTTP_USER_AGENT = detectUserAgent();
-
-       // Default admin
-       $ADMIN = getConfig('MAIN_TITLE');
-
-       // Is the admin logged in?
-       if (isAdmin()) {
-               // Get admin id
-               $adminId = getCurrentAdminId();
-
-               // Load Admin data
-               $ADMIN = getAdminEmail($adminId);
-       } // END - if
-
        // Neutral email address is default
        $email = getConfig('WEBMASTER');
 
-       // Expiration in a nice output format
-       // NOTE: Use $content[expiration] in your templates instead of $EXPIRATION
-       if (getConfig('auto_purge') == '0') {
-               // Will never expire!
-               $EXPIRATION = getMessage('MAIL_WILL_NEVER_EXPIRE');
-       } else {
-               // Create nice date string
-               $EXPIRATION = createFancyTime(getConfig('auto_purge'));
-       }
-
        // Is content an array?
        if (is_array($content)) {
-               // Add expiration to array, $EXPIRATION is now deprecated!
-               $content['expiration'] = $EXPIRATION;
+               // Add expiration to array
+               if (getConfig('auto_purge') == '0') {
+                       // Will never expire!
+                       $content['expiration'] = getMessage('MAIL_WILL_NEVER_EXPIRE');
+               } else {
+                       // Create nice date string
+                       $content['expiration'] = createFancyTime(getConfig('auto_purge'));
+               }
        } // END - if
 
        // Load user's data
-       //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):UID={$UID},template={$template},content[]=".gettype($content).'<br />');
-       if (($UID > 0) && (is_array($content))) {
+       //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):UID={$userid},template={$template},content[]=".gettype($content).'<br />');
+       if (($userid > 0) && (is_array($content))) {
                // If nickname extension is installed, fetch nickname as well
-               if ((isExtensionActive('nickname')) && (isNicknameUsed($UID))) {
+               if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
                        //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NICKNAME!<br />");
                        // Load by nickname
-                       fetchUserData($UID, 'nickname');
+                       fetchUserData($userid, 'nickname');
                } else {
                        //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NO-NICK!<br />");
                        /// Load by userid
-                       fetchUserData($UID);
+                       fetchUserData($userid);
                }
 
                // Merge data if valid
@@ -473,7 +453,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
        if (isset($content['email'])) $email = $content['email'];
 
        // Store email for some functions in global data array
-       // @TODO Do only use $contentn, not $DATA or raw variables
+       // @TODO Do only use $content, not $DATA or raw variables
        $DATA['email'] = $email;
 
        // Base directory
@@ -519,7 +499,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
        // Is there some content?
        if (empty($newContent)) {
                // Compiling failed
-               $newContent = "Compiler error for template {$template}!\nUncompiled content:\n" . $GLOBALS['tpl_content'];
+               $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['tpl_content'];
 
                // Add last error if the required function exists
                if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
@@ -587,7 +567,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
        eval("\$toEmail = \"".compileRawCode(escapeQuotes($toEmail))."\";");
 
        // Compile "MSG"
-       eval("\$message = \"".compileRawCode(escapeQuotes($message))."\";");
+       eval("\$message = \"".str_replace('$', '&#36;', compileRawCode(escapeQuotes($message)))."\";");
 
        // Fix HTML parameter (default is no!)
        if (empty($isHtml)) $isHtml = 'N';
@@ -2559,7 +2539,7 @@ function debug_get_mailable_backtrace () {
 }
 
 // Output a debug backtrace to the user
-function debug_report_bug ($message = '') {
+function debug_report_bug ($message = '', $sendEmail = true) {
        // Is this already called?
        if (isset($GLOBALS[__FUNCTION__])) {
                // Other backtrace
@@ -2591,15 +2571,17 @@ function debug_report_bug ($message = '') {
        $debug .= "</pre>\nRequest-URI: " . getRequestUri()."<br />\n";
        $debug .= "Thank you for finding bugs.";
 
-       // Prepare content
-       $content = array(
-               'message'     => trim($message),
-               'backtrace'   => trim(debug_get_mailable_backtrace()),
-               'request_uri' => trim(getRequestUri())
-       );
+       // Send an email? (e.g. not wanted for evaluation errors)
+       if ($sendEmail === true) {
+               // Prepare content
+               $content = array(
+                       'message'     => trim($message),
+                       'backtrace'   => trim(debug_get_mailable_backtrace())
+               );
 
-       // Send email to webmaster
-       sendAdminNotification(getMessage('DEBUG_REPORT_BUG_SUBJECT'), 'admin_report_bug', $content);
+               // Send email to webmaster
+               sendAdminNotification(getMessage('DEBUG_REPORT_BUG_SUBJECT'), 'admin_report_bug', $content);
+       } // END - if
 
        // And abort here
        // @TODO This cannot be rewritten to app_die(), try to find a solution for this.
@@ -2865,7 +2847,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
 }
 // Send notification to admin
 function sendAdminNotification ($subject, $templateName, $content=array(), $userid = '0') {
-       if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
+       if ((isExtensionInstalledAndNewer('admins', '0.4.1')) && (function_exists('sendAdminsEmails'))) {
                // Send new way
                sendAdminsEmails($subject, $templateName, $content, $userid);
        } else {
@@ -3070,15 +3052,15 @@ function addNewBonusMail ($data, $mode = '', $output=true) {
        if ((empty($mode)) && (isset($data['mode']))) $mode = $data['mode'];
 
        // Generate receiver list
-       $RECEIVER = generateReceiverList($data['cat'], $data['receiver'], $mode);
+       $receiver = generateReceiverList($data['cat'], $data['receiver'], $mode);
 
        // Receivers added?
-       if (!empty($RECEIVER)) {
+       if (!empty($receiver)) {
                // Add bonus mail to queue
                addBonusMailToQueue(
                $data['subject'],
                $data['text'],
-               $RECEIVER,
+               $receiver,
                $data['points'],
                $data['seconds'],
                $data['url'],
@@ -3578,7 +3560,7 @@ function determinePageTitle () {
                $pageTitle = $TITLE;
        } elseif ((isInstalled()) && (isAdminRegistered())) {
                // Installed, admin registered but no ext-sql_patches
-               $pageTitle = '[-- ' . getConfig('MAIN_TITLE').' - '.getModuleTitle(getModule()) . ' --]';
+               $pageTitle = '[-- ' . getConfig('MAIN_TITLE') . ' - ' . getModuleTitle(getModule()) . ' --]';
        } elseif ((isInstalled()) && (!isAdminRegistered())) {
                // Installed but no admin registered
                $pageTitle = sprintf(getMessage('SETUP_OF_MXCHANGE'), getConfig('MAIN_TITLE'));
@@ -3594,7 +3576,7 @@ function determinePageTitle () {
        }
 
        // Return title
-       return $pageTitle;
+       return decodeEntities($pageTitle);
 }
 
 // Checks wethere there is a cache file there. This function is cached.
@@ -3847,11 +3829,16 @@ function encodeUrl ($url, $outputMode = '0') {
                }
 
                // Add it to URL
-               $url .= $seperator . session_name() . '=' . session_id();
+               if (session_id() != '') {
+                       $url .= $seperator . session_name() . '=' . session_id();
+               } // END - if
        } // END - if
 
-       // Add {?URL?}
-       $url = '{?URL?}/' . $url;
+       // Add {?URL?} ?
+       if ((substr($url, 0, strlen(getConfig('URL'))) != getConfig('URL')) && (substr($url, 0, 7) != '{?URL?}') && (substr($url, 0, 7) != 'http://') && (substr($url, 0, 8) != 'https://')) {
+               // Add it
+               $url = '{?URL?}/' . $url;
+       } // END - if
 
        // Return the URL
        return $url;
@@ -3859,6 +3846,9 @@ function encodeUrl ($url, $outputMode = '0') {
 
 // Simple check for spider
 function isSpider () {
+       // It should not be empty, if so it is better a spider/bot
+       if (detectUserAgent(true) == '') return true;
+
        // Is it a spider?
        return ((strpos('spider', strtolower(detectUserAgent(true))) !== false) || (strpos('bot', strtolower(detectUserAgent(true))) !== false));
 }