[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZStringType class 4 // 5 // Created on: <16-Apr-2002 11:08:14 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZStringType ezstringtype.php 31 \ingroup eZDatatype 32 \brief A content datatype which handles text lines 33 34 It provides the functionality to work as a text line and handles 35 class definition input, object definition input and object viewing. 36 37 It uses the spare field data_text in a content object attribute for storing 38 the attribute data. 39 40 */ 41 42 include_once ( 'kernel/classes/ezdatatype.php' ); 43 include_once ( 'lib/ezutils/classes/ezintegervalidator.php' ); 44 include_once ( 'kernel/common/i18n.php' ); 45 46 define( 'EZ_DATATYPESTRING_STRING', 'ezstring' ); 47 define( 'EZ_DATATYPESTRING_MAX_LEN_FIELD', 'data_int1' ); 48 define( 'EZ_DATATYPESTRING_MAX_LEN_VARIABLE', '_ezstring_max_string_length_' ); 49 define( "EZ_DATATYPESTRING_DEFAULT_STRING_FIELD", "data_text1" ); 50 define( "EZ_DATATYPESTRING_DEFAULT_STRING_VARIABLE", "_ezstring_default_value_" ); 51 52 class eZStringType extends eZDataType 53 { 54 /*! 55 Initializes with a string id and a description. 56 */ 57 function eZStringType() 58 { 59 $this->eZDataType( EZ_DATATYPESTRING_STRING, ezi18n( 'kernel/classes/datatypes', 'Text line', 'Datatype name' ), 60 array( 'serialize_supported' => true, 61 'object_serialize_map' => array( 'data_text' => 'text' ) ) ); 62 $this->MaxLenValidator = new eZIntegerValidator(); 63 } 64 65 /*! 66 Sets the default value. 67 */ 68 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute ) 69 { 70 if ( $currentVersion != false ) 71 { 72 // $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" ); 73 // $currentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID, 74 // $currentVersion ); 75 $dataText = $originalContentObjectAttribute->attribute( "data_text" ); 76 $contentObjectAttribute->setAttribute( "data_text", $dataText ); 77 } 78 else 79 { 80 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute(); 81 $default = $contentClassAttribute->attribute( "data_text1" ); 82 if ( $default !== "" ) 83 { 84 $contentObjectAttribute->setAttribute( "data_text", $default ); 85 } 86 } 87 } 88 89 /* 90 Private method, only for using inside this class. 91 */ 92 function validateStringHTTPInput( $data, &$contentObjectAttribute, &$classAttribute ) 93 { 94 $maxLen = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_LEN_FIELD ); 95 $textCodec =& eZTextCodec::instance( false ); 96 if ( $textCodec->strlen( $data ) > $maxLen and 97 $maxLen > 0 ) 98 { 99 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 100 'The input text is too long. The maximum number of characters allowed is %1.' ), 101 $maxLen ); 102 return EZ_INPUT_VALIDATOR_STATE_INVALID; 103 } 104 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 105 } 106 107 108 /*! 109 \reimp 110 */ 111 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 112 { 113 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) ) 114 { 115 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ); 116 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 117 118 if ( $data == "" ) 119 { 120 if ( !$classAttribute->attribute( 'is_information_collector' ) and 121 $contentObjectAttribute->validateIsRequired() ) 122 { 123 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 124 'Input required.' ) ); 125 return EZ_INPUT_VALIDATOR_STATE_INVALID; 126 } 127 } 128 else 129 { 130 return $this->validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute ); 131 } 132 } 133 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 134 } 135 136 /*! 137 \reimp 138 */ 139 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 140 { 141 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) ) 142 { 143 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ); 144 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 145 146 if ( $data == "" ) 147 { 148 if ( $contentObjectAttribute->validateIsRequired() ) 149 { 150 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 151 'Input required.' ) ); 152 return EZ_INPUT_VALIDATOR_STATE_INVALID; 153 } 154 else 155 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 156 } 157 else 158 { 159 return $this->validateStringHTTPInput( $data, $contentObjectAttribute, $classAttribute ); 160 } 161 } 162 else 163 return EZ_INPUT_VALIDATOR_STATE_INVALID; 164 } 165 166 /*! 167 Fetches the http post var string input and stores it in the data instance. 168 */ 169 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 170 { 171 if ( $http->hasPostVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) ) 172 { 173 $data = $http->postVariable( $base . '_ezstring_data_text_' . $contentObjectAttribute->attribute( 'id' ) ); 174 $contentObjectAttribute->setAttribute( 'data_text', $data ); 175 return true; 176 } 177 return false; 178 } 179 180 /*! 181 Fetches the http post variables for collected information 182 */ 183 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute ) 184 { 185 if ( $http->hasPostVariable( $base . "_ezstring_data_text_" . $contentObjectAttribute->attribute( "id" ) ) ) 186 { 187 $dataText = $http->postVariable( $base . "_ezstring_data_text_" . $contentObjectAttribute->attribute( "id" ) ); 188 $collectionAttribute->setAttribute( 'data_text', $dataText ); 189 return true; 190 } 191 return false; 192 } 193 194 /*! 195 Does nothing since it uses the data_text field in the content object attribute. 196 See fetchObjectAttributeHTTPInput for the actual storing. 197 */ 198 function storeObjectAttribute( &$attribute ) 199 { 200 } 201 202 /*! 203 \reimp 204 Simple string insertion is supported. 205 */ 206 function isSimpleStringInsertionSupported() 207 { 208 return true; 209 } 210 211 /*! 212 \reimp 213 Inserts the string \a $string in the \c 'data_text' database field. 214 */ 215 function insertSimpleString( &$object, $objectVersion, $objectLanguage, 216 &$objectAttribute, $string, 217 &$result ) 218 { 219 $result = array( 'errors' => array(), 220 'require_storage' => true ); 221 $objectAttribute->setContent( $string ); 222 $objectAttribute->setAttribute( 'data_text', $string ); 223 return true; 224 } 225 226 function storeClassAttribute( &$attribute, $version ) 227 { 228 } 229 230 function storeDefinedClassAttribute( &$attribute ) 231 { 232 } 233 234 /*! 235 \reimp 236 */ 237 function validateClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 238 { 239 $maxLenName = $base . EZ_DATATYPESTRING_MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' ); 240 if ( $http->hasPostVariable( $maxLenName ) ) 241 { 242 $maxLenValue = $http->postVariable( $maxLenName ); 243 $maxLenValue = str_replace(" ", "", $maxLenValue ); 244 if( ( $maxLenValue == "" ) || ( $maxLenValue == 0 ) ) 245 { 246 $maxLenValue = 0; 247 $http->setPostVariable( $maxLenName, $maxLenValue ); 248 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 249 } 250 else 251 { 252 $this->MaxLenValidator->setRange( 1, false ); 253 return $this->MaxLenValidator->validate( $maxLenValue ); 254 } 255 } 256 return EZ_INPUT_VALIDATOR_STATE_INVALID; 257 } 258 259 /*! 260 \reimp 261 */ 262 function fixupClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 263 { 264 $maxLenName = $base . EZ_DATATYPESTRING_MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' ); 265 if ( $http->hasPostVariable( $maxLenName ) ) 266 { 267 $maxLenValue = $http->postVariable( $maxLenName ); 268 $this->MaxLenValidator->setRange( 1, false ); 269 $maxLenValue = $this->MaxLenValidator->fixup( $maxLenValue ); 270 $http->setPostVariable( $maxLenName, $maxLenValue ); 271 } 272 } 273 274 /*! 275 \reimp 276 */ 277 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute ) 278 { 279 $maxLenName = $base . EZ_DATATYPESTRING_MAX_LEN_VARIABLE . $classAttribute->attribute( 'id' ); 280 $defaultValueName = $base . EZ_DATATYPESTRING_DEFAULT_STRING_VARIABLE . $classAttribute->attribute( 'id' ); 281 if ( $http->hasPostVariable( $maxLenName ) ) 282 { 283 $maxLenValue = $http->postVariable( $maxLenName ); 284 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_LEN_FIELD, $maxLenValue ); 285 } 286 if ( $http->hasPostVariable( $defaultValueName ) ) 287 { 288 $defaultValueValue = $http->postVariable( $defaultValueName ); 289 290 $classAttribute->setAttribute( EZ_DATATYPESTRING_DEFAULT_STRING_FIELD, $defaultValueValue ); 291 } 292 return true; 293 } 294 295 /*! 296 Returns the content. 297 */ 298 function &objectAttributeContent( &$contentObjectAttribute ) 299 { 300 return $contentObjectAttribute->attribute( 'data_text' ); 301 } 302 303 /*! 304 Returns the meta data used for storing search indeces. 305 */ 306 function metaData( &$contentObjectAttribute ) 307 { 308 return $contentObjectAttribute->attribute( 'data_text' ); 309 } 310 /*! 311 \return string representation of an contentobjectattribute data for simplified export 312 313 */ 314 function toString( $contentObjectAttribute ) 315 { 316 return $contentObjectAttribute->attribute( 'data_text' ); 317 } 318 319 function fromString( &$contentObjectAttribute, $string ) 320 { 321 return $contentObjectAttribute->setAttribute( 'data_text', $string ); 322 } 323 324 325 /*! 326 Returns the content of the string for use as a title 327 */ 328 function title( &$contentObjectAttribute ) 329 { 330 return $contentObjectAttribute->attribute( 'data_text' ); 331 } 332 333 function hasObjectAttributeContent( &$contentObjectAttribute ) 334 { 335 return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != ''; 336 } 337 338 /*! 339 \reimp 340 */ 341 function isIndexable() 342 { 343 return true; 344 } 345 346 /*! 347 \reimp 348 */ 349 function isInformationCollector() 350 { 351 return true; 352 } 353 354 /*! 355 \reimp 356 */ 357 function sortKey( &$contentObjectAttribute ) 358 { 359 include_once ( 'lib/ezi18n/classes/ezchartransform.php' ); 360 $trans =& eZCharTransform::instance(); 361 return $trans->transformByGroup( $contentObjectAttribute->attribute( 'data_text' ), 'lowercase' ); 362 } 363 364 /*! 365 \reimp 366 */ 367 function sortKeyType() 368 { 369 return 'string'; 370 } 371 372 /*! 373 \reimp 374 */ 375 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode ) 376 { 377 $maxLength = $classAttribute->attribute( EZ_DATATYPESTRING_MAX_LEN_FIELD ); 378 $defaultString = $classAttribute->attribute( EZ_DATATYPESTRING_DEFAULT_STRING_FIELD ); 379 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'max-length', $maxLength ) ); 380 if ( $defaultString ) 381 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'default-string', $defaultString ) ); 382 else 383 $attributeParametersNode->appendChild( eZDOMDocument::createElementNode( 'default-string' ) ); 384 } 385 386 /*! 387 \reimp 388 */ 389 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode ) 390 { 391 $maxLength = $attributeParametersNode->elementTextContentByName( 'max-length' ); 392 $defaultString = $attributeParametersNode->elementTextContentByName( 'default-string' ); 393 $classAttribute->setAttribute( EZ_DATATYPESTRING_MAX_LEN_FIELD, $maxLength ); 394 $classAttribute->setAttribute( EZ_DATATYPESTRING_DEFAULT_STRING_FIELD, $defaultString ); 395 } 396 397 /*! 398 \reimp 399 */ 400 function diff( $old, $new, $options = false ) 401 { 402 include_once ( 'lib/ezdiff/classes/ezdiff.php' ); 403 $diff = new eZDiff(); 404 $diff->setDiffEngineType( $diff->engineType( 'text' ) ); 405 $diff->initDiffEngine(); 406 $diffObject = $diff->diff( $old->content(), $new->content() ); 407 return $diffObject; 408 } 409 410 /// \privatesection 411 /// The max len validator 412 var $MaxLenValidator; 413 } 414 415 eZDataType::register( EZ_DATATYPESTRING_STRING, 'ezstringtype' ); 416 417 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |