label;
	}
	return $title;
}
add_filter( 'get_the_archive_title', 'singularity_filter_topics_archive_title' );
// We remove some filters in order to restructure the meta data in the single topics template
global $CT_DB_Skins;
// Remove date
remove_filter( 'ctdb_info_meta_after_classic_meta', array( $CT_DB_Skins, 'topic_date_classic' ) );
if( ! function_exists( 'singularity_ctdb_author_meta' ) ) {
	function singularity_ctdb_author_meta( $output, $author ) {
	
		$avatar = get_avatar( get_the_author_meta( 'ID' ), 40 );
		$posted_on = ctdb_topic_date_time();
	
		$return = '
			' . $avatar . '
			
				' . $author . '
				' . $posted_on . '
			 ';
		$return .= sprintf( '
%s', get_edit_post_link(),  __( 'Edit', 'singularity' ) );
		$return .= '
 ';
	
		return $return;
	
	}
}
add_filter( 'ctdb_info_bar_table', 'singularity_ctdb_author_meta', 10, 2 );
if( ! function_exists( 'singularity_discussion_topic_meta' ) ) {
	function singularity_discussion_topic_meta() {
		$avatar = get_avatar( get_the_author_meta( 'ID' ), 40 );
		$posted_on = ctdb_topic_date_time();
	
		$return = '
			' . $avatar . '
			
				' . $author . '
				' . $posted_on . '
			 ';
		$return .= sprintf( '
%s', get_edit_post_link(),  __( 'Edit', 'singularity' ) );
		$return .= '
 ';
	
		return $return;
	}
}
/**
 * Filter comment text for Discussion Board
 */
if ( ! function_exists ( 'singularity_ctdb_classic_forum_comment' ) ) {
	function singularity_ctdb_classic_forum_comment( $comment_html, $comment, $args, $depth ) {
		
		$avatar = get_avatar( $comment, 40 );
		$comment_date = sprintf( __( '%1$s at %2$s', 'singularity' ), get_comment_date( '', $comment ), get_comment_time() );
		$author = get_comment_author_link( $comment );
		
		$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
		
		// Build the comment HTML
		$classes = get_comment_class( empty( $args['has_children']) ? 'parent' : '', $comment );
		$comment_html = '';
		
		echo $comment_html;
	}
}
add_filter( 'ctdb_filter_comment_html', 'singularity_ctdb_classic_forum_comment', 10, 4 );
// Move breadcrumb to above the content area
remove_action( 'ctdb_do_breadcrumb', 'ctdb_breadcrumb_navigation' );
add_action( 'singularity_ctdb_do_breadcrumb', 'ctdb_breadcrumb_navigation' );
/**
 * Display board taxonomy description, image and meta
 */
if( ! function_exists( 'singularity_ctdb_board_description' ) ) {
	function singularity_ctdb_board_description() {
		$term = get_term_by( 'slug', get_query_var('term'), get_query_var( 'taxonomy' ) );
		$image_id = get_term_meta( $term->term_id, 'ctdb-board-image-id', true ); ?>
		
			
			
				
			
			
			
				', '
' );
				$options = get_option( 'ctdb_boards_settings' );
				$fields = array();
				if( isset( $options['boards_fields'] ) ) {
					$fields = $options['boards_fields'];
				}
		
				// Get list of all available fields
				$all_fields = ctdb_boards_fields();
		
				// Iterate through selected fields
				if( ! empty( $fields ) && ! empty( $all_fields ) ) {
					foreach( $fields as $field ) {
						// If the field is available, add the content
						if( isset( $all_fields[$field]['callback'] ) && function_exists( $all_fields[$field]['callback'] ) ) {
							echo '
';
								$label = $all_fields[$field]['label'];
								echo call_user_func( $all_fields[$field]['callback'], $term, $term->term_id, $label );
							echo '
';
						}
				
					}
				}
				?>
			
 
		
	';
		if( $term->name ) {
			$new_content .= '';
			
				if( ctdb_is_user_permitted() == true && $term->count > 0 ) {
					// Site title and link
					$new_content .= sprintf( '
',
						esc_attr( 'board-title' ),
						esc_url( get_term_link( $board_id ) ),
						esc_textarea( $term->name ) 
					);
				} else {
					// Site title only if no topics exist yet or user is not permitted
					$new_content .= sprintf( '
%s
',
						esc_attr( 'board-title' ),
						esc_textarea( $term->name ) 
					);
				}
			$new_content .= '
';
			$new_content .= '
';
				$image_id = get_term_meta( $term->term_id, 'ctdb-board-image-id', true );
				$new_content .= wp_get_attachment_image( $image_id );
			//	$content .= wpautop( $term->description );
			$new_content .= '
';
		
			$new_content .= '
';
		$new_content .= '
' . $field_titles[$col] . '
';
				}
				
			}
		}
		
		return $title_fields;
	}
}
add_filter( 'ctdb_topic_title_fields', 'singularity_ctdb_filter_topic_title_fields', 10, 2 );
/**
 * Redo query that lists each topic in classic layout view
 * @param $output		Initial value, should be empty
 * @param $topics 		wp_query object
 * @param $titles		Selected column titles
 * @param $cols			Which columns to include
 */
if( ! function_exists( 'singularity_ctdb_filter_table_layout' ) ) {
	function singularity_ctdb_filter_table_layout( $output, $topics, $titles, $cols ) {
		
		// Fields enabled on the DB Design tab
		$cols = ctdb_selected_meta_fields();
		$count_cols = count( $cols );
		
		// Only some columns are allowed
		// E.g. freshness is added under topic title with name of poster
		$permitted_cols = array(
			'replies', 'voices', 'status'
		);
		
		// Column headings
		$field_titles = ctdb_meta_data_fields();
		
		// Create the titles
		$output = '';
		$output .= '
';
		$output .= '
';
			
			if( ! empty( $cols ) && is_array( $cols ) ) {
				foreach( $cols as $col ) {
					if( in_array( $col, $permitted_cols ) ) {
						$output .= '
' . $field_titles[$col] . '
';
					}
				}
			}
		$output .= '
';
		
			if( $term->count > 0 ) {
				// Only add the link if there are topics in the term
				$footer .= sprintf( '
%s',
					esc_url( get_term_link( $board_id ) ), 
					__( 'See all topics', 'singularity' )
				);
			}				
		
			// Get the page with the new topic form
			$options = get_option( 'ctdb_options_settings' );
			if( isset( $options['new_topic_page'] ) && $options['new_topic_page'] != '' ) {
				$new_topic_page = intval( $options['new_topic_page'] );
				$footer .= sprintf( '
%s',
					esc_url( add_query_arg(
						array(
							'board_id' => $board_id
						), get_permalink( $new_topic_page ) )
					), 
					__( 'Add new topic', 'singularity' )
				);
			
			} else if( current_user_can( 'update_plugins' ) ) {
				// Display a message to admins that there's no topic page set
				// Show admin a message to let them know
				$footer .= '
' . __( 'Site Admin: please set the "New topic form page" field in Settings > Discussion Board > General for the new_topic_button shortcode to work. This message will not be displayed to non-admins.', 'singularity' ) . '
';
			}
			
			// Add a follow board option if enabled
			$follower_options = get_option( 'ctdb_followers_settings' );
			if( ! empty( $follower_options['enable_board_following'] ) && is_user_logged_in() ) {
				// Is the user following this board?
				$is_following = ctdb_is_following_board( $board_id );
				$footer .= '
';
				if( $is_following ) {
					$footer .= sprintf( '%s',
						absint( $board_id ),
						absint( $board_id ),
						ctdb_get_unfollow_this_board_message()
					);
				} else {
					$footer .= sprintf( '%s',
						absint( $board_id ),
						absint( $board_id ),
						ctdb_get_follow_this_board_message()
					);
				}
				$footer .= wp_nonce_field( 'board_follow_nonce_' . absint( $board_id ), 'board_follow_nonce_' . absint( $board_id ), true, false );
				$footer .= '';
				
			}
		
		$footer .= '