Permalink
Browse files

Block for listing blog tags

  • Loading branch information...
ikawhero
ikawhero committed Mar 20, 2006
1 parent 9a8091a commit f3ea6dfaaaa15e35aff3bd21eb13a93985e1f613
Showing with 67 additions and 0 deletions.
  1. +67 −0 blocks/blog_tags/block_blog_tags.php
@@ -0,0 +1,67 @@
<?PHP //$Id$
class block_blog_tags extends block_base {
function init() {
$this->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 .= '<a href="'.$link.'" class="'.$class.'">'.$tag->text.'</a> ';
/// 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);
}
}
?>

0 comments on commit f3ea6df

Please sign in to comment.