/**
 * Records group activity items in GES for all activity except:
 *  - group forum posts (handled in ass_group_notification_forum_posts())
 *  - created and joined group entries (irrelevant)
 *
 * You can do more fine-grained activity filtering with the
 * 'ass_block_group_activity_types' filter.
 */
function ass_group_notification_activity($content)
{
    global $bp;
    $type = $content->type;
    $component = $content->component;
    $sender_id = $content->user_id;
    // get group activity update replies to work (there is no group id passed in $content, but we can get it from $bp)
    if ($type == 'activity_comment' && bp_is_groups_component() && $component == 'activity') {
        $component = 'groups';
    }
    // at this point we only want group activity, perhaps later we can make a function and interface for personal activity...
    if ($component != 'groups') {
        return;
    }
    // if you want to conditionally block certain activity types from appearing,
    // use the filter below
    if (false === apply_filters('ass_block_group_activity_types', true, $type, $content)) {
        return;
    }
    if (!ass_registered_long_enough($sender_id)) {
        return;
    }
    $group_id = $content->item_id;
    $action = ass_clean_subject($content->action);
    if ($type == 'activity_comment') {
        // if it's an group activity comment, reset to the proper group id and append the group name to the action
        // this will need to be filtered for plugins manually adding group activity comments
        $group_id = bp_get_current_group_id();
        $action = ass_clean_subject($content->action) . ' ' . __('in the group', 'bp-ass') . ' ' . bp_get_current_group_name();
    }
    $action = apply_filters('bp_ass_activity_notification_action', $action, $content);
    // get the group object
    // if the group is already set in the $bp global use that, otherwise get the group
    $group = groups_get_current_group() ? groups_get_current_group() : groups_get_group('group_id=' . $group_id);
    /* Subject & Content */
    $blogname = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . ']';
    $subject = apply_filters('bp_ass_activity_notification_subject', $action . ' ' . $blogname, $action, $blogname);
    $the_content = apply_filters('bp_ass_activity_notification_content', $content->content, $content);
    $the_content = ass_clean_content($the_content);
    /* If it's an activity item, switch the activity permalink to the group homepage rather than the user's homepage */
    $activity_permalink = isset($content->primary_link) && $content->primary_link != bp_core_get_user_domain($content->user_id) ? $content->primary_link : bp_get_group_permalink($group);
    // If message has no content (as in the case of group joins, etc), we'll use a different
    // $message template
    if (empty($the_content)) {
        $message = sprintf(__('%s

To view or reply, log in and go to:
%s

---------------------
', 'bp-ass'), $action, $activity_permalink);
    } else {
        $message = sprintf(__('%s

"%s"

To view or reply, log in and go to:
%s

---------------------
', 'bp-ass'), $action, $the_content, $activity_permalink);
    }
    // get subscribed users for the group
    $subscribed_users = groups_get_groupmeta($group_id, 'ass_subscribed_users');
    // this is used if a user is subscribed to the "Weekly Summary" option.
    // the weekly summary shouldn't record everything, so we have a filter:
    //
    // 'ass_this_activity_is_important'
    //
    // this hook can be used by plugin authors to record important activity items
    // into the weekly summary
    // @see ass_default_weekly_summary_activity_types()
    $this_activity_is_important = apply_filters('ass_this_activity_is_important', false, $type);
    // cycle through subscribed users
    foreach ((array) $subscribed_users as $user_id => $group_status) {
        //echo '<p>uid: ' . $user_id .' | gstat: ' . $group_status ;
        // Does the author want updates of his own posts?
        if ($user_id == $sender_id) {
            if (!ass_self_post_notification()) {
                continue;
            }
        }
        // If this is an activity comment, and the $user_id is the user who is being replied
        // to, check to make sure that the user is not subscribed to BP's native activity
        // reply notifications
        if ('activity_comment' == $type) {
            // First, look at the immediate parent
            $immediate_parent = new BP_Activity_Activity($content->secondary_item_id);
            // Don't send the bp-ass notification if the user is subscribed through BP
            if ($user_id == $immediate_parent->user_id && 'no' != get_user_meta($user_id, 'notification_activity_new_reply', true)) {
                continue;
            }
            // We only need to check the root parent if it's different from the
            // immediate parent
            if ($content->secondary_item_id != $content->item_id) {
                $root_parent = new BP_Activity_Activity($content->item_id);
                // Don't send the bp-ass notification if the user is subscribed through BP
                if ($user_id == $root_parent->user_id && 'no' != get_user_meta($user_id, 'notification_activity_new_reply', true)) {
                    continue;
                }
            }
        }
        // User is subscribed to "All Mail"
        // OR user is subscribed to "New Topics" (bbPress 2) so send email about this item now!
        if ($group_status == 'supersub' || $group_status == 'sub' && $type == 'bbp_topic_create') {
            /* Content footer */
            $footer = ass_group_unsubscribe_links($user_id);
            $notice = "\n" . __('Your email setting for this group is: ', 'bp-ass') . ass_subscribe_translate($group_status);
            $user = bp_core_get_core_userdata($user_id);
            if ($user->user_email) {
                wp_mail($user->user_email, $subject, $message . $footer . $notice);
            }
            // Send the email
            //echo '<br>EMAIL: ' . $user->user_email . "<br>";
            // User is subscribed to "Daily Digest" so record item in digest!
            // OR user is subscribed to "Weekly Summary" and activity item is important
            // enough to be recorded
        } elseif ($group_status == 'dig' || $group_status == 'sum' && $this_activity_is_important) {
            ass_digest_record_activity($content->id, $user_id, $group_id, $group_status);
            //echo '<br>DIGEST: ' . $user_id . "<br>";
        }
    }
    //echo '<p>Subject: ' . $subject;
    //echo '<pre>'; print_r( $message ); echo '</pre>';
}
/**
 * Send welcome email to new group members
 *
 * @uses apply_filters() Filter 'ass_welcome_email' to change the content/subject of the email
 */
function ass_send_welcome_email($group_id, $user_id)
{
    $user = bp_core_get_core_userdata($user_id);
    $welcome_email = groups_get_groupmeta($group_id, 'ass_welcome_email');
    $welcome_email = apply_filters('ass_welcome_email', $welcome_email, $group_id);
    // for multilingual filtering
    $welcome_email_enabled = isset($welcome_email['enabled']) ? $welcome_email['enabled'] : 'no';
    if ('no' == $welcome_email_enabled) {
        return;
    }
    $subject = ass_clean_subject($welcome_email['subject'], false);
    $message = ass_clean_content($welcome_email['content']);
    if (!$user->user_email || 'yes' != $welcome_email_enabled || empty($message)) {
        return;
    }
    if (get_option('ass-global-unsubscribe-link') == 'yes') {
        $global_link = bp_core_get_user_domain($user_id) . '?bpass-action=unsubscribe&access_key=' . md5("{$user_id}unsubscribe" . wp_salt());
        $message .= "\n\n---------------------\n";
        $message .= sprintf(__('To disable emails from all your groups at once click: %s', 'bp-ass'), $global_link);
    }
    $group_admin_ids = groups_get_group_admins($group_id);
    $group_admin = bp_core_get_core_userdata($group_admin_ids[0]->user_id);
    $headers = array("From: \"{$group_admin->display_name}\" <{$group_admin->user_email}>");
    wp_mail($user->user_email, $subject, $message, $headers);
}
Ejemplo n.º 3
0
 /**
  * BPGES: Clean activity subject.
  *
  * This needs to be done due to us overriding the action to use HTML in
  * {@link WPBE_BP::use_html_for_ges_activity_action()}.
  *
  * @param string The email subject
  * @return string
  */
 public function clean_ges_activity_subject($retval)
 {
     return ass_clean_subject($retval);
 }