Форуми / Cotonti / Extensions / Add URI Scheme to HTMLPurifier

Hodges
#1 22.01.2014 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 22.01.2016 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

Відредаговано: Macik (23.11.2017 00:56, 6 років тому)