<commit_before><?php
/**
 * Wizin framework mobile filter class
 *
 * PHP Versions 4
 *
 * @package  Wizin
 * @author  <NAME> a.k.a. gusagi<<EMAIL>>
 * @copyright 2008 <NAME>
 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 *
 */

if (! class_exists('Wizin_Filter_Mobile')) {
    require dirname(dirname(__FILE__)) . '/Wizin_Filter.php';

    /**
     * Wizin framework mobile filter class
     *
     * @access public
     *
     */
    class Wizin_Filter_Mobile extends Wizin_Filter
    {
        /**
         *
         * @return object $instance
         */
        function &getSingleton()
        {
            static $instance;
            if (! isset($instance)) {
                $instance = new Wizin_Filter_Mobile();
            }
            return $instance;
        }

        /**
         * execute input filter
         *
         * @access public
         *
         */
        function executeInputFilter()
        {
            $parent =& parent::getSingleton();
            $inputFilter = $this->_aInputFilter;
            $parentInputFilter = $parent->_aInputFilter;
            $count = count($parentInputFilter);
            for ($index = 0; $index < $count; $index ++) {
                $inputFilter[] = $parentInputFilter[$index];
            }
            $this->_aInputFilter = $inputFilter;
            parent::executeInputFilter();
            $parent->_aInputFilter = array();
        }

        /**
         * execute output filter
         *
         * @access public
         *
         * @param string $contents
         */
        function executeOutputFilter(& $contents)
        {
            $parent =& parent::getSingleton();
            $outputFilter = $this->_aOutputFilter;
            $parentOutputFilter = $parent->_aOutputFilter;
            $count = count($parentOutputFilter);
            for ($index = 0; $index < $count; $index ++) {
                $outputFilter[] = $parentOutputFilter[$index];
            }
            $this->_aOutputFilter = $outputFilter;
            parent::executeOutputFilter($contents);
            $parent->_aOutputFilter = array();
        }

        /**
         * call input filter for mobile
         *
         */
        function filterInputMobile()
        {
            $method = strtolower(getenv('REQUEST_METHOD'));
            if ($method === 'get') {
                $_GET = $this->_filterInputKanaConvert($_GET);
            } else if ($method === 'post') {
                $_POST = $this->_filterInputKanaConvert($_POST);
            }
            $_REQUEST = $this->_filterInputKanaConvert($_REQUEST);
        }

        /**
         * convert kana filter for input value with mobile
         *
         * @param array $input
         * @return array $_input
         */
        function _filterInputKanaConvert($input)
        {
            if (extension_loaded('mbstring')) {
                $_input = array();
                foreach ($input as $key => $value) {
                    if (empty($value) && $value === '') {
                        $_input[$key] = '';
                    } else if (is_array($value)) {
                        $_input[$key] = $this->_filterInputKanaConvert($value);
                    } else {
                        $_input[$key] = mb_convert_kana($value, 'KV');
                    }
                }
            } else {
                $_input = $input;
            }
            return $_input;
        }

        /**
         * optimizer filter for mobile
         *
         * @param string $contents
         * @param string $baseUri
         * @param string $currentUri
         * @param string $basePath
         * @param string $createDir
         * @return string $contents
         */
        function filterOptimizeMobile(& $contents, $params = array())
        {
            extract($params);
            if (! isset($createDir)) {
                $createDir = WIZIN_CACHE_DIR;
            }
            $resizeParams = array(
                'baseUri' => $baseUri,
                'currentUri' => $currentUri,
                'basePath' => $basePath,
                'createDir' => $createDir,
                'maxWidth' => $maxWidth,
                'forceResizeType' => array(IMAGETYPE_PNG)
            );
            Wizin_Filter::filterResizeImage($contents, $resizeParams);
            // replace input type "password" => "text"
            /*
            $pattern = '(<input)([^>]*)(type=)([\"\'])(password)([\"\'])([^>]*)(>)';
            $replacement = '${1}${2}${3}${4}text${6} ${7}${8}';
            $contents = preg_replace("/" .$pattern ."/i", $replacement, $contents);
            */
            $pattern = '(enctype=)([\"\'])(multipart\/form-data)([\"\'])';
            $replacement = '';
            $contents = preg_replace("/" .$pattern ."/i", $replacement, $contents);
            $pattern = '(<input)([^>]*)(type=)([\"\'])(file)([\"\'])([^>]*)(>)';
            $replacement = '${1}${2}${3}${4}hidden${6} ${7}${8}';
            $contents = preg_replace("/" .$pattern ."/i", $replacement, $contents);
            Wizin_Filter_Mobile::filterDeleteTags($contents, $final = true);
            Wizin_Filter_Mobile::filterInsertAnchor($contents, $baseUri, $currentUri);
            // convert from zenkaku to hankaku
            if (extension_loaded('mbstring')) {
                $contents = mb_convert_kana($contents, 'knr');
            }
            // delete contiguous space
            $this->minimize($contents);
            // add mobile link discovery tag
            $pattern = '(<link)([^>]*)(media=)([\"\'])(handheld)([\"\'])([^>]*)(>)';
            if (! preg_match("/" .$pattern ."/i", $contents)) {
                $mobileLinkDiscovery = '<link rel="alternate" media="handheld" type="text/html"' .
                    ' href="' .$currentUri .'" />';
                $contents = str_replace('</head>', $mobileLinkDiscovery .'</head>', $contents);
            }
            // return contents string
            return $contents;
        }<commit_msg>replace '&' string for mobile link discovery.<commit_after><?php
/**
 * Wizin framework mobile filter class
 *
 * PHP Versions 4
 *
 * @package  Wizin
 * @author  <NAME> a.k.a. gusagi<<EMAIL>>
 * @copyright 2008 <NAME>
 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 *
 */

if (! class_exists('Wizin_Filter_Mobile')) {
    require dirname(dirname(__FILE__)) . '/Wizin_Filter.php';

    /**
     * Wizin framework mobile filter class
     *
     * @access public
     *
     */
    class Wizin_Filter_Mobile extends Wizin_Filter
    {
        /**
         *
         * @return object $instance
         */
        function &getSingleton()
        {
            static $instance;
            if (! isset($instance)) {
                $instance = new Wizin_Filter_Mobile();
            }
            return $instance;
        }

        /**
         * execute input filter
         *
         * @access public
         *
         */
        function executeInputFilter()
        {
            $parent =& parent::getSingleton();
            $inputFilter = $this->_aInputFilter;
            $parentInputFilter = $parent->_aInputFilter;
            $count = count($parentInputFilter);
            for ($index = 0; $index < $count; $index ++) {
                $inputFilter[] = $parentInputFilter[$index];
            }
            $this->_aInputFilter = $inputFilter;
            parent::executeInputFilter();
            $parent->_aInputFilter = array();
        }

        /**
         * execute output filter
         *
         * @access public
         *
         * @param string $contents
         */
        function executeOutputFilter(& $contents)
        {
            $parent =& parent::getSingleton();
            $outputFilter = $this->_aOutputFilter;
            $parentOutputFilter = $parent->_aOutputFilter;
            $count = count($parentOutputFilter);
            for ($index = 0; $index < $count; $index ++) {
                $outputFilter[] = $parentOutputFilter[$index];
            }
            $this->_aOutputFilter = $outputFilter;
            parent::executeOutputFilter($contents);
            $parent->_aOutputFilter = array();
        }

        /**
         * call input filter for mobile
         *
         */
        function filterInputMobile()
        {
            $method = strtolower(getenv('REQUEST_METHOD'));
            if ($method === 'get') {
                $_GET = $this->_filterInputKanaConvert($_GET);
            } else if ($method === 'post') {
                $_POST = $this->_filterInputKanaConvert($_POST);
            }
            $_REQUEST = $this->_filterInputKanaConvert($_REQUEST);
        }

        /**
         * convert kana filter for input value with mobile
         *
         * @param array $input
         * @return array $_input
         */
        function _filterInputKanaConvert($input)
        {
            if (extension_loaded('mbstring')) {
                $_input = array();
                foreach ($input as $key => $value) {
                    if (empty($value) && $value === '') {
                        $_input[$key] = '';
                    } else if (is_array($value)) {
                        $_input[$key] = $this->_filterInputKanaConvert($value);
                    } else {
                        $_input[$key] = mb_convert_kana($value, 'KV');
                    }
                }
            } else {
                $_input = $input;
            }
            return $_input;
        }

        /**
         * optimizer filter for mobile
         *
         * @param string $contents
         * @param string $baseUri
         * @param string $currentUri
         * @param string $basePath
         * @param string $createDir
         * @return string $contents
         */
        function filterOptimizeMobile(& $contents, $params = array())
        {
            extract($params);
            if (! isset($createDir)) {
                $createDir = WIZIN_CACHE_DIR;
            }
            $resizeParams = array(
                'baseUri' => $baseUri,
                'currentUri' => $currentUri,
                'basePath' => $basePath,
                'createDir' => $createDir,
                'maxWidth' => $maxWidth,
                'forceResizeType' => array(IMAGETYPE_PNG)
            );
            Wizin_Filter::filterResizeImage($contents, $resizeParams);
            // replace input type "password" => "text"
            /*
            $pattern = '(<input)([^>]*)(type=)([\"\'])(password)([\"\'])([^>]*)(>)';
            $replacement = '${1}${2}${3}${4}text${6} ${7}${8}';
            $contents = preg_replace("/" .$pattern ."/i", $replacement, $contents);
            */
            $pattern = '(enctype=)([\"\'])(multipart\/form-data)([\"\'])';
            $replacement = '';
            $contents = preg_replace("/" .$pattern ."/i", $replacement, $contents);
            $pattern = '(<input)([^>]*)(type=)([\"\'])(file)([\"\'])([^>]*)(>)';
            $replacement = '${1}${2}${3}${4}hidden${6} ${7}${8}';
            $contents = preg_replace("/" .$pattern ."/i", $replacement, $contents);
            Wizin_Filter_Mobile::filterDeleteTags($contents, $final = true);
            Wizin_Filter_Mobile::filterInsertAnchor($contents, $baseUri, $currentUri);
            // convert from zenkaku to hankaku
            if (extension_loaded('mbstring')) {
                $contents = mb_convert_kana($contents, 'knr');
            }
            // delete contiguous space
            $this->minimize($contents);
            // add mobile link discovery tag
            $pattern = '(<link)([^>]*)(media=)([\"\'])(handheld)([\"\'])([^>]*)(>)';
            if (! preg_match("/" .$pattern ."/i", $contents)) {
                $mobileLinkDiscovery = '<link rel="alternate" media="handheld" type="text/html"' .
                    ' href="' .str_replace('&', '&amp;',$currentUri) .'" />';
                $contents = str_replace('</head>', $mobileLinkDiscovery .'</head>', $contents);
            }
            // return contents string
            return $contents;
        }
{'fraction_non_alphanumeric': 0.15778654826508798, 'fraction_numerical': 0.003453379378391712, 'mean_word_length': 1.6005986743639085, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2200184', 'n_tokens_mistral': 3379, 'n_tokens_neox': 3261, 'n_words': 628}