Completed
Push — master ( ea28d3...1760c1 )
by Dennis
04:45
created

MslsOptionsQuery::create()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 20
nc 6
nop 1
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * MslsOptionsQuery
4
 * @author Dennis Ploetner <[email protected]>
5
 * @since 0.9.8
6
 */
7
8
namespace lloc\Msls;
9
10
/**
11
 * OptionsQuery
12
 *
13
 * @package Msls
14
 */
15
class MslsOptionsQuery extends MslsOptions {
16
17
	/**
18
	 * Rewrite with front
19
	 * @var bool
20
	 */
21
	public $with_front = true;
22
23
	/**
24
	 * Factory method
25
	 * @param int $id This parameter is unused here
26
	 * @return MslsOptionsQuery
27
	 */
28
	public static function create( $id = 0 ) {
29
		if ( is_day() ) {
30
			return new MslsOptionsQueryDay(
31
				get_query_var( 'year' ),
32
				get_query_var( 'monthnum' ),
33
				get_query_var( 'day' )
34
			);
35
		}
36
		elseif ( is_month() ) {
37
			return new MslsOptionsQueryMonth(
38
				get_query_var( 'year' ),
39
				get_query_var( 'monthnum' )
40
			);
41
		}
42
		elseif ( is_year() ) {
43
			return new MslsOptionsQueryYear(
44
				get_query_var( 'year' )
45
			);
46
		}
47
		elseif ( is_author() ) {
48
			return new MslsOptionsQueryAuthor(
49
				get_queried_object_id()
50
			);
51
		}
52
		elseif ( is_post_type_archive() ) {
53
			return new MslsOptionsQueryPostType(
54
				get_query_var( 'post_type' )
55
			);
56
		}
57
		return null;
58
	}
59
60
	/**
61
	 * Get postlink
62
	 *
63
	 * @param string $language
64
	 * @return string
65
	 */
66
	public function get_postlink( $language ) {
67
		if ( $this->has_value( $language ) ) {
68
			$link = $this->get_current_link();
69
			if ( ! empty( $link ) ) {
70
				return apply_filters( 'check_url', $link, $this );
71
			}
72
		}
73
		return '';
74
	}
75
76
}
77