Example #1
3
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    if ($result) {
        $rejected_statuses = array(0, 2, 3);
        //these statuses apply to rejected/cancelled bookings
        $user = $EM_Booking->person;
        $member_slug = function_exists('bp_get_members_root_slug') ? bp_get_members_root_slug() : BP_MEMBERS_SLUG;
        $member_link = trailingslashit(bp_get_root_domain()) . $member_slug . '/' . $user->user_login;
        $user_link = "<a href='" . $member_link . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->booking_status;
        $EM_Event = $EM_Booking->get_event();
        if (empty($EM_Event->group_id)) {
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s.', 'dbem'), $user_link, $event_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s anymore.', 'dbem'), $user_link, $event_link);
            }
        } else {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'dbem'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'dbem'), $user_link, $event_link, $group_link);
            }
        }
        if (!empty($action)) {
            bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'item_id' => $EM_Event->event_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            //group activity
            if (!empty($EM_Event->group_id)) {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'item_id' => $EM_Event->group_id, 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            }
        }
    }
    return $result;
}
Example #2
0
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    if ($result) {
        $user = $EM_Booking->person;
        $user_link = "<a href='" . get_bloginfo('wpurl') . '/' . BP_MEMBERS_SLUG . '/' . $user->user_login . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->status;
        if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
            $action = sprintf(__('%s is attending %s.', 'dbem'), $user_link, $event_link);
        } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && ($status > 1 || empty($status) || !get_option('dbem_bookings_approval') && $status != 1)) {
            $action = sprintf(__('%s will not be attending %s anymore.', 'dbem'), $user_link, $event_link);
        }
        $EM_Event = $EM_Booking->get_event();
        if (!empty($EM_Event->group_id)) {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'dbem'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && ($status > 1 || empty($status) || !get_option('dbem_bookings_approval') && $status != 1)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'dbem'), $user_link, $event_link, $group_link);
            }
        }
        if (!empty($action)) {
            bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'item_id' => $EM_Event->id, 'secondary_item_id' => $EM_Booking->id));
            //group activity
            if (!empty($EM_Event->group_id)) {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'item_id' => $EM_Event->group_id, 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'secondary_item_id' => $EM_Booking->id));
            }
        }
    }
    return $result;
}
 function dispatch_creation_activity_update($post_id)
 {
     if (!function_exists('bp_activity_get')) {
         return false;
     }
     // WTF
     $created = $this->_data->get_option('bp-activity_autoupdate-event_created');
     if (!$created) {
         return false;
     }
     $event = new Eab_EventModel(get_post($post_id));
     if (!$event->is_published()) {
         return false;
     }
     $user_link = bp_core_get_userlink($event->get_author());
     $update = false;
     $group_id = $this->_is_group_event($event->get_id());
     $public_announcement = $this->_is_public_announcement($event->get_id());
     if ('any' == $created) {
         $update = sprintf(__('%s created an event', Eab_EventsHub::TEXT_DOMAIN), $user_link);
     } else {
         if ('group' == $created && $group_id) {
             $group = groups_get_group(array('group_id' => $group_id));
             $group_link = bp_get_group_permalink($group);
             $group_name = bp_get_group_name($group);
             $update = sprintf(__('%s created an event in <a href="%s">%s</a>', Eab_EventsHub::TEXT_DOMAIN), $user_link, $group_link, $group_name);
         } else {
             if ('pa' == $created && $public_announcement) {
                 $update = sprintf(__('%s created a public announcement', Eab_EventsHub::TEXT_DOMAIN), $user_link);
             }
         }
     }
     if (!$update) {
         return false;
     }
     $update = sprintf("{$update}, <a href='%s'>%s</a>", get_permalink($event->get_id()), $event->get_title());
     $existing = bp_activity_get(array("filter" => array("object" => 'eab_events', "action" => 'event_created', 'primary_id' => $event->get_id())));
     if (isset($existing['activities']) && !empty($existing['activities'])) {
         return false;
     }
     $activity = array('action' => $update, 'component' => 'eab_events', 'type' => 'event_created', 'item_id' => $event->get_id(), 'user_id' => $event->get_author());
     bp_activity_add($activity);
     if ($this->_data->get_option('bp-activity_autoupdate-created_group_post') && $group_id) {
         global $bp;
         $group_activity = $activity;
         $group_activity['component'] = $bp->groups->id;
         $group_activity['item_id'] = $group_id;
         $group_activity['secondary_item_id'] = $event->get_id();
         $existing = bp_activity_get(array("filter" => array('user_id' => $user_id, "object" => $bp->groups->id, "action" => 'event_created', 'primary_id' => $group_id, 'secondary_id' => $event->get_id())));
         if (isset($existing['activities']) && !empty($existing['activities'])) {
             $old = reset($existing['activities']);
             if (is_object($old) && isset($old->id)) {
                 $group_activity['id'] = $old->id;
             }
         }
         // Add group activity update
         groups_record_activity($group_activity);
     }
 }
function mpp_group_form_uploaded_activity_action($action, $activity, $media_id, $media_ids, $gallery)
{
    if ($gallery->component != 'groups') {
        return $action;
    }
    $media_count = count($media_ids);
    $type = $gallery->type;
    //we need the type plural in case of mult
    $type = _n($type, $type . 's', $media_count);
    //photo vs photos etc
    $group_id = $activity->item_id;
    $group = new BP_Groups_Group($group_id);
    $group_link = sprintf("<a href='%s'>%s</a>", bp_get_group_permalink($group), bp_get_group_name($group));
    $action = sprintf(__('%s uploaded %d new %s to %s', 'mediapress'), mpp_get_user_link($activity->user_id), $media_count, $type, $group_link);
    return $action;
}
function thatcamp_camp_summary()
{
    $summary = 'A new THATCamp has been registered at <a href="http://thatcamp.org">thatcamp.org</a>:<br /><br />';
    $summary .= 'Name: ' . bp_get_group_name() . '<br />';
    $permalink = thatcamp_get_camp_permalink();
    $summary .= 'URL: <a href="' . thatcamp_get_camp_permalink() . '">' . thatcamp_get_camp_permalink() . '</a><br />';
    $location = thatcamp_get_location(bp_get_group_id());
    if ($location) {
        $summary .= 'Location: ' . $location . '<br />';
    }
    $date = thatcamp_get_camp_date_pretty(bp_get_group_id());
    if ($date) {
        $summary .= 'Date: ' . $date . '<br />';
    }
    echo $summary;
}
Example #6
0
 /**
  * Gets user data for a forum reply or article comment
  */
 function get_data($group_id)
 {
     // Get the meta from cache
     $allmeta = wp_cache_get('bp_groups_allmeta_' . $group_id, 'bp');
     // Otherwise query the groupmeta table
     if (false === $allmeta) {
         global $bp, $wpdb;
         $allmeta = array();
         $rawmeta = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d", $group_id));
         foreach ($rawmeta as $meta) {
             $allmeta[$meta->meta_key] = $meta->meta_value;
         }
         wp_cache_set('bp_groups_allmeta_' . $group_id, $allmeta, 'bp');
     }
     // Add data to the class object
     $this->id = $group_id;
     $this->fullname = bp_get_group_name();
     $this->domain = bp_get_group_permalink();
     $this->slug = bp_get_group_slug();
     $this->guild = isset($allmeta['is_guild']) ? $allmeta['is_guild'] : 0;
     $this->members = bp_get_group_member_count();
     $this->alliance = isset($allmeta['group_faction']) ? $allmeta['group_faction'] : 'neutral';
     $this->server = isset($allmeta['group_server']) ? $allmeta['group_server'] : NULL;
     $this->style = isset($allmeta['group_style']) ? $allmeta['group_style'] : NULL;
     $this->interests = isset($allmeta['group_interests']) ? unserialize($allmeta['group_interests']) : array();
     $this->website = isset($allmeta['group_website']) ? $allmeta['group_website'] : NULL;
     // Get some derived data
     $this->type = $this->type();
     $this->faction = $this->allegiance();
     $this->servname = $this->server_name($this->server);
     $this->tooltip = $this->tooltip();
     // Get some extra stuff on user profiles
     if ($this->context == 'profile') {
         $this->byline = $this->byline();
         $this->admins = $this->admins();
         $this->mods = $this->mods();
     }
 }
