Пример #1
0
/**
 * Format 'new_blog' activity actions.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param string $action Static activity action.
 * @param obj $activity Activity data object.
 */
function bp_blogs_format_activity_action_new_blog( $action, $activity ) {
	$blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
	$blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );

	$action = sprintf( __( '%s created the site %s', 'buddypress' ), bp_core_get_userlink( $activity->user_id ), '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );

	// Legacy filter - requires the BP_Blogs_Blog object
	if ( has_filter( 'bp_blogs_activity_created_blog_action' ) ) {
		$user_blog = BP_Blogs_Blog::get_user_blog( $activity->user_id, $activity->item_id );
		if ( $user_blog ) {
			$recorded_blog = new BP_Blogs_Blog( $user_blog );
		}

		if ( isset( $recorded_blog ) ) {
			$action = apply_filters( 'bp_blogs_activity_created_blog_action', $action, $recorded_blog, $blog_name, bp_blogs_get_blogmeta( $activity->item_id, 'description' ) );
		}
	}

	/**
	 * Filters the new blog activity action for the new blog.
	 *
	 * @since BuddyPress (2.0.0)
	 *
	 * @param string $action   Constructed activity action.
	 * @param obj    $activity Activity data object.
	 */
	return apply_filters( 'bp_blogs_format_activity_action_new_blog', $action, $activity );
}
Пример #2
0
/**
 * Format 'new_blog' activity actions.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param string $action Static activity action.
 * @param obj $activity Activity data object.
 */
function bp_blogs_format_activity_action_new_blog($action, $activity)
{
    $blog_url = bp_blogs_get_blogmeta($activity->item_id, 'url');
    $blog_name = bp_blogs_get_blogmeta($activity->item_id, 'name');
    $action = sprintf(__('%s created the site %s', 'buddypress'), bp_core_get_userlink($activity->user_id), '<a href="' . esc_url($blog_url) . '">' . esc_html($blog_name) . '</a>');
    // Legacy filter - requires the BP_Blogs_Blog object
    if (has_filter('bp_blogs_activity_created_blog_action')) {
        $user_blog = BP_Blogs_Blog::get_user_blog($activity->user_id, $activity->item_id);
        if ($user_blog) {
            $recorded_blog = new BP_Blogs_Blog($user_blog);
        }
        if (isset($recorded_blog)) {
            $action = apply_filters('bp_blogs_activity_created_blog_action', $action, $recorded_blog, $blog_name, bp_blogs_get_blogmeta($activity->item_id, 'description'));
        }
    }
    return apply_filters('bp_blogs_format_activity_action_new_blog', $action, $activity);
}
Пример #3
0
	function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) {
		global $bp;

		$this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
		$this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;

		if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
			$this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
		else
			$this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );

		if ( !$max || $max >= (int)$this->blogs['total'] )
			$this->total_blog_count = (int)$this->blogs['total'];
		else
			$this->total_blog_count = (int)$max;

		$this->blogs = $this->blogs['blogs'];

		if ( $max ) {
			if ( $max >= count($this->blogs) ) {
				$this->blog_count = count( $this->blogs );
			} else {
				$this->blog_count = (int)$max;
			}
		} else {
			$this->blog_count = count( $this->blogs );
		}

		if ( (int)$this->total_blog_count && (int)$this->pag_num ) {
			$this->pag_links = paginate_links( array(
				'base'      => add_query_arg( 'bpage', '%#%' ),
				'format'    => '',
				'total'     => ceil( (int)$this->total_blog_count / (int)$this->pag_num ),
				'current'   => (int)$this->pag_page,
				'prev_text' => '&larr;',
				'next_text' => '&rarr;',
				'mid_size'  => 1
			) );
		}
	}
Пример #4
0
 function get_blogs_for_user($user_id = null)
 {
     global $bp, $wpdb;
     if (!$bp->blogs) {
         bp_blogs_setup_globals();
     }
     if (!$user_id) {
         $user_id = $bp->displayed_user->id;
     }
     // Show logged in users their hidden blogs.
     if (!bp_is_home()) {
         $blog_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id));
     } else {
         $blog_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ", $user_id));
     }
     $total_blog_count = BP_Blogs_Blog::total_blog_count($user_id);
     for ($i = 0; $i < count($blog_ids); $i++) {
         $blogs[] = array('id' => $blog_ids[$i], 'siteurl' => get_blog_option($blog_ids[$i], 'siteurl'), 'title' => get_blog_option($blog_ids[$i], 'blogname'), 'description' => get_blog_option($blog_ids[$i], 'blogdescription'));
     }
     return array('blogs' => $blogs, 'count' => $total_blog_count);
 }
