Example #1
0
function send_file($path)
{
    ob_end_clean();
    if (preg_match(':\\.\\.:', $path)) {
        return FALSE;
    }
    if (!preg_match(':^plotcache/:', $path)) {
        return FALSE;
    }
    if (!is_file($path) or connection_status() != 0) {
        return FALSE;
    }
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Content-Type: application/octet-stream");
    header("Content-Length: " . (string) filesize($path));
    header("Content-Disposition: inline; filename=" . basename($path));
    header("Content-Transfer-Encoding: binary\n");
    if ($file = fopen($path, 'rb')) {
        while (!feof($file) and connection_status() == 0) {
            print fread($file, 1024 * 8);
            flush();
            @ob_flush();
        }
        fclose($file);
    }
    return connection_status() == 0 and !connection_aborted();
}
 function getJson($url)
 {
     //echo urlencode($url)."</br>";
     $code = http_response_code();
     //  Initiate curl
     $ch = curl_init();
     // Disable SSL verification
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     // Will return the response, if false it print the response
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Set the url
     curl_setopt($ch, CURLOPT_URL, $url);
     // Execute
     $result = curl_exec($ch);
     if (connection_aborted()) {
         echo "erra bae";
     } elseif (connection_status() == CONNECTION_TIMEOUT) {
         echo "<h1>Error caught, stopped from crashing</h1>";
     } else {
         $this->busted = false;
         //  any normal completion actions
     }
     // Closing
     curl_close($ch);
     return json_decode($result, true);
 }
Example #3
0
/**
 * Stores CSS in a file at the given path.
 *
 * This function either succeeds or throws an exception.
 *
 * @param theme_config $theme The theme that the CSS belongs to.
 * @param string $csspath The path to store the CSS at.
 * @param string $csscontent the complete CSS in one string
 * @param bool $chunk If set to true these files will be chunked to ensure
 *      that no one file contains more than 4095 selectors.
 * @param string $chunkurl If the CSS is be chunked then we need to know the URL
 *      to use for the chunked files.
 */
function css_store_css(theme_config $theme, $csspath, $csscontent, $chunk = false, $chunkurl = null)
{
    global $CFG;
    clearstatcache();
    if (!file_exists(dirname($csspath))) {
        @mkdir(dirname($csspath), $CFG->directorypermissions, true);
    }
    // Prevent serving of incomplete file from concurrent request,
    // the rename() should be more atomic than fwrite().
    ignore_user_abort(true);
    // First up write out the single file for all those using decent browsers.
    css_write_file($csspath, $csscontent);
    if ($chunk) {
        // If we need to chunk the CSS for browsers that are sub-par.
        $css = css_chunk_by_selector_count($csscontent, $chunkurl);
        $files = count($css);
        $count = 1;
        foreach ($css as $content) {
            if ($count === $files) {
                // If there is more than one file and this IS the last file.
                $filename = preg_replace('#\\.css$#', '.0.css', $csspath);
            } else {
                // If there is more than one file and this is not the last file.
                $filename = preg_replace('#\\.css$#', '.' . $count . '.css', $csspath);
            }
            $count++;
            css_write_file($filename, $content);
        }
    }
    ignore_user_abort(false);
    if (connection_aborted()) {
        die;
    }
}
function send_file($name)
{
    $path = $name;
    $path_info = pathinfo($path);
    $basename = $path_info['basename'];
    if (!is_file($path) or connection_status() != 0) {
        return false;
    }
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Content-Type: application/octet-stream");
    header("Content-Length: " . (string) filesize($path));
    header("Content-Disposition: inline; filename={$basename}");
    header("Content-Transfer-Encoding: binary\n");
    if ($file = fopen($path, 'rb')) {
        while (!feof($file) and connection_status() == 0) {
            print fread($file, 1024 * 8);
            flush();
        }
        fclose($file);
    }
    return connection_status() == 0 and !connection_aborted();
}
 public function __construct()
 {
     $this->Connect();
     if (connection_aborted() == TRUE) {
         //@mssql_close($this->Connect);
     }
 }
function send_file($path)
{
    session_write_close();
    ob_end_clean();
    if (!is_file($path) || connection_status() != 0) {
        return false;
    }
    //to prevent long file from getting cut off from    //max_execution_time
    set_time_limit(0);
    $name = basename($path);
    //filenames in IE containing dots will screw up the
    //filename unless we add this
    if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
        $name = preg_replace('/\\./', '%2e', $name, substr_count($name, '.') - 1);
        //required, or it might try to send the serving    //document instead of the file
        $name = str_replace(array("\"", "<", ">", "?", ":"), array('%22', '%3c', '%3e', '%3f', '_'), $name);
    } else {
        $name = str_replace(array("\"", ":"), array("'", "_"), $name);
    }
    header("Cache-Control: ");
    header("Pragma: ");
    header("Content-Type: application/octet-stream");
    header("Content-Length: " . (string) filesize($path));
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header("Content-Transfer-Encoding: binary\n");
    if ($file = fopen($path, 'rb')) {
        while (!feof($file) && connection_status() == 0) {
            print fread($file, 1024 * 8);
            flush();
        }
        fclose($file);
    }
    return connection_status() == 0 and !connection_aborted();
}
function zipify($Dir, $ExhibitName) {
	chdir($Dir);
		
	$filename = '../../tmp/'.$ExhibitName.'.zip';

	echo 'real filename: '.realpath($filename);

	if(size_dir('.') > disk_free_space('.'))
		die('Error: not enough free space to zip');
			
	ignore_user_abort(true);
	
	$command='zip -r '.escapeshellarg($filename).' .';
	exec($command);
			
	if(connection_aborted()) {
		unlink($filename);
		die();
	}
	else {
		header('Content-Description: File Transfer');
	   header('Content-Type: application/zip');
	   header('Content-Disposition: attachment; filename='.urlencode($ExhibitName).'.zip');
	   header('Content-Transfer-Encoding: binary');
	   header('Expires: 0');
	   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
	   header('Pragma: public');
	   header('Content-Length: ' . filesize($filename));
	   ob_clean();
	   flush();
	   readfile($filename);
		unlink($filename);
	   exit;
	}
}
Example #8
0
 /**
 		Transmit file to HTTP client; Return file size if successful,
 		FALSE otherwise
 		@return int|FALSE
 		@param $file string
 		@param $mime string
 		@param $kbps int
 	**/
 function send($file, $mime = NULL, $kbps = 0)
 {
     if (!is_file($file)) {
         return FALSE;
     }
     if (PHP_SAPI != 'cli') {
         header('Content-Type: ' . $mime ?: $this->mime($file));
         if ($mime == 'application/octet-stream') {
             header('Content-Disposition: attachment; ' . 'filename=' . basename($file));
         }
         header('Accept-Ranges: bytes');
         header('Content-Length: ' . ($size = filesize($file)));
         header('X-Powered-By: ' . Base::instance()->get('PACKAGE'));
     }
     $ctr = 0;
     $handle = fopen($file, 'rb');
     $start = microtime(TRUE);
     while (!feof($handle) && ($info = stream_get_meta_data($handle)) && !$info['timed_out'] && !connection_aborted()) {
         if ($kbps) {
             // Throttle output
             $ctr++;
             if ($ctr / $kbps > ($elapsed = microtime(TRUE) - $start)) {
                 usleep(1000000.0 * ($ctr / $kbps - $elapsed));
             }
         }
         // Send 1KiB and reset timer
         echo fread($handle, 1024);
     }
     fclose($handle);
     return $size;
 }
