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