PageRenderTime 48ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/vjCommentPlugin/lib/tools/htmlpurifier/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php

https://bitbucket.org/Kudlaty/360kdw
PHP | 53 lines | 32 code | 12 blank | 9 comment | 4 complexity | ed11d4126e34e45fd127650a45f0ee56 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Validates a rel/rev link attribute against a directive of allowed values
  4. * @note We cannot use Enum because link types allow multiple
  5. * values.
  6. * @note Assumes link types are ASCII text
  7. */
  8. class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
  9. {
  10. /** Name config attribute to pull. */
  11. protected $name;
  12. public function __construct($name) {
  13. $configLookup = array(
  14. 'rel' => 'AllowedRel',
  15. 'rev' => 'AllowedRev'
  16. );
  17. if (!isset($configLookup[$name])) {
  18. trigger_error('Unrecognized attribute name for link '.
  19. 'relationship.', E_USER_ERROR);
  20. return;
  21. }
  22. $this->name = $configLookup[$name];
  23. }
  24. public function validate($string, $config, $context) {
  25. $allowed = $config->get('Attr.' . $this->name);
  26. if (empty($allowed)) return false;
  27. $string = $this->parseCDATA($string);
  28. $parts = explode(' ', $string);
  29. // lookup to prevent duplicates
  30. $ret_lookup = array();
  31. foreach ($parts as $part) {
  32. $part = strtolower(trim($part));
  33. if (!isset($allowed[$part])) continue;
  34. $ret_lookup[$part] = true;
  35. }
  36. if (empty($ret_lookup)) return false;
  37. $string = implode(' ', array_keys($ret_lookup));
  38. return $string;
  39. }
  40. }
  41. // vim: et sw=4 sts=4