Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezurltype.php
Go to the documentation of this file.
1 <?php
19 class eZURLType extends eZDataType
20 {
24 public $MaxLenValidator;
25 const DATA_TYPE_STRING = 'ezurl';
26
27 public function __construct()
28 {
29 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', 'URL', 'Datatype name' ),
30 array( 'serialize_supported' => true ) );
31 $this->MaxLenValidator = new eZIntegerValidator();
32 }
33
37 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
38 {
39 if ( $currentVersion != false )
40 {
41 // $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
42 // $currentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID,
43 // $currentVersion );
44 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
45 $url = $originalContentObjectAttribute->attribute( "content" );
46 $contentObjectAttribute->setContent( $url );
47 $contentObjectAttribute->setAttribute( "data_text", $dataText );
48 }
49 else
50 {
51 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
52 $default = $contentClassAttribute->attribute( 'data_text1' );
53 if ( $default !== '' && $default !== NULL )
54 {
55 $contentObjectAttribute->setAttribute( 'data_text', $default );
56 }
57 }
58 }
59
64 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
65 {
66 if ( $http->hasPostVariable( $base . "_ezurl_url_" . $contentObjectAttribute->attribute( "id" ) ) and
67 $http->hasPostVariable( $base . "_ezurl_text_" . $contentObjectAttribute->attribute( "id" ) )
68 )
69 {
70 $url = $http->PostVariable( $base . "_ezurl_url_" . $contentObjectAttribute->attribute( "id" ) );
71 $text = $http->PostVariable( $base . "_ezurl_text_" . $contentObjectAttribute->attribute( "id" ) );
72 if ( $contentObjectAttribute->validateIsRequired() )
73 if ( $url == "" )
74 {
75 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
76 'Input required.' ) );
77 return eZInputValidator::STATE_INVALID;
78 }
79 // Remove all url-object links to this attribute.
80 eZURLObjectLink::removeURLlinkList( $contentObjectAttribute->attribute( "id" ), $contentObjectAttribute->attribute('version') );
81 }
82 else if ( $contentObjectAttribute->validateIsRequired() )
83 {
84 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Input required.' ) );
85 return eZInputValidator::STATE_INVALID;
86 }
87 return eZInputValidator::STATE_ACCEPTED;
88 }
89
90 function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null )
91 {
92 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
93 $urls = array();
94 if ( $version == null )
95 {
96 $urls = eZURLObjectLink::fetchLinkList( $contentObjectAttributeID, false, false );
97 eZURLObjectLink::removeURLlinkList( $contentObjectAttributeID, false );
98 }
99 else
100 {
101 $urls = eZURLObjectLink::fetchLinkList( $contentObjectAttributeID, $version, false );
102 eZURLObjectLink::removeURLlinkList( $contentObjectAttributeID, $version );
103 }
104 $urls = array_unique( $urls );
105
106 $db = eZDB::instance();
107 $db->begin();
108
109 foreach ( $urls as $urlID )
110 {
111 if ( !eZURLObjectLink::hasObjectLinkList( $urlID ) )
112 {
113 eZURL::removeByID( $urlID );
114 }
115 }
116
117 $db->commit();
118 }
119
123 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
124 {
125 if ( $http->hasPostVariable( $base . '_ezurl_url_' . $contentObjectAttribute->attribute( 'id' ) ) and
126 $http->hasPostVariable( $base . '_ezurl_text_' . $contentObjectAttribute->attribute( 'id' ) )
127 )
128 {
129 $url = $http->postVariable( $base . '_ezurl_url_' . $contentObjectAttribute->attribute( 'id' ) );
130 $text = $http->postVariable( $base . '_ezurl_text_' . $contentObjectAttribute->attribute( 'id' ) );
131
132 $contentObjectAttribute->setAttribute( 'data_text', $text );
133
134 $contentObjectAttribute->setContent( $url );
135 return true;
136 }
137 return false;
138 }
139
143 function postStore( $objectAttribute )
144 {
145 // Update url-object link
146 $urlValue = $objectAttribute->content();
147 if ( trim( $urlValue ) != '' )
148 {
149 $urlID = eZURL::registerURL( $urlValue );
150 $objectAttributeID = $objectAttribute->attribute( 'id' );
151 $objectAttributeVersion = $objectAttribute->attribute( 'version' );
152
153 $db = eZDB::instance();
154 $db->begin();
155
156 $objectLinkList = eZURLObjectLink::fetchLinkObjectList( $objectAttributeID, $objectAttributeVersion );
157
158 // In order not to have duplicated links, delete existing ones that have been created during the version creation process
159 // and create a clean one (we can't update url_id since there's no primary key). This fixes EZP-20988
160 if ( !empty( $objectLinkList ) )
161 {
162 eZURLObjectLink::removeURLlinkList( $objectAttributeID, $objectAttributeVersion );
163 }
164
165 $linkObjectLink = eZURLObjectLink::create( $urlID, $objectAttributeID, $objectAttributeVersion );
166 $linkObjectLink->store();
167
168 $db->commit();
169 }
170 }
171
175 function storeObjectAttribute( $attribute )
176 {
177 $urlValue = $attribute->content();
178 if ( trim( $urlValue ) != '' )
179 {
180 $oldURLID = $attribute->attribute( 'data_int' );
181 $urlID = eZURL::registerURL( $urlValue );
182 $attribute->setAttribute( 'data_int', $urlID );
183
184 if ( $oldURLID && $oldURLID != $urlID &&
185 !eZURLObjectLink::hasObjectLinkList( $oldURLID ) )
186 eZURL::removeByID( $oldURLID );
187 }
188 else
189 {
190 $attribute->setAttribute( 'data_int', 0 );
191 }
192
193 }
194
195 function storeClassAttribute( $attribute, $version )
196 {
197 }
198
199 function storeDefinedClassAttribute( $attribute )
200 {
201 }
202
203 function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
204 {
205 return eZInputValidator::STATE_ACCEPTED;
206 }
207
211 function objectAttributeContent( $contentObjectAttribute )
212 {
213 if ( !$contentObjectAttribute->attribute( 'data_int' ) )
214 {
215 $attrValue = false;
216 return $attrValue;
217 }
218
219 $url = eZURL::url( $contentObjectAttribute->attribute( 'data_int' ) );
220 return $url;
221 }
222
223 function hasObjectAttributeContent( $contentObjectAttribute )
224 {
225 if ( $contentObjectAttribute->attribute( 'data_int' ) == 0 )
226 return false;
227
228 $url = eZURL::fetch( $contentObjectAttribute->attribute( 'data_int' ) );
229 if ( is_object( $url ) and
230 trim( $url->attribute( 'url' ) ) != '' and
231 $url->attribute( 'is_valid' ) )
232 return true;
233 return false;
234 }
235
239 function metaData( $contentObjectAttribute )
240 {
241 return $contentObjectAttribute->attribute( 'data_text' );
242 }
243
247 function title( $contentObjectAttribute, $name = null )
248 {
249 return $contentObjectAttribute->attribute( 'data_text' );
250 }
251
252 function toString( $contentObjectAttribute )
253 {
254 if ( !$contentObjectAttribute->attribute( 'data_int' ) )
255 {
256 $attrValue = false;
257 return $attrValue;
258 }
259
260 $url = eZURL::url( $contentObjectAttribute->attribute( 'data_int' ) );
261 $text = $contentObjectAttribute->attribute( 'data_text');
262 if ( $text != '' )
263 {
264 $exportData = $url . '|' . $text;
265 }
266 else
267 {
268 $exportData = $url;
269 }
270 return $exportData;
271 }
272
273
274 function fromString( $contentObjectAttribute, $string )
275 {
276
277 if ( $string == '' )
278 return true;
279
280 $separatorPos = strpos( $string, '|' );
281 // Check if supplied data has a separator which separates url from url text
282 if( $separatorPos === false )
283 {
284 $urlID = eZURL::registerURL( $string );
285 $contentObjectAttribute->setAttribute( 'data_int', $urlID );
286 return $urlID;
287 }
288 else
289 {
290 $url = substr( $string, 0, $separatorPos );
291 $text = substr( $string, $separatorPos + 1 );
292 if( $url )
293 {
294 $urlID = eZURL::registerURL( $url );
295 $contentObjectAttribute->setAttribute( 'data_int', $urlID );
296 }
297
298 if( $text )
299 {
300 $contentObjectAttribute->setAttribute( 'data_text', $text );
301 }
302
303 return true;
304 }
305 }
306
313 function serializeContentObjectAttribute( $package, $objectAttribute )
314 {
315 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
316 $dom = $node->ownerDocument;
317
318 $url = eZURL::fetch( $objectAttribute->attribute( 'data_int' ) );
319 if ( is_object( $url ) and
320 trim( $url->attribute( 'url' ) ) != '' )
321 {
322 $urlNode = $dom->createElement( 'url' );
323 $urlNode->appendChild( $dom->createTextNode( urlencode( $url->attribute( 'url' ) ) ) );
324 $urlNode->setAttribute( 'original-url-md5', $url->attribute( 'original_url_md5' ) );
325 $urlNode->setAttribute( 'is-valid', $url->attribute( 'is_valid' ) );
326 $urlNode->setAttribute( 'last-checked', $url->attribute( 'last_checked' ) );
327 $urlNode->setAttribute( 'created', $url->attribute( 'created' ) );
328 $urlNode->setAttribute( 'modified', $url->attribute( 'modified' ) );
329 $node->appendChild( $urlNode );
330 }
331
332 if ( $objectAttribute->attribute( 'data_text' ) )
333 {
334 $textNode = $dom->createElement( 'text' );
335 $textNode->appendChild( $dom->createTextNode( $objectAttribute->attribute( 'data_text' ) ) );
336 $node->appendChild( $textNode );
337 }
338
339 return $node;
340 }
341
347 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
348 {
349 $urlNode = $attributeNode->getElementsByTagName( 'url' )->item( 0 );
350
351 if ( is_object( $urlNode ) )
352 {
353 unset( $url );
354 $url = urldecode( $urlNode->textContent );
355
356 $urlID = eZURL::registerURL( $url );
357 if ( $urlID )
358 {
359 $urlObject = eZURL::fetch( $urlID );
360
361 $urlObject->setAttribute( 'original_url_md5', $urlNode->getAttribute( 'original-url-md5' ) );
362 $urlObject->setAttribute( 'is_valid', $urlNode->getAttribute( 'is-valid' ) );
363 $urlObject->setAttribute( 'last_checked', $urlNode->getAttribute( 'last-checked' ) );
364 $urlObject->setAttribute( 'created', time() );
365 $urlObject->setAttribute( 'modified', time() );
366 $urlObject->store();
367
368 $objectAttribute->setAttribute( 'data_int', $urlID );
369 }
370 }
371
372 $textNode = $attributeNode->getElementsByTagName( 'text' )->item( 0 );
373 if ( $textNode )
374 $objectAttribute->setAttribute( 'data_text', $textNode->textContent );
375 }
376
377 function supportsBatchInitializeObjectAttribute()
378 {
379 return true;
380 }
381 }
382
383 eZDataType::register( eZURLType::DATA_TYPE_STRING, 'eZURLType' );
384
385 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
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
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZIntegerValidator
The class eZIntegerValidator does.
Definition: ezintegervalidator.php:18
eZURLObjectLink\create
static create( $urlID, $contentObjectAttributeID, $contentObjectAttributeVersion)
Definition: ezurlobjectlink.php:51
eZURLObjectLink\fetchLinkList
static fetchLinkList( $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject=true)
Definition: ezurlobjectlink.php:159
eZURLObjectLink\hasObjectLinkList
static hasObjectLinkList( $urlID)
Definition: ezurlobjectlink.php:78
eZURLObjectLink\removeURLlinkList
static removeURLlinkList( $contentObjectAttributeID, $contentObjectAttributeVersion)
Definition: ezurlobjectlink.php:144
eZURLObjectLink\fetchLinkObjectList
static fetchLinkObjectList( $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject=true)
Definition: ezurlobjectlink.php:190
eZURLType
A content datatype which handles urls.
Definition: ezurltype.php:20
eZURLType\metaData
metaData( $contentObjectAttribute)
Definition: ezurltype.php:239
eZURLType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezurltype.php:223
eZURLType\deleteStoredObjectAttribute
deleteStoredObjectAttribute( $contentObjectAttribute, $version=null)
Definition: ezurltype.php:90
eZURLType\$MaxLenValidator
$MaxLenValidator
Definition: ezurltype.php:24
eZURLType\storeDefinedClassAttribute
storeDefinedClassAttribute( $attribute)
Definition: ezurltype.php:199
eZURLType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezurltype.php:64
eZURLType\serializeContentObjectAttribute
serializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezurltype.php:313
eZURLType\title
title( $contentObjectAttribute, $name=null)
Definition: ezurltype.php:247
eZURLType\toString
toString( $contentObjectAttribute)
Definition: ezurltype.php:252
eZURLType\postStore
postStore( $objectAttribute)
Definition: ezurltype.php:143
eZURLType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezurltype.php:211
eZURLType\storeObjectAttribute
storeObjectAttribute( $attribute)
Definition: ezurltype.php:175
eZURLType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezurltype.php:37
eZURLType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezurltype.php:25
eZURLType\unserializeContentObjectAttribute
unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode)
Definition: ezurltype.php:347
eZURLType\storeClassAttribute
storeClassAttribute( $attribute, $version)
Definition: ezurltype.php:195
eZURLType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezurltype.php:377
eZURLType\__construct
__construct()
Definition: ezurltype.php:27
eZURLType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezurltype.php:203
eZURLType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezurltype.php:274
eZURLType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezurltype.php:123
eZURL\fetch
static fetch( $id, $asObject=true)
Definition: ezurl.php:211
eZURL\removeByID
static removeByID( $urlID)
Definition: ezurl.php:84
eZURL\url
static url( $id, $onlyValid=false)
Definition: ezurl.php:374
eZURL\registerURL
static registerURL( $url)
Definition: ezurl.php:96
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+.