/** * Displays the form for writing a new private message or replying to an * existing one. Also saves the new private message to database. * * @author Georg Ringer <*****@*****.**> * @author Martin Helmich <*****@*****.**> * @version 2008-01-11 * @param string $content The content * @param array $conf The plugin's configuration vars * @return string The plugin content */ function message_write($content, $conf) { $messageId = intval($this->piVars['messid']); // Load message to reply to from database $res = $this->databaseHandle->exec_SELECTquery('uid,from_name,message,subject', 'tx_mmforum_pminbox', 'hidden=0 AND deleted=0 AND uid=' . $messageId . ' AND to_uid=' . $GLOBALS['TSFE']->fe_user->user['uid'] . $this->getStoragePIDQuery(), '', 'sendtime ASC', '1'); $isReply = $this->databaseHandle->sql_num_rows($res) > 0; $originalMsg = $this->databaseHandle->sql_fetch_assoc($res); $this->databaseHandle->sql_free_result($res); // Commit user search if ($this->piVars['save'] == $this->pi_getLL('write.search')) { // If a messsage text has already been entered, store this text // in the session variables in order to have it available later on. if (!empty($this->piVars['message'])) { session_start(); $_SESSION['mm_forum']['pm']['message'] = $this->piVars['message']; } $content .= $this->list_user($content, $conf); } else { if ($this->piVars['save'] == $this->pi_getLL('write.send')) { $subject = $this->piVars['subject']; $message = $this->piVars['message']; $to_username = $this->piVars['user']; $error = 0; // Check subject if (!$subject) { $error = 1; $errormessage = $this->pi_getLL('errorNoSubject'); } // Check message if (!$message) { $error = 1; $errormessage = $this->pi_getLL('errorNoMessage'); } // Check recipient if (!$to_username) { $error = 1; $errormessage = $this->pi_getLL('errorNoRecipient'); } // Spam protection: just one message per $conf['block_time'] // Load last sent message from database $res = $this->databaseHandle->exec_SELECTquery('crdate', 'tx_mmforum_pminbox', 'from_uid=' . $GLOBALS['TSFE']->fe_user->user['uid'] . ' AND mess_type=0' . $this->getStoragePIDQuery(), '', 'crdate DESC', '1'); $lastMessage = $this->databaseHandle->sql_fetch_assoc($res); $this->databaseHandle->sql_free_result($res); $errormessage = ''; // Compare with current time and spam block interval if ($GLOBALS['EXEC_TIME'] - $conf['block_time'] <= $lastMessage['crdate']) { $error = 1; $errormessage = sprintf($this->pi_getLL('errorBlockinTime'), $conf['block_time']); } $marker = array(); // Check if an error has occurred so far. If so, abort. if ($error > 0) { $template = $this->cObj->fileResource($conf['template.']['error_message']); $marker['###ERROR###'] = $errormessage; $marker['###BACKLINK###'] = '<a href="javascript:history.back()">' . $this->pi_getLL('back') . '</a>'; } else { // Retrieve userId from username $res = $this->databaseHandle->exec_SELECTquery('uid,email,tx_mmforum_pmnotifymode,' . $this->getUserNameField(), 'fe_users', 'deleted=0 AND disable=0 AND username='******'fe_users') . ' AND pid=' . $this->conf['userPID']); $recipient = $this->databaseHandle->sql_fetch_assoc($res); $this->databaseHandle->sql_free_result($res); $recipientId = intval($recipient['uid']); // Save and send the private message if ($recipientId > 0) { // Save the private message for the recipient $val = array('pid' => $this->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'cruser_id' => $GLOBALS['TSFE']->fe_user->user['uid'], 'sendtime' => $GLOBALS['EXEC_TIME'], 'from_uid' => $GLOBALS['TSFE']->fe_user->user['uid'], 'from_name' => $GLOBALS['TSFE']->fe_user->user['username'], 'to_uid' => $recipientId, 'to_name' => $to_username, 'subject' => $subject, 'message' => $message); $this->databaseHandle->exec_INSERTquery('tx_mmforum_pminbox', $val); $mess_id = $this->databaseHandle->sql_insert_id(); // Save as sent private message $val = array('pid' => $this->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'cruser_id' => $GLOBALS['TSFE']->fe_user->user['uid'], 'sendtime' => $GLOBALS['EXEC_TIME'], 'to_uid' => $GLOBALS['TSFE']->fe_user->user['uid'], 'to_name' => $GLOBALS['TSFE']->fe_user->user['username'], 'from_uid' => $recipientId, 'from_name' => $to_username, 'subject' => $subject, 'message' => $message, 'mess_type' => 1); $this->databaseHandle->exec_INSERTquery('tx_mmforum_pminbox', $val); session_start(); unset($_SESSION['mm_forum']['pm']['message']); // Notification to the recipient via email if ($recipient['tx_mmforum_pmnotifymode'] == 0 && GeneralUtility::validEmail($recipient['email'])) { $template = $this->pi_getLL('ntfmail.content'); $linkParams[$this->prefixId] = array('messid' => $mess_id, 'action' => 'message_read'); if ($this->useRealUrl()) { $linkParams[$this->prefixId]['folder'] = 'inbox'; } $msgLink = $this->pi_getPageLink($this->conf['pm_id'], '', $linkParams); $msgLink = $this->tools->escapeBrackets($msgLink); $marker = array('###USERNAME###' => $recipient[$this->getUserNameField()], '###PMLINK###' => $msgLink, '###SITENAME###' => $conf['siteName'], '###MESSAGE###' => $message, '###SUBJECT###' => $this->pi_getLL('messageReplySubjectPrefix') . $subject, '###FROM###' => $GLOBALS['TSFE']->fe_user->user[$this->getUserNameField()], '###LINK##' => $conf['siteName'] . '/' . $msgLink); $mailtext = $this->cObj->substituteMarkerArrayCached($template, $marker); // Compose mail and send $mail = GeneralUtility::makeInstance('t3lib_mail_Message'); $mail->setFrom(array($this->conf['mailerEmail'] => $this->conf['siteName'])); $mail->setTo(array($recipient['email'] => $recipient['username'])); $mail->setSubject($this->pi_getLL('ntfmail.subject')); $mail->setBody($mailtext, 'text/plain'); $mail->send(); $updateArray = array('notified' => 1, 'tstamp' => $GLOBALS['EXEC_TIME']); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_pminbox', 'uid=' . $mess_id, $updateArray); } elseif ($recipient['tx_mmforum_pmnotifymode'] == 1) { $linkParams[$this->prefixId] = array('action' => 'message_read', 'messid' => $mess_id); $link = $this->pi_getPageLink($this->conf['pm_id'], '', $linkParams); tx_mmforum_tools::storeCacheVar('pm.urlCache.' . $mess_id, $link); } // Redirect user to inbox $link = $this->pi_getPageLink($conf['pm_id']); HttpUtility::redirect($link); // Display an error message in case the recipient does not exist } else { $template = $this->cObj->fileResource($conf['template.']['error_message']); $marker['###ERROR###'] = $this->pi_getLL('errorRecipientNotExists'); $marker['###BACKLINK###'] = '<a href="javascript:history.back()">' . $this->pi_getLL('back') . '</a>'; } } // Display message form } else { $content = $this->top_navi($content, $conf); // Load template $template = $this->cObj->fileResource($conf['template.']['message_write']); $template = $this->cObj->getSubpart($template, '###MESSAGE_WRITE###'); // Set language-dependent markers $marker = array('###LABEL_WRITEMESSAGE###' => $this->pi_getLL('write.writeMessage'), '###LABEL_TO###' => $this->pi_getLL('headerTofromOutbox'), '###LABEL_SUBJECT###' => $this->pi_getLL('headerSubject'), '###LABEL_SEND###' => $this->pi_getLL('write.send'), '###LABEL_RESET###' => $this->pi_getLL('write.reset'), '###LABEL_SEARCH###' => $this->pi_getLL('write.search'), '###EXT_PATH###' => ExtensionManagementUtility::siteRelPath("mm_forum"), '###PID###' => $conf['userPID'], '###LANG###' => $this->pi_getLL('write.search'), '###PM###' => $conf['pm_id'], '###AJAX_URL###' => ExtensionManagementUtility::siteRelPath('mm_forum') . 'pi3/tx_mmforum_usersearch.php', '###JAVASCRIPTUSERSEARCHREFRESH###' => $conf['pm_refreshUserSearch'], '###JAVASCRIPTUSERSEARCHHIDE###' => $conf['pm_hideUserSearch'], '###JAVASCRIPTUSERSEARCH###' => str_replace('###AJAX_URL###', ExtensionManagementUtility::siteRelPath('mm_forum') . 'pi3/tx_mmforum_usersearch.php', $conf['pm_UserSearch'])); session_start(); $_SESSION[$this->prefixId]['userPID'] = $this->conf['userPID']; $_SESSION[$this->prefixId]['userGID'] = $this->conf['userGroup']; $_SESSION[$this->prefixId]['usernameField'] = 'username'; //$this->getUserNameField(); // If PM is a reply to another PM, there is a prefix in subject/msg-text if ($isReply) { $msgPrefix = $this->pi_getLL('messageReplyTextPrefix'); $initialText = $msgPrefix . str_replace("\n", "\n" . $msgPrefix, $originalMsg['message']); $marker['###ACTION###'] = $this->pi_getPageLink($GLOBALS['TSFE']->id, '', array($this->prefixId => array('action' => 'message_write'))); $marker['###SUBJECT###'] = $this->pi_getLL('messageReplySubjectPrefix') . $originalMsg['subject']; $marker['###TO_USER###'] = $this->escape($originalMsg['from_name']); $marker['###MESSAGE###'] = $this->escape($initialText); // Create entirely new PM } else { $to_userid = $this->piVars['userid'] ? intval($this->piVars['userid']) : intval(GeneralUtility::_GP('userid')); if ($to_userid != 0) { $res = $this->databaseHandle->exec_SELECTquery('username', 'fe_users', 'uid=' . $to_userid); list($username) = $this->databaseHandle->sql_fetch_row($res); $this->databaseHandle->sql_free_result($res); } else { $username = ''; } $linkVars = array('action' => 'message_write'); $link = $this->pi_getPageLink($GLOBALS['TSFE']->id, '', array($this->prefixId => $linkVars)); $marker['###ACTION###'] = htmlspecialchars($link); $marker['###SUBJECT###'] = ''; $marker['###TO_USER###'] = $this->escape($username); $marker['###DATE###'] = ''; $marker['###MESSAGE###'] = ''; if ($_SESSION['mm_forum']['pm']['message']) { $marker['###MESSAGE###'] = $_SESSION['mm_forum']['pm']['message']; } } } } $content .= $this->cObj->substituteMarkerArrayCached($template, (array) $marker); return $content; }