46 lines
3.5 KiB
PHP
46 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: HG Contactformulier
|
|
* Description: Configureerbaar contactformulier met workflows en talen vanuit de website, zonder inzendingen op te slaan.
|
|
* Version: 1.3.2
|
|
* Requires at least: 6.5
|
|
* Requires PHP: 8.1
|
|
* Text Domain: hg-contactform
|
|
*/
|
|
if (!defined('ABSPATH')) { exit; }
|
|
define('HGCF_VERSION','1.3.2');
|
|
define('HGCF_FILE',__FILE__);
|
|
require_once __DIR__.'/includes/settings.php';
|
|
require_once __DIR__.'/includes/language.php';
|
|
require_once __DIR__.'/includes/form.php';
|
|
require_once __DIR__.'/includes/antispam.php';
|
|
function hgcf_handle_submission() {
|
|
if(($_SERVER['REQUEST_METHOD']??'')!=='POST' || ($_POST['mlhc_action']??'')!=='send') return;
|
|
$id=get_queried_object_id(); $post=get_post($id);
|
|
if(!is_singular() || !$post || (!has_shortcode($post->post_content,'hg_contactform') && !has_shortcode($post->post_content,'mlh_contact'))) wp_die('Invalid form page', '', ['response'=>403]);
|
|
$lang=hgcf_language($post->post_content);
|
|
$error=hgcf_text('Het versturen is niet gelukt. Probeer het opnieuw of gebruik een andere contactmogelijkheid.','Your message could not be sent. Please try again or use another contact option.',$lang);
|
|
$nonce=$_POST['mlhc_nonce']??''; $started=$_POST['mlhc_started']??''; $signature=$_POST['mlhc_signature']??'';
|
|
if(!is_string($nonce) || !wp_verify_nonce($nonce,'hgcf_send') || !is_string($started) || !ctype_digit($started) || !is_string($signature) || !hash_equals(hash_hmac('sha256',$started,wp_salt('nonce')),$signature) || time()-(int)$started<2 || time()-(int)$started>DAY_IN_SECONDS || !empty($_POST['mlhc_website'])) {
|
|
$GLOBALS['mlhc_errors']=new WP_Error('security',$error); return;
|
|
}
|
|
$submitted=[]; foreach(['name','email','phone','message','mode','massage','preferred_date','preferred_time','consent'] as $field) { if(isset($_POST['mlhc_'.$field])) $submitted[$field]=$_POST['mlhc_'.$field]; }
|
|
$data=hgcf_validate($submitted,$lang);
|
|
if(is_wp_error($data)) { $GLOBALS['mlhc_errors']=$data; return; }
|
|
$ip=$_SERVER['REMOTE_ADDR']??'unknown';
|
|
$rate_key='mlhc_rate_'.hash_hmac('sha256',$ip,wp_salt('auth'));
|
|
$rate=get_transient($rate_key);
|
|
if($rate && ($rate['count']>=5 || time()-$rate['last']<30)) { $GLOBALS['mlhc_errors']=new WP_Error('rate',hgcf_text('Even geduld: probeer het over een minuut opnieuw of gebruik een andere contactmogelijkheid.','Please wait a minute before trying again, or use another contact option.',$lang)); return; }
|
|
if(hgcf_altcha_enabled()&&!hgcf_verify_altcha(wp_unslash($_POST['mlhc_altcha']??''),$id)) { $GLOBALS['mlhc_errors']=new WP_Error('altcha',hgcf_text('De antispamcontrole is niet gelukt of verlopen. Probeer de controle opnieuw.','The spam protection check failed or expired. Please verify again.',$lang)); return; }
|
|
$rate=$rate?:['count'=>0,'last'=>0]; $rate['count']++;$rate['last']=time();set_transient($rate_key,$rate,15*MINUTE_IN_SECONDS);
|
|
if(!hgcf_send($data,$lang)) { $GLOBALS['mlhc_errors']=new WP_Error('mail',$error); return; }
|
|
$url=add_query_arg(['contact_status'=>'received','receipt'=>wp_create_nonce('mlhc_received_'.$id)],get_permalink($id));
|
|
wp_safe_redirect($url.'#contact-form',303);exit;
|
|
}
|
|
add_action('template_redirect','hgcf_handle_submission');
|
|
add_shortcode('hg_contactform','hgcf_render');
|
|
add_shortcode('mlh_contact','hgcf_render');
|
|
add_action('wp_enqueue_scripts',function(){
|
|
$post=get_post();if(is_singular()&&$post&&(has_shortcode($post->post_content,'hg_contactform')||has_shortcode($post->post_content,'mlh_contact')))wp_enqueue_style('hgcf',plugins_url('assets/contact.css',__FILE__),[],HGCF_VERSION);
|
|
});
|