[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/dao/ -> article.class.php (source)

   1  <?php
   2      lt_include( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
   3      lt_include( PLOG_CLASS_PATH.'class/dao/articlestatus.class.php' );
   4      lt_include( PLOG_CLASS_PATH.'class/dao/articlecommentstatus.class.php' );
   5  
   6      define( 'POST_EXTENDED_TEXT_MODIFIER', '[@more@]' );
   7  
   8      /**
   9       * \ingroup DAO
  10       * This class represents an article from the database, and provides methods to access all its objects.
  11       */
  12      class Article extends DbObject 
  13      {
  14  
  15          /**
  16           * Private members. Use the getXXX classes to access them
  17           * @private
  18           */
  19          var $_id;
  20          var $_topic;
  21          var $_text;
  22          var $_categoryIds;
  23          var $_categories;
  24          var $_user;
  25          var $_date;
  26          var $_modificationDate;
  27          var $_timestamp;
  28          var $_modificationTimestamp;
  29          var $_comments;
  30          var $_userInfo;
  31          var $_blog;
  32          var $_blogInfo;
  33          var $_status;
  34          var $_totalComments;
  35          var $_numComments;
  36          var $_numReads;
  37          var $_numTrackbacks;
  38          var $_totalTrackbacks;
  39          var $_properties;
  40          var $_timeOffset;
  41          var $_customFields;
  42          var $_trackbacks;
  43          var $_slug;
  44          var $_nextArticle;
  45          var $_prevArticle;
  46          var $_globalCategory;
  47          var $_inSummary;
  48  
  49          /**
  50           * Constructor.
  51           *
  52           * @param topic Topic of the article
  53           * @param text Text of the article
  54           * @param categories An array with the ids of all the categories to which this article belongs
  55           * @param user Identifier of the user who posted the article
  56           * @param blog Identifier of the blog to which the article belongs
  57           * @param status Can be either POST_STATUS_PUBLISHED, POST_STATUS_DRAFT or POST_STATUS_DELETED
  58           * @param numReads How many times the article has been read.
  59           * @param properties An associative array containing some settings for the post,
  60           * such as if comments are enabled/disabled, if it's a private or public post,
  61           * or its password.
  62           * @param id If present, the identifier of the article in the database
  63           */
  64  		function Article( $topic, $text, $categories, $user, $blog, $status, $numReads, $properties = Array(), $slug = "", $id = -1 )
  65          {
  66              lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
  67  
  68              $this->_topic    = $topic;
  69              $this->_text     = $text;
  70              $this->_categoryIds = $categories;
  71              $this->_categories = null;
  72              $this->_user     = $user;
  73              $this->_blog     = $blog;
  74              $this->_id       = $id;
  75              $this->_status   = $status;
  76              $this->_comments = null;
  77              $this->_totalComments = 0;
  78              $this->_numComments = 0;
  79              $this->_numTrackbacks = 0;
  80              $this->_totalTrackbacks = 0;
  81              $this->_numReads = $numReads;
  82              if($slug == "")
  83                  $this->setPostSlug($topic);
  84              else 
  85                  $this->setPostSlug($slug);
  86              
  87              // by default it'll have current time
  88              $this->_timestamp = new Timestamp();
  89              $this->_date      = $this->_timestamp->getTimestamp();
  90              $this->_modificationTimestamp = new Timestamp();
  91              $this->_modificationDate = $this->_timestamp->getTimestamp();
  92              //$this->_timestamp = 0;
  93              //$this->_date = 0;
  94              $this->_properties = $properties;
  95              $this->_timeOffset = 0;
  96              $this->_customFields = null;
  97              $this->_trackbacks = null;
  98              $this->_userInfo = null;
  99              $this->_blogInfo = null;
 100              $this->_globalCategoryId = 0;
 101              $this->_inSummary = true;
 102  
 103              $this->_pk = "id";
 104              $this->_fields = Array(
 105                  "date" => "getDateWithoutOffset",
 106                  "modification_date" => "getModificationDateWithoutOffset",
 107                  "user_id" => "getUserId",
 108                  "blog_id" => "getBlogId",
 109                  "status" => "getStatus",
 110                  "num_reads" => "getNumReads",
 111                  "properties" => "getProperties",
 112                  "slug" => "getPostSlug",
 113                  "num_comments" => "getTotalComments",
 114                  "num_trackbacks" => "getTotalTrackbacks",
 115                  "num_nonspam_trackbacks" => "getNumTrackbacks",
 116                  "num_nonspam_comments" => "getNumComments",
 117                  "global_category_id" => "getGlobalCategoryId",
 118                  "in_summary_page" => "getInSummary"
 119              );        
 120          }
 121  
 122          /**
 123           * Returns the topic of the article
 124           * @return The topic
 125           */
 126  		function getTopic()
 127          {
 128              return $this->_topic;
 129          }
 130  
 131          /**
 132           * Returns the text of the article
 133           * @param replace a string, usually html syntax, to "split"
 134           * the intro and the extended text. Default is <br/>.
 135           * @return The text
 136           */
 137  		function getText( $replace = '' )
 138          {
 139              if( $replace !== false )
 140                  return str_replace( POST_EXTENDED_TEXT_MODIFIER, $replace, $this->_text );
 141              else
 142                  return $this->_text;
 143          }
 144  
 145          /**
 146           * returns the intro text for the post
 147           * 
 148           * @return The intro text for the post
 149           */
 150          function getIntroText()
 151          {
 152              $postParts = explode( POST_EXTENDED_TEXT_MODIFIER, $this->_text );
 153              return $postParts[0];
 154          }
 155          
 156          /**
 157           * sets the intro text
 158           *
 159           * @param introText the new intro text
 160           */
 161  		function setIntroText( $introText )
 162          {
 163              $postParts = explode( POST_EXTENDED_TEXT_MODIFIER, $this->_text );
 164              if( $this->hasExtendedText())
 165                  $this->_text = $introText.POST_EXTENDED_TEXT_MODIFIER.$postParts[1];
 166              else
 167                  $this->setText( $introText );
 168                  
 169              return true;
 170          }
 171  
 172          /**
 173           * returns the extended text
 174           *
 175           * @return the extended text, if any.
 176           */
 177          function getExtendedText()
 178          {
 179              $postParts = explode( POST_EXTENDED_TEXT_MODIFIER, $this->_text );
 180              $extendedText = "";
 181              if ( count($postParts) > 1 )
 182              {
 183                  $extendedText = $postParts[1];
 184              }
 185              return $extendedText;
 186          }
 187          
 188          /**
 189           * sets the extended text
 190           *
 191           * @param extendedText the new extended text
 192           */
 193  		function setExtendedText( $extendedText )
 194          {
 195              $postParts = explode( POST_EXTENDED_TEXT_MODIFIER, $this->_text );
 196              $this->_text = $postParts[0].POST_EXTENDED_TEXT_MODIFIER.$extendedText;
 197              
 198              return true;
 199          }        
 200  
 201          /**
 202           * returns whether this article has extended text or not
 203           *
 204           * @return true if this article has extended text or false otherwise
 205           */
 206          function hasExtendedText()
 207          {
 208              $extendedText = trim($this->getExtendedText());
 209              if($extendedText == "<br />" || $extendedText == "<br/>" ||
 210                 $extendedText == "<p/>" || $extendedText == "<p />" ||
 211                 $extendedText == "" ) 
 212                  return false;
 213              else
 214                  return( strlen($this->getExtendedText()) > 0 );
 215          }
 216          
 217          /** 
 218           * returns an array with all the category ids that this post has
 219           *
 220           * @return An array of category ids
 221           */
 222  		function getCategoryIds()
 223          {
 224            return $this->_categoryIds;
 225          }
 226  
 227          /**
 228           * Returns the ArticleCategory object.
 229           *
 230           * @return The ArticleCategory object.
 231           */
 232          function getCategories()
 233          {
 234              if( $this->_categories == null ) {
 235                  lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );                    
 236                  $categories = new ArticleCategories();
 237                  foreach( $this->getCategoryIds() as $categoryId ) {
 238                      if(( $category = $categories->getCategory( $categoryId )))
 239                          $this->_categories[] = $category;
 240                  }
 241              }
 242              
 243              return $this->_categories;
 244          }
 245          
 246          /**
 247           * this method will return the first category of the article, but it's here only
 248           * for compatibility reasons!!! Please use getCategories and then loop through the 
 249           * returned array
 250           *
 251           * @return an ArticleCategory object
 252           */
 253  		function getCategory()
 254          {
 255              return $this->_categories[0];
 256          }
 257  
 258          /**
 259           * Returns the identifier assigned to this article.
 260           *
 261           * @return An integer value representing the identifier.
 262           */
 263  		function getId()
 264          {
 265              return $this->_id;
 266          }
 267  
 268          /**
 269           * The identifier of the user who posted this comment
 270           *
 271           * NOTE: This is rather disturbing, i would expect to get a User Object
 272           * when calling getUser(), i've added getUserId() which is more 
 273           * precise, but left this one in here to stay backward compatible.
 274           *
 275           * @deprecated Use getUserId() instead
 276           * @return An integer value representing the user idenfitier.
 277           * @see getUserInfo
 278           */
 279  		function getUser()
 280          {
 281              return $this->_user;
 282          }
 283  
 284          /**
 285           * Returns the identifier of the user who posted this article
 286           *
 287           * @return An integer
 288           */
 289          function getUserId()
 290          {
 291              return $this->_user;
 292          }
 293  
 294          /**
 295           * Returns the date, 14-digit format straight from the database.
 296           *
 297           * @return The 14-digit representation of the date.
 298           */
 299  		function getDate()
 300          {
 301              return $this->_date;
 302          }
 303          
 304          /**
 305           * Return the date without the time offset applied. This is used so that we don't save
 306           * the wrong date to the database when updating this post. For general purpose date queries,
 307           * you don't need to use this method, please use getDate.
 308           *
 309           * @return an SQL timestamp
 310           * @see getDate
 311           */
 312  		function getDateWithoutOffset()
 313          {
 314              // get the offset
 315              $offset = $this->getTimeOffset();
 316              // and calculate the date without offset
 317              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 318              $date = Timestamp::getDateWithOffset( $this->getDate(), -$offset );            
 319              return( $date );
 320          }
 321  
 322          /**
 323           * Returns an array of UserComment objects, with all the comments that have been received for
 324           * this article.
 325           *
 326           * @param onlyActive return only those comments that are not marked as spam
 327           * @return An array of UserComment objects.
 328           * @see UserComment
 329           */
 330  		function getComments( $status = COMMENT_STATUS_NONSPAM )
 331          {
 332              // load the comments if they haven't been loaded yet
 333              if( is_null( $this->_comments[$status] )) {
 334                  lt_include( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );            
 335                  $userComments =  new ArticleComments();
 336                  $blogInfo = $this->getBlogInfo();
 337                  $blogSettings = $blogInfo->getSettings();
 338                  $this->setComments( $userComments->getPostComments( $this->getId(), $blogSettings->getValue( 'comments_order' ), $status ), $status );
 339              }    
 340              return( $this->_comments[$status] );
 341          }
 342          
 343          /**
 344           * Returns an array of Trackback objects, with all the trackbacks that have been received for
 345           * this article.
 346           *
 347           * @param onlyActive return only those trackbacks that are not marked as spam         
 348           * @return An array of Trackback objects.
 349           * @see Trackback
 350           */
 351  		function getTrackbacks( $onlyActive = true )
 352          {
 353              // load the comments if they haven't been loaded yet
 354              if( is_null($this->_trackbacks) ) {    
 355                  lt_include( PLOG_CLASS_PATH.'class/dao/trackbacks.class.php' );            
 356                  $trackbacks =  new Trackbacks();
 357                  $blogInfo = $this->getBlogInfo();
 358                  $blogSettings = $blogInfo->getSettings();
 359                  $this->setTrackbacks( $trackbacks->getArticleTrackBacks( $this->getId(), 
 360                                                                           COMMENT_STATUS_ALL ));
 361              }
 362  
 363              // if we only want to return the active ones, then we have to loop through
 364              // the array once more            
 365              if( $onlyActive ) {
 366                  $tbs = Array();
 367                  foreach( $this->_trackbacks as $trackback ) {
 368                      if( $trackback->getStatus() == COMMENT_STATUS_NONSPAM )
 369                          $tbs[] = $trackback;
 370                  }
 371              }
 372              else
 373                  $tbs = $this->_trackbacks;
 374                  
 375              return( $tbs );
 376          }        
 377  
 378          /**
 379           * Returns the UserInfo object containing information about the owner of this post.
 380           *
 381           * @return A UserInfo object.
 382           * @see UserInfo
 383           */
 384  		function getUserInfo()
 385          {
 386              // load the user if it hasn't been loaded yet
 387              if( is_null($this->_userInfo) ) {
 388                  lt_include( PLOG_CLASS_PATH.'class/dao/users.class.php' );
 389                  $users = new Users();
 390                  $this->setUserInfo( $users->getUserInfoFromId( $this->getUser()));
 391              }
 392          
 393              return $this->_userInfo;
 394          }
 395  
 396  
 397          /**
 398           * Returns the blog identifier to which this article belongs.
 399           *
 400           * NOTE: This is rather disturbing, i would expect to get a Blog Object
 401           * when calling getBlog(), i've added getBlogId() which is more 
 402           * precise, but left this one in here to stay backward compatible.
 403           *
 404           * @deprecated Use getBlogId() instead
 405           * @return An integer value representing the blog identifier.
 406           * @see getBlogInfo
 407           */
 408  		function getBlog()
 409          {
 410              return $this->_blog;
 411          }
 412  
 413          /**
 414           * Returns the blog identifier to which this article belongs.
 415           *
 416           * @return An integer value representing the blog identifier.
 417           * @see getBlogInfo
 418           */
 419          function getBlogId()
 420          {
 421              return $this->_blog;
 422          }
 423  
 424          /**
 425           * Returns the status of the article:
 426           * <ul><li>published</li><li>draft</li><li>deleted</li></ul>
 427           *
 428           * @return A string value representing the status of the post.
 429           */
 430  		function getStatus()
 431          {
 432              return $this->_status;
 433          }
 434  
 435          /**
 436           * Returns the BlogInfo object with information regarding the blog to which this
 437           * article belongs.
 438           *
 439           * @return The BlogInfo object.
 440           * @see BlogInfo
 441           */
 442  		function getBlogInfo()
 443          {
 444              if( $this->_blogInfo == null ) {
 445                  lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
 446                  $blogs = new Blogs();
 447                  $this->_blogInfo = $blogs->getBlogInfo( $this->getBlogId());
 448              }
 449              
 450              return( $this->_blogInfo );
 451          }
 452  
 453          /**
 454           * Returns the number of times this article has been visited.
 455           *
 456           * @return An integer value representing the number of times this article has been read.
 457           */
 458          function getNumReads()
 459          {
 460              return $this->_numReads;
 461          }
 462  
 463          /**
 464           * Returns the properties array
 465           *
 466           * @return An associative array
 467           */
 468          function getProperties()
 469          {
 470              return $this->_properties;
 471          }
 472  
 473          /**
 474           * returns whether comments are enabled or not
 475           *
 476           * @return true if comments are enabled for this post or false otherwise
 477           */
 478          function getCommentsEnabled()
 479          {
 480              if( isset( $this->_properties["comments_enabled"] ) )
 481                  $commentsEnabled = $this->_properties["comments_enabled"];
 482              else
 483                  $commentsEnabled = "";
 484                  
 485              if( $commentsEnabled == "" )
 486                  $commentsEnabled = false;
 487  
 488              return $commentsEnabled;
 489          }
 490  
 491          /**
 492           * @private
 493           */
 494  		function setUserInfo( $newUserInfo )
 495          {
 496              $this->_userInfo = $newUserInfo;
 497          }
 498  
 499          /**
 500           * @private
 501           */
 502  		function setTopic( $newTopic )
 503          {
 504              $this->_topic = $newTopic;
 505          }
 506  
 507          /**
 508           * @private
 509           */
 510  		function setText( $newText )
 511          {
 512              $this->_text = $newText;
 513          }
 514  
 515          /**
 516           * Changes the category id
 517           * @private
 518           */
 519  		function setCategoryIds( $newCategories )
 520          {
 521              $this->_categoryIds = $newCategories;
 522          }
 523  
 524          /**
 525           * @private
 526           */
 527          function setCategories( $categories )
 528          {
 529              $this->_categories = $categories;
 530          }
 531  
 532          /**
 533           * @private
 534           */
 535  		function setId( $newId )
 536          {
 537              $this->_id = $newId;
 538          }
 539  
 540          /**
 541           * @private
 542           */
 543  		function setUser( $newUser )
 544          {
 545              $this->_user = $newUser;
 546          }
 547  
 548          /**
 549           * @private
 550           */
 551  		function setComments( $comments, $status = COMMENT_STATUS_NONSPAM )
 552          {
 553              if( !isset( $this->_comments[$status] ))
 554                  $this->_comments[$status] = Array();
 555                  
 556              $this->_comments[$status] = $comments;
 557              
 558              return true;
 559          }
 560          
 561          /**
 562           * @private
 563           */
 564  		function setTrackbacks( $trackbacks )
 565          {
 566              $this->_trackbacks = $trackbacks;
 567              if( !is_array( $this->_trackbacks ))
 568                  $this->_trackbacks = Array();
 569              
 570              return true;
 571          }
 572          
 573  
 574          /**
 575           * @private
 576           */
 577  		function setBlog( $blog )
 578          {
 579              $this->_blog;
 580          }
 581  
 582          /**
 583           * @private
 584           */
 585  		function setStatus( $status )
 586          {
 587              $this->_status = $status;
 588          }
 589  
 590          /**
 591           * Returns true wether this post has the 'DRAFT' status.
 592           *
 593           * @return True if the post is a draft or false otherwise.
 594           */
 595          function isDraft()
 596          {
 597              return( $this->_status == POST_STATUS_DRAFT );
 598          }
 599  
 600          /**
 601           * Returns true wether this post has been deleted or not (status == DELETED)
 602           *
 603           * @return True if the post as deleted or false otherwise.
 604           */
 605          function isDeleted()
 606          {
 607              return( $this->_status == POST_STATUS_DELETED );
 608          }
 609  
 610          /**
 611           * Returns true wether this post has been published or not (status == PUBLISHED)
 612           *
 613           * True if the post has been published or false otherwise.
 614           */
 615          function isPublished()
 616          {
 617              return( $this->_status == POST_STATUS_PUBLISHED );
 618          }
 619  
 620          /**
 621           * Returns the total number of comments that this post has (only the number!!)
 622           *
 623           * @return An integer containing the total number of comments that this post has.
 624           */
 625  		function getTotalComments()
 626          {
 627              return( $this->_totalComments );
 628          }
 629          
 630          /**
 631           * Returns the number of comments that this post has (only the number!!)
 632           *
 633           * @return An integer containing the number of comments that this post has.
 634           */
 635  		function getNumComments()
 636          {
 637              return( $this->_numComments );
 638          }        
 639  
 640          /**
 641           * Returns the total number of trackback pings that this post has received.
 642           *
 643           * @return An integer representing the number of trackback pings.
 644           */
 645  		function getTotalTrackbacks()
 646          {
 647              return( $this->_totalTrackbacks );
 648          }
 649          
 650          /**
 651           * Returns the number of trackback pings that this post has received.
 652           *
 653           * @param onlyActive return only the number of active (as in non-spam, etc)         
 654           * @return An integer representing the number of trackback pings.
 655           */        
 656  		function getNumTrackbacks()
 657          {
 658              return( $this->_numTrackbacks );
 659          }
 660  
 661          /**
 662           * sets the total number of active comments
 663           *
 664           * @private
 665           */
 666          function setTotalComments( $totalComments )
 667          {
 668              $this->_totalComments = $totalComments;
 669          }
 670          
 671          /**
 672           * @private
 673           */
 674          function setNumComments( $numComments )
 675          {
 676              $this->_numComments = $numComments;
 677          }
 678          
 679          /**
 680           * @private
 681           */
 682          function setNumTrackbacks( $numTrackbacks )
 683          {
 684              $this->_numTrackbacks = $numTrackbacks;
 685          }
 686          
 687          /**
 688           * @private
 689           */
 690          function setTotalTrackbacks( $totalTrackbacks )
 691          {
 692              $this->_totalTrackbacks = $totalTrackbacks;
 693          }        
 694  
 695          /**
 696           * @private
 697           */
 698  		function setDate( $newDate )
 699          {
 700              lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
 701  
 702              $this->_date = $newDate;
 703  
 704              $this->_timestamp = new Timestamp( $newDate );
 705          }
 706          
 707          /**
 708           * Sets the date in which this article was last modified.
 709           *
 710           * @param newDate a 14-digit date in SQL's TIMESTAMP format.
 711           */
 712  		function setModificationDate( $newDate )
 713          {
 714              $this->_modificationDate = $newDate;
 715              $this->_modificationTimestamp = new Timestamp( $newDate );
 716          }
 717          
 718          /**
 719           * Returns the date when the post was last modified
 720           *
 721           * @return an SQL timestamp
 722           */
 723  		function getModificationDate()
 724          {
 725              return( $this->_modificationDate );
 726          }
 727          
 728          /**
 729           * Return the date without the time offset applied. This is used so that we don't save
 730           * the wrong date to the database when updating this post. For general purpose date queries,
 731           * you don't need to use this method, please use getDate.
 732           *
 733           * @return an SQL timestamp
 734           * @see getDate
 735           */
 736  		function getModificationDateWithoutOffset()
 737          {
 738              // get the offset
 739              $offset = $this->getTimeOffset();
 740              // and calculate the date without offset
 741              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
 742              $date = Timestamp::getDateWithOffset( $this->getModificationDate(), -$offset );            
 743              return( $date );
 744          }
 745  
 746          /**
 747           * Returns the date when the post was last modified as a Timestamp object
 748           *
 749           * @return a Timestamp object
 750           * @see Timestamp
 751           */        
 752  		function getModificationTimestamp()
 753          {
 754              return( $this->_modificationTimestamp );
 755          }
 756  
 757          /**
 758           * Returns the Timestamp object representing the date when this post was posed.
 759           *
 760           * @see Timestamp
 761           * @return A Timestamp object representing the date.
 762           */
 763  		function getDateObject()
 764          {
 765              return $this->_timestamp;
 766          }
 767  
 768          /**
 769           * @private
 770           */
 771  		function setBlogInfo( $blogInfo )
 772          {
 773              $this->_blogInfo = $blogInfo;
 774          }
 775  
 776          /**
 777           * @private
 778           */
 779          function setNumReads( $numReads )
 780          {
 781              $this->_numReads = $numReads;
 782          }
 783  
 784          /**
 785           * sets a new Timestamp object for this post, so that we can
 786           * change the date of the post if necessary.
 787           */
 788          function setDateObject( $newTimestamp )
 789          {
 790              $this->_timestamp = $newTimestamp;
 791              $this->_date      = $this->_timestamp->getTimestamp();
 792          }
 793  
 794          /**
 795           * @private
 796           */
 797          function setProperties( $properties )
 798          {
 799              $this->_properties = $properties;
 800          }
 801  
 802          /**
 803           * enables or disables comments
 804           *
 805           * @param commentsEnabled Set it to true to enable comments or to false to disable them
 806           */
 807          function setCommentsEnabled( $commentsEnabled )
 808          {
 809              $this->_properties["comments_enabled"] = $commentsEnabled;
 810  
 811              return true;
 812          }
 813          
 814          /**
 815           * sets the time offset
 816           *
 817           * @param timeOffset
 818           */
 819  		function setTimeOffset( $timeOffset )
 820          {
 821              $this->_timeOffset = $timeOffset;
 822          }
 823          
 824          /**
 825           * gets the time offset
 826           *
 827           * @return the time offset
 828           */
 829  		function getTimeOffset()
 830          {
 831              return $this->_timeOffset;
 832          }
 833          
 834          /**
 835           * Sets the values that this post has for the custom fields that have been defined so far.
 836           *
 837           * @param fields An array of CustomFieldValue objects containing some information about the
 838           * type of the field, and its value
 839           * @see CustomFieldValues
 840           * @see CustomFieldValue
 841           * @see CustomFieldDefinitions
 842           * @see CustomFieldDefinition
 843           * @return Always true
 844           */
 845  		function setFields( $fields )
 846          {
 847              $this->_customFields = $fields;
 848              
 849              return true;
 850          }
 851          
 852          /**
 853           * Returns the array of CustomFieldValue objects
 854           *
 855           * @return An array of CustomFieldValue objects
 856           */
 857  		function getCustomFields()
 858          {
 859              if( is_null( $this->_customFields )) {
 860                  lt_include( PLOG_CLASS_PATH.'class/dao/customfields/customfieldsvalues.class.php' );    
 861                  // get the custom fields
 862                  $customFields = new CustomFieldsValues();
 863                  $fields = $customFields->getArticleCustomFieldsValues( $this->getId(), $this->getBlog());
 864                  $this->setFields( $fields );
 865              }
 866              
 867              return $this->_customFields;
 868          }
 869          
 870          /**
 871           * Returns a particular CustomFieldValue object
 872           *
 873           * @param fieldName
 874           * @return A CustomFieldValue object
 875           */
 876  		function getFieldObject( $fieldName )
 877          {            
 878              // if fields haven't been loaded yet, do so now
 879              //if( is_null($this->_customFields) )
 880              //if( !is_array( $this->_customFields ))
 881                  $this->getCustomFields();
 882          
 883              if ( !array_key_exists(  $fieldName, $this->_customFields )) {
 884                  return null;
 885              }
 886              
 887              return $this->_customFields["$fieldName"];
 888          }
 889          
 890          /**
 891           * sets a particular CustomFieldValue object
 892           *
 893           * @param fieldValue
 894           * @return always true
 895           */
 896  		function setFieldObject( $fieldValue )
 897          {
 898              // if fields haven't been loaded yet, do so now
 899              if( is_null($this->_customFields) )
 900                  $this->getCustomFields();        
 901          
 902              $fieldName = $fieldValue->getName();
 903              $this->_customFields["$fieldName"] = $fieldValue;
 904              
 905              return true;
 906          }
 907          
 908          /**
 909           * Returns the description of the given f ield
 910           *
 911           * @param fieldName
 912           * @return A string
 913           */ 
 914  		function getFieldDescription( $fieldName )
 915          {
 916              $field = $this->getFieldObject( $fieldName );
 917              if( $field == "" )
 918                  return "";
 919              else
 920                  return $field->getDescription();
 921          }
 922          
 923          /**
 924           * Gets the value of the given field.
 925           *
 926           * @param fieldName
 927           * @param defaultValue The value that should be returned if the field has no value
 928           * @return A string
 929           */
 930  		function getField( $fieldName )
 931          {
 932              $field = $this->getFieldObject( $fieldName );
 933              if( $field == "" )
 934                  return "";
 935              else 
 936                  return $field->getValue();
 937          }
 938          
 939          /**
 940           * Tells whether the given field name has a value in this post or not
 941           *
 942           * @param fieldName
 943           * @return True whether it has a value or false otherwise.
 944           */
 945  		function hasField( $fieldName )
 946          {
 947              return( $this->getField($fieldName) != "" && $this->getField($fieldName) != null );
 948          }
 949          
 950          /**
 951           * returns the post slug
 952           *
 953           * @return a string with the post slug
 954           */
 955  		function getPostSlug()
 956          {
 957              if( $this->_slug == "" ) {
 958                  lt_include( PLOG_CLASS_PATH.'class/data/textfilter.class.php' );
 959                  $slug = Textfilter::slugify( $this->getTopic());
 960              } else {
 961                  $slug = $this->_slug;
 962              }
 963                  
 964              return $slug;
 965          }
 966          
 967          /**
 968           * sets a new post slug
 969           *
 970           * @param slug the new post slug
 971           */
 972  		function setPostSlug( $slug )
 973          {
 974              lt_include( PLOG_CLASS_PATH.'class/data/textfilter.class.php' );
 975              $this->_slug = Textfilter::slugify( $slug );
 976          }            
 977  
 978          /**
 979           * returns the previous article in time
 980           *
 981           * @return an Article object representing the previous article, in time, in the database
 982           */
 983  		function getPrevArticle()
 984          {
 985              if( !isset($this->_prevArticle )) {
 986                  lt_include( PLOG_CLASS_PATH.'class/dao/articles.class.php' );            
 987                  $articles = new Articles();
 988                  $this->_prevArticle = $articles->getBlogPrevArticle( $this );
 989              }
 990              
 991              return( $this->_prevArticle );
 992          }
 993          
 994          /**
 995           * returns the next article in time
 996           *
 997           * @return an Article object representing the next article, in time, in the database
 998           */
 999  		function getNextArticle()
1000          {
1001              if( !isset($this->_nextArticle )) {
1002                  lt_include( PLOG_CLASS_PATH.'class/dao/articles.class.php' );
1003                  $articles = new Articles();
1004                  $this->_nextArticle = $articles->getBlogNextArticle( $this );
1005              }
1006              
1007              return( $this->_nextArticle );
1008          }
1009          
1010          /**
1011           * returns all the resources which are linked in this post. It basically looks
1012           * at the "id" attribute of all links. When the resource has been added via the
1013           * "add resource" pop-up window from the "new post" and "edit post" pages
1014           * from the admin interface contains something like "res_XX" where "XX" is the
1015           * internal id of the resource.
1016           *
1017           * If this id attribute is not found this method will not work. We could not find
1018           * a better way to identify these resources...
1019           * 
1020           * @return An array of GalleryResource objects containing all the resources
1021           */
1022  		function getArticleResources()
1023          {
1024              lt_include( PLOG_CLASS_PATH."class/data/stringutils.class.php" );
1025              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
1026              
1027              // extract all the "res_XX" values
1028              $regexp ="|<a.*id=\"res_([0-9]+)\".*>.*<\/a>|U";
1029              $resources = Array();
1030              $galleryResources = new GalleryResources();
1031              if( preg_match_all( $regexp, $this->getText(), $out, PREG_SET_ORDER )) {
1032                  // process the results
1033                  foreach( $out as $match ) {
1034                      $resourceId = $match[1];
1035                      // try to load the resource
1036                      $resource = $galleryResources->getResource( $resourceId, $this->getBlog());                    
1037                      if( $resource ) {
1038                          // add it to the array
1039                          $resources[] = $resource;
1040                          // and continue...    
1041                      }
1042                  }
1043              }            
1044  
1045              return( $resources );
1046          }
1047          
1048          /**
1049           * returns the article global category id
1050           *
1051           * @return the global category id
1052           */
1053  		function getGlobalCategoryId()
1054          {
1055              return( $this->_globalCategoryId );
1056          }
1057          
1058          /**
1059           * sets the global category id
1060           *
1061           * @param id the new category id
1062           */
1063  		function setGlobalCategoryId( $id )
1064          {
1065              if( $id != $this->_globalCategoryId )
1066                  $this->_globalCategory = null;
1067                  
1068              $this->_globalCategoryId = $id;
1069          }
1070          
1071          /**
1072           * @return Returns a GlobalArticleCategory object, or null if this article
1073           * has not been assigned a global category
1074           */
1075  		function getGlobalCategory()
1076          {
1077              if( $this->_globalCategory == null ) {
1078                  lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
1079                  $globalCategories = new GlobalArticleCategories();
1080                  $this->_globalCategory = $globalCategories->getGlobalArticleCategory( $this->_globalCategoryId );
1081              }
1082              
1083              return( $this->_globalCategory );
1084          }
1085          
1086          /**
1087           * sets a new global category
1088           *
1089           * @param category A valid GlobalArticleCategory object
1090           */
1091  		function setGlobalCategory( $category ) 
1092          {
1093              $this->_globalCategory = $category;
1094              $this->_globalCategoryId = $category->getId();
1095              return( true );
1096          }
1097          
1098          /**
1099           * @private
1100           */
1101  		function __sleep()
1102          {
1103              // these objects cannot be serialized in the data cache, because otherwise when
1104              // we update one of them via the admin interface, we will only be updating that object
1105              // and not the copy of it that was serialized along this Article object!
1106              $this->_categories = null;
1107              $this->_userInfo = null;
1108              $this->_blogInfo = null;
1109              $this->_nextArticle = null;
1110              $this->_prevArticle = null;
1111              $this->_globalCategory = null;
1112              $this->_customFields = null;
1113              return( parent::__sleep());
1114          }
1115          
1116          /**
1117           * Returns whether this article should appear in the front summary.php page or not
1118           *
1119           * @return boolean value
1120           */
1121  		function getInSummary()
1122          {
1123              return( $this->_inSummary );
1124          }
1125          
1126          /**
1127           * Whether to make this post appear in the front summary.php page
1128           *
1129           * @param inSummary
1130           */
1131  		function setInSummary( $inSummary )
1132          {
1133              $this->_inSummary = $inSummary;
1134          }
1135      }
1136  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics