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