diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 69 |
1 files changed, 36 insertions, 33 deletions
@@ -123,21 +123,27 @@ static function timerlog($label = '') /** * If display_errors is on or stdout is a tty, shows error in page or on stdout respectively * If display_errors is off, mails (with rate limiting) diagnostics to .diffnotice addresses or file owner or SERVER_ADMIN - * @param $p either error title or assoc array of params, see below - * @param $p['title'] error title, one line. also accepted in $p[0] (with priority). false means ignore error - * @param $p['body'] error body: multiline string or any data type (will be dumped) - * @param $p['to'] comma separated recipient list - * @param $p['id'] id of error, used with timewindow, defaults to file and line of caller - * @param $p['graceperiod'] in seconds. deprecated, see $p['timewindow'] - * @param $p['timewindow'] in secs. "5-35" means for an notice to be sent, a second error must occur 5 to 35 seconds after first err - * @param $p['blockmailid'] block mail for $p['blockmail'] seconds with same id. Default: $p['to'] - * @param $p['blockmail'] number of seconds to block mails after having sent a mail [3600] - * @param $p['backtraceskip'] number of stack levels to drop - * @param $p['skipfiles'] files to skip in backtrace - * @param $p['okstate'] give current ok label and ok state, e.g. telresult=1 for working. see failcount - * @param $p['failcount'] give number of consecutive okstate failures needed for creating an error [2] - * @param $p['omitdebuginfo'] value 1 omits long stack and var dumps, value 2 also minimal infos - * @param $p['fatal'] exit after displaying error + * + * Controlling error mail content + * @param $p either error title or assoc array of params, see below + * @param $p['title'] error title, one line. also accepted in $p[0] (with priority). false means suppress error + * @param $p['body'] error body: multiline string or any data type (will be dumped) + * @param $p['backtraceskip'] number of stack levels to drop + * @param $p['skipfiles'] files to skip in backtrace + * @param $p['omitdebuginfo'] value 1 omits long stack and var dumps, value 2 also minimal infos + * + * Controlling the sending of mails + * @param $p['to'] comma separated recipient list + * @param $p['timewindow'] in secs. "5-35" means for an mail to be sent, another err must occur 5 to 35 seconds after first one + * @param $p['id'] id of error, used with timewindow, defaults to file and line of caller + * @param $p['blockmailid'] block mail for $p['blockmail'] seconds with same id. Default: $p['to'] + * @param $p['blockmail'] number of seconds to block mails after having sent a mail [3600] + * @param $p['okstate'] give current ok label and ok state, e.g. telresult=1 for working. see failcount + * @param $p['failcount'] give number of consecutive okstate failures needed for creating an error [2] + * @param $p['fatal'] exit after displaying error + * @param $p['graceperiod'] in seconds. DEPRECATED, see $p['timewindow'] + * Use debug param 'verboseerrors' to include $p['body'] when interactive + * * @return always null (so users can return it::error() in error cases) * * TIMEWINDOW 5-35 (x = error occurs, no mail; m = error occurs, mail sent) @@ -164,6 +170,7 @@ static function error($p = array(), $extra = null) $p['title'] = $p[0] ?: $p['title']; # handle 'it_error' => "oops" that was cast to array on the way $p['title'] = grapheme_substr($p['title'], 0, 2000) ?: substr($p['title'], 0, 2000); + # support for errlike() in tests $GLOBALS['ULTRAERROR'] = $p['title']; if ($GLOBALS['ULTRANOERRORS']) return null; @@ -391,20 +398,6 @@ static function servertype($pattern) /** - * Convert a string to ASCII-only chars, map/strip ISO-8859-1 accents - * @param $text Text to convert - * @return mapped/stripped version of $text contains only chars [0..127] - */ -static function toascii($text) -{ - return strtr(strtr($text, - utf8_decode( 'ÇéâàåçêëèïîìÅÉôòûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ'), - 'CeaaaceeeiiiAEoouuyooaiounNAAAaAEEEIIIOOoOUUUyY'), - array("\xe4" => 'ae', "\xf6" => 'oe', "\xfc" => 'ue', "\xc4" => 'Ae', "\xd6" => 'Oe', "\xdc" => 'Ue', "\xe6" => 'ae', "\xc6" => 'Ae', "\xdf" => 'ss')); -} - - -/** * Check whether an IP adress lies within a given range. Supports IPv4 and IPv6 * @param $ip IP address (192.168.42.123) * @param $cidrs IP range in CIDR notation (192.168.42.64/26) or array of ranges @@ -601,9 +594,9 @@ static function any2utf8($value, $errprefix = "") else if (is_string($value)) { if (grapheme_strlen($value) === null) - list($value, $error) = array(utf8_encode($value), utf8_encode("incorrect utf8-encoding. input=$value")); + list($value, $error) = array(it::utf8_encode($value), it::utf8_encode("incorrect utf8-encoding. input=$value")); if (preg_match('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', $value)) - list($value, $error) = array(it::any2utf8(preg_replace_callback('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', function($m) {return utf8_decode($m[0]);}, $value)), $errprefix ? "double utf8-encoding. input=$value" : ""); + list($value, $error) = array(it::any2utf8(preg_replace_callback('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', function($m) {return it::utf8_decode($m[0]);}, $value)), $errprefix ? "double utf8-encoding. input=$value" : ""); if (preg_match('/\xef\xb7[\x90-\xaf]|\xef\xbf[\xbe\xbf]/', $value)) list($value, $error) = array(preg_replace('/\xef\xb7[\x90-\xaf]|\xef\xbf[\xbe\xbf]/', " ", $value), "forbidden utf-8 character. input=$value"); $value = preg_replace('/\xc2\xad/', '', $value); # Kill invisible soft hyphens @@ -909,7 +902,7 @@ static function getopt($usage, $p = array()) foreach(explode("\n", trim($usage)) as $usageline) { $shortoptname = $shortoptarg = $longoptname = $longoptarg = ""; - foreach (explode(',', $usageline) as $optdesc) + foreach (explode(',', $usageline, 2) as $optdesc) { $optdesc = trim($optdesc); if ($matches = (array)it::match('^--(\w[\w-]*)(=[A-Z])?', $optdesc)) @@ -1058,7 +1051,7 @@ static function date($format = "", $stamp = null) if (!isset($stamp)) $stamp = it::time(); else if (is_string($stamp) && !ctype_digit($stamp)) - $stamp = strtotime($stamp, it::time()); + $stamp = strtotime(it::replace(['\s(--|\+\+)\s*(\d)' => ' +\2', '\s(\+-|-\+)\s*(\d)' => ' -\2'], $stamp), it::time()); list($name, $language) = explode(":", $format); @@ -1383,4 +1376,14 @@ static function request_body() return it::any2utf8(it::file_get_contents('php://input')); } +static function utf8_decode($utf8) +{ + return UConverter::transcode($utf8, 'ISO-8859-1', 'UTF8', ['to_subst' => '?']); +} + +static function utf8_encode($latin1) +{ + return UConverter::transcode($latin1, 'UTF8', 'ISO-8859-1'); +} + } |