/**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * Get and format tags from list ID (SQL Group Concat)
  *
  * @param string $terms
  *
  * @return string
  * @author Amaury Balmer
  */
 public static function get_tags_from_id($terms = '', $taxonomy = 'post_tag')
 {
     if (empty($terms)) {
         return '';
     }
     // Get tags since Term ID.
     $terms = (array) get_terms($taxonomy, 'include=' . $terms);
     if (empty($terms)) {
         return '';
     }
     // HTML Rel (tag)
     $rel = SimpleTags_Client::get_rel_attribut();
     $output = array();
     foreach ((array) $terms as $term) {
         $link = get_term_link($term->term_id, $term->taxonomy);
         if (empty($link) || is_wp_error($link)) {
             continue;
         }
         $output[] = '<a href="' . $link . '" title="' . esc_attr(sprintf(_n('%d topic', '%d topics', (int) $term->count, 'simpletags'), $term->count)) . '" ' . $rel . '>' . esc_html($term->name) . '</a>';
     }
     return implode(', ', $output);
 }
 /**
  * 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);
 }
 /**
  * Replace text by link to tag
  *
  * @param string $content
  * @return string
  */
 public static function the_content($content = '')
 {
     global $post;
     // Show only on singular view ? Check context
     if (SimpleTags_Plugin::get_option_value('auto_link_views') == 'singular' && !is_singular()) {
         return $content;
     }
     // user preference for this post ?
     $meta_value = get_post_meta($post->ID, '_exclude_autolinks', true);
     if (!empty($meta_value)) {
         return $content;
     }
     // Get currents tags if no exists
     self::prepare_auto_link_tags();
     // Shuffle array
     SimpleTags_Client::random_array(self::$link_tags);
     // HTML Rel (tag/no-follow)
     $rel = SimpleTags_Client::get_rel_attribut();
     // only continue if the database actually returned any links
     if (!isset(self::$link_tags) || !is_array(self::$link_tags) || empty(self::$link_tags)) {
         return $content;
     }
     // Case option ?
     $case = (int) SimpleTags_Plugin::get_option_value('auto_link_case') == 1 ? 'i' : '';
     $strpos_fnc = $case == 'i' ? 'stripos' : 'strpos';
     // Prepare exclude terms array
     $excludes_terms = explode(',', SimpleTags_Plugin::get_option_value('auto_link_exclude'));
     if ($excludes_terms == false) {
         $excludes_terms = array();
     } else {
         $excludes_terms = array_filter($excludes_terms, '_delete_empty_element');
         $excludes_terms = array_unique($excludes_terms);
     }
     $z = 0;
     foreach ((array) self::$link_tags as $term_name => $term_link) {
         // Exclude terms ? next...
         if (in_array($term_name, (array) $excludes_terms)) {
             continue;
         }
         // Make a first test with PHP function, economize CPU with regexp
         if ($strpos_fnc($content, $term_name) === false) {
             continue;
         }
         if ((int) SimpleTags_Plugin::get_option_value('auto_link_dom') == 1 && class_exists('DOMDocument') && class_exists('DOMXPath')) {
             self::_replace_by_links_dom($content, $term_name, $term_link, $case, $rel);
         } else {
             self::_replace_by_links_regexp($content, $term_name, $term_link, $case, $rel);
         }
         $z++;
         if ($z > (int) SimpleTags_Plugin::get_option_value('auto_link_max_by_post')) {
             break;
         }
     }
     return $content;
 }