安全表单内容
允许你放心地在表单元素中使用HTML字符(例如引号)，不必担心破坏表单。
@param string $str
@param string $field_name
@return string
513674
public static function form_prep($str = '', $field_name = '')
    {
        static $prepped_fields = array();

        // if the field name is an array we do this recursively
        if (is_array($str)) {
            foreach ($str as $key => $val) {
                $str[$key] = self::form_prep($val);
            }

            return $str;
        }

        if ($str === '') {
            return '';
        }

        // we've already prepped a field with this name
        // @todo need to figure out a way to namespace this so
        // that we know the *exact* field and not just one with
        // the same name
        if (isset($prepped_fields[$field_name])) {
            return $str;
        }

        $str = htmlspecialchars($str);

        // In case htmlspecialchars misses these.
        $str = str_replace(array("'", '"'), array("&#39;", "&quot;"), $str);

        if ($field_name != '') {
            $prepped_fields[$field_name] = $str;
        }

        return $str;
    }
775206
public static Leaderboard getFromDKV(String param_name, String key_str) {
    return getFromDKV(param_name, Key.make(key_str));
  }
915957
private function _do($str)
    {
        $str = (string) $str;
        $strInt = (int) $str;
        $strFloat = (float) $str;
        if (
            !$str
            ||
            (string) $strInt === $str
            ||
            (string) $strFloat === $str
        ) {

            // no xss found
            if ($this->_xss_found !== true) {
                $this->_xss_found = false;
            }

            return $str;
        }

        // remove the BOM from UTF-8 / UTF-16 / UTF-32 strings
        $str = UTF8::remove_bom($str);

        // replace the diamond question mark (�) and invalid-UTF8 chars
        $str = UTF8::replace_diamond_question_mark($str, '');

        // replace invisible characters with one single space
        $str = UTF8::remove_invisible_characters($str, true, ' ');

        // normalize the whitespace
        $str = UTF8::normalize_whitespace($str);

        // decode UTF-7 characters
        $str = $this->_repack_utf7($str);

        // decode the string
        $str = $this->_decode_string($str);

        // remove all >= 4-Byte chars if needed
        if ($this->_stripe_4byte_chars) {
            $str = (string) \preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
        }

        // backup the string (for later comparision)
        $str_backup = $str;

        // remove strings that are never allowed
        $str = $this->_do_never_allowed($str);

        // corrects words before the browser will do it
        $str = $this->_compact_exploded_javascript($str);

        // remove disallowed javascript calls in links, images etc.
        $str = $this->_remove_disallowed_javascript($str);

        // remove evil attributes such as style, onclick and xmlns
        $str = $this->_remove_evil_attributes($str);

        // sanitize naughty JavaScript elements
        $str = $this->_sanitize_naughty_javascript($str);

        // sanitize naughty HTML elements
        $str = $this->_sanitize_naughty_html($str);

        // final clean up
        //
        // -> This adds a bit of extra precaution in case something got through the above filters.
        $str = $this->_do_never_allowed_afterwards($str);

        // check for xss
        if ($this->_xss_found !== true) {
            $this->_xss_found = !($str_backup === $str);
        }

        return $str;
    }
681068
public function getSigDecodeInstructions($player_html, $func_name)
    {
        // extract code block from that function
        // single quote in case function name contains $dollar sign
        // xm=function(a){a=a.split("");wm.zO(a,47);wm.vY(a,1);wm.z9(a,68);wm.zO(a,21);wm.z9(a,34);wm.zO(a,16);wm.z9(a,41);return a.join("")};
        if (preg_match('/' . $func_name . '=function\([a-z]+\){(.*?)}/', $player_html, $matches)) {

            $js_code = $matches[1];

            // extract all relevant statements within that block
            // wm.vY(a,1);
            if (preg_match_all('/([a-z0-9]{2})\.([a-z0-9]{2})\([^,]+,(\d+)\)/i', $js_code, $matches) != false) {

                // must be identical
                $obj_list = $matches[1];

                //
                $func_list = $matches[2];

                // extract javascript code for each one of those statement functions
                preg_match_all('/(' . implode('|', $func_list) . '):function(.*?)\}/m', $player_html, $matches2, PREG_SET_ORDER);

                $functions = array();

                // translate each function according to its use
                foreach ($matches2 as $m) {

                    if (strpos($m[2], 'splice') !== false) {
                        $functions[$m[1]] = 'splice';
                    } elseif (strpos($m[2], 'a.length') !== false) {
                        $functions[$m[1]] = 'swap';
                    } elseif (strpos($m[2], 'reverse') !== false) {
                        $functions[$m[1]] = 'reverse';
                    }
                }

                // FINAL STEP! convert it all to instructions set
                $instructions = array();

                foreach ($matches[2] as $index => $name) {
                    $instructions[] = array($functions[$name], $matches[3][$index]);
                }

                return $instructions;
            }
        }

        return null;
    }
