Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
blogcomment.php
1<?php
2
4
9
10Loc::loadMessages(__FILE__);
11
12final class BlogComment extends Provider
13{
14 public const PROVIDER_ID = 'BLOG_COMMENT';
15 public const CONTENT_TYPE_ID = 'BLOG_COMMENT';
16
17 public static function getId(): string
18 {
19 return static::PROVIDER_ID;
20 }
21
22 public function getEventId(): array
23 {
24 return [ 'blog_comment', 'blog_comment_micro' ];
25 }
26
27 public function getType(): string
28 {
30 }
31
32 public function initSourceFields()
33 {
34 $commentId = $this->entityId;
35
36 if ($commentId <= 0 || !Loader::includeModule('blog'))
37 {
38 return;
39 }
40
41 $res = \CBlogComment::getList(
42 [],
43 ['ID' => $commentId],
44 false,
45 false,
46 [
47 'ID',
48 'BLOG_ID',
49 'POST_ID',
50 'PARENT_ID',
51 'AUTHOR_ID',
52 'AUTHOR_NAME',
53 'AUTHOR_EMAIL',
54 'AUTHOR_IP',
55 'AUTHOR_IP1',
56 'TITLE',
57 'POST_TEXT',
58 'SHARE_DEST',
59 'PUBLISH_STATUS',
60 ]
61 );
62 if (
63 !($comment = $res->fetch())
64 || (
65 $comment['PUBLISH_STATUS'] === BLOG_PUBLISH_STATUS_READY
66 && !$this->isCurrentUserAdmin()
67 )
68 )
69 {
70 return;
71 }
72
73 $res = \CBlogPost::getList([], ['ID' => $comment['POST_ID']]);
74 if (!($post = $res->fetch()))
75 {
76 return;
77 }
78
79 if (
80 $this->getOption('checkAccess') !== false
81 && !BlogPost::canRead(['POST' => $post])
82 )
83 {
84 return;
85 }
86
87 if (!empty($post['DETAIL_TEXT']))
88 {
89 $post['DETAIL_TEXT'] = Emoji::decode($post['DETAIL_TEXT']);
90 }
91
92 $this->setSourceFields(array_merge($comment, ['POST' => $post]));
93 $this->setSourceDescription(htmlspecialcharsback($comment['POST_TEXT']));
94
95 $title = htmlspecialcharsback($comment['POST_TEXT']);
96 $title = Mention::clear($title);
97 $title = (new \blogTextParser())->convert($title, false);
98 $title = preg_replace(
99 [
100 "/\n+/is" . BX_UTF_PCRE_MODIFIER,
101 "/\s+/is" . BX_UTF_PCRE_MODIFIER,
102 "/&nbsp;+/is" . BX_UTF_PCRE_MODIFIER
103 ],
104 " ",
105 \blogTextParser::killAllTags($title)
106 );
107
108 $this->setSourceTitle(truncateText($title, 100));
109 $this->setSourceAttachedDiskObjects($this->getAttachedDiskObjects($this->cloneDiskObjects));
110 $this->setSourceDiskObjects($this->getDiskObjects($commentId, $this->cloneDiskObjects));
111 $this->setSourceOriginalText($comment['POST_TEXT']);
112 $this->setSourceAuxData($comment);
113 }
114
115 private function isCurrentUserAdmin(): bool
116 {
117 global $USER;
118
119 return
120 $USER->isAdmin()
121 || (
122 Loader::includeModule('bitrix24')
123 && \CBitrix24::isPortalAdmin((int)$USER->GetId())
124 )
125 ;
126 }
127
128 protected function getAttachedDiskObjects($clone = false)
129 {
130 return $this->getEntityAttachedDiskObjects([
131 'userFieldEntity' => 'BLOG_COMMENT',
132 'userFieldCode' => 'UF_BLOG_COMMENT_FILE',
133 'clone' => $clone,
134 ]);
135 }
136
137 public function getLiveFeedUrl(): string
138 {
139 $pathToPost = \Bitrix\Socialnetwork\Helper\Path::get('userblogpost_page', $this->getSiteId());
140
141 if (
142 !empty($pathToPost)
143 && ($comment = $this->getSourceFields())
144 && isset($comment["POST"])
145 )
146 {
147 $pathToPost = \CComponentEngine::makePathFromTemplate($pathToPost, array("post_id" => $comment["POST"]["ID"], "user_id" => $comment["POST"]["AUTHOR_ID"]));
148 $pathToPost .= (mb_strpos($pathToPost, '?') === false ? '?' : '&').'commentId='.$comment["ID"].'#com'.$comment["ID"];
149 }
150
151 return $pathToPost;
152 }
153
154 public function getSuffix(): string
155 {
156 return '2';
157 }
158}
static loadMessages($file)
Definition loc.php:64
static decode($text)
Definition emoji.php:24
static clear(string $text='')
Definition mention.php:98
static canRead($params)
Definition blogpost.php:173
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Definition provider.php:739
getEntityAttachedDiskObjects(array $params=[])
getDiskObjects($entityId, $clone=false)
Definition provider.php:822