Guest User

bp-postsonprofile-core

a guest
Jan 9th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.46 KB | None | 0 0
  1. <?php
  2. define ( 'BP_POSTSONPROFILE_IS_INSTALLED', 1 );
  3. define ( 'BP_POSTSONPROFILE_VERSION', '0.1' );
  4.  
  5. if ( !defined( 'BP_POSTSONPROFILE_SLUG' ) )
  6.     define ( 'BP_POSTSONPROFILE_SLUG', 'posts' );
  7.  
  8. if ( file_exists( WP_CONTENT_DIR . '/languages/bp-postsonprofile-' . get_locale() . '.mo' ) )
  9.     load_textdomain( 'bp-postsonprofile', WP_CONTENT_DIR . '/languages/bp-postsonprofile-' . get_locale() . '.mo' );
  10. elseif ( file_exists( dirname( __FILE__ ) . '/languages/bp-postsonprofile-' . get_locale() . '.mo' ) )
  11.     load_textdomain( 'bp-postsonprofile', dirname( __FILE__ ) . '/languages/bp-postsonprofile-' . get_locale() . '.mo' );
  12.  
  13. /**
  14.  * bp_postsonprofile_setup_globals()
  15.  *
  16.  * Sets up global variables for your component.
  17.  */
  18. function bp_postsonprofile_setup_globals() {
  19.     global $bp, $wpdb;
  20.  
  21.     /* For internal identification */
  22.     $bp->postsonprofile->id = 'postsonprofile';
  23.     $bp->postsonprofile->table_name = $wpdb->base_prefix . 'bp_postsonprofile';
  24.     $bp->postsonprofile->format_notification_function = 'bp_postsonprofile_format_notifications';
  25.     $bp->postsonprofile->slug = BP_POSTSONPROFILE_SLUG;
  26.  
  27.     /* Register this in the active components array */
  28.     $bp->active_components[$bp->postsonprofile->slug] = $bp->postsonprofile->id;
  29. }
  30. add_action( 'wp', 'bp_postsonprofile_setup_globals', 2 );
  31. function bp_pop_cur_page() {
  32.     $pageURL = 'http';
  33.     if ($_SERVER["HTTPS"] == "on") $pageURL .= "s";
  34.     $pageURL .= "://";
  35.     if ($_SERVER["SERVER_PORT"] != "80")
  36.         $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  37.     else
  38.         $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  39.     $urlEnd = substr($pageURL, -3);
  40.     return str_replace("/", "", $urlEnd);
  41. }
  42. function bp_postsonprofile_setup_nav() {
  43.     global $bp, $wpdb;
  44.     $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
  45.     $where = $wpdb->prepare('WHERE post_author = %d AND post_type = %s AND post_status=%s', $user_id, 'post', 'publish');
  46.     $post_count  = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
  47.     $post_count = $post_count ? $post_count : 0;
  48.     $postsonprofile_link = $bp->loggedin_user->domain . $bp->postsonprofile->slug . '/';
  49.  
  50.     bp_core_new_nav_item( array(
  51.         'name' => sprintf(__( 'Blog <span>%d</span>', 'bp-postsonprofile' ), $post_count),
  52.         'slug' => $bp->postsonprofile->slug,
  53.         'position' => 21,
  54.         'screen_function' => 'bp_postsonprofile_screen_one',
  55.     ) );
  56.  
  57.     if ( (int) bp_pop_cur_page() > 0) {
  58.         bp_core_new_subnav_item( array(
  59.             'name' => 'Page '. bp_pop_cur_page(),
  60.             'slug' => 'page',
  61.             'parent_slug' => $bp->postsonprofile->slug,
  62.             'parent_url' => $postsonprofile_link,
  63.             'screen_function' => 'bp_postsonprofile_screen_one',
  64.             'position' => 20,
  65.         ) );
  66.         bp_core_new_subnav_item( array(
  67.             'name' => 'Page '.bp_pop_cur_page(),
  68.             'slug' => bp_pop_cur_page(),
  69.             'parent_slug' => $bp->postsonprofile->slug .'/page',
  70.             'parent_url' => $postsonprofile_link .'/page/',
  71.             'screen_function' => 'bp_postsonprofile_screen_one',
  72.             'position' => 20,
  73.         ) );
  74.     }
  75. }
  76.  
  77. /***
  78.  * In versions of BuddyPress 1.2.2 and newer you will be able to use:
  79.  * add_action( 'bp_setup_nav', 'bp_postsonprofile_setup_nav' );
  80.  */
  81. add_action( 'wp', 'bp_postsonprofile_setup_nav', 2 );
  82.  
  83. function bp_postsonprofile_load_template_filter( $found_template, $templates ) {
  84.     global $bp;
  85.  
  86.     /**
  87.      * Only filter the template location when we're on the postsonprofile component pages.
  88.      */
  89.     if ( $bp->current_component != $bp->postsonprofile->slug )
  90.         return $found_template;
  91.  
  92.     foreach ( (array) $templates as $template ) {
  93.         if ( file_exists( STYLESHEETPATH . '/members/single/' . $template ) )
  94.             $filtered_templates[] = STYLESHEETPATH . '/members/single/' . $template;
  95.         else
  96.             $filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
  97.     }
  98.  
  99.     $found_template = $filtered_templates[0];
  100.  
  101.     return apply_filters( 'bp_postsonprofile_load_template_filter', $found_template );
  102. }
  103. add_filter( 'bp_located_template', 'bp_postsonprofile_load_template_filter', 10, 2 );
  104.  
  105. function bp_postsonprofile_screen_one() {
  106.     global $bp;
  107.  
  108.     /* Add a do action here, so your component can be extended by others. */
  109.     do_action( 'bp_postsonprofile_screen_one' );
  110.  
  111.     /* This is going to look in wp-content/plugins/[plugin-name]/includes/templates/ first */
  112.     bp_core_load_template( apply_filters( 'bp_postsonprofile_template_screen_one', 'postsonprofile/screen-one' ) );
  113.  
  114. }
  115.  
  116.  
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment