Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

mod/blog/classes/ElggBlog.php (1 issue)

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
 * @property string $new_post    Whether this is an auto-save (not fully saved) ("1" = yes, "" = no)
9
 */
10
class ElggBlog extends ElggObject {
11
12
	/**
13
	 * {@inheritDoc}
14
	 */
15
	protected function initializeAttributes() {
16
		parent::initializeAttributes();
17
18
		$this->attributes['subtype'] = "blog";
19
	}
20
21
	/**
22
	 * Can a user comment on this blog?
23
	 *
24
	 * @see ElggObject::canComment()
25
	 *
26
	 * @param int  $user_guid User guid (default is logged in user)
27
	 * @param bool $default   Default permission
28
	 *
29
	 * @return bool
30
	 *
31
	 * @since 1.8.0
32
	 */
33
	public function canComment($user_guid = 0, $default = null) {
34
		$result = parent::canComment($user_guid, $default);
35
		if ($result == false) {
0 ignored issues
show
Coding Style Best Practice introduced by Cash Costello
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
36
			return $result;
37
		}
38
39
		if ($this->comments_on === 'Off' || $this->status !== 'published') {
40
			return false;
41
		}
42
		
43
		return true;
44
	}
45
46
	/**
47
	 * Get the excerpt for this blog post
48
	 *
49
	 * @param int $length Length of the excerpt (optional)
50
	 * @return string
51
	 * @since 1.9.0
52
	 */
53
	public function getExcerpt($length = 250) {
54
		if ($this->excerpt) {
55
			return $this->excerpt;
56
		} else {
57
			return elgg_get_excerpt($this->description, $length);
58
		}
59
	}
60
61
}
62