Fixed logfile writing in installation phase, .revision is now ignored
[mailer.git] / inc / libs / html_mail_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 04/25/2004 *
4  * ================                             Last change: 04/29/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : html_mail_functions.php                          *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for the HTML extension                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer die HTML-Erweiterung             *
12  * -------------------------------------------------------------------- *
13  * $Revision:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009)              $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 //
46 function HTML_ADD_VALID_TAGS() {
47         $OUT = "";
48         if (!is_array($GLOBALS['html_tags'])) return "";
49         foreach ($GLOBALS['html_tags'] as $tag) {
50                 $OUT .= ", ".strtoupper($tag);
51         }
52         $OUT = substr($OUT, 2);
53         return $OUT;
54 }
55 //
56 function HTML_CHECK_TAGS ($html) {
57         $test = stripslashes($html);
58         while (ereg("<", $test) && ereg(">", $test)) {
59                 $check = strtolower(substr($test, strpos($test, "<") + 1, strpos($test, ">") - strpos($test, "<") - 1));
60                 $check = str_replace("/", "", $check);
61                 if (!in_array($check, $GLOBALS['html_tags'])) {
62                         // Invalid tag found!
63                         return "";
64                 }
65                 $test = substr($test, strpos($test, ">") + 1);
66         }
67         // Return tested code
68         return $html;
69 }
70 //
71 function HTML_INSERT_URLS ($text) {
72         $test = $text;
73
74         // First replace URLs...
75         while (ereg("http://", $test))
76         {
77                 $check = substr($test, strpos($test, "http://")); $check2 = $check;
78
79                 // See ext-html.php if you want to add more URL ends...
80                 foreach ($GLOBALS['url_ends'] as $end)
81                 {
82                         if (ereg($end, $check)) $check = substr($check, 0, strpos($check, $end));
83                 }
84
85                 // Now replace the URL against anchor container and pray...
86                 $text = substr($text, 0, strpos($text, $check2))."<a href=\"".DEREFERER($check)."\" target=\"_blank\">".$check."</a>".substr($text, strpos($text, $check2) + strlen($check));
87
88                 // Finally remove the url from testing string (or we have a loop and maybe server overload!)
89                 $test = substr($test, strpos($test, $check) + strlen($check));
90         }
91
92         // Now do the (nearly) same thing with email addresses
93         // but now we have the problem that email addresses didn't have
94         // a start mark like http:// and our templates are lame didn't have
95         // a mailto: ... :-(
96         $test = $text;
97
98         // ... what will the email address be out the @... ;-)
99         $PARTS = array();
100         while (ereg("@", $test))
101         {
102                 $pos = strpos($test, "@");
103                 $test2 = substr($test, 0, $pos);
104
105                 // First check backwards
106                 $idx = $pos - 1;
107                 while ($idx > 0)
108                 {
109                         $check = substr($test2, $idx, 1);
110                         if (!in_array($check, $GLOBALS['valid_email_chars']))
111                         {
112                                 // Char found so we end here
113                                 break;
114                         }
115                         $idx--;
116                 }
117                 if ($idx > 0)
118                 {
119                         // Starting mark is found
120                         $check2 = substr($test, 0, ($idx + 1));
121                         $test = substr($test, ($idx + 1));
122                 }
123
124                 // And now go forward...
125                 $idx = 0;
126                 while ($idx < strlen($test))
127                 {
128                         $check = substr($test, $idx, 1);
129                         if ((!in_array($check, $GLOBALS['valid_email_chars'])) && ($check != "@"))
130                         {
131                                 // Char found so end here again
132                                 break;
133                         }
134                         $idx++;
135                 }
136                 if ($idx > 0)
137                 {
138                         // Maybe this is the email address?
139                         $check = substr($test, 0, $idx);
140                 }
141
142                 // Now replace the email against anchor with mailto and pray...
143                 $PARTS[] = $check2."<a href=\"mailto:".$check."\">".$check."</a>";
144
145                 // Remove email from testing string (see above why...)
146                 $test = substr($test, strlen($check));
147         }
148         // Now put all parts together
149         $text = ""; $PARTS[] = $test;
150         foreach ($PARTS as $part)
151         {
152                 $text .= $part;
153         }
154
155         // Replace new-lines agains <br />-s and finally compile possible own HTML tags out...
156         return COMPILE_CODE(str_replace("\n", "<br />\n", $text));
157 }
158 //
159 function SEND_HTML_EMAIL($TO, $SUBJECT, $MSG, $FROM)
160 {
161         if (EXT_IS_ACTIVE("html_mail"))
162         {
163                 // Send mail away as HTML
164                 $FROM = "Content-Type: text/html\n".$FROM;
165                 SEND_EMAIL($TO, $SUBJECT, $MSG, 'N', $FROM);
166         }
167 }
168 //
169 ?>