24 private $blogId = NULL;
27 private $avatarSizes = array(
28 'COMMENT' => array(
'WIDTH' => 30,
'HEIGHT' => 30),
29 'POST' => array(
'WIDTH' => 100,
'HEIGHT' => 100),
32 private $cacheTime = 0;
36 $width = intval($width);
37 $height = intval($height);
40 $key = $key <>
'' ? $key :
"IMG_" . (count($this->avatarSizes) + 1);
41 $this->avatarSizes[$key] = array(
'WIDTH' => $width,
'HEIGHT' => $height);
54 $this->cacheTime = intval($cacheTime);
63 $this->blogId = intval($id);
69 $this->cacheTime = $cacheTime;
84 if ($this->cacheTime > 0)
86 $result = $this->getUsersFromCache($ids);
90 $result = $this->getUsersFromDB($ids);
103 private function getUsersFromCache($ids)
106 if ($cache->initCache($this->cacheTime, self::createCacheId($ids), self::createCacheDir($this->blogId)))
108 $result = $cache->getVars();
110 elseif ($cache->startDataCache())
112 $result = self::getUsersFromDB($ids);
113 $cache->endDataCache($result);
133 return $cache->cleanDir(self::CACHE_ID, self::createCacheDir($blogId));
137 private static function createCacheDir($blogId = NULL)
139 $dir =
'/' . SITE_ID;
140 $dir .= $blogId ?
'/BLOG_ID_' . $blogId :
'/BLOGS_ALL';
151 private static function createCacheId($ids)
153 $ids = array_unique($ids);
156 return self::CACHE_ID .
'_' . implode(
'_', $ids);
163 private function getUsersFromDB($ids = array())
170 $filter[
"=USER_ID"] = $ids;
171 $resBlogUsers = Internals\BlogUserTable::getList(array(
173 'ID',
'USER_ID',
'ALIAS',
'DESCRIPTION',
'AVATAR',
'INTERESTS',
'LAST_VISIT',
'DATE_REG',
'ALLOW_POST',
174 'USER.PERSONAL_PHOTO',
'USER.LOGIN',
'USER.NAME',
'USER.LAST_NAME'
180 if (is_array($ids) && !empty($ids))
181 $notExistingUsersIds = array_combine($ids, $ids);
183 while ($row = $resBlogUsers->fetch())
185 unset($notExistingUsersIds[$row[
"USER_ID"]]);
187 $row[
"BLOG_USER_ID"] = $row[
"ID"];
190 $row[
"BlogUser"] = array(
191 "ALIAS" => $row[
"ALIAS"],
192 "DESCRIPTION" => $row[
"DESCRIPTION"],
193 "INTERESTS" => $row[
"INTERESTS"],
195 $row[
"BlogUser"] = \CBlogTools::htmlspecialcharsExArray($row[
"BlogUser"]);
197 $row[
"BlogUser"][
"DATE_REG"] = FormatDate(
"FULL", $row[
"DATE_REG"]->getTimestamp());
198 if($row[
"LAST_VISIT"])
199 $row[
"BlogUser"][
"LAST_VISIT"] = FormatDate(
"FULL", $row[
"LAST_VISIT"]->getTimestamp());
200 $row[
"BlogUser"][
"ID"] = $row[
"ID"];
201 $row[
"BlogUser"][
"USER_ID"] = $row[
"USER_ID"];
202 $row[
"BlogUser"][
"AVATAR"] = $row[
"AVATAR"];
203 $row[
"BlogUser"][
"ALLOW_POST"] = $row[
"ALLOW_POST"];
206 $row[
"BlogUser"][
"AVATAR_file"] = intval($row[
"AVATAR"]) > 0 ?
207 \CFile::GetFileArray($row[
"AVATAR"]) :
208 \CFile::GetFileArray($row[
"BLOG_INTERNALS_BLOG_USER_USER_PERSONAL_PHOTO"]);
209 if ($row[
"BlogUser"][
"AVATAR_file"] !==
false)
211 foreach ($this->avatarSizes as $key => $avatarSize)
213 $row[
"BlogUser"][
"Avatar_resized"][$avatarSize[
'WIDTH'] .
'_' . $avatarSize[
'HEIGHT']] = \CFile::ResizeImageGet(
214 $row[
"BlogUser"][
"AVATAR_file"],
215 array(
"width" => $avatarSize[
'WIDTH'],
"height" => $avatarSize[
'HEIGHT']),
216 BX_RESIZE_IMAGE_EXACT,
219 $row[
"BlogUser"][
"AVATAR_img"][$avatarSize[
'WIDTH'] .
'_' . $avatarSize[
'HEIGHT']] = \CFile::ShowImage(
220 $row[
"BlogUser"][
"Avatar_resized"][$avatarSize[
'WIDTH'] .
'_' . $avatarSize[
'HEIGHT']][
"src"],
221 $avatarSize[
'WIDTH'],
222 $avatarSize[
'HEIGHT'],
223 "border=0 align='right'"
231 $row[
"BLOG_INTERNALS_BLOG_USER_USER_NAME"],
232 $row[
"BLOG_INTERNALS_BLOG_USER_USER_LAST_NAME"],
233 $row[
"BLOG_INTERNALS_BLOG_USER_USER_LOGIN"]
235 $row[
"~AUTHOR_NAME"] = htmlspecialcharsex($row[
"AUTHOR_NAME"]);
238 $row[
"arUser"] = array(
239 "ID" => $row[
"USER_ID"],
240 "NAME" => $row[
"BLOG_INTERNALS_BLOG_USER_USER_NAME"],
241 "LAST_NAME" => $row[
"BLOG_INTERNALS_BLOG_USER_USER_LAST_NAME"],
242 "LOGIN" => $row[
"BLOG_INTERNALS_BLOG_USER_USER_LOGIN"],
244 $row[
"arUser"] = \CBlogTools::htmlspecialcharsExArray($row[
"arUser"]);
247 $result[$row[
"arUser"][
'ID']] = $row;
251 if (!empty($notExistingUsersIds))
252 $result = $result + $this->addNotExistingUsers($notExistingUsersIds);
258 private function addNotExistingUsers($ids = array())
260 global $APPLICATION, $DB;
263 $rsUsers = \CUser::GetList(
266 array(
'ID' => implode(
'|', $ids)),
267 array(
'FIELDS' => array(
'ID',
'DATE_REGISTER'))
270 while ($user = $rsUsers->Fetch())
274 if (!is_set($user,
"DATE_REGISTER") || (!$DB->IsDate($user[
"DATE_REGISTER"],
false, LANG,
"FULL")))
275 $user[
"DATE_REGISTER"] =
new DateTime();
277 $resId = \CBlogUser::Add(
279 'USER_ID' => $user[
'ID'],
280 'DATE_REG' => $user[
"DATE_REGISTER"],
286 if($ex = $APPLICATION->GetException())
287 throw new SystemException($ex->GetString());
291 return $this->getUsersFromDB($ids);
304 $postId = intval($postId);
307 $resComment = \CBlogComment::GetList(array(), array(
"POST_ID" => $postId),
false,
false, array(
"AUTHOR_ID"));
308 while ($comment = $resComment->Fetch())
310 if ($comment[
"AUTHOR_ID"])
311 $result[$comment[
"AUTHOR_ID"]] = $comment[
"AUTHOR_ID"];
325 $blogId = intval($blogId);
328 $resPost = \CBlogPost::GetList(array(), array(
"BLOG_ID" => $blogId),
false,
false, array(
"AUTHOR_ID"));
329 while ($post = $resPost->Fetch())
330 if ($post[
"AUTHOR_ID"])
331 $result[$post[
"AUTHOR_ID"]] = $post[
"AUTHOR_ID"];
348 if(!is_array($arFilter))
352 $resPost = \CBlogPost::GetList(array(), $arFilter,
false,
false, array(
"AUTHOR_ID"));
353 while ($post = $resPost->Fetch())
354 if ($post[
"AUTHOR_ID"])
355 $result[$post[
"AUTHOR_ID"]] = $post[
"AUTHOR_ID"];
372 public static function GetUserName($alias, $name, $lastName, $login, $secondName =
"")
376 $canUseAlias = \COption::GetOptionString(
"blog",
"allow_alias",
"Y");
377 if ($canUseAlias ==
"Y")
382 $result = \CUser::FormatName(
383 \CSite::GetNameFormat(
false),
384 array(
"NAME" => $name,
385 "LAST_NAME" => $lastName,
386 "SECOND_NAME" => $secondName,
399 if (empty($params[
"bSoNet"]))
401 $canUseAlias = \COption::GetOptionString(
"blog",
"allow_alias",
"Y");
402 if ($canUseAlias ==
"Y")
403 $result = $blogUser[
"ALIAS"];
408 $params[
"NAME_TEMPLATE"] = $params[
"NAME_TEMPLATE"] ? $params[
"NAME_TEMPLATE"] : \CSite::GetNameFormat();
409 $params[
"NAME_TEMPLATE"] = str_replace(
410 array(
"#NOBR#",
"#/NOBR#"),
412 $params[
"NAME_TEMPLATE"]
414 $isUseLogin = ($params[
"SHOW_LOGIN"] ??
null) !=
"N" ?
true :
false;
416 $result = \CUser::FormatName(
417 $params[
"NAME_TEMPLATE"],
435 if (!$userId || $userId <= 0)
437 if (!$agreementId || $agreementId <= 0)
443 $url = $request->getHttpHost() . $request->getScriptFile();
444 $urlDir = pathinfo($url);
445 $urlDir = $urlDir[
'dirname'];
448 "=USER_ID" => $userId,
449 "%=URL" =>
"%$urlDir%",
450 "=AGREEMENT_ID" => $agreementId,
453 $isGivenAgreement =
false;
454 $consents = ConsentTable::getList(array(
'filter' => $filter));
455 if ($consents->fetch())
456 $isGivenAgreement =
true;
458 return $isGivenAgreement;
468 $userId = intval($userId);
474 \Bitrix\Blog\PostSocnetRightsTable::deleteByEntity(
'U'.$userId);
476 return \CBlogUser::delete($userId);
static getPostAuthorsIdsByBlogId($blogId)
static GetUserNameEx($user, $blogUser, $params)
static cleanCache($blogId=NULL)
static getPostAuthorsIdsByDbFilter($arFilter)
__construct($cacheTime=0)
static GetUserName($alias, $name, $lastName, $login, $secondName="")
static onUserDelete($userId=NULL)
static getCommentAuthorsIdsByPostId($postId)
addAvatarSize($width, $height, $key="")
static isUserGivenConsent($userId, $agreementId)
static createInstance($params=[])
static loadMessages($file)