Example #7
0
function invite_anyone_screen_two_content()
{
    global $bp;
    // Load the pagination helper
    if (!class_exists('BBG_CPT_Pag')) {
        require_once BP_INVITE_ANYONE_DIR . 'lib/bbg-cpt-pag.php';
    }
    $pagination = new BBG_CPT_Pag();
    $inviter_id = bp_loggedin_user_id();
    if (isset($_GET['sort_by'])) {
        $sort_by = $_GET['sort_by'];
    } else {
        $sort_by = 'date_invited';
    }
    if (isset($_GET['order'])) {
        $order = $_GET['order'];
    } else {
        $order = 'DESC';
    }
    $base_url = $bp->displayed_user->domain . $bp->invite_anyone->slug . '/sent-invites/';
    ?>

		<h4><?php 
    _e('Sent Invites', 'invite-anyone');
    ?>
</h4>

		<?php 
    $invites = invite_anyone_get_invitations_by_inviter_id(bp_loggedin_user_id(), $sort_by, $order, $pagination->get_per_page, $pagination->get_paged);
    ?>

		<?php 
    $pagination->setup_query($invites);
    ?>

		<?php 
    if ($invites->have_posts()) {
        ?>
			<p id="sent-invites-intro"><?php 
        _e('You have sent invitations to the following people.', 'invite-anyone');
        ?>
</p>

			<div class="ia-pagination">
				<div class="currently-viewing">
					<?php 
        $pagination->currently_viewing_text();
        ?>
				</div>

				<div class="pag-links">
					<?php 
        $pagination->paginate_links();
        ?>
				</div>
			</div>

			<table class="invite-anyone-sent-invites zebra"
			summary="<?php 
        _e('This table displays a list of all your sent invites.
			Invites that have been accepted are highlighted in the listings.
			You may clear any individual invites, all accepted invites or all of the invites from the list.', 'invite-anyone');
        ?>
">
				<thead>
					<tr>
					  <th scope="col"></th>
					  <th scope="col" <?php 
        if ($sort_by == 'email') {
            ?>
class="sort-by-me"<?php 
        }
        ?>
><a class="<?php 
        echo $order;
        ?>
" title="Sort column order <?php 
        echo $order;
        ?>
" href="<?php 
        echo $base_url;
        ?>
?sort_by=email&amp;order=<?php 
        if ($sort_by == 'email' && $order == 'ASC') {
            ?>
DESC<?php 
        } else {
            ?>
ASC<?php 
        }
        ?>
"><?php 
        _e('Invited email address', 'invite-anyone');
        ?>
</a></th>
					  <th scope="col"><?php 
        _e('Group invitations', 'invite-anyone');
        ?>
</th>
					  <th scope="col" <?php 
        if ($sort_by == 'date_invited') {
            ?>
class="sort-by-me"<?php 
        }
        ?>
><a class="<?php 
        echo $order;
        ?>
" title="Sort column order <?php 
        echo $order;
        ?>
" href="<?php 
        echo $base_url;
        ?>
?sort_by=date_invited&amp;order=<?php 
        if ($sort_by == 'date_invited' && $order == 'DESC') {
            ?>
ASC<?php 
        } else {
            ?>
DESC<?php 
        }
        ?>
"><?php 
        _e('Sent', 'invite-anyone');
        ?>
</a></th>
					  <th scope="col" <?php 
        if ($sort_by == 'date_joined') {
            ?>
class="sort-by-me"<?php 
        }
        ?>
><a class="<?php 
        echo $order;
        ?>
" title="Sort column order <?php 
        echo $order;
        ?>
" href="<?php 
        echo $base_url;
        ?>
?sort_by=date_joined&amp;order=<?php 
        if ($order == 'DESC') {
            ?>
ASC<?php 
        } else {
            ?>
DESC<?php 
        }
        ?>
"><?php 
        _e('Accepted', 'invite-anyone');
        ?>
</a></th>
					</tr>
				</thead>

				<tfoot>
				<tr id="batch-clear">
				  <td colspan="5" >
				   <ul id="invite-anyone-clear-links">
				      <li> <a title="<?php 
        _e('Clear all accepted invites from the list', 'invite-anyone');
        ?>
" class="confirm" href="<?php 
        echo wp_nonce_url($base_url . '?clear=accepted', 'invite_anyone_clear');
        ?>
"><?php 
        _e('Clear all accepted invitations', 'invite-anyone');
        ?>
</a></li>
				      <li class="last"><a title="<?php 
        _e('Clear all your listed invites', 'invite-anyone');
        ?>
" class="confirm" href="<?php 
        echo wp_nonce_url($base_url . '?clear=all', 'invite_anyone_clear');
        ?>
"><?php 
        _e('Clear all invitations', 'invite-anyone');
        ?>
</a></li>
				  </ul>
				 </td>
				</tr>
				</tfoot>

				<tbody>
				<?php 
        while ($invites->have_posts()) {
            $invites->the_post();
            ?>

				<?php 
            $emails = wp_get_post_terms(get_the_ID(), invite_anyone_get_invitee_tax_name());
            // Should never happen, but was messing up my test env
            if (empty($emails)) {
                continue;
            }
            // Before storing taxonomy terms in the db, we replaced "+" with ".PLUSSIGN.", so we need to reverse that before displaying the email address.
            $email = str_replace('.PLUSSIGN.', '+', $emails[0]->name);
            $post_id = get_the_ID();
            $query_string = preg_replace("|clear=[0-9]+|", '', $_SERVER['QUERY_STRING']);
            $clear_url = $query_string ? $base_url . '?' . $query_string . '&clear=' . $post_id : $base_url . '?clear=' . $post_id;
            $clear_url = wp_nonce_url($clear_url, 'invite_anyone_clear');
            $clear_link = '<a class="clear-entry confirm" title="' . __('Clear this invitation', 'invite-anyone') . '" href="' . $clear_url . '">x<span></span></a>';
            $groups = wp_get_post_terms(get_the_ID(), invite_anyone_get_invited_groups_tax_name());
            if (!empty($groups)) {
                $group_names = '<ul>';
                foreach ($groups as $group_term) {
                    $group = new BP_Groups_Group($group_term->name);
                    $group_names .= '<li>' . bp_get_group_name($group) . '</li>';
                }
                $group_names .= '</ul>';
            } else {
                $group_names = '-';
            }
            global $post;
            $date_invited = invite_anyone_format_date($post->post_date);
            $accepted = get_post_meta(get_the_ID(), 'bp_ia_accepted', true);
            if ($accepted) {
                $date_joined = invite_anyone_format_date($accepted);
                $accepted = true;
            } else {
                $date_joined = '-';
                $accepted = false;
            }
            ?>

					<tr <?php 
            if ($accepted) {
                ?>
 class="accepted" <?php 
            }
            ?>
>
						<td><?php 
            echo $clear_link;
            ?>
</td>
						<td><?php 
            echo esc_html($email);
            ?>
</td>
						<td><?php 
            echo $group_names;
            ?>
</td>
						<td><?php 
            echo $date_invited;
            ?>
</td>
						<td class="date-joined"><span></span><?php 
            echo $date_joined;
            ?>
</td>
					</tr>
				<?php 
        }
        ?>
			 </tbody>
			</table>

			<div class="ia-pagination">
				<div class="currently-viewing">
					<?php 
        $pagination->currently_viewing_text();
        ?>
				</div>

				<div class="pag-links">
					<?php 
        $pagination->paginate_links();
        ?>
				</div>
			</div>


		<?php 
    } else {
        ?>

		<p id="sent-invites-intro"><?php 
        _e("You haven't sent any email invitations yet.", 'invite-anyone');
        ?>
</p>

		<?php 
    }
    ?>
	<?php 
}
 /**
  * Create the hub overview CSV when requested.
  *
  * @since    1.0.0
  */
 public function run_stat_hub_csv()
 {
     global $wpdb;
     $bp = buddypress();
     // Output headers so that the file is downloaded rather than displayed.
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=cc-hubs-overview.csv');
     // Create a file pointer connected to the output stream.
     $output = fopen('php://output', 'w');
     // Write a header row.
     $row = array('Hub ID', 'Name', 'Slug', 'Status', 'Date Created', 'Last Activity', 'Parent Hub ID', 'Total Members', 'Creator ID', 'Creator Email', 'Forum', 'BP Docs', 'CC Hub Home Page', 'CC Hub Pages', 'CC Hub Narratives', 'Custom Plugins');
     fputcsv($output, $row);
     // Groups Loop
     if (bp_has_groups(array('order' => 'ASC', 'orderby' => 'date_created', 'page' => null, 'per_page' => null, 'max' => false, 'show_hidden' => true, 'user_id' => null, 'meta_query' => false, 'include' => false, 'exclude' => false, 'populate_extras' => false, 'update_meta_cache' => false))) {
         while (bp_groups()) {
             bp_the_group();
             $group_id = bp_get_group_id();
             $group_object = groups_get_group(array('group_id' => (int) $group_id, 'populate_extras' => true));
             // Hub ID
             $row = array($group_id);
             // Name
             $row[] = bp_get_group_name();
             // Slug
             $row[] = bp_get_group_slug();
             // Status
             $row[] = bp_get_group_status();
             // Date Created
             $row[] = $group_object->date_created;
             // Date of last activity
             $row[] = $group_object->last_activity;
             // Parent Hub ID
             $row[] = $wpdb->get_var($wpdb->prepare("SELECT g.parent_id FROM {$bp->groups->table_name} g WHERE g.id = %d", $group_id));
             // Total Members
             $row[] = groups_get_total_member_count($group_id);
             // Creator ID
             $creator_id = $group_object->creator_id;
             $row[] = $creator_id;
             // Creator Email
             $creator = get_user_by('id', $creator_id);
             $row[] = $creator->user_email;
             // Forum
             $row[] = $group_object->enable_forum;
             // BP Docs
             if (function_exists('bp_docs_is_docs_enabled_for_group')) {
                 $row[] = bp_docs_is_docs_enabled_for_group($group_id);
             } else {
                 $row[] = '';
             }
             // CC Hub Home Page
             if (function_exists('cc_get_group_home_page_post') && cc_get_group_home_page_post($group_id)->have_posts()) {
                 $row[] = 1;
             } else {
                 $row[] = 0;
             }
             // CC Hub Pages
             $row[] = (bool) groups_get_groupmeta($group_id, "ccgp_is_enabled");
             // CC Hub Narratives
             $row[] = (bool) groups_get_groupmeta($group_id, "ccgn_is_enabled");
             // Custom Plugins
             // To make your group-specific plugin be counted, so something like this:
             /*	add_filter( 'cc_stats_custom_plugins', 'prefix_report_custom_plugin', 10, 2 );
              *	function prefix_report_custom_plugin( $custom_plugins, $group_id ) {
              *		if ( $group_id == sa_get_group_id() ) {
              *			$custom_plugins[] = "CC Salud America";
              *		}
              *		return $custom_plugins;
              *	}
              */
             $custom_plugins = apply_filters('cc_stats_custom_plugins', array(), $group_id);
             $custom_plugins = implode(' ', $custom_plugins);
             $row[] = $custom_plugins;
             // Write the row.
             fputcsv($output, $row);
         }
     }
     fclose($output);
     exit;
 }
function groups_join_group($group_id, $user_id = 0)
{
    global $bp;
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // Check if the user has an outstanding invite. If so, delete it.
    if (groups_check_user_has_invite($user_id, $group_id)) {
        groups_delete_invite($user_id, $group_id);
    }
    // Check if the user has an outstanding request. If so, delete it.
    if (groups_check_for_membership_request($user_id, $group_id)) {
        groups_delete_membership_request($user_id, $group_id);
    }
    // User is already a member, just return true
    if (groups_is_user_member($user_id, $group_id)) {
        return true;
    }
    $new_member = new BP_Groups_Member();
    $new_member->group_id = $group_id;
    $new_member->user_id = $user_id;
    $new_member->inviter_id = 0;
    $new_member->is_admin = 0;
    $new_member->user_title = '';
    $new_member->date_modified = bp_core_current_time();
    $new_member->is_confirmed = 1;
    if (!$new_member->save()) {
        return false;
    }
    if (!isset($bp->groups->current_group) || !$bp->groups->current_group || $group_id != $bp->groups->current_group->id) {
        $group = groups_get_group(array('group_id' => $group_id));
    } else {
        $group = $bp->groups->current_group;
    }
    // Record this in activity streams
    groups_record_activity(array('action' => apply_filters('groups_activity_joined_group', sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr(bp_get_group_name($group)) . '</a>')), 'type' => 'joined_group', 'item_id' => $group_id, 'user_id' => $user_id));
    // Modify group meta
    groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
    do_action('groups_join_group', $group_id, $user_id);
    return true;
}
/**
 * Display the Group delete confirmation screen.
 *
 * We include a separate confirmation because group deletion is truly
 * irreversible.
 *
 * @since 1.7.0
 */
