1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 06:38:00 +02:00

Issue #4372 Contact page code cleanup and 'layout' template added.

This commit is contained in:
Cameron
2021-02-17 19:04:57 -08:00
parent acccf1d1ba
commit d0404cb9b3
2 changed files with 245 additions and 199 deletions

View File

@@ -25,34 +25,58 @@ class contact_front
{ {
$active = varset($pref['contact_visibility'], e_UC_PUBLIC); $active = varset($pref['contact_visibility'], e_UC_PUBLIC);
$contactInfo = trim(SITECONTACTINFO); $contactInfo = trim(SITECONTACTINFO);
$pref = e107::getPref();
if(!check_class($active) && empty($contactInfo) && empty($pref['contact_info'])) if(!check_class($active) && empty($contactInfo) && empty($pref['contact_info']))
{ {
e107::redirect(); e107::redirect();
} }
if(isset($_POST['send-contactus']))
{
$this->processFormSubmit($sql);
}
$form = '';
$info = '';
if(deftrue('SITECONTACTINFO') || !empty($pref['contact_info']))
{
$info = $this->renderContactInfo();
}
if(check_class($active) && isset($pref['sitecontacts']) && $pref['sitecontacts'] != e_UC_NOBODY)
{
$form = $this->renderContactForm();
}
elseif($active == e_UC_MEMBER && ($pref['sitecontacts'] != e_UC_NOBODY))
{
$this->renderSignupRequired();
}
if(!$LAYOUT = e107::getCoreTemplate('contact', 'layout'))
{
$LAYOUT = '{---CONTACT-INFO---} {---CONTACT-FORM---} ';
}
echo str_replace(
['{---CONTACT-FORM---}', '{---CONTACT-INFO---}'],
[$form, $info],
$LAYOUT
);
}
/**
* @param $sql
* @return array
*/
private function processFormSubmit()
{
$sql = e107::getDb();
$sec_img = e107::getSecureImg(); $sec_img = e107::getSecureImg();
$tp = e107::getParser(); $tp = e107::getParser();
$ns = e107::getRender(); $ns = e107::getRender();
$pref = e107::getPref(); $pref = e107::getPref();
$CONTACT_FORM = varset($GLOBALS['CONTACT_FORM']);
if (empty($CONTACT_FORM))
{
/* if (file_exists(THEME."contact_template.php"))
{
require_once(THEME."contact_template.php");
}
else*/
{
$CONTACT_FORM = e107::getCoreTemplate('contact','form'); // require_once(e_THEME."templates/contact_template.php");
}
}
if(isset($_POST['send-contactus']))
{
$error = ""; $error = "";
$ignore = false; $ignore = false;
@@ -89,7 +113,7 @@ class contact_front
$email_copy = !empty($_POST['email_copy']) ? 1 : 0; $email_copy = !empty($_POST['email_copy']) ? 1 : 0;
// Check Image-Code // Check Image-Code
if (isset($_POST['rand_num']) && !$sec_img->verify_code($_POST['rand_num'], $_POST['code_verify'])) if(isset($_POST['rand_num']) && ($sec_img->invalidCode($_POST['rand_num'], $_POST['code_verify'])))
{ {
$error .= LANCONTACT_15 . "\\n"; $error .= LANCONTACT_15 . "\\n";
} }
@@ -112,7 +136,6 @@ class contact_front
} }
// Check email address on remote server (if enabled). XXX Problematic! // Check email address on remote server (if enabled). XXX Problematic!
/* /*
if ($pref['signup_remote_emailcheck'] && $error == '') if ($pref['signup_remote_emailcheck'] && $error == '')
@@ -146,7 +169,7 @@ class contact_front
$body .= "<br /><br /> $body .= "<br /><br />
<table class='table'> <table class='table'>
<tr> <tr>
<td>IP:</td><td>".e107::getIPHandler()->getIP(TRUE)."</td></tr>"; <td>IP:</td><td>" . e107::getIPHandler()->getIP(true) . "</td></tr>";
if(USER) if(USER)
{ {
@@ -231,8 +254,7 @@ class contact_front
); );
$message = e107::getEmail()->sendEmail($send_to, $send_to_name, $eml) ? LANCONTACT_09 : LANCONTACT_10;
$message = e107::getEmail()->sendEmail($send_to, $send_to_name, $eml, false) ? LANCONTACT_09 : LANCONTACT_10;
// $message = (sendemail($send_to,"[".SITENAME."] ".$subject, $body,$send_to_name,$sender,$sender_name)) ? LANCONTACT_09 : LANCONTACT_10; // $message = (sendemail($send_to,"[".SITENAME."] ".$subject, $body,$send_to_name,$sender,$sender_name)) ? LANCONTACT_09 : LANCONTACT_10;
@@ -244,54 +266,69 @@ class contact_front
$ns->tablerender('', "<div class='alert alert-success'>" . $message . "</div>"); $ns->tablerender('', "<div class='alert alert-success'>" . $message . "</div>");
require_once(FOOTERF);
exit;
} }
else else
{ {
message_handler("P_ALERT", $error); message_handler("P_ALERT", $error);
} }
} }
/**
* @return string html
*/
private function renderContactInfo()
{
$contact_shortcodes = e107::getScBatch('contact'); $contact_shortcodes = e107::getScBatch('contact');
if(deftrue('SITECONTACTINFO') || !empty($pref['contact_info'])) $CONTACT_INFO = varset($GLOBALS['CONTACT_INFO']);
{
if(!isset($CONTACT_INFO)) if(empty($CONTACT_INFO))
{ {
$CONTACT_INFO = e107::getCoreTemplate('contact', 'info'); $CONTACT_INFO = e107::getCoreTemplate('contact', 'info');
} }
$contact_shortcodes->wrapper('contact/info'); $contact_shortcodes->wrapper('contact/info');
$text = $tp->parseTemplate($CONTACT_INFO, true, $contact_shortcodes); $text = e107::getParser()->parseTemplate($CONTACT_INFO, true, $contact_shortcodes);
$ns->tablerender(LANCONTACT_01, $text,"contact-info"); return e107::getRender()->tablerender(LANCONTACT_01, $text, "contact-info", true);
} }
if(check_class($active) && isset($pref['sitecontacts']) && $pref['sitecontacts'] != e_UC_NOBODY) private function renderContactForm()
{ {
// Wrapper support $CONTACT_FORM = varset($GLOBALS['CONTACT_FORM']);
if(empty($CONTACT_FORM))
{
$CONTACT_FORM = e107::getCoreTemplate('contact', 'form'); // require_once(e_THEME."templates/contact_template.php");
}
$contact_shortcodes = e107::getScBatch('contact');
$contact_shortcodes->wrapper('contact/form'); $contact_shortcodes->wrapper('contact/form');
$text = $tp->parseTemplate($CONTACT_FORM, true, $contact_shortcodes); $text = e107::getParser()->parseTemplate($CONTACT_FORM, true, $contact_shortcodes);
if(trim($text) != "") if(trim($text) !== '')
{ {
$ns->tablerender(LANCONTACT_02, $text, "contact-form"); return e107::getRender()->tablerender(LANCONTACT_02, $text, "contact-form", true);
} }
} }
elseif($active == e_UC_MEMBER && ($pref['sitecontacts'] != e_UC_NOBODY))
private function renderSignupRequired()
{ {
$srch = array("[", "]"); $srch = array("[", "]");
$repl = array("<a class='alert-link' href='" . e_SIGNUP . "'>", "</a>"); $repl = array("<a class='alert-link' href='" . e_SIGNUP . "'>", "</a>");
$message = LANCONTACT_16; // "You must be [registered] and signed-in to use this form."; $message = LANCONTACT_16; // "You must be [registered] and signed-in to use this form.";
$ns->tablerender(LANCONTACT_02, "<div class='alert alert-info'>".str_replace($srch, $repl, $message)."</div>", "contact"); e107::getRender()->tablerender(LANCONTACT_02, "<div class='alert alert-info'>" . str_replace($srch, $repl, $message) . "</div>", "contact");
}
} }
} }

View File

@@ -130,6 +130,14 @@ $CONTACT_TEMPLATE['form'] = "
</form>"; </form>";
// Set the layout and order of the info and form.
$CONTACT_TEMPLATE['layout'] = '{---CONTACT-INFO---}
{---CONTACT-FORM---}
';
// Customize the email subject // Customize the email subject
// Variables: CONTACT_SUBJECT and CONTACT_PERSON as well as any custom fields set in the form. ) // Variables: CONTACT_SUBJECT and CONTACT_PERSON as well as any custom fields set in the form. )
$CONTACT_TEMPLATE['email']['subject'] = "{CONTACT_SUBJECT}"; $CONTACT_TEMPLATE['email']['subject'] = "{CONTACT_SUBJECT}";
@@ -137,3 +145,4 @@ $CONTACT_TEMPLATE['email']['subject'] = "{CONTACT_SUBJECT}";