Skip to content

Commit

Permalink
Merge pull request #8 from GeoDirectory/master
Browse files Browse the repository at this point in the history
Merge from master
  • Loading branch information
kprajapatii committed Nov 30, 2015
2 parents 8cf4b46 + 092e2f0 commit 3b85733
Show file tree
Hide file tree
Showing 10 changed files with 528 additions and 9 deletions.
6 changes: 6 additions & 0 deletions bp-compliments-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public function setup_nav( $main_nav = array(), $sub_nav = array() ) {

$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';

if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta(bp_displayed_user_id(), 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if ($bp_compliment_can_see_others_comp == 'yes') {
$show_for_displayed_user = true;
} elseif ($bp_compliment_can_see_others_comp == 'members_only') {
Expand Down
10 changes: 10 additions & 0 deletions bp-compliments.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,13 @@ function bp_compliments_localization() {
}
add_action( 'plugins_loaded', 'bp_compliments_localization' );

add_action( 'admin_notices', 'bp_compliments_required_plugins_nag' );
function bp_compliments_required_plugins_nag() {
// Check for BuddyPress
$class = "update-nag";
$url = 'https://wordpress.org/plugins/buddypress/';
$message = sprintf( wp_kses( __( 'BuddyPress Compliments requires <a target="_blank" href="%s">BuddyPress</a> plugin.', 'bp-compliments' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
if(!class_exists('BuddyPress')){
echo"<div class=\"$class\"> <p>$message</p></div>";
}
}
4 changes: 4 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.0.2
Category support added for compliments - ADDED
Compliment user settings page - ADDED

v1.0.1
Use singular name instead of slug name - FIXED
Admin can delete compliments - ADDED
Expand Down
50 changes: 49 additions & 1 deletion css/bp-compliments.css
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,52 @@
width: 32px;
height: 32px;
margin: 0 auto;
}
}

.comp-modal-category {
border-bottom: 1px solid #ddd;
list-style-type: none;
font-size: 14px;
}

.comp-modal-category > li {
float: left;
margin-bottom: -1px;
}

.comp-modal-category > li > a {
position: relative;
display: block;
padding: 10px 15px;
margin-right: 2px;
line-height: 1.42857143;
border: 1px solid transparent;
border-radius: 4px 4px 0 0;
}

.comp-modal-category > li > a:hover {
border-color: #eee #eee #ddd;
}

.comp-modal-category > li.selected > a,
.comp-modal-category > li.selected > a:hover,
.comp-modal-category > li.selected > a:focus {
color: #555;
cursor: default;
background-color: #fff;
border: 1px solid #ddd;
border-bottom-color: transparent;
opacity: 1;
font-weight: normal;
}

.comp-modal-category:before,
.comp-modal-category:after {
display: table;
content: "";
line-height: 0;
}

.comp-modal-category:after {
clear: both;
}
8 changes: 7 additions & 1 deletion includes/bp-compliments-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ function handle_compliments_form_data() {

$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';
if ($bp_compliment_can_see_others_comp == 'yes') {

if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta(bp_displayed_user_id(), 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if ($bp_compliment_can_see_others_comp == 'yes') {
$show_for_displayed_user = true;
} elseif ($bp_compliment_can_see_others_comp == 'members_only') {
if (is_user_logged_in()) {
Expand Down
10 changes: 10 additions & 0 deletions includes/bp-compliments-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ function compliments_format_activity_action_compliment_received( $action, $activ
$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';

if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($bp->displayed_user->id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if (bp_is_user() && ($bp->loggedin_user->id == $bp->displayed_user->id)) {
$bp_compliment_can_see_others_comp = 'yes';
}
Expand Down Expand Up @@ -200,6 +205,11 @@ function compliments_format_activity_action_compliment_sent( $action, $activity
$bp_compliment_can_see_others_comp_value = esc_attr( get_option('bp_compliment_can_see_others_comp'));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_others_comp_value ? $bp_compliment_can_see_others_comp_value : 'yes';

if ($bp_compliment_can_see_others_comp == 'members_choice') {
$bp_compliment_can_see_your_comp_value = esc_attr( get_user_meta($bp->displayed_user->id, 'bp_compliment_can_see_your_comp', true));
$bp_compliment_can_see_others_comp = $bp_compliment_can_see_your_comp_value ? $bp_compliment_can_see_your_comp_value : 'yes';
}

if (bp_is_user() && ($bp->loggedin_user->id == $bp->displayed_user->id)) {
$bp_compliment_can_see_others_comp = 'yes';
}
Expand Down
79 changes: 75 additions & 4 deletions includes/bp-compliments-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
*
* @param int $pid The post ID.
* @param int $receiver_id Compliment receiver ID.
* @param int $category_id Compliment category ID.
*/
function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
function bp_compliments_modal_form($pid = 0, $receiver_id = 0, $category_id = 0) {
if (!$receiver_id && bp_displayed_user_id()) {
$receiver_id = bp_displayed_user_id();
}
Expand All @@ -26,12 +27,56 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
<h2><?php echo sprintf( __( 'Choose Your %s Type:', 'bp-compliments' ), BP_COMP_SINGULAR_NAME ); ?></h2>
</div>
<div class="comp-modal-content">
<form action="" method="post">
<?php
$bp_compliment_enable_categories_value = esc_attr( get_option('bp_compliment_enable_categories'));
$bp_compliment_enable_categories = $bp_compliment_enable_categories_value ? $bp_compliment_enable_categories_value : 'no';

if ($bp_compliment_enable_categories == 'yes') {
$cat_args = array(
'orderby' => 'name',
'hide_empty' => 0,
);
$cat_terms = get_terms('compliment_category', $cat_args);
$output = "<ul class='comp-modal-category'>";
$count = 0;
foreach ($cat_terms as $cat_term) {
$count++;
$cat_term_id = $cat_term->term_id;
$cat_term_meta = get_option("taxonomy_$cat_term_id");
if ($cat_term_meta) {
$cat_term_name = $cat_term->name;
if ($count == 1 && !$category_id) {
$output .= "<li class='selected'>";
$category_id = $cat_term_id;
} elseif ($cat_term_id == $category_id) {
$output .= "<li class='selected'>";
} else {
$output .= "<li>";
}
$output .= "<a href='#' class='comp-modal-category-cat' data-catid='" . $cat_term_id . "'>" . $cat_term_name . "</a>";
$output .= "</li>";
}
}
$output .= "</ul>";
echo $output;
}
?>
<form action="" method="post">
<?php
$args = array(
'hide_empty' => false,
'orderby' => 'id'
);
if ($category_id) {
$cat_meta = get_option("taxonomy_$category_id");
if ($cat_meta) {
$cat_ids = array();
foreach ($cat_meta as $id) {
$cat_ids[] = (int) $id;
}
$args['include'] = $cat_ids;
}
}
$terms = get_terms( 'compliment', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul class="comp-form-ul">';
Expand All @@ -53,7 +98,7 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
<?php
}
echo '</ul>';

$ajax_nonce = wp_create_nonce("bp-compliments-nonce");
?>
<textarea placeholder="<?php echo __( 'Type your message here', 'bp-compliments' ); ?>" name="message" maxchar="1000"></textarea>
<input type="hidden" name="post_id" value="<?php echo $pid; ?>"/>
Expand All @@ -73,9 +118,28 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
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>");
mod_shadow.hide();
});
jQuery('a.comp-modal-category-cat').click(function (e) {
e.preventDefault();
var mod_shadow = jQuery('#bp_compliments_modal_shadow');
var container = jQuery('.comp-modal');
container.html("<div class='comp-modal-content-wrap'><div class='comp-modal-title comp-loading-icon'><div class='bp-loading-icon'></div></div></div>");
var category_id = jQuery(this).data('catid');
mod_shadow.show();
var data = {
'action': 'bp_compliments_modal_ajax',
'bp_compliments_nonce': '<?php echo $ajax_nonce; ?>',
'category_id': category_id
};

jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function (response) {
container.replaceWith(response);
});
});
});
</script>
<?php
} else {
echo __( 'No compliments found.', 'bp-compliments' );
}
?>
</form>
Expand All @@ -94,7 +158,14 @@ function bp_compliments_modal_form($pid = 0, $receiver_id = 0) {
function bp_compliments_modal_ajax()
{
check_ajax_referer('bp-compliments-nonce', 'bp_compliments_nonce');
bp_compliments_modal_form();

if (isset($_POST['category_id'])) {
$category_id = (int) strip_tags(esc_sql($_POST['category_id']));
bp_compliments_modal_form(0, 0, $category_id);
} else {
bp_compliments_modal_form();
}

wp_die();
}

Expand Down
Loading

0 comments on commit 3b85733

Please sign in to comment.