Forums / Cotonti / Extensions / Add URI Scheme to HTMLPurifier

Macik
#41317 2016-01-22 22:45

If it still actual, here are the example code — add it to `htmlpurifier.group_5.preset.php` (admin group preset):

class HTMLPurifier_URIScheme_tel extends HTMLPurifier_URIScheme {
 
    public $browsable = false;
    public $may_omit_host = true;
 
    public function doValidate(&$uri, $config, $context) {
        $uri->userinfo = null;
        $uri->host     = null;
        $uri->port     = null;
 
        $validCalltoPhoneNumberPattern = '/^\+?[\(\)\.0-9_-]+$/i'; // <---whatever pattern you want to force phone numbers to match
        $proposedPhoneNumber = $uri->path; // defined phone
        if (preg_match($validCalltoPhoneNumberPattern, $proposedPhoneNumber) !== 1) {
            return FALSE;
        } else {
            return TRUE;
        }
    }
}
 
$config->set('URI.AllowedSchemes', array ('http' => true, 'https' => true, 'mailto' => true, 'ftp' => true, 'nntp' => true, 'news' => true, 'tel' => true,));
HTMLPurifier_URISchemeRegistry::instance()->register(new HTMLPurifier_URIScheme_tel, $config);


For more detailed information, check these links:  

Update: starting from version 4.8.0 HTML Purifier support `tel:` scheme by default.

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
This post was edited by Macik (2017-11-23 00:56, 7 years ago)