BlogPost.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. ApplicationSettings::RegisterDefaultSetting("blog", "preview_length", 1000);
  3. class BlogPost extends DBObject {
  4. private $_uri;
  5. public function __construct($id=0) {
  6. $field="post_id";
  7. if (!is_numeric($id))
  8. $field="post_url";
  9. parent::__construct("blog_posts", $field, $id);
  10. $this->_uri=new URI($this->PostTitle, $this->PostUrl);
  11. }
  12. public function Save() {
  13. if (!isset($this->PostUrl) || $this->PostUrl==null || $this->PostUrl=="")
  14. $this->PostUrl=Utils::MakeUniqueURL("blog_posts","post_url",$this->PostTitle);
  15. if (is_numeric($this->PostUrl))
  16. $this->PostUrl="_".$this->PostUrl;
  17. parent::Save();
  18. }
  19. public function Delete() {
  20. $this->PostDeleted=1;
  21. $this->Save();
  22. }
  23. public function GetPostPreview() {
  24. $previewLength=ApplicationSettings::GetSetting("blog", "preview_length");
  25. $content=$this->PostContent;
  26. if ($previewLength<strlen($content)){
  27. $newlinePos=strpos($content,"\n",$previewLength);
  28. $content=substr($content, 0, $newlinePos);
  29. }
  30. return $content;
  31. }
  32. public function GetURI() {
  33. return $this->_uri;
  34. }
  35. public function Publish() {
  36. $this->PostContent=$this->PostDraft;
  37. $this->Save();
  38. }
  39. }