Example #9
0
 function jok($str)
 {
     if ($this->transObj) {
         $this->transObj->query(connection_aborted() ? 'ROLLBACK' : 'COMMIT');
     }
     $cli = HTML_FlexyFramework::get()->cli;
     if ($cli) {
         echo "OK: " . $str . "\n";
         exit;
     }
     require_once 'Services/JSON.php';
     $json = new Services_JSON();
     $retHTML = isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']);
     if ($retHTML) {
         if (isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] == 'NO') {
             $retHTML = false;
         }
     } else {
         $retHTML = isset($_REQUEST['returnHTML']) && $_REQUEST['returnHTML'] != 'NO';
     }
     if ($retHTML) {
         header('Content-type: text/html');
         echo "<HTML><HEAD></HEAD><BODY>";
         // encode html characters so they can be read..
         echo str_replace(array('<', '>'), array('\\u003c', '\\u003e'), $json->encodeUnsafe(array('success' => true, 'data' => $str)));
         echo "</BODY></HTML>";
         exit;
     }
     echo $json->encode(array('success' => true, 'data' => $str));
     exit;
 }
Example #10
0
function SPEWCLEANUP()
{
    global $fp;
    if (!$fp || !connection_aborted()) {
        exit;
    }
    pclose($fp);
    exit;
}
Example #11
0
function can_gzip(){ 
    global $HTTP_ACCEPT_ENCODING;    
    if (headers_sent() || connection_aborted()){ 
        return 0; 
    } 
    if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip"; 
    if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip"; 
    return 0; 
} 
Example #12
0
 /**
  * undocumented function
  *
  * @return  void
  * @author  Neil Brayfield
  **/
 public function indexAction()
 {
     // Get the file path from the request
     $filename = $this->dispatcher->getParam('file');
     // Find the file extension
     $ext = pathinfo($filename, PATHINFO_EXTENSION);
     // Remove the extension from the filename
     $filename = substr($filename, 0, -(strlen($ext) + 1));
     if ($filename = $this->fs->findFile('public', $filename, $ext, false)) {
         // Check if the browser sent an "if-none-match: <etag>" header or the if-modfied-since header,
         // and tell if the file hasn't changed
         $mtime = filemtime($filename);
         $etag = md5($mtime);
         $modified_since = $this->request->getHeader('if-modified-since');
         $non_match = $this->request->getHeader('if-none-match');
         if ($non_match === $etag || $modified_since != "" && strtotime($modified_since) >= $mtime) {
             // Throw 304 not modified cache header
             throw new HTTP304();
         }
         $this->response->setEtag($etag);
         // Set the proper headers to allow caching
         $this->response->setHeader('Content-Type', $this->file->mimeByExt($ext));
         $this->response->setHeader('Last-Modified', date('r', $mtime));
         $this->response->sendHeaders();
         while (ob_get_level()) {
             // Flush all output buffers
             ob_end_flush();
         }
         $start = 0;
         $end = filesize($filename);
         // Open the file for reading
         $file = fopen($filename, 'rb');
         // Send data in 16kb blocks
         $block = 1024 * 16;
         fseek($file, $start);
         while (!feof($file) && ($pos = ftell($file)) <= $end) {
             if (connection_aborted()) {
                 break;
             }
             if ($pos + $block > $end) {
                 // Don't read past the buffer.
                 $block = $end - $pos + 1;
             }
             // Output a block of the file
             echo fread($file, $block);
             // Send the data now
             flush();
         }
         // Close the file
         fclose($file);
         exit;
     } else {
         // Return a 404 status
         throw new HTTP404();
     }
 }
 function write($string = '', $verbosity_status = PROCESS_LEVEL_NOTICE)
 {
     if (!connection_aborted() && $this->current_process) {
         $values['session_id'] = $this->session_id;
         $values['status'] = $verbosity_status;
         $values['name'] = $this->current_process;
         $values['message'] = $string;
         $values['time'] = time();
         $this->db->sql_insert('sys_progress', $values);
     }
 }
