00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 include_once( 'kernel/classes/datatypes/ezxmltext/ezxmlinputhandler.php' );
00033 include_once( 'kernel/classes/datatypes/ezurl/ezurlobjectlink.php' );
00034 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00035 include_once( 'lib/ezutils/classes/ezini.php' );
00036
00037 class eZSimplifiedXMLInput extends eZXMLInputHandler
00038 {
00039 function eZSimplifiedXMLInput( &$xmlData, $aliasedType, $contentObjectAttribute )
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 $this->eZXMLInputHandler( $xmlData, $aliasedType, $contentObjectAttribute );
00053
00054 $this->IsInputValid = true;
00055 $this->ContentObjectAttribute = $contentObjectAttribute;
00056
00057 $contentIni =& eZINI::instance( 'content.ini' );
00058
00059
00060
00061
00062
00063
00064
00065
00066 }
00067
00068
00069
00070
00071 function updateUrlObjectLinks( $contentObjectAttribute, $urlIDArray )
00072 {
00073 $objectAttributeID = $contentObjectAttribute->attribute( "id" );
00074 $objectAttributeVersion = $contentObjectAttribute->attribute('version');
00075
00076 foreach( $urlIDArray as $urlID )
00077 {
00078 $linkObjectLink = eZURLObjectLink::fetch( $urlID, $objectAttributeID, $objectAttributeVersion );
00079 if ( $linkObjectLink == null )
00080 {
00081 $linkObjectLink = eZURLObjectLink::create( $urlID, $objectAttributeID, $objectAttributeVersion );
00082 $linkObjectLink->store();
00083 }
00084 }
00085 }
00086
00087
00088
00089
00090
00091 function validateInput( &$http, $base, &$contentObjectAttribute )
00092 {
00093 $contentObjectID = $contentObjectAttribute->attribute( "contentobject_id" );
00094 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
00095 $contentObjectAttributeVersion = $contentObjectAttribute->attribute('version');
00096 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttributeID ) )
00097 {
00098 $data = $http->postVariable( $base . "_data_text_" . $contentObjectAttributeID );
00099
00100
00101 $originalInput = "originalInput_" . $contentObjectAttributeID;
00102 $GLOBALS[$originalInput] = $data;
00103
00104
00105 $isInputValid = "isInputValid_" . $contentObjectAttributeID;
00106 $GLOBALS[$isInputValid] = true;
00107
00108 include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php' );
00109
00110 $text = $data;
00111
00112 $text = preg_replace('/\r/', '', $text);
00113 $text = preg_replace('/\t/', ' ', $text);
00114
00115
00116 $text = preg_replace('/^\n/', '<p></p>', $text );
00117
00118 $parser = new eZSimplifiedXMLInputParser( $contentObjectID, true, EZ_XMLINPUTPARSER_SHOW_ALL_ERRORS, true );
00119 $document = $parser->process( $text );
00120
00121 if ( !is_object( $document ) )
00122 {
00123 $GLOBALS[$isInputValid] = false;
00124 $errorMessage = implode( ' ', $parser->getMessages() );
00125 $contentObjectAttribute->setValidationError( $errorMessage );
00126 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00127 }
00128
00129 if ( $contentObjectAttribute->validateIsRequired() )
00130 {
00131 $root =& $document->Root;
00132 if ( !count( $root->Children ) )
00133 {
00134 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00135 'Content required' ) );
00136 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00137 }
00138 }
00139 $contentObjectAttribute->setValidationLog( $parser->getMessages() );
00140
00141 $xmlString = eZXMLTextType::domString( $document );
00142
00143
00144 $urlIDArray = $parser->getUrlIDArray();
00145
00146 if ( count( $urlIDArray ) > 0 )
00147 {
00148 $this->updateUrlObjectLinks( $contentObjectAttribute, $urlIDArray );
00149 }
00150
00151 $contentObject =& $contentObjectAttribute->attribute( 'object' );
00152 $contentObject->appendInputRelationList( $parser->getRelatedObjectIDArray(), EZ_CONTENT_OBJECT_RELATION_EMBED );
00153 $contentObject->appendInputRelationList( $parser->getLinkedObjectIDArray(), EZ_CONTENT_OBJECT_RELATION_LINK );
00154
00155 $contentObjectAttribute->setAttribute( "data_text", $xmlString );
00156 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00157 }
00158 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00159 }
00160
00161
00162
00163
00164
00165 function &inputXML()
00166 {
00167 $contentObjectAttribute =& $this->ContentObjectAttribute;
00168 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
00169
00170 $originalInput = "originalInput_" . $contentObjectAttributeID;
00171 $isInputValid = "isInputValid_" . $contentObjectAttributeID;
00172
00173 if ( isset( $GLOBALS[$isInputValid] ) and $GLOBALS[$isInputValid] == false )
00174 {
00175 $output = $GLOBALS[$originalInput];
00176 }
00177 else
00178 {
00179 $xml = new eZXML();
00180 $dom =& $xml->domTree( $this->XMLData, array( 'CharsetConversion' => false, 'ConvertSpecialChars' => false, 'TrimWhiteSpace' => false, 'SetParentNode' => true ) );
00181
00182 include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmleditoutput.php' );
00183
00184 $editOutput = new eZSimplifiedXMLEditOutput();
00185 $output = $editOutput->performOutput( $dom );
00186
00187 if ( $dom )
00188 $dom->cleanup();
00189
00190 }
00191 return $output;
00192 }
00193
00194
00195
00196 var $IsInputValid;
00197
00198
00199 }
00200 ?>