ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
13 {
14  const MODE_EXPORT_WEB = 1;
15  const MODE_EXPORT_CLIENT = 2;
16 
20  protected $is_moderator = false;
21 
25  protected $frm;
26 
27  public $ctrl;
28  public $lng;
29  public $access;
30  public $error;
31  public $user;
33 
34  public function __construct()
35  {
36  global $DIC;
37 
38  $this->lng = $DIC->language();
39  $this->ctrl = $DIC->ctrl();
40  $this->access = $DIC->access();
41  $this->error = $DIC['ilErr'];
42 
43  $this->user = $DIC->user();
44  $this->ilObjDataCache = $DIC['ilObjDataCache'];
45 
46  $forum = new ilObjForum((int) $_GET['ref_id']);
47  $this->frm = $forum->Forum;
48  $this->objProperties = ilForumProperties::getInstance($forum->getId());
49 
50  $this->frm->setForumId($forum->getId());
51  $this->frm->setForumRefId($forum->getRefId());
52 
53  $this->lng->loadLanguageModule('forum');
54 
55  $this->is_moderator = $this->access->checkAccess('moderate_frm', '', (int) $_GET['ref_id']);
56  }
57 
62  public function ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
63  {
64  $forumId = \ilObjForum::lookupForumIdByObjId($objId);
65  if ((int) $thread->getForumId() !== (int) $forumId) {
66  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
67  }
68  }
69 
73  public function executeCommand()
74  {
75  $next_class = $this->ctrl->getNextClass($this);
76  $cmd = $this->ctrl->getCmd();
77 
78  switch ($next_class) {
79  default:
80  return $this->$cmd();
81  break;
82  }
83  }
84 
85  public function printThread()
86  {
87  if (!$this->access->checkAccess('read,visible', '', (int) $_GET['ref_id'])) {
88  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
89  }
90 
91  // fau: call prepare to init mathjax rendering
92  $this->prepare();
93 
95 
96  $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
97  $location_stylesheet = ilUtil::getStyleSheetLocation();
98  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
99 
101  ilMathJax::getInstance()->includeMathJax($tpl);
102 
103  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int) $_GET['thr_top_fk']));
104  if (is_array($frmData = $this->frm->getOneTopic())) {
105  $topic = new ilForumTopic(addslashes($_GET['print_thread']), $this->is_moderator);
106  $this->ensureThreadBelongsToForum((int) $this->frm->getForumId(), $topic);
107 
108  $topic->setOrderField('frm_posts_tree.rgt');
109  $first_post = $topic->getFirstPostNode();
110  $post_collection = $topic->getPostTree($first_post);
111  $num_posts = count($post_collection);
112 
113  $tpl->setVariable('TITLE', $topic->getSubject());
114  $tpl->setVariable(
115  'HEADLINE',
116  $this->lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' .
117  $this->lng->txt('forums_thread') . ': ' . $topic->getSubject() . ' > ' .
118  $this->lng->txt('forums_count_art') . ': ' . $num_posts
119  );
120 
121  $z = 0;
122  foreach ($post_collection as $post) {
123  $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_WEB);
124  }
125  }
126  $tpl->show();
127  }
128 
129  public function printPost()
130  {
131  if (!$this->access->checkAccess('read,visible', '', $_GET['ref_id'])) {
132  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
133  }
134 
135  // call prepare to init mathjax rendering
136  $this->prepare();
137 
139 
140  $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
141  $location_stylesheet = ilUtil::getStyleSheetLocation();
142  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
143 
145  ilMathJax::getInstance()->includeMathJax($tpl);
146 
147  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int) $_GET['top_pk']));
148  if (is_array($frmData = $this->frm->getOneTopic())) {
149  $post = new ilForumPost((int) $_GET['print_post'], $this->is_moderator);
150  $this->ensureThreadBelongsToForum((int) $this->frm->getForumId(), $post->getThread());
151 
152  $tpl->setVariable('TITLE', $post->getThread()->getSubject());
153  $tpl->setVariable('HEADLINE', $this->lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' . $this->lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject());
154 
155  $this->renderPostHtml($tpl, $post, 0, self::MODE_EXPORT_WEB);
156  }
157  $tpl->show();
158  }
159 
163  public function exportHTML()
164  {
165  if (!$this->access->checkAccess('read,visible', '', $_GET['ref_id'])) {
166  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
167  }
168 
169  // call prepare to init mathjax rendering
170  $this->prepare();
171 
173 
174  $tpl = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
175  $location_stylesheet = ilUtil::getStyleSheetLocation();
176  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
177  $tpl->setVariable('BASE', (substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'));
178 
179  $threads = [];
180  $isModerator = $this->is_moderator;
181  $postIds = (array) $_POST['thread_ids'];
182  array_walk($postIds, function ($threadId) use (&$threads, $isModerator) {
183  $thread = new \ilForumTopic($threadId, $isModerator);
184  $this->ensureThreadBelongsToForum((int) $this->frm->getForumId(), $thread);
185 
186  $threads[] = $thread;
187  });
188 
189  $j = 0;
190  foreach ($threads as $topic) {
191  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topic->getForumId()));
192  if (is_array($thread_data = $this->frm->getOneTopic())) {
193  if (0 == $j) {
194  $tpl->setVariable('TITLE', $thread_data['top_name']);
195  }
196 
197  $first_post = $topic->getFirstPostNode();
198  $topic->setOrderField('frm_posts_tree.rgt');
199  $post_collection = $topic->getPostTree($first_post);
200 
201  $z = 0;
202  foreach ($post_collection as $post) {
203  $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_CLIENT);
204  }
205 
206  $tpl->setCurrentBlock('thread_headline');
207  $tpl->setVariable('T_TITLE', $topic->getSubject());
208  if ($this->is_moderator) {
209  $tpl->setVariable('T_NUM_POSTS', $topic->countPosts(true));
210  } else {
211  $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts(true));
212  }
213  $tpl->setVariable('T_NUM_VISITS', $topic->getVisits());
214  $tpl->setVariable('T_FORUM', $thread_data['top_name']);
215  $authorinfo = new ilForumAuthorInformation(
216  $topic->getThrAuthorId(),
217  $topic->getDisplayUserId(),
218  $topic->getUserAlias(),
219  $topic->getImportName()
220  );
221  $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
222  $tpl->setVariable('T_TXT_FORUM', $this->lng->txt('forum') . ': ');
223  $tpl->setVariable('T_TXT_TOPIC', $this->lng->txt('forums_thread') . ': ');
224  $tpl->setVariable('T_TXT_AUTHOR', $this->lng->txt('forums_thread_create_from') . ': ');
225  $tpl->setVariable('T_TXT_NUM_POSTS', $this->lng->txt('forums_articles') . ': ');
226  $tpl->setVariable('T_TXT_NUM_VISITS', $this->lng->txt('visits') . ': ');
227  $tpl->parseCurrentBlock();
228 
229  ++$j;
230  }
231 
232  $tpl->setCurrentBlock('thread_block');
233  $tpl->parseCurrentBlock();
234  }
235 
236  ilUtil::deliverData($tpl->get('DEFAULT', false, false, false, true, false, false), 'forum_html_export_' . $_GET['ref_id'] . '.html');
237  }
238 
245  protected function renderPostHtml(\ilTemplate $tpl, ilForumPost $post, $counter, $mode)
246  {
247  $tpl->setCurrentBlock('posts_row');
248 
249  if (ilForumProperties::getInstance($this->ilObjDataCache->lookupObjId($_GET['ref_id']))->getMarkModeratorPosts() == 1) {
250  if ($post->getIsAuthorModerator() === null && $is_moderator = ilForum::_isModerator($_GET['ref_id'], $post->getPosAuthorId())) {
251  $rowCol = 'ilModeratorPosting';
252  } elseif ($post->getIsAuthorModerator()) {
253  $rowCol = 'ilModeratorPosting';
254  } else {
255  $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
256  }
257  } else {
258  $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
259  }
260 
261  $tpl->setVariable('ROWCOL', ' ' . $rowCol);
262 
263  if ($post->isCensored()) {
264  $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
265  $rowCol = 'tblrowmarked';
266  }
267 
268  $tpl->setVariable('ROWCOL', ' ' . $rowCol);
269  if (!$post->isActivated() && $post->isOwner($this->user->getId())) {
270  $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
271  }
272 
273  $authorinfo = new ilForumAuthorInformation(
274  $post->getPosAuthorId(),
275  $post->getDisplayUserId(),
276  $post->getUserAlias(),
277  $post->getImportName()
278  );
279 
280  if ($authorinfo->hasSuffix()) {
281  if (!$authorinfo->isDeleted()) {
282  $tpl->setVariable('USR_NAME', $authorinfo->getAlias());
283  }
284  $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
285  } else {
286  if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
287  $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
288  }
289  $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
290  }
291 
292  if (self::MODE_EXPORT_CLIENT == $mode) {
293  if ($authorinfo->getAuthor()->getPref('public_profile') != 'n') {
294  $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('registered_since'));
295  $tpl->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
296  }
297 
298  if ($post->getDisplayUserId()) {
299  if ($this->is_moderator) {
300  $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
301  } else {
302  $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
303  }
304  $tpl->setVariable('TXT_NUM_POSTS', $this->lng->txt('forums_posts'));
305  $tpl->setVariable('NUM_POSTS', $num_posts);
306  }
307  }
308 
309  $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
310  if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int) $_GET['ref_id'], $post->getPosAuthorId())) {
311  if ($authorinfo->getAuthor()->getGender() == 'f') {
312  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
313  } elseif ($authorinfo->getAuthor()->getGender() == 'm') {
314  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
315  } elseif ($authorinfo->getAuthor()->getGender() == 'n') {
316  $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_n'));
317  }
318  }
319 
320  // get create- and update-dates
321  if ($post->getUpdateUserId() > 0) {
322  $spanClass = '';
323  if (ilForum::_isModerator((int) $_GET['ref_id'], $post->getUpdateUserId())) {
324  $spanClass = 'moderator_small';
325  }
326 
327  $post->setChangeDate($post->getChangeDate());
328 
329  $authorinfo = new ilForumAuthorInformation(
330  $post->getPosAuthorId(),
331  $post->getDisplayUserId(),
332  $post->getUserAlias(),
333  ''
334  );
335 
336  $tpl->setVariable('POST_UPDATE_TXT', $this->lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($this->lng->txt('by')));
337  $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
338  if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
339  $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
340  }
341  }
342 
343  // prepare post
344  $post->setMessage($this->frm->prepareText($post->getMessage()));
345  $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
346  $tpl->setVariable('SUBJECT', $post->getSubject());
347 
348  if (!$post->isCensored()) {
349  $spanClass = "";
350  if (ilForum::_isModerator((int) $_GET['ref_id'], $post->getDisplayUserId())) {
351  $spanClass = 'moderator';
352  }
353 
354  // possible bugfix for mantis #8223
355  if ($post->getMessage() == strip_tags($post->getMessage())) {
356  // We can be sure, that there are not html tags
357  $post->setMessage(nl2br($post->getMessage()));
358  }
359 
360  if ($spanClass != "") {
361  $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1) . "</span>");
362  } else {
363  $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
364  }
365  } else {
366  $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($post->getCensorshipComment()) . "</span>");
367  }
368 
369  $tpl->parseCurrentBlock('posts_row');
370  }
371 
375  protected function prepare()
376  {
379  ->setZoomFactor(10);
380  }
381 }
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static lookupForumIdByObjId($obj_id)
global $DIC
Definition: saml.php:7
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
$tpl
Definition: ilias.php:10
isOwner($a_user_id=0)
static setUseRelativeDates($a_status)
set use relative dates
renderPostHtml(\ilTemplate $tpl, ilForumPost $post, $counter, $mode)
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...
user()
Definition: user.php:4
ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
static getInstance($a_obj_id=0)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
Forum export to HTML and Print.
special template class to simplify handling of ITX/PEAR
$post
Definition: post.php:34
const PURPOSE_EXPORT
setMessage($a_message)
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
static getInstance()
Singleton: get instance.
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)
inits and adds the jQuery JS-File to the global or a passed template
setChangeDate($a_changedate)
Class ilObjForum.
$_POST["username"]
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...
prepare()
Prepare the export (init MathJax rendering)