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 include_once( "kernel/classes/ezdatatype.php" );
00039 include_once( "kernel/classes/datatypes/ezauthor/ezauthor.php" );
00040 include_once( "lib/ezutils/classes/ezmail.php" );
00041 include_once( 'lib/ezutils/classes/ezstringutils.php' );
00042
00043 define( "EZ_DATATYPESTRING_AUTHOR", "ezauthor" );
00044
00045 class eZAuthorType extends eZDataType
00046 {
00047 function eZAuthorType()
00048 {
00049 $this->eZDataType( EZ_DATATYPESTRING_AUTHOR, ezi18n( 'kernel/classes/datatypes', "Authors", 'Datatype name' ),
00050 array( 'serialize_supported' => true ) );
00051 }
00052
00053
00054
00055
00056
00057 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00058 {
00059 $actionRemoveSelected = false;
00060 if ( $http->hasPostVariable( 'CustomActionButton' ) )
00061 {
00062 $customActionArray = $http->postVariable( 'CustomActionButton' );
00063
00064 if ( isset( $customActionArray[$contentObjectAttribute->attribute( "id" ) . '_remove_selected'] ) )
00065 if ( $customActionArray[$contentObjectAttribute->attribute( "id" ) . '_remove_selected'] == 'Remove selected' )
00066 $actionRemoveSelected = true;
00067 }
00068
00069 if ( $http->hasPostVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ) )
00070 {
00071 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00072 $idList = $http->postVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) );
00073 $nameList = $http->postVariable( $base . "_data_author_name_" . $contentObjectAttribute->attribute( "id" ) );
00074 $emailList = $http->postVariable( $base . "_data_author_email_" . $contentObjectAttribute->attribute( "id" ) );
00075
00076 if ( $http->hasPostVariable( $base . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ) ) )
00077 $removeList = $http->postVariable( $base . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ) );
00078 else
00079 $removeList = array();
00080
00081 if ( $contentObjectAttribute->validateIsRequired() )
00082 {
00083 if ( trim( $nameList[0] ) == "" )
00084 {
00085 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00086 'At least one author is required.' ) );
00087 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00088 }
00089 }
00090 if ( trim( $nameList[0] ) != "" )
00091 {
00092 for ( $i=0;$i<count( $idList );$i++ )
00093 {
00094 if ( $actionRemoveSelected )
00095 if ( in_array( $idList[$i], $removeList ) )
00096 continue;
00097
00098 $name = $nameList[$i];
00099 $email = $emailList[$i];
00100 if ( trim( $name )== "" )
00101 {
00102 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00103 'The author name must be provided.' ) );
00104 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00105
00106 }
00107 $isValidate = eZMail::validate( $email );
00108 if ( ! $isValidate )
00109 {
00110 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00111 'The email address is not valid.' ) );
00112 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00113 }
00114 }
00115 }
00116 }
00117 else
00118 {
00119 if ( $contentObjectAttribute->validateIsRequired() )
00120 {
00121 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00122 'At least one author is required.' ) );
00123 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00124 }
00125 }
00126 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00127 }
00128
00129
00130
00131
00132 function storeObjectAttribute( &$contentObjectAttribute )
00133 {
00134 $author =& $contentObjectAttribute->content();
00135 $contentObjectAttribute->setAttribute( "data_text", $author->xmlString() );
00136 }
00137
00138
00139
00140
00141 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00142 {
00143 if ( $currentVersion != false )
00144 {
00145 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
00146 $contentObjectAttribute->setAttribute( "data_text", $dataText );
00147 }
00148 }
00149
00150
00151
00152
00153 function &objectAttributeContent( &$contentObjectAttribute )
00154 {
00155 $author = new eZAuthor( );
00156
00157 if ( trim( $contentObjectAttribute->attribute( "data_text" ) ) != "" )
00158 {
00159 $author->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
00160 $temp = $contentObjectAttribute->attribute( "data_text");
00161 }
00162 else
00163 {
00164 $user =& eZUser::currentUser();
00165 $userobject =& $user->attribute( 'contentobject' );
00166 if ( $userobject )
00167 {
00168 $author->addAuthor( $userobject->attribute( 'id' ), $userobject->attribute( 'name' ), $user->attribute( 'email' ) );
00169 }
00170 }
00171
00172 if ( count( $author->attribute( 'author_list' ) ) == 0 )
00173 {
00174
00175 }
00176
00177 return $author;
00178 }
00179
00180
00181
00182
00183
00184 function metaData( &$contentObjectAttribute )
00185 {
00186 $author =& $contentObjectAttribute->content();
00187 if ( !$author )
00188 return false;
00189
00190 return $author->metaData();
00191 }
00192
00193 function toString( $contentObjectAttribute )
00194 {
00195 $authorList = array();
00196 $content = $contentObjectAttribute->attribute( 'content' );
00197 foreach ( $content->attribute( 'author_list') as $author )
00198 {
00199 $authorList[] = eZStringUtils::implodeStr( array( $author['name'], $author['email'],$author['id'] ), '|' );
00200 }
00201 return eZStringUtils::implodeStr( $authorList, "&" );
00202 }
00203
00204 function fromString( &$contentObjectAttribute, $string )
00205 {
00206 $authorList = eZStringUtils::explodeStr( $string, '&' );
00207
00208 $author = new eZAuthor( );
00209
00210
00211 foreach ( $authorList as $authorStr )
00212 {
00213 $authorData = eZStringUtils::explodeStr( $authorStr, '|' );
00214 $author->addAuthor( $authorData[2], $authorData[0], $authorData[1] );
00215
00216 }
00217 $contentObjectAttribute->setContent( $author );
00218 return $author;
00219 }
00220
00221
00222
00223
00224 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00225 {
00226 if ( $http->hasPostVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ) )
00227 {
00228 $authorIDArray = $http->postVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) );
00229 $authorNameArray = $http->postVariable( $base . "_data_author_name_" . $contentObjectAttribute->attribute( "id" ) );
00230 $authorEmailArray = $http->postVariable( $base . "_data_author_email_" . $contentObjectAttribute->attribute( "id" ) );
00231
00232 $author = new eZAuthor( );
00233
00234 $i = 0;
00235 foreach ( $authorIDArray as $id )
00236 {
00237 $author->addAuthor( $authorIDArray[$i], $authorNameArray[$i], $authorEmailArray[$i] );
00238 $i++;
00239 }
00240 $contentObjectAttribute->setContent( $author );
00241 }
00242 return true;
00243 }
00244
00245
00246
00247 function customObjectAttributeHTTPAction( $http, $action, &$contentObjectAttribute )
00248 {
00249 switch ( $action )
00250 {
00251 case "new_author" :
00252 {
00253 $author =& $contentObjectAttribute->content( );
00254
00255 $author->addAuthor( -1, "", "" );
00256 $contentObjectAttribute->setContent( $author );
00257 }break;
00258 case "remove_selected" :
00259 {
00260 $author =& $contentObjectAttribute->content( );
00261 $postvarname = "ContentObjectAttribute" . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" );
00262 if ( !$http->hasPostVariable( $postvarname ) )
00263 break;
00264 $array_remove = $http->postVariable( $postvarname );
00265
00266 $author->removeAuthors( $array_remove );
00267 $contentObjectAttribute->setContent( $author );
00268 }break;
00269 default :
00270 {
00271 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZAuthorType" );
00272 }break;
00273 }
00274 }
00275
00276 function hasObjectAttributeContent( &$contentObjectAttribute )
00277 {
00278 $author =& $contentObjectAttribute->content( );
00279 $authorList = $author->attribute( 'author_list' );
00280 return count( $authorList ) > 0;
00281 }
00282
00283
00284
00285
00286 function title( &$contentObjectAttribute )
00287 {
00288 $author =& $contentObjectAttribute->content( );
00289 $name = $author->attribute( 'name' );
00290 if ( trim( $name ) == '' )
00291 {
00292 $authorList = $author->attribute( 'author_list' );
00293 if ( is_array( $authorList ) and isset( $authorList[0]['name'] ) )
00294 {
00295 $name = $authorList[0]['name'];
00296 $author->setName( $name );
00297 }
00298 }
00299 return $name;
00300 }
00301
00302
00303
00304
00305 function isIndexable()
00306 {
00307 return true;
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
00317 function serializeContentObjectAttribute( &$package, &$objectAttribute )
00318 {
00319 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00320
00321 $xml = new eZXML();
00322 $domDocument = $xml->domTree( $objectAttribute->attribute( 'data_text' ) );
00323 $node->appendChild( $domDocument->root() );
00324
00325 return $node;
00326 }
00327
00328
00329
00330
00331
00332
00333
00334
00335 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
00336 {
00337 $rootNode = $attributeNode->firstChild();
00338 $objectAttribute->setAttribute( 'data_text', $rootNode->toString( 0 ) );
00339 }
00340
00341 }
00342
00343 eZDataType::register( EZ_DATATYPESTRING_AUTHOR, "ezauthortype" );
00344
00345 ?>