好吧,我成功地定制注射器添加到HTMLPurifier,那就是:
首先,在创建 “DisplayRemoteLinkURI.php”“包括\ htmlpurifier \库\ HTMLPurifier \注射器“写这在它
<?php
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--
<p>
This directive turns on the in-text display of Remote URIs in <a> tags, and disables
those links. For example, <a href="http://example.com">example</a> becomes
example (<a>http://example.com</a>).
</p>
--# 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()函数可能不太好,而且我找不到检查链接是远程还是本地链接的脚本,因此如果您以后可能会更改该链接需要。
嗨,谢谢你的努力。我创建了该文件,添加了上述代码,并从命令行运行了php文件。文件库/ HTMLPurifier/ConfigSchema/schema.ser被创建。我添加了AutoFormat.DisplayRemoteLinkURI到我的配置,但我得到了这个错误“警告:无法设置未定义的指令AutoFormat.DisplayRemoteLinkURI值......”。我在schema.ser中搜索了DisplayRemoteLinkURI,但是我没有找到它。我的文件是本地的,我运行(php htmlpurifier/maintenance/generate-schema-cache.php)。我收到了消息“Saving schema ... done!' – 2012-03-21 13:02:00
好吧,我没有做任何其他更改。让我再看一次。 – 2012-03-21 13:08:08
还有一个我忘记提到的txt文件。我更新了代码。添加文本文件并重建模式。 – 2012-03-21 13:15:09