|
From: FlorinCB <ory...@us...> - 2010-01-06 19:40:49
|
Update of /cvsroot/mxbb/core/includes In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16897 Modified Files: mx_functions_emailer.php mx_functions_tools.php Log Message: upd Index: mx_functions_tools.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_tools.php,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** mx_functions_tools.php 2 Dec 2009 03:45:36 -0000 1.59 --- mx_functions_tools.php 6 Jan 2010 19:40:38 -0000 1.60 *************** *** 1894,1898 **** function _insert_pm() { ! global $db, $lang, $user_ip, $board_config, $userdata, $phpbb_root_path, $phpEx, $mx_bbcode; // --- 1894,1898 ---- function _insert_pm() { ! global $db, $lang, $user_ip, $mx_user, $board_config, $userdata, $phpbb_root_path, $phpEx, $mx_bbcode; // *************** *** 1900,1906 **** // $msg_time = time(); ! $attach_sig = $userdata['user_attachsig']; ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? TRUE : 0; // --- 1900,1920 ---- // $msg_time = time(); ! ! switch (PORTAL_BACKEND) ! { ! case 'internal': ! ! case 'phpbb2': ! ! $attach_sig = $userdata['user_attachsig']; ! break; ! ! case 'phpbb3': ! ! $attach_sig = ($board_config['allow_sig'] && $mx_user->data['user_sig']) ? TRUE : 0; ! break; ! } ! ! $is_admin = ($userdata['user_level'] == ADMIN && $userdata['session_logged_in']) ? TRUE : 0; // *************** *** 1952,1967 **** // See if recipient is at their inbox limit // ! $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time ! FROM " . PRIVMSGS_TABLE . " ! WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " ! OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " ! OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ! AND privmsgs_to_userid = " . $to_userdata['user_id']; if ( !($result = $db->sql_query($sql)) ) { ! mx_message_die(GENERAL_MESSAGE, $lang['No_such_user']); ! } ! $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : ''; --- 1966,2001 ---- // See if recipient is at their inbox limit // ! switch (PORTAL_BACKEND) ! { ! case 'internal': ! ! case 'phpbb2': ! ! $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time ! FROM " . PRIVMSGS_TABLE . " ! WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " ! OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " ! OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) ! AND privmsgs_to_userid = " . $to_userdata['user_id']; ! break; + case 'phpbb3': + + $sql = 'SELECT t.msg_id, COUNT(t.msg_id) as inbox_items, SUM(t.pm_unread) as oldest_post_time + FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p + WHERE t.msg_id = p.msg_id + AND t.user_id = ' . $to_userdata['user_id'] . ' + AND t.folder_id <> ' . PRIVMSGS_NO_BOX . ' + ORDER BY p.message_time ASC'; + break; + } + + //$result = $db->sql_query($sql); //To Do if ( !($result = $db->sql_query($sql)) ) { ! mx_message_die( GENERAL_ERROR, $lang['No_such_user'], '', __LINE__, __FILE__, $sql ); ! } ! $db->sql_freeresult($result); ! $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : ''; *************** *** 2002,2076 **** } } ! $sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig) ! VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . str_replace("\'", "''", $privmsg_subject) . "', " . $this->from_id . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $this->html_on, $this->bbcode_on, $this->smilies_on, $attach_sig)"; ! if ( !($result = $db->sql_query($sql_info)) ) ! { ! mx_message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info); ! } ! $privmsg_sent_id = $db->sql_nextid(); ! $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) ! VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')"; ! if ( !$db->sql_query($sql) ) ! { ! mx_message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql); ! } ! // ! // Add to the users new pm counter ! // ! $sql = "UPDATE " . USERS_TABLE . " ! SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . " ! WHERE user_id = " . $to_userdata['user_id']; ! if ( !$status = $db->sql_query($sql) ) ! { ! mx_message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql); ! } ! /* ! if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] ) ! { ! $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])); ! $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx; ! $server_name = trim($board_config['server_name']); ! $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; ! $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/'; ! // ! // Include and initiate emailer ! // ! include($phpbb_root_path . 'includes/emailer.'.$phpEx); ! $emailer = new emailer($board_config['smtp_delivery']); ! $emailer->from($board_config['board_email']); ! $emailer->replyto($board_config['board_email']); ! $emailer->use_template('privmsg_notify', $to_userdata['user_lang']); ! $emailer->email_address($to_userdata['user_email']); ! $emailer->set_subject($lang['Notification_subject']); ! $emailer->assign_vars(array( ! 'USERNAME' => $to_username, ! 'SITENAME' => $board_config['sitename'], ! 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '', ! 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox') ! ); ! $emailer->send(); ! $emailer->reset(); ! } ! */ ! return; ! $msg = $lang['Message_sent'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . mx_append_sid("privmsg.$phpEx?folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . mx_append_sid("index.$phpEx") . '">', '</a>'); ! mx_message_die(GENERAL_MESSAGE, $msg); } --- 2036,2149 ---- } } + + switch (PORTAL_BACKEND) + { + case 'internal': ! case 'phpbb2': ! ! $sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig) ! VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . str_replace("\'", "''", $privmsg_subject) . "', " . $this->from_id . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $this->html_on, $this->bbcode_on, $this->smilies_on, $attach_sig)"; ! if ( !($result = $db->sql_query($sql_info)) ) ! { ! mx_message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info); ! } ! $privmsg_sent_id = $db->sql_nextid(); ! $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) ! VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')"; ! if ( !$db->sql_query($sql) ) ! { ! mx_message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql); ! } ! ! // ! // Add to the users new pm counter ! // ! $sql = "UPDATE " . USERS_TABLE . " ! SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . " ! WHERE user_id = " . $to_userdata['user_id']; ! if ( !$status = $db->sql_query($sql) ) ! { ! mx_message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql); ! } ! ! if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] ) ! { ! $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])); ! $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx; ! $server_name = trim($board_config['server_name']); ! $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; ! $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/'; ! // ! // Include and initiate emailer ! // ! include_once($mx_root_path . 'includes/mx_functions_emailer.'.$phpEx); ! $emailer = new mx_emailer($board_config['smtp_delivery']); ! $emailer->from($board_config['board_email']); ! $emailer->replyto($board_config['board_email']); ! $emailer->use_template('privmsg_notify', $to_userdata['user_lang']); ! $emailer->email_address($to_userdata['user_email']); ! $emailer->set_subject($lang['Notification_subject']); ! $emailer->assign_vars(array( ! 'USERNAME' => $to_username, ! 'SITENAME' => $board_config['sitename'], ! 'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '', ! 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox') ! ); ! $emailer->send(); ! $emailer->reset(); ! } ! //return; ! $msg = $lang['Message_sent'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . mx_append_sid("privmsg.$phpEx?folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . mx_append_sid("index.$phpEx") . '">', '</a>'); ! ! mx_message_die(GENERAL_MESSAGE, $msg); ! ! break; + case 'phpbb3': + + if (!class_exists('parse_message')) + { + require($mx_root_path . 'includes/shared/phpbb3/includes/message_parser.' . $phpEx); + } + + $message_parser = new parse_message($privmsg_message); + + $message_parser->message = $privmsg_message; + $message_parser->parse(true, true, true, false, false, true, true); + + $pm_data = array( + 'from_user_id' => $this->from_id, + 'from_user_ip' => $user->ip, + 'from_username' => $to_userdata['user_id'], + 'enable_sig' => $attach_sig, + 'enable_bbcode' => $this->bbcode_on, + 'enable_smilies' => $this->smilies_on, + 'enable_urls' => $this->html_on, + 'icon_id' => 0, + 'bbcode_bitfield' => $message_parser->bbcode_bitfield, + 'bbcode_uid' => $message_parser->bbcode_uid, + 'message' => $message_parser->message, + 'address_list' => array('u' => array($to_userdata['user_id'] => 'to')), + ); + + $this->submit_pm_phpbb3('post', $privmsg_subject, $pm_data, false); + break; + } } *************** *** 2142,2146 **** // Include and initiate mailer // ! include_once($mx_root_path . 'includes/mx_functions_emailer.'.$phpEx); $emailer = new mx_emailer($board_config['smtp_delivery']); --- 2215,2219 ---- // Include and initiate mailer // ! include_once($mx_root_path . 'includes/mx_functions_emailer.'.$phpEx); $emailer = new mx_emailer($board_config['smtp_delivery']); *************** *** 2378,2381 **** --- 2451,2888 ---- return $user_ids_array; } + + /** + * Submit PM + */ + function submit_pm_phpbb3($mode, $subject, &$data, $put_in_outbox = true) + { + global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path; + + // We do not handle erasing pms here + if ($mode == 'delete') + { + return false; + } + + $current_time = time(); + + // Collect some basic information about which tables and which rows to update/insert + $sql_data = array(); + $root_level = 0; + + // Recipient Information + $recipients = $to = $bcc = array(); + + if ($mode != 'edit') + { + // Build Recipient List + // u|g => array($user_id => 'to'|'bcc') + $_types = array('u', 'g'); + foreach ($_types as $ug_type) + { + if (isset($data['address_list'][$ug_type]) && sizeof($data['address_list'][$ug_type])) + { + foreach ($data['address_list'][$ug_type] as $id => $field) + { + $id = (int) $id; + + // Do not rely on the address list being "valid" + if (!$id || ($ug_type == 'u' && $id == ANONYMOUS)) + { + continue; + } + + $field = ($field == 'to') ? 'to' : 'bcc'; + if ($ug_type == 'u') + { + $recipients[$id] = $field; + } + ${$field}[] = $ug_type . '_' . $id; + } + } + } + + if (isset($data['address_list']['g']) && sizeof($data['address_list']['g'])) + { + // We need to check the PM status of group members (do they want to receive PM's?) + // Only check if not a moderator or admin, since they are allowed to override this user setting + $sql_allow_pm = (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? ' AND u.user_allow_pm = 1' : ''; + + $sql = 'SELECT u.user_type, ug.group_id, ug.user_id + FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug + WHERE ' . $db->sql_in_set('ug.group_id', array_keys($data['address_list']['g'])) . ' + AND ug.user_pending = 0 + AND u.user_id = ug.user_id + AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')' . + $sql_allow_pm; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $field = ($data['address_list']['g'][$row['group_id']] == 'to') ? 'to' : 'bcc'; + $recipients[$row['user_id']] = $field; + } + $db->sql_freeresult($result); + } + + if (!sizeof($recipients)) + { + trigger_error('NO_RECIPIENT'); + } + } + + $db->sql_transaction('begin'); + + $sql = ''; + + switch ($mode) + { + case 'reply': + case 'quote': + $root_level = ($data['reply_from_root_level']) ? $data['reply_from_root_level'] : $data['reply_from_msg_id']; + + // Set message_replied switch for this user + $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' + SET pm_replied = 1 + WHERE user_id = ' . $data['from_user_id'] . ' + AND msg_id = ' . $data['reply_from_msg_id']; + + // no break + + case 'forward': + case 'post': + case 'quotepost': + $sql_data = array( + 'root_level' => $root_level, + 'author_id' => $data['from_user_id'], + 'icon_id' => $data['icon_id'], + 'author_ip' => $data['from_user_ip'], + 'message_time' => $current_time, + 'enable_bbcode' => $data['enable_bbcode'], + 'enable_smilies' => $data['enable_smilies'], + 'enable_magic_url' => $data['enable_urls'], + 'enable_sig' => $data['enable_sig'], + 'message_subject' => $subject, + 'message_text' => $data['message'], + 'message_attachment'=> (!empty($data['attachment_data'])) ? 1 : 0, + 'bbcode_bitfield' => $data['bbcode_bitfield'], + 'bbcode_uid' => $data['bbcode_uid'], + 'to_address' => implode(':', $to), + 'bcc_address' => implode(':', $bcc) + ); + break; + + case 'edit': + $sql_data = array( + 'icon_id' => $data['icon_id'], + 'message_edit_time' => $current_time, + 'enable_bbcode' => $data['enable_bbcode'], + 'enable_smilies' => $data['enable_smilies'], + 'enable_magic_url' => $data['enable_urls'], + 'enable_sig' => $data['enable_sig'], + 'message_subject' => $subject, + 'message_text' => $data['message'], + 'message_attachment'=> (!empty($data['attachment_data'])) ? 1 : 0, + 'bbcode_bitfield' => $data['bbcode_bitfield'], + 'bbcode_uid' => $data['bbcode_uid'] + ); + break; + } + + if (sizeof($sql_data)) + { + $query = ''; + + if ($mode == 'post' || $mode == 'reply' || $mode == 'quote' || $mode == 'quotepost' || $mode == 'forward') + { + $db->sql_query('INSERT INTO ' . PRIVMSGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data)); + $data['msg_id'] = $db->sql_nextid(); + } + else if ($mode == 'edit') + { + $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' + SET message_edit_count = message_edit_count + 1, ' . $db->sql_build_array('UPDATE', $sql_data) . ' + WHERE msg_id = ' . $data['msg_id']; + $db->sql_query($sql); + } + } + + if ($mode != 'edit') + { + if ($sql) + { + $db->sql_query($sql); + } + unset($sql); + + $sql_ary = array(); + foreach ($recipients as $user_id => $type) + { + $sql_ary[] = array( + 'msg_id' => (int) $data['msg_id'], + 'user_id' => (int) $user_id, + 'author_id' => (int) $data['from_user_id'], + 'folder_id' => PRIVMSGS_NO_BOX, + 'pm_new' => 1, + 'pm_unread' => 1, + 'pm_forwarded' => ($mode == 'forward') ? 1 : 0 + ); + } + + $db->sql_multi_insert(PRIVMSGS_TO_TABLE, $sql_ary); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_new_privmsg = user_new_privmsg + 1, user_unread_privmsg = user_unread_privmsg + 1, user_last_privmsg = ' . time() . ' + WHERE ' . $db->sql_in_set('user_id', array_keys($recipients)); + $db->sql_query($sql); + + // Put PM into outbox + if ($put_in_outbox) + { + $db->sql_query('INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'msg_id' => (int) $data['msg_id'], + 'user_id' => (int) $data['from_user_id'], + 'author_id' => (int) $data['from_user_id'], + 'folder_id' => PRIVMSGS_OUTBOX, + 'pm_new' => 0, + 'pm_unread' => 0, + 'pm_forwarded' => ($mode == 'forward') ? 1 : 0)) + ); + } + } + + // Set user last post time + if ($mode == 'reply' || $mode == 'quote' || $mode == 'quotepost' || $mode == 'forward' || $mode == 'post') + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lastpost_time = $current_time + WHERE user_id = " . $data['from_user_id']; + $db->sql_query($sql); + } + + // Submit Attachments + if (!empty($data['attachment_data']) && $data['msg_id'] && in_array($mode, array('post', 'reply', 'quote', 'quotepost', 'edit', 'forward'))) + { + $space_taken = $files_added = 0; + $orphan_rows = array(); + + foreach ($data['attachment_data'] as $pos => $attach_row) + { + $orphan_rows[(int) $attach_row['attach_id']] = array(); + } + + if (sizeof($orphan_rows)) + { + $sql = 'SELECT attach_id, filesize, physical_filename + FROM ' . ATTACHMENTS_TABLE . ' + WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . ' + AND in_message = 1 + AND is_orphan = 1 + AND poster_id = ' . $user->data['user_id']; + $result = $db->sql_query($sql); + + $orphan_rows = array(); + while ($row = $db->sql_fetchrow($result)) + { + $orphan_rows[$row['attach_id']] = $row; + } + $db->sql_freeresult($result); + } + + foreach ($data['attachment_data'] as $pos => $attach_row) + { + if ($attach_row['is_orphan'] && !isset($orphan_rows[$attach_row['attach_id']])) + { + continue; + } + + if (!$attach_row['is_orphan']) + { + // update entry in db if attachment already stored in db and filespace + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " + SET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "' + WHERE attach_id = " . (int) $attach_row['attach_id'] . ' + AND is_orphan = 0'; + $db->sql_query($sql); + } + else + { + // insert attachment into db + if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename']))) + { + continue; + } + + $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize']; + $files_added++; + + $attach_sql = array( + 'post_msg_id' => $data['msg_id'], + 'topic_id' => 0, + 'is_orphan' => 0, + 'poster_id' => $data['from_user_id'], + 'attach_comment' => $attach_row['attach_comment'], + ); + + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' + WHERE attach_id = ' . $attach_row['attach_id'] . ' + AND is_orphan = 1 + AND poster_id = ' . $user->data['user_id']; + $db->sql_query($sql); + } + } + + if ($space_taken && $files_added) + { + set_config_count('upload_dir_size', $space_taken, true); + set_config_count('num_files', $files_added, true); + } + } + + // Delete draft if post was loaded... + $draft_id = phpBB3::request_var('draft_loaded', 0); + if ($draft_id) + { + $sql = 'DELETE FROM ' . DRAFTS_TABLE . " + WHERE draft_id = $draft_id + AND user_id = " . $data['from_user_id']; + $db->sql_query($sql); + } + + $db->sql_transaction('commit'); + + // Send Notifications + if ($mode != 'edit') + { + $this->pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message']); + } + + return $data['msg_id']; + } + + /** + * PM Notification + */ + function pm_notification($mode, $author, $recipients, $subject, $message) + { + global $db, $lang, $mx_user, $board_config, $phpbb_root_path, $mx_root_path, $phpEx, $phpbb_auth, $page_id; + + $subject = mx_censor_text($subject); + + unset($recipients[ANONYMOUS], $recipients[$mx_user->data['user_id']]); + + if (!sizeof($recipients)) + { + return; + } + + // Get banned User ID's + $sql = 'SELECT ban_userid + FROM ' . BANLIST_TABLE . ' + WHERE ' . $db->sql_in_set('ban_userid', array_map('intval', array_keys($recipients))) . ' + AND ban_exclude = 0'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + unset($recipients[$row['ban_userid']]); + } + $db->sql_freeresult($result); + + if (!sizeof($recipients)) + { + return; + } + + $sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($recipients))); + $result = $db->sql_query($sql); + + $msg_list_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + if ($row['user_notify_pm'] == 1 && trim($row['user_email'])) + { + $msg_list_ary[] = array( + 'method' => $row['user_notify_type'], + 'email' => $row['user_email'], + 'jabber' => $row['user_jabber'], + 'name' => $row['username'], + 'lang' => $row['user_lang'] + ); + } + } + $db->sql_freeresult($result); + + if (!sizeof($msg_list_ary)) + { + return; + } + + // + // Include and initiate mailer + // + include_once($mx_root_path . 'includes/mx_functions_emailer.'.$phpEx); + + // + // Let's do some checking to make sure that mass mail functions + // are working in win32 versions of php. + // + if ( preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery']) + { + $ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var'; + + // We are running on windows, force delivery to use our smtp functions + // since php's are broken by default + $board_config['smtp_delivery'] = 1; + $board_config['smtp_host'] = @$ini_val('SMTP'); + } + + $emailer = new mx_emailer($board_config['smtp_delivery']); + + foreach ($msg_list_ary as $pos => $addr) + { + //$emailer->to($addr['email'], $addr['name']); + //$emailer->im($addr['jabber'], $addr['name']); + + $emailer_from = $board_config['board_email']; + $emailer_to = $addr['email']; + $emailer_skip = ($emailer_to == $emailer_from) ? $emailer_to : false; + + // + // Mail + // + $emailer->set_mail_html(true); + $emailer->use_template('privmsg_notify'); + $emailer->email_skip($emailer_skip); + $emailer->email_address($board_config['board_email']); + $emailer->set_subject(htmlspecialchars_decode($subject)); + $emailer->extra_headers($email_antetes); + + $emailer->assign_vars(array( + 'SITENAME' => $board_config['sitename'], + 'BOARD_EMAIL' => $board_config['board_email'], + 'SUBJECT' => htmlspecialchars_decode($subject), + 'MESSAGE' => $message, + 'AUTHOR_NAME' => htmlspecialchars_decode($author), + 'USERNAME' => htmlspecialchars_decode($addr['name']), + + 'U_INBOX' => PHPBB_URL . "/ucp.$phpEx?i=pm&folder=inbox") + ); + + $emailer->send(); + $emailer->reset(); + } + + unset($msg_list_ary); + //$emailer->save_queue(); + unset($emailer); + + $msg = $lang['Message_sent'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . mx_append_sid(PHPBB_URL . "/ucp.$phpEx?i=pm&folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . mx_append_sid(PORTAL_URL . 'index.' . $phpEx . '?page=' . $page_id) . '">', '</a>'); + + mx_message_die(GENERAL_MESSAGE, $msg); + + } } Index: mx_functions_emailer.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_emailer.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mx_functions_emailer.php 7 Oct 2008 00:12:00 -0000 1.2 --- mx_functions_emailer.php 6 Jan 2010 19:40:37 -0000 1.3 *************** *** 19,22 **** --- 19,28 ---- * @package MXP3 */ + + // + // The emailer class has support for attaching files, that isn't implemented + // in the 2.0 release but we can probable find some way of using it in a future + // release + // class mx_emailer { *************** *** 74,77 **** --- 80,89 ---- $this->subject = trim(preg_replace('#[\n\r]+#s', '', $subject)); } + + // set up skip mail + function email_skip($email_skip = false) + { + $this->email_skip = $email_skip; + } // set up extra mail headers *************** *** 96,100 **** function use_template($template_file, $template_lang = '') { ! global $board_config, $phpbb_root_path, $mx_root_path, $mx_root_path; if (trim($template_file) == '') --- 108,112 ---- function use_template($template_file, $template_lang = '') { ! global $board_config, $phpbb_root_path, $module_root_path, $mx_root_path; if (trim($template_file) == '') *************** *** 127,136 **** } ! $this->tpl_msg[$template_lang . $template_file] = fread($fd, filesize($tpl_file)); fclose($fd); } $this->msg = $this->tpl_msg[$template_lang . $template_file]; ! return true; } --- 139,148 ---- } ! $this->tpl_msg[$template_lang . $template_file] = @fread($fd, filesize($tpl_file)); fclose($fd); } $this->msg = $this->tpl_msg[$template_lang . $template_file]; ! return true; } *************** *** 197,212 **** $to = $this->addresses['to']; - $cc = (count($this->addresses['cc'])) ? implode(', ', $this->addresses['cc']) : ''; $bcc = (count($this->addresses['bcc'])) ? implode(', ', $this->addresses['bcc']) : ''; // Build header if ($this->use_html) { ! $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/html; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By Mx-Publisher\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); } else { ! $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By Mx-Publisher\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); } --- 209,224 ---- $to = $this->addresses['to']; $cc = (count($this->addresses['cc'])) ? implode(', ', $this->addresses['cc']) : ''; $bcc = (count($this->addresses['bcc'])) ? implode(', ', $this->addresses['bcc']) : ''; + $skip = ($this->email_skip == $this->addresses['to']) ? true : false; // Build header if ($this->use_html) { ! $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\n" . "Message-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/html; charset=" . $this->encoding . "\n" . "Content-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\n" . "X-Priority: 3\n" . "X-MSMail-Priority: Normal\n" . "X-Mailer: PHP\nX-MimeOLE: Produced By MXP\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); } else { ! $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\n" ."Message-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\n" . "Content-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\n". "X-Priority: 3\n" . "X-MSMail-Priority: Normal\n" . "X-Mailer: PHP\nX-MimeOLE: Produced By Mx-Publisher\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); } *************** *** 214,223 **** if ( $this->use_smtp ) { ! if (!defined('SMTP_INCLUDED')) ! { ! include($mx_root_path . 'includes/mx_functions_smtp.' . $phpEx); } ! $result = smtpmail($to, $this->subject, $this->msg, $this->extra_headers); } else --- 226,235 ---- if ( $this->use_smtp ) { ! if ( !defined('SMTP_INCLUDED') ) ! { ! include($mx_root_path . 'includes/contact_smtp.' . $phpEx); } ! $result = ($skip) ? false : smtpmail($to, $this->subject, $this->msg, $this->extra_headers); } else *************** *** 226,230 **** $to = ($to == '') ? (($board_config['sendmail_fix']) ? ' ' : 'Undisclosed-recipients:;') : $to; ! $result = mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); if (!$result && !$board_config['sendmail_fix'] && $empty_to_header) --- 238,242 ---- $to = ($to == '') ? (($board_config['sendmail_fix']) ? ' ' : 'Undisclosed-recipients:;') : $to; ! $result = ($skip) ? false : mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); if (!$result && !$board_config['sendmail_fix'] && $empty_to_header) *************** *** 256,268 **** $board_config['sendmail_fix'] = 1; ! $result = mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); } } // Did it work? ! if (!$result) { mx_message_die(GENERAL_ERROR, 'Failed sending email :: ' . (($this->use_smtp) ? 'SMTP' : 'PHP') . ' :: ' . $result, '', __LINE__, __FILE__); } return true; --- 268,285 ---- $board_config['sendmail_fix'] = 1; ! $result = ($skip) ? false : mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); } } // Did it work? ! if ((!$result) && (!$skip)) { mx_message_die(GENERAL_ERROR, 'Failed sending email :: ' . (($this->use_smtp) ? 'SMTP' : 'PHP') . ' :: ' . $result, '', __LINE__, __FILE__); } + + if (!$skip) + { + //print('Failed sending email :: Use another adress for sender.', __LINE__, __FILE__); + } return true; |