/**
 * Determines whether the user can comment on the given blog post, presuming
 * that they are allowed to see it.
 * @param $cm Course-module (null if personal blog)
 * @param $oublog Blog object
 * @param $post Post object
 * @return bool True if user is allowed to make comments
 */
function oublog_can_comment($cm, $oublog, $post)
{
    global $USER;
    if ($oublog->global) {
        // Just need the 'contributepersonal' permission at system level
        $blogok = $oublog->allowcomments == OUBLOG_COMMENTS_ALLOWPUBLIC || has_capability('mod/oublog:contributepersonal', get_context_instance(CONTEXT_SYSTEM));
    } else {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        // Three ways you can comment to a course blog:
        $blogok = $oublog->allowcomments == OUBLOG_COMMENTS_ALLOWPUBLIC || $post->visibility >= OUBLOG_VISIBILITY_LOGGEDINUSER && $oublog->maxvisibility >= OUBLOG_VISIBILITY_LOGGEDINUSER && has_capability('mod/oublog:contributepersonal', $modcontext) || has_capability('mod/oublog:comment', $modcontext) && oublog_is_writable_group($cm);
        // Note this logic is still a bit weird with regard to groups. If
        // there is a course blog with visible groups, users in other groups
        // can't comment; there is a CONTRIB bug request for us to make an
        // option for this. In that same situation, if a post is set to be
        // visible to logged-in users, now people not in groups can suddenly
        // comment. Hmmm. We might need another level of ->allowcomments to
        // make this make sense, or some other changes.
    }
    // If the blog allows comments, this post must allow comments and either
    // it allows public comments or you're logged in (and not guest)
    return $blogok && $post->allowcomments && ($post->allowcomments >= OUBLOG_COMMENTS_ALLOWPUBLIC || isloggedin() && !isguestuser());
}
/**
 * Determines whether the user can comment on the given blog post, presuming
 * that they are allowed to see it.
 * @param $cm Course-module (null if personal blog)
 * @param $oublog Blog object
 * @param $post Post object
 * @param bool $ignoretime True to ignore any comment time limits
 * @return bool True if user is allowed to make comments
 */
function oublog_can_comment($cm, $oublog, $post, $ignoretime = false)
{
    global $USER;
    if ($oublog->global) {
        // Just need the 'contributepersonal' permission at system level, OR
        // if you are not logged in but the blog allows public comments.
        // Note that if you ARE logged in you must have the capability. This is
        // because logged-in comments do not go through moderation, so we want
        // to be able to prevent them by removing the capability. They will
        // still be able to make comments by logging out, but these will then
        // go through moderation.
        $blogok = !isloggedin() && $oublog->allowcomments == OUBLOG_COMMENTS_ALLOWPUBLIC || has_capability('mod/oublog:contributepersonal', context_system::instance());
    } else {
        $modcontext = context_module::instance($cm->id);
        // Three ways you can comment to a course blog:
        $blogok = $oublog->allowcomments == (OUBLOG_COMMENTS_ALLOWPUBLIC && !isloggedin()) || $post->visibility >= OUBLOG_VISIBILITY_LOGGEDINUSER && $oublog->maxvisibility >= OUBLOG_VISIBILITY_LOGGEDINUSER && has_capability('mod/oublog:comment', $modcontext) || has_capability('mod/oublog:comment', $modcontext) && oublog_is_writable_group($cm);
        // Note this logic is still a bit weird with regard to groups. If
        // there is a course blog with visible groups, users in other groups
        // can't comment; there is a CONTRIB bug request for us to make an
        // option for this. In that same situation, if a post is set to be
        // visible to logged-in users, now people not in groups can suddenly
        // comment. Hmmm. We might need another level of ->allowcomments to
        // make this make sense, or some other changes.
    }
    // Test comment time period.
    $timeok = ($oublog->commentfrom == 0 || $oublog->commentfrom <= time()) && ($oublog->commentuntil == 0 || $oublog->commentuntil > time());
    if ($ignoretime) {
        $timeok = true;
    }
    if (!$timeok && has_capability('mod/oublog:ignorecommentperiod', $oublog->global ? context_system::instance() : context_module::instance($cm->id))) {
        $timeok = true;
    }
    // If the blog allows comments, this post must allow comments and either
    // it allows public comments or you're logged in (and not guest)
    return $blogok && $post->allowcomments && ($post->allowcomments >= OUBLOG_COMMENTS_ALLOWPUBLIC || isloggedin() && !isguestuser()) && $timeok;
}
Exemple #3
0
$straddpost = get_string('newpost', 'oublog', oublog_get_displayname($oublog));
$strexportposts = get_string('oublog:exportposts', 'oublog');
$strtags = get_string('tags', 'oublog');
$stredit = get_string('edit', 'oublog');
$strdelete = get_string('delete', 'oublog');
$strnewposts = get_string('newerposts', 'oublog');
$strolderposts = get_string('olderposts', 'oublog');
$strcomment = get_string('comment', 'oublog');
$strviews = get_string('views', 'oublog', oublog_get_displayname($oublog));
$strlinks = get_string('links', 'oublog');
$strfeeds = get_string('feeds', 'oublog');
$strblogsearch = get_string('searchthisblog', 'oublog', oublog_get_displayname($oublog));
// Set-up groups.
$groupmode = oublog_get_activity_groupmode($cm, $course);
$currentgroup = oublog_get_activity_group($cm, true);
if (!oublog_is_writable_group($cm)) {
    $canpost = false;
    $canmanageposts = false;
    $cancomment = false;
    $canaudit = false;
}
if (isset($cm)) {
    $completion = new completion_info($course);
    $completion->set_module_viewed($cm);
}
// Print the header.
$PAGEWILLCALLSKIPMAINDESTINATION = true;
$hideunusedblog = false;
if ($oublog->global) {
    $blogtype = 'personal';
    $returnurl = $CFG->wwwroot . '/mod/oublog/view.php?user=' . $user;