/**
  * Update cast item
  */
 function updateCastItemObject()
 {
     global $tpl, $lng, $ilCtrl, $ilUser, $log;
     $this->checkPermission("write");
     $this->initAddCastItemForm("edit");
     if ($this->form_gui->checkInput()) {
         // create new media cast item
         include_once "./Services/News/classes/class.ilNewsItem.php";
         $mc_item = new ilNewsItem($_GET["item_id"]);
         $mob_id = $mc_item->getMobId();
         // create dummy object in db (we need an id)
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php";
         $mob = new ilObjMediaObject($mob_id);
         foreach (ilObjMediaCast::$purposes as $purpose) {
             if ($this->form_gui->getInput("delete_" . $purpose)) {
                 $mob->removeMediaItem($purpose);
                 $log->write("Mcst: deleting purpose {$purpose}");
                 continue;
             }
             $media_item = $mob->getMediaItem($purpose);
             $url_gui = $this->form_gui->getInput("url_" . $purpose);
             $file_gui = $this->form_gui->getInput("file_" . $purpose);
             if ($media_item == null) {
                 if ($purpose != "Standard" && ($url_gui || $file_gui["size"] > 0)) {
                     // check if we added an additional purpose when updating
                     // either by url or by file
                     $file = $this->createMediaItemForPurpose($mob, $purpose);
                 }
             } else {
                 $file = $this->updateMediaItem($mob, $media_item);
             }
             if ($purpose == "Standard") {
                 $duration = $this->getDuration($file);
                 $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
                 $description = $this->form_gui->getInput("description");
                 $mob->setTitle($title);
                 $mob->setDescription($description);
                 $prevpic = $this->form_gui->getInput("preview_pic");
                 if ($prevpic["size"] > 0) {
                     $mob->uploadVideoPreviewPic($prevpic);
                 } else {
                     $prevpici = $this->form_gui->getItemByPostVar("preview_pic");
                     if ($prevpici->getDeletionFlag()) {
                         $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
                     }
                 }
             }
         }
         // set real meta and object data
         $mob->update();
         //
         // @todo: save usage
         //
         $news_set = new ilSetting("news");
         $enable_internal_rss = $news_set->get("enable_rss_for_internal");
         $mc_item->setUserId($ilUser->getId());
         if (isset($duration)) {
             $mc_item->setPlaytime($duration);
         }
         $mc_item->setTitle($title);
         $mc_item->setContent($description);
         if ($enable_internal_rss) {
             $mc_item->setVisibility($this->form_gui->getInput("visibility"));
         }
         $mc_item->update();
         $ilCtrl->redirect($this, "listItems");
     } else {
         $this->populateFormFromPost();
     }
 }
 /**
  * @param string $change
  */
 public function addNews($obj_id, $change = 'created')
 {
     global $lng, $ilUser;
     $ilNewsItem = new ilNewsItem();
     $ilNewsItem->setTitle($lng->txt('news_title_' . $change));
     $ilNewsItem->setPriority(NEWS_NOTICE);
     $ilNewsItem->setContext($obj_id, $this->getType());
     $ilNewsItem->setUserId($ilUser->getId());
     $ilNewsItem->setVisibility(NEWS_USERS);
     $ilNewsItem->setContentTextIsLangVar(false);
     $ilNewsItem->create();
 }
示例#3
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();
         }
     }
 }
示例#4
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();
 }
示例#5
0
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "news":
             $mob_id = null;
             if ($a_rec["MobId"] > 0) {
                 $mob_id = $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["MobId"]);
             }
             $c = (int) $a_rec["ContextObjId"] . ":" . $a_rec["ContextObjType"] . ":" . (int) $a_rec["ContextSubObjId"] . ":" . $a_rec["ContextSubObjType"];
             $context = $a_mapping->getMapping("Services/News", "news_context", $c);
             $context = explode(":", $context);
             //var_dump($c);
             //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
             include_once "./Services/News/classes/class.ilNewsItem.php";
             $newObj = new ilNewsItem();
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setContent($a_rec["Content"]);
             $newObj->setPriority($a_rec["Priority"]);
             $newObj->setContextObjId($context[0]);
             $newObj->setContextObjType($context[1]);
             $newObj->setContextSubObjId($context[2]);
             $newObj->setContextSubObjType($context[3]);
             $newObj->setContentType($a_rec["ContentType"]);
             $newObj->setVisibility($a_rec["Visibility"]);
             $newObj->setContentLong($a_rec["ContentLong"]);
             $newObj->setContentIsLangVar($a_rec["ContentIsLangVar"]);
             $newObj->setMobId($mob_id);
             $newObj->setPlaytime($a_rec["Playtime"]);
             $newObj->create();
             $a_mapping->addMapping("Services/News", "news", $a_rec["Id"], $newObj->getId());
             break;
     }
 }
示例#6
0
 function addNewsNotification($a_lang_var)
 {
     // BEGIN WebDAV Suppress news notification for hidden files
     if ($this->isHidden()) {
         return;
     }
     // END WebDAV Suppress news notification for hidden files
     global $ilUser;
     // Add Notification to news
     include_once "./Services/News/classes/class.ilNewsItem.php";
     include_once "./Modules/File/classes/class.ilObjFileAccess.php";
     $news_item = new ilNewsItem();
     $news_item->setContext($this->getId(), $this->getType());
     $news_item->setPriority(NEWS_NOTICE);
     $news_item->setTitle($a_lang_var);
     $news_item->setContentIsLangVar(true);
     if ($this->getDescription() != "") {
         $news_item->setContent("<p>" . $this->getDescription() . "</p>");
     }
     $news_item->setUserId($ilUser->getId());
     $news_item->setVisibility(NEWS_USERS);
     $news_item->create();
 }
