/**
  * @group get_recorded_components
  */
 public function test_get_recorded_components_skip_last_activity_true_la_in_multiple_components()
 {
     $a1 = $this->factory->activity->create(array('component' => 'members', 'action' => 'last_activity'));
     $a2 = $this->factory->activity->create(array('component' => 'groups', 'action' => 'created_group'));
     $a3 = $this->factory->activity->create(array('component' => 'friends', 'action' => 'friendship_accepted'));
     $a4 = $this->factory->activity->create(array('component' => 'groups', 'action' => 'last_activity'));
     $found = BP_Activity_Activity::get_recorded_components(true);
     sort($found);
     $this->assertSame(array('friends', 'groups'), BP_Activity_Activity::get_recorded_components());
 }
Esempio n. 2
0
/**
 * Return the activity filter links.
 *
 * @since 1.1.0
 *
 * @param array $args Defaults to false
 *
 * @global object $activities_template {@link BP_Activity_Template}
 * @global object $bp BuddyPress global settings
 * @uses nxt_parse_args()
 * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
 * @uses esc_attr()
 * @uses add_query_arg()
 * @uses remove_query_arg()
 * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook
 * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook
 *
 * @return string|bool $component_links The activity filter links. False on failure
 */
function bp_get_activity_filter_links($args = false)
{
    global $activities_template, $bp;
    $defaults = array('style' => 'list');
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Fetch the names of components that have activity recorded in the DB
    $components = BP_Activity_Activity::get_recorded_components();
    if (!$components) {
        return false;
    }
    foreach ((array) $components as $component) {
        /* Skip the activity comment filter */
        if ('activity' == $component) {
            continue;
        }
        if (isset($_GET['afilter']) && $component == $_GET['afilter']) {
            $selected = ' class="selected"';
        } else {
            unset($selected);
        }
        $component = esc_attr($component);
        switch ($style) {
            case 'list':
                $tag = 'li';
                $before = '<li id="afilter-' . $component . '"' . $selected . '>';
                $after = '</li>';
                break;
            case 'paragraph':
                $tag = 'p';
                $before = '<p id="afilter-' . $component . '"' . $selected . '>';
                $after = '</p>';
                break;
            case 'span':
                $tag = 'span';
                $before = '<span id="afilter-' . $component . '"' . $selected . '>';
                $after = '</span>';
                break;
        }
        $link = add_query_arg('afilter', $component);
        $link = remove_query_arg('acpage', $link);
        $link = apply_filters('bp_get_activity_filter_link_href', $link, $component);
        // Make sure all core internal component names are translatable
        $translatable_components = array(__('xprofile', 'buddypress'), __('friends', 'buddypress'), __('groups', 'buddypress'), __('status', 'buddypress'), __('sites', 'buddypress'));
        $component_links[] = $before . '<a href="' . esc_attr($link) . '">' . ucwords(__($component, 'buddypress')) . '</a>' . $after;
    }
    $link = remove_query_arg('afilter', $link);
    if (isset($_GET['afilter'])) {
        $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr($link) . '">' . __('Clear Filter', 'buddypress') . '</a></' . $tag . '>';
    }
    return apply_filters('bp_get_activity_filter_links', implode("\n", $component_links));
}
    function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('title' => __('Site Wide Activities', 'swa'), 'max_items' => 200, 'per_page' => 25, 'is_personal' => 'no', 'is_blog_admin_activity' => 'no', 'show_avatar' => 'yes', 'show_feed_link' => 'yes', 'show_post_form' => 'no', 'allow_reply' => 'no', 'show_activity_filters' => 'yes', 'included_components' => false, 'excluded_components' => false));
        $per_page = strip_tags($instance['per_page']);
        $max_items = strip_tags($instance['max_items']);
        $title = strip_tags($instance['title']);
        extract($instance);
        ?>

                <p><label for="bp-swa-title"><strong><?php 
        _e('Title:', 'swa');
        ?>
 </strong><input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" style="width: 100%" /></label></p>
		<p><label for="bp-swa-per-page"><?php 
        _e('Number of Items Per Page:', 'swa');
        ?>
 <input class="widefat" id="<?php 
        echo $this->get_field_id('per_page');
        ?>
