Esempio n. 1
0
/**
 * get the count of viewable entries, easiest way is to count blog_fetch_entries
 * this is used for print_paging_bar
 * this is not ideal, but because of the UNION in the sql in blog_fetch_entries,
 * it is hard to use count_records_sql
 */
function get_viewable_entry_count($postid = '', $fetchlimit = 10, $fetchstart = '', $filtertype = '', $filterselect = '', $tagid = '', $tag = '', $sort = 'lastmodified DESC')
{
    $blogEntries = blog_fetch_entries($postid, $fetchlimit, $fetchstart, $filtertype, $filterselect, $tagid, $tag, $sort = 'lastmodified DESC', false);
    return count($blogEntries);
}
Esempio n. 2
0
function blog_generate_rss_feed($type, $id, $tagid = 0)
{
    global $CFG, $SITE;
    if (empty($CFG->enablerssfeeds)) {
        debugging('Sorry, RSS feeds are disabled on this site');
        return '';
    }
    $filename = blog_rss_file_name($type, $id, $tagid);
    if (file_exists($filename)) {
        if (filemtime($filename) + 3600 > time()) {
            return $filename;
            /// It's already done so we return cached version
        }
    }
    /// Get all the posts from the database
    $blogposts = blog_fetch_entries('', 20, '', $type, $id, $tagid);
    /// Now generate an array of RSS items
    if ($blogposts) {
        $items = array();
        foreach ($blogposts as $blogpost) {
            $item = NULL;
            $item->author = fullname(get_record('user', 'id', $blogpost->userid));
            $item->title = $blogpost->subject;
            $item->pubdate = $blogpost->lastmodified;
            $item->link = $CFG->wwwroot . '/blog/index.php?postid=' . $blogpost->id;
            $item->description = format_text($blogpost->summary, $blogpost->format);
            $items[] = $item;
        }
        $articles = rss_add_items($items);
        /// Change structure to XML
    } else {
        $articles = '';
    }
    /// Get header and footer information
    switch ($type) {
        case 'user':
            $info = fullname(get_record('user', 'id', $id, '', '', '', '', 'firstname,lastname'));
            break;
        case 'course':
            $info = get_field('course', 'fullname', 'id', $id);
            break;
        case 'site':
            $info = $SITE->fullname;
            break;
        case 'group':
            $group = groups_get_group($id, false);
            $info = $group->name;
            //TODO: get_field('groups', 'name', 'id', $id)
            break;
        default:
            $info = '';
            break;
    }
    if ($tagid) {
        $info .= ': ' . get_field('tags', 'text', 'id', $tagid);
    }
    $header = rss_standard_header(get_string($type . 'blog', 'blog', $info), $CFG->wwwroot . '/blog/index.php', get_string('intro', 'blog'));
    $footer = rss_standard_footer();
    /// Save the XML contents to file.
    $rssdata = $header . $articles . $footer;
    if (blog_rss_save_file($type, $id, $tagid, $rssdata)) {
        return $filename;
    } else {
        return false;
        // Couldn't find it or make it
    }
}
Esempio n. 3
0
    $heading = get_string('courses') . ' ' . get_string('taggedwith', 'tag', $tagname) . ': ' . $totalcount;
    echo "<a name='course'></a>";
    echo $OUTPUT->heading($heading, 3);
    foreach ($courses as $course) {
        print_course($course);
    }
    echo $OUTPUT->box_end();
}
// Print up to 10 previous blogs entries
// I was not able to use get_items_tagged_with() because it automatically
// tries to join on 'blog' table, since the itemtype is 'blog'. However blogs
// uses the post table so this would not really work.    - Yu 29/8/07
if (has_capability('moodle/blog:view', $systemcontext)) {
    // You have to see blogs obviously
    $count = 10;
    if ($blogs = blog_fetch_entries('', $count, 0, 'site', '', $tag->id)) {
        echo $OUTPUT->box_start('generalbox', 'tag-blogs');
        $heading = get_string('relatedblogs', 'tag', $tagname) . ' ' . get_string('taggedwith', 'tag', $tagname);
        echo "<a name='blog'></a>";
        echo $OUTPUT->heading($heading, 3);
        echo '<ul id="tagblogentries">';
        foreach ($blogs as $blog) {
            if ($blog->publishstate == 'draft') {
                $class = 'class="dimmed"';
            } else {
                $class = '';
            }
            echo '<li ' . $class . '>';
            echo '<a ' . $class . ' href="' . $CFG->wwwroot . '/blog/index.php?postid=' . $blog->id . '">';
            echo format_string($blog->subject);
            echo '</a>';