Example #14
0
function get_conversations($dao, $user_id, $latest_pulled, $latest_seen_by_u2)
{
    global $user;
    global $INITIAL_CONVO_SIZE;
    $this_conversation = "((user_id1=\"{$user->user_id}\" AND user_id2=\"{$user_id}\") OR \n\t\t \t\t\t\t\t   (user_id2=\"{$user->user_id}\" AND user_id1=\"{$user_id}\"))";
    $properties = array("msg_id", "user_id1", "user_id2", "user_name", "msg_content", "msg_seen");
    //Select all messages that have not been pulled by this client
    // AND all messages that have been seen by the other user, but this has not yet been observed
    // by this client.
    if ($latest_pulled != -1) {
        $query = "SELECT " . implode(",", $properties) . " FROM\n\t\t\t\t\t\tchat_msg JOIN user ON user.user_id=user_id1 \n\t\t\t\t\t\tWHERE {$this_conversation}\n\t\t\t\t\t\t\tAND ((msg_id > {$latest_seen_by_u2} AND msg_seen AND user_id2=\"{$user_id}\")\n\t\t\t\t\t\t\t      OR (msg_id > {$latest_pulled}))\n\t\t\t\t\t\tORDER BY msg_id ASC;";
    } else {
        $query = "(SELECT " . implode(",", $properties) . " FROM\n\t\t\t\t\t\tchat_msg JOIN user ON user.user_id=user_id1 \n\t\t\t \t\t\tWHERE {$this_conversation}\n\t\t\t \t\t\tORDER BY msg_id DESC LIMIT {$INITIAL_CONVO_SIZE}) ORDER BY msg_id ASC;";
    }
    $dao->myquery($query);
    $messages = $dao->fetch_all_obj_part($properties);
    if (connection_aborted()) {
        echo "Connection aborted";
    }
    $conversations = array();
    //When a request for a specific user is made, include conversation info
    // even if there aren't any messages.
    if ($user_id != "-1") {
        $user2 = DataObject::select_one($dao, "user", array("user_id", "user_name", "user_picture"), array("user_id" => $user_id));
        $conversation = new stdClass();
        $conversation->messages = array();
        $conversation->user_name = $user2->user_name;
        $conversation->user_picture = $user2->user_picture;
        $conversation->user_id = $user_id;
        $conversations[$user_id] = $conversation;
    }
    foreach ($messages as $message) {
        $dao->myquery("UPDATE chat_msg SET msg_seen=1 WHERE msg_id=\"{$message->msg_id}\" AND user_id2=\"{$user->user_id}\";");
        if ($message->user_id2 != $user->user_id) {
            $convo_id = $message->user_id2;
        } else {
            $convo_id = $message->user_id1;
        }
        if (!array_key_exists($convo_id, $conversations)) {
            $user2 = DataObject::select_one($dao, "user", array("user_id", "user_name", "user_picture"), array("user_id" => $convo_id));
            $conversation = new stdClass();
            $conversation->messages = array();
            $conversation->user_name = $user2->user_name;
            $conversation->user_id = $convo_id;
            $conversation->user_picture = $user2->user_picture;
            $conversations[$convo_id] = $conversation;
        } else {
            $conversation = $conversations[$convo_id];
        }
        $conversation->messages[$message->msg_id] = $message;
    }
    return $conversations;
}
Example #15
0
/**
 * Stores CSS in a file at the given path.
 *
 * This function either succeeds or throws an exception.
 *
 * @param theme_config $theme The theme that the CSS belongs to.
 * @param string $csspath The path to store the CSS at.
 * @param array $cssfiles The CSS files to store.
 */
