/** * 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); }
$sufix = ''; if ($lang) { $sufix = "_" . $lang; } $msgdir = _CALEM_DIR_ . 'client/lang/'; if (!isset($_CALEM_conf['client_lang_list']['CalemMsg' . $sufix . '.js'])) { $logger->error("Invalid language: " . $lang . ", to use default language."); $sufix = ''; } $mapping = $_CALEM_conf['client_lang_list']['CalemMsg' . $sufix . ".js"]; if ($logger->isDebugEnabled()) { $logger->debug("fetch messages: lang={$lang}; fileset=" . var_export($mapping, true)); } $data = "//Messages for Calem unpacked. " . CALEM_LFCR; foreach ($mapping as $class => $files) { $data .= "//Message definition for " . $class . CALEM_LFCR; $data .= 'function ' . $class . '() {}' . CALEM_LFCR . CALEM_LFCR; foreach ($files as $file) { $fullname = _CALEM_DIR_ . 'client/lang/' . $file . '.properties'; $data .= MessageToJs::fileToJs($class, $fullname); } } //Done parsing messages, now decide the output mode //Disable browser side cache if (!headers_sent()) { header('Cache-Control: no-cache'); } CalemGzip::gzStart(); print $data; CalemGzip::gzEndFlush(false);