Index: branches/5.1.x/core/units/email_events/email_events_event_handler.php =================================================================== diff -u -N -r13666 -r14105 --- branches/5.1.x/core/units/email_events/email_events_event_handler.php (.../email_events_event_handler.php) (revision 13666) +++ branches/5.1.x/core/units/email_events/email_events_event_handler.php (.../email_events_event_handler.php) (revision 14105) @@ -1,6 +1,6 @@ getObject(); /* @var $object kDBItem */ + // validate email subject and body for parsing errors + $this->_validateEmailTemplate($object); + + // validate sender and recipient addresses if ($object->GetDBField('CustomSender')) { $this->_validateAddress($event, 'Sender'); } - $this->_validateAddress($event, 'Recipient'); if (!$this->Application->isDebugMode(false)) { @@ -942,17 +945,19 @@ } // process replacement tags - $minput_helper =& $this->Application->recallObject('MInputHelper'); - /* @var $minput_helper MInputHelper */ + if ( $object->GetDBField('ReplacementTagsXML') ) { + $minput_helper =& $this->Application->recallObject('MInputHelper'); + /* @var $minput_helper MInputHelper */ - $replacement_tags = Array (); - $records = $minput_helper->parseMInputXML( $object->GetDBField('ReplacementTagsXML') ); + $replacement_tags = Array (); + $records = $minput_helper->parseMInputXML( $object->GetDBField('ReplacementTagsXML') ); - foreach ($records as $record) { - $replacement_tags[ trim($record['Tag']) ] = trim($record['Replacement']); - } + foreach ($records as $record) { + $replacement_tags[ trim($record['Tag']) ] = trim($record['Replacement']); + } - $object->SetDBField('ReplacementTags', $replacement_tags ? serialize($replacement_tags) : NULL); + $object->SetDBField('ReplacementTags', $replacement_tags ? serialize($replacement_tags) : NULL); + } } /** @@ -1082,4 +1087,64 @@ echo ''; } + + /** + * Validates subject and body fields of Email template + * @param kDBItem $object + */ + function _validateEmailTemplate(&$object) + { + // 1. prepare parser and error handler + safeDefine('DBG_IGNORE_FATAL_ERRORS', 1); + + $error_handlers = $this->Application->errorHandlers; + $this->Application->errorHandlers = Array ( + Array(&$this, '_saveError'), + ); + + $this->Application->InitParser(); + $this->Application->SetVar('email_parsing_error', 0); + + // 2. parse subject + $this->Application->Parser->CompileRaw($object->GetField('Subject'), 'email_subject'); + + if ( $this->Application->GetVar('email_parsing_error') ) { + $object->SetError('Subject', 'parsing_error'); + $this->Application->SetVar('email_parsing_error', 0); // reset the error status + } + + // 3. parse body + $this->Application->Parser->CompileRaw($object->GetField('Body'), 'email_template'); + + if ( $this->Application->GetVar('email_parsing_error') ) { + $object->SetError('Body', 'parsing_error'); + } + + // 4. restore original settings + $this->Application->errorHandlers = $error_handlers; + } + + /** + * Custom error handler that saves errors during email validation + * @param string $errno + * @param string $errstr + * @param string $errfile + * @param string $errline + * @param string $errcontext + */ + function _saveError($errno, $errstr, $errfile, $errline, $errcontext) + { + if ($errno != E_USER_ERROR) { + // ignore all minor errors, except fatals from parser + return true; + } + + $this->Application->SetVar('email_parsing_error', 1); + + if ( $this->Application->isDebugMode() ) { + $this->Application->Debugger->appendHTML('Error in Email Template: ' . $errstr . ' (line: ' . $errline . ')'); + } + + return true; + } } \ No newline at end of file Index: branches/5.1.x/core/units/email_events/email_events_config.php =================================================================== diff -u -N -r13962 -r14105 --- branches/5.1.x/core/units/email_events/email_events_config.php (.../email_events_config.php) (revision 13962) +++ branches/5.1.x/core/units/email_events/email_events_config.php (.../email_events_config.php) (revision 14105) @@ -1,6 +1,6 @@ Array ( 'type' => 'string', 'formatter' => 'kMultiLanguage', 'db_type' => 'text', + 'error_msgs' => Array ('parsing_error' => '!la_error_ParsingError!'), 'required' => 1, 'default' => null ), 'Body' => Array ( 'type' => 'string', 'formatter' => 'kMultiLanguage', 'db_type' => 'longtext', + 'error_msgs' => Array ('parsing_error' => '!la_error_ParsingError!'), 'required' => 1, 'default' => null ), Index: branches/5.1.x/core/install/english.lang =================================================================== diff -u -N -r14033 -r14105 --- branches/5.1.x/core/install/english.lang (.../english.lang) (revision 14033) +++ branches/5.1.x/core/install/english.lang (.../english.lang) (revision 14105) @@ -326,6 +326,7 @@ TG9naW4gRmFpbGVk RXJyb3IgbW92aW5nIHN1YnNlY3Rpb24= Q2FuJ3QgaW5oZXJpdCB0ZW1wbGF0ZSBmcm9tIHRvcCBjYXRlZ29yeQ== + VmFsaWRhdGlvbiBlcnJvciwgcGxlYXNlIGRvdWJsZS1jaGVjayBJbi1Qb3J0YWwgdGFncw== UGFzc3dvcmRzIGRvIG5vdCBtYXRjaCE= UmVxdWlyZWQgZmllbGQoLXMpIG5vdCBmaWxsZWQ= cmVxdWlyZWQgY29sdW1ucyBtaXNzaW5n