/**
  * Generate iconized tag cloud
  *
  * Attached to "wp_generate_tag_cloud" filter, extends default wp_generate_tag_cloud() function.
  *
  * @since    1.1.0
  *
  * @uses Iconize_WP::get_iconize_support_for()
  * @uses Iconize_WP::iconize_get_term_icon_by()
  * @uses Iconize_WP::iconize_get_icon()
  */
 public function iconize_wp_generate_tag_cloud($return, $tags, $args)
 {
     // Modify default functionality
     $defaults = array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', 'topic_count_text' => null, 'topic_count_text_callback' => null, 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1);
     // Insert "iconized" arg to defaults
     if (!isset($defaults['iconized'])) {
         /**
          * Let users decide wheather to display iconized tag cloud or default one on each wp_tag_cloud() usage.
          * Iconized tag cloud disabled by default
          */
         $iconized_defaults = array();
         // If in admin area, display icons - better for end user
         if (is_admin()) {
             $iconized_defaults = array('hover_effect' => 'default', 'color' => 'default', 'hover_effect_trigger' => 'link', 'hover_color_change' => false, 'fallback_icon' => array(), 'override_icons' => false, 'style' => 'default', 'after_icon' => ' ');
         }
         /**
          * Apply "iconize_tag_cloud_defaults" filter to allow users to change default value of "iconized" parameter.
          */
         $defaults['iconized'] = apply_filters('iconized_tag_cloud_defaults', $iconized_defaults, $args);
     }
     $args = wp_parse_args($args, $defaults);
     // Check if iconize is enabled on this taxonomy
     if (isset($args['taxonomy'])) {
         $tax_support = $this->get_iconize_support_for('taxonomy_' . $args['taxonomy']);
         $tax_icons_enabled = $tax_support['enabled'];
     } else {
         $tax_icons_enabled = false;
     }
     // Return output if no iconized arg or iconize is disabled
     if (false === (bool) $args['iconized'] || !$tax_icons_enabled) {
         return $return;
     }
     // Continue with default logic
     extract($args, EXTR_SKIP);
     $return = 'array' === $format ? array() : '';
     if (empty($tags)) {
         return $return;
     }
     // Juggle topic count tooltips:
     if (isset($args['topic_count_text'])) {
         // First look for nooped plural support via topic_count_text.
         $translate_nooped_plural = $args['topic_count_text'];
     } elseif (!empty($args['topic_count_text_callback'])) {
         // Look for the alternative callback style. Ignore the previous default.
         if ($args['topic_count_text_callback'] === 'default_topic_count_text') {
             $translate_nooped_plural = _n_noop('%s topic', '%s topics');
         } else {
             $translate_nooped_plural = false;
         }
     } elseif (isset($args['single_text']) && isset($args['multiple_text'])) {
         // If no callback exists, look for the old-style single_text and multiple_text arguments.
         $translate_nooped_plural = _n_noop($args['single_text'], $args['multiple_text']);
     } else {
         // This is the default for when no callback, plural, or argument is passed in.
         $translate_nooped_plural = _n_noop('%s topic', '%s topics');
     }
     $tags_sorted = apply_filters('tag_cloud_sort', $tags, $args);
     if (empty($tags_sorted)) {
         return $return;
     }
     if ($tags_sorted !== $tags) {
         $tags = $tags_sorted;
         unset($tags_sorted);
     } else {
         if ('RAND' === $order) {
             shuffle($tags);
         } else {
             // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
             if ('name' === $orderby) {
                 uasort($tags, '_wp_object_name_sort_cb');
             } else {
                 uasort($tags, '_wp_object_count_sort_cb');
             }
             if ('DESC' === $order) {
                 $tags = array_reverse($tags, true);
             }
         }
     }
     if ($number > 0) {
         $tags = array_slice($tags, 0, $number);
     }
     $counts = array();
     $real_counts = array();
     // For the alt tag
     foreach ((array) $tags as $key => $tag) {
         $real_counts[$key] = $tag->count;
         $counts[$key] = $topic_count_scale_callback($tag->count);
     }
     $min_count = min($counts);
     $spread = max($counts) - $min_count;
     if ($spread <= 0) {
         $spread = 1;
     }
     $font_spread = $largest - $smallest;
     if ($font_spread < 0) {
         $font_spread = 1;
     }
     $font_step = $font_spread / $spread;
     // Validate custom settings passed with 'iconize' arg to wp_tag_cloud().
     $hover_effect = isset($iconized['hover_effect']) ? (string) $iconized['hover_effect'] : 'default';
     $color = isset($iconized['color']) ? (string) $iconized['color'] : 'default';
     $hover_effect_trigger = isset($iconized['hover_effect_trigger']) ? (string) $iconized['hover_effect_trigger'] : 'link';
     $hover_color_change = isset($iconized['hover_color_change']) ? (bool) $iconized['hover_color_change'] : false;
     $fallback_icon_args = isset($iconized['fallback_icon']) ? (array) $iconized['fallback_icon'] : array();
     $override_icons = isset($iconized['override_icons']) ? (bool) $iconized['override_icons'] : false;
     $style = isset($iconized['style']) ? (string) $iconized['style'] : 'default';
     $after_icon = isset($iconized['after_icon']) ? (string) $iconized['after_icon'] : '&nbsp;';
     $a = array();
     foreach ($tags as $key => $tag) {
         $count = $counts[$key];
         $real_count = $real_counts[$key];
         $tag_link = '#' != $tag->link ? esc_url($tag->link) : '#';
         $tag_id = isset($tags[$key]->id) ? $tags[$key]->id : $key;
         $tag_name = $tags[$key]->name;
         if ($translate_nooped_plural) {
             $title_attribute = sprintf(translate_nooped_plural($translate_nooped_plural, $real_count), number_format_i18n($real_count));
         } else {
             $title_attribute = call_user_func($topic_count_text_callback, $real_count, $tag, $args);
         }
         // Retrive an array of settings for term icon configured in term edit screen if there is an icon.
         $icon = iconize_get_term_icon_by('name', $tag_name, $taxonomy);
         $term_icon_args = array();
         if (!empty($icon)) {
             $term_icon_args = iconize_get_term_icon_by('name', $tag_name, $taxonomy, 'array');
         }
         // Determine which icon to display.
         if (true === $override_icons) {
             $icon_args = $fallback_icon_args;
         } else {
             $icon_args = $term_icon_args;
             if (empty($icon_args) && !empty($fallback_icon_args)) {
                 $icon_args = $fallback_icon_args;
             }
         }
         // Modify icon args if needed.
         if (!empty($icon_args)) {
             if (true === $hover_color_change && false === strpos($icon_args['icon_custom_classes'], 'hover-color-change')) {
                 $icon_args['icon_custom_classes'] .= !empty($icon_args['icon_custom_classes']) ? ',hover-color-change' : 'hover-color-change';
             }
             // Override effect and color if needed
             if ('default' !== $hover_effect) {
                 $icon_args['icon_transform'] = $hover_effect;
             }
             if ('default' !== $color) {
                 $icon_args['icon_color'] = $color;
             }
         }
         // Generate icon html.
         $icon_html = iconize_get_icon($icon_args, $taxonomy, $after_icon);
         // Add hover effect class to link if needed.
         $het_link = '';
         if ('link' === $hover_effect_trigger && !empty($icon_html) && !empty($icon_args['icon_transform']) && !empty($hover_effect)) {
             $het_link = ' iconized-hover-trigger';
         }
         // Generate link.
         $a[] = "<a href='{$tag_link}' class='{$style}-style iconized-tag-link{$het_link} tag-link-{$tag_id}' title='" . esc_attr($title_attribute) . "' style='font-size: " . str_replace(',', '.', $smallest + ($count - $min_count) * $font_step) . "{$unit};'>{$icon_html}{$tag_name}</a>";
     }
     switch ($format) {
         case 'array':
             $return =& $a;
             break;
         case 'list':
             $return = "<ul class='wp-tag-cloud'>\n\t<li>";
             $return .= join("</li>\n\t<li>", $a);
             $return .= "</li>\n</ul>\n";
             break;
         default:
             $return = join($separator, $a);
             break;
     }
     return $return;
 }
 /**
  * Start the element output.
  *
  * @see Walker::start_el()
  *
  * @since 1.1.0
  *
  * @uses iconize_get_term_icon_by()
  * @uses iconize_get_icon()
  *
  * @param string $output   Passed by reference. Used to append additional content.
  * @param object $category Category data object.
  * @param int    $depth    Depth of category in reference to parents. Default 0.
  * @param array  $args     An array of arguments. @see wp_list_categories()
  * @param int    $id       ID of the current category.
  */
 function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0)
 {
     extract($args);
     // Retrive an array of settings for term icon configured in term edit screen if there is icon.
     $icon = iconize_get_term_icon_by('id', $category->term_id, $category->taxonomy);
     $term_icon_args = array();
     if (!empty($icon)) {
         $term_icon_args = iconize_get_term_icon_by('id', $category->term_id, $category->taxonomy, 'array');
     }
     // Validate custom settings passed with 'iconize' arg to wp_list_categories().
     $hover_effect = isset($iconized['hover_effect']) ? (string) $iconized['hover_effect'] : 'default';
     $color = isset($iconized['color']) ? (string) $iconized['color'] : 'default';
     $hover_effect_trigger = isset($iconized['hover_effect_trigger']) ? (string) $iconized['hover_effect_trigger'] : 'link';
     $hover_color_change = isset($iconized['hover_color_change']) ? (bool) $iconized['hover_color_change'] : false;
     $fallback_icon_args = isset($iconized['fallback_icon']) ? (array) $iconized['fallback_icon'] : array();
     $override_icons = isset($iconized['override_icons']) ? (bool) $iconized['override_icons'] : false;
     $style = isset($iconized['style']) ? (string) $iconized['style'] : 'default';
     $after_icon = isset($iconized['after_icon']) ? (string) $iconized['after_icon'] : '&nbsp;&nbsp;';
     // Determine which icon to display.
     if (true === $override_icons) {
         $icon_args = $fallback_icon_args;
     } else {
         $icon_args = $term_icon_args;
         if (empty($icon_args) && !empty($fallback_icon_args)) {
             $icon_args = $fallback_icon_args;
         }
     }
     // Modify icon args if needed.
     if (!empty($icon_args)) {
         if ('iconize' === $style) {
             $icon_args['icon_custom_classes'] .= !empty($icon_args['icon_custom_classes']) ? ',iconized-li' : 'iconized-li';
         }
         if (true === $hover_color_change && false === strpos($icon_args['icon_custom_classes'], 'hover-color-change')) {
             $icon_args['icon_custom_classes'] .= !empty($icon_args['icon_custom_classes']) ? ',hover-color-change' : 'hover-color-change';
         }
         // Override effect and color if needed
         if ('default' !== $hover_effect) {
             $icon_args['icon_transform'] = $hover_effect;
         }
         if ('default' !== $color) {
             $icon_args['icon_color'] = $color;
         }
     }
     // Generate icon html.
     $icon_html = iconize_get_icon($icon_args, $category->taxonomy, $after_icon);
     // Generate iconized link.
     $cat_name = esc_attr($category->name);
     $cat_name = apply_filters('list_cats', $cat_name, $category);
     $link = '<a href="' . esc_url(get_term_link($category)) . '" ';
     if (0 == $use_desc_for_title || empty($category->description)) {
         $link .= 'title="' . esc_attr(sprintf(__('View all posts filed under %s', 'iconize'), $cat_name)) . '"';
     } else {
         $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"';
     }
     // Add hover effect class to link if needed.
     if ('link' === $hover_effect_trigger && !empty($icon_html) && !empty($icon_args['icon_transform']) && !empty($hover_effect)) {
         $link .= ' class="iconized-hover-trigger"';
     }
     $link .= '>';
     $link .= $icon_html;
     $link .= $cat_name . '</a>';
     // The rest
     if (!empty($feed_image) || !empty($feed)) {
         $link .= ' ';
         if (empty($feed_image)) {
             $link .= '(';
         }
         $link .= '<a href="' . esc_url(get_term_feed_link($category->term_id, $category->taxonomy, $feed_type)) . '"';
         if (empty($feed)) {
             $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s', 'iconize'), $cat_name) . '"';
         } else {
             $title = ' title="' . $feed . '"';
             $alt = ' alt="' . $feed . '"';
             $name = $feed;
             $link .= $title;
         }
         $link .= '>';
         if (empty($feed_image)) {
             $link .= $name;
         } else {
             $link .= "<img src='{$feed_image}'{$alt}{$title}" . ' />';
         }
         $link .= '</a>';
         if (empty($feed_image)) {
             $link .= ')';
         }
     }
     if (!empty($show_count)) {
         $link .= ' (' . intval($category->count) . ')';
     }
     if ('list' === $args['style']) {
         $output .= "\t<li";
         $class = 'cat-item cat-item-' . $category->term_id;
         if (!empty($current_category)) {
             $_current_category = get_term($current_category, $category->taxonomy);
             if ($category->term_id == $current_category) {
                 $class .= ' current-cat';
             } elseif ($category->term_id == $_current_category->parent) {
                 $class .= ' current-cat-parent';
             }
         }
         $output .= ' class="' . $class . '"';
         $output .= ">{$link}\n";
     } else {
         $output .= "\t{$link}<br />\n";
     }
 }