| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZAuthorType class 4 // 5 // Created on: <19-Aug-2002 10:51:10 bf> 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 eZAuthorType ezauthortype.php 31 \ingroup eZDatatype 32 \brief eZAuthorType handles multiple authors 33 34 */ 35 36 include_once ( "kernel/classes/ezdatatype.php" ); 37 include_once ( "kernel/classes/datatypes/ezauthor/ezauthor.php" ); 38 include_once ( "lib/ezutils/classes/ezmail.php" ); 39 include_once ( 'lib/ezutils/classes/ezstringutils.php' ); 40 41 define( "EZ_DATATYPESTRING_AUTHOR", "ezauthor" ); 42 43 class eZAuthorType extends eZDataType 44 { 45 function eZAuthorType() 46 { 47 $this->eZDataType( EZ_DATATYPESTRING_AUTHOR, ezi18n( 'kernel/classes/datatypes', "Authors", 'Datatype name' ), 48 array( 'serialize_supported' => true ) ); 49 } 50 51 /*! 52 Validates the input and returns true if the input was 53 valid for this datatype. 54 */ 55 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 56 { 57 $actionRemoveSelected = false; 58 if ( $http->hasPostVariable( 'CustomActionButton' ) ) 59 { 60 $customActionArray = $http->postVariable( 'CustomActionButton' ); 61 62 if ( isset( $customActionArray[$contentObjectAttribute->attribute( "id" ) . '_remove_selected'] ) ) 63 if ( $customActionArray[$contentObjectAttribute->attribute( "id" ) . '_remove_selected'] == 'Remove selected' ) 64 $actionRemoveSelected = true; 65 } 66 67 if ( $http->hasPostVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ) ) 68 { 69 $classAttribute =& $contentObjectAttribute->contentClassAttribute(); 70 $idList = $http->postVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ); 71 $nameList = $http->postVariable( $base . "_data_author_name_" . $contentObjectAttribute->attribute( "id" ) ); 72 $emailList = $http->postVariable( $base . "_data_author_email_" . $contentObjectAttribute->attribute( "id" ) ); 73 74 if ( $http->hasPostVariable( $base . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ) ) ) 75 $removeList = $http->postVariable( $base . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ) ); 76 else 77 $removeList = array(); 78 79 if ( $contentObjectAttribute->validateIsRequired() ) 80 { 81 if ( trim( $nameList[0] ) == "" ) 82 { 83 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 84 'At least one author is required.' ) ); 85 return EZ_INPUT_VALIDATOR_STATE_INVALID; 86 } 87 } 88 if ( trim( $nameList[0] ) != "" ) 89 { 90 for ( $i=0;$i<count( $idList );$i++ ) 91 { 92 if ( $actionRemoveSelected ) 93 if ( in_array( $idList[$i], $removeList ) ) 94 continue; 95 96 $name = $nameList[$i]; 97 $email = $emailList[$i]; 98 if ( trim( $name )== "" ) 99 { 100 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 101 'The author name must be provided.' ) ); 102 return EZ_INPUT_VALIDATOR_STATE_INVALID; 103 104 } 105 $isValidate = eZMail::validate( $email ); 106 if ( ! $isValidate ) 107 { 108 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 109 'The email address is not valid.' ) ); 110 return EZ_INPUT_VALIDATOR_STATE_INVALID; 111 } 112 } 113 } 114 } 115 else 116 { 117 if ( $contentObjectAttribute->validateIsRequired() ) 118 { 119 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 120 'At least one author is required.' ) ); 121 return EZ_INPUT_VALIDATOR_STATE_INVALID; 122 } 123 } 124 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED; 125 } 126 127 /*! 128 Store content 129 */ 130 function storeObjectAttribute( &$contentObjectAttribute ) 131 { 132 $author =& $contentObjectAttribute->content(); 133 $contentObjectAttribute->setAttribute( "data_text", $author->xmlString() ); 134 } 135 136 /*! 137 Sets the default value. 138 */ 139 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute ) 140 { 141 if ( $currentVersion != false ) 142 { 143 $dataText = $originalContentObjectAttribute->attribute( "data_text" ); 144 $contentObjectAttribute->setAttribute( "data_text", $dataText ); 145 } 146 } 147 148 /*! 149 Returns the content. 150 */ 151 function &objectAttributeContent( &$contentObjectAttribute ) 152 { 153 $author = new eZAuthor( ); 154 155 if ( trim( $contentObjectAttribute->attribute( "data_text" ) ) != "" ) 156 { 157 $author->decodeXML( $contentObjectAttribute->attribute( "data_text" ) ); 158 $temp = $contentObjectAttribute->attribute( "data_text"); 159 } 160 else 161 { 162 $user =& eZUser::currentUser(); 163 $userobject =& $user->attribute( 'contentobject' ); 164 if ( $userobject ) 165 { 166 $author->addAuthor( $userobject->attribute( 'id' ), $userobject->attribute( 'name' ), $user->attribute( 'email' ) ); 167 } 168 } 169 170 if ( count( $author->attribute( 'author_list' ) ) == 0 ) 171 { 172 // $author->addAuthor( "Default", "" ); 173 } 174 175 return $author; 176 } 177 178 179 /*! 180 Returns the meta data used for storing search indeces. 181 */ 182 function metaData( &$contentObjectAttribute ) 183 { 184 $author =& $contentObjectAttribute->content(); 185 if ( !$author ) 186 return false; 187 188 return $author->metaData(); 189 } 190 191 function toString( $contentObjectAttribute ) 192 { 193 $authorList = array(); 194 $content = $contentObjectAttribute->attribute( 'content' ); 195 foreach ( $content->attribute( 'author_list') as $author ) 196 { 197 $authorList[] = eZStringUtils::implodeStr( array( $author['name'], $author['email'],$author['id'] ), '|' ); 198 } 199 return eZStringUtils::implodeStr( $authorList, "&" ); 200 } 201 202 function fromString( &$contentObjectAttribute, $string ) 203 { 204 $authorList = eZStringUtils::explodeStr( $string, '&' ); 205 206 $author = new eZAuthor( ); 207 208 209 foreach ( $authorList as $authorStr ) 210 { 211 $authorData = eZStringUtils::explodeStr( $authorStr, '|' ); 212 $author->addAuthor( $authorData[2], $authorData[0], $authorData[1] ); 213 214 } 215 $contentObjectAttribute->setContent( $author ); 216 return $author; 217 } 218 219 /*! 220 Fetches the http post var integer input and stores it in the data instance. 221 */ 222 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute ) 223 { 224 if ( $http->hasPostVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ) ) 225 { 226 $authorIDArray = $http->postVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ); 227 $authorNameArray = $http->postVariable( $base . "_data_author_name_" . $contentObjectAttribute->attribute( "id" ) ); 228 $authorEmailArray = $http->postVariable( $base . "_data_author_email_" . $contentObjectAttribute->attribute( "id" ) ); 229 230 $author = new eZAuthor( ); 231 232 $i = 0; 233 foreach ( $authorIDArray as $id ) 234 { 235 $author->addAuthor( $authorIDArray[$i], $authorNameArray[$i], $authorEmailArray[$i] ); 236 $i++; 237 } 238 $contentObjectAttribute->setContent( $author ); 239 } 240 return true; 241 } 242 243 /*! 244 */ 245 function customObjectAttributeHTTPAction( $http, $action, &$contentObjectAttribute ) 246 { 247 switch ( $action ) 248 { 249 case "new_author" : 250 { 251 $author =& $contentObjectAttribute->content( ); 252 253 $author->addAuthor( -1, "", "" ); 254 $contentObjectAttribute->setContent( $author ); 255 }break; 256 case "remove_selected" : 257 { 258 $author =& $contentObjectAttribute->content( ); 259 $postvarname = "ContentObjectAttribute" . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ); 260 if ( !$http->hasPostVariable( $postvarname ) ) 261 break; 262 $array_remove = $http->postVariable( $postvarname ); 263 264 $author->removeAuthors( $array_remove ); 265 $contentObjectAttribute->setContent( $author ); 266 }break; 267 default : 268 { 269 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZAuthorType" ); 270 }break; 271 } 272 } 273 274 function hasObjectAttributeContent( &$contentObjectAttribute ) 275 { 276 $author =& $contentObjectAttribute->content( ); 277 $authorList = $author->attribute( 'author_list' ); 278 return count( $authorList ) > 0; 279 } 280 281 /*! 282 Returns the string value. 283 */ 284 function title( &$contentObjectAttribute ) 285 { 286 $author =& $contentObjectAttribute->content( ); 287 $name = $author->attribute( 'name' ); 288 if ( trim( $name ) == '' ) 289 { 290 $authorList = $author->attribute( 'author_list' ); 291 if ( is_array( $authorList ) and isset( $authorList[0]['name'] ) ) 292 { 293 $name = $authorList[0]['name']; // Get the first name of Auhtors 294 $author->setName( $name ); 295 } 296 } 297 return $name; 298 } 299 300 /*! 301 \reimp 302 */ 303 function isIndexable() 304 { 305 return true; 306 } 307 308 /*! 309 \reimp 310 \param package 311 \param content attribute 312 313 \return a DOM representation of the content object attribute 314 */ 315 function serializeContentObjectAttribute( &$package, &$objectAttribute ) 316 { 317 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute ); 318 319 $xml = new eZXML(); 320 $domDocument = $xml->domTree( $objectAttribute->attribute( 'data_text' ) ); 321 $node->appendChild( $domDocument->root() ); 322 323 return $node; 324 } 325 326 /*! 327 \reimp 328 329 \param package 330 \param contentobject attribute object 331 \param ezdomnode object 332 */ 333 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode ) 334 { 335 $rootNode = $attributeNode->firstChild(); 336 $objectAttribute->setAttribute( 'data_text', $rootNode->toString( 0 ) ); 337 } 338 339 } 340 341 eZDataType::register( EZ_DATATYPESTRING_AUTHOR, "ezauthortype" ); 342 343 ?>
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 |