예제 #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();
 }
예제 #2
0
 /**
  * @param $obj_id
  * @param $source_id
  * @param $target_id
  * @throws ilException
  */
 public static function mergeThreads($obj_id, $source_id, $target_id)
 {
     // selected source & target objects
     $source_thread_obj = new ilForumTopic((int) $source_id);
     $target_thread_obj = new ilForumTopic((int) $target_id);
     if ($source_thread_obj->getForumId() != $target_thread_obj->getForumId()) {
         throw new ilException('not_allowed_to_merge_into_another_forum');
     }
     // use the "older" thread as target
     if ($source_thread_obj->getCreateDate() > $target_thread_obj->getCreateDate()) {
         $merge_thread_source = $source_thread_obj;
         $merge_thread_target = $target_thread_obj;
     } else {
         $merge_thread_source = $target_thread_obj;
         $merge_thread_target = $source_thread_obj;
     }
     $thread_subject = $target_thread_obj->getSubject();
     // remember if the threads are open or closed and then close both threads !
     $targed_was_closed = $merge_thread_target->isClosed();
     $merge_thread_source->close();
     if ($targed_was_closed == false) {
         $merge_thread_target->close();
     }
     $source_all_posts = $merge_thread_source->getAllPosts();
     $source_root_node = $merge_thread_source->getFirstPostNode();
     $target_root_node = $merge_thread_target->getFirstPostNode();
     $add_difference = $target_root_node->getRgt();
     // update target root node rgt
     include_once 'Modules/Forum/classes/class.ilForumPostsTree.php';
     //		$new_target_rgt = ($target_root_node->getRgt() + $source_root_node->getRgt() + 1);
     $new_target_rgt = $target_root_node->getRgt() + $source_root_node->getRgt();
     ilForumPostsTree::updateTargetRootRgt($target_root_node->getId(), $new_target_rgt);
     $new_target_root = $target_root_node->getId();
     // get source post tree and update posts tree
     foreach ($source_all_posts as $post) {
         $post_obj = new ilForumPost($post->pos_pk);
         $posts_tree_obj = new ilForumPostsTree();
         $posts_tree_obj->setPosFk($post->pos_pk);
         if ($post_obj->getParentId() == 0) {
             $posts_tree_obj->setParentPos($new_target_root);
             //$posts_tree_obj->setRgt(($post_obj->getRgt() + $add_difference));
             $posts_tree_obj->setRgt($post_obj->getRgt() + $add_difference - 1);
             $posts_tree_obj->setLft($target_root_node->getRgt());
             $posts_tree_obj->setDepth($post_obj->getDepth() + 1);
             $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
             $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
             $posts_tree_obj->mergeParentPos();
         } else {
             $posts_tree_obj->setRgt($post_obj->getRgt() + $add_difference - 1);
             $posts_tree_obj->setLft($post_obj->getLft() + $add_difference - 1);
             $posts_tree_obj->setDepth($post_obj->getDepth() + 1);
             $posts_tree_obj->setSourceThreadId($merge_thread_source->getId());
             $posts_tree_obj->setParentPos($post_obj->getParentId());
             $posts_tree_obj->setTargetThreadId($merge_thread_target->getId());
             $posts_tree_obj->merge();
         }
     }
     // update frm_posts pos_thr_fk = target_thr_id
     include_once 'Modules/Forum/classes/class.ilForumPost.php';
     ilForumPost::mergePosts($merge_thread_source->getId(), $merge_thread_target->getId());
     // check notifications
     include_once 'Modules/Forum/classes/class.ilForumNotification.php';
     ilForumNotification::mergeThreadNotificiations($merge_thread_source->getId(), $merge_thread_target->getId());
     // delete frm_thread_access entries
     include_once './Modules/Forum/classes/class.ilObjForum.php';
     ilObjForum::_deleteAccessEntries($merge_thread_source->getId());
     // update frm_user_read
     ilObjForum::mergeForumUserRead($merge_thread_source->getId(), $merge_thread_target->getId());
     // update visits, thr_num_posts, last_post, subject
     $post_date_source = $merge_thread_source->getLastPost()->getCreateDate();
     $post_date_target = $merge_thread_target->getLastPost()->getCreateDate();
     $target_last_post = $merge_thread_target->getLastPostString();
     $exp = explode('#', $target_last_post);
     if ($post_date_source > $post_date_target) {
         $exp[2] = $merge_thread_source->getLastPost()->getId();
     } else {
         $exp[2] = $merge_thread_target->getLastPost()->getId();
     }
     $new_thr_last_post = implode('#', $exp);
     $num_posts_source = (int) $merge_thread_source->getNumPosts();
     $num_visits_source = (int) $merge_thread_source->getVisits();
     $num_posts_target = (int) $merge_thread_target->getNumPosts();
     $num_visits_target = (int) $merge_thread_source->getVisits();
     $frm_topic_obj = new ilForumTopic(0, false, true);
     $frm_topic_obj->setNumPosts($num_posts_source + $num_posts_target);
     $frm_topic_obj->setVisits($num_visits_source + $num_visits_target);
     $frm_topic_obj->setLastPostString($new_thr_last_post);
     $frm_topic_obj->setSubject($thread_subject);
     $frm_topic_obj->setId($merge_thread_target->getId());
     $frm_topic_obj->updateMergedThread();
     // update frm_data:  top_last_post , top_num_threads
     ilForum::updateLastPostByObjId($obj_id);
     // reopen target if was not "closed" before merging
     if (!$targed_was_closed) {
         $merge_thread_target->reopen();
     }
     // delete source thread
     ilForumTopic::deleteByThreadId($merge_thread_source->getId());
 }