function validateInput($http, $base, $contentObjectAttribute) { $contentObjectID = $contentObjectAttribute->attribute('contentobject_id'); $contentObjectAttributeID = $contentObjectAttribute->attribute('id'); $contentObjectAttributeVersion = $contentObjectAttribute->attribute('version'); if ($http->hasPostVariable($base . '_data_text_' . $contentObjectAttributeID)) { $data = $http->postVariable($base . '_data_text_' . $contentObjectAttributeID); // Set original input to a global variable $originalInput = 'originalInput_' . $contentObjectAttributeID; $GLOBALS[$originalInput] = $data; // Set input valid true to a global variable $isInputValid = 'isInputValid_' . $contentObjectAttributeID; $GLOBALS[$isInputValid] = true; $text = $data; $text = preg_replace('/\\r/', '', $text); $text = preg_replace('/\\t/', ' ', $text); // first empty paragraph $text = preg_replace('/^\\n/', '<p></p>', $text); eZDebugSetting::writeDebug('kernel-datatype-ezxmltext', $text, 'eZSimplifiedXMLInput::validateInput text'); $parser = new eZSimplifiedXMLInputParser($contentObjectID, true, eZXMLInputParser::ERROR_ALL, true); $document = $parser->process($text); if (!is_object($document)) { $GLOBALS[$isInputValid] = false; $errorMessage = implode(' ', $parser->getMessages()); $contentObjectAttribute->setValidationError($errorMessage); return eZInputValidator::STATE_INVALID; } if ($contentObjectAttribute->validateIsRequired()) { $root = $document->documentElement; if (!$root->hasChildNodes()) { $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Content required')); return eZInputValidator::STATE_INVALID; } } $contentObjectAttribute->setValidationLog($parser->getMessages()); $xmlString = eZXMLTextType::domString($document); $urlIDArray = $parser->getUrlIDArray(); if (count($urlIDArray) > 0) { $this->updateUrlObjectLinks($contentObjectAttribute, $urlIDArray); } $contentObject = $contentObjectAttribute->attribute('object'); $contentObject->appendInputRelationList($parser->getRelatedObjectIDArray(), eZContentObject::RELATION_EMBED); $contentObject->appendInputRelationList($parser->getLinkedObjectIDArray(), eZContentObject::RELATION_LINK); $contentObjectAttribute->setAttribute('data_text', $xmlString); return eZInputValidator::STATE_ACCEPTED; } return eZInputValidator::STATE_ACCEPTED; }
private function processXmlTextData($xml, $attribute) { $parser = new eZSimplifiedXMLInputParser($this->object->attribute('id')); $parser->ParseLineBreaks = true; $xml = $parser->process($xml); $xml = eZXMLTextType::domString($xml); $urlIdArray = $parser->getUrlIDArray(); if (count($urlIdArray) > 0) { eZSimplifiedXMLInput::updateUrlObjectLinks($attribute, $urlIdArray); } return $xml; }