Пример #5
0
function bp_blogs_remove_data($user_id)
{
    if (!is_multisite()) {
        return false;
    }
    do_action('bp_blogs_before_remove_data', $user_id);
    // If this is regular blog, delete all data for that blog.
    BP_Blogs_Blog::delete_blogs_for_user($user_id);
    do_action('bp_blogs_remove_data', $user_id);
}
Пример #6
0
 /**
  * Constructor method.
  *
  * @see BP_Blogs_Blog::get() for a description of parameters.
  *
  * @param string     $type              See {@link BP_Blogs_Blog::get()}.
  * @param string     $page              See {@link BP_Blogs_Blog::get()}.
  * @param string     $per_page          See {@link BP_Blogs_Blog::get()}.
  * @param string     $max               See {@link BP_Blogs_Blog::get()}.
  * @param string     $user_id           See {@link BP_Blogs_Blog::get()}.
  * @param string     $search_terms      See {@link BP_Blogs_Blog::get()}.
  * @param string     $page_arg          The string used as a query parameter in
  *                                      pagination links. Default: 'bpage'.
  * @param bool       $update_meta_cache Whether to pre-fetch metadata for
  *                                      queried blogs.
  * @param array|bool $include_blog_ids  Array of blog IDs to include.
  */
 public function __construct($type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false)
 {
     $this->pag_arg = sanitize_key($page_arg);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page);
     $this->pag_num = bp_sanitize_pagination_arg('num', $per_page);
     // Backwards compatibility support for blogs by first letter
     if (!empty($_REQUEST['letter'])) {
         $this->blogs = BP_Blogs_Blog::get_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page);
         // Typical blogs query
     } else {
         $this->blogs = bp_blogs_get_blogs(array('type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'update_meta_cache' => $update_meta_cache, 'include_blog_ids' => $include_blog_ids));
     }
     // Set the total blog count
     if (empty($max) || $max >= (int) $this->blogs['total']) {
         $this->total_blog_count = (int) $this->blogs['total'];
     } else {
         $this->total_blog_count = (int) $max;
     }
     // Set the blogs array (to loop through later
     $this->blogs = $this->blogs['blogs'];
     // Get the current blog count to compare maximum against
     $blog_count = count($this->blogs);
     // Set the current blog count
     if (empty($max) || $max >= (int) $blog_count) {
         $this->blog_count = (int) $blog_count;
     } else {
         $this->blog_count = (int) $max;
     }
     // Build pagination links based on total blogs and current page number
     if (!empty($this->total_blog_count) && !empty($this->pag_num)) {
         $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_blog_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('&larr;', 'Blog pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Blog pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => array()));
     }
 }
 /**
  * Get all of a user's blogs, as tracked by BuddyPress.
  *
  * Note that this is different from the WordPress function
  * {@link get_blogs_of_user()}; the current method returns only those
  * blogs that have been recorded by BuddyPress, while the WP function
  * does a true query of a user's blog capabilities.
  *
  * @param int  $user_id     Optional. ID of the user whose blogs are being
  *                          queried. Defaults to logged-in user.
  * @param bool $show_hidden Optional. Whether to include blogs that are not marked
  *                          public. Defaults to true when viewing one's own profile.
  * @return array Multidimensional results array, structured as follows:
  *               'blogs' - Array of located blog objects.
  *               'total' - A count of the total blogs for the user.
  */
 public static function get_blogs_for_user($user_id = 0, $show_hidden = false)
 {
     global $wpdb;
     $bp = buddypress();
     if (!$user_id) {
         $user_id = bp_displayed_user_id();
     }
     // Show logged in users their hidden blogs.
     if (!bp_is_my_profile() && !$show_hidden) {
         $blogs = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id));
     } else {
         $blogs = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id));
     }
     $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user($user_id);
     $user_blogs = array();
     foreach ((array) $blogs as $blog) {
         $user_blogs[$blog->blog_id] = new stdClass();
         $user_blogs[$blog->blog_id]->id = $blog->id;
         $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
         $user_blogs[$blog->blog_id]->siteurl = is_ssl() ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
         $user_blogs[$blog->blog_id]->name = $blog->name;
     }
     return array('blogs' => $user_blogs, 'count' => $total_blog_count);
 }
 /**
  * @group get_order_by
  */
 public function test_get_order_by()
 {
     if (!is_multisite()) {
         return;
     }
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $bs = array('foobar' => $this->factory->blog->create(array('title' => 'Foo Bar Blog', 'user_id' => $u, 'path' => '/path' . rand() . time() . '/')), 'barfoo' => $this->factory->blog->create(array('title' => 'Bar foo Blog', 'user_id' => $u, 'path' => '/path' . rand() . time() . '/')));
     bp_blogs_record_existing_blogs();
     // make the blog public or it won't turn up in generic results
     foreach ($bs as $b) {
         update_blog_option($b, 'blog_public', '1');
     }
     // Used to make sure barfoo is older than foobar
     $b_time = date_i18n('Y-m-d H:i:s', strtotime('-5 minutes'));
     /* Alphabetical */
     $blogs = BP_Blogs_Blog::get('alphabetical', false, false, $u);
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($bs['barfoo'], $bs['foobar']), $blog_ids);
     /* Newest */
     update_blog_details($bs['barfoo'], array('registered' => $b_time));
     $blogs = BP_Blogs_Blog::get('newest', false, false, $u);
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($bs['foobar'], $bs['barfoo']), $blog_ids);
     /* Active */
     bp_blogs_update_blogmeta($bs['barfoo'], 'last_activity', $b_time);
     $blogs = BP_Blogs_Blog::get('active', false, false, $u);
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($bs['foobar'], $bs['barfoo']), $blog_ids);
     /* Random */
     $blogs = BP_Blogs_Blog::get('random', false, false, $u);
     $this->assertTrue(2 == count($blogs['blogs']));
     $this->set_current_user($old_user);
 }
