aboutsummaryrefslogtreecommitdiffstats
path: root/library/HTMLPurifier/Length.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2015-01-01 22:18:27 -0800
committerfriendica <info@friendica.com>2015-01-01 22:18:27 -0800
commita0052f0176bd079e6a94baec59fea2ec5a8d651e (patch)
treec323edd823681bc2e8ca757e7eaf8354d42c7b51 /library/HTMLPurifier/Length.php
parent545e47933a0816699c68d98a7742a03260d6a54f (diff)
downloadvolse-hubzilla-a0052f0176bd079e6a94baec59fea2ec5a8d651e.tar.gz
volse-hubzilla-a0052f0176bd079e6a94baec59fea2ec5a8d651e.tar.bz2
volse-hubzilla-a0052f0176bd079e6a94baec59fea2ec5a8d651e.zip
htmlpurifier update - compatibility issue with language library autoloader
Diffstat (limited to 'library/HTMLPurifier/Length.php')
-rw-r--r--library/HTMLPurifier/Length.php91
1 files changed, 68 insertions, 23 deletions
diff --git a/library/HTMLPurifier/Length.php b/library/HTMLPurifier/Length.php
index 8d2a46b7d..bbfbe6624 100644
--- a/library/HTMLPurifier/Length.php
+++ b/library/HTMLPurifier/Length.php
@@ -9,21 +9,25 @@ class HTMLPurifier_Length
/**
* String numeric magnitude.
+ * @type string
*/
protected $n;
/**
* String unit. False is permitted if $n = 0.
+ * @type string|bool
*/
protected $unit;
/**
* Whether or not this length is valid. Null if not calculated yet.
+ * @type bool
*/
protected $isValid;
/**
- * Lookup array of units recognized by CSS 2.1
+ * Array Lookup array of units recognized by CSS 2.1
+ * @type array
*/
protected static $allowedUnits = array(
'em' => true, 'ex' => true, 'px' => true, 'in' => true,
@@ -31,85 +35,126 @@ class HTMLPurifier_Length
);
/**
- * @param number $n Magnitude
- * @param string $u Unit
+ * @param string $n Magnitude
+ * @param bool|string $u Unit
*/
- public function __construct($n = '0', $u = false) {
+ public function __construct($n = '0', $u = false)
+ {
$this->n = (string) $n;
$this->unit = $u !== false ? (string) $u : false;
}
/**
* @param string $s Unit string, like '2em' or '3.4in'
+ * @return HTMLPurifier_Length
* @warning Does not perform validation.
*/
- static public function make($s) {
- if ($s instanceof HTMLPurifier_Length) return $s;
+ public static function make($s)
+ {
+ if ($s instanceof HTMLPurifier_Length) {
+ return $s;
+ }
$n_length = strspn($s, '1234567890.+-');
$n = substr($s, 0, $n_length);
$unit = substr($s, $n_length);
- if ($unit === '') $unit = false;
+ if ($unit === '') {
+ $unit = false;
+ }
return new HTMLPurifier_Length($n, $unit);
}
/**
* Validates the number and unit.
+ * @return bool
*/
- protected function validate() {
+ protected function validate()
+ {
// Special case:
- if ($this->n === '+0' || $this->n === '-0') $this->n = '0';
- if ($this->n === '0' && $this->unit === false) return true;
- if (!ctype_lower($this->unit)) $this->unit = strtolower($this->unit);
- if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) return false;
+ if ($this->n === '+0' || $this->n === '-0') {
+ $this->n = '0';
+ }
+ if ($this->n === '0' && $this->unit === false) {
+ return true;
+ }
+ if (!ctype_lower($this->unit)) {
+ $this->unit = strtolower($this->unit);
+ }
+ if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) {
+ return false;
+ }
// Hack:
$def = new HTMLPurifier_AttrDef_CSS_Number();
$result = $def->validate($this->n, false, false);
- if ($result === false) return false;
+ if ($result === false) {
+ return false;
+ }
$this->n = $result;
return true;
}
/**
* Returns string representation of number.
+ * @return string
*/
- public function toString() {
- if (!$this->isValid()) return false;
+ public function toString()
+ {
+ if (!$this->isValid()) {
+ return false;
+ }
return $this->n . $this->unit;
}
/**
* Retrieves string numeric magnitude.
+ * @return string
*/
- public function getN() {return $this->n;}
+ public function getN()
+ {
+ return $this->n;
+ }
/**
* Retrieves string unit.
+ * @return string
*/
- public function getUnit() {return $this->unit;}
+ public function getUnit()
+ {
+ return $this->unit;
+ }
/**
* Returns true if this length unit is valid.
+ * @return bool
*/
- public function isValid() {
- if ($this->isValid === null) $this->isValid = $this->validate();
+ public function isValid()
+ {
+ if ($this->isValid === null) {
+ $this->isValid = $this->validate();
+ }
return $this->isValid;
}
/**
* Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal.
+ * @param HTMLPurifier_Length $l
+ * @return int
* @warning If both values are too large or small, this calculation will
* not work properly
*/
- public function compareTo($l) {
- if ($l === false) return false;
+ public function compareTo($l)
+ {
+ if ($l === false) {
+ return false;
+ }
if ($l->unit !== $this->unit) {
$converter = new HTMLPurifier_UnitConverter();
$l = $converter->convert($l, $this->unit);
- if ($l === false) return false;
+ if ($l === false) {
+ return false;
+ }
}
return $this->n - $l->n;
}
-
}
// vim: et sw=4 sts=4