Example #1
0
/**
 * @todo Document this function
 *
 * @global object
 * @global object
 * @uses CONTEXT_MODULE
 * @return void
 */
function anonforum_print_posts_threaded($course, &$cm, $anonforum, $discussion, $parent, $depth, $reply, $anonforumtracked, $posts)
{
    global $USER, $CFG;
    $link = false;
    if (!empty($posts[$parent->id]->children)) {
        $posts = $posts[$parent->id]->children;
        $modcontext = context_module::instance($cm->id);
        $canviewfullnames = has_capability('moodle/site:viewfullnames', $modcontext);
        foreach ($posts as $post) {
            echo '<div class="indent">';
            if ($depth > 0) {
                $ownpost = $USER->id == $post->userid;
                $post->subject = format_string($post->subject);
                $postread = !empty($post->postread);
                anonforum_print_post($post, $discussion, $anonforum, $cm, $course, $ownpost, $reply, $link, '', '', $postread, true, $anonforumtracked);
            } else {
                if (!anonforum_user_can_see_post($anonforum, $discussion, $post, NULL, $cm)) {
                    echo "</div>\n";
                    continue;
                }
                $by = new stdClass();
                if (empty($post->anonymouspost)) {
                    $by->name = fullname($post, $canviewfullnames);
                } else {
                    $by->name = get_string('anonymoususer', 'anonforum');
                }
                $by->date = userdate($post->modified);
                if ($anonforumtracked) {
                    if (!empty($post->postread)) {
                        $style = '<span class="anonforumthread read">';
                    } else {
                        $style = '<span class="anonforumthread unread">';
                    }
                } else {
                    $style = '<span class="anonforumthread">';
                }
                echo $style . "<a name=\"{$post->id}\"></a>" . "<a href=\"discuss.php?d={$post->discussion}&amp;parent={$post->id}\">" . format_string($post->subject, true) . "</a> ";
                print_string("bynameondate", "anonforum", $by);
                echo "</span>";
            }
            anonforum_print_posts_threaded($course, $cm, $anonforum, $discussion, $post, $depth - 1, $reply, $anonforumtracked, $posts);
            echo "</div>\n";
        }
    }
}
Example #2
0
/**
 * This function return the XML rss contents about the anonforum
 * It returns false if something is wrong
 *
 * @param stdClass $anonforum the anonforum object
 * @param string $sql the SQL used to retrieve the contents from the database
 * @param array $params the SQL parameters used
 * @param object $context the context this anonforum relates to
 * @return bool|string false if the contents is empty, otherwise the contents of the feed is returned
 *
 * @Todo MDL-31129 implement post attachment handling
 */
function anonforum_rss_feed_contents($anonforum, $sql, $params, $context)
{
    global $CFG, $DB, $USER;
    $status = true;
    $recs = $DB->get_recordset_sql($sql, $params, 0, $anonforum->rssarticles);
    //set a flag. Are we displaying discussions or posts?
    $isdiscussion = true;
    if (!empty($anonforum->rsstype) && $anonforum->rsstype != 1) {
        $isdiscussion = false;
    }
    if (!($cm = get_coursemodule_from_instance('anonforum', $anonforum->id, $anonforum->course))) {
        print_error('invalidcoursemodule');
    }
    $formatoptions = new stdClass();
    $items = array();
    foreach ($recs as $rec) {
        $item = new stdClass();
        $discussion = new stdClass();
        $discussion->id = $rec->discussionid;
        $discussion->groupid = $rec->groupid;
        $discussion->timestart = $rec->timestart;
        $discussion->timeend = $rec->timeend;
        $post = null;
        if (!$isdiscussion) {
            $post = new stdClass();
            $post->id = $rec->postid;
            $post->parent = $rec->postparent;
            $post->userid = $rec->userid;
        }
        if ($isdiscussion && !anonforum_user_can_see_discussion($anonforum, $discussion, $context)) {
            // This is a discussion which the user has no permission to view
            $item->title = get_string('anonforumsubjecthidden', 'anonforum');
            $message = get_string('anonforumbodyhidden', 'anonforum');
            $item->author = get_string('anonforumauthorhidden', 'anonforum');
        } else {
            if (!$isdiscussion && !anonforum_user_can_see_post($anonforum, $discussion, $post, $USER, $cm)) {
                // This is a post which the user has no permission to view
                $item->title = get_string('anonforumsubjecthidden', 'anonforum');
                $message = get_string('anonforumbodyhidden', 'anonforum');
                $item->author = get_string('anonforumauthorhidden', 'anonforum');
            } else {
                // The user must have permission to view
                if ($isdiscussion && !empty($rec->discussionname)) {
                    $item->title = format_string($rec->discussionname);
                } else {
                    if (!empty($rec->postsubject)) {
                        $item->title = format_string($rec->postsubject);
                    } else {
                        //we should have an item title by now but if we dont somehow then substitute something somewhat meaningful
                        $item->title = format_string($anonforum->name . ' ' . userdate($rec->postcreated, get_string('strftimedatetimeshort', 'langconfig')));
                    }
                }
                if (empty($rec->anonymouspost)) {
                    $user = new stdClass();
                    $user->firstname = $rec->userfirstname;
                    $user->lastname = $rec->userlastname;
                    $item->author = fullname($user);
                } else {
                    $item->author = get_string('anonymoususer', 'anonforum');
                }
                $message = file_rewrite_pluginfile_urls($rec->postmessage, 'pluginfile.php', $context->id, 'mod_anonforum', 'post', $rec->postid);
                $formatoptions->trusted = $rec->posttrust;
            }
        }
        if ($isdiscussion) {
            $item->link = $CFG->wwwroot . "/mod/anonforum/discuss.php?d=" . $rec->discussionid;
        } else {
            $item->link = $CFG->wwwroot . "/mod/anonforum/discuss.php?d=" . $rec->discussionid . "&parent=" . $rec->postid;
        }
        $formatoptions->trusted = $rec->posttrust;
        $item->description = format_text($message, $rec->postformat, $formatoptions, $anonforum->course);
        //TODO: MDL-31129 implement post attachment handling
        /*if (!$isdiscussion) {
                        $post_file_area_name = str_replace('//', '/', "$anonforum->course/$CFG->moddata/anonforum/$anonforum->id/$rec->postid");
                        $post_files = get_directory_list("$CFG->dataroot/$post_file_area_name");
        
                        if (!empty($post_files)) {
                            $item->attachments = array();
                        }
                    }*/
        $item->pubdate = $rec->postcreated;
        $items[] = $item;
    }
    $recs->close();
    // Create the RSS header.
    $header = rss_standard_header(strip_tags(format_string($anonforum->name, true)), $CFG->wwwroot . "/mod/anonforum/view.php?f=" . $anonforum->id, format_string($anonforum->intro, true));
    // TODO: fix format
    // Now all the RSS items, if there are any.
    $articles = '';
    if (!empty($items)) {
        $articles = rss_add_items($items);
    }
    // Create the RSS footer.
    $footer = rss_standard_footer();
    return $header . $articles . $footer;
}
if ($mode) {
    set_user_preference('anonforum_displaymode', $mode);
}
$displaymode = get_user_preferences('anonforum_displaymode', $CFG->anonforum_displaymode);
if ($parent) {
    // If flat AND parent, then force nested display this time
    if ($displaymode == ANONFORUM_MODE_FLATOLDEST or $displaymode == ANONFORUM_MODE_FLATNEWEST) {
        $displaymode = ANONFORUM_MODE_NESTED;
    }
} else {
    $parent = $discussion->firstpost;
}
if (!($post = anonforum_get_post_full($parent))) {
    print_error("notexists", 'anonforum', "{$CFG->wwwroot}/mod/anonforum/view.php?f={$anonforum->id}");
}
if (!anonforum_user_can_see_post($anonforum, $discussion, $post, null, $cm)) {
    print_error('noviewdiscussionspermission', 'anonforum', "{$CFG->wwwroot}/mod/anonforum/view.php?id={$anonforum->id}");
}
if ($mark == 'read' or $mark == 'unread') {
    if ($CFG->anonforum_usermarksread && anonforum_tp_can_track_anonforums($anonforum) && anonforum_tp_is_tracked($anonforum)) {
        if ($mark == 'read') {
            anonforum_tp_add_read_record($USER->id, $postid);
        } else {
            // unread
            anonforum_tp_delete_read_records($USER->id, $postid);
        }
    }
}
$searchform = anonforum_search_form($course);
$anonforumnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY);
if (empty($anonforumnode)) {