function bcg_posts_pagination_count($q)
{
    $posts_per_page = intval(get_query_var('posts_per_page'));
    $paged = intval(get_query_var('paged'));
    $numposts = $q->found_posts;
    $max_page = $q->max_num_pages;
    if (empty($paged) || $paged == 0) {
        $paged = 1;
    }
    $start_num = intval($posts_per_page * ($paged - 1)) + 1;
    $from_num = bp_core_number_format($start_num);
    $to_num = bp_core_number_format($start_num + ($posts_per_page - 1) > $numposts ? $numposts : $start_num + ($posts_per_page - 1));
    $total = bp_core_number_format($numposts);
    //$taxonomy = get_taxonomy( bcg_get_taxonomy() );
    $post_type_object = get_post_type_object(bcg_get_post_type());
    printf(__('Viewing %1s %2$s to %3$s (of %4$s )', 'bcg'), $post_type_object->labels->name, $from_num, $to_num, $total) . " ";
    //$term = get_term_name ( $q->query_vars['cat'] );
    //if( bcg_is_category() )
    // printf( __( "In the %s %s ","bcg" ), $taxonomy->label, "<span class='bcg-cat-name'>". $term_name ."</span>" );
    ?>
	<span class="ajax-loader"></span><?php 
}
function bcg_get_query()
{
    $bp = buddypress();
    $cats = bcg_get_categories($bp->groups->current_group->id);
    $qs = array('post_type' => bcg_get_post_type(), 'post_status' => 'publish');
    if (empty($cats)) {
        $qs['name'] = -1;
        //we know it will not find anything
    }
    if (bcg_is_single_post()) {
        $slug = $bp->action_variables[0];
        $qs['name'] = $slug;
        //tax query
        $qs['tax_query'] = array(array('taxonomy' => bcg_get_taxonomy(), 'terms' => $cats, 'field' => 'id', 'operator' => 'IN'));
    }
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    if (bcg_is_category()) {
        $qs['tax_query'] = array(array('taxonomy' => bcg_get_taxonomy(), 'terms' => (int) bp_action_variable(1), 'field' => 'id', 'operator' => 'IN'));
    } else {
        $qs['tax_query'] = array(array('taxonomy' => bcg_get_taxonomy(), 'terms' => $cats, 'field' => 'id', 'operator' => 'IN'));
    }
    $qs['paged'] = $paged;
    return apply_filters("bcg_get_query", $qs);
}
/**
 * Get psot by slug
 * 
 * @global type $wpdb
 * @param string $slug
 */
function bcg_get_post_by_slug($slug)
{
    global $wpdb;
    $query = "SELECT * FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s LIMIT 1";
    $post = $wpdb->get_row($wpdb->prepare($query, $slug, bcg_get_post_type()));
    return $post;
}
{
    if (!bcg_is_single_post()) {
        return;
    }
    $post = get_post($post_id);
    $permalink = bcg_get_post_permalink($post);
    ?>
	<input type='hidden' name='redirect_to' value="<?php 
    echo esc_url($permalink);
    ?>
" />
	<?php 
}
/* fixing permalinks for posts/categories inside the bcg loop */
//fix post permalink, should we ?
if (bcg_get_post_type() == 'post') {
    add_filter('post_link', 'bcg_fix_permalink', 10, 3);
} else {
    add_filter('post_type_link', 'bcg_fix_permalink', 10, 3);
}
function bcg_fix_permalink($post_link, $id, $leavename)
{
    if (!bcg_is_component() || !in_bcg_loop()) {
        return $post_link;
    }
    $post_link = bcg_get_post_permalink(get_post($id));
    return $post_link;
}
//todo ix term link too
//on Blog category pages fix the category link to point to internal, may cause troubles in some case
add_filter('category_link', 'bcg_fix_category_permalink', 10, 2);
 /**
  * register post form for Posting/editing
  * @return type 
  */
 public function register_form()
 {
     //make sure the Front end simple post plugin is active
     if (!function_exists('bp_new_simple_blog_post_form')) {
         return;
     }
     $post_status = 'draft';
     $user_id = get_current_user_id();
     $group_id = bp_get_current_group_id();
     $settings = array('post_type' => bcg_get_post_type(), 'post_author' => $user_id, 'post_status' => $post_status, 'comment_status' => 'open', 'show_comment_option' => false, 'custom_field_title' => '', 'custom_fields' => array('_is_bcg_post' => array('type' => 'hidden', 'label' => '', 'default' => 1)), 'tax' => array(bcg_get_taxonomy() => array('include' => bcg_get_categories($group_id))), 'upload_count' => 3, 'has_post_thumbnail' => 1, 'current_user_can_post' => bcg_current_user_can_post(), 'update_callback' => array($this, 'on_save'));
     //use it to add extra fields or filter the post type etc
     $settings = apply_filters('bcg_form_args', $settings);
     $form = bp_new_simple_blog_post_form('bcg_form', $settings);
 }