Exemplo n.º 1
0
 function get_content()
 {
     global $CFG, $USER, $PAGE, $DB, $OUTPUT;
     if (empty($this->config->recentbloginterval)) {
         $this->config->recentbloginterval = 8400;
     }
     if (empty($this->config->numberofrecentblogentries)) {
         $this->config->numberofrecentblogentries = 4;
     }
     if (empty($CFG->bloglevel) || $CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser())) {
         $this->content->text = '';
         if ($this->page->user_is_editing()) {
             $this->content->text = get_string('blogdisable', 'blog');
         }
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $context = $this->page->context;
     $filter = array();
     if ($context->contextlevel == CONTEXT_MODULE) {
         $filter['module'] = $context->instanceid;
         $a = new stdClass();
         $a->type = get_string('modulename', $this->page->cm->modname);
         $strview = get_string('viewallmodentries', 'blog', $a);
     } else {
         if ($context->contextlevel == CONTEXT_COURSE) {
             $filter['course'] = $context->instanceid;
             $a = new stdClass();
             $a->type = get_string('course');
             $strview = get_string('viewblogentries', 'blog', $a);
         } else {
             $strview = get_string('viewsiteentries', 'blog');
         }
     }
     $filter['since'] = $this->config->recentbloginterval;
     $bloglisting = new blog_listing($filter);
     $entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
     $url = new moodle_url('/blog/index.php', $filter);
     if (!empty($entries)) {
         $entrieslist = array();
         $viewblogurl = new moodle_url('/blog/index.php');
         foreach ($entries as $entryid => $entry) {
             $viewblogurl->param('entryid', $entryid);
             $entrylink = html_writer::link($viewblogurl, shorten_text($entry->subject));
             $entrieslist[] = $entrylink;
         }
         $this->content->text .= html_writer::alist($entrieslist, array('class' => 'list'));
         $viewallentrieslink = html_writer::link($url, $strview);
         $this->content->text .= $viewallentrieslink;
     } else {
         $this->content->text .= get_string('norecentblogentries', 'block_blog_recent');
     }
 }
Exemplo n.º 2
0
/**
 * Generate any blog RSS feed via one function
 *
 * @param stdClass $context The context of the blog for which the feed it being generated
 * @param array    $args    An array of arguements needed to build the feed (contextid, token, componentname, type, id, tagid)
 */
