public static function get_repository_xml($xmlfile, $size = -1) { if (!$xmlfile) { return FALSE; } $mod = cms_utils::get_module('ModuleManager'); $orig_chunksize = $mod->GetPreference('dl_chunksize', 256); $chunksize = $orig_chunksize * 1024; $url = $mod->GetPreference('module_repository'); if ($url == '') { return FALSE; } if ($size <= $chunksize) { // downloading the whole file at one shot. $url .= '/modulexml'; $req = new cms_http_request(); $req->execute($url, '', 'POST', array('name' => $xmlfile)); $status = $req->GetStatus(); $result = $req->GetResult(); if ($status != 200 || $result == '') { $req->clear(); return FALSE; } $tmpname = tempnam(TMP_CACHE_LOCATION, 'modmgr_'); if (!$tmpname) { $req->clear(); return FALSE; } $fh = fopen($tmpname, 'w'); fwrite($fh, $result); fclose($fh); return $tmpname; } // download in chunks $tmpname = tempnam(TMP_CACHE_LOCATION, 'modmgr_'); if (!$tmpname) { return FALSE; } $url .= '/modulegetpart'; $nchunks = (int) ($size / $chunksize); if ($size % $chunksize) { $nchunks++; } $req = new cms_http_request(); for ($i = 0; $i < $nchunks; $i++) { $req->execute($url, '', 'POST', array('name' => $xmlfile, 'partnum' => $i, 'sizekb' => $orig_chunksize)); $status = $req->GetStatus(); $result = $req->GetResult(); if ($status != 200 || $result == '') { unlink($tmpname); $req->clear(); return FALSE; } $fh = fopen($tmpname, 'a'); fwrite($fh, base64_decode($result)); fclose($fh); $req->clear(); } return $tmpname; }