Rev 195 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 195 | Rev 386 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OID-Info.com API for PHP |
4 | * OID-Info.com API for PHP |
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019-2020 Daniel Marschall, ViaThinkSoft |
6 | * Version 2019-11-06 |
6 | * Version 2020-09-12 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 311... | Line 311... | ||
311 | $desc = preg_replace('@<\s*br\s*>@ismU', '<br/>', $desc); // auto close <br> |
311 | $desc = preg_replace('@<\s*br\s*>@ismU', '<br/>', $desc); // auto close <br> |
312 | $desc = preg_replace('@(href\s*=\s*)(["\'])(.*)&([^#].*)(\2)@ismU', '\1\2\3&\4\5', $desc); // fix "&" inside href-URLs to & |
312 | $desc = preg_replace('@(href\s*=\s*)(["\'])(.*)&([^#].*)(\2)@ismU', '\1\2\3&\4\5', $desc); // fix "&" inside href-URLs to & |
313 | // TODO: what do we do if there are more XHTML errors (e.g. additional open tags) which would make the XML invalid? |
313 | // TODO: what do we do if there are more XHTML errors (e.g. additional open tags) which would make the XML invalid? |
314 | 314 | ||
315 | // "Trim" <br/> |
315 | // "Trim" <br/> |
- | 316 | $count = 0; |
|
316 | do { $desc = preg_replace('@^\s*<\s*br\s*/{0,1}\s*>@isU', '', $desc, -1, $count); } while ($count > 0); // left trim |
317 | do { $desc = preg_replace('@^\s*<\s*br\s*/{0,1}\s*>@isU', '', $desc, -1, $count); } while ($count > 0); // left trim |
317 | do { $desc = preg_replace('@<\s*br\s*/{0,1}\s*>\s*$@isU', '', $desc, -1, $count); } while ($count > 0); // right trim |
318 | do { $desc = preg_replace('@<\s*br\s*/{0,1}\s*>\s*$@isU', '', $desc, -1, $count); } while ($count > 0); // right trim |
318 | 319 | ||
319 | // Correct double-encoded stuff |
320 | // Correct double-encoded stuff |
320 | if (!isset($params['tolerant_htmlentities']) || $params['tolerant_htmlentities']) { |
321 | if (!isset($params['tolerant_htmlentities']) || $params['tolerant_htmlentities']) { |
Line 541... | Line 542... | ||
541 | $elements['description'] = $this->correctDesc($elements['description'], $params, self::OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT, true); |
542 | $elements['description'] = $this->correctDesc($elements['description'], $params, self::OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT, true); |
542 | $elements['information'] = $this->correctDesc($elements['information'], $params, self::OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT, true); |
543 | $elements['information'] = $this->correctDesc($elements['information'], $params, self::OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT, true); |
543 | 544 | ||
544 | // Request by O.D. 26 August 2019 |
545 | // Request by O.D. 26 August 2019 |
545 | $elements['description'] = trim($elements['description']); |
546 | $elements['description'] = trim($elements['description']); |
- | 547 | $m = array(); |
|
546 | if (preg_match('@^[a-z]@', $elements['description'], $m)) { |
548 | if (preg_match('@^[a-z]@', $elements['description'], $m)) { |
547 | $ending_dot_policy = self::OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT; // for description |
549 | $ending_dot_policy = self::OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT; // for description |
548 | if (($ending_dot_policy != self::OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT) && (strpos($elements['description'], ' ') === false)) { // <-- added by DM |
550 | if (($ending_dot_policy != self::OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT) && (strpos($elements['description'], ' ') === false)) { // <-- added by DM |
549 | $elements['description'] = '"' . $elements['description'] . '"'; |
551 | $elements['description'] = '"' . $elements['description'] . '"'; |
550 | } |
552 | } |
Line 921... | Line 923... | ||
921 | if (!$this->simplePingProviderAvailable()) { |
923 | if (!$this->simplePingProviderAvailable()) { |
922 | throw new OIDInfoException("No simple ping providers available."); |
924 | throw new OIDInfoException("No simple ping providers available."); |
923 | } |
925 | } |
924 | 926 | ||
925 | $one_null = false; |
927 | $one_null = false; |
926 | foreach ($this->simplePingProviders as $addr => $obj) { |
928 | foreach ($this->simplePingProviders as /*$addr =>*/ $obj) { |
927 | $res = $obj->queryOID($oid); |
929 | $res = $obj->queryOID($oid); |
928 | if ($res) return true; |
930 | if ($res) return true; |
929 | if ($res !== false) $one_null = true; |
931 | if ($res !== false) $one_null = true; |
930 | } |
932 | } |
931 | 933 | ||
Line 967... | Line 969... | ||
967 | if (!file_exists($this->csvfile)) { |
969 | if (!file_exists($this->csvfile)) { |
968 | throw new OIDInfoException("File '".$this->csvfile."' does not exist"); |
970 | throw new OIDInfoException("File '".$this->csvfile."' does not exist"); |
969 | } |
971 | } |
970 | $filemtime = filemtime($this->csvfile); |
972 | $filemtime = filemtime($this->csvfile); |
971 | if ($filemtime != $this->filemtime) { |
973 | if ($filemtime != $this->filemtime) { |
972 | $this->lines = file($csvfile); |
974 | $this->lines = file($this->csvfile); |
973 | $this->filemtime = $filemtime; |
975 | $this->filemtime = $filemtime; |
974 | } |
976 | } |
975 | } |
977 | } |
976 | 978 | ||
977 | function __construct($csvfile) { |
979 | function __construct($csvfile) { |