function blog_rss_get_feed($context, $args)
{
    global $CFG, $SITE, $DB;
    if (empty($CFG->bloglevel)) {
        debugging('Blogging disabled on this site, RSS feeds are not available');
        return null;
    }
    if (empty($CFG->enablerssfeeds)) {
        debugging('Sorry, RSS feeds are disabled on this site');
        return '';
    }
    if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
        if (isguestuser()) {
            debugging(get_string('nopermissiontoshow', 'error'));
            return '';
        }
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    if (!has_capability('moodle/blog:view', $sitecontext)) {
        return null;
    }
    $type = clean_param($args[3], PARAM_ALPHA);
    $id = clean_param($args[4], PARAM_INT);
    // could be groupid / courseid  / userid  depending on $type
    $tagid = 0;
    if ($args[5] != 'rss.xml') {
        $tagid = clean_param($args[5], PARAM_INT);
    } else {
        $tagid = 0;
    }
    $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
        }
    }
    $courseid = $groupid = $userid = null;
    switch ($type) {
        case 'site':
            //$siteid = $id;
            break;
        case 'course':
            $courseid = $id;
            break;
        case 'group':
            $groupid = $id;
            break;
        case 'user':
            $userid = $id;
            break;
    }
    // Get all the entries from the database
    require_once $CFG->dirroot . '/blog/locallib.php';
    $blogheaders = blog_get_headers($courseid, $groupid, $userid, $tagid);
    $bloglisting = new blog_listing($blogheaders['filters']);
    $blogentries = $bloglisting->get_entries();
    // Now generate an array of RSS items
    if ($blogentries) {
        $items = array();
        foreach ($blogentries as $blog_entry) {
            $item = NULL;
            $item->author = fullname($DB->get_record('user', array('id' => $blog_entry->userid)));
            // TODO: this is slow
            $item->title = $blog_entry->subject;
            $item->pubdate = $blog_entry->lastmodified;
            $item->link = $CFG->wwwroot . '/blog/index.php?entryid=' . $blog_entry->id;
            $summary = file_rewrite_pluginfile_urls($blog_entry->summary, 'pluginfile.php', $sitecontext->id, 'blog', 'post', $blog_entry->id);
            $item->description = format_text($summary, $blog_entry->format);
            if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id))) {
                if ($blogtags) {
                    $item->tags = $blogtags;
                }
                $item->tagscheme = $CFG->wwwroot . '/tag';
            }
            $items[] = $item;
        }
        $articles = rss_add_items($items);
        /// Change structure to XML
    } else {
        $articles = '';
    }
    /// Get header and footer information
    switch ($type) {
        case 'user':
            $info = fullname($DB->get_record('user', array('id' => $id), 'firstname,lastname'));
            break;
        case 'course':
            $info = $DB->get_field('course', 'fullname', array('id' => $id));
            $info = format_string($info, true, array('context' => get_context_instance(CONTEXT_COURSE, $id)));
            break;
        case 'site':
            $info = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
            break;
        case 'group':
            $group = groups_get_group($id);
            $info = $group->name;
            //TODO: $DB->get_field('groups', 'name', array('id'=>$id))
            break;
        default:
            $info = '';
            break;
    }
    if ($tagid) {
        $info .= ': ' . $DB->get_field('tags', 'text', array('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
    }
}
Exemplo n.º 3
0
if ($courseid != SITEID) {
    $PAGE->set_heading($course->fullname);
    echo $OUTPUT->header();
    if (!empty($user)) {
        $headerinfo = array('heading' => fullname($user), 'user' => $user);
        echo $OUTPUT->context_header($headerinfo, 2);
    }
} else {
    if (isset($userid)) {
        $PAGE->set_heading(fullname($user));
        echo $OUTPUT->header();
    } else {
        if ($courseid == SITEID) {
            echo $OUTPUT->header();
        }
    }
}
echo $OUTPUT->heading($blogheaders['heading'], 2);
$bloglisting = new blog_listing($blogheaders['filters']);
$bloglisting->print_entries();
if ($CFG->enablerssfeeds) {
    blog_rss_print_link($rsscontext, $filtertype, $thingid, $tagid, get_string('rssfeed', 'blog'));
}
echo $OUTPUT->footer();
$eventparams = array('other' => array('entryid' => $entryid, 'tagid' => $tagid, 'userid' => $userid, 'modid' => $modid, 'groupid' => $groupid, 'search' => $search, 'fromstart' => $start));
if (!empty($userid)) {
    $eventparams['relateduserid'] = $userid;
}
$eventparams['other']['courseid'] = $courseid === SITEID ? 0 : $courseid;
$event = \core\event\blog_entries_viewed::create($eventparams);
$event->trigger();
Exemplo n.º 4
0
    echo '<div class="managelink"><a href="' . $CFG->wwwroot . '/tag/manage.php">' . get_string('managetags', 'tag') . '</a></div>';
}
$tagname = tag_display_name($tag);
if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
    $tagname = '<span class="flagged-tag">' . $tagname . '</span>';
}
echo $OUTPUT->heading($tagname, 2, 'headingblock header tag-heading');
tag_print_management_box($tag);
tag_print_description_box($tag);
// Check what type of results are avaialable
require_once $CFG->dirroot . '/tag/coursetagslib.php';
$courses = coursetag_get_tagged_courses($tag->id);
if (has_capability('moodle/blog:view', $systemcontext)) {
    require_once $CFG->dirroot . '/blog/lib.php';
    require_once $CFG->dirroot . '/blog/locallib.php';
    $bloglisting = new blog_listing(array('tag' => $tag->id));
    $limit = 10;
    $start = 0;
    $blogs = $bloglisting->get_entries($start, $limit);
}
$usercount = tag_record_count('user', $tag->id);
// Only include <a href />'s to those anchors that actually will be shown
$relatedpageslink = "";
$countanchors = 0;
if (!empty($courses)) {
    $relatedpageslink = '<a href="#course">' . get_string('courses') . '</a>';
    $countanchors++;
}
if (!empty($blogs)) {
    if ($countanchors > 0) {
        $relatedpageslink .= ' | ';
Exemplo n.º 5
0
 public function test_blog_get_listing_module()
 {
     $this->setAdminUser();
     $coursecontext = context_course::instance($this->courseid);
     $contextmodule = context_module::instance($this->cmid);
     $anothermodule = $this->getDataGenerator()->create_module('page', array('course' => $this->courseid));
     // Add blog associations with a course.
     $blog = new blog_entry($this->postid);
     $blog->add_association($contextmodule->id);
     // There is no entry associated with a course.
     $bloglisting = new blog_listing(array('course' => $this->courseid));
     $this->assertCount(0, $bloglisting->get_entries());
     // There is one entry associated with a module.
     $bloglisting = new blog_listing(array('module' => $this->cmid));
     $this->assertCount(1, $bloglisting->get_entries());
     // There is no entry associated with a wrong module.
     $bloglisting = new blog_listing(array('module' => $anothermodule->cmid));
     $this->assertCount(0, $bloglisting->get_entries());
     // There is one entry associated with a site (id is ignored).
     $bloglisting = new blog_listing(array('site' => 12345));
     $this->assertCount(1, $bloglisting->get_entries());
     // There is one entry associated with course context (module is a subcontext of a course).
     $bloglisting = new blog_listing(array('context' => $coursecontext->id));
     $this->assertCount(1, $bloglisting->get_entries());
 }
Exemplo n.º 6
0
/**
 * Returns posts tagged with a specified tag.
 *
 * @param core_tag_tag $tag
 * @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
 *             are displayed on the page and the per-page limit may be bigger
 * @param int $fromctx context id where the link was displayed, may be used by callbacks
 *            to display items in the same context first
 * @param int $ctx context id where to search for records
 * @param bool $rec search in subcontexts as well
 * @param int $page 0-based number of page being displayed
 * @return \core_tag\output\tagindex
 */
function blog_get_tagged_posts($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = true, $page = 0)
{
    global $CFG, $OUTPUT;
    require_once $CFG->dirroot . '/user/lib.php';
    $systemcontext = context_system::instance();
    $perpage = $exclusivemode ? 20 : 5;
    $context = $ctx ? context::instance_by_id($ctx) : context_system::instance();
    $content = '';
    if (empty($CFG->enableblogs) || !has_capability('moodle/blog:view', $systemcontext)) {
        // Blogs are not enabled or are not visible to the current user.
        $totalpages = 0;
    } else {
        if ($context->contextlevel != CONTEXT_SYSTEM && empty($CFG->useblogassociations)) {
            // No blog entries can be associated to the non-system context.
            $totalpages = 0;
        } else {
            if (!$rec && $context->contextlevel != CONTEXT_COURSE && $context->contextlevel != CONTEXT_MODULE) {
                // No blog entries can be associated with category or block context.
                $totalpages = 0;
            } else {
                require_once $CFG->dirroot . '/blog/locallib.php';
                $filters = array('tag' => $tag->id);
                if ($rec) {
                    if ($context->contextlevel != CONTEXT_SYSTEM) {
                        $filters['context'] = $context->id;
                    }
                } else {
                    if ($context->contextlevel == CONTEXT_COURSE) {
                        $filters['course'] = $context->instanceid;
                    } else {
                        if ($context->contextlevel == CONTEXT_MODULE) {
                            $filters['module'] = $context->instanceid;
                        }
                    }
                }
                $bloglisting = new blog_listing($filters);
                $blogs = $bloglisting->get_entries($page * $perpage, $perpage);
                $totalcount = $bloglisting->count_entries();
                $totalpages = ceil($totalcount / $perpage);
                if (!empty($blogs)) {
                    $tagfeed = new core_tag\output\tagfeed();
                    foreach ($blogs as $blog) {
                        $user = fullclone($blog);
                        $user->id = $blog->userid;
                        $user->deleted = 0;
                        $img = $OUTPUT->user_picture($user, array('size' => 35));
                        $subject = format_string($blog->subject);
                        if ($blog->publishstate == 'draft') {
                            $class = 'dimmed';
                        } else {
                            $class = '';
                        }
                        $url = new moodle_url('/blog/index.php', array('entryid' => $blog->id));
                        $subject = html_writer::link($url, $subject, array('class' => $class));
                        $fullname = fullname($user);
                        if (user_can_view_profile($user)) {
                            $profilelink = new moodle_url('/user/view.php', array('id' => $blog->userid));
                            $fullname = html_writer::link($profilelink, $fullname);
                        }
                        $details = $fullname . ', ' . userdate($blog->created);
                        $tagfeed->add($img, $subject, $details);
                    }
                    $items = $tagfeed->export_for_template($OUTPUT);
                    $content = $OUTPUT->render_from_template('core_tag/tagfeed', $items);
                    $urlparams = array('tagid' => $tag->id);
                    if ($context->contextlevel == CONTEXT_COURSE) {
                        $urlparams['courseid'] = $context->instanceid;
                    } else {
                        if ($context->contextlevel == CONTEXT_MODULE) {
                            $urlparams['modid'] = $context->instanceid;
                        }
                    }
                    $allblogsurl = new moodle_url('/blog/index.php', $urlparams);
                    $rv = new core_tag\output\tagindex($tag, 'core', 'post', $content, $exclusivemode, $fromctx, $ctx, $rec, $page, $totalpages);
                    $rv->exclusiveurl = $allblogsurl;
                    return $rv;
                }
            }
        }
    }
    $rv = new core_tag\output\tagindex($tag, 'core', 'post', $content, $exclusivemode, $fromctx, $ctx, $rec, $page, $totalpages);
    $rv->exclusiveurl = null;
    return $rv;
}