/**
  * Generate extended tag cloud
  *
  * @param string $args
  * @return string|array
  */
 public static function extendedTagCloud($args = '', $copyright = true)
 {
     $defaults = array('taxonomy' => 'post_tag', 'size' => 'true', 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'color' => 'true', 'maxcolor' => '#000000', 'mincolor' => '#CCCCCC', 'number' => 45, 'format' => 'flat', 'selectionby' => 'count', 'selection' => 'desc', 'orderby' => 'random', 'order' => 'asc', 'exclude' => '', 'include' => '', 'limit_days' => 0, 'min_usage' => 0, 'notagstext' => __('No tags.', 'simpletags'), 'xformat' => __('<a href="%tag_link%" id="tag-link-%tag_id%" class="st-tags t%tag_scale%" title="%tag_count% topics" %tag_rel% style="%tag_size% %tag_color%">%tag_name%</a>', 'simpletags'), 'title' => __('<h4>Tag Cloud</h4>', 'simpletags'), 'category' => 0);
     // Get options
     $options = SimpleTags_Plugin::get_option();
     // Get values in DB
     $defaults['taxonomy'] = $options['cloud_taxonomy'];
     $defaults['selectionby'] = $options['cloud_selectionby'];
     $defaults['selection'] = $options['cloud_selection'];
     $defaults['orderby'] = $options['cloud_orderby'];
     $defaults['order'] = $options['cloud_order'];
     $defaults['number'] = $options['cloud_limit_qty'];
     $defaults['notagstext'] = $options['cloud_notagstext'];
     $defaults['title'] = $options['cloud_title'];
     $defaults['maxcolor'] = $options['cloud_max_color'];
     $defaults['mincolor'] = $options['cloud_min_color'];
     $defaults['largest'] = $options['cloud_max_size'];
     $defaults['smallest'] = $options['cloud_min_size'];
     $defaults['unit'] = $options['cloud_unit'];
     $defaults['xformat'] = $options['cloud_xformat'];
     $defaults['format'] = $options['cloud_format'];
     if (empty($args)) {
         $args = $options['cloud_adv_usage'];
     }
     $args = wp_parse_args($args, $defaults);
     // Get correct taxonomy ?
     $taxonomy = self::_get_current_taxonomy($args['taxonomy']);
     // Get terms
     $terms = self::getTags($args, $taxonomy);
     extract($args);
     // Params to variables
     // If empty use default xformat !
     if (empty($xformat)) {
         $xformat = $defaults['xformat'];
     }
     // Clean memory
     $args = array();
     $defaults = array();
     unset($args, $defaults);
     if (empty($terms)) {
         return SimpleTags_Client::output_content('st-tag-cloud', $format, $title, $notagstext, $copyright);
     }
     $counts = $terms_data = array();
     foreach ((array) $terms as $term) {
         $counts[$term->name] = $term->count;
         $terms_data[$term->name] = $term;
     }
     // Remove temp data from memory
     $terms = array();
     unset($terms);
     // Use full RBG code
     if (strlen($maxcolor) == 4) {
         $maxcolor = $maxcolor . substr($maxcolor, 1, strlen($maxcolor));
     }
     if (strlen($mincolor) == 4) {
         $mincolor = $mincolor . substr($mincolor, 1, strlen($mincolor));
     }
     // Check as smallest inferior or egal to largest
     if ($smallest > $largest) {
         $smallest = $largest;
     }
     // Scaling - Hard value for the moment
     $scale_min = 1;
     $scale_max = 10;
     $minval = min($counts);
     $maxval = max($counts);
     $minout = max($scale_min, 0);
     $maxout = max($scale_max, $minout);
     $scale = $maxval > $minval ? ($maxout - $minout) / ($maxval - $minval) : 0;
     // HTML Rel (tag/no-follow)
     $rel = SimpleTags_Client::get_rel_attribut();
     // Remove color marquer if color = false
     if ($color == 'false') {
         $xformat = str_replace('%tag_color%', '', $xformat);
     }
     // Remove size marquer if size = false
     if ($size == 'false') {
         $xformat = str_replace('%tag_size%', '', $xformat);
     }
     // Order terms before output
     // count, name, rand | asc, desc
     $orderby = strtolower($orderby);
     if ($orderby == 'count') {
         asort($counts);
     } elseif ($orderby == 'name') {
         uksort($counts, array(__CLASS__, 'uksortByName'));
     } else {
         // rand
         SimpleTags_Client::random_array($counts);
     }
     $order = strtolower($order);
     if ($order == 'desc' && $orderby != 'random') {
         $counts = array_reverse($counts);
     }
     $output = array();
     foreach ((array) $counts as $term_name => $count) {
         if (!is_object($terms_data[$term_name])) {
             continue;
         }
         $term = $terms_data[$term_name];
         $scale_result = (int) (($term->count - $minval) * $scale + $minout);
         $output[] = SimpleTags_Client::format_internal_tag($xformat, $term, $rel, $scale_result, $scale_max, $scale_min, $largest, $smallest, $unit, $maxcolor, $mincolor);
     }
     // Remove unused variables
     $counts = array();
     $terms = array();
     unset($counts, $terms, $term);
     return SimpleTags_Client::output_content('st-tag-cloud', $format, $title, $output, $copyright);
 }
 /**
  * Generate current post tags
  *
  * @param string $args
  * @return string
  */
 public static function extendedPostTags($args = '', $copyright = true)
 {
     // Get options
     $options = SimpleTags_Plugin::get_option();
     // Default values
     $defaults = array('before' => __('Tags: ', 'simpletags'), 'separator' => ', ', 'after' => '<br />', 'post_id' => 0, 'inc_cats' => 0, 'xformat' => __('<a href="%tag_link%" title="%tag_name_attribute%" %tag_rel%>%tag_name%</a>', 'simpletags'), 'notagtext' => __('No tag for this post.', 'simpletags'), 'number' => 0, 'format' => '');
     // Get values in DB
     $defaults['before'] = $options['tt_before'];
     $defaults['separator'] = $options['tt_separator'];
     $defaults['after'] = $options['tt_after'];
     $defaults['inc_cats'] = $options['tt_inc_cats'];
     $defaults['xformat'] = $options['tt_xformat'];
     $defaults['notagtext'] = $options['tt_notagstext'];
     $defaults['number'] = (int) $options['tt_number'];
     if (empty($args)) {
         $args = $options['tt_adv_usage'];
     }
     // Extract data in variables
     $args = wp_parse_args($args, $defaults);
     extract($args);
     // If empty use default xformat !
     if (empty($xformat)) {
         $xformat = $defaults['xformat'];
     }
     // Clean memory
     $args = array();
     $defaults = array();
     // Choose post ID
     $object_id = (int) $post_id;
     if ($object_id == 0) {
         global $post;
         $object_id = (int) $post->ID;
         if ($object_id == 0) {
             return false;
         }
     }
     // Get categories ?
     $taxonomy = (int) $inc_cats == 0 ? 'post_tag' : array('post_tag', 'category');
     // Get terms
     $terms = get_object_term_cache($object_id, $taxonomy);
     if (false === $terms) {
         $terms = wp_get_object_terms($object_id, $taxonomy);
     }
     // Hook
     $terms = apply_filters('get_the_tags', $terms);
     // Limit to max quantity if set
     $number = (int) $number;
     if ($number != 0) {
         shuffle($terms);
         // Randomize terms
         $terms = array_slice($terms, 0, $number);
     }
     // Return for object format
     if ($format == 'object') {
         return $terms;
     }
     // If no terms, return text nothing.
     if (empty($terms)) {
         return $notagtext;
     }
     // HTML Rel
     $rel = SimpleTags_Client::get_rel_attribut();
     // Prepare output
     foreach ((array) $terms as $term) {
         if (!is_object($term)) {
             continue;
         }
         $output[] = SimpleTags_Client::format_internal_tag($xformat, $term, $rel, null);
     }
     // Clean memory
     $terms = array();
     unset($terms, $term);
     // Array to string
     if (is_array($output) && !empty($output)) {
         $output = implode($separator, $output);
     } else {
         $output = $notagtext;
     }
     // Add container
     $output = $before . $output . $after;
     return SimpleTags_Client::output_content('', 'string', '', $output, $copyright);
 }