示例#7
0
 /**
  * Copy items
  *
  * @param
  * @return
  */
 function copyItems($a_new_obj)
 {
     global $ilUser;
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     foreach ($this->readItems(true) as $item) {
         // copy media object
         $mob_id = $item["mob_id"];
         $mob = new ilObjMediaObject($mob_id);
         $new_mob = $mob->duplicate();
         // copy news item
         // create new media cast item
         include_once "./Services/News/classes/class.ilNewsItem.php";
         $mc_item = new ilNewsItem();
         $mc_item->setMobId($new_mob->getId());
         $mc_item->setContentType(NEWS_AUDIO);
         $mc_item->setContextObjId($a_new_obj->getId());
         $mc_item->setContextObjType($a_new_obj->getType());
         $mc_item->setUserId($ilUser->getId());
         $mc_item->setPlaytime($item["playtime"]);
         $mc_item->setTitle($item["title"]);
         $mc_item->setContent($item["content"]);
         $mc_item->setVisibility($item["visibility"]);
         $mc_item->create();
     }
 }
    /**
     * generate new dataset in frm_posts
     * @param	integer	$topic
     * @param	integer	$thread
     * @param	integer	$user
     * @param	string	$message	
     * @param	integer	$parent_pos	
     * @param	integer	$notify	
     * @param	integer	$anonymize	
     * @param	string	$subject	
     * @param	datetime	$date	
     * @return	integer	$lastInsert: new post ID
     * @access	public
     */
    public function generatePost($forum_id, $thread_id, $user, $message, $parent_pos, $notify, $subject = '', $alias = '', $date = '', $status = 1, $send_activation_mail = 0)
    {
        global $ilUser, $ilDB;
        $objNewPost = new ilForumPost();
        $objNewPost->setForumId($forum_id);
        $objNewPost->setThreadId($thread_id);
        $objNewPost->setSubject($subject);
        $objNewPost->setMessage($message);
        $objNewPost->setUserId($user);
        $objNewPost->setUserAlias($alias);
        if ($date == "") {
            $objNewPost->setCreateDate(date("Y-m-d H:i:s"));
        } else {
            if (strpos($date, "-") > 0) {
                $objNewPost->setCreateDate($date);
            } else {
                $objNewPost->setCreateDate(date("Y-m-d H:i:s", $date));
            }
        }
        $objNewPost->setImportName($this->getImportName());
        $objNewPost->setNotification($notify);
        $objNewPost->setStatus($status);
        $objNewPost->insert();
        // entry in tree-table
        if ($parent_pos == 0) {
            $this->addPostTree($objNewPost->getThreadId(), $objNewPost->getId(), $objNewPost->getCreateDate());
        } else {
            $this->insertPostNode($objNewPost->getId(), $parent_pos, $objNewPost->getThreadId(), $objNewPost->getCreateDate());
        }
        //echo "<br>->".$objNewPost->getId()."-".$parent_pos."-".$objNewPost->getThreadId()."-".
        //	$objNewPost->getCreateDate()."-".$forum_id."-".$message."-".$user."-";
        // string last post
        $lastPost = $objNewPost->getForumId() . "#" . $objNewPost->getThreadId() . "#" . $objNewPost->getId();
        // update thread
        $result = $ilDB->manipulateF('
			UPDATE frm_threads 
			SET thr_num_posts = thr_num_posts + 1,
				thr_last_post = %s
			WHERE thr_pk = %s', array('text', 'integer'), array($lastPost, $objNewPost->getThreadId()));
        // update forum
        $result = $ilDB->manipulateF('
			UPDATE frm_data 
			SET top_num_posts = top_num_posts + 1,
			 	top_last_post = %s
			WHERE top_pk = %s', array('text', 'integer'), array($lastPost, $objNewPost->getForumId()));
        // MARK READ
        $forum_obj = ilObjectFactory::getInstanceByRefId($this->getForumRefId());
        $forum_obj->markPostRead($objNewPost->getUserId(), $objNewPost->getThreadId(), $objNewPost->getId());
        $pos_data = $objNewPost->getDataAsArray();
        $pos_data["ref_id"] = $this->getForumRefId();
        // Send notification to moderators if they have to enable a post
        if (!$status && $send_activation_mail) {
            $pos_data["top_name"] = $forum_obj->getTitle();
            $this->sendPostActivationNotification($pos_data);
        }
        // Add Notification to news
        if ($status) {
            require_once 'Services/RTE/classes/class.ilRTE.php';
            include_once "./Services/News/classes/class.ilNewsItem.php";
            $news_item = new ilNewsItem();
            $news_item->setContext($forum_obj->getId(), 'frm', $objNewPost->getId(), 'pos');
            $news_item->setPriority(NEWS_NOTICE);
            $news_item->setTitle($objNewPost->getSubject());
            $news_item->setContent(ilRTE::_replaceMediaObjectImageSrc($this->prepareText($objNewPost->getMessage(), 0), 1));
            $news_item->setUserId($user);
            $news_item->setVisibility(NEWS_USERS);
            $news_item->create();
        }
        return $objNewPost->getId();
    }