| 1 |
<?php |
| 2 |
|
| 3 |
class SimpleTags_Client { |
| 4 |
/** |
| 5 |
* Initialize TaxoPress client |
| 6 |
* |
| 7 |
* @return boolean |
| 8 |
*/ |
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
// Load translation |
| 12 |
add_action( 'init', array( __CLASS__, 'init_translation' ) ); |
| 13 |
|
| 14 |
// Enqueue frontend scripts |
| 15 |
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_displayformat_scripts' ), 999 ); |
| 16 |
|
| 17 |
require( STAGS_DIR . '/inc/class.client.autolinks.php' ); |
| 18 |
new SimpleTags_Client_Autolinks(); |
| 19 |
|
| 20 |
// Call tag clouds ? |
| 21 |
if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_terms_display' ) ) { |
| 22 |
require_once STAGS_DIR . '/inc/tag-clouds-action.php'; |
| 23 |
} |
| 24 |
|
| 25 |
// Call post tags ? |
| 26 |
if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_post_tags' ) ) { |
| 27 |
require_once STAGS_DIR . '/inc/post-tags-action.php'; |
| 28 |
} |
| 29 |
|
| 30 |
// Call related posts ? |
| 31 |
if ( (int) SimpleTags_Plugin::get_option_value( 'active_related_posts_new' ) === 1 ) { |
| 32 |
require_once STAGS_DIR . '/inc/related-posts-action.php'; |
| 33 |
} |
| 34 |
if ( (int) SimpleTags_Plugin::get_option_value( 'active_related_posts_new' ) === 1 ) { |
| 35 |
require( STAGS_DIR . '/inc/class.client.related_posts.php' ); |
| 36 |
new SimpleTags_Client_RelatedPosts(); |
| 37 |
} |
| 38 |
|
| 39 |
// Call auto terms ? |
| 40 |
require( STAGS_DIR . '/inc/class.client.autoterms.php' ); |
| 41 |
new SimpleTags_Client_Autoterms(); |
| 42 |
|
| 43 |
// Call post tags ? |
| 44 |
require( STAGS_DIR . '/inc/class.client.post_tags.php' ); |
| 45 |
new SimpleTags_Client_PostTags(); |
| 46 |
|
| 47 |
|
| 48 |
if ( (int)SimpleTags_Plugin::get_option_value( 'active_taxonomies' ) === 1 ) { |
| 49 |
require_once STAGS_DIR . '/inc/taxonomies-action.php'; |
| 50 |
add_action( 'parse_query', array( __CLASS__, 'cpt_taxonomy_parse_query' ) ); |
| 51 |
if (defined('STAGS_OPTIONS_NAME')) { |
| 52 |
$saved_option = (array)get_option( STAGS_OPTIONS_NAME ); |
| 53 |
if ((array_key_exists('use_tag_pages', $saved_option))) { |
| 54 |
if((int)$saved_option['use_tag_pages'] === 1){ |
| 55 |
if ( !array_key_exists('post_tag', taxopress_get_extername_taxonomy_data()) ) { |
| 56 |
add_action( 'init', array( __CLASS__, 'init' ), 11 ); |
| 57 |
add_action( 'parse_query', array( __CLASS__, 'parse_query' ) ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
function enqueue_displayformat_scripts() { |
| 68 |
|
| 69 |
if ( (int) SimpleTags_Plugin::get_option_value( 'disable_frontend_scripts' ) === 1 ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
if ( ! apply_filters( 'taxopress_load_frontend_scripts', true ) ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
wp_register_script('taxopress-frontend-js', STAGS_URL . '/assets/frontend/js/frontend.js', array('jquery'), STAGS_VERSION); |
| 78 |
wp_register_style('taxopress-frontend-css', STAGS_URL . '/assets/frontend/css/frontend.css', array(), STAGS_VERSION, 'all'); |
| 79 |
|
| 80 |
wp_enqueue_script('taxopress-frontend-js'); |
| 81 |
wp_enqueue_style('taxopress-frontend-css'); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
/** |
| 87 |
* Retrieves the currently queried object. |
| 88 |
* |
| 89 |
* Wrapper for WP_Query::get_queried_object(). |
| 90 |
* |
| 91 |
* @since 3.1.0 |
| 92 |
* |
| 93 |
* @global WP_Query $wp_query WordPress Query object. |
| 94 |
* |
| 95 |
* @return WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object. |
| 96 |
*/ |
| 97 |
public static function taxopress_get_queried_object() { |
| 98 |
global $wp_query; |
| 99 |
|
| 100 |
if (!is_object($wp_query)) { |
| 101 |
return null; |
| 102 |
} |
| 103 |
|
| 104 |
return $wp_query->get_queried_object(); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Add cpt to taxonomy during the query |
| 109 |
* |
| 110 |
* @param WP_Query $query |
| 111 |
* |
| 112 |
* @return void |
| 113 |
* @author Olatechpro |
| 114 |
*/ |
| 115 |
public static function cpt_taxonomy_parse_query( $query ) { |
| 116 |
if(function_exists('get_current_screen')){ |
| 117 |
$screen = get_current_screen(); |
| 118 |
} |
| 119 |
|
| 120 |
if(is_admin()){ |
| 121 |
return $query; |
| 122 |
} |
| 123 |
if(isset($screen->id) && $screen->id == 'edit-post'){ |
| 124 |
return $query; |
| 125 |
} |
| 126 |
if ( $query->is_category == true || $query->is_tag == true || $query->is_tax == true ) { |
| 127 |
$get_queried_object = self::taxopress_get_queried_object(); |
| 128 |
if(is_object($get_queried_object)){ |
| 129 |
if(!isset($get_queried_object->taxonomy)){ |
| 130 |
return $query; |
| 131 |
} |
| 132 |
if(!taxopress_show_all_cpt_in_archive_result($get_queried_object->taxonomy)){ |
| 133 |
return $query; |
| 134 |
} |
| 135 |
$get_taxonomy = get_taxonomy( $get_queried_object->taxonomy ); |
| 136 |
if(is_object($get_taxonomy)){ |
| 137 |
$post_types = $get_taxonomy->object_type; |
| 138 |
if ( isset( $query->query_vars['post_type'] )){ |
| 139 |
if(is_array( $query->query_vars['post_type'] )){ |
| 140 |
$post_types = array_filter(array_merge($query->query_vars['post_type'],$post_types)); |
| 141 |
}elseif(is_string( $query->query_vars['post_type'] )){ |
| 142 |
$original_post_type = $query->query_vars['post_type']; |
| 143 |
$get_post_type_object = get_post_type_object( $original_post_type ); |
| 144 |
if(is_object($get_post_type_object)){ |
| 145 |
if((int)$get_post_type_object->public === 0){ |
| 146 |
return $query; |
| 147 |
} |
| 148 |
} |
| 149 |
$post_types[] = $query->query_vars['post_type']; |
| 150 |
} |
| 151 |
$new_post_object = $post_types; |
| 152 |
}else{ |
| 153 |
$new_post_object = $post_types; |
| 154 |
} |
| 155 |
$query->query_vars['post_type'] = $new_post_object; |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
return $query; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Load translations |
| 164 |
*/ |
| 165 |
public static function init_translation() { |
| 166 |
load_plugin_textdomain( 'simple-tags', false, basename( STAGS_DIR ) . '/languages' ); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Register taxonomy post_tags for page post type |
| 171 |
* |
| 172 |
* @return void |
| 173 |
* @author WebFactory Ltd |
| 174 |
*/ |
| 175 |
public static function init() { |
| 176 |
register_taxonomy_for_object_type( 'post_tag', 'page' ); |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Add page post type during the query |
| 181 |
* |
| 182 |
* @param WP_Query $query |
| 183 |
* |
| 184 |
* @return void |
| 185 |
* @author WebFactory Ltd |
| 186 |
*/ |
| 187 |
public static function parse_query( $query ) { |
| 188 |
if(function_exists('get_current_screen')){ |
| 189 |
$screen = get_current_screen(); |
| 190 |
} |
| 191 |
|
| 192 |
if(isset($screen->id) && $screen->id == 'edit-post'){ |
| 193 |
return $query; |
| 194 |
} |
| 195 |
|
| 196 |
if ( $query->is_tag == true ) { |
| 197 |
if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) { |
| 198 |
$query->query_vars['post_type'][] = 'page'; |
| 199 |
}else{ |
| 200 |
$query->query_vars['post_type'] = array( 'post', 'page' ); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Randomize an array and keep association |
| 207 |
* |
| 208 |
* @param array $array |
| 209 |
* |
| 210 |
* @return boolean |
| 211 |
*/ |
| 212 |
public static function random_array( &$array ) { |
| 213 |
if ( ! is_array( $array ) || empty( $array ) ) { |
| 214 |
return false; |
| 215 |
} |
| 216 |
|
| 217 |
$keys = array_keys( $array ); |
| 218 |
shuffle( $keys ); |
| 219 |
|
| 220 |
$new = array(); |
| 221 |
foreach ( (array) $keys as $key ) { |
| 222 |
$new[ $key ] = $array[ $key ]; |
| 223 |
} |
| 224 |
|
| 225 |
$array = $new; |
| 226 |
|
| 227 |
return true; |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Build rel for tag link |
| 232 |
* |
| 233 |
* @return string |
| 234 |
*/ |
| 235 |
public static function get_rel_attribut() { |
| 236 |
global $wp_rewrite; |
| 237 |
$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'tag' : ''; // Tag ? |
| 238 |
if ( ! empty( $rel ) ) { |
| 239 |
$rel = 'rel="' . $rel . '"'; // Add HTML Tag |
| 240 |
} |
| 241 |
|
| 242 |
return $rel; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Retrieve the post count for a term across all taxonomies. |
| 247 |
* |
| 248 |
* This function queries terms based on the given term name and returns the number of posts associated with the first matching term. |
| 249 |
* It does not require specifying a taxonomy and will search across all public taxonomies. |
| 250 |
* |
| 251 |
* @param string $item |
| 252 |
* @return int The number of posts associated with the first matching term. Returns 0 if no term is found or if it has no posts. |
| 253 |
*/ |
| 254 |
public static function get_term_post_counts( $item ) { |
| 255 |
|
| 256 |
$terms = get_terms( array( |
| 257 |
'name' => strip_tags($item), |
| 258 |
'hide_empty' => false, |
| 259 |
'fields' => 'all', |
| 260 |
'number' => 1, |
| 261 |
) ); |
| 262 |
|
| 263 |
// If terms exist, return the first matching term's count |
| 264 |
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { |
| 265 |
return $terms[0]->count; |
| 266 |
} |
| 267 |
|
| 268 |
return 0; |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* Format data for output |
| 273 |
* |
| 274 |
* @param string $html_class |
| 275 |
* @param string $format |
| 276 |
* @param string $title |
| 277 |
* @param string|array $content |
| 278 |
* @param boolean $copyright |
| 279 |
* @param string $separator |
| 280 |
* |
| 281 |
* @return string|array |
| 282 |
*/ |
| 283 |
public static function output_content( $html_class = '', $format = 'list', $title = '', $content = '', $copyright = true, $separator = '', $div_class = '', $a_class = '', $before = '', $after = '', $taxonomy = '') { |
| 284 |
if ( empty( $content ) ) { |
| 285 |
return ''; // return nothing |
| 286 |
} |
| 287 |
|
| 288 |
if ( $format == 'array' && is_array( $content ) ) { |
| 289 |
return $content; // Return PHP array if format is array |
| 290 |
} |
| 291 |
|
| 292 |
$title = taxopress_sanitize_text_field($title); |
| 293 |
|
| 294 |
if ( is_array( $content ) ) { |
| 295 |
switch ( $format ) { |
| 296 |
case 'list' : |
| 297 |
$output = ''. $before .' <ul class="' . $html_class . '">' . "\n\t" . '<li>' . implode( "</li>\n\t<li>", $content ) . "</li>\n</ul> {$after}\n"; |
| 298 |
break; |
| 299 |
case 'ol' : |
| 300 |
$output = ''. $before .' <ol class="' . $html_class . '">' . "\n\t" . '<li>' . implode( "</li>\n\t<li>", $content ) . "</li>\n</ol> {$after}\n"; |
| 301 |
break; |
| 302 |
case 'comma': |
| 303 |
$output = ''. ''. ''. ''. $before . implode($separator, $content) . " {$after}\n"; |
| 304 |
break; |
| 305 |
case 'table' : |
| 306 |
$output = $before . '<table class="' . $html_class . ' taxopress-table-container">' . "\n\t"; |
| 307 |
$count = 0; |
| 308 |
foreach ($content as $item) { |
| 309 |
|
| 310 |
// If $item is an array, use its fields |
| 311 |
if (is_array($item) && isset($item['html'], $item['count'])) { |
| 312 |
$term_html = $item['html']; |
| 313 |
$post_count = $item['count']; |
| 314 |
} else { |
| 315 |
// fallback for legacy |
| 316 |
$term_html = $item; |
| 317 |
$post_count = self::get_term_post_counts(strip_tags($item)); |
| 318 |
} |
| 319 |
|
| 320 |
// if ( $post_count === 0 ) { |
| 321 |
// continue; |
| 322 |
// } |
| 323 |
|
| 324 |
$display_class = $count >= 6 ? 'hidden' : ''; |
| 325 |
$output .= '<tr class="taxopress-table-row ' . $display_class . '"><td>' . $term_html . '</td><td class="taxopress-post-count">' . $post_count . '</td></tr>' . "\n\t"; |
| 326 |
$count++; |
| 327 |
} |
| 328 |
if ($count > 6) { |
| 329 |
$output .= '<tr><td class="taxopress-see-more-container" colspan="2">'; |
| 330 |
$output .= '<span class="taxopress-see-more-link">see more <span class="taxopress-arrow right"></span></span>'; |
| 331 |
$output .= '<span class="taxopress-close-table-link">close table <span class="taxopress-arrow down"></span></span>'; |
| 332 |
$output .= '</td></tr>' . "\n"; |
| 333 |
} |
| 334 |
$output .= "</table>" . $after . "\n"; |
| 335 |
break; |
| 336 |
case 'border': |
| 337 |
$output = '<div class="taxopress-border-cloud ' . $html_class . '">'. $before .' ' . "\n\t" . implode( "{$separator}\n", $content ) . " {$after}</div>\n"; |
| 338 |
break; |
| 339 |
case 'box': |
| 340 |
$output = '<div class="taxopress-box-list ' . $html_class . '">'. $before .' ' . "\n\t" . implode( "{$separator}\n", $content ) . " {$after}</div>\n"; |
| 341 |
break; |
| 342 |
case 'parent/child': |
| 343 |
$output = $before . '<ul class="' . $html_class . ' taxopress-parent-child-list">' . "\n"; |
| 344 |
|
| 345 |
// Cache term hierarchy to avoid repeated queries |
| 346 |
static $term_hierarchy = []; |
| 347 |
$cache_key = md5($taxonomy . serialize($content)); |
| 348 |
|
| 349 |
if (!isset($term_hierarchy[$cache_key])) { |
| 350 |
$terms_by_parent = []; |
| 351 |
$all_terms = []; |
| 352 |
|
| 353 |
$term_names = array_map(function($term_html) { |
| 354 |
return strip_tags($term_html); |
| 355 |
}, array_filter($content, 'trim')); |
| 356 |
|
| 357 |
if (!empty($term_names)) { |
| 358 |
$terms = get_terms([ |
| 359 |
'taxonomy' => $taxonomy, |
| 360 |
'name' => $term_names, |
| 361 |
'hide_empty' => false, |
| 362 |
'update_term_meta_cache' => false |
| 363 |
]); |
| 364 |
|
| 365 |
if (!is_wp_error($terms)) { |
| 366 |
foreach ($terms as $term) { |
| 367 |
$all_terms[$term->term_id] = [ |
| 368 |
'term' => $term, |
| 369 |
'html' => $content[array_search($term->name, $term_names)], |
| 370 |
'is_parent' => false |
| 371 |
]; |
| 372 |
|
| 373 |
$parent_id = $term->parent ?: '0'; |
| 374 |
$terms_by_parent[$parent_id][] = $term->term_id; |
| 375 |
} |
| 376 |
|
| 377 |
foreach ($terms_by_parent as $child_ids) { |
| 378 |
foreach ($child_ids as $child_id) { |
| 379 |
if (isset($terms_by_parent[$child_id])) { |
| 380 |
$all_terms[$child_id]['is_parent'] = true; |
| 381 |
} |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
$term_hierarchy[$cache_key] = [ |
| 388 |
'terms' => $all_terms, |
| 389 |
'hierarchy' => $terms_by_parent |
| 390 |
]; |
| 391 |
} |
| 392 |
|
| 393 |
// Use cached hierarchy |
| 394 |
$data = $term_hierarchy[$cache_key]; |
| 395 |
$all_terms = $data['terms']; |
| 396 |
$terms_by_parent = $data['hierarchy']; |
| 397 |
|
| 398 |
// Group terms by parent |
| 399 |
$terms_by_parent = []; |
| 400 |
$all_terms = []; |
| 401 |
|
| 402 |
// First pass - collect all terms |
| 403 |
foreach ($content as $term_html) { |
| 404 |
if (empty(trim($term_html))) continue; |
| 405 |
|
| 406 |
$term_name = strip_tags($term_html); |
| 407 |
$term = get_term_by('name', $term_name, $taxonomy); |
| 408 |
|
| 409 |
if (!$term) continue; |
| 410 |
|
| 411 |
// Store term for reference |
| 412 |
$all_terms[$term->term_id] = [ |
| 413 |
'term' => $term, |
| 414 |
'html' => $term_html, |
| 415 |
'is_parent' => false |
| 416 |
]; |
| 417 |
|
| 418 |
$parent_id = $term->parent ?: '0'; |
| 419 |
if (!isset($terms_by_parent[$parent_id])) { |
| 420 |
$terms_by_parent[$parent_id] = []; |
| 421 |
} |
| 422 |
$terms_by_parent[$parent_id][] = $term->term_id; |
| 423 |
} |
| 424 |
|
| 425 |
foreach ($terms_by_parent as $parent_id => $children) { |
| 426 |
foreach ($children as $child_id) { |
| 427 |
if (isset($terms_by_parent[$child_id])) { |
| 428 |
$all_terms[$child_id]['is_parent'] = true; |
| 429 |
} |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
$output_term = function($term_id, $level = 0) use (&$output_term, &$all_terms, &$terms_by_parent) { |
| 434 |
if (!isset($all_terms[$term_id])) return ''; |
| 435 |
|
| 436 |
$term_data = $all_terms[$term_id]; |
| 437 |
$html = str_repeat("\t", $level); |
| 438 |
$html .= '<li class="taxopress-parent-term">' . $term_data['html']; |
| 439 |
|
| 440 |
if (isset($terms_by_parent[$term_id])) { |
| 441 |
$html .= "\n" . str_repeat("\t", $level + 1); |
| 442 |
$html .= '<ul class="taxopress-child-list">' . "\n"; |
| 443 |
foreach ($terms_by_parent[$term_id] as $child_id) { |
| 444 |
$html .= $output_term($child_id, $level + 2); |
| 445 |
} |
| 446 |
$html .= str_repeat("\t", $level + 1) . "</ul>\n"; |
| 447 |
} |
| 448 |
|
| 449 |
$html .= str_repeat("\t", $level) . "</li>\n"; |
| 450 |
return $html; |
| 451 |
}; |
| 452 |
$display_mode = isset($current['display_mode']) ? $current['display_mode'] : 'parents_and_sub'; |
| 453 |
|
| 454 |
if ($display_mode === 'parents_only') { |
| 455 |
foreach ($all_terms as $term_id => $term_data) { |
| 456 |
if ($term_data['is_parent']) { |
| 457 |
$output .= '<li class="taxopress-parent-term">' . $term_data['html'] . "</li>\n"; |
| 458 |
} |
| 459 |
} |
| 460 |
} elseif ($display_mode === 'sub_terms_only') { |
| 461 |
foreach ($all_terms as $term_id => $term_data) { |
| 462 |
if ($term_data['term']->parent > 0) { |
| 463 |
$output .= '<li class="taxopress-child-term">' . $term_data['html'] . "</li>\n"; |
| 464 |
} |
| 465 |
} |
| 466 |
} else { |
| 467 |
// Display full hierarchy |
| 468 |
// Start with root terms or terms whose parents aren't in our set |
| 469 |
foreach ($all_terms as $term_id => $term_data) { |
| 470 |
$term = $term_data['term']; |
| 471 |
if ($term->parent === 0 || !isset($all_terms[$term->parent])) { |
| 472 |
$output .= $output_term($term_id); |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
$output .= "</ul>" . $after . "\n"; |
| 478 |
return $output; |
| 479 |
break; |
| 480 |
default : |
| 481 |
$output = '<div class="' . $html_class . '">'. $before .' ' . "\n\t" . implode( "{$separator}\n", $content ) . " {$after}</div>\n"; |
| 482 |
break; |
| 483 |
} |
| 484 |
} else { |
| 485 |
$content = trim( $content ); |
| 486 |
switch ( $format ) { |
| 487 |
case 'string' : |
| 488 |
$output = $content; |
| 489 |
break; |
| 490 |
case 'list' : |
| 491 |
$output = ''. $before .' <ul class="' . $html_class . '">' . "\n\t" . '<li>' . $content . "</li>\n\t" . "</ul> {$after}\n"; |
| 492 |
break; |
| 493 |
case 'comma': |
| 494 |
$output = ''. ''. ''. ''. $before . $content . " {$after}\n"; |
| 495 |
break; |
| 496 |
case 'table': |
| 497 |
$output = $before . '<table class="' . $html_class . '">' . "\n\t" |
| 498 |
. '<tr><td>' . $content . '</td></tr>' . "\n\t" |
| 499 |
. "</table>" . $after . "\n"; |
| 500 |
break; |
| 501 |
case 'border': |
| 502 |
$output = '<div class="taxopress-border-cloud ' . $html_class . '">'. $before .' ' . "\n\t" . $content . " {$after} </div>\n"; |
| 503 |
break; |
| 504 |
case 'box': |
| 505 |
$output = '<div class="taxopress-box-list ' . $html_class . '">'. $before .' ' . "\n\t" . $content . " {$after} </div>\n"; |
| 506 |
break; |
| 507 |
case 'parent/child': |
| 508 |
$output = $before . '<ul class="' . esc_attr($html_class) . ' taxopress-parent-child-list">' . "\n"; |
| 509 |
$lines = explode("\n", $content); |
| 510 |
$inside_sublist = false; |
| 511 |
|
| 512 |
foreach ($lines as $line) { |
| 513 |
$line = trim($line); |
| 514 |
if (empty($line)) { |
| 515 |
continue; |
| 516 |
} |
| 517 |
|
| 518 |
if (strpos($line, 'taxopress-parent-term') !== false) { |
| 519 |
if ($inside_sublist) { |
| 520 |
$output .= "</ul></li>\n"; |
| 521 |
$inside_sublist = false; |
| 522 |
} |
| 523 |
|
| 524 |
$output .= '<li class="parent-item" style="list-style-type: disc; color: black;">' . $line; |
| 525 |
|
| 526 |
$output .= "\n<ul class=\"child-items\" style=\"list-style-type: circle; color: black;\">\n"; |
| 527 |
$inside_sublist = true; |
| 528 |
} else { |
| 529 |
$output .= '<li class="child-item">' . $line . "</li>\n"; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
// Close any open tags |
| 534 |
if ($inside_sublist) { |
| 535 |
$output .= "</ul></li>\n"; |
| 536 |
} |
| 537 |
|
| 538 |
$output .= "</ul>" . $after . "\n"; |
| 539 |
break; |
| 540 |
default : |
| 541 |
$output = '<div class="' . $html_class . '">'. $before .' ' . "\n\t" . $content . " {$after} </div>\n"; |
| 542 |
break; |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
//wrap class |
| 547 |
if(!empty(trim($div_class))){ |
| 548 |
$wrap_div_class_open = '<div class="'.taxopress_format_class($div_class).'">'; |
| 549 |
$wrap_div_class_close = '</div>'; |
| 550 |
}else{ |
| 551 |
$wrap_div_class_open = '<div class="taxopress-output-wrapper"> '; |
| 552 |
$wrap_div_class_close = '</div>'; |
| 553 |
} |
| 554 |
// Replace false by empty |
| 555 |
$title = trim( $title ); |
| 556 |
if ( strtolower( $title ) == 'false' ) { |
| 557 |
$title = ''; |
| 558 |
} |
| 559 |
|
| 560 |
// Put title if exist |
| 561 |
if ( ! empty( $title ) ) { |
| 562 |
$title .= "\n\t"; |
| 563 |
} |
| 564 |
|
| 565 |
if ( $copyright === true ) { |
| 566 |
return "\n" . '<!-- Generated by TaxoPress ' . STAGS_VERSION . ' - https://wordpress.org/plugins/simple-tags/ -->' . "\n\t" . $wrap_div_class_open . $title . $output . $wrap_div_class_close . "\n"; |
| 567 |
} else { |
| 568 |
return "\n\t" . $wrap_div_class_open . $title . $output . $wrap_div_class_close . "\n"; |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
/** |
| 573 |
* Remplace marker by dynamic values (use for related tags, current tags and tag cloud) |
| 574 |
* |
| 575 |
* @param string $element_loop |
| 576 |
* @param object $term |
| 577 |
* @param string $rel |
| 578 |
* @param integer $scale_result |
| 579 |
* @param integer $scale_max |
| 580 |
* @param integer $scale_min |
| 581 |
* @param integer $largest |
| 582 |
* @param integer $smallest |
| 583 |
* @param string $unit |
| 584 |
* @param string $maxcolor |
| 585 |
* @param string $mincolor |
| 586 |
* |
| 587 |
* @return string |
| 588 |
*/ |
| 589 |
public static function format_internal_tag( $element_loop = '', $term = null, $rel = '', $scale_result = 0, $scale_max = null, $scale_min = 0, $largest = 0, $smallest = 0, $unit = '', $maxcolor = '', $mincolor = '' ) { |
| 590 |
// Need term object |
| 591 |
$tag_link = get_term_link( $term, $term->taxonomy ); |
| 592 |
$element_loop = str_replace( '%tag_link%', esc_url( $tag_link ), $element_loop ); |
| 593 |
$element_loop = str_replace( '%tag_feed%', esc_url( get_term_feed_link( $term->term_id, $term->taxonomy, '' ) ), $element_loop ); |
| 594 |
|
| 595 |
$element_loop = str_replace( '%tag_name%', esc_html( $term->name ), $element_loop ); |
| 596 |
$element_loop = str_replace( '%tag_name_attribute%', esc_html( strip_tags( $term->name ) ), $element_loop ); |
| 597 |
$element_loop = str_replace( '%tag_id%', $term->term_id, $element_loop ); |
| 598 |
$element_loop = str_replace( '%tag_count%', (int) $term->count, $element_loop ); |
| 599 |
$element_loop = str_replace( '%tag_description%', esc_html( $term->description ), $element_loop ); |
| 600 |
|
| 601 |
// Need rel |
| 602 |
$element_loop = str_replace( '%tag_rel%', $rel, $element_loop ); |
| 603 |
|
| 604 |
// Need max/min/scale and other :) |
| 605 |
if ( $scale_result !== null ) { |
| 606 |
$scale_result = (int) $scale_result; |
| 607 |
$scale_min = (int) $scale_min; |
| 608 |
$scale_max = (int) $scale_max; |
| 609 |
$largest = (int) $largest; |
| 610 |
$smallest = (int) $smallest; |
| 611 |
|
| 612 |
$element_loop = str_replace( '%tag_size%', 'font-size:' . self::round( ( $scale_result - $scale_min ) * ( $largest - $smallest ) / ( $scale_max - $scale_min ) + $smallest, 2 ) . $unit . ';', $element_loop ); |
| 613 |
$element_loop = str_replace( '%tag_color%', 'color:' . self::get_color_by_scale( self::round( ( $scale_result - $scale_min ) * ( 100 ) / ( $scale_max - $scale_min ), 2 ), $mincolor, $maxcolor ) . ';', $element_loop ); |
| 614 |
$element_loop = str_replace( '%tag_scale%', $scale_result, $element_loop ); |
| 615 |
} |
| 616 |
|
| 617 |
// External link |
| 618 |
$element_loop = str_replace( '%tag_technorati%', self::format_external_tag( 'technorati', $term->name ), $element_loop ); |
| 619 |
$element_loop = str_replace( '%tag_flickr%', self::format_external_tag( 'flickr', $term->name ), $element_loop ); |
| 620 |
$element_loop = str_replace( '%tag_delicious%', self::format_external_tag( 'delicious', $term->name ), $element_loop ); |
| 621 |
|
| 622 |
return $element_loop; |
| 623 |
} |
| 624 |
|
| 625 |
/** |
| 626 |
* This is pretty filthy. Doing math in hex is much too weird. It's more likely to work, this way! |
| 627 |
* Provided from UTW. Thanks. |
| 628 |
* |
| 629 |
* @param integer $scale_color |
| 630 |
* @param string $min_color |
| 631 |
* @param string $max_color |
| 632 |
* |
| 633 |
* @return string |
| 634 |
*/ |
| 635 |
public static function get_color_by_scale( $scale_color, $min_color, $max_color ) { |
| 636 |
$scale_color = $scale_color / 100; |
| 637 |
|
| 638 |
$minr = hexdec( substr( $min_color, 1, 2 ) ); |
| 639 |
$ming = hexdec( substr( $min_color, 3, 2 ) ); |
| 640 |
$minb = hexdec( substr( $min_color, 5, 2 ) ); |
| 641 |
|
| 642 |
$maxr = hexdec( substr( $max_color, 1, 2 ) ); |
| 643 |
$maxg = hexdec( substr( $max_color, 3, 2 ) ); |
| 644 |
$maxb = hexdec( substr( $max_color, 5, 2 ) ); |
| 645 |
|
| 646 |
$r = dechex( intval( ( ( $maxr - $minr ) * $scale_color ) + $minr ) ); |
| 647 |
$g = dechex( intval( ( ( $maxg - $ming ) * $scale_color ) + $ming ) ); |
| 648 |
$b = dechex( intval( ( ( $maxb - $minb ) * $scale_color ) + $minb ) ); |
| 649 |
|
| 650 |
if ( strlen( $r ) == 1 ) { |
| 651 |
$r = '0' . $r; |
| 652 |
} |
| 653 |
if ( strlen( $g ) == 1 ) { |
| 654 |
$g = '0' . $g; |
| 655 |
} |
| 656 |
if ( strlen( $b ) == 1 ) { |
| 657 |
$b = '0' . $b; |
| 658 |
} |
| 659 |
|
| 660 |
return '#' . $r . $g . $b; |
| 661 |
} |
| 662 |
|
| 663 |
/** |
| 664 |
* Extend the round PHP public static function for force a dot for all locales instead the comma. |
| 665 |
* |
| 666 |
* @param string $value |
| 667 |
* @param string $approximation |
| 668 |
* |
| 669 |
* @return float |
| 670 |
* @author WebFactory Ltd |
| 671 |
*/ |
| 672 |
public static function round( $value, $approximation ) { |
| 673 |
$value = round( $value, $approximation ); |
| 674 |
$value = str_replace( ',', '.', $value ); // Fixes locale comma |
| 675 |
$value = str_replace( ' ', '', $value ); // No space |
| 676 |
|
| 677 |
return $value; |
| 678 |
} |
| 679 |
|
| 680 |
/** |
| 681 |
* Format nice URL depending service |
| 682 |
* |
| 683 |
* @param string $type |
| 684 |
* @param string $term_name |
| 685 |
* |
| 686 |
* @return string |
| 687 |
*/ |
| 688 |
public static function format_external_tag( $type = '', $term_name = '' ) { |
| 689 |
if ( empty( $term_name ) ) { |
| 690 |
return ''; |
| 691 |
} |
| 692 |
|
| 693 |
$term_name = esc_html( $term_name ); |
| 694 |
switch ( $type ) { |
| 695 |
case 'technorati': |
| 696 |
return '<a class="tag_technorati" href="' . esc_url( 'http://technorati.com/tag/' . str_replace( ' ', '+', $term_name ) ) . '" rel="tag">' . $term_name . '</a>'; |
| 697 |
break; |
| 698 |
case 'flickr': |
| 699 |
return '<a class="tag_flickr" href="' . esc_url( 'http://www.flickr.com/photos/tags/' . preg_replace( '/[^a-zA-Z0-9]/', '', strtolower( $term_name ) ) . '/' ) . '" rel="tag">' . $term_name . '</a>'; |
| 700 |
break; |
| 701 |
case 'delicious': |
| 702 |
return '<a class="tag_delicious" href="' . esc_url( 'http://del.icio.us/popular/' . strtolower( str_replace( ' ', '', $term_name ) ) ) . '" rel="tag">' . $term_name . '</a>'; |
| 703 |
break; |
| 704 |
default: |
| 705 |
return ''; |
| 706 |
break; |
| 707 |
} |
| 708 |
} |
| 709 |
} |
| 710 |
|