ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilForumExportGUI Class Reference

Forum export to HTML and Print. More...

+ Collaboration diagram for ilForumExportGUI:

Public Member Functions

 __construct ()
 
 ensureThreadBelongsToForum (int $objId, \ilForumTopic $thread)
 
 executeCommand ()
 
 printThread ()
 
 printPost ()
 
 exportHTML ()
 

Data Fields

const MODE_EXPORT_WEB = 1
 
const MODE_EXPORT_CLIENT = 2
 
 $ctrl
 
 $lng
 
 $access
 
 $error
 
 $user
 
 $ilObjDataCache
 

Protected Member Functions

 renderPostHtml (\ilTemplate $tpl, ilForumPost $post, $counter, $mode)
 
 prepare ()
 Prepare the export (init MathJax rendering) More...
 

Protected Attributes

 $is_moderator = false
 
 $frm
 

Detailed Description

Forum export to HTML and Print.

Author
Wolfgang Merkens wmerk.nosp@m.ens@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilForumExportGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumExportGUI::__construct ( )

Definition at line 34 of file class.ilForumExportGUI.php.

References $_GET, $DIC, ilForumProperties\getInstance(), and user().

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  }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
user()
Definition: user.php:4
static getInstance($a_obj_id=0)
Class ilObjForum.
+ Here is the call graph for this function:

Member Function Documentation

◆ ensureThreadBelongsToForum()

ilForumExportGUI::ensureThreadBelongsToForum ( int  $objId,
\ilForumTopic  $thread 
)
Parameters
int$objId
ilForumTopic$thread

Definition at line 62 of file class.ilForumExportGUI.php.

References ilForumTopic\getForumId(), and ilObjForum\lookupForumIdByObjId().

Referenced by exportHTML(), printPost(), and printThread().

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  }
static lookupForumIdByObjId($obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilForumExportGUI::executeCommand ( )

Definition at line 73 of file class.ilForumExportGUI.php.

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  }

◆ exportHTML()

ilForumExportGUI::exportHTML ( )

Definition at line 163 of file class.ilForumExportGUI.php.

References $_GET, $_POST, $is_moderator, $post, $tpl, ilUtil\deliverData(), ensureThreadBelongsToForum(), ilUtil\getStyleSheetLocation(), prepare(), renderPostHtml(), and ilDatePresentation\setUseRelativeDates().

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  }
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
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
static setUseRelativeDates($a_status)
set use relative dates
renderPostHtml(\ilTemplate $tpl, ilForumPost $post, $counter, $mode)
ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
special template class to simplify handling of ITX/PEAR
$post
Definition: post.php:34
$_POST["username"]
prepare()
Prepare the export (init MathJax rendering)
+ Here is the call graph for this function:

◆ prepare()

ilForumExportGUI::prepare ( )
protected

Prepare the export (init MathJax rendering)

Definition at line 375 of file class.ilForumExportGUI.php.

References ilMathJax\getInstance(), and ilMathJax\PURPOSE_EXPORT.

Referenced by exportHTML(), printPost(), and printThread().

376  {
379  ->setZoomFactor(10);
380  }
const PURPOSE_EXPORT
static getInstance()
Singleton: get instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ printPost()

ilForumExportGUI::printPost ( )

Definition at line 129 of file class.ilForumExportGUI.php.

References $_GET, $post, $tpl, ensureThreadBelongsToForum(), ilMathJax\getInstance(), ilUtil\getStyleSheetLocation(), iljQueryUtil\initjQuery(), prepare(), renderPostHtml(), and ilDatePresentation\setUseRelativeDates().

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  }
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
static setUseRelativeDates($a_status)
set use relative dates
renderPostHtml(\ilTemplate $tpl, ilForumPost $post, $counter, $mode)
ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
special template class to simplify handling of ITX/PEAR
$post
Definition: post.php:34
static getInstance()
Singleton: get instance.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
prepare()
Prepare the export (init MathJax rendering)
+ Here is the call graph for this function:

