Beispiel #1
0
 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;
         }
     }
 }
Beispiel #2
0
 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;
     }
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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();
 }
 function equals($str, $ignorecase = FALSE)
 {
     $str = StringBuffer::toStringBuffer($str);
     $pattern = '/^(' . preg_quote($str->toString()) . ')$/';
     if ($ignorecase) {
         $pattern .= 'i';
     }
     return @preg_match($pattern, $this->str) > 0;
 }
Beispiel #6
0
 function setUploadFileType($type)
 {
     $type = StringBuffer::toStringBuffer($type);
     $this->upload_type = $type;
 }
Beispiel #7
0
 function containsKey($key)
 {
     $key = StringBuffer::toStringBuffer($key);
     return isset($key) && isset($this->entries[$key->toString()]);
 }
Beispiel #8
0
 function StringReader($source)
 {
     $this->handle = StringBuffer::toStringBuffer($source);
 }
Beispiel #9
0
 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));
 }
Beispiel #10
0
 function write($stream)
 {
     $stream = StringBuffer::toStringBuffer($stream);
     print $stream->toString();
 }
Beispiel #11
0
 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;
     }
 }
Beispiel #12
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;
 }
Beispiel #13
0
 function println($stream)
 {
     $stream = StringBuffer::toStringBuffer($stream);
     $stream->append('\\n');
     $this->write($stream);
 }
Beispiel #14
0
 /**
  * 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);
         }
     }
 }
Beispiel #15
-1
 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;
 }