" name="<?php 
        echo $this->get_field_name('per_page');
        ?>
" type="text" value="<?php 
        echo esc_attr($per_page);
        ?>
" style="width: 30%" /></label></p>
		<p><label for="bp-swa-max"><?php 
        _e('Max items to show:', 'swa');
        ?>
 <input class="widefat" id="<?php 
        echo $this->get_field_id('max_items');
        ?>
" name="<?php 
        echo $this->get_field_name('max_items');
        ?>
" type="text" value="<?php 
        echo esc_attr($max_items);
        ?>
" style="width: 30%" /></label></p>
		 <p><label for="bp-swa-is-personal"><strong><?php 
        _e("Limit to Logged In user's activity:", 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('is_personal');
        ?>
" type="radio" <?php 
        if ($is_personal == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_no" name="<?php 
        echo $this->get_field_name('is_personal');
        ?>
" type="radio" <?php 
        if ($is_personal !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
                <p><label for="bp-swa-is-blog-admin-activity"><strong><?php 
        _e("List My Activity Only:", 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('is_blog_admin_activity');
        ?>
" type="radio" <?php 
        if ($is_blog_admin_activity == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_no" name="<?php 
        echo $this->get_field_name('is_blog_admin_activity');
        ?>
" type="radio" <?php 
        if ($is_blog_admin_activity !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
                <p><label for="bp-swa-show-avatar"><strong><?php 
        _e('Show Avatar:', 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_avatar');
        ?>
" type="radio" <?php 
        if ($show_avatar == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_avatar');
        ?>
" type="radio" <?php 
        if ($show_avatar !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>
                    
                    </label>
               </p>
               <p><label for="bp-swa-show-feed-link"><?php 
        _e('Show Feed Link:', 'swa');
        ?>
                       <label for="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_feed_link');
        ?>
" type="radio" <?php 
        if ($show_feed_link == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_feed_link');
        ?>
" type="radio" <?php 
        if ($show_feed_link !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
               <p><label for="bp-swa-show-post-form"><strong><?php 
        _e('Show Post Form', 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_post_form');
        ?>
" type="radio" <?php 
        if ($show_post_form == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_post_form');
        ?>
" type="radio" <?php 
        if ($show_post_form !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
               <!-- <p><label for="bp-swa-show-reply-link"><?php 
        _e('Allow reply to activity item:', 'swa');
        ?>
                       <label for="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('allow_reply');
        ?>
" type="radio" <?php 
        if ($show_feed_link == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_no" name="<?php 
        echo $this->get_field_name('allow_reply');
        ?>
" type="radio" <?php 
        if ($show_feed_link !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>-->
               <p><label for="bp-swa-show-activity-filters"><strong><?php 
        _e('Show Activity Filters:', 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_activity_filters');
        ?>
" type="radio" <?php 
        if ($show_activity_filters == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_activity_filters');
        ?>
" type="radio" <?php 
        if ($show_activity_filters !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
               <p><label for="bp-swa-included-filters"><strong><?php 
        _e('Include only following Filters:', 'swa');
        ?>
</strong></label></p>
                 <p>     <?php 
        $recorded_components = BP_Activity_Activity::get_recorded_components();
        foreach ((array) $recorded_components as $component) {
            ?>
                         <label for="<?php 
            echo $this->get_field_id('included_components') . '_' . $component;
            ?>
" ><?php 
            echo ucwords($component);
            ?>
 <input id="<?php 
            echo $this->get_field_id('included_components') . '_' . $component;
            ?>
" name="<?php 
            echo $this->get_field_name('included_components');
            ?>
[]" type="checkbox" <?php 
            if (is_array($included_components) && in_array($component, $included_components)) {
                echo "checked='checked'";
            }
            ?>
 value="<?php 
            echo $component;
            ?>
" style="width: 10%" /></label>
                       <?php 
        }
        ?>
                   
               </p>

              <p><label for="bp-swa-included-filters"><strong><?php 
        _e('Exclude following Components activity', 'swa');
        ?>
</strong></label></p>
                 <p>     <?php 
        $recorded_components = BP_Activity_Activity::get_recorded_components();
        foreach ((array) $recorded_components as $component) {
            ?>
                         <label for="<?php 
            echo $this->get_field_id('excluded_components') . '_' . $component;
            ?>
" ><?php 
            echo ucwords($component);
            ?>
 <input id="<?php 
            echo $this->get_field_id('excluded_components') . '_' . $component;
            ?>
" name="<?php 
            echo $this->get_field_name('excluded_components');
            ?>
[]" type="checkbox" <?php 
            if (is_array($excluded_components) && in_array($component, $excluded_components)) {
                echo "checked='checked'";
            }
            ?>
 value="<?php 
            echo $component;
            ?>
" style="width: 10%" /></label>
                       <?php 
        }
        ?>

               </p>
               
	<?php 
    }
/**
 * Return the activity filter links.
 *
 * @since BuddyPress (1.1.0)
 *
 * @uses wp_parse_args()
 * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
 * @uses esc_attr()
 * @uses add_query_arg()
 * @uses remove_query_arg()
 * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook.
 * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook.
 *
 * @param array $args {
 *     @type string $style The type of markup to use for the links.
 *           'list', 'paragraph', or 'span'. Default: 'list'.
 * }
 * @return string|bool $component_links The activity filter links.
 *         False on failure.
 */
function bp_get_activity_filter_links($args = false)
{
    $defaults = array('style' => 'list');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Define local variable
    $component_links = array();
    // Fetch the names of components that have activity recorded in the DB
    $components = BP_Activity_Activity::get_recorded_components();
    if (empty($components)) {
        return false;
    }
    foreach ((array) $components as $component) {
        // Skip the activity comment filter
        if ('activity' == $component) {
            continue;
        }
        if (isset($_GET['afilter']) && $component == $_GET['afilter']) {
            $selected = ' class="selected"';
        } else {
            unset($selected);
        }
        $component = esc_attr($component);
        switch ($style) {
            case 'list':
                $tag = 'li';
                $before = '<li id="afilter-' . $component . '"' . $selected . '>';
                $after = '</li>';
                break;
            case 'paragraph':
                $tag = 'p';
                $before = '<p id="afilter-' . $component . '"' . $selected . '>';
                $after = '</p>';
                break;
            case 'span':
                $tag = 'span';
                $before = '<span id="afilter-' . $component . '"' . $selected . '>';
                $after = '</span>';
                break;
        }
        $link = add_query_arg('afilter', $component);
        $link = remove_query_arg('acpage', $link);
        /**
         * Filters the activity filter link URL for the current activity component.
         *
         * @since BuddyPress (1.1.0)
         *
         * @param string $link The URL for the current component.
         * @param string $component The current component getting links constructed for.
         */
        $link = apply_filters('bp_get_activity_filter_link_href', $link, $component);
        $component_links[] = $before . '<a href="' . esc_url($link) . '">' . ucwords($component) . '</a>' . $after;
    }
    $link = remove_query_arg('afilter', $link);
    if (isset($_GET['afilter'])) {
        $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_url($link) . '">' . __('Clear Filter', 'buddypress') . '</a></' . $tag . '>';
    }
    /**
     * Filters all of the constructed filter links.
     *
     * @since BuddyPress (1.1.0)
     *
     * @param string $value All of the links to be displayed to the user.
     */
    return apply_filters('bp_get_activity_filter_links', implode("\n", $component_links));
}
function swa_get_base_component_scope($include, $exclude)
{
    /* Fetch the names of components that have activity recorded in the DB */
    $components = BP_Activity_Activity::get_recorded_components();
    if (!empty($include)) {
        $components = explode(",", $include);
    }
    //array of component names
    if (!empty($exclude)) {
        //exclude all the
        $components = array_diff((array) $components, explode(",", $exclude));
        //diff of exclude/recorded components
    }
    return $components;
}