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 include_once( "kernel/classes/ezdatatype.php" );
00038
00039 define( "EZ_DATATYPESTRING_EMAIL", "ezemail" );
00040
00041 class eZEmailType extends eZDataType
00042 {
00043 function eZEmailType()
00044 {
00045 $this->eZDataType( EZ_DATATYPESTRING_EMAIL, ezi18n( 'kernel/classes/datatypes', "E-mail", 'Datatype name' ),
00046 array( 'serialize_supported' => true,
00047 'object_serialize_map' => array( 'data_text' => 'email' ) ) );
00048 }
00049
00050
00051
00052
00053 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00054 {
00055 if ( $currentVersion != false )
00056 {
00057 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
00058 $contentObjectAttribute->setAttribute( "data_text", $dataText );
00059 }
00060 }
00061
00062
00063
00064
00065 function validateEMailHTTPInput( $email, &$contentObjectAttribute )
00066 {
00067 include_once( "lib/ezutils/classes/ezmail.php" );
00068 if ( !eZMail::validate( $email ) )
00069 {
00070 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00071 'The email address is not valid.' ) );
00072 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00073 }
00074 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00075 }
00076
00077
00078
00079
00080
00081 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00082 {
00083 if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00084 {
00085 $email = $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00086 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00087
00088 $trimedEmail = trim( $email );
00089
00090 if ( $trimedEmail == "" )
00091 {
00092
00093 if ( !$classAttribute->attribute( 'is_information_collector' ) and
00094 $contentObjectAttribute->validateIsRequired() )
00095 {
00096 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00097 'The email address is empty.' ) );
00098 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00099 }
00100 }
00101 else
00102 {
00103
00104 return $this->validateEMailHTTPInput( $trimedEmail, $contentObjectAttribute );
00105 }
00106 }
00107 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00108 }
00109
00110
00111
00112
00113 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00114 {
00115 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
00116 {
00117 $data = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
00118 $contentObjectAttribute->setAttribute( "data_text", $data );
00119 return true;
00120 }
00121 return false;
00122 }
00123
00124
00125
00126
00127 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00128 {
00129 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
00130 {
00131 $email = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
00132 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00133
00134 $trimedEmail = trim( $email );
00135
00136 if ( $trimedEmail == "" )
00137 {
00138
00139 if ( $contentObjectAttribute->validateIsRequired() )
00140 {
00141 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00142 'The email address is empty.' ) );
00143 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00144 }
00145 else
00146 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00147 }
00148 else
00149 {
00150
00151 return $this->validateEMailHTTPInput( $trimedEmail, $contentObjectAttribute );
00152 }
00153 }
00154 else
00155 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00156 }
00157
00158
00159
00160
00161 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute )
00162 {
00163 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
00164 {
00165 $dataText = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
00166 $collectionAttribute->setAttribute( 'data_text', $dataText );
00167 return true;
00168 }
00169 return false;
00170 }
00171
00172
00173
00174
00175 function storeObjectAttribute( &$attribute )
00176 {
00177 }
00178
00179
00180
00181
00182 function &objectAttributeContent( &$contentObjectAttribute )
00183 {
00184 return $contentObjectAttribute->attribute( "data_text" );
00185 }
00186
00187 function isIndexable()
00188 {
00189 return true;
00190 }
00191
00192
00193
00194
00195 function metaData( $contentObjectAttribute )
00196 {
00197 return $contentObjectAttribute->attribute( "data_text" );
00198 }
00199
00200
00201
00202
00203
00204 function toString( $contentObjectAttribute )
00205 {
00206 return $contentObjectAttribute->attribute( 'data_text' );
00207 }
00208
00209 function fromString( &$contentObjectAttribute, $string )
00210 {
00211 return $contentObjectAttribute->setAttribute( 'data_text', $string );
00212 }
00213
00214
00215
00216
00217 function title( &$contentObjectAttribute )
00218 {
00219 return $contentObjectAttribute->attribute( "data_text" );
00220 }
00221
00222 function hasObjectAttributeContent( &$contentObjectAttribute )
00223 {
00224 return trim( $contentObjectAttribute->attribute( "data_text" ) ) != '';
00225 }
00226
00227
00228
00229
00230 function isInformationCollector()
00231 {
00232 return true;
00233 }
00234
00235
00236
00237
00238 function sortKey( &$contentObjectAttribute )
00239 {
00240 return strtolower( $contentObjectAttribute->attribute( 'data_text' ) );
00241 }
00242
00243
00244
00245
00246 function sortKeyType()
00247 {
00248 return 'string';
00249 }
00250 }
00251
00252 eZDataType::register( EZ_DATATYPESTRING_EMAIL, "ezemailtype" );
00253
00254 ?>