ILIAS  release_8 Revision v8.24
class.ilForumExportGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
23
30{
31 private const MODE_EXPORT_WEB = 1;
32 private const MODE_EXPORT_CLIENT = 2;
33
40 protected bool $is_moderator = false;
41 protected ilForum $frm;
44 private Refinery $refinery;
45 private int $ref_id;
46
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 $this->ctrl = $DIC->ctrl();
53 $this->access = $DIC->access();
54 $this->error = $DIC['ilErr'];
55 $this->user = $DIC->user();
56 $this->ilObjDataCache = $DIC['ilObjDataCache'];
57 $this->http = $DIC->http();
58 $this->refinery = $DIC->refinery();
59
60 $this->ref_id = $this->retrieveRefId();
61
62 $forum = new ilObjForum($this->ref_id);
63 $this->frm = $forum->Forum;
64 $this->objProperties = ilForumProperties::getInstance($forum->getId());
65
66 $this->frm->setForumId($forum->getId());
67 $this->frm->setForumRefId($forum->getRefId());
68
69 $this->lng->loadLanguageModule('forum');
70
71 $this->is_moderator = $this->access->checkAccess('moderate_frm', '', $this->ref_id);
72 }
73
74 private function retrieveRefId(): int
75 {
76 $ref_id = 0;
77 if ($this->http->wrapper()->query()->has('ref_id')) {
78 $ref_id = $this->http->wrapper()->query()->retrieve(
79 'ref_id',
80 $this->refinery->kindlyTo()->int()
81 );
82 }
83
84 return $ref_id;
85 }
86
87 private function prepare(): void
88 {
91 ->setZoomFactor(10);
92 }
93
94 private function ensureThreadBelongsToForum(int $objId, ilForumTopic $thread): void
95 {
97 if ($thread->getForumId() !== $forumId) {
98 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
99 }
100 }
101
102 public function executeCommand(): void
103 {
104 $next_class = $this->ctrl->getNextClass($this);
105 $cmd = $this->ctrl->getCmd();
106
107 switch ($next_class) {
108 default:
109 $this->$cmd();
110 break;
111 }
112 }
113
114 protected function renderPostHtml(ilGlobalTemplateInterface $tpl, ilForumPost $post, int $counter, int $mode): void
115 {
116 $tpl->setCurrentBlock('posts_row');
117
118 if (ilForumProperties::getInstance($this->ilObjDataCache->lookupObjId($this->ref_id))->getMarkModeratorPosts()) {
119 if ($post->isAuthorModerator() === null && $is_moderator = ilForum::_isModerator(
120 $this->ref_id,
121 $post->getPosAuthorId()
122 )) {
123 $rowCol = 'ilModeratorPosting';
124 } elseif ($post->isAuthorModerator()) {
125 $rowCol = 'ilModeratorPosting';
126 } else {
127 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
128 }
129 } else {
130 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
131 }
132
133 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
134
135 if ($post->isCensored()) {
136 $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
137 $rowCol = 'tblrowmarked';
138 }
139
140 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
141 if (!$post->isActivated() && $post->isOwner($this->user->getId())) {
142 $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
143 }
144
145 $authorinfo = new ilForumAuthorInformation(
146 $post->getPosAuthorId(),
147 $post->getDisplayUserId(),
148 (string) $post->getUserAlias(),
149 (string) $post->getImportName()
150 );
151
152 if ($authorinfo->hasSuffix()) {
153 if (!$authorinfo->isDeleted()) {
154 $tpl->setVariable('USR_NAME', $authorinfo->getAlias());
155 }
156 $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
157 } else {
158 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
159 $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
160 }
161 $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
162 }
163
164 if (self::MODE_EXPORT_CLIENT === $mode) {
165 if ($authorinfo->getAuthor()->getPref('public_profile') !== 'n') {
166 $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('registered_since'));
167 $tpl->setVariable(
168 'REGISTERED_SINCE',
169 $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate())
170 );
171 }
172
173 if ($post->getDisplayUserId()) {
174 if ($this->is_moderator) {
175 $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
176 } else {
177 $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
178 }
179 $tpl->setVariable('TXT_NUM_POSTS', $this->lng->txt('forums_posts'));
180 $tpl->setVariable('NUM_POSTS', $num_posts);
181 }
182 }
183
184 $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
185 if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator(
186 $this->ref_id,
187 $post->getPosAuthorId()
188 )) {
189 if ($authorinfo->getAuthor()->getGender() === 'f') {
190 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
191 } elseif ($authorinfo->getAuthor()->getGender() === 'm') {
192 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
193 } else {
194 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_n'));
195 }
196 }
197
198 if ($post->getUpdateUserId() > 0) {
199 $spanClass = '';
200 if (ilForum::_isModerator($this->ref_id, $post->getUpdateUserId())) {
201 $spanClass = 'moderator_small';
202 }
203
204 $post->setChangeDate($post->getChangeDate());
205
206 $authorinfo = new ilForumAuthorInformation(
207 $post->getPosAuthorId(),
208 $post->getDisplayUserId(),
209 (string) $post->getUserAlias(),
210 ''
211 );
212
213 $tpl->setVariable(
214 'POST_UPDATE_TXT',
215 $this->lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($this->lng->txt('by'))
216 );
217 $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
218 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
219 $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
220 }
221 }
222
223 $post->setMessage($this->frm->prepareText($post->getMessage()));
224 $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
225 $tpl->setVariable('SUBJECT', $post->getSubject());
226
227 if (!$post->isCensored()) {
228 $spanClass = "";
229 if (ilForum::_isModerator($this->ref_id, $post->getDisplayUserId())) {
230 $spanClass = 'moderator';
231 }
232
233 // possible bugfix for mantis #8223
234 if ($post->getMessage() === strip_tags($post->getMessage())) {
235 // We can be sure, that there are not html tags
236 $post->setMessage(nl2br($post->getMessage()));
237 }
238
239 if ($spanClass !== '') {
240 $tpl->setVariable(
241 'POST',
242 "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc(
243 $post->getMessage(),
244 1
245 ) . "</span>"
246 );
247 } else {
248 $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
249 }
250 } else {
251 $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br((string) $post->getCensorshipComment()) . "</span>");
252 }
253
254 $tpl->parseCurrentBlock('posts_row');
255 }
256
257 public function printThread(): void
258 {
259 if (
260 !$this->access->checkAccess('read,visible', '', $this->ref_id) ||
261 !$this->http->wrapper()->query()->has('thr_top_fk') ||
262 !$this->http->wrapper()->query()->has('print_thread')
263 ) {
264 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
265 }
266
267 $this->prepare();
268
270
271 $tpl = new ilGlobalTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
272 $location_stylesheet = ilUtil::getStyleSheetLocation();
273 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
274
276 ilMathJax::getInstance()->includeMathJax($tpl);
277
278 $this->frm->setMDB2WhereCondition('top_pk = %s ', ['integer'], [$this->http->wrapper()->query()->retrieve(
279 'thr_top_fk',
280 $this->refinery->kindlyTo()->int()
281 )]);
282 $frmData = $this->frm->getOneTopic();
283
284 if ($frmData->getTopPk() > 0) {
285 $topic = new ilForumTopic($this->http->wrapper()->query()->retrieve(
286 'print_thread',
287 $this->refinery->kindlyTo()->int()
288 ), $this->is_moderator);
289
290 $this->ensureThreadBelongsToForum($this->frm->getForumId(), $topic);
291
292 $topic->setOrderField('frm_posts_tree.rgt');
293 $first_post = $topic->getPostRootNode();
294 $post_collection = $topic->getPostTree($first_post);
295 $num_posts = count($post_collection);
296
297 $tpl->setVariable('TITLE', $topic->getSubject());
298 $tpl->setVariable(
299 'HEADLINE',
300 $this->lng->txt('forum') . ': ' . $frmData->getTopName() . ' > ' .
301 $this->lng->txt('forums_thread') . ': ' . $topic->getSubject() . ' > ' .
302 $this->lng->txt('forums_count_art') . ': ' . $num_posts
303 );
304
305 $i = 0;
306 foreach ($post_collection as $post) {
307 $this->renderPostHtml($tpl, $post, $i++, self::MODE_EXPORT_WEB);
308 }
309 }
310
311 $tpl->printToStdout();
312 }
313
314 public function printPost(): void
315 {
316 if (!$this->access->checkAccess('read,visible', '', $this->ref_id)) {
317 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
318 }
319
320 $this->prepare();
321
323
324 $tpl = new ilGlobalTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
325 $location_stylesheet = ilUtil::getStyleSheetLocation();
326 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
327
329 ilMathJax::getInstance()->includeMathJax($tpl);
330
331 $this->frm->setMDB2WhereCondition('top_pk = %s ', ['integer'], [$this->http->wrapper()->query()->retrieve(
332 'top_pk',
333 $this->refinery->kindlyTo()->int()
334 )]);
335 $frmData = $this->frm->getOneTopic();
336
337 if ($frmData->getTopPk() > 0) {
338 $post = new ilForumPost($this->http->wrapper()->query()->retrieve(
339 'print_post',
340 $this->refinery->kindlyTo()->int()
341 ), $this->is_moderator);
342 $this->ensureThreadBelongsToForum($this->frm->getForumId(), $post->getThread());
343
344 $tpl->setVariable('TITLE', $post->getThread()->getSubject());
345 $tpl->setVariable(
346 'HEADLINE',
347 $this->lng->txt('forum') . ': ' . $frmData->getTopName() . ' > ' .
348 $this->lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject()
349 );
350
351 $this->renderPostHtml($tpl, $post, 0, self::MODE_EXPORT_WEB);
352 }
353 $tpl->printToStdout();
354 }
355
356 public function exportHTML(): void
357 {
358 if (!$this->access->checkAccess('read,visible', '', $this->ref_id)) {
359 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
360 }
361
362 $this->prepare();
363
365
366 $tpl = new ilGlobalTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
367 $location_stylesheet = ilUtil::getStyleSheetLocation();
368 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
369 $tpl->setVariable('BASE', (substr(ILIAS_HTTP_PATH, -1) === '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'));
370
372 ilMathJax::getInstance()->includeMathJax($tpl);
373
375 $threads = [];
376 $thread_ids = [];
377 $isModerator = $this->is_moderator;
378 if ($this->http->wrapper()->post()->has('thread_ids')) {
379 $thread_ids = $this->http->wrapper()->post()->retrieve(
380 'thread_ids',
381 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
382 );
383 }
384 array_walk($thread_ids, function (int $threadId) use (&$threads, $isModerator): void {
385 $thread = new ilForumTopic($threadId, $isModerator);
386 $this->ensureThreadBelongsToForum($this->frm->getForumId(), $thread);
387
388 $threads[] = $thread;
389 });
390
391 $i = 0;
392 foreach ($threads as $topic) {
393 $this->frm->setMDB2WhereCondition('top_pk = %s ', ['integer'], [$topic->getForumId()]);
394 $frmData = $this->frm->getOneTopic();
395
396 if ($frmData->getTopPk() > 0) {
397 if (0 === $i) {
398 $tpl->setVariable('TITLE', $frmData->getTopName());
399 }
400
401 $first_post = $topic->getPostRootNode();
402 $topic->setOrderField('frm_posts_tree.rgt');
403 $post_collection = $topic->getPostTree($first_post);
404
405 $j = 0;
406 foreach ($post_collection as $post) {
407 $this->renderPostHtml($tpl, $post, $j++, self::MODE_EXPORT_CLIENT);
408 }
409
410 $tpl->setCurrentBlock('thread_headline');
411 $tpl->setVariable('T_TITLE', $topic->getSubject());
412 if ($this->is_moderator) {
413 $tpl->setVariable('T_NUM_POSTS', $topic->countPosts(true));
414 } else {
415 $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts(true));
416 }
417 $tpl->setVariable('T_NUM_VISITS', $topic->getVisits());
418 $tpl->setVariable('T_FORUM', $frmData->getTopName());
419 $authorinfo = new ilForumAuthorInformation(
420 $topic->getThrAuthorId(),
421 $topic->getDisplayUserId(),
422 (string) $topic->getUserAlias(),
423 (string) $topic->getImportName()
424 );
425 $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
426 $tpl->setVariable('T_TXT_FORUM', $this->lng->txt('forum') . ': ');
427 $tpl->setVariable('T_TXT_TOPIC', $this->lng->txt('forums_thread') . ': ');
428 $tpl->setVariable('T_TXT_AUTHOR', $this->lng->txt('forums_thread_create_from') . ': ');
429 $tpl->setVariable('T_TXT_NUM_POSTS', $this->lng->txt('forums_articles') . ': ');
430 $tpl->setVariable('T_TXT_NUM_VISITS', $this->lng->txt('visits') . ': ');
431 $tpl->parseCurrentBlock();
432
433 ++$i;
434 }
435
436 $tpl->setCurrentBlock('thread_block');
437 $tpl->parseCurrentBlock();
438 }
439
441 $tpl->get(),
442 'forum_html_export_' . $this->ref_id . '.html'
443 );
444 }
445}
Builds data types.
Definition: Factory.php:21
error(string $a_errmsg)
static setUseRelativeDates(bool $a_status)
set use relative dates
Error Handling & global info handling uses PEAR error class.
Forum export to HTML and Print.
ilForumProperties $objProperties
renderPostHtml(ilGlobalTemplateInterface $tpl, ilForumPost $post, int $counter, int $mode)
ensureThreadBelongsToForum(int $objId, ilForumTopic $thread)
ilObjectDataCache $ilObjDataCache
static getInstance(int $a_obj_id=0)
Class Forum core functions for forum.
static _isModerator(int $a_ref_id, int $a_usr_id)
special template class to simplify handling of ITX/PEAR
language handling
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
const PURPOSE_EXPORT
Class ilObjForum.
static lookupForumIdByObjId(int $obj_id)
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
static switchColor(int $a_num, string $a_css1, string $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows)
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$post
Definition: ltitoken.php:49
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.
$objId
Definition: xapitoken.php:57