ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilForumExportGUI Class Reference

Forum export to HTML and Print. More...

+ Collaboration diagram for ilForumExportGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 printThread ()
 
 printPost ()
 

Data Fields

ilCtrlInterface $ctrl
 
ilLanguage $lng
 
ilAccessHandler $access
 
ilErrorHandling $error
 
ilObjUser $user
 
ilObjectDataCache $ilObjDataCache
 

Protected Member Functions

 renderPostHtml (ilGlobalTemplateInterface $tpl, ilForumPost $post, int $counter, int $mode)
 

Protected Attributes

bool $is_moderator = false
 
ilForum $frm
 

Private Member Functions

 retrieveRefId ()
 
 ensureThreadBelongsToForum (int $objId, ilForumTopic $thread)
 
 addLatexResources (ilGlobalTemplateInterface $tpl)
 Register the resources needed for latex rendering We can't query these resources from the UI framework in a clean way. More...
 

Private Attributes

const int MODE_EXPORT_WEB = 1
 
const int MODE_EXPORT_CLIENT = 2
 
readonly ilForumProperties $objProperties
 
readonly GlobalHttpState $http
 
readonly Refinery $refinery
 
readonly int $ref_id
 

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 \

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

Constructor & Destructor Documentation

◆ __construct()

ilForumExportGUI::__construct ( )

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

