purifier.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Ok, glad you are here
  4. * first we get a config instance, and set the settings
  5. * $config = HTMLPurifier_Config::createDefault();
  6. * $config->set('Core.Encoding', $this->config->get('purifier.encoding'));
  7. * $config->set('Cache.SerializerPath', $this->config->get('purifier.cachePath'));
  8. * if ( ! $this->config->get('purifier.finalize')) {
  9. * $config->autoFinalize = false;
  10. * }
  11. * $config->loadArray($this->getConfig());
  12. *
  13. * You must NOT delete the default settings
  14. * anything in settings should be compacted with params that needed to instance HTMLPurifier_Config.
  15. *
  16. * @link http://htmlpurifier.org/live/configdoc/plain.html
  17. *
  18. * XSS 实例 =>
  19. * $article->body = clean($article->body, 'markdown')
  20. */
  21. return [
  22. 'encoding' => 'UTF-8',
  23. 'finalize' => true,
  24. 'cachePath' => storage_path('app/purifier'),
  25. 'cacheFileMode' => 0755,
  26. 'settings' => [
  27. 'default' => [
  28. 'HTML.Doctype' => 'HTML 4.01 Transitional',
  29. 'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
  30. 'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
  31. 'AutoFormat.AutoParagraph' => true,
  32. 'AutoFormat.RemoveEmpty' => true,
  33. ],
  34. 'test' => [
  35. 'Attr.EnableID' => 'true',
  36. ],
  37. "youtube" => [
  38. "HTML.SafeIframe" => 'true',
  39. "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
  40. ],
  41. 'custom_definition' => [
  42. 'id' => 'html5-definitions',
  43. 'rev' => 1,
  44. 'debug' => false,
  45. 'elements' => [
  46. // http://developers.whatwg.org/sections.html
  47. ['section', 'Block', 'Flow', 'Common'],
  48. ['nav', 'Block', 'Flow', 'Common'],
  49. ['article', 'Block', 'Flow', 'Common'],
  50. ['aside', 'Block', 'Flow', 'Common'],
  51. ['header', 'Block', 'Flow', 'Common'],
  52. ['footer', 'Block', 'Flow', 'Common'],
  53. // Content model actually excludes several tags, not modelled here
  54. ['address', 'Block', 'Flow', 'Common'],
  55. ['hgroup', 'Block', 'Required: h1 | h2 | h3 | h4 | h5 | h6', 'Common'],
  56. // http://developers.whatwg.org/grouping-content.html
  57. ['figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common'],
  58. ['figcaption', 'Inline', 'Flow', 'Common'],
  59. // http://developers.whatwg.org/the-video-element.html#the-video-element
  60. ['video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
  61. 'src' => 'URI',
  62. 'type' => 'Text',
  63. 'width' => 'Length',
  64. 'height' => 'Length',
  65. 'poster' => 'URI',
  66. 'preload' => 'Enum#auto,metadata,none',
  67. 'controls' => 'Bool',
  68. ]],
  69. ['source', 'Block', 'Flow', 'Common', [
  70. 'src' => 'URI',
  71. 'type' => 'Text',
  72. ]],
  73. // http://developers.whatwg.org/text-level-semantics.html
  74. ['s', 'Inline', 'Inline', 'Common'],
  75. ['var', 'Inline', 'Inline', 'Common'],
  76. ['sub', 'Inline', 'Inline', 'Common'],
  77. ['sup', 'Inline', 'Inline', 'Common'],
  78. ['mark', 'Inline', 'Inline', 'Common'],
  79. ['wbr', 'Inline', 'Empty', 'Core'],
  80. // http://developers.whatwg.org/edits.html
  81. ['ins', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
  82. ['del', 'Block', 'Flow', 'Common', ['cite' => 'URI', 'datetime' => 'CDATA']],
  83. ],
  84. 'attributes' => [
  85. ['iframe', 'allowfullscreen', 'Bool'],
  86. ['table', 'height', 'Text'],
  87. ['td', 'border', 'Text'],
  88. ['th', 'border', 'Text'],
  89. ['tr', 'width', 'Text'],
  90. ['tr', 'height', 'Text'],
  91. ['tr', 'border', 'Text'],
  92. ],
  93. ],
  94. 'custom_attributes' => [
  95. ['a', 'target', 'Enum#_blank,_self,_target,_top'],
  96. ],
  97. 'custom_elements' => [
  98. ['u', 'Inline', 'Inline', 'Common'],
  99. ],
  100. 'markdown' => [
  101. 'HTML.Doctype' => 'XHTML 1.0 Transitional',
  102. 'HTML.Allowed' => 'div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,h2,h3,h4,h5,h6,blockquote,del,table,thead,tbody,tr,th,td',
  103. 'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,margin,width,height,font-family,text-decoration,padding-left,color,background-color,text-align',
  104. 'AutoFormat.AutoParagraph' => false,
  105. 'AutoFormat.RemoveEmpty' => false,
  106. ],
  107. 'markdownNoH1_6' => [
  108. 'HTML.Doctype' => 'XHTML 1.0 Transitional',
  109. 'HTML.Allowed' => 'div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,blockquote,del,table,thead,tbody,tr,th,td',
  110. 'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,margin,width,height,font-family,text-decoration,padding-left,color,background-color,text-align',
  111. 'AutoFormat.AutoParagraph' => false,
  112. 'AutoFormat.RemoveEmpty' => false,
  113. ],
  114. ],
  115. ];