Example #1
0
 function bp_group_reviews_extension()
 {
     global $bp;
     $this->group_id = BP_Groups_Group::group_exists($bp->current_item);
     $this->name = __('Reviews', 'bpgr');
     $this->slug = $bp->group_reviews->slug;
     $this->nav_item_position = 22;
     $this->enable_create_step = false;
     $this->enable_nav_item = BP_Group_Reviews::current_group_is_available();
     $this->enable_edit_item = false;
     if (isset($_POST['review_submit'])) {
         check_admin_referer('review_submit');
         $has_posted = '';
         if (empty($_POST['review_content']) || !(int) $_POST['rating']) {
             // Something has gone wrong. Save the user's submitted data to reinsert into the post box after redirect
             $cookie_data = array('review_content' => $_POST['review_content'], 'rating' => $_POST['rating']);
             $cookie = json_encode($cookie_data);
             setcookie('bpgr-data', $cookie, time() + 60 * 60 * 24, COOKIEPATH);
             bp_core_add_message(__("Please make sure you fill in the review, and don't forget to provide a rating!", 'bpgr'), 'error');
         } else {
             /* Auto join this user if they are not yet a member of this group */
             if (!is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member($bp->loggedin_user->id, $bp->groups->current_group->id)) {
                 groups_join_group($bp->groups->current_group->id, $bp->loggedin_user->id);
             }
             if ($rating_id = $this->post_review(array('content' => $_POST['review_content'], 'rating' => (int) $_POST['rating']))) {
                 bp_core_add_message("Your review was posted successfully!");
                 $has_posted = groups_get_groupmeta($bp->groups->current_group->id, 'posted_review');
                 if (!in_array((int) $bp->loggedin_user->id, (array) $has_posted)) {
                     $has_posted[] = (int) $bp->loggedin_user->id;
                 }
                 groups_update_groupmeta($bp->groups->current_group->id, 'posted_review', $has_posted);
                 if ((int) $_POST['rating'] < 0) {
                     $_POST['rating'] = 1;
                 }
                 if ((int) $_POST['rating'] > 5) {
                     $_POST['rating'] = 5;
                 }
             } else {
                 bp_core_add_message("There was a problem posting your review, please try again.", 'error');
             }
         }
         bp_core_redirect(apply_filters('bpgr_after_post_redirect', trailingslashit(bp_get_group_permalink($bp->groups->current_group) . $this->slug, $has_posted)));
     }
 }
 function get_id_from_slug($slug)
 {
     return BP_Groups_Group::group_exists($slug);
 }
/**
 * Get a group ID by its slug.
 *
 * @since 1.6.0
 *
 * @param string $group_slug The group's slug.
 *
 * @return int The ID.
 */
