1
|
|
|
<?php |
2
|
|
|
namespace App\Model\Entity; |
3
|
|
|
|
4
|
|
|
use App\Model\Behavior\AppTranslateTrait; |
5
|
|
|
use Cake\Core\Configure; |
6
|
|
|
use Cake\I18n\Number; |
7
|
|
|
use Cake\ORM\Behavior\Translate\TranslateTrait; |
8
|
|
|
use Cake\ORM\Entity; |
9
|
|
|
use HTMLPurifier; |
10
|
|
|
use HTMLPurifier_Config; |
11
|
|
|
|
12
|
|
|
class BlogArticle extends Entity |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
use AppTranslateTrait; |
16
|
|
|
use TranslateTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Fields that can be mass assigned using newEntity() or patchEntity(). |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $_accessible = [ |
24
|
|
|
'*' => true, |
25
|
|
|
'id' => false, |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Purify the content for display the article. |
30
|
|
|
* |
31
|
|
|
* @param string $content The content to be purified. |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
protected function _getContent($content) |
36
|
|
|
{ |
37
|
|
|
$config = HTMLPurifier_Config::createDefault(); |
38
|
|
|
$config->loadArray(Configure::read('HtmlPurifier.Blog.article')); |
39
|
|
|
|
40
|
|
|
$HTMLPurifier = new HTMLPurifier($config); |
41
|
|
|
|
42
|
|
|
return $HTMLPurifier->purify($content); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Purify the content for display the article on category/archives/index blog page. |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
protected function _getContentEmpty() |
51
|
|
|
{ |
52
|
|
|
$config = HTMLPurifier_Config::createDefault(); |
53
|
|
|
$config->loadArray(Configure::read('HtmlPurifier.Blog.article_empty')); |
54
|
|
|
|
55
|
|
|
$HTMLPurifier = new HTMLPurifier($config); |
56
|
|
|
|
57
|
|
|
return $HTMLPurifier->purify($this->content); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Purify the content for display the article in meta tags. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
protected function _getContentMeta() |
66
|
|
|
{ |
67
|
|
|
$config = HTMLPurifier_Config::createDefault(); |
68
|
|
|
$config->loadArray(Configure::read('HtmlPurifier.Blog.article_meta')); |
69
|
|
|
|
70
|
|
|
$HTMLPurifier = new HTMLPurifier($config); |
71
|
|
|
|
72
|
|
|
return $HTMLPurifier->purify($this->content); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the last page of an article. |
77
|
|
|
* |
78
|
|
|
* @return int |
79
|
|
|
*/ |
80
|
|
|
protected function _getLastPage() |
81
|
|
|
{ |
82
|
|
|
$page = ceil($this->comment_count / Configure::read('Blog.comment_per_page')); |
|
|
|
|
83
|
|
|
|
84
|
|
|
return ($page) ? $page : 1; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the number of comments formatted. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
protected function _getCommentCountFormat() |
93
|
|
|
{ |
94
|
|
|
return Number::format($this->comment_count); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get the number of likes formatted. |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
protected function _getLikeCountFormat() |
103
|
|
|
{ |
104
|
|
|
return Number::format($this->like_count); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.