📄 email.class.inc.php
字号:
// will be able to read e-mails
if ($t12l['public_mails'] == 'N' and t12l_session::get('address_id')) {
$sql = "SELECT m.*
FROM " . T12L_MAIL_TABLE . " AS m
WHERE m.mail_id = ?
AND m.mail_address_id = ?";
$data = array((int)$mail, t12l_session::get('address_id'));
}
// Public e-mails - everyone can read the e-mails
if ($t12l['public_mails'] == 'Y') {
$sql = "SELECT m.*
FROM " . T12L_MAIL_TABLE . " AS m
WHERE m.mail_id = ?";
$data = array((int)$mail);
}
if ($sql == '') {
return false;
}
t12l_system_debug::add_message('SQL Statement get_mail()', $sql, 'debug');
if ($db = t12l_database::query($sql, $data)) {
$res = $db->fetchRow();
if (PEAR::isError($res)) {
t12l_system_debug::add_message($res->getMessage(), $res->getDebugInfo(), 'error', $res->getBacktrace());
t12l_system_debug::add_message('SQL Statement', $sql, 'error');
return false;
}
if (sizeof($res) > 0) {
$res['frontend_date'] = t12l_time::format_date($res['mail_timestamp']);
$res['frontend_time'] = t12l_time::format_time($res['mail_timestamp']);
$res['frontend_subject'] = $res['mail_subject'];
$frontend_text = $res['mail_body'];
// Convert character sets
if (function_exists('iconv')
and $t12l['text']['txt_charset'] != $res['mail_character_set']) {
if ($result = @iconv($res['mail_character_set'], $t12l['text']['txt_charset'] . '//TRANSLIT', $res['mail_subject'])) {
$res['frontend_subject'] = $result;
}
if ($result = @iconv($res['mail_character_set'], $t12l['text']['txt_charset'] . '//TRANSLIT', $frontend_text)) {
$frontend_text = $result;
}
}
if ($t12l['message_body_format'] != 'html') {
$frontend_text = preg_replace('/<a href="(.*?)"(.*?)>(.*?)<\\/a>/i', '<a href="$1">$3 - $1 </a>', $frontend_text);
$frontend_text = preg_replace('/<http(.*?)>/i', 'http$1', $frontend_text);
$frontend_text = strip_tags($frontend_text);
$frontend_text = nl2br(htmlspecialchars($frontend_text));
}
$res['frontend_subject'] = htmlspecialchars(strip_tags($res['frontend_subject']));
$res['frontend_text'] = $frontend_text;
$res['frontend_from'] = htmlspecialchars(stripslashes($res['mail_from']));
t12l_module::call_module('frontend_content', $res, $t12l['module_additional']);
return $res;
} else {
$t12l['message'][] = $t12l['text']['txt_mail_not_found'];
return false;
}
}
}
// -----------------------------------------------------------------------------
/**
* Send reply e-mail
*
*/
function send_reply($mail_id)
{
global $t12l;
if (!$mail_data = $this->get_mail($mail_id)) {
return false;
}
$mail_data['comment'] = $t12l['_post']['text'];
$mail_data['email'] = '';
$mail_data['homepage'] = '';
$mail_data['comment_author_ip'] = getenv('REMOTE_ADDR');
$mail_data['name'] = t12l_session::get('address_email');
$page_data = array(
'page_allow_comment' => ''
);
t12l_module::call_module('frontend_save_content', $mail_data, $page_data);
// Reply message blocked
if ($page_data['page_allow_comment'] == 'N') {
return false;
}
$search = array("\r", "\n", "%0A", "%0D");
// Prepare to
$reply_to = str_replace($search, '', $mail_data['mail_from']);
// Prepare subject
$reply_subject = str_replace($search, '', $mail_data['mail_subject']);
// Convert character sets
if (function_exists('iconv')
and $t12l['text']['txt_charset'] != $mail_data['mail_character_set']) {
if ($result = @iconv($mail_data['mail_character_set'], $t12l['text']['txt_charset'] . '//TRANSLIT', $reply_subject)) {
$reply_subject = $result;
}
}
$reply_subject = 'RE: ' . $reply_subject;
// Prepare body
$reply_body = htmlspecialchars(strip_tags($t12l['_post']['text']));
$detail_template = 'reply.tpl.txt';
$t12l['alternative_template'] = 'mail';
// Start output handling
$out = new t12l_output($detail_template);
$out->assign('reply_body', $reply_body);
$reply_coutput = $out->finish_mail();
// Send mail off
include 'mail.class.inc.php';
if (t12l_mail::send($reply_to,
$reply_subject,
$reply_coutput,
t12l_session::get('address_email'))) {
// Count number of sent e-mails
t12l_setting::increase('sent_emails');
return true;
}
}
//------------------------------------------------------------------------------
/**
* Delete old mails and addresses
*
*/
function delete_expired()
{
$timestamp = (t12l_time::current_timestamp() - $this->lifetime);
// Delete e-mails
$where = " mail_timestamp < ? LIMIT 500";
$data = array($timestamp);
if (!$res = t12l_database::delete(T12L_MAIL_TABLE, $where, $data)) {
return false;
}
// Delete addresses
$where = " address_timestamp < ? LIMIT 500";
$data = array($timestamp);
if ($res = t12l_database::delete(T12L_ADDRESS_TABLE, $where, $data)) {
return true;
}
}
//------------------------------------------------------------------------------
/**
* Delete e-mail
*
*/
function delete_mail($mail_id)
{
if (!is_numeric($mail_id)) {
return false;
}
// Delete e-mails
$where = " mail_id = ? AND mail_address_id = ?";
$data = array($mail_id, t12l_session::get('address_id'));
if ($res = t12l_database::delete(T12L_MAIL_TABLE, $where, $data)) {
return true;
}
}
//------------------------------------------------------------------------------
/**
* Get e-mail message list
*
*/
function email_message_list()
{
global $t12l;
if ($address = t12l_session::get('address_id')) {
include 'emaillist.class.inc.php';
$mail_list_setup = array( 'direction' => $t12l['frontend_order'],
'limit' => 0);
$mail_list = new t12l_email_list(false, $mail_list_setup);
$result = array();
if ($mail_data = $mail_list->get_list($address)) {
$result['mail_data'] = $mail_data;
}
$result['mail_list_values'] = $mail_list->values();
return $result;
}
}
//------------------------------------------------------------------------------
/**
* XMLHTTPRequest
*
*/
function xmlhttprequest($function)
{
//sleep(1);
if ($function == 'refresh') {
$this->xhr_refresh();
}
if ($function == 'setaddress') {
$this->xhr_set_address();
}
if ($function == 'message') {
$this->xhr_message();
}
}
//------------------------------------------------------------------------------
/**
* XMLHTTPRequest
*
*/
function xhr_refresh()
{
$detail_template = 'emailmessagelist.tpl.html';
$show_mail_list = false;
$out = new t12l_output();
$email_message_result = $this->email_message_list();
if (isset($email_message_result['mail_data'])) {
$out->assign('mail_list', $email_message_result['mail_data']);
$show_mail_list = true;
}
$out->assign($email_message_result['mail_list_values']);
$out->assign('show_mail_list', $show_mail_list);
echo $out->finish_xmlhttprequest($detail_template);
exit;
}
//------------------------------------------------------------------------------
/**
* XMLHTTPRequest
*
*/
function xhr_set_address()
{
global $t12l;
$detail_template = 'emailaddress.tpl.html';
// Build e-mail address from input and from defined e-mail host name
if (isset($t12l['_post']['setemail'])) {
$_POST['setemailaddressintern'] = $_POST['setemailaddress'] . '@' . $t12l['email_address_host_name'];
}
// Handle and validate form
require_once 'HTML/QuickForm.php';
// Start form handler
$form = new HTML_QuickForm('setemailform', 'POST', $t12l['script_url'] . '?d=xhr&f=setaddress', '', 'onsubmit="return !HTML_AJAX.formSubmit(this, \'temporary_address\');"');
// Get form configuration
require 'email_form.inc.php';
// Validate form
$mail = new t12l_email();
if (isset($t12l['_post']['setemail'])
and $form->validate()) {
if ($t12l['allow_set_email_address'] == 'Y'
and $mail->get_address(true)) {
//header('Location: ' . $t12l['server_protocol'] . $t12l['server_name'] . $t12l['script_url']);
echo '<script type="text/javascript">window.location = \'' . $t12l['server_protocol'] . $t12l['server_name'] . $t12l['script_url'] . '\';</script>';
exit;
} else {
$t12l['message'][] = $t12l['text']['txt_could_not_create_email'];
}
}
$out = new t12l_output();
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($out->get_object, true);
$form->accept($renderer);
// Assign array with form data
$out->assign('setemailform', $renderer->toArray());
echo $out->finish_xmlhttprequest($detail_template);
exit;
}
//------------------------------------------------------------------------------
/**
* XMLHTTPRequest
*
*/
function xhr_message()
{
$detail_template = 'emailmessage.tpl.html';
$out = new t12l_output();
$mail = new t12l_email();
$mail_details = array();
if ($mail_id = t12l_gpc_vars('m')) {
$mail_details = $mail->get_mail($mail_id);
}
$out->assign($mail_details);
echo $out->finish_xmlhttprequest($detail_template);
exit;
}
//------------------------------------------------------------------------------
/**
* Gadgets/widgets
*
*/
function gadget($function)
{
if ($function == 'igoogle') {
$this->igoogle_gadget();
}
}
//------------------------------------------------------------------------------
/**
* Google gadget
*
*/
function igoogle_gadget()
{
global $t12l;
$detail_template = 'gadget.xml';
$t12l['alternative_template'] = 'syndication';
$out = new t12l_output($detail_template);
$out->set_global_template($detail_template);
echo $out->finish_xml();
exit;
}
//------------------------------------------------------------------------------
/**
* Template
*
*/
function template()
{
global $t12l;
if ($template = 'gadget') {
$t12l['alternative_template'] = 'gadget';
$this->assign('detail_template', $this->output->select_template($this->detail_template));
}
}
//------------------------------------------------------------------------------
} // End of class
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -