Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modèle de page statique pour PLuXml pour une demande de contact
<?php
if(!defined('PLX_ROOT')) { exit; }
if(version_compare(PLX_VERSION, '6.0.0', '<')) {
include_once PLX_CORE . 'lib/class.plx.token.php';
if($plxShow->plxMotor->aConf['capcha']) {
include_once PLX_CORE . 'lib/class.plx.capcha.php';
}
}
const RECIPIENT = '001';
const FORM_FILTER = array(
'name' => FILTER_SANITIZE_STRING,
'phone' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('regexp' => '@^[\d\s.()+]+$@'),
),
'mail' => FILTER_VALIDATE_EMAIL,
'content' => FILTER_SANITIZE_STRING,
'capcha' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('regexp' => '@^\w$@'),
),
);
function processContact(&$plxShow) {
if(!filter_has_var(INPUT_POST, 'mail')) { return false; }
plxToken::validateFormToken();
$params = filter_input_array(INPUT_POST, FORM_FILTER);
if(empty($params['mail']) or empty(trim($params['content']))) {
return 'ERROR_CONTACT_MESSAGE';
}
if(!empty($plxShow->plxMotor->aConf['capcha']) and $_SESSION['capcha'] != sha1($params['capcha'])) {
return 'ERROR_CONTACT_CAPCHA';
}
if(!defined('RECIPIENT') or empty($plxShow->plxMotor->aUsers[RECIPIENT]['email'])) {
uasort($plxShow->plxMotor->aUsers, function ($a, $b) {
if(empty($a['email'])) { return 1; }
if(empty($b['email'])) { return -1; }
return $a['profil'] - $b['profil'];
});
$to = array_values($plxShow->plxMotor->aUsers)[0]['email'];
} else {
$to = $plxShow->plxMotor->aUsers[RECIPIENT]['email'];
}
if(empty($to)) { return 'ERROR_CONTACT_RECIPIENT'; }
// Corps du message
ob_start();
?>
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8" />
<style>
.mail-content { border: 1px solid #444; margin: 1rem 0; padding: 0.5rem 1rem; border-radius: 0.5rem; }
</style>
</head><body>
<p><strong><em>Site :</em> <?= $_SERVER['REQUEST_SCHEME'] ?>://<?= $_SERVER['HTTP_HOST'] ?></strong></p>
<?php
foreach($params as $field=>$value) {
if(!empty($value) and $field != 'capcha') {
if(in_array($field, array('content'))) {
// <textarea>
?>
<p><em><?= $plxShow->getLang('MAIL_' . strtoupper($field)) ?> :</em></p>
<div class="mail-content"><?= nl2br($value) ?></div>
<?php
} else {
?>
<p><em><?= $plxShow->getLang('MAIL_' . strtoupper($field)) ?> :</em> <?= $value ?></p>
<?php
}
}
}
foreach(array(
'Ip Address' => 'REMOTE_ADDR',
'User-Agent' => 'HTTP_USER_AGENT'
) as $k=>$value) {
?>
<p><em><?= $k ?> :</em> <?= $_SERVER[$value] ?></p>
<?php
}
?>
</body></html>
<?php
if(!mail(
$to,
sprintf($plxShow->getLang('MAIL_SUBJECT'), plxUtils::strCheck($plxShow->plxMotor->aConf['title'])), // Subject
ob_get_clean(), // Body
implode("\r\n", array( // Additional headers
'MIME-Version: 1.0',
'Content-type: text/html; charset="' . PLX_CHARSET . '"',
'Content-transfer-encoding: 8bit',
'Date: ' . date('D, j M Y G:i:s O'),
))
)) {
return 'ERROR_CONTACT_DELIVERY';
}
return true;
}
include 'header.php';
?>
<div class="site-content">
<article class="article static contact" id="static-page-<?= $plxShow->staticId(); ?>">
<header>
<h2><?php $plxShow->staticTitle(); ?></h2>
</header>
<?php
$result = processContact($plxShow);
if($result === true) {
?>
<p class="contact success"><?= nl2br($plxShow->getLang('MAIL_SUCCESS')) ?></p>
<?php
} else {
if(!empty($result)) {
// Il y a eu une erreur
?>
<p class="contact error"><?= $plxShow->getLang($result) ?></p>
<?php
}
$plxShow->staticContent();
?>
<form id="frm-contact" method="post">
<div>
<label><?= $plxShow->getLang('CONTACT_NAME') ?></label>
<input type="text" name="name" value="<?= plxUtils::getValue($param['name']) ?>" placeholder="<?= $plxShow->getLang('CONTACT_NAME') ?>" required />
</div>
<div>
<label><?= $plxShow->getLang('CONTACT_PHONE') ?></label>
<input type="text" name="phone" value="<?= plxUtils::getValue($param['phone']) ?>" placeholder="<?= $plxShow->getLang('CONTACT_PHONE') ?>" />
</div>
<div>
<label><?= $plxShow->getLang('CONTACT_MAIL') ?></label>
<input type="text" name="mail" value="<?= plxUtils::getValue($param['mail']) ?>" placeholder="<?= $plxShow->getLang('CONTACT_MAIL') ?>" required />
</div>
<div class="no-label">
<textarea name="content" placeholder="<?= $plxShow->getLang('CONTACT_CONTENT') ?>" rows="5" required><?= plxUtils::getValue($param['name']) ?></textarea>
</div>
<?php
if($plxShow->plxMotor->aConf['capcha']) {
$capcha = new plxCapcha();
?>
<div class="capcha">
<div><label for="id_capcha"><?= $plxShow->lang('ANTISPAM_WARNING') ?>&nbsp;:</label></div>
<div><?= $capcha->q(); ?></div>
<input name="capcha" type="text" size="3" maxlength="1" required />
</div>
<?php
}
?>
<div class="no-label">
<?= plxToken::getTokenPostMethod() ?>
<input type="submit" />
</div>
</form>
<?php
}
?>
</article>
</div>
<?php include 'footer.php'; ?>
@bazooka07

This comment has been minimized.

Copy link
Owner Author

@bazooka07 bazooka07 commented Nov 2, 2020

PluXml avec une version < 6.0.0 ne gére pas l'auto-loader de class pour PHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment