Advertisement
Guest User

CB BuddyPress 1.5 Beta 2

a guest
Aug 11th, 2011
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.27 KB | None | 0 0
  1. <?php
  2.  
  3. /* Define a constant that can be checked to see if the component is installed or not. */
  4. define ( 'BP_CUBEPOINT_IS_INSTALLED', 1 );
  5.  
  6. /* Define a constant that will hold the database version number that can be used for upgrading the DB
  7.  *
  8.  * NOTE: When table defintions change and you need to upgrade,
  9.  * make sure that you increment this constant so that it runs the install function again.
  10. */
  11.  
  12. define ( 'BP_CUBEPOINT_DB_VERSION', '1.9.1' );
  13.  
  14.  
  15. /* Translation support */
  16. load_textdomain( 'bp-cubepoint', dirname( __FILE__ ) . '/languages/bp-cubepoint-' . get_locale() . '.mo' );
  17.  
  18. /**
  19.  * The next step is to include all the files you need for your component.
  20.  * You should remove or comment out any files that you don't need.
  21.  */
  22.  
  23. /* The classes file should hold all database access classes and functions */
  24. require ( dirname( __FILE__ ) . '/bp-cubepoint-classes.php' );
  25.  
  26. /* The screens file hold the screens functions */
  27. require ( dirname( __FILE__ ) . '/bp-cubepoint-screens.php' );
  28.  
  29. /* The cssjs file should set up and enqueue all CSS and JS files used by the component */
  30. require ( dirname( __FILE__ ) . '/bp-cubepoint-cssjs.php' );
  31.  
  32. /* The templatetags file should contain classes and functions designed for use in template files */
  33. require ( dirname( __FILE__ ) . '/bp-cubepoint-templatetags.php' );
  34.  
  35. /* The functions file should contain code to add/remove points */
  36. require ( dirname( __FILE__ ) . '/bp-cubepoint-functions.php' );
  37.  
  38. /* The notifications file should contain functions to send email notifications on specific user actions */
  39. // NEW FOR AWARDS
  40. //require ( dirname( __FILE__ ) . '/bp-cubepoint-notifications.php' );
  41. // NEW FOR AWARDS
  42.  
  43. /* The filters file should create and apply filters to component output functions. */
  44. require ( dirname( __FILE__ ) . '/bp-cubepoint-filters.php' );
  45.  
  46. /**
  47.  * bp_cubepoint_setup_globals()
  48.  *
  49.  * Sets up global variables for your component.
  50.  */
  51. function bp_cubepoint_setup_globals() {
  52.     global $bp, $wpdb;
  53.  
  54.     $bp->cubepoint->id = 'cubepoint';
  55.     //$bp->cubepoint->table_name = $wpdb->base_prefix . 'cubepoints';
  56.     $bp->cubepoint->table_name = $wpdb->prefix . 'cubepoints';
  57.    
  58.     // custom SLUG
  59.     //$bp->cubepoint->slug = 'cubepoints';
  60.     $bg_cp_custom_slug = get_option( 'bp_slug_cp_bp' );
  61.     $bp->cubepoint->slug = $bg_cp_custom_slug;
  62.    
  63.     $bp->cubepoint->points_slug = 'points';
  64.     $bp->cubepoint->table_slug = 'table';
  65.     $bp->cubepoint->earnpoints_slug = 'earnpoints';
  66.     $bp->cubepoint->awards_slug = 'awards';
  67.     $bp->cubepoint->bp_cubepoint_per_page = get_option('bp_points_logs_per_page_cp_bp');
  68.  
  69.     // Notifications
  70.     //$bp->cubepoint->format_notification_function = 'bp_cp_awards_format_notifications';
  71.    
  72.     /* Register this in the active components array */
  73.     $bp->active_components[$bp->cubepoint->slug] = $bp->cubepoint->id;
  74.    
  75.     if ( $bp->current_component == $bp->cubepoint->slug && $bp->cubepoint->table_slug != $bp->current_action  ){
  76.         bp_cubepoint_query_points();
  77.     }
  78.     if ( $bp->current_component == $bp->cubepoint->slug && $bp->cubepoint->table_slug == $bp->current_action  ){
  79.         bp_cubepoint_query_points('uid=');
  80.     }  
  81. }
  82.  
  83. /***
  84.  * In versions of BuddyPress 1.2.2 and newer you will be able to use:
  85.  * add_action( 'bp_setup_globals', 'bp_cubepoint_setup_globals' );
  86.  */
  87. add_action( 'wp', 'bp_cubepoint_setup_globals', 2 );
  88. add_action( 'admin_menu', 'bp_cubepoint_setup_globals', 2 );
  89.  
  90. /**
  91.  * bp_cubepoint_add_admin_menu()
  92.  *
  93.  * This function will add a WordPress wp-admin admin menu for your component under the
  94.  * "BuddyPress" menu.
  95.  */
  96. function bp_cubepoint_add_admin_menu() {
  97.     global $bp;
  98.  
  99.     if ( !$bp->loggedin_user->is_site_admin )
  100.         return false;
  101.  
  102.     require_once('bp-cubepoint-admin.php');
  103.     add_submenu_page('cp_admin_manage', 'Buddypress Integration - ' .__('CubePoints','cp'), __('BuddyPress','cp'), 8, 'cubebp-settings', 'cubebp_admin');
  104. }
  105. add_action( 'admin_menu', 'bp_cubepoint_add_admin_menu' );
  106.  
  107. /**
  108.  * bp_cubepoint_setup_nav()
  109.  *
  110.  * Sets up the user profile navigation items for the component. This adds the top level nav
  111.  * item and all the sub level nav items to the navigation array. This is then
  112.  * rendered in the template.
  113.  */
  114. function bp_cubepoint_setup_nav() {
  115.     global $bp,$points_template;
  116.     $cb_bp_sitewidemtitle = get_option('bp_sitewidemtitle_cp_bp');
  117.     $cb_bp_earnpointtitle = get_option('bp_earnpoints_menutitle_cp_bp');
  118.     $cb_bp_awardstitle = get_option('bp_awards_menutitle_cp_bp');
  119.  
  120.     /* Add 'Points' to the main user profile navigation */
  121.     bp_core_new_nav_item( array(
  122.         'name' => __( 'Points', 'bp-cubepoint' ),
  123.         'slug' => $bp->cubepoint->slug,
  124.         'position' => 80,
  125.         'screen_function' => 'bp_cubepoint_screen_points',
  126.         'default_subnav_slug' => $bp->cubepoint->points_slug
  127.     ) );
  128.    
  129.     // Pre-BuddyPress 1.5
  130.     //$cubepoint_link = ($bp->displayed_user->id ? $bp->displayed_user->domain : $bp->loggedin_user->domain) . $bp->cubepoint->slug . '/';
  131.     $cubepoint_link = bp_get_root_domain() . '/' . $bp->cubepoint->slug . '/';
  132.     $cubepoint_link_title = ($bp->displayed_user->id) ? bp_word_or_name( __( "My Points", 'bp-cubepoint' ), __( "%s's points", 'bp-cubepoint' ) ,false,false) : __( "My Points", 'bp-cubepoint' );
  133.    
  134.     bp_core_new_subnav_item( array(
  135.         'name' => $cubepoint_link_title,
  136.         'slug' => $bp->cubepoint->points_slug,
  137.         'parent_slug' => $bp->cubepoint->slug,
  138.         'parent_url' => $cubepoint_link,
  139.         'screen_function' => 'bp_cubepoint_screen_points',
  140.         'position' => 10
  141.     ) );
  142.  
  143.     if(get_option('bp_sitewide_menu_cp_bp')) {
  144.         bp_core_new_subnav_item( array(
  145.             'name' => __( $cb_bp_sitewidemtitle, 'bp-cubepoint' ),
  146.             //'name' => __( 'Sitewide Points', 'bp-cubepoint' ),
  147.             'slug' => $bp->cubepoint->table_slug,
  148.             'parent_slug' => $bp->cubepoint->slug,
  149.             'parent_url' => $cubepoint_link,
  150.             'screen_function' => 'bp_cubepoint_screen_table',
  151.             'position' => 30,
  152.         ) );
  153.     }
  154.    
  155.     if(get_option('bp_earnpoints_menu_cp_bp')) {
  156.         bp_core_new_subnav_item( array(
  157.             'name' => __( $cb_bp_earnpointtitle, 'bp-cubepoint' ),
  158.             'slug' => $bp->cubepoint->earnpoints_slug,
  159.             'parent_slug' => $bp->cubepoint->slug,
  160.             'parent_url' => $cubepoint_link,
  161.             'screen_function' => 'bp_cubepoint_screen_earnpoints',
  162.             'position' => 50,
  163.         ) );
  164.     }
  165.    
  166.     if(get_option('bp_awards_menu_onoff_cp_bp')) {
  167.         bp_core_new_subnav_item( array(
  168.             'name' => __( $cb_bp_awardstitle, 'bp-cubepoint' ),
  169.             'slug' => $bp->cubepoint->awards_slug,
  170.             'parent_slug' => $bp->cubepoint->slug,
  171.             'parent_url' => $cubepoint_link,
  172.             'screen_function' => 'bp_cubepoint_screen_awards',
  173.             'position' => 70,
  174.         ) );
  175.     }
  176.        
  177. }
  178. /***
  179.  * In versions of BuddyPress 1.2.2 and newer you will be able to use:
  180.  * add_action( 'bp_setup_nav', 'bp_cubepoint_setup_nav' );
  181.  */
  182. add_action( 'wp', 'bp_cubepoint_setup_nav', 2 );
  183. add_action( 'admin_menu', 'bp_cubepoint_setup_nav', 2 );
  184.  
  185.  
  186. /**
  187.  * Awards Notify
  188.  *
  189.  *
  190. */
  191. /*
  192. function bp_cp_awards_format_notifications( $action, $item_id, $secondary_item_id, $total_items )
  193. {
  194.     global $bp;
  195.  
  196.     if( 'cp_bp_dive' == $action )
  197.     {
  198.         if ( (int)$total_items > 1 )
  199.             return apply_filters( 'log_multiple_verifications_notification', '<a href="' . $bp->loggedin_user->domain . 'logs/verifications/" title="' . __( 'Verifications', 'logs' ) . '">' . sprintf( __('You have %d new logbook verifications', 'logs' ), (int)$total_items ) . '</a>', $total_items );
  200.         else
  201.             return apply_filters( 'log_single_verification_notification', '<a href="' . $bp->loggedin_user->domain . 'logs/verifications/" title="' . __( 'Verifications', 'logs' ) . '">' . sprintf( __('You have %d new logbook verification', 'logs' ), (int)$total_items ) . '</a>', $total_items );
  202.     }
  203.  
  204.     do_action( 'bp_cp_awards_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
  205.  
  206.     return false;
  207. }
  208.  
  209. function cb_bp_awards_remove_screen_notifications()
  210. {
  211.     global $bp;
  212.  
  213.     bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->cubepoint->name, 'cp_bp_dive' );
  214. }
  215. add_action( 'log_verifications_screen', 'cb_bp_awards_remove_screen_notifications' );
  216. */
  217.  
  218. /**
  219.  * bp_cubepoint_load_template_filter()
  220.  *
  221.  * You can define a custom load template filter for your component. This will allow
  222.  * you to store and load template files from your plugin directory.
  223.  *
  224.  * This will also allow users to override these templates in their active theme and
  225.  * replace the ones that are stored in the plugin directory.
  226.  *
  227.  * If you're not interested in using template files, then you don't need this function.
  228.  *
  229.  * This will become clearer in the function bp_cubepoint_screen_one() when you want to load
  230.  * a template file.
  231.  */
  232. function bp_cubepoint_load_template_filter( $found_template, $templates ) {
  233.     global $bp;
  234.  
  235.     /**
  236.      * Only filter the template location when we're on the example component pages.
  237.      */
  238.     if ( $bp->current_component != $bp->cubepoint->slug )
  239.         return $found_template;
  240.  
  241.     foreach ( (array) $templates as $template ) {
  242.         if ( file_exists( STYLESHEETPATH . '/' . $template ) )
  243.             $filtered_templates[] = STYLESHEETPATH . '/' . $template;
  244.         elseif ( file_exists( TEMPLATEPATH . '/' . $template ) )
  245.             $filtered_templates[] = TEMPLATEPATH . '/' . $template;
  246.         else
  247.             $filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
  248.     }
  249.  
  250.     $found_template = $filtered_templates[0];
  251.  
  252.     return apply_filters( 'bp_cubepoint_load_template_filter', $found_template );
  253. }
  254. add_filter( 'bp_located_template', 'bp_cubepoint_load_template_filter', 10, 2 );
  255.  
  256. function bp_cubepoint_load_subtemplate( $template_name ) {
  257.     if ( file_exists(STYLESHEETPATH . '/' . $template_name . '.php')) {
  258.         $located = STYLESHEETPATH . '/' . $template_name . '.php';
  259.     } else if ( file_exists(TEMPLATEPATH . '/' . $template_name . '.php') ) {
  260.         $located = TEMPLATEPATH . '/' . $template_name . '.php';
  261.     } else{
  262.         $located = dirname( __FILE__ ) . '/templates/' . $template_name . '.php';
  263.     }
  264.     include ($located);
  265. }
  266.  
  267. function bp_cubepoint_get_points($args = ''){
  268.     return BP_CubePoint_Point::query_points($args);
  269. }
  270.  
  271. function bp_cubepoint_get_point_count($args = ''){
  272.     return BP_CubePoint_Point::query_points($args,true);
  273. }
  274.  
  275. function bp_cubepoint_add_point($uid,$type,$timestamp,$points,$source){
  276.     global $bp;
  277.    
  278.     $point = new BP_CubePoint_Point();
  279.     $point->uid = $uid;
  280.     $point->type = $type;
  281.     $point->timestamp = $timestamp;
  282.     $point->points = $points;
  283.     $point->source = $source;
  284.    
  285.     return $point->save() ? $point->id : false;
  286.  
  287. }
  288. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement