Exemplo n.º 1
0
 /**
  * Test for PMA_checkTimeout
  *
  * @return void
  */
 function testCheckTimeout()
 {
     global $timestamp, $maximum_time, $timeout_passed;
     //Reinit values.
     $timestamp = time();
     $maximum_time = 0;
     $timeout_passed = false;
     $this->assertFalse(PMA_checkTimeout());
     //Reinit values.
     $timestamp = time();
     $maximum_time = 0;
     $timeout_passed = true;
     $this->assertFalse(PMA_checkTimeout());
     //Reinit values.
     $timestamp = time();
     $maximum_time = 30;
     $timeout_passed = true;
     $this->assertTrue(PMA_checkTimeout());
     //Reinit values.
     $timestamp = time() - 15;
     $maximum_time = 30;
     $timeout_passed = false;
     $this->assertFalse(PMA_checkTimeout());
     //Reinit values.
     $timestamp = time() - 60;
     $maximum_time = 30;
     $timeout_passed = false;
     $this->assertTrue(PMA_checkTimeout());
 }
Exemplo n.º 2
0
/**
 *  Returns next part of imported file/buffer
 *
 *  @param  integer size of buffer to read (this is maximal size
 *                  function will return)
 *  @return string part of file/buffer
 *  @access public
 */
function PMA_importGetNextChunk($size = 32768)
{
    global $import_file, $import_text, $finished, $compression, $import_handle, $offset, $charset_conversion, $charset_of_file, $charset, $read_multiply, $read_limit;
    // Add some progression while reading large amount of data
    if ($read_multiply <= 8) {
        $size *= $read_multiply;
    } else {
        $size *= 8;
    }
    $read_multiply++;
    // We can not read too much
    if ($size > $read_limit) {
        $size = $read_limit;
    }
    if (PMA_checkTimeout()) {
        return FALSE;
    }
    if ($finished) {
        return TRUE;
    }
    if ($import_file == 'none') {
        // Well this is not yet supported and tested, but should return content of textarea
        if (strlen($import_text) < $size) {
            $finished = TRUE;
            return $import_text;
        } else {
            $r = substr($import_text, 0, $size);
            $offset += $size;
            $import_text = substr($import_text, $size);
            return $r;
        }
    }
    switch ($compression) {
        case 'application/bzip2':
            $result = bzread($import_handle, $size);
            $finished = feof($import_handle);
            break;
        case 'application/gzip':
            $result = gzread($import_handle, $size);
            $finished = feof($import_handle);
            break;
        case 'application/zip':
            $result = substr($import_text, 0, $size);
            $import_text = substr($import_text, $size);
            $finished = empty($import_text);
            break;
        case 'none':
            $result = fread($import_handle, $size);
            $finished = feof($import_handle);
            break;
    }
    $offset += $size;
    if ($charset_conversion) {
        return PMA_convert_string($charset_of_file, $charset, $result);
    } else {
        return $result;
    }
}
Exemplo n.º 3
0
/**
 * Returns next part of imported file/buffer
 *
 * @param int $size size of buffer to read
 *                  (this is maximal size function will return)
 *
 * @return string part of file/buffer
 * @access public
 */
