get_options();
}
/**
* Pagination based on options/args
*/
function paginate($args = false) {
if ($this->type === 'comments' && !get_option('page_comments'))
return;
$r = wp_parse_args($args, $this->options);
extract($r, EXTR_SKIP);
if (!isset($page) && !isset($pages)) {
global $wp_query;
if ($this->type === 'posts') {
$page = $query->get( 'paged' );//get_query_var('paged');
$posts_per_page = intval( $query->get( 'posts_per_page' ) );//intval(get_query_var('posts_per_page'));
$pages = intval( ceil( $query->found_posts / $posts_per_page ) );
}
else {
$page = get_query_var('cpage');
$comments_per_page = get_option('comments_per_page');
$pages = get_comment_pages_count();
}
$page = !empty($page) ? intval($page) : 1;
}
$prevlink = ($this->type === 'posts')
? esc_url(get_pagenum_link($page - 1))
: get_comments_pagenum_link($page - 1);
$nextlink = ($this->type === 'posts')
? esc_url(get_pagenum_link($page + 1))
: get_comments_pagenum_link($page + 1);
$output = stripslashes($before);
if ($pages > 1) {
$output .= sprintf('
', ($this->type === 'posts') ? $class : ' wp-paginate-comments');
if (strlen(stripslashes($title)) > 0) {
$output .= sprintf('- %s
', stripslashes($title));
}
$ellipsis = "- ...
";
if ($page > 1 && !empty($previouspage)) {
$output .= sprintf('- %s
', $prevlink, stripslashes($previouspage));
}
$min_links = $range * 2 + 1;
$block_min = min($page - $range, $pages - $min_links);
$block_high = max($page + $range, $min_links);
$left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
$right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
if ($left_gap && !$right_gap) {
$output .= sprintf('%s%s%s',
$this->paginate_loop(1, $anchor),
$ellipsis,
$this->paginate_loop($block_min, $pages, $page)
);
}
else if ($left_gap && $right_gap) {
$output .= sprintf('%s%s%s%s%s',
$this->paginate_loop(1, $anchor),
$ellipsis,
$this->paginate_loop($block_min, $block_high, $page),
$ellipsis,
$this->paginate_loop(($pages - $anchor + 1), $pages)
);
}
else if ($right_gap && !$left_gap) {
$output .= sprintf('%s%s%s',
$this->paginate_loop(1, $block_high, $page),
$ellipsis,
$this->paginate_loop(($pages - $anchor + 1), $pages)
);
}
else {
$output .= $this->paginate_loop(1, $pages, $page);
}
if ($page < $pages && !empty($nextpage)) {
$output .= sprintf('- %s
', $nextlink, stripslashes($nextpage));
}
$output .= "
";
}
$output .= stripslashes($after);
if ($pages > 1 || $empty) {
print( $output );
}
}
/**
* Helper function for pagination which builds the page links.
*/
function paginate_loop($start, $max, $page = 0) {
$output = "";
for ($i = $start; $i <= $max; $i++) {
$p = ($this->type === 'posts') ? esc_url(get_pagenum_link($i)) : get_comments_pagenum_link($i);
$output .= ($page == intval($i))
? "$i"
: "$i";
}
return $output;
}
/**
* Retrieves the plugin options from the database.
* @return array
*/
function get_options() {
$this->options = array(
'title' => __('Pages:', 'boson' ),
'nextpage' => '»',
'previouspage' => '«',
'css' => false,
'class' => 'pagination',
'before' => '',
'empty' => true,
'range' => 3,
'anchor' => 1,
'gap' => 3,
'query' => $GLOBALS['wp_query'],
);
}
}
}
//instantiate the class
if (class_exists('Boson_Paginate')) {
$GLOBALS['boson_paginate'] = new Boson_Paginate();
}
/**
* Pagination function to use for posts
*/
function boson_wp_paginate($args = false) {
global $boson_paginate;
$boson_paginate->type = 'posts';
return $boson_paginate->paginate($args);
}
/**
* Pagination function to use for post comments
*/
function boson_wp_paginate_comments($args = false) {
global $boson_paginate;
$boson_paginate->type = 'comments';
return $boson_paginate->paginate($args);
}