/** * 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); }
/** * 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; }