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
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 include_once( 'kernel/classes/ezdatatype.php' );
00045 include_once( 'lib/ezutils/classes/ezintegervalidator.php' );
00046 include_once( 'kernel/common/i18n.php' );
00047
00048 define( 'EZ_DATATYPESTRING_STRING', 'ezstring' );
00049 define( 'EZ_DATATYPESTRING_MAX_LEN_FIELD', 'data_int1' );
00050 define( 'EZ_DATATYPESTRING_MAX_LEN_VARIABLE', '_ezstring_max_string_length_' );
00051 define( "EZ_DATATYPESTRING_DEFAULT_STRING_FIELD", "data_text1" );
00052 define( "EZ_DATATYPESTRING_DEFAULT_STRING_VARIABLE", "_ezstring_default_value_" );
00053
00054 class eZStringType extends eZDataType
00055 {
00056
00057
00058
00059 function eZStringType()
00060 {
00061 $this->eZDataType( EZ_DATATYPESTRING_STRING, ezi18n( 'kernel/classes/datatypes', 'Text line', 'Datatype name' ),
00062 array( 'serialize_supported' => true,
00063 'object_serialize_map' => array( 'data_text' => 'text' ) ) );
00064 $this->MaxLenValidator = new eZIntegerValidator();
00065 }
00066
00067
00068
00069
00070 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00071 {
00072 if ( $currentVersion != false )
00073 {
00074
00075
00076
00077 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
00078 $contentObjectAttribute->setAttribute( "data_text", $dataText );
00079 }
00080 else
00081 {
00082 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
00083 $default = $contentClassAttribute->attribute( "data_text1" );
00084 if ( $default !== "" )
00085 {
00086 $contentObjectAttribute->setAttribute( "data_text", $default );
00087 }
00088 }
00089 }
00090
00091
00092
00093
00094 function validateStringHTTPInput( $data, &$contentObjectAttribute, &$classAttribute )
00095 {
00096 $maxLen = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_LEN_FIELD );
00097 $textCodec =& eZTextCodec::instance( false );
00098 if ( $textCodec->strlen( $data ) > $maxLen and
00099 $maxLen > 0 )
00100 {
00101 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00102 'The input text is too long. The maximum number of characters allowed is %1.' ),
00103 $maxLen );
00104 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00105 }
00106 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00107 }
00108
00109
00110
00111
00112
00113 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00114 {
00115 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00116 {
00117 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00118 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00119
00120 if ( $data == "" )
00121 {
00122 if ( !$classAttribute->attribute( 'is_information_collector' ) and
00123 $contentObjectAttribute->validateIsRequired() )
00124 {
00125 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00126 'Input required.' ) );
00127 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00128 }
00129 }
00130 else
00131 {
00132 return $this->validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute );
00133 }
00134 }
00135 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00136 }
00137
00138
00139
00140
00141 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00142 {
00143 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00144 {
00145 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00146 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00147
00148 if ( $data == "" )
00149 {
00150 if ( $contentObjectAttribute->validateIsRequired() )
00151 {
00152 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00153 'Input required.' ) );
00154 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00155 }
00156 else
00157 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00158 }
00159 else
00160 {
00161 return $this->validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute );
00162 }
00163 }
00164 else
00165 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00166 }
00167
00168
00169
00170
00171 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00172 {
00173 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00174 {
00175 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00176 $contentObjectAttribute->setAttribute( 'data_text', $data );
00177 return true;
00178 }
00179 return false;
00180 }
00181
00182
00183
00184
00185 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute )
00186 {
00187 if ( $http->hasPostVariable( $base . "_ezstring_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
00188 {
00189 $dataText = $http->postVariable( $base . "_ezstring_data_text_" . $contentObjectAttribute->attribute( "id" ) );
00190 $collectionAttribute->setAttribute( 'data_text', $dataText );
00191 return true;
00192 }
00193 return false;
00194 }
00195
00196
00197
00198
00199
00200 function storeObjectAttribute( &$attribute )
00201 {
00202 }
00203
00204
00205
00206
00207
00208 function isSimpleStringInsertionSupported()
00209 {
00210 return true;
00211 }
00212
00213
00214
00215
00216
00217 function insertSimpleString( &$object, $objectVersion, $objectLanguage,
00218 &$objectAttribute, $string,
00219 &$result )
00220 {
00221 $result = array( 'errors' => array(),
00222 'require_storage' => true );
00223 $objectAttribute->setContent( $string );
00224 $objectAttribute->setAttribute( 'data_text', $string );
00225 return true;
00226 }
00227
00228 function storeClassAttribute( &$attribute, $version )
00229 {
00230 }
00231
00232 function storeDefinedClassAttribute( &$attribute )
00233 {
00234 }
00235
00236
00237
00238
00239 function validateClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00240 {
00241 $maxLenName = $base . EZ_DATATYPESTRING_MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' );
00242 if ( $http->hasPostVariable( $maxLenName ) )
00243 {
00244 $maxLenValue = $http->postVariable( $maxLenName );
00245 $maxLenValue = str_replace(" ", "", $maxLenValue );
00246 if( ( $maxLenValue == "" ) || ( $maxLenValue == 0 ) )
00247 {
00248 $maxLenValue = 0;
00249 $http->setPostVariable( $maxLenName, $maxLenValue );
00250 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00251 }
00252 else
00253 {
00254 $this->MaxLenValidator->setRange( 1, false );
00255 return $this->MaxLenValidator->validate( $maxLenValue );
00256 }
00257 }
00258 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00259 }
00260
00261
00262
00263
00264 function fixupClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00265 {
00266 $maxLenName = $base . EZ_DATATYPESTRING_MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' );
00267 if ( $http->hasPostVariable( $maxLenName ) )
00268 {
00269 $maxLenValue = $http->postVariable( $maxLenName );
00270 $this->MaxLenValidator->setRange( 1, false );
00271 $maxLenValue = $this->MaxLenValidator->fixup( $maxLenValue );
00272 $http->setPostVariable( $maxLenName, $maxLenValue );
00273 }
00274 }
00275
00276
00277
00278
00279 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00280 {
00281 $maxLenName = $base . EZ_DATATYPESTRING_MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' );
00282 $defaultValueName = $base . EZ_DATATYPESTRING_DEFAULT_STRING_VARIABLE . $classAttribute->attribute( 'id' );
00283 if ( $http->hasPostVariable( $maxLenName ) )
00284 {
00285 $maxLenValue = $http->postVariable( $maxLenName );
00286 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_LEN_FIELD, $maxLenValue );
00287 }
00288 if ( $http->hasPostVariable( $defaultValueName ) )
00289 {
00290 $defaultValueValue = $http->postVariable( $defaultValueName );
00291
00292 $classAttribute->setAttribute( EZ_DATATYPESTRING_DEFAULT_STRING_FIELD, $defaultValueValue );
00293 }
00294 return true;
00295 }
00296
00297
00298
00299
00300 function &objectAttributeContent( &$contentObjectAttribute )
00301 {
00302 return $contentObjectAttribute->attribute( 'data_text' );
00303 }
00304
00305
00306
00307
00308 function metaData( &$contentObjectAttribute )
00309 {
00310 return $contentObjectAttribute->attribute( 'data_text' );
00311 }
00312
00313
00314
00315
00316 function toString( $contentObjectAttribute )
00317 {
00318 return $contentObjectAttribute->attribute( 'data_text' );
00319 }
00320
00321 function fromString( &$contentObjectAttribute, $string )
00322 {
00323 return $contentObjectAttribute->setAttribute( 'data_text', $string );
00324 }
00325
00326
00327
00328
00329
00330 function title( &$contentObjectAttribute )
00331 {
00332 return $contentObjectAttribute->attribute( 'data_text' );
00333 }
00334
00335 function hasObjectAttributeContent( &$contentObjectAttribute )
00336 {
00337 return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != '';
00338 }
00339
00340
00341
00342
00343 function isIndexable()
00344 {
00345 return true;
00346 }
00347
00348
00349
00350
00351 function isInformationCollector()
00352 {
00353 return true;
00354 }
00355
00356
00357
00358
00359 function sortKey( &$contentObjectAttribute )
00360 {
00361 include_once( 'lib/ezi18n/classes/ezchartransform.php' );
00362 $trans =& eZCharTransform::instance();
00363 return $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ), 'lowercase' );
00364 }
00365
00366
00367
00368
00369 function sortKeyType()
00370 {
00371 return 'string';
00372 }
00373
00374
00375
00376
00377 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00378 {
00379 $maxLength = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_LEN_FIELD );
00380 $defaultString = $classAttribute->attribute( EZ_DATATYPESTRING_DEFAULT_STRING_FIELD );
00381 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'max-length', $maxLength ) );
00382 if ( $defaultString )
00383 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'default-string', $defaultString ) );
00384 else
00385 $attributeParametersNode->appendChild( eZDOMDocument::createElementNode( 'default-string' ) );
00386 }
00387
00388
00389
00390
00391 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00392 {
00393 $maxLength = $attributeParametersNode->elementTextContentByName( 'max-length' );
00394 $defaultString = $attributeParametersNode->elementTextContentByName( 'default-string' );
00395 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_LEN_FIELD, $maxLength );
00396 $classAttribute->setAttribute( EZ_DATATYPESTRING_DEFAULT_STRING_FIELD, $defaultString );
00397 }
00398
00399
00400
00401
00402 function diff( $old, $new, $options = false )
00403 {
00404 include_once( 'lib/ezdiff/classes/ezdiff.php' );
00405 $diff = new eZDiff();
00406 $diff->setDiffEngineType( $diff->engineType( 'text' ) );
00407 $diff->initDiffEngine();
00408 $diffObject = $diff->diff( $old->content(), $new->content() );
00409 return $diffObject;
00410 }
00411
00412
00413
00414 var $MaxLenValidator;
00415 }
00416
00417 eZDataType::register( EZ_DATATYPESTRING_STRING, 'ezstringtype' );
00418
00419 ?>