function groups_get_id($group_slug)
{
    return (int) BP_Groups_Group::group_exists($group_slug);
}
 /**
  * Set up component global data.
  *
  * The BP_GROUPS_SLUG constant is deprecated, and only used here for
  * backwards compatibility.
  *
  * @since 1.5.0
  *
  * @see BP_Component::setup_globals() for a description of arguments.
  *
  * @param array $args See BP_Component::setup_globals() for a description.
  */
 public function setup_globals($args = array())
 {
     $bp = buddypress();
     // Define a slug, if necessary.
     if (!defined('BP_GROUPS_SLUG')) {
         define('BP_GROUPS_SLUG', $this->id);
     }
     // Global tables for groups component.
     $global_tables = array('table_name' => $bp->table_prefix . 'bp_groups', 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta');
     // Metadata tables for groups component.
     $meta_tables = array('group' => $bp->table_prefix . 'bp_groups_groupmeta');
     // All globals for groups component.
     // Note that global_tables is included in this array.
     $args = array('slug' => BP_GROUPS_SLUG, 'root_slug' => isset($bp->pages->groups->slug) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'directory_title' => _x('Groups', 'component directory title', 'buddypress'), 'notification_callback' => 'groups_format_notifications', 'search_string' => _x('Search Groups...', 'Component directory search', 'buddypress'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables);
     parent::setup_globals($args);
     /* Single Group Globals **********************************************/
     // Are we viewing a single group?
     if (bp_is_groups_component() && ($group_id = BP_Groups_Group::group_exists(bp_current_action()))) {
         $bp->is_single_item = true;
         /**
          * Filters the current PHP Class being used.
          *
          * @since 1.5.0
          *
          * @param string $value Name of the class being used.
          */
         $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Group');
         if ($current_group_class == 'BP_Groups_Group') {
             $this->current_group = groups_get_group(array('group_id' => $group_id, 'populate_extras' => true));
         } else {
             /**
              * Filters the current group object being instantiated from previous filter.
              *
              * @since 1.5.0
              *
              * @param object $value Newly instantiated object for the group.
              */
             $this->current_group = apply_filters('bp_groups_current_group_object', new $current_group_class($group_id));
         }
         // When in a single group, the first action is bumped down one because of the
         // group name, so we need to adjust this and set the group name to current_item.
         $bp->current_item = bp_current_action();
         $bp->current_action = bp_action_variable(0);
         array_shift($bp->action_variables);
         // Using "item" not "group" for generic support in other components.
         if (bp_current_user_can('bp_moderate')) {
             bp_update_is_item_admin(true, 'groups');
         } else {
             bp_update_is_item_admin(groups_is_user_admin(bp_loggedin_user_id(), $this->current_group->id), 'groups');
         }
         // If the user is not an admin, check if they are a moderator.
         if (!bp_is_item_admin()) {
             bp_update_is_item_mod(groups_is_user_mod(bp_loggedin_user_id(), $this->current_group->id), 'groups');
         }
         // Is the logged in user a member of the group?
         if (is_user_logged_in() && groups_is_user_member(bp_loggedin_user_id(), $this->current_group->id)) {
             $this->current_group->is_user_member = true;
         } else {
             $this->current_group->is_user_member = false;
         }
         // Should this group be visible to the logged in user?
         if ('public' == $this->current_group->status || $this->current_group->is_user_member) {
             $this->current_group->is_visible = true;
         } else {
             $this->current_group->is_visible = false;
         }
         // If this is a private or hidden group, does the user have access?
         if ('private' == $this->current_group->status || 'hidden' == $this->current_group->status) {
             if ($this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can('bp_moderate')) {
                 $this->current_group->user_has_access = true;
             } else {
                 $this->current_group->user_has_access = false;
             }
         } else {
             $this->current_group->user_has_access = true;
         }
         // Check once if the current group has a custom front template.
         $this->current_group->front_template = bp_groups_get_front_template($this->current_group);
         // Set current_group to 0 to prevent debug errors.
     } else {
         $this->current_group = 0;
     }
     /**
      * Filters the list of illegal groups names/slugs.
      *
      * @since 1.0.0
      *
      * @param array $value Array of illegal group names/slugs.
      */
     $this->forbidden_names = apply_filters('groups_forbidden_names', array('my-groups', 'create', 'invites', 'send-invites', 'forum', 'delete', 'add', 'admin', 'request-membership', 'members', 'settings', 'avatar', $this->slug, $this->root_slug));
     // If the user was attempting to access a group, but no group by that name was found, 404.
     if (bp_is_groups_component() && empty($this->current_group) && bp_current_action() && !in_array(bp_current_action(), $this->forbidden_names)) {
         bp_do_404();
         return;
     }
     /**
      * Filters the preconfigured groups creation steps.
      *
      * @since 1.1.0
      *
      * @param array $value Array of preconfigured group creation steps.
      */
     $this->group_creation_steps = apply_filters('groups_create_group_steps', array('group-details' => array('name' => _x('Details', 'Group screen nav', 'buddypress'), 'position' => 0), 'group-settings' => array('name' => _x('Settings', 'Group screen nav', 'buddypress'), 'position' => 10)));
     // If avatar uploads are not disabled, add avatar option.
     $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads();
     if (!$disabled_avatar_uploads && $bp->avatar->show_avatars) {
         $this->group_creation_steps['group-avatar'] = array('name' => _x('Photo', 'Group screen nav', 'buddypress'), 'position' => 20);
     }
     if (bp_group_use_cover_image_header()) {
         $this->group_creation_steps['group-cover-image'] = array('name' => _x('Cover Image', 'Group screen nav', 'buddypress'), 'position' => 25);
     }
     // If friends component is active, add invitations.
     if (bp_is_active('friends')) {
         $this->group_creation_steps['group-invites'] = array('name' => _x('Invites', 'Group screen nav', 'buddypress'), 'position' => 30);
     }
     /**
      * Filters the list of valid groups statuses.
      *
      * @since 1.1.0
      *
      * @param array $value Array of valid group statuses.
      */
     $this->valid_status = apply_filters('groups_valid_status', array('public', 'private', 'hidden'));
     // Auto join group when non group member performs group activity.
     $this->auto_join = defined('BP_DISABLE_AUTO_GROUP_JOIN') && BP_DISABLE_AUTO_GROUP_JOIN ? false : true;
 }
 /**
  * Setup globals
  *
  * The BP_GROUPS_SLUG constant is deprecated, and only used here for
  * backwards compatibility.
  *
  * @since BuddyPress (1.5)
  * @global BuddyPress $bp The one true BuddyPress instance
  */
 function setup_globals()
 {
     global $bp;
     // Define a slug, if necessary
     if (!defined('BP_GROUPS_SLUG')) {
         define('BP_GROUPS_SLUG', $this->id);
     }
     // Global tables for messaging component
     $global_tables = array('table_name' => $bp->table_prefix . 'bp_groups', 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta');
     // All globals for messaging component.
     // Note that global_tables is included in this array.
     $globals = array('slug' => BP_GROUPS_SLUG, 'root_slug' => isset($bp->pages->groups->slug) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'notification_callback' => 'groups_format_notifications', 'search_string' => __('Search Groups...', 'buddypress'), 'global_tables' => $global_tables);
     parent::setup_globals($globals);
     /** Single Group Globals **********************************************/
     // Are we viewing a single group?
     if (bp_is_groups_component() && ($group_id = BP_Groups_Group::group_exists(bp_current_action()))) {
         $bp->is_single_item = true;
         $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Group');
         $this->current_group = apply_filters('bp_groups_current_group_object', new $current_group_class($group_id));
         // When in a single group, the first action is bumped down one because of the
         // group name, so we need to adjust this and set the group name to current_item.
         $bp->current_item = bp_current_action();
         $bp->current_action = bp_action_variable(0);
         array_shift($bp->action_variables);
         // Using "item" not "group" for generic support in other components.
         if (bp_current_user_can('bp_moderate')) {
             bp_update_is_item_admin(true, 'groups');
         } else {
             bp_update_is_item_admin(groups_is_user_admin(bp_loggedin_user_id(), $this->current_group->id), 'groups');
         }
         // If the user is not an admin, check if they are a moderator
         if (!bp_is_item_admin()) {
             bp_update_is_item_mod(groups_is_user_mod(bp_loggedin_user_id(), $this->current_group->id), 'groups');
         }
         // Is the logged in user a member of the group?
         if (is_user_logged_in() && groups_is_user_member(bp_loggedin_user_id(), $this->current_group->id)) {
             $this->current_group->is_user_member = true;
         } else {
             $this->current_group->is_user_member = false;
         }
         // Should this group be visible to the logged in user?
         if ('public' == $this->current_group->status || $this->current_group->is_user_member) {
             $this->current_group->is_visible = true;
         } else {
             $this->current_group->is_visible = false;
         }
         // If this is a private or hidden group, does the user have access?
         if ('private' == $this->current_group->status || 'hidden' == $this->current_group->status) {
             if ($this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can('bp_moderate')) {
                 $this->current_group->user_has_access = true;
             } else {
                 $this->current_group->user_has_access = false;
             }
         } else {
             $this->current_group->user_has_access = true;
         }
         // Set current_group to 0 to prevent debug errors
     } else {
         $this->current_group = 0;
     }
     // Illegal group names/slugs
     $this->forbidden_names = apply_filters('groups_forbidden_names', array('my-groups', 'create', 'invites', 'send-invites', 'forum', 'delete', 'add', 'admin', 'request-membership', 'members', 'settings', 'avatar', $this->slug, $this->root_slug));
     // If the user was attempting to access a group, but no group by that name was found, 404
     if (bp_is_groups_component() && empty($this->current_group) && bp_current_action() && !in_array(bp_current_action(), $this->forbidden_names)) {
         bp_do_404();
         return;
     }
     if (bp_is_groups_component() && !empty($this->current_group)) {
         $this->default_extension = apply_filters('bp_groups_default_extension', defined('BP_GROUPS_DEFAULT_EXTENSION') ? BP_GROUPS_DEFAULT_EXTENSION : 'home');
         if (!bp_current_action()) {
             $bp->current_action = $this->default_extension;
         }
         // Prepare for a redirect to the canonical URL
         $bp->canonical_stack['base_url'] = bp_get_group_permalink($this->current_group);
         if (bp_current_action()) {
             $bp->canonical_stack['action'] = bp_current_action();
         }
         if (!empty($bp->action_variables)) {
             $bp->canonical_stack['action_variables'] = bp_action_variables();
         }
         // When viewing the default extension, the canonical URL should not have
         // that extension's slug, unless more has been tacked onto the URL via
         // action variables
         if (bp_is_current_action($this->default_extension) && empty($bp->action_variables)) {
             unset($bp->canonical_stack['action']);
         }
     }
     // Group access control
     if (bp_is_groups_component() && !empty($this->current_group)) {
         if (!$this->current_group->user_has_access) {
             // Hidden groups should return a 404 for non-members.
             // Unset the current group so that you're not redirected
             // to the default group tab
             if ('hidden' == $this->current_group->status) {
                 $this->current_group = 0;
                 $bp->is_single_item = false;
                 bp_do_404();
                 return;
                 // Skip the no_access check on home and membership request pages
             } elseif (!bp_is_current_action('home') && !bp_is_current_action('request-membership')) {
                 // Off-limits to this user. Throw an error and redirect to the group's home page
                 if (is_user_logged_in()) {
                     bp_core_no_access(array('message' => __('You do not have access to this group.', 'buddypress'), 'root' => bp_get_group_permalink($bp->groups->current_group), 'redirect' => false));
                     // User does not have access, and does not get a message
                 } else {
                     bp_core_no_access();
                 }
             }
         }
         // Protect the admin tab from non-admins
         if (bp_is_current_action('admin') && !bp_is_item_admin()) {
             bp_core_no_access(array('message' => __('You are not an admin of this group.', 'buddypress'), 'root' => bp_get_group_permalink($bp->groups->current_group), 'redirect' => false));
         }
     }
     // Preconfigured group creation steps
     $this->group_creation_steps = apply_filters('groups_create_group_steps', array('group-details' => array('name' => __('Details', 'buddypress'), 'position' => 0), 'group-settings' => array('name' => __('Settings', 'buddypress'), 'position' => 10)));
     // If avatar uploads are not disabled, add avatar option
     if (!(int) bp_get_option('bp-disable-avatar-uploads')) {
         $this->group_creation_steps['group-avatar'] = array('name' => __('Avatar', 'buddypress'), 'position' => 20);
     }
     // If friends component is active, add invitations
     if (bp_is_active('friends')) {
         $this->group_creation_steps['group-invites'] = array('name' => __('Invites', 'buddypress'), 'position' => 30);
     }
     // Groups statuses
     $this->valid_status = apply_filters('groups_valid_status', array('public', 'private', 'hidden'));
     // Auto join group when non group member performs group activity
     $this->auto_join = defined('BP_DISABLE_AUTO_GROUP_JOIN') && BP_DISABLE_AUTO_GROUP_JOIN ? false : true;
 }
function groups_check_group_exists($group_id)
{
    return BP_Groups_Group::group_exists($group_id);
}
/**
 * Fix forum topic action links (Edit, Delete, Close, Sticky, etc.)
 */
function bp_group_hierarchy_fixup_forum_links($has_topics)
{
    global $forum_template;
    $group_id = BP_Groups_Group::group_exists($forum_template->topic->object_slug);
    $forum_template->topic->object_slug = BP_Groups_Hierarchy::get_path($group_id);
    return $has_topics;
}
function bp_ning_import_get_discussion_groups()
{
    global $wpdb;
    $ning_id_array = get_option('bp_ning_user_array');
    // Get list of Ning groups for cross reference
    $groups = bp_ning_import_prepare_json('groups');
    $ning_group_id_array = get_option('bp_ning_group_array', array());
    // Loop through each discussion. If the topic doesn't have a corresponding group, create one. Then insert the forum items.
    $discussions = bp_ning_import_prepare_json('discussions');
    $counter = 0;
    foreach ((array) $discussions as $discussion_key => $discussion) {
        if (!isset($discussion->category)) {
            continue;
        }
        $ning_group_id = $discussion->category;
        if (isset($ning_group_id_array[$ning_group_id])) {
            continue;
        }
        // todo - what if a topic has no group and no category
        $slug = sanitize_title(esc_attr($discussion->category));
        $ning_group_creator_id = $discussion->contributorName;
        $creator_id = $ning_id_array[$ning_group_creator_id];
        $ndate = strtotime($discussion->createdDate);
        $date_created = date("Y-m-d H:i:s", $ndate);
        if (!($group_id = BP_Groups_Group::group_exists($slug))) {
            $args = array('creator_id' => $creator_id, 'name' => $discussion->category, 'description' => $discussion->category, 'slug' => groups_check_slug($slug), 'status' => 'public', 'enable_forum' => 1, 'date_created' => $date_created);
            if ($group_id = groups_create_group($args)) {
                groups_update_groupmeta($group_id, 'last_activity', $date_created);
                groups_update_groupmeta($group_id, 'total_member_count', 1);
                groups_new_group_forum($group_id, $discussion->category, $discussion->category);
                echo "<strong>Created group: {$discussion->category}</strong><br />";
                $ning_group_id_array[$ning_group_id] = $group_id;
                update_option('bp_ning_group_array', $ning_group_id_array);
            }
        } else {
            echo "<strong>Group already exists: {$discussion->category}</strong><br />";
            $ning_group_id_array[$ning_group_id] = $group_id;
            update_option('bp_ning_group_array', $ning_group_id_array);
        }
    }
}
 /**
  * set_nav()
  *
  * Sets up the component navigation
  */
 function set_nav()
 {
     global $bp;
     if (!$this->courseware_status($bp->groups->current_group->id)) {
         return;
     }
     if ($group_id = BP_Groups_Group::group_exists($bp->current_action)) {
         $bp->is_single_item = true;
         $bp->groups->current_group =& new BP_Groups_Group($group_id);
     }
     $groups_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
     if ($bp->is_single_item) {
         bp_core_new_subnav_item(array('name' => __('Courseware', 'bpsp'), 'slug' => $bp->courseware->slug, 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => array(&$this, 'screen_handler'), 'position' => 35, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'courseware-group'));
         $this->nav_options[__('Home', 'bpsp')] = $groups_link . $bp->courseware->slug;
     }
     do_action('courseware_group_set_nav');
 }
Example #10
0
/**
 * bp_chat_setup_nav()
 *
 * Sets up the navigation items for the component. This adds the top level nav
 * item and all the sub level nav items to the navigation array. This is then
 * rendered in the template.
 */
function bp_chat_setup_nav()
{
    global $bp, $current_blog, $group_object;
    #$chat_link = $bp->loggedin_user->domain . $bp->chat->slug . '/';
    $chat_link = get_bloginfo('wpurl') . $bp->chat->slug . '/';
    if (function_exists('anygig_orig_check_supporter')) {
        if (false == anygig_orig_check_supporter('Chat', 'bp-chat', $bp->chat->slug, 80, $bp->chat->id, $chat_link)) {
            return;
        }
    }
    if (function_exists('bp_core_new_nav_item')) {
        bp_core_new_nav_item(array('name' => __('Chat', 'bp-chat'), 'slug' => $bp->chat->slug, 'screen_function' => 'bp_chat_screen_one', 'default_subnav_slug' => 'chat', 'user_has_access' => bp_is_home()));
    } else {
        /* Add 'Chat' to the main navigation */
        bp_core_add_nav_item(__('Chat', 'bp-chat'), $bp->chat->slug);
        /* Set a specific sub nav item as the default when the top level item is clicked */
        bp_core_add_nav_default($bp->chat->slug, 'bp_chat_screen_one', 'chat-one');
    }
    if (class_exists('BP_Groups_Group')) {
        if ($group_id = BP_Groups_Group::group_exists($bp->current_action)) {
            /* This is a single group page. */
            $bp->is_single_item = true;
            $bp->groups->current_group =& new BP_Groups_Group($group_id);
        }
        $groups_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
        /* Add the subnav item only to the single group nav item*/
        if ($bp->is_single_item) {
            bp_core_new_subnav_item(array('name' => __('Chat', 'bp-chat'), 'slug' => $bp->chat->slug, 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'bp_chat_screen_one', 'position' => 35, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'bp-chat'));
        }
        do_action('bp_group_documents_nav_setup');
    }
    #print "<pre>";
    #print_r ($bp->groups);
    #print "</pre>";
    /* Only execute the following code if we are actually viewing this component (e.g. http://chat.org/chat) */
    if ($bp->current_component == $bp->chat->slug) {
        if (bp_is_home()) {
            /* If the user is viewing their own profile area set the title to "My Chat" */
            $bp->bp_options_title = __('My Chat', 'bp-chat');
        } else {
            /* If the user is viewing someone elses profile area, set the title to "[user fullname]" */
            //$bp->bp_options_avatar = bp_core_get_avatar( $bp->displayed_user->id, 1 );
            $bp->bp_options_title = $bp->displayed_user->fullname;
        }
    }
}