我有一个干净的Prestashop 1.6.1.6安装。我已经在简短说明产品中包含了Javascript。
保存产品Prestashop时,向我显示错误:
无效的简短说明
当我仅在产品说明中保存文本时没有错误。
Prestashop首选项:
HTML Purifier =否
iframe HTML =是
简短说明long = 0
如何像简短的Prestashop版本一样简短地添加javascript?
Product error message
最佳答案
如果查看Product.php
类的定义:
'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
'description_short' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
您会看到它使用了
isCleanHtml
验证程序。这是
isCleanHtml
验证器:/**
* Check for HTML field validity (no XSS please !)
*
* @param string $html HTML field to validate
* @return bool Validity is ok or not
*/
public static function isCleanHtml($html, $allow_iframe = false)
{
$events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange';
$events .= '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend';
$events .= '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove';
$events .= '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel';
$events .= '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart';
$events .= '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange';
$events .= '|onselectstart|onstart|onstop';
if (preg_match('/<[\s]*script/ims', $html) || preg_match('/('.$events.')[\s]*=/ims', $html) || preg_match('/.*script\:/ims', $html)) {
return false;
}
if (!$allow_iframe && preg_match('/<[\s]*(i?frame|form|input|embed|object)/ims', $html)) {
return false;
}
return true;
}
您可以在
<script>
元素上看到测试。现在的解决方案是覆盖
Product.php
类并删除对产品描述的验证。创建文件(或更新文件)
/override/classes/Product.php
:<?php
class Product extends ProductCore
{
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
// Here we remove script validation on description_short field
unset(static::$definition['fields']['description_short']['validate']);
parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
}
}
如果创建此文件,则必须删除
/cache/class_index.php
,以便Prestashop将此替代考虑在内。经过测试和工作。
关于javascript - Prestashop 1.6.1.6无效的简短描述产品使用javascript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37923731/