<commit_before><?php
class Kwc_Menu_Mobile_Controller extends Kwf_Controller_Action
{
    public function jsonIndexAction()
    {
        $categoryComponents = $this->_getCategoryComponent();

        $cacheId = 'kwcMenuMobile-' . $this->_getParam('componentId');
        $data = Kwf_Cache_Simple::fetch($cacheId);
        if ($data === false) {
            $data = array(
                'lifetime' => 60*60,
                'mimeType' => 'application/json',
                'mtime' => time(),
                'contents' => json_encode(array(
                    'pages' => $this->_getChildPages($categoryComponents)
                ))
            );
            Kwf_Cache_Simple::add($cacheId, $data);
        }

        Kwf_Media_Output::output($data);
    }

    protected function _isAllowedComponent()
    {
        return true;
    }

    protected function _getChildPages($parentPage)
    {
        $ret = array();
        $i = 0;
        if (!is_array($parentPage)) $parentPage = array($parentPage);
        foreach ($parentPage as $component) {
            $pages = $component->getChildPages(array('showInMenu'=>true));
            foreach($pages as $page) {
                $ret[$i]['name'] = $page->name;
                $ret[$i]['url'] = $page->url;
                $ret[$i]['class'] = array();
                $ret[$i]['children'] = $this->_getChildPages($page);

                if ($page->row && isset($page->row->device_visible)) $ret[$i]['class'][] = $page->row->device_visible;
                if ($i == 0) $ret[$i]['class'][] = 'first';
                if ($i == count($pages)-1) $ret[$i]['class'][] = 'last';
                if (!empty($ret[$i]['children'])) $ret[$i]['class'][] = 'hasChildren';
                $ret[$i]['class'] = implode(' ', $ret[$i]['class']);

                $i++;
            }
        }
        return $ret;
    }

    protected function _getCategoryComponent()
    {
        $category = Kwc_Abstract::getSetting($this->_getParam('class'), 'level');
        if (is_string($category)) $category = array($category);
        $categoryClass = null;
        $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('subrootComponentId'));

        $categoryComponents = array();
        foreach($component->getChildComponents(array('flag' => 'menuCategory')) as $cat) {
            if (in_array($cat->id, $category)) $categoryComponents[] = $cat;
        }
        return $categoryComponents;
    }
}
<commit_msg>Menu_Mobile: don't show menu items with hideOnMobile device visiblity<commit_after><?php
class Kwc_Menu_Mobile_Controller extends Kwf_Controller_Action
{
    public function jsonIndexAction()
    {
        $categoryComponents = $this->_getCategoryComponent();

        $cacheId = 'kwcMenuMobile-' . $this->_getParam('componentId');
        $data = Kwf_Cache_Simple::fetch($cacheId);
        if ($data === false) {
            $data = array(
                'lifetime' => 60*60,
                'mimeType' => 'application/json',
                'mtime' => time(),
                'contents' => json_encode(array(
                    'pages' => $this->_getChildPages($categoryComponents)
                ))
            );
            Kwf_Cache_Simple::add($cacheId, $data);
        }

        Kwf_Media_Output::output($data);
    }

    protected function _isAllowedComponent()
    {
        return true;
    }

    protected function _getChildPages($parentPage)
    {
        $ret = array();
        $i = 0;
        if (!is_array($parentPage)) $parentPage = array($parentPage);
        foreach ($parentPage as $component) {
            $pages = $component->getChildPages(array('showInMenu'=>true));
            foreach($pages as $page) {
                if ($page->row
                    && isset($page->row->device_visible)
                    && $page->row->device_visible == Kwf_Component_Data::DEVICE_VISIBLE_HIDE_ON_MOBILE
                ) {
                    continue;
                }

                $ret[$i]['name'] = $page->name;
                $ret[$i]['url'] = $page->url;
                $ret[$i]['class'] = array();
                $ret[$i]['children'] = $this->_getChildPages($page);

                if ($i == 0) $ret[$i]['class'][] = 'first';
                if ($i == count($pages)-1) $ret[$i]['class'][] = 'last';
                if (!empty($ret[$i]['children'])) $ret[$i]['class'][] = 'hasChildren';
                $ret[$i]['class'] = implode(' ', $ret[$i]['class']);

                $i++;
            }
        }
        return $ret;
    }

    protected function _getCategoryComponent()
    {
        $category = Kwc_Abstract::getSetting($this->_getParam('class'), 'level');
        if (is_string($category)) $category = array($category);
        $categoryClass = null;
        $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('subrootComponentId'));

        $categoryComponents = array();
        foreach($component->getChildComponents(array('flag' => 'menuCategory')) as $cat) {
            if (in_array($cat->id, $category)) $categoryComponents[] = $cat;
        }
        return $categoryComponents;
    }
}

{'fraction_non_alphanumeric': 0.16979670861568247, 'fraction_numerical': 0.0027105517909002904, 'mean_word_length': 2.167381974248927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '4913423', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1422, 'n_words': 245}