|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZEmailType class 00004 // 00005 // 00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00007 // SOFTWARE NAME: eZ Publish 00008 // SOFTWARE RELEASE: 4.0.x 00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00010 // SOFTWARE LICENSE: GNU General Public License v2.0 00011 // NOTICE: > 00012 // This program is free software; you can redistribute it and/or 00013 // modify it under the terms of version 2.0 of the GNU General 00014 // Public License as published by the Free Software Foundation. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of version 2.0 of the GNU General 00022 // Public License along with this program; if not, write to the Free 00023 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00024 // MA 02110-1301, USA. 00025 // 00026 // 00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00028 // 00029 00030 /*! 00031 \class eZEmailType ezemailtype.php 00032 \ingroup eZDatatype 00033 \brief Stores an email address 00034 00035 */ 00036 00037 //include_once( "kernel/classes/ezdatatype.php" ); 00038 00039 class eZEmailType extends eZDataType 00040 { 00041 const DATA_TYPE_STRING = "ezemail"; 00042 00043 function eZEmailType() 00044 { 00045 $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Email", 'Datatype name' ), 00046 array( 'serialize_supported' => true, 00047 'object_serialize_map' => array( 'data_text' => 'email' ) ) ); 00048 } 00049 00050 /*! 00051 Sets the default value. 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 Private method, only for using inside this class. 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 eZInputValidator::STATE_INVALID; 00073 } 00074 return eZInputValidator::STATE_ACCEPTED; 00075 } 00076 00077 /*! 00078 Validates the input and returns true if the input was 00079 valid for this datatype. 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 // we require user to enter an address only if the attribute is not an informationcollector 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 eZInputValidator::STATE_INVALID; 00099 } 00100 } 00101 else 00102 { 00103 // if the entered address is not empty then we should validate it in any case 00104 return $this->validateEMailHTTPInput( $trimedEmail, $contentObjectAttribute ); 00105 } 00106 } 00107 return eZInputValidator::STATE_ACCEPTED; 00108 } 00109 00110 /*! 00111 Fetches the http post var string input and stores it in the data instance. 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 \reimp 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 // if entered email is empty and required then return state invalid 00139 if ( $contentObjectAttribute->validateIsRequired() ) 00140 { 00141 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00142 'The email address is empty.' ) ); 00143 return eZInputValidator::STATE_INVALID; 00144 } 00145 else 00146 return eZInputValidator::STATE_ACCEPTED; 00147 } 00148 else 00149 { 00150 // if entered email is not empty then we should validate it in any case 00151 return $this->validateEMailHTTPInput( $trimedEmail, $contentObjectAttribute ); 00152 } 00153 } 00154 else 00155 return eZInputValidator::STATE_INVALID; 00156 } 00157 00158 /*! 00159 Fetches the http post variables for collected information 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 Store the content. 00174 */ 00175 function storeObjectAttribute( $attribute ) 00176 { 00177 } 00178 00179 /*! 00180 Returns the content. 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 Returns the meta data used for storing search indeces. 00194 */ 00195 function metaData( $contentObjectAttribute ) 00196 { 00197 return $contentObjectAttribute->attribute( "data_text" ); 00198 } 00199 00200 /*! 00201 \return string representation of an contentobjectattribute data for simplified export 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 Returns the text. 00216 */ 00217 function title( $contentObjectAttribute, $name = null ) 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 \reimp 00229 */ 00230 function isInformationCollector() 00231 { 00232 return true; 00233 } 00234 00235 /*! 00236 \reimp 00237 */ 00238 function sortKey( $contentObjectAttribute ) 00239 { 00240 return strtolower( $contentObjectAttribute->attribute( 'data_text' ) ); 00241 } 00242 00243 /*! 00244 \reimp 00245 */ 00246 function sortKeyType() 00247 { 00248 return 'string'; 00249 } 00250 } 00251 00252 eZDataType::register( eZEmailType::DATA_TYPE_STRING, "eZEmailType" ); 00253 00254 ?>