Ejemplo n.º 1
0
 /**
  * Since we don't always have access to the params passed to BP_Groups_Template
  * we have to wait until after constructor has run to fill in details
  */
 function synchronize()
 {
     global $bp;
     if (isset($this->params) && array_key_exists('parent_id', $this->params)) {
         /**
          * Fill in requests by parent_id for tree traversal on admin side
          */
         $this->groups = bp_group_hierarchy_get_by_hierarchy($this->params);
         $this->total_group_count = $this->groups['total'];
         $this->groups = $this->groups['groups'];
         $this->group_count = count($this->groups);
         // Re-build pagination links with new group counts
         if ((int) $this->total_group_count && (int) $this->pag_num) {
             $this->pag_links = paginate_links(array('base' => add_query_arg(array('grpage' => '%#%', 'num' => $this->pag_num, 'sortby' => $this->sort_by, 'order' => $this->order)), 'format' => '', 'total' => ceil((int) $this->total_group_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1));
         }
     } else {
         if ($this->single_group && $bp->groups->current_group) {
             /**
              * Groups with multi-level slugs are missed by the parent.
              * Fill them in from $bp->groups->current_group
              */
             $this->groups = array((object) array('group_id' => bp_get_current_group_id()));
             $this->group_count = 1;
         }
     }
 }
 /**
  * BP_Groups_Invite_Template constructor.
  *
  * @since 1.5.0
  *
  * @param array $args
  */
 public function __construct($args = array())
 {
     // Backward compatibility with old method of passing arguments.
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '2.0.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
         $old_args_keys = array(0 => 'user_id', 1 => 'group_id');
         $func_args = func_get_args();
         $args = bp_core_parse_args_array($old_args_keys, $func_args);
     }
     $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'invitepage', 'user_id' => bp_loggedin_user_id(), 'group_id' => bp_get_current_group_id()));
     $this->pag_arg = sanitize_key($r['page_arg']);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']);
     $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']);
     $iquery = new BP_Group_Member_Query(array('group_id' => $r['group_id'], 'type' => 'first_joined', 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'is_confirmed' => false, 'inviter_id' => $r['user_id']));
     $this->invite_data = $iquery->results;
     $this->total_invite_count = $iquery->total_users;
     $this->invites = array_values(wp_list_pluck($this->invite_data, 'ID'));
     $this->invite_count = count($this->invites);
     // If per_page is set to 0 (show all results), don't generate
     // pag_links.
     if (!empty($this->pag_num)) {
         $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil($this->total_invite_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1, 'add_args' => array()));
     } else {
         $this->pag_links = '';
     }
 }
/**
 * Can the current user post to group blog
 * @global type $bp
 * @return type 
 */
function bcg_current_user_can_post()
{
    $user_id = bp_loggedin_user_id();
    $group_id = bp_get_current_group_id();
    $can_post = is_user_logged_in() && (groups_is_user_admin($user_id, $group_id) || groups_is_user_mod($user_id, $group_id));
    return apply_filters('bcg_current_user_can_post', $can_post, $group_id, $user_id);
}
 /**
  * Here you can see more customization of the config options
  */
 function __construct()
 {
     global $buddyforms, $buddyforms_user_can;
     $buddyforms_pig = get_option('buddyforms_pig_options');
     $this->post_in_group_form_slug = groups_get_groupmeta(bp_get_current_group_id(), '_bf_pig_form_slug', true);
     $this->buddyforms_pig = groups_get_groupmeta(bp_get_current_group_id(), '_buddyforms_pig', true);
     $buddyforms_user_can = false;
     //$this->enable_create_step       = false;
     $form_slug = $this->post_in_group_form_slug;
     $name = $buddyforms[$form_slug]['name'];
     if (isset($this->buddyforms_pig['create'])) {
         switch ($this->buddyforms_pig['create']) {
             case 'admin':
                 if (groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id())) {
                     $buddyforms_user_can = true;
                 }
                 break;
             case 'mod':
                 if (groups_is_user_mod(bp_loggedin_user_id(), bp_get_current_group_id()) || groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id())) {
                     $buddyforms_user_can = true;
                 }
                 break;
             case 'member':
             default:
                 if (groups_is_user_member(bp_loggedin_user_id(), bp_get_current_group_id())) {
                     $buddyforms_user_can = true;
                 }
                 break;
         }
     }
     $args = array('slug' => $form_slug, 'name' => $name);
     switch ($buddyforms_pig['permission']) {
         case 'all':
             add_action('bp_after_group_settings_admin', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1);
             add_action('groups_group_settings_edited', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1);
             add_action('bp_after_group_settings_creation_step', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1);
             add_action('groups_create_group_step_save_group-settings', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1);
             break;
         case 'group-admin':
             add_action('bp_after_group_settings_admin', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1);
             add_action('groups_group_settings_edited', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1);
             break;
         case 'admin':
             if (is_super_admin()) {
                 add_action('bp_after_group_settings_admin', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1);
                 add_action('groups_group_settings_edited', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1);
             }
             break;
     }
     parent::init($args);
 }
function bp_em_group_events_get_default_search($searches, $array)
{
    if (!empty($array['group']) && (is_numeric($array['group']) || $array['group'] == 'my' || $array['group'] == 'this') && bp_is_active('groups')) {
        if ($array['group'] == 'this') {
            //shows current group, if applicable
            if (is_numeric(bp_get_current_group_id())) {
                $searches['group'] = bp_get_current_group_id();
            }
        } else {
            $searches['group'] = $array['group'];
        }
    }
    return $searches;
}
 public function setup_nav($current_user_access)
 {
     $bp = buddypress();
     if (!bp_is_group()) {
         return;
     }
     $group_id = bp_get_current_group_id();
     if (bcg_is_disabled($group_id)) {
         return;
     }
     $current_group = groups_get_current_group();
     $group_link = bp_get_group_permalink($current_group);
     bp_core_new_subnav_item(array('name' => __('Blog', 'blog-categories-for-groups'), 'slug' => BCG_SLUG, 'parent_url' => $group_link, 'parent_slug' => $current_group->slug, 'screen_function' => array($this, 'display'), 'position' => 10, 'user_has_access' => $current_user_access, 'item_css_id' => 'blog'));
 }
 function group_activity_subscription()
 {
     $this->name = __('Email Options', 'bp-ass');
     $this->slug = 'notifications';
     // Only enable the notifications nav item if the user is a member of the group
     if (bp_is_group() && groups_is_user_member(bp_loggedin_user_id(), bp_get_current_group_id())) {
         $this->enable_nav_item = true;
     } else {
         $this->enable_nav_item = false;
     }
     $this->nav_item_position = 91;
     $this->enable_create_step = false;
     if (get_option('ass-admin-can-send-email') == 'no') {
         $this->enable_edit_item = false;
     }
     // hook in the css and js
     add_action('wp_print_styles', array(&$this, 'add_settings_stylesheet'));
     add_action('wp_enqueue_scripts', array(&$this, 'ass_add_javascript'), 1);
 }
 /**
  * Constructor method.
  *
  * @since 1.5.0
  *
  * @param array $args {
  *     @type int $group_id ID of the group whose membership requests
  *                         are being queried. Default: current group id.
  *     @type int $per_page Number of records to return per page of
  *                         results. Default: 10.
  *     @type int $page     Page of results to show. Default: 1.
  *     @type int $max      Max items to return. Default: false (show all)
  * }
  */
 public function __construct($args = array())
 {
     // Backward compatibility with old method of passing arguments.
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '2.0.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
         $old_args_keys = array(0 => 'group_id', 1 => 'per_page', 2 => 'max');
         $func_args = func_get_args();
         $args = bp_core_parse_args_array($old_args_keys, $func_args);
     }
     $r = wp_parse_args($args, array('page' => 1, 'per_page' => 10, 'page_arg' => 'mrpage', 'max' => false, 'type' => 'first_joined', 'group_id' => bp_get_current_group_id()));
     $this->pag_arg = sanitize_key($r['page_arg']);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']);
     $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']);
     $mquery = new BP_Group_Member_Query(array('group_id' => $r['group_id'], 'type' => $r['type'], 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'is_confirmed' => false, 'inviter_id' => 0));
     $this->requests = array_values($mquery->results);
     $this->request_count = count($this->requests);
     // Compatibility with legacy format of request data objects.
     foreach ($this->requests as $rk => $rv) {
         // For legacy reasons, the 'id' property of each
         // request must match the membership id, not the ID of
         // the user (as it's returned by BP_Group_Member_Query).
         $this->requests[$rk]->user_id = $rv->ID;
         $this->requests[$rk]->id = $rv->membership_id;
         // Miscellaneous values.
         $this->requests[$rk]->group_id = $r['group_id'];
     }
     if (empty($r['max']) || $r['max'] >= (int) $mquery->total_users) {
         $this->total_request_count = (int) $mquery->total_users;
     } else {
         $this->total_request_count = (int) $r['max'];
     }
     if (empty($r['max']) || $r['max'] >= count($this->requests)) {
         $this->request_count = count($this->requests);
     } else {
         $this->request_count = (int) $r['max'];
     }
     $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil($this->total_request_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1, 'add_args' => array()));
 }
function groups_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    // Set the default for hide_sitewide by checking the status of the group
    $hide_sitewide = false;
    if (!empty($args['item_id'])) {
        if (bp_get_current_group_id() == $args['item_id']) {
            $group = groups_get_current_group();
        } else {
            $group = groups_get_group(array('group_id' => $args['item_id']));
        }
        if (isset($group->status) && 'public' != $group->status) {
            $hide_sitewide = true;
        }
    }
    $defaults = array('id' => false, 'user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->groups->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $hide_sitewide);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
 /**
  * Get the group id to set its avatar.
  *
  * @since 2.3.0
  *
  * @return integer The group ID.
  */
 private function get_group_id()
 {
     $group_id = 0;
     if (bp_is_group()) {
         $group_id = bp_get_current_group_id();
     }
     return $group_id;
 }
Ejemplo n.º 11
0
 /**
  * Add custom template hierarchy to theme compat for group pages.
  *
  * This is to mirror how WordPress has
  * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
  *
  * @since 1.8.0
  *
  * @param string $templates The templates from bp_get_theme_compat_templates().
  * @return array $templates Array of custom templates to look for.
  */
 public function single_template_hierarchy($templates)
 {
     // Setup some variables we're going to reference in our custom templates.
     $group = groups_get_current_group();
     /**
      * Filters the Groups single pages template hierarchy based on priority.
      *
      * @since 1.8.0
      *
      * @param array $value Array of default template files to use.
      */
     $new_templates = apply_filters('bp_template_hierarchy_groups_single_item', array('groups/single/index-id-' . sanitize_file_name(bp_get_current_group_id()) . '.php', 'groups/single/index-slug-' . sanitize_file_name(bp_get_current_group_slug()) . '.php', 'groups/single/index-action-' . sanitize_file_name(bp_current_action()) . '.php', 'groups/single/index-status-' . sanitize_file_name($group->status) . '.php', 'groups/single/index.php'));
     // Merge new templates with existing stack.
     // @see bp_get_theme_compat_templates().
     $templates = array_merge((array) $new_templates, $templates);
     return $templates;
 }
Ejemplo n.º 12
0
function bp_cover_group_handle_upload($activity_id)
{
    global $bp, $wpdb;
    $group_id = bp_get_current_group_id();
    $activity_table = $wpdb->prefix . "bp_activity";
    $activity_meta_table = $wpdb->prefix . "bp_activity_meta";
    $sql = "SELECT COUNT(*) as photo_count FROM {$activity_table} a INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id WHERE a.item_id = %d AND meta_key = 'all_bp_cover_group'";
    $sql = $wpdb->prepare($sql, $group_id);
    $cnt = $wpdb->get_var($sql);
    $max_cnt = bp_cover_get_max_total();
    if ($cnt < $max_cnt) {
        if ($_POST['encodedimg']) {
            $file = $_POST['imgsize'];
            $max_upload_size = bp_cover_get_max_media_size();
            if ($max_upload_size > $file) {
                $group_id = $bp->groups->current_group->id;
                $imgresponse = array();
                $uploaddir = wp_upload_dir();
                /* let's decode the base64 encoded image sent */
                $img = $_POST['encodedimg'];
                $img = str_replace('data:' . $_POST['imgtype'] . ';base64,', '', $img);
                $img = str_replace(' ', '+', $img);
                $data = base64_decode($img);
                $imgname = wp_unique_filename($uploaddir['path'], $_POST['imgname']);
                $filepath = $uploaddir['path'] . '/' . $imgname;
                $fileurl = $uploaddir['url'] . '/' . $imgname;
                /* now we write the image in dir */
                $success = file_put_contents($filepath, $data);
                if ($success) {
                    $imgresponse[0] = "1";
                    $imgresponse[1] = $fileurl;
                    $size = @getimagesize($filepath);
                    $attachment = array('post_mime_type' => $_POST['imgtype'], 'guid' => $fileurl, 'post_title' => $imgname);
                    require_once ABSPATH . 'wp-admin/includes/image.php';
                    $attachment_id = wp_insert_attachment($attachment, $filepath);
                    $attach_data = wp_generate_attachment_metadata($attachment_id, $filepath);
                    wp_update_attachment_metadata($attachment_id, $attach_data);
                    groups_update_groupmeta($group_id, 'bp_cover_group', $fileurl);
                    groups_update_groupmeta($group_id, 'bp_cover_group_position', 0);
                    $group = groups_get_group(array("group_id" => $group_id));
                    $activity_id = groups_record_activity(array('action' => sprintf(__('%s uploaded a new cover picture to the group %s', 'bp-cover'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), 'type' => 'cover_added', 'item_id' => $group_id, 'content' => bp_cover_group_get_image_scr(), 'item_id' => $group_id));
                    bp_activity_update_meta($activity_id, 'all_bp_cover_group', $attachment_id);
                    update_post_meta($attachment_id, 'bp_cover_group_thumb', $imgresponse[2]);
                } else {
                    $imgresponse[0] = "0";
                    $imgresponse[1] = __('Upload Failed! Unable to write the image on server', 'bp-cover');
                }
            } else {
                $imgresponse[0] = "0";
                $imgresponse[1] = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'bp-cover'), size_format($max_upload_size));
            }
        } else {
            $imgresponse[0] = "0";
            $imgresponse[1] = __('Upload Failed! No image sent', 'bp-cover');
        }
    } else {
        $imgresponse[0] = "0";
        $imgresponse[1] = sprintf(__('Max total images allowed %d in a cover gallery', 'bp-cover'), $max_cnt);
    }
    /* if everything is ok, we send back url to thumbnail and to full image */
    echo json_encode($imgresponse);
    die;
}
Ejemplo n.º 13
0
if (bp_is_group()) {
    printf(__("What's new in %s, %s?", 'buddypress'), bp_get_group_name(), bp_get_user_firstname(bp_get_loggedin_user_fullname()));
} else {
    printf(__("What's new, %s?", 'buddypress'), bp_get_user_firstname(bp_get_loggedin_user_fullname()));
}
?>
</p>

	<div id="whats-new-content">
		<div id="whats-new-textarea">
			<textarea class="bp-suggestions" name="whats-new" id="whats-new" cols="50" rows="10"
				<?php 
