<?php
 class vB_Api_Contactus extends vB_Api { public function fetchPredefinedSubjects() { $vboptions = vB::getDatastore()->getValue('options'); $options = []; if ($vboptions['contactusoptions']) { $options = explode("\n", trim($vboptions['contactusoptions'])); foreach ($options AS $index => $title) { if (preg_match('#^({.*}) (.*)$#siU', $title, $matches)) { $options[$index] = $matches[2]; } } } return $options; } public function sendMail($maildata, $hvinput = []) { if (empty($maildata['name']) || empty($maildata['email']) || empty($maildata['message'])) { throw new vB_Exception_Api('please_complete_required_fields'); } $vboptions = vB::getDatastore()->getValue('options'); if ( $vboptions['contactusoptions'] AND $maildata['subject'] == 'other' AND ($maildata['other_subject'] == '' OR !$vboptions['contactusother']) ) { throw new vB_Exception_Api('nosubject'); } if (!vB_String::isValidEmail($maildata['email'])) { throw new vB_Exception_Api('bademail'); } vB_Api::instanceInternal('hv')->verifyToken($hvinput, 'contactus'); $phraseApi = vB_Api::instanceInternal('phrase'); $languageid = $vboptions['languageid']; if ($vboptions['contactusoptions']) { if ($maildata['subject'] == 'other') { $maildata['subject'] = $maildata['other_subject']; } else { $options = explode("\n", trim($vboptions['contactusoptions'])); foreach ($options AS $index => $title) { if ($index == $maildata['subject']) { if (preg_match('#^{(.*)} (.*)$#siU', $title, $matches)) { $title = $matches[2]; if (is_numeric($matches[1]) AND intval($matches[1]) !== 0) { $userinfo = vB_User::fetchUserinfo($matches[1]); $alt_email = $userinfo['email']; $languageid = $userinfo['languageid']; } else { $alt_email = $matches[1]; } } $maildata['subject'] = $title; break; } } } } if (!empty($alt_email)) { if ($alt_email == $vboptions['webmasteremail'] OR $alt_email == $vboptions['contactusemail']) { $ip = vB::getRequest()->getIpAddress(); } else { $phrases = $phraseApi->renderPhrases(['n_a' => 'n_a']); $ip = $phrases['phrases']['n_a']; } $destemail = $alt_email; } else { $ip = vB::getRequest()->getIpAddress(); if ($vboptions['contactusemail']) { $destemail = $vboptions['contactusemail']; } else { $destemail = $vboptions['webmasteremail']; } } $currentuser = vB::getCurrentSession()->fetch_userinfo(); $string = vB::getString(); $bbtitle_escaped = $string->htmlspecialchars($vboptions['bbtitle']); $mailcontent = $phraseApi->fetchEmailPhrases( 'contactus', [ $bbtitle_escaped, $string->htmlspecialchars($maildata['name']), $string->htmlspecialchars($maildata['email']), nl2br($string->htmlspecialchars($maildata['message'])), $ip, $currentuser['username'], $currentuser['userid'], ], [ $vboptions['bbtitle'], $maildata['subject'], ], $languageid ); vB_Mail::emailFloodCheck(); vB_Mail::create($destemail, $mailcontent)->addReplyTo([$maildata['email'], $maildata['name']])->sendNow(true); vB_Mail::updateFloodTime(); return true; } } 