|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021 |
|
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
|
|
|
/** client/html/cms/page/contact/subparts |
|
25
|
|
|
* List of HTML sub-clients rendered within the cms page contact section |
|
26
|
|
|
* |
|
27
|
|
|
* The output of the frontend is composed of the code generated by the HTML |
|
28
|
|
|
* clients. Each HTML client can consist of serveral (or none) sub-clients |
|
29
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
|
30
|
|
|
* sub-clients can contain HTML clients themselves and therefore a |
|
31
|
|
|
* hierarchical tree of HTML clients is composed. Each HTML client creates |
|
32
|
|
|
* the output that is placed inside the container of its parent. |
|
33
|
|
|
* |
|
34
|
|
|
* At first, always the HTML code generated by the parent is printed, then |
|
35
|
|
|
* the HTML code of its sub-clients. The order of the HTML sub-clients |
|
36
|
|
|
* determines the order of the output of these sub-clients inside the parent |
|
37
|
|
|
* container. If the configured list of clients is |
|
38
|
|
|
* |
|
39
|
|
|
* array( "subclient1", "subclient2" ) |
|
40
|
|
|
* |
|
41
|
|
|
* you can easily change the order of the output by reordering the subparts: |
|
42
|
|
|
* |
|
43
|
|
|
* client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
|
44
|
|
|
* |
|
45
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
|
46
|
|
|
* |
|
47
|
|
|
* client/html/<clients>/subparts = array( "subclient1" ) |
|
48
|
|
|
* |
|
49
|
|
|
* As the clients only generates structural HTML, the layout defined via CSS |
|
50
|
|
|
* should support adding, removing or reordering content by a fluid like |
|
51
|
|
|
* design. |
|
52
|
|
|
* |
|
53
|
|
|
* @param array List of sub-client names |
|
54
|
|
|
* @since 2021.04 |
|
55
|
|
|
* @category Developer |
|
56
|
|
|
*/ |
|
57
|
|
|
private $subPartPath = 'client/html/cms/page/contact/subparts'; |
|
58
|
|
|
private $subPartNames = []; |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns the HTML code for insertion into the body. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
65
|
|
|
* @return string HTML code |
|
66
|
|
|
*/ |
|
67
|
|
|
public function body( string $uid = '' ) : string |
|
68
|
|
|
{ |
|
69
|
|
|
return ''; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the sub-client given by its name. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $type Name of the client type |
|
77
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
|
78
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface |
|
81
|
|
|
{ |
|
82
|
|
|
/** client/html/cms/page/contact/decorators/excludes |
|
83
|
|
|
* Excludes decorators added by the "common" option from the cms page contact html client |
|
84
|
|
|
* |
|
85
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
86
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
87
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
88
|
|
|
* modify what is returned to the caller. |
|
89
|
|
|
* |
|
90
|
|
|
* This option allows you to remove a decorator added via |
|
91
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
|
92
|
|
|
* around the html client. |
|
93
|
|
|
* |
|
94
|
|
|
* client/html/cms/page/contact/decorators/excludes = array( 'decorator1' ) |
|
95
|
|
|
* |
|
96
|
|
|
* This would remove the decorator named "decorator1" from the list of |
|
97
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
|
98
|
|
|
* "client/html/common/decorators/default" to the html client. |
|
99
|
|
|
* |
|
100
|
|
|
* @param array List of decorator names |
|
101
|
|
|
* @since 2021.04 |
|
102
|
|
|
* @category Developer |
|
103
|
|
|
* @see client/html/common/decorators/default |
|
104
|
|
|
* @see client/html/cms/page/contact/decorators/global |
|
105
|
|
|
* @see client/html/cms/page/contact/decorators/local |
|
106
|
|
|
*/ |
|
107
|
|
|
|
|
108
|
|
|
/** client/html/cms/page/contact/decorators/global |
|
109
|
|
|
* Adds a list of globally available decorators only to the cms page contact html client |
|
110
|
|
|
* |
|
111
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
112
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
113
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
114
|
|
|
* modify what is returned to the caller. |
|
115
|
|
|
* |
|
116
|
|
|
* This option allows you to wrap global decorators |
|
117
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
|
118
|
|
|
* |
|
119
|
|
|
* client/html/cms/page/contact/decorators/global = array( 'decorator1' ) |
|
120
|
|
|
* |
|
121
|
|
|
* This would add the decorator named "decorator1" defined by |
|
122
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
|
123
|
|
|
* |
|
124
|
|
|
* @param array List of decorator names |
|
125
|
|
|
* @since 2021.04 |
|
126
|
|
|
* @category Developer |
|
127
|
|
|
* @see client/html/common/decorators/default |
|
128
|
|
|
* @see client/html/cms/page/contact/decorators/excludes |
|
129
|
|
|
* @see client/html/cms/page/contact/decorators/local |
|
130
|
|
|
*/ |
|
131
|
|
|
|
|
132
|
|
|
/** client/html/cms/page/contact/decorators/local |
|
133
|
|
|
* Adds a list of local decorators only to the cms page contact html client |
|
134
|
|
|
* |
|
135
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
|
136
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
|
137
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
|
138
|
|
|
* modify what is returned to the caller. |
|
139
|
|
|
* |
|
140
|
|
|
* This option allows you to wrap local decorators |
|
141
|
|
|
* ("\Aimeos\Client\Html\Cms\Decorator\*") around the html client. |
|
142
|
|
|
* |
|
143
|
|
|
* client/html/cms/page/contact/decorators/local = array( 'decorator2' ) |
|
144
|
|
|
* |
|
145
|
|
|
* This would add the decorator named "decorator2" defined by |
|
146
|
|
|
* "\Aimeos\Client\Html\Cms\Decorator\Decorator2" only to the html client. |
|
147
|
|
|
* |
|
148
|
|
|
* @param array List of decorator names |
|
149
|
|
|
* @since 2021.04 |
|
150
|
|
|
* @category Developer |
|
151
|
|
|
* @see client/html/common/decorators/default |
|
152
|
|
|
* @see client/html/cms/page/contact/decorators/excludes |
|
153
|
|
|
* @see client/html/cms/page/contact/decorators/global |
|
154
|
|
|
*/ |
|
155
|
|
|
|
|
156
|
|
|
return $this->createSubClient( 'cms/page/contact/' . $type, $name ); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Modifies the cached body content to replace content based on sessions or cookies. |
|
162
|
|
|
* |
|
163
|
|
|
* @param string $content Cached content |
|
164
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
165
|
|
|
* @return string Modified body content |
|
166
|
|
|
*/ |
|
167
|
|
|
public function modifyBody( string $content, string $uid ) : string |
|
168
|
|
|
{ |
|
169
|
|
|
$content = parent::modifyBody( $content, $uid ); |
|
170
|
|
|
$token = !$this->getView()->access( ['editor', 'admin', 'super'] ) ? $this->getView()->csrf()->formfield() : ''; |
|
171
|
|
|
|
|
172
|
|
|
return $this->replaceSection( $content, $token, 'cms.page.contact.csrf' ); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Processes the input, e.g. store given values. |
|
178
|
|
|
* |
|
179
|
|
|
* A view must be available and this method doesn't generate any output |
|
180
|
|
|
* besides setting view variables if necessary. |
|
181
|
|
|
*/ |
|
182
|
|
|
public function init() |
|
183
|
|
|
{ |
|
184
|
|
|
$view = $this->getView(); |
|
185
|
|
|
|
|
186
|
|
|
$name = $view->param( 'contact/name' ); |
|
187
|
|
|
$email = $view->param( 'contact/email' ); |
|
188
|
|
|
$msg = $view->param( 'contact/message' ); |
|
189
|
|
|
$honeypot = $view->param( 'contact/url' ); |
|
190
|
|
|
|
|
191
|
|
|
if( !$honeypot && $name && $email && $msg ) |
|
192
|
|
|
{ |
|
193
|
|
|
$context = $this->getContext(); |
|
194
|
|
|
$config = $context->getConfig(); |
|
195
|
|
|
$i18n = $context->getI18n(); |
|
196
|
|
|
|
|
197
|
|
|
$toAddr = $config->get( 'resource/email/from-email' ); |
|
198
|
|
|
$toName = $config->get( 'resource/email/from-name' ); |
|
199
|
|
|
|
|
200
|
|
|
if( $toAddr ) |
|
201
|
|
|
{ |
|
202
|
|
|
$label = $context->getLocale()->getSiteItem()->getLabel(); |
|
203
|
|
|
|
|
204
|
|
|
$context->mail()->createMessage() |
|
205
|
|
|
->addTo( $toAddr, $toName ) |
|
206
|
|
|
->addFrom( $email, $name ) |
|
207
|
|
|
->setSubject( $i18n->dt( 'client', 'Your request' ) . ' - ' . $label ) |
|
208
|
|
|
->setBody( $msg ) |
|
209
|
|
|
->send(); |
|
210
|
|
|
|
|
211
|
|
|
$error = [$i18n->dt( 'client', 'Message sent successfully' )]; |
|
212
|
|
|
} |
|
213
|
|
|
else |
|
214
|
|
|
{ |
|
215
|
|
|
$error = [$i18n->dt( 'client', 'No recipient configured' )]; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
$view->pageErrorList = array_merge( $view->get( 'pageErrorList', [] ), $error ); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
parent::init(); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* Returns the list of sub-client names configured for the client. |
|
227
|
|
|
* |
|
228
|
|
|
* @return array List of HTML client names |
|
229
|
|
|
*/ |
|
230
|
|
|
protected function getSubClientNames() : array |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|