fooRequestElementBar() functions renamed, adding of request parameters added:
[mailer.git] / inc / libs / newsletter_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              : newsletter_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  * 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 - 2009 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         die();
42 }
43
44 //
45 function insertNewsletterUrls ($text) {
46         $test = $text;
47
48         // First replace URLs...
49         while (ereg('http://', $test)) {
50                 $check = substr($test, strpos($test, 'http://')); $check2 = $check;
51
52                 // See ext-html.php if you want to add more URL ends...
53                 foreach ($GLOBALS['url_ends'] as $end) {
54                         if (ereg($end, $check)) $check = substr($check, 0, strpos($check, $end));
55                 } // END - foreach
56
57                 // Now replace the URL against anchor container and pray...
58                 $text = substr($text, 0, strpos($text, $check2)) . generateDerefererUrl($check) . substr($text, strpos($text, $check2) + strlen($check));
59
60                 // Finally remove the url from testing string (or we have a loop and maybe server overload!)
61                 $test = substr($test, strpos($test, $check) + strlen($check));
62         } // END - while
63
64         // Now do the (nearly) same thing with email addresses
65         // but now we have the problem that email addresses didn't have
66         // a start mark like http:// and our templates are lame didn't have
67         // a mailto: ... :-(
68         $test = $text;
69
70         // ... what will the email address be out the @... ;-)
71         $PARTS = array();
72         while (ereg('@', $test)) {
73                 $pos = strpos($test, '@');
74                 $test2 = substr($test, 0, $pos);
75
76                 // First check backwards
77                 $idx = $pos - 1;
78                 while ($idx > 0) {
79                         $check = substr($test2, $idx, 1);
80                         if (!in_array($check, $GLOBALS['valid_email_chars']))
81                         {
82                                 // Char found so we end here
83                                 break;
84                         }
85                         $idx--;
86                 }
87
88                 if ($idx > 0) {
89                         // Starting mark is found
90                         $check2 = substr($test, 0, ($idx + 1));
91                         $test = substr($test, ($idx + 1));
92                 }
93
94                 // And now go forward...
95                 $idx = '0';
96                 while ($idx < strlen($test)) {
97                         $check = substr($test, $idx, 1);
98                         if ((!in_array($check, $GLOBALS['valid_email_chars'])) && ($check != '@')) {
99                                 // Char found so end here again
100                                 break;
101                         }
102                         $idx++;
103                 }
104
105                 if ($idx > 0) {
106                         // Maybe this is the email address?
107                         $check = substr($test, 0, $idx);
108                 }
109
110                 // Now replace the email against anchor with mailto and pray...
111                 $PARTS[] = $check2 . $check;
112
113                 // Remove email from testing string (see above why...)
114                 $test = substr($test, strlen($check));
115         }
116
117         // Now put all parts together
118         $text = ''; $PARTS[] = $test;
119         foreach ($PARTS as $part) {
120                 $text .= $part;
121         }
122
123         // Compile possible own HTML tags out...
124         return compileCode($text);
125 }
126
127 // Wrapper for sending newsletter and wrapping URLs / HTML mail
128 function sendNewsletter ($to, $subject, $message, $mode) {
129         // Send mail away as HTML
130         if (postRequestParameter('auto_urls') == 'Y') {
131                 // Automatically insert URLs into newsletter
132                 if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
133                         // Send HTML mail
134                         sendEmail($to, $subject, insertUrlsIntoHtml($message), 'Y');
135                 } else {
136                         // Send normal mail
137                         sendEmail($to, $subject, insertNewsletterUrls($message), 'N');
138                 }
139         } else {
140                 // Regular send-out
141                 if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
142                         sendEmail($to, $subject, $message, 'Y');
143                 } else {
144                         sendEmail($to, $subject, $message, 'N');
145                 }
146         }
147 }
148
149 //
150 ?>