ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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->objProperties = ilForumProperties::getInstance($forum->getId());
42 
43  $this->frm->setForumId($forum->getId());
44  $this->frm->setForumRefId($forum->getRefId());
45 
46  $this->ctrl = $ilCtrl;
47  $lng->loadLanguageModule('forum');
48 
49  $this->is_moderator = $ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id']);
50  }
51 
55  public function executeCommand()
56  {
57  $next_class = $this->ctrl->getNextClass($this);
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  return $this->$cmd();
64  break;
65  }
66  }
67 
71  public function printThread()
72  {
79  global $tpl, $lng, $ilAccess, $ilias;
80 
81  if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
82  {
83  $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
84  }
85 
87 
88  $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
89  $location_stylesheet = ilUtil::getStyleSheetLocation();
90  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
91 
92  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
94 
95  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int)$_GET['thr_top_fk']));
96  if(is_array($frmData = $this->frm->getOneTopic()))
97  {
98  $topic = new ilForumTopic(addslashes($_GET['print_thread']), $this->is_moderator);
99 
100  $topic->setOrderField('frm_posts_tree.rgt');
101  $first_post = $topic->getFirstPostNode();
102  $post_collection = $topic->getPostTree($first_post);
103  $num_posts = count($post_collection);
104 
105  $tpl->setVariable('TITLE', $topic->getSubject());
106  $tpl->setVariable(
107  'HEADLINE',
108  $lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' .
109  $lng->txt('forums_thread') . ': ' . $topic->getSubject() . ' > ' .
110  $lng->txt('forums_count_art') . ': ' . $num_posts);
111 
112  $z = 0;
113  foreach($post_collection as $post)
114  {
115  $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_WEB);
116  }
117  }
118  $tpl->show();
119  }
120 
124  public function printPost()
125  {
132  global $tpl, $lng, $ilAccess, $ilias;
133 
134  if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
135  {
136  $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
137  }
138 
140 
141  $tpl = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
142  $location_stylesheet = ilUtil::getStyleSheetLocation();
143  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
144 
145  require_once 'Services/jQuery/classes/class.iljQueryUtil.php';
147 
148  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array((int)$_GET['top_pk']));
149  if(is_array($frmData = $this->frm->getOneTopic()))
150  {
151  $post = new ilForumPost((int)$_GET['print_post'], $this->is_moderator);
152 
153  $tpl->setVariable('TITLE', $post->getThread()->getSubject());
154  $tpl->setVariable('HEADLINE', $lng->txt('forum').': '.$frmData['top_name'].' > '. $lng->txt('forums_thread').': '.$post->getThread()->getSubject());
155 
156  $this->renderPostHtml($tpl, $post, 0, self::MODE_EXPORT_WEB);
157  }
158  $tpl->show();
159  }
160 
164  public function exportHTML()
165  {
172  global $lng, $tpl, $ilAccess, $ilias;
173 
174  if(!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id']))
175  {
176  $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
177  }
178 
180 
181  $tpl = new ilTemplate('tpl.forums_export_html.html', true, true, 'Modules/Forum');
182  $location_stylesheet = ilUtil::getStyleSheetLocation();
183  $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
184  $tpl->setVariable('BASE', (substr(ILIAS_HTTP_PATH, -1) == '/' ? ILIAS_HTTP_PATH : ILIAS_HTTP_PATH . '/'));
185 
186  $num_threads = count((array)$_POST['thread_ids']);
187  for($j = 0; $j < $num_threads; $j++)
188  {
189  $topic = new ilForumTopic((int)$_POST['thread_ids'][$j], $this->is_moderator);
190 
191  $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topic->getForumId()));
192  if(is_array($thread_data = $this->frm->getOneTopic()))
193  {
194  if(0 == $j)
195  {
196  $tpl->setVariable('TITLE', $thread_data['top_name']);
197  }
198 
199  $first_post = $topic->getFirstPostNode();
200  $topic->setOrderField('frm_posts_tree.rgt');
201  $post_collection = $topic->getPostTree($first_post);
202 
203  $z = 0;
204  foreach($post_collection as $post)
205  {
206  $this->renderPostHtml($tpl, $post, $z++, self::MODE_EXPORT_CLIENT);
207  }
208 
209  $tpl->setCurrentBlock('thread_headline');
210  $tpl->setVariable('T_TITLE', $topic->getSubject());
211  if($this->is_moderator)
212  {
213  $tpl->setVariable('T_NUM_POSTS', $topic->countPosts());
214  }
215  else
216  {
217  $tpl->setVariable('T_NUM_POSTS', $topic->countActivePosts());
218  }
219  $tpl->setVariable('T_NUM_VISITS', $topic->getVisits());
220  $tpl->setVariable('T_FORUM', $thread_data['top_name']);
221  $authorinfo = new ilForumAuthorInformation(
222  $topic->getThrAuthorId(),
223  $topic->getDisplayUserId(),
224  $topic->getUserAlias(),
225  $topic->getImportName()
226  );
227  $tpl->setVariable('T_AUTHOR', $authorinfo->getAuthorName());
228  $tpl->setVariable('T_TXT_FORUM', $lng->txt('forum') . ': ');
229  $tpl->setVariable('T_TXT_TOPIC', $lng->txt('forums_thread') . ': ');
230  $tpl->setVariable('T_TXT_AUTHOR', $lng->txt('forums_thread_create_from') . ': ');
231  $tpl->setVariable('T_TXT_NUM_POSTS', $lng->txt('forums_articles') . ': ');
232  $tpl->setVariable('T_TXT_NUM_VISITS', $lng->txt('visits') . ': ');
233  $tpl->parseCurrentBlock();
234  }
235 
236  $tpl->setCurrentBlock('thread_block');
237  $tpl->parseCurrentBlock();
238  }
239 
240  ilUtil::deliverData($tpl->get('DEFAULT', false, false, false, true, false, false), 'forum_html_export_' . $_GET['ref_id'] . '.html');
241  }
242 
249  protected function renderPostHtml(ilTemplate $tpl, ilForumPost $post, $counter, $mode)
250  {
257  global $lng, $rbacreview, $ilUser, $ilObjDataCache;
258 
259  $tpl->setCurrentBlock('posts_row');
260 
261  if(ilForumProperties::getInstance($ilObjDataCache->lookupObjId($_GET['ref_id']))->getMarkModeratorPosts() == 1)
262  {
263  if($post->getIsAuthorModerator() === null && $is_moderator = ilForum::_isModerator($_GET['ref_id'], $post->getPosAuthorId()) )
264  {
265  $rowCol = 'ilModeratorPosting';
266  }
267  else if($post->getIsAuthorModerator())
268  {
269  $rowCol = 'ilModeratorPosting';
270  }
271  else
272  {
273  $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
274  }
275  }
276  else
277  {
278  $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
279  }
280 
281  $tpl->setVariable('ROWCOL', ' ' . $rowCol);
282 
283  // post is censored
284  if($post->isCensored())
285  {
286  // display censorship advice
287  $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $lng->txt('post_censored_comment_by_moderator'));
288  // highlight censored posts
289  $rowCol = 'tblrowmarked';
290  }
291 
292  // set row color
293  $tpl->setVariable('ROWCOL', ' ' . $rowCol);
294  // if post is not activated display message for the owner
295  if(!$post->isActivated() && $post->isOwner($ilUser->getId()))
296  {
297  $tpl->setVariable('POST_NOT_ACTIVATED_YET', $lng->txt('frm_post_not_activated_yet'));
298  }
299 
300  $authorinfo = new ilForumAuthorInformation(
301  $post->getPosAuthorId(),
302  $post->getDisplayUserId(),
303  $post->getUserAlias(),
304  $post->getImportName()
305  );
306 
307  if($authorinfo->hasSuffix())
308  {
309  $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
310  $tpl->setVariable('USR_NAME', $post->getUserAlias());
311  }
312  else
313  {
314  $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
315  if($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized() )
316  {
317  $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
318  }
319  }
320 
321  if(self::MODE_EXPORT_CLIENT == $mode )
322  {
323  if($authorinfo->getAuthor()->getPref('public_profile') != 'n')
324  {
325  $tpl->setVariable('TXT_REGISTERED', $lng->txt('registered_since'));
326  $tpl->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
327  }
328 
329  if($post->getDisplayUserId())
330  {
331  if($this->is_moderator)
332  {
333  $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
334  }
335  else
336  {
337  $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
338  }
339  $tpl->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts'));
340  $tpl->setVariable('NUM_POSTS', $num_posts);
341  }
342  }
343 
344  $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
345  if($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int)$_GET['ref_id'], $post->getPosAuthorId()))
346  {
347  if($authorinfo->getAuthor()->getGender() == 'f')
348  {
349  $tpl->setVariable('ROLE', $lng->txt('frm_moderator_f'));
350  }
351  else if($authorinfo->getAuthor()->getGender() == 'm')
352  {
353  $tpl->setVariable('ROLE', $lng->txt('frm_moderator_m'));
354  }
355  }
356 
357  // get create- and update-dates
358  if($post->getUpdateUserId() > 0)
359  {
360  $spanClass = '';
361 
362  // last update from moderator?
363  $posMod = $this->frm->getModeratorFromPost($post->getId());
364 
365  if(is_array($posMod) && $posMod['top_mods'] > 0)
366  {
367  $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
368  if(is_array($MODS))
369  {
370  if(in_array($post->getUpdateUserId(), $MODS))
371  $spanClass = 'moderator_small';
372  }
373  }
374 
375  $post->setChangeDate($post->getChangeDate());
376 
377  if($spanClass == '') $spanClass = 'small';
378 
379  require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
380  $authorinfo = new ilForumAuthorInformation(
381  $post->getPosAuthorId(),
382  $post->getDisplayUserId(),
383  $post->getUserAlias(),
384  ''
385  );
386 
387  $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($lng->txt('by')));
388  $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
389  if($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized())
390  {
391  $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
392  }
393  }
394 
395  // prepare post
396  $post->setMessage($this->frm->prepareText($post->getMessage()));
397  $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
398  $tpl->setVariable('SUBJECT', $post->getSubject());
399 
400  if(!$post->isCensored())
401  {
402  // post from moderator?
403  $modAuthor = $this->frm->getModeratorFromPost($post->getId());
404 
405  $spanClass = "";
406 
407  if(is_array($modAuthor) && $modAuthor['top_mods'] > 0)
408  {
409  $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
410  if(is_array($MODS) && in_array($post->getDisplayUserId(), $MODS))
411  {
412  $spanClass = 'moderator';
413  }
414  }
415 
416  // possible bugfix for mantis #8223
417  if($post->getMessage() == strip_tags($post->getMessage()))
418  {
419  // We can be sure, that there are not html tags
420  $post->setMessage(nl2br($post->getMessage()));
421  }
422 
423  if($spanClass != "")
424  {
425  $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1) . "</span>");
426  }
427  else
428  {
429  $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
430  }
431  }
432  else
433  {
434  $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($post->getCensorshipComment()) . "</span>");
435  }
436 
437  $tpl->parseCurrentBlock('posts_row');
438  }
439 }
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.
$_POST['username']
Definition: cron.php:12
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
isOwner($a_user_id=0)
$cmd
Definition: sahs_server.php:35
static setUseRelativeDates($a_status)
set use relative dates
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...
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static getInstance($a_obj_id=0)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:626
Forum export to HTML and Print.
special template class to simplify handling of ITX/PEAR
setMessage($a_message)
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
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.
setChangeDate($a_changedate)
Class ilObjForum.
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...