| [ Index ] |
PHP Cross Reference of bbPress |
[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 if ( isset( $topic->topic_last_post_id ) && ( 1 == $topic->topic_last_post_id ) ) { 1211 $user_display_name = $topic->topic_poster_name; 1212 } else { 1213 $user_display_name = get_post_author( $topic->topic_last_post_id ); 1214 } 1215 return apply_filters( 'get_topic_last_poster', $user_display_name, $topic->topic_last_poster, $topic->topic_id ); // $topic->topic_last_poster = user ID 1216 } 1217 1218 function topic_author( $id = 0 ) { 1219 $topic = get_topic( get_topic_id( $id ) ); 1220 echo apply_filters( 'topic_author', get_topic_author( $id ), $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID 1221 } 1222 1223 function get_topic_author( $id = 0 ) { 1224 $topic = get_topic( get_topic_id( $id ) ); 1225 $first_post = bb_get_first_post( $topic ); 1226 if ( !empty( $first_post ) ) { 1227 $user_display_name = get_post_author( $first_post->post_id ); 1228 } else { 1229 $user_display_name = $topic->topic_poster_name; 1230 } 1231 return apply_filters( 'get_topic_author', $user_display_name, $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID 1232 } 1233 1234 // Filters expect the format to by mysql on both topic_time and get_topic_time 1235 function topic_time( $args = '' ) { 1236 $args = _bb_parse_time_function_args( $args ); 1237 $time = apply_filters( 'topic_time', get_topic_time( array('format' => 'mysql') + $args), $args ); 1238 echo _bb_time_function_return( $time, $args ); 1239 } 1240 1241 function get_topic_time( $args = '' ) { 1242 $args = _bb_parse_time_function_args( $args ); 1243 1244 $topic = get_topic( get_topic_id( $args['id'] ) ); 1245 1246 $time = apply_filters( 'get_topic_time', $topic->topic_time, $args ); 1247 1248 return _bb_time_function_return( $time, $args ); 1249 } 1250 1251 function topic_start_time( $args = '' ) { 1252 $args = _bb_parse_time_function_args( $args ); 1253 $time = apply_filters( 'topic_start_time', get_topic_start_time( array('format' => 'mysql') + $args), $args ); 1254 echo _bb_time_function_return( $time, $args ); 1255 } 1256 1257 function get_topic_start_time( $args = '' ) { 1258 $args = _bb_parse_time_function_args( $args ); 1259 1260 $topic = get_topic( get_topic_id( $args['id'] ) ); 1261 1262 $time = apply_filters( 'get_topic_start_time', $topic->topic_start_time, $args, $topic->topic_id ); 1263 1264 return _bb_time_function_return( $time, $args ); 1265 } 1266 1267 function topic_last_post_link( $id = 0 ) { 1268 echo apply_filters( 'topic_last_post_link', get_topic_last_post_link( $id ), $id); 1269 } 1270 1271 function get_topic_last_post_link( $id = 0 ){ 1272 $topic = get_topic( get_topic_id( $id ) ); 1273 $page = bb_get_page_number( $topic->topic_posts ); 1274 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 ); 1275 } 1276 1277 function topic_pages( $args = null ) 1278 { 1279 // Compatibility 1280 if ( $args && is_numeric( $args ) ) { 1281 $args = array( 'id' => $args ); 1282 } 1283 $defaults = array( 'id' => 0, 'before' => '', 'after' => '' ); 1284 $args = wp_parse_args( $args, $defaults ); 1285 1286 global $page; 1287 $topic = get_topic( get_topic_id( $args['id'] ) ); 1288 $add = topic_pages_add( $topic->topic_id ); 1289 if ( $pages = apply_filters( 'topic_pages', get_page_number_links( $page, $topic->topic_posts + $add ), $topic->topic_id ) ) { 1290 echo $args['before'] . $pages . $args['after']; 1291 } 1292 } 1293 1294 function topic_pages_add( $id = 0 ) { 1295 $topic = get_topic( get_topic_id( $id ) ); 1296 if ( isset($_GET['view']) && 'all' == $_GET['view'] && bb_current_user_can('browse_deleted') && isset( $topic->deleted_posts ) ) 1297 $add = $topic->deleted_posts; 1298 else 1299 $add = 0; 1300 return apply_filters( 'topic_pages_add', $add, isset($topic->topic_id) ? $topic->topic_id : 0 ); 1301 } 1302 1303 function get_page_number_links( $args ) { 1304 if ( 1 < func_num_args() ) { 1305 $_args = func_get_args(); 1306 $args = array( 1307 'page' => $_args[0], 1308 'total' => $_args[1], 1309 'per_page' => isset( $_args[2] ) ? $_args[2] : '', 1310 'mod_rewrite' => isset( $_args[3] ) ? $_args[3] : 'use_option' 1311 ); 1312 } 1313 $defaults = array( 1314 'page' => 1, 1315 'total' => false, 1316 'per_page' => '', 1317 'mod_rewrite' => 'use_option', 1318 'prev_text' => __( '« Previous' ), 1319 'next_text' => __( 'Next »' ) 1320 ); 1321 $args = wp_parse_args( $args, $defaults ); 1322 extract( $args, EXTR_SKIP ); 1323 1324 $add_args = array(); 1325 $uri = rtrim( $_SERVER['REQUEST_URI'], '?&' ); 1326 1327 if ( $mod_rewrite === 'use_option' ) { 1328 $mod_rewrite = bb_get_option( 'mod_rewrite' ); 1329 } 1330 1331 if ( $mod_rewrite ) { 1332 $format = '/page/%#%'; 1333 if ( 1 == $page ) { 1334 if ( false === $pos = strpos($uri, '?') ) 1335 $uri = $uri . '%_%'; 1336 else 1337 $uri = substr_replace($uri, '%_%', $pos, 0); 1338 } else { 1339 $uri = preg_replace('|/page/[0-9]+|', '%_%', $uri); 1340 } 1341 $uri = str_replace( '/%_%', '%_%', $uri ); 1342 } else { 1343 if ( 1 == $page ) { 1344 if ( false === $pos = strpos($uri, '?') ) { 1345 $uri = $uri . '%_%'; 1346 $format = '?page=%#%'; 1347 } else { 1348 $uri = substr_replace($uri, '?%_%', $pos, 1); 1349 $format = 'page=%#%&'; 1350 } 1351 } else { 1352 if ( false === strpos($uri, '?page=') ) { 1353 $uri = preg_replace('!&page=[0-9]+!', '%_%', $uri ); 1354 $uri = str_replace( '&page=', '', $uri ); 1355 $format = '&page=%#%'; 1356 } else { 1357 $uri = preg_replace('!\?page=[0-9]+!', '%_%', $uri ); 1358 $uri = str_replace( '?page=', '', $uri ); 1359 $format = '?page=%#%'; 1360 } 1361 } 1362 } 1363 1364 if ( isset($_GET['view']) && in_array($_GET['view'], bb_get_views()) ) 1365 $add_args['view'] = $_GET['view']; 1366 1367 if ( empty( $per_page ) ) { 1368 $per_page = bb_get_option( 'page_topics' ); 1369 } 1370 1371 $links = bb_paginate_links( array( 1372 'base' => $uri, 1373 'format' => $format, 1374 'total' => ceil( $total/$per_page ), 1375 'current' => $page, 1376 'add_args' => $add_args, 1377 'type' => 'array', 1378 'mid_size' => 1, 1379 'prev_text' => $prev_text, 1380 'next_text' => $next_text 1381 ) ); 1382 1383 if ($links) { 1384 $links = join('', $links); 1385 } 1386 return $links; 1387 } 1388 1389 function bb_topic_admin( $args = '' ) { 1390 $parts = array( 1391 'delete' => bb_get_topic_delete_link( $args ), 1392 'close' => bb_get_topic_close_link( $args ), 1393 'sticky' => bb_get_topic_sticky_link( $args ), 1394 'move' => bb_get_topic_move_dropdown( $args ) 1395 ); 1396 1397 echo join( "\n", apply_filters( 'bb_topic_admin', $parts, $args ) ); 1398 } 1399 1400 function topic_delete_link( $args = '' ) { 1401 echo bb_get_topic_delete_link( $args ); 1402 } 1403 1404 function bb_get_topic_delete_link( $args = '' ) { 1405 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'delete_text' => false, 'undelete_text' => false, 'redirect' => true ); 1406 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1407 $id = (int) $id; 1408 1409 $topic = get_topic( get_topic_id( $id ) ); 1410 1411 if ( !$topic || !bb_current_user_can( 'delete_topic', $topic->topic_id ) ) 1412 return; 1413 1414 if ( 0 == $topic->topic_status ) { 1415 if ( true === $redirect ) 1416 $redirect = add_query_arg( bb_is_admin() ? array() : array( 'view' => 'all' ) ); 1417 1418 $query = array( 'id' => $topic->topic_id, '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false ); 1419 $confirm = __('Are you sure you want to delete that?'); 1420 $display = esc_html( $delete_text ? $delete_text : __('Delete entire topic') ); 1421 } else { 1422 if ( true === $redirect ) 1423 $redirect = remove_query_arg( bb_is_admin() ? array() : 'view' ); 1424 1425 $query = array('id' => $topic->topic_id, 'view' => 'all', '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false ); 1426 $confirm = __('Are you sure you want to undelete that?'); 1427 $display = esc_html( $undelete_text ? $undelete_text : __('Undelete entire topic') ); 1428 } 1429 $uri = bb_get_uri('bb-admin/delete-topic.php', $query, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 1430 $uri = esc_url( bb_nonce_url( $uri, 'delete-topic_' . $topic->topic_id ) ); 1431 1432 return $before . '<a href="' . $uri . '" onclick="return confirm(\'' . esc_js( $confirm ) . '\');">' . $display . '</a>' . $after; 1433 } 1434 1435 function topic_close_link( $args = '' ) { 1436 echo bb_get_topic_close_link( $args ); 1437 } 1438 1439 function bb_get_topic_close_link( $args = '' ) { 1440 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'close_text' => false, 'open_text' => false, 'redirect' => true ); 1441 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1442 $id = (int) $id; 1443 1444 $topic = get_topic( get_topic_id( $id ) ); 1445 1446 if ( !$topic || !bb_current_user_can( 'close_topic', $topic->topic_id ) ) 1447 return; 1448 1449 if ( topic_is_open( $topic->topic_id ) ) 1450 $display = esc_html( $close_text ? $close_text : __( 'Close topic' ) ); 1451 else 1452 $display = esc_html( $open_text ? $open_text : __( 'Open topic' ) ); 1453 1454 if ( true === $redirect ) 1455 $redirect = $_SERVER['REQUEST_URI']; 1456 1457 $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); 1458 $uri = esc_url( bb_nonce_url( $uri, 'close-topic_' . $topic->topic_id ) ); 1459 1460 return $before . '<a href="' . $uri . '">' . $display . '</a>' . $after; 1461 } 1462 1463 function topic_sticky_link( $args = '' ) { 1464 echo bb_get_topic_sticky_link( $args ); 1465 } 1466 1467 function bb_get_topic_sticky_link( $args = '' ) { 1468 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' ); 1469 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1470 $id = (int) $id; 1471 1472 $topic = get_topic( get_topic_id( $id ) ); 1473 1474 if ( !$topic || !bb_current_user_can( 'stick_topic', $topic->topic_id ) ) 1475 return; 1476 1477 $uri_stick = bb_get_uri('bb-admin/sticky.php', array('id' => $topic->topic_id), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 1478 $uri_stick = esc_url( bb_nonce_url( $uri_stick, 'stick-topic_' . $topic->topic_id ) ); 1479 1480 $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); 1481 $uri_super = esc_url( bb_nonce_url( $uri_super, 'stick-topic_' . $topic->topic_id ) ); 1482 1483 if ( topic_is_sticky( $topic->topic_id ) ) 1484 return "$before<a href='" . $uri_stick . "'>". __('Unstick topic') ."</a>$after"; 1485 else 1486 return "$before<a href='" . $uri_stick . "'>". __('Stick topic') . "</a> (<a href='" . $uri_super . "'>" . __('to front') . "</a>)$after"; 1487 } 1488 1489 function topic_show_all_link( $id = 0 ) { 1490 if ( !bb_current_user_can( 'browse_deleted' ) ) 1491 return; 1492 if ( 'all' == @$_GET['view'] ) 1493 echo "<a href='" . esc_attr( get_topic_link( $id ) ) . "'>". __('View normal posts') ."</a>"; 1494 else 1495 echo "<a href='" . esc_attr( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>". __('View all posts') ."</a>"; 1496 } 1497 1498 function topic_posts_link( $id = 0 ) { 1499 echo get_topic_posts_link( $id ); 1500 } 1501 1502 function get_topic_posts_link( $id = 0 ) { 1503 $topic = get_topic( get_topic_id( $id ) ); 1504 $post_num = get_topic_posts( $id ); 1505 $posts = sprintf(__ngettext( '%s post', '%s posts', $post_num ), $post_num); 1506 $r = ''; 1507 1508 if ( ( 'all' == @$_GET['view'] || bb_is_admin() ) && bb_current_user_can('browse_deleted') ) 1509 $r .= "<a href='" . esc_attr( get_topic_link( $id ) ) . "'>$posts</a>"; 1510 else 1511 $r .= $posts; 1512 1513 if ( bb_current_user_can( 'browse_deleted' ) ) { 1514 $user_id = bb_get_current_user_info( 'id' ); 1515 if ( isset($topic->bozos[$user_id]) && 'all' != @$_GET['view'] ) 1516 add_filter('get_topic_deleted_posts', create_function('$a', "\$a -= {$topic->bozos[$user_id]}; return \$a;") ); 1517 if ( $deleted = get_topic_deleted_posts( $id ) ) { 1518 $extra = sprintf(__('+%d more'), $deleted); 1519 if ( 'all' == @$_GET['view'] ) 1520 $r .= " $extra"; 1521 else 1522 $r .= " <a href='" . esc_attr( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>$extra</a>"; 1523 } 1524 } 1525 1526 return $r; 1527 } 1528 1529 function topic_move_dropdown( $args = '' ) 1530 { 1531 echo bb_get_topic_move_dropdown( $args ); 1532 } 1533 1534 function bb_get_topic_move_dropdown( $args = '' ) 1535 { 1536 if ( $args && is_numeric( $args ) ) { 1537 $args = array( 'id' => (integer) $args ); 1538 } 1539 1540 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' ); 1541 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 1542 $id = (int) $id; 1543 1544 $topic = get_topic( get_topic_id( $id ) ); 1545 if ( !bb_current_user_can( 'move_topic', $topic->topic_id ) ) 1546 return; 1547 1548 $dropdown = bb_get_forum_dropdown( array( 1549 'callback' => 'bb_current_user_can', 1550 'callback_args' => array('move_topic', $topic->topic_id), 1551 'selected' => $topic->forum_id, 1552 'tab' => false 1553 ) ); 1554 1555 if ( !$dropdown ) 1556 return; 1557 1558 $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"; 1559 $r .= '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "\n"; 1560 $r .= '<label for="forum-id">'. __( 'Move to' ) . '</label>' . "\n"; 1561 $r .= $dropdown . "\n"; 1562 $r .= bb_nonce_field( 'move-topic_' . $topic->topic_id, '_wpnonce', true , false ); 1563 $r .= '<input type="submit" name="Submit" value="' . __( 'Move' ) . '" />' . "\n"; 1564 $r .= '</div></fieldset></form>' . $after; 1565 1566 return $r; 1567 } 1568 1569 function topic_class( $class = '', $key = 'topic', $id = 0 ) { 1570 $topic = get_topic( get_topic_id( $id ) ); 1571 $class = $class ? explode(' ', $class ) : array(); 1572 if ( '1' === $topic->topic_status && bb_current_user_can( 'browse_deleted' ) ) 1573 $class[] = 'deleted'; 1574 elseif ( 1 < $topic->topic_status && bb_current_user_can( 'browse_deleted' ) ) 1575 $class[] = 'bozo'; 1576 if ( '0' === $topic->topic_open ) 1577 $class[] = 'closed'; 1578 if ( 1 == $topic->topic_sticky && ( bb_is_forum() || bb_is_view() ) ) 1579 $class[] = 'sticky'; 1580 elseif ( 2 == $topic->topic_sticky && ( bb_is_front() || bb_is_forum() || bb_is_view() ) ) 1581 $class[] = 'sticky super-sticky'; 1582 $class = apply_filters( 'topic_class', $class, $topic->topic_id ); 1583 $class = join(' ', $class); 1584 alt_class( $key, $class ); 1585 } 1586 1587 /** 1588 * bb_get_new_topic_link() - Get the link to the form for a new topic 1589 * 1590 * @since 1.0 1591 * @param mixed The arguments for this function. 1592 * @return string The link to the new topic form 1593 */ 1594 function bb_get_new_topic_link( $args = null ) { 1595 $defaults = array( 'text' => __('Add New »'), 'forum' => 0, 'tag' => '' ); 1596 if ( $args && is_string($args) && false === strpos($args, '=') ) 1597 $args = array( 'text' => $args ); 1598 1599 $args = wp_parse_args( $args, $defaults ); 1600 extract( $args, EXTR_SKIP ); 1601 1602 if ( $forum && $forum = bb_get_forum( $forum ) ) 1603 $url = get_forum_link( $forum->forum_id ) . '#postform'; 1604 elseif ( $tag && $tag = bb_get_tag( $tag ) ) 1605 $url = bb_get_tag_link( $tag->tag ) . '#postform'; 1606 elseif ( bb_is_forum() ) { 1607 global $forum; 1608 $url = get_forum_link( $forum->forum_id ) . '#postform'; 1609 } elseif ( bb_is_tag() ) { 1610 global $tag; 1611 $url = bb_get_tag_link( $tag ) . '#postform'; 1612 } elseif ( bb_is_topic() ) 1613 $url = get_forum_link() . '#postform'; 1614 elseif ( bb_is_front() ) 1615 $url = bb_get_uri(null, array('new' => 1)); 1616 1617 if ( !bb_is_user_logged_in() && bb_is_login_required() ) 1618 $url = bb_get_uri('bb-login.php', array('redirect_to' => $url), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS); 1619 elseif ( bb_is_forum() || bb_is_topic() ) { 1620 if ( !bb_current_user_can( 'write_topic', get_forum_id() ) ) 1621 return; 1622 } else { 1623 if ( !bb_current_user_can( 'write_topics' ) ) 1624 return; 1625 } 1626 1627 if ( $url = esc_attr( apply_filters( 'new_topic_url', $url, $args ) ) ) 1628 return '<a href="' . $url . '" class="new-topic">' . $text . '</a>' . "\n"; 1629 } 1630 1631 function bb_new_topic_link( $args = null ) { 1632 echo bb_get_new_topic_link($args); 1633 } 1634 1635 function bb_new_topic_forum_dropdown( $args = '' ) { 1636 if ( !is_array( $args ) ) { 1637 $args = array( 1638 'callback' => 'bb_current_user_can', 1639 'callback_args' => array( 'write_topic' ) 1640 ); 1641 } 1642 if ( !isset( $args['callback'] ) && !isset( $args['callback_args'] ) ) { 1643 $args['callback'] = 'bb_current_user_can'; 1644 $args['callback_args'] = array( 'write_topic' ); 1645 } 1646 bb_forum_dropdown( $args ); 1647 } 1648 1649 function bb_topic_search_form( $args = null, $query_obj = null ) { 1650 global $bb_query_form; 1651 1652 if ( $query_obj && is_a($query_obj, 'BB_Query_Form') ); // [sic] 1653 else 1654 $query_obj =& $bb_query_form; 1655 1656 $query_obj->form( $args ); 1657 } 1658 1659 function bb_search_pages( $args = null ) { 1660 global $page, $search_count, $per_page; 1661 1662 $defaults = array( 'before' => '', 'after' => '' ); 1663 $args = wp_parse_args( $args, $defaults ); 1664 1665 if ( $pages = apply_filters( 'bb_search_pages', get_page_number_links( array( 'page' => $page, 'total' => $search_count, 'per_page' => $per_page, 'mod_rewrite' => false ) ) ) ) 1666 echo $args['before'] . $pages . $args['after']; 1667 } 1668 1669 /** 1670 * bb_topic_pagecount() - Print the total page count for a topic 1671 * 1672 * @since 0.9 1673 * @param int $topic_id The topic id of the topic being queried 1674 * @return void 1675 */ 1676 function bb_topic_pagecount( $topic_id = 0 ) { 1677 echo bb_get_topic_pagecount( $topic_id ); 1678 } 1679 1680 /** 1681 * bb_get_topic_pagecount() - Get the total page count for a topic 1682 * 1683 * @since 0.9 1684 * @param int $topic_id The topic id of the topic being queried 1685 * @return int The total number of pages in the topic 1686 */ 1687 function bb_get_topic_pagecount( $topic_id = 0 ) { 1688 $topic = get_topic( get_topic_id( $topic_id ) ); 1689 return bb_get_page_number( $topic->topic_posts + topic_pages_add() ); 1690 } 1691 1692 /** 1693 * bb_is_topic_lastpage() - Report whether the current page is the last page of a given topic 1694 * 1695 * @since 0.9 1696 * @param int $topic_id The topic id of the topic being queried 1697 * @return boolean True if called on the last page of a topic, otherwise false 1698 */ 1699 function bb_is_topic_lastpage( $topic_id = 0 ) { 1700 global $page; 1701 return ( $page == bb_get_topic_pagecount( $topic_id ) ); 1702 } 1703 1704 // POSTS 1705 1706 function post_id( $post_id = 0 ) { 1707 echo get_post_id( $post_id ); 1708 } 1709 1710 function get_post_id( $post_id = 0 ) { 1711 global $bb_post; 1712 $post_id = (int) $post_id; 1713 if ( $post_id ) 1714 $post = bb_get_post( $post_id ); 1715 else 1716 $post =& $bb_post; 1717 return $post->post_id; 1718 } 1719 1720 function post_link( $post_id = 0 ) { 1721 echo apply_filters( 'post_link', get_post_link( $post_id ), get_post_id( $post_id ) ); 1722 } 1723 1724 function get_post_link( $post_id = 0 ) { 1725 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1726 $page = bb_get_page_number( $bb_post->post_position ); 1727 return apply_filters( 'get_post_link', get_topic_link( $bb_post->topic_id, $page ) . "#post-$bb_post->post_id", $bb_post->post_id ); 1728 } 1729 1730 function post_anchor_link( $force_full = false ) { 1731 if ( defined('DOING_AJAX') || $force_full ) 1732 post_link(); 1733 else 1734 echo '#post-' . get_post_id(); 1735 } 1736 1737 function post_position( $post_id = 0 ) { 1738 echo apply_filters( 'post_position', get_post_position( $post_id ), get_post_id( $post_id ) ); 1739 } 1740 1741 function get_post_position( $post_id = 0 ) { 1742 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1743 return apply_filters( 'get_post_position', $bb_post->post_position, $bb_post->post_id ); 1744 } 1745 1746 function post_position_link( $topic_id = 0, $position = 1 ) { 1747 echo apply_filters( 'post_position_link', get_post_position_link( $topic_id, $position ), get_topic_id( $topic_id ), (integer) $position ); 1748 } 1749 1750 function get_post_position_link( $topic_id = 0, $position = 1 ) { 1751 $position = (integer) $position; 1752 $bb_topic = get_topic( get_topic_id( $topic_id ) ); 1753 if ( $bb_topic->topic_posts < $position ) { 1754 return; 1755 } 1756 $page = bb_get_page_number( $position ); 1757 return apply_filters( 'get_post_position_link', get_topic_link( $bb_post->topic_id, $page ) . "#position-$position", $bb_topic->topic_id, $position ); 1758 } 1759 1760 function bb_post_meta( $key, $post_id = 0 ) { 1761 echo bb_get_post_meta( $key, $post_id ); 1762 } 1763 1764 function bb_get_post_meta( $key, $post_id = 0 ) { 1765 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1766 if ( isset($bb_post->$key) ) 1767 return $bb_post->$key; 1768 } 1769 1770 1771 function post_author( $post_id = 0 ) { 1772 echo apply_filters('post_author', get_post_author( $post_id ), $post_id ); 1773 } 1774 1775 function get_post_author( $post_id = 0 ) { 1776 if ( $user = bb_get_user( get_post_author_id( $post_id ) ) ) 1777 return apply_filters( 'get_post_author', $user->display_name, $user->ID, $post_id ); 1778 elseif ( $title = bb_get_post_meta( 'pingback_title', $post_id ) ) 1779 return apply_filters( 'bb_get_pingback_title', $title, $post_id ); 1780 elseif ( $title = bb_get_post_meta( 'post_author', $post_id ) ) 1781 return apply_filters( 'get_post_author', $title, 0, $post_id ); 1782 else 1783 return apply_filters( 'get_post_author', __('Anonymous'), 0, $post_id ); 1784 } 1785 1786 function post_author_link( $post_id = 0 ) { 1787 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 ) ) ) ) { 1788 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1789 } elseif ( $link = bb_get_post_meta( 'pingback_uri' )) { 1790 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1791 } elseif ( $link = bb_get_post_meta( 'post_url' ) ) { 1792 echo '<a href="' . esc_attr( $link ) . '">' . get_post_author( $post_id ) . '</a>'; 1793 } else { 1794 post_author( $post_id ); 1795 } 1796 } 1797 1798 function post_author_avatar( $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 echo bb_get_avatar( $author_id, $size, $default ); 1804 } 1805 1806 function post_author_avatar_link( $size = '48', $default = '', $post_id = 0 ) { 1807 if ( ! bb_get_option('avatars_show') ) 1808 return false; 1809 1810 $author_id = get_post_author_id( $post_id ); 1811 if ( $link = get_user_link( $author_id ) ) { 1812 echo '<a href="' . esc_attr( $link ) . '">' . bb_get_avatar( $author_id, $size, $default ) . '</a>'; 1813 } else { 1814 echo bb_get_avatar( $author_id, $size, $default ); 1815 } 1816 } 1817 1818 function post_text( $post_id = 0 ) { 1819 echo apply_filters( 'post_text', get_post_text( $post_id ), get_post_id( $post_id ) ); 1820 } 1821 1822 function get_post_text( $post_id = 0 ) { 1823 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1824 return apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id ); 1825 } 1826 1827 function bb_post_time( $args = '' ) { 1828 $args = _bb_parse_time_function_args( $args ); 1829 $time = apply_filters( 'bb_post_time', bb_get_post_time( array('format' => 'mysql') + $args ), $args ); 1830 echo _bb_time_function_return( $time, $args ); 1831 } 1832 1833 function bb_get_post_time( $args = '' ) { 1834 $args = _bb_parse_time_function_args( $args ); 1835 1836 $bb_post = bb_get_post( get_post_id( $args['id'] ) ); 1837 1838 $time = apply_filters( 'bb_get_post_time', $bb_post->post_time, $args ); 1839 1840 return _bb_time_function_return( $time, $args ); 1841 } 1842 1843 function post_ip( $post_id = 0 ) { 1844 if ( bb_current_user_can( 'view_by_ip' ) ) 1845 echo apply_filters( 'post_ip', get_post_ip( $post_id ), get_post_id( $post_id ) ); 1846 } 1847 1848 function get_post_ip( $post_id = 0 ) { 1849 $bb_post = bb_get_post( get_post_id( $post_id ) ); 1850 return apply_filters( 'get_post_ip', $bb_post->poster_ip, $bb_post->post_id ); 1851 } 1852 1853 function bb_post_admin( $args = null ) 1854 { 1855 $defaults = array( 1856 'post_id' => 0, 1857 'before' => '', 1858 'after' => '', 1859 'before_each' => '', 1860 'after_each' => "\n", 1861 'each' => array( 1862 'ip' => array( 1863 'post_id' => 0 1864 ), 1865 'edit' => array( 1866 'post_id' => 0 1867 ), 1868 'delete' => array( 1869 'post_id' => 0 1870 ), 1871 'undelete' => array( 1872 'post_id' => 0 1873 ) 1874 ) 1875 ); 1876 if ( isset( $args['each'] ) ) { 1877 $each_args = $args['each']; 1878 $_each_args = $defaults['each']; 1879 foreach ( $each_args as $_part_name => $_part_args ) { 1880 if ( !isset( $defaults['each'][$_part_name] ) ) { 1881 continue; 1882 } 1883 $_each_args[$_part_name] = wp_parse_args( $_part_args, $defaults['each'][$_part_name] ); 1884 } 1885 } 1886 $args = wp_parse_args( $args, $defaults ); 1887 if ( isset( $_each_args ) ) { 1888 $args['each'] = $_each_args; 1889 } 1890 1891 $parts = array(); 1892 if ( is_array( $args['each'] ) && count( $args['each'] ) ) { 1893 foreach ( $args['each'] as $_part_name => $_part_args ) { 1894 if ( $args['post_id'] && !$_part_args['post_id'] ) { 1895 $_part_args['post_id'] = $args['post_id']; 1896 } 1897 if ( $args['before_each'] && !$_part_args['before'] ) { 1898 $_part_args['before'] = $args['before_each']; 1899 } 1900 if ( $args['after_each'] && !$_part_args['after'] ) { 1901 $_part_args['after'] = $args['after_each']; 1902 } 1903 $_part_function = 'bb_get_post_' . $_part_name . '_link'; 1904 $parts[$_part_name] = $_part_function( $_part_args ); 1905 } 1906 1907 // For the benefit of filters, mark the final part 1908 if ( !isset( $args['last_each'] ) ) { 1909 $args['last_each'] = $_part_args; 1910 } 1911 } 1912 1913 $parts = apply_filters( 'bb_post_admin', $parts, $args ); 1914 1915 if ( !count( $parts ) ) { 1916 return; 1917 } 1918 1919 echo $args['before'] . join( '', $parts ) . $args['after']; 1920 } 1921 1922 function post_ip_link( $args = null ) 1923 { 1924 echo bb_get_post_ip_link( $args ); 1925 } 1926 1927 function bb_get_post_ip_link( $args = null ) 1928 { 1929 if ( !bb_current_user_can( 'view_by_ip' ) ) { 1930 return; 1931 } 1932 1933 $defaults = array( 1934 'post_id' => 0, 1935 'before' => '', 1936 'after' => '', 1937 'text' => '%s' 1938 ); 1939 if ( is_numeric( $args ) ) { 1940 $args = array( 'post_id' => $args ); 1941 } 1942 $args = wp_parse_args( $args, $defaults ); 1943 1944 $bb_post = bb_get_post( get_post_id( $args['post_id'] ) ); 1945 1946 $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 ); 1947 1948 // Make sure that the last tag in $before gets a class (if it's there) 1949 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $args['before'], $_node ) ) { 1950 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 1951 $args['before'] = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-ip-link ' . $_class[2] . $_class[1], $args['before'] ); 1952 } else { 1953 $args['before'] = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-ip-link"$3$4>$5', $args['before'], 1 ); 1954 } 1955 } 1956 1957 $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']; 1958 return apply_filters( 'post_ip_link', $link, $bb_post->post_id, $args ); 1959 } 1960 1961 function post_edit_link( $args = null ) 1962 { 1963 echo bb_get_post_edit_link( $args ); 1964 } 1965 1966 function bb_get_post_edit_link( $args = null ) 1967 { 1968 $defaults = array( 1969 'post_id' => 0, 1970 'before' => '', 1971 'after' => '', 1972 'text' => __( 'Edit' ) 1973 ); 1974 if ( is_numeric( $args ) ) { 1975 $args = array( 'post_id' => $args ); 1976 } 1977 $args = wp_parse_args( $args, $defaults ); 1978 1979 $bb_post = bb_get_post( get_post_id( $args['post_id'] ) ); 1980 1981 if ( bb_current_user_can( 'edit_post', $bb_post->post_id ) ) { 1982 $uri = bb_get_uri( 'edit.php', array( 'id' => $bb_post->post_id ) ); 1983 1984 // Make sure that the last tag in $before gets a class (if it's there) 1985 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $args['before'], $_node ) ) { 1986 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 1987 $args['before'] = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-edit-link ' . $_class[2] . $_class[1], $args['before'] ); 1988 } else { 1989 $args['before'] = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-edit-link"$3$4>$5', $args['before'], 1 ); 1990 } 1991 } 1992 1993 $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']; 1994 return apply_filters( 'bb_get_post_edit_link', $r, $bb_post->post_id, $args ); 1995 } 1996 } 1997 1998 function post_del_class( $post_id = 0 ) 1999 { 2000 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2001 $classes = array(); 2002 if ( bb_get_post_meta( 'pingback_uri', $post_id ) ) { 2003 $classes[] = 'pingback'; 2004 } 2005 if ( $bb_post->post_status == 1 ) { 2006 $classes[] = 'deleted'; 2007 } elseif ( $bb_post->post_status != 0 ) { 2008 $classes[] = 'post-status-' . $bb_post->post_status; 2009 } 2010 if ( count( $classes ) ) { 2011 $classes = join( ' ', $classes ); 2012 } else { 2013 $classes = ''; 2014 } 2015 return apply_filters( 'post_del_class', $classes, $bb_post->post_id, $bb_post ); 2016 } 2017 2018 function post_delete_link( $args = null ) 2019 { 2020 echo bb_get_post_delete_link( $args ); 2021 } 2022 2023 function bb_get_post_delete_link( $args = null ) 2024 { 2025 $defaults = array( 2026 'post_id' => 0, 2027 'before' => '', 2028 'after' => '', 2029 'text' => __( 'Delete' ), 2030 'redirect' => true 2031 ); 2032 if ( is_numeric( $args ) || is_object( $args ) ) { 2033 $args = array( 'post_id' => $args ); 2034 } 2035 if ( isset( $args['delete_text'] ) && ( !isset( $args['text'] ) || !$args['text'] ) ) { 2036 $args['text'] = $args['delete_text']; 2037 } 2038 2039 $args = wp_parse_args( $args, $defaults ); 2040 extract( $args, EXTR_SKIP ); 2041 2042 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2043 //if ( bb_is_first( $bb_post->post_id ) ) { 2044 // $topic = get_topic( $bb_post->topic_id ); 2045 // if ( 2 > $topic->topic_posts ) { 2046 // Should delete the whole topic 2047 // return; 2048 // } 2049 //} 2050 2051 if ( !bb_current_user_can( 'delete_post', $bb_post->post_id ) ) { 2052 return; 2053 } 2054 2055 if ( true === $redirect ) { 2056 $redirect = $_SERVER['REQUEST_URI']; 2057 } 2058 2059 $uri = bb_get_uri('bb-admin/delete-post.php', array( 2060 'id' => $bb_post->post_id, 2061 'status' => 1, 2062 '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false 2063 ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 2064 $uri = esc_url( bb_nonce_url( $uri, 'delete-post_' . $bb_post->post_id ) ); 2065 2066 if ( ( bb_is_admin() || isset( $_GET['view'] ) && 'all' == $_GET['view'] ) ) { 2067 $ajax_class = 'dim:thread:post-' . $bb_post->post_id . ':deleted:FF3333:FFFF33:action=delete-post&status=1'; 2068 } else { 2069 $ajax_class = 'delete:thread:post-' . $bb_post->post_id . '::status=1'; 2070 } 2071 2072 $text = esc_html( $text ); 2073 2074 // Make sure that the last tag in $before gets a class (if it's there) 2075 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $before, $_node ) ) { 2076 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 2077 $before = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-delete-link ' . $_class[2] . $_class[1], $before ); 2078 } else { 2079 $before = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-delete-link"$3$4>$5', $before, 1 ); 2080 } 2081 } 2082 2083 $r = $before . '<a href="' . $uri . '" class="' . $ajax_class . ' post-delete-link">' . $text . '</a>' . $after; 2084 $r = apply_filters( 'post_delete_link', $r, $bb_post->post_status, $bb_post->post_id, $args ); 2085 return $r; 2086 } 2087 2088 function bb_post_undelete_link( $args = null ) 2089 { 2090 echo bb_get_post_undelete_link( $args ); 2091 } 2092 2093 function bb_get_post_undelete_link( $args = null ) 2094 { 2095 $defaults = array( 2096 'post_id' => 0, 2097 'before' => '', 2098 'after' => '', 2099 'text' => __( 'Undelete' ), 2100 'redirect' => true 2101 ); 2102 if ( is_numeric( $args ) || is_object( $args ) ) { 2103 $args = array( 'post_id' => $args ); 2104 } 2105 2106 $args = wp_parse_args( $args, $defaults ); 2107 extract( $args, EXTR_SKIP ); 2108 2109 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2110 2111 if ( !bb_current_user_can( 'delete_post', $bb_post->post_id ) ) { 2112 return; 2113 } 2114 2115 if ( true === $redirect ) { 2116 $redirect = $_SERVER['REQUEST_URI']; 2117 } 2118 2119 $uri = bb_get_uri('bb-admin/delete-post.php', array( 2120 'id' => $bb_post->post_id, 2121 'status' => 0, 2122 'view' => 'all', 2123 '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false 2124 ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 2125 $uri = esc_url( bb_nonce_url( $uri, 'delete-post_' . $bb_post->post_id ) ); 2126 2127 $ajax_class = 'dim:thread:post-' . $bb_post->post_id . ':deleted:FF3333:FFFF33:action=delete-post&status=0'; 2128 2129 $text = esc_html( $text ); 2130 2131 // Make sure that the last tag in $before gets a class (if it's there) 2132 if ( preg_match( '/.*(<[^>]+>)[^<]*/', $before, $_node ) ) { 2133 if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) { 2134 $before = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-undelete-link ' . $_class[2] . $_class[1], $before ); 2135 } else { 2136 $before = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-undelete-link"$3$4>$5', $before, 1 ); 2137 } 2138 } 2139 2140 $r = $before . '<a href="' . $uri . '" class="' . $ajax_class . ' post-undelete-link">' . $text . '</a>' . $after; 2141 $r = apply_filters( 'post_undelete_link', $r, $bb_post->post_status, $bb_post->post_id, $args ); 2142 return $r; 2143 } 2144 2145 function post_author_id( $post_id = 0 ) { 2146 echo apply_filters( 'post_author_id', get_post_author_id( $post_id ), get_post_id( $post_id ) ); 2147 } 2148 2149 function get_post_author_id( $post_id = 0 ) { 2150 $bb_post = bb_get_post( get_post_id( $post_id ) ); 2151 return apply_filters( 'get_post_author_id', (int) $bb_post->poster_id, get_post_id( $post_id ) ); 2152 } 2153 2154 function post_author_title( $post_id = 0 ) { 2155 echo apply_filters( 'post_author_title', get_post_author_title( $post_id ), get_post_id( $post_id ) ); 2156 } 2157 2158 function get_post_author_title( $post_id = 0 ) { 2159 return get_user_title( get_post_author_id( $post_id ) ); 2160 } 2161 2162 function post_author_title_link( $post_id = 0 ) { 2163 echo apply_filters( 'post_author_title_link', get_post_author_title_link( $post_id ), get_post_id( $post_id ) ); 2164 } 2165 2166 function get_post_author_title_link( $post_id = 0 ) { 2167 $title = get_post_author_title( $post_id ); 2168 if ( false === $title ) { 2169 if ( bb_get_post_meta( 'pingback_uri', $post_id ) ) 2170 $r = __('PingBack'); 2171 else 2172 $r = __('Unregistered'); // This should never happen 2173 } else { 2174 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 ) ) ) 2175 $r = '<a href="' . esc_attr( $link ) . '">' . $title . '</a>'; 2176 else 2177 $r = $title; 2178 } 2179 2180 return apply_filters( 'get_post_author_title_link', $r, get_post_id( $post_id ) ); 2181 } 2182 2183 function post_author_type( $post_id = 0 ) { 2184 $id = get_post_author_id( $post_id ); 2185 $type = get_user_type( $id ); 2186 if ( false === $type ) { 2187 if ( bb_get_post_meta( 'pingback_uri', $post_id ) ) 2188 $r = __('PingBack'); 2189 else 2190 $r = __('Unregistered'); // This should never happen 2191 } else 2192 $r = '<a href="' . esc_attr( get_user_profile_link( $id ) ) . '">' . $type . '</a>'; 2193 2194 echo apply_filters( 'post_author_type', $r, $post_id ); 2195 } 2196 2197 function allowed_markup( $args = '' ) { 2198 echo apply_filters( 'allowed_markup', get_allowed_markup( $args ) ); 2199 } 2200 2201 // format=list or array( 'format' => 'list' ) 2202 function get_allowed_markup( $args = '' ) { 2203 $args = wp_parse_args( $args, array('format' => 'flat') ); 2204 extract($args, EXTR_SKIP); 2205 2206 $tags = bb_allowed_tags(); 2207 unset($tags['pre'], $tags['br']); 2208 $tags = array_keys($tags); 2209 2210 switch ( $format ) : 2211 case 'array' : 2212 $r = $tags; 2213 break; 2214 case 'list' : 2215 $r = "<ul class='allowed-markup'>\n\t<li>"; 2216 $r .= join("</li>\n\t<li>", $tags); 2217 $r .= "</li>\n</ul>\n"; 2218 break; 2219 default : 2220 $r = join(' ', $tags); 2221 break; 2222 endswitch; 2223 return apply_filters( 'get_allowed_markup', $r, $format ); 2224 } 2225 2226 // USERS 2227 function bb_get_user_id( $id = 0 ) { 2228 global $user; 2229 if ( is_object($id) && isset($id->ID) ) 2230 return (int) $id->ID; 2231 elseif ( !$id ) 2232 return $user->ID; 2233 2234 $_user = bb_get_user( (int) $id ); 2235 return isset($_user->ID) ? $_user->ID : 0; 2236 } 2237 2238 function user_profile_link( $id = 0 , $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 2239 if (!$context || !is_integer($context)) { 2240 $context = BB_URI_CONTEXT_A_HREF; 2241 } 2242 echo apply_filters( 'user_profile_link', get_user_profile_link( $id ), bb_get_user_id( $id ), $context ); 2243 } 2244 2245 function get_user_profile_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 2246 $user = bb_get_user( bb_get_user_id( $id ) ); 2247 2248 if (!$context || !is_integer($context)) { 2249 $context = BB_URI_CONTEXT_A_HREF; 2250 } 2251 2252 $rewrite = bb_get_option( 'mod_rewrite' ); 2253 if ( $rewrite ) { 2254 if ( $rewrite === 'slugs' ) { 2255 $column = 'user_nicename'; 2256 } else { 2257 $column = 'ID'; 2258 } 2259 $page = (1 < $page) ? '/page/' . $page : ''; 2260 $r = bb_get_uri('profile/' . $user->$column . $page, null, $context); 2261 } else { 2262 $query = array( 2263 'id' => $user->ID, 2264 'page' => (1 < $page) ? $page : false 2265 ); 2266 $r = bb_get_uri('profile.php', $query, $context); 2267 } 2268 return apply_filters( 'get_user_profile_link', $r, $user->ID, $context ); 2269 } 2270 2271 function user_delete_button() { 2272 global $user; 2273 2274 $user_obj = new BP_User( $user->ID ); 2275 if ( !bb_current_user_can( 'keep_gate' ) && 'keymaster' == $user_obj->roles[0] ) 2276 return; 2277 2278 if ( bb_current_user_can( 'edit_users' ) && bb_get_current_user_info( 'id' ) != (int) $user->ID ) 2279 echo apply_filters( 'user_delete_button', get_user_delete_button() ); 2280 } 2281 2282 function get_user_delete_button() { 2283 $r = '<input type="submit" class="delete" name="delete-user" value="' . __('Delete User »') . '" '; 2284 $r .= 'onclick="return confirm(\'' . esc_js(__('Are you sure you want to delete this user?')) . '\')" />'; 2285 return apply_filters( 'get_user_delete_button', $r); 2286 } 2287 2288 function profile_tab_link( $id = 0, $tab, $page = 1 ) { 2289 echo apply_filters( 'profile_tab_link', get_profile_tab_link( $id, $tab ) ); 2290 } 2291 2292 function get_profile_tab_link( $id = 0, $tab, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 2293 $user = bb_get_user( bb_get_user_id( $id ) ); 2294 2295 $tab = bb_sanitize_with_dashes($tab); 2296 2297 if (!$context || !is_integer($context)) { 2298 $context = BB_URI_CONTEXT_A_HREF; 2299 } 2300 2301 if ( $tab === 'edit' && !( $context & BB_URI_CONTEXT_BB_USER_FORMS ) ) { 2302 $context += BB_URI_CONTEXT_BB_USER_FORMS; 2303 } 2304 2305 $rewrite = bb_get_option( 'mod_rewrite' ); 2306 if ( $rewrite ) { 2307 if ( $rewrite === 'slugs' ) { 2308 $column = 'user_nicename'; 2309 } else { 2310 $column = 'ID'; 2311 } 2312 $page = (1 < $page) ? '/page/' . $page : ''; 2313 $r = bb_get_uri('profile/' . $user->$column . '/' . $tab . $page, null, $context); 2314 } else { 2315 $query = array( 2316 'id' => $user->ID, 2317 'tab' => $tab, 2318 'page' => (1 < $page) ? $page : false 2319 ); 2320 $r = bb_get_uri('profile.php', $query, $context); 2321 } 2322 return apply_filters( 'get_profile_tab_link', $r, $user->ID, $context ); 2323 } 2324 2325 function user_link( $id = 0 ) { 2326 echo apply_filters( 'user_link', get_user_link( $id ), $id ); 2327 } 2328 2329 function get_user_link( $id = 0 ) { 2330 if ( $user = bb_get_user( bb_get_user_id( $id ) ) ) 2331 return apply_filters( 'get_user_link', $user->user_url, $user->ID ); 2332 } 2333 2334 function full_user_link( $id = 0 ) { 2335 echo get_full_user_link( $id ); 2336 } 2337 2338 function get_full_user_link( $id = 0 ) { 2339 if ( get_user_link( $id ) ) 2340 $r = '<a href="' . esc_attr( get_user_link( $id ) ) . '">' . get_user_display_name( $id ) . '</a>'; 2341 else 2342 $r = get_user_display_name( $id ); 2343 return $r; 2344 } 2345 2346 function user_type_label( $type ) { 2347 echo apply_filters( 'user_type_label', get_user_type_label( $type ), $type ); 2348 } 2349 2350 function get_user_type_label( $type ) { 2351 global $wp_roles; 2352 if ( $wp_roles->is_role( $type ) ) 2353 return apply_filters( 'get_user_type_label', $wp_roles->role_names[$type], $type ); 2354 } 2355 2356 function user_type( $id = 0 ) { 2357 echo apply_filters( 'user_type', get_user_type( $id ), $id ); 2358 } 2359 2360 function get_user_type( $id = 0 ) { 2361 if ( $user = bb_get_user( bb_get_user_id( $id ) ) ) : 2362 @$caps = array_keys($user->capabilities); 2363 if ( !$caps ) 2364 $caps[] = 'inactive'; 2365 2366 $type = get_user_type_label( $caps[0] ); //Just support one role for now. 2367 else : 2368 $type = false; 2369 endif; 2370 return apply_filters( 'get_user_type', $type, $user->ID ); 2371 } 2372 2373 function get_user_name( $id = 0 ) { 2374 $user = bb_get_user( bb_get_user_id( $id ) ); 2375 return apply_filters( 'get_user_name', $user->user_login, $user->ID ); 2376 } 2377 2378 function get_user_display_name( $id = 0 ) { 2379 $user = bb_get_user( bb_get_user_id( $id ) ); 2380 return apply_filters( 'get_user_display_name', $user->display_name, $user->ID ); 2381 } 2382 2383 function user_title( $id = 0 ) { 2384 echo apply_filters( 'user_title', get_user_title( $id ), bb_get_user_id( $id ) ); 2385 } 2386 2387 function get_user_title( $id = 0 ) { 2388 $user = bb_get_user( bb_get_user_id( $id ) ); 2389 return empty( $user->title ) ? get_user_type( $id ) : apply_filters( 'get_user_title', $user->title, $user->ID ); 2390 } 2391 2392 function profile_pages( $args = null ) 2393 { 2394 $defaults = array( 'before' => '', 'after' => '' ); 2395 $args = wp_parse_args( $args, $defaults ); 2396 2397 global $page, $user; 2398 $add = apply_filters( 'profile_pages_add', $add ); 2399 if ( $pages = apply_filters( 'profile_pages', get_page_number_links( $page, $user->topics_replied + $add ), $user->user_id ) ) { 2400 echo $args['before'] . $pages . $args['after']; 2401 } 2402 } 2403 2404 function bb_profile_data( $id = 0 ) { 2405 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2406 return; 2407 2408 $reg_time = bb_gmtstrtotime( $user->user_registered ); 2409 $profile_info_keys = bb_get_profile_info_keys(); 2410 echo "<dl id='userinfo'>\n"; 2411 echo "\t<dt>" . __('Member Since') . "</dt>\n"; 2412 echo "\t<dd>" . bb_datetime_format_i18n($reg_time, 'date') . ' (' . bb_since($reg_time) . ")</dd>\n"; 2413 if ( is_array( $profile_info_keys ) ) { 2414 foreach ( $profile_info_keys as $key => $label ) { 2415 if ( in_array($key, array('first_name', 'last_name', 'display_name')) || !isset($user->$key) ) 2416 continue; 2417 $val = 'user_url' == $key ? get_user_link( $user->ID ) : $user->$key; 2418 if ( 2419 ( 'user_email' != $key || ( 'user_email' == $key && bb_current_user_can( 'edit_users' ) ) ) 2420 && $val 2421 && 'http://' != $val 2422 ) { 2423 echo "\t<dt>{$label[1]}</dt>\n"; 2424 $val = make_clickable( $val ); 2425 $attributes = array(); 2426 if (isset($label[2]) && !empty($label[2])) 2427 if (preg_match("#^<a#i", $val)) 2428 $val = preg_replace("#^<a#i", '<a class="' . esc_attr($label[2]) . '"', $val); 2429 else 2430 $val = '<span class="' . esc_attr($label[2]) . '">' . $val . '</span>'; 2431 2432 echo "\t<dd>" . $val . "</dd>\n"; 2433 } 2434 } 2435 } 2436 echo "</dl>\n"; 2437 } 2438 2439 function bb_profile_base_content() { 2440 global $self; 2441 if ( !is_callable( $self ) ) 2442 return; // should never happen 2443 call_user_func( $self ); 2444 } 2445 2446 function bb_profile_data_form( $id = 0 ) { 2447 global $errors; 2448 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2449 return; 2450 2451 if ( !bb_current_user_can( 'edit_user', $user->ID ) ) 2452 return; 2453 2454 $error_codes = $errors->get_error_codes(); 2455 $profile_info_keys = bb_get_profile_info_keys(); 2456 $required = false; 2457 if ( in_array( 'delete', $error_codes ) ) 2458 echo '<div class="form-invalid error">' . $errors->get_error_message( 'delete' ) . '</div>'; 2459 ?> 2460 <table id="userinfo"> 2461 <?php 2462 if ( is_array($profile_info_keys) ) : 2463 $bb_current_id = bb_get_current_user_info( 'id' ); 2464 foreach ( $profile_info_keys as $key => $label ) : 2465 if ( $label[0] ) { 2466 $class = 'form-field form-required required'; 2467 $required = true; 2468 } else { 2469 $class = 'form-field'; 2470 } 2471 $title = esc_attr( $label[1] ); 2472 2473 $name = esc_attr( $key ); 2474 $type = isset($label[2]) ? esc_attr( $label[2] ) : 'text'; 2475 if ( !in_array( $type, array( 'checkbox', 'file', 'hidden', 'image', 'password', 'radio', 'text' ) ) ) { 2476 $type = 'text'; 2477 } 2478 2479 $checked = false; 2480 if ( in_array( $key, $error_codes ) ) { 2481 $class .= ' form-invalid error'; 2482 $data = $errors->get_error_data( $key ); 2483 if ( 'checkbox' == $type ) { 2484 if ( isset($data['data']) ) 2485 $checked = $data['data']; 2486 else 2487 $checked = $_POST[$key]; 2488 $value = $label[3]; 2489 $checked = $checked == $value; 2490 } else { 2491 if ( isset($data['data']) ) 2492 $value = $data['data']; 2493 else 2494 $value = $_POST[$key]; 2495 } 2496 2497 $message = esc_html( $errors->get_error_message( $key ) ); 2498 $message = "<em>$message</em>"; 2499 } else { 2500 if ( 'checkbox' == $type ) { 2501 $checked = $user->$key == $label[3] || $label[4] == $label[3]; 2502 $value = $label[3]; 2503 } else { 2504 $value = isset($user->$key) ? $user->$key : ''; 2505 } 2506 $message = ''; 2507 } 2508 2509 $checked = $checked ? ' checked="checked"' : ''; 2510 $value = esc_attr( $value ); 2511 2512 ?> 2513 2514 <tr class="<?php echo $class; ?>"> 2515 <th scope="row"> 2516 <label for="<?php echo $name; ?>"><?php echo $title; ?></label> 2517 <?php echo $message; ?> 2518 </th> 2519 <td> 2520 <?php 2521 if ($key == 'display_name') { 2522 ?> 2523 <select name="display_name" id="display_name"> 2524 <?php 2525 $public_display = array(); 2526 $public_display['display_displayname'] = $user->display_name; 2527 //$public_display['display_nickname'] = $user->nickname; 2528 $public_display['display_username'] = $user->user_login; 2529 if ( isset($user->first_name) ) { 2530 $public_display['display_firstname'] = $user->first_name; 2531 if ( isset($user->last_name) ) { 2532 $public_display['display_firstlast'] = $user->first_name.' '.$user->last_name; 2533 $public_display['display_lastfirst'] = $user->last_name.' '.$user->first_name; 2534 } 2535 } 2536 if ( isset($user->last_name) ) 2537 $public_display['display_lastname'] = $user->last_name; 2538 2539 $public_display = array_unique(array_filter(array_map('trim', $public_display))); 2540 2541 foreach($public_display as $id => $item) { 2542 ?> 2543 <option id="<?php echo esc_attr( $id ); ?>" value="<?php echo esc_attr( $item ); ?>"><?php echo esc_html( $item ); ?></option> 2544 <?php 2545 } 2546 ?> 2547 </select> 2548 <?php 2549 } else { 2550 ?> 2551 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo '<label for="' . $name . '">'; ?> 2552 <input name="<?php echo $name; ?>" id="<?php echo $name; ?>" type="<?php echo $type; ?>"<?php echo $checked; ?> value="<?php echo $value; ?>" /> 2553 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo esc_html( $label[5] ) . '</label>'; ?> 2554 <?php 2555 } 2556 ?> 2557 </td> 2558 </tr> 2559 2560 <?php endforeach; endif; // $profile_info_keys; $profile_info_keys ?> 2561 2562 </table> 2563 2564 <?php bb_nonce_field( 'edit-profile_' . $user->ID ); if ( $required ) : ?> 2565 2566 <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p> 2567 2568 <?php 2569 endif; 2570 do_action( 'extra_profile_info', $user->ID ); 2571 } 2572 2573 function bb_profile_admin_form( $id = 0 ) { 2574 global $wp_roles, $errors; 2575 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2576 return; 2577 2578 if ( !bb_current_user_can( 'edit_user', $user->ID ) ) 2579 return; 2580 2581 $error_codes = $errors->get_error_codes(); 2582 $bb_current_id = bb_get_current_user_info( 'id' ); 2583 2584 $profile_admin_keys = bb_get_profile_admin_keys(); 2585 $assignable_caps = bb_get_assignable_caps(); 2586 $required = false; 2587 2588 $roles = $wp_roles->role_names; 2589 $can_keep_gate = bb_current_user_can( 'keep_gate' ); 2590 2591 // Keymasters can't demote themselves 2592 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 ) ) { 2593 $roles = array( 'keymaster' => $roles['keymaster'] ); 2594 } elseif ( !$can_keep_gate ) { // only keymasters can promote others to keymaster status 2595 unset($roles['keymaster']); 2596 } 2597 2598 $selected = array( 'inactive' => ' selected="selected"' ); 2599 ?> 2600 <table id="admininfo"> 2601 <tr class='form-field<?php if ( in_array( 'role', $error_codes ) ) echo ' form-invalid error'; ?>'> 2602 <th scope="row"> 2603 <label for="admininfo_role"><?php _e('User Type'); ?></label> 2604 <?php if ( in_array( 'role', $error_codes ) ) echo '<em>' . $errors->get_error_message( 'role' ) . '</em>'; ?> 2605 </th> 2606 <td> 2607 <select id="admininfo_role" name="role"> 2608 <?php 2609 foreach( $roles as $r => $n ) { 2610 if ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( $r, $user->capabilities ) ) { 2611 $selected['inactive'] = ''; 2612 $selected[$r] = ' selected="selected"'; 2613 } elseif ( $r !== 'inactive' ) { 2614 $selected[$r] = ''; 2615 } 2616 ?> 2617 <option value="<?php echo $r; ?>"<?php echo $selected[$r]; ?>><?php echo $n; ?></option> 2618 <?php 2619 } 2620 ?> 2621 </select> 2622 </td> 2623 </tr> 2624 <?php 2625 if (count($assignable_caps)) : 2626 ?> 2627 <tr class="extra-caps-row"> 2628 <th scope="row"><?php _e('Allow this user to'); ?></th> 2629 <td> 2630 <?php 2631 foreach( $assignable_caps as $cap => $label ) : 2632 $name = esc_attr( $cap ); 2633 $checked = ''; 2634 if ( isset( $user->capabilities ) && is_array( $user->capabilities ) && array_key_exists( $cap, $user->capabilities ) ) { 2635 $checked = ' checked="checked"'; 2636 } 2637 $label = esc_html( $label ); 2638 ?> 2639 2640 <label><input name="<?php echo $name; ?>" value="1" type="checkbox"<?php echo $checked; ?> /> <?php echo $label; ?></label><br /> 2641 2642 <?php endforeach; ?> 2643 2644 </td> 2645 </tr> 2646 2647 <?php 2648 endif; 2649 2650 if ( is_array($profile_admin_keys) ) : 2651 foreach ( $profile_admin_keys as $key => $label ) : 2652 if ( $label[0] ) { 2653 $class = 'form-field form-required required'; 2654 $required = true; 2655 } else { 2656 $class = 'form-field'; 2657 } 2658 $title = esc_attr( $label[1] ); 2659 2660 $name = esc_attr( $key ); 2661 $type = isset($label[2]) ? esc_attr( $label[2] ) : 'text'; 2662 2663 $checked = false; 2664 if ( in_array( $key, $error_codes ) ) { 2665 $class .= ' form-invalid error'; 2666 $data = $errors->get_error_data( $key ); 2667 if ( 'checkbox' == $type ) { 2668 if ( isset($data['data']) ) 2669 $checked = $data['data']; 2670 else 2671 $checked = $_POST[$key]; 2672 $value = $label[3]; 2673 $checked = $checked == $value; 2674 } else { 2675 if ( isset($data['data']) ) 2676 $value = $data['data']; 2677 else 2678 $value = $_POST[$key]; 2679 } 2680 2681 $message = esc_html( $errors->get_error_message( $key ) ); 2682 $message = "<em>$message</em>"; 2683 } else { 2684 if ( 'checkbox' == $type ) { 2685 $checked = $user->$key == $label[3] || $label[4] == $label[3]; 2686 $value = $label[3]; 2687 } else { 2688 $value = isset($user->$key) ? $user->$key : ''; 2689 } 2690 $message = ''; 2691 } 2692 2693 $checked = $checked ? ' checked="checked"' : ''; 2694 $value = esc_attr( $value ); 2695 2696 ?> 2697 2698 <tr class="<?php echo $class; ?>"> 2699 <th scope="row"> 2700 <label for="<?php echo $name; ?>"><?php echo $title ?></label> 2701 <?php echo $message; ?> 2702 </th> 2703 <td> 2704 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo "<label for='$name'>"; ?> 2705 <input name="<?php echo $name; ?>" id="<?php echo $name; ?>" type="<?php echo $type; ?>"<?php echo $checked; ?> value="<?php echo $value; ?>" /> 2706 <?php if ( 'checkbox' == $type && isset($label[5]) ) echo esc_html( $label[5] ) . "</label>"; ?> 2707 </td> 2708 </tr> 2709 2710 <?php endforeach; endif; // $profile_admin_keys; $profile_admin_keys ?> 2711 2712 </table> 2713 2714 <?php if ( $required ) : ?> 2715 <p class="required-message"><?php _e('These items are <span class="required">required</span>.') ?></p> 2716 2717 <?php endif; ?> 2718 <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> 2719 <p><?php _e('<strong>Note</strong>: Blocking a user does <em>not</em> block any IP addresses.'); ?></p> 2720 <?php 2721 } 2722 2723 function bb_profile_password_form( $id = 0 ) { 2724 global $errors; 2725 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2726 return; 2727 2728 if ( !bb_current_user_can( 'change_user_password', $user->ID ) ) 2729 return; 2730 2731 $class = 'form-field'; 2732 2733 if ( $message = $errors->get_error_message( 'pass' ) ) { 2734 $class .= ' form-invalid error'; 2735 $message = '<em>' . esc_html( $message ) . '</em>'; 2736 } 2737 ?> 2738 2739 <table> 2740 <tr class="<?php echo $class; ?>"> 2741 <th scope="row" rowspan="2"> 2742 <label for="pass1"><?php _e('New password'); ?></label> 2743 <?php echo $message; ?> 2744 </th> 2745 <td> 2746 <input name="pass1" type="password" id="pass1" autocomplete="off" /> 2747 </td> 2748 </tr> 2749 <tr class="<?php echo $class; ?>"> 2750 <td> 2751 <input name="pass2" type="password" id="pass2" autocomplete="off" /> 2752 </td> 2753 </tr> 2754 <tr class="pass-strength"> 2755 <th scope="row"><?php _e('Password Strength'); ?></th> 2756 <td> 2757 <input type="hidden" name="user_login" id="user_login" value="<?php echo $user->user_login; ?>" /> 2758 <noscript> 2759 <?php _e('Disabled (requires JavaScript)'); ?> 2760 </noscript> 2761 <script type="text/javascript" charset="utf-8"> 2762 if (typeof jQuery != 'undefined') { 2763 document.writeln('<div id="pass-strength-result">' + pwsL10n.short + '</div>'); 2764 } else { 2765 document.writeln('<?php echo str_replace("'", "\'", __('Disabled.')); ?>') 2766 } 2767 </script> 2768 </td> 2769 </tr> 2770 </table> 2771 2772 <p><?php _e('Hint: Use upper and lower case characters, numbers and symbols like !"?$%^&( in your password.'); ?></p> 2773 2774 <?php 2775 2776 } 2777 2778 function bb_logout_link( $args = '' ) { 2779 echo apply_filters( 'bb_logout_link', bb_get_logout_link( $args ), $args ); 2780 } 2781 2782 function bb_get_logout_link( $args = '' ) { 2783 if ( $args && is_string($args) && false === strpos($args, '=') ) 2784 $args = array( 'text' => $args ); 2785 2786 $defaults = array('text' => __('Log Out'), 'before' => '', 'after' => '', 'redirect' => ''); 2787 $args = wp_parse_args( $args, $defaults ); 2788 extract($args, EXTR_SKIP); 2789 2790 $query = array( 'action' => 'logout' ); 2791 if ( $redirect ) { 2792 $query['redirect_to'] = $redirect; 2793 } 2794 2795 $uri = esc_attr( bb_get_uri('bb-login.php', $query, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS) ); 2796 2797 return apply_filters( 'bb_get_logout_link', $before . '<a href="' . $uri . '">' . $text . '</a>' . $after, $args ); 2798 } 2799 2800 function bb_admin_link( $args = '' ) { 2801 if ( !bb_current_user_can( 'moderate' ) ) 2802 return; 2803 echo apply_filters( 'bb_admin_link', bb_get_admin_link( $args ), $args ); 2804 } 2805 2806 function bb_get_admin_link( $args = '' ) { 2807 if ( !bb_current_user_can( 'moderate' ) ) 2808 return; 2809 if ( $args && is_string($args) && false === strpos($args, '=') ) 2810 $args = array( 'text' => $args ); 2811 2812 $defaults = array('text' => __('Admin'), 'before' => '', 'after' => ''); 2813 $args = wp_parse_args( $args, $defaults ); 2814 extract($args, EXTR_SKIP); 2815 2816 $uri = esc_attr( bb_get_uri('bb-admin/', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN) ); 2817 2818 return apply_filters( 'bb_get_admin_link', $before . '<a href="' . $uri . '">' . $text . '</a>' . $after, $args ); 2819 } 2820 2821 function bb_get_user_admin_link( $user_id = null ) { 2822 if( !$user_id || !bb_current_user_can( 'edit_user', $user_id ) ) 2823 return; 2824 2825 if( !bb_get_user_id( $user_id ) ) 2826 return; 2827 2828 $uri = bb_get_uri( 'bb-admin/users.php', array( 'action' => 'edit', 'user_id' => $user_id ) ); 2829 2830 return apply_filters( 'bb_get_user_admin_link', $uri, $user_id ); 2831 } 2832 2833 function bb_profile_link( $args = '' ) { 2834 echo apply_filters( 'bb_profile_link', bb_get_profile_link( $args ), $args ); 2835 } 2836 2837 function bb_get_profile_link( $args = '' ) { 2838 if ( $args && is_string($args) && false === strpos($args, '=') ) 2839 $args = array( 'text' => $args ); 2840 elseif ( is_numeric($args) ) 2841 $args = array( 'id' => $args ); 2842 2843 $defaults = array( 'text' => __('View your profile'), 'before' => '', 'after' => '', 'id' => false ); 2844 $args = wp_parse_args( $args, $defaults ); 2845 extract($args, EXTR_SKIP); 2846 2847 $id = (int) $id; 2848 if ( !$id ) 2849 $id = bb_get_current_user_info( 'id' ); 2850 2851 return apply_filters( 'bb_get_profile_link', "$before<a href='" . esc_attr( get_user_profile_link( $id ) ) . "'>$text</a>$after", $args ); 2852 } 2853 2854 function bb_current_user_info( $key = '' ) { 2855 if ( !$key ) 2856 return; 2857 echo apply_filters( 'bb_current_user_info', bb_get_current_user_info( $key ), $key ); 2858 } 2859 2860 2861 function bb_get_current_user_info( $key = '' ) { 2862 if ( !is_string($key) ) 2863 return; 2864 if ( !$user = bb_get_current_user() ) // Not globalized 2865 return false; 2866 2867 switch ( $key ) : 2868 case '' : 2869 return $user; 2870 break; 2871 case 'id' : 2872 case 'ID' : 2873 return (int) $user->ID; 2874 break; 2875 case 'name' : 2876 return get_user_display_name( $user->ID ); 2877 break; 2878 case 'login' : 2879 case 'user_login' : 2880 return get_user_name( $user->ID ); 2881 break; 2882 case 'email' : 2883 case 'user_email' : 2884 return bb_get_user_email( $user->ID ); 2885 break; 2886 case 'url' : 2887 case 'uri' : 2888 case 'user_url' : 2889 return get_user_link( $user->ID ); 2890 break; 2891 endswitch; 2892 } 2893 2894 function bb_get_user_email( $id ) { 2895 if ( !$user = bb_get_user( bb_get_user_id( $id ) ) ) 2896 return false; 2897 2898 return apply_filters( 'bb_get_user_email', $user->user_email, $id ); 2899 } 2900 2901 //TAGS 2902 function topic_tags() 2903 { 2904 global $tags, $tag, $topic_tag_cache, $user_tags, $other_tags, $topic; 2905 if ( is_array( $tags ) || bb_current_user_can( 'edit_tag_by_on', bb_get_current_user_info( 'id' ), $topic->topic_id ) ) { 2906 bb_load_template( 'topic-tags.php', array('user_tags', 'other_tags', 'public_tags') ); 2907 } 2908 } 2909 2910 function bb_tag_page_link() 2911 { 2912 echo bb_get_tag_page_link(); 2913 } 2914 2915 function bb_get_tag_page_link( $context = BB_URI_CONTEXT_A_HREF ) 2916 { 2917 if ( bb_get_option( 'mod_rewrite' ) ) { 2918 $r = bb_get_uri( 'tags/', null, $context ); 2919 } else { 2920 $r = bb_get_uri( 'tags.php', null, $context ); 2921 } 2922 return apply_filters( 'bb_get_tag_page_link', $r, $context ); 2923 } 2924 2925 function bb_tag_link( $tag_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) 2926 { 2927 echo apply_filters( 'bb_tag_link', bb_get_tag_link( $tag_id, $page, $context ), $tag_id, $page, $context ); 2928 } 2929 2930 function bb_get_tag_link( $tag_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) 2931 { 2932 global $tag; 2933 2934 if ( $tag_id ) { 2935 if ( is_object( $tag_id ) ) { 2936 $_tag = $tag_id; 2937 } else { 2938 $_tag = bb_get_tag( $tag_id ); 2939 } 2940 } else { 2941 $_tag =& $tag; 2942 } 2943 2944 if ( !is_object( $_tag ) ) { 2945 return ''; 2946 } 2947 2948 if ( !$context || !is_integer( $context ) ) { 2949 $context = BB_URI_CONTEXT_A_HREF; 2950 } 2951 2952 if ( bb_get_option( 'mod_rewrite' ) ) { 2953 $page = (1 < $page) ? '/page/' . $page : ''; 2954 $r = bb_get_uri( 'tags/' . $_tag->tag . $page, null, $context ); 2955 } else { 2956 $query = array( 2957 'tag' => $_tag->tag, 2958 'page' => ( 1 < $page ) ? $page : false 2959 ); 2960 $r = bb_get_uri( 'tags.php', $query, $context ); 2961 } 2962 2963 return apply_filters( 'bb_get_tag_link', $r, $_tag->tag, $page, $context ); 2964 } 2965 2966 function bb_tag_link_base() 2967 { 2968 echo bb_get_tag_link_base(); 2969 } 2970 2971 function bb_get_tag_link_base() 2972 { 2973 return bb_get_tag_page_link() . ( bb_get_option( 'mod_rewrite' ) ? '' : '?tag=' ); 2974 } 2975 2976 function bb_tag_name( $tag_id = 0 ) 2977 { 2978 echo esc_html( bb_get_tag_name( $tag_id ) ); 2979 } 2980 2981 function bb_get_tag_name( $tag_id = 0 ) { 2982 global $tag; 2983 2984 if ( $tag_id ) { 2985 if ( is_object( $tag_id ) ) { 2986 $_tag = $tag_id; 2987 } else { 2988 $_tag = bb_get_tag( $tag_id ); 2989 } 2990 } else { 2991 $_tag =& $tag; 2992 } 2993 2994 if ( !is_object( $_tag ) ) { 2995 return ''; 2996 } 2997 2998 return $_tag->raw_tag; 2999 } 3000 3001 function bb_tag_posts_rss_link( $tag_id = 0, $context = 0 ) 3002 { 3003 if ( !$context || !is_integer( $context ) ) { 3004 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3005 } 3006 3007 echo apply_filters( 'tag_posts_rss_link', bb_get_tag_posts_rss_link( $tagid, $context ), $tag_id, $context ); 3008 } 3009 3010 function bb_get_tag_posts_rss_link( $tag_id = 0, $context = 0 ) 3011 { 3012 global $tag; 3013 3014 if ( $tag_id ) { 3015 if ( is_object( $tag_id ) ) { 3016 $_tag = $tag_id; 3017 } else { 3018 $_tag = bb_get_tag( $tag_id ); 3019 } 3020 } else { 3021 $_tag =& $tag; 3022 } 3023 3024 if ( !is_object( $_tag ) ) { 3025 return ''; 3026 } 3027 3028 if ( !$context || !is_integer( $context ) ) { 3029 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3030 } 3031 3032 if ( bb_get_option( 'mod_rewrite' ) ) { 3033 $link = bb_get_uri( 'rss/tags/' . $_tag->tag, null, $context ); 3034 } else { 3035 $link = bb_get_uri( 'rss.php', array( 'tag' => $_tag->tag ), $context ); 3036 } 3037 3038 return apply_filters( 'get_tag_posts_rss_link', $link, $tag_id, $context ); 3039 } 3040 3041 function bb_tag_topics_rss_link( $tag_id = 0, $context = 0 ) 3042 { 3043 if ( !$context || !is_integer( $context ) ) { 3044 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3045 } 3046 3047 echo apply_filters( 'tag_topics_rss_link', bb_get_tag_topics_rss_link( $tag_id, $context ), $tag_id, $context ); 3048 } 3049 3050 function bb_get_tag_topics_rss_link( $tag_id = 0, $context = 0 ) 3051 { 3052 global $tag; 3053 3054 if ( $tag_id ) { 3055 if ( is_object( $tag_id ) ) { 3056 $_tag = $tag_id; 3057 } else { 3058 $_tag = bb_get_tag( $tag_id ); 3059 } 3060 } else { 3061 $_tag =& $tag; 3062 } 3063 3064 if ( !is_object( $_tag ) ) { 3065 return ''; 3066 } 3067 3068 if ( !$context || !is_integer( $context ) ) { 3069 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3070 } 3071 3072 if ( bb_get_option( 'mod_rewrite' ) ) { 3073 $link = bb_get_uri( 'rss/tags/' . $_tag->tag . '/topics', null, $context ); 3074 } else { 3075 $link = bb_get_uri( 'rss.php', array('tag' => $_tag->tag, 'topics' => 1 ), $context ); 3076 } 3077 3078 return apply_filters( 'get_tag_topics_rss_link', $link, $tag_id, $context ); 3079 } 3080 3081 function bb_list_tags( $args = null ) 3082 { 3083 $defaults = array( 3084 'tags' => false, 3085 'format' => 'list', 3086 'topic' => 0, 3087 'list_id' => 'tags-list' 3088 ); 3089 3090 $args = wp_parse_args( $args, $defaults ); 3091 extract( $args, EXTR_SKIP ); 3092 3093 if ( !$topic = get_topic( get_topic_id( $topic ) ) ) { 3094 return false; 3095 } 3096 3097 if ( !is_array( $tags ) ) { 3098 $tags = bb_get_topic_tags( $topic->topic_id ); 3099 } 3100 3101 if ( !$tags ) { 3102 return false; 3103 } 3104 3105 $list_id = esc_attr( $list_id ); 3106 3107 $r = ''; 3108 switch ( strtolower( $format ) ) { 3109 case 'table' : 3110 break; 3111 3112 case 'list' : 3113 default : 3114 $args['format'] = 'list'; 3115 $r .= '<ul id="' . $list_id . '" class="tags-list list:tag">' . "\n"; 3116 foreach ( $tags as $tag ) { 3117 $r .= _bb_list_tag_item( $tag, $args ); 3118 } 3119 $r .= '</ul>'; 3120 break; 3121 } 3122 3123 echo $r; 3124 } 3125 3126 function _bb_list_tag_item( $tag, $args ) 3127 { 3128 $url = esc_url( bb_get_tag_link( $tag ) ); 3129 $name = esc_html( bb_get_tag_name( $tag ) ); 3130 if ( 'list' == $args['format'] ) { 3131 $id = 'tag-' . $tag->tag_id . '_' . $tag->user_id; 3132 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"; 3133 } 3134 } 3135 3136 function tag_form( $args = null ) 3137 { 3138 $defaults = array( 'topic' => 0, 'submit' => __('Add »'), 'list_id' => 'tags-list' ); 3139 $args = wp_parse_args( $args, $defaults ); 3140 extract( $args, EXTR_SKIP ); 3141 3142 if ( !$topic = get_topic( get_topic_id( $topic ) ) ) { 3143 return false; 3144 } 3145 3146 if ( !bb_current_user_can( 'edit_tag_by_on', bb_get_current_user_info( 'id' ), $topic->topic_id ) ) { 3147 return false; 3148 } 3149 3150 global $page; 3151 ?> 3152 3153 <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 ); ?>:"> 3154 <p> 3155 <input name="tag" type="text" id="tag" /> 3156 <input type="hidden" name="id" value="<?php echo $topic->topic_id; ?>" /> 3157 <input type="hidden" name="page" value="<?php echo $page; ?>" /> 3158 <?php bb_nonce_field( 'add-tag_' . $topic->topic_id ); ?> 3159 <input type="submit" name="submit" id="tagformsub" value="<?php echo esc_attr( $submit ); ?>" /> 3160 </p> 3161 </form> 3162 3163 <?php 3164 } 3165 3166 function manage_tags_forms() 3167 { 3168 global $tag; 3169 if ( !bb_current_user_can( 'manage_tags' ) ) { 3170 return false; 3171 } 3172 3173 $form = '<ul id="manage-tags">' . "\n"; 3174 $form .= '<li id="tag-rename">' . __('Rename tag:') . "\n\t"; 3175 $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"; 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='" . __('Rename') . "' />\n\t"; 3179 echo $form; 3180 bb_nonce_field( 'rename-tag_' . $tag->tag_id ); 3181 echo "\n\t</div></form>\n </li>\n "; 3182 $form = "<li id='tag-merge'>" . __('Merge this tag into:') . "\n\t"; 3183 $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"; 3184 $form .= "<input type='text' name='tag' size='10' maxlength='30' />\n\t"; 3185 $form .= "<input type='hidden' name='id' value='$tag->tag_id' />\n\t"; 3186 $form .= "<input type='submit' name='Submit' value='" . __('Merge') . "' "; 3187 $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"; 3188 echo $form; 3189 bb_nonce_field( 'merge-tag_' . $tag->tag_id ); 3190 echo "\n\t</div></form>\n </li>\n "; 3191 $form = "<li id='tag-destroy'>" . __('Destroy tag:') . "\n\t"; 3192 $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"; 3193 $form .= "<input type='hidden' name='id' value='$tag->tag_id' />\n\t"; 3194 $form .= "<input type='submit' name='Submit' value='" . __('Destroy') . "' "; 3195 $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"; 3196 echo $form; 3197 bb_nonce_field( 'destroy-tag_' . $tag->tag_id ); 3198 echo "\n\t</div></form>\n </li>\n</ul>"; 3199 } 3200 3201 function bb_tag_remove_link( $args = null ) { 3202 echo bb_get_tag_remove_link( $args ); 3203 } 3204 3205 function bb_get_tag_remove_link( $args = null ) { 3206 if ( is_scalar($args) || is_object( $args ) ) 3207 $args = array( 'tag' => $args ); 3208 $defaults = array( 'tag' => 0, 'topic' => 0, 'list_id' => 'tags-list' ); 3209 $args = wp_parse_args( $args, $defaults ); 3210 extract( $args, EXTR_SKIP ); 3211 3212 if ( is_object( $tag ) && isset( $tag->tag_id ) ); // [sic] 3213 elseif ( !$tag = bb_get_tag( bb_get_tag_id( $tag ) ) ) 3214 return false; 3215 if ( !$topic = get_topic( get_topic_id( $topic ) ) ) 3216 return false; 3217 if ( !bb_current_user_can( 'edit_tag_by_on', $tag->user_id, $topic->topic_id ) ) 3218 return false; 3219 $url = bb_get_uri('tag-remove.php', array('tag' => $tag->tag_id, 'user' => $tag->user_id, 'topic' => $topic->topic_id) ); 3220 $url = esc_url( bb_nonce_url( $url, 'remove-tag_' . $tag->tag_id . '|' . $topic->topic_id) ); 3221 $title = esc_attr__( 'Remove this tag' ); 3222 $list_id = esc_attr( $list_id ); 3223 return "[<a href='$url' class='delete:$list_id:tag-{$tag->tag_id}_{$tag->user_id}' title='$title'>×</a>]"; 3224 } 3225 3226 function bb_tag_heat_map( $args = '' ) { 3227 $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'limit' => 40, 'format' => 'flat' ); 3228 $args = wp_parse_args( $args, $defaults ); 3229 3230 if ( 1 < $fn = func_num_args() ) : // For back compat 3231 $args['smallest'] = func_get_arg(0); 3232 $args['largest'] = func_get_arg(1); 3233 $args['unit'] = 2 < $fn ? func_get_arg(2) : $unit; 3234 $args['limit'] = 3 < $fn ? func_get_arg(3) : $limit; 3235 endif; 3236 3237 extract($args, EXTR_SKIP); 3238 3239 $tags = bb_get_top_tags( array( 'number' => $limit ) ); 3240 3241 if ( empty($tags) ) 3242 return; 3243 3244 $r = bb_get_tag_heat_map( $tags, $args ); 3245 echo apply_filters( 'tag_heat_map', $r, $args ); 3246 } 3247 3248 function bb_get_tag_heat_map( $tags, $args = '' ) { 3249 $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'limit' => 45, 'format' => 'flat' ); 3250 $args = wp_parse_args( $args, $defaults ); 3251 extract($args, EXTR_SKIP); 3252 3253 if ( !$tags ) 3254 return; 3255 3256 foreach ( (array) $tags as $tag ) { 3257 $counts{$tag->raw_tag} = $tag->tag_count; 3258 $taglinks{$tag->raw_tag} = bb_get_tag_link( $tag ); 3259 } 3260 3261 $min_count = min($counts); 3262 $spread = max($counts) - $min_count; 3263 if ( $spread <= 0 ) 3264 $spread = 1; 3265 $fontspread = $largest - $smallest; 3266 if ( $fontspread <= 0 ) 3267 $fontspread = 1; 3268 $fontstep = $fontspread / $spread; 3269 3270 do_action_ref_array( 'sort_tag_heat_map', array(&$counts) ); 3271 3272 $a = array(); 3273 3274 foreach ( $counts as $tag => $count ) { 3275 $taglink = esc_attr($taglinks{$tag}); 3276 $tag = str_replace(' ', ' ', esc_html( $tag )); 3277 $fontsize = round( $smallest + ( ( $count - $min_count ) * $fontstep ), 1 ); 3278 $a[] = "<a href='$taglink' title='" . esc_attr( sprintf( __('%d topics'), $count ) ) . "' rel='tag' style='font-size:$fontsize$unit;'>$tag</a>"; 3279 } 3280 3281 switch ( $format ) : 3282 case 'array' : 3283 $r =& $a; 3284 break; 3285 case 'list' : 3286 $r = "<ul class='bb-tag-heat-map'>\n\t<li>"; 3287 $r .= join("</li>\n\t<li>", $a); 3288 $r .= "</li>\n</ul>\n"; 3289 break; 3290 default : 3291 $r = join("\n", $a); 3292 break; 3293 endswitch; 3294 3295 return apply_filters( 'bb_get_tag_heat_map', $r, $tags, $args ); 3296 } 3297 3298 function bb_sort_tag_heat_map( &$tag_counts ) { 3299 uksort($tag_counts, 'strnatcasecmp'); 3300 } 3301 3302 function tag_pages( $args = null ) 3303 { 3304 $defaults = array( 'before' => '', 'after' => '' ); 3305 $args = wp_parse_args( $args, $defaults ); 3306 3307 global $page, $tagged_topic_count; 3308 if ( $pages = apply_filters( 'tag_pages', get_page_number_links( $page, $tagged_topic_count ) ) ) { 3309 echo $args['before'] . $pages . $args['after']; 3310 } 3311 } 3312 3313 function bb_forum_dropdown( $args = '' ) { 3314 if ( $args && is_string($args) && false === strpos($args, '=') ) 3315 $args = array( 'callback' => $args ); 3316 if ( 1 < func_num_args() ) 3317 $args['callback_args'] = func_get_arg(1); 3318 echo bb_get_forum_dropdown( $args ); 3319 } 3320 3321 function bb_get_forum_dropdown( $args = '' ) { 3322 $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 ); 3323 if ( $args && is_string($args) && false === strpos($args, '=') ) 3324 $args = array( 'callback' => $args ); 3325 if ( 1 < func_num_args() ) 3326 $args['callback_args'] = func_get_arg(1); 3327 3328 $args = wp_parse_args( $args, $defaults ); 3329 3330 extract($args, EXTR_SKIP); 3331 3332 if ( !bb_forums( $args ) ) 3333 return; 3334 3335 global $forum_id, $forum; 3336 $old_global = $forum; 3337 3338 $name = esc_attr( $id ); 3339 $id = str_replace( '_', '-', $name ); 3340 $tab = (int) $tab; 3341 3342 if ( $none && 1 == $none ) 3343 $none = __('- None -'); 3344 3345 $r = ''; 3346 if ( !$options_only ) { 3347 if ( $tab ) { 3348 $tab = ' tabindex="' . $tab . '"'; 3349 } else { 3350 $tab = ''; 3351 } 3352 $r .= '<select name="' . $name . '" id="' . $id . '"' . $tab . '>' . "\n"; 3353 } 3354 if ( $none ) 3355 $r .= "\n" . '<option value="0">' . $none . '</option>' . "\n"; 3356 3357 $no_option_selected = true; 3358 $options = array(); 3359 while ( $depth = bb_forum() ) : 3360 global $forum; // Globals + References = Pain 3361 $pad_left = str_repeat( ' ', $depth - 1 ); 3362 if ( $disable_categories && isset($forum->forum_is_category) && $forum->forum_is_category ) { 3363 $options[] = array( 3364 'value' => 0, 3365 'display' => $pad_left . $forum->forum_name, 3366 'disabled' => true, 3367 'selected' => false 3368 ); 3369 continue; 3370 } 3371 $_selected = false; 3372 if ( (!$selected && $forum_id == $forum->forum_id) || $selected == $forum->forum_id ) { 3373 $_selected = true; 3374 $no_option_selected = false; 3375 } 3376 $options[] = array( 3377 'value' => $forum->forum_id, 3378 'display' => $pad_left . $forum->forum_name, 3379 'disabled' => false, 3380 'selected' => $_selected 3381 ); 3382 endwhile; 3383 3384 if ( 1 === count( $options ) && !$none ) { 3385 foreach ( $options as $option_index => $option_value ) { 3386 if ( $option_value['disabled'] ) { 3387 return; 3388 } 3389 return '<input type="hidden" name="' . $name . '" id="' . $id . '" value="' . esc_attr( $option_value['value'] ) . '" /><span>' . esc_html( $option_value['display'] ) . '</span>'; 3390 } 3391 } 3392 3393 foreach ($options as $option_index => $option_value) { 3394 if (!$none && !$selected && $no_option_selected && !$option_value['disabled']) { 3395 $option_value['selected'] = true; 3396 $no_option_selected = false; 3397 } 3398 $option_disabled = $option_value['disabled'] ? ' disabled="disabled"' : ''; 3399 $option_selected = $option_value['selected'] ? ' selected="selected"' : ''; 3400 $r .= "\n" . '<option value="' . esc_attr( $option_value['value'] ) . '"' . $option_disabled . $option_selected . '>' . esc_html( $option_value['display'] ) . '</option>' . "\n"; 3401 } 3402 3403 $forum = $old_global; 3404 if ( !$options_only ) 3405 $r .= '</select>' . "\n"; 3406 3407 return $r; 3408 } 3409 3410 //FAVORITES 3411 function favorites_link( $user_id = 0 ) { 3412 echo apply_filters( 'favorites_link', get_favorites_link( $user_id ) ); 3413 } 3414 3415 function get_favorites_link( $user_id = 0 ) { 3416 if ( !$user_id ) 3417 $user_id = bb_get_current_user_info( 'id' ); 3418 return apply_filters( 'get_favorites_link', get_profile_tab_link($user_id, 'favorites'), $user_id ); 3419 } 3420 3421 function user_favorites_link($add = array(), $rem = array(), $user_id = 0) { 3422 global $topic, $bb_current_user; 3423 if ( empty($add) || !is_array($add) ) 3424 $add = array('mid' => __('Add this topic to your favorites'), 'post' => __(' (%?%)')); 3425 if ( empty($rem) || !is_array($rem) ) 3426 $rem = array( 'pre' => __('This topic is one of your %favorites% ['), 'mid' => __('×'), 'post' => __(']')); 3427 if ( $user_id ) : 3428 if ( !bb_current_user_can( 'edit_favorites_of', (int) $user_id ) ) 3429 return false; 3430 if ( !$user = bb_get_user( bb_get_user_id( $user_id ) ) ) : 3431 return false; 3432 endif; 3433 else : 3434 if ( !bb_current_user_can('edit_favorites') ) 3435 return false; 3436 $user =& $bb_current_user->data; 3437 endif; 3438 3439 $url = esc_url( get_favorites_link( $user_id ) ); 3440 if ( $is_fav = is_user_favorite( $user->ID, $topic->topic_id ) ) : 3441 $rem = preg_replace('|%(.+)%|', "<a href='$url'>$1</a>", $rem); 3442 $favs = array('fav' => '0', 'topic_id' => $topic->topic_id); 3443 $pre = ( is_array($rem) && isset($rem['pre']) ) ? $rem['pre'] : ''; 3444 $mid = ( is_array($rem) && isset($rem['mid']) ) ? $rem['mid'] : ( is_string($rem) ? $rem : '' ); 3445 $post = ( is_array($rem) && isset($rem['post']) ) ? $rem['post'] : ''; 3446 elseif ( false === $is_fav ) : 3447 $add = preg_replace('|%(.+)%|', "<a href='$url'>$1</a>", $add); 3448 $favs = array('fav' => '1', 'topic_id' => $topic->topic_id); 3449 $pre = ( is_array($add) && isset($add['pre']) ) ? $add['pre'] : ''; 3450 $mid = ( is_array($add) && isset($add['mid']) ) ? $add['mid'] : ( is_string($add) ? $add : '' ); 3451 $post = ( is_array($add) && isset($add['post']) ) ? $add['post'] : ''; 3452 endif; 3453 3454 $url = esc_url( bb_nonce_url( add_query_arg( $favs, get_favorites_link( $user_id ) ), 'toggle-favorite_' . $topic->topic_id ) ); 3455 3456 if ( !is_null($is_fav) ) 3457 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>"; 3458 } 3459 3460 function favorites_rss_link( $id = 0, $context = 0 ) { 3461 if (!$context || !is_integer($context)) { 3462 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3463 } 3464 echo apply_filters('favorites_rss_link', get_favorites_rss_link( $id, $context ), $context, $id); 3465 } 3466 3467 function get_favorites_rss_link( $id = 0, $context = 0 ) { 3468 $user = bb_get_user( bb_get_user_id( $id ) ); 3469 3470 if (!$context || !is_integer($context)) { 3471 $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED; 3472 } 3473 3474 $rewrite = bb_get_option( 'mod_rewrite' ); 3475 if ( $rewrite ) { 3476 if ( $rewrite === 'slugs' ) { 3477 $column = 'user_nicename'; 3478 } else { 3479 $column = 'ID'; 3480 } 3481 $link = bb_get_uri('rss/profile/' . $user->$column, null, $context); 3482 } else { 3483 $link = bb_get_uri('rss.php', array('profile' => $user->ID), $context); 3484 } 3485 return apply_filters( 'get_favorites_rss_link', $link, $user->ID, $context ); 3486 } 3487 3488 function favorites_pages( $args = null ) 3489 { 3490 $defaults = array( 'before' => '', 'after' => '' ); 3491 $args = wp_parse_args( $args, $defaults ); 3492 3493 global $page, $user, $favorites_total; 3494 if ( $pages = apply_filters( 'favorites_pages', get_page_number_links( $page, $favorites_total ), $user->user_id ) ) { 3495 echo $args['before'] . $pages . $args['after']; 3496 } 3497 } 3498 3499 //SUBSCRIPTION 3500 3501 /** 3502 * Checks if subscription is enabled. 3503 * 3504 * @since 1.1 3505 * 3506 * @return bool is subscription enabled or not 3507 */ 3508 function bb_is_subscriptions_active() { 3509 return (bool) bb_get_option( 'enable_subscriptions' ); 3510 } 3511 3512 /** 3513 * Checks if user is subscribed to current topic. 3514 * 3515 * @since 1.1 3516 * 3517 * @return bool is user subscribed or not 3518 */ 3519 function bb_is_user_subscribed( $args = null ) { 3520 global $bbdb; 3521 3522 $defaults = array( 3523 'user_id' => bb_is_topic_edit() ? bb_get_user_id( get_post_author_id() ) : bb_get_current_user_info( 'id' ), 3524 'topic_id' => get_topic_id() 3525 ); 3526 $args = wp_parse_args( $args, $defaults ); 3527 extract( $args, EXTR_SKIP ); 3528 3529 $there = $bbdb->get_var( $bbdb->prepare( "SELECT `$bbdb->term_relationships`.`object_id` 3530 FROM $bbdb->term_relationships, $bbdb->term_taxonomy, $bbdb->terms 3531 WHERE `$bbdb->term_relationships`.`object_id` = %d 3532 AND `$bbdb->term_relationships`.`term_taxonomy_id` = `$bbdb->term_taxonomy`.`term_taxonomy_id` 3533 AND `$bbdb->term_taxonomy`.`term_id` = `$bbdb->terms`.`term_id` 3534 AND `$bbdb->term_taxonomy`.`taxonomy` = 'bb_subscribe' 3535 AND `$bbdb->terms`.`slug` = 'topic-%d'", 3536 $user_id, $topic_id ) ); 3537 3538 $there = apply_filters( 'bb_is_user_subscribed', $there, $args ); 3539 3540 if ( $there ) 3541 return true; 3542 3543 return false; 3544 } 3545 3546 /** 3547 * Outputs the subscribe/unsubscibe link. 3548 * 3549 * Checks if user is subscribed and outputs link based on status. 3550 * 3551 * @since 1.1 3552 */ 3553 function bb_user_subscribe_link() { 3554 $topic_id = get_topic_id(); 3555 3556 if ( !bb_is_user_logged_in() ) 3557 return false; 3558 3559 if ( bb_is_user_subscribed() ) 3560 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>'; 3561 else 3562 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>'; 3563 3564 } 3565 3566 /** 3567 * Outputs the post form subscription checkbox. 3568 * 3569 * Checks if user is subscribed and outputs checkbox based on status. 3570 * 3571 * @since 1.1 3572 */ 3573 function bb_user_subscribe_checkbox( $args = null ) { 3574 3575 if ( !bb_is_user_logged_in() ) 3576 return false; 3577 3578 $is_current = false; 3579 $defaults = array( 'tab' => false ); 3580 $args = wp_parse_args( $args, $defaults ); 3581 $tab = $args['tab'] !== false ? ' tabindex="' . $args['tab'] . '"' : ''; 3582 $is_current = bb_get_user_id( get_post_author_id() ) == bb_get_current_user_info( 'id' ); 3583 3584 // Change subscription checkbox message if current or moderating 3585 if ( bb_is_topic_edit() && !$is_current ) 3586 $text = __( 'This user should be notified of follow-up posts via email' ); 3587 else 3588 $text = __( 'Notify me of follow-up posts via email' ); 3589 3590 echo ' 3591 <label for="subscription_checkbox"> 3592 <input name="subscription_checkbox" id="subscription_checkbox" type="checkbox" value="subscribe" ' . checked( true, bb_is_user_subscribed(), false ) . $tab . ' /> 3593 ' . apply_filters( 'bb_user_subscribe_checkbox_label', $text, (bool) $is_current ) . ' 3594 </label>'; 3595 3596 } 3597 3598 //VIEWS 3599 function view_name( $view = '' ) { // Filtration should be done at bb_register_view() 3600 echo get_view_name( $view ); 3601 } 3602 3603 function get_view_name( $_view = '' ) { 3604 global $view, $bb_views; 3605 if ( $_view ) 3606 $v = bb_slug_sanitize($_view); 3607 else 3608 $v =& $view; 3609 3610 if ( isset($bb_views[$v]) ) 3611 return $bb_views[$v]['title']; 3612 } 3613 3614 function view_pages() { 3615 global $page, $view_count; 3616 echo apply_filters( 'view_pages', get_page_number_links( $page, $view_count ) ); 3617 } 3618 3619 function view_link( $_view = false, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 3620 echo get_view_link( $_view, $page, $context ); 3621 } 3622 3623 function get_view_link( $_view = false, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) { 3624 global $view, $bb_views; 3625 if ( $_view ) 3626 $v = bb_slug_sanitize($_view); 3627 else 3628 $v =& $view; 3629 3630 if (!$context || !is_integer($context)) { 3631 $context = BB_URI_CONTEXT_A_HREF; 3632 } 3633 3634 if ( !array_key_exists($v, $bb_views) ) 3635 return bb_get_uri(null, null, $context); 3636 if ( bb_get_option('mod_rewrite') ) { 3637 $page = ( 1 < $page ) ? '/page/' . $page : ''; 3638 $link = bb_get_uri('view/' . $v . $page, null, $context); 3639 } else { 3640 $query = array( 3641 'view' => $v, 3642 'page' => ( 1 < $page ) ? $page : false, 3643 ); 3644 $link = bb_get_uri('view.php', $query, $context); 3645 } 3646 3647 return apply_filters( 'get_view_link', $link, $v, $page, $context ); 3648 } 3649 3650 function _bb_parse_time_function_args( $args ) { 3651 if ( is_numeric($args) ) 3652 $args = array('id' => $args); 3653 elseif ( $args && is_string($args) && false === strpos($args, '=') ) 3654 $args = array('format' => $args); 3655 3656 $defaults = array( 'id' => 0, 'format' => 'since', 'more' => 0, 'localize' => true ); 3657 return wp_parse_args( $args, $defaults ); 3658 } 3659 3660 function _bb_time_function_return( $time, $args ) { 3661 $time = bb_gmtstrtotime( $time ); 3662 3663 switch ( $format = $args['format'] ) : 3664 case 'since' : 3665 return bb_since( $time, $args['more'] ); 3666 break; 3667 case 'timestamp' : 3668 $format = 'U'; 3669 break; 3670 case 'mysql' : 3671 $format = 'Y-m-d H:i:s'; 3672 break; 3673 case 'datetime' : 3674 $format = bb_get_option( 'datetime_format' ); 3675 break; 3676 endswitch; 3677 3678 return $args['localize'] ? bb_gmdate_i18n( $format, $time ) : gmdate( $format, $time ); 3679 } 3680 3681 function bb_template_scripts() { 3682 if ( bb_is_topic() && bb_is_user_logged_in() ) 3683 wp_enqueue_script( 'topic' ); 3684 elseif ( bb_is_profile() && bb_is_user_logged_in() ) { 3685 global $self; 3686 if ($self == 'profile-edit.php') { 3687 wp_enqueue_script( 'profile-edit' ); 3688 } 3689 } 3690 } 3691 3692 if ( !function_exists( 'checked' ) ) : 3693 /** 3694 * Outputs the html checked attribute. 3695 * 3696 * Compares the first two arguments and if identical marks as checked 3697 * 3698 * @since 1.1 3699 * 3700 * @param mixed $checked One of the values to compare 3701 * @param mixed $current (true) The other value to compare if not just true 3702 * @param bool $echo Whether to echo or just return the string 3703 * @return string html attribute or empty string 3704 */ 3705 function checked( $checked, $current = true, $echo = true ) { 3706 return __checked_selected_helper( $checked, $current, $echo, 'checked' ); 3707 } 3708 endif; 3709 3710 if ( !function_exists( 'selected' ) ) : 3711 /** 3712 * Outputs the html selected attribute. 3713 * 3714 * Compares the first two arguments and if identical marks as selected 3715 * 3716 * @since 1.1 3717 * 3718 * @param mixed selected One of the values to compare 3719 * @param mixed $current (true) The other value to compare if not just true 3720 * @param bool $echo Whether to echo or just return the string 3721 * @return string html attribute or empty string 3722 */ 3723 function selected( $selected, $current = true, $echo = true ) { 3724 return __checked_selected_helper( $selected, $current, $echo, 'selected' ); 3725 } 3726 endif; 3727 3728 if ( !function_exists( 'disabled' ) ) : 3729 /** 3730 * Outputs the html disabled attribute. 3731 * 3732 * Compares the first two arguments and if identical marks as disabled 3733 * 3734 * @since 1.1 3735 * 3736 * @param mixed $disabled One of the values to compare 3737 * @param mixed $current (true) The other value to compare if not just true 3738 * @param bool $echo Whether to echo or just return the string 3739 * @return string html attribute or empty string 3740 */ 3741 function disabled( $disabled, $current = true, $echo = true ) { 3742 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); 3743 } 3744 endif; 3745 3746 if ( !function_exists( '__checked_selected_helper' ) ) : 3747 /** 3748 * Private helper function for checked, selected, and disabled. 3749 * 3750 * Compares the first two arguments and if identical marks as $type 3751 * 3752 * @since 1.1 3753 * @access private 3754 * 3755 * @param any $helper One of the values to compare 3756 * @param any $current (true) The other value to compare if not just true 3757 * @param bool $echo Whether to echo or just return the string 3758 * @param string $type The type of checked|selected|disabled we are doing 3759 * @return string html attribute or empty string 3760 */ 3761 function __checked_selected_helper( $helper, $current, $echo, $type ) { 3762 if ( (string) $helper === (string) $current ) 3763 $result = " $type='$type'"; 3764 else 3765 $result = ''; 3766 3767 if ( $echo ) 3768 echo $result; 3769 3770 return $result; 3771 } 3772 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:58:21 2012 | Hosted by follow the white rabbit. |