Skip to content

Commit

Permalink
Filter added to prevent duplicate compliments
Browse files Browse the repository at this point in the history
  • Loading branch information
viruthagiri committed Nov 22, 2016
1 parent 8bfe009 commit 40d1938
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 14 deletions.
2 changes: 2 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion css/bp-compliments.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 39 additions & 3 deletions includes/bp-compliments-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
}

35 changes: 33 additions & 2 deletions includes/bp-compliments-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
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 = "<div class=\"comp-user-header\">";
$image .= '<img style="height: 20px; width: 20px; vertical-align:middle"
src="'.$compliments_icon.'"
/>';
$image .= $term->name;
$image .= '</div>';
$image .= '<br/>';

$message = '<div class="comp-user-message">';
$message .= $comp->message;
$message .= '</div>';
$activity->content = $message;
return $action;
}
4 changes: 2 additions & 2 deletions includes/bp-compliments-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0 ) {
var mod_shadow = jQuery('#bp_compliments_modal_shadow');
var container = jQuery('.comp-modal');
container.hide();
container.replaceWith("<div class='comp-modal' style='display: none;'><div class='comp-modal-content-wrap'><div class='comp-modal-title comp-loading-icon'><div class='bp-loading-icon'></div></div></div></div>");
container.replaceWith("<div class='comp-modal' style='display: none;'><div class='comp-modal-content-wrap'><div class='comp-modal-title comp-loading-icon'><div class='bp-comp-loading-icon'></div></div></div></div>");
mod_shadow.hide();
});
});
Expand Down Expand Up @@ -137,7 +137,7 @@ function bp_compliments_modal_init() {
<div class="comp-modal" style="display: none;">
<div class="comp-modal-content-wrap">
<div class="comp-modal-title comp-loading-icon">
<div class="bp-loading-icon"></div>
<div class="bp-comp-loading-icon"></div>
</div>
</div>
</div>
Expand Down
18 changes: 12 additions & 6 deletions includes/templates/buddypress/members/single/compliments.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@
?>
<li>
<div class="comp-user-header">
<span>
<img style="height: 20px; width: 20px; vertical-align:middle"
src='<?php echo esc_attr($term_meta['compliments_icon']) ? esc_attr($term_meta['compliments_icon']) : ''; ?>'
class='preview-upload'/>
<?php echo $term->name; ?>
</span>
<span>
<?php
$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);
}
?>
<img style="height: 20px; width: 20px; vertical-align:middle"
src='<?php echo $compliments_icon; ?>'
class='preview-upload'/>
<?php echo $term->name; ?>
</span>
<em>
<?php echo date_i18n(get_option('date_format'), strtotime($comp->created_at)); ?>
</em>
Expand Down

0 comments on commit 40d1938

Please sign in to comment.