49 * @param string The word to add |
49 * @param string The word to add |
50 */ |
50 */ |
51 |
51 |
52 function add_word($word) |
52 function add_word($word) |
53 { |
53 { |
54 $word = strtolower($word); |
54 $word = sanitize_tag($word); |
55 |
55 |
56 if ( isset($this->words[$word]) ) |
56 if ( isset($this->words[$word]) ) |
57 $this->words[$word] += 1; |
57 $this->words[$word] += 1; |
58 else |
58 else |
59 $this->words[$word] = 1; |
59 $this->words[$word] = 1; |
123 return $ret; |
123 return $ret; |
124 } |
124 } |
125 |
125 |
126 /** |
126 /** |
127 * Generates and returns HTML for the cloud. |
127 * Generates and returns HTML for the cloud. |
|
128 * @param string Optional. The CSS class applied to all <span> tags. Can be "normal" or "small". Defaults to "normal". |
|
129 * @param string Optional. The alignment for the div. Defaults to "center". |
128 * @return string |
130 * @return string |
129 */ |
131 */ |
130 |
132 |
131 function make_html() |
133 function make_html($span_class = 'normal', $div_align = 'center') |
132 { |
134 { |
133 $html = array(); |
135 $html = array(); |
134 $max = max($this->words); |
136 $max = max($this->words); |
135 $size = $this->get_cloud_size(); |
137 $size = $this->get_cloud_size(); |
|
138 $inc = 0; |
136 if ( count($this->words) > 0 ) |
139 if ( count($this->words) > 0 ) |
137 { |
140 { |
138 foreach ( $this->words as $word => $popularity ) |
141 foreach ( $this->words as $word => $popularity ) |
139 { |
142 { |
|
143 $inc++; |
140 $word = htmlspecialchars($word); |
144 $word = htmlspecialchars($word); |
141 $percent = ( $popularity / $max ) * 100; |
145 $percent = ( $popularity / $max ) * 100; |
142 $index = $this->get_scale_class($percent); |
146 $index = $this->get_scale_class($percent); |
143 $html[] = "<span class='tc_word tc_index_$index'>$word</span>"; |
147 $newline = ( $inc == 5 ) ? "<br />" : ''; |
|
148 ( $inc == 5 ) ? $inc = 0 : null; |
|
149 $url = makeUrlNS('Special', 'TagCloud/' . htmlspecialchars($word)); |
|
150 $s = ( $popularity != 1 ) ? 's' : ''; |
|
151 $html[] = "<span class='tc_word_{$span_class} tc_{$span_class}_index_{$index}'><a href='$url' title='$popularity page$s'>$word</a></span>"; // $newline"; |
144 } |
152 } |
145 } |
153 } |
146 $html = implode("\n", $html); |
154 $html = '<div style="text-align: ' . $div_align . '; margin: 0 auto; max-width: 400px;">' . implode("\n", $html) . '</div>'; |
147 return $html; |
155 return $html; |
148 } |
156 } |
149 |
157 |
150 |
158 |
151 } |
159 } |