if (bp_is_group()) {
    ?>
data-suggestions-group-id="<?php 
    echo esc_attr((int) bp_get_current_group_id());
    ?>
" <?php 
}
?>
			><?php 
if (isset($_GET['r'])) {
    ?>
@<?php 
    echo esc_textarea($_GET['r']);
    ?>
 <?php 
}
?>
</textarea>
		</div>
Ejemplo n.º 14
0
 /**
  * Appends the group args to rendez-vous loop arguments
  *
  * @package Rendez Vous
  * @subpackage Groups
  *
  * @since Rendez Vous (1.1.0)
  *
  * @param  array                     $args the rendez-vous loop arguments
  * @uses   bp_is_group()             to make sure the user is displaying a group
  * @uses   bp_get_current_group_id() to get the current group id
  * @return array                     the rendez-vous loop arguments
  */
 public function append_group_args($args = array())
 {
     // if in a group's single item
     if (bp_is_group()) {
         $args['group_id'] = bp_get_current_group_id();
     }
     // If viewing a single member
     if (bp_is_user()) {
         /**
          * Use this filter to show all displayed user's rendez-vous no matter if they are attached to an hidden group
          * eg: add_filter( 'rendez_vous_member_hide_hidden', '__return_false' );
          *
          * To respect the hidden group visibility, by default, a member not viewing his profile will be returned false
          * avoiding him to see the displayed member's rendez-vous attached to an hidden group
          *
          * @param bool false if a user is viewing his profile or an admin is viewing any user profile, true otherwise
          */
         $hide_hidden = apply_filters('rendez_vous_member_hide_hidden', (bool) (!bp_is_my_profile()) && !bp_current_user_can('bp_moderate'));
         if (!empty($hide_hidden)) {
             $args['exclude'] = self::get_hidden_rendez_vous();
         }
     }
     return $args;
 }
Ejemplo n.º 15
0
if (bp_displayed_user_id() == get_current_user_id()) {
    //profile personal
    $class[] = "my-profile";
}
if (bp_is_group()) {
    //single group
    $class[] = "group-single";
}
$class = implode(" ", $class);
?>

<?php 
if (bp_is_group() && !bp_is_current_action('create')) {
    // Boxed layout cover
    if (boss_get_option('boss_layout_style') == 'boxed') {
        $id = bp_get_current_group_id();
        if ($id != 0 && $id != false) {
            echo buddyboss_cover_photo("group", $id);
        }
    }
    do_action('boss_get_group_template');
    //get_template_part( 'buddypress', 'group-single' );
} else {
    if (is_post_type_archive('bp_doc') || is_single() && get_post_type() == 'bp_doc') {
        $id = boss_get_docs_group_id();
        if ($id != 0 && $id != false) {
            echo buddyboss_cover_photo("group", $id);
        }
    }
    get_template_part('buddypress', 'sidewide');
}
Ejemplo n.º 16
0
/**
 * Determine access setting for a group/user pair.
 *
 * @param int $group_id Group ID. Default: current group ID.
 * @param int $user_id User ID. Default: current user ID.
 */
function invite_anyone_group_invite_access_test($group_id = 0, $user_id = 0)
{
    global $current_user, $bp;
    if (empty($group_id)) {
        $group_id = bp_is_group() ? bp_get_current_group_id() : 0;
    }
    if (empty($group_id) && !bp_is_group_create()) {
        return 'noone';
    }
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    if (empty($user_id)) {
        return 'noone';
    }
    $iaoptions = invite_anyone_options();
    if (bp_is_group_create()) {
        if (empty($iaoptions['group_invites_can_group_admin']) || $iaoptions['group_invites_can_group_admin'] == 'anyone' || !$iaoptions['group_invites_can_group_admin']) {
            return 'anyone';
        }
        if ($iaoptions['group_invites_can_group_admin'] == 'friends') {
            return 'friends';
        }
        if ($iaoptions['group_invites_can_group_admin'] == 'noone') {
            return 'noone';
        }
    }
    if (!groups_is_user_member($user_id, $group_id)) {
        return 'noone';
    }
    if (user_can($user_id, 'bp_moderate')) {
        if (empty($iaoptions['group_invites_can_admin']) || $iaoptions['group_invites_can_admin'] == 'anyone' || !$iaoptions['group_invites_can_admin']) {
            return 'anyone';
        }
        if ($iaoptions['group_invites_can_admin'] == 'friends') {
            return 'friends';
        }
        if ($iaoptions['group_invites_can_admin'] == 'noone') {
            return 'noone';
        }
    } else {
        if (groups_is_user_admin($user_id, $group_id)) {
            if (empty($iaoptions['group_invites_can_group_admin']) || $iaoptions['group_invites_can_group_admin'] == 'anyone' || !$iaoptions['group_invites_can_group_admin']) {
                return 'anyone';
            }
            if ($iaoptions['group_invites_can_group_admin'] == 'friends') {
                return 'friends';
            }
            if ($iaoptions['group_invites_can_group_admin'] == 'noone') {
                return 'noone';
            }
        } else {
            if (groups_is_user_mod($user_id, $group_id)) {
                if (empty($iaoptions['group_invites_can_group_mod']) || $iaoptions['group_invites_can_group_mod'] == 'anyone' || !$iaoptions['group_invites_can_group_mod']) {
                    return 'anyone';
                }
                if ($iaoptions['group_invites_can_group_mod'] == 'friends') {
                    return 'friends';
                }
                if ($iaoptions['group_invites_can_group_mod'] == 'noone') {
                    return 'noone';
                }
            } else {
                if (empty($iaoptions['group_invites_can_group_member']) || $iaoptions['group_invites_can_group_member'] == 'anyone' || !$iaoptions['group_invites_can_group_member']) {
                    return 'anyone';
                }
                if ($iaoptions['group_invites_can_group_member'] == 'friends') {
                    return 'friends';
                }
                if ($iaoptions['group_invites_can_group_member'] == 'noone') {
                    return 'noone';
                }
            }
        }
    }
    return 'noone';
}
Ejemplo n.º 17
0
/**
 * Ajax Upload and set a cover image
 *
 * @since  2.4.0
 *
 * @return  string|null A json object containing success data if the upload succeeded
 *                      error message otherwise.
 */
function bp_attachments_cover_image_ajax_upload()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        wp_die();
    }
    /**
     * Sending the json response will be different if
     * the current Plupload runtime is html4
     */
    $is_html4 = false;
    if (!empty($_POST['html4'])) {
        $is_html4 = true;
    }
    // Check the nonce
    check_admin_referer('bp-uploader');
    // Init the BuddyPress parameters
    $bp_params = array();
    // We need it to carry on
    if (!empty($_POST['bp_params'])) {
        $bp_params = bp_parse_args($_POST['bp_params'], array('object' => 'user', 'item_id' => bp_loggedin_user_id()), 'attachments_cover_image_ajax_upload');
    } else {
        bp_attachments_json_response(false, $is_html4);
    }
    // We need the object to set the uploads dir filter
    if (empty($bp_params['object'])) {
        bp_attachments_json_response(false, $is_html4);
    }
    // Capability check
    if (!bp_attachments_current_user_can('edit_cover_image', $bp_params)) {
        bp_attachments_json_response(false, $is_html4);
    }
    $bp = buddypress();
    $needs_reset = array();
    // Member's cover image
    if ('user' === $bp_params['object']) {
        $object_data = array('dir' => 'members', 'component' => 'xprofile');
        if (!bp_displayed_user_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('key' => 'displayed_user', 'value' => $bp->displayed_user);
            $bp->displayed_user->id = $bp_params['item_id'];
        }
        // Group's cover image
    } elseif ('group' === $bp_params['object']) {
        $object_data = array('dir' => 'groups', 'component' => 'groups');
        if (!bp_get_current_group_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group);
            $bp->groups->current_group = groups_get_group(array('group_id' => $bp_params['item_id'], 'populate_extras' => false));
        }
        // Other object's cover image
    } else {
        $object_data = apply_filters('bp_attachments_cover_image_object_dir', array(), $bp_params['object']);
    }
    // Stop here in case of a missing parameter for the object
    if (empty($object_data['dir']) || empty($object_data['component'])) {
        bp_attachments_json_response(false, $is_html4);
    }
    $cover_image_attachment = new BP_Attachment_Cover_Image();
    $uploaded = $cover_image_attachment->upload($_FILES);
    // Reset objects
    if (!empty($needs_reset)) {
        if (!empty($needs_reset['component'])) {
            $bp->{$needs_reset['component']}->{$needs_reset['key']} = $needs_reset['value'];
        } else {
            $bp->{$needs_reset['key']} = $needs_reset['value'];
        }
    }
    if (!empty($uploaded['error'])) {
        // Upload error response
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $uploaded['error'])));
    }
    // Default error message
    $error_message = __('There was a problem uploading the cover image.', 'buddypress');
    // Get BuddyPress Attachments Uploads Dir datas
    $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
    // The BP Attachments Uploads Dir is not set, stop.
    if (!$bp_attachments_uploads_dir) {
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $error_message));
    }
    $cover_subdir = $object_data['dir'] . '/' . $bp_params['item_id'] . '/cover-image';
    $cover_dir = trailingslashit($bp_attachments_uploads_dir['basedir']) . $cover_subdir;
    if (!is_dir($cover_dir)) {
        // Upload error response
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $error_message));
    }
    /**
     * Generate the cover image so that it fit to feature's dimensions
     *
     * Unlike the Avatar, Uploading and generating the cover image is happening during
     * the same Ajax request, as we already instantiated the BP_Attachment_Cover_Image
     * class, let's use it.
     */
    $cover = bp_attachments_cover_image_generate_file(array('file' => $uploaded['file'], 'component' => $object_data['component'], 'cover_image_dir' => $cover_dir), $cover_image_attachment);
    if (!$cover) {
        // Upload error response
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $error_message));
    }
    // Build the url to the file
    $cover_url = trailingslashit($bp_attachments_uploads_dir['baseurl']) . $cover_subdir . '/' . $cover['cover_basename'];
    // Init Feedback code, 1 is success
    $feedback_code = 1;
    // 0 is the size warning
    if ($cover['is_too_small']) {
        $feedback_code = 0;
    }
    // Set the name of the file
    $name = $_FILES['file']['name'];
    $name_parts = pathinfo($name);
    $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
    /**
     * Fires if the new cover image was successfully uploaded.
     *
     * The dynamic portion of the hook will be xprofile in case of a user's
     * cover image, groups in case of a group's cover image. For instance:
     * Use add_action( 'xprofile_cover_image_uploaded' ) to run your specific
     * code once the user has set his cover image.
     *
     * @since 2.4.0
     *
     * @param int $item_id Inform about the item id the cover image was set for.
     */
    do_action($object_data['component'] . '_cover_image_uploaded', (int) $bp_params['item_id']);
    // Finally return the cover image url to the UI
    bp_attachments_json_response(true, $is_html4, array('name' => $name, 'url' => $cover_url, 'feedback_code' => $feedback_code));
}
/**
 * Customize the body class, according to the currently displayed BP content.
 *
 * Uses the above is_() functions to output a body class for each scenario.
 *
 * @since 1.1.0
 *
 * @param array      $wp_classes     The body classes coming from WP.
 * @param array|bool $custom_classes Classes that were passed to get_body_class().
 * @return array $classes The BP-adjusted body classes.
 */
function bp_get_the_body_class($wp_classes = array(), $custom_classes = false)
{
    $bp_classes = array();
    /* Pages *************************************************************/
    if (is_front_page()) {
        $bp_classes[] = 'home-page';
    }
    if (bp_is_directory()) {
        $bp_classes[] = 'directory';
    }
    if (bp_is_single_item()) {
        $bp_classes[] = 'single-item';
    }
    /* Components ********************************************************/
    if (!bp_is_blog_page()) {
        if (bp_is_user_profile()) {
            $bp_classes[] = 'xprofile';
        }
        if (bp_is_activity_component()) {
            $bp_classes[] = 'activity';
        }
        if (bp_is_blogs_component()) {
            $bp_classes[] = 'blogs';
        }
        if (bp_is_messages_component()) {
            $bp_classes[] = 'messages';
        }
        if (bp_is_friends_component()) {
            $bp_classes[] = 'friends';
        }
        if (bp_is_groups_component()) {
            $bp_classes[] = 'groups';
        }
        if (bp_is_settings_component()) {
            $bp_classes[] = 'settings';
        }
    }
    /* User **************************************************************/
    if (bp_is_user()) {
        $bp_classes[] = 'bp-user';
        // Add current user member types.
        if ($member_types = bp_get_member_type(bp_displayed_user_id(), false)) {
            foreach ($member_types as $member_type) {
                $bp_classes[] = sprintf('member-type-%s', esc_attr($member_type));
            }
        }
    }
    if (!bp_is_directory()) {
        if (bp_is_user_blogs()) {
            $bp_classes[] = 'my-blogs';
        }
        if (bp_is_user_groups()) {
            $bp_classes[] = 'my-groups';
        }
        if (bp_is_user_activity()) {
            $bp_classes[] = 'my-activity';
        }
    } else {
        if (bp_get_current_member_type()) {
            $bp_classes[] = 'type';
        }
    }
    if (bp_is_my_profile()) {
        $bp_classes[] = 'my-account';
    }
    if (bp_is_user_profile()) {
        $bp_classes[] = 'my-profile';
    }
    if (bp_is_user_friends()) {
        $bp_classes[] = 'my-friends';
    }
    if (bp_is_user_messages()) {
        $bp_classes[] = 'my-messages';
    }
    if (bp_is_user_recent_commments()) {
        $bp_classes[] = 'recent-comments';
    }
    if (bp_is_user_recent_posts()) {
        $bp_classes[] = 'recent-posts';
    }
    if (bp_is_user_change_avatar()) {
        $bp_classes[] = 'change-avatar';
    }
    if (bp_is_user_profile_edit()) {
        $bp_classes[] = 'profile-edit';
    }
    if (bp_is_user_friends_activity()) {
        $bp_classes[] = 'friends-activity';
    }
    if (bp_is_user_groups_activity()) {
        $bp_classes[] = 'groups-activity';
    }
    /* Messages **********************************************************/
    if (bp_is_messages_inbox()) {
        $bp_classes[] = 'inbox';
    }
    if (bp_is_messages_sentbox()) {
        $bp_classes[] = 'sentbox';
    }
    if (bp_is_messages_compose_screen()) {
        $bp_classes[] = 'compose';
    }
    if (bp_is_notices()) {
        $bp_classes[] = 'notices';
    }
    if (bp_is_user_friend_requests()) {
        $bp_classes[] = 'friend-requests';
    }
    if (bp_is_create_blog()) {
        $bp_classes[] = 'create-blog';
    }
    /* Groups ************************************************************/
    if (bp_is_group()) {
        $bp_classes[] = 'group-' . groups_get_current_group()->slug;
        // Add current group types.
        if ($group_types = bp_groups_get_group_type(bp_get_current_group_id(), false)) {
            foreach ($group_types as $group_type) {
                $bp_classes[] = sprintf('group-type-%s', esc_attr($group_type));
            }
        }
    }
    if (bp_is_group_leave()) {
        $bp_classes[] = 'leave-group';
    }
    if (bp_is_group_invites()) {
        $bp_classes[] = 'group-invites';
    }
    if (bp_is_group_members()) {
        $bp_classes[] = 'group-members';
    }
    if (bp_is_group_forum_topic()) {
        $bp_classes[] = 'group-forum-topic';
    }
    if (bp_is_group_forum_topic_edit()) {
        $bp_classes[] = 'group-forum-topic-edit';
    }
    if (bp_is_group_forum()) {
        $bp_classes[] = 'group-forum';
    }
    if (bp_is_group_admin_page()) {
        $bp_classes[] = 'group-admin';
        $bp_classes[] = bp_get_group_current_admin_tab();
    }
    if (bp_is_group_create()) {
        $bp_classes[] = 'group-create';
        $bp_classes[] = bp_get_groups_current_create_step();
    }
    if (bp_is_group_home()) {
        $bp_classes[] = 'group-home';
    }
    if (bp_is_single_activity()) {
        $bp_classes[] = 'activity-permalink';
    }
    /* Registration ******************************************************/
    if (bp_is_register_page()) {
        $bp_classes[] = 'registration';
    }
    if (bp_is_activation_page()) {
        $bp_classes[] = 'activation';
    }
    /* Current Component & Action ****************************************/
    if (!bp_is_blog_page()) {
        $bp_classes[] = bp_current_component();
        $bp_classes[] = bp_current_action();
    }
    /* Clean up ***********************************************************/
    // Add BuddyPress class if we are within a BuddyPress page.
    if (!bp_is_blog_page()) {
        $bp_classes[] = 'buddypress';
    }
    // Merge WP classes with BuddyPress classes and remove any duplicates.
    $classes = array_unique(array_merge((array) $bp_classes, (array) $wp_classes));
    /**
     * Filters the BuddyPress classes to be added to body_class()
     *
     * @since 1.1.0
     *
     * @param array $classes        Array of body classes to add.
     * @param array $bp_classes     Array of BuddyPress-based classes.
     * @param array $wp_classes     Array of WordPress-based classes.
     * @param array $custom_classes Array of classes that were passed to get_body_class().
     */
    return apply_filters('bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes);
}
 /**
  * Build script datas for the Uploader UI
  *
  * @since 2.4.0
  *
  * @return array the javascript localization data
  */
 public function script_data()
 {
     // Get default script data
     $script_data = parent::script_data();
     if (bp_is_user()) {
         $item_id = bp_displayed_user_id();
         $script_data['bp_params'] = array('object' => 'user', 'item_id' => $item_id, 'has_cover_image' => bp_attachments_get_user_has_cover_image($item_id), 'nonces' => array('remove' => wp_create_nonce('bp_delete_cover_image')));
         // Set feedback messages
         $script_data['feedback_messages'] = array(1 => __('Your new cover image was uploaded successfully.', 'buddypress'), 2 => __('There was a problem deleting your cover image. Please try again.', 'buddypress'), 3 => __('Your cover image was deleted successfully!', 'buddypress'));
     } elseif (bp_is_group()) {
         $item_id = bp_get_current_group_id();
         $script_data['bp_params'] = array('object' => 'group', 'item_id' => bp_get_current_group_id(), 'has_cover_image' => bp_attachments_get_group_has_cover_image($item_id), 'nonces' => array('remove' => wp_create_nonce('bp_delete_cover_image')));
         // Set feedback messages
         $script_data['feedback_messages'] = array(1 => __('The group cover image was uploaded successfully.', 'buddypress'), 2 => __('There was a problem deleting the group cover image. Please try again.', 'buddypress'), 3 => __('The group cover image was deleted successfully!', 'buddypress'));
     } else {
         /**
          * Use this filter to include specific BuddyPress params for your object.
          * e.g. Cover image for blogs single item.
          *
          * @since 2.4.0
          *
          * @param array $value The cover image specific BuddyPress parameters.
          */
         $script_data['bp_params'] = apply_filters('bp_attachment_cover_image_params', array());
     }
     // Include our specific js & css
     $script_data['extra_js'] = array('bp-cover-image');
     $script_data['extra_css'] = array('bp-avatar');
     return apply_filters('bp_attachments_cover_image_script_data', $script_data);
 }
 /**
  * Save method for our extension during edits.
  *
  * @param int $group_id The group ID.
  */
 public function edit_screen_save($group_id = null)
 {
     if (!isset($_POST['save'])) {
         return false;
     }
     check_admin_referer('groups_edit_save_' . $this->slug);
     $existing_feeds = (array) groups_get_groupmeta(bp_get_current_group_id(), 'blogfeeds');
     $unfiltered_feeds = explode(',', $_POST['blogfeeds']);
     $blog_feeds = array();
     foreach ((array) $unfiltered_feeds as $blog_feed) {
         if (!empty($blog_feed)) {
             $blog_feeds[] = esc_url_raw(trim($blog_feed));
         }
     }
     /* Loop and find any feeds that have been removed, so we can delete activity stream items */
     if (!empty($existing_feeds)) {
         foreach ((array) $existing_feeds as $feed) {
             if (!in_array($feed, (array) $blog_feeds)) {
                 $removed[] = $feed;
             }
         }
     }
     if ($removed) {
         foreach ((array) $removed as $feed) {
             $existing = bp_activity_get(array('user_id' => false, 'component' => 'groups', 'type' => 'exb', 'item_id' => bp_get_current_group_id(), 'update_meta_cache' => false, 'display_comments' => false, 'meta_query' => array(array('key' => 'exb_feedurl', 'value' => trim($feed)))));
             // only delete items matching the feed
             if (!empty($existing['activities'])) {
                 $aids = wp_list_pluck($existing['activities'], 'id');
                 foreach ($aids as $aid) {
                     bp_activity_delete(array('id' => $aid));
                 }
                 // old way - delete all feed items matching the group
             } else {
                 bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'component' => 'groups', 'type' => 'exb'));
             }
         }
     }
     groups_update_groupmeta(bp_get_current_group_id(), 'fetchtime', $_POST['fetch-time']);
     groups_update_groupmeta(bp_get_current_group_id(), 'blogfeeds', $blog_feeds);
     groups_update_groupmeta(bp_get_current_group_id(), 'bp_groupblogs_lastupdate', gmdate("Y-m-d H:i:s"));
     /* Re-fetch */
     bp_groupblogs_fetch_group_feeds(bp_get_current_group_id());
     bp_core_add_message(__('External blog feeds updated successfully!', 'bp-groups-externalblogs'));
     bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . '/admin/' . $this->slug);
 }
