PageRenderTime 77ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 1ms

/wp-content/plugins/buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php

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