ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilForumExportGUI.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.ilForumProperties.php';
5require_once 'Services/RTE/classes/class.ilRTE.php';
6require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
7require_once 'Modules/Forum/classes/class.ilForum.php';
8
18{
19 const MODE_EXPORT_WEB = 1;
21
25 protected $is_moderator = false;
26
30 protected $frm;
31
32 public $ctrl;
33 public $lng;
34 public $access;
35 public $error;
36
40 public function __construct()
41 {
42 global $lng, $ilCtrl, $ilAccess, $ilErr;
43
44 $forum = new ilObjForum((int)$_GET['ref_id']);
45 $this->frm = $forum->Forum;
46 $this->objProperties = ilForumProperties::getInstance($forum->getId());
47
48 $this->frm->setForumId($forum->getId());
49 $this->frm->setForumRefId($forum->getRefId());
50
51 $this->ctrl = $ilCtrl;
52 $this->lng = $lng;
53 $this->access = $ilAccess;
54 $this->error = $ilErr;
55 $this->lng->loadLanguageModule('forum');
56
57 $this->is_moderator = $this->access->checkAccess('moderate_frm', '', (int)$_GET['ref_id']);
58 }
59
64 public function ensureThreadBelongsToForum($objId, \ilForumTopic $thread)
65 {
66 $forumId = \ilObjForum::lookupForumIdByObjId($objId);
67 if ((int)$thread->getForumId() !== (int)$forumId) {
68 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
69 }
70 }
71
75 public function executeCommand()
76 {
77 $next_class = $this->ctrl->getNextClass($this);
78 $cmd = $this->ctrl->getCmd();
79
80 switch($next_class)
81 {
82 default:
83 return $this->$cmd();
84 break;
85 }
86 }
87
91 public function printThread()
92 {
99 global $tpl, $lng, $ilAccess, $ilias;
100
101 if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
102 {
103 $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
104 }
105
106 // fau: call prepare to init mathjax rendering
107 $this->prepare();
108
110
111 $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
112 $location_stylesheet = ilUtil::getStyleSheetLocation();
113 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
114
115 require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
117
118 $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int)$_GET['thr_top_fk']));
119 if(is_array($frmData = $this->frm->getOneTopic()))
120 {
121 $topic = new ilForumTopic(addslashes($_GET['print_thread']), $this->is_moderator);
122 $this->ensureThreadBelongsToForum((int)$this->frm->getForumId(), $topic);
123
124 $topic->setOrderField('frm_posts_tree.rgt');
125 $first_post = $topic->getFirstPostNode();
126 $post_collection = $topic->getPostTree($first_post);
127 $num_posts = count($post_collection);
128
129 $tpl->setVariable('TITLE', $topic->getSubject());
130 $tpl->setVariable(
131 'HEADLINE',
132 $lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' .
133 $lng->txt('forums_thread') . ': ' . $topic->getSubject() . ' > ' .
134 $lng->txt('forums_count_art') . ': ' . $num_posts);
135
136 $z = 0;
137 foreach($post_collection as $post)
138 {
139 $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_WEB);
140 }
141 }
142 $tpl->show();
143 }
144
148 public function printPost()
149 {
156 global $tpl, $lng, $ilAccess, $ilias;
157
158 if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
159 {
160 $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
161 }
162
163 // call prepare to init mathjax rendering
164 $this->prepare();
165
167
168 $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
169 $location_stylesheet = ilUtil::getStyleSheetLocation();
170 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
171
172 require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
174
175 $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int)$_GET['top_pk']));
176 if(is_array($frmData = $this->frm->getOneTopic()))
177 {
178 $post = new ilForumPost((int)$_GET['print_post'], $this->is_moderator);
179 $this->ensureThreadBelongsToForum((int)$this->frm->getForumId(), $post->getThread());
180
181 $tpl->setVariable('TITLE', $post->getThread()->getSubject());
182 $tpl->setVariable('HEADLINE', $lng->txt('forum').': '.$frmData['top_name'].' > '. $lng->txt('forums_thread').': '.$post->getThread()->getSubject());
183
184 $this->renderPostHtml($tpl, $post, 0, self::MODE_EXPORT_WEB);
185 }
186 $tpl->show();
187 }
188
192 public function exportHTML()
193 {
200 global $lng, $tpl, $ilAccess, $ilias;
201
202 if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
203 {
204 $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
205 }
206
207 // call prepare to init mathjax rendering
208 $this->prepare();
209
211
212 $tpl = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
213 $location_stylesheet = ilUtil::getStyleSheetLocation();
214 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
215 $tpl->setVariable('BASE', (substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'));
216
217 $threads = [];
218 $isModerator = $this->is_moderator;
219 $postIds = (array)$_POST['thread_ids'];
220 array_walk($postIds, function($threadId) use (&$threads, $isModerator) {
221 $thread = new \ilForumTopic($threadId, $isModerator);
222 $this->ensureThreadBelongsToForum((int)$this->frm->getForumId(), $thread);
223
224 $threads[] = $thread;
225 });
226
227 $j = 0;
228 foreach ($threads as $topic) {
229 $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topic->getForumId()));
230 if(is_array($thread_data = $this->frm->getOneTopic()))
231 {
232 if(0 == $j)
233 {
234 $tpl->setVariable('TITLE', $thread_data['top_name']);
235 }
236
237 $first_post = $topic->getFirstPostNode();
238 $topic->setOrderField('frm_posts_tree.rgt');
239 $post_collection = $topic->getPostTree($first_post);
240
241 $z = 0;
242 foreach($post_collection as $post)
243 {
244 $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_CLIENT);
245 }
246
247 $tpl->setCurrentBlock('thread_headline');
248 $tpl->setVariable('T_TITLE', $topic->getSubject());
249 if($this->is_moderator)
250 {
251 $tpl->setVariable('T_NUM_POSTS', $topic->countPosts());
252 }
253 else
254 {
255 $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts());
256 }
257 $tpl->setVariable('T_NUM_VISITS', $topic->getVisits());
258 $tpl->setVariable('T_FORUM', $thread_data['top_name']);
259 $authorinfo = new ilForumAuthorInformation(
260 $topic->getThrAuthorId(),
261 $topic->getDisplayUserId(),
262 $topic->getUserAlias(),
263 $topic->getImportName()
264 );
265 $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
266 $tpl->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': ');
267 $tpl->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': ');
268 $tpl->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': ');
269 $tpl->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': ');
270 $tpl->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': ');
271 $tpl->parseCurrentBlock();
272
273 ++$j;
274 }
275
276 $tpl->setCurrentBlock('thread_block');
277 $tpl->parseCurrentBlock();
278 }
279
280 ilUtil::deliverData($tpl->get('DEFAULT', false, false, false, true, false, false), 'forum_html_export_' . $_GET['ref_id'] . '.html');
281 }
282
289 protected function renderPostHtml(ilTemplate $tpl, ilForumPost $post, $counter, $mode)
290 {
297 global $lng, $rbacreview, $ilUser, $ilObjDataCache;
298
299 $tpl->setCurrentBlock('posts_row');
300
301 if(ilForumProperties::getInstance($ilObjDataCache->lookupObjId($_GET['ref_id']))->getMarkModeratorPosts() == 1)
302 {
303 if($post->getIsAuthorModerator() === null && $is_moderator = ilForum::_isModerator($_GET['ref_id'], $post->getPosAuthorId()) )
304 {
305 $rowCol = 'ilModeratorPosting';
306 }
307 else if($post->getIsAuthorModerator())
308 {
309 $rowCol = 'ilModeratorPosting';
310 }
311 else
312 {
313 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
314 }
315 }
316 else
317 {
318 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
319 }
320
321 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
322
323 // post is censored
324 if($post->isCensored())
325 {
326 // display censorship advice
327 $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $lng->txt('post_censored_comment_by_moderator'));
328 // highlight censored posts
329 $rowCol = 'tblrowmarked';
330 }
331
332 // set row color
333 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
334 // if post is not activated display message for the owner
335 if(!$post->isActivated() && $post->isOwner($ilUser->getId()))
336 {
337 $tpl->setVariable('POST_NOT_ACTIVATED_YET', $lng->txt('frm_post_not_activated_yet'));
338 }
339
340 $authorinfo = new ilForumAuthorInformation(
341 $post->getPosAuthorId(),
342 $post->getDisplayUserId(),
343 $post->getUserAlias(),
344 $post->getImportName()
345 );
346
347 if($authorinfo->hasSuffix())
348 {
349 $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
350 $tpl->setVariable('USR_NAME', $post->getUserAlias());
351 }
352 else
353 {
354 $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
355 if($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized() )
356 {
357 $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
358 }
359 }
360
361 if(self::MODE_EXPORT_CLIENT == $mode )
362 {
363 if($authorinfo->getAuthor()->getPref('public_profile') != 'n')
364 {
365 $tpl->setVariable('TXT_REGISTERED', $lng->txt('registered_since'));
366 $tpl->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
367 }
368
369 if($post->getDisplayUserId())
370 {
371 if($this->is_moderator)
372 {
373 $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
374 }
375 else
376 {
377 $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
378 }
379 $tpl->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts'));
380 $tpl->setVariable('NUM_POSTS', $num_posts);
381 }
382 }
383
384 $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
385 if($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int)$_GET['ref_id'], $post->getPosAuthorId()))
386 {
387 if($authorinfo->getAuthor()->getGender() == 'f')
388 {
389 $tpl->setVariable('ROLE', $lng->txt('frm_moderator_f'));
390 }
391 else if($authorinfo->getAuthor()->getGender() == 'm')
392 {
393 $tpl->setVariable('ROLE', $lng->txt('frm_moderator_m'));
394 }
395 }
396
397 // get create- and update-dates
398 if($post->getUpdateUserId() > 0)
399 {
400 $spanClass = '';
401
402 // last update from moderator?
403 $posMod = $this->frm->getModeratorFromPost($post->getId());
404
405 if(is_array($posMod) && $posMod['top_mods'] > 0)
406 {
407 $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
408 if(is_array($MODS))
409 {
410 if(in_array($post->getUpdateUserId(), $MODS))
411 $spanClass = 'moderator_small';
412 }
413 }
414
415 $post->setChangeDate($post->getChangeDate());
416
417 if($spanClass == '') $spanClass = 'small';
418
419 require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
420 $authorinfo = new ilForumAuthorInformation(
421 $post->getPosAuthorId(),
422 $post->getDisplayUserId(),
423 $post->getUserAlias(),
424 ''
425 );
426
427 $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($lng->txt('by')));
428 $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
429 if($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized())
430 {
431 $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
432 }
433 }
434
435 // prepare post
436 $post->setMessage($this->frm->prepareText($post->getMessage()));
437 $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
438 $tpl->setVariable('SUBJECT', $post->getSubject());
439
440 if(!$post->isCensored())
441 {
442 // post from moderator?
443 $modAuthor = $this->frm->getModeratorFromPost($post->getId());
444
445 $spanClass = "";
446
447 if(is_array($modAuthor) && $modAuthor['top_mods'] > 0)
448 {
449 $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
450 if(is_array($MODS) && in_array($post->getDisplayUserId(), $MODS))
451 {
452 $spanClass = 'moderator';
453 }
454 }
455
456 // possible bugfix for mantis #8223
457 if($post->getMessage() == strip_tags($post->getMessage()))
458 {
459 // We can be sure, that there are not html tags
460 $post->setMessage(nl2br($post->getMessage()));
461 }
462
463 if($spanClass != "")
464 {
465 $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1) . "</span>");
466 }
467 else
468 {
469 $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
470 }
471 }
472 else
473 {
474 $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($post->getCensorshipComment()) . "</span>");
475 }
476
477 $tpl->parseCurrentBlock('posts_row');
478 }
479
483 protected function prepare()
484 {
485 include_once './Services/MathJax/classes/class.ilMathJax.php';
488 ->setZoomFactor(10);
489 }
490}
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
static setUseRelativeDates($a_status)
set use relative dates
Forum export to HTML and Print.
ensureThreadBelongsToForum($objId, \ilForumTopic $thread)
prepare()
Prepare the export (init MathJax rendering)
isOwner($a_user_id=0)
setChangeDate($a_changedate)
setMessage($a_message)
static getInstance($a_obj_id=0)
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
static getInstance()
Singleton: get instance.
const PURPOSE_EXPORT
Class ilObjForum.
static lookupForumIdByObjId($obj_id)
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
special template class to simplify handling of ITX/PEAR
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static switchColor($a_num, $a_css1, $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows)
static initjQuery($a_tpl=null)
Init jQuery.
$counter
global $ilCtrl
Definition: ilias.php:18
global $ilErr
Definition: raiseError.php:16
$cmd
Definition: sahs_server.php:35
$ilUser
Definition: imgupload.php:18