[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" ); 7 8 /** 9 * This class represents a comment made by a casual user to an article. Please use the getter methods 10 * exposed here to get all the information regarding this comment, such as the name of the user who 11 * posted it, the email address and even the ip of the machine from which the comment was posted. 12 * 13 * \ingroup DAO 14 */ 15 class UserComment extends DbObject 16 { 17 18 var $_id; 19 var $_artid; 20 var $_userName; 21 var $_userEmail; 22 var $_userUrl; 23 var $_topic; 24 var $_text; 25 var $_date; 26 var $_parentid; 27 var $_clientIp; 28 var $_timeStamp; 29 var $_postInfo; 30 var $_spamRate; 31 var $_status; 32 var $_type; 33 var $_normalizedText; 34 var $_normalizedTopic; 35 var $_article; 36 var $_userId; 37 var $_user; 38 var $_blogInfo; 39 40 /** 41 * Creates a new user comment. 42 */ 43 function UserComment( $artid, $blogId, $parentid, $topic, $text, $date = null, $userName = "", $userEmail = "", $userUrl = "", $clientIp = "0.0.0.0", $spamRate = 0, $status = COMMENT_STATUS_NONSPAM, $properties = Array(), $id = -1 ) 44 { 45 46 47 $this->_topic = $topic; 48 $this->_text = $text; 49 $this->_artid = $artid; 50 $this->_parentid = $parentid; 51 52 $this->_userName = $userName; 53 $this->_userEmail = $userEmail; 54 $this->setUserUrl( $userUrl ); 55 56 $this->_clientIp = $clientIp; 57 58 $this->_id = $id; 59 60 $this->_spamRate = $spamRate; 61 $this->_status = $status; 62 63 if( $date == null ) { 64 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 65 66 $t = new Timestamp(); 67 $date = $t->getTimestamp(); 68 } 69 70 $this->setDate( $date ); 71 $this->_article = null; 72 73 // by default, we've got a user comment instead of a trackback 74 $this->_type = COMMENT_TYPE_COMMENT; 75 76 $this->_blogId = $blogId; 77 $this->_sendNotification = 0; 78 79 $this->_normalizedTopic = ''; 80 $this->_normalizedText = ''; 81 82 $this->setProperties( $properties ); 83 84 $this->_blogInfo = null; 85 86 $this->_fields = Array( 87 "article_id" => "getArticleId", 88 "blog_id" => "getBlogId", 89 "topic" => "getTopic", 90 "text" => "getText", 91 "date" => "getDate", 92 "user_email" => "getUserEmail", 93 "user_url" => "getUserUrl", 94 "user_name" => "getUserName", 95 "parent_id" => "getParentId", 96 "client_ip" => "getClientIp", 97 "send_notification" => "getSendNotification", 98 "status" => "getStatus", 99 "spam_rate" => "getSpamRate", 100 "type" => "getType", 101 "normalized_text" => "getNormalizedText", 102 "normalized_topic" => "getNormalizedTopic", 103 "properties" => "getProperties", 104 "user_id" => "getUserId" 105 ); 106 } 107 108 /** 109 * Returns the identifier assigned to this comment in the database. 110 * 111 * @return Returns an integer value representing the identifier. 112 */ 113 function getId() 114 { 115 return $this->_id; 116 } 117 118 /** 119 * Sets a new identifier. 120 * @private 121 */ 122 function setId( $newid ) 123 { 124 $this->_id = $newid; 125 } 126 127 /** 128 * Returns the article identifier to which this comment belongs. 129 * 130 * @return An integer value representing the article identifier. 131 */ 132 function getArticleId() 133 { 134 return $this->_artid; 135 } 136 137 /** 138 * Sets the article identifier. 139 * @private 140 */ 141 function setArticleId( $newartid ) 142 { 143 $this->_artid = $newartid; 144 } 145 146 /** 147 * Returns the name of the user who posted this comment. 148 * 149 * @return A string representing the name of the user, if any. 150 */ 151 function getUserName() 152 { 153 return $this->_userName; 154 } 155 156 /** 157 * Sets the username. 158 * @private 159 */ 160 function setUserName( $userName ) 161 { 162 $this->_userName = $userName; 163 } 164 165 /** 166 * Gets the email address of the user who posted this message, as it was posted by him or her, and if any. 167 * 168 * @return An string with the email address of the user. 169 */ 170 function getUserEmail() 171 { 172 return $this->_userEmail; 173 } 174 175 /** 176 * Sets the email address. 177 * @private 178 */ 179 function setUserEmail( $userEmail ) 180 { 181 $this->_userEmail = $userEmail; 182 } 183 184 /** 185 * Returns the address specified by the user in the post, if any. 186 * 187 * @return The url as specified by the user. 188 */ 189 function getUserUrl() 190 { 191 return $this->_userUrl; 192 } 193 194 /** 195 * Sets the user url. 196 * @private 197 */ 198 function setUserUrl( $userUrl ) 199 { 200 // fix from yousung 201 if ( $userUrl != null && eregi("http", $userUrl) == null ) 202 $userUrl = "http://".$userUrl; 203 204 $this->_userUrl = $userUrl; 205 } 206 207 /** 208 * Returns the text of the comment. 209 * 210 * @return A string with the text of the comment. 211 */ 212 function getText() 213 { 214 return $this->_text; 215 } 216 217 /** 218 * Sets the text of the comment. 219 * @private 220 */ 221 function setText( $newtext ) 222 { 223 $this->_text = $newtext; 224 } 225 226 /** 227 * Returns the topic of the comment. 228 * 229 * @return A string withthe topic of the comment. 230 */ 231 function getTopic() 232 { 233 return $this->_topic; 234 } 235 236 /** 237 * Sets the topic of the comment. 238 * @private 239 */ 240 function setTopic( $newtopic ) 241 { 242 $this->_topic = $newtopic; 243 } 244 245 /** 246 * Returns the 14-digit date as specified by the database. 247 * 248 * @return A 14-digit date, straight from the database. 249 */ 250 function getDate() 251 { 252 253 return $this->_date; 254 } 255 256 /** 257 * Sets a new date 258 * @private 259 */ 260 function setDate( $newdate ) 261 { 262 // source necessary source 263 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 264 265 $this->_date = $newdate; 266 267 // update the Timestamp object so that we can have more information 268 $this->_timeStamp = new Timestamp( $this->_date ); 269 } 270 271 /** 272 * Returns a Timestamp object representing the date. The Timestamp class offers commodity 273 * methods to access only some parts of the date, and to format it according to our tastes. 274 * 275 * @preturn A Timestamp object representing the date. 276 */ 277 function getDateObject() 278 { 279 return $this->_timeStamp; 280 } 281 282 /** 283 * Returns the identifier of the comment to which this one was replying. 284 * 285 * @return The identifier of the comment to which this one was replying, or 0 if it was not replying 286 * to any. 287 */ 288 function getParentId() 289 { 290 return $this->_parentid; 291 } 292 293 /** 294 * Sets the parent id. 295 * @private 296 */ 297 function setParentId( $parentId ) 298 { 299 return $this->_parentid; 300 } 301 302 /** 303 * Alias for the function getDateObject 304 * 305 * @see getDateObject 306 */ 307 function getTimestamp() 308 { 309 return $this->getDateObject(); 310 } 311 312 /** 313 * Returns an string representing the ip of the machine from which this comment 314 * was posted. It is not very reliable since that ip could have been through many 315 * proxies. 316 * 317 * @return A string representing the ip address. 318 */ 319 function getClientIp() 320 { 321 return $this->_clientIp; 322 } 323 324 /** 325 * Sets the ip address. 326 * @private 327 */ 328 function setClientIp( $clientIp ) 329 { 330 $this->_clientIp = $clientIp; 331 } 332 333 /** 334 * Sets the spamn rate of this comment 335 * 336 * @private 337 * @param spamRate The new spam rate 338 */ 339 function setSpamRate( $spamRate ) 340 { 341 $this->_spamRate = $spamRate; 342 } 343 344 /** 345 * @return Returns the spam rate of this comment 346 */ 347 function getSpamRate() 348 { 349 return $this->_spamRate; 350 } 351 352 /** 353 * Sets the status of this comment 354 * 355 * @param status The new status 356 */ 357 function setStatus( $status ) 358 { 359 $this->_status = $status; 360 } 361 362 /** 363 * @return Returns the new status of this comment 364 */ 365 function getStatus() 366 { 367 return $this->_status; 368 } 369 370 /** 371 * sets the Article object to which this comment belongs. WARNING: this value 372 * <b>IS NOT ALWAYS</b> initialized!!! The most common situation is that it is not initialized 373 * 374 * @param article An Article object 375 * @return Always true 376 */ 377 function setArticle( $article ) 378 { 379 $this->_article = $article; 380 381 return true; 382 } 383 384 /** 385 * returns the Article to which this comment belongs, or NULL if it has not been loaded 386 * 387 * @return An Article object or NULL if it has not been initialized 388 */ 389 function getArticle() 390 { 391 if( $this->_article == null ) { 392 $articles = new Articles(); 393 $this->_article = $articles->getArticle( $this->_artid ); 394 } 395 396 return( $this->_article ); 397 } 398 399 /** 400 * @return Returns the type of this comment, either COMMENT_TYPE_COMMENT or 401 * COMMENT_TYPE_TRACKBACK depending on whether the comment is a "normal" user comment 402 * or a trackback 403 */ 404 function getType() 405 { 406 return( $this->_type ); 407 } 408 409 /** 410 * sets the comment type 411 * 412 * @private 413 * @param type The new type: 414 * - COMMENT_TYPE_COMMENT 415 * - COMMENT_TYPE_TRACKBACK 416 */ 417 function setType( $type ) 418 { 419 $this->_type = $type; 420 } 421 422 function getSendNotification() 423 { 424 return( $this->_sendNotification ); 425 } 426 427 function setSendNotification( $sendNotification ) 428 { 429 if( $sendNotification == "" ) 430 $sendNotificaton = 0; 431 $this->_sendNotification = $sendNotification; 432 } 433 434 function getBlogId() 435 { 436 return( $this->_blogId ); 437 } 438 439 function setBlogId( $blogId ) 440 { 441 $this->_blogId = $blogId; 442 } 443 444 445 /** 446 * Alais for getUrl() 447 * 448 * Returns the permalink of the post that sent the trackback link. 449 * 450 * @return A string with the permalink. 451 */ 452 function getUrl() 453 { 454 return( $this->getUserUrl()); 455 } 456 457 /** 458 * Alias for getTopic() 459 * 460 * Returns the value of the title parameter, as in the trackback ping request. According to the definition 461 * of the trackback ping specification, it can be empty. 462 * 463 * @return The title of the entry. 464 */ 465 function getTitle() 466 { 467 return( $this->getTopic()); 468 } 469 470 /** 471 * Alias for getText(), which is only used by trackbacks. 472 * 473 * According to the specification of the trackback protocol, the excerpt is a short string giving 474 * more information about the entry related to the ping. Normally, it will be at most, the first 255 475 * characters of the entry, but it could also be empty since it is not mandatory. 476 * 477 * @return A string representing the excerpt. 478 */ 479 function getExcerpt() 480 { 481 return( $this->getText()); 482 } 483 484 /** 485 * Alias for getUserName() 486 * 487 * Returns the name of the blog which sent the trackback ping. 488 * 489 * @return A string containing the name of the blog which sent the trackback ping. 490 */ 491 function getBlogName() 492 { 493 return( $this->getUserName()); 494 } 495 496 /** 497 * Returns the BlogInfo object to which this comment/trackback is linked 498 * 499 * @param return A BlogInfo object 500 */ 501 function getBlogInfo() 502 { 503 if( $this->_blogInfo === null ) { 504 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" ); 505 $blogs = new Blogs(); 506 $this->_blogInfo = $blogs->getBlogInfo( $this->getBlogId()); 507 } 508 509 return( $this->_blogInfo ); 510 } 511 512 /** 513 * sets the normalized text 514 * 515 * @param normalizedText 516 */ 517 function setNormalizedText( $normalizedText ) 518 { 519 // do a normalization again, just in case 520 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 521 $this->_normalizedText = TextFilter::normalizeText( $normalizedText ); 522 } 523 524 /** 525 * returns the normalized text 526 * 527 * @return the normalized text 528 */ 529 function getNormalizedText() 530 { 531 if( $this->_normalizedText == "" ) { 532 $this->setNormalizedText( $this->getText()); 533 } 534 535 return( $this->_normalizedText ); 536 } 537 538 /** 539 * sets the normalized topic 540 * 541 * @param normalizedText 542 */ 543 function setNormalizedTopic( $normalizedTopic ) 544 { 545 // do a normalization again, just in case 546 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 547 $this->_normalizedTopic = TextFilter::normalizeText( $normalizedTopic ); 548 } 549 550 /** 551 * returns the normalized text 552 * 553 * @return the normalized text 554 */ 555 function getNormalizedTopic() 556 { 557 if( $this->_normalizedTopic == "" ) { 558 $this->setNormalizedTopic( $this->getTopic()); 559 } 560 561 return( $this->_normalizedTopic ); 562 } 563 564 /** 565 * Returns true if this comment was posted by an authenticated user 566 * 567 * @return True if poster was authenticated or false otherwise 568 */ 569 function IsPosterAuthenticated() 570 { 571 return( $this->getUser() != false ); 572 } 573 574 /** 575 * Returns the UserInfo object of the user who posted this comment or false if the comment 576 * wasn't posted by an authenticated user or if the user does not exist anymore 577 * 578 * @return An UserInfo object or false if the user doesn't exist anymore or poster was not 579 * authenticated when posting the comment 580 */ 581 function getUser() 582 { 583 if( $this->_userId != 0 ) { 584 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 585 $users = new Users(); 586 $this->_user = $users->getUserInfoFromId( $this->_userId ); 587 } 588 589 return( $this->_user ); 590 } 591 592 /** 593 * Returns the id of the user who posted this comment, or '0' if the comment was 594 * posted by a non-authenticated user 595 * 596 * @return Id of the user who posted this comment, '0' if the comment was posted 597 * by a non-authenticated user 598 */ 599 function getUserId() 600 { 601 return( $this->_userId ); 602 } 603 604 /** 605 * Sets the user id of the user who posted this comment 606 * 607 * @param id The user id of the poster, or 0 if the comment was posted by 608 * a non-authenticated user 609 */ 610 function setUserId( $id ) 611 { 612 $this->_userId = $id; 613 } 614 615 /** 616 * Sets the UserInfo object containing information about the user who posted this 617 * comment. 618 * 619 * @param userInfo A UserInfo object 620 */ 621 function setUser( $userInfo ) 622 { 623 $this->_user = $userInfo; 624 $this->_userId = $userInfo->getId(); 625 } 626 627 /** 628 * @private 629 */ 630 function __sleep() 631 { 632 $this->_userInfo = null; 633 return( parent::__sleep()); 634 } 635 } 636 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |