sent = $contact_message_sent; if( empty($config['toemail']) ){ if( \gp\tool::LoggedIn() ){ $url = \gp\tool::GetUrl('Admin_Configuration'); msg($langmessage['enable_contact'], $url); } echo $langmessage['not_enabled']; return; } $cmd = \gp\tool::GetCommand(); switch($cmd){ case 'gp_send_message': if( !$message_send_attempt ){ $message_send_attempt = true; if( !$this->sent && $this->SendMessage() ){ $this->sent = $contact_message_sent = true; break; } } default: break; } $this->ShowForm(); } public function SendMessage(){ global $langmessage, $config; $headers = []; $_POST += [ 'subject' => '', 'contact_nonce' => '', 'message' => '', ]; if( empty($_POST['message']) ){ msg($langmessage['OOPS'] . '(Invalid Message)'); return; } //check nonce if( !\gp\tool\Nonce::Verify('contact_post', $_POST['contact_nonce'], true) ){ msg($langmessage['OOPS'] . '(Invalid Nonce)'); return; } if( !empty($_POST['contact_void']) ){ msg($langmessage['OOPS'] . '(Robot Detected)'); return; } //captcha if( !\gp\tool\Recaptcha::Check() ){ return; } if( !\gp\tool\Plugins::Filter('contact_form_check', [true]) ){ return; } $mailer = new \gp\tool\Emailer(); //subject $_POST['subject'] = strip_tags($_POST['subject']); //message $tags = '

'; $message = nl2br(strip_tags($_POST['message'], $tags)); //reply name if( !empty($_POST['email']) ){ //check format if( !$this->ValidEmail($_POST['email']) ){ msg($langmessage['invalid_email']); return false; } $replyName = str_replace(["\r", "\n"], [' '], $_POST['name']); $replyName = strip_tags($replyName); $replyName = htmlspecialchars($replyName); $mailer->AddReplyTo($_POST['email'], $replyName); if( \gp\tool::ConfigValue('from_use_user', false) ){ $mailer->SetFrom($_POST['email'], $replyName); } } //check for required values $require_email =& $config['require_email']; if( strpos($require_email, 'email') !== false ){ if( empty($_POST['email']) ){ $field = \gp\tool\Output::SelectText('your_email'); msg($langmessage['OOPS_REQUIRED'], $field); return false; } } if( strpos($require_email, 'none') === false ){ if( empty($_POST['subject']) ){ $field = \gp\tool\Output::SelectText('subject'); msg($langmessage['OOPS_REQUIRED'], $field); return false; } if( empty($message) ){ $field = \gp\tool\Output::SelectText('message'); msg($langmessage['OOPS_REQUIRED'], $field); return false; } } if( $mailer->SendEmail($config['toemail'], $_POST['subject'], $message) ){ msg($langmessage['message_sent']); return true; } msg($langmessage['OOPS'] . ' (Send Failed)'); return false; } public function ValidEmail($email){ return (bool)preg_match('/^[^@]+@[^@]+\.[^@]+$/', $email); } public function ShowForm(){ global $langmessage, $config; $readonly_attr = ''; if( $this->sent ){ $readonly_attr = ' readonly="readonly"'; } $_GET += [ 'name' => '', 'email' => '', 'subject' => '', 'message' => '', ]; $_POST += [ 'name' => $_GET['name'], 'email' => $_GET['email'], 'subject' => $_GET['subject'], 'message' => $_GET['message'], ]; $require_email =& $config['require_email']; echo '
'; echo '
'; //nonce fields echo '
'; echo ''; echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; \gp\tool\Plugins::Action('contact_form_pre_captcha'); if( !$this->sent && \gp\tool\Recaptcha::isActive() ){ echo '
'; echo \gp\tool\Output::ReturnText('captcha'); \gp\tool\Recaptcha::Form(); echo '
'; } if( $this->sent ){ echo '
'; echo \gp\tool\Output::ReturnText('message_sent', '%s', 'message_sent'); echo '
'; }else{ echo ''; $key = 'send_message'; $text = \gp\tool\Output::SelectText($key); if( \gp\tool\Output::ShowEditLink('Admin_Theme_Content') ){ $query = 'cmd=EditText&key=' . urlencode($key); echo \gp\tool\Output::EditAreaLink( $edit_index, 'Admin_Theme_Content/Text', $langmessage['edit'], $query, ' title="' . $key . '" data-cmd="gpabox" ' ); echo ''; }else{ echo ''; } } echo '
'; echo '
'; } }