Ejemplo n.º 21
0
 /**
  * Add custom template hierarchy to theme compat for group pages.
  *
  * This is to mirror how WordPress has
  * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
  *
  * @since BuddyPress (1.8.0)
  *
  * @param string $templates The templates from bp_get_theme_compat_templates().
  * @return array $templates Array of custom templates to look for.
  */
 public function single_template_hierarchy($templates)
 {
     // Setup some variables we're going to reference in our custom templates
     $group = groups_get_current_group();
     // Setup our templates based on priority
     $new_templates = apply_filters('bp_template_hierarchy_groups_single_item', array('groups/single/index-id-' . sanitize_file_name(bp_get_current_group_id()) . '.php', 'groups/single/index-slug-' . sanitize_file_name(bp_get_current_group_slug()) . '.php', 'groups/single/index-action-' . sanitize_file_name(bp_current_action()) . '.php', 'groups/single/index-status-' . sanitize_file_name($group->status) . '.php', 'groups/single/index.php'));
     // Merge new templates with existing stack
     // @see bp_get_theme_compat_templates()
     $templates = array_merge((array) $new_templates, $templates);
     return $templates;
 }
 private function current_user_can_modify_settings($group_id = false)
 {
     if (!$group_id) {
         $group_id = bp_get_current_group_id();
     }
     if (is_super_admin() || groups_is_user_admin(get_current_user_id(), $group_id)) {
         return true;
     }
     return false;
 }