1212647
protected function elementName(string $var_name = ''): string
    {
        if ($this->action) {
            return $this->s::restActionFormElementName($var_name);
        } elseif ($this->cfg->Widget) {
            return $this->cfg->Widget->get_field_name($var_name);
        }
        $parts = $var_name // This is optional.
            ? preg_split('/(\[[^[\]]*\])/u', $var_name, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)
            : []; // An empty value could occur either way.

        if (!$parts) {
            return $this->c::slugToVar($this->cfg->slug);
        } elseif (mb_strpos($parts[0], '[') === 0) {
            return $this->c::slugToVar($this->cfg->slug).implode($parts);
        }
        return $this->c::slugToVar($this->cfg->slug).'['.$parts[0].']'.implode(array_slice($parts, 1));
    }
186972
public function getValue(string $plugin_field_name): string
    {
        self::init();

        $field_full_name = self::$selected_plugin .'_'. $plugin_field_name;

        if (isset(self::$data[$field_full_name])) {
            return self::$data[$field_full_name];
        }

        return ''; // No component - empty content
    }
722967
public function getCleanedFieldAsBool(string $field_name): bool
    {
        // Special case, if we have key set but no value - we keep it as true, e.g. &status=active&order_desc = order_desc must be true
        if (isset($this->initial_data[$field_name]) && '' === $this->initial_data[$field_name]) {
            return $this->initial_data[$field_name] = true;
        }

        return parent::getCleanedFieldAsBool($field_name);
    }
1007061
public function addAutoField($str_name, $mix_value)
    {
        switch(gettype($mix_value)) {
            case 'integer':
            case 'double':
                $this->addNumber($str_name);
                break;

            case 'object':
                if($mix_value instanceof \DateTime) {
                    $this->addDate($str_name);
                } elseif (method_exists($mix_value, '__toString')) {
                    $this->addText($str_name);
                } else {
                    // @todo consider exception
                }
                break;

            case 'array': // @todo consider exception
            case 'string':
            case 'boolean': // @todo consider exception / numeric
            case 'resource': // @todo consider exception
            case 'null':
            case 'unknown type': // @todo consider exception
            default:
                $this->addText($str_name);
        }
        return $this;
    }
1241045
public static function listsToHtml($str)
    {

        $str = preg_replace_callback('/(?:(?:^|\n)[#\*].*)+\n?/m', function($match){

            $type = substr(trim($match[0]), 0, 1) == '#' ? 'ol' : 'ul';

            $star_cnt = 1;
            $lis = preg_replace_callback("~^([\*\#]+)(.*)$~m", function($innermatch){

                return '<li>'.$innermatch[2].'</li>';
            }, trim($match[0]));

            $lis = str_replace(Array("\n</li>", "</li>\n"), "</li>", $lis);
            return '<'.$type.' class="tb">'.$lis.'</'.$type.'>';

        }, $str);

        $str = preg_replace_callback("~\[list\](.*?)\[/list\]\n~s", function($match){

            $lis = preg_replace_callback("~^\w|\s.*$~m", function($inner_match){
                $li = trim($inner_match[0]);
                if(!empty($li)){
                    return '<li class="tb">'.trim($li).'</li>';
                }
                return '';
            }, $match[1]);
            return '<ul class="tb">'.$lis.'</ul>';

        }, $str);

        $str = preg_replace_callback("~\[numlist\](.*?)\[/numlist\]\n?~s", function($match){

            $lis = preg_replace_callback("~^\w|\s.*$~m", function($inner_match){
                $li = trim($inner_match[0]);
                if(!empty($li)){
                    return '<li class="tb">'.trim($li).'</li>';
                }
                return '';
            }, $match[1]);
            return '<ol class="tb">'.$lis.'</ol>';

        }, $str);

        $str = preg_replace_callback('~\n{0,}\t{0,}\[(/?(ol|ul|li))\]\n*~', function($match) {
            if (!strstr($match[1], "/")) {
                return '<' . $match[1] . ' class="tb">';
            } else {
                return '<' . $match[1] . '>';
            }
        }, $str);

        return $str;
    }
