2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 04/25/2004 *
\r
4 * ================ Last change: 04/29/2004 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : newsletter_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
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\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
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
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
34 // Some security stuff...
\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
\r
41 function NL_ADD_VALID_TAGS()
\r
43 global $HTML_TAGS; $OUT = "";
\r
44 if (!is_array($HTML_TAGS)) return "";
\r
45 foreach ($HTML_TAGS as $tag)
\r
47 $OUT .= ", ".strtoupper($tag);
\r
49 $OUT = substr($OUT, 2);
\r
53 function NL_CHECK_TAGS($html)
\r
56 $test = stripslashes($html);
\r
57 while (ereg("<", $test) && ereg(">", $test))
\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
63 // Invalid tag found!
\r
66 $test = substr($test, strpos($test, ">") + 1);
\r
68 // Return tested code
\r
72 function NL_INSERT_URLS($text)
\r
74 global $URL_ENDS, $VALID_EMAIL_CHARS;
\r
77 // First replace URLs...
\r
78 while (ereg("http://", $test))
\r
80 $check = substr($test, strpos($test, "http://")); $check2 = $check;
\r
82 // See ext-html.php if you want to add more URL ends...
\r
83 foreach ($URL_ENDS as $end)
\r
85 if (ereg($end, $check)) $check = substr($check, 0, strpos($check, $end));
\r
88 // Now replace the URL against anchor container and pray...
\r
89 $text = substr($text, 0, strpos($text, $check2)) . DEREFERER($check) . substr($text, strpos($text, $check2) + strlen($check));
\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
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
101 // ... what will the email address be out the @... ;-)
\r
103 while (ereg("@", $test))
\r
105 $pos = strpos($test, "@");
\r
106 $test2 = substr($test, 0, $pos);
\r
108 // First check backwards
\r
112 $check = substr($test2, $idx, 1);
\r
113 if (!in_array($check, $VALID_EMAIL_CHARS))
\r
115 // Char found so we end here
\r
122 // Starting mark is found
\r
123 $check2 = substr($test, 0, ($idx + 1));
\r
124 $test = substr($test, ($idx + 1));
\r
127 // And now go forward...
\r
129 while ($idx < strlen($test))
\r
131 $check = substr($test, $idx, 1);
\r
132 if ((!in_array($check, $VALID_EMAIL_CHARS)) && ($check != "@"))
\r
134 // Char found so end here again
\r
141 // Maybe this is the email address?
\r
142 $check = substr($test, 0, $idx);
\r
145 // Now replace the email against anchor with mailto and pray...
\r
146 $PARTS[] = $check2.$check;
\r
148 // Remove email from testing string (see above why...)
\r
149 $test = substr($test, strlen($check));
\r
151 // Now put all parts together
\r
152 $text = ""; $PARTS[] = $test;
\r
153 foreach ($PARTS as $part)
\r
158 // Compile possible own HTML tags out...
\r
159 return COMPILE_CODE($text);
\r
162 function SEND_NEWSLETTER($TO, $SUBJECT, $MSG, $MODE)
\r
165 // Send mail away as HTML
\r
166 if ($_POST['auto_urls'] == "Y") {
\r
167 // Automatically insert URLs into newsletter
\r
168 if ((EXT_IS_ACTIVE("html")) && ($MODE == "html")) {
\r
170 SEND_EMAIL($TO, $SUBJECT, HTML_INSERT_URLS($MSG), "Y");
\r
172 // Send normal mail
\r
173 SEND_EMAIL($TO, $SUBJECT, NL_INSERT_URLS($MSG), "N");
\r
176 // Regular send-out
\r
177 if ((EXT_IS_ACTIVE("html")) && ($MODE == "html")) {
\r
178 SEND_EMAIL($TO, $SUBJECT, $MSG, "Y");
\r
180 SEND_EMAIL($TO, $SUBJECT, $MSG);
\r