<commit_before><?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

namespace ANS\PHPCan\Data\Formats;

defined('ANS') or die();

class Html extends Formats implements Iformats
{
    public $format = 'html';

    public function check ($value)
    {
        $this->error = array();

        return $this->validate($value);
    }

    public function valueForm ($value)
    {
        return array(
            '' => str_replace("\n", '', $value[''])
        );
    }

    public function valueDB (\ANS\PHPCan\Data\Db $Db, $value, $language = '', $id = 0)
    {
        return $this->fixValue($value);
    }

    public function fixValue ($value)
    {
        $value = xssClean($value['']);

        $value = str_replace(' class=', 'class|', $value);
        $value = preg_replace('# [a-z]+=["\'][^"\']*["\']#i', '', $value);
        $value = str_replace('class|', ' class=', $value);
        $value = preg_replace('#</?(font|span)[^>]*>#', '', $value);
        $value = str_replace('&nbsp;', ' ', $value);

        return array('' => $value);
    }

    public function settings ($settings)
    {
        $this->settings = $this->setSettings($settings, array(
            '' => array(
                'db_type' => 'text',

                'length_max' => ''
            )
        ));

        return $this->settings;
    }
}<commit_msg>Improved html format<commit_after><?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

namespace ANS\PHPCan\Data\Formats;

defined('ANS') or die();

class Html extends Formats implements Iformats
{
    public $format = 'html';

    public function check ($value)
    {
        $this->error = array();

        return $this->validate($value);
    }

    public function valueForm ($value)
    {
        return array(
            '' => str_replace("\n", '', $value[''])
        );
    }

    public function valueDB (\ANS\PHPCan\Data\Db $Db, $value, $language = '', $id = 0)
    {
        return $this->fixValue($value);
    }

    public function fixValue ($value)
    {
        $value = xssClean($value['']);

        if (empty($this->settings['']['clean'])) {
            $value = preg_replace('# style=["\'][^"\']+["\']#i', '', $value);
            $value = preg_replace('#</?font[^>]*>#', '', $value);
        } else {
            $valid = 'class|src|target|alt|title|href|rel';

            $value = preg_replace('# ('.$valid.')=#i', ' |$1|', $value);
            $value = preg_replace('# [a-z]+=["\'][^"\']*["\']#i', '', $value);
            $value = preg_replace('#\|('.$valid.')\|#i', ' $1=', $value);
            $value = preg_replace('#</?(font|span)[^>]*>#', '', $value);
        }

        $value = str_replace('&nbsp;', ' ', $value);

        return array('' => $value);
    }

    public function settings ($settings)
    {
        $this->settings = $this->setSettings($settings, array(
            '' => array(
                'db_type' => 'text',

                'length_max' => ''
            )
        ));

        return $this->settings;
    }
}
{'fraction_non_alphanumeric': 0.21021303258145363, 'fraction_numerical': 0.0018796992481203006, 'mean_word_length': 2.2122736418511066, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 32, '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': '3390789', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1003, 'n_words': 212}