interval(1));
}
#0013076: different content when forwarding 'to a friend'
if (FORWARD_ALTERNATIVE_CONTENT) {
$forwardContent = count($forwardedby) > 0;
} else {
$forwardContent = 0;
}
if (empty($cached[$messageid])) {
if (!precacheMessage($messageid, $forwardContent)) {
unset($cached[$messageid]);
logEvent('Error loading message ' . $messageid . ' in cache');
return 0;
}
} else {
# dbg("Using cached {$cached[$messageid]["fromemail"]}");
if (VERBOSE) {
output('Using cached message');
}
}
if (VERBOSE) {
output(s('Sending message %d with subject %s to %s', $messageid, $cached[$messageid]['subject'], $email));
}
## at this stage we don't know whether the content is HTML or text, it's just content
$content = $cached[$messageid]['content'];
if (VERBOSE && $getspeedstats) {
output('Load user start');
}
$userdata = array();
$user_att_values = array();
#0011857: forward to friend, retain attributes
if ($hash == 'forwarded' && defined('KEEPFORWARDERATTRIBUTES') && KEEPFORWARDERATTRIBUTES) {
$user_att_values = getUserAttributeValues($forwardedby['email']);
} elseif ($hash != 'forwarded') {
$user_att_values = getUserAttributeValues($email);
}
if (!is_array($user_att_values)) {
$user_att_values = array();
}
foreach ($user_att_values as $key => $val) {
$newkey = cleanAttributeName($key);
## in the help, we only list attributes with "strlen <= 30"
unset($user_att_values[$key]);
if (strlen($key) <= 30) {
$user_att_values[$newkey] = $val;
}
}
# print '
';var_dump($user_att_values);print '
';exit;
$query = sprintf('select * from %s where email = "%s"', $GLOBALS['tables']['user'], sql_escape($email));
$userdata = Sql_Fetch_Assoc_Query($query);
if (empty($userdata['id'])) {
$userdata = array();
}
#var_dump($userdata);
if (stripos($content, '[LISTS]') !== false) {
$listsarr = array();
$req = Sql_Query(sprintf('select list.name,list.active from %s as list,%s as listuser where list.id = listuser.listid and listuser.userid = %d',
$GLOBALS['tables']['list'], $GLOBALS['tables']['listuser'], $userdata['id']));
while ($row = Sql_Fetch_Assoc($req)) {
if ($row['active'] || PREFERENCEPAGE_SHOW_PRIVATE_LISTS) {
array_push($listsarr, stripslashes($row['name']));
}
}
if (!empty($listsarr)) {
$html['lists'] = implode('
', $listsarr);
$text['lists'] = implode("\n", $listsarr);
} else {
$html['lists'] = $GLOBALS['strNoListsFound'];
$text['lists'] = $GLOBALS['strNoListsFound'];
}
unset($listsarr);
}
if (VERBOSE && $getspeedstats) {
output('Load user end');
}
if ($cached[$messageid]['userspecific_url']) {
if (VERBOSE && $getspeedstats) {
output('fetch personal URL start');
}
## Fetch external content, only if the URL has placeholders
if ($GLOBALS['can_fetchUrl'] && preg_match("/\[URL:([^\s]+)\]/i", $content, $regs)) {
while (isset($regs[1]) && strlen($regs[1])) {
$url = $regs[1];
if (!preg_match('/^http/i', $url)) {
$url = 'http://' . $url;
}
$remote_content = fetchUrl($url, $userdata);
# @@ don't use this
# $remote_content = includeStyles($remote_content);
if ($remote_content) {
## @TODO, work out a nice way to do this: ##17197
## collecting different remote URLS only works if they do not have html and body tags.
## but if we strip them here, that might affect specially crafted ones, eg
if (0) {
$remote_content = preg_replace('/]*>/', '', $remote_content);
$remote_content = preg_replace('/]*>/', '', $remote_content);
$remote_content = preg_replace('/<\/html[^>]*>/', '', $remote_content);
$remote_content = preg_replace('/<\/body[^>]*>/', '', $remote_content);
}
$content = str_replace($regs[0], '' . $remote_content, $content);
$cached[$messageid]['htmlformatted'] = strip_tags($content) != $content;
} else {
logEvent("Error fetching URL: $regs[1] to send to $email");
return 0;
}
preg_match("/\[URL:([^\s]+)\]/i", $content, $regs);
}
}
if (VERBOSE && $getspeedstats) {
output('fetch personal URL end');
}
}
if (VERBOSE && $getspeedstats) {
output('define placeholders start');
}
$url = getConfig('unsubscribeurl');
## https://mantis.phplist.com/view.php?id=16680 -> the "sep" should be & for the text links
$sep = strpos($url, '?') === false ? '?' : '&';
$html['unsubscribe'] = sprintf('%s', $url, htmlspecialchars($sep), $hash, $strUnsubscribe);
$text['unsubscribe'] = sprintf('%s%suid=%s', $url, $sep, $hash);
$text['jumpoff'] = sprintf('%s%suid=%s&jo=1', $url, $sep, $hash);
$html['unsubscribeurl'] = sprintf('%s%suid=%s', $url, htmlspecialchars($sep), $hash);
$text['unsubscribeurl'] = sprintf('%s%suid=%s', $url, $sep, $hash);
$text['jumpoffurl'] = sprintf('%s%suid=%s&jo=1', $url, $sep, $hash);
#0013076: Blacklisting posibility for unknown users
$url = getConfig('blacklisturl');
$sep = strpos($url, '?') === false ? '?' : '&';
$html['blacklist'] = sprintf('%s', $url, htmlspecialchars($sep), $email,
$strUnsubscribe);
$text['blacklist'] = sprintf('%s%semail=%s', $url, $sep, $email);
$html['blacklisturl'] = sprintf('%s%semail=%s', $url, htmlspecialchars($sep), $email);
$text['blacklisturl'] = sprintf('%s%semail=%s', $url, $sep, $email);
#0013076: Problem found during testing: message part must be parsed correctly as well.
if (count($forwardedby) && isset($forwardedby['email'])) {
$html['unsubscribe'] = $html['blacklist'];
$text['unsubscribe'] = $text['blacklist'];
$html['forwardedby'] = $forwardedby['email'];
$text['forwardedby'] = $forwardedby['email'];
}
$url = getConfig('subscribeurl');
$sep = strpos($url, '?') === false ? '?' : '&';
$html['subscribe'] = sprintf('%s', $url, $strThisLink);
$text['subscribe'] = sprintf('%s', $url);
$html['subscribeurl'] = sprintf('%s', $url);
$text['subscribeurl'] = sprintf('%s', $url);
$url = getConfig('forwardurl');
$sep = strpos($url, '?') === false ? '?' : '&';
$html['forward'] = sprintf('%s', $url, htmlspecialchars($sep), $hash,
$messageid, $strThisLink);
$text['forward'] = sprintf('%s%suid=%s&mid=%d', $url, $sep, $hash, $messageid);
$html['forwardurl'] = sprintf('%s%suid=%s&mid=%d', $url, htmlspecialchars($sep), $hash, $messageid);
$text['forwardurl'] = $text['forward'];
$html['messageid'] = sprintf('%d', $messageid);
$text['messageid'] = sprintf('%d', $messageid);
$url = getConfig('forwardurl');
# make sure there are no newlines, otherwise they get turned into
s
$html['forwardform'] = '';#sprintf('',$url,$hash,$messageid,$GLOBALS['strForward']);
$text['signature'] = "\n\n-- powered by phpList, www.phplist.com --\n\n";
$url = getConfig('preferencesurl');
$sep = strpos($url, '?') === false ? '?' : '&';
$html['preferences'] = sprintf('%s', $url, htmlspecialchars($sep), $hash, $strThisLink);
$text['preferences'] = sprintf('%s%suid=%s', $url, $sep, $hash);
$html['preferencesurl'] = sprintf('%s%suid=%s', $url, htmlspecialchars($sep), $hash);
$text['preferencesurl'] = sprintf('%s%suid=%s', $url, $sep, $hash);
$url = getConfig('confirmationurl');
$sep = strpos($url, '?') === false ? '?' : '&';
$html['confirmationurl'] = sprintf('%s%suid=%s', $url, htmlspecialchars($sep), $hash);
$text['confirmationurl'] = sprintf('%s%suid=%s', $url, $sep, $hash);
#historical, not sure it's still used
$html['userid'] = $hash;
$text['userid'] = $hash;
$html['website'] = $GLOBALS['website']; # Your website's address, e.g. www.yourdomain.com
$text['website'] = $GLOBALS['website'];
$html['domain'] = $GLOBALS['domain']; # Your domain, e.g. yourdomain.com
$text['domain'] = $GLOBALS['domain'];
if ($hash != 'forwarded') {
$text['footer'] = $cached[$messageid]['textfooter'];
$html['footer'] = $cached[$messageid]['htmlfooter'];
} else {
#0013076: different content when forwarding 'to a friend'
if (FORWARD_ALTERNATIVE_CONTENT) {
$text['footer'] = stripslashes($messagedata['forwardfooter']);
} else {
$text['footer'] = getConfig('forwardfooter');
}
$html['footer'] = $text['footer'];
}
/*
We request you retain the signature below in your emails including the links.
This not only gives respect to the large amount of time given freely
by the developers but also helps build interest, traffic and use of
phpList, which is beneficial to it's future development.
You can configure how the credits are added to your pages and emails in your
config file.
Michiel Dethmers, phpList Ltd 2003 - 2013
*/
if (!EMAILTEXTCREDITS) {
$html['signature'] = $PoweredByImage;#'';
# oops, accidentally became spyware, never intended that, so take it out again :-)
$html['signature'] = preg_replace('/src=".*power-phplist.png"/', 'src="powerphplist.png"', $html['signature']);
} else {
$html['signature'] = $PoweredByText;
}
# $content = $cached[$messageid]["htmlcontent"];
if (VERBOSE && $getspeedstats) {
output('define placeholders end');
}
## Fill text and html versions depending on given versions.
if (VERBOSE && $getspeedstats) {
output('parse text to html or html to text start');
}
if ($cached[$messageid]['htmlformatted']) {
if (empty($cached[$messageid]['textcontent'])) {
$textcontent = HTML2Text($content);
} else {
$textcontent = $cached[$messageid]['textcontent'];
}
$htmlcontent = $content;
} else {
if (empty($cached[$messageid]['textcontent'])) {
$textcontent = $content;
} else {
$textcontent = $cached[$messageid]['textcontent'];
}
$htmlcontent = parseText($content);
}
if (VERBOSE && $getspeedstats) {
output('parse text to html or html to text end');
}
$defaultstyle = getConfig('html_email_style');
$adddefaultstyle = 0;
if (VERBOSE && $getspeedstats) {
output('merge into template start');
}
if ($cached[$messageid]['template']) {
# template used
$htmlmessage = str_replace('[CONTENT]', $htmlcontent, $cached[$messageid]['template']);
} else {
# no template used
$htmlmessage = $htmlcontent;
$adddefaultstyle = 1;
}
$textmessage = $textcontent;
if (VERBOSE && $getspeedstats) {
output('merge into template end');
}
## Parse placeholders
if (VERBOSE && $getspeedstats) {
output('parse placeholders start');
}
/*
var_dump($html);
var_dump($userdata);
var_dump($user_att_values);
exit;
*/
# print htmlspecialchars($htmlmessage);exit;
### @@@TODO don't use forward and forward form in a forwarded message as it'll fail
if (strpos($htmlmessage, '[FOOTER]') !== false) {
$htmlmessage = str_ireplace('[FOOTER]', $html['footer'], $htmlmessage);
} elseif ($html['footer']) {
$htmlmessage = addHTMLFooter($htmlmessage, '
' . $html['footer']);
}
if (strpos($htmlmessage, '[SIGNATURE]') !== false) {
$htmlmessage = str_ireplace('[SIGNATURE]', $html['signature'], $htmlmessage);
} else {
# BUGFIX 0015303, 2/2
// $htmlmessage .= '
'.$html["signature"];
$htmlmessage = addHTMLFooter($htmlmessage, '
' . $html['signature']);
}
# END BUGFIX 0015303, 2/2
if (strpos($textmessage, '[FOOTER]')) {
$textmessage = str_ireplace('[FOOTER]', $text['footer'], $textmessage);
} else {
$textmessage .= "\n\n" . $text['footer'];
}
if (strpos($textmessage, '[SIGNATURE]')) {
$textmessage = str_ireplace('[SIGNATURE]', $text['signature'], $textmessage);
} else {
$textmessage .= "\n" . $text['signature'];
}
### addition to handle [FORWARDURL:Message ID:Link Text] (link text optional)
while (preg_match('/\[FORWARD:([^\]]+)\]/Uxm', $htmlmessage, $regs)) {
$newforward = $regs[1];
$matchtext = $regs[0];
if (strpos($newforward, ':')) {
## using FORWARDURL:messageid:linktext
list($forwardmessage, $forwardtext) = explode(':', $newforward);
} else {
$forwardmessage = sprintf('%d', $newforward);
$forwardtext = 'this link';
}
if (!empty($forwardmessage)) {
$url = getConfig('forwardurl');
$sep = strpos($url, '?') === false ? '?' : '&';
$forwardurl = sprintf('%s%suid=%s&mid=%d', $url, $sep, $hash, $forwardmessage);
$htmlmessage = str_replace($matchtext,
'' . $forwardtext . '', $htmlmessage);
} else {
## make sure to remove the match, otherwise, it'll be an eternal loop
$htmlmessage = str_replace($matchtext, '', $htmlmessage);
}
}
## the text message has to be parsed seperately, because the line might wrap if the text for the link is long, so the match text is different
while (preg_match('/\[FORWARD:([^\]]+)\]/Uxm', $textmessage, $regs)) {
$newforward = $regs[1];
$matchtext = $regs[0];
if (strpos($newforward, ':')) {
## using FORWARDURL:messageid:linktext
list($forwardmessage, $forwardtext) = explode(':', $newforward);
} else {
$forwardmessage = sprintf('%d', $newforward);
$forwardtext = 'this link';
}
if (!empty($forwardmessage)) {
$url = getConfig('forwardurl');
$sep = strpos($url, '?') === false ? '?' : '&';
$forwardurl = sprintf('%s%suid=%s&mid=%d', $url, $sep, $hash, $forwardmessage);
$textmessage = str_replace($matchtext, $forwardtext . ' ' . $forwardurl, $textmessage);
} else {
## make sure to remove the match, otherwise, it'll be an eternal loop
$textmessage = str_replace($matchtext, '', $textmessage);
}
}
# $req = Sql_Query(sprintf('select filename,data from %s where template = %d',
# $GLOBALS["tables"]["templateimage"],$cached[$messageid]["templateid"]));
if (ALWAYS_ADD_USERTRACK) {
if (stripos($htmlmessage, '')) {
$htmlmessage = str_replace('',
'',
$htmlmessage);
} else {
$htmlmessage .= '';
}
} else {
## can't use str_replace or str_ireplace, because those replace all, and we only want to replace one
$htmlmessage = preg_replace('/\[USERTRACK\]/i',
'',
$htmlmessage, 1);
}
# make sure to only include usertrack once, otherwise the stats would go silly
$htmlmessage = str_ireplace('[USERTRACK]', '', $htmlmessage);
$textmessage = str_ireplace('[USERTRACK]', '', $textmessage);
$html['subject'] = $cached[$messageid]['subject'];
$text['subject'] = $cached[$messageid]['subject'];
$htmlmessage = parsePlaceHolders($htmlmessage, $html);
$textmessage = parsePlaceHolders($textmessage, $text);
if ($cached[$messageid]['adminattributes']) {
$htmlmessage = parsePlaceHolders($htmlmessage, $cached[$messageid]['adminattributes']);
$textmessage = parsePlaceHolders($textmessage, $cached[$messageid]['adminattributes']);
}
if (VERBOSE && $getspeedstats) {
output('parse placeholders end');
}
if (VERBOSE && $getspeedstats) {
output('parse userdata start');
}
$htmlmessage = parsePlaceHolders($htmlmessage, $userdata);
$textmessage = parsePlaceHolders($textmessage, $userdata);
//CUT 2
$destinationemail = '';
if (is_array($user_att_values)) {
// CUT 3
$htmlmessage = parsePlaceHolders($htmlmessage, $user_att_values);
$textmessage = parsePlaceHolders($textmessage, $user_att_values);
}
if (VERBOSE && $getspeedstats) {
output('parse userdata end');
}
if (!$destinationemail) {
$destinationemail = $email;
}
# this should move into a plugin
if (strpos($destinationemail, '@') === false && isset($GLOBALS['expand_unqualifiedemail'])) {
$destinationemail .= $GLOBALS['expand_unqualifiedemail'];
}
if (VERBOSE && $getspeedstats) {
output('pass to plugins for destination email start');
}
foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
# print "Checking Destination for ".$plugin->name."
";
$destinationemail = $plugin->setFinalDestinationEmail($messageid, $user_att_values, $destinationemail);
}
if (VERBOSE && $getspeedstats) {
output('pass to plugins for destination email end');
}
foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
$textmessage = $plugin->parseOutgoingTextMessage($messageid, $textmessage, $destinationemail, $userdata);
$htmlmessage = $plugin->parseOutgoingHTMLMessage($messageid, $htmlmessage, $destinationemail, $userdata);
}
## click tracking
# for now we won't click track forwards, as they are not necessarily users, so everything would fail
if (VERBOSE && $getspeedstats) {
output('click track start');
}
if (CLICKTRACK && $hash != 'forwarded' && !empty($userdata['id'])) {
$urlbase = '';
# let's leave this for now
/*
if (preg_match('/]*)>/Umis',$htmlmessage,$regs)) {
$urlbase = $regs[1];
} else {
$urlbase = '';
}
# print "URLBASE: $urlbase
";
*/
# convert html message
# preg_match_all('/]*)>(.*)<\/a>/Umis',$htmlmessage,$links);
preg_match_all('/]*)>(.*)<\/a>/Umis', $htmlmessage, $links);
# to process the Yahoo webpage with base href and link like we'd need this one
# preg_match_all('/ ]*)([^>]*)>(.*)<\/a>/Umis',$htmlmessage,$links);
$clicktrack_root = sprintf('%s://%s/lt.php', $GLOBALS['public_scheme'], $website . $GLOBALS['pageroot']);
for ($i = 0; $i < count($links[2]); ++$i) {
$link = cleanUrl($links[2][$i]);
$link = str_replace('"', '', $link);
if (preg_match('/\.$/', $link)) {
$link = substr($link, 0, -1);
}
$linkid = 0;
$linktext = $links[4][$i];
## if the link is text containing a "protocol" eg http:// then do not track it, otherwise
## it will look like Phishing
## it's ok when the link is an image
$linktext = strip_tags($linktext);
$looksLikePhishing = stripos($linktext, 'https://') !== false || stripos($linktext, 'http://') !== false;
if (!$looksLikePhishing && (preg_match('/^http|ftp/i', $link) || preg_match('/^http|ftp/i',
$urlbase)) && !strpos($link, $clicktrack_root)
) {
# take off personal uids
$url = cleanUrl($link, array('PHPSESSID', 'uid'));
# $url = preg_replace('/&uid=[^\s&]+/','',$link);
# if (!strpos('http:',$link)) {
# $link = $urlbase . $link;
# }
$linkid = clickTrackLinkId($messageid, $userdata['id'], $url, $link);
$masked = "H|$linkid|$messageid|" . $userdata['id'] ^ XORmask;
$masked = base64_encode($masked);
## 15254- the encoding adds one or two extraneous = signs, take them off
$masked = preg_replace('/=$/', '', $masked);
$masked = preg_replace('/=$/', '', $masked);
$masked = urlencode($masked);
if (!CLICKTRACK_LINKMAP) {
$newlink = sprintf('%s', $links[1][$i],
$GLOBALS['public_scheme'], $website . $GLOBALS['pageroot'], $masked, $links[3][$i],
$links[4][$i]);
} else {
$newlink = sprintf('%s', $links[1][$i], $GLOBALS['public_scheme'],
$website . CLICKTRACK_LINKMAP, $masked, $links[3][$i], $links[4][$i]);
}
$htmlmessage = str_replace($links[0][$i], $newlink, $htmlmessage);
}
}
# convert Text message
# first find occurances of our top domain, to avoid replacing them later
# hmm, this is no point, it's not just *our* topdomain, but any
if (0) {
preg_match_all('#(https?://' . $GLOBALS['website'] . '/?)\s+#mis', $textmessage, $links);
# preg_match_all('#(https?://[a-z0-9\./\#\?&:@=%\-]+)#ims',$textmessage,$links);
# preg_match_all('!(https?:\/\/www\.[a-zA-Z0-9\.\/#~\?+=&%@-_]+)!mis',$textmessage,$links);
for ($i = 0; $i < count($links[1]); ++$i) {
# not entirely sure why strtolower was used, but it seems to break things http://mantis.phplist.com/view.php?id=4406
# $link = strtolower(cleanUrl($links[1][$i]));
$link = cleanUrl($links[1][$i]);
if (preg_match('/\.$/', $link)) {
$link = substr($link, 0, -1);
}
$linkid = 0;
if (preg_match('/^http|ftp/i', $link) && !strpos($link, $clicktrack_root)) {
$url = cleanUrl($link, array('PHPSESSID', 'uid'));
$req = Sql_Query(sprintf('insert ignore into %s (messageid,userid,url,forward)
values(%d,%d,"%s","%s")', $GLOBALS['tables']['linktrack'], $messageid, $userdata['id'], $url, $link));
$req = Sql_Fetch_Row_Query(sprintf('select linkid from %s where messageid = %s and userid = %d and forward = "%s"
', $GLOBALS['tables']['linktrack'], $messageid, $userdata['id'], $link));
$linkid = $req[0];
$masked = "T|$linkid|$messageid|" . $userdata['id'] ^ XORmask;
$masked = urlencode(base64_encode($masked));
$newlink = sprintf('%s://%s/lt.php?id=%s', $GLOBALS['public_scheme'],
$website . $GLOBALS['pageroot'], $masked);
$textmessage = str_replace($links[0][$i], '<' . $newlink . '>', $textmessage);
}
}
}
#now find the rest
# @@@ needs to expand to find complete urls like:
#http://user:password@www.web-site.com:1234/document.php?parameter=something&otherpar=somethingelse#anchor
# or secure
#https://user:password@www.website.com:2345/document.php?parameter=something%20&otherpar=somethingelse#anchor
preg_match_all('#(https?://[^\s\>\}\,]+)#mis', $textmessage, $links);
# preg_match_all('#(https?://[a-z0-9\./\#\?&:@=%\-]+)#ims',$textmessage,$links);
# preg_match_all('!(https?:\/\/www\.[a-zA-Z0-9\.\/#~\?+=&%@-_]+)!mis',$textmessage,$links);
## sort the results in reverse order, so that they are replaced correctly
rsort($links[1]);
$newlinks = array();
for ($i = 0; $i < count($links[1]); ++$i) {
$link = cleanUrl($links[1][$i]);
if (preg_match('/\.$/', $link)) {
$link = substr($link, 0, -1);
}
$linkid = 0;
if (preg_match('/^http|ftp/i', $link)) {
# && !strpos($link,$clicktrack_root)) {
$url = cleanUrl($link, array('PHPSESSID', 'uid'));
$linkid = clickTrackLinkId($messageid, $userdata['id'], $url, $link);
$masked = "T|$linkid|$messageid|" . $userdata['id'] ^ XORmask;
$masked = base64_encode($masked);
## 15254- the encoding adds one or two extraneous = signs, take them off
$masked = preg_replace('/=$/', '', $masked);
$masked = preg_replace('/=$/', '', $masked);
$masked = urlencode($masked);
if (!CLICKTRACK_LINKMAP) {
$newlinks[$linkid] = sprintf('%s://%s/lt.php?id=%s', $GLOBALS['public_scheme'],
$website . $GLOBALS['pageroot'], $masked);
} else {
$newlinks[$linkid] = sprintf('%s://%s%s', $GLOBALS['public_scheme'], $website . CLICKTRACK_LINKMAP,
$masked);
}
# print $links[0][$i] .' -> '.$newlink.'
';
$textmessage = str_replace($links[1][$i], '[%%%' . $linkid . '%%%]', $textmessage);
}
}
foreach ($newlinks as $linkid => $newlink) {
$textmessage = str_replace('[%%%' . $linkid . '%%%]', $newlink, $textmessage);
}
}
if (VERBOSE && $getspeedstats) {
output('click track end');
}
## if we're not tracking clicks, we should add Google tracking here
## otherwise, we can add it when redirecting on the click
if (!CLICKTRACK && !empty($cached[$messageid]['google_track'])) {
preg_match_all('/]*)>(.*)<\/a>/Umis', $htmlmessage, $links);
for ($i = 0; $i < count($links[2]); ++$i) {
$link = cleanUrl($links[2][$i]);
$link = str_replace('"', '', $link);
## http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55578
$trackingcode = 'utm_source=phplist' . $messageid . '&utm_medium=email&utm_content=HTML&utm_campaign=' . urlencode($cached[$messageid]['subject']);
## take off existing tracking code, if found
if (strpos($link, 'utm_medium') !== false) {
$link = preg_replace('/utm_(\w+)\=[^&]+&/U', '', $link);
}
## 16894 make sure to keep the fragment value at the end of the URL
if (strpos($link, '#')) {
list($tmplink, $fragment) = explode('#', $link);
$link = $tmplink;
unset($tmplink);
$fragment = '#' . $fragment;
} else {
$fragment = '';
}
if (strpos($link, '?')) {
$newurl = $link . '&' . $trackingcode . $fragment;
} else {
$newurl = $link . '?' . $trackingcode . $fragment;
}
# print $link. ' '.$newurl.'
';
$newlink = sprintf('%s', $links[1][$i], $newurl, $links[3][$i], $links[4][$i]);
$htmlmessage = str_replace($links[0][$i], $newlink, $htmlmessage);
}
preg_match_all('#(https?://[^\s\>\}\,]+)#mis', $textmessage, $links);
rsort($links[1]);
$newlinks = array();
for ($i = 0; $i < count($links[1]); ++$i) {
$link = cleanUrl($links[1][$i]);
if (preg_match('/\.$/', $link)) {
$link = substr($link, 0, -1);
}
if (preg_match('/^http|ftp/i', $link)) {
# && !strpos($link,$clicktrack_root)) {
$url = cleanUrl($link, array('PHPSESSID', 'uid'));
//@alpha1: maybe source should be message id?
$trackingcode = 'utm_source=phplist' . $messageid . '&utm_medium=email&utm_content=text&utm_campaign=' . urlencode($cached[$messageid]['subject']);
## take off existing tracking code, if found
if (strpos($link, 'utm_medium') !== false) {
$link = preg_replace('/utm_(\w+)\=[^&]+/', '', $link);
}
## 16894 make sure to keep the fragment value at the end of the URL
if (strpos($link, '#')) {
list($tmplink, $fragment) = explode('#', $link);
$link = $tmplink;
unset($tmplink);
$fragment = '#' . $fragment;
} else {
$fragment = '';
}
if (strpos($link, '?')) {
$newurl = $link . '&' . $trackingcode . $fragment;
} else {
$newurl = $link . '?' . $trackingcode . $fragment;
}
$newlinks[$i] = $newurl;
$textmessage = str_replace($links[1][$i], '[%%%' . $i . '%%%]', $textmessage);
}
}
foreach ($newlinks as $linkid => $newlink) {
$textmessage = str_replace('[%%%' . $linkid . '%%%]', $newlink, $textmessage);
}
unset($newlinks);
}
# print htmlspecialchars($htmlmessage);exit;
#0011996: forward to friend - personal message
if (FORWARD_PERSONAL_NOTE_SIZE && $hash == 'forwarded' && !empty($forwardedby['personalNote'])) {
$htmlmessage = nl2br($forwardedby['personalNote']) . '
' . $htmlmessage;
$textmessage = $forwardedby['personalNote'] . "\n" . $textmessage;
}
if (VERBOSE && $getspeedstats) {
output('cleanup start');
}
## allow fallback to default value for the ones that do not have a value
## delimiter is %% to avoid interfering with markup
preg_match_all('/\[.*\%\%([^\]]+)\]/Ui', $htmlmessage, $matches);
for ($i = 0; $i < count($matches[0]); ++$i) {
$htmlmessage = str_ireplace($matches[0][$i], $matches[1][$i], $htmlmessage);
}
preg_match_all('/\[.*\%\%([^\]]+)\]/Ui', $textmessage, $matches);
for ($i = 0; $i < count($matches[0]); ++$i) {
$textmessage = str_ireplace($matches[0][$i], $matches[1][$i], $textmessage);
}
## remove any remaining placeholders
## 16671 - do not do this, as it'll remove conditional CSS and other stuff
## that we'd like to keep
//$htmlmessage = preg_replace("/\[[A-Z\. ]+\]/i","",$htmlmessage);
//$textmessage = preg_replace("/\[[A-Z\. ]+\]/i","",$textmessage);
# print htmlspecialchars($htmlmessage);exit;
# check that the HTML message as proper and tags
# some readers fail when it doesn't
if (!preg_match('##ims', $htmlmessage)) {
$htmlmessage = '' . $htmlmessage . '';
}
if (!preg_match('##ims', $htmlmessage)) {
if (!$adddefaultstyle) {
$defaultstyle = '';
}
$htmlmessage = '
' . $defaultstyle . '' . $htmlmessage;
}
if (!preg_match('##ims', $htmlmessage)) {
$htmlmessage = '' . $htmlmessage . '';
}
## remove trailing code after