Ejemplo n.º 23
0
/**
 * Delete a group forum post and its corresponding activity item.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int      $post_id  The ID of the post you want to delete.
 * @param int|bool $topic_id Optional. The topic to which the post belongs. This
 *                           value isn't used in the function but is passed along
 *                           to do_action() hooks.
 *
 * @return bool True on success.
 */
function groups_delete_group_forum_post($post_id, $topic_id = false)
{
    $action = bp_forums_delete_post(array('post_id' => $post_id));
    if (!empty($action)) {
        /**
         * Fires before the deletion of a group forum post.
         *
         * @since BuddyPress (1.5.0)
         *
         * @param int $post_id  ID of the post to be deleted.
         * @param int $topic_id ID of the associated topic.
         */
        do_action('groups_before_delete_group_forum_post', $post_id, $topic_id);
        // Delete the corresponding activity stream item
        if (bp_is_active('activity')) {
            bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id, 'component' => buddypress()->groups->id, 'type' => 'new_forum_post'));
        }
        /**
         * Fires after the deletion of a group forum post.
         *
         * @since BuddyPress (1.1.0)
         *
         * @param int $post_id  ID of the post that was deleted.
         * @param int $topic_id ID of the associated topic.
         */
        do_action('groups_delete_group_forum_post', $post_id, $topic_id);
    }
    return (bool) $action;
}
Ejemplo n.º 24
0
/**
 * Ajax upload an avatar.
 *
 * @since 2.3.0
 *
 * @return  string|null A json object containing success data if the upload succeeded
 *                      error message otherwise.
 */
function bp_avatar_ajax_upload()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        wp_die();
    }
    /**
     * Sending the json response will be different if
     * the current Plupload runtime is html4
     */
    $is_html4 = false;
    if (!empty($_POST['html4'])) {
        $is_html4 = true;
    }
    // Check the nonce
    check_admin_referer('bp-uploader');
    // Init the BuddyPress parameters
    $bp_params = array();
    // We need it to carry on
    if (!empty($_POST['bp_params'])) {
        $bp_params = $_POST['bp_params'];
    } else {
        bp_attachments_json_response(false, $is_html4);
    }
    // We need the object to set the uploads dir filter
    if (empty($bp_params['object'])) {
        bp_attachments_json_response(false, $is_html4);
    }
    // Capability check
    if (!bp_attachments_current_user_can('edit_avatar', $bp_params)) {
        bp_attachments_json_response(false, $is_html4);
    }
    $bp = buddypress();
    $bp_params['upload_dir_filter'] = '';
    $needs_reset = array();
    if ('user' === $bp_params['object'] && bp_is_active('xprofile')) {
        $bp_params['upload_dir_filter'] = 'xprofile_avatar_upload_dir';
        if (!bp_displayed_user_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('key' => 'displayed_user', 'value' => $bp->displayed_user);
            $bp->displayed_user->id = $bp_params['item_id'];
        }
    } elseif ('group' === $bp_params['object'] && bp_is_active('groups')) {
        $bp_params['upload_dir_filter'] = 'groups_avatar_upload_dir';
        if (!bp_get_current_group_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group);
            $bp->groups->current_group = groups_get_group(array('group_id' => $bp_params['item_id'], 'populate_extras' => false));
        }
    } else {
        /**
         * Filter here to deal with other components.
         *
         * @since 2.3.0
         *
         * @var array $bp_params the BuddyPress Ajax parameters.
         */
        $bp_params = apply_filters('bp_core_avatar_ajax_upload_params', $bp_params);
    }
    if (!isset($bp->avatar_admin)) {
        $bp->avatar_admin = new stdClass();
    }
    /**
     * The BuddyPress upload parameters is including the Avatar UI Available width,
     * add it to the avatar_admin global for a later use.
     */
    if (isset($bp_params['ui_available_width'])) {
        $bp->avatar_admin->ui_available_width = (int) $bp_params['ui_available_width'];
    }
    // Upload the avatar
    $avatar = bp_core_avatar_handle_upload($_FILES, $bp_params['upload_dir_filter']);
    // Reset objects
    if (!empty($needs_reset)) {
        if (!empty($needs_reset['component'])) {
            $bp->{$needs_reset['component']}->{$needs_reset['key']} = $needs_reset['value'];
        } else {
            $bp->{$needs_reset['key']} = $needs_reset['value'];
        }
    }
    // Init the feedback message
    $feedback_message = false;
    if (!empty($bp->template_message)) {
        $feedback_message = $bp->template_message;
        // Remove template message.
        $bp->template_message = false;
        $bp->template_message_type = false;
        @setcookie('bp-message', false, time() - 1000, COOKIEPATH);
        @setcookie('bp-message-type', false, time() - 1000, COOKIEPATH);
    }
    if (empty($avatar)) {
        // Default upload error
        $message = __('Upload failed.', 'buddypress');
        // Use the template message if set
        if (!empty($feedback_message)) {
            $message = $feedback_message;
        }
        // Upload error reply
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $message));
    }
    if (empty($bp->avatar_admin->image->file)) {
        bp_attachments_json_response(false, $is_html4);
    }
    $uploaded_image = @getimagesize($bp->avatar_admin->image->file);
    // Set the name of the file
    $name = $_FILES['file']['name'];
    $name_parts = pathinfo($name);
    $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
    // Finally return the avatar to the editor
    bp_attachments_json_response(true, $is_html4, array('name' => $name, 'url' => $bp->avatar_admin->image->url, 'width' => $uploaded_image[0], 'height' => $uploaded_image[1], 'feedback' => $feedback_message));
}
/**
 * Echoes the output of bp_get_current_group_id().
 *
 * @since 1.5.0
 */
