/** * Returns the number of bytes used on the harddisk by the specified forum * @static * @param int $a_obj_id * @return int */ public static function _lookupDiskUsage($a_obj_id) { /** * @var $ilDB ilDB */ global $ilDB; require_once 'Modules/Forum/classes/class.ilFileDataForum.php'; $res = $ilDB->queryf('SELECT top_frm_fk, pos_pk FROM frm_posts p JOIN frm_data d ON d.top_pk = p.pos_top_fk WHERE top_frm_fk = %s', array('integer'), array($a_obj_id)); $size = 0; while ($row = $ilDB->fetchAssoc($res)) { $fileDataForum = new ilFileDataForum($row['top_frm_fk'], $row['pos_pk']); $filesOfPost = $fileDataForum->getFilesOfPost(); foreach ($filesOfPost as $attachment) { $size += $attachment['size']; } unset($fileDataForum); unset($filesOfPost); } return $size; }
/** * 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; }
/** * Clone Object * @param int $a_target_id * @param int $a_copy_id * @return object */ public function cloneObject($a_target_id, $a_copy_id = 0) { /** * @var $ilDB ilDB */ global $ilDB; $new_obj = parent::cloneObject($a_target_id, $a_copy_id); $this->cloneAutoGeneratedRoles($new_obj); ilForumProperties::getInstance($this->getId())->copy($new_obj->getId()); $this->Forum->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($this->getId())); $topData = $this->Forum->getOneTopic(); $nextId = $ilDB->nextId('frm_data'); $statement = $ilDB->insert('frm_data', array('top_pk' => array('integer', $nextId), 'top_frm_fk' => array('integer', $new_obj->getId()), 'top_name' => array('text', $topData['top_name']), 'top_description' => array('text', $topData['top_description']), 'top_num_posts' => array('integer', $topData['top_num_posts']), 'top_num_threads' => array('integer', $topData['top_num_threads']), 'top_last_post' => array('text', $topData['top_last_post']), 'top_mods' => array('integer', !is_numeric($topData['top_mods']) ? 0 : $topData['top_mods']), 'top_date' => array('timestamp', $topData['top_date']), 'visits' => array('integer', $topData['visits']), 'top_update' => array('timestamp', $topData['top_update']), 'update_user' => array('integer', $topData['update_user']), 'top_usr_id' => array('integer', $topData['top_usr_id']))); // read options include_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php'; $cwo = ilCopyWizardOptions::_getInstance($a_copy_id); $options = $cwo->getOptions($this->getRefId()); $options['threads'] = $this->Forum->_getThreads($this->getId()); // Generate starting threads include_once 'Modules/Forum/classes/class.ilFileDataForum.php'; $new_frm = $new_obj->Forum; $new_frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($new_obj->getId())); $new_frm->setForumId($new_obj->getId()); $new_frm->setForumRefId($new_obj->getRefId()); $new_topic = $new_frm->getOneTopic(); foreach ($options['threads'] as $thread_id => $thread_subject) { $this->Forum->setMDB2WhereCondition('thr_pk = %s ', array('integer'), array($thread_id)); $old_thread = $this->Forum->getOneThread(); $old_post_id = $this->Forum->getFirstPostByThread($old_thread['thr_pk']); $old_post = $this->Forum->getOnePost($old_post_id); // Now create new thread and first post $new_post = $new_frm->generateThread($new_topic['top_pk'], $old_thread['thr_usr_id'], $old_thread['thr_subject'], ilForum::_lookupPostMessage($old_post_id), $old_post['notify'], 0, $old_thread['thr_usr_alias'], $old_thread['thr_date']); // Copy attachments $old_forum_files = new ilFileDataForum($this->getId(), $old_post_id); $old_forum_files->ilClone($new_obj->getId(), $new_post); } return $new_obj; }
public function addThreadObject($a_prevent_redirect = false) { /** * @var $ilUser ilObjUser * @var $ilAccess ilAccessHandler * @var $lng ilLanguage */ global $ilUser, $ilAccess, $lng; $frm = $this->object->Forum; $frm->setForumId($this->object->getId()); $frm->setForumRefId($this->object->getRefId()); if (!$ilAccess->checkAccess('add_thread', '', $this->object->getRefId())) { $this->ilias->raiseError($lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE); } $frm->setMDB2WhereCondition('top_frm_fk = %s ', array('integer'), array($frm->getForumId())); $topicData = $frm->getOneTopic(); $this->initTopicCreateForm(); if ($this->create_topic_form_gui->checkInput()) { require_once 'Services/Captcha/classes/class.ilCaptchaUtil.php'; if ($ilUser->isAnonymous() && !$ilUser->isCaptchaVerified() && ilCaptchaUtil::isActiveForForum()) { $ilUser->setCaptchaVerified(true); } if ($this->objProperties->isAnonymized()) { if (!strlen($this->create_topic_form_gui->getInput('alias'))) { $user_alias = $this->lng->txt('forums_anonymous'); } else { $user_alias = $this->create_topic_form_gui->getInput('alias'); } } else { $user_alias = $ilUser->getLogin(); } $status = 1; if ($this->objProperties->isPostActivationEnabled() && !$this->is_moderator || $this->objCurrentPost->isAnyParentDeactivated()) { $status = 0; } // build new thread $newPost = $frm->generateThread($topicData['top_pk'], $ilUser->getId(), $this->objProperties->isAnonymized() ? 0 : $ilUser->getId(), $this->handleFormInput($this->create_topic_form_gui->getInput('subject'), false), ilRTE::_replaceMediaObjectImageSrc($this->create_topic_form_gui->getInput('message'), 0), $this->create_topic_form_gui->getItemByPostVar('notify') ? (int) $this->create_topic_form_gui->getInput('notify') : 0, $this->create_topic_form_gui->getItemByPostVar('notify_posts') ? (int) $this->create_topic_form_gui->getInput('notify_posts') : 0, $user_alias, '', $status); $file = $_FILES['userfile']; // file upload if (is_array($file) && !empty($file)) { $tmp_file_obj = new ilFileDataForum($this->object->getId(), $newPost); $tmp_file_obj->storeUploadedFile($file); } // Visit-Counter $frm->setDbTable('frm_data'); $frm->setMDB2WhereCondition('top_pk = %s ', array('integer'), array($topicData['top_pk'])); $frm->updateVisits($topicData['top_pk']); $frm->setMDB2WhereCondition('thr_top_fk = %s AND thr_subject = %s AND thr_num_posts = 1 ', array('integer', 'text'), array($topicData['top_pk'], $this->create_topic_form_gui->getInput('subject'))); // copy temporary media objects (frm~) include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; $mediaObjects = ilRTE::_getMediaObjects($this->create_topic_form_gui->getInput('message'), 0); foreach ($mediaObjects as $mob) { if (ilObjMediaObject::_exists($mob)) { ilObjMediaObject::_removeUsage($mob, 'frm~:html', $ilUser->getId()); ilObjMediaObject::_saveUsage($mob, 'frm:html', $newPost); } } if ($this->ilias->getSetting('forum_notification') == 1) { // send notification about new topic $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->sendForumNotifications($post_data); } if (!$a_prevent_redirect) { ilUtil::sendSuccess($this->lng->txt('forums_thread_new_entry'), true); $this->ctrl->redirect($this); } else { return $newPost; } } else { $this->create_topic_form_gui->setValuesByPost(); if (!$this->objProperties->isAnonymized()) { $this->create_topic_form_gui->getItemByPostVar('alias')->setValue($ilUser->getLogin()); } return $this->tpl->setContent($this->create_topic_form_gui->getHTML()); } }
/** * handler for end of element * * @param resource $a_xml_parser xml parser * @param string $a_name element name */ public function handlerEndTag($a_xml_parser, $a_name) { global $ilDB, $ilUser; $this->cdata = trim($this->cdata); $arrayname = strtolower($this->entity) . 'Array'; $x =& $this->{$arrayname}; switch ($a_name) { case 'Forum': $query_num_posts = "SELECT COUNT(pos_pk) cnt\n\t\t\t\t\t\t\t\t\t\tFROM frm_posts\n\t\t\t\t\t\t\t\t\tWHERE pos_top_fk = " . $ilDB->quote($this->lastHandledForumId, 'integer'); $res_pos = $ilDB->query($query_num_posts); $data_pos = $ilDB->fetchAssoc($res_pos); $num_posts = $data_pos['cnt']; $query_num_threads = "SELECT COUNT(thr_pk) cnt\n\t\t\t\t\t\t\t\t\t\tFROM frm_threads\n\t\t\t\t\t\t\t\t\t WHERE thr_top_fk = " . $ilDB->quote($this->lastHandledForumId, 'integer'); $res_thr = $ilDB->query($query_num_threads); $data_thr = $ilDB->fetchAssoc($res_thr); $num_threads = $data_thr['cnt']; $update_str = "{$this->lastHandledForumId}#{$this->lastHandledThreadId}#{$this->lastHandledPostId}"; $ilDB->manipulateF("UPDATE frm_data \n\t\t\t\t\t\tSET top_last_post = %s,\n\t\t\t\t\t\t\ttop_num_posts = %s,\n\t\t\t\t\t\t\ttop_num_threads = %s\n\t\t\t\t\tWHERE top_frm_fk = %s", array('text', 'integer', 'integer', 'integer'), array($update_str, $num_posts, $num_threads, $this->forum_obj_id)); break; case 'Id': $x['Id'] = $this->cdata; break; case 'ObjId': $x['ObjId'] = $this->cdata; break; case 'Title': $x['Title'] = $this->cdata; break; case 'Description': $x['Description'] = $this->cdata; break; case 'DefaultView': $x['DefaultView'] = $this->cdata; break; case 'Pseudonyms': $x['Pseudonyms'] = $this->cdata; break; case 'Statistics': $x['Statistics'] = $this->cdata; break; case 'PostingActivation': $x['PostingActivation'] = $this->cdata; break; case 'PresetSubject': $x['PresetSubject'] = $this->cdata; break; case 'PresetRe': $x['PresetRe'] = $this->cdata; break; case 'NotificationType': $x['NotificationType'] = $this->cdata; break; case 'ForceNotification': $x['ForceNotification'] = $this->cdata; break; case 'ToggleNotification': $x['ToggleNotification'] = $this->cdata; break; case 'LastPost': $x['LastPost'] = $this->cdata; break; case 'Moderator': $x['Moderator'] = $this->cdata; break; case 'CreateDate': $x['CreateDate'] = $this->cdata; break; case 'UpdateDate': $x['UpdateDate'] = $this->cdata; break; case 'UpdateUserId': $x['UpdateUserId'] = $this->cdata; break; case 'UserId': $x['UserId'] = $this->cdata; if ($this->entity == 'forum' && $this->forumArray) { //// @todo: Maybe problems if the forum xml is imported as content of a course // createSettings accesses superglobal $_GET array, which can cause problems // with public_notifications of block settings $this->forum->createSettings(); $forum_array = $this->getUserIdAndAlias($this->forumArray['UserId'], ''); // Store old user id $oldUsrId = $ilUser->getId(); // Manipulate user object $ilUser->setId($forum_array['usr_id']); // create frm_data $this->forum->saveData(array()); // Restore old user id $ilUser->setId($oldUsrId); $update_forum_array = $this->getUserIdAndAlias($this->forumArray['UpdateUserId'], ''); // Store old user id $oldUsrId = $_SESSION["AccountId"]; // Manipulate user object $_SESSION["AccountId"] = $update_forum_array['usr_id']; $this->forum->setTitle($this->forumArray["Title"]); $this->forum->setDescription($this->forumArray["Description"]); $this->forum->update(); // Restore old user id $_SESSION["AccountId"] = $oldUsrId; // create frm_settings $newObjProp = ilForumProperties::getInstance($this->forum->getId()); $newObjProp->setDefaultView((int) $this->forumArray['DefaultView']); $newObjProp->setAnonymisation((int) $this->forumArray['Pseudonyms']); $newObjProp->setStatisticsStatus((int) $this->forumArray['Statistics']); $newObjProp->setPostActivation((int) $this->forumArray['PostingActivation']); $newObjProp->setPresetSubject((int) $this->forumArray['PresetSubject']); $newObjProp->setAddReSubject((int) $this->forumArray['PresetRe']); $newObjProp->setNotificationType($this->forumArray['NotificationType'] ? $this->forumArray['NotificationType'] : 'all_users'); $newObjProp->setAdminForceNoti((int) $this->forumArray['ForceNotification']); $newObjProp->setUserToggleNoti((int) $this->forumArray['ToggleNotification']); $newObjProp->insert(); $id = $this->getNewForumPk(); $this->forum_obj_id = $newObjProp->getObjId(); $this->mapping['frm'][$this->forumArray['Id']] = $id; $this->lastHandledForumId = $id; unset($this->forumArray); } break; case 'Thread': $update_str = "{$this->lastHandledForumId}#{$this->lastHandledThreadId}#{$this->lastHandledPostId}"; $ilDB->manipulateF("UPDATE frm_threads\n\t\t\t\t\t\tSET thr_last_post = %s\n\t\t\t\t\tWHERE thr_pk = %s", array('text', 'integer'), array($update_str, $this->lastHandledThreadId)); break; case 'Subject': $x['Subject'] = $this->cdata; break; case 'Alias': $x['Alias'] = $this->cdata; break; case 'Sticky': $x['Sticky'] = $this->cdata; break; case 'Closed': $x['Closed'] = $this->cdata; if ($this->entity == 'thread' && $this->threadArray) { require_once 'Modules/Forum/classes/class.ilForumTopic.php'; $this->forumThread = new ilForumTopic(); $this->forumThread->setId($this->threadArray['Id']); $this->forumThread->setForumId($this->lastHandledForumId); $this->forumThread->setSubject($this->threadArray['Subject']); $this->forumThread->setSticky($this->threadArray['Sticky']); $this->forumThread->setClosed($this->threadArray['Closed']); $this->forumThread->setCreateDate($this->threadArray['CreateDate']); $this->forumThread->setChangeDate($this->threadArray['UpdateDate']); $this->forumThread->setImportName($this->threadArray['ImportName']); $usr_data = $this->getUserIdAndAlias($this->threadArray['UserId'], $this->threadArray['Alias']); $this->forumThread->setUserId($usr_data['usr_id']); $this->forumThread->setUserAlias($usr_data['usr_alias']); $this->forumThread->insert(); $this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId(); $this->lastHandledThreadId = $this->forumThread->getId(); unset($this->threadArray); } break; case 'Post': break; case 'Censorship': $x['Censorship'] = $this->cdata; break; case 'CensorshipMessage': $x['CensorshipMessage'] = $this->cdata; break; case 'Notification': $x['Notification'] = $this->cdata; break; case 'ImportName': $x['ImportName'] = $this->cdata; break; case 'Status': $x['Status'] = $this->cdata; break; case 'Message': $x['Message'] = $this->cdata; break; case 'Lft': $x['Lft'] = $this->cdata; break; case 'Rgt': $x['Rgt'] = $this->cdata; break; case 'Depth': $x['Depth'] = $this->cdata; break; case 'ParentId': $x['ParentId'] = $this->cdata; if ($this->entity == 'post' && $this->postArray) { require_once 'Modules/Forum/classes/class.ilForumPost.php'; $this->forumPost = new ilForumPost(); $this->forumPost->setId($this->postArray['Id']); $this->forumPost->setCensorship($this->postArray['Censorship']); $this->forumPost->setCensorshipComment($this->postArray['CensorshipMessage']); $this->forumPost->setNotification($this->postArray['Notification']); $this->forumPost->setImportName($this->postArray['ImportName']); $this->forumPost->setStatus($this->postArray['Status']); $this->forumPost->setMessage($this->postArray['Message']); $this->forumPost->setSubject($this->postArray['Subject']); $this->forumPost->setLft($this->postArray['Lft']); $this->forumPost->setRgt($this->postArray['Rgt']); $this->forumPost->setDepth($this->postArray['Depth']); $this->forumPost->setParentId($this->postArray['ParentId']); $this->forumPost->setThread($this->forumThread); $this->forumPost->setThreadId($this->lastHandledThreadId); $this->forumPost->setForumId($this->lastHandledForumId); $this->forumPost->setCreateDate($this->postArray['CreateDate']); $this->forumPost->setChangeDate($this->postArray['UpdateDate']); $usr_data = $this->getUserIdAndAlias($this->postArray['UserId'], $this->postArray['Alias']); $update_usr_data = $this->getUserIdAndAlias($this->postArray['UpdateUserId']); $this->forumPost->setUserId($usr_data['usr_id']); $this->forumPost->setUserAlias($usr_data['usr_alias']); $this->forumPost->setUpdateUserId($update_usr_data['usr_id']); $this->forumPost->insert(); if ($this->mapping['pos'][$this->postArray['ParentId']]) { $parentId = $this->mapping['pos'][$this->postArray['ParentId']]; } else { $parentId = 0; } $postTreeNodeId = $ilDB->nextId('frm_posts_tree'); $ilDB->insert('frm_posts_tree', array('fpt_pk' => array('integer', $postTreeNodeId), 'thr_fk' => array('integer', $this->lastHandledThreadId), 'pos_fk' => array('integer', $this->forumPost->getId()), 'parent_pos' => array('integer', $parentId), 'lft' => array('integer', $this->postArray['Lft']), 'rgt' => array('integer', $this->postArray['Rgt']), 'depth' => array('integer', $this->postArray['Depth']), 'fpt_date' => array('timestamp', date('Y-m-d H:i:s')))); $this->mapping['pos'][$this->postArray['Id']] = $this->forumPost->getId(); $this->lastHandledPostId = $this->forumPost->getId(); $media_objects_found = false; foreach ($this->mediaObjects as $mob_attr) { $importfile = $this->getImportDirectory() . '/' . $mob_attr['uri']; if (file_exists($importfile)) { $mob = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false); ilObjMediaObject::_saveUsage($mob->getId(), "frm:html", $this->forumPost->getId()); $this->forumPost->setMessage(str_replace(array("src=\"" . $mob_attr["label"] . "\"", "src=\"" . preg_replace("/(il)_[\\d]+_(mob)_([\\d]+)/", "\$1_0_\$2_\$3", $mob_attr["label"]) . "\""), "src=\"" . "il_" . IL_INST_ID . "_mob_" . $mob->getId() . "\"", $this->forumPost->getMessage())); $media_objects_found = true; } } if ($media_objects_found) { $this->forumPost->update(); } unset($this->postArray); } break; case 'Content': $x['content'] = $this->cdata; break; case 'Attachment': $filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId); $importPath = $this->contentArray['content']; if (strlen($importPath)) { $importPath = $this->getImportDirectory() . '/' . $importPath; $newFilename = preg_replace("/^\\d+_\\d+(_.*)/ims", $this->forum->getId() . "_" . $this->lastHandledPostId . "\$1", basename($importPath)); $path = $filedata->getForumPath(); $newPath = $path . '/' . $newFilename; @copy($importPath, $newPath); } break; } $this->cdata = ''; return; }
function start() { global $ilDB; ilUtil::makeDir($this->target_dir_absolute . "/objects"); $query_frm = 'SELECT * FROM frm_settings fs ' . 'JOIN object_data od ON fs.obj_id = od.obj_id ' . 'JOIN frm_data ON top_frm_fk = od.obj_id ' . 'WHERE fs.obj_id = ' . $ilDB->quote($this->forum_id, 'integer'); $res = $ilDB->query($query_frm); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { break; } $this->xmlStartTag("Forum", null); $this->xmlElement("Id", null, (int) $row->top_pk); $this->xmlElement("ObjId", null, (int) $row->obj_id); $this->xmlElement("Title", null, $row->title); $this->xmlElement("Description", null, $row->description); $this->xmlElement("DefaultView", null, (int) $row->default_view); $this->xmlElement("Pseudonyms", null, (int) $row->anonymized); $this->xmlElement("Statistics", null, (int) $row->statistics_enabled); $this->xmlElement("PostingActivation", null, (int) $row->post_activation); $this->xmlElement("PresetSubject", null, (int) $row->preset_subject); $this->xmlElement("PresetRe", null, (int) $row->add_re_subject); $this->xmlElement("NotificationType", null, $row->notification_type); $this->xmlElement("ForceNotification", null, (int) $row->admin_force_noti); $this->xmlElement("ToggleNotification", null, (int) $row->user_toggle_noti); $this->xmlElement("LastPost", null, $row->top_last_post); $this->xmlElement("Moderator", null, (int) $row->top_mods); $this->xmlElement("CreateDate", null, $row->top_date); $this->xmlElement("UpdateDate", null, $row->top_update); $this->xmlElement("UpdateUserId", null, $row->update_user); $this->xmlElement("UserId", null, (int) $row->top_usr_id); $query_thr = "SELECT frm_threads.* " . " FROM frm_threads " . " INNER JOIN frm_data ON top_pk = thr_top_fk " . 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer'); $res = $ilDB->query($query_thr); while ($row = $ilDB->fetchObject($res)) { $this->xmlStartTag("Thread"); $this->xmlElement("Id", null, (int) $row->thr_pk); $this->xmlElement("Subject", null, $row->thr_subject); $this->xmlElement("UserId", null, (int) $row->thr_usr_id); $this->xmlElement("Alias", null, $row->thr_usr_alias); $this->xmlElement("LastPost", null, $row->thr_last_post); $this->xmlElement("CreateDate", null, $row->thr_date); $this->xmlElement("UpdateDate", null, $row->thr_date); $this->xmlElement("ImportName", null, $row->import_name); $this->xmlElement("Sticky", null, (int) $row->is_sticky); $this->xmlElement("Closed", null, (int) $row->is_closed); $query = 'SELECT frm_posts.*, frm_posts_tree.* FROM frm_posts INNER JOIN frm_data ON top_pk = pos_top_fk INNER JOIN frm_posts_tree ON pos_fk = pos_pk WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' '; $query .= " ORDER BY frm_posts_tree.lft ASC"; $resPosts = $ilDB->query($query); $lastDepth = null; while ($rowPost = $ilDB->fetchObject($resPosts)) { /* // Used for nested postings if( $rowPost->depth < $lastDepth ) { for( $i = $rowPost->depth; $i <= $lastDepth; $i++ ) { $this->xmlEndTag("Post"); } }*/ $this->xmlStartTag("Post"); $this->xmlElement("Id", null, (int) $rowPost->pos_pk); $this->xmlElement("UserId", null, (int) $rowPost->pos_usr_id); $this->xmlElement("Alias", null, $rowPost->pos_usr_alias); $this->xmlElement("Subject", null, $rowPost->pos_subject); $this->xmlElement("CreateDate", null, $rowPost->pos_date); $this->xmlElement("UpdateDate", null, $rowPost->pos_update); $this->xmlElement("UpdateUserId", null, (int) $rowPost->update_user); $this->xmlElement("Censorship", null, (int) $rowPost->pos_cens); $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com); $this->xmlElement("Notification", null, $rowPost->notify); $this->xmlElement("ImportName", null, $rowPost->import_name); $this->xmlElement("Status", null, (int) $rowPost->pos_status); $this->xmlElement("Message", null, ilRTE::_replaceMediaObjectImageSrc($rowPost->pos_message, 0)); $media_exists = false; $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', $rowPost->pos_pk); foreach ($mobs as $mob) { $moblabel = "il_" . IL_INST_ID . "_mob_" . $mob; if (ilObjMediaObject::_exists($mob)) { if (!$media_exists) { $this->xmlStartTag("MessageMediaObjects"); $media_exists = true; } $mob_obj = new ilObjMediaObject($mob); $imgattrs = array("label" => $moblabel, "uri" => $this->target_dir_relative . "/objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()); $this->xmlElement("MediaObject", $imgattrs, NULL); $mob_obj->exportFiles($this->target_dir_absolute); } } if ($media_exists) { $this->xmlEndTag("MessageMediaObjects"); } $this->xmlElement("Lft", null, (int) $rowPost->lft); $this->xmlElement("Rgt", null, (int) $rowPost->rgt); $this->xmlElement("Depth", null, (int) $rowPost->depth); $this->xmlElement("ParentId", null, (int) $rowPost->parent_pos); $tmp_file_obj = new ilFileDataForum($this->forum_id, $rowPost->pos_pk); $set = array(); if (count($tmp_file_obj->getFilesOfPost())) { foreach ($tmp_file_obj->getFilesOfPost() as $file) { $this->xmlStartTag("Attachment"); copy($file['path'], $this->target_dir_absolute . "/" . basename($file['path'])); $content = $this->target_dir_relative . "/" . basename($file['path']); $this->xmlElement("Content", null, $content); $this->xmlEndTag("Attachment"); } } //Used for nested postings //$lastDepth = $rowPost->depth; $this->xmlEndTag("Post"); } /* // Used for nested postings if( $lastDepth ) { for( $i = 1; $i <= $lastDepth ; $i++ ) { $this->xmlEndTag("Post"); } $lastDepth = null; }*/ $this->xmlEndTag("Thread"); } $this->xmlEndTag("Forum"); return true; }
protected function sendMails($res) { global $ilAccess, $ilDB, $lng; static $cache = array(); static $attachments_cache = array(); include_once 'Modules/Forum/classes/class.ilObjForum.php'; include_once 'Services/Mail/classes/class.ilMail.php'; include_once 'Services/User/classes/class.ilObjUser.php'; include_once 'Services/Language/classes/class.ilLanguage.php'; $forumObj = new ilObjForum(); $frm = $forumObj->Forum; $numRows = 0; $mail_obj = new ilMail(ANONYMOUS_USER_ID); $mail_obj->enableSOAP(false); while ($row = $ilDB->fetchAssoc($res)) { // don not send a notification to the post author if ($row['pos_display_user_id'] != $row['user_id']) { // GET AUTHOR OF NEW POST if ($row['pos_display_user_id']) { $row['pos_usr_name'] = ilObjUser::_lookupLogin($row['pos_display_user_id']); } else { if (strlen($row['pos_usr_alias'])) { $row['pos_usr_name'] = $row['pos_usr_alias'] . ' (' . $lng->txt('frm_pseudonym') . ')'; } } if ($row['pos_usr_name'] == '') { $row['pos_usr_name'] = $lng->txt('forums_anonymous'); } // get all references of obj_id if (!isset($cache[$row['obj_id']])) { $cache[$row['obj_id']] = ilObject::_getAllReferences($row['obj_id']); } // check for attachments $has_attachments = false; if (!isset($attachments_cache[$row['obj_id']][$row['pos_pk']])) { $fileDataForum = new ilFileDataForum($row['obj_id'], $row['pos_pk']); $filesOfPost = $fileDataForum->getFilesOfPost(); foreach ($filesOfPost as $attachment) { $attachments_cache[$row['obj_id']][$row['pos_pk']][] = $attachment['name']; $has_attachments = true; } } else { $has_attachments = true; } // do rbac check before sending notification $send_mail = false; foreach ((array) $cache[$row['obj_id']] as $ref_id) { if ($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) { $row['ref_id'] = $ref_id; $send_mail = true; break; } } $attached_files = array(); if ($has_attachments == true) { $attached_files = $attachments_cache[$row['obj_id']][$row['pos_pk']]; } if ($send_mail) { $frm->setLanguage(ilForum::_getLanguageInstanceByUsrId($row['user_id'])); $mail_obj->sendMail(ilObjUser::_lookupLogin($row['user_id']), '', '', $frm->formatNotificationSubject($row), $frm->formatNotification($row, 1, $attached_files, $row['user_id']), array(), array('normal')); $numRows++; } } } return $numRows; }
function start() { global $ilDB; $query_frm = 'SELECT * FROM frm_settings fs ' . 'JOIN object_data od ON fs.obj_id = od.obj_id ' . 'JOIN frm_data ON top_frm_fk = od.obj_id ' . 'WHERE fs.obj_id = ' . $ilDB->quote($this->forum_id, 'integer'); $res = $ilDB->query($query_frm); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { break; } $this->xmlStartTag("Forum", null); $this->xmlElement("Id", null, (int) $row->top_pk); $this->xmlElement("ObjId", null, (int) $row->obj_id); $this->xmlElement("Title", null, $row->title); $this->xmlElement("Description", null, $row->description); $this->xmlElement("DefaultView", null, (int) $row->default_view); $this->xmlElement("Pseudonyms", null, (int) $row->anonymized); $this->xmlElement("Statistics", null, (int) $row->statistics_enabled); $this->xmlElement("PostingActivation", null, (int) $row->post_activation); $this->xmlElement("PresetSubject", null, (int) $row->preset_subject); $this->xmlElement("PresetRe", null, (int) $row->add_re_subject); $this->xmlElement("NotificationType", null, $row->notification_type); $this->xmlElement("ForceNotification", null, (int) $row->admin_force_noti); $this->xmlElement("ToggleNotification", null, (int) $row->user_toggle_noti); $this->xmlElement("LastPost", null, $row->top_last_post); $this->xmlElement("Moderator", null, (int) $row->top_mods); $this->xmlElement("CreateDate", null, $row->top_date); $this->xmlElement("UpdateDate", null, $row->top_update); $this->xmlElement("UpdateUserId", null, $row->update_user); $this->xmlElement("UserId", null, (int) $row->top_usr_id); $query_thr = "SELECT frm_threads.* " . " FROM frm_threads " . " INNER JOIN frm_data ON top_pk = thr_top_fk " . 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer'); $res = $ilDB->query($query_thr); while ($row = $ilDB->fetchObject($res)) { $this->xmlStartTag("Thread"); $this->xmlElement("Id", null, (int) $row->thr_pk); $this->xmlElement("Subject", null, $row->thr_subject); $this->xmlElement("UserId", null, (int) $row->thr_usr_id); $this->xmlElement("Alias", null, $row->thr_usr_alias); $this->xmlElement("LastPost", null, $row->thr_last_post); $this->xmlElement("CreateDate", null, $row->thr_date); $this->xmlElement("UpdateDate", null, $row->thr_date); $this->xmlElement("ImportName", null, $row->import_name); $this->xmlElement("Sticky", null, (int) $row->is_sticky); $this->xmlElement("Closed", null, (int) $row->is_closed); $query = 'SELECT frm_posts.*, frm_posts_tree.* FROM frm_posts INNER JOIN frm_data ON top_pk = pos_top_fk INNER JOIN frm_posts_tree ON pos_fk = pos_pk WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' '; $query .= " ORDER BY frm_posts_tree.lft ASC"; $resPosts = $ilDB->query($query); $lastDepth = null; while ($rowPost = $ilDB->fetchObject($resPosts)) { /* // Used for nested postings if( $rowPost->depth < $lastDepth ) { for( $i = $rowPost->depth; $i <= $lastDepth; $i++ ) { $this->xmlEndTag("Post"); } }*/ $this->xmlStartTag("Post"); $this->xmlElement("Id", null, (int) $rowPost->pos_pk); $this->xmlElement("UserId", null, (int) $rowPost->pos_usr_id); $this->xmlElement("Alias", null, $rowPost->pos_usr_alias); $this->xmlElement("Subject", null, $rowPost->pos_subject); $this->xmlElement("CreateDate", null, $rowPost->pos_date); $this->xmlElement("UpdateDate", null, $rowPost->pos_update); $this->xmlElement("UpdateUserId", null, (int) $rowPost->update_user); $this->xmlElement("Censorship", null, (int) $rowPost->pos_cens); $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com); $this->xmlElement("Notification", null, $rowPost->notify); $this->xmlElement("ImportName", null, $rowPost->import_name); $this->xmlElement("Status", null, (int) $rowPost->pos_status); $this->xmlElement("Message", null, $rowPost->pos_message); $this->xmlElement("Lft", null, (int) $rowPost->lft); $this->xmlElement("Rgt", null, (int) $rowPost->rgt); $this->xmlElement("Depth", null, (int) $rowPost->depth); $this->xmlElement("ParentId", null, (int) $rowPost->parent_pos); $tmp_file_obj = new ilFileDataForum($this->forum_id, $rowPost->pos_pk); $set = array(); if (count($tmp_file_obj->getFilesOfPost())) { foreach ($tmp_file_obj->getFilesOfPost() as $file) { $this->xmlStartTag("Attachment"); copy($file['path'], $this->target_dir_absolute . "/" . basename($file['path'])); $content = $this->target_dir_relative . "/" . basename($file['path']); $this->xmlElement("Content", null, $content); /* $thumb = $tmp_file_obj->getThumbFilename($file); if($thumb) { copy($tmp_file_obj->getThumbPath().'/'.$thumb, $this->target_dir_absolute."/".$thumb); $contentThumb = $this->target_dir_relative."/".$thumb; $this->xmlElement("ContentThumbnail", null, $contentThumb); }*/ ++$i; $this->xmlEndTag("Attachment"); } } //Used for nested postings //$lastDepth = $rowPost->depth; $this->xmlEndTag("Post"); } /* // Used for nested postings if( $lastDepth ) { for( $i = 1; $i <= $lastDepth ; $i++ ) { $this->xmlEndTag("Post"); } $lastDepth = null; }*/ $this->xmlEndTag("Thread"); } $this->xmlEndTag("Forum"); return true; }
function sendForumNotifications($post_data) { global $ilDB, $ilAccess, $lng, $ilUser; include_once "Services/Mail/classes/class.ilMail.php"; include_once './Services/User/classes/class.ilObjUser.php'; // GET THREAD DATA $result = $ilDB->queryf(' SELECT thr_subject FROM frm_threads WHERE thr_pk = %s', array('integer'), array($post_data['pos_thr_fk'])); while ($record = $ilDB->fetchAssoc($result)) { $post_data['thr_subject'] = $record['thr_subject']; break; } // determine obj_id of the forum $obj_id = self::_lookupObjIdForForumId($post_data['pos_top_fk']); // GET AUTHOR OF NEW POST if ($post_data['pos_usr_id']) { $post_data['pos_usr_name'] = ilObjUser::_lookupLogin($post_data['pos_usr_id']); } else { if (strlen($post_data['pos_usr_alias'])) { $post_data['pos_usr_name'] = $post_data['pos_usr_alias'] . ' (' . $lng->txt('frm_pseudonym') . ')'; } } if ($post_data['pos_usr_name'] == '') { $post_data['pos_usr_name'] = $this->lng->txt('forums_anonymous'); } // GET USERS WHO WANT TO BE INFORMED ABOUT NEW POSTS $res = $ilDB->queryf(' SELECT frm_notification.user_id FROM frm_notification, frm_data WHERE frm_data.top_pk = %s AND frm_notification.frm_id = frm_data.top_frm_fk AND frm_notification.user_id <> %s GROUP BY frm_notification.user_id', array('integer', 'integer'), array($post_data['pos_top_fk'], $ilUser->getId())); // get all references of obj_id $frm_references = ilObject::_getAllReferences($obj_id); // save language of the current user global $lng; $userLanguage = $lng; // get attachments data $fileDataForum = new ilFileDataForum($obj_id, $post_data['pos_pk']); $filesOfPost = $fileDataForum->getFilesOfPost(); $attachments = array(); foreach ($filesOfPost as $attachment) { $attachments[] = $attachment['name']; } $mail_obj = new ilMail(ANONYMOUS_USER_ID); while ($row = $ilDB->fetchAssoc($res)) { // do rbac check before sending notification $send_mail = false; foreach ((array) $frm_references as $ref_id) { if ($ilAccess->checkAccessOfUser($row['user_id'], 'read', '', $ref_id)) { $send_mail = true; break; } } if ($send_mail) { $this->setLanguage(self::_getLanguageInstanceByUsrId($row['user_id'])); $mail_obj->sendMail(ilObjUser::_lookupLogin($row["user_id"]), "", "", $this->formatNotificationSubject($post_data), $this->formatNotification($post_data, 0, $attachments, $row['user_id']), array(), array("system")); } } // reset language $this->setLanguage($userLanguage); }