protected function compute_data($component, $options, $args = array()) { global $wpdb; if (!empty($options['page'])) { do_action('wpak_before_component_page', $component, $options); $page = get_post($options['page']); if (!empty($page) && $page->post_status == 'publish') { $all_pages_by_ids = array(); if (!empty($options['with_subtree'])) { $tree = array(); self::build_tree($tree, $page->ID, $page->post_parent); $all_pages = new WP_Query(array('post__in' => array_keys($tree), 'post_type' => 'any', 'posts_per_page' => -1)); foreach ($all_pages->posts as $_page) { if (isset($tree[$_page->ID])) { $all_pages_by_ids[$_page->ID] = self::get_page_data($component, $_page, $tree[$_page->ID]); } } //Handle internal links: $all_pages_ids = array_keys($all_pages_by_ids); foreach ($all_pages_by_ids as $page_id => $page_data) { $content_with_internal_links = WpakComponentsUtils::handle_internal_links($page_data->content, $all_pages_ids, array(__CLASS__, 'build_page_link'), array($component->slug)); $all_pages_by_ids[$page_id]->content = $content_with_internal_links; } $this->set_specific('is_tree', true); } else { //Important : Include page tree data here too for consistency with the "with_subtree" case : //pages referenced in the tree data wont be included in the global 'pages' if they //are not included in another page tree in the app. $all_pages_by_ids = array($page->ID => self::get_page_data($component, $page, self::get_page_tree_data($page->ID, $page->post_parent))); $this->set_specific('is_tree', false); } $this->set_specific('root_id', $page->ID); $root_depth = 0; if (!empty($all_pages_by_ids) && isset($all_pages_by_ids[$page->ID])) { $tree_data = $all_pages_by_ids[$page->ID]->tree_data; $root_depth = $tree_data[3]; } $this->set_specific('root_depth', $root_depth); $this->set_globals('pages', $all_pages_by_ids); } } }