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 . 'StorageAdapter/AdapterInterface.php';
|
||||
|
||||
class w3form {
|
||||
class w3form
|
||||
{
|
||||
|
||||
private array $email = ['adresses' => '', 'from' => ['name' => '', 'email' => ''], 'message' => '', 'subject' => ''];
|
||||
private array $unraveled = [];
|
||||
|
@ -58,8 +59,9 @@ class w3form {
|
|||
}
|
||||
}
|
||||
|
||||
private function add2Message($key, $value) {
|
||||
if (strlen($key) > 25 OR strlen($value) > 54) {
|
||||
private function add2Message($key, $value): void
|
||||
{
|
||||
if (strlen($key) > 25 or strlen($value) > 54) {
|
||||
$this->email['message'] .= "$key\n$value\n";
|
||||
} else {
|
||||
$this->email['message'] .= $key;
|
||||
|
@ -68,14 +70,16 @@ class w3form {
|
|||
}
|
||||
}
|
||||
|
||||
private function generateEmailMessage() {
|
||||
private function generateEmailMessage(): void
|
||||
{
|
||||
if ($this->unraveled)
|
||||
foreach ($this->unraveled as $key => $value) {
|
||||
$this->add2Message($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
private function suppress() {
|
||||
private function suppress(): array
|
||||
{
|
||||
$fields = [];
|
||||
$suppress = func_get_args();
|
||||
foreach ($_POST as $key => $value) {
|
||||
|
@ -85,7 +89,8 @@ class w3form {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
public function addEmailAdress($email) {
|
||||
public function addEmailAdress($email): void
|
||||
{
|
||||
if (empty($this->emailAdresses)) {
|
||||
$this->email['adresses'] .= "$email";
|
||||
} else {
|
||||
|
@ -93,34 +98,40 @@ class w3form {
|
|||
}
|
||||
}
|
||||
|
||||
public function setEmailSubject($subject) {
|
||||
public function setEmailSubject($subject): void
|
||||
{
|
||||
$this->email['subject'] = $subject;
|
||||
}
|
||||
|
||||
public function setEmailFrom($email, $name) {
|
||||
public function setEmailFrom($email, $name): void
|
||||
{
|
||||
$this->email['from']['email'] = $email;
|
||||
$this->email['from']['name'] = $name;
|
||||
}
|
||||
|
||||
public function setForm($form) {
|
||||
public function setForm($form): void
|
||||
{
|
||||
$this->form['form'] = $form;
|
||||
}
|
||||
|
||||
public function setAnswer($answer) {
|
||||
public function setAnswer($answer): void
|
||||
{
|
||||
$this->form['answer'] = $answer;
|
||||
}
|
||||
|
||||
public function setBackgroundError($color) {
|
||||
public function setBackgroundError($color): void
|
||||
{
|
||||
$this->form['colorError'] = $color;
|
||||
}
|
||||
|
||||
public function formInterpretation(&$form) {
|
||||
public function formInterpretation(&$form): array
|
||||
{
|
||||
$fields = explode('###', $form);
|
||||
$field = [];
|
||||
|
||||
for ($i = 1; $i < count($fields); $i = $i + 2) {
|
||||
$attributte = explode(';', trim($fields[$i]));
|
||||
foreach ($attributte as $attribute) {
|
||||
$attribute = explode(';', trim($fields[$i]));
|
||||
foreach ($attribute as $attribute) {
|
||||
$nameValue = explode(':', trim($attribute));
|
||||
if ($nameValue[0] != 'option' && $nameValue[0] != 'optionvalue') {
|
||||
$field["{$fields[$i]}"]["{$nameValue[0]}"] = $nameValue[1];
|
||||
|
@ -133,7 +144,8 @@ class w3form {
|
|||
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 '<input type="hidden" name="sent" value="true" />';
|
||||
$form = $this->form['form'];
|
||||
|
@ -151,7 +163,8 @@ class w3form {
|
|||
echo '</form></div>';
|
||||
}
|
||||
|
||||
public function formField($attribute, $sent) {
|
||||
public function formField($attribute, $sent): void
|
||||
{
|
||||
$style = '';
|
||||
$value = '';
|
||||
$parameter = "name=\"{$attribute['name']}\"";
|
||||
|
@ -186,9 +199,9 @@ class w3form {
|
|||
$capId = @$_POST['captcha_id'];
|
||||
$securimage = new Securimage();
|
||||
|
||||
if ($securimage->check($captcha) == false) {
|
||||
if (!$securimage->check($captcha)) {
|
||||
echo '<style>'
|
||||
. '#captcha_code {background-color: '.$this->form['colorError'].'}'
|
||||
. '#captcha_code {background-color: ' . $this->form['colorError'] . '}'
|
||||
. '</style>';
|
||||
}
|
||||
}
|
||||
|
@ -281,7 +294,8 @@ class w3form {
|
|||
}
|
||||
}
|
||||
|
||||
private function formComplete() {
|
||||
private function formComplete(): bool
|
||||
{
|
||||
$form = $this->form['form'];
|
||||
$fields = $this->formInterpretation($form);
|
||||
foreach ($fields as $field) {
|
||||
|
@ -292,7 +306,8 @@ class w3form {
|
|||
return true;
|
||||
}
|
||||
|
||||
private function success() {
|
||||
private function success(): void
|
||||
{
|
||||
if ($this->sendEmail()) {
|
||||
echo $this->form['answer'];
|
||||
} else {
|
||||
|
@ -300,7 +315,8 @@ class w3form {
|
|||
}
|
||||
}
|
||||
|
||||
private function formFieldCorrect(&$field) {
|
||||
private function formFieldCorrect(&$field): bool
|
||||
{
|
||||
|
||||
$tmp_name = rtrim($field['name'], '[0]');
|
||||
preg_match('/\[(\d*)\]/', $field['name'], $matches);
|
||||
|
@ -387,7 +403,8 @@ class w3form {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function process() {
|
||||
public function process(): void
|
||||
{
|
||||
if (!isset($_POST['sent'])) {
|
||||
$this->formOutput();
|
||||
} elseif ($this->formComplete()) {
|
||||
|
@ -395,7 +412,7 @@ class w3form {
|
|||
$captcha = @$_POST['ct_captcha'];
|
||||
$capId = @$_POST['captcha_id'];
|
||||
$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>';
|
||||
$this->formOutput(true);
|
||||
} else {
|
||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren