Microweber\Providers\CategoryManager::html_tree PHP Method

html_tree() private method

Prints the selected categories as an
    tree, you might pass several options for more flexibility
private html_tree ( $parent, $link = false, $active_ids = false, $active_code = false, $remove_ids = false, $removed_ids_code = false, $ul_class_name = false, $include_first = false, $content_type = false, $li_class_name = false, $add_ids = false, $orderby = false, $only_with_content = false, $visible_on_frontend = false, $depth_level_counter, $max_level = false, $list_tag = false, $list_item_tag = false, $active_code_tag = false, $ul_class_deep = false, $only_ids = false )
    private function html_tree($parent, $link = false, $active_ids = false, $active_code = false, $remove_ids = false, $removed_ids_code = false, $ul_class_name = false, $include_first = false, $content_type = false, $li_class_name = false, $add_ids = false, $orderby = false, $only_with_content = false, $visible_on_frontend = false, $depth_level_counter = 0, $max_level = false, $list_tag = false, $list_item_tag = false, $active_code_tag = false, $ul_class_deep = false, $only_ids = false)
    {
        $db_t_content = $this->tables['content'];
        $table = $db_categories = $this->tables['categories'];
        if ($parent == false) {
            $parent = 0;
            $include_first = false;
        } else {
            $parent = (int) $parent;
        }
        if (!is_array($orderby)) {
            $orderby[0] = 'position';
            $orderby[1] = 'ASC';
        }
        if (isset($remove_ids) and !is_array($remove_ids)) {
            $temp = intval($remove_ids);
            $remove_ids_q = " and id not in ({$temp}) ";
        } elseif (is_array($remove_ids) and !empty($remove_ids)) {
            $remove_ids_q = implode(',', $remove_ids);
            if ($remove_ids_q != '') {
                $remove_ids_q = " and id not in ({$remove_ids_q}) ";
            }
        } else {
            $remove_ids_q = false;
        }
        if (!empty($add_ids)) {
            $add_ids_q = implode(',', $add_ids);
            $add_ids_q = " and id in ({$add_ids_q}) ";
        } else {
            $add_ids_q = false;
        }
        if ($max_level != false and $depth_level_counter != false) {
            if (intval($depth_level_counter) >= intval($max_level)) {
                echo '';
                return;
            }
        }
        if (isset($list_tag) == false or $list_tag == false) {
            $list_tag = 'ul';
        }
        if (isset($active_code_tag) == false or $active_code_tag == false) {
            $active_code_tag = '';
        }
        if (isset($list_item_tag) == false or $list_item_tag == false) {
            $list_item_tag = 'li';
        }
        if (empty($limit)) {
            $limit = array(0, 10);
        }
        $table = $this->app->database_manager->real_table_name($table);
        $content_type = addslashes($content_type);
        $hard_limit = ' LIMIT 300 ';
        $inf_loop_fix = "  and {$table}.id!={$table}.parent_id  ";
        //	$inf_loop_fix = "     ";
        if ($only_ids != false) {
            if (is_string($only_ids)) {
                $only_ids = explode(',', $only_ids);
            }
            $sql = "SELECT * FROM {$table} WHERE id IN (" . implode(',', $only_ids) . ') ';
            $sql = $sql . " and data_type='category'   and is_deleted=0  ";
            //   $sql = $sql . "$remove_ids_q  $add_ids_q $inf_loop_fix  ";
            $sql = $sql . " group by id order by {$orderby[0]}  {$orderby[1]}  {$hard_limit}";
        } elseif ($content_type == false) {
            if ($include_first == true) {
                $sql = "SELECT * FROM {$table} WHERE id={$parent} ";
                $sql = $sql . " and data_type='category'   and is_deleted=0  ";
                $sql = $sql . "{$remove_ids_q}  {$add_ids_q} {$inf_loop_fix}  ";
                $sql = $sql . " group by id order by {$orderby[0]}  {$orderby[1]}  {$hard_limit}";
            } else {
                $sql = "SELECT * FROM {$table} WHERE parent_id={$parent} AND data_type='category' AND is_deleted=0 ";
                $sql = $sql . "{$remove_ids_q} {$add_ids_q} {$inf_loop_fix} group by id order by {$orderby[0]}  {$orderby[1]}   {$hard_limit}";
            }
        } else {
            if ($include_first == true) {
                $sql = "SELECT * FROM {$table} WHERE id={$parent}  AND is_deleted=0  ";
                $sql = $sql . "{$remove_ids_q} {$add_ids_q}   {$inf_loop_fix} group by id order by {$orderby[0]}  {$orderby[1]}  {$hard_limit}";
            } else {
                $sql = "SELECT * FROM {$table} WHERE parent_id={$parent} AND is_deleted=0 AND data_type='category' AND (category_subtype='{$content_type}' OR category_subtype='inherit' ) ";
                $sql = $sql . " {$remove_ids_q}  {$add_ids_q} {$inf_loop_fix} group by id order by {$orderby[0]}  {$orderby[1]}   {$hard_limit}";
            }
        }
        if (!empty($limit)) {
            $my_offset = $limit[1] - $limit[0];
            $my_limit_q = " limit  {$limit[0]} , {$my_offset}  ";
        } else {
            $my_limit_q = false;
        }
        $output = '';
        $q = $this->app->database_manager->query($sql, $cache_id = 'html_tree_parent_cats_q_' . crc32($sql), 'categories/' . intval($parent));
        //$q = $this->app->database_manager->query($sql, false);
        $result = $q;
        $only_with_content2 = $only_with_content;
        $do_not_show_next = false;
        $chosen_categories_array = array();
        if (isset($result) and is_array($result) and !empty($result)) {
            ++$depth_level_counter;
            $i = 0;
            $do_not_show = false;
            if ($do_not_show == false) {
                $print1 = false;
                if (trim($list_tag) != '') {
                    if ($ul_class_name == false) {
                        $print1 = "<{$list_tag}  class='{active_class} category_tree depth-{$depth_level_counter}'>";
                    } else {
                        $cl_name = $ul_class_name;
                        if ($depth_level_counter > 1) {
                            $cl_name = $ul_class_deep;
                        }
                        $print1 = "<{$list_tag} class='{active_class} {$cl_name} depth-{$depth_level_counter}'>";
                    }
                }
                if (intval($parent) != 0 and intval($parent) == intval(CATEGORY_ID)) {
                    $print1 = str_replace('{active_class}', 'active', $print1);
                }
                $print1 = str_replace('{active_class}', '', $print1);
                echo $print1;
                foreach ($result as $item) {
                    if ($only_with_content == true) {
                        $do_not_show = false;
                        $check_in_content = false;
                        $children_content = array();
                        $do_not_show = false;
                        if (!empty($children_content)) {
                            $do_not_show = false;
                        } else {
                            $do_not_show = true;
                        }
                    } else {
                        $do_not_show = false;
                    }
                    $iid = $item['id'];
                    if ($do_not_show == false) {
                        $output = $output . $item['title'];
                        if ($li_class_name == false) {
                            $output = "<{$list_item_tag} class='{active_class} category_element depth-{$depth_level_counter} item_{$iid}'   value='{$item['id']}' data-category-id='{$item['id']}' data-category-parent-id='{$item['parent_id']}' data-item-id='{$item['id']}'  data-to-table='{$item['rel_type']}'  data-to-table-id='{$item['rel_id']}'    data-categories-type='{$item['data_type']}' {active_code_tag} title='{title_slashes}'>";
                        } else {
                            $output = "<{$list_item_tag} class='{active_class} {$li_class_name}  category_element depth-{$depth_level_counter} item_{$iid}'  value='{$item['id']}' data-item-id='{$item['id']}' data-category-id='{$item['id']}'  data-to-table='{$item['rel_type']}'  data-to-table-id='{$item['rel_id']}'  data-categories-type='{$item['data_type']}'  {active_code_tag} title='{title_slashes}' >";
                        }
                    }
                    if (intval($item['id']) != 0 and intval($item['id']) == intval(CATEGORY_ID)) {
                        $output = str_replace('{active_class}', 'active', $output);
                    } else {
                        $output = str_replace('{active_class}', '', $output);
                    }
                    if ($do_not_show == false) {
                        if ($link != false) {
                            $to_print = false;
                            $empty1 = intval($depth_level_counter);
                            $empty = '';
                            for ($i1 = 0; $i1 < $empty1; ++$i1) {
                                $empty = $empty . '&nbsp;&nbsp;';
                            }
                            $ext_classes = '';
                            $to_print = str_replace('{id}', $item['id'], $link);
                            if (stristr($link, '{items_count}')) {
                                $to_print = str_ireplace('{items_count}', $this->get_items_count($item['id']), $to_print);
                            }
                            $to_print = str_ireplace('{url}', $this->link($item['id']), $to_print);
                            $to_print = str_ireplace('{link}', $this->link($item['id']), $to_print);
                            $to_print = str_replace('{exteded_classes}', $ext_classes, $to_print);
                            $to_print = str_ireplace('{categories_url}', $this->link($item['id']), $to_print);
                            $to_print = str_ireplace('{nest_level}', 'depth-' . $depth_level_counter, $to_print);
                            $to_print = str_ireplace('{title}', $item['title'], $to_print);
                            $to_print = str_ireplace('{title_slashes}', addslashes($item['title']), $to_print);
                            $to_print = str_replace('{content_link_class}', '', $to_print);
                            $output = str_replace('{title_slashes}', addslashes($item['title']), $output);
                            $output = str_replace('{content_link_class}', '', $output);
                            $active_class = ' ';
                            $active_parent_class = '';
                            //if(isset($item['parent']) and intval($item['parent']) != 0){
                            if (intval($item['parent_id']) != 0 and intval($item['parent_id']) == intval(CATEGORY_ID)) {
                                $active_parent_class = 'active-parent';
                                $active_class = '';
                            } elseif (intval($item['id']) != 0 and intval($item['id']) == intval(CATEGORY_ID)) {
                                $active_parent_class = 'active-parent';
                                $active_class = 'active';
                            } else {
                                $active_parent_class = '';
                            }
                            $active_class = str_replace('"', ' ', $active_class);
                            $to_print = str_replace('{active_class}', $active_class, $to_print);
                            $to_print = str_replace('{active_parent_class}', $active_parent_class, $to_print);
                            if (isset($item['category_subtype'])) {
                                $to_print = str_ireplace('{category_subtype}', trim($item['category_subtype']), $to_print);
                            }
                            $to_print = str_replace('{empty}', $empty, $to_print);
                            $active_found = false;
                            if (is_string($active_ids)) {
                                $active_ids = explode(',', $active_ids);
                            }
                            if (is_array($active_ids) == true) {
                                $active_ids = array_trim($active_ids);
                                foreach ($active_ids as $value_active_cat) {
                                    if ($value_active_cat != '') {
                                        $value_active_cat = intval($value_active_cat);
                                        if (intval($item['id']) == $value_active_cat) {
                                            $active_found = $value_active_cat;
                                        }
                                    }
                                }
                                if ($active_found == true) {
                                    $to_print = str_replace('{active_code}', $active_code, $to_print);
                                    $to_print = str_replace('{active_class}', $active_class, $to_print);
                                    $to_print = str_replace('{active_code_tag}', $active_code_tag, $to_print);
                                    $output = str_replace('{active_code_tag}', $active_code_tag, $output);
                                } else {
                                    $to_print = str_replace('{active_code}', '', $to_print);
                                }
                            } else {
                                $to_print = str_ireplace('{active_code}', '', $to_print);
                            }
                            $output = str_replace('{active_code_tag}', '', $output);
                            $output = str_replace('{title_slashes}', '', $output);
                            $output = str_replace('{exteded_classes}', $ext_classes, $output);
                            $to_print = str_replace('{items_count}', '', $to_print);
                            $to_print = str_replace('{active_class}', '', $to_print);
                            $to_print = str_replace('{active_code_tag}', '', $to_print);
                            if (is_array($remove_ids) == true) {
                                if (in_array($item['id'], $remove_ids)) {
                                    if ($removed_ids_code == false) {
                                        $to_print = false;
                                    } else {
                                        $to_print = str_ireplace('{removed_ids_code}', $removed_ids_code, $to_print);
                                    }
                                } else {
                                    $to_print = str_ireplace('{removed_ids_code}', '', $to_print);
                                }
                            }
                            if (strval($to_print) == '') {
                                echo $output . $item['title'];
                            } else {
                                echo $output . $to_print;
                            }
                        } else {
                            echo $output . $item['title'];
                        }
                        $children_of_the_main_parent1 = array();
                        if (!isset($remove_ids) or !is_array($remove_ids)) {
                            $remove_ids = array();
                        }
                        $remove_ids[] = $item['id'];
                        if ($only_ids == false) {
                            $children = $this->html_tree($item['id'], $link, $active_ids, $active_code, $remove_ids, $removed_ids_code, $ul_class_name, false, $content_type, $li_class_name, $add_ids = false, $orderby, $only_with_content, $visible_on_frontend, $depth_level_counter, $max_level, $list_tag, $list_item_tag, $active_code_tag, $ul_class_deep);
                        }
                        echo "</{$list_item_tag}>";
                    }
                }
                if (trim($list_tag) != '') {
                    echo "</{$list_tag}>";
                }
            }
        }
    }