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