| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZURL class 4 // 5 // Created on: <08-Oct-2002 19:44:48 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 eZURL ezurl.php 31 \ingroup eZDatatype 32 \brief A class which handles central storage of urls 33 34 URLs can be stored using eZURL. When registering URL's 35 to eZURL you will get a URL ID which is used to identify 36 URLs. 37 38 */ 39 40 include_once ( 'kernel/classes/ezpersistentobject.php' ); 41 42 class eZURL extends eZPersistentObject 43 { 44 /*! 45 */ 46 function eZURL( $row ) 47 { 48 $this->eZPersistentObject( $row ); 49 } 50 51 function definition() 52 { 53 return array( 'fields' => array( 'id' => array( 'name' => 'ID', 54 'datatype' => 'integer', 55 'default' => 0, 56 'required' => true ), 57 'url' => array( 'name' => 'URL', 58 'datatype' => 'string', 59 'default' => '', 60 'required' => true ), 61 'original_url_md5' => array( 'name' => 'OriginalURLMD5', 62 'datatype' => 'string', 63 'default' => '', 64 'required' => true ), 65 'is_valid' => array( 'name' => 'IsValid', 66 'datatype' => 'integer', 67 'default' => 0, 68 'required' => true ), 69 'last_checked' => array( 'name' => 'LastChecked', 70 'datatype' => 'integer', 71 'default' => 0, 72 'required' => true ), 73 'created' => array( 'name' => 'Created', 74 'datatype' => 'integer', 75 'default' => 0, 76 'required' => true ), 77 'modified' => array( 'name' => 'Modified', 78 'datatype' => 'integer', 79 'default' => 0, 80 'required' => true ) ), 81 'keys' => array( 'id' ), 82 'increment_key' => 'id', 83 'class_name' => 'eZURL', 84 'name' => 'ezurl' ); 85 } 86 87 function create( $url ) 88 { 89 $dateTime = time(); 90 $row = array( 91 'id' => null, 92 'url' => $url, 93 'original_url_md5' => md5( $url ), 94 'is_valid' => true, 95 'last_checked' => 0, 96 'created' => $dateTime, 97 'modified' => $dateTime ); 98 return new eZURL( $row ); 99 } 100 101 /*! 102 \static 103 Removes the URL with ID \a $urlID. 104 */ 105 function removeByID( $urlID ) 106 { 107 eZPersistentObject::removeObject( eZURL::definition(), 108 array( 'id' => $urlID ) ); 109 } 110 111 /*! 112 \static 113 Registers a URL to the URL database. The URL id is 114 returned if successful. False is returned if not. 115 */ 116 function registerURL( $url ) 117 { 118 $urlID = false; 119 $db =& eZDB::instance(); 120 121 // check if URL already exists 122 $checkURLQuery = "SELECT id FROM ezurl WHERE url='" . $db->escapeString( $url ) . "'"; 123 $urlArray = $db->arrayQuery( $checkURLQuery ); 124 125 if ( count( $urlArray ) == 0 ) 126 { 127 // store URL 128 $url = eZURL::create( $url ); 129 $url->store(); 130 $urlID = $url->attribute( 'id' ); 131 } 132 else 133 { 134 $urlID = $urlArray[0]['id']; 135 } 136 return $urlID; 137 } 138 139 /*! 140 \static 141 Registers an array of URLs to the URL database. A hash of array( url -> id ) 142 is returned. 143 */ 144 function registerURLArray( $urlArray ) 145 { 146 $db =& eZDB::instance(); 147 148 foreach( $urlArray as $key => $url ) 149 { 150 $urlArrayTmp[$key] = $db->escapeString( $url ); 151 } 152 // Fetch the already existing URL's 153 $inURLSQL = implode( '\', \'', $urlArrayTmp ); 154 $checkURLQuery = "SELECT id, url FROM ezurl WHERE url IN ( '$inURLSQL' )"; 155 $urlRowArray = $db->arrayQuery( $checkURLQuery ); 156 157 $registeredURLArray = array(); 158 foreach ( $urlRowArray as $urlRow ) 159 { 160 $registeredURLArray[$urlRow['url']] = $urlRow['id']; 161 } 162 163 // Check for URL's which are not registered, and register them 164 foreach ( $urlArray as $url ) 165 { 166 if ( !isset( $registeredURLArray[$url] ) ) 167 { 168 $url = eZURL::create( $url ); 169 $url->store(); 170 $urlID = $url->attribute( 'id' ); 171 $urlText = $url->attribute('url' ); 172 $registeredURLArray[$urlText] = $urlID; 173 } 174 } 175 176 return $registeredURLArray; 177 } 178 179 /*! 180 \static 181 Updates the is_valid field of urls passed in \a $id. 182 \param $id Can either be an array with ids or just one id value. 183 */ 184 function setIsValid( $id, $isValid ) 185 { 186 $dateTime = time(); 187 $isValid = (int) $isValid; 188 eZPersistentObject::updateObjectList( array( 'definition' => eZURL::definition(), 189 'update_fields' => array( 'is_valid' => $isValid, 190 'modified' => $dateTime ), 191 'conditions' => array( 'id' => $id ) ) ); 192 } 193 194 /*! 195 Sets the modification date to \a $dateTime or the current 196 date if it's \c false. 197 */ 198 function setModified( $dateTime = false ) 199 { 200 if ( $dateTime === false ) 201 { 202 $dateTime = time(); 203 } 204 $this->Modified = $dateTime; 205 } 206 207 /*! 208 Sets the last checked date to \a $dateTime or the current 209 date if it's \c false. 210 */ 211 function setLastChecked( $id, $dateTime = false ) 212 { 213 if ( $dateTime === false ) 214 { 215 $dateTime = time(); 216 } 217 eZPersistentObject::updateObjectList( array( 'definition' => eZURL::definition(), 218 'update_fields' => array( 'last_checked' => $dateTime ), 219 'conditions' => array( 'id' => $id ) ) ); 220 } 221 222 /*! 223 \return the url object for id \a $id. 224 */ 225 function fetch( $id, $asObject = true ) 226 { 227 return eZPersistentObject::fetchObject( eZURL::definition(), 228 null, array( 'id' => $id ), 229 $asObject ); 230 } 231 232 /*! 233 \return the number of registered URLs. 234 */ 235 function fetchListCount( $parameters = array() ) 236 { 237 return eZURL::handleList( $parameters, true ); 238 } 239 240 /*! 241 \return all registered URLs. 242 */ 243 function fetchList( $parameters = array() ) 244 { 245 return eZURL::handleList( $parameters, false ); 246 } 247 248 /*! 249 \return all registered URLs. 250 */ 251 function handleList( $parameters = array(), $asCount = false ) 252 { 253 $parameters = array_merge( array( 'as_object' => true, 254 'is_valid' => null, 255 'offset' => false, 256 'limit' => false, 257 'only_published' => false ), 258 $parameters ); 259 $asObject = $parameters['as_object']; 260 $isValid = $parameters['is_valid']; 261 $offset = $parameters['offset']; 262 $limit = $parameters['limit']; 263 $onlyPublished = $parameters['only_published']; 264 $limitArray = null; 265 if ( !$asCount and $offset !== false and $limit !== false ) 266 $limitArray = array( 'offset' => $offset, 267 'length' => $limit ); 268 $conditions = array(); 269 if( $isValid === false ) $isValid = 0; 270 if ( $isValid !== null ) 271 { 272 $conditions['is_valid'] = $isValid; 273 } 274 if ( count( $conditions ) == 0 ) 275 $conditions = null; 276 277 if ( $onlyPublished ) // Only fetch published urls 278 { 279 $conditionQuery = ""; 280 if ( $isValid !== null ) 281 { 282 $isValid = (int) $isValid; 283 $conditionQuery = " AND ezurl.is_valid=$isValid "; 284 } 285 include_once ( "lib/ezdb/classes/ezdb.php" ); 286 $db =& eZDB::instance(); 287 include_once ( 'kernel/classes/datatypes/ezurl/ezurlobjectlink.php' ); 288 $cObjAttrVersionColumn = eZPersistentObject::getShortAttributeName( $db, eZURLObjectLink::definition(), 'contentobject_attribute_version' ); 289 290 if ( $asCount ) 291 { 292 $urls = $db->arrayQuery( "SELECT count( DISTINCT ezurl.id ) AS count 293 FROM 294 ezurl, 295 ezurl_object_link, 296 ezcontentobject_attribute, 297 ezcontentobject_version 298 WHERE 299 ezurl.id = ezurl_object_link.url_id 300 AND ezurl_object_link.contentobject_attribute_id = ezcontentobject_attribute.id 301 AND ezurl_object_link.$cObjAttrVersionColumn = ezcontentobject_attribute.version 302 AND ezcontentobject_attribute.contentobject_id = ezcontentobject_version.contentobject_id 303 AND ezcontentobject_attribute.version = ezcontentobject_version.version 304 AND ezcontentobject_version.status = 1 305 $conditionQuery" ); 306 return $urls[0]['count']; 307 } 308 else 309 { 310 $query = "SELECT DISTINCT ezurl.* 311 FROM 312 ezurl, 313 ezurl_object_link, 314 ezcontentobject_attribute, 315 ezcontentobject_version 316 WHERE 317 ezurl.id = ezurl_object_link.url_id 318 AND ezurl_object_link.contentobject_attribute_id = ezcontentobject_attribute.id 319 AND ezurl_object_link.$cObjAttrVersionColumn = ezcontentobject_attribute.version 320 AND ezcontentobject_attribute.contentobject_id = ezcontentobject_version.contentobject_id 321 AND ezcontentobject_attribute.version = ezcontentobject_version.version 322 AND ezcontentobject_version.status = 1 323 $conditionQuery"; 324 325 if ( !$offset && !$limit ) 326 { 327 $urlArray = $db->arrayQuery( $query ); 328 } 329 else 330 { 331 $urlArray = $db->arrayQuery( $query, array( 'offset' => $offset, 332 'limit' => $limit ) ); 333 } 334 if ( $asObject ) 335 { 336 $urls = array(); 337 foreach ( $urlArray as $url ) 338 { 339 $urls[] = new eZURL( $url ); 340 } 341 return $urls; 342 } 343 else 344 $urls =& $urlArray; 345 return $urls; 346 } 347 } 348 else 349 { 350 if ( $asCount ) 351 { 352 $urls = eZPersistentObject::fetchObjectList( eZURL::definition(), 353 array(), $conditions, null, null, 354 false, null, 355 array( array( 'operation' => 'count( id )', 356 'name' => 'count' ) ) ); 357 return $urls[0]['count']; 358 } 359 else 360 { 361 return eZPersistentObject::fetchObjectList( eZURL::definition(), 362 null, $conditions, null, $limitArray, 363 $asObject ); 364 } 365 } 366 } 367 368 /*! 369 \static 370 Returns the URL with the given ID. False is returned if the ID 371 does not exits. 372 */ 373 function url( $id, $onlyValid = false ) 374 { 375 $url = false; 376 377 if ( !is_numeric( $id ) ) 378 { 379 return $url; 380 } 381 382 $id = (int) $id; 383 $db =& eZDB::instance(); 384 $checkURLQuery = "SELECT url, is_valid FROM ezurl WHERE id='$id'"; 385 $urlArray = $db->arrayQuery( $checkURLQuery ); 386 387 if ( count( $urlArray ) == 1 ) 388 { 389 if ( $onlyValid and 390 !$urlArray[0]['is_valid'] ) 391 { 392 $url = "/url/view/" . $id; 393 return $url; 394 } 395 $url = $urlArray[0]['url']; 396 } 397 return $url; 398 } 399 400 /*! 401 \static 402 Returns the URL with the given ID. False is returned if the ID 403 does not exits. 404 */ 405 function urlByMD5( $urlMD5 ) 406 { 407 $db =& eZDB::instance(); 408 409 $url = false; 410 $urlMD5 = $db->escapeString( $urlMD5 ); 411 $checkURLQuery = "SELECT url FROM ezurl WHERE original_url_md5='$urlMD5'"; 412 $urlArray = $db->arrayQuery( $checkURLQuery ); 413 414 if ( count( $urlArray ) == 1 ) 415 { 416 $url = $urlArray[0]['url']; 417 } 418 return $url; 419 } 420 421 /*! 422 \static 423 Returns the URL with the given URL. Returns false if the URL does not exists. 424 */ 425 function urlByURL( $urlText ) 426 { 427 $db =& eZDB::instance(); 428 429 $url = false; 430 $checkURLQuery = "SELECT * FROM ezurl WHERE url='" . $db->escapeString( $urlText ) . "'"; 431 $urlArray = $db->arrayQuery( $checkURLQuery ); 432 433 if ( count( $urlArray ) == 1 ) 434 { 435 $urlRow =& $urlArray[0]; 436 $url = new eZURL( $urlRow ); 437 } 438 return $url; 439 } 440 } 441 442 ?>
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 |