function getGroups($force = false)
 {
     //need a user id for this
     if (empty($this->ID)) {
         return false;
     }
     //check cache
     if (isset($this->groups) && !$force) {
         return $this->groups;
     }
     //remove the bp-site-groups filter
     remove_filter('groups_get_groups', 'bpsg_groups_get_groups');
     //get corresponding class ids for buddypress groups this user is a member of
     $groups = array();
     if (bp_has_groups(array('user_id' => $this->ID))) {
         while (bp_groups()) {
             bp_the_group();
             $group_id = bp_get_group_id();
             $groups[] = groups_get_group(array('group_id' => $group_id));
         }
     }
     //add the bp-site-groups filter back
     add_filter('groups_get_groups', 'bpsg_groups_get_groups');
     $this->groups = $groups;
     return $this->groups;
 }
 /**
  * Validate and sanitise the parameters for the suggestion service query.
  *
  * @since 2.1.0
  *
  * @return true|WP_Error If validation fails, return a WP_Error object. On success, return true (bool).
  */
 public function validate()
 {
     $this->args['group_id'] = (int) $this->args['group_id'];
     /**
      * Filters the arguments used to validate and sanitize suggestion service query.
      *
      * @since 2.1.0
      *
      * @param array                        $args  Array of arguments for the suggestion service query.
      * @param BP_Groups_Member_Suggestions $this  Instance of the current suggestion class.
      */
     $this->args = apply_filters('bp_groups_member_suggestions_args', $this->args, $this);
     // Check for invalid or missing mandatory parameters.
     if (!$this->args['group_id'] || !bp_is_active('groups')) {
         return new WP_Error('missing_requirement');
     }
     // Check that the specified group_id exists, and that the current user can access it.
     $the_group = groups_get_group(array('group_id' => absint($this->args['group_id']), 'populate_extras' => true));
     if ($the_group->id === 0 || !$the_group->user_has_access) {
         return new WP_Error('access_denied');
     }
     /**
      * Filters the validation results for the suggestion service query.
      *
      * @since 2.1.0
      *
      * @param bool|WP_Error                $value True if valid, WP_Error if not.
      * @param BP_Groups_Member_Suggestions $this  Instance of the current suggestion class.
      */
     return apply_filters('bp_groups_member_suggestions_validate_args', parent::validate(), $this);
 }
示例#3
0
 /**
  * Construct the class
  * @version 2.0
  */
 function __construct()
 {
     // Get the Entropy Rising group from BuddyPress
     $this->group = groups_get_group(array('group_id' => $this->group_id, 'populate_extras' => true));
     // Remap membership flag
     $this->is_member = $this->group->is_member;
 }
/**
 * @param EM_Event $EM_Event
 */
function bp_em_group_event_save($result, $EM_Event)
{
    if (is_object($EM_Event) && !empty($EM_Event->event_id)) {
        if (!empty($_REQUEST['group_id']) && is_numeric($_REQUEST['group_id']) && bp_is_active('groups')) {
            //we have been requested an event creation tied to a group, so does this group exist, and does this person have admin rights to it?
            if (groups_is_user_admin(get_current_user_id(), $_REQUEST['group_id'])) {
                $EM_Event->group_id = $_REQUEST['group_id'];
            }
            if (!empty($EM_Event->group_id)) {
                //if group is private, make it private
                $group = groups_get_group(array('group_id' => $EM_Event->group_id));
                $is_member = groups_is_user_member(get_current_user_id(), $EM_Event->group_id) || groups_is_user_admin(get_current_user_id(), $EM_Event->group_id) || groups_is_user_mod(get_current_user_id(), $EM_Event->group_id);
                if ($group->status != 'public' && $is_member) {
                    //Make sure event status is private and set post status to private
                    global $wpdb;
                    $EM_Event->event_private = 1;
                    $wpdb->update($wpdb->posts, array('post_status' => 'private'), array('ID' => $EM_Event->post_id));
                    $wpdb->update(EM_EVENTS_TABLE, array('event_private' => 1), array('event_id' => $EM_Event->event_id));
                }
            }
        } else {
            $EM_Event->group_id = null;
        }
    }
    return $result;
}
/**
 * bp_course_nav_menu()
 * Navigation menu for BuddyPress course
 */
