extractStyleBlocks.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. require_once 'common.php';
  3. require_once 'HTMLPurifier/Filter/ExtractStyleBlocks.php';
  4. $purifier = new HTMLPurifier(array(
  5. 'Filter.ExtractStyleBlocks' => true,
  6. ));
  7. $html = isset($_POST['html']) ? $_POST['html'] : '';
  8. $purified_html = $purifier->purify($html);
  9. ?><!DOCTYPE html
  10. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  11. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  12. <html>
  13. <head>
  14. <title>Extract Style Blocks - HTML Purifier Smoketest</title>
  15. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  16. <?php
  17. // generate style blocks
  18. foreach ($purifier->context->get('StyleBlocks') as $style) {
  19. ?><style type="text/css">
  20. <!--/*--><![CDATA[/*><!--*/
  21. <?php echo $style; ?>
  22. /*]]>*/-->
  23. </style>
  24. <?php
  25. }
  26. ?>
  27. </head>
  28. <body>
  29. <h1>Extract Style Blocks</h1>
  30. <p>
  31. This smoketest allows users to specify global style sheets for the
  32. document, allowing for interesting techniques and compact markup
  33. that wouldn't normally be possible, using the ExtractStyleBlocks filter.
  34. </p>
  35. <p>
  36. User submitted content:
  37. </p>
  38. <div style="border: 1px solid #CCC; margin: 1em; padding: 1em;">
  39. <?php echo $purified_html ?>
  40. </div>
  41. <form action="" method="post">
  42. <textarea cols="100" rows="20" name="html"><?php echo escapeHTML($html) ?></textarea>
  43. <input type="submit" value="Submit" />
  44. </form>
  45. </body>
  46. </html>
  47. <?php
  48. // vim: et sw=4 sts=4