diff --git a/blocks/blog_tags/block_blog_tags.php b/blocks/blog_tags/block_blog_tags.php new file mode 100644 index 0000000000000..3182098bd7658 --- /dev/null +++ b/blocks/blog_tags/block_blog_tags.php @@ -0,0 +1,67 @@ +title = get_string('blogtags'); + $this->version = 2006032000; + } + + function get_content() { + + global $CFG; + + $timewithin = time() - 7776000; // last 90 days + $topentries = 20; // get the 20 most popular tags + + + if ($this->content !== NULL) { + return $this->content; + } + + if (empty($this->instance)) { + $this->content = ''; + return $this->content; + } + + $this->content = new stdClass; + $this->content->text = ''; + $this->content->footer = ''; + + + /// Get a list of tags + + $sql = 'SELECT t.*, COUNT(DISTINCT bt.id) as ct '; + $sql .= "FROM {$CFG->prefix}tags as t, {$CFG->prefix}blog_tag_instance as bt "; + $sql .= 'WHERE t.id = bt.tagid '; + $sql .= "AND bt.timemodified > $timewithin "; + $sql .= 'GROUP BY bt.tagid '; + $sql .= 'ORDER BY ct DESC, t.text ASC '; + $sql .= "LIMIT $topentries "; + + $tags = get_records_sql($sql) or array(); + + $size = 20; $lasttagcount = -1; $sizecount = 1; + foreach ($tags as $tag) { + $class = "$tag->type s$size"; + $link = $CFG->wwwroot.'/blog/index.php?filtertype=site&tagid='.$tag->id; + + $this->content->text .= ''.$tag->text.' '; + + /// Set the size class + if ($tag->ct != $lasttagcount) { + $size -= $sizecount; + $lasttagcount = $tag->ct; + $sizecount = 1; + } else { + $sizecount++; + } + } + + return $this->content; + } + + function applicable_formats() { + return array('all' => true, 'my' => false); + } +} +?>