好吧,我成功地定制注射器添加到HTMLPurifier,那就是:
首先,在创建 “DisplayRemoteLinkURI.php”“包括\ htmlpurifier \库\ HTMLPurifier \注射器“写这在它
class HTMLPurifier_Injector_DisplayRemoteLinkURI extends HTMLPurifier_Injector
{
public $name = 'DisplayRemoteLinkURI';
public $needed = array('a');
public function handleElement(&$token) {
}
public function handleEnd(&$token) {
if (isset($token->start->attr['href'])){
$url = $token->start->attr['href'];
if($this->is_remote($url)){
unset($token->start->attr['href']);
$token = array($token, new HTMLPurifier_Token_Text(" ($url)"));
}
} else {
// nothing to display
}
}
public function is_remote($path){
$urlvar = parse_url($path);
$remote_schemes = array("mailto");
$local_schemes = array("javascript");
if(in_array($urlvar["scheme"],$remote_schemes)){
return true;
}else if(in_array($urlvar["scheme"],$local_schemes)){
return false;
}else{
if(empty($urlvar["host"]) || $urlvar["host"]==$_SERVER["HTTP_HOST"]){
return false;
}else{
return true;
}
}
}
}
?>
然后创建一个名为另一个文件” AUT oFormat.DisplayRemoteLinkURI.txt “中的”包括\ htmlpurifier \库\ HTMLPurifier \ ConfigSchema \模式“,并补充一点:
AutoFormat.DisplayRemoteLinkURI
TYPE: bool
VERSION: 3.2.0
DEFAULT: false
--DESCRIPTION--
This directive turns on the in-text display of Remote URIs in <a> tags, and disables
those links. For example, example becomes
example (http://example.com).
--# vim: et sw=4 sts=4
之后,添加此行
require 'HTMLPurifier/Injector/DisplayRemoteLinkURI.php';
下
require 'HTMLPurifier/Injector/DisplayLinkURI.php';
in include \ htmlpurifier \ library \ HTMLPurifier.includes.php
然后,添加这一行
require_once $__dir . '/HTMLPurifier/Injector/DisplayRemoteLinkURI.php';
下
require_once $__dir . '/HTMLPurifier/Injector/DisplayLinkURI.php';
在包括\ htmlpurifier \库\ HTMLPurifier.safe-包括。php
经过这些编辑,如果你的文件在本地,运行cmd.exe并进入你的php目录。然后从php.exe运行“include/HTMLPurifier/maintenance/generate-schema-cache.php”。
或者如果你想通过浏览器做到这一点,重命名你的.htaccess文件内的“include/HTMLPurifier/maintenance /”一段时间,然后将此行添加到“generate-schema-cache.php” <?php标签后的第一行 ;
php_set_env("PHP_IS_CLI",true);
然后从浏览器运行此文件。在看到“保存模式完成!”后,重命名您的.htaccess文件。
然后在您的脚本中,使用“AutoFormat.DisplayRemoteLinkURI”作为配置,瞧!
请注意,我在这里给出的第一个文件中的is_remote()函数可能不太好,而且我找不到检查链接是远程还是本地链接的脚本,因此如果您以后可能会更改该链接需要。