gpt4 book ai didi

htmlpurifier - 如何配置 HTML 净化器以允许 anchor href 值中包含 "callto:123"?

转载 作者:行者123 更新时间:2023-12-04 04:17:30 27 4
gpt4 key购买 nike

有人能告诉我如何让这样的 anchor 标签不受影响地通过 htmlpurifier 吗? :

<a href="callto:+1-800-555-1212" class="callUsBtn" style="">...</a>

用我的配置。设置,callto:... 值未被识别为允许的,因此整个 href 属性被删除。我想我需要覆盖 href 值的 type(<-- 或者怎么调用它?),从 URICDATA(?),但不知道如何。我希望有比这里的指示更快/更简单的方法:http://htmlpurifier.org/docs/enduser-customize.html (如果这会导致解决方案?)。

最佳答案

多亏了爱德华的回答,我才开始工作。

试试这个:

在这里相当于:
/htmlpurifier-4_4_0/library/HTMLPurifier/URIScheme/

添加一个名为:callto.php
的文件...具有这些内容:

<?php

// replicated this class/file from '../htmlpurifier-4_4_0/library/HTMLPurifier/URIScheme/mailto.php'

// VERY RELAXED! Shouldn't cause problems, ... but be careful!

/**
* Validates 'callto:' phone number in URI to included only alphanumeric, hyphens, underscore, and optional leading "+"
*/

class HTMLPurifier_URIScheme_callto 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;

/* notes:
where is the actual phone # parked? Answer in $uri->path. See here:

echo '<pre style="color:pink;">';
var_dump($uri);
echo '</pre>';

object(HTMLPurifier_URI)#490 (7) {
["scheme"]=>
string(6) "callto"
["userinfo"]=>
NULL
["host"]=>
NULL
["port"]=>
NULL
["path"]=>
string(15) "+1-800-555-1212"
["query"]=>
NULL
["fragment"]=>
NULL
}
*/

// are the characters in the submitted <a> href's (URI) value (callto:) from amongst a legal/allowed set?
// my legal phone # chars: alphanumeric, underscore, hyphen, optional "+" for the first character. That's it. But you can allow whatever you want. Just change this:
$validCalltoPhoneNumberPattern = '/^\+?[a-zA-Z0-9_-]+$/i'; // <---whatever pattern you want to force phone numbers to match
$proposedPhoneNumber = $uri->path;
if (preg_match($validCalltoPhoneNumberPattern, $proposedPhoneNumber) !== 1) {
// submitted phone # inside the href attribute value looks bad; reject the phone number, and let HTMLpurifier remove the whole href attribute on the submitted <a> tag.
return FALSE;
} else {
// submitted phone # inside the href attribute value looks OK; accept the phone number; HTMLpurifier should NOT strip the href attribute on the submitted <a> tag.
return TRUE;
}
}

}

...并且不要忘记更新您的 HTMLpurifier 配置,从默认配置开始,包括如下内容:

$config->set('URI.AllowedSchemes', array ('http' => true, 'https' => true, 'mailto' => true, 'ftp' => true, 'nntp' => true, 'news' => true, 'callto' => true,));

关于htmlpurifier - 如何配置 HTML 净化器以允许 anchor href 值中包含 "callto:123"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10458783/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com