PostDataFactory.php
11 years ago
PostFactory.php
11 years ago
PostRepository.php
11 years ago
PostTrashActions.php
11 years ago
PostUpdateRepository.php
11 years ago
PostDataFactory.php
98 lines
| 1 | <?php namespace NestedPages\Entities\Post; |
| 2 | /** |
| 3 | * Build Post Data Object |
| 4 | */ |
| 5 | class PostDataFactory { |
| 6 | |
| 7 | /** |
| 8 | * Post Data |
| 9 | * @var object |
| 10 | */ |
| 11 | private $post_data; |
| 12 | |
| 13 | /** |
| 14 | * Build the Object |
| 15 | */ |
| 16 | public function build($post) |
| 17 | { |
| 18 | $this->post_data = new \stdClass(); |
| 19 | $this->addPostVars($post); |
| 20 | $this->addPostMeta($post); |
| 21 | $this->addMenuOptions($post); |
| 22 | $this->addDate($post); |
| 23 | $this->author($post); |
| 24 | |
| 25 | return $this->post_data; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Post Items |
| 30 | */ |
| 31 | public function addPostVars($post) |
| 32 | { |
| 33 | $this->post_data->id = $post->ID; |
| 34 | $this->post_data->parent_id = $post->post_parent; |
| 35 | $this->post_data->title = $post->post_title; |
| 36 | $this->post_data->template = get_post_meta($post->ID, '_wp_page_template', true); |
| 37 | $this->post_data->password = $post->post_password; |
| 38 | $this->post_data->status = $post->post_status; |
| 39 | $this->post_data->type = $post->post_type; |
| 40 | $this->post_data->comment_status = $post->comment_status; |
| 41 | $this->post_data->content = $post->post_content; |
| 42 | $this->post_data->hierarchical = is_post_type_hierarchical($post->post_type); |
| 43 | $this->post_data->link = get_the_permalink($post->ID); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Post Meta |
| 48 | */ |
| 49 | public function addPostMeta($post) |
| 50 | { |
| 51 | // Hidden in Nested Pages? |
| 52 | $np_status = get_post_meta( $post->ID, 'nested_pages_status', true ); |
| 53 | $this->post_data->np_status = ( $np_status == 'hide' ) ? 'hide' : 'show'; |
| 54 | |
| 55 | // Yoast Score |
| 56 | if ( function_exists('wpseo_translate_score') ) { |
| 57 | $yoast_score = get_post_meta($post->ID, '_yoast_wpseo_linkdex', true); |
| 58 | $this->post_data->score = wpseo_translate_score($yoast_score); |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Menu Options |
| 64 | */ |
| 65 | private function addMenuOptions($post) |
| 66 | { |
| 67 | $this->post_data->nav_title = get_post_meta($post->ID, 'np_nav_title', true); |
| 68 | $this->post_data->link_target = get_post_meta($post->ID, 'np_link_target', true); |
| 69 | $this->post_data->nav_title_attr = get_post_meta($post->ID, 'np_title_attribute', true); |
| 70 | $this->post_data->nav_css = get_post_meta($post->ID, 'np_nav_css_classes', true); |
| 71 | $nav_status = get_post_meta( $post->ID, 'np_nav_status', true); |
| 72 | $this->post_data->nav_status = ( $nav_status == 'hide' ) ? 'hide' : 'show'; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Date Vars |
| 77 | */ |
| 78 | private function addDate($post) |
| 79 | { |
| 80 | $this->post_data->date = new \stdClass(); |
| 81 | $this->post_data->date->d = get_the_time('d', $post->ID); |
| 82 | $this->post_data->date->month = get_the_time('m', $post->ID); |
| 83 | $this->post_data->date->y = get_the_time('Y', $post->ID); |
| 84 | $this->post_data->date->h = get_the_time('H', $post->ID); |
| 85 | $this->post_data->date->m = get_the_time('i', $post->ID); |
| 86 | $this->post_data->date->datepicker = get_the_time('U', $post->ID); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Add Author Info |
| 91 | */ |
| 92 | private function author($post) |
| 93 | { |
| 94 | $this->post_data->author = get_the_author_meta('display_name', $post->post_author); |
| 95 | $this->post_data->author_link = admin_url('edit.php?post_type=' . $post->post_type . '&author=' . $post->post_author); |
| 96 | } |
| 97 | |
| 98 | } |