Added update_year.sh (still not fully flexible) and updated all years with it.
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://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 insertNewsletterUrls ($text) {
45         $test = $text;
46
47         // First replace URLs...
48         while (isInString('http://', $test)) {
49                 $check = substr($test, strpos($test, 'http://')); $check2 = $check;
50
51                 // See ext-html.php if you want to add more URL ends...
52                 foreach ($GLOBALS['url_ends'] as $end) {
53                         if (isInString($end, $check)) {
54                                 $check = substr($check, 0, strpos($check, $end));
55                         } // END - if
56                 } // END - foreach
57
58                 // Now replace the URL against anchor container and pray...
59                 $text = substr($text, 0, strpos($text, $check2)) . generateDereferrerUrl($check) . substr($text, strpos($text, $check2) + strlen($check));
60
61                 // Finally remove the url from testing string (or we have a loop and maybe server overload!)
62                 $test = substr($test, strpos($test, $check) + strlen($check));
63         } // END - while
64
65         // Now do the (nearly) same thing with email addresses
66         // but now we have the problem that email addresses didn't have
67         // a start mark like http:// and our templates are lame didn't have
68         // a mailto: ... :-(
69         $test = $text;
70
71         // ... what will the email address be out the @... ;-)
72         $PARTS = array();
73         while (isInString('@', $test)) {
74                 $pos = strpos($test, '@');
75                 $test2 = substr($test, 0, $pos);
76
77                 // First check backwards
78                 $idx = $pos - 1;
79                 while ($idx > 0) {
80                         $check = substr($test2, $idx, 1);
81                         if (!in_array($check, $GLOBALS['valid_email_chars'])) {
82                                 // Char found so we end here
83                                 break;
84                         } // END - if
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                 } // END - if
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                         } // END - if
102                         $idx++;
103                 } // END - while
104
105                 if ($idx > 0) {
106                         // Maybe this is the email address?
107                         $check = substr($test, 0, $idx);
108                 } // END - if
109
110                 // Now replace the email against anchor with mailto and pray...
111                 array_push($PARTS, $check2 . $check);
112
113                 // Remove email from testing string (see above why...)
114                 $test = substr($test, strlen($check));
115         } // END - while
116
117         // Now put all parts together
118         $text = '';
119         array_push($PARTS, $test);
120         foreach ($PARTS as $part) {
121                 $text .= $part;
122         } // END - foreach
123
124         // Pre-ompile possible own HTML tags out...
125         return preCompileCode($text);
126 }
127
128 // Wrapper for sending newsletter and wrapping URLs / HTML mail
129 function sendNewsletter ($to, $subject, $message, $mode) {
130         // Send mail away as HTML
131         if (postRequestElement('auto_urls') == 'Y') {
132                 // Automatically insert URLs into newsletter
133                 if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
134                         // Send HTML mail
135                         sendEmail($to, $subject, insertUrlsIntoHtml($message), 'Y');
136                 } else {
137                         // Send normal mail
138                         sendEmail($to, $subject, insertNewsletterUrls($message), 'N');
139                 }
140         } else {
141                 // Regular send-out
142                 if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
143                         sendEmail($to, $subject, $message, 'Y');
144                 } else {
145                         sendEmail($to, $subject, $message, 'N');
146                 }
147         }
148 }
149
150 // [EOF]
151 ?>