[ 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/blogsettings.class.php" ); 5 6 /** 7 * \ingroup DAO 8 * 9 * This is the representation of a blog. It contains all the information we need to know, 10 * such as the name of the blog, the owner, description, etc. 11 */ 12 class BlogInfo extends DbObject 13 { 14 15 var $_blog; 16 var $_owner; // owner id 17 var $_about; 18 var $_settings; 19 var $_id; 20 21 // More optional information for each blog. Only used when we load this data 22 var $_createDate; 23 var $_updateDate; 24 var $_totalPosts; 25 var $_totalComments; 26 var $_totalTrackbacks; 27 var $_ownerInfo; 28 var $_usersInfo; 29 var $_mangledBlog; 30 var $_customDomain; 31 32 // the TemplateSet representing the template set used by the blog 33 var $_templateSet; 34 35 // the Locale object 36 var $_locale; 37 var $_blogLocale; 38 39 // the status 40 var $_status; 41 42 // the blog category 43 var $_categoryId; 44 var $_category; 45 46 function BlogInfo( $blog, $owner, $about, $settings, $id = -1 ) 47 { 48 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 49 50 $this->DbObject(); 51 52 $this->setBlog( $blog ); 53 $this->_owner = $owner; 54 $this->_about = $about; 55 $this->_settings = $settings; 56 if( empty( $this->_settings ) ) 57 $this->_settings = new BlogSettings(); 58 59 $this->_id = $id; 60 61 $this->_createDate = ""; 62 $this->_updateDate = ""; 63 $this->_totalPosts = 0; 64 $this->_totalTrackbacks = 0; 65 $this->_totalComments = 0; 66 $this->_usersInfo = null; 67 68 $t = new Timestamp(); 69 $this->_createDate = $t->getTimestamp(); 70 $this->_updateDate = $t->getTimestamp(); 71 72 // no template set loaded 73 $this->_templateSet = null; 74 75 // default status is active 76 $this->_status = BLOG_STATUS_ACTIVE; 77 78 // values that are loaded on demand 79 $this->_ownerInfo = null; 80 81 // information about the blog category id 82 $this->_category = null; 83 $this->_categoryId = 0; 84 85 // show in the summary by default 86 $this->_showInSummary = true; 87 88 $this->_pk = "id"; 89 $this->_fields = Array( 90 "blog" => "getBlog", 91 "owner_id" => "getOwnerId", 92 "about" => "getUnformattedAbout", 93 "settings" => "getSettings", 94 "mangled_blog" => "getMangledBlogName", 95 "status" => "getStatus", 96 "show_in_summary" => "getShowInSummary", 97 "blog_category_id" => "getBlogCategoryId", 98 "create_date" => "getCreateDate", 99 "last_update_date" => "getUpdateDate", 100 "num_posts" => "getTotalPosts", 101 "num_comments" => "getTotalComments", 102 "num_trackbacks" => "getTotalTrackbacks", 103 "custom_domain" => "getCustomDomain" 104 ); 105 } 106 107 /** 108 * Returns the short name of the blog. 109 * 110 * @return A string with the short name of the blog. 111 */ 112 function getBlog() 113 { 114 return $this->_blog; 115 } 116 117 /** 118 * Returns the identifier of the user who owns this journal. 119 * 120 * @return An integer value representing the identifier of the user who owns this blog. 121 */ 122 function getOwnerId() 123 { 124 return $this->_owner; 125 } 126 127 /** 128 * Returns the identifier of the user who owns this journal. 129 * 130 * @return An integer value representing the identifier of the user who owns this blog. 131 * @deprecated Use getOwnerId() instead. 132 */ 133 function getOwner() 134 { 135 return $this->_owner; 136 } 137 138 /** 139 * Returns a longer and descriptive text about this blog. It can also be empty since it is 140 * configurable from within the "Blog Settings" in the administration interface. 141 * 142 * @param format Whether basic formatting should be applied to the text 143 * @return A string containing the more descriptive text about the journal. 144 */ 145 function getAbout( $format = true ) 146 { 147 $text = $this->_about; 148 149 if( $format ) { 150 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 151 $text = TextFilter::autoP( $text ); 152 } 153 154 return( $text ); 155 } 156 157 /** 158 * @return Returns the information about this blog without any formatting. 159 */ 160 function getUnformattedAbout() 161 { 162 return( $this->getAbout( false )); 163 } 164 165 /** 166 * Returns a BlogSettings object with information about the settings of the journal. 167 * @private 168 */ 169 function getSettings() 170 { 171 return $this->_settings; 172 } 173 174 function getSetting( $setting ) 175 { 176 return $this->_settings->getValue( $setting ); 177 } 178 179 /** 180 * returns a key from the blog settings 181 */ 182 function getValue( $value ) 183 { 184 if( !$this->_settings ) 185 return ""; 186 187 return $this->getSetting( $value ); 188 } 189 190 /** 191 * returns a key from the blog settings 192 */ 193 function setValue( $key, $value ) 194 { 195 if( !$this->_settings ) 196 return true; 197 198 $this->_settings->setValue( $key, $value ); 199 200 return true; 201 } 202 203 /** 204 * implemented from DbObject. Merges a list of properties with the current settings 205 * 206 * @param properties 207 */ 208 function addProperties( $properties ) 209 { 210 return $this->setProperties( $properties ); 211 } 212 213 /** 214 * adds an array of pairs (key,value) to the blog settings 215 */ 216 function setProperties( $properties ) 217 { 218 // nothing to do if we don't get an array as parameters 219 if( !is_array($properties)) 220 return true; 221 222 foreach( $properties as $key => $value ) { 223 $this->setValue( $key, $value ); 224 } 225 226 return true; 227 } 228 229 /** 230 * 231 */ 232 function getCreateDateObject() 233 { 234 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 235 return( new Timestamp( $this->_createDate )); 236 } 237 238 function getCreateDate() 239 { 240 return( $this->_createDate ); 241 } 242 243 function setCreateDate( $date ) 244 { 245 $this->_createDate = $date; 246 } 247 248 /** 249 */ 250 function getUpdateDateObject() 251 { 252 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" ); 253 return( new Timestamp( $this->_updateDate )); 254 } 255 256 function getUpdateDate() 257 { 258 return( $this->_updateDate ); 259 } 260 261 function setUpdateDate( $date ) 262 { 263 $this->_updateDate = $date; 264 } 265 266 /** 267 */ 268 function getTotalPosts() 269 { 270 return $this->_totalPosts; 271 } 272 273 /** 274 * @private 275 */ 276 function setTotalPosts( $totalPosts ) 277 { 278 $this->_totalPosts = $totalPosts; 279 } 280 281 /** 282 * @private 283 */ 284 function setTotalComments( $totalComments ) 285 { 286 $this->_totalComments = $totalComments; 287 } 288 289 /** 290 */ 291 function getTotalComments() 292 { 293 return $this->_totalComments; 294 } 295 296 /** 297 * @private 298 */ 299 function setTotalTrackbacks( $totalTrackbacks ) 300 { 301 $this->_totalTrackbacks = $totalTrackbacks; 302 } 303 304 /** 305 */ 306 function getTotalTrackbacks() 307 { 308 return $this->_totalTrackbacks; 309 } 310 311 /** 312 * Gets information about the owner of this blog 313 * @return return a UserInfo object which contains much more info about the owner of the blog 314 */ 315 function getOwnerInfo() 316 { 317 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 318 319 if( $this->_ownerInfo === null ) { 320 $users = new Users(); 321 $ownerInfo = $users->getUserInfoFromId( $this->_owner ); 322 $this->setOwnerInfo( $ownerInfo ); 323 } 324 325 return $this->_ownerInfo; 326 } 327 328 /** 329 * Return information about all the users who belong to this blog. 330 * 331 * @return An array of UserInfo objects 332 * @see UserInfo 333 */ 334 function getUsersInfo() 335 { 336 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 337 338 if( $this->_usersInfo === null ) { 339 $users = new Users(); 340 $blogUsers = $users->getBlogUsers( $this->getId()); 341 $this->setUsersInfo( $blogUsers ); 342 } 343 344 return $this->_usersInfo; 345 } 346 347 /** 348 * Returns the identifier of this blog. 349 * 350 * @return An integer value with the identifier of this blog. 351 */ 352 function getId() 353 { 354 return $this->_id; 355 } 356 357 /** 358 * @private 359 */ 360 function setBlog( $blog ) 361 { 362 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 363 364 $tf = new Textfilter(); 365 $this->_blog = $tf->filterAllHTML($blog); 366 } 367 368 /** 369 * @param owner id 370 * @private 371 */ 372 function setOwner( $owner ) 373 { 374 $this->_owner = $owner; 375 } 376 377 /** 378 * @private 379 */ 380 function setAbout( $about ) 381 { 382 $this->_about = $about; 383 } 384 385 /** 386 * @private 387 */ 388 function setSettings( $settings ) 389 { 390 $this->_settings = $settings; 391 } 392 393 /** 394 * @private 395 */ 396 function setOwnerInfo( $newOwnerInfo ) 397 { 398 $this->_ownerInfo = $newOwnerInfo; 399 } 400 401 /** 402 * @private 403 */ 404 function setUsersInfo( $newUsersInfo ) 405 { 406 $this->_usersInfo = $newUsersInfo; 407 } 408 409 /** 410 * @private 411 */ 412 function setId( $id ) 413 { 414 $this->_id = $id; 415 } 416 417 /** 418 * returns the name of the template used by this blog 419 * 420 * @param the name of the template set used by this blog 421 */ 422 function getTemplate() 423 { 424 return $this->getSetting( "template"); 425 } 426 427 /** 428 * sets the template name 429 * 430 * @param template The name of the template that we'd like to use 431 * @return always true 432 */ 433 function setTemplate( $template ) 434 { 435 // save the template in the settings 436 $this->_settings->setValue( "template", $template ); 437 // and reset the TemplateSet object so that it gets reloaded next time 438 // somebody uses BlogInfo::getTemplateSet 439 $this->_templateSet = null; 440 441 return true; 442 } 443 444 /** 445 * this method is some kind of a shortcut for a very common operation: obtaining the 446 * correct RequestGenerator object so that we can generate urls based on the information 447 * from this blog. This is very handy for example in the summary page where we have to 448 * generate lots of different urls for lots of different blogs. 449 * 450 * @return A RequestGenerator object 451 */ 452 function getBlogRequestGenerator() 453 { 454 lt_include( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" ); 455 456 return RequestGenerator::getRequestGenerator( $this ); 457 } 458 459 /** 460 * returns a TemplateSet object with the information about the template used 461 * by the blog 462 * 463 * @return a TemplateSet object 464 */ 465 function getTemplateSet() 466 { 467 // since including these files is quite a costly operation, let's do it only 468 // whenever we have to instead of always and always always... :) 469 if( $this->_templateSet === null ) { 470 lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" ); 471 $ts = new TemplateSets(); 472 $this->_templateSet = $ts->getTemplateSet( $this->getTemplate(), $this->getId()); 473 if( $this->_templateSet == null ) { 474 // what if the admin removes the current template set used by this blog??? 475 $this->_templateSet = $ts->getDefaultTemplateSet(); 476 } 477 } 478 479 return $this->_templateSet; 480 } 481 482 /** 483 * changes the template set used by the blog 484 * 485 * @param templateSet A TemplateSet object 486 * @return always true 487 */ 488 function setTemplateSet( $templateSet ) 489 { 490 $this->setTemplate( $templateSet->getName()); 491 492 return true; 493 } 494 495 /** 496 * returns the right locale object for the blog 497 * 498 * @param a Locale object 499 */ 500 function &getLocale() 501 { 502 if( $this->_locale === null ) { 503 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); 504 $this->_locale =& Locales::getLocale( $this->getSetting( "locale" ), "en_UK" ); 505 } 506 507 return $this->_locale; 508 } 509 510 function &getBlogLocale() 511 { 512 if( $this->_blogLocale === null ) { 513 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); 514 $this->_blogLocale =& Locales::getBlogLocale( $this->getSetting( "locale" ), "en_UK" ); 515 } 516 517 return $this->_blogLocale; 518 } 519 520 521 /** 522 * sets the new locale for the blog 523 * 524 * @param a valid Locale object 525 * @return Always true 526 */ 527 function setLocale( $locale ) 528 { 529 $this->_locale = $locale; 530 $this->_settings->setValue( "locale", $locale->getLocaleCode()); 531 532 return true; 533 } 534 535 /** 536 * returns the status of the blog 537 * 538 * @return the current status of the blog 539 */ 540 function getStatus() 541 { 542 return $this->_status; 543 } 544 545 /** 546 * sets the current status of the blog 547 * 548 * @param status 549 * @return always true 550 */ 551 function setStatus( $status ) 552 { 553 $this->_status = $status; 554 555 return true; 556 } 557 558 /** 559 * returns the quota for this blog, or the value of the global quota 560 * for blogs in case this blog has no quota assigned 561 * 562 * @return the resources quota 563 */ 564 function getResourcesQuota() 565 { 566 $quota = $this->getSetting( "resources_quota" ); 567 568 // if there is no quota for this blog, then fetch it from the global 569 // settings 570 if( $quota == "" ) { 571 lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcequotas.class.php" ); 572 $quota = GalleryResourceQuotas::getGlobalResourceQuota(); 573 } 574 575 return $quota; 576 } 577 578 /** 579 * sets the quota 580 * 581 * @param quota 582 */ 583 function setResourcesQuota( $quota ) 584 { 585 $this->_settings->setValue( "resources_quota", $quota ); 586 587 return true; 588 } 589 590 /** 591 * returns the blog category id. You shouldn't probably use this method, 592 * BlogInfo::getBlogCategory() will return the real BlogCategory object for you. 593 * 594 * @return the blog category id 595 */ 596 function getBlogCategoryId() 597 { 598 return( $this->_categoryId ); 599 } 600 601 /** 602 * sets the blog category id 603 * 604 * @param the new id 605 */ 606 function setBlogCategoryId( $categoryId ) 607 { 608 if( $categoryId != $this->_categoryId ) 609 $this->_category = null; 610 611 $this->_categoryId = $categoryId; 612 } 613 614 /** 615 * loads the blog category 616 * 617 * @return A BlogCategory object 618 */ 619 function getBlogCategory() 620 { 621 // check if the category has already been loaded and if not, load it and save a reference 622 // to it in the object 623 if( $this->_categoryId == 0 ) 624 return( false ); 625 626 if( $this->_category == null ) { 627 lt_include( PLOG_CLASS_PATH."class/dao/blogcategories.class.php" ); 628 $blogCategories = new BlogCategories(); 629 $this->_category = $blogCategories->getBlogCategory( $this->_categoryId ); 630 } 631 632 return( $this->_category ); 633 } 634 635 /** 636 * set the mangled name of this blog 637 * 638 * @param mangledBlog the new mangled blog name 639 */ 640 function setMangledBlogName( $mangledBlog, $modify = false ) 641 { 642 if( $modify ) { 643 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 644 $mangledBlog = Textfilter::domainize( $mangledBlog ); 645 } 646 $this->_mangledBlog = $mangledBlog; 647 } 648 649 /** 650 @return the mangled name of this blog 651 */ 652 function getMangledBlogName() 653 { 654 // fill in the field if it hasn't been filled yet 655 if( $this->_mangledBlog === null ) { 656 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 657 $this->setMangledBlogName( $this->getBlog(), true ); 658 } 659 660 return( $this->_mangledBlog ); 661 } 662 663 664 /** 665 * set the custom domain of this blog 666 * 667 * @param customDomain the new custom domain 668 */ 669 function setCustomDomain($customDomain) 670 { 671 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 672 $this->_customDomain = Textfilter::domainize($customDomain); 673 } 674 675 /** 676 @return the custom domain of this blog 677 */ 678 function getCustomDomain() 679 { 680 // fill in the field if it hasn't been filled yet 681 if($this->_customDomain === null){ 682 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 683 $this->_customDomain = Textfilter::domainize($this->getMangledBlog()); 684 } 685 686 return($this->_customDomain); 687 } 688 689 /** 690 * @see getMangledBlogName 691 * Alias for the method above 692 */ 693 function getMangledBlog() 694 { 695 return( $this->getMangledBlogName()); 696 } 697 698 /** 699 * @return whether this blog should be shown in the summary page 700 */ 701 function getShowInSummary() 702 { 703 return( $this->_showInSummary ); 704 } 705 706 /** 707 * Whether to show this blog in the summary page or not. 708 * 709 * @param showInSummary 710 */ 711 function setShowInSummary( $showInSummary ) 712 { 713 $this->_showInSummary = $showInSummary; 714 } 715 716 /** 717 * @private 718 */ 719 function __sleep() 720 { 721 $this->_ownerInfo = null; 722 $this->_usersInfo = null; 723 $this->_category = null; 724 $this->_locale = null; 725 $this->_blogLocale = null; 726 //return( get_object_vars( $this )); 727 return( parent::__sleep()); 728 } 729 } 730 ?>
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 |
![]() |