diff --git a/config.sample.php b/config.sample.php index dfc34c714..f9153ccb7 100755 --- a/config.sample.php +++ b/config.sample.php @@ -138,6 +138,14 @@ class Config public static $modEMailServerHTTP='https://webmail.your-server.de'; // URL-Link to the server public static $modEMailLogin=''; public static $modEMailPassword=''; + public static $modEMailName='vDiplomacy Moderator Team'; + + /** + * Site name to be shown at various places on the application and inside mails. + * + * @var string + */ + public static $siteName='vDiplomacy'; /** * If you use the piwik-webanalyser define his path here. If not comment this out. diff --git a/lib/html.php b/lib/html.php index 1ad9c5287..b612fe203 100755 --- a/lib/html.php +++ b/lib/html.php @@ -141,9 +141,9 @@ static function alert() * The points icon * @return string */ - static function points() + static function points($path = '') { - return ' D'; + return ' D'; } static function forumMessage($threadID, $messageID) diff --git a/modforum.php b/modforum.php index 4b4094c55..4c82180d2 100644 --- a/modforum.php +++ b/modforum.php @@ -218,9 +218,9 @@ { // To a thread $threadDetails = $DB->sql_hash( - "SELECT f.id, f.latestReplySent, f.assigned, u.type as userType + "SELECT f.id, f.latestReplySent, f.assigned, u.type as userType, f.subject, f.fromMail FROM wD_ModForumMessages f - INNER JOIN wD_Users u ON ( f.fromUserID = u.id ) + LEFT JOIN wD_Users u ON ( f.fromUserID = u.id ) WHERE f.id=".$new['sendtothread']." AND f.type='ThreadStart'"); @@ -234,9 +234,10 @@ $new['id'] = ModForumMessage::send( $new['sendtothread'], $fromUserID, $new['message'], - '', + 'RE: '.$threadDetails['subject'], 'ThreadReply', - (isset($_REQUEST['ReplyAdmin']) ? 'Yes' : 'No') + (isset($_REQUEST['ReplyAdmin']) ? 'Yes' : 'No'), + $threadDetails['fromMail'] ); $_SESSION['lastPostText']=$new['message']; @@ -943,7 +944,14 @@ function readModThread(threadID, lastMessageID) { { print 'type['Moderator']) - print 'onclick="return confirm(\'Are you sure you want post this reply visible for the thread-starter too?\');"'; + { + if( isset($message['fromMail']) ) + { + print 'onclick="return confirm(\'Are you sure you want send this reply visible as email to \\\''.$message['fromMail'].'\\\'?\');"'; + } else { + print 'onclick="return confirm(\'Are you sure you want post this reply visible for the thread-starter too?\');"'; + } + } print 'class="form-submit" value="Post reply" name="Reply">'; if (strpos($message['userType'],'Moderator')===false && $User->type['Moderator']) diff --git a/modforum/libMessage.php b/modforum/libMessage.php index d397a6e3d..e96575302 100644 --- a/modforum/libMessage.php +++ b/modforum/libMessage.php @@ -41,37 +41,76 @@ static public function linkify($message) return preg_replace($patterns, $replacements, $message); } + static public function linkifyWithAbsPaths($message) + { + $message=self::splitWords($message); + + $baseUrl = 'https://'.$_SERVER['SERVER_NAME'].'/'; + + $patterns = array( + '/gameID[:= _]?([0-9]+)/i', + '/userID[:= _]?([0-9]+)/i', + '#(modforum.php.*viewthread[:= _]?)([0-9]+)#i', + '#/forum.php.*threadID[:= _]?([0-9]+)#i', + '/((?:[^a-z0-9])|(?:^))([0-9]+) ?(?:(?:D)|(?:points))((?:[^a-z])|(?:$))/i', + ); + $replacements = array( + 'gameID=\1', + 'userID=\1', + '\1\2', + ''.$baseUrl.'/forum.php?threadID=\1', + '\1\2'.libHTML::points($baseUrl).'\3' + ); + + return preg_replace($patterns, $replacements, $message); + } + /** * Send a message to the public forum. The variables passed are assumed to be already sanitized * * @param int $toID User/Thread ID to send to * @param int $fromUserID UserID sent from - * @param string $message The message to be sent + * @param string $plainMessage The message to be sent * @param string[optional] $subject The subject * @param string[optional] $type 'Bulletin'(GameMaster->Player) 'ThreadStart'(User->All) 'ThreadReply'(User->Thread) + * @param string[optional] $adminReply 'No'(show to recipient) 'Yes'(show only internally) + * @param string[optional] $sendMailTo If set will be used to send an email to the provided address. * * @return int The message ID */ - static public function send($toID, $fromUserID, $message, $subject="", $type='Bulletin', $adminReply='No') + static public function send($toID, $fromUserID, $message, $subject="", $type='Bulletin', $adminReply='No', $sendMailTo=NULL) { global $DB, $User; if( defined('AdminUserSwitch') && AdminUserSwitch != $User->id) $fromUserID = AdminUserSwitch; - $message = self::linkify($message); + $linkifiedMessage = self::linkify($message); $sentTime=time(); - if( 65000 < strlen($message) ) + if( 65000 < strlen($linkifiedMessage) ) { throw new Exception("Message too long"); } + $sendMail = ( $sendMailTo !== NULL && $adminReply === 'No' ); + if( $sendMail ) + { + require_once(l_r('objects/mailer.php')); + $Mailer = new Mailer(); + $Mailer->Send(array($sendMailTo=>$sendMailTo), $subject, self::linkifyWithAbsPaths($message), 'mod'); + } + + if( $type === 'ThreadReply' ) + { + $subject=""; + } + libCache::wipeDir(libCache::dirName('mod_forum')); $DB->sql_put("INSERT INTO wD_ModForumMessages SET toID = ".$toID.", fromUserID = ".$fromUserID.", timeSent = ".$sentTime.", - message = '".$message."', subject = '".$subject."', replies = 0, + message = '".$linkifiedMessage."', subject = '".$subject."', replies = 0, type = '".$type."', latestReplySent = 0, adminReply = '".$adminReply."'"); $id = $DB->last_inserted(); diff --git a/objects/mailer.php b/objects/mailer.php index bf5b2a675..bbbbb1281 100755 --- a/objects/mailer.php +++ b/objects/mailer.php @@ -41,8 +41,6 @@ public function __construct() $this->PHPMailer = new PHPMailer(); - $this->PHPMailer->setFrom(Config::$mailerConfig['From'], Config::$mailerConfig['FromName']); - $this->PHPMailer->addReplyTo(Config::$mailerConfig['From'], Config::$mailerConfig['FromName']); $this->PHPMailer->wordWrap = 50; $this->PHPMailer->isHTML(true); @@ -80,31 +78,55 @@ private function Clear() $this->PHPMailer->clearReplyTos(); } - public function Send(array $to, $title, $message) + public function Send(array $to, $title, $message, $fromMail = 'generated') { + if( $fromMail == 'generated' ) + { + $from = Config::$mailerConfig['From']; + $fromName = Config::$mailerConfig['FromName']; + $generated = true; + } + else if( $fromMail == 'mod' ) + { + $from = Config::$modEMail; + $fromName = Config::$modEMailName; + $generated = false; + } + else + trigger_error(l_t("Invalid mailer sender config chosen.")); + if( $this->useDebug ) { print '

'.l_t('Mailed "%s": %s - %s

','<'.implode('>, <',$to).'>',$title,$message); return; } - $title = l_t('webDiplomacy: %s (no reply)',$title); + $this->PHPMailer->setFrom($from, $fromName); + $this->PHPMailer->addReplyTo($from, $fromName); + + if( $generated ) + $title = l_t('%s: %s (no reply)', Config::$siteName, $title); $this->PHPMailer->Subject = $title; foreach( $to as $email=>$name ) { - $wrappedmessage = ' -

'.l_t('Hello %s,',$name).'

-

-'.$message." -

-

".l_t('Kind regards,')."
-".Config::$mailerConfig['FromName']."

- -

-".l_t("This message was generated by a webDiplomacy server, sent from %s to %s (%s) at %s (GMT+0), on behalf of %s.", - Config::$mailerConfig['From'], + $wrappedmessage = ''; + + if( $generated ) + $wrappedmessage .= '

'.l_t('Hello %s,',$name).'

'; + + $wrappedmessage .= '

+'.$message.' +

'; + if( $generated ) + $wrappedmessage .= "

".l_t('Kind regards,')."
+".$fromName."

"; + + $wrappedmessage .= "

+".l_t("This message was generated by a %s server, sent from %s to %s (%s) at %s (GMT+0), on behalf of %s.", + Config::$siteName, + $from, $email, $name, gmdate("Y-m-d\TH:i:s\Z"),