◆ printThread()

ilForumExportGUI::printThread ( )

Definition at line 85 of file class.ilForumExportGUI.php.

References $_GET, $post, $tpl, ensureThreadBelongsToForum(), ilMathJax\getInstance(), ilUtil\getStyleSheetLocation(), iljQueryUtil\initjQuery(), prepare(), renderPostHtml(), and ilDatePresentation\setUseRelativeDates().

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  }
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
static setUseRelativeDates($a_status)
set use relative dates
renderPostHtml(\ilTemplate $tpl, ilForumPost $post, $counter, $mode)
ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
special template class to simplify handling of ITX/PEAR
$post
Definition: post.php:34
static getInstance()
Singleton: get instance.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
prepare()
Prepare the export (init MathJax rendering)
+ Here is the call graph for this function:

◆ renderPostHtml()

ilForumExportGUI::renderPostHtml ( \ilTemplate  $tpl,
ilForumPost  $post,
  $counter,
  $mode 
)
protected
Parameters
\ilTemplate$tpl
ilForumPost$post
int$counter
int$mode

Definition at line 245 of file class.ilForumExportGUI.php.

References $_GET, $is_moderator, ilForum\_isModerator(), ilRTE\_replaceMediaObjectImageSrc(), ilForumPost\getCensorshipComment(), ilForumPost\getChangeDate(), ilForumPost\getCreateDate(), ilForumPost\getDisplayUserId(), ilForumPost\getImportName(), ilForumProperties\getInstance(), ilForumPost\getIsAuthorModerator(), ilForumPost\getMessage(), ilForumPost\getPosAuthorId(), ilForumPost\getSubject(), ilForumPost\getUpdateUserId(), ilForumPost\getUserAlias(), ilForumPost\isActivated(), ilForumPost\isCensored(), ilForumPost\isOwner(), ilTemplate\parseCurrentBlock(), ilForumPost\setChangeDate(), ilTemplate\setCurrentBlock(), ilForumPost\setMessage(), HTML_Template_IT\setVariable(), ilUtil\switchColor(), and user().

Referenced by exportHTML(), printPost(), and printThread().

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  }
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
$_GET["client_id"]
$tpl
Definition: ilias.php:10
isOwner($a_user_id=0)
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
static getInstance($a_obj_id=0)
setMessage($a_message)
static switchColor($a_num, $a_css1, $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows) ...
setChangeDate($a_changedate)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilForumExportGUI::$access

Definition at line 29 of file class.ilForumExportGUI.php.

◆ $ctrl

ilForumExportGUI::$ctrl

Definition at line 27 of file class.ilForumExportGUI.php.

◆ $error

ilForumExportGUI::$error

Definition at line 30 of file class.ilForumExportGUI.php.

◆ $frm

ilForumExportGUI::$frm
protected

Definition at line 25 of file class.ilForumExportGUI.php.

◆ $ilObjDataCache

ilForumExportGUI::$ilObjDataCache

Definition at line 32 of file class.ilForumExportGUI.php.

◆ $is_moderator

ilForumExportGUI::$is_moderator = false
protected

Definition at line 20 of file class.ilForumExportGUI.php.

Referenced by exportHTML(), and renderPostHtml().

◆ $lng

ilForumExportGUI::$lng

Definition at line 28 of file class.ilForumExportGUI.php.

◆ $user

ilForumExportGUI::$user

Definition at line 31 of file class.ilForumExportGUI.php.

◆ MODE_EXPORT_CLIENT

const ilForumExportGUI::MODE_EXPORT_CLIENT = 2

Definition at line 15 of file class.ilForumExportGUI.php.

◆ MODE_EXPORT_WEB

const ilForumExportGUI::MODE_EXPORT_WEB = 1

Definition at line 14 of file class.ilForumExportGUI.php.


The documentation for this class was generated from the following file: