本文整理汇总了PHP中forum_user_can_post函数的典型用法代码示例。如果您正苦于以下问题:PHP forum_user_can_post函数的具体用法?PHP forum_user_can_post怎么用?PHP forum_user_can_post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forum_user_can_post函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum_print_discussion
/**
* Prints a forum discussion
*
* @uses CONTEXT_MODULE
* @uses FORUM_MODE_FLATNEWEST
* @uses FORUM_MODE_FLATOLDEST
* @uses FORUM_MODE_THREADED
* @uses FORUM_MODE_NESTED
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $forum
* @param stdClass $discussion
* @param stdClass $post
* @param int $mode
* @param mixed $canreply
* @param bool $canrate
*/
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply=NULL, $canrate=false) {
global $USER, $CFG;
require_once($CFG->dirroot.'/rating/lib.php');
$ownpost = (isloggedin() && $USER->id == $post->userid);
$modcontext = context_module::instance($cm->id);
if ($canreply === NULL) {
$reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
} else {
$reply = $canreply;
}
// $cm holds general cache for forum functions
$cm->cache = new stdClass;
$cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid);
$cm->cache->usersgroups = array();
$posters = array();
// preload all posts - TODO: improve...
if ($mode == FORUM_MODE_FLATNEWEST) {
$sort = "p.created DESC";
} else {
$sort = "p.created ASC";
}
$forumtracked = forum_tp_is_tracked($forum);
$posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
$post = $posts[$post->id];
foreach ($posts as $pid=>$p) {
$posters[$p->userid] = $p->userid;
}
// preload all groups of ppl that posted in this discussion
if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) {
foreach($postersgroups as $pg) {
if (!isset($cm->cache->usersgroups[$pg->userid])) {
$cm->cache->usersgroups[$pg->userid] = array();
}
$cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid;
}
unset($postersgroups);
}
//load ratings
if ($forum->assessed != RATING_AGGREGATE_NONE) {
$ratingoptions = new stdClass;
$ratingoptions->context = $modcontext;
$ratingoptions->component = 'mod_forum';
$ratingoptions->ratingarea = 'post';
$ratingoptions->items = $posts;
$ratingoptions->aggregate = $forum->assessed;//the aggregation method
$ratingoptions->scaleid = $forum->scale;
$ratingoptions->userid = $USER->id;
if ($forum->type == 'single' or !$discussion->id) {
$ratingoptions->returnurl = "$CFG->wwwroot/mod/forum/view.php?id=$cm->id";
} else {
$ratingoptions->returnurl = "$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id";
}
$ratingoptions->assesstimestart = $forum->assesstimestart;
$ratingoptions->assesstimefinish = $forum->assesstimefinish;
$rm = new rating_manager();
$posts = $rm->get_ratings($ratingoptions);
}
$post->forum = $forum->id; // Add the forum id to the post object, later used by forum_print_post
$post->forumtype = $forum->type;
$post->subject = format_string($post->subject);
$postread = !empty($post->postread);
forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false,
'', '', $postread, true, $forumtracked);
switch ($mode) {
case FORUM_MODE_FLATOLDEST :
case FORUM_MODE_FLATNEWEST :
//.........这里部分代码省略.........
示例2: print_error
print_error('notpartofdiscussion', 'forum');
}
if (!($forum = $DB->get_record("forum", array("id" => $discussion->forum)))) {
print_error('invalidforumid', 'forum');
}
if (!($course = $DB->get_record("course", array("id" => $discussion->course)))) {
print_error('invalidcourseid');
}
if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) {
print_error('invalidcoursemodule');
}
// Ensure lang, theme, etc. is set up properly. MDL-6926
$PAGE->set_cm($cm, $course, $forum);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
if (!isguestuser()) {
if (!is_enrolled($coursecontext)) {
// User is a guest here!
$SESSION->wantsurl = $FULLME;
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
redirect($CFG->wwwroot . '/enrol/index.php?id=' . $course->id, get_string('youneedtoenrol'));
}
}
print_error('nopostforum', 'forum');
}
// Make sure user can post here
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
示例3: moodle_url
$forumnode->make_active();
}
$node = $forumnode->add(format_string($discussion->name), new moodle_url('/mod/forum/discuss.php', array('d' => $discussion->id)));
$node->display = false;
if ($node && $post->id != $discussion->firstpost) {
$node->add(format_string($post->subject), $PAGE->url);
}
$PAGE->set_title("{$course->shortname}: " . format_string($discussion->name));
$PAGE->set_heading($course->fullname);
$PAGE->set_button($searchform);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);
/// Check to see if groups are being used in this forum
/// If so, make sure the current person is allowed to see this discussion
/// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
if (!$canreply and $forum->type !== 'news') {
if (isguestuser() or !isloggedin()) {
$canreply = true;
}
if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
// allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link
// normal users with temporary guest access see this link too, they are asked to enrol instead
$canreply = enrol_selfenrol_available($course->id);
}
}
/// Print the controls across the top
echo '<div class="discussioncontrols clearfix">';
if (!empty($CFG->enableportfolios) && has_capability('mod/forum:exportdiscussion', $modcontext)) {
require_once $CFG->libdir . '/portfoliolib.php';
$button = new portfolio_add_button();
示例4: get_forum_discussion_posts
/**
* Returns a list of forum posts for a discussion
*
* @param int $discussionid the post ids
* @param string $sortby sort by this element (id, created or modified)
* @param string $sortdirection sort direction: ASC or DESC
*
* @return array the forum post details
* @since Moodle 2.7
*/
public static function get_forum_discussion_posts($discussionid, $sortby = "created", $sortdirection = "DESC")
{
global $CFG, $DB, $USER;
$warnings = array();
// Validate the parameter.
$params = self::validate_parameters(self::get_forum_discussion_posts_parameters(), array('discussionid' => $discussionid, 'sortby' => $sortby, 'sortdirection' => $sortdirection));
// Compact/extract functions are not recommended.
$discussionid = $params['discussionid'];
$sortby = $params['sortby'];
$sortdirection = $params['sortdirection'];
$sortallowedvalues = array('id', 'created', 'modified');
if (!in_array($sortby, $sortallowedvalues)) {
throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $sortby . '),' . 'allowed values are: ' . implode(',', $sortallowedvalues));
}
$sortdirection = strtoupper($sortdirection);
$directionallowedvalues = array('ASC', 'DESC');
if (!in_array($sortdirection, $directionallowedvalues)) {
throw new invalid_parameter_exception('Invalid value for sortdirection parameter (value: ' . $sortdirection . '),' . 'allowed values are: ' . implode(',', $directionallowedvalues));
}
$discussion = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST);
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
// Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
$modcontext = context_module::instance($cm->id);
self::validate_context($modcontext);
// This require must be here, see mod/forum/discuss.php.
require_once $CFG->dirroot . "/mod/forum/lib.php";
// Check they have the view forum capability.
require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
if (!($post = forum_get_post_full($discussion->firstpost))) {
throw new moodle_exception('notexists', 'forum');
}
// This function check groups, qanda, timed discussions, etc.
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
throw new moodle_exception('noviewdiscussionspermission', 'forum');
}
$canviewfullname = has_capability('moodle/site:viewfullnames', $modcontext);
// We will add this field in the response.
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
$forumtracked = forum_tp_is_tracked($forum);
$sort = 'p.' . $sortby . ' ' . $sortdirection;
$posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
foreach ($posts as $pid => $post) {
if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
$warning = array();
$warning['item'] = 'post';
$warning['itemid'] = $post->id;
$warning['warningcode'] = '1';
$warning['message'] = 'You can\'t see this post';
$warnings[] = $warning;
continue;
}
// Function forum_get_all_discussion_posts adds postread field.
// Note that the value returned can be a boolean or an integer. The WS expects a boolean.
if (empty($post->postread)) {
$posts[$pid]->postread = false;
} else {
$posts[$pid]->postread = true;
}
$posts[$pid]->canreply = $canreply;
if (!empty($posts[$pid]->children)) {
$posts[$pid]->children = array_keys($posts[$pid]->children);
} else {
$posts[$pid]->children = array();
}
$user = new stdclass();
$user = username_load_fields_from_object($user, $post);
$posts[$pid]->userfullname = fullname($user, $canviewfullname);
$posts[$pid] = (array) $post;
}
$result = array();
$result['posts'] = $posts;
$result['warnings'] = $warnings;
return $result;
}
示例5: error
error("This post is not part of a discussion!");
}
if (!($forum = get_record("forum", "id", $discussion->forum))) {
error("The forum number was incorrect ({$discussion->forum})");
}
if (!($course = get_record("course", "id", $discussion->course))) {
error("The course number was incorrect ({$discussion->course})");
}
if (!($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id))) {
error("Incorrect cm");
}
// call course_setup to use forced language, MDL-6926
course_setup($course->id);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!forum_user_can_post($forum)) {
if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) {
// User is a guest here!
$SESSION->wantsurl = $FULLME;
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
redirect($CFG->wwwroot . '/course/enrol.php?id=' . $course->id, get_string('youneedtoenrol'));
} else {
print_error('nopostforum', 'forum');
}
}
if (groupmode($course, $cm)) {
// Make sure user can post here
$mygroupid = mygroupid($course->id);
if (!((empty($mygroupid) and $discussion->groupid == -1) || ismember($discussion->groupid) || has_capability('moodle/site:accessallgroups', $modcontext, NULL, false))) {
print_error('nopostdiscussion', 'forum');
}
示例6: add_discussion_post
/**
* Create new posts into an existing discussion.
*
* @param int $postid the post id we are going to reply to
* @param string $subject new post subject
* @param string $message new post message (only html format allowed)
* @param array $options optional settings
* @return array of warnings and the new post id
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function add_discussion_post($postid, $subject, $message, $options = array()) {
global $DB, $CFG, $USER;
require_once($CFG->dirroot . "/mod/forum/lib.php");
$params = self::validate_parameters(self::add_discussion_post_parameters(),
array(
'postid' => $postid,
'subject' => $subject,
'message' => $message,
'options' => $options
));
// Validate options.
$options = array(
'discussionsubscribe' => true
);
foreach ($params['options'] as $option) {
$name = trim($option['name']);
switch ($name) {
case 'discussionsubscribe':
$value = clean_param($option['value'], PARAM_BOOL);
break;
default:
throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
}
$options[$name] = $value;
}
$warnings = array();
if (!$parent = forum_get_post_full($params['postid'])) {
throw new moodle_exception('invalidparentpostid', 'forum');
}
if (!$discussion = $DB->get_record("forum_discussions", array("id" => $parent->discussion))) {
throw new moodle_exception('notpartofdiscussion', 'forum');
}
// Request and permission validation.
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
$context = context_module::instance($cm->id);
self::validate_context($context);
if (!forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context)) {
throw new moodle_exception('nopostforum', 'forum');
}
$thresholdwarning = forum_check_throttling($forum, $cm);
forum_check_blocking_threshold($thresholdwarning);
// Create the post.
$post = new stdClass();
$post->discussion = $discussion->id;
$post->parent = $parent->id;
$post->subject = $params['subject'];
$post->message = $params['message'];
$post->messageformat = FORMAT_HTML; // Force formatting for now.
$post->messagetrust = trusttext_trusted($context);
$post->itemid = 0;
if ($postid = forum_add_new_post($post, null)) {
$post->id = $postid;
// Trigger events and completion.
$params = array(
'context' => $context,
'objectid' => $post->id,
'other' => array(
'discussionid' => $discussion->id,
'forumid' => $forum->id,
'forumtype' => $forum->type,
)
);
$event = \mod_forum\event\post_created::create($params);
$event->add_record_snapshot('forum_posts', $post);
$event->add_record_snapshot('forum_discussions', $discussion);
$event->trigger();
// Update completion state.
$completion = new completion_info($course);
if ($completion->is_enabled($cm) &&
($forum->completionreplies || $forum->completionposts)) {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
$settings = new stdClass();
$settings->discussionsubscribe = $options['discussionsubscribe'];
//.........这里部分代码省略.........
示例7: process_message
/**
* Process a message received and validated by the Inbound Message processor.
*
* @throws \core\message\inbound\processing_failed_exception
* @param \stdClass $messagedata The Inbound Message record
* @param \stdClass $messagedata The message data packet
* @return bool Whether the message was successfully processed.
*/
public function process_message(\stdClass $record, \stdClass $messagedata) {
global $DB, $USER;
// Load the post being replied to.
$post = $DB->get_record('forum_posts', array('id' => $record->datavalue));
if (!$post) {
mtrace("--> Unable to find a post matching with id {$record->datavalue}");
return false;
}
// Load the discussion that this post is in.
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
if (!$post) {
mtrace("--> Unable to find the discussion for post {$record->datavalue}");
return false;
}
// Load the other required data.
$forum = $DB->get_record('forum', array('id' => $discussion->forum));
$course = $DB->get_record('course', array('id' => $forum->course));
$cm = get_fast_modinfo($course->id)->instances['forum'][$forum->id];
$modcontext = \context_module::instance($cm->id);
$usercontext = \context_user::instance($USER->id);
// Make sure user can post in this discussion.
$canpost = true;
if (!forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext)) {
$canpost = false;
}
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) {
if ($discussion->groupid == -1) {
$canpost = false;
} else {
if (!groups_is_member($discussion->groupid)) {
$canpost = false;
}
}
}
if (!$canpost) {
$data = new \stdClass();
$data->forum = $forum;
throw new \core\message\inbound\processing_failed_exception('messageinboundnopostforum', 'mod_forum', $data);
}
// And check the availability.
if (!\core_availability\info_module::is_user_visible($cm, $USER, true)) {
$data = new \stdClass();
$data->forum = $forum;
throw new \core\message\inbound\processing_failed_exception('messageinboundforumhidden', 'mod_forum', $data);
}
// Before we add this we must check that the user will not exceed the blocking threshold.
// This should result in an appropriate reply.
$thresholdwarning = forum_check_throttling($forum, $cm);
if (!empty($thresholdwarning) && !$thresholdwarning->canpost) {
$data = new \stdClass();
$data->forum = $forum;
$data->message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
throw new \core\message\inbound\processing_failed_exception('messageinboundthresholdhit', 'mod_forum', $data);
}
$addpost = new \stdClass();
$addpost->course = $course->id;
$addpost->forum = $forum->id;
$addpost->discussion = $discussion->id;
$addpost->modified = $messagedata->timestamp;
$addpost->subject = clean_param($messagedata->envelope->subject, PARAM_TEXT);
$addpost->parent = $post->id;
$addpost->itemid = file_get_unused_draft_itemid();
if (!empty($messagedata->html)) {
$addpost->message = $messagedata->html;
$addpost->messageformat = FORMAT_HTML;
} else {
$addpost->message = $messagedata->plain;
$addpost->messageformat = FORMAT_PLAIN;
}
// We don't trust text coming from e-mail.
$addpost->messagetrust = false;
// Add attachments to the post.
if (!empty($messagedata->attachments['attachment']) && count($messagedata->attachments['attachment'])) {
$attachmentcount = count($messagedata->attachments['attachment']);
if (empty($forum->maxattachments) || $forum->maxbytes == 1 ||
//.........这里部分代码省略.........
示例8: forum_print_discussion
/**
*
*/
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false)
{
global $USER, $CFG;
if (!empty($USER->id)) {
$ownpost = $USER->id == $post->userid;
} else {
$ownpost = false;
}
if ($canreply === NULL) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
} else {
$reply = $canreply;
}
// $cm holds general cache for forum functions
$cm->cache = new object();
$cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid);
$cm->cache->usersgroups = array();
$posters = array();
// preload all posts - TODO: improve...
if ($mode == FORUM_MODE_FLATNEWEST) {
$sort = "p.created DESC";
} else {
$sort = "p.created ASC";
}
$forumtracked = forum_tp_is_tracked($forum);
$posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
$post = $posts[$post->id];
foreach ($posts as $pid => $p) {
$posters[$p->userid] = $p->userid;
}
// preload all groups of ppl that posted in this discussion
if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) {
foreach ($postersgroups as $pg) {
if (!isset($cm->cache->usersgroups[$pg->userid])) {
$cm->cache->usersgroups[$pg->userid] = array();
}
$cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid;
}
unset($postersgroups);
}
$ratings = NULL;
$ratingsmenuused = false;
$ratingsformused = false;
if ($forum->assessed and isloggedin()) {
if ($ratings->scale = make_grades_menu($forum->scale)) {
$ratings->assesstimestart = $forum->assesstimestart;
$ratings->assesstimefinish = $forum->assesstimefinish;
$ratings->allow = $canrate;
if ($ratings->allow) {
echo '<form id="form" method="post" action="rate.php">';
echo '<div class="ratingform">';
echo '<input type="hidden" name="forumid" value="' . $forum->id . '" />';
$ratingsformused = true;
}
// preload all ratings - one query only and minimal memory
$cm->cache->ratings = array();
$cm->cache->myratings = array();
if ($postratings = forum_get_all_discussion_ratings($discussion)) {
foreach ($postratings as $pr) {
if (!isset($cm->cache->ratings[$pr->postid])) {
$cm->cache->ratings[$pr->postid] = array();
}
$cm->cache->ratings[$pr->postid][$pr->id] = $pr->rating;
if ($pr->userid == $USER->id) {
$cm->cache->myratings[$pr->postid] = $pr->rating;
}
}
unset($postratings);
}
}
}
$post->forum = $forum->id;
// Add the forum id to the post object, later used by forum_print_post
$post->forumtype = $forum->type;
$post->subject = format_string($post->subject);
$postread = !empty($post->postread);
if (forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false, $ratings, '', '', $postread, true, $forumtracked)) {
$ratingsmenuused = true;
}
switch ($mode) {
case FORUM_MODE_FLATOLDEST:
case FORUM_MODE_FLATNEWEST:
default:
if (forum_print_posts_flat($course, $cm, $forum, $discussion, $post, $mode, $ratings, $reply, $forumtracked, $posts)) {
$ratingsmenuused = true;
}
break;
case FORUM_MODE_THREADED:
if (forum_print_posts_threaded($course, $cm, $forum, $discussion, $post, 0, $ratings, $reply, $forumtracked, $posts)) {
$ratingsmenuused = true;
}
break;
case FORUM_MODE_NESTED:
if (forum_print_posts_nested($course, $cm, $forum, $discussion, $post, $ratings, $reply, $forumtracked, $posts)) {
$ratingsmenuused = true;
}
//.........这里部分代码省略.........
示例9: forum_make_mail_html
/**
* Builds and returns the body of the email notification in html format.
*
* @param object $course
* @param object $cm
* @param object $forum
* @param object $discussion
* @param object $post
* @param object $userfrom
* @param object $userto
* @param string $replyaddress The inbound address that a user can reply to the generated e-mail with. [Since 2.8].
* @return string The email text in HTML format
* @deprecated since Moodle 3.0 use \mod_forum\output\forum_post_email instead
*/
function forum_make_mail_html($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $replyaddress = null)
{
return forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfrom, $userto, forum_user_can_post($forum, $discussion, $userto, $cm, $course));
}