Creates a menu level
@param array $array This should be an array of the menu items
@param int $level
@param array $elements This should be an array containing any attributes to add to the main UL element
@return string Returns the HTML menu string
543417
protected static function createMenuLevel($array, $level, $elements = [], $currentItems = [], $activeClass = 'active', $startLevel = 0, $numLevels = 2){
        $menu = ($level >= $startLevel ? '<ul'.Link::htmlClass($elements['ul_default'].' '.$elements['ul_class'], '').Link::htmlID($elements['ul_id']).'>' : '');
        foreach($array as $item){
            $active = ($currentItems[$level]['uri'] === $item['uri'] ? trim($activeClass) : '');
            $has_child_elements = (is_array($item['children']) && !empty($item['children']) && $level < ($startLevel + $numLevels) ? true : false);
            $menu.= ($level >= $startLevel || $currentItems[$level]['uri'] === $item['uri'] ? ($level < $startLevel && $currentItems[$level]['uri'] === $item['uri'] ? (is_array($item['children']) ? self::createMenuLevel($item['children'], ($level + 1), $elements, $currentItems, $activeClass, $startLevel, $numLevels) : '') : (((isset($item['active']) && boolval($item['active']) === true) || !isset($item['active'])) ? '<li'.Link::htmlClass($elements['li_default'].' '.$item['li_class'], $active).Link::htmlID($item['li_id']).'>'.Link::formatLink($item, $active, $has_child_elements).($has_child_elements ? self::wrapChildren($elements, self::createMenuLevel($item['children'], ($level + 1), $item, $currentItems, $activeClass, $startLevel, $numLevels)) : '').'</li>' : '')) : '');
        }
        $menu.= ($level >= $startLevel ? '</ul>' : '');
        return $menu;
    }
1371749
public function findByLevels($levels = 1, $ids = array())
    {
        $query = $this->createQueryBuilder('c');

        if ($levels > 0) {
            $selects = ['c'];
            for ($i = 1; $i <= $levels; ++$i) {
                $selects[] = 'c'.$i;
            }

            $query->select($selects);

            for ($i = 1; $i <= $levels; ++$i) {
                $previous = ($i - 1 == 0) ? '' : ($i - 1);
                $query->leftJoin('c'.$previous.'.children', 'c'.$i, 'WITH', 'c'.$i.'.active = :active AND c'.$i.'.showInNavigation = :show');
            }
        }

        if ($ids) {
            $query->andWhere('c.id IN (:ids)')->setParameter('ids', $ids);
        } else {
            $query->andWhere('c.parent IS NULL');
        }

        $query->andWhere('c.active = :active')->setParameter('active', true);
        $query->andWhere('c.layout = :layout')->setParameter('layout', false);
        $query->andWhere('c.showInNavigation = :show')->setParameter('show', true);

        return $query->getQuery()->getResult();
    }
643537
protected function toList(array $items = [], $level = 0)
    {
        $prefix = str_repeat('&nbsp;&nbsp;', $level);

        $pages = [];

        foreach ($items as $item) {
            $pages[$item['id']] = $prefix . '' . $item['title'];

            if ($item['children']) {
                $pages += $this->toList($item['children'], $level + 1);
            }
        }

        return $pages;
    }
649750
public function arrayToUnorderedList(array $array): string
    {
        $out = '<ul>';
        foreach ($array as $key => $elem) {
            if (!is_array($elem)) {
                $out = $out . "<li><span>{$key}: " . h($elem) . '</span></li>';
            } else {
                $out = $out . "<li><span>{$key}</span>" . $this->arrayToUnorderedList($elem) . '</li>';
            }
        }
        $out .= '</ul>';

        return $out;
    }
676895
private function menuBuilder(array $menu)
    {
        foreach ($menu as $key => $item) {
            $menu[$key] = $this->menuHelper($item);
            if (isset($item['submenu'])) {
                $menu[$key]['submenu'] = $this->menuBuilder($item['submenu']);
            }
        }

        return $menu;
    }
1323389
protected function createTree(&$list, $parent, $level = 1)
    {
        $tree = [];
        foreach ($parent as $l) {
            $l->level = $level;
            if (isset($list[$l->id])) {
                $l->children = $this->createTree($list, $list[$l->id], ++$level);
                $level--;
            }
            $tree[] = $l;
        }

        return $tree;
    }
923220
public function htmlAttributes($array)
    {
        if (!isset($array)) {
            return null;
        }
       
        $str = "";
        foreach ($array as $key => $value) {
            if (!isset($value) || $value === false) {
                continue;
            }
            
            if ($value === true) {
                $value = $key;
            }
            
            $str .= ' ' . $key . '="' . addcslashes($value, '"') . '"';
        }
        
        return trim($str);
    }
619273
protected function _render($items, $depth = 0)
    {
        $content = '';
        $formatter = $this->config('formatter');

        foreach ($items as $item) {
            $children = '';
            if (is_array($item)) {
                $item = new Entity($item);
            }

            if ($item->has('children') && !empty($item->children) && $item->expanded) {
                $children = $this->formatTemplate('parent', [
                    'attrs' => $this->templater()->formatAttributes([
                        'class' => ($this->config('dropdown') ? 'dropdown-menu multi-level' : ''),
                        'role' => 'menu'
                    ]),
                    'content' => $this->_render($item->children, $depth + 1)
                ]);
            }

            $this->_index++;
            $info = [
                'index' => $this->_index,
                'total' => $this->_count,
                'active' => $this->Link->isActive($item),
                'depth' => $depth,
                'hasChildren' => !empty($children),
                'children' => $children,
            ];
            $content .= $formatter($item, $info);
        }

        return $content;
    }
847860
private function createHeader($children = array(), $text = null)
    {
        return $this->createElement('th', $children, array('class' => $this->options['tableHeaderClass']), $text);
    }
187613
public function getMenu($level = 1)
    {
        if ($level == 1) {
            $result = SiteTree::get()->filter([
                "ShowInMenus" => 1,
                "ParentID" => 0,
            ]);
        } else {
            $parent = $this->data();
            $stack = [$parent];

            if ($parent) {
                while (($parent = $parent->Parent()) && $parent->exists()) {
                    array_unshift($stack, $parent);
                }
            }

            if (isset($stack[$level - 2])) {
                $result = $stack[$level - 2]->Children();
            }
        }

        $visible = [];

        // Remove all entries the can not be viewed by the current user
        // We might need to create a show in menu permission
        if (isset($result)) {
            foreach ($result as $page) {
                /** @var SiteTree $page */
                if ($page->canView()) {
                    $visible[] = $page;
                }
            }
        }

        return new ArrayList($visible);
    }
685683
private function normalizeTree(array &$data, $level = 0)
	{
		if ($level === 0 && isset($data['_id']) && is_array($data['_id'])) {
			$data = array_merge($data['_id'], $data);
			unset($data['_id']);
		}

		foreach ($data as &$item) {
			if (is_array($item)) {
				$this->normalizeTree($item, ++$level);
			} elseif (is_object($item)) {
				$item = $this->driver->convertToPhp($item);
			}
		}
	}
1281186
protected static function convertArrayToString( $array, $breakMode, $level = 1 )
	{
		$list = array();
		foreach( $array as $key => $value )
		{
			$string	= self::convertArgumentToString( $value, $breakMode, $level+1 );
			$list[]	= $key.":".$string;
		}
		$block	= implode( ", ", $list );
		if( $breakMode == 2 )
		{
			$level	= str_repeat( "&nbsp;", 3 * $level );
			$indent	= str_repeat( "&nbsp;", 3 );
			$list	= implode( ",<br/>".$level.$indent.$indent.$indent.$indent, $list );
			$block	= "<br/>".$level.$indent.$indent.$indent.$indent.$list."<br/>".$level.$indent.$indent.$indent;
		}
		if( $breakMode == 3 )
		{
			$block	= self::blockquote( implode( ',<br/>', $list ) );
		}
		return '{'.$block.'}';
	}
164228
protected function _mapFeedHeaders($array)
    {
        $feed = $this->_element->createElement('feed');
        $feed->setAttribute('xmlns', 'http://www.w3.org/2005/Atom');

        $id = $this->_element->createElement('id', $array->link);
        $feed->appendChild($id);

        $title = $this->_element->createElement('title');
        $title->appendChild($this->_element->createCDATASection($array->title));
        $feed->appendChild($title);

        if (isset($array->author)) {
            $author = $this->_element->createElement('author');
            $name = $this->_element->createElement('name', $array->author);
            $author->appendChild($name);
            if (isset($array->email)) {
                $email = $this->_element->createElement('email', $array->email);
                $author->appendChild($email);
            }
            $feed->appendChild($author);
        }

        $updated = isset($array->lastUpdate) ? $array->lastUpdate : time();
        $updated = $this->_element->createElement('updated', date(DATE_ATOM, $updated));
        $feed->appendChild($updated);

        if (isset($array->published)) {
            $published = $this->_element->createElement('published', date(DATE_ATOM, $array->published));
            $feed->appendChild($published);
        }

        $link = $this->_element->createElement('link');
        $link->setAttribute('rel', 'self');
        $link->setAttribute('href', $array->link);
        if (isset($array->language)) {
            $link->setAttribute('hreflang', $array->language);
        }
        $feed->appendChild($link);

        if (isset($array->description)) {
            $subtitle = $this->_element->createElement('subtitle');
            $subtitle->appendChild($this->_element->createCDATASection($array->description));
            $feed->appendChild($subtitle);
        }

        if (isset($array->copyright)) {
            $copyright = $this->_element->createElement('rights', $array->copyright);
            $feed->appendChild($copyright);
        }

        if (isset($array->image)) {
            $image = $this->_element->createElement('logo', $array->image);
            $feed->appendChild($image);
        }

        $generator = !empty($array->generator) ? $array->generator : 'Zend_Feed';
        $generator = $this->_element->createElement('generator', $generator);
        $feed->appendChild($generator);

        return $feed;
    }
1173647
public function getElement(\DOMElement $nodeList, $level = 0, $showPaths = false)
    {
        $tabs = str_repeat("\t", $level);
        $output = '';
        if (!$showPaths) {
            $output = "";
            foreach ($nodeList as $attribute) {
                $output .= $tabs . $attribute->nodeName . " = " . $attribute->nodeValue . "\n";
            }

            $output .= $tabs . $nodeList->nodeName . " = " . $nodeList->nodeValue . "\n";
        } else {
            $output .= $nodeList->getNodePath() . "\n";
        }

        foreach ($nodeList->childNodes as $childObject) {
            if ($childObject instanceof \DOMElement) {
                $output .= $this->getElement($childObject, $level + 1, $showPaths);
            } elseif ($showPaths) {
                $output .= $childObject->getNodePath() . "\n";
            }
        }

        return $output;
    }
365104
public function serialize(Level $level, array $options = [])
    {
        $serialized = [
            'id' => $level->getUuid(),
            'name' => $level->getName(),
            'value' => $level->getValue(),
        ];

        return $serialized;
    }
1290731
function headerLabel( $page, $level )
    {
        $headerLabel = '';
        foreach ( array_keys( $this->TOC ) as $key )
        {
            $header = $this->TOC[$key];
            if ( $header['pageNumber'] > $page )
                return $headerLabel;

            if ( $header['level'] == $level )
            {
                $headerLabel = $header['label'];
            }
            else if ( $header['level'] < $level )
            {
                $headerLabel = '';
            }
        }

        return $headerLabel;
    }
171440
public static function buildFromArray(&$html, $array, $tab = 0)
    {
        $pad = '';
        if ($tab > 0) {
            $pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
        }

        if (!isset($array[1])) {
            $html .= $array[0]."\n";

            return;
        }

        if (!empty($array[0])) {
            $html .= $pad;
            $html .= '<'.$array[0].$array[1].'>';
            $html .= "\n";
        }

        if (!empty($array[2])) {
            $html .= $pad.'  ';
            $html .= $array[2];
            $html .= "\n";
        }

        if (isset($array[3]) && is_array($array[3])) {
            foreach ($array[3] as $child_array) {
                self::buildFromArray($html, $child_array, $tab + 1);
            }
        }

        if (!empty($array[0])) {
            $html .= $pad;
            $html .= '</'.$array[0].'>';
            $html .= "\n";
        }
    }