Skip to content

Commit

Permalink
bitbucket changes ported
Browse files Browse the repository at this point in the history
  • Loading branch information
NomadDevs committed Jun 23, 2015
1 parent 735e8a9 commit 6537eaf
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 67 deletions.
3 changes: 3 additions & 0 deletions bp-compliments-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function includes( $includes = array() ) {
require( $this->path . '/bp-compliments-screens.php' );
require( $this->path . '/bp-compliments-templatetags.php' );
require( $this->path . '/bp-compliments-actions.php' );
require( $this->path . '/bp-compliments-notifications.php' );
require( $this->path . '/bp-compliments-forms.php' );
}

Expand All @@ -56,6 +57,7 @@ public function setup_globals( $args = array() ) {

// Set up the $globals array
$globals = array(
'notification_callback' => 'bp_compliments_format_notifications',
'global_tables' => array(
'table_name' => BP_COMPLIMENTS_TABLE,
)
Expand Down Expand Up @@ -101,6 +103,7 @@ public function setup_hooks() {
public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
global $bp;

do_action( 'bp_compliments_before_setup_nav' );
// Need to change the user ID, so if we're not on a member page, $counts variable is still calculated
$user_id = bp_is_user() ? bp_displayed_user_id() : bp_loggedin_user_id();
$counts = bp_compliments_total_counts( array( 'user_id' => $user_id ) );
Expand Down
24 changes: 23 additions & 1 deletion bp-compliments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: BuddyPress Compliments
Plugin URI: http://wpgeodirectory.com/
Description: Compliments module for BuddyPress.
Version: 0.0.1
Version: 0.1
Author: GeoDirectory
Author URI: http://wpgeodirectory.com
*/
Expand Down Expand Up @@ -69,3 +69,25 @@ function bp_compliments_activate() {
}
register_activation_hook( __FILE__, 'bp_compliments_activate' );

/**
* Custom text domain loader.
*
* Checks WP_LANG_DIR for the .mo file first, then the plugin's language folder.
* Allows for a custom language file other than those packaged with the plugin.
*
* @uses load_textdomain() Loads a .mo file into WP
*/
function bp_compliments_localization() {
$mo_file = sprintf( 'bp-compliments-%s.mo', get_locale() );
$mo_file_global = trailingslashit( WP_LANG_DIR ) . $mo_file;
$mo_file_local = plugin_dir_path( __FILE__ ) . 'languages/' . $mo_file;

if ( is_readable( $mo_file_global ) )
return load_textdomain( 'bp-compliments', $mo_file_global );
elseif ( is_readable( $mo_file_local ) )
return load_textdomain( 'bp-compliments', $mo_file_local );
else
return false;
}
add_action( 'plugins_loaded', 'bp_compliments_localization' );

6 changes: 6 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
v0.0.2
BP compliments now supports notification component - ADDED
Send compliment modal form z-index bug - FIXED
Compliment Icon upload form uses latest media uploader - CHANGED


2 changes: 1 addition & 1 deletion includes/bp-compliments-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function handle_compliments_form_data() {
}

if ( ! bp_compliments_start_compliment($args)) {
bp_core_add_message( sprintf( __( 'There was a problem when trying to send compliment to %s, please contact administrator.', 'bp-follow' ), bp_get_displayed_user_fullname() ), 'error' );
bp_core_add_message( sprintf( __( 'There was a problem when trying to send compliment to %s, please contact administrator.', BP_COMP_TEXTDOMAIN ), bp_get_displayed_user_fullname() ), 'error' );
} else {
bp_core_add_message( sprintf( __( 'Your compliment sent to %s.', BP_COMP_TEXTDOMAIN ), bp_get_displayed_user_fullname() ) );
}
Expand Down
13 changes: 6 additions & 7 deletions includes/bp-compliments-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ function bp_compliments_modal_ajax()
wp_die();
}

function bp_compliments_modal_shadow(){ ?>
<div id="bp_compliments_modal_shadow" style="display: none;"></div>
<?php }
add_action('wp_footer', 'bp_compliments_modal_shadow');

//Ajax functions
add_action('wp_ajax_bp_compliments_modal_ajax', 'bp_compliments_modal_ajax');

//Javascript
add_action('bp_after_member_home_content', 'bp_compliments_js');
function bp_compliments_js() {
add_action('wp_footer', 'bp_compliments_modal_init');
function bp_compliments_modal_init() {
if (!bp_is_user() || !is_user_logged_in()){
return;
}
$ajax_nonce = wp_create_nonce("bp-compliments-nonce");
?>
<div id="bp_compliments_modal_shadow" style="display: none;"></div>
<div class="comp-modal" style="display: none;">
<div class="comp-modal-content-wrap">
<div class="comp-modal-title comp-loading-icon">
Expand Down
200 changes: 200 additions & 0 deletions includes/bp-compliments-notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php

// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

function bp_compliments_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
global $bp;

do_action( 'bp_compliments_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $format );

switch ( $action ) {
case 'new_compliment':
$link = false;
$text = false;

if ( 1 == $total_items ) {
$text = sprintf( __( '%s has sent you a compliment', BP_COMP_TEXTDOMAIN ), bp_core_get_user_displayname( $item_id ) );
$link = bp_core_get_user_domain( $bp->displayed_user->id ) .BP_COMPLIMENTS_SLUG. '/?bpc_read=true&bpc_sender_id='.$item_id;
}
break;

default :
$link = apply_filters( 'bp_compliments_extend_notification_link', false, $action, $item_id, $secondary_item_id, $total_items );
$text = apply_filters( 'bp_compliments_extend_notification_text', false, $action, $item_id, $secondary_item_id, $total_items );
break;
}

if ( ! $link || ! $text ) {
return false;
}

if ( 'string' == $format ) {
return apply_filters( 'bp_compliments_new_compliment_notification', '<a href="' . $link . '">' . $text . '</a>', $total_items, $link, $text, $item_id, $secondary_item_id );
} else {
return false;
}
}

function bp_compliments_notifications_add_on_compliment( BP_Compliments $compliment ) {
// Add a screen notification
// BP 1.9+
if ( bp_is_active( 'notifications' ) ) {
bp_notifications_add_notification( array(
'item_id' => $compliment->sender_id,
'user_id' => $compliment->receiver_id,
'component_name' => buddypress()->compliments->id,
'component_action' => 'new_compliment'
) );

// BP < 1.9 - add notifications the old way
} elseif ( ! class_exists( 'BP_Core_Login_Widget' ) ) {
global $bp;

bp_core_add_notification(
$compliment->sender_id,
$compliment->receiver_id,
$bp->compliments->id,
'new_compliment'
);
}

// Add an email notification
bp_compliments_new_compliment_email_notification( array(
'receiver_id' => $compliment->receiver_id,
'sender_id' => $compliment->sender_id
) );
}
add_action( 'bp_compliments_start_compliment', 'bp_compliments_notifications_add_on_compliment' );

function bp_compliments_new_compliment_email_notification() {
$args = '';

$defaults = array(
'receiver_id' => bp_displayed_user_id(),
'sender_id' => bp_loggedin_user_id()
);

$r = wp_parse_args( $args, $defaults );

if ( 'no' == bp_get_user_meta( (int) $r['receiver_id'], 'notification_on_compliments', true ) )
return false;

// Check to see if this receiver has already been notified of this sender before
$has_notified = bp_get_user_meta( $r['sender_id'], 'bp_compliments_has_notified', true );

// Already notified so don't send another email
if ( in_array( $r['receiver_id'], (array) $has_notified ) )
return false;

// Not been notified before, update usermeta and continue to mail
$has_notified[] = $r['receiver_id'];
bp_update_user_meta( $r['sender_id'], 'bp_compliments_has_notified', $has_notified );

$sender_name = bp_core_get_user_displayname( $r['sender_id'] );
$compliment_link = bp_core_get_user_domain( $r['receiver_id'] ) .BP_COMPLIMENTS_SLUG. '/?bpc_read=true&bpc_sender_id='.$r['sender_id'];

$receiver_ud = bp_core_get_core_userdata( $r['receiver_id'] );

// Set up and send the message
$to = $receiver_ud->user_email;

$subject = '[' . wp_specialchars_decode( bp_get_option( 'blogname' ), ENT_QUOTES ) . '] ' . sprintf( __( '%s has sent you a compliment', BP_COMP_TEXTDOMAIN ), $sender_name );

$message = sprintf( __(
'%s has sent you a compliment.
To view %s\'s compliment: %s', BP_COMP_TEXTDOMAIN ), $sender_name, $sender_name, $compliment_link );

// Add notifications link if settings component is enabled
if ( bp_is_active( 'settings' ) ) {
$settings_link = bp_core_get_user_domain( $r['receiver_id'] ) . BP_SETTINGS_SLUG . '/notifications/';
$message .= sprintf( __( '
---------------------
To disable these notifications please log in and go to:
%s', BP_COMP_TEXTDOMAIN ), $settings_link );
}

// Send the message
$to = apply_filters( 'bp_compliments_notification_to', $to );
$subject = apply_filters( 'bp_compliments_notification_subject', $subject, $sender_name );
$message = apply_filters( 'bp_compliments_notification_message', $message, $sender_name, $compliment_link );
wp_mail( $to, $subject, $message );
}

function bp_compliments_notifications_remove_queryarg_from_userlink( $retval ) {
if ( bp_is_current_action( 'read' ) ) {
// if notifications loop has finished rendering, stop now!
if ( did_action( 'bp_after_member_body' ) ) {
return $retval;
}

$retval = str_replace( '?bpc_read', '', $retval );
}

return $retval;
}
add_filter( 'bp_compliments_new_compliment_notification', 'bp_compliments_notifications_remove_queryarg_from_userlink' );

function bp_compliments_screen_notification_settings() {
if ( !$notify = bp_get_user_meta( bp_displayed_user_id(), 'notification_on_compliments', true ) )
$notify = 'yes';
?>

<table class="notification-settings" id="compliments-notification-settings">
<thead>
<tr>
<th class="icon"></th>
<th class="title"><?php _e( 'Compliments', BP_COMP_TEXTDOMAIN ) ?></th>
<th class="yes"><?php _e( 'Yes', BP_COMP_TEXTDOMAIN ) ?></th>
<th class="no"><?php _e( 'No', BP_COMP_TEXTDOMAIN )?></th>
</tr>
</thead>

<tbody>
<tr>
<td></td>
<td><?php _e( 'A member sends you a compliment', BP_COMP_TEXTDOMAIN ) ?></td>
<td class="yes"><input type="radio" name="notifications[notification_on_compliments]" value="yes" <?php checked( $notify, 'yes', true ) ?>/></td>
<td class="no"><input type="radio" name="notifications[notification_on_compliments]" value="no" <?php checked( $notify, 'no', true ) ?>/></td>
</tr>
</tbody>

<?php do_action( 'bp_compliments_screen_notification_settings' ); ?>
</table>
<?php
}
add_action( 'bp_notification_settings', 'bp_compliments_screen_notification_settings' );

function bp_compliments_notifications_mark_compliments_as_read() {
if (!bp_is_user() || !is_user_logged_in()){
return;
}

if ( ! isset( $_GET['bpc_read'] ) || ! isset( $_GET['bpc_sender_id'] ) ) {
return;
}

$sender_id = (int) strip_tags(esc_sql($_GET['bpc_sender_id']));

if (!is_int($sender_id)) {
return;
}


// mark notification as read
if ( bp_is_active( 'notifications' ) ) {
bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $sender_id, buddypress()->compliments->id, 'new_compliment' );

// check if we're not on BP 1.9
// if so, delete notification since marked functionality doesn't exist
} elseif ( ! class_exists( 'BP_Core_Login_Widget' ) ) {
global $bp;

bp_core_delete_notifications_by_item_id( bp_loggedin_user_id(), $sender_id, buddypress()->compliments->id, 'new_compliment' );
}
// Redirect
bp_core_redirect( bp_displayed_user_domain() . BP_COMPLIMENTS_SLUG . '/' );
}
add_action( 'bp_actions', 'bp_compliments_notifications_mark_compliments_as_read' );
33 changes: 17 additions & 16 deletions includes/bp-compliments-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ function create_compliment_taxonomies() {
//compliment icons
add_action( 'admin_enqueue_scripts', 'compliments_enqueue_color_picker' );
function compliments_enqueue_color_picker( $hook_suffix ) {
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
wp_enqueue_script('media-upload');
wp_enqueue_script( 'littlemisscat-colorpicker', constant( 'BP_COMPLIMENTS_URL' ) . '/js/admin.js', array(), false, true );
wp_enqueue_media();
wp_enqueue_script( 'compliments-adminjs', constant( 'BP_COMPLIMENTS_URL' ) . '/js/admin.js', array(), false, true );
}
function compliments_taxonomy_add_new_meta_field() {
?>
<div class="form-field">
<div class="form-field form-required">
<span class='caticon-upload upload'>
<label for="term_meta[compliments_icon]"><?php _e( 'Compliment Icon', 'compliments' ); ?></label>
<input type='text' id='compliments_icon' class='regular-text text-upload compliments-icon-field' name='term_meta[compliments_icon]' value=''/>
<input type='button' class='button button-upload' value='Upload Icon'/></br>
<p>Recommended icon size: 20px x 20px</p>
<!-- <img style='max-width: 300px; display:block' src='' class='preview-upload'/>-->
<label for="term_meta[compliments_icon]"><?php _e( 'Compliment Icon', 'compliments' ); ?></label>
<img id="comp-icon-preview" class="image_preview" src="" style="display: none;" /><br/>
<input id="comp-icon-upload" type="button" data-uploader_title="<?php echo __( 'Upload Icon' , BP_COMP_TEXTDOMAIN ); ?>" data-uploader_button_text="<?php echo __( 'Use Icon' , BP_COMP_TEXTDOMAIN ); ?>" class="image_upload_button button" value="<?php echo __( 'Upload new Icon' , BP_COMP_TEXTDOMAIN ); ?>" />
<input id="comp-icon-delete" type="button" class="image_delete_button button" value="<?php echo __( 'Remove Icon' , BP_COMP_TEXTDOMAIN ); ?>" />
<input id="comp-icon-value" class="image_data_field" type="hidden" name="term_meta[compliments_icon]" value=""/><br/>
<p><?php echo __( 'Recommended icon size: 20px x 20px' , BP_COMP_TEXTDOMAIN ); ?></p>
</span>
</div>
<?php
Expand All @@ -61,14 +60,16 @@ function compliments_taxonomy_add_new_meta_field() {
function compliments_taxonomy_edit_meta_field($term) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<tr class="form-field">
<tr class="form-field form-required">
<th scope="row" valign="top"><label for="term_meta[compliments_icon]"><?php _e( 'Compliment Icon', 'compliments' ); ?></label></th>
<td>
<span class='caticon-upload upload'>
<input type='text' id='compliments_icon' class='regular-text text-upload compliments-icon-field' name='term_meta[compliments_icon]' value='<?php echo esc_attr( $term_meta['compliments_icon'] ) ? esc_attr( $term_meta['compliments_icon'] ) : ''; ?>'/>
<input type='button' class='button button-upload' value='Upload Icon'/></br>
<img style='max-width: 300px; display:block' src='<?php echo esc_attr( $term_meta['compliments_icon'] ) ? esc_attr( $term_meta['compliments_icon'] ) : ''; ?>' class='preview-upload'/>
</span>
<span class='caticon-upload upload'>
<img id="comp-icon-preview" class="image_preview" src="<?php echo esc_attr( $term_meta['compliments_icon'] ) ? esc_attr( $term_meta['compliments_icon'] ) : ''; ?>" /><br/>
<input id="comp-icon-upload" type="button" data-uploader_title="<?php echo __( 'Upload Icon' , BP_COMP_TEXTDOMAIN ); ?>" data-uploader_button_text="<?php echo __( 'Use Icon' , BP_COMP_TEXTDOMAIN ); ?>" class="image_upload_button button" value="<?php echo __( 'Upload new Icon' , BP_COMP_TEXTDOMAIN ); ?>" />
<input id="comp-icon-delete" type="button" class="image_delete_button button" value="<?php echo __( 'Remove Icon' , BP_COMP_TEXTDOMAIN ); ?>" />
<input id="comp-icon-value" class="image_data_field" type="hidden" name="term_meta[compliments_icon]" value=""/><br/>
<p><?php echo __( 'Recommended icon size: 20px x 20px' , BP_COMP_TEXTDOMAIN ); ?></p>
</span>
</td>
</tr>
<?php
Expand Down
Loading

0 comments on commit 6537eaf

Please sign in to comment.