';
$topicclass = 'topic starter';
if (FORUM_DISCUSSION_PINNED == $post->pinned) {
$topicclass .= ' pinned';
}
echo '';
if (FORUM_DISCUSSION_PINNED == $post->pinned) {
echo $OUTPUT->pix_icon('i/pinned', get_string('discussionpinned', 'forum'), 'mod_forum');
}
$canalwaysseetimedpost = $USER->id == $post->userid || $canviewhiddentimedposts;
if ($timeddiscussion && $canalwaysseetimedpost) {
echo $PAGE->get_renderer('mod_forum')->timed_discussion_tooltip($post, empty($timedoutsidewindow));
}
echo ''.$post->subject.'';
echo " | \n";
// Picture
$postuser = new stdClass();
$postuserfields = explode(',', user_picture::fields());
$postuser = username_load_fields_from_object($postuser, $post, null, $postuserfields);
$postuser->id = $post->userid;
echo '';
echo '';
echo " | \n";
// Group picture
if ($group !== -1) { // Groups are active - group is a group data object or NULL
echo '';
if (!empty($group->picture) and empty($group->hidepicture)) {
if ($canviewparticipants && $COURSE->groupmode) {
$picturelink = true;
} else {
$picturelink = false;
}
print_group_picture($group, $forum->course, false, false, $picturelink);
} else if (isset($group->id)) {
if ($canviewparticipants && $COURSE->groupmode) {
echo ''.$group->name.'';
} else {
echo $group->name;
}
}
echo " | \n";
}
if (has_capability('mod/forum:viewdiscussion', $modcontext)) { // Show the column with replies
echo '';
echo '';
echo $post->replies.'';
echo " | \n";
if ($cantrack) {
echo '';
if ($forumtracked) {
if ($post->unread > 0) {
echo '';
echo '';
echo $post->unread;
echo '';
echo '' . $OUTPUT->pix_icon('t/markasread', $strmarkalldread) . '';
echo '';
} else {
echo '';
echo $post->unread;
echo '';
}
} else {
echo '';
echo '-';
echo '';
}
echo " | \n";
}
}
echo '';
$usedate = (empty($post->timemodified)) ? $post->created : $post->timemodified;
$parenturl = '';
$usermodified = new stdClass();
$usermodified->id = $post->usermodified;
$usermodified = username_load_fields_from_object($usermodified, $post, 'um');
// In QA forums we check that the user can view participants.
if ($forum->type !== 'qanda' || $canviewparticipants) {
echo ''.
fullname($usermodified, $canviewfullnames).' ';
$parenturl = (empty($post->lastpostid)) ? '' : '&parent='.$post->lastpostid;
}
echo ''.
userdate_htmltime($usedate, $datestring).'';
echo " | \n";
// is_guest should be used here as this also checks whether the user is a guest in the current course.
// Guests and visitors cannot subscribe - only enrolled users.
if ((!is_guest($modcontext, $USER) && isloggedin()) && has_capability('mod/forum:viewdiscussion', $modcontext)) {
// Discussion subscription.
if (\mod_forum\subscriptions::is_subscribable($forum)) {
echo '';
echo forum_get_discussion_subscription_icon($forum, $post->discussion);
echo ' | ';
}
}
echo "
\n\n";
}
/**
* Return the markup for the discussion subscription toggling icon.
*
* @param stdClass $forum The forum object.
* @param int $discussionid The discussion to create an icon for.
* @return string The generated markup.
*/
function forum_get_discussion_subscription_icon($forum, $discussionid, $returnurl = null, $includetext = false) {
global $USER, $OUTPUT, $PAGE;
if ($returnurl === null && $PAGE->url) {
$returnurl = $PAGE->url->out();
}
$o = '';
$subscriptionstatus = \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussionid);
$subscriptionlink = new moodle_url('/mod/forum/subscribe.php', array(
'sesskey' => sesskey(),
'id' => $forum->id,
'd' => $discussionid,
'returnurl' => $returnurl,
));
if ($includetext) {
$o .= $subscriptionstatus ? get_string('subscribed', 'mod_forum') : get_string('notsubscribed', 'mod_forum');
}
if ($subscriptionstatus) {
$output = $OUTPUT->pix_icon('t/subscribed', get_string('clicktounsubscribe', 'forum'), 'mod_forum');
if ($includetext) {
$output .= get_string('subscribed', 'mod_forum');
}
return html_writer::link($subscriptionlink, $output, array(
'title' => get_string('clicktounsubscribe', 'forum'),
'class' => 'discussiontoggle iconsmall',
'data-forumid' => $forum->id,
'data-discussionid' => $discussionid,
'data-includetext' => $includetext,
));
} else {
$output = $OUTPUT->pix_icon('t/unsubscribed', get_string('clicktosubscribe', 'forum'), 'mod_forum');
if ($includetext) {
$output .= get_string('notsubscribed', 'mod_forum');
}
return html_writer::link($subscriptionlink, $output, array(
'title' => get_string('clicktosubscribe', 'forum'),
'class' => 'discussiontoggle iconsmall',
'data-forumid' => $forum->id,
'data-discussionid' => $discussionid,
'data-includetext' => $includetext,
));
}
}
/**
* Return a pair of spans containing classes to allow the subscribe and
* unsubscribe icons to be pre-loaded by a browser.
*
* @return string The generated markup
*/
function forum_get_discussion_subscription_icon_preloaders() {
$o = '';
$o .= html_writer::span(' ', 'preload-subscribe');
$o .= html_writer::span(' ', 'preload-unsubscribe');
return $o;
}
/**
* Print the drop down that allows the user to select how they want to have
* the discussion displayed.
*
* @param int $id forum id if $forumtype is 'single',
* discussion id for any other forum type
* @param mixed $mode forum layout mode
* @param string $forumtype optional
*/
function forum_print_mode_form($id, $mode, $forumtype='') {
global $OUTPUT;
if ($forumtype == 'single') {
$select = new single_select(new moodle_url("/mod/forum/view.php", array('f'=>$id)), 'mode', forum_get_layout_modes(), $mode, null, "mode");
$select->set_label(get_string('displaymode', 'forum'), array('class' => 'accesshide'));
$select->class = "forummode";
} else {
$select = new single_select(new moodle_url("/mod/forum/discuss.php", array('d'=>$id)), 'mode', forum_get_layout_modes(), $mode, null, "mode");
$select->set_label(get_string('displaymode', 'forum'), array('class' => 'accesshide'));
}
echo $OUTPUT->render($select);
}
/**
* @global object
* @param object $course
* @param string $search
* @return string
*/
function forum_search_form($course, $search='') {
global $CFG, $PAGE;
$forumsearch = new \mod_forum\output\quick_search_form($course->id, $search);
$output = $PAGE->get_renderer('mod_forum');
return $output->render($forumsearch);
}
/**
* @global object
* @global object
*/
function forum_set_return() {
global $CFG, $SESSION;
if (! isset($SESSION->fromdiscussion)) {
$referer = get_local_referer(false);
// If the referer is NOT a login screen then save it.
if (! strncasecmp("$CFG->wwwroot/login", $referer, 300)) {
$SESSION->fromdiscussion = $referer;
}
}
}
/**
* @global object
* @param string|\moodle_url $default
* @return string
*/
function forum_go_back_to($default) {
global $SESSION;
if (!empty($SESSION->fromdiscussion)) {
$returnto = $SESSION->fromdiscussion;
unset($SESSION->fromdiscussion);
return $returnto;
} else {
return $default;
}
}
/**
* Given a discussion object that is being moved to $forumto,
* this function checks all posts in that discussion
* for attachments, and if any are found, these are
* moved to the new forum directory.
*
* @global object
* @param object $discussion
* @param int $forumfrom source forum id
* @param int $forumto target forum id
* @return bool success
*/
function forum_move_attachments($discussion, $forumfrom, $forumto) {
global $DB;
$fs = get_file_storage();
$newcm = get_coursemodule_from_instance('forum', $forumto);
$oldcm = get_coursemodule_from_instance('forum', $forumfrom);
$newcontext = context_module::instance($newcm->id);
$oldcontext = context_module::instance($oldcm->id);
// loop through all posts, better not use attachment flag ;-)
if ($posts = $DB->get_records('forum_posts', array('discussion'=>$discussion->id), '', 'id, attachment')) {
foreach ($posts as $post) {
$fs->move_area_files_to_new_context($oldcontext->id,
$newcontext->id, 'mod_forum', 'post', $post->id);
$attachmentsmoved = $fs->move_area_files_to_new_context($oldcontext->id,
$newcontext->id, 'mod_forum', 'attachment', $post->id);
if ($attachmentsmoved > 0 && $post->attachment != '1') {
// Weird - let's fix it
$post->attachment = '1';
$DB->update_record('forum_posts', $post);
} else if ($attachmentsmoved == 0 && $post->attachment != '') {
// Weird - let's fix it
$post->attachment = '';
$DB->update_record('forum_posts', $post);
}
}
}
return true;
}
/**
* Returns attachments as formated text/html optionally with separate images
*
* @global object
* @global object
* @global object
* @param object $post
* @param object $cm
* @param string $type html/text/separateimages
* @return mixed string or array of (html text withouth images and image HTML)
*/
function forum_print_attachments($post, $cm, $type) {
global $CFG, $DB, $USER, $OUTPUT;
if (empty($post->attachment)) {
return $type !== 'separateimages' ? '' : array('', '');
}
if (!in_array($type, array('separateimages', 'html', 'text'))) {
return $type !== 'separateimages' ? '' : array('', '');
}
if (!$context = context_module::instance($cm->id)) {
return $type !== 'separateimages' ? '' : array('', '');
}
$strattachment = get_string('attachment', 'forum');
$fs = get_file_storage();
$imagereturn = '';
$output = '';
$canexport = !empty($CFG->enableportfolios) && (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context)));
if ($canexport) {
require_once($CFG->libdir.'/portfoliolib.php');
}
// We retrieve all files according to the time that they were created. In the case that several files were uploaded
// at the sametime (e.g. in the case of drag/drop upload) we revert to using the filename.
$files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "filename", false);
if ($files) {
if ($canexport) {
$button = new portfolio_add_button();
}
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename);
if ($type == 'html') {
$output .= "