50, 'big' => 150, 'unit' => '%', 'align' => 'justify', 'orderby' => 'name', 'order' => 'ASC', 'min' => 0, 'hide-empty' => 1, 'hide-poweredby' => 1);
$options = (array) get_option('widget_catcloud');
foreach ( $defaults as $key => $value )
if ( !isset($options[$key]) )
$options[$key] = $defaults[$key];
echo $before_widget;
// omit title if not specified
if ($options['title'] != '')
echo $before_title . $options['title'] . $after_title;
if ($options['exclude'] != '')
$exclude = '&exclude=' . $options['exclude'];
$hide_empty = '&hide_empty=' . $options['hide-empty'];
// check which version of wp is being used
if ( function_exists('get_categories') )
{
// new version of wp (2.1+)
$cats = get_categories("style=cloud&show_count=1&use_desc_for_title=0$exclude&hierarchical=0$hide_empty");
foreach ($cats as $cat)
{
$catlink = get_category_link( $cat->cat_ID );
$catname = $cat->cat_name;
$count = $cat->category_count;
if ($count >= $options['min'])
{
$counts{$catname} = $count;
$catlinks{$catname} = $catlink;
}
}
}
else
{
// old version of wp (pre-2.1)
$cats = wp_list_cats("list=0&sort_column=name&optioncount=1&use_desc_for_title=0$exclude&recurse=1&hierarchical=0$hide_empty");
$cats = explode("
\n", $cats);
foreach ($cats as $cat)
{
$regs = array(); // initialise the regs array
eregi("a href=\"(.+)\" ", $cat, $regs);
$catlink = $regs[1];
$cat = trim(strip_tags($cat));
eregi("(.*) \(([0-9]+)\)$", $cat, $regs);
$catname = $regs[1];
$count = $regs[2];
if ($count >= $options['min'])
{
$counts{$catname} = $count;
$catlinks{$catname} = $catlink;
}
}
}
$spread = max($counts) - min($counts);
if ($spread <= 0) { $spread = 1; };
$fontspread = $options['big'] - $options['small'];
$fontstep = $spread / $fontspread;
if ($fontspread <= 0) { $fontspread = 1; }
echo '';
if ('count' == $options['orderby'])
{
if ('DESC' == $options['order'])
arsort($counts);
else
asort($counts);
}
elseif ('name' == $options['orderby'])
{
if ('DESC' == $options['order'])
uksort($counts, create_function('$a, $b', 'return -(strnatcasecmp($a, $b));'));
else
uksort($counts, 'strnatcasecmp');
}
foreach ($counts as $catname => $count)
{
$catlink = $catlinks{$catname};
echo "\n$catname ";
}
echo '
';
if (!$options['hide-poweredby'])
echo '-- Powered by Category Cloud
';
echo $after_widget;
}
// Tell Dynamic Sidebar about our new widget and its control
register_sidebar_widget('Category Cloud', 'widget_catcloud');
register_widget_control('Category Cloud', 'widget_catcloud_control', 315, 420);
}
// Delay plugin execution to ensure Dynamic Sidebar has a chance to load first
add_action('init', 'widget_catcloud_init');
?>