mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
ENHANCEMENT: Allow specifying the class buckets to assign tags into based on popularity
This commit is contained in:
parent
2d1eb07478
commit
58775ea256
@ -24,6 +24,8 @@ class TagCloudWidget extends Widget {
|
|||||||
static $cmsTitle = "Tag Cloud";
|
static $cmsTitle = "Tag Cloud";
|
||||||
static $description = "Shows a tag cloud of tags on your blog.";
|
static $description = "Shows a tag cloud of tags on your blog.";
|
||||||
|
|
||||||
|
static $popularities = array( 'not-popular', 'not-very-popular', 'somewhat-popular', 'popular', 'very-popular', 'ultra-popular' );
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields() {
|
||||||
return new FieldSet(
|
return new FieldSet(
|
||||||
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
|
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
|
||||||
@ -67,38 +69,24 @@ class TagCloudWidget extends Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sizes = array();
|
$sizes = array();
|
||||||
foreach($allTags as $tag => $count){
|
foreach ($allTags as $tag => $count) $sizes[$count] = true;
|
||||||
$sizes[$count] = true;
|
|
||||||
}
|
$offset = 0;
|
||||||
$numsizes = count($sizes)-1; //Work out the number of different sizes
|
$numsizes = count($sizes)-1; //Work out the number of different sizes
|
||||||
if($numsizes > 5){$numsizes = 5;}
|
$buckets = count(self::$popularities)-1;
|
||||||
|
|
||||||
|
// If there are more frequencies then buckets, divide frequencies into buckets
|
||||||
|
if ($numsizes > $buckets) {
|
||||||
|
$numsizes = $buckets;
|
||||||
|
}
|
||||||
|
// Otherwise center use central buckets
|
||||||
|
else {
|
||||||
|
$offset = round(($buckets-$numsizes)/2);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($allTags as $tag => $count) {
|
foreach($allTags as $tag => $count) {
|
||||||
|
$popularity = round($count / $max * $numsizes) + $offset; $popularity=min($buckets,$popularity);
|
||||||
$popularity = floor($count / $max * $numsizes);
|
$class = self::$popularities[$popularity];
|
||||||
|
|
||||||
switch($popularity) {
|
|
||||||
case 0:
|
|
||||||
$class = "not-popular";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
$class = "not-very-popular";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$class = "somewhat-popular";
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$class = "popular";
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$class = "very-popular";
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
$class = "ultra-popular";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$class = "broken";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$allTags[$tag] = array(
|
$allTags[$tag] = array(
|
||||||
"Tag" => $tag,
|
"Tag" => $tag,
|
||||||
|
Loading…
Reference in New Issue
Block a user