public function autoParagraph($string, $allowedTags = null, $linkUrls = true)
    {
        if(is_null($allowedTags))
            $allowedTags = $this->defaultAllowedTags;

        if(is_null($this->purifier))
        {
            require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php';

            $this->purifier = HTMLPurifier::instance();

            FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory.'/purifier/');
        }

        if ($this->injectors == null && $linkUrls)
            $this->injectors = array(new CF_HTMLPurifier_Injector_Linkify());

        $purifierConfig = array(
                'Core.Encoding'            => $this->charset,
                'AutoFormat.AutoParagraph' => true,
                'HTML.TidyLevel'           =>'none',
                'HTML.Allowed'             => $allowedTags,
                'Cache.SerializerPath'     => $this->vendorCacheDirectory
                );

        if(!is_null($this->injectors))
            $purifierConfig['AutoFormat.Custom'] = $this->injectors;

        $string = $this->purifier->purify($string, $purifierConfig);

        $string = str_replace("\n\n", '[DBLBR]', $string);
        $string = str_replace("\n", '<br/>', $string);
        $string = str_replace('[DBLBR]', "\n\n", $string);

        // trim links
        $string = preg_replace_callback("/\<a\s+href\=\"(".URLUtils::URL_MATCH.")\"\>\\1<\/a\>/Uix",
                    array($this, 'trimCallback'), $string);


        // trim all words longer than 60 chars that aren't URLs, ignoring tags
        if (preg_match_all("/\S60/", strip_tags(preg_replace('/(\<(\/?[^\>]+)\>)/', ' $1', $string)), $m)) {
            foreach ($m[0] as $n) {
                if( !preg_match("/".URLUtils::URL_MATCH."/", $n) )
                    $string = str_replace($n, trim(substr($n, 0, (60 - 3)), '.') . '...', $string);
            }
        }


        return $string;
    }
public function autoParagraph($string, $allowedTags = null, $linkUrls = true)
    {
        if(is_null($allowedTags))
            $allowedTags = $this->defaultAllowedTags;

        if(is_null($this->purifier))
        {
            require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php';

            $this->purifier = HTMLPurifier::instance();

            FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory.'/purifier/');
        }

        if ($this->injectors == null && $linkUrls)
            $this->injectors = array(new CF_HTMLPurifier_Injector_Linkify());

        $purifierConfig = array(
                'Core.Encoding'            => $this->charset,
                'AutoFormat.AutoParagraph' => true,
                'HTML.TidyLevel'           =>'none',
                'HTML.Allowed'             => $allowedTags,
                'Cache.SerializerPath'     => $this->vendorCacheDirectory
                );

        if(!is_null($this->injectors))
            $purifierConfig['AutoFormat.Custom'] = $this->injectors;

        $string = $this->purifier->purify($string, $purifierConfig);

        $string = str_replace("\n\n", '[DBLBR]', $string);
        $string = str_replace("\n", '<br/>', $string);
        $string = str_replace('[DBLBR]', "\n\n", $string);

        // trim links
        $string = preg_replace_callback("/\<a\s+href\=\"(".URLUtils::URL_MATCH.")\"\>\\1<\/a\>/Uix",
                    array($this, 'trimCallback'), $string);


        // trim all words longer than 60 chars that aren't URLs, ignoring tags
        if (preg_match_all("/\S60/", strip_tags(preg_replace('/(\<(\/?[^\>]+)\>)/', ' $1', $string)), $m)) {
            foreach ($m[0] as $n) {
                if( !preg_match("/".URLUtils::URL_MATCH."/", $n) )
                    $string = str_replace($n, trim(substr($n, 0, (60 - 3)), '.') . '...', $string);
            }
        }


        return $string;
    }
public function autoParagraph ( $ string , $ allowedTags = null , $ linkUrls = true ) { if ( is_null ( $ allowedTags ) ) $ allowedTags = $ this -> defaultAllowedTags ; if ( is_null ( $ this -> purifier ) ) { require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php' ; $ this -> purifier = HTMLPurifier :: instance ( ) ; FileSystemUtils :: recursiveMkdir ( $ this -> vendorCacheDirectory . '/purifier/' ) ; } if ( $ this -> injectors == null && $ linkUrls ) $ this -> injectors = array ( new CF_HTMLPurifier_Injector_Linkify ( ) ) ; $ purifierConfig = array ( 'Core.Encoding' => $ this -> charset , 'AutoFormat.AutoParagraph' => true , 'HTML.TidyLevel' => 'none' , 'HTML.Allowed' => $ allowedTags , 'Cache.SerializerPath' => $ this -> vendorCacheDirectory ) ; if ( ! is_null ( $ this -> injectors ) ) $ purifierConfig [ 'AutoFormat.Custom' ] = $ this -> injectors ; $ string = $ this -> purifier -> purify ( $ string , $ purifierConfig ) ; $ string = str_replace ( "\n\n" , '[DBLBR]' , $ string ) ; $ string = str_replace ( "\n" , '<br/>' , $ string ) ; $ string = str_replace ( '[DBLBR]' , "\n\n" , $ string ) ; // trim links $ string = preg_replace_callback ( "/\<a\s+href\=\"(" . URLUtils :: URL_MATCH . ")\"\>\\1<\/a\>/Uix" , array ( $ this , 'trimCallback' ) , $ string ) ; // trim all words longer than 60 chars that aren't URLs, ignoring tags if ( preg_match_all ( "/\S60/" , strip_tags ( preg_replace ( '/(\<(\/?[^\>]+)\>)/' , ' $1' , $ string ) ) , $ m ) ) { foreach ( $ m [ 0 ] as $ n ) { if ( ! preg_match ( "/" . URLUtils :: URL_MATCH . "/" , $ n ) ) $ string = str_replace ( $ n , trim ( substr ( $ n , 0 , ( 60 - 3 ) ) , '.' ) . '...' , $ string ) ; } } return $ string ; }
Marks up a string with paragraphs and automatically links any urls.

This function marks up the output with paragraph tags and auto-links any URLs that are found.
The resulting output is suitable for display in any web-browser, but must have
paragraph and extra html tags removed before it's ready for editing.

Content is XSS cleaned and stripped of all but a few tags (specified by implementation.)

@param string $string      The HTML string to format
@param string $allowedTags (optional) A comma-separated list of allowed tags.

@return string A nicely-formatted version of the input text, with automatic paragraphs and urls in place

@see unAutoParagraph()
Marks up a string with paragraphs and automatically links any urls .