function bp_activity_template($type, $user_id, $per_page, $max, $timeframe)
 {
     global $bp;
     $this->pag_page = isset($_REQUEST['acpage']) ? intval($_REQUEST['acpage']) : 1;
     $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page;
     $this->filter_content = false;
     $this->activity_type = $type;
     if ($type == 'sitewide') {
         $this->activities = bp_activity_get_sitewide_activity($max, $this->pag_num, $this->pag_page);
     }
     if ($type == 'personal') {
         $this->activities = bp_activity_get_user_activity($user_id, $timeframe, $this->page_num, $this->pag_page);
     }
     if ($type == 'friends' && (bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id)) {
         $this->activities = bp_activity_get_friends_activity($user_id, $timeframe, $this->pag_num, $this->pag_page);
     }
     if (!$max) {
         $this->total_activity_count = (int) $this->activities['total'];
     } else {
         $this->total_activity_count = (int) $max;
     }
     $this->activities = $this->activities['activities'];
     if ($max) {
         if ($max >= count($this->activities)) {
             $this->activity_count = count($this->activities);
         } else {
             $this->activity_count = (int) $max;
         }
     } else {
         $this->activity_count = count($this->activities);
     }
     $this->full_name = $bp->displayed_user->fullname;
     $this->pag_links = paginate_links(array('base' => add_query_arg('acpage', '%#%'), 'format' => '', 'total' => ceil((int) $this->total_activity_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => '«', 'next_text' => '»', 'mid_size' => 1));
 }
 function get_sitewide_items_for_feed($limit = 35)
 {
     global $wpdb, $bp;
     $activities = bp_activity_get_sitewide_activity($limit);
     for ($i = 0; $i < count($activities); $i++) {
         $title = explode('<span', $activities[$i]['content']);
         $activity_feed[$i]['title'] = trim(strip_tags($title[0]));
         $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
         $activity_feed[$i]['description'] = @sprintf($activities[$i]['content'], '');
         $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
     }
     return $activity_feed;
 }
function bp_activity_widget_sitewide_activity($args)
{
    global $bp, $current_blog;
    extract($args);
    $options = get_blog_option($current_blog->blog_id, 'bp_activity_widget_sitewide_activity');
    ?>
	<?php 
    echo $before_widget;
    ?>
	<?php 
    echo $before_title . $widget_name . $after_title;
    ?>
		
	<?php 
    if (empty($options['max_items'])) {
        $options['max_items'] = 20;
    }
    ?>
	
	<?php 
    if (!($activity = wp_cache_get('sitewide_activity', 'bp'))) {
        $activity = bp_activity_get_sitewide_activity($options['max_items']);
        wp_cache_set('sitewide_activity', $activity, 'bp');
    }
    ?>

	<?php 
    if ($activity['activities']) {
        ?>
		<div class="item-options" id="activity-list-options">
			<img src="<?php 
        echo $bp->activity->image_base;
        ?>
/rss.png" alt="<?php 
        _e('RSS Feed', 'buddypress');
        ?>
" /> <a href="<?php 
        bp_sitewide_activity_feed_link();
        ?>
" title="<?php 
        _e('Site Wide Activity RSS Feed', 'buddypress');
        ?>
"><?php 
        _e('RSS Feed', 'buddypress');
        ?>
</a>
		</div>
		<ul id="site-wide-stream" class="activity-list">
		<?php 
        foreach ($activity['activities'] as $item) {
            ?>
			<li class="<?php 
            echo $item['component_name'];
            ?>
">
				<?php 
            echo apply_filters('bp_get_activity_content', bp_activity_content_filter($item['content'], $item['date_recorded'], '', true, false, true));
            ?>
			</li>
		<?php 
        }
        ?>
		</ul>
	<?php 
    } else {
        ?>
		<div class="widget-error">
			<?php 
        _e('There has been no recent site activity.', 'buddypress');
        ?>
		</div>
	<?php 
    }
    ?>

	<?php 
    echo $after_widget;
}