xml.php 898 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /*
  3. * HTML is the 'root' scanner, we just override a couple of config settings
  4. * here, to prevent it from looking for CSS or JS.
  5. */
  6. class LuminousXMLScanner extends LuminousHTMLScanner {
  7. public $scripts = false;
  8. public $embedded_server = false;
  9. public static function guess_language($src, $info) {
  10. if (strpos(ltrim($src), '<?xml') === 0) return 1.0;
  11. // don't catch HTML doctypes
  12. if (strpos($src, '<!DOCTYPE') !== false) return 0;
  13. $p = 0;
  14. // simple tag
  15. $lines = preg_match_all('/$/m',
  16. preg_replace('/^\s+/m', '', $src), $m);
  17. // avg 1 tag every 4 lines
  18. if (preg_match_all('%<[!?/]?[a-zA-Z_:\\-]%', $src, $m)
  19. > $lines/4) $p += 0.15;
  20. // self closing tag
  21. if (strpos($src, '/>') !== false) $p += 0.05;
  22. // tag with attr
  23. if (preg_match('/<[a-zA-Z_]\w*\s+[a-zA-Z_]\w+\s*=["\']/', $src))
  24. $p += 0.1;
  25. return $p;
  26. }
  27. }