More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / libs / html_mail_functions.php
index 3d08472af546526b408f64228c395a90d0c9a626..ee0f7bde321cda3d1dce7073f6c4a598b57e2a7a 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Funktionen fuer die HTML-Erweiterung             *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
+if (!defined('__SECURITY')) {
+       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
        require($INC);
 }
+
 //
-function HTML_ADD_VALID_TAGS()
-{
-       global $HTML_TAGS; $OUT = "";
-       if (!is_array($HTML_TAGS)) return "";
-       foreach ($HTML_TAGS as $tag)
-       {
+function HTML_ADD_VALID_TAGS() {
+       $OUT = '';
+       if (!is_array($GLOBALS['html_tags'])) return "";
+       foreach ($GLOBALS['html_tags'] as $tag) {
                $OUT .= ", ".strtoupper($tag);
        }
        $OUT = substr($OUT, 2);
        return $OUT;
 }
 //
-function HTML_CHECK_TAGS($html)
-{
-       global $HTML_TAGS;
+function HTML_CHECK_TAGS ($html) {
        $test = stripslashes($html);
-       while (ereg("<", $test) && ereg(">", $test))
-       {
-               $check = strtolower(substr($test, strpos($test, "<") + 1, strpos($test, ">") - strpos($test, "<") - 1));
-               $check = str_replace("/", "", $check);
-               if (!in_array($check, $HTML_TAGS))
-               {
+       while (ereg('<', $test) && ereg('>', $test)) {
+               $check = strtolower(substr($test, strpos($test, '<') + 1, strpos($test, '>') - strpos($test, '<') - 1));
+               $check = str_replace('/', '', $check);
+               if (!in_array($check, $GLOBALS['html_tags'])) {
                        // Invalid tag found!
                        return "";
                }
-               $test = substr($test, strpos($test, ">") + 1);
+               $test = substr($test, strpos($test, '>') + 1);
        }
        // Return tested code
        return $html;
 }
 //
-function HTML_INSERT_URLS($text)
-{
-       global $URL_ENDS, $VALID_EMAIL_CHARS;
+function HTML_INSERT_URLS ($text) {
        $test = $text;
 
        // First replace URLs...
-       while (ereg("http://", $test))
-       {
-               $check = substr($test, strpos($test, "http://")); $check2 = $check;
+       while (ereg('http://', $test)) {
+               $check = substr($test, strpos($test, 'http://')); $check2 = $check;
 
                // See ext-html.php if you want to add more URL ends...
-               foreach ($URL_ENDS as $end)
-               {
+               foreach ($GLOBALS['url_ends'] as $end) {
                        if (ereg($end, $check)) $check = substr($check, 0, strpos($check, $end));
-               }
+               } // END - foreach
 
                // Now replace the URL against anchor container and pray...
-               $text = substr($text, 0, strpos($text, $check2))."<A href=\"".DEREFERER($check)."\" target=\"_blank\">".$check."</A>".substr($text, strpos($text, $check2) + strlen($check));
+               $text = substr($text, 0, strpos($text, $check2))."<a href=\"".DEREFERER($check)."\" target=\"_blank\">".$check."</a>".substr($text, strpos($text, $check2) + strlen($check));
 
                // Finally remove the url from testing string (or we have a loop and maybe server overload!)
                $test = substr($test, strpos($test, $check) + strlen($check));
-       }
+       } // END - while
 
        // Now do the (nearly) same thing with email addresses
        // but now we have the problem that email addresses didn't have
@@ -100,73 +95,68 @@ function HTML_INSERT_URLS($text)
 
        // ... what will the email address be out the @... ;-)
        $PARTS = array();
-       while (ereg("@", $test))
-       {
-               $pos = strpos($test, "@");
+       while (ereg('@', $test)) {
+               $pos = strpos($test, '@');
                $test2 = substr($test, 0, $pos);
 
                // First check backwards
                $idx = $pos - 1;
-               while ($idx > 0)
-               {
+               while ($idx > 0) {
                        $check = substr($test2, $idx, 1);
-                       if (!in_array($check, $VALID_EMAIL_CHARS))
-                       {
+                       if (!in_array($check, $GLOBALS['valid_email_chars'])) {
                                // Char found so we end here
                                break;
-                       }
+                       } // END - if
                        $idx--;
-               }
-               if ($idx > 0)
-               {
+               } // END - while
+
+               if ($idx > 0) {
                        // Starting mark is found
                        $check2 = substr($test, 0, ($idx + 1));
                        $test = substr($test, ($idx + 1));
-               }
+               } // END - if
 
                // And now go forward...
                $idx = 0;
-               while ($idx < strlen($test))
-               {
+               while ($idx < strlen($test)) {
                        $check = substr($test, $idx, 1);
-                       if ((!in_array($check, $VALID_EMAIL_CHARS)) && ($check != "@"))
-                       {
+                       if ((!in_array($check, $GLOBALS['valid_email_chars'])) && ($check != '@')) {
                                // Char found so end here again
                                break;
-                       }
+                       } // END - if
                        $idx++;
-               }
-               if ($idx > 0)
-               {
+               } // END - while
+
+               if ($idx > 0) {
                        // Maybe this is the email address?
                        $check = substr($test, 0, $idx);
-               }
+               } // END - if
 
                // Now replace the email against anchor with mailto and pray...
-               $PARTS[] = $check2."<A href=\"mailto:".$check."\">".$check."</A>";
+               $PARTS[] = $check2 . "<a href=\"" . generateEmailLink($check, 'user_data') . "\">" . $check . "</a>";
 
                // Remove email from testing string (see above why...)
                $test = substr($test, strlen($check));
        }
+
        // Now put all parts together
-       $text = ""; $PARTS[] = $test;
-       foreach ($PARTS as $part)
-       {
+       $text = ''; $PARTS[] = $test;
+       foreach ($PARTS as $part) {
                $text .= $part;
        }
 
-       // Replace new-lines agains <BR>-s and finally compile possible own HTML tags out...
-       return COMPILE_CODE(str_replace("\n", "<BR>\n", $text));
+       // Replace new-lines agains <br />-s and finally compile possible own HTML tags out...
+       return COMPILE_CODE(str_replace("\n", "<br />\n", $text));
 }
-//
-function SEND_HTML_EMAIL($TO, $SUBJECT, $MSG, $FROM)
-{
-       if (EXT_IS_ACTIVE("html_mail"))
-       {
+
+// Sends a HTML mail to the user
+function sendHtmlEmail($to, $subject, $message, $FROM) {
+       if (EXT_IS_ACTIVE('html_mail')) {
                // Send mail away as HTML
-               $FROM = "Content-Type: text/html\n".$FROM;
-               SEND_EMAIL($TO, $SUBJECT, $MSG, 'N', $FROM);
+               $FROM = "Content-Type: text/html\n" . $FROM;
+               sendEmail($to, $subject, $message, 'N', $FROM);
        }
 }
+
 //
 ?>