1: <?php
2:
3: /**
4: * Post page implementation of Papi page.
5: */
6: class Papi_Post_Page extends Papi_Core_Page {
7:
8: /**
9: * Data type to describe which
10: * type of page data is it.
11: *
12: * @var string
13: */
14: protected $type = self::TYPE_POST;
15:
16: /**
17: * The WordPress post.
18: *
19: * @var object
20: */
21: private $post;
22:
23: /**
24: * The Page type.
25: *
26: * @var Papi_Page_Type
27: */
28: private $page_type;
29:
30: /**
31: * The constructor.
32: *
33: * Create a new instance of the class.
34: *
35: * @param int $post_id
36: */
37: public function __construct( $post_id = 0 ) {
38: if ( $post_id === 0 ) {
39: $this->id = papi_get_post_id();
40: } else {
41: $this->id = intval( $post_id );
42: }
43:
44: $this->post = get_post( $this->id );
45: $id = papi_get_page_type_id( $this->id );
46: $this->page_type = papi_get_page_type_by_id( $id );
47: }
48:
49: /**
50: * Get the page type object of the page.
51: *
52: * @return Papi_Page_Type
53: */
54: public function get_page_type() {
55: return $this->page_type;
56: }
57:
58: /**
59: * Get the permalink for the page.
60: *
61: * @return string
62: */
63: public function get_permalink() {
64: return get_permalink( $this->id );
65: }
66:
67: /**
68: * Get the WordPress post object.
69: *
70: * @return WP_Post
71: */
72: public function get_post() {
73: return $this->post;
74: }
75:
76: /**
77: * Get the post status of a page.
78: *
79: * @return string
80: */
81: public function get_status() {
82: return get_post_status( $this->id );
83: }
84:
85: /**
86: * Load property from page type.
87: *
88: * @param string $slug
89: * @param string $child_slug
90: *
91: * @return object
92: */
93: public function get_property( $slug, $child_slug = '' ) {
94: $page_type_id = papi_get_page_type_id( $this->id );
95: $page_type = papi_get_page_type_by_id( $page_type_id );
96:
97: if ( $page_type instanceof Papi_Page_Type === false ) {
98: return;
99: }
100:
101: return $page_type->get_property( $slug, $child_slug );
102: }
103:
104: /**
105: * Check if the page has the post object and that it's not null.
106: *
107: * @return bool
108: */
109: public function valid() {
110: return ! is_null( $this->post );
111: }
112: }
113: