Esempio n. 1
0
    /**
     * Moves all posts within the current thread to a new forum
     * 
     * @param    integer 	$old_obj_id object id of the current forum
     * @param    integer 	$old_pk		primary key of old forum
     * @param    integer 	$new_obj_id	object id of the new forum
     * @param    integer 	$new_pk		primary key of new forum
     * @return	integer 	number of afffected rows by updating posts
     * @access	public
     */
    public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk)
    {
        global $ilDB;
        if ($this->id) {
            $nodes = $this->getAllPosts();
            if (is_array($nodes)) {
                // Move attachments
                foreach ($nodes as $node) {
                    $file_obj = new ilFileDataForum((int) $old_obj_id, (int) $node->pos_pk);
                    $file_obj->moveFilesOfPost((int) $new_obj_id);
                    unset($file_obj);
                }
            }
            $this->db->lockTables(array(0 => array('name' => 'frm_user_read', 'type' => ilDB::LOCK_WRITE), 1 => array('name' => 'frm_thread_access', 'type' => ilDB::LOCK_WRITE)));
            $this->db->manipulateF('
				DELETE FROM frm_user_read
				WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				UPDATE frm_user_read
				SET obj_id = %s
				WHERE thread_id = %s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				DELETE FROM frm_thread_access
				WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->manipulateF('
				UPDATE frm_thread_access
				SET obj_id = %s
				WHERE thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id));
            $this->db->unlockTables();
            $this->db->manipulateF('
				UPDATE frm_posts
				SET pos_top_fk = %s
				WHERE pos_thr_fk = %s', array('integer', 'integer'), array($new_pk, $this->id));
            // update all related news
            $posts = $ilDB->queryf('
				SELECT * FROM frm_posts WHERE pos_thr_fk = %s', array('integer'), array($this->id));
            $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk);
            $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk);
            while ($post = $posts->fetchRow(DB_FETCHMODE_ASSOC)) {
                include_once "./Services/News/classes/class.ilNewsItem.php";
                $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id, "frm", $post["pos_pk"], "pos");
                $news_item = new ilNewsItem($news_id);
                $news_item->setContextObjId($new_obj_id);
                $news_item->update();
                //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-";
            }
            return count($nodes);
        }
        return 0;
    }
 /**
  * Delete news items.
  */
 function determinePlaytimeObject()
 {
     global $ilCtrl, $lng;
     $mc_item = new ilNewsItem($_GET["item_id"]);
     $mob = $mc_item->getMobId();
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     $mob = new ilObjMediaObject($mob);
     $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
     $m_item = $mob->getMediaItem("Standard");
     $file = $mob_dir . "/" . $m_item->getLocation();
     $duration = $this->getDuration($file);
     if ($duration != "00:00:00") {
         $mc_item->setPlaytime($duration);
         $mc_item->update();
         ilUtil::sendSuccess($lng->txt("mcst_set_playtime"), true);
     } else {
         ilUtil::sendFailure($lng->txt("mcst_unable_to_determin_playtime"), true);
     }
     $ilCtrl->redirect($this, "listItems");
 }
Esempio n. 3
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();
 }
Esempio n. 4
0
 /**
  * Create
  */
 function updateNews($a_update = false)
 {
     global $ilUser;
     $news_set = new ilSetting("news");
     $default_visibility = $news_set->get("default_visibility") != "" ? $news_set->get("default_visibility") : "users";
     include_once "./Services/News/classes/class.ilNewsItem.php";
     if (!$a_update) {
         $news_item = new ilNewsItem();
         $news_item->setContext($this->getWikiId(), "wiki", $this->getId(), "wpg");
         $news_item->setPriority(NEWS_NOTICE);
         $news_item->setTitle($this->getTitle());
         $news_item->setContentTextIsLangVar(true);
         $news_item->setContent("wiki_news_page_created");
         $news_item->setUserId($ilUser->getId());
         $news_item->setVisibility($default_visibility);
         $news_item->create();
     } else {
         // get last news item of the day (if existing)
         $news_id = ilNewsItem::getLastNewsIdForContext($this->getWikiId(), "wiki", $this->getId(), "wpg", true);
         if ($news_id > 0) {
             $news_item = new ilNewsItem($news_id);
             $news_item->setContent("wiki_news_page_changed");
             $news_item->setUserId($ilUser->getId());
             $news_item->setTitle($this->getTitle());
             $news_item->setContentTextIsLangVar(true);
             $news_item->update(true);
         } else {
             $news_item = new ilNewsItem();
             $news_item->setContext($this->getWikiId(), "wiki", $this->getId(), "wpg");
             $news_item->setPriority(NEWS_NOTICE);
             $news_item->setTitle($this->getTitle());
             $news_item->setContentTextIsLangVar(true);
             $news_item->setContent("wiki_news_page_changed");
             $news_item->setUserId($ilUser->getId());
             $news_item->setVisibility($default_visibility);
             $news_item->create();
         }
     }
 }
    /**
     * update dataset in frm_posts with censorship info
     * @param	string	message	
     * @param	integer	pos_pk	
     * @return	boolean
     * @access	public
     */
    public function postCensorship($message, $pos_pk, $cens = 0)
    {
        global $ilDB;
        $statement = $ilDB->manipulateF('
			UPDATE frm_posts
			SET pos_cens_com = %s,
				pos_update = %s,
				pos_cens = %s,
				update_user = %s
			WHERE pos_pk = %s', array('text', 'timestamp', 'integer', 'integer', 'integer'), array($message, date("Y-m-d H:i:s"), $cens, $_SESSION['AccountId'], $pos_pk));
        // Change news item accordingly
        include_once "./Services/News/classes/class.ilNewsItem.php";
        $news_id = ilNewsItem::getFirstNewsIdForContext($this->id, "frm", $pos_pk, "pos");
        if ($news_id > 0) {
            if ($cens > 0) {
                $news_item = new ilNewsItem($news_id);
                //$news_item->setTitle($subject);
                $news_item->setContent(nl2br($this->prepareText($message, 0)));
                $news_item->update();
            } else {
                // get original message
                $res = $ilDB->queryf('
					SELECT * FROM frm_posts
					WHERE pos_pk = %s', array('integer'), array($pos_pk));
                $rec = $ilDB->fetchAssoc($res);
                $news_item = new ilNewsItem($news_id);
                //$news_item->setTitle($subject);
                $news_item->setContent(nl2br($this->prepareText($rec["pos_message"], 0)));
                $news_item->update();
            }
        }
        return true;
    }