Carbon_Pagination_Custom   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
c 8
b 0
f 0
dl 0
loc 71
ccs 24
cts 24
cp 1
rs 10
wmc 7
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A get_page_url() 0 13 3
A get_query_var() 0 3 1
A set_query_var() 0 3 1
1
<?php
2
/**
3
 * Carbon Pagination - custom pagination class.
4
 * Allows to create and maintain a custom pagination.
5
 * By default it takes advantage of the post content pagination (<!--nextpage--> Quicktag)
6
 *
7
 * @uses Carbon_Pagination_HTML
8
 */
9
class Carbon_Pagination_Custom extends Carbon_Pagination_HTML {
10
	/**
11
	 * @var string
12
	 * 
13
	 * The query var that is used to specify the pagination number.
14
	 */
15
	protected $query_var = 'page';
16
17
	/**
18
	 * Constructor.
19
	 * Creates and configures a new pagination with the provided settings.
20
	 *
21
	 * @param array $args Configuration options to modify the pagination settings.
22
	 */
23 7
	public function __construct( $args = array() ) {
24
		// get the default total number of pages from the <!--nextpage--> functionality
25 7
		global $numpages;
26 7
		$total_pages = ! empty( $numpages ) ? $numpages : '';
27
28
		// specify the default args for the Custom pagination
29 7
		$this->default_args = array(
30 7
			'total_pages' => $total_pages,
31 7
			'current_page' => get_query_var( $this->get_query_var() ),
32 7
			'enable_numbers' => true,
33 7
			'enable_prev' => false,
34 7
			'enable_next' => false,
35
		);
36
37 7
		parent::__construct( $args );
38 7
	}
39
40
	/**
41
	 * Get the URL to a certain page.
42
	 *
43
	 * @param int $page_number The page number.
44
	 * @param string $old_url Optional. The URL to add the page number to.
45
	 * @return string $url The URL to the page number.
46
	 */
47 4
	public function get_page_url( $page_number, $old_url = '' ) {
48 4
		$pages = $this->get_pages();
49
50 4
		if ( ! $old_url ) {
51 3
			$old_url = Carbon_Pagination_Utilities::get_current_url();
52 3
		}
53
54 4
		if ( ! isset( $pages[ $page_number ] ) ) {
55 1
			return $old_url;
56
		}
57
58 3
		return add_query_arg( $this->get_query_var(), $pages[ $page_number ], $old_url );
59
	}
60
61
	/**
62
	 * Retrieve the query var name.
63
	 *
64
	 * @return string $query_var The query var name.
65
	 */
66 1
	public function get_query_var() {
67 1
		return $this->query_var;
68
	}
69
70
	/**
71
	 * Modify the query var name.
72
	 *
73
	 * @param string $query_var The new query var name.
74
	 */
75 1
	public function set_query_var( $query_var ) {
76 1
		$this->query_var = $query_var;
77 1
	}
78
79
}