Skip to content

Commit

Permalink
Tag colors
Browse files Browse the repository at this point in the history
  • Loading branch information
p-blomberg committed Jul 1, 2011
1 parent 7ad3d33 commit abc7508
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 11 additions & 0 deletions classes/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ class Tag {
private $type;
private $post_count;
private $weak_post_count;
private $color;

public function __construct($data) {
$this->guid=$data['G'];
$this->name=$data['N'];
$this->type=$data['T'];
$this->post_count=hexdec($data['P']);
$this->weak_post_count=hexdec($data['W']);
$this->color=$this->color();
}

private function color() {
$chars=substr(md5($this->type,true),0,3);
$chars=array($chars[0],$chars[1],$chars[2]);
foreach($chars as $key => $char) {
$chars[$key]=ord($char) / 1.6;
}
return sprintf("#%02x%02x%02x", $chars[0], $chars[1], $chars[2]);
}

public function __get($key) {
Expand Down
4 changes: 1 addition & 3 deletions content/main/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ function tagname_cmp($a,$b) {
usort($tags, "tagname_cmp");

foreach($tags as $t) {
echo '<li style="font-size: '. intval(100 * ($t->post_count / $max)). 'px;">';
echo "<a href=\"/tag/name/".urlencode($t->name)."\">
".htmlspecialchars($t->name)."</a></li>\n";
echo '<li><a href="/tag/name/'. urlencode($t->name) .'" style="font-size: '. intval(100 * ($t->post_count / $max)) .'px; color: '. $t->color .';">'. htmlspecialchars($t->name) ."</a></li>\n";
}
echo "</ul>";
?>
1 change: 0 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.tagcloud li {
display: inline;
margin-right: 2px;
background-color: #fad;
}
.tagcloud a {
text-decoration: none;
Expand Down

0 comments on commit abc7508

Please sign in to comment.