ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilForumAuthorInformation.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Forum/classes/class.ilObjForumAccess.php';
5require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
6
14{
18 protected $display_id;
19
23 protected $alias;
24
28 protected $import_name;
29
34
38 protected $author_name;
39
44
49
54
58 protected $suffix = '';
59
63 protected $profilePicture;
64
68 protected $author;
69
73 protected $files = array();
74
78 protected $author_id;
79
88 {
89 $this->author_id = $author_id;
90 $this->display_id = $display_id;
91 $this->alias = $alias;
92 $this->import_name = $import_name;
93 $this->public_profile_link_attributes = $public_profile_link_attributes;
94
95 $this->init();
96 }
97
101 protected function initUserInstance()
102 {
103 if(is_numeric($this->display_id) && $this->display_id > 0)
104 {
105 // Try to read user instance from preloaded cache array
106 $this->author = ilForumAuthorInformationCache::getUserObjectById($this->display_id);
107 if(!$this->author)
108 {
109 // Get a user instance from forum module's cache method
110 $this->author = ilObjForumAccess::getCachedUserInstance($this->display_id);
111 }
112 }
113
114 if(!$this->author)
115 {
116 $this->author = new ilObjUser();
117 $this->author->setId(0);
118 $this->author->setPref('public_profile', 'n');
119 $this->author->setGender('');
120 }
121 }
122
126 protected function doesAuthorAccountExists()
127 {
128 return $this->getAuthor() instanceof ilObjUser && $this->getAuthor()->getId();
129 }
130
134 protected function isAuthorAnonymous()
135 {
136 return $this->doesAuthorAccountExists() && $this->getAuthor()->getId() == ANONYMOUS_USER_ID;
137 }
138
142 protected function isCurrentUserSessionLoggedIn()
143 {
147 global $ilUser;
148
149 return !$ilUser->isAnonymous();
150 }
151
155 protected function buildAuthorProfileLink($with_profile_link = false)
156 {
157 $link = '';
158
159 if($with_profile_link && $this->public_profile_link_attributes)
160 {
161 $link = '<a';
162
163 foreach($this->public_profile_link_attributes as $attr => $value)
164 {
165 $link .= ' ' . $attr . '="' . $value . '"';
166 }
167
168 $link .= '>';
169 }
170
171 $linked_login = $link . $this->author_short_name;
172 $link .= $this->author_name;
173
174 if($with_profile_link && $this->public_profile_link_attributes)
175 {
176 $link .= '</a>';
177 $linked_login .= '</a>';
178 }
179
180 $this->linked_public_name = $link;
181 $this->linked_short_name = $linked_login;
182 }
183
187 protected function init()
188 {
192 global $lng;
193
194 include_once 'Modules/Forum/classes/class.ilObjForumAccess.php';
195
196 $this->initUserInstance();
197
198 if($this->doesAuthorAccountExists())
199 {
200 if(!$this->isAuthorAnonymous() &&
201 (
202 (
203 $this->isCurrentUserSessionLoggedIn() && $this->getAuthor()->getPref('public_profile') == 'y'
204 ) ||
205 $this->getAuthor()->getPref('public_profile') == 'g')
206 )
207 {
208 // Author is NOT anonymous and (the current user session is logged in and the profile is public (y) or the profile is globally public (g))
209 $this->author_name = $this->getAuthor()->getPublicName();
210 $this->author_short_name = $this->getAuthor()->getLogin();
211
212 if($this->getAuthor()->getPref('public_upload') == 'y')
213 {
214 $this->profilePicture = $this->getAuthor()->getPersonalPicturePath('xsmall');
215 }
216 else
217 {
218 $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
219 }
220
221 if($this->getAuthor()->getPref('public_gender') != 'y')
222 {
223 $this->getAuthor()->setGender('');
224 }
225
226 $this->buildAuthorProfileLink(true);
227 }
228 else
229 {
230 $this->getAuthor()->setGender('');
231 $this->author_short_name = $this->author_name = $this->getAuthor()->getLogin();
232 $this->buildAuthorProfileLink(false);
233 $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
234 }
235 }
236 else if($this->display_id > 0 && !$this->doesAuthorAccountExists() && strlen($this->alias))
237 {
238 // The author does not use a pseudonym, but the id does not exist anymore (deleted, lost on import etc.)
239 // We have no import name,so we check the pseudonym
240 $this->author_short_name = $this->author_name = $this->alias . ' (' . $lng->txt('deleted') . ')';
241 $this->suffix = $lng->txt('deleted');
242 $this->buildAuthorProfileLink(false);
243 $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
244 }
245 else if(strlen($this->import_name))
246 {
247 // We have no user instance,so we check the import name
248 $this->author_short_name = $this->author_name = $this->import_name . ' (' . $lng->txt('imported') . ')';
249 $this->suffix = $lng->txt('imported');
250 $this->buildAuthorProfileLink(false);
251 $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
252 }
253 else if(strlen($this->alias))
254 {
255 // We have no import name,so we check the pseudonym
256 $this->author_short_name = $this->author_name = $this->alias . ' (' . $lng->txt('frm_pseudonym') . ')';
257 $this->suffix = $lng->txt('frm_pseudonym');
258 $this->buildAuthorProfileLink(false);
259 $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
260 }
261 else
262 {
263 // If we did not find a pseudonym, the author could not be determined
264 $this->author_short_name = $this->author_name = $lng->txt('forums_anonymous');
265 $this->buildAuthorProfileLink(false);
266 $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
267 }
268 }
269
273 public function getProfilePicture()
274 {
276 }
277
281 public function getAuthor()
282 {
283 return $this->author;
284 }
285
290 public function getAuthorName($without_short_name = false)
291 {
292 if(!$without_short_name)
293 {
294 return $this->author_name;
295 }
296 else
297 {
298 return trim(preg_replace('/\‍(' . $this->getAuthorShortName() . '\‍)/', '', $this->author_name));
299 }
300 }
301
305 public function getAuthorShortName()
306 {
308 }
309
313 public function getLinkedAuthorName()
314 {
316 }
317
321 public function getLinkedAuthorShortName()
322 {
324 }
325
329 public function hasSuffix()
330 {
331 return strlen($this->suffix);
332 }
333
337 public function getSuffix()
338 {
339 return $this->suffix;
340 }
341}
__construct($author_id, $display_id, $alias, $import_name, array $public_profile_link_attributes=array())
getAuthorName($without_short_name=false)
buildAuthorProfileLink($with_profile_link=false)
static getCachedUserInstance($usr_id)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15