function css_store_css(theme_config $theme, $csspath, array $cssfiles)
{
    global $CFG;
    if (!empty($CFG->enablecssoptimiser)) {
        // This is an experimental feature introduced in Moodle 2.3
        // The CSS optimiser organises the CSS in order to reduce the overall number
        // of rules and styles being sent to the client. It does this by collating
        // the CSS before it is cached removing excess styles and rules and stripping
        // out any extraneous content such as comments and empty rules.
        $optimiser = new css_optimiser();
        $css = '';
        foreach ($cssfiles as $file) {
            $css .= file_get_contents($file) . "\n";
        }
        $css = $theme->post_process($css);
        $css = $optimiser->process($css);
        // If cssoptimisestats is set then stats from the optimisation are collected
        // and output at the beginning of the CSS
        if (!empty($CFG->cssoptimiserstats)) {
            $css = $optimiser->output_stats_css() . $css;
        }
    } else {
        // This is the default behaviour.
        // The cssoptimise setting was introduced in Moodle 2.3 and will hopefully
        // in the future be changed from an experimental setting to the default.
        // The css_minify_css will method will use the Minify library remove
        // comments, additional whitespace and other minor measures to reduce the
        // the overall CSS being sent.
        // However it has the distinct disadvantage of having to minify the CSS
        // before running the post process functions. Potentially things may break
        // here if theme designers try to push things with CSS post processing.
        $css = $theme->post_process(css_minify_css($cssfiles));
    }
    clearstatcache();
    if (!file_exists(dirname($csspath))) {
        @mkdir(dirname($csspath), $CFG->directorypermissions, true);
    }
    // Prevent serving of incomplete file from concurrent request,
    // the rename() should be more atomic than fwrite().
    ignore_user_abort(true);
    if ($fp = fopen($csspath . '.tmp', 'xb')) {
        fwrite($fp, $css);
        fclose($fp);
        rename($csspath . '.tmp', $csspath);
        @chmod($csspath, $CFG->filepermissions);
        @unlink($csspath . '.tmp');
        // just in case anything fails
    }
    ignore_user_abort(false);
    if (connection_aborted()) {
        die;
    }
}
function CanGZIP() {
	if (headers_sent() || connection_aborted() || !extension_loaded("zlib") || !viscacha_function_exists('gzcompress')){
		return false;
	}
	if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
		return "x-gzip";
	}
	if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false) {
		return "gzip";
	}
	return false;
}
function dl_file_resume($file = '', $fileinfo = array(), $onsuccess = false)
{
    // function based on this one here:
    // http://www.php.net/manual/de/function.fread.php#63893
    //First, see if the file exists
    if (!is_file($file) && connection_status()) {
        return false;
    }
    //Gather relevent info about file
    $filename = empty($fileinfo['realfname']) ? basename($file) : $fileinfo['realfname'];
    $disposition = empty($fileinfo['method']) ? 'attachment' : $fileinfo['method'];
    if ($disposition == 'attachment') {
        $fileinfo['mimetype'] = "application/force-download";
    }
    if (empty($fileinfo['mimetype']) && empty($fileinfo['extension'])) {
        $file_extension = strtolower(substr(strrchr($filename, "."), 1));
        $ctype = isset($GLOBALS['phpwcms']['mime_types'][$file_extension]) ? $GLOBALS['phpwcms']['mime_types'][$file_extension] : 'application/force-download';
    } else {
        $ctype = $fileinfo['mimetype'];
        $file_extension = $fileinfo['extension'];
    }
    //Begin writing headers
    header('Cache-Control: ');
    header('Cache-Control: public');
    header('Pragma: ');
    //Use the switch-generated Content-Type
    header('Content-Type: ' . $ctype);
    if (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
        // workaround for IE filename bug with multiple periods / multiple dots in filename
        // that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
        $filename = preg_replace('/\\./', '%2e', $filename, substr_count($filename, '.') - 1);
    }
    //header('Accept-Ranges: bytes');
    $size = filesize($file);
    header('Content-Length: ' . $size);
    header('Content-Transfer-Encoding: binary' . LF);
    header('Content-Disposition: ' . $disposition . '; filename="' . $filename . '"');
    //reset time limit for big files
    @set_time_limit(0);
    //open the file
    $fp = fopen($file, 'rb');
    //seek to start of missing part
    //fseek($fp, $range);
    //start buffered download
    while (!feof($fp) && !connection_status()) {
        print fread($fp, 1024 * 8);
        flush();
        //ob_flush();
    }
    fclose($fp);
    return $onsuccess && !connection_status() && !connection_aborted() ? true : false;
}
Example #18
0
function CheckCanGzip()
{
    if (headers_sent() || connection_aborted() || !function_exists('ob_gzhandler') || ini_get('zlib.output_compression')) {
        return 0;
    }
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
        return "x-gzip";
    }
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
        return "gzip";
    }
    return 0;
}
function vam_check_gzip()
{
    if (headers_sent() || connection_aborted()) {
        return false;
    }
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
        return 'x-gzip';
    }
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
        return 'gzip';
    }
    return false;
}
Example #20
0
function shutdown()
{
    if (connection_aborted()) {
        die;
    } else {
        if (connection_status() == CONNECTION_TIMEOUT) {
            http_response_code(500);
            $error = '{"statuscode":500,"message":"This query took to long, maybe there was an internal error"}';
            die($error);
        } else {
        }
    }
}
Example #21
0
 public function drain(Iterator $i)
 {
     $interval = $this->interval();
     $this->start();
     foreach ($i as $datum) {
         $this->send($datum);
         usleep($interval);
         if (connection_aborted()) {
             break;
         }
     }
     $this->end();
 }