48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 $this->ctrl = $DIC->ctrl();
53 $this->access = $DIC->access();
54 $this->error = $DIC['ilErr'];
55 $this->user = $DIC->user();
56 $this->ilObjDataCache = $DIC['ilObjDataCache'];
57 $this->http = $DIC->http();
58 $this->refinery = $DIC->refinery();
59
60 $this->ref_id = $this->retrieveRefId();
61
62 $forum = new ilObjForum($this->ref_id);
63 $this->frm = $forum->Forum;
64 $this->objProperties = ilForumProperties::getInstance($forum->getId());
65
66 $this->frm->setForumId($forum->getId());
67 $this->frm->setForumRefId($forum->getRefId());
68
69 $this->lng->loadLanguageModule('forum');
70
71 $this->is_moderator = $this->access->checkAccess('moderate_frm', '', $this->ref_id);
72 }
error(string $a_errmsg)
static getInstance(int $a_obj_id=0)
Class ilObjForum.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), error(), ilForumProperties\getInstance(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), retrieveRefId(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ addLatexResources()

ilForumExportGUI::addLatexResources ( ilGlobalTemplateInterface  $tpl)
private

Register the resources needed for latex rendering We can't query these resources from the UI framework in a clean way.

So we have to repeat them here.

See also
\ILIAS\UI\Implementation\Component\Legacy\Renderer::registerResources

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

102 : void
103 {
104 $tpl->addJavaScript('assets/js/mathjax_config.js');
105 $tpl->addJavaScript('node_modules/mathjax/es5/tex-chtml-full.js');
106 }
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.

References ILIAS\UICore\GlobalTemplate\addJavaScript().

Referenced by printPost(), and printThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ensureThreadBelongsToForum()

ilForumExportGUI::ensureThreadBelongsToForum ( int  $objId,
ilForumTopic  $thread 
)
private

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

87 : void
88 {
90 if ($thread->getForumId() !== $forumId) {
91 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
92 }
93 }
static lookupForumIdByObjId(int $obj_id)
$objId
Definition: xapitoken.php:57

References $objId, error(), ilForumTopic\getForumId(), ILIAS\Repository\lng(), and ilObjForum\lookupForumIdByObjId().

Referenced by printPost(), and printThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilForumExportGUI::executeCommand ( )

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

108 : void
109 {
110 $cmd = $this->ctrl->getCmd();
111 $this->$cmd();
112 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ printPost()

ilForumExportGUI::printPost ( )

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

312 : void
313 {
314 if (!$this->access->checkAccess('read,visible', '', $this->ref_id)) {
315 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
316 }
317
319
320 $tpl = new ilGlobalTemplate('tpl.forums_export_print.html', true, true, 'components/ILIAS/Forum');
321 $location_stylesheet = ilUtil::getStyleSheetLocation();
322 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
323
325 $this->addLatexResources($tpl);
326
327 $this->frm->setMDB2WhereCondition('top_pk = %s ', ['integer'], [$this->http->wrapper()->query()->retrieve(
328 'top_pk',
329 $this->refinery->kindlyTo()->int()
330 )]);
331 $frmData = $this->frm->getOneTopic();
332
333 if ($frmData->getTopPk() > 0) {
334 $post = new ilForumPost($this->http->wrapper()->query()->retrieve(
335 'print_post',
336 $this->refinery->kindlyTo()->int()
337 ), $this->is_moderator);
338 $this->ensureThreadBelongsToForum($this->frm->getForumId(), $post->getThread());
339
340 $tpl->setVariable('TITLE', $post->getThread()->getSubject());
341 $tpl->setVariable(
342 'HEADLINE',
343 $this->lng->txt('forum') . ': ' . $frmData->getTopName() . ' > ' .
344 $this->lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject()
345 );
346
347 $this->renderPostHtml($tpl, $post, 0, self::MODE_EXPORT_WEB);
348 }
349 $tpl->printToStdout();
350 }
static setUseRelativeDates(bool $a_status)
set use relative dates
addLatexResources(ilGlobalTemplateInterface $tpl)
Register the resources needed for latex rendering We can't query these resources from the UI framewor...
renderPostHtml(ilGlobalTemplateInterface $tpl, ilForumPost $post, int $counter, int $mode)
ensureThreadBelongsToForum(int $objId, ilForumTopic $thread)
special template class to simplify handling of ITX/PEAR
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$post
Definition: ltitoken.php:46

References $post, ILIAS\Repository\access(), addLatexResources(), ensureThreadBelongsToForum(), error(), ilUtil\getStyleSheetLocation(), ILIAS\FileDelivery\http(), iljQueryUtil\initjQuery(), ILIAS\Repository\lng(), renderPostHtml(), and ilDatePresentation\setUseRelativeDates().

+ Here is the call graph for this function:

◆ printThread()

ilForumExportGUI::printThread ( )

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

257 : void
258 {
259 if (
260 !$this->access->checkAccess('read,visible', '', $this->ref_id) ||
261 !$this->http->wrapper()->query()->has('thr_top_fk') ||
262 !$this->http->wrapper()->query()->has('print_thread')
263 ) {
264 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
265 }
266
268
269 $tpl = new ilGlobalTemplate('tpl.forums_export_print.html', true, true, 'components/ILIAS/Forum');
270 $location_stylesheet = ilUtil::getStyleSheetLocation();
271 $tpl->setVariable('LOCATION_STYLESHEET', $location_stylesheet);
272
274 $this->addLatexResources($tpl);
275
276 $this->frm->setMDB2WhereCondition('top_pk = %s ', ['integer'], [$this->http->wrapper()->query()->retrieve(
277 'thr_top_fk',
278 $this->refinery->kindlyTo()->int()
279 )]);
280 $frmData = $this->frm->getOneTopic();
281
282 if ($frmData->getTopPk() > 0) {
283 $topic = new ilForumTopic($this->http->wrapper()->query()->retrieve(
284 'print_thread',
285 $this->refinery->kindlyTo()->int()
286 ), $this->is_moderator);
287
288 $this->ensureThreadBelongsToForum($this->frm->getForumId(), $topic);
289
290 $topic->setOrderField('frm_posts_tree.rgt');
291 $first_post = $topic->getPostRootNode();
292 $post_collection = $topic->getPostTree($first_post);
293 $num_posts = count($post_collection);
294
295 $tpl->setVariable('TITLE', $topic->getSubject());
296 $tpl->setVariable(
297 'HEADLINE',
298 $this->lng->txt('forum') . ': ' . $frmData->getTopName() . ' > ' .
299 $this->lng->txt('forums_thread') . ': ' . $topic->getSubject() . ' > ' .
300 $this->lng->txt('forums_count_art') . ': ' . $num_posts
301 );
302
303 $i = 0;
304 foreach ($post_collection as $post) {
305 $this->renderPostHtml($tpl, $post, $i++, self::MODE_EXPORT_WEB);
306 }
307 }
308
309 $tpl->printToStdout();
310 }

References $post, ILIAS\Repository\access(), addLatexResources(), ensureThreadBelongsToForum(), error(), ilUtil\getStyleSheetLocation(), ILIAS\FileDelivery\http(), iljQueryUtil\initjQuery(), ILIAS\Repository\lng(), renderPostHtml(), and ilDatePresentation\setUseRelativeDates().

+ Here is the call graph for this function:

◆ renderPostHtml()

ilForumExportGUI::renderPostHtml ( ilGlobalTemplateInterface  $tpl,
ilForumPost  $post,
int  $counter,
int  $mode 
)
protected

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

114 : void
115 {
116 $tpl->setCurrentBlock('posts_row');
117
118 if (ilForumProperties::getInstance($this->ilObjDataCache->lookupObjId($this->ref_id))->getMarkModeratorPosts()) {
119 if ($post->isAuthorModerator() === null && $is_moderator = ilForum::_isModerator(
120 $this->ref_id,
121 $post->getPosAuthorId()
122 )) {
123 $rowCol = 'ilModeratorPosting';
124 } elseif ($post->isAuthorModerator()) {
125 $rowCol = 'ilModeratorPosting';
126 } else {
127 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
128 }
129 } else {
130 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
131 }
132
133 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
134
135 if ($post->isCensored()) {
136 $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
137 $rowCol = 'tblrowmarked';
138 }
139
140 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
141 if (!$post->isActivated() && $post->isOwner($this->user->getId())) {
142 $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
143 }
144
145 $authorinfo = new ilForumAuthorInformation(
146 $post->getPosAuthorId(),
147 $post->getDisplayUserId(),
148 (string) $post->getUserAlias(),
149 (string) $post->getImportName()
150 );
151
152 if ($authorinfo->hasSuffix()) {
153 if (!$authorinfo->isDeleted()) {
154 $tpl->setVariable('USR_NAME', $authorinfo->getAlias());
155 }
156 $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
157 } else {
158 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
159 $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
160 }
161 $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
162 }
163
164 if (self::MODE_EXPORT_CLIENT === $mode) {
165 if ($authorinfo->getAuthor()->getPref('public_profile') !== 'n') {
166 $tpl->setVariable('TXT_REGISTERED', $this->lng->txt('registered_since'));
167 $tpl->setVariable(
168 'REGISTERED_SINCE',
169 $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate())
170 );
171 }
172
173 if ($post->getDisplayUserId() !== 0) {
174 if ($this->is_moderator) {
175 $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
176 } else {
177 $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
178 }
179 $tpl->setVariable('TXT_NUM_POSTS', $this->lng->txt('forums_posts'));
180 $tpl->setVariable('NUM_POSTS', $num_posts);
181 }
182 }
183
184 $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
185 if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator(
186 $this->ref_id,
187 $post->getPosAuthorId()
188 )) {
189 if ($authorinfo->getAuthor()->getGender() === 'f') {
190 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
191 } elseif ($authorinfo->getAuthor()->getGender() === 'm') {
192 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
193 } else {
194 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_n'));
195 }
196 }
197
198 if ($post->getUpdateUserId() > 0) {
199 $spanClass = '';
200 if (ilForum::_isModerator($this->ref_id, $post->getUpdateUserId())) {
201 $spanClass = 'moderator_small';
202 }
203
204 $post->setChangeDate($post->getChangeDate());
205
206 $authorinfo = new ilForumAuthorInformation(
207 $post->getPosAuthorId(),
208 $post->getDisplayUserId(),
209 (string) $post->getUserAlias(),
210 ''
211 );
212
213 $tpl->setVariable(
214 'POST_UPDATE_TXT',
215 $this->lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($this->lng->txt('by'))
216 );
217 $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
218 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
219 $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
220 }
221 }
222
223 $post->setMessage($this->frm->prepareText($post->getMessage()));
224 $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
225 $tpl->setVariable('SUBJECT', $post->getSubject());
226
227 if (!$post->isCensored()) {
228 $spanClass = "";
229 if (ilForum::_isModerator($this->ref_id, $post->getDisplayUserId())) {
230 $spanClass = 'moderator';
231 }
232
233 // possible bugfix for mantis #8223
234 if ($post->getMessage() === strip_tags($post->getMessage())) {
235 // We can be sure, that there are not html tags
236 $post->setMessage(nl2br($post->getMessage()));
237 }
238
239 if ($spanClass !== '') {
240 $tpl->setVariable(
241 'POST',
242 "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc(
243 $post->getMessage(),
244 1
245 ) . "</span>"
246 );
247 } else {
248 $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
249 }
250 } else {
251 $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br((string) $post->getCensorshipComment()) . "</span>");
252 }
253
254 $tpl->parseCurrentBlock('posts_row');
255 }
static _isModerator(int $a_ref_id, int $a_usr_id)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static switchColor(int $a_num, string $a_css1, string $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
$counter

References $counter, $is_moderator, $post, ilForum\_isModerator(), ilRTE\_replaceMediaObjectImageSrc(), ilForumProperties\getInstance(), ilForumPost\getUpdateUserId(), ILIAS\Repository\lng(), ILIAS\UICore\GlobalTemplate\parseCurrentBlock(), ILIAS\UICore\GlobalTemplate\setCurrentBlock(), ILIAS\UICore\GlobalTemplate\setVariable(), and ilUtil\switchColor().

Referenced by printPost(), and printThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveRefId()

ilForumExportGUI::retrieveRefId ( )
private

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

74 : int
75 {
76 $ref_id = 0;
77 if ($this->http->wrapper()->query()->has('ref_id')) {
78 $ref_id = $this->http->wrapper()->query()->retrieve(
79 'ref_id',
80 $this->refinery->kindlyTo()->int()
81 );
82 }
83
84 return $ref_id;
85 }

References $ref_id, ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilForumExportGUI::$access

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

◆ $ctrl

ilCtrlInterface ilForumExportGUI::$ctrl

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

◆ $error

ilErrorHandling ilForumExportGUI::$error

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

◆ $frm

ilForum ilForumExportGUI::$frm
protected

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

◆ $http

readonly GlobalHttpState ilForumExportGUI::$http
private

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

◆ $ilObjDataCache

ilObjectDataCache ilForumExportGUI::$ilObjDataCache

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

◆ $is_moderator

bool ilForumExportGUI::$is_moderator = false
protected

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

Referenced by renderPostHtml().

◆ $lng

ilLanguage ilForumExportGUI::$lng

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

◆ $objProperties

readonly ilForumProperties ilForumExportGUI::$objProperties
private

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

◆ $ref_id

readonly int ilForumExportGUI::$ref_id
private

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

Referenced by retrieveRefId().

◆ $refinery

readonly Refinery ilForumExportGUI::$refinery
private

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

◆ $user

ilObjUser ilForumExportGUI::$user

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

◆ MODE_EXPORT_CLIENT

const int ilForumExportGUI::MODE_EXPORT_CLIENT = 2
private

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

◆ MODE_EXPORT_WEB

const int ilForumExportGUI::MODE_EXPORT_WEB = 1
private

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


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