Exemplo n.º 1
0
 public function add_child($father_node, ApmTree $to_add, $as_first_child = false)
 {
     if ($father_node === false || $father_node === '' || $father_node === null) {
         //$father_node can be 0!
         $father_node = $this->get_root();
     }
     if (array_key_exists($father_node, $this->tree)) {
         if ($as_first_child) {
             array_unshift($this->tree[$father_node], $to_add->get_root());
         } else {
             $this->tree[$father_node][] = $to_add->get_root();
         }
     } else {
         $this->tree = $this->tree + array($father_node => array($to_add->get_root()));
     }
     if (!$to_add->is_simple_node()) {
         $this->tree = $this->tree + $to_add->get_tree();
     }
 }
Exemplo n.º 2
0
 public static function get_multiple_from_wp_pages($wp_pages, $no_marked_infos = false, $no_wp_data = false, $no_position_infos = false, $extended_position_infos = true)
 {
     $nodes_data = array();
     if (self::load_last_tree()) {
         $nodes_data_raw = ApmNodeDataDisplay::get_multiple_from_wp_pages($wp_pages);
         foreach ($nodes_data_raw as $wp_id => $node_data) {
             if (!$no_position_infos) {
                 $node_data->set_node_position(self::$apm_tree->get_node_tree_infos($node_data->apm_id, $extended_position_infos));
                 $node_data->convert_positions_infos_to_wp_ids();
                 //TODO : this is not optimized...
             }
             $nodes_data[$wp_id] = new ApmWpPageTreeData($node_data);
         }
     }
     return $nodes_data;
 }
Exemplo n.º 3
0
 public static function get_lost_pages($allow_autodrafts = false)
 {
     global $wpdb;
     $lost_pages = array();
     $tree = ApmTreeDb::get_last_tree();
     if (!empty($tree)) {
         $tree = new ApmTree($tree);
         $tree_apm_ids = $tree->get_nodes_flat();
         $tree_wp_ids = ApmNodeDataIntern::get_wp_ids($tree_apm_ids);
         $tree_wp_ids = array_diff($tree_wp_ids, array(ApmTreeData::root_id));
         //Remove the zeroes (for root).
         $allowed_post_status = ApmConfig::$allowed_post_status;
         if ($allow_autodrafts) {
             $allowed_post_status[] = 'auto-draft';
         }
         $allowed_post_status = apply_filters('apm_allowed_post_status', $allowed_post_status, 'get_lost_pages');
         $allowed_post_status = array_map("addslashes", $allowed_post_status);
         $sql_status = " AND post_status IN ('" . implode("','", $allowed_post_status) . "') ";
         $sql = "SELECT * FROM {$wpdb->posts} AS p \n\t\t\t\t\t\t\t WHERE p.post_type = 'page' {$sql_status} AND p.ID NOT IN ('" . implode("','", $tree_wp_ids) . "')";
         $lost_pages_raw = $wpdb->get_results($sql);
         if (!empty($lost_pages_raw)) {
             foreach ($lost_pages_raw as $page) {
                 $page->post_title = _draft_or_post_title($page->ID);
                 $lost_pages[$page->ID] = $page;
             }
         }
     }
     return $lost_pages;
 }
Exemplo n.º 4
0
 public function set_nodes_positions_from_last_tree()
 {
     $tree_raw = ApmTreeDb::get_last_tree();
     if (!empty($tree_raw)) {
         $tree = new ApmTree($tree_raw);
         $tree_infos = $tree->get_nodes_tree_infos(array_keys($this->nodes_data));
         foreach (array_keys($this->nodes_data) as $apm_id) {
             $this->nodes_data[$apm_id]->set_node_position($tree_infos[$apm_id]);
         }
     }
 }