PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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

Large files files are truncated, but you can click here to view the full file

  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()

Large files files are truncated, but you can click here to view the full file