Double question mark fixed
[mailer.git] / inc / libs / html_mail_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 //
44 function addValidHtmlTags() {
45         $OUT = '';
46         if (!is_array($GLOBALS['html_tags'])) return "";
47         foreach ($GLOBALS['html_tags'] as $tag) {
48                 $OUT .= ", ".strtoupper($tag);
49         }
50         $OUT = substr($OUT, 2);
51         return $OUT;
52 }
53
54 //
55 function checkHtmlTags ($html) {
56         $test = stripslashes($html);
57         while (isInString('<', $test) && isInString('>', $test)) {
58                 $check = strtolower(substr($test, strpos($test, '<') + 1, strpos($test, '>') - strpos($test, '<') - 1));
59                 $check = str_replace('/', '', $check);
60                 if (!in_array($check, $GLOBALS['html_tags'])) {
61                         // Invalid tag found
62                         return '';
63                 } // END - if
64                 $test = substr($test, strpos($test, '>') + 1);
65         } // END - while
66
67         // Return tested code
68         return $html;
69 }
70
71 //
72 function insertUrlsIntoHtml ($text) {
73         $test = $text;
74
75         // First replace URLs...
76         while (isInString('http://', $test)) {
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                         if (isInString($end, $check)) $check = substr($check, 0, strpos($check, $end));
82                 } // END - foreach
83
84                 // Now replace the URL against anchor container and pray...
85                 $text = substr($text, 0, strpos($text, $check2)) . '<a href="' . generateDerefererUrl($check) . '" target="_blank">' . $check . '</a>' . substr($text, strpos($text, $check2) + strlen($check));
86
87                 // Finally remove the url from testing string (or we have a loop and maybe server overload!)
88                 $test = substr($test, strpos($test, $check) + strlen($check));
89         } // END - while
90
91         // Now do the (nearly) same thing with email addresses
92         // but now we have the problem that email addresses didn't have
93         // a start mark like http:// and our templates are lame didn't have
94         // a mailto: ... :-(
95         $test = $text;
96
97         // ... what will the email address be out the @... ;-)
98         $PARTS = array();
99         while (isInString('@', $test)) {
100                 $pos = strpos($test, '@');
101                 $test2 = substr($test, 0, $pos);
102
103                 // First check backwards
104                 $idx = $pos - 1;
105                 while ($idx > 0) {
106                         $check = substr($test2, $idx, 1);
107                         if (!in_array($check, $GLOBALS['valid_email_chars'])) {
108                                 // Char found so we end here
109                                 break;
110                         } // END - if
111                         $idx--;
112                 } // END - while
113
114                 if ($idx > 0) {
115                         // Starting mark is found
116                         $check2 = substr($test, 0, ($idx + 1));
117                         $test = substr($test, ($idx + 1));
118                 } // END - if
119
120                 // And now go forward...
121                 $idx = '0';
122                 while ($idx < strlen($test)) {
123                         $check = substr($test, $idx, 1);
124                         if ((!in_array($check, $GLOBALS['valid_email_chars'])) && ($check != '@')) {
125                                 // Char found so end here again
126                                 break;
127                         } // END - if
128                         $idx++;
129                 } // END - while
130
131                 if ($idx > 0) {
132                         // Maybe this is the email address?
133                         $check = substr($test, 0, $idx);
134                 } // END - if
135
136                 // Now replace the email against anchor with mailto and pray...
137                 $PARTS[] = $check2 . '<a href="' . generateEmailLink($check, 'user_data') . '">' . $check . '</a>';
138
139                 // Remove email from testing string (see above why...)
140                 $test = substr($test, strlen($check));
141         }
142
143         // Now put all parts together
144         $text = ''; $PARTS[] = $test;
145         foreach ($PARTS as $part) {
146                 $text .= $part;
147         } // END - foreach
148
149         // Replace new-lines agains <br />-s and finally compile possible own HTML tags out...
150         return preCompileCode(str_replace("\n", "<br />\n", $text));
151 }
152
153 // [EOF]
154 ?>