1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
blogcomment.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Livefeed;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Text\Emoji;
8use Bitrix\Socialnetwork\Helper\Mention;
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 static $postCache = [];
74
75 $postId = $comment['POST_ID'];
76
77 if (!isset($postCache[$postId]))
78 {
79 $res = \CBlogPost::getList([], ['ID' => $postId]);
80 if (!($post = $res->fetch()))
81 {
82 return;
83 }
84 $postCache[$postId] = $post;
85 }
86 else
87 {
88 $post = $postCache[$postId];
89 }
90
91 if (
92 $this->getOption('checkAccess') !== false
93 && !BlogPost::canRead(['POST' => $post])
94 )
95 {
96 return;
97 }
98
99 if (!empty($post['DETAIL_TEXT']))
100 {
101 $post['DETAIL_TEXT'] = Emoji::decode($post['DETAIL_TEXT']);
102 }
103
104 $this->setSourceFields(array_merge($comment, ['POST' => $post]));
106
107 $title = htmlspecialcharsback($comment['POST_TEXT']);
108 $title = Mention::clear($title);
109 $title = (new \blogTextParser())->convert($title, false);
110 $title = preg_replace(
111 [
112 "/\n+/isu",
113 "/\s+/isu",
114 "/&nbsp;+/isu"
115 ],
116 " ",
118 );
119
120 $this->setSourceTitle(truncateText($title, 100));
121 $this->setSourceAttachedDiskObjects($this->getAttachedDiskObjects($this->cloneDiskObjects));
122 $this->setSourceDiskObjects($this->getDiskObjects($commentId, $this->cloneDiskObjects));
123 $this->setSourceOriginalText($comment['POST_TEXT']);
125 }
126
127 private function isCurrentUserAdmin(): bool
128 {
129 global $USER;
130
131 return
132 $USER->isAdmin()
133 || (
134 Loader::includeModule('bitrix24')
135 && \CBitrix24::isPortalAdmin((int)$USER->GetId())
136 )
137 ;
138 }
139
140 protected function getAttachedDiskObjects($clone = false)
141 {
142 return $this->getEntityAttachedDiskObjects([
143 'userFieldEntity' => 'BLOG_COMMENT',
144 'userFieldCode' => 'UF_BLOG_COMMENT_FILE',
145 'clone' => $clone,
146 ]);
147 }
148
149 public function getLiveFeedUrl(): string
150 {
151 $pathToPost = \Bitrix\Socialnetwork\Helper\Path::get('userblogpost_page', $this->getSiteId());
152
153 if (
154 !empty($pathToPost)
155 && ($comment = $this->getSourceFields())
156 && isset($comment["POST"])
157 )
158 {
159 $pathToPost = \CComponentEngine::makePathFromTemplate($pathToPost, array("post_id" => $comment["POST"]["ID"], "user_id" => $comment["POST"]["AUTHOR_ID"]));
160 $pathToPost .= (mb_strpos($pathToPost, '?') === false ? '?' : '&').'commentId='.$comment["ID"].'#com'.$comment["ID"];
161 }
162
163 return $pathToPost;
164 }
165
166 public function getSuffix(): string
167 {
168 return '3';
169 }
170}
const BLOG_PUBLISH_STATUS_READY
Определения include.php:46
static get(string $key='', $siteId=SITE_ID)
Определения path.php:17
getAttachedDiskObjects($clone=false)
Определения blogcomment.php:140
static canRead($params)
Определения blogpost.php:173
setSourceFields(array $fields)
Определения provider.php:639
getOption(string $key)
Определения provider.php:118
setSourceAuxData($auxData)
Определения provider.php:736
setSourceDiskObjects(array $files)
Определения provider.php:756
setSourceAttachedDiskObjects(array $diskAttachedObjects)
Определения provider.php:751
getEntityAttachedDiskObjects(array $params=[])
Определения provider.php:1495
setSourceOriginalText($text)
Определения provider.php:721
setSourceDescription($description)
Определения provider.php:654
getDiskObjects($entityId, $clone=false)
Определения provider.php:834
static makePathFromTemplate($template, $arParams=array())
Определения component_engine.php:355
static killAllTags($text)
Определения functions.php:473
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
global $USER
Определения csv_new_run.php:40
htmlspecialcharsback($str)
Определения tools.php:2693
$comment
Определения template.php:15
$post
Определения template.php:8
$title
Определения pdf.php:123