<commit_before><?php
/**
 * @version $Id$
 * @package Abricos
 * @subpackage Notify
 * @copyright Copyright (C) 2008 Abricos. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * @author <NAME> (<EMAIL>)
 */

class NotifyManager extends Ab_Notification {
	
	/**
	 * 
	 * @var NotifyModule
	 */
	public $module = null;
	
	public $core = null;

	/**
	 * 
	 * @var Ab_Database
	 */
	public $db = null;
	
	public $user = null;
	public $userid = 0;
	private $emlcounter = 1;
	
	public function NotifyManager(NotifyModule $module){
		
		$this->module = $module;
		$core = $module->registry;
		$this->core = $core;
		$this->db = $core->db;
		
		$this->user = $core->user->info;
		$this->userid = $this->user['userid'];
	}
	
	public function SendMail($email, $subject, $message, $from='', $fromName=''){
		/*
		// настройки конфига
		$config['module']['notify']['type'] = "abricos";
		/**/
		$cfg = &CMSRegistry::$instance->config['module']['notify'];
		
		if ($cfg['totestfile']){
			
			$filepath = CWD."/cache/eml";
			@mkdir($filepath);
			$filename = $filepath."/".date("YmdHis", time())."-".($this->emlcounter++).".htm";
			
			$fh = fopen($filename, 'a');

			if (!$fh){ return false; }
			
			$str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body class="yui-skin-sam">
	<div style="width: 600px; margin: 0 auto;">';
			
			$str .= "<p>E-mail: <b>".$email."</b><br />";
			$str .= "From: ".$from."<br />";
			$str .= "FromName: ".$fromName."<br />";
			$str .= "Subject: <b>".$subject."</b><br />";
			$str .= "Message (html code):</p>";
			$str .= '<textarea style="width: 100%; height: 300px;">';
			$str .= htmlspecialchars($message);
			$str .= '</textarea>';
			
			$str .= "<p>Message (preview):</p>";
			$str .= "<div style='background-color: #F0F0F0;'>".$message."</div>";
			
			$str .= '</div></body></html>';
			
			fwrite($fh, $str);
			fflush($fh);
			fclose($fh);
			
			return true;
		}else{
			switch($cfg['type']){
				case 'abricos':
					return $this->SendByAbricos($email, $subject, $message, $from, $fromName);
				default: 
					return $this->SendByMailer($email, $subject, $message, $from, $fromName);
			}
		}
	}
	
	
	/**
	 * Отправка почты через PHPMailer
	 * 
	 * Настройка SMTP в файле config.php
	 * $config["module"]["notify"] = array(
	 * 	"SMTP" => true,							// Использовать SMTP
	 * 	"SMTPHost" => "mail.yourdomain.com",	// SMTP сервер
	 * 	"SMTPPort" => 26,						// SMTP порт
	 * 	"SMTPAuth" => true,						// использовать авторизацию SMTP
	 * 	"SMTPUsername" => "<EMAIL>",	// имя пользователя SMTP
	 * 	"SMTPPassword" => "<PASSWORD>",		// пароль пользователя SMTP
	 * 
	 *  // Если необходима предварительная POP3 авторизация
	 *  "POPBefore" => false, 					// Использовать POP3
	 *  "POPHost" => "mail.youdomain.com", 		// POP3 сервер 
	 *	"POPPort" => 110,						// POP3 порт
	 *	"POPUsername" => "yo<EMAIL>",	// имя пользователя POP3
	 *	"POPPassword" => "<PASSWORD>"			// пароль пользователя POP3
	 * );
	 * 
	 * @param string $email
	 * @param string $subject
	 * @param string $message
	 * @param string $from
	 * @param string $fromName
	 */
	
