/** * @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; }
/** * Given a course and a date, prints a summary of all the new * messages posted in the course since that date as HTML media objects * * @global object $CFG * @global object $USER * @global object $DB * @global object $OUTPUT * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return string recent activity */ function hsuforum_recent_activity($course, $viewfullnames, $timestart, $forumid = null) { global $CFG, $USER, $DB, $OUTPUT; $limitfrom = 0; $limitnum = 0; $andforumid = ''; if ($forumid !== null) { $andforumid = 'AND d.forum = ?'; $limitnum = 6; } $allnamefields = user_picture::fields('u', null, 'duserid'); $sql = "SELECT p.*, f.anonymous as forumanonymous, f.type AS forumtype,\n d.forum, d.groupid, d.timestart, d.timeend, {$allnamefields}\n FROM {hsuforum_posts} p\n JOIN {hsuforum_discussions} d ON d.id = p.discussion\n JOIN {hsuforum} f ON f.id = d.forum\n JOIN {user} u ON u.id = p.userid\n WHERE p.created > ?\n AND f.course = ?\n AND (p.privatereply = 0 OR p.privatereply = ? OR p.userid = ?)\n {$andforumid}\n ORDER BY p.created DESC\n "; $params = array($timestart, $course->id, $USER->id, $USER->id, $forumid); if (!($posts = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum))) { return ''; } $modinfo = get_fast_modinfo($course); $config = get_config('hsuforum'); $groupmodes = array(); $cms = array(); $out = ''; foreach ($posts as $post) { if (!isset($modinfo->instances['hsuforum'][$post->forum])) { // not visible continue; } $cm = $modinfo->instances['hsuforum'][$post->forum]; if (!$cm->uservisible) { continue; } $context = context_module::instance($cm->id); if (!has_capability('mod/hsuforum:viewdiscussion', $context)) { continue; } if (!empty($config->enabletimedposts) and $USER->id != $post->duserid and ($post->timestart > 0 and $post->timestart > time() or $post->timeend > 0 and $post->timeend < time())) { if (!has_capability('mod/hsuforum:viewhiddentimedposts', $context)) { continue; } } // Check that the user can see the discussion. if (hsuforum_is_user_group_discussion($cm, $post->groupid)) { $postuser = hsuforum_extract_postuser($post, hsuforum_get_cm_forum($cm), context_module::instance($cm->id)); $userpicture = new user_picture($postuser); $userpicture->link = false; $userpicture->alttext = false; $userpicture->size = 100; $picture = $OUTPUT->render($userpicture); $url = $CFG->wwwroot . '/mod/hsuforum/discuss.php?d=' . $post->discussion; if (!empty($post->parent)) { $url .= '#p' . $post->id; } $postusername = fullname($postuser, $viewfullnames); $postsubject = break_up_long_words(format_string($post->subject, true)); $posttime = hsuforum_relative_time($post->modified); $out .= hsuforum_media_object($url, $picture, $postusername, $posttime, $postsubject); } } if ($out) { $out = "<h3 class='hsuforum-recent-heading'>" . get_string('newforumposts', 'hsuforum') . "</h3>" . $out; } return $out; }
/** * 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); } } }