Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezauthortype.php
Go to the documentation of this file.
1 <?php
18 class eZAuthorType extends eZDataType
19 {
20 const DATA_TYPE_STRING = "ezauthor";
21
22 public function __construct()
23 {
24 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Authors", 'Datatype name' ),
25 array( 'serialize_supported' => true ) );
26 }
27
32 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
33 {
34 $actionRemoveSelected = false;
35 if ( $http->hasPostVariable( 'CustomActionButton' ) )
36 {
37 $customActionArray = $http->postVariable( 'CustomActionButton' );
38
39 if ( isset( $customActionArray[$contentObjectAttribute->attribute( "id" ) . '_remove_selected'] ) )
40 if ( $customActionArray[$contentObjectAttribute->attribute( "id" ) . '_remove_selected'] == 'Remove selected' )
41 $actionRemoveSelected = true;
42 }
43
44 if ( $http->hasPostVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ) )
45 {
46 $classAttribute = $contentObjectAttribute->contentClassAttribute();
47 $idList = $http->postVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) );
48 $nameList = $http->postVariable( $base . "_data_author_name_" . $contentObjectAttribute->attribute( "id" ) );
49 $emailList = $http->postVariable( $base . "_data_author_email_" . $contentObjectAttribute->attribute( "id" ) );
50
51 if ( $http->hasPostVariable( $base . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ) ) )
52 $removeList = $http->postVariable( $base . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" ) );
53 else
54 $removeList = array();
55
56 if ( $contentObjectAttribute->validateIsRequired() )
57 {
58 if ( trim( $nameList[0] ) == "" )
59 {
60 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
61 'At least one author is required.' ) );
62 return eZInputValidator::STATE_INVALID;
63 }
64 }
65 if ( trim( $nameList[0] ) != "" )
66 {
67 for ( $i=0;$i<count( $idList );$i++ )
68 {
69 if ( $actionRemoveSelected )
70 if ( in_array( $idList[$i], $removeList ) )
71 continue;
72
73 $name = $nameList[$i];
74 $email = $emailList[$i];
75 if ( trim( $name )== "" )
76 {
77 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
78 'The author name must be provided.' ) );
79 return eZInputValidator::STATE_INVALID;
80
81 }
82 $isValidate = eZMail::validate( $email );
83 if ( ! $isValidate )
84 {
85 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
86 'The email address is not valid.' ) );
87 return eZInputValidator::STATE_INVALID;
88 }
89 }
90 }
91 }
92 else
93 {
94 if ( $contentObjectAttribute->validateIsRequired() )
95 {
96 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
97 'At least one author is required.' ) );
98 return eZInputValidator::STATE_INVALID;
99 }
100 }
101 return eZInputValidator::STATE_ACCEPTED;
102 }
103
107 function storeObjectAttribute( $contentObjectAttribute )
108 {
109 $author = $contentObjectAttribute->content();
110 $contentObjectAttribute->setAttribute( "data_text", $author->xmlString() );
111 }
112
116 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
117 {
118 if ( $currentVersion != false )
119 {
120 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
121 $contentObjectAttribute->setAttribute( "data_text", $dataText );
122 }
123 }
124
128 function objectAttributeContent( $contentObjectAttribute )
129 {
130 $author = new eZAuthor( );
131
132 if ( trim( $contentObjectAttribute->attribute( "data_text" ) ) != "" )
133 {
134 $author->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
135 $temp = $contentObjectAttribute->attribute( "data_text");
136 }
137 else
138 {
139 $user = eZUser::currentUser();
140 $userobject = $user->attribute( 'contentobject' );
141 if ( $userobject )
142 {
143 $author->addAuthor( $userobject->attribute( 'id' ), $userobject->attribute( 'name' ), $user->attribute( 'email' ) );
144 }
145 }
146
147 if ( count( $author->attribute( 'author_list' ) ) == 0 )
148 {
149 // $author->addAuthor( "Default", "" );
150 }
151
152 return $author;
153 }
154
155
159 function metaData( $contentObjectAttribute )
160 {
161 $author = $contentObjectAttribute->content();
162 if ( !$author )
163 return false;
164
165 return $author->metaData();
166 }
167
168 function toString( $contentObjectAttribute )
169 {
170 $authorList = array();
171 $content = $contentObjectAttribute->attribute( 'content' );
172 foreach ( $content->attribute( 'author_list') as $author )
173 {
174 $authorList[] = eZStringUtils::implodeStr( array( $author['name'], $author['email'],$author['id'] ), '|' );
175 }
176 return eZStringUtils::implodeStr( $authorList, "&" );
177 }
178
179 function fromString( $contentObjectAttribute, $string )
180 {
181 $authorList = eZStringUtils::explodeStr( $string, '&' );
182
183 $author = new eZAuthor( );
184
185
186 foreach ( $authorList as $authorStr )
187 {
188 $authorData = eZStringUtils::explodeStr( $authorStr, '|' );
189 $author->addAuthor( $authorData[2], $authorData[0], $authorData[1] );
190
191 }
192 $contentObjectAttribute->setContent( $author );
193 return $author;
194 }
195
199 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
200 {
201 if ( $http->hasPostVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) ) )
202 {
203 $authorIDArray = $http->postVariable( $base . "_data_author_id_" . $contentObjectAttribute->attribute( "id" ) );
204 $authorNameArray = $http->postVariable( $base . "_data_author_name_" . $contentObjectAttribute->attribute( "id" ) );
205 $authorEmailArray = $http->postVariable( $base . "_data_author_email_" . $contentObjectAttribute->attribute( "id" ) );
206
207 $author = new eZAuthor( );
208
209 $i = 0;
210 foreach ( $authorIDArray as $id )
211 {
212 $author->addAuthor( $authorIDArray[$i], $authorNameArray[$i], $authorEmailArray[$i] );
213 $i++;
214 }
215 $contentObjectAttribute->setContent( $author );
216 }
217 return true;
218 }
219
220 function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters )
221 {
222 switch ( $action )
223 {
224 case "new_author" :
225 {
226 $author = $contentObjectAttribute->content( );
227
228 $author->addAuthor( -1, "", "" );
229 $contentObjectAttribute->setContent( $author );
230 }break;
231 case "remove_selected" :
232 {
233 $author = $contentObjectAttribute->content( );
234 $postvarname = $parameters['base_name'] . "_data_author_remove_" . $contentObjectAttribute->attribute( "id" );
235 if ( !$http->hasPostVariable( $postvarname ) )
236 break;
237 $array_remove = $http->postVariable( $postvarname );
238
239 $author->removeAuthors( $array_remove );
240 $contentObjectAttribute->setContent( $author );
241 }break;
242 default :
243 {
244 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZAuthorType" );
245 }break;
246 }
247 }
248
249 function hasObjectAttributeContent( $contentObjectAttribute )
250 {
251 $author = $contentObjectAttribute->content( );
252 $authorList = $author->attribute( 'author_list' );
253 return count( $authorList ) > 0;
254 }
255
259 function title( $contentObjectAttribute, $name = null )
260 {
261 $author = $contentObjectAttribute->content( );
262 $name = $author->attribute( 'name' );
263 if ( trim( $name ) == '' )
264 {
265 $authorList = $author->attribute( 'author_list' );
266 if ( is_array( $authorList ) and isset( $authorList[0]['name'] ) )
267 {
268 $name = $authorList[0]['name']; // Get the first name of Auhtors
269 $author->setName( $name );
270 }
271 }
272 return $name;
273 }
274
275 function isIndexable()
276 {
277 return true;
278 }
279
280 function serializeContentObjectAttribute( $package, $objectAttribute )
281 {
282 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
283
284 $dom = new DOMDocument( '1.0', 'utf-8' );
285 $success = $dom->loadXML( $objectAttribute->attribute( 'data_text' ) );
286
287 $nodeDOM = $node->ownerDocument;
288 $importedElement = $nodeDOM->importNode( $dom->documentElement, true );
289 $node->appendChild( $importedElement );
290
291 return $node;
292 }
293
294 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
295 {
296 $rootNode = $attributeNode->getElementsByTagName( 'ezauthor' )->item( 0 );
297 $xmlString = $rootNode->ownerDocument->saveXML( $rootNode );
298 $objectAttribute->setAttribute( 'data_text', $xmlString );
299 }
300
301 function supportsBatchInitializeObjectAttribute()
302 {
303 return true;
304 }
305 }
306
307 eZDataType::register( eZAuthorType::DATA_TYPE_STRING, "eZAuthorType" );
308
309 ?>
eZAuthorType
eZAuthorType handles multiple authors
Definition: ezauthortype.php:19
eZAuthorType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezauthortype.php:301
eZAuthorType\serializeContentObjectAttribute
serializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezauthortype.php:280
eZAuthorType\metaData
metaData( $contentObjectAttribute)
Definition: ezauthortype.php:159
eZAuthorType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezauthortype.php:199
eZAuthorType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezauthortype.php:179
eZAuthorType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezauthortype.php:249
eZAuthorType\toString
toString( $contentObjectAttribute)
Definition: ezauthortype.php:168
eZAuthorType\storeObjectAttribute
storeObjectAttribute( $contentObjectAttribute)
Definition: ezauthortype.php:107
eZAuthorType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezauthortype.php:128
eZAuthorType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezauthortype.php:32
eZAuthorType\title
title( $contentObjectAttribute, $name=null)
Definition: ezauthortype.php:259
eZAuthorType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezauthortype.php:116
eZAuthorType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezauthortype.php:20
eZAuthorType\unserializeContentObjectAttribute
unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode)
Definition: ezauthortype.php:294
eZAuthorType\customObjectAttributeHTTPAction
customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters)
Definition: ezauthortype.php:220
eZAuthorType\isIndexable
isIndexable()
Definition: ezauthortype.php:275
eZAuthorType\__construct
__construct()
Definition: ezauthortype.php:22
eZAuthor
eZAuthor handles author lists
Definition: ezauthor.php:29
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZDataType\createContentObjectAttributeDOMNode
createContentObjectAttributeDOMNode( $objectAttribute)
Definition: ezdatatype.php:1371
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZMail\validate
static validate( $address)
Definition: ezmail.php:747
eZStringUtils\implodeStr
static implodeStr( $values, $delimiter='|')
Definition: ezstringutils.php:44
eZStringUtils\explodeStr
static explodeStr( $str, $delimiter='|')
Definition: ezstringutils.php:19
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.