function &createSession($create = TRUE) { if (ServletContext::validClass($this->context)) { $response =& $this->context->getServletResponse(); $session =& $this->context->getServletSession(); if (IHttpResponse::validClass($response) && IHttpSession::validClass($session)) { $sessionid = ''; $cookie = $this->getCookie('_JPHPSESSIONID'); if (!isset($cookie)) { $sessionid = $this->getParameter('_JPHPSESSIONID'); } else { $sessionid = $cookie->getValue(); } if (strlen(trim($sessionid)) < 8) { if ($create == FALSE) { return NULL; } else { $sessionid = md5(StringBuffer::generateKey(16)); } } $session->setSessionID($sessionid); $session->initialize(); $cookie = new Cookie('_JPHPSESSIONID', $sessionid); if ($session->getMaxInactiveInterval() > 0) { $cookie->setMaxAge(time() + $session->getMaxInactiveInterval()); } else { $cookie->setMaxAge(0); } $response->addCookie($cookie); return $session; } } return NULL; }
function FileReader($file = NULL) { $fileobj = NULL; if (!isset($file)) { return; } if (URL::validClass($file)) { $fileobj = $file; $path = $fileobj->toString(); } else { if (File::validClass($file)) { $fileobj = $file; $path = $fileobj->getFilePath(); } else { $str = StringBuffer::toStringBuffer($file); if ($str->startsWith('http://') || $str->startsWith('ftp://') || $str->startsWith('php://')) { $fileobj = new URL($str); $path = $fileobj->toString(); } else { $fileobj = new File($file); $path = $fileobj->getFilePath(); } } } if (isset($fileobj)) { $this->handle = @fopen($path, 'r'); if (isset($this->handle)) { $this->file = $fileobj; } } }
function accept($fileobj, $dirname) { if (File::validClass($fileobj) && (StringBuffer::validClass($dirname) || is_string($dirname))) { return TRUE; } else { return FALSE; } }
function sendFile(&$request, $file, $newname) { $useragent = $request->getUserAgent(); $file = StringBuffer::toStringBuffer($file); $newname = StringBuffer::toStringBuffer($newname); $this->setContentType('application/force-download'); if (isset($file) && $file->length() > 0 && file_exists($file->toString()) && is_file($file->toString())) { if (!empty($useragent) && strstr($user, 'MSIE')) { $this->setHeader('Content-Disposition', 'filename=' . (isset($newname) && $newname->length() > 0 ? $newname->toString() : $file->toString()) . '%20'); // For IE } else { $this->setHeader('Content-Disposition', 'attachment; filename=' . (isset($newname) && $newname->length() > 0 ? $newname->toString() : $file->toString())); } $this->setContentLength(filesize($file->toString())); $this->setHeader('Cache-control', 'private'); readfile(); exit; } }
function loadFromFile() { $configname = new StringBuffer(); $buffers = new StringBuffer(); $key = ''; $value = ''; $conf = ''; $skipline = 0; $c = ''; if ($this->reader->ready()) { while (($c = $this->reader->read()) != '') { if ($c == CONFIG_END_KEY) { if ($buffers->length() > 0) { $buffers = $buffers->trimAll(); if (!$buffers->startsWith(CONFIG_COMMENT)) { $key_separator_pos = $buffers->indexOf(CONFIG_SEPARATOR); if ($key_separator_pos > 0) { $key = $buffers->substring(0, $key_separator_pos); $key = $key->trimAll(); $value = $buffers->substring($key_separator_pos + 1); $value = $value->trimAll(); if ($key->length() > 0 && $value->length() > 0) { $str = $this->get($key->toString()) . $value->toString(); $this->put($key->toString(), $str); } } } } $buffers = new StringBuffer(); } else { $buffers->append($c); } } if ($buffers->length() > 0) { $key_separator_pos = $buffers->indexOf(CONFIG_SEPARATOR); if ($key_separator_pos > 0) { $key = $buffers->substring(0, $key_separator_pos); $key = $key->trimAll(); $value = $buffers->substring($key_separator_pos + 1); $value = $value->trimAll(); if ($key->length() > 0 && $value->length() > 0 && $this->acceptableKey($key)) { $str = $this->get($key->toString()) . $value->toString(); $this->put($key->toString(), $str); } } } } }
function executeQuery($query) { $query = StringBuffer::toStringBuffer($query); $query = $query->trimAll(); $conn =& $this->getCurrentConnection(); $res = mysql_query($query->toString(), $conn->getDatabaseLink()); if (preg_match('/^(delete from |update )/i', $query->toString())) { return $this->getUpdateCount(); } else { if (preg_match('/^(insert into)/i', $query->toString())) { return $this->getLastInsertId(); } else { if (isset($res)) { $this->setResult($res); $err = @mysql_error($conn->getDatabaseLink()); if ($err == "") { $result = new MySQLResultSet($this, $res); return $result; } } } } return NULL; }
function setUploadFileType($type) { $type = StringBuffer::toStringBuffer($type); $this->upload_type = $type; }
function containsKey($key) { $key = StringBuffer::toStringBuffer($key); return isset($key) && isset($this->entries[$key->toString()]); }
function StringReader($source) { $this->handle = StringBuffer::toStringBuffer($source); }
function add($field, $offset) { $offset = StringBuffer::toStringBuffer($offset); $day = $this->get('day'); $month = $this->get('month'); $year = $this->get('year'); $hour = $this->get('hour'); $min = $this->get('minute'); $sec = $this->get('second'); if ($field == 'year') { $year = $year + $offset->intValue(); } else { if ($field == 'month') { $month = $month + $offset->intValue(); } else { if ($field == 'day') { $day = $day + $offset->intValue(); } else { if ($field == 'hour') { $hour = $hour + $offset->intValue(); } else { if ($field == 'minute') { $minute = $minute + $offset->intValue(); } else { if ($field == 'second') { $second = $second + $offset->intValue(); } } } } } } $this->dateobj = new Date(mktime($hour, $min, $sec, $month, $day, $year)); }
function println($stream) { $stream = StringBuffer::toStringBuffer($stream); $stream->append('\\n'); $this->write($stream); }
public function toString() { $sb = new StringBuffer("package "); $sb->append($this->name . " "); if ($this->specTitle) { $sb->append($this->specTitle . " "); } if ($this->specVersion) { $sb->append($this->specVersion . " "); } return $sb->toString(); }
function write($stream) { $stream = StringBuffer::toStringBuffer($stream); print $stream->toString(); }
function performMax($fields, $from, $where = NULL) { $query = new StringBuffer('SELECT '); if (isset($fields)) { $query->append('Max(' . $fields . ') AS total'); } if (isset($from)) { if (is_array($from)) { if (count($from) > 0) { $query->append(implode(',', $from)); } } else { $query->append(' FROM ' . $from); } } $where = StringBuffer::toStringBuffer($where); if (isset($where) && $where->length() > 0) { $query->append(' WHERE ' . $where->toString()); } $result = $this->query($query); if (isset($result) && is_array($result) && count($result) > 0) { $result = $result[0]; return $result['total']; } else { return 0; } }
function getConfigValue($configname, $key) { $configname = StringBuffer::toStringBuffer($configname); $key = StringBuffer::toStringBuffer($key); $cf = $this->getConfig($configname->toString()); if (isset($cf)) { return $cf->get($key->toString()); } return NULL; }
function toStringBuffer($object) { if (StringBuffer::validClass($object)) { return $object; } if (isset($object) && $object != '') { if (is_object($object) && method_exists($object, 'tostring')) { return new StringBuffer($object->toString()); } else { return new StringBuffer($object); } } return NULL; }
function initialize() { // path existance if (!file_exists($this->path)) { if (!$this->createStructure($this->path)) { die('I/O Exception : ' . $this->path . ' cannot be create ...'); } } else { if (!is_dir($this->path)) { die('I/O Exception : ' . $this->path . ' exists and it\' a file ...'); } } // load session object if (isset($this->sessionID)) { if (!file_exists($this->path . $this->sessionID . '.cache')) { $this->cache = array(); $this->creationTime = time(); $this->lastAccessedTime = $this->creationTime; $this->isNewSession = TRUE; $this->saveSessionObject(); } else { if (!$this->loadSessionObject()) { $this->sessionID = md5(StringBuffer::generateKey(16)); $this->cache = array(); $this->creationTime = time(); $this->lastAccessedTime = $this->creationTime; $this->isNewSession = TRUE; $this->saveSessionObject(); } } } }
function writeValue() { $args = func_get_args(); $val = $args[0]; $type = $args[1]; if (count($args) >= 3) { $implicit = $args[2]; } else { $implicit = FALSE; } $typeByte = new StringBuffer(); if ($type === NATIVEOBJECT) { $typeByte->writeUInt8(OBJECTV, 0); } else { $typeByte->writeUInt8($type, 0); } if ($type === UNDEFINED || $type === TRUEVAL || $type === FALSEVAL || $type === NULLVAL || $type === NANV || $type === MINUSINFINITY || $type === INFINITY) { $this->append($typeByte); return 1; } $byteCount = 0; if (!$implicit) { $this->append($typeByte); $byteCount++; } if ($type === STRINGV) { if (count($this->stringIndex) === 0) { $this->writeString($val); return 1 + $byteCount + strlen($val); } $this->writeValue(array_search($val, $this->stringIndex), $this->stringIndexType, TRUE); return $byteCount + 1; } else { if ($type === (SIGNED | CHAR)) { $bytes = new StringBuffer(); $bytes->writeInt8($val, 0); $this->append($bytes); return $byteCount + 1; } else { if ($type === CHAR) { $bytes = new StringBuffer(); $bytes->writeUInt8($val, 0); $this->append($bytes); return $byteCount + 1; } else { if ($type === (SIGNED | SHORT)) { $bytes = new StringBuffer(); $bytes->writeInt16LE($val, 0); $this->append($bytes); return 2 + $byteCount; } else { if ($type === SHORT) { $bytes = new StringBuffer(); $bytes->writeUInt16LE($val, 0); $this->append($bytes); return 2 + $byteCount; } else { if ($type === (SIGNED | INTV)) { $bytes = new StringBuffer(); $bytes->writeInt32LE($val, 0); $this->append($bytes); return 4 + $byteCount; } else { if ($type === INTV) { $bytes = new StringBuffer(); $bytes->writeUInt32LE($val, 0); $this->append($bytes); return 4 + $byteCount; } else { if ($type === FLOATV) { $bytes = new StringBuffer(); $bytes->writeFloatLE($val, 0); $this->append($bytes); return 4 + $byteCount; } else { if ($type === DOUBLEV) { $bytes = new StringBuffer(); $bytes->writeDoubleLE($val, 0); $this->append($bytes); return 8 + $byteCount; } else { if ($type === VARARRAY) { $this->writeValue(count($val), type_check(count($val))); foreach ($val as $v) { $this->writeValue($v, type_check($v)); } return; } else { if ($type === OBJECTV) { $index = match_layout($val, $this->stringIndex, $this->OLI); $this->writeValue($index, $this->OLItype, TRUE); for ($i = 0; $i < count($this->OLI[$index]); ++$i) { $tmp = $val[$this->stringIndex[$this->OLI[$index][$i]]]; $this->writeValue($tmp, type_check($tmp)); } return; } else { if ($type === NATIVEOBJECT) { $index = match_layout($val, $this->stringIndex, $this->OLI); $this->writeValue($index, $this->OLItype, true); for ($i = 0; $i < count($this->OLI[$index]); ++$i) { $tmp = $val->{$this->stringIndex[$this->OLI[$index][$i]]}; $this->writeValue($tmp, type_check($tmp)); } return; } else { if ($type === BUFFER) { $len = strlen($val->buffer); $this->writeValue($len, type_check($len)); for ($i = 0; $i < $len; ++$i) { $this->writeValue(ord($val->buffer[$i]), CHAR, true); } return $byteCount + strlen($val->buffer); } else { if ($type === REGEXP) { $this->writeString($val->pattern); $this->writeString($val->modifier); return $byteCount + 2 + strlen($val->pattern) + strlen($val->modifier); } else { if ($type === DATEVAL) { $this->writeValue($val->timestamp, DOUBLEV, true); return $byteCount + 8; } } } } } } } } } } } } } } } }
private function readJSONString($peek = false, $start = 0) { if (!\hacklib_cast_as_boolean($peek)) { $start = 0; } $this->expectChar("\"", $peek, $start); $count = \hacklib_cast_as_boolean($peek) ? 1 : 0; $sb = new StringBuffer(); $reading = true; while (\hacklib_cast_as_boolean($reading)) { $c = $this->bufTrans->peek(1, $start + $count); switch ($c) { case "\"": $reading = false; break; case "\\": $count++; $c = $this->bufTrans->peek(1, $start + $count); switch ($c) { case "\\": $count++; $sb->append("\\"); break; case "\"": $count++; $sb->append("\""); break; case "b": $count++; $sb->append(chr(0x8)); break; case "/": $count++; $sb->append("/"); break; case "f": $count++; $sb->append("\f"); break; case "n": $count++; $sb->append("\n"); break; case "r": $count++; $sb->append("\r"); break; case "t": $count++; $sb->append("\t"); break; case "u": $count++; $this->expectChar("0", true, $start + $count); $this->expectChar("0", true, $start + $count + 1); $count += 2; $sb->append(hex2bin($this->bufTrans->peek(2, $start + $count))); $count += 2; break; default: throw new TProtocolException("TSimpleJSONProtocol: Expected Control Character, found 0x" . bin2hex($c)); } break; default: $count++; $sb->append($c); break; } } if (!\hacklib_cast_as_boolean($peek)) { $this->trans_->readAll($count); } $this->expectChar("\"", $peek, $start + $count); return \HH\Pair::hacklib_new($sb->detach(), $count + 1); }
function mkdirs($perms) { $path = StringBuffer::toStringBuffer($this->getFilePath()); if ($path->startsWith(".\\") || $path->startsWith("./")) { $path = $path->substring(2); $path = $path->toString(); } else { $path = $this->toString(); } $struct = preg_split('!\\/+!xsmi', $path, -1, PREG_SPLIT_NO_EMPTY); $part = ''; $len = count($struct); for ($i = 0; $i < $len; $i++) { $part .= $struct[$i]; @mkdir($part, $perms); $part .= '/'; } return $this->exists(); }
/** * get all parameter names available as Enumeration * @return jphp.util.Enumeration the parameter value * @see jphp.http.interface.IHttpRequest#getParameterNames */ function getParameterNames($type = 'all') { $type = StringBuffer::toStringBuffer($type); $get_keys = $this->http_get_request->keys(); $post_keys = $this->http_post_request->keys(); $type = $type->toLowerCase(); if ($type->equals('get')) { return $get_keys; } else { if ($type->equals('post')) { return $post_keys; } else { return array_merge($post_keys, $get_keys); } } }
function load($datasource) { $classname = NULL; $hash = NULL; $obj = NULL; $data = StringBuffer::toStringBuffer($datasource); if (isset($data)) { $res = array(); if (preg_match('/^[aA-zZ]:[0-9]+:"([aA-zZ]+)"\\s*/', $data->toString(), $res)) { if ($res[1] == 'stdClass') { $obj = unserialize($data->toString()); return $obj->scalar; } else { if (class_exists($res[1])) { return unserialize($data->toString()); } } } else { if ($data->startsWith('a')) { return unserialize($data->toString()); } } } return NULL; }