/** * validateInput * Validates and parses input using {@link eZOEInputParser::process} * and saves data if valid. * * @param eZHTTPTool $http * @param string $base * @param eZContentObjectAttribute $contentObjectAttribute * @return int signals if status is valid or not */ function validateInput( $http, $base, $contentObjectAttribute ) { if ( !$this->isEditorEnabled() ) { $aliasedHandler = $this->attribute( 'aliased_handler' ); return $aliasedHandler->validateInput( $http, $base, $contentObjectAttribute ); } if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) ) { $text = $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ); if ( self::browserSupportsDHTMLType() === 'Trident' ) // IE { $text = str_replace( "\t", '', $text); } eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext-ezoe', $text, __METHOD__ . ' html from client' ); $parser = new eZOEInputParser(); $document = $parser->process( $text ); // Remove last empty paragraph (added in the output part) $parent = $document->documentElement; $lastChild = $parent->lastChild; while( $lastChild && $lastChild->nodeName !== 'paragraph' ) { $parent = $lastChild; $lastChild = $parent->lastChild; } if ( $lastChild && $lastChild->nodeName === 'paragraph' ) { $textChild = $lastChild->lastChild; // $textChild->textContent == " " : string(2) whitespace in Opera if ( !$textChild || ( $lastChild->childNodes->length == 1 && $textChild->nodeType == XML_TEXT_NODE && ( $textChild->textContent == " " || $textChild->textContent == ' ' || $textChild->textContent == '' || $textChild->textContent == ' ' ) ) ) { $parent->removeChild( $lastChild ); } } $oeini = eZINI::instance( 'ezoe.ini' ); $validationParameters = $contentObjectAttribute->validationParameters(); if ( !( isset( $validationParameters['skip-isRequired'] ) && $validationParameters['skip-isRequired'] === true ) && $parser->getDeletedEmbedIDArray( $oeini->variable('EditorSettings', 'ValidateEmbedObjects' ) === 'enabled' ) ) { self::$showEmbedValidationErrors = true; $contentObjectAttribute->setValidationError( ezpI18n::tr( 'design/standard/ezoe/handler', 'Some objects used in embed(-inline) tags have been deleted and are no longer available.' ) ); return eZInputValidator::STATE_INVALID; } if ( $contentObjectAttribute->validateIsRequired() ) { $root = $document->documentElement; if ( $root->childNodes->length == 0 ) { $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Content required' ) ); return eZInputValidator::STATE_INVALID; } } // Update URL-object links $urlIDArray = $parser->getUrlIDArray(); if ( !empty( $urlIDArray ) ) { self::updateUrlObjectLinks( $contentObjectAttribute, $urlIDArray ); } $contentObject = $contentObjectAttribute->attribute( 'object' ); $contentObject->appendInputRelationList( $parser->getEmbeddedObjectIDArray(), eZContentObject::RELATION_EMBED ); $contentObject->appendInputRelationList( $parser->getLinkedObjectIDArray(), eZContentObject::RELATION_LINK ); $xmlString = eZXMLTextType::domString( $document ); eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext-ezoe', $xmlString, __METHOD__ . ' generated xml' ); $contentObjectAttribute->setAttribute( 'data_text', $xmlString ); $contentObjectAttribute->setValidationLog( $parser->Messages ); return eZInputValidator::STATE_ACCEPTED; } else { return eZInputValidator::STATE_ACCEPTED; } }
/** * Set content object attributes * * @private * @param eZContentObject $object * @param array( attributeIdentifier => attributeStringValue ) $attributesValues * @return void */ private function setObjectAttributes(eZContentObject $object, array $attributesValues) { $attributes = $object->dataMap(); foreach ($attributesValues as $identifier => $value) { if (isset($attributes[$identifier])) { $attribute = $attributes[$identifier]; switch ($attribute->attribute('data_type_string')) { case 'ezimage': $arr = explode('|', trim($value)); $source = str_replace(' ', '%20', $arr[0]); if (file_exists($source)) { // Handle local files $content = $attribute->attribute('content'); $content->initializeFromFile($source, isset($arr[1]) ? $arr[1] : null); $content->store($attribute); } else { // Handle remote files $filename = 'var/cache/' . md5(microtime()) . substr($source, strrpos($source, '.')); if (!empty($source)) { if (in_array('curl', get_loaded_extensions())) { $ch = curl_init(); $out = fopen($filename, 'w'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FILE, $out); curl_exec($ch); curl_close($ch); fclose($out); } else { copy($source, $filename); } } if (file_exists($filename)) { $content = $attribute->attribute('content'); $content->initializeFromFile($filename, isset($arr[1]) ? $arr[1] : null); $content->store($attribute); unlink($filename); } } break; case 'ezxmltext': $parser = new eZOEInputParser(); $value = '<div>' . trim($value) . '</div>'; $document = $parser->process($value); $urlIDArray = $parser->getUrlIDArray(); if (count($urlIDArray) > 0) { eZOEXMLInput::updateUrlObjectLinks($attribute, $urlIDArray); } $object->appendInputRelationList($parser->getLinkedObjectIDArray(), eZContentObject::RELATION_LINK); $object->appendInputRelationList($parser->getEmbeddedObjectIDArray(), eZContentObject::RELATION_EMBED); $value = $document ? eZXMLTextType::domString($document) : null; $attribute->fromString($value); break; default: if (is_callable(array($attribute, 'fromString'))) { $attribute->fromString($value); } else { $attribute->setAttribute('data_text', $value); } } $attribute->store(); } } }