1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207:
<?php
class icms_core_HTMLFilter extends icms_core_DataFilter {
public $purifier;
public function __construct() {
parent::__construct();
}
public static function getInstance() {
static $instance;
if (!isset($instance)) {
$instance = new self();
}
return $instance;
}
public static function filterHTML($html) {
$icmsConfigPurifier = icms::$config->getConfigsByCat(ICMS_CONF_PURIFIER);
$fcomment = '<!-- filtered with htmlpurifier -->';
$purified = strpos($html, $fcomment);
if ($purified !== FALSE) {
$html = str_replace($fcomment, '', $html);
}
if ($icmsConfigPurifier['enable_purifier'] !== 0) {
ICMS_PLUGINS_PATH;
require_once ICMS_LIBRARIES_PATH . '/htmlpurifier/HTMLPurifier.standalone.php';
require_once ICMS_LIBRARIES_PATH . '/htmlpurifier/HTMLPurifier.autoload.php';
if ($icmsConfigPurifier['purifier_Filter_ExtractStyleBlocks'] !== 0) {
require_once ICMS_PLUGINS_PATH . '/csstidy/class.csstidy.php';
}
$icmsPurifyConf = self::getHTMLFilterConfig();
$purifier = new HTMLPurifier($icmsPurifyConf);
$html = $purifier->purify($html);
$html .= $fcomment;
}
return $html;
}
private static function getCustomFilterList() {
$dirPath = ICMS_LIBRARIES_PATH . '/htmlpurifier/standalone/HTMLPurifier/Filter/';
$icmsConfigPurifier = icms::$config->getConfigsByCat(ICMS_CONF_PURIFIER);
if ($icmsConfigPurifier['purifier_Filter_AllowCustom'] !== 0) {
$filterList = array();
$fileList = icms_core_Filesystem::getFileList($dirPath, '', array('php'), true);
unset($fileList['ExtractStyleBlocks.php'], $fileList['YouTube.php']);
$fileList = array_values($fileList);
foreach ($fileList as &$val) {
$val = "HTMLPurifier_Filter_".substr($val, 0,strrpos($val,'.'));
$newObject = new $val;
$filterList[] = $newObject;
}
} else {
$filterList = '';
}
return $filterList;
}
protected static function getHTMLFilterConfig() {
$icmsConfigPurifier = icms::$config->getConfigsByCat(ICMS_CONF_PURIFIER);
$IframeRegExp = $icmsConfigPurifier['purifier_URI_SafeIframeRegexp'];
if ($IframeRegExp !== '') {
$pos = strpos( $IframeRegExp, '|' );
if ($pos === FALSE) {
$IframeRegExp = '%^' . $IframeRegExp . '%';
} else {
$IframeRegExp = '%^(' . $IframeRegExp . ')%';
}
}
$icmsPurifierConf = array(
'HTML.DefinitionID' => $icmsConfigPurifier['purifier_HTML_DefinitionID'],
'HTML.DefinitionRev' => $icmsConfigPurifier['purifier_HTML_DefinitionRev'],
'HTML.Doctype' => $icmsConfigPurifier['purifier_HTML_Doctype'],
'HTML.AllowedElements' => $icmsConfigPurifier['purifier_HTML_AllowedElements'],
'HTML.AllowedAttributes' => $icmsConfigPurifier['purifier_HTML_AllowedAttributes'],
'HTML.ForbiddenElements' => $icmsConfigPurifier['purifier_HTML_ForbiddenElements'],
'HTML.ForbiddenAttributes' => $icmsConfigPurifier['purifier_HTML_ForbiddenAttributes'],
'HTML.MaxImgLength' => $icmsConfigPurifier['purifier_HTML_MaxImgLength'],
'HTML.TidyLevel' => $icmsConfigPurifier['purifier_HTML_TidyLevel'],
'HTML.SafeEmbed' => $icmsConfigPurifier['purifier_HTML_SafeEmbed'],
'HTML.SafeObject' => $icmsConfigPurifier['purifier_HTML_SafeObject'],
'HTML.SafeIframe' => $icmsConfigPurifier['purifier_HTML_SafeIframe'],
'HTML.Attr.Name.UseCDATA' => $icmsConfigPurifier['purifier_HTML_AttrNameUseCDATA'],
'HTML.FlashAllowFullScreen' => $icmsConfigPurifier['purifier_HTML_FlashAllowFullScreen'],
'Output.FlashCompat' => $icmsConfigPurifier['purifier_Output_FlashCompat'],
'CSS.DefinitionRev' => $icmsConfigPurifier['purifier_CSS_DefinitionRev'],
'CSS.AllowImportant' => $icmsConfigPurifier['purifier_CSS_AllowImportant'],
'CSS.AllowTricky' => $icmsConfigPurifier['purifier_CSS_AllowTricky'],
'CSS.AllowedProperties' => $icmsConfigPurifier['purifier_CSS_AllowedProperties'],
'CSS.MaxImgLength' => $icmsConfigPurifier['purifier_CSS_MaxImgLength'],
'CSS.Proprietary' => $icmsConfigPurifier['purifier_CSS_Proprietary'],
'AutoFormat.AutoParagraph' => $icmsConfigPurifier['purifier_AutoFormat_AutoParagraph'],
'AutoFormat.DisplayLinkURI' => $icmsConfigPurifier['purifier_AutoFormat_DisplayLinkURI'],
'AutoFormat.Linkify' => $icmsConfigPurifier['purifier_AutoFormat_Linkify'],
'AutoFormat.PurifierLinkify' => $icmsConfigPurifier['purifier_AutoFormat_PurifierLinkify'],
'AutoFormat.Custom' => $icmsConfigPurifier['purifier_AutoFormat_Custom'],
'AutoFormat.RemoveEmpty' => $icmsConfigPurifier['purifier_AutoFormat_RemoveEmpty'],
'AutoFormat.RemoveEmpty.RemoveNbsp' => $icmsConfigPurifier['purifier_AutoFormat_RemoveEmptyNbsp'],
'AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions' => $icmsConfigPurifier['purifier_AutoFormat_RemoveEmptyNbspExceptions'],
'Core.EscapeNonASCIICharacters' => $icmsConfigPurifier['purifier_Core_EscapeNonASCIICharacters'],
'Core.HiddenElements' => $icmsConfigPurifier['purifier_Core_HiddenElements'],
'Core.NormalizeNewlines' => $icmsConfigPurifier['purifier_Core_NormalizeNewlines'],
'Core.RemoveInvalidImg' => $icmsConfigPurifier['purifier_Core_RemoveInvalidImg'],
'Core.Encoding' => _CHARSET,
'Cache.DefinitionImpl' => 'Serializer',
'Cache.SerializerPath' => ICMS_TRUST_PATH . '/cache/htmlpurifier',
'URI.Host' => $icmsConfigPurifier['purifier_URI_Host'],
'URI.Base' => $icmsConfigPurifier['purifier_URI_Base'],
'URI.Disable' => $icmsConfigPurifier['purifier_URI_Disable'],
'URI.DisableExternal' => $icmsConfigPurifier['purifier_URI_DisableExternal'],
'URI.DisableExternalResources' => $icmsConfigPurifier['purifier_URI_DisableExternalResources'],
'URI.DisableResources' => $icmsConfigPurifier['purifier_URI_DisableResources'],
'URI.MakeAbsolute' => $icmsConfigPurifier['purifier_URI_MakeAbsolute'],
'URI.HostBlacklist' => $icmsConfigPurifier['purifier_URI_HostBlacklist'],
'URI.AllowedSchemes' => $icmsConfigPurifier['purifier_URI_AllowedSchemes'],
'URI.DefinitionID' => $icmsConfigPurifier['purifier_URI_DefinitionID'],
'URI.DefinitionRev' => $icmsConfigPurifier['purifier_URI_DefinitionRev'],
'URI.SafeIframeRegexp' => $IframeRegExp,
'Attr.AllowedFrameTargets' => $icmsConfigPurifier['purifier_Attr_AllowedFrameTargets'],
'Attr.AllowedRel' => $icmsConfigPurifier['purifier_Attr_AllowedRel'],
'Attr.AllowedClasses' => $icmsConfigPurifier['purifier_Attr_AllowedClasses'],
'Attr.ForbiddenClasses' => $icmsConfigPurifier['purifier_Attr_ForbiddenClasses'],
'Attr.DefaultInvalidImage' => $icmsConfigPurifier['purifier_Attr_DefaultInvalidImage'],
'Attr.DefaultInvalidImageAlt' => $icmsConfigPurifier['purifier_Attr_DefaultInvalidImageAlt'],
'Attr.DefaultImageAlt' => $icmsConfigPurifier['purifier_Attr_DefaultImageAlt'],
'Attr.ClassUseCDATA' => $icmsConfigPurifier['purifier_Attr_ClassUseCDATA'],
'Attr.IDPrefix' => $icmsConfigPurifier['purifier_Attr_IDPrefix'],
'Attr.EnableID' => $icmsConfigPurifier['purifier_Attr_EnableID'],
'Attr.IDPrefixLocal' => $icmsConfigPurifier['purifier_Attr_IDPrefixLocal'],
'Attr.IDBlacklist' => $icmsConfigPurifier['purifier_Attr_IDBlacklist'],
'Filter.ExtractStyleBlocks.Escaping' => $icmsConfigPurifier['purifier_Filter_ExtractStyleBlocks_Escaping'],
'Filter.ExtractStyleBlocks.Scope' => $icmsConfigPurifier['purifier_Filter_ExtractStyleBlocks_Scope'],
'Filter.ExtractStyleBlocks' => $icmsConfigPurifier['purifier_Filter_ExtractStyleBlocks'],
'Filter.YouTube' => $icmsConfigPurifier['purifier_Filter_YouTube'],
'Filter.Custom' => self::getCustomFilterList(),
);
return parent::cleanArray($icmsPurifierConf);
}
}