|
1
|
|
|
<?php |
|
2
|
|
|
namespace GV\Wrappers; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file contains magic wrapper code for `gravityview()`. |
|
6
|
|
|
* |
|
7
|
|
|
* Every `gravityview()` magic key maps to a class that exposes more magic. |
|
8
|
|
|
* Chains of inifite magic can be constructed spanning seas of mermaids, |
|
9
|
|
|
* valleys of unicorns and whirlwinds of shooting stars. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The views magic wrapper. |
|
14
|
|
|
*/ |
|
15
|
|
|
class views { |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \GV\View An internal View keeper. |
|
19
|
|
|
*/ |
|
20
|
|
|
private $view = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Gets a View. |
|
24
|
|
|
* |
|
25
|
|
|
* Doesn't care what you provide it. Will try to find |
|
26
|
|
|
* out what you need from the current context, from the supplied |
|
27
|
6 |
|
* args, etc. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string|int|array|\GV\View\WP_Post|null Anything goes. |
|
30
|
|
|
* |
|
31
|
|
|
* @return \GV\View|null The detected View. |
|
32
|
6 |
|
*/ |
|
33
|
1 |
|
public function get( $view = null ) { |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* By View. |
|
37
|
|
|
*/ |
|
38
|
|
|
if ( $view instanceof \GV\View && $view->ID ) { |
|
39
|
6 |
|
return $this->get( $view->ID ); |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* By View ID. |
|
44
|
|
|
*/ |
|
45
|
|
|
if ( is_numeric( $view ) ) { |
|
46
|
6 |
|
return \GV\View::by_id( $view ); |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* By post object. |
|
51
|
|
|
*/ |
|
52
|
|
|
if ( $view instanceof \WP_Post ) { |
|
|
|
|
|
|
53
|
6 |
|
return \GV\View::from_post( $view ); |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* By array. |
|
58
|
|
|
*/ |
|
59
|
|
|
if ( is_array( $view ) && ! empty( $view['id'] ) ) { |
|
60
|
6 |
|
return $this->get( $view['id'] ); |
|
61
|
6 |
|
} |
|
62
|
5 |
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* From various contexts. |
|
65
|
1 |
|
*/ |
|
66
|
|
|
if ( is_null( $view ) ) { |
|
67
|
1 |
|
if ( in_array( get_class( gravityview()->request ), array( 'GV\Frontend_Request', 'GV\Mock_Request' ) ) && $view = gravityview()->request->is_view() ) { |
|
68
|
|
|
return $view; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
global $post; |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
if ( $post instanceof \WP_Post && $post->post_type == 'gravityview' ) { |
|
|
|
|
|
|
74
|
|
|
return $this->get( $post ); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Mock the internal pointer. |
|
81
|
|
|
* |
|
82
|
|
|
* @param \GV\View $view The View to supply on fallback in ::get() |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public function set( $view ) { |
|
87
|
|
|
$this->view = $view; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|