| [ Root ] [ Search ] [ Index ] |
PHP Cross Reference of bbPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 3 function bb_load_template( $files, $globals = false, $action_arg = null ) 4 { 5 global $bb, $bbdb, $bb_current_user, $page, $bb_cache, 6 $posts, $bb_post, $post_id, $topics, $topic, $topic_id, 7 $forums, $forum, $forum_id, $tags, $tag, $tag_name, $user, $user_id, $view, 8 $del_class, $bb_alt; 9 10 if ( $globals ) { 11 foreach ( $globals as $global => $v ) { 12 if ( !is_numeric($global) ) { 13 $$global = $v; 14 } else { 15 global $$v; 16 } 17 } 18 } 19 20 $files = (array) $files; 21 $template = false; 22 $default_template = false; 23 $file_used = false; 24 $default_file_used = false; 25 26 foreach ( $files as $file ) { 27 do_action( 'bb_' . $file, $action_arg ); 28 if ( false !== $template = bb_get_template( $file, false ) ) { 29 $file_used = $file; 30 break; 31 } 32 if ( !$default_template ) { 33 if ( false !== $default_template = bb_get_default_template( $file ) ) { 34 $default_file_used = $file; 35 } 36 } 37 } 38 39 if ( !$template && $default_template ) { 40 $template = $default_template; 41 $file_used = $default_file_used; 42 } 43 44 $template = apply_filters( 'bb_template', $template, $file_used ); 45 include( $template ); 46 47 do_action( 'bb_after_' . $file_used, $action_arg ); 48 } 49 50 function bb_get_template( $file, $default = true ) 51 { 52 global $bb; 53 // Skip theme loading in "safe" mode 54 if ( !isset( $bb->safemode ) || $bb->safemode !== true ) { 55 if ( file_exists( bb_get_active_theme_directory() . $file ) ) { 56 return bb_get_active_theme_directory() . $file; 57 } 58 } 59 60 if ( !$default ) { 61 return false; 62 } 63 64 return bb_get_default_template( $file ); 65 } 66 67 function bb_get_default_template( $file ) 68 { 69 if ( file_exists( BB_DEFAULT_THEME_DIR . $file ) ) { 70 return BB_DEFAULT_THEME_DIR . $file; 71 } 72 } 73 74 function bb_get_header() 75 { 76 bb_load_template( 'header.php' ); 77 } 78 79 function bb_language_attributes( $xhtml = 0 ) 80 { 81 $output = ''; 82 if ( $dir = bb_get_option( 'text_direction' ) ) { 83 $output = 'dir="' . $dir . '" '; 84 } 85 if ( $lang = bb_get_option( 'language' ) ) { 86 $output .= 'xml:lang="' . $lang . '" '; 87 if ( $xhtml < '1.1' ) { 88 $output .= 'lang="' . $lang . '"'; 89 } 90 } 91 92 echo ' ' . rtrim( $output ); 93 } 94 95 function bb_generator( $type = 'xhtml' ) 96 { 97 if ( !$type ) { 98 $type = 'xhtml'; 99 } 100 echo apply_filters( 'bb_generator', bb_get_generator( $type ) . "\n", $type ); 101 } 102 103 function bb_get_generator( $type = 'xhtml' ) 104 { 105 if ( !$type ) { 106 $type = 'xhtml'; 107 } 108 switch ( $type ) { 109 case 'html': 110 $gen = '<meta name="generator" content="bbPress ' . bb_get_option( 'version' ) . '">'; 111 break; 112 case 'xhtml': 113 $gen = '<meta name="generator" content="bbPress ' . bb_get_option( 'version' ) . '" />'; 114 break; 115 case 'atom': 116 $gen = '<generator uri="http://bbpress.org/" version="' . bb_get_option( 'version' ) . '">bbPress</generator>'; 117 break; 118 case 'rss2': 119 $gen = '<generator>http://bbpress.org/?v=' . bb_get_option( 'version' ) . '</generator>'; 120 break; 121 case 'rdf': 122 $gen = '<admin:generatorAgent rdf:resource="http://bbpress.org/?v=' . bb_get_option( 'version' ) . '" />'; 123 break; 124 case 'comment': 125 $gen = '<!-- generator="bbPress/' . bb_get_option( 'version' ) . '" -->'; 126 break; 127 case 'export': 128 $gen = '<!-- generator="bbPress/' . bb_get_option( 'version' ) . '" created="'. date( 'Y-m-d H:i' ) . '"-->'; 129 break; 130 } 131 return apply_filters( 'bb_get_generator', $gen, $type ); 132 } 133 134 function bb_stylesheet_uri( $stylesheet = '' ) 135 { 136 echo esc_html( bb_get_stylesheet_uri( $stylesheet ) ); 137 } 138 139 function bb_get_stylesheet_uri( $stylesheet = '' ) 140 { 141 if ( 'rtl' == $stylesheet ) { 142 $css_file = 'style-rtl.css'; 143 } else { 144 $css_file = 'style.css'; 145 } 146 147 $active_theme = bb_get_active_theme_directory(); 148 149 if ( file_exists( $active_theme . $css_file ) ) { 150 $r = bb_get_active_theme_uri() . $css_file; 151 } else { 152 $r = BB_DEFAULT_THEME_URL . $css_file; 153 } 154 155 return apply_filters( 'bb_get_stylesheet_uri', $r, $stylesheet ); 156 } 157 158 function bb_active_theme_uri() 159 { 160 echo bb_get_active_theme_uri(); 161 } 162 163 function bb_get_active_theme_uri() 164 { 165 global $bb; 166 // Skip theme loading in "safe" mode 167 if ( isset( $bb->safemode ) && $bb->safemode === true ) { 168 $active_theme_uri = BB_DEFAULT_THEME_URL; 169 } elseif ( !$active_theme = bb_get_option( 'bb_active_theme' ) ) { 170 $active_theme_uri = BB_DEFAULT_THEME_URL; 171 } else { 172 $active_theme_uri = bb_get_theme_uri( $active_theme ); 173 } 174 return apply_filters( 'bb_get_active_theme_uri', $active_theme_uri ); 175 } 176 177 function bb_get_theme_uri( $theme = false ) 178 { 179 global $bb; 180 if ( preg_match( '/^([a-z0-9_-]+)#([a-z0-9_-]+)$/i', $theme, $_matches ) ) { 181 $theme_uri = $bb->theme_locations[$_matches[1]]['url'] . $_matches[2] . '/'; 182 } else { 183 $theme_uri = $bb->theme_locations['core']['url']; 184 } 185 return apply_filters( 'bb_get_theme_uri', $theme_uri, $theme ); 186 } 187 188 function bb_get_footer() 189 { 190 bb_load_template( 'footer.php' ); 191 } 192 193 function bb_head() 194 { 195 do_action('bb_head'); 196 } 197 198 /** 199 * Display the link to the Really Simple Discovery service endpoint. 200 * 201 * @link http://archipelago.phrasewise.com/rsd 202 * @since 1.0 203 */ 204 function bb_rsd_link() { 205 if (bb_get_option('enable_xmlrpc')) 206 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . bb_get_uri('xmlrpc.php', 'rsd', BB_URI_CONTEXT_LINK_OTHER + BB_URI_CONTEXT_BB_XMLRPC) . '" />' . "\n"; 207 } 208 209 /** 210 * Display the link to the pingback service endpoint. 211 * 212 * @since 1.0 213 */ 214 function bb_pingback_link() { 215 if (bb_get_option('enable_pingback')) 216 echo '<link rel="pingback" href="' . bb_get_uri('xmlrpc.php', null, BB_URI_CONTEXT_LINK_OTHER + BB_URI_CONTEXT_BB_XMLRPC) . '" />' . "\n"; 217 } 218 219 function profile_menu() { 220 global $user_id, $profile_menu, $self, $profile_page_title; 221 $list = "<ul id='profile-menu'>"; 222 $list .= "\n\t<li" . ( ( $self ) ? '' : ' class="current"' ) . '><a href="' . esc_attr( get_user_profile_link( $user_id ) ) . '">' . __('Profile') . '</a></li>'; 223 $id = bb_get_current_user_info( 'id' ); 224 foreach ($profile_menu as $item) { 225 // 0 = name, 1 = users cap, 2 = others cap, 3 = file 226 $class = ''; 227 if ( $item[3] == $self ) { 228 $class = ' class="current"'; 229 $profile_page_title = $item[0]; 230 } 231 if ( bb_can_access_tab( $item, $id, $user_id ) ) 232 if ( file_exists($item[3]) || is_callable($item[3]) ) 233 $list .= "\n\t<li$class><a href='" . esc_attr( get_profile_tab_link($user_id, $item[4]) ) . "'>{$item[0]}</a></li>"; 234 } 235 $list .= "\n</ul>"; 236 echo $list; 237 } 238 239 function login_form() { 240 if ( bb_is_user_logged_in() ) 241 bb_load_template( 'logged-in.php' ); 242 else 243 bb_load_template( 'login-form.php', array('user_login', 'remember_checked', 'redirect_to', 're') ); 244 } 245 246 function search_form( $q = '' ) { 247 bb_load_template( 'search-form.php', array('q' => $q) ); 248 } 249 250 function bb_post_template() { 251 bb_load_template( 'post.php' ); 252 } 253 254 function post_form( $args = array() ) { 255 global $page, $topic, $forum; 256 257 $defaults = array( 258 'h2' => '', 259 'last_page_only' => true 260 ); 261 if ( is_string( $args ) ) { 262 $defaults['h2'] = $args; 263 } 264 $args = wp_parse_args( $args, $defaults ); 265 extract( $args, EXTR_SKIP ); 266 267 if ( isset( $forum->forum_is_category ) && $forum->forum_is_category ) { 268 return; 269 } 270 271 $add = topic_pages_add(); 272 if ( empty( $h2 ) && false !== $h2 ) { 273 if ( bb_is_topic() ) { 274 $h2 = __( 'Reply' ); 275 } elseif ( bb_is_forum() ) { 276 $h2 = __( 'New Topic in this Forum' ); 277 } elseif ( bb_is_tag() || bb_is_front() ) { 278 $h2 = __( 'Add New Topic' ); 279 } 280 } 281 282 $last_page = bb_get_page_number( ( isset( $topic->topic_posts ) ? $topic->topic_posts : 0 ) + $add ); 283 284 if ( !empty( $h2 ) ) { 285 if ( bb_is_topic() && ( $page != $last_page && $last_page_only ) ) { 286 $h2 = '<a href="' . esc_attr( get_topic_link( 0, $last_page ) . '#postform' ) . '">' . $h2 . ' »</a>'; 287 } 288 echo '<h2 class="post-form">' . $h2 . '</h2>' . "\n"; 289 } 290 291 do_action( 'pre_post_form' ); 292 293 if ( 294 ( false === bb_is_login_required() ) || 295 ( bb_is_topic() && bb_current_user_can( 'write_post', $topic->topic_id ) && ( $page == $last_page || !$last_page_only ) ) || 296 ( !bb_is_topic() && bb_current_user_can( 'write_topic', isset( $forum->forum_id ) ? $forum->forum_id : 0 ) ) 297 ) { 298 echo '<form class="postform post-form" id="postform" method="post" action="' . bb_get_uri( 'bb-post.php', null, BB_URI_CONTEXT_FORM_ACTION ) . '">' . "\n"; 299 echo '<fieldset>' . "\n"; 300 bb_load_template( 'post-form.php', array('h2' => $h2) ); 301 bb_nonce_field( bb_is_topic() ? 'create-post_' . $topic->topic_id : 'create-topic' ); 302 if ( bb_is_forum() ) { 303 echo '<input type="hidden" name="forum_id" value="' . $forum->forum_id . '" />' . "\n"; 304 } elseif ( bb_is_topic() ) { 305 echo '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "\n"; 306 } 307 do_action( 'post_form' ); 308 echo "\n</fieldset>\n</form>\n"; 309 } elseif ( !bb_is_user_logged_in() ) { 310 echo '<p>'; 311 printf( 312 __('You must <a href="%s">log in</a> to post.'), 313 esc_attr( bb_get_uri( 'bb-login.php', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS ) ) 314 ); 315 echo '</p>'; 316 } 317 318 do_action( 'post_post_form' ); 319 } 320 321 function edit_form() { 322 global $bb_post; 323 do_action('pre_edit_form'); 324 echo '<form class="postform edit-form" method="post" action="' . bb_get_uri('bb-edit.php', null, BB_URI_CONTEXT_FORM_ACTION) . '">' . "\n"; 325 echo '<fieldset>' . "\n"; 326 bb_load_template( 'edit-form.php', array('topic_title') ); 327 bb_nonce_field( 'edit-post_' . $bb_post->post_id ); 328 do_action('edit_form'); 329 if ($_REQUEST['view'] === 'all') 330 echo "\n" . '<input type="hidden" name="view" value="all" />'; 331 echo "\n" . '</fieldset>' . "\n" . '</form>' . "\n"; 332 do_action('post_edit_form'); 333 } 334 335 function bb_anonymous_post_form() { 336 if ( !bb_is_user_logged_in() && !bb_is_login_required() ) 337 bb_load_template( 'post-form-anonymous.php' ); 338 } 339 340 function alt_class( $key, $others = '' ) { 341 echo get_alt_class( $key, $others ); 342 } 343 344 function get_alt_class( $key, $others = '' ) { 345 global $bb_alt; 346 $class = ''; 347 if ( !isset( $bb_alt[$key] ) ) $bb_alt[$key] = -1; 348 ++$bb_alt[$key]; 349 $others = trim($others); 350 if ( $others xor $bb_alt[$key] % 2 ) 351 $class = ' class="' . ( ($others) ? $others : 'alt' ) . '"'; 352 elseif ( $others && $bb_alt[$key] % 2 ) 353 $class = ' class="' . $others . ' alt"'; 354 return $class; 355 } 356 357 function bb_location() { 358 echo apply_filters( 'bb_location', bb_get_location() ); 359 } 360 361 function bb_get_location() { // Not for display. Do not internationalize. 362 static $file; 363 static $filename; 364 365 if ( !isset( $file ) ) { 366 $path = ''; 367 foreach ( array( $_SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'], $_SERVER['PHP_SELF'] ) as $_path ) { 368 if ( false !== strpos( $_path, '.php' ) ) { 369 $path = $_path; 370 break; 371 } 372 } 373 374 $filename = bb_find_filename( $path ); 375 // Make $file relative to bbPress root directory 376 $file = str_replace( bb_get_option( 'path' ), '', $path ); 377 } 378 379 switch ( $filename ) { 380 case 'index.php': 381 case 'page.php': 382 $location = 'front-page'; 383 break; 384 case 'forum.php': 385 $location = 'forum-page'; 386 break; 387 case 'tags.php': 388 $location = 'tag-page'; 389 break; 390 case 'edit.php': 391 $location = 'topic-edit-page'; 392 break; 393 case 'topic.php': 394 $location = 'topic-page'; 395 break; 396 case 'rss.php': 397 $location = 'feed-page'; 398 break; 399 case 'search.php': 400 $location = 'search-page'; 401 break; 402 case 'profile.php': 403 $location = 'profile-page'; 404 break; 405 case 'favorites.php': 406 $location = 'favorites-page'; 407 break; 408 case 'view.php': 409 $location = 'view-page'; 410 break; 411 case 'statistics.php': 412 $location = 'stats-page'; 413 break; 414 case 'bb-login.php': 415 $location = 'login-page'; 416 break; 417 case 'register.php': 418 $location = 'register-page'; 419 break; 420 default: 421 $location = apply_filters( 'bb_get_location', '', $file ); 422 break; 423 } 424 425 return $location; 426 } 427 428 function bb_is_front() { 429 return 'front-page' == bb_get_location(); 430 } 431 432 function bb_is_forum() { 433 return 'forum-page' == bb_get_location(); 434 } 435 436 /** 437 * Whether a user is required to log in in order to create posts and forums. 438 * @return bool Whether a user must be logged in. 439 */ 440 function bb_is_login_required() { 441 return ! (bool) bb_get_option('enable_loginless'); 442 } 443 444 function bb_is_tags() { 445 return 'tag-page' == bb_get_location(); 446 } 447 448 function bb_is_tag() { 449 global $tag, $tag_name; 450 return $tag && $tag_name && bb_is_tags(); 451 } 452 453 function bb_is_topic_edit() { 454 return 'topic-edit-page' == bb_get_location(); 455 } 456 457 function bb_is_topic() { 458 return 'topic-page' == bb_get_location(); 459 } 460 461 function bb_is_feed() { 462 return 'feed-page' == bb_get_location(); 463 } 464 465 function bb_is_search() { 466 return 'search-page' == bb_get_location(); 467 } 468 469 function bb_is_profile() { 470 return 'profile-page' == bb_get_location(); 471 } 472 473 function bb_is_favorites() { 474 return 'favorites-page' == bb_get_location(); 475 } 476 477 function bb_is_view() { 478 return 'view-page' == bb_get_location(); 479 } 480 481 function bb_is_statistics() { 482 return 'stats-page' == bb_get_location(); 483 } 484 485 function bb_is_admin() { 486 if ( defined('BB_IS_ADMIN') ) 487 return BB_IS_ADMIN; 488 return false; 489 } 490 491 function bb_title( $args = '' ) { 492 echo apply_filters( 'bb_title', bb_get_title( $args ), $args ); 493 } 494 495 function bb_get_title( $args = '' ) { 496 $defaults = array( 497 'separator' => ' « ', 498 'order' => 'normal', 499 'front' => '' 500 ); 501 $args = wp_parse_args( $args, $defaults ); 502 $title = array(); 503 504 switch ( bb_get_location() ) { 505 case 'search-page': 506 if ( !$q = trim( @$_GET['search'] ) ) 507 if ( !$q = trim( @$_GET['q'] ) ) 508 break; 509 $title[] = sprintf( __( 'Search for %s' ), esc_html( $q ) ); 510 break; 511 case 'front-page': 512 if ( !empty( $args['front'] ) ) 513 $title[] = $args['front']; 514 break; 515 516 case 'topic-edit-page': 517 case 'topic-page': 518 $title[] = get_topic_title(); 519 break; 520 521 case 'forum-page': 522 $title[] = get_forum_name(); 523 break; 524 525 case 'tag-page': 526 if ( bb_is_tag() ) 527 $title[] = esc_html( bb_get_tag_name() ); 528 529 $title[] = __( 'Tags' ); 530 break; 531 532 case 'profile-page': 533 $title[] = get_user_display_name(); 534 break; 535 536 case 'view-page': 537 $title[] = get_view_name(); 538 break; 539 } 540 541 if ( $st = bb_get_option( 'static_title' ) ) 542 $title = array( $st ); 543 544 $title[] = bb_get_option( 'name' ); 545 546 if ( 'reversed' == $args['order'] ) 547 $title = array_reverse( $title ); 548 549 return apply_filters( 'bb_get_title', implode( $args['separator'], $title ), $args, $title ); 550 } 551 552 function bb_feed_head() { 553 554 $feeds = array(); 555 556 switch (bb_get_location()) { 557 case 'profile-page': 558 if ( $tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2) ) 559 if ($tab != 'favorites') 560 break; 561 562 $feeds[] = array( 563 'title' => sprintf(__('%1$s » User Favorites: %2$s'), bb_get_option( 'name' ), get_user_name()), 564 'href' => get_favorites_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 565 ); 566 break; 567 568 case 'topic-page': 569 $feeds[] = array( 570 'title' => sprintf(__('%1$s » Topic: %2$s'), bb_get_option( 'name' ), get_topic_title()), 571 'href' => get_topic_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 572 ); 573 break; 574 575 case 'tag-page': 576 if (bb_is_tag()) { 577 $feeds[] = array( 578 'title' => sprintf(__('%1$s » Tag: %2$s - Recent Posts'), bb_get_option( 'name' ), bb_get_tag_name()), 579 'href' => bb_get_tag_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 580 ); 581 $feeds[] = array( 582 'title' => sprintf(__('%1$s » Tag: %2$s - Recent Topics'), bb_get_option( 'name' ), bb_get_tag_name()), 583 'href' => bb_get_tag_topics_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 584 ); 585 } 586 break; 587 588 case 'forum-page': 589 $feeds[] = array( 590 'title' => sprintf(__('%1$s » Forum: %2$s - Recent Posts'), bb_get_option( 'name' ), get_forum_name()), 591 'href' => bb_get_forum_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 592 ); 593 $feeds[] = array( 594 'title' => sprintf(__('%1$s » Forum: %2$s - Recent Topics'), bb_get_option( 'name' ), get_forum_name()), 595 'href' => bb_get_forum_topics_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 596 ); 597 break; 598 599 case 'front-page': 600 $feeds[] = array( 601 'title' => sprintf(__('%1$s » Recent Posts'), bb_get_option( 'name' )), 602 'href' => bb_get_posts_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 603 ); 604 $feeds[] = array( 605 'title' => sprintf(__('%1$s » Recent Topics'), bb_get_option( 'name' )), 606 'href' => bb_get_topics_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 607 ); 608 break; 609 610 case 'view-page': 611 global $bb_views, $view; 612 if ($bb_views[$view]['feed']) { 613 $feeds[] = array( 614 'title' => sprintf(__('%1$s » View: %2$s'), bb_get_option( 'name' ), get_view_name()), 615 'href' => bb_get_view_rss_link(null, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED) 616 ); 617 } 618 break; 619 } 620 621 if (count($feeds)) { 622 $feed_links = array(); 623 foreach ($feeds as $feed) { 624 $link = '<link rel="alternate" type="application/rss+xml" '; 625 $link .= 'title="' . esc_attr($feed['title']) . '" '; 626 $link .= 'href="' . esc_attr($feed['href']) . '" />'; 627 $feed_links[] = $link; 628 } 629 $feed_links = join("\n", $feed_links); 630 } else { 631 $feed_links = ''; 632 } 633 634 echo apply_filters('bb_feed_head', $feed_links); 635 } 636 637 function bb_get_posts_rss_link($context = 0) { 638 if (!$context || !is_integer($context)) { 639 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 640 } 641 if ( bb_get_option( 'mod_rewrite' ) ) 642 $link = bb_get_uri('rss/', null, $context); 643 else 644 $link = bb_get_uri('rss.php', null, $context); 645 return apply_filters( 'bb_get_posts_rss_link', $link, $context ); 646 } 647 648 function bb_get_topics_rss_link($context = 0) { 649 if (!$context || !is_integer($context)) { 650 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 651 } 652 if ( bb_get_option( 'mod_rewrite' ) ) 653 $link = bb_get_uri('rss/topics', null, $context); 654 else 655 $link = bb_get_uri('rss.php', array('topics' => 1), $context); 656 return apply_filters( 'bb_get_topics_rss_link', $link, $context ); 657 } 658 659 function bb_view_rss_link($view = null, $context = 0) { 660 echo apply_filters( 'bb_view_rss_link', bb_get_view_rss_link($view, $context), $context); 661 } 662 663 function bb_get_view_rss_link($view = null, $context = 0) { 664 if (!$view) { 665 global $view; 666 } 667 if (!$context || !is_integer($context)) { 668 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 669 } 670 if ( bb_get_option( 'mod_rewrite' ) ) 671 $link = bb_get_uri('rss/view/' . $view, null, $context); 672 else 673 $link = bb_get_uri('rss.php', array('view' => $view), $context); 674 return apply_filters( 'bb_get_view_rss_link', $link, $context ); 675 } 676 677 function bb_latest_topics_pages( $args = null ) 678 { 679 $defaults = array( 'before' => '', 'after' => '' ); 680 $args = wp_parse_args( $args, $defaults ); 681 682 global $page; 683 static $bb_latest_topics_count; 684 if ( !$bb_latest_topics_count) { 685 global $bbdb; 686 $bb_latest_topics_count = $bbdb->get_var('SELECT COUNT(`topic_id`) FROM `' . $bbdb->topics . '` WHERE `topic_status` = 0 AND `topic_sticky` != 2;'); 687 } 688 if ( $pages = apply_filters( 'bb_latest_topics_pages', get_page_number_links( $page, $bb_latest_topics_count ), $bb_latest_topics_count ) ) { 689 echo $args['before'] . $pages . $args['after']; 690 } 691 } 692 693 // FORUMS 694 695 function forum_id( $forum_id = 0 ) { 696 echo apply_filters( 'forum_id', get_forum_id( $forum_id ) ); 697 } 698 699 function get_forum_id( $forum_id = 0 ) { 700 global $forum; 701 $forum_id = (int) $forum_id; 702 if ( $forum_id ) 703 $_forum = bb_get_forum( $forum_id ); 704 else 705 $_forum =& $forum; 706 return $_forum->forum_id; 707 } 708 709 function forum_link( $forum_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 710 if (!$context || !is_integer($context)) { 711 $context = BB_URI_CONTEXT_A_HREF; 712 } 713 echo apply_filters('forum_link', get_forum_link( $forum_id, $page, $context ), $forum_id, $context ); 714 } 715 716 function get_forum_link( $forum_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 717 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 718 719 if (!$context || !is_integer($context)) { 720 $context = BB_URI_CONTEXT_A_HREF; 721 } 722 723 $rewrite = bb_get_option( 'mod_rewrite' ); 724 if ( $rewrite ) { 725 if ( $rewrite === 'slugs' ) { 726 $column = 'forum_slug'; 727 } else { 728 $column = 'forum_id'; 729 } 730 $page = (1 < $page) ? '/page/' . $page : ''; 731 $link = bb_get_uri('forum/' . $forum->$column . $page, null, $context); 732 } else { 733 $query = array( 734 'id' => $forum->forum_id, 735 'page' => (1 < $page) ? $page : false 736 ); 737 $link = bb_get_uri('forum.php', $query, $context); 738 } 739 740 return apply_filters( 'get_forum_link', $link, $forum->forum_id, $context ); 741 } 742 743 function forum_name( $forum_id = 0 ) { 744 echo apply_filters( 'forum_name', get_forum_name( $forum_id ), $forum_id ); 745 } 746 747 function get_forum_name( $forum_id = 0 ) { 748 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 749 return apply_filters( 'get_forum_name', $forum->forum_name, $forum->forum_id ); 750 } 751 752 function forum_description( $args = null ) { 753 if ( is_numeric($args) ) 754 $args = array( 'id' => $args ); 755 elseif ( $args && is_string($args) && false === strpos($args, '=') ) 756 $args = array( 'before' => $args ); 757 $defaults = array( 'id' => 0, 'before' => ' – ', 'after' => '' ); 758 $args = wp_parse_args( $args, $defaults ); 759 760 if ( $desc = apply_filters( 'forum_description', get_forum_description( $args['id'] ), $args['id'], $args ) ) 761 echo $args['before'] . $desc . $args['after']; 762 } 763 764 function get_forum_description( $forum_id = 0 ) { 765 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 766 return apply_filters( 'get_forum_description', $forum->forum_desc, $forum->forum_id ); 767 } 768 769 function get_forum_parent( $forum_id = 0 ) { 770 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 771 return apply_filters( 'get_forum_parent', $forum->forum_parent, $forum->forum_id ); 772 } 773 774 function get_forum_position( $forum_id = 0 ) { 775 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 776 return apply_filters( 'get_forum_position', $forum->forum_order, $forum->forum_id ); 777 } 778 779 function bb_get_forum_is_category( $forum_id = 0 ) { 780 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 781 return apply_filters( 'bb_get_forum_is_category', isset($forum->forum_is_category) ? $forum->forum_is_category : false, $forum->forum_id ); 782 } 783 784 function forum_topics( $forum_id = 0 ) { 785 echo apply_filters( 'forum_topics', get_forum_topics( $forum_id ), $forum_id ); 786 } 787 788 function get_forum_topics( $forum_id = 0 ) { 789 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 790 return apply_filters( 'get_forum_topics', $forum->topics, $forum->forum_id ); 791 } 792 793 function forum_posts( $forum_id = 0 ) { 794 echo apply_filters( 'forum_posts', get_forum_posts( $forum_id ), $forum_id ); 795 } 796 797 function get_forum_posts( $forum_id = 0 ) { 798 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 799 return apply_filters( 'get_forum_posts', $forum->posts, $forum->forum_id ); 800 } 801 802 function forum_pages( $args = null ) 803 { 804 // Compatibility 805 if ( $args && is_numeric( $args ) ) { 806 $args = array( 'id' => $args ); 807 } 808 $defaults = array( 'id' => 0, 'before' => '', 'after' => '' ); 809 $args = wp_parse_args( $args, $defaults ); 810 811 global $page; 812 $forum = bb_get_forum( get_forum_id( $args['id'] ) ); 813 if ( $pages = apply_filters( 'forum_pages', get_page_number_links( $page, $forum->topics ), $forum->topics ) ) { 814 echo $args['before'] . $pages . $args['after']; 815 } 816 } 817 818 function bb_forum_posts_rss_link( $forum_id = 0, $context = 0 ) { 819 if (!$context || !is_integer($context)) { 820 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 821 } 822 echo apply_filters('bb_forum_posts_rss_link', bb_get_forum_posts_rss_link( $forum_id, $context ), $context ); 823 } 824 825 function bb_get_forum_posts_rss_link( $forum_id = 0, $context = 0 ) { 826 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 827 828 if (!$context || !is_integer($context)) { 829 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 830 } 831 832 $rewrite = bb_get_option( 'mod_rewrite' ); 833 if ( $rewrite ) { 834 if ( $rewrite === 'slugs' ) { 835 $column = 'forum_slug'; 836 } else { 837 $column = 'forum_id'; 838 } 839 $link = bb_get_uri('rss/forum/' . $forum->$column, null, $context); 840 } else { 841 $link = bb_get_uri('rss.php', array('forum' => $forum->forum_id), $context); 842 } 843 return apply_filters( 'bb_get_forum_posts_rss_link', $link, $forum->forum_id, $context ); 844 } 845 846 function bb_forum_topics_rss_link( $forum_id = 0, $context = 0 ) { 847 if (!$context || !is_integer($context)) { 848 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 849 } 850 echo apply_filters('bb_forum_topics_rss_link', bb_get_forum_topics_rss_link( $forum_id, $context ), $context ); 851 } 852 853 function bb_get_forum_topics_rss_link( $forum_id = 0, $context = 0 ) { 854 $forum = bb_get_forum( get_forum_id( $forum_id ) ); 855 856 if (!$context || !is_integer($context)) { 857 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 858 } 859 860 $rewrite = bb_get_option( 'mod_rewrite' ); 861 if ( $rewrite ) { 862 if ( $rewrite === 'slugs' ) { 863 $column = 'forum_slug'; 864 } else { 865 $column = 'forum_id'; 866 } 867 $link = bb_get_uri('rss/forum/' . $forum->$column . '/topics', null, $context); 868 } else { 869 $link = bb_get_uri('rss.php', array('forum' => $forum->forum_id, 'topics' => 1), $context); 870 } 871 return apply_filters( 'bb_get_forum_topics_rss_link', $link, $forum->forum_id, $context ); 872 } 873 874 function bb_get_forum_bread_crumb($args = '') { 875 $defaults = array( 876 'forum_id' => 0, 877 'separator' => ' » ', 878 'class' => null 879 ); 880 $args = wp_parse_args($args, $defaults); 881 extract($args, EXTR_SKIP); 882 883 $trail = ''; 884 $trail_forum = bb_get_forum(get_forum_id($forum_id)); 885 if ($class) { 886 $class = ' class="' . $class . '"'; 887 } 888 $current_trail_forum_id = $trail_forum->forum_id; 889 while ( $trail_forum && $trail_forum->forum_id > 0 ) { 890 $crumb = $separator; 891 if ($current_trail_forum_id != $trail_forum->forum_id || !bb_is_forum()) { 892 $crumb .= '<a' . $class . ' href="' . get_forum_link($trail_forum->forum_id) . '">'; 893 } elseif ($class) { 894 $crumb .= '<span' . $class . '>'; 895 } 896 $crumb .= get_forum_name($trail_forum->forum_id); 897 if ($current_trail_forum_id != $trail_forum->forum_id || !bb_is_forum()) { 898 $crumb .= '</a>'; 899 } elseif ($class) { 900 $crumb .= '</span>'; 901 } 902 $trail = $crumb . $trail; 903 $trail_forum = bb_get_forum($trail_forum->forum_parent); 904 } 905 906 return apply_filters('bb_get_forum_bread_crumb', $trail, $forum_id ); 907 } 908 909 function bb_forum_bread_crumb( $args = '' ) { 910 echo apply_filters('bb_forum_bread_crumb', bb_get_forum_bread_crumb( $args ) ); 911 } 912 913 // Forum Loop // 914 915 function &bb_forums( $args = '' ) { 916 global $bb_forums_loop; 917 918 $default_type = 'flat'; 919 920 if ( is_numeric($args) ) { 921 $args = array( 'child_of' => $args ); 922 } elseif ( func_num_args() > 1 ) { // bb_forums( 'ul', $args ); Deprecated 923 $default_type = $args; 924 $args = func_get_arg(1); 925 } elseif ( $args && is_string($args) && false === strpos($args, '=') ) { 926 $args = array( 'type' => $args ); 927 } 928 929 // hierarchical not used here. Sent to bb_get_forums for proper ordering. 930 $args = wp_parse_args( $args, array('hierarchical' => true, 'type' => $default_type, 'walker' => 'BB_Walker_Blank') ); 931 932 $levels = array( '', '' ); 933 934 if ( in_array($args['type'], array('list', 'ul')) ) 935 $levels = array( '<ul>', '</ul>' ); 936 937 $forums = bb_get_forums( $args ); 938 939 if ( !class_exists($args['walker']) ) 940 $args['walker'] = 'BB_Walker_Blank'; 941 942 if ( $bb_forums_loop = BB_Loop::start( $forums, $args['walker'] ) ) { 943 $bb_forums_loop->preserve( array('forum', 'forum_id') ); 944 $bb_forums_loop->walker->db_fields = array( 'id' => 'forum_id', 'parent' => 'forum_parent' ); 945 list($bb_forums_loop->walker->start_lvl, $bb_forums_loop->walker->end_lvl) = $levels; 946 return $bb_forums_loop->elements; 947 } 948 $false = false; 949 return $false; 950 } 951 952 function bb_forum() { // Returns current depth 953 global $bb_forums_loop; 954 if ( !is_object($bb_forums_loop) || !is_a($bb_forums_loop, 'BB_Loop') ) 955 return false; 956 if ( !is_array($bb_forums_loop->elements) ) 957 return false; 958 959 if ( $bb_forums_loop->step() ) { 960 $GLOBALS['forum'] =& $bb_forums_loop->elements[key($bb_forums_loop->elements)]; // Globalize the current forum object 961 } else { 962 $bb_forums_loop->reinstate(); 963 return $bb_forums_loop = null; // All done? Kill the object and exit the loop. 964 } 965 966 return $bb_forums_loop->walker->depth; 967 } 968 969 function bb_forum_pad( $pad, $offset = 0 ) { 970 global $bb_forums_loop; 971 if ( !is_object($bb_forums_loop) || !is_a($bb_forums_loop, 'BB_Loop') ) 972 return false; 973 974 echo $bb_forums_loop->pad( $pad, $offset ); 975 } 976 977 function bb_forum_class( $args = null ) { 978 echo apply_filters( 'bb_forum_class', get_alt_class( 'forum', bb_get_forum_class_names( $args ) ), $args ); 979 } 980 981 function bb_get_forum_class_names( $args = null ) { 982 if ( is_numeric( $args ) ) { // Not used 983 $args = array( 'id' => $args ); 984 } elseif ( $args && is_string( $args ) && false === strpos( $args, '=' ) ) { 985 $args = array( 'class' => $args ); 986 } 987 $defaults = array( 'id' => 0, 'key' => 'forum', 'class' => '', 'output' => 'string' ); 988 $args = wp_parse_args( $args, $defaults ); 989 990 $classes = array(); 991 if ( $args['class'] ) { 992 $classes[] = $args['class']; 993 } 994 995 global $bb_forums_loop; 996 if ( is_object( $bb_forums_loop ) && is_a( $bb_forums_loop, 'BB_Loop' ) ) { 997 $classes = array_merge( $classes, $bb_forums_loop->classes( 'array' ) ); 998 } 999 1000 if ( $args['output'] === 'string' ) { 1001 $classes = join( ' ', $classes ); 1002 } 1003 1004 return apply_filters( 'bb_get_forum_class', $classes, $args ); 1005 } 1006 1007 // TOPICS 1008 function topic_id( $id = 0 ) { 1009 echo apply_filters( 'topic_id', get_topic_id( $id ) ); 1010 } 1011 1012 function get_topic_id( $id = 0 ) { 1013 global $topic; 1014 $id = (int) $id; 1015 if ( $id ) 1016 $_topic = get_topic( $id ); 1017 else 1018 $_topic =& $topic; 1019 1020 if ( empty($_topic->topic_id) ) 1021 return 0; 1022 1023 return (int) $_topic->topic_id; 1024 } 1025 1026 function topic_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 1027 echo apply_filters( 'topic_link', get_topic_link( $id, $page, $context ), $id, $page, $context ); 1028 } 1029 1030 function get_topic_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 1031 $topic = get_topic( get_topic_id( $id ) ); 1032 1033 if (!$context || !is_integer($context)) { 1034 $context = BB_URI_CONTEXT_A_HREF; 1035 } 1036 1037 $args = array(); 1038 1039 $rewrite = bb_get_option( 'mod_rewrite' ); 1040 if ( $rewrite ) { 1041 if ( $rewrite === 'slugs' ) { 1042 $column = 'topic_slug'; 1043 } else { 1044 $column = 'topic_id'; 1045 } 1046 $page = (1 < $page) ? '/page/' . $page : ''; 1047 $link = bb_get_uri('topic/' . $topic->$column . $page, null, $context); 1048 } else { 1049 $page = (1 < $page) ? $page : false; 1050 $link = bb_get_uri('topic.php', array('id' => $topic->topic_id, 'page' => $page), $context); 1051 } 1052 1053 return apply_filters( 'get_topic_link', $link, $topic->topic_id, $context ); 1054 } 1055 1056 function topic_rss_link( $id = 0, $context = 0 ) { 1057 if (!$context || !is_integer($context)) { 1058 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 1059 } 1060 echo apply_filters('topic_rss_link', get_topic_rss_link($id, $context), $id, $context ); 1061 } 1062 1063 function get_topic_rss_link( $id = 0, $context = 0 ) { 1064 $topic = get_topic( get_topic_id( $id ) ); 1065 1066 if (!$context || !is_integer($context)) { 1067 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 1068 } 1069 1070 $rewrite = bb_get_option( 'mod_rewrite' ); 1071 if ( $rewrite ) { 1072 if ( $rewrite === 'slugs' ) { 1073 $column = 'topic_slug'; 1074 } else { 1075 $column = 'topic_id'; 1076 } 1077 $link = bb_get_uri('rss/topic/' . $topic->$column, null, $context); 1078 } else { 1079 $link = bb_get_uri('rss.php', array('topic' => $topic->topic_id), $context); 1080 } 1081 return apply_filters( 'get_topic_rss_link', $link, $topic->topic_id, $context ); 1082 } 1083 1084 function bb_topic_labels() { 1085 echo apply_filters( 'bb_topic_labels', null ); 1086 } 1087 1088 function topic_title( $id = 0 ) { 1089 echo apply_filters( 'topic_title', get_topic_title( $id ), get_topic_id( $id ) ); 1090 } 1091 1092 function get_topic_title( $id = 0 ) { 1093 $topic = get_topic( get_topic_id( $id ) ); 1094 return apply_filters( 'get_topic_title', $topic->topic_title, $topic->topic_id ); 1095 } 1096 1097 function topic_page_links( $id = 0, $args = null ) { 1098 echo apply_filters( 'topic_page_links', get_topic_page_links( $id, $args ), get_topic_id( $id ) ); 1099 } 1100 1101 function get_topic_page_links( $id = 0, $args = null ) { 1102 1103 $defaults = array( 1104 'show_all' => false, 1105 'end_size' => 3, 1106 'before' => ' - ', 1107 'after' => null 1108 ); 1109 1110 $args = wp_parse_args( $args, $defaults ); 1111 1112 $topic = get_topic( get_topic_id( $id ) ); 1113 1114 $uri = get_topic_link(); 1115 if ( bb_get_option('mod_rewrite') ) { 1116 if ( false === $pos = strpos( $uri, '?' ) ) { 1117 $uri = $uri . '%_%'; 1118 } else { 1119 $uri = substr_replace( $uri, '%_%', $pos, 0 ); 1120 } 1121 } else { 1122 $uri = add_query_arg( 'page', '%_%', $uri ); 1123 } 1124 1125 $posts = $topic->topic_posts + topic_pages_add( $topic->topic_id ); 1126 1127 $per_page = apply_filters( 'get_topic_page_links_per_page', bb_get_option('page_topics') ); 1128 1129 $_links = bb_paginate_links( 1130 array( 1131 'base' => $uri, 1132 'format' => bb_get_option('mod_rewrite') ? '/page/%#%' : '%#%', 1133 'total' => ceil($posts/$per_page), 1134 'current' => 0, 1135 'show_all' => $args['show_all'], 1136 'end_size' => $args['end_size'], 1137 'type' => 'array' 1138 ) 1139 ); 1140 1141 $links = $_links; 1142 1143 $r = ''; 1144 1145 if ( $links ) { 1146 if ( !$show_first ) { 1147 unset( $links[0] ); 1148 } 1149 1150 if ( $args['before'] ) { 1151 $r .= $args['before']; 1152 } 1153 $r .= join('', $links); 1154 if ( $args['after'] ) { 1155 $r .= $args['after']; 1156 } 1157 } 1158 1159 return apply_filters( 'get_topic_page_links', $r, $_links, $topic->topic_id ); 1160 } 1161 1162 function bb_topic_voices( $id = 0 ) { 1163 echo apply_filters( 'bb_topic_voices', bb_get_topic_voices( $id ), get_topic_id( $id ) ); 1164 } 1165 1166 function bb_get_topic_voices( $id = 0 ) { 1167 $topic = get_topic( get_topic_id( $id ) ); 1168 1169 if ( empty( $topic->voices_count ) ) { 1170 global $bbdb; 1171 1172 if ( $voices = $bbdb->get_col( $bbdb->prepare( "SELECT DISTINCT poster_id FROM $bbdb->posts WHERE topic_id = %s AND post_status = '0';", $topic->topic_id ) ) ) { 1173 $voices = count( $voices ); 1174 bb_update_topicmeta( $topic->topic_id, 'voices_count', $voices ); 1175 } 1176 } else { 1177 $voices = $topic->voices_count; 1178 } 1179 1180 return apply_filters( 'bb_get_topic_voices', $voices, $topic->topic_id ); 1181 } 1182 1183 function topic_posts( $id = 0 ) { 1184 echo apply_filters( 'topic_posts', get_topic_posts( $id ), get_topic_id( $id ) ); 1185 } 1186 1187 function get_topic_posts( $id = 0 ) { 1188 $topic = get_topic( get_topic_id( $id ) ); 1189 return apply_filters( 'get_topic_posts', $topic->topic_posts, $topic->topic_id ); 1190 } 1191 1192 function get_topic_deleted_posts( $id = 0 ) { 1193 $topic = get_topic( get_topic_id( $id ) ); 1194 return apply_filters( 'get_topic_deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts : 0, $topic->topic_id ); 1195 } 1196 1197 function topic_noreply( $title ) { 1198 if ( 1 == get_topic_posts() && ( bb_is_front() || bb_is_forum() ) ) 1199 $title = "<strong>$title</strong>"; 1200 return $title; 1201 } 1202 1203 function topic_last_poster( $id = 0 ) { 1204 $topic = get_topic( get_topic_id( $id ) ); 1205 echo apply_filters( 'topic_last_poster', get_topic_last_poster( $id ), $topic->topic_last_poster, $topic->topic_id ); // $topic->topic_last_poster = user ID 1206 } 1207 1208 function get_topic_last_poster( $id = 0 ) { 1209 $topic = get_topic( get_topic_id( $id ) ); 1210 $user_display_name = get_post_author( $topic->topic_last_post_id ); 1211 return apply_filters( 'get_topic_last_poster', $user_display_name, $topic->topic_last_poster, $topic->topic_id ); // $topic->topic_last_poster = user ID 1212 } 1213 1214 function topic_author( $id = 0 ) { 1215 $topic = get_topic( get_topic_id( $id ) ); 1216 echo apply_filters( 'topic_author', get_topic_author( $id ), $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID 1217 } 1218 1219 function get_topic_author( $id = 0 ) { 1220 $topic = get_topic( get_topic_id( $id ) ); 1221 $first_post = bb_get_first_post( $topic ); 1222 $user_display_name = get_post_author( $first_post->post_id ); 1223 return apply_filters( 'get_topic_author', $user_display_name, $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID 1224 } 1225 1226 // Filters expect the format to by mysql on both topic_time and get_topic_time 1227 function topic_time( $args = '' ) { 1228 $args = _bb_parse_time_function_args( $args ); 1229 $time = apply_filters( 'topic_time', get_topic_time( array('format' => 'mysql') + $args), $args ); 1230 echo _bb_time_function_return( $time, $args ); 1231 } 1232 1233 function get_topic_time( $args = '' ) { 1234 $args = _bb_parse_time_function_args( $args ); 1235 1236 $topic = get_topic( get_topic_id( $args['id'] ) ); 1237 1238 $time = apply_filters( 'get_topic_time', $topic->topic_time, $args ); 1239 1240 return _bb_time_function_return( $time, $args ); 1241 } 1242 1243 function topic_start_time( $args = '' ) { 1244 $args = _bb_parse_time_function_args( $args ); 1245 $time = apply_filters( 'topic_start_time', get_topic_start_time( array('format' => 'mysql') + $args), $args ); 1246 echo _bb_time_function_return( $time, $args ); 1247 } 1248 1249 function get_topic_start_time( $args = '' ) { 1250 $args = _bb_parse_time_function_args( $args ); 1251 1252 $topic = get_topic( get_topic_id( $args['id'] ) ); 1253 1254 $time = apply_filters( 'get_topic_start_time', $topic->topic_start_time, $args, $topic->topic_id ); 1255 1256 return _bb_time_function_return( $time, $args ); 1257 } 1258 1259 function topic_last_post_link( $id = 0 ) { 1260 echo apply_filters( 'topic_last_post_link', get_topic_last_post_link( $id ), $id); 1261 } 1262 1263 function get_topic_last_post_link( $id = 0 ){ 1264 $topic = get_topic( get_topic_id( $id ) ); 1265 $page = bb_get_page_number( $topic->topic_posts ); 1266 return apply_filters( 'get_post_link', get_topic_link( $topic->topic_id, $page ) . "#post-$topic->topic_last_post_id", $topic->topic_last_post_id, $topic->topic_id ); 1267 } 1268 1269 function topic_pages( $args = null ) 1270 { 1271 // Compatibility 1272 if ( $args && is_numeric( $args ) ) { 1273 $args = array( 'id' => $args ); 1274 } 1275 $defaults = array( 'id' => 0, 'before' => '', 'after' => '' ); 1276 $args = wp_parse_args( $args, $defaults ); 1277 1278 global $page; 1279 $topic = get_topic( get_topic_id( $args['id'] ) ); 1280 $add = topic_pages_add( $topic->topic_id ); 1281 if ( $pages = apply_filters( 'topic_pages', get_page_number_links( $page, $topic->topic_posts + $add ), $topic->topic_id ) ) { 1282 echo $args['before'] . $pages . $args['after']; 1283 } 1284 } 1285 1286 function topic_pages_add( $id = 0 ) { 1287 $topic = get_topic( get_topic_id( $id ) ); 1288 if ( isset($_GET['view']) && 'all' == $_GET['view'] && bb_current_user_can('browse_deleted') && isset( $topic->deleted_posts ) ) 1289 $add = $topic->deleted_posts; 1290 else 1291 $add = 0; 1292 return apply_filters( 'topic_pages_add', $add, isset($topic->topic_id) ? $topic->topic_id : 0 ); 1293 } 1294 1295 function get_page_number_links( $args ) { 1296 if ( 1 < func_num_args() ) { 1297 $_args = func_get_args(); 1298 $args = array( 1299 'page' => $_args[0], 1300 'total' => $_args[1], 1301 'per_page' => isset( $_args[2] ) ? $_args[2] : '', 1302 'mod_rewrite' => isset( $_args[3] ) ? $_args[3] : 'use_option' 1303 ); 1304 } 1305 $defaults = array( 1306 'page' => 1, 1307 'total' => false, 1308 'per_page' => '', 1309 'mod_rewrite' => 'use_option', 1310 'prev_text' => __( '« Previous' ), 1311 'next_text' => __( 'Next »' ) 1312 ); 1313 $args = wp_parse_args( $args, $defaults ); 1314 extract( $args, EXTR_SKIP ); 1315 1316 $add_args = array(); 1317 $uri = rtrim( $_SERVER['REQUEST_URI'], '?&' ); 1318 1319 if ( $mod_rewrite === 'use_option' ) { 1320 $mod_rewrite = bb_get_option( 'mod_rewrite' ); 1321 } 1322 1323 if ( $mod_rewrite ) { 1324 $format = '/page/%#%'; 1325 if ( 1 == $page ) { 1326 if ( false === $pos = strpos($uri, '?') ) 1327 $uri = $uri . '%_%'; 1328 else 1329 $uri = substr_replace($uri, '%_%', $pos, 0); 1330 } else { 1331 $uri = preg_replace('|/page/[0-9]+|', '%_%', $uri); 1332 } 1333 $uri = str_replace( '/%_%', '%_%', $uri ); 1334 } else { 1335 if ( 1 == $page ) { 1336 if ( false === $pos = strpos($uri, '?') ) { 1337 $uri = $uri . '%_%'; 1338 $format = '?page=%#%'; 1339 } else { 1340 $uri = substr_replace($uri, '?%_%', $pos, 1); 1341 $format = 'page=%#%&'; 1342 } 1343 } else { 1344 if ( false === strpos($uri, '?page=') ) { 1345 $uri = preg_replace('!&page=[0-9]+!', '%_%', $uri ); 1346 $uri = str_replace( '&page=', '', $uri ); 1347 $format = '&page=%#%'; 1348 } else { 1349 $uri = preg_replace('!\?page=[0-9]+!', '%_%', $uri ); 1350 $uri = str_replace( '?page=', '', $uri ); 1351 $format = '?page=%#%'; 1352 } 1353 } 1354 } 1355 1356 if ( isset($_GET['view']) && in_array($_GET['view'], bb_get_views()) ) 1357 $add_args['view'] = $_GET['view']; 1358 1359 if ( empty( $per_page ) ) { 1360 $per_page = bb_get_option( 'page_topics' ); 1361 } 1362 1363 $links = bb_paginate_links( array( 1364 'base' => $uri, 1365 'format' => $format, 1366 'total' => ceil( $total/$per_page ), 1367 'current' => $page, 1368 'add_args' => $add_args, 1369 'type' => 'array', 1370 'mid_size' => 1, 1371 'prev_text' => $prev_text, 1372 'next_text' => $next_text 1373 ) ); 1374 1375 if ($links) { 1376 $links = join('', $links); 1377 } 1378 return $links; 1379 } 1380 1381 function bb_topic_admin( $args = '' ) { 1382 $parts = array( 1383 'delete' => bb_get_topic_delete_link( $args ), 1384 'close' => bb_get_topic_close_link( $args ), 1385 'sticky' => bb_get_topic_sticky_link( $args ), 1386 'move' => bb_get_topic_move_dropdown( $args ) 1387 ); 1388 1389 echo join( "\n", apply_filters( 'bb_topic_admin', $parts, $args ) ); 1390 } 1391 1392 function topic_delete_link( $args = '' ) { 1393 echo bb_get_topic_delete_link( $args ); 1394 } 1395 1396 function bb_get_topic_delete_link( $args = '' ) { 1397 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'delete_text' => false, 'undelete_text' => false, 'redirect' => true ); 1398 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1399 $id = (int) $id; 1400 1401 $topic = get_topic( get_topic_id( $id ) ); 1402 1403 if ( !$topic || !bb_current_user_can( 'delete_topic', $topic->topic_id ) ) 1404 return; 1405 1406 if ( 0 == $topic->topic_status ) { 1407 if ( true === $redirect ) 1408 $redirect = add_query_arg( bb_is_admin() ? array() : array( 'view' => 'all' ) ); 1409 1410 $query = array( 'id' => $topic->topic_id, '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false ); 1411 $confirm = __('Are you sure you want to delete that?'); 1412 $display = esc_html( $delete_text ? $delete_text : __('Delete entire topic') ); 1413 } else { 1414 if ( true === $redirect ) 1415 $redirect = remove_query_arg( bb_is_admin() ? array() : 'view' ); 1416 1417 $query = array('id' => $topic->topic_id, 'view' => 'all', '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false ); 1418 $confirm = __('Are you sure you want to undelete that?'); 1419 $display = esc_html( $undelete_text ? $undelete_text : __('Undelete entire topic') ); 1420 } 1421 $uri = bb_get_uri('bb-admin/delete-topic.php', $query, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 1422 $uri = esc_url( bb_nonce_url( $uri, 'delete-topic_' . $topic->topic_id ) ); 1423 1424 return $before . '<a href="' . $uri . '" onclick="return confirm(\'' . esc_js( $confirm ) . '\');">' . $display . '</a>' . $after; 1425 } 1426 1427 function topic_close_link( $args = '' ) { 1428 echo bb_get_topic_close_link( $args ); 1429 } 1430 1431 function bb_get_topic_close_link( $args = '' ) { 1432 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'close_text' => false, 'open_text' => false, 'redirect' => true ); 1433 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1434 $id = (int) $id; 1435 1436 $topic = get_topic( get_topic_id( $id ) ); 1437 1438 if ( !$topic || !bb_current_user_can( 'close_topic', $topic->topic_id ) ) 1439 return; 1440 1441 if ( topic_is_open( $topic->topic_id ) ) 1442 $display = esc_html( $close_text ? $close_text : __( 'Close topic' ) ); 1443 else 1444 $display = esc_html( $open_text ? $open_text : __( 'Open topic' ) ); 1445 1446 if ( true === $redirect ) 1447 $redirect = $_SERVER['REQUEST_URI']; 1448 1449 $uri = bb_get_uri('bb-admin/topic-toggle.php', array( 'id' => $topic->topic_id, '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 1450 $uri = esc_url( bb_nonce_url( $uri, 'close-topic_' . $topic->topic_id ) ); 1451 1452 return $before . '<a href="' . $uri . '">' . $display . '</a>' . $after; 1453 } 1454 1455 function topic_sticky_link( $args = '' ) { 1456 echo bb_get_topic_sticky_link( $args ); 1457 } 1458 1459 function bb_get_topic_sticky_link( $args = '' ) { 1460 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' ); 1461 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1462 $id = (int) $id; 1463 1464 $topic = get_topic( get_topic_id( $id ) ); 1465 1466 if ( !$topic || !bb_current_user_can( 'stick_topic', $topic->topic_id ) ) 1467 return; 1468 1469 $uri_stick = bb_get_uri('bb-admin/sticky.php', array('id' => $topic->topic_id), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 1470 $uri_stick = esc_url( bb_nonce_url( $uri_stick, 'stick-topic_' . $topic->topic_id ) ); 1471 1472 $uri_super = bb_get_uri('bb-admin/sticky.php', array('id' => $topic->topic_id, 'super' => 1), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 1473 $uri_super = esc_url( bb_nonce_url( $uri_super, 'stick-topic_' . $topic->topic_id ) ); 1474 1475 if ( topic_is_sticky( $topic->topic_id ) ) 1476 return "$before<a href='" . $uri_stick . "'>". __('Unstick topic') ."</a>$after"; 1477 else 1478 return "$before<a href='" . $uri_stick . "'>". __('Stick topic') . "</a> (<a href='" . $uri_super . "'>" . __('to front') . "</a>)$after"; 1479 } 1480 1481 function topic_show_all_link( $id = 0 ) { 1482 if ( !bb_current_user_can( 'browse_deleted' ) ) 1483 return; 1484 if ( 'all' == @$_GET['view'] ) 1485 echo "<a href='" . esc_attr( get_topic_link( $id ) ) . "'>". __('View normal posts') ."</a>"; 1486 else 1487 echo "<a href='" . esc_attr( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>". __('View all posts') ."</a>"; 1488 } 1489 1490 function topic_posts_link( $id = 0 ) { 1491 echo get_topic_posts_link( $id ); 1492 } 1493 1494 function get_topic_posts_link( $id = 0 ) { 1495 $topic = get_topic( get_topic_id( $id ) ); 1496 $post_num = get_topic_posts( $id ); 1497 $posts = sprintf(__ngettext( '%s post', '%s posts', $post_num ), $post_num); 1498 $r = ''; 1499 1500 if ( ( 'all' == @$_GET['view'] || bb_is_admin() ) && bb_current_user_can('browse_deleted') ) 1501 $r .= "<a href='" . esc_attr( get_topic_link( $id ) ) . "'>$posts</a>"; 1502 else 1503 $r .= $posts; 1504 1505 if ( bb_current_user_can( 'browse_deleted' ) ) { 1506 $user_id = bb_get_current_user_info( 'id' ); 1507 if ( isset($topic->bozos[$user_id]) && 'all' != @$_GET['view'] ) 1508 add_filter('get_topic_deleted_posts', create_function('$a', "\$a -= {$topic->bozos[$user_id]}; return \$a;") ); 1509 if ( $deleted = get_topic_deleted_posts( $id ) ) { 1510 $extra = sprintf(__('+%d more'), $deleted); 1511 if ( 'all' == @$_GET['view'] ) 1512 $r .= " $extra"; 1513 else 1514 $r .= " <a href='" . esc_attr( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>$extra</a>"; 1515 } 1516 } 1517 1518 return $r; 1519 } 1520 1521 function topic_move_dropdown( $args = '' ) 1522 { 1523 echo bb_get_topic_move_dropdown( $args ); 1524 } 1525 1526 function bb_get_topic_move_dropdown( $args = '' ) 1527 { 1528 if ( $args && is_numeric( $args ) ) { 1529 $args = array( 'id' => (integer) $args ); 1530 } 1531 1532 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' ); 1533 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1534 $id = (int) $id; 1535 1536 $topic = get_topic( get_topic_id( $id ) ); 1537 if ( !bb_current_user_can( 'move_topic', $topic->topic_id ) ) 1538 return; 1539 1540 $dropdown = bb_get_forum_dropdown( array( 1541 'callback' => 'bb_current_user_can', 1542 'callback_args' => array('move_topic', $topic->topic_id), 1543 'selected' => $topic->forum_id, 1544 'tab' => false 1545 ) ); 1546 1547 if ( !$dropdown ) 1548 return; 1549 1550 $r = $before . '<form id="topic-move" method="post" action="' . bb_get_uri( 'bb-admin/topic-move.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ) . '"><fieldset><div>' . "\n"; 1551 $r .= '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "\n"; 1552 $r .= '<label for="forum-id">'. __( 'Move to' ) . '</label>' . "\n"; 1553 $r .= $dropdown . "\n"; 1554 $r .= bb_nonce_field( 'move-topic_' . $topic->topic_id, '_wpnonce', true , false ); 1555 $r .= '<input type="submit" name="Submit" value="' . __( 'Move' ) . '" />' . "\n"; 1556 $r .= '</div></fieldset></form>' . $after; 1557 1558 return $r; 1559 } 1560 1561 function topic_class( $class = '', $key = 'topic', $id = 0 ) { 1562 $topic = get_topic( get_topic_id( $id ) ); 1563 $class = $class ? explode(' ', $class ) : array(); 1564 if ( '1' === $topic->topic_status && bb_current_user_can( 'browse_deleted' ) ) 1565 $class[] = 'deleted'; 1566 elseif ( 1 < $topic->topic_status && bb_current_user_can( 'browse_deleted' ) ) 1567 $class[] = 'bozo'; 1568 if ( '0' === $topic->topic_open ) 1569 $class[] = 'closed'; 1570 if ( 1 == $topic->topic_sticky && ( bb_is_forum() || bb_is_view() ) ) 1571 $class[] = 'sticky'; 1572 elseif ( 2 == $topic->topic_sticky && ( bb_is_front() || bb_is_forum() || bb_is_view() ) ) 1573 $class[] = 'sticky super-sticky'; 1574 $class = apply_filters( 'topic_class', $class, $topic->topic_id ); 1575 $class = join(' ', $class); 1576 alt_class( $key, $class ); 1577 } 1578 1579 /** 1580 * bb_get_new_topic_link() - Get the link to the form for a new topic 1581 * 1582 * @since 1.0 1583 * @param mixed The arguments for this function. 1584 * @return string The link to the new topic form 1585 */ 1586 function bb_get_new_topic_link( $args = null ) { 1587 $defaults = array( 'text' => __('Add New »'), 'forum' => 0, 'tag' => '' ); 1588 if ( $args && is_string($args) && false === strpos($args, '=') ) 1589 $args = array( 'text' => $args ); 1590 1591 $args = wp_parse_args( $args, $defaults ); 1592 extract( $args, EXTR_SKIP ); 1593 1594 if ( $forum && $forum = bb_get_forum( $forum ) ) 1595 $url = get_forum_link( $forum->forum_id ) . '#postform'; 1596 elseif ( $tag && $tag = bb_get_tag( $tag ) ) 1597 $url = bb_get_tag_link( $tag->tag ) . '#postform'; 1598 elseif ( bb_is_forum() ) { 1599 global $forum; 1600 $url = get_forum_link( $forum->forum_id ) . '#postform'; 1601 } elseif ( bb_is_tag() ) { 1602 global $tag; 1603 $url = bb_get_tag_link( $tag ) . '#postform'; 1604 } elseif ( bb_is_topic() ) 1605 $url = get_forum_link() . '#postform'; 1606 elseif ( bb_is_front() ) 1607 $url = bb_get_uri(null, array('new' => 1)); 1608 1609 if ( !bb_is_user_logged_in() && bb_is_login_required() ) 1610 $url = bb_get_uri('bb-login.php', array('redirect_to' => $url), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS); 1611 elseif ( bb_is_forum() || bb_is_topic() ) { 1612 if ( !bb_current_user_can( 'write_topic', get_forum_id() ) ) 1613 return; 1614 } else { 1615 if ( !bb_current_user_can( 'write_topics' ) ) 1616 return; 1617 } 1618 1619 if ( $url = esc_attr( apply_filters( 'new_topic_url', $url, $args ) ) ) 1620 return '<a href="' . $url . '" class="new-topic">' . $text . '</a>' . "\n"; 1621 } 1622 1623 function bb_new_topic_link( $args = null ) { 1624 echo bb_get_new_topic_link($args); 1625 } 1626 1627 function bb_new_topic_forum_dropdown( $args = '' ) { 1628 if ( !is_array( $args ) ) { 1629 $args = array( 1630 'callback' => 'bb_current_user_can', 1631 'callback_args' => array( 'write_topic' ) 1632 ); 1633 } 1634 if ( !isset( $args['callback'] ) && !isset( $args['callback_args'] ) ) { 1635 $args['callback'] = 'bb_current_user_can'; 1636 $args['callback_args'] = array( 'write_topic' ); 1637 } 1638 bb_forum_dropdown( $args ); 1639 } 1640 1641 function bb_topic_search_form( $args = null, $query_obj = null ) { 1642 global $bb_query_form; 1643 1644 if ( $query_obj && is_a($query_obj, 'BB_Query_Form') ); // [sic] 1645 else 1646 $query_obj =& $bb_query_form; 1647 1648 $query_obj->form( $args ); 1649 } 1650 1651 function bb_search_pages( $args = null ) { 1652 global $page, $search_count, $per_page; 1653 1654 $defaults = array( 'before' => '', 'after' => '' ); 1655 $args = wp_parse_args( $args, $defaults ); 1656 1657 if ( $pages = apply_filters( 'bb_search_pages', get_page_number_links( array( 'page' => $page, 'total' => $search_count, 'per_page' => $per_page, 'mod_rewrite' => false ) ) ) ) 1658 echo $args['before'] . $pages . $args['after']; 1659 } 1660 1661 /** 1662 * bb_topic_pagecount() - Print the total page count for a topic 1663 * 1664 * @since 0.9 1665 * @param int $topic_id The topic id of the topic being queried 1666 * @return void 1667 */ 1668 function bb_topic_pagecount( $topic_id = 0 ) { 1669 echo bb_get_topic_pagecount( $topic_id ); 1670 } 1671 1672 /** 1673 * bb_get_topic_pagecount() - Get the total page count for a topic 1674 * 1675 * @since 0.9 1676 * @param int $topic_id The topic id of the topic being queried 1677 * @return int The total number of pages in the topic 1678 */ 1679 function bb_get_topic_pagecount( $topic_id = 0 ) { 1680 $topic = get_topic( get_topic_id( $topic_id ) ); 1681 return bb_get_page_number( $topic->topic_posts + topic_pages_add() ); 1682 } 1683 1684 /** 1685 * bb_is_topic_lastpage() - Report whether the current page is the last page of a given topic 1686 * 1687 * @since 0.9 1688 * @param int $topic_id The topic id of the topic being queried 1689 * @return boolean True if called on the last page of a topic, otherwise false 1690 */ 1691 function bb_is_topic_lastpage( $topic_id = 0 ) { 1692 global $page; 1693 return ( $page == bb_get_topic_pagecount( $topic_id ) ); 1694 } 1695 1696 // POSTS 1697 1698 function post_id( $post_id = 0 ) { 1699 echo get_post_id( $post_id ); 1700 } 1701 1702 function get_post_id( $post_id = 0 ) { 1703 global $bb_post; 1704 $post_id = (int) $post_id; 1705 if ( $post_id ) 1706 $post = bb_get_post( $post_id ); 1707 else 1708 $post =& $bb_post; 1709 return $post->post_id; 1710 } 1711 1712 function post_link( $post_id = 0 ) { 1713 echo apply_filters( 'post_link', get_post_link( $post_id ), get_post_id( $post_id ) ); 1714 } 1715 1716 function get_post_link( $post_id = 0 ) { 1717 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1718 $page = bb_get_page_number( $bb_post->post_position ); 1719 return apply_filters( 'get_post_link', get_topic_link( $bb_post->topic_id, $page ) . "#post-$bb_post->post_id", $bb_post->post_id ); 1720 } 1721 1722 function post_anchor_link( $force_full = false ) { 1723 if ( defined('DOING_AJAX') || $force_full ) 1724 post_link(); 1725 else 1726 echo '#post-' . get_post_id(); 1727 } 1728 1729 function post_position( $post_id = 0 ) { 1730 echo apply_filters( 'post_position', get_post_position( $post_id ), get_post_id( $post_id ) ); 1731 } 1732 1733 function get_post_position( $post_id = 0 ) { 1734 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1735 return apply_filters( 'get_post_position', $bb_post->post_position, $bb_post->post_id ); 1736 } 1737 1738 function post_position_link( $topic_id = 0, $position = 1 ) { 1739 echo apply_filters( 'post_position_link', get_post_position_link( $topic_id, $position ), get_topic_id( $topic_id ), (integer) $position ); 1740 } 1741 1742 function get_post_position_link( $topic_id = 0, $position = 1 ) { 1743 $position = (integer) $position; 1744 $bb_topic = get_topic( get_topic_id( $topic_id ) ); 1745 if ( $bb_topic->topic_posts < $position ) { 1746 return; 1747 } 1748 $page = bb_get_page_number( $position ); 1749 return apply_filters( 'get_post_position_link', get_topic_link( $bb_post->topic_id, $page ) . "#position-$position", $bb_topic->topic_id, $position ); 1750 } 1751 1752 function bb_post_meta( $key, $post_id = 0 ) { 1753 echo bb_get_post_meta( $key, $post_id ); 1754 } 1755 1756 function bb_get_post_meta( $key, $post_id = 0 ) { 1757 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1758 if ( isset($bb_post->$key) ) 1759 return $bb_post->$key; 1760 } 1761 1762 1763 function post_author( $post_id = 0 ) { 1764 echo apply_filters('post_author', get_post_author( $post_id ), $post_id ); 1765 } 1766 1767 function get_post_author( $post_id = 0 ) { 1768 if ( $user = bb_get_user( get_post_author_id( $post_id ) ) ) 1769 return apply_filters( 'get_post_author', $user->display_name, $user->ID, $post_id ); 1770 elseif ( $title = bb_get_post_meta( 'pingback_title', $post_id ) ) 1771 return apply_filters( 'bb_get_pingback_title', $title, $post_id ); 1772 elseif ( $title = bb_get_post_meta( 'post_author', $post_id ) ) 1773 return apply_filters( 'get_post_author', $title, 0, $post_id ); 1774 else 1775 return apply_filters( 'get_post_author', __('Anonymous'), 0, $post_id ); 1776 } 1777 1778 function post_author_link( $post_id = 0 ) { 1779 if ( $link = ( bb_get_option( 'name_link_profile' ) ? get_user_profile_link( get_post_author_id( $post_id ) ) : get_user_link( get_post_author_id( $post_id ) ) ) ) { 1780 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1781 } elseif ( $link = bb_get_post_meta( 'pingback_uri' )) { 1782 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1783 } elseif ( $link = bb_get_post_meta( 'post_url' ) ) { 1784 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1785 } else { 1786 post_author( $post_id ); 1787 } 1788 } 1789 1790 function post_author_avatar( $size = '48', $default = '', $post_id = 0 ) { 1791 if ( ! bb_get_option('avatars_show') ) 1792 return false; 1793 1794 $author_id = get_post_author_id( $post_id ); 1795 echo bb_get_avatar( $author_id, $size, $default ); 1796 } 1797 1798 function post_author_avatar_link( $size = '48', $default = '', $post_id = 0 ) { 1799 if ( ! bb_get_option('avatars_show') ) 1800 return false; 1801 1802 $author_id = get_post_author_id( $post_id ); 1803 if ( $link = get_user_link( $author_id ) ) { 1804 echo '<a href="' . esc_attr( $link ) . '">' . bb_get_avatar( $author_id, $size, $default ) . '</a>'; 1805 } else { 1806 echo bb_get_avatar( $author_id, $size, $default ); 1807 } 1808 } 1809 1810 function post_text( $post_id = 0 ) { 1811 echo apply_filters( 'post_text', get_post_text( $post_id ), get_post_id( $post_id ) ); 1812 } 1813 1814 function get_post_text( $post_id = 0 ) { 1815 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1816 return apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id ); 1817 } 1818 1819 function bb_post_time( $args = '' ) { 1820 $args = _bb_parse_time_function_args( $args ); 1821 $time = apply_filters( 'bb_post_time', bb_get_post_time( array('format' => 'mysql') + $args ), $args ); 1822 echo _bb_time_function_return( $time, $args ); 1823 } 1824 1825 function bb_get_post_time( $args = '' ) { 1826 $args = _bb_parse_time_function_args( $args ); 1827 1828 $bb_post = bb_get_post( get_post_id( $args['id'] ) ); 1829 1830 $time = apply_filters( 'bb_get_post_time', $bb_post->post_time, $args ); 1831 1832 return _bb_time_function_return( $time, $args ); 1833 } 1834 1835 function post_ip( $post_id = 0 ) { 1836 if ( bb_current_user_can( 'view_by_ip' ) ) 1837 echo apply_filters( 'post_ip', get_post_ip( $post_id ), get_post_id( $post_id ) ); 1838 } 1839 1840 function get_post_ip( $post_id = 0 ) { 1841 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1842 return apply_filters( 'get_post_ip', $bb_post->poster_ip, $bb_post->post_id ); 1843 } 1844 1845 function bb_post_admin( $args = null ) 1846 { 1847 $defaults = array( 1848 'post_id' => 0, 1849 'before' => '', 1850 'after' => '', 1851 'before_each' => '', 1852 'after_each' => "\n", 1853 'each' => array( 1854 'ip' => array( 1855 'post_id' => 0 1856 ), 1857 'edit' => array( 1858 'post_id' => 0 1859 ), 1860 'delete' => array( 1861 'post_id' => 0 1862 ), 1863 'undelete' => array( 1864 'post_id' => 0 1865 ) 1866 ) 1867 ); 1868 if ( isset( $args['each'] ) ) { 1869 $each_args = $args['each']; 1870 $_each_args = $defaults['each']; 1871 foreach ( $each_args as $_part_name => $_part_args ) { 1872 if ( !isset( $defaults['each'][$_part_name] ) ) { 1873 continue; 1874 } 1875 $_each_args[$_part_name] = wp_parse_args( $_part_args, $defaults['each'][$_part_name] ); 1876 } 1877 } 1878 $args = wp_parse_args( $args, $defaults ); 1879 if ( isset( $_each_args ) ) { 1880 $args['each'] = $_each_args; 1881 } 1882 1883 $parts = array(); 1884 if ( is_array( $args['each'] ) && count( $args['each'] ) ) { 1885 foreach ( $args['each'] as $_part_name => $_part_args ) { 1886 if ( $args['post_id'] && !$_part_args['post_id'] ) { 1887 $_part_args['post_id'] = $args['post_id']; 1888 } 1889 if ( $args['before_each'] && !$_part_args['before'] ) { 1890 $_part_args['before'] = $args['before_each']; 1891 } 1892 if ( $args['after_each'] && !$_part_args['after'] ) { 1893 $_part_args['after'] = $args['after_each']; 1894 } 1895 $_part_function = 'bb_get_post_' . $_part_name . '_link'; 1896 $parts[$_part_name] = $_part_function( $_part_args ); 1897 } 1898 1899 // For the benefit of filters, mark the final part 1900 if ( !isset( $args['last_each'] ) ) { 1901 $args['last_each'] = $_part_args; 1902 } 1903 } 1904 1905 $parts = apply_filters( 'bb_post_admin', $parts, $args ); 1906 1907 if ( !count( $parts ) ) { 1908 return; 1909 } 1910 1911 echo $args['before'] . join( '', $parts ) . $args['after']; 1912 } 1913 1914 function post_ip_link( $args = null ) 1915 { 1916 echo bb_get_post_ip_link( $args ); 1917 } 1918 1919 function bb_get_post_ip_link( $args = null ) 1920 { 1921 if ( !bb_current_user_can( 'view_by_ip' ) ) { 1922 return; 1923 } 1924 1925 $defaults = array( 1926 'post_id' => 0, 1927 'before' => '', 1928 'after' => '', 1929 'text' => '%s' 1930 ); 1931 if ( is_numeric( $args ) ) { 1932 $args = array( 'post_id' => $args ); 1933 } 1934 $args = wp_parse_args( $args, $defaults ); 1935 1936 $bb_post = bb_get_post( get_post_id( $args['post_id'] ) ); 1937 1938 $uri = bb_get_uri( 'bb-admin/posts.php', array( 'poster_ip' => get_post_ip( $bb_post->post_id ) ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ); 1939 1940 // Make sure that the last tag in $before gets a class (if it's there) 1941 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $args['before'], $_node ) ) { 1942 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 1943 $args['before'] = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-ip-link ' . $_class[2] . $_class[1], $args['before'] ); 1944 } else { 1945 $args['before'] = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-ip-link"$3$4>$5', $args['before'], 1 ); 1946 } 1947 } 1948 1949 $link = $args['before'] . '<a class="post-ip-link" href="' . esc_attr( $uri ) . '">' . esc_html( sprintf( $args['text'], get_post_ip( $bb_post->post_id ) ) ) . '</a>' . $args['after']; 1950 return apply_filters( 'post_ip_link', $link, $bb_post->post_id, $args ); 1951 } 1952 1953 function post_edit_link( $args = null ) 1954 { 1955 echo bb_get_post_edit_link( $args ); 1956 } 1957 1958 function bb_get_post_edit_link( $args = null ) 1959 { 1960 $defaults = array( 1961 'post_id' => 0, 1962 'before' => '', 1963 'after' => '', 1964 'text' => __( 'Edit' ) 1965 ); 1966 if ( is_numeric( $args ) ) { 1967 $args = array( 'post_id' => $args ); 1968 } 1969 $args = wp_parse_args( $args, $defaults ); 1970 1971 $bb_post = bb_get_post( get_post_id( $args['post_id'] ) ); 1972 1973 if ( bb_current_user_can( 'edit_post', $bb_post->post_id ) ) { 1974 $uri = bb_get_uri( 'edit.php', array( 'id' => $bb_post->post_id ) ); 1975 1976 // Make sure that the last tag in $before gets a class (if it's there) 1977 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $args['before'], $_node ) ) { 1978 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 1979 $args['before'] = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-edit-link ' . $_class[2] . $_class[1], $args['before'] ); 1980 } else { 1981 $args['before'] = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-edit-link"$3$4>$5', $args['before'], 1 ); 1982 } 1983 } 1984 1985 $r = $args['before'] . '<a class="post-edit-link" href="' . esc_attr( apply_filters( 'post_edit_uri', $uri, $bb_post->post_id, $args ) ) . '">' . esc_html( $args['text'] ) . '</a>' . $args['after']; 1986 return apply_filters( 'bb_get_post_edit_link', $r, $bb_post->post_id, $args ); 1987 } 1988 } 1989 1990 function post_del_class( $post_id = 0 ) 1991 { 1992 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1993 $classes = array(); 1994 if ( bb_get_post_meta( 'pingback_uri', $post_id ) ) { 1995 $classes[] = 'pingback'; 1996 } 1997 if ( $bb_post->post_status == 1 ) { 1998 $classes[] = 'deleted'; 1999 } elseif ( $bb_post->post_status != 0 ) { 2000 $classes[] = 'post-status-' . $bb_post->post_status; 2001 } 2002 if ( count( $classes ) ) { 2003 $classes = join( ' ', $classes ); 2004 } else { 2005 $classes = ''; 2006 } 2007 return apply_filters( 'post_del_class', $classes, $bb_post->post_id, $bb_post ); 2008 } 2009 2010 function post_delete_link( $args = null ) 2011 { 2012 echo bb_get_post_delete_link( $args ); 2013 } 2014 2015 function bb_get_post_delete_link( $args = null ) 2016 { 2017 $defaults = array( 2018 'post_id' => 0, 2019 'before' => '', 2020 'after' => '', 2021 'text' => __( 'Delete' ), 2022 'redirect' => true 2023 ); 2024 if ( is_numeric( $args ) || is_object( $args ) ) { 2025 $args = array( 'post_id' => $args ); 2026 } 2027 if ( isset( $args['delete_text'] ) && ( !isset( $args['text'] ) || !$args['text'] ) ) { 2028 $args['text'] = $args['delete_text']; 2029 } 2030 2031 $args = wp_parse_args( $args, $defaults ); 2032 extract( $args, EXTR_SKIP ); 2033 2034 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2035 //if ( bb_is_first( $bb_post->post_id ) ) { 2036 // $topic = get_topic( $bb_post->topic_id ); 2037 // if ( 2 > $topic->topic_posts ) { 2038 // Should delete the whole topic 2039 // return; 2040 // } 2041 //} 2042 2043 if ( !bb_current_user_can( 'delete_post', $bb_post->post_id ) ) { 2044 return; 2045 } 2046 2047 if ( true === $redirect ) { 2048 $redirect = $_SERVER['REQUEST_URI']; 2049 } 2050 2051 $uri = bb_get_uri('bb-admin/delete-post.php', array( 2052 'id' => $bb_post->post_id, 2053 'status' => 1, 2054 '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false 2055 ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 2056 $uri = esc_url( bb_nonce_url( $uri, 'delete-post_' . $bb_post->post_id ) ); 2057 2058 if ( ( bb_is_admin() || isset( $_GET['view'] ) && 'all' == $_GET['view'] ) ) { 2059 $ajax_class = 'dim:thread:post-' . $bb_post->post_id . ':deleted:FF3333:FFFF33:action=delete-post&status=1'; 2060 } else { 2061 $ajax_class = 'delete:thread:post-' . $bb_post->post_id . '::status=1'; 2062 } 2063 2064 $text = esc_html( $text ); 2065 2066 // Make sure that the last tag in $before gets a class (if it's there) 2067 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $before, $_node ) ) { 2068 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 2069 $before = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-delete-link ' . $_class[2] . $_class[1], $before ); 2070 } else { 2071 $before = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-delete-link"$3$4>$5', $before, 1 ); 2072 } 2073 } 2074 2075 $r = $before . '<a href="' . $uri . '" class="' . $ajax_class . ' post-delete-link">' . $text . '</a>' . $after; 2076 $r = apply_filters( 'post_delete_link', $r, $bb_post->post_status, $bb_post->post_id, $args ); 2077 return $r; 2078 } 2079 2080 function bb_post_undelete_link( $args = null ) 2081 { 2082 echo bb_get_post_undelete_link( $args ); 2083 } 2084 2085 function bb_get_post_undelete_link( $args = null ) 2086 { 2087 $defaults = array( 2088 'post_id' => 0, 2089 'before' => '', 2090 'after' => '', 2091 'text' => __( 'Undelete' ), 2092 'redirect' => true 2093 ); 2094 if ( is_numeric( $args ) || is_object( $args ) ) { 2095 $args = array( 'post_id' => $args ); 2096 } 2097 2098 $args = wp_parse_args( $args, $defaults ); 2099 extract( $args, EXTR_SKIP ); 2100 2101 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2102 2103 if ( !bb_current_user_can( 'delete_post', $bb_post->post_id ) ) { 2104 return; 2105 } 2106 2107 if ( true === $redirect ) { 2108 $redirect = $_SERVER['REQUEST_URI']; 2109 } 2110 2111 $uri = bb_get_uri('bb-admin/delete-post.php', array( 2112 'id' => $bb_post->post_id, 2113 'status' => 0, 2114 'view' => 'all', 2115 '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false 2116 ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 2117 $uri = esc_url( bb_nonce_url( $uri, 'delete-post_' . $bb_post->post_id ) ); 2118 2119 $ajax_class = 'dim:thread:post-' . $bb_post->post_id . ':deleted:FF3333:FFFF33:action=delete-post&status=0'; 2120 2121 $text = esc_html( $text ); 2122 2123 // Make sure that the last tag in $before gets a class (if it's there) 2124 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $before, $_node ) ) { 2125 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 2126 $before = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-undelete-link ' . $_class[2] . $_class[1], $before ); 2127 } else { 2128 $before = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-undelete-link"$3$4>$5', $before, 1 ); 2129 } 2130 } 2131 2132 $r = $before . '<a href="' . $uri . '" class="' . $ajax_class . ' post-undelete-link">' . $text . '</a>' . $after; 2133 $r = apply_filters( 'post_undelete_link', $r, $bb_post->post_status, $bb_post->post_id, $args ); 2134 return $r; 2135 } 2136 2137 function post_author_id( $post_id = 0 ) { 2138 echo apply_filters( 'post_author_id', get_post_author_id( $post_id ), get_post_id( $post_id ) ); 2139 } 2140 2141 function get_post_author_id( $post_id = 0 ) { 2142 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2143 return apply_filters( 'get_post_author_id', (int) $bb_post->poster_id, get_post_id( $post_id ) ); 2144 } 2145 2146 function post_author_title( $post_id = 0 ) { 2147 echo apply_filters( 'post_author_title', get_post_author_title( $post_id ), get_post_id( $post_id ) ); 2148 } 2149 2150 function get_post_author_title( $post_id = 0 ) { 2151 return get_user_title( get_post_author_id( $post_id ) ); 2152 } 2153 2154 function post_author_title_link( $post_id = 0 ) { 2155 echo apply_filters( 'post_author_title_link', get_post_author_title_link( $post_id ), get_post_id( $post_id ) ); 2156 } 2157 2158 function get_post_author_title_link( $post_id = 0 ) { 2159 $title = get_post_author_title( $post_id ); 2160 if ( false === $title ) { 2161 if ( bb_get_post_meta( 'pingback_uri', $post_id ) ) 2162 $r = __('PingBack'); 2163 else 2164 $r = __('Unregistered'); // This should never happen 2165 } else { 2166 if ( $link = bb_get_option( 'name_link_profile' ) ? get_user_link( get_post_author_id( $post_id ) ) : get_user_profile_link( get_post_author_id( $post_id ) ) ) 2167 $r = '<a href="' . esc_attr( $link ) . '">' . $title . '</a>'; 2168 else 2169 $r = $title; 2170 } 2171 2172 return apply_filters( 'get_post_author_title_link', $r, get_post_id( $post_id ) ); 2173 } 2174 2175 function post_author_type( $post_id = 0 ) { 2176 $id = get_post_author_id( $post_id ); 2177 $type = get_user_type( $id ); 2178 if ( false === $type ) { 2179 if ( bb_get_post_meta( 'pingback_uri', $post_id ) ) 2180 $r = __('PingBack'); 2181 else 2182 $r = __('Unregistered'); // This should never happen 2183 } else 2184 $r = '<a href="' . esc_attr( get_user_profile_link( $id ) ) . '">' . $type . '</a>'; 2185 2186 echo apply_filters( 'post_author_type', $r, $post_id ); 2187 } 2188 2189 function allowed_markup( $args = '' ) { 2190 echo apply_filters( 'allowed_markup', get_allowed_markup( $args ) ); 2191 } 2192 2193 // format=list or array( 'format' => 'list' ) 2194 function get_allowed_markup( $args = '' ) { 2195 $args = wp_parse_args( $args, array('format' => 'flat') ); 2196 extract($args, EXTR_SKIP); 2197 2198 $tags = bb_allowed_tags(); 2199 unset($tags['pre'], $tags['br']); 2200 $tags = array_keys($tags); 2201 2202 switch ( $format ) : 2203 case 'array' : 2204 $r = $tags; 2205 break; 2206 case 'list' : 2207 $r = "<ul class='allowed-markup'>\n\t<li>"; 2208 $r .= join("</li>\n\t<li>", $tags); 2209 $r .= "</li>\n</ul>\n"; 2210 break; 2211 default : 2212 $r = join(' ', $tags); 2213 break; 2214 endswitch; 2215 return apply_filters( 'get_allowed_markup', $r, $format ); 2216 } 2217 2218 // USERS 2219 function bb_get_user_id( $id = 0 ) { 2220 global $user; 2221 if ( is_object($id) && isset($id->ID) ) 2222 return (int) $id->ID; 2223 elseif ( !$id ) 2224 return $user->ID; 2225 2226 $_user = bb_get_user( (int) $id ); 2227 return isset($_user->ID) ? $_user->ID : 0; 2228 } 2229 2230 function user_profile_link( $id = 0 , $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 2231 if (!$context || !is_integer($context)) { 2232 $context = BB_URI_CONTEXT_A_HREF; 2233 } 2234 echo apply_filters( 'user_profile_link', get_user_profile_link( $id ), bb_get_user_id( $id ), $context ); 2235 } 2236 2237 function get_user_profile_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 2238 $user = bb_get_user( bb_get_user_id( $id ) ); 2239 2240 if (!$context || !is_integer($context)) { 2241 $context = BB_URI_CONTEXT_A_HREF; 2242 } 2243 2244 $rewrite = bb_get_option( 'mod_rewrite' ); 2245 if ( $rewrite ) { 2246 if ( $rewrite === 'slugs' ) { 2247 $column = 'user_nicename'; 2248 } else { 2249 $column = 'ID'; 2250 } 2251 $page = (1 < $page) ? '/page/' . $page : ''; 2252 $r = bb_get_uri('profile/' . $user->$column . $page, null, $context); 2253 } else { 2254 $query = array( 2255 'id' => $user->ID, 2256 'page' => (1 < $page) ? $page : false 2257 ); 2258 $r = bb_get_uri('profile.php', $query, $context); 2259 } 2260 return apply_filters( 'get_user_profile_link', $r, $user->ID, $context ); 2261 } 2262 2263 function user_delete_button() { 2264 global $user; 2265 2266 $user_obj = new BP_User( $user->ID ); 2267 if ( !bb_current_user_can( 'keep_gate' ) && 'keymaster' == $user_obj->roles[0] ) 2268 return; 2269 2270 if ( bb_current_user_can( 'edit_users' ) && bb_get_current_user_info( 'id' ) != (int) $user->ID ) 2271 echo apply_filters( 'user_delete_button', get_user_delete_button() ); 2272 } 2273 2274 function get_user_delete_button() { 2275 $r = '<input type="submit" class="delete" name="delete-user" value="' . __('Delete User »') . '" '; 2276 $r .= 'onclick="return confirm(\'' . esc_js(__('Are you sure you want to delete this user?')) . '\')" />'; 2277 return apply_filters( 'get_user_delete_button', $r); 2278 } 2279 2280 function profile_tab_link( $id = 0, $tab, $page = 1 ) { 2281 echo apply_filters( 'profile_tab_link', get_profile_tab_link( $id, $tab ) ); 2282 } 2283 2284 function get_profile_tab_link( $id = 0, $tab, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 2285 $user = bb_get_user( bb_get_user_id( $id ) ); 2286 2287 $tab = bb_sanitize_with_dashes($tab); 2288 2289 if (!$context || !is_integer($context)) { 2290 $context = BB_URI_CONTEXT_A_HREF; 2291 } 2292 2293 if ( $tab === 'edit' && !( $context & BB_URI_CONTEXT_BB_USER_FORMS ) ) { 2294 $context += BB_URI_CONTEXT_BB_USER_FORMS; 2295 } 2296 2297 $rewrite = bb_get_option( 'mod_rewrite' ); 2298 if ( $rewrite ) { 2299 if ( $rewrite === 'slugs' ) { 2300 $column = 'user_nicename'; 2301 } else { 2302 $column = 'ID'; 2303 } 2304 $page = (1 < $page) ? '/page/' . $page : ''; 2305 $r = bb_get_uri('profile/' . $user->$column . '/' . $tab . $page, null, $context); 2306 } else { 2307 $query = array( 2308 'id' => $user->ID, 2309 'tab' => $tab, 2310 'page' => (1 < $page) ? $page : false 2311 ); 2312 $r = bb_get_uri('profile.php', $query, $context); 2313 } 2314 return apply_filters( 'get_profile_tab_link', $r, $user->ID, $context ); 2315 } 2316 2317 function user_link( $id = 0 ) { 2318 echo apply_filters( 'user_link', get_user_link( $id ), $id ); 2319 } 2320 2321 function get_user_link( $id = 0 ) { 2322 if ( $user = bb_get_user( bb_get_user_id( $id ) ) ) 2323 return apply_filters( 'get_user_link', $user->user_url, $user->ID ); 2324 } 2325 2326 function full_user_link( $id = 0 ) { 2327 echo get_full_user_link( $id ); 2328 } 2329 2330 function get_full_user_link( $id = 0 ) { 2331 if ( get_user_link( $id ) ) 2332 $r = '<a href="' . esc_attr( get_user_link( $id ) ) . '">' . get_user_display_name( $id ) . '</a>'; 2333 else 2334 $r = get_user_display_name( $id ); 2335 return $r; 2336 } 2337 2338 function user_type_label( $type ) { 2339 echo apply_filters( 'user_type_label', get_user_type_label( $type ), $type ); 2340 } 2341 2342 function get_user_type_label( $type ) { 2343 global $wp_roles; 2344 if ( $wp_roles->is_role( $type ) ) 2345 return apply_filters( 'get_user_type_label', $wp_roles->role_names[$type], $type ); 2346 } 2347 2348 function user_type( $id = 0 ) { 2349 echo apply_filters( 'user_type', get_user_type( $id ), $id ); 2350 } 2351 2352 function get_user_type( $id = 0 ) { 2353 if ( $user = bb_get_user( bb_get_user_id( $id ) ) ) : 2354 @$caps = array_keys($user->capabilities); 2355 if ( !$caps ) 2356 $caps[] = 'inactive'; 2357 2358 $type = get_user_type_label( $caps[0] ); //Just support one role for now. 2359 else : 2360 $type = false; 2361 endif; 2362 return apply_filters( 'get_user_type', $type, $user->ID ); 2363 } 2364 2365 function get_user_name( $id = 0 ) { 2366 $user = bb_get_user( bb_get_user_id( $id ) ); 2367 return apply_filters( 'get_user_name', $user->user_login, $user->ID ); 2368 } 2369 2370 function get_user_display_name( $id = 0 ) { 2371 $user = bb_get_user( bb_get_user_id( $id ) ); 2372 return apply_filters( 'get_user_display_name', $user->display_name, $user->ID ); 2373 } 2374 2375 function user_title( $id = 0 ) { 2376 echo apply_filters( 'user_title', get_user_title( $id ), bb_get_user_id( $id ) ); 2377 } 2378 2379 function get_user_title( $id = 0 ) { 2380 $user = bb_get_user( bb_get_user_id( $id ) ); 2381 return empty( $user->title ) ? get_user_type( $id ) : apply_filters( 'get_user_title', $user->title, $user->ID ); 2382 } 2383 2384 function profile_pages( $args = null ) 2385 { 2386 $defaults = array( 'before' => '', 'after' => '' ); 2387 $args = wp_parse_args( $args, $defaults ); 2388 2389 global $page, $user; 2390 $add = apply_filters( 'profile_pages_add', $add ); 2391 if ( $pages = apply_filters( 'profile_pages', get_page_number_links( $page, $user->topics_replied + $add ), $user->user_id ) ) { 2392 echo $args['before'] . $pages . $args['after']; 2393 } 2394 } 2395 2396 function bb_profile_data( $id = 0 ) { 2397 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2398 return; 2399 2400 $reg_time = bb_gmtstrtotime( $user->user_registered ); 2401 $profile_info_keys = bb_get_profile_info_keys(); 2402 echo "<dl id='userinfo'>\n"; 2403 echo "\t<dt>" . __('Member Since') . "</dt>\n"; 2404 echo "\t<dd>" . bb_datetime_format_i18n($reg_time, 'date') . ' (' . bb_since($reg_time) . ")</dd>\n"; 2405 if ( is_array( $profile_info_keys ) ) { 2406 foreach ( $profile_info_keys as $key => $label ) { 2407 if ( in_array($key, array('first_name', 'last_name', 'display_name')) || !isset($user->$key) ) 2408 continue; 2409 $val = 'user_url' == $key ? get_user_link( $user->ID ) : $user->$key; 2410 if ( 2411 ( 'user_email' != $key || ( 'user_email' == $key && bb_current_user_can( 'edit_users' ) ) ) 2412 && $val 2413 && 'http://' != $val 2414 ) { 2415 echo "\t<dt>{$label[1]}</dt>\n"; 2416 $val = make_clickable( $val ); 2417 $attributes = array(); 2418 if (isset($label[2]) && !empty($label[2])) 2419 if (preg_match("#^<a#i", $val)) 2420 $val = preg_replace("#^<a#i", '<a class="' . esc_attr($label[2]) . '"', $val); 2421 else 2422 $val = '<span class="' . esc_attr($label[2]) . '">' . $val . '</span>'; 2423 2424 echo "\t<dd>" . $val . "</dd>\n"; 2425 } 2426 } 2427 } 2428 echo "</dl>\n"; 2429 } 2430 2431 function bb_profile_base_content() { 2432 global $self; 2433 if ( !is_callable( $self ) ) 2434 return; // should never happen 2435 call_user_func( $self ); 2436 } 2437 2438 function bb_profile_data_form( $id = 0 ) { 2439 global $errors; 2440 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2441 return; 2442 2443 if ( !bb_current_user_can( 'edit_user', $user->ID ) ) 2444 return; 2445 2446 $error_codes = $errors->get_error_codes(); 2447 $profile_info_keys = bb_get_profile_info_keys(); 2448 $required = false; 2449 if ( in_array( 'delete', $error_codes ) ) 2450 echo '<div class="form-invalid error">' . $errors->get_error_message( 'delete' ) . '</div>'; 2451 ?> 2452 <table id="userinfo"> 2453 <?php 2454 if ( is_array($profile_info_keys) ) : 2455 $bb_current_id = bb_get_current_user_info( 'id' ); 2456 foreach ( $profile_info_keys as $key => $label ) : 2457 if ( $label[0] ) { 2458 $class = 'form-field form-required required'; 2459 $required = true; 2460 } else { 2461 $class = 'form-field'; 2462 } 2463 $title = esc_attr( $label[1] ); 2464 2465 $name = esc_attr( $key ); 2466 $type = isset($label[2]) ? esc_attr( $label[2] ) : 'text'; 2467 if ( !in_array( $type, array( 'checkbox', 'file', 'hidden', 'image', 'password', 'radio', 'text' ) ) ) { 2468 $type = 'text'; 2469 } 2470 2471 $checked = false; 2472 if ( in_array( $key, $error_codes ) ) { 2473 $class .= ' form-invalid error'; 2474 $data = $errors->get_error_data( $key ); 2475 if ( 'checkbox' == $type ) { 2476 if ( isset($data['data']) ) 2477 $checked = $data['data']; 2478 else 2479 $checked = $_POST[$key]; 2480 $value = $label[3]; 2481 $checked = $checked == $value; 2482 } else { 2483 if ( isset($data['data']) ) 2484 $value = $data['data']; 2485 else 2486 $value = $_POST[$key]; 2487 } 2488 2489 $message = esc_html( $errors->get_error_message( $key ) ); 2490 $message = "<em>$message</em>"; 2491 } else { 2492 if ( 'checkbox' == $type ) { 2493 $checked = $user->$key == $label[3] || $label[4] == $label[3]; 2494 $value = $label[3]; 2495 } else { 2496 $value = isset($user->$key) ? $user->$key : ''; 2497 } 2498 $message = ''; 2499 } 2500 2501 $checked = $checked ? ' checked="checked"' : ''; 2502 $value = esc_attr( $value ); 2503 2504 ?> 2505 2506 <tr class="<?php echo $class; ?>"> 2507 <th scope="row"> 2508 <label for="<?php echo $name; ?>"><?php echo $title; ?></label> 2509 <?php echo $message; ?> 2510 </th> 2511 <td> 2512 <?php 2513 if ($key == 'display_name') { 2514 ?> 2515 <select name="display_name" id="display_name"> 2516 <?php 2517 $public_display = array(); 2518 $public_display['display_displayname'] = $user->display_name; 2519 //$public_display['display_nickname'] = $user->nickname; 2520 $public_display['display_username'] = $user->user_login; 2521 if ( isset($user->first_name) ) { 2522 $public_display['display_firstname'] = $user->first_name; 2523 if ( isset($user->last_name) ) { 2524 $public_display['display_firstlast'] = $user->first_name.' '.$user->last_name; 2525 $public_display['display_lastfirst'] = $user->last_name.' '.$user->first_name; 2526 } 2527 } 2528 if ( isset($user->last_name) ) 2529 $public_display['display_lastname'] = $user->last_name; 2530 2531 $public_display = array_unique(array_filter(array_map('trim', $public_display))); 2532 2533 foreach($public_display as $id => $item) { 2534 ?> 2535 <option id="<?php echo esc_attr( $id ); ?>" value="<?php echo esc_attr( $item ); ?>"><?php echo esc_html( $item ); ?></option> 2536 <?php 2537 } 2538 ?> 2539 </select> 2540 <?php 2541 } else { 2542 ?> 2543 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo '<label for="' . $name . '">'; ?> 2544 <input name="<?php echo $name; ?>" id="<?php echo $name; ?>" type="<?php echo $type; ?>"<?php echo $checked; ?> value="<?php echo $value; ?>" /> 2545 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo esc_html( $label[5] ) . '</label>'; ?> 2546 <?php 2547 } 2548 ?> 2549 </td> 2550 </tr> 2551 2552 <?php endforeach; endif; // $profile_info_keys; $profile_info_keys ?> 2553 2554 </table> 2555 2556 <?php bb_nonce_field( 'edit-profile_' . $user->ID ); if ( $required ) : ?> 2557 2558 <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p> 2559 2560 <?php 2561 endif; 2562 do_action( 'extra_profile_info', $user->ID ); 2563 } 2564 2565 function bb_profile_admin_form( $id = 0 ) { 2566 global $wp_roles, $errors; 2567 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2568 return; 2569 2570 if ( !bb_current_user_can( 'edit_user', $user->ID ) ) 2571 return; 2572 2573 $error_codes = $errors->get_error_codes(); 2574 $bb_current_id = bb_get_current_user_info( 'id' ); 2575 2576 $profile_admin_keys = bb_get_profile_admin_keys(); 2577 $assignable_caps = bb_get_assignable_caps(); 2578 $required = false; 2579 2580 $roles = $wp_roles->role_names; 2581 $can_keep_gate = bb_current_user_can( 'keep_gate' ); 2582 2583 // Keymasters can't demote themselves 2584 if ( ( $bb_current_id == $user->ID && $can_keep_gate ) || ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( 'keymaster', $user->capabilities ) && !$can_keep_gate ) ) { 2585 $roles = array( 'keymaster' => $roles['keymaster'] ); 2586 } elseif ( !$can_keep_gate ) { // only keymasters can promote others to keymaster status 2587 unset($roles['keymaster']); 2588 } 2589 2590 $selected = array( 'inactive' => ' selected="selected"' ); 2591 ?> 2592 <table id="admininfo"> 2593 <tr class='form-field<?php if ( in_array( 'role', $error_codes ) ) echo ' form-invalid error'; ?>'> 2594 <th scope="row"> 2595 <label for="admininfo_role"><?php _e('User Type'); ?></label> 2596 <?php if ( in_array( 'role', $error_codes ) ) echo '<em>' . $errors->get_error_message( 'role' ) . '</em>'; ?> 2597 </th> 2598 <td> 2599 <select id="admininfo_role" name="role"> 2600 <?php 2601 foreach( $roles as $r => $n ) { 2602 if ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( $r, $user->capabilities ) ) { 2603 $selected['inactive'] = ''; 2604 $selected[$r] = ' selected="selected"'; 2605 } elseif ( $r !== 'inactive' ) { 2606 $selected[$r] = ''; 2607 } 2608 ?> 2609 <option value="<?php echo $r; ?>"<?php echo $selected[$r]; ?>><?php echo $n; ?></option> 2610 <?php 2611 } 2612 ?> 2613 </select> 2614 </td> 2615 </tr> 2616 <?php 2617 if (count($assignable_caps)) : 2618 ?> 2619 <tr class="extra-caps-row"> 2620 <th scope="row"><?php _e('Allow this user to'); ?></th> 2621 <td> 2622 <?php 2623 foreach( $assignable_caps as $cap => $label ) : 2624 $name = esc_attr( $cap ); 2625 $checked = ''; 2626 if ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( $cap, $user->capabilities ) ) { 2627 $checked = ' checked="checked"'; 2628 } 2629 $label = esc_html( $label ); 2630 ?> 2631 2632 <label><input name="<?php echo $name; ?>" value="1" type="checkbox"<?php echo $checked; ?> /> <?php echo $label; ?></label><br /> 2633 2634 <?php endforeach; ?> 2635 2636 </td> 2637 </tr> 2638 2639 <?php 2640 endif; 2641 2642 if ( is_array($profile_admin_keys) ) : 2643 foreach ( $profile_admin_keys as $key => $label ) : 2644 if ( $label[0] ) { 2645 $class = 'form-field form-required required'; 2646 $required = true; 2647 } else { 2648 $class = 'form-field'; 2649 } 2650 $title = esc_attr( $label[1] ); 2651 2652 $name = esc_attr( $key ); 2653 $type = isset($label[2]) ? esc_attr( $label[2] ) : 'text'; 2654 2655 $checked = false; 2656 if ( in_array( $key, $error_codes ) ) { 2657 $class .= ' form-invalid error'; 2658 $data = $errors->get_error_data( $key ); 2659 if ( 'checkbox' == $type ) { 2660 if ( isset($data['data']) ) 2661 $checked = $data['data']; 2662 else 2663 $checked = $_POST[$key]; 2664 $value = $label[3]; 2665 $checked = $checked == $value; 2666 } else { 2667 if ( isset($data['data']) ) 2668 $value = $data['data']; 2669 else 2670 $value = $_POST[$key]; 2671 } 2672 2673 $message = esc_html( $errors->get_error_message( $key ) ); 2674 $message = "<em>$message</em>"; 2675 } else { 2676 if ( 'checkbox' == $type ) { 2677 $checked = $user->$key == $label[3] || $label[4] == $label[3]; 2678 $value = $label[3]; 2679 } else { 2680 $value = isset($user->$key) ? $user->$key : ''; 2681 } 2682 $message = ''; 2683 } 2684 2685 $checked = $checked ? ' checked="checked"' : ''; 2686 $value = esc_attr( $value ); 2687 2688 ?> 2689 2690 <tr class="<?php echo $class; ?>"> 2691 <th scope="row"> 2692 <label for="<?php echo $name; ?>"><?php echo $title ?></label> 2693 <?php echo $message; ?> 2694 </th> 2695 <td> 2696 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo "<label for='$name'>"; ?> 2697 <input name="<?php echo $name; ?>" id="<?php echo $name; ?>" type="<?php echo $type; ?>"<?php echo $checked; ?> value="<?php echo $value; ?>" /> 2698 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo esc_html( $label[5] ) . "</label>"; ?> 2699 </td> 2700 </tr> 2701 2702 <?php endforeach; endif; // $profile_admin_keys; $profile_admin_keys ?> 2703 2704 </table> 2705 2706 <?php if ( $required ) : ?> 2707 <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p> 2708 2709 <?php endif; ?> 2710 <p><?php _e('Inactive users can login and look around but not do anything. Blocked users just see a simple error message when they visit the site.'); ?></p> 2711 <p><?php _e('<strong>Note</strong>: Blocking a user does <em>not</em> block any IP addresses.'); ?></p> 2712 <?php 2713 } 2714 2715 function bb_profile_password_form( $id = 0 ) { 2716 global $errors; 2717 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2718 return; 2719 2720 if ( !bb_current_user_can( 'change_user_password', $user->ID ) ) 2721 return; 2722 2723 $class = 'form-field'; 2724 2725 if ( $message = $errors->get_error_message( 'pass' ) ) { 2726 $class .= ' form-invalid error'; 2727 $message = '<em>' . esc_html( $message ) . '</em>'; 2728 } 2729 ?> 2730 2731 <table> 2732 <tr class="<?php echo $class; ?>"> 2733 <th scope="row" rowspan="2"> 2734 <label for="pass1"><?php _e('New password'); ?></label> 2735 <?php echo $message; ?> 2736 </th> 2737 <td> 2738 <input name="pass1" type="password" id="pass1" autocomplete="off" /> 2739 </td> 2740 </tr> 2741 <tr class="<?php echo $class; ?>"> 2742 <td> 2743 <input name="pass2" type="password" id="pass2" autocomplete="off" /> 2744 </td> 2745 </tr> 2746 <tr class="pass-strength"> 2747 <th scope="row"><?php _e('Password Strength'); ?></th> 2748 <td> 2749 <input type="hidden" name="user_login" id="user_login" value="<?php echo $user->user_login; ?>" /> 2750 <noscript> 2751 <?php _e('Disabled (requires JavaScript)'); ?> 2752 </noscript> 2753 <script type="text/javascript" charset="utf-8"> 2754 if (typeof jQuery != 'undefined') { 2755 document.writeln('<div id="pass-strength-result">' + pwsL10n.short + '</div>'); 2756 } else { 2757 document.writeln('<?php echo str_replace("'", "\'", __('Disabled.')); ?>') 2758 } 2759 </script> 2760 </td> 2761 </tr> 2762 </table> 2763 2764 <p><?php _e('Hint: Use upper and lower case characters, numbers and symbols like !"?$%^&( in your password.'); ?></p> 2765 2766 <?php 2767 2768 } 2769 2770 function bb_logout_link( $args = '' ) { 2771 echo apply_filters( 'bb_logout_link', bb_get_logout_link( $args ), $args ); 2772 } 2773 2774 function bb_get_logout_link( $args = '' ) { 2775 if ( $args && is_string($args) && false === strpos($args, '=') ) 2776 $args = array( 'text' => $args ); 2777 2778 $defaults = array('text' => __('Log Out'), 'before' => '', 'after' => '', 'redirect' => ''); 2779 $args = wp_parse_args( $args, $defaults ); 2780 extract($args, EXTR_SKIP); 2781 2782 $query = array( 'action' => 'logout' ); 2783 if ( $redirect ) { 2784 $query['redirect_to'] = $redirect; 2785 } 2786 2787 $uri = esc_attr( bb_get_uri('bb-login.php', $query, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS) ); 2788 2789 return apply_filters( 'bb_get_logout_link', $before . '<a href="' . $uri . '">' . $text . '</a>' . $after, $args ); 2790 } 2791 2792 function bb_admin_link( $args = '' ) { 2793 if ( !bb_current_user_can( 'moderate' ) ) 2794 return; 2795 echo apply_filters( 'bb_admin_link', bb_get_admin_link( $args ), $args ); 2796 } 2797 2798 function bb_get_admin_link( $args = '' ) { 2799 if ( !bb_current_user_can( 'moderate' ) ) 2800 return; 2801 if ( $args && is_string($args) && false === strpos($args, '=') ) 2802 $args = array( 'text' => $args ); 2803 2804 $defaults = array('text' => __('Admin'), 'before' => '', 'after' => ''); 2805 $args = wp_parse_args( $args, $defaults ); 2806 extract($args, EXTR_SKIP); 2807 2808 $uri = esc_attr( bb_get_uri('bb-admin/', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN) ); 2809 2810 return apply_filters( 'bb_get_admin_link', $before . '<a href="' . $uri . '">' . $text . '</a>' . $after, $args ); 2811 } 2812 2813 function bb_get_user_admin_link( $user_id = null ) { 2814 if( !$user_id || !bb_current_user_can( 'edit_user', $user_id ) ) 2815 return; 2816 2817 if( !bb_get_user_id( $user_id ) ) 2818 return; 2819 2820 $uri = bb_get_uri( 'bb-admin/users.php', array( 'action' => 'edit', 'user_id' => $user_id ) ); 2821 2822 return apply_filters( 'bb_get_user_admin_link', $uri, $user_id ); 2823 } 2824 2825 function bb_profile_link( $args = '' ) { 2826 echo apply_filters( 'bb_profile_link', bb_get_profile_link( $args ), $args ); 2827 } 2828 2829 function bb_get_profile_link( $args = '' ) { 2830 if ( $args && is_string($args) && false === strpos($args, '=') ) 2831 $args = array( 'text' => $args ); 2832 elseif ( is_numeric($args) ) 2833 $args = array( 'id' => $args ); 2834 2835 $defaults = array( 'text' => __('View your profile'), 'before' => '', 'after' => '', 'id' => false ); 2836 $args = wp_parse_args( $args, $defaults ); 2837 extract($args, EXTR_SKIP); 2838 2839 $id = (int) $id; 2840 if ( !$id ) 2841 $id = bb_get_current_user_info( 'id' ); 2842 2843 return apply_filters( 'bb_get_profile_link', "$before<a href='" . esc_attr( get_user_profile_link( $id ) ) . "'>$text</a>$after", $args ); 2844 } 2845 2846 function bb_current_user_info( $key = '' ) { 2847 if ( !$key ) 2848 return; 2849 echo apply_filters( 'bb_current_user_info', bb_get_current_user_info( $key ), $key ); 2850 } 2851 2852 2853 function bb_get_current_user_info( $key = '' ) { 2854 if ( !is_string($key) ) 2855 return; 2856 if ( !$user = bb_get_current_user() ) // Not globalized 2857 return false; 2858 2859 switch ( $key ) : 2860 case '' : 2861 return $user; 2862 break; 2863 case 'id' : 2864 case 'ID' : 2865 return (int) $user->ID; 2866 break; 2867 case 'name' : 2868 return get_user_display_name( $user->ID ); 2869 break; 2870 case 'login' : 2871 case 'user_login' : 2872 return get_user_name( $user->ID ); 2873 break; 2874 case 'email' : 2875 case 'user_email' : 2876 return bb_get_user_email( $user->ID ); 2877 break; 2878 case 'url' : 2879 case 'uri' : 2880 case 'user_url' : 2881 return get_user_link( $user->ID ); 2882 break; 2883 endswitch; 2884 } 2885 2886 function bb_get_user_email( $id ) { 2887 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2888 return false; 2889 2890 return apply_filters( 'bb_get_user_email', $user->user_email, $id ); 2891 } 2892 2893 //TAGS 2894 function topic_tags() 2895 { 2896 global $tags, $tag, $topic_tag_cache, $user_tags, $other_tags, $topic; 2897 if ( is_array( $tags ) || bb_current_user_can( 'edit_tag_by_on', bb_get_current_user_info( 'id' ), $topic->topic_id ) ) { 2898 bb_load_template( 'topic-tags.php', array('user_tags', 'other_tags', 'public_tags') ); 2899 } 2900 } 2901 2902 function bb_tag_page_link() 2903 { 2904 echo bb_get_tag_page_link(); 2905 } 2906 2907 function bb_get_tag_page_link( $context = BB_URI_CONTEXT_A_HREF ) 2908 { 2909 if ( bb_get_option( 'mod_rewrite' ) ) { 2910 $r = bb_get_uri( 'tags/', null, $context ); 2911 } else { 2912 $r = bb_get_uri( 'tags.php', null, $context ); 2913 } 2914 return apply_filters( 'bb_get_tag_page_link', $r, $context ); 2915 } 2916 2917 function bb_tag_link( $tag_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) 2918 { 2919 echo apply_filters( 'bb_tag_link', bb_get_tag_link( $tag_id, $page, $context ), $tag_id, $page, $context ); 2920 } 2921 2922 function bb_get_tag_link( $tag_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) 2923 { 2924 global $tag; 2925 2926 if ( $tag_id ) { 2927 if ( is_object( $tag_id ) ) { 2928 $_tag = $tag_id; 2929 } else { 2930 $_tag = bb_get_tag( $tag_id ); 2931 } 2932 } else { 2933 $_tag =& $tag; 2934 } 2935 2936 if ( !is_object( $_tag ) ) { 2937 return ''; 2938 } 2939 2940 if ( !$context || !is_integer( $context ) ) { 2941 $context = BB_URI_CONTEXT_A_HREF; 2942 } 2943 2944 if ( bb_get_option( 'mod_rewrite' ) ) { 2945 $page = (1 < $page) ? '/page/' . $page : ''; 2946 $r = bb_get_uri( 'tags/' . $_tag->tag . $page, null, $context ); 2947 } else { 2948 $query = array( 2949 'tag' => $_tag->tag, 2950 'page' => ( 1 < $page ) ? $page : false 2951 ); 2952 $r = bb_get_uri( 'tags.php', $query, $context ); 2953 } 2954 2955 return apply_filters( 'bb_get_tag_link', $r, $_tag->tag, $page, $context ); 2956 } 2957 2958 function bb_tag_link_base() 2959 { 2960 echo bb_get_tag_link_base(); 2961 } 2962 2963 function bb_get_tag_link_base() 2964 { 2965 return bb_get_tag_page_link() . ( bb_get_option( 'mod_rewrite' ) ? '' : '?tag=' ); 2966 } 2967 2968 function bb_tag_name( $tag_id = 0 ) 2969 { 2970 echo esc_html( bb_get_tag_name( $tag_id ) ); 2971 } 2972 2973 function bb_get_tag_name( $tag_id = 0 ) { 2974 global $tag; 2975 2976 if ( $tag_id ) { 2977 if ( is_object( $tag_id ) ) { 2978 $_tag = $tag_id; 2979 } else { 2980 $_tag = bb_get_tag( $tag_id ); 2981 } 2982 } else { 2983 $_tag =& $tag; 2984 } 2985 2986 if ( !is_object( $_tag ) ) { 2987 return ''; 2988 } 2989 2990 return $_tag->raw_tag; 2991 } 2992 2993 function bb_tag_posts_rss_link( $tag_id = 0, $context = 0 ) 2994 { 2995 if ( !$context || !is_integer( $context ) ) { 2996 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 2997 } 2998 2999 echo apply_filters( 'tag_posts_rss_link', bb_get_tag_posts_rss_link( $tagid, $context ), $tag_id, $context ); 3000 } 3001 3002 function bb_get_tag_posts_rss_link( $tag_id = 0, $context = 0 ) 3003 { 3004 global $tag; 3005 3006 if ( $tag_id ) { 3007 if ( is_object( $tag_id ) ) { 3008 $_tag = $tag_id; 3009 } else { 3010 $_tag = bb_get_tag( $tag_id ); 3011 } 3012 } else { 3013 $_tag =& $tag; 3014 } 3015 3016 if ( !is_object( $_tag ) ) { 3017 return ''; 3018 } 3019 3020 if ( !$context || !is_integer( $context ) ) { 3021 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3022 } 3023 3024 if ( bb_get_option( 'mod_rewrite' ) ) { 3025 $link = bb_get_uri( 'rss/tags/' . $_tag->tag, null, $context ); 3026 } else { 3027 $link = bb_get_uri( 'rss.php', array( 'tag' => $_tag->tag ), $context ); 3028 } 3029 3030 return apply_filters( 'get_tag_posts_rss_link', $link, $tag_id, $context ); 3031 } 3032 3033 function bb_tag_topics_rss_link( $tag_id = 0, $context = 0 ) 3034 { 3035 if ( !$context || !is_integer( $context ) ) { 3036 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3037 } 3038 3039 echo apply_filters( 'tag_topics_rss_link', bb_get_tag_topics_rss_link( $tag_id, $context ), $tag_id, $context ); 3040 } 3041 3042 function bb_get_tag_topics_rss_link( $tag_id = 0, $context = 0 ) 3043 { 3044 global $tag; 3045 3046 if ( $tag_id ) { 3047 if ( is_object( $tag_id ) ) { 3048 $_tag = $tag_id; 3049 } else { 3050 $_tag = bb_get_tag( $tag_id ); 3051 } 3052 } else { 3053 $_tag =& $tag; 3054 } 3055 3056 if ( !is_object( $_tag ) ) { 3057 return ''; 3058 } 3059 3060 if ( !$context || !is_integer( $context ) ) { 3061 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3062 } 3063 3064 if ( bb_get_option( 'mod_rewrite' ) ) { 3065 $link = bb_get_uri( 'rss/tags/' . $_tag->tag . '/topics', null, $context ); 3066 } else { 3067 $link = bb_get_uri( 'rss.php', array('tag' => $_tag->tag, 'topics' => 1 ), $context ); 3068 } 3069 3070 return apply_filters( 'get_tag_topics_rss_link', $link, $tag_id, $context ); 3071 } 3072 3073 function bb_list_tags( $args = null ) 3074 { 3075 $defaults = array( 3076 'tags' => false, 3077 'format' => 'list', 3078 'topic' => 0, 3079 'list_id' => 'tags-list' 3080 ); 3081 3082 $args = wp_parse_args( $args, $defaults ); 3083 extract( $args, EXTR_SKIP ); 3084 3085 if ( !$topic = get_topic( get_topic_id( $topic ) ) ) { 3086 return false; 3087 } 3088 3089 if ( !is_array( $tags ) ) { 3090 $tags = bb_get_topic_tags( $topic->topic_id ); 3091 } 3092 3093 if ( !$tags ) { 3094 return false; 3095 } 3096 3097 $list_id = esc_attr( $list_id ); 3098 3099 $r = ''; 3100 switch ( strtolower( $format ) ) { 3101 case 'table' : 3102 break; 3103 3104 case 'list' : 3105 default : 3106 $args['format'] = 'list'; 3107 $r .= '<ul id="' . $list_id . '" class="tags-list list:tag">' . "\n"; 3108 foreach ( $tags as $tag ) { 3109 $r .= _bb_list_tag_item( $tag, $args ); 3110 } 3111 $r .= '</ul>'; 3112 break; 3113 } 3114 3115 echo $r; 3116 } 3117 3118 function _bb_list_tag_item( $tag, $args ) 3119 { 3120 $url = esc_url( bb_get_tag_link( $tag ) ); 3121 $name = esc_html( bb_get_tag_name( $tag ) ); 3122 if ( 'list' == $args['format'] ) { 3123 $id = 'tag-' . $tag->tag_id . '_' . $tag->user_id; 3124 return "\t" . '<li id="' . $id . '"' . get_alt_class( 'topic-tags' ) . '><a href="' . $url . '" rel="tag">' . $name . '</a> ' . bb_get_tag_remove_link( array( 'tag' => $tag, 'list_id' => $args['list_id'] ) ) . '</li>' . "\n"; 3125 } 3126 } 3127 3128 function tag_form( $args = null ) 3129 { 3130 $defaults = array( 'topic' => 0, 'submit' => __('Add »'), 'list_id' => 'tags-list' ); 3131 $args = wp_parse_args( $args, $defaults ); 3132 extract( $args, EXTR_SKIP ); 3133 3134 if ( !$topic = get_topic( get_topic_id( $topic ) ) ) { 3135 return false; 3136 } 3137 3138 if ( !bb_current_user_can( 'edit_tag_by_on', bb_get_current_user_info( 'id' ), $topic->topic_id ) ) { 3139 return false; 3140 } 3141 3142 global $page; 3143 ?> 3144 3145 <form id="tag-form" method="post" action="<?php bb_uri('tag-add.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN); ?>" class="add:<?php echo esc_attr( $list_id ); ?>:"> 3146 <p> 3147 <input name="tag" type="text" id="tag" /> 3148 <input type="hidden" name="id" value="<?php echo $topic->topic_id; ?>" /> 3149 <input type="hidden" name="page" value="<?php echo $page; ?>" /> 3150 <?php bb_nonce_field( 'add-tag_' . $topic->topic_id ); ?> 3151 <input type="submit" name="submit" id="tagformsub" value="<?php echo esc_attr( $submit ); ?>" /> 3152 </p> 3153 </form> 3154 3155 <?php 3156 } 3157 3158 function manage_tags_forms() 3159 { 3160 global $tag; 3161 if ( !bb_current_user_can( 'manage_tags' ) ) { 3162 return false; 3163 } 3164 3165 $form = '<ul id="manage-tags">' . "\n"; 3166 $form .= '<li id="tag-rename">' . __('Rename tag:') . "\n\t"; 3167 $form .= '<form method="post" action="' . bb_get_uri( 'bb-admin/tag-rename.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ) . '"><div>' . "\n\t"; 3168 $form .= '<input type="text" name="tag" size="10" maxlength="30" />' . "\n\t"; 3169 $form .= '<input type="hidden" name="id" value="' . $tag->tag_id . '" />' . "\n\t"; 3170 $form .= "<input type='submit' name='Submit' value='" . __('Rename') . "' />\n\t"; 3171 echo $form; 3172 bb_nonce_field( 'rename-tag_' . $tag->tag_id ); 3173 echo "\n\t</div></form>\n </li>\n "; 3174 $form = "<li id='tag-merge'>" . __('Merge this tag into:') . "\n\t"; 3175 $form .= "<form method='post' action='" . bb_get_uri('bb-admin/tag-merge.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN) . "'><div>\n\t"; 3176 $form .= "<input type='text' name='tag' size='10' maxlength='30' />\n\t"; 3177 $form .= "<input type='hidden' name='id' value='$tag->tag_id' />\n\t"; 3178 $form .= "<input type='submit' name='Submit' value='" . __('Merge') . "' "; 3179 $form .= 'onclick="return confirm(\'' . esc_js( sprintf(__('Are you sure you want to merge the "%s" tag into the tag you specified? This is permanent and cannot be undone.'), $tag->raw_tag) ) . "');\" />\n\t"; 3180 echo $form; 3181 bb_nonce_field( 'merge-tag_' . $tag->tag_id ); 3182 echo "\n\t</div></form>\n </li>\n "; 3183 $form = "<li id='tag-destroy'>" . __('Destroy tag:') . "\n\t"; 3184 $form .= "<form method='post' action='" . bb_get_uri('bb-admin/tag-destroy.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN) . "'><div>\n\t"; 3185 $form .= "<input type='hidden' name='id' value='$tag->tag_id' />\n\t"; 3186 $form .= "<input type='submit' name='Submit' value='" . __('Destroy') . "' "; 3187 $form .= 'onclick="return confirm(\'' . esc_js( sprintf(__('Are you sure you want to destroy the "%s" tag? This is permanent and cannot be undone.'), $tag->raw_tag) ) . "');\" />\n\t"; 3188 echo $form; 3189 bb_nonce_field( 'destroy-tag_' . $tag->tag_id ); 3190 echo "\n\t</div></form>\n </li>\n</ul>"; 3191 } 3192 3193 function bb_tag_remove_link( $args = null ) { 3194 echo bb_get_tag_remove_link( $args ); 3195 } 3196 3197 function bb_get_tag_remove_link( $args = null ) { 3198 if ( is_scalar($args) || is_object( $args ) ) 3199 $args = array( 'tag' => $args ); 3200 $defaults = array( 'tag' => 0, 'topic' => 0, 'list_id' => 'tags-list' ); 3201 $args = wp_parse_args( $args, $defaults ); 3202 extract( $args, EXTR_SKIP ); 3203 3204 if ( is_object( $tag ) && isset( $tag->tag_id ) ); // [sic] 3205 elseif ( !$tag = bb_get_tag( bb_get_tag_id( $tag ) ) ) 3206 return false; 3207 if ( !$topic = get_topic( get_topic_id( $topic ) ) ) 3208 return false; 3209 if ( !bb_current_user_can( 'edit_tag_by_on', $tag->user_id, $topic->topic_id ) ) 3210 return false; 3211 $url = bb_get_uri('tag-remove.php', array('tag' => $tag->tag_id, 'user' => $tag->user_id, 'topic' => $topic->topic_id) ); 3212 $url = esc_url( bb_nonce_url( $url, 'remove-tag_' . $tag->tag_id . '|' . $topic->topic_id) ); 3213 $title = esc_attr__( 'Remove this tag' ); 3214 $list_id = esc_attr( $list_id ); 3215 return "[<a href='$url' class='delete:$list_id:tag-{$tag->tag_id}_{$tag->user_id}' title='$title'>×</a>]"; 3216 } 3217 3218 function bb_tag_heat_map( $args = '' ) { 3219 $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'limit' => 40, 'format' => 'flat' ); 3220 $args = wp_parse_args( $args, $defaults ); 3221 3222 if ( 1 < $fn = func_num_args() ) : // For back compat 3223 $args['smallest'] = func_get_arg(0); 3224 $args['largest'] = func_get_arg(1); 3225 $args['unit'] = 2 < $fn ? func_get_arg(2) : $unit; 3226 $args['limit'] = 3 < $fn ? func_get_arg(3) : $limit; 3227 endif; 3228 3229 extract($args, EXTR_SKIP); 3230 3231 $tags = bb_get_top_tags( array( 'number' => $limit ) ); 3232 3233 if ( empty($tags) ) 3234 return; 3235 3236 $r = bb_get_tag_heat_map( $tags, $args ); 3237 echo apply_filters( 'tag_heat_map', $r, $args ); 3238 } 3239 3240 function bb_get_tag_heat_map( $tags, $args = '' ) { 3241 $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'limit' => 45, 'format' => 'flat' ); 3242 $args = wp_parse_args( $args, $defaults ); 3243 extract($args, EXTR_SKIP); 3244 3245 if ( !$tags ) 3246 return; 3247 3248 foreach ( (array) $tags as $tag ) { 3249 $counts{$tag->raw_tag} = $tag->tag_count; 3250 $taglinks{$tag->raw_tag} = bb_get_tag_link( $tag ); 3251 } 3252 3253 $min_count = min($counts); 3254 $spread = max($counts) - $min_count; 3255 if ( $spread <= 0 ) 3256 $spread = 1; 3257 $fontspread = $largest - $smallest; 3258 if ( $fontspread <= 0 ) 3259 $fontspread = 1; 3260 $fontstep = $fontspread / $spread; 3261 3262 do_action_ref_array( 'sort_tag_heat_map', array(&$counts) ); 3263 3264 $a = array(); 3265 3266 foreach ( $counts as $tag => $count ) { 3267 $taglink = esc_attr($taglinks{$tag}); 3268 $tag = str_replace(' ', ' ', esc_html( $tag )); 3269 $fontsize = round( $smallest + ( ( $count - $min_count ) * $fontstep ), 1 ); 3270 $a[] = "<a href='$taglink' title='" . esc_attr( sprintf( __('%d topics'), $count ) ) . "' rel='tag' style='font-size:$fontsize$unit;'>$tag</a>"; 3271 } 3272 3273 switch ( $format ) : 3274 case 'array' : 3275 $r =& $a; 3276 break; 3277 case 'list' : 3278 $r = "<ul class='bb-tag-heat-map'>\n\t<li>"; 3279 $r .= join("</li>\n\t<li>", $a); 3280 $r .= "</li>\n</ul>\n"; 3281 break; 3282 default : 3283 $r = join("\n", $a); 3284 break; 3285 endswitch; 3286 3287 return apply_filters( 'bb_get_tag_heat_map', $r, $tags, $args ); 3288 } 3289 3290 function bb_sort_tag_heat_map( &$tag_counts ) { 3291 uksort($tag_counts, 'strnatcasecmp'); 3292 } 3293 3294 function tag_pages( $args = null ) 3295 { 3296 $defaults = array( 'before' => '', 'after' => '' ); 3297 $args = wp_parse_args( $args, $defaults ); 3298 3299 global $page, $tagged_topic_count; 3300 if ( $pages = apply_filters( 'tag_pages', get_page_number_links( $page, $tagged_topic_count ) ) ) { 3301 echo $args['before'] . $pages . $args['after']; 3302 } 3303 } 3304 3305 function bb_forum_dropdown( $args = '' ) { 3306 if ( $args && is_string($args) && false === strpos($args, '=') ) 3307 $args = array( 'callback' => $args ); 3308 if ( 1 < func_num_args() ) 3309 $args['callback_args'] = func_get_arg(1); 3310 echo bb_get_forum_dropdown( $args ); 3311 } 3312 3313 function bb_get_forum_dropdown( $args = '' ) { 3314 $defaults = array( 'callback' => false, 'callback_args' => false, 'id' => 'forum_id', 'none' => false, 'selected' => false, 'tab' => false, 'hierarchical' => 1, 'depth' => 0, 'child_of' => 0, 'disable_categories' => 1, 'options_only' => false ); 3315 if ( $args && is_string($args) && false === strpos($args, '=') ) 3316 $args = array( 'callback' => $args ); 3317 if ( 1 < func_num_args() ) 3318 $args['callback_args'] = func_get_arg(1); 3319 3320 $args = wp_parse_args( $args, $defaults ); 3321 3322 extract($args, EXTR_SKIP); 3323 3324 if ( !bb_forums( $args ) ) 3325 return; 3326 3327 global $forum_id, $forum; 3328 $old_global = $forum; 3329 3330 $name = esc_attr( $id ); 3331 $id = str_replace( '_', '-', $name ); 3332 $tab = (int) $tab; 3333 3334 if ( $none && 1 == $none ) 3335 $none = __('- None -'); 3336 3337 $r = ''; 3338 if ( !$options_only ) { 3339 if ( $tab ) { 3340 $tab = ' tabindex="' . $tab . '"'; 3341 } else { 3342 $tab = ''; 3343 } 3344 $r .= '<select name="' . $name . '" id="' . $id . '"' . $tab . '>' . "\n"; 3345 } 3346 if ( $none ) 3347 $r .= "\n" . '<option value="0">' . $none . '</option>' . "\n"; 3348 3349 $no_option_selected = true; 3350 $options = array(); 3351 while ( $depth = bb_forum() ) : 3352 global $forum; // Globals + References = Pain 3353 $pad_left = str_repeat( ' ', $depth - 1 ); 3354 if ( $disable_categories && isset($forum->forum_is_category) && $forum->forum_is_category ) { 3355 $options[] = array( 3356 'value' => 0, 3357 'display' => $pad_left . $forum->forum_name, 3358 'disabled' => true, 3359 'selected' => false 3360 ); 3361 continue; 3362 } 3363 $_selected = false; 3364 if ( (!$selected && $forum_id == $forum->forum_id) || $selected == $forum->forum_id ) { 3365 $_selected = true; 3366 $no_option_selected = false; 3367 } 3368 $options[] = array( 3369 'value' => $forum->forum_id, 3370 'display' => $pad_left . $forum->forum_name, 3371 'disabled' => false, 3372 'selected' => $_selected 3373 ); 3374 endwhile; 3375 3376 if ( 1 === count( $options ) && !$none ) { 3377 foreach ( $options as $option_index => $option_value ) { 3378 if ( $option_value['disabled'] ) { 3379 return; 3380 } 3381 return '<input type="hidden" name="' . $name . '" id="' . $id . '" value="' . esc_attr( $option_value['value'] ) . '" /><span>' . esc_html( $option_value['display'] ) . '</span>'; 3382 } 3383 } 3384 3385 foreach ($options as $option_index => $option_value) { 3386 if (!$none && !$selected && $no_option_selected && !$option_value['disabled']) { 3387 $option_value['selected'] = true; 3388 $no_option_selected = false; 3389 } 3390 $option_disabled = $option_value['disabled'] ? ' disabled="disabled"' : ''; 3391 $option_selected = $option_value['selected'] ? ' selected="selected"' : ''; 3392 $r .= "\n" . '<option value="' . esc_attr( $option_value['value'] ) . '"' . $option_disabled . $option_selected . '>' . esc_html( $option_value['display'] ) . '</option>' . "\n"; 3393 } 3394 3395 $forum = $old_global; 3396 if ( !$options_only ) 3397 $r .= '</select>' . "\n"; 3398 3399 return $r; 3400 } 3401 3402 //FAVORITES 3403 function favorites_link( $user_id = 0 ) { 3404 echo apply_filters( 'favorites_link', get_favorites_link( $user_id ) ); 3405 } 3406 3407 function get_favorites_link( $user_id = 0 ) { 3408 if ( !$user_id ) 3409 $user_id = bb_get_current_user_info( 'id' ); 3410 return apply_filters( 'get_favorites_link', get_profile_tab_link($user_id, 'favorites'), $user_id ); 3411 } 3412 3413 function user_favorites_link($add = array(), $rem = array(), $user_id = 0) { 3414 global $topic, $bb_current_user; 3415 if ( empty($add) || !is_array($add) ) 3416 $add = array('mid' => __('Add this topic to your favorites'), 'post' => __(' (%?%)')); 3417 if ( empty($rem) || !is_array($rem) ) 3418 $rem = array( 'pre' => __('This topic is one of your %favorites% ['), 'mid' => __('×'), 'post' => __(']')); 3419 if ( $user_id ) : 3420 if ( !bb_current_user_can( 'edit_favorites_of', (int) $user_id ) ) 3421 return false; 3422 if ( !$user = bb_get_user( bb_get_user_id( $user_id ) ) ) : 3423 return false; 3424 endif; 3425 else : 3426 if ( !bb_current_user_can('edit_favorites') ) 3427 return false; 3428 $user =& $bb_current_user->data; 3429 endif; 3430 3431 $url = esc_url( get_favorites_link( $user_id ) ); 3432 if ( $is_fav = is_user_favorite( $user->ID, $topic->topic_id ) ) : 3433 $rem = preg_replace('|%(.+)%|', "<a href='$url'>$1</a>", $rem); 3434 $favs = array('fav' => '0', 'topic_id' => $topic->topic_id); 3435 $pre = ( is_array($rem) && isset($rem['pre']) ) ? $rem['pre'] : ''; 3436 $mid = ( is_array($rem) && isset($rem['mid']) ) ? $rem['mid'] : ( is_string($rem) ? $rem : '' ); 3437 $post = ( is_array($rem) && isset($rem['post']) ) ? $rem['post'] : ''; 3438 elseif ( false === $is_fav ) : 3439 $add = preg_replace('|%(.+)%|', "<a href='$url'>$1</a>", $add); 3440 $favs = array('fav' => '1', 'topic_id' => $topic->topic_id); 3441 $pre = ( is_array($add) && isset($add['pre']) ) ? $add['pre'] : ''; 3442 $mid = ( is_array($add) && isset($add['mid']) ) ? $add['mid'] : ( is_string($add) ? $add : '' ); 3443 $post = ( is_array($add) && isset($add['post']) ) ? $add['post'] : ''; 3444 endif; 3445 3446 $url = esc_url( bb_nonce_url( add_query_arg( $favs, get_favorites_link( $user_id ) ), 'toggle-favorite_' . $topic->topic_id ) ); 3447 3448 if ( !is_null($is_fav) ) 3449 echo "<span id='favorite-$topic->topic_id'>$pre<a href='$url' class='dim:favorite-toggle:favorite-$topic->topic_id:is-favorite'>$mid</a>$post</span>"; 3450 } 3451 3452 function favorites_rss_link( $id = 0, $context = 0 ) { 3453 if (!$context || !is_integer($context)) { 3454 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3455 } 3456 echo apply_filters('favorites_rss_link', get_favorites_rss_link( $id, $context ), $context, $id); 3457 } 3458 3459 function get_favorites_rss_link( $id = 0, $context = 0 ) { 3460 $user = bb_get_user( bb_get_user_id( $id ) ); 3461 3462 if (!$context || !is_integer($context)) { 3463 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3464 } 3465 3466 $rewrite = bb_get_option( 'mod_rewrite' ); 3467 if ( $rewrite ) { 3468 if ( $rewrite === 'slugs' ) { 3469 $column = 'user_nicename'; 3470 } else { 3471 $column = 'ID'; 3472 } 3473 $link = bb_get_uri('rss/profile/' . $user->$column, null, $context); 3474 } else { 3475 $link = bb_get_uri('rss.php', array('profile' => $user->ID), $context); 3476 } 3477 return apply_filters( 'get_favorites_rss_link', $link, $user->ID, $context ); 3478 } 3479 3480 function favorites_pages( $args = null ) 3481 { 3482 $defaults = array( 'before' => '', 'after' => '' ); 3483 $args = wp_parse_args( $args, $defaults ); 3484 3485 global $page, $user, $favorites_total; 3486 if ( $pages = apply_filters( 'favorites_pages', get_page_number_links( $page, $favorites_total ), $user->user_id ) ) { 3487 echo $args['before'] . $pages . $args['after']; 3488 } 3489 } 3490 3491 //SUBSCRIPTION 3492 3493 /** 3494 * Checks if subscription is enabled. 3495 * 3496 * @since 1.1 3497 * 3498 * @return bool is subscription enabled or not 3499 */ 3500 function bb_is_subscriptions_active() { 3501 return (bool) bb_get_option( 'enable_subscriptions' ); 3502 } 3503 3504 /** 3505 * Checks if user is subscribed to current topic. 3506 * 3507 * @since 1.1 3508 * 3509 * @return bool is user subscribed or not 3510 */ 3511 function bb_is_user_subscribed( $args = null ) { 3512 global $bbdb; 3513 3514 $defaults = array( 3515 'user_id' => bb_get_current_user_info( 'id' ), 3516 'topic_id' => get_topic_id() 3517 ); 3518 $args = wp_parse_args( $args, $defaults ); 3519 extract( $args, EXTR_SKIP ); 3520 3521 $there = $bbdb->get_var( $bbdb->prepare( "SELECT `$bbdb->term_relationships`.`object_id` 3522 FROM $bbdb->term_relationships, $bbdb->term_taxonomy, $bbdb->terms 3523 WHERE `$bbdb->term_relationships`.`object_id` = %d 3524 AND `$bbdb->term_relationships`.`term_taxonomy_id` = `$bbdb->term_taxonomy`.`term_taxonomy_id` 3525 AND `$bbdb->term_taxonomy`.`term_id` = `$bbdb->terms`.`term_id` 3526 AND `$bbdb->term_taxonomy`.`taxonomy` = 'bb_subscribe' 3527 AND `$bbdb->terms`.`slug` = 'topic-%d'", 3528 $user_id, $topic_id ) ); 3529 3530 $there = apply_filters( 'bb_is_user_subscribed', $there, $args ); 3531 3532 if ( $there ) 3533 return true; 3534 3535 return false; 3536 } 3537 3538 /** 3539 * Outputs the subscribe/unsubscibe link. 3540 * 3541 * Checks if user is subscribed and outputs link based on status. 3542 * 3543 * @since 1.1 3544 */ 3545 function bb_user_subscribe_link() { 3546 $topic_id = get_topic_id(); 3547 3548 if ( !bb_is_user_logged_in() ) 3549 return false; 3550 3551 if ( bb_is_user_subscribed() ) 3552 echo '<li id="subscription-toggle"><a href="'. bb_nonce_url( bb_get_uri( null, array( 'doit' => 'bb-subscribe', 'topic_id' => $topic_id, 'and' => 'remove' ) ), 'toggle-subscribe_' . $topic_id ) .'">' . apply_filters( 'bb_user_subscribe_link_unsubscribe', __( 'Unsubscribe from Topic' ) ) . '</a></li>'; 3553 else 3554 echo '<li id="subscription-toggle"><a href="'. bb_nonce_url( bb_get_uri( null, array( 'doit' => 'bb-subscribe', 'topic_id' => $topic_id, 'and' => 'add' ) ), 'toggle-subscribe_' . $topic_id ) .'">' . apply_filters( 'bb_user_subscribe_link_subscribe', __( 'Subscribe to Topic' ) ) . '</a></li>'; 3555 3556 } 3557 3558 /** 3559 * Outputs the post form subscription checkbox. 3560 * 3561 * Checks if user is subscribed and outputs checkbox based on status. 3562 * 3563 * @since 1.1 3564 */ 3565 function bb_user_subscribe_checkbox( $args = null ) { 3566 3567 if ( !bb_is_user_logged_in() ) 3568 return false; 3569 3570 $defaults = array( 'tab' => false ); 3571 $args = wp_parse_args( $args, $defaults ); 3572 $tab = $args['tab'] !== false ? ' tabindex="' . $args['tab'] . '"' : ''; 3573 3574 echo ' 3575 <label for="subscription_checkbox"> 3576 <input name="subscription_checkbox" id="subscription_checkbox" type="checkbox" value="subscribe" ' . checked( true, bb_is_user_subscribed(), false ) . $tab . ' /> 3577 ' . apply_filters( 'bb_user_subscribe_checkbox_label', __( 'Notify me of followup posts via e-mail' ) ) . ' 3578 </label>'; 3579 3580 } 3581 3582 //VIEWS 3583 function view_name( $view = '' ) { // Filtration should be done at bb_register_view() 3584 echo get_view_name( $view ); 3585 } 3586 3587 function get_view_name( $_view = '' ) { 3588 global $view, $bb_views; 3589 if ( $_view ) 3590 $v = bb_slug_sanitize($_view); 3591 else 3592 $v =& $view; 3593 3594 if ( isset($bb_views[$v]) ) 3595 return $bb_views[$v]['title']; 3596 } 3597 3598 function view_pages() { 3599 global $page, $view_count; 3600 echo apply_filters( 'view_pages', get_page_number_links( $page, $view_count ) ); 3601 } 3602 3603 function view_link( $_view = false, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 3604 echo get_view_link( $_view, $page, $context ); 3605 } 3606 3607 function get_view_link( $_view = false, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 3608 global $view, $bb_views; 3609 if ( $_view ) 3610 $v = bb_slug_sanitize($_view); 3611 else 3612 $v =& $view; 3613 3614 if (!$context || !is_integer($context)) { 3615 $context = BB_URI_CONTEXT_A_HREF; 3616 } 3617 3618 if ( !array_key_exists($v, $bb_views) ) 3619 return bb_get_uri(null, null, $context); 3620 if ( bb_get_option('mod_rewrite') ) { 3621 $page = ( 1 < $page ) ? '/page/' . $page : ''; 3622 $link = bb_get_uri('view/' . $v . $page, null, $context); 3623 } else { 3624 $query = array( 3625 'view' => $v, 3626 'page' => ( 1 < $page ) ? $page : false, 3627 ); 3628 $link = bb_get_uri('view.php', $query, $context); 3629 } 3630 3631 return apply_filters( 'get_view_link', $link, $v, $page, $context ); 3632 } 3633 3634 function _bb_parse_time_function_args( $args ) { 3635 if ( is_numeric($args) ) 3636 $args = array('id' => $args); 3637 elseif ( $args && is_string($args) && false === strpos($args, '=') ) 3638 $args = array('format' => $args); 3639 3640 $defaults = array( 'id' => 0, 'format' => 'since', 'more' => 0, 'localize' => true ); 3641 return wp_parse_args( $args, $defaults ); 3642 } 3643 3644 function _bb_time_function_return( $time, $args ) { 3645 $time = bb_gmtstrtotime( $time ); 3646 3647 switch ( $format = $args['format'] ) : 3648 case 'since' : 3649 return bb_since( $time, $args['more'] ); 3650 break; 3651 case 'timestamp' : 3652 $format = 'U'; 3653 break; 3654 case 'mysql' : 3655 $format = 'Y-m-d H:i:s'; 3656 break; 3657 case 'datetime' : 3658 $format = bb_get_option( 'datetime_format' ); 3659 break; 3660 endswitch; 3661 3662 return $args['localize'] ? bb_gmdate_i18n( $format, $time ) : gmdate( $format, $time ); 3663 } 3664 3665 function bb_template_scripts() { 3666 if ( bb_is_topic() && bb_is_user_logged_in() ) 3667 wp_enqueue_script( 'topic' ); 3668 elseif ( bb_is_profile() && bb_is_user_logged_in() ) { 3669 global $self; 3670 if ($self == 'profile-edit.php') { 3671 wp_enqueue_script( 'profile-edit' ); 3672 } 3673 } 3674 } 3675 3676 if ( !function_exists( 'checked' ) ) : 3677 /** 3678 * Outputs the html checked attribute. 3679 * 3680 * Compares the first two arguments and if identical marks as checked 3681 * 3682 * @since 1.1 3683 * 3684 * @param mixed $checked One of the values to compare 3685 * @param mixed $current (true) The other value to compare if not just true 3686 * @param bool $echo Whether to echo or just return the string 3687 * @return string html attribute or empty string 3688 */ 3689 function checked( $checked, $current = true, $echo = true ) { 3690 return __checked_selected_helper( $checked, $current, $echo, 'checked' ); 3691 } 3692 endif; 3693 3694 if ( !function_exists( 'selected' ) ) : 3695 /** 3696 * Outputs the html selected attribute. 3697 * 3698 * Compares the first two arguments and if identical marks as selected 3699 * 3700 * @since 1.1 3701 * 3702 * @param mixed selected One of the values to compare 3703 * @param mixed $current (true) The other value to compare if not just true 3704 * @param bool $echo Whether to echo or just return the string 3705 * @return string html attribute or empty string 3706 */ 3707 function selected( $selected, $current = true, $echo = true ) { 3708 return __checked_selected_helper( $selected, $current, $echo, 'selected' ); 3709 } 3710 endif; 3711 3712 if ( !function_exists( 'disabled' ) ) : 3713 /** 3714 * Outputs the html disabled attribute. 3715 * 3716 * Compares the first two arguments and if identical marks as disabled 3717 * 3718 * @since 1.1 3719 * 3720 * @param mixed $disabled One of the values to compare 3721 * @param mixed $current (true) The other value to compare if not just true 3722 * @param bool $echo Whether to echo or just return the string 3723 * @return string html attribute or empty string 3724 */ 3725 function disabled( $disabled, $current = true, $echo = true ) { 3726 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); 3727 } 3728 endif; 3729 3730 if ( !function_exists( '__checked_selected_helper' ) ) : 3731 /** 3732 * Private helper function for checked, selected, and disabled. 3733 * 3734 * Compares the first two arguments and if identical marks as $type 3735 * 3736 * @since 1.1 3737 * @access private 3738 * 3739 * @param any $helper One of the values to compare 3740 * @param any $current (true) The other value to compare if not just true 3741 * @param bool $echo Whether to echo or just return the string 3742 * @param string $type The type of checked|selected|disabled we are doing 3743 * @return string html attribute or empty string 3744 */ 3745 function __checked_selected_helper( $helper, $current, $echo, $type ) { 3746 if ( (string) $helper === (string) $current ) 3747 $result = " $type='$type'"; 3748 else 3749 $result = ''; 3750 3751 if ( $echo ) 3752 echo $result; 3753 3754 return $result; 3755 } 3756 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Nov 15 04:45:27 2010 | Cross-referenced by PHPXref 0.7 |