ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 require_once 'Modules/Forum/classes/class.ilForumProperties.php';
5 require_once 'Services/RTE/classes/class.ilRTE.php';
6 require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
7 require_once 'Modules/Forum/classes/class.ilForum.php';
8 
18 {
19  const MODE_EXPORT_WEB = 1;
20  const MODE_EXPORT_CLIENT = 2;
21 
25  protected $is_moderator = false;
26 
30  protected $frm;
31 
35  public function __construct()
36  {
37  global $lng, $ilCtrl, $ilAccess;
38 
39  $forum = new ilObjForum((int)$_GET['ref_id']);
40  $this->frm = $forum->Forum;
41  $this->frm->setForumId($forum->getId());
42  $this->frm->setForumRefId($forum->getRefId());
43 
44  $this->ctrl = $ilCtrl;
45  $lng->loadLanguageModule('forum');
46 
47  $this->is_moderator = $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id']);
48  }
49 
53  public function executeCommand()
54  {
55  $next_class = $this->ctrl->getNextClass($this);
56  $cmd = $this->ctrl->getCmd();
57 
58  switch($next_class)
59  {
60  default:
61  return $this->$cmd();
62  break;
63  }
64  }
65 
69  public function printThread()
70  {
77  global $tpl, $lng, $ilAccess, $ilias;
78 
79  if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
80  {
81  $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
82  }
83 
85 
86  $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
87  $location_stylesheet = ilUtil::getStyleSheetLocation();
88  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
89 
90  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
92 
93  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int)$_GET['thr_top_fk']));
94  if(is_array($frmData = $this->frm->getOneTopic()))
95  {
96  $topic = new ilForumTopic(addslashes($_GET['print_thread']), $this->is_moderator);
97 
98  $topic->setOrderField('frm_posts_tree.rgt');
99  $first_post = $topic->getFirstPostNode();
100  $post_collection = $topic->getPostTree($first_post);
101  $num_posts = count($post_collection);
102 
103  $tpl->setVariable('TITLE', $topic->getSubject());
104  $tpl->setVariable(
105  'HEADLINE',
106  $lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' .
107  $lng->txt('forums_thread') . ': ' . $topic->getSubject() . ' > ' .
108  $lng->txt('forums_count_art') . ': ' . $num_posts);
109 
110  $z = 0;
111  foreach($post_collection as $post)
112  {
113  $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_WEB);
114  }
115  }
116  $tpl->show();
117  }
118 
122  public function printPost()
123  {
130  global $tpl, $lng, $ilAccess, $ilias;
131 
132  if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
133  {
134  $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
135  }
136 
138 
139  $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
140  $location_stylesheet = ilUtil::getStyleSheetLocation();
141  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
142 
143  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
145 
146  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int)$_GET['top_pk']));
147  if(is_array($frmData = $this->frm->getOneTopic()))
148  {
149  $post = new ilForumPost((int)$_GET['print_post'], $this->is_moderator);
150 
151  $tpl->setVariable('TITLE', $post->getThread()->getSubject());
152  $tpl->setVariable('HEADLINE', $lng->txt('forum').': '.$frmData['top_name'].' > '. $lng->txt('forums_thread').': '.$post->getThread()->getSubject());
153 
154  $this->renderPostHtml($tpl, $post, 0, self::MODE_EXPORT_WEB);
155  }
156  $tpl->show();
157  }
158 
162  public function exportHTML()
163  {
170  global $lng, $tpl, $ilAccess, $ilias;
171 
172  if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
173  {
174  $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
175  }
176 
178 
179  $tpl = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
180  $location_stylesheet = ilUtil::getStyleSheetLocation();
181  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
182  $tpl->setVariable('BASE', (substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'));
183 
184  $num_threads = count((array)$_POST['thread_ids']);
185  for($j = 0; $j < $num_threads; $j++)
186  {
187  $topic = new ilForumTopic((int)$_POST['thread_ids'][$j], $this->is_moderator);
188 
189  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topic->getForumId()));
190  if(is_array($thread_data = $this->frm->getOneTopic()))
191  {
192  if(0 == $j)
193  {
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  {
204  $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_CLIENT);
205  }
206 
207  $tpl->setCurrentBlock('thread_headline');
208  $tpl->setVariable('T_TITLE', $topic->getSubject());
209  if($this->is_moderator)
210  {
211  $tpl->setVariable('T_NUM_POSTS', $topic->countPosts());
212  }
213  else
214  {
215  $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts());
216  }
217  $tpl->setVariable('T_NUM_VISITS', $topic->getVisits());
218  $tpl->setVariable('T_FORUM', $thread_data['top_name']);
219  $authorinfo = new ilForumAuthorInformation(
220  $topic->getUserId(),
221  $topic->getUserAlias(),
222  $topic->getImportName()
223  );
224  $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
225  $tpl->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': ');
226  $tpl->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': ');
227  $tpl->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': ');
228  $tpl->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': ');
229  $tpl->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': ');
230  $tpl->parseCurrentBlock();
231  }
232 
233  $tpl->setCurrentBlock('thread_block');
234  $tpl->parseCurrentBlock();
235  }
236 
237  ilUtil::deliverData($tpl->get('DEFAULT', false, false, false, true, false, false), 'forum_html_export_' . $_GET['ref_id'] . '.html');
238  }
239 
246  protected function renderPostHtml(ilTemplate $tpl, ilForumPost $post, $counter, $mode)
247  {
254  global $lng, $rbacreview, $ilUser, $ilObjDataCache;
255 
256  $tpl->setCurrentBlock('posts_row');
257 
258  if(ilForumProperties::getInstance($ilObjDataCache->lookupObjId($_GET['ref_id']))->getMarkModeratorPosts() == 1)
259  {
260  $is_moderator = ilForum::_isModerator($_GET['ref_id'], $post->getUserId());
261  if($is_moderator)
262  {
263  $rowCol = 'ilHighlighted';
264  }
265  else
266  {
267  $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
268  }
269  }
270  else
271  {
272  $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
273  }
274 
275  $tpl->setVariable('ROWCOL', ' ' . $rowCol);
276 
277  // post is censored
278  if($post->isCensored())
279  {
280  // display censorship advice
281  $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $lng->txt('post_censored_comment_by_moderator'));
282  // highlight censored posts
283  $rowCol = 'tblrowmarked';
284  }
285 
286  // set row color
287  $tpl->setVariable('ROWCOL', ' ' . $rowCol);
288  // if post is not activated display message for the owner
289  if(!$post->isActivated() && $post->isOwner($ilUser->getId()))
290  {
291  $tpl->setVariable('POST_NOT_ACTIVATED_YET', $lng->txt('frm_post_not_activated_yet'));
292  }
293 
294  $authorinfo = new ilForumAuthorInformation(
295  $post->getUserId(),
296  $post->getUserAlias(),
297  $post->getImportName()
298  );
299 
300  $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
301  if($authorinfo->getAuthorName(true))
302  {
303  $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
304  }
305 
306  if(self::MODE_EXPORT_CLIENT == $mode )
307  {
308  if($authorinfo->getAuthor()->getPref('public_profile') != 'n')
309  {
310  $tpl->setVariable('TXT_REGISTERED', $lng->txt('registered_since'));
311  $tpl->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
312  }
313 
314  if($post->getUserId())
315  {
316  if($this->is_moderator)
317  {
318  $num_posts = $this->frm->countUserArticles($post->getUserId());
319  }
320  else
321  {
322  $num_posts = $this->frm->countActiveUserArticles($post->getUserId());
323  }
324  $tpl->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts'));
325  $tpl->setVariable('NUM_POSTS', $num_posts);
326  }
327  }
328 
329  $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
330  if($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int)$_GET['ref_id'], $authorinfo->getAuthor()->getId()))
331  {
332  if($authorinfo->getAuthor()->getGender() == 'f')
333  {
334  $tpl->setVariable('ROLE', $lng->txt('frm_moderator_f'));
335  }
336  else if($authorinfo->getAuthor()->getGender() == 'm')
337  {
338  $tpl->setVariable('ROLE', $lng->txt('frm_moderator_m'));
339  }
340  }
341 
342  // get create- and update-dates
343  if($post->getUpdateUserId() > 0)
344  {
345  $spanClass = '';
346 
347  // last update from moderator?
348  $posMod = $this->frm->getModeratorFromPost($post->getId());
349 
350  if(is_array($posMod) && $posMod['top_mods'] > 0)
351  {
352  $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
353  if(is_array($MODS))
354  {
355  if(in_array($post->getUpdateUserId(), $MODS))
356  $spanClass = 'moderator_small';
357  }
358  }
359 
360  $post->setChangeDate($post->getChangeDate());
361 
362  if($spanClass == '') $spanClass = 'small';
363 
364  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
365  $authorinfo = new ilForumAuthorInformation(
366  $post->getUpdateUserId(),
367  '',
368  ''
369  );
370 
371  $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($lng->txt('by')));
372  $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
373  if($authorinfo->getAuthorName(true))
374  {
375  $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
376  }
377  }
378 
379  // prepare post
380  $post->setMessage($this->frm->prepareText($post->getMessage()));
381  $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
382  $tpl->setVariable('SUBJECT', $post->getSubject());
383 
384  if(!$post->isCensored())
385  {
386  // post from moderator?
387  $modAuthor = $this->frm->getModeratorFromPost($post->getId());
388 
389  $spanClass = "";
390 
391  if(is_array($modAuthor) && $modAuthor['top_mods'] > 0)
392  {
393  $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
394  if(is_array($MODS) && in_array($post->getUserId(), $MODS))
395  {
396  $spanClass = 'moderator';
397  }
398  }
399 
400  // possible bugfix for mantis #8223
401  if($post->getMessage() == strip_tags($post->getMessage()))
402  {
403  // We can be sure, that there are not html tags
404  $post->setMessage(nl2br($post->getMessage()));
405  }
406 
407  if($spanClass != "")
408  {
409  $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1) . "</span>");
410  }
411  else
412  {
413  $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
414  }
415  }
416  else
417  {
418  $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($post->getCensorshipComment()) . "</span>");
419  }
420 
421  $tpl->parseCurrentBlock('posts_row');
422  }
423 }