/
class.event.section.php
773 lines (669 loc) · 29.2 KB
/
class.event.section.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<?php
/**
* @package events
*/
/**
* The `SectionEvent` class provides methods required to save
* data entered on the frontend to a corresponding Symphony section.
*
* @since Symphony 2.3.1
* @link http://getsymphony.com/learn/concepts/view/events/
*/
abstract class SectionEvent extends Event
{
/**
* An associative array of results from the filters that have run
* on this event.
* @var array
*/
public $filter_results = array();
/**
* An associative array of errors from the filters that have run
* on this event.
* @var array
*/
public $filter_errors = array();
/**
* This method will construct XML that represents the result of
* an Event filter.
*
* @param string $name
* The name of the filter
* @param string $status
* The status of the filter, either passed or failed.
* @param XMLElement|string $message
* Optionally, an XMLElement or string to be appended to this
* `<filter>` element. XMLElement allows for more complex return
* types.
* @param array $attributes
* An associative array of additional attributes to add to this
* `<filter>` element
* @return XMLElement
*/
public static function buildFilterElement($name, $status, $message = null, array $attributes = null)
{
$filter = new XMLElement('filter', (!$message || is_object($message) ? null : $message), array('name' => $name, 'status' => $status));
if ($message instanceof XMLElement) {
$filter->appendChild($message);
}
if (is_array($attributes)) {
$filter->setAttributeArray($attributes);
}
return $filter;
}
/**
* Appends errors generated from fields during the execution of an Event
*
* @param XMLElement $result
* @param array $fields
* @param array $errors
* @param object $post_values
* @throws Exception
* @return XMLElement
*/
public static function appendErrors(XMLElement $result, array $fields, $errors, $post_values)
{
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::ENTRY_ERRORS
)));
foreach ($errors as $field_id => $message) {
$field = FieldManager::fetch($field_id);
// Do a little bit of a check for files so that we can correctly show
// whether they are 'missing' or 'invalid'. If it's missing, then we
// want to remove the data so `__reduceType` will correctly resolve to
// missing instead of invalid.
// @see https://github.com/symphonists/s3upload_field/issues/17
if (isset($_FILES['fields']['error'][$field->get('element_name')])) {
$upload = $_FILES['fields']['error'][$field->get('element_name')];
if ($upload === UPLOAD_ERR_NO_FILE) {
unset($fields[$field->get('element_name')]);
}
}
if (is_array($fields[$field->get('element_name')])) {
$type = array_reduce($fields[$field->get('element_name')], array('SectionEvent', '__reduceType'));
} else {
$type = ($fields[$field->get('element_name')] == '') ? 'missing' : 'invalid';
}
$error = self::createError($field, $type, $message);
$result->appendChild($error);
}
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return $result;
}
/**
* Given a Field instance, the type of error, and the message, this function
* creates an XMLElement node so that it can be added to the `?debug` for the
* Event
*
* @since Symphony 2.5.0
* @param Field $field
* @param string $type
* At the moment 'missing' or 'invalid' accepted
* @param string $message
* @return XMLElement
*/
public static function createError(Field $field, $type, $message = null)
{
$error = new XMLElement($field->get('element_name'), null, array(
'label' => General::sanitize($field->get('label')),
'type' => $type,
'message-id' => ($type === 'missing') ? EventMessages::FIELD_MISSING : EventMessages::FIELD_INVALID,
'message' => General::sanitize($message)
));
return $error;
}
/**
* This function searches the `$haystack` for the given `$needle`,
* where the needle is a string representation of where the desired
* value exists in the `$haystack` array. For example `fields[name]`
* would look in the `$haystack` for the key of `fields` that has the
* key `name` and return the value.
*
* @param string $needle
* The needle, ie. `fields[name]`.
* @param array $haystack
* Associative array to find the needle, ie.
* `array('fields' => array(
* 'name' => 'Bob',
* 'age' => '10'
* ))`
* @param string $default
* If the `$needle` is not found, return this value. Defaults to null.
* @param boolean $discard_field_name
* When matches are found in the `$haystack`, they are added to results
* array. This parameter defines if this should be an associative array
* or just an array of the matches. Used in conjunction with `$collapse`
* @param boolean $collapse
* If multiple values are found, this will cause them to be reduced
* to single string with ' ' as the separator. Defaults to true.
* @return string|array
*/
public static function replaceFieldToken($needle, $haystack, $default = null, $discard_field_name = true, $collapse = true)
{
if (preg_match('/^(fields\[[^\]]+\],?)+$/i', $needle)) {
$parts = preg_split('/\,/i', $needle, -1, PREG_SPLIT_NO_EMPTY);
$parts = array_map('trim', $parts);
$stack = array();
foreach ($parts as $p) {
$field = str_replace(array('fields[', ']'), '', $p);
($discard_field_name ? $stack[] = $haystack[$field] : $stack[$field] = $haystack[$field]);
}
if (is_array($stack) && !empty($stack)) {
return $collapse ? implode(' ', $stack) : $stack;
} else {
$needle = null;
}
}
$needle = trim($needle);
if (empty($needle)) {
return $default;
} else {
return $needle;
}
}
/**
* Helper method to determine if a field is missing, or if the data
* provided was invalid. Used in conjunction with `array_reduce`.
*
* @param array $a,
* @param array $b
* @return string
* 'missing' or 'invalid'
*/
public function __reduceType($a, $b)
{
if (is_array($b)) {
return array_reduce($b, array('SectionEvent', '__reduceType'));
}
return (strlen(trim($b)) === 0) ? 'missing' : 'invalid';
}
/**
* This function will process the core Filters, Admin Only and Expect
* Multiple, before invoking the `__doit` function, which actually
* processes the Event. Once the Event has executed, this function will
* determine if the user should be redirected to a URL, or to just return
* the XML.
*
* @throws Exception
* @return XMLElement|void
* If `$_REQUEST{'redirect']` is set, and the Event executed successfully,
* the user will be redirected to the given location. If `$_REQUEST['redirect']`
* is not set, or the Event encountered errors, an XMLElement of the Event
* result will be returned.
*/
public function execute()
{
if (!isset($this->eParamFILTERS) || !is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
$result = new XMLElement($this->ROOTELEMENT);
if (in_array('admin-only', $this->eParamFILTERS) && !Symphony::Engine()->isLoggedIn()) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::ENTRY_ERRORS
)));
$result->appendChild(self::buildFilterElement('admin-only', 'failed'));
return $result;
}
$entry_id = $position = $fields = null;
$post = General::getPostData();
$success = true;
if (!is_array($post['fields'])) {
$post['fields'] = array();
}
if (in_array('expect-multiple', $this->eParamFILTERS)) {
foreach ($post['fields'] as $position => $fields) {
if (isset($post['id'][$position]) && is_numeric($post['id'][$position])) {
$entry_id = $post['id'][$position];
} else {
$entry_id = null;
}
$entry = new XMLElement('entry', null, array('position' => $position));
// Reset errors for each entry execution
$this->filter_results = $this->filter_errors = array();
// Ensure that we are always dealing with an array.
if (!is_array($fields)) {
$fields = array();
}
// Execute the event for this entry
if (!$this->__doit($fields, $entry, $position, $entry_id)) {
$success = false;
}
$result->appendChild($entry);
}
} else {
$fields = $post['fields'];
if (isset($post['id']) && is_numeric($post['id'])) {
$entry_id = $post['id'];
}
$success = $this->__doit($fields, $result, null, $entry_id);
}
if ($success && isset($_REQUEST['redirect'])) {
redirect($_REQUEST['redirect']);
}
return $result;
}
/**
* This function does the bulk of processing the Event, from running the delegates
* to validating the data and eventually saving the data into Symphony. The result
* of the Event is returned via the `$result` parameter.
*
* @param array $fields
* An array of $_POST data, to process and add/edit an entry.
* @param XMLElement $result
* The XMLElement contains the result of the Event, it is passed by
* reference.
* @param integer $position
* When the Expect Multiple filter is added, this event should expect
* to deal with adding (or editing) multiple entries at once.
* @param integer $entry_id
* If this Event is editing an existing entry, that Entry ID will
* be passed to this function.
* @throws Exception
* @return XMLElement
* The result of the Event
*/
public function __doit(array $fields = array(), XMLElement &$result, $position = null, $entry_id = null)
{
$post_values = new XMLElement('post-values');
if (!is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
// Check to see if the Section of this Event is valid.
if (!$section = SectionManager::fetch($this->getSource())) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('The Section, %s, could not be found.', array($this->getSource())), array(
'message-id' => EventMessages::SECTION_MISSING
)));
return false;
}
// Create the post data element
if (!empty($fields)) {
General::array_to_xml($post_values, $fields, true);
}
// If the EventPreSaveFilter fails, return early
if ($this->processPreSaveFilters($result, $fields, $post_values, $entry_id) === false) {
return false;
}
// If the `$entry_id` is provided, check to see if it exists.
// @todo If this was moved above PreSaveFilters, we can pass the
// Entry object to the delegate meaning extensions don't have to
// do that step.
if (isset($entry_id)) {
$entry = EntryManager::fetch($entry_id);
$entry = $entry[0];
if (!is_object($entry)) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('The Entry, %s, could not be found.', array($entry_id)), array(
'message-id' => EventMessages::ENTRY_MISSING
)));
return false;
}
// `$entry_id` wasn't provided, create a new Entry object.
} else {
$entry = EntryManager::create();
$entry->set('section_id', $this->getSource());
}
// Validate the data. `$entry->checkPostData` loops over all fields calling
// their `checkPostFieldData` function. If the return of the function is
// `Entry::__ENTRY_FIELD_ERROR__` then abort the event and add the error
// messages to the `$result`.
if (Entry::__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, ($entry->get('id') ? true : false))) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
// If the data is good, process the data, almost ready to save it to the
// Database. If processing fails, abort the event and display the errors
} elseif (Entry::__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, ($entry->get('id') ? true : false))) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
// Data is checked, data has been processed, by trying to save the
// Entry caused an error to occur, so abort and return.
} elseif ($entry->commit() === false) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.'), array(
'message-id' => EventMessages::ENTRY_UNKNOWN
)));
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return false;
// Entry was created, add the good news to the return `$result`
} else {
$result->setAttributeArray(array(
'result' => 'success',
'type' => (isset($entry_id) ? 'edited' : 'created'),
'id' => $entry->get('id')
));
if (isset($entry_id)) {
$result->appendChild(new XMLElement('message', __('Entry edited successfully.'), array(
'message-id' => EventMessages::ENTRY_EDITED_SUCCESS
)));
} else {
$result->appendChild(new XMLElement('message', __('Entry created successfully.'), array(
'message-id' => EventMessages::ENTRY_CREATED_SUCCESS
)));
}
}
// PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
$result = $this->processSendMailFilter($result, $_POST['send-email'], $fields, $section, $entry);
}
$result = $this->processPostSaveFilters($result, $fields, $entry);
$result = $this->processFinalSaveFilters($result, $fields, $entry);
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return true;
}
/**
* Processes all extensions attached to the `EventPreSaveFilter` delegate
*
* @uses EventPreSaveFilter
*
* @param XMLElement $result
* @param array $fields
* @param XMLElement $post_values
* @param integer $entry_id
* @return boolean
*/
protected function processPreSaveFilters(XMLElement $result, array &$fields, XMLElement &$post_values, $entry_id = null)
{
$can_proceed = true;
/**
* Prior to saving entry from the front-end. This delegate will
* force the Event to terminate if it populates the `$filter_results`
* array. All parameters are passed by reference.
*
* @delegate EventPreSaveFilter
* @param string $context
* '/frontend/'
* @param array $fields
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
* @param XMLElement $post_values
* @param integer $entry_id
* If editing an entry, this parameter will be an integer,
* otherwise null.
*/
Symphony::ExtensionManager()->notifyMembers(
'EventPreSaveFilter',
'/frontend/',
array(
'fields' => &$fields,
'event' => &$this,
'messages' => &$this->filter_results,
'post_values' => &$post_values,
'entry_id' => $entry_id
)
);
// Logic taken from `event.section.php` to fail should any `$this->filter_results`
// be returned. This delegate can cause the event to exit early.
if (is_array($this->filter_results) && !empty($this->filter_results)) {
$can_proceed = true;
foreach ($this->filter_results as $fr) {
list($name, $status, $message, $attributes) = array_pad($fr, 4, null);
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
if ($status === false) {
$can_proceed = false;
}
}
if ($can_proceed !== true) {
$result->appendChild($post_values);
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::FILTER_FAILED
)));
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $can_proceed;
}
/**
* Processes all extensions attached to the `EventPostSaveFilter` delegate
*
* @uses EventPostSaveFilter
*
* @param XMLElement $result
* @param array $fields
* @param Entry $entry
* @return XMLElement
*/
protected function processPostSaveFilters(XMLElement $result, array $fields, Entry $entry = null)
{
/**
* After saving entry from the front-end. This delegate will not force
* the Events to terminate if it populates the `$filter_results` array.
* Provided with references to this object, the `$_POST` data and also
* the error array
*
* @delegate EventPostSaveFilter
* @param string $context
* '/frontend/'
* @param integer $entry_id
* @param array $fields
* @param Entry $entry
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
*/
Symphony::ExtensionManager()->notifyMembers('EventPostSaveFilter', '/frontend/', array(
'entry_id' => $entry->get('id'),
'fields' => $fields,
'entry' => $entry,
'event' => &$this,
'messages' => &$this->filter_results
));
if (is_array($this->filter_results) && !empty($this->filter_results)) {
foreach ($this->filter_results as $fr) {
list($name, $status, $message, $attributes) = $fr;
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $result;
}
/**
* Processes all extensions attached to the `EventFinalSaveFilter` delegate
*
* @uses EventFinalSaveFilter
*
* @param XMLElement $result
* @param array $fields
* @param Entry $entry
* @return XMLElement
*/
protected function processFinalSaveFilters(XMLElement $result, array $fields, Entry $entry = null)
{
/**
* This delegate that lets extensions know the final status of the
* current Event. It is triggered when everything has processed correctly.
* The `$messages` array contains the results of the previous filters that
* have executed, and the `$errors` array contains any errors that have
* occurred as a result of this delegate. These errors cannot stop the
* processing of the Event, as that has already been done.
*
*
* @delegate EventFinalSaveFilter
* @param string $context
* '/frontend/'
* @param array $fields
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
* @param array $errors
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
* @param Entry $entry
*/
Symphony::ExtensionManager()->notifyMembers('EventFinalSaveFilter', '/frontend/', array(
'fields' => $fields,
'event' => $this,
'messages' => $this->filter_results,
'errors' => &$this->filter_errors,
'entry' => $entry
));
if (is_array($this->filter_errors) && !empty($this->filter_errors)) {
foreach ($this->filter_errors as $fr) {
list($name, $status, $message, $attributes) = $fr;
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $result;
}
/**
* This function handles the Send Mail filter which will send an email
* to each specified recipient informing them that an Entry has been
* created.
*
* @param XMLElement $result
* The XMLElement of the XML that is going to be returned as part
* of this event to the page.
* @param array $send_email
* Associative array of `send-mail` parameters.* Associative array of `send-mail` parameters.
* @param array $fields
* Array of post data to extract the values from
* @param Section $section
* This current Entry that has just been updated or created
* @param Entry $entry
* @throws Exception
* @return XMLElement
* The modified `$result` with the results of the filter.
*/
public function processSendMailFilter(XMLElement $result, array $send_email, array &$fields, Section $section, Entry $entry)
{
$fields['recipient'] = self::replaceFieldToken($send_email['recipient'], $fields);
$fields['recipient'] = preg_split('/\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY);
$fields['recipient'] = array_map('trim', $fields['recipient']);
$fields['subject'] = self::replaceFieldToken($send_email['subject'], $fields, __('[Symphony] A new entry was created on %s', array(Symphony::Configuration()->get('sitename', 'general'))));
$fields['body'] = self::replaceFieldToken($send_email['body'], $fields, null, false, false);
$fields['sender-email'] = self::replaceFieldToken($send_email['sender-email'], $fields);
$fields['sender-name'] = self::replaceFieldToken($send_email['sender-name'], $fields);
$fields['reply-to-name'] = self::replaceFieldToken($send_email['reply-to-name'], $fields);
$fields['reply-to-email'] = self::replaceFieldToken($send_email['reply-to-email'], $fields);
$edit_link = SYMPHONY_URL . '/publish/' . $section->get('handle') . '/edit/' . $entry->get('id').'/';
$language = Symphony::Configuration()->get('lang', 'symphony');
$template_path = Event::getNotificationTemplate($language);
$body = sprintf(file_get_contents($template_path), $section->get('name'), $edit_link);
if (is_array($fields['body'])) {
foreach ($fields['body'] as $field_handle => $value) {
$body .= "// $field_handle" . PHP_EOL . $value . PHP_EOL . PHP_EOL;
}
} else {
$body .= $fields['body'];
}
// Loop over all the recipients and attempt to send them an email
// Errors will be appended to the Event XML
$errors = array();
foreach ($fields['recipient'] as $recipient) {
$author = AuthorManager::fetchByUsername($recipient);
if (empty($author)) {
$errors['recipient'][$recipient] = __('Recipient not found');
continue;
}
$email = Email::create();
// Huib: Exceptions are also thrown in the settings functions, not only in the send function.
// Those Exceptions should be caught too.
try {
$email->recipients = array(
$author->get('first_name') => $author->get('email')
);
if ($fields['sender-name'] != null) {
$email->sender_name = $fields['sender-name'];
}
if ($fields['sender-email'] != null) {
$email->sender_email_address = $fields['sender-email'];
}
if ($fields['reply-to-name'] != null) {
$email->reply_to_name = $fields['reply-to-name'];
}
if ($fields['reply-to-email'] != null) {
$email->reply_to_email_address = $fields['reply-to-email'];
}
$email->text_plain = str_replace('<!-- RECIPIENT NAME -->', $author->get('first_name'), $body);
$email->subject = $fields['subject'];
$email->send();
} catch (EmailValidationException $e) {
$errors['address'][$author->get('email')] = $e->getMessage();
// The current error array does not permit custom tags.
// Therefore, it is impossible to set a "proper" error message.
// Will return the failed email address instead.
} catch (EmailGatewayException $e) {
$errors['gateway'][$author->get('email')] = $e->getMessage();
// Because we don't want symphony to break because it can not send emails,
// all exceptions are logged silently.
// Any custom event can change this behaviour.
} catch (EmailException $e) {
$errors['email'][$author->get('email')] = $e->getMessage();
}
}
// If there were errors, output them to the event
if (!empty($errors)) {
$xml = self::buildFilterElement('send-email', 'failed');
foreach ($errors as $type => $messages) {
$xType = new XMLElement('error');
$xType->setAttribute('error-type', $type);
foreach ($messages as $recipient => $message) {
$xType->appendChild(
new XMLElement('message', General::wrapInCDATA($message), array(
'recipient' => $recipient
))
);
}
$xml->appendChild($xType);
}
$result->appendChild($xml);
} else {
$result->appendChild(
self::buildFilterElement('send-email', 'passed')
);
}
return $result;
}
}
/**
* Basic lookup class for Event messages, allows for frontend developers
* to localise and change event messages without relying on string
* comparision.
*
* @since Symphony 2.4
*/
class EventMessages
{
const UNKNOWN_ERROR = 0;
const ENTRY_CREATED_SUCCESS = 100;
const ENTRY_EDITED_SUCCESS = 101;
const ENTRY_ERRORS = 102;
const ENTRY_MISSING = 103;
const ENTRY_NOT_UNIQUE = 104;
const SECTION_MISSING = 200;
const FIELD_MISSING = 301;
const FIELD_INVALID = 302;
const FIELD_NOT_UNIQUE = 303;
const FILTER_FAILED = 400;
const SECURITY_XSRF = 500;
}