function precacheMessage($messageid, $forwardContent = 0) { global $cached; $domain = getConfig('domain'); # $message = Sql_query("select * from {$GLOBALS["tables"]["message"]} where id = $messageid"); # $cached[$messageid] = array(); # $message = Sql_fetch_array($message); $message = loadMessageData($messageid); ## the reply to is actually not in use if (preg_match("/([^ ]+@[^ ]+)/", $message["replyto"], $regs)) { # if there is an email in the from, rewrite it as "name <email>" $message["replyto"] = str_replace($regs[0], "", $message["replyto"]); $cached[$messageid]["replytoemail"] = $regs[0]; # if the email has < and > take them out here $cached[$messageid]["replytoemail"] = str_replace("<", "", $cached[$messageid]["replytoemail"]); $cached[$messageid]["replytoemail"] = str_replace(">", "", $cached[$messageid]["replytoemail"]); # make sure there are no quotes around the name $cached[$messageid]["replytoname"] = str_replace('"', "", ltrim(rtrim($message["replyto"]))); } elseif (strpos($message["replyto"], " ")) { # if there is a space, we need to add the email $cached[$messageid]["replytoname"] = $message["replyto"]; $cached[$messageid]["replytoemail"] = "listmaster@{$domain}"; } else { if (!empty($message["replyto"])) { $cached[$messageid]["replytoemail"] = $message["replyto"] . "@{$domain}"; ## makes more sense not to add the domain to the word, but the help says it does ## so let's keep it for now $cached[$messageid]["replytoname"] = $message["replyto"] . "@{$domain}"; } } $cached[$messageid]["fromname"] = $message["fromname"]; $cached[$messageid]["fromemail"] = $message["fromemail"]; $cached[$messageid]["to"] = $message["tofield"]; #0013076: different content when forwarding 'to a friend' $cached[$messageid]["subject"] = $forwardContent ? stripslashes($message["forwardsubject"]) : $message["subject"]; #0013076: different content when forwarding 'to a friend' $cached[$messageid]["content"] = $forwardContent ? stripslashes($message["forwardmessage"]) : $message["message"]; if (USE_MANUAL_TEXT_PART && !$forwardContent) { $cached[$messageid]["textcontent"] = $message["textmessage"]; } else { $cached[$messageid]["textcontent"] = ''; } # var_dump($cached);exit; #0013076: different content when forwarding 'to a friend' $cached[$messageid]["footer"] = $forwardContent ? stripslashes($message["forwardfooter"]) : $message["footer"]; if (strip_tags($cached[$messageid]["footer"]) != $cached[$messageid]["footer"]) { $cached[$messageid]["textfooter"] = HTML2Text($cached[$messageid]["footer"]); $cached[$messageid]["htmlfooter"] = $cached[$messageid]["footer"]; } else { $cached[$messageid]["textfooter"] = $cached[$messageid]["footer"]; $cached[$messageid]["htmlfooter"] = parseText($cached[$messageid]["footer"]); } $cached[$messageid]["htmlformatted"] = strip_tags($cached[$messageid]["content"]) != $cached[$messageid]["content"]; $cached[$messageid]["sendformat"] = $message["sendformat"]; if ($message["template"]) { $req = Sql_Fetch_Row_Query("select template from {$GLOBALS["tables"]["template"]} where id = {$message["template"]}"); $cached[$messageid]["template"] = stripslashes($req[0]); $cached[$messageid]["templateid"] = $message["template"]; # dbg("TEMPLATE: ".$req[0]); } else { $cached[$messageid]["template"] = ''; $cached[$messageid]["templateid"] = 0; } ## @@ put this here, so it can become editable per email sent out at a later stage $cached[$messageid]["html_charset"] = 'UTF-8'; #getConfig("html_charset"); ## @@ need to check on validity of charset if (!$cached[$messageid]["html_charset"]) { $cached[$messageid]["html_charset"] = 'UTF-8'; #'iso-8859-1'; } $cached[$messageid]["text_charset"] = 'UTF-8'; #getConfig("text_charset"); if (!$cached[$messageid]["text_charset"]) { $cached[$messageid]["text_charset"] = 'UTF-8'; #'iso-8859-1'; } ## if we are sending a URL that contains user attributes, we cannot pre-parse the message here ## but that has quite some impact on speed. So check if that's the case and apply $cached[$messageid]['userspecific_url'] = preg_match('/\\[.+\\]/', $message['sendurl']); if (!$cached[$messageid]['userspecific_url']) { ## Fetch external content here, because URL does not contain placeholders if ($GLOBALS["can_fetchUrl"] && preg_match("/\\[URL:([^\\s]+)\\]/i", $cached[$messageid]["content"], $regs)) { $remote_content = fetchUrl($regs[1], array()); # $remote_content = fetchUrl($message['sendurl'],array()); # @@ don't use this # $remote_content = includeStyles($remote_content); if ($remote_content) { $cached[$messageid]['content'] = str_replace($regs[0], $remote_content, $cached[$messageid]['content']); # $cached[$messageid]['content'] = $remote_content; $cached[$messageid]["htmlformatted"] = strip_tags($remote_content) != $remote_content; ## 17086 - disregard any template settings when we have a valid remote URL $cached[$messageid]["template"] = NULL; $cached[$messageid]["templateid"] = NULL; } else { #print Error(s('unable to fetch web page for sending')); logEvent("Error fetching URL: " . $message['sendurl'] . ' cannot proceed'); return false; } } if (VERBOSE && !empty($GLOBALS['getspeedstats'])) { output('fetch URL end'); } /* print $message['sendurl']; print $remote_content;exit; */ } // end if not userspecific url if ($cached[$messageid]["htmlformatted"]) { # $cached[$messageid]["content"] = compressContent($cached[$messageid]["content"]); } $cached[$messageid]['google_track'] = $message['google_track']; /* else { print $message['sendurl']; exit; } */ if (VERBOSE && !empty($GLOBALS['getspeedstats'])) { output('parse config start'); } /* * this is not a good idea, as it'll replace eg "unsubscribeurl" with a general one instead of personalised * if (is_array($GLOBALS["default_config"])) { foreach($GLOBALS["default_config"] as $key => $val) { if (is_array($val)) { $cached[$messageid]['content'] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['content']); $cached[$messageid]["textcontent"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]["textcontent"]); $cached[$messageid]["textfooter"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['textfooter']); $cached[$messageid]["htmlfooter"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['htmlfooter']); } } } */ if (VERBOSE && !empty($GLOBALS['getspeedstats'])) { output('parse config end'); } ## ##17233 not that many fields are actually useful, so don't blatantly use all # foreach($message as $key => $val) { foreach (array('subject', 'id', 'fromname', 'fromemail') as $key) { $val = $message[$key]; if (!is_array($val)) { $cached[$messageid]['content'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['content']); $cached[$messageid]["textcontent"] = str_ireplace("[{$key}]", $val, $cached[$messageid]["textcontent"]); $cached[$messageid]["textfooter"] = str_ireplace("[{$key}]", $val, $cached[$messageid]['textfooter']); $cached[$messageid]["htmlfooter"] = str_ireplace("[{$key}]", $val, $cached[$messageid]['htmlfooter']); } } if (preg_match("/##LISTOWNER=(.*)/", $cached[$messageid]['content'], $regs)) { $cached[$messageid]['listowner'] = $regs[1]; $cached[$messageid]['content'] = str_replace($regs[0], "", $cached[$messageid]['content']); } else { $cached[$messageid]['listowner'] = 0; } if (!empty($cached[$messageid]['listowner'])) { $att_req = Sql_Query("select name,value from {$GLOBALS["tables"]["adminattribute"]},{$GLOBALS["tables"]["admin_attribute"]} where {$GLOBALS["tables"]["adminattribute"]}.id = {$GLOBALS["tables"]["admin_attribute"]}.adminattributeid and {$GLOBALS["tables"]["admin_attribute"]}.adminid = " . $cached[$messageid]['listowner']); while ($att = Sql_Fetch_Array($att_req)) { $cached[$messageid]['content'] = preg_replace("#\\[LISTOWNER." . strtoupper(preg_quote($att["name"])) . "\\]#", $att["value"], $cached[$messageid]['content']); } } $baseurl = $GLOBALS['website']; if (defined('UPLOADIMAGES_DIR') && UPLOADIMAGES_DIR) { ## escape subdirectories, otherwise this renders empty $dir = str_replace('/', '\\/', UPLOADIMAGES_DIR); $cached[$messageid]['content'] = preg_replace('/<img(.*)src="\\/' . $dir . '(.*)>/iU', '<img\\1src="' . $GLOBALS['public_scheme'] . '://' . $baseurl . '/' . UPLOADIMAGES_DIR . '\\2>', $cached[$messageid]['content']); } //if (defined('FCKIMAGES_DIR') && FCKIMAGES_DIR) { //$cached[$messageid]['content'] = preg_replace('/<img(.*)src="\/lists\/'.FCKIMAGES_DIR.'(.*)>/iU','<img\\1src="'.$GLOBALS['public_scheme'].'://'.$baseurl.'/lists/'.FCKIMAGES_DIR.'\\2>',$cached[$messageid]['content']); //} return 1; }
function constructSystemMail($message, $subject = '') { $hasHTML = strip_tags($message) != $message; $htmlcontent = ''; if ($hasHTML) { $message = stripslashes($message); $textmessage = HTML2Text($message); $htmlmessage = $message; } else { $textmessage = $message; $htmlmessage = $message; # $htmlmessage = str_replace("\n\n","\n",$htmlmessage); $htmlmessage = nl2br($htmlmessage); ## make links clickable: preg_match_all('~https?://[^\\s<]+~i', $htmlmessage, $matches); for ($i = 0; $i < count($matches[0]); ++$i) { $match = $matches[0][$i]; $htmlmessage = str_replace($match, '<a href="' . $match . '">' . $match . '</a>', $htmlmessage); } } ## add li-s around the lists if (preg_match('/<ul>\\s+(\\*.*)<\\/ul>/imsxU', $htmlmessage, $listsmatch)) { $lists = $listsmatch[1]; $listsHTML = ''; preg_match_all('/\\*([^\\*]+)/', $lists, $matches); for ($i = 0; $i < count($matches[0]); ++$i) { $listsHTML .= '<li>' . $matches[1][$i] . '</li>'; } $htmlmessage = str_replace($listsmatch[0], '<ul>' . $listsHTML . '</ul>', $htmlmessage); } $htmltemplate = ''; $templateid = getConfig('systemmessagetemplate'); if (!empty($templateid)) { $req = Sql_Fetch_Row_Query(sprintf('select template from %s where id = %d', $GLOBALS['tables']['template'], $templateid)); $htmltemplate = stripslashes($req[0]); } if (strpos($htmltemplate, '[CONTENT]')) { $htmlcontent = str_replace('[CONTENT]', $htmlmessage, $htmltemplate); $htmlcontent = str_replace('[SUBJECT]', $subject, $htmlcontent); $htmlcontent = str_replace('[FOOTER]', '', $htmlcontent); if (!EMAILTEXTCREDITS) { $phpListPowered = preg_replace('/src=".*power-phplist.png"/', 'src="powerphplist.png"', $GLOBALS['PoweredByImage']); } else { $phpListPowered = $GLOBALS['PoweredByText']; } if (strpos($htmlcontent, '[SIGNATURE]')) { $htmlcontent = str_replace('[SIGNATURE]', $phpListPowered, $htmlcontent); } elseif (strpos($htmlcontent, '</body>')) { $htmlcontent = str_replace('</body>', $phpListPowered . '</body>', $htmlcontent); } else { $htmlcontent .= $phpListPowered; } } return array($htmlcontent, $textmessage); }
<?php verifyCsrfGetToken(); # generate text content $msgid = sprintf('%d', $_GET['id']); $messagedata = loadMessageData($msgid); //sleep(10); // to test the busy image if (preg_match('/\\[URL:(.+)\\]/', $messagedata['message'], $regs)) { $content = fetchUrl($regs[1]); # $textversion = 'Fetched '.$regs[1]; $textversion = HTML2Text($content); } else { $textversion = HTML2Text($messagedata['message']); } setMessageData($msgid, 'textmessage', $textversion); ## convert to feedback in the textarea ## @@FIXME this fails when the text is large, or contains £ $textversion = trim($textversion); $textversion = preg_replace("/\n/", '\\n', $textversion); $textversion = preg_replace("/\r/", '', $textversion); $textversion = htmlentities($textversion, ENT_IGNORE, 'UTF-8', true); $status = '<script type="text/javascript"> $("#textmessage").html("' . str_replace('"', '"', $textversion) . '"); //$("#textmessage").load("./?page=pageaction&action=messagedata&field=textmessage&id=' . $msgid . '"); $("#generatetextversion").hide(); </script> ';
/** * Retrieve a URL and send the contents as an HTML email * * @param string $sTo * @param string $sFrom * @param string $sSubject * @param string $sUrl * @return boolean Succes / failure */ function mailURL($sTo, $sFrom, $sSubject, $sUrl) { if ($sHtmlBody = file_get_contents($sUrl)) { $sHtmlBody = addAbsoluteResources($sHtmlBody, sprintf('http://%s/', $_SERVER['HTTP_HOST'])); $sTextBody = HTML2Text($sHtmlBody); return htmlEmail($sTo, $sFrom, $sSubject, $sTextBody, '', $sFrom, $sHtmlBody); } else { Error("URL {$sUrl} could not be opened"); return false; } }
function precacheMessage($messageid, $forwardContent = 0) { global $cached, $tables; $domain = getConfig('domain'); # $message = Sql_query("select * from {$GLOBALS["tables"]["message"]} where id = $messageid"); # $cached[$messageid] = array(); # $message = Sql_fetch_array($message); $message = loadMessageData($messageid); ## the reply to is actually not in use if (preg_match('/([^ ]+@[^ ]+)/', $message['replyto'], $regs)) { # if there is an email in the from, rewrite it as "name <email>" $message['replyto'] = str_replace($regs[0], '', $message['replyto']); $cached[$messageid]['replytoemail'] = $regs[0]; # if the email has < and > take them out here $cached[$messageid]['replytoemail'] = str_replace('<', '', $cached[$messageid]['replytoemail']); $cached[$messageid]['replytoemail'] = str_replace('>', '', $cached[$messageid]['replytoemail']); # make sure there are no quotes around the name $cached[$messageid]['replytoname'] = str_replace('"', '', ltrim(rtrim($message['replyto']))); } elseif (strpos($message['replyto'], ' ')) { # if there is a space, we need to add the email $cached[$messageid]['replytoname'] = $message['replyto']; $cached[$messageid]['replytoemail'] = "listmaster@{$domain}"; } else { if (!empty($message['replyto'])) { $cached[$messageid]['replytoemail'] = $message['replyto'] . "@{$domain}"; ## makes more sense not to add the domain to the word, but the help says it does ## so let's keep it for now $cached[$messageid]['replytoname'] = $message['replyto'] . "@{$domain}"; } } $cached[$messageid]['fromname'] = $message['fromname']; $cached[$messageid]['fromemail'] = $message['fromemail']; $cached[$messageid]['to'] = $message['tofield']; #0013076: different content when forwarding 'to a friend' $cached[$messageid]['subject'] = $forwardContent ? stripslashes($message['forwardsubject']) : $message['subject']; #0013076: different content when forwarding 'to a friend' $cached[$messageid]['content'] = $forwardContent ? stripslashes($message['forwardmessage']) : $message['message']; if (USE_MANUAL_TEXT_PART && !$forwardContent) { $cached[$messageid]['textcontent'] = $message['textmessage']; } else { $cached[$messageid]['textcontent'] = ''; } # var_dump($cached);exit; #0013076: different content when forwarding 'to a friend' $cached[$messageid]['footer'] = $forwardContent ? stripslashes($message['forwardfooter']) : $message['footer']; if (strip_tags($cached[$messageid]['footer']) != $cached[$messageid]['footer']) { $cached[$messageid]['textfooter'] = HTML2Text($cached[$messageid]['footer']); $cached[$messageid]['htmlfooter'] = $cached[$messageid]['footer']; } else { $cached[$messageid]['textfooter'] = $cached[$messageid]['footer']; $cached[$messageid]['htmlfooter'] = parseText($cached[$messageid]['footer']); } $cached[$messageid]['htmlformatted'] = strip_tags($cached[$messageid]['content']) != $cached[$messageid]['content']; $cached[$messageid]['sendformat'] = $message['sendformat']; if ($message['template']) { $req = Sql_Fetch_Row_Query("select template from {$GLOBALS['tables']['template']} where id = {$message['template']}"); $cached[$messageid]['template'] = stripslashes($req[0]); $cached[$messageid]['templateid'] = $message['template']; # dbg("TEMPLATE: ".$req[0]); } else { $cached[$messageid]['template'] = ''; $cached[$messageid]['templateid'] = 0; } ## @@ put this here, so it can become editable per email sent out at a later stage $cached[$messageid]['html_charset'] = 'UTF-8'; #getConfig("html_charset"); ## @@ need to check on validity of charset if (!$cached[$messageid]['html_charset']) { $cached[$messageid]['html_charset'] = 'UTF-8'; #'iso-8859-1'; } $cached[$messageid]['text_charset'] = 'UTF-8'; #getConfig("text_charset"); if (!$cached[$messageid]['text_charset']) { $cached[$messageid]['text_charset'] = 'UTF-8'; #'iso-8859-1'; } ## if we are sending a URL that contains user attributes, we cannot pre-parse the message here ## but that has quite some impact on speed. So check if that's the case and apply $cached[$messageid]['userspecific_url'] = preg_match('/\\[.+\\]/', $message['sendurl']); if (!$cached[$messageid]['userspecific_url']) { ## Fetch external content here, because URL does not contain placeholders if ($GLOBALS['can_fetchUrl'] && preg_match("/\\[URL:([^\\s]+)\\]/i", $cached[$messageid]['content'], $regs)) { $remote_content = fetchUrl($regs[1], array()); # $remote_content = fetchUrl($message['sendurl'],array()); # @@ don't use this # $remote_content = includeStyles($remote_content); if ($remote_content) { $cached[$messageid]['content'] = str_replace($regs[0], $remote_content, $cached[$messageid]['content']); # $cached[$messageid]['content'] = $remote_content; $cached[$messageid]['htmlformatted'] = strip_tags($remote_content) != $remote_content; ## 17086 - disregard any template settings when we have a valid remote URL $cached[$messageid]['template'] = null; $cached[$messageid]['templateid'] = null; } else { #print Error(s('unable to fetch web page for sending')); logEvent('Error fetching URL: ' . $message['sendurl'] . ' cannot proceed'); return false; } } if (VERBOSE && !empty($GLOBALS['getspeedstats'])) { output('fetch URL end'); } /* print $message['sendurl']; print $remote_content;exit; */ } // end if not userspecific url if ($cached[$messageid]['htmlformatted']) { # $cached[$messageid]["content"] = compressContent($cached[$messageid]["content"]); } $cached[$messageid]['google_track'] = $message['google_track']; /* else { print $message['sendurl']; exit; } */ foreach ($GLOBALS['plugins'] as $plugin) { $plugin->processPrecachedCampaign($messageid, $cached[$messageid]); } if (VERBOSE && !empty($GLOBALS['getspeedstats'])) { output('parse config start'); } /* * this is not a good idea, as it'll replace eg "unsubscribeurl" with a general one instead of personalised * if (is_array($GLOBALS["default_config"])) { foreach($GLOBALS["default_config"] as $key => $val) { if (is_array($val)) { $cached[$messageid]['content'] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['content']); $cached[$messageid]["textcontent"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]["textcontent"]); $cached[$messageid]["textfooter"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['textfooter']); $cached[$messageid]["htmlfooter"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['htmlfooter']); } } } */ if (VERBOSE && !empty($GLOBALS['getspeedstats'])) { output('parse config end'); } ## ##17233 not that many fields are actually useful, so don't blatantly use all # foreach($message as $key => $val) { foreach (array('subject', 'id', 'fromname', 'fromemail') as $key) { $val = $message[$key]; if (!is_array($val)) { $cached[$messageid]['content'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['content']); $cached[$messageid]['textcontent'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['textcontent']); $cached[$messageid]['textfooter'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['textfooter']); $cached[$messageid]['htmlfooter'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['htmlfooter']); } } /* * cache message owner and list owner attribute values */ $cached[$messageid]['adminattributes'] = array(); $result = Sql_Query("SELECT a.name, aa.value\n FROM {$tables['adminattribute']} a\n JOIN {$tables['admin_attribute']} aa ON a.id = aa.adminattributeid\n JOIN {$tables['message']} m ON aa.adminid = m.owner\n WHERE m.id = {$messageid}"); if ($result !== false) { while ($att = Sql_Fetch_Array($result)) { $cached[$messageid]['adminattributes']['OWNER.' . $att['name']] = $att['value']; } } $result = Sql_Query("SELECT DISTINCT l.owner\n FROM {$tables['list']} AS l\n JOIN {$tables['listmessage']} AS lm ON lm.listid = l.id\n WHERE lm.messageid = {$messageid}"); if ($result !== false && Sql_Num_Rows($result) == 1) { $row = Sql_Fetch_Assoc($result); $listOwner = $row['owner']; $att_req = Sql_Query("SELECT a.name, aa.value\n FROM {$tables['adminattribute']} a\n JOIN {$tables['admin_attribute']} aa ON a.id = aa.adminattributeid\n WHERE aa.adminid = {$listOwner}"); while ($att = Sql_Fetch_Array($att_req)) { $cached[$messageid]['adminattributes']['LISTOWNER.' . $att['name']] = $att['value']; } } $baseurl = $GLOBALS['website']; if (defined('UPLOADIMAGES_DIR') && UPLOADIMAGES_DIR) { ## escape subdirectories, otherwise this renders empty $dir = str_replace('/', '\\/', UPLOADIMAGES_DIR); $cached[$messageid]['content'] = preg_replace('/<img(.*)src="\\/' . $dir . '(.*)>/iU', '<img\\1src="' . $GLOBALS['public_scheme'] . '://' . $baseurl . '/' . UPLOADIMAGES_DIR . '\\2>', $cached[$messageid]['content']); } foreach (array('content', 'template', 'htmlfooter') as $element) { $cached[$messageid][$element] = parseLogoPlaceholders($cached[$messageid][$element]); } return 1; }
if ($pagesnext < $pageend) { echo "<a class='link' style='padding-right:5px' href='{$linktmp}/{$pageend}'>... {$pageend}</a>"; } ?> </td> </tr> </thead> <tfoot> <tr id="tfoot_paging"></tr> </tfoot> <tbody> <?php foreach ($lstRaovat as $raovat) { $alink = BASE_PATH . "/raovat/view/" . $raovat["raovat"]["id"] . "/" . $raovat["raovat"]["alias"]; $atitle = $raovat["raovat"]["tieude"]; $aintro = trimString(HTML2Text($raovat["raovat"]["noidung"]), 200); ?> <tr> <td align="left"> <a href="<?php echo $alink; ?> "> <div class="first_text" style="min-height: 60px;"> <span class="avata"><?php echo $atitle; ?> </span> <div class="cat_intro" style="padding-left: 10px;color: gray;"><?php echo $aintro; ?>