1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2022 |
6
|
|
|
* @package Client |
7
|
|
|
* @subpackage Html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Cms\Page\Contact; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation for CMS contact form. |
16
|
|
|
* |
17
|
|
|
* @package Client |
18
|
|
|
* @subpackage Html |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Client\Html\Common\Client\Factory\Base |
22
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Returns the HTML code for insertion into the body. |
26
|
|
|
* |
27
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
28
|
|
|
* @return string HTML code |
29
|
|
|
*/ |
30
|
|
|
public function body( string $uid = '' ) : string |
31
|
|
|
{ |
32
|
|
|
return ''; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Modifies the cached body content to replace content based on sessions or cookies. |
38
|
|
|
* |
39
|
|
|
* @param string $content Cached content |
40
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
41
|
|
|
* @return string Modified body content |
42
|
|
|
*/ |
43
|
|
|
public function modify( string $content, string $uid ) : string |
44
|
|
|
{ |
45
|
|
|
$token = !$this->view()->access( ['editor', 'admin', 'super'] ) ? $this->view()->csrf()->formfield() : ''; |
46
|
|
|
|
47
|
|
|
return $this->replaceSection( $content, $token, 'cms.page.contact.csrf' ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Processes the input, e.g. store given values. |
53
|
|
|
* |
54
|
|
|
* A view must be available and this method doesn't generate any output |
55
|
|
|
* besides setting view variables if necessary. |
56
|
|
|
*/ |
57
|
|
|
public function init() |
58
|
|
|
{ |
59
|
|
|
$view = $this->view(); |
60
|
|
|
|
61
|
|
|
$name = $view->param( 'contact/name' ); |
62
|
|
|
$email = $view->param( 'contact/email' ); |
63
|
|
|
$msg = $view->param( 'contact/message' ); |
64
|
|
|
$honeypot = $view->param( 'contact/url' ); |
65
|
|
|
|
66
|
|
|
if( !$honeypot && $name && $email && $msg ) |
67
|
|
|
{ |
68
|
|
|
$context = $this->context(); |
69
|
|
|
$config = $context->config(); |
70
|
|
|
$i18n = $context->i18n(); |
71
|
|
|
|
72
|
|
|
$toAddr = $config->get( 'resource/email/from-email' ); |
73
|
|
|
$toName = $config->get( 'resource/email/from-name' ); |
74
|
|
|
|
75
|
|
|
if( $toAddr ) |
76
|
|
|
{ |
77
|
|
|
$label = $context->locale()->getSiteItem()->getLabel(); |
78
|
|
|
|
79
|
|
|
$context->mail()->create() |
80
|
|
|
->to( $toAddr, $toName ) |
81
|
|
|
->from( $email, $name ) |
82
|
|
|
->subject( $i18n->dt( 'client', 'Your request' ) . ' - ' . $label ) |
83
|
|
|
->text( $msg ) |
84
|
|
|
->send(); |
85
|
|
|
|
86
|
|
|
$error = [$i18n->dt( 'client', 'Message sent successfully' )]; |
87
|
|
|
} |
88
|
|
|
else |
89
|
|
|
{ |
90
|
|
|
$error = [$i18n->dt( 'client', 'No recipient configured' )]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$view->errors = array_merge( $view->get( 'errors', [] ), $error ); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|