<commit_before><?php
class Kwc_Menu_Mobile_Controller extends Kwf_Controller_Action
{
    public function jsonIndexAction()
    {
        if ($this->_getParam('subrootComponentId')) {
            $cacheId = 'kwcMenuMobile-root-' . $this->_getParam('subrootComponentId').'-'.$this->_getParam('class');
        } else if ($this->_getParam('pageId')) {
            $cacheId = 'kwcMenuMobile-' . $this->_getParam('pageId');
        }
        foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $plugin) {
            $plugin->preDispatch($this->_getParam('pageUrl'));
        }
        $data = Kwf_Cache_Simple::fetch($cacheId);
        if ($data === false) {
            if ($this->_getParam('subrootComponentId')) {
                $pages = $this->_getChildPages();
            } else if ($this->_getParam('pageId')) {
                $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('pageId'));
                $pages = $this->_getChildPagesRecursive(array($component), 2);
                foreach ($pages as $k=>$p) {
                    unset($pages[$k]['name']);
                    unset($pages[$k]['url']);
                }
            }
            $data = array(
                'lifetime' => 60*60,
                'mimeType' => 'application/json',
                'mtime' => time(),
                'contents' => json_encode(array(
                    'pages' => $pages
                ))
            );
            Kwf_Cache_Simple::add($cacheId, $data);
        }

        $skipProcessPages = true;
        foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_MaskComponent') as $plugin) {
            if (!$plugin->canIgnoreMasks()) {
                $skipProcessPages = false;
            }
        }
        foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) {
            if (!$plugin->canIgnoreProcessUrl()) {
                $skipProcessPages = false;
            }
        }
        if (!$skipProcessPages) {
            $contents = json_decode($data['contents'], true);
            $contents['pages'] = $this->_processPages($contents['pages']);
            $data['contents'] = json_encode($contents);
        }

        Kwf_Media_Output::output($data);
    }

    protected function _processPages($pages)
    {
        $ret = array();
        foreach ($pages as $page) {
            if (isset($page['mask'])) {
                foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_MaskComponent') as $plugin) {
                    if (!$plugin->showMasked($page['mask']['type'], $page['mask']['params'])) {
                        continue 2; //don't show this page
                    }
                }
            }

            if (isset($page['children'])) {
                $page['children'] = $this->_processPages($page['children']);
            }
            if (isset($page['url'])) {
                foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) {
                    $page['url'] = $plugin->processUrl($page['url']);
                }
            }<commit_msg>Menu_Mobile: when _processPages and showMasked is true remove hidden flag<commit_after><?php
class Kwc_Menu_Mobile_Controller extends Kwf_Controller_Action
{
    public function jsonIndexAction()
    {
        if ($this->_getParam('subrootComponentId')) {
            $cacheId = 'kwcMenuMobile-root-' . $this->_getParam('subrootComponentId').'-'.$this->_getParam('class');
        } else if ($this->_getParam('pageId')) {
            $cacheId = 'kwcMenuMobile-' . $this->_getParam('pageId');
        }
        foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $plugin) {
            $plugin->preDispatch($this->_getParam('pageUrl'));
        }
        $data = Kwf_Cache_Simple::fetch($cacheId);
        if ($data === false) {
            if ($this->_getParam('subrootComponentId')) {
                $pages = $this->_getChildPages();
            } else if ($this->_getParam('pageId')) {
                $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('pageId'));
                $pages = $this->_getChildPagesRecursive(array($component), 2);
                foreach ($pages as $k=>$p) {
                    unset($pages[$k]['name']);
                    unset($pages[$k]['url']);
                }
            }
            $data = array(
                'lifetime' => 60*60,
                'mimeType' => 'application/json',
                'mtime' => time(),
                'contents' => json_encode(array(
                    'pages' => $pages
                ))
            );
            Kwf_Cache_Simple::add($cacheId, $data);
        }

        $skipProcessPages = true;
        foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_MaskComponent') as $plugin) {
            if (!$plugin->canIgnoreMasks()) {
                $skipProcessPages = false;
            }
        }
        foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) {
            if (!$plugin->canIgnoreProcessUrl()) {
                $skipProcessPages = false;
            }
        }
        if (!$skipProcessPages) {
            $contents = json_decode($data['contents'], true);
            $contents['pages'] = $this->_processPages($contents['pages']);
            $data['contents'] = json_encode($contents);
        }

        Kwf_Media_Output::output($data);
    }

    protected function _processPages($pages)
    {
        $ret = array();
        foreach ($pages as $page) {
            if (isset($page['mask'])) {
                foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_MaskComponent') as $plugin) {
                    if (!$plugin->showMasked($page['mask']['type'], $page['mask']['params'])) {
                        continue 2; //don't show this page
                    } else {
                        unset($page['hidden']);
                    }
                }
            }

            if (isset($page['children'])) {
                $page['children'] = $this->_processPages($page['children']);
            }
            if (isset($page['url'])) {
                foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) {
                    $page['url'] = $plugin->processUrl($page['url']);
                }
            }
{'fraction_non_alphanumeric': 0.1515419802272392, 'fraction_numerical': 0.0017706949977866313, 'mean_word_length': 2.072529465095195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2204592', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1771, 'n_words': 261}