HTMLPurifier/AttrDef/HTML/Pixels.php Quellcode

Pixels.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
7 {
8 
12  protected $max;
13 
17  public function __construct($max = null)
18  {
19  $this->max = $max;
20  }
21 
28  public function validate($string, $config, $context)
29  {
30  $string = trim($string);
31  if ($string === '0') {
32  return $string;
33  }
34  if ($string === '') {
35  return false;
36  }
37  $length = strlen($string);
38  if (substr($string, $length - 2) == 'px') {
39  $string = substr($string, 0, $length - 2);
40  }
41  if (!is_numeric($string)) {
42  return false;
43  }
44  $int = (int)$string;
45 
46  if ($int < 0) {
47  return '0';
48  }
49 
50  // upper-bound value, extremely high values can
51  // crash operating systems, see <http://ha.ckers.org/imagecrash.html>
52  // WARNING, above link WILL crash you if you're using Windows
53 
54  if ($this->max !== null && $int > $this->max) {
55  return (string)$this->max;
56  }
57  return (string)$int;
58  }
59 
64  public function make($string)
65  {
66  if ($string === '') {
67  $max = null;
68  } else {
69  $max = (int)$string;
70  }
71  $class = get_class($this);
72  return new $class($max);
73  }
74 }
75 
76 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.