	public function SendByMailer($email, $subject, $message, $from='', $fromName=''){
		
		$cfg = &CMSRegistry::$instance->config['module']['notify'];
		
		$mailer = new NotifyMailer();
		if (!$mailer->ValidateAddress($email)){
			return false;
		}
		
		if ($cfg['POPBefore']){ // авторизация POP перед SMTP
			require_once 'phpmailer/class.pop3.php';
			$pop = new POP3();
			$res = $pop->Authorise($cfg['POPHost'], $cfg['POPPort'], 30, $cfg['POPUsername'], $cfg['POPPassword']);
		}
		
		if ($cfg['SMTP']){ // использовать SMTP
			$mailer->IsSMTP();
			$mailer->Host = $cfg['SMTPHost'];
			if (intval($cfg['SMTPPort']) > 0){
				$mailer->Port = intval($cfg['SMTPPort']);
			}
			
		if ($cfg['SMTPAuth']){
				$mailer->SMTPAuth = true;
				$mailer->Username = $cfg['SMTPUsername'];
				$mailer->Password = $cfg['SMTPPassword'];
			}
		}
		
		$mailer->Subject = $subject;
		$mailer->MsgHTML($message);
		$mailer->AddAddress($email);
		if (!empty($from)){
			$mailer->From = $from;
		}
		if (!empty($fromName)){
			$mailer->FromName = $fromName;
		}
		
		$result = $mailer->Send();
		return $result;
	}
	
	public function SendByAbricos($email, $subject, $message, $from='', $fromName=''){
		$mailer = new NotifyAbricos();
		$mailer->email = $email;
		$mailer->subject = $subject;
		$mailer->message = $message;
		if (!empty($from)){
			$mailer->from = $from;
		}
		if (!empty($fromName)){
			$mailer->fromName = $fromName;
		}
		$mailer->Send();
	}
}

class NotifyAbricos {
	
	public $fromName = "";
	public $from = "";
	public $email = "";
	public $subject = "";
	public $message = "";
	
	private $host = "";
	private $password = "";
	<commit_msg>Notify: добавлен лог отправки<commit_after><?php
/**
 * @version $Id$
 * @package Abricos
 * @subpackage Notify
 * @copyright Copyright (C) 2008 Abricos. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * @author <NAME> (<EMAIL>)
 */

class NotifyManager extends Ab_Notification {
	
	/**
	 * 
	 * @var NotifyModule
	 */
	public $module = null;
	
	public $core = null;

	/**
	 * 
	 * @var Ab_Database
	 */
	public $db = null;
	
	public $user = null;
	public $userid = 0;
	private $emlcounter = 1;
	
	public function NotifyManager(NotifyModule $module){
		
		$this->module = $module;
		$core = $module->registry;
		$this->core = $core;
		$this->db = $core->db;
		
		$this->user = $core->user->info;
		$this->userid = $this->user['userid'];
	}
	
	public function SendMail($email, $subject, $message, $from='', $fromName=''){
		/*
		// настройки конфига
		$config['module']['notify']['type'] = "abricos";
		/**/
		$cfg = &CMSRegistry::$instance->config['module']['notify'];
		
		if ($cfg['totestfile']){
			
			$filepath = CWD."/cache/eml";
			@mkdir($filepath);
			$filename = $filepath."/".date("YmdHis", time())."-".($this->emlcounter++).".htm";
			
			$fh = fopen($filename, 'a');

			if (!$fh){ return false; }
			
			$str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body class="yui-skin-sam">
	<div style="width: 600px; margin: 0 auto;">';
			
			$str .= "<p>E-mail: <b>".$email."</b><br />";
			$str .= "From: ".$from."<br />";
			$str .= "FromName: ".$fromName."<br />";
			$str .= "Subject: <b>".$subject."</b><br />";
			$str .= "Message (html code):</p>";
			$str .= '<textarea style="width: 100%; height: 300px;">';
			$str .= htmlspecialchars($message);
			$str .= '</textarea>';
			
			$str .= "<p>Message (preview):</p>";
			$str .= "<div style='background-color: #F0F0F0;'>".$message."</div>";
			
			$str .= '</div></body></html>';
			
			fwrite($fh, $str);
			fflush($fh);
			fclose($fh);
			
			return true;
		}else{
			switch($cfg['type']){
				case 'abricos':
					return $this->SendByAbricos($email, $subject, $message, $from, $fromName);
				default: 
					return $this->SendByMailer($email, $subject, $message, $from, $fromName);
			}
		}
	}
	
	
	/**
	 * Отправка почты через PHPMailer
	 * 
	 * Настройка SMTP в файле config.php
	 * $config["module"]["notify"] = array(
	 * 	"SMTP" => true,							// Использовать SMTP
	 * 	"SMTPHost" => "mail.yourdomain.com",	// SMTP сервер
	 * 	"SMTPPort" => 26,						// SMTP порт
	 * 	"SMTPAuth" => true,						// использовать авторизацию SMTP
	 * 	"SMTPUsername" => "<EMAIL>",	// имя пользователя SMTP
	 * 	"SMTPPassword" => "<PASSWORD>",		// пароль пользователя SMTP
	 * 
	 *  // Если необходима предварительная POP3 авторизация
	 *  "POPBefore" => false, 					// Использовать POP3
	 *  "POPHost" => "mail.youdomain.com", 		// POP3 сервер 
	 *	"POPPort" => 110,						// POP3 порт
	 *	"POPUsername" => "<EMAIL>",	// имя пользователя POP3
	 *	"POPPassword" => "<PASSWORD>"			// пароль пользователя POP3
	 * );
	 * 
	 * @param string $email
	 * @param string $subject
	 * @param string $message
	 * @param string $from
	 * @param string $fromName
	 */
	