function bp_groups_admin_delete()
{
    if (!bp_current_user_can('bp_moderate')) {
        die('-1');
    }
    $group_ids = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : 0;
    if (!is_array($group_ids)) {
        $group_ids = explode(',', $group_ids);
    }
    $group_ids = wp_parse_id_list($group_ids);
    $groups = groups_get_groups(array('include' => $group_ids, 'show_hidden' => true, 'per_page' => null));
    // Create a new list of group ids, based on those that actually exist.
    $gids = array();
    foreach ($groups['groups'] as $group) {
        $gids[] = $group->id;
    }
    $base_url = remove_query_arg(array('action', 'action2', 'paged', 's', '_wpnonce', 'gid'), $_SERVER['REQUEST_URI']);
    ?>

	<div class="wrap">
		<h1><?php 
    _e('Delete Groups', 'buddypress');
    ?>
</h1>
		<p><?php 
    _e('You are about to delete the following groups:', 'buddypress');
    ?>
</p>

		<ul class="bp-group-delete-list">
		<?php 
    foreach ($groups['groups'] as $group) {
        ?>
			<li><?php 
        echo esc_html(bp_get_group_name($group));
        ?>
</li>
		<?php 
    }
    ?>
		</ul>

		<p><strong><?php 
    _e('This action cannot be undone.', 'buddypress');
    ?>
</strong></p>

		<a class="button-primary" href="<?php 
    echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'do_delete', 'gid' => implode(',', $gids)), $base_url), 'bp-groups-delete'));
    ?>
"><?php 
    _e('Delete Permanently', 'buddypress');
    ?>
</a>
		<a class="button" href="<?php 
    echo esc_attr($base_url);
    ?>
"><?php 
    _e('Cancel', 'buddypress');
    ?>
</a>
	</div>

	<?php 
}
<?php

do_action('bp_before_group_request_membership_content');
?>

<?php 
if (!bp_group_has_requested_membership()) {
    ?>
	<p><?php 
    printf(__("You are requesting to become a member of the group '%s'.", "buddypress"), bp_get_group_name(false));
    ?>
</p>

	<form action="<?php 
    bp_group_form_action('request-membership');
    ?>
" method="post" name="request-membership-form" id="request-membership-form" class="standard-form">
		<label for="group-request-membership-comments"><?php 
    _e('Comments (optional)', 'buddypress');
    ?>
</label>
		<textarea name="group-request-membership-comments" id="group-request-membership-comments"></textarea>

		<?php 
    do_action('bp_group_request_membership_content');
    ?>

		<p><input type="submit" name="group-request-send" id="group-request-send" value="<?php 
    _e('Send Request', 'buddypress');
    ?>
 &rarr;" />
/**
 * Returns the name of the current group.
 *
 * @since 1.5.0
 *
 * @return string The name of the current group, if there is one.
 */
function bp_get_current_group_name()
{
    $current_group = groups_get_current_group();
    $current_name = bp_get_group_name($current_group);
    /**
     * Filters the name of the current group.
     *
     * @since 1.2.0
     *
     * @param string $current_name  Name of the current group.
     * @param object $current_group Instance holding the current group.
     */
    return apply_filters('bp_get_current_group_name', $current_name, $current_group);
}
Example #13
0
"><?php 
        bp_group_name();
        ?>
</a></h1>
				<p class="status"><?php 
        bp_group_type();
        ?>
</p>
			</div>

			<div class="info-group">
				<?php 
        if (function_exists('bp_wire_get_post_list')) {
            ?>
					<?php 
            bp_wire_get_post_list(bp_get_group_id(), __('Group Wire', 'buddypress'), sprintf(__('The are no wire posts for %s', 'buddypress'), bp_get_group_name()), bp_group_is_member(), true);
            ?>
				<?php 
        }
        ?>
			</div>
			
		</div>
	</div>
	
	<?php 
    }
}
?>

</div>
function gtags_activity_for_item($args)
{
    global $wpdb, $bp;
    ob_start();
    $defaults = array('group_ids' => '', 'scope' => '', 'show' => 4, 'show_more' => 8, 'truncate' => 190);
    $args = wp_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    if ($scope == 'my' && is_user_logged_in()) {
        $my_groups = BP_Groups_Member::get_group_ids($bp->loggedin_user->id);
        $group_ids = array_intersect($group_ids, $my_groups['groups']);
        $show_hidden = true;
    }
    if (empty($group_ids)) {
        echo '<div class="recent recent-none-found">' . __('Sorry no groups were found.', 'gtags') . '</div>';
        return;
    }
    ?>
<div class="recent"><?php 
    // generate source group links
    foreach ($group_ids as $group_id) {
        $group = groups_get_group(array('group_id' => $group_id));
        $avatar = bp_core_fetch_avatar('object=group&type=thumb&width=50&height=50&item_id=' . $group->id);
        $group_output .= $sep . '<a href="' . bp_get_group_permalink($group) . '" class="recent-group-avatar">' . $avatar . '&nbsp;' . $group->name . '</a>';
        $sep = ', ';
        //compile group data to be used in loop below
        $the_groups[$group->id] = array('permalink' => bp_get_group_permalink($group), 'name' => bp_get_group_name($group), 'avatar' => $avatar);
    }
    ?>
	<div class="gtags-recent-groups">
		<?php 
    _e('Recent Activity From', 'gtags');
    ?>
 <a href="#" class="gtags-more-groups"><?php 
    _e('these groups +', 'gtags');
    ?>
</a>
		<div class="gtags-recent-groups-list"><?php 
    echo $group_output;
    ?>
</div>
	</div>
	<?php 
    // fetch a whole bunch of activity so we can sort them by date below, otherwise they are sorted by group
    $filter = array('user_id' => false, 'object' => 'groups', 'action' => false, 'primary_id' => implode(',', (array) $group_ids));
    $activity = bp_activity_get(array('max' => 1000, 'per_page' => 1000, 'filter' => $filter, 'show_hidden' => $show_hidden));
    //$type_skip = apply_filters( 'gtags_type_skip', array( 'joined_group' ) ); // array of activity types to skip
    // generate a cleaned array of content
    foreach ($activity['activities'] as $item) {
        if (in_array($item->type, (array) $type_skip)) {
            continue;
        }
        $action = preg_replace('/:$/', '', $item->action);
        // remove trailing colon in activity
        $action = apply_filters('gtags_action', $action);
        $content = strip_tags(stripslashes($item->content));
        if ($truncate && strlen($content) > $truncate) {
            $content = substr($content, 0, $truncate) . '... ';
        }
        if ($content) {
            $content .= ' &nbsp;<a href="' . $item->primary_link . '">view</a>';
        }
        $activity_list[$item->date_recorded] = array('action' => $action, 'group_id' => $item->item_id, 'content' => $content, 'primary_link' => $item->primary_link, 'user_id' => $item->user_id);
    }
    if (empty($activity_list)) {
        echo __("Sorry, there was no activity found.", 'gtags');
        echo "</div>";
        //close the div
        return;
    }
    // sort them by date (regardless of group)
    ksort($activity_list);
    $activity_list = array_reverse($activity_list);
    // output pretty html for recent activity for groups
    foreach ((array) $activity_list as $date => $item) {
        $i++;
        $group_id = $item['group_id'];
        $action = $item['action'];
        // show only a certain amount, after that make a 'show more' link and show the rest in a hidden div
        if ($i == $show + 1 && $show_more) {
            ?>
<a href="#" class="gtags-more-activity"><?php 
            _e('show more +', 'gtags');
            ?>
</a>
			<div class="gtags-more-content"><?php 
            $more_link = true;
        }
        if ($i > $show + $show_more + 1) {
            break;
        }
        // for repeating group content, remove group link and shrink group avatar
        if ($prev_group_id == $group_id) {
            $action = preg_replace('/ in the group(.*)$/i', '', $action);
            $dup_class = ' duplicate-group';
        } else {
            $dup_class = '';
        }
        $prev_group_id = $group_id;
        // group avatar
        echo '<a href="' . $the_groups[$group_id]['permalink'] . '" title="' . $the_groups[$group_id]['name'] . '" class="gtags-item-group-avatar' . $dup_class . '">' . $the_groups[$group_id]['avatar'] . '</a>';
        // the actual content
        ?>
<div class="gtags-item-recent group">
			<div class="gtags-item-avatar">
				<a href="<?php 
        echo bp_core_get_user_domain($item['user_id']);
        ?>
">
					<?php 
        echo bp_core_fetch_avatar('object=user&type=full&width=50&height=50&item_id=' . $item['user_id']);
        ?>
				</a>
			</div>
			<div class="gtags-item-action">
				<?php 
        echo $action;
        ?>
 
				<span class="gtags-time-ago"><?php 
        echo bp_core_time_since($date);
        ?>
 <?php 
        _e('ago', 'gtags');
        ?>
</span>
			</div>
			<div class="gtags-item-content">
				<?php 
        echo convert_smilies($item['content']);
        ?>
			</div>
		</div><?php 
    }
    if ($more_link) {
        echo '<div class="gtags-recent-groups"> ' . __('Continue reading in:', 'gtags') . ' ' . $group_output . '</div>';
        echo '</div>';
        // close the more div
    }
    ?>
</div><?php 
    // end recent
    return ob_get_clean();
}
?>

	<div id="whats-new-avatar">
		<a href="<?php 
echo bp_loggedin_user_domain();
?>
">
			<?php 
bp_loggedin_user_avatar('width=' . bp_core_avatar_thumb_width() . '&height=' . bp_core_avatar_thumb_height());
?>
		</a>
	</div>

	<h5><?php 
if (bp_is_group()) {
    printf(__("What's new in %s, %s?", 'vibe'), bp_get_group_name(), bp_get_user_firstname());
} else {
    printf(__("What's new, %s?", 'vibe'), bp_get_user_firstname());
}
?>
</h5>

	<div id="whats-new-content">
		<div id="whats-new-textarea">
			<textarea name="whats-new" class="bp-suggestions" id="whats-new" cols="50" rows="10"><?php 
