From eb20caebc5bed91b6324ed16c1c427b7f31de9cd Mon Sep 17 00:00:00 2001 From: azett Date: Wed, 1 Jan 2020 00:48:46 +0100 Subject: [PATCH] Fix for #55: HTTPS URLs in the contact form are now handled correctly. --- contact.php | 183 ++++++++++++++++++++++++---------------------------- 1 file changed, 83 insertions(+), 100 deletions(-) diff --git a/contact.php b/contact.php index dfc9d73..09ee813 100755 --- a/contact.php +++ b/contact.php @@ -1,114 +1,97 @@ assign('success', system_geterr('contact')); + $smarty->assign_by_ref('panelstrings', $lang ['contact']); - if(empty($_POST)) { - - $smarty->assign('success', system_geterr('contact')); - $smarty->assign_by_ref('panelstrings', $lang['contact']); - - // new form, we (re)set the session data - SmartyValidate::connect($smarty, true); + SmartyValidate::connect($smarty, true); // register our validators - SmartyValidate::register_validator('name', 'name', 'notEmpty', false, false, 'trim'); - SmartyValidate::register_validator('email', 'email', 'isEmail', true, false, 'trim'); - SmartyValidate::register_validator('www', 'url', 'isURL', true, false, 'trim'); - SmartyValidate::register_validator('content', 'content', 'notEmpty', false, false); - } else { - utils_nocache_headers(); - // validate after a POST - SmartyValidate::connect($smarty); + SmartyValidate::register_validator('name', 'name', 'notEmpty', false, false, 'trim'); + SmartyValidate::register_validator('email', 'email', 'isEmail', true, false, 'trim'); + SmartyValidate::register_validator('www', 'url', 'isURL', true, false, 'trim'); + SmartyValidate::register_validator('content', 'content', 'notEmpty', false, false); + } else { + utils_nocache_headers(); + // validate after a POST + SmartyValidate::connect($smarty); - if (!empty($_POST['url']) && strpos($_POST['url'], 'http://')===false) $_POST['url'] = 'http://'.$_POST['url']; - - - // custom hook here!! - // we'll use comment actions, anyway - if(SmartyValidate::is_valid($_POST) && $arr=contact_form_validate()) { - - $msg = "Name: \n{$arr['name']} \n\n"; - - if (isset($arr['email'])) - $msg .= "Email: {$arr['email']}\n\n"; - if (isset($arr['url'])) - $msg .= "WWW: {$arr['url']}\n\n"; - $msg .= "Content:\n{$arr['content']}\n"; - - $success = @utils_mail( - ( - isset($arr['email'])? - $arr['email'] - : - $fp_config['general']['email'] - ), - "Contact sent through {$fp_config['general']['title']} ", $msg ); + // add http to url if not given + if (!empty($_POST ['url']) && strpos($_POST ['url'], 'http://') === false && strpos($_POST ['url'], 'https://') === false) + $_POST ['url'] = 'http://' . $_POST ['url']; - system_seterr('contact', $success? 1 : -1); - utils_redirect(basename(__FILE__)); - } else { - $smarty->assign('values', $_POST); - } + // custom hook here!! + // we'll use comment actions, anyway + if (SmartyValidate::is_valid($_POST) && $arr = contact_form_validate()) { + + $msg = "Name: \n{$arr['name']} \n\n"; + + if (isset($arr ['email'])) + $msg .= "Email: {$arr['email']}\n\n"; + if (isset($arr ['url'])) + $msg .= "WWW: {$arr['url']}\n\n"; + $msg .= "Content:\n{$arr['content']}\n"; + + $success = @utils_mail((isset($arr ['email']) ? $arr ['email'] : $fp_config ['general'] ['email']), "Contact sent through {$fp_config['general']['title']} ", $msg); + + system_seterr('contact', $success ? 1 : -1); + utils_redirect(basename(__FILE__)); + } else { + $smarty->assign('values', $_POST); } } +} - - function contact_main() { - global $smarty; - - $lang = lang_load('contact'); - - $smarty->assign('subject', $lang['contact']['head']); - $smarty->assign('content', 'shared:contact.tpl'); - contact_form(); - - } +function contact_main() { + global $smarty; - function contact_display() { - global $smarty; - - contact_main(); - - theme_init($smarty); - - $smarty->display('default.tpl'); - - unset($smarty); - - do_action('shutdown'); - - } + $lang = lang_load('contact'); + + $smarty->assign('subject', $lang ['contact'] ['head']); + $smarty->assign('content', 'shared:contact.tpl'); + contact_form(); +} + +function contact_display() { + global $smarty; + + contact_main(); + + theme_init($smarty); + + $smarty->display('default.tpl'); + + unset($smarty); + + do_action('shutdown'); +} + +system_init(); +contact_display(); - - system_init(); - contact_display(); - ?>