/bp-forums/bbpress/bb-includes/functions.bb-template.php

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