/wp-content/plugins/buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php
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
- <?php
- function bb_load_template( $files, $globals = false, $action_arg = null )
- {
- global $bb, $bbdb, $bb_current_user, $page, $bb_cache,
- $posts, $bb_post, $post_id, $topics, $topic, $topic_id,
- $forums, $forum, $forum_id, $tags, $tag, $tag_name, $user, $user_id, $view,
- $del_class, $bb_alt;
- if ( $globals ) {
- foreach ( $globals as $global => $v ) {
- if ( !is_numeric($global) ) {
- $$global = $v;
- } else {
- global $$v;
- }
- }
- }
- $files = (array) $files;
- $template = false;
- $default_template = false;
- $file_used = false;
- $default_file_used = false;
- foreach ( $files as $file ) {
- do_action( 'bb_' . $file, $action_arg );
- if ( false !== $template = bb_get_template( $file, false ) ) {
- $file_used = $file;
- break;
- }
- if ( !$default_template ) {
- if ( false !== $default_template = bb_get_default_template( $file ) ) {
- $default_file_used = $file;
- }
- }
- }
- if ( !$template && $default_template ) {
- $template = $default_template;
- $file_used = $default_file_used;
- }
- $template = apply_filters( 'bb_template', $template, $file_used );
- include( $template );
- do_action( 'bb_after_' . $file_used, $action_arg );
- }
- function bb_get_template( $file, $default = true )
- {
- global $bb;
- // Skip theme loading in "safe" mode
- if ( !isset( $bb->safemode ) || $bb->safemode !== true ) {
- if ( file_exists( bb_get_active_theme_directory() . $file ) ) {
- return bb_get_active_theme_directory() . $file;
- }
- }
- if ( !$default ) {
- return false;
- }
- return bb_get_default_template( $file );
- }
- function bb_get_default_template( $file )
- {
- if ( file_exists( BB_DEFAULT_THEME_DIR . $file ) ) {
- return BB_DEFAULT_THEME_DIR . $file;
- }
- }
- function bb_get_header()
- {
- bb_load_template( 'header.php' );
- }
- function bb_language_attributes( $xhtml = 0 )
- {
- $output = '';
- if ( $dir = bb_get_option( 'text_direction' ) ) {
- $output = 'dir="' . $dir . '" ';
- }
- if ( $lang = bb_get_option( 'language' ) ) {
- $output .= 'xml:lang="' . $lang . '" ';
- if ( $xhtml < '1.1' ) {
- $output .= 'lang="' . $lang . '"';
- }
- }
- echo ' ' . rtrim( $output );
- }
- function bb_generator( $type = 'xhtml' )
- {
- if ( !$type ) {
- $type = 'xhtml';
- }
- echo apply_filters( 'bb_generator', bb_get_generator( $type ) . "\n", $type );
- }
- function bb_get_generator( $type = 'xhtml' )
- {
- if ( !$type ) {
- $type = 'xhtml';
- }
- switch ( $type ) {
- case 'html':
- $gen = '<meta name="generator" content="bbPress ' . bb_get_option( 'version' ) . '">';
- break;
- case 'xhtml':
- $gen = '<meta name="generator" content="bbPress ' . bb_get_option( 'version' ) . '" />';
- break;
- case 'atom':
- $gen = '<generator uri="http://bbpress.org/" version="' . bb_get_option( 'version' ) . '">bbPress</generator>';
- break;
- case 'rss2':
- $gen = '<generator>http://bbpress.org/?v=' . bb_get_option( 'version' ) . '</generator>';
- break;
- case 'rdf':
- $gen = '<admin:generatorAgent rdf:resource="http://bbpress.org/?v=' . bb_get_option( 'version' ) . '" />';
- break;
- case 'comment':
- $gen = '<!-- generator="bbPress/' . bb_get_option( 'version' ) . '" -->';
- break;
- case 'export':
- $gen = '<!-- generator="bbPress/' . bb_get_option( 'version' ) . '" created="'. date( 'Y-m-d H:i' ) . '"-->';
- break;
- }
- return apply_filters( 'bb_get_generator', $gen, $type );
- }
- function bb_stylesheet_uri( $stylesheet = '' )
- {
- echo esc_html( bb_get_stylesheet_uri( $stylesheet ) );
- }
- function bb_get_stylesheet_uri( $stylesheet = '' )
- {
- if ( 'rtl' == $stylesheet ) {
- $css_file = 'style-rtl.css';
- } else {
- $css_file = 'style.css';
- }
- $active_theme = bb_get_active_theme_directory();
- if ( file_exists( $active_theme . $css_file ) ) {
- $r = bb_get_active_theme_uri() . $css_file;
- } else {
- $r = BB_DEFAULT_THEME_URL . $css_file;
- }
- return apply_filters( 'bb_get_stylesheet_uri', $r, $stylesheet );
- }
- function bb_active_theme_uri()
- {
- echo bb_get_active_theme_uri();
- }
- function bb_get_active_theme_uri()
- {
- global $bb;
- // Skip theme loading in "safe" mode
- if ( isset( $bb->safemode ) && $bb->safemode === true ) {
- $active_theme_uri = BB_DEFAULT_THEME_URL;
- } elseif ( !$active_theme = bb_get_option( 'bb_active_theme' ) ) {
- $active_theme_uri = BB_DEFAULT_THEME_URL;
- } else {
- $active_theme_uri = bb_get_theme_uri( $active_theme );
- }
- return apply_filters( 'bb_get_active_theme_uri', $active_theme_uri );
- }
- function bb_get_theme_uri( $theme = false )
- {
- global $bb;
- if ( preg_match( '/^([a-z0-9_-]+)#([a-z0-9_-]+)$/i', $theme, $_matches ) ) {
- $theme_uri = $bb->theme_locations[$_matches[1]]['url'] . $_matches[2] . '/';
- } else {
- $theme_uri = $bb->theme_locations['core']['url'];
- }
- return apply_filters( 'bb_get_theme_uri', $theme_uri, $theme );
- }
- function bb_get_footer()
- {
- bb_load_template( 'footer.php' );
- }
- function bb_head()
- {
- do_action('bb_head');
- }
- /**
- * Display the link to the Really Simple Discovery service endpoint.
- *
- * @link http://archipelago.phrasewise.com/rsd
- * @since 1.0
- */
- function bb_rsd_link() {
- if (bb_get_option('enable_xmlrpc'))
- 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";
- }
- /**
- * Display the link to the pingback service endpoint.
- *
- * @since 1.0
- */
- function bb_pingback_link() {
- if (bb_get_option('enable_pingback'))
- echo '<link rel="pingback" href="' . bb_get_uri('xmlrpc.php', null, BB_URI_CONTEXT_LINK_OTHER + BB_URI_CONTEXT_BB_XMLRPC) . '" />' . "\n";
- }
- function profile_menu() {
- global $user_id, $profile_menu, $self, $profile_page_title;
- $list = "<ul id='profile-menu'>";
- $list .= "\n\t<li" . ( ( $self ) ? '' : ' class="current"' ) . '><a href="' . esc_attr( get_user_profile_link( $user_id ) ) . '">' . __('Profile') . '</a></li>';
- $id = bb_get_current_user_info( 'id' );
- foreach ($profile_menu as $item) {
- // 0 = name, 1 = users cap, 2 = others cap, 3 = file
- $class = '';
- if ( $item[3] == $self ) {
- $class = ' class="current"';
- $profile_page_title = $item[0];
- }
- if ( bb_can_access_tab( $item, $id, $user_id ) )
- if ( file_exists($item[3]) || is_callable($item[3]) )
- $list .= "\n\t<li$class><a href='" . esc_attr( get_profile_tab_link($user_id, $item[4]) ) . "'>{$item[0]}</a></li>";
- }
- $list .= "\n</ul>";
- echo $list;
- }
- function login_form() {
- if ( bb_is_user_logged_in() )
- bb_load_template( 'logged-in.php' );
- else
- bb_load_template( 'login-form.php', array('user_login', 'remember_checked', 'redirect_to', 're') );
- }
- function search_form( $q = '' ) {
- bb_load_template( 'search-form.php', array('q' => $q) );
- }
- function bb_post_template() {
- bb_load_template( 'post.php' );
- }
- function post_form( $args = array() ) {
- global $page, $topic, $forum;
- if ( is_string( $args ) ) {
- $args['h2'] = $args;
- }
- $defaults = array(
- 'h2' => '',
- 'last_page_only' => true
- );
- $args = wp_parse_args( $args, $defaults );
- extract( $args, EXTR_SKIP );
- if ( isset( $forum->forum_is_category ) && $forum->forum_is_category ) {
- return;
- }
- $add = topic_pages_add();
- if ( empty( $h2 ) && false !== $h2 ) {
- if ( bb_is_topic() ) {
- $h2 = __( 'Reply' );
- } elseif ( bb_is_forum() ) {
- $h2 = __( 'New Topic in this Forum' );
- } elseif ( bb_is_tag() || bb_is_front() ) {
- $h2 = __( 'Add New Topic' );
- }
- }
- $last_page = bb_get_page_number( ( isset( $topic->topic_posts ) ? $topic->topic_posts : 0 ) + $add );
- if ( !empty( $h2 ) ) {
- if ( bb_is_topic() && ( $page != $last_page && $last_page_only ) ) {
- $h2 = '<a href="' . esc_attr( get_topic_link( 0, $last_page ) . '#postform' ) . '">' . $h2 . ' »</a>';
- }
- echo '<h2 class="post-form">' . $h2 . '</h2>' . "\n";
- }
- do_action( 'pre_post_form' );
- if (
- ( bb_is_topic() && bb_current_user_can( 'write_post', $topic->topic_id ) && ( $page == $last_page || !$last_page_only ) ) ||
- ( !bb_is_topic() && bb_current_user_can( 'write_topic', isset( $forum->forum_id ) ? $forum->forum_id : 0 ) )
- ) {
- echo '<form class="postform post-form" id="postform" method="post" action="' . bb_get_uri( 'bb-post.php', null, BB_URI_CONTEXT_FORM_ACTION ) . '">' . "\n";
- echo '<fieldset>' . "\n";
- bb_load_template( 'post-form.php', array('h2' => $h2) );
- bb_nonce_field( bb_is_topic() ? 'create-post_' . $topic->topic_id : 'create-topic' );
- if ( bb_is_forum() ) {
- echo '<input type="hidden" name="forum_id" value="' . $forum->forum_id . '" />' . "\n";
- } elseif ( bb_is_topic() ) {
- echo '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "\n";
- }
- do_action( 'post_form' );
- echo "\n</fieldset>\n</form>\n";
- } elseif ( !bb_is_user_logged_in() ) {
- echo '<p>';
- printf(
- __('You must <a href="%s">log in</a> to post.'),
- esc_attr( bb_get_uri( 'bb-login.php', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS ) )
- );
- echo '</p>';
- }
- do_action( 'post_post_form' );
- }
- function edit_form() {
- global $bb_post;
- do_action('pre_edit_form');
- echo '<form class="postform edit-form" method="post" action="' . bb_get_uri('bb-edit.php', null, BB_URI_CONTEXT_FORM_ACTION) . '">' . "\n";
- echo '<fieldset>' . "\n";
- bb_load_template( 'edit-form.php', array('topic_title') );
- bb_nonce_field( 'edit-post_' . $bb_post->post_id );
- do_action('edit_form');
- if ($_REQUEST['view'] === 'all')
- echo "\n" . '<input type="hidden" name="view" value="all" />';
- echo "\n" . '</fieldset>' . "\n" . '</form>' . "\n";
- do_action('post_edit_form');
- }
- function alt_class( $key, $others = '' ) {
- echo get_alt_class( $key, $others );
- }
- function get_alt_class( $key, $others = '' ) {
- global $bb_alt;
- $class = '';
- if ( !isset( $bb_alt[$key] ) ) $bb_alt[$key] = -1;
- ++$bb_alt[$key];
- $others = trim($others);
- if ( $others xor $bb_alt[$key] % 2 )
- $class = ' class="' . ( ($others) ? $others : 'alt' ) . '"';
- elseif ( $others && $bb_alt[$key] % 2 )
- $class = ' class="' . $others . ' alt"';
- return $class;
- }
- function bb_location() {
- echo apply_filters( 'bb_location', bb_get_location() );
- }
- function bb_get_location() { // Not for display. Do not internationalize.
- static $file;
- static $filename;
- if ( !isset( $file ) ) {
- $path = '';
- foreach ( array( $_SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'], $_SERVER['PHP_SELF'] ) as $_path ) {
- if ( false !== strpos( $_path, '.php' ) ) {
- $path = $_path;
- break;
- }
- }
- $filename = bb_find_filename( $path );
- // Make $file relative to bbPress root directory
- $file = str_replace( bb_get_option( 'path' ), '', $path );
- }
- switch ( $filename ) {
- case 'index.php':
- case 'page.php':
- $location = 'front-page';
- break;
- case 'forum.php':
- $location = 'forum-page';
- break;
- case 'tags.php':
- $location = 'tag-page';
- break;
- case 'edit.php':
- $location = 'topic-edit-page';
- break;
- case 'topic.php':
- $location = 'topic-page';
- break;
- case 'rss.php':
- $location = 'feed-page';
- break;
- case 'search.php':
- $location = 'search-page';
- break;
- case 'profile.php':
- $location = 'profile-page';
- break;
- case 'favorites.php':
- $location = 'favorites-page';
- break;
- case 'view.php':
- $location = 'view-page';
- break;
- case 'statistics.php':
- $location = 'stats-page';
- break;
- case 'bb-login.php':
- $location = 'login-page';
- break;
- case 'register.php':
- $location = 'register-page';
- break;
- default:
- $location = apply_filters( 'bb_get_location', '', $file );
- break;
- }
- return $location;
- }
- function bb_is_front() {
- return 'front-page' == bb_get_location();
- }
- function bb_is_forum() {
- return 'forum-page' == bb_get_location();
- }
- function bb_is_tags() {
- return 'tag-page' == bb_get_location();
- }
- function bb_is_tag() {
- global $tag, $tag_name;
- return $tag && $tag_name && bb_is_tags();
- }
- function bb_is_topic_edit() {
- return 'topic-edit-page' == bb_get_location();
- }
- function bb_is_topic() {
- return 'topic-page' == bb_get_location();
- }
- function bb_is_feed() {
- return 'feed-page' == bb_get_location();
- }
- function bb_is_search() {
- return 'search-page' == bb_get_location();
- }
- function bb_is_profile() {
- return 'profile-page' == bb_get_location();
- }
- function bb_is_favorites() {
- return 'favorites-page' == bb_get_location();
- }
- function bb_is_view() {
- return 'view-page' == bb_get_location();
- }
- function bb_is_statistics() {
- return 'stats-page' == bb_get_location();
- }
- function bb_is_admin() {
- if ( defined('BB_IS_ADMIN') )
- return BB_IS_ADMIN;
- return false;
- }
- function bb_title( $args = '' ) {
- echo apply_filters( 'bb_title', bb_get_title( $args ) );
- }
- function bb_get_title( $args = '' ) {
- $defaults = array(
- 'separator' => ' « ',
- 'order' => 'normal',
- 'front' => ''
- );
- $args = wp_parse_args( $args, $defaults );
- $title = array();
-
- switch ( bb_get_location() ) {
- case 'front-page':
- if ( !empty( $args['front'] ) )
- $title[] = $args['front'];
- break;
-
- case 'topic-edit-page':
- case 'topic-page':
- $title[] = get_topic_title();
- break;
-
- case 'forum-page':
- $title[] = get_forum_name();
- break;
-
- case 'tag-page':
- if ( bb_is_tag() )
- $title[] = esc_html( bb_get_tag_name() );
-
- $title[] = __('Tags');
- break;
-
- case 'profile-page':
- $title[] = get_user_display_name();
- break;
-
- case 'view-page':
- $title[] = get_view_name();
- break;
- }
-
- if ( $st = bb_get_option( 'static_title' ) )
- $title = array( $st );
-
- $title[] = bb_get_option( 'name' );
-
- if ( 'reversed' == $args['order'] )
- $title = array_reverse( $title );
-
- return apply_filters( 'bb_get_title', implode( $args['separator'], $title ) );
- }
- function bb_feed_head() {
-
- $feeds = array();
-
- switch (bb_get_location()) {
- case 'profile-page':
- if ( $tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2) )
- if ($tab != 'favorites')
- break;
-
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » User Favorites: %2$s'), bb_get_option( 'name' ), get_user_name()),
- 'href' => get_favorites_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- break;
-
- case 'topic-page':
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Topic: %2$s'), bb_get_option( 'name' ), get_topic_title()),
- 'href' => get_topic_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- break;
-
- case 'tag-page':
- if (bb_is_tag()) {
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Tag: %2$s - Recent Posts'), bb_get_option( 'name' ), bb_get_tag_name()),
- 'href' => bb_get_tag_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Tag: %2$s - Recent Topics'), bb_get_option( 'name' ), bb_get_tag_name()),
- 'href' => bb_get_tag_topics_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- }
- break;
-
- case 'forum-page':
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Forum: %2$s - Recent Posts'), bb_get_option( 'name' ), get_forum_name()),
- 'href' => bb_get_forum_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Forum: %2$s - Recent Topics'), bb_get_option( 'name' ), get_forum_name()),
- 'href' => bb_get_forum_topics_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- break;
-
- case 'front-page':
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Recent Posts'), bb_get_option( 'name' )),
- 'href' => bb_get_posts_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » Recent Topics'), bb_get_option( 'name' )),
- 'href' => bb_get_topics_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- break;
-
- case 'view-page':
- global $bb_views, $view;
- if ($bb_views[$view]['feed']) {
- $feeds[] = array(
- 'title' => sprintf(__('%1$s » View: %2$s'), bb_get_option( 'name' ), get_view_name()),
- 'href' => bb_get_view_rss_link(null, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED)
- );
- }
- break;
- }
-
- if (count($feeds)) {
- $feed_links = array();
- foreach ($feeds as $feed) {
- $link = '<link rel="alternate" type="application/rss+xml" ';
- $link .= 'title="' . esc_attr($feed['title']) . '" ';
- $link .= 'href="' . esc_attr($feed['href']) . '" />';
- $feed_links[] = $link;
- }
- $feed_links = join("\n", $feed_links);
- } else {
- $feed_links = '';
- }
-
- echo apply_filters('bb_feed_head', $feed_links);
- }
- function bb_get_posts_rss_link($context = 0) {
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- if ( bb_get_option( 'mod_rewrite' ) )
- $link = bb_get_uri('rss/', null, $context);
- else
- $link = bb_get_uri('rss.php', null, $context);
- return apply_filters( 'bb_get_posts_rss_link', $link, $context );
- }
- function bb_get_topics_rss_link($context = 0) {
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- if ( bb_get_option( 'mod_rewrite' ) )
- $link = bb_get_uri('rss/topics', null, $context);
- else
- $link = bb_get_uri('rss.php', array('topics' => 1), $context);
- return apply_filters( 'bb_get_topics_rss_link', $link, $context );
- }
- function bb_view_rss_link($view = null, $context = 0) {
- echo apply_filters( 'bb_view_rss_link', bb_get_view_rss_link($view, $context), $context);
- }
- function bb_get_view_rss_link($view = null, $context = 0) {
- if (!$view) {
- global $view;
- }
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- if ( bb_get_option( 'mod_rewrite' ) )
- $link = bb_get_uri('rss/view/' . $view, null, $context);
- else
- $link = bb_get_uri('rss.php', array('view' => $view), $context);
- return apply_filters( 'bb_get_view_rss_link', $link, $context );
- }
- function bb_latest_topics_pages( $args = null )
- {
- $defaults = array( 'before' => '', 'after' => '' );
- $args = wp_parse_args( $args, $defaults );
- global $page;
- static $bb_latest_topics_count;
- if ( !$bb_latest_topics_count) {
- global $bbdb;
- $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;');
- }
- if ( $pages = apply_filters( 'bb_latest_topics_pages', get_page_number_links( $page, $bb_latest_topics_count ), $bb_latest_topics_count ) ) {
- echo $args['before'] . $pages . $args['after'];
- }
- }
- // FORUMS
- function forum_id( $forum_id = 0 ) {
- echo apply_filters( 'forum_id', get_forum_id( $forum_id ) );
- }
- function get_forum_id( $forum_id = 0 ) {
- global $forum;
- $forum_id = (int) $forum_id;
- if ( $forum_id )
- $_forum = bb_get_forum( $forum_id );
- else
- $_forum =& $forum;
- return $_forum->forum_id;
- }
- function forum_link( $forum_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) {
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF;
- }
- echo apply_filters('forum_link', get_forum_link( $forum_id, $page, $context ), $forum_id, $context );
- }
- function get_forum_link( $forum_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
-
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF;
- }
-
- $rewrite = bb_get_option( 'mod_rewrite' );
- if ( $rewrite ) {
- if ( $rewrite === 'slugs' ) {
- $column = 'forum_slug';
- } else {
- $column = 'forum_id';
- }
- $page = (1 < $page) ? '/page/' . $page : '';
- $link = bb_get_uri('forum/' . $forum->$column . $page, null, $context);
- } else {
- $query = array(
- 'id' => $forum->forum_id,
- 'page' => (1 < $page) ? $page : false
- );
- $link = bb_get_uri('forum.php', $query, $context);
- }
- return apply_filters( 'get_forum_link', $link, $forum->forum_id, $context );
- }
- function forum_name( $forum_id = 0 ) {
- echo apply_filters( 'forum_name', get_forum_name( $forum_id ), $forum_id );
- }
- function get_forum_name( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'get_forum_name', $forum->forum_name, $forum->forum_id );
- }
- function forum_description( $args = null ) {
- if ( is_numeric($args) )
- $args = array( 'id' => $args );
- elseif ( $args && is_string($args) && false === strpos($args, '=') )
- $args = array( 'before' => $args );
- $defaults = array( 'id' => 0, 'before' => ' – ', 'after' => '' );
- $args = wp_parse_args( $args, $defaults );
- if ( $desc = apply_filters( 'forum_description', get_forum_description( $args['id'] ), $args['id'], $args ) )
- echo $args['before'] . $desc . $args['after'];
- }
- function get_forum_description( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'get_forum_description', $forum->forum_desc, $forum->forum_id );
- }
- function get_forum_parent( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'get_forum_parent', $forum->forum_parent, $forum->forum_id );
- }
- function get_forum_position( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'get_forum_position', $forum->forum_order, $forum->forum_id );
- }
- function bb_get_forum_is_category( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'bb_get_forum_is_category', isset($forum->forum_is_category) ? $forum->forum_is_category : false, $forum->forum_id );
- }
- function forum_topics( $forum_id = 0 ) {
- echo apply_filters( 'forum_topics', get_forum_topics( $forum_id ), $forum_id );
- }
- function get_forum_topics( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'get_forum_topics', $forum->topics, $forum->forum_id );
- }
- function forum_posts( $forum_id = 0 ) {
- echo apply_filters( 'forum_posts', get_forum_posts( $forum_id ), $forum_id );
- }
- function get_forum_posts( $forum_id = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
- return apply_filters( 'get_forum_posts', $forum->posts, $forum->forum_id );
- }
- function forum_pages( $args = null )
- {
- // Compatibility
- if ( $args && is_numeric( $args ) ) {
- $args = array( 'id' => $args );
- }
- $defaults = array( 'id' => 0, 'before' => '', 'after' => '' );
- $args = wp_parse_args( $args, $defaults );
- global $page;
- $forum = bb_get_forum( get_forum_id( $args['id'] ) );
- if ( $pages = apply_filters( 'forum_pages', get_page_number_links( $page, $forum->topics ), $forum->topics ) ) {
- echo $args['before'] . $pages . $args['after'];
- }
- }
- function bb_forum_posts_rss_link( $forum_id = 0, $context = 0 ) {
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- echo apply_filters('bb_forum_posts_rss_link', bb_get_forum_posts_rss_link( $forum_id, $context ), $context );
- }
- function bb_get_forum_posts_rss_link( $forum_id = 0, $context = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
-
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
-
- $rewrite = bb_get_option( 'mod_rewrite' );
- if ( $rewrite ) {
- if ( $rewrite === 'slugs' ) {
- $column = 'forum_slug';
- } else {
- $column = 'forum_id';
- }
- $link = bb_get_uri('rss/forum/' . $forum->$column, null, $context);
- } else {
- $link = bb_get_uri('rss.php', array('forum' => $forum->forum_id), $context);
- }
- return apply_filters( 'bb_get_forum_posts_rss_link', $link, $forum->forum_id, $context );
- }
- function bb_forum_topics_rss_link( $forum_id = 0, $context = 0 ) {
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- echo apply_filters('bb_forum_topics_rss_link', bb_get_forum_topics_rss_link( $forum_id, $context ), $context );
- }
- function bb_get_forum_topics_rss_link( $forum_id = 0, $context = 0 ) {
- $forum = bb_get_forum( get_forum_id( $forum_id ) );
-
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
-
- $rewrite = bb_get_option( 'mod_rewrite' );
- if ( $rewrite ) {
- if ( $rewrite === 'slugs' ) {
- $column = 'forum_slug';
- } else {
- $column = 'forum_id';
- }
- $link = bb_get_uri('rss/forum/' . $forum->$column . '/topics', null, $context);
- } else {
- $link = bb_get_uri('rss.php', array('forum' => $forum->forum_id, 'topics' => 1), $context);
- }
- return apply_filters( 'bb_get_forum_topics_rss_link', $link, $forum->forum_id, $context );
- }
- function bb_get_forum_bread_crumb($args = '') {
- $defaults = array(
- 'forum_id' => 0,
- 'separator' => ' » ',
- 'class' => null
- );
- $args = wp_parse_args($args, $defaults);
- extract($args, EXTR_SKIP);
- $trail = '';
- $trail_forum = bb_get_forum(get_forum_id($forum_id));
- if ($class) {
- $class = ' class="' . $class . '"';
- }
- $current_trail_forum_id = $trail_forum->forum_id;
- while ( $trail_forum && $trail_forum->forum_id > 0 ) {
- $crumb = $separator;
- if ($current_trail_forum_id != $trail_forum->forum_id || !bb_is_forum()) {
- $crumb .= '<a' . $class . ' href="' . get_forum_link($trail_forum->forum_id) . '">';
- } elseif ($class) {
- $crumb .= '<span' . $class . '>';
- }
- $crumb .= get_forum_name($trail_forum->forum_id);
- if ($current_trail_forum_id != $trail_forum->forum_id || !bb_is_forum()) {
- $crumb .= '</a>';
- } elseif ($class) {
- $crumb .= '</span>';
- }
- $trail = $crumb . $trail;
- $trail_forum = bb_get_forum($trail_forum->forum_parent);
- }
- return apply_filters('bb_get_forum_bread_crumb', $trail, $forum_id );
- }
- function bb_forum_bread_crumb( $args = '' ) {
- echo apply_filters('bb_forum_bread_crumb', bb_get_forum_bread_crumb( $args ) );
- }
- // Forum Loop //
- function &bb_forums( $args = '' ) {
- global $bb_forums_loop;
- $default_type = 'flat';
- if ( is_numeric($args) ) {
- $args = array( 'child_of' => $args );
- } elseif ( func_num_args() > 1 ) { // bb_forums( 'ul', $args ); Deprecated
- $default_type = $args;
- $args = func_get_arg(1);
- } elseif ( $args && is_string($args) && false === strpos($args, '=') ) {
- $args = array( 'type' => $args );
- }
- // hierarchical not used here. Sent to bb_get_forums for proper ordering.
- $args = wp_parse_args( $args, array('hierarchical' => true, 'type' => $default_type, 'walker' => 'BB_Walker_Blank') );
- $levels = array( '', '' );
- if ( in_array($args['type'], array('list', 'ul')) )
- $levels = array( '<ul>', '</ul>' );
- $forums = bb_get_forums( $args );
- if ( !class_exists($args['walker']) )
- $args['walker'] = 'BB_Walker_Blank';
- if ( $bb_forums_loop = BB_Loop::start( $forums, $args['walker'] ) ) {
- $bb_forums_loop->preserve( array('forum', 'forum_id') );
- $bb_forums_loop->walker->db_fields = array( 'id' => 'forum_id', 'parent' => 'forum_parent' );
- list($bb_forums_loop->walker->start_lvl, $bb_forums_loop->walker->end_lvl) = $levels;
- return $bb_forums_loop->elements;
- }
- $false = false;
- return $false;
- }
- function bb_forum() { // Returns current depth
- global $bb_forums_loop;
- if ( !is_object($bb_forums_loop) || !is_a($bb_forums_loop, 'BB_Loop') )
- return false;
- if ( !is_array($bb_forums_loop->elements) )
- return false;
- if ( $bb_forums_loop->step() ) {
- $GLOBALS['forum'] =& $bb_forums_loop->elements[key($bb_forums_loop->elements)]; // Globalize the current forum object
- } else {
- $bb_forums_loop->reinstate();
- return $bb_forums_loop = null; // All done? Kill the object and exit the loop.
- }
- return $bb_forums_loop->walker->depth;
- }
- function bb_forum_pad( $pad, $offset = 0 ) {
- global $bb_forums_loop;
- if ( !is_object($bb_forums_loop) || !is_a($bb_forums_loop, 'BB_Loop') )
- return false;
- echo $bb_forums_loop->pad( $pad, $offset );
- }
- function bb_forum_class( $args = null ) {
- echo apply_filters( 'bb_forum_class', get_alt_class( 'forum', bb_get_forum_class_names( $args ) ), $args );
- }
- function bb_get_forum_class_names( $args = null ) {
- if ( is_numeric( $args ) ) { // Not used
- $args = array( 'id' => $args );
- } elseif ( $args && is_string( $args ) && false === strpos( $args, '=' ) ) {
- $args = array( 'class' => $args );
- }
- $defaults = array( 'id' => 0, 'key' => 'forum', 'class' => '', 'output' => 'string' );
- $args = wp_parse_args( $args, $defaults );
- $classes = array();
- if ( $args['class'] ) {
- $classes[] = $args['class'];
- }
- global $bb_forums_loop;
- if ( is_object( $bb_forums_loop ) && is_a( $bb_forums_loop, 'BB_Loop' ) ) {
- $classes = array_merge( $classes, $bb_forums_loop->classes( 'array' ) );
- }
- if ( $args['output'] === 'string' ) {
- $classes = join( ' ', $classes );
- }
- return apply_filters( 'bb_get_forum_class', $classes, $args );
- }
- // TOPICS
- function topic_id( $id = 0 ) {
- echo apply_filters( 'topic_id', get_topic_id( $id ) );
- }
- function get_topic_id( $id = 0 ) {
- global $topic;
- $id = (int) $id;
- if ( $id )
- $_topic = get_topic( $id );
- else
- $_topic =& $topic;
- if ( empty($_topic->topic_id) )
- return 0;
- return (int) $_topic->topic_id;
- }
- function topic_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) {
- echo apply_filters( 'topic_link', get_topic_link( $id, $page, $context ), $id, $page, $context );
- }
- function get_topic_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) {
- $topic = get_topic( get_topic_id( $id ) );
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF;
- }
- $args = array();
- $rewrite = bb_get_option( 'mod_rewrite' );
- if ( $rewrite ) {
- if ( $rewrite === 'slugs' ) {
- $column = 'topic_slug';
- } else {
- $column = 'topic_id';
- }
- $page = (1 < $page) ? '/page/' . $page : '';
- $link = bb_get_uri('topic/' . $topic->$column . $page, null, $context);
- } else {
- $page = (1 < $page) ? $page : false;
- $link = bb_get_uri('topic.php', array('id' => $topic->topic_id, 'page' => $page), $context);
- }
- return apply_filters( 'get_topic_link', $link, $topic->topic_id, $context );
- }
- function topic_rss_link( $id = 0, $context = 0 ) {
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- echo apply_filters('topic_rss_link', get_topic_rss_link($id, $context), $id, $context );
- }
- function get_topic_rss_link( $id = 0, $context = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- if (!$context || !is_integer($context)) {
- $context = BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_FEED;
- }
- $rewrite = bb_get_option( 'mod_rewrite' );
- if ( $rewrite ) {
- if ( $rewrite === 'slugs' ) {
- $column = 'topic_slug';
- } else {
- $column = 'topic_id';
- }
- $link = bb_get_uri('rss/topic/' . $topic->$column, null, $context);
- } else {
- $link = bb_get_uri('rss.php', array('topic' => $topic->topic_id), $context);
- }
- return apply_filters( 'get_topic_rss_link', $link, $topic->topic_id, $context );
- }
- function bb_topic_labels() {
- echo apply_filters( 'bb_topic_labels', null );
- }
- function topic_title( $id = 0 ) {
- echo apply_filters( 'topic_title', get_topic_title( $id ), get_topic_id( $id ) );
- }
- function get_topic_title( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- return apply_filters( 'get_topic_title', $topic->topic_title, $topic->topic_id );
- }
- function topic_page_links( $id = 0, $args = null ) {
- echo apply_filters( 'topic_page_links', get_topic_page_links( $id, $args ), get_topic_id( $id ) );
- }
- function get_topic_page_links( $id = 0, $args = null ) {
- $defaults = array(
- 'show_all' => false,
- 'end_size' => 3,
- 'before' => ' - ',
- 'after' => null
- );
- $args = wp_parse_args( $args, $defaults );
- $topic = get_topic( get_topic_id( $id ) );
- $uri = get_topic_link();
- if ( bb_get_option('mod_rewrite') ) {
- if ( false === $pos = strpos( $uri, '?' ) ) {
- $uri = $uri . '%_%';
- } else {
- $uri = substr_replace( $uri, '%_%', $pos, 0 );
- }
- } else {
- $uri = add_query_arg( 'page', '%_%', $uri );
- }
- $posts = $topic->topic_posts + topic_pages_add( $topic->topic_id );
- $per_page = apply_filters( 'get_topic_page_links_per_page', bb_get_option('page_topics') );
- $_links = bb_paginate_links(
- array(
- 'base' => $uri,
- 'format' => bb_get_option('mod_rewrite') ? '/page/%#%' : '%#%',
- 'total' => ceil($posts/$per_page),
- 'current' => 0,
- 'show_all' => $args['show_all'],
- 'end_size' => $args['end_size'],
- 'type' => 'array'
- )
- );
- $links = $_links;
- if ( $links ) {
- if ( !$show_first ) {
- unset( $links[0] );
- }
- $r = '';
- if ( $args['before'] ) {
- $r .= $args['before'];
- }
- $r .= join('', $links);
- if ( $args['after'] ) {
- $r .= $args['after'];
- }
- }
- return apply_filters( 'get_topic_page_links', $r, $_links, $topic->topic_id );
- }
- function bb_topic_voices( $id = 0 ) {
- echo apply_filters( 'bb_topic_voices', bb_get_topic_voices( $id ), get_topic_id( $id ) );
- }
- function bb_get_topic_voices( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- if ( empty( $topic->voices_count ) ) {
- global $bbdb;
- 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 ) ) ) {
- $voices = count( $voices );
- bb_update_topicmeta( $topic->topic_id, 'voices_count', $voices );
- }
- } else {
- $voices = $topic->voices_count;
- }
- return apply_filters( 'bb_get_topic_voices', $voices, $topic->topic_id );
- }
- function topic_posts( $id = 0 ) {
- echo apply_filters( 'topic_posts', get_topic_posts( $id ), get_topic_id( $id ) );
- }
- function get_topic_posts( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- return apply_filters( 'get_topic_posts', $topic->topic_posts, $topic->topic_id );
- }
- function get_topic_deleted_posts( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- return apply_filters( 'get_topic_deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts : 0, $topic->topic_id );
- }
- function topic_noreply( $title ) {
- if ( 1 == get_topic_posts() && ( bb_is_front() || bb_is_forum() ) )
- $title = "<strong>$title</strong>";
- return $title;
- }
- function topic_last_poster( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- echo apply_filters( 'topic_last_poster', get_topic_last_poster( $id ), $topic->topic_last_poster, $topic->topic_id ); // $topic->topic_last_poster = user ID
- }
- function get_topic_last_poster( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- $user_display_name = get_user_display_name($topic->topic_last_poster);
- return apply_filters( 'get_topic_last_poster', $user_display_name, $topic->topic_last_poster, $topic->topic_id ); // $topic->topic_last_poster = user ID
- }
- function topic_author( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- echo apply_filters( 'topic_author', get_topic_author( $id ), $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID
- }
- function get_topic_author( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- $user_display_name = get_user_display_name($topic->topic_poster);
- return apply_filters( 'get_topic_author', $user_display_name, $topic->topic_poster, $topic->topic_id ); // $topic->topic_poster = user ID
- }
- // Filters expect the format to by mysql on both topic_time and get_topic_time
- function topic_time( $args = '' ) {
- $args = _bb_parse_time_function_args( $args );
- $time = apply_filters( 'topic_time', get_topic_time( array('format' => 'mysql') + $args), $args );
- echo _bb_time_function_return( $time, $args );
- }
- function get_topic_time( $args = '' ) {
- $args = _bb_parse_time_function_args( $args );
- $topic = get_topic( get_topic_id( $args['id'] ) );
- $time = apply_filters( 'get_topic_time', $topic->topic_time, $args );
- return _bb_time_function_return( $time, $args );
- }
- function topic_start_time( $args = '' ) {
- $args = _bb_parse_time_function_args( $args );
- $time = apply_filters( 'topic_start_time', get_topic_start_time( array('format' => 'mysql') + $args), $args );
- echo _bb_time_function_return( $time, $args );
- }
- function get_topic_start_time( $args = '' ) {
- $args = _bb_parse_time_function_args( $args );
- $topic = get_topic( get_topic_id( $args['id'] ) );
- $time = apply_filters( 'get_topic_start_time', $topic->topic_start_time, $args, $topic->topic_id );
- return _bb_time_function_return( $time, $args );
- }
- function topic_last_post_link( $id = 0 ) {
- echo apply_filters( 'topic_last_post_link', get_topic_last_post_link( $id ), $id);
- }
- function get_topic_last_post_link( $id = 0 ){
- $topic = get_topic( get_topic_id( $id ) );
- $page = bb_get_page_number( $topic->topic_posts );
- 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 );
- }
- function topic_pages( $args = null )
- {
- // Compatibility
- if ( $args && is_numeric( $args ) ) {
- $args = array( 'id' => $args );
- }
- $defaults = array( 'id' => 0, 'before' => '', 'after' => '' );
- $args = wp_parse_args( $args, $defaults );
- global $page;
- $topic = get_topic( get_topic_id( $args['id'] ) );
- $add = topic_pages_add( $topic->topic_id );
- if ( $pages = apply_filters( 'topic_pages', get_page_number_links( $page, $topic->topic_posts + $add ), $topic->topic_id ) ) {
- echo $args['before'] . $pages . $args['after'];
- }
- }
- function topic_pages_add( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- if ( isset($_GET['view']) && 'all' == $_GET['view'] && bb_current_user_can('browse_deleted') && isset( $topic->deleted_posts ) )
- $add = $topic->deleted_posts;
- else
- $add = 0;
- return apply_filters( 'topic_pages_add', $add, isset($topic->topic_id) ? $topic->topic_id : 0 );
- }
- function get_page_number_links( $args ) {
- if ( 1 < func_num_args() ) {
- $_args = func_get_args();
- $args = array(
- 'page' => $_args[0],
- 'total' => $_args[1],
- 'per_page' => isset( $_args[2] ) ? $_args[2] : '',
- 'mod_rewrite' => isset( $_args[3] ) ? $_args[3] : 'use_option'
- );
- }
- $defaults = array(
- 'page' => 1,
- 'total' => false,
- 'per_page' => '',
- 'mod_rewrite' => 'use_option',
- 'prev_text' => __( '« Previous' ),
- 'next_text' => __( 'Next »' )
- );
- $args = wp_parse_args( $args, $defaults );
- extract( $args, EXTR_SKIP );
- $add_args = array();
- $uri = rtrim( $_SERVER['REQUEST_URI'], '?&' );
- if ( $mod_rewrite === 'use_option' ) {
- $mod_rewrite = bb_get_option( 'mod_rewrite' );
- }
- if ( $mod_rewrite ) {
- $format = '/page/%#%';
- if ( 1 == $page ) {
- if ( false === $pos = strpos($uri, '?') )
- $uri = $uri . '%_%';
- else
- $uri = substr_replace($uri, '%_%', $pos, 0);
- } else {
- $uri = preg_replace('|/page/[0-9]+|', '%_%', $uri);
- }
- $uri = str_replace( '/%_%', '%_%', $uri );
- } else {
- if ( 1 == $page ) {
- if ( false === $pos = strpos($uri, '?') ) {
- $uri = $uri . '%_%';
- $format = '?page=%#%';
- } else {
- $uri = substr_replace($uri, '?%_%', $pos, 1);
- $format = 'page=%#%&';
- }
- } else {
- if ( false === strpos($uri, '?page=') ) {
- $uri = preg_replace('!&page=[0-9]+!', '%_%', $uri );
- $uri = str_replace( '&page=', '', $uri );
- $format = '&page=%#%';
- } else {
- $uri = preg_replace('!\?page=[0-9]+!', '%_%', $uri );
- $uri = str_replace( '?page=', '', $uri );
- $format = '?page=%#%';
- }
- }
- }
- if ( isset($_GET['view']) && in_array($_GET['view'], bb_get_views()) )
- $add_args['view'] = $_GET['view'];
- if ( empty( $per_page ) ) {
- $per_page = bb_get_option( 'page_topics' );
- }
- $links = bb_paginate_links( array(
- 'base' => $uri,
- 'format' => $format,
- 'total' => ceil( $total/$per_page ),
- 'current' => $page,
- 'add_args' => $add_args,
- 'type' => 'array',
- 'mid_size' => 1,
- 'prev_text' => $prev_text,
- 'next_text' => $next_text
- ) );
- if ($links) {
- $links = join('', $links);
- }
- return $links;
- }
- function bb_topic_admin( $args = '' )
- {
- $parts = array(
- 'delete' => bb_get_topic_delete_link( $args ),
- 'close' => bb_get_topic_close_link( $args ),
- 'sticky' => bb_get_topic_sticky_link( $args ),
- 'move' => bb_get_topic_move_dropdown( $args )
- );
- echo join( "\n", apply_filters( 'bb_topic_admin', $parts ) );
- }
- function topic_delete_link( $args = '' ) {
- echo bb_get_topic_delete_link( $args );
- }
- function bb_get_topic_delete_link( $args = '' ) {
- $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'delete_text' => false, 'undelete_text' => false, 'redirect' => true );
- extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
- $id = (int) $id;
- $topic = get_topic( get_topic_id( $id ) );
- if ( !$topic || !bb_current_user_can( 'delete_topic', $topic->topic_id ) )
- return;
- if ( true === $redirect )
- $redirect = $_SERVER['REQUEST_URI'];
- if ( 0 == $topic->topic_status ) {
- $query = array( 'id' => $topic->topic_id, '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false );
- $confirm = __('Are you sure you wanna delete that?');
- $display = esc_html( $delete_text ? $delete_text : __('Delete entire topic') );
- } else {
- $query = array('id' => $topic->topic_id, 'view' => 'all', '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false );
- $confirm = __('Are you sure you wanna undelete that?');
- $display = esc_html( $undelete_text ? $undelete_text : __('Undelete entire topic') );
- }
- $uri = bb_get_uri('bb-admin/delete-topic.php', $query, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN);
- $uri = esc_url( bb_nonce_url( $uri, 'delete-topic_' . $topic->topic_id ) );
-
- return $before . '<a href="' . $uri . '" onclick="return confirm(\'' . esc_js( $confirm ) . '\');">' . $display . '</a>' . $after;
- }
- function topic_close_link( $args = '' ) {
- echo bb_get_topic_close_link( $args );
- }
- function bb_get_topic_close_link( $args = '' ) {
- $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'close_text' => false, 'open_text' => false, 'redirect' => true );
- extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
- $id = (int) $id;
- $topic = get_topic( get_topic_id( $id ) );
- if ( !$topic || !bb_current_user_can( 'close_topic', $topic->topic_id ) )
- return;
- if ( topic_is_open( $topic->topic_id ) )
- $display = esc_html( $close_text ? $close_text : __( 'Close topic' ) );
- else
- $display = esc_html( $open_text ? $open_text : __( 'Open topic' ) );
- if ( true === $redirect )
- $redirect = $_SERVER['REQUEST_URI'];
- $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);
- $uri = esc_url( bb_nonce_url( $uri, 'close-topic_' . $topic->topic_id ) );
-
- return $before . '<a href="' . $uri . '">' . $display . '</a>' . $after;
- }
- function topic_sticky_link( $args = '' ) {
- echo bb_get_topic_sticky_link( $args );
- }
- function bb_get_topic_sticky_link( $args = '' ) {
- $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' );
- extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
- $id = (int) $id;
- $topic = get_topic( get_topic_id( $id ) );
- if ( !$topic || !bb_current_user_can( 'stick_topic', $topic->topic_id ) )
- return;
- $uri_stick = bb_get_uri('bb-admin/sticky.php', array('id' => $topic->topic_id), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN);
- $uri_stick = esc_url( bb_nonce_url( $uri_stick, 'stick-topic_' . $topic->topic_id ) );
- $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);
- $uri_super = esc_url( bb_nonce_url( $uri_super, 'stick-topic_' . $topic->topic_id ) );
- if ( topic_is_sticky( $topic->topic_id ) )
- return "$before<a href='" . $uri_stick . "'>". __('Unstick topic') ."</a>$after";
- else
- return "$before<a href='" . $uri_stick . "'>". __('Stick topic') . "</a> (<a href='" . $uri_super . "'>" . __('to front') . "</a>)$after";
- }
- function topic_show_all_link( $id = 0 ) {
- if ( !bb_current_user_can( 'browse_deleted' ) )
- return;
- if ( 'all' == @$_GET['view'] )
- echo "<a href='" . esc_attr( get_topic_link( $id ) ) . "'>". __('View normal posts') ."</a>";
- else
- echo "<a href='" . esc_attr( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>". __('View all posts') ."</a>";
- }
- function topic_posts_link( $id = 0 ) {
- echo get_topic_posts_link( $id );
- }
- function get_topic_posts_link( $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- $post_num = get_topic_posts( $id );
- $posts = sprintf(__ngettext( '%s post', '%s posts', $post_num ), $post_num);
- $r = '';
- if ( ( 'all' == @$_GET['view'] || bb_is_admin() ) && bb_current_user_can('browse_deleted') )
- $r .= "<a href='" . esc_attr( get_topic_link( $id ) ) . "'>$posts</a>";
- else
- $r .= $posts;
- if ( bb_current_user_can( 'browse_deleted' ) ) {
- $user_id = bb_get_current_user_info( 'id' );
- if ( isset($topic->bozos[$user_id]) && 'all' != @$_GET['view'] )
- add_filter('get_topic_deleted_posts', create_function('$a', "\$a -= {$topic->bozos[$user_id]}; return \$a;") );
- if ( $deleted = get_topic_deleted_posts( $id ) ) {
- $extra = sprintf(__('+%d more'), $deleted);
- if ( 'all' == @$_GET['view'] )
- $r .= " $extra";
- else
- $r .= " <a href='" . esc_attr( add_query_arg( 'view', 'all', get_topic_link( $id ) ) ) . "'>$extra</a>";
- }
- }
- return $r;
- }
- function topic_move_dropdown( $args = '' )
- {
- echo bb_get_topic_move_dropdown( $args );
- }
- function bb_get_topic_move_dropdown( $args = '' )
- {
- if ( $args && is_numeric( $args ) ) {
- $args = array( 'id' => (integer) $args );
- }
- $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']' );
- extract(wp_parse_args( $args, $defaults ), EXTR_SKIP);
- $id = (int) $id;
- $topic = get_topic( get_topic_id( $id ) );
- if ( !bb_current_user_can( 'move_topic', $topic->topic_id ) )
- return;
- $dropdown = bb_get_forum_dropdown( array(
- 'callback' => 'bb_current_user_can',
- 'callback_args' => array('move_topic', $topic->topic_id),
- 'selected' => $topic->forum_id,
- 'tab' => false
- ) );
- if ( !$dropdown )
- return;
- $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";
- $r .= '<fieldset>' . "\n";
- $r .= '<div>' . "\n";
- $r .= '<input type="hidden" name="topic_id" value="' . $topic->topic_id . '" />' . "\n";
- $r .= '<label for="forum-id">'. __( 'Move to' ) . '</label>' . "\n";
- $r .= $dropdown . "\n";
- $r .= bb_nonce_field( 'move-topic_' . $topic->topic_id, '_wpnonce', true , false );
- $r .= '<input type="submit" name="Submit" value="' . __( 'Move' ) . '" />' . "\n";
- $r .= '</div>' . "\n";
- $r .= '</fieldset>' . "\n";
- $r .= '</form>' . $after;
- return $r;
- }
- function topic_class( $class = '', $key = 'topic', $id = 0 ) {
- $topic = get_topic( get_topic_id( $id ) );
- $class = $class ? explode(' ', $class ) : array();
- if ( '1' === $topic->topic_status && bb_current_user_can( 'browse_deleted' ) )
- $class[] = 'deleted';
- elseif ( 1 < $topic->topic_status && bb_current_user_can( 'browse_deleted' ) )
- $class[] = 'bozo';
- if ( '0' === $topic->topic_open )
- $class[] = 'closed';
- if ( 1 == $topic->topic_sticky && ( bb_is_forum() || bb_is_view() ) )
- $class[] = 'sticky';
- elseif ( 2 == $topic->topic_sticky && ( bb_is_front() || bb_is_forum() ) )
- $class[] = 'sticky super-sticky';
- $class = apply_filters( 'topic_class', $class, $topic->topic_id );
- $class = join(' ', $class);
- alt_class( $key, $class );
- }
- /**
- * bb_get_new_topic_link() - Get the link to the form for a new topic
- *
- * @since 1.0
- * @param mixed The arguments for this function.
- * @return string The link to the new topic form
- */
- function bb_get_new_topic_link( $args = null ) {
- $defaults = array( 'text' => __('Add New »'), 'forum' => 0, 'tag' => '' );
- if ( $args && is_string($args) && false === strpos($args, '=') )
- $args = array( 'text' => $args );
- $args = wp_parse_args( $args, $defaults );
- extract( $args, EXTR_SKIP );
- if ( $forum && $forum = bb_get_forum( $forum ) )
- $url = get_forum_link( $forum->forum_id ) . '#postform';
- elseif ( $tag && $tag = bb_get_tag( $tag ) )
- $url = bb_get_tag_link( $tag->tag ) . '#postform';
- elseif ( bb_is_forum() ) {
- global $forum;
- $url = get_forum_link( $forum->forum_id ) . '#postform';
- } elseif ( bb_is_tag() ) {
- global $tag;
- $url = bb_get_tag_link( $tag ) . '#postform';
- } elseif ( bb_is_topic() )
- $url = get_forum_link() . '#postform';
- elseif ( bb_is_front() )
- $url = bb_get_uri(null, array('new' => 1));
- if ( !bb_is_user_logged_in() )
- $url = bb_get_uri('bb-login.php', array('re' => $url), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS);
- elseif ( bb_is_forum() || bb_is_topic() ) {
- if ( !bb_current_user_can( 'write_topic', get_forum_id() ) )
- return;
- } else {
- if ( !bb_current_user_can( 'write_topics' ) )
- return;
- }
- if ( $url = esc_attr( apply_filters( 'new_topic_url', $url, $args ) ) )
- return '<a href="' . $url . '" class="new-topic">' . $text . '</a>' . "\n";
- }
- function bb_new_topic_link( $args = null ) {
- echo bb_get_new_topic_link($args);
- }
- function bb_new_topic_forum_dropdown( $args = '' ) {
- if ( !is_array( $args ) ) {
- $args = array(
- 'callback' => 'bb_current_user_can',
- 'callback_args' => array( 'write_topic' )
- );
- }
- if ( !isset( $args['callback'] ) && !isset( $args['callback_args'] ) ) {
- $args['callback'] = 'bb_current_user_can';
- $args['callback_args'] = array( 'write_topic' );
- }
- bb_forum_dropdown( $args );
- }
- function bb_topic_search_form( $args = null, $query_obj = null ) {
- global $bb_query_form;
- if ( $query_obj && is_a($query_obj, 'BB_Query_Form') ); // [sic]
- else
- $query_obj =& $bb_query_form;
- $query_obj->form( $args );
- }
- /**
- * bb_topic_pagecount() - Print the total page count for a topic
- *
- * @since 0.9
- * @param int $topic_id The topic id of the topic being queried
- * @return void
- */
- function bb_topic_pagecount( $topic_id = 0 ) {
- echo bb_get_topic_pagecount( $topic_id );
- }
- /**
- * bb_get_topic_pagecount() - Get the total page count for a topic
- *
- * @since 0.9
- * @param int $topic_id The topic id of the topic being queried
- * @return int The total number of pages in the topic
- */
- function bb_get_topic_pagecount( $topic_id = 0 ) {
- $topic = get_topic( get_topic_id( $topic_id ) );
- 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