刚刚使用最新的Custom Contact Forms更新了WordPress网站。更新后,网站不再加载,我看到这些错误:
[27-Jun-2015 06:01:05 UTC] PHP Warning: SimpleXMLElement::__construct(): Entity: line 130: parser error : Opening and ending tag mismatch: wphead line 1 and script in /storage/web/public/sites/www.site.nl/wp-content/themes/site/vihv/control/TControl.php on line 91
[27-Jun-2015 06:01:05 UTC] PHP Warning: SimpleXMLElement::__construct(): </script> in /storage/web/public/sites/www.site.nl/wp-content/themes/site/vihv/control/TControl.php on line 91
[27-Jun-2015 06:01:05 UTC] PHP Warning: SimpleXMLElement::__construct(): ^ in /storage/web/public/sites/www.site.nl/wp-content/themes/site/vihv/control/TControl.php on line 91
[27-Jun-2015 06:01:05 UTC] PHP Warning: SimpleXMLElement::__construct(): Entity: line 148: parser error : Sequence ']]>' not allowed in content in /storage/web/public/sites/www.site.nl/wp-content/themes/site/vihv/control/TControl.php on line 91
第一个错误是指这个函数:
function GetXml() {
try {
$Xml = new SimpleXmlElement(TXml::MakeTree($this->GetData(), get_class($this)));
return $Xml->asXml();
} catch(Exception $e) {
//print_r($this->GetData());
}
return "<".get_class($this)."/>";
}
但这些错误只是PHP警告,而不是致命错误。但无论如何我都会看到死亡的白屏。
我不熟悉XML和XML解析。主题由第三方开发者创建,至今尚未与他联系。自这个主题创建以来已经有一段时间了。 我取消了print_r的注释,看看会显示什么,所有内容都打印出来,第一个数组出现了:
Array ( [THeadControl] => Array ( [wphead] => ]]> [template_url] => http://www.site.nl/wp-content/themes/site [title] => ) [TLeftBlockContainer] => Array ( [THeaderControl] => Array ( [siteurl] => http://www.site.nl [siteTitle] => VERLOSKUNDIGENPRAKTIJK site [headpic] => http://www.site.nl/wp-content/uploads/2015/02/siteheader2.jpg [logoPhone] => http://www.site.nl/wp-content/themes/site/img/logo-phone.png ) [TSimpleMenuControl] => Array ( [menu] =>
在第130行,我看到了
<script type='text/javascript' src='http://www.site.nl/wp-includes/js/underscore.min.js?ver=1.6.0'></script>
我怀疑该插件会在标头中添加一些内容,导致html标记错误/创建无效的XML。
更新 这里添加了__construct()方法,如@danbahrami
所示function __construct() {
$Manager = TEventManager::getInstance();
$Manager->AddListener($this);
$this->SetEvent('OnGet', array($this,'OnGetEvent'));
$this->SetEvent('OnPost', array($this,'OnPostEvent'));
$this->SetEvent('OnDisplay', array($this,'OnDisplayEvent'));
$this->SetEvent('OnBeforeDisplay', array($this,'OnBeforeDisplayEvent'));
$this->SetEvent('OnEnable', array($this,'OnEnableEvent'));
$this->SetEvent('OnDisable', array($this,'OnDisableEvent'));
$this->SetEvent('OnCreate', array($this,'OnCreateEvent'));
$this->SetEvent('OnRootTemplateLoad', array($this,'OnRootTemplateLoadEvent'));
$this->SetEvent('OnDefaultPage', array($this,'OnDefaultPageEvent'));
$this->OnCreate($this);
}
可以看到整个文件TControl.php here。我该如何调试此错误?是否可以绕过错误?
答案 0 :(得分:0)
自定义联系表单在CDATA标记中添加了一个JavaScript,注释掉/* <![CDATA[ */
和/* ]]> */
。还有一个子弹粘贴为•
,这扼杀了XML Parser。似乎解析器不喜欢CDATA以这种方式注释掉。
为了调试,我得到了另一位使用
print("<pre>");
var_dump($this->GetData());
libxml_use_internal_errors(true);
echo 'Caught exception: ', $e->getMessage(), "\n";
print($xml);
die();
但为了测试它,他从输出中复制了xml,保存到文件并通过单独的脚本检查出来:
$xml = file_get_contents("qqq.xml");
$xml = str_replace("", "X", $xml);
$xml = preg_replace("@/\*.*\*/@", "", $xml);
$rr = simplexml_load_string($xml);
var_dump($rr);
如果一切正常,哪些打印错误或XML。使用调整后的TConfig函数
$xml = $TXml->MakeTree($this->GetData(), get_class($this));
#$xml = str_replace("", "-", $xml);
#$xml = preg_replace("@/\*.*\*/@", "", $xml);
$xml = preg_replace("@/\*.*\*/@", "<!-- commented out -->", $xml);
$Xml = new SimpleXmlElement($xml);
return $Xml->asXml();
} catch(Exception $e) {
print("<pre>");
var_dump($this->GetData());
libxml_use_internal_errors(true);
echo 'Caught exception: ', $e->getMessage(), "\n";
print($xml);
die();
一切都在恢复。 Preg replace用于删除有问题的CDATA代码。稍后会看到它是否可以在没有/**/
的情况下停留。