Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Define a constant that can be checked to see if the component is installed or not. */
- define ( 'BP_CUBEPOINT_IS_INSTALLED', 1 );
- /* Define a constant that will hold the database version number that can be used for upgrading the DB
- *
- * NOTE: When table defintions change and you need to upgrade,
- * make sure that you increment this constant so that it runs the install function again.
- */
- define ( 'BP_CUBEPOINT_DB_VERSION', '1.9.1' );
- /* Translation support */
- load_textdomain( 'bp-cubepoint', dirname( __FILE__ ) . '/languages/bp-cubepoint-' . get_locale() . '.mo' );
- /**
- * The next step is to include all the files you need for your component.
- * You should remove or comment out any files that you don't need.
- */
- /* The classes file should hold all database access classes and functions */
- require ( dirname( __FILE__ ) . '/bp-cubepoint-classes.php' );
- /* The screens file hold the screens functions */
- require ( dirname( __FILE__ ) . '/bp-cubepoint-screens.php' );
- /* The cssjs file should set up and enqueue all CSS and JS files used by the component */
- require ( dirname( __FILE__ ) . '/bp-cubepoint-cssjs.php' );
- /* The templatetags file should contain classes and functions designed for use in template files */
- require ( dirname( __FILE__ ) . '/bp-cubepoint-templatetags.php' );
- /* The functions file should contain code to add/remove points */
- require ( dirname( __FILE__ ) . '/bp-cubepoint-functions.php' );
- /* The notifications file should contain functions to send email notifications on specific user actions */
- // NEW FOR AWARDS
- //require ( dirname( __FILE__ ) . '/bp-cubepoint-notifications.php' );
- // NEW FOR AWARDS
- /* The filters file should create and apply filters to component output functions. */
- require ( dirname( __FILE__ ) . '/bp-cubepoint-filters.php' );
- /**
- * bp_cubepoint_setup_globals()
- *
- * Sets up global variables for your component.
- */
- function bp_cubepoint_setup_globals() {
- global $bp, $wpdb;
- $bp->cubepoint->id = 'cubepoint';
- //$bp->cubepoint->table_name = $wpdb->base_prefix . 'cubepoints';
- $bp->cubepoint->table_name = $wpdb->prefix . 'cubepoints';
- // custom SLUG
- //$bp->cubepoint->slug = 'cubepoints';
- $bg_cp_custom_slug = get_option( 'bp_slug_cp_bp' );
- $bp->cubepoint->slug = $bg_cp_custom_slug;
- $bp->cubepoint->points_slug = 'points';
- $bp->cubepoint->table_slug = 'table';
- $bp->cubepoint->earnpoints_slug = 'earnpoints';
- $bp->cubepoint->awards_slug = 'awards';
- $bp->cubepoint->bp_cubepoint_per_page = get_option('bp_points_logs_per_page_cp_bp');
- // Notifications
- //$bp->cubepoint->format_notification_function = 'bp_cp_awards_format_notifications';
- /* Register this in the active components array */
- $bp->active_components[$bp->cubepoint->slug] = $bp->cubepoint->id;
- if ( $bp->current_component == $bp->cubepoint->slug && $bp->cubepoint->table_slug != $bp->current_action ){
- bp_cubepoint_query_points();
- }
- if ( $bp->current_component == $bp->cubepoint->slug && $bp->cubepoint->table_slug == $bp->current_action ){
- bp_cubepoint_query_points('uid=');
- }
- }
- /***
- * In versions of BuddyPress 1.2.2 and newer you will be able to use:
- * add_action( 'bp_setup_globals', 'bp_cubepoint_setup_globals' );
- */
- add_action( 'wp', 'bp_cubepoint_setup_globals', 2 );
- add_action( 'admin_menu', 'bp_cubepoint_setup_globals', 2 );
- /**
- * bp_cubepoint_add_admin_menu()
- *
- * This function will add a WordPress wp-admin admin menu for your component under the
- * "BuddyPress" menu.
- */
- function bp_cubepoint_add_admin_menu() {
- global $bp;
- if ( !$bp->loggedin_user->is_site_admin )
- return false;
- require_once('bp-cubepoint-admin.php');
- add_submenu_page('cp_admin_manage', 'Buddypress Integration - ' .__('CubePoints','cp'), __('BuddyPress','cp'), 8, 'cubebp-settings', 'cubebp_admin');
- }
- add_action( 'admin_menu', 'bp_cubepoint_add_admin_menu' );
- /**
- * bp_cubepoint_setup_nav()
- *
- * Sets up the user profile navigation items for the component. This adds the top level nav
- * item and all the sub level nav items to the navigation array. This is then
- * rendered in the template.
- */
- function bp_cubepoint_setup_nav() {
- global $bp,$points_template;
- $cb_bp_sitewidemtitle = get_option('bp_sitewidemtitle_cp_bp');
- $cb_bp_earnpointtitle = get_option('bp_earnpoints_menutitle_cp_bp');
- $cb_bp_awardstitle = get_option('bp_awards_menutitle_cp_bp');
- /* Add 'Points' to the main user profile navigation */
- bp_core_new_nav_item( array(
- 'name' => __( 'Points', 'bp-cubepoint' ),
- 'slug' => $bp->cubepoint->slug,
- 'position' => 80,
- 'screen_function' => 'bp_cubepoint_screen_points',
- 'default_subnav_slug' => $bp->cubepoint->points_slug
- ) );
- // Pre-BuddyPress 1.5
- //$cubepoint_link = ($bp->displayed_user->id ? $bp->displayed_user->domain : $bp->loggedin_user->domain) . $bp->cubepoint->slug . '/';
- $cubepoint_link = bp_get_root_domain() . '/' . $bp->cubepoint->slug . '/';
- $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' );
- bp_core_new_subnav_item( array(
- 'name' => $cubepoint_link_title,
- 'slug' => $bp->cubepoint->points_slug,
- 'parent_slug' => $bp->cubepoint->slug,
- 'parent_url' => $cubepoint_link,
- 'screen_function' => 'bp_cubepoint_screen_points',
- 'position' => 10
- ) );
- if(get_option('bp_sitewide_menu_cp_bp')) {
- bp_core_new_subnav_item( array(
- 'name' => __( $cb_bp_sitewidemtitle, 'bp-cubepoint' ),
- //'name' => __( 'Sitewide Points', 'bp-cubepoint' ),
- 'slug' => $bp->cubepoint->table_slug,
- 'parent_slug' => $bp->cubepoint->slug,
- 'parent_url' => $cubepoint_link,
- 'screen_function' => 'bp_cubepoint_screen_table',
- 'position' => 30,
- ) );
- }
- if(get_option('bp_earnpoints_menu_cp_bp')) {
- bp_core_new_subnav_item( array(
- 'name' => __( $cb_bp_earnpointtitle, 'bp-cubepoint' ),
- 'slug' => $bp->cubepoint->earnpoints_slug,
- 'parent_slug' => $bp->cubepoint->slug,
- 'parent_url' => $cubepoint_link,
- 'screen_function' => 'bp_cubepoint_screen_earnpoints',
- 'position' => 50,
- ) );
- }
- if(get_option('bp_awards_menu_onoff_cp_bp')) {
- bp_core_new_subnav_item( array(
- 'name' => __( $cb_bp_awardstitle, 'bp-cubepoint' ),
- 'slug' => $bp->cubepoint->awards_slug,
- 'parent_slug' => $bp->cubepoint->slug,
- 'parent_url' => $cubepoint_link,
- 'screen_function' => 'bp_cubepoint_screen_awards',
- 'position' => 70,
- ) );
- }
- }
- /***
- * In versions of BuddyPress 1.2.2 and newer you will be able to use:
- * add_action( 'bp_setup_nav', 'bp_cubepoint_setup_nav' );
- */
- add_action( 'wp', 'bp_cubepoint_setup_nav', 2 );
- add_action( 'admin_menu', 'bp_cubepoint_setup_nav', 2 );
- /**
- * Awards Notify
- *
- *
- */
- /*
- function bp_cp_awards_format_notifications( $action, $item_id, $secondary_item_id, $total_items )
- {
- global $bp;
- if( 'cp_bp_dive' == $action )
- {
- if ( (int)$total_items > 1 )
- 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 );
- else
- 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 );
- }
- do_action( 'bp_cp_awards_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
- return false;
- }
- function cb_bp_awards_remove_screen_notifications()
- {
- global $bp;
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->cubepoint->name, 'cp_bp_dive' );
- }
- add_action( 'log_verifications_screen', 'cb_bp_awards_remove_screen_notifications' );
- */
- /**
- * bp_cubepoint_load_template_filter()
- *
- * You can define a custom load template filter for your component. This will allow
- * you to store and load template files from your plugin directory.
- *
- * This will also allow users to override these templates in their active theme and
- * replace the ones that are stored in the plugin directory.
- *
- * If you're not interested in using template files, then you don't need this function.
- *
- * This will become clearer in the function bp_cubepoint_screen_one() when you want to load
- * a template file.
- */
- function bp_cubepoint_load_template_filter( $found_template, $templates ) {
- global $bp;
- /**
- * Only filter the template location when we're on the example component pages.
- */
- if ( $bp->current_component != $bp->cubepoint->slug )
- return $found_template;
- foreach ( (array) $templates as $template ) {
- if ( file_exists( STYLESHEETPATH . '/' . $template ) )
- $filtered_templates[] = STYLESHEETPATH . '/' . $template;
- elseif ( file_exists( TEMPLATEPATH . '/' . $template ) )
- $filtered_templates[] = TEMPLATEPATH . '/' . $template;
- else
- $filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
- }
- $found_template = $filtered_templates[0];
- return apply_filters( 'bp_cubepoint_load_template_filter', $found_template );
- }
- add_filter( 'bp_located_template', 'bp_cubepoint_load_template_filter', 10, 2 );
- function bp_cubepoint_load_subtemplate( $template_name ) {
- if ( file_exists(STYLESHEETPATH . '/' . $template_name . '.php')) {
- $located = STYLESHEETPATH . '/' . $template_name . '.php';
- } else if ( file_exists(TEMPLATEPATH . '/' . $template_name . '.php') ) {
- $located = TEMPLATEPATH . '/' . $template_name . '.php';
- } else{
- $located = dirname( __FILE__ ) . '/templates/' . $template_name . '.php';
- }
- include ($located);
- }
- function bp_cubepoint_get_points($args = ''){
- return BP_CubePoint_Point::query_points($args);
- }
- function bp_cubepoint_get_point_count($args = ''){
- return BP_CubePoint_Point::query_points($args,true);
- }
- function bp_cubepoint_add_point($uid,$type,$timestamp,$points,$source){
- global $bp;
- $point = new BP_CubePoint_Point();
- $point->uid = $uid;
- $point->type = $type;
- $point->timestamp = $timestamp;
- $point->points = $points;
- $point->source = $source;
- return $point->save() ? $point->id : false;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement