Example #1
0
 public function savePostObject()
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilAccess ilAccessHandler
      * @var $lng ilLanguage
      */
     global $ilUser, $ilAccess, $lng;
     if (!isset($_POST['del_file']) || !is_array($_POST['del_file'])) {
         $_POST['del_file'] = array();
     }
     if ($this->objCurrentTopic->isClosed()) {
         $_GET['action'] = '';
         return $this->viewThreadObject();
     }
     $oReplyEditForm = $this->getReplyEditForm();
     if ($oReplyEditForm->checkInput()) {
         require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php';
         if ($ilUser->isAnonymous() && !$ilUser->isCaptchaVerified() && ilCaptchaUtil::isActiveForForum()) {
             $ilUser->setCaptchaVerified(true);
         }
         // init objects
         $oForumObjects = $this->getForumObjects();
         /**
          * @var $forumObj ilObjForum
          */
         $forumObj = $oForumObjects['forumObj'];
         /**
          * @var $frm ilForum
          */
         $frm = $oForumObjects['frm'];
         $frm->setMDB2WhereCondition(' top_frm_fk = %s ', array('integer'), array($frm->getForumId()));
         $topicData = $frm->getOneTopic();
         // Generating new posting
         if ($_GET['action'] == 'ready_showreply') {
             if (!$ilAccess->checkAccess('add_reply', '', (int) $_GET['ref_id'])) {
                 $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
             }
             // reply: new post
             $status = 1;
             $send_activation_mail = 0;
             if ($this->objProperties->isPostActivationEnabled()) {
                 if (!$this->is_moderator) {
                     $status = 0;
                     $send_activation_mail = 1;
                 } else {
                     if ($this->objCurrentPost->isAnyParentDeactivated()) {
                         $status = 0;
                     }
                 }
             }
             if ($this->objProperties->isAnonymized()) {
                 if (!strlen($oReplyEditForm->getInput('alias'))) {
                     $user_alias = $this->lng->txt('forums_anonymous');
                 } else {
                     $user_alias = $oReplyEditForm->getInput('alias');
                 }
             } else {
                 $user_alias = $ilUser->getLogin();
             }
             $newPost = $frm->generatePost($topicData['top_pk'], $this->objCurrentTopic->getId(), $ilUser->getId(), $this->objProperties->isAnonymized() ? 0 : $ilUser->getId(), ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0), $this->objCurrentPost->getId(), (int) $oReplyEditForm->getInput('notify'), $this->handleFormInput($oReplyEditForm->getInput('subject'), false), $user_alias, '', $status, $send_activation_mail);
             // mantis #8115: Mark parent as read
             $this->object->markPostRead($ilUser->getId(), (int) $this->objCurrentTopic->getId(), (int) $this->objCurrentPost->getId());
             // copy temporary media objects (frm~)
             include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
             $mediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
             $myMediaObjects = ilObjMediaObject::_getMobsOfObject('frm~:html', $ilUser->getId());
             foreach ($mediaObjects as $mob) {
                 foreach ($myMediaObjects as $myMob) {
                     if ($mob == $myMob) {
                         // change usage
                         ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId());
                         break;
                     }
                 }
                 ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost);
             }
             $oFDForum = new ilFileDataForum($forumObj->getId(), $newPost);
             $file = $_FILES['userfile'];
             if (is_array($file) && !empty($file)) {
                 $oFDForum->storeUploadedFile($file);
             }
             // FINALLY SEND MESSAGE
             if ($this->ilias->getSetting("forum_notification") == 1 && (int) $status) {
                 $objPost = new ilForumPost((int) $newPost, $this->is_moderator);
                 $post_data = array();
                 $post_data = $objPost->getDataAsArray();
                 $titles = $this->getTitlesByRefId(array($this->object->getRefId()));
                 $post_data["top_name"] = $titles[0];
                 $post_data["ref_id"] = $this->object->getRefId();
                 $frm->__sendMessage($objPost->getParentId(), $post_data);
                 $frm->sendForumNotifications($post_data);
                 $frm->sendThreadNotifications($post_data);
             }
             $message = '';
             if (!$this->is_moderator && !$status) {
                 $message .= $lng->txt('forums_post_needs_to_be_activated');
             } else {
                 $message .= $lng->txt('forums_post_new_entry');
             }
             $_SESSION['frm'][(int) $_GET['thr_pk']]['openTreeNodes'][] = (int) $this->objCurrentPost->getId();
             ilUtil::sendSuccess($message, true);
             $this->ctrl->setParameter($this, 'pos_pk', $newPost);
             $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
             $this->ctrl->redirect($this, 'viewThread');
         } else {
             if (!$this->is_moderator && !$this->objCurrentPost->isOwner($ilUser->getId()) || $this->objCurrentPost->isCensored() || $ilUser->getId() == ANONYMOUS_USER_ID) {
                 $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
             }
             // remove usage of deleted media objects
             include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
             $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('frm:html', $this->objCurrentPost->getId());
             $curMediaObjects = ilRTE::_getMediaObjects($oReplyEditForm->getInput('message'), 0);
             foreach ($oldMediaObjects as $oldMob) {
                 $found = false;
                 foreach ($curMediaObjects as $curMob) {
                     if ($oldMob == $curMob) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     if (ilObjMediaObject::_exists($oldMob)) {
                         ilObjMediaObject::_removeUsage($oldMob, 'frm:html', $this->objCurrentPost->getId());
                         $mob_obj = new ilObjMediaObject($oldMob);
                         $mob_obj->delete();
                     }
                 }
             }
             // if post has been edited posting mus be activated again by moderator
             $status = 1;
             $send_activation_mail = 0;
             if ($this->objProperties->isPostActivationEnabled()) {
                 if (!$this->is_moderator) {
                     $status = 0;
                     $send_activation_mail = 1;
                 } else {
                     if ($this->objCurrentPost->isAnyParentDeactivated()) {
                         $status = 0;
                     }
                 }
             }
             $this->objCurrentPost->setStatus($status);
             $this->objCurrentPost->setSubject($this->handleFormInput($oReplyEditForm->getInput('subject'), false));
             $this->objCurrentPost->setMessage(ilRTE::_replaceMediaObjectImageSrc($oReplyEditForm->getInput('message'), 0));
             $this->objCurrentPost->setNotification((int) $oReplyEditForm->getInput('notify'));
             $this->objCurrentPost->setChangeDate(date('Y-m-d H:i:s'));
             $this->objCurrentPost->setUpdateUserId($ilUser->getId());
             // edit: update post
             if ($this->objCurrentPost->update()) {
                 $this->objCurrentPost->reload();
                 // Change news item accordingly
                 include_once 'Services/News/classes/class.ilNewsItem.php';
                 // note: $this->objCurrentPost->getForumId() does not give us the forum ID here (why?)
                 $news_id = ilNewsItem::getFirstNewsIdForContext($forumObj->getId(), 'frm', $this->objCurrentPost->getId(), 'pos');
                 if ($news_id > 0) {
                     $news_item = new ilNewsItem($news_id);
                     $news_item->setTitle($this->objCurrentPost->getSubject());
                     $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($frm->prepareText($this->objCurrentPost->getMessage(), 0), 1));
                     $news_item->update();
                 }
                 // attachments
                 $oFDForum = $oForumObjects['file_obj'];
                 $file = $_FILES['userfile'];
                 if (is_array($file) && !empty($file)) {
                     $oFDForum->storeUploadedFile($file);
                 }
                 $file2delete = $oReplyEditForm->getInput('del_file');
                 if (is_array($file2delete) && count($file2delete)) {
                     $oFDForum->unlinkFilesByMD5Filenames($file2delete);
                 }
             }
             if (!$status && $send_activation_mail) {
                 $pos_data = $this->objCurrentPost->getDataAsArray();
                 $pos_data["top_name"] = $this->object->getTitle();
                 $frm->sendPostActivationNotification($pos_data);
             }
             ilUtil::sendSuccess($lng->txt('forums_post_modified'), true);
             $this->ctrl->setParameter($this, 'pos_pk', $this->objCurrentPost->getId());
             $this->ctrl->setParameter($this, 'thr_pk', $this->objCurrentPost->getThreadId());
             $this->ctrl->setParameter($this, 'viewmode', $_SESSION['viewmode']);
             $this->ctrl->redirect($this, 'viewThread');
         }
     } else {
         $_GET['action'] = substr($_GET['action'], 6);
     }
     return $this->viewThreadObject();
 }
 /**
  * Print Posting.
  *
  */
 function printPost()
 {
     global $tpl, $lng, $ilAccess, $ilias;
     if (!$ilAccess->checkAccess('read,visible', '', $_GET['ref_id'])) {
         $ilias->raiseError($lng->txt('permission_denied'), $ilias->error_obj->MESSAGE);
     }
     $tplEx = new ilTemplate('tpl.forums_export_print.html', true, true, 'Modules/Forum');
     $tplEx->setVariable('CSSPATH', $tpl->tplPath);
     // get forum- and thread-data
     $this->frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($_GET['top_pk']));
     if (is_array($frmData = $this->frm->getOneTopic())) {
         // post object
         $post = new ilForumPost((int) $_GET['print_post']);
         // headline
         $tplEx->setVariable('HEADLINE', $lng->txt('forum') . ': ' . $frmData['top_name'] . ' > ' . $lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject());
         $tplEx->setCurrentBlock('posts_row');
         $tplEx->setVariable('ROWCOL', 'tblrow2');
         $authorinfo = new ilForumAuthorInformation($post->getUserId(), $post->getUserAlias(), $post->getImportName());
         $tplEx->setVariable('AUTHOR', $authorinfo->getAuthorName());
         if ($post->getUserId()) {
             // get create- and update-dates
             if ($post->getUpdateUserId()) {
                 $authorinfo = new ilForumAuthorInformation($post->getUpdateUserId(), '', '');
                 $tplEx->setVariable('POST_UPDATE', "<br />[" . $lng->txt('edited_on') . ": " . $this->frm->convertDate($post->getChangeDate()) . " - " . strtolower($lng->txt('from')) . " " . $authorinfo->getAuthorName() . "]");
             }
             if ($ilAccess->checkAccess('moderate_frm', '', $_GET['ref_id'])) {
                 $numPosts = $this->frm->countUserArticles($post->getUserId());
             } else {
                 $numPosts = $this->frm->countActiveUserArticles($post->getUserId());
             }
         }
         $tplEx->setVariable('SUBJECT', $post->getSubject());
         $tplEx->setVariable('TXT_CREATE_DATE', $lng->txt('forums_thread_create_date'));
         $tplEx->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
         $tplEx->setVariable('SPACER', "<hr noshade width=\"100%\" size=\"1\" align=\"center\" />");
         if ($post->isCensored()) {
             $tplEx->setVariable('POST', nl2br(stripslashes($post->getCensorshipComment())));
         } else {
             /** @todo mjansen: possible bugfix for mantis #8223 */
             if ($post->getMessage() == strip_tags($post->getMessage())) {
                 // We can be sure, that there are not html tags
                 $post->setMessage(nl2br($post->getMessage()));
             }
             $tplEx->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($this->frm->prepareText($post->getMessage(), 0, '', 'export'), 1));
         }
         $tplEx->parseCurrentBlock('posts_row');
         $tplEx->setCurrentBlock('posttable');
         $tplEx->setVariable('TXT_AUTHOR', $lng->txt('author'));
         $tplEx->setVariable('TXT_POST', $lng->txt('forums_thread') . ': ' . $post->getThread()->getSubject());
         $tplEx->parseCurrentBlock('posttable');
     }
     // if (is_array($frmData = $this->frm->getOneTopic()))
     $tplEx->show();
 }
 /**
  * @param ilTemplate $tpl
  * @param ilForumPost $post
  * @param int $counter
  * @param int $mode
  */
 protected function renderPostHtml(ilTemplate $tpl, ilForumPost $post, $counter, $mode)
 {
     /**
      * @var $lng            ilLanguage
      * @var $rbacreview     ilRbacReview
      * @var $ilUser         ilObjUser
      * @var $ilObjDataCache ilObjectDataCache
      */
     global $lng, $rbacreview, $ilUser, $ilObjDataCache;
     $tpl->setCurrentBlock('posts_row');
     if (ilForumProperties::getInstance($ilObjDataCache->lookupObjId($_GET['ref_id']))->getMarkModeratorPosts() == 1) {
         if ($post->getIsAuthorModerator() === null && ($is_moderator = ilForum::_isModerator($_GET['ref_id'], $post->getPosAuthorId()))) {
             $rowCol = 'ilModeratorPosting';
         } else {
             if ($post->getIsAuthorModerator()) {
                 $rowCol = 'ilModeratorPosting';
             } else {
                 $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
             }
         }
     } else {
         $rowCol = ilUtil::switchColor($counter, 'tblrow1', 'tblrow2');
     }
     $tpl->setVariable('ROWCOL', ' ' . $rowCol);
     // post is censored
     if ($post->isCensored()) {
         // display censorship advice
         $tpl->setVariable('TXT_CENSORSHIP_ADVICE', $lng->txt('post_censored_comment_by_moderator'));
         // highlight censored posts
         $rowCol = 'tblrowmarked';
     }
     // set row color
     $tpl->setVariable('ROWCOL', ' ' . $rowCol);
     // if post is not activated display message for the owner
     if (!$post->isActivated() && $post->isOwner($ilUser->getId())) {
         $tpl->setVariable('POST_NOT_ACTIVATED_YET', $lng->txt('frm_post_not_activated_yet'));
     }
     $authorinfo = new ilForumAuthorInformation($post->getPosAuthorId(), $post->getDisplayUserId(), $post->getUserAlias(), $post->getImportName());
     if ($authorinfo->hasSuffix()) {
         $tpl->setVariable('AUTHOR', $authorinfo->getSuffix());
         $tpl->setVariable('USR_NAME', $post->getUserAlias());
     } else {
         $tpl->setVariable('AUTHOR', $authorinfo->getAuthorShortName());
         if ($authorinfo->getAuthorName(true)) {
             $tpl->setVariable('USR_NAME', $authorinfo->getAuthorName(true));
         }
     }
     if (self::MODE_EXPORT_CLIENT == $mode) {
         if ($authorinfo->getAuthor()->getPref('public_profile') != 'n') {
             $tpl->setVariable('TXT_REGISTERED', $lng->txt('registered_since'));
             $tpl->setVariable('REGISTERED_SINCE', $this->frm->convertDate($authorinfo->getAuthor()->getCreateDate()));
         }
         if ($post->getDisplayUserId()) {
             if ($this->is_moderator) {
                 $num_posts = $this->frm->countUserArticles($post->getDisplayUserId());
             } else {
                 $num_posts = $this->frm->countActiveUserArticles($post->getDisplayUserId());
             }
             $tpl->setVariable('TXT_NUM_POSTS', $lng->txt('forums_posts'));
             $tpl->setVariable('NUM_POSTS', $num_posts);
         }
     }
     $tpl->setVariable('USR_IMAGE', $authorinfo->getProfilePicture());
     if ($authorinfo->getAuthor()->getId() && ilForum::_isModerator((int) $_GET['ref_id'], $post->getPosAuthorId())) {
         if ($authorinfo->getAuthor()->getGender() == 'f') {
             $tpl->setVariable('ROLE', $lng->txt('frm_moderator_f'));
         } else {
             if ($authorinfo->getAuthor()->getGender() == 'm') {
                 $tpl->setVariable('ROLE', $lng->txt('frm_moderator_m'));
             }
         }
     }
     // get create- and update-dates
     if ($post->getUpdateUserId() > 0) {
         $spanClass = '';
         // last update from moderator?
         $posMod = $this->frm->getModeratorFromPost($post->getId());
         if (is_array($posMod) && $posMod['top_mods'] > 0) {
             $MODS = $rbacreview->assignedUsers($posMod['top_mods']);
             if (is_array($MODS)) {
                 if (in_array($post->getUpdateUserId(), $MODS)) {
                     $spanClass = 'moderator_small';
                 }
             }
         }
         $post->setChangeDate($post->getChangeDate());
         if ($spanClass == '') {
             $spanClass = 'small';
         }
         require_once 'Modules/Forum/classes/class.ilForumAuthorInformation.php';
         $authorinfo = new ilForumAuthorInformation($post->getPosAuthorId(), $post->getUpdateUserId(), '', '');
         $tpl->setVariable('POST_UPDATE_TXT', $lng->txt('edited_on') . ': ' . $this->frm->convertDate($post->getChangeDate()) . ' - ' . strtolower($lng->txt('by')));
         $tpl->setVariable('UPDATE_AUTHOR', $authorinfo->getLinkedAuthorShortName());
         if ($authorinfo->getAuthorName(true)) {
             $tpl->setVariable('UPDATE_USR_NAME', $authorinfo->getAuthorName(true));
         }
     }
     // prepare post
     $post->setMessage($this->frm->prepareText($post->getMessage()));
     $tpl->setVariable('POST_DATE', $this->frm->convertDate($post->getCreateDate()));
     $tpl->setVariable('SUBJECT', $post->getSubject());
     if (!$post->isCensored()) {
         // post from moderator?
         $modAuthor = $this->frm->getModeratorFromPost($post->getId());
         $spanClass = "";
         if (is_array($modAuthor) && $modAuthor['top_mods'] > 0) {
             $MODS = $rbacreview->assignedUsers($modAuthor['top_mods']);
             if (is_array($MODS) && in_array($post->getDisplayUserId(), $MODS)) {
                 $spanClass = 'moderator';
             }
         }
         // possible bugfix for mantis #8223
         if ($post->getMessage() == strip_tags($post->getMessage())) {
             // We can be sure, that there are not html tags
             $post->setMessage(nl2br($post->getMessage()));
         }
         if ($spanClass != "") {
             $tpl->setVariable('POST', "<span class=\"" . $spanClass . "\">" . ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1) . "</span>");
         } else {
             $tpl->setVariable('POST', ilRTE::_replaceMediaObjectImageSrc($post->getMessage(), 1));
         }
     } else {
         $tpl->setVariable('POST', "<span class=\"moderator\">" . nl2br($post->getCensorshipComment()) . "</span>");
     }
     $tpl->parseCurrentBlock('posts_row');
 }