documentation and cleaning code
Dieser Commit ist enthalten in:
Ursprung
bfadeb3ffc
Commit
08ff39e4b5
1 geänderte Dateien mit 41 neuen und 24 gelöschten Zeilen
|
@ -16,7 +16,8 @@ require_once $sFrontEndPath . 'securimage.php';
|
||||||
require_once $sFrontEndPath . 'CaptchaObject.php';
|
require_once $sFrontEndPath . 'CaptchaObject.php';
|
||||||
require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php';
|
require_once $sFrontEndPath . 'StorageAdapter/AdapterInterface.php';
|
||||||
|
|
||||||
class w3form {
|
class w3form
|
||||||
|
{
|
||||||
|
|
||||||
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
||||||
private array $unraveled = [];
|
private array $unraveled = [];
|
||||||
|
@ -58,8 +59,9 @@ class w3form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function add2Message($key, $value) {
|
private function add2Message($key, $value): void
|
||||||
if (strlen($key) > 25 OR strlen($value) > 54) {
|
{
|
||||||
|
if (strlen($key) > 25 or strlen($value) > 54) {
|
||||||
$this->email['message'] .= "$key\n$value\n";
|
$this->email['message'] .= "$key\n$value\n";
|
||||||
} else {
|
} else {
|
||||||
$this->email['message'] .= $key;
|
$this->email['message'] .= $key;
|
||||||
|
@ -68,14 +70,16 @@ class w3form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateEmailMessage() {
|
private function generateEmailMessage(): void
|
||||||
|
{
|
||||||
if ($this->unraveled)
|
if ($this->unraveled)
|
||||||
foreach ($this->unraveled as $key => $value) {
|
foreach ($this->unraveled as $key => $value) {
|
||||||
$this->add2Message($key, $value);
|
$this->add2Message($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function suppress() {
|
private function suppress(): array
|
||||||
|
{
|
||||||
$fields = [];
|
$fields = [];
|
||||||
$suppress = func_get_args();
|
$suppress = func_get_args();
|
||||||
foreach ($_POST as $key => $value) {
|
foreach ($_POST as $key => $value) {
|
||||||
|
@ -85,7 +89,8 @@ class w3form {
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addEmailAdress($email) {
|
public function addEmailAdress($email): void
|
||||||
|
{
|
||||||
if (empty($this->emailAdresses)) {
|
if (empty($this->emailAdresses)) {
|
||||||
$this->email['adresses'] .= "$email";
|
$this->email['adresses'] .= "$email";
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,34 +98,40 @@ class w3form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEmailSubject($subject) {
|
public function setEmailSubject($subject): void
|
||||||
|
{
|
||||||
$this->email['subject'] = $subject;
|
$this->email['subject'] = $subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEmailFrom($email, $name) {
|
public function setEmailFrom($email, $name): void
|
||||||
|
{
|
||||||
$this->email['from']['email'] = $email;
|
$this->email['from']['email'] = $email;
|
||||||
$this->email['from']['name'] = $name;
|
$this->email['from']['name'] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setForm($form) {
|
public function setForm($form): void
|
||||||
|
{
|
||||||
$this->form['form'] = $form;
|
$this->form['form'] = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnswer($answer) {
|
public function setAnswer($answer): void
|
||||||
|
{
|
||||||
$this->form['answer'] = $answer;
|
$this->form['answer'] = $answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBackgroundError($color) {
|
public function setBackgroundError($color): void
|
||||||
|
{
|
||||||
$this->form['colorError'] = $color;
|
$this->form['colorError'] = $color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formInterpretation(&$form) {
|
public function formInterpretation(&$form): array
|
||||||
|
{
|
||||||
$fields = explode('###', $form);
|
$fields = explode('###', $form);
|
||||||
$field = [];
|
$field = [];
|
||||||
|
|
||||||
for ($i = 1; $i < count($fields); $i = $i + 2) {
|
for ($i = 1; $i < count($fields); $i = $i + 2) {
|
||||||
$attributte = explode(';', trim($fields[$i]));
|
$attribute = explode(';', trim($fields[$i]));
|
||||||
foreach ($attributte as $attribute) {
|
foreach ($attribute as $attribute) {
|
||||||
$nameValue = explode(':', trim($attribute));
|
$nameValue = explode(':', trim($attribute));
|
||||||
if ($nameValue[0] != 'option' && $nameValue[0] != 'optionvalue') {
|
if ($nameValue[0] != 'option' && $nameValue[0] != 'optionvalue') {
|
||||||
$field["{$fields[$i]}"]["{$nameValue[0]}"] = $nameValue[1];
|
$field["{$fields[$i]}"]["{$nameValue[0]}"] = $nameValue[1];
|
||||||
|
@ -133,7 +144,8 @@ class w3form {
|
||||||
return $field;
|
return $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formOutput($sent = false) {
|
public function formOutput($sent = false): void
|
||||||
|
{
|
||||||
echo '<div class="textItem secondItem"><form action="" method="POST" class="form-horizontal">';
|
echo '<div class="textItem secondItem"><form action="" method="POST" class="form-horizontal">';
|
||||||
echo '<input type="hidden" name="sent" value="true" />';
|
echo '<input type="hidden" name="sent" value="true" />';
|
||||||
$form = $this->form['form'];
|
$form = $this->form['form'];
|
||||||
|
@ -151,7 +163,8 @@ class w3form {
|
||||||
echo '</form></div>';
|
echo '</form></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formField($attribute, $sent) {
|
public function formField($attribute, $sent): void
|
||||||
|
{
|
||||||
$style = '';
|
$style = '';
|
||||||
$value = '';
|
$value = '';
|
||||||
$parameter = "name=\"{$attribute['name']}\"";
|
$parameter = "name=\"{$attribute['name']}\"";
|
||||||
|
@ -186,10 +199,10 @@ class w3form {
|
||||||
$capId = @$_POST['captcha_id'];
|
$capId = @$_POST['captcha_id'];
|
||||||
$securimage = new Securimage();
|
$securimage = new Securimage();
|
||||||
|
|
||||||
if ($securimage->check($captcha) == false) {
|
if (!$securimage->check($captcha)) {
|
||||||
echo '<style>'
|
echo '<style>'
|
||||||
. '#captcha_code {background-color: '.$this->form['colorError'].'}'
|
. '#captcha_code {background-color: ' . $this->form['colorError'] . '}'
|
||||||
. '</style>';
|
. '</style>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// show captcha HTML using Securimage::getCaptchaHtml()
|
// show captcha HTML using Securimage::getCaptchaHtml()
|
||||||
|
@ -281,7 +294,8 @@ class w3form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formComplete() {
|
private function formComplete(): bool
|
||||||
|
{
|
||||||
$form = $this->form['form'];
|
$form = $this->form['form'];
|
||||||
$fields = $this->formInterpretation($form);
|
$fields = $this->formInterpretation($form);
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
|
@ -292,7 +306,8 @@ class w3form {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function success() {
|
private function success(): void
|
||||||
|
{
|
||||||
if ($this->sendEmail()) {
|
if ($this->sendEmail()) {
|
||||||
echo $this->form['answer'];
|
echo $this->form['answer'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -300,7 +315,8 @@ class w3form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formFieldCorrect(&$field) {
|
private function formFieldCorrect(&$field): bool
|
||||||
|
{
|
||||||
|
|
||||||
$tmp_name = rtrim($field['name'], '[0]');
|
$tmp_name = rtrim($field['name'], '[0]');
|
||||||
preg_match('/\[(\d*)\]/', $field['name'], $matches);
|
preg_match('/\[(\d*)\]/', $field['name'], $matches);
|
||||||
|
@ -387,7 +403,8 @@ class w3form {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process() {
|
public function process(): void
|
||||||
|
{
|
||||||
if (!isset($_POST['sent'])) {
|
if (!isset($_POST['sent'])) {
|
||||||
$this->formOutput();
|
$this->formOutput();
|
||||||
} elseif ($this->formComplete()) {
|
} elseif ($this->formComplete()) {
|
||||||
|
@ -395,7 +412,7 @@ class w3form {
|
||||||
$captcha = @$_POST['ct_captcha'];
|
$captcha = @$_POST['ct_captcha'];
|
||||||
$capId = @$_POST['captcha_id'];
|
$capId = @$_POST['captcha_id'];
|
||||||
$securimage = new Securimage();
|
$securimage = new Securimage();
|
||||||
if ($securimage->check($captcha, $capId, true) == false) {
|
if (!$securimage->check($captcha, $capId, true)) {
|
||||||
echo '<div style="color: red;">' . mi18n("Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.") . '</div>';
|
echo '<div style="color: red;">' . mi18n("Ihr Captcha Code war nicht korrekt. Bitte versuchen Sie es erneut.") . '</div>';
|
||||||
$this->formOutput(true);
|
$this->formOutput(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren