|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZTextType class 00004 // 00005 // Created on: <06-May-2002 20:02:55 bf> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! 00032 \class eZTextType eztexttype.php 00033 \ingroup eZDatatype 00034 \brief Stores a text area value 00035 00036 */ 00037 00038 //include_once( "kernel/classes/ezdatatype.php" ); 00039 00040 class eZTextType extends eZDataType 00041 { 00042 const DATA_TYPE_STRING = "eztext"; 00043 const COLS_FIELD = 'data_int1'; 00044 const COLS_VARIABLE = '_eztext_cols_'; 00045 00046 function eZTextType() 00047 { 00048 $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Text block", 'Datatype name' ), 00049 array( 'serialize_supported' => true, 00050 'object_serialize_map' => array( 'data_text' => 'text' ) ) ); 00051 } 00052 00053 /*! 00054 Set class attribute value for template version 00055 */ 00056 function initializeClassAttribute( $classAttribute ) 00057 { 00058 if ( $classAttribute->attribute( self::COLS_FIELD ) == null ) 00059 $classAttribute->setAttribute( self::COLS_FIELD, 10 ); 00060 $classAttribute->store(); 00061 } 00062 00063 /*! 00064 Sets the default value. 00065 */ 00066 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute ) 00067 { 00068 if ( $currentVersion != false ) 00069 { 00070 $dataText = $originalContentObjectAttribute->attribute( "data_text" ); 00071 $contentObjectAttribute->setAttribute( "data_text", $dataText ); 00072 } 00073 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00074 if ( $contentClassAttribute->attribute( "data_int1" ) == 0 ) 00075 { 00076 $contentClassAttribute->setAttribute( "data_int1", 10 ); 00077 $contentClassAttribute->store(); 00078 } 00079 } 00080 00081 /*! 00082 Validates the input and returns true if the input was 00083 valid for this datatype. 00084 */ 00085 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00086 { 00087 if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) ) 00088 { 00089 $data = $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ); 00090 $classAttribute = $contentObjectAttribute->contentClassAttribute(); 00091 00092 if ( $data == "" ) 00093 { 00094 if ( !$classAttribute->attribute( 'is_information_collector' ) and 00095 $contentObjectAttribute->validateIsRequired() ) 00096 { 00097 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00098 'Input required.' ) ); 00099 return eZInputValidator::STATE_INVALID; 00100 } 00101 } 00102 } 00103 return eZInputValidator::STATE_ACCEPTED; 00104 } 00105 00106 /*! 00107 */ 00108 function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00109 { 00110 if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) ) 00111 { 00112 $data = $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ); 00113 $classAttribute = $contentObjectAttribute->contentClassAttribute(); 00114 00115 if ( $data == "" ) 00116 { 00117 if ( $contentObjectAttribute->validateIsRequired() ) 00118 { 00119 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00120 'Input required.' ) ); 00121 return eZInputValidator::STATE_INVALID; 00122 } 00123 } 00124 return eZInputValidator::STATE_ACCEPTED; 00125 } 00126 else 00127 return eZInputValidator::STATE_INVALID; 00128 } 00129 00130 /*! 00131 Fetches the http post var string input and stores it in the data instance. 00132 */ 00133 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00134 { 00135 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) ) 00136 { 00137 $data = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ); 00138 $contentObjectAttribute->setAttribute( "data_text", $data ); 00139 return true; 00140 } 00141 return false; 00142 } 00143 00144 /*! 00145 Fetches the http post variables for collected information 00146 */ 00147 function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute ) 00148 { 00149 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) ) 00150 { 00151 $dataText = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ); 00152 $collectionAttribute->setAttribute( 'data_text', $dataText ); 00153 return true; 00154 } 00155 return false; 00156 } 00157 00158 /*! 00159 Store the content. 00160 */ 00161 function storeObjectAttribute( $attribute ) 00162 { 00163 } 00164 00165 /*! 00166 \reimp 00167 Simple string insertion is supported. 00168 */ 00169 function isSimpleStringInsertionSupported() 00170 { 00171 return true; 00172 } 00173 00174 /*! 00175 \reimp 00176 Inserts the string \a $string in the \c 'data_text' database field. 00177 */ 00178 function insertSimpleString( $object, $objectVersion, $objectLanguage, 00179 $objectAttribute, $string, 00180 &$result ) 00181 { 00182 $result = array( 'errors' => array(), 00183 'require_storage' => true ); 00184 $objectAttribute->setContent( $string ); 00185 $objectAttribute->setAttribute( 'data_text', $string ); 00186 return true; 00187 } 00188 00189 /*! 00190 Returns the content. 00191 */ 00192 function objectAttributeContent( $contentObjectAttribute ) 00193 { 00194 return $contentObjectAttribute->attribute( "data_text" ); 00195 } 00196 00197 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) 00198 { 00199 $column = $base . self::COLS_VARIABLE . $classAttribute->attribute( 'id' ); 00200 if ( $http->hasPostVariable( $column ) ) 00201 { 00202 $columnValue = $http->postVariable( $column ); 00203 $classAttribute->setAttribute( self::COLS_FIELD, $columnValue ); 00204 return true; 00205 } 00206 return false; 00207 } 00208 00209 /*! 00210 Returns the meta data used for storing search indeces. 00211 */ 00212 function metaData( $contentObjectAttribute ) 00213 { 00214 return $contentObjectAttribute->attribute( "data_text" ); 00215 } 00216 00217 /*! 00218 \return string representation of an contentobjectattribute data for simplified export 00219 00220 */ 00221 function toString( $contentObjectAttribute ) 00222 { 00223 return $contentObjectAttribute->attribute( 'data_text' ); 00224 } 00225 00226 function fromString( $contentObjectAttribute, $string ) 00227 { 00228 return $contentObjectAttribute->setAttribute( 'data_text', $string ); 00229 } 00230 00231 function hasObjectAttributeContent( $contentObjectAttribute ) 00232 { 00233 return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != ''; 00234 } 00235 00236 /*! 00237 Returns the text. 00238 */ 00239 function title( $data_instance, $name = null ) 00240 { 00241 return $data_instance->attribute( "data_text" ); 00242 } 00243 00244 /*! 00245 \reimp 00246 */ 00247 function isIndexable() 00248 { 00249 return true; 00250 } 00251 00252 /*! 00253 \reimp 00254 */ 00255 function isInformationCollector() 00256 { 00257 return true; 00258 } 00259 00260 /*! 00261 \reimp 00262 */ 00263 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00264 { 00265 $dom = $attributeParametersNode->ownerDocument; 00266 $textColumns = $classAttribute->attribute( self::COLS_FIELD ); 00267 00268 $textColumnCountNode = $dom->createElement( 'text-column-count' ); 00269 $textColumnCountNode->appendChild( $dom->createTextNode( $textColumns ) ); 00270 $attributeParametersNode->appendChild( $textColumnCountNode ); 00271 } 00272 00273 /*! 00274 \reimp 00275 */ 00276 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00277 { 00278 $textColumns = $attributeParametersNode->getElementsByTagName( 'text-column-count' )->item( 0 )->textContent; 00279 $classAttribute->setAttribute( self::COLS_FIELD, $textColumns ); 00280 } 00281 00282 /*! 00283 \reimp 00284 */ 00285 function diff( $old, $new, $options = false ) 00286 { 00287 //include_once( 'lib/ezdiff/classes/ezdiff.php' ); 00288 $diff = new eZDiff(); 00289 $diff->setDiffEngineType( $diff->engineType( 'text' ) ); 00290 $diff->initDiffEngine(); 00291 $diffObject = $diff->diff( $old->content(), $new->content() ); 00292 return $diffObject; 00293 } 00294 00295 } 00296 00297 eZDataType::register( eZTextType::DATA_TYPE_STRING, "eZTextType" ); 00298 00299 ?>