/** * * Binary version of strpos * @param $haystack * @param $needle * @param int $offset * @return bool|int */ public static function getBinaryStrpos($haystack, $needle, $offset = 0) { if (defined("BX_UTF")) { if (function_exists("mb_orig_strpos")) { return mb_orig_strpos($haystack, $needle, $offset); } return mb_strpos($haystack, $needle, $offset, "latin1"); } return strpos($haystack, $needle, $offset); }
/** * Find class * @param string $class Class * @param string $namespace Namespace * @param string $rootns Root namespace * @return string */ public static function find($class, $namespace = null, $rootns = null) { $e = explode('\\', $class); if ($e[0] === '') { return $class; } if ('Pool' === $class || 'TransportContext' === $class) { return '\\PHPDaemon\\Core\\' . $class; } if (mb_orig_strpos($class, '\\') === false && $namespace === null) { if ('Example' === substr($class, 0, 7)) { array_unshift($e, 'Examples'); } if ('Server' === substr($class, -6)) { $path = '\\PHPDaemon\\Servers\\' . substr($class, 0, -6) . '\\Pool'; $r = str_replace('\\Servers\\Servers', '\\Servers', $path); Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.'); return $r; } if ('Client' === substr($class, -6)) { $path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -6) . '\\Pool'; $r = str_replace('\\Clients\\Clients', '\\Clients', $path); Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.'); return $r; } if ('ClientAsync' === substr($class, -11)) { $path = '\\PHPDaemon\\Clients\\' . substr($class, 0, -11) . '\\Pool'; $r = str_replace('\\Client\\Clients', '\\Clients', $path); Daemon::log('ClassFinder: \'' . $class . '\' -> \'' . $r . '\', you should change your code.'); return $r; } } if ($namespace !== null && sizeof($e) < 2) { array_unshift($e, $namespace); } array_unshift($e, '\\' . ($rootns !== null ? $rootns : Daemon::$config->defaultns->value)); return implode('\\', $e); }
/** * @param $p */ protected function onPacket($p) { if ($p['op'] === 'spawnInstance') { $fullname = $p['appfullname']; $fullname = str_replace('-', ':', $fullname); if (mb_orig_strpos($fullname, ':') === false) { $fullname .= ':'; } list($app, $name) = explode(':', $fullname, 2); Daemon::$appResolver->getInstance($app, $name, true, true); } elseif ($p['op'] === 'importFile') { if (!Daemon::$config->autoreimport->value) { Daemon::$process->gracefulRestart(); return; } $path = $p['path']; Timer::add(function ($event) use($path) { if (Daemon::supported(Daemon::SUPPORT_RUNKIT_IMPORT)) { //Daemon::log('--start runkit_import('.$path.')'); runkit_import($path, RUNKIT_IMPORT_FUNCTIONS | RUNKIT_IMPORT_CLASSES | RUNKIT_IMPORT_OVERRIDE); //Daemon::log('--end runkit_import('.$path.')'); } else { $this->appInstance->log('Cannot import \'' . $path . '\': runkit_import is not callable.'); } $event->finish(); }, 5); } elseif ($p['op'] === 'call') { if (mb_orig_strpos($p['appfullname'], ':') === false) { $p['appfullname'] .= ':'; } list($app, $name) = explode(':', $p['appfullname'], 2); if ($app = Daemon::$appResolver->getInstance($app, $name)) { $app->RPCall($p['method'], $p['args']); } } }
public function saslScrumSHA1Step($session, $input = null) { $session['step']++; $query = []; if (!is_null($input) && (!empty($input['$err']) || !empty($input['errmsg']))) { $session['cb']($input); return; } if ($session['step'] == 1) { $session['nonce'] = base64_encode(openssl_random_pseudo_bytes(24)); $payload = 'n,,n=' . $session['user'] . ',r=' . $session['nonce']; $query = ['saslStart' => 1, 'mechanism' => 'SCRAM-SHA-1', 'payload' => base64_encode($payload)]; $session['auth_message'] .= 'n=' . $session['user'] . ',r=' . $session['nonce'] . ','; } elseif ($session['step'] == 2) { $in_payload = $this->saslScrumSHA1ExtractPayload($input['payload']); $error = null; if (count($in_payload) != 3) { $error = 'Incorrect number of arguments for first SCRAM-SHA-1 server message, got ' . count($in_payload) . 'expected 3'; } elseif (mb_orig_strlen($in_payload['r']) < 2) { $error = 'Incorrect SCRAM-SHA-1 client|server nonce: ' . $in_payload['r']; } elseif (mb_orig_strlen($in_payload['s']) < 6) { $error = 'Incorrect SCRAM-SHA-1 salt: ' . $in_payload['s']; } elseif (mb_orig_strlen($in_payload['i']) < 3) { $error = 'Incorrect SCRAM-SHA-1 iteration count: ' . $in_payload['i']; } elseif (mb_orig_strpos($in_payload['r'], $session['nonce']) !== 0) { $error = 'Server SCRAM-SHA-1 nonce does not match client nonce'; } if (!empty($error)) { $session['cb'](['ok' => 0, 'errmsg' => $error]); return; } else { $session['conversation_id'] = $input['conversationId']; $session['nonce'] = $in_payload['r']; } $payload = 'c=biws,r=' . $session['nonce']; $session['auth_message'] .= base64_decode($input['payload']) . ',' . $payload; $decoded_salt = base64_decode($in_payload['s']); $password = md5($session['user'] . ':mongo:' . $session['password']); $salted_password = hash_pbkdf2('sha1', $password, $decoded_salt, (int) $in_payload['i'], 0, true); $client_key = hash_hmac('sha1', 'Client Key', $salted_password, true); $stored_key = sha1($client_key, true); $client_sign = hash_hmac('sha1', $session['auth_message'], $stored_key, true); $client_proof = $client_key ^ $client_sign; $payload .= ',p=' . base64_encode($client_proof); $query = ['saslContinue' => 1, 'conversationId' => $session['conversation_id'], 'payload' => base64_encode($payload)]; } elseif ($session['step'] == 3) { $in_payload = $this->saslScrumSHA1ExtractPayload($input['payload']); if (!empty($in_payload['v'])) { $session['server_signature'] = $in_payload['v']; $query = ['saslContinue' => 1, 'conversationId' => $session['conversation_id'], 'payload' => base64_encode('')]; } } elseif ($session['step'] == 4) { $in_payload = $this->saslScrumSHA1ExtractPayload($input['payload']); $res = $input['done'] ? ['ok' => 1, 'server_signature' => $session['server_signature']] : ['ok' => 0, 'errmsg' => 'Authentication failed.']; $session['cb']($res); return; } $this->saslScrumSHA1Conversation($session['dbname'], $query, function ($res) use($session) { $this->saslScrumSHA1Step($session, $res); }, $session['conn']); }
private function _getFilteredDirs($dirs) { $curdir = getcwd(); foreach ($dirs as $idx => $dir) { if ($dir === $curdir) { $dir = "."; } if (mb_orig_strpos($dir, "{$curdir}/") === 0) { $dir = mb_orig_substr($dir, mb_orig_strlen($curdir) + 1); } $parts = explode("/", $dir); foreach ($parts as $p) { if ($p === ".") { continue; } if (isset($this->exclude[$p])) { unset($dirs[$idx]); continue 2; } } /* check if dir is still present, because event could be delivered when dir does not exist anymore */ $stat = $this->_stat($dir); if ($stat !== 'dir') { unset($dirs[$idx]); continue; } $dirs[$idx] = $dir; } return $dirs; }
/** * Tells whether the file was uploaded via HTTP POST * @param string $path The filename being checked * @return boolean Whether if this is uploaded file */ public function isUploadedFile($path) { if (!$path) { return false; } if (mb_orig_strpos($path, $this->getUploadTempDir() . '/') !== 0) { return false; } foreach ($this->attrs->files as $file) { if ($file['tmp_name'] === $path) { return true; } } return false; }
public function _get_xml_chunk_mb_orig($fp) { if ($this->buf_position >= $this->buf_len) { if (!feof($fp)) { $this->buf = fread($fp, $this->read_size); $this->buf_position = 0; $this->buf_len = mb_orig_strlen($this->buf); } else { return false; } } //Skip line delimiters (ltrim) $xml_position = mb_orig_strpos($this->buf, "<", $this->buf_position); while ($xml_position === $this->buf_position) { $this->buf_position++; $this->file_position++; //Buffer ended with white space so we can refill it if ($this->buf_position >= $this->buf_len) { if (!feof($fp)) { $this->buf = fread($fp, $this->read_size); $this->buf_position = 0; $this->buf_len = mb_orig_strlen($this->buf); } else { return false; } } $xml_position = mb_orig_strpos($this->buf, "<", $this->buf_position); } //Let's find next line delimiter while ($xml_position === false) { $next_search = $this->buf_len; //Delimiter not in buffer so try to add more data to it if (!feof($fp)) { $this->buf .= fread($fp, $this->read_size); $this->buf_len = mb_orig_strlen($this->buf); } else { break; } //Let's find xml tag start $xml_position = mb_orig_strpos($this->buf, "<", $next_search); } if ($xml_position === false) { $xml_position = $this->buf_len + 1; } $len = $xml_position - $this->buf_position; $this->file_position += $len; $result = mb_orig_substr($this->buf, $this->buf_position, $len); $this->buf_position = $xml_position; return $result; }
/** * Loads default setting. * @return void */ public static function initSettings() { Daemon::$version = file_get_contents('VERSION', true); Daemon::$config = new Config\Object(); if (!defined('SO_REUSEPORT') && mb_orig_strpos(php_uname('s'), 'BSD') !== false) { // @TODO: better if-BSD check define('SO_REUSEPORT', 0x200); } }
/** * Routes incoming request to related application * @param object $req Generic * @param object $upstream AppInstance of Upstream * @param string $responder * @return object Request */ public function getRequest($req, $upstream, $responder = null) { if (isset($req->attrs->server['APPNAME'])) { $appName = $req->attrs->server['APPNAME']; } elseif ($responder !== null) { $appName = $responder; } elseif (($appName = $this->getRequestRoute($req, $upstream)) !== null) { if ($appName === false) { return $req; } } else { return $req; } if (mb_orig_strpos($appName, ':') === false) { $appName .= ':'; } list($app, $instance) = explode(':', $appName, 2); $appInstance = $this->getInstanceByAppName($app, $instance); if (!$appInstance) { return $req; } return $appInstance->handleRequest($req, $upstream); }
/** * session_decode() - clone, which not require session_start() * @see http://www.php.net/manual/en/function.session-decode.php#108037 * @param string $session_data * @return array */ protected function unserializePHP($session_data) { $return_data = array(); $offset = 0; while ($offset < mb_orig_strlen($session_data)) { if (!strstr(substr($session_data, $offset), "|")) { return $return_data; //throw new \Exception("invalid session data, remaining: " . substr($session_data, $offset)); } $pos = mb_orig_strpos($session_data, "|", $offset); $num = $pos - $offset; $varname = substr($session_data, $offset, $num); $offset += $num + 1; $data = unserialize(substr($session_data, $offset)); $return_data[$varname] = $data; $offset += mb_orig_strlen(serialize($data)); } return $return_data; }
protected static function fastStrpos($haystack, $needle) { if (function_exists("mb_orig_strpos")) { return mb_orig_strpos($haystack, $needle); } return strpos($haystack, $needle); }
/** * Checks if property exists * @param string Property name * @return boolean Exists? */ public static function parseCfgUri($uri, $source = null) { if (mb_orig_strpos($uri, '://') === false) { if (strncmp($uri, 'unix:', 5) === 0) { $e = explode(':', $uri); if (sizeof($e) === 4) { $uri = 'unix://' . $e[1] . ':' . $e[2] . '@localhost' . $e[3]; } elseif (sizeof($e) === 3) { $uri = 'unix://' . $e[1] . '@localhost' . $e[2]; } else { $uri = 'unix://localhost' . $e[1]; } } else { $uri = 'tcp://' . $uri; } } if (stripos($uri, 'unix:///') === 0) { $uri = 'unix://localhost/' . substr($uri, 8); } $zeroPortNum = false; $uri = preg_replace_callback('~:0(?:$|/)~', function () use(&$zeroPortNum) { $zeroPortNum = true; return ''; }, $uri); $u = parse_url($uri); $u['host'] = trim($u['host'], ']['); $u['uri'] = $uri; if ($zeroPortNum) { $u['port'] = 0; } if (!isset($u['scheme'])) { $u['scheme'] = ''; } $u['params'] = []; if (!isset($u['fragment'])) { return $u; } $hash = '#' . $u['fragment']; $error = false; preg_replace_callback('~(#+)(.+?)(?=#|$)|(.+)~', function ($m) use(&$u, &$error, $uri) { if ($error) { return; } list(, $type, $value) = $m; if ($type === '#') { // standard value $e = explode('=', $value, 2); if (sizeof($e) === 2) { list($key, $value) = $e; } else { $key = $value; $value = true; } $u['params'][$key] = $value; } elseif ($type === '##') { // Context name $u['params']['ctxname'] = $value; } else { Daemon::log('Malformed URI: ' . var_export($uri, true) . ', unexpected token \'' . $type . '\''); $error = true; } }, $hash); return $error ? false : $u; }
/** * @TODO DESCR * @param string $nick * @param string $mode */ public function addMode($nick, $mode) { if (!isset($this->nicknames[$nick])) { return; } $participant = $this->nicknames[$nick]; if (mb_orig_strpos($participant->mode, $mode) === false) { $participant->mode .= $mode; } $participant->onModeUpdate(); }
function strpos($a, $b) { return function_exists('mb_orig_strpos') ? mb_orig_strpos($a, $b) : strpos($a, $b); }
protected function _getChunk_mb_orig() { if ($this->_bufferPosition >= $this->_bufferLength) { if (!feof($this->_file)) { $this->_buffer = fread($this->_file, $this->_chunkReadSize); $this->_bufferPosition = 0; $this->_bufferLength = mb_orig_strlen($this->_buffer); } else { return false; } } //Skip line delimiters (ltrim) $position = mb_orig_strpos($this->_buffer, "<", $this->_bufferPosition); while ($position === $this->_bufferPosition) { $this->_bufferPosition++; $this->_filePosition++; //Buffer ended with white space so we can refill it if ($this->_bufferPosition >= $this->_bufferLength) { if (!feof($this->_file)) { $this->_buffer = fread($this->_file, $this->_chunkReadSize); $this->_bufferPosition = 0; $this->_bufferLength = mb_orig_strlen($this->_buffer); } else { return false; } } $position = mb_orig_strpos($this->_buffer, "<", $this->_bufferPosition); } //Let's find next line delimiter while ($position === false) { $next_search = $this->_bufferLength; //Delimiter not in buffer so try to add more data to it if (!feof($this->_file)) { $this->_buffer .= fread($this->_file, $this->_chunkReadSize); $this->_bufferLength = mb_orig_strlen($this->_buffer); } else { break; } //Let's find xml tag start $position = mb_orig_strpos($this->_buffer, "<", $next_search); } if ($position === false) { $position = $this->_bufferLength + 1; } $len = $position - $this->_bufferPosition; $this->_filePosition += $len; $result = mb_orig_substr($this->_buffer, $this->_bufferPosition, $len); $this->_bufferPosition = $position; return $result; }
public static function strpos($s, $a) { if (function_exists('mb_orig_strpos')) return mb_orig_strpos($s, $a); return strpos($s, $a); }
/** * Converts string of flags to integer or standard text representation * @param string $mode Mode * @param boolean $text Text? * @return mixed */ public static function convertFlags($mode, $text = false) { $plus = mb_orig_strpos($mode, '+') !== false; $sync = mb_orig_strpos($mode, 's') !== false; $type = strtr($mode, ['b' => '', '+' => '', 's' => '', '!' => '']); if ($text) { return $type; } $types = ['r' => $plus ? EIO_O_RDWR : EIO_O_RDONLY, 'w' => ($plus ? EIO_O_RDWR : EIO_O_WRONLY) | EIO_O_CREAT | EIO_O_TRUNC, 'a' => ($plus ? EIO_O_RDWR : EIO_O_WRONLY) | EIO_O_CREAT | EIO_O_APPEND, 'x' => ($plus ? EIO_O_RDWR : EIO_O_WRONLY) | EIO_O_EXCL | EIO_O_CREAT, 'c' => ($plus ? EIO_O_RDWR : EIO_O_WRONLY) | EIO_O_CREAT]; $m = $types[$type]; if ($sync) { $m |= EIO_O_FSYNC; } return $m; }
/** * Called when new data received * @return void */ public function onRead() { while (($line = $this->readline()) !== null) { if ($line === '') { continue; } if (mb_orig_strlen($line) > 512) { Daemon::$process->log('IRCClientConnection error: buffer overflow.'); $this->finish(); return; } $line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL)); $p = mb_orig_strpos($line, ' :', 1); $max = $p !== false ? substr_count($line, " ", 0, $p + 1) + 1 : 18; $e = explode(" ", $line, $max); $i = 0; $from = IRC::parseUsermask($e[$i][0] === ':' ? mb_orig_substr($e[$i++], 1) : null); $cmd = $e[$i++]; $args = []; for ($s = min(sizeof($e), 14); $i < $s; ++$i) { if ($e[$i][0] === ':') { $args[] = mb_orig_substr($e[$i], 1); break; } $args[] = $e[$i]; } if (ctype_digit($cmd)) { $code = (int) $cmd; $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code; } $this->lastLine = $line; $this->onCommand($from, $cmd, $args); } if (mb_orig_strlen($this->buf) > 512) { Daemon::$process->log('IRCClientConnection error: buffer overflow.'); $this->finish(); } }
/** * Creates Request. * @param object $req Request. * @param object $upstream Upstream application instance. * @return object Request. */ public function beginRequest($req, $upstream) { $e = array_map('rawurldecode', explode('/', $req->attrs->server['DOCUMENT_URI'])); $serverId = null; $sessId = null; /* Route discovery */ $path = null; $extra = []; do { foreach ($this->wss as $wss) { $try = implode('/', $e); if ($try === '') { $try = '/'; } if ($wss->routeExists($try)) { $path = $try; break 2; } } array_unshift($extra, array_pop($e)); } while (sizeof($e) > 0); if ($path === null) { return $this->callMethod('NotFound', $req, $upstream); } if (sizeof($extra) > 0 && end($extra) === '') { array_pop($extra); } $method = sizeof($extra) ? array_pop($extra) : null; if ($method === null) { $method = 'Welcome'; } elseif ($method === 'info') { } elseif (preg_match('~^iframe(?:-([^/]*))?\\.html$~', $method, $m)) { $method = 'Iframe'; $version = isset($m[1]) ? $m[1] : null; } else { if (sizeof($extra) < 2) { return $this->callMethod('NotFound', $req, $upstream); } $sessId = array_pop($extra); $serverId = array_pop($extra); if ($sessId === '' || $serverId === '' || mb_orig_strpos($sessId, '.') !== false || mb_orig_strpos($serverId, '.') !== false) { return $this->callMethod('NotFound', $req, $upstream); } } $req->attrs->sessId = $sessId; $req->attrs->serverId = $serverId; $req->attrs->path = $path; $req = $this->callMethod($method, $req, $upstream); if ($req instanceof Methods\Iframe && mb_orig_strlen($version)) { $req->attrs->version = $version; } return $req; }
/** * Parse nul-terminated string * @param string &$str Data * @return string */ public static function getString(&$str) { $p = mb_orig_strpos($str, ""); if ($p === false) { return ''; } $r = mb_orig_substr($str, 0, $p); $str = mb_orig_substr($str, $p + 1); return $r; }
function strpos($s, $a) { if (function_exists('mb_orig_strpos')) { return mb_orig_strpos($s, $a); } return strpos($s, $a); }
/** * Open file * @param string $path Path * @param string $flags Flags * @param callable $cb Callback (File) * @param integer $mode Mode (see EIO_S_I* constants) * @param integer $pri Priority * @return resource */ public static function open($path, $flags, $cb, $mode = null, $pri = EIO_PRI_DEFAULT) { $cb = CallbackWrapper::forceWrap($cb); if (!FileSystem::$supported) { $mode = File::convertFlags($flags, true); $fd = fopen($path, $mode); if (!$fd) { $cb(false); return false; } $file = new File($fd, $path); $cb($file); return true; } $fdCacheKey = $path . "" . $flags; $noncache = mb_orig_strpos($flags, '!') !== false; $flags = File::convertFlags($flags); if (!$noncache && ($item = FileSystem::$fdCache->get($fdCacheKey))) { // cache hit $file = $item->getValue(); if ($file === null) { // operation in progress $item->addListener($cb); } else { // hit $cb($file); } return null; } elseif (!$noncache) { $item = FileSystem::$fdCache->put($fdCacheKey, null); $item->addListener($cb); } return eio_open($path, $flags, $mode, $pri, function ($path, $fd) use($cb, $flags, $fdCacheKey, $noncache) { if ($fd === -1) { if ($noncache) { $cb(false); } else { FileSystem::$fdCache->put($fdCacheKey, false, self::$badFDttl); } return; } $file = new File($fd, $path); $file->append = ($flags | EIO_O_APPEND) === $flags; if ($file->append) { $file->stat(function ($file, $stat) use($cb, $noncache, $fdCacheKey) { $file->offset = $stat['size']; if (!$noncache) { $file->fdCacheKey = $fdCacheKey; FileSystem::$fdCache->put($fdCacheKey, $file); } else { $cb($file); } }); } else { if (!$noncache) { $file->fdCacheKey = $fdCacheKey; FileSystem::$fdCache->put($fdCacheKey, $file); } else { $cb($file); } } }, $path); }
/** * @return bool */ public function loadFile() { $this->_openConnection(); fwrite($this->_socket, $this->_requestHeader); // stream_set_blocking($this->_socket, 0); :) $bHeaderRead = false; $header = ''; $startTime = getmicrotime(); while (!($this->_bComplete = feof($this->_socket) || $this->_rangeTo > 0 && $this->_fileLoaded >= $this->_rangeTo)) { if ($this->_timeLimit > 0 && getmicrotime() - $startTime > $this->_timeLimit) { break; } $result = fread($this->_socket, 256 * 1024); if (false === $bHeaderRead) { $header .= $result; if (static::$_bMBStringOrig) { $posHSplit = mb_orig_strpos($header, "\r\n\r\n"); } else { $posHSplit = strpos($header, "\r\n\r\n"); } if ($posHSplit !== false) { if (static::$_bMBStringOrig) { $result = mb_orig_substr($header, $posHSplit + 4); $header = mb_orig_substr($header, 0, $posHSplit + 2); $this->_headerSize = mb_orig_strlen($header); } else { $result = substr($header, $posHSplit + 4); $header = substr($header, 0, $posHSplit + 2); $this->_headerSize = strlen($header); } $this->_readHeaderData($header); $bHeaderRead = true; } else { continue; } } $this->_writeResult($result); } if ($this->_bufferLoaded > 0) { $result = null; $this->_writeResult($result, true); } if (true === $this->_bComplete) { @unlink($this->_dwnStateFilePath); } else { $this->_saveStepToFile(); } fclose($this->_socket); $this->_socket = null; fclose($this->_dwnFileHandler); $this->_dwnFileHandler = null; return $this->_bComplete; }
/** * Called when new data received * @return void */ public function onRead() { Timer::setTimeout($this->keepaliveTimer); while (($line = $this->readline()) !== null) { if ($line === '') { continue; } if (mb_orig_strlen($line) > 512) { Daemon::$process->log('IRCBouncerConnection error: buffer overflow.'); $this->finish(); return; } $line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL)); $p = mb_orig_strpos($line, ':', 1); $max = $p ? substr_count($line, " ", 0, $p) + 1 : 18; $e = explode(" ", $line, $max); $i = 0; $cmd = $e[$i++]; $args = []; for ($s = min(sizeof($e), 14); $i < $s; ++$i) { if ($e[$i][0] === ':') { $args[] = mb_orig_substr($e[$i], 1); break; } $args[] = $e[$i]; } if (ctype_digit($cmd)) { $code = (int) $cmd; $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : 'UNKNOWN-' . $code; } $this->onCommand($cmd, $args); } if (mb_orig_strlen($this->buf) > 512) { Daemon::$process->log('IRCClientConnection error: buffer overflow.'); $this->finish(); } }
/** * XML start callback * * @see xml_set_element_handler * @param resource $parser * @param string $name * @param array $attr * @return void */ public function startXML($parser, $name, $attr) { ++$this->xml_depth; if (array_key_exists('XMLNS', $attr)) { $this->current_ns[$this->xml_depth] = $attr['XMLNS']; } else { $this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1]; if (!$this->current_ns[$this->xml_depth]) { $this->current_ns[$this->xml_depth] = $this->default_ns; } } $ns = $this->current_ns[$this->xml_depth]; foreach ($attr as $key => $value) { if (mb_orig_strpos($key, ':') !== false) { $key = explode(':', $key); $key = $key[1]; $this->ns_map[$key] = $value; } } if (mb_orig_strpos($name, ':') !== false) { $name = explode(':', $name); $ns = $this->ns_map[$name[0]]; $name = $name[1]; } $obj = new XMLStreamObject($name, $ns, $attr); if ($this->xml_depth > 1) { $this->xmlobj[$this->xml_depth - 1]->subs[] = $obj; } $this->xmlobj[$this->xml_depth] = $obj; }
public static function BinStrpos($haystack, $needle, $offset = 0) { if (defined("BX_UTF")) { if (function_exists('mb_orig_strpos')) { return mb_orig_strpos($haystack, $needle, $offset); } return mb_strpos($haystack, $needle, $offset, 'latin1'); } return strpos($haystack, $needle, $offset); }
protected static function strpos($s, $a) { $a = self::chr($a); if (function_exists('mb_orig_strpos')) { return mb_orig_strpos($s, $a); } return strpos($s, $a); }
/** * Builds URL from array * @param string $mixed * @call ( string $str ) * @call ( array $mixed ) * @return string|false */ public static function buildUrl($mixed) { if (is_string($mixed)) { return $mixed; } if (!is_array($mixed)) { return false; } $url = ''; $buf = []; $queryDelimiter = '?'; $mixed[] = ''; foreach ($mixed as $k => $v) { if (is_int($k) || ctype_digit($k)) { if (sizeof($buf) > 0) { if (mb_orig_strpos($url, '?') !== false) { $queryDelimiter = '&'; } $url .= $queryDelimiter . http_build_query($buf); $queryDelimiter = ''; } $url .= $v; } else { $buf[$k] = $v; } } return $url; }