Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
blogpostconnector.php
1<?
3
6
7Loc::loadMessages(__FILE__);
8
9final class BlogPostConnector extends Connector
10{
11 private $canRead = null;
12 private $canEdit = null;
13 private static $permissions = array();
14 private static $posts = array();
15
16 private static function getPostData($entityId)
17 {
18 if (array_key_exists($entityId, self::$posts))
19 return self::$posts[$entityId];
20 $cacheTtl = 2592000;
21 $cacheId = 'blog_post_socnet_general_' . $entityId . '_' . LANGUAGE_ID . '_voteconnector';
22 $timezoneOffset = \CTimeZone::getOffset();
23 if($timezoneOffset != 0)
24 {
25 $cacheId .= "_" . $timezoneOffset;
26 }
27 $cacheDir = '/blog/socnet_post/gen/' . intval($entityId / 100) . '/' . $entityId;
28
29 $cache = new \CPHPCache;
30 if ($cache->initCache($cacheTtl, $cacheId, $cacheDir))
31 {
32 $post = $cache->getVars();
33 }
34 else
35 {
36 $cache->startDataCache();
37 $post = \CBlogPost::getList(array(), array("ID" => $entityId), false, false, array(
38 "ID",
39 "BLOG_ID",
40 "BLOG_OWNER_ID",
41 "PUBLISH_STATUS",
42 "TITLE",
43 "AUTHOR_ID",
44 "ENABLE_COMMENTS",
45 "NUM_COMMENTS",
46 "VIEWS",
47 "CODE",
48 "MICRO",
49 "DETAIL_TEXT",
50 "DATE_PUBLISH",
51 "CATEGORY_ID",
52 "HAS_SOCNET_ALL",
53 "HAS_TAGS",
54 "HAS_IMAGES",
55 "HAS_PROPS",
56 "HAS_COMMENT_IMAGES"
57 ))->fetch();
58
59 if (!empty($post['DETAIL_TEXT']))
60 {
61 $post['DETAIL_TEXT'] = \Bitrix\Main\Text\Emoji::decode($post['DETAIL_TEXT']);
62 }
63
64 $cache->endDataCache($post);
65 }
66 self::$posts[$entityId] = $post;
67 return $post;
68 }
69
70 private function getPermission($userId)
71 {
72 global $APPLICATION;
73
74 if (!Loader::includeModule('socialnetwork'))
75 return false;
76 elseif (
77 $APPLICATION->getGroupRight("blog") >= "W"
78 || \CSocNetUser::isCurrentUserModuleAdmin()
79 )
80 {
81 self::$permissions[$this->entityId] = BLOG_PERMS_FULL;
82 }
83 else if (!array_key_exists($this->entityId, self::$permissions))
84 {
85 self::$permissions[$this->entityId] = BLOG_PERMS_DENY;
86 $post = self::getPostData($this->entityId);
87 if ($post && $post["ID"] > 0)
88 {
89 $p = \CBlogPost::getSocNetPostPerms($this->entityId, true, $userId, $post["AUTHOR_ID"]);
90 if ($p > BLOG_PERMS_MODERATE || ($p >= BLOG_PERMS_WRITE && $post["AUTHOR_ID"] == $userId))
91 $p = BLOG_PERMS_FULL;
92 self::$permissions[$this->entityId] = $p;
93 }
94
95 }
96 return self::$permissions[$this->entityId];
97 }
98
103 public function checkFields(&$data)
104 {
105 $post = self::getPostData($this->entityId);
106 if ($post)
107 {
108 $data["TITLE"] = $post["TITLE"];
109 $data["URL"] = str_replace(
110 array("#user_id#", "#post_id#"),
111 array($post["BLOG_OWNER_ID"], $post["ID"]),
112 \COption::GetOptionString("socialnetwork", "userblogpost_page")
113 );
114 }
115 return $data;
116 }
121 public function canRead($userId)
122 {
123 if ($this->entityId === null)
124 return true;
125 if (is_null($this->canRead))
126 $this->canRead = $this->getPermission($userId) >= BLOG_PERMS_READ;
127
128 return $this->canRead;
129 }
130
135 public function canEdit($userId)
136 {
137 if ($this->entityId === null)
138 return true;
139 if(is_null($this->canEdit))
140 $this->canEdit = $this->getPermission($userId) > BLOG_PERMS_MODERATE;
141
142 return $this->canEdit;
143 }
144}
static includeModule($moduleName)
Definition loader.php:69
static loadMessages($file)
Definition loc.php:64
canEdit($userId)
checkFields(&$data)
canRead($userId)