function PMA_importGetNextChunk($size = 32768)
{
    global $compression, $import_handle, $charset_conversion, $charset_of_file, $read_multiply;
    // Add some progression while reading large amount of data
    if ($read_multiply <= 8) {
        $size *= $read_multiply;
    } else {
        $size *= 8;
    }
    $read_multiply++;
    // We can not read too much
    if ($size > $GLOBALS['read_limit']) {
        $size = $GLOBALS['read_limit'];
    }
    if (PMA_checkTimeout()) {
        return false;
    }
    if ($GLOBALS['finished']) {
        return true;
    }
    if ($GLOBALS['import_file'] == 'none') {
        // Well this is not yet supported and tested,
        // but should return content of textarea
        if (mb_strlen($GLOBALS['import_text']) < $size) {
            $GLOBALS['finished'] = true;
            return $GLOBALS['import_text'];
        } else {
            $r = mb_substr($GLOBALS['import_text'], 0, $size);
            $GLOBALS['offset'] += $size;
            $GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size);
            return $r;
        }
    }
    switch ($compression) {
        case 'application/bzip2':
            $result = bzread($import_handle, $size);
            $GLOBALS['finished'] = feof($import_handle);
            break;
        case 'application/gzip':
            $result = gzread($import_handle, $size);
            $GLOBALS['finished'] = feof($import_handle);
            break;
        case 'application/zip':
            $result = mb_substr($GLOBALS['import_text'], 0, $size);
            $GLOBALS['import_text'] = mb_substr($GLOBALS['import_text'], $size);
            $GLOBALS['finished'] = empty($GLOBALS['import_text']);
            break;
        case 'none':
            $result = fread($import_handle, $size);
            $GLOBALS['finished'] = feof($import_handle);
            break;
    }
    $GLOBALS['offset'] += $size;
    if ($charset_conversion) {
        return PMA_convertString($charset_of_file, 'utf-8', $result);
    }
    /**
     * Skip possible byte order marks (I do not think we need more
     * charsets, but feel free to add more, you can use wikipedia for
     * reference: <http://en.wikipedia.org/wiki/Byte_Order_Mark>)
     *
     * @todo BOM could be used for charset autodetection
     */
    if ($GLOBALS['offset'] == $size) {
        // UTF-8
        if (strncmp($result, "", 3) == 0) {
            $result = mb_substr($result, 3);
            // UTF-16 BE, LE
        } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) {
            $result = mb_substr($result, 2);
        }
    }
    return $result;
}
Exemplo n.º 4
0
/**
 *  Returns next part of imported file/buffer
 *
 *  @param  integer size of buffer to read (this is maximal size
 *                  function will return)
 *  @return string part of file/buffer
 *  @access public
 */
function PMA_importGetNextChunk($size = 32768)
{
    global $import_file, $import_text, $finished, $compression, $import_handle, $offset, $charset_conversion, $charset_of_file, $charset, $read_multiply, $read_limit;
    // Add some progression while reading large amount of data
    if ($read_multiply <= 8) {
        $size *= $read_multiply;
    } else {
        $size *= 8;
    }
    $read_multiply++;
    // We can not read too much
    if ($size > $read_limit) {
        $size = $read_limit;
    }
    if (PMA_checkTimeout()) {
        return FALSE;
    }
    if ($finished) {
        return TRUE;
    }
    if ($import_file == 'none') {
        // Well this is not yet supported and tested, but should return content of textarea
        if (strlen($import_text) < $size) {
            $finished = TRUE;
            return $import_text;
        } else {
            $r = substr($import_text, 0, $size);
            $offset += $size;
            $import_text = substr($import_text, $size);
            return $r;
        }
    }
    switch ($compression) {
        case 'application/bzip2':
            $result = bzread($import_handle, $size);
            $finished = feof($import_handle);
            break;
        case 'application/gzip':
            $result = gzread($import_handle, $size);
            $finished = feof($import_handle);
            break;
        case 'application/zip':
            $result = substr($import_text, 0, $size);
            $import_text = substr($import_text, $size);
            $finished = empty($import_text);
            break;
        case 'none':
            $result = fread($import_handle, $size);
            $finished = feof($import_handle);
            break;
    }
    $offset += $size;
    if ($charset_conversion) {
        return PMA_convert_string($charset_of_file, $charset, $result);
    } else {
        // Skip possible byte order marks (I do not think we need more
        // charsets, but feel free to add more, you can use wikipedia for
        // reference: <http://en.wikipedia.org/wiki/Byte_Order_Mark>)
        // @TODO: BOM could be used for charset autodetection
        if ($offset == $size) {
            // UTF-8
            if (strncmp($result, "", 3) == 0) {
                $result = substr($result, 3);
                // UTF-16 BE, LE
            } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) {
                $result = substr($result, 2);
            }
        }
        return $result;
    }
}