|
From: Jon O. <jon...@us...> - 2006-07-05 22:51:18
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7915/includes Modified Files: mx_functions_tools.php Log Message: related to kb/pafiledb Index: mx_functions_tools.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions_tools.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** mx_functions_tools.php 26 Jun 2006 21:32:22 -0000 1.4 --- mx_functions_tools.php 5 Jul 2006 22:51:13 -0000 1.5 *************** *** 1200,1202 **** --- 1200,2113 ---- } } + + /** + * mx_text_formatting + * + * Description + * + * @access public + * @author Jon Ohlsson + * + */ + class mx_text_formatting + { + /** + * Enter description here... + * + * @param unknown_type $mytext + * @param unknown_type $do_url + * @param unknown_type $do_images + * @param unknown_type $do_wordwrap + * @return unknown + */ + function decode( $mytext = '', $do_url = true, $do_images = '300', $do_wordwrap = true ) + { + global $board_config; + + if ( $do_url ) + { + $mytext = $this->_magic_url( $mytext ); + } + + if ( $do_images > 0 ) + { + $mytext = $this->_magic_img( $mytext, $do_images ); + } + + if ( $do_wordwrap ) + { + $mytext = $this->_word_wrap_pass( $mytext ); + } + + return $mytext; + } + + /** + * Enter description here... + * + * Replace magic urls of form http://xxx.xxx., www.xxx. and xx...@xx.... + * Cuts down displayed size of link if over 50 chars, turns absolute links + * into relative versions when the server/script path matches the link + * + * @access private + * @param unknown_type $url + * @return unknown + */ + function _magic_url( $url ) + { + global $board_config; + // $url = stripslashes($url); + if ( $url ) + { + $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; + $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim( $board_config['server_port'] ) . '/' : '/'; + + $match = array(); + $replace = array(); + // relative urls for this board + $match[] = '#(^|[\n ])' . $server_protocol . trim( $board_config['server_name'] ) . $server_port . preg_replace( '/^\/?(.*?)(\/)?$/', '$1', trim( $board_config['script_path'] ) ) . '/([^ \t\n\r <"\']+)#i'; + $replace[] = '<a href="$1" target="_blank">$1</a>'; + // matches a xxxx://aaaaa.bbb.cccc. ... + $match[] = '#(^|[\n ])([\w]+?://.*?[^ \t\n\r<"]*)#ie'; + $replace[] = "'\$1<a href=\"\$2\" target=\"_blank\">' . ((strlen('\$2') > 25) ? substr(str_replace('http://','','\$2'), 0, 17) . '...' : '\$2') . '</a>'"; + // $replace[] = "'\$1<a href=\"\$2\" target=\"_blank\">' . ((strlen('\$2') > 25) ? substr(str_replace('http://','','\$2'), 0, 12) . ' ... ' . substr('\$2', -3) : '\$2') . '</a>'"; + // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing + $match[] = '#(^|[\n ])(www\.[\w\-]+\.[\w\-.\~]+(?:/[^ \t\n\r<"]*)?)#ie'; + $replace[] = "'\$1<a href=\"http://\$2\" target=\"_blank\">' . ((strlen('\$2') > 25) ? substr(str_replace(' ', '%20', str_replace('http://','', '\$2')), 0, 17) . '...' : '\$2') . '</a>'"; + // $replace[] = "'\$1<a href=\"http://\$2\" target=\"_blank\">' . ((strlen('\$2') > 25) ? substr(str_replace(' ', '%20', str_replace('http://','', '\$2')), 0, 12) . ' ... ' . substr('\$2', -3) : '\$2') . '</a>'"; + // matches an email@domain type address at the start of a line, or after a space. + $match[] = '#(^|[\n ])([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie'; + $replace[] = "'\$1<a href=\"mailto:\$2\">' . ((strlen('\$2') > 25) ? substr('\$2', 0, 15) . ' ... ' . substr('\$2', -5) : '\$2') . '</a>'"; + + $url = preg_replace( $match, $replace, $url ); + // Also fix already tagged links + $url = preg_replace( "/<a href=(.*?)>(.*?)<\/a>/ie", "(strlen(\"\\2\") > 25 && !eregi(\"<\", \"\\2\") ) ? '<a href='.stripslashes(\"\\1\").'>'.substr(str_replace(\"http://\",\"\",\"\\2\"), 0, 17) . '...</a>' : '<a href='.stripslashes(\"\\1\").'>'.\"\\2\".'</a>'", $url ); + // $url = preg_replace("/<a href=(.*?)>(.*?)<\/a>/ie", "(strlen(\"\\2\") > 25 && !eregi(\"<\", \"\\2\") ) ? '<a href='.stripslashes(\"\\1\").'>'.substr(str_replace(\"http://\",\"\",\"\\2\"), 0, 12) . ' ... ' . substr(\"\\2\", -3).'</a>' : '<a href='.stripslashes(\"\\1\").'>'.\"\\2\".'</a>'", $url); + return $url; + } + return $url; + } + + /** + * Enter description here... + * + * Validates the img for block_size and resizes when needed + * run within a div tag to ensure the table layout is not broken + * + * @access private + * @param unknown_type $img + * @param unknown_type $do_images + * @return unknown + */ + function _magic_img( $img, $do_images = '300' ) + { + global $board_config, $block_size; + // $img = stripslashes($img); + $image_size = $do_images; + if ( $img ) + { + // Also fix already tagged links + // $img = preg_replace("/<img src=(.*?)(|border(.*?)|alt(.*?))>/ie", "'<br /><br /><center><img src='.stripslashes(\"\\1\").' width=\"'.makeImgWidth(trim(stripslashes(\"\\1\"))).'\" ></center><br />'", $img); + $img = preg_replace( "/<img src=(.*?)>/ie", "(substr_count(\"\\1\", \"smiles\") > 0 ) ? '<img src='.stripslashes(\"\\1\").'>' : + + '<div style=\" overflow: hidden; margin: 0px; padding: 0px; float: left; \"> + <img class=\"noenlarge\" src='.stripslashes(\"\\1\").' border=\"0\" OnLoad=\"if(this.width > $image_size) { this.width = $image_size }\" onclick = \"full_img( this.src )\" alt=\" Click to enlarge \"> + </div>'", $img ); + return $img; + } + return $img; + } + + /** + * Enter description here... + * + * Force Word Wrapping (by TerraFrost) + * + * @access private + * @param unknown_type $message + * @return unknown + */ + function _word_wrap_pass( $message ) + { + $tempText = ""; + $finalText = ""; + $curCount = $tempCount = 0; + $longestAmp = 9; + $inTag = false; + $ampText = ""; + + for ( $num = 0;$num < strlen( $message );$num++ ) + { + $curChar = $message{$num}; + + if ( $curChar == "<" ) + { + for ( $snum = 0;$snum < strlen( $ampText );$snum++ ) + $this->_addWrap( $ampText{$snum}, $ampText{$snum+1}, $finalText, $tempText, $curCount, $tempCount ); + $ampText = ""; + $tempText .= "<"; + $inTag = true; + } + elseif ( $inTag && $curChar == ">" ) + { + $tempText .= ">"; + $inTag = false; + } + elseif ( $inTag ) + { + $tempText .= $curChar; + } + elseif ( $curChar == "&" ) + { + for ( $snum = 0;$snum < strlen( $ampText );$snum++ ) + $this->_addWrap( $ampText{$snum}, $ampText{$snum+1}, $finalText, $tempText, $curCount, $tempCount ); + $ampText = "&"; + } + elseif ( strlen( $ampText ) < $longestAmp && $curChar == ";" && + ( strlen( html_entity_decode( "$ampText;" ) ) == 1 || preg_match( '/^&#[0-9][0-9]*$/', $ampText ) ) ) + { + $this->_addWrap( "$ampText;", $message{$num+1}, $finalText, $tempText, $curCount, $tempCount ); + $ampText = ""; + } + elseif ( strlen( $ampText ) >= $longestAmp || $curChar == ";" ) + { + for ( $snum = 0;$snum < strlen( $ampText );$snum++ ) + $this->_addWrap( $ampText{$snum}, $ampText{$snum+1}, $finalText, $tempText, $curCount, $tempCount ); + $this->_addWrap( $curChar, $message{$num+1}, $finalText, $tempText, $curCount, $tempCount ); + $ampText = ""; + } + elseif ( strlen( $ampText ) != 0 && strlen( $ampText ) < $longestAmp ) + { + $ampText .= $curChar; + } + else + { + $this->_addWrap( $curChar, $message{$num+1}, $finalText, $tempText, $curCount, $tempCount ); + } + } + + return $finalText . $tempText; + } + + /** + * Enter description here... + * + * @param unknown_type $curChar + * @param unknown_type $nextChar + * @param unknown_type $finalText + * @param unknown_type $tempText + * @param unknown_type $curCount + * @param unknown_type $tempCount + */ + function _addWrap( $curChar, $nextChar, &$finalText, &$tempText, &$curCount, &$tempCount ) + { + $softHyph = "­"; + // $softHyph = " "; + $maxChars = 10; + $wrapProhibitedChars = "([{!;,:?}])"; + + if ( $curChar == " " || $curChar == "\n" ) + { + $finalText .= $tempText . $curChar; + $tempText = ""; + $curCount = 0; + $curChar = ""; + }elseif ( $curCount >= $maxChars ) + { + $finalText .= $tempText . $softHyph; + $tempText = ""; + $curCount = 1; + } + else + { + $tempText .= $curChar; + $curCount++; + } + // the following code takes care of (unicode) characters prohibiting non-mandatory breaks directly before them. + // $curChar isn't a " " or "\n" + if ( $tempText != "" && $curChar != "" ) + $tempCount++; + // $curChar is " " or "\n", but $nextChar prohibits wrapping. + elseif ( ( $curCount == 1 && strstr( $wrapProhibitedChars, $curChar ) !== false ) || + ( $curCount == 0 && $nextChar != "" && $nextChar != " " && $nextChar != "\n" && strstr( $wrapProhibitedChars, $nextChar ) !== false ) ) + $tempCount++; + // $curChar and $nextChar aren't both either " " or "\n" + elseif ( !( $curCount == 0 && ( $nextChar == " " || $nextChar == "\n" ) ) ) + $tempCount = 0; + + if ( $tempCount >= $maxChars && $tempText == "" ) + { + $finalText .= " "; + $tempCount = 1; + $curCount = 2; + } + + if ( $tempText == "" && $curCount > 0 ) + $finalText .= $curChar; + } + + /** + * Enter description here... + * + * @param unknown_type $comments_text + * @param unknown_type $allow_images + * @param unknown_type $no_image_message + * @param unknown_type $allow_links + * @param unknown_type $no_link_message + * @return unknown + */ + function remove_images_links( $comments_text, $allow_images = false, $no_image_message = '[No image please]', $allow_links = false, $no_link_message = '[No links please]') + { + if ( $comments_text != '' ) + { + if ( !$allow_images ) + { + if ( preg_match( '/(<img src=)(.+?)(\>)/i', $comments_text ) ) + { + $comments_text = preg_replace( '/(<img src=)(.+?)(\>)/i', $no_image_message, $comments_text ); + } + + if ( preg_match( '/(\[img\])([^\[]*)(\[\/img\])/i', $comments_text ) ) + { + $comments_text = preg_replace( '/(\[img\])([^\[]*)(\[\/img\])/i', $no_image_message, $comments_text ); + } + } + + if ( !$allow_links ) + { + if ( preg_match( '/(\[url=(.*?)\])([^\[]*)(\[\/url\])/i', $comments_text ) ) + { + $comments_text = preg_replace( '/(\[url=(.*?)\])([^\[]*)(\[\/url\])/i', $no_link_message, $comments_text ); + } + + if ( preg_match( '/(\[url\])([^\[]*)(\[\/url\])/i', $comments_text ) ) + { + $comments_text = preg_replace( '/(\[url\])([^\[]*)(\[\/url\])/i', $no_link_message, $comments_text ); + } + + if ( preg_match( "#([\n ])http://www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", $comments_text ) ) + { + $comments_text = preg_replace( "#([\n ])http://www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", $no_link_message, $comments_text ); + } + + if ( preg_match( "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", $comments_text ) ) + { + $comments_text = preg_replace( "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", $no_link_message, $comments_text ); + } + } + } + return $comments_text; + } + + /** + * Enter description here... + * + * @param unknown_type $mytext + * @param unknown_type $length + * @param unknown_type $add_dots + * @return unknown + */ + function truncate_text( $mytext, $length = 200, $add_dots = true ) + { + $do_trunc = false; + if ( strlen( $mytext ) > $length ) + { + $do_trunc = true; + $mytext = substr( $mytext, 0, $length ); + $mytext = str_replace('<br />', '<br/>', $mytext); + $mytext = substr( $mytext, 0, strrpos( $mytext, ' ' ) ); + $mytext = str_replace('<br/>', '<br />', $mytext); + + if ( $add_dots ) + { + $mytext .= '...'; + } + } + //$return_data = array($mytext, $do_trunc); + return $mytext; + } + } + + define('MX_MAIL_MODE' , 1); + define('MX_PM_MODE' , 2); + define('MX_POST_MODE' , 2); + + define('MX_NEW_NOTIFICATION' , 10); + define('MX_EDITED_NOTIFICATION' , 11); + define('MX_APPROVED_NOTIFICATION' , 12); + define('MX_UNAPPROVED_NOTIFICATION' , 13); + define('MX_DELETED_NOTIFICATION' , 14); + + // + // Includes + // + include_once( $phpbb_root_path . 'includes/functions_post.' . $phpEx ); + + /** + * mx_notification. + * + * This class will handle most PM/MAIL tasks. + * + * // MODE: MX_PM_MODE/MX_MAIL_MODE, $id: get all file/article data for this id + * $mx_notification->init($mode, $id); // MODE: MX_PM_MODE/MX_MAIL_MODE + * + * // MODE: MX_PM_MODE/MX_MAIL_MODE, ACTION: MX_NEW_NOTIFICATION/MX_EDITED_NOTIFICATION/MX_APPROVED_NOTIFICATION/MX_UNAPPROVED_NOTIFICATION + * $mx_notification->notify( $mode = MX_PM_MODE, $action = MX_NEW_NOTIFICATION, $to_id, $from_id, $subject, $message, $html_on, $bbcode_on, $smilies_on ) + * + * @access public + * @author Jon Ohlsson + */ + class mx_notification + { + // + // PM/EMAIL Notification + // + var $subject = ''; + var $message = ''; + + var $to_id = ''; // to one user + var $to_ids = ''; // to many users + var $from_id = ''; + var $html_on = 0; + var $bbcode_on = 1; + var $smilies_on = 1; + + var $first_commnent = ''; // only used for phpBB comments + var $next_commnent = ''; + + // + // Autogenerated comments [Optional] + // + var $data = array(); // all item data in one array (only needed when using automessages) [Optional] + var $langs = array(); // generic lang keys (only needed when using automessages) [Optional] + var $temp_url = ''; // (only needed when using automessages) [Optional] + + var $auto_message = ''; // for auto generated messages + var $auto_message_update = ''; // for auto generated messages + + + + /** + * this will be replaced by the loaded module. + * + * If you are using automessages, this init must populate $lang, $data and $url_rewrite. + * If not, you need no init and may use the notify method as is. + * + * @param unknown_type $module_id + * @return unknown + */ + function init( $item_id = false ) + { + return false; + } + + /** + * Notification - email/PM. + * + * Note: This method may be used by itself (if subject and message is passed) + * to_id: to single user ($to_id > 0), to ALL admins ($to_id == 0) or to all members in group with group_id = -$to_id ($to_id < 0) + * + * @param unknown_type $mode + * @param unknown_type $action + * @param unknown_type $to_id + * @param unknown_type $from_id + * @param unknown_type $subject + * @param unknown_type $message + * @param unknown_type $html_on + * @param unknown_type $bbcode_on + * @param unknown_type $smilies_on + */ + function notify( $mode = MX_PM_MODE, $action = MX_NEW_NOTIFICATION, $to_id = 0, $from_id = '', $subject = '', $message = '', $html_on = '', $bbcode_on = '', $smilies_on = '' ) + { + global $lang, $board_config, $db, $phpbb_root_path, $mx_root_path, $phpEx, $userdata; + + // + // Precheck + // + if (intval($to_id) > 0) + { + $this->to_ids = array('single' => intval($to_id)); // Notify specific user + } + else if(intval($to_id) == 0) + { + $this->to_ids = $this->_get_admins(); // Notify all admins (DEFAULT) + } + else if(intval($to_id) < 0) + { + $group_id = intval( -$to_id); + $this->to_ids = $this->_get_users_in_group( $group_id ); // Notify all in group + } + else + { + mx_message_die(GENERAL_ERROR, 'Bad notify pars - no to_id'); + } + + $this->from_id = empty( $from_id ) ? $userdata['user_id'] : $from_id; + + // + // Toggles + // + $this->html_on = !empty($html_on) ? $html_on : $this->html_on; + $this->bbcode_on = !empty($bbcode_on) ? $bbcode_on : $this->bbcode_on; + $this->smilies_on = !empty($smilies_on) ? $smilies_on : $this->smilies_on; + + $this->subject = $subject; + $this->message = $message; + + // + // Compose Subject + // + if (empty($this->subject) || empty($this->message)) + { + if ( count($this->data) > 0 && count($this->langs) > 0 ) + { + $this->_compose_auto_note($action); + } + else + { + mx_message_die(GENERAL_ERROR, 'Error: no subject or no message'); + } + } + + // + // Now send PM/MAIL + // + foreach ( $this->to_ids as $key => $id ) + { + $this->to_id = $id; + + // + // Why send PM/MAIL to yourself??? + // + if ( $this->to_id == $this->from_id ) + { + //continue; + } + + switch ( $mode ) + { + case MX_MAIL_MODE: + $this->_mailer(); + break; + + case MX_PM_MODE: + $this->_insert_pm(); + break; + + default: + mx_message_die(GENERAL_ERROR, 'Bad notify type'); + } + } + } + + /** + * Notification - PM + * + * based on wgErics good old insert_pm function + * + */ + function _insert_pm() + { + global $db, $lang, $user_ip, $board_config, $userdata, $phpbb_root_path, $phpEx; + + // + // get varibles ready + // + $msg_time = time(); + $attach_sig = $userdata['user_attachsig']; + + // + //get 'to user's info + // + $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active + FROM " . USERS_TABLE . " + WHERE user_id = '" . $this->to_id . "' + AND user_id <> " . ANONYMOUS; + + if ( !($result = $db->sql_query($sql)) ) + { + $error = TRUE; + $error_msg = $lang['No_such_user']; + } + + $to_userdata = $db->sql_fetchrow($result); + $privmsg_subject = trim(strip_tags($this->subject)); + + if ( empty($privmsg_subject) ) + { + $error = TRUE; + $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject']; + } + + if ( !empty($this->message) ) + { + if ( !$error ) + { + if ( $this->bbcode_on ) + { + $bbcode_uid = make_bbcode_uid(); + } + + $privmsg_message = prepare_message(addslashes($this->message), $this->html_on, $this->bbcode_on, $this->smilies_on, $bbcode_uid); + $privmsg_message = str_replace('\\\n', '\n', $privmsg_message); + } + } + else + { + $error = TRUE; + $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message']; + } + + // + // 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' : ''; + + if ( $inbox_info = $db->sql_fetchrow($result) ) + { + if ( $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'] ) + { + $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . " + WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . " + OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " + OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " ) + AND privmsgs_date = " . $inbox_info['oldest_post_time'] . " + AND privmsgs_to_userid = " . $to_userdata['user_id']; + + if ( !$result = $db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (inbox)', '', __LINE__, __FILE__, $sql); + } + + $old_privmsgs_id = $db->sql_fetchrow($result); + $old_privmsgs_id = $old_privmsgs_id['privmsgs_id']; + + $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . " + WHERE privmsgs_id = $old_privmsgs_id"; + + if ( !$db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (inbox)'.$sql, '', __LINE__, __FILE__, $sql); + } + + $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . " + WHERE privmsgs_text_id = $old_privmsgs_id"; + + if ( !$db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (inbox)', '', __LINE__, __FILE__, $sql); + } + } + } + + $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="' . append_sid("privmsg.$phpEx?folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>'); + + mx_message_die(GENERAL_MESSAGE, $msg); + + } + + /** + * Notification - email + * + */ + function _mailer() + { + global $db, $lang, $user_ip, $board_config, $userdata, $phpbb_root_path, $phpEx; + + // + //get varibles ready + // + $msg_time = time(); + $attach_sig = $userdata['user_attachsig']; + + // + //get to users info + // + $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active + FROM " . USERS_TABLE . " + WHERE user_id = '".$this->to_id."' + AND user_id <> " . ANONYMOUS; + + if ( !($result = $db->sql_query($sql)) ) + { + $error = TRUE; + $error_msg = $lang['No_such_user']; + } + + $to_userdata = $db->sql_fetchrow($result); + + $mail_subject = trim(strip_tags($this->subject)); + + if ( empty($mail_subject) ) + { + $error = TRUE; + $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject']; + } + + if ( !empty($this->message) ) + { + if ( !$error ) + { + if ( $this->bbcode_on ) + { + $bbcode_uid = make_bbcode_uid(); + } + + $mail_message = prepare_message($this->message, $this->html_on, $this->bbcode_on, $this->smilies_on, $bbcode_uid); + $mail_message = str_replace('\\\n', '\n', $mail_message); + + } + } + else + { + $error = TRUE; + $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message']; + } + + $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 mailer + // + include($phpbb_root_path . 'includes/emailer.'.$phpEx); + $emailer = new emailer($board_config['smtp_delivery']); + + // + // Mail + // + $emailer->from( $board_config['board_email'] ); + $emailer->replyto( $board_config['board_email'] ); + + $emailer->email_address($to_userdata['user_email'] ); + $emailer->set_subject( $mail_subject ); + $emailer->msg = $mail_message; + + $emailer->send(); + $emailer->reset(); + } + + /** + * Compose auto note + * + * @access private + * @param unknown_type $action + */ + function _compose_auto_note($action = '') + { + global $lang, $phpEx; + + // + // Compose phpBB post header + // + $this->temp_url = PORTAL_URL . this_kb_mxurl("mode=" . "article&k=" . $this->data['item_id'], false, true); + + $this->auto_message = "[b]" . $this->langs['item_title'] . ":[/b] " . $this->data['item_title'] . "\n"; + $this->auto_message .= "[b]" . $this->langs['author'] . ":[/b] " . $this->data['item_author'] . "\n"; + $this->auto_message .= "[b]" . $this->langs['item_description'] . ":[/b] [i]" . $this->data['item_desc'] . "[/i]\n\n"; + + if ($action != MX_DELETED_NOTIFICATION) + { + $this->auto_message .= "\n\n[b][url=" . $this->temp_url . "]" . $this->langs['read_full_item'] . "[/url][/b]"; + } + + // + // Update message + // + $this->auto_message_update = "[i]" . $this->langs['edited_item_info'] . $this->data['item_editor'] . "[/i]" . "\n\n"; + + // + // Auto generated subject and message + // + switch ( $action ) + { + case MX_NEW_NOTIFICATION: + $this->subject = $this->langs['module_title'] . ' - ' . $this->langs['notify_subject_new']; + $this->message = $this->langs['notify_new_body'] . "\n\n" . $this->auto_message; + break; + + case MX_EDITED_NOTIFICATION: + $this->subject = $this->langs['module_title'] . ' - ' . $this->langs['notify_subject_edited']; + $this->message = $this->langs['notify_edited_body'] . "\n\n" . $this->auto_message_update . $this->auto_message; + break; + + case MX_APPROVED_NOTIFICATION: + $this->subject = $this->langs['module_title'] . ' - ' . $this->langs['notify_subject_approved']; + $this->message = $this->langs['notify_approved_body'] . "\n\n". $this->auto_message; + break; + + case MX_UNAPPROVED_NOTIFICATION: + $this->subject = $this->langs['module_title'] . ' - ' . $this->langs['notify_subject_unapproved']; + $this->message = $this->langs['notify_unapproved_body'] . "\n\n" . $this->auto_message; + break; + + case MX_DELETED_NOTIFICATION: + $this->subject = $this->langs['module_title'] . ' - ' . $this->langs['notify_subject_deleted']; + $this->message = $this->langs['notify_deleted_body'] . "\n\n" . $this->auto_message; + break; + + default: + mx_message_die(GENERAL_ERROR, 'Bad notify action'); + } + } + + /** + * Enter description here... + * + * @param unknown_type $get_all_userdata + * @return unknown + */ + function _get_admins( $get_all_userdata = false ) + { + global $db; + + $admin_type = ADMIN; + + $sql = "SELECT * + FROM " . USERS_TABLE . " + WHERE user_level = '$admin_type'"; + + if ( !( $result = $db->sql_query( $sql ) ) ) + { + mx_message_die( GENERAL_ERROR, "Could not obtain author data", '', __LINE__, __FILE__, $sql ); + } + + $user_ids_array = array(); + while( $row = $db->sql_fetchrow( $result ) ) + { + if ( $get_all_userdata ) + { + $user_ids_array[] = $row; + } + else + { + $user_ids_array[] = $row['user_id']; + } + } + + return $user_ids_array; + } + + /** + * Enter description here... + * + * @param unknown_type $group_id + * @param unknown_type $get_all_userdata + * @return unknown + */ + function _get_users_in_group( $group_id, $get_all_userdata = false ) + { + global $db; + + // + // Get user information for this group + // + $sql = "SELECT u.username, u.user_id, ug.group_id + FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug + WHERE ug.group_id = $group_id + AND u.user_id = ug.user_id + AND ug.user_pending = 0 + ORDER BY u.user_id"; + + if ( !($result = $db->sql_query($sql)) ) + { + mx_message_die(GENERAL_ERROR, 'Error getting user list for group', '', __LINE__, __FILE__, $sql); + } + + $user_ids_array = array(); + while( $row = $db->sql_fetchrow( $result ) ) + { + if ( $get_all_userdata ) + { + $user_ids_array[] = $row; + } + else + { + $user_ids_array[] = $row['user_id']; + } + } + return $user_ids_array; + } + } ?> \ No newline at end of file |