208655
public function getNodeElements($field_name)
	{
		$node_elements = $this->findAll(
			'named',
			array('field', $this->getXpathEscaper()->escapeLiteral($field_name))
		);

		if ( empty($node_elements) ) {
			throw new FormException(
				sprintf('Form field "%s" not found', $field_name),
				FormException::TYPE_NOT_FOUND
			);
		}

		return $node_elements;
	}
1235484
static public function formatValue($field, $field_value=null)
    {
        $methods = [];
        if (isset($field['data_format']) && $field['data_format']) {
            $methods[] = $field['data_format'];
        }
        $methods[] = $field['field_name'];
        if (isset($field['base_type']) && $field['base_type']) {
            $methods[] = $field['base_type'];
        }
        $methods[] = $field['data_type'];
        
        foreach ($methods as $m) {
            if (method_exists(get_called_class(), $m)) {
                return static::$m($field_value);
            }
        }
        
        $data_type = strtolower($field['data_type']);
        if (preg_match('/int/', $data_type)) {
            $field_value = intval($field_value);
        } else {
            $field_value = static::output($field_value);
        }
        
        return $field_value;
    }
199005
function(strList) {
            if (typeof(strList) != 'string' || !strList) return [];
            var items = [];
            var field_name_buffer = [];
            var inquote = false;
            var str = $.trim(strList);
            for (var i=0,j=str.length; i<j; i++) {
                if (str.charAt(i) == '\\') {
                    var nextidx = i+1;
                    if (j > nextidx && (str.charAt(nextidx) == '\\' || str.charAt(nextidx) == '"')) {
                        field_name_buffer.push(str.charAt(nextidx));
                        i++;
                        continue;
                    } else {
                        field_name_buffer.push(str.charAt(i));
                        continue;
                    }
                }

                if (str.charAt(i) == '"') {
                    if (!inquote) {
                        inquote = true;
                        continue;
                    } else {
                        inquote = false;
                        items.push(field_name_buffer.join(''));
                        field_name_buffer = [];
                        continue;
                    }
                }

                if ((str.charAt(i) == ' ' || str.charAt(i) == ',') && !inquote) {
                    if (field_name_buffer.length > 0) {
                        items.push(field_name_buffer.join(''));
                    }
                    field_name_buffer = [];
                    continue;
                }
                field_name_buffer.push(str.charAt(i));
            }
            if (field_name_buffer.length > 0) items.push(field_name_buffer.join(''));
            return items;
        }
450873
static function str2array($str, $line_keys = null)
    {
        //切分成多行
        $lines = explode(self::$row_sep, $str);
        $result = array();
        foreach ($lines as $li)
        {
            $li = trim($li);
            if (!empty($li))
            {
                if (is_array($line_keys))
                {
                    //切分成多列
                    $data = self::parse_line($li);
                    $tmp = array();
                    foreach ($line_keys as $index => $key)
                    {
                        $tmp[$key] = $data[$index];
                    }
                    $result[] = $tmp;
                }
                else
                {
                    $result[] = self::parse_line($li);
                }
            }
        }
        return $result;
    }
846968
public static function getForm($url, $token, $field_name)
    {
        $rand = uniqid();

        return '
        <form action="' . $url . '" id="webpay-form-' . $rand . '" method="POST">
            <input type="hidden" name="' . $field_name . '" value="' . $token . '" />
        </form>

        <script>document.getElementById("webpay-form-' . $rand . '").submit();</script>';
    }
81687
public function getFieldValue(string $field_name)
    {
        try {
            $value = null;
            $fields = $this->stmt->fetch(\PDO::FETCH_ASSOC);
            if (array_key_exists($field_name, $fields)) {
                $value = $fields[$field_name];
            } else {
                throw new \Exception("Field '$field_name' is not present in the current result set.\n");
            }
            return $value;
        } catch (\PDOException $e) {
            die('Error: ' . $e->getMessage());
        } catch (\Exception $e) {
            die("Error: " . $e->getMessage());
        }
    }
832267
public function getFieldValue(string $field_name)
    {
        if (false === $this->validated) {
            $this->validate();
        }
        foreach ($this->validators as $validator) {
            if ($validator->getFieldName() == $field_name) {
                return $validator->getValue();
            }
        }
        throw new InvalidInputException('A field called ' . $field_name . ' was not defined.');
    }
1208007
public function error($fieldName, $str)
    {
        // by using this hook you can overwrite default behavior of this method
        if ($this->hookHasCallbacks('displayError')) {
            return $this->hook('displayError', [$fieldName, $str]);
        }

        $jsError = [$this->js()->form('add prompt', $fieldName, $str)];

        return $jsError;
    }