/** * Build the html for a tree view * * @param array $items An array of items that may or may not have children (under a key named `children` for each appropriate array entry). * @param array $html The html string to parse. Example: <li id="{{ id }}"><a href="#">{{ title }}</a>{{ children }}</li> * */ function tree_builder($items, $html) { $output = ''; if (is_array($items)) { foreach ($items as $item) { if (isset($item['children']) and !empty($item['children'])) { // if there are children we build their html and set it up to be parsed as {{ children }} $item['children'] = '<ul>' . tree_builder($item['children'], $html) . '</ul>'; } // now that the children html is sorted we parse the html that they passed $output .= ci()->parser->parse_string($html, $item, true); } return $output; } }
<div class="one_full"> <div class="one_half"> <section class="title"> <h4><?php echo lang('pages:list_title'); ?> </h4> </section> <section class="item"> <div class="content"> <div id="page-list"> <ul class="sortable"> <?php echo tree_builder($pages, '<li id="page_{{ id }}"><div><a href="#" class="{{ status }}" rel="{{ id }}">{{ title }}</a></div>{{ children }}</li>'); ?> </ul> </div> </div> </section> </div> <div class="one_half last"> <section class="title"> <h4><?php echo lang('pages:tree_explanation_title'); ?> </h4> </section> <section class="item">
<li class="folder places" data-id="0"><a href="#"><?php echo lang('files:places'); ?> </a></li> <?php if (!$folders) { ?> <li class="no_data"><?php echo lang('files:no_folders_places'); ?> </li> <?php } elseif ($folder_tree) { ?> <?php echo tree_builder($folder_tree, '<li class="folder" data-id="{{ id }}" data-name="{{ name }}"><div></div><a href="#">{{ name }}</a>{{ children }}</li>'); ?> <?php } ?> </ul> </section> <section class="two_third"> <?php if (!$folders) { ?> <div class="no_data"><?php echo lang('files:no_folders'); ?> </div>
</li> </ul> </section> <?php if (!empty($navigation[$group->id])) { ?> <section class="item collapsed"> <div class="content"> <div class="one_half"> <div id="link-list"> <ul class="sortable"> <?php echo tree_builder($navigation[$group->id], '<li id="link_{{ id }}"><div><a href="#" rel="' . $group->id . '" alt="{{ id }}">{{ title }}</a></div>{{ children }}</li>'); ?> </ul> </div> </div> <div class="one_half last"> <div id="link-details" class="group-<?php echo $group->id; ?> "> <p> <?php echo lang('navs.tree_explanation'); ?>
<div class="one_full"> <div class="one_half"> <section class="title"> <h4><?php echo lang('category:categories'); ?> </h4> </section> <section class="item"> <div class="content"> <div id="page-list"> <ul class="sortable"> <?php echo tree_builder($categories, '<li id="category_{{ id }}"><div><a href="#" class="status_{{ category_status }}" rel="{{ id }}">{{ category_title }}</a></div>{{ children }}</li>'); ?> </ul> </div> </div> </section> </div> <div class="one_half last"> <section class="title"> <h4><?php echo lang('category:tree_explanation_title'); ?> </h4> </section> <section class="item">