コード例 #1
0
 /**
  * @group get_by_letter
  */
 public function test_get_by_letter()
 {
     if (!is_multisite()) {
         return;
     }
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $b = $this->factory->blog->create(array('title' => 'Foo Bar 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
     update_blog_option($b, 'blog_public', '1');
     $blogs = BP_Blogs_Blog::get_by_letter('F');
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($b), $blog_ids);
 }
コード例 #2
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' => '←',
				'next_text' => '→',
				'mid_size'  => 1
			) );
		}
	}
コード例 #3
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('←', 'Blog pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Blog pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => array()));
     }
 }
コード例 #4
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('←', 'Blog pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Blog pagination next text', 'buddypress'), 'mid_size' => 1));
     }
 }
コード例 #5
0
 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' => '«', 'next_text' => '»', 'mid_size' => 1));
 }