Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Forums / Cotonti / Extensions / Add URI Scheme to HTMLPurifier

Hodges
#1 2014-01-22 17:14

Hi,

Can anyone help me add the tel: URI scheme to HTMLPurifier? All the example instructions on doing this refer to path structures dissimilar from Cotonti's implementation of HTMLPurifier.

Cheers,
Hodges

Macik
#2 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, 1 year ago)