if (isset($_GET['r'])) {
    ?>
@<?php 
    echo esc_attr($_GET['r']);
    ?>
 <?php 
/**
 * Output a restriction message for each group in the loop.
 *
 * @since 1.0.2
 */
function cfbgr_group_loop_item_restriction_message()
{
    // Get group restriction data.
    $restriction_type = groups_get_groupmeta(bp_get_group_id(), 'cf-buddypress-group-restrictions');
    // Exit early if the group isn't restricted.
    if (empty($restriction_type)) {
        return;
    }
    // Get the name of the group.
    $group_name = bp_get_group_name();
    ?>
	<div class="group-restriction-notice">
		<?php 
    printf(__('%s is open to %s members only.', 'buddypress-group-restrictions'), $group_name, $restriction_type);
    ?>
	</div>
	<?php 
}
Example #17
0
function bpdd_import_groups_members($groups = false)
{
    $members = array();
    if (!$groups) {
        $groups = bpdd_get_random_groups_ids(0);
    }
    $new_member = new BP_Groups_Member();
    foreach ($groups as $group_id) {
        $user_ids = bpdd_get_random_users_ids(rand(2, 15));
        foreach ($user_ids as $user_id) {
            if (groups_is_user_member($user_id, $group_id)) {
                continue;
            }
            $time = bpdd_get_random_date(25, 1);
            $new_member->id = false;
            $new_member->group_id = $group_id;
            $new_member->user_id = $user_id;
            $new_member->inviter_id = 0;
            $new_member->is_admin = 0;
            $new_member->user_title = '';
            $new_member->date_modified = $time;
            $new_member->is_confirmed = 1;
            // save data - finally
            if ($new_member->save()) {
                $group = new BP_Groups_Group($group_id);
                // record this in activity streams
                $activity_id[] = groups_record_activity(array('action' => apply_filters('groups_activity_joined_group', sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr(bp_get_group_name($group)) . '</a>')), 'type' => 'joined_group', 'item_id' => $group_id, 'user_id' => $user_id, 'recorded_time' => $time));
                // modify group meta
                groups_update_groupmeta($group_id, 'total_member_count', (int) groups_get_groupmeta($group_id, 'total_member_count') + 1);
                groups_update_groupmeta($group_id, 'last_activity', $time);
                do_action('groups_join_group', $group_id, $user_id);
                // I need to know how many users were added to display in report after the import
                $members[] = $group_id;
            }
        }
    }
    return $members;
}
 function create_field($field)
 {
     // defaults?
     $field = array_merge($this->defaults, $field);
     // Change Field into a select
     $field['type'] = 'select';
     $field['choices'] = array();
     // set the user ID if you want to return only groups that this user is a member of.
     $user_id = $field['groups'] == 1 ? FALSE : get_current_user_id();
     $args = array('per_page' => 999, 'user_id' => $user_id);
     if (bp_has_groups($args)) {
         while (bp_groups()) {
             bp_the_group();
             $field['choices'][bp_get_group_id()] = bp_get_group_name();
         }
     }
     // create field
     do_action('acf/create_field', $field);
 }
Example #19
0
    function on_bp_gtm_admin_groups($bp_gtm)
    {
        global $bp;
        ?>
        <table id="bp-gtm-admin-table" class="widefat link-group">
            <thead>
                <tr class="header">
                    <td colspan="2"><?php 
        _e('Which groups should have GTM System turned on?', 'bp_gtm');
        ?>
</td>
                    <td class="own_roles"><?php 
        _e('Own roles?', 'bp_gtm');
        ?>
</td>
                </tr>
            </thead>
            <tbody id="the-list">
                <tr>
                    <td><input type="checkbox" class="bp_gtm_allgroups" name="bp_gtm_allgroups" <?php 
        echo 'all' == $bp_gtm['groups'] ? 'checked="checked" ' : '';
        ?>
 value="all" /></td>
                    <td><?php 
        _e('All groups', 'bp_gtm');
        ?>
</td>
                    <td class="own_roles">&nbsp;</td>
                </tr>
                <?php 
        $arg['type'] = 'alphabetical';
        $arg['per_page'] = '1000';
        if (bp_has_groups($arg)) {
            while (bp_groups()) {
                bp_the_group();
                $description = preg_replace(array('<<p>>', '<</p>>', '<<br />>', '<<br>>'), '', bp_get_group_description_excerpt());
                echo '<tr>
                                <td><input name="bp_gtm_groups[' . bp_get_group_id() . ']" class="bp_gtm_groups" type="checkbox" ' . ('all' == $bp_gtm['groups'] || $bp_gtm['groups'][bp_get_group_id()] == 'on' ? 'checked="checked" ' : '') . 'value="on" /></td>
                                <td><a href="' . bp_get_group_permalink() . $bp->gtm->slug . '/" target="_blank">' . bp_get_group_name() . '</a> &rarr; ' . $description . '</td>
                                <td class="own_roles"><input name="bp_gtm_groups_own_roles[' . bp_get_group_id() . ']" class="bp_gtm_groups_own_roles" type="checkbox" ' . ((!empty($bp_gtm['groups_own_roles']) || !empty($bp_gtm['groups_own_roles'][bp_get_group_id()])) && 'all' == $bp_gtm['groups_own_roles'] || !empty($bp_gtm['groups_own_roles'][bp_get_group_id()]) && $bp_gtm['groups_own_roles'][bp_get_group_id()] == bp_get_group_id() ? 'checked="checked" ' : '') . 'value="' . bp_get_group_id() . '" /></td>
                            </tr>';
            }
        }
        ?>
            </tbody>
            <tfoot>
                <tr class="header">
                    <td><input type="checkbox" class="bp_gtm_allgroups" name="bp_gtm_allgroups" <?php 
        echo 'all' == $bp_gtm['groups'] ? 'checked="checked" ' : '';
        ?>
 value="all" /></td>
                    <td><?php 
        _e('All groups', 'bp_gtm');
        ?>
</td>
                    <td>&nbsp;</td>
                </tr>
            </tfoot>
        </table>
        <?php 
    }
        do_action('bp_after_group_menu_mods');
    }
}
?>

</div><!-- #item-actions -->

<?php 
if (!bp_disable_group_avatar_uploads()) {
    ?>
	<div id="item-header-avatar">
		<a href="<?php 
    echo esc_url(bp_get_group_permalink());
    ?>
" title="<?php 
    echo esc_attr(bp_get_group_name());
    ?>
">

			<?php 
    bp_group_avatar();
    ?>

		</a>
	</div><!-- #item-header-avatar -->
<?php 
}
?>

<div id="item-header-content">
	<span class="highlight"><?php 
function bp_group_name()
{
    echo bp_get_group_name();
}
Example #22
0
            bp_activity_delete_link();
            ?>
