/** * 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; } }
if ($dataType->validateIntegerHTTPInput($postVar, $attr, $classAttr) !== eZInputValidator::STATE_ACCEPTED) { throw new InvalidArgumentException($attr->validationError()); } case 'ezboolean': $attr->setAttribute('data_int', (int) $postVar); $attr->store(); break; case 'ezimage': // validation has been done by eZContentUpload $content = $attr->attribute('content'); $content->setAttribute('alternative_text', $postVar); $content->store($attr); break; case 'ezxmltext': $parser = new eZOEInputParser(); $document = $parser->process($postVar); $xmlString = eZXMLTextType::domString($document); $attr->setAttribute('data_text', $xmlString); $attr->store(); break; } } } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $newObjectID, 'version' => $uploadVersion->attribute('version'))); $newObject = eZContentObject::fetch($newObjectID); $newObjectName = $newObject->attribute('name'); $newObjectNodeID = (int) $newObject->attribute('main_node_id'); $object->addContentObjectRelation($newObjectID, $uploadVersion->attribute('version'), 0, eZContentObject::RELATION_EMBED); echo '<html><head><title>HiddenUploadFrame</title><script type="text/javascript">'; echo 'window.parent.eZOEPopupUtils.selectByEmbedId( ' . $newObjectID . ', ' . $newObjectNodeID . ', ' . json_encode($newObjectName) . ' );'; echo '</script></head><body></body></html>';
/** * Tests for EZP-21346 * @link https://jira.ez.no/browse/EZP-21346 * @dataProvider providerMixedCaseAttributes */ public function testMixedCaseAttributes($html, $xpathSel, $attrNS, $attrLocalName, $attrValue) { $parser = new eZOEInputParser(); $dom = $parser->process($html); $xpath = new DomXPath($dom); $node = $xpath->query($xpathSel)->item(0); $attr = $node->getAttributeNodeNS($attrNS, $attrLocalName); self::assertInstanceOf('DOMAttr', $attr); self::assertEquals($attrValue, $attr->value); }
<?php $return = true; $attributeId = (int) $_REQUEST['attribute_id']; $versionId = (int) $_REQUEST['version_id']; $content = $_REQUEST['data']; if ($attributeId && $versionId) { $attribute = eZContentObjectAttribute::fetch($attributeId, $versionId); switch ($attribute->attribute('data_type_string')) { case 'ezxmltext': if (eZOEXMLInput::browserSupportsDHTMLType() === 'Trident') { $content = str_replace("\t", '', $content); } $parser = new eZOEInputParser(); $document = $parser->process($content); // 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); } } $xmlString = eZXMLTextType::domString($document); $attribute->setAttribute('data_text', $xmlString);
/** * Test for issue #18220: non breaking spaces are wrongly encoded * * Check that non breaking spaces are encoded with the UTF8 character * instead of XML encoding of the HTML entity (&nbsp;) * * @group issue_18220 * @link http://issues.ez.no/18220 */ public function testNonBreakingSpaceEncoding() { $htmlData = '<p>French typography rules :</p>'; $parser = new eZOEInputParser(); $dom = $parser->process($htmlData); self::assertInstanceOf('DomDocument', $dom); $xpath = new DomXPath($dom); $paragraph = $xpath->query('//paragraph')->item(0); self::assertEquals("French typography rules :", $paragraph->textContent); }
private function createContentObject($classIdentifier, $parentNodeId, $fillMode) { $contentClass = eZContentClass::fetchByIdentifier($classIdentifier); if (!$contentClass) { throw new Exception("This content class does not exist: [" . $classIdentifier . "]"); } if (!eepValidate::validateContentNodeId($parentNodeId)) { throw new Exception("This is not an node id: [" . $parentNodeId . "]"); } // todo, in addition to "random" mode, datamap content should be // pullable from a suitable xml file; might also provide a way to dump // the framework for a content class "as xml" if ("random" == $fillMode) { $classId = eZContentClass::classIDByIdentifier($classIdentifier); $attributeList = eZContentClassAttribute::fetchListByClassID($classId); $words = explode(" ", self::fake_text); $dataSet = array(); foreach ($attributeList as $attr) { switch ($attr->DataTypeString) { default: case "ezmedia": echo "NOT YET SUPPORTED: [" . $attr->DataTypeString . "]\n"; $dataSet[$attr->Identifier] = "123"; break; case "ezkeyword": $randomKeys = array_flip(array_rand($words, 2)); $randomWords = array_intersect_key($words, $randomKeys); $dataSet[$attr->Identifier] = implode(",", $randomWords); break; case "ezstring": $randomKeys = array_flip(array_rand($words, 5)); $randomWords = array_intersect_key($words, $randomKeys); $dataSet[$attr->Identifier] = implode(" ", $randomWords); break; case "eztext": $randomKeys = array_flip(array_rand($words, 100)); $randomWords = array_intersect_key($words, $randomKeys); $dataSet[$attr->Identifier] = implode(" ", $randomWords); break; case "ezdatetime": $dataSet[$attr->Identifier] = time(); break; case "ezxmltext": $text = ""; for ($paraCount = 0; $paraCount < 5; $paraCount += 1) { $randomKeys = array_flip(array_rand($words, 60)); $randomWords = array_intersect_key($words, $randomKeys); $text .= "<p>" . implode(" ", $randomWords) . "</p>"; } $parser = new eZOEInputParser(); $document = $parser->process($text); $dataSet[$attr->Identifier] = eZXMLTextType::domString($document); break; } } $createResults = $this->create($parentNodeId, $classIdentifier, $dataSet); //echo "\nobject creation results\n"; //var_dump( $createResults ); } else { throw new Exception("Only 'random' is currently supported."); } }
$newObjectDataMap[$key]->setAttribute('data_int', (int) $http->postVariable($base)); $newObjectDataMap[$key]->store(); break; case 'ezimage': $content = $newObjectDataMap[$key]->attribute('content'); $content->setAttribute('alternative_text', trim($http->postVariable($base))); $content->store($newObjectDataMap[$key]); break; case 'ezkeyword': $newObjectDataMap[$key]->fromString($http->postVariable($base)); $newObjectDataMap[$key]->store(); break; case 'ezxmltext': $text = trim($http->postVariable($base)); $parser = new eZOEInputParser(); $document = $parser->process($text); $xmlString = eZXMLTextType::domString($document); $newObjectDataMap[$key]->setAttribute('data_text', $xmlString); $newObjectDataMap[$key]->store(); break; } } } $object->addContentObjectRelation($newObjectID, $objectVersion, 0, eZContentObject::RELATION_EMBED); echo '<html><head><title>HiddenUploadFrame</title><script type="text/javascript">'; echo 'window.parent.eZOEPopupUtils.selectByEmbedId( ' . $newObjectID . ', ' . $newObjectNodeID . ', "' . $newObjectName . '" );'; echo '</script></head><body></body></html>'; } else { echo '<html><head><title>HiddenUploadFrame</title><script type="text/javascript">'; echo 'window.parent.document.getElementById("upload_in_progress").style.display = "none";'; echo '</script></head><body><div style="position:absolute; top: 0px; left: 0px;background-color: white; width: 100%;">';
/** * 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(); } } }