/** * download a bunch of files in gz mode. */ public function downloadBulk($bulkList, $jsList = null) { //language global $_CALEM_conf; $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : null; $ext = false; if ($lang) { $ext = '_' . $lang; } //download mode $mode = isset($_REQUEST['loadmode']) ? $_REQUEST['loadmode'] : $_CALEM_conf['client_js_load_mode']; $zip = false; $zipIt = count($bulkList) > 1; //zipping more than 1 files using min. if ($mode == "gzip") { if ($encoding = CalemGzip::canGzip()) { $zip = true; } if ($zipIt) { //More than 1 files so must use min regardless. $mode_ext = $_CALEM_conf['client_js_custom_ext']['min']; } else { if ($zip) { //single file case - could use a zip file. $mode_ext = $_CALEM_conf['client_js_custom_ext']['gzip']; } else { //zip not available. $mode_ext = $_CALEM_conf['client_js_custom_ext']['min']; //use min instead. } } } else { //This is no gzip case. $mode_ext = $_CALEM_conf['client_js_custom_ext'][$mode]; } //Now let's process file list here. $js = ''; foreach ($bulkList as $fileItem) { $fileName = $fileItem['addLang'] && $ext ? $fileItem['id'] . $ext : $fileItem['id']; $fileName .= $fileItem['ext'] . $mode_ext; if (is_file($fileName)) { $data = file_get_contents($fileName); $js .= $data; if ($this->logger->isDebugEnabled()) { $this->logger->debug("adding file for download: " . $fileName); } } } //Add in text list if any if (isset($jsList)) { foreach ($jsList as $jsDef) { $js .= $jsDef; if ($this->logger->isDebugEnabled()) { $this->logger->debug("adding jsDef for download: " . $jsDef); } } } //Needs to pipe through gz if it's zipped format. if ($zip && $zipIt) { $js = gzencode($js, $_CALEM_conf['server_gzip_rate']); } if ($this->logger->isDebugEnabled()) { $this->logger->debug("Downloading JS by query: zip=" . $zip . ", mode=" . $mode_ext . ", fileCount=" . count($bulkList)); } //Disable browser side cache header('Cache-Control: no-cache'); //Output data CalemGzip::gzStart(); print $js; CalemGzip::gzEndFlush($zip, $encoding); }
/** * Send a response back to client * @param String Response text */ private function sendResponse($status, $response, $zipIt) { //Check for gzip per each service global $_CALEM_conf; $zip = false; if ($zipIt && $_CALEM_conf['calem_soap_allow_gzip'] && ($encoding = CalemGzip::canGzip())) { $zip = true; } //Output data CalemGzip::gzStart(); print $response; CalemGzip::gzSoapCompressEndFlush($status, $zip, $encoding, $this->logger); }