</p>
	</div>
	
	<?php 
        }
    }
    ?>

	<?php 
} else {
    ?>

	<h5><?php 
    printf(__('What are your thoughts on %s, %s?', 'bpgr'), bp_get_group_name(), bp_get_user_firstname());
    ?>
</h5>

	<div id="whats-new-content">
		<div id="whats-new-textarea">
			<div>
				<textarea name="review_content" id="whats-new" value="" /><?php 
    if (!empty($bp->group_reviews->previous_data->review_content)) {
        echo esc_html($bp->group_reviews->previous_data->review_content);
        ?>
 <?php 
    }
    ?>
</textarea>
			</div>
Example #23
0
/**
 * Get an avatar for a BuddyPress object.
 *
 * Supports avatars for users, groups, and blogs by default, but can be
 * extended to support custom components as well.
 *
 * This function gives precedence to locally-uploaded avatars. When a local
 * avatar is not found, Gravatar is queried. To disable Gravatar fallbacks
 * locally:
 *    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
 *
 * @param array $args {
 *     An array of arguments. All arguments are technically optional; some
 *     will, if not provided, be auto-detected by bp_core_fetch_avatar(). This
 *     auto-detection is described more below, when discussing specific
 *     arguments.
 *
 *     @type int|bool $item_id The numeric ID of the item for which you're
 *           requesting an avatar (eg, a user ID). If no 'item_id' is present,
 *           the function attempts to infer an ID from the 'object' + the
 *           current context: if 'object' is 'user' and the current page is a
 *           user page, 'item_id' will default to the displayed user ID; if
 *           'group' and on a group page, to the current group ID; if 'blog',
 *           to the current blog's ID. If no 'item_id' can be determined in
 *           this way, the function returns false. Default: false.
 *     @type string $object The kind of object for which you're getting an
 *           avatar. BuddyPress natively supports three options: 'user',
 *           'group', 'blog'; a plugin may register more.  Default: 'user'.
 *     @type string $type When a new avatar is uploaded to BP, 'thumb' and
 *           'full' versions are saved. This parameter specifies whether you'd
 *           like the 'full' or smaller 'thumb' avatar. Default: 'thumb'.
 *     @type string|bool $avatar_dir The name of the subdirectory where the
 *           requested avatar should be found. If no value is passed,
 *           'avatar_dir' is inferred from 'object': 'user' becomes 'avatars',
 *           'group' becomes 'group-avatars', 'blog' becomes 'blog-avatars'.
 *           Remember that this string denotes a subdirectory of BP's main
 *           avatar directory (usually based on {@link wp_upload_dir()}); it's a
 *           string like 'group-avatars' rather than the full directory path.
 *           Generally, it'll only be necessary to override the default value if
 *           storing avatars in a non-default location. Defaults to false
 *           (auto-detected).
 *     @type int|bool $width Requested avatar width. The unit is px. This value
 *           is used to build the 'width' attribute for the <img> element. If
 *           no value is passed, BP uses the global avatar width for this
 *           avatar type. Default: false (auto-detected).
 *     @type int|bool $height Requested avatar height. The unit is px. This
 *           value is used to build the 'height' attribute for the <img>
 *           element. If no value is passed, BP uses the global avatar height
 *           for this avatar type. Default: false (auto-detected).
 *     @type string $class The CSS class for the <img> element. Note that BP
 *           uses the 'avatar' class fairly extensively in its default styling,
 *           so if you plan to pass a custom value, consider appending it to
 *           'avatar' (eg 'avatar foo') rather than replacing it altogether.
 *           Default: 'avatar'.
 *     @type string|bool $css_id The CSS id for the <img> element.
 *           Default: false.
 *     @type string $title The title attribute for the <img> element.
 *           Default: false.
 *     @type string $alt The alt attribute for the <img> element. In BP, this
 *           value is generally passed by the wrapper functions, where the data
 *           necessary for concatenating the string is at hand; see
 *           {@link bp_get_activity_avatar()} for an example. Default: ''.
 *     @type string|bool $email An email to use in Gravatar queries. Unless
 *           otherwise configured, BP uses Gravatar as a fallback for avatars
 *           that are not provided locally. Gravatar's API requires using a hash
 *           of the user's email address; this argument provides it. If not
 *           provided, the function will infer it: for users, by getting the
 *           user's email from the database, for groups/blogs, by concatenating
 *           "{$item_id}-{$object}@{bp_get_root_domain()}". The user query adds
 *           overhead, so it's recommended that wrapper functions provide a
 *           value for 'email' when querying user IDs. Default: false.
 *     @type bool $no_grav Whether to disable the default Gravatar fallback.
 *           By default, BP will fall back on Gravatar when it cannot find a
 *           local avatar. In some cases, this may be undesirable, in which
 *           case 'no_grav' should be set to true. To disable Gravatar
 *           fallbacks globally, see the 'bp_core_fetch_avatar_no_grav' filter.
 *           Default: false.
 *     @type bool $html Whether to return an <img> HTML element, vs a raw URL
 *           to an avatar. If false, <img>-specific arguments (like 'css_id')
 *           will be ignored. Default: true.
 * }
 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg.
 */
function bp_core_fetch_avatar($args = '')
{
    // If avatars are disabled for the root site, obey that request and bail
    if (!buddypress()->avatar->show_avatars) {
        return;
    }
    global $current_blog;
    $bp = buddypress();
    // Set a few default variables
    $def_object = 'user';
    $def_type = 'thumb';
    $def_class = 'avatar';
    // Set the default variables array
    $params = wp_parse_args($args, array('item_id' => false, 'object' => $def_object, 'type' => $def_type, 'avatar_dir' => false, 'width' => false, 'height' => false, 'class' => $def_class, 'css_id' => false, 'alt' => '', 'email' => false, 'no_grav' => false, 'html' => true, 'title' => ''));
    extract($params, EXTR_SKIP);
    /** Set item_id ***********************************************************/
    if (empty($item_id)) {
        switch ($object) {
            case 'blog':
                $item_id = $current_blog->id;
                break;
            case 'group':
                if (bp_is_active('groups')) {
                    $item_id = $bp->groups->current_group->id;
                } else {
                    $item_id = false;
                }
                break;
            case 'user':
            default:
                $item_id = bp_displayed_user_id();
                break;
        }
        $item_id = apply_filters('bp_core_avatar_item_id', $item_id, $object, $params);
        if (empty($item_id)) {
            return false;
        }
    }
    $class = apply_filters('bp_core_avatar_class', $class, $item_id, $object, $params);
    /** Set avatar_dir ********************************************************/
    if (empty($avatar_dir)) {
        switch ($object) {
            case 'blog':
                $avatar_dir = 'blog-avatars';
                break;
            case 'group':
                if (bp_is_active('groups')) {
                    $avatar_dir = 'group-avatars';
                } else {
                    $avatar_dir = false;
                }
                break;
            case 'user':
            default:
                $avatar_dir = 'avatars';
                break;
        }
        $avatar_dir = apply_filters('bp_core_avatar_dir', $avatar_dir, $object, $params);
        if (empty($avatar_dir)) {
            return false;
        }
    }
    /** <img> alt *************************************************************/
    if (false !== strpos($alt, '%s') || false !== strpos($alt, '%1$s')) {
        switch ($object) {
            case 'blog':
                $item_name = get_blog_option($item_id, 'blogname');
                break;
            case 'group':
                $item_name = bp_get_group_name(groups_get_group(array('group_id' => $item_id)));
                break;
            case 'user':
            default:
                $item_name = bp_core_get_user_displayname($item_id);
                break;
        }
        $item_name = apply_filters('bp_core_avatar_alt', $item_name, $item_id, $object, $params);
        $alt = sprintf($alt, $item_name);
    }
    /** Sanity Checks *********************************************************/
    // Get a fallback for the 'alt' parameter
    if (empty($alt)) {
        $alt = __('Profile Photo', 'buddypress');
    }
    $html_alt = ' alt="' . esc_attr($alt) . '"';
    // Set title tag, if it's been provided
    if (!empty($title)) {
        $title = " title='" . esc_attr(apply_filters('bp_core_avatar_title', $title, $item_id, $object, $params)) . "'";
    }
    // Set CSS ID if passed
    if (!empty($css_id)) {
        $css_id = ' id="' . esc_attr($css_id) . '"';
    }
    // Set image width
    if (false !== $width) {
        $html_width = ' width="' . $width . '"';
    } elseif ('thumb' == $type) {
        $html_width = ' width="' . bp_core_avatar_thumb_width() . '"';
    } else {
        $html_width = ' width="' . bp_core_avatar_full_width() . '"';
    }
    // Set image height
    if (false !== $height) {
        $html_height = ' height="' . $height . '"';
    } elseif ('thumb' == $type) {
        $html_height = ' height="' . bp_core_avatar_thumb_height() . '"';
    } else {
        $html_height = ' height="' . bp_core_avatar_full_height() . '"';
    }
    // Set img URL and DIR based on prepopulated constants
    $avatar_loc = new stdClass();
    $avatar_loc->path = trailingslashit(bp_core_avatar_upload_path());
    $avatar_loc->url = trailingslashit(bp_core_avatar_url());
    $avatar_loc->dir = trailingslashit($avatar_dir);
    $avatar_folder_url = apply_filters('bp_core_avatar_folder_url', $avatar_loc->url . $avatar_loc->dir . $item_id, $item_id, $object, $avatar_dir);
    $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', $avatar_loc->path . $avatar_loc->dir . $item_id, $item_id, $object, $avatar_dir);
    // Add an identifying class
    $class .= ' ' . $object . '-' . $item_id . '-avatar ' . sanitize_html_class("avatar-{$width}") . ' photo';
    /**
     * Look for uploaded avatar first. Use it if it exists.
     * Set the file names to search for, to select the full size
     * or thumbnail image.
     */
    $avatar_size = 'full' == $type ? '-bpfull' : '-bpthumb';
    $legacy_user_avatar_name = 'full' == $type ? '-avatar2' : '-avatar1';
    $legacy_group_avatar_name = 'full' == $type ? '-groupavatar-full' : '-groupavatar-thumb';
    // Check for directory
    if (file_exists($avatar_folder_dir)) {
        // Open directory
        if ($av_dir = opendir($avatar_folder_dir)) {
            // Stash files in an array once to check for one that matches
            $avatar_files = array();
            while (false !== ($avatar_file = readdir($av_dir))) {
                // Only add files to the array (skip directories)
                if (2 < strlen($avatar_file)) {
                    $avatar_files[] = $avatar_file;
                }
            }
            // Check for array
            if (0 < count($avatar_files)) {
                // Check for current avatar
                foreach ($avatar_files as $key => $value) {
                    if (strpos($value, $avatar_size) !== false) {
                        $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                    }
                }
                // Legacy avatar check
                if (!isset($avatar_url)) {
                    foreach ($avatar_files as $key => $value) {
                        if (strpos($value, $legacy_user_avatar_name) !== false) {
                            $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                        }
                    }
                    // Legacy group avatar check
                    if (!isset($avatar_url)) {
                        foreach ($avatar_files as $key => $value) {
                            if (strpos($value, $legacy_group_avatar_name) !== false) {
                                $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                            }
                        }
                    }
                }
            }
        }
        // Close the avatar directory
        closedir($av_dir);
        // If we found a locally uploaded avatar
        if (isset($avatar_url)) {
            // Return it wrapped in an <img> element
            if (true === $html) {
                return apply_filters('bp_core_fetch_avatar', '<img src="' . $avatar_url . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . $html_alt . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
                // ...or only the URL
            } else {
                return apply_filters('bp_core_fetch_avatar_url', $avatar_url, $params);
            }
        }
    }
    // If no avatars could be found, try to display a gravatar
    // Skips gravatar check if $no_grav is passed
    if (!apply_filters('bp_core_fetch_avatar_no_grav', $no_grav)) {
        // Set gravatar size
        if (false !== $width) {
            $grav_size = $width;
        } else {
            if ('full' == $type) {
                $grav_size = bp_core_avatar_full_width();
            } else {
                if ('thumb' == $type) {
                    $grav_size = bp_core_avatar_thumb_width();
                }
            }
        }
        // Set gravatar type
        if (empty($bp->grav_default->{$object})) {
            $default_grav = 'wavatar';
        } else {
            if ('mystery' == $bp->grav_default->{$object}) {
                $default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $grav_size);
            } else {
                $default_grav = $bp->grav_default->{$object};
            }
        }
        // Set gravatar object
        if (empty($email)) {
            if ('user' == $object) {
                $email = bp_core_get_user_email($item_id);
            } else {
                if ('group' == $object || 'blog' == $object) {
                    $email = "{$item_id}-{$object}@{bp_get_root_domain()}";
                }
            }
        }
        // Set host based on if using ssl
        $host = 'http://gravatar.com/avatar/';
        if (is_ssl()) {
            $host = 'https://secure.gravatar.com/avatar/';
        }
        // Filter gravatar vars
        $email = apply_filters('bp_core_gravatar_email', $email, $item_id, $object);
        $gravatar = apply_filters('bp_gravatar_url', $host) . md5(strtolower($email)) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
        // Gravatar rating; http://bit.ly/89QxZA
        $rating = get_option('avatar_rating');
        if (!empty($rating)) {
            $gravatar .= "&amp;r={$rating}";
        }
        // No avatar was found, and we've been told not to use a gravatar.
    } else {
        $gravatar = apply_filters("bp_core_default_avatar_{$object}", bp_core_avatar_default('local'), $params);
    }
    if (true === $html) {
        return apply_filters('bp_core_fetch_avatar', '<img src="' . $gravatar . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . $html_alt . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
    } else {
        return apply_filters('bp_core_fetch_avatar_url', $gravatar, $params);
    }
}
Example #24
0
						<?php 
    if (bp_has_groups('user_id=' . bp_loggedin_user_id() . '&type=alphabetical&max=100&per_page=100&populate_extras=0')) {
        while (bp_groups()) {
            bp_the_group();
            ?>

								<option value="<?php 
            bp_group_id();
            ?>
"><?php 
            bp_group_name();
            ?>
</option>

								<?php 
            $dd_fake_select .= '<li><a href="#" data-group-id="' . bp_get_group_id() . '">' . bp_get_group_name() . '</a></li>';
            ?>

							<?php 
        }
    }
    ?>

					</select>

					<div class="dd-button-dropdown dd-bp-post-in-fake">
						<div class="dd-button-dropdown-content">
							<ul>
								<?php 
    echo $dd_fake_select;
    ?>
Example #25
0
/**
 * Get an avatar for a BuddyPress object.
 *
 * Supports avatars for users, groups, and blogs by default, but can be
 * extended to support custom components as well.
 *
 * This function gives precedence to locally-uploaded avatars. When a local
 * avatar is not found, Gravatar is queried. To disable Gravatar fallbacks
 * locally:
 *    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
 *
 * @since 2.4.0 Added 'extra_attr', 'scheme', 'rating' and 'force_default' for $args.
 *              These are inherited from WordPress 4.2.0. See {@link get_avatar()}.
 *
 * @param array|string $args {
 *     An array of arguments. All arguments are technically optional; some
 *     will, if not provided, be auto-detected by bp_core_fetch_avatar(). This
 *     auto-detection is described more below, when discussing specific
 *     arguments.
 *
 *     @type int|bool    $item_id    The numeric ID of the item for which you're requesting
 *                                   an avatar (eg, a user ID). If no 'item_id' is present,
 *                                   the function attempts to infer an ID from the 'object' + the
 *                                   current context: if 'object' is 'user' and the current page is a
 *                                   user page, 'item_id' will default to the displayed user ID; if
 *                                   'group' and on a group page, to the current group ID; if 'blog',
 *                                   to the current blog's ID. If no 'item_id' can be determined in
 *                                   this way, the function returns false. Default: false.
 *     @type string      $object     The kind of object for which you're getting an
 *                                   avatar. BuddyPress natively supports three options: 'user',
 *                                   'group', 'blog'; a plugin may register more.  Default: 'user'.
 *     @type string      $type       When a new avatar is uploaded to BP, 'thumb' and
 *                                   'full' versions are saved. This parameter specifies whether you'd
 *                                   like the 'full' or smaller 'thumb' avatar. Default: 'thumb'.
 *     @type string|bool $avatar_dir The name of the subdirectory where the
 *                                   requested avatar should be found. If no value is passed,
 *                                   'avatar_dir' is inferred from 'object': 'user' becomes 'avatars',
 *                                   'group' becomes 'group-avatars', 'blog' becomes 'blog-avatars'.
 *                                   Remember that this string denotes a subdirectory of BP's main
 *                                   avatar directory (usually based on {@link wp_upload_dir()}); it's a
 *                                   string like 'group-avatars' rather than the full directory path.
 *                                   Generally, it'll only be necessary to override the default value if
 *                                   storing avatars in a non-default location. Defaults to false
 *                                   (auto-detected).
 *     @type int|bool    $width      Requested avatar width. The unit is px. This value
 *                                   is used to build the 'width' attribute for the <img> element. If
 *                                   no value is passed, BP uses the global avatar width for this
 *                                   avatar type. Default: false (auto-detected).
 *     @type int|bool    $height     Requested avatar height. The unit is px. This
 *                                   value is used to build the 'height' attribute for the <img>
 *                                   element. If no value is passed, BP uses the global avatar height
 *                                   for this avatar type. Default: false (auto-detected).
 *     @type string      $class      The CSS class for the <img> element. Note that BP
 *                                   uses the 'avatar' class fairly extensively in its default styling,
 *                                   so if you plan to pass a custom value, consider appending it to
 *                                   'avatar' (eg 'avatar foo') rather than replacing it altogether.
 *                                   Default: 'avatar'.
 *     @type string|bool $css_id     The CSS id for the <img> element.
 *                                   Default: false.
 *     @type string      $title      The title attribute for the <img> element.
 *                                   Default: false.
 *     @type string      $alt        The alt attribute for the <img> element. In BP, this
 *                                   value is generally passed by the wrapper functions, where the data
 *                                   necessary for concatenating the string is at hand; see
 *                                   {@link bp_get_activity_avatar()} for an example. Default: ''.
 *     @type string|bool $email      An email to use in Gravatar queries. Unless
 *                                   otherwise configured, BP uses Gravatar as a fallback for avatars
 *                                   that are not provided locally. Gravatar's API requires using a hash
 *                                   of the user's email address; this argument provides it. If not
 *                                   provided, the function will infer it: for users, by getting the
 *                                   user's email from the database, for groups/blogs, by concatenating
 *                                   "{$item_id}-{$object}@{bp_get_root_domain()}". The user query adds
 *                                   overhead, so it's recommended that wrapper functions provide a
 *                                   value for 'email' when querying user IDs. Default: false.
 *     @type bool       $no_grav     Whether to disable the default Gravatar fallback.
 *                                   By default, BP will fall back on Gravatar when it cannot find a
 *                                   local avatar. In some cases, this may be undesirable, in which
 *                                   case 'no_grav' should be set to true. To disable Gravatar
 *                                   fallbacks globally, see the 'bp_core_fetch_avatar_no_grav' filter.
 *                                   Default: false.
 *     @type bool       $html        Whether to return an <img> HTML element, vs a raw URL
 *                                   to an avatar. If false, <img>-specific arguments (like 'css_id')
 *                                   will be ignored. Default: true.
 *     @type string     $extra_attr  HTML attributes to insert in the IMG element. Not sanitized. Default: ''.
 *     @type string     $scheme      URL scheme to use. See set_url_scheme() for accepted values.
 *                                   Default null.
 *     @type string     $rating      What rating to display Gravatars for. Accepts 'G', 'PG', 'R', 'X'.
 *                                   Default is the value of the 'avatar_rating' option.
 *     @type bool       $force_default Used when creating the Gravatar URL. Whether to force the default
 *                                     image regardless if the Gravatar exists. Default: false.
 * }
 *
 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg.
 */
function bp_core_fetch_avatar($args = '')
{
    $bp = buddypress();
    // If avatars are disabled for the root site, obey that request and bail
    if (!$bp->avatar->show_avatars) {
        return;
    }
    global $current_blog;
    // Set the default variables array and parse it against incoming $args array.
    $params = wp_parse_args($args, array('item_id' => false, 'object' => 'user', 'type' => 'thumb', 'avatar_dir' => false, 'width' => false, 'height' => false, 'class' => 'avatar', 'css_id' => false, 'alt' => '', 'email' => false, 'no_grav' => false, 'html' => true, 'title' => '', 'extra_attr' => '', 'scheme' => null, 'rating' => get_option('avatar_rating'), 'force_default' => false));
    /** Set item_id ***********************************************************/
    if (empty($params['item_id'])) {
        switch ($params['object']) {
            case 'blog':
                $params['item_id'] = $current_blog->id;
                break;
            case 'group':
                if (bp_is_active('groups')) {
                    $params['item_id'] = $bp->groups->current_group->id;
                } else {
                    $params['item_id'] = false;
                }
                break;
            case 'user':
            default:
                $params['item_id'] = bp_displayed_user_id();
                break;
        }
        /**
         * Filters the ID of the item being requested.
         *
         * @since 1.1.0
         *
         * @param string $value  ID of avatar item being requested.
         * @param string $value  Avatar type being requested.
         * @param array  $params Array of parameters for the request.
         */
        $params['item_id'] = apply_filters('bp_core_avatar_item_id', $params['item_id'], $params['object'], $params);
        if (empty($params['item_id'])) {
            return false;
        }
    }
    /** Set avatar_dir ********************************************************/
    if (empty($params['avatar_dir'])) {
        switch ($params['object']) {
            case 'blog':
                $params['avatar_dir'] = 'blog-avatars';
                break;
            case 'group':
                if (bp_is_active('groups')) {
                    $params['avatar_dir'] = 'group-avatars';
                } else {
                    $params['avatar_dir'] = false;
                }
                break;
            case 'user':
            default:
                $params['avatar_dir'] = 'avatars';
                break;
        }
        /**
         * Filters the avatar directory to use.
         *
         * @since 1.1.0
         *
         * @param string $value  Name of the subdirectory where the requested avatar should be found.
         * @param string $value  Avatar type being requested.
         * @param array  $params Array of parameters for the request.
         */
        $params['avatar_dir'] = apply_filters('bp_core_avatar_dir', $params['avatar_dir'], $params['object'], $params);
        if (empty($params['avatar_dir'])) {
            return false;
        }
    }
    /** <img> alt *************************************************************/
    if (false !== strpos($params['alt'], '%s') || false !== strpos($params['alt'], '%1$s')) {
        switch ($params['object']) {
            case 'blog':
                $item_name = get_blog_option($params['item_id'], 'blogname');
                break;
            case 'group':
                $item_name = bp_get_group_name(groups_get_group(array('group_id' => $params['item_id'])));
                break;
            case 'user':
            default:
                $item_name = bp_core_get_user_displayname($params['item_id']);
                break;
        }
        /**
         * Filters the alt attribute value to be applied to avatar.
         *
         * @since 1.5.0
         *
         * @param string $value  alt to be applied to avatar.
         * @param string $value  ID of avatar item being requested.
         * @param string $value  Avatar type being requested.
         * @param array  $params Array of parameters for the request.
         */
        $item_name = apply_filters('bp_core_avatar_alt', $item_name, $params['item_id'], $params['object'], $params);
        $params['alt'] = sprintf($params['alt'], $item_name);
    }
    /** Sanity Checks *********************************************************/
    // Get a fallback for the 'alt' parameter, create html output.
    if (empty($params['alt'])) {
        $params['alt'] = __('Profile Photo', 'buddypress');
    }
    $html_alt = ' alt="' . esc_attr($params['alt']) . '"';
    // Filter image title and create html string.
    $html_title = '';
    /**
     * Filters the title attribute value to be applied to avatar.
     *
     * @since 1.5.0
     *
     * @param string $value  Title to be applied to avatar.
     * @param string $value  ID of avatar item being requested.
     * @param string $value  Avatar type being requested.
     * @param array  $params Array of parameters for the request.
     */
    $params['title'] = apply_filters('bp_core_avatar_title', $params['title'], $params['item_id'], $params['object'], $params);
    if (!empty($params['title'])) {
        $html_title = ' title="' . esc_attr($params['title']) . '"';
    }
    // Extra attributes
    $extra_attr = !empty($args['extra_attr']) ? ' ' . $args['extra_attr'] : '';
    // Set CSS ID and create html string.
    $html_css_id = '';
    /**
     * Filters the ID attribute to be applied to avatar.
     *
     * @since 2.2.0
     *
     * @param string $value  ID to be applied to avatar.
     * @param string $value  ID of avatar item being requested.
     * @param string $value  Avatar type being requested.
     * @param array  $params Array of parameters for the request.
     */
    $params['css_id'] = apply_filters('bp_core_css_id', $params['css_id'], $params['item_id'], $params['object'], $params);
    if (!empty($params['css_id'])) {
        $html_css_id = ' id="' . esc_attr($params['css_id']) . '"';
    }
    // Set image width
    if (false !== $params['width']) {
        // Width has been specified. No modification necessary.
    } elseif ('thumb' == $params['type']) {
        $params['width'] = bp_core_avatar_thumb_width();
    } else {
        $params['width'] = bp_core_avatar_full_width();
    }
    $html_width = ' width="' . $params['width'] . '"';
    // Set image height
    if (false !== $params['height']) {
        // Height has been specified. No modification necessary.
    } elseif ('thumb' == $params['type']) {
        $params['height'] = bp_core_avatar_thumb_height();
    } else {
        $params['height'] = bp_core_avatar_full_height();
    }
    $html_height = ' height="' . $params['height'] . '"';
    /**
     * Filters the classes to be applied to the avatar.
     *
     * @since 1.6.0
     *
     * @param array|string $value  Class(es) to be applied to the avatar.
     * @param string       $value  ID of the avatar item being requested.
     * @param string       $value  Avatar type being requested.
     * @param array        $params Array of parameters for the request.
     */
    $params['class'] = apply_filters('bp_core_avatar_class', $params['class'], $params['item_id'], $params['object'], $params);
    // Use an alias to leave the param unchanged
    $avatar_classes = $params['class'];
    if (!is_array($avatar_classes)) {
        $avatar_classes = explode(' ', $avatar_classes);
    }
    // merge classes
    $avatar_classes = array_merge($avatar_classes, array($params['object'] . '-' . $params['item_id'] . '-avatar', 'avatar-' . $params['width']));
    // Sanitize each class
    $avatar_classes = array_map('sanitize_html_class', $avatar_classes);
    // populate the class attribute
    $html_class = ' class="' . join(' ', $avatar_classes) . ' photo"';
    // Set img URL and DIR based on prepopulated constants
    $avatar_loc = new stdClass();
    $avatar_loc->path = trailingslashit(bp_core_avatar_upload_path());
    $avatar_loc->url = trailingslashit(bp_core_avatar_url());
    $avatar_loc->dir = trailingslashit($params['avatar_dir']);
    /**
     * Filters the avatar folder directory URL.
     *
     * @since 1.1.0
     *
     * @param string $value Path to the avatar folder URL.
     * @param int    $value ID of the avatar item being requested.
     * @param string $value Avatar type being requested.
     * @param string $value Subdirectory where the requested avatar should be found.
     */
    $avatar_folder_url = apply_filters('bp_core_avatar_folder_url', $avatar_loc->url . $avatar_loc->dir . $params['item_id'], $params['item_id'], $params['object'], $params['avatar_dir']);
    /**
     * Filters the avatar folder directory path.
     *
     * @since 1.1.0
     *
     * @param string $value Path to the avatar folder directory.
     * @param int    $value ID of the avatar item being requested.
     * @param string $value Avatar type being requested.
     * @param string $value Subdirectory where the requested avatar should be found.
     */
    $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', $avatar_loc->path . $avatar_loc->dir . $params['item_id'], $params['item_id'], $params['object'], $params['avatar_dir']);
    /**
     * Look for uploaded avatar first. Use it if it exists.
     * Set the file names to search for, to select the full size
     * or thumbnail image.
     */
    $avatar_size = 'full' == $params['type'] ? '-bpfull' : '-bpthumb';
    $legacy_user_avatar_name = 'full' == $params['type'] ? '-avatar2' : '-avatar1';
    $legacy_group_avatar_name = 'full' == $params['type'] ? '-groupavatar-full' : '-groupavatar-thumb';
    // Check for directory
    if (file_exists($avatar_folder_dir)) {
        // Open directory
        if ($av_dir = opendir($avatar_folder_dir)) {
            // Stash files in an array once to check for one that matches
            $avatar_files = array();
            while (false !== ($avatar_file = readdir($av_dir))) {
                // Only add files to the array (skip directories)
                if (2 < strlen($avatar_file)) {
                    $avatar_files[] = $avatar_file;
                }
            }
            // Check for array
            if (0 < count($avatar_files)) {
                // Check for current avatar
                foreach ($avatar_files as $key => $value) {
                    if (strpos($value, $avatar_size) !== false) {
                        $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                    }
                }
                // Legacy avatar check
                if (!isset($avatar_url)) {
                    foreach ($avatar_files as $key => $value) {
                        if (strpos($value, $legacy_user_avatar_name) !== false) {
                            $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                        }
                    }
                    // Legacy group avatar check
                    if (!isset($avatar_url)) {
                        foreach ($avatar_files as $key => $value) {
                            if (strpos($value, $legacy_group_avatar_name) !== false) {
                                $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                            }
                        }
                    }
                }
            }
        }
        // Close the avatar directory
        closedir($av_dir);
        // If we found a locally uploaded avatar
        if (isset($avatar_url)) {
            // Support custom scheme
            $avatar_url = set_url_scheme($avatar_url, $params['scheme']);
            // Return it wrapped in an <img> element
            if (true === $params['html']) {
                /**
                 * Filters an avatar URL wrapped in an <img> element.
                 *
                 * @since 1.1.0
                 *
                 * @param string $value             Full <img> element for an avatar.
                 * @param array  $params            Array of parameters for the request.
                 * @param string $value             ID of the item requested.
                 * @param string $value             Subdirectory where the requested avatar should be found.
                 * @param string $html_css_id       ID attribute for avatar.
                 * @param string $html_width        Width attribute for avatar.
                 * @param string $html_height       Height attribtue for avatar.
                 * @param string $avatar_folder_url Avatar URL path.
                 * @param string $avatar_folder_dir Avatar dir path.
                 */
                return apply_filters('bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
                // ...or only the URL
            } else {
                /**
                 * Filters a locally uploaded avatar URL.
                 *
                 * @since 1.2.5
                 *
                 * @param string $avatar_url URL for a locally uploaded avatar.
                 * @param array  $params     Array of parameters for the request.
                 */
                return apply_filters('bp_core_fetch_avatar_url', $avatar_url, $params);
            }
        }
    }
    /**
     * Filters whether or not to skip Gravatar check.
     *
     * @since 1.5.0
     *
     * @param bool  $value  Whether or not to skip Gravatar.
     * @param array $params Array of parameters for the avatar request.
     */
    if (!apply_filters('bp_core_fetch_avatar_no_grav', $params['no_grav'], $params)) {
        // Set gravatar type
        if (empty($bp->grav_default->{$params['object']})) {
            $default_grav = 'wavatar';
        } elseif ('mystery' == $bp->grav_default->{$params['object']}) {
            /**
             * Filters the Mystery person avatar src value.
             *
             * @since 1.2.0
             *
             * @param string $value Avatar value.
             * @param string $value Width to display avatar at.
             */
            $default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $params['width']);
        } else {
            $default_grav = $bp->grav_default->{$params['object']};
        }
        // Set gravatar object
        if (empty($params['email'])) {
            if ('user' == $params['object']) {
                $params['email'] = bp_core_get_user_email($params['item_id']);
            } elseif ('group' == $params['object'] || 'blog' == $params['object']) {
                $params['email'] = $params['item_id'] . '-' . $params['object'] . '@' . bp_get_root_domain();
            }
        }
        /**
         * Filters the Gravatar email to use.
         *
         * @since 1.1.0
         *
         * @param string $value Email to use in Gravatar request.
         * @param string $value ID of the item being requested.
         * @param string $value Object type being requested.
         */
        $params['email'] = apply_filters('bp_core_gravatar_email', $params['email'], $params['item_id'], $params['object']);
        /**
         * Filters the Gravatar URL host.
         *
         * @since 1.0.2
         *
         * @param string $value Gravatar URL host.
         */
        $gravatar = apply_filters('bp_gravatar_url', '//www.gravatar.com/avatar/');
        // Append email hash to Gravatar
        $gravatar .= md5(strtolower($params['email']));
        // Main Gravatar URL args
        $url_args = array('s' => $params['width']);
        // Custom Gravatar URL args
        if (!empty($params['force_default'])) {
            $url_args['f'] = 'y';
        }
        if (!empty($params['rating'])) {
            $url_args['r'] = strtolower($params['rating']);
        }
        // Only set default image if 'Gravatar Logo' is not requested
        if ('gravatar_default' !== $default_grav) {
            $url_args['d'] = $default_grav;
        }
        // Set up the Gravatar URL
        $gravatar = esc_url(add_query_arg(rawurlencode_deep(array_filter($url_args)), $gravatar));
        // No avatar was found, and we've been told not to use a gravatar.
    } else {
        /**
         * Filters the avatar default when Gravatar is not used.
         *
         * This is a variable filter dependent on the avatar type being requested.
         *
         * @since 1.5.0
         *
         * @param string $value  Default avatar for non-gravatar requests.
         * @param array  $params Array of parameters for the avatar request.
         */
        $gravatar = apply_filters('bp_core_default_avatar_' . $params['object'], bp_core_avatar_default('local'), $params);
    }
    if (true === $params['html']) {
        /** This filter is documented in bp-core/bp-core-avatars.php */
        return apply_filters('bp_core_fetch_avatar', '<img src="' . $gravatar . '"' . $html_css_id . $html_class . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
    } else {
        /** This filter is documented in bp-core/bp-core-avatars.php */
        return apply_filters('bp_core_fetch_avatar_url', $gravatar, $params);
    }
}
//output cover photo.
if (boss_get_option('boss_layout_style') != 'boxed' && boss_get_option('boss_cover_group')) {
    echo buddyboss_cover_photo("group", bp_get_group_id());
}
?>

<div id="item-header-cover" class="table">

	<div class="table-cell">
        <span class="bp-group-hierarchy-breadcrumbs"><?php 
bp_group_hierarchy_breadcrumbs();
?>
</span>
		<div id="group-name">
			<h1 class="main-title"><?php 
$group_name = bp_get_group_name();
if (!empty($group_name)) {
    //Get truncated string with long width group title
    if (wp_is_mobile()) {
        echo mb_strimwidth($group_name, 0, 35, "...");
    } else {
        echo mb_strimwidth($group_name, 0, 55, "...");
    }
}
?>
</h1>
			<span class="activity"><?php 
printf(__('active %s', 'boss'), bp_get_group_last_active());
?>
</span>
		</div>
function bp_group_name($group = false)
{
    echo bp_get_group_name($group);
}
/**
 * Prints the box content.
 * 
 * @param WP_Post $post The object for the current post/page.
 */
function bpgroups_meta_box_callback($post)
{
    // Add an nonce field so we can check for it later.
    wp_nonce_field('bpgroups_meta_box', 'bpgroups_meta_box_nonce');
    // to store the groups this user is member of
    $buddypressgroups = array();
    $checkgroups = array();
    // Get real Buddypress Groups
    if (function_exists('bp_groups')) {
        if (bp_has_groups()) {
            while (bp_groups()) {
                bp_the_group();
                $groupname = bp_get_group_name();
                $groupslug = bp_get_group_slug();
                // Set group as taxonomy term if not already done
                $termexists = term_exists($groupname, 'buddypress_groups');
                if (empty($termexists)) {
                    wp_insert_term($groupname, 'buddypress_groups', array('slug' => strtolower($groupname)));
                }
                // Get only groups the current user is member of
                if (groups_is_user_member(get_current_user_id(), bp_get_group_id())) {
                    $buddypressgroups[] = array('name' => $groupname, 'slug' => $groupslug);
                    $checkgroups[] = strtolower($groupslug);
                }
            }
        }
    }
    // Remove tax terms that have no buddypress group counterpart anymore in case of changes
    $allgroupterms = get_terms('buddypress_groups', array('hide_empty' => false));
    foreach ($allgroupterms as $groupterm) {
        if (!in_array($groupterm->slug, $checkgroups) && $groupterm->slug != 'keine') {
            // just keep non assignment term
            $term = get_term_by('slug', $groupterm->name, 'buddypress_groups');
            if ($term) {
                wp_delete_term($term->term_id, 'buddypress_groups');
            }
        }
    }
    //get the group assigned to this post if any
    $assignedgroups = wp_get_object_terms(array($post->ID), array('buddypress_groups'));
    $assignedgroup = 'keine';
    // posts without assignments
    if ($assignedgroups) {
        $assignedgroup = $assignedgroups[0]->slug;
        // technically more than one but we use only one
    }
    ?>
	<p>
		<select name="bpgroups_groupselector" id="bpgroups_groupselector" size="1">
			<option value="keine" <?php 
    selected($assignedgroup, 'keine', true);
    ?>
>Keine</option>
			<?php 
    foreach ($buddypressgroups as $bpgroup) {
        $name = $bpgroup['name'];
        $slug = $bpgroup['slug'];
        ?>
				<option value="<?php 
        echo esc_html($slug);
        ?>
" <?php 
        selected($assignedgroup, $slug, true);
        ?>
><?php 
        echo esc_html($name);
        ?>
</option>
	<?php 
    }
    ?>
		</select>
	</p>
	<?php 
}
Example #29
0
?>

	<div id="whats-new-avatar">
		<a href="<?php 
echo bp_loggedin_user_domain();
?>
">
			<?php 
bp_loggedin_user_avatar('width=' . bp_core_avatar_thumb_width() . '&height=' . bp_core_avatar_thumb_height());
?>
		</a>
	</div>

	<h5><?php 
if (bp_is_group()) {
    printf(__("What's new in %s, %s?", 'buddypress'), bp_get_group_name(), bp_get_user_firstname());
} else {
    printf(__("What's new, %s?", 'buddypress'), bp_get_user_firstname());
}
?>
</h5>

	<div id="whats-new-content">
		<div id="whats-new-textarea">
			<textarea name="whats-new" id="whats-new" cols="50" rows="10"><?php 
if (isset($_GET['r'])) {
    ?>
@<?php 
    echo esc_attr($_GET['r']);
    ?>
 <?php 
Example #30
0
/**
 * bp_core_fetch_avatar()
 *
 * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
 * default, but can be extended to include your own custom components too.
 *
 * @global object $bp Global BuddyPress settings object
 * @global $current_blog NXTClass global containing information and settings for the current blog being viewed.
 * @param array $args Determine the output of this function
 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
 */
function bp_core_fetch_avatar($args = '')
{
    global $bp, $current_blog;
    // Set a few default variables
    $def_object = 'user';
    $def_type = 'thumb';
    $def_class = 'avatar';
    $def_alt = __('Avatar Image', 'buddypress');
    // Set the default variables array
    $defaults = array('item_id' => false, 'object' => $def_object, 'type' => $def_type, 'avatar_dir' => false, 'width' => false, 'height' => false, 'class' => $def_class, 'css_id' => false, 'alt' => $def_alt, 'email' => false, 'no_grav' => false, 'html' => true, 'title' => '');
    // Compare defaults to passed and extract
    $params = nxt_parse_args($args, $defaults);
    extract($params, EXTR_SKIP);
    // Set item_id if not passed
    if (!$item_id) {
        if ('user' == $object) {
            $item_id = $bp->displayed_user->id;
        } else {
            if (bp_is_active('groups') && 'group' == $object) {
                $item_id = $bp->groups->current_group->id;
            } else {
                if ('blog' == $object) {
                    $item_id = $current_blog->id;
                }
            }
        }
        $item_id = apply_filters('bp_core_avatar_item_id', $item_id, $object);
        if (!$item_id) {
            return false;
        }
    }
    // Set avatar_dir if not passed (uses $object)
    if (!$avatar_dir) {
        if ('user' == $object) {
            $avatar_dir = 'avatars';
        } else {
            if (bp_is_active('groups') && 'group' == $object) {
                $avatar_dir = 'group-avatars';
            } else {
                if ('blog' == $object) {
                    $avatar_dir = 'blog-avatars';
                }
            }
        }
        $avatar_dir = apply_filters('bp_core_avatar_dir', $avatar_dir, $object);
        if (!$avatar_dir) {
            return false;
        }
    }
    // Add an identifying class to each item
    $class .= ' ' . $object . '-' . $item_id . '-avatar';
    // Get item name for alt/title tags
    $item_name = '';
    if ('user' == $object) {
        $item_name = bp_core_get_user_displayname($item_id);
    } elseif ('group' == $object) {
        $item_name = bp_get_group_name(new BP_Groups_Group($item_id));
    } elseif ('blog' == $object) {
        $item_name = get_blog_option($item_id, 'blogname');
    }
    $alt = sprintf($alt, apply_filters('bp_core_avatar_alt', $item_name, $item_id, $object));
    // Set title tag
    if ($title) {
        $title = " title='" . esc_attr(apply_filters('bp_core_avatar_title', $title, $item_id, $object)) . "'";
    } elseif ($item_name) {
        $title = " title='" . esc_attr(apply_filters('bp_core_avatar_title', $item_name, $item_id, $object)) . "'";
    }
    // Set CSS ID if passed
    if (!empty($css_id)) {
        $css_id = " id='{$css_id}'";
    }
    // Set avatar width
    if ($width) {
        $html_width = " width='{$width}'";
    } else {
        $html_width = 'thumb' == $type ? ' width="' . bp_core_avatar_thumb_width() . '"' : ' width="' . bp_core_avatar_full_width() . '"';
    }
    // Set avatar height
    if ($height) {
        $html_height = " height='{$height}'";
    } else {
        $html_height = 'thumb' == $type ? ' height="' . bp_core_avatar_thumb_height() . '"' : ' height="' . bp_core_avatar_full_height() . '"';
    }
    // Set avatar URL and DIR based on prepopulated constants
    $avatar_folder_url = apply_filters('bp_core_avatar_folder_url', bp_core_avatar_url() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir);
    $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir);
    /****
     * Look for uploaded avatar first. Use it if it exists.
     * Set the file names to search for, to select the full size
     * or thumbnail image.
     */
    $avatar_size = 'full' == $type ? '-bpfull' : '-bpthumb';
    $legacy_user_avatar_name = 'full' == $type ? '-avatar2' : '-avatar1';
    $legacy_group_avatar_name = 'full' == $type ? '-groupavatar-full' : '-groupavatar-thumb';
    // Check for directory
    if (file_exists($avatar_folder_dir)) {
        // Open directory
        if ($av_dir = opendir($avatar_folder_dir)) {
            // Stash files in an array once to check for one that matches
            $avatar_files = array();
            while (false !== ($avatar_file = readdir($av_dir))) {
                // Only add files to the array (skip directories)
                if (2 < strlen($avatar_file)) {
                    $avatar_files[] = $avatar_file;
                }
            }
            // Check for array
            if (0 < count($avatar_files)) {
                // Check for current avatar
                foreach ($avatar_files as $key => $value) {
                    if (strpos($value, $avatar_size) !== false) {
                        $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                    }
                }
                // Legacy avatar check
                if (!isset($avatar_url)) {
                    foreach ($avatar_files as $key => $value) {
                        if (strpos($value, $legacy_user_avatar_name) !== false) {
                            $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                        }
                    }
                    // Legacy group avatar check
                    if (!isset($avatar_url)) {
                        foreach ($avatar_files as $key => $value) {
                            if (strpos($value, $legacy_group_avatar_name) !== false) {
                                $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
                            }
                        }
                    }
                }
            }
        }
        // Close the avatar directory
        closedir($av_dir);
        // If we found a locally uploaded avatar
        if (isset($avatar_url)) {
            // Return it wrapped in an <img> element
            if (true === $html) {
                return apply_filters('bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . esc_attr($alt) . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
                // ...or only the URL
            } else {
                return apply_filters('bp_core_fetch_avatar_url', $avatar_url);
            }
        }
    }
    // If no avatars could be found, try to display a gravatar
    // Skips gravatar check if $no_grav is passed
    if (!apply_filters('bp_core_fetch_avatar_no_grav', $no_grav)) {
        // Set gravatar size
        if ($width) {
            $grav_size = $width;
        } else {
            if ('full' == $type) {
                $grav_size = bp_core_avatar_full_width();
            } else {
                if ('thumb' == $type) {
                    $grav_size = bp_core_avatar_thumb_width();
                }
            }
        }
        // Set gravatar type
        if (empty($bp->grav_default->{$object})) {
            $default_grav = 'wavatar';
        } else {
            if ('mystery' == $bp->grav_default->{$object}) {
                $default_grav = apply_filters('bp_core_mysteryman_src', bp_core_avatar_default(), $grav_size);
            } else {
                $default_grav = $bp->grav_default->{$object};
            }
        }
        // Set gravatar object
        if (empty($email)) {
            if ('user' == $object) {
                $email = bp_core_get_user_email($item_id);
            } else {
                if ('group' == $object || 'blog' == $object) {
                    $email = "{$item_id}-{$object}@{bp_get_root_domain()}";
                }
            }
        }
        // Set host based on if using ssl
        if (is_ssl()) {
            $host = 'https://secure.gravatar.com/avatar/';
        } else {
            $host = 'http://www.gravatar.com/avatar/';
        }
        // Filter gravatar vars
        $email = apply_filters('bp_core_gravatar_email', $email, $item_id, $object);
        $gravatar = apply_filters('bp_gravatar_url', $host) . md5(strtolower($email)) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    } else {
        // No avatar was found, and we've been told not to use a gravatar.
        $gravatar = apply_filters("bp_core_default_avatar_{$object}", BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg', $params);
    }
    if (true === $html) {
        return apply_filters('bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . esc_attr($alt) . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
    } else {
        return apply_filters('bp_core_fetch_avatar_url', $gravatar);
    }
}