diff --git a/change_log.txt b/change_log.txt index 18734a7..2559a10 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,8 @@ v1.0.7 Send compliment button can be displayed in /members page - ADDED PHP undefined notices in wordpress admin - FIXED +Compliment not displaying content in activity page - FIXED +Filter added to prevent duplicate compliments - ADDED v1.0.6 Notification incorrect from email - FIXED diff --git a/css/bp-compliments.css b/css/bp-compliments.css index 200bad3..ca15e0e 100644 --- a/css/bp-compliments.css +++ b/css/bp-compliments.css @@ -171,7 +171,7 @@ .bp-compliments-wrap .pagination span { display: inline-block; } -.bp-loading-icon { +.bp-comp-loading-icon { background-image: url("../images/loading.gif"); width: 32px; height: 32px; diff --git a/includes/bp-compliments-actions.php b/includes/bp-compliments-actions.php index f2dd165..5bfe806 100644 --- a/includes/bp-compliments-actions.php +++ b/includes/bp-compliments-actions.php @@ -47,10 +47,26 @@ function handle_compliments_form_data() { $redirect_url = bp_core_get_user_domain($receiver_id); - if ( ! bp_compliments_start_compliment($args)) { - bp_core_add_message( sprintf( __( 'There was a problem when trying to send %s to %s, please contact administrator.', 'bp-compliments' ), strtolower(BP_COMP_SINGULAR_NAME), $receiver_name ), 'error' ); + //check duplicate + $check_duplicate = apply_filters('bp_comp_check_duplicate', false); + + if ($check_duplicate) { + $count = bp_comp_check_duplicate_comp($args); + if ($count != 0) { + bp_core_add_message( __( 'Duplicate compliment detected.', 'bp-compliments' ), 'error' ); + } else { + if ( ! bp_compliments_start_compliment($args)) { + bp_core_add_message( sprintf( __( 'There was a problem when trying to send %s to %s, please contact administrator.', 'bp-compliments' ), strtolower(BP_COMP_SINGULAR_NAME), $receiver_name ), 'error' ); + } else { + bp_core_add_message( sprintf( __( 'Your %s sent to %s.', 'bp-compliments' ), BP_COMP_SINGULAR_NAME, $receiver_name ) ); + } + } } else { - bp_core_add_message( sprintf( __( 'Your %s sent to %s.', 'bp-compliments' ), BP_COMP_SINGULAR_NAME, $receiver_name ) ); + if ( ! bp_compliments_start_compliment($args)) { + bp_core_add_message( sprintf( __( 'There was a problem when trying to send %s to %s, please contact administrator.', 'bp-compliments' ), strtolower(BP_COMP_SINGULAR_NAME), $receiver_name ), 'error' ); + } else { + bp_core_add_message( sprintf( __( 'Your %s sent to %s.', 'bp-compliments' ), BP_COMP_SINGULAR_NAME, $receiver_name ) ); + } } $bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp')); @@ -153,3 +169,23 @@ function delete_single_complement() { } add_action( 'bp_actions', 'delete_single_complement'); +function bp_comp_check_duplicate_comp($args) { + + global $wpdb; + + $r = wp_parse_args( $args, array( + 'receiver_id' => bp_displayed_user_id(), + 'sender_id' => bp_loggedin_user_id(), + 'term_id' => 0, + 'post_id' => 0, + 'message' => null + ) ); + + $term_id = (int) $r['term_id']; + $sender_id = (int) $r['sender_id']; + $receiver_id = (int) $r['receiver_id']; + + $count = $wpdb->get_var($wpdb->prepare("select COUNT(id) from " . BP_COMPLIMENTS_TABLE . " where term_id= %d AND sender_id= %d AND receiver_id= %d", array($term_id, $sender_id, $receiver_id))); + return $count; +} + diff --git a/includes/bp-compliments-activity.php b/includes/bp-compliments-activity.php index 2c06a51..2a49e1a 100644 --- a/includes/bp-compliments-activity.php +++ b/includes/bp-compliments-activity.php @@ -176,7 +176,6 @@ function compliments_format_activity_action_compliment_received( $action, $activ $action = sprintf( __( '%1$s has received a %2$s from %3$s', 'bp-compliments' ), $receiver_link, strtolower(BP_COMP_SINGULAR_NAME), $sender_link ); } - /** * Filters the 'compliment_received' activity action format. * @@ -314,4 +313,36 @@ function compliments_merge_filter( $filters, $context ){ } return $filters; } -add_filter('bp_get_activity_show_filters_options', 'compliments_merge_filter', 10, 2); \ No newline at end of file +add_filter('bp_get_activity_show_filters_options', 'compliments_merge_filter', 10, 2); + +add_filter('compliments_format_activity_action_compliment_received', 'bp_comp_add_compliment_received_content', 10, 2); +function bp_comp_add_compliment_received_content($action, $activity) { + + $display_comp_content = apply_filters('bp_comp_display_comp_content_in_activity', false); + if (!$display_comp_content) { + return $action; + } + + global $wpdb; + $comp = $wpdb->get_row($wpdb->prepare("select * from " . BP_COMPLIMENTS_TABLE . " where id= %d", array($activity->item_id))); + $t_id = $comp->term_id; + $term = get_term_by('id', $t_id, 'compliment'); + $term_meta = get_option("taxonomy_$t_id"); + $compliments_icon = esc_attr($term_meta['compliments_icon']) ? esc_attr($term_meta['compliments_icon']) : ''; + if (is_ssl()) { + $compliments_icon = str_replace('http://', 'https://', $compliments_icon); + } + $image = "