<commit_before><?php
/*
 * @author Anakeen
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package FDL
*/
/**
 * Get Html Value for document
 * @class DocHtmlFormat
 *
 */
class DocHtmlFormat
{
    /**
     * @var Doc
     */
    public $doc = null;
    private $index = - 1;
    private $target = '_self';
    /**
     * @var NormalAttribute
     */
    private $oattr = null;
    private $attrid = '';
    /**
     * format set in type
     * @var string
     */
    private $cFormat = '';
    private $htmlLink = true;
    private $useEntities = true;
    private $abstractMode = false;
    /**
     * @var bool to send once vault error
     */
    private $vaultErrorSent = false;
    
    public function __construct(Doc & $doc)
    {
        $this->setDoc($doc);
    }
    
    public function setDoc(Doc & $doc)
    {
        $this->doc = $doc;
    }
    /**
     * @param NormalAttribute $oattr
     * @param string $value raw value
     * @param string $target
     * @param bool $htmlLink
     * @param int $index
     * @param bool $useEntities
     * @param bool $abstractMode
     * @return string the HTML formated value
     */
    public function getHtmlValue($oattr, $value, $target = "_self", $htmlLink = true, $index = - 1, $useEntities = true, $abstractMode = false)
    {
        global $action;
        
        $this->oattr = $oattr;
        $this->target = $target;
        $this->index = $index;
        $this->cFormat = $this->oattr->format;
        $atype = $this->oattr->type;
        $this->htmlLink = $htmlLink;
        $this->useEntities = $useEntities;
        $this->abstractMode = $abstractMode;
        
        if (($this->oattr->repeat) && ($this->index <= 0)) {
            $tvalues = explode("\n", $value);
        } else {
            $tvalues[$this->index] = $value;
        }
        $this->attrid = $this->oattr->id;
        $thtmlval = array();
        foreach ($tvalues as $kvalue => $avalue) {
            
            switch ($atype) {
                case "idoc":
                    $htmlval = $this->formatIDoc($kvalue, $avalue);
                    break;

                case "image":
                    $htmlval = $this->formatImage($kvalue, $avalue);
                    break;

                case "file":
                    
                    $htmlval = $this->formatFile($kvalue, $avalue);
                    break;

                case "longtext":
                case "xml":
                    
                    $htmlval = $this->formatLongtext($kvalue, $avalue);
                    break;

                case "password":
                    
                    $htmlval = $this->formatPassword($kvalue, $avalue);
                    break;

                case "enum":
                    
                    $htmlval = $this->formatEnum($kvalue, $avalue);
                    break;

                case "array":
                    
                    $htmlval = $this->formatArray($kvalue, $avalue);
                    break;

                case "doc":
                    $htmlval = $this->formatDoc($kvalue, $avalue);
                    break;

                case "account":
                    $htmlval = $this->formatAccount($kvalue, $avalue);
                    break;

                case "docid":
                    $htmlval = $this->formatDocid($kvalue, $avalue);
                    break;

                case "thesaurus":
                    
                    $htmlval = $this->formatThesaurus($kvalue, $avalue);
                    break;

                case "option":
                    
                    $htmlval = $this->formatOption($kvalue, $avalue);
                    break;

                case 'money':
                    
                    $htmlval = $this->formatMoney($kvalue, $avalue);
                    break;

                case 'htmltext':
                    
                    $htmlval = $this->formatHtmltext($kvalue, $avalue);
                    break;

                case 'date':
                    
                    $htmlval = $this->formatDate($kvalue, $avalue);
                    break;

                case 'time':
                    
                    $htmlval = $this->formatTime($kvalue, $avalue);
                    break;

                case 'timestamp':
                    
                    $htmlval = $this->formatTimeStamp($kvalue, $avalue);
                    
                    break;

                case 'ifile':
                    
                    $htmlval = $this->formatIfile($kvalue, $avalue);
                    break;

                case 'color':
                    $htmlval = $this->formatColor($kvalue, $avalue);
                    break;

                default:
                    $htmlval = $this->formatDefault($kvalue, $avalue);
                    
                    break;
            }
            
            $abegin = $aend = '';
            if ($htmlval == '' && $this->oattr->getOption('showempty')) {
                $htmlval = $this->oattr->getOption('showempty');
            } else if (($this->cFormat != "") && ($atype != "doc") && ($atype != "array") && ($atype != "option")) {
                //printf($htmlval);
                $htmlval = sprintf($this->cFormat, $htmlval);
            }
            // add link if needed
            if ($this->htmlLink && ($this->oattr->link != "")) {
                $ititle = "";
                $hlink = $this->oattr->link;
                if ($hlink[0] == "[") {
                    if (preg_match('/\[(.*)\](.*)/', $hlink, $reg)) {
                        $hlink = $reg[2];
                        $ititle = str_replace("\"", "'", $reg[1]);
                    }
                }
                if ($ulink = $this->doc->urlWhatEncode($hlink, $kvalue)) {
                    if ($this->target == "ext") {
                        if (preg_match("/FDL_CARD.*id=([0-9]+)/", $ulink, $reg)) {
                            
                            $abegin = $this->doc->getDocAnchor($reg[1], $this->target, true, html_entity_decode($htmlval));
                            $htmlval = '';
                            $aend = "";
                        } else if (true || preg_match("/^http:/", $ulink, $reg)) {
                            $ec = getSessionValue("ext:targetUrl");
                            <commit_msg>explicit encoding in html decode(refs #3381)<commit_after><?php
/*
 * @author Anakeen
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 * @package FDL
*/
/**
 * Get Html Value for document
 * @class DocHtmlFormat
 *
 */
class DocHtmlFormat
{
    /**
     * @var Doc
     */
    public $doc = null;
    private $index = - 1;
    private $target = '_self';
    /**
     * @var NormalAttribute
     */
    private $oattr = null;
    private $attrid = '';
    /**
     * format set in type
     * @var string
     */
    private $cFormat = '';
    private $htmlLink = true;
    private $useEntities = true;
    private $abstractMode = false;
    /**
     * @var bool to send once vault error
     */
    private $vaultErrorSent = false;
    
    public function __construct(Doc & $doc)
    {
        $this->setDoc($doc);
    }
    
    public function setDoc(Doc & $doc)
    {
        $this->doc = $doc;
    }
    /**
     * @param NormalAttribute $oattr
     * @param string $value raw value
     * @param string $target
     * @param bool $htmlLink
     * @param int $index
     * @param bool $useEntities
     * @param bool $abstractMode
     * @return string the HTML formated value
     */
    public function getHtmlValue($oattr, $value, $target = "_self", $htmlLink = true, $index = - 1, $useEntities = true, $abstractMode = false)
    {
        global $action;
        
        $this->oattr = $oattr;
        $this->target = $target;
        $this->index = $index;
        $this->cFormat = $this->oattr->format;
        $atype = $this->oattr->type;
        $this->htmlLink = $htmlLink;
        $this->useEntities = $useEntities;
        $this->abstractMode = $abstractMode;
        
        if (($this->oattr->repeat) && ($this->index <= 0)) {
            $tvalues = explode("\n", $value);
        } else {
            $tvalues[$this->index] = $value;
        }
        $this->attrid = $this->oattr->id;
        $thtmlval = array();
        foreach ($tvalues as $kvalue => $avalue) {
            
            switch ($atype) {
                case "idoc":
                    $htmlval = $this->formatIDoc($kvalue, $avalue);
                    break;

                case "image":
                    $htmlval = $this->formatImage($kvalue, $avalue);
                    break;

                case "file":
                    
                    $htmlval = $this->formatFile($kvalue, $avalue);
                    break;

                case "longtext":
                case "xml":
                    
                    $htmlval = $this->formatLongtext($kvalue, $avalue);
                    break;

                case "password":
                    
                    $htmlval = $this->formatPassword($kvalue, $avalue);
                    break;

                case "enum":
                    
                    $htmlval = $this->formatEnum($kvalue, $avalue);
                    break;

                case "array":
                    
                    $htmlval = $this->formatArray($kvalue, $avalue);
                    break;

                case "doc":
                    $htmlval = $this->formatDoc($kvalue, $avalue);
                    break;

                case "account":
                    $htmlval = $this->formatAccount($kvalue, $avalue);
                    break;

                case "docid":
                    $htmlval = $this->formatDocid($kvalue, $avalue);
                    break;

                case "thesaurus":
                    
                    $htmlval = $this->formatThesaurus($kvalue, $avalue);
                    break;

                case "option":
                    
                    $htmlval = $this->formatOption($kvalue, $avalue);
                    break;

                case 'money':
                    
                    $htmlval = $this->formatMoney($kvalue, $avalue);
                    break;

                case 'htmltext':
                    
                    $htmlval = $this->formatHtmltext($kvalue, $avalue);
                    break;

                case 'date':
                    
                    $htmlval = $this->formatDate($kvalue, $avalue);
                    break;

                case 'time':
                    
                    $htmlval = $this->formatTime($kvalue, $avalue);
                    break;

                case 'timestamp':
                    
                    $htmlval = $this->formatTimeStamp($kvalue, $avalue);
                    
                    break;

                case 'ifile':
                    
                    $htmlval = $this->formatIfile($kvalue, $avalue);
                    break;

                case 'color':
                    $htmlval = $this->formatColor($kvalue, $avalue);
                    break;

                default:
                    $htmlval = $this->formatDefault($kvalue, $avalue);
                    
                    break;
            }
            
            $abegin = $aend = '';
            if ($htmlval == '' && $this->oattr->getOption('showempty')) {
                $htmlval = $this->oattr->getOption('showempty');
            } else if (($this->cFormat != "") && ($atype != "doc") && ($atype != "array") && ($atype != "option")) {
                //printf($htmlval);
                $htmlval = sprintf($this->cFormat, $htmlval);
            }
            // add link if needed
            if ($this->htmlLink && ($this->oattr->link != "")) {
                $ititle = "";
                $hlink = $this->oattr->link;
                if ($hlink[0] == "[") {
                    if (preg_match('/\[(.*)\](.*)/', $hlink, $reg)) {
                        $hlink = $reg[2];
                        $ititle = str_replace("\"", "'", $reg[1]);
                    }
                }
                if ($ulink = $this->doc->urlWhatEncode($hlink, $kvalue)) {
                    if ($this->target == "ext") {
                        if (preg_match("/FDL_CARD.*id=([0-9]+)/", $ulink, $reg)) {
                            
                            $abegin = $this->doc->getDocAnchor($reg[1], $this->target, true, html_entity_decode($htmlval, ENT_QUOTES, 'UTF-8'));
                            $htmlval = '';
                            $aend = "";
                        } else if (true || preg_match("/^http:/", $ulink, $reg)) {
                            $ec = getSessionValue("ext:targetUrl");
                            
{'fraction_non_alphanumeric': 0.13982985305491105, 'fraction_numerical': 0.0020881670533642693, 'mean_word_length': 1.134885256727753, 'pattern_counts': {'":': 26, '<': 7, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '2342352', 'n_tokens_mistral': 3607, 'n_tokens_neox': 3378, 'n_words': 701}