public function modEntry($text, $enableSmilies, $enableHtml, $enableBBCodes) { $text = WCF::getDB()->escapeString($text); $curDate = time(); $eExists = WCF::getDB()->getFirstRow("SELECT COUNT(*) AS CNT FROM wcf" . WCF_N . "_user_wanted_poster WHERE userID = " . $this->userID); if (!empty($eExists['CNT'])) { $sql = "UPDATE wcf" . WCF_N . "_user_wanted_poster" . "\n SET text = '" . $text . "'" . "\n ,updateDate = " . $curDate . "\n ,enableSmilies = " . $enableSmilies . "\n ,enableHtml = " . $enableHtml . "\n ,enableBBCodes = " . $enableBBCodes . "\n WHERE userID = " . $this->userID; } else { $sql = "INSERT INTO wcf" . WCF_N . "_user_wanted_poster" . "\n(userID, text, insertDate, updateDate, enableSmilies, enableHtml, enableBBCodes)" . "\nVALUES (" . $this->userID . ", '" . $text . "', " . $curDate . ", " . $curDate . ", " . $enableSmilies . ", " . $enableHtml . ", " . $enableBBCodes . ")"; } WCF::getDB()->sendQuery($sql); // admin pm notifier... if (USERWANTEDPOSTER_PMNOTIFIERUGRP || USERWANTEDPOSTER_PMNOTIFIERUSER) { require_once WCF_DIR . 'lib/data/message/pm/PMEditor.class.php'; require_once WCF_DIR . 'lib/data/user/UserProfile.class.php'; $notify = array(); $u = USERWANTEDPOSTER_PMNOTIFIERUSER; $g = USERWANTEDPOSTER_PMNOTIFIERUGRP; $sql = "SELECT username FROM wcf" . WCF_N . "_user WHERE userID = " . $this->userID; list($username) = WCF::getDB()->getFirstRow($sql, MYSQL_NUM); if (!empty($u)) { $tmp = explode(',', $u); foreach ($tmp as $k => $v) { $notify[] = intval(trim($v)); } } if (!empty($g)) { $sql = "SELECT DISTINCT userID" . "\n FROM wcf" . WCF_N . "_user_to_groups" . "\n WHERE groupID IN (" . $g . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { if (!in_array($row['userID'], $notify)) { $notify[] = $row['userID']; } } } foreach ($notify as $k => $userID) { if (!empty($userID) && $userID > 0) { $user = new UserProfile($userID, null, null, null); $lang = $user->languageID == WCF::getLanguage()->getLanguageID() ? WCF::getLanguage() : new Language($user->languageID); $subject = $lang->get('wcf.user.wantedPoster.pmAdminNotifier.subject', array('$username' => $username)); $msg = $lang->get('wcf.user.wantedPoster.pmAdminNotifier.message', array('$username' => '[url=' . PAGE_URL . '/index.php?page=UserWantedPoster&userID=' . $this->userID . SID_ARG_2ND . ']' . $username . '[/url]', '$moderator' => $user->username)); PMEditor::create(false, array(array("username" => $user->username, 'userID' => $user->userID)), array(), $subject, $msg, $this->userID, $username, array('enableBBCodes' => 1, 'showSignature' => 0)); } } } }
/** * Sends the newsletters. */ protected function sendNewsletters() { $templateName = 'newsletterMail'; //Sends mail to all subscribers. foreach ($this->outstandingNewsletters as $id => $newsletter) { $text = $newsletter['text']; //workaround to make sure that the template is found $templatePaths = array(WCF_DIR . 'templates/', WCF_DIR . 'acp/templates/'); WCF::getTPL()->setTemplatePaths($templatePaths); $newsletterObj = new ViewableNewsletter($id); $emailText = $newsletterObj->getFormattedMessage(); WCF::getTPL()->assign(array('subject' => $newsletter['subject'], 'text' => $emailText)); $content = WCF::getTPL()->fetch($templateName); $i = 0; usleep(1); //sending one mail per subscriber //is longer, but safer foreach ($this->subscribersList as $subscriber) { //sleep 2 seconds after 10 sent mails if (fmod($i, 10) == 0) { usleep(2000000); } $unsubscribeToken = ''; if (!isset($this->unsubscribeTokens[$subscriber['subscriberID']])) { $unsubscribeToken = StringUtil::getRandomID(); $sql = 'INSERT INTO wcf' . WCF_N . '_' . $this->unsubscriptionTable . ' (subscriberID, token) VALUES (' . intval($subscriber['subscriberID']) . ", '" . escapeString($unsubscribeToken) . "')"; WCF::getDB()->sendQuery($sql); } else { $unsubscribeToken = $this->unsubscribeTokens[$subscriber['subscriberID']]['token']; } $recipient = null; if ($subscriber['userID']) { $recipient = new User($subscriber['userID']); // check for non receiving groups if (!NewsletterUtil::canReceiveNewsletters($recipient)) { continue; } } // {$username} stands for the username of the specific subscriber if (is_null($recipient) || $recipient->getUserOption('acceptNewsletterAsEmail')) { $tmpContent = str_replace('{$username}', $subscriber['username'], $content); $tmpContent = str_replace('subscriberID', $subscriber['subscriberID'], $tmpContent); $tmpContent = str_replace('token', $unsubscribeToken, $tmpContent); $email = $subscriber['email']; $mail = new Mail($email, $newsletter['subject'], $tmpContent, MESSAGE_NEWSLETTERSYSTEM_GENERAL_FROM); //$mail->addBCC(MAIL_ADMIN_ADDRESS); would result in x mails $mail->setContentType('text/html'); $mail->send(); } if (!is_null($recipient) && $recipient->getUserOption('acceptNewsletterAsPM')) { $recipientArray = array(); $recipientArray[] = array('userID' => $subscriber['userID'], 'username' => $subscriber['username']); $admin = new User(MESSAGE_NEWSLETTERSYSTEM_GENERAL_ADMIN); $options = array('enableSmilies' => $newsletter['enableSmilies'], 'enableHtml' => $newsletter['enableHtml'], 'enableBBCodes' => $newsletter['enableBBCodes']); $tmpText = str_replace('{$username}', $subscriber['username'], $text); $pm = PMEditor::create(false, $recipientArray, array(), $newsletter['subject'], $tmpText, $admin->userID, $admin->username, $options); } $i++; } } WCF::getCache()->clearResource('newsletter-subscriber-' . PACKAGE_ID); }
/** * @see Form::save() */ public function save() { parent::save(); // save message in database $update = $this->pm && !$this->forwarding && !$this->reply; // search for double posts if (!$update && PMEditor::test($this->recipientArray, $this->blindCopyArray, $this->subject, $this->text, WCF::getUser()->userID, WCF::getUser()->username)) { HeaderUtil::redirect('index.php?page=PMList' . SID_ARG_2ND_NOT_ENCODED); exit; } if ($update) { $this->pm->update($this->draft, $this->recipientArray, $this->blindCopyArray, $this->subject, $this->text, $this->getOptions(), $this->attachmentListEditor); $this->newPm = new PMEditor($this->pm->pmID); } else { $this->newPm = PMEditor::create($this->draft, $this->recipientArray, $this->blindCopyArray, $this->subject, $this->text, WCF::getUser()->userID, WCF::getUser()->username, $this->getOptions(), $this->attachmentListEditor, $this->pm && $this->reply ? $this->pm->parentPmID : 0); } // reply & forwarding if ($this->pmID) { if ($this->reply) { $this->pm->markAsReplied(); } if ($this->forwarding) { $this->pm->markAsForwarded(); } } // send e-mail notification if (!$this->draft) { $this->sendNotification(); } // apply rules if (!$this->draft) { $this->newPm->applyRules(); } $this->saved(); // forward to pm index if ($this->draft) { HeaderUtil::redirect('index.php?page=PMList&folderID=-2' . SID_ARG_2ND_NOT_ENCODED); } else { HeaderUtil::redirect('index.php?page=PMList' . SID_ARG_2ND_NOT_ENCODED); } exit; }
public function addEntry($fromUserID, $text, $enableSmilies, $enableHtml, $enableBBCodes) { $cTime = TIME_NOW; $text = WCF::getDB()->escapeString($text); $fromUsername = WCF::getUser()->username; $fromUsername = WCF::getDB()->escapeString($fromUsername); $sql = "INSERT INTO wcf" . WCF_N . "_user_guestbook" . "\n (userID, fromUserID, fromUsername, text, enableSmilies, enableHtml, enableBBCodes, entryTime)" . "\nVALUES (" . $this->userID . ", " . $fromUserID . ", '" . $fromUsername . "', '" . $text . "', " . $enableSmilies . ", " . $enableHtml . ", " . $enableBBCodes . ", " . $cTime . ")"; WCF::getDB()->sendQuery($sql); $sql = "SELECT COUNT(*) AS count" . "\n FROM wcf" . WCF_N . "_user_guestbook" . "\n WHERE userID = " . $this->userID; list($cntEntries) = WCF::getDB()->getFirstRow($sql, MYSQL_NUM); if ($this->userID == $fromUserID) { $sql = "INSERT INTO wcf" . WCF_N . "_user_guestbook_header" . "\n (userID, userLastVisit, lastEntryUserID, lastEntryUsername, lastEntry, entries, newEntries)" . "\nVALUES (" . $this->userID . ", " . $cTime . ", " . $fromUserID . ", '" . $fromUsername . "', " . $cTime . ", " . $cntEntries . ", 0)" . "\n ON DUPLICATE KEY UPDATE" . "\n userID = " . $this->userID . "\n ,userLastVisit = " . $cTime . "\n ,lastEntryUserID = " . $fromUserID . "\n ,lastEntryUsername = '******'" . "\n ,lastEntry = " . $cTime . "\n ,entries = " . $cntEntries . "\n ,newEntries = 0"; } else { $sql = "SELECT COUNT(*) AS count" . "\n FROM wcf" . WCF_N . "_user_guestbook gb" . "\n LEFT JOIN wcf" . WCF_N . "_user_guestbook_header gbh ON (gbh.userID = gb.userID)" . "\n WHERE gb.userID = " . $this->userID . "\n AND gbh.userLastVisit < gb.entryTime"; list($cntNewEntries) = WCF::getDB()->getFirstRow($sql, MYSQL_NUM); $sql = "INSERT INTO wcf" . WCF_N . "_user_guestbook_header" . "\n (userID, lastEntryUserID, lastEntryUsername, lastEntry, entries, newEntries, visitorID, visitorLastVisit)" . "\nVALUES (" . $this->userID . ", " . $fromUserID . ", '" . $fromUsername . "', " . $cTime . ", " . $cntEntries . ", " . $cntNewEntries . ", " . $fromUserID . ", " . $cTime . ")" . "\n ON DUPLICATE KEY UPDATE" . "\n userID = " . $this->userID . "\n ,lastEntryUserID = " . $fromUserID . "\n ,lastEntryUsername = '******'" . "\n ,lastEntry = " . $cTime . "\n ,entries = " . $cntEntries . "\n ,newEntries = " . $cntNewEntries . "\n ,visitorID = " . $fromUserID . "\n ,visitorLastVisit = " . $cTime; } WCF::getDB()->sendQuery($sql); // PN senden if ($this->user->userGuestbook_sendPM && $this->user->userID != $fromUserID) { $user = new UserProfile($fromUserID, null, null, null); $fromUserName = $user->username; $lang = $this->user->languageID == WCF::getLanguage()->getLanguageID() ? WCF::getLanguage() : new Language($this->user->languageID); $subject = $lang->get('wcf.user.guestbook.pm.subject'); $msg = $lang->get('wcf.user.guestbook.pm.message', array('$username' => $this->user->username)); PMEditor::create(false, array(array("username" => $this->user->username, 'userID' => $this->userID)), array(), $subject, $msg, $user->userID, $user->username); } // admin pm notifier... if (!empty($fromUserID) && (USERGUESTBOOK_PMNOTIFIERUGRP || USERGUESTBOOK_PMNOTIFIERUSER)) { $notify = array(); $u = USERGUESTBOOK_PMNOTIFIERUSER; $g = USERGUESTBOOK_PMNOTIFIERUGRP; if (empty($fromUserName)) { $user = new UserProfile($fromUserID, null, null, null); $fromUserName = $user->username; } if (!empty($u)) { $tmp = explode(',', $u); foreach ($tmp as $k => $v) { $notify[] = intval(trim($v)); } } if (!empty($g)) { $sql = "SELECT DISTINCT userID" . "\n FROM wcf" . WCF_N . "_user_to_groups" . "\n WHERE groupID IN (" . $g . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { if (!in_array($row['userID'], $notify)) { $notify[] = $row['userID']; } } } foreach ($notify as $k => $userID) { if (!empty($userID) && $userID > 0) { $user = new UserProfile($userID, null, null, null); $lang = $user->languageID == WCF::getLanguage()->getLanguageID() ? WCF::getLanguage() : new Language($user->languageID); $subject = $lang->get('wcf.user.guestbook.pmAdminNotifier.subject', array('$username' => $this->user->username)); $msg = $lang->get('wcf.user.guestbook.pmAdminNotifier.message', array('$username' => '[url=' . PAGE_URL . '/index.php?page=UserGuestbook&userID=' . $this->userID . SID_ARG_2ND . ']' . $this->user->username . '[/url]', '$userID' => $this->userID, '$fromusername' => '[url=' . PAGE_URL . '/index.php?page=User&userID=' . $fromUserID . SID_ARG_2ND . ']' . $fromUserName . '[/url]', '$moderator' => $user->username)); PMEditor::create(false, array(array("username" => $user->username, 'userID' => $user->userID)), array(), $subject, $msg, $fromUserID, $fromUserName, array('enableBBCodes' => 1, 'showSignature' => 0)); } } } }
/** * @see Action::execute() */ public function execute() { parent::execute(); // check permission WCF::getUser()->checkPermission('admin.user.canPMToUserGroups'); $sql = "SELECT COUNT(DISTINCT u.userID) AS cnt" . "\n FROM wcf" . WCF_N . "_user u" . "\n LEFT JOIN wcf" . WCF_N . "_user_to_groups g ON (g.userID = u.userID)" . "\n LEFT JOIN wcf" . WCF_N . "_group_option_value v ON (v.groupID = g.groupID)" . "\n LEFT JOIN wcf" . WCF_N . "_group_option o ON (o.optionID = v.optionID)" . "\n WHERE o.optionName = 'user.pm.canUsePm'" . "\n AND v.optionValue = '1'" . "\n AND u.userID != " . $this->userID . "\n AND g.groupID IN (" . $this->pmData['groupIDs'] . ")"; $row = WCF::getDB()->getFirstRow($sql); $count = $row['cnt']; if (!$count > 0) { // clear session if (isset($this->pmData)) { $pmData = WCF::getSession()->getVar('pmData'); unset($pmData[$this->pmSessionID]); WCF::getSession()->register('pmData', $pmData); } $this->finish('wcf.pmToUgrps.error.noRecipients', 'index.php?form=PMToUserGroups&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED); } if ($count <= $this->limit * $this->loop) { $endTime = TIME_NOW; $lf = "\n"; // remove from outbox $sql = "UPDATE wcf" . WCF_N . "_pm" . "\n SET saveInOutbox = 0" . "\n WHERE pmID = " . $this->pmID; WCF::getDB()->sendQuery($sql); // groups... $groups = ''; $sql = "SELECT groupName" . "\n FROM wcf" . WCF_N . "_group" . "\n WHERE groupID IN (" . $this->pmData['groupIDs'] . ")" . "\n ORDER BY groupName"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { if (!empty($groups)) { $groups .= ', '; } $groups .= StringUtil::decodeHTML($row['groupName']); } // log... $log = ''; $subject = WCF::getLanguage()->get('wcf.pmToUgrps.log.subject', array('$pmID' => $this->pmID)) . ' ' . $this->pmData['subject']; if ($this->pmData['enableHtml']) { $log .= '<pre>'; } $log .= WCF::getLanguage()->get('wcf.pmToUgrps.log.started', array('$startTime' => DateUtil::formatDate('%d.%m.%Y %H:%M:%S', $this->pmData['startTime']))) . $lf; $log .= WCF::getLanguage()->get('wcf.pmToUgrps.log.finished', array('$endTime' => DateUtil::formatDate('%d.%m.%Y %H:%M:%S', $endTime))) . $lf; $log .= WCF::getLanguage()->get('wcf.pmToUgrps.log.recipients', array('$groups' => $groups, '$count' => StringUtil::decodeHTML(StringUtil::formatInteger($count)))) . $lf; $log .= str_repeat('-', 60) . $lf; if ($this->pmData['enableHtml']) { $log .= '</pre>' . $lf; } $log .= $this->pmData['text']; $this->recipientArray = $this->blindCopyArray = array(); $this->recipientArray[0]['userID'] = $this->userID; $this->recipientArray[0]['username'] = $this->username; PMEditor::create($this->draft, $this->recipientArray, $this->blindCopyArray, $subject, $log, $this->userID, $this->username, array('enableSmilies' => $this->pmData['enableSmilies'], 'enableHtml' => $this->pmData['enableHtml'], 'enableBBCodes' => $this->pmData['enableBBCodes'], 'showSignature' => false)); // clear session $pmData = WCF::getSession()->getVar('pmData'); unset($pmData[$this->pmSessionID]); WCF::getSession()->register('pmData', $pmData); $this->calcProgress(); $msg = WCF::getLanguage()->get('wcf.pmToUgrps.finish', array('$count' => StringUtil::decodeHTML(StringUtil::formatInteger($count)), '$startTime' => DateUtil::formatShortTime('%H:%M:%S', $this->pmData['startTime']), '$endTime' => DateUtil::formatShortTime('%H:%M:%S', $endTime))); $this->finish($msg, 'index.php?form=PMToUserGroups&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED); } // get users $sql = "SELECT DISTINCT u.userID, u.username" . "\n FROM wcf" . WCF_N . "_user u" . "\n LEFT JOIN wcf" . WCF_N . "_user_to_groups g ON (g.userID = u.userID)" . "\n LEFT JOIN wcf" . WCF_N . "_group_option_value v ON (v.groupID = g.groupID)" . "\n LEFT JOIN wcf" . WCF_N . "_group_option o ON (o.optionID = v.optionID)" . "\n WHERE o.optionName = 'user.pm.canUsePm'" . "\n AND v.optionValue = '1'" . "\n AND u.userID != " . $this->userID . "\n AND g.groupID IN (" . $this->pmData['groupIDs'] . ")" . "\n ORDER BY u.userID"; $this->blindCopyArray = array(); $i = 0; $result = WCF::getDB()->sendQuery($sql, $this->limit, $this->limit * $this->loop); while ($row = WCF::getDB()->fetchArray($result)) { $this->blindCopyArray[$i]['userID'] = $row['userID']; $this->blindCopyArray[$i]['username'] = $row['username']; $i++; } if (count($this->blindCopyArray)) { if (empty($this->pmID)) { $tmp = PMEditor::create($this->draft, $this->recipientArray, $this->blindCopyArray, $this->pmData['subject'], $this->pmData['text'], $this->userID, $this->username, array('enableSmilies' => $this->pmData['enableSmilies'], 'enableHtml' => $this->pmData['enableHtml'], 'enableBBCodes' => $this->pmData['enableBBCodes'], 'showSignature' => $this->pmData['showSignature'])); if ($tmp->pmID) { $this->pmID = intval($tmp->pmID); $pmData = WCF::getSession()->getVar('pmData'); $pmData[$this->pmSessionID]['pmID'] = $this->pmID; WCF::getSession()->register('pmData', $pmData); $mlt = intval($this->pmData['maxLifeTime']); if ($mlt > 0) { $mlt = $this->pmData['startTime'] + 86400 * $mlt; } else { $mlt = 0; } $sql = "INSERT IGNORE INTO wcf" . WCF_N . "_pm_bulk_mailing" . "\n (pmID, elapsedTime, time, userID)" . "\nVALUES (" . $this->pmID . ", " . $mlt . ", " . $this->pmData['startTime'] . ", " . $this->userID . ")"; WCF::getDB()->sendQuery($sql); } } else { $recipientIDs = $inserts = ''; foreach ($this->blindCopyArray as $k => $v) { $username = WCF::getDB()->escapeString($this->blindCopyArray[$k]['username']); if (!empty($recipientIDs)) { $recipientIDs .= ','; } $recipientIDs .= $this->blindCopyArray[$k]['userID']; if (!empty($inserts)) { $inserts .= ','; } $inserts .= "\n (" . $this->pmID . ", " . intval($this->blindCopyArray[$k]['userID']) . ", '" . $username . "', 1)"; } if (!empty($recipientIDs) && !empty($inserts)) { $sql = "INSERT IGNORE INTO wcf" . WCF_N . "_pm_to_user" . "\n (pmID, recipientID, recipient, isBlindCopy)" . "\nVALUES " . $inserts; WCF::getDB()->sendQuery($sql); PMEditor::updateUnreadMessageCount($recipientIDs); PMEditor::updateTotalMessageCount($recipientIDs); Session::resetSessions($recipientIDs, true, false); } } } $this->executed(); $this->calcProgress($this->limit * $this->loop, $count); $msg = WCF::getLanguage()->get('wcf.pmToUgrps.progress', array('$loop' => StringUtil::decodeHTML(StringUtil::formatInteger($this->limit * $this->loop)), '$count' => StringUtil::decodeHTML(StringUtil::formatInteger($count)))); $this->nextLoop($msg, 'index.php?action=' . $this->action . '&pmSessionID=' . $this->pmSessionID . '&limit=' . $this->limit . '&loop=' . ($this->loop + 1) . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED); }
/** * @see Form::save() */ public function save() { parent::save(); // create user warning $expires = $this->expiresHour * 3600 + $this->expiresDay * 86400 + $this->expiresWeek * 86400 * 7; $userWarning = UserWarningEditor::create($this->userID, WCF::getUser()->userID, $this->warningID, $this->objectID, $this->objectType, $this->title, $this->points, $expires ? TIME_NOW + $expires : 0, $this->reason); // check suspensions UserWarningEditor::checkWarnings($this->userID); // get language $languages = array(WCF::getLanguage()->getLanguageID() => WCF::getLanguage(), 0 => WCF::getLanguage()); if (!isset($languages[$this->user->languageID])) { $languages[$this->user->languageID] = new Language($this->user->languageID); } $languages[$this->user->languageID]->setLocale(); // send pm require_once WCF_DIR . 'lib/data/message/pm/PMEditor.class.php'; PMEditor::create(0, array($this->user->userID => array('userID' => $this->user->userID, 'username' => $this->user->username)), array(), $languages[$this->user->languageID]->get('wcf.user.infraction.userWarning.message.subject'), $languages[$this->user->languageID]->getDynamicVariable('wcf.user.infraction.userWarning.message.text', array('title' => $this->title, 'reason' => $this->reason)), WCF::getUser()->userID, WCF::getUser()->username); $this->saved(); // reset language WCF::getLanguage()->setLocale(); // show success message and forward user $url = ($this->object !== null ? $this->object->getURL() : 'index.php?page=User&userID=' . $this->userID) . SID_ARG_2ND_NOT_ENCODED; WCF::getTPL()->assign(array('url' => $url, 'message' => WCF::getLanguage()->get('wcf.user.infraction.userWarning.add.success'), 'wait' => 5)); WCF::getTPL()->display('redirect'); exit; }