PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.0.8
Nested Pages v3.0.8
3.3.1 3.2.15 3.2.14 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / app / Entities / Post / PostDataFactory.php
wp-nested-pages / app / Entities / Post Last commit date
PostCloner.php 8 years ago PostDataFactory.php 8 years ago PostFactory.php 8 years ago PostRepository.php 8 years ago PostTrashActions.php 8 years ago PostUpdateRepository.php 7 years ago PrivatePostParent.php 8 years ago
PostDataFactory.php
149 lines
1 <?php
2 namespace NestedPages\Entities\Post;
3
4 use NestedPages\Entities\PluginIntegration\IntegrationFactory;
5
6 /**
7 * Build Post Data Object
8 */
9 class PostDataFactory
10 {
11 /**
12 * Post Data
13 * @var object
14 */
15 private $post_data;
16
17 /**
18 * Plugin Integrations
19 * @var object
20 */
21 private $integrations;
22
23 /**
24 * Build the Object
25 */
26 public function build($post, $h_taxonomies = null, $f_taxonomies = null)
27 {
28 $this->integrations = new IntegrationFactory;
29 $this->post_data = new \WP_Post($post);
30 $this->addPostVars($post);
31 $this->addPostMeta($post);
32 $this->addOriginalLink($post);
33 $this->addDate($post);
34 $this->author($post);
35 if ( $h_taxonomies || $f_taxonomies ) $this->addTaxonomies($post, $h_taxonomies, $f_taxonomies);
36 return $this->post_data;
37 }
38
39 /**
40 * Post Items
41 */
42 public function addPostVars($post)
43 {
44 $this->post_data->id = $post->ID;
45 $this->post_data->ID = $post->ID;
46 $this->post_data->parent_id = $post->post_parent;
47 $this->post_data->title = $post->post_title;
48 $this->post_data->password = $post->post_password;
49 $this->post_data->status = $post->post_status;
50 $this->post_data->type = $post->post_type;
51 $this->post_data->comment_status = $post->comment_status;
52 $this->post_data->content = $post->post_content;
53 $this->post_data->hierarchical = is_post_type_hierarchical($post->post_type);
54 $this->post_data->post_type = $post->post_type;
55 $this->post_data->link = get_the_permalink($post->ID);
56 }
57
58 /**
59 * Post Meta
60 */
61 public function addPostMeta($post)
62 {
63 $meta = get_metadata('post', $post->ID);
64 $this->post_data->nav_title = ( isset($meta['_np_nav_title'][0]) ) ? $meta['_np_nav_title'][0] : null;
65 $this->post_data->link_target = ( isset($meta['_np_link_target'][0]) ) ? $meta['_np_link_target'][0] : null;
66 $this->post_data->nav_title_attr = ( isset($meta['_np_title_attribute'][0]) ) ? $meta['_np_title_attribute'][0] : null;
67 $this->post_data->nav_css = ( isset($meta['_np_nav_css_classes'][0]) ) ? $meta['_np_nav_css_classes'][0] : null;
68 $this->post_data->nav_object = ( isset($meta['_np_nav_menu_item_object'][0]) ) ? $meta['_np_nav_menu_item_object'][0] : null;
69 $this->post_data->nav_object_id = ( isset($meta['_np_nav_menu_item_object_id'][0]) ) ? $meta['_np_nav_menu_item_object_id'][0] : null;
70 $this->post_data->nav_type = ( isset($meta['_np_nav_menu_item_type'][0]) ) ? $meta['_np_nav_menu_item_type'][0] : null;
71 $this->post_data->nav_status = ( isset($meta['_np_nav_status'][0]) && $meta['_np_nav_status'][0] == 'hide' ) ? 'hide' : 'show';
72 $this->post_data->np_status = ( isset($meta['_nested_pages_status'][0]) && $meta['_nested_pages_status'][0] == 'hide' ) ? 'hide' : 'show';
73 $this->post_data->template = ( isset($meta['_wp_page_template'][0]) ) ? $meta['_wp_page_template'][0] : false;
74
75 // Yoast Score
76 if ( $this->integrations->plugins->yoast->installed ) {
77 $this->post_data->score = $this->integrations->plugins->yoast->getScore($post->ID);
78 }
79 }
80
81 /**
82 * Add original item/link to link
83 */
84 private function addOriginalLink($post)
85 {
86 if ( $post->post_type !== 'np-redirect' ) {
87 $this->post_data->nav_original_link = null;
88 $this->post_data->nav_original_type = null;
89 return;
90 }
91
92 if ( $this->post_data->nav_type && $this->post_data->nav_type == 'taxonomy' ){
93 $term = get_term_by('id', $this->post_data->nav_object_id, $this->post_data->nav_object);
94 $this->post_data->nav_original_link = get_term_link($term);
95 $this->post_data->nav_original_title = $term->name;
96 return;
97 }
98
99 $id = $this->post_data->nav_object_id;
100 $this->post_data->nav_original_link = get_the_permalink($id);
101 $this->post_data->nav_original_title = get_the_title($id);
102 }
103
104 /**
105 * Date Vars
106 */
107 private function addDate($post)
108 {
109 $this->post_data->date = new \stdClass();
110 $time = get_the_time('U', $post->ID);
111 $this->post_data->date->d = date('d', $time);
112 $this->post_data->date->month = date('m', $time);
113 $this->post_data->date->y = date('Y', $time);
114 $this->post_data->date->h = date('H', $time);
115 $this->post_data->date->m = date('i', $time);
116 $this->post_data->date->datepicker = $time;
117 }
118
119 /**
120 * Add Author Info
121 */
122 private function author($post)
123 {
124 $this->post_data->author = get_the_author_meta('display_name', $post->post_author);
125 $this->post_data->author_link = admin_url('edit.php?post_type=' . $post->post_type . '&author=' . $post->post_author);
126 }
127
128 /**
129 * Add taxonomies
130 */
131 public function addTaxonomies($post, $h_taxonomies, $f_taxonomies)
132 {
133 // Add taxonomies
134 if ( count($h_taxonomies) > 0 ) {
135 foreach($h_taxonomies as $tax){
136 $taxname = $tax->name;
137 if ( !isset($post->$taxname) ) continue;
138 $this->post_data->$taxname = explode(',', $post->$taxname);
139 }
140 }
141 if ( count($f_taxonomies) > 0 ) {
142 foreach($f_taxonomies as $tax){
143 $taxname = $tax->name;
144 if ( !isset($post->$taxname) ) continue;
145 $this->post_data->$taxname = explode(',', $post->$taxname);
146 }
147 }
148 }
149 }