Пример #9
0
/**
 * Remove all blog associations for a given user.
 *
 * @param int $user_id ID whose blog data should be removed.
 * @return bool|null Returns false on failure.
 */
function bp_blogs_remove_data($user_id)
{
    if (!is_multisite()) {
        return false;
    }
    /**
     * Fires before all blog associations are removed for a given user.
     *
     * @since BuddyPress (1.5.0)
     *
     * @param int $user_id ID of the user whose blog associations are being removed.
     */
    do_action('bp_blogs_before_remove_data', $user_id);
    // If this is regular blog, delete all data for that blog.
    BP_Blogs_Blog::delete_blogs_for_user($user_id);
    /**
     * Fires after all blog associations are removed for a given user.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param int $user_id ID of the user whose blog associations were removed.
     */
    do_action('bp_blogs_remove_data', $user_id);
}
Пример #10
0
function bp_blogs_remove_data( $user_id ) {
	if ( !bp_core_is_multisite() )
		return false;

	/* If this is regular blog, delete all data for that blog. */
	BP_Blogs_Blog::delete_blogs_for_user( $user_id );

	do_action( 'bp_blogs_remove_data', $user_id );
}
Пример #11
0
 /**
  * Constructor method.
  *
  * @see BP_Blogs_Blog::get() for a description of parameters.
  *
  * @param string $type See {@link BP_Blogs_Blog::get()}.
  * @param string $page See {@link BP_Blogs_Blog::get()}.
  * @param string $per_page See {@link BP_Blogs_Blog::get()}.
  * @param string $max See {@link BP_Blogs_Blog::get()}.
  * @param string $user_id See {@link BP_Blogs_Blog::get()}.
  * @param string $search_terms See {@link BP_Blogs_Blog::get()}.
  * @param string $page_arg The string used as a query parameter in
  *        pagination links. Default: 'bpage'.
  * @param bool $update_meta_cache Whether to pre-fetch metadata for
  *        queried blogs.
  * @param array $include_blog_ids Array of blog IDs to include.
  */
 function __construct($type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false)
 {
     $this->pag_page = isset($_REQUEST[$page_arg]) ? intval($_REQUEST[$page_arg]) : $page;
     $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page;
     if (isset($_REQUEST['letter']) && '' != $_REQUEST['letter']) {
         $this->blogs = BP_Blogs_Blog::get_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page);
     } else {
         $this->blogs = bp_blogs_get_blogs(array('type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'update_meta_cache' => $update_meta_cache, 'include_blog_ids' => $include_blog_ids));
     }
     if (!$max || $max >= (int) $this->blogs['total']) {
         $this->total_blog_count = (int) $this->blogs['total'];
     } else {
         $this->total_blog_count = (int) $max;
     }
     $this->blogs = $this->blogs['blogs'];
     if ($max) {
         if ($max >= count($this->blogs)) {
             $this->blog_count = count($this->blogs);
         } else {
             $this->blog_count = (int) $max;
         }
     } else {
         $this->blog_count = count($this->blogs);
     }
     if ((int) $this->total_blog_count && (int) $this->pag_num) {
         $this->pag_links = paginate_links(array('base' => add_query_arg($page_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_blog_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('&larr;', 'Blog pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Blog pagination next text', 'buddypress'), 'mid_size' => 1));
     }
 }
Пример #12
0
 /**
  * @group bp_blogs_remove_blog_for_user
  */
 public function test_bp_blogs_remove_blog_for_user_is_contributor()
 {
     if (!is_multisite()) {
         return;
     }
     $reset_post = $_POST;
     $old_user = get_current_user_id();
     // Simulate a new "BuddyPress generated" blog
     $_POST['blog_public'] = 1;
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     // Create three sites.
     $b = $this->factory->blog->create(array('user_id' => $u));
     $u2 = $this->factory->user->create();
     add_user_to_blog($b, $u2, 'contributor');
     $u2_blogs = BP_Blogs_Blog::get_blog_ids_for_user($u2);
     $this->assertContains($b, $u2_blogs, 'The user should be associated to the blog as he is a contributor');
     remove_user_from_blog($u2, $b);
     $u2_blogs = BP_Blogs_Blog::get_blog_ids_for_user($u2);
     $this->assertNotContains($b, $u2_blogs, 'The user should not be associated anymore to the blog');
     $activity = bp_activity_get(array('filter' => array('object' => 'blogs', 'action' => 'new_blog', 'primary_id' => $b)));
     $new_blog = array_map('intval', wp_list_pluck($activity['activities'], 'item_id', 'id'));
     $this->assertSame($b, reset($new_blog), 'The new_blog activity should not be deleted when a contributor is removed from the blog.');
     $_POST = $reset_post;
     $this->set_current_user($old_user);
 }
Пример #13
0
function bp_blogs_remove_data($user_id)
{
    /* If this is regular blog, delete all data for that blog. */
    BP_Blogs_Blog::delete_blogs_for_user($user_id);
    BP_Blogs_Post::delete_posts_for_user($user_id);
    BP_Blogs_Comment::delete_comments_for_user($user_id);
    do_action('bp_blogs_remove_data', $user_id);
}
Пример #14
0
 /**
  * @group bp_blogs_format_activity_action_new_blog
  */
 public function test_bp_activity_format_activity_action_new_blog_backpat()
 {
     if (!is_multisite()) {
         return;
     }
     add_filter('bp_blogs_activity_created_blog_action', array($this, 'created_blog_passthrough'), 10, 2);
     $b = $this->factory->blog->create();
     $u = $this->factory->user->create();
     $recorded_blog = new BP_Blogs_Blog();
     $recorded_blog->user_id = $u;
     $recorded_blog->blog_id = $b;
     $recorded_blog_id = $recorded_blog->save();
     $a = $this->factory->activity->create(array('component' => buddypress()->blogs->id, 'type' => 'new_blog', 'user_id' => $u, 'item_id' => $b));
     $this->assertEquals($this->userblog_id, $recorded_blog_id);
 }
 function bp_blogs_site_blogs_template($type, $per_page, $max)
 {
     global $bp;
     $this->pag_page = isset($_REQUEST['bpage']) ? intval($_REQUEST['bpage']) : 1;
     $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page;
     if (isset($_REQUEST['s']) && '' != $_REQUEST['s'] && $type != 'random') {
         $this->blogs = BP_Blogs_Blog::search_blogs($_REQUEST['s'], $this->pag_num, $this->pag_page);
     } else {
         if (isset($_REQUEST['letter']) && '' != $_REQUEST['letter']) {
             $this->blogs = BP_Blogs_Blog::get_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page);
         } else {
             switch ($type) {
                 case 'random':
                     $this->blogs = BP_Blogs_Blog::get_random($this->pag_num, $this->pag_page);
                     break;
                 case 'newest':
                     $this->blogs = BP_Blogs_Blog::get_newest($this->pag_num, $this->pag_page);
                     break;
                 case 'active':
                 default:
                     $this->blogs = BP_Blogs_Blog::get_active($this->pag_num, $this->pag_page);
                     break;
             }
         }
     }
     if (!$max) {
         $this->total_blog_count = (int) $this->blogs['total'];
     } else {
         $this->total_blog_count = (int) $max;
     }
     $this->blogs = $this->blogs['blogs'];
     if ($max) {
         if ($max >= count($this->blogs)) {
             $this->blog_count = count($this->blogs);
         } else {
             $this->blog_count = (int) $max;
         }
     } else {
         $this->blog_count = count($this->blogs);
     }
     $this->pag_links = paginate_links(array('base' => add_query_arg('bpage', '%#%'), 'format' => '', 'total' => ceil((int) $this->total_blog_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => '&laquo;', 'next_text' => '&raquo;', 'mid_size' => 1));
 }