ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjForumGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6
18{
20 private $viewModeOptions = [
21 ilForumProperties::VIEW_TREE => 'sort_by_posts',
22 ilForumProperties::VIEW_DATE_ASC => 'sort_by_date',
23 ];
24
27 ilForumProperties::VIEW_DATE_ASC => 'ascending_order',
28 ilForumProperties::VIEW_DATE_DESC => 'descending_order',
29 ];
30
33
36
38 public $modal_history = '';
39
42
45
48
51
53 private $is_moderator = false;
54
57
60
62 private $hideToolbar = false;
63
65 public $object;
66
68 private $httpRequest;
69
71 private $uiFactory;
72
74 private $uiRenderer;
75
77 private $forumObjects = null;
78
81
84
88 private $requestAction = '';
89
90 public $access;
92 public $tabs;
93 public $error;
94 public $user;
95 public $settings;
96 public $toolbar;
98 public $rbac;
99 public $locator;
100 public $ilHelp;
101
102 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
103 {
104 global $DIC;
105
106 $this->ctrl = $DIC->ctrl();
107 $this->ctrl->saveParameter($this, ['ref_id', 'cmdClass']);
108
109 $this->tpl = $DIC->ui()->mainTemplate();
110 $this->lng = $DIC->language();
111 $this->httpRequest = $DIC->http()->request();
112 $this->uiFactory = $DIC->ui()->factory();
113 $this->uiRenderer = $DIC->ui()->renderer();
114 $this->globalScreen = $DIC->globalScreen();
115
116 $this->access = $DIC->access();
117 $this->ilObjDataCache = $DIC['ilObjDataCache'];
118 $this->tabs = $DIC->tabs();
119 $this->error = $DIC['ilErr'];
120 $this->ilNavigationHistory = $DIC['ilNavigationHistory'];
121 $this->user = $DIC->user();
122 $this->settings = $DIC->settings();
123 $this->toolbar = $DIC->toolbar();
124 $this->repositoryTree = $DIC->repositoryTree();
125 $this->ilHelp = $DIC['ilHelp'];
126 $this->rbac = $DIC->rbac();
127 $this->locator = $DIC['ilLocator'];
128
129 $this->tpl->addJavaScript('./Services/JavaScript/js/Basic.js');
130
131 $this->type = 'frm';
132 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
133
134 $this->lng->loadLanguageModule('forum');
135
136 $this->initSessionStorage();
137
138 $this->objProperties = \ilForumProperties::getInstance($this->ilObjDataCache->lookupObjId($_GET['ref_id']));
139 $this->is_moderator = $this->access->checkAccess('moderate_frm', '', $_GET['ref_id']);
140
141 $this->objCurrentTopic = new ilForumTopic((int) $this->httpRequest->getQueryParams()['thr_pk'] ?? 0, $this->is_moderator);
142 $this->objCurrentPost = new ilForumPost((int) $this->httpRequest->getQueryParams()['pos_pk'] ?? 0, $this->is_moderator);
143
144 $this->requestAction = (string) ($this->httpRequest->getQueryParams()['action'] ?? '');
145 }
146
147 protected function initSessionStorage()
148 {
149 $forumValues = \ilSession::get('frm');
150 if (!is_array($forumValues)) {
151 $forumValues = [];
152 \ilSession::set('frm', $forumValues);
153 }
154
155 $threadId = $this->httpRequest->getQueryParams()['thr_pk'] ?? 0;
156 if ((int) $threadId > 0 && !is_array($forumValues[(int) $threadId])) {
157 $forumValues[(int) $threadId] = [];
158 \ilSession::set('frm', $forumValues);
159 }
160 }
161
165 protected function toggleExplorerNodeStateObject() : void
166 {
167 $exp = new ilForumExplorerGUI(
168 'frm_exp_' . $this->objCurrentTopic->getId(),
169 $this,
170 'viewThread',
171 $this->objCurrentTopic,
172 $this->objCurrentTopic->getFirstPostNode($this->is_moderator)
173 );
174 $exp->toggleExplorerNodeState();
175 }
176
177
185 array $subtree_nodes,
186 array $pagedPostings,
187 int $pageSize,
188 ilForumPost $firstForumPost
189 ) {
190 if ($firstForumPost->getId() == $this->objCurrentPost->getId()) {
191 return;
192 }
193
194 if (count($subtree_nodes) > 0 && $this->objCurrentPost->getId() > 0) {
195 $isCurrentPostingInPage = array_filter($pagedPostings, function (ilForumPost $posting) {
196 return $posting->getId() == $this->objCurrentPost->getId();
197 });
198
199 if (0 === count($isCurrentPostingInPage)) {
200 $pageOfCurrentPosting = 0;
201 $i = 0;
202 foreach ($subtree_nodes as $node) {
203 if ($i > 0 && 0 === $i % $pageSize) {
204 ++$pageOfCurrentPosting;
205 }
206
207 if ($node->getId() == $this->objCurrentPost->getId()) {
208 break;
209 }
210
211 ++$i;
212 }
213
214 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
215 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
216 $this->ctrl->setParameter($this, 'page', $pageOfCurrentPosting);
217 $this->ctrl->setParameter(
218 $this,
219 'orderby',
220 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
221 );
222 $this->ctrl->redirect($this, 'viewThread', $this->objCurrentPost->getId());
223 }
224 }
225 }
226
231 public function ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
232 {
234 if ((int) $thread->getForumId() !== (int) $forumId) {
235 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
236 }
237 }
238
243 {
246
247 $this->tpl->addJavascript('./Modules/Forum/js/autosave.js');
248 $autosave_cmd = 'autosaveDraftAsync';
249 if ($this->objCurrentPost->getId() == 0 && $this->objCurrentPost->getThreadId() == 0) {
250 $autosave_cmd = 'autosaveThreadDraftAsync';
251 }
252 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
253 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
254 $draft_id = (int) $_GET['draft_id'] > 0 ? (int) $_GET['draft_id'] : 0;
255 $this->ctrl->setParameter($this, 'draft_id', $draft_id);
256 $this->ctrl->setParameter($this, 'action', \ilUtil::stripSlashes($this->requestAction));
257 $this->tpl->addOnLoadCode(
258 "il.Language.setLangVar('saving', " . json_encode($this->lng->txt('saving')) . ");"
259 );
260
261 $this->tpl->addOnLoadCode('il.ForumDraftsAutosave.init(' . json_encode(array(
262 'loading_img_src' => \ilUtil::getImagePath('loader.svg'),
263 'draft_id' => $draft_id,
264 'interval' => $interval * 1000,
265 'url' => $this->ctrl->getFormAction($this, $autosave_cmd, '', true, false),
266 'selectors' => array(
267 'form' => '#form_' . $form->getId()
268 )
269 )) . ');');
270 }
271 }
272
276 private function isHierarchicalView() : bool
277 {
278 return (
279 $_SESSION['viewmode'] == 'answers' ||
281 ) || !(
282 $_SESSION['viewmode'] == 'date' ||
285 );
286 }
287
291 private function isTopLevelReplyCommand() : bool
292 {
293 return in_array(
294 strtolower($this->ctrl->getCmd()),
295 array_map('strtolower', array('createTopLevelPost', 'saveTopLevelPost', 'saveTopLevelDraft'))
296 );
297 }
298
299 public function executeCommand()
300 {
301 $next_class = $this->ctrl->getNextClass($this);
302 $cmd = $this->ctrl->getCmd();
303
304 $exclude_cmds = array(
305 'viewThread',
306 'markPostUnread',
307 'markPostRead',
308 'showThreadNotification',
309 'performPostActivation',
310 'askForPostActivation',
311 'askForPostDeactivation',
312 'toggleThreadNotification',
313 'toggleThreadNotificationTab',
314 'toggleStickiness',
315 'cancelPost',
316 'savePost',
317 'saveTopLevelPost',
318 'createTopLevelPost',
319 'saveTopLevelDraft',
320 'quotePost',
321 'getQuotationHTMLAsynch',
322 'autosaveDraftAsync',
323 'autosaveThreadDraftAsync',
324 'saveAsDraft',
325 'editDraft',
326 'updateDraft',
327 'deliverDraftZipFile',
328 'deliverZipFile',
329 'cancelDraft',
330 'deleteThreadDrafts',
331 'deletePosting',
332 'deletePostingDraft',
333 'revokeCensorship',
334 'addCensorship',
335 );
336
337 if (!in_array($cmd, $exclude_cmds)) {
338 $this->prepareOutput();
339 }
340
341 if (!$this->getCreationMode() && !$this->ctrl->isAsynch() && $this->access->checkAccess(
342 'read',
343 '',
344 $_GET['ref_id']
345 )) {
347 (int) $_GET['ref_id'],
348 \ilLink::_getLink((int) $_GET['ref_id'], 'frm'),
349 'frm'
350 );
351 }
352
353 switch ($next_class) {
354 case 'ilforumsettingsgui':
356 $this->ctrl->forwardCommand($forum_settings_gui);
357 break;
358
359 case 'ilrepositoryobjectsearchgui':
360 $this->addHeaderAction();
361 $this->setSideBlocks();
362 $this->tabs->activateTab("forums_threads");
363 $this->ctrl->setReturn($this, 'view');
364 $search_gui = new ilRepositoryObjectSearchGUI(
365 $this->object->getRefId(),
366 $this,
367 'view'
368 );
369 $this->ctrl->forwardCommand($search_gui);
370 break;
371
372 case 'ilpermissiongui':
373 $perm_gui = new ilPermissionGUI($this);
374 $this->ctrl->forwardCommand($perm_gui);
375 break;
376
377 case 'ilforumexportgui':
378 $fex_gui = new ilForumExportGUI();
379 $this->ctrl->forwardCommand($fex_gui);
380 exit();
381 break;
382
383 case 'ilforummoderatorsgui':
384 $fm_gui = new ilForumModeratorsGUI();
385 $this->ctrl->forwardCommand($fm_gui);
386 break;
387
388 case 'ilinfoscreengui':
389 $this->infoScreen();
390 break;
391
392 case 'ilcolumngui':
393 $this->showThreadsObject();
394 break;
395
396 case 'ilpublicuserprofilegui':
397 $profile_gui = new ilPublicUserProfileGUI((int) $_GET['user']);
398 $add = $this->getUserProfileAdditional((int) $_GET['ref_id'], (int) $_GET['user']);
399 $profile_gui->setAdditional($add);
400 $ret = $this->ctrl->forwardCommand($profile_gui);
401 $this->tpl->setContent($ret);
402 break;
403
404 case 'ilobjectcopygui':
405 $cp = new ilObjectCopyGUI($this);
406 $cp->setType('frm');
407 $this->ctrl->forwardCommand($cp);
408 break;
409
410 case 'ilexportgui':
411 $this->tabs->activateTab('export');
412 $exp = new ilExportGUI($this);
413 $exp->addFormat('xml');
414 $this->ctrl->forwardCommand($exp);
415 break;
416
417 case "ilratinggui":
418 if (!$this->objProperties->isIsThreadRatingEnabled() || $this->user->isAnonymous()) {
419 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
420 }
421
422 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
423 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
424 }
425
426 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentTopic);
427
428 $rating_gui = new ilRatingGUI();
429 $rating_gui->setObject(
430 $this->object->getId(),
431 $this->object->getType(),
432 $this->objCurrentTopic->getId(),
433 'thread'
434 );
435
436 $this->ctrl->setParameter($this, 'thr_pk', (int) $this->objCurrentTopic->getId());
437 $this->ctrl->forwardCommand($rating_gui);
438
440 $this->object->getId(),
441 $this->object->getType(),
442 (int) $this->objCurrentTopic->getId(),
443 'thread'
444 );
445 $this->objCurrentTopic->setAverageRating($avg['avg']);
446 $this->objCurrentTopic->update();
447
448 $this->ctrl->redirect($this, "showThreads");
449 break;
450
451 case 'ilcommonactiondispatchergui':
453 $this->ctrl->forwardCommand($gui);
454 break;
455
456 case "ilcontainernewssettingsgui":
458 $forum_settings_gui->settingsTabs();
459
460 $this->lng->loadLanguageModule('cont');
461 $news_set_gui = new ilContainerNewsSettingsGUI($this);
462 $news_set_gui->setNewsBlockForced(true);
463 $news_set_gui->setPublicNotification(true);
464 $this->ctrl->forwardCommand($news_set_gui);
465 break;
466
467 default:
468 // alex, 11 Jan 2011:
469 // I inserted this workaround due to bug report 6971.
470 // In general the command handling is quite obscure here.
471 // The form action of the table should be filled
472 // with $ilCtrl->getFormAction(..) not with $ilCtrl->getLinkTarget(..)
473 // Commands should be determined with $ilCtrl->getCmd() not
474 // with accessing $_POST['selected_cmd'], since this is internal
475 // of ilTable2GUI/ilCtrl and may change.
476 if (isset($_POST['select_cmd2'])) {
477 $_POST['selected_cmd'] = $_POST["selected_cmd2"];
478 }
479
480 if (isset($_POST['selected_cmd']) && $_POST['selected_cmd'] != null) {
481 $member_cmd = array(
482 'enableAdminForceNoti',
483 'disableAdminForceNoti',
484 'enableHideUserToggleNoti',
485 'disableHideUserToggleNoti'
486 );
487 in_array(
488 $_POST['selected_cmd'],
489 $member_cmd
490 ) ? $cmd = $_POST['selected_cmd'] : $cmd = 'performThreadsAction';
491 } elseif (!$cmd && !$_POST['selected_cmd']) {
492 $cmd = 'showThreads';
493 }
494
495 $cmd .= 'Object';
496 $this->$cmd();
497
498 break;
499 }
500
501 // suppress for topic level
502 if ($cmd != 'viewThreadObject' && $cmd != 'showUserObject') {
503 $this->addHeaderAction();
504 }
505 }
506
510 public function infoScreenObject()
511 {
512 $this->ctrl->setCmd('showSummary');
513 $this->ctrl->setCmdClass('ilinfoscreengui');
514 $this->infoScreen();
515 }
516
520 protected function initEditCustomForm(ilPropertyFormGUI $a_form)
521 {
522 $this->forum_settings_gui = new ilForumSettingsGUI($this);
523 $this->forum_settings_gui->getCustomForm($a_form);
524 }
525
529 protected function getEditFormCustomValues(array &$a_values)
530 {
531 $this->forum_settings_gui->getCustomValues($a_values);
532 }
533
537 protected function updateCustom(ilPropertyFormGUI $a_form)
538 {
539 $this->forum_settings_gui->updateCustomValues($a_form);
540 }
541
546 private function getThreadEditingForm($a_thread_id)
547 {
548 $form = new ilPropertyFormGUI();
549 $this->ctrl->setParameter($this, 'thr_pk', $a_thread_id);
550 $form->setFormAction($this->ctrl->getFormAction($this, 'updateThread'));
551
552 $ti_prop = new ilTextInputGUI($this->lng->txt('title'), 'title');
553 $ti_prop->setRequired(true);
554 $ti_prop->setMaxLength(255);
555 $ti_prop->setSize(50);
556 $form->addItem($ti_prop);
557
558 $form->addCommandButton('updateThread', $this->lng->txt('save'));
559 $form->addCommandButton('showThreads', $this->lng->txt('cancel'));
560
561 return $form;
562 }
563
568 public function editThreadObject($threadId, ilPropertyFormGUI $form = null)
569 {
570 if (!$this->is_moderator) {
571 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
572 }
573
574 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
575 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
576 }
577
578 $thread = new \ilForumTopic($threadId);
579 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $thread);
580
581 $this->tabs->activateTab('forums_threads');
582
583 if (!($form instanceof \ilPropertyFormGUI)) {
584 $form = $this->getThreadEditingForm($threadId);
585 $form->setValuesByArray(array(
586 'title' => $thread->getSubject()
587 ));
588 }
589
590 $this->tpl->setContent($form->getHTML());
591 }
592
596 public function updateThreadObject()
597 {
598 if (!$this->is_moderator) {
599 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
600 }
601
602 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
603 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
604 }
605
606 if (!$this->objCurrentTopic->getId()) {
607 $this->showThreadsObject();
608 return;
609 }
610
611 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentTopic);
612
613 $form = $this->getThreadEditingForm($this->objCurrentTopic->getId());
614 if (!$form->checkInput()) {
615 $form->setValuesByPost();
616 $this->editThreadObject($this->objCurrentTopic->getId(), $form);
617 return;
618 }
619
620 $this->objCurrentTopic->setSubject($form->getInput('title'));
621 $this->objCurrentTopic->updateThreadTitle();
622
623 ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
624 $this->showThreadsObject();
625 }
626
627 public function markAllReadObject()
628 {
629 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
630 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
631 }
632
633 $this->object->markAllThreadsRead($this->user->getId());
634 ilUtil::sendInfo($this->lng->txt('forums_all_threads_marked_read'));
635 $this->showThreadsObject();
636 }
637
638 public function showThreadsObject()
639 {
640 $this->getSubTabs('showThreads');
641 $this->setSideBlocks();
642 $this->getCenterColumnHTML();
643 }
644
645 public function sortThreadsObject()
646 {
647 $this->getSubTabs('sortThreads');
648 $this->setSideBlocks();
649 $this->getCenterColumnHTML();
650 }
651
652 public function getSubTabs($subtab = 'showThreads')
653 {
654 if ($this->objProperties->getThreadSorting() == 1 && $this->is_moderator) {
655 $this->tabs->addSubTabTarget(
656 'show',
657 $this->ctrl->getLinkTarget($this, 'showThreads'),
658 'showThreads',
659 get_class($this),
660 '',
661 $subtab == 'showThreads' ? true : false
662 );
663 $this->tabs->addSubTabTarget(
664 'sorting_header',
665 $this->ctrl->getLinkTarget($this, 'sortThreads'),
666 'sortThreads',
667 get_class($this),
668 '',
669 $subtab == 'sortThreads' ? true : false
670 );
671 }
672 }
673
674 public function getContent()
675 {
676 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
677 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
678 }
679
680 $cmd = $this->ctrl->getCmd();
681 $frm = $this->object->Forum;
682 $frm->setForumId($this->object->getId());
683 $frm->setForumRefId($this->object->getRefId());
684 $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
685
686 $threadsTemplate = new \ilTemplate(
687 'tpl.forums_threads_liste.html',
688 true,
689 true,
690 'Modules/Forum'
691 );
692
693 if ((int) strlen($this->confirmation_gui_html)) {
694 $threadsTemplate->setVariable('CONFIRMATION_GUI', $this->confirmation_gui_html);
695 }
696
697 // Create topic button
698 if ($this->access->checkAccess('add_thread', '', $this->object->getRefId()) && !$this->hideToolbar()) {
700 $btn->setUrl($this->ctrl->getLinkTarget($this, 'createThread'));
701 $btn->setCaption('forums_new_thread');
702 $this->toolbar->addStickyItem($btn);
703 }
704
705 // Mark all topics as read button
706 if (!$this->user->isAnonymous() && !(int) strlen($this->confirmation_gui_html)) {
707 $this->toolbar->addButton(
708 $this->lng->txt('forums_mark_read'),
709 $this->ctrl->getLinkTarget($this, 'markAllRead'),
710 '',
712 );
713 $this->ctrl->clearParameters($this);
714 }
715
718 $this->user->getId(),
719 ilObjForum::lookupForumIdByObjId($this->object->getId())
720 );
721 if (count($drafts) > 0) {
722 $draftsTable = new ilForumDraftsTableGUI(
723 $this,
724 $cmd,
725 $this->access->checkAccess('add_thread', '', $this->object->getRefId())
726 );
727 $draftsTable->setData($drafts);
728 $threadsTemplate->setVariable('THREADS_DRAFTS_TABLE', $draftsTable->getHTML());
729 }
730 }
731
732 // Import information: Topic (variable $topicData) means frm object, not thread
733 $topicData = $frm->getOneTopic();
734 if ($topicData) {
735 // Visit-Counter
736 $frm->setDbTable('frm_data');
737 $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
738 $frm->updateVisits($topicData['top_pk']);
739
740 if (!in_array($cmd, array('showThreads', 'sortThreads'))) {
741 $cmd = 'showThreads';
742 }
743
744 $tbl = new ilForumTopicTableGUI(
745 $this,
746 $cmd,
747 '',
748 (int) $_GET['ref_id'],
749 $topicData,
750 $this->is_moderator,
751 $this->settings->get('forum_overview')
752 );
753 $tbl->init();
754 $tbl->setMapper($frm)->fetchData();
755 $threadsTemplate->setVariable('THREADS_TABLE', $tbl->getHTML());
756 }
757
758 $this->tpl->setPermanentLink($this->object->getType(), $this->object->getRefId(), '', '_top');
759
760 $this->tpl->setContent($threadsTemplate->get());
761 }
762
770 protected function renderDraftContent(
772 string $action,
773 ilForumPost $referencePosting,
774 array $drafts
775 ) : void {
776 $frm = $this->object->Forum;
777
778 foreach ($drafts as $draft) {
779 $tmp_file_obj = new ilFileDataForumDrafts($this->object->getId(), $draft->getDraftId());
780 $filesOfDraft = $tmp_file_obj->getFilesOfPost();
781 ksort($filesOfDraft);
782
783 if (count($filesOfDraft)) {
784 if ($action !== 'showdraft') {
785 foreach ($filesOfDraft as $file) {
786 $tpl->setCurrentBlock('attachment_download_row');
787 $this->ctrl->setParameter($this, 'draft_id', $tmp_file_obj->getDraftId());
788 $this->ctrl->setParameter($this, 'file', $file['md5']);
789 $tpl->setVariable('HREF_DOWNLOAD', $this->ctrl->getLinkTarget($this, 'viewThread'));
790 $tpl->setVariable('TXT_FILENAME', $file['name']);
791 $this->ctrl->setParameter($this, 'file', '');
792 $this->ctrl->setParameter($this, 'draft_id', '');
793 $this->ctrl->clearParameters($this);
794 $tpl->parseCurrentBlock();
795 }
796
797 $tpl->setCurrentBlock('attachments');
798 $tpl->setVariable('TXT_ATTACHMENTS_DOWNLOAD', $this->lng->txt('forums_attachments'));
799 $tpl->setVariable(
800 'DOWNLOAD_IMG',
801 ilGlyphGUI::get(ilGlyphGUI::ATTACHMENT, $this->lng->txt('forums_download_attachment'))
802 );
803 if (count($filesOfDraft) > 1) {
804 $download_zip_button = ilLinkButton::getInstance();
805 $download_zip_button->setCaption($this->lng->txt('download'), false);
806 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
807 $download_zip_button->setUrl($this->ctrl->getLinkTarget($this, 'deliverDraftZipFile'));
808 $this->ctrl->setParameter($this, 'draft_id', '');
809 $tpl->setVariable('DOWNLOAD_ZIP', $download_zip_button->render());
810 }
811 $tpl->parseCurrentBlock();
812 }
813 }
814
815 $this->renderSplitButton(
816 $tpl,
817 $action,
818 false,
819 $referencePosting,
820 (int) $this->httpRequest->getQueryParams()['page'],
821 $draft
822 );
823
824 $rowCol = 'tblrowmarked';
825 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
826 $tpl->setVariable('DEPTH', (int) ($referencePosting->getDepth() - 1));
827
828 $this->ctrl->setParameter($this, 'pos_pk', $referencePosting->getId());
829 $this->ctrl->setParameter($this, 'thr_pk', $referencePosting->getThreadId());
830 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
831
832 $backurl = urlencode($this->ctrl->getLinkTarget($this, 'viewThread', $referencePosting->getId()));
833
834 $this->ctrl->setParameter($this, 'backurl', $backurl);
835 $this->ctrl->setParameter($this, 'thr_pk', $referencePosting->getThreadId());
836 $this->ctrl->setParameter($this, 'user', $draft->getPostDisplayUserId());
837
838 $authorinfo = new ilForumAuthorInformation(
839 $draft->getPostAuthorId(),
840 $draft->getPostDisplayUserId(),
841 $draft->getPostUserAlias(),
842 '',
843 array(
844 'href' => $this->ctrl->getLinkTarget($this, 'showUser')
845 )
846 );
847
848 $this->ctrl->clearParameters($this);
849
850 if ($authorinfo->hasSuffix()) {
851 $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
852 $tpl->setVariable('USR_NAME', $draft->getPostUserAlias());
853 } else {
854 $tpl->setVariable('AUTHOR', $authorinfo->getLinkedAuthorShortName());
855 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
856 $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
857 }
858 }
859 $tpl->setVariable('DRAFT_ANCHOR', 'draft_' . $draft->getDraftId());
860
861 $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
862 $tpl->setVariable('USR_ICON_ALT', ilUtil::prepareFormOutput($authorinfo->getAuthorShortName()));
863 if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator(
864 (int) $_GET['ref_id'],
865 $draft->getPostAuthorId()
866 )) {
867 if ($authorinfo->getAuthor()->getGender() == 'f') {
868 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_f'));
869 } elseif ($authorinfo->getAuthor()->getGender() == 'm') {
870 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_m'));
871 } elseif ($authorinfo->getAuthor()->getGender() == 'n') {
872 $tpl->setVariable('ROLE', $this->lng->txt('frm_moderator_n'));
873 }
874 }
875
876 if ($draft->getUpdateUserId() > 0) {
877 $draft->setPostUpdate($draft->getPostUpdate());
878
879 $this->ctrl->setParameter($this, 'backurl', $backurl);
880 $this->ctrl->setParameter($this, 'thr_pk', $referencePosting->getThreadId());
881 $this->ctrl->setParameter($this, 'user', $referencePosting->getUpdateUserId());
882 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
883
884 $authorinfo = new ilForumAuthorInformation(
885 $draft->getPostAuthorId(),
886 $draft->getUpdateUserId(),
887 $draft->getPostUserAlias(),
888 '',
889 array(
890 'href' => $this->ctrl->getLinkTarget($this, 'showUser')
891 )
892 );
893
894 $this->ctrl->clearParameters($this);
895
896 $tpl->setVariable(
897 'POST_UPDATE_TXT',
898 $this->lng->txt('edited_on') . ': ' . $frm->convertDate($draft->getPostUpdate()) . ' - ' . strtolower($this->lng->txt('by'))
899 );
900 $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
901 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized() && !$authorinfo->hasSuffix()) {
902 $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
903 }
904 }
905
906 $draft->setPostMessage($frm->prepareText($draft->getPostMessage()));
907
908 $tpl->setVariable('SUBJECT', $draft->getPostSubject());
909 $tpl->setVariable('POST_DATE', $frm->convertDate($draft->getPostDate()));
910
911 if (!$referencePosting->isCensored() || ($this->objCurrentPost->getId() == $referencePosting->getId() && $action === 'censor')) {
912 $spanClass = '';
913 if (ilForum::_isModerator($this->ref_id, $draft->getPostDisplayUserId())) {
914 $spanClass = 'moderator';
915 }
916
917 if ($draft->getPostMessage() == strip_tags($draft->getPostMessage())) {
918 // We can be sure, that there are not html tags
919 $draft->setPostMessage(nl2br($draft->getPostMessage()));
920 }
921
922 if ($spanClass != "") {
923 $tpl->setVariable(
924 'POST',
925 "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc(
926 $draft->getPostMessage(),
927 1
928 ) . "</span>"
929 );
930 } else {
931 $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($draft->getPostMessage(), 1));
932 }
933 }
934
935 if (!$this->objCurrentTopic->isClosed() && $action === 'deletedraft') {
936 if (!$this->user->isAnonymous() && (int) $draft->getDraftId() === (int) $_GET['draft_id']) {
937 // confirmation: delete
938 $tpl->setVariable('FORM', $this->getDeleteDraftFormHTML());
939 }
940 } elseif ($action === 'editdraft' && (int) $draft->getDraftId() === (int) $_GET['draft_id']) {
941 $oEditReplyForm = $this->getReplyEditForm();
942
943 if (!$this->objCurrentTopic->isClosed() && in_array($this->requestAction, ['showdraft', 'editdraft'])) {
944 $this->renderPostingForm($tpl, $frm, $referencePosting, $this->requestAction);
945 }
946
947 $tpl->setVariable('EDIT_DRAFT_ANCHOR', 'draft_edit_' . $draft->getDraftId());
948 $tpl->setVariable('DRAFT_FORM', $oEditReplyForm->getHTML() . $this->modal_history);
949 }
950
951 $tpl->parseCurrentBlock();
952 }
953 }
954
963 protected function renderPostContent(
965 ilForumPost $node,
966 string $action,
967 int $pageIndex,
968 int $postIndex
969 ) {
970 $forumObj = $this->object;
971 $frm = $this->object->Forum;
972
973 $fileDataOfForum = new ilFileDataForum($forumObj->getId(), $node->getId());
974
975 $filesOfPost = $fileDataOfForum->getFilesOfPost();
976 ksort($filesOfPost);
977 if (count($filesOfPost) > 0) {
978 if ($node->getId() != $this->objCurrentPost->getId() || $action !== 'showedit') {
979 foreach ($filesOfPost as $file) {
980 $tpl->setCurrentBlock('attachment_download_row');
981 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
982 $this->ctrl->setParameter($this, 'file', $file['md5']);
983 $tpl->setVariable('HREF_DOWNLOAD', $this->ctrl->getLinkTarget($this, 'viewThread'));
984 $tpl->setVariable('TXT_FILENAME', $file['name']);
985 $this->ctrl->clearParameters($this);
986 $tpl->parseCurrentBlock();
987 }
988
989 $tpl->setCurrentBlock('attachments');
990 $tpl->setVariable('TXT_ATTACHMENTS_DOWNLOAD', $this->lng->txt('forums_attachments'));
991 $tpl->setVariable(
992 'DOWNLOAD_IMG',
993 ilGlyphGUI::get(ilGlyphGUI::ATTACHMENT, $this->lng->txt('forums_download_attachment'))
994 );
995 if (count($filesOfPost) > 1) {
996 $download_zip_button = ilLinkButton::getInstance();
997 $download_zip_button->setCaption($this->lng->txt('download'), false);
998 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
999 $download_zip_button->setUrl($this->ctrl->getLinkTarget($this, 'deliverZipFile'));
1000
1001 $tpl->setVariable('DOWNLOAD_ZIP', $download_zip_button->render());
1002 }
1003
1004 $tpl->parseCurrentBlock();
1005 }
1006 }
1007 $this->renderSplitButton($tpl, $action, true, $node, $pageIndex);
1008
1009 $tpl->setVariable('POST_ANKER', $node->getId());
1010 $tpl->setVariable('TXT_PERMA_LINK', $this->lng->txt('perma_link'));
1011 $tpl->setVariable('PERMA_TARGET', '_top');
1012
1013 $rowCol = ilUtil::switchColor($postIndex, 'tblrow1', 'tblrow2');
1014 if (!$node->isActivated() && !$this->objCurrentTopic->isClosed() && $this->is_moderator) {
1015 $rowCol = 'ilPostingNeedsActivation';
1016 } elseif ($this->objProperties->getMarkModeratorPosts() == 1) {
1017 $isAuthorModerator = ilForum::_isModerator($this->object->getRefId(), $node->getPosAuthorId());
1018 if ($node->getIsAuthorModerator() === null && $isAuthorModerator) {
1019 $rowCol = 'ilModeratorPosting';
1020 } elseif ($node->getIsAuthorModerator()) {
1021 $rowCol = 'ilModeratorPosting';
1022 }
1023 }
1024
1025 if (
1026 (!in_array($action, ['delete', 'censor']) && !$this->displayConfirmPostActivation()) ||
1027 $this->objCurrentPost->getId() != $node->getId()
1028 ) {
1029 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
1030 } else {
1031 $rowCol = 'tblrowmarked';
1032 }
1033
1034 if ($node->isCensored()) {
1035 if ($action !== 'censor') {
1036 $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $this->lng->txt('post_censored_comment_by_moderator'));
1037 }
1038
1039 $rowCol = 'tblrowmarked';
1040 }
1041
1042 $tpl->setVariable('ROWCOL', ' ' . $rowCol);
1043 $tpl->setVariable('DEPTH', (int) ($node->getDepth() - 1));
1044 if (!$node->isActivated() && $node->isOwner($this->user->getId())) {
1045 $tpl->setVariable('POST_NOT_ACTIVATED_YET', $this->lng->txt('frm_post_not_activated_yet'));
1046 }
1047
1048 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
1049 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
1050 $backurl = urlencode($this->ctrl->getLinkTarget($this, 'viewThread', $node->getId()));
1051 $this->ctrl->clearParameters($this);
1052
1053 $this->ctrl->setParameter($this, 'backurl', $backurl);
1054 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
1055 $this->ctrl->setParameter($this, 'user', $node->getDisplayUserId());
1056 $authorinfo = new ilForumAuthorInformation(
1057 $node->getPosAuthorId(),
1058 $node->getDisplayUserId(),
1059 $node->getUserAlias(),
1060 $node->getImportName(),
1061 [
1062 'href' => $this->ctrl->getLinkTarget($this, 'showUser')
1063 ]
1064 );
1065 $this->ctrl->clearParameters($this);
1066
1067 if ($authorinfo->hasSuffix()) {
1068 if (!$authorinfo->isDeleted()) {
1069 $tpl->setVariable('USR_NAME', $authorinfo->getAlias());
1070 }
1071 $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
1072 } else {
1073 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized()) {
1074 $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
1075 }
1076 $tpl->setVariable('AUTHOR', $authorinfo->getLinkedAuthorShortName());
1077 }
1078
1079 $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
1080 $tpl->setVariable('USR_ICON_ALT', ilUtil::prepareFormOutput($authorinfo->getAuthorShortName()));
1081 $isModerator = ilForum::_isModerator((int) $authorinfo->getAuthor()->getId(), $node->getPosAuthorId());
1082 if ($authorinfo->getAuthor()->getId() && $isModerator) {
1083 $authorRole = $this->lng->txt('frm_moderator_n');
1084 if (is_string($authorinfo->getAuthor()->getGender()) && strlen($authorinfo->getAuthor()->getGender()) > 0) {
1085 $authorRole = $this->lng->txt('frm_moderator_' . $authorinfo->getAuthor()->getGender());
1086 }
1087 $tpl->setVariable('ROLE', $authorRole);
1088 }
1089
1090 if ($node->getUpdateUserId() > 0) {
1091 $node->setChangeDate($node->getChangeDate());
1092
1093 $this->ctrl->setParameter($this, 'backurl', $backurl);
1094 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
1095 $this->ctrl->setParameter($this, 'user', $node->getUpdateUserId());
1096 $update_user_id = $node->getUpdateUserId();
1097 if ($node->getPosAuthorId() == $node->getUpdateUserId() && $node->getDisplayUserId() == 0) {
1098 $update_user_id = $node->getDisplayUserId();
1099 }
1100 $authorinfo = new ilForumAuthorInformation(
1101 $node->getPosAuthorId(),
1102 $update_user_id,
1103 $node->getUserAlias(),
1104 $node->getImportName(),
1105 array(
1106 'href' => $this->ctrl->getLinkTarget($this, 'showUser')
1107 )
1108 );
1109 $this->ctrl->clearParameters($this);
1110
1111 $tpl->setVariable(
1112 'POST_UPDATE_TXT',
1113 $this->lng->txt('edited_on') . ': ' . $frm->convertDate($node->getChangeDate()) . ' - ' . strtolower($this->lng->txt('by'))
1114 );
1115 $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
1116 if ($authorinfo->getAuthorName(true) && !$this->objProperties->isAnonymized() && !$authorinfo->hasSuffix()) {
1117 $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
1118 }
1119 }
1120
1121 $node->setMessage($frm->prepareText($node->getMessage()));
1122
1123 if ($this->user->isAnonymous() || $node->isPostRead()) {
1124 $tpl->setVariable('SUBJECT', $node->getSubject());
1125 } else {
1126 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
1127 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
1128 $this->ctrl->setParameter($this, 'page', $pageIndex);
1129 $this->ctrl->setParameter(
1130 $this,
1131 'orderby',
1132 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
1133 );
1134 $this->ctrl->setParameter($this, 'viewmode', ilUtil::stripSlashes($_SESSION['viewmode']));
1135 $mark_post_target = $this->ctrl->getLinkTarget($this, 'markPostRead', $node->getId());
1136
1137 $tpl->setVariable(
1138 'SUBJECT',
1139 "<a href=\"" . $mark_post_target . "\"><b>" . $node->getSubject() . "</b></a>"
1140 );
1141 }
1142
1143 $tpl->setVariable('POST_DATE', $frm->convertDate($node->getCreateDate()));
1144
1145 if (!$node->isCensored() || ($this->objCurrentPost->getId() == $node->getId() && $action === 'censor')) {
1146 $spanClass = "";
1147 if (ilForum::_isModerator($this->ref_id, $node->getDisplayUserId())) {
1148 $spanClass = 'moderator';
1149 }
1150
1151 // possible bugfix for mantis #8223
1152 if ($node->getMessage() == strip_tags($node->getMessage())) {
1153 // We can be sure, that there are not html tags
1154 $node->setMessage(nl2br($node->getMessage()));
1155 }
1156
1157 if ($spanClass !== '') {
1158 $tpl->setVariable(
1159 'POST',
1160 "<span class=\"" . $spanClass . "\">" .
1162 "</span>"
1163 );
1164 } else {
1165 $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($node->getMessage(), 1));
1166 }
1167 } else {
1168 $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($node->getCensorshipComment()) . "</span>");
1169 }
1170
1171 $tpl->parseCurrentBlock();
1172 }
1173
1177 protected function afterSave(ilObject $a_new_object)
1178 {
1179 \ilUtil::sendSuccess($this->lng->txt('frm_added'), true);
1180 $this->ctrl->setParameter($this, 'ref_id', $a_new_object->getRefId());
1181 $this->ctrl->redirect($this, 'createThread');
1182 }
1183
1184 protected function getTabs()
1185 {
1186 $this->ilHelp->setScreenIdComponent("frm");
1187
1188 $this->ctrl->setParameter($this, 'ref_id', $this->ref_id);
1189
1190 $active = array(
1191 '',
1192 'showThreads',
1193 'view',
1194 'markAllRead',
1195 'enableForumNotification',
1196 'disableForumNotification',
1197 'moveThreads',
1198 'performMoveThreads',
1199 'cancelMoveThreads',
1200 'performThreadsAction',
1201 'createThread',
1202 'addThread',
1203 'showUser',
1204 'confirmDeleteThreads',
1205 'merge',
1206 'mergeThreads',
1207 'performMergeThreads'
1208 );
1209
1210 (in_array($this->ctrl->getCmd(), $active)) ? $force_active = true : $force_active = false;
1211
1212 if ($this->access->checkAccess(
1213 'read',
1214 '',
1215 $this->ref_id
1216 )) {
1217 $this->tabs->addTarget(
1218 'forums_threads',
1219 $this->ctrl->getLinkTarget($this, 'showThreads'),
1220 $this->ctrl->getCmd(),
1221 get_class($this),
1222 '',
1223 $force_active
1224 );
1225 }
1226
1227 // info tab
1228 if ($this->access->checkAccess('visible', '', $this->ref_id) || $this->access->checkAccess(
1229 'read',
1230 '',
1231 $this->ref_id
1232 )) {
1233 $force_active = ($this->ctrl->getNextClass() == 'ilinfoscreengui' || strtolower($_GET['cmdClass']) == 'ilnotegui') ? true : false;
1234 $this->tabs->addTarget(
1235 'info_short',
1236 $this->ctrl->getLinkTargetByClass(array('ilobjforumgui', 'ilinfoscreengui'), 'showSummary'),
1237 array('showSummary', 'infoScreen'),
1238 '',
1239 '',
1240 $force_active
1241 );
1242 }
1243
1244 if ($this->access->checkAccess('write', '', $this->ref_id)) {
1245 $force_active = ($this->ctrl->getCmd() == 'edit') ? true : false;
1246 $this->tabs->addTarget(
1247 'settings',
1248 $this->ctrl->getLinkTarget($this, 'edit'),
1249 'edit',
1250 get_class($this),
1251 '',
1252 $force_active
1253 );
1254 }
1255
1256 if ($this->access->checkAccess('write', '', $this->ref_id)) {
1257 $this->tabs->addTarget(
1258 'frm_moderators',
1259 $this->ctrl->getLinkTargetByClass('ilForumModeratorsGUI', 'showModerators'),
1260 'showModerators',
1261 get_class($this)
1262 );
1263 }
1264
1265 if ($this->settings->get('enable_fora_statistics', false)) {
1266 $hasStatisticsAccess = $this->access->checkAccess('write', '', $this->ref_id);
1267 if (!$hasStatisticsAccess) {
1268 $hasStatisticsAccess = (
1269 $this->objProperties->isStatisticEnabled() &&
1270 $this->access->checkAccess('read', '', $this->ref_id)
1271 );
1272 }
1273
1274 if ($hasStatisticsAccess) {
1275 $force_active = ($this->ctrl->getCmd() == 'showStatistics') ? true : false;
1276 $this->tabs->addTarget(
1277 'frm_statistics',
1278 $this->ctrl->getLinkTarget($this, 'showStatistics'),
1279 'showStatistics',
1280 get_class($this),
1281 '',
1282 $force_active
1283 );
1284 }
1285 }
1286
1287 if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
1288 $this->tabs->addTarget('export', $this->ctrl->getLinkTargetByClass('ilexportgui', ''), '', 'ilexportgui');
1289 }
1290
1291 if ($this->access->checkAccess('edit_permission', '', $this->ref_id)) {
1292 $this->tabs->addTarget(
1293 'perm_settings',
1294 $this->ctrl->getLinkTargetByClass(array(get_class($this), 'ilpermissiongui'), 'perm'),
1295 array('perm', 'info', 'owner'),
1296 'ilpermissiongui'
1297 );
1298 }
1299 }
1300
1301 public function showStatisticsObject()
1302 {
1304 if (!$this->settings->get('enable_fora_statistics', false)) {
1305 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1306 }
1307
1308 // if no read access -> intrusion detected
1309 if (!$this->access->checkAccess('read', '', (int) $_GET['ref_id'])) {
1310 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1311 }
1312
1313 // if read access and statistics disabled -> intrusion detected
1314 if (!$this->objProperties->isStatisticEnabled()) {
1315 // if write access and statistics disabled -> ok, for forum admin
1316 if ($this->access->checkAccess('write', '', (int) $_GET['ref_id'])) {
1317 ilUtil::sendInfo($this->lng->txt('frm_statistics_disabled_for_participants'));
1318 } else {
1319 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1320 }
1321 }
1322
1323 $this->object->Forum->setForumId($this->object->getId());
1324
1325 $tbl = new ilForumStatisticsTableGUI($this, 'showStatistics');
1326 $tbl->setId('il_frm_statistic_table_' . (int) $_GET['ref_id']);
1327 $tbl->setTitle(
1328 $this->lng->txt('statistic'),
1329 'icon_usr.svg',
1330 $this->lng->txt('obj_' . $this->object->getType())
1331 );
1332
1333 $data = $this->object->Forum->getUserStatistic($this->is_moderator);
1334 $result = array();
1335 $counter = 0;
1336 foreach ($data as $row) {
1337 $result[$counter]['ranking'] = $row[0];
1338 $result[$counter]['login'] = $row[1];
1339 $result[$counter]['lastname'] = $row[2];
1340 $result[$counter]['firstname'] = $row[3];
1341
1342 ++$counter;
1343 }
1344 $tbl->setData($result);
1345
1346 $this->tpl->setContent($tbl->getHTML());
1347 }
1348
1349 public static function _goto($a_target, $a_thread = 0, $a_posting = 0)
1350 {
1351 global $DIC;
1352
1353 $ilAccess = $DIC->access();
1354 $lng = $DIC->language();
1355 $ilErr = $DIC['ilErr'];
1356
1357 if ($ilAccess->checkAccess('read', '', $a_target)) {
1358 if ($a_thread != 0) {
1359 $objTopic = new ilForumTopic($a_thread);
1360 if ($objTopic->getFrmObjId() &&
1361 $objTopic->getFrmObjId() != ilObject::_lookupObjectId($a_target)) {
1362 $ref_ids = ilObject::_getAllReferences($objTopic->getFrmObjId());
1363 foreach ($ref_ids as $ref_id) {
1364 if ($ilAccess->checkAccess('read', '', $ref_id)) {
1365 $new_ref_id = $ref_id;
1366 break;
1367 }
1368 }
1369
1370 if (isset($new_ref_id) && $new_ref_id != $a_target) {
1371 $DIC->ctrl()->redirectToURL(
1372 ILIAS_HTTP_PATH . '/goto.php?target=frm_' . $new_ref_id . '_' . $a_thread . '_' . $a_posting
1373 );
1374 }
1375 }
1376
1377 $DIC->ctrl()->setParameterByClass(ilObjForumGUI::class, 'ref_id', (int) $a_target);
1378 if (is_numeric($a_thread)) {
1379 $DIC->ctrl()->setParameterByClass(ilObjForumGUI::class, 'thr_pk', (int) $a_thread);
1380 }
1381 if (is_numeric($a_posting)) {
1382 $DIC->ctrl()->setParameterByClass(ilObjForumGUI::class, 'pos_pk', (int) $a_posting);
1383 }
1384 $DIC->ctrl()->redirectByClass(
1385 [ilRepositoryGUI::class, self::class],
1386 'viewThread',
1387 is_numeric($a_posting) ? (int) $a_posting : ''
1388 );
1389 } else {
1390 $_GET['ref_id'] = $a_target;
1391 $_GET['baseClass'] = 'ilRepositoryGUI';
1392 include_once('ilias.php');
1393 exit();
1394 }
1395 } elseif ($ilAccess->checkAccess('visible', '', $a_target)) {
1396 $DIC->ctrl()->setParameterByClass(ilInfoScreenGUI::class, 'ref_id', $a_target);
1397 $DIC->ctrl()->redirectByClass(
1398 [
1399 ilRepositoryGUI::class,
1400 self::class,
1401 ilInfoScreenGUI::class
1402 ],
1403 'showSummary'
1404 );
1405 } elseif ($ilAccess->checkAccess('read', '', ROOT_FOLDER_ID)) {
1406 $_GET['target'] = '';
1407 $_GET['ref_id'] = ROOT_FOLDER_ID;
1408 ilUtil::sendInfo(sprintf(
1409 $lng->txt('msg_no_perm_read_item'),
1411 ), true);
1412 $_GET['baseClass'] = 'ilRepositoryGUI';
1413 include_once('ilias.php');
1414 exit();
1415 }
1416
1417 $ilErr->raiseError($lng->txt('msg_no_perm_read'), $ilErr->FATAL);
1418 }
1419
1421 {
1422 if (!$this->is_moderator) {
1423 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1424 }
1425
1426 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1427 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1428 }
1429
1430 if (!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids'])) {
1431 ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
1432 return $this->showThreadsObject();
1433 }
1434
1435 $forumObj = new ilObjForum($this->object->getRefId());
1436 $this->objProperties->setObjId($forumObj->getId());
1437
1438 $frm = new ilForum();
1439
1440 $success_message = "forums_thread_deleted";
1441 if (count($_POST['thread_ids']) > 1) {
1442 $success_message = "forums_threads_deleted";
1443 }
1444
1445 $threadIds = [];
1446 if (isset($_POST['thread_ids']) && is_array($_POST['thread_ids'])) {
1447 $threadIds = $_POST['thread_ids'];
1448 }
1449
1450 $threads = [];
1451 array_walk($threadIds, function ($threadId) use (&$threads) {
1452 $thread = new \ilForumTopic($threadId);
1453 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $thread);
1454
1455 $threads[] = $thread;
1456 });
1457
1458 foreach ($threads as $thread) {
1459 $frm->setForumId($forumObj->getId());
1460 $frm->setForumRefId($forumObj->getRefId());
1461
1462 $first_node = $frm->getFirstPostNode($thread->getId());
1463 if ((int) $first_node['pos_pk']) {
1464 $frm->deletePost($first_node['pos_pk']);
1465 ilUtil::sendInfo($this->lng->txt($success_message), true);
1466 }
1467 }
1468 $this->ctrl->redirect($this, 'showThreads');
1469 }
1470
1471 public function confirmDeleteThreads()
1472 {
1473 if (!isset($_POST['thread_ids']) || !is_array($_POST['thread_ids'])) {
1474 ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
1475 return $this->showThreadsObject();
1476 }
1477
1478 if (!$this->is_moderator) {
1479 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1480 }
1481
1482 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1483 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1484 }
1485
1486 $threads = [];
1487 array_walk($_POST['thread_ids'], function ($threadId) use (&$threads) {
1488 $thread = new \ilForumTopic($threadId);
1489 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $thread);
1490
1491 $threads[] = $thread;
1492 });
1493
1494 $c_gui = new ilConfirmationGUI();
1495
1496 $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteThreads'));
1497 $c_gui->setHeaderText($this->lng->txt('frm_sure_delete_threads'));
1498 $c_gui->setCancel($this->lng->txt('cancel'), 'showThreads');
1499 $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteThreads');
1500
1501 foreach ($threads as $thread) {
1502 $c_gui->addItem('thread_ids[]', $thread->getId(), $thread->getSubject());
1503 }
1504
1505 $this->confirmation_gui_html = $c_gui->getHTML();
1506
1507 $this->hideToolbar(true);
1508
1509 return $this->tpl->setContent($c_gui->getHTML());
1510 }
1511
1513 {
1514 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1515 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1516 }
1517
1518 $draftIds = array_filter((array) ($this->httpRequest->getParsedBody()['draft_ids'] ?? []));
1519 if (0 === count($draftIds)) {
1520 \ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'));
1521 $this->showThreadsObject();
1522 return;
1523 }
1524
1525 $confirmation = new ilConfirmationGUI();
1526 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteThreadDrafts'));
1527 $confirmation->setHeaderText($this->lng->txt('sure_delete_drafts'));
1528 $confirmation->setCancel($this->lng->txt('cancel'), 'showThreads');
1529 $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteThreadDrafts');
1530 $instances = \ilForumPostDraft::getDraftInstancesByUserId($this->user->getId());
1531 foreach ($draftIds as $draftId) {
1532 if (array_key_exists($draftId, $instances)) {
1533 $confirmation->addItem('draft_ids[]', $draftId, $instances[$draftId]->getPostSubject());
1534 }
1535 }
1536
1537 $this->tpl->setContent($confirmation->getHTML());
1538 }
1539
1540 public function prepareThreadScreen(ilObjForum $a_forum_obj)
1541 {
1542 $this->ilHelp->setScreenIdComponent("frm");
1543
1544 $this->tpl->loadStandardTemplate();
1547
1548 $this->tpl->setTitleIcon(ilObject::_getIcon("", "big", "frm"));
1549
1550 $this->tabs->setBackTarget(
1551 $this->lng->txt('all_topics'),
1552 'ilias.php?baseClass=ilRepositoryGUI&amp;ref_id=' . $_GET['ref_id']
1553 );
1554
1558 $frm = $a_forum_obj->Forum;
1559 $frm->setForumId($a_forum_obj->getId());
1560 }
1561
1563 {
1564 if (!$this->is_moderator) {
1565 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1566 }
1567
1568 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1569 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1570 }
1571
1572 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
1573
1574 $this->objCurrentPost->activatePost();
1575 $GLOBALS['ilAppEventHandler']->raise(
1576 'Modules/Forum',
1577 'activatedPost',
1578 array(
1579 'ref_id' => $this->object->getRefId(),
1580 'post' => $this->objCurrentPost
1581 )
1582 );
1583 ilUtil::sendInfo($this->lng->txt('forums_post_was_activated'), true);
1584
1585 $this->viewThreadObject();
1586 }
1587
1588 private function deletePostingObject()
1589 {
1590 if (
1591 !$this->objCurrentTopic->isClosed() && (
1592 $this->is_moderator ||
1593 ($this->objCurrentPost->isOwner($this->user->getId()) && !$this->objCurrentPost->hasReplies())
1594 ) &&
1595 !$this->user->isAnonymous()
1596 ) {
1597 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
1598
1599 $oForumObjects = $this->getForumObjects();
1601 $forumObj = $oForumObjects['forumObj'];
1602
1603 $frm = new ilForum();
1604 $frm->setForumId($forumObj->getId());
1605 $frm->setForumRefId($forumObj->getRefId());
1606 $dead_thr = $frm->deletePost($this->objCurrentPost->getId());
1607
1608 // if complete thread was deleted ...
1609 if ($dead_thr == $this->objCurrentTopic->getId()) {
1610 $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($forumObj->getId()));
1611 $topicData = $frm->getOneTopic();
1612 ilUtil::sendInfo($this->lng->txt('forums_post_deleted'), true);
1613 if ($topicData['top_num_threads'] > 0) {
1614 $this->ctrl->redirect($this, 'showThreads');
1615 } else {
1616 $this->ctrl->redirect($this, 'createThread');
1617 }
1618 }
1619 ilUtil::sendInfo($this->lng->txt('forums_post_deleted'), true);
1620 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
1621 $this->ctrl->redirect($this, 'viewThread');
1622 }
1623
1624 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1625 }
1626
1627 private function deletePostingDraftObject()
1628 {
1629 $this->deleteSelectedDraft();
1630 }
1631
1632 private function revokeCensorshipObject()
1633 {
1634 $this->handleCensorship(true);
1635 }
1636
1637 private function addCensorshipObject()
1638 {
1639 $this->handleCensorship();
1640 }
1641
1642 private function handleCensorship($wasRevoked = false)
1643 {
1644 if (!$this->objCurrentTopic->isClosed() && $this->is_moderator) {
1645 $message = $this->handleFormInput($_POST['formData']['cens_message']);
1646 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
1647
1648 $oForumObjects = $this->getForumObjects();
1650 $frm = $oForumObjects['frm'];
1651
1652 if ($wasRevoked) {
1653 $frm->postCensorship($message, $this->objCurrentPost->getId());
1654 ilUtil::sendSuccess($this->lng->txt('frm_censorship_revoked'));
1655 } else {
1656 $frm->postCensorship($message, $this->objCurrentPost->getId(), 1);
1657 ilUtil::sendSuccess($this->lng->txt('frm_censorship_applied'));
1658 }
1659
1660 $this->viewThreadObject();
1661 return;
1662 }
1663
1664 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1665 }
1666
1668 {
1669 if (!$this->is_moderator) {
1670 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1671 }
1672
1673 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1674 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1675 }
1676
1677 $this->setDisplayConfirmPostActivation(true);
1678
1679 $this->viewThreadObject();
1680 }
1681
1682 public function setDisplayConfirmPostActivation($status = 0)
1683 {
1684 $this->display_confirm_post_activation = $status;
1685 }
1686
1688 {
1689 return $this->display_confirm_post_activation;
1690 }
1691
1693 {
1694 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1695 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1696 }
1697
1698 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentTopic);
1699
1700 if ($this->objCurrentTopic->isNotificationEnabled($this->user->getId())) {
1701 $this->objCurrentTopic->disableNotification($this->user->getId());
1702 \ilUtil::sendInfo($this->lng->txt('forums_notification_disabled'));
1703 } else {
1704 $this->objCurrentTopic->enableNotification($this->user->getId());
1705 \ilUtil::sendInfo($this->lng->txt('forums_notification_enabled'));
1706 }
1707
1708 $this->viewThreadObject();
1709 }
1710
1711 protected function toggleStickinessObject()
1712 {
1713 if (!$this->is_moderator) {
1714 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1715 }
1716
1717 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
1718 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
1719 }
1720
1721 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentTopic);
1722
1723 if ($this->objCurrentTopic->isSticky()) {
1724 $this->objCurrentTopic->unmakeSticky();
1725 } else {
1726 $this->objCurrentTopic->makeSticky();
1727 }
1728
1729 $this->viewThreadObject();
1730 }
1731
1732 public function cancelPostObject()
1733 {
1734 $this->requestAction = '';
1735 if (isset($_POST['draft_id']) && (int) $_POST['draft_id'] > 0) {
1736 $draft = ilForumPostDraft::newInstanceByDraftId((int) $_POST['draft_id']);
1737 $draft->deleteDraftsByDraftIds(array((int) $_POST['draft_id']));
1738 }
1739
1740 $this->viewThreadObject();
1741 }
1742
1743 public function cancelDraftObject()
1744 {
1745 $this->requestAction = '';
1746 if (isset($_GET['draft_id']) && (int) $_GET['draft_id'] > 0) {
1748 $history_obj = new ilForumDraftsHistory();
1749 $history_obj->getFirstAutosaveByDraftId((int) $_GET['draft_id']);
1750 $draft = ilForumPostDraft::newInstanceByDraftId((int) $_GET['draft_id']);
1751 $draft->setPostSubject($history_obj->getPostSubject());
1752 $draft->setPostMessage($history_obj->getPostMessage());
1753
1755 $history_obj->getPostMessage(),
1757 $history_obj->getHistoryId(),
1759 $draft->getDraftId()
1760 );
1761
1762 $draft->updateDraft();
1763
1764 $history_obj->deleteHistoryByDraftIds(array($draft->getDraftId()));
1765 }
1766 }
1767 $this->ctrl->clearParameters($this);
1768 $this->viewThreadObject();
1769 }
1770
1771 public function getDeleteFormHTML()
1772 {
1774 $form_tpl = new ilTemplate('tpl.frm_delete_post_form.html', true, true, 'Modules/Forum');
1775 $form_tpl->setVariable('ANKER', $this->objCurrentPost->getId());
1776 $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1777 $form_tpl->setVariable('TXT_DELETE', $this->lng->txt('forums_info_delete_post'));
1778 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1779 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1780 $this->ctrl->setParameter(
1781 $this,
1782 'orderby',
1783 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
1784 );
1785 $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'viewThread'));
1786 $this->ctrl->clearParameters($this);
1787 $form_tpl->setVariable('CMD_CONFIRM', 'deletePosting');
1788 $form_tpl->setVariable('CMD_CANCEL', 'viewThread');
1789 $form_tpl->setVariable('CANCEL_BUTTON', $this->lng->txt('cancel'));
1790 $form_tpl->setVariable('CONFIRM_BUTTON', $this->lng->txt('confirm'));
1791
1792 return $form_tpl->get();
1793 }
1794
1795 public function getDeleteDraftFormHTML()
1796 {
1798 $form_tpl = new ilTemplate('tpl.frm_delete_post_form.html', true, true, 'Modules/Forum');
1799 $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1800 $form_tpl->setVariable('TXT_DELETE', $this->lng->txt('forums_info_delete_draft'));
1801 $this->ctrl->setParameter($this, 'draft_id', (int) $_GET['draft_id']);
1802 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1803 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1804 $this->ctrl->setParameter(
1805 $this,
1806 'orderby',
1807 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
1808 );
1809 $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'viewThread'));
1810 $this->ctrl->clearParameters($this);
1811 $form_tpl->setVariable('CMD_CONFIRM', 'deletePostingDraft');
1812 $form_tpl->setVariable('CMD_CANCEL', 'viewThread');
1813 $form_tpl->setVariable('CANCEL_BUTTON', $this->lng->txt('cancel'));
1814 $form_tpl->setVariable('CONFIRM_BUTTON', $this->lng->txt('confirm'));
1815
1816 return $form_tpl->get();
1817 }
1818
1819 public function getActivationFormHTML()
1820 {
1821 $form_tpl = new ilTemplate('tpl.frm_activation_post_form.html', true, true, 'Modules/Forum');
1822 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1823 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1824 $this->ctrl->setParameter(
1825 $this,
1826 'orderby',
1827 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
1828 );
1829 $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'performPostActivation'));
1830 $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1831 $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1832 $form_tpl->setVariable('TXT_ACT', $this->lng->txt('activate_post_txt'));
1833 $form_tpl->setVariable('CONFIRM_BUTTON', $this->lng->txt('activate_only_current'));
1834 $form_tpl->setVariable('CMD_CONFIRM', 'performPostActivation');
1835 $form_tpl->setVariable('CANCEL_BUTTON', $this->lng->txt('cancel'));
1836 $form_tpl->setVariable('CMD_CANCEL', 'viewThread');
1837 $this->ctrl->clearParameters($this);
1838
1839 return $form_tpl->get();
1840 }
1841
1842 public function getCensorshipFormHTML()
1843 {
1844 $frm = $this->object->Forum;
1845 $form_tpl = new ilTemplate('tpl.frm_censorship_post_form.html', true, true, 'Modules/Forum');
1846
1847 $form_tpl->setVariable('ANCHOR', $this->objCurrentPost->getId());
1848 $form_tpl->setVariable('SPACER', '<hr noshade="noshade" width="100%" size="1" align="center" />');
1849 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1850 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1851 $this->ctrl->setParameter(
1852 $this,
1853 'orderby',
1854 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
1855 );
1856 $form_tpl->setVariable('FORM_ACTION', $this->ctrl->getFormAction($this, 'viewThread'));
1857 $this->ctrl->clearParameters($this);
1858 $form_tpl->setVariable('TXT_CENS_MESSAGE', $this->lng->txt('forums_the_post'));
1859 $form_tpl->setVariable('TXT_CENS_COMMENT', $this->lng->txt('forums_censor_comment') . ':');
1860 $form_tpl->setVariable('CENS_MESSAGE', $frm->prepareText($this->objCurrentPost->getCensorshipComment(), 2));
1861
1862 if ($this->objCurrentPost->isCensored()) {
1863 $form_tpl->setVariable('TXT_CENS', $this->lng->txt('forums_info_censor2_post'));
1864 $form_tpl->setVariable('YES_BUTTON', $this->lng->txt('confirm'));
1865 $form_tpl->setVariable('NO_BUTTON', $this->lng->txt('cancel'));
1866 $form_tpl->setVariable('CMD_REVOKE_CENSORSHIP', 'revokeCensorship');
1867 $form_tpl->setVariable('CMD_CANCEL_REVOKE_CENSORSHIP', 'viewThread');
1868 } else {
1869 $form_tpl->setVariable('TXT_CENS', $this->lng->txt('forums_info_censor_post'));
1870 $form_tpl->setVariable('CANCEL_BUTTON', $this->lng->txt('cancel'));
1871 $form_tpl->setVariable('CONFIRM_BUTTON', $this->lng->txt('confirm'));
1872 $form_tpl->setVariable('CMD_ADD_CENSORSHIP', 'addCensorship');
1873 $form_tpl->setVariable('CMD_CANCEL_ADD_CENSORSHIP', 'viewThread');
1874 }
1875
1876 return $form_tpl->get();
1877 }
1878
1882 private function initReplyEditForm()
1883 {
1887 $isReply = in_array($this->requestAction, ['showreply', 'ready_showreply']);
1888 $isDraft = in_array($this->requestAction, ['publishDraft', 'editdraft']);
1889
1890 // init objects
1891 $oForumObjects = $this->getForumObjects();
1892 $frm = $oForumObjects['frm'];
1893 $oFDForum = $oForumObjects['file_obj'];
1894
1895 $this->replyEditForm = new ilPropertyFormGUI();
1896 $this->replyEditForm->setId('id_showreply');
1897 $this->replyEditForm->setTableWidth('100%');
1898 $cancel_cmd = 'cancelPost';
1899 if (in_array($this->requestAction, ['showreply', 'ready_showreply'])) {
1900 $this->ctrl->setParameter($this, 'action', 'ready_showreply');
1901 } elseif (in_array($this->requestAction, ['showdraft', 'editdraft'])) {
1902 $this->ctrl->setParameter($this, 'action', $this->requestAction);
1903 $this->ctrl->setParameter($this, 'draft_id', (int) $_GET['draft_id']);
1904 } else {
1905 $this->ctrl->setParameter($this, 'action', 'ready_showedit');
1906 }
1907
1908 $this->ctrl->setParameter($this, 'page', (int) $this->httpRequest->getQueryParams()['page']);
1909 $this->ctrl->setParameter(
1910 $this,
1911 'orderby',
1912 \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
1913 );
1914 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
1915 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
1916 if ($this->isTopLevelReplyCommand()) {
1917 $this->replyEditForm->setFormAction(
1918 $this->ctrl->getFormAction($this, 'saveTopLevelPost'),
1919 'frm_page_bottom'
1920 );
1921 } elseif (in_array($this->requestAction, ['publishDraft', 'editdraft'])) {
1922 $this->replyEditForm->setFormAction(
1923 $this->ctrl->getFormAction($this, 'publishDraft'),
1924 $this->objCurrentPost->getId()
1925 );
1926 } else {
1927 $this->replyEditForm->setFormAction(
1928 $this->ctrl->getFormAction($this, 'savePost'),
1929 $this->objCurrentPost->getId()
1930 );
1931 }
1932 $this->ctrl->clearParameters($this);
1933
1934 if ($isReply) {
1935 $this->replyEditForm->setTitle($this->lng->txt('forums_your_reply'));
1936 } elseif ($isDraft) {
1937 $this->replyEditForm->setTitle($this->lng->txt('forums_edit_draft'));
1938 } else {
1939 $this->replyEditForm->setTitle($this->lng->txt('forums_edit_post'));
1940 }
1941
1942 if (
1943 $this->isWritingWithPseudonymAllowed() &&
1944 in_array($this->requestAction, ['showreply', 'ready_showreply', 'editdraft'])
1945 ) {
1946 $oAnonymousNameGUI = new ilTextInputGUI($this->lng->txt('forums_your_name'), 'alias');
1947 $oAnonymousNameGUI->setMaxLength(64);
1948 $oAnonymousNameGUI->setInfo($this->lng->txt('forums_use_alias'));
1949
1950 $this->replyEditForm->addItem($oAnonymousNameGUI);
1951 }
1952
1953 $oSubjectGUI = new ilTextInputGUI($this->lng->txt('forums_subject'), 'subject');
1954 $oSubjectGUI->setMaxLength(255);
1955 $oSubjectGUI->setRequired(true);
1956
1957 if ($this->objProperties->getSubjectSetting() == 'empty_subject') {
1958 $oSubjectGUI->setInfo($this->lng->txt('enter_new_subject'));
1959 }
1960
1961 $this->replyEditForm->addItem($oSubjectGUI);
1962
1963 $oPostGUI = new ilTextAreaInputGUI(
1964 $isReply ? $this->lng->txt('forums_your_reply') : $this->lng->txt('forums_edit_post'),
1965 'message'
1966 );
1967 $oPostGUI->setRequired(true);
1968 $oPostGUI->setRows(15);
1969 $oPostGUI->setUseRte(true);
1970 $oPostGUI->addPlugin('latex');
1971 $oPostGUI->addButton('latex');
1972 $oPostGUI->addButton('pastelatex');
1973
1974 $quotingAllowed = (
1975 !$this->isTopLevelReplyCommand() && (
1976 ($isReply && $this->objCurrentPost->getDepth() >= 2) ||
1977 (!$isDraft && !$isReply && $this->objCurrentPost->getDepth() > 2) ||
1978 ($isDraft && $this->objCurrentPost->getDepth() >= 2)
1979 )
1980 );
1981 if ($quotingAllowed) {
1982 $oPostGUI->addPlugin('ilfrmquote');
1983 $oPostGUI->addButton('ilFrmQuoteAjaxCall');
1984 }
1985
1986 $oPostGUI->removePlugin('advlink');
1987 $oPostGUI->setRTERootBlockElement('');
1988 $oPostGUI->usePurifier(true);
1989 $oPostGUI->disableButtons(array(
1990 'charmap',
1991 'undo',
1992 'redo',
1993 'justifyleft',
1994 'justifycenter',
1995 'justifyright',
1996 'justifyfull',
1997 'anchor',
1998 'fullscreen',
1999 'cut',
2000 'copy',
2001 'paste',
2002 'pastetext',
2003 'formatselect'
2004 ));
2005
2006 if (in_array($this->requestAction, ['showreply', 'ready_showreply', 'showdraft', 'editdraft'])) {
2007 $oPostGUI->setRTESupport(
2008 $this->user->getId(),
2009 'frm~',
2010 'frm_post',
2011 'tpl.tinymce_frm_post.js',
2012 false,
2013 '3.5.11'
2014 );
2015 } else {
2016 $oPostGUI->setRTESupport(
2017 $this->objCurrentPost->getId(),
2018 'frm',
2019 'frm_post',
2020 'tpl.tinymce_frm_post.js',
2021 false,
2022 '3.5.11'
2023 );
2024 }
2025 // purifier
2026 $oPostGUI->setPurifier(ilHtmlPurifierFactory::_getInstanceByType('frm_post'));
2027
2028 $this->replyEditForm->addItem($oPostGUI);
2029
2030 // notification only if gen. notification is disabled and forum isn't anonymous
2031 $umail = new ilMail($this->user->getId());
2032 if ($this->rbac->system()->checkAccess('internal_mail', $umail->getMailObjectReferenceId()) &&
2033 !$frm->isThreadNotificationEnabled($this->user->getId(), $this->objCurrentPost->getThreadId()) &&
2034 !$this->objProperties->isAnonymized()) {
2035 $oNotificationGUI = new ilCheckboxInputGUI($this->lng->txt('forum_direct_notification'), 'notify');
2036 $oNotificationGUI->setInfo($this->lng->txt('forum_notify_me'));
2037
2038 $this->replyEditForm->addItem($oNotificationGUI);
2039 }
2040
2041 if ($this->objProperties->isFileUploadAllowed()) {
2042 $oFileUploadGUI = new ilFileWizardInputGUI($this->lng->txt('forums_attachments_add'), 'userfile');
2043 $oFileUploadGUI->setFilenames(array(0 => ''));
2044 $this->replyEditForm->addItem($oFileUploadGUI);
2045 }
2046
2047 if (
2048 $this->user->isAnonymous() &&
2049 !$this->user->isCaptchaVerified() &&
2050 ilCaptchaUtil::isActiveForForum()
2051 ) {
2052 $captcha = new ilCaptchaInputGUI($this->lng->txt('cont_captcha_code'), 'captcha_code');
2053 $captcha->setRequired(true);
2054 $this->replyEditForm->addItem($captcha);
2055 }
2056
2057 $attachments_of_node = $oFDForum->getFilesOfPost();
2058 if (count($attachments_of_node) && in_array($this->requestAction, ['showedit', 'ready_showedit'])) {
2059 $oExistingAttachmentsGUI = new ilCheckboxGroupInputGUI($this->lng->txt('forums_delete_file'), 'del_file');
2060 foreach ($oFDForum->getFilesOfPost() as $file) {
2061 $oAttachmentGUI = new ilCheckboxInputGUI($file['name'], 'del_file');
2062 $oAttachmentGUI->setValue($file['md5']);
2063 $oExistingAttachmentsGUI->addOption($oAttachmentGUI);
2064 }
2065 $this->replyEditForm->addItem($oExistingAttachmentsGUI);
2066 }
2067
2069 if (in_array($this->requestAction, ['showdraft', 'editdraft'])) {
2070 $draftInfoGUI = new ilNonEditableValueGUI('', 'autosave_info', true);
2071 $draftInfoGUI->setValue(sprintf(
2072 $this->lng->txt('autosave_draft_info'),
2074 ));
2075 $this->replyEditForm->addItem($draftInfoGUI);
2076 } elseif (!in_array($this->requestAction, ['showedit', 'ready_showedit'])) {
2077 $draftInfoGUI = new ilNonEditableValueGUI('', 'autosave_info', true);
2078 $draftInfoGUI->setValue(sprintf(
2079 $this->lng->txt('autosave_post_draft_info'),
2081 ));
2082 $this->replyEditForm->addItem($draftInfoGUI);
2083 }
2084 }
2085 $selected_draft_id = (int) $_GET['draft_id'];
2086 $draftObj = new ilForumPostDraft(
2087 $this->user->getId(),
2088 $this->objCurrentPost->getId(),
2089 $selected_draft_id
2090 );
2091 if ($draftObj->getDraftId() > 0) {
2092 $oFDForumDrafts = new ilFileDataForumDrafts(0, $draftObj->getDraftId());
2093 if (count($oFDForumDrafts->getFilesOfPost())) {
2094 $oExistingAttachmentsGUI = new ilCheckboxGroupInputGUI(
2095 $this->lng->txt('forums_delete_file'),
2096 'del_file'
2097 );
2098 foreach ($oFDForumDrafts->getFilesOfPost() as $file) {
2099 $oAttachmentGUI = new ilCheckboxInputGUI($file['name'], 'del_file');
2100 $oAttachmentGUI->setValue($file['md5']);
2101 $oExistingAttachmentsGUI->addOption($oAttachmentGUI);
2102 }
2103 $this->replyEditForm->addItem($oExistingAttachmentsGUI);
2104 }
2105 }
2106
2107 if ($this->isTopLevelReplyCommand()) {
2108 $this->replyEditForm->addCommandButton('saveTopLevelPost', $this->lng->txt('create'));
2109 } elseif (ilForumPostDraft::isSavePostDraftAllowed() && $this->requestAction == 'editdraft') {
2110 $this->replyEditForm->addCommandButton('publishDraft', $this->lng->txt('publish'));
2111 } else {
2112 $this->replyEditForm->addCommandButton('savePost', $this->lng->txt('save'));
2113 }
2114 $hidden_draft_id = new ilHiddenInputGUI('draft_id');
2115 if (isset($_GET['draft_id']) && (int) $_GET['draft_id'] > 0) {
2116 $auto_save_draft_id = (int) $_GET['draft_id'];
2117 }
2118 $hidden_draft_id->setValue($auto_save_draft_id);
2119 $this->replyEditForm->addItem($hidden_draft_id);
2120
2121 if (in_array($this->requestAction, ['showreply', 'ready_showreply', 'editdraft'])) {
2122 $rtestring = ilRTE::_getRTEClassname();
2123
2124 if (array_key_exists('show_rte', $_POST)) {
2126 }
2127
2128 if (strtolower($rtestring) != 'iltinymce' || !ilObjAdvancedEditing::_getRichTextEditorUserState()) {
2129 if ($quotingAllowed) {
2130 $this->replyEditForm->addCommandButton('quotePost', $this->lng->txt('forum_add_quote'));
2131 }
2132 }
2133
2134 if (
2135 !$this->user->isAnonymous() &&
2136 in_array($this->requestAction, ['editdraft', 'showreply', 'ready_showreply']) &&
2138 ) {
2140 $this->decorateWithAutosave($this->replyEditForm);
2141 }
2142
2143 if ($this->requestAction == 'editdraft') {
2144 $this->replyEditForm->addCommandButton('updateDraft', $this->lng->txt('save_message'));
2145 } elseif ($this->isTopLevelReplyCommand()) {
2146 $this->replyEditForm->addCommandButton('saveTopLevelDraft', $this->lng->txt('save_message'));
2147 } else {
2148 $this->replyEditForm->addCommandButton('saveAsDraft', $this->lng->txt('save_message'));
2149 }
2150
2151 $cancel_cmd = 'cancelDraft';
2152 }
2153 }
2154 $this->replyEditForm->addCommandButton($cancel_cmd, $this->lng->txt('cancel'));
2155 }
2156
2160 private function getReplyEditForm()
2161 {
2162 if (null === $this->replyEditForm) {
2163 $this->initReplyEditForm();
2164 }
2165
2166 return $this->replyEditForm;
2167 }
2168
2173 {
2174 if (isset($_GET['draft_id']) && (int) $_GET['draft_id'] > 0 && !$this->user->isAnonymous()
2176 $draft_obj = new ilForumPostDraft(
2177 $this->user->getId(),
2178 $this->objCurrentPost->getId(),
2179 (int) $_GET['draft_id']
2180 );
2181 }
2182
2183 if ($draft_obj instanceof ilForumPostDraft && $draft_obj->getDraftId() > 0) {
2184 $this->ctrl->setParameter($this, 'action', 'editdraft');
2185 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2186 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2187 $this->ctrl->setParameter($this, 'draft_id', $draft_obj->getDraftId());
2188 $this->ctrl->setParameter($this, 'page', 1);
2189 $this->ctrl->setParameter(
2190 $this,
2191 'orderby',
2192 \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
2193 );
2194 $this->ctrl->redirect($this, 'editDraft');
2195 } else {
2196 $this->viewThreadObject();
2197 }
2198 return;
2199 }
2200
2204 public function saveTopLevelPostObject()
2205 {
2206 $this->savePostObject();
2207 return;
2208 }
2209
2211 {
2212 if (isset($_GET['draft_id']) && (int) $_GET['draft_id'] > 0) {
2213 $this->publishDraftObject(false);
2214 }
2215 }
2216
2217 public function publishDraftObject($use_replyform = true)
2218 {
2219 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
2220 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2221 }
2222
2223 if (!$this->access->checkAccess('add_reply', '', $this->object->getRefId())) {
2224 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2225 }
2226
2227 if (!$this->objCurrentTopic->getId()) {
2228 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_deleted'), true);
2229 $this->ctrl->redirect($this);
2230 }
2231
2232 if ($this->objCurrentTopic->isClosed()) {
2233 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_closed'), true);
2234 $this->ctrl->redirect($this);
2235 }
2236
2237 if (!$this->objCurrentPost->getId()) {
2238 $this->requestAction = '';
2239 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_parent_deleted'));
2240 $this->viewThreadObject();
2241 return;
2242 }
2243
2244 $post_id = $this->objCurrentPost->getId();
2245
2246 $draft_obj = new ilForumPostDraft($this->user->getId(), $post_id, (int) $_GET['draft_id']);
2247
2248 if ($use_replyform) {
2249 $oReplyEditForm = $this->getReplyEditForm();
2250 if (!$oReplyEditForm->checkInput()) {
2251 $oReplyEditForm->setValuesByPost();
2252 return $this->viewThreadObject();
2253 }
2254 $post_subject = $oReplyEditForm->getInput('subject');
2255 $post_message = $oReplyEditForm->getInput('message');
2256 $mob_direction = 0;
2257 } else {
2258 $post_subject = $draft_obj->getPostSubject();
2259 $post_message = $draft_obj->getPostMessage();
2260 $mob_direction = 1;
2261 }
2262
2263 if ($draft_obj->getDraftId() > 0) {
2264 // init objects
2265 $oForumObjects = $this->getForumObjects();
2266 $frm = $oForumObjects['frm'];
2267 $frm->setMDB2WhereCondition(' top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
2268
2269 // reply: new post
2270 $status = 1;
2271 $send_activation_mail = 0;
2272
2273 if ($this->objProperties->isPostActivationEnabled()) {
2274 if (!$this->is_moderator) {
2275 $status = 0;
2276 $send_activation_mail = 1;
2277 } elseif ($this->objCurrentPost->isAnyParentDeactivated()) {
2278 $status = 0;
2279 }
2280 }
2281
2282 $newPost = $frm->generatePost(
2283 $draft_obj->getForumId(),
2284 $draft_obj->getThreadId(),
2285 $this->user->getId(),
2286 $draft_obj->getPostDisplayUserId(),
2287 ilRTE::_replaceMediaObjectImageSrc($post_message, $mob_direction),
2288 $draft_obj->getPostId(),
2289 (int) $draft_obj->getNotify(),
2290 $this->handleFormInput($post_subject, false),
2291 $draft_obj->getPostUserAlias(),
2292 '',
2293 $status,
2294 $send_activation_mail
2295 );
2296
2297 $this->object->markPostRead(
2298 $this->user->getId(),
2299 (int) $this->objCurrentTopic->getId(),
2300 (int) $this->objCurrentPost->getId()
2301 );
2302
2303 $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->user->getId());
2304
2305 foreach ($uploadedObjects as $mob) {
2306 ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->user->getId());
2307 ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
2308 }
2309 ilForumUtil::saveMediaObjects($post_message, 'frm:html', $newPost, $mob_direction);
2310
2311 if ($this->objProperties->isFileUploadAllowed()) {
2312 $file = $_FILES['userfile'];
2313 if (is_array($file) && !empty($file)) {
2314 $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost);
2315 $tmp_file_obj->storeUploadedFile($file);
2316 }
2317
2318 //move files of draft to posts directory
2319 $oFDForum = new ilFileDataForum($this->object->getId(), $newPost);
2320 $oFDForumDrafts = new ilFileDataForumDrafts($this->object->getId(), $draft_obj->getDraftId());
2321
2322 $oFDForumDrafts->moveFilesOfDraft($oFDForum->getForumPath(), $newPost);
2323 $oFDForumDrafts->delete();
2324 }
2325
2327 $GLOBALS['ilAppEventHandler']->raise(
2328 'Modules/Forum',
2329 'publishedDraft',
2330 array(
2331 'draftObj' => $draft_obj,
2332 'obj_id' => $this->object->getId(),
2333 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed()
2334 )
2335 );
2336 }
2337 $draft_obj->deleteDraft();
2338
2339 $GLOBALS['ilAppEventHandler']->raise(
2340 'Modules/Forum',
2341 'createdPost',
2342 array(
2343 'ref_id' => $this->object->getRefId(),
2344 'post' => new ilForumPost($newPost),
2345 'notify_moderators' => (bool) $send_activation_mail
2346 )
2347 );
2348
2349 $message = '';
2350 if (!$this->is_moderator && !$status) {
2351 $message .= $this->lng->txt('forums_post_needs_to_be_activated');
2352 } else {
2353 $message .= $this->lng->txt('forums_post_new_entry');
2354 }
2355
2356 $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes'][] = (int) $this->objCurrentPost->getId();
2357
2358 $this->ctrl->clearParameters($this);
2359 ilUtil::sendSuccess($message, true);
2360 $this->ctrl->setParameter($this, 'pos_pk', $newPost);
2361 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2362
2363 $this->ctrl->redirect($this, 'viewThread');
2364 }
2365 }
2366
2370 public function savePostObject()
2371 {
2372 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
2373 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2374 }
2375
2376 if (!$this->objCurrentTopic->getId()) {
2377 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_deleted'), true);
2378 $this->ctrl->redirect($this);
2379 }
2380
2381 if ($this->objCurrentTopic->isClosed()) {
2382 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_closed'), true);
2383 $this->ctrl->redirect($this);
2384 }
2385
2386 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentTopic);
2387
2388 if (!isset($_POST['del_file']) || !is_array($_POST['del_file'])) {
2389 $_POST['del_file'] = array();
2390 }
2391
2392 $oReplyEditForm = $this->getReplyEditForm();
2393 if ($oReplyEditForm->checkInput()) {
2394 if (!$this->objCurrentPost->getId()) {
2395 $this->requestAction = '';
2396 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_parent_deleted'));
2397 $this->viewThreadObject();
2398 return;
2399 }
2400
2401 $this->doCaptchaCheck();
2402
2403 // init objects
2404 $oForumObjects = $this->getForumObjects();
2408 $forumObj = $oForumObjects['forumObj'];
2412 $frm = $oForumObjects['frm'];
2413 $frm->setMDB2WhereCondition(' top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
2414 $topicData = $frm->getOneTopic();
2415
2416 // Generating new posting
2417 if ($this->requestAction == 'ready_showreply') {
2418 if (!$this->access->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
2419 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2420 }
2421
2422 // reply: new post
2423 $status = 1;
2424 $send_activation_mail = 0;
2425
2426 if ($this->objProperties->isPostActivationEnabled()) {
2427 if (!$this->is_moderator) {
2428 $status = 0;
2429 $send_activation_mail = 1;
2430 } elseif ($this->objCurrentPost->isAnyParentDeactivated()) {
2431 $status = 0;
2432 }
2433 }
2434
2435 if ($this->isWritingWithPseudonymAllowed()) {
2436 if (!strlen($oReplyEditForm->getInput('alias'))) {
2437 $user_alias = $this->lng->txt('forums_anonymous');
2438 } else {
2439 $user_alias = $oReplyEditForm->getInput('alias');
2440 }
2441 $display_user_id = 0;
2442 } else {
2443 $user_alias = $this->user->getLogin();
2444 $display_user_id = $this->user->getId();
2445 }
2446
2447 $newPost = $frm->generatePost(
2448 $topicData['top_pk'],
2449 $this->objCurrentTopic->getId(),
2450 $this->user->getId(),
2451 $display_user_id,
2452 ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0),
2453 $this->objCurrentPost->getId(),
2454 (int) $oReplyEditForm->getInput('notify'),
2455 $this->handleFormInput($oReplyEditForm->getInput('subject'), false),
2456 $user_alias,
2457 '',
2458 $status,
2459 $send_activation_mail
2460 );
2461
2463 $draft_id = 0;
2465 $draft_id = $_POST['draft_id']; // info aus dem autosave?
2466 }
2467 $draft_obj = new ilForumPostDraft($this->user->getId(), $this->objCurrentPost->getId(), $draft_id);
2468 if ($draft_obj instanceof ilForumPostDraft) {
2469 $draft_obj->deleteDraft();
2470 }
2471 }
2472
2473 // mantis #8115: Mark parent as read
2474 $this->object->markPostRead(
2475 $this->user->getId(),
2476 (int) $this->objCurrentTopic->getId(),
2477 (int) $this->objCurrentPost->getId()
2478 );
2479
2480 // copy temporary media objects (frm~)
2482 $oReplyEditForm->getInput('message'),
2483 'frm~:html',
2484 $this->user->getId(),
2485 'frm:html',
2486 $newPost
2487 );
2488
2489 if ($this->objProperties->isFileUploadAllowed()) {
2490 $oFDForum = new ilFileDataForum($forumObj->getId(), $newPost);
2491 $file = $_FILES['userfile'];
2492 if (is_array($file) && !empty($file)) {
2493 $oFDForum->storeUploadedFile($file);
2494 }
2495 }
2496
2497 $GLOBALS['ilAppEventHandler']->raise(
2498 'Modules/Forum',
2499 'createdPost',
2500 array(
2501 'ref_id' => $this->object->getRefId(),
2502 'post' => new ilForumPost($newPost),
2503 'notify_moderators' => (bool) $send_activation_mail
2504 )
2505 );
2506
2507 $message = '';
2508 if (!$this->is_moderator && !$status) {
2509 $message .= $this->lng->txt('forums_post_needs_to_be_activated');
2510 } else {
2511 $message .= $this->lng->txt('forums_post_new_entry');
2512 }
2513
2514 ilUtil::sendSuccess($message, true);
2515 $this->ctrl->clearParameters($this);
2516 $this->ctrl->setParameter($this, 'post_created_below', $this->objCurrentPost->getId());
2517 $this->ctrl->setParameter($this, 'pos_pk', $newPost);
2518 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2519 $this->ctrl->redirect($this, 'viewThread');
2520 } else {
2521 if ((!$this->is_moderator &&
2522 !$this->objCurrentPost->isOwner($this->user->getId())) || $this->objCurrentPost->isCensored() ||
2523 $this->user->isAnonymous()) {
2524 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2525 }
2526
2527 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
2528
2529 // remove usage of deleted media objects
2530 $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm:html', $this->objCurrentPost->getId());
2531 $curMediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
2532 foreach ($oldMediaObjects as $oldMob) {
2533 $found = false;
2534 foreach ($curMediaObjects as $curMob) {
2535 if ($oldMob == $curMob) {
2536 $found = true;
2537 break;
2538 }
2539 }
2540 if (!$found) {
2541 if (ilObjMediaObject::_exists($oldMob)) {
2542 ilObjMediaObject::_removeUsage($oldMob, 'frm:html', $this->objCurrentPost->getId());
2543 $mob_obj = new ilObjMediaObject($oldMob);
2544 $mob_obj->delete();
2545 }
2546 }
2547 }
2548
2549 // save old activation status for send_notification decision
2550 $old_status_was_active = $this->objCurrentPost->isActivated();
2551
2552 // if active post has been edited posting mus be activated again by moderator
2553 $status = 1;
2554 $send_activation_mail = 0;
2555
2556 if ($this->objProperties->isPostActivationEnabled()) {
2557 if (!$this->is_moderator) {
2558 $status = 0;
2559 $send_activation_mail = 1;
2560 } elseif ($this->objCurrentPost->isAnyParentDeactivated()) {
2561 $status = 0;
2562 }
2563 }
2564 $this->objCurrentPost->setStatus($status);
2565
2566 $this->objCurrentPost->setSubject($this->handleFormInput($oReplyEditForm->getInput('subject'), false));
2567 $this->objCurrentPost->setMessage(ilRTE::_replaceMediaObjectImageSrc(
2568 $oReplyEditForm->getInput('message'),
2569 0
2570 ));
2571 $this->objCurrentPost->setNotification((int) $oReplyEditForm->getInput('notify'));
2572 $this->objCurrentPost->setChangeDate(date('Y-m-d H:i:s'));
2573 $this->objCurrentPost->setUpdateUserId($this->user->getId());
2574
2575 // edit: update post
2576 if ($this->objCurrentPost->update()) {
2577 $this->objCurrentPost->reload();
2578
2579 // Change news item accordingly
2580 // note: $this->objCurrentPost->getForumId() does not give us the forum ID here (why?)
2582 $forumObj->getId(),
2583 'frm',
2584 $this->objCurrentPost->getId(),
2585 'pos'
2586 );
2587 if ($news_id > 0) {
2588 $news_item = new ilNewsItem($news_id);
2589 $news_item->setTitle($this->objCurrentPost->getSubject());
2590 $news_item->setContent(
2591 ilRTE::_replaceMediaObjectImageSrc($frm->prepareText(
2592 $this->objCurrentPost->getMessage(),
2593 0
2594 ), 1)
2595 );
2596
2597 if ($this->objCurrentPost->getMessage() != strip_tags($this->objCurrentPost->getMessage())) {
2598 $news_item->setContentHtml(true);
2599 } else {
2600 $news_item->setContentHtml(false);
2601 }
2602 $news_item->update();
2603 }
2604
2605 $oFDForum = $oForumObjects['file_obj'];
2606
2607 $file2delete = $oReplyEditForm->getInput('del_file');
2608 if (is_array($file2delete) && count($file2delete)) {
2609 $oFDForum->unlinkFilesByMD5Filenames($file2delete);
2610 }
2611
2612 if ($this->objProperties->isFileUploadAllowed()) {
2613 $file = $_FILES['userfile'];
2614 if (is_array($file) && !empty($file)) {
2615 $oFDForum->storeUploadedFile($file);
2616 }
2617 }
2618
2619 $GLOBALS['ilAppEventHandler']->raise(
2620 'Modules/Forum',
2621 'updatedPost',
2622 array(
2623 'ref_id' => $this->object->getRefId(),
2624 'post' => $this->objCurrentPost,
2625 'notify_moderators' => (bool) $send_activation_mail,
2626 'old_status_was_active' => (bool) $old_status_was_active
2627 )
2628 );
2629
2630 ilUtil::sendSuccess($this->lng->txt('forums_post_modified'), true);
2631 }
2632
2633 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
2634 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
2635 $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
2636 $this->ctrl->redirect($this, 'viewThread');
2637 }
2638 } else {
2639 $this->requestAction = substr($this->requestAction, 6);
2640 }
2641 return $this->viewThreadObject();
2642 }
2643
2644 private function hideToolbar($a_flag = null)
2645 {
2646 if (null === $a_flag) {
2647 return $this->hideToolbar;
2648 }
2649
2650 $this->hideToolbar = $a_flag;
2651 return $this;
2652 }
2653
2654 public function quotePostObject()
2655 {
2656 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
2657 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2658 }
2659
2660 if (!is_array($_POST['del_file'])) {
2661 $_POST['del_file'] = array();
2662 }
2663
2664 if ($this->objCurrentTopic->isClosed()) {
2665 $this->requestAction = '';
2666 return $this->viewThreadObject();
2667 }
2668
2669 $oReplyEditForm = $this->getReplyEditForm();
2670
2671 // remove mandatory fields
2672 $oReplyEditForm->getItemByPostVar('subject')->setRequired(false);
2673 $oReplyEditForm->getItemByPostVar('message')->setRequired(false);
2674
2675 $oReplyEditForm->checkInput();
2676
2677 // add mandatory fields
2678 $oReplyEditForm->getItemByPostVar('subject')->setRequired(true);
2679 $oReplyEditForm->getItemByPostVar('message')->setRequired(true);
2680
2681 $this->requestAction = 'showreply';
2682
2683 $this->viewThreadObject();
2684 }
2685
2686 public function getQuotationHTMLAsynchObject()
2687 {
2688 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
2689 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2690 }
2691
2692 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
2693
2694 $oForumObjects = $this->getForumObjects();
2698 $frm = $oForumObjects['frm'];
2699
2700 $authorinfo = new ilForumAuthorInformation(
2701 $this->objCurrentPost->getPosAuthorId(),
2702 $this->objCurrentPost->getDisplayUserId(),
2703 $this->objCurrentPost->getUserAlias(),
2704 $this->objCurrentPost->getImportName()
2705 );
2706
2707 $html = ilRTE::_replaceMediaObjectImageSrc($frm->prepareText(
2708 $this->objCurrentPost->getMessage(),
2709 1,
2710 $authorinfo->getAuthorName()
2711 ), 1);
2712 echo $html;
2713 exit();
2714 }
2715
2716 private function getForumObjects()
2717 {
2718 if (null === $this->forumObjects) {
2719 $forumObj = $this->object;
2720 $file_obj = new ilFileDataForum($forumObj->getId(), $this->objCurrentPost->getId());
2721 $frm = $forumObj->Forum;
2722 $frm->setForumId($forumObj->getId());
2723 $frm->setForumRefId($forumObj->getRefId());
2724
2725 $this->forumObjects['forumObj'] = $forumObj;
2726 $this->forumObjects['frm'] = $frm;
2727 $this->forumObjects['file_obj'] = $file_obj;
2728 }
2729
2730 return $this->forumObjects;
2731 }
2732
2733 public function checkUsersViewMode() : void
2734 {
2735 if (!isset($_SESSION['viewmode'])) {
2736 $_SESSION['viewmode'] = $this->objProperties->getDefaultView();
2737 }
2738
2739 if (isset($_GET['viewmode']) && (int) $_GET['viewmode'] !== (int) $_SESSION['viewmode']) {
2740 $_SESSION['viewmode'] = (int) $_GET['viewmode'];
2741 }
2742
2743 if (isset($_GET['action']) && !in_array($_SESSION['viewmode'], [
2747 ])) {
2748 $_SESSION['viewmode'] = $this->objProperties->getDefaultView();
2749 }
2750 }
2751
2752 public function viewThreadObject()
2753 {
2754 $this->checkUsersViewMode();
2755
2756 $bottom_toolbar = clone $this->toolbar;
2757 $bottom_toolbar_split_button_items = [];
2758
2759 // quick and dirty: check for treeview
2760 if (!isset($_SESSION['thread_control']['old'])) {
2761 $_SESSION['thread_control']['old'] = $_GET['thr_pk'];
2762 $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
2763 } else {
2764 if (isset($_SESSION['thread_control']['old']) && $_GET['thr_pk'] != $_SESSION['thread_control']['old']) {
2765 $_SESSION['thread_control']['new'] = $_GET['thr_pk'];
2766 }
2767 }
2768
2769 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
2770 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
2771 }
2772
2773 $pageIndex = 0;
2774 if (isset($this->httpRequest->getQueryParams()['page'])) {
2775 $pageIndex = max((int) $this->httpRequest->getQueryParams()['page'], $pageIndex);
2776 }
2777
2778 $firstNodeInThread = $this->objCurrentTopic->getFirstPostNode();
2779
2780 $toolContext = $this->globalScreen
2781 ->tool()
2782 ->context()
2783 ->current();
2784
2785 $additionalDataExists = $toolContext->getAdditionalData()->exists(ForumGlobalScreenToolsProvider::SHOW_FORUM_THREADS_TOOL);
2786 if (false === $additionalDataExists && $_SESSION['viewmode'] === ilForumProperties::VIEW_TREE) {
2787 $toolContext
2789 ->addAdditionalData(ForumGlobalScreenToolsProvider::REF_ID, (int) $this->ref_id)
2790 ->addAdditionalData(ForumGlobalScreenToolsProvider::FORUM_THEAD, $this->objCurrentTopic)
2791 ->addAdditionalData(ForumGlobalScreenToolsProvider::FORUM_THREAD_ROOT, $firstNodeInThread)
2793 ->addAdditionalData(ForumGlobalScreenToolsProvider::PAGE, $pageIndex);
2794 }
2795
2796 $oForumObjects = $this->getForumObjects();
2798 $forumObj = $oForumObjects['forumObj'];
2800 $frm = $oForumObjects['frm'];
2802 $file_obj = $oForumObjects['file_obj'];
2803
2804 $selected_draft_id = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
2805
2806 if (isset($this->httpRequest->getQueryParams()['file'])) {
2807 $file_obj_for_delivery = $file_obj;
2808 if (ilForumPostDraft::isSavePostDraftAllowed() && $selected_draft_id > 0) {
2809 $file_obj_for_delivery = new ilFileDataForumDrafts($forumObj->getId(), $selected_draft_id);
2810 }
2811 $file_obj_for_delivery->deliverFile(\ilUtil::stripSlashes($this->httpRequest->getQueryParams()['file']));
2812 }
2813
2814 if (!$this->objCurrentTopic->getId()) {
2815 $this->ctrl->redirect($this, 'showThreads');
2816 }
2817
2818 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentTopic);
2819
2820 // Set context for login
2821 $append = '_' . $this->objCurrentTopic->getId() .
2822 ($this->objCurrentPost->getId() ? '_' . $this->objCurrentPost->getId() : '');
2823 $this->tpl->setLoginTargetPar('frm_' . $_GET['ref_id'] . $append);
2824
2825 // delete temporary media object (not in case a user adds media objects and wants to save an invalid form)
2826 if (!in_array($this->requestAction, ['showreply', 'showedit'])) {
2827 try {
2828 $mobs = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->user->getId());
2829 foreach ($mobs as $mob) {
2830 if (ilObjMediaObject::_exists($mob)) {
2831 ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->user->getId());
2832 $mob_obj = new ilObjMediaObject($mob);
2833 $mob_obj->delete();
2834 }
2835 }
2836 } catch (Exception $e) {
2837 }
2838 }
2839
2840 if (!$this->getCreationMode() && $this->access->checkAccess('read', '', $this->object->getRefId())) {
2842 (int) $this->object->getRefId(),
2843 \ilLink::_getLink((int) $this->object->getRefId(), 'frm'),
2844 'frm'
2845 );
2846 }
2847
2848 // save last access
2849 $forumObj->updateLastAccess($this->user->getId(), (int) $this->objCurrentTopic->getId());
2850
2851 $this->prepareThreadScreen($forumObj);
2852
2853 $threadContentTemplate = new \ilTemplate(
2854 'tpl.forums_threads_view.html',
2855 true,
2856 true,
2857 'Modules/Forum'
2858 );
2859
2860 if (isset($this->httpRequest->getQueryParams()['anchor'])) {
2861 $threadContentTemplate->setVariable('JUMP2ANCHOR_ID', (int) $this->httpRequest->getQueryParams()['anchor']);
2862 }
2863
2864 $currentSortation = ilForumProperties::VIEW_DATE_ASC;
2865 if ($this->isHierarchicalView()) {
2866 $orderField = 'frm_posts_tree.rgt';
2867 $this->objCurrentTopic->setOrderDirection('DESC');
2868 } else {
2869 if (isset($_SESSION['viewmode'])) {
2870 $currentSortation = (in_array($_SESSION['viewmode'], [
2873 ]) ? $_SESSION['viewmode'] : $currentSortation);
2874 }
2875
2876 $orderField = 'frm_posts.pos_date';
2877 $this->objCurrentTopic->setOrderDirection(
2878 (int) $currentSortation === ilForumProperties::VIEW_DATE_DESC ? 'DESC' : 'ASC'
2879 );
2880 }
2881
2882 $currentViewMode = $this->objProperties->getDefaultView();
2883 if (isset($_SESSION['viewmode'])) {
2884 $currentViewMode = (in_array($_SESSION['viewmode'], [
2888 }
2889 $threadContentTemplate->setVariable('LIST_TYPE', $this->viewModeOptions[$currentViewMode]);
2890
2891 $numberOfPostings = 0;
2892
2893 // get forum- and thread-data
2894 $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
2895
2896 if ($firstNodeInThread) {
2897 $this->objCurrentTopic->updateVisits();
2898
2899 $this->tpl->setTitle($this->lng->txt('forums_thread') . " \"" . $this->objCurrentTopic->getSubject() . "\"");
2900
2901 $this->locator->addRepositoryItems();
2902 $this->locator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "_top");
2903 $this->tpl->setLocator();
2904
2905 if (
2906 !$this->user->isAnonymous() &&
2907 $forumObj->getCountUnread($this->user->getId(), (int) $this->objCurrentTopic->getId(), true)
2908 ) {
2909 $this->ctrl->setParameter($this, 'mark_read', '1');
2910 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2911
2912 $mark_thr_read_button = ilLinkButton::getInstance();
2913 $mark_thr_read_button->setCaption('forums_mark_read');
2914 $mark_thr_read_button->setUrl($this->ctrl->getLinkTarget($this, 'viewThread'));
2915 $mark_thr_read_button->setAccessKey(ilAccessKey::MARK_ALL_READ);
2916
2917 $bottom_toolbar_split_button_items[] = $mark_thr_read_button;
2918
2919 $this->ctrl->clearParameters($this);
2920 }
2921
2922 // print thread
2923 $this->ctrl->setParameterByClass('ilforumexportgui', 'print_thread', $this->objCurrentTopic->getId());
2924 $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_top_fk', $this->objCurrentTopic->getForumId());
2925
2926 $print_thr_button = ilLinkButton::getInstance();
2927 $print_thr_button->setCaption('forums_print_thread');
2928 $print_thr_button->setUrl($this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printThread'));
2929
2930 $bottom_toolbar_split_button_items[] = $print_thr_button;
2931
2932 $this->ctrl->clearParametersByClass('ilforumexportgui');
2933
2934 $this->addHeaderAction();
2935
2936 if (isset($this->httpRequest->getQueryParams()['mark_read'])) {
2937 $forumObj->markThreadRead($this->user->getId(), (int) $this->objCurrentTopic->getId());
2938 ilUtil::sendInfo($this->lng->txt('forums_thread_marked'), true);
2939 }
2940
2941 $this->objCurrentTopic->setOrderField($orderField);
2942 $subtree_nodes = $this->objCurrentTopic->getPostTree($firstNodeInThread);
2943
2944 if (!$this->isTopLevelReplyCommand() &&
2945 $firstNodeInThread instanceof ilForumPost &&
2946 !$this->objCurrentTopic->isClosed() &&
2947 $this->access->checkAccess('add_reply', '', (int) $_GET['ref_id'])
2948 ) {
2949 $reply_button = ilLinkButton::getInstance();
2950 $reply_button->setPrimary(true);
2951 $reply_button->setCaption('add_new_answer');
2952 $this->ctrl->setParameter($this, 'action', 'showreply');
2953 $this->ctrl->setParameter($this, 'pos_pk', $firstNodeInThread->getId());
2954 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
2955 $this->ctrl->setParameter($this, 'page', (int) $this->httpRequest->getQueryParams()['page']);
2956 $this->ctrl->setParameter(
2957 $this,
2958 'orderby',
2959 \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
2960 );
2961
2962 $reply_button->setUrl($this->ctrl->getLinkTarget($this, 'createTopLevelPost', 'frm_page_bottom'));
2963
2964 $this->ctrl->clearParameters($this);
2965 array_unshift($bottom_toolbar_split_button_items, $reply_button);
2966 }
2967
2968 // no posts
2969 if (!$numberOfPostings = count($subtree_nodes)) {
2970 ilUtil::sendInfo($this->lng->txt('forums_no_posts_available'));
2971 }
2972
2973 $pageSize = $frm->getPageHits();
2974 $postIndex = 0;
2975 if ($numberOfPostings > $pageSize) {
2976 $this->ctrl->setParameter($this, 'ref_id', (int) $this->object->getRefId());
2977 $this->ctrl->setParameter($this, 'thr_pk', (int) $this->objCurrentTopic->getId());
2978 $this->ctrl->setParameter(
2979 $this,
2980 'orderby',
2981 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
2982 );
2983 $paginationUrl = $this->ctrl->getLinkTarget($this, 'viewThread', '', false, false);
2984 $this->ctrl->clearParameters($this);
2985
2986 $pagination = $this->uiFactory->viewControl()
2987 ->pagination()
2988 ->withTargetURL($paginationUrl, 'page')
2989 ->withTotalEntries($numberOfPostings)
2990 ->withPageSize($pageSize)
2991 ->withMaxPaginationButtons(10)
2992 ->withCurrentPage($pageIndex);
2993
2994 $threadContentTemplate->setVariable('THREAD_MENU', $this->uiRenderer->render(
2995 $pagination
2996 ));
2997 $threadContentTemplate->setVariable('THREAD_MENU_BOTTOM', $this->uiRenderer->render(
2998 $pagination
2999 ));
3000 }
3001
3002 $doRenderDrafts = ilForumPostDraft::isSavePostDraftAllowed() && !$this->user->isAnonymous();
3003 $draftsObjects = [];
3004 if ($doRenderDrafts) {
3005 $draftsObjects = ilForumPostDraft::getSortedDrafts(
3006 (int) $this->user->getId(),
3007 (int) $this->objCurrentTopic->getId(),
3008 (int) $currentViewMode
3009 );
3010 }
3011
3012 $pagedPostings = array_slice($subtree_nodes, $pageIndex * $pageSize, $pageSize);
3013
3014 $this->ensureValidPageForCurrentPosting($subtree_nodes, $pagedPostings, $pageSize, $firstNodeInThread);
3015
3016 if (
3017 $doRenderDrafts && 0 === $pageIndex &&
3018 $currentViewMode === ilForumProperties::VIEW_DATE &&
3019 $currentSortation === ilForumProperties::VIEW_DATE_DESC
3020 ) {
3021 foreach ($draftsObjects as $draft) {
3022 $referencePosting = array_values(array_filter(
3023 $subtree_nodes,
3024 static function (ilForumPost $post) use ($draft) : bool {
3025 return $draft->getPostId() == $post->getId();
3026 }
3027 ))[0] ?? $firstNodeInThread;
3028
3029 $this->renderDraftContent(
3030 $threadContentTemplate,
3031 $this->requestAction,
3032 $referencePosting,
3033 [$draft]
3034 );
3035 }
3036 }
3037
3038 foreach ($pagedPostings as $node) {
3039 $this->ctrl->clearParameters($this);
3040
3041 if (!$this->isTopLevelReplyCommand() && $this->objCurrentPost->getId() == $node->getId()) {
3042 if ($this->is_moderator || $node->isActivated() || $node->isOwner($this->user->getId())) {
3043 if (!$this->objCurrentTopic->isClosed() && in_array($this->requestAction, [
3044 'showreply',
3045 'showedit',
3046 ])) {
3047 $this->renderPostingForm($threadContentTemplate, $frm, $node, $this->requestAction);
3048 } elseif (!$this->objCurrentTopic->isClosed() && $this->requestAction === 'delete') {
3049 if (
3050 $this->is_moderator ||
3051 ($node->isOwner($this->user->getId()) && !$node->hasReplies()) &&
3052 !$this->user->isAnonymous()
3053 ) {
3054 $threadContentTemplate->setVariable('FORM', $this->getDeleteFormHTML());
3055 }
3056 } elseif (!$this->objCurrentTopic->isClosed() && $this->requestAction === 'censor') {
3057 if ($this->is_moderator) {
3058 $threadContentTemplate->setVariable('FORM', $this->getCensorshipFormHTML());
3059 }
3060 } elseif (!$this->objCurrentTopic->isClosed() && $this->displayConfirmPostActivation()) {
3061 if ($this->is_moderator) {
3062 $threadContentTemplate->setVariable('FORM', $this->getActivationFormHTML());
3063 }
3064 }
3065 }
3066 }
3067
3068 $this->renderPostContent($threadContentTemplate, $node, $this->requestAction, $pageIndex, $postIndex);
3069 if ($doRenderDrafts && $currentViewMode === ilForumProperties::VIEW_TREE) {
3070 $this->renderDraftContent(
3071 $threadContentTemplate,
3072 $this->requestAction,
3073 $node,
3074 $draftsObjects[$node->getId()] ?? []
3075 );
3076 }
3077
3078 $postIndex++;
3079 }
3080
3081 if (
3082 $doRenderDrafts && $pageIndex === max(0, (int) (ceil($numberOfPostings / $pageSize) - 1)) &&
3083 $currentViewMode === ilForumProperties::VIEW_DATE &&
3084 $currentSortation === ilForumProperties::VIEW_DATE_ASC
3085 ) {
3086 foreach ($draftsObjects as $draft) {
3087 $referencePosting = array_values(array_filter(
3088 $subtree_nodes,
3089 static function (ilForumPost $post) use ($draft) : bool {
3090 return $draft->getPostId() == $post->getId();
3091 }
3092 ))[0] ?? $firstNodeInThread;
3093
3094 $this->renderDraftContent(
3095 $threadContentTemplate,
3096 $this->requestAction,
3097 $referencePosting,
3098 [$draft]
3099 );
3100 }
3101 }
3102
3103 if (
3104 $firstNodeInThread instanceof ilForumPost && $doRenderDrafts &&
3105 $currentViewMode === ilForumProperties::VIEW_TREE
3106 ) {
3107 $this->renderDraftContent(
3108 $threadContentTemplate,
3109 $this->requestAction,
3110 $firstNodeInThread,
3111 $draftsObjects[$firstNodeInThread->getId()] ?? []
3112 );
3113 }
3114
3115 if (
3116 $firstNodeInThread instanceof ilForumPost &&
3117 in_array($this->ctrl->getCmd(), array('createTopLevelPost', 'saveTopLevelPost', 'saveTopLevelDraft')) &&
3118 !$this->objCurrentTopic->isClosed() &&
3119 $this->access->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
3120 // Important: Don't separate the following two lines (very fragile code ...)
3121 $this->objCurrentPost->setId($firstNodeInThread->getId());
3122 $form = $this->getReplyEditForm();
3123
3124 if (in_array($this->ctrl->getCmd(), ['saveTopLevelPost', 'saveTopLevelDraft'])) {
3125 $form->setValuesByPost();
3126 }
3127 $this->ctrl->setParameter($this, 'pos_pk', $firstNodeInThread->getId());
3128 $this->ctrl->setParameter($this, 'thr_pk', $firstNodeInThread->getThreadId());
3129 $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum');
3130 $jsTpl->setVariable(
3131 'IL_FRM_QUOTE_CALLBACK_SRC',
3132 $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true)
3133 );
3134 $this->ctrl->clearParameters($this);
3135 $threadContentTemplate->setVariable('BOTTOM_FORM_ADDITIONAL_JS', $jsTpl->get());
3136 $threadContentTemplate->setVariable('BOTTOM_FORM', $form->getHTML());
3137 }
3138 } else {
3139 $threadContentTemplate->setCurrentBlock('posts_no');
3140 $threadContentTemplate->setVariable(
3141 'TXT_MSG_NO_POSTS_AVAILABLE',
3142 $this->lng->txt('forums_posts_not_available')
3143 );
3144 $threadContentTemplate->parseCurrentBlock();
3145 }
3146
3147 if ($bottom_toolbar_split_button_items) {
3148 $bottom_split_button = ilSplitButtonGUI::getInstance();
3149 $i = 0;
3150 foreach ($bottom_toolbar_split_button_items as $item) {
3151 if ($i == 0) {
3152 $bottom_split_button->setDefaultButton($item);
3153 } else {
3154 $bottom_split_button->addMenuItem(new ilButtonToSplitButtonMenuItemAdapter($item));
3155 }
3156
3157 ++$i;
3158 }
3159 $bottom_toolbar->addStickyItem($bottom_split_button);
3160 $this->toolbar->addStickyItem($bottom_split_button);
3161 }
3162
3163 if ($bottom_toolbar_split_button_items) {
3164 $bottom_toolbar->addSeparator();
3165 }
3166
3167 $to_top_button = ilLinkButton::getInstance();
3168 $to_top_button->setCaption('top_of_page');
3169 $to_top_button->setUrl('#frm_page_top');
3170 $bottom_toolbar->addButtonInstance($to_top_button);
3171 if ($numberOfPostings > 0) {
3172 $threadContentTemplate->setVariable('TOOLBAR_BOTTOM', $bottom_toolbar->getHTML());
3173 }
3174
3175 $this->renderViewModeControl($currentViewMode);
3176 if ($currentViewMode === ilForumProperties::VIEW_DATE) {
3177 $this->renderSortationControl($currentSortation);
3178 }
3179
3180 $this->tpl->setPermanentLink(
3181 $this->object->getType(),
3182 $this->object->getRefId(),
3183 '_' . $this->objCurrentTopic->getId(),
3184 '_top'
3185 );
3186
3187 $this->tpl->addOnLoadCode('$(".ilFrmPostContent img").each(function() {
3188 var $elm = $(this);
3189 $elm.css({
3190 maxWidth: $elm.attr("width") + "px",
3191 maxHeight: $elm.attr("height") + "px"
3192 });
3193 $elm.removeAttr("width");
3194 $elm.removeAttr("height");
3195 });');
3196
3197 $this->tpl->setContent($threadContentTemplate->get());
3198
3199 return true;
3200 }
3201
3202 private function renderViewModeControl(int $currentViewMode) : void
3203 {
3204 $translationKeys = [];
3205 foreach ($this->viewModeOptions as $sortingConstantKey => $languageKey) {
3206 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3207 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
3208 $this->ctrl->setParameter($this, 'viewmode', $sortingConstantKey);
3209
3210 $translationKeys[$this->lng->txt($languageKey)] = $this->ctrl->getLinkTarget(
3211 $this,
3212 'viewThread',
3213 '',
3214 false,
3215 false
3216 );
3217
3218 $this->ctrl->clearParameters($this);
3219 }
3220
3221 $sortViewControl = $this->uiFactory
3222 ->viewControl()
3223 ->mode($translationKeys, $this->lng->txt($this->viewModeOptions[$currentViewMode]))
3224 ->withActive($this->lng->txt($this->viewModeOptions[$currentViewMode]));
3225 $this->toolbar->addComponent($sortViewControl);
3226 }
3227
3228 private function renderSortationControl(int $currentSorting) : void
3229 {
3230 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3231 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
3232 $target = $this->ctrl->getLinkTarget(
3233 $this,
3234 'viewThread',
3235 '',
3236 false,
3237 false
3238 );
3239
3240 $translatedSortationOptions = array_map(function ($value) {
3241 return $this->lng->txt($value);
3242 }, $this->sortationOptions);
3243
3244 $sortingDirectionViewControl = $this->uiFactory
3245 ->viewControl()
3246 ->sortation($translatedSortationOptions)
3247 ->withLabel($this->lng->txt($this->sortationOptions[$currentSorting]))
3248 ->withTargetURL($target, 'viewmode');
3249 $this->toolbar->addComponent($sortingDirectionViewControl);
3250 }
3251
3252 private function getModifiedReOnSubject($on_reply = false)
3253 {
3254 $subject = $this->objCurrentPost->getSubject();
3255 $re_txt = $this->lng->txt('post_reply');
3256
3257 $re_txt_with_num = str_replace(':', '(', $re_txt);
3258 $search_length = strlen($re_txt_with_num);
3259 $comp = substr_compare($re_txt_with_num, substr($subject, 0, $search_length), 0, $search_length);
3260
3261 if ($comp == 0) {
3262 $modified_subject = $subject;
3263 if ($on_reply == true) {
3264 // i.e. $subject = "Re(12):"
3265 $str_pos_start = strpos($subject, '(');
3266 $str_pos_end = strpos($subject, ')');
3267
3268 $length = ((int) $str_pos_end - (int) $str_pos_start);
3269 $str_pos_start++;
3270 $txt_number = substr($subject, $str_pos_start, $length - 1);
3271
3272 if (is_numeric($txt_number)) {
3273 $re_count = (int) $txt_number + 1;
3274 $modified_subject = substr($subject, 0, $str_pos_start) . $re_count . substr(
3275 $subject,
3276 $str_pos_end
3277 );
3278 }
3279 }
3280 } else {
3281 $re_count = substr_count($subject, $re_txt);
3282 if ($re_count >= 1 && $on_reply == true) {
3283 $subject = str_replace($re_txt, '', $subject);
3284
3285 // i.e. $subject = "Re: Re: Re: ... " -> "Re(4):"
3286 $re_count++;
3287 $modified_subject = sprintf($this->lng->txt('post_reply_count'), $re_count) . ' ' . trim($subject);
3288 } elseif ($re_count >= 1 && $on_reply == false) {
3289 // possibility to modify the subject only for output
3290 // i.e. $subject = "Re: Re: Re: ... " -> "Re(3):"
3291 $modified_subject = sprintf($this->lng->txt('post_reply_count'), $re_count) . ' ' . trim($subject);
3292 } elseif ($re_count == 0) {
3293 // the first reply to a thread
3294 $modified_subject = $this->lng->txt('post_reply') . ' ' . $this->objCurrentPost->getSubject();
3295 }
3296 }
3297 return $modified_subject;
3298 }
3299
3300 public function showUserObject()
3301 {
3302 $profile_gui = new ilPublicUserProfileGUI((int) $_GET['user']);
3303 $add = $this->getUserProfileAdditional((int) $_GET['ref_id'], (int) $_GET['user']);
3304 $profile_gui->setAdditional($add);
3305 $profile_gui->setBackUrl(\ilUtil::stripSlashes($_GET['backurl']));
3306 $this->tpl->setContent($this->ctrl->getHTML($profile_gui));
3307 }
3308
3309 protected function getUserProfileAdditional($a_forum_ref_id, $a_user_id)
3310 {
3311 if (!$this->access->checkAccess('read', '', $a_forum_ref_id)) {
3312 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3313 }
3314
3318 $ref_obj = ilObjectFactory::getInstanceByRefId($a_forum_ref_id);
3319 if ($ref_obj->getType() == 'frm') {
3320 $forumObj = new ilObjForum($a_forum_ref_id);
3321 $frm = $forumObj->Forum;
3322 $frm->setForumId($forumObj->getId());
3323 $frm->setForumRefId($forumObj->getRefId());
3324 } else {
3325 $frm = new ilForum();
3326 }
3327
3328 // count articles of user
3329 if ($this->access->checkAccess('moderate_frm', '', $a_forum_ref_id)) {
3330 $numPosts = $frm->countUserArticles(addslashes($a_user_id));
3331 } else {
3332 $numPosts = $frm->countActiveUserArticles(addslashes($a_user_id));
3333 }
3334
3335 return array($this->lng->txt('forums_posts') => $numPosts);
3336 }
3337
3339 {
3340 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3341 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3342 }
3343
3344 unset($_SESSION['threads2move']);
3345
3346 if (isset($_POST['thread_ids']) && is_array($_POST['thread_ids'])) {
3347 if (isset($_POST['selected_cmd']) && $_POST['selected_cmd'] == 'move') {
3348 if ($this->is_moderator) {
3349 $_SESSION['threads2move'] = $_POST['thread_ids'];
3350 $this->moveThreadsObject();
3351 }
3352 } elseif ($_POST['selected_cmd'] == 'enable_notifications' && $this->settings->get('forum_notification') != 0) {
3353 for ($i = 0; $i < count($_POST['thread_ids']); $i++) {
3354 $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3355 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $tmp_obj);
3356 $tmp_obj->enableNotification($this->user->getId());
3357 }
3358
3359 $this->ctrl->redirect($this, 'showThreads');
3360 } elseif ($_POST['selected_cmd'] == 'disable_notifications' && $this->settings->get('forum_notification') != 0) {
3361 for ($i = 0; $i < count($_POST['thread_ids']); $i++) {
3362 $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3363 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $tmp_obj);
3364 $tmp_obj->disableNotification($this->user->getId());
3365 }
3366
3367 $this->ctrl->redirect($this, 'showThreads');
3368 } elseif ($_POST['selected_cmd'] == 'close') {
3369 if ($this->is_moderator) {
3370 for ($i = 0; $i < count($_POST['thread_ids']); $i++) {
3371 $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3372 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $tmp_obj);
3373 $tmp_obj->close();
3374 }
3375 }
3376 ilUtil::sendSuccess($this->lng->txt('selected_threads_closed'), true);
3377 $this->ctrl->redirect($this, 'showThreads');
3378 } elseif ($_POST['selected_cmd'] == 'reopen') {
3379 if ($this->is_moderator) {
3380 for ($i = 0; $i < count($_POST['thread_ids']); $i++) {
3381 $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3382 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $tmp_obj);
3383 $tmp_obj->reopen();
3384 }
3385 }
3386
3387 ilUtil::sendSuccess($this->lng->txt('selected_threads_reopened'), true);
3388 $this->ctrl->redirect($this, 'showThreads');
3389 } elseif ($_POST['selected_cmd'] == 'makesticky') {
3390 if ($this->is_moderator) {
3391 $message = $this->lng->txt('sel_threads_make_sticky');
3392
3393 for ($i = 0; $i < count($_POST['thread_ids']); $i++) {
3394 $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3395 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $tmp_obj);
3396 $makeSticky = $tmp_obj->makeSticky();
3397
3398 if (!$makeSticky) {
3399 $message = $this->lng->txt('sel_threads_already_sticky');
3400 }
3401 }
3402 }
3403 if ($message != null) {
3405 }
3406 $this->ctrl->redirect($this, 'showThreads');
3407 } elseif ($_POST['selected_cmd'] == 'unmakesticky') {
3408 if ($this->is_moderator) {
3409 $message = $this->lng->txt('sel_threads_make_unsticky');
3410 for ($i = 0; $i < count($_POST['thread_ids']); $i++) {
3411 $tmp_obj = new ilForumTopic($_POST['thread_ids'][$i]);
3412 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $tmp_obj);
3413 $unmakeSticky = $tmp_obj->unmakeSticky();
3414 if (!$unmakeSticky) {
3415 $message = $this->lng->txt('sel_threads_already_unsticky');
3416 }
3417 }
3418 }
3419
3420 if ($message != null) {
3422 }
3423 $this->ctrl->redirect($this, 'showThreads');
3424 } elseif ($_POST['selected_cmd'] == 'editThread') {
3425 if ($this->is_moderator) {
3426 $count = count($_POST['thread_ids']);
3427 if ($count != 1) {
3428 ilUtil::sendInfo($this->lng->txt('select_max_one_thread'), true);
3429 $this->ctrl->redirect($this, 'showThreads');
3430 } else {
3431 foreach ($_POST['thread_ids'] as $thread_id) {
3432 return $this->editThreadObject($thread_id, null);
3433 }
3434 }
3435 }
3436
3437 $this->ctrl->redirect($this, 'showThreads');
3438 } elseif ($_POST['selected_cmd'] == 'html') {
3439 $this->ctrl->setCmd('exportHTML');
3440 $this->ctrl->setCmdClass('ilForumExportGUI');
3441 $this->executeCommand();
3442 } elseif ($_POST['selected_cmd'] == 'confirmDeleteThreads') {
3443 $this->confirmDeleteThreads();
3444 } elseif ($_POST['selected_cmd'] == 'merge') {
3445 $this->mergeThreadsObject();
3446 } else {
3447 ilUtil::sendInfo($this->lng->txt('topics_please_select_one_action'), true);
3448 $this->ctrl->redirect($this, 'showThreads');
3449 }
3450 } else {
3451 ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3452 $this->ctrl->redirect($this, 'showThreads');
3453 }
3454 }
3455
3457 {
3458 if (!$this->is_moderator) {
3459 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3460 }
3461
3462 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3463 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3464 }
3465
3466
3467 $threads2move = $_SESSION['threads2move'];
3468 if (!is_array($threads2move) || !count($threads2move)) {
3469 ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3470 $this->ctrl->redirect($this, 'showThreads');
3471 }
3472
3473 if (!$this->access->checkAccess('read', '', (int) $_POST['frm_ref_id'])) {
3474 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3475 }
3476
3477 $threads = [];
3478 array_walk($threads2move, function ($threadId) use (&$threads) {
3479 $thread = new \ilForumTopic($threadId);
3480 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $thread);
3481
3482 $threads[] = $threadId;
3483 });
3484
3485 if (isset($_POST['frm_ref_id']) && (int) $_POST['frm_ref_id']) {
3486 $errorMessages = $this->object->Forum->moveThreads(
3487 (array) $_SESSION['threads2move'],
3488 $this->object->getRefId(),
3489 $this->ilObjDataCache->lookupObjId($_POST['frm_ref_id'])
3490 );
3491
3492 if (array() !== $errorMessages) {
3494 implode("<br><br>", $errorMessages),
3495 true
3496 );
3497 return $this->ctrl->redirectByClass('ilObjForumGUI', 'showThreads');
3498 }
3499
3500 unset($_SESSION['threads2move']);
3501 ilUtil::sendInfo($this->lng->txt('threads_moved_successfully'), true);
3502 $this->ctrl->redirect($this, 'showThreads');
3503 } else {
3504 ilUtil::sendInfo($this->lng->txt('no_forum_selected'));
3505 $this->moveThreadsObject();
3506 }
3507 }
3508
3509 public function cancelMoveThreadsObject()
3510 {
3511 unset($_SESSION['threads2move']);
3512 $this->ctrl->redirect($this, 'showThreads');
3513 }
3514
3515 public function moveThreadsObject()
3516 {
3517 if (!$this->is_moderator) {
3518 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3519 }
3520
3521 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3522 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3523 }
3524
3525 $threads2move = $_SESSION['threads2move'];
3526 if (!is_array($threads2move) || !count($threads2move)) {
3527 ilUtil::sendInfo($this->lng->txt('select_at_least_one_thread'), true);
3528 $this->ctrl->redirect($this, 'showThreads');
3529 }
3530
3531 $threads = [];
3532 $isModerator = $this->is_moderator;
3533 array_walk($threads2move, function ($threadId) use (&$threads, $isModerator) {
3534 $thread = new \ilForumTopic($threadId, $isModerator);
3535 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $thread);
3536
3537 $threads[] = $thread;
3538 });
3539
3540 $exp = new ilForumMoveTopicsExplorer($this, 'moveThreads');
3541 $exp->setPathOpen($this->object->getRefId());
3542 $exp->setNodeSelected(isset($_POST['frm_ref_id']) && (int) $_POST['frm_ref_id'] ? (int) $_POST['frm_ref_id'] : 0);
3543 $exp->setCurrentFrmRefId($this->object->getRefId());
3544 $exp->setHighlightedNode($this->object->getRefId());
3545 if (!$exp->handleCommand()) {
3546 $moveThreadTemplate = new ilTemplate(
3547 'tpl.forums_threads_move.html',
3548 true,
3549 true,
3550 'Modules/Forum'
3551 );
3552
3553 if (!$this->hideToolbar()) {
3554 $this->toolbar->addButton($this->lng->txt('back'), $this->ctrl->getLinkTarget($this));
3555 }
3556
3557 $tblThr = new ilTable2GUI($this);
3558 $tblThr->setId('il_frm_thread_move_table_' . $this->object->getRefId());
3559 $tblThr->setTitle($this->lng->txt('move_chosen_topics'));
3560 $tblThr->addColumn($this->lng->txt('subject'), 'top_name', '100%');
3561 $tblThr->disable('header');
3562 $tblThr->disable('footer');
3563 $tblThr->disable('linkbar');
3564 $tblThr->disable('sort');
3565 $tblThr->disable('linkbar');
3566 $tblThr->setLimit(PHP_INT_MAX);
3567 $tblThr->setRowTemplate('tpl.forums_threads_move_thr_row.html', 'Modules/Forum');
3568 $tblThr->setDefaultOrderField('is_sticky');
3569 $counter = 0;
3570 $result = array();
3571 foreach ($threads as $thread) {
3572 $result[$counter]['num'] = $counter + 1;
3573 $result[$counter]['thr_subject'] = $thread->getSubject();
3574 ++$counter;
3575 }
3576 $tblThr->setData($result);
3577 $moveThreadTemplate->setVariable('THREADS_TABLE', $tblThr->getHTML());
3578
3579 $moveThreadTemplate->setVariable('FRM_SELECTION_TREE', $exp->getHTML());
3580 $moveThreadTemplate->setVariable('CMD_SUBMIT', 'performMoveThreads');
3581 $moveThreadTemplate->setVariable('TXT_SUBMIT', $this->lng->txt('move'));
3582 $moveThreadTemplate->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'performMoveThreads'));
3583
3584 $this->tpl->setContent($moveThreadTemplate->get());
3585 }
3586
3587 return true;
3588 }
3589
3590 private function isWritingWithPseudonymAllowed() : bool
3591 {
3592 if ($this->objProperties->isAnonymized() && (!$this->is_moderator || !$this->objProperties->getMarkModeratorPosts())) {
3593 return true;
3594 }
3595 return false;
3596 }
3597
3598 protected function deleteThreadDraftsObject()
3599 {
3600 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3601 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3602 }
3603
3604 $draftIds = array_filter((array) ($this->httpRequest->getParsedBody()['draft_ids'] ?? []));
3605 if (0 === count($draftIds)) {
3606 $draftIds = array_filter([(int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0)]);
3607 }
3608
3609 $instances = \ilForumPostDraft::getDraftInstancesByUserId($this->user->getId());
3610 $checkedDraftIds = [];
3611 foreach ($draftIds as $draftId) {
3612 if (array_key_exists($draftId, $instances)) {
3613 $checkedDraftIds[] = $draftId;
3614 $draft = $instances[$draftId];
3615
3616 $this->deleteMobsOfDraft($draft->getDraftId(), $draft->getPostMessage());
3617
3618 $draftFileData = new \ilFileDataForumDrafts(0, $draft->getDraftId());
3619 $draftFileData->delete();
3620
3621 $GLOBALS['ilAppEventHandler']->raise(
3622 'Modules/Forum',
3623 'deletedDraft',
3624 [
3625 'draftObj' => $draft,
3626 'obj_id' => $this->object->getId(),
3627 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed(),
3628 ]
3629 );
3630
3631 $draft->deleteDraft();
3632 }
3633 }
3634
3635 if (count($checkedDraftIds) > 1) {
3636 \ilUtil::sendInfo($this->lng->txt('delete_drafts_successfully'), true);
3637 } else {
3638 \ilUtil::sendInfo($this->lng->txt('delete_draft_successfully'), true);
3639 }
3640 $this->ctrl->redirect($this, 'showThreads');
3641 }
3642
3647 private function buildThreadForm($isDraft = false) : \ilPropertyFormGUI
3648 {
3649 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
3650 $allowNotification = !$this->objProperties->isAnonymized();
3651
3652 $mail = new \ilMail($this->user->getId());
3653 if (!$this->rbac->system()->checkAccess('internal_mail', $mail->getMailObjectReferenceId())) {
3654 $allowNotification = false;
3655 }
3656
3657 $form = new \ilForumThreadFormGUI(
3658 $this,
3659 $this->objProperties,
3660 $this->isWritingWithPseudonymAllowed(),
3661 $allowNotification,
3662 $isDraft,
3663 $draftId
3664 );
3665
3666 $this->decorateWithAutosave($form);
3667
3668 return $form;
3669 }
3670
3671 protected function createThreadObject()
3672 {
3673 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3674 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3675 }
3676
3677 if (!$this->access->checkAccess('add_thread', '', $this->object->getRefId())) {
3678 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3679 }
3680
3681 $templateForWidthHandling = new \ilTemplate('tpl.create_thread_form.html', true, true, 'Modules/Forum');
3682 $templateForWidthHandling->setVariable('CREATE_FORM', $this->buildThreadForm()->getHTML());
3683 $templateForWidthHandling->parseCurrentBlock();
3684
3685 $this->tpl->setContent($templateForWidthHandling->get());
3686 }
3687
3693 private function createThread(\ilForumPostDraft $draft, bool $createFromDraft = false)
3694 {
3695 if (
3696 !$this->access->checkAccess('add_thread', '', $this->object->getRefId()) ||
3697 !$this->access->checkAccess('read', '', $this->object->getRefId())
3698 ) {
3699 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3700 }
3701
3702 $frm = $this->object->Forum;
3703 $frm->setForumId($this->object->getId());
3704 $frm->setForumRefId($this->object->getRefId());
3705 $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
3706 $topicData = $frm->getOneTopic();
3707
3708 $form = $this->buildThreadForm($createFromDraft);
3709 if ($form->checkInput()) {
3710 $this->doCaptchaCheck();
3711
3712 $userIdForDisplayPurposes = $this->user->getId();
3713 if ($this->isWritingWithPseudonymAllowed()) {
3714 $userIdForDisplayPurposes = 0;
3715 }
3716
3717 $status = 1;
3718 if (
3719 ($this->objProperties->isPostActivationEnabled() && !$this->is_moderator) ||
3720 $this->objCurrentPost->isAnyParentDeactivated()
3721 ) {
3722 $status = 0;
3723 }
3724
3725 if ($createFromDraft) {
3726 $newThread = new \ilForumTopic(0, true, true);
3727 $newThread->setForumId($topicData['top_pk']);
3728 $newThread->setThrAuthorId($draft->getPostAuthorId());
3729 $newThread->setDisplayUserId($draft->getPostDisplayUserId());
3730 $newThread->setSubject($this->handleFormInput($form->getInput('subject'), false));
3731 $newThread->setUserAlias($draft->getPostUserAlias());
3732
3733 $newPost = $frm->generateThread(
3734 $newThread,
3735 \ilRTE::_replaceMediaObjectImageSrc($form->getInput('message'), 0),
3736 $draft->getNotify(),
3737 $draft->getPostNotify(),
3738 $status
3739 );
3740 } else {
3742 $form->getInput('alias'),
3743 $this->objProperties->isAnonymized()
3744 );
3745 $newThread = new \ilForumTopic(0, true, true);
3746 $newThread->setForumId($topicData['top_pk']);
3747 $newThread->setThrAuthorId($this->user->getId());
3748 $newThread->setDisplayUserId($userIdForDisplayPurposes);
3749 $newThread->setSubject($this->handleFormInput($form->getInput('subject'), false));
3750 $newThread->setUserAlias($userAlias);
3751
3752 $newPost = $frm->generateThread(
3753 $newThread,
3754 \ilRTE::_replaceMediaObjectImageSrc($form->getInput('message'), 0),
3755 $form->getItemByPostVar('notify') ? (int) $form->getInput('notify') : 0,
3756 0, // #19980
3757 $status
3758 );
3759 }
3760
3761 if ($this->objProperties->isFileUploadAllowed()) {
3762 $file = $_FILES['userfile'];
3763 if (is_array($file) && !empty($file)) {
3764 $fileData = new \ilFileDataForum($this->object->getId(), $newPost);
3765 $fileData->storeUploadedFile($file);
3766 }
3767 }
3768
3769 $frm->setDbTable('frm_data');
3770 $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk']));
3771 $frm->updateVisits($topicData['top_pk']);
3772
3773 if ($createFromDraft) {
3774 $mediaObjects = \ilObjMediaObject::_getMobsOfObject('frm~:html', $this->user->getId());
3775 } else {
3776 $mediaObjects = \ilRTE::_getMediaObjects($form->getInput('message'), 0);
3777 }
3778 foreach ($mediaObjects as $mob) {
3779 if (\ilObjMediaObject::_exists($mob)) {
3780 \ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->user->getId());
3781 \ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
3782 }
3783 }
3784
3785 if ($draft->getDraftId() > 0) {
3786 $draftHistory = new \ilForumDraftsHistory();
3787 $draftHistory->deleteHistoryByDraftIds([$draft->getDraftId()]);
3788 if ($this->objProperties->isFileUploadAllowed()) {
3789 $forumFileData = new \ilFileDataForum($this->object->getId(), $newPost);
3790 $draftFileData = new \ilFileDataForumDrafts($this->object->getId(), $draft->getDraftId());
3791 $draftFileData->moveFilesOfDraft($forumFileData->getForumPath(), $newPost);
3792 }
3793 $draft->deleteDraft();
3794 }
3795
3796 $GLOBALS['ilAppEventHandler']->raise(
3797 'Modules/Forum',
3798 'createdPost',
3799 [
3800 'ref_id' => $this->object->getRefId(),
3801 'post' => new \ilForumPost($newPost),
3802 'notify_moderators' => !$status
3803 ]
3804 );
3805
3806 \ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true);
3807 $this->ctrl->redirect($this);
3808 }
3809
3810 $form->setValuesByPost();
3811 if (!$this->objProperties->isAnonymized()) {
3812 $form->getItemByPostVar('alias')->setValue($this->user->getLogin());
3813 }
3814
3815 $this->tpl->setContent($form->getHTML());
3816 }
3817
3818 protected function publishThreadDraftObject()
3819 {
3821 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3822 }
3823
3824 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
3825 $draft = \ilForumPostDraft::newInstanceByDraftId($draftId);
3826
3827 if ((int) $draft->getDraftId() <= 0) {
3828 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3829 }
3830
3831 $this->createThread($draft, true);
3832 }
3833
3834 protected function addThreadObject()
3835 {
3836 $draft = new \ilForumPostDraft();
3838 $draftId = (int) ($this->httpRequest->getParsedBody()['draft_id'] ?? 0);
3839 if ($draftId > 0) {
3840 $draft = \ilForumPostDraft::newInstanceByDraftId($draftId);
3841 }
3842 }
3843
3844 $this->createThread($draft, false);
3845 }
3846
3848 {
3849 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3850 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3851 }
3852
3853 $frm = $this->object->Forum;
3854 $frm->setForumId($this->object->getId());
3855 $frm->enableForumNotification($this->user->getId());
3856
3857 if ((int) $this->objCurrentTopic->getId() > 0) {
3858 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3859 \ilUtil::sendInfo($this->lng->txt('forums_forum_notification_enabled'), true);
3860 $this->ctrl->redirect($this, 'viewThread');
3861 }
3862
3863 \ilUtil::sendInfo($this->lng->txt('forums_forum_notification_enabled'));
3864 $this->showThreadsObject();
3865 }
3866
3868 {
3869 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3870 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3871 }
3872
3873 $frm = $this->object->Forum;
3874 $frm->setForumId($this->object->getId());
3875 $frm->disableForumNotification($this->user->getId());
3876
3877 if ((int) $this->objCurrentTopic->getId() > 0) {
3878 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
3879 \ilUtil::sendInfo($this->lng->txt('forums_forum_notification_disabled'), true);
3880 $this->ctrl->redirect($this, 'viewThread');
3881 }
3882
3883 \ilUtil::sendInfo($this->lng->txt('forums_forum_notification_disabled'));
3884 $this->showThreadsObject();
3885 }
3886
3890 protected function setColumnSettings(ilColumnGUI $column_gui)
3891 {
3892 $column_gui->setBlockProperty('news', 'title', $this->lng->txt('frm_latest_postings'));
3893 $column_gui->setBlockProperty('news', 'prevent_aggregation', true);
3894 $column_gui->setRepositoryMode(true);
3895
3896 if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
3897 $news_set = new \ilSetting('news');
3898 if ($news_set->get('enable_rss_for_internal')) {
3899 $column_gui->setBlockProperty('news', 'settings', true);
3900 $column_gui->setBlockProperty('news', 'public_notifications_option', true);
3901 }
3902 }
3903 }
3904
3908 protected function addLocatorItems()
3909 {
3910 if ($this->object instanceof \ilObjForum) {
3911 $this->locator->addItem(
3912 $this->object->getTitle(),
3913 $this->ctrl->getLinkTarget($this),
3914 '',
3915 $this->object->getRefId()
3916 );
3917 }
3918 }
3919
3920 public function handleFormInput($a_text, $a_stripslashes = true)
3921 {
3922 $a_text = str_replace("<", "&lt;", $a_text);
3923 $a_text = str_replace(">", "&gt;", $a_text);
3924 if ($a_stripslashes) {
3925 $a_text = ilUtil::stripSlashes($a_text);
3926 }
3927
3928 return $a_text;
3929 }
3930
3931 public function prepareFormOutput($a_text)
3932 {
3933 $a_text = str_replace("&lt;", "<", $a_text);
3934 $a_text = str_replace("&gt;", ">", $a_text);
3935 $a_text = ilUtil::prepareFormOutput($a_text);
3936 return $a_text;
3937 }
3938
3939 protected function infoScreen()
3940 {
3941 if (
3942 !$this->access->checkAccess('visible', '', $this->object->getRefId()) &&
3943 !$this->access->checkAccess('read', '', $this->object->getRefId())
3944 ) {
3945 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
3946 }
3947
3948 $info = new \ilInfoScreenGUI($this);
3949 $info->enablePrivateNotes();
3950 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
3951 $this->ctrl->forwardCommand($info);
3952 }
3953
3957 protected function markPostUnreadObject()
3958 {
3959 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3960 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3961 }
3962
3963 if ((int) $this->objCurrentPost->getId() > 0) {
3964 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
3965
3966 $this->object->markPostUnread($this->user->getId(), (int) $this->objCurrentPost->getId());
3967 }
3968 $this->viewThreadObject();
3969 }
3970
3974 protected function markPostReadObject()
3975 {
3976 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
3977 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
3978 }
3979
3980 if ((int) $this->objCurrentTopic->getId() > 0 && (int) $this->objCurrentPost->getId() > 0) {
3981 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
3982
3983 $this->object->markPostRead(
3984 $this->user->getId(),
3985 (int) $this->objCurrentTopic->getId(),
3986 (int) $this->objCurrentPost->getId()
3987 );
3988 }
3989 $this->viewThreadObject();
3990 }
3991
3995 protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
3996 {
3997 $lg = parent::initHeaderAction();
3998
3999 if ((int) $this->objCurrentTopic->getId() > 0) {
4000 $container_obj = null; // Workaround: Do not show "desktop actions" in thread view
4001 $lg->setContainerObject($container_obj);
4002 }
4003
4004 if (!($lg instanceof \ilObjForumListGUI) || !$this->settings->get('forum_notification')) {
4005 return $lg;
4006 }
4007
4008 if ($this->user->isAnonymous() || !$this->access->checkAccess('read', '', $this->object->getRefId())) {
4009 return $lg;
4010 }
4011
4012 $frm = $this->object->Forum;
4013 $frm->setForumId($this->object->getId());
4014 $frm->setForumRefId($this->object->getRefId());
4015 $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4016
4017 $isForumNotificationEnabled = $frm->isForumNotificationEnabled($this->user->getId());
4018 $userMayDisableNotifications = $this->isUserAllowedToDeactivateNotification();
4019
4020 if ((int) $this->objCurrentTopic->getId() > 0) {
4021 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
4022 }
4023
4024 if ($this->isParentObjectCrsOrGrp()) {
4025 // special behaviour for CRS/GRP-Forum notification!!
4026 if ($isForumNotificationEnabled && $userMayDisableNotifications) {
4027 $lg->addCustomCommand(
4028 $this->ctrl->getLinkTarget($this, 'disableForumNotification'),
4029 'forums_disable_forum_notification'
4030 );
4031 } elseif (!$isForumNotificationEnabled) {
4032 $lg->addCustomCommand(
4033 $this->ctrl->getLinkTarget($this, 'enableForumNotification'),
4034 'forums_enable_forum_notification'
4035 );
4036 }
4037 } elseif ($isForumNotificationEnabled) {
4038 $lg->addCustomCommand(
4039 $this->ctrl->getLinkTarget($this, 'disableForumNotification'),
4040 'forums_disable_forum_notification'
4041 );
4042 } else {
4043 $lg->addCustomCommand(
4044 $this->ctrl->getLinkTarget($this, 'enableForumNotification'),
4045 'forums_enable_forum_notification'
4046 );
4047 }
4048
4049 $isThreadNotificationEnabled = false;
4050 if ((int) $this->objCurrentTopic->getId() > 0) {
4051 $isThreadNotificationEnabled = $this->objCurrentTopic->isNotificationEnabled($this->user->getId());
4052 if ($isThreadNotificationEnabled) {
4053 $lg->addCustomCommand(
4054 $this->ctrl->getLinkTarget($this, 'toggleThreadNotification'),
4055 'forums_disable_notification'
4056 );
4057 } else {
4058 $lg->addCustomCommand(
4059 $this->ctrl->getLinkTarget($this, 'toggleThreadNotification'),
4060 'forums_enable_notification'
4061 );
4062 }
4063 }
4064 $this->ctrl->setParameter($this, 'thr_pk', '');
4065
4066 if ($isForumNotificationEnabled || $isThreadNotificationEnabled) {
4067 $lg->addHeaderIcon(
4068 'not_icon',
4069 ilUtil::getImagePath('notification_on.svg'),
4070 $this->lng->txt('frm_notification_activated')
4071 );
4072 } else {
4073 $lg->addHeaderIcon(
4074 'not_icon',
4075 ilUtil::getImagePath('notification_off.svg'),
4076 $this->lng->txt('frm_notification_deactivated')
4077 );
4078 }
4079
4080 return $lg;
4081 }
4082
4084 {
4085 if ($this->objProperties->getNotificationType() == 'default') {
4086 return true;
4087 }
4088
4089 if ($this->objProperties->isUserToggleNoti() == 0) {
4090 return true;
4091 }
4092
4093 if ($this->isParentObjectCrsOrGrp()) {
4094 $frm_noti = new ilForumNotification((int) $_GET['ref_id']);
4095 $frm_noti->setUserId($this->user->getId());
4096
4097 $user_toggle = (int) $frm_noti->isUserToggleNotification();
4098 if ($user_toggle == 0 && $this->objProperties->isUserToggleNoti() == 0) {
4099 return true;
4100 }
4101 }
4102
4103 return false;
4104 }
4105
4106 public function isParentObjectCrsOrGrp() : bool
4107 {
4108 $grpRefId = $this->repositoryTree->checkForParentType($this->object->getRefId(), 'grp');
4109 $crsRefId = $this->repositoryTree->checkForParentType($this->object->getRefId(), 'crs');
4110
4111 return ($grpRefId > 0 || $crsRefId > 0);
4112 }
4113
4114 protected function saveThreadSortingObject()
4115 {
4116 if (!$this->is_moderator) {
4117 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4118 }
4119
4120 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
4121 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4122 }
4123
4124 $threadIdToSortValueMap = (array) ($this->httpRequest->getParsedBody()['thread_sorting'] ?? []);
4125
4126 array_walk($threadIdToSortValueMap, function ($sortValue, $threadId) {
4127 $this->ensureThreadBelongsToForum((int) $this->object->getId(), new \ilForumTopic($threadId));
4128 });
4129
4130 foreach ($threadIdToSortValueMap as $threadId => $sortValue) {
4131 $sortValue = str_replace(',', '.', $sortValue);
4132 $sortValue = (float) $sortValue * 100;
4133 $this->object->setThreadSorting((int) $threadId, $sortValue);
4134 }
4135
4136 \ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
4137 $this->ctrl->redirect($this, 'showThreads');
4138 }
4139
4143 public function mergeThreadsObject()
4144 {
4145 if (!$this->is_moderator) {
4146 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4147 }
4148
4149 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
4150 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4151 }
4152
4153 $threadIdToMerge = (int) ($this->httpRequest->getQueryParams()['merge_thread_id'] ?? 0);
4154 if (!($threadIdToMerge > 0)) {
4155 $threadIds = array_values(
4156 array_filter(array_map('intval', (array) $this->httpRequest->getParsedBody()['thread_ids'] ?? []))
4157 );
4158 if (1 === count($threadIds)) {
4159 $threadIdToMerge = current($threadIds);
4160 } else {
4161 \ilUtil::sendInfo($this->lng->txt('select_one'));
4162 $this->showThreadsObject();
4163 return;
4164 }
4165 }
4166
4167 $frm = $this->object->Forum;
4168 $frm->setForumId($this->object->getId());
4169 $frm->setForumRefId($this->object->getRefId());
4170
4171 $threadToMerge = new ilForumTopic($threadIdToMerge);
4172
4173 if (\ilForum::_lookupObjIdForForumId($threadToMerge->getForumId()) != $frm->getForumId()) {
4174 \ilUtil::sendFailure($this->lng->txt('not_allowed_to_merge_into_another_forum'));
4175 $this->showThreadsObject();
4176 return;
4177 }
4178
4179 $frm->setMDB2Wherecondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4180
4181 $threadsTemplate = new \ilTemplate(
4182 'tpl.forums_threads_liste.html',
4183 true,
4184 true,
4185 'Modules/Forum'
4186 );
4187
4188 $topicData = $frm->getOneTopic();
4189 if ($topicData) {
4190 $this->ctrl->setParameter($this, 'merge_thread_id', $threadIdToMerge);
4191 $tbl = new \ilForumTopicTableGUI(
4192 $this,
4193 'mergeThreads',
4194 '',
4195 (int) $this->httpRequest->getQueryParams()['ref_id'],
4196 $topicData,
4197 $this->is_moderator,
4198 $this->settings->get('forum_overview')
4199 );
4200 $tbl->setSelectedThread($threadToMerge);
4201 $tbl->setMapper($frm)->fetchData();
4202 $tbl->init();
4203 $threadsTemplate->setVariable('THREADS_TABLE', $tbl->getHTML());
4204 $this->tpl->setContent($threadsTemplate->get());
4205 } else {
4206 \ilUtil::sendFailure($this->lng->txt('select_one'));
4207 $this->showThreadsObject();
4208 }
4209 }
4210
4215 {
4216 if (!$this->is_moderator) {
4217 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4218 }
4219
4220 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
4221 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4222 }
4223
4224 $sourceThreadId = (int) ($this->httpRequest->getQueryParams()['merge_thread_id'] ?? 0);
4225 $targetThreadIds = array_values(
4226 array_filter(array_map('intval', (array) $this->httpRequest->getParsedBody()['thread_ids'] ?? []))
4227 );
4228
4229 if (!($sourceThreadId > 0) || 1 !== count($targetThreadIds)) {
4230 \ilUtil::sendFailure($this->lng->txt('select_one'));
4231 $this->mergeThreadsObject();
4232 return;
4233 }
4234
4235 $targetThreadId = current($targetThreadIds);
4236 if ($sourceThreadId == $targetThreadId) {
4237 \ilUtil::sendFailure($this->lng->txt('error_same_thread_ids'));
4238 $this->showThreadsObject();
4239 return;
4240 }
4241
4242 if (ilForumTopic::lookupForumIdByTopicId($sourceThreadId) != ilForumTopic::lookupForumIdByTopicId($targetThreadId)) {
4243 \ilUtil::sendFailure($this->lng->txt('not_allowed_to_merge_into_another_forum'));
4244 $this->ctrl->clearParameters($this);
4245 $this->showThreadsObject();
4246 return;
4247 }
4248
4249 if (\ilForumTopic::_lookupDate($sourceThreadId) < ilForumTopic::_lookupDate($targetThreadId)) {
4250 \ilUtil::sendInfo($this->lng->txt('switch_threads_for_merge'));
4251 }
4252
4253 $this->ensureThreadBelongsToForum((int) $this->object->getId(), new \ilForumTopic((int) $sourceThreadId));
4254 $this->ensureThreadBelongsToForum((int) $this->object->getId(), new \ilForumTopic((int) $targetThreadId));
4255
4256 $c_gui = new ilConfirmationGUI();
4257
4258 $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performMergeThreads'));
4259 $c_gui->setHeaderText($this->lng->txt('frm_sure_merge_threads'));
4260 $c_gui->setCancel($this->lng->txt('cancel'), 'showThreads');
4261 $c_gui->setConfirm($this->lng->txt('confirm'), 'performMergeThreads');
4262
4263 $c_gui->addItem(
4264 'thread_ids[]',
4265 $sourceThreadId,
4266 sprintf($this->lng->txt('frm_merge_src'), ilForumTopic::_lookupTitle($sourceThreadId))
4267 );
4268 $c_gui->addItem(
4269 'thread_ids[]',
4270 $targetThreadId,
4271 sprintf($this->lng->txt('frm_merge_target'), ilForumTopic::_lookupTitle($targetThreadId))
4272 );
4273 $this->tpl->setContent($c_gui->getHTML());
4274 }
4275
4280 {
4281 if (!$this->is_moderator) {
4282 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4283 }
4284
4285 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
4286 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4287 }
4288
4289 $threadIds = array_values(
4290 array_filter(array_map('intval', (array) $this->httpRequest->getParsedBody()['thread_ids'] ?? []))
4291 );
4292 if (2 !== count($threadIds)) {
4293 ilUtil::sendFailure($this->lng->txt('select_one'));
4294 $this->showThreadsObject();
4295 return;
4296 }
4297
4298 if ((int) $threadIds[0] === (int) $threadIds[1]) {
4299 ilUtil::sendFailure($this->lng->txt('error_same_thread_ids'));
4300 $this->showThreadsObject();
4301 return;
4302 }
4303
4304 try {
4305 $frm = new \ilForum();
4306 $frm->setForumId($this->object->getId());
4307 $frm->setForumRefId($this->object->getRefId());
4308
4309 $this->ensureThreadBelongsToForum((int) $this->object->getId(), new \ilForumTopic((int) $threadIds[0]));
4310 $this->ensureThreadBelongsToForum((int) $this->object->getId(), new \ilForumTopic((int) $threadIds[1]));
4311
4312 $frm->mergeThreads((int) $threadIds[0], (int) $threadIds[1]);
4313 \ilUtil::sendSuccess($this->lng->txt('merged_threads_successfully'));
4314 } catch (\ilException $e) {
4315 \ilUtil::sendFailure($this->lng->txt($e->getMessage()));
4316 }
4317
4318 $this->showThreadsObject();
4319 }
4320
4324 protected function setSideBlocks()
4325 {
4326 $content = $this->getRightColumnHTML();
4327 if (!$this->ctrl->isAsynch()) {
4328 $content = implode('', [
4329 \ilRepositoryObjectSearchGUI::getSearchBlockHTML($this->lng->txt('frm_search')),
4330 $content,
4331 ]);
4332 }
4333 $this->tpl->setRightContent($content);
4334 }
4335
4339 protected function deliverDraftZipFileObject()
4340 {
4341 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
4342 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4343 }
4344
4345 $draftId = $this->httpRequest->getQueryParams()['draft_id'] ?? 0;
4346 $draft = \ilForumPostDraft::newInstanceByDraftId((int) $draftId);
4347 if ($draft->getPostAuthorId() == $this->user->getId()) {
4348 $fileData = new \ilFileDataForumDrafts(0, $draft->getDraftId());
4349 if (!$fileData->deliverZipFile()) {
4350 $this->ctrl->redirect($this);
4351 }
4352 }
4353 }
4354
4358 protected function deliverZipFileObject()
4359 {
4360 if (!$this->access->checkAccess('read', '', $this->object->getRefId())) {
4361 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4362 }
4363
4364 $this->ensureThreadBelongsToForum((int) $this->object->getId(), $this->objCurrentPost->getThread());
4365
4366 $fileData = new \ilFileDataForum($this->object->getId(), $this->objCurrentPost->getId());
4367 if (!$fileData->deliverZipFile()) {
4368 $this->ctrl->redirect($this);
4369 }
4370 }
4371
4375 protected function editThreadDraftObject(\ilPropertyFormGUI $form = null)
4376 {
4377 if (
4378 !$this->access->checkAccess('add_thread', '', $this->object->getRefId()) ||
4379 !$this->access->checkAccess('read', '', $this->object->getRefId()) ||
4381 ) {
4382 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4383 }
4384
4385 $frm = $this->object->Forum;
4386 $frm->setForumId($this->object->getId());
4387 $frm->setForumRefId($this->object->getRefId());
4388
4389 $draft = new \ilForumPostDraft();
4390 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
4391 if ($draftId > 0) {
4392 $draft = $draft->newInstanceByDraftId($draftId);
4393 }
4394
4395 $historyCheck = (int) ($this->httpRequest->getQueryParams()['hist_check'] ?? 1);
4396 if (!($form instanceof \ilPropertyFormGUI) && $historyCheck > 0) {
4397 $this->doHistoryCheck($draft->getDraftId());
4398 }
4399
4400 if (!$form instanceof \ilPropertyFormGUI) {
4401 $form = $this->buildThreadForm(true);
4402 $form->setValuesByArray([
4403 'alias' => $draft->getPostUserAlias(),
4404 'subject' => $draft->getPostSubject(),
4405 'message' => \ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($draft->getPostMessage(), 2), 1),
4406 'notify' => $draft->getNotify() ? true : false,
4407 'userfile' => '',
4408 'del_file' => []
4409 ]);
4410 } else {
4411 $this->ctrl->setParameter($this, 'draft_id', $draftId);
4412 }
4413
4414 $this->tpl->setContent($form->getHTML() . $this->modal_history);
4415 }
4416
4417 protected function restoreFromHistoryObject()
4418 {
4419 $historyId = (int) ($this->httpRequest->getQueryParams()['history_id'] ?? 0);
4420 $history = new \ilForumDraftsHistory($historyId);
4421
4422 $draft = $history->rollbackAutosave();
4423 if ($draft->getThreadId() == 0 && $draft->getPostId() == 0) {
4424 $this->ctrl->setParameter($this, 'draft_id', $history->getDraftId());
4425 $this->ctrl->redirect($this, 'editThreadDraft');
4426 }
4427
4428 $this->ctrl->clearParameters($this);
4429 $this->ctrl->setParameter($this, 'pos_pk', $draft->getPostId());
4430 $this->ctrl->setParameter($this, 'thr_pk', $draft->getThreadId());
4431 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
4432 $this->ctrl->setParameter($this, 'action', 'editdraft');
4433
4434 // create draft backup before redirect!
4435 \ilForumPostDraft::createDraftBackup((int) $draft->getDraftId());
4436
4437 $this->ctrl->redirect($this, 'viewThread');
4438 }
4439
4440 protected function saveThreadAsDraftObject()
4441 {
4442 if (
4443 !$this->access->checkAccess('add_thread', '', $this->object->getRefId()) ||
4444 !$this->access->checkAccess('read', '', $this->object->getRefId()) ||
4446 ) {
4447 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4448 }
4449
4450 $autoSavedDraftId = (int) ($this->httpRequest->getParsedBody()['draft_id'] ?? 0);
4451 if ($autoSavedDraftId <= 0) {
4452 $autoSavedDraftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
4453 }
4454
4455 $frm = $this->object->Forum;
4456 $frm->setForumId($this->object->getId());
4457 $frm->setForumRefId($this->object->getRefId());
4458 $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4459 $topicData = $frm->getOneTopic();
4460
4461 $form = $this->buildThreadForm();
4462 if ($form->checkInput()) {
4463 $this->doCaptchaCheck();
4464
4465 if (0 === $autoSavedDraftId) {
4466 $draft = new \ilForumPostDraft();
4467 } else {
4468 $draft = \ilForumPostDraft::newInstanceByDraftId($autoSavedDraftId);
4469 }
4470
4471 $draft->setForumId($topicData['top_pk']);
4472 $draft->setThreadId(0);
4473 $draft->setPostId(0);
4474 $draft->setPostSubject($this->handleFormInput($form->getInput('subject'), false));
4475 $draft->setPostMessage(\ilRTE::_replaceMediaObjectImageSrc($form->getInput('message'), 0));
4477 $form->getInput('alias'),
4478 $this->objProperties->isAnonymized()
4479 );
4480 $draft->setPostUserAlias($userAlias);
4481 $draft->setNotify((int) $form->getInput('notify'));
4482 $draft->setPostAuthorId($this->user->getId());
4483 $draft->setPostDisplayUserId(($this->objProperties->isAnonymized() ? 0 : $this->user->getId()));
4484
4485 if (0 === $autoSavedDraftId) {
4486 $draftId = $draft->saveDraft();
4487 } else {
4488 $draft->updateDraft();
4489 $draftId = $draft->getDraftId();
4490 }
4491
4492 $GLOBALS['ilAppEventHandler']->raise(
4493 'Modules/Forum',
4494 'savedAsDraft',
4495 [
4496 'draftObj' => $draft,
4497 'obj_id' => $this->object->getId(),
4498 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed(),
4499 ]
4500 );
4501
4502 \ilForumUtil::moveMediaObjects($form->getInput('message'), 'frm~d:html', $draftId, 'frm~d:html', $draftId);
4503
4504 $draftFileData = new \ilFileDataForumDrafts($this->object->getId(), $draftId);
4505
4506 $files2delete = $form->getInput('del_file');
4507 if (is_array($files2delete) && count($files2delete) > 0) {
4508 $draftFileData->unlinkFilesByMD5Filenames($files2delete);
4509 }
4510
4511 if ($this->objProperties->isFileUploadAllowed()) {
4512 $file = $_FILES['userfile'];
4513 if (is_array($file) && !empty($file)) {
4514 $draftFileData->storeUploadedFile($file);
4515 }
4516 }
4517
4518 \ilUtil::sendSuccess($this->lng->txt('save_draft_successfully'), true);
4519 $this->ctrl->clearParameters($this);
4520 $this->ctrl->redirect($this, 'showThreads');
4521 }
4522
4523 $this->requestAction = substr($this->requestAction, 6); // @nmatuschek: Why this, I don't get it???
4524 $form->setValuesByPost();
4525 $this->ctrl->setParameter($this, 'draft_id', $autoSavedDraftId);
4526 $this->tpl->setContent($form->getHTML());
4527 }
4528
4529 protected function updateThreadDraftObject()
4530 {
4531 if (
4532 !$this->access->checkAccess('add_thread', '', $this->object->getRefId()) ||
4533 !$this->access->checkAccess('read', '', $this->object->getRefId()) ||
4535 ) {
4536 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4537 }
4538
4539 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
4540 if ($draftId <= 0 || !$this->checkDraftAccess($draftId)) {
4541 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4542 }
4543
4544 $form = $this->buildThreadForm(true);
4545 if ($form->checkInput()) {
4546 $this->doCaptchaCheck();
4547
4549 $form->getInput('alias'),
4550 $this->objProperties->isAnonymized()
4551 );
4552
4553 $draft = \ilForumPostDraft::newInstanceByDraftId($draftId);
4554 $draft->setPostSubject($this->handleFormInput($form->getInput('subject'), false));
4555 $draft->setPostMessage(\ilRTE::_replaceMediaObjectImageSrc($form->getInput('message'), 0));
4556 $draft->setPostUserAlias($userAlias);
4557 $draft->setNotify((int) $form->getInput('notify'));
4558 $draft->setPostAuthorId($this->user->getId());
4559 $draft->setPostDisplayUserId(($this->objProperties->isAnonymized() ? 0 : $this->user->getId()));
4560 $draft->updateDraft();
4561
4562 $GLOBALS['ilAppEventHandler']->raise(
4563 'Modules/Forum',
4564 'updatedDraft',
4565 [
4566 'draftObj' => $draft,
4567 'obj_id' => $this->object->getId(),
4568 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed(),
4569 ]
4570 );
4571
4573 $form->getInput('message'),
4574 'frm~d:html',
4575 $draft->getDraftId(),
4576 'frm~d:html',
4577 $draft->getDraftId()
4578 );
4579
4580 $draftFileData = new \ilFileDataForumDrafts($this->object->getId(), $draft->getDraftId());
4581
4582 $files2delete = $form->getInput('del_file');
4583 if (is_array($files2delete) && count($files2delete) > 0) {
4584 $draftFileData->unlinkFilesByMD5Filenames($files2delete);
4585 }
4586
4587 if ($this->objProperties->isFileUploadAllowed()) {
4588 $file = $_FILES['userfile'];
4589 if (is_array($file) && !empty($file)) {
4590 $draftFileData->storeUploadedFile($file);
4591 }
4592 }
4593
4594 \ilUtil::sendSuccess($this->lng->txt('save_draft_successfully'), true);
4595 $this->ctrl->clearParameters($this);
4596 $this->ctrl->redirect($this, 'showThreads');
4597 }
4598
4599 $form->setValuesByPost();
4600 $this->ctrl->setParameter($this, 'hist_check', 0);
4601 $this->ctrl->setParameter($this, 'draft_id', $draftId);
4602 $this->editThreadDraftObject($form);
4603 }
4604
4605 public function saveTopLevelDraftObject() : void
4606 {
4607 $this->saveAsDraftObject();
4608 }
4609
4610 public function saveAsDraftObject()
4611 {
4612 if (!$this->objCurrentTopic->getId()) {
4613 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_deleted'), true);
4614 $this->ctrl->redirect($this);
4615 }
4616
4617 if ($this->objCurrentTopic->isClosed()) {
4618 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_closed'), true);
4619 $this->ctrl->redirect($this);
4620 }
4621
4622 if (!isset($_POST['del_file']) || !is_array($_POST['del_file'])) {
4623 $_POST['del_file'] = array();
4624 }
4625
4626 $autosave_draft_id = 0;
4627 if (ilForumPostDraft::isAutoSavePostDraftAllowed() && isset($_POST['draft_id'])) {
4628 $autosave_draft_id = (int) $_POST['draft_id'];
4629 }
4630 $oReplyEditForm = $this->getReplyEditForm();
4631 if ($oReplyEditForm->checkInput()) {
4632 if (!$this->objCurrentPost->getId()) {
4633 $this->requestAction = '';
4634 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_parent_deleted'));
4635 $this->viewThreadObject();
4636 return;
4637 }
4638
4639 $this->doCaptchaCheck();
4640
4641 // init objects
4642 $oForumObjects = $this->getForumObjects();
4646 $forumObj = $oForumObjects['forumObj'];
4650 $frm = $oForumObjects['frm'];
4651 $frm->setMDB2WhereCondition(' top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
4652 $topicData = $frm->getOneTopic();
4653
4654 // Generating new posting
4655 if ($this->requestAction == 'ready_showreply') {
4656 if (!$this->access->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
4657 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4658 }
4659
4660 $user_alias = ilForumUtil::getPublicUserAlias(
4661 $oReplyEditForm->getInput('alias'),
4662 $this->objProperties->isAnonymized()
4663 );
4664
4665 if ($autosave_draft_id == 0) {
4666 $draftObj = new ilForumPostDraft();
4667 } else {
4668 $draftObj = ilForumPostDraft::newInstanceByDraftId($autosave_draft_id);
4669 }
4670 $draftObj->setForumId($topicData['top_pk']);
4671 $draftObj->setThreadId($this->objCurrentTopic->getId());
4672 $draftObj->setPostId($this->objCurrentPost->getId());
4673
4674 $draftObj->setPostSubject($this->handleFormInput($oReplyEditForm->getInput('subject'), false));
4675 $draftObj->setPostMessage(ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0));
4676 $draftObj->setPostUserAlias($user_alias);
4677 $draftObj->setNotify((int) $oReplyEditForm->getInput('notify'));
4678 $draftObj->setPostNotify((int) $oReplyEditForm->getInput('notify_post'));
4679
4680 $draftObj->setPostAuthorId($this->user->getId());
4681 $draftObj->setPostDisplayUserId(($this->objProperties->isAnonymized() ? 0 : $this->user->getId()));
4682
4683 if ($autosave_draft_id == 0) {
4684 $draft_id = $draftObj->saveDraft();
4685 } else {
4686 $draftObj->updateDraft();
4687 $draft_id = $draftObj->getDraftId();
4688 }
4689
4691 $GLOBALS['ilAppEventHandler']->raise(
4692 'Modules/Forum',
4693 'savedAsDraft',
4694 array(
4695 'draftObj' => $draftObj,
4696 'obj_id' => $this->object->getId(),
4697 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed()
4698 )
4699 );
4700 }
4701
4702 if ($this->objProperties->isFileUploadAllowed()) {
4703 $file = $_FILES['userfile'];
4704 if (is_array($file) && !empty($file)) {
4705 $oFDForumDrafts = new ilFileDataForumDrafts($this->object->getId(), $draftObj->getDraftId());
4706 $oFDForumDrafts->storeUploadedFile($file);
4707 }
4708 }
4709
4710 // copy temporary media objects (frm~)
4712 $oReplyEditForm->getInput('message'),
4713 'frm~d:html',
4714 $draft_id,
4715 'frm~d:html',
4716 $draft_id
4717 );
4718
4719 $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes'][] = (int) $this->objCurrentPost->getId();
4720
4721 ilUtil::sendSuccess($this->lng->txt('save_draft_successfully'), true);
4722 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
4723 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
4724 $this->ctrl->redirect($this, 'viewThread');
4725 }
4726 } else {
4727 $oReplyEditForm->setValuesByPost();
4728 $this->requestAction = substr($this->requestAction, 6);
4729 }
4730 return $this->viewThreadObject();
4731 }
4732
4733 protected function editDraftObject()
4734 {
4736 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
4737 if ($this->checkDraftAccess($draftId)) {
4738 $this->doHistoryCheck($draftId);
4739 }
4740 }
4741
4742 $this->viewThreadObject();
4743 }
4744
4748 public function updateDraftObject()
4749 {
4750 if (!$this->objCurrentTopic->getId()) {
4751 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_deleted'), true);
4752 $this->ctrl->redirect($this);
4753 }
4754
4755 if ($this->objCurrentTopic->isClosed()) {
4756 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_thr_closed'), true);
4757 $this->ctrl->redirect($this);
4758 }
4759
4760 if (!$this->objCurrentPost->getId()) {
4761 $this->requestAction = '';
4762 \ilUtil::sendFailure($this->lng->txt('frm_action_not_possible_parent_deleted'));
4763 $this->viewThreadObject();
4764 return;
4765 }
4766
4767 if (!isset($_POST['del_file']) || !is_array($_POST['del_file'])) {
4768 $_POST['del_file'] = array();
4769 }
4770
4771 $oReplyEditForm = $this->getReplyEditForm();
4772 if ($oReplyEditForm->checkInput()) {
4773 $this->doCaptchaCheck();
4774
4775 // init objects
4776 $oForumObjects = $this->getForumObjects();
4780 $forumObj = $oForumObjects['forumObj'];
4781
4782 if (!$this->user->isAnonymous() && in_array($this->requestAction, ['showdraft', 'editdraft'])) {
4783 if (!$this->access->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
4784 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4785 }
4786 if (!$this->checkDraftAccess((int) $_GET['draft_id'])) {
4787 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4788 }
4789
4790 $user_alias = ilForumUtil::getPublicUserAlias(
4791 $oReplyEditForm->getInput('alias'),
4792 $this->objProperties->isAnonymized()
4793 );
4794
4795 // generateDraft
4796 $update_draft = new ilForumPostDraft(
4797 $this->user->getId(),
4798 $this->objCurrentPost->getId(),
4799 (int) $_GET['draft_id']
4800 );
4801
4802 $update_draft->setPostSubject($this->handleFormInput($oReplyEditForm->getInput('subject'), false));
4803 $update_draft->setPostMessage(ilRTE::_replaceMediaObjectImageSrc(
4804 $oReplyEditForm->getInput('message'),
4805 0
4806 ));
4807 $update_draft->setPostUserAlias($user_alias);
4808 $update_draft->setNotify((int) $oReplyEditForm->getInput('notify'));
4809 $update_draft->setUpdateUserId($this->user->getId());
4810 $update_draft->setPostAuthorId($this->user->getId());
4811 $update_draft->setPostDisplayUserId(($this->objProperties->isAnonymized() ? 0 : $this->user->getId()));
4812
4813 $update_draft->updateDraft();
4814
4816 $GLOBALS['ilAppEventHandler']->raise(
4817 'Modules/Forum',
4818 'updatedDraft',
4819 array(
4820 'draftObj' => $update_draft,
4821 'obj_id' => $this->object->getId(),
4822 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed()
4823 )
4824 );
4825 }
4826
4827 $uploadedObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $this->user->getId());
4828
4829 foreach ($uploadedObjects as $mob) {
4830 ilObjMediaObject::_removeUsage($mob, 'frm~:html', $this->user->getId());
4831 ilObjMediaObject::_saveUsage($mob, 'frm~d:html', $update_draft->getDraftId());
4832 }
4834 $oReplyEditForm->getInput('message'),
4835 'frm~d:html',
4836 $update_draft->getDraftId()
4837 );
4838
4839 $oFDForumDrafts = new ilFileDataForumDrafts($forumObj->getId(), $update_draft->getDraftId());
4840
4841 $file2delete = $oReplyEditForm->getInput('del_file');
4842 if (is_array($file2delete) && count($file2delete)) {
4843 $oFDForumDrafts->unlinkFilesByMD5Filenames($file2delete);
4844 }
4845
4846 if ($this->objProperties->isFileUploadAllowed()) {
4847 $file = $_FILES['userfile'];
4848 if (is_array($file) && !empty($file)) {
4849 $oFDForumDrafts->storeUploadedFile($file);
4850 }
4851 }
4852
4853 $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes'][] = (int) $this->objCurrentPost->getId();
4854 ilUtil::sendSuccess($this->lng->txt('save_draft_successfully'), true);
4855 }
4856 $this->ctrl->clearParameters($this);
4857 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
4858 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
4859 $this->ctrl->setParameter($this, 'draft_id', $update_draft->getDraftId());
4860 } else {
4861 $this->ctrl->clearParameters($this);
4862 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
4863 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
4864 $this->ctrl->setParameter($this, 'draft_id', (int) $_GET['draft_id']);
4865 $this->ctrl->setParameter($this, 'action', 'editdraft');
4866 $oReplyEditForm->setValuesByPost();
4867 return $this->viewThreadObject();
4868 }
4869 $this->ctrl->clearParameters($this);
4870 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
4871 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
4872 $this->ctrl->redirect($this, 'viewThread');
4873 }
4874
4880 protected function deleteMobsOfDraft($draft_id, $message)
4881 {
4882 // remove usage of deleted media objects
4883 $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~d:html', $draft_id);
4884 $curMediaObjects = ilRTE::_getMediaObjects($message, 0);
4885 foreach ($oldMediaObjects as $oldMob) {
4886 $found = false;
4887 foreach ($curMediaObjects as $curMob) {
4888 if ($oldMob == $curMob) {
4889 $found = true;
4890 break;
4891 }
4892 }
4893 if (!$found) {
4894 if (ilObjMediaObject::_exists($oldMob)) {
4895 ilObjMediaObject::_removeUsage($oldMob, 'frm~d:html', $draft_id);
4896 $mob_obj = new ilObjMediaObject($oldMob);
4897 $mob_obj->delete();
4898 }
4899 }
4900 }
4901 }
4902
4906 protected function deleteSelectedDraft(ilForumPostDraft $draft_obj = null)
4907 {
4908 if (
4909 !$this->access->checkAccess('add_reply', '', (int) $_GET['ref_id']) ||
4910 $this->user->isAnonymous() ||
4911 ($draft_obj instanceof ilForumPostDraft && $this->user->getId() != $draft_obj->getPostAuthorId())) {
4912 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
4913 }
4914
4915 $post_id = $this->objCurrentPost->getId();
4916 if (!($draft_obj instanceof ilForumPostDraft)) {
4917 $draft_id_to_delete = (int) $_GET['draft_id'];
4918 $draft_obj = new ilForumPostDraft($this->user->getId(), $post_id, $draft_id_to_delete);
4919
4920 if (!$draft_obj->getDraftId() || ($draft_obj->getDraftId() != $draft_id_to_delete)) {
4921 $this->ctrl->clearParameters($this);
4922 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
4923 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
4924 $this->ctrl->redirect($this, 'viewThread');
4925 }
4926 }
4927
4928 $this->deleteMobsOfDraft($draft_obj->getDraftId(), $draft_obj->getPostMessage());
4929
4930 $objFileDataForumDrafts = new ilFileDataForumDrafts(0, $draft_obj->getDraftId());
4931 $objFileDataForumDrafts->delete();
4932
4934 $GLOBALS['ilAppEventHandler']->raise(
4935 'Modules/Forum',
4936 'deletedDraft',
4937 array(
4938 'draftObj' => $draft_obj,
4939 'obj_id' => $this->object->getId(),
4940 'is_file_upload_allowed' => $this->objProperties->isFileUploadAllowed()
4941 )
4942 );
4943 }
4944 $draft_obj->deleteDraft();
4945
4946 ilUtil::sendSuccess($this->lng->txt('delete_draft_successfully'), true);
4947 $this->ctrl->clearParameters($this);
4948 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
4949 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
4950 $this->ctrl->redirect($this, 'viewThread');
4951 }
4952
4953 protected function autosaveDraftAsyncObject()
4954 {
4955 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
4956 if (
4957 $this->requestAction !== 'ready_showreply' &&
4958 $this->access->checkAccess('read', '', $this->object->getRefId()) &&
4959 $this->access->checkAccess('add_reply', '', $this->object->getRefId())
4960 ) {
4961 $action = new \ilForumAutoSaveAsyncDraftAction(
4962 $this->user,
4963 $this->getReplyEditForm(),
4964 $this->objProperties,
4965 $this->objCurrentTopic,
4966 $this->objCurrentPost,
4967 function (string $message) : string {
4968 return $this->handleFormInput($message);
4969 },
4970 $draftId,
4971 (int) \ilObjForum::lookupForumIdByRefId($this->ref_id),
4972 \ilUtil::stripSlashes($this->requestAction)
4973 );
4974
4975 echo json_encode($action->executeAndGetResponseObject());
4976 }
4977
4978 exit();
4979 }
4980
4982 {
4983 $draftId = (int) ($this->httpRequest->getQueryParams()['draft_id'] ?? 0);
4984 if (
4985 $this->requestAction !== 'ready_showreply' &&
4986 $this->access->checkAccess('read', '', $this->object->getRefId()) &&
4987 $this->access->checkAccess('add_thread', '', $this->object->getRefId())
4988 ) {
4989 $action = new \ilForumAutoSaveAsyncDraftAction(
4990 $this->user,
4991 $this->buildThreadForm(),
4992 $this->objProperties,
4993 $this->objCurrentTopic,
4994 $this->objCurrentPost,
4995 function (string $message) : string {
4996 return $this->handleFormInput($message, false);
4997 },
4998 $draftId,
4999 (int) \ilObjForum::lookupForumIdByRefId($this->ref_id),
5000 \ilUtil::stripSlashes($this->requestAction)
5001 );
5002
5003 echo json_encode($action->executeAndGetResponseObject());
5004 }
5005
5006 exit();
5007 }
5008
5018 private function renderSplitButton(
5020 string $action,
5021 bool $is_post,
5022 ilForumPost $node,
5023 int $pageIndex = 0,
5024 ilForumPostDraft $draft = null
5025 ) {
5026 $actions = array();
5027 if ($is_post) {
5028 if ($this->objCurrentPost->getId() != $node->getId() || (
5029 !in_array(
5030 $action,
5031 ['showreply', 'showedit', 'censor', 'delete']
5032 ) && !$this->displayConfirmPostActivation()
5033 )) {
5034 if ($this->is_moderator || $node->isActivated() || $node->isOwner($this->user->getId())) {
5035 if (!$this->objCurrentTopic->isClosed() && $node->isActivated() &&
5036 $this->access->checkAccess('add_reply', '', (int) $this->object->getRefId()) &&
5037 !$node->isCensored()
5038 ) {
5039 $this->ctrl->setParameter($this, 'action', 'showreply');
5040 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5041 $this->ctrl->setParameter($this, 'page', $pageIndex);
5042 $this->ctrl->setParameter(
5043 $this,
5044 'orderby',
5045 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5046 );
5047 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5048
5049 if (!isset($draftsObjects[$node->getId()])) {
5050 $actions['reply_to_postings'] = $this->ctrl->getLinkTarget(
5051 $this,
5052 'viewThread',
5053 'reply_' . $node->getId()
5054 );
5055 }
5056
5057 $this->ctrl->clearParameters($this);
5058 }
5059
5060 if (!$this->objCurrentTopic->isClosed() &&
5061 ($node->isOwner($this->user->getId()) || $this->is_moderator) &&
5062 !$node->isCensored() &&
5063 !$this->user->isAnonymous()
5064 ) {
5065 $this->ctrl->setParameter($this, 'action', 'showedit');
5066 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5067 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5068 $this->ctrl->setParameter($this, 'page', $pageIndex);
5069 $this->ctrl->setParameter(
5070 $this,
5071 'orderby',
5072 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5073 );
5074
5075 $actions['edit'] = $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId());
5076
5077 $this->ctrl->clearParameters($this);
5078 }
5079
5080 if (!$this->user->isAnonymous() && !$node->isPostRead()) {
5081 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5082 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5083 $this->ctrl->setParameter($this, 'page', $pageIndex);
5084 $this->ctrl->setParameter(
5085 $this,
5086 'orderby',
5087 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5088 );
5089 $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
5090
5091 $actions['frm_mark_as_read'] = $this->ctrl->getLinkTarget(
5092 $this,
5093 'markPostRead',
5094 $node->getId()
5095 );
5096
5097 $this->ctrl->clearParameters($this);
5098 }
5099
5100 if (!$this->user->isAnonymous() && $node->isPostRead()
5101 ) {
5102 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5103 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5104 $this->ctrl->setParameter($this, 'page', $pageIndex);
5105 $this->ctrl->setParameter(
5106 $this,
5107 'orderby',
5108 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5109 );
5110 $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
5111
5112 $actions['frm_mark_as_unread'] = $this->ctrl->getLinkTarget(
5113 $this,
5114 'markPostUnread',
5115 $node->getId()
5116 );
5117
5118 $this->ctrl->clearParameters($this);
5119 }
5120
5121 if (!$node->isCensored()) {
5122 $this->ctrl->setParameterByClass('ilforumexportgui', 'print_post', $node->getId());
5123 $this->ctrl->setParameterByClass('ilforumexportgui', 'top_pk', $node->getForumId());
5124 $this->ctrl->setParameterByClass('ilforumexportgui', 'thr_pk', $node->getThreadId());
5125
5126 $actions['print'] = $this->ctrl->getLinkTargetByClass('ilforumexportgui', 'printPost');
5127
5128 $this->ctrl->clearParameters($this);
5129 }
5130
5131 if (!$this->objCurrentTopic->isClosed() &&
5132 ($this->is_moderator ||
5133 ($node->isOwner($this->user->getId()) && !$node->hasReplies())) &&
5134 !$this->user->isAnonymous()
5135 ) {
5136 $this->ctrl->setParameter($this, 'action', 'delete');
5137 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5138 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5139 $this->ctrl->setParameter($this, 'page', $pageIndex);
5140 $this->ctrl->setParameter(
5141 $this,
5142 'orderby',
5143 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5144 );
5145
5146 $actions['delete'] = $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId());
5147
5148 $this->ctrl->clearParameters($this);
5149 }
5150
5151 if (!$this->objCurrentTopic->isClosed() && $this->is_moderator) {
5152 $this->ctrl->setParameter($this, 'action', 'censor');
5153 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5154 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5155 $this->ctrl->setParameter($this, 'page', $pageIndex);
5156 $this->ctrl->setParameter(
5157 $this,
5158 'orderby',
5159 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5160 );
5161 if ($node->isCensored()) {
5162 $actions['frm_revoke_censorship'] = $this->ctrl->getLinkTarget(
5163 $this,
5164 'viewThread',
5165 $node->getId()
5166 );
5167 } else {
5168 $actions['frm_censorship'] = $this->ctrl->getLinkTarget(
5169 $this,
5170 'viewThread',
5171 $node->getId()
5172 );
5173 }
5174
5175 $this->ctrl->clearParameters($this);
5176
5177 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5178 $this->ctrl->setParameter($this, 'thr_pk', $node->getThreadId());
5179 $this->ctrl->setParameter($this, 'page', $pageIndex);
5180 $this->ctrl->setParameter(
5181 $this,
5182 'orderby',
5183 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5184 );
5185
5186 if (!$node->isActivated()) {
5187 $actions['activate_post'] = $this->ctrl->getLinkTarget(
5188 $this,
5189 'askForPostActivation',
5190 $node->getId()
5191 );
5192 }
5193
5194 $this->ctrl->clearParameters($this);
5195 }
5196 }
5197 }
5198 } elseif ($_GET['draft_id'] != $draft->getDraftId() || !in_array($action, ['deletedraft', 'editdraft'])) {
5199 // get actions for drafts
5200 $this->ctrl->setParameter($this, 'action', 'publishdraft');
5201 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5202 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
5203 $this->ctrl->setParameter($this, 'page', (int) $this->httpRequest->getQueryParams()['page']);
5204 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
5205 $this->ctrl->setParameter(
5206 $this,
5207 'orderby',
5208 \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5209 );
5210 $actions['publish'] = $this->ctrl->getLinkTarget($this, 'publishSelectedDraft', $node->getId());
5211 $this->ctrl->clearParameters($this);
5212
5213 $this->ctrl->setParameter($this, 'action', 'editdraft');
5214 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5215 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
5216 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
5217 $this->ctrl->setParameter($this, 'page', (int) $this->httpRequest->getQueryParams()['page']);
5218 $this->ctrl->setParameter(
5219 $this,
5220 'orderby',
5221 \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5222 );
5223 $actions['edit'] = $this->ctrl->getLinkTarget($this, 'editDraft', 'draft_edit_' . $draft->getDraftId());
5224 $this->ctrl->clearParameters($this);
5225
5226 $this->ctrl->setParameter($this, 'action', 'deletedraft');
5227 $this->ctrl->setParameter($this, 'pos_pk', $node->getId());
5228 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentTopic->getId());
5229 $this->ctrl->setParameter($this, 'draft_id', $draft->getDraftId());
5230 $this->ctrl->setParameter($this, 'page', (int) $this->httpRequest->getQueryParams()['page']);
5231 $this->ctrl->setParameter(
5232 $this,
5233 'orderby',
5234 \ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5235 );
5236 $actions['delete'] = $this->ctrl->getLinkTarget($this, 'viewThread', $node->getId());
5237 $this->ctrl->clearParameters($this);
5238 }
5239
5240 $tpl->setCurrentBlock('posts_row');
5241 if (count($actions) > 0 && !$this->objCurrentTopic->isClosed()) {
5242 $action_button = ilSplitButtonGUI::getInstance();
5243
5244 $i = 0;
5245 foreach ($actions as $lng_id => $url) {
5246 if ($i == 0) {
5247 $sb_item = ilLinkButton::getInstance();
5248 $sb_item->setCaption($lng_id);
5249 $sb_item->setUrl($url);
5250
5251 $action_button->setDefaultButton($sb_item);
5252 ++$i;
5253 } else {
5254 $sb_item = ilLinkButton::getInstance();
5255 $sb_item->setCaption($lng_id);
5256 $sb_item->setUrl($url);
5257
5258 $action_button->addMenuItem(new ilButtonToSplitButtonMenuItemAdapter($sb_item));
5259 }
5260 }
5261
5262 $tpl->setVariable('COMMANDS', $action_button->render());
5263 }
5264 }
5265
5270 public function checkDraftAccess(int $draftId) : bool
5271 {
5272 $draft = \ilForumPostDraft::newInstanceByDraftId($draftId);
5273 if (
5274 !$this->access->checkAccess('add_reply', '', $this->object->getRefId()) || $this->user->isAnonymous() ||
5275 ($draft instanceof \ilForumPostDraft && $this->user->getId() != $draft->getPostAuthorId())
5276 ) {
5277 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
5278 }
5279
5280 return true;
5281 }
5282
5286 private function doHistoryCheck($draftId)
5287 {
5288 if (!$this->checkDraftAccess($draftId)) {
5289 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
5290 }
5291
5293 return;
5294 }
5295
5297 $draftsFromHistory = \ilForumDraftsHistory::getInstancesByDraftId($draftId);
5298 if (is_array($draftsFromHistory) && sizeof($draftsFromHistory) > 0) {
5299 $modal = \ilModalGUI::getInstance();
5300 $modal->setHeading($this->lng->txt('restore_draft_from_autosave'));
5301 $modal->setId('frm_autosave_restore');
5302 $form_tpl = new \ilTemplate('tpl.restore_thread_draft.html', true, true, 'Modules/Forum');
5303
5304 foreach ($draftsFromHistory as $key => $history_instance) {
5305 $accordion = new ilAccordionGUI();
5306 $accordion->setId('acc_' . $history_instance->getHistoryId());
5307
5308 $form_tpl->setCurrentBlock('list_item');
5309 $message = \ilRTE::_replaceMediaObjectImageSrc($history_instance->getPostMessage(), 1);
5310
5311 $history_date = ilDatePresentation::formatDate(new ilDateTime(
5312 $history_instance->getDraftDate(),
5314 ));
5315 $this->ctrl->setParameter($this, 'history_id', $history_instance->getHistoryId());
5316 $header = $history_date . ' - ' . $history_instance->getPostSubject();
5317 $accordion->addItem($header, $message . $this->uiRenderer->render(
5318 $this->uiFactory->button()->standard(
5319 $this->lng->txt('restore'),
5320 $this->ctrl->getLinkTarget($this, 'restoreFromHistory')
5321 )
5322 ));
5323
5324 $form_tpl->setVariable('ACC_AUTO_SAVE', $accordion->getHtml());
5325 $form_tpl->parseCurrentBlock();
5326 }
5327
5328 $form_tpl->setVariable('RESTORE_DATA_EXISTS', 'found_threat_history_to_restore');
5329 $modal->setBody($form_tpl->get());
5330 $modal->initJS();
5331 $this->modal_history = $modal->getHTML();
5332 } else {
5334 }
5335 }
5336
5340 protected function doCaptchaCheck()
5341 {
5342 if ($this->user->isAnonymous() && !$this->user->isCaptchaVerified() && \ilCaptchaUtil::isActiveForForum()) {
5343 $this->user->setCaptchaVerified(true);
5344 }
5345 }
5346
5354 private function renderPostingForm(ilTemplate $tpl, ilForum $frm, ilForumPost $node, string $action)
5355 {
5356 if (
5357 $action == 'showedit' && (
5358 (!$this->is_moderator && !$node->isOwner($this->user->getId()) || $this->user->isAnonymous()) || $node->isCensored()
5359 )
5360 ) {
5361 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->getMessage());
5362 } elseif ($action == 'showreply' && !$this->access->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
5363 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->getMessage());
5364 }
5365
5366 $tpl->setVariable('REPLY_ANKER', 'reply_' . $this->objCurrentPost->getId());
5367 $oEditReplyForm = $this->getReplyEditForm();
5368 if ($action !== 'editdraft') {
5369 switch ($this->objProperties->getSubjectSetting()) {
5370 case 'add_re_to_subject':
5371 $subject = $this->getModifiedReOnSubject(true);
5372 break;
5373
5374 case 'preset_subject':
5375 $subject = $this->objCurrentPost->getSubject();
5376 break;
5377
5378 case 'empty_subject':
5379 default:
5380 $subject = null;
5381 break;
5382 }
5383 }
5384
5385 switch ($action) {
5386 case 'showreply':
5387 if ($this->ctrl->getCmd() == 'savePost' || $this->ctrl->getCmd() == 'saveAsDraft') {
5388 $oEditReplyForm->setValuesByPost();
5389 } elseif ($this->ctrl->getCmd() == 'quotePost') {
5390 $authorinfo = new ilForumAuthorInformation(
5391 $node->getPosAuthorId(),
5392 $node->getDisplayUserId(),
5393 $node->getUserAlias(),
5394 $node->getImportName()
5395 );
5396
5397 $oEditReplyForm->setValuesByPost();
5398 $oEditReplyForm->getItemByPostVar('message')->setValue(
5400 $frm->prepareText(
5401 $node->getMessage(),
5402 1,
5403 $authorinfo->getAuthorName()
5404 ) . "\n" . $oEditReplyForm->getInput('message'),
5405 1
5406 )
5407 );
5408 } else {
5409 $oEditReplyForm->setValuesByArray(array(
5410 'alias' => '',
5411 'subject' => $subject,
5412 'message' => '',
5413 'notify' => 0,
5414 'userfile' => '',
5415 'del_file' => array()
5416 ));
5417 }
5418
5419 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
5420 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
5421
5422 $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum');
5423 $jsTpl->setVariable(
5424 'IL_FRM_QUOTE_CALLBACK_SRC',
5425 $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true)
5426 );
5427 $this->ctrl->clearParameters($this);
5428 $tpl->setVariable('FORM_ADDITIONAL_JS', $jsTpl->get());
5429 break;
5430
5431 case 'showedit':
5432 if ($this->ctrl->getCmd() == 'savePost') {
5433 $oEditReplyForm->setValuesByPost();
5434 } else {
5435 $oEditReplyForm->setValuesByArray(array(
5436 'alias' => '',
5437 'subject' => $this->objCurrentPost->getSubject(),
5439 $this->objCurrentPost->getMessage(),
5440 2
5441 ), 1),
5442 'notify' => $this->objCurrentPost->isNotificationEnabled() ? true : false,
5443 'userfile' => '',
5444 'del_file' => array()
5445 ));
5446 }
5447
5448 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getParentId());
5449 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
5450 $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum');
5451 $jsTpl->setVariable(
5452 'IL_FRM_QUOTE_CALLBACK_SRC',
5453 $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true)
5454 );
5455 $this->ctrl->clearParameters($this);
5456 $tpl->setVariable('FORM_ADDITIONAL_JS', $jsTpl->get());
5457 break;
5458
5459 case 'editdraft':
5460 if (in_array($this->ctrl->getCmd(), array('saveDraft', 'updateDraft', 'publishDraft'))) {
5461 $oEditReplyForm->setValuesByPost();
5462 } elseif (isset($_GET['draft_id']) && (int) $_GET['draft_id'] > 0) {
5466 $draftObject = new ilForumPostDraft(
5467 $this->user->getId(),
5468 $this->objCurrentPost->getId(),
5469 (int) $_GET['draft_id']
5470 );
5471 $oEditReplyForm->setValuesByArray(array(
5472 'alias' => $draftObject->getPostUserAlias(),
5473 'subject' => $draftObject->getPostSubject(),
5475 $draftObject->getPostMessage(),
5476 2
5477 ), 1),
5478 'notify' => $draftObject->getNotify() ? true : false,
5479 'userfile' => '',
5480 'del_file' => []
5481 ));
5482 }
5483
5484 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
5485 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
5486
5487 $jsTpl = new ilTemplate('tpl.forum_post_quoation_ajax_handler.html', true, true, 'Modules/Forum');
5488 $jsTpl->setVariable(
5489 'IL_FRM_QUOTE_CALLBACK_SRC',
5490 $this->ctrl->getLinkTarget($this, 'getQuotationHTMLAsynch', '', true)
5491 );
5492 $this->ctrl->clearParameters($this);
5493 $tpl->setVariable('FORM_ADDITIONAL_JS', $jsTpl->get());
5494 break;
5495 }
5496
5497 $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
5498 $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
5499 $this->ctrl->setParameter($this, 'page', (int) $this->httpRequest->getQueryParams()['page']);
5500 $this->ctrl->setParameter(
5501 $this,
5502 'orderby',
5503 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['orderby'])
5504 );
5505 $this->ctrl->setParameter(
5506 $this,
5507 'action',
5508 ilUtil::stripSlashes($this->httpRequest->getQueryParams()['action'])
5509 );
5510 if ($action !== 'editdraft') {
5511 $tpl->setVariable('FORM', $oEditReplyForm->getHTML());
5512 }
5513 $this->ctrl->clearParameters($this);
5514 }
5515}
$result
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
error($a_errmsg)
set error message @access public
Accordion user interface class.
This class represents a captcha input in a property form.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
Column user interface class.
setBlockProperty($a_block_type, $a_property, $a_value)
This function is supposed to be used for block type specific properties, that should be passed to ilB...
setRepositoryMode($a_repositorymode)
Set RepositoryMode.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Confirmation screen class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Base class for ILIAS Exception handling.
Export User Interface Class.
This class handles all operations on files for the drafts of a forum object.
This class handles all operations on files for the forum object.
This class represents a file wizard property in a property form.
getId()
Get Id.
Class ilForumDraftHistory.
static getInstancesByDraftId($draft_id)
Class ilForumDraftsTableGUI.
Class ilForumExplorerGUI.
Forum export to HTML and Print.
Class ilForumModeratorsGUI.
Class ilForumNotification.
Class ilForumPostDraft.
static newInstanceByDraftId($draft_id)
static getDraftInstancesByUserId($user_id)
static createDraftBackup($draft_id)
static getThreadDraftData($post_author_id, $forum_id)
static getSortedDrafts(int $usrId, int $threadId, int $sorting=ilForumProperties::VIEW_DATE_ASC)
isOwner($a_user_id=0)
setChangeDate($a_changedate)
setMessage($a_message)
static getInstance($a_obj_id=0)
Class ilForumSettingsGUI.
Class ilForumStatisticsTableGUI.
Class ilForumTopicTableGUI.
static lookupForumIdByTopicId($a_topic_id)
static _lookupDate($thread_id)
static _lookupTitle($a_topic_id)
Looks up the title/subject of a topic/thread.
static getPublicUserAlias($user_alias, $is_anonymized=false)
static moveMediaObjects($post_message, $source_type, $source_id, $target_type, $target_id, $direction=0)
static saveMediaObjects($post_message, $target_type, $target_id, $direction=0)
Class Forum core functions for forum.
static _isModerator($a_ref_id, $a_usr_id)
checks whether a user is moderator of a given forum object
prepareText($text, $edit=0, $quote_user='', $type='')
prepares given string @access public
static _lookupObjIdForForumId($a_for_id)
static get($a_glyph, $a_text="")
Get glyph html.
Online help application class.
This class represents a hidden form property in a property form.
static _getInstanceByType(string $type)
Factory method for creating purifier instances.
static getInstance()
Factory.
static getInstance()
Get instance.
Navigation History of Repository Items.
addItem( $a_ref_id, $a_link, $a_type, $a_title="", $a_sub_obj_id="", $a_goto_link="")
Add an item to the stack.
static getFirstNewsIdForContext( $a_context_obj_id, $a_context_obj_type, $a_context_sub_obj_id="", $a_context_sub_obj_type="")
Get first new id of news set related to a certain context.
This class represents a non editable value in a property form.
static _getRichTextEditorUserState()
Gets the state of the rich text editor visibility for the current user.
static _setRichTextEditorUserState($a_state)
Sets the state of the rich text editor visibility for the current user.
Class ilObjForumGUI.
toggleExplorerNodeStateObject()
Toggle explorer node.
ensureThreadBelongsToForum(int $objId, \ilForumTopic $thread)
addLocatorItems()
should be overwritten to add object specific items (repository items are preloaded)
getThreadEditingForm($a_thread_id)
doCaptchaCheck()
Performs a CAPTCHA check for anonymous users if the CAPTCHA should be used for forums in the public a...
publishDraftObject($use_replyform=true)
initHeaderAction($a_sub_type=null, $a_sub_id=null)
Add header action menu.ilObjectListGUI
getModifiedReOnSubject($on_reply=false)
executeCommand()
execute command
buildThreadForm($isDraft=false)
getTabs()
get tabs abstract method.
getSubTabs($subtab='showThreads')
getEditFormCustomValues(array &$a_values)
static _goto($a_target, $a_thread=0, $a_posting=0)
renderDraftContent(ilTemplate $tpl, string $action, ilForumPost $referencePosting, array $drafts)
renderSplitButton(ilTemplate $tpl, string $action, bool $is_post, ilForumPost $node, int $pageIndex=0, ilForumPostDraft $draft=null)
editThreadDraftObject(\ilPropertyFormGUI $form=null)
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
hideToolbar($a_flag=null)
setColumnSettings(ilColumnGUI $column_gui)
May be overwritten in subclasses.
handleFormInput($a_text, $a_stripslashes=true)
updateCustom(ilPropertyFormGUI $a_form)
createThread(\ilForumPostDraft $draft, bool $createFromDraft=false)
Refactored thread creation to method, refactoring to a separate class should be done in next refactor...
decorateWithAutosave(\ilPropertyFormGUI $form)
afterSave(ilObject $a_new_object)
editThreadObject($threadId, ilPropertyFormGUI $form=null)
setDisplayConfirmPostActivation($status=0)
deleteSelectedDraft(ilForumPostDraft $draft_obj=null)
renderPostContent(ilTemplate $tpl, ilForumPost $node, string $action, int $pageIndex, int $postIndex)
ensureValidPageForCurrentPosting(array $subtree_nodes, array $pagedPostings, int $pageSize, ilForumPost $firstForumPost)
initEditCustomForm(ilPropertyFormGUI $a_form)
renderSortationControl(int $currentSorting)
renderViewModeControl(int $currentViewMode)
deleteMobsOfDraft($draft_id, $message)
todo: move to ilForumUtil
checkDraftAccess(int $draftId)
Class ilObjForumListGUI.
Class ilObjForum.
static lookupForumIdByRefId($ref_id)
static lookupForumIdByObjId($obj_id)
Class ilObjMediaObject.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
GUI class for the workflow of copying objects.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput($a_show_subobjects=true)
prepare output
getCenterColumnHTML()
Get center column.
getCreationMode()
get creation mode
addHeaderAction()
Add header action menu.
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
getRefId()
get reference id @access public
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id @access public
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
GUI class for public user profile presentation.
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...
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
static _getRTEClassname()
Class ilRatingGUI.
static getOverallRatingForObject($a_obj_id, $a_obj_type, $a_sub_obj_id=null, $a_sub_obj_type=null, $a_category_id=null)
Get overall rating for an object.
static getSearchBlockHTML($a_title)
Get standar search block html.
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
Class ilTable2GUI.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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 stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static infoPanel($a_keep=true)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
Interface for gui classes (e.g ilLuceneSearchGUI) that offer add/remove to/from desktop.
exit
Definition: login.php:29
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$url
$ilErr
Definition: raiseError.php:18
$lng
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$mobs
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46
$objId
Definition: xapitoken.php:41