<commit_before><?php
/**
 * CoolMS2 Common Module (http://www.coolms.com/)
 *
 * @link      http://github.com/coolms/common for the canonical source repository
 * @copyright Copyright (c) 2006-2015 Altgraphic, ALC (http://www.altgraphic.com)
 * @license   http://www.coolms.com/license/new-bsd New BSD License
 * @author    <NAME> <<EMAIL>>
 */

namespace CmsCommon\View\Helper\Navigation;

use RecursiveIteratorIterator,
    Zend\Navigation\AbstractContainer,
    Zend\Navigation\Page\AbstractPage,
    Zend\View\Helper\Navigation\Menu as MenuHelper,
    CmsCommon\View\Helper\Decorator\Decorator;

class Menu extends MenuHelper
{
    /**
     * @var string
     */
    protected $decoratorNamespace = Decorator::OPTION_KEY;

    /**
     * @var bool
     */
    protected $inheritUlClass = false;

    /**
     * @var string
     */
    protected $id;

    /**
     * @var string
     */
    protected $liContainerClass = 'hasChild';

    /**
     * {@inheritDoc}
     */
    public function renderMenu($container = null, array $options = [])
    {
        if (!empty($options['id'])) {
            $this->id = (string) $options['id'];
        }

        return parent::renderMenu($container, $options);
    }

    /**
     * {@inheritDoc}
     */
    protected function renderNormalMenu(
        AbstractContainer $container,
        $ulClass,
        $indent,
        $minDepth,
        $maxDepth,
        $onlyActive,
        $escapeLabels,
        $addClassToListItem,
        $liActiveClass
    ) {
        $html = '';

        // find deepest active
        $found = $this->findActive($container, $minDepth, $maxDepth);
        /* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */
        $escaper = $this->view->plugin('escapeHtmlAttr');

        if ($found) {
            $foundPage  = $found['page'];
            $foundDepth = $found['depth'];
        } else {
            $foundPage = null;
        }

        // create iterator
        $iterator = new RecursiveIteratorIterator(
            $container,
            RecursiveIteratorIterator::SELF_FIRST
        );

        if (is_int($maxDepth)) {
            $iterator->setMaxDepth($maxDepth);
        }

        // iterate container
        $prevDepth = -1;
        foreach ($iterator as $page) {
            $depth = $iterator->getDepth();
            $isActive = $page->isActive(true);
            if ($depth < $minDepth || !$this->accept($page)) {
                // page is below minDepth or not accepted by acl/visibility
                continue;
            } elseif ($onlyActive && !$isActive) {
                // page is not active itself, but might be in the active branch
                $accept = false;
                if ($foundPage) {
                    if ($foundPage->hasPage($page)) {
                        // accept if page is a direct child of the active page
                        $accept = true;
                    } elseif ($foundPage->getParent()->hasPage($page)) {
                        // page is a sibling of the active page...
                        if (!$foundPage->hasPages(!$this->renderInvisible) ||
                            is_int($maxDepth) && $foundDepth + 1 > $maxDepth
                        ) {
                            // accept if active page has no children, or the
                            // children are too deep to be rendered
                            $accept = true;
                        }
                    }
                }

                if (!$accept) {
                    continue;
                }
            }

            // make sure indentation is correct
            $depth -= $minDepth;
            $myIndent = $indent . str_repeat('        ', $depth);

            if ($depth > $prevDepth) {
                if (!$this->inheritUlClass()) {
                    $commonUlClass = null;
                }

                // start new ul tag
                if ($ulClass && $depth == 0) {
                    $commonUlClass = $ulClass;
                    $ulClass = ' class="' . $escaper($ulClass) . '"';
                    if ($this->id) {
                        $ulClass .= ' id="' . $escaper($this->id) . '"';
                        $this->id = null;
                    }
                } else {
                    if ($commonUlClass) {
                        $ulClass = $commonUlClass . ' ' . $ulClass;
                    }

                    $ulClass = $ulClass ? ' class="' . $escaper($ulClass) . '"' : '';
                }

                $html .= $myIndent . '<ul' . $ulClass . '>' . PHP_EOL;
            } elseif ($prevDepth > $depth) {
                // close li/ul tags until we're at current depth
                for ($i = $prevDepth; $i > $depth; $i--) {
                    $ind = $indent . str_repeat('        ', $i);
                    $html .= $ind . '    </li>' . PHP_EOL;
                    $html .= $ind . '</ul>' . PHP_EOL;
                }

                // close previous li tag
                $html .= $myIndent . '    </li>' . PHP_EOL;
            } else {
                // close previous li tag
                $html .= $myIndent . '    </li>' . PHP_EOL;
            }

            // render li tag and page
            $liClasses = [];
            // Is page active?
            if ($isActive) {
                $liClasses[] = $liActiveClass;
            }
<commit_msg>Initial commit<commit_after><?php
/**
 * CoolMS2 Common Module (http://www.coolms.com/)
 *
 * @link      http://github.com/coolms/common for the canonical source repository
 * @copyright Copyright (c) 2006-2015 Altgraphic, ALC (http://www.altgraphic.com)
 * @license   http://www.coolms.com/license/new-bsd New BSD License
 * @author    <NAME> <<EMAIL>>
 */

namespace CmsCommon\View\Helper\Navigation;

use RecursiveIteratorIterator,
    Zend\Navigation\AbstractContainer,
    Zend\Navigation\Page\AbstractPage,
    Zend\View\Helper\Navigation\Menu as MenuHelper,
    CmsCommon\View\Helper\Decorator\Decorator;

class Menu extends MenuHelper
{
    /**
     * @var string
     */
    protected $decoratorNamespace = Decorator::OPTION_KEY;

    /**
     * @var bool
     */
    protected $inheritUlClass = false;

    /**
     * @var string
     */
    protected $id;

    /**
     * @var string
     */
    protected $liContainerClass;

    /**
     * {@inheritDoc}
     */
    public function renderMenu($container = null, array $options = [])
    {
        if (!empty($options['id'])) {
            $this->id = (string) $options['id'];
        }

        return parent::renderMenu($container, $options);
    }

    /**
     * {@inheritDoc}
     */
    protected function renderNormalMenu(
        AbstractContainer $container,
        $ulClass,
        $indent,
        $minDepth,
        $maxDepth,
        $onlyActive,
        $escapeLabels,
        $addClassToListItem,
        $liActiveClass
    ) {
        $html = '';

        // find deepest active
        $found = $this->findActive($container, $minDepth, $maxDepth);
        /* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */
        $escaper = $this->view->plugin('escapeHtmlAttr');

        if ($found) {
            $foundPage  = $found['page'];
            $foundDepth = $found['depth'];
        } else {
            $foundPage = null;
        }

        // create iterator
        $iterator = new RecursiveIteratorIterator(
            $container,
            RecursiveIteratorIterator::SELF_FIRST
        );

        if (is_int($maxDepth)) {
            $iterator->setMaxDepth($maxDepth);
        }

        // iterate container
        $prevDepth = -1;
        foreach ($iterator as $page) {
            $depth = $iterator->getDepth();
            $isActive = $page->isActive(true);
            if ($depth < $minDepth || !$this->accept($page)) {
                // page is below minDepth or not accepted by acl/visibility
                continue;
            } elseif ($onlyActive && !$isActive) {
                // page is not active itself, but might be in the active branch
                $accept = false;
                if ($foundPage) {
                    if ($foundPage->hasPage($page)) {
                        // accept if page is a direct child of the active page
                        $accept = true;
                    } elseif ($foundPage->getParent()->hasPage($page)) {
                        // page is a sibling of the active page...
                        if (!$foundPage->hasPages(!$this->renderInvisible) ||
                            is_int($maxDepth) && $foundDepth + 1 > $maxDepth
                        ) {
                            // accept if active page has no children, or the
                            // children are too deep to be rendered
                            $accept = true;
                        }
                    }
                }

                if (!$accept) {
                    continue;
                }
            }

            // make sure indentation is correct
            $depth -= $minDepth;
            $myIndent = $indent . str_repeat('        ', $depth);

            if ($depth > $prevDepth) {
                if (!$this->inheritUlClass()) {
                    $commonUlClass = null;
                }

                // start new ul tag
                if ($ulClass && $depth == 0) {
                    $commonUlClass = $ulClass;
                    $ulClass = ' class="' . $escaper($ulClass) . '"';
                    if ($this->id) {
                        $ulClass .= ' id="' . $escaper($this->id) . '"';
                        $this->id = null;
                    }
                } else {
                    if ($commonUlClass) {
                        $ulClass = $commonUlClass . ' ' . $ulClass;
                    }

                    $ulClass = trim($ulClass);
                    $ulClass = $ulClass ? ' class="' . $escaper($ulClass) . '"' : '';
                }

                $html .= $myIndent . '<ul' . $ulClass . '>' . PHP_EOL;
            } elseif ($prevDepth > $depth) {
                // close li/ul tags until we're at current depth
                for ($i = $prevDepth; $i > $depth; $i--) {
                    $ind = $indent . str_repeat('        ', $i);
                    $html .= $ind . '    </li>' . PHP_EOL;
                    $html .= $ind . '</ul>' . PHP_EOL;
                }

                // close previous li tag
                $html .= $myIndent . '    </li>' . PHP_EOL;
            } else {
                // close previous li tag
                $html .= $myIndent . '    </li>' . PHP_EOL;
            }

            // render li tag and page
            $liClasses = [];
            // Is page active?
            if ($isActive) {
                $liClasses[] = $liActiveClass;
            }

{'fraction_non_alphanumeric': 0.1312494202764122, 'fraction_numerical': 0.002226138577126426, 'mean_word_length': 1.2636993491496955, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '347956', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2828, 'n_words': 662}