ElggBlog.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Extended class to override the time_created
  4. *
  5. * @property string $status The published status of the blog post (published, draft)
  6. * @property string $comments_on Whether commenting is allowed (Off, On)
  7. * @property string $excerpt An excerpt of the blog post used when displaying the post
  8. */
  9. class ElggBlog extends ElggObject {
  10. /**
  11. * Set subtype to blog.
  12. */
  13. protected function initializeAttributes() {
  14. parent::initializeAttributes();
  15. $this->attributes['subtype'] = "blog";
  16. }
  17. /**
  18. * Can a user comment on this blog?
  19. *
  20. * @see ElggObject::canComment()
  21. *
  22. * @param int $user_guid User guid (default is logged in user)
  23. * @return bool
  24. * @since 1.8.0
  25. */
  26. public function canComment($user_guid = 0) {
  27. $result = parent::canComment($user_guid);
  28. if ($result == false) {
  29. return $result;
  30. }
  31. if ($this->comments_on == 'Off') {
  32. return false;
  33. }
  34. return true;
  35. }
  36. /**
  37. * Get the excerpt for this blog post
  38. *
  39. * @param int $length Length of the excerpt (optional)
  40. * @return string
  41. * @since 1.9.0
  42. */
  43. public function getExcerpt($length = 250) {
  44. if ($this->excerpt) {
  45. return $this->excerpt;
  46. } else {
  47. return elgg_get_excerpt($this->description, $length);
  48. }
  49. }
  50. }