/** * Adds information about recent messages for the course view page * to the course-module object. * @param cm_info $cm Course-module object */ function hsuforum_cm_info_view(cm_info $cm) { if (!$cm->uservisible) { return; } $config = get_config('hsuforum'); $forum = hsuforum_get_cm_forum($cm); $out = ''; if (empty($config->hiderecentposts) && $forum->showrecent) { $out .= hsuforum_recent_activity($cm->get_course(), true, 0, $forum->id); } if ($unread = hsuforum_count_forum_unread_posts($cm, $cm->get_course())) { $out .= '<a class="unread" href="' . $cm->url . '">'; if ($unread == 1) { $out .= get_string('unreadpostsone', 'hsuforum'); } else { $out .= get_string('unreadpostsnumber', 'hsuforum', $unread); } $out .= '</a>'; } $cm->set_after_link($out); }
/** * Process posts by removing unwanted data, etc. * * @param \stdClass $discussion * @param \stdClass[] $posts */ public function clean_posts($discussion, &$posts) { foreach ($posts as $key => $post) { if (!hsuforum_user_can_see_post(hsuforum_get_cm_forum($this->cm), $discussion, $post, null, $this->cm)) { unset($posts[$key]); continue; } // Remove children, not processing them. unset($post->children); } }
/** * @param stdClass $post * @param stdClass $discussion * @param stdClass $cm * @param bool $canreply * @return array * @throws coding_exception * @author Mark Nielsen */ public function post_get_commands($post, $discussion, $cm, $canreply) { global $CFG, $USER; $discussionlink = new moodle_url('/mod/hsuforum/discuss.php', array('d' => $post->discussion)); $ownpost = (isloggedin() and $post->userid == $USER->id); $commands = array(); if (!property_exists($post, 'privatereply')) { throw new coding_exception('Must set post\'s privatereply property!'); } $forum = hsuforum_get_cm_forum($cm); if ($canreply and empty($post->privatereply)) { $postuser = hsuforum_extract_postuser($post, $forum, context_module::instance($cm->id)); $replytitle = get_string('replybuttontitle', 'hsuforum', strip_tags($postuser->fullname)); $commands['reply'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('reply' => $post->id)), get_string('reply', 'hsuforum'), array('title' => $replytitle, 'class' => 'hsuforum-reply-link btn btn-default')); } // Hack for allow to edit news posts those are not displayed yet until they are displayed $age = time() - $post->created; if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) { $age = 0; } if ($ownpost && $age < $CFG->maxeditingtime || local::cached_has_capability('mod/hsuforum:editanypost', context_module::instance($cm->id))) { $commands['edit'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('edit' => $post->id)), get_string('edit', 'hsuforum')); } if ($ownpost && $age < $CFG->maxeditingtime && local::cached_has_capability('mod/hsuforum:deleteownpost', context_module::instance($cm->id)) || local::cached_has_capability('mod/hsuforum:deleteanypost', context_module::instance($cm->id))) { $commands['delete'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('delete' => $post->id)), get_string('delete', 'hsuforum')); } if (local::cached_has_capability('mod/hsuforum:splitdiscussions', context_module::instance($cm->id)) && $post->parent && !$post->privatereply && $forum->type != 'single') { $commands['split'] = html_writer::link(new moodle_url('/mod/hsuforum/post.php', array('prune' => $post->id)), get_string('prune', 'hsuforum'), array('title' => get_string('pruneheading', 'hsuforum'))); } if ($CFG->enableportfolios && empty($forum->anonymous) && (local::cached_has_capability('mod/hsuforum:exportpost', context_module::instance($cm->id)) || $ownpost && local::cached_has_capability('mod/hsuforum:exportownpost', context_module::instance($cm->id)))) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('hsuforum_portfolio_caller', array('postid' => $post->id), 'mod_hsuforum'); list($attachments, $attachedimages) = hsuforum_print_attachments($post, $cm, 'separateimages'); if (empty($attachments)) { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } $porfoliohtml = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); if (!empty($porfoliohtml)) { $commands['portfolio'] = $porfoliohtml; } } $rating = $this->post_rating($post); if (!empty($rating)) { $commands['rating'] = $rating; } return $commands; }
/** * Send a discussion and its posts to the export * * @param \stdClass $discussion * @param \stdClass[] $posts * @return void */ public function send_discussion($discussion, $posts) { $discname = format_string($discussion->name); foreach ($posts as $post) { $postuser = hsuforum_extract_postuser($post, hsuforum_get_cm_forum($this->cm), \context_module::instance($this->cm->id)); $author = fullname($postuser); $attachments = $this->process_attachments($post); $options = new \stdClass(); $options->para = false; $options->trusted = $post->messagetrust; $options->context = \context_module::instance($this->cm->id); $message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', \context_module::instance($this->cm->id)->id, 'mod_hsuforum', 'post', $post->id); $message = format_text($message, $post->messageformat, $options, $this->cm->course); $message = \core_text::specialtoascii(html_to_text($message)); if ($post->id == $discussion->firstpost) { $this->format->export_discussion($post->id, $discname, $author, $post->created, $message, $attachments); } else { $private = ''; if (!empty($post->privatereply)) { $private = get_string('yes'); } $this->format->export_post($post->id, $discname, format_string($post->subject), $author, $post->created, $message, $attachments, $private); } } }