/** * Before action */ public function before() { parent::before(); // Получаем статус ошибки $status = (int) $this->request->action(); // Если вызов из строки браузера (http://example.com/error/500) if (Request::$initial === Request::$current) { $status = 404; $this->response->status($status); $this->request->action($status); } else { // Если кода ошибки нет в списке обрабатываемых if (!in_array($status, [403, 404, 500, 503])) { $status = 404; $this->response->status($status); $this->request->action($status); } else { $this->response->status($status); $message = $this->request->param('message'); // Если стандартное сообщение 404 if (UTF8::strpos($message, 'Unable to find a route to match the URI') !== false) { // Не будем выводить message //$message = ''; } } } $this->content = View::factory('errors/' . $status)->bind('message', $message); }
/** * UTF8::strpos * * @package JsonApiApplication * @author JsonApiApplication Team * @copyright (c) 2007-2012 JsonApiApplication Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _strpos($str, $search, $offset = 0) { $offset = (int) $offset; if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) { return strpos($str, $search, $offset); } if ($offset == 0) { $array = explode($search, $str, 2); return isset($array[1]) ? UTF8::strlen($array[0]) : FALSE; } $str = UTF8::substr($str, $offset); $pos = UTF8::strpos($str, $search); return $pos === FALSE ? FALSE : $pos + $offset; }
/** * Tests UTF8::strpos * * @test * @dataProvider provider_strpos */ public function test_strpos($input, $str, $offset, $expected) { $this->assertSame($expected, UTF8::strpos($input, $str, $offset)); UTF8::$server_utf8 = !UTF8::$server_utf8; $this->assertSame($expected, UTF8::strpos($input, $str, $offset)); UTF8::$server_utf8 = !UTF8::$server_utf8; }
/** * Finds position of first occurrence of a UTF-8 string. This is a * UTF8-aware version of [strpos](http://php.net/strpos). * * $position = UTF8::strpos($str, $search); * * @author Harry Fuecks <*****@*****.**> * @param string haystack * @param string needle * @param integer offset from which character in haystack to start searching * @return integer position of needle * @return boolean FALSE if the needle is not found * @uses IS_MBSTRING */ public static function strpos($str, $search, $offset = 0) { $offset = (int) $offset; if (IS_MBSTRING) { return mb_strpos($str, $search, $offset, Core::$charset); } if (UTF8::is_ascii($str) && UTF8::is_ascii($search)) { return strpos($str, $search, $offset); } if ($offset == 0) { $array = explode($search, $str, 2); return isset($array[1]) ? UTF8::strlen($array[0]) : FALSE; } $str = UTF8::substr($str, $offset); $pos = UTF8::strpos($str, $search); return $pos === FALSE ? FALSE : $pos + $offset; }
private function goodbrowser() { $browser = 'good'; if (UTF8::strpos($_SERVER['HTTP_USER_AGENT'], 'Opera')) { $browser = 'bad'; } if (UTF8::strpos($_SERVER['HTTP_USER_AGENT'], 'OPR')) { $browser = 'bad'; } if (UTF8::strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { $browser = 'bad'; } if ($browser == 'good') { return TRUE; } return FALSE; }
/** * Tests UTF8::strpos * * @test * @dataProvider provider_strpos */ public function test_strpos($input, $str, $offset, $expected) { $this->assertSame($expected, UTF8::strpos($input, $str, $offset)); }
<div id="ptb_err"> <div class="head"> <div class="type"><?php echo $class; ?> <span class="typeCode">[ <?php echo $code; ?> ]</span></div> <div class="message"> <?php if ($class == 'Database_Exception') { ?> <?php $start = UTF8::strpos($message, '[ '); $end = UTF8::strpos($message, ' ]'); $sql = UTF8::substr($message, $start + 2, $end - $start - 2); $message = UTF8::substr($message, 0, $start); ?> <?php echo $message; ?> <?php if ($highlightSQL) { ?> <pre class="source sql"><?php echo ProfilerToolbar::highlight($sql, 'sql'); ?> </pre> <?php } else {
/** * UTF8::stripos * * @copyright (c) 2015 Ivan Tcholakov * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _stripos($str, $search, $offset = 0) { return UTF8::strpos(UTF8::strtolower($str), UTF8::strtolower($search), $offset); }