Example #22
0
 static function stream($filename)
 {
     $fullpath = Video::fullpath('stream', $filename);
     if ($fullpath === false) {
         return false;
     }
     if (connection_status() != 0) {
         return false;
     }
     header('Content-Type: video/quicktime');
     readfile($fullpath);
     return connection_status() == 0 and !connection_aborted();
 }
Example #23
0
function CheckCanGZip()
{
    $HTTP_ACCEPT_ENCODING = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : "";
    if (headers_sent() || connection_aborted()) {
        return 0;
    }
    if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) {
        return "x-gzip";
    }
    if (strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false) {
        return "gzip";
    }
    return 0;
}
Example #24
0
function tep_check_gzip()
{
    global $HTTP_ACCEPT_ENCODING;
    if (headers_sent() || connection_aborted()) {
        return false;
    }
    if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) {
        return 'x-gzip';
    }
    if (strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false) {
        return 'gzip';
    }
    return false;
}
Example #25
0
function can_gzip()
{
    global $HTTP_SERVER_VARS;
    if (headers_sent() || connection_aborted()) {
        return 0;
    }
    if (strpos($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
        return "x-gzip";
    }
    if (strpos($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
        return "gzip";
    }
    return 0;
}
 /**
  * Are we capable to receive gzipped data?
  *
  * @return mixed (string | boolean) Returns the encoding if it is accepted, false otherwise. Maybe additional check for Mac OS...
  */
 public function encoding()
 {
     if (headers_sent() || connection_aborted()) {
         return false;
     }
     $sEncoding = Server::getVar(Server::HTTP_ACCEPT_ENCODING);
     if (false !== strpos($sEncoding, 'gzip')) {
         return 'gzip';
     }
     if (false !== strpos($sEncoding, 'x-gzip')) {
         return 'x-gzip';
     }
     return false;
 }
Example #27
0
 function stream($lastid = 0)
 {
     header("Content-Type:application/x-dom-event-stream");
     @ob_end_clean();
     @ob_end_clean();
     @ob_end_clean();
     $boring = 0;
     $max = 500;
     $minnullid = 99999999;
     $lastrows = 0;
     ignore_user_abort(false);
     while ($max-- && !connection_aborted()) {
         $data = $this->fetchdata($lastid ? min($minnullid, $lastid + 1) : 0);
         $minnullid = $lastid + 100000;
         foreach ($data['lastposts'] as $d) {
             if ($d['work'] == NULL) {
                 $minnullid = min($minnullid, $d['id']);
             }
             $lastid = max($lastid, $d['id']);
         }
         foreach ($data['processlist'] as $k => $d) {
             if ($d['Info'] == 'show processlist') {
                 unset($data['processlist'][$k]);
             }
         }
         $data['processlist'] = array_values($data['processlist']);
         //			echo "event: message\n";
         echo "id: {$lastid}\n";
         echo "data: " . json_encode($data) . "\n";
         echo "\n";
         @flush();
         if ($lastrows == count($data['lastposts']) + 100 * count($data['processlist'])) {
             $boring++;
             if ($boring > 20) {
                 $boring = 20;
             }
         } else {
             $boring = 0;
         }
         $lastrows = count($data['lastposts']) + 100 * count($data['processlist']);
         if (count($data['lastposts']) > 7 || count($data['processlist']) > 7) {
             sleep(1);
         } else {
             usleep(300000 + 100000 * $boring);
         }
     }
 }
Example #28
0
function redesenhaMapa()
{
    global $map_file, $tipoimagem, $cp, $postgis_mapa, $utilizacgi, $locmapserv, $interface, $mapexten;
    substituiCon($map_file, $postgis_mapa);
    if ($tipoimagem != "nenhum" && $tipoimagem != "") {
        $utilizacgi = "nao";
    }
    if (connection_aborted()) {
        exit;
    }
    if ($interface == "googleearth" && $mapexten != "") {
        include_once dirname(__FILE__) . "/../classesphp/classe_navegacao.php";
        $m = new Navegacao($map_file);
        $m->mudaExtensao($mapexten);
        $m->salva();
    }
    include_once dirname(__FILE__) . "/../classesphp/classe_mapa.php";
    $m = new Mapa($map_file);
    $par = $m->parametrosTemas();
    //
    //na interface googlemaps n&atilde;o &eacute; necess&aacute;rio gerar a imagem
    //
    $e = $m->mapa->extent;
    $ext = $e->minx . " " . $e->miny . " " . $e->maxx . " " . $e->maxy;
    $res["mapimagem"] = "";
    $res["mapexten"] = $ext;
    $res["mapres"] = "";
    $res["erro"] = "";
    $res["mapscale"] = "";
    $res["pixelsize"] = "";
    $res["mapimagem"] = "";
    $res["w"] = $m->mapa->width;
    $res["h"] = $m->mapa->height;
    $res["mappath"] = "";
    $res["mapurl"] = "";
    $res["mensagens"] = $m->pegaMensagens();
    $res["tempo"] = microtime(1) - $tempo;
    restauraCon($map_file, $postgis_mapa);
    ob_clean();
    if ($par == "") {
        $retorno = "erro";
    } else {
        $retorno = array("variaveis" => $res, "temas" => $par);
    }
    cpjson($retorno);
}
Example #29
0
function loadvideo($fileLocation, $maxSpeed = 100)
{
    $count = 0;
    if (connection_status() != 0) {
        return false;
    }
    $range = 0;
    $size = filesize($fileLocation);
    header("Content-Type: video/ogg");
    header("Accept-Ranges: bytes");
    if (isset($_SERVER['HTTP_RANGE'])) {
        list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
        str_replace($range, "-", $range);
        $size2 = $size - 1;
        $new_length = $size - $range;
        header("HTTP/1.1 206 Partial Content");
        header("Content-Length: {$new_length}");
        header("Content-Range: bytes {$range}{$size2}/{$size}");
    } else {
        $size2 = $size - 1;
        header("Content-Range: bytes 0-{$size2}/{$size}");
        header("Content-Length: " . $size);
    }
    if ($size == 0) {
        die('Zero byte file! Aborting download');
    }
    set_magic_quotes_runtime(0);
    $fp = fopen("{$fileLocation}", "rb");
    fseek($fp, $range);
    while (!feof($fp) and connection_status() == 0) {
        set_time_limit(0);
        ignore_user_abort(true);
        $temp = fread($fp, 1 * $maxSpeed);
        $count++;
        print $temp;
        flush();
        ob_flush();
        if ($count > 20000) {
            sleep(10);
        } else {
            sleep(0);
        }
    }
    fclose($fp);
    return connection_status() == 0 and !connection_aborted();
}
Example #30
0
function tep_check_gzip()
{
    // >>> BEGIN REGISTER_GLOBALS
    //    global $HTTP_ACCEPT_ENCODING;
    // <<< END REGISTER_GLOBALS
    if (headers_sent() || connection_aborted()) {
        return false;
    }
    // >>> BEGIN REGISTER_GLOBALS
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) {
        return 'x-gzip';
    }
    if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
        return 'gzip';
    }
    // <<< END REGISTER_GLOBALS
    return false;
}