function bp_course_nav_menu()
{
    $nav = bp_course_get_nav_permalinks();
    $defaults = array('' => array('id' => 'home', 'label' => __('Home', 'vibe'), 'action' => '', 'link' => bp_get_course_permalink()), 'curriculum' => array('id' => 'curriculum', 'label' => __('Curriculum', 'vibe'), 'can_view' => 1, 'action' => empty($nav['curriculum_slug']) ? __('curriculum', 'vibe') : $nav['curriculum_slug'], 'link' => bp_get_course_permalink()), 'members' => array('id' => 'members', 'label' => __('Members', 'vibe'), 'can_view' => 1, 'action' => empty($nav['members_slug']) ? __('members', 'vibe') : $nav['members_slug'], 'link' => bp_get_course_permalink()), 'activity' => array('id' => 'activity', 'label' => __('Activity', 'vibe'), 'can_view' => 1, 'action' => empty($nav['activity_slug']) ? __('activity', 'vibe') : $nav['activity_slug'], 'link' => bp_get_course_permalink()));
    global $post;
    if ($post->post_type == 'course') {
        if (function_exists('bp_is_active') && bp_is_active('groups')) {
            $vgroup = get_post_meta(get_the_ID(), 'vibe_group', true);
            if (!empty($vgroup)) {
                $group = groups_get_group(array('group_id' => $vgroup));
                $defaults['group'] = array('id' => 'group', 'label' => __('Group', 'vibe'), 'action' => 'group', 'can_view' => 1, 'link' => bp_get_group_permalink($group), 'external' => true);
            }
        }
        if (in_array('bbpress/bbpress.php', apply_filters('active_plugins', get_option('active_plugins'))) || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('bbpress/bbpress.php')) {
            $forum = get_post_meta(get_the_ID(), 'vibe_forum', true);
            if (!empty($forum)) {
                $defaults['forum'] = array('id' => 'forum', 'label' => __('Forum', 'vibe'), 'action' => 'forum', 'can_view' => 1, 'link' => get_permalink($forum), 'external' => true);
            }
        }
    }
    $nav_menu = apply_filters('wplms_course_nav_menu', $defaults);
    global $bp;
    $action = bp_current_action();
    if (empty($action)) {
        !empty($_GET['action']) ? $action = $_GET['action'] : ($action = '');
    }
    if (is_array($nav_menu)) {
        foreach ($nav_menu as $key => $menu_item) {
            $menu_item['action'] = str_replace('/', '', $menu_item['action']);
            if ($key == $action) {
                $class = 'class="current"';
            } else {
                $class = '';
            }
            global $wp_query;
            if (!empty($nav[$menu_item['id'] . '_slug'])) {
                echo '<li id="' . $menu_item['id'] . '" ' . $class . '><a href="' . $menu_item['link'] . '' . (isset($menu_item['action']) && !isset($menu_item['external']) ? $menu_item['action'] : '') . '">' . $menu_item['label'] . '</a></li>';
            } else {
                echo '<li id="' . $menu_item['id'] . '" ' . $class . '><a href="' . $menu_item['link'] . '' . (!empty($menu_item['action']) && !isset($menu_item['external']) ? (strpos($menu_item['link'], '?') ? '&' : '?') . 'action=' . $menu_item['action'] : '') . '">' . $menu_item['label'] . '</a></li>';
            }
        }
    }
    if (is_super_admin() || is_instructor()) {
        $admin_slug = empty($nav['admin_slug']) ? _x('admin', 'course admin slug', 'vibe') : $nav['admin_slug'];
        $admin_slug = apply_filters('wplms_course_admin_slug', str_replace('/', '', $admin_slug));
        ?>
      <li id="admin" class="<?php 
        echo !empty($action) && ($action == 'admin' || $action == 'submission' || $action == 'stats') ? 'selected current' : '';
        ?>
"><a href="<?php 
        bp_course_permalink();
        echo $admin_slug;
        ?>
"><?php 
        _e('Admin', 'vibe');
        ?>
</a></li>
      <?php 
    }
}
    public static function admin_notices()
    {
        //When editing
        global $post, $EM_Event, $pagenow;
        if ($pagenow == 'post.php' && ($post->post_type == EM_POST_TYPE_EVENT || $post->post_type == 'event-recurring')) {
            if ($EM_Event->is_recurring()) {
                $warning = "<p><strong>" . __('WARNING: This is a recurring event.', 'dbem') . "</strong></p>";
                $warning .= "<p>" . __('Modifications to this event will cause all recurrences of this event to be deleted and recreated and previous bookings will be deleted! You can edit individual recurrences and disassociate them with this recurring event.', 'dbem');
                ?>
<div class="updated"><?php 
                echo $warning;
                ?>
</div><?php 
            } elseif ($EM_Event->is_recurrence()) {
                $warning = "<p><strong>" . __('WARNING: This is a recurrence in a set of recurring events.', 'dbem') . "</strong></p>";
                $warning .= "<p>" . sprintf(__('If you update this event data and save, it could get overwritten if you edit the recurring event template. To make it an independent, <a href="%s">detach it</a>.', 'dbem'), $EM_Event->get_detach_url()) . "</p>";
                $warning .= "<p>" . sprintf(__('To manage the whole set, <a href="%s">edit the recurring event template</a>.', 'dbem'), admin_url('post.php?action=edit&amp;post=' . $EM_Event->get_event_recurrence()->post_id)) . "</p>";
                ?>
<div class="updated"><?php 
                echo $warning;
                ?>
</div><?php 
            }
            if (!empty($EM_Event->group_id) && function_exists('groups_get_group')) {
                $group = groups_get_group(array('group_id' => $EM_Event->group_id));
                $warning = sprintf(__('WARNING: This is a event belonging to the group "%s". Other group admins can also modify this event.', 'dbem'), $group->name);
                ?>
<div class="updated"><p><?php 
                echo $warning;
                ?>
</p></div><?php 
            }
        }
    }
 function add_cover()
 {
     if (!is_user_logged_in()) {
         return;
     }
     $user_ID = get_current_user_id();
     $output = '';
     if (groups_is_user_mod($user_ID, $this->group_id) || groups_is_user_admin($user_ID, $this->group_id)) {
         if ($this->get_cover()) {
             $message = __("Change Cover", 'bpcp');
         } else {
             $message = __("Add Cover", 'bpcp');
         }
         $group = groups_get_group(array('group_id' => $this->group_id));
         $group_permalink = trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group->slug . '/');
         $output .= '<div class="profile-cover-action">';
         $output .= '<a href="' . trailingslashit($group_permalink . 'admin') . $this->slug . '" class="button">' . $message . '</a>';
         $output .= '</div>';
     }
     $default_cover = bp_get_option('bpcp-group-default');
     if ($this->get_cover() || $default_cover) {
         $output .= '<div class="profile-cover-inner"></div>';
     }
     echo $output;
 }
 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);
     }
 }
/**
 * Load the Forums directory.
 */
function bp_forums_directory_forums_setup()
{
    // Get BuddyPress once
    $bp = buddypress();
    if (bp_is_forums_component() && (!bp_current_action() || 'tag' == bp_current_action() && bp_action_variables()) && !bp_current_item()) {
        if (!bp_forums_has_directory()) {
            return false;
        }
        if (!bp_forums_is_installed_correctly()) {
            bp_core_add_message(__('The forums component has not been set up yet.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain());
        }
        bp_update_is_directory(true, 'forums');
        do_action('bbpress_init');
        // Check to see if the user has posted a new topic from the forums page.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            check_admin_referer('bp_forums_new_topic');
            $bp->groups->current_group = groups_get_group(array('group_id' => $_POST['topic_group_id']));
            if (!empty($bp->groups->current_group->id)) {
                // Auto join this user if they are not yet a member of this group
                if (!bp_current_user_can('bp_moderate') && '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);
                }
                $error_message = '';
                $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
                if (!empty($forum_id)) {
                    if (empty($_POST['topic_title'])) {
                        $error_message = __('Please provide a title for your forum topic.', 'buddypress');
                    } else {
                        if (empty($_POST['topic_text'])) {
                            $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
                        }
                    }
                    if ($error_message) {
                        bp_core_add_message($error_message, 'error');
                        $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                    } else {
                        if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                            bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                        } else {
                            bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                        }
                    }
                    bp_core_redirect($redirect);
                } else {
                    bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                    bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
                }
            } else {
                bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
            }
        }
        do_action('bp_forums_directory_forums_setup');
        bp_core_load_template(apply_filters('bp_forums_template_directory_forums_setup', 'forums/index'));
    }
}
示例#10
0
 /**
  * Create a group, set up nav item, and go to the group.
  */
 protected function set_up_group()
 {
     $g = $this->factory->group->create(array('slug' => 'testgroup'));
     $group = groups_get_group($g);
     $group_permalink = bp_get_group_permalink($group);
     $this->go_to($group_permalink);
     bp_core_new_subnav_item(array('name' => 'Foo', 'slug' => 'foo', 'parent_url' => $group_permalink, 'parent_slug' => 'testgroup', 'screen_function' => 'foo_screen_function', 'position' => 10), 'groups');
 }
/**
 * Catch and route requests for single activity item permalinks.
 *
 * @since 1.2.0
 *
 * @uses bp_is_activity_component()
 * @uses bp_is_current_action()
 * @uses bp_action_variable()
 * @uses bp_activity_get_specific()
 * @uses bp_is_active()
 * @uses bp_core_get_user_domain()
 * @uses groups_get_group()
 * @uses bp_get_group_permalink()
 * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook.
 * @uses bp_core_redirect()
 * @uses bp_get_root_domain()
 *
 * @return bool False on failure.
 */
function bp_activity_action_permalink_router()
{
    // Not viewing activity.
    if (!bp_is_activity_component() || !bp_is_current_action('p')) {
        return false;
    }
    // No activity to display.
    if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) {
        return false;
    }
    // Get the activity details.
    $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true));
    // 404 if activity does not exist
    if (empty($activity['activities'][0])) {
        bp_do_404();
        return;
    } else {
        $activity = $activity['activities'][0];
    }
    // Do not redirect at default.
    $redirect = false;
    // Redirect based on the type of activity.
    if (bp_is_active('groups') && $activity->component == buddypress()->groups->id) {
        // Activity is a user update.
        if (!empty($activity->user_id)) {
            $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/';
            // Activity is something else.
        } else {
            // Set redirect to group activity stream.
            if ($group = groups_get_group(array('group_id' => $activity->item_id))) {
                $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/';
            }
        }
        // Set redirect to users' activity stream.
    } elseif (!empty($activity->user_id)) {
        $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/';
    }
    // If set, add the original query string back onto the redirect URL.
    if (!empty($_SERVER['QUERY_STRING'])) {
        $query_frags = array();
        wp_parse_str($_SERVER['QUERY_STRING'], $query_frags);
        $redirect = add_query_arg(urlencode_deep($query_frags), $redirect);
    }
    /**
     * Filter the intended redirect url before the redirect occurs for the single activity item.
     *
     * @since 1.2.2
     *
     * @param array $value Array with url to redirect to and activity related to the redirect.
     */
    if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) {
        bp_core_redirect(bp_get_root_domain());
    }
    // Redirect to the actual activity permalink page.
    bp_core_redirect($redirect);
}
示例#12
0
/**
 * Handle the loading of a user's Groups > Invites page.
 */
function groups_screen_group_invites()
{
    $group_id = (int) bp_action_variable(1);
    if (bp_is_action_variable('accept') && is_numeric($group_id)) {
        // Check the nonce.
        if (!check_admin_referer('groups_accept_invite')) {
            return false;
        }
        if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
            bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Group invite accepted', 'buddypress'));
            // Record this in activity streams.
            $group = groups_get_group(array('group_id' => $group_id));
            groups_record_activity(array('type' => 'joined_group', 'item_id' => $group->id));
        }
        if (isset($_GET['redirect_to'])) {
            $redirect_to = urldecode($_GET['redirect_to']);
        } else {
            $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
        }
        bp_core_redirect($redirect_to);
    } elseif (bp_is_action_variable('reject') && is_numeric($group_id)) {
        // Check the nonce.
        if (!check_admin_referer('groups_reject_invite')) {
            return false;
        }
        if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
            bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Group invite rejected', 'buddypress'));
        }
        if (isset($_GET['redirect_to'])) {
            $redirect_to = urldecode($_GET['redirect_to']);
        } else {
            $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
        }
        bp_core_redirect($redirect_to);
    }
    /**
     * Fires before the loading of a users Groups > Invites template.
     *
     * @since 1.0.0
     *
     * @param int $group_id ID of the group being displayed
     */
    do_action('groups_screen_group_invites', $group_id);
    /**
     * Filters the template to load for a users Groups > Invites page.
     *
     * @since 1.0.0
     *
     * @param string $value Path to a users Groups > Invites page template.
     */
    bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
示例#13
0
 /**
  * @group activity_action
  * @group bp_groups_format_activity_action_joined_group
  */
 public function test_bp_groups_format_activity_action_joined_group()
 {
     $u = $this->factory->user->create();
     $g = $this->factory->group->create();
     $a = $this->factory->activity->create(array('component' => buddypress()->groups->id, 'type' => 'joined_group', 'user_id' => $u, 'item_id' => $g));
     $a_obj = new BP_Activity_Activity($a);
     $g_obj = groups_get_group($g);
     $expected = sprintf(__('%s joined the group %s', 'buddypress'), bp_core_get_userlink($u), '<a href="' . bp_get_group_permalink($g_obj) . '">' . $g_obj->name . '</a>');
     $this->assertSame($expected, $a_obj->action);
 }
/**
 * Format activity actions.
 *
 * @param string $action   Activity action as determined by BuddyPress.
 * @param obj    $activity Activity item.
 * @return string
 */
function cacsp_format_activity_action($action, $activity)
{
    $paper = new CACSP_Paper($activity->secondary_item_id);
    $paper_id = $paper->ID;
    if (!$paper_id) {
        return $action;
    }
    $paper_title = $paper->post_title;
    $paper_link = get_permalink($paper->ID);
    $user_link = bp_core_get_userlink($activity->user_id);
    switch ($activity->type) {
        case 'new_cacsp_paper':
            $action = sprintf(__('%1$s created a new paper %2$s', 'social-paper'), $user_link, sprintf('<a href="%s">%s</a>', esc_url($paper_link), esc_html($paper_title)));
            break;
        case 'new_cacsp_comment':
            $comment = get_comment($activity->item_id);
            if (!$comment) {
                return $action;
            }
            if ($comment->user_id) {
                $commenter_link = bp_core_get_userlink($comment->user_id);
            } elseif ($comment->comment_author_url) {
                $commenter_link = sprintf('<a href="%s">%s</a>', esc_url($comment->comment_author_url), esc_html($comment->comment_author));
            } else {
                $commenter_link = esc_html($comment->comment_author);
            }
            $action = sprintf(__('%1$s commented on the paper %2$s', 'social-paper'), $commenter_link, sprintf('<a href="%s">%s</a>', esc_url($paper_link), esc_html($paper_title)));
            break;
        case 'new_cacsp_edit':
            $action = sprintf(__('%1$s edited the paper %2$s', 'social-paper'), $user_link, sprintf('<a href="%s">%s</a>', esc_url($paper_link), esc_html($paper_title)));
            break;
        case 'cacsp_paper_added_to_group':
            if (!bp_is_active('groups')) {
                return $action;
            }
            $group = groups_get_group(array('group_id' => $activity->item_id));
            $action = sprintf(__('%1$s added the paper %2$s to the group %3$s', 'social-paper'), $user_link, sprintf('<a href="%s">%s</a>', esc_url($paper_link), esc_html($paper_title)), sprintf('<a href="%s">%s</a>', esc_url(bp_get_group_permalink($group)), esc_html(stripslashes($group->name))));
            break;
        default:
            return $action;
    }
    /**
     * Filters the formatted action for paper activities.
     *
     * Used by hooks-buddypress-groups.php to add group information.
     *
     * @param string      $action      Formatted action string.
     * @param obj         $activity    Activity item.
     * @param CACSP_Paper $paper       Paper object.
     * @param string      $paper_title Paper title.
     * @param string      $paper_link  Paper URL.
     * @param string      $user_link   User link.
     */
    return apply_filters('cacsp_format_activity_action', $action, $activity, $paper, $paper_title, $paper_link, $user_link);
}
/**
 * Allow core components and dependent plugins to register activity actions
 *
 * @since BuddyPress (1.2)
 *
 * @global object $bp BuddyPress global settings
 * @uses bp_is_activity_component()
 * @uses bp_is_current_action()
 * @uses bp_action_variable()
 * @uses bp_activity_get_specific()
 * @uses bp_is_active()
 * @uses bp_core_get_user_domain()
 * @uses groups_get_group()
 * @uses bp_get_group_permalink()
 * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook
 * @uses bp_core_redirect()
 * @uses bp_get_root_domain()
 *
 * @return bool False on failure
 */
