/** * Given the data about a posting, builds up the HTML to display it and * returns the HTML in a string. This is designed for sending via HTML email. * * @global object * @param object $course * @param object $cm * @param object $forum * @param object $discussion * @param object $post * @param object $userform * @param object $userto * @param bool $ownpost * @param bool $reply * @param bool $link * @param bool $rate * @param string $footer * @return string */ function hsuforum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $ownpost = false, $reply = false, $link = false, $rate = false, $footer = "") { global $CFG, $OUTPUT; $modcontext = context_module::instance($cm->id); if (!isset($userto->viewfullnames[$forum->id])) { $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id); } else { $viewfullnames = $userto->viewfullnames[$forum->id]; } $postuser = hsuforum_anonymize_user($userfrom, $forum, $post); // add absolute file links $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_hsuforum', 'post', $post->id); // format the post body $options = new stdClass(); $options->para = true; $formattedtext = format_text($post->message, $post->messageformat, $options, $course->id); $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">'; $output .= '<tr class="header"><td width="35" valign="top" class="picture left">'; $output .= $OUTPUT->user_picture($postuser, array('courseid' => $course->id, 'link' => !hsuforum_is_anonymous_user($postuser))); $output .= '</td>'; if ($post->parent) { $output .= '<td class="topic">'; } else { $output .= '<td class="topic starter">'; } $output .= '<div class="subject">' . format_string($post->subject) . '</div>'; $fullname = fullname($postuser, $viewfullnames); $by = new stdClass(); if (!hsuforum_is_anonymous_user($postuser)) { $by->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $postuser->id . '&course=' . $course->id . '">' . $fullname . '</a>'; } else { $by->name = $fullname; } $by->date = userdate($post->modified, '', $userto->timezone); $output .= '<div class="author">' . get_string('bynameondate', 'hsuforum', $by) . '</div>'; $output .= '</td></tr>'; $output .= '<tr><td class="left side" valign="top">'; if (isset($userfrom->groups)) { $groups = $userfrom->groups[$forum->id]; } else { $groups = groups_get_all_groups($course->id, $userfrom->id, $cm->groupingid); } if ($groups) { $output .= print_group_picture($groups, $course->id, false, true, true); } else { $output .= ' '; } $output .= '</td><td class="content">'; $attachments = hsuforum_print_attachments($post, $cm, 'html'); if ($attachments !== '') { $output .= '<div class="attachments">'; $output .= $attachments; $output .= '</div>'; } $output .= $formattedtext; // Commands $commands = array(); if ($post->parent) { $commands[] = '<a target="_blank" href="' . $CFG->wwwroot . '/mod/hsuforum/discuss.php?d=' . $post->discussion . '&parent=' . $post->parent . '">' . get_string('parent', 'hsuforum') . '</a>'; } if ($reply) { $commands[] = '<a target="_blank" href="' . $CFG->wwwroot . '/mod/hsuforum/post.php?reply=' . $post->id . '">' . get_string('reply', 'hsuforum') . '</a>'; } $output .= '<div class="commands">'; $output .= implode(' | ', $commands); $output .= '</div>'; // Context link to post if required if ($link) { $output .= '<div class="link">'; $output .= '<a target="_blank" href="' . $CFG->wwwroot . '/mod/hsuforum/discuss.php?d=' . $post->discussion . '#p' . $post->id . '">' . get_string('postincontext', 'hsuforum') . '</a>'; $output .= '</div>'; } if ($footer) { $output .= '<div class="footer">' . $footer . '</div>'; } $output .= '</td></tr></table>' . "\n\n"; return $output; }
/** * @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; }