Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezurl.php
Go to the documentation of this file.
1 <?php
22 class eZURL extends eZPersistentObject
23 {
24 public $URL;
25 public $IsValid;
26 public $OriginalURLMD5;
27 public $LastChecked;
28
29 static function definition()
30 {
31 static $definition = array( 'fields' => array( 'id' => array( 'name' => 'ID',
32 'datatype' => 'integer',
33 'default' => 0,
34 'required' => true ),
35 'url' => array( 'name' => 'URL',
36 'datatype' => 'string',
37 'default' => '',
38 'required' => true ),
39 'original_url_md5' => array( 'name' => 'OriginalURLMD5',
40 'datatype' => 'string',
41 'default' => '',
42 'required' => true ),
43 'is_valid' => array( 'name' => 'IsValid',
44 'datatype' => 'integer',
45 'default' => 0,
46 'required' => true ),
47 'last_checked' => array( 'name' => 'LastChecked',
48 'datatype' => 'integer',
49 'default' => 0,
50 'required' => true ),
51 'created' => array( 'name' => 'Created',
52 'datatype' => 'integer',
53 'default' => 0,
54 'required' => true ),
55 'modified' => array( 'name' => 'Modified',
56 'datatype' => 'integer',
57 'default' => 0,
58 'required' => true ) ),
59 'keys' => array( 'id' ),
60 'increment_key' => 'id',
61 'class_name' => 'eZURL',
62 'name' => 'ezurl' );
63 return $definition;
64 }
65
66 static function create( $url )
67 {
68 $dateTime = time();
69 $row = array(
70 'id' => null,
71 'url' => $url,
72 'original_url_md5' => md5( $url ),
73 'is_valid' => true,
74 'last_checked' => 0,
75 'created' => $dateTime,
76 'modified' => $dateTime );
77 return new eZURL( $row );
78 }
79
84 static function removeByID( $urlID )
85 {
86 eZPersistentObject::removeObject( eZURL::definition(),
87 array( 'id' => $urlID ) );
88 }
89
96 static function registerURL( $url )
97 {
98 $urlID = null;
99 $urlObject = self::fetchByUrl( $url );
100
101 if ( !$urlObject instanceof eZURL )
102 {
103 // store URL
104 $urlObject = self::create( $url );
105 $urlObject->store();
106 $urlID = $urlObject->attribute( 'id' );
107 }
108 else
109 {
110 // Mismatch => most likely case sensitivity difference, so update the url
111 if ( $urlObject->attribute( 'url' ) !== $url )
112 {
113 $urlObject->setAttribute( 'url', $url );
114 $urlObject->setAttribute( 'original_url_md5', md5( $url ) );
115 $urlObject->setAttribute( 'modified', time() );
116 $urlObject->store( array( 'url', 'original_url_md5', 'modified' ) );
117 }
118
119 $urlID = $urlObject->attribute( 'id' );
120 }
121
122 return $urlID;
123 }
124
130 static function registerURLArray( $urlArray )
131 {
132 $db = eZDB::instance();
133
134 foreach( $urlArray as $key => $url )
135 {
136 $urlArrayTmp[$key] = $db->escapeString( $url );
137 }
138 // Fetch the already existing URL's
139 $inURLSQL = implode( '\', \'', $urlArrayTmp );
140 $checkURLQuery = "SELECT id, url FROM ezurl WHERE url IN ( '$inURLSQL' )";
141 $urlRowArray = $db->arrayQuery( $checkURLQuery );
142
143 $registeredURLArray = array();
144 foreach ( $urlRowArray as $urlRow )
145 {
146 $registeredURLArray[$urlRow['url']] = $urlRow['id'];
147 }
148
149 // Check for URL's which are not registered, and register them
150 foreach ( $urlArray as $url )
151 {
152 if ( !isset( $registeredURLArray[$url] ) )
153 {
154 $url = eZURL::create( $url );
155 $url->store();
156 $urlID = $url->attribute( 'id' );
157 $urlText = $url->attribute('url' );
158 $registeredURLArray[$urlText] = $urlID;
159 }
160 }
161
162 return $registeredURLArray;
163 }
164
170 static function setIsValid( $id, $isValid )
171 {
172 $dateTime = time();
173 $isValid = (int) $isValid;
174 eZPersistentObject::updateObjectList( array( 'definition' => eZURL::definition(),
175 'update_fields' => array( 'is_valid' => $isValid,
176 'modified' => $dateTime ),
177 'conditions' => array( 'id' => $id ) ) );
178 }
179
184 function setModified( $dateTime = false )
185 {
186 if ( $dateTime === false )
187 {
188 $dateTime = time();
189 }
190 $this->Modified = $dateTime;
191 }
192
197 static function setLastChecked( $id, $dateTime = false )
198 {
199 if ( $dateTime === false )
200 {
201 $dateTime = time();
202 }
203 eZPersistentObject::updateObjectList( array( 'definition' => eZURL::definition(),
204 'update_fields' => array( 'last_checked' => $dateTime ),
205 'conditions' => array( 'id' => $id ) ) );
206 }
207
211 static function fetch( $id, $asObject = true )
212 {
213 return eZPersistentObject::fetchObject( eZURL::definition(),
214 null, array( 'id' => $id ),
215 $asObject );
216 }
217
221 static function fetchListCount( $parameters = array() )
222 {
223 return eZURL::handleList( $parameters, true );
224 }
225
229 static function fetchList( $parameters = array() )
230 {
231 return eZURL::handleList( $parameters, false );
232 }
233
240 public static function fetchByUrl( $url, $asObject = true )
241 {
242 return parent::fetchObject( self::definition(),
243 null, array( 'url' => $url ),
244 $asObject );
245 }
246
250 static function handleList( $parameters = array(), $asCount = false )
251 {
252 $parameters = array_merge( array( 'as_object' => true,
253 'is_valid' => null,
254 'offset' => false,
255 'limit' => false,
256 'only_published' => false ),
257 $parameters );
258 $asObject = $parameters['as_object'];
259 $isValid = $parameters['is_valid'];
260 $offset = $parameters['offset'];
261 $limit = $parameters['limit'];
262 $onlyPublished = $parameters['only_published'];
263 $limitArray = null;
264 if ( !$asCount and $offset !== false and $limit !== false )
265 $limitArray = array( 'offset' => $offset,
266 'length' => $limit );
267 $conditions = array();
268 if( $isValid === false ) $isValid = 0;
269 if ( $isValid !== null )
270 {
271 $conditions['is_valid'] = $isValid;
272 }
273 if ( count( $conditions ) == 0 )
274 $conditions = null;
275
276 if ( $onlyPublished ) // Only fetch published urls
277 {
278 $conditionQuery = "";
279 if ( $isValid !== null )
280 {
281 $isValid = (int) $isValid;
282 $conditionQuery = " AND ezurl.is_valid=$isValid ";
283 }
284 $db = eZDB::instance();
285 $cObjAttrVersionColumn = eZPersistentObject::getShortAttributeName( $db, eZURLObjectLink::definition(), 'contentobject_attribute_version' );
286
287 if ( $asCount )
288 {
289 $urls = $db->arrayQuery( "SELECT count( DISTINCT ezurl.id ) AS count
290 FROM
291 ezurl,
292 ezurl_object_link,
293 ezcontentobject_attribute,
294 ezcontentobject_version
295 WHERE
296 ezurl.id = ezurl_object_link.url_id
297 AND ezurl_object_link.contentobject_attribute_id = ezcontentobject_attribute.id
298 AND ezurl_object_link.$cObjAttrVersionColumn = ezcontentobject_attribute.version
299 AND ezcontentobject_attribute.contentobject_id = ezcontentobject_version.contentobject_id
300 AND ezcontentobject_attribute.version = ezcontentobject_version.version
301 AND ezcontentobject_version.status = " . eZContentObjectVersion::STATUS_PUBLISHED . "
302 $conditionQuery" );
303 return $urls[0]['count'];
304 }
305 else
306 {
307 $query = "SELECT DISTINCT ezurl.*
308 FROM
309 ezurl,
310 ezurl_object_link,
311 ezcontentobject_attribute,
312 ezcontentobject_version
313 WHERE
314 ezurl.id = ezurl_object_link.url_id
315 AND ezurl_object_link.contentobject_attribute_id = ezcontentobject_attribute.id
316 AND ezurl_object_link.$cObjAttrVersionColumn = ezcontentobject_attribute.version
317 AND ezcontentobject_attribute.contentobject_id = ezcontentobject_version.contentobject_id
318 AND ezcontentobject_attribute.version = ezcontentobject_version.version
319 AND ezcontentobject_version.status = " . eZContentObjectVersion::STATUS_PUBLISHED . "
320 $conditionQuery";
321
322 if ( !$offset && !$limit )
323 {
324 $urlArray = $db->arrayQuery( $query );
325 }
326 else
327 {
328 $urlArray = $db->arrayQuery( $query, array( 'offset' => $offset,
329 'limit' => $limit ) );
330 }
331 if ( $asObject )
332 {
333 $urls = array();
334 foreach ( $urlArray as $url )
335 {
336 $urls[] = new eZURL( $url );
337 }
338 return $urls;
339 }
340 else
341 $urls = $urlArray;
342 return $urls;
343 }
344 }
345 else
346 {
347 if ( $asCount )
348 {
349 $urls = eZPersistentObject::fetchObjectList( eZURL::definition(),
350 array(),
351 $conditions,
352 false,
353 null,
354 false,
355 false,
356 array( array( 'operation' => 'count( id )',
357 'name' => 'count' ) ) );
358 return $urls[0]['count'];
359 }
360 else
361 {
362 return eZPersistentObject::fetchObjectList( eZURL::definition(),
363 null, $conditions, null, $limitArray,
364 $asObject );
365 }
366 }
367 }
368
374 static function url( $id, $onlyValid = false )
375 {
376 $url = false;
377
378 if ( !is_numeric( $id ) )
379 {
380 return $url;
381 }
382
383 $id = (int) $id;
384 $db = eZDB::instance();
385 $checkURLQuery = "SELECT url, is_valid FROM ezurl WHERE id='$id'";
386 $urlArray = $db->arrayQuery( $checkURLQuery );
387
388 if ( count( $urlArray ) == 1 )
389 {
390 if ( $onlyValid and
391 !$urlArray[0]['is_valid'] )
392 {
393 $url = "/url/view/" . $id;
394 return $url;
395 }
396 $url = $urlArray[0]['url'];
397 }
398 return $url;
399 }
400
406 static function urlByMD5( $urlMD5 )
407 {
408 $db = eZDB::instance();
409
410 $url = false;
411 $urlMD5 = $db->escapeString( $urlMD5 );
412 $checkURLQuery = "SELECT url FROM ezurl WHERE original_url_md5='$urlMD5'";
413 $urlArray = $db->arrayQuery( $checkURLQuery );
414
415 if ( count( $urlArray ) == 1 )
416 {
417 $url = $urlArray[0]['url'];
418 }
419 return $url;
420 }
421
426 static function urlByURL( $urlText )
427 {
428 $db = eZDB::instance();
429
430 $url = false;
431 $checkURLQuery = "SELECT * FROM ezurl WHERE url='" . $db->escapeString( $urlText ) . "'";
432 $urlArray = $db->arrayQuery( $checkURLQuery );
433
434 if ( count( $urlArray ) == 1 )
435 {
436 $url = new eZURL( $urlArray[0] );
437 }
438 return $url;
439 }
440 }
441
442 ?>
eZContentObjectVersion\STATUS_PUBLISHED
const STATUS_PUBLISHED
Definition: ezcontentobjectversion.php:30
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\updateObjectList
static updateObjectList( $parameters)
Definition: ezpersistentobject.php:1209
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\getShortAttributeName
static getShortAttributeName( $db, $def, $attrName)
Definition: ezpersistentobject.php:1438
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZURLObjectLink\definition
static definition()
Definition: ezurlobjectlink.php:20
eZURL
A class which handles central storage of urls.
Definition: ezurl.php:23
eZURL\setIsValid
static setIsValid( $id, $isValid)
Definition: ezurl.php:170
eZURL\fetch
static fetch( $id, $asObject=true)
Definition: ezurl.php:211
eZURL\urlByMD5
static urlByMD5( $urlMD5)
Definition: ezurl.php:406
eZURL\$IsValid
$IsValid
Definition: ezurl.php:25
eZURL\handleList
static handleList( $parameters=array(), $asCount=false)
Definition: ezurl.php:250
eZURL\setModified
setModified( $dateTime=false)
Definition: ezurl.php:184
eZURL\fetchList
static fetchList( $parameters=array())
Definition: ezurl.php:229
eZURL\removeByID
static removeByID( $urlID)
Definition: ezurl.php:84
eZURL\fetchListCount
static fetchListCount( $parameters=array())
Definition: ezurl.php:221
eZURL\$LastChecked
$LastChecked
Definition: ezurl.php:27
eZURL\url
static url( $id, $onlyValid=false)
Definition: ezurl.php:374
eZURL\setLastChecked
static setLastChecked( $id, $dateTime=false)
Definition: ezurl.php:197
eZURL\registerURL
static registerURL( $url)
Definition: ezurl.php:96
eZURL\urlByURL
static urlByURL( $urlText)
Definition: ezurl.php:426
eZURL\definition
static definition()
Definition: ezurl.php:29
eZURL\$URL
$URL
Definition: ezurl.php:24
eZURL\$OriginalURLMD5
$OriginalURLMD5
Definition: ezurl.php:26
eZURL\create
static create( $url)
Definition: ezurl.php:66
eZURL\registerURLArray
static registerURLArray( $urlArray)
Definition: ezurl.php:130
eZURL\fetchByUrl
static fetchByUrl( $url, $asObject=true)
Definition: ezurl.php:240
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.