function bp_activity_action_permalink_router()
{
    global $bp;
    // Not viewing activity
    if (!bp_is_activity_component() || !bp_is_current_action('p')) {
        return false;
    }
    // No activity to display
    if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) {
        return false;
    }
    // Get the activity details
    $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true));
    // 404 if activity does not exist
    if (empty($activity['activities'][0])) {
        bp_do_404();
        return;
    } else {
        $activity = $activity['activities'][0];
    }
    // Do not redirect at default
    $redirect = false;
    // Redirect based on the type of activity
    if (bp_is_active('groups') && $activity->component == $bp->groups->id) {
        // Activity is a user update
        if (!empty($activity->user_id)) {
            $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/';
            // Activity is something else
        } else {
            // Set redirect to group activity stream
            if ($group = groups_get_group(array('group_id' => $activity->item_id))) {
                $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/';
            }
        }
        // Set redirect to users' activity stream
    } else {
        $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/';
    }
    // If set, add the original query string back onto the redirect URL
    if (!empty($_SERVER['QUERY_STRING'])) {
        $query_frags = array();
        wp_parse_str($_SERVER['QUERY_STRING'], $query_frags);
        $redirect = add_query_arg(urlencode_deep($query_frags), $redirect);
    }
    // Allow redirect to be filtered
    if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) {
        bp_core_redirect(bp_get_root_domain());
    }
    // Redirect to the actual activity permalink page
    bp_core_redirect($redirect);
}
function bp_reshare_prepare_reshare($activity_id)
{
    global $bp;
    $activity_to_reshare = bp_activity_get_specific('activity_ids=' . $activity_id);
    $activity = $activity_to_reshare['activities'][0];
    /* get and increment reshared count */
    $rs_count = bp_activity_get_meta($activity_id, 'reshared_count');
    $rs_count = !empty($rs_count) ? (int) $rs_count + 1 : 1;
    bp_activity_update_meta($activity_id, 'reshared_count', $rs_count);
    /* get an array of users that reshared the activity */
    $reshared_by = bp_activity_get_meta($activity_id, 'reshared_by');
    if (is_array($reshared_by) && !in_array($bp->loggedin_user->id, $reshared_by)) {
        $reshared_by[] = $bp->loggedin_user->id;
    } else {
        $reshared_by[] = $bp->loggedin_user->id;
    }
    bp_activity_update_meta($activity_id, 'reshared_by', $reshared_by);
    $secondary_avatar = bp_core_fetch_avatar(array('item_id' => $activity->user_id, 'object' => 'user', 'type' => 'thumb', 'alt' => $alt, 'class' => 'avatar', 'width' => 20, 'height' => 20));
    $component = $activity->component;
    $item_id = $activity->item_id;
    if ($component != 'activity') {
        if ($activity->type == 'new_blog_post') {
            $action = sprintf(__('%s reshared a <a href="%s">blog post</a> originally posted by %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id));
        } else {
            if ($activity->type == 'new_blog_comment') {
                $action = sprintf(__('%s reshared a <a href="%s">comment</a> originally posted by %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id));
            } else {
                if ($component == 'groups') {
                    $group = groups_get_group(array('group_id' => $item_id));
                    $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . $group->name . '</a>';
                    if ($activity->type == 'new_forum_topic') {
                        $action = sprintf(__('%s reshared a <a href="%s">forum topic</a> originally posted by %s in the group %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id), $group_link);
                    } else {
                        if ($activity->type == 'new_forum_post') {
                            $action = sprintf(__('%s reshared a <a href="%s">forum reply</a> originally posted by %s in the group %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id), $group_link);
                        } else {
                            $action = sprintf(__("%s reshared an activity originally shared by %s in the group %s", 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $secondary_avatar . bp_core_get_userlink($activity->user_id), $group_link);
                        }
                    }
                }
            }
        }
    } else {
        $action = sprintf(__("%s reshared an activity originally shared by %s", 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $secondary_avatar . bp_core_get_userlink($activity->user_id));
    }
    $reshared_args = array('action' => apply_filters('bp_reshare_action_parent_activity', $action, $activity->type), 'content' => $activity->content, 'component' => $component, 'type' => 'reshare_update', 'user_id' => $bp->loggedin_user->id, 'secondary_item_id' => $activity_id, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $activity->hide_sitewide);
    if (!empty($item_id)) {
        $reshared_args['item_id'] = $item_id;
    }
    return apply_filters('bp_reshare_prepare_reshare', $reshared_args, $activity_id);
}
 public function test_group_nav()
 {
     $bp_nav = buddypress()->bp_nav;
     $u = $this->factory->user->create();
     $g = $this->factory->group->create();
     $old_current_user = get_current_user_id();
     $this->set_current_user($u);
     $group = groups_get_group(array('group_id' => $g));
     $this->go_to(bp_get_group_permalink($group));
     $this->assertTrue(buddypress()->bp_nav[$group->slug]['position'] === -1);
     // Clean up
     buddypress()->bp_nav = $bp_nav;
     $this->set_current_user($old_current_user);
 }
示例#18
0
/**
 * Update group forum metadata (title, description, slug) when the group's details are edited.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int $group_id Group id, passed from groups_details_updated.
 */
function groups_update_group_forum($group_id)
{
    $group = groups_get_group(array('group_id' => $group_id));
    /**
     * Bail in the following three situations:
     *  1. Forums are not enabled for this group
     *  2. The BP Forum component is not enabled
     *  3. The built-in bbPress forums are not correctly installed (usually means they've been
     *     uninstalled)
     */
    if (empty($group->enable_forum) || !bp_is_active('forums') || function_exists('bp_forums_is_installed_correctly') && !bp_forums_is_installed_correctly()) {
        return false;
    }
    bp_forums_update_forum(apply_filters('groups_update_group_forum', array('forum_id' => groups_get_groupmeta($group_id, 'forum_id'), 'forum_name' => $group->name, 'forum_desc' => $group->description, 'forum_slug' => $group->slug)));
}
示例#19
0
 /**
  * Get some groups
  * @param array|struct $params
  * @subparam integer $params:groupid
  * @return object $return
  * @subreturn integer $return:group->id
  * @subreturn integer $return:group->courseid
  * @subreturn string $return:group->name
  * @subreturn string $return:group->enrolmentkey
  */
 static function get_groups($params)
 {
     if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_SYSTEM))) {
         foreach ($params as $groupid) {
             $group = groups_get_group(clean_param($groupid, PARAM_INTEGER));
             $ret = new StdClass();
             $ret->id = $group->id;
             $ret->courseid = $group->courseid;
             $ret->name = $group->name;
             $ret->enrolmentkey = $group->enrolmentkey;
             $groups[] = $ret;
         }
         return $groups;
     } else {
         throw new moodle_exception('wscouldnotgetgroupnopermission');
     }
 }
示例#20
0
function sp_assignments_dashboard_widget()
{
    $options = get_option("assignments_dashboard_widget_options", array());
    if (!empty($options['course_id'])) {
        $group = groups_get_group(array('group_id' => $options['course_id']));
    }
    if (!empty($group)) {
        echo "Showing assignments for class " . $group->name . ".<br />...";
        /*
        	get assignments for this group and list their status
        */
    } else {
        echo "Showing all assignments.<br />...";
        /*
        	get all assignments and list their status
        */
    }
}
 public function test_backcompat_remove_group_nav_items()
 {
     $g1 = $this->factory->group->create();
     // In group context
     $g_obj = groups_get_group($g1);
     $this->go_to(bp_get_group_permalink($g_obj));
     bp_core_new_subnav_item(array('name' => 'Clam', 'slug' => 'clam', 'parent_slug' => bp_get_current_group_slug(), 'parent_url' => bp_get_group_permalink($g_obj), 'screen_function' => 'clam_subnav'));
     bp_core_remove_subnav_item($g_obj->slug, 'clam');
     $nav = bp_get_nav_menu_items('groups');
     $found = false;
     foreach ($nav as $_nav) {
         if ('clam' === $_nav->css_id) {
             $found = true;
             break;
         }
     }
     $this->assertFalse($found);
 }
示例#22
0
function bp_forums_directory_forums_setup() {
	global $bp;

	if ( $bp->current_component == $bp->forums->slug ) {
		if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
			return false;

		if ( !bp_forums_is_installed_correctly() ) {
			bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
			bp_core_redirect( $bp->root_domain );
		}

		$bp->is_directory = true;

		do_action( 'bbpress_init' );

		/* Check to see if the user has posted a new topic from the forums page. */
		if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
			/* Check the nonce */
			check_admin_referer( 'bp_forums_new_topic' );

			if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
				/* 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->groups->current_group->id );

				if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
					if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
						bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
					else
						bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );

					bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
				} else {
					bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
				}
			}
		}

		do_action( 'bp_forums_directory_forums_setup' );

		bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
	}
}
function groups_screen_group_invites()
{
    $group_id = (int) bp_action_variable(1);
    if (bp_is_action_variable('accept') && is_numeric($group_id)) {
        // Check the nonce
        if (!check_admin_referer('groups_accept_invite')) {
            return false;
        }
        if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
            bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Group invite accepted', 'buddypress'));
            // Record this in activity streams
            $group = groups_get_group(array('group_id' => $group_id));
            groups_record_activity(array('type' => 'joined_group', 'item_id' => $group->id));
        }
        if (isset($_GET['redirect_to'])) {
            $redirect_to = urldecode($_GET['redirect_to']);
        } else {
            $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
        }
        bp_core_redirect($redirect_to);
    } else {
        if (bp_is_action_variable('reject') && is_numeric($group_id)) {
            // Check the nonce
            if (!check_admin_referer('groups_reject_invite')) {
                return false;
            }
            if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
                bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Group invite rejected', 'buddypress'));
            }
            if (isset($_GET['redirect_to'])) {
                $redirect_to = urldecode($_GET['redirect_to']);
            } else {
                $redirect_to = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action());
            }
            bp_core_redirect($redirect_to);
        }
    }
    do_action('groups_screen_group_invites', $group_id);
    bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
示例#24
0
/**
 * This function return the object val from given object and object_id
 * @param <string> $object mention for what you need cover eg. user,taxonomy,group
 * @param <int> $object_id ID of the object
 * @return <string> Object value of object.
 **/
function buddyboss_cover_photo_get_object($object, $object_id)
{
    global $bb_cover_photo_support;
    if (!in_array($object, $bb_cover_photo_support)) {
        //return nothing.
        return false;
    }
    //user
    if ($object == 'user') {
        $user = get_userdata($object_id);
        if (empty($user)) {
            return false;
        }
        return $user;
    }
    //taxonomy
    if ($object == 'taxonomy') {
        return '';
    }
    //group
    if ($object == 'group') {
        $group = groups_get_group(array('group_id' => $object_id));
        if (empty($group)) {
            return false;
        }
        return $group;
    }
    //forum
    if ($object == 'forum') {
        $forum = get_post($object_id);
        if (empty($forum)) {
            return false;
        }
        return $forum;
    }
}
function groups_screen_group_invites()
{
    $group_id = (int) bp_action_variable(1);
    if (bp_is_action_variable('accept') && is_numeric($group_id)) {
        // Check the nonce
        if (!check_admin_referer('groups_accept_invite')) {
            return false;
        }
        if (!groups_accept_invite(bp_loggedin_user_id(), $group_id)) {
            bp_core_add_message(__('Group invite could not be accepted', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Group invite accepted', 'buddypress'));
            // Record this in activity streams
            $group = groups_get_group(array('group_id' => $group_id));
            groups_record_activity(array('action' => apply_filters_ref_array('groups_activity_accepted_invite_action', array(sprintf(__('%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink(bp_loggedin_user_id()), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), bp_loggedin_user_id(), &$group)), 'type' => 'joined_group', 'item_id' => $group->id));
        }
        bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()));
    } else {
        if (bp_is_action_variable('reject') && is_numeric($group_id)) {
            // Check the nonce
            if (!check_admin_referer('groups_reject_invite')) {
                return false;
            }
            if (!groups_reject_invite(bp_loggedin_user_id(), $group_id)) {
                bp_core_add_message(__('Group invite could not be rejected', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Group invite rejected', 'buddypress'));
            }
            bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action()));
        }
    }
    // Remove notifications
    bp_core_delete_notifications_by_type(bp_loggedin_user_id(), 'groups', 'group_invite');
    do_action('groups_screen_group_invites', $group_id);
    bp_core_load_template(apply_filters('groups_template_group_invites', 'members/single/home'));
}
示例#26
0
/**
 * Generate any blog RSS feed via one function
 *
 * @param stdClass $context The context of the blog for which the feed it being generated
 * @param array    $args    An array of arguements needed to build the feed (contextid, token, componentname, type, id, tagid)
 */
function blog_rss_get_feed($context, $args)
{
    global $CFG, $SITE, $DB;
    if (empty($CFG->bloglevel)) {
        debugging('Blogging disabled on this site, RSS feeds are not available');
        return null;
    }
    if (empty($CFG->enablerssfeeds)) {
        debugging('Sorry, RSS feeds are disabled on this site');
        return '';
    }
    if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
        if (isguestuser()) {
            debugging(get_string('nopermissiontoshow', 'error'));
            return '';
        }
    }
    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
    if (!has_capability('moodle/blog:view', $sitecontext)) {
        return null;
    }
    $type = clean_param($args[3], PARAM_ALPHA);
    $id = clean_param($args[4], PARAM_INT);
    // could be groupid / courseid  / userid  depending on $type
    $tagid = 0;
    if ($args[5] != 'rss.xml') {
        $tagid = clean_param($args[5], PARAM_INT);
    } else {
        $tagid = 0;
    }
    $filename = blog_rss_file_name($type, $id, $tagid);
    if (file_exists($filename)) {
        if (filemtime($filename) + 3600 > time()) {
            return $filename;
            // It's already done so we return cached version
        }
    }
    $courseid = $groupid = $userid = null;
    switch ($type) {
        case 'site':
            //$siteid = $id;
            break;
        case 'course':
            $courseid = $id;
            break;
        case 'group':
            $groupid = $id;
            break;
        case 'user':
            $userid = $id;
            break;
    }
    // Get all the entries from the database
    require_once $CFG->dirroot . '/blog/locallib.php';
    $blogheaders = blog_get_headers($courseid, $groupid, $userid, $tagid);
    $bloglisting = new blog_listing($blogheaders['filters']);
    $blogentries = $bloglisting->get_entries();
    // Now generate an array of RSS items
    if ($blogentries) {
        $items = array();
        foreach ($blogentries as $blog_entry) {
            $item = NULL;
            $item->author = fullname($DB->get_record('user', array('id' => $blog_entry->userid)));
            // TODO: this is slow
            $item->title = $blog_entry->subject;
            $item->pubdate = $blog_entry->lastmodified;
            $item->link = $CFG->wwwroot . '/blog/index.php?entryid=' . $blog_entry->id;
            $summary = file_rewrite_pluginfile_urls($blog_entry->summary, 'pluginfile.php', $sitecontext->id, 'blog', 'post', $blog_entry->id);
            $item->description = format_text($summary, $blog_entry->format);
            if (!empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id))) {
                if ($blogtags) {
                    $item->tags = $blogtags;
                }
                $item->tagscheme = $CFG->wwwroot . '/tag';
            }
            $items[] = $item;
        }
        $articles = rss_add_items($items);
        /// Change structure to XML
    } else {
        $articles = '';
    }
    /// Get header and footer information
    switch ($type) {
        case 'user':
            $info = fullname($DB->get_record('user', array('id' => $id), 'firstname,lastname'));
            break;
        case 'course':
            $info = $DB->get_field('course', 'fullname', array('id' => $id));
            $info = format_string($info, true, array('context' => get_context_instance(CONTEXT_COURSE, $id)));
            break;
        case 'site':
            $info = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
            break;
        case 'group':
            $group = groups_get_group($id);
            $info = $group->name;
            //TODO: $DB->get_field('groups', 'name', array('id'=>$id))
            break;
        default:
            $info = '';
            break;
    }
    if ($tagid) {
        $info .= ': ' . $DB->get_field('tags', 'text', array('id' => $tagid));
    }
    $header = rss_standard_header(get_string($type . 'blog', 'blog', $info), $CFG->wwwroot . '/blog/index.php', get_string('intro', 'blog'));
    $footer = rss_standard_footer();
    // Save the XML contents to file.
    $rssdata = $header . $articles . $footer;
    if (blog_rss_save_file($type, $id, $tagid, $rssdata)) {
        return $filename;
    } else {
        return false;
        // Couldn't find it or make it
    }
}
示例#27
0
    if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
        print_error('invalidcourseid');
    }
    $courseid = $course->id;
    require_login($course);
    if (!has_capability('moodle/blog:view', $sitecontext)) {
        print_error('cannotviewcourseblog', 'blog');
    }
} else {
    $coursecontext = context_course::instance(SITEID);
}
if (!empty($groupid)) {
    if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
        print_error('groupblogdisable', 'blog');
    }
    if (!($group = groups_get_group($groupid))) {
        print_error(get_string('invalidgroupid', 'blog'));
    }
    if (!($course = $DB->get_record('course', array('id' => $group->courseid)))) {
        print_error('invalidcourseid');
    }
    $coursecontext = context_course::instance($course->id);
    $courseid = $course->id;
    require_login($course);
    if (!has_capability('moodle/blog:view', $sitecontext)) {
        print_error(get_string('cannotviewcourseorgroupblog', 'blog'));
    }
    if (groups_get_course_groupmode($course) == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $coursecontext)) {
        if (!groups_is_member($groupid)) {
            print_error('notmemberofgroup');
        }
示例#28
0
        $select = new single_select($baseurl, 'accesssince', $timeoptions, $accesssince, null, 'timeoptions');
        $select->set_label(get_string('usersnoaccesssince'));
        $controlstable->data[0]->cells[] = $OUTPUT->render($select);
    }
}
$formatmenu = array('0' => get_string('brief'), '1' => get_string('userdetails'));
$select = new single_select($baseurl, 'mode', $formatmenu, $mode, null, 'formatmenu');
$select->set_label(get_string('userlist'));
$userlistcell = new html_table_cell();
$userlistcell->attributes['class'] = 'right';
$userlistcell->text = $OUTPUT->render($select);
$controlstable->data[0]->cells[] = $userlistcell;
echo html_writer::table($controlstable);
if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', $context))) {
    // Display info about the group.
    if ($group = groups_get_group($currentgroup)) {
        if (!empty($group->description) or !empty($group->picture) and empty($group->hidepicture)) {
            $groupinfotable = new html_table();
            $groupinfotable->attributes['class'] = 'groupinfobox';
            $picturecell = new html_table_cell();
            $picturecell->attributes['class'] = 'left side picture';
            $picturecell->text = print_group_picture($group, $course->id, true, true, false);
            $contentcell = new html_table_cell();
            $contentcell->attributes['class'] = 'content';
            $contentheading = $group->name;
            if (has_capability('moodle/course:managegroups', $context)) {
                $aurl = new moodle_url('/group/group.php', array('id' => $group->id, 'courseid' => $group->courseid));
                $contentheading .= '&nbsp;' . $OUTPUT->action_icon($aurl, new pix_icon('t/edit', get_string('editgroupprofile')));
            }
            $group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
            if (!isset($group->descriptionformat)) {
示例#29
0
 /**
  * Set up items for display in the list table.
  *
  * Handles filtering of data, sorting, pagination, and any other data
  * manipulation required prior to rendering.
  *
  * @since 1.7.0
  */
 public function prepare_items()
 {
     global $groups_template;
     $screen = get_current_screen();
     // Option defaults
     $include_id = false;
     $search_terms = false;
     // Set current page
     $page = $this->get_pagenum();
     // Set per page from the screen options
     $per_page = $this->get_items_per_page(str_replace('-', '_', "{$screen->id}_per_page"));
     // Sort order.
     $order = 'DESC';
     if (!empty($_REQUEST['order'])) {
         $order = 'desc' == strtolower($_REQUEST['order']) ? 'DESC' : 'ASC';
     }
     // Order by - default to newest
     $orderby = 'last_activity';
     if (!empty($_REQUEST['orderby'])) {
         switch ($_REQUEST['orderby']) {
             case 'name':
                 $orderby = 'name';
                 break;
             case 'id':
                 $orderby = 'date_created';
                 break;
             case 'members':
                 $orderby = 'total_member_count';
                 break;
             case 'last_active':
                 $orderby = 'last_activity';
                 break;
         }
     }
     // Are we doing a search?
     if (!empty($_REQUEST['s'])) {
         $search_terms = $_REQUEST['s'];
     }
     // Check if user has clicked on a specific group (if so, fetch only that group).
     if (!empty($_REQUEST['gid'])) {
         $include_id = (int) $_REQUEST['gid'];
     }
     // Set the current view
     if (isset($_GET['group_status']) && in_array($_GET['group_status'], array('public', 'private', 'hidden'))) {
         $this->view = $_GET['group_status'];
     }
     // We'll use the ids of group types for the 'include' param
     $this->group_type_ids = BP_Groups_Group::get_group_type_ids();
     // Pass a dummy array if there are no groups of this type
     $include = false;
     if ('all' != $this->view && isset($this->group_type_ids[$this->view])) {
         $include = !empty($this->group_type_ids[$this->view]) ? $this->group_type_ids[$this->view] : array(0);
     }
     // Get group type counts for display in the filter tabs
     $this->group_counts = array();
     foreach ($this->group_type_ids as $group_type => $group_ids) {
         $this->group_counts[$group_type] = count($group_ids);
     }
     // If we're viewing a specific group, flatten all activities into a single array.
     if ($include_id) {
         $groups = array((array) groups_get_group('group_id=' . $include_id));
     } else {
         $groups_args = array('include' => $include, 'per_page' => $per_page, 'page' => $page, 'orderby' => $orderby, 'order' => $order);
         $groups = array();
         if (bp_has_groups($groups_args)) {
             while (bp_groups()) {
                 bp_the_group();
                 $groups[] = (array) $groups_template->group;
             }
         }
     }
     // Set raw data to display
     $this->items = $groups;
     // Store information needed for handling table pagination
     $this->set_pagination_args(array('per_page' => $per_page, 'total_items' => $groups_template->total_group_count, 'total_pages' => ceil($groups_template->total_group_count / $per_page)));
 }
示例#30
0
/**
 * Prints the discussion view screen for a forum.
 *
 * @global object
 * @global object
 * @param object $course The current course object.
 * @param object $forum Forum to be printed.
 * @param int $maxdiscussions .
 * @param string $displayformat The display format to use (optional).
 * @param string $sort Sort arguments for database query (optional).
 * @param int $groupmode Group mode of the forum (optional).
 * @param void $unused (originally current group)
 * @param int $page Page mode, page to display (optional).
 * @param int $perpage The maximum number of discussions per page(optional)
 *
 */
function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $displayformat='plain', $sort='',
                                        $currentgroup=-1, $groupmode=-1, $page=-1, $perpage=100, $cm=NULL) {
    global $CFG, $USER, $OUTPUT;

    if (!$cm) {
        if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course)) {
            print_error('invalidcoursemodule');
        }
    }
    $context = context_module::instance($cm->id);

    if (empty($sort)) {
        $sort = "d.timemodified DESC";
    }

    $olddiscussionlink = false;

 // Sort out some defaults
    if ($perpage <= 0) {
        $perpage = 0;
        $page    = -1;
    }

    if ($maxdiscussions == 0) {
        // all discussions - backwards compatibility
        $page    = -1;
        $perpage = 0;
        if ($displayformat == 'plain') {
            $displayformat = 'header';  // Abbreviate display by default
        }

    } else if ($maxdiscussions > 0) {
        $page    = -1;
        $perpage = $maxdiscussions;
    }

    $fullpost = false;
    if ($displayformat == 'plain') {
        $fullpost = true;
    }


// Decide if current user is allowed to see ALL the current discussions or not

// First check the group stuff
    if ($currentgroup == -1 or $groupmode == -1) {
        $groupmode    = groups_get_activity_groupmode($cm, $course);
        $currentgroup = groups_get_activity_group($cm);
    }

    $groups = array(); //cache

// If the user can post discussions, then this is a good place to put the
// button for it. We do not show the button if we are showing site news
// and the current user is a guest.

    $canstart = forum_user_can_post_discussion($forum, $currentgroup, $groupmode, $cm, $context);
    if (!$canstart and $forum->type !== 'news') {
        if (isguestuser() or !isloggedin()) {
            $canstart = true;
        }
        if (!is_enrolled($context) and !is_viewing($context)) {
            // allow guests and not-logged-in to see the button - they are prompted to log in after clicking the link
            // normal users with temporary guest access see this button too, they are asked to enrol instead
            // do not show the button to users with suspended enrolments here
            $canstart = enrol_selfenrol_available($course->id);
        }
    }

    if ($canstart) {
        echo '<div class="singlebutton forumaddnew">';
        echo "<form id=\"newdiscussionform\" method=\"get\" action=\"$CFG->wwwroot/mod/forum/post.php\">";
        echo '<div>';
        echo "<input type=\"hidden\" name=\"forum\" value=\"$forum->id\" />";
        switch ($forum->type) {
            case 'news':
            case 'blog':
                $buttonadd = get_string('addanewtopic', 'forum');
                break;
            case 'qanda':
                $buttonadd = get_string('addanewquestion', 'forum');
                break;
            default:
                $buttonadd = get_string('addanewdiscussion', 'forum');
                break;
        }
        echo '<input type="submit" value="'.$buttonadd.'" />';
        echo '</div>';
        echo '</form>';
        echo "</div>\n";

    } else if (isguestuser() or !isloggedin() or $forum->type == 'news') {
        // no button and no info

    } else if ($groupmode and has_capability('mod/forum:startdiscussion', $context)) {
        // inform users why they can not post new discussion
        if ($currentgroup) {
            echo $OUTPUT->notification(get_string('cannotadddiscussion', 'forum'));
        } else {
            echo $OUTPUT->notification(get_string('cannotadddiscussionall', 'forum'));
        }
    }

// Get all the recent discussions we're allowed to see

    $getuserlastmodified = ($displayformat == 'header');

    if (! $discussions = forum_get_discussions($cm, $sort, $fullpost, null, $maxdiscussions, $getuserlastmodified, $page, $perpage) ) {
        echo '<div class="forumnodiscuss">';
        if ($forum->type == 'news') {
            echo '('.get_string('nonews', 'forum').')';
        } else if ($forum->type == 'qanda') {
            echo '('.get_string('noquestions','forum').')';
        } else {
            echo '('.get_string('nodiscussions', 'forum').')';
        }
        echo "</div>\n";
        return;
    }

// If we want paging
    if ($page != -1) {
        ///Get the number of discussions found
        $numdiscussions = forum_get_discussions_count($cm);

        ///Show the paging bar
        echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f=$forum->id");
        if ($numdiscussions > 1000) {
            // saves some memory on sites with very large forums
            $replies = forum_count_discussion_replies($forum->id, $sort, $maxdiscussions, $page, $perpage);
        } else {
            $replies = forum_count_discussion_replies($forum->id);
        }

    } else {
        $replies = forum_count_discussion_replies($forum->id);

        if ($maxdiscussions > 0 and $maxdiscussions <= count($discussions)) {
            $olddiscussionlink = true;
        }
    }

    $canviewparticipants = has_capability('moodle/course:viewparticipants',$context);

    $strdatestring = get_string('strftimerecentfull');

    // Check if the forum is tracked.
    if ($cantrack = forum_tp_can_track_forums($forum)) {
        $forumtracked = forum_tp_is_tracked($forum);
    } else {
        $forumtracked = false;
    }

    if ($forumtracked) {
        $unreads = forum_get_discussions_unread($cm);
    } else {
        $unreads = array();
    }

    if ($displayformat == 'header') {
        echo '<table cellspacing="0" class="forumheaderlist">';
        echo '<thead>';
        echo '<tr>';
        echo '<th class="header topic" scope="col">'.get_string('discussion', 'forum').'</th>';
        echo '<th class="header author" colspan="2" scope="col">'.get_string('startedby', 'forum').'</th>';
        if ($groupmode > 0) {
            echo '<th class="header group" scope="col">'.get_string('group').'</th>';
        }
        if (has_capability('mod/forum:viewdiscussion', $context)) {
            echo '<th class="header replies" scope="col">'.get_string('replies', 'forum').'</th>';
            // If the forum can be tracked, display the unread column.
            if ($cantrack) {
                echo '<th class="header replies" scope="col">'.get_string('unread', 'forum');
                if ($forumtracked) {
                    echo '<a title="'.get_string('markallread', 'forum').
                         '" href="'.$CFG->wwwroot.'/mod/forum/markposts.php?f='.
                         $forum->id.'&amp;mark=read&amp;returnpage=view.php">'.
                         '<img src="'.$OUTPUT->pix_url('t/markasread') . '" class="iconsmall" alt="'.get_string('markallread', 'forum').'" /></a>';
                }
                echo '</th>';
            }
        }
        echo '<th class="header lastpost" scope="col">'.get_string('lastpost', 'forum').'</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
    }

    foreach ($discussions as $discussion) {
        if (!empty($replies[$discussion->discussion])) {
            $discussion->replies = $replies[$discussion->discussion]->replies;
            $discussion->lastpostid = $replies[$discussion->discussion]->lastpostid;
        } else {
            $discussion->replies = 0;
        }

        // SPECIAL CASE: The front page can display a news item post to non-logged in users.
        // All posts are read in this case.
        if (!$forumtracked) {
            $discussion->unread = '-';
        } else if (empty($USER)) {
            $discussion->unread = 0;
        } else {
            if (empty($unreads[$discussion->discussion])) {
                $discussion->unread = 0;
            } else {
                $discussion->unread = $unreads[$discussion->discussion];
            }
        }

        if (isloggedin()) {
            $ownpost = ($discussion->userid == $USER->id);
        } else {
            $ownpost=false;
        }
        // Use discussion name instead of subject of first post
        $discussion->subject = $discussion->name;

        switch ($displayformat) {
            case 'header':
                if ($groupmode > 0) {
                    if (isset($groups[$discussion->groupid])) {
                        $group = $groups[$discussion->groupid];
                    } else {
                        $group = $groups[$discussion->groupid] = groups_get_group($discussion->groupid);
                    }
                } else {
                    $group = -1;
                }
                forum_print_discussion_header($discussion, $forum, $group, $strdatestring, $cantrack, $forumtracked,
                    $canviewparticipants, $context);
            break;
            default:
                $link = false;

                if ($discussion->replies) {
                    $link = true;
                } else {
                    $modcontext = context_module::instance($cm->id);
                    $link = forum_user_can_see_discussion($forum, $discussion, $modcontext, $USER);
                }

                $discussion->forum = $forum->id;

                forum_print_post($discussion, $discussion, $forum, $cm, $course, $ownpost, 0, $link, false,
                        '', null, true, $forumtracked);
            break;
        }
    }

    if ($displayformat == "header") {
        echo '</tbody>';
        echo '</table>';
    }

    if ($olddiscussionlink) {
        if ($forum->type == 'news') {
            $strolder = get_string('oldertopics', 'forum');
        } else {
            $strolder = get_string('olderdiscussions', 'forum');
        }
        echo '<div class="forumolddiscuss">';
        echo '<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id.'&amp;showall=1">';
        echo $strolder.'</a> ...</div>';
    }

    if ($page != -1) { ///Show the paging bar
        echo $OUTPUT->paging_bar($numdiscussions, $page, $perpage, "view.php?f=$forum->id");
    }
}