<div class="section map">
    <ul>
        <li><a href="">Homepage</a></li>
        <li><a href="product">Products</a></li>
        <?php if ($tree) : ?>
            <?php
            function tree2(array &$tree, $parent = 1, $path = '')
            {
                echo '<ul>';
                
                foreach ($tree[$parent] as $c)
                {
                    echo '<li><a href="product/index/' . htmlspecialchars($path . $c['path']) . '">' . htmlspecialchars($c['name']) . '</a>';
                    echo '<ul>';
                    
                    foreach (product::get_list($c['id']) as $p)
                    {
                        echo '<li><a href="product/view/' . htmlspecialchars($path . $c['path'] . '/' . $p['path']) . '">' . htmlspecialchars($p['name']) . '</a></li>';
                    }
                    
                    if (array_key_exists($c['id'], $tree))
                    {
                        tree2($tree, $c['id'], ltrim($path . '/' . $c['path'] . '/', '/'));
                    }
                    
                    echo '</ul>';
                }
                
                echo '</ul>';
            }
            tree2($tree, 1);
            ?>
        <?php endif; ?>
        <?php foreach ($page as $p) : ?>
            <li><a href="page/view/<?php echo htmlspecialchars($p['path']); ?>"><?php echo htmlspecialchars($p['name']); ?></a></li>
        <?php endforeach; ?>
        <li><a href="contact">Contact us</a></li>
        <?php foreach ($word as $w) : ?>
            <li><a href="search?search=<?php echo htmlspecialchars($w['word']); ?>"><?php echo htmlspecialchars($w['word']); ?></a></li>
        <?php endforeach; ?>
    </ul>
</div>