175 lines
5.8 KiB
PHP
175 lines
5.8 KiB
PHP
|
<?php
|
||
|
|
||
|
if (IN_serendipity !== true) {
|
||
|
die ("Don't hack!");
|
||
|
}
|
||
|
|
||
|
|
||
|
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
||
|
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
||
|
if (file_exists($probelang)) {
|
||
|
include $probelang;
|
||
|
}
|
||
|
|
||
|
include dirname(__FILE__) . '/lang_en.inc.php';
|
||
|
|
||
|
class serendipity_event_smtpmail extends serendipity_event
|
||
|
{
|
||
|
var $title = PLUGIN_EVENT_SMTPMAIL_NAME;
|
||
|
|
||
|
function introspect(&$propbag)
|
||
|
{
|
||
|
global $serendipity;
|
||
|
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_NAME);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_DESC);
|
||
|
$propbag->add('stackable', false);
|
||
|
$propbag->add('author', 'kleinerChemiker');
|
||
|
$propbag->add('version', '0.11');
|
||
|
$propbag->add('license', 'GPL');
|
||
|
$propbag->add('requirements', array(
|
||
|
'serendipity' => '1.3',
|
||
|
'php' => '4.1.0'
|
||
|
));
|
||
|
$propbag->add('event_hooks', array(
|
||
|
'backend_sendmail' => true
|
||
|
));
|
||
|
$propbag->add('groups', array('BACKEND_FEATURES'));
|
||
|
|
||
|
$conf_array = array();
|
||
|
$conf_array[] = 'smtpmail_smtp_server';
|
||
|
$conf_array[] = 'smtpmail_smtp_port';
|
||
|
$conf_array[] = 'smtpmail_auth';
|
||
|
$conf_array[] = 'smtpmail_secure';
|
||
|
$conf_array[] = 'smtpmail_pop3_server';
|
||
|
$conf_array[] = 'smtpmail_pop3_port';
|
||
|
$conf_array[] = 'smtpmail_user';
|
||
|
$conf_array[] = 'smtpmail_passwd';
|
||
|
$propbag->add('configuration', $conf_array);
|
||
|
}
|
||
|
|
||
|
function introspect_config_item($name, &$propbag) {
|
||
|
switch($name) {
|
||
|
case 'smtpmail_smtp_server':
|
||
|
$propbag->add('type', 'string');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_SMTP_SERVER);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_SMTP_SERVER_DESC);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_smtp_port':
|
||
|
$propbag->add('type', 'string');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_SMTP_PORT);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_SMTP_PORT_DESC);
|
||
|
$propbag->add('validate', 'number');
|
||
|
$propbag->add('default', 25);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_auth':
|
||
|
$propbag->add('type', 'select');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_AUTH);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_AUTH_DESC);
|
||
|
$propbag->add('select_values', array(
|
||
|
0 => 'none',
|
||
|
1 => 'POP3 before SMTP',
|
||
|
2 => 'SMTP AUTH',
|
||
|
));
|
||
|
$propbag->add('default', 0);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_secure':
|
||
|
$propbag->add('type', 'select');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_SECURE);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_SECURE_DESC);
|
||
|
$propbag->add('select_values', array(
|
||
|
0 => 'none',
|
||
|
'ssl' => 'SSL',
|
||
|
'tls' => 'TLS',
|
||
|
));
|
||
|
$propbag->add('default', 0);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_pop3_server':
|
||
|
$propbag->add('type', 'string');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_POP3_SERVER);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_POP3_SERVER_DESC);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_pop3_port':
|
||
|
$propbag->add('type', 'string');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_POP3_PORT);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_POP3_PORT_DESC);
|
||
|
$propbag->add('validate', 'number');
|
||
|
$propbag->add('default', 110);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_user':
|
||
|
$propbag->add('type', 'string');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_USER);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_USER_DESC);
|
||
|
break;
|
||
|
|
||
|
case 'smtpmail_passwd':
|
||
|
$propbag->add('type', 'string');
|
||
|
$propbag->add('name', PLUGIN_EVENT_SMTPMAIL_PASSWD);
|
||
|
$propbag->add('description', PLUGIN_EVENT_SMTPMAIL_PASSWD_DESC);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
function generate_content(&$title) {
|
||
|
$title = $this->title;
|
||
|
}
|
||
|
|
||
|
function event_hook($event, &$bag, &$eventData, $addData = null) {
|
||
|
global $serendipity;
|
||
|
|
||
|
if ($event == 'backend_sendmail') {
|
||
|
# Load phpmailer
|
||
|
substr(PHP_VERSION, 0,1) > 4 ? include_once('php5/class.phpmailer.php') : include_once('php4/class.phpmailer.php');
|
||
|
|
||
|
# Login to POP3 Server if Auth is "POP3 before SMTP"
|
||
|
if ($this->get_config('smtpmail_auth') == 1) {
|
||
|
substr(PHP_VERSION, 0,1) > 4 ? include_once('php5/class.pop3.php') : include_once('php4/class.pop3.php');
|
||
|
$pop = new POP3();
|
||
|
$pop->Authorise($this->get_config('smtpmail_pop3_server'), $this->get_config('smtpmail_pop3_port'), false, $this->get_config('smtpmail_user'), $this->get_config('smtpmail_passwd'), 0);
|
||
|
}
|
||
|
|
||
|
$mail = new PHPMailer();
|
||
|
$mail->IsSMTP();
|
||
|
|
||
|
# Activate Auth if Auth is "SMTP AUTH"
|
||
|
if ($this->get_config('smtpmail_auth') == 2) {
|
||
|
$mail->SMTPAuth = true;
|
||
|
if ($this->get_config('smtpmail_auth') != 0) {$mail->SMTPSecure = $this->get_config('smtpmail_secure');}
|
||
|
$mail->Username = $this->get_config('smtpmail_user');
|
||
|
$mail->Password = $this->get_config('smtpmail_passwd');
|
||
|
}
|
||
|
|
||
|
$mail->IsHTML(false);
|
||
|
$mail->Host = $this->get_config('smtpmail_smtp_server');
|
||
|
$mail->Port = $this->get_config('smtpmail_smtp_port');
|
||
|
$mail->From = $eventData['fromMail'];
|
||
|
$mail->FromName = $eventData['fromName'];
|
||
|
$mail->Subject = $eventData['subject'];
|
||
|
$mail->Body = $eventData['message'];
|
||
|
$mail->CharSet = LANG_CHARSET;
|
||
|
if (strpos($eventData['to'], '<') === false || strpos($eventData['to'], '>') === false) {
|
||
|
$mail->AddAddress($eventData['to']);
|
||
|
}
|
||
|
else {
|
||
|
preg_match('/^(.)+ <(.)+>$/',$eventData['to'], $splited_mail);
|
||
|
$mail->AddAddress($splited_mail[2], $splited_mail[1]);
|
||
|
}
|
||
|
$eventData['skip_native'] = true;
|
||
|
return $mail->send();
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|