PageRenderTime 31ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/www/forum/bb-includes/template-functions.php

https://github.com/micz/elencode
PHP | 2265 lines | 1910 code | 323 blank | 32 comment | 318 complexity | f1dae6eb375b291f97cff31ff3d297e2 MD5 | raw file
Possible License(s): GPL-2.0

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

  1. <?php
  2. function bb_load_template( $file, $globals = false ) {
  3. global $bb, $bbdb, $bb_current_user, $page, $bb_cache,
  4. $posts, $bb_post, $post_id, $topics, $topic, $topic_id,
  5. $forums, $forum, $forum_id, $tags, $tag, $tag_name, $user, $user_id, $view,
  6. $del_class, $bb_alt;
  7. if ( $globals )
  8. foreach ( $globals as $global => $v )
  9. if ( !is_numeric($global) )
  10. $$global = $v;
  11. else
  12. global $$v;
  13. $template = apply_filters( 'bb_template', bb_get_template( $file ), $file );
  14. include($template);
  15. }
  16. function bb_get_template( $file ) {
  17. if ( file_exists( bb_get_active_theme_directory() . $file) )
  18. return bb_get_active_theme_directory() . $file;
  19. return BB_DEFAULT_THEME_DIR . $file;
  20. }
  21. function bb_get_header() {
  22. bb_load_template( 'header.php' );
  23. }
  24. function bb_language_attributes( $xhtml = 0 ) {
  25. $output = '';
  26. if ( $dir = bb_get_option('text_direction') )
  27. $output = "dir=\"$dir\" ";
  28. if ( $lang = bb_get_option('language') ) {
  29. $output .= "xml:lang=\"$lang\" ";
  30. if ( $xhtml < '1.1' )
  31. $output .= "lang=\"$lang\"";
  32. }
  33. echo ' ' . rtrim($output);
  34. }
  35. function bb_stylesheet_uri( $stylesheet = '' ) {
  36. echo wp_specialchars( bb_get_stylesheet_uri( $stylesheet ) );
  37. }
  38. function bb_get_stylesheet_uri( $stylesheet = '' ) {
  39. if ( 'rtl' == $stylesheet )
  40. $css_file = 'style-rtl.css';
  41. else
  42. $css_file = 'style.css';
  43. $active_theme = bb_get_active_theme_directory();
  44. if ( file_exists( $active_theme . 'style.css' ) )
  45. $r = bb_get_active_theme_uri() . $css_file;
  46. else
  47. $r = BB_DEFAULT_THEME_URL . $css_file;
  48. return apply_filters( 'bb_get_stylesheet_uri', $r, $stylesheet );
  49. }
  50. function bb_active_theme_uri() {
  51. echo bb_get_active_theme_uri();
  52. }
  53. function bb_get_active_theme_uri() {
  54. if ( !$active_theme = bb_get_option( 'bb_active_theme' ) )
  55. $active_theme_uri = BB_DEFAULT_THEME_URL;
  56. else
  57. $active_theme_uri = bb_get_theme_uri( $active_theme );
  58. return apply_filters( 'bb_get_active_theme_uri', $active_theme_uri );
  59. }
  60. function bb_get_theme_uri( $theme = false ) {
  61. if ( !$theme ) {
  62. $theme_uri = BB_THEME_URL;
  63. } else {
  64. $theme_uri = str_replace(
  65. array('core#', 'user#'),
  66. array(BB_CORE_THEME_URL, BB_THEME_URL),
  67. $theme
  68. ) . '/';
  69. }
  70. return apply_filters( 'bb_get_theme_uri', $theme_uri, $theme );
  71. }
  72. function bb_get_footer() {
  73. bb_load_template( 'footer.php' );
  74. }
  75. function bb_head() {
  76. do_action('bb_head');
  77. }
  78. function profile_menu() {
  79. global $user_id, $profile_menu, $self, $profile_page_title;
  80. $list = "<ul id='profile-menu'>";
  81. $list .= "\n\t<li" . ( ( $self ) ? '' : ' class="current"' ) . '><a href="' . attribute_escape( get_user_profile_link( $user_id ) ) . '">' . __('Profile') . '</a></li>';
  82. $id = bb_get_current_user_info( 'id' );
  83. foreach ($profile_menu as $item) {
  84. // 0 = name, 1 = users cap, 2 = others cap, 3 = file
  85. $class = '';
  86. if ( $item[3] == $self ) {
  87. $class = ' class="current"';
  88. $profile_page_title = $item[0];
  89. }
  90. if ( can_access_tab( $item, $id, $user_id ) )
  91. if ( file_exists($item[3]) || is_callable($item[3]) )
  92. $list .= "\n\t<li$class><a href='" . attribute_escape( get_profile_tab_link($user_id, $item[4]) ) . "'>{$item[0]}</a></li>";
  93. }
  94. $list .= "\n</ul>";
  95. echo $list;
  96. }
  97. function login_form() {
  98. if ( bb_is_user_logged_in() )
  99. bb_load_template( 'logged-in.php' );
  100. else
  101. bb_load_template( 'login-form.php', array('user_login', 'remember_checked', 'redirect_to', 're') );
  102. }
  103. function search_form( $q = '' ) {
  104. bb_load_template( 'search-form.php', array('q' => $q) );
  105. }
  106. function bb_post_template() {
  107. bb_load_template( 'post.php' );
  108. }
  109. function post_form( $h2 = '' ) {
  110. global $page, $topic, $forum;
  111. $add = topic_pages_add();
  112. if ( empty($h2) && false !== $h2 ) {
  113. if ( is_topic() )
  114. $h2 = __('Reply');
  115. elseif ( is_forum() )
  116. $h2 = __('New Topic in this Forum');
  117. elseif ( is_bb_tag() || is_front() )
  118. $h2 = __('Add New Topic');
  119. }
  120. $last_page = get_page_number( $topic->topic_posts + $add );
  121. if ( !empty($h2) ) {
  122. if ( is_topic() && $page != $last_page )
  123. $h2 = $h2 . ' <a href="' . attribute_escape( get_topic_link( 0, $last_page ) . '#postform' ) . '">&raquo;</a>';
  124. echo '<h2 class="post-form">' . $h2 . '</h2>' . "\n";
  125. }
  126. do_action('pre_post_form');
  127. if ( ( is_topic() && bb_current_user_can( 'write_post', $topic->topic_id ) && $page == $last_page ) || ( !is_topic() && bb_current_user_can( 'write_topic', $forum->forum_id ) ) ) {
  128. echo '<form class="postform post-form" id="postform" method="post" action="' . bb_get_option('uri') . 'bb-post.php">' . "\n";
  129. echo "<fieldset>\n";
  130. bb_load_template( 'post-form.php', array('h2' => $h2) );
  131. bb_nonce_field( is_topic() ? 'create-post_' . $topic->topic_id : 'create-topic' );
  132. if ( is_forum() )
  133. echo '<input type="hidden" name="forum_id" value="' . $forum->forum_id . '" />' . "\n";
  134. else if ( is_topic() )
  135. echo '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "\n";
  136. do_action('post_form');
  137. echo "\n</fieldset>\n</form>\n";
  138. } elseif ( !bb_is_user_logged_in() ) {
  139. echo '<p>';
  140. printf(__('You must <a href="%s">log in</a> to post.'), attribute_escape( bb_get_option('uri') . 'bb-login.php' ));
  141. echo '</p>';
  142. }
  143. do_action('post_post_form');
  144. }
  145. function edit_form() {
  146. global $bb_post;
  147. do_action('pre_edit_form');
  148. echo "<form class='postform edit-form' method='post' action='" . bb_get_option('uri') . "bb-edit.php'>\n";
  149. echo "<fieldset>\n";
  150. bb_load_template( 'edit-form.php', array('topic_title') );
  151. bb_nonce_field( 'edit-post_' . $bb_post->post_id );
  152. do_action('edit_form');
  153. echo "\n</fieldset>\n</form>\n";
  154. do_action('post_edit_form');
  155. }
  156. function alt_class( $key, $others = '' ) {
  157. echo get_alt_class( $key, $others );
  158. }
  159. function get_alt_class( $key, $others = '' ) {
  160. global $bb_alt;
  161. $class = '';
  162. if ( !isset( $bb_alt[$key] ) ) $bb_alt[$key] = -1;
  163. ++$bb_alt[$key];
  164. $others = trim($others);
  165. if ( $others xor $bb_alt[$key] % 2 )
  166. $class = ' class="' . ( ($others) ? $others : 'alt' ) . '"';
  167. elseif ( $others && $bb_alt[$key] % 2 )
  168. $class = ' class="' . $others . ' alt"';
  169. return $class;
  170. }
  171. function bb_location() {
  172. echo apply_filters( 'bb_location', bb_get_location() );
  173. }
  174. function bb_get_location() { // Not for display. Do not internationalize.
  175. $file = '';
  176. foreach ( array($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_FILENAME'], $_SERVER['SCRIPT_NAME']) as $name )
  177. if ( false !== strpos($name, '.php') )
  178. $file = $name;
  179. switch ( bb_find_filename( $file ) ) :
  180. case 'index.php' :
  181. return 'front-page';
  182. break;
  183. case 'forum.php' :
  184. return 'forum-page';
  185. break;
  186. case 'tags.php' :
  187. return 'tag-page';
  188. break;
  189. case 'edit.php' :
  190. case 'topic.php' :
  191. return 'topic-page';
  192. break;
  193. case 'rss.php' :
  194. return 'feed-page';
  195. break;
  196. case 'search.php' :
  197. return 'search-page';
  198. break;
  199. case 'profile.php' :
  200. return 'profile-page';
  201. break;
  202. case 'favorites.php' :
  203. return 'favorites-page';
  204. break;
  205. case 'view.php' :
  206. return 'view-page';
  207. break;
  208. case 'statistics.php' :
  209. return 'stats-page';
  210. break;
  211. case 'bb-login.php' :
  212. return 'login-page';
  213. break;
  214. case 'register.php' :
  215. return 'register-page';
  216. break;
  217. default:
  218. return apply_filters( 'bb_get_location', '', $file );
  219. break;
  220. endswitch;
  221. }
  222. function is_front() {
  223. return 'front-page' == bb_get_location();
  224. }
  225. function is_forum() {
  226. return 'forum-page' == bb_get_location();
  227. }
  228. function is_bb_tags() {
  229. return 'tag-page' == bb_get_location();
  230. }
  231. function is_bb_tag() {
  232. global $tag, $tag_name;
  233. return $tag && $tag_name && is_bb_tags();
  234. }
  235. function is_topic() {
  236. return 'topic-page' == bb_get_location();
  237. }
  238. function is_bb_feed() {
  239. return 'feed-page' == bb_get_location();
  240. }
  241. function is_bb_search() {
  242. return 'search-page' == bb_get_location();
  243. }
  244. function is_bb_profile() {
  245. return 'profile-page' == bb_get_location();
  246. }
  247. function is_bb_favorites() {
  248. return 'favorites-page' == bb_get_location();
  249. }
  250. function is_view() {
  251. return 'view-page' == bb_get_location();
  252. }
  253. function is_bb_stats() {
  254. return 'stats-page' == bb_get_location();
  255. }
  256. function is_bb_admin() {
  257. if ( defined('BB_IS_ADMIN') )
  258. return BB_IS_ADMIN;
  259. return false;
  260. }
  261. function bb_title( $args = '' ) {
  262. echo apply_filters( 'bb_title', bb_get_title( $args ) );
  263. }
  264. function bb_get_title( $args = '' ) {
  265. $defaults = array(
  266. 'separator' => ' &laquo; ',
  267. 'order' => 'normal',
  268. 'front' => ''
  269. );
  270. $args = wp_parse_args( $args, $defaults );
  271. $title = array();
  272. switch ( bb_get_location() ) {
  273. case 'front-page':
  274. if ( !empty( $args['front'] ) )
  275. $title[] = $args['front'];
  276. break;
  277. case 'topic-page':
  278. $title[] = get_topic_title();
  279. break;
  280. case 'forum-page':
  281. $title[] = get_forum_name();
  282. break;
  283. case 'tag-page':
  284. if ( is_bb_tag() )
  285. $title[] = wp_specialchars( bb_get_tag_name() );
  286. $title[] = __('Tags');
  287. break;
  288. case 'profile-page':
  289. $title[] = get_user_name();
  290. break;
  291. case 'view-page':
  292. $title[] = get_view_name();
  293. break;
  294. }
  295. if ( $st = bb_get_option( 'static_title' ) )
  296. $title = array( $st );
  297. $title[] = bb_get_option( 'name' );
  298. if ( 'reversed' == $args['order'] )
  299. $title = array_reverse( $title );
  300. return apply_filters( 'bb_get_title', implode( $args['separator'], $title ) );
  301. }
  302. function bb_feed_head() {
  303. $feeds = array();
  304. switch (bb_get_location()) {
  305. case 'profile-page':
  306. if ( $tab = isset($_GET['tab']) ? $_GET['tab'] : get_path(2) )
  307. if ($tab != 'favorites')
  308. break;
  309. $feeds[] = array(
  310. 'title' => sprintf(__('User Favorites: %s'), get_user_name()),
  311. 'href' => get_favorites_rss_link()
  312. );
  313. break;
  314. case 'topic-page':
  315. $feeds[] = array(
  316. 'title' => sprintf(__('Topic: %s'), get_topic_title()),
  317. 'href' => get_topic_rss_link()
  318. );
  319. break;
  320. case 'tag-page':
  321. if (is_bb_tag()) {
  322. $feeds[] = array(
  323. 'title' => sprintf(__('Tag: %s'), bb_get_tag_name()),
  324. 'href' => bb_get_tag_rss_link()
  325. );
  326. }
  327. break;
  328. case 'forum-page':
  329. $feeds[] = array(
  330. 'title' => sprintf(__('Forum: %s - Recent Posts'), get_forum_name()),
  331. 'href' => get_forum_rss_link()
  332. );
  333. $feeds[] = array(
  334. 'title' => sprintf(__('Forum: %s - Recent Topics'), get_forum_name()),
  335. 'href' => bb_get_forum_topics_rss_link()
  336. );
  337. break;
  338. case 'front-page':
  339. $feeds[] = array(
  340. 'title' => __('Recent Posts'),
  341. 'href' => bb_get_posts_rss_link()
  342. );
  343. $feeds[] = array(
  344. 'title' => __('Recent Topics'),
  345. 'href' => bb_get_topics_rss_link()
  346. );
  347. break;
  348. case 'view-page':
  349. global $bb_views, $view;
  350. if ($bb_views[$view]['feed']) {
  351. $feeds[] = array(
  352. 'title' => get_view_name(),
  353. 'href' => bb_get_view_rss_link()
  354. );
  355. }
  356. break;
  357. }
  358. if (count($feeds)) {
  359. $feed_links = array();
  360. foreach ($feeds as $feed) {
  361. $link = '<link rel="alternate" type="application/rss+xml" ';
  362. $link .= 'title="' . attribute_escape($feed['title']) . '" ';
  363. $link .= 'href="' . attribute_escape($feed['href']) . '" />';
  364. $feed_links[] = $link;
  365. }
  366. $feed_links = join("\n", $feed_links);
  367. } else {
  368. $feed_links = '';
  369. }
  370. echo apply_filters('bb_feed_head', $feed_links);
  371. }
  372. function bb_get_posts_rss_link() {
  373. if ( bb_get_option( 'mod_rewrite' ) )
  374. $link = bb_get_option( 'uri' ) . 'rss/';
  375. else
  376. $link = bb_get_option( 'uri' ) . 'rss.php';
  377. return apply_filters( 'bb_get_posts_rss_link', $link );
  378. }
  379. function bb_get_topics_rss_link() {
  380. if ( bb_get_option( 'mod_rewrite' ) )
  381. $link = bb_get_option( 'uri' ) . 'rss/topics';
  382. else
  383. $link = bb_get_option( 'uri' ) . 'rss.php?topics=1';
  384. return apply_filters( 'bb_get_topics_rss_link', $link );
  385. }
  386. function bb_get_view_rss_link() {
  387. global $view;
  388. if ( bb_get_option( 'mod_rewrite' ) )
  389. $link = bb_get_option( 'uri' ) . 'rss/view/' . $view;
  390. else
  391. $link = bb_get_option( 'uri' ) . 'rss.php?view=' . $view;
  392. return apply_filters( 'bb_get_view_rss_link', $link );
  393. }
  394. // FORUMS
  395. function forum_id( $forum_id = 0 ) {
  396. echo apply_filters( 'forum_id', get_forum_id( $forum_id ) );
  397. }
  398. function get_forum_id( $forum_id = 0 ) {
  399. global $forum;
  400. $forum_id = (int) $forum_id;
  401. if ( $forum_id )
  402. $_forum = get_forum( $forum_id );
  403. else
  404. $_forum =& $forum;
  405. return $_forum->forum_id;
  406. }
  407. function forum_link( $forum_id = 0, $page = 1 ) {
  408. echo apply_filters('forum_link', get_forum_link( $forum_id, $page ), $forum_id );
  409. }
  410. function get_forum_link( $forum_id = 0, $page = 1 ) {
  411. $forum = get_forum( get_forum_id( $forum_id ) );
  412. $rewrite = bb_get_option( 'mod_rewrite' );
  413. if ( $rewrite ) {
  414. if ( $rewrite === 'slugs' ) {
  415. $column = 'forum_slug';
  416. } else {
  417. $column = 'forum_id';
  418. }
  419. $link = bb_get_option( 'uri' ) . "forum/" . $forum->$column . ( 1 < $page ? "/page/$page" : '' );
  420. } else {
  421. $args = array();
  422. $link = bb_get_option( 'uri' ) . 'forum.php';
  423. $args['id'] = $forum->forum_id;
  424. $args['page'] = 1 < $page ? $page : false;
  425. $link = add_query_arg( $args, $link );
  426. }
  427. return apply_filters( 'get_forum_link', $link, $forum->forum_id );
  428. }
  429. function forum_name( $forum_id = 0 ) {
  430. echo apply_filters( 'forum_name', get_forum_name( $forum_id ), $forum_id );
  431. }
  432. function get_forum_name( $forum_id = 0 ) {
  433. $forum = get_forum( get_forum_id( $forum_id ) );
  434. return apply_filters( 'get_forum_name', $forum->forum_name, $forum->forum_id );
  435. }
  436. function forum_description( $args = null ) {
  437. if ( is_numeric($args) )
  438. $args = array( 'id' => $args );
  439. elseif ( $args && is_string($args) && false === strpos($args, '=') )
  440. $args = array( 'before' => $args );
  441. $defaults = array( 'id' => 0, 'before' => ' &#8211; ', 'after' => '' );
  442. $args = wp_parse_args( $args, $defaults );
  443. if ( $desc = apply_filters( 'forum_description', get_forum_description( $args['id'] ), $args['id'], $args ) )
  444. echo $args['before'] . $desc . $args['after'];
  445. }
  446. function get_forum_description( $forum_id = 0 ) {
  447. $forum = get_forum( get_forum_id( $forum_id ) );
  448. return apply_filters( 'get_forum_description', $forum->forum_desc, $forum->forum_id );
  449. }
  450. function get_forum_parent( $forum_id = 0 ) {
  451. $forum = get_forum( get_forum_id( $forum_id ) );
  452. return apply_filters( 'get_forum_parent', $forum->forum_parent, $forum->forum_id );
  453. }
  454. function get_forum_position( $forum_id = 0 ) {
  455. $forum = get_forum( get_forum_id( $forum_id ) );
  456. return apply_filters( 'get_forum_position', $forum->forum_order, $forum->forum_id );
  457. }
  458. function forum_topics( $forum_id = 0 ) {
  459. echo apply_filters( 'forum_topics', get_forum_topics( $forum_id ), $forum_id );
  460. }
  461. function get_forum_topics( $forum_id = 0 ) {
  462. $forum = get_forum( get_forum_id( $forum_id ) );
  463. return apply_filters( 'get_forum_topics', $forum->topics, $forum->forum_id );
  464. }
  465. function forum_posts( $forum_id = 0 ) {
  466. echo apply_filters( 'forum_posts', get_forum_posts( $forum_id ), $forum_id );
  467. }
  468. function get_forum_posts( $forum_id = 0 ) {
  469. $forum = get_forum( get_forum_id( $forum_id ) );
  470. return apply_filters( 'get_forum_posts', $forum->posts, $forum->forum_id );
  471. }
  472. function forum_pages( $forum_id = 0 ) {
  473. global $page;
  474. $forum = get_forum( get_forum_id( $forum_id ) );
  475. echo apply_filters( 'forum_pages', get_page_number_links( $page, $forum->topics ), $forum->forum_topics );
  476. }
  477. function bb_forum_posts_rss_link( $forum_id = 0 ) {
  478. echo apply_filters('bb_forum_posts_rss_link', bb_get_forum_posts_rss_link( $forum_id ) );
  479. }
  480. function bb_get_forum_posts_rss_link( $forum_id = 0 ) {
  481. $forum = get_forum( get_forum_id( $forum_id ) );
  482. $rewrite = bb_get_option( 'mod_rewrite' );
  483. if ( $rewrite ) {
  484. if ( $rewrite === 'slugs' ) {
  485. $column = 'forum_slug';
  486. } else {
  487. $column = 'forum_id';
  488. }
  489. $link = bb_get_option('uri') . 'rss/forum/' . $forum->$column;
  490. } else {
  491. $link = bb_get_option('uri') . 'rss.php?forum=' . $forum->forum_id;
  492. }
  493. return apply_filters( 'bb_get_forum_posts_rss_link', $link, $forum->forum_id );
  494. }
  495. function bb_forum_topics_rss_link( $forum_id = 0 ) {
  496. echo apply_filters('bb_forum_topics_rss_link', bb_get_forum_topics_rss_link( $forum_id ) );
  497. }
  498. function bb_get_forum_topics_rss_link( $forum_id = 0 ) {
  499. $forum = get_forum( get_forum_id( $forum_id ) );
  500. $rewrite = bb_get_option( 'mod_rewrite' );
  501. if ( $rewrite ) {
  502. if ( $rewrite === 'slugs' ) {
  503. $column = 'forum_slug';
  504. } else {
  505. $column = 'forum_id';
  506. }
  507. $link = bb_get_option('uri') . 'rss/forum/' . $forum->$column . '/topics';
  508. } else {
  509. $link = bb_get_option('uri') . 'rss.php?forum=' . $forum->forum_id . '&amp;topics=1';
  510. }
  511. return apply_filters( 'bb_get_forum_topics_rss_link', $link, $forum->forum_id );
  512. }
  513. function bb_get_forum_bread_crumb($args = '') {
  514. $defaults = array(
  515. 'forum_id' => 0,
  516. 'separator' => ' &raquo; ',
  517. 'class' => null
  518. );
  519. $args = wp_parse_args($args, $defaults);
  520. extract($args, EXTR_SKIP);
  521. $trail = '';
  522. $trail_forum = get_forum(get_forum_id($forum_id));
  523. if ($class) {
  524. $class = ' class="' . $class . '"';
  525. }
  526. $current_trail_forum_id = $trail_forum->forum_id;
  527. while ($trail_forum->forum_id > 0) {
  528. $crumb = $separator;
  529. if ($current_trail_forum_id != $trail_forum->forum_id || !is_forum()) {
  530. $crumb .= '<a' . $class . ' href="' . get_forum_link($trail_forum->forum_id) . '">';
  531. } elseif ($class) {
  532. $crumb .= '<span' . $class . '>';
  533. }
  534. $crumb .= get_forum_name($trail_forum->forum_id);
  535. if ($current_trail_forum_id != $trail_forum->forum_id || !is_forum()) {
  536. $crumb .= '</a>';
  537. } elseif ($class) {
  538. $crumb .= '</span>';
  539. }
  540. $trail = $crumb . $trail;
  541. $trail_forum = get_forum($trail_forum->forum_parent);
  542. }
  543. return apply_filters('bb_get_forum_bread_crumb', $trail, $forum_id );
  544. }
  545. function bb_forum_bread_crumb( $args = '' ) {
  546. echo apply_filters('bb_forum_bread_crumb', bb_get_forum_bread_crumb( $args ) );
  547. }
  548. // Forum Loop //
  549. function &bb_forums( $args = '' ) {
  550. global $bb_forums_loop;
  551. $default_type = 'flat';
  552. if ( is_numeric($args) ) {
  553. $args = array( 'child_of' => $args );
  554. } elseif ( func_num_args() > 1 ) { // bb_forums( 'ul', $args ); Deprecated
  555. $default_type = $args;
  556. $args = func_get_arg(1);
  557. } elseif ( $args && is_string($args) && false === strpos($args, '=') ) {
  558. $args = array( 'type' => $args );
  559. }
  560. // hierarchical not used here. Sent to get_forums for proper ordering.
  561. $args = wp_parse_args( $args, array('hierarchical' => true, 'type' => $default_type, 'walker' => 'BB_Walker_Blank') );
  562. $levels = array( '', '' );
  563. if ( in_array($args['type'], array('list', 'ul')) )
  564. $levels = array( '<ul>', '</ul>' );
  565. $forums = get_forums( $args );
  566. if ( !class_exists($args['walker']) )
  567. $args['walker'] = 'BB_Walker_Blank';
  568. if ( $bb_forums_loop = BB_Loop::start( $forums, $args['walker'] ) ) {
  569. $bb_forums_loop->preserve( array('forum', 'forum_id') );
  570. $bb_forums_loop->walker->db_fields = array( 'id' => 'forum_id', 'parent' => 'forum_parent' );
  571. list($bb_forums_loop->walker->start_lvl, $bb_forums_loop->walker->end_lvl) = $levels;
  572. return $bb_forums_loop->elements;
  573. }
  574. return false;
  575. }
  576. function bb_forum() { // Returns current depth
  577. global $bb_forums_loop;
  578. if ( !is_object($bb_forums_loop) || !is_a($bb_forums_loop, 'BB_Loop') )
  579. return false;
  580. if ( !is_array($bb_forums_loop->elements) )
  581. return false;
  582. if ( $bb_forums_loop->step() ) {
  583. $GLOBALS['forum'] =& $bb_forums_loop->elements[key($bb_forums_loop->elements)]; // Globalize the current forum object
  584. } else {
  585. $bb_forums_loop->reinstate();
  586. return $bb_forums_loop = null; // All done? Kill the object and exit the loop.
  587. }
  588. return $bb_forums_loop->walker->depth;
  589. }
  590. function bb_forum_pad( $pad, $offset = 0 ) {
  591. global $bb_forums_loop;
  592. if ( !is_object($bb_forums_loop) || !is_a($bb_forums_loop, 'BB_Loop') )
  593. return false;
  594. echo $bb_forums_loop->pad( $pad, $offset );
  595. }
  596. function bb_forum_class( $args = null ) {
  597. if ( is_numeric($args) ) // Not used
  598. $args = array( 'id' => $args );
  599. elseif ( $args && is_string($args) && false === strpos($args, '=') )
  600. $args = array( 'class' => $args );
  601. $defaults = array( 'id' => 0, 'key' => 'forum', 'class' => '' );
  602. $args = wp_parse_args( $args, $defaults );
  603. global $bb_forums_loop;
  604. if ( is_object($bb_forums_loop) && is_a($bb_forums_loop, 'BB_Loop') )
  605. $args['class'] .= ' ' . $bb_forums_loop->classes();
  606. echo apply_filters( 'bb_forum_class', get_alt_class( 'forum', $args['class'] ) );
  607. }
  608. // TOPICS
  609. function topic_id( $id = 0 ) {
  610. echo apply_filters( 'topic_id', get_topic_id( $id ) );
  611. }
  612. function get_topic_id( $id = 0 ) {
  613. global $topic;
  614. $id = (int) $id;
  615. if ( $id )
  616. $_topic = get_topic( $id );
  617. else
  618. $_topic =& $topic;
  619. return $_topic->topic_id;
  620. }
  621. function topic_link( $id = 0, $page = 1 ) {
  622. echo apply_filters( 'topic_link', get_topic_link( $id ), $id );
  623. }
  624. function get_topic_link( $id = 0, $page = 1 ) {
  625. $topic = get_topic( get_topic_id( $id ) );
  626. $args = array();
  627. $rewrite = bb_get_option( 'mod_rewrite' );
  628. if ( $rewrite ) {
  629. if ( $rewrite === 'slugs' ) {
  630. $column = 'topic_slug';
  631. } else {
  632. $column = 'topic_id';
  633. }
  634. $link = bb_get_option('uri') . "topic/" . $topic->$column . ( 1 < $page ? "/page/$page" : '' );
  635. } else {
  636. $link = bb_get_option('uri') . 'topic.php';
  637. $args['id'] = $topic->topic_id;
  638. $args['page'] = 1 < $page ? $page : false;
  639. }
  640. if ( $args )
  641. $link = add_query_arg( $args, $link );
  642. return apply_filters( 'get_topic_link', $link, $topic->topic_id );
  643. }
  644. function topic_rss_link( $id = 0 ) {
  645. echo apply_filters('topic_rss_link', get_topic_rss_link($id), $id );
  646. }
  647. function get_topic_rss_link( $id = 0 ) {
  648. $topic = get_topic( get_topic_id( $id ) );
  649. $rewrite = bb_get_option( 'mod_rewrite' );
  650. if ( $rewrite ) {
  651. if ( $rewrite === 'slugs' ) {
  652. $column = 'topic_slug';
  653. } else {
  654. $column = 'topic_id';
  655. }
  656. $link = bb_get_option('uri') . 'rss/topic/' . $topic->$column;
  657. } else {
  658. $link = bb_get_option('uri') . 'rss.php?topic=' . $topic->topic_id;
  659. }
  660. return apply_filters( 'get_topic_rss_link', $link, $topic->topic_id );
  661. }
  662. function bb_topic_labels() {
  663. echo apply_filters( 'bb_topic_labels', null );
  664. }
  665. function topic_title( $id = 0 ) {
  666. echo apply_filters( 'topic_title', get_topic_title( $id ), get_topic_id( $id ) );
  667. }
  668. function get_topic_title( $id = 0 ) {
  669. $topic = get_topic( get_topic_id( $id ) );
  670. return apply_filters( 'get_topic_title', $topic->topic_title, $topic->topic_id );
  671. }
  672. function topic_posts( $id = 0 ) {
  673. echo apply_filters( 'topic_posts', get_topic_posts( $id ), get_topic_id( $id ) );
  674. }
  675. function get_topic_posts( $id = 0 ) {
  676. $topic = get_topic( get_topic_id( $id ) );
  677. return apply_filters( 'get_topic_posts', $topic->topic_posts, $topic->topic_id );
  678. }
  679. function get_topic_deleted_posts( $id = 0 ) {
  680. $topic = get_topic( get_topic_id( $id ) );
  681. return apply_filters( 'get_topic_deleted_posts', $topic->deleted_posts, $topic->topic_id );
  682. }
  683. function topic_noreply( $title ) {
  684. if ( 1 == get_topic_posts() && ( is_front() || is_forum() ) )
  685. $title = "<strong>$title</strong>";
  686. return $title;
  687. }
  688. function topic_last_poster( $id = 0 ) {
  689. $topic = get_topic( get_topic_id( $id ) );
  690. echo apply_filters( 'topic_last_poster', get_topic_last_poster( $id ), $topic->topic_last_poster ); // Last arg = user ID
  691. }
  692. function get_topic_last_poster( $id = 0 ) {
  693. $topic = get_topic( get_topic_id( $id ) );
  694. return apply_filters( 'get_topic_last_poster', $topic->topic_last_poster_name, $topic->topic_last_poster ); // Last arg = user ID
  695. }
  696. function topic_author( $id = 0 ) {
  697. $topic = get_topic( get_topic_id( $id ) );
  698. echo apply_filters( 'topic_author', get_topic_author( $id ), $topic->topic_poster ); // Last arg = user ID
  699. }
  700. function get_topic_author( $id = 0 ) {
  701. $topic = get_topic( get_topic_id( $id ) );
  702. return apply_filters( 'get_topic_author', $topic->topic_poster_name, $topic->topic_poster ); // Last arg = user ID
  703. }
  704. // Filters expect the format to by mysql on both topic_time and get_topic_time
  705. function topic_time( $args = '' ) {
  706. $args = _bb_parse_time_function_args( $args );
  707. $time = apply_filters( 'topic_time', get_topic_time( array('format' => 'mysql') + $args), $args );
  708. echo _bb_time_function_return( $time, $args );
  709. }
  710. function get_topic_time( $args = '' ) {
  711. $args = _bb_parse_time_function_args( $args );
  712. $topic = get_topic( get_topic_id( $args['id'] ) );
  713. $time = apply_filters( 'get_topic_time', $topic->topic_time, $args );
  714. return _bb_time_function_return( $time, $args );
  715. }
  716. function topic_start_time( $args = '' ) {
  717. $args = _bb_parse_time_function_args( $args );
  718. $time = apply_filters( 'topic_start_time', get_topic_start_time( array('format' => 'mysql') + $args), $args );
  719. echo _bb_time_function_return( $time, $args );
  720. }
  721. function get_topic_start_time( $args = '' ) {
  722. $args = _bb_parse_time_function_args( $args );
  723. $topic = get_topic( get_topic_id( $args['id'] ) );
  724. $time = apply_filters( 'get_topic_start_time', $topic->topic_start_time, $args );
  725. return _bb_time_function_return( $time, $args );
  726. }
  727. function topic_last_post_link( $id = 0 ) {
  728. echo apply_filters( 'topic_last_post_link', get_topic_last_post_link( $id ));
  729. }
  730. function get_topic_last_post_link( $id = 0 ){
  731. $topic = get_topic( get_topic_id( $id ) );
  732. $page = get_page_number( $topic->topic_posts );
  733. return apply_filters( 'get_post_link', get_topic_link( $topic->topic_id, $page ) . "#post-$topic->topic_last_post_id", $topic->topic_last_post_id );
  734. }
  735. function topic_pages( $id = 0 ) {
  736. global $page;
  737. $topic = get_topic( get_topic_id( $id ) );
  738. $add = topic_pages_add( $topic->topic_id );
  739. echo apply_filters( 'topic_pages', get_page_number_links( $page, $topic->topic_posts + $add ), $topic->topic_id );
  740. }
  741. function topic_pages_add( $id = 0 ) {
  742. $topic = get_topic( get_topic_id( $id ) );
  743. if ( isset($_GET['view']) && 'all' == $_GET['view'] && bb_current_user_can('browse_deleted') )
  744. $add += $topic->deleted_posts;
  745. return apply_filters( 'topic_pages_add', $add, $topic->topic_id );
  746. }
  747. function get_page_number_links($page, $total) {
  748. $args = array();
  749. $uri = $_SERVER['REQUEST_URI'];
  750. if ( bb_get_option('mod_rewrite') ) {
  751. $format = '/page/%#%';
  752. if ( 1 == $page ) {
  753. if ( false === $pos = strpos($uri, '?') )
  754. $uri = $uri . '%_%';
  755. else
  756. $uri = substr_replace($uri, '%_%', $pos, 0);
  757. } else {
  758. $uri = preg_replace('|/page/[0-9]+|', '%_%', $uri);
  759. }
  760. $uri = str_replace( '/%_%', '%_%', $uri );
  761. } else {
  762. if ( 1 == $page ) {
  763. if ( false === $pos = strpos($uri, '?') ) {
  764. $uri = $uri . '%_%';
  765. $format = '?page=%#%';
  766. } else {
  767. $uri = substr_replace($uri, '?%_%', $pos, 1);
  768. $format = 'page=%#%&';
  769. }
  770. } else {
  771. if ( false === strpos($uri, '?page=') ) {
  772. $uri = preg_replace('!&page=[0-9]+!', '%_%', $uri );
  773. $format = '&page=%#%';
  774. } else {
  775. $uri = preg_replace('!\?page=[0-9]+!', '%_%', $uri );
  776. $format = '?page=%#%';
  777. }
  778. }
  779. }
  780. if ( isset($_GET['view']) && in_array($_GET['view'], bb_get_views()) )
  781. $args['view'] = $_GET['view'];
  782. return paginate_links( array(
  783. 'base' => $uri,
  784. 'format' => $format,
  785. 'total' => ceil($total/bb_get_option('page_topics')),
  786. 'current' => $page,
  787. 'add_args' => $args
  788. ) );
  789. }
  790. function topic_delete_link( $args = '' ) {
  791. $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' );
  792. extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
  793. $id = (int) $id;
  794. $topic = get_topic( get_topic_id( $id ) );
  795. if ( !$topic || !bb_current_user_can( 'delete_topic', $topic->topic_id ) )
  796. return;
  797. if ( 0 == $topic->topic_status )
  798. echo "$before<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-topic.php?id=' . $topic->topic_id , 'delete-topic_' . $topic->topic_id ) ) . "' onclick=\"return confirm('" . js_escape( __('Are you sure you wanna delete that?') ) . "')\">" . __('Delete entire topic') . "</a>$after";
  799. else
  800. echo "$before<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-topic.php?id=' . $topic->topic_id . '&view=all', 'delete-topic_' . $topic->topic_id ) ) . "' onclick=\"return confirm('" . js_escape( __('Are you sure you wanna undelete that?') ) . "')\">" . __('Undelete entire topic') . "</a>$after";
  801. }
  802. function topic_close_link( $args = '' ) {
  803. $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' );
  804. extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
  805. $id = (int) $id;
  806. $topic = get_topic( get_topic_id( $id ) );
  807. if ( !$topic || !bb_current_user_can( 'close_topic', $topic->topic_id ) )
  808. return;
  809. $text = topic_is_open( $topic->topic_id ) ? __('Close topic') : __('Open topic');
  810. echo "$before<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/topic-toggle.php?id=' . $topic->topic_id, 'close-topic_' . $topic->topic_id ) ) . "'>$text</a>$after";
  811. }
  812. function topic_sticky_link( $args = '' ) {
  813. $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' );
  814. extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
  815. $id = (int) $id;
  816. $topic = get_topic( get_topic_id( $id ) );
  817. if ( !$topic || !bb_current_user_can( 'stick_topic', $topic->topic_id ) )
  818. return;
  819. if ( topic_is_sticky( $topic->topic_id ) )
  820. echo "$before<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/sticky.php?id=' . $topic->topic_id, 'stick-topic_' . $topic->topic_id ) ) . "'>". __('Unstick topic') ."</a>$after";
  821. else
  822. echo "$before<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/sticky.php?id=' . $topic->topic_id, 'stick-topic_' . $topic->topic_id ) ) . "'>". __('Stick topic') . "</a> (<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/sticky.php?id=' . $topic->topic_id . '&super=1', 'stick-topic_' . $topic->topic_id ) ) . "'>" . __('to front') . "</a>)$after";
  823. }
  824. function topic_show_all_link( $id = 0 ) {
  825. if ( !bb_current_user_can( 'browse_deleted' ) )
  826. return;
  827. if ( 'all' == @$_GET['view'] )
  828. echo "<a href='" . attribute_escape( get_topic_link( $id ) ) . "'>". __('View normal posts') ."</a>";
  829. else
  830. echo "<a href='" . attribute_escape( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>". __('View all posts') ."</a>";
  831. }
  832. function topic_posts_link( $id = 0 ) {
  833. $topic = get_topic( get_topic_id( $id ) );
  834. $post_num = get_topic_posts( $id );
  835. $posts = sprintf(__ngettext( '%s post', '%s posts', $post_num ), $post_num);
  836. if ( 'all' == @$_GET['view'] && bb_current_user_can('browse_deleted') )
  837. echo "<a href='" . attribute_escape( get_topic_link( $id ) ) . "'>$posts</a>";
  838. else
  839. echo $posts;
  840. if ( bb_current_user_can( 'browse_deleted' ) ) {
  841. $user_id = bb_get_current_user_info( 'id' );
  842. if ( isset($topic->bozos[$user_id]) && 'all' != @$_GET['view'] )
  843. add_filter('get_topic_deleted_posts', create_function('$a', "\$a -= {$topic->bozos[$user_id]}; return \$a;") );
  844. if ( $deleted = get_topic_deleted_posts( $id ) ) {
  845. $extra = sprintf(__('+%d more'), $deleted);
  846. if ( 'all' == @$_GET['view'] )
  847. echo " $extra";
  848. else
  849. echo " <a href='" . attribute_escape( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>$extra</a>";
  850. }
  851. }
  852. }
  853. function topic_move_dropdown( $id = 0 ) {
  854. $topic = get_topic( get_topic_id( $id ) );
  855. if ( !bb_current_user_can( 'move_topic', $topic->topic_id ) )
  856. return;
  857. $dropdown = bb_get_forum_dropdown( array(
  858. 'callback' => 'bb_current_user_can',
  859. 'callback_args' => array('move_topic', $topic->topic_id),
  860. 'selected' => $topic->forum_id
  861. ) );
  862. if ( !$dropdown )
  863. return;
  864. echo '<form id="topic-move" method="post" action="' . bb_get_option('uri') . 'bb-admin/topic-move.php"><fieldset><div>' . "\n\t";
  865. echo "<input type='hidden' name='topic_id' value='$topic->topic_id' />\n\t";
  866. echo '<label for="forum-id">'. __('Move this topic to the selected forum:') . ' ';
  867. echo $dropdown;
  868. echo "</label>\n\t";
  869. bb_nonce_field( 'move-topic_' . $topic->topic_id );
  870. echo "<input type='submit' name='Submit' value='". __('Move') ."' />\n</div></fieldset></form>";
  871. }
  872. function topic_class( $class = '', $key = 'topic', $id = 0 ) {
  873. $topic = get_topic( get_topic_id( $id ) );
  874. $class = $class ? explode(' ', $class ) : array();
  875. if ( '1' === $topic->topic_status && bb_current_user_can( 'browse_deleted' ) )
  876. $class[] = 'deleted';
  877. elseif ( 1 < $topic->topic_status && bb_current_user_can( 'browse_deleted' ) )
  878. $class[] = 'bozo';
  879. if ( '0' === $topic->topic_open )
  880. $class[] = 'closed';
  881. if ( 1 == $topic->topic_sticky && is_forum() )
  882. $class[] = 'sticky';
  883. elseif ( 2 == $topic->topic_sticky && ( is_front() || is_forum() ) )
  884. $class[] = 'sticky super-sticky';
  885. $class = apply_filters( 'topic_class', $class, $topic->topic_id );
  886. $class = join(' ', $class);
  887. alt_class( $key, $class );
  888. }
  889. function new_topic( $args = null ) {
  890. $defaults = array( 'text' => __('Add New &raquo;'), 'forum' => 0, 'tag' => '' );
  891. if ( $args && is_string($args) && false === strpos($args, '=') )
  892. $args = array( 'text' => $args );
  893. $args = wp_parse_args( $args, $defaults );
  894. extract( $args, EXTR_SKIP );
  895. if ( $forum && $forum = get_forum( $forum ) )
  896. $url = get_forum_link( $forum->forum_id ) . '#postform';
  897. elseif ( $tag && ( ( is_numeric($tag) && $tag = bb_get_tag( $tag ) ) || $tag = bb_get_tag_by_name( $tag ) ) )
  898. $url = bb_get_tag_link( $tag->tag ) . '#postform';
  899. elseif ( is_forum() || is_bb_tag() )
  900. $url = '#postform';
  901. elseif ( is_topic() )
  902. $url = get_forum_link() . '#postform';
  903. elseif ( is_front() )
  904. $url = add_query_arg( 'new', '1', bb_get_option( 'uri' ) );
  905. if ( !bb_is_user_logged_in() )
  906. $url = add_query_arg( 're', urlencode($url), bb_get_option( 'uri' ) . 'bb-login.php' );
  907. elseif ( is_forum() || is_topic() ) {
  908. if ( !bb_current_user_can( 'write_topic', get_forum_id() ) )
  909. return;
  910. } else {
  911. if ( !bb_current_user_can( 'write_topics' ) )
  912. return;
  913. }
  914. if ( $url = attribute_escape( apply_filters( 'new_topic_url', $url ) ) )
  915. echo "<a href='$url' class='new-topic'>$text</a>\n";
  916. }
  917. function bb_new_topic_forum_dropdown() {
  918. bb_forum_dropdown( 'bb_current_user_can', array('write_topic') );
  919. }
  920. function bb_topic_search_form( $args = null, $query_obj = null ) {
  921. global $bb_query_form;
  922. if ( $query_obj && is_a($query_obj, 'BB_Query_Form') ); // [sic]
  923. else
  924. $query_obj =& $bb_query_form;
  925. $query_obj->form( $args );
  926. }
  927. /**
  928. * bb_topic_pagecount() - Print the total page count for a topic
  929. *
  930. * @since 0.9
  931. * @param int $topic_id The topic id of the topic being queried
  932. * @return void
  933. **/
  934. function bb_topic_pagecount( $topic_id = 0 ) {
  935. echo bb_get_topic_pagecount( $topic_id );
  936. }
  937. /**
  938. * bb_get_topic_pagecount() - Get the total page count for a topic
  939. *
  940. * @since 0.9
  941. * @param int $topic_id The topic id of the topic being queried
  942. * @return int The total number of pages in the topic
  943. **/
  944. function bb_get_topic_pagecount( $topic_id = 0 ) {
  945. $topic = get_topic( get_topic_id( $topic_id ) );
  946. return get_page_number( $topic->topic_posts + topic_pages_add() );
  947. }
  948. /**
  949. * bb_is_topic_lastpage() - Report whether the current page is the last page of a given topic
  950. *
  951. * @since 0.9
  952. * @param int $topic_id The topic id of the topic being queried
  953. * @return boolean True if called on the last page of a topic, otherwise false
  954. **/
  955. function bb_is_topic_lastpage( $topic_id = 0 ) {
  956. global $page;
  957. return ( $page == bb_get_topic_pagecount( $topic_id ) );
  958. }
  959. // POSTS
  960. function post_id( $post_id = 0 ) {
  961. echo get_post_id( $post_id );
  962. }
  963. function get_post_id( $post_id = 0 ) {
  964. global $bb_post;
  965. $post_id = (int) $post_id;
  966. if ( $post_id )
  967. $post = bb_get_post( $post_id );
  968. else
  969. $post =& $bb_post;
  970. return $post->post_id;
  971. }
  972. function post_link( $post_id = 0 ) {
  973. echo apply_filters( 'post_link', get_post_link( $post_id ), get_post_id( $post_id ) );
  974. }
  975. function get_post_link( $post_id = 0 ) {
  976. $bb_post = bb_get_post( get_post_id( $post_id ) );
  977. $page = get_page_number( $bb_post->post_position );
  978. return apply_filters( 'get_post_link', get_topic_link( $bb_post->topic_id, $page ) . "#post-$bb_post->post_id", $bb_post->post_id );
  979. }
  980. function post_anchor_link( $force_full = false ) {
  981. if ( defined('DOING_AJAX') || $force_full )
  982. post_link();
  983. else
  984. echo '#post-' . get_post_id();
  985. }
  986. function post_author( $post_id = 0 ) {
  987. echo apply_filters('post_author', get_post_author( $post_id ) );
  988. }
  989. function get_post_author( $post_id = 0 ) {
  990. if ( $user = bb_get_user( get_post_author_id( $post_id ) ) )
  991. return apply_filters( 'get_post_author', $user->user_login, $user->ID );
  992. else
  993. return __('Anonymous');
  994. }
  995. function post_author_link( $post_id = 0 ) {
  996. if ( $link = get_user_link( get_post_author_id( $post_id ) ) ) {
  997. echo '<a href="' . attribute_escape( $link ) . '">' . get_post_author( $post_id ) . '</a>';
  998. } else {
  999. post_author( $post_id );
  1000. }
  1001. }
  1002. function post_author_avatar( $size = '48', $default = '', $post_id = 0 ) {
  1003. if ( ! bb_get_option('avatars_show') )
  1004. return false;
  1005. $author_id = get_post_author_id( $post_id );
  1006. if ( $link = get_user_link( $author_id ) ) {
  1007. echo '<a href="' . attribute_escape( $link ) . '">' . bb_get_avatar( $author_id, $size, $default ) . '</a>';
  1008. } else {
  1009. echo bb_get_avatar( $author_id, $size, $default );
  1010. }
  1011. }
  1012. function post_text( $post_id = 0 ) {
  1013. echo apply_filters( 'post_text', get_post_text( $post_id ), get_post_id( $post_id ) );
  1014. }
  1015. function get_post_text( $post_id = 0 ) {
  1016. $bb_post = bb_get_post( get_post_id( $post_id ) );
  1017. return apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id );
  1018. }
  1019. function bb_post_time( $args = '' ) {
  1020. $args = _bb_parse_time_function_args( $args );
  1021. $time = apply_filters( 'bb_post_time', bb_get_post_time( array('format' => 'mysql') + $args ), $args );
  1022. echo _bb_time_function_return( $time, $args );
  1023. }
  1024. function bb_get_post_time( $args = '' ) {
  1025. $args = _bb_parse_time_function_args( $args );
  1026. $bb_post = bb_get_post( get_post_id( $args['id'] ) );
  1027. $time = apply_filters( 'bb_get_post_time', $bb_post->post_time, $args );
  1028. return _bb_time_function_return( $time, $args );
  1029. }
  1030. function post_ip( $post_id = 0 ) {
  1031. if ( bb_current_user_can( 'view_by_ip' ) )
  1032. echo apply_filters( 'post_ip', get_post_ip( $post_id ), get_post_id( $post_id ) );
  1033. }
  1034. function get_post_ip( $post_id = 0 ) {
  1035. $bb_post = bb_get_post( get_post_id( $post_id ) );
  1036. return apply_filters( 'get_post_ip', $bb_post->poster_ip, $bb_post->post_id );
  1037. }
  1038. function post_ip_link( $post_id = 0 ) {
  1039. if ( !bb_current_user_can( 'view_by_ip' ) )
  1040. return;
  1041. $link = '<a href="' . attribute_escape( bb_get_option('uri') . 'bb-admin/view-ip.php?ip=' . get_post_ip( $post_id ) ) . '">' . get_post_ip( $post_id ) . '</a>';
  1042. echo apply_filters( 'post_ip_link', $link, get_post_id( $post_id ) );
  1043. }
  1044. function post_edit_link( $post_id = 0 ) {
  1045. $bb_post = bb_get_post( get_post_id( $post_id ) );
  1046. if ( bb_current_user_can( 'edit_post', $bb_post->post_id ) )
  1047. echo "<a href='" . attribute_escape( apply_filters( 'post_edit_uri', bb_get_option('uri') . 'edit.php?id=' . $bb_post->post_id, $bb_post->post_id ) ) . "'>". __('Edit') ."</a>";
  1048. }
  1049. function post_del_class( $post_id = 0 ) {
  1050. $bb_post = bb_get_post( get_post_id( $post_id ) );
  1051. switch ( $bb_post->post_status ) :
  1052. case 0 : return ''; break;
  1053. case 1 : return 'deleted'; break;
  1054. default: return apply_filters( 'post_del_class', $bb_post->post_status, $bb_post->post_id );
  1055. endswitch;
  1056. }
  1057. function post_delete_link( $post_id = 0 ) {
  1058. $bb_post = bb_get_post( get_post_id( $post_id ) );
  1059. if ( !bb_current_user_can( 'delete_post', $bb_post->post_id ) )
  1060. return;
  1061. if ( 1 == $bb_post->post_status )
  1062. $r = "<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-post.php?id=' . $bb_post->post_id . '&status=0&view=all', 'delete-post_' . $bb_post->post_id ) ) . "' onclick='return confirm(\" ". js_escape( __('Are you sure you wanna undelete that?') ) ." \");'>". __('Undelete') ."</a>";
  1063. else
  1064. $r = "<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-post.php?id=' . $bb_post->post_id . '&status=1', 'delete-post_' . $bb_post->post_id ) ) . "' onclick='return ajaxPostDelete(" . $bb_post->post_id . ", \"" . get_post_author( $post_id ) . "\", this);'>". __('Delete') ."</a>";
  1065. $r = apply_filters( 'post_delete_link', $r, $bb_post->post_status, $bb_post->post_id );
  1066. echo $r;
  1067. }
  1068. function post_author_id( $post_id = 0 ) {
  1069. echo apply_filters( 'post_author_id', get_post_author_id( $post_id ), get_post_id( $post_id ) );
  1070. }
  1071. function get_post_author_id( $post_id = 0 ) {
  1072. $bb_post = bb_get_post( get_post_id( $post_id ) );
  1073. return apply_filters( 'get_post_author_id', (int) $bb_post->poster_id, get_post_id( $post_id ) );
  1074. }
  1075. function post_author_title( $post_id = 0 ) {
  1076. $title = get_post_author_title( $post_id );
  1077. if ( false === $title )
  1078. $r = __('Unregistered'); // This should never happen
  1079. else
  1080. $r = '<a href="' . attribute_escape( get_user_profile_link( get_post_author_id( $post_id ) ) ) . '">' . $title . '</a>';
  1081. echo apply_filters( 'post_author_title', $r, get_post_id( $post_id ) );
  1082. }
  1083. function get_post_author_title( $post_id = 0 ) {
  1084. return get_user_title( get_post_author_id( $post_id ) );
  1085. }
  1086. function post_author_type( $post_id = 0 ) {
  1087. $id = get_post_author_id( $post_id );
  1088. $type = get_user_type( $id );
  1089. if ( false === $type )
  1090. $r = __('Unregistered'); // This should never happen
  1091. else
  1092. $r = '<a href="' . attribute_escape( get_user_profile_link( $id ) ) . '">' . $type . '</a>';
  1093. echo apply_filters( 'post_author_type', $r );
  1094. }
  1095. function allowed_markup( $args = '' ) {
  1096. echo apply_filters( 'allowed_markup', get_allowed_markup( $args ) );
  1097. }
  1098. // format=list or array( 'format' => 'list' )
  1099. function get_allowed_markup( $args = '' ) {
  1100. $args = wp_parse_args( $args, array('format' => 'flat') );
  1101. extract($args, EXTR_SKIP);
  1102. $tags = bb_allowed_tags();
  1103. unset($tags['pre'], $tags['br']);
  1104. $tags = array_keys($tags);
  1105. switch ( $format ) :
  1106. case 'array' :
  1107. $r = $tags;
  1108. break;
  1109. case 'list' :
  1110. $r = "<ul class='allowed-markup'>\n\t<li>";
  1111. $r .= join("</li>\n\t<li>", $tags);
  1112. $r .= "</li>\n</ul>\n";
  1113. break;
  1114. default :
  1115. $r = join(' ', $tags);
  1116. break;
  1117. endswitch;
  1118. return apply_filters( 'get_allowed_markup', $r, $format );
  1119. }
  1120. // USERS
  1121. function bb_get_user_id( $id = 0 ) {
  1122. global $user;
  1123. if ( is_object($id) && isset($id->ID) )
  1124. return (int) $id->ID;
  1125. elseif ( !$id )
  1126. return $user->ID;
  1127. $_user = bb_get_user( $id );
  1128. return $_user->ID;
  1129. }
  1130. function user_profile_link( $id = 0 , $page = 1 ) {
  1131. echo apply_filters( 'user_profile_link', get_user_profile_link( $id ), bb_get_user_id( $id ) );
  1132. }
  1133. function get_user_profile_link( $id = 0, $page = 1 ) {
  1134. $user = bb_get_user( bb_get_user_id( $id ) );
  1135. $rewrite = bb_get_option( 'mod_rewrite' );
  1136. if ( $rewrite ) {
  1137. if ( $rewrite === 'slugs' ) {
  1138. $column = 'user_nicename';
  1139. } else {
  1140. $column = 'ID';
  1141. }
  1142. $r = bb_get_option('uri') . "profile/" . $user->$column . ( 1 < $page ? "/page/$page" : '' );
  1143. } else {
  1144. $r = bb_get_option('uri') . "profile.php?id=$user->ID" . ( 1 < $page ? "&page=$page" : '' );
  1145. }
  1146. return apply_filters( 'get_user_profile_link', $r, $user->ID );
  1147. }
  1148. function user_delete_button() {
  1149. global $user;
  1150. if ( bb_current_user_can( 'edit_users' ) && bb_get_current_user_info( 'id' ) != (int) $user->ID )
  1151. echo apply_filters( 'user_delete_button', get_user_delete_button() );
  1152. }
  1153. function get_user_delete_button() {
  1154. $r = '<input type="submit" class="delete" name="delete-user" value="' . __('Delete User &raquo;') . '" ';
  1155. $r .= 'onclick="return confirm(\'' . js_escape(__('Are you sure you want to delete this user?')) . '\')" />';
  1156. return apply_filters( 'get_user_delete_button', $r);
  1157. }
  1158. function profile_tab_link( $id = 0, $tab, $page = 1 ) {
  1159. echo apply_filters( 'profile_tab_link', get_profile_tab_link( $id, $tab ) );
  1160. }
  1161. function get_profile_tab_link( $id = 0, $tab, $page = 1 ) {
  1162. $tab = bb_tag_sanitize($tab);
  1163. if ( bb_get_option('mod_rewrite') )
  1164. $r = get_user_profile_link( $id ) . "/$tab" . ( 1 < $page ? "/page/$page" : '' );
  1165. else {
  1166. $args = array('tab' => $tab);
  1167. $args['page'] = 1 < $page ? $page : false;
  1168. $r = add_query_arg( $args, get_user_profile_link( $id ) );
  1169. }
  1170. return apply_filters( 'get_profile_tab_link', $r, bb_get_user_id( $id ) );
  1171. }
  1172. function user_link( $id = 0 ) {
  1173. echo apply_filters( 'user_link', get_user_link( $id ), $id );
  1174. }
  1175. function get_user_link( $id = 0 ) {
  1176. if ( $user = bb_get_user( bb_get_user_id( $id ) ) )
  1177. return apply_filters( 'get_user_link', $user->user_url, $user->ID );
  1178. }
  1179. function full_user_link( $id = 0 ) {
  1180. echo get_full_user_link( $id );
  1181. }
  1182. function get_full_user_link( $id = 0 ) {
  1183. if ( get_user_link( $id ) )
  1184. $r = '<a href="' . attribute_escape( get_user_link( $id ) ) . '">' . get_user_name( $id ) . '</a>';
  1185. else
  1186. $r = get_user_name( $id );
  1187. return $r;
  1188. }
  1189. function user_type_label( $type ) {
  1190. echo apply_filters( 'user_type_label', get_user_type_label( $type ), $type );
  1191. }
  1192. function get_user_type_label( $type ) {
  1193. global $bb_roles;
  1194. if ( $bb_roles->is_role( $type ) )
  1195. return apply_filters( 'get_user_type_label', $bb_roles->role_names[$type], $type );
  1196. }
  1197. function user_type( $id = 0 ) {
  1198. echo apply_filters( 'user_type', get_user_type( $id ) );
  1199. }
  1200. function get_user_type( $id = 0 ) {
  1201. if ( $user = bb_get_user( bb_get_user_id( $id ) ) ) :
  1202. @$caps = array_keys($user->capabilities);
  1203. if ( !$caps )
  1204. $caps[] = 'inactive';
  1205. $type = get_user_type_label( $caps[0] ); //Just support one role for now.
  1206. else :
  1207. $type = false;
  1208. endif;
  1209. return apply_filters( 'get_user_type', $type, $user->ID );
  1210. }
  1211. function get_user_name( $id = 0 ) {
  1212. $user = bb_get_user( bb_get_user_id( $id ) );
  1213. return apply_filters( 'get_user_name', $user->user_login, $user->ID );
  1214. }
  1215. function user_title( $id = 0 ) {
  1216. echo apply_filters( 'user_title', get_user_title( $id ), bb_get_user_id( $id ) );
  1217. }
  1218. function get_user_title( $id = 0 ) {
  1219. $user = bb_get_user( bb_get_user_id( $id ) );
  1220. return empty( $user->title ) ? get_user_type( $id ) : apply_filters( 'get_user_title', $user->title, $user->ID );
  1221. }
  1222. function profile_pages() {
  1223. global $user, $page;
  1224. $add = 0;
  1225. $add = apply_filters( 'profile_pages_add', $add );
  1226. echo apply_filters( 'topic_pages', get_page_number_links( $page, $user->topics_replied + $add ) );
  1227. }
  1228. function bb_profile_data( $id = 0 ) {
  1229. if ( !$user = bb_get_user( bb_get_user_id( $id ) ) )
  1230. return;
  1231. $reg_time = bb_gmtstrtotime( $user->user_registered );
  1232. $profile_info_keys = get_profile_info_keys();
  1233. echo "<dl id='userinfo'>\n";
  1234. echo "\t<dt>" . __('Member Since') . "</dt>\n";
  1235. echo "\t<dd>" . bb_datetime_format_i18n($reg_time, 'date') . ' (' . bb_since($reg_time) . ")</dd>\n";
  1236. if ( is_array( $profile_info_keys ) ) {
  1237. foreach ( $profile_info_keys as $key => $label ) {
  1238. $val = 'user_url' == $key ? get_user_link( $user->ID ) : $user->$key;
  1239. if (
  1240. ( 'user_email' != $key || ( 'user_email' == $key && bb_current_user_can( 'edit_users' ) ) )
  1241. && isset( $user->$key )
  1242. && $val
  1243. && 'http://' != $val
  1244. ) {
  1245. echo "\t<dt>{$label[1]}</dt>\n";
  1246. echo "\t<dd>" . make_clickable( $val ) . "</dd>\n";
  1247. }
  1248. }
  1249. }
  1250. echo "</dl>\n";
  1251. }
  1252. function bb_profile_base_content() {
  1253. global $self;
  1254. if ( !is_callable( $self ) )
  1255. return; // should never happen
  1256. call_user_func( $self );
  1257. }
  1258. function bb_profile_data_form( $id = 0 ) {
  1259. global $errors;
  1260. if ( !$user = bb_get_user( bb_get_user_id( $id ) ) )
  1261. return;
  1262. if ( !bb_current_user_can( 'edit_user', $user->ID ) )
  1263. return;
  1264. $error_codes = $errors->get_error_codes();
  1265. $profile_info_keys = get_profile_info_keys();
  1266. $required = false;
  1267. ?>
  1268. <table id="userinfo">
  1269. <?php
  1270. if ( is_array($profile_info_keys) ) :
  1271. $bb_current_id = bb_get_current_user_info( 'id' );
  1272. foreach ( $profile_info_keys as $key => $label ) :
  1273. if ( $label[0] ) {
  1274. $class = 'form-field form-required required';
  1275. $title = '<sup class="required">*</sup> ' . attribute_escape( $label[1] );
  1276. $required = true;
  1277. } else {
  1278. $class = 'form-field';
  1279. $title = attribute_escape( $label[1] );
  1280. }
  1281. $name = attribute_escape( $key );
  1282. $type = isset($label[2]) ? attribute_escape( $label[2] ) : 'text';
  1283. if ( in_array( $key, $error_codes ) ) {
  1284. $class .= ' form-invalid';
  1285. $data = $errors->get_error_data( $key );
  1286. if ( isset($data['data']) )
  1287. $value = $data['data'];
  1288. else
  1289. $value = $_POST[$key];
  1290. $message = wp_specialchars( $errors->get_error_message( $key ) );
  1291. $message = "<p class='error'>$message</p>";
  1292. } else {
  1293. $value = $user->$key;
  1294. $message = '';
  1295. }
  1296. $value = attribute_escape( $value );
  1297. ?>
  1298. <tr class="<?php echo $class; ?>">
  1299. <th scope="row"><label for="<?php echo $name; ?>"><?php echo $title; ?></label></th>
  1300. <td>
  1301. <input name="<?php echo $name; ?>" type="<?php echo $type; ?>" id="<?php echo $name; ?>" value="<?php echo $value; ?>" />
  1302. <?php echo $message; ?>
  1303. </td>
  1304. </tr>
  1305. <?php endforeach; endif; // $profile_info_keys; $profile_info_keys ?>
  1306. </table>
  1307. <?php bb_nonce_field( 'edit-profile_' . $user->ID ); if ( $required ) : ?>
  1308. <p><sup class="required">*</sup> <?php _e('These items are <span class="required">required</span>.') ?></p>
  1309. <?php
  1310. endif;
  1311. do_action( 'extra_profile_info', $user->ID );
  1312. }
  1313. function bb_profile_admin_form( $id = 0 ) {
  1314. global $bb_roles, $errors;
  1315. if ( !$user = bb_get_user( bb_get_user_id( $id ) ) )
  1316. return;
  1317. if ( !bb_current_user_can( 'edit_user', $user->ID ) )
  1318. return;
  1319. $error_codes = $errors->get_error_codes();
  1320. $bb_current_id = bb_get_current_user_info( 'id' );
  1321. $profile_admin_keys = get_profile_admin_keys();
  1322. $assignable_caps = get_assignable_caps();
  1323. $required = false;
  1324. $roles = $bb_roles->role_names;
  1325. $can_keep_gate = bb_current_user_can( 'keep_gate' );
  1326. // Keymasters can't demote themselves
  1327. if ( ( $bb_current_id == $user->ID && $can_keep_gate ) || ( array_key_exists('keymaster', $user->capabilities) && !$can_keep_gate ) )
  1328. $roles = array( 'keymaster' => $roles['keymaster'] );
  1329. elseif ( !$can_keep_gate ) // only keymasters can promote others to keymaster status
  1330. unset($roles['keymaster']);
  1331. ?>
  1332. <table id="admininfo">
  1333. <tr class='form-field<?php if ( in_array( 'role', $error_codes ) ) echo ' form-invalid'; ?>'>
  1334. <th scope="row"><?php _e('User Type'); ?></th>
  1335. <td>
  1336. <select name="role">
  1337. <?php foreach( $roles as $r => $n ) : ?>
  1338. <option value="<?php echo $r; ?>"<?php if ( array_key_exists($r, $user->capabilities) ) echo ' selected="selected"'; ?>><?php echo $n; ?></option>
  1339. <?php endforeach; ?>
  1340. </select>
  1341. <?php if ( in_array( 'role', $error_codes ) ) echo '<p class="error">' . $errors->get_error_message( 'role' ) . '</p>'; ?>
  1342. </td>
  1343. </tr>
  1344. <tr class="extra-caps-row">
  1345. <th scope="row"><?php _e('A…

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