Example #1
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
			) );
		}
	}
 /**
  * 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()));
     }
 }
Example #3
0
    function admin_main($data)
    {
        if (!$data) {
            $data = array();
        }
        ?>
		<div class='level-operation' id='main-bpblogs'>
			<h2 class='sidebar-name'><?php 
        _e('Blogs', 'membership');
        ?>
<span><a href='#remove' id='remove-bpblogs' class='removelink' title='<?php 
        _e("Remove Blogs from this rules area.", 'membership');
        ?>
'><?php 
        _e('Remove', 'membership');
        ?>
</a></span></h2>
			<div class='inner-operation'>
				<p><?php 
        _e('Select the blogs to be covered by this rule by checking the box next to the relevant blogs name.', 'membership');
        ?>
</p>
				<?php 
        if (function_exists('bp_blogs_get_blogs')) {
            $blogs = bp_blogs_get_blogs(array('per_page' => 50));
        }
        if ($blogs) {
            ?>
						<table cellspacing="0" class="widefat fixed">
							<thead>
							<tr>
								<th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th>
								<th style="" class="manage-column column-name" id="name" scope="col"><?php 
            _e('Blog title', 'membership');
            ?>
</th>
								<th style="" class="manage-column column-date" id="date" scope="col"><?php 
            _e('Last activity', 'membership');
            ?>
</th>
							</tr>
							</thead>

							<tfoot>
							<tr>
								<th style="" class="manage-column column-cb check-column" id="cb" scope="col"><input type="checkbox"></th>
								<th style="" class="manage-column column-name" id="name" scope="col"><?php 
            _e('Blog title', 'membership');
            ?>
</th>
								<th style="" class="manage-column column-date" id="date" scope="col"><?php 
            _e('Last activity', 'membership');
            ?>
</th>
							</tr>
							</tfoot>

							<tbody>
						<?php 
            foreach ($blogs['blogs'] as $key => $blog) {
                ?>
							<tr valign="middle" class="alternate" id="bpblog-<?php 
                echo $blog->blog_id;
                ?>
">
								<th class="check-column" scope="row">
									<input type="checkbox" value="<?php 
                echo $blog->blog_id;
                ?>
" name="bpblogs[]" <?php 
                if (in_array($blog->blog_id, $data)) {
                    echo 'checked="checked"';
                }
                ?>
>
								</th>
								<td class="column-name">
									<strong><?php 
                echo esc_html($blog->name);
                ?>
</strong>
								</td>
								<td class="column-date">
									<?php 
                echo date("Y/m/d", strtotime($blog->last_activity));
                ?>
								</td>
						    </tr>
							<?php 
            }
            ?>
							</tbody>
						</table>
						<?php 
        }
        if ($blogs['total'] > 50) {
            ?>
						<p class='description'><?php 
            _e("Only the most recently updated 50 blogs are shown above.", 'membership');
            ?>
</p>
						<?php 
        }
        ?>

			</div>
		</div>
		<?php 
    }
 /**
  * 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));
     }
 }
 /**
  * @group bp_blogs_record_existing_blogs
  */
 public function test_bp_blogs_record_existing_blogs_limit()
 {
     if (!is_multisite()) {
         return;
     }
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     // Create three sites.
     $this->factory->blog->create_many(3, array('user_id' => $u));
     // Record each site one at a time
     bp_blogs_record_existing_blogs(array('limit' => 1));
     // Assert!
     $blogs = bp_blogs_get_blogs(array('user_id' => $u));
     $this->assertSame(3, (int) $blogs['total']);
     $this->set_current_user($old_user);
 }