Version Description
- Initial release
=
Download this release
Release Info
Developer | exz |
Plugin | Ultimate Tag Cloud Widget |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- readme.txt +68 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- ultimate-tag-cloud-widget.php +471 -0
- utcw.css +12 -0
- utcw.js +13 -0
readme.txt
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Ultimate Tag Cloud Widget ===
|
2 |
+
Contributors: exz
|
3 |
+
Tags: widget, tags, configurable, tag cloud
|
4 |
+
Requires at least: 2.8
|
5 |
+
Tested up to: 3.0.1
|
6 |
+
Stable tag: 1.0
|
7 |
+
|
8 |
+
This plugin aims to be the most configurable tag cloud widget out there, able to suit all your wierd tag cloud needs.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
This is a highly configurable tag cloud widget which you can use within your own blog.
|
13 |
+
|
14 |
+
Current version supports the following preferences:
|
15 |
+
|
16 |
+
* Multiple instances
|
17 |
+
* Choose which authors tags should be shown
|
18 |
+
* Ordering of the tags
|
19 |
+
* Exclude tags you don't want to show
|
20 |
+
* Title
|
21 |
+
* Size and color customization
|
22 |
+
* Max amount of tags in your cloud
|
23 |
+
* Spacing between letters and words
|
24 |
+
* Transform tags into lowercase, uppercase or Capitalize them
|
25 |
+
* Can also show categories
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
|
29 |
+
This is the same procedure as with all ordinary plugins.
|
30 |
+
|
31 |
+
1. Download the zip file, unzip it
|
32 |
+
2. Upload it to your /wp-content/plugins/ folder
|
33 |
+
3. Activate the plugin through the 'Plugins' menu in WordPress
|
34 |
+
4. Use the widgets settings page under 'Appearance' to add it to your page
|
35 |
+
|
36 |
+
All the configuration options is set individually in every instance. Some default values are set if you're unsure on how to configure it.
|
37 |
+
|
38 |
+
|
39 |
+
== Frequently Asked Questions ==
|
40 |
+
|
41 |
+
This is a new plugin, haven't had any questions yet. If you have any, be sure to send them to me.
|
42 |
+
|
43 |
+
== Screenshots ==
|
44 |
+
|
45 |
+
1. This shows my widget with the default settings on the default wordpress theme.
|
46 |
+
2. This is a more colorful examle with random colors and all tags in uppercase. I'd like to actually see someone use it like this.
|
47 |
+
3. Maybe a more realistic usage of the widget with spanning colors and capitalized tags.
|
48 |
+
|
49 |
+
== Changelog ==
|
50 |
+
|
51 |
+
= 1.0 =
|
52 |
+
|
53 |
+
* Initial release
|
54 |
+
|
55 |
+
== Upgrade Notice ==
|
56 |
+
|
57 |
+
= 1.0 =
|
58 |
+
|
59 |
+
* Initial release
|
60 |
+
|
61 |
+
== Feedback ==
|
62 |
+
|
63 |
+
This is my very first WordPress widget and I'd love to hear your feedback. Since this widget aims to be the most configurable tag cloud there is, you are welcome to send your suggestions and improvements to me and I'll to my best to fulfil your your tag cloud wishes.
|
64 |
+
|
65 |
+
My contact information is
|
66 |
+
|
67 |
+
* rickard (a) 0x539.se
|
68 |
+
* [twitter.com/rickard2](http://twitter.com/rickard2)
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
screenshot-3.png
ADDED
Binary file
|
ultimate-tag-cloud-widget.php
ADDED
@@ -0,0 +1,471 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?
|
2 |
+
/*
|
3 |
+
Plugin Name: Ultimate tag cloud widget
|
4 |
+
Plugin URI: http://bennison.se/?page_id=173
|
5 |
+
Description: This plugin aims to be the most configurable tag cloud widget out there, able to suit all your wierd tag cloud needs.
|
6 |
+
Version: 1.0
|
7 |
+
Author: Rickad Andersson
|
8 |
+
Author URI: http://bennison.se
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Ultimate tag cloud widget class
|
13 |
+
* @package UTCW
|
14 |
+
*/
|
15 |
+
class UTCW extends WP_Widget {
|
16 |
+
|
17 |
+
// Default values if the widget isn't configured properly
|
18 |
+
private $default_title = "Tag Cloud";
|
19 |
+
private $default_order = "alphabetically";
|
20 |
+
private $default_size_from = 10;
|
21 |
+
private $default_size_to = 30;
|
22 |
+
private $default_max = 45;
|
23 |
+
private $default_taxonomy = "post_tag";
|
24 |
+
private $default_reverse = false;
|
25 |
+
private $default_color = "none";
|
26 |
+
private $default_letter_spacing = "normal";
|
27 |
+
private $default_word_spacing = "normal";
|
28 |
+
private $default_case = "off";
|
29 |
+
|
30 |
+
// Allowed values for miscellanious options in the widget
|
31 |
+
private $allowed_orders = array('random', 'alphabetically', 'count');
|
32 |
+
private $allowed_taxonomys = array('post_tag', 'category');
|
33 |
+
private $allowed_colors = array('none', 'random', 'set', 'span');
|
34 |
+
private $allowed_cases = array('lowercase', 'uppercase', 'capitalize', 'off');
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Constructor
|
38 |
+
* @return void
|
39 |
+
*/
|
40 |
+
function UTCW() {
|
41 |
+
$options = array('description' => __("Highly configurable tag cloud"));
|
42 |
+
parent::WP_Widget(false, __('Ultimate Tag Cloud'), $options);
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Action handler for the form in the admin panel
|
47 |
+
* @param array $new_instance
|
48 |
+
* @param array $old_instance
|
49 |
+
* @retrn array
|
50 |
+
*/
|
51 |
+
function update($new_instance, $old_instance) {
|
52 |
+
|
53 |
+
extract($new_instance);
|
54 |
+
|
55 |
+
// Check all input values and set the default value if any value is invalid or empty
|
56 |
+
$instance = $old_instance;
|
57 |
+
$instance['title'] = strlen($title) > 0 ? apply_filters('widget_title', $title) : apply_filters('widget_title', $this->default_title);
|
58 |
+
$instance['size_from'] = is_numeric($size_from) ? $size_from : $this->default_size_from;
|
59 |
+
$instance['size_to'] = is_numeric($size_to) ? $size_to : $this->default_size_to;
|
60 |
+
$instance['max'] = is_numeric($max) ? $max : $this->default_max;
|
61 |
+
$instance['letter_spacing'] = is_numeric($letter_spacing) ? $letter_spacing : $this->default_letter_spacing;
|
62 |
+
$instance['word_spacing'] = is_numeric($word_spacing) ? $word_spacing : $this->default_word_spacing;
|
63 |
+
$instance['reverse'] = $reverse == "on" ? true : false;
|
64 |
+
$instance['exclude'] = strlen($exclude) > 0 ? @explode(",", $exclude) : array();
|
65 |
+
$instance['color_set'] = strlen($color_set) > 0 ? @explode(",", $color_set) : array();
|
66 |
+
$instance['authors'] = array();
|
67 |
+
|
68 |
+
$instance['color_span_from'] = preg_match('/#([a-f0-9]{6}|[a-f0-9]{3})/i', $color_span_from) > 0 ? $color_span_from : "";
|
69 |
+
$instance['color_span_to'] = preg_match('/#([a-f0-9]{6}|[a-f0-9]{3})/i', $color_span_to) > 0 ? $color_span_to : "";
|
70 |
+
|
71 |
+
$instance['taxonomy'] = in_array($taxonomy, $this->allowed_taxonomys) ? $taxonomy : $this->default_taxonomy;
|
72 |
+
$instance['order'] = in_array($order, $this->allowed_orders) ? $order : $this->default_order;
|
73 |
+
$instance['color'] = in_array($color, $this->allowed_colors) ? $color : $this->default_color;
|
74 |
+
$instance['case'] = in_array($case, $this->allowed_cases) ? $case : $this->default_case;
|
75 |
+
|
76 |
+
// Only accept numeric authors (user ID)
|
77 |
+
foreach ($authors as $author) {
|
78 |
+
if (is_numeric($author)) {
|
79 |
+
$instance['authors'][] = $author;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
// Remove spaces in the comma separated list
|
84 |
+
foreach ($instance['exclude'] as $key => $value) {
|
85 |
+
$instance['exclude'][$key] = trim($value);
|
86 |
+
}
|
87 |
+
|
88 |
+
// Only allow hexadecimal color values in the format #ffffff and #fff
|
89 |
+
foreach ($instance['color_set'] as $key => $color) {
|
90 |
+
if (preg_match('/#([a-f0-9]{6}|[a-f0-9]{3})/i', $color) == 0) {
|
91 |
+
unset($instance['color_set'][$key]);
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
return $instance;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Function for displaying the widget on the page
|
100 |
+
* @param array $args
|
101 |
+
* @param array $instance
|
102 |
+
* @return void
|
103 |
+
*/
|
104 |
+
function widget($args, $instance) {
|
105 |
+
|
106 |
+
global $wpdb;
|
107 |
+
|
108 |
+
extract($args);
|
109 |
+
extract($instance);
|
110 |
+
|
111 |
+
// Parse settings from $instance and set default values where empty or invalid
|
112 |
+
$title = strlen($title) > 0 ? $title : $this->default_title;
|
113 |
+
$size_from = is_numeric($size_from) ? $size_from : $this->default_size_from;
|
114 |
+
$size_to = is_numeric($size_to) ? $size_to : $this->default_size_to;
|
115 |
+
$max = is_numeric($max) ? $max : $this->default_max;
|
116 |
+
$reverse = is_bool($reverse) ? $reverse : $this->default_reverse;
|
117 |
+
$authors = is_array($authors) ? $authors : array();
|
118 |
+
$exclude = is_array($exclude) ? $exclude : array();
|
119 |
+
$color_set = is_array($color_set) ? $color_set : array();
|
120 |
+
$letter_spacing = is_numeric($letter_spacing) ? $letter_spacing . "px" : $this->default_letter_spacing;
|
121 |
+
$word_spacing = is_numeric($word_spacing) ? $word_spacing . "px" : $this->default_word_spacing;
|
122 |
+
$color_span_from = is_string($color_span_from) ? $color_span_from : "";
|
123 |
+
$color_span_to = is_string($color_span_to) ? $color_span_to : "";
|
124 |
+
|
125 |
+
$order = in_array($order, $this->allowed_orders) ? $order : $this->default_order;
|
126 |
+
$taxonomy = in_array($taxonomy, $this->allowed_taxonomys) ? $taxonomy : $this->default_taxonomy;
|
127 |
+
$color = in_array($color, $this->allowed_colors) ? $color : $this->default_color;
|
128 |
+
$case = in_array($case, $this->allowed_cases) ? $case : $this->default_case;
|
129 |
+
|
130 |
+
// Fallback values
|
131 |
+
$counts = array();
|
132 |
+
$tag_array = array();
|
133 |
+
|
134 |
+
// Build SQL query
|
135 |
+
$q = "SELECT t.term_id, t.name, t.slug, COUNT(tr.term_taxonomy_id) AS `count` ";
|
136 |
+
$q .= "FROM `$wpdb->posts` AS p ";
|
137 |
+
$q .= "LEFT JOIN `$wpdb->term_relationships` AS tr ON tr.object_id = p.ID ";
|
138 |
+
$q .= "LEFT JOIN `$wpdb->terms` AS t ON t.term_id = tr.term_taxonomy_id ";
|
139 |
+
$q .= "LEFT JOIN `$wpdb->term_taxonomy` AS tt ON tt.term_id = t.term_id ";
|
140 |
+
$q .= "WHERE tt.taxonomy = '$taxonomy' ";
|
141 |
+
|
142 |
+
if (count($authors) > 0) {
|
143 |
+
$q .= "AND post_author IN (" . implode(",", $authors) . ") ";
|
144 |
+
}
|
145 |
+
if (count($exclude) > 0) {
|
146 |
+
$q .= "AND t.name NOT IN ('" . implode("', '", $exclude) . "') ";
|
147 |
+
}
|
148 |
+
|
149 |
+
$q .= "GROUP BY t.term_id ";
|
150 |
+
$q .= "ORDER BY COUNT(tr.term_taxonomy_id) DESC ";
|
151 |
+
$q .= "LIMIT $max;";
|
152 |
+
|
153 |
+
$tag_data = $wpdb->get_results($q);
|
154 |
+
|
155 |
+
if (count($tag_data) > 0) {
|
156 |
+
|
157 |
+
// Extract counts and create an array to work with
|
158 |
+
foreach ($tag_data as $tag) {
|
159 |
+
$counts[] = $tag->count;
|
160 |
+
$tag_array[] = array(
|
161 |
+
'term_id' => $tag->term_id,
|
162 |
+
'count' => $tag->count,
|
163 |
+
'slug' => $tag->slug,
|
164 |
+
'name' => $tag->name,
|
165 |
+
'color' => ""
|
166 |
+
);
|
167 |
+
}
|
168 |
+
|
169 |
+
// Highest and lowest values
|
170 |
+
$min_count = min($counts);
|
171 |
+
$max_count = max($counts);
|
172 |
+
|
173 |
+
// Get the step size
|
174 |
+
$font_step = $this->calc_step($min_count, $max_count, $size_from, $size_to);
|
175 |
+
|
176 |
+
// Calculate sizes for all tags
|
177 |
+
foreach ($tag_array as $key => $tag) {
|
178 |
+
$tag_array[$key]['size'] = $size_from + ( ( $tag['count'] - $min_count ) * $font_step );
|
179 |
+
}
|
180 |
+
|
181 |
+
// Check the coloring preference, default is none
|
182 |
+
switch ($color) {
|
183 |
+
|
184 |
+
// Just get an randomized value, who would ever use this?!
|
185 |
+
case "random":
|
186 |
+
foreach ($tag_array as $key => $tag) {
|
187 |
+
$tag_array[$key]['color'] = sprintf("#%s%s%s", dechex(rand() % 255), dechex(rand() % 255), dechex(rand() % 255));
|
188 |
+
}
|
189 |
+
break;
|
190 |
+
|
191 |
+
// Select a random value from the preset colors
|
192 |
+
case "set":
|
193 |
+
if (is_array($color_set) && count($color_set) > 0) {
|
194 |
+
foreach ($tag_array as $key => $tag) {
|
195 |
+
$tag_array[$key]['color'] = $color_set[ array_rand($color_set) ];
|
196 |
+
}
|
197 |
+
}
|
198 |
+
break;
|
199 |
+
|
200 |
+
// Calculate colors in a span between two values
|
201 |
+
case "span":
|
202 |
+
|
203 |
+
// Check the color format, #fff or #fffff
|
204 |
+
if (strlen($color_span_from) == 4) {
|
205 |
+
$red_from = hexdec(sprintf("%s%s", $color_span_from[1], $color_span_from[1]));
|
206 |
+
$green_from = hexdec(sprintf("%s%s", $color_span_from[2], $color_span_from[2]));
|
207 |
+
$blue_from = hexdec(sprintf("%s%s", $color_span_from[3], $color_span_from[3]));
|
208 |
+
} else {
|
209 |
+
$red_from = hexdec(substr($color_span_from, 1, 2));
|
210 |
+
$green_from = hexdec(substr($color_span_from, 3, 2));
|
211 |
+
$blue_from = hexdec(substr($color_span_from, 5, 2));
|
212 |
+
}
|
213 |
+
if (strlen($color_span_to) == 4) {
|
214 |
+
$red_to = hexdec(sprintf("%s%s", $color_span_to[1], $color_span_to[1]));
|
215 |
+
$green_to = hexdec(sprintf("%s%s", $color_span_to[2], $color_span_to[2]));
|
216 |
+
$blue_to = hexdec(sprintf("%s%s", $color_span_to[3], $color_span_to[3]));
|
217 |
+
} else {
|
218 |
+
$red_to = hexdec(substr($color_span_to, 1, 2));
|
219 |
+
$green_to = hexdec(substr($color_span_to, 3, 2));
|
220 |
+
$blue_to = hexdec(substr($color_span_to, 5, 2));
|
221 |
+
}
|
222 |
+
|
223 |
+
// Calculate steps for all the colors.
|
224 |
+
$red_step = $this->calc_step($min_count, $max_count, $red_from, $red_to);
|
225 |
+
$green_step = $this->calc_step($min_count, $max_count, $green_from, $green_to);
|
226 |
+
$blue_step = $this->calc_step($min_count, $max_count, $blue_from, $blue_to);
|
227 |
+
|
228 |
+
// Iterate all tags and calculate their color
|
229 |
+
foreach ($tag_array as $key => $tag) {
|
230 |
+
$red = round($red_from + ( ( $tag['count'] - $min_count ) * $red_step ));
|
231 |
+
$green = round($green_from + ( ( $tag['count'] - $min_count ) * $green_step ));
|
232 |
+
$blue = round($blue_from + ( ( $tag['count'] - $min_count ) * $blue_step ));
|
233 |
+
|
234 |
+
$tag_array[$key]['color'] = sprintf("rgb(%s,%s,%s)", $red, $green, $blue);
|
235 |
+
}
|
236 |
+
break;
|
237 |
+
}
|
238 |
+
|
239 |
+
// Check the ordering preference, default is alphabetically
|
240 |
+
switch ($order) {
|
241 |
+
case "random":
|
242 |
+
shuffle($tag_array);
|
243 |
+
break;
|
244 |
+
|
245 |
+
case "count":
|
246 |
+
usort($tag_array, 'utcw_cmp_count');
|
247 |
+
break;
|
248 |
+
|
249 |
+
default:
|
250 |
+
usort($tag_array, 'utcw_cmp_name');
|
251 |
+
break;
|
252 |
+
}
|
253 |
+
|
254 |
+
// Reverse the list if the user prefers it that way. Reversing an random sorted result seems correct.
|
255 |
+
if ($reverse === true) {
|
256 |
+
$tag_array = array_reverse($tag_array);
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
switch ($case) {
|
261 |
+
case 'uppercase':
|
262 |
+
$text_transform = 'text-transform: uppercase;';
|
263 |
+
break;
|
264 |
+
|
265 |
+
case 'lowercase':
|
266 |
+
$text_transform = 'text-transform: lowercase;';
|
267 |
+
break;
|
268 |
+
|
269 |
+
case 'capitalize':
|
270 |
+
$text_transform = 'text-transform: capitalize;';
|
271 |
+
break;
|
272 |
+
}
|
273 |
+
|
274 |
+
// Print the tag cloud content
|
275 |
+
echo $before_widget;
|
276 |
+
echo $before_title . $title . $after_title;
|
277 |
+
|
278 |
+
printf('<div class="widget_tag_cloud" style="letter-spacing:%s;word-spacing:%s;%s">',
|
279 |
+
$letter_spacing, $word_spacing, $text_transform);
|
280 |
+
|
281 |
+
foreach ($tag_array as $tag) {
|
282 |
+
extract($tag);
|
283 |
+
|
284 |
+
printf('<a class="tag-link-%s" href="?tag=%s" style="font-size:%spx;%s;" title="' . _("%s topics") . '">%s</a> ',
|
285 |
+
$term_id, $slug, $size, strlen($color) > 0 ? "color:$color" : "", $count, $name);
|
286 |
+
}
|
287 |
+
|
288 |
+
echo "</div>";
|
289 |
+
|
290 |
+
echo $after_widget;
|
291 |
+
}
|
292 |
+
|
293 |
+
/**
|
294 |
+
* Function for handling the widget control in admin panel
|
295 |
+
* @param array $instance
|
296 |
+
* @return void
|
297 |
+
*/
|
298 |
+
function form($instance) {
|
299 |
+
|
300 |
+
// Get stored preferences
|
301 |
+
$title = esc_attr($instance['title']);
|
302 |
+
$order = esc_attr($instance['order']);
|
303 |
+
$size_from = esc_attr($instance['size_from']);
|
304 |
+
$size_to = esc_attr($instance['size_to']);
|
305 |
+
$max = esc_attr($instance['max']);
|
306 |
+
$taxonomy = esc_attr($instance['taxonomy']);
|
307 |
+
$color = esc_attr($instance['color']);
|
308 |
+
$color_span_from = esc_attr($instance['color_span_from']);
|
309 |
+
$color_span_to = esc_attr($instance['color_span_to']);
|
310 |
+
$letter_spacing = esc_attr($instance['letter_spacing']);
|
311 |
+
$word_spacing = esc_attr($instance['word_spacing']);
|
312 |
+
$case = esc_attr($instance['case']);
|
313 |
+
$exclude = $instance['exclude'];
|
314 |
+
$reverse = $instance['reverse'];
|
315 |
+
$authors = $instance['authors'];
|
316 |
+
$color_set = $instance['color_set'];
|
317 |
+
|
318 |
+
// Fallbacks
|
319 |
+
if (!is_array($authors)) {
|
320 |
+
$authors = array();
|
321 |
+
}
|
322 |
+
if (!is_array($exclude)) {
|
323 |
+
$exclude = array();
|
324 |
+
}
|
325 |
+
if (!is_array($color_set)) {
|
326 |
+
$color_set = array();
|
327 |
+
}
|
328 |
+
|
329 |
+
// Content of the widget settings form
|
330 |
+
?>
|
331 |
+
<fieldset class="utcw">
|
332 |
+
<legend><?_e("Data")?></legend>
|
333 |
+
<? _e("Authors:"); ?><br/>
|
334 |
+
<?php foreach (get_users_of_blog() as $user) : ?>
|
335 |
+
<input type="checkbox" name="<?=$this->get_field_name('authors')?>[]" id="<?=$this->get_field_id('author_' . $user->ID)?>" value="<?=$user->ID?>" <?= in_array($user->ID, $authors, true) ? 'checked="checked"' : "" ?> />
|
336 |
+
<label for="<?=$this->get_field_id('author_' . $user->ID)?>"><?=$user->user_login?></label><br/>
|
337 |
+
<?php endforeach; ?>
|
338 |
+
<br/>
|
339 |
+
<? _e("Order:"); ?><br/>
|
340 |
+
<input type="radio" name="<?=$this->get_field_name('order')?>" id="<?=$this->get_field_id('order_random')?>" value="random" <?= $order == "random" ? ' checked="checked" ' : "" ?>/>
|
341 |
+
<label for="<?=$this->get_field_id('order_random')?>"><?_e("Random")?></label><br/>
|
342 |
+
<input type="radio" name="<?=$this->get_field_name('order')?>" id="<?=$this->get_field_id('order_alphabetically')?>" value="alphabetically" <?= $order == "alphabetically" ? ' checked="checked"' : "" ?>/>
|
343 |
+
<label for="<?=$this->get_field_id('order_alphabetically')?>"><?_e("Alphabetically")?></label><br/>
|
344 |
+
<input type="radio" name="<?=$this->get_field_name('order')?>" id="<?=$this->get_field_id('order_count')?>" value="count" <?= $order == "count" || strlen($order) == 0 ? ' checked="checked" ' : "" ?>/>
|
345 |
+
<label for="<?=$this->get_field_id('order_count')?>"><?_e("Count")?></label><br/>
|
346 |
+
<input type="checkbox" name="<?=$this->get_field_name('reverse')?>" id="<?=$this->get_field_id('reverse')?>" <?= $reverse === true ? ' checked="checked"' : "" ?> />
|
347 |
+
<label for="<?=$this->get_field_id('reverse')?>"><?_e("Reverse order")?></label><br/>
|
348 |
+
<br/>
|
349 |
+
<label for="<?=$this->get_field_id('taxonomy')?>"><?_e("Taxonomy:")?></label><br/>
|
350 |
+
<select id="<?=$this->get_field_id('taxonomy')?>" name="<?=$this->get_field_name('taxonomy')?>">
|
351 |
+
<option value="post_tag" <?= $taxonomy == "post_tag" || strlen($taxonomy) == 0 ? 'selected="selected"' : ""?>><?_e("Post Tags")?></option>
|
352 |
+
<option value="category" <?= $taxonomy == "category" ? 'selected="selected"' : ""?>><?_e("Categories")?></option>
|
353 |
+
</select><br/>
|
354 |
+
<br/>
|
355 |
+
<label for="<?=$this->get_field_id('exclude')?>"><?_e("Exclude:")?></label>
|
356 |
+
<input type="text" name="<?=$this->get_field_name('exclude')?>" id="<?=$this->get_field_id('exclude')?>" value="<?=implode(",", $exclude)?>" />
|
357 |
+
</fieldset>
|
358 |
+
|
359 |
+
<fieldset class="utcw">
|
360 |
+
<legend><?_e("Appearance")?></legend>
|
361 |
+
<label for="<?=$this->get_field_id('title');?>"><? _e("Title:") ?></label><br/>
|
362 |
+
<input type="text" id="<?=$this->get_field_id('title');?>" name="<?=$this->get_field_name('title');?>" value="<?= strlen($title) > 0 ? $title : $this->default_title?>" /><br/>
|
363 |
+
<br/>
|
364 |
+
<?_e("Tag size (in px):")?><br/>
|
365 |
+
<label for="<?=$this->get_field_id('size_from')?>"><?_e("From")?></label>
|
366 |
+
<input type="text" name="<?=$this->get_field_name('size_from')?>" id="<?=$this->get_field_id('size_from')?>" size="3" value="<?=is_numeric($size_from) ? $size_from : $this->default_size_from?>" />
|
367 |
+
<label for="<?=$this->get_field_id('size_to')?>"><?_e("to")?></label>
|
368 |
+
<input type="text" name="<?=$this->get_field_name('size_to')?>" id="<?=$this->get_field_id('size_to')?>" size="3" value="<?=is_numeric($size_to) ? $size_to : $this->default_size_to?>" /><br/>
|
369 |
+
<br/>
|
370 |
+
<label for="<?=$this->get_field_id('max')?>"><?_e("Max tags:")?></label><br/>
|
371 |
+
<input type="text" name="<?=$this->get_field_name('max')?>" id="<?=$this->get_field_id('max')?>" value="<?=is_numeric($max) ? $max : $this->default_max?>" /><br/>
|
372 |
+
<br/>
|
373 |
+
<?_e("Coloring:") ?><br/>
|
374 |
+
<input type="radio" name="<?=$this->get_field_name('color')?>" id="<?=$this->get_field_id('color_none')?>" value="none" <?= $color == "none" || empty($color) ? 'checked="checked"' : "" ?> onclick="javascript:utcw_change()" />
|
375 |
+
<label for="<?=$this->get_field_id('color_none')?>"><?_e("None")?></label><br/>
|
376 |
+
<input type="radio" name="<?=$this->get_field_name('color')?>" id="<?=$this->get_field_id('color_random')?>" value="random" <?= $color == "random" ? 'checked="checked"' : "" ?> onclick="javascript:utcw_change()" />
|
377 |
+
<label for="<?=$this->get_field_id('color_random')?>"><?_e("Totally random")?></label><br/>
|
378 |
+
<input type="radio" name="<?=$this->get_field_name('color')?>" id="<?=$this->get_field_id('color_set')?>" value="set" <?= $color == "set" ? 'checked="checked"' : "" ?> onclick="javascript:utcw_change()" />
|
379 |
+
<label for="<?=$this->get_field_id('color_set')?>"><?_e("Random from preset values")?></label><br/>
|
380 |
+
<div id="<?=$this->get_field_id('set_chooser')?>" <?= $color != "set" ? 'class="utcw-hidden"' : "" ?>>
|
381 |
+
<input type="text" name="<?=$this->get_field_name('color_set')?>" id="<?=$this->get_field_id('color_set_chooser')?>" value="<?= implode(",", $color_set) ?>" />
|
382 |
+
</div>
|
383 |
+
<input type="radio" name="<?=$this->get_field_name('color')?>" id="<?=$this->get_field_id('color_span')?>" value="span" <?= $color == "span" ? 'checked="checked"' : "" ?> onclick="javascript:utcw_change()" />
|
384 |
+
<label for="<?=$this->get_field_id('color_span')?>"><?_e("Spanning between values")?></label><br/>
|
385 |
+
<div id="<?=$this->get_field_id('span_chooser')?>" <?= $color != "span" ? 'class="utcw-hidden"' : "" ?>>
|
386 |
+
<?_e("From")?> <input type="text" size="7" name="<?=$this->get_field_name('color_span_from')?>" id="<?=$this->get_field_id('color_span_from')?>" value="<?=$color_span_from?>" />
|
387 |
+
<?_e("to")?> <input type="text" size="7" name="<?=$this->get_field_name('color_span_to')?>"" id="<?=$this->get_field_id('color_span_to')?>" value="<?=$color_span_to?>" />
|
388 |
+
</div>
|
389 |
+
<br/>
|
390 |
+
<?_e("Spacing (in px):")?><br/>
|
391 |
+
<label for="<?=$this->get_field_id('letter_spacing')?>"><?_e("Between letters:")?></label>
|
392 |
+
<input type="text" size="5" name="<?=$this->get_field_name('letter_spacing')?>" id="<?=$this->get_field_id?>" value="<?=strlen($letter_spacing) > 0 ? $letter_spacing : $this->default_letter_spacing?>" /><br/>
|
393 |
+
<label for="<?=$this->get_field_id('word_spacing')?>"><?_e("Between words:")?></label>
|
394 |
+
<input type="text" size="5" name="<?=$this->get_field_name('word_spacing')?>" id="<?=$this->get_field_id('word_spacing')?>" value="<?=strlen($word_spacing) > 0 ? $word_spacing : $this->default_word_spacing?>" /><br/>
|
395 |
+
<br/>
|
396 |
+
<?_e("Transform tags:")?><br/>
|
397 |
+
<input type="radio" name="<?=$this->get_field_name('case')?>" id="<?=$this->get_field_id('text_transform_off')?>" value="off" <?= ($case == "off" || empty($case)) ? ' checked="checked"' : "" ?> />
|
398 |
+
<label for="<?=$this->get_field_id('text_transform_off')?>"><?_e("Off")?></label><br/>
|
399 |
+
<input type="radio" name="<?=$this->get_field_name('case')?>" id="<?=$this->get_field_id('text_transform_lowercase')?>" value="lowercase" <?= $case == "lowercase" ? ' checked="checked"' : "" ?> />
|
400 |
+
<label for="<?=$this->get_field_id('text_transform_lowercase')?>"><?_e("To lowercase")?></label><br/>
|
401 |
+
<input type="radio" name="<?=$this->get_field_name('case')?>" id="<?=$this->get_field_id('text_transform_uppercase')?>" value="uppercase" <?= $case == "uppercase" ? ' checked="checked"' : "" ?> />
|
402 |
+
<label for="<?=$this->get_field_id('text_transform_uppercase')?>"><?_e("To uppercase")?></label><br/>
|
403 |
+
<input type="radio" name="<?=$this->get_field_name('case')?>" id="<?=$this->get_field_id('text_transform_capitalize')?>" value="capitalize" <?= $case == "capitalize" ? ' checked="checked"' : "" ?> />
|
404 |
+
<label for="<?=$this->get_field_id('text_transform_capitalize')?>"><?_e("Capitalize")?></label><br/>
|
405 |
+
</fieldset>
|
406 |
+
<?
|
407 |
+
}
|
408 |
+
/**
|
409 |
+
* Used to calculate how step size in spanning values
|
410 |
+
* @param integer $min
|
411 |
+
* @param integer $max
|
412 |
+
* @param integer $from
|
413 |
+
* @param integer $to
|
414 |
+
* @return integer
|
415 |
+
*/
|
416 |
+
private function calc_step($min, $max, $from, $to) {
|
417 |
+
|
418 |
+
// Thank you wordpress for this
|
419 |
+
$spread = $max - $min;
|
420 |
+
if ( $spread <= 0 )
|
421 |
+
$spread = 1;
|
422 |
+
$font_spread = $to - $from;
|
423 |
+
if ( $font_spread < 0 && $negative === false)
|
424 |
+
$font_spread = 1;
|
425 |
+
$step = $font_spread / $spread;
|
426 |
+
|
427 |
+
return $step;
|
428 |
+
}
|
429 |
+
}
|
430 |
+
|
431 |
+
// Register widget with wordpress
|
432 |
+
add_action('widgets_init', create_function('', 'return register_widget("UTCW");'));
|
433 |
+
|
434 |
+
//Register scripts and css with wordpress
|
435 |
+
wp_register_script('utcw-js', '/wp-content/plugins/ultimate-tag-cloud-widget/utcw.js', array('jquery'), rand(), false);
|
436 |
+
wp_register_style('utcw-css', '/wp-content/plugins/ultimate-tag-cloud-widget/utcw.css', array(), rand(), 'all');
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Action handler for wordpress init used to attach scripts and styles
|
440 |
+
* @return void
|
441 |
+
*/
|
442 |
+
function utcw_init() {
|
443 |
+
wp_enqueue_script('utcw-js');
|
444 |
+
wp_enqueue_style('utcw-css');
|
445 |
+
}
|
446 |
+
add_action('init', 'utcw_init');
|
447 |
+
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Compare function for sorting by count
|
451 |
+
* @param array $a
|
452 |
+
* @param array $b
|
453 |
+
* @return integer
|
454 |
+
*/
|
455 |
+
function utcw_cmp_count($a, $b) {
|
456 |
+
if ($a['count'] == $b['count']) {
|
457 |
+
return 0;
|
458 |
+
} else{
|
459 |
+
return ($a['count'] < $b['count']) ? -1 : 1;
|
460 |
+
}
|
461 |
+
}
|
462 |
+
|
463 |
+
/**
|
464 |
+
* Compare function for sorting by name
|
465 |
+
* @param array $a
|
466 |
+
* @param array $b
|
467 |
+
* @return integer
|
468 |
+
*/
|
469 |
+
function utcw_cmp_name($a, $b) {
|
470 |
+
return strcasecmp($a['name'], $b['name']);
|
471 |
+
}
|
utcw.css
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fieldset.utcw {
|
2 |
+
padding: 10px;
|
3 |
+
border: solid 1px #dfdfdf;
|
4 |
+
border-radius: 4px;
|
5 |
+
-moz-border-radius: 4px;
|
6 |
+
}
|
7 |
+
.utcw-hidden {
|
8 |
+
display:none;
|
9 |
+
}
|
10 |
+
div.widget_utcw {
|
11 |
+
word-wrap: break-word;
|
12 |
+
}
|
utcw.js
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function utcw_change() {
|
2 |
+
|
3 |
+
jQuery("div[id$='set_chooser']").addClass('utcw-hidden');
|
4 |
+
jQuery("div[id$='span_chooser']").addClass('utcw-hidden');
|
5 |
+
|
6 |
+
jQuery("input[id$='color_set']:checked").each(function() {
|
7 |
+
jQuery("div[id$='set_chooser']").removeClass('utcw-hidden');
|
8 |
+
});
|
9 |
+
|
10 |
+
jQuery("input[id$='color_span']:checked").each(function() {
|
11 |
+
jQuery("div[id$='span_chooser']").removeClass('utcw-hidden');
|
12 |
+
});
|
13 |
+
}
|