[ Index ] |
PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 23 session_start(); 24 $phpwcms = array(); 25 require_once ('../../config/phpwcms/conf.inc.php'); 26 require_once ('../inc_lib/default.inc.php'); 27 require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php'); 28 29 require_once (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php'); 30 checkLogin(); 31 require_once (PHPWCMS_ROOT.'/include/inc_ext/phpmailer/class.phpmailer.php'); 32 //load default language EN 33 require_once (PHPWCMS_ROOT.'/include/inc_lang/backend/en/lang.inc.php'); 34 if($_SESSION["wcs_user_lang_custom"]) { //use custom lang if available -> was set in login.php 35 include(PHPWCMS_ROOT.'/include/inc_lang/backend/'.substr($_SESSION["wcs_user_lang"],0,2).'/lang.inc.php'); 36 } 37 38 ?> 39 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 40 <html xmlns="http://www.w3.org/1999/xhtml"> 41 <head> 42 <title>phpwcms: Send Newsletter</title> 43 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 44 <link href="../inc_css/newsletter.iframe.css" rel="stylesheet" type="text/css" /> 45 </head> 46 <body> 47 <?php 48 49 $newsletter_id = empty($_GET['newsletter_id']) ? 0 : intval($_GET['newsletter_id']); 50 51 if($newsletter_id) { 52 // read the given subscription datas from db 53 $sql = "SELECT *FROM ".DB_PREPEND."phpwcms_newsletter WHERE newsletter_id=".$newsletter_id." LIMIT 1"; 54 $newsletter = _dbQuery($sql); 55 if(isset($newsletter[0]['newsletter_vars'])) { 56 $newsletter[0]['newsletter_vars'] = unserialize($newsletter[0]['newsletter_vars']); 57 $newsletter = $newsletter[0]; 58 } else { 59 $newsletter = false; 60 } 61 } else { 62 $newsletter = false; 63 } 64 65 if(!$newsletter) { 66 67 echo 'No valid newsletter ID given.'; 68 69 } elseif($_SESSION["wcs_user_admin"] == 1) { 70 71 $notest = 1; 72 $recipient = array(); 73 $loop = isset($_GET['loop']) ? intval($_GET['loop']) : 0; 74 if(!$loop && @ini_get('safe_mode') == '1') { 75 $loop = 25; 76 } 77 $pause = isset($_GET['pause']) ? intval($_GET['pause']) : 1; 78 79 //check if a test email should be send 80 if(!empty($_GET['send_testemail'])) { 81 82 $notest = 0; 83 84 $test_email_error = array(); 85 $test_email = clean_slweg($_GET['send_testemail']); 86 $test_email = str_replace(array(' ', ','), ';', $test_email); 87 $test_email = convertStringToArray($test_email, ';'); 88 89 foreach($test_email as $test_email_value) { 90 if(is_valid_email($test_email_value)) { 91 92 $recipient[] = array( 'address_name' => 'Newsletter test recipient', 93 'address_email' => $test_email_value, 94 'address_key' => '', 95 'queue_id' => 0 ); 96 97 echo '<p><strong>'.$BL['be_newsletter_testemail'].'</strong></p>'; 98 99 } else { 100 $test_email_error[] = $test_email_value; 101 } 102 } 103 104 if(count($test_email_error)) { 105 echo str_replace('###TEST###', ' • '.implode(' • ', $test_email_error), $BL['be_newsletter_testerror']); 106 } 107 108 109 } elseif(isset($_GET['send_confirm']) && $_GET['send_confirm'] == 'confirmed') { 110 111 // retrieve all recipients now 112 113 // disable time limit 114 if(!$loop) { 115 set_time_limit(0); 116 } 117 118 // retrieve recipients for current loop 119 $sql = 'SELECT address_key, address_email, address_name, queue_id '; 120 $sql .= 'FROM '.DB_PREPEND.'phpwcms_address '; 121 $sql .= 'LEFT JOIN '.DB_PREPEND.'phpwcms_newsletterqueue '; 122 $sql .= 'ON '.DB_PREPEND.'phpwcms_address.address_id = '.DB_PREPEND.'phpwcms_newsletterqueue.queue_rid '; 123 $sql .= 'WHERE '.DB_PREPEND.'phpwcms_newsletterqueue.queue_status=0 AND '; 124 $sql .= DB_PREPEND.'phpwcms_newsletterqueue.queue_pid='.$newsletter["newsletter_id"]; 125 if($loop) { 126 $sql .= ' LIMIT '.$loop; 127 } 128 $recipient = _dbQuery($sql); 129 130 131 } else { 132 133 // do nothing 134 135 } 136 137 138 if(count($recipient)) { 139 140 echo '<p><strong>'.$BL['be_newsletter_to'].': </strong><p>'; 141 142 // check for newsletter template 143 if(!empty($newsletter['newsletter_vars']['template']) && ($template = @file_get_contents(PHPWCMS_TEMPLATE.'inc_newsletter/'.$newsletter['newsletter_vars']['template'].'/newsletter.tmpl'))) { 144 $template_html = trim(get_tmpl_section('HTML', $template)); 145 $template_text = trim(get_tmpl_section('TEXT', $template)); 146 if($template_html) { 147 $newsletter['newsletter_vars']['html'] = str_replace('{CONTENT}', $newsletter['newsletter_vars']['html'], $template_html); 148 } 149 if($template_text) { 150 $newsletter['newsletter_vars']['text'] = str_replace('{CONTENT}', $newsletter['newsletter_vars']['text'], $template_text); 151 } 152 } 153 154 $mail = new PHPMailer(); 155 $mail->Mailer = $phpwcms['SMTP_MAILER']; 156 $mail->Host = $phpwcms['SMTP_HOST']; 157 $mail->Port = $phpwcms['SMTP_PORT']; 158 $mail->CharSet = $phpwcms["charset"]; 159 if($phpwcms['SMTP_AUTH']) { 160 $mail->SMTPAuth = 1; 161 $mail->Username = $phpwcms['SMTP_USER']; 162 $mail->Password = $phpwcms['SMTP_PASS']; 163 } 164 165 $mail->From = $newsletter['newsletter_vars']['from_email']; 166 $mail->FromName = $newsletter['newsletter_vars']['from_name']; 167 $mail->Sender = $newsletter['newsletter_vars']['replyto']; 168 $mail->Subject = $newsletter['newsletter_subject']; 169 170 if(!$mail->SetLanguage($phpwcms['default_lang'])) { 171 $mail->SetLanguage('en'); 172 } 173 174 $mail->SMTPKeepAlive = true; 175 176 $x = 0; 177 178 foreach($recipient as $value) { 179 180 if($x == 20) { 181 $mail->SmtpClose(); // Manually close the SMTP connection 182 $mail->SMTPKeepAlive = true; 183 } 184 185 $mail->AddAddress($value['address_email'], $value['address_name']); 186 187 if($newsletter['newsletter_vars']['html'] && $newsletter['newsletter_vars']['text']) { 188 //send both TEXT and HTML part 189 $mail->Body = build_email_text($newsletter['newsletter_vars']['html'], $value); 190 $mail->AltBody = build_email_text($newsletter['newsletter_vars']['text'], $value); 191 $mail->IsHTML(1); 192 } 193 194 if($newsletter['newsletter_vars']['html'] && !$newsletter['newsletter_vars']['text']) { 195 //send HTML part 196 $mail->Body = build_email_text($newsletter['newsletter_vars']['html'], $value); 197 $mail->IsHTML(1); 198 } 199 200 if(!$newsletter['newsletter_vars']['html'] && $newsletter['newsletter_vars']['text']) { 201 //send TEXT part 202 $mail->Body = build_email_text($newsletter['newsletter_vars']['text'], $value); 203 $mail->IsHTML(0); 204 } 205 206 // update newsletter queue 207 $sql = 'UPDATE '.DB_PREPEND.'phpwcms_newsletterqueue SET '; 208 $sql .= 'queue_changed=NOW(), '; 209 if( ( $mailresult = $mail->Send() ) == false ) { 210 // save error information 211 $sql .= 'queue_status=2, '; 212 $sql .= "queue_errormsg='".aporeplace($mail->ErrorInfo)."' "; 213 } else { 214 // save success 215 $sql .= 'queue_status=1 '; 216 } 217 $sql .= 'WHERE queue_id='.$value['queue_id']; 218 @_dbQuery($sql, 'UPDATE'); 219 220 if($mailresult == false) { 221 echo '<p style="color:#CC3300">'.$value['address_email'].' ('.$mail->ErrorInfo.')</p>'; 222 } else { 223 echo '. '; 224 } 225 flush(); 226 227 $mail->ClearAddresses(); 228 $x++; 229 230 if($loop && $loop == $x) { 231 $mail->SmtpClose(); 232 updateSentDate($newsletter["newsletter_id"]); 233 echo '<script language="javascript" type="text/javascript">'.LF.SCRIPT_CDATA_START.LF; 234 echo 'function loopIt() { self.location.href="act_sendnewsletter.php?'; 235 echo 'newsletter_id='.$newsletter["newsletter_id"].'&'; 236 echo 'send_confirm=confirmed&loop='.$loop.'&pause='.$pause.'"; }'.LF; 237 echo 'window.setTimeout("loopIt()", '. ($pause * 1000) .')'.LF; 238 echo LF.SCRIPT_CDATA_END.LF.'</script></body></html>'; 239 240 flush(); 241 exit(); 242 } 243 244 } 245 246 $mail->SmtpClose(); 247 updateSentDate($newsletter["newsletter_id"]); 248 echo '<br /><br />'; 249 echo $BL['be_newsletter_ready']; 250 251 252 } 253 254 } else { 255 echo 'no permission'; 256 } 257 258 function build_email_text($text, &$value) { 259 260 //build right message part 261 $refkey = rawurlencode($value['address_key']); 262 263 $text = str_replace('###RECIPIENT_NAME###', $value['address_name'], $text); 264 $text = str_replace('###RECIPIENT_EMAIL###', $value['address_email'], $text); 265 $text = str_replace('###SITE_URL###', PHPWCMS_URL, $text); 266 $text = str_replace('###VERIFY_LINK###', PHPWCMS_URL.'verify.php?s='.$refkey, $text); 267 $text = str_replace('###DELETE_LINK###', PHPWCMS_URL.'verify.php?u='.$refkey, $text); 268 269 return $text; 270 271 } 272 273 function updateSentDate($id=0) { 274 275 $sql = "UPDATE ".DB_PREPEND."phpwcms_newsletter SET "; 276 $sql .= "newsletter_lastsending=NOW(), "; 277 $sql .= "newsletter_changed=newsletter_changed "; 278 $sql .= "WHERE newsletter_id=".$id." LIMIT 1"; 279 _dbQuery($sql, 'UPDATE'); 280 281 } 282 283 284 ?> 285 </body> 286 </html>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 30 05:55:15 2009 | Cross-referenced by PHPXref 0.7 |