function bp_current_group_id()
{
    echo bp_get_current_group_id();
}
Ejemplo n.º 26
0
    function widget($args, $instance)
    {
        global $bp;
        $instance['group_id'] = bp_get_current_group_id();
        if ($instance['group_id'] > 0) {
            $group = $bp->groups->current_group;
            // If the group  public, or the user is super_admin or the user is member of group
            if ($group->status == 'public' || is_super_admin() || groups_is_user_member(bp_loggedin_user_id(), $group_id)) {
                extract($args);
                $title = apply_filters('widget_title', empty($instance['title']) ? sprintf(__('Recent %s for the group', 'bp-group-documents'), $this->bp_group_documents_name) : sanitize_text_field($instance['title']));
                echo $before_widget . $before_title . $title . $after_title;
                do_action('bp_group_documents_current_group_widget_before_html');
                $document_list = BP_Group_Documents::get_list_for_newest_widget(absint($instance['num_items']), $instance['group_id'], (bool) $instance['featured']);
                if ($document_list && count($document_list) >= 1) {
                    echo '<ul id="bp-group-documents-current-group" class="bp-group-documents-list">';
                    foreach ($document_list as $item) {
                        $document = new BP_Group_Documents($item['id']);
                        echo '<li>';
                        if (get_option('bp_group_documents_display_icons')) {
                            $document->icon();
                        }
                        ?>
                                                <a class="bp-group-documents-title" id="group-document-link-<?php 
                        echo $document->id;
                        ?>
" href="<?php 
                        $document->url();
                        ?>
" target="_blank"><?php 
                        echo esc_html($document->name);
                        ?>

                                                    <?php 
                        if (get_option('bp_group_documents_display_file_size')) {
                            echo ' <span class="group-documents-filesize">(' . get_file_size($document) . ')</span>';
                        }
                        ?>
</a> &nbsp;<div class="bp-group-documents-meta">
                                                    <?php 
                        $document->categories();
                        printf(__('Uploaded by %s on %s', 'bp-group-documents'), bp_core_get_userlink($document->user_id), date_i18n(get_option('date_format'), $document->created_ts));
                        ?>
                                                    <?php 
                        echo '</li>';
                    }
                    echo '</ul>';
                } else {
                    echo '<div class="widget-error">' . sprintf(__('There are no %s to display.', 'bp-group-documents'), $this->bp_group_documents_name) . '</div></p>';
                }
                echo '<div class="view-all"><a href="' . bp_get_group_permalink($bp->groups->current_group) . BP_GROUP_DOCUMENTS_SLUG . '#object-nav">' . __("View all", 'bp-group-documents') . '</a></div>';
                echo $after_widget;
            }
        }
    }
Ejemplo n.º 27
0
/**
 * Initiate the loop for a single topic's posts.
 *
 * @param array $args {
 *     Arguments for limiting the contents of the topic posts loop.
 *     @type int $topic_id ID of the topic to which the posts belong.
 *     @type int $per_page Number of items to return per page. Default: 15.
 *     @type int $max Max items to return. Default: false.
 *     @type string $order 'ASC' or 'DESC'.
 * }
 * @return bool True when posts are found corresponding to the args,
 *         otherwise false.
 */
function bp_has_forum_topic_posts($args = '')
{
    global $topic_template;
    $defaults = array('topic_id' => false, 'per_page' => 15, 'max' => false, 'order' => 'ASC');
    $r = bp_parse_args($args, $defaults, 'has_forum_topic_posts');
    extract($r, EXTR_SKIP);
    if (empty($topic_id) && bp_is_groups_component() && bp_is_current_action('forum') && bp_is_action_variable('topic', 0) && bp_action_variable(1)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(1));
    } elseif (empty($topic_id) && bp_is_forums_component() && bp_is_current_action('topic') && bp_action_variable(0)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(0));
    }
    if (empty($topic_id)) {
        return false;
    } else {
        $topic_template = new BP_Forums_Template_Topic((int) $topic_id, $per_page, $max, $order);
        // Current topic forum_id needs to match current_group forum_id
        if (bp_is_groups_component() && $topic_template->forum_id != groups_get_groupmeta(bp_get_current_group_id(), 'forum_id')) {
            return false;
        }
    }
    return apply_filters('bp_has_topic_posts', $topic_template->has_posts(), $topic_template);
}
Ejemplo n.º 28
0
/**
 * Various checks to see if a user can remove an item from a group
 *
 * @param  int $group_id the group id
 * @uses bp_get_current_group_id() to get current group id
 * @uses buddydrive_is_group() to check we're on a group's BuddyDrive
 * @uses buddydrive_get_parent_item_id() to get parent item
 * @uses groups_is_user_admin() to check if the current user is admin of the group
 * @uses bp_loggedin_user_id() to get current user id
 * @uses is_super_admin() to give power to admin !
 * @return boolean $can_remove
 */
function buddydrive_current_user_can_remove($group_id = false)
{
    $can_remove = false;
    if (empty($group_id)) {
        $group_id = bp_get_current_group_id();
    }
    if (!buddydrive_is_group() || buddydrive_get_parent_item_id()) {
        $can_remove = false;
    } else {
        if (groups_is_user_admin(bp_loggedin_user_id(), $group_id)) {
            $can_remove = true;
        } else {
            if (is_super_admin()) {
                $can_remove = true;
            }
        }
    }
    return apply_filters('buddydrive_current_user_can_remove', $can_remove);
}
Ejemplo n.º 29
0
/**
 * Generate the avatar upload directory path for a given group.
 *
 * @param int $group_id Optional. ID of the group. Default: ID of the
 *                      current group.
 * @return string
 */
function groups_avatar_upload_dir($group_id = 0)
{
    if (empty($group_id)) {
        $group_id = bp_get_current_group_id();
    }
    $directory = 'group-avatars';
    $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $group_id;
    $newbdir = $path;
    $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $group_id;
    $newburl = $newurl;
    $newsubdir = '/' . $directory . '/' . $group_id;
    /**
     * Filters the avatar upload directory path for a given group.
     *
     * @since 1.1.0
     *
     * @param array $value Array of parts related to the groups avatar upload directory.
     */
    return apply_filters('groups_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false));
}
 function get_create_link($link)
 {
     $slug = bp_get_current_group_slug();
     if ($slug && current_user_can('bp_docs_associate_with_group', bp_get_current_group_id())) {
         $link = add_query_arg('group', $slug, $link);
     }
     return $link;
 }