src/Budkit/Protocol/Input.php
public function getFormattedString($name, $default = '', $verb = 'post', $blacklisted = array())
    {
        //FILTER_SANITIZE_STRING
        //FILTER_SANITIZE_STRIPPED
        //\IS\HTML;
        //just form casting
        if (strtolower($verb) == 'request') {
            $verb = $this->getVerb();
        }
        $verb = strtolower($verb);

        if (!($input = $this->data($verb))) {
            return $default;
        }

        //Undefined
        if (empty($name) || !isset($input) || !isset($input[$name])) {
            if (isset($default) && !empty($default)) {
                return $default;
            } else {
                return null; //nothing for that name;
            }
        }
        //uhhhnrrr...
        $string = $input[$name];


        //print_R($string);

        //DOMDocument will screw up the encoding so we utf8 encode everything?
        $string = mb_convert_encoding($string, 'utf-8', mb_detect_encoding($string));
        $string = mb_convert_encoding($string, 'html-entities', 'utf-8');

        //if string is empty no need to proceed;

        if (empty($string)) return $string;


        $doc = new \DOMDocument('1.0', 'UTF-8');
        //$doc->substituteEntities = TRUE;
        $doc->loadHTML($string); //Load XML here, if you use loadHTML the string will be wrapped in HTML tags. Not good.
        $xpath = new \DOMXPath($doc);
        //@TODO remove tags that are not allowed;
        //Remove attributes
        $nodes = $xpath->query('//*[@style]');

        foreach ($nodes as $node):
            $node->removeAttribute('style'); //Removes the style attribute;
        endforeach;

        //We don't want to wrap in HTML tags
        $original = $xpath->query("body/*");
        if ($original->length > 0) {
            $string = '';
            foreach ($original as $node) {
                //cannot use doc->saveElement because it wraps it in p tags!
                //so lets just go ahead and use the nodevalue;
                $string .= $node->nodeValue;
            }
        }

        $filter = \IS\SPECIAL_CHARS;
        $options = array(
            "flags" => FILTER_FLAG_ENCODE_LOW, //or strip?
            "options" => array()
        );

        //if (is_array($html)) $str = strip_tags($str, implode('', $html));
        //elseif (preg_match('|<([a-z]+)>|i', $html)) $str = strip_tags($str, $html);
        //elseif ($html !== true) $str = strip_tags($str);
        //Some tags we really don't need
        $string = $this->filter($string, $filter, $options);

        return $string;
    }
public function getFormattedString($name, $default = '', $verb = 'post', $blacklisted = array())
    {
        //FILTER_SANITIZE_STRING
        //FILTER_SANITIZE_STRIPPED
        //\IS\HTML;
        //just form casting
        if (strtolower($verb) == 'request') {
            $verb = $this->getVerb();
        }
        $verb = strtolower($verb);

        if (!($input = $this->data($verb))) {
            return $default;
        }

        //Undefined
        if (empty($name) || !isset($input) || !isset($input[$name])) {
            if (isset($default) && !empty($default)) {
                return $default;
            } else {
                return null; //nothing for that name;
            }
        }
        //uhhhnrrr...
        $string = $input[$name];


        //print_R($string);

        //DOMDocument will screw up the encoding so we utf8 encode everything?
        $string = mb_convert_encoding($string, 'utf-8', mb_detect_encoding($string));
        $string = mb_convert_encoding($string, 'html-entities', 'utf-8');

        //if string is empty no need to proceed;

        if (empty($string)) return $string;


        $doc = new \DOMDocument('1.0', 'UTF-8');
        //$doc->substituteEntities = TRUE;
        $doc->loadHTML($string); //Load XML here, if you use loadHTML the string will be wrapped in HTML tags. Not good.
        $xpath = new \DOMXPath($doc);
        //@TODO remove tags that are not allowed;
        //Remove attributes
        $nodes = $xpath->query('//*[@style]');

        foreach ($nodes as $node):
            $node->removeAttribute('style'); //Removes the style attribute;
        endforeach;

        //We don't want to wrap in HTML tags
        $original = $xpath->query("body/*");
        if ($original->length > 0) {
            $string = '';
            foreach ($original as $node) {
                //cannot use doc->saveElement because it wraps it in p tags!
                //so lets just go ahead and use the nodevalue;
                $string .= $node->nodeValue;
            }
        }

        $filter = \IS\SPECIAL_CHARS;
        $options = array(
            "flags" => FILTER_FLAG_ENCODE_LOW, //or strip?
            "options" => array()
        );

        //if (is_array($html)) $str = strip_tags($str, implode('', $html));
        //elseif (preg_match('|<([a-z]+)>|i', $html)) $str = strip_tags($str, $html);
        //elseif ($html !== true) $str = strip_tags($str);
        //Some tags we really don't need
        $string = $this->filter($string, $filter, $options);

        return $string;
    }
public function getFormattedString ( $ name , $ default = '' , $ verb = 'post' , $ blacklisted = array ( ) ) { //FILTER_SANITIZE_STRING //FILTER_SANITIZE_STRIPPED //\IS\HTML; //just form casting if ( strtolower ( $ verb ) == 'request' ) { $ verb = $ this -> getVerb ( ) ; } $ verb = strtolower ( $ verb ) ; if ( ! ( $ input = $ this -> data ( $ verb ) ) ) { return $ default ; } //Undefined if ( empty ( $ name ) || ! isset ( $ input ) || ! isset ( $ input [ $ name ] ) ) { if ( isset ( $ default ) && ! empty ( $ default ) ) { return $ default ; } else { return null ; //nothing for that name; } } //uhhhnrrr... $ string = $ input [ $ name ] ; //print_R($string); //DOMDocument will screw up the encoding so we utf8 encode everything? $ string = mb_convert_encoding ( $ string , 'utf-8' , mb_detect_encoding ( $ string ) ) ; $ string = mb_convert_encoding ( $ string , 'html-entities' , 'utf-8' ) ; //if string is empty no need to proceed; if ( empty ( $ string ) ) return $ string ; $ doc = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; //$doc->substituteEntities = TRUE; $ doc -> loadHTML ( $ string ) ; //Load XML here, if you use loadHTML the string will be wrapped in HTML tags. Not good. $ xpath = new \ DOMXPath ( $ doc ) ; //@TODO remove tags that are not allowed; //Remove attributes $ nodes = $ xpath -> query ( '//*[@style]' ) ; foreach ( $ nodes as $ node ) : $ node -> removeAttribute ( 'style' ) ; //Removes the style attribute; endforeach ; //We don't want to wrap in HTML tags $ original = $ xpath -> query ( "body/*" ) ; if ( $ original -> length > 0 ) { $ string = '' ; foreach ( $ original as $ node ) { //cannot use doc->saveElement because it wraps it in p tags! //so lets just go ahead and use the nodevalue; $ string .= $ node -> nodeValue ; } } $ filter = \ IS \ SPECIAL_CHARS ; $ options = array ( "flags" => FILTER_FLAG_ENCODE_LOW , //or strip? "options" => array ( ) ) ; //if (is_array($html)) $str = strip_tags($str, implode('', $html)); //elseif (preg_match('|<([a-z]+)>|i', $html)) $str = strip_tags($str, $html); //elseif ($html !== true) $str = strip_tags($str); //Some tags we really don't need $ string = $ this -> filter ( $ string , $ filter , $ options ) ; return $ string ; }
Returns a formatted string

@param type $name
@param type $default
@param type $verb
@param type $allowedtags
Returns a formatted string