	public function SendByMailer($email, $subject, $message, $from='', $fromName=''){
		
		$cfg = &CMSRegistry::$instance->config['module']['notify'];
		
		$mailer = new NotifyMailer();
		if (!$mailer->ValidateAddress($email)){
			return false;
		}
		
		if ($cfg['POPBefore']){ // авторизация POP перед SMTP
			require_once 'phpmailer/class.pop3.php';
			$pop = new POP3();
			$res = $pop->Authorise($cfg['POPHost'], $cfg['POPPort'], 30, $cfg['POPUsername'], $cfg['POPPassword']);
		}
		
		if ($cfg['SMTP']){ // использовать SMTP
			$mailer->IsSMTP();
			$mailer->Host = $cfg['SMTPHost'];
			if (intval($cfg['SMTPPort']) > 0){
				$mailer->Port = intval($cfg['SMTPPort']);
			}
			
		if ($cfg['SMTPAuth']){
				$mailer->SMTPAuth = true;
				$mailer->Username = $cfg['SMTPUsername'];
				$mailer->Password = $cfg['<PASSWORD>'];
			}
		}
		
		$mailer->Subject = $subject;
		$mailer->MsgHTML($message);
		$mailer->AddAddress($email);
		if (!empty($from)){
			$mailer->From = $from;
		}
		if (!empty($fromName)){
			$mailer->FromName = $fromName;
		}
		
		$result = $mailer->Send();
		
		if (!$result && $cfg['errorlog']){
			$filepath = CWD."/cache/eml";
			@mkdir($filepath);
			$filename = $filepath."/error.log";
				
			$fh = fopen($filename, 'a');
		
			if (!$fh){
				return false;
			}
				
			$str = date("YmdHis", time())." ";
			$str .=  $mailer->ErrorInfo."\n";
				
			fwrite($fh, $str);
			fflush($fh);
			fclose($fh);
		}
		
		return $result;
	}
	
	public function SendByAbricos($email, $subject, $message, $from='', $fromName=''){
		$mailer = new NotifyAbricos();
		$mailer->email = $email;
		$mailer->subject = $subject;
		$mailer->message = $message;
		if (!empty($from)){
			$mailer->from = $from;
		}
		if (!empty($fromName)){
			$mailer->fromName = $fromName;
		}
		$mailer->Send();
	}
}

class NotifyAbricos {
	
	public $fromName = "";
	public $from = "";
	public $email = "";
	public $subject = "";
	public $message = "";
	
	private $host = "";
	private $password = "";
	
{'fraction_non_alphanumeric': 0.22036342659359676, 'fraction_numerical': 0.009037592539178924, 'mean_word_length': 3.291254125412541, 'pattern_counts': {'":': 0, '<': 70, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4512581', 'n_tokens_mistral': 4571, 'n_tokens_neox': 3936, 'n_words': 763}